@mastra/deployer 0.19.1-alpha.1 → 0.20.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
- package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
- package/dist/build/analyze.cjs +2 -2
- package/dist/build/analyze.js +1 -1
- package/dist/build/bundler.cjs +3 -3
- package/dist/build/bundler.js +1 -1
- package/dist/build/index.cjs +12 -12
- package/dist/build/index.js +4 -4
- package/dist/build/utils.d.ts +1 -1
- package/dist/build/utils.d.ts.map +1 -1
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/{chunk-7XYNDWHM.cjs → chunk-4I4DWMYP.cjs} +81 -33
- package/dist/chunk-4I4DWMYP.cjs.map +1 -0
- package/dist/{chunk-RZGW2FV5.js → chunk-7YSO4XUX.js} +3 -3
- package/dist/{chunk-RZGW2FV5.js.map → chunk-7YSO4XUX.js.map} +1 -1
- package/dist/{chunk-JKSGIHN5.cjs → chunk-D5U2TTNK.cjs} +5 -5
- package/dist/{chunk-JKSGIHN5.cjs.map → chunk-D5U2TTNK.cjs.map} +1 -1
- package/dist/{chunk-LSVYJCYH.cjs → chunk-H7R3PAM4.cjs} +17 -17
- package/dist/{chunk-LSVYJCYH.cjs.map → chunk-H7R3PAM4.cjs.map} +1 -1
- package/dist/{chunk-C63Y45DE.cjs → chunk-OWF6JR2D.cjs} +9 -9
- package/dist/{chunk-C63Y45DE.cjs.map → chunk-OWF6JR2D.cjs.map} +1 -1
- package/dist/{chunk-5HLB56SX.cjs → chunk-QT4EHSOA.cjs} +14 -14
- package/dist/{chunk-5HLB56SX.cjs.map → chunk-QT4EHSOA.cjs.map} +1 -1
- package/dist/{chunk-P76ACDWK.js → chunk-SLXO6AYI.js} +3 -3
- package/dist/{chunk-P76ACDWK.js.map → chunk-SLXO6AYI.js.map} +1 -1
- package/dist/{chunk-RCG3326W.js → chunk-V6M3WK2G.js} +5 -5
- package/dist/{chunk-RCG3326W.js.map → chunk-V6M3WK2G.js.map} +1 -1
- package/dist/{chunk-E56YDU6G.js → chunk-YA2QB5O6.js} +80 -33
- package/dist/chunk-YA2QB5O6.js.map +1 -0
- package/dist/{chunk-G6MQAGP6.js → chunk-YY75MSEU.js} +4 -4
- package/dist/{chunk-G6MQAGP6.js.map → chunk-YY75MSEU.js.map} +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.js +2 -2
- package/dist/server/handlers/routes/agents/handlers.d.ts +3 -3
- package/dist/server/handlers/routes/agents/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/agents/router.d.ts.map +1 -1
- package/dist/server/handlers/routes/memory/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/workflows/handlers.d.ts +1 -0
- package/dist/server/handlers/routes/workflows/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/workflows/router.d.ts.map +1 -1
- package/dist/server/index.cjs +389 -558
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +391 -560
- package/dist/server/index.js.map +1 -1
- package/package.json +8 -7
- package/dist/chunk-7XYNDWHM.cjs.map +0 -1
- package/dist/chunk-E56YDU6G.js.map +0 -1
- package/dist/server/handlers/routes/networks/router.d.ts +0 -4
- package/dist/server/handlers/routes/networks/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/networks/vNextNetwork.d.ts +0 -8
- package/dist/server/handlers/routes/networks/vNextNetwork.d.ts.map +0 -1
package/dist/server/index.cjs
CHANGED
|
@@ -35,7 +35,6 @@ var logs = require('@mastra/server/handlers/logs');
|
|
|
35
35
|
var util = require('util');
|
|
36
36
|
var buffer = require('buffer');
|
|
37
37
|
var memory = require('@mastra/server/handlers/memory');
|
|
38
|
-
var vNextNetwork = require('@mastra/server/handlers/vNextNetwork');
|
|
39
38
|
var aiTracing = require('@mastra/core/ai-tracing');
|
|
40
39
|
var observability = require('@mastra/server/handlers/observability');
|
|
41
40
|
var scores = require('@mastra/server/handlers/scores');
|
|
@@ -353,13 +352,13 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
353
352
|
}
|
|
354
353
|
}
|
|
355
354
|
}
|
|
356
|
-
function writeFromReadableStream(
|
|
357
|
-
if (
|
|
355
|
+
function writeFromReadableStream(stream6, writable) {
|
|
356
|
+
if (stream6.locked) {
|
|
358
357
|
throw new TypeError("ReadableStream is locked.");
|
|
359
358
|
} else if (writable.destroyed) {
|
|
360
359
|
return;
|
|
361
360
|
}
|
|
362
|
-
return writeFromReadableStreamDefaultReader(
|
|
361
|
+
return writeFromReadableStreamDefaultReader(stream6.getReader(), writable);
|
|
363
362
|
}
|
|
364
363
|
var buildOutgoingHttpHeaders = (headers) => {
|
|
365
364
|
const res = {};
|
|
@@ -624,21 +623,21 @@ var ENCODINGS = {
|
|
|
624
623
|
gzip: ".gz"
|
|
625
624
|
};
|
|
626
625
|
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
627
|
-
var createStreamBody = (
|
|
626
|
+
var createStreamBody = (stream6) => {
|
|
628
627
|
const body = new ReadableStream({
|
|
629
628
|
start(controller) {
|
|
630
|
-
|
|
629
|
+
stream6.on("data", (chunk) => {
|
|
631
630
|
controller.enqueue(chunk);
|
|
632
631
|
});
|
|
633
|
-
|
|
632
|
+
stream6.on("error", (err) => {
|
|
634
633
|
controller.error(err);
|
|
635
634
|
});
|
|
636
|
-
|
|
635
|
+
stream6.on("end", () => {
|
|
637
636
|
controller.close();
|
|
638
637
|
});
|
|
639
638
|
},
|
|
640
639
|
cancel() {
|
|
641
|
-
|
|
640
|
+
stream6.destroy();
|
|
642
641
|
}
|
|
643
642
|
});
|
|
644
643
|
return body;
|
|
@@ -730,10 +729,10 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
730
729
|
end = size - 1;
|
|
731
730
|
}
|
|
732
731
|
const chunksize = end - start + 1;
|
|
733
|
-
const
|
|
732
|
+
const stream6 = fs.createReadStream(path$1, { start, end });
|
|
734
733
|
c2.header("Content-Length", chunksize.toString());
|
|
735
734
|
c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
736
|
-
return c2.body(createStreamBody(
|
|
735
|
+
return c2.body(createStreamBody(stream6), 206);
|
|
737
736
|
};
|
|
738
737
|
};
|
|
739
738
|
var RENDER_TYPE = {
|
|
@@ -1031,15 +1030,15 @@ async function getAgentExecutionHandler(c2) {
|
|
|
1031
1030
|
if (body.method === "message/stream") {
|
|
1032
1031
|
return streaming.stream(
|
|
1033
1032
|
c2,
|
|
1034
|
-
async (
|
|
1033
|
+
async (stream6) => {
|
|
1035
1034
|
try {
|
|
1036
|
-
|
|
1035
|
+
stream6.onAbort(() => {
|
|
1037
1036
|
if (!result.locked) {
|
|
1038
1037
|
return result.cancel();
|
|
1039
1038
|
}
|
|
1040
1039
|
});
|
|
1041
1040
|
for await (const chunk of result) {
|
|
1042
|
-
await
|
|
1041
|
+
await stream6.write(JSON.stringify(chunk) + "");
|
|
1043
1042
|
}
|
|
1044
1043
|
} catch (err) {
|
|
1045
1044
|
logger2.error("Error in message/stream stream: " + err?.message);
|
|
@@ -1286,7 +1285,7 @@ var authorizationMiddleware = async (c2, next) => {
|
|
|
1286
1285
|
var clients = /* @__PURE__ */ new Set();
|
|
1287
1286
|
var hotReloadDisabled = false;
|
|
1288
1287
|
function handleClientsRefresh(c2) {
|
|
1289
|
-
const
|
|
1288
|
+
const stream6 = new ReadableStream({
|
|
1290
1289
|
start(controller) {
|
|
1291
1290
|
clients.add(controller);
|
|
1292
1291
|
controller.enqueue("data: connected\n\n");
|
|
@@ -1295,7 +1294,7 @@ function handleClientsRefresh(c2) {
|
|
|
1295
1294
|
});
|
|
1296
1295
|
}
|
|
1297
1296
|
});
|
|
1298
|
-
return new Response(
|
|
1297
|
+
return new Response(stream6, {
|
|
1299
1298
|
headers: {
|
|
1300
1299
|
"Content-Type": "text/event-stream",
|
|
1301
1300
|
"Cache-Control": "no-cache",
|
|
@@ -1553,7 +1552,7 @@ async function watchAgentBuilderActionHandler(c2) {
|
|
|
1553
1552
|
throw new httpException.HTTPException(400, { message: "runId required to watch action" });
|
|
1554
1553
|
}
|
|
1555
1554
|
c2.header("Transfer-Encoding", "chunked");
|
|
1556
|
-
return streaming.stream(c2, async (
|
|
1555
|
+
return streaming.stream(c2, async (stream6) => {
|
|
1557
1556
|
try {
|
|
1558
1557
|
disableHotReload();
|
|
1559
1558
|
const result = await agentBuilder.watchAgentBuilderActionHandler({
|
|
@@ -1563,12 +1562,12 @@ async function watchAgentBuilderActionHandler(c2) {
|
|
|
1563
1562
|
eventType
|
|
1564
1563
|
});
|
|
1565
1564
|
const reader = result.getReader();
|
|
1566
|
-
|
|
1565
|
+
stream6.onAbort(() => {
|
|
1567
1566
|
void reader.cancel("request aborted");
|
|
1568
1567
|
});
|
|
1569
1568
|
let chunkResult;
|
|
1570
1569
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1571
|
-
await
|
|
1570
|
+
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
1572
1571
|
}
|
|
1573
1572
|
enableHotReload();
|
|
1574
1573
|
} catch (err) {
|
|
@@ -1592,7 +1591,7 @@ async function streamAgentBuilderActionHandler(c2) {
|
|
|
1592
1591
|
c2.header("Transfer-Encoding", "chunked");
|
|
1593
1592
|
return streaming.stream(
|
|
1594
1593
|
c2,
|
|
1595
|
-
async (
|
|
1594
|
+
async (stream6) => {
|
|
1596
1595
|
try {
|
|
1597
1596
|
disableHotReload();
|
|
1598
1597
|
const result = await agentBuilder.streamAgentBuilderActionHandler({
|
|
@@ -1603,17 +1602,17 @@ async function streamAgentBuilderActionHandler(c2) {
|
|
|
1603
1602
|
runtimeContext
|
|
1604
1603
|
});
|
|
1605
1604
|
const reader = result.stream.getReader();
|
|
1606
|
-
|
|
1605
|
+
stream6.onAbort(() => {
|
|
1607
1606
|
void reader.cancel("request aborted");
|
|
1608
1607
|
});
|
|
1609
1608
|
let chunkResult;
|
|
1610
1609
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1611
|
-
await
|
|
1610
|
+
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
1612
1611
|
}
|
|
1613
1612
|
} catch (err) {
|
|
1614
1613
|
logger2.error("Error in action stream: " + (err?.message ?? "Unknown error"));
|
|
1615
1614
|
}
|
|
1616
|
-
await
|
|
1615
|
+
await stream6.close();
|
|
1617
1616
|
enableHotReload();
|
|
1618
1617
|
},
|
|
1619
1618
|
async (err) => {
|
|
@@ -1636,7 +1635,7 @@ async function streamVNextAgentBuilderActionHandler(c2) {
|
|
|
1636
1635
|
c2.header("Transfer-Encoding", "chunked");
|
|
1637
1636
|
return streaming.stream(
|
|
1638
1637
|
c2,
|
|
1639
|
-
async (
|
|
1638
|
+
async (stream6) => {
|
|
1640
1639
|
try {
|
|
1641
1640
|
disableHotReload();
|
|
1642
1641
|
const result = await agentBuilder.streamVNextAgentBuilderActionHandler({
|
|
@@ -1647,12 +1646,12 @@ async function streamVNextAgentBuilderActionHandler(c2) {
|
|
|
1647
1646
|
runtimeContext
|
|
1648
1647
|
});
|
|
1649
1648
|
const reader = result.getReader();
|
|
1650
|
-
|
|
1649
|
+
stream6.onAbort(() => {
|
|
1651
1650
|
void reader.cancel("request aborted");
|
|
1652
1651
|
});
|
|
1653
1652
|
let chunkResult;
|
|
1654
1653
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1655
|
-
await
|
|
1654
|
+
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
1656
1655
|
}
|
|
1657
1656
|
} catch (err) {
|
|
1658
1657
|
logger2.error("Error in action VNext stream: " + (err?.message ?? "Unknown error"));
|
|
@@ -2500,61 +2499,112 @@ async function generateHandler(c2) {
|
|
|
2500
2499
|
return handleError(error, "Error generating from agent");
|
|
2501
2500
|
}
|
|
2502
2501
|
}
|
|
2503
|
-
async function
|
|
2502
|
+
async function streamGenerateLegacyHandler(c2) {
|
|
2504
2503
|
try {
|
|
2505
2504
|
const mastra = c2.get("mastra");
|
|
2506
2505
|
const agentId = c2.req.param("agentId");
|
|
2507
2506
|
const runtimeContext = c2.get("runtimeContext");
|
|
2508
2507
|
const body = await c2.req.json();
|
|
2509
|
-
const
|
|
2508
|
+
const streamResponse = await agents.streamGenerateLegacyHandler({
|
|
2510
2509
|
mastra,
|
|
2511
2510
|
agentId,
|
|
2512
2511
|
runtimeContext,
|
|
2513
2512
|
body,
|
|
2514
2513
|
abortSignal: c2.req.raw.signal
|
|
2515
2514
|
});
|
|
2516
|
-
return
|
|
2515
|
+
return streamResponse;
|
|
2517
2516
|
} catch (error) {
|
|
2518
|
-
return handleError(error, "Error
|
|
2517
|
+
return handleError(error, "Error streaming from agent");
|
|
2519
2518
|
}
|
|
2520
2519
|
}
|
|
2521
|
-
async function
|
|
2520
|
+
async function streamGenerateHandler(c2) {
|
|
2522
2521
|
try {
|
|
2523
2522
|
const mastra = c2.get("mastra");
|
|
2524
2523
|
const agentId = c2.req.param("agentId");
|
|
2525
2524
|
const runtimeContext = c2.get("runtimeContext");
|
|
2526
2525
|
const body = await c2.req.json();
|
|
2527
|
-
const
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2526
|
+
const logger2 = mastra.getLogger();
|
|
2527
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
2528
|
+
return streaming.stream(
|
|
2529
|
+
c2,
|
|
2530
|
+
async (stream6) => {
|
|
2531
|
+
try {
|
|
2532
|
+
const streamResponse = await agents.streamGenerateHandler({
|
|
2533
|
+
mastra,
|
|
2534
|
+
agentId,
|
|
2535
|
+
runtimeContext,
|
|
2536
|
+
body,
|
|
2537
|
+
abortSignal: c2.req.raw.signal
|
|
2538
|
+
});
|
|
2539
|
+
const reader = streamResponse.fullStream.getReader();
|
|
2540
|
+
stream6.onAbort(() => {
|
|
2541
|
+
void reader.cancel("request aborted");
|
|
2542
|
+
});
|
|
2543
|
+
let chunkResult;
|
|
2544
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2545
|
+
await stream6.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2546
|
+
|
|
2547
|
+
`);
|
|
2548
|
+
}
|
|
2549
|
+
await stream6.write("data: [DONE]\n\n");
|
|
2550
|
+
} catch (err) {
|
|
2551
|
+
logger2.error("Error in stream generate: " + (err?.message ?? "Unknown error"));
|
|
2552
|
+
}
|
|
2553
|
+
await stream6.close();
|
|
2554
|
+
},
|
|
2555
|
+
async (err) => {
|
|
2556
|
+
logger2.error("Error in watch stream: " + err?.message);
|
|
2557
|
+
}
|
|
2558
|
+
);
|
|
2535
2559
|
} catch (error) {
|
|
2536
2560
|
return handleError(error, "Error streaming from agent");
|
|
2537
2561
|
}
|
|
2538
2562
|
}
|
|
2539
|
-
async function
|
|
2563
|
+
async function approveToolCallHandler(c2) {
|
|
2540
2564
|
try {
|
|
2541
2565
|
const mastra = c2.get("mastra");
|
|
2542
2566
|
const agentId = c2.req.param("agentId");
|
|
2543
2567
|
const runtimeContext = c2.get("runtimeContext");
|
|
2544
2568
|
const body = await c2.req.json();
|
|
2545
|
-
const
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2569
|
+
const logger2 = mastra.getLogger();
|
|
2570
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
2571
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
2572
|
+
return streaming.stream(
|
|
2573
|
+
c2,
|
|
2574
|
+
async (stream6) => {
|
|
2575
|
+
try {
|
|
2576
|
+
const streamResponse = await agents.approveToolCallHandler({
|
|
2577
|
+
mastra,
|
|
2578
|
+
runtimeContext,
|
|
2579
|
+
agentId,
|
|
2580
|
+
body,
|
|
2581
|
+
abortSignal: c2.req.raw.signal
|
|
2582
|
+
});
|
|
2583
|
+
const reader = streamResponse.fullStream.getReader();
|
|
2584
|
+
stream6.onAbort(() => {
|
|
2585
|
+
void reader.cancel("request aborted");
|
|
2586
|
+
});
|
|
2587
|
+
let chunkResult;
|
|
2588
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2589
|
+
await stream6.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2590
|
+
|
|
2591
|
+
`);
|
|
2592
|
+
}
|
|
2593
|
+
await stream6.write("data: [DONE]\n\n");
|
|
2594
|
+
} catch (err) {
|
|
2595
|
+
logger2.error("Error in approve tool call: " + (err?.message ?? "Unknown error"));
|
|
2596
|
+
}
|
|
2597
|
+
await stream6.close();
|
|
2598
|
+
},
|
|
2599
|
+
async (err) => {
|
|
2600
|
+
logger2.error("Error in watch stream: " + err?.message);
|
|
2601
|
+
}
|
|
2602
|
+
);
|
|
2553
2603
|
} catch (error) {
|
|
2554
|
-
return handleError(error, "Error
|
|
2604
|
+
return handleError(error, "Error approving tool call");
|
|
2555
2605
|
}
|
|
2556
2606
|
}
|
|
2557
|
-
async function
|
|
2607
|
+
async function declineToolCallHandler(c2) {
|
|
2558
2608
|
try {
|
|
2559
2609
|
const mastra = c2.get("mastra");
|
|
2560
2610
|
const agentId = c2.req.param("agentId");
|
|
@@ -2564,37 +2614,37 @@ async function streamVNextGenerateHandler(c2) {
|
|
|
2564
2614
|
c2.header("Transfer-Encoding", "chunked");
|
|
2565
2615
|
return streaming.stream(
|
|
2566
2616
|
c2,
|
|
2567
|
-
async (
|
|
2617
|
+
async (stream6) => {
|
|
2568
2618
|
try {
|
|
2569
|
-
const streamResponse = await agents.
|
|
2619
|
+
const streamResponse = await agents.declineToolCallHandler({
|
|
2570
2620
|
mastra,
|
|
2571
|
-
agentId,
|
|
2572
2621
|
runtimeContext,
|
|
2622
|
+
agentId,
|
|
2573
2623
|
body,
|
|
2574
2624
|
abortSignal: c2.req.raw.signal
|
|
2575
2625
|
});
|
|
2576
2626
|
const reader = streamResponse.fullStream.getReader();
|
|
2577
|
-
|
|
2627
|
+
stream6.onAbort(() => {
|
|
2578
2628
|
void reader.cancel("request aborted");
|
|
2579
2629
|
});
|
|
2580
2630
|
let chunkResult;
|
|
2581
2631
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2582
|
-
await
|
|
2632
|
+
await stream6.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2583
2633
|
|
|
2584
2634
|
`);
|
|
2585
2635
|
}
|
|
2586
|
-
await
|
|
2636
|
+
await stream6.write("data: [DONE]\n\n");
|
|
2587
2637
|
} catch (err) {
|
|
2588
|
-
logger2.error("Error in
|
|
2638
|
+
logger2.error("Error in decline tool call: " + (err?.message ?? "Unknown error"));
|
|
2589
2639
|
}
|
|
2590
|
-
await
|
|
2640
|
+
await stream6.close();
|
|
2591
2641
|
},
|
|
2592
2642
|
async (err) => {
|
|
2593
2643
|
logger2.error("Error in watch stream: " + err?.message);
|
|
2594
2644
|
}
|
|
2595
2645
|
);
|
|
2596
2646
|
} catch (error) {
|
|
2597
|
-
return handleError(error, "Error
|
|
2647
|
+
return handleError(error, "Error declining tool call");
|
|
2598
2648
|
}
|
|
2599
2649
|
}
|
|
2600
2650
|
async function streamNetworkHandler(c2) {
|
|
@@ -2628,7 +2678,7 @@ async function streamNetworkHandler(c2) {
|
|
|
2628
2678
|
c2.header("Transfer-Encoding", "chunked");
|
|
2629
2679
|
return streaming.stream(
|
|
2630
2680
|
c2,
|
|
2631
|
-
async (
|
|
2681
|
+
async (stream6) => {
|
|
2632
2682
|
try {
|
|
2633
2683
|
const streamResponse = await agents.streamNetworkHandler({
|
|
2634
2684
|
mastra,
|
|
@@ -2638,20 +2688,20 @@ async function streamNetworkHandler(c2) {
|
|
|
2638
2688
|
// abortSignal: c.req.raw.signal,
|
|
2639
2689
|
});
|
|
2640
2690
|
const reader = streamResponse.getReader();
|
|
2641
|
-
|
|
2691
|
+
stream6.onAbort(() => {
|
|
2642
2692
|
void reader.cancel("request aborted");
|
|
2643
2693
|
});
|
|
2644
2694
|
let chunkResult;
|
|
2645
2695
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2646
|
-
await
|
|
2696
|
+
await stream6.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2647
2697
|
|
|
2648
2698
|
`);
|
|
2649
2699
|
}
|
|
2650
|
-
await
|
|
2700
|
+
await stream6.write("data: [DONE]\n\n");
|
|
2651
2701
|
} catch (err) {
|
|
2652
2702
|
logger2.error("Error in streamNetwork generate: " + (err?.message ?? "Unknown error"));
|
|
2653
2703
|
}
|
|
2654
|
-
await
|
|
2704
|
+
await stream6.close();
|
|
2655
2705
|
},
|
|
2656
2706
|
async (err) => {
|
|
2657
2707
|
logger2.error("Error in watch stream: " + err?.message);
|
|
@@ -2661,13 +2711,13 @@ async function streamNetworkHandler(c2) {
|
|
|
2661
2711
|
return handleError(error, "Error streaming from agent in network mode");
|
|
2662
2712
|
}
|
|
2663
2713
|
}
|
|
2664
|
-
async function
|
|
2714
|
+
async function streamUIMessageHandler(c2) {
|
|
2665
2715
|
try {
|
|
2666
2716
|
const mastra = c2.get("mastra");
|
|
2667
2717
|
const agentId = c2.req.param("agentId");
|
|
2668
2718
|
const runtimeContext = c2.get("runtimeContext");
|
|
2669
2719
|
const body = await c2.req.json();
|
|
2670
|
-
const streamResponse = await agents.
|
|
2720
|
+
const streamResponse = await agents.streamUIMessageHandler({
|
|
2671
2721
|
mastra,
|
|
2672
2722
|
agentId,
|
|
2673
2723
|
runtimeContext,
|
|
@@ -2725,9 +2775,9 @@ async function deprecatedStreamVNextHandler(c2) {
|
|
|
2725
2775
|
return c2.json(
|
|
2726
2776
|
{
|
|
2727
2777
|
error: "This endpoint is deprecated",
|
|
2728
|
-
message: "The /
|
|
2729
|
-
deprecated_endpoint: "/api/agents/:agentId/
|
|
2730
|
-
replacement_endpoint: "/api/agents/:agentId/stream
|
|
2778
|
+
message: "The /stream/vnext endpoint has been deprecated. Please use an alternative streaming endpoint.",
|
|
2779
|
+
deprecated_endpoint: "/api/agents/:agentId/stream/vnext",
|
|
2780
|
+
replacement_endpoint: "/api/agents/:agentId/stream"
|
|
2731
2781
|
},
|
|
2732
2782
|
410
|
|
2733
2783
|
// 410 Gone status code for deprecated endpoints
|
|
@@ -3341,14 +3391,15 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3341
3391
|
}
|
|
3342
3392
|
}
|
|
3343
3393
|
}),
|
|
3344
|
-
|
|
3394
|
+
generateHandler
|
|
3345
3395
|
);
|
|
3346
3396
|
router.post(
|
|
3347
3397
|
"/:agentId/stream/vnext",
|
|
3348
3398
|
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3349
3399
|
w({
|
|
3350
|
-
description: "
|
|
3400
|
+
description: "[DEPRECATED] This endpoint is deprecated. Please use /stream instead.",
|
|
3351
3401
|
tags: ["agents"],
|
|
3402
|
+
deprecated: true,
|
|
3352
3403
|
parameters: [
|
|
3353
3404
|
{
|
|
3354
3405
|
name: "agentId",
|
|
@@ -3378,7 +3429,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3378
3429
|
}
|
|
3379
3430
|
}
|
|
3380
3431
|
}),
|
|
3381
|
-
|
|
3432
|
+
streamGenerateHandler
|
|
3382
3433
|
);
|
|
3383
3434
|
router.post(
|
|
3384
3435
|
"/:agentId/stream-legacy",
|
|
@@ -3594,6 +3645,44 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3594
3645
|
router.post(
|
|
3595
3646
|
"/:agentId/stream/vnext/ui",
|
|
3596
3647
|
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3648
|
+
w({
|
|
3649
|
+
description: "[DEPRECATED] This endpoint is deprecated. Please use /stream/ui instead.",
|
|
3650
|
+
tags: ["agents"],
|
|
3651
|
+
deprecated: true,
|
|
3652
|
+
parameters: [
|
|
3653
|
+
{
|
|
3654
|
+
name: "agentId",
|
|
3655
|
+
in: "path",
|
|
3656
|
+
required: true,
|
|
3657
|
+
schema: { type: "string" }
|
|
3658
|
+
}
|
|
3659
|
+
],
|
|
3660
|
+
requestBody: {
|
|
3661
|
+
required: true,
|
|
3662
|
+
content: {
|
|
3663
|
+
"application/json": {
|
|
3664
|
+
schema: {
|
|
3665
|
+
type: "object",
|
|
3666
|
+
properties: vNextBodyOptions,
|
|
3667
|
+
required: ["messages"]
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
},
|
|
3672
|
+
responses: {
|
|
3673
|
+
200: {
|
|
3674
|
+
description: "Streamed response"
|
|
3675
|
+
},
|
|
3676
|
+
404: {
|
|
3677
|
+
description: "Agent not found"
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
}),
|
|
3681
|
+
streamUIMessageHandler
|
|
3682
|
+
);
|
|
3683
|
+
router.post(
|
|
3684
|
+
"/:agentId/stream/ui",
|
|
3685
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
3597
3686
|
w({
|
|
3598
3687
|
description: "Stream a response from an agent",
|
|
3599
3688
|
tags: ["agents"],
|
|
@@ -3626,7 +3715,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3626
3715
|
}
|
|
3627
3716
|
}
|
|
3628
3717
|
}),
|
|
3629
|
-
|
|
3718
|
+
streamUIMessageHandler
|
|
3630
3719
|
);
|
|
3631
3720
|
router.post(
|
|
3632
3721
|
"/:agentId/model",
|
|
@@ -4271,6 +4360,88 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
4271
4360
|
}),
|
|
4272
4361
|
executeAgentToolHandler
|
|
4273
4362
|
);
|
|
4363
|
+
router.post(
|
|
4364
|
+
"/:agentId/approve-tool-call",
|
|
4365
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
4366
|
+
w({
|
|
4367
|
+
description: "Approve a tool call in human-in-the-loop workflow",
|
|
4368
|
+
tags: ["agents"],
|
|
4369
|
+
parameters: [
|
|
4370
|
+
{
|
|
4371
|
+
name: "agentId",
|
|
4372
|
+
in: "path",
|
|
4373
|
+
required: true,
|
|
4374
|
+
schema: { type: "string" }
|
|
4375
|
+
}
|
|
4376
|
+
],
|
|
4377
|
+
requestBody: {
|
|
4378
|
+
required: true,
|
|
4379
|
+
content: {
|
|
4380
|
+
"application/json": {
|
|
4381
|
+
schema: {
|
|
4382
|
+
type: "object",
|
|
4383
|
+
properties: {
|
|
4384
|
+
runId: { type: "string", description: "The run ID for the execution" },
|
|
4385
|
+
runtimeContext: { type: "object", description: "Runtime context for the execution" },
|
|
4386
|
+
format: { type: "string", enum: ["aisdk", "mastra"], description: "Output format" }
|
|
4387
|
+
},
|
|
4388
|
+
required: ["runId"]
|
|
4389
|
+
}
|
|
4390
|
+
}
|
|
4391
|
+
}
|
|
4392
|
+
},
|
|
4393
|
+
responses: {
|
|
4394
|
+
200: {
|
|
4395
|
+
description: "Tool call approved and execution resumed"
|
|
4396
|
+
},
|
|
4397
|
+
404: {
|
|
4398
|
+
description: "Agent not found"
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4401
|
+
}),
|
|
4402
|
+
approveToolCallHandler
|
|
4403
|
+
);
|
|
4404
|
+
router.post(
|
|
4405
|
+
"/:agentId/decline-tool-call",
|
|
4406
|
+
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
4407
|
+
w({
|
|
4408
|
+
description: "Decline a tool call in human-in-the-loop workflow",
|
|
4409
|
+
tags: ["agents"],
|
|
4410
|
+
parameters: [
|
|
4411
|
+
{
|
|
4412
|
+
name: "agentId",
|
|
4413
|
+
in: "path",
|
|
4414
|
+
required: true,
|
|
4415
|
+
schema: { type: "string" }
|
|
4416
|
+
}
|
|
4417
|
+
],
|
|
4418
|
+
requestBody: {
|
|
4419
|
+
required: true,
|
|
4420
|
+
content: {
|
|
4421
|
+
"application/json": {
|
|
4422
|
+
schema: {
|
|
4423
|
+
type: "object",
|
|
4424
|
+
properties: {
|
|
4425
|
+
runId: { type: "string", description: "The run ID for the execution" },
|
|
4426
|
+
runtimeContext: { type: "object", description: "Runtime context for the execution" },
|
|
4427
|
+
format: { type: "string", enum: ["aisdk", "mastra"], description: "Output format" }
|
|
4428
|
+
},
|
|
4429
|
+
required: ["runId"]
|
|
4430
|
+
}
|
|
4431
|
+
}
|
|
4432
|
+
}
|
|
4433
|
+
},
|
|
4434
|
+
responses: {
|
|
4435
|
+
200: {
|
|
4436
|
+
description: "Tool call declined and execution resumed"
|
|
4437
|
+
},
|
|
4438
|
+
404: {
|
|
4439
|
+
description: "Agent not found"
|
|
4440
|
+
}
|
|
4441
|
+
}
|
|
4442
|
+
}),
|
|
4443
|
+
declineToolCallHandler
|
|
4444
|
+
);
|
|
4274
4445
|
return router;
|
|
4275
4446
|
}
|
|
4276
4447
|
function agentsRouterDev(bodyLimitOptions) {
|
|
@@ -7076,11 +7247,9 @@ async function getMemoryStatusHandler(c2) {
|
|
|
7076
7247
|
try {
|
|
7077
7248
|
const mastra = c2.get("mastra");
|
|
7078
7249
|
const agentId = c2.req.query("agentId");
|
|
7079
|
-
const networkId = c2.req.query("networkId");
|
|
7080
7250
|
const result = await memory.getMemoryStatusHandler({
|
|
7081
7251
|
mastra,
|
|
7082
|
-
agentId
|
|
7083
|
-
networkId
|
|
7252
|
+
agentId
|
|
7084
7253
|
});
|
|
7085
7254
|
return c2.json(result);
|
|
7086
7255
|
} catch (error) {
|
|
@@ -7091,11 +7260,9 @@ async function getMemoryConfigHandler(c2) {
|
|
|
7091
7260
|
try {
|
|
7092
7261
|
const mastra = c2.get("mastra");
|
|
7093
7262
|
const agentId = c2.req.query("agentId");
|
|
7094
|
-
const networkId = c2.req.query("networkId");
|
|
7095
7263
|
const result = await memory.getMemoryConfigHandler({
|
|
7096
7264
|
mastra,
|
|
7097
|
-
agentId
|
|
7098
|
-
networkId
|
|
7265
|
+
agentId
|
|
7099
7266
|
});
|
|
7100
7267
|
return c2.json(result);
|
|
7101
7268
|
} catch (error) {
|
|
@@ -7107,14 +7274,12 @@ async function getThreadsHandler(c2) {
|
|
|
7107
7274
|
const mastra = c2.get("mastra");
|
|
7108
7275
|
const agentId = c2.req.query("agentId");
|
|
7109
7276
|
const resourceId = c2.req.query("resourceid");
|
|
7110
|
-
const networkId = c2.req.query("networkId");
|
|
7111
7277
|
const orderBy = c2.req.query("orderBy");
|
|
7112
7278
|
const sortDirection = c2.req.query("sortDirection");
|
|
7113
7279
|
const result = await memory.getThreadsHandler({
|
|
7114
7280
|
mastra,
|
|
7115
7281
|
agentId,
|
|
7116
7282
|
resourceId,
|
|
7117
|
-
networkId,
|
|
7118
7283
|
orderBy,
|
|
7119
7284
|
sortDirection
|
|
7120
7285
|
});
|
|
@@ -7128,7 +7293,6 @@ async function getThreadsPaginatedHandler(c2) {
|
|
|
7128
7293
|
const mastra = c2.get("mastra");
|
|
7129
7294
|
const agentId = c2.req.query("agentId");
|
|
7130
7295
|
const resourceId = c2.req.query("resourceId");
|
|
7131
|
-
const networkId = c2.req.query("networkId");
|
|
7132
7296
|
const page = parseInt(c2.req.query("page") || "0", 10);
|
|
7133
7297
|
const perPage = parseInt(c2.req.query("perPage") || "100", 10);
|
|
7134
7298
|
const orderBy = c2.req.query("orderBy");
|
|
@@ -7137,7 +7301,6 @@ async function getThreadsPaginatedHandler(c2) {
|
|
|
7137
7301
|
mastra,
|
|
7138
7302
|
agentId,
|
|
7139
7303
|
resourceId,
|
|
7140
|
-
networkId,
|
|
7141
7304
|
page,
|
|
7142
7305
|
perPage,
|
|
7143
7306
|
orderBy,
|
|
@@ -7153,12 +7316,10 @@ async function getThreadByIdHandler(c2) {
|
|
|
7153
7316
|
const mastra = c2.get("mastra");
|
|
7154
7317
|
const agentId = c2.req.query("agentId");
|
|
7155
7318
|
const threadId = c2.req.param("threadId");
|
|
7156
|
-
const networkId = c2.req.query("networkId");
|
|
7157
7319
|
const result = await memory.getThreadByIdHandler({
|
|
7158
7320
|
mastra,
|
|
7159
7321
|
agentId,
|
|
7160
|
-
threadId
|
|
7161
|
-
networkId
|
|
7322
|
+
threadId
|
|
7162
7323
|
});
|
|
7163
7324
|
return c2.json(result);
|
|
7164
7325
|
} catch (error) {
|
|
@@ -7169,13 +7330,11 @@ async function saveMessagesHandler(c2) {
|
|
|
7169
7330
|
try {
|
|
7170
7331
|
const mastra = c2.get("mastra");
|
|
7171
7332
|
const agentId = c2.req.query("agentId");
|
|
7172
|
-
const networkId = c2.req.query("networkId");
|
|
7173
7333
|
const body = await c2.req.json();
|
|
7174
7334
|
const result = await memory.saveMessagesHandler({
|
|
7175
7335
|
mastra,
|
|
7176
7336
|
agentId,
|
|
7177
|
-
body
|
|
7178
|
-
networkId
|
|
7337
|
+
body
|
|
7179
7338
|
});
|
|
7180
7339
|
return c2.json(result);
|
|
7181
7340
|
} catch (error) {
|
|
@@ -7186,13 +7345,11 @@ async function createThreadHandler(c2) {
|
|
|
7186
7345
|
try {
|
|
7187
7346
|
const mastra = c2.get("mastra");
|
|
7188
7347
|
const agentId = c2.req.query("agentId");
|
|
7189
|
-
const networkId = c2.req.query("networkId");
|
|
7190
7348
|
const body = await c2.req.json();
|
|
7191
7349
|
const result = await memory.createThreadHandler({
|
|
7192
7350
|
mastra,
|
|
7193
7351
|
agentId,
|
|
7194
|
-
body
|
|
7195
|
-
networkId
|
|
7352
|
+
body
|
|
7196
7353
|
});
|
|
7197
7354
|
return c2.json(result);
|
|
7198
7355
|
} catch (error) {
|
|
@@ -7204,14 +7361,12 @@ async function updateThreadHandler(c2) {
|
|
|
7204
7361
|
const mastra = c2.get("mastra");
|
|
7205
7362
|
const agentId = c2.req.query("agentId");
|
|
7206
7363
|
const threadId = c2.req.param("threadId");
|
|
7207
|
-
const networkId = c2.req.query("networkId");
|
|
7208
7364
|
const body = await c2.req.json();
|
|
7209
7365
|
const result = await memory.updateThreadHandler({
|
|
7210
7366
|
mastra,
|
|
7211
7367
|
agentId,
|
|
7212
7368
|
threadId,
|
|
7213
|
-
body
|
|
7214
|
-
networkId
|
|
7369
|
+
body
|
|
7215
7370
|
});
|
|
7216
7371
|
return c2.json(result);
|
|
7217
7372
|
} catch (error) {
|
|
@@ -7223,12 +7378,10 @@ async function deleteThreadHandler(c2) {
|
|
|
7223
7378
|
const mastra = c2.get("mastra");
|
|
7224
7379
|
const agentId = c2.req.query("agentId");
|
|
7225
7380
|
const threadId = c2.req.param("threadId");
|
|
7226
|
-
const networkId = c2.req.query("networkId");
|
|
7227
7381
|
const result = await memory.deleteThreadHandler({
|
|
7228
7382
|
mastra,
|
|
7229
7383
|
agentId,
|
|
7230
|
-
threadId
|
|
7231
|
-
networkId
|
|
7384
|
+
threadId
|
|
7232
7385
|
});
|
|
7233
7386
|
return c2.json(result);
|
|
7234
7387
|
} catch (error) {
|
|
@@ -7239,14 +7392,12 @@ async function getMessagesHandler(c2) {
|
|
|
7239
7392
|
try {
|
|
7240
7393
|
const mastra = c2.get("mastra");
|
|
7241
7394
|
const agentId = c2.req.query("agentId");
|
|
7242
|
-
const networkId = c2.req.query("networkId");
|
|
7243
7395
|
const threadId = c2.req.param("threadId");
|
|
7244
7396
|
const limit = parseLimit(c2.req.query("limit"));
|
|
7245
7397
|
const result = await memory.getMessagesHandler({
|
|
7246
7398
|
mastra,
|
|
7247
7399
|
agentId,
|
|
7248
7400
|
threadId,
|
|
7249
|
-
networkId,
|
|
7250
7401
|
limit
|
|
7251
7402
|
});
|
|
7252
7403
|
return c2.json(result);
|
|
@@ -7285,14 +7436,12 @@ async function updateWorkingMemoryHandler(c2) {
|
|
|
7285
7436
|
const mastra = c2.get("mastra");
|
|
7286
7437
|
const agentId = c2.req.query("agentId");
|
|
7287
7438
|
const threadId = c2.req.param("threadId");
|
|
7288
|
-
const networkId = c2.req.query("networkId");
|
|
7289
7439
|
const body = await c2.req.json();
|
|
7290
7440
|
const result = await memory.updateWorkingMemoryHandler({
|
|
7291
7441
|
mastra,
|
|
7292
7442
|
agentId,
|
|
7293
7443
|
threadId,
|
|
7294
|
-
body
|
|
7295
|
-
networkId
|
|
7444
|
+
body
|
|
7296
7445
|
});
|
|
7297
7446
|
return c2.json(result);
|
|
7298
7447
|
} catch (error) {
|
|
@@ -7305,13 +7454,11 @@ async function getWorkingMemoryHandler(c2) {
|
|
|
7305
7454
|
const agentId = c2.req.query("agentId");
|
|
7306
7455
|
const threadId = c2.req.param("threadId");
|
|
7307
7456
|
const resourceId = c2.req.query("resourceId");
|
|
7308
|
-
const networkId = c2.req.query("networkId");
|
|
7309
7457
|
const result = await memory.getWorkingMemoryHandler({
|
|
7310
7458
|
mastra,
|
|
7311
7459
|
agentId,
|
|
7312
7460
|
threadId,
|
|
7313
|
-
resourceId
|
|
7314
|
-
networkId
|
|
7461
|
+
resourceId
|
|
7315
7462
|
});
|
|
7316
7463
|
return c2.json(result);
|
|
7317
7464
|
} catch (error) {
|
|
@@ -7327,7 +7474,6 @@ async function searchMemoryHandler(c2) {
|
|
|
7327
7474
|
const threadId = c2.req.query("threadId");
|
|
7328
7475
|
const limit = parseLimit(c2.req.query("limit"));
|
|
7329
7476
|
const memoryConfig = c2.req.query("memoryConfig") ? JSON.parse(c2.req.query("memoryConfig")) : void 0;
|
|
7330
|
-
const networkId = c2.req.query("networkId");
|
|
7331
7477
|
const runtimeContext = c2.get("runtimeContext");
|
|
7332
7478
|
const result = await memory.searchMemoryHandler({
|
|
7333
7479
|
mastra,
|
|
@@ -7337,7 +7483,6 @@ async function searchMemoryHandler(c2) {
|
|
|
7337
7483
|
threadId,
|
|
7338
7484
|
limit,
|
|
7339
7485
|
memoryConfig,
|
|
7340
|
-
networkId,
|
|
7341
7486
|
runtimeContext
|
|
7342
7487
|
});
|
|
7343
7488
|
return c2.json(result);
|
|
@@ -7349,7 +7494,6 @@ async function deleteMessagesHandler(c2) {
|
|
|
7349
7494
|
try {
|
|
7350
7495
|
const mastra = c2.get("mastra");
|
|
7351
7496
|
const agentId = c2.req.query("agentId");
|
|
7352
|
-
const networkId = c2.req.query("networkId");
|
|
7353
7497
|
const runtimeContext = c2.get("runtimeContext");
|
|
7354
7498
|
const body = await c2.req.json();
|
|
7355
7499
|
const messageIds = body?.messageIds;
|
|
@@ -7357,7 +7501,6 @@ async function deleteMessagesHandler(c2) {
|
|
|
7357
7501
|
mastra,
|
|
7358
7502
|
agentId,
|
|
7359
7503
|
messageIds,
|
|
7360
|
-
networkId,
|
|
7361
7504
|
runtimeContext
|
|
7362
7505
|
});
|
|
7363
7506
|
return c2.json(result);
|
|
@@ -8538,447 +8681,70 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8538
8681
|
);
|
|
8539
8682
|
return router;
|
|
8540
8683
|
}
|
|
8541
|
-
async function
|
|
8684
|
+
async function getAITraceHandler(c2) {
|
|
8542
8685
|
try {
|
|
8543
8686
|
const mastra = c2.get("mastra");
|
|
8544
|
-
const
|
|
8545
|
-
|
|
8687
|
+
const traceId = c2.req.param("traceId");
|
|
8688
|
+
if (!traceId) {
|
|
8689
|
+
return c2.json({ error: "Trace ID is required" }, 400);
|
|
8690
|
+
}
|
|
8691
|
+
const trace = await observability.getAITraceHandler({
|
|
8546
8692
|
mastra,
|
|
8547
|
-
|
|
8693
|
+
traceId
|
|
8548
8694
|
});
|
|
8549
|
-
return c2.json(
|
|
8695
|
+
return c2.json(trace);
|
|
8550
8696
|
} catch (error) {
|
|
8551
|
-
return handleError(error, "Error getting
|
|
8697
|
+
return handleError(error, "Error getting AI trace");
|
|
8552
8698
|
}
|
|
8553
8699
|
}
|
|
8554
|
-
async function
|
|
8700
|
+
async function getAITracesPaginatedHandler(c2) {
|
|
8555
8701
|
try {
|
|
8556
8702
|
const mastra = c2.get("mastra");
|
|
8557
|
-
const
|
|
8558
|
-
const
|
|
8559
|
-
|
|
8703
|
+
const { page, perPage, name, spanType, dateRange, entityId, entityType } = c2.req.query();
|
|
8704
|
+
const pagination = {
|
|
8705
|
+
page: parseInt(page || "0"),
|
|
8706
|
+
perPage: parseInt(perPage || "10")
|
|
8707
|
+
};
|
|
8708
|
+
const filters = {};
|
|
8709
|
+
if (name) filters.name = name;
|
|
8710
|
+
if (spanType) {
|
|
8711
|
+
if (Object.values(aiTracing.AISpanType).includes(spanType)) {
|
|
8712
|
+
filters.spanType = spanType;
|
|
8713
|
+
} else {
|
|
8714
|
+
return c2.json({ error: "Invalid spanType" }, 400);
|
|
8715
|
+
}
|
|
8716
|
+
}
|
|
8717
|
+
if (entityId && entityType && (entityType === "agent" || entityType === "workflow")) {
|
|
8718
|
+
filters.entityId = entityId;
|
|
8719
|
+
filters.entityType = entityType;
|
|
8720
|
+
}
|
|
8721
|
+
let start;
|
|
8722
|
+
let end;
|
|
8723
|
+
if (dateRange) {
|
|
8724
|
+
try {
|
|
8725
|
+
const parsedDateRange = JSON.parse(dateRange);
|
|
8726
|
+
start = parsedDateRange.start ? new Date(parsedDateRange.start) : void 0;
|
|
8727
|
+
end = parsedDateRange.end ? new Date(parsedDateRange.end) : void 0;
|
|
8728
|
+
} catch {
|
|
8729
|
+
return c2.json({ error: "Invalid start date" }, 400);
|
|
8730
|
+
}
|
|
8731
|
+
}
|
|
8732
|
+
if (start || end) {
|
|
8733
|
+
pagination.dateRange = { start, end };
|
|
8734
|
+
}
|
|
8735
|
+
const result = await observability.getAITracesPaginatedHandler({
|
|
8560
8736
|
mastra,
|
|
8561
|
-
|
|
8562
|
-
|
|
8737
|
+
body: {
|
|
8738
|
+
pagination,
|
|
8739
|
+
filters
|
|
8740
|
+
}
|
|
8563
8741
|
});
|
|
8564
|
-
return c2.json(
|
|
8742
|
+
return c2.json(result);
|
|
8565
8743
|
} catch (error) {
|
|
8566
|
-
return handleError(error, "Error getting
|
|
8744
|
+
return handleError(error, "Error getting AI traces paginated");
|
|
8567
8745
|
}
|
|
8568
8746
|
}
|
|
8569
|
-
async function
|
|
8570
|
-
try {
|
|
8571
|
-
const mastra = c2.get("mastra");
|
|
8572
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
8573
|
-
const networkId = c2.req.param("networkId");
|
|
8574
|
-
const body = await c2.req.json();
|
|
8575
|
-
const result = await vNextNetwork.generateVNextNetworkHandler({
|
|
8576
|
-
mastra,
|
|
8577
|
-
runtimeContext,
|
|
8578
|
-
networkId,
|
|
8579
|
-
body
|
|
8580
|
-
});
|
|
8581
|
-
return c2.json(result);
|
|
8582
|
-
} catch (error) {
|
|
8583
|
-
return handleError(error, "Error generating from network");
|
|
8584
|
-
}
|
|
8585
|
-
}
|
|
8586
|
-
async function streamGenerateVNextNetworkHandler(c2) {
|
|
8587
|
-
try {
|
|
8588
|
-
const mastra = c2.get("mastra");
|
|
8589
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
8590
|
-
const logger2 = mastra.getLogger();
|
|
8591
|
-
const networkId = c2.req.param("networkId");
|
|
8592
|
-
const body = await c2.req.json();
|
|
8593
|
-
c2.header("Transfer-Encoding", "chunked");
|
|
8594
|
-
return streaming.stream(
|
|
8595
|
-
c2,
|
|
8596
|
-
async (stream7) => {
|
|
8597
|
-
try {
|
|
8598
|
-
const result = await vNextNetwork.streamGenerateVNextNetworkHandler({
|
|
8599
|
-
mastra,
|
|
8600
|
-
runtimeContext,
|
|
8601
|
-
networkId,
|
|
8602
|
-
body
|
|
8603
|
-
});
|
|
8604
|
-
const reader = result.stream.getReader();
|
|
8605
|
-
stream7.onAbort(() => {
|
|
8606
|
-
void reader.cancel("request aborted");
|
|
8607
|
-
});
|
|
8608
|
-
let chunkResult;
|
|
8609
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
8610
|
-
await stream7.write(JSON.stringify(chunkResult.value) + "");
|
|
8611
|
-
}
|
|
8612
|
-
} catch (err) {
|
|
8613
|
-
mastra.getLogger().error("Error in network stream: " + (err?.message ?? "Unknown error"));
|
|
8614
|
-
}
|
|
8615
|
-
},
|
|
8616
|
-
async (err) => {
|
|
8617
|
-
logger2.error("Error in network stream: " + err?.message);
|
|
8618
|
-
}
|
|
8619
|
-
);
|
|
8620
|
-
} catch (error) {
|
|
8621
|
-
return handleError(error, "Error streaming from network");
|
|
8622
|
-
}
|
|
8623
|
-
}
|
|
8624
|
-
async function loopVNextNetworkHandler(c2) {
|
|
8625
|
-
try {
|
|
8626
|
-
const mastra = c2.get("mastra");
|
|
8627
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
8628
|
-
const networkId = c2.req.param("networkId");
|
|
8629
|
-
const body = await c2.req.json();
|
|
8630
|
-
const result = await vNextNetwork.loopVNextNetworkHandler({
|
|
8631
|
-
mastra,
|
|
8632
|
-
runtimeContext,
|
|
8633
|
-
networkId,
|
|
8634
|
-
body
|
|
8635
|
-
});
|
|
8636
|
-
return c2.json(result);
|
|
8637
|
-
} catch (error) {
|
|
8638
|
-
return handleError(error, "Error looping from network");
|
|
8639
|
-
}
|
|
8640
|
-
}
|
|
8641
|
-
async function loopStreamVNextNetworkHandler(c2) {
|
|
8642
|
-
try {
|
|
8643
|
-
const mastra = c2.get("mastra");
|
|
8644
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
8645
|
-
const logger2 = mastra.getLogger();
|
|
8646
|
-
const networkId = c2.req.param("networkId");
|
|
8647
|
-
const body = await c2.req.json();
|
|
8648
|
-
c2.header("Transfer-Encoding", "chunked");
|
|
8649
|
-
return streaming.stream(
|
|
8650
|
-
c2,
|
|
8651
|
-
async (stream7) => {
|
|
8652
|
-
try {
|
|
8653
|
-
const result = await vNextNetwork.loopStreamVNextNetworkHandler({
|
|
8654
|
-
mastra,
|
|
8655
|
-
runtimeContext,
|
|
8656
|
-
networkId,
|
|
8657
|
-
body
|
|
8658
|
-
});
|
|
8659
|
-
const reader = result.stream.getReader();
|
|
8660
|
-
stream7.onAbort(() => {
|
|
8661
|
-
void reader.cancel("request aborted");
|
|
8662
|
-
});
|
|
8663
|
-
let chunkResult;
|
|
8664
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
8665
|
-
await stream7.write(JSON.stringify(chunkResult.value) + "");
|
|
8666
|
-
}
|
|
8667
|
-
} catch (err) {
|
|
8668
|
-
mastra.getLogger().error("Error in network loop stream: " + (err?.message ?? "Unknown error"));
|
|
8669
|
-
}
|
|
8670
|
-
},
|
|
8671
|
-
async (err) => {
|
|
8672
|
-
logger2.error("Error in network loop stream: " + err?.message);
|
|
8673
|
-
}
|
|
8674
|
-
);
|
|
8675
|
-
} catch (error) {
|
|
8676
|
-
return handleError(error, "Error streaming network loop");
|
|
8677
|
-
}
|
|
8678
|
-
}
|
|
8679
|
-
|
|
8680
|
-
// src/server/handlers/routes/networks/router.ts
|
|
8681
|
-
function vNextNetworksRouter(bodyLimitOptions) {
|
|
8682
|
-
const router = new hono.Hono();
|
|
8683
|
-
router.get(
|
|
8684
|
-
"/v-next",
|
|
8685
|
-
w({
|
|
8686
|
-
description: "Get all available v-next networks",
|
|
8687
|
-
tags: ["vNextNetworks"],
|
|
8688
|
-
responses: {
|
|
8689
|
-
200: {
|
|
8690
|
-
description: "List of all v-next networks"
|
|
8691
|
-
}
|
|
8692
|
-
}
|
|
8693
|
-
}),
|
|
8694
|
-
getVNextNetworksHandler
|
|
8695
|
-
);
|
|
8696
|
-
router.get(
|
|
8697
|
-
"/v-next/:networkId",
|
|
8698
|
-
w({
|
|
8699
|
-
description: "Get v-next network by ID",
|
|
8700
|
-
tags: ["vNextNetworks"],
|
|
8701
|
-
parameters: [
|
|
8702
|
-
{
|
|
8703
|
-
name: "networkId",
|
|
8704
|
-
in: "path",
|
|
8705
|
-
required: true,
|
|
8706
|
-
schema: { type: "string" }
|
|
8707
|
-
}
|
|
8708
|
-
],
|
|
8709
|
-
responses: {
|
|
8710
|
-
200: {
|
|
8711
|
-
description: "v-next Network details"
|
|
8712
|
-
},
|
|
8713
|
-
404: {
|
|
8714
|
-
description: "v-next Network not found"
|
|
8715
|
-
}
|
|
8716
|
-
}
|
|
8717
|
-
}),
|
|
8718
|
-
getVNextNetworkByIdHandler
|
|
8719
|
-
);
|
|
8720
|
-
router.post(
|
|
8721
|
-
"/v-next/:networkId/generate",
|
|
8722
|
-
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
8723
|
-
w({
|
|
8724
|
-
description: "Generate a response from a v-next network",
|
|
8725
|
-
tags: ["vNextNetworks"],
|
|
8726
|
-
parameters: [
|
|
8727
|
-
{
|
|
8728
|
-
name: "networkId",
|
|
8729
|
-
in: "path",
|
|
8730
|
-
required: true,
|
|
8731
|
-
schema: { type: "string" }
|
|
8732
|
-
}
|
|
8733
|
-
],
|
|
8734
|
-
requestBody: {
|
|
8735
|
-
required: true,
|
|
8736
|
-
content: {
|
|
8737
|
-
"application/json": {
|
|
8738
|
-
schema: {
|
|
8739
|
-
type: "object",
|
|
8740
|
-
properties: {
|
|
8741
|
-
message: {
|
|
8742
|
-
type: "string",
|
|
8743
|
-
description: "Message for the v-next network"
|
|
8744
|
-
},
|
|
8745
|
-
threadId: {
|
|
8746
|
-
type: "string",
|
|
8747
|
-
description: "Thread Id of the conversation"
|
|
8748
|
-
},
|
|
8749
|
-
resourceId: {
|
|
8750
|
-
type: "string",
|
|
8751
|
-
description: "Resource Id of the conversation"
|
|
8752
|
-
}
|
|
8753
|
-
},
|
|
8754
|
-
required: ["message"]
|
|
8755
|
-
}
|
|
8756
|
-
}
|
|
8757
|
-
}
|
|
8758
|
-
},
|
|
8759
|
-
responses: {
|
|
8760
|
-
200: {
|
|
8761
|
-
description: "Generated response"
|
|
8762
|
-
},
|
|
8763
|
-
404: {
|
|
8764
|
-
description: "v-next Network not found"
|
|
8765
|
-
}
|
|
8766
|
-
}
|
|
8767
|
-
}),
|
|
8768
|
-
generateVNextNetworkHandler
|
|
8769
|
-
);
|
|
8770
|
-
router.post(
|
|
8771
|
-
"/v-next/:networkId/loop",
|
|
8772
|
-
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
8773
|
-
w({
|
|
8774
|
-
description: "Loop a v-next network",
|
|
8775
|
-
tags: ["vNextNetworks"],
|
|
8776
|
-
parameters: [
|
|
8777
|
-
{
|
|
8778
|
-
name: "networkId",
|
|
8779
|
-
in: "path",
|
|
8780
|
-
required: true,
|
|
8781
|
-
schema: { type: "string" }
|
|
8782
|
-
}
|
|
8783
|
-
],
|
|
8784
|
-
requestBody: {
|
|
8785
|
-
required: true,
|
|
8786
|
-
content: {
|
|
8787
|
-
"application/json": {
|
|
8788
|
-
schema: {
|
|
8789
|
-
type: "object",
|
|
8790
|
-
properties: {
|
|
8791
|
-
message: {
|
|
8792
|
-
type: "string",
|
|
8793
|
-
description: "Message for the v-next network"
|
|
8794
|
-
}
|
|
8795
|
-
},
|
|
8796
|
-
required: ["message"]
|
|
8797
|
-
}
|
|
8798
|
-
}
|
|
8799
|
-
}
|
|
8800
|
-
},
|
|
8801
|
-
responses: {
|
|
8802
|
-
200: {
|
|
8803
|
-
description: "Looped response"
|
|
8804
|
-
},
|
|
8805
|
-
404: {
|
|
8806
|
-
description: "v-next Network not found"
|
|
8807
|
-
}
|
|
8808
|
-
}
|
|
8809
|
-
}),
|
|
8810
|
-
loopVNextNetworkHandler
|
|
8811
|
-
);
|
|
8812
|
-
router.post(
|
|
8813
|
-
"/v-next/:networkId/loop-stream",
|
|
8814
|
-
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
8815
|
-
w({
|
|
8816
|
-
description: "Stream a v-next network loop",
|
|
8817
|
-
tags: ["vNextNetworks"],
|
|
8818
|
-
parameters: [
|
|
8819
|
-
{
|
|
8820
|
-
name: "networkId",
|
|
8821
|
-
in: "path",
|
|
8822
|
-
required: true,
|
|
8823
|
-
schema: { type: "string" }
|
|
8824
|
-
}
|
|
8825
|
-
],
|
|
8826
|
-
requestBody: {
|
|
8827
|
-
required: true,
|
|
8828
|
-
content: {
|
|
8829
|
-
"application/json": {
|
|
8830
|
-
schema: {
|
|
8831
|
-
type: "object",
|
|
8832
|
-
properties: {
|
|
8833
|
-
message: {
|
|
8834
|
-
type: "string",
|
|
8835
|
-
description: "Message for the v-next network"
|
|
8836
|
-
},
|
|
8837
|
-
threadId: {
|
|
8838
|
-
type: "string",
|
|
8839
|
-
description: "Thread Id of the conversation"
|
|
8840
|
-
},
|
|
8841
|
-
resourceId: {
|
|
8842
|
-
type: "string",
|
|
8843
|
-
description: "Resource Id of the conversation"
|
|
8844
|
-
},
|
|
8845
|
-
maxIterations: {
|
|
8846
|
-
type: "number",
|
|
8847
|
-
description: "Maximum number of iterations to run"
|
|
8848
|
-
}
|
|
8849
|
-
},
|
|
8850
|
-
required: ["message"]
|
|
8851
|
-
}
|
|
8852
|
-
}
|
|
8853
|
-
}
|
|
8854
|
-
},
|
|
8855
|
-
responses: {
|
|
8856
|
-
200: {
|
|
8857
|
-
description: "Streamed response"
|
|
8858
|
-
},
|
|
8859
|
-
404: {
|
|
8860
|
-
description: "v-next Network not found"
|
|
8861
|
-
}
|
|
8862
|
-
}
|
|
8863
|
-
}),
|
|
8864
|
-
loopStreamVNextNetworkHandler
|
|
8865
|
-
);
|
|
8866
|
-
router.post(
|
|
8867
|
-
"/v-next/:networkId/stream",
|
|
8868
|
-
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
8869
|
-
w({
|
|
8870
|
-
description: "Stream a response from a v-next network",
|
|
8871
|
-
tags: ["vNextNetworks"],
|
|
8872
|
-
parameters: [
|
|
8873
|
-
{
|
|
8874
|
-
name: "networkId",
|
|
8875
|
-
in: "path",
|
|
8876
|
-
required: true,
|
|
8877
|
-
schema: { type: "string" }
|
|
8878
|
-
}
|
|
8879
|
-
],
|
|
8880
|
-
requestBody: {
|
|
8881
|
-
required: true,
|
|
8882
|
-
content: {
|
|
8883
|
-
"application/json": {
|
|
8884
|
-
schema: {
|
|
8885
|
-
type: "object",
|
|
8886
|
-
properties: {
|
|
8887
|
-
message: {
|
|
8888
|
-
type: "string",
|
|
8889
|
-
description: "Message for the v-next network"
|
|
8890
|
-
},
|
|
8891
|
-
threadId: {
|
|
8892
|
-
type: "string",
|
|
8893
|
-
description: "Thread Id of the conversation"
|
|
8894
|
-
},
|
|
8895
|
-
resourceId: {
|
|
8896
|
-
type: "string",
|
|
8897
|
-
description: "Resource Id of the conversation"
|
|
8898
|
-
}
|
|
8899
|
-
},
|
|
8900
|
-
required: ["message"]
|
|
8901
|
-
}
|
|
8902
|
-
}
|
|
8903
|
-
}
|
|
8904
|
-
},
|
|
8905
|
-
responses: {
|
|
8906
|
-
200: {
|
|
8907
|
-
description: "Streamed response"
|
|
8908
|
-
},
|
|
8909
|
-
404: {
|
|
8910
|
-
description: "v-next Network not found"
|
|
8911
|
-
}
|
|
8912
|
-
}
|
|
8913
|
-
}),
|
|
8914
|
-
streamGenerateVNextNetworkHandler
|
|
8915
|
-
);
|
|
8916
|
-
return router;
|
|
8917
|
-
}
|
|
8918
|
-
async function getAITraceHandler(c2) {
|
|
8919
|
-
try {
|
|
8920
|
-
const mastra = c2.get("mastra");
|
|
8921
|
-
const traceId = c2.req.param("traceId");
|
|
8922
|
-
if (!traceId) {
|
|
8923
|
-
return c2.json({ error: "Trace ID is required" }, 400);
|
|
8924
|
-
}
|
|
8925
|
-
const trace = await observability.getAITraceHandler({
|
|
8926
|
-
mastra,
|
|
8927
|
-
traceId
|
|
8928
|
-
});
|
|
8929
|
-
return c2.json(trace);
|
|
8930
|
-
} catch (error) {
|
|
8931
|
-
return handleError(error, "Error getting AI trace");
|
|
8932
|
-
}
|
|
8933
|
-
}
|
|
8934
|
-
async function getAITracesPaginatedHandler(c2) {
|
|
8935
|
-
try {
|
|
8936
|
-
const mastra = c2.get("mastra");
|
|
8937
|
-
const { page, perPage, name, spanType, dateRange, entityId, entityType } = c2.req.query();
|
|
8938
|
-
const pagination = {
|
|
8939
|
-
page: parseInt(page || "0"),
|
|
8940
|
-
perPage: parseInt(perPage || "10")
|
|
8941
|
-
};
|
|
8942
|
-
const filters = {};
|
|
8943
|
-
if (name) filters.name = name;
|
|
8944
|
-
if (spanType) {
|
|
8945
|
-
if (Object.values(aiTracing.AISpanType).includes(spanType)) {
|
|
8946
|
-
filters.spanType = spanType;
|
|
8947
|
-
} else {
|
|
8948
|
-
return c2.json({ error: "Invalid spanType" }, 400);
|
|
8949
|
-
}
|
|
8950
|
-
}
|
|
8951
|
-
if (entityId && entityType && (entityType === "agent" || entityType === "workflow")) {
|
|
8952
|
-
filters.entityId = entityId;
|
|
8953
|
-
filters.entityType = entityType;
|
|
8954
|
-
}
|
|
8955
|
-
let start;
|
|
8956
|
-
let end;
|
|
8957
|
-
if (dateRange) {
|
|
8958
|
-
try {
|
|
8959
|
-
const parsedDateRange = JSON.parse(dateRange);
|
|
8960
|
-
start = parsedDateRange.start ? new Date(parsedDateRange.start) : void 0;
|
|
8961
|
-
end = parsedDateRange.end ? new Date(parsedDateRange.end) : void 0;
|
|
8962
|
-
} catch {
|
|
8963
|
-
return c2.json({ error: "Invalid start date" }, 400);
|
|
8964
|
-
}
|
|
8965
|
-
}
|
|
8966
|
-
if (start || end) {
|
|
8967
|
-
pagination.dateRange = { start, end };
|
|
8968
|
-
}
|
|
8969
|
-
const result = await observability.getAITracesPaginatedHandler({
|
|
8970
|
-
mastra,
|
|
8971
|
-
body: {
|
|
8972
|
-
pagination,
|
|
8973
|
-
filters
|
|
8974
|
-
}
|
|
8975
|
-
});
|
|
8976
|
-
return c2.json(result);
|
|
8977
|
-
} catch (error) {
|
|
8978
|
-
return handleError(error, "Error getting AI traces paginated");
|
|
8979
|
-
}
|
|
8980
|
-
}
|
|
8981
|
-
async function processTraceScoringHandler(c2) {
|
|
8747
|
+
async function processTraceScoringHandler(c2) {
|
|
8982
8748
|
try {
|
|
8983
8749
|
const mastra = c2.get("mastra");
|
|
8984
8750
|
const { scorerName, targets } = await c2.req.json();
|
|
@@ -10107,7 +9873,7 @@ function watchWorkflowHandler(c2) {
|
|
|
10107
9873
|
c2.header("Transfer-Encoding", "chunked");
|
|
10108
9874
|
return streaming.stream(
|
|
10109
9875
|
c2,
|
|
10110
|
-
async (
|
|
9876
|
+
async (stream6) => {
|
|
10111
9877
|
try {
|
|
10112
9878
|
const result = await workflows.watchWorkflowHandler({
|
|
10113
9879
|
mastra,
|
|
@@ -10115,12 +9881,12 @@ function watchWorkflowHandler(c2) {
|
|
|
10115
9881
|
runId
|
|
10116
9882
|
});
|
|
10117
9883
|
const reader = result.getReader();
|
|
10118
|
-
|
|
9884
|
+
stream6.onAbort(() => {
|
|
10119
9885
|
void reader.cancel("request aborted");
|
|
10120
9886
|
});
|
|
10121
9887
|
let chunkResult;
|
|
10122
9888
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10123
|
-
await
|
|
9889
|
+
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
10124
9890
|
}
|
|
10125
9891
|
} catch (err) {
|
|
10126
9892
|
logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
|
|
@@ -10145,7 +9911,7 @@ async function streamWorkflowHandler(c2) {
|
|
|
10145
9911
|
c2.header("Transfer-Encoding", "chunked");
|
|
10146
9912
|
return streaming.stream(
|
|
10147
9913
|
c2,
|
|
10148
|
-
async (
|
|
9914
|
+
async (stream6) => {
|
|
10149
9915
|
try {
|
|
10150
9916
|
const result = await workflows.streamWorkflowHandler({
|
|
10151
9917
|
mastra,
|
|
@@ -10156,17 +9922,17 @@ async function streamWorkflowHandler(c2) {
|
|
|
10156
9922
|
tracingOptions
|
|
10157
9923
|
});
|
|
10158
9924
|
const reader = result.stream.getReader();
|
|
10159
|
-
|
|
9925
|
+
stream6.onAbort(() => {
|
|
10160
9926
|
void reader.cancel("request aborted");
|
|
10161
9927
|
});
|
|
10162
9928
|
let chunkResult;
|
|
10163
9929
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10164
|
-
await
|
|
9930
|
+
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
10165
9931
|
}
|
|
10166
9932
|
} catch (err) {
|
|
10167
9933
|
logger2.error("Error in workflow stream: " + (err?.message ?? "Unknown error"));
|
|
10168
9934
|
}
|
|
10169
|
-
await
|
|
9935
|
+
await stream6.close();
|
|
10170
9936
|
},
|
|
10171
9937
|
async (err) => {
|
|
10172
9938
|
logger2.error("Error in workflow stream: " + err?.message);
|
|
@@ -10188,7 +9954,7 @@ async function observeStreamWorkflowHandler(c2) {
|
|
|
10188
9954
|
c2.header("Transfer-Encoding", "chunked");
|
|
10189
9955
|
return streaming.stream(
|
|
10190
9956
|
c2,
|
|
10191
|
-
async (
|
|
9957
|
+
async (stream6) => {
|
|
10192
9958
|
try {
|
|
10193
9959
|
const result = await workflows.observeStreamWorkflowHandler({
|
|
10194
9960
|
mastra,
|
|
@@ -10196,17 +9962,17 @@ async function observeStreamWorkflowHandler(c2) {
|
|
|
10196
9962
|
runId
|
|
10197
9963
|
});
|
|
10198
9964
|
const reader = result.getReader();
|
|
10199
|
-
|
|
9965
|
+
stream6.onAbort(() => {
|
|
10200
9966
|
void reader.cancel("request aborted");
|
|
10201
9967
|
});
|
|
10202
9968
|
let chunkResult;
|
|
10203
9969
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10204
|
-
await
|
|
9970
|
+
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
10205
9971
|
}
|
|
10206
9972
|
} catch (err) {
|
|
10207
9973
|
logger2.error("Error in workflow observe stream: " + (err?.message ?? "Unknown error"));
|
|
10208
9974
|
}
|
|
10209
|
-
await
|
|
9975
|
+
await stream6.close();
|
|
10210
9976
|
},
|
|
10211
9977
|
async (err) => {
|
|
10212
9978
|
logger2.error("Error in workflow observe stream: " + err?.message);
|
|
@@ -10227,7 +9993,7 @@ async function streamVNextWorkflowHandler(c2) {
|
|
|
10227
9993
|
c2.header("Transfer-Encoding", "chunked");
|
|
10228
9994
|
return streaming.stream(
|
|
10229
9995
|
c2,
|
|
10230
|
-
async (
|
|
9996
|
+
async (stream6) => {
|
|
10231
9997
|
try {
|
|
10232
9998
|
const result = await workflows.streamVNextWorkflowHandler({
|
|
10233
9999
|
mastra,
|
|
@@ -10239,12 +10005,12 @@ async function streamVNextWorkflowHandler(c2) {
|
|
|
10239
10005
|
tracingOptions
|
|
10240
10006
|
});
|
|
10241
10007
|
const reader = result.getReader();
|
|
10242
|
-
|
|
10008
|
+
stream6.onAbort(() => {
|
|
10243
10009
|
void reader.cancel("request aborted");
|
|
10244
10010
|
});
|
|
10245
10011
|
let chunkResult;
|
|
10246
10012
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10247
|
-
await
|
|
10013
|
+
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
10248
10014
|
}
|
|
10249
10015
|
} catch (err) {
|
|
10250
10016
|
logger2.error("Error in workflow VNext stream: " + (err?.message ?? "Unknown error"));
|
|
@@ -10258,6 +10024,42 @@ async function streamVNextWorkflowHandler(c2) {
|
|
|
10258
10024
|
return handleError(error, "Error streaming workflow");
|
|
10259
10025
|
}
|
|
10260
10026
|
}
|
|
10027
|
+
async function observeStreamVNextWorkflowHandler(c2) {
|
|
10028
|
+
try {
|
|
10029
|
+
const mastra = c2.get("mastra");
|
|
10030
|
+
const logger2 = mastra.getLogger();
|
|
10031
|
+
const workflowId = c2.req.param("workflowId");
|
|
10032
|
+
const runId = c2.req.query("runId");
|
|
10033
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
10034
|
+
return streaming.stream(
|
|
10035
|
+
c2,
|
|
10036
|
+
async (stream6) => {
|
|
10037
|
+
try {
|
|
10038
|
+
const result = await workflows.observeStreamVNextWorkflowHandler({
|
|
10039
|
+
mastra,
|
|
10040
|
+
workflowId,
|
|
10041
|
+
runId
|
|
10042
|
+
});
|
|
10043
|
+
const reader = result.getReader();
|
|
10044
|
+
stream6.onAbort(() => {
|
|
10045
|
+
void reader.cancel("request aborted");
|
|
10046
|
+
});
|
|
10047
|
+
let chunkResult;
|
|
10048
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10049
|
+
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
10050
|
+
}
|
|
10051
|
+
} catch (err) {
|
|
10052
|
+
logger2.error("Error in workflow VNext observe stream: " + (err?.message ?? "Unknown error"));
|
|
10053
|
+
}
|
|
10054
|
+
},
|
|
10055
|
+
async (err) => {
|
|
10056
|
+
logger2.error("Error in workflow VNext observe stream: " + err?.message);
|
|
10057
|
+
}
|
|
10058
|
+
);
|
|
10059
|
+
} catch (error) {
|
|
10060
|
+
return handleError(error, "Error observing vNext workflow stream");
|
|
10061
|
+
}
|
|
10062
|
+
}
|
|
10261
10063
|
async function resumeStreamWorkflowHandler(c2) {
|
|
10262
10064
|
try {
|
|
10263
10065
|
const mastra = c2.get("mastra");
|
|
@@ -10269,7 +10071,7 @@ async function resumeStreamWorkflowHandler(c2) {
|
|
|
10269
10071
|
c2.header("Transfer-Encoding", "chunked");
|
|
10270
10072
|
return streaming.stream(
|
|
10271
10073
|
c2,
|
|
10272
|
-
async (
|
|
10074
|
+
async (stream6) => {
|
|
10273
10075
|
try {
|
|
10274
10076
|
const result = await workflows.resumeStreamWorkflowHandler({
|
|
10275
10077
|
mastra,
|
|
@@ -10280,12 +10082,12 @@ async function resumeStreamWorkflowHandler(c2) {
|
|
|
10280
10082
|
tracingOptions
|
|
10281
10083
|
});
|
|
10282
10084
|
const reader = result.getReader();
|
|
10283
|
-
|
|
10085
|
+
stream6.onAbort(() => {
|
|
10284
10086
|
void reader.cancel("request aborted");
|
|
10285
10087
|
});
|
|
10286
10088
|
let chunkResult;
|
|
10287
10089
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10288
|
-
await
|
|
10090
|
+
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
10289
10091
|
}
|
|
10290
10092
|
} catch (err) {
|
|
10291
10093
|
logger2.error("Error in workflow VNext stream: " + (err?.message ?? "Unknown error"));
|
|
@@ -10515,20 +10317,20 @@ function watchLegacyWorkflowHandler(c2) {
|
|
|
10515
10317
|
}
|
|
10516
10318
|
return streaming.stream(
|
|
10517
10319
|
c2,
|
|
10518
|
-
async (
|
|
10320
|
+
async (stream6) => {
|
|
10519
10321
|
try {
|
|
10520
10322
|
const result = await legacyWorkflows.watchLegacyWorkflowHandler({
|
|
10521
10323
|
mastra,
|
|
10522
10324
|
workflowId,
|
|
10523
10325
|
runId
|
|
10524
10326
|
});
|
|
10525
|
-
|
|
10327
|
+
stream6.onAbort(() => {
|
|
10526
10328
|
if (!result.locked) {
|
|
10527
10329
|
return result.cancel();
|
|
10528
10330
|
}
|
|
10529
10331
|
});
|
|
10530
10332
|
for await (const chunk of result) {
|
|
10531
|
-
await
|
|
10333
|
+
await stream6.write(chunk.toString() + "");
|
|
10532
10334
|
}
|
|
10533
10335
|
} catch (err) {
|
|
10534
10336
|
console.error(err);
|
|
@@ -11322,6 +11124,36 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11322
11124
|
}),
|
|
11323
11125
|
streamVNextWorkflowHandler
|
|
11324
11126
|
);
|
|
11127
|
+
router.post(
|
|
11128
|
+
"/:workflowId/observe-streamVNext",
|
|
11129
|
+
w({
|
|
11130
|
+
description: "Observe workflow stream in real-time using the VNext streaming API",
|
|
11131
|
+
parameters: [
|
|
11132
|
+
{
|
|
11133
|
+
name: "workflowId",
|
|
11134
|
+
in: "path",
|
|
11135
|
+
required: true,
|
|
11136
|
+
schema: { type: "string" }
|
|
11137
|
+
},
|
|
11138
|
+
{
|
|
11139
|
+
name: "runId",
|
|
11140
|
+
in: "query",
|
|
11141
|
+
required: true,
|
|
11142
|
+
schema: { type: "string" }
|
|
11143
|
+
}
|
|
11144
|
+
],
|
|
11145
|
+
responses: {
|
|
11146
|
+
200: {
|
|
11147
|
+
description: "workflow stream vNext observed"
|
|
11148
|
+
},
|
|
11149
|
+
404: {
|
|
11150
|
+
description: "workflow not found"
|
|
11151
|
+
}
|
|
11152
|
+
},
|
|
11153
|
+
tags: ["workflows"]
|
|
11154
|
+
}),
|
|
11155
|
+
observeStreamVNextWorkflowHandler
|
|
11156
|
+
);
|
|
11325
11157
|
router.post(
|
|
11326
11158
|
"/:workflowId/create-run",
|
|
11327
11159
|
bodyLimit.bodyLimit(bodyLimitOptions),
|
|
@@ -12000,7 +11832,6 @@ async function createHonoServer(mastra, options = {
|
|
|
12000
11832
|
getModelProvidersHandler
|
|
12001
11833
|
);
|
|
12002
11834
|
app.route("/api/agents", agentsRouter(bodyLimitOptions));
|
|
12003
|
-
app.route("/api/networks", vNextNetworksRouter(bodyLimitOptions));
|
|
12004
11835
|
if (options.isDev) {
|
|
12005
11836
|
app.route("/api/agents", agentsRouterDev(bodyLimitOptions));
|
|
12006
11837
|
}
|