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