@mastra/server 0.0.0-separate-trace-data-from-component-20250501141108 → 0.0.0-taofeeqInngest-20250603090617

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +48 -135
  2. package/dist/_tsup-dts-rollup.d.cts +282 -92
  3. package/dist/_tsup-dts-rollup.d.ts +282 -92
  4. package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
  5. package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
  6. package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
  7. package/dist/chunk-75ZPJI57.cjs +9 -0
  8. package/dist/{chunk-4BIX6GMY.cjs → chunk-A3KDUGS7.cjs} +78 -28
  9. package/dist/{chunk-7IWQE76Z.cjs → chunk-B4MQFJ7G.cjs} +16 -10
  10. package/dist/{chunk-WTHDCRMY.js → chunk-BFOA2QQY.js} +12 -6
  11. package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
  12. package/dist/{chunk-QJ3AHN64.js → chunk-C7564HUT.js} +4 -3
  13. package/dist/{chunk-55HTWX4C.cjs → chunk-CMMOIUFC.cjs} +40 -19
  14. package/dist/{chunk-Q6SHQECN.js → chunk-CP55EVBK.js} +24 -4
  15. package/dist/{chunk-RBQASTUP.js → chunk-DJJIUEL2.js} +13 -5
  16. package/dist/{chunk-3EJZQ6TQ.js → chunk-DQLE3DVM.js} +5 -5
  17. package/dist/chunk-GHC4YV6R.js +504 -0
  18. package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
  19. package/dist/{chunk-Y3SV5XK4.js → chunk-J3PKLB3A.js} +60 -10
  20. package/dist/{chunk-JPB6RPGB.js → chunk-KUNQFY2W.js} +112 -51
  21. package/dist/chunk-LIVAK2DM.js +2001 -0
  22. package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
  23. package/dist/chunk-MLKGABMK.js +7 -0
  24. package/dist/chunk-MMO2HDM6.cjs +378 -0
  25. package/dist/{chunk-SKBVVI24.cjs → chunk-NEOOQUKW.cjs} +11 -11
  26. package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
  27. package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
  28. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  29. package/dist/{chunk-5JNVY6DU.js → chunk-TJKLBTFB.js} +20 -8
  30. package/dist/{chunk-5YGDYMRB.cjs → chunk-VPNDC2DI.cjs} +14 -13
  31. package/dist/{chunk-M3YJLWTU.js → chunk-W7VCKPAD.js} +62 -51
  32. package/dist/{chunk-2FJURXCL.cjs → chunk-Y7UWRW5X.cjs} +43 -35
  33. package/dist/chunk-YIOVBYZH.cjs +332 -0
  34. package/dist/chunk-YWLUOY3D.cjs +2004 -0
  35. package/dist/{chunk-D3G23FP3.cjs → chunk-ZE5AAC4I.cjs} +37 -25
  36. package/dist/server/handlers/a2a.cjs +30 -0
  37. package/dist/server/handlers/a2a.d.cts +6 -0
  38. package/dist/server/handlers/a2a.d.ts +6 -0
  39. package/dist/server/handlers/a2a.js +1 -0
  40. package/dist/server/handlers/agents.cjs +7 -7
  41. package/dist/server/handlers/agents.js +1 -1
  42. package/dist/server/handlers/error.cjs +2 -2
  43. package/dist/server/handlers/error.js +1 -1
  44. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  45. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  46. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  47. package/dist/server/handlers/legacyWorkflows.js +1 -0
  48. package/dist/server/handlers/logs.cjs +4 -4
  49. package/dist/server/handlers/logs.js +1 -1
  50. package/dist/server/handlers/memory.cjs +9 -9
  51. package/dist/server/handlers/memory.js +1 -1
  52. package/dist/server/handlers/network.cjs +5 -5
  53. package/dist/server/handlers/network.js +1 -1
  54. package/dist/server/handlers/telemetry.cjs +3 -3
  55. package/dist/server/handlers/telemetry.js +1 -1
  56. package/dist/server/handlers/tools.cjs +5 -5
  57. package/dist/server/handlers/tools.js +1 -1
  58. package/dist/server/handlers/utils.cjs +2 -2
  59. package/dist/server/handlers/utils.js +1 -1
  60. package/dist/server/handlers/vector.cjs +7 -7
  61. package/dist/server/handlers/vector.js +1 -1
  62. package/dist/server/handlers/voice.cjs +8 -4
  63. package/dist/server/handlers/voice.d.cts +1 -0
  64. package/dist/server/handlers/voice.d.ts +1 -0
  65. package/dist/server/handlers/voice.js +1 -1
  66. package/dist/server/handlers/workflows.cjs +17 -13
  67. package/dist/server/handlers/workflows.d.cts +3 -2
  68. package/dist/server/handlers/workflows.d.ts +3 -2
  69. package/dist/server/handlers/workflows.js +1 -1
  70. package/dist/server/handlers.cjs +32 -27
  71. package/dist/server/handlers.d.cts +2 -1
  72. package/dist/server/handlers.d.ts +2 -1
  73. package/dist/server/handlers.js +11 -10
  74. package/package.json +7 -5
  75. package/dist/chunk-5SWCVTNL.cjs +0 -5579
  76. package/dist/chunk-AELYAUEE.cjs +0 -316
  77. package/dist/chunk-EVCC233P.cjs +0 -321
  78. package/dist/chunk-OMN3UI6X.js +0 -5576
  79. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  80. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  81. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  82. package/dist/server/handlers/vNextWorkflows.js +0 -1
@@ -0,0 +1,512 @@
1
+ 'use strict';
2
+
3
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
4
+ var a2a = require('@mastra/core/a2a');
5
+ var zod = require('zod');
6
+
7
+ // src/server/handlers/a2a.ts
8
+ var a2a_exports = {};
9
+ chunk75ZPJI57_cjs.__export(a2a_exports, {
10
+ getAgentCardByIdHandler: () => getAgentCardByIdHandler,
11
+ getAgentExecutionHandler: () => getAgentExecutionHandler,
12
+ handleTaskCancel: () => handleTaskCancel,
13
+ handleTaskGet: () => handleTaskGet,
14
+ handleTaskSend: () => handleTaskSend,
15
+ handleTaskSendSubscribe: () => handleTaskSendSubscribe
16
+ });
17
+ function normalizeError(error, reqId, taskId, logger) {
18
+ let a2aError;
19
+ if (error instanceof a2a.A2AError) {
20
+ a2aError = error;
21
+ } else if (error instanceof Error) {
22
+ a2aError = a2a.A2AError.internalError(error.message, { stack: error.stack });
23
+ } else {
24
+ a2aError = a2a.A2AError.internalError("An unknown error occurred.", error);
25
+ }
26
+ if (taskId && !a2aError.taskId) {
27
+ a2aError.taskId = taskId;
28
+ }
29
+ logger?.error(`Error processing request (Task: ${a2aError.taskId ?? "N/A"}, ReqID: ${reqId ?? "N/A"}):`, a2aError);
30
+ return createErrorResponse(reqId, a2aError.toJSONRPCError());
31
+ }
32
+ function createErrorResponse(id, error) {
33
+ return {
34
+ jsonrpc: "2.0",
35
+ id,
36
+ // Can be null if request ID was invalid/missing
37
+ error
38
+ };
39
+ }
40
+ function createSuccessResponse(id, result) {
41
+ if (!id) {
42
+ throw a2a.A2AError.internalError("Cannot create success response for null ID.");
43
+ }
44
+ return {
45
+ jsonrpc: "2.0",
46
+ id,
47
+ result
48
+ };
49
+ }
50
+ function convertToCoreMessage(message) {
51
+ return {
52
+ role: message.role === "user" ? "user" : "assistant",
53
+ content: message.parts.map((msg) => convertToCoreMessagePart(msg))
54
+ };
55
+ }
56
+ function convertToCoreMessagePart(part) {
57
+ switch (part.type) {
58
+ case "text":
59
+ return {
60
+ type: "text",
61
+ text: part.text
62
+ };
63
+ case "file":
64
+ return {
65
+ type: "file",
66
+ data: new URL(part.file.uri),
67
+ mimeType: part.file.mimeType
68
+ };
69
+ case "data":
70
+ throw new Error("Data parts are not supported in core messages");
71
+ }
72
+ }
73
+
74
+ // src/server/a2a/store.ts
75
+ var InMemoryTaskStore = class {
76
+ store = /* @__PURE__ */ new Map();
77
+ activeCancellations = /* @__PURE__ */ new Set();
78
+ async load({ agentId, taskId }) {
79
+ const entry = this.store.get(`${agentId}-${taskId}`);
80
+ if (!entry) {
81
+ return null;
82
+ }
83
+ return { task: { ...entry.task }, history: [...entry.history] };
84
+ }
85
+ async save({ agentId, data }) {
86
+ const key = `${agentId}-${data.task.id}`;
87
+ if (!data.task.id) {
88
+ throw new Error("Task ID is required");
89
+ }
90
+ this.store.set(key, {
91
+ task: { ...data.task },
92
+ history: [...data.history]
93
+ });
94
+ }
95
+ };
96
+
97
+ // src/server/a2a/tasks.ts
98
+ function isTaskStatusUpdate(update) {
99
+ return "state" in update && !("parts" in update);
100
+ }
101
+ function isArtifactUpdate(update) {
102
+ return "parts" in update;
103
+ }
104
+ function applyUpdateToTaskAndHistory(current, update) {
105
+ let newTask = structuredClone(current.task);
106
+ let newHistory = structuredClone(current.history);
107
+ if (isTaskStatusUpdate(update)) {
108
+ newTask.status = {
109
+ ...newTask.status,
110
+ // Keep existing properties if not overwritten
111
+ ...update,
112
+ // Apply updates
113
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
114
+ };
115
+ if (update.message?.role === "agent") {
116
+ newHistory.push(update.message);
117
+ }
118
+ } else if (isArtifactUpdate(update)) {
119
+ if (!newTask.artifacts) {
120
+ newTask.artifacts = [];
121
+ } else {
122
+ newTask.artifacts = [...newTask.artifacts];
123
+ }
124
+ const existingIndex = update.index ?? -1;
125
+ let replaced = false;
126
+ if (existingIndex >= 0 && existingIndex < newTask.artifacts.length) {
127
+ const existingArtifact = newTask.artifacts[existingIndex];
128
+ if (update.append) {
129
+ const appendedArtifact = JSON.parse(JSON.stringify(existingArtifact));
130
+ appendedArtifact.parts.push(...update.parts);
131
+ if (update.metadata) {
132
+ appendedArtifact.metadata = {
133
+ ...appendedArtifact.metadata || {},
134
+ ...update.metadata
135
+ };
136
+ }
137
+ if (update.lastChunk !== void 0) appendedArtifact.lastChunk = update.lastChunk;
138
+ if (update.description) appendedArtifact.description = update.description;
139
+ newTask.artifacts[existingIndex] = appendedArtifact;
140
+ replaced = true;
141
+ } else {
142
+ newTask.artifacts[existingIndex] = { ...update };
143
+ replaced = true;
144
+ }
145
+ } else if (update.name) {
146
+ const namedIndex = newTask.artifacts.findIndex((a) => a.name === update.name);
147
+ if (namedIndex >= 0) {
148
+ newTask.artifacts[namedIndex] = { ...update };
149
+ replaced = true;
150
+ }
151
+ }
152
+ if (!replaced) {
153
+ newTask.artifacts.push({ ...update });
154
+ if (newTask.artifacts.some((a) => a.index !== void 0)) {
155
+ newTask.artifacts.sort((a, b) => (a.index ?? 0) - (b.index ?? 0));
156
+ }
157
+ }
158
+ }
159
+ return { task: newTask, history: newHistory };
160
+ }
161
+ async function loadOrCreateTaskAndHistory({
162
+ agentId,
163
+ taskId,
164
+ taskStore,
165
+ message,
166
+ sessionId,
167
+ metadata,
168
+ logger
169
+ }) {
170
+ const data = await taskStore.load({ agentId, taskId });
171
+ if (!data) {
172
+ const initialTask = {
173
+ id: taskId,
174
+ sessionId,
175
+ status: {
176
+ state: "submitted",
177
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
178
+ message: null
179
+ },
180
+ artifacts: [],
181
+ metadata
182
+ };
183
+ const initialData = {
184
+ task: initialTask,
185
+ history: [message]
186
+ };
187
+ logger?.info(`[Task ${taskId}] Created new task and history.`);
188
+ await taskStore.save({ agentId, data: initialData });
189
+ return initialData;
190
+ }
191
+ logger?.info(`[Task ${taskId}] Loaded existing task and history.`);
192
+ let updatedData = {
193
+ task: data.task,
194
+ history: [...data.history, message]
195
+ };
196
+ const { status } = data.task;
197
+ const finalStates = ["completed", "failed", "canceled"];
198
+ if (finalStates.includes(status.state)) {
199
+ logger?.warn(`[Task ${taskId}] Received message for task in final state ${status.state}. Restarting.`);
200
+ updatedData = applyUpdateToTaskAndHistory(updatedData, {
201
+ state: "submitted",
202
+ message: null
203
+ });
204
+ } else if (status.state === "input-required") {
205
+ logger?.info(`[Task ${taskId}] Changing state from 'input-required' to 'working'.`);
206
+ updatedData = applyUpdateToTaskAndHistory(updatedData, { state: "working" });
207
+ } else if (status.state === "working") {
208
+ logger?.warn(`[Task ${taskId}] Received message while already 'working'. Proceeding.`);
209
+ }
210
+ await taskStore.save({ agentId, data: updatedData });
211
+ return {
212
+ task: { ...updatedData.task },
213
+ history: [...updatedData.history]
214
+ };
215
+ }
216
+ function createTaskContext({
217
+ task,
218
+ userMessage,
219
+ history,
220
+ activeCancellations
221
+ }) {
222
+ return {
223
+ task: structuredClone(task),
224
+ userMessage,
225
+ history: structuredClone(history),
226
+ isCancelled: () => activeCancellations.has(task.id)
227
+ };
228
+ }
229
+
230
+ // src/server/handlers/a2a.ts
231
+ var taskSendParamsSchema = zod.z.object({
232
+ id: zod.z.string().min(1, "Invalid or missing task ID (params.id)."),
233
+ message: zod.z.object({
234
+ parts: zod.z.array(
235
+ zod.z.object({
236
+ type: zod.z.enum(["text"]),
237
+ text: zod.z.string()
238
+ })
239
+ )
240
+ })
241
+ });
242
+ async function getAgentCardByIdHandler({
243
+ mastra,
244
+ agentId,
245
+ executionUrl = `/a2a/${agentId}`,
246
+ provider = {
247
+ organization: "Mastra",
248
+ url: "https://mastra.ai"
249
+ },
250
+ version = "1.0",
251
+ runtimeContext
252
+ }) {
253
+ const agent = mastra.getAgent(agentId);
254
+ if (!agent) {
255
+ throw new Error(`Agent with ID ${agentId} not found`);
256
+ }
257
+ const [instructions, tools] = await Promise.all([
258
+ agent.getInstructions({ runtimeContext }),
259
+ agent.getTools({ runtimeContext })
260
+ ]);
261
+ const agentCard = {
262
+ name: agent.id || agentId,
263
+ description: instructions,
264
+ url: executionUrl,
265
+ provider,
266
+ version,
267
+ capabilities: {
268
+ streaming: true,
269
+ // All agents support streaming
270
+ pushNotifications: false,
271
+ stateTransitionHistory: false
272
+ },
273
+ defaultInputModes: ["text"],
274
+ defaultOutputModes: ["text"],
275
+ // Convert agent tools to skills format for A2A protocol
276
+ skills: Object.entries(tools).map(([toolId, tool]) => ({
277
+ id: toolId,
278
+ name: toolId,
279
+ description: tool.description || `Tool: ${toolId}`,
280
+ // Optional fields
281
+ tags: ["tool"]
282
+ }))
283
+ };
284
+ return agentCard;
285
+ }
286
+ function validateTaskSendParams(params) {
287
+ try {
288
+ taskSendParamsSchema.parse(params);
289
+ } catch (error) {
290
+ if (error instanceof zod.z.ZodError) {
291
+ throw a2a.A2AError.invalidParams(error.errors[0].message);
292
+ }
293
+ throw error;
294
+ }
295
+ }
296
+ async function handleTaskSend({
297
+ requestId,
298
+ params,
299
+ taskStore,
300
+ agent,
301
+ agentId,
302
+ logger,
303
+ runtimeContext
304
+ }) {
305
+ validateTaskSendParams(params);
306
+ const { id: taskId, message, sessionId, metadata } = params;
307
+ let currentData = await loadOrCreateTaskAndHistory({
308
+ taskId,
309
+ taskStore,
310
+ agentId,
311
+ message,
312
+ sessionId,
313
+ metadata
314
+ });
315
+ createTaskContext({
316
+ task: currentData.task,
317
+ userMessage: message,
318
+ history: currentData.history,
319
+ activeCancellations: taskStore.activeCancellations
320
+ });
321
+ try {
322
+ const { text } = await agent.generate([convertToCoreMessage(message)], {
323
+ runId: taskId,
324
+ runtimeContext
325
+ });
326
+ currentData = applyUpdateToTaskAndHistory(currentData, {
327
+ state: "completed",
328
+ message: {
329
+ role: "agent",
330
+ parts: [
331
+ {
332
+ type: "text",
333
+ text
334
+ }
335
+ ]
336
+ }
337
+ });
338
+ await taskStore.save({ agentId, data: currentData });
339
+ } catch (handlerError) {
340
+ const failureStatusUpdate = {
341
+ state: "failed",
342
+ message: {
343
+ role: "agent",
344
+ parts: [
345
+ {
346
+ type: "text",
347
+ text: `Handler failed: ${handlerError instanceof Error ? handlerError.message : String(handlerError)}`
348
+ }
349
+ ]
350
+ }
351
+ };
352
+ currentData = applyUpdateToTaskAndHistory(currentData, failureStatusUpdate);
353
+ try {
354
+ await taskStore.save({ agentId, data: currentData });
355
+ } catch (saveError) {
356
+ logger?.error(`Failed to save task ${taskId} after handler error:`, saveError?.message);
357
+ }
358
+ return normalizeError(handlerError, requestId, taskId, logger);
359
+ }
360
+ return createSuccessResponse(requestId, currentData.task);
361
+ }
362
+ async function handleTaskGet({
363
+ requestId,
364
+ taskStore,
365
+ agentId,
366
+ taskId
367
+ }) {
368
+ const task = await taskStore.load({ agentId, taskId });
369
+ if (!task) {
370
+ throw a2a.A2AError.taskNotFound(taskId);
371
+ }
372
+ return createSuccessResponse(requestId, task);
373
+ }
374
+ async function* handleTaskSendSubscribe({
375
+ requestId,
376
+ params,
377
+ taskStore,
378
+ agent,
379
+ agentId,
380
+ logger,
381
+ runtimeContext
382
+ }) {
383
+ yield createSuccessResponse(requestId, {
384
+ state: "working",
385
+ message: {
386
+ role: "agent",
387
+ parts: [{ type: "text", text: "Generating response..." }]
388
+ }
389
+ });
390
+ let result;
391
+ try {
392
+ result = await handleTaskSend({
393
+ requestId,
394
+ params,
395
+ taskStore,
396
+ agent,
397
+ agentId,
398
+ runtimeContext,
399
+ logger
400
+ });
401
+ } catch (err) {
402
+ if (!(err instanceof a2a.A2AError)) {
403
+ throw err;
404
+ }
405
+ result = createErrorResponse(requestId, err.toJSONRPCError());
406
+ }
407
+ yield result;
408
+ }
409
+ async function handleTaskCancel({
410
+ requestId,
411
+ taskStore,
412
+ agentId,
413
+ taskId,
414
+ logger
415
+ }) {
416
+ let data = await taskStore.load({
417
+ agentId,
418
+ taskId
419
+ });
420
+ if (!data) {
421
+ throw a2a.A2AError.taskNotFound(taskId);
422
+ }
423
+ const finalStates = ["completed", "failed", "canceled"];
424
+ if (finalStates.includes(data.task.status.state)) {
425
+ logger?.info(`Task ${taskId} already in final state ${data.task.status.state}, cannot cancel.`);
426
+ return createSuccessResponse(requestId, data.task);
427
+ }
428
+ taskStore.activeCancellations.add(taskId);
429
+ const cancelUpdate = {
430
+ state: "canceled",
431
+ message: {
432
+ role: "agent",
433
+ parts: [{ type: "text", text: "Task cancelled by request." }]
434
+ }
435
+ };
436
+ data = applyUpdateToTaskAndHistory(data, cancelUpdate);
437
+ await taskStore.save({ agentId, data });
438
+ taskStore.activeCancellations.delete(taskId);
439
+ return createSuccessResponse(requestId, data.task);
440
+ }
441
+ async function getAgentExecutionHandler({
442
+ requestId,
443
+ mastra,
444
+ agentId,
445
+ runtimeContext,
446
+ method,
447
+ params,
448
+ taskStore = new InMemoryTaskStore(),
449
+ logger
450
+ }) {
451
+ const agent = mastra.getAgent(agentId);
452
+ let taskId;
453
+ try {
454
+ taskId = params.id;
455
+ switch (method) {
456
+ case "tasks/send": {
457
+ const result2 = await handleTaskSend({
458
+ requestId,
459
+ params,
460
+ taskStore,
461
+ agent,
462
+ agentId,
463
+ runtimeContext
464
+ });
465
+ return result2;
466
+ }
467
+ case "tasks/sendSubscribe":
468
+ const result = await handleTaskSendSubscribe({
469
+ requestId,
470
+ taskStore,
471
+ params,
472
+ agent,
473
+ agentId,
474
+ runtimeContext
475
+ });
476
+ return result;
477
+ case "tasks/get": {
478
+ const result2 = await handleTaskGet({
479
+ requestId,
480
+ taskStore,
481
+ agentId,
482
+ taskId
483
+ });
484
+ return result2;
485
+ }
486
+ case "tasks/cancel": {
487
+ const result2 = await handleTaskCancel({
488
+ requestId,
489
+ taskStore,
490
+ agentId,
491
+ taskId
492
+ });
493
+ return result2;
494
+ }
495
+ default:
496
+ throw a2a.A2AError.methodNotFound(method);
497
+ }
498
+ } catch (error) {
499
+ if (error instanceof a2a.A2AError && taskId && !error.taskId) {
500
+ error.taskId = taskId;
501
+ }
502
+ return normalizeError(error, requestId, taskId, logger);
503
+ }
504
+ }
505
+
506
+ exports.a2a_exports = a2a_exports;
507
+ exports.getAgentCardByIdHandler = getAgentCardByIdHandler;
508
+ exports.getAgentExecutionHandler = getAgentExecutionHandler;
509
+ exports.handleTaskCancel = handleTaskCancel;
510
+ exports.handleTaskGet = handleTaskGet;
511
+ exports.handleTaskSend = handleTaskSend;
512
+ exports.handleTaskSendSubscribe = handleTaskSendSubscribe;
@@ -1,7 +1,9 @@
1
- import { stringify, esm_default } from './chunk-OMN3UI6X.js';
2
- import { validateBody } from './chunk-L7XE5QTW.js';
3
- import { handleError } from './chunk-3AHQ5RGN.js';
4
- import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
1
+ import { stringify, esm_default } from './chunk-LIVAK2DM.js';
2
+ import { validateBody } from './chunk-H5PTF3Y4.js';
3
+ import { handleError } from './chunk-M5ABIP7D.js';
4
+ import { HTTPException } from './chunk-NYN7KFXL.js';
5
+ import { __export } from './chunk-MLKGABMK.js';
6
+ import { RuntimeContext } from '@mastra/core/di';
5
7
  import { isVercelTool } from '@mastra/core/tools';
6
8
 
7
9
  // src/server/handlers/tools.ts
@@ -56,7 +58,8 @@ function executeToolHandler(tools) {
56
58
  runId,
57
59
  toolId,
58
60
  data,
59
- runtimeContext
61
+ runtimeContext,
62
+ runtimeContextFromRequest
60
63
  }) => {
61
64
  try {
62
65
  if (!toolId) {
@@ -74,11 +77,15 @@ function executeToolHandler(tools) {
74
77
  const result2 = await tool.execute(data);
75
78
  return result2;
76
79
  }
80
+ const finalRuntimeContext = new RuntimeContext([
81
+ ...Array.from(runtimeContext.entries()),
82
+ ...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
83
+ ]);
77
84
  const result = await tool.execute({
78
85
  context: data,
79
86
  mastra,
80
87
  runId,
81
- runtimeContext
88
+ runtimeContext: finalRuntimeContext
82
89
  });
83
90
  return result;
84
91
  } catch (error) {
@@ -91,7 +98,8 @@ async function executeAgentToolHandler({
91
98
  agentId,
92
99
  toolId,
93
100
  data,
94
- runtimeContext
101
+ runtimeContext,
102
+ runtimeContextFromRequest
95
103
  }) {
96
104
  try {
97
105
  const agent = agentId ? mastra.getAgent(agentId) : null;
@@ -105,9 +113,13 @@ async function executeAgentToolHandler({
105
113
  if (!tool?.execute) {
106
114
  throw new HTTPException(400, { message: "Tool is not executable" });
107
115
  }
116
+ const finalRuntimeContext = new RuntimeContext([
117
+ ...Array.from(runtimeContext.entries()),
118
+ ...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
119
+ ]);
108
120
  const result = await tool.execute({
109
121
  context: data,
110
- runtimeContext,
122
+ runtimeContext: finalRuntimeContext,
111
123
  mastra,
112
124
  runId: agentId
113
125
  });
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
4
- var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
5
- var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
3
+ var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
4
+ var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
5
+ var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
6
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
6
7
 
7
8
  // src/server/handlers/network.ts
8
9
  var network_exports = {};
9
- chunkFV45V6WC_cjs.__export(network_exports, {
10
+ chunk75ZPJI57_cjs.__export(network_exports, {
10
11
  generateHandler: () => generateHandler,
11
12
  getNetworkByIdHandler: () => getNetworkByIdHandler,
12
13
  getNetworksHandler: () => getNetworksHandler,
@@ -46,7 +47,7 @@ async function getNetworksHandler({
46
47
  );
47
48
  return serializedNetworks;
48
49
  } catch (error) {
49
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting networks");
50
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting networks");
50
51
  }
51
52
  }
52
53
  async function getNetworkByIdHandler({
@@ -61,7 +62,7 @@ async function getNetworkByIdHandler({
61
62
  return network2.formatAgentId(routingAgent2.name) === networkId;
62
63
  });
63
64
  if (!network) {
64
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Network not found" });
65
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
65
66
  }
66
67
  const routingAgent = network.getRoutingAgent();
67
68
  const routingLLM = await routingAgent.getLLM({ runtimeContext });
@@ -87,7 +88,7 @@ async function getNetworkByIdHandler({
87
88
  };
88
89
  return serializedNetwork;
89
90
  } catch (error) {
90
- return chunkZLBRQFDD_cjs.handleError(error, "Error getting network by ID");
91
+ return chunk64U3UDTH_cjs.handleError(error, "Error getting network by ID");
91
92
  }
92
93
  }
93
94
  async function generateHandler({
@@ -99,14 +100,14 @@ async function generateHandler({
99
100
  try {
100
101
  const network = mastra.getNetwork(networkId);
101
102
  if (!network) {
102
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Network not found" });
103
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
103
104
  }
104
- chunkQN4KF3BH_cjs.validateBody({ messages: body.messages });
105
+ chunk57CJTIPW_cjs.validateBody({ messages: body.messages });
105
106
  const { messages, ...rest } = body;
106
107
  const result = await network.generate(messages, { ...rest, runtimeContext });
107
108
  return result;
108
109
  } catch (error) {
109
- return chunkZLBRQFDD_cjs.handleError(error, "Error generating from network");
110
+ return chunk64U3UDTH_cjs.handleError(error, "Error generating from network");
110
111
  }
111
112
  }
112
113
  async function streamGenerateHandler({
@@ -118,9 +119,9 @@ async function streamGenerateHandler({
118
119
  try {
119
120
  const network = mastra.getNetwork(networkId);
120
121
  if (!network) {
121
- throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Network not found" });
122
+ throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
122
123
  }
123
- chunkQN4KF3BH_cjs.validateBody({ messages: body.messages });
124
+ chunk57CJTIPW_cjs.validateBody({ messages: body.messages });
124
125
  const { messages, output, ...rest } = body;
125
126
  const streamResult = await network.stream(messages, {
126
127
  output,
@@ -136,7 +137,7 @@ async function streamGenerateHandler({
136
137
  });
137
138
  return streamResponse;
138
139
  } catch (error) {
139
- return chunkZLBRQFDD_cjs.handleError(error, "Error streaming from network");
140
+ return chunk64U3UDTH_cjs.handleError(error, "Error streaming from network");
140
141
  }
141
142
  }
142
143