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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -19,21 +19,22 @@ import { HTTPException } from 'hono/http-exception';
19
19
  import { getAgentCardByIdHandler as getAgentCardByIdHandler$1, getAgentExecutionHandler as getAgentExecutionHandler$1 } from '@mastra/server/handlers/a2a';
20
20
  import { stream } from 'hono/streaming';
21
21
  import { bodyLimit } from 'hono/body-limit';
22
- import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateHandler as generateHandler$1, streamGenerateHandler as streamGenerateHandler$1 } from '@mastra/server/handlers/agents';
23
22
  import { Agent } from '@mastra/core/agent';
24
23
  import { z } from 'zod';
25
24
  import { executeAgentToolHandler as executeAgentToolHandler$1, getToolsHandler as getToolsHandler$1, getToolByIdHandler as getToolByIdHandler$1, executeToolHandler as executeToolHandler$1 } from '@mastra/server/handlers/tools';
25
+ import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateHandler as generateHandler$1, streamGenerateHandler as streamGenerateHandler$1, streamVNextGenerateHandler as streamVNextGenerateHandler$1 } from '@mastra/server/handlers/agents';
26
26
  import { getSpeakersHandler as getSpeakersHandler$1, generateSpeechHandler, getListenerHandler as getListenerHandler$1, transcribeSpeechHandler } from '@mastra/server/handlers/voice';
27
27
  import { getLogsHandler as getLogsHandler$1, getLogTransports as getLogTransports$1, getLogsByRunIdHandler as getLogsByRunIdHandler$1 } from '@mastra/server/handlers/logs';
28
28
  import util from 'util';
29
29
  import { Buffer as Buffer$1 } from 'buffer';
30
- import { getMemoryStatusHandler as getMemoryStatusHandler$1, getThreadsHandler as getThreadsHandler$1, getThreadByIdHandler as getThreadByIdHandler$1, getMessagesHandler as getMessagesHandler$1, createThreadHandler as createThreadHandler$1, updateThreadHandler as updateThreadHandler$1, deleteThreadHandler as deleteThreadHandler$1, saveMessagesHandler as saveMessagesHandler$1, getWorkingMemoryHandler as getWorkingMemoryHandler$1, updateWorkingMemoryHandler as updateWorkingMemoryHandler$1 } from '@mastra/server/handlers/memory';
30
+ import { getMemoryStatusHandler as getMemoryStatusHandler$1, getThreadsHandler as getThreadsHandler$1, getThreadByIdHandler as getThreadByIdHandler$1, getMessagesHandler as getMessagesHandler$1, createThreadHandler as createThreadHandler$1, updateThreadHandler as updateThreadHandler$1, deleteThreadHandler as deleteThreadHandler$1, saveMessagesHandler as saveMessagesHandler$1, getMemoryConfigHandler as getMemoryConfigHandler$1, getMessagesPaginatedHandler as getMessagesPaginatedHandler$1, searchMemoryHandler as searchMemoryHandler$1, getWorkingMemoryHandler as getWorkingMemoryHandler$1, updateWorkingMemoryHandler as updateWorkingMemoryHandler$1 } from '@mastra/server/handlers/memory';
31
31
  import { getNetworksHandler as getNetworksHandler$1, getNetworkByIdHandler as getNetworkByIdHandler$1, generateHandler as generateHandler$2, streamGenerateHandler as streamGenerateHandler$2 } from '@mastra/server/handlers/network';
32
32
  import { getVNextNetworksHandler as getVNextNetworksHandler$1, getVNextNetworkByIdHandler as getVNextNetworkByIdHandler$1, generateVNextNetworkHandler as generateVNextNetworkHandler$1, loopVNextNetworkHandler as loopVNextNetworkHandler$1, loopStreamVNextNetworkHandler as loopStreamVNextNetworkHandler$1, streamGenerateVNextNetworkHandler as streamGenerateVNextNetworkHandler$1 } from '@mastra/server/handlers/vNextNetwork';
33
+ import { getScorersHandler as getScorersHandler$1, getScorerHandler as getScorerHandler$1, getScoresByRunIdHandler as getScoresByRunIdHandler$1, getScoresByScorerIdHandler as getScoresByScorerIdHandler$1, getScoresByEntityIdHandler as getScoresByEntityIdHandler$1, saveScoreHandler as saveScoreHandler$1 } from '@mastra/server/handlers/scores';
33
34
  import { getTelemetryHandler as getTelemetryHandler$1, storeTelemetryHandler as storeTelemetryHandler$1 } from '@mastra/server/handlers/telemetry';
34
35
  import { upsertVectors as upsertVectors$1, createIndex as createIndex$1, queryVectors as queryVectors$1, listIndexes as listIndexes$1, describeIndex as describeIndex$1, deleteIndex as deleteIndex$1 } from '@mastra/server/handlers/vector';
36
+ import { getWorkflowsHandler as getWorkflowsHandler$1, getWorkflowByIdHandler as getWorkflowByIdHandler$1, getWorkflowRunsHandler as getWorkflowRunsHandler$1, getWorkflowRunExecutionResultHandler as getWorkflowRunExecutionResultHandler$1, getWorkflowRunByIdHandler as getWorkflowRunByIdHandler$1, resumeWorkflowHandler as resumeWorkflowHandler$1, resumeAsyncWorkflowHandler as resumeAsyncWorkflowHandler$1, streamWorkflowHandler as streamWorkflowHandler$1, streamVNextWorkflowHandler as streamVNextWorkflowHandler$1, createWorkflowRunHandler as createWorkflowRunHandler$1, startAsyncWorkflowHandler as startAsyncWorkflowHandler$1, startWorkflowRunHandler as startWorkflowRunHandler$1, watchWorkflowHandler as watchWorkflowHandler$1, cancelWorkflowRunHandler as cancelWorkflowRunHandler$1, sendWorkflowRunEventHandler as sendWorkflowRunEventHandler$1 } from '@mastra/server/handlers/workflows';
35
37
  import { getLegacyWorkflowsHandler as getLegacyWorkflowsHandler$1, getLegacyWorkflowByIdHandler as getLegacyWorkflowByIdHandler$1, getLegacyWorkflowRunsHandler as getLegacyWorkflowRunsHandler$1, resumeLegacyWorkflowHandler as resumeLegacyWorkflowHandler$1, resumeAsyncLegacyWorkflowHandler as resumeAsyncLegacyWorkflowHandler$1, createLegacyWorkflowRunHandler as createLegacyWorkflowRunHandler$1, startAsyncLegacyWorkflowHandler as startAsyncLegacyWorkflowHandler$1, startLegacyWorkflowRunHandler as startLegacyWorkflowRunHandler$1, watchLegacyWorkflowHandler as watchLegacyWorkflowHandler$1 } from '@mastra/server/handlers/legacyWorkflows';
36
- import { getWorkflowsHandler as getWorkflowsHandler$1, getWorkflowByIdHandler as getWorkflowByIdHandler$1, getWorkflowRunsHandler as getWorkflowRunsHandler$1, getWorkflowRunExecutionResultHandler as getWorkflowRunExecutionResultHandler$1, getWorkflowRunByIdHandler as getWorkflowRunByIdHandler$1, resumeWorkflowHandler as resumeWorkflowHandler$1, resumeAsyncWorkflowHandler as resumeAsyncWorkflowHandler$1, streamWorkflowHandler as streamWorkflowHandler$1, createWorkflowRunHandler as createWorkflowRunHandler$1, startAsyncWorkflowHandler as startAsyncWorkflowHandler$1, startWorkflowRunHandler as startWorkflowRunHandler$1, watchWorkflowHandler as watchWorkflowHandler$1, cancelWorkflowRunHandler as cancelWorkflowRunHandler$1, sendWorkflowRunEventHandler as sendWorkflowRunEventHandler$1 } from '@mastra/server/handlers/workflows';
37
38
 
38
39
  // src/server/index.ts
39
40
  var RequestError = class extends Error {
@@ -258,14 +259,14 @@ var Response2 = class _Response {
258
259
  });
259
260
  Object.setPrototypeOf(Response2, GlobalResponse);
260
261
  Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
261
- function writeFromReadableStream(stream5, writable) {
262
- if (stream5.locked) {
262
+ function writeFromReadableStream(stream6, writable) {
263
+ if (stream6.locked) {
263
264
  throw new TypeError("ReadableStream is locked.");
264
265
  } else if (writable.destroyed) {
265
- stream5.cancel();
266
+ stream6.cancel();
266
267
  return;
267
268
  }
268
- const reader = stream5.getReader();
269
+ const reader = stream6.getReader();
269
270
  writable.on("close", cancel);
270
271
  writable.on("error", cancel);
271
272
  reader.read().then(flow, cancel);
@@ -500,18 +501,18 @@ var ENCODINGS = {
500
501
  gzip: ".gz"
501
502
  };
502
503
  var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
503
- var createStreamBody = (stream5) => {
504
+ var createStreamBody = (stream6) => {
504
505
  const body = new ReadableStream({
505
506
  start(controller) {
506
- stream5.on("data", (chunk) => {
507
+ stream6.on("data", (chunk) => {
507
508
  controller.enqueue(chunk);
508
509
  });
509
- stream5.on("end", () => {
510
+ stream6.on("end", () => {
510
511
  controller.close();
511
512
  });
512
513
  },
513
514
  cancel() {
514
- stream5.destroy();
515
+ stream6.destroy();
515
516
  }
516
517
  });
517
518
  return body;
@@ -607,10 +608,10 @@ var serveStatic = (options = { root: "" }) => {
607
608
  end = size - 1;
608
609
  }
609
610
  const chunksize = end - start + 1;
610
- const stream5 = createReadStream(path, { start, end });
611
+ const stream6 = createReadStream(path, { start, end });
611
612
  c2.header("Content-Length", chunksize.toString());
612
613
  c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
613
- return c2.body(createStreamBody(stream5), 206);
614
+ return c2.body(createStreamBody(stream6), 206);
614
615
  };
615
616
  };
616
617
  var RENDER_TYPE = {
@@ -906,15 +907,15 @@ async function getAgentExecutionHandler(c2) {
906
907
  if (body.method === "tasks/sendSubscribe") {
907
908
  return stream(
908
909
  c2,
909
- async (stream5) => {
910
+ async (stream6) => {
910
911
  try {
911
- stream5.onAbort(() => {
912
+ stream6.onAbort(() => {
912
913
  if (!result.locked) {
913
914
  return result.cancel();
914
915
  }
915
916
  });
916
917
  for await (const chunk of result) {
917
- await stream5.write(JSON.stringify(chunk) + "");
918
+ await stream6.write(JSON.stringify(chunk) + "");
918
919
  }
919
920
  } catch (err) {
920
921
  logger2.error("Error in tasks/sendSubscribe stream: " + err?.message);
@@ -952,6 +953,9 @@ var defaultAuthConfig = {
952
953
  };
953
954
 
954
955
  // src/server/handlers/auth/helpers.ts
956
+ var isDevPlaygroundRequest = (req) => {
957
+ return req.header("x-mastra-dev-playground") === "true" && (req.header("referer")?.includes("localhost") ?? false);
958
+ };
955
959
  var isProtectedPath = (path, method, authConfig) => {
956
960
  const protectedAccess = [...defaultAuthConfig.protected || [], ...authConfig.protected || []];
957
961
  return isAnyMatch(path, method, protectedAccess);
@@ -1041,6 +1045,9 @@ var authenticationMiddleware = async (c2, next) => {
1041
1045
  if (!authConfig) {
1042
1046
  return next();
1043
1047
  }
1048
+ if (isDevPlaygroundRequest(c2.req)) {
1049
+ return next();
1050
+ }
1044
1051
  if (!isProtectedPath(c2.req.path, c2.req.method, authConfig)) {
1045
1052
  return next();
1046
1053
  }
@@ -1080,6 +1087,9 @@ var authorizationMiddleware = async (c2, next) => {
1080
1087
  }
1081
1088
  const path = c2.req.path;
1082
1089
  const method = c2.req.method;
1090
+ if (isDevPlaygroundRequest(c2.req)) {
1091
+ return next();
1092
+ }
1083
1093
  if (!isProtectedPath(c2.req.path, c2.req.method, authConfig)) {
1084
1094
  return next();
1085
1095
  }
@@ -1130,7 +1140,7 @@ var authorizationMiddleware = async (c2, next) => {
1130
1140
  // src/server/handlers/client.ts
1131
1141
  var clients = /* @__PURE__ */ new Set();
1132
1142
  function handleClientsRefresh(c2) {
1133
- const stream5 = new ReadableStream({
1143
+ const stream6 = new ReadableStream({
1134
1144
  start(controller) {
1135
1145
  clients.add(controller);
1136
1146
  controller.enqueue("data: connected\n\n");
@@ -1139,7 +1149,7 @@ function handleClientsRefresh(c2) {
1139
1149
  });
1140
1150
  }
1141
1151
  });
1142
- return new Response(stream5, {
1152
+ return new Response(stream6, {
1143
1153
  headers: {
1144
1154
  "Content-Type": "text/event-stream",
1145
1155
  "Cache-Control": "no-cache",
@@ -1180,111 +1190,6 @@ function errorHandler(err, c2, isDev) {
1180
1190
  async function rootHandler(c2) {
1181
1191
  return c2.text("Hello to the Mastra API!");
1182
1192
  }
1183
- async function getAgentsHandler(c2) {
1184
- const serializedAgents = await getAgentsHandler$1({
1185
- mastra: c2.get("mastra"),
1186
- runtimeContext: c2.get("runtimeContext")
1187
- });
1188
- return c2.json(serializedAgents);
1189
- }
1190
- async function getAgentByIdHandler(c2) {
1191
- const mastra = c2.get("mastra");
1192
- const agentId = c2.req.param("agentId");
1193
- const runtimeContext = c2.get("runtimeContext");
1194
- const isPlayground = c2.req.header("x-mastra-dev-playground") === "true";
1195
- const result = await getAgentByIdHandler$1({
1196
- mastra,
1197
- agentId,
1198
- runtimeContext,
1199
- isPlayground
1200
- });
1201
- return c2.json(result);
1202
- }
1203
- async function getEvalsByAgentIdHandler(c2) {
1204
- const mastra = c2.get("mastra");
1205
- const agentId = c2.req.param("agentId");
1206
- const runtimeContext = c2.get("runtimeContext");
1207
- const result = await getEvalsByAgentIdHandler$1({
1208
- mastra,
1209
- agentId,
1210
- runtimeContext
1211
- });
1212
- return c2.json(result);
1213
- }
1214
- async function getLiveEvalsByAgentIdHandler(c2) {
1215
- const mastra = c2.get("mastra");
1216
- const agentId = c2.req.param("agentId");
1217
- const runtimeContext = c2.get("runtimeContext");
1218
- const result = await getLiveEvalsByAgentIdHandler$1({
1219
- mastra,
1220
- agentId,
1221
- runtimeContext
1222
- });
1223
- return c2.json(result);
1224
- }
1225
- async function generateHandler(c2) {
1226
- try {
1227
- const mastra = c2.get("mastra");
1228
- const agentId = c2.req.param("agentId");
1229
- const runtimeContext = c2.get("runtimeContext");
1230
- const body = await c2.req.json();
1231
- const result = await generateHandler$1({
1232
- mastra,
1233
- agentId,
1234
- runtimeContext,
1235
- body,
1236
- abortSignal: c2.req.raw.signal
1237
- });
1238
- return c2.json(result);
1239
- } catch (error) {
1240
- return handleError(error, "Error generating from agent");
1241
- }
1242
- }
1243
- async function streamGenerateHandler(c2) {
1244
- try {
1245
- const mastra = c2.get("mastra");
1246
- const agentId = c2.req.param("agentId");
1247
- const runtimeContext = c2.get("runtimeContext");
1248
- const body = await c2.req.json();
1249
- const streamResponse = await streamGenerateHandler$1({
1250
- mastra,
1251
- agentId,
1252
- runtimeContext,
1253
- body,
1254
- abortSignal: c2.req.raw.signal
1255
- });
1256
- return streamResponse;
1257
- } catch (error) {
1258
- return handleError(error, "Error streaming from agent");
1259
- }
1260
- }
1261
- async function setAgentInstructionsHandler(c2) {
1262
- try {
1263
- const isPlayground = c2.get("playground") === true;
1264
- if (!isPlayground) {
1265
- return c2.json({ error: "This API is only available in the playground environment" }, 403);
1266
- }
1267
- const agentId = c2.req.param("agentId");
1268
- const { instructions } = await c2.req.json();
1269
- if (!agentId || !instructions) {
1270
- return c2.json({ error: "Missing required fields" }, 400);
1271
- }
1272
- const mastra = c2.get("mastra");
1273
- const agent = mastra.getAgent(agentId);
1274
- if (!agent) {
1275
- return c2.json({ error: "Agent not found" }, 404);
1276
- }
1277
- agent.__updateInstructions(instructions);
1278
- return c2.json(
1279
- {
1280
- instructions
1281
- },
1282
- 200
1283
- );
1284
- } catch (error) {
1285
- return handleError(error, "Error setting agent instructions");
1286
- }
1287
- }
1288
1193
  async function generateSystemPromptHandler(c2) {
1289
1194
  try {
1290
1195
  const agentId = c2.req.param("agentId");
@@ -1458,6 +1363,151 @@ async function executeAgentToolHandler(c2) {
1458
1363
  return handleError(error, "Error executing tool");
1459
1364
  }
1460
1365
  }
1366
+ async function getAgentsHandler(c2) {
1367
+ const serializedAgents = await getAgentsHandler$1({
1368
+ mastra: c2.get("mastra"),
1369
+ runtimeContext: c2.get("runtimeContext")
1370
+ });
1371
+ return c2.json(serializedAgents);
1372
+ }
1373
+ async function getAgentByIdHandler(c2) {
1374
+ const mastra = c2.get("mastra");
1375
+ const agentId = c2.req.param("agentId");
1376
+ const runtimeContext = c2.get("runtimeContext");
1377
+ const isPlayground = c2.req.header("x-mastra-dev-playground") === "true";
1378
+ const result = await getAgentByIdHandler$1({
1379
+ mastra,
1380
+ agentId,
1381
+ runtimeContext,
1382
+ isPlayground
1383
+ });
1384
+ return c2.json(result);
1385
+ }
1386
+ async function getEvalsByAgentIdHandler(c2) {
1387
+ const mastra = c2.get("mastra");
1388
+ const agentId = c2.req.param("agentId");
1389
+ const runtimeContext = c2.get("runtimeContext");
1390
+ const result = await getEvalsByAgentIdHandler$1({
1391
+ mastra,
1392
+ agentId,
1393
+ runtimeContext
1394
+ });
1395
+ return c2.json(result);
1396
+ }
1397
+ async function getLiveEvalsByAgentIdHandler(c2) {
1398
+ const mastra = c2.get("mastra");
1399
+ const agentId = c2.req.param("agentId");
1400
+ const runtimeContext = c2.get("runtimeContext");
1401
+ const result = await getLiveEvalsByAgentIdHandler$1({
1402
+ mastra,
1403
+ agentId,
1404
+ runtimeContext
1405
+ });
1406
+ return c2.json(result);
1407
+ }
1408
+ async function generateHandler(c2) {
1409
+ try {
1410
+ const mastra = c2.get("mastra");
1411
+ const agentId = c2.req.param("agentId");
1412
+ const runtimeContext = c2.get("runtimeContext");
1413
+ const body = await c2.req.json();
1414
+ const result = await generateHandler$1({
1415
+ mastra,
1416
+ agentId,
1417
+ runtimeContext,
1418
+ body,
1419
+ abortSignal: c2.req.raw.signal
1420
+ });
1421
+ return c2.json(result);
1422
+ } catch (error) {
1423
+ return handleError(error, "Error generating from agent");
1424
+ }
1425
+ }
1426
+ async function streamGenerateHandler(c2) {
1427
+ try {
1428
+ const mastra = c2.get("mastra");
1429
+ const agentId = c2.req.param("agentId");
1430
+ const runtimeContext = c2.get("runtimeContext");
1431
+ const body = await c2.req.json();
1432
+ const streamResponse = await streamGenerateHandler$1({
1433
+ mastra,
1434
+ agentId,
1435
+ runtimeContext,
1436
+ body,
1437
+ abortSignal: c2.req.raw.signal
1438
+ });
1439
+ return streamResponse;
1440
+ } catch (error) {
1441
+ return handleError(error, "Error streaming from agent");
1442
+ }
1443
+ }
1444
+ async function streamVNextGenerateHandler(c2) {
1445
+ try {
1446
+ const mastra = c2.get("mastra");
1447
+ const agentId = c2.req.param("agentId");
1448
+ const runtimeContext = c2.get("runtimeContext");
1449
+ const body = await c2.req.json();
1450
+ const logger2 = mastra.getLogger();
1451
+ c2.header("Transfer-Encoding", "chunked");
1452
+ return stream(
1453
+ c2,
1454
+ async (stream6) => {
1455
+ try {
1456
+ const result = streamVNextGenerateHandler$1({
1457
+ mastra,
1458
+ agentId,
1459
+ runtimeContext,
1460
+ body,
1461
+ abortSignal: c2.req.raw.signal
1462
+ });
1463
+ const reader = result.getReader();
1464
+ stream6.onAbort(() => {
1465
+ void reader.cancel("request aborted");
1466
+ });
1467
+ let chunkResult;
1468
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
1469
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
1470
+ }
1471
+ } catch (err) {
1472
+ logger2.error("Error in streamVNext generate: " + (err?.message ?? "Unknown error"));
1473
+ }
1474
+ await stream6.close();
1475
+ },
1476
+ async (err) => {
1477
+ logger2.error("Error in watch stream: " + err?.message);
1478
+ }
1479
+ );
1480
+ } catch (error) {
1481
+ return handleError(error, "Error streaming from agent");
1482
+ }
1483
+ }
1484
+ async function setAgentInstructionsHandler(c2) {
1485
+ try {
1486
+ const isPlayground = c2.get("playground") === true;
1487
+ if (!isPlayground) {
1488
+ return c2.json({ error: "This API is only available in the playground environment" }, 403);
1489
+ }
1490
+ const agentId = c2.req.param("agentId");
1491
+ const { instructions } = await c2.req.json();
1492
+ if (!agentId || !instructions) {
1493
+ return c2.json({ error: "Missing required fields" }, 400);
1494
+ }
1495
+ const mastra = c2.get("mastra");
1496
+ const agent = mastra.getAgent(agentId);
1497
+ if (!agent) {
1498
+ return c2.json({ error: "Agent not found" }, 404);
1499
+ }
1500
+ agent.__updateInstructions(instructions);
1501
+ return c2.json(
1502
+ {
1503
+ instructions
1504
+ },
1505
+ 200
1506
+ );
1507
+ } catch (error) {
1508
+ return handleError(error, "Error setting agent instructions");
1509
+ }
1510
+ }
1461
1511
  async function getSpeakersHandler(c2) {
1462
1512
  try {
1463
1513
  const mastra = c2.get("mastra");
@@ -1531,7 +1581,7 @@ async function listenHandler(c2) {
1531
1581
  }
1532
1582
  }
1533
1583
 
1534
- // src/server/handlers/routes/agents.ts
1584
+ // src/server/handlers/routes/agents/router.ts
1535
1585
  function agentsRouter(bodyLimitOptions) {
1536
1586
  const router = new Hono();
1537
1587
  router.get(
@@ -1715,16 +1765,81 @@ function agentsRouter(bodyLimitOptions) {
1715
1765
  }),
1716
1766
  streamGenerateHandler
1717
1767
  );
1718
- router.get(
1719
- "/:agentId/speakers",
1720
- async (c2, next) => {
1721
- c2.header("Deprecation", "true");
1722
- c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/speakers instead"');
1723
- c2.header("Link", '</api/agents/:agentId/voice/speakers>; rel="successor-version"');
1724
- return next();
1725
- },
1768
+ router.post(
1769
+ "/:agentId/streamVNext",
1770
+ bodyLimit(bodyLimitOptions),
1726
1771
  w({
1727
- description: "[DEPRECATED] Use /api/agents/:agentId/voice/speakers instead. Get available speakers for an agent",
1772
+ description: "Stream a response from an agent using the VNext streaming API",
1773
+ tags: ["agents"],
1774
+ parameters: [
1775
+ {
1776
+ name: "agentId",
1777
+ in: "path",
1778
+ required: true,
1779
+ schema: { type: "string" }
1780
+ }
1781
+ ],
1782
+ requestBody: {
1783
+ required: true,
1784
+ content: {
1785
+ "application/json": {
1786
+ schema: {
1787
+ type: "object",
1788
+ properties: {
1789
+ messages: {
1790
+ type: "array",
1791
+ items: { type: "object" }
1792
+ },
1793
+ runId: { type: "string" },
1794
+ output: { type: "object" },
1795
+ experimental_output: { type: "object" },
1796
+ instructions: { type: "string" },
1797
+ toolsets: { type: "object" },
1798
+ clientTools: { type: "object" },
1799
+ context: {
1800
+ type: "array",
1801
+ items: { type: "object" }
1802
+ },
1803
+ memory: {
1804
+ type: "object",
1805
+ properties: {
1806
+ threadId: { type: "string" },
1807
+ resourceId: { type: "string", description: "The resource ID for the conversation" }
1808
+ }
1809
+ },
1810
+ toolChoice: {
1811
+ oneOf: [
1812
+ { type: "string", enum: ["auto", "none", "required"] },
1813
+ { type: "object", properties: { type: { type: "string" }, toolName: { type: "string" } } }
1814
+ ]
1815
+ }
1816
+ },
1817
+ required: ["messages"]
1818
+ }
1819
+ }
1820
+ }
1821
+ },
1822
+ responses: {
1823
+ 200: {
1824
+ description: "Streamed response"
1825
+ },
1826
+ 404: {
1827
+ description: "Agent not found"
1828
+ }
1829
+ }
1830
+ }),
1831
+ streamVNextGenerateHandler
1832
+ );
1833
+ router.get(
1834
+ "/:agentId/speakers",
1835
+ async (c2, next) => {
1836
+ c2.header("Deprecation", "true");
1837
+ c2.header("Warning", '299 - "This endpoint is deprecated, use /api/agents/:agentId/voice/speakers instead"');
1838
+ c2.header("Link", '</api/agents/:agentId/voice/speakers>; rel="successor-version"');
1839
+ return next();
1840
+ },
1841
+ w({
1842
+ description: "[DEPRECATED] Use /api/agents/:agentId/voice/speakers instead. Get available speakers for an agent",
1728
1843
  tags: ["agents"],
1729
1844
  parameters: [
1730
1845
  {
@@ -2350,7 +2465,7 @@ async function getLogTransports(c2) {
2350
2465
  }
2351
2466
  }
2352
2467
 
2353
- // src/server/handlers/routes/logs.ts
2468
+ // src/server/handlers/routes/logs/router.ts
2354
2469
  function logsRouter() {
2355
2470
  const router = new Hono();
2356
2471
  router.get(
@@ -4345,7 +4460,7 @@ function toFetchResponse(res) {
4345
4460
  return res.fetchResponse;
4346
4461
  }
4347
4462
 
4348
- // src/server/handlers/mcp.ts
4463
+ // src/server/handlers/routes/mcp/handlers.ts
4349
4464
  var getMastra = (c2) => c2.get("mastra");
4350
4465
  var getMcpServerMessageHandler = async (c2) => {
4351
4466
  const mastra = getMastra(c2);
@@ -4549,7 +4664,7 @@ var executeMcpServerToolHandler = async (c2) => {
4549
4664
  }
4550
4665
  };
4551
4666
 
4552
- // src/server/handlers/routes/mcp.ts
4667
+ // src/server/handlers/routes/mcp/router.ts
4553
4668
  function mcpRouter(bodyLimitOptions) {
4554
4669
  const router = new Hono();
4555
4670
  router.post(
@@ -4958,6 +5073,20 @@ function mcpRouter(bodyLimitOptions) {
4958
5073
  );
4959
5074
  return router;
4960
5075
  }
5076
+
5077
+ // src/server/handlers/utils/query-parsers.ts
5078
+ function parseLimit(rawLimit) {
5079
+ if (rawLimit === void 0) {
5080
+ return void 0;
5081
+ }
5082
+ const n2 = Number(rawLimit);
5083
+ if (Number.isFinite(n2) && Number.isInteger(n2) && n2 > 0) {
5084
+ return n2;
5085
+ }
5086
+ return void 0;
5087
+ }
5088
+
5089
+ // src/server/handlers/routes/memory/handlers.ts
4961
5090
  async function getMemoryStatusHandler(c2) {
4962
5091
  try {
4963
5092
  const mastra = c2.get("mastra");
@@ -4973,6 +5102,21 @@ async function getMemoryStatusHandler(c2) {
4973
5102
  return handleError(error, "Error getting memory status");
4974
5103
  }
4975
5104
  }
5105
+ async function getMemoryConfigHandler(c2) {
5106
+ try {
5107
+ const mastra = c2.get("mastra");
5108
+ const agentId = c2.req.query("agentId");
5109
+ const networkId = c2.req.query("networkId");
5110
+ const result = await getMemoryConfigHandler$1({
5111
+ mastra,
5112
+ agentId,
5113
+ networkId
5114
+ });
5115
+ return c2.json(result);
5116
+ } catch (error) {
5117
+ return handleError(error, "Error getting memory configuration");
5118
+ }
5119
+ }
4976
5120
  async function getThreadsHandler(c2) {
4977
5121
  try {
4978
5122
  const mastra = c2.get("mastra");
@@ -5083,14 +5227,7 @@ async function getMessagesHandler(c2) {
5083
5227
  const agentId = c2.req.query("agentId");
5084
5228
  const networkId = c2.req.query("networkId");
5085
5229
  const threadId = c2.req.param("threadId");
5086
- const rawLimit = c2.req.query("limit");
5087
- let limit = void 0;
5088
- if (rawLimit !== void 0) {
5089
- const n2 = Number(rawLimit);
5090
- if (Number.isFinite(n2) && Number.isInteger(n2) && n2 > 0) {
5091
- limit = n2;
5092
- }
5093
- }
5230
+ const limit = parseLimit(c2.req.query("limit"));
5094
5231
  const result = await getMessagesHandler$1({
5095
5232
  mastra,
5096
5233
  agentId,
@@ -5103,6 +5240,32 @@ async function getMessagesHandler(c2) {
5103
5240
  return handleError(error, "Error getting messages");
5104
5241
  }
5105
5242
  }
5243
+ async function getMessagesPaginatedHandler(c2) {
5244
+ try {
5245
+ const mastra = c2.get("mastra");
5246
+ const threadId = c2.req.param("threadId");
5247
+ const resourceId = c2.req.query("resourceId");
5248
+ const format = c2.req.query("format") || "v1";
5249
+ const selectByArgs = c2.req.query("selectBy");
5250
+ let selectBy = {};
5251
+ if (selectByArgs) {
5252
+ try {
5253
+ selectBy = JSON.parse(selectByArgs);
5254
+ } catch (_error) {
5255
+ }
5256
+ }
5257
+ const result = await getMessagesPaginatedHandler$1({
5258
+ mastra,
5259
+ threadId,
5260
+ resourceId,
5261
+ format,
5262
+ selectBy
5263
+ });
5264
+ return c2.json(result);
5265
+ } catch (error) {
5266
+ return handleError(error, "Error getting messages");
5267
+ }
5268
+ }
5106
5269
  async function updateWorkingMemoryHandler(c2) {
5107
5270
  try {
5108
5271
  const mastra = c2.get("mastra");
@@ -5141,8 +5304,35 @@ async function getWorkingMemoryHandler(c2) {
5141
5304
  return handleError(error, "Error getting working memory");
5142
5305
  }
5143
5306
  }
5307
+ async function searchMemoryHandler(c2) {
5308
+ try {
5309
+ const mastra = c2.get("mastra");
5310
+ const agentId = c2.req.query("agentId");
5311
+ const searchQuery = c2.req.query("searchQuery");
5312
+ const resourceId = c2.req.query("resourceId");
5313
+ const threadId = c2.req.query("threadId");
5314
+ const limit = parseLimit(c2.req.query("limit"));
5315
+ const memoryConfig = c2.req.query("memoryConfig") ? JSON.parse(c2.req.query("memoryConfig")) : void 0;
5316
+ const networkId = c2.req.query("networkId");
5317
+ const runtimeContext = c2.get("runtimeContext");
5318
+ const result = await searchMemoryHandler$1({
5319
+ mastra,
5320
+ agentId,
5321
+ searchQuery,
5322
+ resourceId,
5323
+ threadId,
5324
+ limit,
5325
+ memoryConfig,
5326
+ networkId,
5327
+ runtimeContext
5328
+ });
5329
+ return c2.json(result);
5330
+ } catch (error) {
5331
+ return handleError(error, "Error searching memory");
5332
+ }
5333
+ }
5144
5334
 
5145
- // src/server/handlers/routes/memory.ts
5335
+ // src/server/handlers/routes/memory/router.ts
5146
5336
  function memoryRoutes(bodyLimitOptions) {
5147
5337
  const router = new Hono();
5148
5338
  router.get(
@@ -5423,6 +5613,84 @@ function memoryRoutes(bodyLimitOptions) {
5423
5613
  }),
5424
5614
  getMemoryStatusHandler
5425
5615
  );
5616
+ router.get(
5617
+ "/config",
5618
+ w({
5619
+ description: "Get memory configuration",
5620
+ tags: ["memory"],
5621
+ parameters: [
5622
+ {
5623
+ name: "agentId",
5624
+ in: "query",
5625
+ required: true,
5626
+ schema: { type: "string" }
5627
+ }
5628
+ ],
5629
+ responses: {
5630
+ 200: {
5631
+ description: "Memory configuration",
5632
+ content: {
5633
+ "application/json": {
5634
+ schema: {
5635
+ type: "object",
5636
+ properties: {
5637
+ config: {
5638
+ type: "object",
5639
+ properties: {
5640
+ lastMessages: {
5641
+ oneOf: [{ type: "number" }, { type: "boolean" }]
5642
+ },
5643
+ semanticRecall: {
5644
+ oneOf: [
5645
+ { type: "boolean" },
5646
+ {
5647
+ type: "object",
5648
+ properties: {
5649
+ topK: { type: "number" },
5650
+ messageRange: {
5651
+ oneOf: [
5652
+ { type: "number" },
5653
+ {
5654
+ type: "object",
5655
+ properties: {
5656
+ before: { type: "number" },
5657
+ after: { type: "number" }
5658
+ }
5659
+ }
5660
+ ]
5661
+ },
5662
+ scope: { type: "string", enum: ["thread", "resource"] }
5663
+ }
5664
+ }
5665
+ ]
5666
+ },
5667
+ workingMemory: {
5668
+ type: "object",
5669
+ properties: {
5670
+ enabled: { type: "boolean" },
5671
+ scope: { type: "string", enum: ["thread", "resource"] },
5672
+ template: { type: "string" }
5673
+ }
5674
+ },
5675
+ threads: {
5676
+ type: "object",
5677
+ properties: {
5678
+ generateTitle: {
5679
+ oneOf: [{ type: "boolean" }, { type: "object" }]
5680
+ }
5681
+ }
5682
+ }
5683
+ }
5684
+ }
5685
+ }
5686
+ }
5687
+ }
5688
+ }
5689
+ }
5690
+ }
5691
+ }),
5692
+ getMemoryConfigHandler
5693
+ );
5426
5694
  router.get(
5427
5695
  "/threads",
5428
5696
  w({
@@ -5482,6 +5750,15 @@ function memoryRoutes(bodyLimitOptions) {
5482
5750
  );
5483
5751
  router.get(
5484
5752
  "/threads/:threadId/messages",
5753
+ async (c2, next) => {
5754
+ c2.header("Deprecation", "true");
5755
+ c2.header(
5756
+ "Warning",
5757
+ '299 - "This endpoint is deprecated, use /api/memory/threads/:threadId/messages/paginated instead"'
5758
+ );
5759
+ c2.header("Link", '</api/memory/threads/:threadId/messages/paginated>; rel="successor-version"');
5760
+ return next();
5761
+ },
5485
5762
  w({
5486
5763
  description: "Get messages for a thread",
5487
5764
  tags: ["memory"],
@@ -5515,46 +5792,152 @@ function memoryRoutes(bodyLimitOptions) {
5515
5792
  getMessagesHandler
5516
5793
  );
5517
5794
  router.get(
5518
- "/threads/:threadId/working-memory",
5795
+ "/threads/:threadId/messages/paginated",
5519
5796
  w({
5520
- description: "Get working memory for a thread",
5797
+ description: "Get paginated messages for a thread",
5521
5798
  tags: ["memory"],
5522
5799
  parameters: [
5523
5800
  {
5524
5801
  name: "threadId",
5525
5802
  in: "path",
5526
5803
  required: true,
5527
- schema: { type: "string" }
5804
+ description: "The unique identifier of the thread",
5805
+ schema: {
5806
+ type: "string"
5807
+ }
5528
5808
  },
5529
5809
  {
5530
- name: "agentId",
5810
+ name: "resourceId",
5811
+ in: "query",
5812
+ required: false,
5813
+ description: "Filter messages by resource ID",
5814
+ schema: {
5815
+ type: "string"
5816
+ }
5817
+ },
5818
+ {
5819
+ name: "format",
5820
+ in: "query",
5821
+ required: false,
5822
+ description: "Message format to return",
5823
+ schema: {
5824
+ type: "string",
5825
+ enum: ["v1", "v2"],
5826
+ default: "v1"
5827
+ }
5828
+ },
5829
+ {
5830
+ name: "selectBy",
5831
+ in: "query",
5832
+ required: false,
5833
+ description: "JSON string containing selection criteria for messages",
5834
+ schema: {
5835
+ type: "string",
5836
+ 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}]}'
5837
+ }
5838
+ }
5839
+ ],
5840
+ responses: {
5841
+ 200: {
5842
+ description: "List of messages"
5843
+ }
5844
+ }
5845
+ }),
5846
+ getMessagesPaginatedHandler
5847
+ );
5848
+ router.get(
5849
+ "/search",
5850
+ w({
5851
+ description: "Search messages in a thread",
5852
+ tags: ["memory"],
5853
+ parameters: [
5854
+ {
5855
+ name: "searchQuery",
5531
5856
  in: "query",
5532
5857
  required: true,
5533
- schema: { type: "string" }
5858
+ schema: { type: "string" },
5859
+ description: "The text to search for"
5534
5860
  },
5535
5861
  {
5536
5862
  name: "resourceId",
5537
5863
  in: "query",
5864
+ required: true,
5865
+ schema: { type: "string" },
5866
+ description: "The resource ID (user/org) to validate thread ownership"
5867
+ },
5868
+ {
5869
+ name: "threadId",
5870
+ in: "query",
5538
5871
  required: false,
5539
- schema: { type: "string" }
5872
+ schema: { type: "string" },
5873
+ description: "The thread ID to search within (optional - searches all threads if not provided)"
5874
+ },
5875
+ {
5876
+ name: "agentId",
5877
+ in: "query",
5878
+ required: true,
5879
+ schema: { type: "string" },
5880
+ description: "The agent ID"
5881
+ },
5882
+ {
5883
+ name: "limit",
5884
+ in: "query",
5885
+ required: false,
5886
+ schema: { type: "number" },
5887
+ description: "Maximum number of results to return (default: 20)"
5888
+ },
5889
+ {
5890
+ name: "memoryConfig",
5891
+ in: "query",
5892
+ required: false,
5893
+ schema: { type: "string" },
5894
+ description: 'JSON-encoded memory configuration (e.g., {"lastMessages": 0} for semantic-only search)'
5540
5895
  }
5541
5896
  ],
5542
5897
  responses: {
5543
5898
  200: {
5544
- description: "Working memory details"
5899
+ description: "Search results",
5900
+ content: {
5901
+ "application/json": {
5902
+ schema: {
5903
+ type: "object",
5904
+ properties: {
5905
+ results: {
5906
+ type: "array",
5907
+ items: {
5908
+ type: "object",
5909
+ properties: {
5910
+ id: { type: "string" },
5911
+ role: { type: "string" },
5912
+ content: { type: "string" },
5913
+ createdAt: { type: "string" }
5914
+ }
5915
+ }
5916
+ },
5917
+ count: { type: "number" },
5918
+ query: { type: "string" }
5919
+ }
5920
+ }
5921
+ }
5922
+ }
5923
+ },
5924
+ 400: {
5925
+ description: "Bad request"
5926
+ },
5927
+ 403: {
5928
+ description: "Thread does not belong to the specified resource"
5545
5929
  },
5546
5930
  404: {
5547
5931
  description: "Thread not found"
5548
5932
  }
5549
5933
  }
5550
5934
  }),
5551
- getWorkingMemoryHandler
5935
+ searchMemoryHandler
5552
5936
  );
5553
- router.post(
5937
+ router.get(
5554
5938
  "/threads/:threadId/working-memory",
5555
- bodyLimit(bodyLimitOptions),
5556
5939
  w({
5557
- description: "Update working memory for a thread",
5940
+ description: "Get working memory for a thread",
5558
5941
  tags: ["memory"],
5559
5942
  parameters: [
5560
5943
  {
@@ -5568,14 +5951,51 @@ function memoryRoutes(bodyLimitOptions) {
5568
5951
  in: "query",
5569
5952
  required: true,
5570
5953
  schema: { type: "string" }
5954
+ },
5955
+ {
5956
+ name: "resourceId",
5957
+ in: "query",
5958
+ required: false,
5959
+ schema: { type: "string" }
5571
5960
  }
5572
5961
  ],
5573
- requestBody: {
5574
- required: true,
5575
- content: {
5576
- "application/json": {
5577
- schema: {
5578
- type: "object",
5962
+ responses: {
5963
+ 200: {
5964
+ description: "Working memory details"
5965
+ },
5966
+ 404: {
5967
+ description: "Thread not found"
5968
+ }
5969
+ }
5970
+ }),
5971
+ getWorkingMemoryHandler
5972
+ );
5973
+ router.post(
5974
+ "/threads/:threadId/working-memory",
5975
+ bodyLimit(bodyLimitOptions),
5976
+ w({
5977
+ description: "Update working memory for a thread",
5978
+ tags: ["memory"],
5979
+ parameters: [
5980
+ {
5981
+ name: "threadId",
5982
+ in: "path",
5983
+ required: true,
5984
+ schema: { type: "string" }
5985
+ },
5986
+ {
5987
+ name: "agentId",
5988
+ in: "query",
5989
+ required: true,
5990
+ schema: { type: "string" }
5991
+ }
5992
+ ],
5993
+ requestBody: {
5994
+ required: true,
5995
+ content: {
5996
+ "application/json": {
5997
+ schema: {
5998
+ type: "object",
5579
5999
  properties: {
5580
6000
  workingMemory: { type: "string" },
5581
6001
  resourceId: { type: "string" }
@@ -5860,7 +6280,7 @@ async function streamGenerateVNextNetworkHandler(c2) {
5860
6280
  c2.header("Transfer-Encoding", "chunked");
5861
6281
  return stream(
5862
6282
  c2,
5863
- async (stream5) => {
6283
+ async (stream6) => {
5864
6284
  try {
5865
6285
  const result = await streamGenerateVNextNetworkHandler$1({
5866
6286
  mastra,
@@ -5869,12 +6289,12 @@ async function streamGenerateVNextNetworkHandler(c2) {
5869
6289
  body
5870
6290
  });
5871
6291
  const reader = result.stream.getReader();
5872
- stream5.onAbort(() => {
6292
+ stream6.onAbort(() => {
5873
6293
  void reader.cancel("request aborted");
5874
6294
  });
5875
6295
  let chunkResult;
5876
6296
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
5877
- await stream5.write(JSON.stringify(chunkResult.value) + "");
6297
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
5878
6298
  }
5879
6299
  } catch (err) {
5880
6300
  mastra.getLogger().error("Error in network stream: " + (err?.message ?? "Unknown error"));
@@ -5915,7 +6335,7 @@ async function loopStreamVNextNetworkHandler(c2) {
5915
6335
  c2.header("Transfer-Encoding", "chunked");
5916
6336
  return stream(
5917
6337
  c2,
5918
- async (stream5) => {
6338
+ async (stream6) => {
5919
6339
  try {
5920
6340
  const result = await loopStreamVNextNetworkHandler$1({
5921
6341
  mastra,
@@ -5924,12 +6344,12 @@ async function loopStreamVNextNetworkHandler(c2) {
5924
6344
  body
5925
6345
  });
5926
6346
  const reader = result.stream.getReader();
5927
- stream5.onAbort(() => {
6347
+ stream6.onAbort(() => {
5928
6348
  void reader.cancel("request aborted");
5929
6349
  });
5930
6350
  let chunkResult;
5931
6351
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
5932
- await stream5.write(JSON.stringify(chunkResult.value) + "");
6352
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
5933
6353
  }
5934
6354
  } catch (err) {
5935
6355
  mastra.getLogger().error("Error in network loop stream: " + (err?.message ?? "Unknown error"));
@@ -5944,7 +6364,7 @@ async function loopStreamVNextNetworkHandler(c2) {
5944
6364
  }
5945
6365
  }
5946
6366
 
5947
- // src/server/handlers/routes/networks.ts
6367
+ // src/server/handlers/routes/networks/router.ts
5948
6368
  function vNextNetworksRouter(bodyLimitOptions) {
5949
6369
  const router = new Hono();
5950
6370
  router.get(
@@ -6319,6 +6739,288 @@ function networksRouter(bodyLimitOptions) {
6319
6739
  );
6320
6740
  return router;
6321
6741
  }
6742
+ async function getScorersHandler(c2) {
6743
+ try {
6744
+ const scorers = await getScorersHandler$1({
6745
+ mastra: c2.get("mastra"),
6746
+ runtimeContext: c2.get("runtimeContext")
6747
+ });
6748
+ return c2.json(scorers);
6749
+ } catch (error) {
6750
+ return handleError(error, "Error getting scorers");
6751
+ }
6752
+ }
6753
+ async function getScorerHandler(c2) {
6754
+ const mastra = c2.get("mastra");
6755
+ const scorerId = c2.req.param("scorerId");
6756
+ const runtimeContext = c2.get("runtimeContext");
6757
+ const scorer = await getScorerHandler$1({
6758
+ mastra,
6759
+ scorerId,
6760
+ runtimeContext
6761
+ });
6762
+ return c2.json(scorer);
6763
+ }
6764
+ async function getScoresByRunIdHandler(c2) {
6765
+ const mastra = c2.get("mastra");
6766
+ const runId = c2.req.param("runId");
6767
+ const page = parseInt(c2.req.query("page") || "0");
6768
+ const perPage = parseInt(c2.req.query("perPage") || "10");
6769
+ const pagination = { page, perPage };
6770
+ try {
6771
+ const scores = await getScoresByRunIdHandler$1({
6772
+ mastra,
6773
+ runId,
6774
+ pagination
6775
+ });
6776
+ return c2.json(scores);
6777
+ } catch (error) {
6778
+ return handleError(error, "Error getting scores by run id");
6779
+ }
6780
+ }
6781
+ async function getScoresByScorerIdHandler(c2) {
6782
+ const mastra = c2.get("mastra");
6783
+ const scorerId = c2.req.param("scorerId");
6784
+ const page = parseInt(c2.req.query("page") || "0");
6785
+ const perPage = parseInt(c2.req.query("perPage") || "10");
6786
+ const entityId = c2.req.query("entityId");
6787
+ const entityType = c2.req.query("entityType");
6788
+ const pagination = { page, perPage };
6789
+ try {
6790
+ const scores = await getScoresByScorerIdHandler$1({
6791
+ mastra,
6792
+ scorerId,
6793
+ pagination,
6794
+ entityId,
6795
+ entityType
6796
+ });
6797
+ return c2.json(scores);
6798
+ } catch (error) {
6799
+ return handleError(error, "Error getting scores by scorer id");
6800
+ }
6801
+ }
6802
+ async function getScoresByEntityIdHandler(c2) {
6803
+ const mastra = c2.get("mastra");
6804
+ const entityId = c2.req.param("entityId");
6805
+ const entityType = c2.req.param("entityType");
6806
+ const page = parseInt(c2.req.query("page") || "0");
6807
+ const perPage = parseInt(c2.req.query("perPage") || "10");
6808
+ const pagination = { page, perPage };
6809
+ try {
6810
+ const scores = await getScoresByEntityIdHandler$1({
6811
+ mastra,
6812
+ entityId,
6813
+ entityType,
6814
+ pagination
6815
+ });
6816
+ return c2.json(scores);
6817
+ } catch (error) {
6818
+ return handleError(error, "Error getting scores by entity id");
6819
+ }
6820
+ }
6821
+ async function saveScoreHandler(c2) {
6822
+ const mastra = c2.get("mastra");
6823
+ const score = await c2.req.json();
6824
+ try {
6825
+ const result = await saveScoreHandler$1({
6826
+ mastra,
6827
+ score
6828
+ });
6829
+ return c2.json(result);
6830
+ } catch (error) {
6831
+ return handleError(error, "Error saving score");
6832
+ }
6833
+ }
6834
+
6835
+ // src/server/handlers/routes/scores/router.ts
6836
+ function scoresRouter(bodyLimitOptions) {
6837
+ const router = new Hono();
6838
+ router.get(
6839
+ "/scorers",
6840
+ w({
6841
+ description: "Get all scorers",
6842
+ tags: ["scores"],
6843
+ responses: {
6844
+ 200: {
6845
+ description: "List of all scorers"
6846
+ }
6847
+ }
6848
+ }),
6849
+ getScorersHandler
6850
+ );
6851
+ router.get(
6852
+ "/scorers/:scorerId",
6853
+ w({
6854
+ description: "Get a scorer by ID",
6855
+ tags: ["scores"],
6856
+ responses: {
6857
+ 200: {
6858
+ description: "Scorer details"
6859
+ }
6860
+ }
6861
+ }),
6862
+ getScorerHandler
6863
+ );
6864
+ router.get(
6865
+ "/run/:runId",
6866
+ w({
6867
+ description: "Get scores by run ID",
6868
+ tags: ["scores"],
6869
+ parameters: [
6870
+ {
6871
+ name: "runId",
6872
+ in: "path",
6873
+ required: true,
6874
+ schema: { type: "string" }
6875
+ },
6876
+ {
6877
+ name: "page",
6878
+ in: "query",
6879
+ required: false,
6880
+ schema: { type: "number" },
6881
+ description: "Page number for pagination (default: 0)"
6882
+ },
6883
+ {
6884
+ name: "perPage",
6885
+ in: "query",
6886
+ required: false,
6887
+ schema: { type: "number" },
6888
+ description: "Number of items per page (default: 10)"
6889
+ }
6890
+ ],
6891
+ responses: {
6892
+ 200: {
6893
+ description: "Paginated list of scores for run ID"
6894
+ }
6895
+ }
6896
+ }),
6897
+ getScoresByRunIdHandler
6898
+ );
6899
+ router.get(
6900
+ "/scorer/:scorerId",
6901
+ w({
6902
+ description: "Get scores by scorer ID",
6903
+ tags: ["scores"],
6904
+ parameters: [
6905
+ {
6906
+ name: "scorerId",
6907
+ in: "path",
6908
+ required: true,
6909
+ schema: { type: "string" }
6910
+ },
6911
+ {
6912
+ name: "page",
6913
+ in: "query",
6914
+ required: false,
6915
+ schema: { type: "number" },
6916
+ description: "Page number for pagination (default: 0)"
6917
+ },
6918
+ {
6919
+ name: "perPage",
6920
+ in: "query",
6921
+ required: false,
6922
+ schema: { type: "number" },
6923
+ description: "Number of items per page (default: 10)"
6924
+ }
6925
+ ],
6926
+ responses: {
6927
+ 200: {
6928
+ description: "Paginated list of scores for run ID"
6929
+ }
6930
+ }
6931
+ }),
6932
+ getScoresByScorerIdHandler
6933
+ );
6934
+ router.get(
6935
+ "/entity/:entityType/:entityId",
6936
+ w({
6937
+ description: "Get scores by entity ID and type",
6938
+ tags: ["scores"],
6939
+ parameters: [
6940
+ {
6941
+ name: "entityType",
6942
+ in: "path",
6943
+ required: true,
6944
+ schema: { type: "string" },
6945
+ description: "Type of entity (e.g., agent, workflow, tool)"
6946
+ },
6947
+ {
6948
+ name: "entityId",
6949
+ in: "path",
6950
+ required: true,
6951
+ schema: { type: "string" },
6952
+ description: "ID of the entity"
6953
+ },
6954
+ {
6955
+ name: "page",
6956
+ in: "query",
6957
+ required: false,
6958
+ schema: { type: "number" },
6959
+ description: "Page number for pagination (default: 0)"
6960
+ },
6961
+ {
6962
+ name: "perPage",
6963
+ in: "query",
6964
+ required: false,
6965
+ schema: { type: "number" },
6966
+ description: "Number of items per page (default: 10)"
6967
+ }
6968
+ ],
6969
+ responses: {
6970
+ 200: {
6971
+ description: "Paginated list of scores for entity"
6972
+ }
6973
+ }
6974
+ }),
6975
+ getScoresByEntityIdHandler
6976
+ );
6977
+ router.post(
6978
+ "/",
6979
+ bodyLimit(bodyLimitOptions),
6980
+ w({
6981
+ description: "Save a score",
6982
+ tags: ["scores"],
6983
+ requestBody: {
6984
+ required: true,
6985
+ content: {
6986
+ "application/json": {
6987
+ schema: {
6988
+ type: "object",
6989
+ properties: {
6990
+ id: { type: "string" },
6991
+ runId: { type: "string" },
6992
+ scorer: { type: "object" },
6993
+ result: { type: "object" },
6994
+ input: { type: "object" },
6995
+ output: { type: "object" },
6996
+ source: { type: "string" },
6997
+ entityType: { type: "string" },
6998
+ entity: { type: "object" },
6999
+ metadata: { type: "object" },
7000
+ additionalLLMContext: { type: "object" },
7001
+ runtimeContext: { type: "object" },
7002
+ resourceId: { type: "string" },
7003
+ threadId: { type: "string" },
7004
+ traceId: { type: "string" }
7005
+ },
7006
+ required: ["id", "runId", "scorer", "result", "input", "output", "source"]
7007
+ }
7008
+ }
7009
+ }
7010
+ },
7011
+ responses: {
7012
+ 200: {
7013
+ description: "Score saved successfully"
7014
+ },
7015
+ 400: {
7016
+ description: "Invalid score data"
7017
+ }
7018
+ }
7019
+ }),
7020
+ saveScoreHandler
7021
+ );
7022
+ return router;
7023
+ }
6322
7024
  async function getTelemetryHandler(c2) {
6323
7025
  try {
6324
7026
  const mastra = c2.get("mastra");
@@ -6355,7 +7057,7 @@ async function storeTelemetryHandler(c2) {
6355
7057
  }
6356
7058
  }
6357
7059
 
6358
- // src/server/handlers/routes/telemetry.ts
7060
+ // src/server/handlers/routes/telemetry/router.ts
6359
7061
  function telemetryRouter() {
6360
7062
  const router = new Hono();
6361
7063
  router.get(
@@ -6572,7 +7274,7 @@ async function deleteIndex(c2) {
6572
7274
  }
6573
7275
  }
6574
7276
 
6575
- // src/server/handlers/routes/vector.ts
7277
+ // src/server/handlers/routes/vector/router.ts
6576
7278
  function vectorRouter(bodyLimitOptions) {
6577
7279
  const router = new Hono();
6578
7280
  router.post(
@@ -6787,184 +7489,6 @@ function vectorRouter(bodyLimitOptions) {
6787
7489
  );
6788
7490
  return router;
6789
7491
  }
6790
- async function getLegacyWorkflowsHandler(c2) {
6791
- try {
6792
- const mastra = c2.get("mastra");
6793
- const workflows = await getLegacyWorkflowsHandler$1({
6794
- mastra
6795
- });
6796
- return c2.json(workflows);
6797
- } catch (error) {
6798
- return handleError(error, "Error getting workflows");
6799
- }
6800
- }
6801
- async function getLegacyWorkflowByIdHandler(c2) {
6802
- try {
6803
- const mastra = c2.get("mastra");
6804
- const workflowId = c2.req.param("workflowId");
6805
- const workflow = await getLegacyWorkflowByIdHandler$1({
6806
- mastra,
6807
- workflowId
6808
- });
6809
- return c2.json(workflow);
6810
- } catch (error) {
6811
- return handleError(error, "Error getting workflow");
6812
- }
6813
- }
6814
- async function startAsyncLegacyWorkflowHandler(c2) {
6815
- try {
6816
- const mastra = c2.get("mastra");
6817
- const runtimeContext = c2.get("runtimeContext");
6818
- const workflowId = c2.req.param("workflowId");
6819
- const triggerData = await c2.req.json();
6820
- const runId = c2.req.query("runId");
6821
- const result = await startAsyncLegacyWorkflowHandler$1({
6822
- mastra,
6823
- runtimeContext,
6824
- workflowId,
6825
- runId,
6826
- triggerData
6827
- });
6828
- return c2.json(result);
6829
- } catch (error) {
6830
- return handleError(error, "Error executing workflow");
6831
- }
6832
- }
6833
- async function createLegacyWorkflowRunHandler(c2) {
6834
- try {
6835
- const mastra = c2.get("mastra");
6836
- const workflowId = c2.req.param("workflowId");
6837
- const prevRunId = c2.req.query("runId");
6838
- const result = await createLegacyWorkflowRunHandler$1({
6839
- mastra,
6840
- workflowId,
6841
- runId: prevRunId
6842
- });
6843
- return c2.json(result);
6844
- } catch (e2) {
6845
- return handleError(e2, "Error creating run");
6846
- }
6847
- }
6848
- async function startLegacyWorkflowRunHandler(c2) {
6849
- try {
6850
- const mastra = c2.get("mastra");
6851
- const runtimeContext = c2.get("runtimeContext");
6852
- const workflowId = c2.req.param("workflowId");
6853
- const triggerData = await c2.req.json();
6854
- const runId = c2.req.query("runId");
6855
- await startLegacyWorkflowRunHandler$1({
6856
- mastra,
6857
- runtimeContext,
6858
- workflowId,
6859
- runId,
6860
- triggerData
6861
- });
6862
- return c2.json({ message: "Workflow run started" });
6863
- } catch (e2) {
6864
- return handleError(e2, "Error starting workflow run");
6865
- }
6866
- }
6867
- function watchLegacyWorkflowHandler(c2) {
6868
- try {
6869
- const mastra = c2.get("mastra");
6870
- const logger2 = mastra.getLogger();
6871
- const workflowId = c2.req.param("workflowId");
6872
- const runId = c2.req.query("runId");
6873
- if (!runId) {
6874
- throw new HTTPException(400, { message: "runId required to watch workflow" });
6875
- }
6876
- return stream(
6877
- c2,
6878
- async (stream5) => {
6879
- try {
6880
- const result = await watchLegacyWorkflowHandler$1({
6881
- mastra,
6882
- workflowId,
6883
- runId
6884
- });
6885
- stream5.onAbort(() => {
6886
- if (!result.locked) {
6887
- return result.cancel();
6888
- }
6889
- });
6890
- for await (const chunk of result) {
6891
- await stream5.write(chunk.toString() + "");
6892
- }
6893
- } catch (err) {
6894
- console.log(err);
6895
- }
6896
- },
6897
- async (err) => {
6898
- logger2.error("Error in watch stream: " + err?.message);
6899
- }
6900
- );
6901
- } catch (error) {
6902
- return handleError(error, "Error watching workflow");
6903
- }
6904
- }
6905
- async function resumeAsyncLegacyWorkflowHandler(c2) {
6906
- try {
6907
- const mastra = c2.get("mastra");
6908
- const runtimeContext = c2.get("runtimeContext");
6909
- const workflowId = c2.req.param("workflowId");
6910
- const runId = c2.req.query("runId");
6911
- const { stepId, context } = await c2.req.json();
6912
- if (!runId) {
6913
- throw new HTTPException(400, { message: "runId required to resume workflow" });
6914
- }
6915
- const result = await resumeAsyncLegacyWorkflowHandler$1({
6916
- mastra,
6917
- runtimeContext,
6918
- workflowId,
6919
- runId,
6920
- body: { stepId, context }
6921
- });
6922
- return c2.json(result);
6923
- } catch (error) {
6924
- return handleError(error, "Error resuming workflow step");
6925
- }
6926
- }
6927
- async function resumeLegacyWorkflowHandler(c2) {
6928
- try {
6929
- const mastra = c2.get("mastra");
6930
- const runtimeContext = c2.get("runtimeContext");
6931
- const workflowId = c2.req.param("workflowId");
6932
- const runId = c2.req.query("runId");
6933
- const { stepId, context } = await c2.req.json();
6934
- if (!runId) {
6935
- throw new HTTPException(400, { message: "runId required to resume workflow" });
6936
- }
6937
- await resumeLegacyWorkflowHandler$1({
6938
- mastra,
6939
- runtimeContext,
6940
- workflowId,
6941
- runId,
6942
- body: { stepId, context }
6943
- });
6944
- return c2.json({ message: "Workflow run resumed" });
6945
- } catch (error) {
6946
- return handleError(error, "Error resuming workflow");
6947
- }
6948
- }
6949
- async function getLegacyWorkflowRunsHandler(c2) {
6950
- try {
6951
- const mastra = c2.get("mastra");
6952
- const workflowId = c2.req.param("workflowId");
6953
- const { fromDate, toDate, limit, offset, resourceId } = c2.req.query();
6954
- const workflowRuns = await getLegacyWorkflowRunsHandler$1({
6955
- mastra,
6956
- workflowId,
6957
- fromDate: fromDate ? new Date(fromDate) : void 0,
6958
- toDate: toDate ? new Date(toDate) : void 0,
6959
- limit: limit ? Number(limit) : void 0,
6960
- offset: offset ? Number(offset) : void 0,
6961
- resourceId
6962
- });
6963
- return c2.json(workflowRuns);
6964
- } catch (error) {
6965
- return handleError(error, "Error getting workflow runs");
6966
- }
6967
- }
6968
7492
  async function getWorkflowsHandler(c2) {
6969
7493
  try {
6970
7494
  const mastra = c2.get("mastra");
@@ -7042,46 +7566,87 @@ async function startWorkflowRunHandler(c2) {
7042
7566
  return handleError(e2, "Error starting workflow run");
7043
7567
  }
7044
7568
  }
7045
- function watchWorkflowHandler(c2) {
7569
+ function watchWorkflowHandler(c2) {
7570
+ try {
7571
+ const mastra = c2.get("mastra");
7572
+ const logger2 = mastra.getLogger();
7573
+ const workflowId = c2.req.param("workflowId");
7574
+ const runId = c2.req.query("runId");
7575
+ if (!runId) {
7576
+ throw new HTTPException(400, { message: "runId required to watch workflow" });
7577
+ }
7578
+ c2.header("Transfer-Encoding", "chunked");
7579
+ return stream(
7580
+ c2,
7581
+ async (stream6) => {
7582
+ try {
7583
+ const result = await watchWorkflowHandler$1({
7584
+ mastra,
7585
+ workflowId,
7586
+ runId
7587
+ });
7588
+ const reader = result.getReader();
7589
+ stream6.onAbort(() => {
7590
+ void reader.cancel("request aborted");
7591
+ });
7592
+ let chunkResult;
7593
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
7594
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
7595
+ }
7596
+ } catch (err) {
7597
+ logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
7598
+ }
7599
+ },
7600
+ async (err) => {
7601
+ logger2.error("Error in watch stream: " + err?.message);
7602
+ }
7603
+ );
7604
+ } catch (error) {
7605
+ return handleError(error, "Error watching workflow");
7606
+ }
7607
+ }
7608
+ async function streamWorkflowHandler(c2) {
7046
7609
  try {
7047
7610
  const mastra = c2.get("mastra");
7611
+ const runtimeContext = c2.get("runtimeContext");
7048
7612
  const logger2 = mastra.getLogger();
7049
7613
  const workflowId = c2.req.param("workflowId");
7614
+ const { inputData } = await c2.req.json();
7050
7615
  const runId = c2.req.query("runId");
7051
- if (!runId) {
7052
- throw new HTTPException(400, { message: "runId required to watch workflow" });
7053
- }
7054
7616
  c2.header("Transfer-Encoding", "chunked");
7055
7617
  return stream(
7056
7618
  c2,
7057
- async (stream5) => {
7619
+ async (stream6) => {
7058
7620
  try {
7059
- const result = await watchWorkflowHandler$1({
7621
+ const result = await streamWorkflowHandler$1({
7060
7622
  mastra,
7061
7623
  workflowId,
7062
- runId
7624
+ runId,
7625
+ inputData,
7626
+ runtimeContext
7063
7627
  });
7064
- const reader = result.getReader();
7065
- stream5.onAbort(() => {
7628
+ const reader = result.stream.getReader();
7629
+ stream6.onAbort(() => {
7066
7630
  void reader.cancel("request aborted");
7067
7631
  });
7068
7632
  let chunkResult;
7069
7633
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
7070
- await stream5.write(JSON.stringify(chunkResult.value) + "");
7634
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
7071
7635
  }
7072
7636
  } catch (err) {
7073
- mastra.getLogger().error("Error in watch stream: " + (err?.message ?? "Unknown error"));
7637
+ logger2.error("Error in workflow stream: " + (err?.message ?? "Unknown error"));
7074
7638
  }
7639
+ await stream6.close();
7075
7640
  },
7076
7641
  async (err) => {
7077
- logger2.error("Error in watch stream: " + err?.message);
7642
+ logger2.error("Error in workflow stream: " + err?.message);
7078
7643
  }
7079
7644
  );
7080
7645
  } catch (error) {
7081
- return handleError(error, "Error watching workflow");
7646
+ return handleError(error, "Error streaming workflow");
7082
7647
  }
7083
7648
  }
7084
- async function streamWorkflowHandler(c2) {
7649
+ async function streamVNextWorkflowHandler(c2) {
7085
7650
  try {
7086
7651
  const mastra = c2.get("mastra");
7087
7652
  const runtimeContext = c2.get("runtimeContext");
@@ -7092,29 +7657,29 @@ async function streamWorkflowHandler(c2) {
7092
7657
  c2.header("Transfer-Encoding", "chunked");
7093
7658
  return stream(
7094
7659
  c2,
7095
- async (stream5) => {
7660
+ async (stream6) => {
7096
7661
  try {
7097
- const result = await streamWorkflowHandler$1({
7662
+ const result = await streamVNextWorkflowHandler$1({
7098
7663
  mastra,
7099
7664
  workflowId,
7100
7665
  runId,
7101
7666
  inputData,
7102
7667
  runtimeContext
7103
7668
  });
7104
- const reader = result.stream.getReader();
7105
- stream5.onAbort(() => {
7669
+ const reader = result.getReader();
7670
+ stream6.onAbort(() => {
7106
7671
  void reader.cancel("request aborted");
7107
7672
  });
7108
7673
  let chunkResult;
7109
7674
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
7110
- await stream5.write(JSON.stringify(chunkResult.value) + "");
7675
+ await stream6.write(JSON.stringify(chunkResult.value) + "");
7111
7676
  }
7112
7677
  } catch (err) {
7113
- console.log(err);
7678
+ logger2.error("Error in workflow VNext stream: " + (err?.message ?? "Unknown error"));
7114
7679
  }
7115
7680
  },
7116
7681
  async (err) => {
7117
- logger2.error("Error in workflow stream: " + err?.message);
7682
+ logger2.error("Error in workflow VNext stream: " + err?.message);
7118
7683
  }
7119
7684
  );
7120
7685
  } catch (error) {
@@ -7247,8 +7812,186 @@ async function sendWorkflowRunEventHandler(c2) {
7247
7812
  return handleError(error, "Error sending workflow run event");
7248
7813
  }
7249
7814
  }
7815
+ async function getLegacyWorkflowsHandler(c2) {
7816
+ try {
7817
+ const mastra = c2.get("mastra");
7818
+ const workflows = await getLegacyWorkflowsHandler$1({
7819
+ mastra
7820
+ });
7821
+ return c2.json(workflows);
7822
+ } catch (error) {
7823
+ return handleError(error, "Error getting workflows");
7824
+ }
7825
+ }
7826
+ async function getLegacyWorkflowByIdHandler(c2) {
7827
+ try {
7828
+ const mastra = c2.get("mastra");
7829
+ const workflowId = c2.req.param("workflowId");
7830
+ const workflow = await getLegacyWorkflowByIdHandler$1({
7831
+ mastra,
7832
+ workflowId
7833
+ });
7834
+ return c2.json(workflow);
7835
+ } catch (error) {
7836
+ return handleError(error, "Error getting workflow");
7837
+ }
7838
+ }
7839
+ async function startAsyncLegacyWorkflowHandler(c2) {
7840
+ try {
7841
+ const mastra = c2.get("mastra");
7842
+ const runtimeContext = c2.get("runtimeContext");
7843
+ const workflowId = c2.req.param("workflowId");
7844
+ const triggerData = await c2.req.json();
7845
+ const runId = c2.req.query("runId");
7846
+ const result = await startAsyncLegacyWorkflowHandler$1({
7847
+ mastra,
7848
+ runtimeContext,
7849
+ workflowId,
7850
+ runId,
7851
+ triggerData
7852
+ });
7853
+ return c2.json(result);
7854
+ } catch (error) {
7855
+ return handleError(error, "Error executing workflow");
7856
+ }
7857
+ }
7858
+ async function createLegacyWorkflowRunHandler(c2) {
7859
+ try {
7860
+ const mastra = c2.get("mastra");
7861
+ const workflowId = c2.req.param("workflowId");
7862
+ const prevRunId = c2.req.query("runId");
7863
+ const result = await createLegacyWorkflowRunHandler$1({
7864
+ mastra,
7865
+ workflowId,
7866
+ runId: prevRunId
7867
+ });
7868
+ return c2.json(result);
7869
+ } catch (e2) {
7870
+ return handleError(e2, "Error creating run");
7871
+ }
7872
+ }
7873
+ async function startLegacyWorkflowRunHandler(c2) {
7874
+ try {
7875
+ const mastra = c2.get("mastra");
7876
+ const runtimeContext = c2.get("runtimeContext");
7877
+ const workflowId = c2.req.param("workflowId");
7878
+ const triggerData = await c2.req.json();
7879
+ const runId = c2.req.query("runId");
7880
+ await startLegacyWorkflowRunHandler$1({
7881
+ mastra,
7882
+ runtimeContext,
7883
+ workflowId,
7884
+ runId,
7885
+ triggerData
7886
+ });
7887
+ return c2.json({ message: "Workflow run started" });
7888
+ } catch (e2) {
7889
+ return handleError(e2, "Error starting workflow run");
7890
+ }
7891
+ }
7892
+ function watchLegacyWorkflowHandler(c2) {
7893
+ try {
7894
+ const mastra = c2.get("mastra");
7895
+ const logger2 = mastra.getLogger();
7896
+ const workflowId = c2.req.param("workflowId");
7897
+ const runId = c2.req.query("runId");
7898
+ if (!runId) {
7899
+ throw new HTTPException(400, { message: "runId required to watch workflow" });
7900
+ }
7901
+ return stream(
7902
+ c2,
7903
+ async (stream6) => {
7904
+ try {
7905
+ const result = await watchLegacyWorkflowHandler$1({
7906
+ mastra,
7907
+ workflowId,
7908
+ runId
7909
+ });
7910
+ stream6.onAbort(() => {
7911
+ if (!result.locked) {
7912
+ return result.cancel();
7913
+ }
7914
+ });
7915
+ for await (const chunk of result) {
7916
+ await stream6.write(chunk.toString() + "");
7917
+ }
7918
+ } catch (err) {
7919
+ console.log(err);
7920
+ }
7921
+ },
7922
+ async (err) => {
7923
+ logger2.error("Error in watch stream: " + err?.message);
7924
+ }
7925
+ );
7926
+ } catch (error) {
7927
+ return handleError(error, "Error watching workflow");
7928
+ }
7929
+ }
7930
+ async function resumeAsyncLegacyWorkflowHandler(c2) {
7931
+ try {
7932
+ const mastra = c2.get("mastra");
7933
+ const runtimeContext = c2.get("runtimeContext");
7934
+ const workflowId = c2.req.param("workflowId");
7935
+ const runId = c2.req.query("runId");
7936
+ const { stepId, context } = await c2.req.json();
7937
+ if (!runId) {
7938
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
7939
+ }
7940
+ const result = await resumeAsyncLegacyWorkflowHandler$1({
7941
+ mastra,
7942
+ runtimeContext,
7943
+ workflowId,
7944
+ runId,
7945
+ body: { stepId, context }
7946
+ });
7947
+ return c2.json(result);
7948
+ } catch (error) {
7949
+ return handleError(error, "Error resuming workflow step");
7950
+ }
7951
+ }
7952
+ async function resumeLegacyWorkflowHandler(c2) {
7953
+ try {
7954
+ const mastra = c2.get("mastra");
7955
+ const runtimeContext = c2.get("runtimeContext");
7956
+ const workflowId = c2.req.param("workflowId");
7957
+ const runId = c2.req.query("runId");
7958
+ const { stepId, context } = await c2.req.json();
7959
+ if (!runId) {
7960
+ throw new HTTPException(400, { message: "runId required to resume workflow" });
7961
+ }
7962
+ await resumeLegacyWorkflowHandler$1({
7963
+ mastra,
7964
+ runtimeContext,
7965
+ workflowId,
7966
+ runId,
7967
+ body: { stepId, context }
7968
+ });
7969
+ return c2.json({ message: "Workflow run resumed" });
7970
+ } catch (error) {
7971
+ return handleError(error, "Error resuming workflow");
7972
+ }
7973
+ }
7974
+ async function getLegacyWorkflowRunsHandler(c2) {
7975
+ try {
7976
+ const mastra = c2.get("mastra");
7977
+ const workflowId = c2.req.param("workflowId");
7978
+ const { fromDate, toDate, limit, offset, resourceId } = c2.req.query();
7979
+ const workflowRuns = await getLegacyWorkflowRunsHandler$1({
7980
+ mastra,
7981
+ workflowId,
7982
+ fromDate: fromDate ? new Date(fromDate) : void 0,
7983
+ toDate: toDate ? new Date(toDate) : void 0,
7984
+ limit: limit ? Number(limit) : void 0,
7985
+ offset: offset ? Number(offset) : void 0,
7986
+ resourceId
7987
+ });
7988
+ return c2.json(workflowRuns);
7989
+ } catch (error) {
7990
+ return handleError(error, "Error getting workflow runs");
7991
+ }
7992
+ }
7250
7993
 
7251
- // src/server/handlers/routes/workflows.ts
7994
+ // src/server/handlers/routes/workflows/router.ts
7252
7995
  function workflowsRouter(bodyLimitOptions) {
7253
7996
  const router = new Hono();
7254
7997
  router.get(
@@ -7785,6 +8528,53 @@ function workflowsRouter(bodyLimitOptions) {
7785
8528
  }),
7786
8529
  streamWorkflowHandler
7787
8530
  );
8531
+ router.post(
8532
+ "/:workflowId/streamVNext",
8533
+ w({
8534
+ description: "Stream workflow in real-time using the VNext streaming API",
8535
+ parameters: [
8536
+ {
8537
+ name: "workflowId",
8538
+ in: "path",
8539
+ required: true,
8540
+ schema: { type: "string" }
8541
+ },
8542
+ {
8543
+ name: "runId",
8544
+ in: "query",
8545
+ required: false,
8546
+ schema: { type: "string" }
8547
+ }
8548
+ ],
8549
+ requestBody: {
8550
+ required: true,
8551
+ content: {
8552
+ "application/json": {
8553
+ schema: {
8554
+ type: "object",
8555
+ properties: {
8556
+ inputData: { type: "object" },
8557
+ runtimeContext: {
8558
+ type: "object",
8559
+ description: "Runtime context for the workflow execution"
8560
+ }
8561
+ }
8562
+ }
8563
+ }
8564
+ }
8565
+ },
8566
+ responses: {
8567
+ 200: {
8568
+ description: "workflow run started"
8569
+ },
8570
+ 404: {
8571
+ description: "workflow not found"
8572
+ }
8573
+ },
8574
+ tags: ["workflows"]
8575
+ }),
8576
+ streamVNextWorkflowHandler
8577
+ );
7788
8578
  router.post(
7789
8579
  "/:workflowId/create-run",
7790
8580
  bodyLimit(bodyLimitOptions),
@@ -8108,13 +8898,9 @@ var html2 = `
8108
8898
  `;
8109
8899
 
8110
8900
  // src/server/index.ts
8111
- async function createHonoServer(mastra, options = {}) {
8112
- const app = new Hono();
8113
- const server = mastra.getServer();
8114
- let tools = {};
8901
+ function getToolExports(tools) {
8115
8902
  try {
8116
- const toolImports = (await import('#tools')).tools;
8117
- tools = toolImports.reduce((acc, toolModule) => {
8903
+ return tools.reduce((acc, toolModule) => {
8118
8904
  Object.entries(toolModule).forEach(([key, tool]) => {
8119
8905
  if (tool instanceof Tool) {
8120
8906
  acc[key] = tool;
@@ -8131,6 +8917,12 @@ ${err.stack.split("\n").slice(1).join("\n")}
8131
8917
  err
8132
8918
  );
8133
8919
  }
8920
+ }
8921
+ async function createHonoServer(mastra, options = {
8922
+ tools: {}
8923
+ }) {
8924
+ const app = new Hono();
8925
+ const server = mastra.getServer();
8134
8926
  app.use("*", async function setTelemetryInfo(c2, next) {
8135
8927
  const requestId = c2.req.header("x-request-id") ?? randomUUID();
8136
8928
  const span = Telemetry.getActiveSpan();
@@ -8168,7 +8960,7 @@ ${err.stack.split("\n").slice(1).join("\n")}
8168
8960
  }
8169
8961
  c2.set("runtimeContext", runtimeContext);
8170
8962
  c2.set("mastra", mastra);
8171
- c2.set("tools", tools);
8963
+ c2.set("tools", options.tools);
8172
8964
  c2.set("playground", options.playground === true);
8173
8965
  c2.set("isDev", options.isDev === true);
8174
8966
  return next();
@@ -8402,7 +9194,8 @@ ${err.stack.split("\n").slice(1).join("\n")}
8402
9194
  app.route("/api/telemetry", telemetryRouter());
8403
9195
  app.route("/api/workflows", workflowsRouter(bodyLimitOptions));
8404
9196
  app.route("/api/logs", logsRouter());
8405
- app.route("/api/tools", toolsRouter(bodyLimitOptions, tools));
9197
+ app.route("/api/scores", scoresRouter(bodyLimitOptions));
9198
+ app.route("/api/tools", toolsRouter(bodyLimitOptions, options.tools));
8406
9199
  app.route("/api/vector", vectorRouter(bodyLimitOptions));
8407
9200
  if (options?.isDev || server?.build?.openAPIDocs || server?.build?.swaggerUI) {
8408
9201
  app.get(
@@ -8477,7 +9270,7 @@ ${err.stack.split("\n").slice(1).join("\n")}
8477
9270
  });
8478
9271
  return app;
8479
9272
  }
8480
- async function createNodeServer(mastra, options = {}) {
9273
+ async function createNodeServer(mastra, options = { tools: {} }) {
8481
9274
  const app = await createHonoServer(mastra, options);
8482
9275
  const serverOptions = mastra.getServer();
8483
9276
  const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
@@ -8507,4 +9300,4 @@ async function createNodeServer(mastra, options = {}) {
8507
9300
  return server;
8508
9301
  }
8509
9302
 
8510
- export { createHonoServer, createNodeServer };
9303
+ export { createHonoServer, createNodeServer, getToolExports };