@mastra/inngest 0.0.0-fix-multi-modal-for-cloud-20251028082043 → 0.0.0-fix-persist-session-cache-option-mcp-server-20251030161352

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/index.js CHANGED
@@ -2,7 +2,7 @@ import { randomUUID } from 'crypto';
2
2
  import { ReadableStream } from 'stream/web';
3
3
  import { subscribe } from '@inngest/realtime';
4
4
  import { wrapMastra, AISpanType } from '@mastra/core/ai-tracing';
5
- import { RuntimeContext } from '@mastra/core/di';
5
+ import { RequestContext } from '@mastra/core/di';
6
6
  import { ChunkFrom, WorkflowRunOutput } from '@mastra/core/stream';
7
7
  import { ToolStream, Tool } from '@mastra/core/tools';
8
8
  import { Run, Workflow, DefaultExecutionEngine, createDeprecationProxy, getStepResult, runCountDeprecationMessage, validateStepInput } from '@mastra/core/workflows';
@@ -18,7 +18,7 @@ function serve({
18
18
  functions: userFunctions = [],
19
19
  registerOptions
20
20
  }) {
21
- const wfs = mastra.getWorkflows();
21
+ const wfs = mastra.listWorkflows();
22
22
  const workflowFunctions = Array.from(
23
23
  new Set(
24
24
  Object.values(wfs).flatMap((wf) => {
@@ -108,9 +108,15 @@ var InngestRun = class extends Run {
108
108
  });
109
109
  }
110
110
  }
111
- async start({
111
+ async start(params) {
112
+ return this._start(params);
113
+ }
114
+ async _start({
112
115
  inputData,
113
- initialState
116
+ initialState,
117
+ outputOptions,
118
+ tracingOptions,
119
+ format
114
120
  }) {
115
121
  await this.#mastra.getStorage()?.persistWorkflowSnapshot({
116
122
  workflowName: this.workflowId,
@@ -137,7 +143,10 @@ var InngestRun = class extends Run {
137
143
  inputData: inputDataToUse,
138
144
  initialState: initialStateToUse,
139
145
  runId: this.runId,
140
- resourceId: this.resourceId
146
+ resourceId: this.resourceId,
147
+ outputOptions,
148
+ tracingOptions,
149
+ format
141
150
  }
142
151
  });
143
152
  const eventId = eventOutput.ids[0];
@@ -226,20 +235,35 @@ var InngestRun = class extends Run {
226
235
  });
227
236
  };
228
237
  }
229
- streamLegacy({ inputData, runtimeContext } = {}) {
238
+ streamLegacy({ inputData, requestContext } = {}) {
230
239
  const { readable, writable } = new TransformStream();
231
240
  const writer = writable.getWriter();
232
241
  const unwatch = this.watch(async (event) => {
233
242
  try {
243
+ await writer.write({
244
+ // @ts-ignore
245
+ type: "start",
246
+ // @ts-ignore
247
+ payload: { runId: this.runId }
248
+ });
234
249
  const e = {
235
250
  ...event,
236
251
  type: event.type.replace("workflow-", "")
237
252
  };
253
+ if (e.type === "step-output") {
254
+ e.type = e.payload.output.type;
255
+ e.payload = e.payload.output.payload;
256
+ }
238
257
  await writer.write(e);
239
258
  } catch {
240
259
  }
241
260
  }, "watch-v2");
242
261
  this.closeStreamAction = async () => {
262
+ await writer.write({
263
+ type: "finish",
264
+ // @ts-ignore
265
+ payload: { runId: this.runId }
266
+ });
243
267
  unwatch();
244
268
  try {
245
269
  await writer.close();
@@ -249,7 +273,7 @@ var InngestRun = class extends Run {
249
273
  writer.releaseLock();
250
274
  }
251
275
  };
252
- this.executionResults = this.start({ inputData, runtimeContext }).then((result) => {
276
+ this.executionResults = this._start({ inputData, requestContext, format: "legacy" }).then((result) => {
253
277
  if (result.status !== "suspended") {
254
278
  this.closeStreamAction?.().catch(() => {
255
279
  });
@@ -263,11 +287,18 @@ var InngestRun = class extends Run {
263
287
  }
264
288
  stream({
265
289
  inputData,
266
- runtimeContext,
267
- closeOnSuspend = true
290
+ requestContext,
291
+ tracingOptions,
292
+ closeOnSuspend = true,
293
+ initialState,
294
+ outputOptions
268
295
  } = {}) {
296
+ if (this.closeStreamAction && this.streamOutput) {
297
+ return this.streamOutput;
298
+ }
299
+ this.closeStreamAction = async () => {
300
+ };
269
301
  const self = this;
270
- let streamOutput;
271
302
  const stream = new ReadableStream({
272
303
  async start(controller) {
273
304
  const unwatch = self.watch(async ({ type, from = ChunkFrom.WORKFLOW, payload }) => {
@@ -276,7 +307,7 @@ var InngestRun = class extends Run {
276
307
  runId: self.runId,
277
308
  from,
278
309
  payload: {
279
- stepName: payload.id,
310
+ stepName: payload?.id,
280
311
  ...payload
281
312
  }
282
313
  });
@@ -289,29 +320,46 @@ var InngestRun = class extends Run {
289
320
  console.error("Error closing stream:", err);
290
321
  }
291
322
  };
292
- const executionResultsPromise = self.start({
323
+ const executionResultsPromise = self._start({
293
324
  inputData,
294
- runtimeContext
325
+ requestContext,
326
+ // tracingContext, // We are not able to pass a reference to a span here, what to do?
327
+ initialState,
328
+ tracingOptions,
329
+ outputOptions,
330
+ format: "vnext"
295
331
  });
296
- const executionResults = await executionResultsPromise;
297
- if (closeOnSuspend) {
298
- self.closeStreamAction?.().catch(() => {
299
- });
300
- } else if (executionResults.status !== "suspended") {
332
+ let executionResults;
333
+ try {
334
+ executionResults = await executionResultsPromise;
335
+ if (closeOnSuspend) {
336
+ self.closeStreamAction?.().catch(() => {
337
+ });
338
+ } else if (executionResults.status !== "suspended") {
339
+ self.closeStreamAction?.().catch(() => {
340
+ });
341
+ }
342
+ if (self.streamOutput) {
343
+ self.streamOutput.updateResults(
344
+ executionResults
345
+ );
346
+ }
347
+ } catch (err) {
348
+ self.streamOutput?.rejectResults(err);
301
349
  self.closeStreamAction?.().catch(() => {
302
350
  });
303
351
  }
304
- if (streamOutput) {
305
- streamOutput.updateResults(executionResults);
306
- }
307
352
  }
308
353
  });
309
- streamOutput = new WorkflowRunOutput({
354
+ this.streamOutput = new WorkflowRunOutput({
310
355
  runId: this.runId,
311
356
  workflowId: this.workflowId,
312
357
  stream
313
358
  });
314
- return streamOutput;
359
+ return this.streamOutput;
360
+ }
361
+ streamVNext(args = {}) {
362
+ return this.stream(args);
315
363
  }
316
364
  };
317
365
  var InngestWorkflow = class _InngestWorkflow extends Workflow {
@@ -435,7 +483,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
435
483
  },
436
484
  { event: `workflow.${this.id}` },
437
485
  async ({ event, step, attempt, publish }) => {
438
- let { inputData, initialState, runId, resourceId, resume, outputOptions } = event.data;
486
+ let { inputData, initialState, runId, resourceId, resume, outputOptions, format } = event.data;
439
487
  if (!runId) {
440
488
  runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
441
489
  return randomUUID();
@@ -474,13 +522,19 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
474
522
  initialState,
475
523
  emitter,
476
524
  retryConfig: this.retryConfig,
477
- runtimeContext: new RuntimeContext(),
525
+ requestContext: new RequestContext(),
478
526
  // TODO
479
527
  resume,
528
+ format,
480
529
  abortController: new AbortController(),
481
- currentSpan: void 0,
482
- // TODO: Pass actual parent AI span from workflow execution context
483
- outputOptions
530
+ // currentSpan: undefined, // TODO: Pass actual parent AI span from workflow execution context
531
+ outputOptions,
532
+ writableStream: new WritableStream({
533
+ write(chunk) {
534
+ void emitter.emit("watch-v2", chunk).catch(() => {
535
+ });
536
+ }
537
+ })
484
538
  });
485
539
  await step.run(`workflow.${this.id}.finalize`, async () => {
486
540
  if (result.status === "failed") {
@@ -518,7 +572,7 @@ function isAgent(params) {
518
572
  function isTool(params) {
519
573
  return params instanceof Tool;
520
574
  }
521
- function createStep(params) {
575
+ function createStep(params, agentOptions) {
522
576
  if (isAgent(params)) {
523
577
  return {
524
578
  id: params.name,
@@ -526,12 +580,23 @@ function createStep(params) {
526
580
  // @ts-ignore
527
581
  inputSchema: z.object({
528
582
  prompt: z.string()
583
+ // resourceId: z.string().optional(),
584
+ // threadId: z.string().optional(),
529
585
  }),
530
586
  // @ts-ignore
531
587
  outputSchema: z.object({
532
588
  text: z.string()
533
589
  }),
534
- execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
590
+ execute: async ({
591
+ inputData,
592
+ [EMITTER_SYMBOL]: emitter,
593
+ [STREAM_FORMAT_SYMBOL]: streamFormat,
594
+ requestContext,
595
+ tracingContext,
596
+ abortSignal,
597
+ abort,
598
+ writer
599
+ }) => {
535
600
  let streamPromise = {};
536
601
  streamPromise.promise = new Promise((resolve, reject) => {
537
602
  streamPromise.resolve = resolve;
@@ -541,48 +606,40 @@ function createStep(params) {
541
606
  name: params.name,
542
607
  args: inputData
543
608
  };
544
- if ((await params.getLLM()).getModel().specificationVersion === `v2`) {
545
- const { fullStream } = await params.stream(inputData.prompt, {
546
- runtimeContext,
609
+ let stream;
610
+ if ((await params.getModel()).specificationVersion === "v1") {
611
+ const { fullStream } = await params.streamLegacy(inputData.prompt, {
612
+ ...agentOptions ?? {},
613
+ // resourceId: inputData.resourceId,
614
+ // threadId: inputData.threadId,
615
+ requestContext,
547
616
  tracingContext,
548
617
  onFinish: (result) => {
549
618
  streamPromise.resolve(result.text);
619
+ void agentOptions?.onFinish?.(result);
550
620
  },
551
621
  abortSignal
552
622
  });
553
- if (abortSignal.aborted) {
554
- return abort();
555
- }
556
- await emitter.emit("watch-v2", {
557
- type: "tool-call-streaming-start",
558
- ...toolData ?? {}
559
- });
560
- for await (const chunk of fullStream) {
561
- if (chunk.type === "text-delta") {
562
- await emitter.emit("watch-v2", {
563
- type: "tool-call-delta",
564
- ...toolData ?? {},
565
- argsTextDelta: chunk.payload.text
566
- });
567
- }
568
- }
623
+ stream = fullStream;
569
624
  } else {
570
- const { fullStream } = await params.streamLegacy(inputData.prompt, {
571
- runtimeContext,
625
+ const modelOutput = await params.stream(inputData.prompt, {
626
+ ...agentOptions ?? {},
627
+ requestContext,
572
628
  tracingContext,
573
629
  onFinish: (result) => {
574
630
  streamPromise.resolve(result.text);
631
+ void agentOptions?.onFinish?.(result);
575
632
  },
576
633
  abortSignal
577
634
  });
578
- if (abortSignal.aborted) {
579
- return abort();
580
- }
635
+ stream = modelOutput.fullStream;
636
+ }
637
+ if (streamFormat === "legacy") {
581
638
  await emitter.emit("watch-v2", {
582
639
  type: "tool-call-streaming-start",
583
640
  ...toolData ?? {}
584
641
  });
585
- for await (const chunk of fullStream) {
642
+ for await (const chunk of stream) {
586
643
  if (chunk.type === "text-delta") {
587
644
  await emitter.emit("watch-v2", {
588
645
  type: "tool-call-delta",
@@ -591,11 +648,18 @@ function createStep(params) {
591
648
  });
592
649
  }
593
650
  }
651
+ await emitter.emit("watch-v2", {
652
+ type: "tool-call-streaming-finish",
653
+ ...toolData ?? {}
654
+ });
655
+ } else {
656
+ for await (const chunk of stream) {
657
+ await writer.write(chunk);
658
+ }
659
+ }
660
+ if (abortSignal.aborted) {
661
+ return abort();
594
662
  }
595
- await emitter.emit("watch-v2", {
596
- type: "tool-call-streaming-finish",
597
- ...toolData ?? {}
598
- });
599
663
  return {
600
664
  text: await streamPromise.promise
601
665
  };
@@ -614,11 +678,11 @@ function createStep(params) {
614
678
  description: params.description,
615
679
  inputSchema: params.inputSchema,
616
680
  outputSchema: params.outputSchema,
617
- execute: async ({ inputData, mastra, runtimeContext, tracingContext, suspend, resumeData }) => {
681
+ execute: async ({ inputData, mastra, requestContext, tracingContext, suspend, resumeData }) => {
618
682
  return params.execute({
619
683
  context: inputData,
620
684
  mastra: wrapMastra(mastra, tracingContext),
621
- runtimeContext,
685
+ requestContext,
622
686
  tracingContext,
623
687
  suspend,
624
688
  resumeData
@@ -681,18 +745,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
681
745
  this.inngestStep = inngestStep;
682
746
  this.inngestAttempts = inngestAttempts;
683
747
  }
684
- async execute(params) {
685
- await params.emitter.emit("watch-v2", {
686
- type: "workflow-start",
687
- payload: { runId: params.runId }
688
- });
689
- const result = await super.execute(params);
690
- await params.emitter.emit("watch-v2", {
691
- type: "workflow-finish",
692
- payload: { runId: params.runId }
693
- });
694
- return result;
695
- }
696
748
  async fmtReturnValue(emitter, stepResults, lastOutput, error) {
697
749
  const base = {
698
750
  status: lastOutput.status,
@@ -760,7 +812,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
760
812
  stepResults,
761
813
  emitter,
762
814
  abortController,
763
- runtimeContext,
815
+ requestContext,
764
816
  executionContext,
765
817
  writableStream,
766
818
  tracingContext
@@ -784,7 +836,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
784
836
  runId,
785
837
  workflowId,
786
838
  mastra: this.mastra,
787
- runtimeContext,
839
+ requestContext,
788
840
  inputData: prevOutput,
789
841
  state: executionContext.state,
790
842
  setState: (state) => {
@@ -806,7 +858,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
806
858
  abortController?.abort();
807
859
  },
808
860
  [EMITTER_SYMBOL]: emitter,
809
- // TODO: add streamVNext support
810
861
  [STREAM_FORMAT_SYMBOL]: executionContext.format,
811
862
  engine: { step: this.inngestStep },
812
863
  abortSignal: abortController?.signal,
@@ -850,7 +901,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
850
901
  stepResults,
851
902
  emitter,
852
903
  abortController,
853
- runtimeContext,
904
+ requestContext,
854
905
  executionContext,
855
906
  writableStream,
856
907
  tracingContext
@@ -875,7 +926,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
875
926
  runId,
876
927
  workflowId,
877
928
  mastra: this.mastra,
878
- runtimeContext,
929
+ requestContext,
879
930
  inputData: prevOutput,
880
931
  state: executionContext.state,
881
932
  setState: (state) => {
@@ -898,7 +949,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
898
949
  },
899
950
  [EMITTER_SYMBOL]: emitter,
900
951
  [STREAM_FORMAT_SYMBOL]: executionContext.format,
901
- // TODO: add streamVNext support
902
952
  engine: { step: this.inngestStep },
903
953
  abortSignal: abortController?.signal,
904
954
  writer: new ToolStream(
@@ -959,7 +1009,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
959
1009
  prevOutput,
960
1010
  emitter,
961
1011
  abortController,
962
- runtimeContext,
1012
+ requestContext,
963
1013
  tracingContext,
964
1014
  writableStream,
965
1015
  disableScorers
@@ -1223,6 +1273,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1223
1273
  resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
1224
1274
  };
1225
1275
  }
1276
+ const stepCallId = randomUUID();
1226
1277
  let stepRes;
1227
1278
  try {
1228
1279
  stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
@@ -1236,8 +1287,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1236
1287
  const result = await step.execute({
1237
1288
  runId: executionContext.runId,
1238
1289
  mastra: this.mastra,
1239
- runtimeContext,
1240
- writableStream,
1290
+ requestContext,
1291
+ writer: new ToolStream(
1292
+ {
1293
+ prefix: "workflow-step",
1294
+ callId: stepCallId,
1295
+ name: step.id,
1296
+ runId: executionContext.runId
1297
+ },
1298
+ writableStream
1299
+ ),
1241
1300
  state: executionContext?.state ?? {},
1242
1301
  setState: (state) => {
1243
1302
  executionContext.state = state;
@@ -1272,6 +1331,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1272
1331
  runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
1273
1332
  },
1274
1333
  [EMITTER_SYMBOL]: emitter,
1334
+ [STREAM_FORMAT_SYMBOL]: executionContext.format,
1275
1335
  engine: {
1276
1336
  step: this.inngestStep
1277
1337
  },
@@ -1393,7 +1453,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1393
1453
  output: stepRes.result,
1394
1454
  workflowId: executionContext.workflowId,
1395
1455
  stepId: step.id,
1396
- runtimeContext,
1456
+ requestContext,
1397
1457
  disableScorers,
1398
1458
  tracingContext: { currentSpan: stepAISpan }
1399
1459
  });
@@ -1451,14 +1511,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1451
1511
  runId,
1452
1512
  entry,
1453
1513
  prevOutput,
1454
- prevStep,
1455
1514
  stepResults,
1456
- serializedStepGraph,
1457
1515
  resume,
1458
1516
  executionContext,
1459
1517
  emitter,
1460
1518
  abortController,
1461
- runtimeContext,
1519
+ requestContext,
1462
1520
  writableStream,
1463
1521
  disableScorers,
1464
1522
  tracingContext
@@ -1492,7 +1550,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1492
1550
  runId,
1493
1551
  workflowId,
1494
1552
  mastra: this.mastra,
1495
- runtimeContext,
1553
+ requestContext,
1496
1554
  runCount: -1,
1497
1555
  retryCount: -1,
1498
1556
  inputData: prevOutput,
@@ -1515,7 +1573,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1515
1573
  },
1516
1574
  [EMITTER_SYMBOL]: emitter,
1517
1575
  [STREAM_FORMAT_SYMBOL]: executionContext.format,
1518
- // TODO: add streamVNext support
1519
1576
  engine: {
1520
1577
  step: this.inngestStep
1521
1578
  },
@@ -1564,13 +1621,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1564
1621
  }
1565
1622
  });
1566
1623
  const results = await Promise.all(
1567
- stepsToRun.map(
1568
- (step, index) => this.executeEntry({
1569
- workflowId,
1570
- runId,
1571
- entry: step,
1572
- serializedStepGraph,
1573
- prevStep,
1624
+ stepsToRun.map(async (step, index) => {
1625
+ const currStepResult = stepResults[step.step.id];
1626
+ if (currStepResult && currStepResult.status === "success") {
1627
+ return currStepResult;
1628
+ }
1629
+ const result = await this.executeStep({
1630
+ step: step.step,
1631
+ prevOutput,
1574
1632
  stepResults,
1575
1633
  resume,
1576
1634
  executionContext: {
@@ -1584,26 +1642,28 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1584
1642
  },
1585
1643
  emitter,
1586
1644
  abortController,
1587
- runtimeContext,
1645
+ requestContext,
1588
1646
  writableStream,
1589
1647
  disableScorers,
1590
1648
  tracingContext: {
1591
1649
  currentSpan: conditionalSpan
1592
1650
  }
1593
- })
1594
- )
1651
+ });
1652
+ stepResults[step.step.id] = result;
1653
+ return result;
1654
+ })
1595
1655
  );
1596
- const hasFailed = results.find((result) => result.result.status === "failed");
1597
- const hasSuspended = results.find((result) => result.result.status === "suspended");
1656
+ const hasFailed = results.find((result) => result.status === "failed");
1657
+ const hasSuspended = results.find((result) => result.status === "suspended");
1598
1658
  if (hasFailed) {
1599
- execResults = { status: "failed", error: hasFailed.result.error };
1659
+ execResults = { status: "failed", error: hasFailed.error };
1600
1660
  } else if (hasSuspended) {
1601
- execResults = { status: "suspended", suspendPayload: hasSuspended.result.suspendPayload };
1661
+ execResults = { status: "suspended", suspendPayload: hasSuspended.suspendPayload };
1602
1662
  } else {
1603
1663
  execResults = {
1604
1664
  status: "success",
1605
1665
  output: results.reduce((acc, result, index) => {
1606
- if (result.result.status === "success") {
1666
+ if (result.status === "success") {
1607
1667
  acc[stepsToRun[index].step.id] = result.output;
1608
1668
  }
1609
1669
  return acc;