@mastra/inngest 0.14.1 → 0.14.2-alpha.0

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
@@ -3,7 +3,7 @@ import { subscribe } from '@inngest/realtime';
3
3
  import { wrapMastra, AISpanType } from '@mastra/core/ai-tracing';
4
4
  import { RuntimeContext } from '@mastra/core/di';
5
5
  import { ToolStream, Tool } from '@mastra/core/tools';
6
- import { Run, Workflow, DefaultExecutionEngine, getStepResult } from '@mastra/core/workflows';
6
+ import { Run, Workflow, DefaultExecutionEngine, getStepResult, validateStepInput } from '@mastra/core/workflows';
7
7
  import { EMITTER_SYMBOL, STREAM_FORMAT_SYMBOL } from '@mastra/core/workflows/_constants';
8
8
  import { serve as serve$1 } from 'inngest/hono';
9
9
  import { z } from 'zod';
@@ -12,7 +12,8 @@ import { z } from 'zod';
12
12
  function serve({
13
13
  mastra,
14
14
  inngest,
15
- functions: userFunctions = []
15
+ functions: userFunctions = [],
16
+ registerOptions
16
17
  }) {
17
18
  const wfs = mastra.getWorkflows();
18
19
  const workflowFunctions = Array.from(
@@ -27,6 +28,7 @@ function serve({
27
28
  )
28
29
  );
29
30
  return serve$1({
31
+ ...registerOptions,
30
32
  client: inngest,
31
33
  functions: [...workflowFunctions, ...userFunctions]
32
34
  });
@@ -115,10 +117,11 @@ var InngestRun = class extends Run {
115
117
  status: "running"
116
118
  }
117
119
  });
120
+ const inputDataToUse = await this._validateInput(inputData);
118
121
  const eventOutput = await this.inngest.send({
119
122
  name: `workflow.${this.workflowId}`,
120
123
  data: {
121
- inputData,
124
+ inputData: inputDataToUse,
122
125
  runId: this.runId,
123
126
  resourceId: this.resourceId
124
127
  }
@@ -156,17 +159,19 @@ var InngestRun = class extends Run {
156
159
  workflowName: this.workflowId,
157
160
  runId: this.runId
158
161
  });
162
+ const suspendedStep = this.workflowSteps[steps?.[0] ?? ""];
163
+ const resumeDataToUse = await this._validateResumeData(params.resumeData, suspendedStep);
159
164
  const eventOutput = await this.inngest.send({
160
165
  name: `workflow.${this.workflowId}`,
161
166
  data: {
162
- inputData: params.resumeData,
167
+ inputData: resumeDataToUse,
163
168
  runId: this.runId,
164
169
  workflowId: this.workflowId,
165
170
  stepResults: snapshot?.context,
166
171
  resume: {
167
172
  steps,
168
173
  stepResults: snapshot?.context,
169
- resumePayload: params.resumeData,
174
+ resumePayload: resumeDataToUse,
170
175
  // @ts-ignore
171
176
  resumePath: snapshot?.suspendedPaths?.[steps?.[0]]
172
177
  }
@@ -313,7 +318,8 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
313
318
  serializedStepGraph: this.serializedStepGraph,
314
319
  mastra: this.#mastra,
315
320
  retryConfig: this.retryConfig,
316
- cleanup: () => this.runs.delete(runIdToUse)
321
+ cleanup: () => this.runs.delete(runIdToUse),
322
+ workflowSteps: this.steps
317
323
  },
318
324
  this.inngest
319
325
  );
@@ -434,6 +440,7 @@ function createStep(params) {
434
440
  if (isAgent(params)) {
435
441
  return {
436
442
  id: params.name,
443
+ description: params.getDescription(),
437
444
  // @ts-ignore
438
445
  inputSchema: z.object({
439
446
  prompt: z.string()
@@ -483,7 +490,8 @@ function createStep(params) {
483
490
  return {
484
491
  text: await streamPromise.promise
485
492
  };
486
- }
493
+ },
494
+ component: params.component
487
495
  };
488
496
  }
489
497
  if (isTool(params)) {
@@ -494,6 +502,7 @@ function createStep(params) {
494
502
  // TODO: tool probably should have strong id type
495
503
  // @ts-ignore
496
504
  id: params.id,
505
+ description: params.description,
497
506
  inputSchema: params.inputSchema,
498
507
  outputSchema: params.outputSchema,
499
508
  execute: async ({ inputData, mastra, runtimeContext, tracingContext, suspend, resumeData }) => {
@@ -505,7 +514,8 @@ function createStep(params) {
505
514
  suspend,
506
515
  resumeData
507
516
  });
508
- }
517
+ },
518
+ component: "TOOL"
509
519
  };
510
520
  }
511
521
  return {
@@ -530,7 +540,8 @@ function init(inngest) {
530
540
  description: step.description,
531
541
  inputSchema: step.inputSchema,
532
542
  outputSchema: step.outputSchema,
533
- execute: step.execute
543
+ execute: step.execute,
544
+ component: step.component
534
545
  };
535
546
  },
536
547
  cloneWorkflow(workflow, opts) {
@@ -820,6 +831,11 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
820
831
  },
821
832
  tracingPolicy: this.options?.tracingPolicy
822
833
  });
834
+ const { inputData, validationError } = await validateStepInput({
835
+ prevOutput,
836
+ step,
837
+ validateInputs: this.options?.validateInputs ?? false
838
+ });
823
839
  const startedAt = await this.inngestStep.run(
824
840
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
825
841
  async () => {
@@ -850,7 +866,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
850
866
  payload: {
851
867
  id: step.id,
852
868
  status: "running",
853
- payload: prevOutput,
869
+ payload: inputData,
854
870
  startedAt: startedAt2
855
871
  }
856
872
  });
@@ -870,7 +886,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
870
886
  const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
871
887
  function: step.getFunction(),
872
888
  data: {
873
- inputData: prevOutput,
889
+ inputData,
874
890
  runId,
875
891
  resume: {
876
892
  runId,
@@ -888,7 +904,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
888
904
  const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
889
905
  function: step.getFunction(),
890
906
  data: {
891
- inputData: prevOutput
907
+ inputData
892
908
  }
893
909
  });
894
910
  result = invokeResp.result;
@@ -1033,12 +1049,15 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1033
1049
  let suspended;
1034
1050
  let bailed;
1035
1051
  try {
1052
+ if (validationError) {
1053
+ throw validationError;
1054
+ }
1036
1055
  const result = await step.execute({
1037
1056
  runId: executionContext.runId,
1038
1057
  mastra: this.mastra,
1039
1058
  runtimeContext,
1040
1059
  writableStream,
1041
- inputData: prevOutput,
1060
+ inputData,
1042
1061
  resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
1043
1062
  tracingContext: {
1044
1063
  currentSpan: stepAISpan
@@ -1070,14 +1089,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1070
1089
  output: result,
1071
1090
  startedAt,
1072
1091
  endedAt,
1073
- payload: prevOutput,
1092
+ payload: inputData,
1074
1093
  resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
1075
1094
  resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
1076
1095
  };
1077
1096
  } catch (e) {
1078
1097
  execResults = {
1079
1098
  status: "failed",
1080
- payload: prevOutput,
1099
+ payload: inputData,
1081
1100
  error: e instanceof Error ? e.message : String(e),
1082
1101
  endedAt: Date.now(),
1083
1102
  startedAt,
@@ -1089,14 +1108,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1089
1108
  execResults = {
1090
1109
  status: "suspended",
1091
1110
  suspendedPayload: suspended.payload,
1092
- payload: prevOutput,
1111
+ payload: inputData,
1093
1112
  suspendedAt: Date.now(),
1094
1113
  startedAt,
1095
1114
  resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
1096
1115
  resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
1097
1116
  };
1098
1117
  } else if (bailed) {
1099
- execResults = { status: "bailed", output: bailed.payload, payload: prevOutput, endedAt: Date.now(), startedAt };
1118
+ execResults = { status: "bailed", output: bailed.payload, payload: inputData, endedAt: Date.now(), startedAt };
1100
1119
  }
1101
1120
  if (execResults.status === "failed") {
1102
1121
  if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
@@ -1154,7 +1173,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1154
1173
  await this.runScorers({
1155
1174
  scorers: step.scorers,
1156
1175
  runId: executionContext.runId,
1157
- input: prevOutput,
1176
+ input: inputData,
1158
1177
  output: stepRes.result,
1159
1178
  workflowId: executionContext.workflowId,
1160
1179
  stepId: step.id,