@mastra/deployer 0.15.3-alpha.2 → 0.15.3-alpha.4

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 (84) hide show
  1. package/dist/build/__fixtures__/no-bundler.d.ts +1 -1
  2. package/dist/build/__fixtures__/no-bundler.d.ts.map +1 -1
  3. package/dist/build/__fixtures__/no-server.d.ts +1 -1
  4. package/dist/build/__fixtures__/no-server.d.ts.map +1 -1
  5. package/dist/build/__fixtures__/no-telemetry.d.ts +1 -1
  6. package/dist/build/__fixtures__/no-telemetry.d.ts.map +1 -1
  7. package/dist/build/analyze.cjs +3 -3
  8. package/dist/build/analyze.js +1 -1
  9. package/dist/build/bundler.cjs +3 -3
  10. package/dist/build/bundler.js +1 -1
  11. package/dist/build/index.cjs +15 -15
  12. package/dist/build/index.js +5 -5
  13. package/dist/build/plugins/__fixtures__/basic-with-bundler.d.ts +1 -1
  14. package/dist/build/plugins/__fixtures__/basic-with-bundler.d.ts.map +1 -1
  15. package/dist/build/plugins/__fixtures__/basic-with-const.d.ts +1 -1
  16. package/dist/build/plugins/__fixtures__/basic-with-const.d.ts.map +1 -1
  17. package/dist/build/plugins/__fixtures__/basic-with-function.d.ts +1 -1
  18. package/dist/build/plugins/__fixtures__/basic-with-function.d.ts.map +1 -1
  19. package/dist/build/plugins/__fixtures__/basic-with-import.d.ts +1 -1
  20. package/dist/build/plugins/__fixtures__/basic-with-import.d.ts.map +1 -1
  21. package/dist/build/plugins/__fixtures__/basic-with-json.d.ts +1 -1
  22. package/dist/build/plugins/__fixtures__/basic-with-json.d.ts.map +1 -1
  23. package/dist/build/plugins/__fixtures__/basic.d.ts +1 -1
  24. package/dist/build/plugins/__fixtures__/basic.d.ts.map +1 -1
  25. package/dist/build/plugins/__fixtures__/empty-mastra.d.ts +1 -1
  26. package/dist/build/plugins/__fixtures__/empty-mastra.d.ts.map +1 -1
  27. package/dist/build/plugins/__fixtures__/mastra-with-extra-code.d.ts +1 -1
  28. package/dist/build/plugins/__fixtures__/mastra-with-extra-code.d.ts.map +1 -1
  29. package/dist/bundler/index.cjs +2 -2
  30. package/dist/bundler/index.js +1 -1
  31. package/dist/{chunk-YSFTC4AH.js → chunk-2GPZM6PP.js} +7 -7
  32. package/dist/{chunk-YSFTC4AH.js.map → chunk-2GPZM6PP.js.map} +1 -1
  33. package/dist/{chunk-X54LEGAC.cjs → chunk-AM2S5WCK.cjs} +30 -19
  34. package/dist/chunk-AM2S5WCK.cjs.map +1 -0
  35. package/dist/{chunk-GPGRGCTW.js → chunk-DG6YR6QC.js} +28 -17
  36. package/dist/chunk-DG6YR6QC.js.map +1 -0
  37. package/dist/{chunk-FXJQRVOQ.cjs → chunk-FOPPWICF.cjs} +21 -21
  38. package/dist/{chunk-FXJQRVOQ.cjs.map → chunk-FOPPWICF.cjs.map} +1 -1
  39. package/dist/{chunk-OXFTV5D2.cjs → chunk-HFSNFLSA.cjs} +7 -7
  40. package/dist/{chunk-OXFTV5D2.cjs.map → chunk-HFSNFLSA.cjs.map} +1 -1
  41. package/dist/{chunk-656BANCN.js → chunk-HUAOVISC.js} +4 -4
  42. package/dist/{chunk-656BANCN.js.map → chunk-HUAOVISC.js.map} +1 -1
  43. package/dist/{chunk-NOI4CTSN.js → chunk-IKIYTFYW.js} +3 -3
  44. package/dist/chunk-IKIYTFYW.js.map +1 -0
  45. package/dist/{chunk-ETHVQE5F.js → chunk-IVGJKJCG.js} +5 -5
  46. package/dist/{chunk-ETHVQE5F.js.map → chunk-IVGJKJCG.js.map} +1 -1
  47. package/dist/{chunk-QXZRRU7Y.cjs → chunk-KVBYKVQQ.cjs} +15 -15
  48. package/dist/{chunk-QXZRRU7Y.cjs.map → chunk-KVBYKVQQ.cjs.map} +1 -1
  49. package/dist/{chunk-3NMAUV2K.js → chunk-LQCSOGOC.js} +4 -4
  50. package/dist/{chunk-3NMAUV2K.js.map → chunk-LQCSOGOC.js.map} +1 -1
  51. package/dist/{chunk-LG5W6D2R.cjs → chunk-NK2IP3RO.cjs} +3 -3
  52. package/dist/chunk-NK2IP3RO.cjs.map +1 -0
  53. package/dist/{chunk-IPCTGBLD.js → chunk-U4ZNNX34.js} +3 -3
  54. package/dist/{chunk-IPCTGBLD.js.map → chunk-U4ZNNX34.js.map} +1 -1
  55. package/dist/{chunk-NBXPDOUR.cjs → chunk-WHMSFLP7.cjs} +5 -5
  56. package/dist/{chunk-NBXPDOUR.cjs.map → chunk-WHMSFLP7.cjs.map} +1 -1
  57. package/dist/{chunk-K5ES6Z7D.cjs → chunk-WSYCRXET.cjs} +13 -13
  58. package/dist/{chunk-K5ES6Z7D.cjs.map → chunk-WSYCRXET.cjs.map} +1 -1
  59. package/dist/index.cjs +12 -12
  60. package/dist/index.js +4 -4
  61. package/dist/server/handlers/routes/agent-builder/handlers.d.ts +17 -0
  62. package/dist/server/handlers/routes/agent-builder/handlers.d.ts.map +1 -0
  63. package/dist/server/handlers/routes/agent-builder/router.d.ts +4 -0
  64. package/dist/server/handlers/routes/agent-builder/router.d.ts.map +1 -0
  65. package/dist/server/handlers/routes/agents/handlers.d.ts +2 -0
  66. package/dist/server/handlers/routes/agents/handlers.d.ts.map +1 -1
  67. package/dist/server/handlers/routes/agents/router.d.ts.map +1 -1
  68. package/dist/server/handlers/routes/tools/handlers.d.ts +1 -0
  69. package/dist/server/handlers/routes/tools/handlers.d.ts.map +1 -1
  70. package/dist/server/index.cjs +1145 -111
  71. package/dist/server/index.cjs.map +1 -1
  72. package/dist/server/index.d.ts.map +1 -1
  73. package/dist/server/index.js +1074 -40
  74. package/dist/server/index.js.map +1 -1
  75. package/dist/services/deps.d.ts +5 -0
  76. package/dist/services/deps.d.ts.map +1 -1
  77. package/dist/services/index.cjs +4 -4
  78. package/dist/services/index.js +1 -1
  79. package/dist/templates/instrumentation-template.js +11 -1
  80. package/package.json +6 -6
  81. package/dist/chunk-GPGRGCTW.js.map +0 -1
  82. package/dist/chunk-LG5W6D2R.cjs.map +0 -1
  83. package/dist/chunk-NOI4CTSN.js.map +0 -1
  84. package/dist/chunk-X54LEGAC.cjs.map +0 -1
@@ -21,8 +21,9 @@ var timeout = require('hono/timeout');
21
21
  var httpException = require('hono/http-exception');
22
22
  var a2a = require('@mastra/server/handlers/a2a');
23
23
  var streaming = require('hono/streaming');
24
- var agents = require('@mastra/server/handlers/agents');
25
24
  var bodyLimit = require('hono/body-limit');
25
+ var agentBuilder = require('@mastra/server/handlers/agent-builder');
26
+ var agents = require('@mastra/server/handlers/agents');
26
27
  var agent = require('@mastra/core/agent');
27
28
  var zod = require('zod');
28
29
  var tools$1 = require('@mastra/server/handlers/tools');
@@ -287,13 +288,13 @@ var Response2 = class _Response {
287
288
  });
288
289
  Object.setPrototypeOf(Response2, GlobalResponse);
289
290
  Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
290
- function writeFromReadableStream(stream6, writable) {
291
- if (stream6.locked) {
291
+ function writeFromReadableStream(stream7, writable) {
292
+ if (stream7.locked) {
292
293
  throw new TypeError("ReadableStream is locked.");
293
294
  } else if (writable.destroyed) {
294
295
  return;
295
296
  }
296
- const reader = stream6.getReader();
297
+ const reader = stream7.getReader();
297
298
  const handleError2 = () => {
298
299
  };
299
300
  writable.on("error", handleError2);
@@ -560,18 +561,18 @@ var ENCODINGS = {
560
561
  gzip: ".gz"
561
562
  };
562
563
  var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
563
- var createStreamBody = (stream6) => {
564
+ var createStreamBody = (stream7) => {
564
565
  const body = new ReadableStream({
565
566
  start(controller) {
566
- stream6.on("data", (chunk) => {
567
+ stream7.on("data", (chunk) => {
567
568
  controller.enqueue(chunk);
568
569
  });
569
- stream6.on("end", () => {
570
+ stream7.on("end", () => {
570
571
  controller.close();
571
572
  });
572
573
  },
573
574
  cancel() {
574
- stream6.destroy();
575
+ stream7.destroy();
575
576
  }
576
577
  });
577
578
  return body;
@@ -660,10 +661,10 @@ var serveStatic = (options = { root: "" }) => {
660
661
  end = size - 1;
661
662
  }
662
663
  const chunksize = end - start + 1;
663
- const stream6 = fs.createReadStream(path$1, { start, end });
664
+ const stream7 = fs.createReadStream(path$1, { start, end });
664
665
  c2.header("Content-Length", chunksize.toString());
665
666
  c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
666
- return c2.body(createStreamBody(stream6), 206);
667
+ return c2.body(createStreamBody(stream7), 206);
667
668
  };
668
669
  };
669
670
  var RENDER_TYPE = {
@@ -961,15 +962,15 @@ async function getAgentExecutionHandler(c2) {
961
962
  if (body.method === "message/stream") {
962
963
  return streaming.stream(
963
964
  c2,
964
- async (stream6) => {
965
+ async (stream7) => {
965
966
  try {
966
- stream6.onAbort(() => {
967
+ stream7.onAbort(() => {
967
968
  if (!result.locked) {
968
969
  return result.cancel();
969
970
  }
970
971
  });
971
972
  for await (const chunk of result) {
972
- await stream6.write(JSON.stringify(chunk) + "");
973
+ await stream7.write(JSON.stringify(chunk) + "");
973
974
  }
974
975
  } catch (err) {
975
976
  logger2.error("Error in message/stream stream: " + err?.message);
@@ -1169,80 +1170,927 @@ var authorizationMiddleware = async (c2, next) => {
1169
1170
  if (isAuthorized) {
1170
1171
  return next();
1171
1172
  }
1172
- return c2.json({ error: "Access denied" }, 403);
1173
- } catch (err) {
1174
- console.error(err);
1175
- return c2.json({ error: "Authorization error" }, 500);
1176
- }
1177
- }
1178
- if ("rules" in authConfig && authConfig.rules && authConfig.rules.length > 0) {
1179
- const isAuthorized = await checkRules(authConfig.rules, path, method, user);
1180
- if (isAuthorized) {
1181
- return next();
1182
- }
1183
- return c2.json({ error: "Access denied" }, 403);
1184
- }
1185
- if (defaultAuthConfig.rules && defaultAuthConfig.rules.length > 0) {
1186
- const isAuthorized = await checkRules(defaultAuthConfig.rules, path, method, user);
1187
- if (isAuthorized) {
1188
- return next();
1189
- }
1190
- }
1191
- return c2.json({ error: "Access denied" }, 403);
1192
- };
1193
-
1194
- // src/server/handlers/client.ts
1195
- var clients = /* @__PURE__ */ new Set();
1196
- function handleClientsRefresh(c2) {
1197
- const stream6 = new ReadableStream({
1198
- start(controller) {
1199
- clients.add(controller);
1200
- controller.enqueue("data: connected\n\n");
1201
- c2.req.raw.signal.addEventListener("abort", () => {
1202
- clients.delete(controller);
1203
- });
1204
- }
1205
- });
1206
- return new Response(stream6, {
1207
- headers: {
1208
- "Content-Type": "text/event-stream",
1209
- "Cache-Control": "no-cache",
1210
- Connection: "keep-alive",
1211
- "Access-Control-Allow-Origin": "*"
1212
- }
1213
- });
1214
- }
1215
- function handleTriggerClientsRefresh(c2) {
1216
- clients.forEach((controller) => {
1217
- try {
1218
- controller.enqueue("data: refresh\n\n");
1219
- } catch {
1220
- clients.delete(controller);
1221
- }
1222
- });
1223
- return c2.json({ success: true, clients: clients.size });
1224
- }
1225
- function handleError(error, defaultMessage) {
1226
- const apiError = error;
1227
- throw new httpException.HTTPException(apiError.status || 500, {
1228
- message: apiError.message || defaultMessage,
1229
- cause: apiError.cause
1230
- });
1231
- }
1232
- function errorHandler(err, c2, isDev) {
1233
- if (err instanceof httpException.HTTPException) {
1234
- if (isDev) {
1235
- return c2.json({ error: err.message, cause: err.cause, stack: err.stack }, err.status);
1236
- }
1237
- return c2.json({ error: err.message }, err.status);
1238
- }
1239
- console.error(err);
1240
- return c2.json({ error: "Internal Server Error" }, 500);
1241
- }
1242
-
1243
- // src/server/handlers/root.ts
1244
- async function rootHandler(c2) {
1245
- return c2.text("Hello to the Mastra API!");
1173
+ return c2.json({ error: "Access denied" }, 403);
1174
+ } catch (err) {
1175
+ console.error(err);
1176
+ return c2.json({ error: "Authorization error" }, 500);
1177
+ }
1178
+ }
1179
+ if ("rules" in authConfig && authConfig.rules && authConfig.rules.length > 0) {
1180
+ const isAuthorized = await checkRules(authConfig.rules, path, method, user);
1181
+ if (isAuthorized) {
1182
+ return next();
1183
+ }
1184
+ return c2.json({ error: "Access denied" }, 403);
1185
+ }
1186
+ if (defaultAuthConfig.rules && defaultAuthConfig.rules.length > 0) {
1187
+ const isAuthorized = await checkRules(defaultAuthConfig.rules, path, method, user);
1188
+ if (isAuthorized) {
1189
+ return next();
1190
+ }
1191
+ }
1192
+ return c2.json({ error: "Access denied" }, 403);
1193
+ };
1194
+
1195
+ // src/server/handlers/client.ts
1196
+ var clients = /* @__PURE__ */ new Set();
1197
+ function handleClientsRefresh(c2) {
1198
+ const stream7 = new ReadableStream({
1199
+ start(controller) {
1200
+ clients.add(controller);
1201
+ controller.enqueue("data: connected\n\n");
1202
+ c2.req.raw.signal.addEventListener("abort", () => {
1203
+ clients.delete(controller);
1204
+ });
1205
+ }
1206
+ });
1207
+ return new Response(stream7, {
1208
+ headers: {
1209
+ "Content-Type": "text/event-stream",
1210
+ "Cache-Control": "no-cache",
1211
+ Connection: "keep-alive",
1212
+ "Access-Control-Allow-Origin": "*"
1213
+ }
1214
+ });
1215
+ }
1216
+ function handleTriggerClientsRefresh(c2) {
1217
+ clients.forEach((controller) => {
1218
+ try {
1219
+ controller.enqueue("data: refresh\n\n");
1220
+ } catch {
1221
+ clients.delete(controller);
1222
+ }
1223
+ });
1224
+ return c2.json({ success: true, clients: clients.size });
1225
+ }
1226
+ function handleError(error, defaultMessage) {
1227
+ const apiError = error;
1228
+ throw new httpException.HTTPException(apiError.status || 500, {
1229
+ message: apiError.message || defaultMessage,
1230
+ cause: apiError.cause
1231
+ });
1232
+ }
1233
+ function errorHandler(err, c2, isDev) {
1234
+ if (err instanceof httpException.HTTPException) {
1235
+ if (isDev) {
1236
+ return c2.json({ error: err.message, cause: err.cause, stack: err.stack }, err.status);
1237
+ }
1238
+ return c2.json({ error: err.message }, err.status);
1239
+ }
1240
+ console.error(err);
1241
+ return c2.json({ error: "Internal Server Error" }, 500);
1242
+ }
1243
+
1244
+ // src/server/handlers/root.ts
1245
+ async function rootHandler(c2) {
1246
+ return c2.text("Hello to the Mastra API!");
1247
+ }
1248
+ async function getAgentBuilderActionsHandler(c2) {
1249
+ try {
1250
+ const mastra = c2.get("mastra");
1251
+ const actions = await agentBuilder.getAgentBuilderActionsHandler({
1252
+ mastra
1253
+ });
1254
+ return c2.json(actions);
1255
+ } catch (error) {
1256
+ return handleError(error, "Error getting agent builder actions");
1257
+ }
1258
+ }
1259
+ async function getAgentBuilderActionByIdHandler(c2) {
1260
+ try {
1261
+ const mastra = c2.get("mastra");
1262
+ const actionId = c2.req.param("actionId");
1263
+ const action = await agentBuilder.getAgentBuilderActionByIdHandler({
1264
+ mastra,
1265
+ actionId
1266
+ });
1267
+ return c2.json(action);
1268
+ } catch (error) {
1269
+ return handleError(error, "Error getting agent builder action by ID");
1270
+ }
1271
+ }
1272
+ async function createAgentBuilderActionRunHandler(c2) {
1273
+ try {
1274
+ const mastra = c2.get("mastra");
1275
+ const actionId = c2.req.param("actionId");
1276
+ const runId = c2.req.query("runId");
1277
+ const result = await agentBuilder.createAgentBuilderActionRunHandler({
1278
+ mastra,
1279
+ actionId,
1280
+ runId
1281
+ });
1282
+ return c2.json(result);
1283
+ } catch (error) {
1284
+ return handleError(error, "Error creating agent builder action run");
1285
+ }
1286
+ }
1287
+ async function startAsyncAgentBuilderActionHandler(c2) {
1288
+ try {
1289
+ const mastra = c2.get("mastra");
1290
+ const runtimeContext = c2.get("runtimeContext");
1291
+ const actionId = c2.req.param("actionId");
1292
+ const { inputData } = await c2.req.json();
1293
+ const runId = c2.req.query("runId");
1294
+ const result = await agentBuilder.startAsyncAgentBuilderActionHandler({
1295
+ mastra,
1296
+ runtimeContext,
1297
+ actionId,
1298
+ runId,
1299
+ inputData
1300
+ });
1301
+ return c2.json(result);
1302
+ } catch (error) {
1303
+ return handleError(error, "Error starting async agent builder action");
1304
+ }
1305
+ }
1306
+ async function startAgentBuilderActionRunHandler(c2) {
1307
+ try {
1308
+ const mastra = c2.get("mastra");
1309
+ const runtimeContext = c2.get("runtimeContext");
1310
+ const actionId = c2.req.param("actionId");
1311
+ const { inputData } = await c2.req.json();
1312
+ const runId = c2.req.query("runId");
1313
+ const result = await agentBuilder.startAgentBuilderActionRunHandler({
1314
+ mastra,
1315
+ runtimeContext,
1316
+ actionId,
1317
+ runId,
1318
+ inputData
1319
+ });
1320
+ return c2.json(result);
1321
+ } catch (error) {
1322
+ return handleError(error, "Error starting agent builder action run");
1323
+ }
1324
+ }
1325
+ async function watchAgentBuilderActionHandler(c2) {
1326
+ try {
1327
+ const mastra = c2.get("mastra");
1328
+ const logger2 = mastra.getLogger();
1329
+ const actionId = c2.req.param("actionId");
1330
+ const runId = c2.req.query("runId");
1331
+ const eventType = c2.req.query("eventType");
1332
+ if (!runId) {
1333
+ throw new httpException.HTTPException(400, { message: "runId required to watch action" });
1334
+ }
1335
+ c2.header("Transfer-Encoding", "chunked");
1336
+ return streaming.stream(c2, async (stream7) => {
1337
+ try {
1338
+ const result = await agentBuilder.watchAgentBuilderActionHandler({
1339
+ mastra,
1340
+ actionId,
1341
+ runId,
1342
+ eventType
1343
+ });
1344
+ const reader = result.getReader();
1345
+ stream7.onAbort(() => {
1346
+ void reader.cancel("request aborted");
1347
+ });
1348
+ let chunkResult;
1349
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
1350
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
1351
+ }
1352
+ } catch (err) {
1353
+ logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
1354
+ }
1355
+ });
1356
+ } catch (error) {
1357
+ return handleError(error, "Error watching agent builder action");
1358
+ }
1359
+ }
1360
+ async function streamAgentBuilderActionHandler(c2) {
1361
+ try {
1362
+ const mastra = c2.get("mastra");
1363
+ const runtimeContext = c2.get("runtimeContext");
1364
+ const logger2 = mastra.getLogger();
1365
+ const actionId = c2.req.param("actionId");
1366
+ const { inputData } = await c2.req.json();
1367
+ const runId = c2.req.query("runId");
1368
+ c2.header("Transfer-Encoding", "chunked");
1369
+ return streaming.stream(
1370
+ c2,
1371
+ async (stream7) => {
1372
+ try {
1373
+ const result = await agentBuilder.streamAgentBuilderActionHandler({
1374
+ mastra,
1375
+ actionId,
1376
+ runId,
1377
+ inputData,
1378
+ runtimeContext
1379
+ });
1380
+ const reader = result.stream.getReader();
1381
+ stream7.onAbort(() => {
1382
+ void reader.cancel("request aborted");
1383
+ });
1384
+ let chunkResult;
1385
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
1386
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
1387
+ }
1388
+ } catch (err) {
1389
+ logger2.error("Error in action stream: " + (err?.message ?? "Unknown error"));
1390
+ }
1391
+ await stream7.close();
1392
+ },
1393
+ async (err) => {
1394
+ logger2.error("Error in action stream: " + err?.message);
1395
+ }
1396
+ );
1397
+ } catch (error) {
1398
+ return handleError(error, "Error streaming agent builder action");
1399
+ }
1400
+ }
1401
+ async function streamVNextAgentBuilderActionHandler(c2) {
1402
+ try {
1403
+ const mastra = c2.get("mastra");
1404
+ const runtimeContext = c2.get("runtimeContext");
1405
+ const logger2 = mastra.getLogger();
1406
+ const actionId = c2.req.param("actionId");
1407
+ const { inputData } = await c2.req.json();
1408
+ const runId = c2.req.query("runId");
1409
+ c2.header("Transfer-Encoding", "chunked");
1410
+ return streaming.stream(
1411
+ c2,
1412
+ async (stream7) => {
1413
+ try {
1414
+ const result = await agentBuilder.streamVNextAgentBuilderActionHandler({
1415
+ mastra,
1416
+ actionId,
1417
+ runId,
1418
+ inputData,
1419
+ runtimeContext
1420
+ });
1421
+ const reader = result.getReader();
1422
+ stream7.onAbort(() => {
1423
+ void reader.cancel("request aborted");
1424
+ });
1425
+ let chunkResult;
1426
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
1427
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
1428
+ }
1429
+ } catch (err) {
1430
+ logger2.error("Error in action VNext stream: " + (err?.message ?? "Unknown error"));
1431
+ }
1432
+ },
1433
+ async (err) => {
1434
+ logger2.error("Error in action VNext stream: " + err?.message);
1435
+ }
1436
+ );
1437
+ } catch (error) {
1438
+ return handleError(error, "Error streaming VNext agent builder action");
1439
+ }
1440
+ }
1441
+ async function resumeAsyncAgentBuilderActionHandler(c2) {
1442
+ try {
1443
+ const mastra = c2.get("mastra");
1444
+ const runtimeContext = c2.get("runtimeContext");
1445
+ const actionId = c2.req.param("actionId");
1446
+ const runId = c2.req.query("runId");
1447
+ const { step, resumeData } = await c2.req.json();
1448
+ if (!runId) {
1449
+ throw new httpException.HTTPException(400, { message: "runId required to resume action" });
1450
+ }
1451
+ const result = await agentBuilder.resumeAsyncAgentBuilderActionHandler({
1452
+ mastra,
1453
+ runtimeContext,
1454
+ actionId,
1455
+ runId,
1456
+ body: { step, resumeData }
1457
+ });
1458
+ return c2.json(result);
1459
+ } catch (error) {
1460
+ return handleError(error, "Error resuming async agent builder action");
1461
+ }
1462
+ }
1463
+ async function resumeAgentBuilderActionHandler(c2) {
1464
+ try {
1465
+ const mastra = c2.get("mastra");
1466
+ const runtimeContext = c2.get("runtimeContext");
1467
+ const actionId = c2.req.param("actionId");
1468
+ const runId = c2.req.query("runId");
1469
+ const { step, resumeData } = await c2.req.json();
1470
+ if (!runId) {
1471
+ throw new httpException.HTTPException(400, { message: "runId required to resume action" });
1472
+ }
1473
+ await agentBuilder.resumeAgentBuilderActionHandler({
1474
+ mastra,
1475
+ runtimeContext,
1476
+ actionId,
1477
+ runId,
1478
+ body: { step, resumeData }
1479
+ });
1480
+ return c2.json({ message: "Action run resumed" });
1481
+ } catch (error) {
1482
+ return handleError(error, "Error resuming agent builder action");
1483
+ }
1484
+ }
1485
+ async function getAgentBuilderActionRunsHandler(c2) {
1486
+ try {
1487
+ const mastra = c2.get("mastra");
1488
+ const actionId = c2.req.param("actionId");
1489
+ const { fromDate, toDate, limit, offset, resourceId } = c2.req.query();
1490
+ const runs = await agentBuilder.getAgentBuilderActionRunsHandler({
1491
+ mastra,
1492
+ actionId,
1493
+ fromDate: fromDate ? new Date(fromDate) : void 0,
1494
+ toDate: toDate ? new Date(toDate) : void 0,
1495
+ limit: limit ? Number(limit) : void 0,
1496
+ offset: offset ? Number(offset) : void 0,
1497
+ resourceId
1498
+ });
1499
+ return c2.json(runs);
1500
+ } catch (error) {
1501
+ return handleError(error, "Error getting agent builder action runs");
1502
+ }
1503
+ }
1504
+ async function getAgentBuilderActionRunByIdHandler(c2) {
1505
+ try {
1506
+ const mastra = c2.get("mastra");
1507
+ const actionId = c2.req.param("actionId");
1508
+ const runId = c2.req.param("runId");
1509
+ const run = await agentBuilder.getAgentBuilderActionRunByIdHandler({
1510
+ mastra,
1511
+ actionId,
1512
+ runId
1513
+ });
1514
+ return c2.json(run);
1515
+ } catch (error) {
1516
+ return handleError(error, "Error getting agent builder action run by ID");
1517
+ }
1518
+ }
1519
+ async function getAgentBuilderActionRunExecutionResultHandler(c2) {
1520
+ try {
1521
+ const mastra = c2.get("mastra");
1522
+ const actionId = c2.req.param("actionId");
1523
+ const runId = c2.req.param("runId");
1524
+ const result = await agentBuilder.getAgentBuilderActionRunExecutionResultHandler({
1525
+ mastra,
1526
+ actionId,
1527
+ runId
1528
+ });
1529
+ return c2.json(result);
1530
+ } catch (error) {
1531
+ return handleError(error, "Error getting agent builder action run execution result");
1532
+ }
1533
+ }
1534
+ async function cancelAgentBuilderActionRunHandler(c2) {
1535
+ try {
1536
+ const mastra = c2.get("mastra");
1537
+ const actionId = c2.req.param("actionId");
1538
+ const runId = c2.req.param("runId");
1539
+ const result = await agentBuilder.cancelAgentBuilderActionRunHandler({
1540
+ mastra,
1541
+ actionId,
1542
+ runId
1543
+ });
1544
+ return c2.json(result);
1545
+ } catch (error) {
1546
+ return handleError(error, "Error cancelling agent builder action run");
1547
+ }
1548
+ }
1549
+ async function sendAgentBuilderActionRunEventHandler(c2) {
1550
+ try {
1551
+ const mastra = c2.get("mastra");
1552
+ const actionId = c2.req.param("actionId");
1553
+ const runId = c2.req.param("runId");
1554
+ const { event, data } = await c2.req.json();
1555
+ const result = await agentBuilder.sendAgentBuilderActionRunEventHandler({
1556
+ mastra,
1557
+ actionId,
1558
+ runId,
1559
+ event,
1560
+ data
1561
+ });
1562
+ return c2.json(result);
1563
+ } catch (error) {
1564
+ return handleError(error, "Error sending agent builder action run event");
1565
+ }
1566
+ }
1567
+
1568
+ // src/server/handlers/routes/agent-builder/router.ts
1569
+ function agentBuilderRouter(bodyLimitOptions) {
1570
+ const router = new hono.Hono();
1571
+ router.get(
1572
+ "/",
1573
+ w({
1574
+ description: "Get all agent builder actions",
1575
+ tags: ["agent-builder"],
1576
+ responses: {
1577
+ 200: {
1578
+ description: "List of all agent builder actions"
1579
+ }
1580
+ }
1581
+ }),
1582
+ getAgentBuilderActionsHandler
1583
+ );
1584
+ router.get(
1585
+ "/:actionId",
1586
+ w({
1587
+ description: "Get agent builder action by ID",
1588
+ tags: ["agent-builder"],
1589
+ parameters: [
1590
+ {
1591
+ name: "actionId",
1592
+ in: "path",
1593
+ required: true,
1594
+ schema: { type: "string" }
1595
+ }
1596
+ ],
1597
+ responses: {
1598
+ 200: {
1599
+ description: "Agent builder action details"
1600
+ },
1601
+ 404: {
1602
+ description: "Agent builder action not found"
1603
+ }
1604
+ }
1605
+ }),
1606
+ getAgentBuilderActionByIdHandler
1607
+ );
1608
+ router.get(
1609
+ "/:actionId/runs",
1610
+ w({
1611
+ description: "Get all runs for an agent builder action",
1612
+ tags: ["agent-builder"],
1613
+ parameters: [
1614
+ {
1615
+ name: "actionId",
1616
+ in: "path",
1617
+ required: true,
1618
+ schema: { type: "string" }
1619
+ },
1620
+ { name: "fromDate", in: "query", required: false, schema: { type: "string", format: "date-time" } },
1621
+ { name: "toDate", in: "query", required: false, schema: { type: "string", format: "date-time" } },
1622
+ { name: "limit", in: "query", required: false, schema: { type: "number" } },
1623
+ { name: "offset", in: "query", required: false, schema: { type: "number" } },
1624
+ { name: "resourceId", in: "query", required: false, schema: { type: "string" } }
1625
+ ],
1626
+ responses: {
1627
+ 200: {
1628
+ description: "List of agent builder action runs from storage"
1629
+ }
1630
+ }
1631
+ }),
1632
+ getAgentBuilderActionRunsHandler
1633
+ );
1634
+ router.get(
1635
+ "/:actionId/runs/:runId/execution-result",
1636
+ w({
1637
+ description: "Get execution result for an agent builder action run",
1638
+ tags: ["agent-builder"],
1639
+ parameters: [
1640
+ {
1641
+ name: "actionId",
1642
+ in: "path",
1643
+ required: true,
1644
+ schema: { type: "string" }
1645
+ },
1646
+ {
1647
+ name: "runId",
1648
+ in: "path",
1649
+ required: true,
1650
+ schema: { type: "string" }
1651
+ }
1652
+ ],
1653
+ responses: {
1654
+ 200: {
1655
+ description: "Agent builder action run execution result"
1656
+ },
1657
+ 404: {
1658
+ description: "Agent builder action run execution result not found"
1659
+ }
1660
+ }
1661
+ }),
1662
+ getAgentBuilderActionRunExecutionResultHandler
1663
+ );
1664
+ router.get(
1665
+ "/:actionId/runs/:runId",
1666
+ w({
1667
+ description: "Get agent builder action run by ID",
1668
+ tags: ["agent-builder"],
1669
+ parameters: [
1670
+ {
1671
+ name: "actionId",
1672
+ in: "path",
1673
+ required: true,
1674
+ schema: { type: "string" }
1675
+ },
1676
+ {
1677
+ name: "runId",
1678
+ in: "path",
1679
+ required: true,
1680
+ schema: { type: "string" }
1681
+ }
1682
+ ],
1683
+ responses: {
1684
+ 200: {
1685
+ description: "Agent builder action run by ID"
1686
+ },
1687
+ 404: {
1688
+ description: "Agent builder action run not found"
1689
+ }
1690
+ }
1691
+ }),
1692
+ getAgentBuilderActionRunByIdHandler
1693
+ );
1694
+ router.post(
1695
+ "/:actionId/resume",
1696
+ w({
1697
+ description: "Resume a suspended agent builder action step",
1698
+ tags: ["agent-builder"],
1699
+ parameters: [
1700
+ {
1701
+ name: "actionId",
1702
+ in: "path",
1703
+ required: true,
1704
+ schema: { type: "string" }
1705
+ },
1706
+ {
1707
+ name: "runId",
1708
+ in: "query",
1709
+ required: true,
1710
+ schema: { type: "string" }
1711
+ }
1712
+ ],
1713
+ requestBody: {
1714
+ required: true,
1715
+ content: {
1716
+ "application/json": {
1717
+ schema: {
1718
+ type: "object",
1719
+ properties: {
1720
+ step: {
1721
+ oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
1722
+ },
1723
+ resumeData: { type: "object" },
1724
+ runtimeContext: {
1725
+ type: "object",
1726
+ description: "Runtime context for the agent builder action execution"
1727
+ }
1728
+ },
1729
+ required: ["step"]
1730
+ }
1731
+ }
1732
+ }
1733
+ }
1734
+ }),
1735
+ resumeAgentBuilderActionHandler
1736
+ );
1737
+ router.post(
1738
+ "/:actionId/resume-async",
1739
+ bodyLimit.bodyLimit(bodyLimitOptions),
1740
+ w({
1741
+ description: "Resume a suspended agent builder action step",
1742
+ tags: ["agent-builder"],
1743
+ parameters: [
1744
+ {
1745
+ name: "actionId",
1746
+ in: "path",
1747
+ required: true,
1748
+ schema: { type: "string" }
1749
+ },
1750
+ {
1751
+ name: "runId",
1752
+ in: "query",
1753
+ required: true,
1754
+ schema: { type: "string" }
1755
+ }
1756
+ ],
1757
+ requestBody: {
1758
+ required: true,
1759
+ content: {
1760
+ "application/json": {
1761
+ schema: {
1762
+ type: "object",
1763
+ properties: {
1764
+ step: {
1765
+ oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
1766
+ },
1767
+ resumeData: { type: "object" },
1768
+ runtimeContext: {
1769
+ type: "object",
1770
+ description: "Runtime context for the agent builder action execution"
1771
+ }
1772
+ },
1773
+ required: ["step"]
1774
+ }
1775
+ }
1776
+ }
1777
+ }
1778
+ }),
1779
+ resumeAsyncAgentBuilderActionHandler
1780
+ );
1781
+ router.post(
1782
+ "/:actionId/stream",
1783
+ w({
1784
+ description: "Stream agent builder action in real-time",
1785
+ parameters: [
1786
+ {
1787
+ name: "actionId",
1788
+ in: "path",
1789
+ required: true,
1790
+ schema: { type: "string" }
1791
+ },
1792
+ {
1793
+ name: "runId",
1794
+ in: "query",
1795
+ required: false,
1796
+ schema: { type: "string" }
1797
+ }
1798
+ ],
1799
+ requestBody: {
1800
+ required: true,
1801
+ content: {
1802
+ "application/json": {
1803
+ schema: {
1804
+ type: "object",
1805
+ properties: {
1806
+ inputData: { type: "object" },
1807
+ runtimeContext: {
1808
+ type: "object",
1809
+ description: "Runtime context for the agent builder action execution"
1810
+ }
1811
+ }
1812
+ }
1813
+ }
1814
+ }
1815
+ },
1816
+ responses: {
1817
+ 200: {
1818
+ description: "agent builder action run started"
1819
+ },
1820
+ 404: {
1821
+ description: "agent builder action not found"
1822
+ }
1823
+ },
1824
+ tags: ["agent-builder"]
1825
+ }),
1826
+ streamAgentBuilderActionHandler
1827
+ );
1828
+ router.post(
1829
+ "/:actionId/streamVNext",
1830
+ w({
1831
+ description: "Stream agent builder action in real-time using the VNext streaming API",
1832
+ parameters: [
1833
+ {
1834
+ name: "actionId",
1835
+ in: "path",
1836
+ required: true,
1837
+ schema: { type: "string" }
1838
+ },
1839
+ {
1840
+ name: "runId",
1841
+ in: "query",
1842
+ required: false,
1843
+ schema: { type: "string" }
1844
+ }
1845
+ ],
1846
+ requestBody: {
1847
+ required: true,
1848
+ content: {
1849
+ "application/json": {
1850
+ schema: {
1851
+ type: "object",
1852
+ properties: {
1853
+ inputData: { type: "object" },
1854
+ runtimeContext: {
1855
+ type: "object",
1856
+ description: "Runtime context for the agent builder action execution"
1857
+ }
1858
+ }
1859
+ }
1860
+ }
1861
+ }
1862
+ },
1863
+ responses: {
1864
+ 200: {
1865
+ description: "agent builder action run started"
1866
+ },
1867
+ 404: {
1868
+ description: "agent builder action not found"
1869
+ }
1870
+ },
1871
+ tags: ["agent-builder"]
1872
+ }),
1873
+ streamVNextAgentBuilderActionHandler
1874
+ );
1875
+ router.post(
1876
+ "/:actionId/create-run",
1877
+ bodyLimit.bodyLimit(bodyLimitOptions),
1878
+ w({
1879
+ description: "Create a new agent builder action run",
1880
+ tags: ["agent-builder"],
1881
+ parameters: [
1882
+ {
1883
+ name: "actionId",
1884
+ in: "path",
1885
+ required: true,
1886
+ schema: { type: "string" }
1887
+ },
1888
+ {
1889
+ name: "runId",
1890
+ in: "query",
1891
+ required: false,
1892
+ schema: { type: "string" }
1893
+ }
1894
+ ],
1895
+ responses: {
1896
+ 200: {
1897
+ description: "New agent builder action run created"
1898
+ }
1899
+ }
1900
+ }),
1901
+ createAgentBuilderActionRunHandler
1902
+ );
1903
+ router.post(
1904
+ "/:actionId/start-async",
1905
+ bodyLimit.bodyLimit(bodyLimitOptions),
1906
+ w({
1907
+ description: "Execute/Start an agent builder action",
1908
+ tags: ["agent-builder"],
1909
+ parameters: [
1910
+ {
1911
+ name: "actionId",
1912
+ in: "path",
1913
+ required: true,
1914
+ schema: { type: "string" }
1915
+ },
1916
+ {
1917
+ name: "runId",
1918
+ in: "query",
1919
+ required: false,
1920
+ schema: { type: "string" }
1921
+ }
1922
+ ],
1923
+ requestBody: {
1924
+ required: true,
1925
+ content: {
1926
+ "application/json": {
1927
+ schema: {
1928
+ type: "object",
1929
+ properties: {
1930
+ inputData: { type: "object" },
1931
+ runtimeContext: {
1932
+ type: "object",
1933
+ description: "Runtime context for the agent builder action execution"
1934
+ }
1935
+ }
1936
+ }
1937
+ }
1938
+ }
1939
+ },
1940
+ responses: {
1941
+ 200: {
1942
+ description: "agent builder action execution result"
1943
+ },
1944
+ 404: {
1945
+ description: "agent builder action not found"
1946
+ }
1947
+ }
1948
+ }),
1949
+ startAsyncAgentBuilderActionHandler
1950
+ );
1951
+ router.post(
1952
+ "/:actionId/start",
1953
+ w({
1954
+ description: "Create and start a new agent builder action run",
1955
+ tags: ["agent-builder"],
1956
+ parameters: [
1957
+ {
1958
+ name: "actionId",
1959
+ in: "path",
1960
+ required: true,
1961
+ schema: { type: "string" }
1962
+ },
1963
+ {
1964
+ name: "runId",
1965
+ in: "query",
1966
+ required: true,
1967
+ schema: { type: "string" }
1968
+ }
1969
+ ],
1970
+ requestBody: {
1971
+ required: true,
1972
+ content: {
1973
+ "application/json": {
1974
+ schema: {
1975
+ type: "object",
1976
+ properties: {
1977
+ inputData: { type: "object" },
1978
+ runtimeContext: {
1979
+ type: "object",
1980
+ description: "Runtime context for the agent builder action execution"
1981
+ }
1982
+ }
1983
+ }
1984
+ }
1985
+ }
1986
+ },
1987
+ responses: {
1988
+ 200: {
1989
+ description: "agent builder action run started"
1990
+ },
1991
+ 404: {
1992
+ description: "agent builder action not found"
1993
+ }
1994
+ }
1995
+ }),
1996
+ startAgentBuilderActionRunHandler
1997
+ );
1998
+ router.get(
1999
+ "/:actionId/watch",
2000
+ w({
2001
+ description: "Watch agent builder action transitions in real-time",
2002
+ parameters: [
2003
+ {
2004
+ name: "actionId",
2005
+ in: "path",
2006
+ required: true,
2007
+ schema: { type: "string" }
2008
+ },
2009
+ {
2010
+ name: "runId",
2011
+ in: "query",
2012
+ required: false,
2013
+ schema: { type: "string" }
2014
+ },
2015
+ {
2016
+ name: "eventType",
2017
+ in: "query",
2018
+ required: false,
2019
+ schema: { type: "string", enum: ["watch", "watch-v2"] }
2020
+ }
2021
+ ],
2022
+ tags: ["agent-builder"],
2023
+ responses: {
2024
+ 200: {
2025
+ description: "agent builder action transitions in real-time"
2026
+ }
2027
+ }
2028
+ }),
2029
+ watchAgentBuilderActionHandler
2030
+ );
2031
+ router.post(
2032
+ "/:actionId/runs/:runId/cancel",
2033
+ w({
2034
+ description: "Cancel an agent builder action run",
2035
+ parameters: [
2036
+ {
2037
+ name: "actionId",
2038
+ in: "path",
2039
+ required: true,
2040
+ schema: { type: "string" }
2041
+ },
2042
+ {
2043
+ name: "runId",
2044
+ in: "path",
2045
+ required: true,
2046
+ schema: { type: "string" }
2047
+ }
2048
+ ],
2049
+ tags: ["agent-builder"],
2050
+ responses: {
2051
+ 200: {
2052
+ description: "agent builder action run cancelled"
2053
+ }
2054
+ }
2055
+ }),
2056
+ cancelAgentBuilderActionRunHandler
2057
+ );
2058
+ router.post(
2059
+ "/:actionId/runs/:runId/send-event",
2060
+ w({
2061
+ description: "Send an event to an agent builder action run",
2062
+ parameters: [
2063
+ {
2064
+ name: "actionId",
2065
+ in: "path",
2066
+ required: true,
2067
+ schema: { type: "string" }
2068
+ },
2069
+ {
2070
+ name: "runId",
2071
+ in: "path",
2072
+ required: true,
2073
+ schema: { type: "string" }
2074
+ }
2075
+ ],
2076
+ requestBody: {
2077
+ required: true,
2078
+ content: {
2079
+ "application/json": {
2080
+ schema: { type: "object", properties: { event: { type: "string" }, data: { type: "object" } } }
2081
+ }
2082
+ }
2083
+ },
2084
+ tags: ["agent-builder"],
2085
+ responses: {
2086
+ 200: {
2087
+ description: "agent builder action run event sent"
2088
+ }
2089
+ }
2090
+ }),
2091
+ sendAgentBuilderActionRunEventHandler
2092
+ );
2093
+ return router;
1246
2094
  }
1247
2095
  var AllowedProviderKeys = {
1248
2096
  openai: "OPENAI_API_KEY",
@@ -1345,6 +2193,24 @@ async function getLiveEvalsByAgentIdHandler(c2) {
1345
2193
  });
1346
2194
  return c2.json(result);
1347
2195
  }
2196
+ async function generateLegacyHandler(c2) {
2197
+ try {
2198
+ const mastra = c2.get("mastra");
2199
+ const agentId = c2.req.param("agentId");
2200
+ const runtimeContext = c2.get("runtimeContext");
2201
+ const body = await c2.req.json();
2202
+ const result = await agents.generateLegacyHandler({
2203
+ mastra,
2204
+ agentId,
2205
+ runtimeContext,
2206
+ body,
2207
+ abortSignal: c2.req.raw.signal
2208
+ });
2209
+ return c2.json(result);
2210
+ } catch (error) {
2211
+ return handleError(error, "Error generating from agent");
2212
+ }
2213
+ }
1348
2214
  async function generateHandler(c2) {
1349
2215
  try {
1350
2216
  const mastra = c2.get("mastra");
@@ -1381,6 +2247,24 @@ async function generateVNextHandler(c2) {
1381
2247
  return handleError(error, "Error generating vnext from agent");
1382
2248
  }
1383
2249
  }
2250
+ async function streamGenerateLegacyHandler(c2) {
2251
+ try {
2252
+ const mastra = c2.get("mastra");
2253
+ const agentId = c2.req.param("agentId");
2254
+ const runtimeContext = c2.get("runtimeContext");
2255
+ const body = await c2.req.json();
2256
+ const streamResponse = await agents.streamGenerateLegacyHandler({
2257
+ mastra,
2258
+ agentId,
2259
+ runtimeContext,
2260
+ body,
2261
+ abortSignal: c2.req.raw.signal
2262
+ });
2263
+ return streamResponse;
2264
+ } catch (error) {
2265
+ return handleError(error, "Error streaming from agent");
2266
+ }
2267
+ }
1384
2268
  async function streamGenerateHandler(c2) {
1385
2269
  try {
1386
2270
  const mastra = c2.get("mastra");
@@ -1409,7 +2293,7 @@ async function streamVNextGenerateHandler(c2) {
1409
2293
  c2.header("Transfer-Encoding", "chunked");
1410
2294
  return streaming.stream(
1411
2295
  c2,
1412
- async (stream6) => {
2296
+ async (stream7) => {
1413
2297
  try {
1414
2298
  const streamResponse = await agents.streamVNextGenerateHandler({
1415
2299
  mastra,
@@ -1419,20 +2303,20 @@ async function streamVNextGenerateHandler(c2) {
1419
2303
  abortSignal: c2.req.raw.signal
1420
2304
  });
1421
2305
  const reader = streamResponse.fullStream.getReader();
1422
- stream6.onAbort(() => {
2306
+ stream7.onAbort(() => {
1423
2307
  void reader.cancel("request aborted");
1424
2308
  });
1425
2309
  let chunkResult;
1426
2310
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
1427
- await stream6.write(`data: ${JSON.stringify(chunkResult.value)}
2311
+ await stream7.write(`data: ${JSON.stringify(chunkResult.value)}
1428
2312
 
1429
2313
  `);
1430
2314
  }
1431
- await stream6.write("data: [DONE]\n\n");
2315
+ await stream7.write("data: [DONE]\n\n");
1432
2316
  } catch (err) {
1433
2317
  logger2.error("Error in streamVNext generate: " + (err?.message ?? "Unknown error"));
1434
2318
  }
1435
- await stream6.close();
2319
+ await stream7.close();
1436
2320
  },
1437
2321
  async (err) => {
1438
2322
  logger2.error("Error in watch stream: " + err?.message);
@@ -1680,6 +2564,23 @@ function executeToolHandler(tools) {
1680
2564
  }
1681
2565
  };
1682
2566
  }
2567
+ async function getAgentToolHandler(c2) {
2568
+ try {
2569
+ const mastra = c2.get("mastra");
2570
+ const runtimeContext = c2.get("runtimeContext");
2571
+ const agentId = c2.req.param("agentId");
2572
+ const toolId = c2.req.param("toolId");
2573
+ const result = await tools$1.getAgentToolHandler({
2574
+ mastra,
2575
+ agentId,
2576
+ toolId,
2577
+ runtimeContext
2578
+ });
2579
+ return c2.json(result);
2580
+ } catch (error) {
2581
+ return handleError(error, "Error getting agent tool");
2582
+ }
2583
+ }
1683
2584
  async function executeAgentToolHandler(c2) {
1684
2585
  try {
1685
2586
  const mastra = c2.get("mastra");
@@ -1854,6 +2755,57 @@ function agentsRouter(bodyLimitOptions) {
1854
2755
  }),
1855
2756
  getLiveEvalsByAgentIdHandler
1856
2757
  );
2758
+ router.post(
2759
+ "/:agentId/generate-legacy",
2760
+ bodyLimit.bodyLimit(bodyLimitOptions),
2761
+ w({
2762
+ description: "Generate a response from an agent",
2763
+ tags: ["agents"],
2764
+ parameters: [
2765
+ {
2766
+ name: "agentId",
2767
+ in: "path",
2768
+ required: true,
2769
+ schema: { type: "string" }
2770
+ }
2771
+ ],
2772
+ requestBody: {
2773
+ required: true,
2774
+ content: {
2775
+ "application/json": {
2776
+ schema: {
2777
+ type: "object",
2778
+ properties: {
2779
+ messages: {
2780
+ type: "array",
2781
+ items: { type: "object" }
2782
+ },
2783
+ threadId: { type: "string" },
2784
+ resourceId: { type: "string", description: "The resource ID for the conversation" },
2785
+ resourceid: {
2786
+ type: "string",
2787
+ description: "The resource ID for the conversation (deprecated, use resourceId instead)",
2788
+ deprecated: true
2789
+ },
2790
+ runId: { type: "string" },
2791
+ output: { type: "object" }
2792
+ },
2793
+ required: ["messages"]
2794
+ }
2795
+ }
2796
+ }
2797
+ },
2798
+ responses: {
2799
+ 200: {
2800
+ description: "Generated response"
2801
+ },
2802
+ 404: {
2803
+ description: "Agent not found"
2804
+ }
2805
+ }
2806
+ }),
2807
+ generateLegacyHandler
2808
+ );
1857
2809
  router.post(
1858
2810
  "/:agentId/generate",
1859
2811
  bodyLimit.bodyLimit(bodyLimitOptions),
@@ -1979,6 +2931,57 @@ function agentsRouter(bodyLimitOptions) {
1979
2931
  }),
1980
2932
  streamVNextGenerateHandler
1981
2933
  );
2934
+ router.post(
2935
+ "/:agentId/stream-legacy",
2936
+ bodyLimit.bodyLimit(bodyLimitOptions),
2937
+ w({
2938
+ description: "Stream a response from an agent",
2939
+ tags: ["agents"],
2940
+ parameters: [
2941
+ {
2942
+ name: "agentId",
2943
+ in: "path",
2944
+ required: true,
2945
+ schema: { type: "string" }
2946
+ }
2947
+ ],
2948
+ requestBody: {
2949
+ required: true,
2950
+ content: {
2951
+ "application/json": {
2952
+ schema: {
2953
+ type: "object",
2954
+ properties: {
2955
+ messages: {
2956
+ type: "array",
2957
+ items: { type: "object" }
2958
+ },
2959
+ threadId: { type: "string" },
2960
+ resourceId: { type: "string", description: "The resource ID for the conversation" },
2961
+ resourceid: {
2962
+ type: "string",
2963
+ description: "The resource ID for the conversation (deprecated, use resourceId instead)",
2964
+ deprecated: true
2965
+ },
2966
+ runId: { type: "string" },
2967
+ output: { type: "object" }
2968
+ },
2969
+ required: ["messages"]
2970
+ }
2971
+ }
2972
+ }
2973
+ },
2974
+ responses: {
2975
+ 200: {
2976
+ description: "Streamed response"
2977
+ },
2978
+ 404: {
2979
+ description: "Agent not found"
2980
+ }
2981
+ }
2982
+ }),
2983
+ streamGenerateLegacyHandler
2984
+ );
1982
2985
  router.post(
1983
2986
  "/:agentId/stream",
1984
2987
  bodyLimit.bodyLimit(bodyLimitOptions),
@@ -2600,6 +3603,36 @@ function agentsRouter(bodyLimitOptions) {
2600
3603
  }),
2601
3604
  listenHandler
2602
3605
  );
3606
+ router.get(
3607
+ "/:agentId/tools/:toolId",
3608
+ w({
3609
+ description: "Get agent tool by ID",
3610
+ tags: ["agents"],
3611
+ parameters: [
3612
+ {
3613
+ name: "agentId",
3614
+ in: "path",
3615
+ required: true,
3616
+ schema: { type: "string" }
3617
+ },
3618
+ {
3619
+ name: "toolId",
3620
+ in: "path",
3621
+ required: true,
3622
+ schema: { type: "string" }
3623
+ }
3624
+ ],
3625
+ responses: {
3626
+ 200: {
3627
+ description: "Tool details"
3628
+ },
3629
+ 404: {
3630
+ description: "Tool or agent not found"
3631
+ }
3632
+ }
3633
+ }),
3634
+ getAgentToolHandler
3635
+ );
2603
3636
  router.post(
2604
3637
  "/:agentId/tools/:toolId/execute",
2605
3638
  bodyLimit.bodyLimit(bodyLimitOptions),
@@ -7030,7 +8063,7 @@ async function streamGenerateVNextNetworkHandler(c2) {
7030
8063
  c2.header("Transfer-Encoding", "chunked");
7031
8064
  return streaming.stream(
7032
8065
  c2,
7033
- async (stream6) => {
8066
+ async (stream7) => {
7034
8067
  try {
7035
8068
  const result = await vNextNetwork.streamGenerateVNextNetworkHandler({
7036
8069
  mastra,
@@ -7039,12 +8072,12 @@ async function streamGenerateVNextNetworkHandler(c2) {
7039
8072
  body
7040
8073
  });
7041
8074
  const reader = result.stream.getReader();
7042
- stream6.onAbort(() => {
8075
+ stream7.onAbort(() => {
7043
8076
  void reader.cancel("request aborted");
7044
8077
  });
7045
8078
  let chunkResult;
7046
8079
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
7047
- await stream6.write(JSON.stringify(chunkResult.value) + "");
8080
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
7048
8081
  }
7049
8082
  } catch (err) {
7050
8083
  mastra.getLogger().error("Error in network stream: " + (err?.message ?? "Unknown error"));
@@ -7085,7 +8118,7 @@ async function loopStreamVNextNetworkHandler(c2) {
7085
8118
  c2.header("Transfer-Encoding", "chunked");
7086
8119
  return streaming.stream(
7087
8120
  c2,
7088
- async (stream6) => {
8121
+ async (stream7) => {
7089
8122
  try {
7090
8123
  const result = await vNextNetwork.loopStreamVNextNetworkHandler({
7091
8124
  mastra,
@@ -7094,12 +8127,12 @@ async function loopStreamVNextNetworkHandler(c2) {
7094
8127
  body
7095
8128
  });
7096
8129
  const reader = result.stream.getReader();
7097
- stream6.onAbort(() => {
8130
+ stream7.onAbort(() => {
7098
8131
  void reader.cancel("request aborted");
7099
8132
  });
7100
8133
  let chunkResult;
7101
8134
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
7102
- await stream6.write(JSON.stringify(chunkResult.value) + "");
8135
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
7103
8136
  }
7104
8137
  } catch (err) {
7105
8138
  mastra.getLogger().error("Error in network loop stream: " + (err?.message ?? "Unknown error"));
@@ -8485,7 +9518,7 @@ function watchWorkflowHandler(c2) {
8485
9518
  c2.header("Transfer-Encoding", "chunked");
8486
9519
  return streaming.stream(
8487
9520
  c2,
8488
- async (stream6) => {
9521
+ async (stream7) => {
8489
9522
  try {
8490
9523
  const result = await workflows.watchWorkflowHandler({
8491
9524
  mastra,
@@ -8493,12 +9526,12 @@ function watchWorkflowHandler(c2) {
8493
9526
  runId
8494
9527
  });
8495
9528
  const reader = result.getReader();
8496
- stream6.onAbort(() => {
9529
+ stream7.onAbort(() => {
8497
9530
  void reader.cancel("request aborted");
8498
9531
  });
8499
9532
  let chunkResult;
8500
9533
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
8501
- await stream6.write(JSON.stringify(chunkResult.value) + "");
9534
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
8502
9535
  }
8503
9536
  } catch (err) {
8504
9537
  logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
@@ -8523,7 +9556,7 @@ async function streamWorkflowHandler(c2) {
8523
9556
  c2.header("Transfer-Encoding", "chunked");
8524
9557
  return streaming.stream(
8525
9558
  c2,
8526
- async (stream6) => {
9559
+ async (stream7) => {
8527
9560
  try {
8528
9561
  const result = await workflows.streamWorkflowHandler({
8529
9562
  mastra,
@@ -8533,17 +9566,17 @@ async function streamWorkflowHandler(c2) {
8533
9566
  runtimeContext
8534
9567
  });
8535
9568
  const reader = result.stream.getReader();
8536
- stream6.onAbort(() => {
9569
+ stream7.onAbort(() => {
8537
9570
  void reader.cancel("request aborted");
8538
9571
  });
8539
9572
  let chunkResult;
8540
9573
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
8541
- await stream6.write(JSON.stringify(chunkResult.value) + "");
9574
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
8542
9575
  }
8543
9576
  } catch (err) {
8544
9577
  logger2.error("Error in workflow stream: " + (err?.message ?? "Unknown error"));
8545
9578
  }
8546
- await stream6.close();
9579
+ await stream7.close();
8547
9580
  },
8548
9581
  async (err) => {
8549
9582
  logger2.error("Error in workflow stream: " + err?.message);
@@ -8564,7 +9597,7 @@ async function streamVNextWorkflowHandler(c2) {
8564
9597
  c2.header("Transfer-Encoding", "chunked");
8565
9598
  return streaming.stream(
8566
9599
  c2,
8567
- async (stream6) => {
9600
+ async (stream7) => {
8568
9601
  try {
8569
9602
  const result = await workflows.streamVNextWorkflowHandler({
8570
9603
  mastra,
@@ -8574,12 +9607,12 @@ async function streamVNextWorkflowHandler(c2) {
8574
9607
  runtimeContext
8575
9608
  });
8576
9609
  const reader = result.getReader();
8577
- stream6.onAbort(() => {
9610
+ stream7.onAbort(() => {
8578
9611
  void reader.cancel("request aborted");
8579
9612
  });
8580
9613
  let chunkResult;
8581
9614
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
8582
- await stream6.write(JSON.stringify(chunkResult.value) + "");
9615
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
8583
9616
  }
8584
9617
  } catch (err) {
8585
9618
  logger2.error("Error in workflow VNext stream: " + (err?.message ?? "Unknown error"));
@@ -8807,20 +9840,20 @@ function watchLegacyWorkflowHandler(c2) {
8807
9840
  }
8808
9841
  return streaming.stream(
8809
9842
  c2,
8810
- async (stream6) => {
9843
+ async (stream7) => {
8811
9844
  try {
8812
9845
  const result = await legacyWorkflows.watchLegacyWorkflowHandler({
8813
9846
  mastra,
8814
9847
  workflowId,
8815
9848
  runId
8816
9849
  });
8817
- stream6.onAbort(() => {
9850
+ stream7.onAbort(() => {
8818
9851
  if (!result.locked) {
8819
9852
  return result.cancel();
8820
9853
  }
8821
9854
  });
8822
9855
  for await (const chunk of result) {
8823
- await stream6.write(chunk.toString() + "");
9856
+ await stream7.write(chunk.toString() + "");
8824
9857
  }
8825
9858
  } catch (err) {
8826
9859
  console.log(err);
@@ -10120,6 +11153,7 @@ async function createHonoServer(mastra, options = {
10120
11153
  app.route("/api/workflows", workflowsRouter(bodyLimitOptions));
10121
11154
  app.route("/api/logs", logsRouter());
10122
11155
  app.route("/api/scores", scoresRouter(bodyLimitOptions));
11156
+ app.route("/api/agent-builder", agentBuilderRouter(bodyLimitOptions));
10123
11157
  app.route("/api/tools", toolsRouter(bodyLimitOptions, options.tools));
10124
11158
  app.route("/api/vector", vectorRouter(bodyLimitOptions));
10125
11159
  if (options?.isDev || server?.build?.openAPIDocs || server?.build?.swaggerUI) {