@mastra/deployer 0.2.5 → 0.2.6-alpha.10
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 +95 -33
- package/dist/_tsup-dts-rollup.d.ts +95 -33
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.js +1 -1
- package/dist/build/bundler.cjs +3 -3
- package/dist/build/bundler.js +1 -1
- package/dist/build/index.cjs +22 -24
- package/dist/build/index.d.cts +3 -4
- package/dist/build/index.d.ts +3 -4
- package/dist/build/index.js +6 -4
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/chunk-2ZPQX6BX.cjs +254 -0
- package/dist/chunk-4AYFLP6G.js +227 -0
- package/dist/chunk-5UBGPRKT.js +185 -0
- package/dist/{chunk-KLVSED7T.js → chunk-74KZVNKH.js} +8 -4
- package/dist/{chunk-OT6UKL2S.cjs → chunk-AE4CVAPK.cjs} +11 -0
- package/dist/{chunk-UTZ3434D.js → chunk-BDTZS3JM.js} +3 -0
- package/dist/chunk-DYQ225MJ.js +115 -0
- package/dist/chunk-I3UVE6EH.cjs +161 -0
- package/dist/{chunk-XEFBJH3T.js → chunk-IKPL4RGG.js} +11 -0
- package/dist/chunk-NCROGJGB.cjs +142 -0
- package/dist/{chunk-NWERLYTR.cjs → chunk-P5SATU7G.cjs} +3 -0
- package/dist/chunk-VFZVVUQE.cjs +198 -0
- package/dist/chunk-WB3T6NKI.js +133 -0
- package/dist/{chunk-NXBTVZHO.cjs → chunk-WFC3CUZ3.cjs} +14 -10
- package/dist/index.cjs +12 -11
- package/dist/index.js +7 -6
- package/dist/server/index.cjs +617 -2682
- package/dist/server/index.js +512 -2577
- package/dist/services/index.cjs +19 -0
- package/dist/services/index.d.cts +3 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +2 -0
- package/dist/templates/instrumentation-template.js +25 -30
- package/package.json +15 -4
- package/dist/chunk-7GYBZLVN.cjs +0 -286
- package/dist/chunk-KFOGAPGX.cjs +0 -433
- package/dist/chunk-PUX2FDGX.js +0 -252
- package/dist/chunk-ZAXXMFXX.js +0 -399
package/dist/server/index.js
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
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';
|
|
17
|
+
import { timeout } from 'hono/timeout';
|
|
16
18
|
import { HTTPException } from 'hono/http-exception';
|
|
17
|
-
import {
|
|
19
|
+
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';
|
|
20
|
+
import { getLogsHandler as getLogsHandler$1, getLogTransports as getLogTransports$1, getLogsByRunIdHandler as getLogsByRunIdHandler$1 } from '@mastra/server/handlers/logs';
|
|
21
|
+
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';
|
|
22
|
+
import { getNetworksHandler as getNetworksHandler$1, getNetworkByIdHandler as getNetworkByIdHandler$1, generateHandler as generateHandler$1, streamGenerateHandler as streamGenerateHandler$1 } from '@mastra/server/handlers/network';
|
|
18
23
|
import { Agent } from '@mastra/core/agent';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
24
|
+
import { z } from 'zod';
|
|
25
|
+
import { getTelemetryHandler as getTelemetryHandler$1, storeTelemetryHandler as storeTelemetryHandler$1 } from '@mastra/server/handlers/telemetry';
|
|
26
|
+
import { executeAgentToolHandler as executeAgentToolHandler$1, getToolsHandler as getToolsHandler$1, getToolByIdHandler as getToolByIdHandler$1, executeToolHandler as executeToolHandler$1 } from '@mastra/server/handlers/tools';
|
|
27
|
+
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';
|
|
28
|
+
import { getSpeakersHandler as getSpeakersHandler$1, generateSpeechHandler, transcribeSpeechHandler } from '@mastra/server/handlers/voice';
|
|
29
|
+
import { getWorkflowsHandler as getWorkflowsHandler$1, getWorkflowByIdHandler as getWorkflowByIdHandler$1, getWorkflowRunsHandler as getWorkflowRunsHandler$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';
|
|
30
|
+
import { stream } from 'hono/streaming';
|
|
21
31
|
|
|
22
32
|
// src/server/index.ts
|
|
23
33
|
var RequestError = class extends Error {
|
|
@@ -155,14 +165,14 @@ var newRequest = (incoming, defaultHostname) => {
|
|
|
155
165
|
req[urlKey] = url.href;
|
|
156
166
|
return req;
|
|
157
167
|
};
|
|
158
|
-
function writeFromReadableStream(
|
|
159
|
-
if (
|
|
168
|
+
function writeFromReadableStream(stream2, writable) {
|
|
169
|
+
if (stream2.locked) {
|
|
160
170
|
throw new TypeError("ReadableStream is locked.");
|
|
161
171
|
} else if (writable.destroyed) {
|
|
162
|
-
|
|
172
|
+
stream2.cancel();
|
|
163
173
|
return;
|
|
164
174
|
}
|
|
165
|
-
const reader =
|
|
175
|
+
const reader = stream2.getReader();
|
|
166
176
|
writable.on("close", cancel);
|
|
167
177
|
writable.on("error", cancel);
|
|
168
178
|
reader.read().then(flow, cancel);
|
|
@@ -360,7 +370,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
360
370
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
361
371
|
const internalBody = getInternalBody(res);
|
|
362
372
|
if (internalBody) {
|
|
363
|
-
const { length, source, stream } = internalBody;
|
|
373
|
+
const { length, source, stream: stream2 } = internalBody;
|
|
364
374
|
if (source instanceof Uint8Array && source.byteLength !== length) ; else {
|
|
365
375
|
if (length) {
|
|
366
376
|
resHeaderRecord["content-length"] = length;
|
|
@@ -371,7 +381,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
371
381
|
} else if (source instanceof Blob) {
|
|
372
382
|
outgoing.end(new Uint8Array(await source.arrayBuffer()));
|
|
373
383
|
} else {
|
|
374
|
-
await writeFromReadableStream(
|
|
384
|
+
await writeFromReadableStream(stream2, outgoing);
|
|
375
385
|
}
|
|
376
386
|
return;
|
|
377
387
|
}
|
|
@@ -462,7 +472,7 @@ var createAdaptorServer = (options) => {
|
|
|
462
472
|
};
|
|
463
473
|
var serve = (options, listeningListener) => {
|
|
464
474
|
const server = createAdaptorServer(options);
|
|
465
|
-
server.listen(options?.port, options.hostname, () => {
|
|
475
|
+
server.listen(options?.port ?? 3e3, options.hostname, () => {
|
|
466
476
|
const serverInfo = server.address();
|
|
467
477
|
listeningListener && listeningListener(serverInfo);
|
|
468
478
|
});
|
|
@@ -475,18 +485,18 @@ var ENCODINGS = {
|
|
|
475
485
|
gzip: ".gz"
|
|
476
486
|
};
|
|
477
487
|
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
478
|
-
var createStreamBody = (
|
|
488
|
+
var createStreamBody = (stream2) => {
|
|
479
489
|
const body = new ReadableStream({
|
|
480
490
|
start(controller) {
|
|
481
|
-
|
|
491
|
+
stream2.on("data", (chunk) => {
|
|
482
492
|
controller.enqueue(chunk);
|
|
483
493
|
});
|
|
484
|
-
|
|
494
|
+
stream2.on("end", () => {
|
|
485
495
|
controller.close();
|
|
486
496
|
});
|
|
487
497
|
},
|
|
488
498
|
cancel() {
|
|
489
|
-
|
|
499
|
+
stream2.destroy();
|
|
490
500
|
}
|
|
491
501
|
});
|
|
492
502
|
return body;
|
|
@@ -582,10 +592,10 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
582
592
|
end = size - 1;
|
|
583
593
|
}
|
|
584
594
|
const chunksize = end - start + 1;
|
|
585
|
-
const
|
|
595
|
+
const stream2 = createReadStream(path, { start, end });
|
|
586
596
|
c2.header("Content-Length", chunksize.toString());
|
|
587
597
|
c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
588
|
-
return c2.body(createStreamBody(
|
|
598
|
+
return c2.body(createStreamBody(stream2), 206);
|
|
589
599
|
};
|
|
590
600
|
};
|
|
591
601
|
var RENDER_TYPE = {
|
|
@@ -832,2006 +842,7 @@ async function x(e2, t2, s3 = {}) {
|
|
|
832
842
|
}
|
|
833
843
|
return { docs: o2, components: n2 };
|
|
834
844
|
}
|
|
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
845
|
function handleError(error, defaultMessage) {
|
|
2834
|
-
console.error(defaultMessage, error);
|
|
2835
846
|
const apiError = error;
|
|
2836
847
|
throw new HTTPException(apiError.status || 500, {
|
|
2837
848
|
message: apiError.message || defaultMessage
|
|
@@ -2844,120 +855,49 @@ function errorHandler(err, c2) {
|
|
|
2844
855
|
console.error(err);
|
|
2845
856
|
return c2.json({ error: "Internal Server Error" }, 500);
|
|
2846
857
|
}
|
|
2847
|
-
function validateBody(body) {
|
|
2848
|
-
const errorResponse = Object.entries(body).reduce((acc, [key, value]) => {
|
|
2849
|
-
if (!value) {
|
|
2850
|
-
acc[key] = `${key} is required`;
|
|
2851
|
-
}
|
|
2852
|
-
return acc;
|
|
2853
|
-
}, {});
|
|
2854
|
-
if (Object.keys(errorResponse).length > 0) {
|
|
2855
|
-
throw new HTTPException(400, { message: JSON.stringify(errorResponse) });
|
|
2856
|
-
}
|
|
2857
|
-
}
|
|
2858
858
|
|
|
2859
859
|
// src/server/handlers/agents.ts
|
|
2860
860
|
async function getAgentsHandler(c2) {
|
|
2861
|
-
|
|
2862
|
-
|
|
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
|
-
}
|
|
861
|
+
const serializedAgents = await getAgentsHandler$1({ mastra: c2.get("mastra") });
|
|
862
|
+
return c2.json(serializedAgents);
|
|
2888
863
|
}
|
|
2889
864
|
async function getAgentByIdHandler(c2) {
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
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
|
-
}
|
|
865
|
+
const mastra = c2.get("mastra");
|
|
866
|
+
const agentId = c2.req.param("agentId");
|
|
867
|
+
const result = await getAgentByIdHandler$1({
|
|
868
|
+
mastra,
|
|
869
|
+
agentId
|
|
870
|
+
});
|
|
871
|
+
return c2.json(result);
|
|
2916
872
|
}
|
|
2917
873
|
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
|
-
}
|
|
874
|
+
const mastra = c2.get("mastra");
|
|
875
|
+
const agentId = c2.req.param("agentId");
|
|
876
|
+
const result = await getEvalsByAgentIdHandler$1({
|
|
877
|
+
mastra,
|
|
878
|
+
agentId
|
|
879
|
+
});
|
|
880
|
+
return c2.json(result);
|
|
2932
881
|
}
|
|
2933
882
|
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
|
-
}
|
|
883
|
+
const mastra = c2.get("mastra");
|
|
884
|
+
const agentId = c2.req.param("agentId");
|
|
885
|
+
const result = await getLiveEvalsByAgentIdHandler$1({
|
|
886
|
+
mastra,
|
|
887
|
+
agentId
|
|
888
|
+
});
|
|
889
|
+
return c2.json(result);
|
|
2948
890
|
}
|
|
2949
891
|
async function generateHandler(c2) {
|
|
2950
892
|
try {
|
|
2951
893
|
const mastra = c2.get("mastra");
|
|
2952
894
|
const agentId = c2.req.param("agentId");
|
|
2953
|
-
const
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
const finalResourceId = resourceId ?? resourceid;
|
|
2960
|
-
const result = await agent.generate(messages, { threadId, resourceId: finalResourceId, output, runId, ...rest });
|
|
895
|
+
const body = await c2.req.json();
|
|
896
|
+
const result = await generateHandler$2({
|
|
897
|
+
mastra,
|
|
898
|
+
agentId,
|
|
899
|
+
body
|
|
900
|
+
});
|
|
2961
901
|
return c2.json(result);
|
|
2962
902
|
} catch (error) {
|
|
2963
903
|
return handleError(error, "Error generating from agent");
|
|
@@ -2967,26 +907,11 @@ async function streamGenerateHandler(c2) {
|
|
|
2967
907
|
try {
|
|
2968
908
|
const mastra = c2.get("mastra");
|
|
2969
909
|
const agentId = c2.req.param("agentId");
|
|
2970
|
-
const
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
validateBody({ messages });
|
|
2976
|
-
const finalResourceId = resourceId ?? resourceid;
|
|
2977
|
-
const streamResult = await agent.stream(messages, {
|
|
2978
|
-
threadId,
|
|
2979
|
-
resourceId: finalResourceId,
|
|
2980
|
-
output,
|
|
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
|
-
}
|
|
910
|
+
const body = await c2.req.json();
|
|
911
|
+
const streamResponse = await streamGenerateHandler$2({
|
|
912
|
+
mastra,
|
|
913
|
+
agentId,
|
|
914
|
+
body
|
|
2990
915
|
});
|
|
2991
916
|
return streamResponse;
|
|
2992
917
|
} catch (error) {
|
|
@@ -3024,7 +949,7 @@ async function setAgentInstructionsHandler(c2) {
|
|
|
3024
949
|
// src/server/handlers/client.ts
|
|
3025
950
|
var clients = /* @__PURE__ */ new Set();
|
|
3026
951
|
function handleClientsRefresh(c2) {
|
|
3027
|
-
const
|
|
952
|
+
const stream2 = new ReadableStream({
|
|
3028
953
|
start(controller) {
|
|
3029
954
|
clients.add(controller);
|
|
3030
955
|
controller.enqueue("data: connected\n\n");
|
|
@@ -3033,7 +958,7 @@ function handleClientsRefresh(c2) {
|
|
|
3033
958
|
});
|
|
3034
959
|
}
|
|
3035
960
|
});
|
|
3036
|
-
return new Response(
|
|
961
|
+
return new Response(stream2, {
|
|
3037
962
|
headers: {
|
|
3038
963
|
"Content-Type": "text/event-stream",
|
|
3039
964
|
"Cache-Control": "no-cache",
|
|
@@ -3056,10 +981,10 @@ async function getLogsHandler(c2) {
|
|
|
3056
981
|
try {
|
|
3057
982
|
const mastra = c2.get("mastra");
|
|
3058
983
|
const transportId = c2.req.query("transportId");
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
984
|
+
const logs = await getLogsHandler$1({
|
|
985
|
+
mastra,
|
|
986
|
+
transportId
|
|
987
|
+
});
|
|
3063
988
|
return c2.json(logs);
|
|
3064
989
|
} catch (error) {
|
|
3065
990
|
return handleError(error, "Error getting logs");
|
|
@@ -3070,10 +995,11 @@ async function getLogsByRunIdHandler(c2) {
|
|
|
3070
995
|
const mastra = c2.get("mastra");
|
|
3071
996
|
const runId = c2.req.param("runId");
|
|
3072
997
|
const transportId = c2.req.query("transportId");
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
998
|
+
const logs = await getLogsByRunIdHandler$1({
|
|
999
|
+
mastra,
|
|
1000
|
+
runId,
|
|
1001
|
+
transportId
|
|
1002
|
+
});
|
|
3077
1003
|
return c2.json(logs);
|
|
3078
1004
|
} catch (error) {
|
|
3079
1005
|
return handleError(error, "Error getting logs by run ID");
|
|
@@ -3082,85 +1008,67 @@ async function getLogsByRunIdHandler(c2) {
|
|
|
3082
1008
|
async function getLogTransports(c2) {
|
|
3083
1009
|
try {
|
|
3084
1010
|
const mastra = c2.get("mastra");
|
|
3085
|
-
const
|
|
3086
|
-
|
|
3087
|
-
return c2.json({
|
|
3088
|
-
transports: Object.keys(transports)
|
|
1011
|
+
const result = await getLogTransports$1({
|
|
1012
|
+
mastra
|
|
3089
1013
|
});
|
|
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" });
|
|
1014
|
+
return c2.json(result);
|
|
1015
|
+
} catch (error) {
|
|
1016
|
+
return handleError(error, "Error getting log Transports");
|
|
3100
1017
|
}
|
|
3101
|
-
const memory = agent?.getMemory?.() || mastra.memory;
|
|
3102
|
-
return memory;
|
|
3103
1018
|
}
|
|
3104
1019
|
async function getMemoryStatusHandler(c2) {
|
|
3105
1020
|
try {
|
|
3106
|
-
const
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
1021
|
+
const mastra = c2.get("mastra");
|
|
1022
|
+
const agentId = c2.req.query("agentId");
|
|
1023
|
+
const result = await getMemoryStatusHandler$1({
|
|
1024
|
+
mastra,
|
|
1025
|
+
agentId
|
|
1026
|
+
});
|
|
1027
|
+
return c2.json(result);
|
|
3111
1028
|
} catch (error) {
|
|
3112
1029
|
return handleError(error, "Error getting memory status");
|
|
3113
1030
|
}
|
|
3114
1031
|
}
|
|
3115
1032
|
async function getThreadsHandler(c2) {
|
|
3116
1033
|
try {
|
|
3117
|
-
const
|
|
3118
|
-
const
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
}
|
|
3125
|
-
|
|
3126
|
-
return c2.json(threads);
|
|
1034
|
+
const mastra = c2.get("mastra");
|
|
1035
|
+
const agentId = c2.req.query("agentId");
|
|
1036
|
+
const resourceId = c2.req.query("resourceid");
|
|
1037
|
+
const result = await getThreadsHandler$1({
|
|
1038
|
+
mastra,
|
|
1039
|
+
agentId,
|
|
1040
|
+
resourceId
|
|
1041
|
+
});
|
|
1042
|
+
return c2.json(result);
|
|
3127
1043
|
} catch (error) {
|
|
3128
1044
|
return handleError(error, "Error getting threads");
|
|
3129
1045
|
}
|
|
3130
1046
|
}
|
|
3131
1047
|
async function getThreadByIdHandler(c2) {
|
|
3132
1048
|
try {
|
|
3133
|
-
const
|
|
1049
|
+
const mastra = c2.get("mastra");
|
|
1050
|
+
const agentId = c2.req.query("agentId");
|
|
3134
1051
|
const threadId = c2.req.param("threadId");
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
}
|
|
3142
|
-
return c2.json(thread);
|
|
1052
|
+
const result = await getThreadByIdHandler$1({
|
|
1053
|
+
mastra,
|
|
1054
|
+
agentId,
|
|
1055
|
+
threadId
|
|
1056
|
+
});
|
|
1057
|
+
return c2.json(result);
|
|
3143
1058
|
} catch (error) {
|
|
3144
1059
|
return handleError(error, "Error getting thread");
|
|
3145
1060
|
}
|
|
3146
1061
|
}
|
|
3147
1062
|
async function saveMessagesHandler(c2) {
|
|
3148
1063
|
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: {} });
|
|
1064
|
+
const mastra = c2.get("mastra");
|
|
1065
|
+
const agentId = c2.req.query("agentId");
|
|
1066
|
+
const body = await c2.req.json();
|
|
1067
|
+
const result = await saveMessagesHandler$1({
|
|
1068
|
+
mastra,
|
|
1069
|
+
agentId,
|
|
1070
|
+
body
|
|
1071
|
+
});
|
|
3164
1072
|
return c2.json(result);
|
|
3165
1073
|
} catch (error) {
|
|
3166
1074
|
return handleError(error, "Error saving messages");
|
|
@@ -3168,13 +1076,14 @@ async function saveMessagesHandler(c2) {
|
|
|
3168
1076
|
}
|
|
3169
1077
|
async function createThreadHandler(c2) {
|
|
3170
1078
|
try {
|
|
3171
|
-
const
|
|
3172
|
-
const
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
1079
|
+
const mastra = c2.get("mastra");
|
|
1080
|
+
const agentId = c2.req.query("agentId");
|
|
1081
|
+
const body = await c2.req.json();
|
|
1082
|
+
const result = await createThreadHandler$1({
|
|
1083
|
+
mastra,
|
|
1084
|
+
agentId,
|
|
1085
|
+
body
|
|
1086
|
+
});
|
|
3178
1087
|
return c2.json(result);
|
|
3179
1088
|
} catch (error) {
|
|
3180
1089
|
return handleError(error, "Error saving thread to memory");
|
|
@@ -3182,26 +1091,16 @@ async function createThreadHandler(c2) {
|
|
|
3182
1091
|
}
|
|
3183
1092
|
async function updateThreadHandler(c2) {
|
|
3184
1093
|
try {
|
|
3185
|
-
const
|
|
1094
|
+
const mastra = c2.get("mastra");
|
|
1095
|
+
const agentId = c2.req.query("agentId");
|
|
3186
1096
|
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 });
|
|
1097
|
+
const body = await c2.req.json();
|
|
1098
|
+
const result = await updateThreadHandler$1({
|
|
1099
|
+
mastra,
|
|
1100
|
+
agentId,
|
|
1101
|
+
threadId,
|
|
1102
|
+
body
|
|
1103
|
+
});
|
|
3205
1104
|
return c2.json(result);
|
|
3206
1105
|
} catch (error) {
|
|
3207
1106
|
return handleError(error, "Error updating thread");
|
|
@@ -3209,33 +1108,29 @@ async function updateThreadHandler(c2) {
|
|
|
3209
1108
|
}
|
|
3210
1109
|
async function deleteThreadHandler(c2) {
|
|
3211
1110
|
try {
|
|
3212
|
-
const
|
|
1111
|
+
const mastra = c2.get("mastra");
|
|
1112
|
+
const agentId = c2.req.query("agentId");
|
|
3213
1113
|
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" });
|
|
1114
|
+
const result = await deleteThreadHandler$1({
|
|
1115
|
+
mastra,
|
|
1116
|
+
agentId,
|
|
1117
|
+
threadId
|
|
1118
|
+
});
|
|
1119
|
+
return c2.json(result);
|
|
3223
1120
|
} catch (error) {
|
|
3224
1121
|
return handleError(error, "Error deleting thread");
|
|
3225
1122
|
}
|
|
3226
1123
|
}
|
|
3227
1124
|
async function getMessagesHandler(c2) {
|
|
3228
1125
|
try {
|
|
3229
|
-
const
|
|
1126
|
+
const mastra = c2.get("mastra");
|
|
1127
|
+
const agentId = c2.req.query("agentId");
|
|
3230
1128
|
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 });
|
|
1129
|
+
const result = await getMessagesHandler$1({
|
|
1130
|
+
mastra,
|
|
1131
|
+
agentId,
|
|
1132
|
+
threadId
|
|
1133
|
+
});
|
|
3239
1134
|
return c2.json(result);
|
|
3240
1135
|
} catch (error) {
|
|
3241
1136
|
return handleError(error, "Error getting messages");
|
|
@@ -3244,26 +1139,10 @@ async function getMessagesHandler(c2) {
|
|
|
3244
1139
|
async function getNetworksHandler(c2) {
|
|
3245
1140
|
try {
|
|
3246
1141
|
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
|
-
};
|
|
1142
|
+
const networks = await getNetworksHandler$1({
|
|
1143
|
+
mastra
|
|
3265
1144
|
});
|
|
3266
|
-
return c2.json(
|
|
1145
|
+
return c2.json(networks);
|
|
3267
1146
|
} catch (error) {
|
|
3268
1147
|
return handleError(error, "Error getting networks");
|
|
3269
1148
|
}
|
|
@@ -3272,31 +1151,11 @@ async function getNetworkByIdHandler(c2) {
|
|
|
3272
1151
|
try {
|
|
3273
1152
|
const mastra = c2.get("mastra");
|
|
3274
1153
|
const networkId = c2.req.param("networkId");
|
|
3275
|
-
const
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
return network2.formatAgentId(routingAgent2.name) === networkId;
|
|
1154
|
+
const network = await getNetworkByIdHandler$1({
|
|
1155
|
+
mastra,
|
|
1156
|
+
networkId
|
|
3279
1157
|
});
|
|
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);
|
|
1158
|
+
return c2.json(network);
|
|
3300
1159
|
} catch (error) {
|
|
3301
1160
|
return handleError(error, "Error getting network by ID");
|
|
3302
1161
|
}
|
|
@@ -3305,43 +1164,26 @@ async function generateHandler2(c2) {
|
|
|
3305
1164
|
try {
|
|
3306
1165
|
const mastra = c2.get("mastra");
|
|
3307
1166
|
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 });
|
|
1167
|
+
const body = await c2.req.json();
|
|
1168
|
+
const result = await generateHandler$1({
|
|
1169
|
+
mastra,
|
|
1170
|
+
networkId,
|
|
1171
|
+
body
|
|
1172
|
+
});
|
|
3316
1173
|
return c2.json(result);
|
|
3317
1174
|
} catch (error) {
|
|
3318
1175
|
return handleError(error, "Error generating from network");
|
|
3319
1176
|
}
|
|
3320
1177
|
}
|
|
3321
|
-
async function streamGenerateHandler2(c2) {
|
|
3322
|
-
try {
|
|
3323
|
-
const mastra = c2.get("mastra");
|
|
3324
|
-
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
|
-
}
|
|
1178
|
+
async function streamGenerateHandler2(c2) {
|
|
1179
|
+
try {
|
|
1180
|
+
const mastra = c2.get("mastra");
|
|
1181
|
+
const networkId = c2.req.param("networkId");
|
|
1182
|
+
const body = await c2.req.json();
|
|
1183
|
+
const streamResponse = await streamGenerateHandler$1({
|
|
1184
|
+
mastra,
|
|
1185
|
+
networkId,
|
|
1186
|
+
body
|
|
3345
1187
|
});
|
|
3346
1188
|
return streamResponse;
|
|
3347
1189
|
} catch (error) {
|
|
@@ -3366,8 +1208,8 @@ async function generateSystemPromptHandler(c2) {
|
|
|
3366
1208
|
}
|
|
3367
1209
|
let evalSummary = "";
|
|
3368
1210
|
try {
|
|
3369
|
-
const testEvals = await mastra.storage?.
|
|
3370
|
-
const liveEvals = await mastra.storage?.
|
|
1211
|
+
const testEvals = await mastra.storage?.__getEvalsByAgentName?.(agent.name, "test") || [];
|
|
1212
|
+
const liveEvals = await mastra.storage?.__getEvalsByAgentName?.(agent.name, "live") || [];
|
|
3371
1213
|
const evalsMapped = [...testEvals, ...liveEvals].filter(
|
|
3372
1214
|
({ instructions: evalInstructions }) => evalInstructions === instructions
|
|
3373
1215
|
);
|
|
@@ -3465,53 +1307,37 @@ async function rootHandler(c2) {
|
|
|
3465
1307
|
async function getTelemetryHandler(c2) {
|
|
3466
1308
|
try {
|
|
3467
1309
|
const mastra = c2.get("mastra");
|
|
3468
|
-
const telemetry = mastra.getTelemetry();
|
|
3469
|
-
const storage = mastra.getStorage();
|
|
3470
1310
|
const { name, scope, page, perPage } = c2.req.query();
|
|
3471
1311
|
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
|
|
1312
|
+
const traces = await getTelemetryHandler$1({
|
|
1313
|
+
mastra,
|
|
1314
|
+
body: { name, scope, page: Number(page ?? 0), perPage: Number(perPage ?? 100), attribute }
|
|
3490
1315
|
});
|
|
3491
1316
|
return c2.json({ traces });
|
|
3492
1317
|
} catch (error) {
|
|
3493
|
-
return handleError(error, "Error
|
|
1318
|
+
return handleError(error, "Error getting telemetry traces");
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
async function storeTelemetryHandler(c2) {
|
|
1322
|
+
try {
|
|
1323
|
+
const body = await c2.req.json();
|
|
1324
|
+
const mastra = c2.get("mastra");
|
|
1325
|
+
const result = await storeTelemetryHandler$1({ mastra, body });
|
|
1326
|
+
if (result.status === "error") {
|
|
1327
|
+
return c2.json(result, 500);
|
|
1328
|
+
}
|
|
1329
|
+
return c2.json(result, 200);
|
|
1330
|
+
} catch (error) {
|
|
1331
|
+
return handleError(error, "Error storing telemetry traces");
|
|
3494
1332
|
}
|
|
3495
1333
|
}
|
|
3496
1334
|
async function getToolsHandler(c2) {
|
|
3497
1335
|
try {
|
|
3498
1336
|
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);
|
|
1337
|
+
const result = await getToolsHandler$1({
|
|
1338
|
+
tools
|
|
1339
|
+
});
|
|
1340
|
+
return c2.json(result);
|
|
3515
1341
|
} catch (error) {
|
|
3516
1342
|
return handleError(error, "Error getting tools");
|
|
3517
1343
|
}
|
|
@@ -3520,16 +1346,11 @@ async function getToolByIdHandler(c2) {
|
|
|
3520
1346
|
try {
|
|
3521
1347
|
const tools = c2.get("tools");
|
|
3522
1348
|
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);
|
|
1349
|
+
const result = await getToolByIdHandler$1({
|
|
1350
|
+
tools,
|
|
1351
|
+
toolId
|
|
1352
|
+
});
|
|
1353
|
+
return c2.json(result);
|
|
3533
1354
|
} catch (error) {
|
|
3534
1355
|
return handleError(error, "Error getting tool");
|
|
3535
1356
|
}
|
|
@@ -3537,24 +1358,13 @@ async function getToolByIdHandler(c2) {
|
|
|
3537
1358
|
function executeToolHandler(tools) {
|
|
3538
1359
|
return async (c2) => {
|
|
3539
1360
|
try {
|
|
1361
|
+
const mastra = c2.get("mastra");
|
|
3540
1362
|
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
1363
|
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,
|
|
1364
|
+
const result = await executeToolHandler$1(tools)({
|
|
3556
1365
|
mastra,
|
|
3557
|
-
|
|
1366
|
+
toolId,
|
|
1367
|
+
data
|
|
3558
1368
|
});
|
|
3559
1369
|
return c2.json(result);
|
|
3560
1370
|
} catch (error) {
|
|
@@ -3567,45 +1377,28 @@ async function executeAgentToolHandler(c2) {
|
|
|
3567
1377
|
const mastra = c2.get("mastra");
|
|
3568
1378
|
const agentId = c2.req.param("agentId");
|
|
3569
1379
|
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
1380
|
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,
|
|
1381
|
+
const result = await executeAgentToolHandler$1({
|
|
3585
1382
|
mastra,
|
|
3586
|
-
|
|
1383
|
+
agentId,
|
|
1384
|
+
toolId,
|
|
1385
|
+
data
|
|
3587
1386
|
});
|
|
3588
1387
|
return c2.json(result);
|
|
3589
1388
|
} catch (error) {
|
|
3590
1389
|
return handleError(error, "Error executing tool");
|
|
3591
1390
|
}
|
|
3592
1391
|
}
|
|
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
1392
|
async function upsertVectors(c2) {
|
|
3601
1393
|
try {
|
|
1394
|
+
const mastra = c2.get("mastra");
|
|
3602
1395
|
const vectorName = c2.req.param("vectorName");
|
|
3603
|
-
const
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
1396
|
+
const body = await c2.req.json();
|
|
1397
|
+
const result = await upsertVectors$1({
|
|
1398
|
+
mastra,
|
|
1399
|
+
vectorName,
|
|
1400
|
+
index: body
|
|
1401
|
+
});
|
|
3609
1402
|
return c2.json({ ids: result });
|
|
3610
1403
|
} catch (error) {
|
|
3611
1404
|
return handleError(error, "Error upserting vectors");
|
|
@@ -3613,18 +1406,14 @@ async function upsertVectors(c2) {
|
|
|
3613
1406
|
}
|
|
3614
1407
|
async function createIndex(c2) {
|
|
3615
1408
|
try {
|
|
1409
|
+
const mastra = c2.get("mastra");
|
|
3616
1410
|
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 });
|
|
1411
|
+
const body = await c2.req.json();
|
|
1412
|
+
await createIndex$1({
|
|
1413
|
+
mastra,
|
|
1414
|
+
vectorName,
|
|
1415
|
+
index: body
|
|
1416
|
+
});
|
|
3628
1417
|
return c2.json({ success: true });
|
|
3629
1418
|
} catch (error) {
|
|
3630
1419
|
return handleError(error, "Error creating index");
|
|
@@ -3632,13 +1421,14 @@ async function createIndex(c2) {
|
|
|
3632
1421
|
}
|
|
3633
1422
|
async function queryVectors(c2) {
|
|
3634
1423
|
try {
|
|
1424
|
+
const mastra = c2.get("mastra");
|
|
3635
1425
|
const vectorName = c2.req.param("vectorName");
|
|
3636
1426
|
const { indexName, queryVector, topK = 10, filter, includeVector = false } = await c2.req.json();
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
1427
|
+
const results = await queryVectors$1({
|
|
1428
|
+
mastra,
|
|
1429
|
+
vectorName,
|
|
1430
|
+
query: { indexName, queryVector, topK, filter, includeVector }
|
|
1431
|
+
});
|
|
3642
1432
|
return c2.json({ results });
|
|
3643
1433
|
} catch (error) {
|
|
3644
1434
|
return handleError(error, "Error querying vectors");
|
|
@@ -3646,23 +1436,30 @@ async function queryVectors(c2) {
|
|
|
3646
1436
|
}
|
|
3647
1437
|
async function listIndexes(c2) {
|
|
3648
1438
|
try {
|
|
1439
|
+
const mastra = c2.get("mastra");
|
|
3649
1440
|
const vectorName = c2.req.param("vectorName");
|
|
3650
|
-
const
|
|
3651
|
-
|
|
3652
|
-
|
|
1441
|
+
const indexes = await listIndexes$1({
|
|
1442
|
+
mastra,
|
|
1443
|
+
vectorName
|
|
1444
|
+
});
|
|
1445
|
+
return c2.json({ indexes });
|
|
3653
1446
|
} catch (error) {
|
|
3654
1447
|
return handleError(error, "Error listing indexes");
|
|
3655
1448
|
}
|
|
3656
1449
|
}
|
|
3657
1450
|
async function describeIndex(c2) {
|
|
3658
1451
|
try {
|
|
1452
|
+
const mastra = c2.get("mastra");
|
|
3659
1453
|
const vectorName = c2.req.param("vectorName");
|
|
3660
1454
|
const indexName = c2.req.param("indexName");
|
|
3661
1455
|
if (!indexName) {
|
|
3662
1456
|
throw new HTTPException(400, { message: "Index name is required" });
|
|
3663
1457
|
}
|
|
3664
|
-
const
|
|
3665
|
-
|
|
1458
|
+
const stats = await describeIndex$1({
|
|
1459
|
+
mastra,
|
|
1460
|
+
vectorName,
|
|
1461
|
+
indexName
|
|
1462
|
+
});
|
|
3666
1463
|
return c2.json({
|
|
3667
1464
|
dimension: stats.dimension,
|
|
3668
1465
|
count: stats.count,
|
|
@@ -3674,13 +1471,17 @@ async function describeIndex(c2) {
|
|
|
3674
1471
|
}
|
|
3675
1472
|
async function deleteIndex(c2) {
|
|
3676
1473
|
try {
|
|
1474
|
+
const mastra = c2.get("mastra");
|
|
3677
1475
|
const vectorName = c2.req.param("vectorName");
|
|
3678
1476
|
const indexName = c2.req.param("indexName");
|
|
3679
1477
|
if (!indexName) {
|
|
3680
1478
|
throw new HTTPException(400, { message: "Index name is required" });
|
|
3681
1479
|
}
|
|
3682
|
-
|
|
3683
|
-
|
|
1480
|
+
await deleteIndex$1({
|
|
1481
|
+
mastra,
|
|
1482
|
+
vectorName,
|
|
1483
|
+
indexName
|
|
1484
|
+
});
|
|
3684
1485
|
return c2.json({ success: true });
|
|
3685
1486
|
} catch (error) {
|
|
3686
1487
|
return handleError(error, "Error deleting index");
|
|
@@ -3690,14 +1491,10 @@ async function getSpeakersHandler(c2) {
|
|
|
3690
1491
|
try {
|
|
3691
1492
|
const mastra = c2.get("mastra");
|
|
3692
1493
|
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();
|
|
1494
|
+
const speakers = await getSpeakersHandler$1({
|
|
1495
|
+
mastra,
|
|
1496
|
+
agentId
|
|
1497
|
+
});
|
|
3701
1498
|
return c2.json(speakers);
|
|
3702
1499
|
} catch (error) {
|
|
3703
1500
|
return handleError(error, "Error getting speakers");
|
|
@@ -3707,16 +1504,12 @@ async function speakHandler(c2) {
|
|
|
3707
1504
|
try {
|
|
3708
1505
|
const mastra = c2.get("mastra");
|
|
3709
1506
|
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
1507
|
const { input, options } = await c2.req.json();
|
|
3718
|
-
await
|
|
3719
|
-
|
|
1508
|
+
const audioStream = await generateSpeechHandler({
|
|
1509
|
+
mastra,
|
|
1510
|
+
agentId,
|
|
1511
|
+
body: { text: input, speakerId: options?.speakerId }
|
|
1512
|
+
});
|
|
3720
1513
|
c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
|
|
3721
1514
|
c2.header("Transfer-Encoding", "chunked");
|
|
3722
1515
|
return c2.body(audioStream);
|
|
@@ -3728,14 +1521,6 @@ async function listenHandler(c2) {
|
|
|
3728
1521
|
try {
|
|
3729
1522
|
const mastra = c2.get("mastra");
|
|
3730
1523
|
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
1524
|
const formData = await c2.req.formData();
|
|
3740
1525
|
const audioFile = formData.get("audio");
|
|
3741
1526
|
const options = formData.get("options");
|
|
@@ -3743,19 +1528,19 @@ async function listenHandler(c2) {
|
|
|
3743
1528
|
throw new HTTPException(400, { message: "Audio file is required" });
|
|
3744
1529
|
}
|
|
3745
1530
|
const audioData = await audioFile.arrayBuffer();
|
|
3746
|
-
|
|
3747
|
-
audioStream.push(Buffer.from(audioData));
|
|
3748
|
-
audioStream.push(null);
|
|
3749
|
-
let parsedOptions;
|
|
1531
|
+
let parsedOptions = {};
|
|
3750
1532
|
try {
|
|
3751
1533
|
parsedOptions = options ? JSON.parse(options) : {};
|
|
3752
|
-
} catch
|
|
3753
|
-
if (error instanceof SyntaxError) {
|
|
3754
|
-
logger2.error("Invalid JSON in options:", error);
|
|
3755
|
-
}
|
|
3756
|
-
parsedOptions = {};
|
|
1534
|
+
} catch {
|
|
3757
1535
|
}
|
|
3758
|
-
const transcription = await
|
|
1536
|
+
const transcription = await transcribeSpeechHandler({
|
|
1537
|
+
mastra,
|
|
1538
|
+
agentId,
|
|
1539
|
+
body: {
|
|
1540
|
+
audioData: Buffer.from(audioData),
|
|
1541
|
+
options: parsedOptions
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
3759
1544
|
return c2.json({ text: transcription });
|
|
3760
1545
|
} catch (error) {
|
|
3761
1546
|
return handleError(error, "Error transcribing speech");
|
|
@@ -3764,28 +1549,10 @@ async function listenHandler(c2) {
|
|
|
3764
1549
|
async function getWorkflowsHandler(c2) {
|
|
3765
1550
|
try {
|
|
3766
1551
|
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);
|
|
1552
|
+
const workflows = await getWorkflowsHandler$1({
|
|
1553
|
+
mastra
|
|
1554
|
+
});
|
|
1555
|
+
return c2.json(workflows);
|
|
3789
1556
|
} catch (error) {
|
|
3790
1557
|
return handleError(error, "Error getting workflows");
|
|
3791
1558
|
}
|
|
@@ -3794,30 +1561,11 @@ async function getWorkflowByIdHandler(c2) {
|
|
|
3794
1561
|
try {
|
|
3795
1562
|
const mastra = c2.get("mastra");
|
|
3796
1563
|
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
|
|
1564
|
+
const workflow = await getWorkflowByIdHandler$1({
|
|
1565
|
+
mastra,
|
|
1566
|
+
workflowId
|
|
3820
1567
|
});
|
|
1568
|
+
return c2.json(workflow);
|
|
3821
1569
|
} catch (error) {
|
|
3822
1570
|
return handleError(error, "Error getting workflow");
|
|
3823
1571
|
}
|
|
@@ -3826,18 +1574,13 @@ async function startAsyncWorkflowHandler(c2) {
|
|
|
3826
1574
|
try {
|
|
3827
1575
|
const mastra = c2.get("mastra");
|
|
3828
1576
|
const workflowId = c2.req.param("workflowId");
|
|
3829
|
-
const
|
|
3830
|
-
const body = await c2.req.json();
|
|
1577
|
+
const triggerData = await c2.req.json();
|
|
3831
1578
|
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
|
|
1579
|
+
const result = await startAsyncWorkflowHandler$1({
|
|
1580
|
+
mastra,
|
|
1581
|
+
workflowId,
|
|
1582
|
+
runId,
|
|
1583
|
+
triggerData
|
|
3841
1584
|
});
|
|
3842
1585
|
return c2.json(result);
|
|
3843
1586
|
} catch (error) {
|
|
@@ -3848,10 +1591,13 @@ async function createRunHandler(c2) {
|
|
|
3848
1591
|
try {
|
|
3849
1592
|
const mastra = c2.get("mastra");
|
|
3850
1593
|
const workflowId = c2.req.param("workflowId");
|
|
3851
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
3852
1594
|
const prevRunId = c2.req.query("runId");
|
|
3853
|
-
const
|
|
3854
|
-
|
|
1595
|
+
const result = await createRunHandler$1({
|
|
1596
|
+
mastra,
|
|
1597
|
+
workflowId,
|
|
1598
|
+
runId: prevRunId
|
|
1599
|
+
});
|
|
1600
|
+
return c2.json(result);
|
|
3855
1601
|
} catch (e2) {
|
|
3856
1602
|
return handleError(e2, "Error creating run");
|
|
3857
1603
|
}
|
|
@@ -3860,54 +1606,51 @@ async function startWorkflowRunHandler(c2) {
|
|
|
3860
1606
|
try {
|
|
3861
1607
|
const mastra = c2.get("mastra");
|
|
3862
1608
|
const workflowId = c2.req.param("workflowId");
|
|
3863
|
-
const
|
|
3864
|
-
const body = await c2.req.json();
|
|
1609
|
+
const triggerData = await c2.req.json();
|
|
3865
1610
|
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
|
|
1611
|
+
await startWorkflowRunHandler$1({
|
|
1612
|
+
mastra,
|
|
1613
|
+
workflowId,
|
|
1614
|
+
runId,
|
|
1615
|
+
triggerData
|
|
3875
1616
|
});
|
|
3876
1617
|
return c2.json({ message: "Workflow run started" });
|
|
3877
1618
|
} catch (e2) {
|
|
3878
1619
|
return handleError(e2, "Error starting workflow run");
|
|
3879
1620
|
}
|
|
3880
1621
|
}
|
|
3881
|
-
|
|
1622
|
+
function watchWorkflowHandler(c2) {
|
|
3882
1623
|
try {
|
|
3883
1624
|
const mastra = c2.get("mastra");
|
|
3884
1625
|
const logger2 = mastra.getLogger();
|
|
3885
1626
|
const workflowId = c2.req.param("workflowId");
|
|
3886
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
3887
1627
|
const runId = c2.req.query("runId");
|
|
3888
1628
|
if (!runId) {
|
|
3889
1629
|
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
3890
1630
|
}
|
|
3891
|
-
|
|
3892
|
-
if (!run) {
|
|
3893
|
-
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
3894
|
-
}
|
|
3895
|
-
return streamText(
|
|
1631
|
+
return stream(
|
|
3896
1632
|
c2,
|
|
3897
|
-
async (
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
1633
|
+
async (stream2) => {
|
|
1634
|
+
try {
|
|
1635
|
+
const result = await watchWorkflowHandler$1({
|
|
1636
|
+
mastra,
|
|
1637
|
+
workflowId,
|
|
1638
|
+
runId
|
|
3901
1639
|
});
|
|
3902
|
-
|
|
3903
|
-
|
|
1640
|
+
stream2.onAbort(() => {
|
|
1641
|
+
if (!result.locked) {
|
|
1642
|
+
return result.cancel();
|
|
1643
|
+
}
|
|
3904
1644
|
});
|
|
3905
|
-
|
|
1645
|
+
for await (const chunk of result) {
|
|
1646
|
+
await stream2.write(chunk.toString() + "");
|
|
1647
|
+
}
|
|
1648
|
+
} catch (err) {
|
|
1649
|
+
console.log(err);
|
|
1650
|
+
}
|
|
3906
1651
|
},
|
|
3907
|
-
async (err
|
|
1652
|
+
async (err) => {
|
|
3908
1653
|
logger2.error("Error in watch stream: " + err?.message);
|
|
3909
|
-
stream.abort();
|
|
3910
|
-
await stream.close();
|
|
3911
1654
|
}
|
|
3912
1655
|
);
|
|
3913
1656
|
} catch (error) {
|
|
@@ -3918,19 +1661,16 @@ async function resumeAsyncWorkflowHandler(c2) {
|
|
|
3918
1661
|
try {
|
|
3919
1662
|
const mastra = c2.get("mastra");
|
|
3920
1663
|
const workflowId = c2.req.param("workflowId");
|
|
3921
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
3922
1664
|
const runId = c2.req.query("runId");
|
|
3923
1665
|
const { stepId, context } = await c2.req.json();
|
|
3924
1666
|
if (!runId) {
|
|
3925
1667
|
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
3926
1668
|
}
|
|
3927
|
-
const
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
stepId,
|
|
3933
|
-
context
|
|
1669
|
+
const result = await resumeAsyncWorkflowHandler$1({
|
|
1670
|
+
mastra,
|
|
1671
|
+
workflowId,
|
|
1672
|
+
runId,
|
|
1673
|
+
body: { stepId, context }
|
|
3934
1674
|
});
|
|
3935
1675
|
return c2.json(result);
|
|
3936
1676
|
} catch (error) {
|
|
@@ -3941,25 +1681,35 @@ async function resumeWorkflowHandler(c2) {
|
|
|
3941
1681
|
try {
|
|
3942
1682
|
const mastra = c2.get("mastra");
|
|
3943
1683
|
const workflowId = c2.req.param("workflowId");
|
|
3944
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
3945
1684
|
const runId = c2.req.query("runId");
|
|
3946
1685
|
const { stepId, context } = await c2.req.json();
|
|
3947
1686
|
if (!runId) {
|
|
3948
1687
|
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
3949
1688
|
}
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
stepId,
|
|
3956
|
-
context
|
|
1689
|
+
await resumeWorkflowHandler$1({
|
|
1690
|
+
mastra,
|
|
1691
|
+
workflowId,
|
|
1692
|
+
runId,
|
|
1693
|
+
body: { stepId, context }
|
|
3957
1694
|
});
|
|
3958
1695
|
return c2.json({ message: "Workflow run resumed" });
|
|
3959
1696
|
} catch (error) {
|
|
3960
1697
|
return handleError(error, "Error resuming workflow");
|
|
3961
1698
|
}
|
|
3962
1699
|
}
|
|
1700
|
+
async function getWorkflowRunsHandler(c2) {
|
|
1701
|
+
try {
|
|
1702
|
+
const mastra = c2.get("mastra");
|
|
1703
|
+
const workflowId = c2.req.param("workflowId");
|
|
1704
|
+
const workflowRuns = await getWorkflowRunsHandler$1({
|
|
1705
|
+
mastra,
|
|
1706
|
+
workflowId
|
|
1707
|
+
});
|
|
1708
|
+
return c2.json(workflowRuns);
|
|
1709
|
+
} catch (error) {
|
|
1710
|
+
return handleError(error, "Error getting workflow runs");
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
3963
1713
|
|
|
3964
1714
|
// src/server/welcome.ts
|
|
3965
1715
|
var html2 = `
|
|
@@ -4071,6 +1821,7 @@ var html2 = `
|
|
|
4071
1821
|
// src/server/index.ts
|
|
4072
1822
|
async function createHonoServer(mastra, options = {}) {
|
|
4073
1823
|
const app = new Hono();
|
|
1824
|
+
const server = mastra.getServer();
|
|
4074
1825
|
const mastraToolsPaths = process.env.MASTRA_TOOLS_PATH;
|
|
4075
1826
|
const toolImports = mastraToolsPaths ? await Promise.all(
|
|
4076
1827
|
mastraToolsPaths.split(",").map(async (toolPath) => {
|
|
@@ -4085,10 +1836,11 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4085
1836
|
}, {});
|
|
4086
1837
|
app.use(
|
|
4087
1838
|
"*",
|
|
1839
|
+
timeout(server?.timeout ?? 1e3 * 30),
|
|
4088
1840
|
cors({
|
|
4089
1841
|
origin: "*",
|
|
4090
1842
|
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
4091
|
-
allowHeaders: ["Content-Type", "Authorization"],
|
|
1843
|
+
allowHeaders: ["Content-Type", "Authorization", "x-mastra-client-type"],
|
|
4092
1844
|
exposeHeaders: ["Content-Length", "X-Requested-With"],
|
|
4093
1845
|
credentials: false,
|
|
4094
1846
|
maxAge: 3600
|
|
@@ -4108,13 +1860,66 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4108
1860
|
c2.set("mastra", mastra);
|
|
4109
1861
|
c2.set("tools", tools);
|
|
4110
1862
|
c2.set("playground", options.playground === true);
|
|
4111
|
-
|
|
1863
|
+
const requestId = c2.req.header("x-request-id") ?? randomUUID();
|
|
1864
|
+
const span = Telemetry.getActiveSpan();
|
|
1865
|
+
if (span) {
|
|
1866
|
+
span.setAttribute("http.request_id", requestId);
|
|
1867
|
+
span.updateName(`${c2.req.method} ${c2.req.path}`);
|
|
1868
|
+
const newCtx = Telemetry.setBaggage({
|
|
1869
|
+
"http.request_id": requestId
|
|
1870
|
+
});
|
|
1871
|
+
await new Promise((resolve) => {
|
|
1872
|
+
Telemetry.withContext(newCtx, async () => {
|
|
1873
|
+
await next();
|
|
1874
|
+
resolve(true);
|
|
1875
|
+
});
|
|
1876
|
+
});
|
|
1877
|
+
} else {
|
|
1878
|
+
await next();
|
|
1879
|
+
}
|
|
4112
1880
|
});
|
|
4113
1881
|
const bodyLimitOptions = {
|
|
4114
1882
|
maxSize: 4.5 * 1024 * 1024,
|
|
4115
1883
|
// 4.5 MB,
|
|
4116
1884
|
onError: (c2) => c2.json({ error: "Request body too large" }, 413)
|
|
4117
1885
|
};
|
|
1886
|
+
const routes = server?.apiRoutes;
|
|
1887
|
+
if (server?.middleware) {
|
|
1888
|
+
const normalizedMiddlewares = Array.isArray(server.middleware) ? server.middleware : [server.middleware];
|
|
1889
|
+
const middlewares = normalizedMiddlewares.map((middleware2) => {
|
|
1890
|
+
if (typeof middleware2 === "function") {
|
|
1891
|
+
return {
|
|
1892
|
+
path: "*",
|
|
1893
|
+
handler: middleware2
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
return middleware2;
|
|
1897
|
+
});
|
|
1898
|
+
for (const middleware2 of middlewares) {
|
|
1899
|
+
app.use(middleware2.path, middleware2.handler);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
if (routes) {
|
|
1903
|
+
for (const route of routes) {
|
|
1904
|
+
const middlewares = [];
|
|
1905
|
+
if (route.middleware) {
|
|
1906
|
+
middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
|
|
1907
|
+
}
|
|
1908
|
+
if (route.openapi) {
|
|
1909
|
+
middlewares.push(h(route.openapi));
|
|
1910
|
+
}
|
|
1911
|
+
console.log({ path: route.path, middlewares });
|
|
1912
|
+
if (route.method === "GET") {
|
|
1913
|
+
app.get(route.path, ...middlewares, route.handler);
|
|
1914
|
+
} else if (route.method === "POST") {
|
|
1915
|
+
app.post(route.path, ...middlewares, route.handler);
|
|
1916
|
+
} else if (route.method === "PUT") {
|
|
1917
|
+
app.put(route.path, ...middlewares, route.handler);
|
|
1918
|
+
} else if (route.method === "DELETE") {
|
|
1919
|
+
app.delete(route.path, ...middlewares, route.handler);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
4118
1923
|
app.get(
|
|
4119
1924
|
"/api",
|
|
4120
1925
|
h({
|
|
@@ -5236,6 +3041,19 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5236
3041
|
}),
|
|
5237
3042
|
getTelemetryHandler
|
|
5238
3043
|
);
|
|
3044
|
+
app.post(
|
|
3045
|
+
"/api/telemetry",
|
|
3046
|
+
h({
|
|
3047
|
+
description: "Store telemetry",
|
|
3048
|
+
tags: ["telemetry"],
|
|
3049
|
+
responses: {
|
|
3050
|
+
200: {
|
|
3051
|
+
description: "Traces stored"
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
}),
|
|
3055
|
+
storeTelemetryHandler
|
|
3056
|
+
);
|
|
5239
3057
|
app.get(
|
|
5240
3058
|
"/api/workflows",
|
|
5241
3059
|
h({
|
|
@@ -5273,6 +3091,27 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5273
3091
|
}),
|
|
5274
3092
|
getWorkflowByIdHandler
|
|
5275
3093
|
);
|
|
3094
|
+
app.get(
|
|
3095
|
+
"/api/workflows/:workflowId/runs",
|
|
3096
|
+
h({
|
|
3097
|
+
description: "Get all runs for a workflow",
|
|
3098
|
+
tags: ["workflows"],
|
|
3099
|
+
parameters: [
|
|
3100
|
+
{
|
|
3101
|
+
name: "workflowId",
|
|
3102
|
+
in: "path",
|
|
3103
|
+
required: true,
|
|
3104
|
+
schema: { type: "string" }
|
|
3105
|
+
}
|
|
3106
|
+
],
|
|
3107
|
+
responses: {
|
|
3108
|
+
200: {
|
|
3109
|
+
description: "List of workflow runs from storage"
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
}),
|
|
3113
|
+
getWorkflowRunsHandler
|
|
3114
|
+
);
|
|
5276
3115
|
app.post(
|
|
5277
3116
|
"/api/workflows/:workflowId/resume",
|
|
5278
3117
|
h({
|
|
@@ -5312,6 +3151,43 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5312
3151
|
app.post(
|
|
5313
3152
|
"/api/workflows/:workflowId/resumeAsync",
|
|
5314
3153
|
bodyLimit(bodyLimitOptions),
|
|
3154
|
+
h({
|
|
3155
|
+
description: "@deprecated Use /api/workflows/:workflowId/resume-async instead",
|
|
3156
|
+
tags: ["workflows"],
|
|
3157
|
+
parameters: [
|
|
3158
|
+
{
|
|
3159
|
+
name: "workflowId",
|
|
3160
|
+
in: "path",
|
|
3161
|
+
required: true,
|
|
3162
|
+
schema: { type: "string" }
|
|
3163
|
+
},
|
|
3164
|
+
{
|
|
3165
|
+
name: "runId",
|
|
3166
|
+
in: "query",
|
|
3167
|
+
required: true,
|
|
3168
|
+
schema: { type: "string" }
|
|
3169
|
+
}
|
|
3170
|
+
],
|
|
3171
|
+
requestBody: {
|
|
3172
|
+
required: true,
|
|
3173
|
+
content: {
|
|
3174
|
+
"application/json": {
|
|
3175
|
+
schema: {
|
|
3176
|
+
type: "object",
|
|
3177
|
+
properties: {
|
|
3178
|
+
stepId: { type: "string" },
|
|
3179
|
+
context: { type: "object" }
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
}),
|
|
3186
|
+
resumeAsyncWorkflowHandler
|
|
3187
|
+
);
|
|
3188
|
+
app.post(
|
|
3189
|
+
"/api/workflows/:workflowId/resume-async",
|
|
3190
|
+
bodyLimit(bodyLimitOptions),
|
|
5315
3191
|
h({
|
|
5316
3192
|
description: "Resume a suspended workflow step",
|
|
5317
3193
|
tags: ["workflows"],
|
|
@@ -5417,6 +3293,50 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5417
3293
|
}),
|
|
5418
3294
|
startAsyncWorkflowHandler
|
|
5419
3295
|
);
|
|
3296
|
+
app.post(
|
|
3297
|
+
"/api/workflows/:workflowId/start-async",
|
|
3298
|
+
bodyLimit(bodyLimitOptions),
|
|
3299
|
+
h({
|
|
3300
|
+
description: "@deprecated Use /api/workflows/:workflowId/start-async instead",
|
|
3301
|
+
tags: ["workflows"],
|
|
3302
|
+
parameters: [
|
|
3303
|
+
{
|
|
3304
|
+
name: "workflowId",
|
|
3305
|
+
in: "path",
|
|
3306
|
+
required: true,
|
|
3307
|
+
schema: { type: "string" }
|
|
3308
|
+
},
|
|
3309
|
+
{
|
|
3310
|
+
name: "runId",
|
|
3311
|
+
in: "query",
|
|
3312
|
+
required: false,
|
|
3313
|
+
schema: { type: "string" }
|
|
3314
|
+
}
|
|
3315
|
+
],
|
|
3316
|
+
requestBody: {
|
|
3317
|
+
required: true,
|
|
3318
|
+
content: {
|
|
3319
|
+
"application/json": {
|
|
3320
|
+
schema: {
|
|
3321
|
+
type: "object",
|
|
3322
|
+
properties: {
|
|
3323
|
+
input: { type: "object" }
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
},
|
|
3329
|
+
responses: {
|
|
3330
|
+
200: {
|
|
3331
|
+
description: "Workflow execution result"
|
|
3332
|
+
},
|
|
3333
|
+
404: {
|
|
3334
|
+
description: "Workflow not found"
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
}),
|
|
3338
|
+
startAsyncWorkflowHandler
|
|
3339
|
+
);
|
|
5420
3340
|
app.post(
|
|
5421
3341
|
"/api/workflows/:workflowId/start",
|
|
5422
3342
|
h({
|
|
@@ -5436,6 +3356,19 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5436
3356
|
schema: { type: "string" }
|
|
5437
3357
|
}
|
|
5438
3358
|
],
|
|
3359
|
+
requestBody: {
|
|
3360
|
+
required: true,
|
|
3361
|
+
content: {
|
|
3362
|
+
"application/json": {
|
|
3363
|
+
schema: {
|
|
3364
|
+
type: "object",
|
|
3365
|
+
properties: {
|
|
3366
|
+
input: { type: "object" }
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
},
|
|
5439
3372
|
responses: {
|
|
5440
3373
|
200: {
|
|
5441
3374
|
description: "Workflow run started"
|
|
@@ -5872,10 +3805,12 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5872
3805
|
}
|
|
5873
3806
|
async function createNodeServer(mastra, options = {}) {
|
|
5874
3807
|
const app = await createHonoServer(mastra, options);
|
|
3808
|
+
const serverOptions = mastra.getServer();
|
|
3809
|
+
const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
|
|
5875
3810
|
return serve(
|
|
5876
3811
|
{
|
|
5877
3812
|
fetch: app.fetch,
|
|
5878
|
-
port
|
|
3813
|
+
port
|
|
5879
3814
|
},
|
|
5880
3815
|
() => {
|
|
5881
3816
|
const logger2 = mastra.getLogger();
|