@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/CHANGELOG.md +3 -99
- package/dist/_tsup-dts-rollup.d.cts +17 -51
- package/dist/_tsup-dts-rollup.d.ts +17 -51
- package/dist/index.cjs +18 -225
- package/dist/index.js +18 -225
- package/package.json +8 -8
- package/src/index.test.ts +132 -1478
- package/src/index.ts +28 -305
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var crypto = require('crypto');
|
|
4
4
|
var realtime = require('@inngest/realtime');
|
|
5
|
+
var core = require('@mastra/core');
|
|
5
6
|
var di = require('@mastra/core/di');
|
|
6
|
-
var tools = require('@mastra/core/tools');
|
|
7
7
|
var workflows = require('@mastra/core/workflows');
|
|
8
8
|
var _constants = require('@mastra/core/workflows/_constants');
|
|
9
9
|
var hono = require('inngest/hono');
|
|
@@ -45,7 +45,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
45
45
|
}
|
|
46
46
|
async getRunOutput(eventId) {
|
|
47
47
|
let runs = await this.getRuns(eventId);
|
|
48
|
-
while (runs?.[0]?.status !== "Completed"
|
|
48
|
+
while (runs?.[0]?.status !== "Completed") {
|
|
49
49
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
50
50
|
runs = await this.getRuns(eventId);
|
|
51
51
|
if (runs?.[0]?.status === "Failed" || runs?.[0]?.status === "Cancelled") {
|
|
@@ -54,12 +54,6 @@ var InngestRun = class extends workflows.Run {
|
|
|
54
54
|
}
|
|
55
55
|
return runs?.[0];
|
|
56
56
|
}
|
|
57
|
-
async sendEvent(event, data) {
|
|
58
|
-
await this.inngest.send({
|
|
59
|
-
name: `user-event-${event}`,
|
|
60
|
-
data
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
57
|
async start({
|
|
64
58
|
inputData
|
|
65
59
|
}) {
|
|
@@ -97,17 +91,6 @@ var InngestRun = class extends workflows.Run {
|
|
|
97
91
|
return result;
|
|
98
92
|
}
|
|
99
93
|
async resume(params) {
|
|
100
|
-
const p = this._resume(params).then((result) => {
|
|
101
|
-
if (result.status !== "suspended") {
|
|
102
|
-
this.closeStreamAction?.().catch(() => {
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
return result;
|
|
106
|
-
});
|
|
107
|
-
this.executionResults = p;
|
|
108
|
-
return p;
|
|
109
|
-
}
|
|
110
|
-
async _resume(params) {
|
|
111
94
|
const steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
|
|
112
95
|
(step) => typeof step === "string" ? step : step?.id
|
|
113
96
|
);
|
|
@@ -141,60 +124,25 @@ var InngestRun = class extends workflows.Run {
|
|
|
141
124
|
}
|
|
142
125
|
return result;
|
|
143
126
|
}
|
|
144
|
-
watch(cb
|
|
145
|
-
let active = true;
|
|
127
|
+
watch(cb) {
|
|
146
128
|
const streamPromise = realtime.subscribe(
|
|
147
129
|
{
|
|
148
130
|
channel: `workflow:${this.workflowId}:${this.runId}`,
|
|
149
|
-
topics: [
|
|
131
|
+
topics: ["watch"],
|
|
150
132
|
app: this.inngest
|
|
151
133
|
},
|
|
152
134
|
(message) => {
|
|
153
|
-
|
|
154
|
-
cb(message.data);
|
|
155
|
-
}
|
|
135
|
+
cb(message.data);
|
|
156
136
|
}
|
|
157
137
|
);
|
|
158
138
|
return () => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return stream.cancel();
|
|
139
|
+
streamPromise.then((stream) => {
|
|
140
|
+
stream.cancel();
|
|
162
141
|
}).catch((err) => {
|
|
163
142
|
console.error(err);
|
|
164
143
|
});
|
|
165
144
|
};
|
|
166
145
|
}
|
|
167
|
-
stream({ inputData, runtimeContext } = {}) {
|
|
168
|
-
const { readable, writable } = new TransformStream();
|
|
169
|
-
const writer = writable.getWriter();
|
|
170
|
-
const unwatch = this.watch(async (event) => {
|
|
171
|
-
try {
|
|
172
|
-
await writer.write(event);
|
|
173
|
-
} catch {
|
|
174
|
-
}
|
|
175
|
-
}, "watch-v2");
|
|
176
|
-
this.closeStreamAction = async () => {
|
|
177
|
-
unwatch();
|
|
178
|
-
try {
|
|
179
|
-
await writer.close();
|
|
180
|
-
} catch (err) {
|
|
181
|
-
console.error("Error closing stream:", err);
|
|
182
|
-
} finally {
|
|
183
|
-
writer.releaseLock();
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
this.executionResults = this.start({ inputData, runtimeContext }).then((result) => {
|
|
187
|
-
if (result.status !== "suspended") {
|
|
188
|
-
this.closeStreamAction?.().catch(() => {
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
return result;
|
|
192
|
-
});
|
|
193
|
-
return {
|
|
194
|
-
stream: readable,
|
|
195
|
-
getWorkflowState: () => this.executionResults
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
146
|
};
|
|
199
147
|
var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
200
148
|
#mastra;
|
|
@@ -279,41 +227,6 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
279
227
|
this.runs.set(runIdToUse, run);
|
|
280
228
|
return run;
|
|
281
229
|
}
|
|
282
|
-
async createRunAsync(options) {
|
|
283
|
-
const runIdToUse = options?.runId || crypto.randomUUID();
|
|
284
|
-
const run = this.runs.get(runIdToUse) ?? new InngestRun(
|
|
285
|
-
{
|
|
286
|
-
workflowId: this.id,
|
|
287
|
-
runId: runIdToUse,
|
|
288
|
-
executionEngine: this.executionEngine,
|
|
289
|
-
executionGraph: this.executionGraph,
|
|
290
|
-
serializedStepGraph: this.serializedStepGraph,
|
|
291
|
-
mastra: this.#mastra,
|
|
292
|
-
retryConfig: this.retryConfig,
|
|
293
|
-
cleanup: () => this.runs.delete(runIdToUse)
|
|
294
|
-
},
|
|
295
|
-
this.inngest
|
|
296
|
-
);
|
|
297
|
-
this.runs.set(runIdToUse, run);
|
|
298
|
-
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
299
|
-
workflowName: this.id,
|
|
300
|
-
runId: runIdToUse,
|
|
301
|
-
snapshot: {
|
|
302
|
-
runId: runIdToUse,
|
|
303
|
-
status: "pending",
|
|
304
|
-
value: {},
|
|
305
|
-
context: {},
|
|
306
|
-
activePaths: [],
|
|
307
|
-
serializedStepGraph: this.serializedStepGraph,
|
|
308
|
-
suspendedPaths: {},
|
|
309
|
-
result: void 0,
|
|
310
|
-
error: void 0,
|
|
311
|
-
// @ts-ignore
|
|
312
|
-
timestamp: Date.now()
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
return run;
|
|
316
|
-
}
|
|
317
230
|
getFunction() {
|
|
318
231
|
if (this.function) {
|
|
319
232
|
return this.function;
|
|
@@ -337,18 +250,12 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
337
250
|
try {
|
|
338
251
|
await publish({
|
|
339
252
|
channel: `workflow:${this.id}:${runId}`,
|
|
340
|
-
topic:
|
|
253
|
+
topic: "watch",
|
|
341
254
|
data
|
|
342
255
|
});
|
|
343
256
|
} catch (err) {
|
|
344
257
|
this.logger.error("Error emitting event: " + (err?.stack ?? err?.message ?? err));
|
|
345
258
|
}
|
|
346
|
-
},
|
|
347
|
-
on: (_event, _callback) => {
|
|
348
|
-
},
|
|
349
|
-
off: (_event, _callback) => {
|
|
350
|
-
},
|
|
351
|
-
once: (_event, _callback) => {
|
|
352
259
|
}
|
|
353
260
|
};
|
|
354
261
|
const engine = new InngestExecutionEngine(this.#mastra, step, attempt);
|
|
@@ -386,14 +293,8 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
386
293
|
return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
|
|
387
294
|
}
|
|
388
295
|
};
|
|
389
|
-
function isAgent(params) {
|
|
390
|
-
return params?.component === "AGENT";
|
|
391
|
-
}
|
|
392
|
-
function isTool(params) {
|
|
393
|
-
return params instanceof tools.Tool;
|
|
394
|
-
}
|
|
395
296
|
function createStep(params) {
|
|
396
|
-
if (
|
|
297
|
+
if (params instanceof core.Agent) {
|
|
397
298
|
return {
|
|
398
299
|
id: params.name,
|
|
399
300
|
// @ts-ignore
|
|
@@ -458,7 +359,7 @@ function createStep(params) {
|
|
|
458
359
|
}
|
|
459
360
|
};
|
|
460
361
|
}
|
|
461
|
-
if (
|
|
362
|
+
if (params instanceof core.Tool) {
|
|
462
363
|
if (!params.inputSchema || !params.outputSchema) {
|
|
463
364
|
throw new Error("Tool must have input and output schemas defined");
|
|
464
365
|
}
|
|
@@ -524,18 +425,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
524
425
|
this.inngestStep = inngestStep;
|
|
525
426
|
this.inngestAttempts = inngestAttempts;
|
|
526
427
|
}
|
|
527
|
-
async execute(params) {
|
|
528
|
-
await params.emitter.emit("watch-v2", {
|
|
529
|
-
type: "start",
|
|
530
|
-
payload: { runId: params.runId }
|
|
531
|
-
});
|
|
532
|
-
const result = await super.execute(params);
|
|
533
|
-
await params.emitter.emit("watch-v2", {
|
|
534
|
-
type: "finish",
|
|
535
|
-
payload: { runId: params.runId }
|
|
536
|
-
});
|
|
537
|
-
return result;
|
|
538
|
-
}
|
|
539
428
|
async fmtReturnValue(executionSpan, emitter, stepResults, lastOutput, error) {
|
|
540
429
|
const base = {
|
|
541
430
|
status: lastOutput.status,
|
|
@@ -619,16 +508,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
619
508
|
async executeSleep({ id, duration }) {
|
|
620
509
|
await this.inngestStep.sleep(id, duration);
|
|
621
510
|
}
|
|
622
|
-
async executeWaitForEvent({ event, timeout }) {
|
|
623
|
-
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
624
|
-
event: `user-event-${event}`,
|
|
625
|
-
timeout: timeout ?? 5e3
|
|
626
|
-
});
|
|
627
|
-
if (eventData === null) {
|
|
628
|
-
throw "Timeout waiting for event";
|
|
629
|
-
}
|
|
630
|
-
return eventData?.data;
|
|
631
|
-
}
|
|
632
511
|
async executeStep({
|
|
633
512
|
step,
|
|
634
513
|
stepResults,
|
|
@@ -638,10 +517,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
638
517
|
emitter,
|
|
639
518
|
runtimeContext
|
|
640
519
|
}) {
|
|
641
|
-
|
|
520
|
+
await this.inngestStep.run(
|
|
642
521
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
643
522
|
async () => {
|
|
644
|
-
const startedAt2 = Date.now();
|
|
645
523
|
await emitter.emit("watch", {
|
|
646
524
|
type: "watch",
|
|
647
525
|
payload: {
|
|
@@ -663,13 +541,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
663
541
|
},
|
|
664
542
|
eventTimestamp: Date.now()
|
|
665
543
|
});
|
|
666
|
-
await emitter.emit("watch-v2", {
|
|
667
|
-
type: "step-start",
|
|
668
|
-
payload: {
|
|
669
|
-
id: step.id
|
|
670
|
-
}
|
|
671
|
-
});
|
|
672
|
-
return startedAt2;
|
|
673
544
|
}
|
|
674
545
|
);
|
|
675
546
|
if (step instanceof InngestWorkflow) {
|
|
@@ -730,13 +601,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
730
601
|
},
|
|
731
602
|
eventTimestamp: Date.now()
|
|
732
603
|
});
|
|
733
|
-
await emitter.emit("watch-v2", {
|
|
734
|
-
type: "step-result",
|
|
735
|
-
payload: {
|
|
736
|
-
id: step.id,
|
|
737
|
-
status: "failed"
|
|
738
|
-
}
|
|
739
|
-
});
|
|
740
604
|
return { executionContext, result: { status: "failed", error: result?.error } };
|
|
741
605
|
} else if (result.status === "suspended") {
|
|
742
606
|
const suspendedSteps = Object.entries(result.steps).filter(([_stepName, stepResult]) => {
|
|
@@ -763,12 +627,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
763
627
|
},
|
|
764
628
|
eventTimestamp: Date.now()
|
|
765
629
|
});
|
|
766
|
-
await emitter.emit("watch-v2", {
|
|
767
|
-
type: "step-suspended",
|
|
768
|
-
payload: {
|
|
769
|
-
id: step.id
|
|
770
|
-
}
|
|
771
|
-
});
|
|
772
630
|
return {
|
|
773
631
|
executionContext,
|
|
774
632
|
result: {
|
|
@@ -819,13 +677,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
819
677
|
},
|
|
820
678
|
eventTimestamp: Date.now()
|
|
821
679
|
});
|
|
822
|
-
await emitter.emit("watch-v2", {
|
|
823
|
-
type: "step-finish",
|
|
824
|
-
payload: {
|
|
825
|
-
id: step.id,
|
|
826
|
-
metadata: {}
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
680
|
return { executionContext, result: { status: "success", output: result?.result } };
|
|
830
681
|
}
|
|
831
682
|
);
|
|
@@ -835,7 +686,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
835
686
|
const stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
|
|
836
687
|
let execResults;
|
|
837
688
|
let suspended;
|
|
838
|
-
let bailed;
|
|
839
689
|
try {
|
|
840
690
|
const result = await step.execute({
|
|
841
691
|
runId: executionContext.runId,
|
|
@@ -855,9 +705,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
855
705
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
856
706
|
suspended = { payload: suspendPayload };
|
|
857
707
|
},
|
|
858
|
-
bail: (result2) => {
|
|
859
|
-
bailed = { payload: result2 };
|
|
860
|
-
},
|
|
861
708
|
resume: {
|
|
862
709
|
steps: resume?.steps?.slice(1) || [],
|
|
863
710
|
resumePayload: resume?.resumePayload,
|
|
@@ -869,39 +716,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
869
716
|
step: this.inngestStep
|
|
870
717
|
}
|
|
871
718
|
});
|
|
872
|
-
|
|
873
|
-
execResults = {
|
|
874
|
-
status: "success",
|
|
875
|
-
output: result,
|
|
876
|
-
startedAt,
|
|
877
|
-
endedAt,
|
|
878
|
-
payload: prevOutput,
|
|
879
|
-
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
880
|
-
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
881
|
-
};
|
|
719
|
+
execResults = { status: "success", output: result };
|
|
882
720
|
} catch (e) {
|
|
883
|
-
execResults = {
|
|
884
|
-
status: "failed",
|
|
885
|
-
payload: prevOutput,
|
|
886
|
-
error: e instanceof Error ? e.message : String(e),
|
|
887
|
-
endedAt: Date.now(),
|
|
888
|
-
startedAt,
|
|
889
|
-
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
890
|
-
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
891
|
-
};
|
|
721
|
+
execResults = { status: "failed", error: e instanceof Error ? e.message : String(e) };
|
|
892
722
|
}
|
|
893
723
|
if (suspended) {
|
|
894
|
-
execResults = {
|
|
895
|
-
status: "suspended",
|
|
896
|
-
suspendedPayload: suspended.payload,
|
|
897
|
-
payload: prevOutput,
|
|
898
|
-
suspendedAt: Date.now(),
|
|
899
|
-
startedAt,
|
|
900
|
-
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
901
|
-
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
902
|
-
};
|
|
903
|
-
} else if (bailed) {
|
|
904
|
-
execResults = { status: "bailed", output: bailed.payload, payload: prevOutput, endedAt: Date.now(), startedAt };
|
|
724
|
+
execResults = { status: "suspended", payload: suspended.payload };
|
|
905
725
|
}
|
|
906
726
|
if (execResults.status === "failed") {
|
|
907
727
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
@@ -913,43 +733,18 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
913
733
|
payload: {
|
|
914
734
|
currentStep: {
|
|
915
735
|
id: step.id,
|
|
916
|
-
|
|
736
|
+
status: execResults.status,
|
|
737
|
+
output: execResults.output
|
|
917
738
|
},
|
|
918
739
|
workflowState: {
|
|
919
740
|
status: "running",
|
|
920
|
-
steps:
|
|
741
|
+
steps: stepResults,
|
|
921
742
|
result: null,
|
|
922
743
|
error: null
|
|
923
744
|
}
|
|
924
745
|
},
|
|
925
746
|
eventTimestamp: Date.now()
|
|
926
747
|
});
|
|
927
|
-
if (execResults.status === "suspended") {
|
|
928
|
-
await emitter.emit("watch-v2", {
|
|
929
|
-
type: "step-suspended",
|
|
930
|
-
payload: {
|
|
931
|
-
id: step.id,
|
|
932
|
-
status: execResults.status,
|
|
933
|
-
output: execResults.status === "success" ? execResults?.output : void 0
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
} else {
|
|
937
|
-
await emitter.emit("watch-v2", {
|
|
938
|
-
type: "step-result",
|
|
939
|
-
payload: {
|
|
940
|
-
id: step.id,
|
|
941
|
-
status: execResults.status,
|
|
942
|
-
output: execResults.status === "success" ? execResults?.output : void 0
|
|
943
|
-
}
|
|
944
|
-
});
|
|
945
|
-
await emitter.emit("watch-v2", {
|
|
946
|
-
type: "step-finish",
|
|
947
|
-
payload: {
|
|
948
|
-
id: step.id,
|
|
949
|
-
metadata: {}
|
|
950
|
-
}
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
748
|
return { result: execResults, executionContext, stepResults };
|
|
954
749
|
});
|
|
955
750
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
@@ -1026,8 +821,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1026
821
|
// TODO: this function shouldn't have suspend probably?
|
|
1027
822
|
suspend: async (_suspendPayload) => {
|
|
1028
823
|
},
|
|
1029
|
-
bail: () => {
|
|
1030
|
-
},
|
|
1031
824
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1032
825
|
engine: {
|
|
1033
826
|
step: this.inngestStep
|
|
@@ -1069,7 +862,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1069
862
|
if (hasFailed) {
|
|
1070
863
|
execResults = { status: "failed", error: hasFailed.result.error };
|
|
1071
864
|
} else if (hasSuspended) {
|
|
1072
|
-
execResults = { status: "suspended", payload: hasSuspended.result.
|
|
865
|
+
execResults = { status: "suspended", payload: hasSuspended.result.payload };
|
|
1073
866
|
} else {
|
|
1074
867
|
execResults = {
|
|
1075
868
|
status: "success",
|