@mastra/inngest 0.0.0-custom-instrumentation-20250626084921 → 0.0.0-fix-generate-title-20250616171351

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
@@ -1,7 +1,7 @@
1
1
  import { randomUUID } from 'crypto';
2
2
  import { subscribe } from '@inngest/realtime';
3
+ import { Agent, Tool } from '@mastra/core';
3
4
  import { RuntimeContext } from '@mastra/core/di';
4
- import { Tool } from '@mastra/core/tools';
5
5
  import { Run, Workflow, DefaultExecutionEngine } from '@mastra/core/workflows';
6
6
  import { EMITTER_SYMBOL } from '@mastra/core/workflows/_constants';
7
7
  import { serve as serve$1 } from 'inngest/hono';
@@ -43,7 +43,7 @@ var InngestRun = class extends Run {
43
43
  }
44
44
  async getRunOutput(eventId) {
45
45
  let runs = await this.getRuns(eventId);
46
- while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
46
+ while (runs?.[0]?.status !== "Completed") {
47
47
  await new Promise((resolve) => setTimeout(resolve, 1e3));
48
48
  runs = await this.getRuns(eventId);
49
49
  if (runs?.[0]?.status === "Failed" || runs?.[0]?.status === "Cancelled") {
@@ -52,12 +52,6 @@ var InngestRun = class extends Run {
52
52
  }
53
53
  return runs?.[0];
54
54
  }
55
- async sendEvent(event, data) {
56
- await this.inngest.send({
57
- name: `user-event-${event}`,
58
- data
59
- });
60
- }
61
55
  async start({
62
56
  inputData
63
57
  }) {
@@ -95,17 +89,6 @@ var InngestRun = class extends Run {
95
89
  return result;
96
90
  }
97
91
  async resume(params) {
98
- const p = this._resume(params).then((result) => {
99
- if (result.status !== "suspended") {
100
- this.closeStreamAction?.().catch(() => {
101
- });
102
- }
103
- return result;
104
- });
105
- this.executionResults = p;
106
- return p;
107
- }
108
- async _resume(params) {
109
92
  const steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
110
93
  (step) => typeof step === "string" ? step : step?.id
111
94
  );
@@ -139,60 +122,25 @@ var InngestRun = class extends Run {
139
122
  }
140
123
  return result;
141
124
  }
142
- watch(cb, type = "watch") {
143
- let active = true;
125
+ watch(cb) {
144
126
  const streamPromise = subscribe(
145
127
  {
146
128
  channel: `workflow:${this.workflowId}:${this.runId}`,
147
- topics: [type],
129
+ topics: ["watch"],
148
130
  app: this.inngest
149
131
  },
150
132
  (message) => {
151
- if (active) {
152
- cb(message.data);
153
- }
133
+ cb(message.data);
154
134
  }
155
135
  );
156
136
  return () => {
157
- active = false;
158
- streamPromise.then(async (stream) => {
159
- return stream.cancel();
137
+ streamPromise.then((stream) => {
138
+ stream.cancel();
160
139
  }).catch((err) => {
161
140
  console.error(err);
162
141
  });
163
142
  };
164
143
  }
165
- stream({ inputData, runtimeContext } = {}) {
166
- const { readable, writable } = new TransformStream();
167
- const writer = writable.getWriter();
168
- const unwatch = this.watch(async (event) => {
169
- try {
170
- await writer.write(event);
171
- } catch {
172
- }
173
- }, "watch-v2");
174
- this.closeStreamAction = async () => {
175
- unwatch();
176
- try {
177
- await writer.close();
178
- } catch (err) {
179
- console.error("Error closing stream:", err);
180
- } finally {
181
- writer.releaseLock();
182
- }
183
- };
184
- this.executionResults = this.start({ inputData, runtimeContext }).then((result) => {
185
- if (result.status !== "suspended") {
186
- this.closeStreamAction?.().catch(() => {
187
- });
188
- }
189
- return result;
190
- });
191
- return {
192
- stream: readable,
193
- getWorkflowState: () => this.executionResults
194
- };
195
- }
196
144
  };
197
145
  var InngestWorkflow = class _InngestWorkflow extends Workflow {
198
146
  #mastra;
@@ -277,41 +225,6 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
277
225
  this.runs.set(runIdToUse, run);
278
226
  return run;
279
227
  }
280
- async createRunAsync(options) {
281
- const runIdToUse = options?.runId || randomUUID();
282
- const run = this.runs.get(runIdToUse) ?? new InngestRun(
283
- {
284
- workflowId: this.id,
285
- runId: runIdToUse,
286
- executionEngine: this.executionEngine,
287
- executionGraph: this.executionGraph,
288
- serializedStepGraph: this.serializedStepGraph,
289
- mastra: this.#mastra,
290
- retryConfig: this.retryConfig,
291
- cleanup: () => this.runs.delete(runIdToUse)
292
- },
293
- this.inngest
294
- );
295
- this.runs.set(runIdToUse, run);
296
- await this.mastra?.getStorage()?.persistWorkflowSnapshot({
297
- workflowName: this.id,
298
- runId: runIdToUse,
299
- snapshot: {
300
- runId: runIdToUse,
301
- status: "pending",
302
- value: {},
303
- context: {},
304
- activePaths: [],
305
- serializedStepGraph: this.serializedStepGraph,
306
- suspendedPaths: {},
307
- result: void 0,
308
- error: void 0,
309
- // @ts-ignore
310
- timestamp: Date.now()
311
- }
312
- });
313
- return run;
314
- }
315
228
  getFunction() {
316
229
  if (this.function) {
317
230
  return this.function;
@@ -335,18 +248,12 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
335
248
  try {
336
249
  await publish({
337
250
  channel: `workflow:${this.id}:${runId}`,
338
- topic: event2,
251
+ topic: "watch",
339
252
  data
340
253
  });
341
254
  } catch (err) {
342
255
  this.logger.error("Error emitting event: " + (err?.stack ?? err?.message ?? err));
343
256
  }
344
- },
345
- on: (_event, _callback) => {
346
- },
347
- off: (_event, _callback) => {
348
- },
349
- once: (_event, _callback) => {
350
257
  }
351
258
  };
352
259
  const engine = new InngestExecutionEngine(this.#mastra, step, attempt);
@@ -384,14 +291,8 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
384
291
  return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
385
292
  }
386
293
  };
387
- function isAgent(params) {
388
- return params?.component === "AGENT";
389
- }
390
- function isTool(params) {
391
- return params instanceof Tool;
392
- }
393
294
  function createStep(params) {
394
- if (isAgent(params)) {
295
+ if (params instanceof Agent) {
395
296
  return {
396
297
  id: params.name,
397
298
  // @ts-ignore
@@ -456,7 +357,7 @@ function createStep(params) {
456
357
  }
457
358
  };
458
359
  }
459
- if (isTool(params)) {
360
+ if (params instanceof Tool) {
460
361
  if (!params.inputSchema || !params.outputSchema) {
461
362
  throw new Error("Tool must have input and output schemas defined");
462
363
  }
@@ -522,18 +423,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
522
423
  this.inngestStep = inngestStep;
523
424
  this.inngestAttempts = inngestAttempts;
524
425
  }
525
- async execute(params) {
526
- await params.emitter.emit("watch-v2", {
527
- type: "start",
528
- payload: { runId: params.runId }
529
- });
530
- const result = await super.execute(params);
531
- await params.emitter.emit("watch-v2", {
532
- type: "finish",
533
- payload: { runId: params.runId }
534
- });
535
- return result;
536
- }
537
426
  async fmtReturnValue(executionSpan, emitter, stepResults, lastOutput, error) {
538
427
  const base = {
539
428
  status: lastOutput.status,
@@ -617,16 +506,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
617
506
  async executeSleep({ id, duration }) {
618
507
  await this.inngestStep.sleep(id, duration);
619
508
  }
620
- async executeWaitForEvent({ event, timeout }) {
621
- const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
622
- event: `user-event-${event}`,
623
- timeout: timeout ?? 5e3
624
- });
625
- if (eventData === null) {
626
- throw "Timeout waiting for event";
627
- }
628
- return eventData?.data;
629
- }
630
509
  async executeStep({
631
510
  step,
632
511
  stepResults,
@@ -636,10 +515,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
636
515
  emitter,
637
516
  runtimeContext
638
517
  }) {
639
- const startedAt = await this.inngestStep.run(
518
+ await this.inngestStep.run(
640
519
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
641
520
  async () => {
642
- const startedAt2 = Date.now();
643
521
  await emitter.emit("watch", {
644
522
  type: "watch",
645
523
  payload: {
@@ -661,13 +539,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
661
539
  },
662
540
  eventTimestamp: Date.now()
663
541
  });
664
- await emitter.emit("watch-v2", {
665
- type: "step-start",
666
- payload: {
667
- id: step.id
668
- }
669
- });
670
- return startedAt2;
671
542
  }
672
543
  );
673
544
  if (step instanceof InngestWorkflow) {
@@ -728,13 +599,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
728
599
  },
729
600
  eventTimestamp: Date.now()
730
601
  });
731
- await emitter.emit("watch-v2", {
732
- type: "step-result",
733
- payload: {
734
- id: step.id,
735
- status: "failed"
736
- }
737
- });
738
602
  return { executionContext, result: { status: "failed", error: result?.error } };
739
603
  } else if (result.status === "suspended") {
740
604
  const suspendedSteps = Object.entries(result.steps).filter(([_stepName, stepResult]) => {
@@ -761,12 +625,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
761
625
  },
762
626
  eventTimestamp: Date.now()
763
627
  });
764
- await emitter.emit("watch-v2", {
765
- type: "step-suspended",
766
- payload: {
767
- id: step.id
768
- }
769
- });
770
628
  return {
771
629
  executionContext,
772
630
  result: {
@@ -817,13 +675,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
817
675
  },
818
676
  eventTimestamp: Date.now()
819
677
  });
820
- await emitter.emit("watch-v2", {
821
- type: "step-finish",
822
- payload: {
823
- id: step.id,
824
- metadata: {}
825
- }
826
- });
827
678
  return { executionContext, result: { status: "success", output: result?.result } };
828
679
  }
829
680
  );
@@ -833,7 +684,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
833
684
  const stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
834
685
  let execResults;
835
686
  let suspended;
836
- let bailed;
837
687
  try {
838
688
  const result = await step.execute({
839
689
  runId: executionContext.runId,
@@ -853,9 +703,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
853
703
  executionContext.suspendedPaths[step.id] = executionContext.executionPath;
854
704
  suspended = { payload: suspendPayload };
855
705
  },
856
- bail: (result2) => {
857
- bailed = { payload: result2 };
858
- },
859
706
  resume: {
860
707
  steps: resume?.steps?.slice(1) || [],
861
708
  resumePayload: resume?.resumePayload,
@@ -867,39 +714,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
867
714
  step: this.inngestStep
868
715
  }
869
716
  });
870
- const endedAt = Date.now();
871
- execResults = {
872
- status: "success",
873
- output: result,
874
- startedAt,
875
- endedAt,
876
- payload: prevOutput,
877
- resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
878
- resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
879
- };
717
+ execResults = { status: "success", output: result };
880
718
  } catch (e) {
881
- execResults = {
882
- status: "failed",
883
- payload: prevOutput,
884
- error: e instanceof Error ? e.message : String(e),
885
- endedAt: Date.now(),
886
- startedAt,
887
- resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
888
- resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
889
- };
719
+ execResults = { status: "failed", error: e instanceof Error ? e.message : String(e) };
890
720
  }
891
721
  if (suspended) {
892
- execResults = {
893
- status: "suspended",
894
- suspendedPayload: suspended.payload,
895
- payload: prevOutput,
896
- suspendedAt: Date.now(),
897
- startedAt,
898
- resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
899
- resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
900
- };
901
- } else if (bailed) {
902
- execResults = { status: "bailed", output: bailed.payload, payload: prevOutput, endedAt: Date.now(), startedAt };
722
+ execResults = { status: "suspended", payload: suspended.payload };
903
723
  }
904
724
  if (execResults.status === "failed") {
905
725
  if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
@@ -911,43 +731,18 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
911
731
  payload: {
912
732
  currentStep: {
913
733
  id: step.id,
914
- ...execResults
734
+ status: execResults.status,
735
+ output: execResults.output
915
736
  },
916
737
  workflowState: {
917
738
  status: "running",
918
- steps: { ...stepResults, [step.id]: execResults },
739
+ steps: stepResults,
919
740
  result: null,
920
741
  error: null
921
742
  }
922
743
  },
923
744
  eventTimestamp: Date.now()
924
745
  });
925
- if (execResults.status === "suspended") {
926
- await emitter.emit("watch-v2", {
927
- type: "step-suspended",
928
- payload: {
929
- id: step.id,
930
- status: execResults.status,
931
- output: execResults.status === "success" ? execResults?.output : void 0
932
- }
933
- });
934
- } else {
935
- await emitter.emit("watch-v2", {
936
- type: "step-result",
937
- payload: {
938
- id: step.id,
939
- status: execResults.status,
940
- output: execResults.status === "success" ? execResults?.output : void 0
941
- }
942
- });
943
- await emitter.emit("watch-v2", {
944
- type: "step-finish",
945
- payload: {
946
- id: step.id,
947
- metadata: {}
948
- }
949
- });
950
- }
951
746
  return { result: execResults, executionContext, stepResults };
952
747
  });
953
748
  Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
@@ -1024,8 +819,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1024
819
  // TODO: this function shouldn't have suspend probably?
1025
820
  suspend: async (_suspendPayload) => {
1026
821
  },
1027
- bail: () => {
1028
- },
1029
822
  [EMITTER_SYMBOL]: emitter,
1030
823
  engine: {
1031
824
  step: this.inngestStep
@@ -1067,7 +860,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1067
860
  if (hasFailed) {
1068
861
  execResults = { status: "failed", error: hasFailed.result.error };
1069
862
  } else if (hasSuspended) {
1070
- execResults = { status: "suspended", payload: hasSuspended.result.suspendPayload };
863
+ execResults = { status: "suspended", payload: hasSuspended.result.payload };
1071
864
  } else {
1072
865
  execResults = {
1073
866
  status: "success",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/inngest",
3
- "version": "0.0.0-custom-instrumentation-20250626084921",
3
+ "version": "0.0.0-fix-generate-title-20250616171351",
4
4
  "description": "Mastra Inngest integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "@inngest/realtime": "^0.3.1",
23
23
  "@opentelemetry/api": "^1.9.0",
24
24
  "inngest": "^3.39.1",
25
- "zod": "^3.25.67"
25
+ "zod": "^3.25.57"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@ai-sdk/openai": "^1.3.22",
@@ -30,20 +30,20 @@
30
30
  "@microsoft/api-extractor": "^7.52.8",
31
31
  "@types/node": "^20.19.0",
32
32
  "ai": "^4.3.16",
33
- "eslint": "^9.29.0",
33
+ "eslint": "^9.28.0",
34
34
  "execa": "^9.6.0",
35
35
  "get-port": "7.1.0",
36
36
  "hono": "^4.7.11",
37
37
  "tsup": "^8.5.0",
38
38
  "typescript": "^5.8.3",
39
39
  "vitest": "^2.1.9",
40
- "@internal/lint": "0.0.0-custom-instrumentation-20250626084921",
41
- "@mastra/core": "0.0.0-custom-instrumentation-20250626084921",
42
- "@mastra/libsql": "0.0.0-custom-instrumentation-20250626084921",
43
- "@mastra/deployer": "0.0.0-custom-instrumentation-20250626084921"
40
+ "@internal/lint": "0.0.0-fix-generate-title-20250616171351",
41
+ "@mastra/libsql": "0.0.0-fix-generate-title-20250616171351",
42
+ "@mastra/core": "0.0.0-fix-generate-title-20250616171351",
43
+ "@mastra/deployer": "0.0.0-fix-generate-title-20250616171351"
44
44
  },
45
45
  "peerDependencies": {
46
- "@mastra/core": "0.0.0-custom-instrumentation-20250626084921"
46
+ "@mastra/core": "0.0.0-fix-generate-title-20250616171351"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",