@mastra/inngest 0.12.3-alpha.2 → 0.12.3-alpha.4

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
@@ -202,10 +202,38 @@ var InngestRun = class extends Run {
202
202
  }
203
203
  stream({ inputData, runtimeContext } = {}) {
204
204
  const { readable, writable } = new TransformStream();
205
+ let currentToolData = void 0;
205
206
  const writer = writable.getWriter();
206
207
  const unwatch = this.watch(async (event) => {
208
+ if (event.type === "workflow-agent-call-start") {
209
+ currentToolData = {
210
+ name: event.payload.name,
211
+ args: event.payload.args
212
+ };
213
+ await writer.write({
214
+ ...event.payload,
215
+ type: "tool-call-streaming-start"
216
+ });
217
+ return;
218
+ }
207
219
  try {
208
- await writer.write(event);
220
+ if (event.type === "workflow-agent-call-finish") {
221
+ return;
222
+ } else if (!event.type.startsWith("workflow-")) {
223
+ if (event.type === "text-delta") {
224
+ await writer.write({
225
+ type: "tool-call-delta",
226
+ ...currentToolData ?? {},
227
+ argsTextDelta: event.textDelta
228
+ });
229
+ }
230
+ return;
231
+ }
232
+ const e = {
233
+ ...event,
234
+ type: event.type.replace("workflow-", "")
235
+ };
236
+ await writer.write(e);
209
237
  } catch {
210
238
  }
211
239
  }, "watch-v2");
@@ -264,27 +292,6 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
264
292
  const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
265
293
  return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
266
294
  }
267
- async getWorkflowRunExecutionResult(runId) {
268
- const storage = this.#mastra?.getStorage();
269
- if (!storage) {
270
- this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
271
- return null;
272
- }
273
- const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
274
- if (!run?.snapshot) {
275
- return null;
276
- }
277
- if (typeof run.snapshot === "string") {
278
- return null;
279
- }
280
- return {
281
- status: run.snapshot.status,
282
- result: run.snapshot.result,
283
- error: run.snapshot.error,
284
- payload: run.snapshot.context?.input,
285
- steps: run.snapshot.context
286
- };
287
- }
288
295
  __registerMastra(mastra) {
289
296
  this.#mastra = mastra;
290
297
  this.executionEngine.__registerMastra(mastra);
@@ -337,7 +344,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
337
344
  this.inngest
338
345
  );
339
346
  this.runs.set(runIdToUse, run);
340
- const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
347
+ const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
341
348
  if (!workflowSnapshotInStorage) {
342
349
  await this.mastra?.getStorage()?.persistWorkflowSnapshot({
343
350
  workflowName: this.id,
@@ -472,8 +479,8 @@ function createStep(params) {
472
479
  args: inputData
473
480
  };
474
481
  await emitter.emit("watch-v2", {
475
- type: "tool-call-streaming-start",
476
- ...toolData
482
+ type: "workflow-agent-call-start",
483
+ payload: toolData
477
484
  });
478
485
  const { fullStream } = await params.stream(inputData.prompt, {
479
486
  // resourceId: inputData.resourceId,
@@ -489,29 +496,12 @@ function createStep(params) {
489
496
  return abort();
490
497
  }
491
498
  for await (const chunk of fullStream) {
492
- switch (chunk.type) {
493
- case "text-delta":
494
- await emitter.emit("watch-v2", {
495
- type: "tool-call-delta",
496
- ...toolData,
497
- argsTextDelta: chunk.textDelta
498
- });
499
- break;
500
- case "step-start":
501
- case "step-finish":
502
- case "finish":
503
- break;
504
- case "tool-call":
505
- case "tool-result":
506
- case "tool-call-streaming-start":
507
- case "tool-call-delta":
508
- case "source":
509
- case "file":
510
- default:
511
- await emitter.emit("watch-v2", chunk);
512
- break;
513
- }
499
+ await emitter.emit("watch-v2", chunk);
514
500
  }
501
+ await emitter.emit("watch-v2", {
502
+ type: "workflow-agent-call-finish",
503
+ payload: toolData
504
+ });
515
505
  return {
516
506
  text: await streamPromise.promise
517
507
  };
@@ -587,12 +577,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
587
577
  }
588
578
  async execute(params) {
589
579
  await params.emitter.emit("watch-v2", {
590
- type: "start",
580
+ type: "workflow-start",
591
581
  payload: { runId: params.runId }
592
582
  });
593
583
  const result = await super.execute(params);
594
584
  await params.emitter.emit("watch-v2", {
595
- type: "finish",
585
+ type: "workflow-finish",
596
586
  payload: { runId: params.runId }
597
587
  });
598
588
  return result;
@@ -715,7 +705,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
715
705
  abortSignal: abortController?.signal,
716
706
  writer: new ToolStream(
717
707
  {
718
- prefix: "step",
708
+ prefix: "workflow-step",
719
709
  callId: stepCallId,
720
710
  name: "sleep",
721
711
  runId
@@ -797,7 +787,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
797
787
  abortSignal: abortController?.signal,
798
788
  writer: new ToolStream(
799
789
  {
800
- prefix: "step",
790
+ prefix: "workflow-step",
801
791
  callId: stepCallId,
802
792
  name: "sleep",
803
793
  runId
@@ -882,7 +872,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
882
872
  eventTimestamp: Date.now()
883
873
  });
884
874
  await emitter.emit("watch-v2", {
885
- type: "step-start",
875
+ type: "workflow-step-start",
886
876
  payload: {
887
877
  id: step.id,
888
878
  status: "running",
@@ -952,7 +942,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
952
942
  eventTimestamp: Date.now()
953
943
  });
954
944
  await emitter.emit("watch-v2", {
955
- type: "step-result",
945
+ type: "workflow-step-result",
956
946
  payload: {
957
947
  id: step.id,
958
948
  status: "failed",
@@ -987,7 +977,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
987
977
  eventTimestamp: Date.now()
988
978
  });
989
979
  await emitter.emit("watch-v2", {
990
- type: "step-suspended",
980
+ type: "workflow-step-suspended",
991
981
  payload: {
992
982
  id: step.id,
993
983
  status: "suspended"
@@ -1044,7 +1034,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1044
1034
  eventTimestamp: Date.now()
1045
1035
  });
1046
1036
  await emitter.emit("watch-v2", {
1047
- type: "step-result",
1037
+ type: "workflow-step-result",
1048
1038
  payload: {
1049
1039
  id: step.id,
1050
1040
  status: "success",
@@ -1052,7 +1042,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1052
1042
  }
1053
1043
  });
1054
1044
  await emitter.emit("watch-v2", {
1055
- type: "step-finish",
1045
+ type: "workflow-step-finish",
1056
1046
  payload: {
1057
1047
  id: step.id,
1058
1048
  metadata: {}
@@ -1165,7 +1155,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1165
1155
  });
1166
1156
  if (execResults.status === "suspended") {
1167
1157
  await emitter.emit("watch-v2", {
1168
- type: "step-suspended",
1158
+ type: "workflow-step-suspended",
1169
1159
  payload: {
1170
1160
  id: step.id,
1171
1161
  ...execResults
@@ -1173,14 +1163,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1173
1163
  });
1174
1164
  } else {
1175
1165
  await emitter.emit("watch-v2", {
1176
- type: "step-result",
1166
+ type: "workflow-step-result",
1177
1167
  payload: {
1178
1168
  id: step.id,
1179
1169
  ...execResults
1180
1170
  }
1181
1171
  });
1182
1172
  await emitter.emit("watch-v2", {
1183
- type: "step-finish",
1173
+ type: "workflow-step-finish",
1184
1174
  payload: {
1185
1175
  id: step.id,
1186
1176
  metadata: {}
@@ -1319,7 +1309,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1319
1309
  abortSignal: abortController.signal,
1320
1310
  writer: new ToolStream(
1321
1311
  {
1322
- prefix: "step",
1312
+ prefix: "workflow-step",
1323
1313
  callId: randomUUID(),
1324
1314
  name: "conditional",
1325
1315
  runId