@mastra/deployer 0.24.0 → 1.0.0-beta.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 +230 -95
- 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 +10 -15
- package/dist/build/index.d.ts +0 -1
- package/dist/build/index.d.ts.map +1 -1
- package/dist/build/index.js +3 -4
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.d.ts +2 -2
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/index.js +1 -1
- package/dist/{chunk-OART5HV7.cjs → chunk-AQAOWLJJ.cjs} +29 -124
- package/dist/chunk-AQAOWLJJ.cjs.map +1 -0
- package/dist/{chunk-IAEJ3C3J.cjs → chunk-C74EXQSL.cjs} +12 -12
- package/dist/chunk-C74EXQSL.cjs.map +1 -0
- package/dist/{chunk-CVRN2K4O.js → chunk-H3LLQ2MW.js} +12 -12
- package/dist/chunk-H3LLQ2MW.js.map +1 -0
- package/dist/{chunk-FD5X42ZU.js → chunk-HQJR52M7.js} +4 -4
- package/dist/{chunk-FD5X42ZU.js.map → chunk-HQJR52M7.js.map} +1 -1
- package/dist/{chunk-NSINCI76.cjs → chunk-IL2VLNIJ.cjs} +9 -9
- package/dist/{chunk-NSINCI76.cjs.map → chunk-IL2VLNIJ.cjs.map} +1 -1
- package/dist/{chunk-XHLN6E4D.js → chunk-OFUWEVGF.js} +3 -3
- package/dist/{chunk-XHLN6E4D.js.map → chunk-OFUWEVGF.js.map} +1 -1
- package/dist/{chunk-Z546LAA6.cjs → chunk-TDWIGFVF.cjs} +14 -14
- package/dist/{chunk-Z546LAA6.cjs.map → chunk-TDWIGFVF.cjs.map} +1 -1
- package/dist/{chunk-VDRZB7JQ.js → chunk-WBAWUM7Z.js} +23 -116
- package/dist/chunk-WBAWUM7Z.js.map +1 -0
- package/dist/index.cjs +5 -5
- package/dist/index.js +2 -2
- package/dist/server/handlers/health.d.ts +5 -0
- package/dist/server/handlers/health.d.ts.map +1 -0
- package/dist/server/handlers/prompt.d.ts.map +1 -1
- package/dist/server/handlers/routes/agent-builder/handlers.d.ts +5 -2
- package/dist/server/handlers/routes/agent-builder/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/agent-builder/router.d.ts.map +1 -1
- package/dist/server/handlers/routes/agents/handlers.d.ts +21 -143
- 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/logs/handlers.d.ts +3 -3
- package/dist/server/handlers/routes/logs/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/mcp/handlers.d.ts +1 -1
- package/dist/server/handlers/routes/mcp/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/memory/handlers.d.ts +2 -4
- package/dist/server/handlers/routes/memory/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/memory/router.d.ts.map +1 -1
- package/dist/server/handlers/routes/observability/handlers.d.ts +3 -3
- package/dist/server/handlers/routes/observability/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/observability/router.d.ts.map +1 -1
- package/dist/server/handlers/routes/scores/handlers.d.ts +8 -6
- package/dist/server/handlers/routes/scores/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/tools/handlers.d.ts +1 -1
- package/dist/server/handlers/routes/tools/handlers.d.ts.map +1 -1
- package/dist/server/handlers/routes/workflows/handlers.d.ts +2 -4
- 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/handlers/utils/query-parsers.d.ts +15 -0
- package/dist/server/handlers/utils/query-parsers.d.ts.map +1 -1
- package/dist/server/index.cjs +1207 -1559
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1214 -1566
- package/dist/server/index.js.map +1 -1
- package/dist/server/welcome.d.ts +1 -1
- package/dist/server/welcome.d.ts.map +1 -1
- package/package.json +11 -15
- package/dist/build/babel/remove-all-options-telemetry.d.ts +0 -5
- package/dist/build/babel/remove-all-options-telemetry.d.ts.map +0 -1
- package/dist/build/customInstrumentation.d.ts +0 -10
- package/dist/build/customInstrumentation.d.ts.map +0 -1
- package/dist/build/telemetry.d.ts +0 -8
- package/dist/build/telemetry.d.ts.map +0 -1
- package/dist/chunk-AJX72IGP.cjs +0 -28
- package/dist/chunk-AJX72IGP.cjs.map +0 -1
- package/dist/chunk-B2Q76NIL.js +0 -26
- package/dist/chunk-B2Q76NIL.js.map +0 -1
- package/dist/chunk-CVRN2K4O.js.map +0 -1
- package/dist/chunk-IAEJ3C3J.cjs.map +0 -1
- package/dist/chunk-OART5HV7.cjs.map +0 -1
- package/dist/chunk-VDRZB7JQ.js.map +0 -1
- package/dist/server/handlers/routes/telemetry/handlers.d.ts +0 -4
- package/dist/server/handlers/routes/telemetry/handlers.d.ts.map +0 -1
- package/dist/server/handlers/routes/telemetry/router.d.ts +0 -3
- package/dist/server/handlers/routes/telemetry/router.d.ts.map +0 -1
- package/dist/server/handlers/routes/workflows/legacyWorkflows.d.ts +0 -11
- package/dist/server/handlers/routes/workflows/legacyWorkflows.d.ts.map +0 -1
- package/dist/templates/instrumentation-template.js +0 -172
package/dist/server/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import crypto, { randomUUID } from 'crypto';
|
|
2
1
|
import { readFile } from 'fs/promises';
|
|
3
2
|
import * as https from 'https';
|
|
4
3
|
import { join } from 'path/posix';
|
|
5
4
|
import { createServer } from 'http';
|
|
6
5
|
import { Http2ServerRequest } from 'http2';
|
|
7
6
|
import { Writable, Readable } from 'stream';
|
|
7
|
+
import crypto, { randomUUID } from 'crypto';
|
|
8
8
|
import { getMimeType } from 'hono/utils/mime';
|
|
9
9
|
import { existsSync, createReadStream, lstatSync } from 'fs';
|
|
10
10
|
import { join as join$1 } from 'path';
|
|
11
11
|
import { html } from 'hono/html';
|
|
12
|
-
import {
|
|
13
|
-
import { Telemetry } from '@mastra/core/telemetry';
|
|
12
|
+
import { RequestContext } from '@mastra/core/request-context';
|
|
14
13
|
import { Tool } from '@mastra/core/tools';
|
|
15
14
|
import { InMemoryTaskStore } from '@mastra/server/a2a/store';
|
|
16
15
|
import { Hono } from 'hono';
|
|
@@ -21,26 +20,24 @@ import { HTTPException } from 'hono/http-exception';
|
|
|
21
20
|
import { getAgentCardByIdHandler as getAgentCardByIdHandler$1, getAgentExecutionHandler as getAgentExecutionHandler$1 } from '@mastra/server/handlers/a2a';
|
|
22
21
|
import { stream } from 'hono/streaming';
|
|
23
22
|
import { bodyLimit } from 'hono/body-limit';
|
|
24
|
-
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,
|
|
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, resumeStreamAgentBuilderActionHandler as resumeStreamAgentBuilderActionHandler$1, streamLegacyAgentBuilderActionHandler as streamLegacyAgentBuilderActionHandler$1, observeStreamLegacyAgentBuilderActionHandler as observeStreamLegacyAgentBuilderActionHandler$1, streamAgentBuilderActionHandler as streamAgentBuilderActionHandler$1, observeStreamAgentBuilderActionHandler as observeStreamAgentBuilderActionHandler$1, observeStreamVNextAgentBuilderActionHandler as observeStreamVNextAgentBuilderActionHandler$1, streamVNextAgentBuilderActionHandler as streamVNextAgentBuilderActionHandler$1, createAgentBuilderActionRunHandler as createAgentBuilderActionRunHandler$1, startAsyncAgentBuilderActionHandler as startAsyncAgentBuilderActionHandler$1, startAgentBuilderActionRunHandler as startAgentBuilderActionRunHandler$1, cancelAgentBuilderActionRunHandler as cancelAgentBuilderActionRunHandler$1 } from '@mastra/server/handlers/agent-builder';
|
|
25
24
|
import { Agent } from '@mastra/core/agent';
|
|
26
25
|
import { z } from 'zod';
|
|
27
|
-
import { getAgentToolHandler as getAgentToolHandler$1, executeAgentToolHandler as executeAgentToolHandler$1,
|
|
26
|
+
import { getAgentToolHandler as getAgentToolHandler$1, executeAgentToolHandler as executeAgentToolHandler$1, listToolsHandler as listToolsHandler$1, getToolByIdHandler as getToolByIdHandler$1, executeToolHandler as executeToolHandler$1 } from '@mastra/server/handlers/tools';
|
|
28
27
|
import { MastraError, ErrorCategory, ErrorDomain, getErrorFromUnknown } from '@mastra/core/error';
|
|
29
28
|
import { PROVIDER_REGISTRY, getProviderConfig } from '@mastra/core/llm';
|
|
30
29
|
import { ChunkFrom } from '@mastra/core/stream';
|
|
31
|
-
import {
|
|
30
|
+
import { listAgentsHandler as listAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, generateLegacyHandler as generateLegacyHandler$1, generateHandler as generateHandler$1, getAgentFromSystem, streamNetworkHandler as streamNetworkHandler$1, streamGenerateHandler as streamGenerateHandler$1, streamGenerateLegacyHandler as streamGenerateLegacyHandler$1, streamUIMessageHandler as streamUIMessageHandler$1, updateAgentModelHandler as updateAgentModelHandler$1, resetAgentModelHandler as resetAgentModelHandler$1, reorderAgentModelListHandler as reorderAgentModelListHandler$1, updateAgentModelInModelListHandler as updateAgentModelInModelListHandler$1, approveToolCallHandler as approveToolCallHandler$1, declineToolCallHandler as declineToolCallHandler$1 } from '@mastra/server/handlers/agents';
|
|
32
31
|
import { getSpeakersHandler as getSpeakersHandler$1, generateSpeechHandler, getListenerHandler as getListenerHandler$1, transcribeSpeechHandler } from '@mastra/server/handlers/voice';
|
|
33
|
-
import {
|
|
32
|
+
import { listLogsHandler as listLogsHandler$1, listLogTransports as listLogTransports$1, listLogsByRunIdHandler as listLogsByRunIdHandler$1 } from '@mastra/server/handlers/logs';
|
|
34
33
|
import util from 'util';
|
|
35
34
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
36
|
-
import { getMemoryStatusHandler as getMemoryStatusHandler$1,
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import { getTelemetryHandler as getTelemetryHandler$1, storeTelemetryHandler as storeTelemetryHandler$1 } from '@mastra/server/handlers/telemetry';
|
|
35
|
+
import { getMemoryStatusHandler as getMemoryStatusHandler$1, listThreadsHandler as listThreadsHandler$1, getThreadByIdHandler as getThreadByIdHandler$1, listMessagesHandler as listMessagesHandler$1, createThreadHandler as createThreadHandler$1, updateThreadHandler as updateThreadHandler$1, deleteThreadHandler as deleteThreadHandler$1, saveMessagesHandler as saveMessagesHandler$1, deleteMessagesHandler as deleteMessagesHandler$1, getMemoryConfigHandler as getMemoryConfigHandler$1, searchMemoryHandler as searchMemoryHandler$1, getWorkingMemoryHandler as getWorkingMemoryHandler$1, updateWorkingMemoryHandler as updateWorkingMemoryHandler$1 } from '@mastra/server/handlers/memory';
|
|
36
|
+
import { SpanType } from '@mastra/core/observability';
|
|
37
|
+
import { getTracesPaginatedHandler as getTracesPaginatedHandler$1, getTraceHandler as getTraceHandler$1, listScoresBySpan as listScoresBySpan$1, scoreTracesHandler } from '@mastra/server/handlers/observability';
|
|
38
|
+
import { listScorersHandler as listScorersHandler$1, getScorerHandler as getScorerHandler$1, listScoresByRunIdHandler as listScoresByRunIdHandler$1, listScoresByScorerIdHandler as listScoresByScorerIdHandler$1, listScoresByEntityIdHandler as listScoresByEntityIdHandler$1, saveScoreHandler as saveScoreHandler$1 } from '@mastra/server/handlers/scores';
|
|
41
39
|
import { upsertVectors as upsertVectors$1, createIndex as createIndex$1, queryVectors as queryVectors$1, listIndexes as listIndexes$1, describeIndex as describeIndex$1, deleteIndex as deleteIndex$1 } from '@mastra/server/handlers/vector';
|
|
42
|
-
import {
|
|
43
|
-
import { getLegacyWorkflowsHandler as getLegacyWorkflowsHandler$1, getLegacyWorkflowByIdHandler as getLegacyWorkflowByIdHandler$1, getLegacyWorkflowRunsHandler as getLegacyWorkflowRunsHandler$1, resumeLegacyWorkflowHandler as resumeLegacyWorkflowHandler$1, resumeAsyncLegacyWorkflowHandler as resumeAsyncLegacyWorkflowHandler$1, createLegacyWorkflowRunHandler as createLegacyWorkflowRunHandler$1, startAsyncLegacyWorkflowHandler as startAsyncLegacyWorkflowHandler$1, startLegacyWorkflowRunHandler as startLegacyWorkflowRunHandler$1, watchLegacyWorkflowHandler as watchLegacyWorkflowHandler$1 } from '@mastra/server/handlers/legacyWorkflows';
|
|
40
|
+
import { listWorkflowsHandler as listWorkflowsHandler$1, getWorkflowByIdHandler as getWorkflowByIdHandler$1, listWorkflowRunsHandler as listWorkflowRunsHandler$1, getWorkflowRunExecutionResultHandler as getWorkflowRunExecutionResultHandler$1, getWorkflowRunByIdHandler as getWorkflowRunByIdHandler$1, resumeWorkflowHandler as resumeWorkflowHandler$1, resumeStreamWorkflowHandler as resumeStreamWorkflowHandler$1, resumeAsyncWorkflowHandler as resumeAsyncWorkflowHandler$1, streamLegacyWorkflowHandler as streamLegacyWorkflowHandler$1, observeStreamLegacyWorkflowHandler as observeStreamLegacyWorkflowHandler$1, streamVNextWorkflowHandler as streamVNextWorkflowHandler$1, observeStreamVNextWorkflowHandler as observeStreamVNextWorkflowHandler$1, createWorkflowRunHandler as createWorkflowRunHandler$1, startAsyncWorkflowHandler as startAsyncWorkflowHandler$1, startWorkflowRunHandler as startWorkflowRunHandler$1, cancelWorkflowRunHandler as cancelWorkflowRunHandler$1 } from '@mastra/server/handlers/workflows';
|
|
44
41
|
|
|
45
42
|
// src/server/index.ts
|
|
46
43
|
var RequestError = class extends Error {
|
|
@@ -327,13 +324,13 @@ function writeFromReadableStreamDefaultReader(reader, writable, currentReadPromi
|
|
|
327
324
|
}
|
|
328
325
|
}
|
|
329
326
|
}
|
|
330
|
-
function writeFromReadableStream(
|
|
331
|
-
if (
|
|
327
|
+
function writeFromReadableStream(stream5, writable) {
|
|
328
|
+
if (stream5.locked) {
|
|
332
329
|
throw new TypeError("ReadableStream is locked.");
|
|
333
330
|
} else if (writable.destroyed) {
|
|
334
331
|
return;
|
|
335
332
|
}
|
|
336
|
-
return writeFromReadableStreamDefaultReader(
|
|
333
|
+
return writeFromReadableStreamDefaultReader(stream5.getReader(), writable);
|
|
337
334
|
}
|
|
338
335
|
var buildOutgoingHttpHeaders = (headers) => {
|
|
339
336
|
const res = {};
|
|
@@ -598,21 +595,21 @@ var ENCODINGS = {
|
|
|
598
595
|
gzip: ".gz"
|
|
599
596
|
};
|
|
600
597
|
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
601
|
-
var createStreamBody = (
|
|
598
|
+
var createStreamBody = (stream5) => {
|
|
602
599
|
const body = new ReadableStream({
|
|
603
600
|
start(controller) {
|
|
604
|
-
|
|
601
|
+
stream5.on("data", (chunk) => {
|
|
605
602
|
controller.enqueue(chunk);
|
|
606
603
|
});
|
|
607
|
-
|
|
604
|
+
stream5.on("error", (err) => {
|
|
608
605
|
controller.error(err);
|
|
609
606
|
});
|
|
610
|
-
|
|
607
|
+
stream5.on("end", () => {
|
|
611
608
|
controller.close();
|
|
612
609
|
});
|
|
613
610
|
},
|
|
614
611
|
cancel() {
|
|
615
|
-
|
|
612
|
+
stream5.destroy();
|
|
616
613
|
}
|
|
617
614
|
});
|
|
618
615
|
return body;
|
|
@@ -663,7 +660,6 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
663
660
|
await options.onNotFound?.(path, c2);
|
|
664
661
|
return next();
|
|
665
662
|
}
|
|
666
|
-
await options.onFound?.(path, c2);
|
|
667
663
|
const mimeType = getMimeType(path);
|
|
668
664
|
c2.header("Content-Type", mimeType || "application/octet-stream");
|
|
669
665
|
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
@@ -684,30 +680,33 @@ var serveStatic = (options = { root: "" }) => {
|
|
|
684
680
|
}
|
|
685
681
|
}
|
|
686
682
|
}
|
|
683
|
+
let result;
|
|
687
684
|
const size = stats.size;
|
|
685
|
+
const range = c2.req.header("range") || "";
|
|
688
686
|
if (c2.req.method == "HEAD" || c2.req.method == "OPTIONS") {
|
|
689
687
|
c2.header("Content-Length", size.toString());
|
|
690
688
|
c2.status(200);
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
const range = c2.req.header("range") || "";
|
|
694
|
-
if (!range) {
|
|
689
|
+
result = c2.body(null);
|
|
690
|
+
} else if (!range) {
|
|
695
691
|
c2.header("Content-Length", size.toString());
|
|
696
|
-
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
692
|
+
result = c2.body(createStreamBody(createReadStream(path)), 200);
|
|
693
|
+
} else {
|
|
694
|
+
c2.header("Accept-Ranges", "bytes");
|
|
695
|
+
c2.header("Date", stats.birthtime.toUTCString());
|
|
696
|
+
const parts = range.replace(/bytes=/, "").split("-", 2);
|
|
697
|
+
const start = parseInt(parts[0], 10) || 0;
|
|
698
|
+
let end = parseInt(parts[1], 10) || size - 1;
|
|
699
|
+
if (size < end - start + 1) {
|
|
700
|
+
end = size - 1;
|
|
701
|
+
}
|
|
702
|
+
const chunksize = end - start + 1;
|
|
703
|
+
const stream5 = createReadStream(path, { start, end });
|
|
704
|
+
c2.header("Content-Length", chunksize.toString());
|
|
705
|
+
c2.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
706
|
+
result = c2.body(createStreamBody(stream5), 206);
|
|
707
|
+
}
|
|
708
|
+
await options.onFound?.(path, c2);
|
|
709
|
+
return result;
|
|
711
710
|
};
|
|
712
711
|
};
|
|
713
712
|
var RENDER_TYPE = {
|
|
@@ -828,7 +827,7 @@ var middleware = (options) => async (c2) => {
|
|
|
828
827
|
);
|
|
829
828
|
};
|
|
830
829
|
|
|
831
|
-
// ../../node_modules/.pnpm/hono-openapi@0.4.8_hono@4.10.
|
|
830
|
+
// ../../node_modules/.pnpm/hono-openapi@0.4.8_hono@4.10.3_openapi-types@12.1.3_zod@3.25.76/node_modules/hono-openapi/utils.js
|
|
832
831
|
var e = Symbol("openapi");
|
|
833
832
|
var n = ["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"];
|
|
834
833
|
var s2 = (e2) => e2.charAt(0).toUpperCase() + e2.slice(1);
|
|
@@ -974,18 +973,18 @@ async function x(e2, t2, n2 = {}) {
|
|
|
974
973
|
async function getAgentCardByIdHandler(c2) {
|
|
975
974
|
const mastra = c2.get("mastra");
|
|
976
975
|
const agentId = c2.req.param("agentId");
|
|
977
|
-
const
|
|
976
|
+
const requestContext = c2.get("requestContext");
|
|
978
977
|
const result = await getAgentCardByIdHandler$1({
|
|
979
978
|
mastra,
|
|
980
979
|
agentId,
|
|
981
|
-
|
|
980
|
+
requestContext
|
|
982
981
|
});
|
|
983
982
|
return c2.json(result);
|
|
984
983
|
}
|
|
985
984
|
async function getAgentExecutionHandler(c2) {
|
|
986
985
|
const mastra = c2.get("mastra");
|
|
987
986
|
const agentId = c2.req.param("agentId");
|
|
988
|
-
const
|
|
987
|
+
const requestContext = c2.get("requestContext");
|
|
989
988
|
const taskStore = c2.get("taskStore");
|
|
990
989
|
const logger2 = mastra.getLogger();
|
|
991
990
|
const body = await c2.req.json();
|
|
@@ -995,7 +994,7 @@ async function getAgentExecutionHandler(c2) {
|
|
|
995
994
|
const result = await getAgentExecutionHandler$1({
|
|
996
995
|
mastra,
|
|
997
996
|
agentId,
|
|
998
|
-
|
|
997
|
+
requestContext,
|
|
999
998
|
requestId: randomUUID(),
|
|
1000
999
|
method: body.method,
|
|
1001
1000
|
params: body.params,
|
|
@@ -1005,15 +1004,15 @@ async function getAgentExecutionHandler(c2) {
|
|
|
1005
1004
|
if (body.method === "message/stream") {
|
|
1006
1005
|
return stream(
|
|
1007
1006
|
c2,
|
|
1008
|
-
async (
|
|
1007
|
+
async (stream5) => {
|
|
1009
1008
|
try {
|
|
1010
|
-
|
|
1009
|
+
stream5.onAbort(() => {
|
|
1011
1010
|
if (!result.locked) {
|
|
1012
1011
|
return result.cancel();
|
|
1013
1012
|
}
|
|
1014
1013
|
});
|
|
1015
1014
|
for await (const chunk of result) {
|
|
1016
|
-
await
|
|
1015
|
+
await stream5.write(JSON.stringify(chunk) + "");
|
|
1017
1016
|
}
|
|
1018
1017
|
} catch (err) {
|
|
1019
1018
|
logger2.error("Error in message/stream stream: " + err?.message);
|
|
@@ -1153,7 +1152,7 @@ var checkRules = async (rules, path, method, user) => {
|
|
|
1153
1152
|
// src/server/handlers/auth/index.ts
|
|
1154
1153
|
var authenticationMiddleware = async (c2, next) => {
|
|
1155
1154
|
const mastra = c2.get("mastra");
|
|
1156
|
-
const authConfig = mastra.getServer()?.
|
|
1155
|
+
const authConfig = mastra.getServer()?.auth;
|
|
1157
1156
|
const customRouteAuthConfig = c2.get("customRouteAuthConfig");
|
|
1158
1157
|
if (!authConfig) {
|
|
1159
1158
|
return next();
|
|
@@ -1185,7 +1184,7 @@ var authenticationMiddleware = async (c2, next) => {
|
|
|
1185
1184
|
if (!user) {
|
|
1186
1185
|
return c2.json({ error: "Invalid or expired token" }, 401);
|
|
1187
1186
|
}
|
|
1188
|
-
c2.get("
|
|
1187
|
+
c2.get("requestContext").set("user", user);
|
|
1189
1188
|
return next();
|
|
1190
1189
|
} catch (err) {
|
|
1191
1190
|
console.error(err);
|
|
@@ -1194,7 +1193,7 @@ var authenticationMiddleware = async (c2, next) => {
|
|
|
1194
1193
|
};
|
|
1195
1194
|
var authorizationMiddleware = async (c2, next) => {
|
|
1196
1195
|
const mastra = c2.get("mastra");
|
|
1197
|
-
const authConfig = mastra.getServer()?.
|
|
1196
|
+
const authConfig = mastra.getServer()?.auth;
|
|
1198
1197
|
const customRouteAuthConfig = c2.get("customRouteAuthConfig");
|
|
1199
1198
|
if (!authConfig) {
|
|
1200
1199
|
return next();
|
|
@@ -1210,7 +1209,7 @@ var authorizationMiddleware = async (c2, next) => {
|
|
|
1210
1209
|
if (canAccessPublicly(path, method, authConfig)) {
|
|
1211
1210
|
return next();
|
|
1212
1211
|
}
|
|
1213
|
-
const user = c2.get("
|
|
1212
|
+
const user = c2.get("requestContext").get("user");
|
|
1214
1213
|
if ("authorizeUser" in authConfig && typeof authConfig.authorizeUser === "function") {
|
|
1215
1214
|
try {
|
|
1216
1215
|
const isAuthorized = await authConfig.authorizeUser(user, c2.req);
|
|
@@ -1255,7 +1254,7 @@ var authorizationMiddleware = async (c2, next) => {
|
|
|
1255
1254
|
var clients = /* @__PURE__ */ new Set();
|
|
1256
1255
|
var hotReloadDisabled = false;
|
|
1257
1256
|
function handleClientsRefresh(c2) {
|
|
1258
|
-
const
|
|
1257
|
+
const stream5 = new ReadableStream({
|
|
1259
1258
|
start(controller) {
|
|
1260
1259
|
clients.add(controller);
|
|
1261
1260
|
controller.enqueue("data: connected\n\n");
|
|
@@ -1264,7 +1263,7 @@ function handleClientsRefresh(c2) {
|
|
|
1264
1263
|
});
|
|
1265
1264
|
}
|
|
1266
1265
|
});
|
|
1267
|
-
return new Response(
|
|
1266
|
+
return new Response(stream5, {
|
|
1268
1267
|
headers: {
|
|
1269
1268
|
"Content-Type": "text/event-stream",
|
|
1270
1269
|
"Cache-Control": "no-cache",
|
|
@@ -1312,6 +1311,11 @@ function errorHandler(err, c2, isDev) {
|
|
|
1312
1311
|
return c2.json({ error: "Internal Server Error" }, 500);
|
|
1313
1312
|
}
|
|
1314
1313
|
|
|
1314
|
+
// src/server/handlers/health.ts
|
|
1315
|
+
async function healthHandler(c2) {
|
|
1316
|
+
return c2.json({ success: true }, 200);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1315
1319
|
// src/server/handlers/root.ts
|
|
1316
1320
|
async function rootHandler(c2) {
|
|
1317
1321
|
const baseUrl = new URL(c2.req.url).origin;
|
|
@@ -1473,17 +1477,18 @@ async function createAgentBuilderActionRunHandler(c2) {
|
|
|
1473
1477
|
async function startAsyncAgentBuilderActionHandler(c2) {
|
|
1474
1478
|
try {
|
|
1475
1479
|
const mastra = c2.get("mastra");
|
|
1476
|
-
const
|
|
1480
|
+
const requestContext = c2.get("requestContext");
|
|
1477
1481
|
const actionId = c2.req.param("actionId");
|
|
1478
|
-
const { inputData } = await c2.req.json();
|
|
1482
|
+
const { inputData, tracingOptions } = await c2.req.json();
|
|
1479
1483
|
const runId = c2.req.query("runId");
|
|
1480
1484
|
disableHotReload();
|
|
1481
1485
|
const result = await startAsyncAgentBuilderActionHandler$1({
|
|
1482
1486
|
mastra,
|
|
1483
|
-
|
|
1487
|
+
requestContext,
|
|
1484
1488
|
actionId,
|
|
1485
1489
|
runId,
|
|
1486
|
-
inputData
|
|
1490
|
+
inputData,
|
|
1491
|
+
tracingOptions
|
|
1487
1492
|
});
|
|
1488
1493
|
enableHotReload();
|
|
1489
1494
|
return c2.json(result);
|
|
@@ -1495,73 +1500,35 @@ async function startAsyncAgentBuilderActionHandler(c2) {
|
|
|
1495
1500
|
async function startAgentBuilderActionRunHandler(c2) {
|
|
1496
1501
|
try {
|
|
1497
1502
|
const mastra = c2.get("mastra");
|
|
1498
|
-
const
|
|
1503
|
+
const requestContext = c2.get("requestContext");
|
|
1499
1504
|
const actionId = c2.req.param("actionId");
|
|
1500
|
-
const { inputData } = await c2.req.json();
|
|
1505
|
+
const { inputData, tracingOptions } = await c2.req.json();
|
|
1501
1506
|
const runId = c2.req.query("runId");
|
|
1502
1507
|
await startAgentBuilderActionRunHandler$1({
|
|
1503
1508
|
mastra,
|
|
1504
|
-
|
|
1509
|
+
requestContext,
|
|
1505
1510
|
actionId,
|
|
1506
1511
|
runId,
|
|
1507
|
-
inputData
|
|
1512
|
+
inputData,
|
|
1513
|
+
tracingOptions
|
|
1508
1514
|
});
|
|
1509
1515
|
return c2.json({ message: "Agent builder action run started" });
|
|
1510
1516
|
} catch (error) {
|
|
1511
1517
|
return handleError(error, "Error starting agent builder action run");
|
|
1512
1518
|
}
|
|
1513
1519
|
}
|
|
1514
|
-
async function watchAgentBuilderActionHandler(c2) {
|
|
1515
|
-
try {
|
|
1516
|
-
const mastra = c2.get("mastra");
|
|
1517
|
-
const logger2 = mastra.getLogger();
|
|
1518
|
-
const actionId = c2.req.param("actionId");
|
|
1519
|
-
const runId = c2.req.query("runId");
|
|
1520
|
-
const eventType = c2.req.query("eventType");
|
|
1521
|
-
if (!runId) {
|
|
1522
|
-
throw new HTTPException(400, { message: "runId required to watch action" });
|
|
1523
|
-
}
|
|
1524
|
-
c2.header("Transfer-Encoding", "chunked");
|
|
1525
|
-
return stream(c2, async (stream6) => {
|
|
1526
|
-
try {
|
|
1527
|
-
disableHotReload();
|
|
1528
|
-
const result = await watchAgentBuilderActionHandler$1({
|
|
1529
|
-
mastra,
|
|
1530
|
-
actionId,
|
|
1531
|
-
runId,
|
|
1532
|
-
eventType
|
|
1533
|
-
});
|
|
1534
|
-
const reader = result.getReader();
|
|
1535
|
-
stream6.onAbort(() => {
|
|
1536
|
-
void reader.cancel("request aborted");
|
|
1537
|
-
});
|
|
1538
|
-
let chunkResult;
|
|
1539
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1540
|
-
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
1541
|
-
}
|
|
1542
|
-
enableHotReload();
|
|
1543
|
-
} catch (err) {
|
|
1544
|
-
enableHotReload();
|
|
1545
|
-
logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
|
|
1546
|
-
}
|
|
1547
|
-
});
|
|
1548
|
-
} catch (error) {
|
|
1549
|
-
enableHotReload();
|
|
1550
|
-
return handleError(error, "Error watching agent builder action");
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
1520
|
async function streamAgentBuilderActionHandler(c2) {
|
|
1554
1521
|
try {
|
|
1555
1522
|
const mastra = c2.get("mastra");
|
|
1556
|
-
const
|
|
1523
|
+
const requestContext = c2.get("requestContext");
|
|
1557
1524
|
const logger2 = mastra.getLogger();
|
|
1558
1525
|
const actionId = c2.req.param("actionId");
|
|
1559
|
-
const { inputData } = await c2.req.json();
|
|
1526
|
+
const { inputData, tracingOptions } = await c2.req.json();
|
|
1560
1527
|
const runId = c2.req.query("runId");
|
|
1561
1528
|
c2.header("Transfer-Encoding", "chunked");
|
|
1562
1529
|
return stream(
|
|
1563
1530
|
c2,
|
|
1564
|
-
async (
|
|
1531
|
+
async (stream5) => {
|
|
1565
1532
|
try {
|
|
1566
1533
|
disableHotReload();
|
|
1567
1534
|
const result = await streamAgentBuilderActionHandler$1({
|
|
@@ -1569,20 +1536,21 @@ async function streamAgentBuilderActionHandler(c2) {
|
|
|
1569
1536
|
actionId,
|
|
1570
1537
|
runId,
|
|
1571
1538
|
inputData,
|
|
1572
|
-
|
|
1539
|
+
requestContext,
|
|
1540
|
+
tracingOptions
|
|
1573
1541
|
});
|
|
1574
|
-
const reader = result.
|
|
1575
|
-
|
|
1542
|
+
const reader = result.getReader();
|
|
1543
|
+
stream5.onAbort(() => {
|
|
1576
1544
|
void reader.cancel("request aborted");
|
|
1577
1545
|
});
|
|
1578
1546
|
let chunkResult;
|
|
1579
1547
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1580
|
-
await
|
|
1548
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1581
1549
|
}
|
|
1582
1550
|
} catch (err) {
|
|
1583
1551
|
logger2.error("Error in action stream: " + (err?.message ?? "Unknown error"));
|
|
1584
1552
|
}
|
|
1585
|
-
await
|
|
1553
|
+
await stream5.close();
|
|
1586
1554
|
enableHotReload();
|
|
1587
1555
|
},
|
|
1588
1556
|
async (err) => {
|
|
@@ -1597,15 +1565,15 @@ async function streamAgentBuilderActionHandler(c2) {
|
|
|
1597
1565
|
async function streamVNextAgentBuilderActionHandler(c2) {
|
|
1598
1566
|
try {
|
|
1599
1567
|
const mastra = c2.get("mastra");
|
|
1600
|
-
const
|
|
1568
|
+
const requestContext = c2.get("requestContext");
|
|
1601
1569
|
const logger2 = mastra.getLogger();
|
|
1602
1570
|
const actionId = c2.req.param("actionId");
|
|
1603
|
-
const { inputData } = await c2.req.json();
|
|
1571
|
+
const { inputData, closeOnSuspend, tracingOptions } = await c2.req.json();
|
|
1604
1572
|
const runId = c2.req.query("runId");
|
|
1605
1573
|
c2.header("Transfer-Encoding", "chunked");
|
|
1606
1574
|
return stream(
|
|
1607
1575
|
c2,
|
|
1608
|
-
async (
|
|
1576
|
+
async (stream5) => {
|
|
1609
1577
|
try {
|
|
1610
1578
|
disableHotReload();
|
|
1611
1579
|
const result = await streamVNextAgentBuilderActionHandler$1({
|
|
@@ -1613,15 +1581,17 @@ async function streamVNextAgentBuilderActionHandler(c2) {
|
|
|
1613
1581
|
actionId,
|
|
1614
1582
|
runId,
|
|
1615
1583
|
inputData,
|
|
1616
|
-
|
|
1584
|
+
requestContext,
|
|
1585
|
+
closeOnSuspend,
|
|
1586
|
+
tracingOptions
|
|
1617
1587
|
});
|
|
1618
1588
|
const reader = result.getReader();
|
|
1619
|
-
|
|
1589
|
+
stream5.onAbort(() => {
|
|
1620
1590
|
void reader.cancel("request aborted");
|
|
1621
1591
|
});
|
|
1622
1592
|
let chunkResult;
|
|
1623
1593
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1624
|
-
await
|
|
1594
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1625
1595
|
}
|
|
1626
1596
|
} catch (err) {
|
|
1627
1597
|
logger2.error("Error in action VNext stream: " + (err?.message ?? "Unknown error"));
|
|
@@ -1640,20 +1610,21 @@ async function streamVNextAgentBuilderActionHandler(c2) {
|
|
|
1640
1610
|
async function resumeAsyncAgentBuilderActionHandler(c2) {
|
|
1641
1611
|
try {
|
|
1642
1612
|
const mastra = c2.get("mastra");
|
|
1643
|
-
const
|
|
1613
|
+
const requestContext = c2.get("requestContext");
|
|
1644
1614
|
const actionId = c2.req.param("actionId");
|
|
1645
1615
|
const runId = c2.req.query("runId");
|
|
1646
|
-
const { step, resumeData } = await c2.req.json();
|
|
1616
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
1647
1617
|
if (!runId) {
|
|
1648
1618
|
throw new HTTPException(400, { message: "runId required to resume action" });
|
|
1649
1619
|
}
|
|
1650
1620
|
disableHotReload();
|
|
1651
1621
|
const result = await resumeAsyncAgentBuilderActionHandler$1({
|
|
1652
1622
|
mastra,
|
|
1653
|
-
|
|
1623
|
+
requestContext,
|
|
1654
1624
|
actionId,
|
|
1655
1625
|
runId,
|
|
1656
|
-
body: { step, resumeData }
|
|
1626
|
+
body: { step, resumeData },
|
|
1627
|
+
tracingOptions
|
|
1657
1628
|
});
|
|
1658
1629
|
enableHotReload();
|
|
1659
1630
|
return c2.json(result);
|
|
@@ -1665,20 +1636,21 @@ async function resumeAsyncAgentBuilderActionHandler(c2) {
|
|
|
1665
1636
|
async function resumeAgentBuilderActionHandler(c2) {
|
|
1666
1637
|
try {
|
|
1667
1638
|
const mastra = c2.get("mastra");
|
|
1668
|
-
const
|
|
1639
|
+
const requestContext = c2.get("requestContext");
|
|
1669
1640
|
const actionId = c2.req.param("actionId");
|
|
1670
1641
|
const runId = c2.req.query("runId");
|
|
1671
|
-
const { step, resumeData } = await c2.req.json();
|
|
1642
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
1672
1643
|
if (!runId) {
|
|
1673
1644
|
throw new HTTPException(400, { message: "runId required to resume action" });
|
|
1674
1645
|
}
|
|
1675
1646
|
disableHotReload();
|
|
1676
1647
|
await resumeAgentBuilderActionHandler$1({
|
|
1677
1648
|
mastra,
|
|
1678
|
-
|
|
1649
|
+
requestContext,
|
|
1679
1650
|
actionId,
|
|
1680
1651
|
runId,
|
|
1681
|
-
body: { step, resumeData }
|
|
1652
|
+
body: { step, resumeData },
|
|
1653
|
+
tracingOptions
|
|
1682
1654
|
});
|
|
1683
1655
|
enableHotReload();
|
|
1684
1656
|
return c2.json({ message: "Action run resumed" });
|
|
@@ -1691,14 +1663,15 @@ async function getAgentBuilderActionRunsHandler(c2) {
|
|
|
1691
1663
|
try {
|
|
1692
1664
|
const mastra = c2.get("mastra");
|
|
1693
1665
|
const actionId = c2.req.param("actionId");
|
|
1694
|
-
const
|
|
1666
|
+
const queryParams = c2.req.query();
|
|
1667
|
+
const { fromDate, toDate, perPage, page, resourceId } = queryParams;
|
|
1695
1668
|
const runs = await getAgentBuilderActionRunsHandler$1({
|
|
1696
1669
|
mastra,
|
|
1697
1670
|
actionId,
|
|
1698
1671
|
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
1699
1672
|
toDate: toDate ? new Date(toDate) : void 0,
|
|
1700
|
-
|
|
1701
|
-
|
|
1673
|
+
perPage: perPage !== null && perPage !== void 0 && !isNaN(Number(perPage)) ? Number(perPage) : void 0,
|
|
1674
|
+
page: page !== null && page !== void 0 && !isNaN(Number(page)) ? Number(page) : void 0,
|
|
1702
1675
|
resourceId
|
|
1703
1676
|
});
|
|
1704
1677
|
return c2.json(runs);
|
|
@@ -1751,22 +1724,219 @@ async function cancelAgentBuilderActionRunHandler(c2) {
|
|
|
1751
1724
|
return handleError(error, "Error cancelling agent builder action run");
|
|
1752
1725
|
}
|
|
1753
1726
|
}
|
|
1754
|
-
async function
|
|
1727
|
+
async function streamLegacyAgentBuilderActionHandler(c2) {
|
|
1755
1728
|
try {
|
|
1756
1729
|
const mastra = c2.get("mastra");
|
|
1730
|
+
const requestContext = c2.get("requestContext");
|
|
1731
|
+
const logger2 = mastra.getLogger();
|
|
1757
1732
|
const actionId = c2.req.param("actionId");
|
|
1758
|
-
const
|
|
1759
|
-
const
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1733
|
+
const { inputData, tracingOptions } = await c2.req.json();
|
|
1734
|
+
const runId = c2.req.query("runId");
|
|
1735
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1736
|
+
return stream(
|
|
1737
|
+
c2,
|
|
1738
|
+
async (stream5) => {
|
|
1739
|
+
try {
|
|
1740
|
+
disableHotReload();
|
|
1741
|
+
const result = await streamLegacyAgentBuilderActionHandler$1({
|
|
1742
|
+
mastra,
|
|
1743
|
+
actionId,
|
|
1744
|
+
runId,
|
|
1745
|
+
inputData,
|
|
1746
|
+
requestContext,
|
|
1747
|
+
tracingOptions
|
|
1748
|
+
});
|
|
1749
|
+
const reader = result?.stream?.getReader();
|
|
1750
|
+
if (!reader) {
|
|
1751
|
+
throw new Error("No reader available from legacy stream");
|
|
1752
|
+
}
|
|
1753
|
+
stream5.onAbort(() => {
|
|
1754
|
+
void reader.cancel("request aborted");
|
|
1755
|
+
});
|
|
1756
|
+
let chunkResult;
|
|
1757
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1758
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1759
|
+
}
|
|
1760
|
+
} catch (err) {
|
|
1761
|
+
logger2.error("Error in action legacy stream: " + (err?.message ?? "Unknown error"));
|
|
1762
|
+
}
|
|
1763
|
+
await stream5.close();
|
|
1764
|
+
enableHotReload();
|
|
1765
|
+
},
|
|
1766
|
+
async (err) => {
|
|
1767
|
+
logger2.error("Error in action legacy stream: " + err?.message);
|
|
1768
|
+
}
|
|
1769
|
+
);
|
|
1770
|
+
} catch (error) {
|
|
1771
|
+
enableHotReload();
|
|
1772
|
+
return handleError(error, "Error streaming legacy agent builder action");
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
async function observeStreamLegacyAgentBuilderActionHandler(c2) {
|
|
1776
|
+
try {
|
|
1777
|
+
const mastra = c2.get("mastra");
|
|
1778
|
+
const logger2 = mastra.getLogger();
|
|
1779
|
+
const actionId = c2.req.param("actionId");
|
|
1780
|
+
const runId = c2.req.query("runId");
|
|
1781
|
+
if (!runId) {
|
|
1782
|
+
throw new HTTPException(400, { message: "runId required to observe stream" });
|
|
1783
|
+
}
|
|
1784
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1785
|
+
return stream(c2, async (stream5) => {
|
|
1786
|
+
try {
|
|
1787
|
+
disableHotReload();
|
|
1788
|
+
const result = await observeStreamLegacyAgentBuilderActionHandler$1({
|
|
1789
|
+
mastra,
|
|
1790
|
+
actionId,
|
|
1791
|
+
runId
|
|
1792
|
+
});
|
|
1793
|
+
const reader = result?.getReader();
|
|
1794
|
+
if (!reader) {
|
|
1795
|
+
throw new Error("No reader available from observe stream");
|
|
1796
|
+
}
|
|
1797
|
+
stream5.onAbort(() => {
|
|
1798
|
+
void reader.cancel("request aborted");
|
|
1799
|
+
});
|
|
1800
|
+
let chunkResult;
|
|
1801
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1802
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1803
|
+
}
|
|
1804
|
+
enableHotReload();
|
|
1805
|
+
} catch (err) {
|
|
1806
|
+
enableHotReload();
|
|
1807
|
+
logger2.error("Error in observe legacy stream: " + (err?.message ?? "Unknown error"));
|
|
1808
|
+
}
|
|
1766
1809
|
});
|
|
1767
|
-
return c2.json(result);
|
|
1768
1810
|
} catch (error) {
|
|
1769
|
-
|
|
1811
|
+
enableHotReload();
|
|
1812
|
+
return handleError(error, "Error observing legacy stream for agent builder action");
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
async function observeStreamAgentBuilderActionHandler(c2) {
|
|
1816
|
+
try {
|
|
1817
|
+
const mastra = c2.get("mastra");
|
|
1818
|
+
const logger2 = mastra.getLogger();
|
|
1819
|
+
const actionId = c2.req.param("actionId");
|
|
1820
|
+
const runId = c2.req.query("runId");
|
|
1821
|
+
if (!runId) {
|
|
1822
|
+
throw new HTTPException(400, { message: "runId required to observe stream" });
|
|
1823
|
+
}
|
|
1824
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1825
|
+
return stream(c2, async (stream5) => {
|
|
1826
|
+
try {
|
|
1827
|
+
disableHotReload();
|
|
1828
|
+
const result = await observeStreamAgentBuilderActionHandler$1({
|
|
1829
|
+
mastra,
|
|
1830
|
+
actionId,
|
|
1831
|
+
runId
|
|
1832
|
+
});
|
|
1833
|
+
const reader = result?.getReader();
|
|
1834
|
+
if (!reader) {
|
|
1835
|
+
throw new Error("No reader available from observe stream");
|
|
1836
|
+
}
|
|
1837
|
+
stream5.onAbort(() => {
|
|
1838
|
+
void reader.cancel("request aborted");
|
|
1839
|
+
});
|
|
1840
|
+
let chunkResult;
|
|
1841
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1842
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1843
|
+
}
|
|
1844
|
+
enableHotReload();
|
|
1845
|
+
} catch (err) {
|
|
1846
|
+
enableHotReload();
|
|
1847
|
+
logger2.error("Error in observe stream: " + (err?.message ?? "Unknown error"));
|
|
1848
|
+
}
|
|
1849
|
+
});
|
|
1850
|
+
} catch (error) {
|
|
1851
|
+
enableHotReload();
|
|
1852
|
+
return handleError(error, "Error observing stream for agent builder action");
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
async function observeStreamVNextAgentBuilderActionHandler(c2) {
|
|
1856
|
+
try {
|
|
1857
|
+
const mastra = c2.get("mastra");
|
|
1858
|
+
const logger2 = mastra.getLogger();
|
|
1859
|
+
const actionId = c2.req.param("actionId");
|
|
1860
|
+
const runId = c2.req.query("runId");
|
|
1861
|
+
if (!runId) {
|
|
1862
|
+
throw new HTTPException(400, { message: "runId required to observe stream" });
|
|
1863
|
+
}
|
|
1864
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1865
|
+
return stream(c2, async (stream5) => {
|
|
1866
|
+
try {
|
|
1867
|
+
disableHotReload();
|
|
1868
|
+
const result = await observeStreamVNextAgentBuilderActionHandler$1({
|
|
1869
|
+
mastra,
|
|
1870
|
+
actionId,
|
|
1871
|
+
runId
|
|
1872
|
+
});
|
|
1873
|
+
const reader = result?.getReader();
|
|
1874
|
+
if (!reader) {
|
|
1875
|
+
throw new Error("No reader available from observe stream VNext");
|
|
1876
|
+
}
|
|
1877
|
+
stream5.onAbort(() => {
|
|
1878
|
+
void reader.cancel("request aborted");
|
|
1879
|
+
});
|
|
1880
|
+
let chunkResult;
|
|
1881
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1882
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1883
|
+
}
|
|
1884
|
+
enableHotReload();
|
|
1885
|
+
} catch (err) {
|
|
1886
|
+
enableHotReload();
|
|
1887
|
+
logger2.error("Error in observe VNext stream: " + (err?.message ?? "Unknown error"));
|
|
1888
|
+
}
|
|
1889
|
+
});
|
|
1890
|
+
} catch (error) {
|
|
1891
|
+
enableHotReload();
|
|
1892
|
+
return handleError(error, "Error observing VNext stream for agent builder action");
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
async function resumeStreamAgentBuilderActionHandler(c2) {
|
|
1896
|
+
try {
|
|
1897
|
+
const mastra = c2.get("mastra");
|
|
1898
|
+
const requestContext = c2.get("requestContext");
|
|
1899
|
+
const logger2 = mastra.getLogger();
|
|
1900
|
+
const actionId = c2.req.param("actionId");
|
|
1901
|
+
const runId = c2.req.query("runId");
|
|
1902
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
1903
|
+
if (!runId) {
|
|
1904
|
+
throw new HTTPException(400, { message: "runId required to resume stream" });
|
|
1905
|
+
}
|
|
1906
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1907
|
+
return stream(
|
|
1908
|
+
c2,
|
|
1909
|
+
async (stream5) => {
|
|
1910
|
+
try {
|
|
1911
|
+
disableHotReload();
|
|
1912
|
+
const result = await resumeStreamAgentBuilderActionHandler$1({
|
|
1913
|
+
mastra,
|
|
1914
|
+
actionId,
|
|
1915
|
+
runId,
|
|
1916
|
+
requestContext,
|
|
1917
|
+
body: { step, resumeData },
|
|
1918
|
+
tracingOptions
|
|
1919
|
+
});
|
|
1920
|
+
const reader = result.getReader();
|
|
1921
|
+
stream5.onAbort(() => {
|
|
1922
|
+
void reader.cancel("request aborted");
|
|
1923
|
+
});
|
|
1924
|
+
let chunkResult;
|
|
1925
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1926
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
1927
|
+
}
|
|
1928
|
+
} catch (err) {
|
|
1929
|
+
logger2.error("Error in resume stream: " + (err?.message ?? "Unknown error"));
|
|
1930
|
+
}
|
|
1931
|
+
enableHotReload();
|
|
1932
|
+
},
|
|
1933
|
+
async (err) => {
|
|
1934
|
+
logger2.error("Error in resume stream: " + err?.message);
|
|
1935
|
+
}
|
|
1936
|
+
);
|
|
1937
|
+
} catch (error) {
|
|
1938
|
+
enableHotReload();
|
|
1939
|
+
return handleError(error, "Error resuming stream for agent builder action");
|
|
1770
1940
|
}
|
|
1771
1941
|
}
|
|
1772
1942
|
|
|
@@ -1926,9 +2096,20 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
1926
2096
|
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
1927
2097
|
},
|
|
1928
2098
|
resumeData: { type: "object" },
|
|
1929
|
-
|
|
2099
|
+
requestContext: {
|
|
2100
|
+
type: "object",
|
|
2101
|
+
description: "Request Context for the agent builder action execution"
|
|
2102
|
+
},
|
|
2103
|
+
tracingOptions: {
|
|
1930
2104
|
type: "object",
|
|
1931
|
-
description: "
|
|
2105
|
+
description: "Tracing options for the action execution",
|
|
2106
|
+
properties: {
|
|
2107
|
+
metadata: {
|
|
2108
|
+
type: "object",
|
|
2109
|
+
description: "Custom metadata to attach to the trace",
|
|
2110
|
+
additionalProperties: true
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
1932
2113
|
}
|
|
1933
2114
|
}
|
|
1934
2115
|
}
|
|
@@ -1969,9 +2150,20 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
1969
2150
|
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
1970
2151
|
},
|
|
1971
2152
|
resumeData: { type: "object" },
|
|
1972
|
-
|
|
2153
|
+
requestContext: {
|
|
1973
2154
|
type: "object",
|
|
1974
|
-
description: "
|
|
2155
|
+
description: "Request Context for the agent builder action execution"
|
|
2156
|
+
},
|
|
2157
|
+
tracingOptions: {
|
|
2158
|
+
type: "object",
|
|
2159
|
+
description: "Tracing options for the action execution",
|
|
2160
|
+
properties: {
|
|
2161
|
+
metadata: {
|
|
2162
|
+
type: "object",
|
|
2163
|
+
description: "Custom metadata to attach to the trace",
|
|
2164
|
+
additionalProperties: true
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
1975
2167
|
}
|
|
1976
2168
|
}
|
|
1977
2169
|
}
|
|
@@ -1982,9 +2174,10 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
1982
2174
|
resumeAsyncAgentBuilderActionHandler
|
|
1983
2175
|
);
|
|
1984
2176
|
router.post(
|
|
1985
|
-
"/:actionId/stream",
|
|
2177
|
+
"/:actionId/resume-stream",
|
|
1986
2178
|
w({
|
|
1987
|
-
description: "
|
|
2179
|
+
description: "Resume a suspended agent builder action that uses streamVNext",
|
|
2180
|
+
tags: ["agent-builder"],
|
|
1988
2181
|
parameters: [
|
|
1989
2182
|
{
|
|
1990
2183
|
name: "actionId",
|
|
@@ -1995,7 +2188,7 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
1995
2188
|
{
|
|
1996
2189
|
name: "runId",
|
|
1997
2190
|
in: "query",
|
|
1998
|
-
required:
|
|
2191
|
+
required: true,
|
|
1999
2192
|
schema: { type: "string" }
|
|
2000
2193
|
}
|
|
2001
2194
|
],
|
|
@@ -2006,32 +2199,38 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2006
2199
|
schema: {
|
|
2007
2200
|
type: "object",
|
|
2008
2201
|
properties: {
|
|
2009
|
-
|
|
2010
|
-
|
|
2202
|
+
step: {
|
|
2203
|
+
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
2204
|
+
},
|
|
2205
|
+
resumeData: { type: "object" },
|
|
2206
|
+
requestContext: {
|
|
2011
2207
|
type: "object",
|
|
2012
|
-
description: "
|
|
2208
|
+
description: "Request Context for the agent builder action execution"
|
|
2209
|
+
},
|
|
2210
|
+
tracingOptions: {
|
|
2211
|
+
type: "object",
|
|
2212
|
+
description: "Tracing options for the action execution",
|
|
2213
|
+
properties: {
|
|
2214
|
+
metadata: {
|
|
2215
|
+
type: "object",
|
|
2216
|
+
description: "Custom metadata to attach to the trace",
|
|
2217
|
+
additionalProperties: true
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2013
2220
|
}
|
|
2014
|
-
}
|
|
2221
|
+
},
|
|
2222
|
+
required: ["step"]
|
|
2015
2223
|
}
|
|
2016
2224
|
}
|
|
2017
2225
|
}
|
|
2018
|
-
}
|
|
2019
|
-
responses: {
|
|
2020
|
-
200: {
|
|
2021
|
-
description: "agent builder action run started"
|
|
2022
|
-
},
|
|
2023
|
-
404: {
|
|
2024
|
-
description: "agent builder action not found"
|
|
2025
|
-
}
|
|
2026
|
-
},
|
|
2027
|
-
tags: ["agent-builder"]
|
|
2226
|
+
}
|
|
2028
2227
|
}),
|
|
2029
|
-
|
|
2228
|
+
resumeStreamAgentBuilderActionHandler
|
|
2030
2229
|
);
|
|
2031
2230
|
router.post(
|
|
2032
|
-
"/:actionId/
|
|
2231
|
+
"/:actionId/stream-legacy",
|
|
2033
2232
|
w({
|
|
2034
|
-
description: "Stream agent builder action in real-time
|
|
2233
|
+
description: "Stream legacy agent builder action in real-time",
|
|
2035
2234
|
parameters: [
|
|
2036
2235
|
{
|
|
2037
2236
|
name: "actionId",
|
|
@@ -2054,9 +2253,20 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2054
2253
|
type: "object",
|
|
2055
2254
|
properties: {
|
|
2056
2255
|
inputData: { type: "object" },
|
|
2057
|
-
|
|
2256
|
+
requestContext: {
|
|
2257
|
+
type: "object",
|
|
2258
|
+
description: "Request Context for the agent builder action execution"
|
|
2259
|
+
},
|
|
2260
|
+
tracingOptions: {
|
|
2058
2261
|
type: "object",
|
|
2059
|
-
description: "
|
|
2262
|
+
description: "Tracing options for the action execution",
|
|
2263
|
+
properties: {
|
|
2264
|
+
metadata: {
|
|
2265
|
+
type: "object",
|
|
2266
|
+
description: "Custom metadata to attach to the trace",
|
|
2267
|
+
additionalProperties: true
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2060
2270
|
}
|
|
2061
2271
|
}
|
|
2062
2272
|
}
|
|
@@ -2073,14 +2283,12 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2073
2283
|
},
|
|
2074
2284
|
tags: ["agent-builder"]
|
|
2075
2285
|
}),
|
|
2076
|
-
|
|
2286
|
+
streamLegacyAgentBuilderActionHandler
|
|
2077
2287
|
);
|
|
2078
2288
|
router.post(
|
|
2079
|
-
"/:actionId/
|
|
2080
|
-
bodyLimit(bodyLimitOptions),
|
|
2289
|
+
"/:actionId/observe-stream-legacy",
|
|
2081
2290
|
w({
|
|
2082
|
-
description: "
|
|
2083
|
-
tags: ["agent-builder"],
|
|
2291
|
+
description: "Observe agent builder action stream in real-time",
|
|
2084
2292
|
parameters: [
|
|
2085
2293
|
{
|
|
2086
2294
|
name: "actionId",
|
|
@@ -2091,24 +2299,26 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2091
2299
|
{
|
|
2092
2300
|
name: "runId",
|
|
2093
2301
|
in: "query",
|
|
2094
|
-
required:
|
|
2302
|
+
required: true,
|
|
2095
2303
|
schema: { type: "string" }
|
|
2096
2304
|
}
|
|
2097
2305
|
],
|
|
2098
2306
|
responses: {
|
|
2099
2307
|
200: {
|
|
2100
|
-
description: "
|
|
2308
|
+
description: "agent builder action stream observed"
|
|
2309
|
+
},
|
|
2310
|
+
404: {
|
|
2311
|
+
description: "agent builder action not found"
|
|
2101
2312
|
}
|
|
2102
|
-
}
|
|
2313
|
+
},
|
|
2314
|
+
tags: ["agent-builder"]
|
|
2103
2315
|
}),
|
|
2104
|
-
|
|
2316
|
+
observeStreamLegacyAgentBuilderActionHandler
|
|
2105
2317
|
);
|
|
2106
2318
|
router.post(
|
|
2107
|
-
"/:actionId/
|
|
2108
|
-
bodyLimit(bodyLimitOptions),
|
|
2319
|
+
"/:actionId/stream",
|
|
2109
2320
|
w({
|
|
2110
|
-
description: "
|
|
2111
|
-
tags: ["agent-builder"],
|
|
2321
|
+
description: "Stream agent builder action in real-time",
|
|
2112
2322
|
parameters: [
|
|
2113
2323
|
{
|
|
2114
2324
|
name: "actionId",
|
|
@@ -2131,9 +2341,20 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2131
2341
|
type: "object",
|
|
2132
2342
|
properties: {
|
|
2133
2343
|
inputData: { type: "object" },
|
|
2134
|
-
|
|
2344
|
+
requestContext: {
|
|
2345
|
+
type: "object",
|
|
2346
|
+
description: "Request Context for the agent builder action execution"
|
|
2347
|
+
},
|
|
2348
|
+
tracingOptions: {
|
|
2135
2349
|
type: "object",
|
|
2136
|
-
description: "
|
|
2350
|
+
description: "Tracing options for the action execution",
|
|
2351
|
+
properties: {
|
|
2352
|
+
metadata: {
|
|
2353
|
+
type: "object",
|
|
2354
|
+
description: "Custom metadata to attach to the trace",
|
|
2355
|
+
additionalProperties: true
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2137
2358
|
}
|
|
2138
2359
|
}
|
|
2139
2360
|
}
|
|
@@ -2142,20 +2363,50 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2142
2363
|
},
|
|
2143
2364
|
responses: {
|
|
2144
2365
|
200: {
|
|
2145
|
-
description: "agent builder action
|
|
2366
|
+
description: "agent builder action run started"
|
|
2146
2367
|
},
|
|
2147
2368
|
404: {
|
|
2148
2369
|
description: "agent builder action not found"
|
|
2149
2370
|
}
|
|
2150
|
-
}
|
|
2371
|
+
},
|
|
2372
|
+
tags: ["agent-builder"]
|
|
2151
2373
|
}),
|
|
2152
|
-
|
|
2374
|
+
streamAgentBuilderActionHandler
|
|
2153
2375
|
);
|
|
2154
2376
|
router.post(
|
|
2155
|
-
"/:actionId/
|
|
2377
|
+
"/:actionId/observe",
|
|
2156
2378
|
w({
|
|
2157
|
-
description: "
|
|
2158
|
-
|
|
2379
|
+
description: "Observe agent builder action stream in real-time using the streaming API",
|
|
2380
|
+
parameters: [
|
|
2381
|
+
{
|
|
2382
|
+
name: "actionId",
|
|
2383
|
+
in: "path",
|
|
2384
|
+
required: true,
|
|
2385
|
+
schema: { type: "string" }
|
|
2386
|
+
},
|
|
2387
|
+
{
|
|
2388
|
+
name: "runId",
|
|
2389
|
+
in: "query",
|
|
2390
|
+
required: true,
|
|
2391
|
+
schema: { type: "string" }
|
|
2392
|
+
}
|
|
2393
|
+
],
|
|
2394
|
+
responses: {
|
|
2395
|
+
200: {
|
|
2396
|
+
description: "agent builder action stream observed"
|
|
2397
|
+
},
|
|
2398
|
+
404: {
|
|
2399
|
+
description: "agent builder action not found"
|
|
2400
|
+
}
|
|
2401
|
+
},
|
|
2402
|
+
tags: ["agent-builder"]
|
|
2403
|
+
}),
|
|
2404
|
+
observeStreamAgentBuilderActionHandler
|
|
2405
|
+
);
|
|
2406
|
+
router.post(
|
|
2407
|
+
"/:actionId/observe-streamVNext",
|
|
2408
|
+
w({
|
|
2409
|
+
description: "Observe agent builder action stream in real-time using the VNext streaming API",
|
|
2159
2410
|
parameters: [
|
|
2160
2411
|
{
|
|
2161
2412
|
name: "actionId",
|
|
@@ -2170,6 +2421,36 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2170
2421
|
schema: { type: "string" }
|
|
2171
2422
|
}
|
|
2172
2423
|
],
|
|
2424
|
+
responses: {
|
|
2425
|
+
200: {
|
|
2426
|
+
description: "agent builder action stream vNext observed"
|
|
2427
|
+
},
|
|
2428
|
+
404: {
|
|
2429
|
+
description: "agent builder action not found"
|
|
2430
|
+
}
|
|
2431
|
+
},
|
|
2432
|
+
tags: ["agent-builder"]
|
|
2433
|
+
}),
|
|
2434
|
+
observeStreamVNextAgentBuilderActionHandler
|
|
2435
|
+
);
|
|
2436
|
+
router.post(
|
|
2437
|
+
"/:actionId/streamVNext",
|
|
2438
|
+
w({
|
|
2439
|
+
description: "Stream agent builder action in real-time using the VNext streaming API",
|
|
2440
|
+
parameters: [
|
|
2441
|
+
{
|
|
2442
|
+
name: "actionId",
|
|
2443
|
+
in: "path",
|
|
2444
|
+
required: true,
|
|
2445
|
+
schema: { type: "string" }
|
|
2446
|
+
},
|
|
2447
|
+
{
|
|
2448
|
+
name: "runId",
|
|
2449
|
+
in: "query",
|
|
2450
|
+
required: false,
|
|
2451
|
+
schema: { type: "string" }
|
|
2452
|
+
}
|
|
2453
|
+
],
|
|
2173
2454
|
requestBody: {
|
|
2174
2455
|
required: true,
|
|
2175
2456
|
content: {
|
|
@@ -2178,9 +2459,24 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2178
2459
|
type: "object",
|
|
2179
2460
|
properties: {
|
|
2180
2461
|
inputData: { type: "object" },
|
|
2181
|
-
|
|
2462
|
+
requestContext: {
|
|
2463
|
+
type: "object",
|
|
2464
|
+
description: "Request Context for the agent builder action execution"
|
|
2465
|
+
},
|
|
2466
|
+
closeOnSuspend: {
|
|
2467
|
+
type: "boolean",
|
|
2468
|
+
description: "Close the stream on suspend"
|
|
2469
|
+
},
|
|
2470
|
+
tracingOptions: {
|
|
2182
2471
|
type: "object",
|
|
2183
|
-
description: "
|
|
2472
|
+
description: "Tracing options for the action execution",
|
|
2473
|
+
properties: {
|
|
2474
|
+
metadata: {
|
|
2475
|
+
type: "object",
|
|
2476
|
+
description: "Custom metadata to attach to the trace",
|
|
2477
|
+
additionalProperties: true
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2184
2480
|
}
|
|
2185
2481
|
}
|
|
2186
2482
|
}
|
|
@@ -2194,14 +2490,17 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2194
2490
|
404: {
|
|
2195
2491
|
description: "agent builder action not found"
|
|
2196
2492
|
}
|
|
2197
|
-
}
|
|
2493
|
+
},
|
|
2494
|
+
tags: ["agent-builder"]
|
|
2198
2495
|
}),
|
|
2199
|
-
|
|
2496
|
+
streamVNextAgentBuilderActionHandler
|
|
2200
2497
|
);
|
|
2201
|
-
router.
|
|
2202
|
-
"/:actionId/
|
|
2498
|
+
router.post(
|
|
2499
|
+
"/:actionId/create-run",
|
|
2500
|
+
bodyLimit(bodyLimitOptions),
|
|
2203
2501
|
w({
|
|
2204
|
-
description: "
|
|
2502
|
+
description: "Create a new agent builder action run",
|
|
2503
|
+
tags: ["agent-builder"],
|
|
2205
2504
|
parameters: [
|
|
2206
2505
|
{
|
|
2207
2506
|
name: "actionId",
|
|
@@ -2214,27 +2513,22 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2214
2513
|
in: "query",
|
|
2215
2514
|
required: false,
|
|
2216
2515
|
schema: { type: "string" }
|
|
2217
|
-
},
|
|
2218
|
-
{
|
|
2219
|
-
name: "eventType",
|
|
2220
|
-
in: "query",
|
|
2221
|
-
required: false,
|
|
2222
|
-
schema: { type: "string", enum: ["watch", "watch-v2"] }
|
|
2223
2516
|
}
|
|
2224
2517
|
],
|
|
2225
|
-
tags: ["agent-builder"],
|
|
2226
2518
|
responses: {
|
|
2227
2519
|
200: {
|
|
2228
|
-
description: "agent builder action
|
|
2520
|
+
description: "New agent builder action run created"
|
|
2229
2521
|
}
|
|
2230
2522
|
}
|
|
2231
2523
|
}),
|
|
2232
|
-
|
|
2524
|
+
createAgentBuilderActionRunHandler
|
|
2233
2525
|
);
|
|
2234
2526
|
router.post(
|
|
2235
|
-
"/:actionId/
|
|
2527
|
+
"/:actionId/start-async",
|
|
2528
|
+
bodyLimit(bodyLimitOptions),
|
|
2236
2529
|
w({
|
|
2237
|
-
description: "
|
|
2530
|
+
description: "Execute/Start an agent builder action",
|
|
2531
|
+
tags: ["agent-builder"],
|
|
2238
2532
|
parameters: [
|
|
2239
2533
|
{
|
|
2240
2534
|
name: "actionId",
|
|
@@ -2244,24 +2538,55 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2244
2538
|
},
|
|
2245
2539
|
{
|
|
2246
2540
|
name: "runId",
|
|
2247
|
-
in: "
|
|
2248
|
-
required:
|
|
2541
|
+
in: "query",
|
|
2542
|
+
required: false,
|
|
2249
2543
|
schema: { type: "string" }
|
|
2250
2544
|
}
|
|
2251
2545
|
],
|
|
2252
|
-
|
|
2546
|
+
requestBody: {
|
|
2547
|
+
required: true,
|
|
2548
|
+
content: {
|
|
2549
|
+
"application/json": {
|
|
2550
|
+
schema: {
|
|
2551
|
+
type: "object",
|
|
2552
|
+
properties: {
|
|
2553
|
+
inputData: { type: "object" },
|
|
2554
|
+
requestContext: {
|
|
2555
|
+
type: "object",
|
|
2556
|
+
description: "Request Context for the agent builder action execution"
|
|
2557
|
+
},
|
|
2558
|
+
tracingOptions: {
|
|
2559
|
+
type: "object",
|
|
2560
|
+
description: "Tracing options for the action execution",
|
|
2561
|
+
properties: {
|
|
2562
|
+
metadata: {
|
|
2563
|
+
type: "object",
|
|
2564
|
+
description: "Custom metadata to attach to the trace",
|
|
2565
|
+
additionalProperties: true
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
},
|
|
2253
2574
|
responses: {
|
|
2254
2575
|
200: {
|
|
2255
|
-
description: "agent builder action
|
|
2576
|
+
description: "agent builder action execution result"
|
|
2577
|
+
},
|
|
2578
|
+
404: {
|
|
2579
|
+
description: "agent builder action not found"
|
|
2256
2580
|
}
|
|
2257
2581
|
}
|
|
2258
2582
|
}),
|
|
2259
|
-
|
|
2583
|
+
startAsyncAgentBuilderActionHandler
|
|
2260
2584
|
);
|
|
2261
2585
|
router.post(
|
|
2262
|
-
"/:actionId/
|
|
2586
|
+
"/:actionId/start",
|
|
2263
2587
|
w({
|
|
2264
|
-
description: "
|
|
2588
|
+
description: "Create and start a new agent builder action run",
|
|
2589
|
+
tags: ["agent-builder"],
|
|
2265
2590
|
parameters: [
|
|
2266
2591
|
{
|
|
2267
2592
|
name: "actionId",
|
|
@@ -2271,7 +2596,7 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2271
2596
|
},
|
|
2272
2597
|
{
|
|
2273
2598
|
name: "runId",
|
|
2274
|
-
in: "
|
|
2599
|
+
in: "query",
|
|
2275
2600
|
required: true,
|
|
2276
2601
|
schema: { type: "string" }
|
|
2277
2602
|
}
|
|
@@ -2280,18 +2605,67 @@ function agentBuilderRouter(bodyLimitOptions) {
|
|
|
2280
2605
|
required: true,
|
|
2281
2606
|
content: {
|
|
2282
2607
|
"application/json": {
|
|
2283
|
-
schema: {
|
|
2608
|
+
schema: {
|
|
2609
|
+
type: "object",
|
|
2610
|
+
properties: {
|
|
2611
|
+
inputData: { type: "object" },
|
|
2612
|
+
requestContext: {
|
|
2613
|
+
type: "object",
|
|
2614
|
+
description: "Request Context for the agent builder action execution"
|
|
2615
|
+
},
|
|
2616
|
+
tracingOptions: {
|
|
2617
|
+
type: "object",
|
|
2618
|
+
description: "Tracing options for the action execution",
|
|
2619
|
+
properties: {
|
|
2620
|
+
metadata: {
|
|
2621
|
+
type: "object",
|
|
2622
|
+
description: "Custom metadata to attach to the trace",
|
|
2623
|
+
additionalProperties: true
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2284
2629
|
}
|
|
2285
2630
|
}
|
|
2286
2631
|
},
|
|
2632
|
+
responses: {
|
|
2633
|
+
200: {
|
|
2634
|
+
description: "agent builder action run started"
|
|
2635
|
+
},
|
|
2636
|
+
404: {
|
|
2637
|
+
description: "agent builder action not found"
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
}),
|
|
2641
|
+
startAgentBuilderActionRunHandler
|
|
2642
|
+
);
|
|
2643
|
+
router.post(
|
|
2644
|
+
"/:actionId/runs/:runId/cancel",
|
|
2645
|
+
w({
|
|
2646
|
+
description: "Cancel an agent builder action run",
|
|
2647
|
+
parameters: [
|
|
2648
|
+
{
|
|
2649
|
+
name: "actionId",
|
|
2650
|
+
in: "path",
|
|
2651
|
+
required: true,
|
|
2652
|
+
schema: { type: "string" }
|
|
2653
|
+
},
|
|
2654
|
+
{
|
|
2655
|
+
name: "runId",
|
|
2656
|
+
in: "path",
|
|
2657
|
+
required: true,
|
|
2658
|
+
schema: { type: "string" }
|
|
2659
|
+
}
|
|
2660
|
+
],
|
|
2287
2661
|
tags: ["agent-builder"],
|
|
2288
2662
|
responses: {
|
|
2289
2663
|
200: {
|
|
2290
|
-
description: "agent builder action run
|
|
2664
|
+
description: "agent builder action run cancelled"
|
|
2291
2665
|
}
|
|
2292
2666
|
}
|
|
2293
2667
|
}),
|
|
2294
|
-
|
|
2668
|
+
cancelAgentBuilderActionRunHandler
|
|
2295
2669
|
);
|
|
2296
2670
|
return router;
|
|
2297
2671
|
}
|
|
@@ -2311,26 +2685,6 @@ async function generateSystemPromptHandler(c2) {
|
|
|
2311
2685
|
if (!agent) {
|
|
2312
2686
|
return c2.json({ error: "Agent not found" }, 404);
|
|
2313
2687
|
}
|
|
2314
|
-
let evalSummary = "";
|
|
2315
|
-
try {
|
|
2316
|
-
const testEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
2317
|
-
const liveEvals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
2318
|
-
const evalsMapped = [...testEvals, ...liveEvals].filter(
|
|
2319
|
-
({ instructions: evalInstructions }) => evalInstructions === instructions
|
|
2320
|
-
);
|
|
2321
|
-
evalSummary = evalsMapped.map(
|
|
2322
|
-
({ input, output, result: result2 }) => `
|
|
2323
|
-
Input: ${input}
|
|
2324
|
-
|
|
2325
|
-
Output: ${output}
|
|
2326
|
-
|
|
2327
|
-
Result: ${JSON.stringify(result2)}
|
|
2328
|
-
|
|
2329
|
-
`
|
|
2330
|
-
).join("");
|
|
2331
|
-
} catch (error) {
|
|
2332
|
-
mastra.getLogger().error(`Error fetching evals`, { error });
|
|
2333
|
-
}
|
|
2334
2688
|
const ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS = `
|
|
2335
2689
|
You are an expert system prompt engineer, specialized in analyzing and enhancing instructions to create clear, effective, and comprehensive system prompts. Your goal is to help users transform their basic instructions into well-structured system prompts that will guide AI behavior effectively.
|
|
2336
2690
|
Follow these steps to analyze and enhance the instructions:
|
|
@@ -2379,24 +2733,24 @@ async function generateSystemPromptHandler(c2) {
|
|
|
2379
2733
|
Focus on creating prompts that are clear, actionable, and aligned with the intended use case.
|
|
2380
2734
|
`;
|
|
2381
2735
|
const systemPromptAgent = new Agent({
|
|
2736
|
+
id: "system-prompt-enhancer",
|
|
2382
2737
|
name: "system-prompt-enhancer",
|
|
2383
2738
|
instructions: ENHANCE_SYSTEM_PROMPT_INSTRUCTIONS,
|
|
2384
|
-
model: agent.
|
|
2739
|
+
model: await agent.getModel()
|
|
2385
2740
|
});
|
|
2386
2741
|
const result = await systemPromptAgent.generate(
|
|
2387
2742
|
`
|
|
2388
2743
|
We need to improve the system prompt.
|
|
2389
2744
|
Current: ${instructions}
|
|
2390
2745
|
${comment ? `User feedback: ${comment}` : ""}
|
|
2391
|
-
${evalSummary ? `
|
|
2392
|
-
Evaluation Results:
|
|
2393
|
-
${evalSummary}` : ""}
|
|
2394
2746
|
`,
|
|
2395
2747
|
{
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2748
|
+
structuredOutput: {
|
|
2749
|
+
schema: z.object({
|
|
2750
|
+
new_prompt: z.string(),
|
|
2751
|
+
explanation: z.string()
|
|
2752
|
+
})
|
|
2753
|
+
}
|
|
2400
2754
|
}
|
|
2401
2755
|
);
|
|
2402
2756
|
return c2.json(result?.object || {});
|
|
@@ -2404,10 +2758,10 @@ ${evalSummary}` : ""}
|
|
|
2404
2758
|
return handleError(error, "Error generating system prompt");
|
|
2405
2759
|
}
|
|
2406
2760
|
}
|
|
2407
|
-
async function
|
|
2761
|
+
async function listToolsHandler(c2) {
|
|
2408
2762
|
try {
|
|
2409
2763
|
const tools = c2.get("tools");
|
|
2410
|
-
const result = await
|
|
2764
|
+
const result = await listToolsHandler$1({
|
|
2411
2765
|
tools
|
|
2412
2766
|
});
|
|
2413
2767
|
return c2.json(result || {});
|
|
@@ -2432,7 +2786,7 @@ function executeToolHandler(tools) {
|
|
|
2432
2786
|
return async (c2) => {
|
|
2433
2787
|
try {
|
|
2434
2788
|
const mastra = c2.get("mastra");
|
|
2435
|
-
const
|
|
2789
|
+
const requestContext = c2.get("requestContext");
|
|
2436
2790
|
const toolId = decodeURIComponent(c2.req.param("toolId"));
|
|
2437
2791
|
const runId = c2.req.query("runId");
|
|
2438
2792
|
const { data } = await c2.req.json();
|
|
@@ -2440,7 +2794,7 @@ function executeToolHandler(tools) {
|
|
|
2440
2794
|
mastra,
|
|
2441
2795
|
toolId,
|
|
2442
2796
|
data,
|
|
2443
|
-
|
|
2797
|
+
requestContext,
|
|
2444
2798
|
runId
|
|
2445
2799
|
});
|
|
2446
2800
|
return c2.json(result);
|
|
@@ -2452,14 +2806,14 @@ function executeToolHandler(tools) {
|
|
|
2452
2806
|
async function getAgentToolHandler(c2) {
|
|
2453
2807
|
try {
|
|
2454
2808
|
const mastra = c2.get("mastra");
|
|
2455
|
-
const
|
|
2809
|
+
const requestContext = c2.get("requestContext");
|
|
2456
2810
|
const agentId = c2.req.param("agentId");
|
|
2457
2811
|
const toolId = c2.req.param("toolId");
|
|
2458
2812
|
const result = await getAgentToolHandler$1({
|
|
2459
2813
|
mastra,
|
|
2460
2814
|
agentId,
|
|
2461
2815
|
toolId,
|
|
2462
|
-
|
|
2816
|
+
requestContext
|
|
2463
2817
|
});
|
|
2464
2818
|
return c2.json(result);
|
|
2465
2819
|
} catch (error) {
|
|
@@ -2469,7 +2823,7 @@ async function getAgentToolHandler(c2) {
|
|
|
2469
2823
|
async function executeAgentToolHandler(c2) {
|
|
2470
2824
|
try {
|
|
2471
2825
|
const mastra = c2.get("mastra");
|
|
2472
|
-
const
|
|
2826
|
+
const requestContext = c2.get("requestContext");
|
|
2473
2827
|
const agentId = c2.req.param("agentId");
|
|
2474
2828
|
const toolId = c2.req.param("toolId");
|
|
2475
2829
|
const { data } = await c2.req.json();
|
|
@@ -2478,7 +2832,7 @@ async function executeAgentToolHandler(c2) {
|
|
|
2478
2832
|
agentId,
|
|
2479
2833
|
toolId,
|
|
2480
2834
|
data,
|
|
2481
|
-
|
|
2835
|
+
requestContext
|
|
2482
2836
|
});
|
|
2483
2837
|
return c2.json(result);
|
|
2484
2838
|
} catch (error) {
|
|
@@ -2549,10 +2903,10 @@ var vNextBodyOptions = {
|
|
|
2549
2903
|
},
|
|
2550
2904
|
...sharedBodyOptions
|
|
2551
2905
|
};
|
|
2552
|
-
async function
|
|
2553
|
-
const serializedAgents = await
|
|
2906
|
+
async function listAgentsHandler(c2) {
|
|
2907
|
+
const serializedAgents = await listAgentsHandler$1({
|
|
2554
2908
|
mastra: c2.get("mastra"),
|
|
2555
|
-
|
|
2909
|
+
requestContext: c2.get("requestContext")
|
|
2556
2910
|
});
|
|
2557
2911
|
return c2.json(serializedAgents);
|
|
2558
2912
|
}
|
|
@@ -2580,48 +2934,26 @@ async function getProvidersHandler(c2) {
|
|
|
2580
2934
|
async function getAgentByIdHandler(c2) {
|
|
2581
2935
|
const mastra = c2.get("mastra");
|
|
2582
2936
|
const agentId = c2.req.param("agentId");
|
|
2583
|
-
const
|
|
2937
|
+
const requestContext = c2.get("requestContext");
|
|
2584
2938
|
const isPlayground = c2.req.header("x-mastra-dev-playground") === "true";
|
|
2585
2939
|
const result = await getAgentByIdHandler$1({
|
|
2586
2940
|
mastra,
|
|
2587
2941
|
agentId,
|
|
2588
|
-
|
|
2942
|
+
requestContext,
|
|
2589
2943
|
isPlayground
|
|
2590
2944
|
});
|
|
2591
2945
|
return c2.json(result);
|
|
2592
2946
|
}
|
|
2593
|
-
async function getEvalsByAgentIdHandler(c2) {
|
|
2594
|
-
const mastra = c2.get("mastra");
|
|
2595
|
-
const agentId = c2.req.param("agentId");
|
|
2596
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
2597
|
-
const result = await getEvalsByAgentIdHandler$1({
|
|
2598
|
-
mastra,
|
|
2599
|
-
agentId,
|
|
2600
|
-
runtimeContext
|
|
2601
|
-
});
|
|
2602
|
-
return c2.json(result);
|
|
2603
|
-
}
|
|
2604
|
-
async function getLiveEvalsByAgentIdHandler(c2) {
|
|
2605
|
-
const mastra = c2.get("mastra");
|
|
2606
|
-
const agentId = c2.req.param("agentId");
|
|
2607
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
2608
|
-
const result = await getLiveEvalsByAgentIdHandler$1({
|
|
2609
|
-
mastra,
|
|
2610
|
-
agentId,
|
|
2611
|
-
runtimeContext
|
|
2612
|
-
});
|
|
2613
|
-
return c2.json(result);
|
|
2614
|
-
}
|
|
2615
2947
|
async function generateLegacyHandler(c2) {
|
|
2616
2948
|
try {
|
|
2617
2949
|
const mastra = c2.get("mastra");
|
|
2618
2950
|
const agentId = c2.req.param("agentId");
|
|
2619
|
-
const
|
|
2951
|
+
const requestContext = c2.get("requestContext");
|
|
2620
2952
|
const body = await c2.req.json();
|
|
2621
2953
|
const result = await generateLegacyHandler$1({
|
|
2622
2954
|
mastra,
|
|
2623
2955
|
agentId,
|
|
2624
|
-
|
|
2956
|
+
requestContext,
|
|
2625
2957
|
body,
|
|
2626
2958
|
abortSignal: c2.req.raw.signal
|
|
2627
2959
|
});
|
|
@@ -2634,12 +2966,12 @@ async function generateHandler(c2) {
|
|
|
2634
2966
|
try {
|
|
2635
2967
|
const mastra = c2.get("mastra");
|
|
2636
2968
|
const agentId = c2.req.param("agentId");
|
|
2637
|
-
const
|
|
2969
|
+
const requestContext = c2.get("requestContext");
|
|
2638
2970
|
const body = await c2.req.json();
|
|
2639
2971
|
const result = await generateHandler$1({
|
|
2640
2972
|
mastra,
|
|
2641
2973
|
agentId,
|
|
2642
|
-
|
|
2974
|
+
requestContext,
|
|
2643
2975
|
body,
|
|
2644
2976
|
abortSignal: c2.req.raw.signal
|
|
2645
2977
|
});
|
|
@@ -2652,12 +2984,12 @@ async function streamGenerateLegacyHandler(c2) {
|
|
|
2652
2984
|
try {
|
|
2653
2985
|
const mastra = c2.get("mastra");
|
|
2654
2986
|
const agentId = c2.req.param("agentId");
|
|
2655
|
-
const
|
|
2987
|
+
const requestContext = c2.get("requestContext");
|
|
2656
2988
|
const body = await c2.req.json();
|
|
2657
2989
|
const streamResponse = await streamGenerateLegacyHandler$1({
|
|
2658
2990
|
mastra,
|
|
2659
2991
|
agentId,
|
|
2660
|
-
|
|
2992
|
+
requestContext,
|
|
2661
2993
|
body,
|
|
2662
2994
|
abortSignal: c2.req.raw.signal
|
|
2663
2995
|
});
|
|
@@ -2669,7 +3001,7 @@ async function streamGenerateLegacyHandler(c2) {
|
|
|
2669
3001
|
async function streamGenerateHandler(c2) {
|
|
2670
3002
|
const mastra = c2.get("mastra");
|
|
2671
3003
|
const agentId = c2.req.param("agentId");
|
|
2672
|
-
const
|
|
3004
|
+
const requestContext = c2.get("requestContext");
|
|
2673
3005
|
const body = await c2.req.json();
|
|
2674
3006
|
const logger2 = mastra.getLogger();
|
|
2675
3007
|
let streamResponse;
|
|
@@ -2677,7 +3009,7 @@ async function streamGenerateHandler(c2) {
|
|
|
2677
3009
|
streamResponse = await streamGenerateHandler$1({
|
|
2678
3010
|
mastra,
|
|
2679
3011
|
agentId,
|
|
2680
|
-
|
|
3012
|
+
requestContext,
|
|
2681
3013
|
body,
|
|
2682
3014
|
abortSignal: c2.req.raw.signal
|
|
2683
3015
|
});
|
|
@@ -2687,19 +3019,19 @@ async function streamGenerateHandler(c2) {
|
|
|
2687
3019
|
c2.header("Transfer-Encoding", "chunked");
|
|
2688
3020
|
return stream(
|
|
2689
3021
|
c2,
|
|
2690
|
-
async (
|
|
3022
|
+
async (stream5) => {
|
|
2691
3023
|
try {
|
|
2692
3024
|
const reader = streamResponse.fullStream.getReader();
|
|
2693
|
-
|
|
3025
|
+
stream5.onAbort(() => {
|
|
2694
3026
|
void reader.cancel("request aborted");
|
|
2695
3027
|
});
|
|
2696
3028
|
let chunkResult;
|
|
2697
3029
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2698
|
-
await
|
|
3030
|
+
await stream5.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2699
3031
|
|
|
2700
3032
|
`);
|
|
2701
3033
|
}
|
|
2702
|
-
await
|
|
3034
|
+
await stream5.write("data: [DONE]\n\n");
|
|
2703
3035
|
} catch (err) {
|
|
2704
3036
|
logger2.error("Error in stream generate: " + (err?.message ?? "Unknown error"));
|
|
2705
3037
|
const errorChunk = {
|
|
@@ -2710,11 +3042,11 @@ async function streamGenerateHandler(c2) {
|
|
|
2710
3042
|
error: getErrorFromUnknown(err, { fallbackMessage: "Unknown error in stream generate" })
|
|
2711
3043
|
}
|
|
2712
3044
|
};
|
|
2713
|
-
await
|
|
3045
|
+
await stream5.write(`data: ${JSON.stringify(errorChunk)}
|
|
2714
3046
|
|
|
2715
3047
|
`);
|
|
2716
3048
|
}
|
|
2717
|
-
await
|
|
3049
|
+
await stream5.close();
|
|
2718
3050
|
},
|
|
2719
3051
|
async (err) => {
|
|
2720
3052
|
logger2.error("Error in watch stream: " + err?.message);
|
|
@@ -2724,14 +3056,14 @@ async function streamGenerateHandler(c2) {
|
|
|
2724
3056
|
async function approveToolCallHandler(c2) {
|
|
2725
3057
|
const mastra = c2.get("mastra");
|
|
2726
3058
|
const agentId = c2.req.param("agentId");
|
|
2727
|
-
const
|
|
3059
|
+
const requestContext = c2.get("requestContext");
|
|
2728
3060
|
const body = await c2.req.json();
|
|
2729
3061
|
const logger2 = mastra.getLogger();
|
|
2730
3062
|
let streamResponse;
|
|
2731
3063
|
try {
|
|
2732
3064
|
streamResponse = await approveToolCallHandler$1({
|
|
2733
3065
|
mastra,
|
|
2734
|
-
|
|
3066
|
+
requestContext,
|
|
2735
3067
|
agentId,
|
|
2736
3068
|
body,
|
|
2737
3069
|
abortSignal: c2.req.raw.signal
|
|
@@ -2742,19 +3074,19 @@ async function approveToolCallHandler(c2) {
|
|
|
2742
3074
|
c2.header("Transfer-Encoding", "chunked");
|
|
2743
3075
|
return stream(
|
|
2744
3076
|
c2,
|
|
2745
|
-
async (
|
|
3077
|
+
async (stream5) => {
|
|
2746
3078
|
try {
|
|
2747
3079
|
const reader = streamResponse.fullStream.getReader();
|
|
2748
|
-
|
|
3080
|
+
stream5.onAbort(() => {
|
|
2749
3081
|
void reader.cancel("request aborted");
|
|
2750
3082
|
});
|
|
2751
3083
|
let chunkResult;
|
|
2752
3084
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2753
|
-
await
|
|
3085
|
+
await stream5.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2754
3086
|
|
|
2755
3087
|
`);
|
|
2756
3088
|
}
|
|
2757
|
-
await
|
|
3089
|
+
await stream5.write("data: [DONE]\n\n");
|
|
2758
3090
|
} catch (err) {
|
|
2759
3091
|
logger2.error("Error in approve tool call: " + (err?.message ?? "Unknown error"));
|
|
2760
3092
|
const errorChunk = {
|
|
@@ -2769,11 +3101,11 @@ async function approveToolCallHandler(c2) {
|
|
|
2769
3101
|
} : String(err)
|
|
2770
3102
|
}
|
|
2771
3103
|
};
|
|
2772
|
-
await
|
|
3104
|
+
await stream5.write(`data: ${JSON.stringify(errorChunk)}
|
|
2773
3105
|
|
|
2774
3106
|
`);
|
|
2775
3107
|
}
|
|
2776
|
-
await
|
|
3108
|
+
await stream5.close();
|
|
2777
3109
|
},
|
|
2778
3110
|
async (err) => {
|
|
2779
3111
|
logger2.error("Error in watch stream: " + err?.message);
|
|
@@ -2783,14 +3115,14 @@ async function approveToolCallHandler(c2) {
|
|
|
2783
3115
|
async function declineToolCallHandler(c2) {
|
|
2784
3116
|
const mastra = c2.get("mastra");
|
|
2785
3117
|
const agentId = c2.req.param("agentId");
|
|
2786
|
-
const
|
|
3118
|
+
const requestContext = c2.get("requestContext");
|
|
2787
3119
|
const body = await c2.req.json();
|
|
2788
3120
|
const logger2 = mastra.getLogger();
|
|
2789
3121
|
let streamResponse;
|
|
2790
3122
|
try {
|
|
2791
3123
|
streamResponse = await declineToolCallHandler$1({
|
|
2792
3124
|
mastra,
|
|
2793
|
-
|
|
3125
|
+
requestContext,
|
|
2794
3126
|
agentId,
|
|
2795
3127
|
body,
|
|
2796
3128
|
abortSignal: c2.req.raw.signal
|
|
@@ -2801,19 +3133,19 @@ async function declineToolCallHandler(c2) {
|
|
|
2801
3133
|
c2.header("Transfer-Encoding", "chunked");
|
|
2802
3134
|
return stream(
|
|
2803
3135
|
c2,
|
|
2804
|
-
async (
|
|
3136
|
+
async (stream5) => {
|
|
2805
3137
|
try {
|
|
2806
3138
|
const reader = streamResponse.fullStream.getReader();
|
|
2807
|
-
|
|
3139
|
+
stream5.onAbort(() => {
|
|
2808
3140
|
void reader.cancel("request aborted");
|
|
2809
3141
|
});
|
|
2810
3142
|
let chunkResult;
|
|
2811
3143
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2812
|
-
await
|
|
3144
|
+
await stream5.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2813
3145
|
|
|
2814
3146
|
`);
|
|
2815
3147
|
}
|
|
2816
|
-
await
|
|
3148
|
+
await stream5.write("data: [DONE]\n\n");
|
|
2817
3149
|
} catch (err) {
|
|
2818
3150
|
logger2.error("Error in decline tool call: " + (err?.message ?? "Unknown error"));
|
|
2819
3151
|
const errorChunk = {
|
|
@@ -2828,11 +3160,11 @@ async function declineToolCallHandler(c2) {
|
|
|
2828
3160
|
} : String(err)
|
|
2829
3161
|
}
|
|
2830
3162
|
};
|
|
2831
|
-
await
|
|
3163
|
+
await stream5.write(`data: ${JSON.stringify(errorChunk)}
|
|
2832
3164
|
|
|
2833
3165
|
`);
|
|
2834
3166
|
}
|
|
2835
|
-
await
|
|
3167
|
+
await stream5.close();
|
|
2836
3168
|
},
|
|
2837
3169
|
async (err) => {
|
|
2838
3170
|
logger2.error("Error in watch stream: " + err?.message);
|
|
@@ -2842,11 +3174,11 @@ async function declineToolCallHandler(c2) {
|
|
|
2842
3174
|
async function streamNetworkHandler(c2) {
|
|
2843
3175
|
const mastra = c2.get("mastra");
|
|
2844
3176
|
const agentId = c2.req.param("agentId");
|
|
2845
|
-
const
|
|
3177
|
+
const requestContext = c2.get("requestContext");
|
|
2846
3178
|
const body = await c2.req.json();
|
|
2847
3179
|
const logger2 = mastra.getLogger();
|
|
2848
3180
|
const agent = await getAgentFromSystem({ mastra, agentId });
|
|
2849
|
-
const memory = await agent.getMemory({
|
|
3181
|
+
const memory = await agent.getMemory({ requestContext });
|
|
2850
3182
|
if (!memory) {
|
|
2851
3183
|
return handleError(
|
|
2852
3184
|
new MastraError({
|
|
@@ -2866,7 +3198,7 @@ async function streamNetworkHandler(c2) {
|
|
|
2866
3198
|
streamResponse = await streamNetworkHandler$1({
|
|
2867
3199
|
mastra,
|
|
2868
3200
|
agentId,
|
|
2869
|
-
|
|
3201
|
+
requestContext,
|
|
2870
3202
|
body
|
|
2871
3203
|
// abortSignal: c.req.raw.signal,
|
|
2872
3204
|
});
|
|
@@ -2876,19 +3208,19 @@ async function streamNetworkHandler(c2) {
|
|
|
2876
3208
|
c2.header("Transfer-Encoding", "chunked");
|
|
2877
3209
|
return stream(
|
|
2878
3210
|
c2,
|
|
2879
|
-
async (
|
|
3211
|
+
async (stream5) => {
|
|
2880
3212
|
try {
|
|
2881
3213
|
const reader = streamResponse.getReader();
|
|
2882
|
-
|
|
3214
|
+
stream5.onAbort(() => {
|
|
2883
3215
|
void reader.cancel("request aborted");
|
|
2884
3216
|
});
|
|
2885
3217
|
let chunkResult;
|
|
2886
3218
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
2887
|
-
await
|
|
3219
|
+
await stream5.write(`data: ${JSON.stringify(chunkResult.value)}
|
|
2888
3220
|
|
|
2889
3221
|
`);
|
|
2890
3222
|
}
|
|
2891
|
-
await
|
|
3223
|
+
await stream5.write("data: [DONE]\n\n");
|
|
2892
3224
|
} catch (err) {
|
|
2893
3225
|
logger2.error("Error in streamNetwork generate: " + (err?.message ?? "Unknown error"));
|
|
2894
3226
|
const errorChunk = {
|
|
@@ -2903,11 +3235,11 @@ async function streamNetworkHandler(c2) {
|
|
|
2903
3235
|
} : String(err)
|
|
2904
3236
|
}
|
|
2905
3237
|
};
|
|
2906
|
-
await
|
|
3238
|
+
await stream5.write(`data: ${JSON.stringify(errorChunk)}
|
|
2907
3239
|
|
|
2908
3240
|
`);
|
|
2909
3241
|
}
|
|
2910
|
-
await
|
|
3242
|
+
await stream5.close();
|
|
2911
3243
|
},
|
|
2912
3244
|
async (err) => {
|
|
2913
3245
|
logger2.error("Error in watch stream: " + err?.message);
|
|
@@ -2918,12 +3250,12 @@ async function streamUIMessageHandler(c2) {
|
|
|
2918
3250
|
try {
|
|
2919
3251
|
const mastra = c2.get("mastra");
|
|
2920
3252
|
const agentId = c2.req.param("agentId");
|
|
2921
|
-
const
|
|
3253
|
+
const requestContext = c2.get("requestContext");
|
|
2922
3254
|
const body = await c2.req.json();
|
|
2923
3255
|
const streamResponse = await streamUIMessageHandler$1({
|
|
2924
3256
|
mastra,
|
|
2925
3257
|
agentId,
|
|
2926
|
-
|
|
3258
|
+
requestContext,
|
|
2927
3259
|
body,
|
|
2928
3260
|
abortSignal: c2.req.raw.signal
|
|
2929
3261
|
});
|
|
@@ -3032,11 +3364,11 @@ async function getSpeakersHandler(c2) {
|
|
|
3032
3364
|
try {
|
|
3033
3365
|
const mastra = c2.get("mastra");
|
|
3034
3366
|
const agentId = c2.req.param("agentId");
|
|
3035
|
-
const
|
|
3367
|
+
const requestContext = c2.get("requestContext");
|
|
3036
3368
|
const speakers = await getSpeakersHandler$1({
|
|
3037
3369
|
mastra,
|
|
3038
3370
|
agentId,
|
|
3039
|
-
|
|
3371
|
+
requestContext
|
|
3040
3372
|
});
|
|
3041
3373
|
return c2.json(speakers);
|
|
3042
3374
|
} catch (error) {
|
|
@@ -3047,12 +3379,12 @@ async function speakHandler(c2) {
|
|
|
3047
3379
|
try {
|
|
3048
3380
|
const mastra = c2.get("mastra");
|
|
3049
3381
|
const agentId = c2.req.param("agentId");
|
|
3050
|
-
const
|
|
3382
|
+
const requestContext = c2.get("requestContext");
|
|
3051
3383
|
const { input, options } = await c2.req.json();
|
|
3052
3384
|
const audioStream = await generateSpeechHandler({
|
|
3053
3385
|
mastra,
|
|
3054
3386
|
agentId,
|
|
3055
|
-
|
|
3387
|
+
requestContext,
|
|
3056
3388
|
body: { text: input, speakerId: options?.speakerId }
|
|
3057
3389
|
});
|
|
3058
3390
|
c2.header("Content-Type", `audio/${options?.filetype ?? "mp3"}`);
|
|
@@ -3066,11 +3398,11 @@ async function getListenerHandler(c2) {
|
|
|
3066
3398
|
try {
|
|
3067
3399
|
const mastra = c2.get("mastra");
|
|
3068
3400
|
const agentId = c2.req.param("agentId");
|
|
3069
|
-
const
|
|
3401
|
+
const requestContext = c2.get("requestContext");
|
|
3070
3402
|
const listeners = await getListenerHandler$1({
|
|
3071
3403
|
mastra,
|
|
3072
3404
|
agentId,
|
|
3073
|
-
|
|
3405
|
+
requestContext
|
|
3074
3406
|
});
|
|
3075
3407
|
return c2.json(listeners);
|
|
3076
3408
|
} catch (error) {
|
|
@@ -3081,7 +3413,7 @@ async function listenHandler(c2) {
|
|
|
3081
3413
|
try {
|
|
3082
3414
|
const mastra = c2.get("mastra");
|
|
3083
3415
|
const agentId = c2.req.param("agentId");
|
|
3084
|
-
const
|
|
3416
|
+
const requestContext = c2.get("requestContext");
|
|
3085
3417
|
const formData = await c2.req.formData();
|
|
3086
3418
|
const audioFile = formData.get("audio");
|
|
3087
3419
|
const options = formData.get("options");
|
|
@@ -3097,7 +3429,7 @@ async function listenHandler(c2) {
|
|
|
3097
3429
|
const transcription = await transcribeSpeechHandler({
|
|
3098
3430
|
mastra,
|
|
3099
3431
|
agentId,
|
|
3100
|
-
|
|
3432
|
+
requestContext,
|
|
3101
3433
|
body: {
|
|
3102
3434
|
audioData: Buffer.from(audioData),
|
|
3103
3435
|
options: parsedOptions
|
|
@@ -3123,7 +3455,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3123
3455
|
}
|
|
3124
3456
|
}
|
|
3125
3457
|
}),
|
|
3126
|
-
|
|
3458
|
+
listAgentsHandler
|
|
3127
3459
|
);
|
|
3128
3460
|
router.get(
|
|
3129
3461
|
"/providers",
|
|
@@ -3162,48 +3494,6 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3162
3494
|
}),
|
|
3163
3495
|
getAgentByIdHandler
|
|
3164
3496
|
);
|
|
3165
|
-
router.get(
|
|
3166
|
-
"/:agentId/evals/ci",
|
|
3167
|
-
w({
|
|
3168
|
-
description: "Get CI evals by agent ID",
|
|
3169
|
-
tags: ["agents"],
|
|
3170
|
-
parameters: [
|
|
3171
|
-
{
|
|
3172
|
-
name: "agentId",
|
|
3173
|
-
in: "path",
|
|
3174
|
-
required: true,
|
|
3175
|
-
schema: { type: "string" }
|
|
3176
|
-
}
|
|
3177
|
-
],
|
|
3178
|
-
responses: {
|
|
3179
|
-
200: {
|
|
3180
|
-
description: "List of evals"
|
|
3181
|
-
}
|
|
3182
|
-
}
|
|
3183
|
-
}),
|
|
3184
|
-
getEvalsByAgentIdHandler
|
|
3185
|
-
);
|
|
3186
|
-
router.get(
|
|
3187
|
-
"/:agentId/evals/live",
|
|
3188
|
-
w({
|
|
3189
|
-
description: "Get live evals by agent ID",
|
|
3190
|
-
tags: ["agents"],
|
|
3191
|
-
parameters: [
|
|
3192
|
-
{
|
|
3193
|
-
name: "agentId",
|
|
3194
|
-
in: "path",
|
|
3195
|
-
required: true,
|
|
3196
|
-
schema: { type: "string" }
|
|
3197
|
-
}
|
|
3198
|
-
],
|
|
3199
|
-
responses: {
|
|
3200
|
-
200: {
|
|
3201
|
-
description: "List of evals"
|
|
3202
|
-
}
|
|
3203
|
-
}
|
|
3204
|
-
}),
|
|
3205
|
-
getLiveEvalsByAgentIdHandler
|
|
3206
|
-
);
|
|
3207
3497
|
router.post(
|
|
3208
3498
|
"/:agentId/generate-legacy",
|
|
3209
3499
|
bodyLimit(bodyLimitOptions),
|
|
@@ -3693,7 +3983,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3693
3983
|
"/:agentId/stream/vnext/ui",
|
|
3694
3984
|
bodyLimit(bodyLimitOptions),
|
|
3695
3985
|
w({
|
|
3696
|
-
description: "[DEPRECATED] This endpoint is deprecated. Please use /
|
|
3986
|
+
description: "[DEPRECATED] This endpoint is deprecated. Please use the @mastra/ai-sdk package to for uiMessage transformations",
|
|
3697
3987
|
tags: ["agents"],
|
|
3698
3988
|
deprecated: true,
|
|
3699
3989
|
parameters: [
|
|
@@ -3731,8 +4021,9 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
3731
4021
|
"/:agentId/stream/ui",
|
|
3732
4022
|
bodyLimit(bodyLimitOptions),
|
|
3733
4023
|
w({
|
|
3734
|
-
description: "
|
|
4024
|
+
description: "[DEPRECATED] This endpoint is deprecated. Please use the @mastra/ai-sdk package to for uiMessage transformations",
|
|
3735
4025
|
tags: ["agents"],
|
|
4026
|
+
deprecated: true,
|
|
3736
4027
|
parameters: [
|
|
3737
4028
|
{
|
|
3738
4029
|
name: "agentId",
|
|
@@ -4414,7 +4705,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
4414
4705
|
type: "object",
|
|
4415
4706
|
properties: {
|
|
4416
4707
|
data: { type: "object" },
|
|
4417
|
-
|
|
4708
|
+
requestContext: { type: "object" }
|
|
4418
4709
|
},
|
|
4419
4710
|
required: ["data"]
|
|
4420
4711
|
}
|
|
@@ -4455,7 +4746,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
4455
4746
|
properties: {
|
|
4456
4747
|
runId: { type: "string", description: "The run ID for the execution" },
|
|
4457
4748
|
toolCallId: { type: "string", description: "The tool call ID for the execution" },
|
|
4458
|
-
|
|
4749
|
+
requestContext: { type: "object", description: "Request Context for the execution" },
|
|
4459
4750
|
format: { type: "string", enum: ["aisdk", "mastra"], description: "Output format" }
|
|
4460
4751
|
},
|
|
4461
4752
|
required: ["runId", "toolCallId"]
|
|
@@ -4497,7 +4788,7 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
4497
4788
|
properties: {
|
|
4498
4789
|
runId: { type: "string", description: "The run ID for the execution" },
|
|
4499
4790
|
toolCallId: { type: "string", description: "The tool call ID for the execution" },
|
|
4500
|
-
|
|
4791
|
+
requestContext: { type: "object", description: "Request Context for the execution" },
|
|
4501
4792
|
format: { type: "string", enum: ["aisdk", "mastra"], description: "Output format" }
|
|
4502
4793
|
},
|
|
4503
4794
|
required: ["runId", "toolCallId"]
|
|
@@ -4637,12 +4928,12 @@ function agentsRouterDev(bodyLimitOptions) {
|
|
|
4637
4928
|
);
|
|
4638
4929
|
return router;
|
|
4639
4930
|
}
|
|
4640
|
-
async function
|
|
4931
|
+
async function listLogsHandler(c2) {
|
|
4641
4932
|
try {
|
|
4642
4933
|
const mastra = c2.get("mastra");
|
|
4643
4934
|
const { transportId, fromDate, toDate, logLevel, page, perPage } = c2.req.query();
|
|
4644
4935
|
const filters = c2.req.queries("filters");
|
|
4645
|
-
const logs = await
|
|
4936
|
+
const logs = await listLogsHandler$1({
|
|
4646
4937
|
mastra,
|
|
4647
4938
|
transportId,
|
|
4648
4939
|
params: {
|
|
@@ -4659,13 +4950,13 @@ async function getLogsHandler(c2) {
|
|
|
4659
4950
|
return handleError(error, "Error getting logs");
|
|
4660
4951
|
}
|
|
4661
4952
|
}
|
|
4662
|
-
async function
|
|
4953
|
+
async function listLogsByRunIdHandler(c2) {
|
|
4663
4954
|
try {
|
|
4664
4955
|
const mastra = c2.get("mastra");
|
|
4665
4956
|
const runId = c2.req.param("runId");
|
|
4666
4957
|
const { transportId, fromDate, toDate, logLevel, page, perPage } = c2.req.query();
|
|
4667
4958
|
const filters = c2.req.queries("filters");
|
|
4668
|
-
const logs = await
|
|
4959
|
+
const logs = await listLogsByRunIdHandler$1({
|
|
4669
4960
|
mastra,
|
|
4670
4961
|
runId,
|
|
4671
4962
|
transportId,
|
|
@@ -4683,10 +4974,10 @@ async function getLogsByRunIdHandler(c2) {
|
|
|
4683
4974
|
return handleError(error, "Error getting logs by run ID");
|
|
4684
4975
|
}
|
|
4685
4976
|
}
|
|
4686
|
-
async function
|
|
4977
|
+
async function listLogTransports(c2) {
|
|
4687
4978
|
try {
|
|
4688
4979
|
const mastra = c2.get("mastra");
|
|
4689
|
-
const result = await
|
|
4980
|
+
const result = await listLogTransports$1({
|
|
4690
4981
|
mastra
|
|
4691
4982
|
});
|
|
4692
4983
|
return c2.json(result);
|
|
@@ -4753,7 +5044,7 @@ function logsRouter() {
|
|
|
4753
5044
|
}
|
|
4754
5045
|
}
|
|
4755
5046
|
}),
|
|
4756
|
-
|
|
5047
|
+
listLogsHandler
|
|
4757
5048
|
);
|
|
4758
5049
|
router.get(
|
|
4759
5050
|
"/transports",
|
|
@@ -4766,7 +5057,7 @@ function logsRouter() {
|
|
|
4766
5057
|
}
|
|
4767
5058
|
}
|
|
4768
5059
|
}),
|
|
4769
|
-
|
|
5060
|
+
listLogTransports
|
|
4770
5061
|
);
|
|
4771
5062
|
router.get(
|
|
4772
5063
|
"/:runId",
|
|
@@ -4829,7 +5120,7 @@ function logsRouter() {
|
|
|
4829
5120
|
}
|
|
4830
5121
|
}
|
|
4831
5122
|
}),
|
|
4832
|
-
|
|
5123
|
+
listLogsByRunIdHandler
|
|
4833
5124
|
);
|
|
4834
5125
|
return router;
|
|
4835
5126
|
}
|
|
@@ -6696,11 +6987,11 @@ var getMcpServerMessageHandler = async (c2) => {
|
|
|
6696
6987
|
const mastra = getMastra(c2);
|
|
6697
6988
|
const serverId = c2.req.param("serverId");
|
|
6698
6989
|
const { req, res } = toReqRes(c2.req.raw);
|
|
6699
|
-
const server = mastra.
|
|
6990
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6700
6991
|
if (!server) {
|
|
6701
6992
|
res.writeHead(404, { "Content-Type": "application/json" });
|
|
6702
6993
|
res.end(JSON.stringify({ error: `MCP server '${serverId}' not found` }));
|
|
6703
|
-
return;
|
|
6994
|
+
return await toFetchResponse(res);
|
|
6704
6995
|
}
|
|
6705
6996
|
try {
|
|
6706
6997
|
await server.startHTTP({
|
|
@@ -6724,15 +7015,17 @@ var getMcpServerMessageHandler = async (c2) => {
|
|
|
6724
7015
|
// Cannot determine original request ID in catch
|
|
6725
7016
|
})
|
|
6726
7017
|
);
|
|
7018
|
+
return await toFetchResponse(res);
|
|
6727
7019
|
} else {
|
|
6728
7020
|
c2.get("logger")?.error("Error after headers sent:", error);
|
|
7021
|
+
return await toFetchResponse(res);
|
|
6729
7022
|
}
|
|
6730
7023
|
}
|
|
6731
7024
|
};
|
|
6732
7025
|
var getMcpServerSseHandler = async (c2) => {
|
|
6733
7026
|
const mastra = getMastra(c2);
|
|
6734
7027
|
const serverId = c2.req.param("serverId");
|
|
6735
|
-
const server = mastra.
|
|
7028
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6736
7029
|
if (!server) {
|
|
6737
7030
|
return c2.json({ error: `MCP server '${serverId}' not found` }, 404);
|
|
6738
7031
|
}
|
|
@@ -6753,13 +7046,13 @@ var getMcpServerSseHandler = async (c2) => {
|
|
|
6753
7046
|
};
|
|
6754
7047
|
var listMcpRegistryServersHandler = async (c2) => {
|
|
6755
7048
|
const mastra = getMastra(c2);
|
|
6756
|
-
if (!mastra || typeof mastra.
|
|
6757
|
-
c2.get("logger")?.error("Mastra instance or
|
|
6758
|
-
return c2.json({ error: "Mastra instance or
|
|
7049
|
+
if (!mastra || typeof mastra.listMCPServers !== "function") {
|
|
7050
|
+
c2.get("logger")?.error("Mastra instance or listMCPServers method not available in listMcpRegistryServersHandler");
|
|
7051
|
+
return c2.json({ error: "Mastra instance or listMCPServers method not available" }, 500);
|
|
6759
7052
|
}
|
|
6760
|
-
const mcpServersMap = mastra.
|
|
7053
|
+
const mcpServersMap = mastra.listMCPServers();
|
|
6761
7054
|
if (!mcpServersMap) {
|
|
6762
|
-
c2.get("logger")?.warn("
|
|
7055
|
+
c2.get("logger")?.warn("listMCPServers returned undefined or null in listMcpRegistryServersHandler");
|
|
6763
7056
|
return c2.json({ servers: [], next: null, total_count: 0 });
|
|
6764
7057
|
}
|
|
6765
7058
|
const allServersArray = Array.from(
|
|
@@ -6788,11 +7081,13 @@ var getMcpRegistryServerDetailHandler = async (c2) => {
|
|
|
6788
7081
|
const mastra = getMastra(c2);
|
|
6789
7082
|
const serverId = c2.req.param("id");
|
|
6790
7083
|
const requestedVersion = c2.req.query("version");
|
|
6791
|
-
if (!mastra || typeof mastra.
|
|
6792
|
-
c2.get("logger")?.error(
|
|
6793
|
-
|
|
7084
|
+
if (!mastra || typeof mastra.getMCPServerById !== "function") {
|
|
7085
|
+
c2.get("logger")?.error(
|
|
7086
|
+
"Mastra instance or getMCPServerById method not available in getMcpRegistryServerDetailHandler"
|
|
7087
|
+
);
|
|
7088
|
+
return c2.json({ error: "Mastra instance or getMCPServerById method not available" }, 500);
|
|
6794
7089
|
}
|
|
6795
|
-
const server = mastra.
|
|
7090
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6796
7091
|
if (!server) {
|
|
6797
7092
|
return c2.json({ error: `MCP server with ID '${serverId}' not found` }, 404);
|
|
6798
7093
|
}
|
|
@@ -6814,11 +7109,11 @@ var getMcpRegistryServerDetailHandler = async (c2) => {
|
|
|
6814
7109
|
var listMcpServerToolsHandler = async (c2) => {
|
|
6815
7110
|
const mastra = getMastra(c2);
|
|
6816
7111
|
const serverId = c2.req.param("serverId");
|
|
6817
|
-
if (!mastra || typeof mastra.
|
|
6818
|
-
c2.get("logger")?.error("Mastra instance or
|
|
6819
|
-
return c2.json({ error: "Mastra instance or
|
|
7112
|
+
if (!mastra || typeof mastra.getMCPServerById !== "function") {
|
|
7113
|
+
c2.get("logger")?.error("Mastra instance or getMCPServerById method not available in listMcpServerToolsHandler");
|
|
7114
|
+
return c2.json({ error: "Mastra instance or getMCPServerById method not available" }, 500);
|
|
6820
7115
|
}
|
|
6821
|
-
const server = mastra.
|
|
7116
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6822
7117
|
if (!server) {
|
|
6823
7118
|
return c2.json({ error: `MCP server with ID '${serverId}' not found` }, 404);
|
|
6824
7119
|
}
|
|
@@ -6838,11 +7133,11 @@ var getMcpServerToolDetailHandler = async (c2) => {
|
|
|
6838
7133
|
const mastra = getMastra(c2);
|
|
6839
7134
|
const serverId = c2.req.param("serverId");
|
|
6840
7135
|
const toolId = c2.req.param("toolId");
|
|
6841
|
-
if (!mastra || typeof mastra.
|
|
6842
|
-
c2.get("logger")?.error("Mastra instance or
|
|
6843
|
-
return c2.json({ error: "Mastra instance or
|
|
7136
|
+
if (!mastra || typeof mastra.getMCPServerById !== "function") {
|
|
7137
|
+
c2.get("logger")?.error("Mastra instance or getMCPServerById method not available in getMcpServerToolDetailHandler");
|
|
7138
|
+
return c2.json({ error: "Mastra instance or getMCPServerById method not available" }, 500);
|
|
6844
7139
|
}
|
|
6845
|
-
const server = mastra.
|
|
7140
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6846
7141
|
if (!server) {
|
|
6847
7142
|
return c2.json({ error: `MCP server with ID '${serverId}' not found` }, 404);
|
|
6848
7143
|
}
|
|
@@ -6867,11 +7162,11 @@ var executeMcpServerToolHandler = async (c2) => {
|
|
|
6867
7162
|
const mastra = getMastra(c2);
|
|
6868
7163
|
const serverId = c2.req.param("serverId");
|
|
6869
7164
|
const toolId = c2.req.param("toolId");
|
|
6870
|
-
if (!mastra || typeof mastra.
|
|
6871
|
-
c2.get("logger")?.error("Mastra instance or
|
|
6872
|
-
return c2.json({ error: "Mastra instance or
|
|
7165
|
+
if (!mastra || typeof mastra.getMCPServerById !== "function") {
|
|
7166
|
+
c2.get("logger")?.error("Mastra instance or getMCPServerById method not available in executeMcpServerToolHandler");
|
|
7167
|
+
return c2.json({ error: "Mastra instance or getMCPServerById method not available" }, 500);
|
|
6873
7168
|
}
|
|
6874
|
-
const server = mastra.
|
|
7169
|
+
const server = mastra.getMCPServerById(serverId);
|
|
6875
7170
|
if (!server) {
|
|
6876
7171
|
return c2.json({ error: `MCP server with ID '${serverId}' not found` }, 404);
|
|
6877
7172
|
}
|
|
@@ -6882,8 +7177,8 @@ var executeMcpServerToolHandler = async (c2) => {
|
|
|
6882
7177
|
try {
|
|
6883
7178
|
const body = await c2.req.json();
|
|
6884
7179
|
const args = body?.data;
|
|
6885
|
-
const
|
|
6886
|
-
const result = await server.executeTool(toolId, args,
|
|
7180
|
+
const requestContext = body?.requestContext;
|
|
7181
|
+
const result = await server.executeTool(toolId, args, requestContext);
|
|
6887
7182
|
return c2.json({ result });
|
|
6888
7183
|
} catch (error) {
|
|
6889
7184
|
c2.get("logger")?.error(`Error executing tool '${toolId}' on server '${serverId}':`, { error: error.message });
|
|
@@ -7285,7 +7580,7 @@ function mcpRouter(bodyLimitOptions) {
|
|
|
7285
7580
|
type: "object",
|
|
7286
7581
|
properties: {
|
|
7287
7582
|
data: { type: "object" },
|
|
7288
|
-
|
|
7583
|
+
requestContext: { type: "object" }
|
|
7289
7584
|
}
|
|
7290
7585
|
}
|
|
7291
7586
|
}
|
|
@@ -7315,17 +7610,38 @@ function parseLimit(rawLimit) {
|
|
|
7315
7610
|
}
|
|
7316
7611
|
return void 0;
|
|
7317
7612
|
}
|
|
7613
|
+
function parsePage(value, defaultValue = 0) {
|
|
7614
|
+
const parsed = parseInt(value || String(defaultValue), 10);
|
|
7615
|
+
return isNaN(parsed) ? defaultValue : Math.max(0, parsed);
|
|
7616
|
+
}
|
|
7617
|
+
function parsePerPage(value, defaultValue = 100, max = 1e3) {
|
|
7618
|
+
const normalized = (value || "").trim().toLowerCase();
|
|
7619
|
+
if (normalized === "false") {
|
|
7620
|
+
return false;
|
|
7621
|
+
}
|
|
7622
|
+
const parsed = parseInt(value || String(defaultValue), 10);
|
|
7623
|
+
if (isNaN(parsed)) return defaultValue;
|
|
7624
|
+
return Math.min(max, Math.max(1, parsed));
|
|
7625
|
+
}
|
|
7318
7626
|
|
|
7319
7627
|
// src/server/handlers/routes/memory/handlers.ts
|
|
7628
|
+
function parseJsonParam(value) {
|
|
7629
|
+
if (!value) return void 0;
|
|
7630
|
+
try {
|
|
7631
|
+
return JSON.parse(value);
|
|
7632
|
+
} catch {
|
|
7633
|
+
return void 0;
|
|
7634
|
+
}
|
|
7635
|
+
}
|
|
7320
7636
|
async function getMemoryStatusHandler(c2) {
|
|
7321
7637
|
try {
|
|
7322
7638
|
const mastra = c2.get("mastra");
|
|
7323
7639
|
const agentId = c2.req.query("agentId");
|
|
7324
|
-
const
|
|
7640
|
+
const requestContext = c2.get("requestContext");
|
|
7325
7641
|
const result = await getMemoryStatusHandler$1({
|
|
7326
7642
|
mastra,
|
|
7327
7643
|
agentId,
|
|
7328
|
-
|
|
7644
|
+
requestContext
|
|
7329
7645
|
});
|
|
7330
7646
|
return c2.json(result);
|
|
7331
7647
|
} catch (error) {
|
|
@@ -7336,61 +7652,51 @@ async function getMemoryConfigHandler(c2) {
|
|
|
7336
7652
|
try {
|
|
7337
7653
|
const mastra = c2.get("mastra");
|
|
7338
7654
|
const agentId = c2.req.query("agentId");
|
|
7339
|
-
const
|
|
7655
|
+
const requestContext = c2.get("requestContext");
|
|
7340
7656
|
const result = await getMemoryConfigHandler$1({
|
|
7341
7657
|
mastra,
|
|
7342
7658
|
agentId,
|
|
7343
|
-
|
|
7659
|
+
requestContext
|
|
7344
7660
|
});
|
|
7345
7661
|
return c2.json(result);
|
|
7346
7662
|
} catch (error) {
|
|
7347
7663
|
return handleError(error, "Error getting memory configuration");
|
|
7348
7664
|
}
|
|
7349
7665
|
}
|
|
7350
|
-
async function
|
|
7351
|
-
try {
|
|
7352
|
-
const mastra = c2.get("mastra");
|
|
7353
|
-
const agentId = c2.req.query("agentId");
|
|
7354
|
-
const resourceId = c2.req.query("resourceid");
|
|
7355
|
-
const orderBy = c2.req.query("orderBy");
|
|
7356
|
-
const sortDirection = c2.req.query("sortDirection");
|
|
7357
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
7358
|
-
const result = await getThreadsHandler$1({
|
|
7359
|
-
mastra,
|
|
7360
|
-
agentId,
|
|
7361
|
-
resourceId,
|
|
7362
|
-
orderBy,
|
|
7363
|
-
sortDirection,
|
|
7364
|
-
runtimeContext
|
|
7365
|
-
});
|
|
7366
|
-
return c2.json(result);
|
|
7367
|
-
} catch (error) {
|
|
7368
|
-
return handleError(error, "Error getting threads");
|
|
7369
|
-
}
|
|
7370
|
-
}
|
|
7371
|
-
async function getThreadsPaginatedHandler(c2) {
|
|
7666
|
+
async function listThreadsHandler(c2) {
|
|
7372
7667
|
try {
|
|
7373
7668
|
const mastra = c2.get("mastra");
|
|
7374
7669
|
const agentId = c2.req.query("agentId");
|
|
7375
7670
|
const resourceId = c2.req.query("resourceId");
|
|
7376
|
-
const page =
|
|
7377
|
-
const perPage =
|
|
7378
|
-
const
|
|
7379
|
-
const
|
|
7380
|
-
const
|
|
7381
|
-
const
|
|
7671
|
+
const page = parsePage(c2.req.query("page"));
|
|
7672
|
+
const perPage = parsePerPage(c2.req.query("perPage"));
|
|
7673
|
+
const field = c2.req.query("orderBy");
|
|
7674
|
+
const direction = c2.req.query("sortDirection");
|
|
7675
|
+
const requestContext = c2.get("requestContext");
|
|
7676
|
+
const validFields = ["createdAt", "updatedAt"];
|
|
7677
|
+
const validDirections = ["ASC", "DESC"];
|
|
7678
|
+
if (field && !validFields.includes(field)) {
|
|
7679
|
+
return c2.json({ error: `Invalid orderBy field: ${field}. Must be one of: ${validFields.join(", ")}` }, 400);
|
|
7680
|
+
}
|
|
7681
|
+
if (direction && !validDirections.includes(direction)) {
|
|
7682
|
+
return c2.json(
|
|
7683
|
+
{ error: `Invalid sortDirection: ${direction}. Must be one of: ${validDirections.join(", ")}` },
|
|
7684
|
+
400
|
|
7685
|
+
);
|
|
7686
|
+
}
|
|
7687
|
+
const orderBy = field || direction ? { field: field || "createdAt", direction: direction || "DESC" } : void 0;
|
|
7688
|
+
const result = await listThreadsHandler$1({
|
|
7382
7689
|
mastra,
|
|
7383
7690
|
agentId,
|
|
7384
7691
|
resourceId,
|
|
7385
7692
|
page,
|
|
7386
7693
|
perPage,
|
|
7387
7694
|
orderBy,
|
|
7388
|
-
|
|
7389
|
-
runtimeContext
|
|
7695
|
+
requestContext
|
|
7390
7696
|
});
|
|
7391
7697
|
return c2.json(result);
|
|
7392
7698
|
} catch (error) {
|
|
7393
|
-
return handleError(error, "Error
|
|
7699
|
+
return handleError(error, "Error listing threads");
|
|
7394
7700
|
}
|
|
7395
7701
|
}
|
|
7396
7702
|
async function getThreadByIdHandler(c2) {
|
|
@@ -7398,12 +7704,12 @@ async function getThreadByIdHandler(c2) {
|
|
|
7398
7704
|
const mastra = c2.get("mastra");
|
|
7399
7705
|
const agentId = c2.req.query("agentId");
|
|
7400
7706
|
const threadId = c2.req.param("threadId");
|
|
7401
|
-
const
|
|
7707
|
+
const requestContext = c2.get("requestContext");
|
|
7402
7708
|
const result = await getThreadByIdHandler$1({
|
|
7403
7709
|
mastra,
|
|
7404
7710
|
agentId,
|
|
7405
7711
|
threadId,
|
|
7406
|
-
|
|
7712
|
+
requestContext
|
|
7407
7713
|
});
|
|
7408
7714
|
return c2.json(result);
|
|
7409
7715
|
} catch (error) {
|
|
@@ -7415,12 +7721,12 @@ async function saveMessagesHandler(c2) {
|
|
|
7415
7721
|
const mastra = c2.get("mastra");
|
|
7416
7722
|
const agentId = c2.req.query("agentId");
|
|
7417
7723
|
const body = await c2.req.json();
|
|
7418
|
-
const
|
|
7724
|
+
const requestContext = c2.get("requestContext");
|
|
7419
7725
|
const result = await saveMessagesHandler$1({
|
|
7420
7726
|
mastra,
|
|
7421
7727
|
agentId,
|
|
7422
7728
|
body,
|
|
7423
|
-
|
|
7729
|
+
requestContext
|
|
7424
7730
|
});
|
|
7425
7731
|
return c2.json(result);
|
|
7426
7732
|
} catch (error) {
|
|
@@ -7432,12 +7738,12 @@ async function createThreadHandler(c2) {
|
|
|
7432
7738
|
const mastra = c2.get("mastra");
|
|
7433
7739
|
const agentId = c2.req.query("agentId");
|
|
7434
7740
|
const body = await c2.req.json();
|
|
7435
|
-
const
|
|
7741
|
+
const requestContext = c2.get("requestContext");
|
|
7436
7742
|
const result = await createThreadHandler$1({
|
|
7437
7743
|
mastra,
|
|
7438
7744
|
agentId,
|
|
7439
7745
|
body,
|
|
7440
|
-
|
|
7746
|
+
requestContext
|
|
7441
7747
|
});
|
|
7442
7748
|
return c2.json(result);
|
|
7443
7749
|
} catch (error) {
|
|
@@ -7450,13 +7756,13 @@ async function updateThreadHandler(c2) {
|
|
|
7450
7756
|
const agentId = c2.req.query("agentId");
|
|
7451
7757
|
const threadId = c2.req.param("threadId");
|
|
7452
7758
|
const body = await c2.req.json();
|
|
7453
|
-
const
|
|
7759
|
+
const requestContext = c2.get("requestContext");
|
|
7454
7760
|
const result = await updateThreadHandler$1({
|
|
7455
7761
|
mastra,
|
|
7456
7762
|
agentId,
|
|
7457
7763
|
threadId,
|
|
7458
7764
|
body,
|
|
7459
|
-
|
|
7765
|
+
requestContext
|
|
7460
7766
|
});
|
|
7461
7767
|
return c2.json(result);
|
|
7462
7768
|
} catch (error) {
|
|
@@ -7468,57 +7774,41 @@ async function deleteThreadHandler(c2) {
|
|
|
7468
7774
|
const mastra = c2.get("mastra");
|
|
7469
7775
|
const agentId = c2.req.query("agentId");
|
|
7470
7776
|
const threadId = c2.req.param("threadId");
|
|
7471
|
-
const
|
|
7777
|
+
const requestContext = c2.get("requestContext");
|
|
7472
7778
|
const result = await deleteThreadHandler$1({
|
|
7473
7779
|
mastra,
|
|
7474
7780
|
agentId,
|
|
7475
7781
|
threadId,
|
|
7476
|
-
|
|
7782
|
+
requestContext
|
|
7477
7783
|
});
|
|
7478
7784
|
return c2.json(result);
|
|
7479
7785
|
} catch (error) {
|
|
7480
7786
|
return handleError(error, "Error deleting thread");
|
|
7481
7787
|
}
|
|
7482
7788
|
}
|
|
7483
|
-
async function
|
|
7789
|
+
async function listMessagesHandler(c2) {
|
|
7484
7790
|
try {
|
|
7485
7791
|
const mastra = c2.get("mastra");
|
|
7486
7792
|
const agentId = c2.req.query("agentId");
|
|
7487
7793
|
const threadId = c2.req.param("threadId");
|
|
7488
|
-
const limit = parseLimit(c2.req.query("limit"));
|
|
7489
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
7490
|
-
const result = await getMessagesHandler$1({
|
|
7491
|
-
mastra,
|
|
7492
|
-
agentId,
|
|
7493
|
-
threadId,
|
|
7494
|
-
limit,
|
|
7495
|
-
runtimeContext
|
|
7496
|
-
});
|
|
7497
|
-
return c2.json(result);
|
|
7498
|
-
} catch (error) {
|
|
7499
|
-
return handleError(error, "Error getting messages");
|
|
7500
|
-
}
|
|
7501
|
-
}
|
|
7502
|
-
async function getMessagesPaginatedHandler(c2) {
|
|
7503
|
-
try {
|
|
7504
|
-
const mastra = c2.get("mastra");
|
|
7505
|
-
const threadId = c2.req.param("threadId");
|
|
7506
7794
|
const resourceId = c2.req.query("resourceId");
|
|
7507
|
-
const
|
|
7508
|
-
const
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
|
|
7514
|
-
}
|
|
7515
|
-
}
|
|
7516
|
-
const result = await getMessagesPaginatedHandler$1({
|
|
7795
|
+
const page = parsePage(c2.req.query("page"));
|
|
7796
|
+
const perPage = parsePerPage(c2.req.query("perPage"));
|
|
7797
|
+
const orderBy = parseJsonParam(c2.req.query("orderBy"));
|
|
7798
|
+
const include = parseJsonParam(c2.req.query("include"));
|
|
7799
|
+
const filter = parseJsonParam(c2.req.query("filter"));
|
|
7800
|
+
const requestContext = c2.get("requestContext");
|
|
7801
|
+
const result = await listMessagesHandler$1({
|
|
7517
7802
|
mastra,
|
|
7803
|
+
agentId,
|
|
7518
7804
|
threadId,
|
|
7519
7805
|
resourceId,
|
|
7520
|
-
|
|
7521
|
-
|
|
7806
|
+
page,
|
|
7807
|
+
perPage,
|
|
7808
|
+
orderBy,
|
|
7809
|
+
include,
|
|
7810
|
+
filter,
|
|
7811
|
+
requestContext
|
|
7522
7812
|
});
|
|
7523
7813
|
return c2.json(result);
|
|
7524
7814
|
} catch (error) {
|
|
@@ -7531,13 +7821,13 @@ async function updateWorkingMemoryHandler(c2) {
|
|
|
7531
7821
|
const agentId = c2.req.query("agentId");
|
|
7532
7822
|
const threadId = c2.req.param("threadId");
|
|
7533
7823
|
const body = await c2.req.json();
|
|
7534
|
-
const
|
|
7824
|
+
const requestContext = c2.get("requestContext");
|
|
7535
7825
|
const result = await updateWorkingMemoryHandler$1({
|
|
7536
7826
|
mastra,
|
|
7537
7827
|
agentId,
|
|
7538
7828
|
threadId,
|
|
7539
7829
|
body,
|
|
7540
|
-
|
|
7830
|
+
requestContext
|
|
7541
7831
|
});
|
|
7542
7832
|
return c2.json(result);
|
|
7543
7833
|
} catch (error) {
|
|
@@ -7550,13 +7840,13 @@ async function getWorkingMemoryHandler(c2) {
|
|
|
7550
7840
|
const agentId = c2.req.query("agentId");
|
|
7551
7841
|
const threadId = c2.req.param("threadId");
|
|
7552
7842
|
const resourceId = c2.req.query("resourceId");
|
|
7553
|
-
const
|
|
7843
|
+
const requestContext = c2.get("requestContext");
|
|
7554
7844
|
const result = await getWorkingMemoryHandler$1({
|
|
7555
7845
|
mastra,
|
|
7556
7846
|
agentId,
|
|
7557
7847
|
threadId,
|
|
7558
7848
|
resourceId,
|
|
7559
|
-
|
|
7849
|
+
requestContext
|
|
7560
7850
|
});
|
|
7561
7851
|
return c2.json(result);
|
|
7562
7852
|
} catch (error) {
|
|
@@ -7572,7 +7862,7 @@ async function searchMemoryHandler(c2) {
|
|
|
7572
7862
|
const threadId = c2.req.query("threadId");
|
|
7573
7863
|
const limit = parseLimit(c2.req.query("limit"));
|
|
7574
7864
|
const memoryConfig = c2.req.query("memoryConfig") ? JSON.parse(c2.req.query("memoryConfig")) : void 0;
|
|
7575
|
-
const
|
|
7865
|
+
const requestContext = c2.get("requestContext");
|
|
7576
7866
|
const result = await searchMemoryHandler$1({
|
|
7577
7867
|
mastra,
|
|
7578
7868
|
agentId,
|
|
@@ -7581,7 +7871,7 @@ async function searchMemoryHandler(c2) {
|
|
|
7581
7871
|
threadId,
|
|
7582
7872
|
limit,
|
|
7583
7873
|
memoryConfig,
|
|
7584
|
-
|
|
7874
|
+
requestContext
|
|
7585
7875
|
});
|
|
7586
7876
|
return c2.json(result);
|
|
7587
7877
|
} catch (error) {
|
|
@@ -7592,14 +7882,14 @@ async function deleteMessagesHandler(c2) {
|
|
|
7592
7882
|
try {
|
|
7593
7883
|
const mastra = c2.get("mastra");
|
|
7594
7884
|
const agentId = c2.req.query("agentId");
|
|
7595
|
-
const
|
|
7885
|
+
const requestContext = c2.get("requestContext");
|
|
7596
7886
|
const body = await c2.req.json();
|
|
7597
7887
|
const messageIds = body?.messageIds;
|
|
7598
7888
|
const result = await deleteMessagesHandler$1({
|
|
7599
7889
|
mastra,
|
|
7600
7890
|
agentId,
|
|
7601
7891
|
messageIds,
|
|
7602
|
-
|
|
7892
|
+
requestContext
|
|
7603
7893
|
});
|
|
7604
7894
|
return c2.json(result);
|
|
7605
7895
|
} catch (error) {
|
|
@@ -7649,6 +7939,20 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
7649
7939
|
required: true,
|
|
7650
7940
|
schema: { type: "string" }
|
|
7651
7941
|
},
|
|
7942
|
+
{
|
|
7943
|
+
name: "offset",
|
|
7944
|
+
in: "query",
|
|
7945
|
+
required: false,
|
|
7946
|
+
schema: { type: "number", default: 0 },
|
|
7947
|
+
description: "Number of records to skip"
|
|
7948
|
+
},
|
|
7949
|
+
{
|
|
7950
|
+
name: "limit",
|
|
7951
|
+
in: "query",
|
|
7952
|
+
required: false,
|
|
7953
|
+
schema: { type: "number", default: 100 },
|
|
7954
|
+
description: "Maximum number of threads to return"
|
|
7955
|
+
},
|
|
7652
7956
|
{
|
|
7653
7957
|
name: "orderBy",
|
|
7654
7958
|
in: "query",
|
|
@@ -7678,7 +7982,7 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
7678
7982
|
}
|
|
7679
7983
|
}
|
|
7680
7984
|
}),
|
|
7681
|
-
|
|
7985
|
+
listThreadsHandler
|
|
7682
7986
|
);
|
|
7683
7987
|
router.get(
|
|
7684
7988
|
"/network/threads/:threadId",
|
|
@@ -7713,14 +8017,17 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
7713
8017
|
router.get(
|
|
7714
8018
|
"/network/threads/:threadId/messages",
|
|
7715
8019
|
w({
|
|
7716
|
-
description: "Get messages for a thread",
|
|
8020
|
+
description: "Get paginated messages for a thread",
|
|
7717
8021
|
tags: ["networkMemory"],
|
|
7718
8022
|
parameters: [
|
|
7719
8023
|
{
|
|
7720
8024
|
name: "threadId",
|
|
7721
8025
|
in: "path",
|
|
7722
8026
|
required: true,
|
|
7723
|
-
|
|
8027
|
+
description: "The unique identifier of the thread",
|
|
8028
|
+
schema: {
|
|
8029
|
+
type: "string"
|
|
8030
|
+
}
|
|
7724
8031
|
},
|
|
7725
8032
|
{
|
|
7726
8033
|
name: "networkId",
|
|
@@ -7729,20 +8036,85 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
7729
8036
|
schema: { type: "string" }
|
|
7730
8037
|
},
|
|
7731
8038
|
{
|
|
7732
|
-
name: "
|
|
8039
|
+
name: "agentId",
|
|
8040
|
+
in: "query",
|
|
8041
|
+
required: true,
|
|
8042
|
+
description: "The unique identifier of the agent",
|
|
8043
|
+
schema: {
|
|
8044
|
+
type: "string"
|
|
8045
|
+
}
|
|
8046
|
+
},
|
|
8047
|
+
{
|
|
8048
|
+
name: "resourceId",
|
|
7733
8049
|
in: "query",
|
|
7734
8050
|
required: false,
|
|
7735
|
-
|
|
7736
|
-
|
|
8051
|
+
description: "Filter messages by resource ID",
|
|
8052
|
+
schema: {
|
|
8053
|
+
type: "string"
|
|
8054
|
+
}
|
|
8055
|
+
},
|
|
8056
|
+
{
|
|
8057
|
+
name: "page",
|
|
8058
|
+
in: "query",
|
|
8059
|
+
required: false,
|
|
8060
|
+
description: "Zero-indexed page number for pagination (default: 0)",
|
|
8061
|
+
schema: {
|
|
8062
|
+
type: "integer",
|
|
8063
|
+
minimum: 0,
|
|
8064
|
+
default: 0
|
|
8065
|
+
}
|
|
8066
|
+
},
|
|
8067
|
+
{
|
|
8068
|
+
name: "perPage",
|
|
8069
|
+
in: "query",
|
|
8070
|
+
required: false,
|
|
8071
|
+
description: 'Number of items per page, or "false" to fetch all records (default: 40)',
|
|
8072
|
+
schema: {
|
|
8073
|
+
oneOf: [
|
|
8074
|
+
{ type: "integer", minimum: 0 },
|
|
8075
|
+
{ type: "boolean", enum: [false] }
|
|
8076
|
+
],
|
|
8077
|
+
default: 40
|
|
8078
|
+
}
|
|
8079
|
+
},
|
|
8080
|
+
{
|
|
8081
|
+
name: "orderBy",
|
|
8082
|
+
in: "query",
|
|
8083
|
+
required: false,
|
|
8084
|
+
description: "JSON string specifying sort order",
|
|
8085
|
+
schema: {
|
|
8086
|
+
type: "string",
|
|
8087
|
+
example: '{"field":"createdAt","direction":"DESC"}'
|
|
8088
|
+
}
|
|
8089
|
+
},
|
|
8090
|
+
{
|
|
8091
|
+
name: "include",
|
|
8092
|
+
in: "query",
|
|
8093
|
+
required: false,
|
|
8094
|
+
description: "JSON string specifying messages to include with context",
|
|
8095
|
+
schema: {
|
|
8096
|
+
type: "string",
|
|
8097
|
+
example: '[{"id":"msg-123","withPreviousMessages":5,"withNextMessages":3}]'
|
|
8098
|
+
}
|
|
8099
|
+
},
|
|
8100
|
+
{
|
|
8101
|
+
name: "filter",
|
|
8102
|
+
in: "query",
|
|
8103
|
+
required: false,
|
|
8104
|
+
description: "JSON string specifying filter criteria",
|
|
8105
|
+
schema: {
|
|
8106
|
+
type: "string",
|
|
8107
|
+
example: '{"dateRange":{"start":"2024-01-01T00:00:00Z","end":"2024-12-31T23:59:59Z"}}'
|
|
8108
|
+
}
|
|
7737
8109
|
}
|
|
7738
8110
|
],
|
|
7739
8111
|
responses: {
|
|
7740
8112
|
200: {
|
|
7741
|
-
description: "
|
|
8113
|
+
description: "Paginated list of messages with metadata"
|
|
7742
8114
|
}
|
|
7743
8115
|
}
|
|
7744
8116
|
}),
|
|
7745
|
-
|
|
8117
|
+
listMessagesHandler
|
|
7746
8118
|
);
|
|
7747
8119
|
router.post(
|
|
7748
8120
|
"/network/threads",
|
|
@@ -8108,55 +8480,6 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8108
8480
|
);
|
|
8109
8481
|
router.get(
|
|
8110
8482
|
"/threads",
|
|
8111
|
-
w({
|
|
8112
|
-
description: "Get all threads",
|
|
8113
|
-
tags: ["memory"],
|
|
8114
|
-
parameters: [
|
|
8115
|
-
{
|
|
8116
|
-
name: "resourceid",
|
|
8117
|
-
in: "query",
|
|
8118
|
-
required: true,
|
|
8119
|
-
schema: { type: "string" }
|
|
8120
|
-
},
|
|
8121
|
-
{
|
|
8122
|
-
name: "agentId",
|
|
8123
|
-
in: "query",
|
|
8124
|
-
required: true,
|
|
8125
|
-
schema: { type: "string" }
|
|
8126
|
-
},
|
|
8127
|
-
{
|
|
8128
|
-
name: "orderBy",
|
|
8129
|
-
in: "query",
|
|
8130
|
-
required: false,
|
|
8131
|
-
schema: {
|
|
8132
|
-
type: "string",
|
|
8133
|
-
enum: ["createdAt", "updatedAt"],
|
|
8134
|
-
default: "createdAt"
|
|
8135
|
-
},
|
|
8136
|
-
description: "Field to sort by"
|
|
8137
|
-
},
|
|
8138
|
-
{
|
|
8139
|
-
name: "sortDirection",
|
|
8140
|
-
in: "query",
|
|
8141
|
-
required: false,
|
|
8142
|
-
schema: {
|
|
8143
|
-
type: "string",
|
|
8144
|
-
enum: ["ASC", "DESC"],
|
|
8145
|
-
default: "DESC"
|
|
8146
|
-
},
|
|
8147
|
-
description: "Sort direction"
|
|
8148
|
-
}
|
|
8149
|
-
],
|
|
8150
|
-
responses: {
|
|
8151
|
-
200: {
|
|
8152
|
-
description: "List of all threads"
|
|
8153
|
-
}
|
|
8154
|
-
}
|
|
8155
|
-
}),
|
|
8156
|
-
getThreadsHandler
|
|
8157
|
-
);
|
|
8158
|
-
router.get(
|
|
8159
|
-
"/threads/paginated",
|
|
8160
8483
|
w({
|
|
8161
8484
|
description: "Get paginated threads",
|
|
8162
8485
|
tags: ["memory"],
|
|
@@ -8174,18 +8497,18 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8174
8497
|
schema: { type: "string" }
|
|
8175
8498
|
},
|
|
8176
8499
|
{
|
|
8177
|
-
name: "
|
|
8500
|
+
name: "offset",
|
|
8178
8501
|
in: "query",
|
|
8179
8502
|
required: false,
|
|
8180
8503
|
schema: { type: "number", default: 0 },
|
|
8181
|
-
description: "
|
|
8504
|
+
description: "Number of records to skip"
|
|
8182
8505
|
},
|
|
8183
8506
|
{
|
|
8184
|
-
name: "
|
|
8507
|
+
name: "limit",
|
|
8185
8508
|
in: "query",
|
|
8186
8509
|
required: false,
|
|
8187
8510
|
schema: { type: "number", default: 100 },
|
|
8188
|
-
description: "
|
|
8511
|
+
description: "Maximum number of threads to return"
|
|
8189
8512
|
},
|
|
8190
8513
|
{
|
|
8191
8514
|
name: "orderBy",
|
|
@@ -8214,7 +8537,7 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8214
8537
|
}
|
|
8215
8538
|
}
|
|
8216
8539
|
}),
|
|
8217
|
-
|
|
8540
|
+
listThreadsHandler
|
|
8218
8541
|
);
|
|
8219
8542
|
router.get(
|
|
8220
8543
|
"/threads/:threadId",
|
|
@@ -8248,58 +8571,24 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8248
8571
|
);
|
|
8249
8572
|
router.get(
|
|
8250
8573
|
"/threads/:threadId/messages",
|
|
8251
|
-
async (c2, next) => {
|
|
8252
|
-
c2.header("Deprecation", "true");
|
|
8253
|
-
c2.header(
|
|
8254
|
-
"Warning",
|
|
8255
|
-
'299 - "This endpoint is deprecated, use /api/memory/threads/:threadId/messages/paginated instead"'
|
|
8256
|
-
);
|
|
8257
|
-
c2.header("Link", '</api/memory/threads/:threadId/messages/paginated>; rel="successor-version"');
|
|
8258
|
-
return next();
|
|
8259
|
-
},
|
|
8260
8574
|
w({
|
|
8261
|
-
description: "Get messages for a thread",
|
|
8575
|
+
description: "Get paginated messages for a thread",
|
|
8262
8576
|
tags: ["memory"],
|
|
8263
8577
|
parameters: [
|
|
8264
8578
|
{
|
|
8265
8579
|
name: "threadId",
|
|
8266
8580
|
in: "path",
|
|
8267
8581
|
required: true,
|
|
8268
|
-
|
|
8582
|
+
description: "The unique identifier of the thread",
|
|
8583
|
+
schema: {
|
|
8584
|
+
type: "string"
|
|
8585
|
+
}
|
|
8269
8586
|
},
|
|
8270
8587
|
{
|
|
8271
8588
|
name: "agentId",
|
|
8272
8589
|
in: "query",
|
|
8273
8590
|
required: true,
|
|
8274
|
-
|
|
8275
|
-
},
|
|
8276
|
-
{
|
|
8277
|
-
name: "limit",
|
|
8278
|
-
in: "query",
|
|
8279
|
-
required: false,
|
|
8280
|
-
schema: { type: "number" },
|
|
8281
|
-
description: "Limit the number of messages to retrieve (default: 40)"
|
|
8282
|
-
}
|
|
8283
|
-
],
|
|
8284
|
-
responses: {
|
|
8285
|
-
200: {
|
|
8286
|
-
description: "List of messages"
|
|
8287
|
-
}
|
|
8288
|
-
}
|
|
8289
|
-
}),
|
|
8290
|
-
getMessagesHandler
|
|
8291
|
-
);
|
|
8292
|
-
router.get(
|
|
8293
|
-
"/threads/:threadId/messages/paginated",
|
|
8294
|
-
w({
|
|
8295
|
-
description: "Get paginated messages for a thread",
|
|
8296
|
-
tags: ["memory"],
|
|
8297
|
-
parameters: [
|
|
8298
|
-
{
|
|
8299
|
-
name: "threadId",
|
|
8300
|
-
in: "path",
|
|
8301
|
-
required: true,
|
|
8302
|
-
description: "The unique identifier of the thread",
|
|
8591
|
+
description: "The unique identifier of the agent",
|
|
8303
8592
|
schema: {
|
|
8304
8593
|
type: "string"
|
|
8305
8594
|
}
|
|
@@ -8314,34 +8603,67 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8314
8603
|
}
|
|
8315
8604
|
},
|
|
8316
8605
|
{
|
|
8317
|
-
name: "
|
|
8606
|
+
name: "page",
|
|
8318
8607
|
in: "query",
|
|
8319
8608
|
required: false,
|
|
8320
|
-
description: "
|
|
8609
|
+
description: "Zero-indexed page number for pagination (default: 0)",
|
|
8321
8610
|
schema: {
|
|
8322
|
-
type: "
|
|
8323
|
-
|
|
8324
|
-
default:
|
|
8611
|
+
type: "integer",
|
|
8612
|
+
minimum: 0,
|
|
8613
|
+
default: 0
|
|
8325
8614
|
}
|
|
8326
8615
|
},
|
|
8327
8616
|
{
|
|
8328
|
-
name: "
|
|
8617
|
+
name: "perPage",
|
|
8329
8618
|
in: "query",
|
|
8330
8619
|
required: false,
|
|
8331
|
-
description: "
|
|
8620
|
+
description: 'Number of items per page, or "false" to fetch all records (default: 40)',
|
|
8332
8621
|
schema: {
|
|
8333
|
-
|
|
8334
|
-
|
|
8622
|
+
oneOf: [
|
|
8623
|
+
{ type: "integer", minimum: 0 },
|
|
8624
|
+
{ type: "boolean", enum: [false] }
|
|
8625
|
+
],
|
|
8626
|
+
default: 40
|
|
8335
8627
|
}
|
|
8336
|
-
}
|
|
8628
|
+
},
|
|
8629
|
+
{
|
|
8630
|
+
name: "orderBy",
|
|
8631
|
+
in: "query",
|
|
8632
|
+
required: false,
|
|
8633
|
+
description: "JSON string specifying sort order",
|
|
8634
|
+
schema: {
|
|
8635
|
+
type: "string",
|
|
8636
|
+
example: '{"field":"createdAt","direction":"DESC"}'
|
|
8637
|
+
}
|
|
8638
|
+
},
|
|
8639
|
+
{
|
|
8640
|
+
name: "include",
|
|
8641
|
+
in: "query",
|
|
8642
|
+
required: false,
|
|
8643
|
+
description: "JSON string specifying messages to include with context",
|
|
8644
|
+
schema: {
|
|
8645
|
+
type: "string",
|
|
8646
|
+
example: '[{"id":"msg-123","withPreviousMessages":5,"withNextMessages":3}]'
|
|
8647
|
+
}
|
|
8648
|
+
},
|
|
8649
|
+
{
|
|
8650
|
+
name: "filter",
|
|
8651
|
+
in: "query",
|
|
8652
|
+
required: false,
|
|
8653
|
+
description: "JSON string specifying filter criteria",
|
|
8654
|
+
schema: {
|
|
8655
|
+
type: "string",
|
|
8656
|
+
example: '{"dateRange":{"start":"2024-01-01T00:00:00Z","end":"2024-12-31T23:59:59Z"}}'
|
|
8657
|
+
}
|
|
8658
|
+
}
|
|
8337
8659
|
],
|
|
8338
8660
|
responses: {
|
|
8339
8661
|
200: {
|
|
8340
|
-
description: "
|
|
8662
|
+
description: "Paginated list of messages with metadata"
|
|
8341
8663
|
}
|
|
8342
8664
|
}
|
|
8343
8665
|
}),
|
|
8344
|
-
|
|
8666
|
+
listMessagesHandler
|
|
8345
8667
|
);
|
|
8346
8668
|
router.get(
|
|
8347
8669
|
"/search",
|
|
@@ -8779,23 +9101,23 @@ function memoryRoutes(bodyLimitOptions) {
|
|
|
8779
9101
|
);
|
|
8780
9102
|
return router;
|
|
8781
9103
|
}
|
|
8782
|
-
async function
|
|
9104
|
+
async function getTraceHandler(c2) {
|
|
8783
9105
|
try {
|
|
8784
9106
|
const mastra = c2.get("mastra");
|
|
8785
9107
|
const traceId = c2.req.param("traceId");
|
|
8786
9108
|
if (!traceId) {
|
|
8787
9109
|
return c2.json({ error: "Trace ID is required" }, 400);
|
|
8788
9110
|
}
|
|
8789
|
-
const trace = await
|
|
9111
|
+
const trace = await getTraceHandler$1({
|
|
8790
9112
|
mastra,
|
|
8791
9113
|
traceId
|
|
8792
9114
|
});
|
|
8793
9115
|
return c2.json(trace);
|
|
8794
9116
|
} catch (error) {
|
|
8795
|
-
return handleError(error, "Error getting
|
|
9117
|
+
return handleError(error, "Error getting trace");
|
|
8796
9118
|
}
|
|
8797
9119
|
}
|
|
8798
|
-
async function
|
|
9120
|
+
async function getTracesPaginatedHandler(c2) {
|
|
8799
9121
|
try {
|
|
8800
9122
|
const mastra = c2.get("mastra");
|
|
8801
9123
|
const { page, perPage, name, spanType, dateRange, entityId, entityType } = c2.req.query();
|
|
@@ -8806,7 +9128,7 @@ async function getAITracesPaginatedHandler(c2) {
|
|
|
8806
9128
|
const filters = {};
|
|
8807
9129
|
if (name) filters.name = name;
|
|
8808
9130
|
if (spanType) {
|
|
8809
|
-
if (Object.values(
|
|
9131
|
+
if (Object.values(SpanType).includes(spanType)) {
|
|
8810
9132
|
filters.spanType = spanType;
|
|
8811
9133
|
} else {
|
|
8812
9134
|
return c2.json({ error: "Invalid spanType" }, 400);
|
|
@@ -8830,7 +9152,7 @@ async function getAITracesPaginatedHandler(c2) {
|
|
|
8830
9152
|
if (start || end) {
|
|
8831
9153
|
pagination.dateRange = { start, end };
|
|
8832
9154
|
}
|
|
8833
|
-
const result = await
|
|
9155
|
+
const result = await getTracesPaginatedHandler$1({
|
|
8834
9156
|
mastra,
|
|
8835
9157
|
body: {
|
|
8836
9158
|
pagination,
|
|
@@ -8839,7 +9161,7 @@ async function getAITracesPaginatedHandler(c2) {
|
|
|
8839
9161
|
});
|
|
8840
9162
|
return c2.json(result);
|
|
8841
9163
|
} catch (error) {
|
|
8842
|
-
return handleError(error, "Error getting
|
|
9164
|
+
return handleError(error, "Error getting traces paginated");
|
|
8843
9165
|
}
|
|
8844
9166
|
}
|
|
8845
9167
|
async function processTraceScoringHandler(c2) {
|
|
@@ -8855,7 +9177,7 @@ async function processTraceScoringHandler(c2) {
|
|
|
8855
9177
|
return handleError(error, "Error processing trace scoring");
|
|
8856
9178
|
}
|
|
8857
9179
|
}
|
|
8858
|
-
async function
|
|
9180
|
+
async function listScoresBySpan(c2) {
|
|
8859
9181
|
const mastra = c2.get("mastra");
|
|
8860
9182
|
const traceId = c2.req.param("traceId");
|
|
8861
9183
|
const spanId = c2.req.param("spanId");
|
|
@@ -8863,7 +9185,7 @@ async function getScoresBySpan(c2) {
|
|
|
8863
9185
|
const perPage = parseInt(c2.req.query("perPage") || "10");
|
|
8864
9186
|
const pagination = { page, perPage };
|
|
8865
9187
|
try {
|
|
8866
|
-
const scores = await
|
|
9188
|
+
const scores = await listScoresBySpan$1({
|
|
8867
9189
|
mastra,
|
|
8868
9190
|
traceId,
|
|
8869
9191
|
spanId,
|
|
@@ -8881,7 +9203,7 @@ function observabilityRouter() {
|
|
|
8881
9203
|
router.get(
|
|
8882
9204
|
"/traces",
|
|
8883
9205
|
w({
|
|
8884
|
-
description: "Get paginated list of
|
|
9206
|
+
description: "Get paginated list of traces",
|
|
8885
9207
|
tags: ["observability"],
|
|
8886
9208
|
parameters: [
|
|
8887
9209
|
{
|
|
@@ -8929,19 +9251,19 @@ function observabilityRouter() {
|
|
|
8929
9251
|
],
|
|
8930
9252
|
responses: {
|
|
8931
9253
|
200: {
|
|
8932
|
-
description: "Paginated list of
|
|
9254
|
+
description: "Paginated list of traces"
|
|
8933
9255
|
},
|
|
8934
9256
|
400: {
|
|
8935
9257
|
description: "Bad request - invalid parameters"
|
|
8936
9258
|
}
|
|
8937
9259
|
}
|
|
8938
9260
|
}),
|
|
8939
|
-
|
|
9261
|
+
getTracesPaginatedHandler
|
|
8940
9262
|
);
|
|
8941
9263
|
router.get(
|
|
8942
9264
|
"/traces/:traceId",
|
|
8943
9265
|
w({
|
|
8944
|
-
description: "Get a specific
|
|
9266
|
+
description: "Get a specific trace by ID",
|
|
8945
9267
|
tags: ["observability"],
|
|
8946
9268
|
parameters: [
|
|
8947
9269
|
{
|
|
@@ -8954,7 +9276,7 @@ function observabilityRouter() {
|
|
|
8954
9276
|
],
|
|
8955
9277
|
responses: {
|
|
8956
9278
|
200: {
|
|
8957
|
-
description: "
|
|
9279
|
+
description: "Trace with all its spans"
|
|
8958
9280
|
},
|
|
8959
9281
|
400: {
|
|
8960
9282
|
description: "Bad request - missing trace ID"
|
|
@@ -8964,7 +9286,7 @@ function observabilityRouter() {
|
|
|
8964
9286
|
}
|
|
8965
9287
|
}
|
|
8966
9288
|
}),
|
|
8967
|
-
|
|
9289
|
+
getTraceHandler
|
|
8968
9290
|
);
|
|
8969
9291
|
router.get(
|
|
8970
9292
|
"/traces/:traceId/:spanId/scores",
|
|
@@ -9007,7 +9329,7 @@ function observabilityRouter() {
|
|
|
9007
9329
|
}
|
|
9008
9330
|
}
|
|
9009
9331
|
}),
|
|
9010
|
-
|
|
9332
|
+
listScoresBySpan
|
|
9011
9333
|
);
|
|
9012
9334
|
router.post(
|
|
9013
9335
|
"/traces/score",
|
|
@@ -9130,36 +9452,36 @@ function observabilityRouter() {
|
|
|
9130
9452
|
);
|
|
9131
9453
|
return router;
|
|
9132
9454
|
}
|
|
9133
|
-
async function
|
|
9455
|
+
async function listScorersHandler(c2) {
|
|
9134
9456
|
try {
|
|
9135
|
-
const scorers = await
|
|
9457
|
+
const scorers = await listScorersHandler$1({
|
|
9136
9458
|
mastra: c2.get("mastra"),
|
|
9137
|
-
|
|
9459
|
+
requestContext: c2.get("requestContext")
|
|
9138
9460
|
});
|
|
9139
9461
|
return c2.json(scorers);
|
|
9140
9462
|
} catch (error) {
|
|
9141
|
-
return handleError(error, "Error
|
|
9463
|
+
return handleError(error, "Error listing scorers");
|
|
9142
9464
|
}
|
|
9143
9465
|
}
|
|
9144
9466
|
async function getScorerHandler(c2) {
|
|
9145
9467
|
const mastra = c2.get("mastra");
|
|
9146
9468
|
const scorerId = c2.req.param("scorerId");
|
|
9147
|
-
const
|
|
9469
|
+
const requestContext = c2.get("requestContext");
|
|
9148
9470
|
const scorer = await getScorerHandler$1({
|
|
9149
9471
|
mastra,
|
|
9150
9472
|
scorerId,
|
|
9151
|
-
|
|
9473
|
+
requestContext
|
|
9152
9474
|
});
|
|
9153
9475
|
return c2.json(scorer);
|
|
9154
9476
|
}
|
|
9155
|
-
async function
|
|
9477
|
+
async function listScoresByRunIdHandler(c2) {
|
|
9156
9478
|
const mastra = c2.get("mastra");
|
|
9157
9479
|
const runId = c2.req.param("runId");
|
|
9158
|
-
const page =
|
|
9159
|
-
const perPage =
|
|
9480
|
+
const page = parsePage(c2.req.query("page"));
|
|
9481
|
+
const perPage = parsePerPage(c2.req.query("perPage"), 10);
|
|
9160
9482
|
const pagination = { page, perPage };
|
|
9161
9483
|
try {
|
|
9162
|
-
const scores = await
|
|
9484
|
+
const scores = await listScoresByRunIdHandler$1({
|
|
9163
9485
|
mastra,
|
|
9164
9486
|
runId,
|
|
9165
9487
|
pagination
|
|
@@ -9169,16 +9491,16 @@ async function getScoresByRunIdHandler(c2) {
|
|
|
9169
9491
|
return handleError(error, "Error getting scores by run id");
|
|
9170
9492
|
}
|
|
9171
9493
|
}
|
|
9172
|
-
async function
|
|
9494
|
+
async function listScoresByScorerIdHandler(c2) {
|
|
9173
9495
|
const mastra = c2.get("mastra");
|
|
9174
9496
|
const scorerId = c2.req.param("scorerId");
|
|
9175
|
-
const page =
|
|
9176
|
-
const perPage =
|
|
9497
|
+
const page = parsePage(c2.req.query("page"));
|
|
9498
|
+
const perPage = parsePerPage(c2.req.query("perPage"), 10);
|
|
9177
9499
|
const entityId = c2.req.query("entityId");
|
|
9178
9500
|
const entityType = c2.req.query("entityType");
|
|
9179
9501
|
const pagination = { page, perPage };
|
|
9180
9502
|
try {
|
|
9181
|
-
const scores = await
|
|
9503
|
+
const scores = await listScoresByScorerIdHandler$1({
|
|
9182
9504
|
mastra,
|
|
9183
9505
|
scorerId,
|
|
9184
9506
|
pagination,
|
|
@@ -9190,15 +9512,15 @@ async function getScoresByScorerIdHandler(c2) {
|
|
|
9190
9512
|
return handleError(error, "Error getting scores by scorer id");
|
|
9191
9513
|
}
|
|
9192
9514
|
}
|
|
9193
|
-
async function
|
|
9515
|
+
async function listScoresByEntityIdHandler(c2) {
|
|
9194
9516
|
const mastra = c2.get("mastra");
|
|
9195
9517
|
const entityId = c2.req.param("entityId");
|
|
9196
9518
|
const entityType = c2.req.param("entityType");
|
|
9197
|
-
const page =
|
|
9198
|
-
const perPage =
|
|
9519
|
+
const page = parsePage(c2.req.query("page"));
|
|
9520
|
+
const perPage = parsePerPage(c2.req.query("perPage"), 10);
|
|
9199
9521
|
const pagination = { page, perPage };
|
|
9200
9522
|
try {
|
|
9201
|
-
const scores = await
|
|
9523
|
+
const scores = await listScoresByEntityIdHandler$1({
|
|
9202
9524
|
mastra,
|
|
9203
9525
|
entityId,
|
|
9204
9526
|
entityType,
|
|
@@ -9237,7 +9559,7 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9237
9559
|
}
|
|
9238
9560
|
}
|
|
9239
9561
|
}),
|
|
9240
|
-
|
|
9562
|
+
listScorersHandler
|
|
9241
9563
|
);
|
|
9242
9564
|
router.get(
|
|
9243
9565
|
"/scorers/:scorerId",
|
|
@@ -9285,7 +9607,7 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9285
9607
|
}
|
|
9286
9608
|
}
|
|
9287
9609
|
}),
|
|
9288
|
-
|
|
9610
|
+
listScoresByRunIdHandler
|
|
9289
9611
|
);
|
|
9290
9612
|
router.get(
|
|
9291
9613
|
"/scorer/:scorerId",
|
|
@@ -9320,7 +9642,7 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9320
9642
|
}
|
|
9321
9643
|
}
|
|
9322
9644
|
}),
|
|
9323
|
-
|
|
9645
|
+
listScoresByScorerIdHandler
|
|
9324
9646
|
);
|
|
9325
9647
|
router.get(
|
|
9326
9648
|
"/entity/:entityType/:entityId",
|
|
@@ -9363,7 +9685,7 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9363
9685
|
}
|
|
9364
9686
|
}
|
|
9365
9687
|
}),
|
|
9366
|
-
|
|
9688
|
+
listScoresByEntityIdHandler
|
|
9367
9689
|
);
|
|
9368
9690
|
router.post(
|
|
9369
9691
|
"/",
|
|
@@ -9389,7 +9711,7 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9389
9711
|
entity: { type: "object" },
|
|
9390
9712
|
metadata: { type: "object" },
|
|
9391
9713
|
additionalLLMContext: { type: "object" },
|
|
9392
|
-
|
|
9714
|
+
requestContext: { type: "object" },
|
|
9393
9715
|
resourceId: { type: "string" },
|
|
9394
9716
|
threadId: { type: "string" },
|
|
9395
9717
|
traceId: { type: "string" }
|
|
@@ -9412,73 +9734,6 @@ function scoresRouter(bodyLimitOptions) {
|
|
|
9412
9734
|
);
|
|
9413
9735
|
return router;
|
|
9414
9736
|
}
|
|
9415
|
-
async function getTelemetryHandler(c2) {
|
|
9416
|
-
try {
|
|
9417
|
-
const mastra = c2.get("mastra");
|
|
9418
|
-
const { name, scope, page, perPage, fromDate, toDate } = c2.req.query();
|
|
9419
|
-
const attribute = c2.req.queries("attribute");
|
|
9420
|
-
const traces = await getTelemetryHandler$1({
|
|
9421
|
-
mastra,
|
|
9422
|
-
body: {
|
|
9423
|
-
name,
|
|
9424
|
-
scope,
|
|
9425
|
-
page: Number(page ?? 0),
|
|
9426
|
-
perPage: Number(perPage ?? 100),
|
|
9427
|
-
attribute,
|
|
9428
|
-
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
9429
|
-
toDate: toDate ? new Date(toDate) : void 0
|
|
9430
|
-
}
|
|
9431
|
-
});
|
|
9432
|
-
return c2.json({ traces });
|
|
9433
|
-
} catch (error) {
|
|
9434
|
-
return handleError(error, "Error getting telemetry traces");
|
|
9435
|
-
}
|
|
9436
|
-
}
|
|
9437
|
-
async function storeTelemetryHandler(c2) {
|
|
9438
|
-
try {
|
|
9439
|
-
const body = await c2.req.json();
|
|
9440
|
-
const mastra = c2.get("mastra");
|
|
9441
|
-
const result = await storeTelemetryHandler$1({ mastra, body });
|
|
9442
|
-
if (result.status === "error") {
|
|
9443
|
-
return c2.json(result, 500);
|
|
9444
|
-
}
|
|
9445
|
-
return c2.json(result, 200);
|
|
9446
|
-
} catch (error) {
|
|
9447
|
-
return handleError(error, "Error storing telemetry traces");
|
|
9448
|
-
}
|
|
9449
|
-
}
|
|
9450
|
-
|
|
9451
|
-
// src/server/handlers/routes/telemetry/router.ts
|
|
9452
|
-
function telemetryRouter() {
|
|
9453
|
-
const router = new Hono();
|
|
9454
|
-
router.get(
|
|
9455
|
-
"/",
|
|
9456
|
-
w({
|
|
9457
|
-
description: "Get all traces",
|
|
9458
|
-
tags: ["telemetry"],
|
|
9459
|
-
responses: {
|
|
9460
|
-
200: {
|
|
9461
|
-
description: "List of all traces (paged)"
|
|
9462
|
-
}
|
|
9463
|
-
}
|
|
9464
|
-
}),
|
|
9465
|
-
getTelemetryHandler
|
|
9466
|
-
);
|
|
9467
|
-
router.post(
|
|
9468
|
-
"/",
|
|
9469
|
-
w({
|
|
9470
|
-
description: "Store telemetry",
|
|
9471
|
-
tags: ["telemetry"],
|
|
9472
|
-
responses: {
|
|
9473
|
-
200: {
|
|
9474
|
-
description: "Traces stored"
|
|
9475
|
-
}
|
|
9476
|
-
}
|
|
9477
|
-
}),
|
|
9478
|
-
storeTelemetryHandler
|
|
9479
|
-
);
|
|
9480
|
-
return router;
|
|
9481
|
-
}
|
|
9482
9737
|
function toolsRouter(bodyLimitOptions, tools) {
|
|
9483
9738
|
const router = new Hono();
|
|
9484
9739
|
router.get(
|
|
@@ -9492,7 +9747,7 @@ function toolsRouter(bodyLimitOptions, tools) {
|
|
|
9492
9747
|
}
|
|
9493
9748
|
}
|
|
9494
9749
|
}),
|
|
9495
|
-
|
|
9750
|
+
listToolsHandler
|
|
9496
9751
|
);
|
|
9497
9752
|
router.get(
|
|
9498
9753
|
"/:toolId",
|
|
@@ -9546,7 +9801,7 @@ function toolsRouter(bodyLimitOptions, tools) {
|
|
|
9546
9801
|
type: "object",
|
|
9547
9802
|
properties: {
|
|
9548
9803
|
data: { type: "object" },
|
|
9549
|
-
|
|
9804
|
+
requestContext: { type: "object" }
|
|
9550
9805
|
},
|
|
9551
9806
|
required: ["data"]
|
|
9552
9807
|
}
|
|
@@ -9880,10 +10135,10 @@ function vectorRouter(bodyLimitOptions) {
|
|
|
9880
10135
|
);
|
|
9881
10136
|
return router;
|
|
9882
10137
|
}
|
|
9883
|
-
async function
|
|
10138
|
+
async function listWorkflowsHandler(c2) {
|
|
9884
10139
|
try {
|
|
9885
10140
|
const mastra = c2.get("mastra");
|
|
9886
|
-
const workflows = await
|
|
10141
|
+
const workflows = await listWorkflowsHandler$1({
|
|
9887
10142
|
mastra
|
|
9888
10143
|
});
|
|
9889
10144
|
return c2.json(workflows);
|
|
@@ -9922,13 +10177,13 @@ async function createWorkflowRunHandler(c2) {
|
|
|
9922
10177
|
async function startAsyncWorkflowHandler(c2) {
|
|
9923
10178
|
try {
|
|
9924
10179
|
const mastra = c2.get("mastra");
|
|
9925
|
-
const
|
|
10180
|
+
const requestContext = c2.get("requestContext");
|
|
9926
10181
|
const workflowId = c2.req.param("workflowId");
|
|
9927
10182
|
const { inputData, tracingOptions } = await c2.req.json();
|
|
9928
10183
|
const runId = c2.req.query("runId");
|
|
9929
10184
|
const result = await startAsyncWorkflowHandler$1({
|
|
9930
10185
|
mastra,
|
|
9931
|
-
|
|
10186
|
+
requestContext,
|
|
9932
10187
|
workflowId,
|
|
9933
10188
|
runId,
|
|
9934
10189
|
inputData,
|
|
@@ -9942,13 +10197,13 @@ async function startAsyncWorkflowHandler(c2) {
|
|
|
9942
10197
|
async function startWorkflowRunHandler(c2) {
|
|
9943
10198
|
try {
|
|
9944
10199
|
const mastra = c2.get("mastra");
|
|
9945
|
-
const
|
|
10200
|
+
const requestContext = c2.get("requestContext");
|
|
9946
10201
|
const workflowId = c2.req.param("workflowId");
|
|
9947
10202
|
const { inputData, tracingOptions } = await c2.req.json();
|
|
9948
10203
|
const runId = c2.req.query("runId");
|
|
9949
10204
|
await startWorkflowRunHandler$1({
|
|
9950
10205
|
mastra,
|
|
9951
|
-
|
|
10206
|
+
requestContext,
|
|
9952
10207
|
workflowId,
|
|
9953
10208
|
runId,
|
|
9954
10209
|
inputData,
|
|
@@ -9959,49 +10214,10 @@ async function startWorkflowRunHandler(c2) {
|
|
|
9959
10214
|
return handleError(e2, "Error starting workflow run");
|
|
9960
10215
|
}
|
|
9961
10216
|
}
|
|
9962
|
-
function watchWorkflowHandler(c2) {
|
|
9963
|
-
try {
|
|
9964
|
-
const mastra = c2.get("mastra");
|
|
9965
|
-
const logger2 = mastra.getLogger();
|
|
9966
|
-
const workflowId = c2.req.param("workflowId");
|
|
9967
|
-
const runId = c2.req.query("runId");
|
|
9968
|
-
if (!runId) {
|
|
9969
|
-
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
9970
|
-
}
|
|
9971
|
-
c2.header("Transfer-Encoding", "chunked");
|
|
9972
|
-
return stream(
|
|
9973
|
-
c2,
|
|
9974
|
-
async (stream6) => {
|
|
9975
|
-
try {
|
|
9976
|
-
const result = await watchWorkflowHandler$1({
|
|
9977
|
-
mastra,
|
|
9978
|
-
workflowId,
|
|
9979
|
-
runId
|
|
9980
|
-
});
|
|
9981
|
-
const reader = result.getReader();
|
|
9982
|
-
stream6.onAbort(() => {
|
|
9983
|
-
void reader.cancel("request aborted");
|
|
9984
|
-
});
|
|
9985
|
-
let chunkResult;
|
|
9986
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
9987
|
-
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
9988
|
-
}
|
|
9989
|
-
} catch (err) {
|
|
9990
|
-
logger2.error("Error in watch stream: " + (err?.message ?? "Unknown error"));
|
|
9991
|
-
}
|
|
9992
|
-
},
|
|
9993
|
-
async (err) => {
|
|
9994
|
-
logger2.error("Error in watch stream: " + err?.message);
|
|
9995
|
-
}
|
|
9996
|
-
);
|
|
9997
|
-
} catch (error) {
|
|
9998
|
-
return handleError(error, "Error watching workflow");
|
|
9999
|
-
}
|
|
10000
|
-
}
|
|
10001
10217
|
async function streamVNextWorkflowHandler(c2) {
|
|
10002
10218
|
try {
|
|
10003
10219
|
const mastra = c2.get("mastra");
|
|
10004
|
-
const
|
|
10220
|
+
const requestContext = c2.get("requestContext");
|
|
10005
10221
|
const logger2 = mastra.getLogger();
|
|
10006
10222
|
const workflowId = c2.req.param("workflowId");
|
|
10007
10223
|
const { inputData, closeOnSuspend, tracingOptions } = await c2.req.json();
|
|
@@ -10009,24 +10225,24 @@ async function streamVNextWorkflowHandler(c2) {
|
|
|
10009
10225
|
c2.header("Transfer-Encoding", "chunked");
|
|
10010
10226
|
return stream(
|
|
10011
10227
|
c2,
|
|
10012
|
-
async (
|
|
10228
|
+
async (stream5) => {
|
|
10013
10229
|
try {
|
|
10014
10230
|
const result = await streamVNextWorkflowHandler$1({
|
|
10015
10231
|
mastra,
|
|
10016
10232
|
workflowId,
|
|
10017
10233
|
runId,
|
|
10018
10234
|
inputData,
|
|
10019
|
-
|
|
10235
|
+
requestContext,
|
|
10020
10236
|
closeOnSuspend,
|
|
10021
10237
|
tracingOptions
|
|
10022
10238
|
});
|
|
10023
10239
|
const reader = result.getReader();
|
|
10024
|
-
|
|
10240
|
+
stream5.onAbort(() => {
|
|
10025
10241
|
void reader.cancel("request aborted");
|
|
10026
10242
|
});
|
|
10027
10243
|
let chunkResult;
|
|
10028
10244
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10029
|
-
await
|
|
10245
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
10030
10246
|
}
|
|
10031
10247
|
} catch (err) {
|
|
10032
10248
|
logger2.error("Error in workflow stream: " + (err?.message ?? "Unknown error"));
|
|
@@ -10049,7 +10265,7 @@ async function observeStreamVNextWorkflowHandler(c2) {
|
|
|
10049
10265
|
c2.header("Transfer-Encoding", "chunked");
|
|
10050
10266
|
return stream(
|
|
10051
10267
|
c2,
|
|
10052
|
-
async (
|
|
10268
|
+
async (stream5) => {
|
|
10053
10269
|
try {
|
|
10054
10270
|
const result = await observeStreamVNextWorkflowHandler$1({
|
|
10055
10271
|
mastra,
|
|
@@ -10057,12 +10273,12 @@ async function observeStreamVNextWorkflowHandler(c2) {
|
|
|
10057
10273
|
runId
|
|
10058
10274
|
});
|
|
10059
10275
|
const reader = result.getReader();
|
|
10060
|
-
|
|
10276
|
+
stream5.onAbort(() => {
|
|
10061
10277
|
void reader.cancel("request aborted");
|
|
10062
10278
|
});
|
|
10063
10279
|
let chunkResult;
|
|
10064
10280
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10065
|
-
await
|
|
10281
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
10066
10282
|
}
|
|
10067
10283
|
} catch (err) {
|
|
10068
10284
|
logger2.error("Error in workflow observe stream: " + (err?.message ?? "Unknown error"));
|
|
@@ -10079,7 +10295,7 @@ async function observeStreamVNextWorkflowHandler(c2) {
|
|
|
10079
10295
|
async function streamLegacyWorkflowHandler(c2) {
|
|
10080
10296
|
try {
|
|
10081
10297
|
const mastra = c2.get("mastra");
|
|
10082
|
-
const
|
|
10298
|
+
const requestContext = c2.get("requestContext");
|
|
10083
10299
|
const logger2 = mastra.getLogger();
|
|
10084
10300
|
const workflowId = c2.req.param("workflowId");
|
|
10085
10301
|
const { inputData, tracingOptions } = await c2.req.json();
|
|
@@ -10087,28 +10303,28 @@ async function streamLegacyWorkflowHandler(c2) {
|
|
|
10087
10303
|
c2.header("Transfer-Encoding", "chunked");
|
|
10088
10304
|
return stream(
|
|
10089
10305
|
c2,
|
|
10090
|
-
async (
|
|
10306
|
+
async (stream5) => {
|
|
10091
10307
|
try {
|
|
10092
10308
|
const result = await streamLegacyWorkflowHandler$1({
|
|
10093
10309
|
mastra,
|
|
10094
10310
|
workflowId,
|
|
10095
10311
|
runId,
|
|
10096
10312
|
inputData,
|
|
10097
|
-
|
|
10313
|
+
requestContext,
|
|
10098
10314
|
tracingOptions
|
|
10099
10315
|
});
|
|
10100
10316
|
const reader = result.stream.getReader();
|
|
10101
|
-
|
|
10317
|
+
stream5.onAbort(() => {
|
|
10102
10318
|
void reader.cancel("request aborted");
|
|
10103
10319
|
});
|
|
10104
10320
|
let chunkResult;
|
|
10105
10321
|
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10106
|
-
await
|
|
10322
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
10107
10323
|
}
|
|
10108
10324
|
} catch (err) {
|
|
10109
10325
|
logger2.error("Error in workflow stream: " + (err?.message ?? "Unknown error"));
|
|
10110
10326
|
}
|
|
10111
|
-
await
|
|
10327
|
+
await stream5.close();
|
|
10112
10328
|
},
|
|
10113
10329
|
async (err) => {
|
|
10114
10330
|
logger2.error("Error in workflow stream: " + err?.message);
|
|
@@ -10130,684 +10346,189 @@ async function observeStreamLegacyWorkflowHandler(c2) {
|
|
|
10130
10346
|
c2.header("Transfer-Encoding", "chunked");
|
|
10131
10347
|
return stream(
|
|
10132
10348
|
c2,
|
|
10133
|
-
async (
|
|
10134
|
-
try {
|
|
10135
|
-
const result = await observeStreamLegacyWorkflowHandler$1({
|
|
10136
|
-
mastra,
|
|
10137
|
-
workflowId,
|
|
10138
|
-
runId
|
|
10139
|
-
});
|
|
10140
|
-
const reader = result.getReader();
|
|
10141
|
-
|
|
10142
|
-
void reader.cancel("request aborted");
|
|
10143
|
-
});
|
|
10144
|
-
let chunkResult;
|
|
10145
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10146
|
-
await
|
|
10147
|
-
}
|
|
10148
|
-
} catch (err) {
|
|
10149
|
-
logger2.error("Error in workflow observe stream: " + (err?.message ?? "Unknown error"));
|
|
10150
|
-
}
|
|
10151
|
-
await stream6.close();
|
|
10152
|
-
},
|
|
10153
|
-
async (err) => {
|
|
10154
|
-
logger2.error("Error in workflow observe stream: " + err?.message);
|
|
10155
|
-
}
|
|
10156
|
-
);
|
|
10157
|
-
} catch (error) {
|
|
10158
|
-
return handleError(error, "Error observing workflow stream");
|
|
10159
|
-
}
|
|
10160
|
-
}
|
|
10161
|
-
async function resumeStreamWorkflowHandler(c2) {
|
|
10162
|
-
try {
|
|
10163
|
-
const mastra = c2.get("mastra");
|
|
10164
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10165
|
-
const logger2 = mastra.getLogger();
|
|
10166
|
-
const workflowId = c2.req.param("workflowId");
|
|
10167
|
-
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10168
|
-
const runId = c2.req.query("runId");
|
|
10169
|
-
c2.header("Transfer-Encoding", "chunked");
|
|
10170
|
-
return stream(
|
|
10171
|
-
c2,
|
|
10172
|
-
async (stream6) => {
|
|
10173
|
-
try {
|
|
10174
|
-
const result = await resumeStreamWorkflowHandler$1({
|
|
10175
|
-
mastra,
|
|
10176
|
-
workflowId,
|
|
10177
|
-
runId,
|
|
10178
|
-
body: { step, resumeData },
|
|
10179
|
-
runtimeContext,
|
|
10180
|
-
tracingOptions
|
|
10181
|
-
});
|
|
10182
|
-
const reader = result.getReader();
|
|
10183
|
-
stream6.onAbort(() => {
|
|
10184
|
-
void reader.cancel("request aborted");
|
|
10185
|
-
});
|
|
10186
|
-
let chunkResult;
|
|
10187
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10188
|
-
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
10189
|
-
}
|
|
10190
|
-
} catch (err) {
|
|
10191
|
-
logger2.error("Error in workflow VNext stream: " + (err?.message ?? "Unknown error"));
|
|
10192
|
-
}
|
|
10193
|
-
},
|
|
10194
|
-
async (err) => {
|
|
10195
|
-
logger2.error("Error in workflow VNext stream: " + err?.message);
|
|
10196
|
-
}
|
|
10197
|
-
);
|
|
10198
|
-
} catch (error) {
|
|
10199
|
-
return handleError(error, "Error streaming workflow");
|
|
10200
|
-
}
|
|
10201
|
-
}
|
|
10202
|
-
async function resumeAsyncWorkflowHandler(c2) {
|
|
10203
|
-
try {
|
|
10204
|
-
const mastra = c2.get("mastra");
|
|
10205
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10206
|
-
const workflowId = c2.req.param("workflowId");
|
|
10207
|
-
const runId = c2.req.query("runId");
|
|
10208
|
-
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10209
|
-
if (!runId) {
|
|
10210
|
-
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
10211
|
-
}
|
|
10212
|
-
const result = await resumeAsyncWorkflowHandler$1({
|
|
10213
|
-
mastra,
|
|
10214
|
-
runtimeContext,
|
|
10215
|
-
workflowId,
|
|
10216
|
-
runId,
|
|
10217
|
-
body: { step, resumeData },
|
|
10218
|
-
tracingOptions
|
|
10219
|
-
});
|
|
10220
|
-
return c2.json(result);
|
|
10221
|
-
} catch (error) {
|
|
10222
|
-
return handleError(error, "Error resuming workflow step");
|
|
10223
|
-
}
|
|
10224
|
-
}
|
|
10225
|
-
async function resumeWorkflowHandler(c2) {
|
|
10226
|
-
try {
|
|
10227
|
-
const mastra = c2.get("mastra");
|
|
10228
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10229
|
-
const workflowId = c2.req.param("workflowId");
|
|
10230
|
-
const runId = c2.req.query("runId");
|
|
10231
|
-
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10232
|
-
if (!runId) {
|
|
10233
|
-
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
10234
|
-
}
|
|
10235
|
-
await resumeWorkflowHandler$1({
|
|
10236
|
-
mastra,
|
|
10237
|
-
runtimeContext,
|
|
10238
|
-
workflowId,
|
|
10239
|
-
runId,
|
|
10240
|
-
body: { step, resumeData },
|
|
10241
|
-
tracingOptions
|
|
10242
|
-
});
|
|
10243
|
-
return c2.json({ message: "Workflow run resumed" });
|
|
10244
|
-
} catch (error) {
|
|
10245
|
-
return handleError(error, "Error resuming workflow");
|
|
10246
|
-
}
|
|
10247
|
-
}
|
|
10248
|
-
async function getWorkflowRunsHandler(c2) {
|
|
10249
|
-
try {
|
|
10250
|
-
const mastra = c2.get("mastra");
|
|
10251
|
-
const workflowId = c2.req.param("workflowId");
|
|
10252
|
-
const { fromDate, toDate, limit, offset, resourceId } = c2.req.query();
|
|
10253
|
-
const workflowRuns = await getWorkflowRunsHandler$1({
|
|
10254
|
-
mastra,
|
|
10255
|
-
workflowId,
|
|
10256
|
-
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
10257
|
-
toDate: toDate ? new Date(toDate) : void 0,
|
|
10258
|
-
limit: limit ? Number(limit) : void 0,
|
|
10259
|
-
offset: offset ? Number(offset) : void 0,
|
|
10260
|
-
resourceId
|
|
10261
|
-
});
|
|
10262
|
-
return c2.json(workflowRuns);
|
|
10263
|
-
} catch (error) {
|
|
10264
|
-
return handleError(error, "Error getting workflow runs");
|
|
10265
|
-
}
|
|
10266
|
-
}
|
|
10267
|
-
async function getWorkflowRunByIdHandler(c2) {
|
|
10268
|
-
try {
|
|
10269
|
-
const mastra = c2.get("mastra");
|
|
10270
|
-
const workflowId = c2.req.param("workflowId");
|
|
10271
|
-
const runId = c2.req.param("runId");
|
|
10272
|
-
const workflowRun = await getWorkflowRunByIdHandler$1({
|
|
10273
|
-
mastra,
|
|
10274
|
-
workflowId,
|
|
10275
|
-
runId
|
|
10276
|
-
});
|
|
10277
|
-
return c2.json(workflowRun);
|
|
10278
|
-
} catch (error) {
|
|
10279
|
-
return handleError(error, "Error getting workflow run");
|
|
10280
|
-
}
|
|
10281
|
-
}
|
|
10282
|
-
async function getWorkflowRunExecutionResultHandler(c2) {
|
|
10283
|
-
try {
|
|
10284
|
-
const mastra = c2.get("mastra");
|
|
10285
|
-
const workflowId = c2.req.param("workflowId");
|
|
10286
|
-
const runId = c2.req.param("runId");
|
|
10287
|
-
const workflowRunExecutionResult = await getWorkflowRunExecutionResultHandler$1({
|
|
10288
|
-
mastra,
|
|
10289
|
-
workflowId,
|
|
10290
|
-
runId
|
|
10291
|
-
});
|
|
10292
|
-
return c2.json(workflowRunExecutionResult);
|
|
10293
|
-
} catch (error) {
|
|
10294
|
-
return handleError(error, "Error getting workflow run execution result");
|
|
10295
|
-
}
|
|
10296
|
-
}
|
|
10297
|
-
async function cancelWorkflowRunHandler(c2) {
|
|
10298
|
-
try {
|
|
10299
|
-
const mastra = c2.get("mastra");
|
|
10300
|
-
const workflowId = c2.req.param("workflowId");
|
|
10301
|
-
const runId = c2.req.param("runId");
|
|
10302
|
-
const result = await cancelWorkflowRunHandler$1({
|
|
10303
|
-
mastra,
|
|
10304
|
-
workflowId,
|
|
10305
|
-
runId
|
|
10306
|
-
});
|
|
10307
|
-
return c2.json(result);
|
|
10308
|
-
} catch (error) {
|
|
10309
|
-
return handleError(error, "Error canceling workflow run");
|
|
10310
|
-
}
|
|
10311
|
-
}
|
|
10312
|
-
async function sendWorkflowRunEventHandler(c2) {
|
|
10313
|
-
try {
|
|
10314
|
-
const mastra = c2.get("mastra");
|
|
10315
|
-
const workflowId = c2.req.param("workflowId");
|
|
10316
|
-
const runId = c2.req.param("runId");
|
|
10317
|
-
const { event, data } = await c2.req.json();
|
|
10318
|
-
const result = await sendWorkflowRunEventHandler$1({
|
|
10319
|
-
mastra,
|
|
10320
|
-
workflowId,
|
|
10321
|
-
runId,
|
|
10322
|
-
event,
|
|
10323
|
-
data
|
|
10324
|
-
});
|
|
10325
|
-
return c2.json(result);
|
|
10326
|
-
} catch (error) {
|
|
10327
|
-
return handleError(error, "Error sending workflow run event");
|
|
10328
|
-
}
|
|
10329
|
-
}
|
|
10330
|
-
async function getLegacyWorkflowsHandler(c2) {
|
|
10331
|
-
try {
|
|
10332
|
-
const mastra = c2.get("mastra");
|
|
10333
|
-
const workflows = await getLegacyWorkflowsHandler$1({
|
|
10334
|
-
mastra
|
|
10335
|
-
});
|
|
10336
|
-
return c2.json(workflows);
|
|
10337
|
-
} catch (error) {
|
|
10338
|
-
return handleError(error, "Error getting workflows");
|
|
10339
|
-
}
|
|
10340
|
-
}
|
|
10341
|
-
async function getLegacyWorkflowByIdHandler(c2) {
|
|
10342
|
-
try {
|
|
10343
|
-
const mastra = c2.get("mastra");
|
|
10344
|
-
const workflowId = c2.req.param("workflowId");
|
|
10345
|
-
const workflow = await getLegacyWorkflowByIdHandler$1({
|
|
10346
|
-
mastra,
|
|
10347
|
-
workflowId
|
|
10348
|
-
});
|
|
10349
|
-
return c2.json(workflow);
|
|
10350
|
-
} catch (error) {
|
|
10351
|
-
return handleError(error, "Error getting workflow");
|
|
10352
|
-
}
|
|
10353
|
-
}
|
|
10354
|
-
async function startAsyncLegacyWorkflowHandler(c2) {
|
|
10355
|
-
try {
|
|
10356
|
-
const mastra = c2.get("mastra");
|
|
10357
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10358
|
-
const workflowId = c2.req.param("workflowId");
|
|
10359
|
-
const triggerData = await c2.req.json();
|
|
10360
|
-
const runId = c2.req.query("runId");
|
|
10361
|
-
const result = await startAsyncLegacyWorkflowHandler$1({
|
|
10362
|
-
mastra,
|
|
10363
|
-
runtimeContext,
|
|
10364
|
-
workflowId,
|
|
10365
|
-
runId,
|
|
10366
|
-
triggerData
|
|
10367
|
-
});
|
|
10368
|
-
return c2.json(result);
|
|
10369
|
-
} catch (error) {
|
|
10370
|
-
return handleError(error, "Error executing workflow");
|
|
10371
|
-
}
|
|
10372
|
-
}
|
|
10373
|
-
async function createLegacyWorkflowRunHandler(c2) {
|
|
10374
|
-
try {
|
|
10375
|
-
const mastra = c2.get("mastra");
|
|
10376
|
-
const workflowId = c2.req.param("workflowId");
|
|
10377
|
-
const prevRunId = c2.req.query("runId");
|
|
10378
|
-
const result = await createLegacyWorkflowRunHandler$1({
|
|
10379
|
-
mastra,
|
|
10380
|
-
workflowId,
|
|
10381
|
-
runId: prevRunId
|
|
10382
|
-
});
|
|
10383
|
-
return c2.json(result);
|
|
10384
|
-
} catch (e2) {
|
|
10385
|
-
return handleError(e2, "Error creating run");
|
|
10386
|
-
}
|
|
10387
|
-
}
|
|
10388
|
-
async function startLegacyWorkflowRunHandler(c2) {
|
|
10389
|
-
try {
|
|
10390
|
-
const mastra = c2.get("mastra");
|
|
10391
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10392
|
-
const workflowId = c2.req.param("workflowId");
|
|
10393
|
-
const triggerData = await c2.req.json();
|
|
10394
|
-
const runId = c2.req.query("runId");
|
|
10395
|
-
await startLegacyWorkflowRunHandler$1({
|
|
10396
|
-
mastra,
|
|
10397
|
-
runtimeContext,
|
|
10398
|
-
workflowId,
|
|
10399
|
-
runId,
|
|
10400
|
-
triggerData
|
|
10401
|
-
});
|
|
10402
|
-
return c2.json({ message: "Workflow run started" });
|
|
10403
|
-
} catch (e2) {
|
|
10404
|
-
return handleError(e2, "Error starting workflow run");
|
|
10405
|
-
}
|
|
10406
|
-
}
|
|
10407
|
-
function watchLegacyWorkflowHandler(c2) {
|
|
10408
|
-
try {
|
|
10409
|
-
const mastra = c2.get("mastra");
|
|
10410
|
-
const logger2 = mastra.getLogger();
|
|
10411
|
-
const workflowId = c2.req.param("workflowId");
|
|
10412
|
-
const runId = c2.req.query("runId");
|
|
10413
|
-
if (!runId) {
|
|
10414
|
-
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
10415
|
-
}
|
|
10416
|
-
return stream(
|
|
10417
|
-
c2,
|
|
10418
|
-
async (stream6) => {
|
|
10419
|
-
try {
|
|
10420
|
-
const result = await watchLegacyWorkflowHandler$1({
|
|
10421
|
-
mastra,
|
|
10422
|
-
workflowId,
|
|
10423
|
-
runId
|
|
10424
|
-
});
|
|
10425
|
-
stream6.onAbort(() => {
|
|
10426
|
-
if (!result.locked) {
|
|
10427
|
-
return result.cancel();
|
|
10428
|
-
}
|
|
10429
|
-
});
|
|
10430
|
-
for await (const chunk of result) {
|
|
10431
|
-
await stream6.write(chunk.toString() + "");
|
|
10432
|
-
}
|
|
10433
|
-
} catch (err) {
|
|
10434
|
-
console.error(err);
|
|
10435
|
-
}
|
|
10436
|
-
},
|
|
10437
|
-
async (err) => {
|
|
10438
|
-
logger2.error("Error in watch stream: " + err?.message);
|
|
10439
|
-
}
|
|
10440
|
-
);
|
|
10441
|
-
} catch (error) {
|
|
10442
|
-
return handleError(error, "Error watching workflow");
|
|
10443
|
-
}
|
|
10444
|
-
}
|
|
10445
|
-
async function resumeAsyncLegacyWorkflowHandler(c2) {
|
|
10446
|
-
try {
|
|
10447
|
-
const mastra = c2.get("mastra");
|
|
10448
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10449
|
-
const workflowId = c2.req.param("workflowId");
|
|
10450
|
-
const runId = c2.req.query("runId");
|
|
10451
|
-
const { stepId, context } = await c2.req.json();
|
|
10452
|
-
if (!runId) {
|
|
10453
|
-
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
10454
|
-
}
|
|
10455
|
-
const result = await resumeAsyncLegacyWorkflowHandler$1({
|
|
10456
|
-
mastra,
|
|
10457
|
-
runtimeContext,
|
|
10458
|
-
workflowId,
|
|
10459
|
-
runId,
|
|
10460
|
-
body: { stepId, context }
|
|
10461
|
-
});
|
|
10462
|
-
return c2.json(result);
|
|
10463
|
-
} catch (error) {
|
|
10464
|
-
return handleError(error, "Error resuming workflow step");
|
|
10465
|
-
}
|
|
10466
|
-
}
|
|
10467
|
-
async function resumeLegacyWorkflowHandler(c2) {
|
|
10468
|
-
try {
|
|
10469
|
-
const mastra = c2.get("mastra");
|
|
10470
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
10471
|
-
const workflowId = c2.req.param("workflowId");
|
|
10472
|
-
const runId = c2.req.query("runId");
|
|
10473
|
-
const { stepId, context } = await c2.req.json();
|
|
10474
|
-
if (!runId) {
|
|
10475
|
-
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
10476
|
-
}
|
|
10477
|
-
await resumeLegacyWorkflowHandler$1({
|
|
10478
|
-
mastra,
|
|
10479
|
-
runtimeContext,
|
|
10480
|
-
workflowId,
|
|
10481
|
-
runId,
|
|
10482
|
-
body: { stepId, context }
|
|
10483
|
-
});
|
|
10484
|
-
return c2.json({ message: "Workflow run resumed" });
|
|
10485
|
-
} catch (error) {
|
|
10486
|
-
return handleError(error, "Error resuming workflow");
|
|
10487
|
-
}
|
|
10488
|
-
}
|
|
10489
|
-
async function getLegacyWorkflowRunsHandler(c2) {
|
|
10490
|
-
try {
|
|
10491
|
-
const mastra = c2.get("mastra");
|
|
10492
|
-
const workflowId = c2.req.param("workflowId");
|
|
10493
|
-
const { fromDate, toDate, limit, offset, resourceId } = c2.req.query();
|
|
10494
|
-
const workflowRuns = await getLegacyWorkflowRunsHandler$1({
|
|
10495
|
-
mastra,
|
|
10496
|
-
workflowId,
|
|
10497
|
-
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
10498
|
-
toDate: toDate ? new Date(toDate) : void 0,
|
|
10499
|
-
limit: limit ? Number(limit) : void 0,
|
|
10500
|
-
offset: offset ? Number(offset) : void 0,
|
|
10501
|
-
resourceId
|
|
10502
|
-
});
|
|
10503
|
-
return c2.json(workflowRuns);
|
|
10504
|
-
} catch (error) {
|
|
10505
|
-
return handleError(error, "Error getting workflow runs");
|
|
10506
|
-
}
|
|
10507
|
-
}
|
|
10508
|
-
|
|
10509
|
-
// src/server/handlers/routes/workflows/router.ts
|
|
10510
|
-
function workflowsRouter(bodyLimitOptions) {
|
|
10511
|
-
const router = new Hono();
|
|
10512
|
-
router.get(
|
|
10513
|
-
"/legacy",
|
|
10514
|
-
w({
|
|
10515
|
-
description: "Get all legacy workflows",
|
|
10516
|
-
tags: ["legacyWorkflows"],
|
|
10517
|
-
responses: {
|
|
10518
|
-
200: {
|
|
10519
|
-
description: "List of all legacy workflows"
|
|
10520
|
-
}
|
|
10521
|
-
}
|
|
10522
|
-
}),
|
|
10523
|
-
getLegacyWorkflowsHandler
|
|
10524
|
-
);
|
|
10525
|
-
router.get(
|
|
10526
|
-
"/legacy/:workflowId",
|
|
10527
|
-
w({
|
|
10528
|
-
description: "Get legacy workflow by ID",
|
|
10529
|
-
tags: ["legacyWorkflows"],
|
|
10530
|
-
parameters: [
|
|
10531
|
-
{
|
|
10532
|
-
name: "workflowId",
|
|
10533
|
-
in: "path",
|
|
10534
|
-
required: true,
|
|
10535
|
-
schema: { type: "string" }
|
|
10536
|
-
}
|
|
10537
|
-
],
|
|
10538
|
-
responses: {
|
|
10539
|
-
200: {
|
|
10540
|
-
description: "Legacy Workflow details"
|
|
10541
|
-
},
|
|
10542
|
-
404: {
|
|
10543
|
-
description: "Legacy Workflow not found"
|
|
10544
|
-
}
|
|
10545
|
-
}
|
|
10546
|
-
}),
|
|
10547
|
-
getLegacyWorkflowByIdHandler
|
|
10548
|
-
);
|
|
10549
|
-
router.get(
|
|
10550
|
-
"/legacy/:workflowId/runs",
|
|
10551
|
-
w({
|
|
10552
|
-
description: "Get all runs for a legacy workflow",
|
|
10553
|
-
tags: ["legacyWorkflows"],
|
|
10554
|
-
parameters: [
|
|
10555
|
-
{
|
|
10556
|
-
name: "workflowId",
|
|
10557
|
-
in: "path",
|
|
10558
|
-
required: true,
|
|
10559
|
-
schema: { type: "string" }
|
|
10560
|
-
},
|
|
10561
|
-
{ name: "fromDate", in: "query", required: false, schema: { type: "string", format: "date-time" } },
|
|
10562
|
-
{ name: "toDate", in: "query", required: false, schema: { type: "string", format: "date-time" } },
|
|
10563
|
-
{ name: "limit", in: "query", required: false, schema: { type: "number" } },
|
|
10564
|
-
{ name: "offset", in: "query", required: false, schema: { type: "number" } },
|
|
10565
|
-
{ name: "resourceId", in: "query", required: false, schema: { type: "string" } }
|
|
10566
|
-
],
|
|
10567
|
-
responses: {
|
|
10568
|
-
200: {
|
|
10569
|
-
description: "List of legacy workflow runs from storage"
|
|
10570
|
-
}
|
|
10571
|
-
}
|
|
10572
|
-
}),
|
|
10573
|
-
getLegacyWorkflowRunsHandler
|
|
10574
|
-
);
|
|
10575
|
-
router.post(
|
|
10576
|
-
"/legacy/:workflowId/resume",
|
|
10577
|
-
w({
|
|
10578
|
-
description: "Resume a suspended legacy workflow step",
|
|
10579
|
-
tags: ["legacyWorkflows"],
|
|
10580
|
-
parameters: [
|
|
10581
|
-
{
|
|
10582
|
-
name: "workflowId",
|
|
10583
|
-
in: "path",
|
|
10584
|
-
required: true,
|
|
10585
|
-
schema: { type: "string" }
|
|
10586
|
-
},
|
|
10587
|
-
{
|
|
10588
|
-
name: "runId",
|
|
10589
|
-
in: "query",
|
|
10590
|
-
required: true,
|
|
10591
|
-
schema: { type: "string" }
|
|
10592
|
-
}
|
|
10593
|
-
],
|
|
10594
|
-
requestBody: {
|
|
10595
|
-
required: true,
|
|
10596
|
-
content: {
|
|
10597
|
-
"application/json": {
|
|
10598
|
-
schema: {
|
|
10599
|
-
type: "object",
|
|
10600
|
-
properties: {
|
|
10601
|
-
stepId: { type: "string" },
|
|
10602
|
-
context: { type: "object" },
|
|
10603
|
-
tracingOptions: {
|
|
10604
|
-
type: "object",
|
|
10605
|
-
description: "Tracing options for the workflow execution",
|
|
10606
|
-
properties: {
|
|
10607
|
-
metadata: {
|
|
10608
|
-
type: "object",
|
|
10609
|
-
description: "Custom metadata to attach to the trace",
|
|
10610
|
-
additionalProperties: true
|
|
10611
|
-
}
|
|
10612
|
-
}
|
|
10613
|
-
}
|
|
10614
|
-
}
|
|
10615
|
-
}
|
|
10616
|
-
}
|
|
10617
|
-
}
|
|
10618
|
-
}
|
|
10619
|
-
}),
|
|
10620
|
-
resumeLegacyWorkflowHandler
|
|
10621
|
-
);
|
|
10622
|
-
router.post(
|
|
10623
|
-
"/legacy/:workflowId/resume-async",
|
|
10624
|
-
bodyLimit(bodyLimitOptions),
|
|
10625
|
-
w({
|
|
10626
|
-
description: "Resume a suspended legacy workflow step",
|
|
10627
|
-
tags: ["legacyWorkflows"],
|
|
10628
|
-
parameters: [
|
|
10629
|
-
{
|
|
10630
|
-
name: "workflowId",
|
|
10631
|
-
in: "path",
|
|
10632
|
-
required: true,
|
|
10633
|
-
schema: { type: "string" }
|
|
10634
|
-
},
|
|
10635
|
-
{
|
|
10636
|
-
name: "runId",
|
|
10637
|
-
in: "query",
|
|
10638
|
-
required: true,
|
|
10639
|
-
schema: { type: "string" }
|
|
10640
|
-
}
|
|
10641
|
-
],
|
|
10642
|
-
requestBody: {
|
|
10643
|
-
required: true,
|
|
10644
|
-
content: {
|
|
10645
|
-
"application/json": {
|
|
10646
|
-
schema: {
|
|
10647
|
-
type: "object",
|
|
10648
|
-
properties: {
|
|
10649
|
-
stepId: { type: "string" },
|
|
10650
|
-
context: { type: "object" },
|
|
10651
|
-
tracingOptions: {
|
|
10652
|
-
type: "object",
|
|
10653
|
-
description: "Tracing options for the workflow execution",
|
|
10654
|
-
properties: {
|
|
10655
|
-
metadata: {
|
|
10656
|
-
type: "object",
|
|
10657
|
-
description: "Custom metadata to attach to the trace",
|
|
10658
|
-
additionalProperties: true
|
|
10659
|
-
}
|
|
10660
|
-
}
|
|
10661
|
-
}
|
|
10662
|
-
}
|
|
10663
|
-
}
|
|
10664
|
-
}
|
|
10665
|
-
}
|
|
10666
|
-
}
|
|
10667
|
-
}),
|
|
10668
|
-
resumeAsyncLegacyWorkflowHandler
|
|
10669
|
-
);
|
|
10670
|
-
router.post(
|
|
10671
|
-
"/legacy/:workflowId/create-run",
|
|
10672
|
-
w({
|
|
10673
|
-
description: "Create a new legacy workflow run",
|
|
10674
|
-
tags: ["legacyWorkflows"],
|
|
10675
|
-
parameters: [
|
|
10676
|
-
{
|
|
10677
|
-
name: "workflowId",
|
|
10678
|
-
in: "path",
|
|
10679
|
-
required: true,
|
|
10680
|
-
schema: { type: "string" }
|
|
10681
|
-
},
|
|
10682
|
-
{
|
|
10683
|
-
name: "runId",
|
|
10684
|
-
in: "query",
|
|
10685
|
-
required: false,
|
|
10686
|
-
schema: { type: "string" }
|
|
10687
|
-
}
|
|
10688
|
-
],
|
|
10689
|
-
responses: {
|
|
10690
|
-
200: {
|
|
10691
|
-
description: "New legacy workflow run created"
|
|
10692
|
-
}
|
|
10693
|
-
}
|
|
10694
|
-
}),
|
|
10695
|
-
createLegacyWorkflowRunHandler
|
|
10696
|
-
);
|
|
10697
|
-
router.post(
|
|
10698
|
-
"/legacy/:workflowId/start-async",
|
|
10699
|
-
bodyLimit(bodyLimitOptions),
|
|
10700
|
-
w({
|
|
10701
|
-
description: "Execute/Start a legacy workflow",
|
|
10702
|
-
tags: ["legacyWorkflows"],
|
|
10703
|
-
parameters: [
|
|
10704
|
-
{
|
|
10705
|
-
name: "workflowId",
|
|
10706
|
-
in: "path",
|
|
10707
|
-
required: true,
|
|
10708
|
-
schema: { type: "string" }
|
|
10709
|
-
},
|
|
10710
|
-
{
|
|
10711
|
-
name: "runId",
|
|
10712
|
-
in: "query",
|
|
10713
|
-
required: false,
|
|
10714
|
-
schema: { type: "string" }
|
|
10715
|
-
}
|
|
10716
|
-
],
|
|
10717
|
-
requestBody: {
|
|
10718
|
-
required: true,
|
|
10719
|
-
content: {
|
|
10720
|
-
"application/json": {
|
|
10721
|
-
schema: {
|
|
10722
|
-
type: "object",
|
|
10723
|
-
properties: {
|
|
10724
|
-
input: { type: "object" }
|
|
10725
|
-
}
|
|
10726
|
-
}
|
|
10727
|
-
}
|
|
10728
|
-
}
|
|
10729
|
-
},
|
|
10730
|
-
responses: {
|
|
10731
|
-
200: {
|
|
10732
|
-
description: "Legacy Workflow execution result"
|
|
10733
|
-
},
|
|
10734
|
-
404: {
|
|
10735
|
-
description: "Legacy Workflow not found"
|
|
10736
|
-
}
|
|
10737
|
-
}
|
|
10738
|
-
}),
|
|
10739
|
-
startAsyncLegacyWorkflowHandler
|
|
10740
|
-
);
|
|
10741
|
-
router.post(
|
|
10742
|
-
"/legacy/:workflowId/start",
|
|
10743
|
-
w({
|
|
10744
|
-
description: "Create and start a new legacy workflow run",
|
|
10745
|
-
tags: ["legacyWorkflows"],
|
|
10746
|
-
parameters: [
|
|
10747
|
-
{
|
|
10748
|
-
name: "workflowId",
|
|
10749
|
-
in: "path",
|
|
10750
|
-
required: true,
|
|
10751
|
-
schema: { type: "string" }
|
|
10752
|
-
},
|
|
10753
|
-
{
|
|
10754
|
-
name: "runId",
|
|
10755
|
-
in: "query",
|
|
10756
|
-
required: true,
|
|
10757
|
-
schema: { type: "string" }
|
|
10758
|
-
}
|
|
10759
|
-
],
|
|
10760
|
-
requestBody: {
|
|
10761
|
-
required: true,
|
|
10762
|
-
content: {
|
|
10763
|
-
"application/json": {
|
|
10764
|
-
schema: {
|
|
10765
|
-
type: "object",
|
|
10766
|
-
properties: {
|
|
10767
|
-
input: { type: "object" }
|
|
10768
|
-
}
|
|
10769
|
-
}
|
|
10349
|
+
async (stream5) => {
|
|
10350
|
+
try {
|
|
10351
|
+
const result = await observeStreamLegacyWorkflowHandler$1({
|
|
10352
|
+
mastra,
|
|
10353
|
+
workflowId,
|
|
10354
|
+
runId
|
|
10355
|
+
});
|
|
10356
|
+
const reader = result.getReader();
|
|
10357
|
+
stream5.onAbort(() => {
|
|
10358
|
+
void reader.cancel("request aborted");
|
|
10359
|
+
});
|
|
10360
|
+
let chunkResult;
|
|
10361
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10362
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
10770
10363
|
}
|
|
10364
|
+
} catch (err) {
|
|
10365
|
+
logger2.error("Error in workflow observe stream: " + (err?.message ?? "Unknown error"));
|
|
10771
10366
|
}
|
|
10367
|
+
await stream5.close();
|
|
10772
10368
|
},
|
|
10773
|
-
|
|
10774
|
-
|
|
10775
|
-
description: "Legacy Workflow run started"
|
|
10776
|
-
},
|
|
10777
|
-
404: {
|
|
10778
|
-
description: "Legacy Workflow not found"
|
|
10779
|
-
}
|
|
10369
|
+
async (err) => {
|
|
10370
|
+
logger2.error("Error in workflow observe stream: " + err?.message);
|
|
10780
10371
|
}
|
|
10781
|
-
|
|
10782
|
-
|
|
10783
|
-
|
|
10784
|
-
|
|
10785
|
-
|
|
10786
|
-
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
|
|
10790
|
-
|
|
10791
|
-
|
|
10792
|
-
|
|
10793
|
-
|
|
10794
|
-
|
|
10795
|
-
|
|
10796
|
-
|
|
10797
|
-
|
|
10798
|
-
|
|
10799
|
-
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
|
|
10805
|
-
|
|
10372
|
+
);
|
|
10373
|
+
} catch (error) {
|
|
10374
|
+
return handleError(error, "Error observing workflow stream");
|
|
10375
|
+
}
|
|
10376
|
+
}
|
|
10377
|
+
async function resumeStreamWorkflowHandler(c2) {
|
|
10378
|
+
try {
|
|
10379
|
+
const mastra = c2.get("mastra");
|
|
10380
|
+
const requestContext = c2.get("requestContext");
|
|
10381
|
+
const logger2 = mastra.getLogger();
|
|
10382
|
+
const workflowId = c2.req.param("workflowId");
|
|
10383
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10384
|
+
const runId = c2.req.query("runId");
|
|
10385
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
10386
|
+
return stream(
|
|
10387
|
+
c2,
|
|
10388
|
+
async (stream5) => {
|
|
10389
|
+
try {
|
|
10390
|
+
const result = await resumeStreamWorkflowHandler$1({
|
|
10391
|
+
mastra,
|
|
10392
|
+
workflowId,
|
|
10393
|
+
runId,
|
|
10394
|
+
body: { step, resumeData },
|
|
10395
|
+
requestContext,
|
|
10396
|
+
tracingOptions
|
|
10397
|
+
});
|
|
10398
|
+
const reader = result.getReader();
|
|
10399
|
+
stream5.onAbort(() => {
|
|
10400
|
+
void reader.cancel("request aborted");
|
|
10401
|
+
});
|
|
10402
|
+
let chunkResult;
|
|
10403
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
10404
|
+
await stream5.write(JSON.stringify(chunkResult.value) + "");
|
|
10405
|
+
}
|
|
10406
|
+
} catch (err) {
|
|
10407
|
+
logger2.error("Error in workflow VNext stream: " + (err?.message ?? "Unknown error"));
|
|
10806
10408
|
}
|
|
10409
|
+
},
|
|
10410
|
+
async (err) => {
|
|
10411
|
+
logger2.error("Error in workflow VNext stream: " + err?.message);
|
|
10807
10412
|
}
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10413
|
+
);
|
|
10414
|
+
} catch (error) {
|
|
10415
|
+
return handleError(error, "Error streaming workflow");
|
|
10416
|
+
}
|
|
10417
|
+
}
|
|
10418
|
+
async function resumeAsyncWorkflowHandler(c2) {
|
|
10419
|
+
try {
|
|
10420
|
+
const mastra = c2.get("mastra");
|
|
10421
|
+
const requestContext = c2.get("requestContext");
|
|
10422
|
+
const workflowId = c2.req.param("workflowId");
|
|
10423
|
+
const runId = c2.req.query("runId");
|
|
10424
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10425
|
+
if (!runId) {
|
|
10426
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
10427
|
+
}
|
|
10428
|
+
const result = await resumeAsyncWorkflowHandler$1({
|
|
10429
|
+
mastra,
|
|
10430
|
+
requestContext,
|
|
10431
|
+
workflowId,
|
|
10432
|
+
runId,
|
|
10433
|
+
body: { step, resumeData },
|
|
10434
|
+
tracingOptions
|
|
10435
|
+
});
|
|
10436
|
+
return c2.json(result);
|
|
10437
|
+
} catch (error) {
|
|
10438
|
+
return handleError(error, "Error resuming workflow step");
|
|
10439
|
+
}
|
|
10440
|
+
}
|
|
10441
|
+
async function resumeWorkflowHandler(c2) {
|
|
10442
|
+
try {
|
|
10443
|
+
const mastra = c2.get("mastra");
|
|
10444
|
+
const requestContext = c2.get("requestContext");
|
|
10445
|
+
const workflowId = c2.req.param("workflowId");
|
|
10446
|
+
const runId = c2.req.query("runId");
|
|
10447
|
+
const { step, resumeData, tracingOptions } = await c2.req.json();
|
|
10448
|
+
if (!runId) {
|
|
10449
|
+
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
10450
|
+
}
|
|
10451
|
+
await resumeWorkflowHandler$1({
|
|
10452
|
+
mastra,
|
|
10453
|
+
requestContext,
|
|
10454
|
+
workflowId,
|
|
10455
|
+
runId,
|
|
10456
|
+
body: { step, resumeData },
|
|
10457
|
+
tracingOptions
|
|
10458
|
+
});
|
|
10459
|
+
return c2.json({ message: "Workflow run resumed" });
|
|
10460
|
+
} catch (error) {
|
|
10461
|
+
return handleError(error, "Error resuming workflow");
|
|
10462
|
+
}
|
|
10463
|
+
}
|
|
10464
|
+
async function listWorkflowRunsHandler(c2) {
|
|
10465
|
+
try {
|
|
10466
|
+
const mastra = c2.get("mastra");
|
|
10467
|
+
const workflowId = c2.req.param("workflowId");
|
|
10468
|
+
const { fromDate, toDate, perPage: perPageRaw, page: pageRaw, resourceId } = c2.req.query();
|
|
10469
|
+
const workflowRuns = await listWorkflowRunsHandler$1({
|
|
10470
|
+
mastra,
|
|
10471
|
+
workflowId,
|
|
10472
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
10473
|
+
toDate: toDate ? new Date(toDate) : void 0,
|
|
10474
|
+
perPage: perPageRaw !== void 0 ? parsePerPage(perPageRaw) : void 0,
|
|
10475
|
+
page: pageRaw !== void 0 ? parsePage(pageRaw) : void 0,
|
|
10476
|
+
resourceId
|
|
10477
|
+
});
|
|
10478
|
+
return c2.json(workflowRuns);
|
|
10479
|
+
} catch (error) {
|
|
10480
|
+
return handleError(error, "Error getting workflow runs");
|
|
10481
|
+
}
|
|
10482
|
+
}
|
|
10483
|
+
async function getWorkflowRunByIdHandler(c2) {
|
|
10484
|
+
try {
|
|
10485
|
+
const mastra = c2.get("mastra");
|
|
10486
|
+
const workflowId = c2.req.param("workflowId");
|
|
10487
|
+
const runId = c2.req.param("runId");
|
|
10488
|
+
const workflowRun = await getWorkflowRunByIdHandler$1({
|
|
10489
|
+
mastra,
|
|
10490
|
+
workflowId,
|
|
10491
|
+
runId
|
|
10492
|
+
});
|
|
10493
|
+
return c2.json(workflowRun);
|
|
10494
|
+
} catch (error) {
|
|
10495
|
+
return handleError(error, "Error getting workflow run");
|
|
10496
|
+
}
|
|
10497
|
+
}
|
|
10498
|
+
async function getWorkflowRunExecutionResultHandler(c2) {
|
|
10499
|
+
try {
|
|
10500
|
+
const mastra = c2.get("mastra");
|
|
10501
|
+
const workflowId = c2.req.param("workflowId");
|
|
10502
|
+
const runId = c2.req.param("runId");
|
|
10503
|
+
const workflowRunExecutionResult = await getWorkflowRunExecutionResultHandler$1({
|
|
10504
|
+
mastra,
|
|
10505
|
+
workflowId,
|
|
10506
|
+
runId
|
|
10507
|
+
});
|
|
10508
|
+
return c2.json(workflowRunExecutionResult);
|
|
10509
|
+
} catch (error) {
|
|
10510
|
+
return handleError(error, "Error getting workflow run execution result");
|
|
10511
|
+
}
|
|
10512
|
+
}
|
|
10513
|
+
async function cancelWorkflowRunHandler(c2) {
|
|
10514
|
+
try {
|
|
10515
|
+
const mastra = c2.get("mastra");
|
|
10516
|
+
const workflowId = c2.req.param("workflowId");
|
|
10517
|
+
const runId = c2.req.param("runId");
|
|
10518
|
+
const result = await cancelWorkflowRunHandler$1({
|
|
10519
|
+
mastra,
|
|
10520
|
+
workflowId,
|
|
10521
|
+
runId
|
|
10522
|
+
});
|
|
10523
|
+
return c2.json(result);
|
|
10524
|
+
} catch (error) {
|
|
10525
|
+
return handleError(error, "Error canceling workflow run");
|
|
10526
|
+
}
|
|
10527
|
+
}
|
|
10528
|
+
|
|
10529
|
+
// src/server/handlers/routes/workflows/router.ts
|
|
10530
|
+
function workflowsRouter(bodyLimitOptions) {
|
|
10531
|
+
const router = new Hono();
|
|
10811
10532
|
router.get(
|
|
10812
10533
|
"/",
|
|
10813
10534
|
w({
|
|
@@ -10819,7 +10540,7 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
10819
10540
|
}
|
|
10820
10541
|
}
|
|
10821
10542
|
}),
|
|
10822
|
-
|
|
10543
|
+
listWorkflowsHandler
|
|
10823
10544
|
);
|
|
10824
10545
|
router.get(
|
|
10825
10546
|
"/:workflowId",
|
|
@@ -10848,7 +10569,7 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
10848
10569
|
router.get(
|
|
10849
10570
|
"/:workflowId/runs",
|
|
10850
10571
|
w({
|
|
10851
|
-
description: "
|
|
10572
|
+
description: "List all runs for a workflow",
|
|
10852
10573
|
tags: ["workflows"],
|
|
10853
10574
|
parameters: [
|
|
10854
10575
|
{
|
|
@@ -10869,7 +10590,7 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
10869
10590
|
}
|
|
10870
10591
|
}
|
|
10871
10592
|
}),
|
|
10872
|
-
|
|
10593
|
+
listWorkflowRunsHandler
|
|
10873
10594
|
);
|
|
10874
10595
|
router.get(
|
|
10875
10596
|
"/:workflowId/runs/:runId/execution-result",
|
|
@@ -10961,9 +10682,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
10961
10682
|
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
10962
10683
|
},
|
|
10963
10684
|
resumeData: { type: "object" },
|
|
10964
|
-
|
|
10685
|
+
requestContext: {
|
|
10965
10686
|
type: "object",
|
|
10966
|
-
description: "
|
|
10687
|
+
description: "Request Context for the workflow execution"
|
|
10967
10688
|
}
|
|
10968
10689
|
}
|
|
10969
10690
|
}
|
|
@@ -11003,9 +10724,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11003
10724
|
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
11004
10725
|
},
|
|
11005
10726
|
resumeData: { type: "object" },
|
|
11006
|
-
|
|
10727
|
+
requestContext: {
|
|
11007
10728
|
type: "object",
|
|
11008
|
-
description: "
|
|
10729
|
+
description: "Request Context for the workflow execution"
|
|
11009
10730
|
},
|
|
11010
10731
|
tracingOptions: {
|
|
11011
10732
|
type: "object",
|
|
@@ -11057,9 +10778,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11057
10778
|
oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }]
|
|
11058
10779
|
},
|
|
11059
10780
|
resumeData: { type: "object" },
|
|
11060
|
-
|
|
10781
|
+
requestContext: {
|
|
11061
10782
|
type: "object",
|
|
11062
|
-
description: "
|
|
10783
|
+
description: "Request Context for the workflow execution"
|
|
11063
10784
|
}
|
|
11064
10785
|
}
|
|
11065
10786
|
}
|
|
@@ -11095,9 +10816,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11095
10816
|
type: "object",
|
|
11096
10817
|
properties: {
|
|
11097
10818
|
inputData: { type: "object" },
|
|
11098
|
-
|
|
10819
|
+
requestContext: {
|
|
11099
10820
|
type: "object",
|
|
11100
|
-
description: "
|
|
10821
|
+
description: "Request Context for the workflow execution"
|
|
11101
10822
|
},
|
|
11102
10823
|
tracingOptions: {
|
|
11103
10824
|
type: "object",
|
|
@@ -11183,9 +10904,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11183
10904
|
type: "object",
|
|
11184
10905
|
properties: {
|
|
11185
10906
|
inputData: { type: "object" },
|
|
11186
|
-
|
|
10907
|
+
requestContext: {
|
|
11187
10908
|
type: "object",
|
|
11188
|
-
description: "
|
|
10909
|
+
description: "Request Context for the workflow execution"
|
|
11189
10910
|
},
|
|
11190
10911
|
closeOnSuspend: {
|
|
11191
10912
|
type: "boolean",
|
|
@@ -11275,9 +10996,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11275
10996
|
type: "object",
|
|
11276
10997
|
properties: {
|
|
11277
10998
|
inputData: { type: "object" },
|
|
11278
|
-
|
|
10999
|
+
requestContext: {
|
|
11279
11000
|
type: "object",
|
|
11280
|
-
description: "
|
|
11001
|
+
description: "Request Context for the workflow execution"
|
|
11281
11002
|
},
|
|
11282
11003
|
closeOnSuspend: {
|
|
11283
11004
|
type: "boolean",
|
|
@@ -11397,9 +11118,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11397
11118
|
type: "object",
|
|
11398
11119
|
properties: {
|
|
11399
11120
|
inputData: { type: "object" },
|
|
11400
|
-
|
|
11121
|
+
requestContext: {
|
|
11401
11122
|
type: "object",
|
|
11402
|
-
description: "
|
|
11123
|
+
description: "Request Context for the workflow execution"
|
|
11403
11124
|
},
|
|
11404
11125
|
tracingOptions: {
|
|
11405
11126
|
type: "object",
|
|
@@ -11455,9 +11176,9 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11455
11176
|
type: "object",
|
|
11456
11177
|
properties: {
|
|
11457
11178
|
inputData: { type: "object" },
|
|
11458
|
-
|
|
11179
|
+
requestContext: {
|
|
11459
11180
|
type: "object",
|
|
11460
|
-
description: "
|
|
11181
|
+
description: "Request Context for the workflow execution"
|
|
11461
11182
|
},
|
|
11462
11183
|
tracingOptions: {
|
|
11463
11184
|
type: "object",
|
|
@@ -11486,33 +11207,6 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11486
11207
|
}),
|
|
11487
11208
|
startWorkflowRunHandler
|
|
11488
11209
|
);
|
|
11489
|
-
router.get(
|
|
11490
|
-
"/:workflowId/watch",
|
|
11491
|
-
w({
|
|
11492
|
-
description: "Watch workflow transitions in real-time",
|
|
11493
|
-
parameters: [
|
|
11494
|
-
{
|
|
11495
|
-
name: "workflowId",
|
|
11496
|
-
in: "path",
|
|
11497
|
-
required: true,
|
|
11498
|
-
schema: { type: "string" }
|
|
11499
|
-
},
|
|
11500
|
-
{
|
|
11501
|
-
name: "runId",
|
|
11502
|
-
in: "query",
|
|
11503
|
-
required: false,
|
|
11504
|
-
schema: { type: "string" }
|
|
11505
|
-
}
|
|
11506
|
-
],
|
|
11507
|
-
tags: ["workflows"],
|
|
11508
|
-
responses: {
|
|
11509
|
-
200: {
|
|
11510
|
-
description: "workflow transitions in real-time"
|
|
11511
|
-
}
|
|
11512
|
-
}
|
|
11513
|
-
}),
|
|
11514
|
-
watchWorkflowHandler
|
|
11515
|
-
);
|
|
11516
11210
|
router.post(
|
|
11517
11211
|
"/:workflowId/runs/:runId/cancel",
|
|
11518
11212
|
w({
|
|
@@ -11540,41 +11234,6 @@ function workflowsRouter(bodyLimitOptions) {
|
|
|
11540
11234
|
}),
|
|
11541
11235
|
cancelWorkflowRunHandler
|
|
11542
11236
|
);
|
|
11543
|
-
router.post(
|
|
11544
|
-
"/:workflowId/runs/:runId/send-event",
|
|
11545
|
-
w({
|
|
11546
|
-
description: "Send an event to a workflow run",
|
|
11547
|
-
parameters: [
|
|
11548
|
-
{
|
|
11549
|
-
name: "workflowId",
|
|
11550
|
-
in: "path",
|
|
11551
|
-
required: true,
|
|
11552
|
-
schema: { type: "string" }
|
|
11553
|
-
},
|
|
11554
|
-
{
|
|
11555
|
-
name: "runId",
|
|
11556
|
-
in: "path",
|
|
11557
|
-
required: true,
|
|
11558
|
-
schema: { type: "string" }
|
|
11559
|
-
}
|
|
11560
|
-
],
|
|
11561
|
-
requestBody: {
|
|
11562
|
-
required: true,
|
|
11563
|
-
content: {
|
|
11564
|
-
"application/json": {
|
|
11565
|
-
schema: { type: "object", properties: { event: { type: "string" }, data: { type: "object" } } }
|
|
11566
|
-
}
|
|
11567
|
-
}
|
|
11568
|
-
},
|
|
11569
|
-
tags: ["workflows"],
|
|
11570
|
-
responses: {
|
|
11571
|
-
200: {
|
|
11572
|
-
description: "workflow run event sent"
|
|
11573
|
-
}
|
|
11574
|
-
}
|
|
11575
|
-
}),
|
|
11576
|
-
sendWorkflowRunEventHandler
|
|
11577
|
-
);
|
|
11578
11237
|
return router;
|
|
11579
11238
|
}
|
|
11580
11239
|
|
|
@@ -11663,7 +11322,7 @@ var html2 = `
|
|
|
11663
11322
|
<main>
|
|
11664
11323
|
<h1>Welcome to Mastra</h1>
|
|
11665
11324
|
<p class="subtitle">
|
|
11666
|
-
|
|
11325
|
+
Prototype and productionize AI features with a modern JS/TS stack.
|
|
11667
11326
|
</p>
|
|
11668
11327
|
|
|
11669
11328
|
<a href="https://mastra.ai/docs" class="docs-link">
|
|
@@ -11721,36 +11380,17 @@ async function createHonoServer(mastra, options = {
|
|
|
11721
11380
|
customRouteAuthConfig.set(routeKey, requiresAuth);
|
|
11722
11381
|
}
|
|
11723
11382
|
}
|
|
11724
|
-
app.use("*", async function setTelemetryInfo(c2, next) {
|
|
11725
|
-
const requestId = c2.req.header("x-request-id") ?? randomUUID();
|
|
11726
|
-
const span = Telemetry.getActiveSpan();
|
|
11727
|
-
if (span) {
|
|
11728
|
-
span.setAttribute("http.request_id", requestId);
|
|
11729
|
-
span.updateName(`${c2.req.method} ${c2.req.path}`);
|
|
11730
|
-
const newCtx = Telemetry.setBaggage({
|
|
11731
|
-
"http.request_id": { value: requestId }
|
|
11732
|
-
});
|
|
11733
|
-
await new Promise((resolve) => {
|
|
11734
|
-
Telemetry.withContext(newCtx, async () => {
|
|
11735
|
-
await next();
|
|
11736
|
-
resolve(true);
|
|
11737
|
-
});
|
|
11738
|
-
});
|
|
11739
|
-
} else {
|
|
11740
|
-
await next();
|
|
11741
|
-
}
|
|
11742
|
-
});
|
|
11743
11383
|
app.onError((err, c2) => errorHandler(err, c2, options.isDev));
|
|
11744
11384
|
app.use("*", async function setContext(c2, next) {
|
|
11745
|
-
let
|
|
11385
|
+
let requestContext = new RequestContext();
|
|
11746
11386
|
if (c2.req.method === "POST" || c2.req.method === "PUT") {
|
|
11747
11387
|
const contentType = c2.req.header("content-type");
|
|
11748
11388
|
if (contentType?.includes("application/json")) {
|
|
11749
11389
|
try {
|
|
11750
11390
|
const clonedReq = c2.req.raw.clone();
|
|
11751
11391
|
const body = await clonedReq.json();
|
|
11752
|
-
if (body.
|
|
11753
|
-
|
|
11392
|
+
if (body.requestContext) {
|
|
11393
|
+
requestContext = new RequestContext(Object.entries(body.requestContext));
|
|
11754
11394
|
}
|
|
11755
11395
|
} catch {
|
|
11756
11396
|
}
|
|
@@ -11758,26 +11398,26 @@ async function createHonoServer(mastra, options = {
|
|
|
11758
11398
|
}
|
|
11759
11399
|
if (c2.req.method === "GET") {
|
|
11760
11400
|
try {
|
|
11761
|
-
const
|
|
11762
|
-
if (
|
|
11763
|
-
let
|
|
11401
|
+
const encodedRequestContext = c2.req.query("requestContext");
|
|
11402
|
+
if (encodedRequestContext) {
|
|
11403
|
+
let parsedRequestContext;
|
|
11764
11404
|
try {
|
|
11765
|
-
|
|
11405
|
+
parsedRequestContext = JSON.parse(encodedRequestContext);
|
|
11766
11406
|
} catch {
|
|
11767
11407
|
try {
|
|
11768
|
-
const json = Buffer.from(
|
|
11769
|
-
|
|
11408
|
+
const json = Buffer.from(encodedRequestContext, "base64").toString("utf-8");
|
|
11409
|
+
parsedRequestContext = JSON.parse(json);
|
|
11770
11410
|
} catch {
|
|
11771
11411
|
}
|
|
11772
11412
|
}
|
|
11773
|
-
if (
|
|
11774
|
-
|
|
11413
|
+
if (parsedRequestContext && typeof parsedRequestContext === "object") {
|
|
11414
|
+
requestContext = new RequestContext([...requestContext.entries(), ...Object.entries(parsedRequestContext)]);
|
|
11775
11415
|
}
|
|
11776
11416
|
}
|
|
11777
11417
|
} catch {
|
|
11778
11418
|
}
|
|
11779
11419
|
}
|
|
11780
|
-
c2.set("
|
|
11420
|
+
c2.set("requestContext", requestContext);
|
|
11781
11421
|
c2.set("mastra", mastra);
|
|
11782
11422
|
c2.set("tools", options.tools);
|
|
11783
11423
|
c2.set("taskStore", a2aTaskStore);
|
|
@@ -11806,6 +11446,19 @@ async function createHonoServer(mastra, options = {
|
|
|
11806
11446
|
};
|
|
11807
11447
|
app.use("*", timeout(server?.timeout ?? 3 * 60 * 1e3), cors(corsConfig));
|
|
11808
11448
|
}
|
|
11449
|
+
app.get(
|
|
11450
|
+
"/health",
|
|
11451
|
+
w({
|
|
11452
|
+
description: "Health check endpoint",
|
|
11453
|
+
tags: ["system"],
|
|
11454
|
+
responses: {
|
|
11455
|
+
200: {
|
|
11456
|
+
description: "Service is healthy"
|
|
11457
|
+
}
|
|
11458
|
+
}
|
|
11459
|
+
}),
|
|
11460
|
+
healthHandler
|
|
11461
|
+
);
|
|
11809
11462
|
app.use("*", authenticationMiddleware);
|
|
11810
11463
|
app.use("*", authorizationMiddleware);
|
|
11811
11464
|
const bodyLimitOptions = {
|
|
@@ -12011,7 +11664,6 @@ async function createHonoServer(mastra, options = {
|
|
|
12011
11664
|
}
|
|
12012
11665
|
app.route("/api/mcp", mcpRouter(bodyLimitOptions));
|
|
12013
11666
|
app.route("/api/memory", memoryRoutes(bodyLimitOptions));
|
|
12014
|
-
app.route("/api/telemetry", telemetryRouter());
|
|
12015
11667
|
app.route("/api/observability", observabilityRouter());
|
|
12016
11668
|
app.route("/api/workflows", workflowsRouter(bodyLimitOptions));
|
|
12017
11669
|
app.route("/api/logs", logsRouter());
|
|
@@ -12092,10 +11744,6 @@ async function createHonoServer(mastra, options = {
|
|
|
12092
11744
|
}
|
|
12093
11745
|
if (options?.playground) {
|
|
12094
11746
|
let indexHtml = await readFile(join(process.cwd(), "./playground/index.html"), "utf-8");
|
|
12095
|
-
indexHtml = indexHtml.replace(
|
|
12096
|
-
`'%%MASTRA_TELEMETRY_DISABLED%%'`,
|
|
12097
|
-
`${Boolean(process.env.MASTRA_TELEMETRY_DISABLED)}`
|
|
12098
|
-
);
|
|
12099
11747
|
const serverOptions = mastra.getServer();
|
|
12100
11748
|
const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
|
|
12101
11749
|
const hideCloudCta = process.env.MASTRA_HIDE_CLOUD_CTA === "true";
|