@mastra/deployer 0.11.0-alpha.1 → 0.11.0-alpha.3

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.
Files changed (34) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +79 -8
  2. package/dist/_tsup-dts-rollup.d.ts +79 -8
  3. package/dist/build/analyze.cjs +2 -2
  4. package/dist/build/analyze.js +1 -1
  5. package/dist/build/bundler.cjs +3 -3
  6. package/dist/build/bundler.js +1 -1
  7. package/dist/build/index.cjs +15 -15
  8. package/dist/build/index.js +5 -5
  9. package/dist/bundler/index.cjs +2 -2
  10. package/dist/bundler/index.js +1 -1
  11. package/dist/{chunk-GPD54HBC.js → chunk-7HFWRNM7.js} +1 -7
  12. package/dist/{chunk-Z544XXXK.js → chunk-AFR3LY44.js} +45 -4
  13. package/dist/{chunk-LT2BJRBN.js → chunk-APPDEIPA.js} +9 -4
  14. package/dist/{chunk-YFMAWUII.cjs → chunk-D73JIE6N.cjs} +37 -19
  15. package/dist/{chunk-HJGC75ZR.js → chunk-DB7LRMOC.js} +27 -9
  16. package/dist/{chunk-M2VZQFTW.cjs → chunk-E7ZSCQUV.cjs} +15 -9
  17. package/dist/{chunk-KCP5ITLV.cjs → chunk-F25LATVR.cjs} +3 -9
  18. package/dist/{chunk-TIC2KT3M.js → chunk-HZNWZQHG.js} +2 -1
  19. package/dist/{chunk-D2DCFCLH.cjs → chunk-MOG6ASL4.cjs} +4 -3
  20. package/dist/{chunk-ENT5RDOI.js → chunk-NB6XIOPQ.js} +14 -8
  21. package/dist/{chunk-YVPLA2GR.cjs → chunk-TK2RG7LU.cjs} +14 -9
  22. package/dist/{chunk-UYQZMNZL.js → chunk-TLGEPS44.js} +29 -3
  23. package/dist/{chunk-54KOF3NB.cjs → chunk-WKW236CI.cjs} +46 -4
  24. package/dist/{chunk-XKH6F4NE.cjs → chunk-WTGMSQT5.cjs} +32 -6
  25. package/dist/index.cjs +11 -11
  26. package/dist/index.js +4 -4
  27. package/dist/server/index.cjs +1169 -375
  28. package/dist/server/index.d.cts +1 -0
  29. package/dist/server/index.d.ts +1 -0
  30. package/dist/server/index.js +1174 -381
  31. package/dist/services/index.cjs +4 -4
  32. package/dist/services/index.js +1 -1
  33. package/dist/templates/instrumentation-template.js +10 -6
  34. package/package.json +3 -3
@@ -21,10 +21,10 @@ var httpException = require('hono/http-exception');
21
21
  var a2a = require('@mastra/server/handlers/a2a');
22
22
  var streaming = require('hono/streaming');
23
23
  var bodyLimit = require('hono/body-limit');
24
- var agents = require('@mastra/server/handlers/agents');
25
24
  var agent = require('@mastra/core/agent');
26
25
  var zod = require('zod');
27
26
  var tools$1 = require('@mastra/server/handlers/tools');
27
+ var agents = require('@mastra/server/handlers/agents');
28
28
  var voice = require('@mastra/server/handlers/voice');
29
29
  var logs = require('@mastra/server/handlers/logs');
30
30
  var util = require('util');
@@ -32,10 +32,11 @@ var buffer = require('buffer');
32
32
  var memory = require('@mastra/server/handlers/memory');
33
33
  var network = require('@mastra/server/handlers/network');
34
34
  var vNextNetwork = require('@mastra/server/handlers/vNextNetwork');
35
+ var scores = require('@mastra/server/handlers/scores');
35
36
  var telemetry = require('@mastra/server/handlers/telemetry');
36
37
  var vector = require('@mastra/server/handlers/vector');
37
- var legacyWorkflows = require('@mastra/server/handlers/legacyWorkflows');
38
38
  var workflows = require('@mastra/server/handlers/workflows');
39
+ var legacyWorkflows = require('@mastra/server/handlers/legacyWorkflows');
39
40
 
40
41
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
41
42
 
@@ -265,14 +266,14 @@ var Response2 = class _Response {
265
266
  });
266
267
  Object.setPrototypeOf(Response2, GlobalResponse);
267
268
  Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
268
- function writeFromReadableStream(stream5, writable) {
269
- if (stream5.locked) {
269
+ function writeFromReadableStream(stream6, writable) {
270
+ if (stream6.locked) {
270
271
  throw new TypeError("ReadableStream is locked.");
271
272
  } else if (writable.destroyed) {
272
- stream5.cancel();
273
+ stream6.cancel();
273
274
  return;
274
275
  }
275
- const reader = stream5.getReader();
276
+ const reader = stream6.getReader();
276
277
  writable.on("close", cancel);
277
278
  writable.on("error", cancel);
278
279
  reader.read().then(flow, cancel);
@@ -507,18 +508,18 @@ var ENCODINGS = {
507
508
  gzip: ".gz"
508
509
  };
509
510
  var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
510
- var createStreamBody = (stream5) => {
511
+ var createStreamBody = (stream6) => {
511
512
  const body = new ReadableStream({
512
513
  start(controller) {
513
- stream5.on("data", (chunk) => {
514
+ stream6.on("data", (chunk) => {
514
515
  controller.enqueue(chunk);
515
516
  });
516
- stream5.on("end", () => {
517
+ stream6.on("end", () => {
517
518
  controller.close();
518
519
  });
519
520
  },
520
521
  cancel() {
521
- stream5.destroy();
522
+ stream6.destroy();
522
523
  }
523
524
  });
524
525
  return body;
@@ -614,10 +615,10 @@ var serveStatic = (options = { root: "" }) => {
614
615
  end = size - 1;
615
616
  }
616
617
  const chunksize = end - start + 1;
617
- const stream5 = fs.createReadStream(path, { start, end });
618
+ const stream6 = fs.createReadStream(path, { start, end });
618
619
  c2.header("Content-Length", chunksize.toString());
619
620
  c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
620
- return c2.body(createStreamBody(stream5), 206);
621
+ return c2.body(createStreamBody(stream6), 206);
621
622
  };
622
623
  };
623
624
  var RENDER_TYPE = {
@@ -913,15 +914,15 @@ async function getAgentExecutionHandler(c2) {
913
914
  if (body.method === "tasks/sendSubscribe") {
914
915
  return streaming.stream(
915
916
  c2,
916
- async (stream5) => {
917
+ async (stream6) => {
917
918
  try {
918
- stream5.onAbort(() => {
919
+ stream6.onAbort(() => {
919
920
  if (!result.locked) {
920
921
  return result.cancel();
921
922
  }
922
923
  });
923
924
  for await (const chunk of result) {
924
- await stream5.write(JSON.stringify(chunk) + "");
925
+ await stream6.write(JSON.stringify(chunk) + "");
925
926
  }
926
927
  } catch (err) {
927
928
  logger2.error("Error in tasks/sendSubscribe stream: " + err?.message);
@@ -959,6 +960,9 @@ var defaultAuthConfig = {
959
960
  };
960
961
 
961
962
  // src/server/handlers/auth/helpers.ts
963
+ var isDevPlaygroundRequest = (req) => {
964
+ return req.header("x-mastra-dev-playground") === "true" && (req.header("referer")?.includes("localhost") ?? false);
965
+ };
962
966
  var isProtectedPath = (path, method, authConfig) => {
963
967
  const protectedAccess = [...defaultAuthConfig.protected || [], ...authConfig.protected || []];
964
968
  return isAnyMatch(path, method, protectedAccess);
@@ -1048,6 +1052,9 @@ var authenticationMiddleware = async (c2, next) => {
1048
1052
  if (!authConfig) {
1049
1053
  return next();
1050
1054
  }
1055
+ if (isDevPlaygroundRequest(c2.req)) {
1056
+ return next();
1057
+ }
1051
1058
  if (!isProtectedPath(c2.req.path, c2.req.method, authConfig)) {
1052
1059
  return next();
1053
1060
  }
@@ -1087,6 +1094,9 @@ var authorizationMiddleware = async (c2, next) => {
1087
1094
  }
1088
1095
  const path = c2.req.path;
1089
1096
  const method = c2.req.method;
1097
+ if (isDevPlaygroundRequest(c2.req)) {
1098
+ return next();
1099
+ }
1090
1100
  if (!isProtectedPath(c2.req.path, c2.req.method, authConfig)) {
1091
1101
  return next();
1092
1102
  }
@@ -1137,7 +1147,7 @@ var authorizationMiddleware = async (c2, next) => {
1137
1147
  // src/server/handlers/client.ts
1138
1148
  var clients = /* @__PURE__ */ new Set();
1139
1149
  function handleClientsRefresh(c2) {
1140
- const stream5 = new ReadableStream({
1150
+ const stream6 = new ReadableStream({
1141
1151
  start(controller) {
1142
1152
  clients.add(controller);
1143
1153
  controller.enqueue("data: connected\n\n");
@@ -1146,7 +1156,7 @@ function handleClientsRefresh(c2) {
1146
1156
  });
1147
1157
  }
1148
1158
  });
1149
- return new Response(stream5, {
1159
+ return new Response(stream6, {
1150
1160
  headers: {
1151
1161
  "Content-Type": "text/event-stream",
1152
1162
  "Cache-Control": "no-cache",
@@ -1187,111 +1197,6 @@ function errorHandler(err, c2, isDev) {
1187
1197
  async function rootHandler(c2) {
1188
1198
  return c2.text("Hello to the Mastra API!");
1189
1199
  }
1190
- async function getAgentsHandler(c2) {
1191
- const serializedAgents = await agents.getAgentsHandler({
1192
- mastra: c2.get("mastra"),
1193
- runtimeContext: c2.get("runtimeContext")
1194
- });
1195
- return c2.json(serializedAgents);
1196
- }
1197
- async function getAgentByIdHandler(c2) {
1198
- const mastra = c2.get("mastra");
1199
- const agentId = c2.req.param("agentId");
1200
- const runtimeContext = c2.get("runtimeContext");
1201
- const isPlayground = c2.req.header("x-mastra-dev-playground") === "true";
1202
- const result = await agents.getAgentByIdHandler({
1203
- mastra,
1204
- agentId,
1205
- runtimeContext,
1206
- isPlayground
1207
- });
1208
- return c2.json(result);
1209
- }
1210
- async function getEvalsByAgentIdHandler(c2) {
1211
- const mastra = c2.get("mastra");
1212
- const agentId = c2.req.param("agentId");
1213
- const runtimeContext = c2.get("runtimeContext");
1214
- const result = await agents.getEvalsByAgentIdHandler({
1215
- mastra,
1216
- agentId,
1217
- runtimeContext
1218
- });
1219
- return c2.json(result);
1220
- }
1221
- async function getLiveEvalsByAgentIdHandler(c2) {
1222
- const mastra = c2.get("mastra");
1223
- const agentId = c2.req.param("agentId");
1224
- const runtimeContext = c2.get("runtimeContext");
1225
- const result = await agents.getLiveEvalsByAgentIdHandler({
1226
- mastra,
1227
- agentId,
1228
- runtimeContext
1229
- });
1230
- return c2.json(result);
1231
- }
1232
- async function generateHandler(c2) {
1233
- try {
1234
- const mastra = c2.get("mastra");
1235
- const agentId = c2.req.param("agentId");
1236
- const runtimeContext = c2.get("runtimeContext");
1237
- const body = await c2.req.json();
1238
- const result = await agents.generateHandler({
1239
- mastra,
1240
- agentId,
1241
- runtimeContext,
1242
- body,
1243
- abortSignal: c2.req.raw.signal
1244
- });
1245
- return c2.json(result);
1246
- } catch (error) {
1247
- return handleError(error, "Error generating from agent");
1248
- }
1249
- }
1250
- async function streamGenerateHandler(c2) {
1251
- try {
1252
- const mastra = c2.get("mastra");
1253
- const agentId = c2.req.param("agentId");
1254
- const runtimeContext = c2.get("runtimeContext");
1255
- const body = await c2.req.json();
1256
- const streamResponse = await agents.streamGenerateHandler({
1257
- mastra,
1258
- agentId,
1259
- runtimeContext,
1260
- body,
1261
- abortSignal: c2.req.raw.signal
1262
- });
1263
- return streamResponse;
1264
- } catch (error) {
1265
- return handleError(error, "Error streaming from agent");
1266
- }
1267
- }
1268
- async function setAgentInstructionsHandler(c2) {
1269
- try {
1270
- const isPlayground = c2.get("playground") === true;
1271
- if (!isPlayground) {
1272
- return c2.json({ error: "This API is only available in the playground environment" }, 403);
1273
- }
1274
- const agentId = c2.req.param("agentId");
1275
- const { instructions } = await c2.req.json();
1276
- if (!agentId || !instructions) {
1277
- return c2.json({ error: "Missing required fields" }, 400);
1278
- }
1279
- const mastra = c2.get("mastra");
1280
- const agent = mastra.getAgent(agentId);
1281
- if (!agent) {
1282
- return c2.json({ error: "Agent not found" }, 404);
1283
- }
1284
- agent.__updateInstructions(instructions);
1285
- return c2.json(
1286
- {
1287
- instructions
1288
- },
1289
- 200
1290
- );
1291
- } catch (error) {
1292
- return handleError(error, "Error setting agent instructions");
1293
- }
1294
- }
1295
1200
  async function generateSystemPromptHandler(c2) {
1296
1201
  try {
1297
1202
  const agentId = c2.req.param("agentId");
@@ -1465,6 +1370,151 @@ async function executeAgentToolHandler(c2) {
1465
1370
  return handleError(error, "Error executing tool");
1466
1371
  }
1467
1372
  }
1373
+ async function getAgentsHandler(c2) {
1374
+ const serializedAgents = await agents.getAgentsHandler({
1375
+ mastra: c2.get("mastra"),
1376
+ runtimeContext: c2.get("runtimeContext")
1377
+ });
1378
+ return c2.json(serializedAgents);
1379
+ }
1380
+ async function getAgentByIdHandler(c2) {
1381
+ const mastra = c2.get("mastra");
1382
+ const agentId = c2.req.param("agentId");
1383
+ const runtimeContext = c2.get("runtimeContext");
1384
+ const isPlayground = c2.req.header("x-mastra-dev-playground") === "true";
1385
+ const result = await agents.getAgentByIdHandler({
1386
+ mastra,
1387
+ agentId,
1388
+ runtimeContext,
1389
+ isPlayground
1390
+ });
1391
+ return c2.json(result);
1392
+ }
1393
+ async function getEvalsByAgentIdHandler(c2) {
1394
+ const mastra = c2.get("mastra");
1395
+ const agentId = c2.req.param("agentId");
1396
+ const runtimeContext = c2.get("runtimeContext");
1397
+ const result = await agents.getEvalsByAgentIdHandler({
1398
+ mastra,
1399
+ agentId,
1400
+ runtimeContext
1401
+ });
1402
+ return c2.json(result);
1403
+ }
1404
+ async function getLiveEvalsByAgentIdHandler(c2) {
1405
+ const mastra = c2.get("mastra");
1406
+ const agentId = c2.req.param("agentId");
1407
+ const runtimeContext = c2.get("runtimeContext");
1408
+ const result = await agents.getLiveEvalsByAgentIdHandler({
1409
+ mastra,
1410
+ agentId,
1411
+ runtimeContext
1412
+ });
1413
+ return c2.json(result);
1414
+ }
1415
+ async function generateHandler(c2) {
1416
+ try {
1417
+ const mastra = c2.get("mastra");
1418
+ const agentId = c2.req.param("agentId");
1419
+ const runtimeContext = c2.get("runtimeContext");
1420
+ const body = await c2.req.json();
1421
+ const result = await agents.generateHandler({
1422
+ mastra,
1423
+ agentId,
1424
+ runtimeContext,
1425
+ body,
1426
+ abortSignal: c2.req.raw.signal
1427
+ });
1428
+ return c2.json(result);
1429
+ } catch (error) {
1430
+ return handleError(error, "Error generating from agent");
1431
+ }
1432
+ }
1433
+ async function streamGenerateHandler(c2) {
1434
+ try {
1435
+ const mastra = c2.get("mastra");
1436
+ const agentId = c2.req.param("agentId");
1437
+ const runtimeContext = c2.get("runtimeContext");
1438
+ const body = await c2.req.json();
1439
+ const streamResponse = await agents.streamGenerateHandler({
1440
+ mastra,
1441
+ agentId,
1442
+ runtimeContext,
1443
+ body,
1444
+ abortSignal: c2.req.raw.signal
1445
+ });
1446
+ return streamResponse;
1447
+ } catch (error) {
1448
+ return handleError(error, "Error streaming from agent");
1449
+ }
1450
+ }
1451
+ async function streamVNextGenerateHandler(c2) {
1452
+ try {
1453
+ const mastra = c2.get("mastra");
1454
+ const agentId = c2.req.param("agentId");
1455
+ const runtimeContext = c2.get("runtimeContext");
1456
+ const body = await c2.req.json();
1457
+ const logger2 = mastra.getLogger();
1458
+ c2.header("Transfer-Encoding", "chunked");
1459
+ return streaming.stream(
1460
+ c2,
1461
+ async (stream6) => {
1462
+ try {
1463
+ const result = agents.streamVNextGenerateHandler({
1464
+ mastra,
1465
+ agentId,
1466
+ runtimeContext,
1467
+ body,
1468
+ abortSignal: c2.req.raw.signal
1469
+ });
1470
+ const reader = result.getReader();
1471
+ stream6.onAbort(() => {
1472
+ void reader.cancel("request aborted");
1473
+ });
1474
+ let chunkResult;
1475
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
1476
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
1477
+ }
1478
+ } catch (err) {
1479
+ logger2.error("Error in streamVNext generate: " + (err?.message ?? "Unknown error"));
1480
+ }
1481
+ await stream6.close();
1482
+ },
1483
+ async (err) => {
1484
+ logger2.error("Error in watch stream: " + err?.message);
1485
+ }
1486
+ );
1487
+ } catch (error) {
1488
+ return handleError(error, "Error streaming from agent");
1489
+ }
1490
+ }
1491
+ async function setAgentInstructionsHandler(c2) {
1492
+ try {
1493
+ const isPlayground = c2.get("playground") === true;
1494
+ if (!isPlayground) {
1495
+ return c2.json({ error: "This API is only available in the playground environment" }, 403);
1496
+ }
1497
+ const agentId = c2.req.param("agentId");
1498
+ const { instructions } = await c2.req.json();
1499
+ if (!agentId || !instructions) {
1500
+ return c2.json({ error: "Missing required fields" }, 400);
1501
+ }
1502
+ const mastra = c2.get("mastra");
1503
+ const agent = mastra.getAgent(agentId);
1504
+ if (!agent) {
1505
+ return c2.json({ error: "Agent not found" }, 404);
1506
+ }
1507
+ agent.__updateInstructions(instructions);
1508
+ return c2.json(
1509
+ {
1510
+ instructions
1511
+ },
1512
+ 200
1513
+ );
1514
+ } catch (error) {
1515
+ return handleError(error, "Error setting agent instructions");
1516
+ }
1517
+ }
1468
1518
  async function getSpeakersHandler(c2) {
1469
1519
  try {
1470
1520
  const mastra = c2.get("mastra");
@@ -1538,7 +1588,7 @@ async function listenHandler(c2) {
1538
1588
  }
1539
1589
  }
1540
1590
 
1541
- // src/server/handlers/routes/agents.ts
1591
+ // src/server/handlers/routes/agents/router.ts
1542
1592
  function agentsRouter(bodyLimitOptions) {
1543
1593
  const router = new hono.Hono();
1544
1594
  router.get(
@@ -1722,13 +1772,78 @@ function agentsRouter(bodyLimitOptions) {
1722
1772
  }),
1723
1773
  streamGenerateHandler
1724
1774
  );
1725
- router.get(
1726
- "/:agentId/speakers",
1727
- async (c2, next) => {
1728
- c2.header("Deprecation", "true");
1729
- c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/speakers instead"');
1730
- c2.header("Link", '</api/agents/:agentId/voice/speakers>; rel="successor-version"');
1731
- return next();
1775
+ router.post(
1776
+ "/:agentId/streamVNext",
1777
+ bodyLimit.bodyLimit(bodyLimitOptions),
1778
+ w({
1779
+ description: "Stream a response from an agent using the VNext streaming API",
1780
+ tags: ["agents"],
1781
+ parameters: [
1782
+ {
1783
+ name: "agentId",
1784
+ in: "path",
1785
+ required: true,
1786
+ schema: { type: "string" }
1787
+ }
1788
+ ],
1789
+ requestBody: {
1790
+ required: true,
1791
+ content: {
1792
+ "application/json": {
1793
+ schema: {
1794
+ type: "object",
1795
+ properties: {
1796
+ messages: {
1797
+ type: "array",
1798
+ items: { type: "object" }
1799
+ },
1800
+ runId: { type: "string" },
1801
+ output: { type: "object" },
1802
+ experimental_output: { type: "object" },
1803
+ instructions: { type: "string" },
1804
+ toolsets: { type: "object" },
1805
+ clientTools: { type: "object" },
1806
+ context: {
1807
+ type: "array",
1808
+ items: { type: "object" }
1809
+ },
1810
+ memory: {
1811
+ type: "object",
1812
+ properties: {
1813
+ threadId: { type: "string" },
1814
+ resourceId: { type: "string", description: "The resource ID for the conversation" }
1815
+ }
1816
+ },
1817
+ toolChoice: {
1818
+ oneOf: [
1819
+ { type: "string", enum: ["auto", "none", "required"] },
1820
+ { type: "object", properties: { type: { type: "string" }, toolName: { type: "string" } } }
1821
+ ]
1822
+ }
1823
+ },
1824
+ required: ["messages"]
1825
+ }
1826
+ }
1827
+ }
1828
+ },
1829
+ responses: {
1830
+ 200: {
1831
+ description: "Streamed response"
1832
+ },
1833
+ 404: {
1834
+ description: "Agent not found"
1835
+ }
1836
+ }
1837
+ }),
1838
+ streamVNextGenerateHandler
1839
+ );
1840
+ router.get(
1841
+ "/:agentId/speakers",
1842
+ async (c2, next) => {
1843
+ c2.header("Deprecation", "true");
1844
+ c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/speakers instead"');
1845
+ c2.header("Link", '</api/agents/:agentId/voice/speakers>; rel="successor-version"');
1846
+ return next();
1732
1847
  },
1733
1848
  w({
1734
1849
  description: "[DEPRECATED] Use /api/agents/:agentId/voice/speakers instead. Get available speakers for an agent",
@@ -2357,7 +2472,7 @@ async function getLogTransports(c2) {
2357
2472
  }
2358
2473
  }
2359
2474
 
2360
- // src/server/handlers/routes/logs.ts
2475
+ // src/server/handlers/routes/logs/router.ts
2361
2476
  function logsRouter() {
2362
2477
  const router = new hono.Hono();
2363
2478
  router.get(
@@ -4352,7 +4467,7 @@ function toFetchResponse(res) {
4352
4467
  return res.fetchResponse;
4353
4468
  }
4354
4469
 
4355
- // src/server/handlers/mcp.ts
4470
+ // src/server/handlers/routes/mcp/handlers.ts
4356
4471
  var getMastra = (c2) => c2.get("mastra");
4357
4472
  var getMcpServerMessageHandler = async (c2) => {
4358
4473
  const mastra = getMastra(c2);
@@ -4556,7 +4671,7 @@ var executeMcpServerToolHandler = async (c2) => {
4556
4671
  }
4557
4672
  };
4558
4673
 
4559
- // src/server/handlers/routes/mcp.ts
4674
+ // src/server/handlers/routes/mcp/router.ts
4560
4675
  function mcpRouter(bodyLimitOptions) {
4561
4676
  const router = new hono.Hono();
4562
4677
  router.post(
@@ -4965,6 +5080,20 @@ function mcpRouter(bodyLimitOptions) {
4965
5080
  );
4966
5081
  return router;
4967
5082
  }
5083
+
5084
+ // src/server/handlers/utils/query-parsers.ts
5085
+ function parseLimit(rawLimit) {
5086
+ if (rawLimit === void 0) {
5087
+ return void 0;
5088
+ }
5089
+ const n2 = Number(rawLimit);
5090
+ if (Number.isFinite(n2) && Number.isInteger(n2) && n2 > 0) {
5091
+ return n2;
5092
+ }
5093
+ return void 0;
5094
+ }
5095
+
5096
+ // src/server/handlers/routes/memory/handlers.ts
4968
5097
  async function getMemoryStatusHandler(c2) {
4969
5098
  try {
4970
5099
  const mastra = c2.get("mastra");
@@ -4980,6 +5109,21 @@ async function getMemoryStatusHandler(c2) {
4980
5109
  return handleError(error, "Error getting memory status");
4981
5110
  }
4982
5111
  }
5112
+ async function getMemoryConfigHandler(c2) {
5113
+ try {
5114
+ const mastra = c2.get("mastra");
5115
+ const agentId = c2.req.query("agentId");
5116
+ const networkId = c2.req.query("networkId");
5117
+ const result = await memory.getMemoryConfigHandler({
5118
+ mastra,
5119
+ agentId,
5120
+ networkId
5121
+ });
5122
+ return c2.json(result);
5123
+ } catch (error) {
5124
+ return handleError(error, "Error getting memory configuration");
5125
+ }
5126
+ }
4983
5127
  async function getThreadsHandler(c2) {
4984
5128
  try {
4985
5129
  const mastra = c2.get("mastra");
@@ -5090,14 +5234,7 @@ async function getMessagesHandler(c2) {
5090
5234
  const agentId = c2.req.query("agentId");
5091
5235
  const networkId = c2.req.query("networkId");
5092
5236
  const threadId = c2.req.param("threadId");
5093
- const rawLimit = c2.req.query("limit");
5094
- let limit = void 0;
5095
- if (rawLimit !== void 0) {
5096
- const n2 = Number(rawLimit);
5097
- if (Number.isFinite(n2) && Number.isInteger(n2) && n2 > 0) {
5098
- limit = n2;
5099
- }
5100
- }
5237
+ const limit = parseLimit(c2.req.query("limit"));
5101
5238
  const result = await memory.getMessagesHandler({
5102
5239
  mastra,
5103
5240
  agentId,
@@ -5110,6 +5247,32 @@ async function getMessagesHandler(c2) {
5110
5247
  return handleError(error, "Error getting messages");
5111
5248
  }
5112
5249
  }
5250
+ async function getMessagesPaginatedHandler(c2) {
5251
+ try {
5252
+ const mastra = c2.get("mastra");
5253
+ const threadId = c2.req.param("threadId");
5254
+ const resourceId = c2.req.query("resourceId");
5255
+ const format = c2.req.query("format") || "v1";
5256
+ const selectByArgs = c2.req.query("selectBy");
5257
+ let selectBy = {};
5258
+ if (selectByArgs) {
5259
+ try {
5260
+ selectBy = JSON.parse(selectByArgs);
5261
+ } catch (_error) {
5262
+ }
5263
+ }
5264
+ const result = await memory.getMessagesPaginatedHandler({
5265
+ mastra,
5266
+ threadId,
5267
+ resourceId,
5268
+ format,
5269
+ selectBy
5270
+ });
5271
+ return c2.json(result);
5272
+ } catch (error) {
5273
+ return handleError(error, "Error getting messages");
5274
+ }
5275
+ }
5113
5276
  async function updateWorkingMemoryHandler(c2) {
5114
5277
  try {
5115
5278
  const mastra = c2.get("mastra");
@@ -5148,8 +5311,35 @@ async function getWorkingMemoryHandler(c2) {
5148
5311
  return handleError(error, "Error getting working memory");
5149
5312
  }
5150
5313
  }
5314
+ async function searchMemoryHandler(c2) {
5315
+ try {
5316
+ const mastra = c2.get("mastra");
5317
+ const agentId = c2.req.query("agentId");
5318
+ const searchQuery = c2.req.query("searchQuery");
5319
+ const resourceId = c2.req.query("resourceId");
5320
+ const threadId = c2.req.query("threadId");
5321
+ const limit = parseLimit(c2.req.query("limit"));
5322
+ const memoryConfig = c2.req.query("memoryConfig") ? JSON.parse(c2.req.query("memoryConfig")) : void 0;
5323
+ const networkId = c2.req.query("networkId");
5324
+ const runtimeContext = c2.get("runtimeContext");
5325
+ const result = await memory.searchMemoryHandler({
5326
+ mastra,
5327
+ agentId,
5328
+ searchQuery,
5329
+ resourceId,
5330
+ threadId,
5331
+ limit,
5332
+ memoryConfig,
5333
+ networkId,
5334
+ runtimeContext
5335
+ });
5336
+ return c2.json(result);
5337
+ } catch (error) {
5338
+ return handleError(error, "Error searching memory");
5339
+ }
5340
+ }
5151
5341
 
5152
- // src/server/handlers/routes/memory.ts
5342
+ // src/server/handlers/routes/memory/router.ts
5153
5343
  function memoryRoutes(bodyLimitOptions) {
5154
5344
  const router = new hono.Hono();
5155
5345
  router.get(
@@ -5430,6 +5620,84 @@ function memoryRoutes(bodyLimitOptions) {
5430
5620
  }),
5431
5621
  getMemoryStatusHandler
5432
5622
  );
5623
+ router.get(
5624
+ "/config",
5625
+ w({
5626
+ description: "Get memory configuration",
5627
+ tags: ["memory"],
5628
+ parameters: [
5629
+ {
5630
+ name: "agentId",
5631
+ in: "query",
5632
+ required: true,
5633
+ schema: { type: "string" }
5634
+ }
5635
+ ],
5636
+ responses: {
5637
+ 200: {
5638
+ description: "Memory configuration",
5639
+ content: {
5640
+ "application/json": {
5641
+ schema: {
5642
+ type: "object",
5643
+ properties: {
5644
+ config: {
5645
+ type: "object",
5646
+ properties: {
5647
+ lastMessages: {
5648
+ oneOf: [{ type: "number" }, { type: "boolean" }]
5649
+ },
5650
+ semanticRecall: {
5651
+ oneOf: [
5652
+ { type: "boolean" },
5653
+ {
5654
+ type: "object",
5655
+ properties: {
5656
+ topK: { type: "number" },
5657
+ messageRange: {
5658
+ oneOf: [
5659
+ { type: "number" },
5660
+ {
5661
+ type: "object",
5662
+ properties: {
5663
+ before: { type: "number" },
5664
+ after: { type: "number" }
5665
+ }
5666
+ }
5667
+ ]
5668
+ },
5669
+ scope: { type: "string", enum: ["thread", "resource"] }
5670
+ }
5671
+ }
5672
+ ]
5673
+ },
5674
+ workingMemory: {
5675
+ type: "object",
5676
+ properties: {
5677
+ enabled: { type: "boolean" },
5678
+ scope: { type: "string", enum: ["thread", "resource"] },
5679
+ template: { type: "string" }
5680
+ }
5681
+ },
5682
+ threads: {
5683
+ type: "object",
5684
+ properties: {
5685
+ generateTitle: {
5686
+ oneOf: [{ type: "boolean" }, { type: "object" }]
5687
+ }
5688
+ }
5689
+ }
5690
+ }
5691
+ }
5692
+ }
5693
+ }
5694
+ }
5695
+ }
5696
+ }
5697
+ }
5698
+ }),
5699
+ getMemoryConfigHandler
5700
+ );
5433
5701
  router.get(
5434
5702
  "/threads",
5435
5703
  w({
@@ -5489,6 +5757,15 @@ function memoryRoutes(bodyLimitOptions) {
5489
5757
  );
5490
5758
  router.get(
5491
5759
  "/threads/:threadId/messages",
5760
+ async (c2, next) => {
5761
+ c2.header("Deprecation", "true");
5762
+ c2.header(
5763
+ "Warning",
5764
+ '299 - "This endpoint is deprecated, use /api/memory/threads/:threadId/messages/paginated instead"'
5765
+ );
5766
+ c2.header("Link", '</api/memory/threads/:threadId/messages/paginated>; rel="successor-version"');
5767
+ return next();
5768
+ },
5492
5769
  w({
5493
5770
  description: "Get messages for a thread",
5494
5771
  tags: ["memory"],
@@ -5522,46 +5799,152 @@ function memoryRoutes(bodyLimitOptions) {
5522
5799
  getMessagesHandler
5523
5800
  );
5524
5801
  router.get(
5525
- "/threads/:threadId/working-memory",
5802
+ "/threads/:threadId/messages/paginated",
5526
5803
  w({
5527
- description: "Get working memory for a thread",
5804
+ description: "Get paginated messages for a thread",
5528
5805
  tags: ["memory"],
5529
5806
  parameters: [
5530
5807
  {
5531
5808
  name: "threadId",
5532
5809
  in: "path",
5533
5810
  required: true,
5534
- schema: { type: "string" }
5811
+ description: "The unique identifier of the thread",
5812
+ schema: {
5813
+ type: "string"
5814
+ }
5535
5815
  },
5536
5816
  {
5537
- name: "agentId",
5817
+ name: "resourceId",
5818
+ in: "query",
5819
+ required: false,
5820
+ description: "Filter messages by resource ID",
5821
+ schema: {
5822
+ type: "string"
5823
+ }
5824
+ },
5825
+ {
5826
+ name: "format",
5827
+ in: "query",
5828
+ required: false,
5829
+ description: "Message format to return",
5830
+ schema: {
5831
+ type: "string",
5832
+ enum: ["v1", "v2"],
5833
+ default: "v1"
5834
+ }
5835
+ },
5836
+ {
5837
+ name: "selectBy",
5838
+ in: "query",
5839
+ required: false,
5840
+ description: "JSON string containing selection criteria for messages",
5841
+ schema: {
5842
+ type: "string",
5843
+ example: '{"pagination":{"page":0,"perPage":20,"dateRange":{"start":"2024-01-01T00:00:00Z","end":"2024-12-31T23:59:59Z"}},"include":[{"id":"msg-123","withPreviousMessages":5,"withNextMessages":3}]}'
5844
+ }
5845
+ }
5846
+ ],
5847
+ responses: {
5848
+ 200: {
5849
+ description: "List of messages"
5850
+ }
5851
+ }
5852
+ }),
5853
+ getMessagesPaginatedHandler
5854
+ );
5855
+ router.get(
5856
+ "/search",
5857
+ w({
5858
+ description: "Search messages in a thread",
5859
+ tags: ["memory"],
5860
+ parameters: [
5861
+ {
5862
+ name: "searchQuery",
5538
5863
  in: "query",
5539
5864
  required: true,
5540
- schema: { type: "string" }
5865
+ schema: { type: "string" },
5866
+ description: "The text to search for"
5541
5867
  },
5542
5868
  {
5543
5869
  name: "resourceId",
5544
5870
  in: "query",
5871
+ required: true,
5872
+ schema: { type: "string" },
5873
+ description: "The resource ID (user/org) to validate thread ownership"
5874
+ },
5875
+ {
5876
+ name: "threadId",
5877
+ in: "query",
5545
5878
  required: false,
5546
- schema: { type: "string" }
5879
+ schema: { type: "string" },
5880
+ description: "The thread ID to search within (optional - searches all threads if not provided)"
5881
+ },
5882
+ {
5883
+ name: "agentId",
5884
+ in: "query",
5885
+ required: true,
5886
+ schema: { type: "string" },
5887
+ description: "The agent ID"
5888
+ },
5889
+ {
5890
+ name: "limit",
5891
+ in: "query",
5892
+ required: false,
5893
+ schema: { type: "number" },
5894
+ description: "Maximum number of results to return (default: 20)"
5895
+ },
5896
+ {
5897
+ name: "memoryConfig",
5898
+ in: "query",
5899
+ required: false,
5900
+ schema: { type: "string" },
5901
+ description: 'JSON-encoded memory configuration (e.g., {"lastMessages": 0} for semantic-only search)'
5547
5902
  }
5548
5903
  ],
5549
5904
  responses: {
5550
5905
  200: {
5551
- description: "Working memory details"
5906
+ description: "Search results",
5907
+ content: {
5908
+ "application/json": {
5909
+ schema: {
5910
+ type: "object",
5911
+ properties: {
5912
+ results: {
5913
+ type: "array",
5914
+ items: {
5915
+ type: "object",
5916
+ properties: {
5917
+ id: { type: "string" },
5918
+ role: { type: "string" },
5919
+ content: { type: "string" },
5920
+ createdAt: { type: "string" }
5921
+ }
5922
+ }
5923
+ },
5924
+ count: { type: "number" },
5925
+ query: { type: "string" }
5926
+ }
5927
+ }
5928
+ }
5929
+ }
5930
+ },
5931
+ 400: {
5932
+ description: "Bad request"
5933
+ },
5934
+ 403: {
5935
+ description: "Thread does not belong to the specified resource"
5552
5936
  },
5553
5937
  404: {
5554
5938
  description: "Thread not found"
5555
5939
  }
5556
5940
  }
5557
5941
  }),
5558
- getWorkingMemoryHandler
5942
+ searchMemoryHandler
5559
5943
  );
5560
- router.post(
5944
+ router.get(
5561
5945
  "/threads/:threadId/working-memory",
5562
- bodyLimit.bodyLimit(bodyLimitOptions),
5563
5946
  w({
5564
- description: "Update working memory for a thread",
5947
+ description: "Get working memory for a thread",
5565
5948
  tags: ["memory"],
5566
5949
  parameters: [
5567
5950
  {
@@ -5575,14 +5958,51 @@ function memoryRoutes(bodyLimitOptions) {
5575
5958
  in: "query",
5576
5959
  required: true,
5577
5960
  schema: { type: "string" }
5961
+ },
5962
+ {
5963
+ name: "resourceId",
5964
+ in: "query",
5965
+ required: false,
5966
+ schema: { type: "string" }
5578
5967
  }
5579
5968
  ],
5580
- requestBody: {
5581
- required: true,
5582
- content: {
5583
- "application/json": {
5584
- schema: {
5585
- type: "object",
5969
+ responses: {
5970
+ 200: {
5971
+ description: "Working memory details"
5972
+ },
5973
+ 404: {
5974
+ description: "Thread not found"
5975
+ }
5976
+ }
5977
+ }),
5978
+ getWorkingMemoryHandler
5979
+ );
5980
+ router.post(
5981
+ "/threads/:threadId/working-memory",
5982
+ bodyLimit.bodyLimit(bodyLimitOptions),
5983
+ w({
5984
+ description: "Update working memory for a thread",
5985
+ tags: ["memory"],
5986
+ parameters: [
5987
+ {
5988
+ name: "threadId",
5989
+ in: "path",
5990
+ required: true,
5991
+ schema: { type: "string" }
5992
+ },
5993
+ {
5994
+ name: "agentId",
5995
+ in: "query",
5996
+ required: true,
5997
+ schema: { type: "string" }
5998
+ }
5999
+ ],
6000
+ requestBody: {
6001
+ required: true,
6002
+ content: {
6003
+ "application/json": {
6004
+ schema: {
6005
+ type: "object",
5586
6006
  properties: {
5587
6007
  workingMemory: { type: "string" },
5588
6008
  resourceId: { type: "string" }
@@ -5867,7 +6287,7 @@ async function streamGenerateVNextNetworkHandler(c2) {
5867
6287
  c2.header("Transfer-Encoding", "chunked");
5868
6288
  return streaming.stream(
5869
6289
  c2,
5870
- async (stream5) => {
6290
+ async (stream6) => {
5871
6291
  try {
5872
6292
  const result = await vNextNetwork.streamGenerateVNextNetworkHandler({
5873
6293
  mastra,
@@ -5876,12 +6296,12 @@ async function streamGenerateVNextNetworkHandler(c2) {
5876
6296
  body
5877
6297
  });
5878
6298
  const reader = result.stream.getReader();
5879
- stream5.onAbort(() => {
6299
+ stream6.onAbort(() => {
5880
6300
  void reader.cancel("request aborted");
5881
6301
  });
5882
6302
  let chunkResult;
5883
6303
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
5884
- await stream5.write(JSON.stringify(chunkResult.value) + "");
6304
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
5885
6305
  }
5886
6306
  } catch (err) {
5887
6307
  mastra.getLogger().error("Error in network stream: " + (err?.message ?? "Unknown error"));
@@ -5922,7 +6342,7 @@ async function loopStreamVNextNetworkHandler(c2) {
5922
6342
  c2.header("Transfer-Encoding", "chunked");
5923
6343
  return streaming.stream(
5924
6344
  c2,
5925
- async (stream5) => {
6345
+ async (stream6) => {
5926
6346
  try {
5927
6347
  const result = await vNextNetwork.loopStreamVNextNetworkHandler({
5928
6348
  mastra,
@@ -5931,12 +6351,12 @@ async function loopStreamVNextNetworkHandler(c2) {
5931
6351
  body
5932
6352
  });
5933
6353
  const reader = result.stream.getReader();
5934
- stream5.onAbort(() => {
6354
+ stream6.onAbort(() => {
5935
6355
  void reader.cancel("request aborted");
5936
6356
  });
5937
6357
  let chunkResult;
5938
6358
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
5939
- await stream5.write(JSON.stringify(chunkResult.value) + "");
6359
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
5940
6360
  }
5941
6361
  } catch (err) {
5942
6362
  mastra.getLogger().error("Error in network loop stream: " + (err?.message ?? "Unknown error"));
@@ -5951,7 +6371,7 @@ async function loopStreamVNextNetworkHandler(c2) {
5951
6371
  }
5952
6372
  }
5953
6373
 
5954
- // src/server/handlers/routes/networks.ts
6374
+ // src/server/handlers/routes/networks/router.ts
5955
6375
  function vNextNetworksRouter(bodyLimitOptions) {
5956
6376
  const router = new hono.Hono();
5957
6377
  router.get(
@@ -6326,6 +6746,288 @@ function networksRouter(bodyLimitOptions) {
6326
6746
  );
6327
6747
  return router;
6328
6748
  }
6749
+ async function getScorersHandler(c2) {
6750
+ try {
6751
+ const scorers = await scores.getScorersHandler({
6752
+ mastra: c2.get("mastra"),
6753
+ runtimeContext: c2.get("runtimeContext")
6754
+ });
6755
+ return c2.json(scorers);
6756
+ } catch (error) {
6757
+ return handleError(error, "Error getting scorers");
6758
+ }
6759
+ }
6760
+ async function getScorerHandler(c2) {
6761
+ const mastra = c2.get("mastra");
6762
+ const scorerId = c2.req.param("scorerId");
6763
+ const runtimeContext = c2.get("runtimeContext");
6764
+ const scorer = await scores.getScorerHandler({
6765
+ mastra,
6766
+ scorerId,
6767
+ runtimeContext
6768
+ });
6769
+ return c2.json(scorer);
6770
+ }
6771
+ async function getScoresByRunIdHandler(c2) {
6772
+ const mastra = c2.get("mastra");
6773
+ const runId = c2.req.param("runId");
6774
+ const page = parseInt(c2.req.query("page") || "0");
6775
+ const perPage = parseInt(c2.req.query("perPage") || "10");
6776
+ const pagination = { page, perPage };
6777
+ try {
6778
+ const scores$1 = await scores.getScoresByRunIdHandler({
6779
+ mastra,
6780
+ runId,
6781
+ pagination
6782
+ });
6783
+ return c2.json(scores$1);
6784
+ } catch (error) {
6785
+ return handleError(error, "Error getting scores by run id");
6786
+ }
6787
+ }
6788
+ async function getScoresByScorerIdHandler(c2) {
6789
+ const mastra = c2.get("mastra");
6790
+ const scorerId = c2.req.param("scorerId");
6791
+ const page = parseInt(c2.req.query("page") || "0");
6792
+ const perPage = parseInt(c2.req.query("perPage") || "10");
6793
+ const entityId = c2.req.query("entityId");
6794
+ const entityType = c2.req.query("entityType");
6795
+ const pagination = { page, perPage };
6796
+ try {
6797
+ const scores$1 = await scores.getScoresByScorerIdHandler({
6798
+ mastra,
6799
+ scorerId,
6800
+ pagination,
6801
+ entityId,
6802
+ entityType
6803
+ });
6804
+ return c2.json(scores$1);
6805
+ } catch (error) {
6806
+ return handleError(error, "Error getting scores by scorer id");
6807
+ }
6808
+ }
6809
+ async function getScoresByEntityIdHandler(c2) {
6810
+ const mastra = c2.get("mastra");
6811
+ const entityId = c2.req.param("entityId");
6812
+ const entityType = c2.req.param("entityType");
6813
+ const page = parseInt(c2.req.query("page") || "0");
6814
+ const perPage = parseInt(c2.req.query("perPage") || "10");
6815
+ const pagination = { page, perPage };
6816
+ try {
6817
+ const scores$1 = await scores.getScoresByEntityIdHandler({
6818
+ mastra,
6819
+ entityId,
6820
+ entityType,
6821
+ pagination
6822
+ });
6823
+ return c2.json(scores$1);
6824
+ } catch (error) {
6825
+ return handleError(error, "Error getting scores by entity id");
6826
+ }
6827
+ }
6828
+ async function saveScoreHandler(c2) {
6829
+ const mastra = c2.get("mastra");
6830
+ const score = await c2.req.json();
6831
+ try {
6832
+ const result = await scores.saveScoreHandler({
6833
+ mastra,
6834
+ score
6835
+ });
6836
+ return c2.json(result);
6837
+ } catch (error) {
6838
+ return handleError(error, "Error saving score");
6839
+ }
6840
+ }
6841
+
6842
+ // src/server/handlers/routes/scores/router.ts
6843
+ function scoresRouter(bodyLimitOptions) {
6844
+ const router = new hono.Hono();
6845
+ router.get(
6846
+ "/scorers",
6847
+ w({
6848
+ description: "Get all scorers",
6849
+ tags: ["scores"],
6850
+ responses: {
6851
+ 200: {
6852
+ description: "List of all scorers"
6853
+ }
6854
+ }
6855
+ }),
6856
+ getScorersHandler
6857
+ );
6858
+ router.get(
6859
+ "/scorers/:scorerId",
6860
+ w({
6861
+ description: "Get a scorer by ID",
6862
+ tags: ["scores"],
6863
+ responses: {
6864
+ 200: {
6865
+ description: "Scorer details"
6866
+ }
6867
+ }
6868
+ }),
6869
+ getScorerHandler
6870
+ );
6871
+ router.get(
6872
+ "/run/:runId",
6873
+ w({
6874
+ description: "Get scores by run ID",
6875
+ tags: ["scores"],
6876
+ parameters: [
6877
+ {
6878
+ name: "runId",
6879
+ in: "path",
6880
+ required: true,
6881
+ schema: { type: "string" }
6882
+ },
6883
+ {
6884
+ name: "page",
6885
+ in: "query",
6886
+ required: false,
6887
+ schema: { type: "number" },
6888
+ description: "Page number for pagination (default: 0)"
6889
+ },
6890
+ {
6891
+ name: "perPage",
6892
+ in: "query",
6893
+ required: false,
6894
+ schema: { type: "number" },
6895
+ description: "Number of items per page (default: 10)"
6896
+ }
6897
+ ],
6898
+ responses: {
6899
+ 200: {
6900
+ description: "Paginated list of scores for run ID"
6901
+ }
6902
+ }
6903
+ }),
6904
+ getScoresByRunIdHandler
6905
+ );
6906
+ router.get(
6907
+ "/scorer/:scorerId",
6908
+ w({
6909
+ description: "Get scores by scorer ID",
6910
+ tags: ["scores"],
6911
+ parameters: [
6912
+ {
6913
+ name: "scorerId",
6914
+ in: "path",
6915
+ required: true,
6916
+ schema: { type: "string" }
6917
+ },
6918
+ {
6919
+ name: "page",
6920
+ in: "query",
6921
+ required: false,
6922
+ schema: { type: "number" },
6923
+ description: "Page number for pagination (default: 0)"
6924
+ },
6925
+ {
6926
+ name: "perPage",
6927
+ in: "query",
6928
+ required: false,
6929
+ schema: { type: "number" },
6930
+ description: "Number of items per page (default: 10)"
6931
+ }
6932
+ ],
6933
+ responses: {
6934
+ 200: {
6935
+ description: "Paginated list of scores for run ID"
6936
+ }
6937
+ }
6938
+ }),
6939
+ getScoresByScorerIdHandler
6940
+ );
6941
+ router.get(
6942
+ "/entity/:entityType/:entityId",
6943
+ w({
6944
+ description: "Get scores by entity ID and type",
6945
+ tags: ["scores"],
6946
+ parameters: [
6947
+ {
6948
+ name: "entityType",
6949
+ in: "path",
6950
+ required: true,
6951
+ schema: { type: "string" },
6952
+ description: "Type of entity (e.g., agent, workflow, tool)"
6953
+ },
6954
+ {
6955
+ name: "entityId",
6956
+ in: "path",
6957
+ required: true,
6958
+ schema: { type: "string" },
6959
+ description: "ID of the entity"
6960
+ },
6961
+ {
6962
+ name: "page",
6963
+ in: "query",
6964
+ required: false,
6965
+ schema: { type: "number" },
6966
+ description: "Page number for pagination (default: 0)"
6967
+ },
6968
+ {
6969
+ name: "perPage",
6970
+ in: "query",
6971
+ required: false,
6972
+ schema: { type: "number" },
6973
+ description: "Number of items per page (default: 10)"
6974
+ }
6975
+ ],
6976
+ responses: {
6977
+ 200: {
6978
+ description: "Paginated list of scores for entity"
6979
+ }
6980
+ }
6981
+ }),
6982
+ getScoresByEntityIdHandler
6983
+ );
6984
+ router.post(
6985
+ "/",
6986
+ bodyLimit.bodyLimit(bodyLimitOptions),
6987
+ w({
6988
+ description: "Save a score",
6989
+ tags: ["scores"],
6990
+ requestBody: {
6991
+ required: true,
6992
+ content: {
6993
+ "application/json": {
6994
+ schema: {
6995
+ type: "object",
6996
+ properties: {
6997
+ id: { type: "string" },
6998
+ runId: { type: "string" },
6999
+ scorer: { type: "object" },
7000
+ result: { type: "object" },
7001
+ input: { type: "object" },
7002
+ output: { type: "object" },
7003
+ source: { type: "string" },
7004
+ entityType: { type: "string" },
7005
+ entity: { type: "object" },
7006
+ metadata: { type: "object" },
7007
+ additionalLLMContext: { type: "object" },
7008
+ runtimeContext: { type: "object" },
7009
+ resourceId: { type: "string" },
7010
+ threadId: { type: "string" },
7011
+ traceId: { type: "string" }
7012
+ },
7013
+ required: ["id", "runId", "scorer", "result", "input", "output", "source"]
7014
+ }
7015
+ }
7016
+ }
7017
+ },
7018
+ responses: {
7019
+ 200: {
7020
+ description: "Score saved successfully"
7021
+ },
7022
+ 400: {
7023
+ description: "Invalid score data"
7024
+ }
7025
+ }
7026
+ }),
7027
+ saveScoreHandler
7028
+ );
7029
+ return router;
7030
+ }
6329
7031
  async function getTelemetryHandler(c2) {
6330
7032
  try {
6331
7033
  const mastra = c2.get("mastra");
@@ -6362,7 +7064,7 @@ async function storeTelemetryHandler(c2) {
6362
7064
  }
6363
7065
  }
6364
7066
 
6365
- // src/server/handlers/routes/telemetry.ts
7067
+ // src/server/handlers/routes/telemetry/router.ts
6366
7068
  function telemetryRouter() {
6367
7069
  const router = new hono.Hono();
6368
7070
  router.get(
@@ -6579,7 +7281,7 @@ async function deleteIndex(c2) {
6579
7281
  }
6580
7282
  }
6581
7283
 
6582
- // src/server/handlers/routes/vector.ts
7284
+ // src/server/handlers/routes/vector/router.ts
6583
7285
  function vectorRouter(bodyLimitOptions) {
6584
7286
  const router = new hono.Hono();
6585
7287
  router.post(
@@ -6794,22 +7496,22 @@ function vectorRouter(bodyLimitOptions) {
6794
7496
  );
6795
7497
  return router;
6796
7498
  }
6797
- async function getLegacyWorkflowsHandler(c2) {
7499
+ async function getWorkflowsHandler(c2) {
6798
7500
  try {
6799
7501
  const mastra = c2.get("mastra");
6800
- const workflows = await legacyWorkflows.getLegacyWorkflowsHandler({
7502
+ const workflows$1 = await workflows.getWorkflowsHandler({
6801
7503
  mastra
6802
7504
  });
6803
- return c2.json(workflows);
7505
+ return c2.json(workflows$1);
6804
7506
  } catch (error) {
6805
7507
  return handleError(error, "Error getting workflows");
6806
7508
  }
6807
7509
  }
6808
- async function getLegacyWorkflowByIdHandler(c2) {
7510
+ async function getWorkflowByIdHandler(c2) {
6809
7511
  try {
6810
7512
  const mastra = c2.get("mastra");
6811
7513
  const workflowId = c2.req.param("workflowId");
6812
- const workflow = await legacyWorkflows.getLegacyWorkflowByIdHandler({
7514
+ const workflow = await workflows.getWorkflowByIdHandler({
6813
7515
  mastra,
6814
7516
  workflowId
6815
7517
  });
@@ -6818,31 +7520,12 @@ async function getLegacyWorkflowByIdHandler(c2) {
6818
7520
  return handleError(error, "Error getting workflow");
6819
7521
  }
6820
7522
  }
6821
- async function startAsyncLegacyWorkflowHandler(c2) {
6822
- try {
6823
- const mastra = c2.get("mastra");
6824
- const runtimeContext = c2.get("runtimeContext");
6825
- const workflowId = c2.req.param("workflowId");
6826
- const triggerData = await c2.req.json();
6827
- const runId = c2.req.query("runId");
6828
- const result = await legacyWorkflows.startAsyncLegacyWorkflowHandler({
6829
- mastra,
6830
- runtimeContext,
6831
- workflowId,
6832
- runId,
6833
- triggerData
6834
- });
6835
- return c2.json(result);
6836
- } catch (error) {
6837
- return handleError(error, "Error executing workflow");
6838
- }
6839
- }
6840
- async function createLegacyWorkflowRunHandler(c2) {
7523
+ async function createWorkflowRunHandler(c2) {
6841
7524
  try {
6842
7525
  const mastra = c2.get("mastra");
6843
7526
  const workflowId = c2.req.param("workflowId");
6844
7527
  const prevRunId = c2.req.query("runId");
6845
- const result = await legacyWorkflows.createLegacyWorkflowRunHandler({
7528
+ const result = await workflows.createWorkflowRunHandler({
6846
7529
  mastra,
6847
7530
  workflowId,
6848
7531
  runId: prevRunId
@@ -6852,178 +7535,19 @@ async function createLegacyWorkflowRunHandler(c2) {
6852
7535
  return handleError(e2, "Error creating run");
6853
7536
  }
6854
7537
  }
6855
- async function startLegacyWorkflowRunHandler(c2) {
7538
+ async function startAsyncWorkflowHandler(c2) {
6856
7539
  try {
6857
7540
  const mastra = c2.get("mastra");
6858
7541
  const runtimeContext = c2.get("runtimeContext");
6859
7542
  const workflowId = c2.req.param("workflowId");
6860
- const triggerData = await c2.req.json();
7543
+ const { inputData } = await c2.req.json();
6861
7544
  const runId = c2.req.query("runId");
6862
- await legacyWorkflows.startLegacyWorkflowRunHandler({
7545
+ const result = await workflows.startAsyncWorkflowHandler({
6863
7546
  mastra,
6864
7547
  runtimeContext,
6865
7548
  workflowId,
6866
7549
  runId,
6867
- triggerData
6868
- });
6869
- return c2.json({ message: "Workflow run started" });
6870
- } catch (e2) {
6871
- return handleError(e2, "Error starting workflow run");
6872
- }
6873
- }
6874
- function watchLegacyWorkflowHandler(c2) {
6875
- try {
6876
- const mastra = c2.get("mastra");
6877
- const logger2 = mastra.getLogger();
6878
- const workflowId = c2.req.param("workflowId");
6879
- const runId = c2.req.query("runId");
6880
- if (!runId) {
6881
- throw new httpException.HTTPException(400, { message: "runId required to watch workflow" });
6882
- }
6883
- return streaming.stream(
6884
- c2,
6885
- async (stream5) => {
6886
- try {
6887
- const result = await legacyWorkflows.watchLegacyWorkflowHandler({
6888
- mastra,
6889
- workflowId,
6890
- runId
6891
- });
6892
- stream5.onAbort(() => {
6893
- if (!result.locked) {
6894
- return result.cancel();
6895
- }
6896
- });
6897
- for await (const chunk of result) {
6898
- await stream5.write(chunk.toString() + "");
6899
- }
6900
- } catch (err) {
6901
- console.log(err);
6902
- }
6903
- },
6904
- async (err) => {
6905
- logger2.error("Error in watch stream: " + err?.message);
6906
- }
6907
- );
6908
- } catch (error) {
6909
- return handleError(error, "Error watching workflow");
6910
- }
6911
- }
6912
- async function resumeAsyncLegacyWorkflowHandler(c2) {
6913
- try {
6914
- const mastra = c2.get("mastra");
6915
- const runtimeContext = c2.get("runtimeContext");
6916
- const workflowId = c2.req.param("workflowId");
6917
- const runId = c2.req.query("runId");
6918
- const { stepId, context } = await c2.req.json();
6919
- if (!runId) {
6920
- throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
6921
- }
6922
- const result = await legacyWorkflows.resumeAsyncLegacyWorkflowHandler({
6923
- mastra,
6924
- runtimeContext,
6925
- workflowId,
6926
- runId,
6927
- body: { stepId, context }
6928
- });
6929
- return c2.json(result);
6930
- } catch (error) {
6931
- return handleError(error, "Error resuming workflow step");
6932
- }
6933
- }
6934
- async function resumeLegacyWorkflowHandler(c2) {
6935
- try {
6936
- const mastra = c2.get("mastra");
6937
- const runtimeContext = c2.get("runtimeContext");
6938
- const workflowId = c2.req.param("workflowId");
6939
- const runId = c2.req.query("runId");
6940
- const { stepId, context } = await c2.req.json();
6941
- if (!runId) {
6942
- throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
6943
- }
6944
- await legacyWorkflows.resumeLegacyWorkflowHandler({
6945
- mastra,
6946
- runtimeContext,
6947
- workflowId,
6948
- runId,
6949
- body: { stepId, context }
6950
- });
6951
- return c2.json({ message: "Workflow run resumed" });
6952
- } catch (error) {
6953
- return handleError(error, "Error resuming workflow");
6954
- }
6955
- }
6956
- async function getLegacyWorkflowRunsHandler(c2) {
6957
- try {
6958
- const mastra = c2.get("mastra");
6959
- const workflowId = c2.req.param("workflowId");
6960
- const { fromDate, toDate, limit, offset, resourceId } = c2.req.query();
6961
- const workflowRuns = await legacyWorkflows.getLegacyWorkflowRunsHandler({
6962
- mastra,
6963
- workflowId,
6964
- fromDate: fromDate ? new Date(fromDate) : void 0,
6965
- toDate: toDate ? new Date(toDate) : void 0,
6966
- limit: limit ? Number(limit) : void 0,
6967
- offset: offset ? Number(offset) : void 0,
6968
- resourceId
6969
- });
6970
- return c2.json(workflowRuns);
6971
- } catch (error) {
6972
- return handleError(error, "Error getting workflow runs");
6973
- }
6974
- }
6975
- async function getWorkflowsHandler(c2) {
6976
- try {
6977
- const mastra = c2.get("mastra");
6978
- const workflows$1 = await workflows.getWorkflowsHandler({
6979
- mastra
6980
- });
6981
- return c2.json(workflows$1);
6982
- } catch (error) {
6983
- return handleError(error, "Error getting workflows");
6984
- }
6985
- }
6986
- async function getWorkflowByIdHandler(c2) {
6987
- try {
6988
- const mastra = c2.get("mastra");
6989
- const workflowId = c2.req.param("workflowId");
6990
- const workflow = await workflows.getWorkflowByIdHandler({
6991
- mastra,
6992
- workflowId
6993
- });
6994
- return c2.json(workflow);
6995
- } catch (error) {
6996
- return handleError(error, "Error getting workflow");
6997
- }
6998
- }
6999
- async function createWorkflowRunHandler(c2) {
7000
- try {
7001
- const mastra = c2.get("mastra");
7002
- const workflowId = c2.req.param("workflowId");
7003
- const prevRunId = c2.req.query("runId");
7004
- const result = await workflows.createWorkflowRunHandler({
7005
- mastra,
7006
- workflowId,
7007
- runId: prevRunId
7008
- });
7009
- return c2.json(result);
7010
- } catch (e2) {
7011
- return handleError(e2, "Error creating run");
7012
- }
7013
- }
7014
- async function startAsyncWorkflowHandler(c2) {
7015
- try {
7016
- const mastra = c2.get("mastra");
7017
- const runtimeContext = c2.get("runtimeContext");
7018
- const workflowId = c2.req.param("workflowId");
7019
- const { inputData } = await c2.req.json();
7020
- const runId = c2.req.query("runId");
7021
- const result = await workflows.startAsyncWorkflowHandler({
7022
- mastra,
7023
- runtimeContext,
7024
- workflowId,
7025
- runId,
7026
- inputData
7550
+ inputData
7027
7551
  });
7028
7552
  return c2.json(result);
7029
7553
  } catch (error) {
@@ -7061,7 +7585,7 @@ function watchWorkflowHandler(c2) {
7061
7585
  c2.header("Transfer-Encoding", "chunked");
7062
7586
  return streaming.stream(
7063
7587
  c2,
7064
- async (stream5) => {
7588
+ async (stream6) => {
7065
7589
  try {
7066
7590
  const result = await workflows.watchWorkflowHandler({
7067
7591
  mastra,
@@ -7069,15 +7593,15 @@ function watchWorkflowHandler(c2) {
7069
7593
  runId
7070
7594
  });
7071
7595
  const reader = result.getReader();
7072
- stream5.onAbort(() => {
7596
+ stream6.onAbort(() => {
7073
7597
  void reader.cancel("request aborted");
7074
7598
  });
7075
7599
  let chunkResult;
7076
7600
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
7077
- await stream5.write(JSON.stringify(chunkResult.value) + "");
7601
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
7078
7602
  }
7079
7603
  } catch (err) {
7080
- mastra.getLogger().error("Error in watch stream: " + (err?.message ?? "Unknown error"));
7604
+ logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
7081
7605
  }
7082
7606
  },
7083
7607
  async (err) => {
@@ -7099,7 +7623,7 @@ async function streamWorkflowHandler(c2) {
7099
7623
  c2.header("Transfer-Encoding", "chunked");
7100
7624
  return streaming.stream(
7101
7625
  c2,
7102
- async (stream5) => {
7626
+ async (stream6) => {
7103
7627
  try {
7104
7628
  const result = await workflows.streamWorkflowHandler({
7105
7629
  mastra,
@@ -7109,16 +7633,17 @@ async function streamWorkflowHandler(c2) {
7109
7633
  runtimeContext
7110
7634
  });
7111
7635
  const reader = result.stream.getReader();
7112
- stream5.onAbort(() => {
7636
+ stream6.onAbort(() => {
7113
7637
  void reader.cancel("request aborted");
7114
7638
  });
7115
7639
  let chunkResult;
7116
7640
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
7117
- await stream5.write(JSON.stringify(chunkResult.value) + "");
7641
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
7118
7642
  }
7119
7643
  } catch (err) {
7120
- console.log(err);
7644
+ logger2.error("Error in workflow stream: " + (err?.message ?? "Unknown error"));
7121
7645
  }
7646
+ await stream6.close();
7122
7647
  },
7123
7648
  async (err) => {
7124
7649
  logger2.error("Error in workflow stream: " + err?.message);
@@ -7128,6 +7653,46 @@ async function streamWorkflowHandler(c2) {
7128
7653
  return handleError(error, "Error streaming workflow");
7129
7654
  }
7130
7655
  }
7656
+ async function streamVNextWorkflowHandler(c2) {
7657
+ try {
7658
+ const mastra = c2.get("mastra");
7659
+ const runtimeContext = c2.get("runtimeContext");
7660
+ const logger2 = mastra.getLogger();
7661
+ const workflowId = c2.req.param("workflowId");
7662
+ const { inputData } = await c2.req.json();
7663
+ const runId = c2.req.query("runId");
7664
+ c2.header("Transfer-Encoding", "chunked");
7665
+ return streaming.stream(
7666
+ c2,
7667
+ async (stream6) => {
7668
+ try {
7669
+ const result = await workflows.streamVNextWorkflowHandler({
7670
+ mastra,
7671
+ workflowId,
7672
+ runId,
7673
+ inputData,
7674
+ runtimeContext
7675
+ });
7676
+ const reader = result.getReader();
7677
+ stream6.onAbort(() => {
7678
+ void reader.cancel("request aborted");
7679
+ });
7680
+ let chunkResult;
7681
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
7682
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
7683
+ }
7684
+ } catch (err) {
7685
+ logger2.error("Error in workflow VNext stream: " + (err?.message ?? "Unknown error"));
7686
+ }
7687
+ },
7688
+ async (err) => {
7689
+ logger2.error("Error in workflow VNext stream: " + err?.message);
7690
+ }
7691
+ );
7692
+ } catch (error) {
7693
+ return handleError(error, "Error streaming workflow");
7694
+ }
7695
+ }
7131
7696
  async function resumeAsyncWorkflowHandler(c2) {
7132
7697
  try {
7133
7698
  const mastra = c2.get("mastra");
@@ -7254,8 +7819,186 @@ async function sendWorkflowRunEventHandler(c2) {
7254
7819
  return handleError(error, "Error sending workflow run event");
7255
7820
  }
7256
7821
  }
7822
+ async function getLegacyWorkflowsHandler(c2) {
7823
+ try {
7824
+ const mastra = c2.get("mastra");
7825
+ const workflows = await legacyWorkflows.getLegacyWorkflowsHandler({
7826
+ mastra
7827
+ });
7828
+ return c2.json(workflows);
7829
+ } catch (error) {
7830
+ return handleError(error, "Error getting workflows");
7831
+ }
7832
+ }
7833
+ async function getLegacyWorkflowByIdHandler(c2) {
7834
+ try {
7835
+ const mastra = c2.get("mastra");
7836
+ const workflowId = c2.req.param("workflowId");
7837
+ const workflow = await legacyWorkflows.getLegacyWorkflowByIdHandler({
7838
+ mastra,
7839
+ workflowId
7840
+ });
7841
+ return c2.json(workflow);
7842
+ } catch (error) {
7843
+ return handleError(error, "Error getting workflow");
7844
+ }
7845
+ }
7846
+ async function startAsyncLegacyWorkflowHandler(c2) {
7847
+ try {
7848
+ const mastra = c2.get("mastra");
7849
+ const runtimeContext = c2.get("runtimeContext");
7850
+ const workflowId = c2.req.param("workflowId");
7851
+ const triggerData = await c2.req.json();
7852
+ const runId = c2.req.query("runId");
7853
+ const result = await legacyWorkflows.startAsyncLegacyWorkflowHandler({
7854
+ mastra,
7855
+ runtimeContext,
7856
+ workflowId,
7857
+ runId,
7858
+ triggerData
7859
+ });
7860
+ return c2.json(result);
7861
+ } catch (error) {
7862
+ return handleError(error, "Error executing workflow");
7863
+ }
7864
+ }
7865
+ async function createLegacyWorkflowRunHandler(c2) {
7866
+ try {
7867
+ const mastra = c2.get("mastra");
7868
+ const workflowId = c2.req.param("workflowId");
7869
+ const prevRunId = c2.req.query("runId");
7870
+ const result = await legacyWorkflows.createLegacyWorkflowRunHandler({
7871
+ mastra,
7872
+ workflowId,
7873
+ runId: prevRunId
7874
+ });
7875
+ return c2.json(result);
7876
+ } catch (e2) {
7877
+ return handleError(e2, "Error creating run");
7878
+ }
7879
+ }
7880
+ async function startLegacyWorkflowRunHandler(c2) {
7881
+ try {
7882
+ const mastra = c2.get("mastra");
7883
+ const runtimeContext = c2.get("runtimeContext");
7884
+ const workflowId = c2.req.param("workflowId");
7885
+ const triggerData = await c2.req.json();
7886
+ const runId = c2.req.query("runId");
7887
+ await legacyWorkflows.startLegacyWorkflowRunHandler({
7888
+ mastra,
7889
+ runtimeContext,
7890
+ workflowId,
7891
+ runId,
7892
+ triggerData
7893
+ });
7894
+ return c2.json({ message: "Workflow run started" });
7895
+ } catch (e2) {
7896
+ return handleError(e2, "Error starting workflow run");
7897
+ }
7898
+ }
7899
+ function watchLegacyWorkflowHandler(c2) {
7900
+ try {
7901
+ const mastra = c2.get("mastra");
7902
+ const logger2 = mastra.getLogger();
7903
+ const workflowId = c2.req.param("workflowId");
7904
+ const runId = c2.req.query("runId");
7905
+ if (!runId) {
7906
+ throw new httpException.HTTPException(400, { message: "runId required to watch workflow" });
7907
+ }
7908
+ return streaming.stream(
7909
+ c2,
7910
+ async (stream6) => {
7911
+ try {
7912
+ const result = await legacyWorkflows.watchLegacyWorkflowHandler({
7913
+ mastra,
7914
+ workflowId,
7915
+ runId
7916
+ });
7917
+ stream6.onAbort(() => {
7918
+ if (!result.locked) {
7919
+ return result.cancel();
7920
+ }
7921
+ });
7922
+ for await (const chunk of result) {
7923
+ await stream6.write(chunk.toString() + "");
7924
+ }
7925
+ } catch (err) {
7926
+ console.log(err);
7927
+ }
7928
+ },
7929
+ async (err) => {
7930
+ logger2.error("Error in watch stream: " + err?.message);
7931
+ }
7932
+ );
7933
+ } catch (error) {
7934
+ return handleError(error, "Error watching workflow");
7935
+ }
7936
+ }
7937
+ async function resumeAsyncLegacyWorkflowHandler(c2) {
7938
+ try {
7939
+ const mastra = c2.get("mastra");
7940
+ const runtimeContext = c2.get("runtimeContext");
7941
+ const workflowId = c2.req.param("workflowId");
7942
+ const runId = c2.req.query("runId");
7943
+ const { stepId, context } = await c2.req.json();
7944
+ if (!runId) {
7945
+ throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
7946
+ }
7947
+ const result = await legacyWorkflows.resumeAsyncLegacyWorkflowHandler({
7948
+ mastra,
7949
+ runtimeContext,
7950
+ workflowId,
7951
+ runId,
7952
+ body: { stepId, context }
7953
+ });
7954
+ return c2.json(result);
7955
+ } catch (error) {
7956
+ return handleError(error, "Error resuming workflow step");
7957
+ }
7958
+ }
7959
+ async function resumeLegacyWorkflowHandler(c2) {
7960
+ try {
7961
+ const mastra = c2.get("mastra");
7962
+ const runtimeContext = c2.get("runtimeContext");
7963
+ const workflowId = c2.req.param("workflowId");
7964
+ const runId = c2.req.query("runId");
7965
+ const { stepId, context } = await c2.req.json();
7966
+ if (!runId) {
7967
+ throw new httpException.HTTPException(400, { message: "runId required to resume workflow" });
7968
+ }
7969
+ await legacyWorkflows.resumeLegacyWorkflowHandler({
7970
+ mastra,
7971
+ runtimeContext,
7972
+ workflowId,
7973
+ runId,
7974
+ body: { stepId, context }
7975
+ });
7976
+ return c2.json({ message: "Workflow run resumed" });
7977
+ } catch (error) {
7978
+ return handleError(error, "Error resuming workflow");
7979
+ }
7980
+ }
7981
+ async function getLegacyWorkflowRunsHandler(c2) {
7982
+ try {
7983
+ const mastra = c2.get("mastra");
7984
+ const workflowId = c2.req.param("workflowId");
7985
+ const { fromDate, toDate, limit, offset, resourceId } = c2.req.query();
7986
+ const workflowRuns = await legacyWorkflows.getLegacyWorkflowRunsHandler({
7987
+ mastra,
7988
+ workflowId,
7989
+ fromDate: fromDate ? new Date(fromDate) : void 0,
7990
+ toDate: toDate ? new Date(toDate) : void 0,
7991
+ limit: limit ? Number(limit) : void 0,
7992
+ offset: offset ? Number(offset) : void 0,
7993
+ resourceId
7994
+ });
7995
+ return c2.json(workflowRuns);
7996
+ } catch (error) {
7997
+ return handleError(error, "Error getting workflow runs");
7998
+ }
7999
+ }
7257
8000
 
7258
- // src/server/handlers/routes/workflows.ts
8001
+ // src/server/handlers/routes/workflows/router.ts
7259
8002
  function workflowsRouter(bodyLimitOptions) {
7260
8003
  const router = new hono.Hono();
7261
8004
  router.get(
@@ -7792,6 +8535,53 @@ function workflowsRouter(bodyLimitOptions) {
7792
8535
  }),
7793
8536
  streamWorkflowHandler
7794
8537
  );
8538
+ router.post(
8539
+ "/:workflowId/streamVNext",
8540
+ w({
8541
+ description: "Stream workflow in real-time using the VNext streaming API",
8542
+ parameters: [
8543
+ {
8544
+ name: "workflowId",
8545
+ in: "path",
8546
+ required: true,
8547
+ schema: { type: "string" }
8548
+ },
8549
+ {
8550
+ name: "runId",
8551
+ in: "query",
8552
+ required: false,
8553
+ schema: { type: "string" }
8554
+ }
8555
+ ],
8556
+ requestBody: {
8557
+ required: true,
8558
+ content: {
8559
+ "application/json": {
8560
+ schema: {
8561
+ type: "object",
8562
+ properties: {
8563
+ inputData: { type: "object" },
8564
+ runtimeContext: {
8565
+ type: "object",
8566
+ description: "Runtime context for the workflow execution"
8567
+ }
8568
+ }
8569
+ }
8570
+ }
8571
+ }
8572
+ },
8573
+ responses: {
8574
+ 200: {
8575
+ description: "workflow run started"
8576
+ },
8577
+ 404: {
8578
+ description: "workflow not found"
8579
+ }
8580
+ },
8581
+ tags: ["workflows"]
8582
+ }),
8583
+ streamVNextWorkflowHandler
8584
+ );
7795
8585
  router.post(
7796
8586
  "/:workflowId/create-run",
7797
8587
  bodyLimit.bodyLimit(bodyLimitOptions),
@@ -8115,13 +8905,9 @@ var html2 = `
8115
8905
  `;
8116
8906
 
8117
8907
  // src/server/index.ts
8118
- async function createHonoServer(mastra, options = {}) {
8119
- const app = new hono.Hono();
8120
- const server = mastra.getServer();
8121
- let tools$1 = {};
8908
+ function getToolExports(tools$1) {
8122
8909
  try {
8123
- const toolImports = (await import('#tools')).tools;
8124
- tools$1 = toolImports.reduce((acc, toolModule) => {
8910
+ return tools$1.reduce((acc, toolModule) => {
8125
8911
  Object.entries(toolModule).forEach(([key, tool]) => {
8126
8912
  if (tool instanceof tools.Tool) {
8127
8913
  acc[key] = tool;
@@ -8138,6 +8924,12 @@ ${err.stack.split("\n").slice(1).join("\n")}
8138
8924
  err
8139
8925
  );
8140
8926
  }
8927
+ }
8928
+ async function createHonoServer(mastra, options = {
8929
+ tools: {}
8930
+ }) {
8931
+ const app = new hono.Hono();
8932
+ const server = mastra.getServer();
8141
8933
  app.use("*", async function setTelemetryInfo(c2, next) {
8142
8934
  const requestId = c2.req.header("x-request-id") ?? crypto.randomUUID();
8143
8935
  const span = core.Telemetry.getActiveSpan();
@@ -8175,7 +8967,7 @@ ${err.stack.split("\n").slice(1).join("\n")}
8175
8967
  }
8176
8968
  c2.set("runtimeContext", runtimeContext$1);
8177
8969
  c2.set("mastra", mastra);
8178
- c2.set("tools", tools$1);
8970
+ c2.set("tools", options.tools);
8179
8971
  c2.set("playground", options.playground === true);
8180
8972
  c2.set("isDev", options.isDev === true);
8181
8973
  return next();
@@ -8409,7 +9201,8 @@ ${err.stack.split("\n").slice(1).join("\n")}
8409
9201
  app.route("/api/telemetry", telemetryRouter());
8410
9202
  app.route("/api/workflows", workflowsRouter(bodyLimitOptions));
8411
9203
  app.route("/api/logs", logsRouter());
8412
- app.route("/api/tools", toolsRouter(bodyLimitOptions, tools$1));
9204
+ app.route("/api/scores", scoresRouter(bodyLimitOptions));
9205
+ app.route("/api/tools", toolsRouter(bodyLimitOptions, options.tools));
8413
9206
  app.route("/api/vector", vectorRouter(bodyLimitOptions));
8414
9207
  if (options?.isDev || server?.build?.openAPIDocs || server?.build?.swaggerUI) {
8415
9208
  app.get(
@@ -8484,7 +9277,7 @@ ${err.stack.split("\n").slice(1).join("\n")}
8484
9277
  });
8485
9278
  return app;
8486
9279
  }
8487
- async function createNodeServer(mastra, options = {}) {
9280
+ async function createNodeServer(mastra, options = { tools: {} }) {
8488
9281
  const app = await createHonoServer(mastra, options);
8489
9282
  const serverOptions = mastra.getServer();
8490
9283
  const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
@@ -8516,3 +9309,4 @@ async function createNodeServer(mastra, options = {}) {
8516
9309
 
8517
9310
  exports.createHonoServer = createHonoServer;
8518
9311
  exports.createNodeServer = createNodeServer;
9312
+ exports.getToolExports = getToolExports;