@mastra/server 0.0.0-taofeeqInngest-20250603090617 → 0.0.0-tool-call-parts-20250630193309

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 (41) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +252 -35
  2. package/dist/_tsup-dts-rollup.d.ts +252 -35
  3. package/dist/{chunk-J3PKLB3A.js → chunk-2BCWG3EZ.js} +52 -13
  4. package/dist/{chunk-KUNQFY2W.js → chunk-72LOJGUV.js} +106 -50
  5. package/dist/{chunk-W7VCKPAD.js → chunk-E2LP4J6K.js} +2 -2
  6. package/dist/{chunk-A3KDUGS7.cjs → chunk-EP3XVEVC.cjs} +56 -17
  7. package/dist/{chunk-TJKLBTFB.js → chunk-EWLR2PNT.js} +7 -17
  8. package/dist/{chunk-NEOOQUKW.cjs → chunk-IMBY5XUG.cjs} +36 -4
  9. package/dist/{chunk-MMO2HDM6.cjs → chunk-L3VURYKY.cjs} +117 -60
  10. package/dist/{chunk-YWLUOY3D.cjs → chunk-LI436ITD.cjs} +107 -69
  11. package/dist/{chunk-LIVAK2DM.js → chunk-MEGCYGBU.js} +108 -70
  12. package/dist/{chunk-YIOVBYZH.cjs → chunk-NGHSYB5B.cjs} +7 -7
  13. package/dist/{chunk-DQLE3DVM.js → chunk-QLG2PFHE.js} +36 -4
  14. package/dist/{chunk-CP55EVBK.js → chunk-R5VGYBV6.js} +12 -8
  15. package/dist/{chunk-Y7UWRW5X.cjs → chunk-RQ2Z56EC.cjs} +51 -21
  16. package/dist/{chunk-CMMOIUFC.cjs → chunk-WJY57THV.cjs} +12 -8
  17. package/dist/{chunk-DJJIUEL2.js → chunk-XUIJ7WRT.js} +51 -21
  18. package/dist/{chunk-ZE5AAC4I.cjs → chunk-Z3PTO2AK.cjs} +11 -21
  19. package/dist/server/handlers/agents.cjs +7 -7
  20. package/dist/server/handlers/agents.js +1 -1
  21. package/dist/server/handlers/legacyWorkflows.cjs +11 -11
  22. package/dist/server/handlers/legacyWorkflows.js +1 -1
  23. package/dist/server/handlers/logs.cjs +4 -4
  24. package/dist/server/handlers/logs.js +1 -1
  25. package/dist/server/handlers/memory.cjs +9 -9
  26. package/dist/server/handlers/memory.js +1 -1
  27. package/dist/server/handlers/tools.cjs +5 -5
  28. package/dist/server/handlers/tools.js +1 -1
  29. package/dist/server/handlers/vNextNetwork.cjs +218 -0
  30. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  31. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  32. package/dist/server/handlers/vNextNetwork.js +211 -0
  33. package/dist/server/handlers/voice.cjs +5 -5
  34. package/dist/server/handlers/voice.js +1 -1
  35. package/dist/server/handlers/workflows.cjs +16 -12
  36. package/dist/server/handlers/workflows.d.cts +1 -0
  37. package/dist/server/handlers/workflows.d.ts +1 -0
  38. package/dist/server/handlers/workflows.js +1 -1
  39. package/dist/server/handlers.cjs +14 -14
  40. package/dist/server/handlers.js +7 -7
  41. package/package.json +12 -13
@@ -1,9 +1,8 @@
1
- import { stringify, esm_default } from './chunk-LIVAK2DM.js';
1
+ import { stringify, esm_default } from './chunk-MEGCYGBU.js';
2
2
  import { handleError } from './chunk-M5ABIP7D.js';
3
3
  import { HTTPException } from './chunk-NYN7KFXL.js';
4
4
  import { __export } from './chunk-MLKGABMK.js';
5
- import { ReadableStream } from 'node:stream/web';
6
- import { RuntimeContext } from '@mastra/core/di';
5
+ import { ReadableStream } from 'stream/web';
7
6
 
8
7
  // src/server/handlers/workflows.ts
9
8
  var workflows_exports = {};
@@ -11,6 +10,7 @@ __export(workflows_exports, {
11
10
  createWorkflowRunHandler: () => createWorkflowRunHandler,
12
11
  getWorkflowByIdHandler: () => getWorkflowByIdHandler,
13
12
  getWorkflowRunByIdHandler: () => getWorkflowRunByIdHandler,
13
+ getWorkflowRunExecutionResultHandler: () => getWorkflowRunExecutionResultHandler,
14
14
  getWorkflowRunsHandler: () => getWorkflowRunsHandler,
15
15
  getWorkflowsHandler: () => getWorkflowsHandler,
16
16
  resumeAsyncWorkflowHandler: () => resumeAsyncWorkflowHandler,
@@ -49,12 +49,46 @@ async function getWorkflowsHandler({ mastra }) {
49
49
  throw new HTTPException(500, { message: error?.message || "Error getting workflows" });
50
50
  }
51
51
  }
52
+ async function getWorkflowsFromSystem({ mastra, workflowId }) {
53
+ const logger = mastra.getLogger();
54
+ if (!workflowId) {
55
+ throw new HTTPException(400, { message: "Workflow ID is required" });
56
+ }
57
+ let workflow;
58
+ try {
59
+ workflow = mastra.getWorkflow(workflowId);
60
+ } catch (error) {
61
+ logger.debug("Error getting workflow, searching agents for workflow", error);
62
+ }
63
+ if (!workflow) {
64
+ logger.debug("Workflow not found, searching agents for workflow", { workflowId });
65
+ const agents = mastra.getAgents();
66
+ if (Object.keys(agents || {}).length) {
67
+ for (const [_, agent] of Object.entries(agents)) {
68
+ try {
69
+ const workflows = await agent.getWorkflows();
70
+ if (workflows[workflowId]) {
71
+ workflow = workflows[workflowId];
72
+ break;
73
+ }
74
+ break;
75
+ } catch (error) {
76
+ logger.debug("Error getting workflow from agent", error);
77
+ }
78
+ }
79
+ }
80
+ }
81
+ if (!workflow) {
82
+ throw new HTTPException(404, { message: "Workflow not found" });
83
+ }
84
+ return { workflow };
85
+ }
52
86
  async function getWorkflowByIdHandler({ mastra, workflowId }) {
53
87
  try {
54
88
  if (!workflowId) {
55
89
  throw new HTTPException(400, { message: "Workflow ID is required" });
56
90
  }
57
- const workflow = mastra.getWorkflow(workflowId);
91
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
58
92
  if (!workflow) {
59
93
  throw new HTTPException(404, { message: "Workflow not found" });
60
94
  }
@@ -92,7 +126,7 @@ async function getWorkflowRunByIdHandler({
92
126
  if (!runId) {
93
127
  throw new HTTPException(400, { message: "Run ID is required" });
94
128
  }
95
- const workflow = mastra.getWorkflow(workflowId);
129
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
96
130
  if (!workflow) {
97
131
  throw new HTTPException(404, { message: "Workflow not found" });
98
132
  }
@@ -105,6 +139,33 @@ async function getWorkflowRunByIdHandler({
105
139
  throw new HTTPException(500, { message: error?.message || "Error getting workflow run" });
106
140
  }
107
141
  }
142
+ async function getWorkflowRunExecutionResultHandler({
143
+ mastra,
144
+ workflowId,
145
+ runId
146
+ }) {
147
+ try {
148
+ if (!workflowId) {
149
+ throw new HTTPException(400, { message: "Workflow ID is required" });
150
+ }
151
+ if (!runId) {
152
+ throw new HTTPException(400, { message: "Run ID is required" });
153
+ }
154
+ const workflow = mastra.getWorkflow(workflowId);
155
+ if (!workflow) {
156
+ throw new HTTPException(404, { message: "Workflow not found" });
157
+ }
158
+ const executionResult = await workflow.getWorkflowRunExecutionResult(runId);
159
+ if (!executionResult) {
160
+ throw new HTTPException(404, { message: "Workflow run execution result not found" });
161
+ }
162
+ return executionResult;
163
+ } catch (error) {
164
+ throw new HTTPException(500, {
165
+ message: error?.message || "Error getting workflow run execution result"
166
+ });
167
+ }
168
+ }
108
169
  async function createWorkflowRunHandler({
109
170
  mastra,
110
171
  workflowId,
@@ -114,11 +175,11 @@ async function createWorkflowRunHandler({
114
175
  if (!workflowId) {
115
176
  throw new HTTPException(400, { message: "Workflow ID is required" });
116
177
  }
117
- const workflow = mastra.getWorkflow(workflowId);
178
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
118
179
  if (!workflow) {
119
180
  throw new HTTPException(404, { message: "Workflow not found" });
120
181
  }
121
- const run = workflow.createRun({ runId: prevRunId });
182
+ const run = await workflow.createRunAsync({ runId: prevRunId });
122
183
  return { runId: run.runId };
123
184
  } catch (error) {
124
185
  throw new HTTPException(500, { message: error?.message || "Error creating workflow run" });
@@ -129,25 +190,20 @@ async function startAsyncWorkflowHandler({
129
190
  runtimeContext,
130
191
  workflowId,
131
192
  runId,
132
- inputData,
133
- runtimeContextFromRequest
193
+ inputData
134
194
  }) {
135
195
  try {
136
196
  if (!workflowId) {
137
197
  throw new HTTPException(400, { message: "Workflow ID is required" });
138
198
  }
139
- const workflow = mastra.getWorkflow(workflowId);
199
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
140
200
  if (!workflow) {
141
201
  throw new HTTPException(404, { message: "Workflow not found" });
142
202
  }
143
- const finalRuntimeContext = new RuntimeContext([
144
- ...Array.from(runtimeContext?.entries() ?? []),
145
- ...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
146
- ]);
147
- const _run = workflow.createRun({ runId });
203
+ const _run = await workflow.createRunAsync({ runId });
148
204
  const result = await _run.start({
149
205
  inputData,
150
- runtimeContext: finalRuntimeContext
206
+ runtimeContext
151
207
  });
152
208
  return result;
153
209
  } catch (error) {
@@ -159,8 +215,7 @@ async function startWorkflowRunHandler({
159
215
  runtimeContext,
160
216
  workflowId,
161
217
  runId,
162
- inputData,
163
- runtimeContextFromRequest
218
+ inputData
164
219
  }) {
165
220
  try {
166
221
  if (!workflowId) {
@@ -169,19 +224,18 @@ async function startWorkflowRunHandler({
169
224
  if (!runId) {
170
225
  throw new HTTPException(400, { message: "runId required to start run" });
171
226
  }
172
- const workflow = mastra.getWorkflow(workflowId);
227
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
228
+ if (!workflow) {
229
+ throw new HTTPException(404, { message: "Workflow not found" });
230
+ }
173
231
  const run = await workflow.getWorkflowRunById(runId);
174
232
  if (!run) {
175
233
  throw new HTTPException(404, { message: "Workflow run not found" });
176
234
  }
177
- const finalRuntimeContext = new RuntimeContext([
178
- ...Array.from(runtimeContext?.entries() ?? []),
179
- ...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
180
- ]);
181
- const _run = workflow.createRun({ runId });
235
+ const _run = await workflow.createRunAsync({ runId });
182
236
  void _run.start({
183
237
  inputData,
184
- runtimeContext: finalRuntimeContext
238
+ runtimeContext
185
239
  });
186
240
  return { message: "Workflow run started" };
187
241
  } catch (e) {
@@ -200,12 +254,15 @@ async function watchWorkflowHandler({
200
254
  if (!runId) {
201
255
  throw new HTTPException(400, { message: "runId required to watch workflow" });
202
256
  }
203
- const workflow = mastra.getWorkflow(workflowId);
257
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
258
+ if (!workflow) {
259
+ throw new HTTPException(404, { message: "Workflow not found" });
260
+ }
204
261
  const run = await workflow.getWorkflowRunById(runId);
205
262
  if (!run) {
206
263
  throw new HTTPException(404, { message: "Workflow run not found" });
207
264
  }
208
- const _run = workflow.createRun({ runId });
265
+ const _run = await workflow.createRunAsync({ runId });
209
266
  let unwatch;
210
267
  let asyncRef = null;
211
268
  const stream = new ReadableStream({
@@ -234,13 +291,12 @@ async function watchWorkflowHandler({
234
291
  return handleError(error, "Error watching workflow");
235
292
  }
236
293
  }
237
- function streamWorkflowHandler({
294
+ async function streamWorkflowHandler({
238
295
  mastra,
239
296
  runtimeContext,
240
297
  workflowId,
241
298
  runId,
242
- inputData,
243
- runtimeContextFromRequest
299
+ inputData
244
300
  }) {
245
301
  try {
246
302
  if (!workflowId) {
@@ -249,18 +305,14 @@ function streamWorkflowHandler({
249
305
  if (!runId) {
250
306
  throw new HTTPException(400, { message: "runId required to resume workflow" });
251
307
  }
252
- const workflow = mastra.getWorkflow(workflowId);
308
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
253
309
  if (!workflow) {
254
310
  throw new HTTPException(404, { message: "Workflow not found" });
255
311
  }
256
- const finalRuntimeContext = new RuntimeContext([
257
- ...Array.from(runtimeContext?.entries() ?? []),
258
- ...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
259
- ]);
260
- const run = workflow.createRun({ runId });
312
+ const run = await workflow.createRunAsync({ runId });
261
313
  const result = run.stream({
262
314
  inputData,
263
- runtimeContext: finalRuntimeContext
315
+ runtimeContext
264
316
  });
265
317
  return result;
266
318
  } catch (error) {
@@ -272,8 +324,7 @@ async function resumeAsyncWorkflowHandler({
272
324
  workflowId,
273
325
  runId,
274
326
  body,
275
- runtimeContext,
276
- runtimeContextFromRequest
327
+ runtimeContext
277
328
  }) {
278
329
  try {
279
330
  if (!workflowId) {
@@ -285,20 +336,19 @@ async function resumeAsyncWorkflowHandler({
285
336
  if (!body.step) {
286
337
  throw new HTTPException(400, { message: "step required to resume workflow" });
287
338
  }
288
- const workflow = mastra.getWorkflow(workflowId);
339
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
340
+ if (!workflow) {
341
+ throw new HTTPException(404, { message: "Workflow not found" });
342
+ }
289
343
  const run = await workflow.getWorkflowRunById(runId);
290
344
  if (!run) {
291
345
  throw new HTTPException(404, { message: "Workflow run not found" });
292
346
  }
293
- const finalRuntimeContext = new RuntimeContext([
294
- ...Array.from(runtimeContext?.entries() ?? []),
295
- ...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
296
- ]);
297
- const _run = workflow.createRun({ runId });
347
+ const _run = await workflow.createRunAsync({ runId });
298
348
  const result = await _run.resume({
299
349
  step: body.step,
300
350
  resumeData: body.resumeData,
301
- runtimeContext: finalRuntimeContext
351
+ runtimeContext
302
352
  });
303
353
  return result;
304
354
  } catch (error) {
@@ -322,12 +372,15 @@ async function resumeWorkflowHandler({
322
372
  if (!body.step) {
323
373
  throw new HTTPException(400, { message: "step required to resume workflow" });
324
374
  }
325
- const workflow = mastra.getWorkflow(workflowId);
375
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
376
+ if (!workflow) {
377
+ throw new HTTPException(404, { message: "Workflow not found" });
378
+ }
326
379
  const run = await workflow.getWorkflowRunById(runId);
327
380
  if (!run) {
328
381
  throw new HTTPException(404, { message: "Workflow run not found" });
329
382
  }
330
- const _run = workflow.createRun({ runId });
383
+ const _run = await workflow.createRunAsync({ runId });
331
384
  void _run.resume({
332
385
  step: body.step,
333
386
  resumeData: body.resumeData,
@@ -351,7 +404,10 @@ async function getWorkflowRunsHandler({
351
404
  if (!workflowId) {
352
405
  throw new HTTPException(400, { message: "Workflow ID is required" });
353
406
  }
354
- const workflow = mastra.getWorkflow(workflowId);
407
+ const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
408
+ if (!workflow) {
409
+ throw new HTTPException(404, { message: "Workflow not found" });
410
+ }
355
411
  const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
356
412
  runs: [],
357
413
  total: 0
@@ -362,4 +418,4 @@ async function getWorkflowRunsHandler({
362
418
  }
363
419
  }
364
420
 
365
- export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
421
+ export { createWorkflowRunHandler, getWorkflowByIdHandler, getWorkflowRunByIdHandler, getWorkflowRunExecutionResultHandler, getWorkflowRunsHandler, getWorkflowsHandler, resumeAsyncWorkflowHandler, resumeWorkflowHandler, startAsyncWorkflowHandler, startWorkflowRunHandler, streamWorkflowHandler, watchWorkflowHandler, workflows_exports };
@@ -1,8 +1,8 @@
1
- import { stringify, esm_default } from './chunk-LIVAK2DM.js';
1
+ import { stringify, esm_default } from './chunk-MEGCYGBU.js';
2
2
  import { handleError } from './chunk-M5ABIP7D.js';
3
3
  import { HTTPException } from './chunk-NYN7KFXL.js';
4
4
  import { __export } from './chunk-MLKGABMK.js';
5
- import { ReadableStream } from 'node:stream/web';
5
+ import { ReadableStream } from 'stream/web';
6
6
 
7
7
  // src/server/handlers/legacyWorkflows.ts
8
8
  var legacyWorkflows_exports = {};
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkYWLUOY3D_cjs = require('./chunk-YWLUOY3D.cjs');
3
+ var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
4
4
  var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
5
5
  var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
6
6
  var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
@@ -25,12 +25,14 @@ 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
  }, {});
@@ -59,8 +61,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
59
61
  workflows: serializedAgentWorkflows,
60
62
  provider: llm?.getProvider(),
61
63
  modelId: llm?.getModelId(),
62
- defaultGenerateOptions: agent.getDefaultGenerateOptions(),
63
- defaultStreamOptions: agent.getDefaultStreamOptions()
64
+ defaultGenerateOptions,
65
+ defaultStreamOptions
64
66
  };
65
67
  })
66
68
  );
@@ -76,7 +78,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
76
78
  async function getAgentByIdHandler({
77
79
  mastra,
78
80
  runtimeContext,
79
- agentId
81
+ agentId,
82
+ isPlayground = false
80
83
  }) {
81
84
  try {
82
85
  const agent = mastra.getAgent(agentId);
@@ -88,8 +91,8 @@ async function getAgentByIdHandler({
88
91
  const _tool = tool;
89
92
  acc[key] = {
90
93
  ..._tool,
91
- inputSchema: _tool.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(_tool.inputSchema)) : void 0,
92
- 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
93
96
  };
94
97
  return acc;
95
98
  }, {});
@@ -102,7 +105,16 @@ async function getAgentByIdHandler({
102
105
  return {
103
106
  ...acc,
104
107
  [key]: {
105
- name: workflow.name
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
+ }, {})
106
118
  }
107
119
  };
108
120
  }, {});
@@ -110,8 +122,24 @@ async function getAgentByIdHandler({
110
122
  logger.error("Error getting workflows for agent", { agentName: agent.name, error });
111
123
  }
112
124
  }
113
- const instructions = await agent.getInstructions({ runtimeContext });
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 });
114
140
  const llm = await agent.getLLM({ runtimeContext });
141
+ const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
142
+ const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
115
143
  return {
116
144
  name: agent.name,
117
145
  instructions,
@@ -119,8 +147,8 @@ async function getAgentByIdHandler({
119
147
  workflows: serializedAgentWorkflows,
120
148
  provider: llm?.getProvider(),
121
149
  modelId: llm?.getModelId(),
122
- defaultGenerateOptions: agent.getDefaultGenerateOptions(),
123
- defaultStreamOptions: agent.getDefaultStreamOptions()
150
+ defaultGenerateOptions,
151
+ defaultStreamOptions
124
152
  };
125
153
  } catch (error) {
126
154
  return chunk64U3UDTH_cjs.handleError(error, "Error getting agent");
@@ -168,7 +196,8 @@ async function generateHandler({
168
196
  mastra,
169
197
  runtimeContext: runtimeContext$1,
170
198
  agentId,
171
- body
199
+ body,
200
+ abortSignal
172
201
  }) {
173
202
  try {
174
203
  const agent = mastra.getAgent(agentId);
@@ -186,7 +215,8 @@ async function generateHandler({
186
215
  ...rest,
187
216
  // @ts-expect-error TODO fix types
188
217
  resourceId: finalResourceId,
189
- runtimeContext: finalRuntimeContext
218
+ runtimeContext: finalRuntimeContext,
219
+ signal: abortSignal
190
220
  });
191
221
  return result;
192
222
  } catch (error) {
@@ -197,7 +227,8 @@ async function streamGenerateHandler({
197
227
  mastra,
198
228
  runtimeContext: runtimeContext$1,
199
229
  agentId,
200
- body
230
+ body,
231
+ abortSignal
201
232
  }) {
202
233
  try {
203
234
  const agent = mastra.getAgent(agentId);
@@ -215,13 +246,21 @@ async function streamGenerateHandler({
215
246
  ...rest,
216
247
  // @ts-expect-error TODO fix types
217
248
  resourceId: finalResourceId,
218
- runtimeContext: finalRuntimeContext
249
+ runtimeContext: finalRuntimeContext,
250
+ signal: abortSignal
219
251
  });
220
- 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({
221
257
  sendUsage: true,
222
258
  sendReasoning: true,
223
259
  getErrorMessage: (error) => {
224
260
  return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
261
+ },
262
+ headers: {
263
+ "Transfer-Encoding": "chunked"
225
264
  }
226
265
  });
227
266
  return streamResponse;
@@ -1,9 +1,8 @@
1
- import { stringify, esm_default } from './chunk-LIVAK2DM.js';
1
+ import { stringify, esm_default } from './chunk-MEGCYGBU.js';
2
2
  import { validateBody } from './chunk-H5PTF3Y4.js';
3
3
  import { handleError } from './chunk-M5ABIP7D.js';
4
4
  import { HTTPException } from './chunk-NYN7KFXL.js';
5
5
  import { __export } from './chunk-MLKGABMK.js';
6
- import { RuntimeContext } from '@mastra/core/di';
7
6
  import { isVercelTool } from '@mastra/core/tools';
8
7
 
9
8
  // src/server/handlers/tools.ts
@@ -58,8 +57,7 @@ function executeToolHandler(tools) {
58
57
  runId,
59
58
  toolId,
60
59
  data,
61
- runtimeContext,
62
- runtimeContextFromRequest
60
+ runtimeContext
63
61
  }) => {
64
62
  try {
65
63
  if (!toolId) {
@@ -77,15 +75,11 @@ function executeToolHandler(tools) {
77
75
  const result2 = await tool.execute(data);
78
76
  return result2;
79
77
  }
80
- const finalRuntimeContext = new RuntimeContext([
81
- ...Array.from(runtimeContext.entries()),
82
- ...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
83
- ]);
84
78
  const result = await tool.execute({
85
79
  context: data,
86
80
  mastra,
87
81
  runId,
88
- runtimeContext: finalRuntimeContext
82
+ runtimeContext
89
83
  });
90
84
  return result;
91
85
  } catch (error) {
@@ -98,28 +92,24 @@ async function executeAgentToolHandler({
98
92
  agentId,
99
93
  toolId,
100
94
  data,
101
- runtimeContext,
102
- runtimeContextFromRequest
95
+ runtimeContext
103
96
  }) {
104
97
  try {
105
98
  const agent = agentId ? mastra.getAgent(agentId) : null;
106
99
  if (!agent) {
107
100
  throw new HTTPException(404, { message: "Tool not found" });
108
101
  }
109
- const tool = Object.values(agent?.tools || {}).find((tool2) => tool2.id === toolId);
102
+ const agentTools = await agent.getTools({ runtimeContext });
103
+ const tool = Object.values(agentTools || {}).find((tool2) => tool2.id === toolId);
110
104
  if (!tool) {
111
105
  throw new HTTPException(404, { message: "Tool not found" });
112
106
  }
113
107
  if (!tool?.execute) {
114
108
  throw new HTTPException(400, { message: "Tool is not executable" });
115
109
  }
116
- const finalRuntimeContext = new RuntimeContext([
117
- ...Array.from(runtimeContext.entries()),
118
- ...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
119
- ]);
120
110
  const result = await tool.execute({
121
111
  context: data,
122
- runtimeContext: finalRuntimeContext,
112
+ runtimeContext,
123
113
  mastra,
124
114
  runId: agentId
125
115
  });
@@ -13,11 +13,26 @@ chunk75ZPJI57_cjs.__export(logs_exports, {
13
13
  });
14
14
  async function getLogsHandler({
15
15
  mastra,
16
- transportId
16
+ transportId,
17
+ params
17
18
  }) {
18
19
  try {
19
20
  chunk57CJTIPW_cjs.validateBody({ transportId });
20
- const logs = await mastra.getLogs(transportId);
21
+ const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
22
+ const filters = _filters ? Object.fromEntries(
23
+ (Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
24
+ const [key, value] = attr.split(":");
25
+ return [key, value];
26
+ })
27
+ ) : void 0;
28
+ const logs = await mastra.getLogs(transportId, {
29
+ fromDate,
30
+ toDate,
31
+ logLevel,
32
+ filters,
33
+ page: page ? Number(page) : void 0,
34
+ perPage: perPage ? Number(perPage) : void 0
35
+ });
21
36
  return logs;
22
37
  } catch (error) {
23
38
  return chunk64U3UDTH_cjs.handleError(error, "Error getting logs");
@@ -26,11 +41,28 @@ async function getLogsHandler({
26
41
  async function getLogsByRunIdHandler({
27
42
  mastra,
28
43
  runId,
29
- transportId
44
+ transportId,
45
+ params
30
46
  }) {
31
47
  try {
32
48
  chunk57CJTIPW_cjs.validateBody({ runId, transportId });
33
- const logs = await mastra.getLogsByRunId({ runId, transportId });
49
+ const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
50
+ const filters = _filters ? Object.fromEntries(
51
+ (Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
52
+ const [key, value] = attr.split(":");
53
+ return [key, value];
54
+ })
55
+ ) : void 0;
56
+ const logs = await mastra.getLogsByRunId({
57
+ runId,
58
+ transportId,
59
+ fromDate,
60
+ toDate,
61
+ logLevel,
62
+ filters,
63
+ page: page ? Number(page) : void 0,
64
+ perPage: perPage ? Number(perPage) : void 0
65
+ });
34
66
  return logs;
35
67
  } catch (error) {
36
68
  return chunk64U3UDTH_cjs.handleError(error, "Error getting logs by run ID");