@mastra/server 0.0.0-generate-message-id-20250512171942 → 0.0.0-http-transporter-20250702160118

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 (85) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +394 -128
  2. package/dist/_tsup-dts-rollup.d.ts +394 -128
  3. package/dist/{chunk-OCWPVYNI.cjs → chunk-2KZFMI6P.cjs} +1 -0
  4. package/dist/{chunk-VPNDC2DI.cjs → chunk-2SLFAFTR.cjs} +12 -12
  5. package/dist/chunk-4D66QEKC.js +81 -0
  6. package/dist/{chunk-EJO45KYT.js → chunk-5PQQ42EZ.js} +43 -43
  7. package/dist/{chunk-4YZ3U35L.cjs → chunk-7TP2LX5L.cjs} +18 -18
  8. package/dist/chunk-B2PAS2IB.cjs +514 -0
  9. package/dist/{chunk-Q6KMBIAN.js → chunk-BK4XT6EG.js} +93 -14
  10. package/dist/{chunk-57CJTIPW.cjs → chunk-CCGRCYWJ.cjs} +2 -2
  11. package/dist/{chunk-C7564HUT.js → chunk-CRCR3ZUK.js} +3 -3
  12. package/dist/{chunk-24EGIVT7.cjs → chunk-DN7K6FJK.cjs} +91 -54
  13. package/dist/{chunk-ZE5AAC4I.cjs → chunk-FRVBFMO2.cjs} +26 -36
  14. package/dist/{chunk-MHKNLNAN.cjs → chunk-G7KH752Y.cjs} +10 -7
  15. package/dist/{chunk-P6SCPDYW.js → chunk-GHC4YV6R.js} +5 -1
  16. package/dist/chunk-H7DMHBKY.js +498 -0
  17. package/dist/chunk-JMLYCXMK.cjs +332 -0
  18. package/dist/{chunk-HFWCEP5S.js → chunk-KHZKYUNR.js} +33 -10
  19. package/dist/{chunk-NYN7KFXL.js → chunk-LCM566I4.js} +1 -0
  20. package/dist/chunk-LF7P5PLR.js +14 -0
  21. package/dist/{chunk-YWLUOY3D.cjs → chunk-LI436ITD.cjs} +107 -69
  22. package/dist/{chunk-TJKLBTFB.js → chunk-LRCAAFUA.js} +10 -20
  23. package/dist/{chunk-3HQNCTZ2.cjs → chunk-LZ3VJXSO.cjs} +107 -28
  24. package/dist/{chunk-LIVAK2DM.js → chunk-MEGCYGBU.js} +108 -70
  25. package/dist/{chunk-X3ZDCS52.js → chunk-MKLYEKEF.js} +62 -25
  26. package/dist/chunk-PZQDCRPV.cjs +16 -0
  27. package/dist/chunk-QGX47B5D.cjs +86 -0
  28. package/dist/{chunk-OR3CIE2H.js → chunk-RG473F6Y.js} +7 -4
  29. package/dist/chunk-RHSWAXKB.cjs +118 -0
  30. package/dist/{chunk-H5PTF3Y4.js → chunk-RSEO4XPX.js} +1 -1
  31. package/dist/{chunk-5SN4U5AC.cjs → chunk-SDPGVWQJ.cjs} +5 -1
  32. package/dist/{chunk-IU5VO2I2.js → chunk-WNVFNNWN.js} +4 -4
  33. package/dist/server/handlers/a2a.cjs +7 -7
  34. package/dist/server/handlers/a2a.js +1 -1
  35. package/dist/server/handlers/agents.cjs +7 -7
  36. package/dist/server/handlers/agents.js +1 -1
  37. package/dist/server/handlers/error.cjs +2 -2
  38. package/dist/server/handlers/error.js +1 -1
  39. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  40. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  41. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  42. package/dist/server/handlers/legacyWorkflows.js +1 -0
  43. package/dist/server/handlers/logs.cjs +4 -4
  44. package/dist/server/handlers/logs.js +1 -1
  45. package/dist/server/handlers/memory.cjs +9 -9
  46. package/dist/server/handlers/memory.js +1 -1
  47. package/dist/server/handlers/network.cjs +5 -5
  48. package/dist/server/handlers/network.js +1 -1
  49. package/dist/server/handlers/telemetry.cjs +3 -3
  50. package/dist/server/handlers/telemetry.js +1 -1
  51. package/dist/server/handlers/tools.cjs +5 -5
  52. package/dist/server/handlers/tools.js +1 -1
  53. package/dist/server/handlers/utils.cjs +2 -2
  54. package/dist/server/handlers/utils.js +1 -1
  55. package/dist/server/handlers/vNextNetwork.cjs +218 -0
  56. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  57. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  58. package/dist/server/handlers/vNextNetwork.js +211 -0
  59. package/dist/server/handlers/vector.cjs +7 -7
  60. package/dist/server/handlers/vector.js +1 -1
  61. package/dist/server/handlers/voice.cjs +8 -4
  62. package/dist/server/handlers/voice.d.cts +1 -0
  63. package/dist/server/handlers/voice.d.ts +1 -0
  64. package/dist/server/handlers/voice.js +1 -1
  65. package/dist/server/handlers/workflows.cjs +29 -13
  66. package/dist/server/handlers/workflows.d.cts +6 -2
  67. package/dist/server/handlers/workflows.d.ts +6 -2
  68. package/dist/server/handlers/workflows.js +1 -1
  69. package/dist/server/handlers.cjs +28 -28
  70. package/dist/server/handlers.d.cts +1 -1
  71. package/dist/server/handlers.d.ts +1 -1
  72. package/dist/server/handlers.js +11 -11
  73. package/package.json +12 -13
  74. package/dist/chunk-64U3UDTH.cjs +0 -13
  75. package/dist/chunk-HWZVAG3H.js +0 -49
  76. package/dist/chunk-I2B73Y4I.cjs +0 -332
  77. package/dist/chunk-M5ABIP7D.js +0 -11
  78. package/dist/chunk-MIQYDLLM.js +0 -329
  79. package/dist/chunk-OGCNNUHF.cjs +0 -54
  80. package/dist/chunk-UCTEMO2Q.cjs +0 -341
  81. package/dist/chunk-YBVOQN4M.cjs +0 -94
  82. package/dist/server/handlers/vNextWorkflows.cjs +0 -46
  83. package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
  84. package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
  85. package/dist/server/handlers/vNextWorkflows.js +0 -1
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkYWLUOY3D_cjs = require('./chunk-YWLUOY3D.cjs');
4
- var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
5
- var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
6
- var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
3
+ var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
4
+ var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
5
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
6
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
7
7
  var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
8
8
  var runtimeContext = require('@mastra/core/runtime-context');
9
9
 
@@ -25,22 +25,44 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
25
25
  const instructions = await agent.getInstructions({ runtimeContext });
26
26
  const tools = await agent.getTools({ runtimeContext });
27
27
  const llm = await agent.getLLM({ runtimeContext });
28
+ const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
29
+ const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
28
30
  const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
29
31
  const _tool = tool;
30
32
  acc[key] = {
31
33
  ..._tool,
32
- inputSchema: _tool.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(_tool.inputSchema)) : void 0,
33
- outputSchema: _tool.outputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(_tool.outputSchema)) : void 0
34
+ inputSchema: _tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_tool.inputSchema)) : void 0,
35
+ outputSchema: _tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_tool.outputSchema)) : void 0
34
36
  };
35
37
  return acc;
36
38
  }, {});
39
+ let serializedAgentWorkflows = {};
40
+ if ("getWorkflows" in agent) {
41
+ const logger = mastra.getLogger();
42
+ try {
43
+ const workflows = await agent.getWorkflows({ runtimeContext });
44
+ serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
45
+ return {
46
+ ...acc,
47
+ [key]: {
48
+ name: workflow.name
49
+ }
50
+ };
51
+ }, {});
52
+ } catch (error) {
53
+ logger.error("Error getting workflows for agent", { agentName: agent.name, error });
54
+ }
55
+ }
37
56
  return {
38
57
  id,
39
58
  name: agent.name,
40
59
  instructions,
41
60
  tools: serializedAgentTools,
61
+ workflows: serializedAgentWorkflows,
42
62
  provider: llm?.getProvider(),
43
- modelId: llm?.getModelId()
63
+ modelId: llm?.getModelId(),
64
+ defaultGenerateOptions,
65
+ defaultStreamOptions
44
66
  };
45
67
  })
46
68
  );
@@ -50,40 +72,86 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
50
72
  }, {});
51
73
  return serializedAgents;
52
74
  } catch (error) {
53
- return chunk64U3UDTH_cjs.handleError(error, "Error getting agents");
75
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting agents");
54
76
  }
55
77
  }
56
78
  async function getAgentByIdHandler({
57
79
  mastra,
58
80
  runtimeContext,
59
- agentId
81
+ agentId,
82
+ isPlayground = false
60
83
  }) {
61
84
  try {
62
85
  const agent = mastra.getAgent(agentId);
63
86
  if (!agent) {
64
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
87
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
65
88
  }
66
89
  const tools = await agent.getTools({ runtimeContext });
67
90
  const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
68
91
  const _tool = tool;
69
92
  acc[key] = {
70
93
  ..._tool,
71
- inputSchema: _tool.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(_tool.inputSchema)) : void 0,
72
- outputSchema: _tool.outputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(_tool.outputSchema)) : void 0
94
+ inputSchema: _tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_tool.inputSchema)) : void 0,
95
+ outputSchema: _tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_tool.outputSchema)) : void 0
73
96
  };
74
97
  return acc;
75
98
  }, {});
76
- const instructions = await agent.getInstructions({ runtimeContext });
99
+ let serializedAgentWorkflows = {};
100
+ if ("getWorkflows" in agent) {
101
+ const logger = mastra.getLogger();
102
+ try {
103
+ const workflows = await agent.getWorkflows({ runtimeContext });
104
+ serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
105
+ return {
106
+ ...acc,
107
+ [key]: {
108
+ name: workflow.name,
109
+ steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
110
+ return {
111
+ ...acc2,
112
+ [key2]: {
113
+ id: step.id,
114
+ description: step.description
115
+ }
116
+ };
117
+ }, {})
118
+ }
119
+ };
120
+ }, {});
121
+ } catch (error) {
122
+ logger.error("Error getting workflows for agent", { agentName: agent.name, error });
123
+ }
124
+ }
125
+ let proxyRuntimeContext = runtimeContext;
126
+ if (isPlayground) {
127
+ proxyRuntimeContext = new Proxy(runtimeContext, {
128
+ get(target, prop) {
129
+ if (prop === "get") {
130
+ return function(key) {
131
+ const value = target.get(key);
132
+ return value ?? `<${key}>`;
133
+ };
134
+ }
135
+ return Reflect.get(target, prop);
136
+ }
137
+ });
138
+ }
139
+ const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
77
140
  const llm = await agent.getLLM({ runtimeContext });
141
+ const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
142
+ const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
78
143
  return {
79
144
  name: agent.name,
80
145
  instructions,
81
146
  tools: serializedAgentTools,
147
+ workflows: serializedAgentWorkflows,
82
148
  provider: llm?.getProvider(),
83
- modelId: llm?.getModelId()
149
+ modelId: llm?.getModelId(),
150
+ defaultGenerateOptions,
151
+ defaultStreamOptions
84
152
  };
85
153
  } catch (error) {
86
- return chunk64U3UDTH_cjs.handleError(error, "Error getting agent");
154
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting agent");
87
155
  }
88
156
  }
89
157
  async function getEvalsByAgentIdHandler({
@@ -102,7 +170,7 @@ async function getEvalsByAgentIdHandler({
102
170
  evals
103
171
  };
104
172
  } catch (error) {
105
- return chunk64U3UDTH_cjs.handleError(error, "Error getting test evals");
173
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting test evals");
106
174
  }
107
175
  }
108
176
  async function getLiveEvalsByAgentIdHandler({
@@ -121,19 +189,20 @@ async function getLiveEvalsByAgentIdHandler({
121
189
  evals
122
190
  };
123
191
  } catch (error) {
124
- return chunk64U3UDTH_cjs.handleError(error, "Error getting live evals");
192
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting live evals");
125
193
  }
126
194
  }
127
195
  async function generateHandler({
128
196
  mastra,
129
197
  runtimeContext: runtimeContext$1,
130
198
  agentId,
131
- body
199
+ body,
200
+ abortSignal
132
201
  }) {
133
202
  try {
134
203
  const agent = mastra.getAgent(agentId);
135
204
  if (!agent) {
136
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
205
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
137
206
  }
138
207
  const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
139
208
  const finalResourceId = resourceId ?? resourceid;
@@ -141,28 +210,30 @@ async function generateHandler({
141
210
  ...Array.from(runtimeContext$1.entries()),
142
211
  ...Array.from(Object.entries(agentRuntimeContext ?? {}))
143
212
  ]);
144
- chunk57CJTIPW_cjs.validateBody({ messages });
213
+ chunkCCGRCYWJ_cjs.validateBody({ messages });
145
214
  const result = await agent.generate(messages, {
146
215
  ...rest,
147
216
  // @ts-expect-error TODO fix types
148
217
  resourceId: finalResourceId,
149
- runtimeContext: finalRuntimeContext
218
+ runtimeContext: finalRuntimeContext,
219
+ signal: abortSignal
150
220
  });
151
221
  return result;
152
222
  } catch (error) {
153
- return chunk64U3UDTH_cjs.handleError(error, "Error generating from agent");
223
+ return chunkPZQDCRPV_cjs.handleError(error, "Error generating from agent");
154
224
  }
155
225
  }
156
226
  async function streamGenerateHandler({
157
227
  mastra,
158
228
  runtimeContext: runtimeContext$1,
159
229
  agentId,
160
- body
230
+ body,
231
+ abortSignal
161
232
  }) {
162
233
  try {
163
234
  const agent = mastra.getAgent(agentId);
164
235
  if (!agent) {
165
- throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
236
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
166
237
  }
167
238
  const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
168
239
  const finalResourceId = resourceId ?? resourceid;
@@ -170,23 +241,31 @@ async function streamGenerateHandler({
170
241
  ...Array.from(runtimeContext$1.entries()),
171
242
  ...Array.from(Object.entries(agentRuntimeContext ?? {}))
172
243
  ]);
173
- chunk57CJTIPW_cjs.validateBody({ messages });
244
+ chunkCCGRCYWJ_cjs.validateBody({ messages });
174
245
  const streamResult = await agent.stream(messages, {
175
246
  ...rest,
176
247
  // @ts-expect-error TODO fix types
177
248
  resourceId: finalResourceId,
178
- runtimeContext: finalRuntimeContext
249
+ runtimeContext: finalRuntimeContext,
250
+ signal: abortSignal
179
251
  });
180
- const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
252
+ const streamResponse = rest.output ? streamResult.toTextStreamResponse({
253
+ headers: {
254
+ "Transfer-Encoding": "chunked"
255
+ }
256
+ }) : streamResult.toDataStreamResponse({
181
257
  sendUsage: true,
182
258
  sendReasoning: true,
183
259
  getErrorMessage: (error) => {
184
260
  return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
261
+ },
262
+ headers: {
263
+ "Transfer-Encoding": "chunked"
185
264
  }
186
265
  });
187
266
  return streamResponse;
188
267
  } catch (error) {
189
- throw new chunkOCWPVYNI_cjs.HTTPException(error?.status ?? 500, { message: error?.message ?? "Error streaming from agent" });
268
+ return chunkPZQDCRPV_cjs.handleError(error, "error streaming agent response");
190
269
  }
191
270
  }
192
271