@mastra/inngest 0.13.2 → 0.13.3-alpha.1

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
@@ -52,7 +52,6 @@ var InngestRun = class extends Run {
52
52
  await new Promise((resolve) => setTimeout(resolve, 1e3));
53
53
  runs = await this.getRuns(eventId);
54
54
  if (runs?.[0]?.status === "Failed") {
55
- console.log("run", runs?.[0]);
56
55
  throw new Error(`Function run ${runs?.[0]?.status}`);
57
56
  } else if (runs?.[0]?.status === "Cancelled") {
58
57
  const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
@@ -85,6 +84,7 @@ var InngestRun = class extends Run {
85
84
  await this.#mastra?.storage?.persistWorkflowSnapshot({
86
85
  workflowName: this.workflowId,
87
86
  runId: this.runId,
87
+ resourceId: this.resourceId,
88
88
  snapshot: {
89
89
  ...snapshot,
90
90
  status: "canceled"
@@ -98,6 +98,7 @@ var InngestRun = class extends Run {
98
98
  await this.#mastra.getStorage()?.persistWorkflowSnapshot({
99
99
  workflowName: this.workflowId,
100
100
  runId: this.runId,
101
+ resourceId: this.resourceId,
101
102
  snapshot: {
102
103
  runId: this.runId,
103
104
  serializedStepGraph: this.serializedStepGraph,
@@ -114,7 +115,8 @@ var InngestRun = class extends Run {
114
115
  name: `workflow.${this.workflowId}`,
115
116
  data: {
116
117
  inputData,
117
- runId: this.runId
118
+ runId: this.runId,
119
+ resourceId: this.resourceId
118
120
  }
119
121
  });
120
122
  const eventId = eventOutput.ids[0];
@@ -202,33 +204,9 @@ var InngestRun = class extends Run {
202
204
  }
203
205
  stream({ inputData, runtimeContext } = {}) {
204
206
  const { readable, writable } = new TransformStream();
205
- let currentToolData = void 0;
206
207
  const writer = writable.getWriter();
207
208
  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
- }
219
209
  try {
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
210
  const e = {
233
211
  ...event,
234
212
  type: event.type.replace("workflow-", "")
@@ -334,6 +312,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
334
312
  {
335
313
  workflowId: this.id,
336
314
  runId: runIdToUse,
315
+ resourceId: options?.resourceId,
337
316
  executionEngine: this.executionEngine,
338
317
  executionGraph: this.executionGraph,
339
318
  serializedStepGraph: this.serializedStepGraph,
@@ -349,6 +328,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
349
328
  await this.mastra?.getStorage()?.persistWorkflowSnapshot({
350
329
  workflowName: this.id,
351
330
  runId: runIdToUse,
331
+ resourceId: options?.resourceId,
352
332
  snapshot: {
353
333
  runId: runIdToUse,
354
334
  status: "pending",
@@ -382,7 +362,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
382
362
  },
383
363
  { event: `workflow.${this.id}` },
384
364
  async ({ event, step, attempt, publish }) => {
385
- let { inputData, runId, resume } = event.data;
365
+ let { inputData, runId, resourceId, resume } = event.data;
386
366
  if (!runId) {
387
367
  runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
388
368
  return randomUUID();
@@ -414,6 +394,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
414
394
  const result = await engine.execute({
415
395
  workflowId: this.id,
416
396
  runId,
397
+ resourceId,
417
398
  graph: this.executionGraph,
418
399
  serializedStepGraph: this.serializedStepGraph,
419
400
  input: inputData,
@@ -461,8 +442,6 @@ function createStep(params) {
461
442
  // @ts-ignore
462
443
  inputSchema: z.object({
463
444
  prompt: z.string()
464
- // resourceId: z.string().optional(),
465
- // threadId: z.string().optional(),
466
445
  }),
467
446
  // @ts-ignore
468
447
  outputSchema: z.object({
@@ -478,13 +457,7 @@ function createStep(params) {
478
457
  name: params.name,
479
458
  args: inputData
480
459
  };
481
- await emitter.emit("watch-v2", {
482
- type: "workflow-agent-call-start",
483
- payload: toolData
484
- });
485
460
  const { fullStream } = await params.stream(inputData.prompt, {
486
- // resourceId: inputData.resourceId,
487
- // threadId: inputData.threadId,
488
461
  runtimeContext,
489
462
  tracingContext,
490
463
  onFinish: (result) => {
@@ -495,12 +468,22 @@ function createStep(params) {
495
468
  if (abortSignal.aborted) {
496
469
  return abort();
497
470
  }
471
+ await emitter.emit("watch-v2", {
472
+ type: "tool-call-streaming-start",
473
+ ...toolData ?? {}
474
+ });
498
475
  for await (const chunk of fullStream) {
499
- await emitter.emit("watch-v2", chunk);
476
+ if (chunk.type === "text-delta") {
477
+ await emitter.emit("watch-v2", {
478
+ type: "tool-call-delta",
479
+ ...toolData ?? {},
480
+ argsTextDelta: chunk.textDelta
481
+ });
482
+ }
500
483
  }
501
484
  await emitter.emit("watch-v2", {
502
- type: "workflow-agent-call-finish",
503
- payload: toolData
485
+ type: "tool-call-streaming-finish",
486
+ ...toolData ?? {}
504
487
  });
505
488
  return {
506
489
  text: await streamPromise.promise
@@ -667,7 +650,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
667
650
  attributes: {
668
651
  durationMs: duration,
669
652
  sleepType: fn ? "dynamic" : "fixed"
670
- }
653
+ },
654
+ isInternal: tracingContext?.isInternal
671
655
  });
672
656
  if (fn) {
673
657
  const stepCallId = randomUUID();
@@ -680,7 +664,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
680
664
  inputData: prevOutput,
681
665
  runCount: -1,
682
666
  tracingContext: {
683
- currentSpan: sleepSpan
667
+ currentSpan: sleepSpan,
668
+ isInternal: sleepSpan?.isInternal
684
669
  },
685
670
  getInitData: () => stepResults?.input,
686
671
  getStepResult: (step) => {
@@ -752,7 +737,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
752
737
  untilDate: date,
753
738
  durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
754
739
  sleepType: fn ? "dynamic" : "fixed"
755
- }
740
+ },
741
+ isInternal: tracingContext?.isInternal
756
742
  });
757
743
  if (fn) {
758
744
  date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
@@ -765,7 +751,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
765
751
  inputData: prevOutput,
766
752
  runCount: -1,
767
753
  tracingContext: {
768
- currentSpan: sleepUntilSpan
754
+ currentSpan: sleepUntilSpan,
755
+ isInternal: sleepUntilSpan?.isInternal
769
756
  },
770
757
  getInitData: () => stepResults?.input,
771
758
  getStepResult: (step) => {
@@ -802,6 +789,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
802
789
  )
803
790
  });
804
791
  });
792
+ if (date && !(date instanceof Date)) {
793
+ date = new Date(date);
794
+ }
805
795
  const time = !date ? 0 : date.getTime() - Date.now();
806
796
  sleepUntilSpan?.update({
807
797
  attributes: {
@@ -850,7 +840,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
850
840
  input: prevOutput,
851
841
  attributes: {
852
842
  stepId: step.id
853
- }
843
+ },
844
+ isInternal: tracingContext?.isInternal
854
845
  });
855
846
  const startedAt = await this.inngestStep.run(
856
847
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
@@ -1073,7 +1064,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1073
1064
  inputData: prevOutput,
1074
1065
  resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
1075
1066
  tracingContext: {
1076
- currentSpan: stepAISpan
1067
+ currentSpan: stepAISpan,
1068
+ isInternal: stepAISpan?.isInternal
1077
1069
  },
1078
1070
  getInitData: () => stepResults?.input,
1079
1071
  getStepResult: (step2) => {
@@ -1198,7 +1190,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1198
1190
  stepId: step.id,
1199
1191
  runtimeContext,
1200
1192
  disableScorers,
1201
- tracingContext: { currentSpan: stepAISpan }
1193
+ tracingContext: { currentSpan: stepAISpan, isInternal: true }
1202
1194
  });
1203
1195
  }
1204
1196
  });
@@ -1211,6 +1203,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1211
1203
  workflowId,
1212
1204
  runId,
1213
1205
  stepResults,
1206
+ resourceId,
1214
1207
  executionContext,
1215
1208
  serializedStepGraph,
1216
1209
  workflowStatus,
@@ -1223,6 +1216,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1223
1216
  await this.mastra?.getStorage()?.persistWorkflowSnapshot({
1224
1217
  workflowName: workflowId,
1225
1218
  runId,
1219
+ resourceId,
1226
1220
  snapshot: {
1227
1221
  runId,
1228
1222
  value: {},
@@ -1264,7 +1258,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1264
1258
  input: prevOutput,
1265
1259
  attributes: {
1266
1260
  conditionCount: entry.conditions.length
1267
- }
1261
+ },
1262
+ isInternal: tracingContext?.isInternal
1268
1263
  });
1269
1264
  let execResults;
1270
1265
  const truthyIndexes = (await Promise.all(
@@ -1276,7 +1271,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1276
1271
  input: prevOutput,
1277
1272
  attributes: {
1278
1273
  conditionIndex: index
1279
- }
1274
+ },
1275
+ isInternal: tracingContext?.isInternal
1280
1276
  });
1281
1277
  try {
1282
1278
  const result = await cond({
@@ -1287,7 +1283,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1287
1283
  runCount: -1,
1288
1284
  inputData: prevOutput,
1289
1285
  tracingContext: {
1290
- currentSpan: evalSpan
1286
+ currentSpan: evalSpan,
1287
+ isInternal: evalSpan?.isInternal
1291
1288
  },
1292
1289
  getInitData: () => stepResults?.input,
1293
1290
  getStepResult: (step) => {
@@ -1375,7 +1372,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1375
1372
  writableStream,
1376
1373
  disableScorers,
1377
1374
  tracingContext: {
1378
- currentSpan: conditionalSpan
1375
+ currentSpan: conditionalSpan,
1376
+ isInternal: conditionalSpan?.isInternal
1379
1377
  }
1380
1378
  })
1381
1379
  )