@mastra/deployer 0.13.2-alpha.1 → 0.13.2-alpha.3
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/dist/build/analyze.cjs +3 -3
- package/dist/build/analyze.d.ts.map +1 -1
- package/dist/build/analyze.js +1 -1
- package/dist/build/babel/check-config-export.d.ts +5 -0
- package/dist/build/babel/check-config-export.d.ts.map +1 -0
- package/dist/build/index.cjs +9 -9
- package/dist/build/index.js +3 -3
- package/dist/bundler/index.cjs +2 -2
- package/dist/bundler/index.js +1 -1
- package/dist/{chunk-E742PKW3.js → chunk-3OH2F6RQ.js} +56 -6
- package/dist/chunk-3OH2F6RQ.js.map +1 -0
- package/dist/{chunk-GA3I2SUH.cjs → chunk-7T2PU7VS.cjs} +56 -6
- package/dist/chunk-7T2PU7VS.cjs.map +1 -0
- package/dist/{chunk-FQIQKPRH.js → chunk-7U5E2KBV.js} +3 -3
- package/dist/{chunk-FQIQKPRH.js.map → chunk-7U5E2KBV.js.map} +1 -1
- package/dist/{chunk-OPNQQDWL.cjs → chunk-DO5ZQHCX.cjs} +9 -9
- package/dist/{chunk-OPNQQDWL.cjs.map → chunk-DO5ZQHCX.cjs.map} +1 -1
- package/dist/{chunk-IAZWZE5D.js → chunk-IA6E2T4X.js} +4 -4
- package/dist/{chunk-IAZWZE5D.js.map → chunk-IA6E2T4X.js.map} +1 -1
- package/dist/{chunk-MJK4QE4U.cjs → chunk-J4CNHLNI.cjs} +7 -7
- package/dist/{chunk-MJK4QE4U.cjs.map → chunk-J4CNHLNI.cjs.map} +1 -1
- package/dist/{chunk-PKWWUDUT.cjs → chunk-USWV4OQC.cjs} +5 -5
- package/dist/{chunk-PKWWUDUT.cjs.map → chunk-USWV4OQC.cjs.map} +1 -1
- package/dist/{chunk-T454CVHE.js → chunk-XJGTXD3R.js} +3 -3
- package/dist/{chunk-T454CVHE.js.map → chunk-XJGTXD3R.js.map} +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.js +2 -2
- package/dist/server/handlers/a2a.d.ts +81 -21
- package/dist/server/handlers/a2a.d.ts.map +1 -1
- package/dist/server/handlers/routes/agents/handlers.d.ts +4 -0
- 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/utils.d.ts +7 -0
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/index.cjs +266 -160
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +266 -160
- package/dist/server/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-E742PKW3.js.map +0 -1
- package/dist/chunk-GA3I2SUH.cjs.map +0 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Mastra } from '@mastra/core';
|
|
2
2
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
3
3
|
import { Tool } from '@mastra/core/tools';
|
|
4
|
+
import { InMemoryTaskStore } from '@mastra/server/a2a/store';
|
|
4
5
|
import { Hono } from 'hono';
|
|
5
6
|
import type { ServerBundleOptions } from './types.js';
|
|
6
7
|
type Bindings = {};
|
|
@@ -11,6 +12,7 @@ type Variables = {
|
|
|
11
12
|
controller: ReadableStreamDefaultController;
|
|
12
13
|
}>;
|
|
13
14
|
tools: Record<string, Tool>;
|
|
15
|
+
taskStore: InMemoryTaskStore;
|
|
14
16
|
playground: boolean;
|
|
15
17
|
isDev: boolean;
|
|
16
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAsB5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnD,KAAK,QAAQ,GAAG,EAAE,CAAC;AAEnB,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,GAAG,CAAC;QAAE,UAAU,EAAE,+BAA+B,CAAA;KAAE,CAAC,CAAC;IAC9D,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,wCAmB/D;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAER;cAGgC,QAAQ;eAAa,SAAS;2CAochE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAmC,mDAgClG"}
|
package/dist/server/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { html } from 'hono/html';
|
|
|
11
11
|
import { Telemetry } from '@mastra/core';
|
|
12
12
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
13
13
|
import { Tool } from '@mastra/core/tools';
|
|
14
|
+
import { InMemoryTaskStore } from '@mastra/server/a2a/store';
|
|
14
15
|
import { Hono } from 'hono';
|
|
15
16
|
import { cors } from 'hono/cors';
|
|
16
17
|
import { logger } from 'hono/logger';
|
|
@@ -18,11 +19,11 @@ import { timeout } from 'hono/timeout';
|
|
|
18
19
|
import { HTTPException } from 'hono/http-exception';
|
|
19
20
|
import { getAgentCardByIdHandler as getAgentCardByIdHandler$1, getAgentExecutionHandler as getAgentExecutionHandler$1 } from '@mastra/server/handlers/a2a';
|
|
20
21
|
import { stream } from 'hono/streaming';
|
|
22
|
+
import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateHandler as generateHandler$1, streamGenerateHandler as streamGenerateHandler$1, streamVNextGenerateHandler as streamVNextGenerateHandler$1, updateAgentModelHandler as updateAgentModelHandler$1 } from '@mastra/server/handlers/agents';
|
|
21
23
|
import { bodyLimit } from 'hono/body-limit';
|
|
22
24
|
import { Agent } from '@mastra/core/agent';
|
|
23
25
|
import { z } from 'zod';
|
|
24
26
|
import { executeAgentToolHandler as executeAgentToolHandler$1, getToolsHandler as getToolsHandler$1, getToolByIdHandler as getToolByIdHandler$1, executeToolHandler as executeToolHandler$1 } from '@mastra/server/handlers/tools';
|
|
25
|
-
import { getAgentsHandler as getAgentsHandler$1, getAgentByIdHandler as getAgentByIdHandler$1, getEvalsByAgentIdHandler as getEvalsByAgentIdHandler$1, getLiveEvalsByAgentIdHandler as getLiveEvalsByAgentIdHandler$1, generateHandler as generateHandler$1, streamGenerateHandler as streamGenerateHandler$1, streamVNextGenerateHandler as streamVNextGenerateHandler$1 } from '@mastra/server/handlers/agents';
|
|
26
27
|
import { getSpeakersHandler as getSpeakersHandler$1, generateSpeechHandler, getListenerHandler as getListenerHandler$1, transcribeSpeechHandler } from '@mastra/server/handlers/voice';
|
|
27
28
|
import { getLogsHandler as getLogsHandler$1, getLogTransports as getLogTransports$1, getLogsByRunIdHandler as getLogsByRunIdHandler$1 } from '@mastra/server/handlers/logs';
|
|
28
29
|
import util from 'util';
|
|
@@ -932,9 +933,10 @@ async function getAgentExecutionHandler(c2) {
|
|
|
932
933
|
const mastra = c2.get("mastra");
|
|
933
934
|
const agentId = c2.req.param("agentId");
|
|
934
935
|
const runtimeContext = c2.get("runtimeContext");
|
|
936
|
+
const taskStore = c2.get("taskStore");
|
|
935
937
|
const logger2 = mastra.getLogger();
|
|
936
938
|
const body = await c2.req.json();
|
|
937
|
-
if (!["
|
|
939
|
+
if (!["message/send", "message/stream", "tasks/get", "tasks/cancel"].includes(body.method)) {
|
|
938
940
|
return c2.json({ error: { message: `Unsupported method: ${body.method}`, code: "invalid_method" } }, 400);
|
|
939
941
|
}
|
|
940
942
|
const result = await getAgentExecutionHandler$1({
|
|
@@ -944,9 +946,10 @@ async function getAgentExecutionHandler(c2) {
|
|
|
944
946
|
requestId: randomUUID(),
|
|
945
947
|
method: body.method,
|
|
946
948
|
params: body.params,
|
|
949
|
+
taskStore,
|
|
947
950
|
logger: logger2
|
|
948
951
|
});
|
|
949
|
-
if (body.method === "
|
|
952
|
+
if (body.method === "message/stream") {
|
|
950
953
|
return stream(
|
|
951
954
|
c2,
|
|
952
955
|
async (stream6) => {
|
|
@@ -960,11 +963,11 @@ async function getAgentExecutionHandler(c2) {
|
|
|
960
963
|
await stream6.write(JSON.stringify(chunk) + "");
|
|
961
964
|
}
|
|
962
965
|
} catch (err) {
|
|
963
|
-
logger2.error("Error in
|
|
966
|
+
logger2.error("Error in message/stream stream: " + err?.message);
|
|
964
967
|
}
|
|
965
968
|
},
|
|
966
969
|
async (err) => {
|
|
967
|
-
logger2.error("Error in
|
|
970
|
+
logger2.error("Error in message/stream stream: " + err?.message);
|
|
968
971
|
}
|
|
969
972
|
);
|
|
970
973
|
}
|
|
@@ -996,7 +999,7 @@ var defaultAuthConfig = {
|
|
|
996
999
|
|
|
997
1000
|
// src/server/handlers/auth/helpers.ts
|
|
998
1001
|
var isDevPlaygroundRequest = (req) => {
|
|
999
|
-
return req.header("x-mastra-dev-playground") === "true" &&
|
|
1002
|
+
return req.header("x-mastra-dev-playground") === "true" && process.env.MASTRA_DEV === "true";
|
|
1000
1003
|
};
|
|
1001
1004
|
var isProtectedPath = (path, method, authConfig) => {
|
|
1002
1005
|
const protectedAccess = [...defaultAuthConfig.protected || [], ...authConfig.protected || []];
|
|
@@ -1232,6 +1235,187 @@ function errorHandler(err, c2, isDev) {
|
|
|
1232
1235
|
async function rootHandler(c2) {
|
|
1233
1236
|
return c2.text("Hello to the Mastra API!");
|
|
1234
1237
|
}
|
|
1238
|
+
var AllowedProviderKeys = {
|
|
1239
|
+
openai: "OPENAI_API_KEY",
|
|
1240
|
+
xai: "XAI_API_KEY",
|
|
1241
|
+
anthropic: "ANTHROPIC_API_KEY",
|
|
1242
|
+
google: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
1243
|
+
groq: "GROQ_API_KEY"
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
// src/server/handlers/routes/agents/handlers.ts
|
|
1247
|
+
async function getAgentsHandler(c2) {
|
|
1248
|
+
const serializedAgents = await getAgentsHandler$1({
|
|
1249
|
+
mastra: c2.get("mastra"),
|
|
1250
|
+
runtimeContext: c2.get("runtimeContext")
|
|
1251
|
+
});
|
|
1252
|
+
return c2.json(serializedAgents);
|
|
1253
|
+
}
|
|
1254
|
+
async function getAgentByIdHandler(c2) {
|
|
1255
|
+
const mastra = c2.get("mastra");
|
|
1256
|
+
const agentId = c2.req.param("agentId");
|
|
1257
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
1258
|
+
const isPlayground = c2.req.header("x-mastra-dev-playground") === "true";
|
|
1259
|
+
const result = await getAgentByIdHandler$1({
|
|
1260
|
+
mastra,
|
|
1261
|
+
agentId,
|
|
1262
|
+
runtimeContext,
|
|
1263
|
+
isPlayground
|
|
1264
|
+
});
|
|
1265
|
+
return c2.json(result);
|
|
1266
|
+
}
|
|
1267
|
+
async function getEvalsByAgentIdHandler(c2) {
|
|
1268
|
+
const mastra = c2.get("mastra");
|
|
1269
|
+
const agentId = c2.req.param("agentId");
|
|
1270
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
1271
|
+
const result = await getEvalsByAgentIdHandler$1({
|
|
1272
|
+
mastra,
|
|
1273
|
+
agentId,
|
|
1274
|
+
runtimeContext
|
|
1275
|
+
});
|
|
1276
|
+
return c2.json(result);
|
|
1277
|
+
}
|
|
1278
|
+
async function getLiveEvalsByAgentIdHandler(c2) {
|
|
1279
|
+
const mastra = c2.get("mastra");
|
|
1280
|
+
const agentId = c2.req.param("agentId");
|
|
1281
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
1282
|
+
const result = await getLiveEvalsByAgentIdHandler$1({
|
|
1283
|
+
mastra,
|
|
1284
|
+
agentId,
|
|
1285
|
+
runtimeContext
|
|
1286
|
+
});
|
|
1287
|
+
return c2.json(result);
|
|
1288
|
+
}
|
|
1289
|
+
async function generateHandler(c2) {
|
|
1290
|
+
try {
|
|
1291
|
+
const mastra = c2.get("mastra");
|
|
1292
|
+
const agentId = c2.req.param("agentId");
|
|
1293
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
1294
|
+
const body = await c2.req.json();
|
|
1295
|
+
const result = await generateHandler$1({
|
|
1296
|
+
mastra,
|
|
1297
|
+
agentId,
|
|
1298
|
+
runtimeContext,
|
|
1299
|
+
body,
|
|
1300
|
+
abortSignal: c2.req.raw.signal
|
|
1301
|
+
});
|
|
1302
|
+
return c2.json(result);
|
|
1303
|
+
} catch (error) {
|
|
1304
|
+
return handleError(error, "Error generating from agent");
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
async function streamGenerateHandler(c2) {
|
|
1308
|
+
try {
|
|
1309
|
+
const mastra = c2.get("mastra");
|
|
1310
|
+
const agentId = c2.req.param("agentId");
|
|
1311
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
1312
|
+
const body = await c2.req.json();
|
|
1313
|
+
const streamResponse = await streamGenerateHandler$1({
|
|
1314
|
+
mastra,
|
|
1315
|
+
agentId,
|
|
1316
|
+
runtimeContext,
|
|
1317
|
+
body,
|
|
1318
|
+
abortSignal: c2.req.raw.signal
|
|
1319
|
+
});
|
|
1320
|
+
return streamResponse;
|
|
1321
|
+
} catch (error) {
|
|
1322
|
+
return handleError(error, "Error streaming from agent");
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
async function streamVNextGenerateHandler(c2) {
|
|
1326
|
+
try {
|
|
1327
|
+
const mastra = c2.get("mastra");
|
|
1328
|
+
const agentId = c2.req.param("agentId");
|
|
1329
|
+
const runtimeContext = c2.get("runtimeContext");
|
|
1330
|
+
const body = await c2.req.json();
|
|
1331
|
+
const logger2 = mastra.getLogger();
|
|
1332
|
+
c2.header("Transfer-Encoding", "chunked");
|
|
1333
|
+
return stream(
|
|
1334
|
+
c2,
|
|
1335
|
+
async (stream6) => {
|
|
1336
|
+
try {
|
|
1337
|
+
const result = streamVNextGenerateHandler$1({
|
|
1338
|
+
mastra,
|
|
1339
|
+
agentId,
|
|
1340
|
+
runtimeContext,
|
|
1341
|
+
body,
|
|
1342
|
+
abortSignal: c2.req.raw.signal
|
|
1343
|
+
});
|
|
1344
|
+
const reader = result.getReader();
|
|
1345
|
+
stream6.onAbort(() => {
|
|
1346
|
+
void reader.cancel("request aborted");
|
|
1347
|
+
});
|
|
1348
|
+
let chunkResult;
|
|
1349
|
+
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1350
|
+
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
1351
|
+
}
|
|
1352
|
+
} catch (err) {
|
|
1353
|
+
logger2.error("Error in streamVNext generate: " + (err?.message ?? "Unknown error"));
|
|
1354
|
+
}
|
|
1355
|
+
await stream6.close();
|
|
1356
|
+
},
|
|
1357
|
+
async (err) => {
|
|
1358
|
+
logger2.error("Error in watch stream: " + err?.message);
|
|
1359
|
+
}
|
|
1360
|
+
);
|
|
1361
|
+
} catch (error) {
|
|
1362
|
+
return handleError(error, "Error streaming from agent");
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
async function setAgentInstructionsHandler(c2) {
|
|
1366
|
+
try {
|
|
1367
|
+
const isPlayground = c2.get("playground") === true;
|
|
1368
|
+
if (!isPlayground) {
|
|
1369
|
+
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
1370
|
+
}
|
|
1371
|
+
const agentId = c2.req.param("agentId");
|
|
1372
|
+
const { instructions } = await c2.req.json();
|
|
1373
|
+
if (!agentId || !instructions) {
|
|
1374
|
+
return c2.json({ error: "Missing required fields" }, 400);
|
|
1375
|
+
}
|
|
1376
|
+
const mastra = c2.get("mastra");
|
|
1377
|
+
const agent = mastra.getAgent(agentId);
|
|
1378
|
+
if (!agent) {
|
|
1379
|
+
return c2.json({ error: "Agent not found" }, 404);
|
|
1380
|
+
}
|
|
1381
|
+
agent.__updateInstructions(instructions);
|
|
1382
|
+
return c2.json(
|
|
1383
|
+
{
|
|
1384
|
+
instructions
|
|
1385
|
+
},
|
|
1386
|
+
200
|
|
1387
|
+
);
|
|
1388
|
+
} catch (error) {
|
|
1389
|
+
return handleError(error, "Error setting agent instructions");
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
async function updateAgentModelHandler(c2) {
|
|
1393
|
+
try {
|
|
1394
|
+
const mastra = c2.get("mastra");
|
|
1395
|
+
const agentId = c2.req.param("agentId");
|
|
1396
|
+
const body = await c2.req.json();
|
|
1397
|
+
const result = updateAgentModelHandler$1({
|
|
1398
|
+
mastra,
|
|
1399
|
+
agentId,
|
|
1400
|
+
body
|
|
1401
|
+
});
|
|
1402
|
+
return c2.json(result);
|
|
1403
|
+
} catch (error) {
|
|
1404
|
+
return handleError(error, "Error updating agent model");
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
async function getModelProvidersHandler(c2) {
|
|
1408
|
+
const isPlayground = c2.get("playground") === true;
|
|
1409
|
+
if (!isPlayground) {
|
|
1410
|
+
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
1411
|
+
}
|
|
1412
|
+
const envVars = process.env;
|
|
1413
|
+
const providers = Object.entries(AllowedProviderKeys);
|
|
1414
|
+
const envKeys = Object.keys(envVars);
|
|
1415
|
+
const availableProviders = providers.filter(([_, value]) => envKeys.includes(value) && !!envVars[value]);
|
|
1416
|
+
const availableProvidersNames = availableProviders.map(([key]) => key);
|
|
1417
|
+
return c2.json(availableProvidersNames);
|
|
1418
|
+
}
|
|
1235
1419
|
async function generateSystemPromptHandler(c2) {
|
|
1236
1420
|
try {
|
|
1237
1421
|
const agentId = c2.req.param("agentId");
|
|
@@ -1405,151 +1589,6 @@ async function executeAgentToolHandler(c2) {
|
|
|
1405
1589
|
return handleError(error, "Error executing tool");
|
|
1406
1590
|
}
|
|
1407
1591
|
}
|
|
1408
|
-
async function getAgentsHandler(c2) {
|
|
1409
|
-
const serializedAgents = await getAgentsHandler$1({
|
|
1410
|
-
mastra: c2.get("mastra"),
|
|
1411
|
-
runtimeContext: c2.get("runtimeContext")
|
|
1412
|
-
});
|
|
1413
|
-
return c2.json(serializedAgents);
|
|
1414
|
-
}
|
|
1415
|
-
async function getAgentByIdHandler(c2) {
|
|
1416
|
-
const mastra = c2.get("mastra");
|
|
1417
|
-
const agentId = c2.req.param("agentId");
|
|
1418
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
1419
|
-
const isPlayground = c2.req.header("x-mastra-dev-playground") === "true";
|
|
1420
|
-
const result = await getAgentByIdHandler$1({
|
|
1421
|
-
mastra,
|
|
1422
|
-
agentId,
|
|
1423
|
-
runtimeContext,
|
|
1424
|
-
isPlayground
|
|
1425
|
-
});
|
|
1426
|
-
return c2.json(result);
|
|
1427
|
-
}
|
|
1428
|
-
async function getEvalsByAgentIdHandler(c2) {
|
|
1429
|
-
const mastra = c2.get("mastra");
|
|
1430
|
-
const agentId = c2.req.param("agentId");
|
|
1431
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
1432
|
-
const result = await getEvalsByAgentIdHandler$1({
|
|
1433
|
-
mastra,
|
|
1434
|
-
agentId,
|
|
1435
|
-
runtimeContext
|
|
1436
|
-
});
|
|
1437
|
-
return c2.json(result);
|
|
1438
|
-
}
|
|
1439
|
-
async function getLiveEvalsByAgentIdHandler(c2) {
|
|
1440
|
-
const mastra = c2.get("mastra");
|
|
1441
|
-
const agentId = c2.req.param("agentId");
|
|
1442
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
1443
|
-
const result = await getLiveEvalsByAgentIdHandler$1({
|
|
1444
|
-
mastra,
|
|
1445
|
-
agentId,
|
|
1446
|
-
runtimeContext
|
|
1447
|
-
});
|
|
1448
|
-
return c2.json(result);
|
|
1449
|
-
}
|
|
1450
|
-
async function generateHandler(c2) {
|
|
1451
|
-
try {
|
|
1452
|
-
const mastra = c2.get("mastra");
|
|
1453
|
-
const agentId = c2.req.param("agentId");
|
|
1454
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
1455
|
-
const body = await c2.req.json();
|
|
1456
|
-
const result = await generateHandler$1({
|
|
1457
|
-
mastra,
|
|
1458
|
-
agentId,
|
|
1459
|
-
runtimeContext,
|
|
1460
|
-
body,
|
|
1461
|
-
abortSignal: c2.req.raw.signal
|
|
1462
|
-
});
|
|
1463
|
-
return c2.json(result);
|
|
1464
|
-
} catch (error) {
|
|
1465
|
-
return handleError(error, "Error generating from agent");
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
async function streamGenerateHandler(c2) {
|
|
1469
|
-
try {
|
|
1470
|
-
const mastra = c2.get("mastra");
|
|
1471
|
-
const agentId = c2.req.param("agentId");
|
|
1472
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
1473
|
-
const body = await c2.req.json();
|
|
1474
|
-
const streamResponse = await streamGenerateHandler$1({
|
|
1475
|
-
mastra,
|
|
1476
|
-
agentId,
|
|
1477
|
-
runtimeContext,
|
|
1478
|
-
body,
|
|
1479
|
-
abortSignal: c2.req.raw.signal
|
|
1480
|
-
});
|
|
1481
|
-
return streamResponse;
|
|
1482
|
-
} catch (error) {
|
|
1483
|
-
return handleError(error, "Error streaming from agent");
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
async function streamVNextGenerateHandler(c2) {
|
|
1487
|
-
try {
|
|
1488
|
-
const mastra = c2.get("mastra");
|
|
1489
|
-
const agentId = c2.req.param("agentId");
|
|
1490
|
-
const runtimeContext = c2.get("runtimeContext");
|
|
1491
|
-
const body = await c2.req.json();
|
|
1492
|
-
const logger2 = mastra.getLogger();
|
|
1493
|
-
c2.header("Transfer-Encoding", "chunked");
|
|
1494
|
-
return stream(
|
|
1495
|
-
c2,
|
|
1496
|
-
async (stream6) => {
|
|
1497
|
-
try {
|
|
1498
|
-
const result = streamVNextGenerateHandler$1({
|
|
1499
|
-
mastra,
|
|
1500
|
-
agentId,
|
|
1501
|
-
runtimeContext,
|
|
1502
|
-
body,
|
|
1503
|
-
abortSignal: c2.req.raw.signal
|
|
1504
|
-
});
|
|
1505
|
-
const reader = result.getReader();
|
|
1506
|
-
stream6.onAbort(() => {
|
|
1507
|
-
void reader.cancel("request aborted");
|
|
1508
|
-
});
|
|
1509
|
-
let chunkResult;
|
|
1510
|
-
while ((chunkResult = await reader.read()) && !chunkResult.done) {
|
|
1511
|
-
await stream6.write(JSON.stringify(chunkResult.value) + "");
|
|
1512
|
-
}
|
|
1513
|
-
} catch (err) {
|
|
1514
|
-
logger2.error("Error in streamVNext generate: " + (err?.message ?? "Unknown error"));
|
|
1515
|
-
}
|
|
1516
|
-
await stream6.close();
|
|
1517
|
-
},
|
|
1518
|
-
async (err) => {
|
|
1519
|
-
logger2.error("Error in watch stream: " + err?.message);
|
|
1520
|
-
}
|
|
1521
|
-
);
|
|
1522
|
-
} catch (error) {
|
|
1523
|
-
return handleError(error, "Error streaming from agent");
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
async function setAgentInstructionsHandler(c2) {
|
|
1527
|
-
try {
|
|
1528
|
-
const isPlayground = c2.get("playground") === true;
|
|
1529
|
-
if (!isPlayground) {
|
|
1530
|
-
return c2.json({ error: "This API is only available in the playground environment" }, 403);
|
|
1531
|
-
}
|
|
1532
|
-
const agentId = c2.req.param("agentId");
|
|
1533
|
-
const { instructions } = await c2.req.json();
|
|
1534
|
-
if (!agentId || !instructions) {
|
|
1535
|
-
return c2.json({ error: "Missing required fields" }, 400);
|
|
1536
|
-
}
|
|
1537
|
-
const mastra = c2.get("mastra");
|
|
1538
|
-
const agent = mastra.getAgent(agentId);
|
|
1539
|
-
if (!agent) {
|
|
1540
|
-
return c2.json({ error: "Agent not found" }, 404);
|
|
1541
|
-
}
|
|
1542
|
-
agent.__updateInstructions(instructions);
|
|
1543
|
-
return c2.json(
|
|
1544
|
-
{
|
|
1545
|
-
instructions
|
|
1546
|
-
},
|
|
1547
|
-
200
|
|
1548
|
-
);
|
|
1549
|
-
} catch (error) {
|
|
1550
|
-
return handleError(error, "Error setting agent instructions");
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
1592
|
async function getSpeakersHandler(c2) {
|
|
1554
1593
|
try {
|
|
1555
1594
|
const mastra = c2.get("mastra");
|
|
@@ -1872,6 +1911,48 @@ function agentsRouter(bodyLimitOptions) {
|
|
|
1872
1911
|
}),
|
|
1873
1912
|
streamVNextGenerateHandler
|
|
1874
1913
|
);
|
|
1914
|
+
router.post(
|
|
1915
|
+
"/:agentId/model",
|
|
1916
|
+
bodyLimit(bodyLimitOptions),
|
|
1917
|
+
w({
|
|
1918
|
+
description: "Update the model for an agent",
|
|
1919
|
+
tags: ["agents"],
|
|
1920
|
+
parameters: [
|
|
1921
|
+
{
|
|
1922
|
+
name: "agentId",
|
|
1923
|
+
in: "path",
|
|
1924
|
+
required: true,
|
|
1925
|
+
schema: { type: "string" }
|
|
1926
|
+
}
|
|
1927
|
+
],
|
|
1928
|
+
requestBody: {
|
|
1929
|
+
required: true,
|
|
1930
|
+
content: {
|
|
1931
|
+
"application/json": {
|
|
1932
|
+
schema: {
|
|
1933
|
+
type: "object",
|
|
1934
|
+
properties: {
|
|
1935
|
+
model: {
|
|
1936
|
+
type: "object",
|
|
1937
|
+
description: "The model to update the agent to"
|
|
1938
|
+
}
|
|
1939
|
+
},
|
|
1940
|
+
required: ["model"]
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
},
|
|
1945
|
+
responses: {
|
|
1946
|
+
200: {
|
|
1947
|
+
description: "Model updated successfully"
|
|
1948
|
+
},
|
|
1949
|
+
404: {
|
|
1950
|
+
description: "Agent not found"
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
}),
|
|
1954
|
+
updateAgentModelHandler
|
|
1955
|
+
);
|
|
1875
1956
|
router.get(
|
|
1876
1957
|
"/:agentId/speakers",
|
|
1877
1958
|
async (c2, next) => {
|
|
@@ -9355,6 +9436,7 @@ async function createHonoServer(mastra, options = {
|
|
|
9355
9436
|
}) {
|
|
9356
9437
|
const app = new Hono();
|
|
9357
9438
|
const server = mastra.getServer();
|
|
9439
|
+
const a2aTaskStore = new InMemoryTaskStore();
|
|
9358
9440
|
app.use("*", async function setTelemetryInfo(c2, next) {
|
|
9359
9441
|
const requestId = c2.req.header("x-request-id") ?? randomUUID();
|
|
9360
9442
|
const span = Telemetry.getActiveSpan();
|
|
@@ -9393,6 +9475,7 @@ async function createHonoServer(mastra, options = {
|
|
|
9393
9475
|
c2.set("runtimeContext", runtimeContext);
|
|
9394
9476
|
c2.set("mastra", mastra);
|
|
9395
9477
|
c2.set("tools", options.tools);
|
|
9478
|
+
c2.set("taskStore", a2aTaskStore);
|
|
9396
9479
|
c2.set("playground", options.playground === true);
|
|
9397
9480
|
c2.set("isDev", options.isDev === true);
|
|
9398
9481
|
return next();
|
|
@@ -9467,7 +9550,7 @@ async function createHonoServer(mastra, options = {
|
|
|
9467
9550
|
app.use(logger());
|
|
9468
9551
|
}
|
|
9469
9552
|
app.get(
|
|
9470
|
-
"/.well-known/:agentId/agent.json",
|
|
9553
|
+
"/.well-known/:agentId/agent-card.json",
|
|
9471
9554
|
w({
|
|
9472
9555
|
description: "Get agent configuration",
|
|
9473
9556
|
tags: ["agents"],
|
|
@@ -9509,14 +9592,14 @@ async function createHonoServer(mastra, options = {
|
|
|
9509
9592
|
properties: {
|
|
9510
9593
|
method: {
|
|
9511
9594
|
type: "string",
|
|
9512
|
-
enum: ["
|
|
9595
|
+
enum: ["message/send", "message/stream", "tasks/get", "tasks/cancel"],
|
|
9513
9596
|
description: "The A2A protocol method to execute"
|
|
9514
9597
|
},
|
|
9515
9598
|
params: {
|
|
9516
9599
|
type: "object",
|
|
9517
9600
|
oneOf: [
|
|
9518
9601
|
{
|
|
9519
|
-
//
|
|
9602
|
+
// MessageSendParams
|
|
9520
9603
|
type: "object",
|
|
9521
9604
|
properties: {
|
|
9522
9605
|
id: {
|
|
@@ -9615,6 +9698,19 @@ async function createHonoServer(mastra, options = {
|
|
|
9615
9698
|
}),
|
|
9616
9699
|
rootHandler
|
|
9617
9700
|
);
|
|
9701
|
+
app.get(
|
|
9702
|
+
"/api/model-providers",
|
|
9703
|
+
w({
|
|
9704
|
+
description: "Get all model providers with available keys",
|
|
9705
|
+
tags: ["agents"],
|
|
9706
|
+
responses: {
|
|
9707
|
+
200: {
|
|
9708
|
+
description: "All model providers with available keys"
|
|
9709
|
+
}
|
|
9710
|
+
}
|
|
9711
|
+
}),
|
|
9712
|
+
getModelProvidersHandler
|
|
9713
|
+
);
|
|
9618
9714
|
app.route("/api/agents", agentsRouter(bodyLimitOptions));
|
|
9619
9715
|
app.route("/api/networks", vNextNetworksRouter(bodyLimitOptions));
|
|
9620
9716
|
app.route("/api/networks", networksRouter(bodyLimitOptions));
|
|
@@ -9679,27 +9775,37 @@ async function createHonoServer(mastra, options = {
|
|
|
9679
9775
|
root: "./playground/assets"
|
|
9680
9776
|
})
|
|
9681
9777
|
);
|
|
9682
|
-
app.use(
|
|
9683
|
-
"*",
|
|
9684
|
-
serveStatic({
|
|
9685
|
-
root: "./playground"
|
|
9686
|
-
})
|
|
9687
|
-
);
|
|
9688
9778
|
}
|
|
9689
9779
|
app.get("*", async (c2, next) => {
|
|
9690
9780
|
if (c2.req.path.startsWith("/api/") || c2.req.path.startsWith("/swagger-ui") || c2.req.path.startsWith("/openapi.json")) {
|
|
9691
9781
|
return await next();
|
|
9692
9782
|
}
|
|
9783
|
+
const path = c2.req.path;
|
|
9784
|
+
if (path.includes(".") && !path.endsWith(".html")) {
|
|
9785
|
+
return await next();
|
|
9786
|
+
}
|
|
9693
9787
|
if (options?.playground) {
|
|
9694
9788
|
let indexHtml = await readFile(join(process.cwd(), "./playground/index.html"), "utf-8");
|
|
9695
9789
|
indexHtml = indexHtml.replace(
|
|
9696
9790
|
`'%%MASTRA_TELEMETRY_DISABLED%%'`,
|
|
9697
9791
|
`${Boolean(process.env.MASTRA_TELEMETRY_DISABLED)}`
|
|
9698
9792
|
);
|
|
9793
|
+
const serverOptions = mastra.getServer();
|
|
9794
|
+
const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
|
|
9795
|
+
const host = serverOptions?.host ?? "localhost";
|
|
9796
|
+
indexHtml = indexHtml.replace(`'%%MASTRA_SERVER_URL%%'`, `'http://${host}:${port}'`);
|
|
9699
9797
|
return c2.newResponse(indexHtml, 200, { "Content-Type": "text/html" });
|
|
9700
9798
|
}
|
|
9701
9799
|
return c2.newResponse(html2, 200, { "Content-Type": "text/html" });
|
|
9702
9800
|
});
|
|
9801
|
+
if (options?.playground) {
|
|
9802
|
+
app.use(
|
|
9803
|
+
"*",
|
|
9804
|
+
serveStatic({
|
|
9805
|
+
root: "./playground"
|
|
9806
|
+
})
|
|
9807
|
+
);
|
|
9808
|
+
}
|
|
9703
9809
|
return app;
|
|
9704
9810
|
}
|
|
9705
9811
|
async function createNodeServer(mastra, options = { tools: {} }) {
|