@mastra/deployer 0.2.6-alpha.1 → 0.2.6-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_tsup-dts-rollup.d.cts +94 -42
- package/dist/_tsup-dts-rollup.d.ts +94 -42
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.js +1 -1
- package/dist/build/bundler.cjs +3 -3
- package/dist/build/bundler.js +1 -1
- package/dist/build/index.cjs +22 -24
- package/dist/build/index.d.cts +3 -4
- package/dist/build/index.d.ts +3 -4
- package/dist/build/index.js +6 -4
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/chunk-2ZPQX6BX.cjs +254 -0
- package/dist/chunk-4AYFLP6G.js +227 -0
- package/dist/chunk-5UBGPRKT.js +185 -0
- package/dist/{chunk-KLVSED7T.js → chunk-74KZVNKH.js} +8 -4
- package/dist/{chunk-OT6UKL2S.cjs → chunk-AE4CVAPK.cjs} +11 -0
- package/dist/{chunk-UTZ3434D.js → chunk-BDTZS3JM.js} +3 -0
- package/dist/chunk-DYQ225MJ.js +115 -0
- package/dist/chunk-I3UVE6EH.cjs +161 -0
- package/dist/{chunk-XEFBJH3T.js → chunk-IKPL4RGG.js} +11 -0
- package/dist/chunk-NCROGJGB.cjs +142 -0
- package/dist/{chunk-NWERLYTR.cjs → chunk-P5SATU7G.cjs} +3 -0
- package/dist/chunk-VFZVVUQE.cjs +198 -0
- package/dist/chunk-WB3T6NKI.js +133 -0
- package/dist/{chunk-NXBTVZHO.cjs → chunk-WFC3CUZ3.cjs} +14 -10
- package/dist/index.cjs +12 -11
- package/dist/index.js +7 -6
- package/dist/server/index.cjs +621 -2828
- package/dist/server/index.js +534 -2741
- package/dist/services/index.cjs +19 -0
- package/dist/services/index.d.cts +3 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +2 -0
- package/dist/templates/instrumentation-template.js +25 -19
- package/package.json +15 -4
- package/dist/chunk-7GYBZLVN.cjs +0 -286
- package/dist/chunk-KFOGAPGX.cjs +0 -433
- package/dist/chunk-PUX2FDGX.js +0 -252
- package/dist/chunk-ZAXXMFXX.js +0 -399
package/dist/server/index.cjs
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
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');
|
|
19
|
+
var timeout = require('hono/timeout');
|
|
18
20
|
var httpException = require('hono/http-exception');
|
|
19
|
-
var
|
|
21
|
+
var agents = require('@mastra/server/handlers/agents');
|
|
22
|
+
var logs = require('@mastra/server/handlers/logs');
|
|
23
|
+
var memory = require('@mastra/server/handlers/memory');
|
|
24
|
+
var network = require('@mastra/server/handlers/network');
|
|
20
25
|
var agent = require('@mastra/core/agent');
|
|
21
|
-
var
|
|
22
|
-
var
|
|
26
|
+
var zod = require('zod');
|
|
27
|
+
var telemetry = require('@mastra/server/handlers/telemetry');
|
|
28
|
+
var tools = require('@mastra/server/handlers/tools');
|
|
29
|
+
var vector = require('@mastra/server/handlers/vector');
|
|
30
|
+
var voice = require('@mastra/server/handlers/voice');
|
|
31
|
+
var workflows = require('@mastra/server/handlers/workflows');
|
|
23
32
|
var streaming = require('hono/streaming');
|
|
24
33
|
|
|
25
34
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -162,14 +171,14 @@ var newRequest = (incoming, defaultHostname) => {
|
|
|
162
171
|
req[urlKey] = url.href;
|
|
163
172
|
return req;
|
|
164
173
|
};
|
|
165
|
-
function writeFromReadableStream(
|
|
166
|
-
if (
|
|
174
|
+
function writeFromReadableStream(stream2, writable) {
|
|
175
|
+
if (stream2.locked) {
|
|
167
176
|
throw new TypeError("ReadableStream is locked.");
|
|
168
177
|
} else if (writable.destroyed) {
|
|
169
|
-
|
|
178
|
+
stream2.cancel();
|
|
170
179
|
return;
|
|
171
180
|
}
|
|
172
|
-
const reader =
|
|
181
|
+
const reader = stream2.getReader();
|
|
173
182
|
writable.on("close", cancel);
|
|
174
183
|
writable.on("error", cancel);
|
|
175
184
|
reader.read().then(flow, cancel);
|
|
@@ -177,11 +186,11 @@ function writeFromReadableStream(stream, writable) {
|
|
|
177
186
|
writable.off("close", cancel);
|
|
178
187
|
writable.off("error", cancel);
|
|
179
188
|
});
|
|
180
|
-
function cancel(
|
|
181
|
-
reader.cancel(
|
|
189
|
+
function cancel(error) {
|
|
190
|
+
reader.cancel(error).catch(() => {
|
|
182
191
|
});
|
|
183
|
-
if (
|
|
184
|
-
writable.destroy(
|
|
192
|
+
if (error) {
|
|
193
|
+
writable.destroy(error);
|
|
185
194
|
}
|
|
186
195
|
}
|
|
187
196
|
function onDrain() {
|
|
@@ -367,7 +376,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
367
376
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
368
377
|
const internalBody = getInternalBody(res);
|
|
369
378
|
if (internalBody) {
|
|
370
|
-
const { length, source, stream } = internalBody;
|
|
379
|
+
const { length, source, stream: stream2 } = internalBody;
|
|
371
380
|
if (source instanceof Uint8Array && source.byteLength !== length) ; else {
|
|
372
381
|
if (length) {
|
|
373
382
|
resHeaderRecord["content-length"] = length;
|
|
@@ -378,7 +387,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
|
378
387
|
} else if (source instanceof Blob) {
|
|
379
388
|
outgoing.end(new Uint8Array(await source.arrayBuffer()));
|
|
380
389
|
} else {
|
|
381
|
-
await writeFromReadableStream(
|
|
390
|
+
await writeFromReadableStream(stream2, outgoing);
|
|
382
391
|
}
|
|
383
392
|
return;
|
|
384
393
|
}
|
|
@@ -469,7 +478,7 @@ var createAdaptorServer = (options) => {
|
|
|
469
478
|
};
|
|
470
479
|
var serve = (options, listeningListener) => {
|
|
471
480
|
const server = createAdaptorServer(options);
|
|
472
|
-
server.listen(options?.port, options.hostname, () => {
|
|
481
|
+
server.listen(options?.port ?? 3e3, options.hostname, () => {
|
|
473
482
|
const serverInfo = server.address();
|
|
474
483
|
listeningListener && listeningListener(serverInfo);
|
|
475
484
|
});
|
|
@@ -482,18 +491,18 @@ var ENCODINGS = {
|
|
|
482
491
|
gzip: ".gz"
|
|
483
492
|
};
|
|
484
493
|
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
485
|
-
var createStreamBody = (
|
|
494
|
+
var createStreamBody = (stream2) => {
|
|
486
495
|
const body = new ReadableStream({
|
|
487
496
|
start(controller) {
|
|
488
|
-
|
|
497
|
+
stream2.on("data", (chunk) => {
|
|
489
498
|
controller.enqueue(chunk);
|
|
490
499
|
});
|
|
491
|
-
|
|
500
|
+
stream2.on("end", () => {
|
|
492
501
|
controller.close();
|
|
493
502
|
});
|
|
494
503
|
},
|
|
495
504
|
cancel() {
|
|
496
|
-
|
|
505
|
+
stream2.destroy();
|
|
497
506
|
}
|
|
498
507
|
});
|
|
499
508
|
return body;
|
|
@@ -589,10 +598,10 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
589
598
|
end = size - 1;
|
|
590
599
|
}
|
|
591
600
|
const chunksize = end - start + 1;
|
|
592
|
-
const
|
|
601
|
+
const stream2 = fs.createReadStream(path, { start, end });
|
|
593
602
|
c2.header("Content-Length", chunksize.toString());
|
|
594
603
|
c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
595
|
-
return c2.body(createStreamBody(
|
|
604
|
+
return c2.body(createStreamBody(stream2), 206);
|
|
596
605
|
};
|
|
597
606
|
};
|
|
598
607
|
var RENDER_TYPE = {
|
|
@@ -839,2520 +848,352 @@ async function x(e2, t2, s3 = {}) {
|
|
|
839
848
|
}
|
|
840
849
|
return { docs: o2, components: n2 };
|
|
841
850
|
}
|
|
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);
|
|
851
|
+
function handleError(error, defaultMessage) {
|
|
852
|
+
const apiError = error;
|
|
853
|
+
throw new httpException.HTTPException(apiError.status || 500, {
|
|
854
|
+
message: apiError.message || defaultMessage
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
function errorHandler(err, c2) {
|
|
858
|
+
if (err instanceof httpException.HTTPException) {
|
|
859
|
+
return c2.json({ error: err.message }, err.status);
|
|
909
860
|
}
|
|
910
|
-
|
|
861
|
+
console.error(err);
|
|
862
|
+
return c2.json({ error: "Internal Server Error" }, 500);
|
|
863
|
+
}
|
|
911
864
|
|
|
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;
|
|
865
|
+
// src/server/handlers/agents.ts
|
|
866
|
+
async function getAgentsHandler(c2) {
|
|
867
|
+
const serializedAgents = await agents.getAgentsHandler({ mastra: c2.get("mastra") });
|
|
868
|
+
return c2.json(serializedAgents);
|
|
924
869
|
}
|
|
925
|
-
function
|
|
926
|
-
const
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
if (predicate(value)) {
|
|
934
|
-
return value;
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
return void 0;
|
|
870
|
+
async function getAgentByIdHandler(c2) {
|
|
871
|
+
const mastra = c2.get("mastra");
|
|
872
|
+
const agentId = c2.req.param("agentId");
|
|
873
|
+
const result = await agents.getAgentByIdHandler({
|
|
874
|
+
mastra,
|
|
875
|
+
agentId
|
|
876
|
+
});
|
|
877
|
+
return c2.json(result);
|
|
938
878
|
}
|
|
939
|
-
function
|
|
940
|
-
|
|
879
|
+
async function getEvalsByAgentIdHandler(c2) {
|
|
880
|
+
const mastra = c2.get("mastra");
|
|
881
|
+
const agentId = c2.req.param("agentId");
|
|
882
|
+
const result = await agents.getEvalsByAgentIdHandler({
|
|
883
|
+
mastra,
|
|
884
|
+
agentId
|
|
885
|
+
});
|
|
886
|
+
return c2.json(result);
|
|
941
887
|
}
|
|
942
|
-
function
|
|
943
|
-
|
|
888
|
+
async function getLiveEvalsByAgentIdHandler(c2) {
|
|
889
|
+
const mastra = c2.get("mastra");
|
|
890
|
+
const agentId = c2.req.param("agentId");
|
|
891
|
+
const result = await agents.getLiveEvalsByAgentIdHandler({
|
|
892
|
+
mastra,
|
|
893
|
+
agentId
|
|
894
|
+
});
|
|
895
|
+
return c2.json(result);
|
|
944
896
|
}
|
|
945
|
-
function
|
|
946
|
-
|
|
947
|
-
const
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
897
|
+
async function generateHandler(c2) {
|
|
898
|
+
try {
|
|
899
|
+
const mastra = c2.get("mastra");
|
|
900
|
+
const agentId = c2.req.param("agentId");
|
|
901
|
+
const body = await c2.req.json();
|
|
902
|
+
const result = await agents.generateHandler({
|
|
903
|
+
mastra,
|
|
904
|
+
agentId,
|
|
905
|
+
body
|
|
906
|
+
});
|
|
907
|
+
return c2.json(result);
|
|
908
|
+
} catch (error) {
|
|
909
|
+
return handleError(error, "Error generating from agent");
|
|
951
910
|
}
|
|
952
|
-
return void 0;
|
|
953
911
|
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
return
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
return this.transfomers[name];
|
|
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;
|
|
912
|
+
async function streamGenerateHandler(c2) {
|
|
913
|
+
try {
|
|
914
|
+
const mastra = c2.get("mastra");
|
|
915
|
+
const agentId = c2.req.param("agentId");
|
|
916
|
+
const body = await c2.req.json();
|
|
917
|
+
const streamResponse = await agents.streamGenerateHandler({
|
|
918
|
+
mastra,
|
|
919
|
+
agentId,
|
|
920
|
+
body
|
|
921
|
+
});
|
|
922
|
+
return streamResponse;
|
|
923
|
+
} catch (error) {
|
|
924
|
+
return handleError(error, "Error streaming from agent");
|
|
1023
925
|
}
|
|
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
926
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
if (
|
|
1042
|
-
return
|
|
927
|
+
async function setAgentInstructionsHandler(c2) {
|
|
928
|
+
try {
|
|
929
|
+
const isPlayground = c2.get("playground") === true;
|
|
930
|
+
if (!isPlayground) {
|
|
931
|
+
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
1043
932
|
}
|
|
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";
|
|
933
|
+
const agentId = c2.req.param("agentId");
|
|
934
|
+
const { instructions } = await c2.req.json();
|
|
935
|
+
if (!agentId || !instructions) {
|
|
936
|
+
return c2.json({ error: "Missing required fields" }, 400);
|
|
1083
937
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
return "
|
|
938
|
+
const mastra = c2.get("mastra");
|
|
939
|
+
const agent = mastra.getAgent(agentId);
|
|
940
|
+
if (!agent) {
|
|
941
|
+
return c2.json({ error: "Agent not found" }, 404);
|
|
1088
942
|
}
|
|
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;
|
|
943
|
+
agent.__updateInstructions(instructions);
|
|
944
|
+
return c2.json(
|
|
945
|
+
{
|
|
946
|
+
instructions
|
|
947
|
+
},
|
|
948
|
+
200
|
|
949
|
+
);
|
|
950
|
+
} catch (error) {
|
|
951
|
+
return handleError(error, "Error setting agent instructions");
|
|
1144
952
|
}
|
|
1145
|
-
return false;
|
|
1146
953
|
}
|
|
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
954
|
|
|
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);
|
|
955
|
+
// src/server/handlers/client.ts
|
|
956
|
+
var clients = /* @__PURE__ */ new Set();
|
|
957
|
+
function handleClientsRefresh(c2) {
|
|
958
|
+
const stream2 = new ReadableStream({
|
|
959
|
+
start(controller) {
|
|
960
|
+
clients.add(controller);
|
|
961
|
+
controller.enqueue("data: connected\n\n");
|
|
962
|
+
c2.req.raw.signal.addEventListener("abort", () => {
|
|
963
|
+
clients.delete(controller);
|
|
964
|
+
});
|
|
1319
965
|
}
|
|
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
|
-
}
|
|
966
|
+
});
|
|
967
|
+
return new Response(stream2, {
|
|
968
|
+
headers: {
|
|
969
|
+
"Content-Type": "text/event-stream",
|
|
970
|
+
"Cache-Control": "no-cache",
|
|
971
|
+
Connection: "keep-alive",
|
|
972
|
+
"Access-Control-Allow-Origin": "*"
|
|
1338
973
|
}
|
|
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);
|
|
974
|
+
});
|
|
1359
975
|
}
|
|
1360
|
-
function
|
|
1361
|
-
|
|
1362
|
-
|
|
976
|
+
function handleTriggerClientsRefresh(c2) {
|
|
977
|
+
clients.forEach((controller) => {
|
|
978
|
+
try {
|
|
979
|
+
controller.enqueue("data: refresh\n\n");
|
|
980
|
+
} catch {
|
|
981
|
+
clients.delete(controller);
|
|
982
|
+
}
|
|
1363
983
|
});
|
|
1364
|
-
return
|
|
984
|
+
return c2.json({ success: true, clients: clients.size });
|
|
1365
985
|
}
|
|
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);
|
|
986
|
+
async function getLogsHandler(c2) {
|
|
987
|
+
try {
|
|
988
|
+
const mastra = c2.get("mastra");
|
|
989
|
+
const transportId = c2.req.query("transportId");
|
|
990
|
+
const logs$1 = await logs.getLogsHandler({
|
|
991
|
+
mastra,
|
|
992
|
+
transportId
|
|
1377
993
|
});
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
} else {
|
|
1382
|
-
forEach(annotations, apply);
|
|
994
|
+
return c2.json(logs$1);
|
|
995
|
+
} catch (error) {
|
|
996
|
+
return handleError(error, "Error getting logs");
|
|
1383
997
|
}
|
|
1384
|
-
return plain;
|
|
1385
998
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
999
|
+
async function getLogsByRunIdHandler(c2) {
|
|
1000
|
+
try {
|
|
1001
|
+
const mastra = c2.get("mastra");
|
|
1002
|
+
const runId = c2.req.param("runId");
|
|
1003
|
+
const transportId = c2.req.query("transportId");
|
|
1004
|
+
const logs$1 = await logs.getLogsByRunIdHandler({
|
|
1005
|
+
mastra,
|
|
1006
|
+
runId,
|
|
1007
|
+
transportId
|
|
1008
|
+
});
|
|
1009
|
+
return c2.json(logs$1);
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
return handleError(error, "Error getting logs by run ID");
|
|
1393
1012
|
}
|
|
1394
1013
|
}
|
|
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;
|
|
1014
|
+
async function getLogTransports(c2) {
|
|
1015
|
+
try {
|
|
1016
|
+
const mastra = c2.get("mastra");
|
|
1017
|
+
const result = await logs.getLogTransports({
|
|
1018
|
+
mastra
|
|
1019
|
+
});
|
|
1020
|
+
return c2.json(result);
|
|
1021
|
+
} catch (error) {
|
|
1022
|
+
return handleError(error, "Error getting log Transports");
|
|
1420
1023
|
}
|
|
1421
1024
|
}
|
|
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);
|
|
1025
|
+
async function getMemoryStatusHandler(c2) {
|
|
1026
|
+
try {
|
|
1027
|
+
const mastra = c2.get("mastra");
|
|
1028
|
+
const agentId = c2.req.query("agentId");
|
|
1029
|
+
const result = await memory.getMemoryStatusHandler({
|
|
1030
|
+
mastra,
|
|
1031
|
+
agentId
|
|
1032
|
+
});
|
|
1033
|
+
return c2.json(result);
|
|
1034
|
+
} catch (error) {
|
|
1035
|
+
return handleError(error, "Error getting memory status");
|
|
1478
1036
|
}
|
|
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
1037
|
}
|
|
1486
|
-
function
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
// ../../node_modules/.pnpm/copy-anything@3.0.5/node_modules/copy-anything/dist/index.js
|
|
1497
|
-
function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
|
|
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
|
|
1038
|
+
async function getThreadsHandler(c2) {
|
|
1039
|
+
try {
|
|
1040
|
+
const mastra = c2.get("mastra");
|
|
1041
|
+
const agentId = c2.req.query("agentId");
|
|
1042
|
+
const resourceId = c2.req.query("resourceid");
|
|
1043
|
+
const result = await memory.getThreadsHandler({
|
|
1044
|
+
mastra,
|
|
1045
|
+
agentId,
|
|
1046
|
+
resourceId
|
|
1507
1047
|
});
|
|
1048
|
+
return c2.json(result);
|
|
1049
|
+
} catch (error) {
|
|
1050
|
+
return handleError(error, "Error getting threads");
|
|
1508
1051
|
}
|
|
1509
1052
|
}
|
|
1510
|
-
function
|
|
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) {
|
|
1053
|
+
async function getThreadByIdHandler(c2) {
|
|
2941
1054
|
try {
|
|
2942
1055
|
const mastra = c2.get("mastra");
|
|
2943
|
-
const agentId = c2.req.
|
|
2944
|
-
const
|
|
2945
|
-
const
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
instructions: agent.instructions,
|
|
2950
|
-
evals
|
|
1056
|
+
const agentId = c2.req.query("agentId");
|
|
1057
|
+
const threadId = c2.req.param("threadId");
|
|
1058
|
+
const result = await memory.getThreadByIdHandler({
|
|
1059
|
+
mastra,
|
|
1060
|
+
agentId,
|
|
1061
|
+
threadId
|
|
2951
1062
|
});
|
|
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
1063
|
return c2.json(result);
|
|
2969
|
-
} catch (
|
|
2970
|
-
return handleError(
|
|
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");
|
|
1064
|
+
} catch (error) {
|
|
1065
|
+
return handleError(error, "Error getting thread");
|
|
3087
1066
|
}
|
|
3088
1067
|
}
|
|
3089
|
-
async function
|
|
1068
|
+
async function saveMessagesHandler(c2) {
|
|
3090
1069
|
try {
|
|
3091
1070
|
const mastra = c2.get("mastra");
|
|
3092
|
-
const
|
|
3093
|
-
const
|
|
3094
|
-
|
|
3095
|
-
|
|
1071
|
+
const agentId = c2.req.query("agentId");
|
|
1072
|
+
const body = await c2.req.json();
|
|
1073
|
+
const result = await memory.saveMessagesHandler({
|
|
1074
|
+
mastra,
|
|
1075
|
+
agentId,
|
|
1076
|
+
body
|
|
3096
1077
|
});
|
|
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");
|
|
3136
|
-
}
|
|
3137
|
-
}
|
|
3138
|
-
async function getThreadByIdHandler(c2) {
|
|
3139
|
-
try {
|
|
3140
|
-
const memory = getMemoryFromContext(c2);
|
|
3141
|
-
const threadId = c2.req.param("threadId");
|
|
3142
|
-
if (!memory) {
|
|
3143
|
-
throw new httpException.HTTPException(400, { message: "Memory is not initialized" });
|
|
3144
|
-
}
|
|
3145
|
-
const thread = await memory.getThreadById({ threadId });
|
|
3146
|
-
if (!thread) {
|
|
3147
|
-
throw new httpException.HTTPException(404, { message: "Thread not found" });
|
|
3148
|
-
}
|
|
3149
|
-
return c2.json(thread);
|
|
3150
|
-
} catch (error2) {
|
|
3151
|
-
return handleError(error2, "Error getting thread");
|
|
3152
|
-
}
|
|
3153
|
-
}
|
|
3154
|
-
async function saveMessagesHandler(c2) {
|
|
3155
|
-
try {
|
|
3156
|
-
const memory = getMemoryFromContext(c2);
|
|
3157
|
-
const { messages } = await c2.req.json();
|
|
3158
|
-
if (!memory) {
|
|
3159
|
-
throw new httpException.HTTPException(400, { message: "Memory is not initialized" });
|
|
3160
|
-
}
|
|
3161
|
-
validateBody({ messages });
|
|
3162
|
-
if (!Array.isArray(messages)) {
|
|
3163
|
-
throw new httpException.HTTPException(400, { message: "Messages should be an array" });
|
|
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: {} });
|
|
3171
1078
|
return c2.json(result);
|
|
3172
|
-
} catch (
|
|
3173
|
-
return handleError(
|
|
1079
|
+
} catch (error) {
|
|
1080
|
+
return handleError(error, "Error saving messages");
|
|
3174
1081
|
}
|
|
3175
1082
|
}
|
|
3176
1083
|
async function createThreadHandler(c2) {
|
|
3177
1084
|
try {
|
|
3178
|
-
const
|
|
3179
|
-
const
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
1085
|
+
const mastra = c2.get("mastra");
|
|
1086
|
+
const agentId = c2.req.query("agentId");
|
|
1087
|
+
const body = await c2.req.json();
|
|
1088
|
+
const result = await memory.createThreadHandler({
|
|
1089
|
+
mastra,
|
|
1090
|
+
agentId,
|
|
1091
|
+
body
|
|
1092
|
+
});
|
|
3185
1093
|
return c2.json(result);
|
|
3186
|
-
} catch (
|
|
3187
|
-
return handleError(
|
|
1094
|
+
} catch (error) {
|
|
1095
|
+
return handleError(error, "Error saving thread to memory");
|
|
3188
1096
|
}
|
|
3189
1097
|
}
|
|
3190
1098
|
async function updateThreadHandler(c2) {
|
|
3191
1099
|
try {
|
|
3192
|
-
const
|
|
1100
|
+
const mastra = c2.get("mastra");
|
|
1101
|
+
const agentId = c2.req.query("agentId");
|
|
3193
1102
|
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 });
|
|
1103
|
+
const body = await c2.req.json();
|
|
1104
|
+
const result = await memory.updateThreadHandler({
|
|
1105
|
+
mastra,
|
|
1106
|
+
agentId,
|
|
1107
|
+
threadId,
|
|
1108
|
+
body
|
|
1109
|
+
});
|
|
3212
1110
|
return c2.json(result);
|
|
3213
|
-
} catch (
|
|
3214
|
-
return handleError(
|
|
1111
|
+
} catch (error) {
|
|
1112
|
+
return handleError(error, "Error updating thread");
|
|
3215
1113
|
}
|
|
3216
1114
|
}
|
|
3217
1115
|
async function deleteThreadHandler(c2) {
|
|
3218
1116
|
try {
|
|
3219
|
-
const
|
|
1117
|
+
const mastra = c2.get("mastra");
|
|
1118
|
+
const agentId = c2.req.query("agentId");
|
|
3220
1119
|
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");
|
|
1120
|
+
const result = await memory.deleteThreadHandler({
|
|
1121
|
+
mastra,
|
|
1122
|
+
agentId,
|
|
1123
|
+
threadId
|
|
1124
|
+
});
|
|
1125
|
+
return c2.json(result);
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
return handleError(error, "Error deleting thread");
|
|
3232
1128
|
}
|
|
3233
1129
|
}
|
|
3234
1130
|
async function getMessagesHandler(c2) {
|
|
3235
1131
|
try {
|
|
3236
|
-
const
|
|
1132
|
+
const mastra = c2.get("mastra");
|
|
1133
|
+
const agentId = c2.req.query("agentId");
|
|
3237
1134
|
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 });
|
|
1135
|
+
const result = await memory.getMessagesHandler({
|
|
1136
|
+
mastra,
|
|
1137
|
+
agentId,
|
|
1138
|
+
threadId
|
|
1139
|
+
});
|
|
3246
1140
|
return c2.json(result);
|
|
3247
|
-
} catch (
|
|
3248
|
-
return handleError(
|
|
1141
|
+
} catch (error) {
|
|
1142
|
+
return handleError(error, "Error getting messages");
|
|
3249
1143
|
}
|
|
3250
1144
|
}
|
|
3251
1145
|
async function getNetworksHandler(c2) {
|
|
3252
1146
|
try {
|
|
3253
1147
|
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
|
-
};
|
|
1148
|
+
const networks = await network.getNetworksHandler({
|
|
1149
|
+
mastra
|
|
3272
1150
|
});
|
|
3273
|
-
return c2.json(
|
|
3274
|
-
} catch (
|
|
3275
|
-
return handleError(
|
|
1151
|
+
return c2.json(networks);
|
|
1152
|
+
} catch (error) {
|
|
1153
|
+
return handleError(error, "Error getting networks");
|
|
3276
1154
|
}
|
|
3277
1155
|
}
|
|
3278
1156
|
async function getNetworkByIdHandler(c2) {
|
|
3279
1157
|
try {
|
|
3280
1158
|
const mastra = c2.get("mastra");
|
|
3281
1159
|
const networkId = c2.req.param("networkId");
|
|
3282
|
-
const
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
return network2.formatAgentId(routingAgent2.name) === networkId;
|
|
1160
|
+
const network$1 = await network.getNetworkByIdHandler({
|
|
1161
|
+
mastra,
|
|
1162
|
+
networkId
|
|
3286
1163
|
});
|
|
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");
|
|
1164
|
+
return c2.json(network$1);
|
|
1165
|
+
} catch (error) {
|
|
1166
|
+
return handleError(error, "Error getting network by ID");
|
|
3309
1167
|
}
|
|
3310
1168
|
}
|
|
3311
1169
|
async function generateHandler2(c2) {
|
|
3312
1170
|
try {
|
|
3313
1171
|
const mastra = c2.get("mastra");
|
|
3314
1172
|
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 });
|
|
1173
|
+
const body = await c2.req.json();
|
|
1174
|
+
const result = await network.generateHandler({
|
|
1175
|
+
mastra,
|
|
1176
|
+
networkId,
|
|
1177
|
+
body
|
|
1178
|
+
});
|
|
3323
1179
|
return c2.json(result);
|
|
3324
|
-
} catch (
|
|
3325
|
-
return handleError(
|
|
1180
|
+
} catch (error) {
|
|
1181
|
+
return handleError(error, "Error generating from network");
|
|
3326
1182
|
}
|
|
3327
1183
|
}
|
|
3328
1184
|
async function streamGenerateHandler2(c2) {
|
|
3329
1185
|
try {
|
|
3330
1186
|
const mastra = c2.get("mastra");
|
|
3331
1187
|
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
|
-
}
|
|
1188
|
+
const body = await c2.req.json();
|
|
1189
|
+
const streamResponse = await network.streamGenerateHandler({
|
|
1190
|
+
mastra,
|
|
1191
|
+
networkId,
|
|
1192
|
+
body
|
|
3352
1193
|
});
|
|
3353
1194
|
return streamResponse;
|
|
3354
|
-
} catch (
|
|
3355
|
-
return handleError(
|
|
1195
|
+
} catch (error) {
|
|
1196
|
+
return handleError(error, "Error streaming from network");
|
|
3356
1197
|
}
|
|
3357
1198
|
}
|
|
3358
1199
|
async function generateSystemPromptHandler(c2) {
|
|
@@ -3373,8 +1214,8 @@ async function generateSystemPromptHandler(c2) {
|
|
|
3373
1214
|
}
|
|
3374
1215
|
let evalSummary = "";
|
|
3375
1216
|
try {
|
|
3376
|
-
const testEvals = await mastra.storage?.
|
|
3377
|
-
const liveEvals = await mastra.storage?.
|
|
1217
|
+
const testEvals = await mastra.storage?.__getEvalsByAgentName?.(agent$1.name, "test") || [];
|
|
1218
|
+
const liveEvals = await mastra.storage?.__getEvalsByAgentName?.(agent$1.name, "live") || [];
|
|
3378
1219
|
const evalsMapped = [...testEvals, ...liveEvals].filter(
|
|
3379
1220
|
({ instructions: evalInstructions }) => evalInstructions === instructions
|
|
3380
1221
|
);
|
|
@@ -3388,8 +1229,8 @@ async function generateSystemPromptHandler(c2) {
|
|
|
3388
1229
|
|
|
3389
1230
|
`
|
|
3390
1231
|
).join("");
|
|
3391
|
-
} catch (
|
|
3392
|
-
mastra.getLogger().error(`Error fetching evals`, { error
|
|
1232
|
+
} catch (error) {
|
|
1233
|
+
mastra.getLogger().error(`Error fetching evals`, { error });
|
|
3393
1234
|
}
|
|
3394
1235
|
const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
|
|
3395
1236
|
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 +1301,8 @@ ${evalSummary}` : ""}
|
|
|
3460
1301
|
}
|
|
3461
1302
|
);
|
|
3462
1303
|
return c2.json(result?.object || {});
|
|
3463
|
-
} catch (
|
|
3464
|
-
return handleError(
|
|
1304
|
+
} catch (error) {
|
|
1305
|
+
return handleError(error, "Error generating system prompt");
|
|
3465
1306
|
}
|
|
3466
1307
|
}
|
|
3467
1308
|
|
|
@@ -3472,189 +1313,68 @@ async function rootHandler(c2) {
|
|
|
3472
1313
|
async function getTelemetryHandler(c2) {
|
|
3473
1314
|
try {
|
|
3474
1315
|
const mastra = c2.get("mastra");
|
|
3475
|
-
const telemetry = mastra.getTelemetry();
|
|
3476
|
-
const storage = mastra.getStorage();
|
|
3477
1316
|
const { name, scope, page, perPage } = c2.req.query();
|
|
3478
1317
|
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
|
|
1318
|
+
const traces = await telemetry.getTelemetryHandler({
|
|
1319
|
+
mastra,
|
|
1320
|
+
body: { name, scope, page: Number(page ?? 0), perPage: Number(perPage ?? 100), attribute }
|
|
3497
1321
|
});
|
|
3498
1322
|
return c2.json({ traces });
|
|
3499
|
-
} catch (
|
|
3500
|
-
return handleError(
|
|
1323
|
+
} catch (error) {
|
|
1324
|
+
return handleError(error, "Error getting telemetry traces");
|
|
3501
1325
|
}
|
|
3502
1326
|
}
|
|
3503
1327
|
async function storeTelemetryHandler(c2) {
|
|
3504
1328
|
try {
|
|
3505
1329
|
const body = await c2.req.json();
|
|
3506
1330
|
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
|
-
);
|
|
1331
|
+
const result = await telemetry.storeTelemetryHandler({ mastra, body });
|
|
1332
|
+
if (result.status === "error") {
|
|
1333
|
+
return c2.json(result, 500);
|
|
1334
|
+
}
|
|
1335
|
+
return c2.json(result, 200);
|
|
1336
|
+
} catch (error) {
|
|
1337
|
+
return handleError(error, "Error storing telemetry traces");
|
|
3590
1338
|
}
|
|
3591
1339
|
}
|
|
3592
1340
|
async function getToolsHandler(c2) {
|
|
3593
1341
|
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");
|
|
1342
|
+
const tools$1 = c2.get("tools");
|
|
1343
|
+
const result = await tools.getToolsHandler({
|
|
1344
|
+
tools: tools$1
|
|
1345
|
+
});
|
|
1346
|
+
return c2.json(result);
|
|
1347
|
+
} catch (error) {
|
|
1348
|
+
return handleError(error, "Error getting tools");
|
|
3613
1349
|
}
|
|
3614
1350
|
}
|
|
3615
1351
|
async function getToolByIdHandler(c2) {
|
|
3616
1352
|
try {
|
|
3617
|
-
const tools = c2.get("tools");
|
|
1353
|
+
const tools$1 = c2.get("tools");
|
|
3618
1354
|
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");
|
|
1355
|
+
const result = await tools.getToolByIdHandler({
|
|
1356
|
+
tools: tools$1,
|
|
1357
|
+
toolId
|
|
1358
|
+
});
|
|
1359
|
+
return c2.json(result);
|
|
1360
|
+
} catch (error) {
|
|
1361
|
+
return handleError(error, "Error getting tool");
|
|
3631
1362
|
}
|
|
3632
1363
|
}
|
|
3633
|
-
function executeToolHandler(tools) {
|
|
1364
|
+
function executeToolHandler(tools$1) {
|
|
3634
1365
|
return async (c2) => {
|
|
3635
1366
|
try {
|
|
1367
|
+
const mastra = c2.get("mastra");
|
|
3636
1368
|
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
1369
|
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,
|
|
1370
|
+
const result = await tools.executeToolHandler(tools$1)({
|
|
3652
1371
|
mastra,
|
|
3653
|
-
|
|
1372
|
+
toolId,
|
|
1373
|
+
data
|
|
3654
1374
|
});
|
|
3655
1375
|
return c2.json(result);
|
|
3656
|
-
} catch (
|
|
3657
|
-
return handleError(
|
|
1376
|
+
} catch (error) {
|
|
1377
|
+
return handleError(error, "Error executing tool");
|
|
3658
1378
|
}
|
|
3659
1379
|
};
|
|
3660
1380
|
}
|
|
@@ -3663,175 +1383,150 @@ async function executeAgentToolHandler(c2) {
|
|
|
3663
1383
|
const mastra = c2.get("mastra");
|
|
3664
1384
|
const agentId = c2.req.param("agentId");
|
|
3665
1385
|
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
1386
|
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,
|
|
1387
|
+
const result = await tools.executeAgentToolHandler({
|
|
3681
1388
|
mastra,
|
|
3682
|
-
|
|
1389
|
+
agentId,
|
|
1390
|
+
toolId,
|
|
1391
|
+
data
|
|
3683
1392
|
});
|
|
3684
1393
|
return c2.json(result);
|
|
3685
|
-
} catch (
|
|
3686
|
-
return handleError(
|
|
1394
|
+
} catch (error) {
|
|
1395
|
+
return handleError(error, "Error executing tool");
|
|
3687
1396
|
}
|
|
3688
1397
|
}
|
|
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
1398
|
async function upsertVectors(c2) {
|
|
3697
1399
|
try {
|
|
1400
|
+
const mastra = c2.get("mastra");
|
|
3698
1401
|
const vectorName = c2.req.param("vectorName");
|
|
3699
|
-
const
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
1402
|
+
const body = await c2.req.json();
|
|
1403
|
+
const result = await vector.upsertVectors({
|
|
1404
|
+
mastra,
|
|
1405
|
+
vectorName,
|
|
1406
|
+
index: body
|
|
1407
|
+
});
|
|
3705
1408
|
return c2.json({ ids: result });
|
|
3706
|
-
} catch (
|
|
3707
|
-
return handleError(
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
return handleError(error, "Error upserting vectors");
|
|
3708
1411
|
}
|
|
3709
1412
|
}
|
|
3710
1413
|
async function createIndex(c2) {
|
|
3711
1414
|
try {
|
|
1415
|
+
const mastra = c2.get("mastra");
|
|
3712
1416
|
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 });
|
|
1417
|
+
const body = await c2.req.json();
|
|
1418
|
+
await vector.createIndex({
|
|
1419
|
+
mastra,
|
|
1420
|
+
vectorName,
|
|
1421
|
+
index: body
|
|
1422
|
+
});
|
|
3724
1423
|
return c2.json({ success: true });
|
|
3725
|
-
} catch (
|
|
3726
|
-
return handleError(
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
return handleError(error, "Error creating index");
|
|
3727
1426
|
}
|
|
3728
1427
|
}
|
|
3729
1428
|
async function queryVectors(c2) {
|
|
3730
1429
|
try {
|
|
1430
|
+
const mastra = c2.get("mastra");
|
|
3731
1431
|
const vectorName = c2.req.param("vectorName");
|
|
3732
1432
|
const { indexName, queryVector, topK = 10, filter, includeVector = false } = await c2.req.json();
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
1433
|
+
const results = await vector.queryVectors({
|
|
1434
|
+
mastra,
|
|
1435
|
+
vectorName,
|
|
1436
|
+
query: { indexName, queryVector, topK, filter, includeVector }
|
|
1437
|
+
});
|
|
3738
1438
|
return c2.json({ results });
|
|
3739
|
-
} catch (
|
|
3740
|
-
return handleError(
|
|
1439
|
+
} catch (error) {
|
|
1440
|
+
return handleError(error, "Error querying vectors");
|
|
3741
1441
|
}
|
|
3742
1442
|
}
|
|
3743
1443
|
async function listIndexes(c2) {
|
|
3744
1444
|
try {
|
|
1445
|
+
const mastra = c2.get("mastra");
|
|
3745
1446
|
const vectorName = c2.req.param("vectorName");
|
|
3746
|
-
const
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
return
|
|
1447
|
+
const indexes = await vector.listIndexes({
|
|
1448
|
+
mastra,
|
|
1449
|
+
vectorName
|
|
1450
|
+
});
|
|
1451
|
+
return c2.json({ indexes });
|
|
1452
|
+
} catch (error) {
|
|
1453
|
+
return handleError(error, "Error listing indexes");
|
|
3751
1454
|
}
|
|
3752
1455
|
}
|
|
3753
1456
|
async function describeIndex(c2) {
|
|
3754
1457
|
try {
|
|
1458
|
+
const mastra = c2.get("mastra");
|
|
3755
1459
|
const vectorName = c2.req.param("vectorName");
|
|
3756
1460
|
const indexName = c2.req.param("indexName");
|
|
3757
1461
|
if (!indexName) {
|
|
3758
1462
|
throw new httpException.HTTPException(400, { message: "Index name is required" });
|
|
3759
1463
|
}
|
|
3760
|
-
const
|
|
3761
|
-
|
|
1464
|
+
const stats = await vector.describeIndex({
|
|
1465
|
+
mastra,
|
|
1466
|
+
vectorName,
|
|
1467
|
+
indexName
|
|
1468
|
+
});
|
|
3762
1469
|
return c2.json({
|
|
3763
1470
|
dimension: stats.dimension,
|
|
3764
1471
|
count: stats.count,
|
|
3765
1472
|
metric: stats.metric?.toLowerCase()
|
|
3766
1473
|
});
|
|
3767
|
-
} catch (
|
|
3768
|
-
return handleError(
|
|
1474
|
+
} catch (error) {
|
|
1475
|
+
return handleError(error, "Error describing index");
|
|
3769
1476
|
}
|
|
3770
1477
|
}
|
|
3771
1478
|
async function deleteIndex(c2) {
|
|
3772
1479
|
try {
|
|
1480
|
+
const mastra = c2.get("mastra");
|
|
3773
1481
|
const vectorName = c2.req.param("vectorName");
|
|
3774
1482
|
const indexName = c2.req.param("indexName");
|
|
3775
1483
|
if (!indexName) {
|
|
3776
1484
|
throw new httpException.HTTPException(400, { message: "Index name is required" });
|
|
3777
1485
|
}
|
|
3778
|
-
|
|
3779
|
-
|
|
1486
|
+
await vector.deleteIndex({
|
|
1487
|
+
mastra,
|
|
1488
|
+
vectorName,
|
|
1489
|
+
indexName
|
|
1490
|
+
});
|
|
3780
1491
|
return c2.json({ success: true });
|
|
3781
|
-
} catch (
|
|
3782
|
-
return handleError(
|
|
1492
|
+
} catch (error) {
|
|
1493
|
+
return handleError(error, "Error deleting index");
|
|
3783
1494
|
}
|
|
3784
1495
|
}
|
|
3785
1496
|
async function getSpeakersHandler(c2) {
|
|
3786
1497
|
try {
|
|
3787
1498
|
const mastra = c2.get("mastra");
|
|
3788
1499
|
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();
|
|
1500
|
+
const speakers = await voice.getSpeakersHandler({
|
|
1501
|
+
mastra,
|
|
1502
|
+
agentId
|
|
1503
|
+
});
|
|
3797
1504
|
return c2.json(speakers);
|
|
3798
|
-
} catch (
|
|
3799
|
-
return handleError(
|
|
1505
|
+
} catch (error) {
|
|
1506
|
+
return handleError(error, "Error getting speakers");
|
|
3800
1507
|
}
|
|
3801
1508
|
}
|
|
3802
1509
|
async function speakHandler(c2) {
|
|
3803
1510
|
try {
|
|
3804
1511
|
const mastra = c2.get("mastra");
|
|
3805
1512
|
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
1513
|
const { input, options } = await c2.req.json();
|
|
3814
|
-
await
|
|
3815
|
-
|
|
1514
|
+
const audioStream = await voice.generateSpeechHandler({
|
|
1515
|
+
mastra,
|
|
1516
|
+
agentId,
|
|
1517
|
+
body: { text: input, speakerId: options?.speakerId }
|
|
1518
|
+
});
|
|
3816
1519
|
c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
|
|
3817
1520
|
c2.header("Transfer-Encoding", "chunked");
|
|
3818
1521
|
return c2.body(audioStream);
|
|
3819
|
-
} catch (
|
|
3820
|
-
return handleError(
|
|
1522
|
+
} catch (error) {
|
|
1523
|
+
return handleError(error, "Error generating speech");
|
|
3821
1524
|
}
|
|
3822
1525
|
}
|
|
3823
1526
|
async function listenHandler(c2) {
|
|
3824
1527
|
try {
|
|
3825
1528
|
const mastra = c2.get("mastra");
|
|
3826
1529
|
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
1530
|
const formData = await c2.req.formData();
|
|
3836
1531
|
const audioFile = formData.get("audio");
|
|
3837
1532
|
const options = formData.get("options");
|
|
@@ -3839,115 +1534,76 @@ async function listenHandler(c2) {
|
|
|
3839
1534
|
throw new httpException.HTTPException(400, { message: "Audio file is required" });
|
|
3840
1535
|
}
|
|
3841
1536
|
const audioData = await audioFile.arrayBuffer();
|
|
3842
|
-
|
|
3843
|
-
audioStream.push(Buffer.from(audioData));
|
|
3844
|
-
audioStream.push(null);
|
|
3845
|
-
let parsedOptions;
|
|
1537
|
+
let parsedOptions = {};
|
|
3846
1538
|
try {
|
|
3847
1539
|
parsedOptions = options ? JSON.parse(options) : {};
|
|
3848
|
-
} catch
|
|
3849
|
-
if (error2 instanceof SyntaxError) {
|
|
3850
|
-
logger2.error("Invalid JSON in options:", error2);
|
|
3851
|
-
}
|
|
3852
|
-
parsedOptions = {};
|
|
1540
|
+
} catch {
|
|
3853
1541
|
}
|
|
3854
|
-
const transcription = await
|
|
1542
|
+
const transcription = await voice.transcribeSpeechHandler({
|
|
1543
|
+
mastra,
|
|
1544
|
+
agentId,
|
|
1545
|
+
body: {
|
|
1546
|
+
audioData: Buffer.from(audioData),
|
|
1547
|
+
options: parsedOptions
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
3855
1550
|
return c2.json({ text: transcription });
|
|
3856
|
-
} catch (
|
|
3857
|
-
return handleError(
|
|
1551
|
+
} catch (error) {
|
|
1552
|
+
return handleError(error, "Error transcribing speech");
|
|
3858
1553
|
}
|
|
3859
1554
|
}
|
|
3860
1555
|
async function getWorkflowsHandler(c2) {
|
|
3861
1556
|
try {
|
|
3862
1557
|
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");
|
|
1558
|
+
const workflows$1 = await workflows.getWorkflowsHandler({
|
|
1559
|
+
mastra
|
|
1560
|
+
});
|
|
1561
|
+
return c2.json(workflows$1);
|
|
1562
|
+
} catch (error) {
|
|
1563
|
+
return handleError(error, "Error getting workflows");
|
|
3887
1564
|
}
|
|
3888
1565
|
}
|
|
3889
1566
|
async function getWorkflowByIdHandler(c2) {
|
|
3890
1567
|
try {
|
|
3891
1568
|
const mastra = c2.get("mastra");
|
|
3892
1569
|
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
|
|
1570
|
+
const workflow = await workflows.getWorkflowByIdHandler({
|
|
1571
|
+
mastra,
|
|
1572
|
+
workflowId
|
|
3916
1573
|
});
|
|
3917
|
-
|
|
3918
|
-
|
|
1574
|
+
return c2.json(workflow);
|
|
1575
|
+
} catch (error) {
|
|
1576
|
+
return handleError(error, "Error getting workflow");
|
|
3919
1577
|
}
|
|
3920
1578
|
}
|
|
3921
1579
|
async function startAsyncWorkflowHandler(c2) {
|
|
3922
1580
|
try {
|
|
3923
1581
|
const mastra = c2.get("mastra");
|
|
3924
1582
|
const workflowId = c2.req.param("workflowId");
|
|
3925
|
-
const
|
|
3926
|
-
const body = await c2.req.json();
|
|
1583
|
+
const triggerData = await c2.req.json();
|
|
3927
1584
|
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
|
|
1585
|
+
const result = await workflows.startAsyncWorkflowHandler({
|
|
1586
|
+
mastra,
|
|
1587
|
+
workflowId,
|
|
1588
|
+
runId,
|
|
1589
|
+
triggerData
|
|
3937
1590
|
});
|
|
3938
1591
|
return c2.json(result);
|
|
3939
|
-
} catch (
|
|
3940
|
-
return handleError(
|
|
1592
|
+
} catch (error) {
|
|
1593
|
+
return handleError(error, "Error executing workflow");
|
|
3941
1594
|
}
|
|
3942
1595
|
}
|
|
3943
1596
|
async function createRunHandler(c2) {
|
|
3944
1597
|
try {
|
|
3945
1598
|
const mastra = c2.get("mastra");
|
|
3946
1599
|
const workflowId = c2.req.param("workflowId");
|
|
3947
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
3948
1600
|
const prevRunId = c2.req.query("runId");
|
|
3949
|
-
const
|
|
3950
|
-
|
|
1601
|
+
const result = await workflows.createRunHandler({
|
|
1602
|
+
mastra,
|
|
1603
|
+
workflowId,
|
|
1604
|
+
runId: prevRunId
|
|
1605
|
+
});
|
|
1606
|
+
return c2.json(result);
|
|
3951
1607
|
} catch (e2) {
|
|
3952
1608
|
return handleError(e2, "Error creating run");
|
|
3953
1609
|
}
|
|
@@ -3956,105 +1612,108 @@ async function startWorkflowRunHandler(c2) {
|
|
|
3956
1612
|
try {
|
|
3957
1613
|
const mastra = c2.get("mastra");
|
|
3958
1614
|
const workflowId = c2.req.param("workflowId");
|
|
3959
|
-
const
|
|
3960
|
-
const body = await c2.req.json();
|
|
1615
|
+
const triggerData = await c2.req.json();
|
|
3961
1616
|
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
|
|
1617
|
+
await workflows.startWorkflowRunHandler({
|
|
1618
|
+
mastra,
|
|
1619
|
+
workflowId,
|
|
1620
|
+
runId,
|
|
1621
|
+
triggerData
|
|
3971
1622
|
});
|
|
3972
1623
|
return c2.json({ message: "Workflow run started" });
|
|
3973
1624
|
} catch (e2) {
|
|
3974
1625
|
return handleError(e2, "Error starting workflow run");
|
|
3975
1626
|
}
|
|
3976
1627
|
}
|
|
3977
|
-
|
|
1628
|
+
function watchWorkflowHandler(c2) {
|
|
3978
1629
|
try {
|
|
3979
1630
|
const mastra = c2.get("mastra");
|
|
3980
1631
|
const logger2 = mastra.getLogger();
|
|
3981
1632
|
const workflowId = c2.req.param("workflowId");
|
|
3982
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
3983
1633
|
const runId = c2.req.query("runId");
|
|
3984
1634
|
if (!runId) {
|
|
3985
1635
|
throw new httpException.HTTPException(400, { message: "runId required to watch workflow" });
|
|
3986
1636
|
}
|
|
3987
|
-
|
|
3988
|
-
if (!run) {
|
|
3989
|
-
throw new httpException.HTTPException(404, { message: "Workflow run not found" });
|
|
3990
|
-
}
|
|
3991
|
-
return streaming.streamText(
|
|
1637
|
+
return streaming.stream(
|
|
3992
1638
|
c2,
|
|
3993
|
-
async (
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
1639
|
+
async (stream2) => {
|
|
1640
|
+
try {
|
|
1641
|
+
const result = await workflows.watchWorkflowHandler({
|
|
1642
|
+
mastra,
|
|
1643
|
+
workflowId,
|
|
1644
|
+
runId
|
|
3998
1645
|
});
|
|
3999
|
-
|
|
4000
|
-
|
|
1646
|
+
stream2.onAbort(() => {
|
|
1647
|
+
if (!result.locked) {
|
|
1648
|
+
return result.cancel();
|
|
1649
|
+
}
|
|
4001
1650
|
});
|
|
4002
|
-
|
|
1651
|
+
for await (const chunk of result) {
|
|
1652
|
+
await stream2.write(chunk.toString() + "");
|
|
1653
|
+
}
|
|
1654
|
+
} catch (err) {
|
|
1655
|
+
console.log(err);
|
|
1656
|
+
}
|
|
4003
1657
|
},
|
|
4004
|
-
async (err
|
|
1658
|
+
async (err) => {
|
|
4005
1659
|
logger2.error("Error in watch stream: " + err?.message);
|
|
4006
|
-
stream.abort();
|
|
4007
|
-
await stream.close();
|
|
4008
1660
|
}
|
|
4009
1661
|
);
|
|
4010
|
-
} catch (
|
|
4011
|
-
return handleError(
|
|
1662
|
+
} catch (error) {
|
|
1663
|
+
return handleError(error, "Error watching workflow");
|
|
4012
1664
|
}
|
|
4013
1665
|
}
|
|
4014
1666
|
async function resumeAsyncWorkflowHandler(c2) {
|
|
4015
1667
|
try {
|
|
4016
1668
|
const mastra = c2.get("mastra");
|
|
4017
1669
|
const workflowId = c2.req.param("workflowId");
|
|
4018
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
4019
1670
|
const runId = c2.req.query("runId");
|
|
4020
1671
|
const { stepId, context } = await c2.req.json();
|
|
4021
1672
|
if (!runId) {
|
|
4022
1673
|
throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
|
|
4023
1674
|
}
|
|
4024
|
-
const
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
stepId,
|
|
4030
|
-
context
|
|
1675
|
+
const result = await workflows.resumeAsyncWorkflowHandler({
|
|
1676
|
+
mastra,
|
|
1677
|
+
workflowId,
|
|
1678
|
+
runId,
|
|
1679
|
+
body: { stepId, context }
|
|
4031
1680
|
});
|
|
4032
1681
|
return c2.json(result);
|
|
4033
|
-
} catch (
|
|
4034
|
-
return handleError(
|
|
1682
|
+
} catch (error) {
|
|
1683
|
+
return handleError(error, "Error resuming workflow step");
|
|
4035
1684
|
}
|
|
4036
1685
|
}
|
|
4037
1686
|
async function resumeWorkflowHandler(c2) {
|
|
4038
1687
|
try {
|
|
4039
1688
|
const mastra = c2.get("mastra");
|
|
4040
1689
|
const workflowId = c2.req.param("workflowId");
|
|
4041
|
-
const workflow = mastra.getWorkflow(workflowId);
|
|
4042
1690
|
const runId = c2.req.query("runId");
|
|
4043
1691
|
const { stepId, context } = await c2.req.json();
|
|
4044
1692
|
if (!runId) {
|
|
4045
1693
|
throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
|
|
4046
1694
|
}
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
stepId,
|
|
4053
|
-
context
|
|
1695
|
+
await workflows.resumeWorkflowHandler({
|
|
1696
|
+
mastra,
|
|
1697
|
+
workflowId,
|
|
1698
|
+
runId,
|
|
1699
|
+
body: { stepId, context }
|
|
4054
1700
|
});
|
|
4055
1701
|
return c2.json({ message: "Workflow run resumed" });
|
|
4056
|
-
} catch (
|
|
4057
|
-
return handleError(
|
|
1702
|
+
} catch (error) {
|
|
1703
|
+
return handleError(error, "Error resuming workflow");
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
async function getWorkflowRunsHandler(c2) {
|
|
1707
|
+
try {
|
|
1708
|
+
const mastra = c2.get("mastra");
|
|
1709
|
+
const workflowId = c2.req.param("workflowId");
|
|
1710
|
+
const workflowRuns = await workflows.getWorkflowRunsHandler({
|
|
1711
|
+
mastra,
|
|
1712
|
+
workflowId
|
|
1713
|
+
});
|
|
1714
|
+
return c2.json(workflowRuns);
|
|
1715
|
+
} catch (error) {
|
|
1716
|
+
return handleError(error, "Error getting workflow runs");
|
|
4058
1717
|
}
|
|
4059
1718
|
}
|
|
4060
1719
|
|
|
@@ -4168,6 +1827,7 @@ var html2 = `
|
|
|
4168
1827
|
// src/server/index.ts
|
|
4169
1828
|
async function createHonoServer(mastra, options = {}) {
|
|
4170
1829
|
const app = new hono.Hono();
|
|
1830
|
+
const server = mastra.getServer();
|
|
4171
1831
|
const mastraToolsPaths = process.env.MASTRA_TOOLS_PATH;
|
|
4172
1832
|
const toolImports = mastraToolsPaths ? await Promise.all(
|
|
4173
1833
|
mastraToolsPaths.split(",").map(async (toolPath) => {
|
|
@@ -4182,6 +1842,7 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4182
1842
|
}, {});
|
|
4183
1843
|
app.use(
|
|
4184
1844
|
"*",
|
|
1845
|
+
timeout.timeout(server?.timeout ?? 1e3 * 30),
|
|
4185
1846
|
cors.cors({
|
|
4186
1847
|
origin: "*",
|
|
4187
1848
|
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
@@ -4205,14 +1866,29 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
4205
1866
|
c2.set("mastra", mastra);
|
|
4206
1867
|
c2.set("tools", tools);
|
|
4207
1868
|
c2.set("playground", options.playground === true);
|
|
4208
|
-
|
|
1869
|
+
const requestId = c2.req.header("x-request-id") ?? crypto.randomUUID();
|
|
1870
|
+
const span = core.Telemetry.getActiveSpan();
|
|
1871
|
+
if (span) {
|
|
1872
|
+
span.setAttribute("http.request_id", requestId);
|
|
1873
|
+
span.updateName(`${c2.req.method} ${c2.req.path}`);
|
|
1874
|
+
const newCtx = core.Telemetry.setBaggage({
|
|
1875
|
+
"http.request_id": requestId
|
|
1876
|
+
});
|
|
1877
|
+
await new Promise((resolve) => {
|
|
1878
|
+
core.Telemetry.withContext(newCtx, async () => {
|
|
1879
|
+
await next();
|
|
1880
|
+
resolve(true);
|
|
1881
|
+
});
|
|
1882
|
+
});
|
|
1883
|
+
} else {
|
|
1884
|
+
await next();
|
|
1885
|
+
}
|
|
4209
1886
|
});
|
|
4210
1887
|
const bodyLimitOptions = {
|
|
4211
1888
|
maxSize: 4.5 * 1024 * 1024,
|
|
4212
1889
|
// 4.5 MB,
|
|
4213
1890
|
onError: (c2) => c2.json({ error: "Request body too large" }, 413)
|
|
4214
1891
|
};
|
|
4215
|
-
const server = mastra.getServer();
|
|
4216
1892
|
const routes = server?.apiRoutes;
|
|
4217
1893
|
if (server?.middleware) {
|
|
4218
1894
|
const normalizedMiddlewares = Array.isArray(server.middleware) ? server.middleware : [server.middleware];
|
|
@@ -5421,6 +3097,27 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5421
3097
|
}),
|
|
5422
3098
|
getWorkflowByIdHandler
|
|
5423
3099
|
);
|
|
3100
|
+
app.get(
|
|
3101
|
+
"/api/workflows/:workflowId/runs",
|
|
3102
|
+
h({
|
|
3103
|
+
description: "Get all runs for a workflow",
|
|
3104
|
+
tags: ["workflows"],
|
|
3105
|
+
parameters: [
|
|
3106
|
+
{
|
|
3107
|
+
name: "workflowId",
|
|
3108
|
+
in: "path",
|
|
3109
|
+
required: true,
|
|
3110
|
+
schema: { type: "string" }
|
|
3111
|
+
}
|
|
3112
|
+
],
|
|
3113
|
+
responses: {
|
|
3114
|
+
200: {
|
|
3115
|
+
description: "List of workflow runs from storage"
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
}),
|
|
3119
|
+
getWorkflowRunsHandler
|
|
3120
|
+
);
|
|
5424
3121
|
app.post(
|
|
5425
3122
|
"/api/workflows/:workflowId/resume",
|
|
5426
3123
|
h({
|
|
@@ -5460,6 +3157,43 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5460
3157
|
app.post(
|
|
5461
3158
|
"/api/workflows/:workflowId/resumeAsync",
|
|
5462
3159
|
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3160
|
+
h({
|
|
3161
|
+
description: "@deprecated Use /api/workflows/:workflowId/resume-async instead",
|
|
3162
|
+
tags: ["workflows"],
|
|
3163
|
+
parameters: [
|
|
3164
|
+
{
|
|
3165
|
+
name: "workflowId",
|
|
3166
|
+
in: "path",
|
|
3167
|
+
required: true,
|
|
3168
|
+
schema: { type: "string" }
|
|
3169
|
+
},
|
|
3170
|
+
{
|
|
3171
|
+
name: "runId",
|
|
3172
|
+
in: "query",
|
|
3173
|
+
required: true,
|
|
3174
|
+
schema: { type: "string" }
|
|
3175
|
+
}
|
|
3176
|
+
],
|
|
3177
|
+
requestBody: {
|
|
3178
|
+
required: true,
|
|
3179
|
+
content: {
|
|
3180
|
+
"application/json": {
|
|
3181
|
+
schema: {
|
|
3182
|
+
type: "object",
|
|
3183
|
+
properties: {
|
|
3184
|
+
stepId: { type: "string" },
|
|
3185
|
+
context: { type: "object" }
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
}),
|
|
3192
|
+
resumeAsyncWorkflowHandler
|
|
3193
|
+
);
|
|
3194
|
+
app.post(
|
|
3195
|
+
"/api/workflows/:workflowId/resume-async",
|
|
3196
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
5463
3197
|
h({
|
|
5464
3198
|
description: "Resume a suspended workflow step",
|
|
5465
3199
|
tags: ["workflows"],
|
|
@@ -5565,6 +3299,50 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5565
3299
|
}),
|
|
5566
3300
|
startAsyncWorkflowHandler
|
|
5567
3301
|
);
|
|
3302
|
+
app.post(
|
|
3303
|
+
"/api/workflows/:workflowId/start-async",
|
|
3304
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3305
|
+
h({
|
|
3306
|
+
description: "@deprecated Use /api/workflows/:workflowId/start-async instead",
|
|
3307
|
+
tags: ["workflows"],
|
|
3308
|
+
parameters: [
|
|
3309
|
+
{
|
|
3310
|
+
name: "workflowId",
|
|
3311
|
+
in: "path",
|
|
3312
|
+
required: true,
|
|
3313
|
+
schema: { type: "string" }
|
|
3314
|
+
},
|
|
3315
|
+
{
|
|
3316
|
+
name: "runId",
|
|
3317
|
+
in: "query",
|
|
3318
|
+
required: false,
|
|
3319
|
+
schema: { type: "string" }
|
|
3320
|
+
}
|
|
3321
|
+
],
|
|
3322
|
+
requestBody: {
|
|
3323
|
+
required: true,
|
|
3324
|
+
content: {
|
|
3325
|
+
"application/json": {
|
|
3326
|
+
schema: {
|
|
3327
|
+
type: "object",
|
|
3328
|
+
properties: {
|
|
3329
|
+
input: { type: "object" }
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
},
|
|
3335
|
+
responses: {
|
|
3336
|
+
200: {
|
|
3337
|
+
description: "Workflow execution result"
|
|
3338
|
+
},
|
|
3339
|
+
404: {
|
|
3340
|
+
description: "Workflow not found"
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
}),
|
|
3344
|
+
startAsyncWorkflowHandler
|
|
3345
|
+
);
|
|
5568
3346
|
app.post(
|
|
5569
3347
|
"/api/workflows/:workflowId/start",
|
|
5570
3348
|
h({
|
|
@@ -5584,6 +3362,19 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
5584
3362
|
schema: { type: "string" }
|
|
5585
3363
|
}
|
|
5586
3364
|
],
|
|
3365
|
+
requestBody: {
|
|
3366
|
+
required: true,
|
|
3367
|
+
content: {
|
|
3368
|
+
"application/json": {
|
|
3369
|
+
schema: {
|
|
3370
|
+
type: "object",
|
|
3371
|
+
properties: {
|
|
3372
|
+
input: { type: "object" }
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
},
|
|
5587
3378
|
responses: {
|
|
5588
3379
|
200: {
|
|
5589
3380
|
description: "Workflow run started"
|
|
@@ -6020,10 +3811,12 @@ async function createHonoServer(mastra, options = {}) {
|
|
|
6020
3811
|
}
|
|
6021
3812
|
async function createNodeServer(mastra, options = {}) {
|
|
6022
3813
|
const app = await createHonoServer(mastra, options);
|
|
3814
|
+
const serverOptions = mastra.getServer();
|
|
3815
|
+
const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
|
|
6023
3816
|
return serve(
|
|
6024
3817
|
{
|
|
6025
3818
|
fetch: app.fetch,
|
|
6026
|
-
port
|
|
3819
|
+
port
|
|
6027
3820
|
},
|
|
6028
3821
|
() => {
|
|
6029
3822
|
const logger2 = mastra.getLogger();
|