@mastra/inngest 0.13.3-alpha.0 → 0.14.0-alpha.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @mastra/inngest
2
2
 
3
+ ## 0.14.0-alpha.2
4
+
5
+ ### Minor Changes
6
+
7
+ - Fully deprecated createRun (now throws an error) in favour of createRunAsync ([#7897](https://github.com/mastra-ai/mastra/pull/7897))
8
+
9
+ ### Patch Changes
10
+
11
+ - refactored handling of internal ai spans to be more intelligent ([#7876](https://github.com/mastra-ai/mastra/pull/7876))
12
+
13
+ - feat(inngest): add support for user-supplied functions in `serve` / `inngestServe` ([#7900](https://github.com/mastra-ai/mastra/pull/7900))
14
+
15
+ - Updated dependencies [[`fb84c21`](https://github.com/mastra-ai/mastra/commit/fb84c21859d09bdc8f158bd5412bdc4b5835a61c), [`9d4fc09`](https://github.com/mastra-ai/mastra/commit/9d4fc09b2ad55caa7738c7ceb3a905e454f74cdd), [`d75ccf0`](https://github.com/mastra-ai/mastra/commit/d75ccf06dfd2582b916aa12624e3cd61b279edf1), [`0fed8f2`](https://github.com/mastra-ai/mastra/commit/0fed8f2aa84b167b3415ea6f8f70755775132c8d), [`87fd07f`](https://github.com/mastra-ai/mastra/commit/87fd07ff35387a38728967163460231b5d33ae3b)]:
16
+ - @mastra/core@0.17.0-alpha.4
17
+
18
+ ## 0.13.3-alpha.1
19
+
20
+ ### Patch Changes
21
+
22
+ - dependencies updates: ([#7865](https://github.com/mastra-ai/mastra/pull/7865))
23
+ - Updated dependency [`inngest@^3.40.3` ↗︎](https://www.npmjs.com/package/inngest/v/3.40.3) (from `^3.40.2`, in `dependencies`)
24
+
25
+ - Update peerdep of @mastra/core ([#7619](https://github.com/mastra-ai/mastra/pull/7619))
26
+
27
+ - fix(workflows/inngest): handle Date serialization in sleepUntil execution ([#7863](https://github.com/mastra-ai/mastra/pull/7863))
28
+
29
+ - add resourceId support to inngest workflow execution engine for workflow snapshot persistance ([#7792](https://github.com/mastra-ai/mastra/pull/7792))
30
+
31
+ - Updated dependencies [[`a1bb887`](https://github.com/mastra-ai/mastra/commit/a1bb887e8bfae44230f487648da72e96ef824561), [`a0f5f1c`](https://github.com/mastra-ai/mastra/commit/a0f5f1ca39c3c5c6d26202e9fcab986b4fe14568), [`b356f5f`](https://github.com/mastra-ai/mastra/commit/b356f5f7566cb3edb755d91f00b72fc1420b2a37), [`f5ce05f`](https://github.com/mastra-ai/mastra/commit/f5ce05f831d42c69559bf4c0fdb46ccb920fc3a3), [`9f6f30f`](https://github.com/mastra-ai/mastra/commit/9f6f30f04ec6648bbca798ea8aad59317c40d8db), [`d706fad`](https://github.com/mastra-ai/mastra/commit/d706fad6e6e4b72357b18d229ba38e6c913c0e70), [`5c3768f`](https://github.com/mastra-ai/mastra/commit/5c3768fa959454232ad76715c381f4aac00c6881), [`8a3f5e4`](https://github.com/mastra-ai/mastra/commit/8a3f5e4212ec36b302957deb4bd47005ab598382)]:
32
+ - @mastra/core@0.17.0-alpha.3
33
+
3
34
  ## 0.13.3-alpha.0
4
35
 
5
36
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -11,9 +11,13 @@ var hono = require('inngest/hono');
11
11
  var zod = require('zod');
12
12
 
13
13
  // src/index.ts
14
- function serve({ mastra, inngest }) {
14
+ function serve({
15
+ mastra,
16
+ inngest,
17
+ functions: userFunctions = []
18
+ }) {
15
19
  const wfs = mastra.getWorkflows();
16
- const functions = Array.from(
20
+ const workflowFunctions = Array.from(
17
21
  new Set(
18
22
  Object.values(wfs).flatMap((wf) => {
19
23
  if (wf instanceof InngestWorkflow) {
@@ -26,7 +30,7 @@ function serve({ mastra, inngest }) {
26
30
  );
27
31
  return hono.serve({
28
32
  client: inngest,
29
- functions
33
+ functions: [...workflowFunctions, ...userFunctions]
30
34
  });
31
35
  }
32
36
  var InngestRun = class extends workflows.Run {
@@ -54,7 +58,6 @@ var InngestRun = class extends workflows.Run {
54
58
  await new Promise((resolve) => setTimeout(resolve, 1e3));
55
59
  runs = await this.getRuns(eventId);
56
60
  if (runs?.[0]?.status === "Failed") {
57
- console.log("run", runs?.[0]);
58
61
  throw new Error(`Function run ${runs?.[0]?.status}`);
59
62
  } else if (runs?.[0]?.status === "Cancelled") {
60
63
  const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
@@ -87,6 +90,7 @@ var InngestRun = class extends workflows.Run {
87
90
  await this.#mastra?.storage?.persistWorkflowSnapshot({
88
91
  workflowName: this.workflowId,
89
92
  runId: this.runId,
93
+ resourceId: this.resourceId,
90
94
  snapshot: {
91
95
  ...snapshot,
92
96
  status: "canceled"
@@ -100,6 +104,7 @@ var InngestRun = class extends workflows.Run {
100
104
  await this.#mastra.getStorage()?.persistWorkflowSnapshot({
101
105
  workflowName: this.workflowId,
102
106
  runId: this.runId,
107
+ resourceId: this.resourceId,
103
108
  snapshot: {
104
109
  runId: this.runId,
105
110
  serializedStepGraph: this.serializedStepGraph,
@@ -116,7 +121,8 @@ var InngestRun = class extends workflows.Run {
116
121
  name: `workflow.${this.workflowId}`,
117
122
  data: {
118
123
  inputData,
119
- runId: this.runId
124
+ runId: this.runId,
125
+ resourceId: this.resourceId
120
126
  }
121
127
  });
122
128
  const eventId = eventOutput.ids[0];
@@ -288,23 +294,14 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
288
294
  }
289
295
  }
290
296
  }
291
- createRun(options) {
292
- const runIdToUse = options?.runId || crypto.randomUUID();
293
- const run = this.runs.get(runIdToUse) ?? new InngestRun(
294
- {
295
- workflowId: this.id,
296
- runId: runIdToUse,
297
- executionEngine: this.executionEngine,
298
- executionGraph: this.executionGraph,
299
- serializedStepGraph: this.serializedStepGraph,
300
- mastra: this.#mastra,
301
- retryConfig: this.retryConfig,
302
- cleanup: () => this.runs.delete(runIdToUse)
303
- },
304
- this.inngest
297
+ /**
298
+ * @deprecated Use createRunAsync() instead.
299
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
300
+ */
301
+ createRun(_options) {
302
+ throw new Error(
303
+ "createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
305
304
  );
306
- this.runs.set(runIdToUse, run);
307
- return run;
308
305
  }
309
306
  async createRunAsync(options) {
310
307
  const runIdToUse = options?.runId || crypto.randomUUID();
@@ -312,6 +309,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
312
309
  {
313
310
  workflowId: this.id,
314
311
  runId: runIdToUse,
312
+ resourceId: options?.resourceId,
315
313
  executionEngine: this.executionEngine,
316
314
  executionGraph: this.executionGraph,
317
315
  serializedStepGraph: this.serializedStepGraph,
@@ -327,6 +325,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
327
325
  await this.mastra?.getStorage()?.persistWorkflowSnapshot({
328
326
  workflowName: this.id,
329
327
  runId: runIdToUse,
328
+ resourceId: options?.resourceId,
330
329
  snapshot: {
331
330
  runId: runIdToUse,
332
331
  status: "pending",
@@ -360,7 +359,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
360
359
  },
361
360
  { event: `workflow.${this.id}` },
362
361
  async ({ event, step, attempt, publish }) => {
363
- let { inputData, runId, resume } = event.data;
362
+ let { inputData, runId, resourceId, resume } = event.data;
364
363
  if (!runId) {
365
364
  runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
366
365
  return crypto.randomUUID();
@@ -392,6 +391,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
392
391
  const result = await engine.execute({
393
392
  workflowId: this.id,
394
393
  runId,
394
+ resourceId,
395
395
  graph: this.executionGraph,
396
396
  serializedStepGraph: this.serializedStepGraph,
397
397
  input: inputData,
@@ -439,8 +439,6 @@ function createStep(params) {
439
439
  // @ts-ignore
440
440
  inputSchema: zod.z.object({
441
441
  prompt: zod.z.string()
442
- // resourceId: z.string().optional(),
443
- // threadId: z.string().optional(),
444
442
  }),
445
443
  // @ts-ignore
446
444
  outputSchema: zod.z.object({
@@ -457,8 +455,6 @@ function createStep(params) {
457
455
  args: inputData
458
456
  };
459
457
  const { fullStream } = await params.stream(inputData.prompt, {
460
- // resourceId: inputData.resourceId,
461
- // threadId: inputData.threadId,
462
458
  runtimeContext,
463
459
  tracingContext,
464
460
  onFinish: (result) => {
@@ -554,8 +550,8 @@ function init(inngest) {
554
550
  var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
555
551
  inngestStep;
556
552
  inngestAttempts;
557
- constructor(mastra, inngestStep, inngestAttempts = 0) {
558
- super({ mastra });
553
+ constructor(mastra, inngestStep, inngestAttempts = 0, options) {
554
+ super({ mastra, options });
559
555
  this.inngestStep = inngestStep;
560
556
  this.inngestAttempts = inngestAttempts;
561
557
  }
@@ -652,7 +648,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
652
648
  durationMs: duration,
653
649
  sleepType: fn ? "dynamic" : "fixed"
654
650
  },
655
- isInternal: tracingContext?.isInternal
651
+ tracingPolicy: this.options?.tracingPolicy
656
652
  });
657
653
  if (fn) {
658
654
  const stepCallId = crypto.randomUUID();
@@ -665,8 +661,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
665
661
  inputData: prevOutput,
666
662
  runCount: -1,
667
663
  tracingContext: {
668
- currentSpan: sleepSpan,
669
- isInternal: sleepSpan?.isInternal
664
+ currentSpan: sleepSpan
670
665
  },
671
666
  getInitData: () => stepResults?.input,
672
667
  getStepResult: (step) => {
@@ -739,7 +734,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
739
734
  durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
740
735
  sleepType: fn ? "dynamic" : "fixed"
741
736
  },
742
- isInternal: tracingContext?.isInternal
737
+ tracingPolicy: this.options?.tracingPolicy
743
738
  });
744
739
  if (fn) {
745
740
  date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
@@ -752,8 +747,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
752
747
  inputData: prevOutput,
753
748
  runCount: -1,
754
749
  tracingContext: {
755
- currentSpan: sleepUntilSpan,
756
- isInternal: sleepUntilSpan?.isInternal
750
+ currentSpan: sleepUntilSpan
757
751
  },
758
752
  getInitData: () => stepResults?.input,
759
753
  getStepResult: (step) => {
@@ -790,6 +784,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
790
784
  )
791
785
  });
792
786
  });
787
+ if (date && !(date instanceof Date)) {
788
+ date = new Date(date);
789
+ }
793
790
  const time = !date ? 0 : date.getTime() - Date.now();
794
791
  sleepUntilSpan?.update({
795
792
  attributes: {
@@ -839,7 +836,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
839
836
  attributes: {
840
837
  stepId: step.id
841
838
  },
842
- isInternal: tracingContext?.isInternal
839
+ tracingPolicy: this.options?.tracingPolicy
843
840
  });
844
841
  const startedAt = await this.inngestStep.run(
845
842
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
@@ -1062,8 +1059,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1062
1059
  inputData: prevOutput,
1063
1060
  resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
1064
1061
  tracingContext: {
1065
- currentSpan: stepAISpan,
1066
- isInternal: stepAISpan?.isInternal
1062
+ currentSpan: stepAISpan
1067
1063
  },
1068
1064
  getInitData: () => stepResults?.input,
1069
1065
  getStepResult: (step2) => {
@@ -1188,7 +1184,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1188
1184
  stepId: step.id,
1189
1185
  runtimeContext,
1190
1186
  disableScorers,
1191
- tracingContext: { currentSpan: stepAISpan, isInternal: true }
1187
+ tracingContext: { currentSpan: stepAISpan }
1192
1188
  });
1193
1189
  }
1194
1190
  });
@@ -1201,6 +1197,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1201
1197
  workflowId,
1202
1198
  runId,
1203
1199
  stepResults,
1200
+ resourceId,
1204
1201
  executionContext,
1205
1202
  serializedStepGraph,
1206
1203
  workflowStatus,
@@ -1213,6 +1210,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1213
1210
  await this.mastra?.getStorage()?.persistWorkflowSnapshot({
1214
1211
  workflowName: workflowId,
1215
1212
  runId,
1213
+ resourceId,
1216
1214
  snapshot: {
1217
1215
  runId,
1218
1216
  value: {},
@@ -1255,7 +1253,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1255
1253
  attributes: {
1256
1254
  conditionCount: entry.conditions.length
1257
1255
  },
1258
- isInternal: tracingContext?.isInternal
1256
+ tracingPolicy: this.options?.tracingPolicy
1259
1257
  });
1260
1258
  let execResults;
1261
1259
  const truthyIndexes = (await Promise.all(
@@ -1268,7 +1266,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1268
1266
  attributes: {
1269
1267
  conditionIndex: index
1270
1268
  },
1271
- isInternal: tracingContext?.isInternal
1269
+ tracingPolicy: this.options?.tracingPolicy
1272
1270
  });
1273
1271
  try {
1274
1272
  const result = await cond({
@@ -1279,8 +1277,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1279
1277
  runCount: -1,
1280
1278
  inputData: prevOutput,
1281
1279
  tracingContext: {
1282
- currentSpan: evalSpan,
1283
- isInternal: evalSpan?.isInternal
1280
+ currentSpan: evalSpan
1284
1281
  },
1285
1282
  getInitData: () => stepResults?.input,
1286
1283
  getStepResult: (step) => {
@@ -1368,8 +1365,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1368
1365
  writableStream,
1369
1366
  disableScorers,
1370
1367
  tracingContext: {
1371
- currentSpan: conditionalSpan,
1372
- isInternal: conditionalSpan?.isInternal
1368
+ currentSpan: conditionalSpan
1373
1369
  }
1374
1370
  })
1375
1371
  )