@mastra/deployer 0.15.3-alpha.3 → 0.15.3-alpha.5

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 (72) hide show
  1. package/CHANGELOG.md +4037 -0
  2. package/dist/build/__fixtures__/no-bundler.d.ts +1 -1
  3. package/dist/build/__fixtures__/no-bundler.d.ts.map +1 -1
  4. package/dist/build/__fixtures__/no-server.d.ts +1 -1
  5. package/dist/build/__fixtures__/no-server.d.ts.map +1 -1
  6. package/dist/build/__fixtures__/no-telemetry.d.ts +1 -1
  7. package/dist/build/__fixtures__/no-telemetry.d.ts.map +1 -1
  8. package/dist/build/analyze.cjs +3 -3
  9. package/dist/build/analyze.js +1 -1
  10. package/dist/build/index.cjs +12 -12
  11. package/dist/build/index.js +4 -4
  12. package/dist/build/plugins/__fixtures__/basic-with-bundler.d.ts +1 -1
  13. package/dist/build/plugins/__fixtures__/basic-with-bundler.d.ts.map +1 -1
  14. package/dist/build/plugins/__fixtures__/basic-with-const.d.ts +1 -1
  15. package/dist/build/plugins/__fixtures__/basic-with-const.d.ts.map +1 -1
  16. package/dist/build/plugins/__fixtures__/basic-with-function.d.ts +1 -1
  17. package/dist/build/plugins/__fixtures__/basic-with-function.d.ts.map +1 -1
  18. package/dist/build/plugins/__fixtures__/basic-with-import.d.ts +1 -1
  19. package/dist/build/plugins/__fixtures__/basic-with-import.d.ts.map +1 -1
  20. package/dist/build/plugins/__fixtures__/basic-with-json.d.ts +1 -1
  21. package/dist/build/plugins/__fixtures__/basic-with-json.d.ts.map +1 -1
  22. package/dist/build/plugins/__fixtures__/basic.d.ts +1 -1
  23. package/dist/build/plugins/__fixtures__/basic.d.ts.map +1 -1
  24. package/dist/build/plugins/__fixtures__/empty-mastra.d.ts +1 -1
  25. package/dist/build/plugins/__fixtures__/empty-mastra.d.ts.map +1 -1
  26. package/dist/build/plugins/__fixtures__/mastra-with-extra-code.d.ts +1 -1
  27. package/dist/build/plugins/__fixtures__/mastra-with-extra-code.d.ts.map +1 -1
  28. package/dist/bundler/index.cjs +2 -2
  29. package/dist/bundler/index.js +1 -1
  30. package/dist/{chunk-AVESU2SU.js → chunk-2GPZM6PP.js} +5 -5
  31. package/dist/{chunk-AVESU2SU.js.map → chunk-2GPZM6PP.js.map} +1 -1
  32. package/dist/{chunk-X54LEGAC.cjs → chunk-AM2S5WCK.cjs} +30 -19
  33. package/dist/chunk-AM2S5WCK.cjs.map +1 -0
  34. package/dist/{chunk-GPGRGCTW.js → chunk-DG6YR6QC.js} +28 -17
  35. package/dist/chunk-DG6YR6QC.js.map +1 -0
  36. package/dist/{chunk-PEPYV5JI.cjs → chunk-FOPPWICF.cjs} +16 -16
  37. package/dist/{chunk-PEPYV5JI.cjs.map → chunk-FOPPWICF.cjs.map} +1 -1
  38. package/dist/{chunk-WAZSZUBG.js → chunk-HUAOVISC.js} +3 -3
  39. package/dist/{chunk-WAZSZUBG.js.map → chunk-HUAOVISC.js.map} +1 -1
  40. package/dist/{chunk-C5VTZTAY.js → chunk-IVGJKJCG.js} +3 -3
  41. package/dist/{chunk-C5VTZTAY.js.map → chunk-IVGJKJCG.js.map} +1 -1
  42. package/dist/{chunk-TE5Y7CVX.cjs → chunk-KVBYKVQQ.cjs} +5 -5
  43. package/dist/{chunk-TE5Y7CVX.cjs.map → chunk-KVBYKVQQ.cjs.map} +1 -1
  44. package/dist/{chunk-7P4PV6QU.js → chunk-U4ZNNX34.js} +3 -3
  45. package/dist/{chunk-7P4PV6QU.js.map → chunk-U4ZNNX34.js.map} +1 -1
  46. package/dist/{chunk-GDMDXD6B.cjs → chunk-WHMSFLP7.cjs} +5 -5
  47. package/dist/{chunk-GDMDXD6B.cjs.map → chunk-WHMSFLP7.cjs.map} +1 -1
  48. package/dist/{chunk-EJQ67F7F.cjs → chunk-WSYCRXET.cjs} +9 -9
  49. package/dist/{chunk-EJQ67F7F.cjs.map → chunk-WSYCRXET.cjs.map} +1 -1
  50. package/dist/index.cjs +12 -12
  51. package/dist/index.js +4 -4
  52. package/dist/server/handlers/routes/agent-builder/handlers.d.ts +17 -0
  53. package/dist/server/handlers/routes/agent-builder/handlers.d.ts.map +1 -0
  54. package/dist/server/handlers/routes/agent-builder/router.d.ts +4 -0
  55. package/dist/server/handlers/routes/agent-builder/router.d.ts.map +1 -0
  56. package/dist/server/handlers/routes/agents/handlers.d.ts +2 -0
  57. package/dist/server/handlers/routes/agents/handlers.d.ts.map +1 -1
  58. package/dist/server/handlers/routes/agents/router.d.ts.map +1 -1
  59. package/dist/server/handlers/routes/tools/handlers.d.ts +1 -0
  60. package/dist/server/handlers/routes/tools/handlers.d.ts.map +1 -1
  61. package/dist/server/index.cjs +1145 -111
  62. package/dist/server/index.cjs.map +1 -1
  63. package/dist/server/index.d.ts.map +1 -1
  64. package/dist/server/index.js +1074 -40
  65. package/dist/server/index.js.map +1 -1
  66. package/dist/services/deps.d.ts +5 -0
  67. package/dist/services/deps.d.ts.map +1 -1
  68. package/dist/services/index.cjs +4 -4
  69. package/dist/services/index.js +1 -1
  70. package/package.json +17 -7
  71. package/dist/chunk-GPGRGCTW.js.map +0 -1
  72. package/dist/chunk-X54LEGAC.cjs.map +0 -1
@@ -19,11 +19,12 @@ import { timeout } from 'hono/timeout';
19
19
  import { HTTPException } from 'hono/http-exception';
20
20
  import { getAgentCardByIdHandler as getAgentCardByIdHandler$1, getAgentExecutionHandler as getAgentExecutionHandler$1 } from '@mastra/server/handlers/a2a';
21
21
  import { stream } from 'hono/streaming';
22
- import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateHandler as generateHandler$1, generateVNextHandler as generateVNextHandler$1, streamVNextGenerateHandler as streamVNextGenerateHandler$1, streamGenerateHandler as streamGenerateHandler$1, streamVNextUIMessageHandler as streamVNextUIMessageHandler$1, updateAgentModelHandler as updateAgentModelHandler$1 } from '@mastra/server/handlers/agents';
23
22
  import { bodyLimit } from 'hono/body-limit';
23
+ import { getAgentBuilderActionsHandler as getAgentBuilderActionsHandler$1, getAgentBuilderActionByIdHandler as getAgentBuilderActionByIdHandler$1, getAgentBuilderActionRunsHandler as getAgentBuilderActionRunsHandler$1, getAgentBuilderActionRunExecutionResultHandler as getAgentBuilderActionRunExecutionResultHandler$1, getAgentBuilderActionRunByIdHandler as getAgentBuilderActionRunByIdHandler$1, resumeAgentBuilderActionHandler as resumeAgentBuilderActionHandler$1, resumeAsyncAgentBuilderActionHandler as resumeAsyncAgentBuilderActionHandler$1, streamAgentBuilderActionHandler as streamAgentBuilderActionHandler$1, streamVNextAgentBuilderActionHandler as streamVNextAgentBuilderActionHandler$1, createAgentBuilderActionRunHandler as createAgentBuilderActionRunHandler$1, startAsyncAgentBuilderActionHandler as startAsyncAgentBuilderActionHandler$1, startAgentBuilderActionRunHandler as startAgentBuilderActionRunHandler$1, watchAgentBuilderActionHandler as watchAgentBuilderActionHandler$1, cancelAgentBuilderActionRunHandler as cancelAgentBuilderActionRunHandler$1, sendAgentBuilderActionRunEventHandler as sendAgentBuilderActionRunEventHandler$1 } from '@mastra/server/handlers/agent-builder';
24
+ import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateLegacyHandler as generateLegacyHandler$1, generateHandler as generateHandler$1, generateVNextHandler as generateVNextHandler$1, streamVNextGenerateHandler as streamVNextGenerateHandler$1, streamGenerateLegacyHandler as streamGenerateLegacyHandler$1, streamGenerateHandler as streamGenerateHandler$1, streamVNextUIMessageHandler as streamVNextUIMessageHandler$1, updateAgentModelHandler as updateAgentModelHandler$1 } from '@mastra/server/handlers/agents';
24
25
  import { Agent } from '@mastra/core/agent';
25
26
  import { z } from 'zod';
26
- import { executeAgentToolHandler as executeAgentToolHandler$1, getToolsHandler as getToolsHandler$1, getToolByIdHandler as getToolByIdHandler$1, executeToolHandler as executeToolHandler$1 } from '@mastra/server/handlers/tools';
27
+ import { getAgentToolHandler as getAgentToolHandler$1, executeAgentToolHandler as executeAgentToolHandler$1, getToolsHandler as getToolsHandler$1, getToolByIdHandler as getToolByIdHandler$1, executeToolHandler as executeToolHandler$1 } from '@mastra/server/handlers/tools';
27
28
  import { getSpeakersHandler as getSpeakersHandler$1, generateSpeechHandler, getListenerHandler as getListenerHandler$1, transcribeSpeechHandler } from '@mastra/server/handlers/voice';
28
29
  import { getLogsHandler as getLogsHandler$1, getLogTransports as getLogTransports$1, getLogsByRunIdHandler as getLogsByRunIdHandler$1 } from '@mastra/server/handlers/logs';
29
30
  import util from 'util';
@@ -280,13 +281,13 @@ var Response2 = class _Response {
280
281
  });
281
282
  Object.setPrototypeOf(Response2, GlobalResponse);
282
283
  Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
283
- function writeFromReadableStream(stream6, writable) {
284
- if (stream6.locked) {
284
+ function writeFromReadableStream(stream7, writable) {
285
+ if (stream7.locked) {
285
286
  throw new TypeError("ReadableStream is locked.");
286
287
  } else if (writable.destroyed) {
287
288
  return;
288
289
  }
289
- const reader = stream6.getReader();
290
+ const reader = stream7.getReader();
290
291
  const handleError2 = () => {
291
292
  };
292
293
  writable.on("error", handleError2);
@@ -553,18 +554,18 @@ var ENCODINGS = {
553
554
  gzip: ".gz"
554
555
  };
555
556
  var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
556
- var createStreamBody = (stream6) => {
557
+ var createStreamBody = (stream7) => {
557
558
  const body = new ReadableStream({
558
559
  start(controller) {
559
- stream6.on("data", (chunk) => {
560
+ stream7.on("data", (chunk) => {
560
561
  controller.enqueue(chunk);
561
562
  });
562
- stream6.on("end", () => {
563
+ stream7.on("end", () => {
563
564
  controller.close();
564
565
  });
565
566
  },
566
567
  cancel() {
567
- stream6.destroy();
568
+ stream7.destroy();
568
569
  }
569
570
  });
570
571
  return body;
@@ -653,10 +654,10 @@ var serveStatic = (options = { root: "" }) => {
653
654
  end = size - 1;
654
655
  }
655
656
  const chunksize = end - start + 1;
656
- const stream6 = createReadStream(path, { start, end });
657
+ const stream7 = createReadStream(path, { start, end });
657
658
  c2.header("Content-Length", chunksize.toString());
658
659
  c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
659
- return c2.body(createStreamBody(stream6), 206);
660
+ return c2.body(createStreamBody(stream7), 206);
660
661
  };
661
662
  };
662
663
  var RENDER_TYPE = {
@@ -954,15 +955,15 @@ async function getAgentExecutionHandler(c2) {
954
955
  if (body.method === "message/stream") {
955
956
  return stream(
956
957
  c2,
957
- async (stream6) => {
958
+ async (stream7) => {
958
959
  try {
959
- stream6.onAbort(() => {
960
+ stream7.onAbort(() => {
960
961
  if (!result.locked) {
961
962
  return result.cancel();
962
963
  }
963
964
  });
964
965
  for await (const chunk of result) {
965
- await stream6.write(JSON.stringify(chunk) + "");
966
+ await stream7.write(JSON.stringify(chunk) + "");
966
967
  }
967
968
  } catch (err) {
968
969
  logger2.error("Error in message/stream stream: " + err?.message);
@@ -1187,7 +1188,7 @@ var authorizationMiddleware = async (c2, next) => {
1187
1188
  // src/server/handlers/client.ts
1188
1189
  var clients = /* @__PURE__ */ new Set();
1189
1190
  function handleClientsRefresh(c2) {
1190
- const stream6 = new ReadableStream({
1191
+ const stream7 = new ReadableStream({
1191
1192
  start(controller) {
1192
1193
  clients.add(controller);
1193
1194
  controller.enqueue("data: connected\n\n");
@@ -1196,7 +1197,7 @@ function handleClientsRefresh(c2) {
1196
1197
  });
1197
1198
  }
1198
1199
  });
1199
- return new Response(stream6, {
1200
+ return new Response(stream7, {
1200
1201
  headers: {
1201
1202
  "Content-Type": "text/event-stream",
1202
1203
  "Cache-Control": "no-cache",
@@ -1237,6 +1238,853 @@ function errorHandler(err, c2, isDev) {
1237
1238
  async function rootHandler(c2) {
1238
1239
  return c2.text("Hello to the Mastra API!");
1239
1240
  }
1241
+ async function getAgentBuilderActionsHandler(c2) {
1242
+ try {
1243
+ const mastra = c2.get("mastra");
1244
+ const actions = await getAgentBuilderActionsHandler$1({
1245
+ mastra
1246
+ });
1247
+ return c2.json(actions);
1248
+ } catch (error) {
1249
+ return handleError(error, "Error getting agent builder actions");
1250
+ }
1251
+ }
1252
+ async function getAgentBuilderActionByIdHandler(c2) {
1253
+ try {
1254
+ const mastra = c2.get("mastra");
1255
+ const actionId = c2.req.param("actionId");
1256
+ const action = await getAgentBuilderActionByIdHandler$1({
1257
+ mastra,
1258
+ actionId
1259
+ });
1260
+ return c2.json(action);
1261
+ } catch (error) {
1262
+ return handleError(error, "Error getting agent builder action by ID");
1263
+ }
1264
+ }
1265
+ async function createAgentBuilderActionRunHandler(c2) {
1266
+ try {
1267
+ const mastra = c2.get("mastra");
1268
+ const actionId = c2.req.param("actionId");
1269
+ const runId = c2.req.query("runId");
1270
+ const result = await createAgentBuilderActionRunHandler$1({
1271
+ mastra,
1272
+ actionId,
1273
+ runId
1274
+ });
1275
+ return c2.json(result);
1276
+ } catch (error) {
1277
+ return handleError(error, "Error creating agent builder action run");
1278
+ }
1279
+ }
1280
+ async function startAsyncAgentBuilderActionHandler(c2) {
1281
+ try {
1282
+ const mastra = c2.get("mastra");
1283
+ const runtimeContext = c2.get("runtimeContext");
1284
+ const actionId = c2.req.param("actionId");
1285
+ const { inputData } = await c2.req.json();
1286
+ const runId = c2.req.query("runId");
1287
+ const result = await startAsyncAgentBuilderActionHandler$1({
1288
+ mastra,
1289
+ runtimeContext,
1290
+ actionId,
1291
+ runId,
1292
+ inputData
1293
+ });
1294
+ return c2.json(result);
1295
+ } catch (error) {
1296
+ return handleError(error, "Error starting async agent builder action");
1297
+ }
1298
+ }
1299
+ async function startAgentBuilderActionRunHandler(c2) {
1300
+ try {
1301
+ const mastra = c2.get("mastra");
1302
+ const runtimeContext = c2.get("runtimeContext");
1303
+ const actionId = c2.req.param("actionId");
1304
+ const { inputData } = await c2.req.json();
1305
+ const runId = c2.req.query("runId");
1306
+ const result = await startAgentBuilderActionRunHandler$1({
1307
+ mastra,
1308
+ runtimeContext,
1309
+ actionId,
1310
+ runId,
1311
+ inputData
1312
+ });
1313
+ return c2.json(result);
1314
+ } catch (error) {
1315
+ return handleError(error, "Error starting agent builder action run");
1316
+ }
1317
+ }
1318
+ async function watchAgentBuilderActionHandler(c2) {
1319
+ try {
1320
+ const mastra = c2.get("mastra");
1321
+ const logger2 = mastra.getLogger();
1322
+ const actionId = c2.req.param("actionId");
1323
+ const runId = c2.req.query("runId");
1324
+ const eventType = c2.req.query("eventType");
1325
+ if (!runId) {
1326
+ throw new HTTPException(400, { message: "runId required to watch action" });
1327
+ }
1328
+ c2.header("Transfer-Encoding", "chunked");
1329
+ return stream(c2, async (stream7) => {
1330
+ try {
1331
+ const result = await watchAgentBuilderActionHandler$1({
1332
+ mastra,
1333
+ actionId,
1334
+ runId,
1335
+ eventType
1336
+ });
1337
+ const reader = result.getReader();
1338
+ stream7.onAbort(() => {
1339
+ void reader.cancel("request aborted");
1340
+ });
1341
+ let chunkResult;
1342
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
1343
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
1344
+ }
1345
+ } catch (err) {
1346
+ logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
1347
+ }
1348
+ });
1349
+ } catch (error) {
1350
+ return handleError(error, "Error watching agent builder action");
1351
+ }
1352
+ }
1353
+ async function streamAgentBuilderActionHandler(c2) {
1354
+ try {
1355
+ const mastra = c2.get("mastra");
1356
+ const runtimeContext = c2.get("runtimeContext");
1357
+ const logger2 = mastra.getLogger();
1358
+ const actionId = c2.req.param("actionId");
1359
+ const { inputData } = await c2.req.json();
1360
+ const runId = c2.req.query("runId");
1361
+ c2.header("Transfer-Encoding", "chunked");
1362
+ return stream(
1363
+ c2,
1364
+ async (stream7) => {
1365
+ try {
1366
+ const result = await streamAgentBuilderActionHandler$1({
1367
+ mastra,
1368
+ actionId,
1369
+ runId,
1370
+ inputData,
1371
+ runtimeContext
1372
+ });
1373
+ const reader = result.stream.getReader();
1374
+ stream7.onAbort(() => {
1375
+ void reader.cancel("request aborted");
1376
+ });
1377
+ let chunkResult;
1378
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
1379
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
1380
+ }
1381
+ } catch (err) {
1382
+ logger2.error("Error in action stream: " + (err?.message ?? "Unknown error"));
1383
+ }
1384
+ await stream7.close();
1385
+ },
1386
+ async (err) => {
1387
+ logger2.error("Error in action stream: " + err?.message);
1388
+ }
1389
+ );
1390
+ } catch (error) {
1391
+ return handleError(error, "Error streaming agent builder action");
1392
+ }
1393
+ }
1394
+ async function streamVNextAgentBuilderActionHandler(c2) {
1395
+ try {
1396
+ const mastra = c2.get("mastra");
1397
+ const runtimeContext = c2.get("runtimeContext");
1398
+ const logger2 = mastra.getLogger();
1399
+ const actionId = c2.req.param("actionId");
1400
+ const { inputData } = await c2.req.json();
1401
+ const runId = c2.req.query("runId");
1402
+ c2.header("Transfer-Encoding", "chunked");
1403
+ return stream(
1404
+ c2,
1405
+ async (stream7) => {
1406
+ try {
1407
+ const result = await streamVNextAgentBuilderActionHandler$1({
1408
+ mastra,
1409
+ actionId,
1410
+ runId,
1411
+ inputData,
1412
+ runtimeContext
1413
+ });
1414
+ const reader = result.getReader();
1415
+ stream7.onAbort(() => {
1416
+ void reader.cancel("request aborted");
1417
+ });
1418
+ let chunkResult;
1419
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
1420
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
1421
+ }
1422
+ } catch (err) {
1423
+ logger2.error("Error in action VNext stream: " + (err?.message ?? "Unknown error"));
1424
+ }
1425
+ },
1426
+ async (err) => {
1427
+ logger2.error("Error in action VNext stream: " + err?.message);
1428
+ }
1429
+ );
1430
+ } catch (error) {
1431
+ return handleError(error, "Error streaming VNext agent builder action");
1432
+ }
1433
+ }
1434
+ async function resumeAsyncAgentBuilderActionHandler(c2) {
1435
+ try {
1436
+ const mastra = c2.get("mastra");
1437
+ const runtimeContext = c2.get("runtimeContext");
1438
+ const actionId = c2.req.param("actionId");
1439
+ const runId = c2.req.query("runId");
1440
+ const { step, resumeData } = await c2.req.json();
1441
+ if (!runId) {
1442
+ throw new HTTPException(400, { message: "runId required to resume action" });
1443
+ }
1444
+ const result = await resumeAsyncAgentBuilderActionHandler$1({
1445
+ mastra,
1446
+ runtimeContext,
1447
+ actionId,
1448
+ runId,
1449
+ body: { step, resumeData }
1450
+ });
1451
+ return c2.json(result);
1452
+ } catch (error) {
1453
+ return handleError(error, "Error resuming async agent builder action");
1454
+ }
1455
+ }
1456
+ async function resumeAgentBuilderActionHandler(c2) {
1457
+ try {
1458
+ const mastra = c2.get("mastra");
1459
+ const runtimeContext = c2.get("runtimeContext");
1460
+ const actionId = c2.req.param("actionId");
1461
+ const runId = c2.req.query("runId");
1462
+ const { step, resumeData } = await c2.req.json();
1463
+ if (!runId) {
1464
+ throw new HTTPException(400, { message: "runId required to resume action" });
1465
+ }
1466
+ await resumeAgentBuilderActionHandler$1({
1467
+ mastra,
1468
+ runtimeContext,
1469
+ actionId,
1470
+ runId,
1471
+ body: { step, resumeData }
1472
+ });
1473
+ return c2.json({ message: "Action run resumed" });
1474
+ } catch (error) {
1475
+ return handleError(error, "Error resuming agent builder action");
1476
+ }
1477
+ }
1478
+ async function getAgentBuilderActionRunsHandler(c2) {
1479
+ try {
1480
+ const mastra = c2.get("mastra");
1481
+ const actionId = c2.req.param("actionId");
1482
+ const { fromDate, toDate, limit, offset, resourceId } = c2.req.query();
1483
+ const runs = await getAgentBuilderActionRunsHandler$1({
1484
+ mastra,
1485
+ actionId,
1486
+ fromDate: fromDate ? new Date(fromDate) : void 0,
1487
+ toDate: toDate ? new Date(toDate) : void 0,
1488
+ limit: limit ? Number(limit) : void 0,
1489
+ offset: offset ? Number(offset) : void 0,
1490
+ resourceId
1491
+ });
1492
+ return c2.json(runs);
1493
+ } catch (error) {
1494
+ return handleError(error, "Error getting agent builder action runs");
1495
+ }
1496
+ }
1497
+ async function getAgentBuilderActionRunByIdHandler(c2) {
1498
+ try {
1499
+ const mastra = c2.get("mastra");
1500
+ const actionId = c2.req.param("actionId");
1501
+ const runId = c2.req.param("runId");
1502
+ const run = await getAgentBuilderActionRunByIdHandler$1({
1503
+ mastra,
1504
+ actionId,
1505
+ runId
1506
+ });
1507
+ return c2.json(run);
1508
+ } catch (error) {
1509
+ return handleError(error, "Error getting agent builder action run by ID");
1510
+ }
1511
+ }
1512
+ async function getAgentBuilderActionRunExecutionResultHandler(c2) {
1513
+ try {
1514
+ const mastra = c2.get("mastra");
1515
+ const actionId = c2.req.param("actionId");
1516
+ const runId = c2.req.param("runId");
1517
+ const result = await getAgentBuilderActionRunExecutionResultHandler$1({
1518
+ mastra,
1519
+ actionId,
1520
+ runId
1521
+ });
1522
+ return c2.json(result);
1523
+ } catch (error) {
1524
+ return handleError(error, "Error getting agent builder action run execution result");
1525
+ }
1526
+ }
1527
+ async function cancelAgentBuilderActionRunHandler(c2) {
1528
+ try {
1529
+ const mastra = c2.get("mastra");
1530
+ const actionId = c2.req.param("actionId");
1531
+ const runId = c2.req.param("runId");
1532
+ const result = await cancelAgentBuilderActionRunHandler$1({
1533
+ mastra,
1534
+ actionId,
1535
+ runId
1536
+ });
1537
+ return c2.json(result);
1538
+ } catch (error) {
1539
+ return handleError(error, "Error cancelling agent builder action run");
1540
+ }
1541
+ }
1542
+ async function sendAgentBuilderActionRunEventHandler(c2) {
1543
+ try {
1544
+ const mastra = c2.get("mastra");
1545
+ const actionId = c2.req.param("actionId");
1546
+ const runId = c2.req.param("runId");
1547
+ const { event, data } = await c2.req.json();
1548
+ const result = await sendAgentBuilderActionRunEventHandler$1({
1549
+ mastra,
1550
+ actionId,
1551
+ runId,
1552
+ event,
1553
+ data
1554
+ });
1555
+ return c2.json(result);
1556
+ } catch (error) {
1557
+ return handleError(error, "Error sending agent builder action run event");
1558
+ }
1559
+ }
1560
+
1561
+ // src/server/handlers/routes/agent-builder/router.ts
1562
+ function agentBuilderRouter(bodyLimitOptions) {
1563
+ const router = new Hono();
1564
+ router.get(
1565
+ "/",
1566
+ w({
1567
+ description: "Get all agent builder actions",
1568
+ tags: ["agent-builder"],
1569
+ responses: {
1570
+ 200: {
1571
+ description: "List of all agent builder actions"
1572
+ }
1573
+ }
1574
+ }),
1575
+ getAgentBuilderActionsHandler
1576
+ );
1577
+ router.get(
1578
+ "/:actionId",
1579
+ w({
1580
+ description: "Get agent builder action by ID",
1581
+ tags: ["agent-builder"],
1582
+ parameters: [
1583
+ {
1584
+ name: "actionId",
1585
+ in: "path",
1586
+ required: true,
1587
+ schema: { type: "string" }
1588
+ }
1589
+ ],
1590
+ responses: {
1591
+ 200: {
1592
+ description: "Agent builder action details"
1593
+ },
1594
+ 404: {
1595
+ description: "Agent builder action not found"
1596
+ }
1597
+ }
1598
+ }),
1599
+ getAgentBuilderActionByIdHandler
1600
+ );
1601
+ router.get(
1602
+ "/:actionId/runs",
1603
+ w({
1604
+ description: "Get all runs for an agent builder action",
1605
+ tags: ["agent-builder"],
1606
+ parameters: [
1607
+ {
1608
+ name: "actionId",
1609
+ in: "path",
1610
+ required: true,
1611
+ schema: { type: "string" }
1612
+ },
1613
+ { name: "fromDate", in: "query", required: false, schema: { type: "string", format: "date-time" } },
1614
+ { name: "toDate", in: "query", required: false, schema: { type: "string", format: "date-time" } },
1615
+ { name: "limit", in: "query", required: false, schema: { type: "number" } },
1616
+ { name: "offset", in: "query", required: false, schema: { type: "number" } },
1617
+ { name: "resourceId", in: "query", required: false, schema: { type: "string" } }
1618
+ ],
1619
+ responses: {
1620
+ 200: {
1621
+ description: "List of agent builder action runs from storage"
1622
+ }
1623
+ }
1624
+ }),
1625
+ getAgentBuilderActionRunsHandler
1626
+ );
1627
+ router.get(
1628
+ "/:actionId/runs/:runId/execution-result",
1629
+ w({
1630
+ description: "Get execution result for an agent builder action run",
1631
+ tags: ["agent-builder"],
1632
+ parameters: [
1633
+ {
1634
+ name: "actionId",
1635
+ in: "path",
1636
+ required: true,
1637
+ schema: { type: "string" }
1638
+ },
1639
+ {
1640
+ name: "runId",
1641
+ in: "path",
1642
+ required: true,
1643
+ schema: { type: "string" }
1644
+ }
1645
+ ],
1646
+ responses: {
1647
+ 200: {
1648
+ description: "Agent builder action run execution result"
1649
+ },
1650
+ 404: {
1651
+ description: "Agent builder action run execution result not found"
1652
+ }
1653
+ }
1654
+ }),
1655
+ getAgentBuilderActionRunExecutionResultHandler
1656
+ );
1657
+ router.get(
1658
+ "/:actionId/runs/:runId",
1659
+ w({
1660
+ description: "Get agent builder action run by ID",
1661
+ tags: ["agent-builder"],
1662
+ parameters: [
1663
+ {
1664
+ name: "actionId",
1665
+ in: "path",
1666
+ required: true,
1667
+ schema: { type: "string" }
1668
+ },
1669
+ {
1670
+ name: "runId",
1671
+ in: "path",
1672
+ required: true,
1673
+ schema: { type: "string" }
1674
+ }
1675
+ ],
1676
+ responses: {
1677
+ 200: {
1678
+ description: "Agent builder action run by ID"
1679
+ },
1680
+ 404: {
1681
+ description: "Agent builder action run not found"
1682
+ }
1683
+ }
1684
+ }),
1685
+ getAgentBuilderActionRunByIdHandler
1686
+ );
1687
+ router.post(
1688
+ "/:actionId/resume",
1689
+ w({
1690
+ description: "Resume a suspended agent builder action step",
1691
+ tags: ["agent-builder"],
1692
+ parameters: [
1693
+ {
1694
+ name: "actionId",
1695
+ in: "path",
1696
+ required: true,
1697
+ schema: { type: "string" }
1698
+ },
1699
+ {
1700
+ name: "runId",
1701
+ in: "query",
1702
+ required: true,
1703
+ schema: { type: "string" }
1704
+ }
1705
+ ],
1706
+ requestBody: {
1707
+ required: true,
1708
+ content: {
1709
+ "application/json": {
1710
+ schema: {
1711
+ type: "object",
1712
+ properties: {
1713
+ step: {
1714
+ oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
1715
+ },
1716
+ resumeData: { type: "object" },
1717
+ runtimeContext: {
1718
+ type: "object",
1719
+ description: "Runtime context for the agent builder action execution"
1720
+ }
1721
+ },
1722
+ required: ["step"]
1723
+ }
1724
+ }
1725
+ }
1726
+ }
1727
+ }),
1728
+ resumeAgentBuilderActionHandler
1729
+ );
1730
+ router.post(
1731
+ "/:actionId/resume-async",
1732
+ bodyLimit(bodyLimitOptions),
1733
+ w({
1734
+ description: "Resume a suspended agent builder action step",
1735
+ tags: ["agent-builder"],
1736
+ parameters: [
1737
+ {
1738
+ name: "actionId",
1739
+ in: "path",
1740
+ required: true,
1741
+ schema: { type: "string" }
1742
+ },
1743
+ {
1744
+ name: "runId",
1745
+ in: "query",
1746
+ required: true,
1747
+ schema: { type: "string" }
1748
+ }
1749
+ ],
1750
+ requestBody: {
1751
+ required: true,
1752
+ content: {
1753
+ "application/json": {
1754
+ schema: {
1755
+ type: "object",
1756
+ properties: {
1757
+ step: {
1758
+ oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
1759
+ },
1760
+ resumeData: { type: "object" },
1761
+ runtimeContext: {
1762
+ type: "object",
1763
+ description: "Runtime context for the agent builder action execution"
1764
+ }
1765
+ },
1766
+ required: ["step"]
1767
+ }
1768
+ }
1769
+ }
1770
+ }
1771
+ }),
1772
+ resumeAsyncAgentBuilderActionHandler
1773
+ );
1774
+ router.post(
1775
+ "/:actionId/stream",
1776
+ w({
1777
+ description: "Stream agent builder action in real-time",
1778
+ parameters: [
1779
+ {
1780
+ name: "actionId",
1781
+ in: "path",
1782
+ required: true,
1783
+ schema: { type: "string" }
1784
+ },
1785
+ {
1786
+ name: "runId",
1787
+ in: "query",
1788
+ required: false,
1789
+ schema: { type: "string" }
1790
+ }
1791
+ ],
1792
+ requestBody: {
1793
+ required: true,
1794
+ content: {
1795
+ "application/json": {
1796
+ schema: {
1797
+ type: "object",
1798
+ properties: {
1799
+ inputData: { type: "object" },
1800
+ runtimeContext: {
1801
+ type: "object",
1802
+ description: "Runtime context for the agent builder action execution"
1803
+ }
1804
+ }
1805
+ }
1806
+ }
1807
+ }
1808
+ },
1809
+ responses: {
1810
+ 200: {
1811
+ description: "agent builder action run started"
1812
+ },
1813
+ 404: {
1814
+ description: "agent builder action not found"
1815
+ }
1816
+ },
1817
+ tags: ["agent-builder"]
1818
+ }),
1819
+ streamAgentBuilderActionHandler
1820
+ );
1821
+ router.post(
1822
+ "/:actionId/streamVNext",
1823
+ w({
1824
+ description: "Stream agent builder action in real-time using the VNext streaming API",
1825
+ parameters: [
1826
+ {
1827
+ name: "actionId",
1828
+ in: "path",
1829
+ required: true,
1830
+ schema: { type: "string" }
1831
+ },
1832
+ {
1833
+ name: "runId",
1834
+ in: "query",
1835
+ required: false,
1836
+ schema: { type: "string" }
1837
+ }
1838
+ ],
1839
+ requestBody: {
1840
+ required: true,
1841
+ content: {
1842
+ "application/json": {
1843
+ schema: {
1844
+ type: "object",
1845
+ properties: {
1846
+ inputData: { type: "object" },
1847
+ runtimeContext: {
1848
+ type: "object",
1849
+ description: "Runtime context for the agent builder action execution"
1850
+ }
1851
+ }
1852
+ }
1853
+ }
1854
+ }
1855
+ },
1856
+ responses: {
1857
+ 200: {
1858
+ description: "agent builder action run started"
1859
+ },
1860
+ 404: {
1861
+ description: "agent builder action not found"
1862
+ }
1863
+ },
1864
+ tags: ["agent-builder"]
1865
+ }),
1866
+ streamVNextAgentBuilderActionHandler
1867
+ );
1868
+ router.post(
1869
+ "/:actionId/create-run",
1870
+ bodyLimit(bodyLimitOptions),
1871
+ w({
1872
+ description: "Create a new agent builder action run",
1873
+ tags: ["agent-builder"],
1874
+ parameters: [
1875
+ {
1876
+ name: "actionId",
1877
+ in: "path",
1878
+ required: true,
1879
+ schema: { type: "string" }
1880
+ },
1881
+ {
1882
+ name: "runId",
1883
+ in: "query",
1884
+ required: false,
1885
+ schema: { type: "string" }
1886
+ }
1887
+ ],
1888
+ responses: {
1889
+ 200: {
1890
+ description: "New agent builder action run created"
1891
+ }
1892
+ }
1893
+ }),
1894
+ createAgentBuilderActionRunHandler
1895
+ );
1896
+ router.post(
1897
+ "/:actionId/start-async",
1898
+ bodyLimit(bodyLimitOptions),
1899
+ w({
1900
+ description: "Execute/Start an agent builder action",
1901
+ tags: ["agent-builder"],
1902
+ parameters: [
1903
+ {
1904
+ name: "actionId",
1905
+ in: "path",
1906
+ required: true,
1907
+ schema: { type: "string" }
1908
+ },
1909
+ {
1910
+ name: "runId",
1911
+ in: "query",
1912
+ required: false,
1913
+ schema: { type: "string" }
1914
+ }
1915
+ ],
1916
+ requestBody: {
1917
+ required: true,
1918
+ content: {
1919
+ "application/json": {
1920
+ schema: {
1921
+ type: "object",
1922
+ properties: {
1923
+ inputData: { type: "object" },
1924
+ runtimeContext: {
1925
+ type: "object",
1926
+ description: "Runtime context for the agent builder action execution"
1927
+ }
1928
+ }
1929
+ }
1930
+ }
1931
+ }
1932
+ },
1933
+ responses: {
1934
+ 200: {
1935
+ description: "agent builder action execution result"
1936
+ },
1937
+ 404: {
1938
+ description: "agent builder action not found"
1939
+ }
1940
+ }
1941
+ }),
1942
+ startAsyncAgentBuilderActionHandler
1943
+ );
1944
+ router.post(
1945
+ "/:actionId/start",
1946
+ w({
1947
+ description: "Create and start a new agent builder action run",
1948
+ tags: ["agent-builder"],
1949
+ parameters: [
1950
+ {
1951
+ name: "actionId",
1952
+ in: "path",
1953
+ required: true,
1954
+ schema: { type: "string" }
1955
+ },
1956
+ {
1957
+ name: "runId",
1958
+ in: "query",
1959
+ required: true,
1960
+ schema: { type: "string" }
1961
+ }
1962
+ ],
1963
+ requestBody: {
1964
+ required: true,
1965
+ content: {
1966
+ "application/json": {
1967
+ schema: {
1968
+ type: "object",
1969
+ properties: {
1970
+ inputData: { type: "object" },
1971
+ runtimeContext: {
1972
+ type: "object",
1973
+ description: "Runtime context for the agent builder action execution"
1974
+ }
1975
+ }
1976
+ }
1977
+ }
1978
+ }
1979
+ },
1980
+ responses: {
1981
+ 200: {
1982
+ description: "agent builder action run started"
1983
+ },
1984
+ 404: {
1985
+ description: "agent builder action not found"
1986
+ }
1987
+ }
1988
+ }),
1989
+ startAgentBuilderActionRunHandler
1990
+ );
1991
+ router.get(
1992
+ "/:actionId/watch",
1993
+ w({
1994
+ description: "Watch agent builder action transitions in real-time",
1995
+ parameters: [
1996
+ {
1997
+ name: "actionId",
1998
+ in: "path",
1999
+ required: true,
2000
+ schema: { type: "string" }
2001
+ },
2002
+ {
2003
+ name: "runId",
2004
+ in: "query",
2005
+ required: false,
2006
+ schema: { type: "string" }
2007
+ },
2008
+ {
2009
+ name: "eventType",
2010
+ in: "query",
2011
+ required: false,
2012
+ schema: { type: "string", enum: ["watch", "watch-v2"] }
2013
+ }
2014
+ ],
2015
+ tags: ["agent-builder"],
2016
+ responses: {
2017
+ 200: {
2018
+ description: "agent builder action transitions in real-time"
2019
+ }
2020
+ }
2021
+ }),
2022
+ watchAgentBuilderActionHandler
2023
+ );
2024
+ router.post(
2025
+ "/:actionId/runs/:runId/cancel",
2026
+ w({
2027
+ description: "Cancel an agent builder action run",
2028
+ parameters: [
2029
+ {
2030
+ name: "actionId",
2031
+ in: "path",
2032
+ required: true,
2033
+ schema: { type: "string" }
2034
+ },
2035
+ {
2036
+ name: "runId",
2037
+ in: "path",
2038
+ required: true,
2039
+ schema: { type: "string" }
2040
+ }
2041
+ ],
2042
+ tags: ["agent-builder"],
2043
+ responses: {
2044
+ 200: {
2045
+ description: "agent builder action run cancelled"
2046
+ }
2047
+ }
2048
+ }),
2049
+ cancelAgentBuilderActionRunHandler
2050
+ );
2051
+ router.post(
2052
+ "/:actionId/runs/:runId/send-event",
2053
+ w({
2054
+ description: "Send an event to an agent builder action run",
2055
+ parameters: [
2056
+ {
2057
+ name: "actionId",
2058
+ in: "path",
2059
+ required: true,
2060
+ schema: { type: "string" }
2061
+ },
2062
+ {
2063
+ name: "runId",
2064
+ in: "path",
2065
+ required: true,
2066
+ schema: { type: "string" }
2067
+ }
2068
+ ],
2069
+ requestBody: {
2070
+ required: true,
2071
+ content: {
2072
+ "application/json": {
2073
+ schema: { type: "object", properties: { event: { type: "string" }, data: { type: "object" } } }
2074
+ }
2075
+ }
2076
+ },
2077
+ tags: ["agent-builder"],
2078
+ responses: {
2079
+ 200: {
2080
+ description: "agent builder action run event sent"
2081
+ }
2082
+ }
2083
+ }),
2084
+ sendAgentBuilderActionRunEventHandler
2085
+ );
2086
+ return router;
2087
+ }
1240
2088
  var AllowedProviderKeys = {
1241
2089
  openai: "OPENAI_API_KEY",
1242
2090
  xai: "XAI_API_KEY",
@@ -1338,6 +2186,24 @@ async function getLiveEvalsByAgentIdHandler(c2) {
1338
2186
  });
1339
2187
  return c2.json(result);
1340
2188
  }
2189
+ async function generateLegacyHandler(c2) {
2190
+ try {
2191
+ const mastra = c2.get("mastra");
2192
+ const agentId = c2.req.param("agentId");
2193
+ const runtimeContext = c2.get("runtimeContext");
2194
+ const body = await c2.req.json();
2195
+ const result = await generateLegacyHandler$1({
2196
+ mastra,
2197
+ agentId,
2198
+ runtimeContext,
2199
+ body,
2200
+ abortSignal: c2.req.raw.signal
2201
+ });
2202
+ return c2.json(result);
2203
+ } catch (error) {
2204
+ return handleError(error, "Error generating from agent");
2205
+ }
2206
+ }
1341
2207
  async function generateHandler(c2) {
1342
2208
  try {
1343
2209
  const mastra = c2.get("mastra");
@@ -1374,6 +2240,24 @@ async function generateVNextHandler(c2) {
1374
2240
  return handleError(error, "Error generating vnext from agent");
1375
2241
  }
1376
2242
  }
2243
+ async function streamGenerateLegacyHandler(c2) {
2244
+ try {
2245
+ const mastra = c2.get("mastra");
2246
+ const agentId = c2.req.param("agentId");
2247
+ const runtimeContext = c2.get("runtimeContext");
2248
+ const body = await c2.req.json();
2249
+ const streamResponse = await streamGenerateLegacyHandler$1({
2250
+ mastra,
2251
+ agentId,
2252
+ runtimeContext,
2253
+ body,
2254
+ abortSignal: c2.req.raw.signal
2255
+ });
2256
+ return streamResponse;
2257
+ } catch (error) {
2258
+ return handleError(error, "Error streaming from agent");
2259
+ }
2260
+ }
1377
2261
  async function streamGenerateHandler(c2) {
1378
2262
  try {
1379
2263
  const mastra = c2.get("mastra");
@@ -1402,7 +2286,7 @@ async function streamVNextGenerateHandler(c2) {
1402
2286
  c2.header("Transfer-Encoding", "chunked");
1403
2287
  return stream(
1404
2288
  c2,
1405
- async (stream6) => {
2289
+ async (stream7) => {
1406
2290
  try {
1407
2291
  const streamResponse = await streamVNextGenerateHandler$1({
1408
2292
  mastra,
@@ -1412,20 +2296,20 @@ async function streamVNextGenerateHandler(c2) {
1412
2296
  abortSignal: c2.req.raw.signal
1413
2297
  });
1414
2298
  const reader = streamResponse.fullStream.getReader();
1415
- stream6.onAbort(() => {
2299
+ stream7.onAbort(() => {
1416
2300
  void reader.cancel("request aborted");
1417
2301
  });
1418
2302
  let chunkResult;
1419
2303
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
1420
- await stream6.write(`data: ${JSON.stringify(chunkResult.value)}
2304
+ await stream7.write(`data: ${JSON.stringify(chunkResult.value)}
1421
2305
 
1422
2306
  `);
1423
2307
  }
1424
- await stream6.write("data: [DONE]\n\n");
2308
+ await stream7.write("data: [DONE]\n\n");
1425
2309
  } catch (err) {
1426
2310
  logger2.error("Error in streamVNext generate: " + (err?.message ?? "Unknown error"));
1427
2311
  }
1428
- await stream6.close();
2312
+ await stream7.close();
1429
2313
  },
1430
2314
  async (err) => {
1431
2315
  logger2.error("Error in watch stream: " + err?.message);
@@ -1673,6 +2557,23 @@ function executeToolHandler(tools) {
1673
2557
  }
1674
2558
  };
1675
2559
  }
2560
+ async function getAgentToolHandler(c2) {
2561
+ try {
2562
+ const mastra = c2.get("mastra");
2563
+ const runtimeContext = c2.get("runtimeContext");
2564
+ const agentId = c2.req.param("agentId");
2565
+ const toolId = c2.req.param("toolId");
2566
+ const result = await getAgentToolHandler$1({
2567
+ mastra,
2568
+ agentId,
2569
+ toolId,
2570
+ runtimeContext
2571
+ });
2572
+ return c2.json(result);
2573
+ } catch (error) {
2574
+ return handleError(error, "Error getting agent tool");
2575
+ }
2576
+ }
1676
2577
  async function executeAgentToolHandler(c2) {
1677
2578
  try {
1678
2579
  const mastra = c2.get("mastra");
@@ -1847,6 +2748,57 @@ function agentsRouter(bodyLimitOptions) {
1847
2748
  }),
1848
2749
  getLiveEvalsByAgentIdHandler
1849
2750
  );
2751
+ router.post(
2752
+ "/:agentId/generate-legacy",
2753
+ bodyLimit(bodyLimitOptions),
2754
+ w({
2755
+ description: "Generate a response from an agent",
2756
+ tags: ["agents"],
2757
+ parameters: [
2758
+ {
2759
+ name: "agentId",
2760
+ in: "path",
2761
+ required: true,
2762
+ schema: { type: "string" }
2763
+ }
2764
+ ],
2765
+ requestBody: {
2766
+ required: true,
2767
+ content: {
2768
+ "application/json": {
2769
+ schema: {
2770
+ type: "object",
2771
+ properties: {
2772
+ messages: {
2773
+ type: "array",
2774
+ items: { type: "object" }
2775
+ },
2776
+ threadId: { type: "string" },
2777
+ resourceId: { type: "string", description: "The resource ID for the conversation" },
2778
+ resourceid: {
2779
+ type: "string",
2780
+ description: "The resource ID for the conversation (deprecated, use resourceId instead)",
2781
+ deprecated: true
2782
+ },
2783
+ runId: { type: "string" },
2784
+ output: { type: "object" }
2785
+ },
2786
+ required: ["messages"]
2787
+ }
2788
+ }
2789
+ }
2790
+ },
2791
+ responses: {
2792
+ 200: {
2793
+ description: "Generated response"
2794
+ },
2795
+ 404: {
2796
+ description: "Agent not found"
2797
+ }
2798
+ }
2799
+ }),
2800
+ generateLegacyHandler
2801
+ );
1850
2802
  router.post(
1851
2803
  "/:agentId/generate",
1852
2804
  bodyLimit(bodyLimitOptions),
@@ -1972,6 +2924,57 @@ function agentsRouter(bodyLimitOptions) {
1972
2924
  }),
1973
2925
  streamVNextGenerateHandler
1974
2926
  );
2927
+ router.post(
2928
+ "/:agentId/stream-legacy",
2929
+ bodyLimit(bodyLimitOptions),
2930
+ w({
2931
+ description: "Stream a response from an agent",
2932
+ tags: ["agents"],
2933
+ parameters: [
2934
+ {
2935
+ name: "agentId",
2936
+ in: "path",
2937
+ required: true,
2938
+ schema: { type: "string" }
2939
+ }
2940
+ ],
2941
+ requestBody: {
2942
+ required: true,
2943
+ content: {
2944
+ "application/json": {
2945
+ schema: {
2946
+ type: "object",
2947
+ properties: {
2948
+ messages: {
2949
+ type: "array",
2950
+ items: { type: "object" }
2951
+ },
2952
+ threadId: { type: "string" },
2953
+ resourceId: { type: "string", description: "The resource ID for the conversation" },
2954
+ resourceid: {
2955
+ type: "string",
2956
+ description: "The resource ID for the conversation (deprecated, use resourceId instead)",
2957
+ deprecated: true
2958
+ },
2959
+ runId: { type: "string" },
2960
+ output: { type: "object" }
2961
+ },
2962
+ required: ["messages"]
2963
+ }
2964
+ }
2965
+ }
2966
+ },
2967
+ responses: {
2968
+ 200: {
2969
+ description: "Streamed response"
2970
+ },
2971
+ 404: {
2972
+ description: "Agent not found"
2973
+ }
2974
+ }
2975
+ }),
2976
+ streamGenerateLegacyHandler
2977
+ );
1975
2978
  router.post(
1976
2979
  "/:agentId/stream",
1977
2980
  bodyLimit(bodyLimitOptions),
@@ -2593,6 +3596,36 @@ function agentsRouter(bodyLimitOptions) {
2593
3596
  }),
2594
3597
  listenHandler
2595
3598
  );
3599
+ router.get(
3600
+ "/:agentId/tools/:toolId",
3601
+ w({
3602
+ description: "Get agent tool by ID",
3603
+ tags: ["agents"],
3604
+ parameters: [
3605
+ {
3606
+ name: "agentId",
3607
+ in: "path",
3608
+ required: true,
3609
+ schema: { type: "string" }
3610
+ },
3611
+ {
3612
+ name: "toolId",
3613
+ in: "path",
3614
+ required: true,
3615
+ schema: { type: "string" }
3616
+ }
3617
+ ],
3618
+ responses: {
3619
+ 200: {
3620
+ description: "Tool details"
3621
+ },
3622
+ 404: {
3623
+ description: "Tool or agent not found"
3624
+ }
3625
+ }
3626
+ }),
3627
+ getAgentToolHandler
3628
+ );
2596
3629
  router.post(
2597
3630
  "/:agentId/tools/:toolId/execute",
2598
3631
  bodyLimit(bodyLimitOptions),
@@ -7023,7 +8056,7 @@ async function streamGenerateVNextNetworkHandler(c2) {
7023
8056
  c2.header("Transfer-Encoding", "chunked");
7024
8057
  return stream(
7025
8058
  c2,
7026
- async (stream6) => {
8059
+ async (stream7) => {
7027
8060
  try {
7028
8061
  const result = await streamGenerateVNextNetworkHandler$1({
7029
8062
  mastra,
@@ -7032,12 +8065,12 @@ async function streamGenerateVNextNetworkHandler(c2) {
7032
8065
  body
7033
8066
  });
7034
8067
  const reader = result.stream.getReader();
7035
- stream6.onAbort(() => {
8068
+ stream7.onAbort(() => {
7036
8069
  void reader.cancel("request aborted");
7037
8070
  });
7038
8071
  let chunkResult;
7039
8072
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
7040
- await stream6.write(JSON.stringify(chunkResult.value) + "");
8073
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
7041
8074
  }
7042
8075
  } catch (err) {
7043
8076
  mastra.getLogger().error("Error in network stream: " + (err?.message ?? "Unknown error"));
@@ -7078,7 +8111,7 @@ async function loopStreamVNextNetworkHandler(c2) {
7078
8111
  c2.header("Transfer-Encoding", "chunked");
7079
8112
  return stream(
7080
8113
  c2,
7081
- async (stream6) => {
8114
+ async (stream7) => {
7082
8115
  try {
7083
8116
  const result = await loopStreamVNextNetworkHandler$1({
7084
8117
  mastra,
@@ -7087,12 +8120,12 @@ async function loopStreamVNextNetworkHandler(c2) {
7087
8120
  body
7088
8121
  });
7089
8122
  const reader = result.stream.getReader();
7090
- stream6.onAbort(() => {
8123
+ stream7.onAbort(() => {
7091
8124
  void reader.cancel("request aborted");
7092
8125
  });
7093
8126
  let chunkResult;
7094
8127
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
7095
- await stream6.write(JSON.stringify(chunkResult.value) + "");
8128
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
7096
8129
  }
7097
8130
  } catch (err) {
7098
8131
  mastra.getLogger().error("Error in network loop stream: " + (err?.message ?? "Unknown error"));
@@ -8478,7 +9511,7 @@ function watchWorkflowHandler(c2) {
8478
9511
  c2.header("Transfer-Encoding", "chunked");
8479
9512
  return stream(
8480
9513
  c2,
8481
- async (stream6) => {
9514
+ async (stream7) => {
8482
9515
  try {
8483
9516
  const result = await watchWorkflowHandler$1({
8484
9517
  mastra,
@@ -8486,12 +9519,12 @@ function watchWorkflowHandler(c2) {
8486
9519
  runId
8487
9520
  });
8488
9521
  const reader = result.getReader();
8489
- stream6.onAbort(() => {
9522
+ stream7.onAbort(() => {
8490
9523
  void reader.cancel("request aborted");
8491
9524
  });
8492
9525
  let chunkResult;
8493
9526
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
8494
- await stream6.write(JSON.stringify(chunkResult.value) + "");
9527
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
8495
9528
  }
8496
9529
  } catch (err) {
8497
9530
  logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
@@ -8516,7 +9549,7 @@ async function streamWorkflowHandler(c2) {
8516
9549
  c2.header("Transfer-Encoding", "chunked");
8517
9550
  return stream(
8518
9551
  c2,
8519
- async (stream6) => {
9552
+ async (stream7) => {
8520
9553
  try {
8521
9554
  const result = await streamWorkflowHandler$1({
8522
9555
  mastra,
@@ -8526,17 +9559,17 @@ async function streamWorkflowHandler(c2) {
8526
9559
  runtimeContext
8527
9560
  });
8528
9561
  const reader = result.stream.getReader();
8529
- stream6.onAbort(() => {
9562
+ stream7.onAbort(() => {
8530
9563
  void reader.cancel("request aborted");
8531
9564
  });
8532
9565
  let chunkResult;
8533
9566
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
8534
- await stream6.write(JSON.stringify(chunkResult.value) + "");
9567
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
8535
9568
  }
8536
9569
  } catch (err) {
8537
9570
  logger2.error("Error in workflow stream: " + (err?.message ?? "Unknown error"));
8538
9571
  }
8539
- await stream6.close();
9572
+ await stream7.close();
8540
9573
  },
8541
9574
  async (err) => {
8542
9575
  logger2.error("Error in workflow stream: " + err?.message);
@@ -8557,7 +9590,7 @@ async function streamVNextWorkflowHandler(c2) {
8557
9590
  c2.header("Transfer-Encoding", "chunked");
8558
9591
  return stream(
8559
9592
  c2,
8560
- async (stream6) => {
9593
+ async (stream7) => {
8561
9594
  try {
8562
9595
  const result = await streamVNextWorkflowHandler$1({
8563
9596
  mastra,
@@ -8567,12 +9600,12 @@ async function streamVNextWorkflowHandler(c2) {
8567
9600
  runtimeContext
8568
9601
  });
8569
9602
  const reader = result.getReader();
8570
- stream6.onAbort(() => {
9603
+ stream7.onAbort(() => {
8571
9604
  void reader.cancel("request aborted");
8572
9605
  });
8573
9606
  let chunkResult;
8574
9607
  while ((chunkResult = await reader.read()) && !chunkResult.done) {
8575
- await stream6.write(JSON.stringify(chunkResult.value) + "");
9608
+ await stream7.write(JSON.stringify(chunkResult.value) + "");
8576
9609
  }
8577
9610
  } catch (err) {
8578
9611
  logger2.error("Error in workflow VNext stream: " + (err?.message ?? "Unknown error"));
@@ -8800,20 +9833,20 @@ function watchLegacyWorkflowHandler(c2) {
8800
9833
  }
8801
9834
  return stream(
8802
9835
  c2,
8803
- async (stream6) => {
9836
+ async (stream7) => {
8804
9837
  try {
8805
9838
  const result = await watchLegacyWorkflowHandler$1({
8806
9839
  mastra,
8807
9840
  workflowId,
8808
9841
  runId
8809
9842
  });
8810
- stream6.onAbort(() => {
9843
+ stream7.onAbort(() => {
8811
9844
  if (!result.locked) {
8812
9845
  return result.cancel();
8813
9846
  }
8814
9847
  });
8815
9848
  for await (const chunk of result) {
8816
- await stream6.write(chunk.toString() + "");
9849
+ await stream7.write(chunk.toString() + "");
8817
9850
  }
8818
9851
  } catch (err) {
8819
9852
  console.log(err);
@@ -10113,6 +11146,7 @@ async function createHonoServer(mastra, options = {
10113
11146
  app.route("/api/workflows", workflowsRouter(bodyLimitOptions));
10114
11147
  app.route("/api/logs", logsRouter());
10115
11148
  app.route("/api/scores", scoresRouter(bodyLimitOptions));
11149
+ app.route("/api/agent-builder", agentBuilderRouter(bodyLimitOptions));
10116
11150
  app.route("/api/tools", toolsRouter(bodyLimitOptions, options.tools));
10117
11151
  app.route("/api/vector", vectorRouter(bodyLimitOptions));
10118
11152
  if (options?.isDev || server?.build?.openAPIDocs || server?.build?.swaggerUI) {