@mastra/deployer 0.24.0 → 1.0.0-beta.1
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/CHANGELOG.md +240 -95
- 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 +10 -15
- package/dist/build/index.d.ts +0 -1
- package/dist/build/index.d.ts.map +1 -1
- package/dist/build/index.js +3 -4
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.d.ts +2 -2
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +1 -1
- package/dist/{chunk-OART5HV7.cjs → chunk-AQAOWLJJ.cjs} +29 -124
- package/dist/chunk-AQAOWLJJ.cjs.map +1 -0
- package/dist/{chunk-IAEJ3C3J.cjs → chunk-C74EXQSL.cjs} +12 -12
- package/dist/chunk-C74EXQSL.cjs.map +1 -0
- package/dist/{chunk-CVRN2K4O.js → chunk-H3LLQ2MW.js} +12 -12
- package/dist/chunk-H3LLQ2MW.js.map +1 -0
- package/dist/{chunk-FD5X42ZU.js → chunk-HQJR52M7.js} +4 -4
- package/dist/{chunk-FD5X42ZU.js.map → chunk-HQJR52M7.js.map} +1 -1
- package/dist/{chunk-NSINCI76.cjs → chunk-IL2VLNIJ.cjs} +9 -9
- package/dist/{chunk-NSINCI76.cjs.map → chunk-IL2VLNIJ.cjs.map} +1 -1
- package/dist/{chunk-XHLN6E4D.js → chunk-OFUWEVGF.js} +3 -3
- package/dist/{chunk-XHLN6E4D.js.map → chunk-OFUWEVGF.js.map} +1 -1
- package/dist/{chunk-Z546LAA6.cjs → chunk-TDWIGFVF.cjs} +14 -14
- package/dist/{chunk-Z546LAA6.cjs.map → chunk-TDWIGFVF.cjs.map} +1 -1
- package/dist/{chunk-VDRZB7JQ.js → chunk-WBAWUM7Z.js} +23 -116
- package/dist/chunk-WBAWUM7Z.js.map +1 -0
- package/dist/index.cjs +5 -5
- package/dist/index.js +2 -2
- package/dist/server/handlers/health.d.ts +5 -0
- package/dist/server/handlers/health.d.ts.map +1 -0
- package/dist/server/handlers/prompt.d.ts.map +1 -1
- package/dist/server/handlers/routes/agent-builder/handlers.d.ts +5 -2
- package/dist/server/handlers/routes/agent-builder/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/agent-builder/router.d.ts.map +1 -1
- package/dist/server/handlers/routes/agents/handlers.d.ts +21 -143
- package/dist/server/handlers/routes/agents/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/agents/router.d.ts.map +1 -1
- package/dist/server/handlers/routes/logs/handlers.d.ts +3 -3
- package/dist/server/handlers/routes/logs/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/mcp/handlers.d.ts +1 -1
- package/dist/server/handlers/routes/mcp/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/memory/handlers.d.ts +2 -4
- package/dist/server/handlers/routes/memory/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/memory/router.d.ts.map +1 -1
- package/dist/server/handlers/routes/observability/handlers.d.ts +3 -3
- package/dist/server/handlers/routes/observability/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/observability/router.d.ts.map +1 -1
- package/dist/server/handlers/routes/scores/handlers.d.ts +8 -6
- package/dist/server/handlers/routes/scores/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/tools/handlers.d.ts +1 -1
- package/dist/server/handlers/routes/tools/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/workflows/handlers.d.ts +2 -4
- package/dist/server/handlers/routes/workflows/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/workflows/router.d.ts.map +1 -1
- package/dist/server/handlers/utils/query-parsers.d.ts +15 -0
- package/dist/server/handlers/utils/query-parsers.d.ts.map +1 -1
- package/dist/server/index.cjs +1207 -1559
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1214 -1566
- package/dist/server/index.js.map +1 -1
- package/dist/server/welcome.d.ts +1 -1
- package/dist/server/welcome.d.ts.map +1 -1
- package/package.json +12 -16
- package/dist/build/babel/remove-all-options-telemetry.d.ts +0 -5
- package/dist/build/babel/remove-all-options-telemetry.d.ts.map +0 -1
- package/dist/build/customInstrumentation.d.ts +0 -10
- package/dist/build/customInstrumentation.d.ts.map +0 -1
- package/dist/build/telemetry.d.ts +0 -8
- package/dist/build/telemetry.d.ts.map +0 -1
- package/dist/chunk-AJX72IGP.cjs +0 -28
- package/dist/chunk-AJX72IGP.cjs.map +0 -1
- package/dist/chunk-B2Q76NIL.js +0 -26
- package/dist/chunk-B2Q76NIL.js.map +0 -1
- package/dist/chunk-CVRN2K4O.js.map +0 -1
- package/dist/chunk-IAEJ3C3J.cjs.map +0 -1
- package/dist/chunk-OART5HV7.cjs.map +0 -1
- package/dist/chunk-VDRZB7JQ.js.map +0 -1
- package/dist/server/handlers/routes/telemetry/handlers.d.ts +0 -4
- package/dist/server/handlers/routes/telemetry/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/telemetry/router.d.ts +0 -3
- package/dist/server/handlers/routes/telemetry/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/workflows/legacyWorkflows.d.ts +0 -11
- package/dist/server/handlers/routes/workflows/legacyWorkflows.d.ts.map +0 -1
- package/dist/templates/instrumentation-template.js +0 -172
package/dist/server/index.cjs
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var crypto = require('crypto');
|
|
4
3
|
var promises = require('fs/promises');
|
|
5
4
|
var https = require('https');
|
|
6
5
|
var posix = require('path/posix');
|
|
7
6
|
var http = require('http');
|
|
8
7
|
var http2 = require('http2');
|
|
9
8
|
var stream = require('stream');
|
|
9
|
+
var crypto = require('crypto');
|
|
10
10
|
var mime = require('hono/utils/mime');
|
|
11
11
|
var fs = require('fs');
|
|
12
12
|
var path = require('path');
|
|
13
13
|
var html = require('hono/html');
|
|
14
|
-
var
|
|
15
|
-
var telemetry = require('@mastra/core/telemetry');
|
|
14
|
+
var requestContext = require('@mastra/core/request-context');
|
|
16
15
|
var tools = require('@mastra/core/tools');
|
|
17
16
|
var store = require('@mastra/server/a2a/store');
|
|
18
17
|
var hono = require('hono');
|
|
@@ -36,13 +35,11 @@ var logs = require('@mastra/server/handlers/logs');
|
|
|
36
35
|
var util = require('util');
|
|
37
36
|
var buffer = require('buffer');
|
|
38
37
|
var memory = require('@mastra/server/handlers/memory');
|
|
39
|
-
var
|
|
40
|
-
var observability = require('@mastra/server/handlers/observability');
|
|
38
|
+
var observability = require('@mastra/core/observability');
|
|
39
|
+
var observability$1 = require('@mastra/server/handlers/observability');
|
|
41
40
|
var scores = require('@mastra/server/handlers/scores');
|
|
42
|
-
var telemetry$1 = require('@mastra/server/handlers/telemetry');
|
|
43
41
|
var vector = require('@mastra/server/handlers/vector');
|
|
44
42
|
var workflows = require('@mastra/server/handlers/workflows');
|
|
45
|
-
var legacyWorkflows = require('@mastra/server/handlers/legacyWorkflows');
|
|
46
43
|
|
|
47
44
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
48
45
|
|
|
@@ -64,8 +61,8 @@ function _interopNamespace(e) {
|
|
|
64
61
|
return Object.freeze(n);
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
68
64
|
var https__namespace = /*#__PURE__*/_interopNamespace(https);
|
|
65
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
69
66
|
var util__default = /*#__PURE__*/_interopDefault(util);
|
|
70
67
|
|
|
71
68
|
// src/server/index.ts
|
|
@@ -353,13 +350,13 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
353
350
|
}
|
|
354
351
|
}
|
|
355
352
|
}
|
|
356
|
-
function writeFromReadableStream(
|
|
357
|
-
if (
|
|
353
|
+
function writeFromReadableStream(stream5, writable) {
|
|
354
|
+
if (stream5.locked) {
|
|
358
355
|
throw new TypeError("ReadableStream is locked.");
|
|
359
356
|
} else if (writable.destroyed) {
|
|
360
357
|
return;
|
|
361
358
|
}
|
|
362
|
-
return writeFromReadableStreamDefaultReader(
|
|
359
|
+
return writeFromReadableStreamDefaultReader(stream5.getReader(), writable);
|
|
363
360
|
}
|
|
364
361
|
var buildOutgoingHttpHeaders = (headers) => {
|
|
365
362
|
const res = {};
|
|
@@ -624,21 +621,21 @@ var ENCODINGS = {
|
|
|
624
621
|
gzip: ".gz"
|
|
625
622
|
};
|
|
626
623
|
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
627
|
-
var createStreamBody = (
|
|
624
|
+
var createStreamBody = (stream5) => {
|
|
628
625
|
const body = new ReadableStream({
|
|
629
626
|
start(controller) {
|
|
630
|
-
|
|
627
|
+
stream5.on("data", (chunk) => {
|
|
631
628
|
controller.enqueue(chunk);
|
|
632
629
|
});
|
|
633
|
-
|
|
630
|
+
stream5.on("error", (err) => {
|
|
634
631
|
controller.error(err);
|
|
635
632
|
});
|
|
636
|
-
|
|
633
|
+
stream5.on("end", () => {
|
|
637
634
|
controller.close();
|
|
638
635
|
});
|
|
639
636
|
},
|
|
640
637
|
cancel() {
|
|
641
|
-
|
|
638
|
+
stream5.destroy();
|
|
642
639
|
}
|
|
643
640
|
});
|
|
644
641
|
return body;
|
|
@@ -689,7 +686,6 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
689
686
|
await options.onNotFound?.(path$1, c2);
|
|
690
687
|
return next();
|
|
691
688
|
}
|
|
692
|
-
await options.onFound?.(path$1, c2);
|
|
693
689
|
const mimeType = mime.getMimeType(path$1);
|
|
694
690
|
c2.header("Content-Type", mimeType || "application/octet-stream");
|
|
695
691
|
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
@@ -710,30 +706,33 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
710
706
|
}
|
|
711
707
|
}
|
|
712
708
|
}
|
|
709
|
+
let result;
|
|
713
710
|
const size = stats.size;
|
|
711
|
+
const range = c2.req.header("range") || "";
|
|
714
712
|
if (c2.req.method == "HEAD" || c2.req.method == "OPTIONS") {
|
|
715
713
|
c2.header("Content-Length", size.toString());
|
|
716
714
|
c2.status(200);
|
|
717
|
-
|
|
718
|
-
}
|
|
719
|
-
const range = c2.req.header("range") || "";
|
|
720
|
-
if (!range) {
|
|
715
|
+
result = c2.body(null);
|
|
716
|
+
} else if (!range) {
|
|
721
717
|
c2.header("Content-Length", size.toString());
|
|
722
|
-
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
718
|
+
result = c2.body(createStreamBody(fs.createReadStream(path$1)), 200);
|
|
719
|
+
} else {
|
|
720
|
+
c2.header("Accept-Ranges", "bytes");
|
|
721
|
+
c2.header("Date", stats.birthtime.toUTCString());
|
|
722
|
+
const parts = range.replace(/bytes=/, "").split("-", 2);
|
|
723
|
+
const start = parseInt(parts[0], 10) || 0;
|
|
724
|
+
let end = parseInt(parts[1], 10) || size - 1;
|
|
725
|
+
if (size < end - start + 1) {
|
|
726
|
+
end = size - 1;
|
|
727
|
+
}
|
|
728
|
+
const chunksize = end - start + 1;
|
|
729
|
+
const stream5 = fs.createReadStream(path$1, { start, end });
|
|
730
|
+
c2.header("Content-Length", chunksize.toString());
|
|
731
|
+
c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
732
|
+
result = c2.body(createStreamBody(stream5), 206);
|
|
733
|
+
}
|
|
734
|
+
await options.onFound?.(path$1, c2);
|
|
735
|
+
return result;
|
|
737
736
|
};
|
|
738
737
|
};
|
|
739
738
|
var RENDER_TYPE = {
|
|
@@ -854,7 +853,7 @@ var middleware = (options) => async (c2) => {
|
|
|
854
853
|
);
|
|
855
854
|
};
|
|
856
855
|
|
|
857
|
-
// ../../node_modules/.pnpm/hono-openapi@0.4.8_hono@4.10.
|
|
856
|
+
// ../../node_modules/.pnpm/hono-openapi@0.4.8_hono@4.10.3_openapi-types@12.1.3_zod@3.25.76/node_modules/hono-openapi/utils.js
|
|
858
857
|
var e = Symbol("openapi");
|
|
859
858
|
var n = ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
|
|
860
859
|
var s2 = (e2) => e2.charAt(0).toUpperCase() + e2.slice(1);
|
|
@@ -1000,18 +999,18 @@ async function x(e2, t2, n2 = {}) {
|
|
|
1000
999
|
async function getAgentCardByIdHandler(c2) {
|
|
1001
1000
|
const mastra = c2.get("mastra");
|
|
1002
1001
|
const agentId = c2.req.param("agentId");
|
|
1003
|
-
const
|
|
1002
|
+
const requestContext = c2.get("requestContext");
|
|
1004
1003
|
const result = await a2a.getAgentCardByIdHandler({
|
|
1005
1004
|
mastra,
|
|
1006
1005
|
agentId,
|
|
1007
|
-
|
|
1006
|
+
requestContext
|
|
1008
1007
|
});
|
|
1009
1008
|
return c2.json(result);
|
|
1010
1009
|
}
|
|
1011
1010
|
async function getAgentExecutionHandler(c2) {
|
|
1012
1011
|
const mastra = c2.get("mastra");
|
|
1013
1012
|
const agentId = c2.req.param("agentId");
|
|
1014
|
-
const
|
|
1013
|
+
const requestContext = c2.get("requestContext");
|
|
1015
1014
|
const taskStore = c2.get("taskStore");
|
|
1016
1015
|
const logger2 = mastra.getLogger();
|
|
1017
1016
|
const body = await c2.req.json();
|
|
@@ -1021,7 +1020,7 @@ async function getAgentExecutionHandler(c2) {
|
|
|
1021
1020
|
const result = await a2a.getAgentExecutionHandler({
|
|
1022
1021
|
mastra,
|
|
1023
1022
|
agentId,
|
|
1024
|
-
|
|
1023
|
+
requestContext,
|
|
1025
1024
|
requestId: crypto.randomUUID(),
|
|
1026
1025
|
method: body.method,
|
|
1027
1026
|
params: body.params,
|
|
@@ -1031,15 +1030,15 @@ async function getAgentExecutionHandler(c2) {
|
|
|
1031
1030
|
if (body.method === "message/stream") {
|
|
1032
1031
|
return streaming.stream(
|
|
1033
1032
|
c2,
|
|
1034
|
-
async (
|
|
1033
|
+
async (stream5) => {
|
|
1035
1034
|
try {
|
|
1036
|
-
|
|
1035
|
+
stream5.onAbort(() => {
|
|
1037
1036
|
if (!result.locked) {
|
|
1038
1037
|
return result.cancel();
|
|
1039
1038
|
}
|
|
1040
1039
|
});
|
|
1041
1040
|
for await (const chunk of result) {
|
|
1042
|
-
await
|
|
1041
|
+
await stream5.write(JSON.stringify(chunk) + "");
|
|
1043
1042
|
}
|
|
1044
1043
|
} catch (err) {
|
|
1045
1044
|
logger2.error("Error in message/stream stream: " + err?.message);
|
|
@@ -1179,7 +1178,7 @@ var checkRules = async (rules, path, method, user) => {
|
|
|
1179
1178
|
// src/server/handlers/auth/index.ts
|
|
1180
1179
|
var authenticationMiddleware = async (c2, next) => {
|
|
1181
1180
|
const mastra = c2.get("mastra");
|
|
1182
|
-
const authConfig = mastra.getServer()?.
|
|
1181
|
+
const authConfig = mastra.getServer()?.auth;
|
|
1183
1182
|
const customRouteAuthConfig = c2.get("customRouteAuthConfig");
|
|
1184
1183
|
if (!authConfig) {
|
|
1185
1184
|
return next();
|
|
@@ -1211,7 +1210,7 @@ var authenticationMiddleware = async (c2, next) => {
|
|
|
1211
1210
|
if (!user) {
|
|
1212
1211
|
return c2.json({ error: "Invalid or expired token" }, 401);
|
|
1213
1212
|
}
|
|
1214
|
-
c2.get("
|
|
1213
|
+
c2.get("requestContext").set("user", user);
|
|
1215
1214
|
return next();
|
|
1216
1215
|
} catch (err) {
|
|
1217
1216
|
console.error(err);
|
|
@@ -1220,7 +1219,7 @@ var authenticationMiddleware = async (c2, next) => {
|
|
|
1220
1219
|
};
|
|
1221
1220
|
var authorizationMiddleware = async (c2, next) => {
|
|
1222
1221
|
const mastra = c2.get("mastra");
|
|
1223
|
-
const authConfig = mastra.getServer()?.
|
|
1222
|
+
const authConfig = mastra.getServer()?.auth;
|
|
1224
1223
|
const customRouteAuthConfig = c2.get("customRouteAuthConfig");
|
|
1225
1224
|
if (!authConfig) {
|
|
1226
1225
|
return next();
|
|
@@ -1236,7 +1235,7 @@ var authorizationMiddleware = async (c2, next) => {
|
|
|
1236
1235
|
if (canAccessPublicly(path, method, authConfig)) {
|
|
1237
1236
|
return next();
|
|
1238
1237
|
}
|
|
1239
|
-
const user = c2.get("
|
|
1238
|
+
const user = c2.get("requestContext").get("user");
|
|
1240
1239
|
if ("authorizeUser" in authConfig && typeof authConfig.authorizeUser === "function") {
|
|
1241
1240
|
try {
|
|
1242
1241
|
const isAuthorized = await authConfig.authorizeUser(user, c2.req);
|
|
@@ -1281,7 +1280,7 @@ var authorizationMiddleware = async (c2, next) => {
|
|
|
1281
1280
|
var clients = /* @__PURE__ */ new Set();
|
|
1282
1281
|
var hotReloadDisabled = false;
|
|
1283
1282
|
function handleClientsRefresh(c2) {
|
|
1284
|
-
const
|
|
1283
|
+
const stream5 = new ReadableStream({
|
|
1285
1284
|
start(controller) {
|
|
1286
1285
|
clients.add(controller);
|
|
1287
1286
|
controller.enqueue("data: connected\n\n");
|
|
@@ -1290,7 +1289,7 @@ function handleClientsRefresh(c2) {
|
|
|
1290
1289
|
});
|
|
1291
1290
|
}
|
|
1292
1291
|
});
|
|
1293
|
-
return new Response(
|
|
1292
|
+
return new Response(stream5, {
|
|
1294
1293
|
headers: {
|
|
1295
1294
|
"Content-Type": "text/event-stream",
|
|
1296
1295
|
"Cache-Control": "no-cache",
|
|
@@ -1338,6 +1337,11 @@ function errorHandler(err, c2, isDev) {
|
|
|
1338
1337
|
return c2.json({ error: "Internal Server Error" }, 500);
|
|
1339
1338
|
}
|
|
1340
1339
|
|
|
1340
|
+
// src/server/handlers/health.ts
|
|
1341
|
+
async function healthHandler(c2) {
|
|
1342
|
+
return c2.json({ success: true }, 200);
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1341
1345
|
// src/server/handlers/root.ts
|
|
1342
1346
|
async function rootHandler(c2) {
|
|
1343
1347
|
const baseUrl = new URL(c2.req.url).origin;
|
|
@@ -1499,17 +1503,18 @@ async function createAgentBuilderActionRunHandler(c2) {
|
|
|
1499
1503
|
async function startAsyncAgentBuilderActionHandler(c2) {
|
|
1500
1504
|
try {
|
|
1501
1505
|
const mastra = c2.get("mastra");
|
|
1502
|
-
const
|
|
1506
|
+
const requestContext = c2.get("requestContext");
|
|
1503
1507
|
const actionId = c2.req.param("actionId");
|
|
1504
|
-
const { inputData } = await c2.req.json();
|
|
1508
|
+
const { inputData, tracingOptions } = await c2.req.json();
|
|
1505
1509
|
const runId = c2.req.query("runId");
|
|
1506
1510
|
disableHotReload();
|
|
1507
1511
|
const result = await agentBuilder.startAsyncAgentBuilderActionHandler({
|
|
1508
1512
|
mastra,
|
|
1509
|
-
|
|
1513
|
+
requestContext,
|
|
1510
1514
|
actionId,
|
|
1511
1515
|
runId,
|
|
1512
|
-
inputData
|
|
1516
|
+
inputData,
|
|
1517
|
+
tracingOptions
|
|
1513
1518
|
});
|
|
1514
1519
|
enableHotReload();
|
|
1515
1520
|
return c2.json(result);
|
|
@@ -1521,73 +1526,35 @@ async function startAsyncAgentBuilderActionHandler(c2) {
|
|
|
1521
1526
|
async function startAgentBuilderActionRunHandler(c2) {
|
|
1522
1527
|
try {
|
|
1523
1528
|
const mastra = c2.get("mastra");
|
|
1524
|
-
const
|
|
1529
|
+
const requestContext = c2.get("requestContext");
|
|
1525
1530
|
const actionId = c2.req.param("actionId");
|
|
1526
|
-
const { inputData } = await c2.req.json();
|
|
1531
|
+
const { inputData, tracingOptions } = await c2.req.json();
|
|
1527
1532
|
const runId = c2.req.query("runId");
|
|
1528
1533
|
await agentBuilder.startAgentBuilderActionRunHandler({
|
|
1529
1534
|
mastra,
|
|
1530
|
-
|
|
1535
|
+
requestContext,
|
|
1531
1536
|
actionId,
|
|
1532
1537
|
runId,
|
|
1533
|
-
inputData
|
|
1538
|
+
inputData,
|
|
1539
|
+
tracingOptions
|
|
1534
1540
|
});
|
|
1535
1541
|
return c2.json({ message: "Agent builder action run started" });
|
|
1536
1542
|
} catch (error) {
|
|
1537
1543
|
return handleError(error, "Error starting agent builder action run");
|
|
1538
1544
|
}
|
|
1539
1545
|
}
|
|
1540
|
-
async function watchAgentBuilderActionHandler(c2) {
|
|
1541
|
-
try {
|
|
1542
|
-
const mastra = c2.get("mastra");
|
|
1543
|
-
const logger2 = mastra.getLogger();
|
|
1544
|
-
const actionId = c2.req.param("actionId");
|
|
1545
|
-
const runId = c2.req.query("runId");
|
|
1546
|
-
const eventType = c2.req.query("eventType");
|
|
1547
|
-
if (!runId) {
|
|
1548
|
-
throw new httpException.HTTPException(400, { message: "runId required to watch action" });
|
|
1549
|
-
}
|
|
1550
|
-
c2.header("Transfer-Encoding", "chunked");
|
|
1551
|
-
return streaming.stream(c2, async (stream6) => {
|
|
1552
|
-
try {
|
|
1553
|
-
disableHotReload();
|
|
1554
|
-
const result = await agentBuilder.watchAgentBuilderActionHandler({
|
|
1555
|
-
mastra,
|
|
1556
|
-
actionId,
|
|
1557
|
-
runId,
|
|
1558
|
-
eventType
|
|
1559
|
-
});
|
|
1560
|
-
const reader = result.getReader();
|
|
1561
|
-
stream6.onAbort(() => {
|
|
1562
|
-
void reader.cancel("request aborted");
|
|
1563
|
-
});
|
|
1564
|
-
let chunkResult;
|
|
1565
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1566
|
-
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
1567
|
-
}
|
|
1568
|
-
enableHotReload();
|
|
1569
|
-
} catch (err) {
|
|
1570
|
-
enableHotReload();
|
|
1571
|
-
logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
|
|
1572
|
-
}
|
|
1573
|
-
});
|
|
1574
|
-
} catch (error) {
|
|
1575
|
-
enableHotReload();
|
|
1576
|
-
return handleError(error, "Error watching agent builder action");
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
1546
|
async function streamAgentBuilderActionHandler(c2) {
|
|
1580
1547
|
try {
|
|
1581
1548
|
const mastra = c2.get("mastra");
|
|
1582
|
-
const
|
|
1549
|
+
const requestContext = c2.get("requestContext");
|
|
1583
1550
|
const logger2 = mastra.getLogger();
|
|
1584
1551
|
const actionId = c2.req.param("actionId");
|
|
1585
|
-
const { inputData } = await c2.req.json();
|
|
1552
|
+
const { inputData, tracingOptions } = await c2.req.json();
|
|
1586
1553
|
const runId = c2.req.query("runId");
|
|
1587
1554
|
c2.header("Transfer-Encoding", "chunked");
|
|
1588
1555
|
return streaming.stream(
|
|
1589
1556
|
c2,
|
|
1590
|
-
async (
|
|
1557
|
+
async (stream5) => {
|
|
1591
1558
|
try {
|
|
1592
1559
|
disableHotReload();
|
|
1593
1560
|
const result = await agentBuilder.streamAgentBuilderActionHandler({
|
|
@@ -1595,20 +1562,21 @@ async function streamAgentBuilderActionHandler(c2) {
|
|
|
1595
1562
|
actionId,
|
|
1596
1563
|
runId,
|
|
1597
1564
|
inputData,
|
|
1598
|
-
|
|
1565
|
+
requestContext,
|
|
1566
|
+
tracingOptions
|
|
1599
1567
|
});
|
|
1600
|
-
const reader = result.
|
|
1601
|
-
|
|
1568
|
+
const reader = result.getReader();
|
|
1569
|
+
stream5.onAbort(() => {
|
|
1602
1570
|
void reader.cancel("request aborted");
|
|
1603
1571
|
});
|
|
1604
1572
|
let chunkResult;
|
|
1605
1573
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1606
|
-
await
|
|
1574
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1607
1575
|
}
|
|
1608
1576
|
} catch (err) {
|
|
1609
1577
|
logger2.error("Error in action stream: " + (err?.message ?? "Unknown error"));
|
|
1610
1578
|
}
|
|
1611
|
-
await
|
|
1579
|
+
await stream5.close();
|
|
1612
1580
|
enableHotReload();
|
|
1613
1581
|
},
|
|
1614
1582
|
async (err) => {
|
|
@@ -1623,15 +1591,15 @@ async function streamAgentBuilderActionHandler(c2) {
|
|
|
1623
1591
|
async function streamVNextAgentBuilderActionHandler(c2) {
|
|
1624
1592
|
try {
|
|
1625
1593
|
const mastra = c2.get("mastra");
|
|
1626
|
-
const
|
|
1594
|
+
const requestContext = c2.get("requestContext");
|
|
1627
1595
|
const logger2 = mastra.getLogger();
|
|
1628
1596
|
const actionId = c2.req.param("actionId");
|
|
1629
|
-
const { inputData } = await c2.req.json();
|
|
1597
|
+
const { inputData, closeOnSuspend, tracingOptions } = await c2.req.json();
|
|
1630
1598
|
const runId = c2.req.query("runId");
|
|
1631
1599
|
c2.header("Transfer-Encoding", "chunked");
|
|
1632
1600
|
return streaming.stream(
|
|
1633
1601
|
c2,
|
|
1634
|
-
async (
|
|
1602
|
+
async (stream5) => {
|
|
1635
1603
|
try {
|
|
1636
1604
|
disableHotReload();
|
|
1637
1605
|
const result = await agentBuilder.streamVNextAgentBuilderActionHandler({
|
|
@@ -1639,15 +1607,17 @@ async function streamVNextAgentBuilderActionHandler(c2) {
|
|
|
1639
1607
|
actionId,
|
|
1640
1608
|
runId,
|
|
1641
1609
|
inputData,
|
|
1642
|
-
|
|
1610
|
+
requestContext,
|
|
1611
|
+
closeOnSuspend,
|
|
1612
|
+
tracingOptions
|
|
1643
1613
|
});
|
|
1644
1614
|
const reader = result.getReader();
|
|
1645
|
-
|
|
1615
|
+
stream5.onAbort(() => {
|
|
1646
1616
|
void reader.cancel("request aborted");
|
|
1647
1617
|
});
|
|
1648
1618
|
let chunkResult;
|
|
1649
1619
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1650
|
-
await
|
|
1620
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1651
1621
|
}
|
|
1652
1622
|
} catch (err) {
|
|
1653
1623
|
logger2.error("Error in action VNext stream: " + (err?.message ?? "Unknown error"));
|
|
@@ -1666,20 +1636,21 @@ async function streamVNextAgentBuilderActionHandler(c2) {
|
|
|
1666
1636
|
async function resumeAsyncAgentBuilderActionHandler(c2) {
|
|
1667
1637
|
try {
|
|
1668
1638
|
const mastra = c2.get("mastra");
|
|
1669
|
-
const
|
|
1639
|
+
const requestContext = c2.get("requestContext");
|
|
1670
1640
|
const actionId = c2.req.param("actionId");
|
|
1671
1641
|
const runId = c2.req.query("runId");
|
|
1672
|
-
const { step, resumeData } = await c2.req.json();
|
|
1642
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
1673
1643
|
if (!runId) {
|
|
1674
1644
|
throw new httpException.HTTPException(400, { message: "runId required to resume action" });
|
|
1675
1645
|
}
|
|
1676
1646
|
disableHotReload();
|
|
1677
1647
|
const result = await agentBuilder.resumeAsyncAgentBuilderActionHandler({
|
|
1678
1648
|
mastra,
|
|
1679
|
-
|
|
1649
|
+
requestContext,
|
|
1680
1650
|
actionId,
|
|
1681
1651
|
runId,
|
|
1682
|
-
body: { step, resumeData }
|
|
1652
|
+
body: { step, resumeData },
|
|
1653
|
+
tracingOptions
|
|
1683
1654
|
});
|
|
1684
1655
|
enableHotReload();
|
|
1685
1656
|
return c2.json(result);
|
|
@@ -1691,20 +1662,21 @@ async function resumeAsyncAgentBuilderActionHandler(c2) {
|
|
|
1691
1662
|
async function resumeAgentBuilderActionHandler(c2) {
|
|
1692
1663
|
try {
|
|
1693
1664
|
const mastra = c2.get("mastra");
|
|
1694
|
-
const
|
|
1665
|
+
const requestContext = c2.get("requestContext");
|
|
1695
1666
|
const actionId = c2.req.param("actionId");
|
|
1696
1667
|
const runId = c2.req.query("runId");
|
|
1697
|
-
const { step, resumeData } = await c2.req.json();
|
|
1668
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
1698
1669
|
if (!runId) {
|
|
1699
1670
|
throw new httpException.HTTPException(400, { message: "runId required to resume action" });
|
|
1700
1671
|
}
|
|
1701
1672
|
disableHotReload();
|
|
1702
1673
|
await agentBuilder.resumeAgentBuilderActionHandler({
|
|
1703
1674
|
mastra,
|
|
1704
|
-
|
|
1675
|
+
requestContext,
|
|
1705
1676
|
actionId,
|
|
1706
1677
|
runId,
|
|
1707
|
-
body: { step, resumeData }
|
|
1678
|
+
body: { step, resumeData },
|
|
1679
|
+
tracingOptions
|
|
1708
1680
|
});
|
|
1709
1681
|
enableHotReload();
|
|
1710
1682
|
return c2.json({ message: "Action run resumed" });
|
|
@@ -1717,14 +1689,15 @@ async function getAgentBuilderActionRunsHandler(c2) {
|
|
|
1717
1689
|
try {
|
|
1718
1690
|
const mastra = c2.get("mastra");
|
|
1719
1691
|
const actionId = c2.req.param("actionId");
|
|
1720
|
-
const
|
|
1692
|
+
const queryParams = c2.req.query();
|
|
1693
|
+
const { fromDate, toDate, perPage, page, resourceId } = queryParams;
|
|
1721
1694
|
const runs = await agentBuilder.getAgentBuilderActionRunsHandler({
|
|
1722
1695
|
mastra,
|
|
1723
1696
|
actionId,
|
|
1724
1697
|
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
1725
1698
|
toDate: toDate ? new Date(toDate) : void 0,
|
|
1726
|
-
|
|
1727
|
-
|
|
1699
|
+
perPage: perPage !== null && perPage !== void 0 && !isNaN(Number(perPage)) ? Number(perPage) : void 0,
|
|
1700
|
+
page: page !== null && page !== void 0 && !isNaN(Number(page)) ? Number(page) : void 0,
|
|
1728
1701
|
resourceId
|
|
1729
1702
|
});
|
|
1730
1703
|
return c2.json(runs);
|
|
@@ -1777,22 +1750,219 @@ async function cancelAgentBuilderActionRunHandler(c2) {
|
|
|
1777
1750
|
return handleError(error, "Error cancelling agent builder action run");
|
|
1778
1751
|
}
|
|
1779
1752
|
}
|
|
1780
|
-
async function
|
|
1753
|
+
async function streamLegacyAgentBuilderActionHandler(c2) {
|
|
1781
1754
|
try {
|
|
1782
1755
|
const mastra = c2.get("mastra");
|
|
1756
|
+
const requestContext = c2.get("requestContext");
|
|
1757
|
+
const logger2 = mastra.getLogger();
|
|
1783
1758
|
const actionId = c2.req.param("actionId");
|
|
1784
|
-
const
|
|
1785
|
-
const
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1759
|
+
const { inputData, tracingOptions } = await c2.req.json();
|
|
1760
|
+
const runId = c2.req.query("runId");
|
|
1761
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1762
|
+
return streaming.stream(
|
|
1763
|
+
c2,
|
|
1764
|
+
async (stream5) => {
|
|
1765
|
+
try {
|
|
1766
|
+
disableHotReload();
|
|
1767
|
+
const result = await agentBuilder.streamLegacyAgentBuilderActionHandler({
|
|
1768
|
+
mastra,
|
|
1769
|
+
actionId,
|
|
1770
|
+
runId,
|
|
1771
|
+
inputData,
|
|
1772
|
+
requestContext,
|
|
1773
|
+
tracingOptions
|
|
1774
|
+
});
|
|
1775
|
+
const reader = result?.stream?.getReader();
|
|
1776
|
+
if (!reader) {
|
|
1777
|
+
throw new Error("No reader available from legacy stream");
|
|
1778
|
+
}
|
|
1779
|
+
stream5.onAbort(() => {
|
|
1780
|
+
void reader.cancel("request aborted");
|
|
1781
|
+
});
|
|
1782
|
+
let chunkResult;
|
|
1783
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1784
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1785
|
+
}
|
|
1786
|
+
} catch (err) {
|
|
1787
|
+
logger2.error("Error in action legacy stream: " + (err?.message ?? "Unknown error"));
|
|
1788
|
+
}
|
|
1789
|
+
await stream5.close();
|
|
1790
|
+
enableHotReload();
|
|
1791
|
+
},
|
|
1792
|
+
async (err) => {
|
|
1793
|
+
logger2.error("Error in action legacy stream: " + err?.message);
|
|
1794
|
+
}
|
|
1795
|
+
);
|
|
1796
|
+
} catch (error) {
|
|
1797
|
+
enableHotReload();
|
|
1798
|
+
return handleError(error, "Error streaming legacy agent builder action");
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
async function observeStreamLegacyAgentBuilderActionHandler(c2) {
|
|
1802
|
+
try {
|
|
1803
|
+
const mastra = c2.get("mastra");
|
|
1804
|
+
const logger2 = mastra.getLogger();
|
|
1805
|
+
const actionId = c2.req.param("actionId");
|
|
1806
|
+
const runId = c2.req.query("runId");
|
|
1807
|
+
if (!runId) {
|
|
1808
|
+
throw new httpException.HTTPException(400, { message: "runId required to observe stream" });
|
|
1809
|
+
}
|
|
1810
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1811
|
+
return streaming.stream(c2, async (stream5) => {
|
|
1812
|
+
try {
|
|
1813
|
+
disableHotReload();
|
|
1814
|
+
const result = await agentBuilder.observeStreamLegacyAgentBuilderActionHandler({
|
|
1815
|
+
mastra,
|
|
1816
|
+
actionId,
|
|
1817
|
+
runId
|
|
1818
|
+
});
|
|
1819
|
+
const reader = result?.getReader();
|
|
1820
|
+
if (!reader) {
|
|
1821
|
+
throw new Error("No reader available from observe stream");
|
|
1822
|
+
}
|
|
1823
|
+
stream5.onAbort(() => {
|
|
1824
|
+
void reader.cancel("request aborted");
|
|
1825
|
+
});
|
|
1826
|
+
let chunkResult;
|
|
1827
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1828
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1829
|
+
}
|
|
1830
|
+
enableHotReload();
|
|
1831
|
+
} catch (err) {
|
|
1832
|
+
enableHotReload();
|
|
1833
|
+
logger2.error("Error in observe legacy stream: " + (err?.message ?? "Unknown error"));
|
|
1834
|
+
}
|
|
1792
1835
|
});
|
|
1793
|
-
return c2.json(result);
|
|
1794
1836
|
} catch (error) {
|
|
1795
|
-
|
|
1837
|
+
enableHotReload();
|
|
1838
|
+
return handleError(error, "Error observing legacy stream for agent builder action");
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
async function observeStreamAgentBuilderActionHandler(c2) {
|
|
1842
|
+
try {
|
|
1843
|
+
const mastra = c2.get("mastra");
|
|
1844
|
+
const logger2 = mastra.getLogger();
|
|
1845
|
+
const actionId = c2.req.param("actionId");
|
|
1846
|
+
const runId = c2.req.query("runId");
|
|
1847
|
+
if (!runId) {
|
|
1848
|
+
throw new httpException.HTTPException(400, { message: "runId required to observe stream" });
|
|
1849
|
+
}
|
|
1850
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1851
|
+
return streaming.stream(c2, async (stream5) => {
|
|
1852
|
+
try {
|
|
1853
|
+
disableHotReload();
|
|
1854
|
+
const result = await agentBuilder.observeStreamAgentBuilderActionHandler({
|
|
1855
|
+
mastra,
|
|
1856
|
+
actionId,
|
|
1857
|
+
runId
|
|
1858
|
+
});
|
|
1859
|
+
const reader = result?.getReader();
|
|
1860
|
+
if (!reader) {
|
|
1861
|
+
throw new Error("No reader available from observe stream");
|
|
1862
|
+
}
|
|
1863
|
+
stream5.onAbort(() => {
|
|
1864
|
+
void reader.cancel("request aborted");
|
|
1865
|
+
});
|
|
1866
|
+
let chunkResult;
|
|
1867
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1868
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1869
|
+
}
|
|
1870
|
+
enableHotReload();
|
|
1871
|
+
} catch (err) {
|
|
1872
|
+
enableHotReload();
|
|
1873
|
+
logger2.error("Error in observe stream: " + (err?.message ?? "Unknown error"));
|
|
1874
|
+
}
|
|
1875
|
+
});
|
|
1876
|
+
} catch (error) {
|
|
1877
|
+
enableHotReload();
|
|
1878
|
+
return handleError(error, "Error observing stream for agent builder action");
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
async function observeStreamVNextAgentBuilderActionHandler(c2) {
|
|
1882
|
+
try {
|
|
1883
|
+
const mastra = c2.get("mastra");
|
|
1884
|
+
const logger2 = mastra.getLogger();
|
|
1885
|
+
const actionId = c2.req.param("actionId");
|
|
1886
|
+
const runId = c2.req.query("runId");
|
|
1887
|
+
if (!runId) {
|
|
1888
|
+
throw new httpException.HTTPException(400, { message: "runId required to observe stream" });
|
|
1889
|
+
}
|
|
1890
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1891
|
+
return streaming.stream(c2, async (stream5) => {
|
|
1892
|
+
try {
|
|
1893
|
+
disableHotReload();
|
|
1894
|
+
const result = await agentBuilder.observeStreamVNextAgentBuilderActionHandler({
|
|
1895
|
+
mastra,
|
|
1896
|
+
actionId,
|
|
1897
|
+
runId
|
|
1898
|
+
});
|
|
1899
|
+
const reader = result?.getReader();
|
|
1900
|
+
if (!reader) {
|
|
1901
|
+
throw new Error("No reader available from observe stream VNext");
|
|
1902
|
+
}
|
|
1903
|
+
stream5.onAbort(() => {
|
|
1904
|
+
void reader.cancel("request aborted");
|
|
1905
|
+
});
|
|
1906
|
+
let chunkResult;
|
|
1907
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1908
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1909
|
+
}
|
|
1910
|
+
enableHotReload();
|
|
1911
|
+
} catch (err) {
|
|
1912
|
+
enableHotReload();
|
|
1913
|
+
logger2.error("Error in observe VNext stream: " + (err?.message ?? "Unknown error"));
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
} catch (error) {
|
|
1917
|
+
enableHotReload();
|
|
1918
|
+
return handleError(error, "Error observing VNext stream for agent builder action");
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
async function resumeStreamAgentBuilderActionHandler(c2) {
|
|
1922
|
+
try {
|
|
1923
|
+
const mastra = c2.get("mastra");
|
|
1924
|
+
const requestContext = c2.get("requestContext");
|
|
1925
|
+
const logger2 = mastra.getLogger();
|
|
1926
|
+
const actionId = c2.req.param("actionId");
|
|
1927
|
+
const runId = c2.req.query("runId");
|
|
1928
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
1929
|
+
if (!runId) {
|
|
1930
|
+
throw new httpException.HTTPException(400, { message: "runId required to resume stream" });
|
|
1931
|
+
}
|
|
1932
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1933
|
+
return streaming.stream(
|
|
1934
|
+
c2,
|
|
1935
|
+
async (stream5) => {
|
|
1936
|
+
try {
|
|
1937
|
+
disableHotReload();
|
|
1938
|
+
const result = await agentBuilder.resumeStreamAgentBuilderActionHandler({
|
|
1939
|
+
mastra,
|
|
1940
|
+
actionId,
|
|
1941
|
+
runId,
|
|
1942
|
+
requestContext,
|
|
1943
|
+
body: { step, resumeData },
|
|
1944
|
+
tracingOptions
|
|
1945
|
+
});
|
|
1946
|
+
const reader = result.getReader();
|
|
1947
|
+
stream5.onAbort(() => {
|
|
1948
|
+
void reader.cancel("request aborted");
|
|
1949
|
+
});
|
|
1950
|
+
let chunkResult;
|
|
1951
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1952
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1953
|
+
}
|
|
1954
|
+
} catch (err) {
|
|
1955
|
+
logger2.error("Error in resume stream: " + (err?.message ?? "Unknown error"));
|
|
1956
|
+
}
|
|
1957
|
+
enableHotReload();
|
|
1958
|
+
},
|
|
1959
|
+
async (err) => {
|
|
1960
|
+
logger2.error("Error in resume stream: " + err?.message);
|
|
1961
|
+
}
|
|
1962
|
+
);
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
enableHotReload();
|
|
1965
|
+
return handleError(error, "Error resuming stream for agent builder action");
|
|
1796
1966
|
}
|
|
1797
1967
|
}
|
|
1798
1968
|
|
|
@@ -1952,9 +2122,20 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
1952
2122
|
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
1953
2123
|
},
|
|
1954
2124
|
resumeData: { type: "object" },
|
|
1955
|
-
|
|
2125
|
+
requestContext: {
|
|
1956
2126
|
type: "object",
|
|
1957
|
-
description: "
|
|
2127
|
+
description: "Request Context for the agent builder action execution"
|
|
2128
|
+
},
|
|
2129
|
+
tracingOptions: {
|
|
2130
|
+
type: "object",
|
|
2131
|
+
description: "Tracing options for the action execution",
|
|
2132
|
+
properties: {
|
|
2133
|
+
metadata: {
|
|
2134
|
+
type: "object",
|
|
2135
|
+
description: "Custom metadata to attach to the trace",
|
|
2136
|
+
additionalProperties: true
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
1958
2139
|
}
|
|
1959
2140
|
}
|
|
1960
2141
|
}
|
|
@@ -1995,9 +2176,20 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
1995
2176
|
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
1996
2177
|
},
|
|
1997
2178
|
resumeData: { type: "object" },
|
|
1998
|
-
|
|
2179
|
+
requestContext: {
|
|
2180
|
+
type: "object",
|
|
2181
|
+
description: "Request Context for the agent builder action execution"
|
|
2182
|
+
},
|
|
2183
|
+
tracingOptions: {
|
|
1999
2184
|
type: "object",
|
|
2000
|
-
description: "
|
|
2185
|
+
description: "Tracing options for the action execution",
|
|
2186
|
+
properties: {
|
|
2187
|
+
metadata: {
|
|
2188
|
+
type: "object",
|
|
2189
|
+
description: "Custom metadata to attach to the trace",
|
|
2190
|
+
additionalProperties: true
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2001
2193
|
}
|
|
2002
2194
|
}
|
|
2003
2195
|
}
|
|
@@ -2008,9 +2200,10 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2008
2200
|
resumeAsyncAgentBuilderActionHandler
|
|
2009
2201
|
);
|
|
2010
2202
|
router.post(
|
|
2011
|
-
"/:actionId/stream",
|
|
2203
|
+
"/:actionId/resume-stream",
|
|
2012
2204
|
w({
|
|
2013
|
-
description: "
|
|
2205
|
+
description: "Resume a suspended agent builder action that uses streamVNext",
|
|
2206
|
+
tags: ["agent-builder"],
|
|
2014
2207
|
parameters: [
|
|
2015
2208
|
{
|
|
2016
2209
|
name: "actionId",
|
|
@@ -2021,7 +2214,7 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2021
2214
|
{
|
|
2022
2215
|
name: "runId",
|
|
2023
2216
|
in: "query",
|
|
2024
|
-
required:
|
|
2217
|
+
required: true,
|
|
2025
2218
|
schema: { type: "string" }
|
|
2026
2219
|
}
|
|
2027
2220
|
],
|
|
@@ -2032,32 +2225,38 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2032
2225
|
schema: {
|
|
2033
2226
|
type: "object",
|
|
2034
2227
|
properties: {
|
|
2035
|
-
|
|
2036
|
-
|
|
2228
|
+
step: {
|
|
2229
|
+
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
2230
|
+
},
|
|
2231
|
+
resumeData: { type: "object" },
|
|
2232
|
+
requestContext: {
|
|
2233
|
+
type: "object",
|
|
2234
|
+
description: "Request Context for the agent builder action execution"
|
|
2235
|
+
},
|
|
2236
|
+
tracingOptions: {
|
|
2037
2237
|
type: "object",
|
|
2038
|
-
description: "
|
|
2238
|
+
description: "Tracing options for the action execution",
|
|
2239
|
+
properties: {
|
|
2240
|
+
metadata: {
|
|
2241
|
+
type: "object",
|
|
2242
|
+
description: "Custom metadata to attach to the trace",
|
|
2243
|
+
additionalProperties: true
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2039
2246
|
}
|
|
2040
|
-
}
|
|
2247
|
+
},
|
|
2248
|
+
required: ["step"]
|
|
2041
2249
|
}
|
|
2042
2250
|
}
|
|
2043
2251
|
}
|
|
2044
|
-
}
|
|
2045
|
-
responses: {
|
|
2046
|
-
200: {
|
|
2047
|
-
description: "agent builder action run started"
|
|
2048
|
-
},
|
|
2049
|
-
404: {
|
|
2050
|
-
description: "agent builder action not found"
|
|
2051
|
-
}
|
|
2052
|
-
},
|
|
2053
|
-
tags: ["agent-builder"]
|
|
2252
|
+
}
|
|
2054
2253
|
}),
|
|
2055
|
-
|
|
2254
|
+
resumeStreamAgentBuilderActionHandler
|
|
2056
2255
|
);
|
|
2057
2256
|
router.post(
|
|
2058
|
-
"/:actionId/
|
|
2257
|
+
"/:actionId/stream-legacy",
|
|
2059
2258
|
w({
|
|
2060
|
-
description: "Stream agent builder action in real-time
|
|
2259
|
+
description: "Stream legacy agent builder action in real-time",
|
|
2061
2260
|
parameters: [
|
|
2062
2261
|
{
|
|
2063
2262
|
name: "actionId",
|
|
@@ -2080,9 +2279,20 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2080
2279
|
type: "object",
|
|
2081
2280
|
properties: {
|
|
2082
2281
|
inputData: { type: "object" },
|
|
2083
|
-
|
|
2282
|
+
requestContext: {
|
|
2084
2283
|
type: "object",
|
|
2085
|
-
description: "
|
|
2284
|
+
description: "Request Context for the agent builder action execution"
|
|
2285
|
+
},
|
|
2286
|
+
tracingOptions: {
|
|
2287
|
+
type: "object",
|
|
2288
|
+
description: "Tracing options for the action execution",
|
|
2289
|
+
properties: {
|
|
2290
|
+
metadata: {
|
|
2291
|
+
type: "object",
|
|
2292
|
+
description: "Custom metadata to attach to the trace",
|
|
2293
|
+
additionalProperties: true
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2086
2296
|
}
|
|
2087
2297
|
}
|
|
2088
2298
|
}
|
|
@@ -2099,14 +2309,12 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2099
2309
|
},
|
|
2100
2310
|
tags: ["agent-builder"]
|
|
2101
2311
|
}),
|
|
2102
|
-
|
|
2312
|
+
streamLegacyAgentBuilderActionHandler
|
|
2103
2313
|
);
|
|
2104
2314
|
router.post(
|
|
2105
|
-
"/:actionId/
|
|
2106
|
-
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2315
|
+
"/:actionId/observe-stream-legacy",
|
|
2107
2316
|
w({
|
|
2108
|
-
description: "
|
|
2109
|
-
tags: ["agent-builder"],
|
|
2317
|
+
description: "Observe agent builder action stream in real-time",
|
|
2110
2318
|
parameters: [
|
|
2111
2319
|
{
|
|
2112
2320
|
name: "actionId",
|
|
@@ -2117,24 +2325,26 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2117
2325
|
{
|
|
2118
2326
|
name: "runId",
|
|
2119
2327
|
in: "query",
|
|
2120
|
-
required:
|
|
2328
|
+
required: true,
|
|
2121
2329
|
schema: { type: "string" }
|
|
2122
2330
|
}
|
|
2123
2331
|
],
|
|
2124
2332
|
responses: {
|
|
2125
2333
|
200: {
|
|
2126
|
-
description: "
|
|
2334
|
+
description: "agent builder action stream observed"
|
|
2335
|
+
},
|
|
2336
|
+
404: {
|
|
2337
|
+
description: "agent builder action not found"
|
|
2127
2338
|
}
|
|
2128
|
-
}
|
|
2339
|
+
},
|
|
2340
|
+
tags: ["agent-builder"]
|
|
2129
2341
|
}),
|
|
2130
|
-
|
|
2342
|
+
observeStreamLegacyAgentBuilderActionHandler
|
|
2131
2343
|
);
|
|
2132
2344
|
router.post(
|
|
2133
|
-
"/:actionId/
|
|
2134
|
-
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2345
|
+
"/:actionId/stream",
|
|
2135
2346
|
w({
|
|
2136
|
-
description: "
|
|
2137
|
-
tags: ["agent-builder"],
|
|
2347
|
+
description: "Stream agent builder action in real-time",
|
|
2138
2348
|
parameters: [
|
|
2139
2349
|
{
|
|
2140
2350
|
name: "actionId",
|
|
@@ -2157,9 +2367,20 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2157
2367
|
type: "object",
|
|
2158
2368
|
properties: {
|
|
2159
2369
|
inputData: { type: "object" },
|
|
2160
|
-
|
|
2370
|
+
requestContext: {
|
|
2371
|
+
type: "object",
|
|
2372
|
+
description: "Request Context for the agent builder action execution"
|
|
2373
|
+
},
|
|
2374
|
+
tracingOptions: {
|
|
2161
2375
|
type: "object",
|
|
2162
|
-
description: "
|
|
2376
|
+
description: "Tracing options for the action execution",
|
|
2377
|
+
properties: {
|
|
2378
|
+
metadata: {
|
|
2379
|
+
type: "object",
|
|
2380
|
+
description: "Custom metadata to attach to the trace",
|
|
2381
|
+
additionalProperties: true
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2163
2384
|
}
|
|
2164
2385
|
}
|
|
2165
2386
|
}
|
|
@@ -2168,20 +2389,50 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2168
2389
|
},
|
|
2169
2390
|
responses: {
|
|
2170
2391
|
200: {
|
|
2171
|
-
description: "agent builder action
|
|
2392
|
+
description: "agent builder action run started"
|
|
2172
2393
|
},
|
|
2173
2394
|
404: {
|
|
2174
2395
|
description: "agent builder action not found"
|
|
2175
2396
|
}
|
|
2176
|
-
}
|
|
2397
|
+
},
|
|
2398
|
+
tags: ["agent-builder"]
|
|
2177
2399
|
}),
|
|
2178
|
-
|
|
2400
|
+
streamAgentBuilderActionHandler
|
|
2179
2401
|
);
|
|
2180
2402
|
router.post(
|
|
2181
|
-
"/:actionId/
|
|
2403
|
+
"/:actionId/observe",
|
|
2182
2404
|
w({
|
|
2183
|
-
description: "
|
|
2184
|
-
|
|
2405
|
+
description: "Observe agent builder action stream in real-time using the streaming API",
|
|
2406
|
+
parameters: [
|
|
2407
|
+
{
|
|
2408
|
+
name: "actionId",
|
|
2409
|
+
in: "path",
|
|
2410
|
+
required: true,
|
|
2411
|
+
schema: { type: "string" }
|
|
2412
|
+
},
|
|
2413
|
+
{
|
|
2414
|
+
name: "runId",
|
|
2415
|
+
in: "query",
|
|
2416
|
+
required: true,
|
|
2417
|
+
schema: { type: "string" }
|
|
2418
|
+
}
|
|
2419
|
+
],
|
|
2420
|
+
responses: {
|
|
2421
|
+
200: {
|
|
2422
|
+
description: "agent builder action stream observed"
|
|
2423
|
+
},
|
|
2424
|
+
404: {
|
|
2425
|
+
description: "agent builder action not found"
|
|
2426
|
+
}
|
|
2427
|
+
},
|
|
2428
|
+
tags: ["agent-builder"]
|
|
2429
|
+
}),
|
|
2430
|
+
observeStreamAgentBuilderActionHandler
|
|
2431
|
+
);
|
|
2432
|
+
router.post(
|
|
2433
|
+
"/:actionId/observe-streamVNext",
|
|
2434
|
+
w({
|
|
2435
|
+
description: "Observe agent builder action stream in real-time using the VNext streaming API",
|
|
2185
2436
|
parameters: [
|
|
2186
2437
|
{
|
|
2187
2438
|
name: "actionId",
|
|
@@ -2196,6 +2447,36 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2196
2447
|
schema: { type: "string" }
|
|
2197
2448
|
}
|
|
2198
2449
|
],
|
|
2450
|
+
responses: {
|
|
2451
|
+
200: {
|
|
2452
|
+
description: "agent builder action stream vNext observed"
|
|
2453
|
+
},
|
|
2454
|
+
404: {
|
|
2455
|
+
description: "agent builder action not found"
|
|
2456
|
+
}
|
|
2457
|
+
},
|
|
2458
|
+
tags: ["agent-builder"]
|
|
2459
|
+
}),
|
|
2460
|
+
observeStreamVNextAgentBuilderActionHandler
|
|
2461
|
+
);
|
|
2462
|
+
router.post(
|
|
2463
|
+
"/:actionId/streamVNext",
|
|
2464
|
+
w({
|
|
2465
|
+
description: "Stream agent builder action in real-time using the VNext streaming API",
|
|
2466
|
+
parameters: [
|
|
2467
|
+
{
|
|
2468
|
+
name: "actionId",
|
|
2469
|
+
in: "path",
|
|
2470
|
+
required: true,
|
|
2471
|
+
schema: { type: "string" }
|
|
2472
|
+
},
|
|
2473
|
+
{
|
|
2474
|
+
name: "runId",
|
|
2475
|
+
in: "query",
|
|
2476
|
+
required: false,
|
|
2477
|
+
schema: { type: "string" }
|
|
2478
|
+
}
|
|
2479
|
+
],
|
|
2199
2480
|
requestBody: {
|
|
2200
2481
|
required: true,
|
|
2201
2482
|
content: {
|
|
@@ -2204,9 +2485,24 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2204
2485
|
type: "object",
|
|
2205
2486
|
properties: {
|
|
2206
2487
|
inputData: { type: "object" },
|
|
2207
|
-
|
|
2488
|
+
requestContext: {
|
|
2489
|
+
type: "object",
|
|
2490
|
+
description: "Request Context for the agent builder action execution"
|
|
2491
|
+
},
|
|
2492
|
+
closeOnSuspend: {
|
|
2493
|
+
type: "boolean",
|
|
2494
|
+
description: "Close the stream on suspend"
|
|
2495
|
+
},
|
|
2496
|
+
tracingOptions: {
|
|
2208
2497
|
type: "object",
|
|
2209
|
-
description: "
|
|
2498
|
+
description: "Tracing options for the action execution",
|
|
2499
|
+
properties: {
|
|
2500
|
+
metadata: {
|
|
2501
|
+
type: "object",
|
|
2502
|
+
description: "Custom metadata to attach to the trace",
|
|
2503
|
+
additionalProperties: true
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2210
2506
|
}
|
|
2211
2507
|
}
|
|
2212
2508
|
}
|
|
@@ -2220,14 +2516,17 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2220
2516
|
404: {
|
|
2221
2517
|
description: "agent builder action not found"
|
|
2222
2518
|
}
|
|
2223
|
-
}
|
|
2519
|
+
},
|
|
2520
|
+
tags: ["agent-builder"]
|
|
2224
2521
|
}),
|
|
2225
|
-
|
|
2522
|
+
streamVNextAgentBuilderActionHandler
|
|
2226
2523
|
);
|
|
2227
|
-
router.
|
|
2228
|
-
"/:actionId/
|
|
2524
|
+
router.post(
|
|
2525
|
+
"/:actionId/create-run",
|
|
2526
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2229
2527
|
w({
|
|
2230
|
-
description: "
|
|
2528
|
+
description: "Create a new agent builder action run",
|
|
2529
|
+
tags: ["agent-builder"],
|
|
2231
2530
|
parameters: [
|
|
2232
2531
|
{
|
|
2233
2532
|
name: "actionId",
|
|
@@ -2240,27 +2539,22 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2240
2539
|
in: "query",
|
|
2241
2540
|
required: false,
|
|
2242
2541
|
schema: { type: "string" }
|
|
2243
|
-
},
|
|
2244
|
-
{
|
|
2245
|
-
name: "eventType",
|
|
2246
|
-
in: "query",
|
|
2247
|
-
required: false,
|
|
2248
|
-
schema: { type: "string", enum: ["watch", "watch-v2"] }
|
|
2249
2542
|
}
|
|
2250
2543
|
],
|
|
2251
|
-
tags: ["agent-builder"],
|
|
2252
2544
|
responses: {
|
|
2253
2545
|
200: {
|
|
2254
|
-
description: "agent builder action
|
|
2546
|
+
description: "New agent builder action run created"
|
|
2255
2547
|
}
|
|
2256
2548
|
}
|
|
2257
2549
|
}),
|
|
2258
|
-
|
|
2550
|
+
createAgentBuilderActionRunHandler
|
|
2259
2551
|
);
|
|
2260
2552
|
router.post(
|
|
2261
|
-
"/:actionId/
|
|
2553
|
+
"/:actionId/start-async",
|
|
2554
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
2262
2555
|
w({
|
|
2263
|
-
description: "
|
|
2556
|
+
description: "Execute/Start an agent builder action",
|
|
2557
|
+
tags: ["agent-builder"],
|
|
2264
2558
|
parameters: [
|
|
2265
2559
|
{
|
|
2266
2560
|
name: "actionId",
|
|
@@ -2270,24 +2564,55 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2270
2564
|
},
|
|
2271
2565
|
{
|
|
2272
2566
|
name: "runId",
|
|
2273
|
-
in: "
|
|
2274
|
-
required:
|
|
2567
|
+
in: "query",
|
|
2568
|
+
required: false,
|
|
2275
2569
|
schema: { type: "string" }
|
|
2276
2570
|
}
|
|
2277
2571
|
],
|
|
2278
|
-
|
|
2572
|
+
requestBody: {
|
|
2573
|
+
required: true,
|
|
2574
|
+
content: {
|
|
2575
|
+
"application/json": {
|
|
2576
|
+
schema: {
|
|
2577
|
+
type: "object",
|
|
2578
|
+
properties: {
|
|
2579
|
+
inputData: { type: "object" },
|
|
2580
|
+
requestContext: {
|
|
2581
|
+
type: "object",
|
|
2582
|
+
description: "Request Context for the agent builder action execution"
|
|
2583
|
+
},
|
|
2584
|
+
tracingOptions: {
|
|
2585
|
+
type: "object",
|
|
2586
|
+
description: "Tracing options for the action execution",
|
|
2587
|
+
properties: {
|
|
2588
|
+
metadata: {
|
|
2589
|
+
type: "object",
|
|
2590
|
+
description: "Custom metadata to attach to the trace",
|
|
2591
|
+
additionalProperties: true
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
},
|
|
2279
2600
|
responses: {
|
|
2280
2601
|
200: {
|
|
2281
|
-
description: "agent builder action
|
|
2602
|
+
description: "agent builder action execution result"
|
|
2603
|
+
},
|
|
2604
|
+
404: {
|
|
2605
|
+
description: "agent builder action not found"
|
|
2282
2606
|
}
|
|
2283
2607
|
}
|
|
2284
2608
|
}),
|
|
2285
|
-
|
|
2609
|
+
startAsyncAgentBuilderActionHandler
|
|
2286
2610
|
);
|
|
2287
2611
|
router.post(
|
|
2288
|
-
"/:actionId/
|
|
2612
|
+
"/:actionId/start",
|
|
2289
2613
|
w({
|
|
2290
|
-
description: "
|
|
2614
|
+
description: "Create and start a new agent builder action run",
|
|
2615
|
+
tags: ["agent-builder"],
|
|
2291
2616
|
parameters: [
|
|
2292
2617
|
{
|
|
2293
2618
|
name: "actionId",
|
|
@@ -2297,7 +2622,7 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2297
2622
|
},
|
|
2298
2623
|
{
|
|
2299
2624
|
name: "runId",
|
|
2300
|
-
in: "
|
|
2625
|
+
in: "query",
|
|
2301
2626
|
required: true,
|
|
2302
2627
|
schema: { type: "string" }
|
|
2303
2628
|
}
|
|
@@ -2306,18 +2631,67 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2306
2631
|
required: true,
|
|
2307
2632
|
content: {
|
|
2308
2633
|
"application/json": {
|
|
2309
|
-
schema: {
|
|
2634
|
+
schema: {
|
|
2635
|
+
type: "object",
|
|
2636
|
+
properties: {
|
|
2637
|
+
inputData: { type: "object" },
|
|
2638
|
+
requestContext: {
|
|
2639
|
+
type: "object",
|
|
2640
|
+
description: "Request Context for the agent builder action execution"
|
|
2641
|
+
},
|
|
2642
|
+
tracingOptions: {
|
|
2643
|
+
type: "object",
|
|
2644
|
+
description: "Tracing options for the action execution",
|
|
2645
|
+
properties: {
|
|
2646
|
+
metadata: {
|
|
2647
|
+
type: "object",
|
|
2648
|
+
description: "Custom metadata to attach to the trace",
|
|
2649
|
+
additionalProperties: true
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2310
2655
|
}
|
|
2311
2656
|
}
|
|
2312
2657
|
},
|
|
2658
|
+
responses: {
|
|
2659
|
+
200: {
|
|
2660
|
+
description: "agent builder action run started"
|
|
2661
|
+
},
|
|
2662
|
+
404: {
|
|
2663
|
+
description: "agent builder action not found"
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
}),
|
|
2667
|
+
startAgentBuilderActionRunHandler
|
|
2668
|
+
);
|
|
2669
|
+
router.post(
|
|
2670
|
+
"/:actionId/runs/:runId/cancel",
|
|
2671
|
+
w({
|
|
2672
|
+
description: "Cancel an agent builder action run",
|
|
2673
|
+
parameters: [
|
|
2674
|
+
{
|
|
2675
|
+
name: "actionId",
|
|
2676
|
+
in: "path",
|
|
2677
|
+
required: true,
|
|
2678
|
+
schema: { type: "string" }
|
|
2679
|
+
},
|
|
2680
|
+
{
|
|
2681
|
+
name: "runId",
|
|
2682
|
+
in: "path",
|
|
2683
|
+
required: true,
|
|
2684
|
+
schema: { type: "string" }
|
|
2685
|
+
}
|
|
2686
|
+
],
|
|
2313
2687
|
tags: ["agent-builder"],
|
|
2314
2688
|
responses: {
|
|
2315
2689
|
200: {
|
|
2316
|
-
description: "agent builder action run
|
|
2690
|
+
description: "agent builder action run cancelled"
|
|
2317
2691
|
}
|
|
2318
2692
|
}
|
|
2319
2693
|
}),
|
|
2320
|
-
|
|
2694
|
+
cancelAgentBuilderActionRunHandler
|
|
2321
2695
|
);
|
|
2322
2696
|
return router;
|
|
2323
2697
|
}
|
|
@@ -2337,26 +2711,6 @@ async function generateSystemPromptHandler(c2) {
|
|
|
2337
2711
|
if (!agent$1) {
|
|
2338
2712
|
return c2.json({ error: "Agent not found" }, 404);
|
|
2339
2713
|
}
|
|
2340
|
-
let evalSummary = "";
|
|
2341
|
-
try {
|
|
2342
|
-
const testEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent$1.name, "test") || [];
|
|
2343
|
-
const liveEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent$1.name, "live") || [];
|
|
2344
|
-
const evalsMapped = [...testEvals, ...liveEvals].filter(
|
|
2345
|
-
({ instructions: evalInstructions }) => evalInstructions === instructions
|
|
2346
|
-
);
|
|
2347
|
-
evalSummary = evalsMapped.map(
|
|
2348
|
-
({ input, output, result: result2 }) => `
|
|
2349
|
-
Input: ${input}
|
|
2350
|
-
|
|
2351
|
-
Output: ${output}
|
|
2352
|
-
|
|
2353
|
-
Result: ${JSON.stringify(result2)}
|
|
2354
|
-
|
|
2355
|
-
`
|
|
2356
|
-
).join("");
|
|
2357
|
-
} catch (error) {
|
|
2358
|
-
mastra.getLogger().error(`Error fetching evals`, { error });
|
|
2359
|
-
}
|
|
2360
2714
|
const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
|
|
2361
2715
|
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.
|
|
2362
2716
|
Follow these steps to analyze and enhance the instructions:
|
|
@@ -2405,24 +2759,24 @@ async function generateSystemPromptHandler(c2) {
|
|
|
2405
2759
|
Focus on creating prompts that are clear, actionable, and aligned with the intended use case.
|
|
2406
2760
|
`;
|
|
2407
2761
|
const systemPromptAgent = new agent.Agent({
|
|
2762
|
+
id: "system-prompt-enhancer",
|
|
2408
2763
|
name: "system-prompt-enhancer",
|
|
2409
2764
|
instructions: ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS,
|
|
2410
|
-
model: agent$1.
|
|
2765
|
+
model: await agent$1.getModel()
|
|
2411
2766
|
});
|
|
2412
2767
|
const result = await systemPromptAgent.generate(
|
|
2413
2768
|
`
|
|
2414
2769
|
We need to improve the system prompt.
|
|
2415
2770
|
Current: ${instructions}
|
|
2416
2771
|
${comment ? `User feedback: ${comment}` : ""}
|
|
2417
|
-
${evalSummary ? `
|
|
2418
|
-
Evaluation Results:
|
|
2419
|
-
${evalSummary}` : ""}
|
|
2420
2772
|
`,
|
|
2421
2773
|
{
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2774
|
+
structuredOutput: {
|
|
2775
|
+
schema: zod.z.object({
|
|
2776
|
+
new_prompt: zod.z.string(),
|
|
2777
|
+
explanation: zod.z.string()
|
|
2778
|
+
})
|
|
2779
|
+
}
|
|
2426
2780
|
}
|
|
2427
2781
|
);
|
|
2428
2782
|
return c2.json(result?.object || {});
|
|
@@ -2430,10 +2784,10 @@ ${evalSummary}` : ""}
|
|
|
2430
2784
|
return handleError(error, "Error generating system prompt");
|
|
2431
2785
|
}
|
|
2432
2786
|
}
|
|
2433
|
-
async function
|
|
2787
|
+
async function listToolsHandler(c2) {
|
|
2434
2788
|
try {
|
|
2435
2789
|
const tools = c2.get("tools");
|
|
2436
|
-
const result = await tools$1.
|
|
2790
|
+
const result = await tools$1.listToolsHandler({
|
|
2437
2791
|
tools
|
|
2438
2792
|
});
|
|
2439
2793
|
return c2.json(result || {});
|
|
@@ -2458,7 +2812,7 @@ function executeToolHandler(tools) {
|
|
|
2458
2812
|
return async (c2) => {
|
|
2459
2813
|
try {
|
|
2460
2814
|
const mastra = c2.get("mastra");
|
|
2461
|
-
const
|
|
2815
|
+
const requestContext = c2.get("requestContext");
|
|
2462
2816
|
const toolId = decodeURIComponent(c2.req.param("toolId"));
|
|
2463
2817
|
const runId = c2.req.query("runId");
|
|
2464
2818
|
const { data } = await c2.req.json();
|
|
@@ -2466,7 +2820,7 @@ function executeToolHandler(tools) {
|
|
|
2466
2820
|
mastra,
|
|
2467
2821
|
toolId,
|
|
2468
2822
|
data,
|
|
2469
|
-
|
|
2823
|
+
requestContext,
|
|
2470
2824
|
runId
|
|
2471
2825
|
});
|
|
2472
2826
|
return c2.json(result);
|
|
@@ -2478,14 +2832,14 @@ function executeToolHandler(tools) {
|
|
|
2478
2832
|
async function getAgentToolHandler(c2) {
|
|
2479
2833
|
try {
|
|
2480
2834
|
const mastra = c2.get("mastra");
|
|
2481
|
-
const
|
|
2835
|
+
const requestContext = c2.get("requestContext");
|
|
2482
2836
|
const agentId = c2.req.param("agentId");
|
|
2483
2837
|
const toolId = c2.req.param("toolId");
|
|
2484
2838
|
const result = await tools$1.getAgentToolHandler({
|
|
2485
2839
|
mastra,
|
|
2486
2840
|
agentId,
|
|
2487
2841
|
toolId,
|
|
2488
|
-
|
|
2842
|
+
requestContext
|
|
2489
2843
|
});
|
|
2490
2844
|
return c2.json(result);
|
|
2491
2845
|
} catch (error) {
|
|
@@ -2495,7 +2849,7 @@ async function getAgentToolHandler(c2) {
|
|
|
2495
2849
|
async function executeAgentToolHandler(c2) {
|
|
2496
2850
|
try {
|
|
2497
2851
|
const mastra = c2.get("mastra");
|
|
2498
|
-
const
|
|
2852
|
+
const requestContext = c2.get("requestContext");
|
|
2499
2853
|
const agentId = c2.req.param("agentId");
|
|
2500
2854
|
const toolId = c2.req.param("toolId");
|
|
2501
2855
|
const { data } = await c2.req.json();
|
|
@@ -2504,7 +2858,7 @@ async function executeAgentToolHandler(c2) {
|
|
|
2504
2858
|
agentId,
|
|
2505
2859
|
toolId,
|
|
2506
2860
|
data,
|
|
2507
|
-
|
|
2861
|
+
requestContext
|
|
2508
2862
|
});
|
|
2509
2863
|
return c2.json(result);
|
|
2510
2864
|
} catch (error) {
|
|
@@ -2575,10 +2929,10 @@ var vNextBodyOptions = {
|
|
|
2575
2929
|
},
|
|
2576
2930
|
...sharedBodyOptions
|
|
2577
2931
|
};
|
|
2578
|
-
async function
|
|
2579
|
-
const serializedAgents = await agents.
|
|
2932
|
+
async function listAgentsHandler(c2) {
|
|
2933
|
+
const serializedAgents = await agents.listAgentsHandler({
|
|
2580
2934
|
mastra: c2.get("mastra"),
|
|
2581
|
-
|
|
2935
|
+
requestContext: c2.get("requestContext")
|
|
2582
2936
|
});
|
|
2583
2937
|
return c2.json(serializedAgents);
|
|
2584
2938
|
}
|
|
@@ -2606,48 +2960,26 @@ async function getProvidersHandler(c2) {
|
|
|
2606
2960
|
async function getAgentByIdHandler(c2) {
|
|
2607
2961
|
const mastra = c2.get("mastra");
|
|
2608
2962
|
const agentId = c2.req.param("agentId");
|
|
2609
|
-
const
|
|
2963
|
+
const requestContext = c2.get("requestContext");
|
|
2610
2964
|
const isPlayground = c2.req.header("x-mastra-dev-playground") === "true";
|
|
2611
2965
|
const result = await agents.getAgentByIdHandler({
|
|
2612
2966
|
mastra,
|
|
2613
2967
|
agentId,
|
|
2614
|
-
|
|
2968
|
+
requestContext,
|
|
2615
2969
|
isPlayground
|
|
2616
2970
|
});
|
|
2617
2971
|
return c2.json(result);
|
|
2618
2972
|
}
|
|
2619
|
-
async function getEvalsByAgentIdHandler(c2) {
|
|
2620
|
-
const mastra = c2.get("mastra");
|
|
2621
|
-
const agentId = c2.req.param("agentId");
|
|
2622
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
2623
|
-
const result = await agents.getEvalsByAgentIdHandler({
|
|
2624
|
-
mastra,
|
|
2625
|
-
agentId,
|
|
2626
|
-
runtimeContext
|
|
2627
|
-
});
|
|
2628
|
-
return c2.json(result);
|
|
2629
|
-
}
|
|
2630
|
-
async function getLiveEvalsByAgentIdHandler(c2) {
|
|
2631
|
-
const mastra = c2.get("mastra");
|
|
2632
|
-
const agentId = c2.req.param("agentId");
|
|
2633
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
2634
|
-
const result = await agents.getLiveEvalsByAgentIdHandler({
|
|
2635
|
-
mastra,
|
|
2636
|
-
agentId,
|
|
2637
|
-
runtimeContext
|
|
2638
|
-
});
|
|
2639
|
-
return c2.json(result);
|
|
2640
|
-
}
|
|
2641
2973
|
async function generateLegacyHandler(c2) {
|
|
2642
2974
|
try {
|
|
2643
2975
|
const mastra = c2.get("mastra");
|
|
2644
2976
|
const agentId = c2.req.param("agentId");
|
|
2645
|
-
const
|
|
2977
|
+
const requestContext = c2.get("requestContext");
|
|
2646
2978
|
const body = await c2.req.json();
|
|
2647
2979
|
const result = await agents.generateLegacyHandler({
|
|
2648
2980
|
mastra,
|
|
2649
2981
|
agentId,
|
|
2650
|
-
|
|
2982
|
+
requestContext,
|
|
2651
2983
|
body,
|
|
2652
2984
|
abortSignal: c2.req.raw.signal
|
|
2653
2985
|
});
|
|
@@ -2660,12 +2992,12 @@ async function generateHandler(c2) {
|
|
|
2660
2992
|
try {
|
|
2661
2993
|
const mastra = c2.get("mastra");
|
|
2662
2994
|
const agentId = c2.req.param("agentId");
|
|
2663
|
-
const
|
|
2995
|
+
const requestContext = c2.get("requestContext");
|
|
2664
2996
|
const body = await c2.req.json();
|
|
2665
2997
|
const result = await agents.generateHandler({
|
|
2666
2998
|
mastra,
|
|
2667
2999
|
agentId,
|
|
2668
|
-
|
|
3000
|
+
requestContext,
|
|
2669
3001
|
body,
|
|
2670
3002
|
abortSignal: c2.req.raw.signal
|
|
2671
3003
|
});
|
|
@@ -2678,12 +3010,12 @@ async function streamGenerateLegacyHandler(c2) {
|
|
|
2678
3010
|
try {
|
|
2679
3011
|
const mastra = c2.get("mastra");
|
|
2680
3012
|
const agentId = c2.req.param("agentId");
|
|
2681
|
-
const
|
|
3013
|
+
const requestContext = c2.get("requestContext");
|
|
2682
3014
|
const body = await c2.req.json();
|
|
2683
3015
|
const streamResponse = await agents.streamGenerateLegacyHandler({
|
|
2684
3016
|
mastra,
|
|
2685
3017
|
agentId,
|
|
2686
|
-
|
|
3018
|
+
requestContext,
|
|
2687
3019
|
body,
|
|
2688
3020
|
abortSignal: c2.req.raw.signal
|
|
2689
3021
|
});
|
|
@@ -2695,7 +3027,7 @@ async function streamGenerateLegacyHandler(c2) {
|
|
|
2695
3027
|
async function streamGenerateHandler(c2) {
|
|
2696
3028
|
const mastra = c2.get("mastra");
|
|
2697
3029
|
const agentId = c2.req.param("agentId");
|
|
2698
|
-
const
|
|
3030
|
+
const requestContext = c2.get("requestContext");
|
|
2699
3031
|
const body = await c2.req.json();
|
|
2700
3032
|
const logger2 = mastra.getLogger();
|
|
2701
3033
|
let streamResponse;
|
|
@@ -2703,7 +3035,7 @@ async function streamGenerateHandler(c2) {
|
|
|
2703
3035
|
streamResponse = await agents.streamGenerateHandler({
|
|
2704
3036
|
mastra,
|
|
2705
3037
|
agentId,
|
|
2706
|
-
|
|
3038
|
+
requestContext,
|
|
2707
3039
|
body,
|
|
2708
3040
|
abortSignal: c2.req.raw.signal
|
|
2709
3041
|
});
|
|
@@ -2713,19 +3045,19 @@ async function streamGenerateHandler(c2) {
|
|
|
2713
3045
|
c2.header("Transfer-Encoding", "chunked");
|
|
2714
3046
|
return streaming.stream(
|
|
2715
3047
|
c2,
|
|
2716
|
-
async (
|
|
3048
|
+
async (stream5) => {
|
|
2717
3049
|
try {
|
|
2718
3050
|
const reader = streamResponse.fullStream.getReader();
|
|
2719
|
-
|
|
3051
|
+
stream5.onAbort(() => {
|
|
2720
3052
|
void reader.cancel("request aborted");
|
|
2721
3053
|
});
|
|
2722
3054
|
let chunkResult;
|
|
2723
3055
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2724
|
-
await
|
|
3056
|
+
await stream5.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2725
3057
|
|
|
2726
3058
|
`);
|
|
2727
3059
|
}
|
|
2728
|
-
await
|
|
3060
|
+
await stream5.write("data: [DONE]\n\n");
|
|
2729
3061
|
} catch (err) {
|
|
2730
3062
|
logger2.error("Error in stream generate: " + (err?.message ?? "Unknown error"));
|
|
2731
3063
|
const errorChunk = {
|
|
@@ -2736,11 +3068,11 @@ async function streamGenerateHandler(c2) {
|
|
|
2736
3068
|
error: error.getErrorFromUnknown(err, { fallbackMessage: "Unknown error in stream generate" })
|
|
2737
3069
|
}
|
|
2738
3070
|
};
|
|
2739
|
-
await
|
|
3071
|
+
await stream5.write(`data: ${JSON.stringify(errorChunk)}
|
|
2740
3072
|
|
|
2741
3073
|
`);
|
|
2742
3074
|
}
|
|
2743
|
-
await
|
|
3075
|
+
await stream5.close();
|
|
2744
3076
|
},
|
|
2745
3077
|
async (err) => {
|
|
2746
3078
|
logger2.error("Error in watch stream: " + err?.message);
|
|
@@ -2750,14 +3082,14 @@ async function streamGenerateHandler(c2) {
|
|
|
2750
3082
|
async function approveToolCallHandler(c2) {
|
|
2751
3083
|
const mastra = c2.get("mastra");
|
|
2752
3084
|
const agentId = c2.req.param("agentId");
|
|
2753
|
-
const
|
|
3085
|
+
const requestContext = c2.get("requestContext");
|
|
2754
3086
|
const body = await c2.req.json();
|
|
2755
3087
|
const logger2 = mastra.getLogger();
|
|
2756
3088
|
let streamResponse;
|
|
2757
3089
|
try {
|
|
2758
3090
|
streamResponse = await agents.approveToolCallHandler({
|
|
2759
3091
|
mastra,
|
|
2760
|
-
|
|
3092
|
+
requestContext,
|
|
2761
3093
|
agentId,
|
|
2762
3094
|
body,
|
|
2763
3095
|
abortSignal: c2.req.raw.signal
|
|
@@ -2768,19 +3100,19 @@ async function approveToolCallHandler(c2) {
|
|
|
2768
3100
|
c2.header("Transfer-Encoding", "chunked");
|
|
2769
3101
|
return streaming.stream(
|
|
2770
3102
|
c2,
|
|
2771
|
-
async (
|
|
3103
|
+
async (stream5) => {
|
|
2772
3104
|
try {
|
|
2773
3105
|
const reader = streamResponse.fullStream.getReader();
|
|
2774
|
-
|
|
3106
|
+
stream5.onAbort(() => {
|
|
2775
3107
|
void reader.cancel("request aborted");
|
|
2776
3108
|
});
|
|
2777
3109
|
let chunkResult;
|
|
2778
3110
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2779
|
-
await
|
|
3111
|
+
await stream5.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2780
3112
|
|
|
2781
3113
|
`);
|
|
2782
3114
|
}
|
|
2783
|
-
await
|
|
3115
|
+
await stream5.write("data: [DONE]\n\n");
|
|
2784
3116
|
} catch (err) {
|
|
2785
3117
|
logger2.error("Error in approve tool call: " + (err?.message ?? "Unknown error"));
|
|
2786
3118
|
const errorChunk = {
|
|
@@ -2795,11 +3127,11 @@ async function approveToolCallHandler(c2) {
|
|
|
2795
3127
|
} : String(err)
|
|
2796
3128
|
}
|
|
2797
3129
|
};
|
|
2798
|
-
await
|
|
3130
|
+
await stream5.write(`data: ${JSON.stringify(errorChunk)}
|
|
2799
3131
|
|
|
2800
3132
|
`);
|
|
2801
3133
|
}
|
|
2802
|
-
await
|
|
3134
|
+
await stream5.close();
|
|
2803
3135
|
},
|
|
2804
3136
|
async (err) => {
|
|
2805
3137
|
logger2.error("Error in watch stream: " + err?.message);
|
|
@@ -2809,14 +3141,14 @@ async function approveToolCallHandler(c2) {
|
|
|
2809
3141
|
async function declineToolCallHandler(c2) {
|
|
2810
3142
|
const mastra = c2.get("mastra");
|
|
2811
3143
|
const agentId = c2.req.param("agentId");
|
|
2812
|
-
const
|
|
3144
|
+
const requestContext = c2.get("requestContext");
|
|
2813
3145
|
const body = await c2.req.json();
|
|
2814
3146
|
const logger2 = mastra.getLogger();
|
|
2815
3147
|
let streamResponse;
|
|
2816
3148
|
try {
|
|
2817
3149
|
streamResponse = await agents.declineToolCallHandler({
|
|
2818
3150
|
mastra,
|
|
2819
|
-
|
|
3151
|
+
requestContext,
|
|
2820
3152
|
agentId,
|
|
2821
3153
|
body,
|
|
2822
3154
|
abortSignal: c2.req.raw.signal
|
|
@@ -2827,19 +3159,19 @@ async function declineToolCallHandler(c2) {
|
|
|
2827
3159
|
c2.header("Transfer-Encoding", "chunked");
|
|
2828
3160
|
return streaming.stream(
|
|
2829
3161
|
c2,
|
|
2830
|
-
async (
|
|
3162
|
+
async (stream5) => {
|
|
2831
3163
|
try {
|
|
2832
3164
|
const reader = streamResponse.fullStream.getReader();
|
|
2833
|
-
|
|
3165
|
+
stream5.onAbort(() => {
|
|
2834
3166
|
void reader.cancel("request aborted");
|
|
2835
3167
|
});
|
|
2836
3168
|
let chunkResult;
|
|
2837
3169
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2838
|
-
await
|
|
3170
|
+
await stream5.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2839
3171
|
|
|
2840
3172
|
`);
|
|
2841
3173
|
}
|
|
2842
|
-
await
|
|
3174
|
+
await stream5.write("data: [DONE]\n\n");
|
|
2843
3175
|
} catch (err) {
|
|
2844
3176
|
logger2.error("Error in decline tool call: " + (err?.message ?? "Unknown error"));
|
|
2845
3177
|
const errorChunk = {
|
|
@@ -2854,11 +3186,11 @@ async function declineToolCallHandler(c2) {
|
|
|
2854
3186
|
} : String(err)
|
|
2855
3187
|
}
|
|
2856
3188
|
};
|
|
2857
|
-
await
|
|
3189
|
+
await stream5.write(`data: ${JSON.stringify(errorChunk)}
|
|
2858
3190
|
|
|
2859
3191
|
`);
|
|
2860
3192
|
}
|
|
2861
|
-
await
|
|
3193
|
+
await stream5.close();
|
|
2862
3194
|
},
|
|
2863
3195
|
async (err) => {
|
|
2864
3196
|
logger2.error("Error in watch stream: " + err?.message);
|
|
@@ -2868,11 +3200,11 @@ async function declineToolCallHandler(c2) {
|
|
|
2868
3200
|
async function streamNetworkHandler(c2) {
|
|
2869
3201
|
const mastra = c2.get("mastra");
|
|
2870
3202
|
const agentId = c2.req.param("agentId");
|
|
2871
|
-
const
|
|
3203
|
+
const requestContext = c2.get("requestContext");
|
|
2872
3204
|
const body = await c2.req.json();
|
|
2873
3205
|
const logger2 = mastra.getLogger();
|
|
2874
3206
|
const agent = await agents.getAgentFromSystem({ mastra, agentId });
|
|
2875
|
-
const memory = await agent.getMemory({
|
|
3207
|
+
const memory = await agent.getMemory({ requestContext });
|
|
2876
3208
|
if (!memory) {
|
|
2877
3209
|
return handleError(
|
|
2878
3210
|
new error.MastraError({
|
|
@@ -2892,7 +3224,7 @@ async function streamNetworkHandler(c2) {
|
|
|
2892
3224
|
streamResponse = await agents.streamNetworkHandler({
|
|
2893
3225
|
mastra,
|
|
2894
3226
|
agentId,
|
|
2895
|
-
|
|
3227
|
+
requestContext,
|
|
2896
3228
|
body
|
|
2897
3229
|
// abortSignal: c.req.raw.signal,
|
|
2898
3230
|
});
|
|
@@ -2902,19 +3234,19 @@ async function streamNetworkHandler(c2) {
|
|
|
2902
3234
|
c2.header("Transfer-Encoding", "chunked");
|
|
2903
3235
|
return streaming.stream(
|
|
2904
3236
|
c2,
|
|
2905
|
-
async (
|
|
3237
|
+
async (stream5) => {
|
|
2906
3238
|
try {
|
|
2907
3239
|
const reader = streamResponse.getReader();
|
|
2908
|
-
|
|
3240
|
+
stream5.onAbort(() => {
|
|
2909
3241
|
void reader.cancel("request aborted");
|
|
2910
3242
|
});
|
|
2911
3243
|
let chunkResult;
|
|
2912
3244
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2913
|
-
await
|
|
3245
|
+
await stream5.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2914
3246
|
|
|
2915
3247
|
`);
|
|
2916
3248
|
}
|
|
2917
|
-
await
|
|
3249
|
+
await stream5.write("data: [DONE]\n\n");
|
|
2918
3250
|
} catch (err) {
|
|
2919
3251
|
logger2.error("Error in streamNetwork generate: " + (err?.message ?? "Unknown error"));
|
|
2920
3252
|
const errorChunk = {
|
|
@@ -2929,11 +3261,11 @@ async function streamNetworkHandler(c2) {
|
|
|
2929
3261
|
} : String(err)
|
|
2930
3262
|
}
|
|
2931
3263
|
};
|
|
2932
|
-
await
|
|
3264
|
+
await stream5.write(`data: ${JSON.stringify(errorChunk)}
|
|
2933
3265
|
|
|
2934
3266
|
`);
|
|
2935
3267
|
}
|
|
2936
|
-
await
|
|
3268
|
+
await stream5.close();
|
|
2937
3269
|
},
|
|
2938
3270
|
async (err) => {
|
|
2939
3271
|
logger2.error("Error in watch stream: " + err?.message);
|
|
@@ -2944,12 +3276,12 @@ async function streamUIMessageHandler(c2) {
|
|
|
2944
3276
|
try {
|
|
2945
3277
|
const mastra = c2.get("mastra");
|
|
2946
3278
|
const agentId = c2.req.param("agentId");
|
|
2947
|
-
const
|
|
3279
|
+
const requestContext = c2.get("requestContext");
|
|
2948
3280
|
const body = await c2.req.json();
|
|
2949
3281
|
const streamResponse = await agents.streamUIMessageHandler({
|
|
2950
3282
|
mastra,
|
|
2951
3283
|
agentId,
|
|
2952
|
-
|
|
3284
|
+
requestContext,
|
|
2953
3285
|
body,
|
|
2954
3286
|
abortSignal: c2.req.raw.signal
|
|
2955
3287
|
});
|
|
@@ -3058,11 +3390,11 @@ async function getSpeakersHandler(c2) {
|
|
|
3058
3390
|
try {
|
|
3059
3391
|
const mastra = c2.get("mastra");
|
|
3060
3392
|
const agentId = c2.req.param("agentId");
|
|
3061
|
-
const
|
|
3393
|
+
const requestContext = c2.get("requestContext");
|
|
3062
3394
|
const speakers = await voice.getSpeakersHandler({
|
|
3063
3395
|
mastra,
|
|
3064
3396
|
agentId,
|
|
3065
|
-
|
|
3397
|
+
requestContext
|
|
3066
3398
|
});
|
|
3067
3399
|
return c2.json(speakers);
|
|
3068
3400
|
} catch (error) {
|
|
@@ -3073,12 +3405,12 @@ async function speakHandler(c2) {
|
|
|
3073
3405
|
try {
|
|
3074
3406
|
const mastra = c2.get("mastra");
|
|
3075
3407
|
const agentId = c2.req.param("agentId");
|
|
3076
|
-
const
|
|
3408
|
+
const requestContext = c2.get("requestContext");
|
|
3077
3409
|
const { input, options } = await c2.req.json();
|
|
3078
3410
|
const audioStream = await voice.generateSpeechHandler({
|
|
3079
3411
|
mastra,
|
|
3080
3412
|
agentId,
|
|
3081
|
-
|
|
3413
|
+
requestContext,
|
|
3082
3414
|
body: { text: input, speakerId: options?.speakerId }
|
|
3083
3415
|
});
|
|
3084
3416
|
c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
|
|
@@ -3092,11 +3424,11 @@ async function getListenerHandler(c2) {
|
|
|
3092
3424
|
try {
|
|
3093
3425
|
const mastra = c2.get("mastra");
|
|
3094
3426
|
const agentId = c2.req.param("agentId");
|
|
3095
|
-
const
|
|
3427
|
+
const requestContext = c2.get("requestContext");
|
|
3096
3428
|
const listeners = await voice.getListenerHandler({
|
|
3097
3429
|
mastra,
|
|
3098
3430
|
agentId,
|
|
3099
|
-
|
|
3431
|
+
requestContext
|
|
3100
3432
|
});
|
|
3101
3433
|
return c2.json(listeners);
|
|
3102
3434
|
} catch (error) {
|
|
@@ -3107,7 +3439,7 @@ async function listenHandler(c2) {
|
|
|
3107
3439
|
try {
|
|
3108
3440
|
const mastra = c2.get("mastra");
|
|
3109
3441
|
const agentId = c2.req.param("agentId");
|
|
3110
|
-
const
|
|
3442
|
+
const requestContext = c2.get("requestContext");
|
|
3111
3443
|
const formData = await c2.req.formData();
|
|
3112
3444
|
const audioFile = formData.get("audio");
|
|
3113
3445
|
const options = formData.get("options");
|
|
@@ -3123,7 +3455,7 @@ async function listenHandler(c2) {
|
|
|
3123
3455
|
const transcription = await voice.transcribeSpeechHandler({
|
|
3124
3456
|
mastra,
|
|
3125
3457
|
agentId,
|
|
3126
|
-
|
|
3458
|
+
requestContext,
|
|
3127
3459
|
body: {
|
|
3128
3460
|
audioData: Buffer.from(audioData),
|
|
3129
3461
|
options: parsedOptions
|
|
@@ -3149,7 +3481,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3149
3481
|
}
|
|
3150
3482
|
}
|
|
3151
3483
|
}),
|
|
3152
|
-
|
|
3484
|
+
listAgentsHandler
|
|
3153
3485
|
);
|
|
3154
3486
|
router.get(
|
|
3155
3487
|
"/providers",
|
|
@@ -3188,48 +3520,6 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3188
3520
|
}),
|
|
3189
3521
|
getAgentByIdHandler
|
|
3190
3522
|
);
|
|
3191
|
-
router.get(
|
|
3192
|
-
"/:agentId/evals/ci",
|
|
3193
|
-
w({
|
|
3194
|
-
description: "Get CI evals by agent ID",
|
|
3195
|
-
tags: ["agents"],
|
|
3196
|
-
parameters: [
|
|
3197
|
-
{
|
|
3198
|
-
name: "agentId",
|
|
3199
|
-
in: "path",
|
|
3200
|
-
required: true,
|
|
3201
|
-
schema: { type: "string" }
|
|
3202
|
-
}
|
|
3203
|
-
],
|
|
3204
|
-
responses: {
|
|
3205
|
-
200: {
|
|
3206
|
-
description: "List of evals"
|
|
3207
|
-
}
|
|
3208
|
-
}
|
|
3209
|
-
}),
|
|
3210
|
-
getEvalsByAgentIdHandler
|
|
3211
|
-
);
|
|
3212
|
-
router.get(
|
|
3213
|
-
"/:agentId/evals/live",
|
|
3214
|
-
w({
|
|
3215
|
-
description: "Get live evals by agent ID",
|
|
3216
|
-
tags: ["agents"],
|
|
3217
|
-
parameters: [
|
|
3218
|
-
{
|
|
3219
|
-
name: "agentId",
|
|
3220
|
-
in: "path",
|
|
3221
|
-
required: true,
|
|
3222
|
-
schema: { type: "string" }
|
|
3223
|
-
}
|
|
3224
|
-
],
|
|
3225
|
-
responses: {
|
|
3226
|
-
200: {
|
|
3227
|
-
description: "List of evals"
|
|
3228
|
-
}
|
|
3229
|
-
}
|
|
3230
|
-
}),
|
|
3231
|
-
getLiveEvalsByAgentIdHandler
|
|
3232
|
-
);
|
|
3233
3523
|
router.post(
|
|
3234
3524
|
"/:agentId/generate-legacy",
|
|
3235
3525
|
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
@@ -3719,7 +4009,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3719
4009
|
"/:agentId/stream/vnext/ui",
|
|
3720
4010
|
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3721
4011
|
w({
|
|
3722
|
-
description: "[DEPRECATED] This endpoint is deprecated. Please use /
|
|
4012
|
+
description: "[DEPRECATED] This endpoint is deprecated. Please use the @mastra/ai-sdk package to for uiMessage transformations",
|
|
3723
4013
|
tags: ["agents"],
|
|
3724
4014
|
deprecated: true,
|
|
3725
4015
|
parameters: [
|
|
@@ -3757,8 +4047,9 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3757
4047
|
"/:agentId/stream/ui",
|
|
3758
4048
|
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3759
4049
|
w({
|
|
3760
|
-
description: "
|
|
4050
|
+
description: "[DEPRECATED] This endpoint is deprecated. Please use the @mastra/ai-sdk package to for uiMessage transformations",
|
|
3761
4051
|
tags: ["agents"],
|
|
4052
|
+
deprecated: true,
|
|
3762
4053
|
parameters: [
|
|
3763
4054
|
{
|
|
3764
4055
|
name: "agentId",
|
|
@@ -4440,7 +4731,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
4440
4731
|
type: "object",
|
|
4441
4732
|
properties: {
|
|
4442
4733
|
data: { type: "object" },
|
|
4443
|
-
|
|
4734
|
+
requestContext: { type: "object" }
|
|
4444
4735
|
},
|
|
4445
4736
|
required: ["data"]
|
|
4446
4737
|
}
|
|
@@ -4481,7 +4772,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
4481
4772
|
properties: {
|
|
4482
4773
|
runId: { type: "string", description: "The run ID for the execution" },
|
|
4483
4774
|
toolCallId: { type: "string", description: "The tool call ID for the execution" },
|
|
4484
|
-
|
|
4775
|
+
requestContext: { type: "object", description: "Request Context for the execution" },
|
|
4485
4776
|
format: { type: "string", enum: ["aisdk", "mastra"], description: "Output format" }
|
|
4486
4777
|
},
|
|
4487
4778
|
required: ["runId", "toolCallId"]
|
|
@@ -4523,7 +4814,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
4523
4814
|
properties: {
|
|
4524
4815
|
runId: { type: "string", description: "The run ID for the execution" },
|
|
4525
4816
|
toolCallId: { type: "string", description: "The tool call ID for the execution" },
|
|
4526
|
-
|
|
4817
|
+
requestContext: { type: "object", description: "Request Context for the execution" },
|
|
4527
4818
|
format: { type: "string", enum: ["aisdk", "mastra"], description: "Output format" }
|
|
4528
4819
|
},
|
|
4529
4820
|
required: ["runId", "toolCallId"]
|
|
@@ -4663,12 +4954,12 @@ function agentsRouterDev(bodyLimitOptions) {
|
|
|
4663
4954
|
);
|
|
4664
4955
|
return router;
|
|
4665
4956
|
}
|
|
4666
|
-
async function
|
|
4957
|
+
async function listLogsHandler(c2) {
|
|
4667
4958
|
try {
|
|
4668
4959
|
const mastra = c2.get("mastra");
|
|
4669
4960
|
const { transportId, fromDate, toDate, logLevel, page, perPage } = c2.req.query();
|
|
4670
4961
|
const filters = c2.req.queries("filters");
|
|
4671
|
-
const logs$1 = await logs.
|
|
4962
|
+
const logs$1 = await logs.listLogsHandler({
|
|
4672
4963
|
mastra,
|
|
4673
4964
|
transportId,
|
|
4674
4965
|
params: {
|
|
@@ -4685,13 +4976,13 @@ async function getLogsHandler(c2) {
|
|
|
4685
4976
|
return handleError(error, "Error getting logs");
|
|
4686
4977
|
}
|
|
4687
4978
|
}
|
|
4688
|
-
async function
|
|
4979
|
+
async function listLogsByRunIdHandler(c2) {
|
|
4689
4980
|
try {
|
|
4690
4981
|
const mastra = c2.get("mastra");
|
|
4691
4982
|
const runId = c2.req.param("runId");
|
|
4692
4983
|
const { transportId, fromDate, toDate, logLevel, page, perPage } = c2.req.query();
|
|
4693
4984
|
const filters = c2.req.queries("filters");
|
|
4694
|
-
const logs$1 = await logs.
|
|
4985
|
+
const logs$1 = await logs.listLogsByRunIdHandler({
|
|
4695
4986
|
mastra,
|
|
4696
4987
|
runId,
|
|
4697
4988
|
transportId,
|
|
@@ -4709,10 +5000,10 @@ async function getLogsByRunIdHandler(c2) {
|
|
|
4709
5000
|
return handleError(error, "Error getting logs by run ID");
|
|
4710
5001
|
}
|
|
4711
5002
|
}
|
|
4712
|
-
async function
|
|
5003
|
+
async function listLogTransports(c2) {
|
|
4713
5004
|
try {
|
|
4714
5005
|
const mastra = c2.get("mastra");
|
|
4715
|
-
const result = await logs.
|
|
5006
|
+
const result = await logs.listLogTransports({
|
|
4716
5007
|
mastra
|
|
4717
5008
|
});
|
|
4718
5009
|
return c2.json(result);
|
|
@@ -4779,7 +5070,7 @@ function logsRouter() {
|
|
|
4779
5070
|
}
|
|
4780
5071
|
}
|
|
4781
5072
|
}),
|
|
4782
|
-
|
|
5073
|
+
listLogsHandler
|
|
4783
5074
|
);
|
|
4784
5075
|
router.get(
|
|
4785
5076
|
"/transports",
|
|
@@ -4792,7 +5083,7 @@ function logsRouter() {
|
|
|
4792
5083
|
}
|
|
4793
5084
|
}
|
|
4794
5085
|
}),
|
|
4795
|
-
|
|
5086
|
+
listLogTransports
|
|
4796
5087
|
);
|
|
4797
5088
|
router.get(
|
|
4798
5089
|
"/:runId",
|
|
@@ -4855,7 +5146,7 @@ function logsRouter() {
|
|
|
4855
5146
|
}
|
|
4856
5147
|
}
|
|
4857
5148
|
}),
|
|
4858
|
-
|
|
5149
|
+
listLogsByRunIdHandler
|
|
4859
5150
|
);
|
|
4860
5151
|
return router;
|
|
4861
5152
|
}
|
|
@@ -6722,11 +7013,11 @@ var getMcpServerMessageHandler = async (c2) => {
|
|
|
6722
7013
|
const mastra = getMastra(c2);
|
|
6723
7014
|
const serverId = c2.req.param("serverId");
|
|
6724
7015
|
const { req, res } = toReqRes(c2.req.raw);
|
|
6725
|
-
const server = mastra.
|
|
7016
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6726
7017
|
if (!server) {
|
|
6727
7018
|
res.writeHead(404, { "Content-Type": "application/json" });
|
|
6728
7019
|
res.end(JSON.stringify({ error: `MCP server '${serverId}' not found` }));
|
|
6729
|
-
return;
|
|
7020
|
+
return await toFetchResponse(res);
|
|
6730
7021
|
}
|
|
6731
7022
|
try {
|
|
6732
7023
|
await server.startHTTP({
|
|
@@ -6750,15 +7041,17 @@ var getMcpServerMessageHandler = async (c2) => {
|
|
|
6750
7041
|
// Cannot determine original request ID in catch
|
|
6751
7042
|
})
|
|
6752
7043
|
);
|
|
7044
|
+
return await toFetchResponse(res);
|
|
6753
7045
|
} else {
|
|
6754
7046
|
c2.get("logger")?.error("Error after headers sent:", error);
|
|
7047
|
+
return await toFetchResponse(res);
|
|
6755
7048
|
}
|
|
6756
7049
|
}
|
|
6757
7050
|
};
|
|
6758
7051
|
var getMcpServerSseHandler = async (c2) => {
|
|
6759
7052
|
const mastra = getMastra(c2);
|
|
6760
7053
|
const serverId = c2.req.param("serverId");
|
|
6761
|
-
const server = mastra.
|
|
7054
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6762
7055
|
if (!server) {
|
|
6763
7056
|
return c2.json({ error: `MCP server '${serverId}' not found` }, 404);
|
|
6764
7057
|
}
|
|
@@ -6779,13 +7072,13 @@ var getMcpServerSseHandler = async (c2) => {
|
|
|
6779
7072
|
};
|
|
6780
7073
|
var listMcpRegistryServersHandler = async (c2) => {
|
|
6781
7074
|
const mastra = getMastra(c2);
|
|
6782
|
-
if (!mastra || typeof mastra.
|
|
6783
|
-
c2.get("logger")?.error("Mastra instance or
|
|
6784
|
-
return c2.json({ error: "Mastra instance or
|
|
7075
|
+
if (!mastra || typeof mastra.listMCPServers !== "function") {
|
|
7076
|
+
c2.get("logger")?.error("Mastra instance or listMCPServers method not available in listMcpRegistryServersHandler");
|
|
7077
|
+
return c2.json({ error: "Mastra instance or listMCPServers method not available" }, 500);
|
|
6785
7078
|
}
|
|
6786
|
-
const mcpServersMap = mastra.
|
|
7079
|
+
const mcpServersMap = mastra.listMCPServers();
|
|
6787
7080
|
if (!mcpServersMap) {
|
|
6788
|
-
c2.get("logger")?.warn("
|
|
7081
|
+
c2.get("logger")?.warn("listMCPServers returned undefined or null in listMcpRegistryServersHandler");
|
|
6789
7082
|
return c2.json({ servers: [], next: null, total_count: 0 });
|
|
6790
7083
|
}
|
|
6791
7084
|
const allServersArray = Array.from(
|
|
@@ -6814,11 +7107,13 @@ var getMcpRegistryServerDetailHandler = async (c2) => {
|
|
|
6814
7107
|
const mastra = getMastra(c2);
|
|
6815
7108
|
const serverId = c2.req.param("id");
|
|
6816
7109
|
const requestedVersion = c2.req.query("version");
|
|
6817
|
-
if (!mastra || typeof mastra.
|
|
6818
|
-
c2.get("logger")?.error(
|
|
6819
|
-
|
|
7110
|
+
if (!mastra || typeof mastra.getMCPServerById !== "function") {
|
|
7111
|
+
c2.get("logger")?.error(
|
|
7112
|
+
"Mastra instance or getMCPServerById method not available in getMcpRegistryServerDetailHandler"
|
|
7113
|
+
);
|
|
7114
|
+
return c2.json({ error: "Mastra instance or getMCPServerById method not available" }, 500);
|
|
6820
7115
|
}
|
|
6821
|
-
const server = mastra.
|
|
7116
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6822
7117
|
if (!server) {
|
|
6823
7118
|
return c2.json({ error: `MCP server with ID '${serverId}' not found` }, 404);
|
|
6824
7119
|
}
|
|
@@ -6840,11 +7135,11 @@ var getMcpRegistryServerDetailHandler = async (c2) => {
|
|
|
6840
7135
|
var listMcpServerToolsHandler = async (c2) => {
|
|
6841
7136
|
const mastra = getMastra(c2);
|
|
6842
7137
|
const serverId = c2.req.param("serverId");
|
|
6843
|
-
if (!mastra || typeof mastra.
|
|
6844
|
-
c2.get("logger")?.error("Mastra instance or
|
|
6845
|
-
return c2.json({ error: "Mastra instance or
|
|
7138
|
+
if (!mastra || typeof mastra.getMCPServerById !== "function") {
|
|
7139
|
+
c2.get("logger")?.error("Mastra instance or getMCPServerById method not available in listMcpServerToolsHandler");
|
|
7140
|
+
return c2.json({ error: "Mastra instance or getMCPServerById method not available" }, 500);
|
|
6846
7141
|
}
|
|
6847
|
-
const server = mastra.
|
|
7142
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6848
7143
|
if (!server) {
|
|
6849
7144
|
return c2.json({ error: `MCP server with ID '${serverId}' not found` }, 404);
|
|
6850
7145
|
}
|
|
@@ -6864,11 +7159,11 @@ var getMcpServerToolDetailHandler = async (c2) => {
|
|
|
6864
7159
|
const mastra = getMastra(c2);
|
|
6865
7160
|
const serverId = c2.req.param("serverId");
|
|
6866
7161
|
const toolId = c2.req.param("toolId");
|
|
6867
|
-
if (!mastra || typeof mastra.
|
|
6868
|
-
c2.get("logger")?.error("Mastra instance or
|
|
6869
|
-
return c2.json({ error: "Mastra instance or
|
|
7162
|
+
if (!mastra || typeof mastra.getMCPServerById !== "function") {
|
|
7163
|
+
c2.get("logger")?.error("Mastra instance or getMCPServerById method not available in getMcpServerToolDetailHandler");
|
|
7164
|
+
return c2.json({ error: "Mastra instance or getMCPServerById method not available" }, 500);
|
|
6870
7165
|
}
|
|
6871
|
-
const server = mastra.
|
|
7166
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6872
7167
|
if (!server) {
|
|
6873
7168
|
return c2.json({ error: `MCP server with ID '${serverId}' not found` }, 404);
|
|
6874
7169
|
}
|
|
@@ -6893,11 +7188,11 @@ var executeMcpServerToolHandler = async (c2) => {
|
|
|
6893
7188
|
const mastra = getMastra(c2);
|
|
6894
7189
|
const serverId = c2.req.param("serverId");
|
|
6895
7190
|
const toolId = c2.req.param("toolId");
|
|
6896
|
-
if (!mastra || typeof mastra.
|
|
6897
|
-
c2.get("logger")?.error("Mastra instance or
|
|
6898
|
-
return c2.json({ error: "Mastra instance or
|
|
7191
|
+
if (!mastra || typeof mastra.getMCPServerById !== "function") {
|
|
7192
|
+
c2.get("logger")?.error("Mastra instance or getMCPServerById method not available in executeMcpServerToolHandler");
|
|
7193
|
+
return c2.json({ error: "Mastra instance or getMCPServerById method not available" }, 500);
|
|
6899
7194
|
}
|
|
6900
|
-
const server = mastra.
|
|
7195
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6901
7196
|
if (!server) {
|
|
6902
7197
|
return c2.json({ error: `MCP server with ID '${serverId}' not found` }, 404);
|
|
6903
7198
|
}
|
|
@@ -6908,8 +7203,8 @@ var executeMcpServerToolHandler = async (c2) => {
|
|
|
6908
7203
|
try {
|
|
6909
7204
|
const body = await c2.req.json();
|
|
6910
7205
|
const args = body?.data;
|
|
6911
|
-
const
|
|
6912
|
-
const result = await server.executeTool(toolId, args,
|
|
7206
|
+
const requestContext = body?.requestContext;
|
|
7207
|
+
const result = await server.executeTool(toolId, args, requestContext);
|
|
6913
7208
|
return c2.json({ result });
|
|
6914
7209
|
} catch (error) {
|
|
6915
7210
|
c2.get("logger")?.error(`Error executing tool '${toolId}' on server '${serverId}':`, { error: error.message });
|
|
@@ -7311,7 +7606,7 @@ function mcpRouter(bodyLimitOptions) {
|
|
|
7311
7606
|
type: "object",
|
|
7312
7607
|
properties: {
|
|
7313
7608
|
data: { type: "object" },
|
|
7314
|
-
|
|
7609
|
+
requestContext: { type: "object" }
|
|
7315
7610
|
}
|
|
7316
7611
|
}
|
|
7317
7612
|
}
|
|
@@ -7341,17 +7636,38 @@ function parseLimit(rawLimit) {
|
|
|
7341
7636
|
}
|
|
7342
7637
|
return void 0;
|
|
7343
7638
|
}
|
|
7639
|
+
function parsePage(value, defaultValue = 0) {
|
|
7640
|
+
const parsed = parseInt(value || String(defaultValue), 10);
|
|
7641
|
+
return isNaN(parsed) ? defaultValue : Math.max(0, parsed);
|
|
7642
|
+
}
|
|
7643
|
+
function parsePerPage(value, defaultValue = 100, max = 1e3) {
|
|
7644
|
+
const normalized = (value || "").trim().toLowerCase();
|
|
7645
|
+
if (normalized === "false") {
|
|
7646
|
+
return false;
|
|
7647
|
+
}
|
|
7648
|
+
const parsed = parseInt(value || String(defaultValue), 10);
|
|
7649
|
+
if (isNaN(parsed)) return defaultValue;
|
|
7650
|
+
return Math.min(max, Math.max(1, parsed));
|
|
7651
|
+
}
|
|
7344
7652
|
|
|
7345
7653
|
// src/server/handlers/routes/memory/handlers.ts
|
|
7654
|
+
function parseJsonParam(value) {
|
|
7655
|
+
if (!value) return void 0;
|
|
7656
|
+
try {
|
|
7657
|
+
return JSON.parse(value);
|
|
7658
|
+
} catch {
|
|
7659
|
+
return void 0;
|
|
7660
|
+
}
|
|
7661
|
+
}
|
|
7346
7662
|
async function getMemoryStatusHandler(c2) {
|
|
7347
7663
|
try {
|
|
7348
7664
|
const mastra = c2.get("mastra");
|
|
7349
7665
|
const agentId = c2.req.query("agentId");
|
|
7350
|
-
const
|
|
7666
|
+
const requestContext = c2.get("requestContext");
|
|
7351
7667
|
const result = await memory.getMemoryStatusHandler({
|
|
7352
7668
|
mastra,
|
|
7353
7669
|
agentId,
|
|
7354
|
-
|
|
7670
|
+
requestContext
|
|
7355
7671
|
});
|
|
7356
7672
|
return c2.json(result);
|
|
7357
7673
|
} catch (error) {
|
|
@@ -7362,61 +7678,51 @@ async function getMemoryConfigHandler(c2) {
|
|
|
7362
7678
|
try {
|
|
7363
7679
|
const mastra = c2.get("mastra");
|
|
7364
7680
|
const agentId = c2.req.query("agentId");
|
|
7365
|
-
const
|
|
7681
|
+
const requestContext = c2.get("requestContext");
|
|
7366
7682
|
const result = await memory.getMemoryConfigHandler({
|
|
7367
7683
|
mastra,
|
|
7368
7684
|
agentId,
|
|
7369
|
-
|
|
7685
|
+
requestContext
|
|
7370
7686
|
});
|
|
7371
7687
|
return c2.json(result);
|
|
7372
7688
|
} catch (error) {
|
|
7373
7689
|
return handleError(error, "Error getting memory configuration");
|
|
7374
7690
|
}
|
|
7375
7691
|
}
|
|
7376
|
-
async function
|
|
7377
|
-
try {
|
|
7378
|
-
const mastra = c2.get("mastra");
|
|
7379
|
-
const agentId = c2.req.query("agentId");
|
|
7380
|
-
const resourceId = c2.req.query("resourceid");
|
|
7381
|
-
const orderBy = c2.req.query("orderBy");
|
|
7382
|
-
const sortDirection = c2.req.query("sortDirection");
|
|
7383
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
7384
|
-
const result = await memory.getThreadsHandler({
|
|
7385
|
-
mastra,
|
|
7386
|
-
agentId,
|
|
7387
|
-
resourceId,
|
|
7388
|
-
orderBy,
|
|
7389
|
-
sortDirection,
|
|
7390
|
-
runtimeContext
|
|
7391
|
-
});
|
|
7392
|
-
return c2.json(result);
|
|
7393
|
-
} catch (error) {
|
|
7394
|
-
return handleError(error, "Error getting threads");
|
|
7395
|
-
}
|
|
7396
|
-
}
|
|
7397
|
-
async function getThreadsPaginatedHandler(c2) {
|
|
7692
|
+
async function listThreadsHandler(c2) {
|
|
7398
7693
|
try {
|
|
7399
7694
|
const mastra = c2.get("mastra");
|
|
7400
7695
|
const agentId = c2.req.query("agentId");
|
|
7401
7696
|
const resourceId = c2.req.query("resourceId");
|
|
7402
|
-
const page =
|
|
7403
|
-
const perPage =
|
|
7404
|
-
const
|
|
7405
|
-
const
|
|
7406
|
-
const
|
|
7407
|
-
const
|
|
7697
|
+
const page = parsePage(c2.req.query("page"));
|
|
7698
|
+
const perPage = parsePerPage(c2.req.query("perPage"));
|
|
7699
|
+
const field = c2.req.query("orderBy");
|
|
7700
|
+
const direction = c2.req.query("sortDirection");
|
|
7701
|
+
const requestContext = c2.get("requestContext");
|
|
7702
|
+
const validFields = ["createdAt", "updatedAt"];
|
|
7703
|
+
const validDirections = ["ASC", "DESC"];
|
|
7704
|
+
if (field && !validFields.includes(field)) {
|
|
7705
|
+
return c2.json({ error: `Invalid orderBy field: ${field}. Must be one of: ${validFields.join(", ")}` }, 400);
|
|
7706
|
+
}
|
|
7707
|
+
if (direction && !validDirections.includes(direction)) {
|
|
7708
|
+
return c2.json(
|
|
7709
|
+
{ error: `Invalid sortDirection: ${direction}. Must be one of: ${validDirections.join(", ")}` },
|
|
7710
|
+
400
|
|
7711
|
+
);
|
|
7712
|
+
}
|
|
7713
|
+
const orderBy = field || direction ? { field: field || "createdAt", direction: direction || "DESC" } : void 0;
|
|
7714
|
+
const result = await memory.listThreadsHandler({
|
|
7408
7715
|
mastra,
|
|
7409
7716
|
agentId,
|
|
7410
7717
|
resourceId,
|
|
7411
7718
|
page,
|
|
7412
7719
|
perPage,
|
|
7413
7720
|
orderBy,
|
|
7414
|
-
|
|
7415
|
-
runtimeContext
|
|
7721
|
+
requestContext
|
|
7416
7722
|
});
|
|
7417
7723
|
return c2.json(result);
|
|
7418
7724
|
} catch (error) {
|
|
7419
|
-
return handleError(error, "Error
|
|
7725
|
+
return handleError(error, "Error listing threads");
|
|
7420
7726
|
}
|
|
7421
7727
|
}
|
|
7422
7728
|
async function getThreadByIdHandler(c2) {
|
|
@@ -7424,12 +7730,12 @@ async function getThreadByIdHandler(c2) {
|
|
|
7424
7730
|
const mastra = c2.get("mastra");
|
|
7425
7731
|
const agentId = c2.req.query("agentId");
|
|
7426
7732
|
const threadId = c2.req.param("threadId");
|
|
7427
|
-
const
|
|
7733
|
+
const requestContext = c2.get("requestContext");
|
|
7428
7734
|
const result = await memory.getThreadByIdHandler({
|
|
7429
7735
|
mastra,
|
|
7430
7736
|
agentId,
|
|
7431
7737
|
threadId,
|
|
7432
|
-
|
|
7738
|
+
requestContext
|
|
7433
7739
|
});
|
|
7434
7740
|
return c2.json(result);
|
|
7435
7741
|
} catch (error) {
|
|
@@ -7441,12 +7747,12 @@ async function saveMessagesHandler(c2) {
|
|
|
7441
7747
|
const mastra = c2.get("mastra");
|
|
7442
7748
|
const agentId = c2.req.query("agentId");
|
|
7443
7749
|
const body = await c2.req.json();
|
|
7444
|
-
const
|
|
7750
|
+
const requestContext = c2.get("requestContext");
|
|
7445
7751
|
const result = await memory.saveMessagesHandler({
|
|
7446
7752
|
mastra,
|
|
7447
7753
|
agentId,
|
|
7448
7754
|
body,
|
|
7449
|
-
|
|
7755
|
+
requestContext
|
|
7450
7756
|
});
|
|
7451
7757
|
return c2.json(result);
|
|
7452
7758
|
} catch (error) {
|
|
@@ -7458,12 +7764,12 @@ async function createThreadHandler(c2) {
|
|
|
7458
7764
|
const mastra = c2.get("mastra");
|
|
7459
7765
|
const agentId = c2.req.query("agentId");
|
|
7460
7766
|
const body = await c2.req.json();
|
|
7461
|
-
const
|
|
7767
|
+
const requestContext = c2.get("requestContext");
|
|
7462
7768
|
const result = await memory.createThreadHandler({
|
|
7463
7769
|
mastra,
|
|
7464
7770
|
agentId,
|
|
7465
7771
|
body,
|
|
7466
|
-
|
|
7772
|
+
requestContext
|
|
7467
7773
|
});
|
|
7468
7774
|
return c2.json(result);
|
|
7469
7775
|
} catch (error) {
|
|
@@ -7476,13 +7782,13 @@ async function updateThreadHandler(c2) {
|
|
|
7476
7782
|
const agentId = c2.req.query("agentId");
|
|
7477
7783
|
const threadId = c2.req.param("threadId");
|
|
7478
7784
|
const body = await c2.req.json();
|
|
7479
|
-
const
|
|
7785
|
+
const requestContext = c2.get("requestContext");
|
|
7480
7786
|
const result = await memory.updateThreadHandler({
|
|
7481
7787
|
mastra,
|
|
7482
7788
|
agentId,
|
|
7483
7789
|
threadId,
|
|
7484
7790
|
body,
|
|
7485
|
-
|
|
7791
|
+
requestContext
|
|
7486
7792
|
});
|
|
7487
7793
|
return c2.json(result);
|
|
7488
7794
|
} catch (error) {
|
|
@@ -7494,57 +7800,41 @@ async function deleteThreadHandler(c2) {
|
|
|
7494
7800
|
const mastra = c2.get("mastra");
|
|
7495
7801
|
const agentId = c2.req.query("agentId");
|
|
7496
7802
|
const threadId = c2.req.param("threadId");
|
|
7497
|
-
const
|
|
7803
|
+
const requestContext = c2.get("requestContext");
|
|
7498
7804
|
const result = await memory.deleteThreadHandler({
|
|
7499
7805
|
mastra,
|
|
7500
7806
|
agentId,
|
|
7501
7807
|
threadId,
|
|
7502
|
-
|
|
7808
|
+
requestContext
|
|
7503
7809
|
});
|
|
7504
7810
|
return c2.json(result);
|
|
7505
7811
|
} catch (error) {
|
|
7506
7812
|
return handleError(error, "Error deleting thread");
|
|
7507
7813
|
}
|
|
7508
7814
|
}
|
|
7509
|
-
async function
|
|
7815
|
+
async function listMessagesHandler(c2) {
|
|
7510
7816
|
try {
|
|
7511
7817
|
const mastra = c2.get("mastra");
|
|
7512
7818
|
const agentId = c2.req.query("agentId");
|
|
7513
7819
|
const threadId = c2.req.param("threadId");
|
|
7514
|
-
const limit = parseLimit(c2.req.query("limit"));
|
|
7515
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
7516
|
-
const result = await memory.getMessagesHandler({
|
|
7517
|
-
mastra,
|
|
7518
|
-
agentId,
|
|
7519
|
-
threadId,
|
|
7520
|
-
limit,
|
|
7521
|
-
runtimeContext
|
|
7522
|
-
});
|
|
7523
|
-
return c2.json(result);
|
|
7524
|
-
} catch (error) {
|
|
7525
|
-
return handleError(error, "Error getting messages");
|
|
7526
|
-
}
|
|
7527
|
-
}
|
|
7528
|
-
async function getMessagesPaginatedHandler(c2) {
|
|
7529
|
-
try {
|
|
7530
|
-
const mastra = c2.get("mastra");
|
|
7531
|
-
const threadId = c2.req.param("threadId");
|
|
7532
7820
|
const resourceId = c2.req.query("resourceId");
|
|
7533
|
-
const
|
|
7534
|
-
const
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
}
|
|
7541
|
-
}
|
|
7542
|
-
const result = await memory.getMessagesPaginatedHandler({
|
|
7821
|
+
const page = parsePage(c2.req.query("page"));
|
|
7822
|
+
const perPage = parsePerPage(c2.req.query("perPage"));
|
|
7823
|
+
const orderBy = parseJsonParam(c2.req.query("orderBy"));
|
|
7824
|
+
const include = parseJsonParam(c2.req.query("include"));
|
|
7825
|
+
const filter = parseJsonParam(c2.req.query("filter"));
|
|
7826
|
+
const requestContext = c2.get("requestContext");
|
|
7827
|
+
const result = await memory.listMessagesHandler({
|
|
7543
7828
|
mastra,
|
|
7829
|
+
agentId,
|
|
7544
7830
|
threadId,
|
|
7545
7831
|
resourceId,
|
|
7546
|
-
|
|
7547
|
-
|
|
7832
|
+
page,
|
|
7833
|
+
perPage,
|
|
7834
|
+
orderBy,
|
|
7835
|
+
include,
|
|
7836
|
+
filter,
|
|
7837
|
+
requestContext
|
|
7548
7838
|
});
|
|
7549
7839
|
return c2.json(result);
|
|
7550
7840
|
} catch (error) {
|
|
@@ -7557,13 +7847,13 @@ async function updateWorkingMemoryHandler(c2) {
|
|
|
7557
7847
|
const agentId = c2.req.query("agentId");
|
|
7558
7848
|
const threadId = c2.req.param("threadId");
|
|
7559
7849
|
const body = await c2.req.json();
|
|
7560
|
-
const
|
|
7850
|
+
const requestContext = c2.get("requestContext");
|
|
7561
7851
|
const result = await memory.updateWorkingMemoryHandler({
|
|
7562
7852
|
mastra,
|
|
7563
7853
|
agentId,
|
|
7564
7854
|
threadId,
|
|
7565
7855
|
body,
|
|
7566
|
-
|
|
7856
|
+
requestContext
|
|
7567
7857
|
});
|
|
7568
7858
|
return c2.json(result);
|
|
7569
7859
|
} catch (error) {
|
|
@@ -7576,13 +7866,13 @@ async function getWorkingMemoryHandler(c2) {
|
|
|
7576
7866
|
const agentId = c2.req.query("agentId");
|
|
7577
7867
|
const threadId = c2.req.param("threadId");
|
|
7578
7868
|
const resourceId = c2.req.query("resourceId");
|
|
7579
|
-
const
|
|
7869
|
+
const requestContext = c2.get("requestContext");
|
|
7580
7870
|
const result = await memory.getWorkingMemoryHandler({
|
|
7581
7871
|
mastra,
|
|
7582
7872
|
agentId,
|
|
7583
7873
|
threadId,
|
|
7584
7874
|
resourceId,
|
|
7585
|
-
|
|
7875
|
+
requestContext
|
|
7586
7876
|
});
|
|
7587
7877
|
return c2.json(result);
|
|
7588
7878
|
} catch (error) {
|
|
@@ -7598,7 +7888,7 @@ async function searchMemoryHandler(c2) {
|
|
|
7598
7888
|
const threadId = c2.req.query("threadId");
|
|
7599
7889
|
const limit = parseLimit(c2.req.query("limit"));
|
|
7600
7890
|
const memoryConfig = c2.req.query("memoryConfig") ? JSON.parse(c2.req.query("memoryConfig")) : void 0;
|
|
7601
|
-
const
|
|
7891
|
+
const requestContext = c2.get("requestContext");
|
|
7602
7892
|
const result = await memory.searchMemoryHandler({
|
|
7603
7893
|
mastra,
|
|
7604
7894
|
agentId,
|
|
@@ -7607,7 +7897,7 @@ async function searchMemoryHandler(c2) {
|
|
|
7607
7897
|
threadId,
|
|
7608
7898
|
limit,
|
|
7609
7899
|
memoryConfig,
|
|
7610
|
-
|
|
7900
|
+
requestContext
|
|
7611
7901
|
});
|
|
7612
7902
|
return c2.json(result);
|
|
7613
7903
|
} catch (error) {
|
|
@@ -7618,14 +7908,14 @@ async function deleteMessagesHandler(c2) {
|
|
|
7618
7908
|
try {
|
|
7619
7909
|
const mastra = c2.get("mastra");
|
|
7620
7910
|
const agentId = c2.req.query("agentId");
|
|
7621
|
-
const
|
|
7911
|
+
const requestContext = c2.get("requestContext");
|
|
7622
7912
|
const body = await c2.req.json();
|
|
7623
7913
|
const messageIds = body?.messageIds;
|
|
7624
7914
|
const result = await memory.deleteMessagesHandler({
|
|
7625
7915
|
mastra,
|
|
7626
7916
|
agentId,
|
|
7627
7917
|
messageIds,
|
|
7628
|
-
|
|
7918
|
+
requestContext
|
|
7629
7919
|
});
|
|
7630
7920
|
return c2.json(result);
|
|
7631
7921
|
} catch (error) {
|
|
@@ -7675,6 +7965,20 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
7675
7965
|
required: true,
|
|
7676
7966
|
schema: { type: "string" }
|
|
7677
7967
|
},
|
|
7968
|
+
{
|
|
7969
|
+
name: "offset",
|
|
7970
|
+
in: "query",
|
|
7971
|
+
required: false,
|
|
7972
|
+
schema: { type: "number", default: 0 },
|
|
7973
|
+
description: "Number of records to skip"
|
|
7974
|
+
},
|
|
7975
|
+
{
|
|
7976
|
+
name: "limit",
|
|
7977
|
+
in: "query",
|
|
7978
|
+
required: false,
|
|
7979
|
+
schema: { type: "number", default: 100 },
|
|
7980
|
+
description: "Maximum number of threads to return"
|
|
7981
|
+
},
|
|
7678
7982
|
{
|
|
7679
7983
|
name: "orderBy",
|
|
7680
7984
|
in: "query",
|
|
@@ -7704,7 +8008,7 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
7704
8008
|
}
|
|
7705
8009
|
}
|
|
7706
8010
|
}),
|
|
7707
|
-
|
|
8011
|
+
listThreadsHandler
|
|
7708
8012
|
);
|
|
7709
8013
|
router.get(
|
|
7710
8014
|
"/network/threads/:threadId",
|
|
@@ -7739,14 +8043,17 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
7739
8043
|
router.get(
|
|
7740
8044
|
"/network/threads/:threadId/messages",
|
|
7741
8045
|
w({
|
|
7742
|
-
description: "Get messages for a thread",
|
|
8046
|
+
description: "Get paginated messages for a thread",
|
|
7743
8047
|
tags: ["networkMemory"],
|
|
7744
8048
|
parameters: [
|
|
7745
8049
|
{
|
|
7746
8050
|
name: "threadId",
|
|
7747
8051
|
in: "path",
|
|
7748
8052
|
required: true,
|
|
7749
|
-
|
|
8053
|
+
description: "The unique identifier of the thread",
|
|
8054
|
+
schema: {
|
|
8055
|
+
type: "string"
|
|
8056
|
+
}
|
|
7750
8057
|
},
|
|
7751
8058
|
{
|
|
7752
8059
|
name: "networkId",
|
|
@@ -7755,20 +8062,85 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
7755
8062
|
schema: { type: "string" }
|
|
7756
8063
|
},
|
|
7757
8064
|
{
|
|
7758
|
-
name: "
|
|
8065
|
+
name: "agentId",
|
|
8066
|
+
in: "query",
|
|
8067
|
+
required: true,
|
|
8068
|
+
description: "The unique identifier of the agent",
|
|
8069
|
+
schema: {
|
|
8070
|
+
type: "string"
|
|
8071
|
+
}
|
|
8072
|
+
},
|
|
8073
|
+
{
|
|
8074
|
+
name: "resourceId",
|
|
7759
8075
|
in: "query",
|
|
7760
8076
|
required: false,
|
|
7761
|
-
|
|
7762
|
-
|
|
8077
|
+
description: "Filter messages by resource ID",
|
|
8078
|
+
schema: {
|
|
8079
|
+
type: "string"
|
|
8080
|
+
}
|
|
8081
|
+
},
|
|
8082
|
+
{
|
|
8083
|
+
name: "page",
|
|
8084
|
+
in: "query",
|
|
8085
|
+
required: false,
|
|
8086
|
+
description: "Zero-indexed page number for pagination (default: 0)",
|
|
8087
|
+
schema: {
|
|
8088
|
+
type: "integer",
|
|
8089
|
+
minimum: 0,
|
|
8090
|
+
default: 0
|
|
8091
|
+
}
|
|
8092
|
+
},
|
|
8093
|
+
{
|
|
8094
|
+
name: "perPage",
|
|
8095
|
+
in: "query",
|
|
8096
|
+
required: false,
|
|
8097
|
+
description: 'Number of items per page, or "false" to fetch all records (default: 40)',
|
|
8098
|
+
schema: {
|
|
8099
|
+
oneOf: [
|
|
8100
|
+
{ type: "integer", minimum: 0 },
|
|
8101
|
+
{ type: "boolean", enum: [false] }
|
|
8102
|
+
],
|
|
8103
|
+
default: 40
|
|
8104
|
+
}
|
|
8105
|
+
},
|
|
8106
|
+
{
|
|
8107
|
+
name: "orderBy",
|
|
8108
|
+
in: "query",
|
|
8109
|
+
required: false,
|
|
8110
|
+
description: "JSON string specifying sort order",
|
|
8111
|
+
schema: {
|
|
8112
|
+
type: "string",
|
|
8113
|
+
example: '{"field":"createdAt","direction":"DESC"}'
|
|
8114
|
+
}
|
|
8115
|
+
},
|
|
8116
|
+
{
|
|
8117
|
+
name: "include",
|
|
8118
|
+
in: "query",
|
|
8119
|
+
required: false,
|
|
8120
|
+
description: "JSON string specifying messages to include with context",
|
|
8121
|
+
schema: {
|
|
8122
|
+
type: "string",
|
|
8123
|
+
example: '[{"id":"msg-123","withPreviousMessages":5,"withNextMessages":3}]'
|
|
8124
|
+
}
|
|
8125
|
+
},
|
|
8126
|
+
{
|
|
8127
|
+
name: "filter",
|
|
8128
|
+
in: "query",
|
|
8129
|
+
required: false,
|
|
8130
|
+
description: "JSON string specifying filter criteria",
|
|
8131
|
+
schema: {
|
|
8132
|
+
type: "string",
|
|
8133
|
+
example: '{"dateRange":{"start":"2024-01-01T00:00:00Z","end":"2024-12-31T23:59:59Z"}}'
|
|
8134
|
+
}
|
|
7763
8135
|
}
|
|
7764
8136
|
],
|
|
7765
8137
|
responses: {
|
|
7766
8138
|
200: {
|
|
7767
|
-
description: "
|
|
8139
|
+
description: "Paginated list of messages with metadata"
|
|
7768
8140
|
}
|
|
7769
8141
|
}
|
|
7770
8142
|
}),
|
|
7771
|
-
|
|
8143
|
+
listMessagesHandler
|
|
7772
8144
|
);
|
|
7773
8145
|
router.post(
|
|
7774
8146
|
"/network/threads",
|
|
@@ -8134,55 +8506,6 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8134
8506
|
);
|
|
8135
8507
|
router.get(
|
|
8136
8508
|
"/threads",
|
|
8137
|
-
w({
|
|
8138
|
-
description: "Get all threads",
|
|
8139
|
-
tags: ["memory"],
|
|
8140
|
-
parameters: [
|
|
8141
|
-
{
|
|
8142
|
-
name: "resourceid",
|
|
8143
|
-
in: "query",
|
|
8144
|
-
required: true,
|
|
8145
|
-
schema: { type: "string" }
|
|
8146
|
-
},
|
|
8147
|
-
{
|
|
8148
|
-
name: "agentId",
|
|
8149
|
-
in: "query",
|
|
8150
|
-
required: true,
|
|
8151
|
-
schema: { type: "string" }
|
|
8152
|
-
},
|
|
8153
|
-
{
|
|
8154
|
-
name: "orderBy",
|
|
8155
|
-
in: "query",
|
|
8156
|
-
required: false,
|
|
8157
|
-
schema: {
|
|
8158
|
-
type: "string",
|
|
8159
|
-
enum: ["createdAt", "updatedAt"],
|
|
8160
|
-
default: "createdAt"
|
|
8161
|
-
},
|
|
8162
|
-
description: "Field to sort by"
|
|
8163
|
-
},
|
|
8164
|
-
{
|
|
8165
|
-
name: "sortDirection",
|
|
8166
|
-
in: "query",
|
|
8167
|
-
required: false,
|
|
8168
|
-
schema: {
|
|
8169
|
-
type: "string",
|
|
8170
|
-
enum: ["ASC", "DESC"],
|
|
8171
|
-
default: "DESC"
|
|
8172
|
-
},
|
|
8173
|
-
description: "Sort direction"
|
|
8174
|
-
}
|
|
8175
|
-
],
|
|
8176
|
-
responses: {
|
|
8177
|
-
200: {
|
|
8178
|
-
description: "List of all threads"
|
|
8179
|
-
}
|
|
8180
|
-
}
|
|
8181
|
-
}),
|
|
8182
|
-
getThreadsHandler
|
|
8183
|
-
);
|
|
8184
|
-
router.get(
|
|
8185
|
-
"/threads/paginated",
|
|
8186
8509
|
w({
|
|
8187
8510
|
description: "Get paginated threads",
|
|
8188
8511
|
tags: ["memory"],
|
|
@@ -8200,18 +8523,18 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8200
8523
|
schema: { type: "string" }
|
|
8201
8524
|
},
|
|
8202
8525
|
{
|
|
8203
|
-
name: "
|
|
8526
|
+
name: "offset",
|
|
8204
8527
|
in: "query",
|
|
8205
8528
|
required: false,
|
|
8206
8529
|
schema: { type: "number", default: 0 },
|
|
8207
|
-
description: "
|
|
8530
|
+
description: "Number of records to skip"
|
|
8208
8531
|
},
|
|
8209
8532
|
{
|
|
8210
|
-
name: "
|
|
8533
|
+
name: "limit",
|
|
8211
8534
|
in: "query",
|
|
8212
8535
|
required: false,
|
|
8213
8536
|
schema: { type: "number", default: 100 },
|
|
8214
|
-
description: "
|
|
8537
|
+
description: "Maximum number of threads to return"
|
|
8215
8538
|
},
|
|
8216
8539
|
{
|
|
8217
8540
|
name: "orderBy",
|
|
@@ -8240,7 +8563,7 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8240
8563
|
}
|
|
8241
8564
|
}
|
|
8242
8565
|
}),
|
|
8243
|
-
|
|
8566
|
+
listThreadsHandler
|
|
8244
8567
|
);
|
|
8245
8568
|
router.get(
|
|
8246
8569
|
"/threads/:threadId",
|
|
@@ -8274,58 +8597,24 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8274
8597
|
);
|
|
8275
8598
|
router.get(
|
|
8276
8599
|
"/threads/:threadId/messages",
|
|
8277
|
-
async (c2, next) => {
|
|
8278
|
-
c2.header("Deprecation", "true");
|
|
8279
|
-
c2.header(
|
|
8280
|
-
"Warning",
|
|
8281
|
-
'299 - "This endpoint is deprecated, use /api/memory/threads/:threadId/messages/paginated instead"'
|
|
8282
|
-
);
|
|
8283
|
-
c2.header("Link", '</api/memory/threads/:threadId/messages/paginated>; rel="successor-version"');
|
|
8284
|
-
return next();
|
|
8285
|
-
},
|
|
8286
8600
|
w({
|
|
8287
|
-
description: "Get messages for a thread",
|
|
8601
|
+
description: "Get paginated messages for a thread",
|
|
8288
8602
|
tags: ["memory"],
|
|
8289
8603
|
parameters: [
|
|
8290
8604
|
{
|
|
8291
8605
|
name: "threadId",
|
|
8292
8606
|
in: "path",
|
|
8293
8607
|
required: true,
|
|
8294
|
-
|
|
8608
|
+
description: "The unique identifier of the thread",
|
|
8609
|
+
schema: {
|
|
8610
|
+
type: "string"
|
|
8611
|
+
}
|
|
8295
8612
|
},
|
|
8296
8613
|
{
|
|
8297
8614
|
name: "agentId",
|
|
8298
8615
|
in: "query",
|
|
8299
8616
|
required: true,
|
|
8300
|
-
|
|
8301
|
-
},
|
|
8302
|
-
{
|
|
8303
|
-
name: "limit",
|
|
8304
|
-
in: "query",
|
|
8305
|
-
required: false,
|
|
8306
|
-
schema: { type: "number" },
|
|
8307
|
-
description: "Limit the number of messages to retrieve (default: 40)"
|
|
8308
|
-
}
|
|
8309
|
-
],
|
|
8310
|
-
responses: {
|
|
8311
|
-
200: {
|
|
8312
|
-
description: "List of messages"
|
|
8313
|
-
}
|
|
8314
|
-
}
|
|
8315
|
-
}),
|
|
8316
|
-
getMessagesHandler
|
|
8317
|
-
);
|
|
8318
|
-
router.get(
|
|
8319
|
-
"/threads/:threadId/messages/paginated",
|
|
8320
|
-
w({
|
|
8321
|
-
description: "Get paginated messages for a thread",
|
|
8322
|
-
tags: ["memory"],
|
|
8323
|
-
parameters: [
|
|
8324
|
-
{
|
|
8325
|
-
name: "threadId",
|
|
8326
|
-
in: "path",
|
|
8327
|
-
required: true,
|
|
8328
|
-
description: "The unique identifier of the thread",
|
|
8617
|
+
description: "The unique identifier of the agent",
|
|
8329
8618
|
schema: {
|
|
8330
8619
|
type: "string"
|
|
8331
8620
|
}
|
|
@@ -8340,34 +8629,67 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8340
8629
|
}
|
|
8341
8630
|
},
|
|
8342
8631
|
{
|
|
8343
|
-
name: "
|
|
8632
|
+
name: "page",
|
|
8344
8633
|
in: "query",
|
|
8345
8634
|
required: false,
|
|
8346
|
-
description: "
|
|
8635
|
+
description: "Zero-indexed page number for pagination (default: 0)",
|
|
8347
8636
|
schema: {
|
|
8348
|
-
type: "
|
|
8349
|
-
|
|
8350
|
-
default:
|
|
8637
|
+
type: "integer",
|
|
8638
|
+
minimum: 0,
|
|
8639
|
+
default: 0
|
|
8351
8640
|
}
|
|
8352
8641
|
},
|
|
8353
8642
|
{
|
|
8354
|
-
name: "
|
|
8643
|
+
name: "perPage",
|
|
8355
8644
|
in: "query",
|
|
8356
8645
|
required: false,
|
|
8357
|
-
description: "
|
|
8646
|
+
description: 'Number of items per page, or "false" to fetch all records (default: 40)',
|
|
8647
|
+
schema: {
|
|
8648
|
+
oneOf: [
|
|
8649
|
+
{ type: "integer", minimum: 0 },
|
|
8650
|
+
{ type: "boolean", enum: [false] }
|
|
8651
|
+
],
|
|
8652
|
+
default: 40
|
|
8653
|
+
}
|
|
8654
|
+
},
|
|
8655
|
+
{
|
|
8656
|
+
name: "orderBy",
|
|
8657
|
+
in: "query",
|
|
8658
|
+
required: false,
|
|
8659
|
+
description: "JSON string specifying sort order",
|
|
8660
|
+
schema: {
|
|
8661
|
+
type: "string",
|
|
8662
|
+
example: '{"field":"createdAt","direction":"DESC"}'
|
|
8663
|
+
}
|
|
8664
|
+
},
|
|
8665
|
+
{
|
|
8666
|
+
name: "include",
|
|
8667
|
+
in: "query",
|
|
8668
|
+
required: false,
|
|
8669
|
+
description: "JSON string specifying messages to include with context",
|
|
8670
|
+
schema: {
|
|
8671
|
+
type: "string",
|
|
8672
|
+
example: '[{"id":"msg-123","withPreviousMessages":5,"withNextMessages":3}]'
|
|
8673
|
+
}
|
|
8674
|
+
},
|
|
8675
|
+
{
|
|
8676
|
+
name: "filter",
|
|
8677
|
+
in: "query",
|
|
8678
|
+
required: false,
|
|
8679
|
+
description: "JSON string specifying filter criteria",
|
|
8358
8680
|
schema: {
|
|
8359
8681
|
type: "string",
|
|
8360
|
-
example: '{"
|
|
8682
|
+
example: '{"dateRange":{"start":"2024-01-01T00:00:00Z","end":"2024-12-31T23:59:59Z"}}'
|
|
8361
8683
|
}
|
|
8362
8684
|
}
|
|
8363
8685
|
],
|
|
8364
8686
|
responses: {
|
|
8365
8687
|
200: {
|
|
8366
|
-
description: "
|
|
8688
|
+
description: "Paginated list of messages with metadata"
|
|
8367
8689
|
}
|
|
8368
8690
|
}
|
|
8369
8691
|
}),
|
|
8370
|
-
|
|
8692
|
+
listMessagesHandler
|
|
8371
8693
|
);
|
|
8372
8694
|
router.get(
|
|
8373
8695
|
"/search",
|
|
@@ -8805,23 +9127,23 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8805
9127
|
);
|
|
8806
9128
|
return router;
|
|
8807
9129
|
}
|
|
8808
|
-
async function
|
|
9130
|
+
async function getTraceHandler(c2) {
|
|
8809
9131
|
try {
|
|
8810
9132
|
const mastra = c2.get("mastra");
|
|
8811
9133
|
const traceId = c2.req.param("traceId");
|
|
8812
9134
|
if (!traceId) {
|
|
8813
9135
|
return c2.json({ error: "Trace ID is required" }, 400);
|
|
8814
9136
|
}
|
|
8815
|
-
const trace = await observability.
|
|
9137
|
+
const trace = await observability$1.getTraceHandler({
|
|
8816
9138
|
mastra,
|
|
8817
9139
|
traceId
|
|
8818
9140
|
});
|
|
8819
9141
|
return c2.json(trace);
|
|
8820
9142
|
} catch (error) {
|
|
8821
|
-
return handleError(error, "Error getting
|
|
9143
|
+
return handleError(error, "Error getting trace");
|
|
8822
9144
|
}
|
|
8823
9145
|
}
|
|
8824
|
-
async function
|
|
9146
|
+
async function getTracesPaginatedHandler(c2) {
|
|
8825
9147
|
try {
|
|
8826
9148
|
const mastra = c2.get("mastra");
|
|
8827
9149
|
const { page, perPage, name, spanType, dateRange, entityId, entityType } = c2.req.query();
|
|
@@ -8832,7 +9154,7 @@ async function getAITracesPaginatedHandler(c2) {
|
|
|
8832
9154
|
const filters = {};
|
|
8833
9155
|
if (name) filters.name = name;
|
|
8834
9156
|
if (spanType) {
|
|
8835
|
-
if (Object.values(
|
|
9157
|
+
if (Object.values(observability.SpanType).includes(spanType)) {
|
|
8836
9158
|
filters.spanType = spanType;
|
|
8837
9159
|
} else {
|
|
8838
9160
|
return c2.json({ error: "Invalid spanType" }, 400);
|
|
@@ -8856,7 +9178,7 @@ async function getAITracesPaginatedHandler(c2) {
|
|
|
8856
9178
|
if (start || end) {
|
|
8857
9179
|
pagination.dateRange = { start, end };
|
|
8858
9180
|
}
|
|
8859
|
-
const result = await observability.
|
|
9181
|
+
const result = await observability$1.getTracesPaginatedHandler({
|
|
8860
9182
|
mastra,
|
|
8861
9183
|
body: {
|
|
8862
9184
|
pagination,
|
|
@@ -8865,14 +9187,14 @@ async function getAITracesPaginatedHandler(c2) {
|
|
|
8865
9187
|
});
|
|
8866
9188
|
return c2.json(result);
|
|
8867
9189
|
} catch (error) {
|
|
8868
|
-
return handleError(error, "Error getting
|
|
9190
|
+
return handleError(error, "Error getting traces paginated");
|
|
8869
9191
|
}
|
|
8870
9192
|
}
|
|
8871
9193
|
async function processTraceScoringHandler(c2) {
|
|
8872
9194
|
try {
|
|
8873
9195
|
const mastra = c2.get("mastra");
|
|
8874
9196
|
const { scorerName, targets } = await c2.req.json();
|
|
8875
|
-
const result = await observability.scoreTracesHandler({
|
|
9197
|
+
const result = await observability$1.scoreTracesHandler({
|
|
8876
9198
|
mastra,
|
|
8877
9199
|
body: { scorerName, targets }
|
|
8878
9200
|
});
|
|
@@ -8881,7 +9203,7 @@ async function processTraceScoringHandler(c2) {
|
|
|
8881
9203
|
return handleError(error, "Error processing trace scoring");
|
|
8882
9204
|
}
|
|
8883
9205
|
}
|
|
8884
|
-
async function
|
|
9206
|
+
async function listScoresBySpan(c2) {
|
|
8885
9207
|
const mastra = c2.get("mastra");
|
|
8886
9208
|
const traceId = c2.req.param("traceId");
|
|
8887
9209
|
const spanId = c2.req.param("spanId");
|
|
@@ -8889,7 +9211,7 @@ async function getScoresBySpan(c2) {
|
|
|
8889
9211
|
const perPage = parseInt(c2.req.query("perPage") || "10");
|
|
8890
9212
|
const pagination = { page, perPage };
|
|
8891
9213
|
try {
|
|
8892
|
-
const scores = await observability.
|
|
9214
|
+
const scores = await observability$1.listScoresBySpan({
|
|
8893
9215
|
mastra,
|
|
8894
9216
|
traceId,
|
|
8895
9217
|
spanId,
|
|
@@ -8907,7 +9229,7 @@ function observabilityRouter() {
|
|
|
8907
9229
|
router.get(
|
|
8908
9230
|
"/traces",
|
|
8909
9231
|
w({
|
|
8910
|
-
description: "Get paginated list of
|
|
9232
|
+
description: "Get paginated list of traces",
|
|
8911
9233
|
tags: ["observability"],
|
|
8912
9234
|
parameters: [
|
|
8913
9235
|
{
|
|
@@ -8955,19 +9277,19 @@ function observabilityRouter() {
|
|
|
8955
9277
|
],
|
|
8956
9278
|
responses: {
|
|
8957
9279
|
200: {
|
|
8958
|
-
description: "Paginated list of
|
|
9280
|
+
description: "Paginated list of traces"
|
|
8959
9281
|
},
|
|
8960
9282
|
400: {
|
|
8961
9283
|
description: "Bad request - invalid parameters"
|
|
8962
9284
|
}
|
|
8963
9285
|
}
|
|
8964
9286
|
}),
|
|
8965
|
-
|
|
9287
|
+
getTracesPaginatedHandler
|
|
8966
9288
|
);
|
|
8967
9289
|
router.get(
|
|
8968
9290
|
"/traces/:traceId",
|
|
8969
9291
|
w({
|
|
8970
|
-
description: "Get a specific
|
|
9292
|
+
description: "Get a specific trace by ID",
|
|
8971
9293
|
tags: ["observability"],
|
|
8972
9294
|
parameters: [
|
|
8973
9295
|
{
|
|
@@ -8980,7 +9302,7 @@ function observabilityRouter() {
|
|
|
8980
9302
|
],
|
|
8981
9303
|
responses: {
|
|
8982
9304
|
200: {
|
|
8983
|
-
description: "
|
|
9305
|
+
description: "Trace with all its spans"
|
|
8984
9306
|
},
|
|
8985
9307
|
400: {
|
|
8986
9308
|
description: "Bad request - missing trace ID"
|
|
@@ -8990,7 +9312,7 @@ function observabilityRouter() {
|
|
|
8990
9312
|
}
|
|
8991
9313
|
}
|
|
8992
9314
|
}),
|
|
8993
|
-
|
|
9315
|
+
getTraceHandler
|
|
8994
9316
|
);
|
|
8995
9317
|
router.get(
|
|
8996
9318
|
"/traces/:traceId/:spanId/scores",
|
|
@@ -9033,7 +9355,7 @@ function observabilityRouter() {
|
|
|
9033
9355
|
}
|
|
9034
9356
|
}
|
|
9035
9357
|
}),
|
|
9036
|
-
|
|
9358
|
+
listScoresBySpan
|
|
9037
9359
|
);
|
|
9038
9360
|
router.post(
|
|
9039
9361
|
"/traces/score",
|
|
@@ -9156,36 +9478,36 @@ function observabilityRouter() {
|
|
|
9156
9478
|
);
|
|
9157
9479
|
return router;
|
|
9158
9480
|
}
|
|
9159
|
-
async function
|
|
9481
|
+
async function listScorersHandler(c2) {
|
|
9160
9482
|
try {
|
|
9161
|
-
const scorers = await scores.
|
|
9483
|
+
const scorers = await scores.listScorersHandler({
|
|
9162
9484
|
mastra: c2.get("mastra"),
|
|
9163
|
-
|
|
9485
|
+
requestContext: c2.get("requestContext")
|
|
9164
9486
|
});
|
|
9165
9487
|
return c2.json(scorers);
|
|
9166
9488
|
} catch (error) {
|
|
9167
|
-
return handleError(error, "Error
|
|
9489
|
+
return handleError(error, "Error listing scorers");
|
|
9168
9490
|
}
|
|
9169
9491
|
}
|
|
9170
9492
|
async function getScorerHandler(c2) {
|
|
9171
9493
|
const mastra = c2.get("mastra");
|
|
9172
9494
|
const scorerId = c2.req.param("scorerId");
|
|
9173
|
-
const
|
|
9495
|
+
const requestContext = c2.get("requestContext");
|
|
9174
9496
|
const scorer = await scores.getScorerHandler({
|
|
9175
9497
|
mastra,
|
|
9176
9498
|
scorerId,
|
|
9177
|
-
|
|
9499
|
+
requestContext
|
|
9178
9500
|
});
|
|
9179
9501
|
return c2.json(scorer);
|
|
9180
9502
|
}
|
|
9181
|
-
async function
|
|
9503
|
+
async function listScoresByRunIdHandler(c2) {
|
|
9182
9504
|
const mastra = c2.get("mastra");
|
|
9183
9505
|
const runId = c2.req.param("runId");
|
|
9184
|
-
const page =
|
|
9185
|
-
const perPage =
|
|
9506
|
+
const page = parsePage(c2.req.query("page"));
|
|
9507
|
+
const perPage = parsePerPage(c2.req.query("perPage"), 10);
|
|
9186
9508
|
const pagination = { page, perPage };
|
|
9187
9509
|
try {
|
|
9188
|
-
const scores$1 = await scores.
|
|
9510
|
+
const scores$1 = await scores.listScoresByRunIdHandler({
|
|
9189
9511
|
mastra,
|
|
9190
9512
|
runId,
|
|
9191
9513
|
pagination
|
|
@@ -9195,16 +9517,16 @@ async function getScoresByRunIdHandler(c2) {
|
|
|
9195
9517
|
return handleError(error, "Error getting scores by run id");
|
|
9196
9518
|
}
|
|
9197
9519
|
}
|
|
9198
|
-
async function
|
|
9520
|
+
async function listScoresByScorerIdHandler(c2) {
|
|
9199
9521
|
const mastra = c2.get("mastra");
|
|
9200
9522
|
const scorerId = c2.req.param("scorerId");
|
|
9201
|
-
const page =
|
|
9202
|
-
const perPage =
|
|
9523
|
+
const page = parsePage(c2.req.query("page"));
|
|
9524
|
+
const perPage = parsePerPage(c2.req.query("perPage"), 10);
|
|
9203
9525
|
const entityId = c2.req.query("entityId");
|
|
9204
9526
|
const entityType = c2.req.query("entityType");
|
|
9205
9527
|
const pagination = { page, perPage };
|
|
9206
9528
|
try {
|
|
9207
|
-
const scores$1 = await scores.
|
|
9529
|
+
const scores$1 = await scores.listScoresByScorerIdHandler({
|
|
9208
9530
|
mastra,
|
|
9209
9531
|
scorerId,
|
|
9210
9532
|
pagination,
|
|
@@ -9216,15 +9538,15 @@ async function getScoresByScorerIdHandler(c2) {
|
|
|
9216
9538
|
return handleError(error, "Error getting scores by scorer id");
|
|
9217
9539
|
}
|
|
9218
9540
|
}
|
|
9219
|
-
async function
|
|
9541
|
+
async function listScoresByEntityIdHandler(c2) {
|
|
9220
9542
|
const mastra = c2.get("mastra");
|
|
9221
9543
|
const entityId = c2.req.param("entityId");
|
|
9222
9544
|
const entityType = c2.req.param("entityType");
|
|
9223
|
-
const page =
|
|
9224
|
-
const perPage =
|
|
9545
|
+
const page = parsePage(c2.req.query("page"));
|
|
9546
|
+
const perPage = parsePerPage(c2.req.query("perPage"), 10);
|
|
9225
9547
|
const pagination = { page, perPage };
|
|
9226
9548
|
try {
|
|
9227
|
-
const scores$1 = await scores.
|
|
9549
|
+
const scores$1 = await scores.listScoresByEntityIdHandler({
|
|
9228
9550
|
mastra,
|
|
9229
9551
|
entityId,
|
|
9230
9552
|
entityType,
|
|
@@ -9263,7 +9585,7 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9263
9585
|
}
|
|
9264
9586
|
}
|
|
9265
9587
|
}),
|
|
9266
|
-
|
|
9588
|
+
listScorersHandler
|
|
9267
9589
|
);
|
|
9268
9590
|
router.get(
|
|
9269
9591
|
"/scorers/:scorerId",
|
|
@@ -9311,7 +9633,7 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9311
9633
|
}
|
|
9312
9634
|
}
|
|
9313
9635
|
}),
|
|
9314
|
-
|
|
9636
|
+
listScoresByRunIdHandler
|
|
9315
9637
|
);
|
|
9316
9638
|
router.get(
|
|
9317
9639
|
"/scorer/:scorerId",
|
|
@@ -9346,7 +9668,7 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9346
9668
|
}
|
|
9347
9669
|
}
|
|
9348
9670
|
}),
|
|
9349
|
-
|
|
9671
|
+
listScoresByScorerIdHandler
|
|
9350
9672
|
);
|
|
9351
9673
|
router.get(
|
|
9352
9674
|
"/entity/:entityType/:entityId",
|
|
@@ -9389,7 +9711,7 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9389
9711
|
}
|
|
9390
9712
|
}
|
|
9391
9713
|
}),
|
|
9392
|
-
|
|
9714
|
+
listScoresByEntityIdHandler
|
|
9393
9715
|
);
|
|
9394
9716
|
router.post(
|
|
9395
9717
|
"/",
|
|
@@ -9415,7 +9737,7 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9415
9737
|
entity: { type: "object" },
|
|
9416
9738
|
metadata: { type: "object" },
|
|
9417
9739
|
additionalLLMContext: { type: "object" },
|
|
9418
|
-
|
|
9740
|
+
requestContext: { type: "object" },
|
|
9419
9741
|
resourceId: { type: "string" },
|
|
9420
9742
|
threadId: { type: "string" },
|
|
9421
9743
|
traceId: { type: "string" }
|
|
@@ -9438,73 +9760,6 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9438
9760
|
);
|
|
9439
9761
|
return router;
|
|
9440
9762
|
}
|
|
9441
|
-
async function getTelemetryHandler(c2) {
|
|
9442
|
-
try {
|
|
9443
|
-
const mastra = c2.get("mastra");
|
|
9444
|
-
const { name, scope, page, perPage, fromDate, toDate } = c2.req.query();
|
|
9445
|
-
const attribute = c2.req.queries("attribute");
|
|
9446
|
-
const traces = await telemetry$1.getTelemetryHandler({
|
|
9447
|
-
mastra,
|
|
9448
|
-
body: {
|
|
9449
|
-
name,
|
|
9450
|
-
scope,
|
|
9451
|
-
page: Number(page ?? 0),
|
|
9452
|
-
perPage: Number(perPage ?? 100),
|
|
9453
|
-
attribute,
|
|
9454
|
-
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
9455
|
-
toDate: toDate ? new Date(toDate) : void 0
|
|
9456
|
-
}
|
|
9457
|
-
});
|
|
9458
|
-
return c2.json({ traces });
|
|
9459
|
-
} catch (error) {
|
|
9460
|
-
return handleError(error, "Error getting telemetry traces");
|
|
9461
|
-
}
|
|
9462
|
-
}
|
|
9463
|
-
async function storeTelemetryHandler(c2) {
|
|
9464
|
-
try {
|
|
9465
|
-
const body = await c2.req.json();
|
|
9466
|
-
const mastra = c2.get("mastra");
|
|
9467
|
-
const result = await telemetry$1.storeTelemetryHandler({ mastra, body });
|
|
9468
|
-
if (result.status === "error") {
|
|
9469
|
-
return c2.json(result, 500);
|
|
9470
|
-
}
|
|
9471
|
-
return c2.json(result, 200);
|
|
9472
|
-
} catch (error) {
|
|
9473
|
-
return handleError(error, "Error storing telemetry traces");
|
|
9474
|
-
}
|
|
9475
|
-
}
|
|
9476
|
-
|
|
9477
|
-
// src/server/handlers/routes/telemetry/router.ts
|
|
9478
|
-
function telemetryRouter() {
|
|
9479
|
-
const router = new hono.Hono();
|
|
9480
|
-
router.get(
|
|
9481
|
-
"/",
|
|
9482
|
-
w({
|
|
9483
|
-
description: "Get all traces",
|
|
9484
|
-
tags: ["telemetry"],
|
|
9485
|
-
responses: {
|
|
9486
|
-
200: {
|
|
9487
|
-
description: "List of all traces (paged)"
|
|
9488
|
-
}
|
|
9489
|
-
}
|
|
9490
|
-
}),
|
|
9491
|
-
getTelemetryHandler
|
|
9492
|
-
);
|
|
9493
|
-
router.post(
|
|
9494
|
-
"/",
|
|
9495
|
-
w({
|
|
9496
|
-
description: "Store telemetry",
|
|
9497
|
-
tags: ["telemetry"],
|
|
9498
|
-
responses: {
|
|
9499
|
-
200: {
|
|
9500
|
-
description: "Traces stored"
|
|
9501
|
-
}
|
|
9502
|
-
}
|
|
9503
|
-
}),
|
|
9504
|
-
storeTelemetryHandler
|
|
9505
|
-
);
|
|
9506
|
-
return router;
|
|
9507
|
-
}
|
|
9508
9763
|
function toolsRouter(bodyLimitOptions, tools) {
|
|
9509
9764
|
const router = new hono.Hono();
|
|
9510
9765
|
router.get(
|
|
@@ -9518,7 +9773,7 @@ function toolsRouter(bodyLimitOptions, tools) {
|
|
|
9518
9773
|
}
|
|
9519
9774
|
}
|
|
9520
9775
|
}),
|
|
9521
|
-
|
|
9776
|
+
listToolsHandler
|
|
9522
9777
|
);
|
|
9523
9778
|
router.get(
|
|
9524
9779
|
"/:toolId",
|
|
@@ -9572,7 +9827,7 @@ function toolsRouter(bodyLimitOptions, tools) {
|
|
|
9572
9827
|
type: "object",
|
|
9573
9828
|
properties: {
|
|
9574
9829
|
data: { type: "object" },
|
|
9575
|
-
|
|
9830
|
+
requestContext: { type: "object" }
|
|
9576
9831
|
},
|
|
9577
9832
|
required: ["data"]
|
|
9578
9833
|
}
|
|
@@ -9906,10 +10161,10 @@ function vectorRouter(bodyLimitOptions) {
|
|
|
9906
10161
|
);
|
|
9907
10162
|
return router;
|
|
9908
10163
|
}
|
|
9909
|
-
async function
|
|
10164
|
+
async function listWorkflowsHandler(c2) {
|
|
9910
10165
|
try {
|
|
9911
10166
|
const mastra = c2.get("mastra");
|
|
9912
|
-
const workflows$1 = await workflows.
|
|
10167
|
+
const workflows$1 = await workflows.listWorkflowsHandler({
|
|
9913
10168
|
mastra
|
|
9914
10169
|
});
|
|
9915
10170
|
return c2.json(workflows$1);
|
|
@@ -9948,13 +10203,13 @@ async function createWorkflowRunHandler(c2) {
|
|
|
9948
10203
|
async function startAsyncWorkflowHandler(c2) {
|
|
9949
10204
|
try {
|
|
9950
10205
|
const mastra = c2.get("mastra");
|
|
9951
|
-
const
|
|
10206
|
+
const requestContext = c2.get("requestContext");
|
|
9952
10207
|
const workflowId = c2.req.param("workflowId");
|
|
9953
10208
|
const { inputData, tracingOptions } = await c2.req.json();
|
|
9954
10209
|
const runId = c2.req.query("runId");
|
|
9955
10210
|
const result = await workflows.startAsyncWorkflowHandler({
|
|
9956
10211
|
mastra,
|
|
9957
|
-
|
|
10212
|
+
requestContext,
|
|
9958
10213
|
workflowId,
|
|
9959
10214
|
runId,
|
|
9960
10215
|
inputData,
|
|
@@ -9968,13 +10223,13 @@ async function startAsyncWorkflowHandler(c2) {
|
|
|
9968
10223
|
async function startWorkflowRunHandler(c2) {
|
|
9969
10224
|
try {
|
|
9970
10225
|
const mastra = c2.get("mastra");
|
|
9971
|
-
const
|
|
10226
|
+
const requestContext = c2.get("requestContext");
|
|
9972
10227
|
const workflowId = c2.req.param("workflowId");
|
|
9973
10228
|
const { inputData, tracingOptions } = await c2.req.json();
|
|
9974
10229
|
const runId = c2.req.query("runId");
|
|
9975
10230
|
await workflows.startWorkflowRunHandler({
|
|
9976
10231
|
mastra,
|
|
9977
|
-
|
|
10232
|
+
requestContext,
|
|
9978
10233
|
workflowId,
|
|
9979
10234
|
runId,
|
|
9980
10235
|
inputData,
|
|
@@ -9985,49 +10240,10 @@ async function startWorkflowRunHandler(c2) {
|
|
|
9985
10240
|
return handleError(e2, "Error starting workflow run");
|
|
9986
10241
|
}
|
|
9987
10242
|
}
|
|
9988
|
-
function watchWorkflowHandler(c2) {
|
|
9989
|
-
try {
|
|
9990
|
-
const mastra = c2.get("mastra");
|
|
9991
|
-
const logger2 = mastra.getLogger();
|
|
9992
|
-
const workflowId = c2.req.param("workflowId");
|
|
9993
|
-
const runId = c2.req.query("runId");
|
|
9994
|
-
if (!runId) {
|
|
9995
|
-
throw new httpException.HTTPException(400, { message: "runId required to watch workflow" });
|
|
9996
|
-
}
|
|
9997
|
-
c2.header("Transfer-Encoding", "chunked");
|
|
9998
|
-
return streaming.stream(
|
|
9999
|
-
c2,
|
|
10000
|
-
async (stream6) => {
|
|
10001
|
-
try {
|
|
10002
|
-
const result = await workflows.watchWorkflowHandler({
|
|
10003
|
-
mastra,
|
|
10004
|
-
workflowId,
|
|
10005
|
-
runId
|
|
10006
|
-
});
|
|
10007
|
-
const reader = result.getReader();
|
|
10008
|
-
stream6.onAbort(() => {
|
|
10009
|
-
void reader.cancel("request aborted");
|
|
10010
|
-
});
|
|
10011
|
-
let chunkResult;
|
|
10012
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10013
|
-
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
10014
|
-
}
|
|
10015
|
-
} catch (err) {
|
|
10016
|
-
logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
|
|
10017
|
-
}
|
|
10018
|
-
},
|
|
10019
|
-
async (err) => {
|
|
10020
|
-
logger2.error("Error in watch stream: " + err?.message);
|
|
10021
|
-
}
|
|
10022
|
-
);
|
|
10023
|
-
} catch (error) {
|
|
10024
|
-
return handleError(error, "Error watching workflow");
|
|
10025
|
-
}
|
|
10026
|
-
}
|
|
10027
10243
|
async function streamVNextWorkflowHandler(c2) {
|
|
10028
10244
|
try {
|
|
10029
10245
|
const mastra = c2.get("mastra");
|
|
10030
|
-
const
|
|
10246
|
+
const requestContext = c2.get("requestContext");
|
|
10031
10247
|
const logger2 = mastra.getLogger();
|
|
10032
10248
|
const workflowId = c2.req.param("workflowId");
|
|
10033
10249
|
const { inputData, closeOnSuspend, tracingOptions } = await c2.req.json();
|
|
@@ -10035,24 +10251,24 @@ async function streamVNextWorkflowHandler(c2) {
|
|
|
10035
10251
|
c2.header("Transfer-Encoding", "chunked");
|
|
10036
10252
|
return streaming.stream(
|
|
10037
10253
|
c2,
|
|
10038
|
-
async (
|
|
10254
|
+
async (stream5) => {
|
|
10039
10255
|
try {
|
|
10040
10256
|
const result = await workflows.streamVNextWorkflowHandler({
|
|
10041
10257
|
mastra,
|
|
10042
10258
|
workflowId,
|
|
10043
10259
|
runId,
|
|
10044
10260
|
inputData,
|
|
10045
|
-
|
|
10261
|
+
requestContext,
|
|
10046
10262
|
closeOnSuspend,
|
|
10047
10263
|
tracingOptions
|
|
10048
10264
|
});
|
|
10049
10265
|
const reader = result.getReader();
|
|
10050
|
-
|
|
10266
|
+
stream5.onAbort(() => {
|
|
10051
10267
|
void reader.cancel("request aborted");
|
|
10052
10268
|
});
|
|
10053
10269
|
let chunkResult;
|
|
10054
10270
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10055
|
-
await
|
|
10271
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
10056
10272
|
}
|
|
10057
10273
|
} catch (err) {
|
|
10058
10274
|
logger2.error("Error in workflow stream: " + (err?.message ?? "Unknown error"));
|
|
@@ -10075,7 +10291,7 @@ async function observeStreamVNextWorkflowHandler(c2) {
|
|
|
10075
10291
|
c2.header("Transfer-Encoding", "chunked");
|
|
10076
10292
|
return streaming.stream(
|
|
10077
10293
|
c2,
|
|
10078
|
-
async (
|
|
10294
|
+
async (stream5) => {
|
|
10079
10295
|
try {
|
|
10080
10296
|
const result = await workflows.observeStreamVNextWorkflowHandler({
|
|
10081
10297
|
mastra,
|
|
@@ -10083,12 +10299,12 @@ async function observeStreamVNextWorkflowHandler(c2) {
|
|
|
10083
10299
|
runId
|
|
10084
10300
|
});
|
|
10085
10301
|
const reader = result.getReader();
|
|
10086
|
-
|
|
10302
|
+
stream5.onAbort(() => {
|
|
10087
10303
|
void reader.cancel("request aborted");
|
|
10088
10304
|
});
|
|
10089
10305
|
let chunkResult;
|
|
10090
10306
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10091
|
-
await
|
|
10307
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
10092
10308
|
}
|
|
10093
10309
|
} catch (err) {
|
|
10094
10310
|
logger2.error("Error in workflow observe stream: " + (err?.message ?? "Unknown error"));
|
|
@@ -10105,7 +10321,7 @@ async function observeStreamVNextWorkflowHandler(c2) {
|
|
|
10105
10321
|
async function streamLegacyWorkflowHandler(c2) {
|
|
10106
10322
|
try {
|
|
10107
10323
|
const mastra = c2.get("mastra");
|
|
10108
|
-
const
|
|
10324
|
+
const requestContext = c2.get("requestContext");
|
|
10109
10325
|
const logger2 = mastra.getLogger();
|
|
10110
10326
|
const workflowId = c2.req.param("workflowId");
|
|
10111
10327
|
const { inputData, tracingOptions } = await c2.req.json();
|
|
@@ -10113,28 +10329,28 @@ async function streamLegacyWorkflowHandler(c2) {
|
|
|
10113
10329
|
c2.header("Transfer-Encoding", "chunked");
|
|
10114
10330
|
return streaming.stream(
|
|
10115
10331
|
c2,
|
|
10116
|
-
async (
|
|
10332
|
+
async (stream5) => {
|
|
10117
10333
|
try {
|
|
10118
10334
|
const result = await workflows.streamLegacyWorkflowHandler({
|
|
10119
10335
|
mastra,
|
|
10120
10336
|
workflowId,
|
|
10121
10337
|
runId,
|
|
10122
10338
|
inputData,
|
|
10123
|
-
|
|
10339
|
+
requestContext,
|
|
10124
10340
|
tracingOptions
|
|
10125
10341
|
});
|
|
10126
10342
|
const reader = result.stream.getReader();
|
|
10127
|
-
|
|
10343
|
+
stream5.onAbort(() => {
|
|
10128
10344
|
void reader.cancel("request aborted");
|
|
10129
10345
|
});
|
|
10130
10346
|
let chunkResult;
|
|
10131
10347
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10132
|
-
await
|
|
10348
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
10133
10349
|
}
|
|
10134
10350
|
} catch (err) {
|
|
10135
10351
|
logger2.error("Error in workflow stream: " + (err?.message ?? "Unknown error"));
|
|
10136
10352
|
}
|
|
10137
|
-
await
|
|
10353
|
+
await stream5.close();
|
|
10138
10354
|
},
|
|
10139
10355
|
async (err) => {
|
|
10140
10356
|
logger2.error("Error in workflow stream: " + err?.message);
|
|
@@ -10156,684 +10372,189 @@ async function observeStreamLegacyWorkflowHandler(c2) {
|
|
|
10156
10372
|
c2.header("Transfer-Encoding", "chunked");
|
|
10157
10373
|
return streaming.stream(
|
|
10158
10374
|
c2,
|
|
10159
|
-
async (
|
|
10160
|
-
try {
|
|
10161
|
-
const result = await workflows.observeStreamLegacyWorkflowHandler({
|
|
10162
|
-
mastra,
|
|
10163
|
-
workflowId,
|
|
10164
|
-
runId
|
|
10165
|
-
});
|
|
10166
|
-
const reader = result.getReader();
|
|
10167
|
-
|
|
10168
|
-
void reader.cancel("request aborted");
|
|
10169
|
-
});
|
|
10170
|
-
let chunkResult;
|
|
10171
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10172
|
-
await
|
|
10173
|
-
}
|
|
10174
|
-
} catch (err) {
|
|
10175
|
-
logger2.error("Error in workflow observe stream: " + (err?.message ?? "Unknown error"));
|
|
10176
|
-
}
|
|
10177
|
-
await stream6.close();
|
|
10178
|
-
},
|
|
10179
|
-
async (err) => {
|
|
10180
|
-
logger2.error("Error in workflow observe stream: " + err?.message);
|
|
10181
|
-
}
|
|
10182
|
-
);
|
|
10183
|
-
} catch (error) {
|
|
10184
|
-
return handleError(error, "Error observing workflow stream");
|
|
10185
|
-
}
|
|
10186
|
-
}
|
|
10187
|
-
async function resumeStreamWorkflowHandler(c2) {
|
|
10188
|
-
try {
|
|
10189
|
-
const mastra = c2.get("mastra");
|
|
10190
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10191
|
-
const logger2 = mastra.getLogger();
|
|
10192
|
-
const workflowId = c2.req.param("workflowId");
|
|
10193
|
-
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10194
|
-
const runId = c2.req.query("runId");
|
|
10195
|
-
c2.header("Transfer-Encoding", "chunked");
|
|
10196
|
-
return streaming.stream(
|
|
10197
|
-
c2,
|
|
10198
|
-
async (stream6) => {
|
|
10199
|
-
try {
|
|
10200
|
-
const result = await workflows.resumeStreamWorkflowHandler({
|
|
10201
|
-
mastra,
|
|
10202
|
-
workflowId,
|
|
10203
|
-
runId,
|
|
10204
|
-
body: { step, resumeData },
|
|
10205
|
-
runtimeContext,
|
|
10206
|
-
tracingOptions
|
|
10207
|
-
});
|
|
10208
|
-
const reader = result.getReader();
|
|
10209
|
-
stream6.onAbort(() => {
|
|
10210
|
-
void reader.cancel("request aborted");
|
|
10211
|
-
});
|
|
10212
|
-
let chunkResult;
|
|
10213
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10214
|
-
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
10215
|
-
}
|
|
10216
|
-
} catch (err) {
|
|
10217
|
-
logger2.error("Error in workflow VNext stream: " + (err?.message ?? "Unknown error"));
|
|
10218
|
-
}
|
|
10219
|
-
},
|
|
10220
|
-
async (err) => {
|
|
10221
|
-
logger2.error("Error in workflow VNext stream: " + err?.message);
|
|
10222
|
-
}
|
|
10223
|
-
);
|
|
10224
|
-
} catch (error) {
|
|
10225
|
-
return handleError(error, "Error streaming workflow");
|
|
10226
|
-
}
|
|
10227
|
-
}
|
|
10228
|
-
async function resumeAsyncWorkflowHandler(c2) {
|
|
10229
|
-
try {
|
|
10230
|
-
const mastra = c2.get("mastra");
|
|
10231
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10232
|
-
const workflowId = c2.req.param("workflowId");
|
|
10233
|
-
const runId = c2.req.query("runId");
|
|
10234
|
-
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10235
|
-
if (!runId) {
|
|
10236
|
-
throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
|
|
10237
|
-
}
|
|
10238
|
-
const result = await workflows.resumeAsyncWorkflowHandler({
|
|
10239
|
-
mastra,
|
|
10240
|
-
runtimeContext,
|
|
10241
|
-
workflowId,
|
|
10242
|
-
runId,
|
|
10243
|
-
body: { step, resumeData },
|
|
10244
|
-
tracingOptions
|
|
10245
|
-
});
|
|
10246
|
-
return c2.json(result);
|
|
10247
|
-
} catch (error) {
|
|
10248
|
-
return handleError(error, "Error resuming workflow step");
|
|
10249
|
-
}
|
|
10250
|
-
}
|
|
10251
|
-
async function resumeWorkflowHandler(c2) {
|
|
10252
|
-
try {
|
|
10253
|
-
const mastra = c2.get("mastra");
|
|
10254
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10255
|
-
const workflowId = c2.req.param("workflowId");
|
|
10256
|
-
const runId = c2.req.query("runId");
|
|
10257
|
-
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10258
|
-
if (!runId) {
|
|
10259
|
-
throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
|
|
10260
|
-
}
|
|
10261
|
-
await workflows.resumeWorkflowHandler({
|
|
10262
|
-
mastra,
|
|
10263
|
-
runtimeContext,
|
|
10264
|
-
workflowId,
|
|
10265
|
-
runId,
|
|
10266
|
-
body: { step, resumeData },
|
|
10267
|
-
tracingOptions
|
|
10268
|
-
});
|
|
10269
|
-
return c2.json({ message: "Workflow run resumed" });
|
|
10270
|
-
} catch (error) {
|
|
10271
|
-
return handleError(error, "Error resuming workflow");
|
|
10272
|
-
}
|
|
10273
|
-
}
|
|
10274
|
-
async function getWorkflowRunsHandler(c2) {
|
|
10275
|
-
try {
|
|
10276
|
-
const mastra = c2.get("mastra");
|
|
10277
|
-
const workflowId = c2.req.param("workflowId");
|
|
10278
|
-
const { fromDate, toDate, limit, offset, resourceId } = c2.req.query();
|
|
10279
|
-
const workflowRuns = await workflows.getWorkflowRunsHandler({
|
|
10280
|
-
mastra,
|
|
10281
|
-
workflowId,
|
|
10282
|
-
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
10283
|
-
toDate: toDate ? new Date(toDate) : void 0,
|
|
10284
|
-
limit: limit ? Number(limit) : void 0,
|
|
10285
|
-
offset: offset ? Number(offset) : void 0,
|
|
10286
|
-
resourceId
|
|
10287
|
-
});
|
|
10288
|
-
return c2.json(workflowRuns);
|
|
10289
|
-
} catch (error) {
|
|
10290
|
-
return handleError(error, "Error getting workflow runs");
|
|
10291
|
-
}
|
|
10292
|
-
}
|
|
10293
|
-
async function getWorkflowRunByIdHandler(c2) {
|
|
10294
|
-
try {
|
|
10295
|
-
const mastra = c2.get("mastra");
|
|
10296
|
-
const workflowId = c2.req.param("workflowId");
|
|
10297
|
-
const runId = c2.req.param("runId");
|
|
10298
|
-
const workflowRun = await workflows.getWorkflowRunByIdHandler({
|
|
10299
|
-
mastra,
|
|
10300
|
-
workflowId,
|
|
10301
|
-
runId
|
|
10302
|
-
});
|
|
10303
|
-
return c2.json(workflowRun);
|
|
10304
|
-
} catch (error) {
|
|
10305
|
-
return handleError(error, "Error getting workflow run");
|
|
10306
|
-
}
|
|
10307
|
-
}
|
|
10308
|
-
async function getWorkflowRunExecutionResultHandler(c2) {
|
|
10309
|
-
try {
|
|
10310
|
-
const mastra = c2.get("mastra");
|
|
10311
|
-
const workflowId = c2.req.param("workflowId");
|
|
10312
|
-
const runId = c2.req.param("runId");
|
|
10313
|
-
const workflowRunExecutionResult = await workflows.getWorkflowRunExecutionResultHandler({
|
|
10314
|
-
mastra,
|
|
10315
|
-
workflowId,
|
|
10316
|
-
runId
|
|
10317
|
-
});
|
|
10318
|
-
return c2.json(workflowRunExecutionResult);
|
|
10319
|
-
} catch (error) {
|
|
10320
|
-
return handleError(error, "Error getting workflow run execution result");
|
|
10321
|
-
}
|
|
10322
|
-
}
|
|
10323
|
-
async function cancelWorkflowRunHandler(c2) {
|
|
10324
|
-
try {
|
|
10325
|
-
const mastra = c2.get("mastra");
|
|
10326
|
-
const workflowId = c2.req.param("workflowId");
|
|
10327
|
-
const runId = c2.req.param("runId");
|
|
10328
|
-
const result = await workflows.cancelWorkflowRunHandler({
|
|
10329
|
-
mastra,
|
|
10330
|
-
workflowId,
|
|
10331
|
-
runId
|
|
10332
|
-
});
|
|
10333
|
-
return c2.json(result);
|
|
10334
|
-
} catch (error) {
|
|
10335
|
-
return handleError(error, "Error canceling workflow run");
|
|
10336
|
-
}
|
|
10337
|
-
}
|
|
10338
|
-
async function sendWorkflowRunEventHandler(c2) {
|
|
10339
|
-
try {
|
|
10340
|
-
const mastra = c2.get("mastra");
|
|
10341
|
-
const workflowId = c2.req.param("workflowId");
|
|
10342
|
-
const runId = c2.req.param("runId");
|
|
10343
|
-
const { event, data } = await c2.req.json();
|
|
10344
|
-
const result = await workflows.sendWorkflowRunEventHandler({
|
|
10345
|
-
mastra,
|
|
10346
|
-
workflowId,
|
|
10347
|
-
runId,
|
|
10348
|
-
event,
|
|
10349
|
-
data
|
|
10350
|
-
});
|
|
10351
|
-
return c2.json(result);
|
|
10352
|
-
} catch (error) {
|
|
10353
|
-
return handleError(error, "Error sending workflow run event");
|
|
10354
|
-
}
|
|
10355
|
-
}
|
|
10356
|
-
async function getLegacyWorkflowsHandler(c2) {
|
|
10357
|
-
try {
|
|
10358
|
-
const mastra = c2.get("mastra");
|
|
10359
|
-
const workflows = await legacyWorkflows.getLegacyWorkflowsHandler({
|
|
10360
|
-
mastra
|
|
10361
|
-
});
|
|
10362
|
-
return c2.json(workflows);
|
|
10363
|
-
} catch (error) {
|
|
10364
|
-
return handleError(error, "Error getting workflows");
|
|
10365
|
-
}
|
|
10366
|
-
}
|
|
10367
|
-
async function getLegacyWorkflowByIdHandler(c2) {
|
|
10368
|
-
try {
|
|
10369
|
-
const mastra = c2.get("mastra");
|
|
10370
|
-
const workflowId = c2.req.param("workflowId");
|
|
10371
|
-
const workflow = await legacyWorkflows.getLegacyWorkflowByIdHandler({
|
|
10372
|
-
mastra,
|
|
10373
|
-
workflowId
|
|
10374
|
-
});
|
|
10375
|
-
return c2.json(workflow);
|
|
10376
|
-
} catch (error) {
|
|
10377
|
-
return handleError(error, "Error getting workflow");
|
|
10378
|
-
}
|
|
10379
|
-
}
|
|
10380
|
-
async function startAsyncLegacyWorkflowHandler(c2) {
|
|
10381
|
-
try {
|
|
10382
|
-
const mastra = c2.get("mastra");
|
|
10383
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10384
|
-
const workflowId = c2.req.param("workflowId");
|
|
10385
|
-
const triggerData = await c2.req.json();
|
|
10386
|
-
const runId = c2.req.query("runId");
|
|
10387
|
-
const result = await legacyWorkflows.startAsyncLegacyWorkflowHandler({
|
|
10388
|
-
mastra,
|
|
10389
|
-
runtimeContext,
|
|
10390
|
-
workflowId,
|
|
10391
|
-
runId,
|
|
10392
|
-
triggerData
|
|
10393
|
-
});
|
|
10394
|
-
return c2.json(result);
|
|
10395
|
-
} catch (error) {
|
|
10396
|
-
return handleError(error, "Error executing workflow");
|
|
10397
|
-
}
|
|
10398
|
-
}
|
|
10399
|
-
async function createLegacyWorkflowRunHandler(c2) {
|
|
10400
|
-
try {
|
|
10401
|
-
const mastra = c2.get("mastra");
|
|
10402
|
-
const workflowId = c2.req.param("workflowId");
|
|
10403
|
-
const prevRunId = c2.req.query("runId");
|
|
10404
|
-
const result = await legacyWorkflows.createLegacyWorkflowRunHandler({
|
|
10405
|
-
mastra,
|
|
10406
|
-
workflowId,
|
|
10407
|
-
runId: prevRunId
|
|
10408
|
-
});
|
|
10409
|
-
return c2.json(result);
|
|
10410
|
-
} catch (e2) {
|
|
10411
|
-
return handleError(e2, "Error creating run");
|
|
10412
|
-
}
|
|
10413
|
-
}
|
|
10414
|
-
async function startLegacyWorkflowRunHandler(c2) {
|
|
10415
|
-
try {
|
|
10416
|
-
const mastra = c2.get("mastra");
|
|
10417
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10418
|
-
const workflowId = c2.req.param("workflowId");
|
|
10419
|
-
const triggerData = await c2.req.json();
|
|
10420
|
-
const runId = c2.req.query("runId");
|
|
10421
|
-
await legacyWorkflows.startLegacyWorkflowRunHandler({
|
|
10422
|
-
mastra,
|
|
10423
|
-
runtimeContext,
|
|
10424
|
-
workflowId,
|
|
10425
|
-
runId,
|
|
10426
|
-
triggerData
|
|
10427
|
-
});
|
|
10428
|
-
return c2.json({ message: "Workflow run started" });
|
|
10429
|
-
} catch (e2) {
|
|
10430
|
-
return handleError(e2, "Error starting workflow run");
|
|
10431
|
-
}
|
|
10432
|
-
}
|
|
10433
|
-
function watchLegacyWorkflowHandler(c2) {
|
|
10434
|
-
try {
|
|
10435
|
-
const mastra = c2.get("mastra");
|
|
10436
|
-
const logger2 = mastra.getLogger();
|
|
10437
|
-
const workflowId = c2.req.param("workflowId");
|
|
10438
|
-
const runId = c2.req.query("runId");
|
|
10439
|
-
if (!runId) {
|
|
10440
|
-
throw new httpException.HTTPException(400, { message: "runId required to watch workflow" });
|
|
10441
|
-
}
|
|
10442
|
-
return streaming.stream(
|
|
10443
|
-
c2,
|
|
10444
|
-
async (stream6) => {
|
|
10445
|
-
try {
|
|
10446
|
-
const result = await legacyWorkflows.watchLegacyWorkflowHandler({
|
|
10447
|
-
mastra,
|
|
10448
|
-
workflowId,
|
|
10449
|
-
runId
|
|
10450
|
-
});
|
|
10451
|
-
stream6.onAbort(() => {
|
|
10452
|
-
if (!result.locked) {
|
|
10453
|
-
return result.cancel();
|
|
10454
|
-
}
|
|
10455
|
-
});
|
|
10456
|
-
for await (const chunk of result) {
|
|
10457
|
-
await stream6.write(chunk.toString() + "");
|
|
10458
|
-
}
|
|
10459
|
-
} catch (err) {
|
|
10460
|
-
console.error(err);
|
|
10461
|
-
}
|
|
10462
|
-
},
|
|
10463
|
-
async (err) => {
|
|
10464
|
-
logger2.error("Error in watch stream: " + err?.message);
|
|
10465
|
-
}
|
|
10466
|
-
);
|
|
10467
|
-
} catch (error) {
|
|
10468
|
-
return handleError(error, "Error watching workflow");
|
|
10469
|
-
}
|
|
10470
|
-
}
|
|
10471
|
-
async function resumeAsyncLegacyWorkflowHandler(c2) {
|
|
10472
|
-
try {
|
|
10473
|
-
const mastra = c2.get("mastra");
|
|
10474
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10475
|
-
const workflowId = c2.req.param("workflowId");
|
|
10476
|
-
const runId = c2.req.query("runId");
|
|
10477
|
-
const { stepId, context } = await c2.req.json();
|
|
10478
|
-
if (!runId) {
|
|
10479
|
-
throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
|
|
10480
|
-
}
|
|
10481
|
-
const result = await legacyWorkflows.resumeAsyncLegacyWorkflowHandler({
|
|
10482
|
-
mastra,
|
|
10483
|
-
runtimeContext,
|
|
10484
|
-
workflowId,
|
|
10485
|
-
runId,
|
|
10486
|
-
body: { stepId, context }
|
|
10487
|
-
});
|
|
10488
|
-
return c2.json(result);
|
|
10489
|
-
} catch (error) {
|
|
10490
|
-
return handleError(error, "Error resuming workflow step");
|
|
10491
|
-
}
|
|
10492
|
-
}
|
|
10493
|
-
async function resumeLegacyWorkflowHandler(c2) {
|
|
10494
|
-
try {
|
|
10495
|
-
const mastra = c2.get("mastra");
|
|
10496
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10497
|
-
const workflowId = c2.req.param("workflowId");
|
|
10498
|
-
const runId = c2.req.query("runId");
|
|
10499
|
-
const { stepId, context } = await c2.req.json();
|
|
10500
|
-
if (!runId) {
|
|
10501
|
-
throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
|
|
10502
|
-
}
|
|
10503
|
-
await legacyWorkflows.resumeLegacyWorkflowHandler({
|
|
10504
|
-
mastra,
|
|
10505
|
-
runtimeContext,
|
|
10506
|
-
workflowId,
|
|
10507
|
-
runId,
|
|
10508
|
-
body: { stepId, context }
|
|
10509
|
-
});
|
|
10510
|
-
return c2.json({ message: "Workflow run resumed" });
|
|
10511
|
-
} catch (error) {
|
|
10512
|
-
return handleError(error, "Error resuming workflow");
|
|
10513
|
-
}
|
|
10514
|
-
}
|
|
10515
|
-
async function getLegacyWorkflowRunsHandler(c2) {
|
|
10516
|
-
try {
|
|
10517
|
-
const mastra = c2.get("mastra");
|
|
10518
|
-
const workflowId = c2.req.param("workflowId");
|
|
10519
|
-
const { fromDate, toDate, limit, offset, resourceId } = c2.req.query();
|
|
10520
|
-
const workflowRuns = await legacyWorkflows.getLegacyWorkflowRunsHandler({
|
|
10521
|
-
mastra,
|
|
10522
|
-
workflowId,
|
|
10523
|
-
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
10524
|
-
toDate: toDate ? new Date(toDate) : void 0,
|
|
10525
|
-
limit: limit ? Number(limit) : void 0,
|
|
10526
|
-
offset: offset ? Number(offset) : void 0,
|
|
10527
|
-
resourceId
|
|
10528
|
-
});
|
|
10529
|
-
return c2.json(workflowRuns);
|
|
10530
|
-
} catch (error) {
|
|
10531
|
-
return handleError(error, "Error getting workflow runs");
|
|
10532
|
-
}
|
|
10533
|
-
}
|
|
10534
|
-
|
|
10535
|
-
// src/server/handlers/routes/workflows/router.ts
|
|
10536
|
-
function workflowsRouter(bodyLimitOptions) {
|
|
10537
|
-
const router = new hono.Hono();
|
|
10538
|
-
router.get(
|
|
10539
|
-
"/legacy",
|
|
10540
|
-
w({
|
|
10541
|
-
description: "Get all legacy workflows",
|
|
10542
|
-
tags: ["legacyWorkflows"],
|
|
10543
|
-
responses: {
|
|
10544
|
-
200: {
|
|
10545
|
-
description: "List of all legacy workflows"
|
|
10546
|
-
}
|
|
10547
|
-
}
|
|
10548
|
-
}),
|
|
10549
|
-
getLegacyWorkflowsHandler
|
|
10550
|
-
);
|
|
10551
|
-
router.get(
|
|
10552
|
-
"/legacy/:workflowId",
|
|
10553
|
-
w({
|
|
10554
|
-
description: "Get legacy workflow by ID",
|
|
10555
|
-
tags: ["legacyWorkflows"],
|
|
10556
|
-
parameters: [
|
|
10557
|
-
{
|
|
10558
|
-
name: "workflowId",
|
|
10559
|
-
in: "path",
|
|
10560
|
-
required: true,
|
|
10561
|
-
schema: { type: "string" }
|
|
10562
|
-
}
|
|
10563
|
-
],
|
|
10564
|
-
responses: {
|
|
10565
|
-
200: {
|
|
10566
|
-
description: "Legacy Workflow details"
|
|
10567
|
-
},
|
|
10568
|
-
404: {
|
|
10569
|
-
description: "Legacy Workflow not found"
|
|
10570
|
-
}
|
|
10571
|
-
}
|
|
10572
|
-
}),
|
|
10573
|
-
getLegacyWorkflowByIdHandler
|
|
10574
|
-
);
|
|
10575
|
-
router.get(
|
|
10576
|
-
"/legacy/:workflowId/runs",
|
|
10577
|
-
w({
|
|
10578
|
-
description: "Get all runs for a legacy workflow",
|
|
10579
|
-
tags: ["legacyWorkflows"],
|
|
10580
|
-
parameters: [
|
|
10581
|
-
{
|
|
10582
|
-
name: "workflowId",
|
|
10583
|
-
in: "path",
|
|
10584
|
-
required: true,
|
|
10585
|
-
schema: { type: "string" }
|
|
10586
|
-
},
|
|
10587
|
-
{ name: "fromDate", in: "query", required: false, schema: { type: "string", format: "date-time" } },
|
|
10588
|
-
{ name: "toDate", in: "query", required: false, schema: { type: "string", format: "date-time" } },
|
|
10589
|
-
{ name: "limit", in: "query", required: false, schema: { type: "number" } },
|
|
10590
|
-
{ name: "offset", in: "query", required: false, schema: { type: "number" } },
|
|
10591
|
-
{ name: "resourceId", in: "query", required: false, schema: { type: "string" } }
|
|
10592
|
-
],
|
|
10593
|
-
responses: {
|
|
10594
|
-
200: {
|
|
10595
|
-
description: "List of legacy workflow runs from storage"
|
|
10596
|
-
}
|
|
10597
|
-
}
|
|
10598
|
-
}),
|
|
10599
|
-
getLegacyWorkflowRunsHandler
|
|
10600
|
-
);
|
|
10601
|
-
router.post(
|
|
10602
|
-
"/legacy/:workflowId/resume",
|
|
10603
|
-
w({
|
|
10604
|
-
description: "Resume a suspended legacy workflow step",
|
|
10605
|
-
tags: ["legacyWorkflows"],
|
|
10606
|
-
parameters: [
|
|
10607
|
-
{
|
|
10608
|
-
name: "workflowId",
|
|
10609
|
-
in: "path",
|
|
10610
|
-
required: true,
|
|
10611
|
-
schema: { type: "string" }
|
|
10612
|
-
},
|
|
10613
|
-
{
|
|
10614
|
-
name: "runId",
|
|
10615
|
-
in: "query",
|
|
10616
|
-
required: true,
|
|
10617
|
-
schema: { type: "string" }
|
|
10618
|
-
}
|
|
10619
|
-
],
|
|
10620
|
-
requestBody: {
|
|
10621
|
-
required: true,
|
|
10622
|
-
content: {
|
|
10623
|
-
"application/json": {
|
|
10624
|
-
schema: {
|
|
10625
|
-
type: "object",
|
|
10626
|
-
properties: {
|
|
10627
|
-
stepId: { type: "string" },
|
|
10628
|
-
context: { type: "object" },
|
|
10629
|
-
tracingOptions: {
|
|
10630
|
-
type: "object",
|
|
10631
|
-
description: "Tracing options for the workflow execution",
|
|
10632
|
-
properties: {
|
|
10633
|
-
metadata: {
|
|
10634
|
-
type: "object",
|
|
10635
|
-
description: "Custom metadata to attach to the trace",
|
|
10636
|
-
additionalProperties: true
|
|
10637
|
-
}
|
|
10638
|
-
}
|
|
10639
|
-
}
|
|
10640
|
-
}
|
|
10641
|
-
}
|
|
10642
|
-
}
|
|
10643
|
-
}
|
|
10644
|
-
}
|
|
10645
|
-
}),
|
|
10646
|
-
resumeLegacyWorkflowHandler
|
|
10647
|
-
);
|
|
10648
|
-
router.post(
|
|
10649
|
-
"/legacy/:workflowId/resume-async",
|
|
10650
|
-
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
10651
|
-
w({
|
|
10652
|
-
description: "Resume a suspended legacy workflow step",
|
|
10653
|
-
tags: ["legacyWorkflows"],
|
|
10654
|
-
parameters: [
|
|
10655
|
-
{
|
|
10656
|
-
name: "workflowId",
|
|
10657
|
-
in: "path",
|
|
10658
|
-
required: true,
|
|
10659
|
-
schema: { type: "string" }
|
|
10660
|
-
},
|
|
10661
|
-
{
|
|
10662
|
-
name: "runId",
|
|
10663
|
-
in: "query",
|
|
10664
|
-
required: true,
|
|
10665
|
-
schema: { type: "string" }
|
|
10666
|
-
}
|
|
10667
|
-
],
|
|
10668
|
-
requestBody: {
|
|
10669
|
-
required: true,
|
|
10670
|
-
content: {
|
|
10671
|
-
"application/json": {
|
|
10672
|
-
schema: {
|
|
10673
|
-
type: "object",
|
|
10674
|
-
properties: {
|
|
10675
|
-
stepId: { type: "string" },
|
|
10676
|
-
context: { type: "object" },
|
|
10677
|
-
tracingOptions: {
|
|
10678
|
-
type: "object",
|
|
10679
|
-
description: "Tracing options for the workflow execution",
|
|
10680
|
-
properties: {
|
|
10681
|
-
metadata: {
|
|
10682
|
-
type: "object",
|
|
10683
|
-
description: "Custom metadata to attach to the trace",
|
|
10684
|
-
additionalProperties: true
|
|
10685
|
-
}
|
|
10686
|
-
}
|
|
10687
|
-
}
|
|
10688
|
-
}
|
|
10689
|
-
}
|
|
10690
|
-
}
|
|
10691
|
-
}
|
|
10692
|
-
}
|
|
10693
|
-
}),
|
|
10694
|
-
resumeAsyncLegacyWorkflowHandler
|
|
10695
|
-
);
|
|
10696
|
-
router.post(
|
|
10697
|
-
"/legacy/:workflowId/create-run",
|
|
10698
|
-
w({
|
|
10699
|
-
description: "Create a new legacy workflow run",
|
|
10700
|
-
tags: ["legacyWorkflows"],
|
|
10701
|
-
parameters: [
|
|
10702
|
-
{
|
|
10703
|
-
name: "workflowId",
|
|
10704
|
-
in: "path",
|
|
10705
|
-
required: true,
|
|
10706
|
-
schema: { type: "string" }
|
|
10707
|
-
},
|
|
10708
|
-
{
|
|
10709
|
-
name: "runId",
|
|
10710
|
-
in: "query",
|
|
10711
|
-
required: false,
|
|
10712
|
-
schema: { type: "string" }
|
|
10713
|
-
}
|
|
10714
|
-
],
|
|
10715
|
-
responses: {
|
|
10716
|
-
200: {
|
|
10717
|
-
description: "New legacy workflow run created"
|
|
10718
|
-
}
|
|
10719
|
-
}
|
|
10720
|
-
}),
|
|
10721
|
-
createLegacyWorkflowRunHandler
|
|
10722
|
-
);
|
|
10723
|
-
router.post(
|
|
10724
|
-
"/legacy/:workflowId/start-async",
|
|
10725
|
-
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
10726
|
-
w({
|
|
10727
|
-
description: "Execute/Start a legacy workflow",
|
|
10728
|
-
tags: ["legacyWorkflows"],
|
|
10729
|
-
parameters: [
|
|
10730
|
-
{
|
|
10731
|
-
name: "workflowId",
|
|
10732
|
-
in: "path",
|
|
10733
|
-
required: true,
|
|
10734
|
-
schema: { type: "string" }
|
|
10735
|
-
},
|
|
10736
|
-
{
|
|
10737
|
-
name: "runId",
|
|
10738
|
-
in: "query",
|
|
10739
|
-
required: false,
|
|
10740
|
-
schema: { type: "string" }
|
|
10741
|
-
}
|
|
10742
|
-
],
|
|
10743
|
-
requestBody: {
|
|
10744
|
-
required: true,
|
|
10745
|
-
content: {
|
|
10746
|
-
"application/json": {
|
|
10747
|
-
schema: {
|
|
10748
|
-
type: "object",
|
|
10749
|
-
properties: {
|
|
10750
|
-
input: { type: "object" }
|
|
10751
|
-
}
|
|
10752
|
-
}
|
|
10753
|
-
}
|
|
10754
|
-
}
|
|
10755
|
-
},
|
|
10756
|
-
responses: {
|
|
10757
|
-
200: {
|
|
10758
|
-
description: "Legacy Workflow execution result"
|
|
10759
|
-
},
|
|
10760
|
-
404: {
|
|
10761
|
-
description: "Legacy Workflow not found"
|
|
10762
|
-
}
|
|
10763
|
-
}
|
|
10764
|
-
}),
|
|
10765
|
-
startAsyncLegacyWorkflowHandler
|
|
10766
|
-
);
|
|
10767
|
-
router.post(
|
|
10768
|
-
"/legacy/:workflowId/start",
|
|
10769
|
-
w({
|
|
10770
|
-
description: "Create and start a new legacy workflow run",
|
|
10771
|
-
tags: ["legacyWorkflows"],
|
|
10772
|
-
parameters: [
|
|
10773
|
-
{
|
|
10774
|
-
name: "workflowId",
|
|
10775
|
-
in: "path",
|
|
10776
|
-
required: true,
|
|
10777
|
-
schema: { type: "string" }
|
|
10778
|
-
},
|
|
10779
|
-
{
|
|
10780
|
-
name: "runId",
|
|
10781
|
-
in: "query",
|
|
10782
|
-
required: true,
|
|
10783
|
-
schema: { type: "string" }
|
|
10784
|
-
}
|
|
10785
|
-
],
|
|
10786
|
-
requestBody: {
|
|
10787
|
-
required: true,
|
|
10788
|
-
content: {
|
|
10789
|
-
"application/json": {
|
|
10790
|
-
schema: {
|
|
10791
|
-
type: "object",
|
|
10792
|
-
properties: {
|
|
10793
|
-
input: { type: "object" }
|
|
10794
|
-
}
|
|
10795
|
-
}
|
|
10375
|
+
async (stream5) => {
|
|
10376
|
+
try {
|
|
10377
|
+
const result = await workflows.observeStreamLegacyWorkflowHandler({
|
|
10378
|
+
mastra,
|
|
10379
|
+
workflowId,
|
|
10380
|
+
runId
|
|
10381
|
+
});
|
|
10382
|
+
const reader = result.getReader();
|
|
10383
|
+
stream5.onAbort(() => {
|
|
10384
|
+
void reader.cancel("request aborted");
|
|
10385
|
+
});
|
|
10386
|
+
let chunkResult;
|
|
10387
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10388
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
10796
10389
|
}
|
|
10390
|
+
} catch (err) {
|
|
10391
|
+
logger2.error("Error in workflow observe stream: " + (err?.message ?? "Unknown error"));
|
|
10797
10392
|
}
|
|
10393
|
+
await stream5.close();
|
|
10798
10394
|
},
|
|
10799
|
-
|
|
10800
|
-
|
|
10801
|
-
description: "Legacy Workflow run started"
|
|
10802
|
-
},
|
|
10803
|
-
404: {
|
|
10804
|
-
description: "Legacy Workflow not found"
|
|
10805
|
-
}
|
|
10395
|
+
async (err) => {
|
|
10396
|
+
logger2.error("Error in workflow observe stream: " + err?.message);
|
|
10806
10397
|
}
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10398
|
+
);
|
|
10399
|
+
} catch (error) {
|
|
10400
|
+
return handleError(error, "Error observing workflow stream");
|
|
10401
|
+
}
|
|
10402
|
+
}
|
|
10403
|
+
async function resumeStreamWorkflowHandler(c2) {
|
|
10404
|
+
try {
|
|
10405
|
+
const mastra = c2.get("mastra");
|
|
10406
|
+
const requestContext = c2.get("requestContext");
|
|
10407
|
+
const logger2 = mastra.getLogger();
|
|
10408
|
+
const workflowId = c2.req.param("workflowId");
|
|
10409
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10410
|
+
const runId = c2.req.query("runId");
|
|
10411
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
10412
|
+
return streaming.stream(
|
|
10413
|
+
c2,
|
|
10414
|
+
async (stream5) => {
|
|
10415
|
+
try {
|
|
10416
|
+
const result = await workflows.resumeStreamWorkflowHandler({
|
|
10417
|
+
mastra,
|
|
10418
|
+
workflowId,
|
|
10419
|
+
runId,
|
|
10420
|
+
body: { step, resumeData },
|
|
10421
|
+
requestContext,
|
|
10422
|
+
tracingOptions
|
|
10423
|
+
});
|
|
10424
|
+
const reader = result.getReader();
|
|
10425
|
+
stream5.onAbort(() => {
|
|
10426
|
+
void reader.cancel("request aborted");
|
|
10427
|
+
});
|
|
10428
|
+
let chunkResult;
|
|
10429
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10430
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
10431
|
+
}
|
|
10432
|
+
} catch (err) {
|
|
10433
|
+
logger2.error("Error in workflow VNext stream: " + (err?.message ?? "Unknown error"));
|
|
10832
10434
|
}
|
|
10435
|
+
},
|
|
10436
|
+
async (err) => {
|
|
10437
|
+
logger2.error("Error in workflow VNext stream: " + err?.message);
|
|
10833
10438
|
}
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10439
|
+
);
|
|
10440
|
+
} catch (error) {
|
|
10441
|
+
return handleError(error, "Error streaming workflow");
|
|
10442
|
+
}
|
|
10443
|
+
}
|
|
10444
|
+
async function resumeAsyncWorkflowHandler(c2) {
|
|
10445
|
+
try {
|
|
10446
|
+
const mastra = c2.get("mastra");
|
|
10447
|
+
const requestContext = c2.get("requestContext");
|
|
10448
|
+
const workflowId = c2.req.param("workflowId");
|
|
10449
|
+
const runId = c2.req.query("runId");
|
|
10450
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10451
|
+
if (!runId) {
|
|
10452
|
+
throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
|
|
10453
|
+
}
|
|
10454
|
+
const result = await workflows.resumeAsyncWorkflowHandler({
|
|
10455
|
+
mastra,
|
|
10456
|
+
requestContext,
|
|
10457
|
+
workflowId,
|
|
10458
|
+
runId,
|
|
10459
|
+
body: { step, resumeData },
|
|
10460
|
+
tracingOptions
|
|
10461
|
+
});
|
|
10462
|
+
return c2.json(result);
|
|
10463
|
+
} catch (error) {
|
|
10464
|
+
return handleError(error, "Error resuming workflow step");
|
|
10465
|
+
}
|
|
10466
|
+
}
|
|
10467
|
+
async function resumeWorkflowHandler(c2) {
|
|
10468
|
+
try {
|
|
10469
|
+
const mastra = c2.get("mastra");
|
|
10470
|
+
const requestContext = c2.get("requestContext");
|
|
10471
|
+
const workflowId = c2.req.param("workflowId");
|
|
10472
|
+
const runId = c2.req.query("runId");
|
|
10473
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10474
|
+
if (!runId) {
|
|
10475
|
+
throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
|
|
10476
|
+
}
|
|
10477
|
+
await workflows.resumeWorkflowHandler({
|
|
10478
|
+
mastra,
|
|
10479
|
+
requestContext,
|
|
10480
|
+
workflowId,
|
|
10481
|
+
runId,
|
|
10482
|
+
body: { step, resumeData },
|
|
10483
|
+
tracingOptions
|
|
10484
|
+
});
|
|
10485
|
+
return c2.json({ message: "Workflow run resumed" });
|
|
10486
|
+
} catch (error) {
|
|
10487
|
+
return handleError(error, "Error resuming workflow");
|
|
10488
|
+
}
|
|
10489
|
+
}
|
|
10490
|
+
async function listWorkflowRunsHandler(c2) {
|
|
10491
|
+
try {
|
|
10492
|
+
const mastra = c2.get("mastra");
|
|
10493
|
+
const workflowId = c2.req.param("workflowId");
|
|
10494
|
+
const { fromDate, toDate, perPage: perPageRaw, page: pageRaw, resourceId } = c2.req.query();
|
|
10495
|
+
const workflowRuns = await workflows.listWorkflowRunsHandler({
|
|
10496
|
+
mastra,
|
|
10497
|
+
workflowId,
|
|
10498
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
10499
|
+
toDate: toDate ? new Date(toDate) : void 0,
|
|
10500
|
+
perPage: perPageRaw !== void 0 ? parsePerPage(perPageRaw) : void 0,
|
|
10501
|
+
page: pageRaw !== void 0 ? parsePage(pageRaw) : void 0,
|
|
10502
|
+
resourceId
|
|
10503
|
+
});
|
|
10504
|
+
return c2.json(workflowRuns);
|
|
10505
|
+
} catch (error) {
|
|
10506
|
+
return handleError(error, "Error getting workflow runs");
|
|
10507
|
+
}
|
|
10508
|
+
}
|
|
10509
|
+
async function getWorkflowRunByIdHandler(c2) {
|
|
10510
|
+
try {
|
|
10511
|
+
const mastra = c2.get("mastra");
|
|
10512
|
+
const workflowId = c2.req.param("workflowId");
|
|
10513
|
+
const runId = c2.req.param("runId");
|
|
10514
|
+
const workflowRun = await workflows.getWorkflowRunByIdHandler({
|
|
10515
|
+
mastra,
|
|
10516
|
+
workflowId,
|
|
10517
|
+
runId
|
|
10518
|
+
});
|
|
10519
|
+
return c2.json(workflowRun);
|
|
10520
|
+
} catch (error) {
|
|
10521
|
+
return handleError(error, "Error getting workflow run");
|
|
10522
|
+
}
|
|
10523
|
+
}
|
|
10524
|
+
async function getWorkflowRunExecutionResultHandler(c2) {
|
|
10525
|
+
try {
|
|
10526
|
+
const mastra = c2.get("mastra");
|
|
10527
|
+
const workflowId = c2.req.param("workflowId");
|
|
10528
|
+
const runId = c2.req.param("runId");
|
|
10529
|
+
const workflowRunExecutionResult = await workflows.getWorkflowRunExecutionResultHandler({
|
|
10530
|
+
mastra,
|
|
10531
|
+
workflowId,
|
|
10532
|
+
runId
|
|
10533
|
+
});
|
|
10534
|
+
return c2.json(workflowRunExecutionResult);
|
|
10535
|
+
} catch (error) {
|
|
10536
|
+
return handleError(error, "Error getting workflow run execution result");
|
|
10537
|
+
}
|
|
10538
|
+
}
|
|
10539
|
+
async function cancelWorkflowRunHandler(c2) {
|
|
10540
|
+
try {
|
|
10541
|
+
const mastra = c2.get("mastra");
|
|
10542
|
+
const workflowId = c2.req.param("workflowId");
|
|
10543
|
+
const runId = c2.req.param("runId");
|
|
10544
|
+
const result = await workflows.cancelWorkflowRunHandler({
|
|
10545
|
+
mastra,
|
|
10546
|
+
workflowId,
|
|
10547
|
+
runId
|
|
10548
|
+
});
|
|
10549
|
+
return c2.json(result);
|
|
10550
|
+
} catch (error) {
|
|
10551
|
+
return handleError(error, "Error canceling workflow run");
|
|
10552
|
+
}
|
|
10553
|
+
}
|
|
10554
|
+
|
|
10555
|
+
// src/server/handlers/routes/workflows/router.ts
|
|
10556
|
+
function workflowsRouter(bodyLimitOptions) {
|
|
10557
|
+
const router = new hono.Hono();
|
|
10837
10558
|
router.get(
|
|
10838
10559
|
"/",
|
|
10839
10560
|
w({
|
|
@@ -10845,7 +10566,7 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
10845
10566
|
}
|
|
10846
10567
|
}
|
|
10847
10568
|
}),
|
|
10848
|
-
|
|
10569
|
+
listWorkflowsHandler
|
|
10849
10570
|
);
|
|
10850
10571
|
router.get(
|
|
10851
10572
|
"/:workflowId",
|
|
@@ -10874,7 +10595,7 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
10874
10595
|
router.get(
|
|
10875
10596
|
"/:workflowId/runs",
|
|
10876
10597
|
w({
|
|
10877
|
-
description: "
|
|
10598
|
+
description: "List all runs for a workflow",
|
|
10878
10599
|
tags: ["workflows"],
|
|
10879
10600
|
parameters: [
|
|
10880
10601
|
{
|
|
@@ -10895,7 +10616,7 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
10895
10616
|
}
|
|
10896
10617
|
}
|
|
10897
10618
|
}),
|
|
10898
|
-
|
|
10619
|
+
listWorkflowRunsHandler
|
|
10899
10620
|
);
|
|
10900
10621
|
router.get(
|
|
10901
10622
|
"/:workflowId/runs/:runId/execution-result",
|
|
@@ -10987,9 +10708,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
10987
10708
|
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
10988
10709
|
},
|
|
10989
10710
|
resumeData: { type: "object" },
|
|
10990
|
-
|
|
10711
|
+
requestContext: {
|
|
10991
10712
|
type: "object",
|
|
10992
|
-
description: "
|
|
10713
|
+
description: "Request Context for the workflow execution"
|
|
10993
10714
|
}
|
|
10994
10715
|
}
|
|
10995
10716
|
}
|
|
@@ -11029,9 +10750,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11029
10750
|
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
11030
10751
|
},
|
|
11031
10752
|
resumeData: { type: "object" },
|
|
11032
|
-
|
|
10753
|
+
requestContext: {
|
|
11033
10754
|
type: "object",
|
|
11034
|
-
description: "
|
|
10755
|
+
description: "Request Context for the workflow execution"
|
|
11035
10756
|
},
|
|
11036
10757
|
tracingOptions: {
|
|
11037
10758
|
type: "object",
|
|
@@ -11083,9 +10804,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11083
10804
|
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
11084
10805
|
},
|
|
11085
10806
|
resumeData: { type: "object" },
|
|
11086
|
-
|
|
10807
|
+
requestContext: {
|
|
11087
10808
|
type: "object",
|
|
11088
|
-
description: "
|
|
10809
|
+
description: "Request Context for the workflow execution"
|
|
11089
10810
|
}
|
|
11090
10811
|
}
|
|
11091
10812
|
}
|
|
@@ -11121,9 +10842,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11121
10842
|
type: "object",
|
|
11122
10843
|
properties: {
|
|
11123
10844
|
inputData: { type: "object" },
|
|
11124
|
-
|
|
10845
|
+
requestContext: {
|
|
11125
10846
|
type: "object",
|
|
11126
|
-
description: "
|
|
10847
|
+
description: "Request Context for the workflow execution"
|
|
11127
10848
|
},
|
|
11128
10849
|
tracingOptions: {
|
|
11129
10850
|
type: "object",
|
|
@@ -11209,9 +10930,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11209
10930
|
type: "object",
|
|
11210
10931
|
properties: {
|
|
11211
10932
|
inputData: { type: "object" },
|
|
11212
|
-
|
|
10933
|
+
requestContext: {
|
|
11213
10934
|
type: "object",
|
|
11214
|
-
description: "
|
|
10935
|
+
description: "Request Context for the workflow execution"
|
|
11215
10936
|
},
|
|
11216
10937
|
closeOnSuspend: {
|
|
11217
10938
|
type: "boolean",
|
|
@@ -11301,9 +11022,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11301
11022
|
type: "object",
|
|
11302
11023
|
properties: {
|
|
11303
11024
|
inputData: { type: "object" },
|
|
11304
|
-
|
|
11025
|
+
requestContext: {
|
|
11305
11026
|
type: "object",
|
|
11306
|
-
description: "
|
|
11027
|
+
description: "Request Context for the workflow execution"
|
|
11307
11028
|
},
|
|
11308
11029
|
closeOnSuspend: {
|
|
11309
11030
|
type: "boolean",
|
|
@@ -11423,9 +11144,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11423
11144
|
type: "object",
|
|
11424
11145
|
properties: {
|
|
11425
11146
|
inputData: { type: "object" },
|
|
11426
|
-
|
|
11147
|
+
requestContext: {
|
|
11427
11148
|
type: "object",
|
|
11428
|
-
description: "
|
|
11149
|
+
description: "Request Context for the workflow execution"
|
|
11429
11150
|
},
|
|
11430
11151
|
tracingOptions: {
|
|
11431
11152
|
type: "object",
|
|
@@ -11481,9 +11202,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11481
11202
|
type: "object",
|
|
11482
11203
|
properties: {
|
|
11483
11204
|
inputData: { type: "object" },
|
|
11484
|
-
|
|
11205
|
+
requestContext: {
|
|
11485
11206
|
type: "object",
|
|
11486
|
-
description: "
|
|
11207
|
+
description: "Request Context for the workflow execution"
|
|
11487
11208
|
},
|
|
11488
11209
|
tracingOptions: {
|
|
11489
11210
|
type: "object",
|
|
@@ -11512,33 +11233,6 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11512
11233
|
}),
|
|
11513
11234
|
startWorkflowRunHandler
|
|
11514
11235
|
);
|
|
11515
|
-
router.get(
|
|
11516
|
-
"/:workflowId/watch",
|
|
11517
|
-
w({
|
|
11518
|
-
description: "Watch workflow transitions in real-time",
|
|
11519
|
-
parameters: [
|
|
11520
|
-
{
|
|
11521
|
-
name: "workflowId",
|
|
11522
|
-
in: "path",
|
|
11523
|
-
required: true,
|
|
11524
|
-
schema: { type: "string" }
|
|
11525
|
-
},
|
|
11526
|
-
{
|
|
11527
|
-
name: "runId",
|
|
11528
|
-
in: "query",
|
|
11529
|
-
required: false,
|
|
11530
|
-
schema: { type: "string" }
|
|
11531
|
-
}
|
|
11532
|
-
],
|
|
11533
|
-
tags: ["workflows"],
|
|
11534
|
-
responses: {
|
|
11535
|
-
200: {
|
|
11536
|
-
description: "workflow transitions in real-time"
|
|
11537
|
-
}
|
|
11538
|
-
}
|
|
11539
|
-
}),
|
|
11540
|
-
watchWorkflowHandler
|
|
11541
|
-
);
|
|
11542
11236
|
router.post(
|
|
11543
11237
|
"/:workflowId/runs/:runId/cancel",
|
|
11544
11238
|
w({
|
|
@@ -11566,41 +11260,6 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11566
11260
|
}),
|
|
11567
11261
|
cancelWorkflowRunHandler
|
|
11568
11262
|
);
|
|
11569
|
-
router.post(
|
|
11570
|
-
"/:workflowId/runs/:runId/send-event",
|
|
11571
|
-
w({
|
|
11572
|
-
description: "Send an event to a workflow run",
|
|
11573
|
-
parameters: [
|
|
11574
|
-
{
|
|
11575
|
-
name: "workflowId",
|
|
11576
|
-
in: "path",
|
|
11577
|
-
required: true,
|
|
11578
|
-
schema: { type: "string" }
|
|
11579
|
-
},
|
|
11580
|
-
{
|
|
11581
|
-
name: "runId",
|
|
11582
|
-
in: "path",
|
|
11583
|
-
required: true,
|
|
11584
|
-
schema: { type: "string" }
|
|
11585
|
-
}
|
|
11586
|
-
],
|
|
11587
|
-
requestBody: {
|
|
11588
|
-
required: true,
|
|
11589
|
-
content: {
|
|
11590
|
-
"application/json": {
|
|
11591
|
-
schema: { type: "object", properties: { event: { type: "string" }, data: { type: "object" } } }
|
|
11592
|
-
}
|
|
11593
|
-
}
|
|
11594
|
-
},
|
|
11595
|
-
tags: ["workflows"],
|
|
11596
|
-
responses: {
|
|
11597
|
-
200: {
|
|
11598
|
-
description: "workflow run event sent"
|
|
11599
|
-
}
|
|
11600
|
-
}
|
|
11601
|
-
}),
|
|
11602
|
-
sendWorkflowRunEventHandler
|
|
11603
|
-
);
|
|
11604
11263
|
return router;
|
|
11605
11264
|
}
|
|
11606
11265
|
|
|
@@ -11689,7 +11348,7 @@ var html2 = `
|
|
|
11689
11348
|
<main>
|
|
11690
11349
|
<h1>Welcome to Mastra</h1>
|
|
11691
11350
|
<p class="subtitle">
|
|
11692
|
-
|
|
11351
|
+
Prototype and productionize AI features with a modern JS/TS stack.
|
|
11693
11352
|
</p>
|
|
11694
11353
|
|
|
11695
11354
|
<a href="https://mastra.ai/docs" class="docs-link">
|
|
@@ -11747,36 +11406,17 @@ async function createHonoServer(mastra, options = {
|
|
|
11747
11406
|
customRouteAuthConfig.set(routeKey, requiresAuth);
|
|
11748
11407
|
}
|
|
11749
11408
|
}
|
|
11750
|
-
app.use("*", async function setTelemetryInfo(c2, next) {
|
|
11751
|
-
const requestId = c2.req.header("x-request-id") ?? crypto.randomUUID();
|
|
11752
|
-
const span = telemetry.Telemetry.getActiveSpan();
|
|
11753
|
-
if (span) {
|
|
11754
|
-
span.setAttribute("http.request_id", requestId);
|
|
11755
|
-
span.updateName(`${c2.req.method} ${c2.req.path}`);
|
|
11756
|
-
const newCtx = telemetry.Telemetry.setBaggage({
|
|
11757
|
-
"http.request_id": { value: requestId }
|
|
11758
|
-
});
|
|
11759
|
-
await new Promise((resolve) => {
|
|
11760
|
-
telemetry.Telemetry.withContext(newCtx, async () => {
|
|
11761
|
-
await next();
|
|
11762
|
-
resolve(true);
|
|
11763
|
-
});
|
|
11764
|
-
});
|
|
11765
|
-
} else {
|
|
11766
|
-
await next();
|
|
11767
|
-
}
|
|
11768
|
-
});
|
|
11769
11409
|
app.onError((err, c2) => errorHandler(err, c2, options.isDev));
|
|
11770
11410
|
app.use("*", async function setContext(c2, next) {
|
|
11771
|
-
let
|
|
11411
|
+
let requestContext$1 = new requestContext.RequestContext();
|
|
11772
11412
|
if (c2.req.method === "POST" || c2.req.method === "PUT") {
|
|
11773
11413
|
const contentType = c2.req.header("content-type");
|
|
11774
11414
|
if (contentType?.includes("application/json")) {
|
|
11775
11415
|
try {
|
|
11776
11416
|
const clonedReq = c2.req.raw.clone();
|
|
11777
11417
|
const body = await clonedReq.json();
|
|
11778
|
-
if (body.
|
|
11779
|
-
|
|
11418
|
+
if (body.requestContext) {
|
|
11419
|
+
requestContext$1 = new requestContext.RequestContext(Object.entries(body.requestContext));
|
|
11780
11420
|
}
|
|
11781
11421
|
} catch {
|
|
11782
11422
|
}
|
|
@@ -11784,26 +11424,26 @@ async function createHonoServer(mastra, options = {
|
|
|
11784
11424
|
}
|
|
11785
11425
|
if (c2.req.method === "GET") {
|
|
11786
11426
|
try {
|
|
11787
|
-
const
|
|
11788
|
-
if (
|
|
11789
|
-
let
|
|
11427
|
+
const encodedRequestContext = c2.req.query("requestContext");
|
|
11428
|
+
if (encodedRequestContext) {
|
|
11429
|
+
let parsedRequestContext;
|
|
11790
11430
|
try {
|
|
11791
|
-
|
|
11431
|
+
parsedRequestContext = JSON.parse(encodedRequestContext);
|
|
11792
11432
|
} catch {
|
|
11793
11433
|
try {
|
|
11794
|
-
const json = Buffer.from(
|
|
11795
|
-
|
|
11434
|
+
const json = Buffer.from(encodedRequestContext, "base64").toString("utf-8");
|
|
11435
|
+
parsedRequestContext = JSON.parse(json);
|
|
11796
11436
|
} catch {
|
|
11797
11437
|
}
|
|
11798
11438
|
}
|
|
11799
|
-
if (
|
|
11800
|
-
|
|
11439
|
+
if (parsedRequestContext && typeof parsedRequestContext === "object") {
|
|
11440
|
+
requestContext$1 = new requestContext.RequestContext([...requestContext$1.entries(), ...Object.entries(parsedRequestContext)]);
|
|
11801
11441
|
}
|
|
11802
11442
|
}
|
|
11803
11443
|
} catch {
|
|
11804
11444
|
}
|
|
11805
11445
|
}
|
|
11806
|
-
c2.set("
|
|
11446
|
+
c2.set("requestContext", requestContext$1);
|
|
11807
11447
|
c2.set("mastra", mastra);
|
|
11808
11448
|
c2.set("tools", options.tools);
|
|
11809
11449
|
c2.set("taskStore", a2aTaskStore);
|
|
@@ -11832,6 +11472,19 @@ async function createHonoServer(mastra, options = {
|
|
|
11832
11472
|
};
|
|
11833
11473
|
app.use("*", timeout.timeout(server?.timeout ?? 3 * 60 * 1e3), cors.cors(corsConfig));
|
|
11834
11474
|
}
|
|
11475
|
+
app.get(
|
|
11476
|
+
"/health",
|
|
11477
|
+
w({
|
|
11478
|
+
description: "Health check endpoint",
|
|
11479
|
+
tags: ["system"],
|
|
11480
|
+
responses: {
|
|
11481
|
+
200: {
|
|
11482
|
+
description: "Service is healthy"
|
|
11483
|
+
}
|
|
11484
|
+
}
|
|
11485
|
+
}),
|
|
11486
|
+
healthHandler
|
|
11487
|
+
);
|
|
11835
11488
|
app.use("*", authenticationMiddleware);
|
|
11836
11489
|
app.use("*", authorizationMiddleware);
|
|
11837
11490
|
const bodyLimitOptions = {
|
|
@@ -12037,7 +11690,6 @@ async function createHonoServer(mastra, options = {
|
|
|
12037
11690
|
}
|
|
12038
11691
|
app.route("/api/mcp", mcpRouter(bodyLimitOptions));
|
|
12039
11692
|
app.route("/api/memory", memoryRoutes(bodyLimitOptions));
|
|
12040
|
-
app.route("/api/telemetry", telemetryRouter());
|
|
12041
11693
|
app.route("/api/observability", observabilityRouter());
|
|
12042
11694
|
app.route("/api/workflows", workflowsRouter(bodyLimitOptions));
|
|
12043
11695
|
app.route("/api/logs", logsRouter());
|
|
@@ -12118,10 +11770,6 @@ async function createHonoServer(mastra, options = {
|
|
|
12118
11770
|
}
|
|
12119
11771
|
if (options?.playground) {
|
|
12120
11772
|
let indexHtml = await promises.readFile(posix.join(process.cwd(), "./playground/index.html"), "utf-8");
|
|
12121
|
-
indexHtml = indexHtml.replace(
|
|
12122
|
-
`'%%MASTRA_TELEMETRY_DISABLED%%'`,
|
|
12123
|
-
`${Boolean(process.env.MASTRA_TELEMETRY_DISABLED)}`
|
|
12124
|
-
);
|
|
12125
11773
|
const serverOptions = mastra.getServer();
|
|
12126
11774
|
const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
|
|
12127
11775
|
const hideCloudCta = process.env.MASTRA_HIDE_CLOUD_CTA === "true";
|