@mastra/inngest 0.0.0-netlify-no-bundle-20251127120354 → 0.0.0-new-button-export-20251219130424
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 +517 -12
- package/dist/execution-engine.d.ts +109 -0
- package/dist/execution-engine.d.ts.map +1 -0
- package/dist/index.cjs +684 -963
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +18 -319
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +682 -963
- package/dist/index.js.map +1 -1
- package/dist/pubsub.d.ts +56 -0
- package/dist/pubsub.d.ts.map +1 -0
- package/dist/run.d.ts +167 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/serve.d.ts +13 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/workflow.d.ts +51 -0
- package/dist/workflow.d.ts.map +1 -0
- package/package.json +7 -8
package/dist/index.cjs
CHANGED
|
@@ -1,43 +1,475 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var crypto = require('crypto');
|
|
4
|
-
var web = require('stream/web');
|
|
5
|
-
var realtime = require('@inngest/realtime');
|
|
6
|
-
var di = require('@mastra/core/di');
|
|
7
|
-
var observability = require('@mastra/core/observability');
|
|
8
|
-
var stream = require('@mastra/core/stream');
|
|
9
3
|
var tools = require('@mastra/core/tools');
|
|
10
4
|
var workflows = require('@mastra/core/workflows');
|
|
11
5
|
var _constants = require('@mastra/core/workflows/_constants');
|
|
6
|
+
var zod = require('zod');
|
|
7
|
+
var crypto$1 = require('crypto');
|
|
8
|
+
var di = require('@mastra/core/di');
|
|
12
9
|
var inngest = require('inngest');
|
|
10
|
+
var error = require('@mastra/core/error');
|
|
11
|
+
var realtime = require('@inngest/realtime');
|
|
12
|
+
var events = require('@mastra/core/events');
|
|
13
|
+
var web = require('stream/web');
|
|
14
|
+
var stream = require('@mastra/core/stream');
|
|
13
15
|
var hono = require('inngest/hono');
|
|
14
|
-
var zod = require('zod');
|
|
15
16
|
|
|
16
17
|
// src/index.ts
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
19
|
+
inngestStep;
|
|
20
|
+
inngestAttempts;
|
|
21
|
+
constructor(mastra, inngestStep, inngestAttempts = 0, options) {
|
|
22
|
+
super({ mastra, options });
|
|
23
|
+
this.inngestStep = inngestStep;
|
|
24
|
+
this.inngestAttempts = inngestAttempts;
|
|
25
|
+
}
|
|
26
|
+
// =============================================================================
|
|
27
|
+
// Hook Overrides
|
|
28
|
+
// =============================================================================
|
|
29
|
+
/**
|
|
30
|
+
* Format errors while preserving Error instances and their custom properties.
|
|
31
|
+
* Uses getErrorFromUnknown to ensure all error properties are preserved.
|
|
32
|
+
*/
|
|
33
|
+
formatResultError(error$1, lastOutput) {
|
|
34
|
+
const outputError = lastOutput?.error;
|
|
35
|
+
const errorSource = error$1 || outputError;
|
|
36
|
+
const errorInstance = error.getErrorFromUnknown(errorSource, {
|
|
37
|
+
serializeStack: true,
|
|
38
|
+
// Include stack in JSON for better debugging in Inngest
|
|
39
|
+
fallbackMessage: "Unknown workflow error"
|
|
40
|
+
});
|
|
41
|
+
return errorInstance.toJSON();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Detect InngestWorkflow instances for special nested workflow handling
|
|
45
|
+
*/
|
|
46
|
+
isNestedWorkflowStep(step) {
|
|
47
|
+
return step instanceof InngestWorkflow;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Inngest requires requestContext serialization for memoization.
|
|
51
|
+
* When steps are replayed, the original function doesn't re-execute,
|
|
52
|
+
* so requestContext modifications must be captured and restored.
|
|
53
|
+
*/
|
|
54
|
+
requiresDurableContextSerialization() {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Execute a step with retry logic for Inngest.
|
|
59
|
+
* Retries are handled via step-level retry (RetryAfterError thrown INSIDE step.run()).
|
|
60
|
+
* After retries exhausted, error propagates here and we return a failed result.
|
|
61
|
+
*/
|
|
62
|
+
async executeStepWithRetry(stepId, runStep, params) {
|
|
63
|
+
try {
|
|
64
|
+
const result = await this.wrapDurableOperation(stepId, runStep, { delay: params.delay });
|
|
65
|
+
return { ok: true, result };
|
|
66
|
+
} catch (e) {
|
|
67
|
+
const cause = e?.cause;
|
|
68
|
+
if (cause?.status === "failed") {
|
|
69
|
+
params.stepSpan?.error({
|
|
70
|
+
error: e,
|
|
71
|
+
attributes: { status: "failed" }
|
|
72
|
+
});
|
|
73
|
+
if (cause.error && !(cause.error instanceof Error)) {
|
|
74
|
+
cause.error = error.getErrorFromUnknown(cause.error, { serializeStack: false });
|
|
30
75
|
}
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
76
|
+
return { ok: false, error: cause };
|
|
77
|
+
}
|
|
78
|
+
const errorInstance = error.getErrorFromUnknown(e, {
|
|
79
|
+
serializeStack: false,
|
|
80
|
+
fallbackMessage: "Unknown step execution error"
|
|
81
|
+
});
|
|
82
|
+
params.stepSpan?.error({
|
|
83
|
+
error: errorInstance,
|
|
84
|
+
attributes: { status: "failed" }
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
ok: false,
|
|
88
|
+
error: {
|
|
89
|
+
status: "failed",
|
|
90
|
+
error: errorInstance,
|
|
91
|
+
endedAt: Date.now()
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Use Inngest's sleep primitive for durability
|
|
98
|
+
*/
|
|
99
|
+
async executeSleepDuration(duration, sleepId, workflowId) {
|
|
100
|
+
await this.inngestStep.sleep(`workflow.${workflowId}.sleep.${sleepId}`, duration < 0 ? 0 : duration);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Use Inngest's sleepUntil primitive for durability
|
|
104
|
+
*/
|
|
105
|
+
async executeSleepUntilDate(date, sleepUntilId, workflowId) {
|
|
106
|
+
await this.inngestStep.sleepUntil(`workflow.${workflowId}.sleepUntil.${sleepUntilId}`, date);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Wrap durable operations in Inngest step.run() for durability.
|
|
110
|
+
* If retryConfig is provided, throws RetryAfterError INSIDE step.run() to trigger
|
|
111
|
+
* Inngest's step-level retry mechanism (not function-level retry).
|
|
112
|
+
*/
|
|
113
|
+
async wrapDurableOperation(operationId, operationFn, retryConfig) {
|
|
114
|
+
return this.inngestStep.run(operationId, async () => {
|
|
115
|
+
try {
|
|
116
|
+
return await operationFn();
|
|
117
|
+
} catch (e) {
|
|
118
|
+
if (retryConfig) {
|
|
119
|
+
const errorInstance = error.getErrorFromUnknown(e, {
|
|
120
|
+
serializeStack: false,
|
|
121
|
+
fallbackMessage: "Unknown step execution error"
|
|
122
|
+
});
|
|
123
|
+
throw new inngest.RetryAfterError(errorInstance.message, retryConfig.delay, {
|
|
124
|
+
cause: {
|
|
125
|
+
status: "failed",
|
|
126
|
+
error: errorInstance,
|
|
127
|
+
endedAt: Date.now()
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
throw e;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Provide Inngest step primitive in engine context
|
|
137
|
+
*/
|
|
138
|
+
getEngineContext() {
|
|
139
|
+
return { step: this.inngestStep };
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* For Inngest, lifecycle callbacks are invoked in the workflow's finalize step
|
|
143
|
+
* (wrapped in step.run for durability), not in execute(). Override to skip.
|
|
144
|
+
*/
|
|
145
|
+
async invokeLifecycleCallbacks(_result) {
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Actually invoke the lifecycle callbacks. Called from workflow.ts finalize step.
|
|
149
|
+
*/
|
|
150
|
+
async invokeLifecycleCallbacksInternal(result) {
|
|
151
|
+
return super.invokeLifecycleCallbacks(result);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Execute nested InngestWorkflow using inngestStep.invoke() for durability.
|
|
155
|
+
* This MUST be called directly (not inside step.run()) due to Inngest constraints.
|
|
156
|
+
*/
|
|
157
|
+
async executeWorkflowStep(params) {
|
|
158
|
+
if (!(params.step instanceof InngestWorkflow)) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const { step, stepResults, executionContext, resume, timeTravel, prevOutput, inputData, pubsub, startedAt } = params;
|
|
162
|
+
const isResume = !!resume?.steps?.length;
|
|
163
|
+
let result;
|
|
164
|
+
let runId;
|
|
165
|
+
const isTimeTravel = !!(timeTravel && timeTravel.steps?.length > 1 && timeTravel.steps[0] === step.id);
|
|
166
|
+
try {
|
|
167
|
+
if (isResume) {
|
|
168
|
+
runId = stepResults[resume?.steps?.[0] ?? ""]?.suspendPayload?.__workflow_meta?.runId ?? crypto$1.randomUUID();
|
|
169
|
+
const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
170
|
+
workflowName: step.id,
|
|
171
|
+
runId
|
|
172
|
+
});
|
|
173
|
+
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
174
|
+
function: step.getFunction(),
|
|
175
|
+
data: {
|
|
176
|
+
inputData,
|
|
177
|
+
initialState: executionContext.state ?? snapshot?.value ?? {},
|
|
178
|
+
runId,
|
|
179
|
+
resume: {
|
|
180
|
+
runId,
|
|
181
|
+
steps: resume.steps.slice(1),
|
|
182
|
+
stepResults: snapshot?.context,
|
|
183
|
+
resumePayload: resume.resumePayload,
|
|
184
|
+
resumePath: resume.steps?.[1] ? snapshot?.suspendedPaths?.[resume.steps?.[1]] : void 0
|
|
185
|
+
},
|
|
186
|
+
outputOptions: { includeState: true }
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
result = invokeResp.result;
|
|
190
|
+
runId = invokeResp.runId;
|
|
191
|
+
executionContext.state = invokeResp.result.state;
|
|
192
|
+
} else if (isTimeTravel) {
|
|
193
|
+
const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
194
|
+
workflowName: step.id,
|
|
195
|
+
runId: executionContext.runId
|
|
196
|
+
}) ?? { context: {} };
|
|
197
|
+
const timeTravelParams = workflows.createTimeTravelExecutionParams({
|
|
198
|
+
steps: timeTravel.steps.slice(1),
|
|
199
|
+
inputData: timeTravel.inputData,
|
|
200
|
+
resumeData: timeTravel.resumeData,
|
|
201
|
+
context: timeTravel.nestedStepResults?.[step.id] ?? {},
|
|
202
|
+
nestedStepsContext: timeTravel.nestedStepResults ?? {},
|
|
203
|
+
snapshot,
|
|
204
|
+
graph: step.buildExecutionGraph()
|
|
205
|
+
});
|
|
206
|
+
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
207
|
+
function: step.getFunction(),
|
|
208
|
+
data: {
|
|
209
|
+
timeTravel: timeTravelParams,
|
|
210
|
+
initialState: executionContext.state ?? {},
|
|
211
|
+
runId: executionContext.runId,
|
|
212
|
+
outputOptions: { includeState: true }
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
result = invokeResp.result;
|
|
216
|
+
runId = invokeResp.runId;
|
|
217
|
+
executionContext.state = invokeResp.result.state;
|
|
218
|
+
} else {
|
|
219
|
+
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
220
|
+
function: step.getFunction(),
|
|
221
|
+
data: {
|
|
222
|
+
inputData,
|
|
223
|
+
initialState: executionContext.state ?? {},
|
|
224
|
+
outputOptions: { includeState: true }
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
result = invokeResp.result;
|
|
228
|
+
runId = invokeResp.runId;
|
|
229
|
+
executionContext.state = invokeResp.result.state;
|
|
230
|
+
}
|
|
231
|
+
} catch (e) {
|
|
232
|
+
const errorCause = e?.cause;
|
|
233
|
+
if (errorCause && typeof errorCause === "object") {
|
|
234
|
+
result = errorCause;
|
|
235
|
+
runId = errorCause.runId || crypto$1.randomUUID();
|
|
236
|
+
} else {
|
|
237
|
+
runId = crypto$1.randomUUID();
|
|
238
|
+
result = {
|
|
239
|
+
status: "failed",
|
|
240
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
241
|
+
steps: {},
|
|
242
|
+
input: inputData
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const res = await this.inngestStep.run(
|
|
247
|
+
`workflow.${executionContext.workflowId}.step.${step.id}.nestedwf-results`,
|
|
248
|
+
async () => {
|
|
249
|
+
if (result.status === "failed") {
|
|
250
|
+
await pubsub.publish(`workflow.events.v2.${executionContext.runId}`, {
|
|
251
|
+
type: "watch",
|
|
252
|
+
runId: executionContext.runId,
|
|
253
|
+
data: {
|
|
254
|
+
type: "workflow-step-result",
|
|
255
|
+
payload: {
|
|
256
|
+
id: step.id,
|
|
257
|
+
status: "failed",
|
|
258
|
+
error: result?.error,
|
|
259
|
+
payload: prevOutput
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
return { executionContext, result: { status: "failed", error: result?.error } };
|
|
264
|
+
} else if (result.status === "suspended") {
|
|
265
|
+
const suspendedSteps = Object.entries(result.steps).filter(([_stepName, stepResult]) => {
|
|
266
|
+
const stepRes = stepResult;
|
|
267
|
+
return stepRes?.status === "suspended";
|
|
268
|
+
});
|
|
269
|
+
for (const [stepName, stepResult] of suspendedSteps) {
|
|
270
|
+
const suspendPath = [stepName, ...stepResult?.suspendPayload?.__workflow_meta?.path ?? []];
|
|
271
|
+
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
272
|
+
await pubsub.publish(`workflow.events.v2.${executionContext.runId}`, {
|
|
273
|
+
type: "watch",
|
|
274
|
+
runId: executionContext.runId,
|
|
275
|
+
data: {
|
|
276
|
+
type: "workflow-step-suspended",
|
|
277
|
+
payload: {
|
|
278
|
+
id: step.id,
|
|
279
|
+
status: "suspended"
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
return {
|
|
284
|
+
executionContext,
|
|
285
|
+
result: {
|
|
286
|
+
status: "suspended",
|
|
287
|
+
payload: stepResult.payload,
|
|
288
|
+
suspendPayload: {
|
|
289
|
+
...stepResult?.suspendPayload,
|
|
290
|
+
__workflow_meta: { runId, path: suspendPath }
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
executionContext,
|
|
297
|
+
result: {
|
|
298
|
+
status: "suspended",
|
|
299
|
+
payload: {}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
} else if (result.status === "tripwire") {
|
|
303
|
+
await pubsub.publish(`workflow.events.v2.${executionContext.runId}`, {
|
|
304
|
+
type: "watch",
|
|
305
|
+
runId: executionContext.runId,
|
|
306
|
+
data: {
|
|
307
|
+
type: "workflow-step-result",
|
|
308
|
+
payload: {
|
|
309
|
+
id: step.id,
|
|
310
|
+
status: "tripwire",
|
|
311
|
+
error: result?.tripwire?.reason,
|
|
312
|
+
payload: prevOutput
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
return {
|
|
317
|
+
executionContext,
|
|
318
|
+
result: {
|
|
319
|
+
status: "tripwire",
|
|
320
|
+
tripwire: result?.tripwire
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
await pubsub.publish(`workflow.events.v2.${executionContext.runId}`, {
|
|
325
|
+
type: "watch",
|
|
326
|
+
runId: executionContext.runId,
|
|
327
|
+
data: {
|
|
328
|
+
type: "workflow-step-result",
|
|
329
|
+
payload: {
|
|
330
|
+
id: step.id,
|
|
331
|
+
status: "success",
|
|
332
|
+
output: result?.result
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
await pubsub.publish(`workflow.events.v2.${executionContext.runId}`, {
|
|
337
|
+
type: "watch",
|
|
338
|
+
runId: executionContext.runId,
|
|
339
|
+
data: {
|
|
340
|
+
type: "workflow-step-finish",
|
|
341
|
+
payload: {
|
|
342
|
+
id: step.id,
|
|
343
|
+
metadata: {}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
return { executionContext, result: { status: "success", output: result?.result } };
|
|
348
|
+
}
|
|
349
|
+
);
|
|
350
|
+
Object.assign(executionContext, res.executionContext);
|
|
351
|
+
return {
|
|
352
|
+
...res.result,
|
|
353
|
+
startedAt,
|
|
354
|
+
endedAt: Date.now(),
|
|
355
|
+
payload: inputData,
|
|
356
|
+
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
357
|
+
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var InngestPubSub = class extends events.PubSub {
|
|
362
|
+
inngest;
|
|
363
|
+
workflowId;
|
|
364
|
+
publishFn;
|
|
365
|
+
subscriptions = /* @__PURE__ */ new Map();
|
|
366
|
+
constructor(inngest, workflowId, publishFn) {
|
|
367
|
+
super();
|
|
368
|
+
this.inngest = inngest;
|
|
369
|
+
this.workflowId = workflowId;
|
|
370
|
+
this.publishFn = publishFn;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Publish an event to Inngest's realtime system.
|
|
374
|
+
*
|
|
375
|
+
* Topic format: "workflow.events.v2.{runId}"
|
|
376
|
+
* Maps to Inngest channel: "workflow:{workflowId}:{runId}"
|
|
377
|
+
*/
|
|
378
|
+
async publish(topic, event) {
|
|
379
|
+
if (!this.publishFn) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const match = topic.match(/^workflow\.events\.v2\.(.+)$/);
|
|
383
|
+
if (!match) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const runId = match[1];
|
|
387
|
+
try {
|
|
388
|
+
await this.publishFn({
|
|
389
|
+
channel: `workflow:${this.workflowId}:${runId}`,
|
|
390
|
+
topic: "watch",
|
|
391
|
+
data: event.data
|
|
392
|
+
});
|
|
393
|
+
} catch (err) {
|
|
394
|
+
console.error("InngestPubSub publish error:", err?.message ?? err);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Subscribe to events from Inngest's realtime system.
|
|
399
|
+
*
|
|
400
|
+
* Topic format: "workflow.events.v2.{runId}"
|
|
401
|
+
* Maps to Inngest channel: "workflow:{workflowId}:{runId}"
|
|
402
|
+
*/
|
|
403
|
+
async subscribe(topic, cb) {
|
|
404
|
+
const match = topic.match(/^workflow\.events\.v2\.(.+)$/);
|
|
405
|
+
if (!match || !match[1]) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const runId = match[1];
|
|
409
|
+
if (this.subscriptions.has(topic)) {
|
|
410
|
+
this.subscriptions.get(topic).callbacks.add(cb);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const callbacks = /* @__PURE__ */ new Set([cb]);
|
|
414
|
+
const channel = `workflow:${this.workflowId}:${runId}`;
|
|
415
|
+
const streamPromise = realtime.subscribe(
|
|
416
|
+
{
|
|
417
|
+
channel,
|
|
418
|
+
topics: ["watch"],
|
|
419
|
+
app: this.inngest
|
|
420
|
+
},
|
|
421
|
+
(message) => {
|
|
422
|
+
const event = {
|
|
423
|
+
id: crypto.randomUUID(),
|
|
424
|
+
type: "watch",
|
|
425
|
+
runId,
|
|
426
|
+
data: message.data,
|
|
427
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
428
|
+
};
|
|
429
|
+
for (const callback of callbacks) {
|
|
430
|
+
callback(event);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
);
|
|
434
|
+
this.subscriptions.set(topic, {
|
|
435
|
+
unsubscribe: () => {
|
|
436
|
+
streamPromise.then((stream) => stream.cancel()).catch((err) => {
|
|
437
|
+
console.error("InngestPubSub unsubscribe error:", err);
|
|
438
|
+
});
|
|
439
|
+
},
|
|
440
|
+
callbacks
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Unsubscribe a callback from a topic.
|
|
445
|
+
* If no callbacks remain, the underlying Inngest subscription is cancelled.
|
|
446
|
+
*/
|
|
447
|
+
async unsubscribe(topic, cb) {
|
|
448
|
+
const sub = this.subscriptions.get(topic);
|
|
449
|
+
if (!sub) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
sub.callbacks.delete(cb);
|
|
453
|
+
if (sub.callbacks.size === 0) {
|
|
454
|
+
sub.unsubscribe();
|
|
455
|
+
this.subscriptions.delete(topic);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Flush any pending operations. No-op for Inngest.
|
|
460
|
+
*/
|
|
461
|
+
async flush() {
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Clean up all subscriptions during graceful shutdown.
|
|
465
|
+
*/
|
|
466
|
+
async close() {
|
|
467
|
+
for (const [, sub] of this.subscriptions) {
|
|
468
|
+
sub.unsubscribe();
|
|
469
|
+
}
|
|
470
|
+
this.subscriptions.clear();
|
|
471
|
+
}
|
|
472
|
+
};
|
|
41
473
|
var InngestRun = class extends workflows.Run {
|
|
42
474
|
inngest;
|
|
43
475
|
serializedStepGraph;
|
|
@@ -49,27 +481,77 @@ var InngestRun = class extends workflows.Run {
|
|
|
49
481
|
this.#mastra = params.mastra;
|
|
50
482
|
}
|
|
51
483
|
async getRuns(eventId) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
484
|
+
const maxRetries = 3;
|
|
485
|
+
let lastError = null;
|
|
486
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
487
|
+
try {
|
|
488
|
+
const response = await fetch(
|
|
489
|
+
`${this.inngest.apiBaseUrl ?? "https://api.inngest.com"}/v1/events/${eventId}/runs`,
|
|
490
|
+
{
|
|
491
|
+
headers: {
|
|
492
|
+
Authorization: `Bearer ${process.env.INNGEST_SIGNING_KEY}`
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
);
|
|
496
|
+
if (response.status === 429) {
|
|
497
|
+
const retryAfter = parseInt(response.headers.get("retry-after") || "2", 10);
|
|
498
|
+
await new Promise((resolve) => setTimeout(resolve, retryAfter * 1e3));
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
if (!response.ok) {
|
|
502
|
+
throw new Error(`Inngest API error: ${response.status} ${response.statusText}`);
|
|
503
|
+
}
|
|
504
|
+
const text = await response.text();
|
|
505
|
+
if (!text) {
|
|
506
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * (attempt + 1)));
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const json = JSON.parse(text);
|
|
510
|
+
return json.data;
|
|
511
|
+
} catch (error) {
|
|
512
|
+
lastError = error;
|
|
513
|
+
if (attempt < maxRetries - 1) {
|
|
514
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 * Math.pow(2, attempt)));
|
|
515
|
+
}
|
|
55
516
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return json.data;
|
|
517
|
+
}
|
|
518
|
+
throw new inngest.NonRetriableError(`Failed to get runs after ${maxRetries} attempts: ${lastError?.message}`);
|
|
59
519
|
}
|
|
60
|
-
async getRunOutput(eventId) {
|
|
61
|
-
|
|
520
|
+
async getRunOutput(eventId, maxWaitMs = 3e5) {
|
|
521
|
+
const startTime = Date.now();
|
|
62
522
|
const storage = this.#mastra?.getStorage();
|
|
63
|
-
while (
|
|
64
|
-
|
|
65
|
-
|
|
523
|
+
while (Date.now() - startTime < maxWaitMs) {
|
|
524
|
+
let runs;
|
|
525
|
+
try {
|
|
526
|
+
runs = await this.getRuns(eventId);
|
|
527
|
+
} catch (error) {
|
|
528
|
+
if (error instanceof inngest.NonRetriableError) {
|
|
529
|
+
throw error;
|
|
530
|
+
}
|
|
531
|
+
throw new inngest.NonRetriableError(
|
|
532
|
+
`Failed to poll workflow status: ${error instanceof Error ? error.message : String(error)}`
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
if (runs?.[0]?.status === "Completed" && runs?.[0]?.event_id === eventId) {
|
|
536
|
+
return runs[0];
|
|
537
|
+
}
|
|
66
538
|
if (runs?.[0]?.status === "Failed") {
|
|
67
539
|
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
68
540
|
workflowName: this.workflowId,
|
|
69
541
|
runId: this.runId
|
|
70
542
|
});
|
|
543
|
+
if (snapshot?.context) {
|
|
544
|
+
snapshot.context = workflows.hydrateSerializedStepErrors(snapshot.context);
|
|
545
|
+
}
|
|
71
546
|
return {
|
|
72
|
-
output: {
|
|
547
|
+
output: {
|
|
548
|
+
result: {
|
|
549
|
+
steps: snapshot?.context,
|
|
550
|
+
status: "failed",
|
|
551
|
+
// Get the original error from NonRetriableError's cause (which contains the workflow result)
|
|
552
|
+
error: error.getErrorFromUnknown(runs?.[0]?.output?.cause?.error, { serializeStack: false })
|
|
553
|
+
}
|
|
554
|
+
}
|
|
73
555
|
};
|
|
74
556
|
}
|
|
75
557
|
if (runs?.[0]?.status === "Cancelled") {
|
|
@@ -79,8 +561,9 @@ var InngestRun = class extends workflows.Run {
|
|
|
79
561
|
});
|
|
80
562
|
return { output: { result: { steps: snapshot?.context, status: "canceled" } } };
|
|
81
563
|
}
|
|
564
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3 + Math.random() * 1e3));
|
|
82
565
|
}
|
|
83
|
-
|
|
566
|
+
throw new inngest.NonRetriableError(`Workflow did not complete within ${maxWaitMs}ms`);
|
|
84
567
|
}
|
|
85
568
|
async cancel() {
|
|
86
569
|
const storage = this.#mastra?.getStorage();
|
|
@@ -110,12 +593,58 @@ var InngestRun = class extends workflows.Run {
|
|
|
110
593
|
async start(params) {
|
|
111
594
|
return this._start(params);
|
|
112
595
|
}
|
|
596
|
+
/**
|
|
597
|
+
* Starts the workflow execution without waiting for completion (fire-and-forget).
|
|
598
|
+
* Returns immediately with the runId after sending the event to Inngest.
|
|
599
|
+
* The workflow executes independently in Inngest.
|
|
600
|
+
* Use this when you don't need to wait for the result or want to avoid polling failures.
|
|
601
|
+
*/
|
|
602
|
+
async startAsync(params) {
|
|
603
|
+
await this.#mastra.getStorage()?.persistWorkflowSnapshot({
|
|
604
|
+
workflowName: this.workflowId,
|
|
605
|
+
runId: this.runId,
|
|
606
|
+
resourceId: this.resourceId,
|
|
607
|
+
snapshot: {
|
|
608
|
+
runId: this.runId,
|
|
609
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
610
|
+
status: "running",
|
|
611
|
+
value: {},
|
|
612
|
+
context: {},
|
|
613
|
+
activePaths: [],
|
|
614
|
+
suspendedPaths: {},
|
|
615
|
+
activeStepsPath: {},
|
|
616
|
+
resumeLabels: {},
|
|
617
|
+
waitingPaths: {},
|
|
618
|
+
timestamp: Date.now()
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
const inputDataToUse = await this._validateInput(params.inputData);
|
|
622
|
+
const initialStateToUse = await this._validateInitialState(params.initialState ?? {});
|
|
623
|
+
const eventOutput = await this.inngest.send({
|
|
624
|
+
name: `workflow.${this.workflowId}`,
|
|
625
|
+
data: {
|
|
626
|
+
inputData: inputDataToUse,
|
|
627
|
+
initialState: initialStateToUse,
|
|
628
|
+
runId: this.runId,
|
|
629
|
+
resourceId: this.resourceId,
|
|
630
|
+
outputOptions: params.outputOptions,
|
|
631
|
+
tracingOptions: params.tracingOptions,
|
|
632
|
+
requestContext: params.requestContext ? Object.fromEntries(params.requestContext.entries()) : {}
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
const eventId = eventOutput.ids[0];
|
|
636
|
+
if (!eventId) {
|
|
637
|
+
throw new Error("Event ID is not set");
|
|
638
|
+
}
|
|
639
|
+
return { runId: this.runId };
|
|
640
|
+
}
|
|
113
641
|
async _start({
|
|
114
642
|
inputData,
|
|
115
643
|
initialState,
|
|
116
644
|
outputOptions,
|
|
117
645
|
tracingOptions,
|
|
118
|
-
format
|
|
646
|
+
format,
|
|
647
|
+
requestContext
|
|
119
648
|
}) {
|
|
120
649
|
await this.#mastra.getStorage()?.persistWorkflowSnapshot({
|
|
121
650
|
workflowName: this.workflowId,
|
|
@@ -146,7 +675,8 @@ var InngestRun = class extends workflows.Run {
|
|
|
146
675
|
resourceId: this.resourceId,
|
|
147
676
|
outputOptions,
|
|
148
677
|
tracingOptions,
|
|
149
|
-
format
|
|
678
|
+
format,
|
|
679
|
+
requestContext: requestContext ? Object.fromEntries(requestContext.entries()) : {}
|
|
150
680
|
}
|
|
151
681
|
});
|
|
152
682
|
const eventId = eventOutput.ids[0];
|
|
@@ -155,9 +685,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
155
685
|
}
|
|
156
686
|
const runOutput = await this.getRunOutput(eventId);
|
|
157
687
|
const result = runOutput?.output?.result;
|
|
158
|
-
|
|
159
|
-
result.error = new Error(result.error);
|
|
160
|
-
}
|
|
688
|
+
this.hydrateFailedResult(result);
|
|
161
689
|
if (result.status !== "suspended") {
|
|
162
690
|
this.cleanup?.();
|
|
163
691
|
}
|
|
@@ -190,6 +718,9 @@ var InngestRun = class extends workflows.Run {
|
|
|
190
718
|
});
|
|
191
719
|
const suspendedStep = this.workflowSteps[steps?.[0] ?? ""];
|
|
192
720
|
const resumeDataToUse = await this._validateResumeData(params.resumeData, suspendedStep);
|
|
721
|
+
const persistedRequestContext = snapshot?.requestContext ?? {};
|
|
722
|
+
const newRequestContext = params.requestContext ? Object.fromEntries(params.requestContext.entries()) : {};
|
|
723
|
+
const mergedRequestContext = { ...persistedRequestContext, ...newRequestContext };
|
|
193
724
|
const eventOutput = await this.inngest.send({
|
|
194
725
|
name: `workflow.${this.workflowId}`,
|
|
195
726
|
data: {
|
|
@@ -203,7 +734,8 @@ var InngestRun = class extends workflows.Run {
|
|
|
203
734
|
stepResults: snapshot?.context,
|
|
204
735
|
resumePayload: resumeDataToUse,
|
|
205
736
|
resumePath: steps?.[0] ? snapshot?.suspendedPaths?.[steps?.[0]] : void 0
|
|
206
|
-
}
|
|
737
|
+
},
|
|
738
|
+
requestContext: mergedRequestContext
|
|
207
739
|
}
|
|
208
740
|
});
|
|
209
741
|
const eventId = eventOutput.ids[0];
|
|
@@ -212,9 +744,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
212
744
|
}
|
|
213
745
|
const runOutput = await this.getRunOutput(eventId);
|
|
214
746
|
const result = runOutput?.output?.result;
|
|
215
|
-
|
|
216
|
-
result.error = new Error(result.error);
|
|
217
|
-
}
|
|
747
|
+
this.hydrateFailedResult(result);
|
|
218
748
|
return result;
|
|
219
749
|
}
|
|
220
750
|
async timeTravel(params) {
|
|
@@ -294,7 +824,8 @@ var InngestRun = class extends workflows.Run {
|
|
|
294
824
|
stepResults: timeTravelData.stepResults,
|
|
295
825
|
timeTravel: timeTravelData,
|
|
296
826
|
tracingOptions: params.tracingOptions,
|
|
297
|
-
outputOptions: params.outputOptions
|
|
827
|
+
outputOptions: params.outputOptions,
|
|
828
|
+
requestContext: params.requestContext ? Object.fromEntries(params.requestContext.entries()) : {}
|
|
298
829
|
}
|
|
299
830
|
});
|
|
300
831
|
const eventId = eventOutput.ids[0];
|
|
@@ -303,9 +834,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
303
834
|
}
|
|
304
835
|
const runOutput = await this.getRunOutput(eventId);
|
|
305
836
|
const result = runOutput?.output?.result;
|
|
306
|
-
|
|
307
|
-
result.error = new Error(result.error);
|
|
308
|
-
}
|
|
837
|
+
this.hydrateFailedResult(result);
|
|
309
838
|
return result;
|
|
310
839
|
}
|
|
311
840
|
watch(cb) {
|
|
@@ -487,7 +1016,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
487
1016
|
self.closeStreamAction = async () => {
|
|
488
1017
|
unwatch();
|
|
489
1018
|
try {
|
|
490
|
-
|
|
1019
|
+
controller.close();
|
|
491
1020
|
} catch (err) {
|
|
492
1021
|
console.error("Error closing stream:", err);
|
|
493
1022
|
}
|
|
@@ -526,7 +1055,21 @@ var InngestRun = class extends workflows.Run {
|
|
|
526
1055
|
});
|
|
527
1056
|
return this.streamOutput;
|
|
528
1057
|
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Hydrates errors in a failed workflow result back to proper Error instances.
|
|
1060
|
+
* This ensures error.cause chains and custom properties are preserved.
|
|
1061
|
+
*/
|
|
1062
|
+
hydrateFailedResult(result) {
|
|
1063
|
+
if (result.status === "failed") {
|
|
1064
|
+
result.error = error.getErrorFromUnknown(result.error, { serializeStack: false });
|
|
1065
|
+
if (result.steps) {
|
|
1066
|
+
workflows.hydrateSerializedStepErrors(result.steps);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
529
1070
|
};
|
|
1071
|
+
|
|
1072
|
+
// src/workflow.ts
|
|
530
1073
|
var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
531
1074
|
#mastra;
|
|
532
1075
|
inngest;
|
|
@@ -561,6 +1104,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
561
1104
|
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
562
1105
|
}
|
|
563
1106
|
__registerMastra(mastra) {
|
|
1107
|
+
super.__registerMastra(mastra);
|
|
564
1108
|
this.#mastra = mastra;
|
|
565
1109
|
this.executionEngine.__registerMastra(mastra);
|
|
566
1110
|
const updateNested = (step) => {
|
|
@@ -579,7 +1123,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
579
1123
|
}
|
|
580
1124
|
}
|
|
581
1125
|
async createRun(options) {
|
|
582
|
-
const runIdToUse = options?.runId || crypto.randomUUID();
|
|
1126
|
+
const runIdToUse = options?.runId || crypto$1.randomUUID();
|
|
583
1127
|
const run = this.runs.get(runIdToUse) ?? new InngestRun(
|
|
584
1128
|
{
|
|
585
1129
|
workflowId: this.id,
|
|
@@ -602,7 +1146,9 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
602
1146
|
workflowStatus: run.workflowRunStatus,
|
|
603
1147
|
stepResults: {}
|
|
604
1148
|
});
|
|
605
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse,
|
|
1149
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, {
|
|
1150
|
+
withNestedWorkflows: false
|
|
1151
|
+
});
|
|
606
1152
|
if (!workflowSnapshotInStorage && shouldPersistSnapshot) {
|
|
607
1153
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
608
1154
|
workflowName: this.id,
|
|
@@ -644,31 +1190,10 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
644
1190
|
let { inputData, initialState, runId, resourceId, resume, outputOptions, format, timeTravel } = event.data;
|
|
645
1191
|
if (!runId) {
|
|
646
1192
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
647
|
-
return crypto.randomUUID();
|
|
1193
|
+
return crypto$1.randomUUID();
|
|
648
1194
|
});
|
|
649
1195
|
}
|
|
650
|
-
const
|
|
651
|
-
emit: async (event2, data) => {
|
|
652
|
-
if (!publish) {
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
try {
|
|
656
|
-
await publish({
|
|
657
|
-
channel: `workflow:${this.id}:${runId}`,
|
|
658
|
-
topic: event2,
|
|
659
|
-
data
|
|
660
|
-
});
|
|
661
|
-
} catch (err) {
|
|
662
|
-
this.logger.error("Error emitting event: " + (err?.stack ?? err?.message ?? err));
|
|
663
|
-
}
|
|
664
|
-
},
|
|
665
|
-
on: (_event, _callback) => {
|
|
666
|
-
},
|
|
667
|
-
off: (_event, _callback) => {
|
|
668
|
-
},
|
|
669
|
-
once: (_event, _callback) => {
|
|
670
|
-
}
|
|
671
|
-
};
|
|
1196
|
+
const pubsub = new InngestPubSub(this.inngest, this.id, publish);
|
|
672
1197
|
const engine = new InngestExecutionEngine(this.#mastra, step, attempt, this.options);
|
|
673
1198
|
const result = await engine.execute({
|
|
674
1199
|
workflowId: this.id,
|
|
@@ -678,24 +1203,29 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
678
1203
|
serializedStepGraph: this.serializedStepGraph,
|
|
679
1204
|
input: inputData,
|
|
680
1205
|
initialState,
|
|
681
|
-
|
|
1206
|
+
pubsub,
|
|
682
1207
|
retryConfig: this.retryConfig,
|
|
683
|
-
requestContext: new di.RequestContext(),
|
|
684
|
-
// TODO
|
|
1208
|
+
requestContext: new di.RequestContext(Object.entries(event.data.requestContext ?? {})),
|
|
685
1209
|
resume,
|
|
686
1210
|
timeTravel,
|
|
687
1211
|
format,
|
|
688
1212
|
abortController: new AbortController(),
|
|
689
1213
|
// currentSpan: undefined, // TODO: Pass actual parent Span from workflow execution context
|
|
690
1214
|
outputOptions,
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
1215
|
+
outputWriter: async (chunk) => {
|
|
1216
|
+
try {
|
|
1217
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
1218
|
+
type: "watch",
|
|
1219
|
+
runId,
|
|
1220
|
+
data: chunk
|
|
694
1221
|
});
|
|
1222
|
+
} catch (err) {
|
|
1223
|
+
this.logger.debug?.("Failed to publish watch event:", err);
|
|
695
1224
|
}
|
|
696
|
-
}
|
|
1225
|
+
}
|
|
697
1226
|
});
|
|
698
1227
|
await step.run(`workflow.${this.id}.finalize`, async () => {
|
|
1228
|
+
await engine.invokeLifecycleCallbacksInternal(result);
|
|
699
1229
|
if (result.status === "failed") {
|
|
700
1230
|
throw new inngest.NonRetriableError(`Workflow failed`, {
|
|
701
1231
|
cause: result
|
|
@@ -725,14 +1255,50 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
725
1255
|
return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
|
|
726
1256
|
}
|
|
727
1257
|
};
|
|
1258
|
+
function serve({
|
|
1259
|
+
mastra,
|
|
1260
|
+
inngest,
|
|
1261
|
+
functions: userFunctions = [],
|
|
1262
|
+
registerOptions
|
|
1263
|
+
}) {
|
|
1264
|
+
const wfs = mastra.listWorkflows();
|
|
1265
|
+
const workflowFunctions = Array.from(
|
|
1266
|
+
new Set(
|
|
1267
|
+
Object.values(wfs).flatMap((wf) => {
|
|
1268
|
+
if (wf instanceof InngestWorkflow) {
|
|
1269
|
+
wf.__registerMastra(mastra);
|
|
1270
|
+
return wf.getFunctions();
|
|
1271
|
+
}
|
|
1272
|
+
return [];
|
|
1273
|
+
})
|
|
1274
|
+
)
|
|
1275
|
+
);
|
|
1276
|
+
return hono.serve({
|
|
1277
|
+
...registerOptions,
|
|
1278
|
+
client: inngest,
|
|
1279
|
+
functions: [...workflowFunctions, ...userFunctions]
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
// src/types.ts
|
|
1284
|
+
var _compatibilityCheck = true;
|
|
1285
|
+
|
|
1286
|
+
// src/index.ts
|
|
728
1287
|
function isAgent(params) {
|
|
729
1288
|
return params?.component === "AGENT";
|
|
730
1289
|
}
|
|
731
1290
|
function isTool(params) {
|
|
732
1291
|
return params instanceof tools.Tool;
|
|
733
1292
|
}
|
|
1293
|
+
function isInngestWorkflow(params) {
|
|
1294
|
+
return params instanceof InngestWorkflow;
|
|
1295
|
+
}
|
|
734
1296
|
function createStep(params, agentOptions) {
|
|
1297
|
+
if (isInngestWorkflow(params)) {
|
|
1298
|
+
return params;
|
|
1299
|
+
}
|
|
735
1300
|
if (isAgent(params)) {
|
|
1301
|
+
const outputSchema = agentOptions?.structuredOutput?.schema ?? zod.z.object({ text: zod.z.string() });
|
|
736
1302
|
return {
|
|
737
1303
|
id: params.name,
|
|
738
1304
|
description: params.getDescription(),
|
|
@@ -741,12 +1307,11 @@ function createStep(params, agentOptions) {
|
|
|
741
1307
|
// resourceId: z.string().optional(),
|
|
742
1308
|
// threadId: z.string().optional(),
|
|
743
1309
|
}),
|
|
744
|
-
outputSchema
|
|
745
|
-
text: zod.z.string()
|
|
746
|
-
}),
|
|
1310
|
+
outputSchema,
|
|
747
1311
|
execute: async ({
|
|
748
1312
|
inputData,
|
|
749
|
-
|
|
1313
|
+
runId,
|
|
1314
|
+
[_constants.PUBSUB_SYMBOL]: pubsub,
|
|
750
1315
|
[_constants.STREAM_FORMAT_SYMBOL]: streamFormat,
|
|
751
1316
|
requestContext,
|
|
752
1317
|
tracingContext,
|
|
@@ -759,6 +1324,7 @@ function createStep(params, agentOptions) {
|
|
|
759
1324
|
streamPromise.resolve = resolve;
|
|
760
1325
|
streamPromise.reject = reject;
|
|
761
1326
|
});
|
|
1327
|
+
let structuredResult = null;
|
|
762
1328
|
const toolData = {
|
|
763
1329
|
name: params.name,
|
|
764
1330
|
args: inputData
|
|
@@ -772,6 +1338,10 @@ function createStep(params, agentOptions) {
|
|
|
772
1338
|
requestContext,
|
|
773
1339
|
tracingContext,
|
|
774
1340
|
onFinish: (result) => {
|
|
1341
|
+
const resultWithObject = result;
|
|
1342
|
+
if (agentOptions?.structuredOutput?.schema && resultWithObject.object) {
|
|
1343
|
+
structuredResult = resultWithObject.object;
|
|
1344
|
+
}
|
|
775
1345
|
streamPromise.resolve(result.text);
|
|
776
1346
|
void agentOptions?.onFinish?.(result);
|
|
777
1347
|
},
|
|
@@ -784,6 +1354,10 @@ function createStep(params, agentOptions) {
|
|
|
784
1354
|
requestContext,
|
|
785
1355
|
tracingContext,
|
|
786
1356
|
onFinish: (result) => {
|
|
1357
|
+
const resultWithObject = result;
|
|
1358
|
+
if (agentOptions?.structuredOutput?.schema && resultWithObject.object) {
|
|
1359
|
+
structuredResult = resultWithObject.object;
|
|
1360
|
+
}
|
|
787
1361
|
streamPromise.resolve(result.text);
|
|
788
1362
|
void agentOptions?.onFinish?.(result);
|
|
789
1363
|
},
|
|
@@ -792,22 +1366,24 @@ function createStep(params, agentOptions) {
|
|
|
792
1366
|
stream = modelOutput.fullStream;
|
|
793
1367
|
}
|
|
794
1368
|
if (streamFormat === "legacy") {
|
|
795
|
-
await
|
|
796
|
-
type: "
|
|
797
|
-
|
|
1369
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
1370
|
+
type: "watch",
|
|
1371
|
+
runId,
|
|
1372
|
+
data: { type: "tool-call-streaming-start", ...toolData ?? {} }
|
|
798
1373
|
});
|
|
799
1374
|
for await (const chunk of stream) {
|
|
800
1375
|
if (chunk.type === "text-delta") {
|
|
801
|
-
await
|
|
802
|
-
type: "
|
|
803
|
-
|
|
804
|
-
argsTextDelta: chunk.textDelta
|
|
1376
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
1377
|
+
type: "watch",
|
|
1378
|
+
runId,
|
|
1379
|
+
data: { type: "tool-call-delta", ...toolData ?? {}, argsTextDelta: chunk.textDelta }
|
|
805
1380
|
});
|
|
806
1381
|
}
|
|
807
1382
|
}
|
|
808
|
-
await
|
|
809
|
-
type: "
|
|
810
|
-
|
|
1383
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
1384
|
+
type: "watch",
|
|
1385
|
+
runId,
|
|
1386
|
+
data: { type: "tool-call-streaming-finish", ...toolData ?? {} }
|
|
811
1387
|
});
|
|
812
1388
|
} else {
|
|
813
1389
|
for await (const chunk of stream) {
|
|
@@ -817,6 +1393,9 @@ function createStep(params, agentOptions) {
|
|
|
817
1393
|
if (abortSignal.aborted) {
|
|
818
1394
|
return abort();
|
|
819
1395
|
}
|
|
1396
|
+
if (structuredResult !== null) {
|
|
1397
|
+
return structuredResult;
|
|
1398
|
+
}
|
|
820
1399
|
return {
|
|
821
1400
|
text: await streamPromise.promise
|
|
822
1401
|
};
|
|
@@ -915,870 +1494,12 @@ function init(inngest) {
|
|
|
915
1494
|
}
|
|
916
1495
|
};
|
|
917
1496
|
}
|
|
918
|
-
var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
919
|
-
inngestStep;
|
|
920
|
-
inngestAttempts;
|
|
921
|
-
constructor(mastra, inngestStep, inngestAttempts = 0, options) {
|
|
922
|
-
super({ mastra, options });
|
|
923
|
-
this.inngestStep = inngestStep;
|
|
924
|
-
this.inngestAttempts = inngestAttempts;
|
|
925
|
-
}
|
|
926
|
-
async fmtReturnValue(emitter, stepResults, lastOutput, error) {
|
|
927
|
-
const base = {
|
|
928
|
-
status: lastOutput.status,
|
|
929
|
-
steps: stepResults
|
|
930
|
-
};
|
|
931
|
-
if (lastOutput.status === "success") {
|
|
932
|
-
base.result = lastOutput.output;
|
|
933
|
-
} else if (lastOutput.status === "failed") {
|
|
934
|
-
base.error = error instanceof Error ? error?.stack ?? error.message : lastOutput?.error instanceof Error ? lastOutput.error.message : lastOutput.error ?? error ?? "Unknown error";
|
|
935
|
-
} else if (lastOutput.status === "suspended") {
|
|
936
|
-
const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
|
|
937
|
-
if (stepResult?.status === "suspended") {
|
|
938
|
-
const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
|
|
939
|
-
return nestedPath ? [[stepId, ...nestedPath]] : [[stepId]];
|
|
940
|
-
}
|
|
941
|
-
return [];
|
|
942
|
-
});
|
|
943
|
-
base.suspended = suspendedStepIds;
|
|
944
|
-
}
|
|
945
|
-
return base;
|
|
946
|
-
}
|
|
947
|
-
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
948
|
-
// await this.inngestStep.sleep(id, duration);
|
|
949
|
-
// }
|
|
950
|
-
async executeSleep({
|
|
951
|
-
workflowId,
|
|
952
|
-
runId,
|
|
953
|
-
entry,
|
|
954
|
-
prevOutput,
|
|
955
|
-
stepResults,
|
|
956
|
-
emitter,
|
|
957
|
-
abortController,
|
|
958
|
-
requestContext,
|
|
959
|
-
executionContext,
|
|
960
|
-
writableStream,
|
|
961
|
-
tracingContext
|
|
962
|
-
}) {
|
|
963
|
-
let { duration, fn } = entry;
|
|
964
|
-
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
965
|
-
type: observability.SpanType.WORKFLOW_SLEEP,
|
|
966
|
-
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
967
|
-
attributes: {
|
|
968
|
-
durationMs: duration,
|
|
969
|
-
sleepType: fn ? "dynamic" : "fixed"
|
|
970
|
-
},
|
|
971
|
-
tracingPolicy: this.options?.tracingPolicy
|
|
972
|
-
});
|
|
973
|
-
if (fn) {
|
|
974
|
-
const stepCallId = crypto.randomUUID();
|
|
975
|
-
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
976
|
-
return await fn(
|
|
977
|
-
workflows.createDeprecationProxy(
|
|
978
|
-
{
|
|
979
|
-
runId,
|
|
980
|
-
workflowId,
|
|
981
|
-
mastra: this.mastra,
|
|
982
|
-
requestContext,
|
|
983
|
-
inputData: prevOutput,
|
|
984
|
-
state: executionContext.state,
|
|
985
|
-
setState: (state) => {
|
|
986
|
-
executionContext.state = state;
|
|
987
|
-
},
|
|
988
|
-
retryCount: -1,
|
|
989
|
-
tracingContext: {
|
|
990
|
-
currentSpan: sleepSpan
|
|
991
|
-
},
|
|
992
|
-
getInitData: () => stepResults?.input,
|
|
993
|
-
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
994
|
-
// TODO: this function shouldn't have suspend probably?
|
|
995
|
-
suspend: async (_suspendPayload) => {
|
|
996
|
-
},
|
|
997
|
-
bail: () => {
|
|
998
|
-
},
|
|
999
|
-
abort: () => {
|
|
1000
|
-
abortController?.abort();
|
|
1001
|
-
},
|
|
1002
|
-
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1003
|
-
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1004
|
-
engine: { step: this.inngestStep },
|
|
1005
|
-
abortSignal: abortController?.signal,
|
|
1006
|
-
writer: new tools.ToolStream(
|
|
1007
|
-
{
|
|
1008
|
-
prefix: "workflow-step",
|
|
1009
|
-
callId: stepCallId,
|
|
1010
|
-
name: "sleep",
|
|
1011
|
-
runId
|
|
1012
|
-
},
|
|
1013
|
-
writableStream
|
|
1014
|
-
)
|
|
1015
|
-
},
|
|
1016
|
-
{
|
|
1017
|
-
paramName: "runCount",
|
|
1018
|
-
deprecationMessage: workflows.runCountDeprecationMessage,
|
|
1019
|
-
logger: this.logger
|
|
1020
|
-
}
|
|
1021
|
-
)
|
|
1022
|
-
);
|
|
1023
|
-
});
|
|
1024
|
-
sleepSpan?.update({
|
|
1025
|
-
attributes: {
|
|
1026
|
-
durationMs: duration
|
|
1027
|
-
}
|
|
1028
|
-
});
|
|
1029
|
-
}
|
|
1030
|
-
try {
|
|
1031
|
-
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
1032
|
-
sleepSpan?.end();
|
|
1033
|
-
} catch (e) {
|
|
1034
|
-
sleepSpan?.error({ error: e });
|
|
1035
|
-
throw e;
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
async executeSleepUntil({
|
|
1039
|
-
workflowId,
|
|
1040
|
-
runId,
|
|
1041
|
-
entry,
|
|
1042
|
-
prevOutput,
|
|
1043
|
-
stepResults,
|
|
1044
|
-
emitter,
|
|
1045
|
-
abortController,
|
|
1046
|
-
requestContext,
|
|
1047
|
-
executionContext,
|
|
1048
|
-
writableStream,
|
|
1049
|
-
tracingContext
|
|
1050
|
-
}) {
|
|
1051
|
-
let { date, fn } = entry;
|
|
1052
|
-
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1053
|
-
type: observability.SpanType.WORKFLOW_SLEEP,
|
|
1054
|
-
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
1055
|
-
attributes: {
|
|
1056
|
-
untilDate: date,
|
|
1057
|
-
durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
|
|
1058
|
-
sleepType: fn ? "dynamic" : "fixed"
|
|
1059
|
-
},
|
|
1060
|
-
tracingPolicy: this.options?.tracingPolicy
|
|
1061
|
-
});
|
|
1062
|
-
if (fn) {
|
|
1063
|
-
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
1064
|
-
const stepCallId = crypto.randomUUID();
|
|
1065
|
-
return await fn(
|
|
1066
|
-
workflows.createDeprecationProxy(
|
|
1067
|
-
{
|
|
1068
|
-
runId,
|
|
1069
|
-
workflowId,
|
|
1070
|
-
mastra: this.mastra,
|
|
1071
|
-
requestContext,
|
|
1072
|
-
inputData: prevOutput,
|
|
1073
|
-
state: executionContext.state,
|
|
1074
|
-
setState: (state) => {
|
|
1075
|
-
executionContext.state = state;
|
|
1076
|
-
},
|
|
1077
|
-
retryCount: -1,
|
|
1078
|
-
tracingContext: {
|
|
1079
|
-
currentSpan: sleepUntilSpan
|
|
1080
|
-
},
|
|
1081
|
-
getInitData: () => stepResults?.input,
|
|
1082
|
-
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1083
|
-
// TODO: this function shouldn't have suspend probably?
|
|
1084
|
-
suspend: async (_suspendPayload) => {
|
|
1085
|
-
},
|
|
1086
|
-
bail: () => {
|
|
1087
|
-
},
|
|
1088
|
-
abort: () => {
|
|
1089
|
-
abortController?.abort();
|
|
1090
|
-
},
|
|
1091
|
-
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1092
|
-
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1093
|
-
engine: { step: this.inngestStep },
|
|
1094
|
-
abortSignal: abortController?.signal,
|
|
1095
|
-
writer: new tools.ToolStream(
|
|
1096
|
-
{
|
|
1097
|
-
prefix: "workflow-step",
|
|
1098
|
-
callId: stepCallId,
|
|
1099
|
-
name: "sleep",
|
|
1100
|
-
runId
|
|
1101
|
-
},
|
|
1102
|
-
writableStream
|
|
1103
|
-
)
|
|
1104
|
-
},
|
|
1105
|
-
{
|
|
1106
|
-
paramName: "runCount",
|
|
1107
|
-
deprecationMessage: workflows.runCountDeprecationMessage,
|
|
1108
|
-
logger: this.logger
|
|
1109
|
-
}
|
|
1110
|
-
)
|
|
1111
|
-
);
|
|
1112
|
-
});
|
|
1113
|
-
if (date && !(date instanceof Date)) {
|
|
1114
|
-
date = new Date(date);
|
|
1115
|
-
}
|
|
1116
|
-
const time = !date ? 0 : date.getTime() - Date.now();
|
|
1117
|
-
sleepUntilSpan?.update({
|
|
1118
|
-
attributes: {
|
|
1119
|
-
durationMs: Math.max(0, time)
|
|
1120
|
-
}
|
|
1121
|
-
});
|
|
1122
|
-
}
|
|
1123
|
-
if (!(date instanceof Date)) {
|
|
1124
|
-
sleepUntilSpan?.end();
|
|
1125
|
-
return;
|
|
1126
|
-
}
|
|
1127
|
-
try {
|
|
1128
|
-
await this.inngestStep.sleepUntil(entry.id, date);
|
|
1129
|
-
sleepUntilSpan?.end();
|
|
1130
|
-
} catch (e) {
|
|
1131
|
-
sleepUntilSpan?.error({ error: e });
|
|
1132
|
-
throw e;
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
async executeStep({
|
|
1136
|
-
step,
|
|
1137
|
-
stepResults,
|
|
1138
|
-
executionContext,
|
|
1139
|
-
resume,
|
|
1140
|
-
timeTravel,
|
|
1141
|
-
prevOutput,
|
|
1142
|
-
emitter,
|
|
1143
|
-
abortController,
|
|
1144
|
-
requestContext,
|
|
1145
|
-
tracingContext,
|
|
1146
|
-
writableStream,
|
|
1147
|
-
disableScorers
|
|
1148
|
-
}) {
|
|
1149
|
-
const stepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1150
|
-
name: `workflow step: '${step.id}'`,
|
|
1151
|
-
type: observability.SpanType.WORKFLOW_STEP,
|
|
1152
|
-
input: prevOutput,
|
|
1153
|
-
attributes: {
|
|
1154
|
-
stepId: step.id
|
|
1155
|
-
},
|
|
1156
|
-
tracingPolicy: this.options?.tracingPolicy
|
|
1157
|
-
});
|
|
1158
|
-
const { inputData, validationError } = await workflows.validateStepInput({
|
|
1159
|
-
prevOutput,
|
|
1160
|
-
step,
|
|
1161
|
-
validateInputs: this.options?.validateInputs ?? true
|
|
1162
|
-
});
|
|
1163
|
-
const startedAt = await this.inngestStep.run(
|
|
1164
|
-
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
1165
|
-
async () => {
|
|
1166
|
-
const startedAt2 = Date.now();
|
|
1167
|
-
await emitter.emit("watch", {
|
|
1168
|
-
type: "workflow-step-start",
|
|
1169
|
-
payload: {
|
|
1170
|
-
id: step.id,
|
|
1171
|
-
status: "running",
|
|
1172
|
-
payload: inputData,
|
|
1173
|
-
startedAt: startedAt2
|
|
1174
|
-
}
|
|
1175
|
-
});
|
|
1176
|
-
return startedAt2;
|
|
1177
|
-
}
|
|
1178
|
-
);
|
|
1179
|
-
if (step instanceof InngestWorkflow) {
|
|
1180
|
-
const isResume = !!resume?.steps?.length;
|
|
1181
|
-
let result;
|
|
1182
|
-
let runId;
|
|
1183
|
-
const isTimeTravel = !!(timeTravel && timeTravel.steps?.length > 1 && timeTravel.steps[0] === step.id);
|
|
1184
|
-
try {
|
|
1185
|
-
if (isResume) {
|
|
1186
|
-
runId = stepResults[resume?.steps?.[0] ?? ""]?.suspendPayload?.__workflow_meta?.runId ?? crypto.randomUUID();
|
|
1187
|
-
const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
1188
|
-
workflowName: step.id,
|
|
1189
|
-
runId
|
|
1190
|
-
});
|
|
1191
|
-
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
1192
|
-
function: step.getFunction(),
|
|
1193
|
-
data: {
|
|
1194
|
-
inputData,
|
|
1195
|
-
initialState: executionContext.state ?? snapshot?.value ?? {},
|
|
1196
|
-
runId,
|
|
1197
|
-
resume: {
|
|
1198
|
-
runId,
|
|
1199
|
-
steps: resume.steps.slice(1),
|
|
1200
|
-
stepResults: snapshot?.context,
|
|
1201
|
-
resumePayload: resume.resumePayload,
|
|
1202
|
-
resumePath: resume.steps?.[1] ? snapshot?.suspendedPaths?.[resume.steps?.[1]] : void 0
|
|
1203
|
-
},
|
|
1204
|
-
outputOptions: { includeState: true }
|
|
1205
|
-
}
|
|
1206
|
-
});
|
|
1207
|
-
result = invokeResp.result;
|
|
1208
|
-
runId = invokeResp.runId;
|
|
1209
|
-
executionContext.state = invokeResp.result.state;
|
|
1210
|
-
} else if (isTimeTravel) {
|
|
1211
|
-
const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
1212
|
-
workflowName: step.id,
|
|
1213
|
-
runId: executionContext.runId
|
|
1214
|
-
}) ?? { context: {} };
|
|
1215
|
-
const timeTravelParams = workflows.createTimeTravelExecutionParams({
|
|
1216
|
-
steps: timeTravel.steps.slice(1),
|
|
1217
|
-
inputData: timeTravel.inputData,
|
|
1218
|
-
resumeData: timeTravel.resumeData,
|
|
1219
|
-
context: timeTravel.nestedStepResults?.[step.id] ?? {},
|
|
1220
|
-
nestedStepsContext: timeTravel.nestedStepResults ?? {},
|
|
1221
|
-
snapshot,
|
|
1222
|
-
graph: step.buildExecutionGraph()
|
|
1223
|
-
});
|
|
1224
|
-
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
1225
|
-
function: step.getFunction(),
|
|
1226
|
-
data: {
|
|
1227
|
-
timeTravel: timeTravelParams,
|
|
1228
|
-
initialState: executionContext.state ?? {},
|
|
1229
|
-
runId: executionContext.runId,
|
|
1230
|
-
outputOptions: { includeState: true }
|
|
1231
|
-
}
|
|
1232
|
-
});
|
|
1233
|
-
result = invokeResp.result;
|
|
1234
|
-
runId = invokeResp.runId;
|
|
1235
|
-
executionContext.state = invokeResp.result.state;
|
|
1236
|
-
} else {
|
|
1237
|
-
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
1238
|
-
function: step.getFunction(),
|
|
1239
|
-
data: {
|
|
1240
|
-
inputData,
|
|
1241
|
-
initialState: executionContext.state ?? {},
|
|
1242
|
-
outputOptions: { includeState: true }
|
|
1243
|
-
}
|
|
1244
|
-
});
|
|
1245
|
-
result = invokeResp.result;
|
|
1246
|
-
runId = invokeResp.runId;
|
|
1247
|
-
executionContext.state = invokeResp.result.state;
|
|
1248
|
-
}
|
|
1249
|
-
} catch (e) {
|
|
1250
|
-
const errorCause = e?.cause;
|
|
1251
|
-
if (errorCause && typeof errorCause === "object") {
|
|
1252
|
-
result = errorCause;
|
|
1253
|
-
runId = errorCause.runId || crypto.randomUUID();
|
|
1254
|
-
} else {
|
|
1255
|
-
runId = crypto.randomUUID();
|
|
1256
|
-
result = {
|
|
1257
|
-
status: "failed",
|
|
1258
|
-
error: e instanceof Error ? e : new Error(String(e)),
|
|
1259
|
-
steps: {},
|
|
1260
|
-
input: inputData
|
|
1261
|
-
};
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
const res = await this.inngestStep.run(
|
|
1265
|
-
`workflow.${executionContext.workflowId}.step.${step.id}.nestedwf-results`,
|
|
1266
|
-
async () => {
|
|
1267
|
-
if (result.status === "failed") {
|
|
1268
|
-
await emitter.emit("watch", {
|
|
1269
|
-
type: "workflow-step-result",
|
|
1270
|
-
payload: {
|
|
1271
|
-
id: step.id,
|
|
1272
|
-
status: "failed",
|
|
1273
|
-
error: result?.error,
|
|
1274
|
-
payload: prevOutput
|
|
1275
|
-
}
|
|
1276
|
-
});
|
|
1277
|
-
return { executionContext, result: { status: "failed", error: result?.error } };
|
|
1278
|
-
} else if (result.status === "suspended") {
|
|
1279
|
-
const suspendedSteps = Object.entries(result.steps).filter(([_stepName, stepResult]) => {
|
|
1280
|
-
const stepRes2 = stepResult;
|
|
1281
|
-
return stepRes2?.status === "suspended";
|
|
1282
|
-
});
|
|
1283
|
-
for (const [stepName, stepResult] of suspendedSteps) {
|
|
1284
|
-
const suspendPath = [stepName, ...stepResult?.suspendPayload?.__workflow_meta?.path ?? []];
|
|
1285
|
-
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1286
|
-
await emitter.emit("watch", {
|
|
1287
|
-
type: "workflow-step-suspended",
|
|
1288
|
-
payload: {
|
|
1289
|
-
id: step.id,
|
|
1290
|
-
status: "suspended"
|
|
1291
|
-
}
|
|
1292
|
-
});
|
|
1293
|
-
return {
|
|
1294
|
-
executionContext,
|
|
1295
|
-
result: {
|
|
1296
|
-
status: "suspended",
|
|
1297
|
-
payload: stepResult.payload,
|
|
1298
|
-
suspendPayload: {
|
|
1299
|
-
...stepResult?.suspendPayload,
|
|
1300
|
-
__workflow_meta: { runId, path: suspendPath }
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
};
|
|
1304
|
-
}
|
|
1305
|
-
return {
|
|
1306
|
-
executionContext,
|
|
1307
|
-
result: {
|
|
1308
|
-
status: "suspended",
|
|
1309
|
-
payload: {}
|
|
1310
|
-
}
|
|
1311
|
-
};
|
|
1312
|
-
}
|
|
1313
|
-
await emitter.emit("watch", {
|
|
1314
|
-
type: "workflow-step-result",
|
|
1315
|
-
payload: {
|
|
1316
|
-
id: step.id,
|
|
1317
|
-
status: "success",
|
|
1318
|
-
output: result?.result
|
|
1319
|
-
}
|
|
1320
|
-
});
|
|
1321
|
-
await emitter.emit("watch", {
|
|
1322
|
-
type: "workflow-step-finish",
|
|
1323
|
-
payload: {
|
|
1324
|
-
id: step.id,
|
|
1325
|
-
metadata: {}
|
|
1326
|
-
}
|
|
1327
|
-
});
|
|
1328
|
-
return { executionContext, result: { status: "success", output: result?.result } };
|
|
1329
|
-
}
|
|
1330
|
-
);
|
|
1331
|
-
Object.assign(executionContext, res.executionContext);
|
|
1332
|
-
return {
|
|
1333
|
-
...res.result,
|
|
1334
|
-
startedAt,
|
|
1335
|
-
endedAt: Date.now(),
|
|
1336
|
-
payload: inputData,
|
|
1337
|
-
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1338
|
-
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1339
|
-
};
|
|
1340
|
-
}
|
|
1341
|
-
const stepCallId = crypto.randomUUID();
|
|
1342
|
-
let stepRes;
|
|
1343
|
-
try {
|
|
1344
|
-
stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
|
|
1345
|
-
let execResults;
|
|
1346
|
-
let suspended;
|
|
1347
|
-
let bailed;
|
|
1348
|
-
const { resumeData: timeTravelResumeData, validationError: timeTravelResumeValidationError } = await workflows.validateStepResumeData({
|
|
1349
|
-
resumeData: timeTravel?.stepResults[step.id]?.status === "suspended" ? timeTravel?.resumeData : void 0,
|
|
1350
|
-
step
|
|
1351
|
-
});
|
|
1352
|
-
let resumeDataToUse;
|
|
1353
|
-
if (timeTravelResumeData && !timeTravelResumeValidationError) {
|
|
1354
|
-
resumeDataToUse = timeTravelResumeData;
|
|
1355
|
-
} else if (timeTravelResumeData && timeTravelResumeValidationError) {
|
|
1356
|
-
this.logger.warn("Time travel resume data validation failed", {
|
|
1357
|
-
stepId: step.id,
|
|
1358
|
-
error: timeTravelResumeValidationError.message
|
|
1359
|
-
});
|
|
1360
|
-
} else if (resume?.steps[0] === step.id) {
|
|
1361
|
-
resumeDataToUse = resume?.resumePayload;
|
|
1362
|
-
}
|
|
1363
|
-
try {
|
|
1364
|
-
if (validationError) {
|
|
1365
|
-
throw validationError;
|
|
1366
|
-
}
|
|
1367
|
-
const retryCount = this.getOrGenerateRetryCount(step.id);
|
|
1368
|
-
const result = await step.execute({
|
|
1369
|
-
runId: executionContext.runId,
|
|
1370
|
-
workflowId: executionContext.workflowId,
|
|
1371
|
-
mastra: this.mastra,
|
|
1372
|
-
requestContext,
|
|
1373
|
-
retryCount,
|
|
1374
|
-
writer: new tools.ToolStream(
|
|
1375
|
-
{
|
|
1376
|
-
prefix: "workflow-step",
|
|
1377
|
-
callId: stepCallId,
|
|
1378
|
-
name: step.id,
|
|
1379
|
-
runId: executionContext.runId
|
|
1380
|
-
},
|
|
1381
|
-
writableStream
|
|
1382
|
-
),
|
|
1383
|
-
state: executionContext?.state ?? {},
|
|
1384
|
-
setState: (state) => {
|
|
1385
|
-
executionContext.state = state;
|
|
1386
|
-
},
|
|
1387
|
-
inputData,
|
|
1388
|
-
resumeData: resumeDataToUse,
|
|
1389
|
-
tracingContext: {
|
|
1390
|
-
currentSpan: stepSpan
|
|
1391
|
-
},
|
|
1392
|
-
getInitData: () => stepResults?.input,
|
|
1393
|
-
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1394
|
-
suspend: async (suspendPayload, suspendOptions) => {
|
|
1395
|
-
const { suspendData, validationError: validationError2 } = await workflows.validateStepSuspendData({
|
|
1396
|
-
suspendData: suspendPayload,
|
|
1397
|
-
step
|
|
1398
|
-
});
|
|
1399
|
-
if (validationError2) {
|
|
1400
|
-
throw validationError2;
|
|
1401
|
-
}
|
|
1402
|
-
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1403
|
-
if (suspendOptions?.resumeLabel) {
|
|
1404
|
-
const resumeLabel = Array.isArray(suspendOptions.resumeLabel) ? suspendOptions.resumeLabel : [suspendOptions.resumeLabel];
|
|
1405
|
-
for (const label of resumeLabel) {
|
|
1406
|
-
executionContext.resumeLabels[label] = {
|
|
1407
|
-
stepId: step.id,
|
|
1408
|
-
foreachIndex: executionContext.foreachIndex
|
|
1409
|
-
};
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
suspended = { payload: suspendData };
|
|
1413
|
-
},
|
|
1414
|
-
bail: (result2) => {
|
|
1415
|
-
bailed = { payload: result2 };
|
|
1416
|
-
},
|
|
1417
|
-
abort: () => {
|
|
1418
|
-
abortController?.abort();
|
|
1419
|
-
},
|
|
1420
|
-
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1421
|
-
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1422
|
-
engine: {
|
|
1423
|
-
step: this.inngestStep
|
|
1424
|
-
},
|
|
1425
|
-
abortSignal: abortController.signal
|
|
1426
|
-
});
|
|
1427
|
-
const endedAt = Date.now();
|
|
1428
|
-
execResults = {
|
|
1429
|
-
status: "success",
|
|
1430
|
-
output: result,
|
|
1431
|
-
startedAt,
|
|
1432
|
-
endedAt,
|
|
1433
|
-
payload: inputData,
|
|
1434
|
-
resumedAt: resumeDataToUse ? startedAt : void 0,
|
|
1435
|
-
resumePayload: resumeDataToUse
|
|
1436
|
-
};
|
|
1437
|
-
} catch (e) {
|
|
1438
|
-
const stepFailure = {
|
|
1439
|
-
status: "failed",
|
|
1440
|
-
payload: inputData,
|
|
1441
|
-
error: e instanceof Error ? e.message : String(e),
|
|
1442
|
-
endedAt: Date.now(),
|
|
1443
|
-
startedAt,
|
|
1444
|
-
resumedAt: resumeDataToUse ? startedAt : void 0,
|
|
1445
|
-
resumePayload: resumeDataToUse
|
|
1446
|
-
};
|
|
1447
|
-
execResults = stepFailure;
|
|
1448
|
-
const fallbackErrorMessage = `Step ${step.id} failed`;
|
|
1449
|
-
stepSpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
|
|
1450
|
-
throw new inngest.RetryAfterError(execResults.error ?? fallbackErrorMessage, executionContext.retryConfig.delay, {
|
|
1451
|
-
cause: execResults
|
|
1452
|
-
});
|
|
1453
|
-
}
|
|
1454
|
-
if (suspended) {
|
|
1455
|
-
execResults = {
|
|
1456
|
-
status: "suspended",
|
|
1457
|
-
suspendPayload: suspended.payload,
|
|
1458
|
-
...execResults.output ? { suspendOutput: execResults.output } : {},
|
|
1459
|
-
payload: inputData,
|
|
1460
|
-
suspendedAt: Date.now(),
|
|
1461
|
-
startedAt,
|
|
1462
|
-
resumedAt: resumeDataToUse ? startedAt : void 0,
|
|
1463
|
-
resumePayload: resumeDataToUse
|
|
1464
|
-
};
|
|
1465
|
-
} else if (bailed) {
|
|
1466
|
-
execResults = {
|
|
1467
|
-
status: "bailed",
|
|
1468
|
-
output: bailed.payload,
|
|
1469
|
-
payload: inputData,
|
|
1470
|
-
endedAt: Date.now(),
|
|
1471
|
-
startedAt
|
|
1472
|
-
};
|
|
1473
|
-
}
|
|
1474
|
-
if (execResults.status === "suspended") {
|
|
1475
|
-
await emitter.emit("watch", {
|
|
1476
|
-
type: "workflow-step-suspended",
|
|
1477
|
-
payload: {
|
|
1478
|
-
id: step.id,
|
|
1479
|
-
...execResults
|
|
1480
|
-
}
|
|
1481
|
-
});
|
|
1482
|
-
} else {
|
|
1483
|
-
await emitter.emit("watch", {
|
|
1484
|
-
type: "workflow-step-result",
|
|
1485
|
-
payload: {
|
|
1486
|
-
id: step.id,
|
|
1487
|
-
...execResults
|
|
1488
|
-
}
|
|
1489
|
-
});
|
|
1490
|
-
await emitter.emit("watch", {
|
|
1491
|
-
type: "workflow-step-finish",
|
|
1492
|
-
payload: {
|
|
1493
|
-
id: step.id,
|
|
1494
|
-
metadata: {}
|
|
1495
|
-
}
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
stepSpan?.end({ output: execResults });
|
|
1499
|
-
return { result: execResults, executionContext, stepResults };
|
|
1500
|
-
});
|
|
1501
|
-
} catch (e) {
|
|
1502
|
-
const stepFailure = e instanceof Error ? e?.cause : {
|
|
1503
|
-
status: "failed",
|
|
1504
|
-
error: e instanceof Error ? e.message : String(e),
|
|
1505
|
-
payload: inputData,
|
|
1506
|
-
startedAt,
|
|
1507
|
-
endedAt: Date.now()
|
|
1508
|
-
};
|
|
1509
|
-
await emitter.emit("watch", {
|
|
1510
|
-
type: "workflow-step-result",
|
|
1511
|
-
payload: {
|
|
1512
|
-
id: step.id,
|
|
1513
|
-
...stepFailure
|
|
1514
|
-
}
|
|
1515
|
-
});
|
|
1516
|
-
await emitter.emit("watch", {
|
|
1517
|
-
type: "workflow-step-finish",
|
|
1518
|
-
payload: {
|
|
1519
|
-
id: step.id,
|
|
1520
|
-
metadata: {}
|
|
1521
|
-
}
|
|
1522
|
-
});
|
|
1523
|
-
stepRes = {
|
|
1524
|
-
result: stepFailure,
|
|
1525
|
-
executionContext,
|
|
1526
|
-
stepResults: {
|
|
1527
|
-
...stepResults,
|
|
1528
|
-
[step.id]: stepFailure
|
|
1529
|
-
}
|
|
1530
|
-
};
|
|
1531
|
-
}
|
|
1532
|
-
if (disableScorers !== false && stepRes.result.status === "success") {
|
|
1533
|
-
await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
|
|
1534
|
-
if (step.scorers) {
|
|
1535
|
-
await this.runScorers({
|
|
1536
|
-
scorers: step.scorers,
|
|
1537
|
-
runId: executionContext.runId,
|
|
1538
|
-
input: inputData,
|
|
1539
|
-
output: stepRes.result,
|
|
1540
|
-
workflowId: executionContext.workflowId,
|
|
1541
|
-
stepId: step.id,
|
|
1542
|
-
requestContext,
|
|
1543
|
-
disableScorers,
|
|
1544
|
-
tracingContext: { currentSpan: stepSpan }
|
|
1545
|
-
});
|
|
1546
|
-
}
|
|
1547
|
-
});
|
|
1548
|
-
}
|
|
1549
|
-
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1550
|
-
executionContext.state = stepRes.executionContext.state;
|
|
1551
|
-
return stepRes.result;
|
|
1552
|
-
}
|
|
1553
|
-
async persistStepUpdate({
|
|
1554
|
-
workflowId,
|
|
1555
|
-
runId,
|
|
1556
|
-
stepResults,
|
|
1557
|
-
resourceId,
|
|
1558
|
-
executionContext,
|
|
1559
|
-
serializedStepGraph,
|
|
1560
|
-
workflowStatus,
|
|
1561
|
-
result,
|
|
1562
|
-
error
|
|
1563
|
-
}) {
|
|
1564
|
-
await this.inngestStep.run(
|
|
1565
|
-
`workflow.${workflowId}.run.${runId}.path.${JSON.stringify(executionContext.executionPath)}.stepUpdate`,
|
|
1566
|
-
async () => {
|
|
1567
|
-
const shouldPersistSnapshot = this.options.shouldPersistSnapshot({ stepResults, workflowStatus });
|
|
1568
|
-
if (!shouldPersistSnapshot) {
|
|
1569
|
-
return;
|
|
1570
|
-
}
|
|
1571
|
-
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
1572
|
-
workflowName: workflowId,
|
|
1573
|
-
runId,
|
|
1574
|
-
resourceId,
|
|
1575
|
-
snapshot: {
|
|
1576
|
-
runId,
|
|
1577
|
-
status: workflowStatus,
|
|
1578
|
-
value: executionContext.state,
|
|
1579
|
-
context: stepResults,
|
|
1580
|
-
activePaths: executionContext.executionPath,
|
|
1581
|
-
activeStepsPath: executionContext.activeStepsPath,
|
|
1582
|
-
suspendedPaths: executionContext.suspendedPaths,
|
|
1583
|
-
resumeLabels: executionContext.resumeLabels,
|
|
1584
|
-
waitingPaths: {},
|
|
1585
|
-
serializedStepGraph,
|
|
1586
|
-
result,
|
|
1587
|
-
error,
|
|
1588
|
-
timestamp: Date.now()
|
|
1589
|
-
}
|
|
1590
|
-
});
|
|
1591
|
-
}
|
|
1592
|
-
);
|
|
1593
|
-
}
|
|
1594
|
-
async executeConditional({
|
|
1595
|
-
workflowId,
|
|
1596
|
-
runId,
|
|
1597
|
-
entry,
|
|
1598
|
-
prevOutput,
|
|
1599
|
-
stepResults,
|
|
1600
|
-
timeTravel,
|
|
1601
|
-
resume,
|
|
1602
|
-
executionContext,
|
|
1603
|
-
emitter,
|
|
1604
|
-
abortController,
|
|
1605
|
-
requestContext,
|
|
1606
|
-
writableStream,
|
|
1607
|
-
disableScorers,
|
|
1608
|
-
tracingContext
|
|
1609
|
-
}) {
|
|
1610
|
-
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1611
|
-
type: observability.SpanType.WORKFLOW_CONDITIONAL,
|
|
1612
|
-
name: `conditional: '${entry.conditions.length} conditions'`,
|
|
1613
|
-
input: prevOutput,
|
|
1614
|
-
attributes: {
|
|
1615
|
-
conditionCount: entry.conditions.length
|
|
1616
|
-
},
|
|
1617
|
-
tracingPolicy: this.options?.tracingPolicy
|
|
1618
|
-
});
|
|
1619
|
-
let execResults;
|
|
1620
|
-
const truthyIndexes = (await Promise.all(
|
|
1621
|
-
entry.conditions.map(
|
|
1622
|
-
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1623
|
-
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1624
|
-
type: observability.SpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1625
|
-
name: `condition: '${index}'`,
|
|
1626
|
-
input: prevOutput,
|
|
1627
|
-
attributes: {
|
|
1628
|
-
conditionIndex: index
|
|
1629
|
-
},
|
|
1630
|
-
tracingPolicy: this.options?.tracingPolicy
|
|
1631
|
-
});
|
|
1632
|
-
try {
|
|
1633
|
-
const result = await cond(
|
|
1634
|
-
workflows.createDeprecationProxy(
|
|
1635
|
-
{
|
|
1636
|
-
runId,
|
|
1637
|
-
workflowId,
|
|
1638
|
-
mastra: this.mastra,
|
|
1639
|
-
requestContext,
|
|
1640
|
-
retryCount: -1,
|
|
1641
|
-
inputData: prevOutput,
|
|
1642
|
-
state: executionContext.state,
|
|
1643
|
-
setState: (state) => {
|
|
1644
|
-
executionContext.state = state;
|
|
1645
|
-
},
|
|
1646
|
-
tracingContext: {
|
|
1647
|
-
currentSpan: evalSpan
|
|
1648
|
-
},
|
|
1649
|
-
getInitData: () => stepResults?.input,
|
|
1650
|
-
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1651
|
-
// TODO: this function shouldn't have suspend probably?
|
|
1652
|
-
suspend: async (_suspendPayload) => {
|
|
1653
|
-
},
|
|
1654
|
-
bail: () => {
|
|
1655
|
-
},
|
|
1656
|
-
abort: () => {
|
|
1657
|
-
abortController.abort();
|
|
1658
|
-
},
|
|
1659
|
-
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1660
|
-
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1661
|
-
engine: {
|
|
1662
|
-
step: this.inngestStep
|
|
1663
|
-
},
|
|
1664
|
-
abortSignal: abortController.signal,
|
|
1665
|
-
writer: new tools.ToolStream(
|
|
1666
|
-
{
|
|
1667
|
-
prefix: "workflow-step",
|
|
1668
|
-
callId: crypto.randomUUID(),
|
|
1669
|
-
name: "conditional",
|
|
1670
|
-
runId
|
|
1671
|
-
},
|
|
1672
|
-
writableStream
|
|
1673
|
-
)
|
|
1674
|
-
},
|
|
1675
|
-
{
|
|
1676
|
-
paramName: "runCount",
|
|
1677
|
-
deprecationMessage: workflows.runCountDeprecationMessage,
|
|
1678
|
-
logger: this.logger
|
|
1679
|
-
}
|
|
1680
|
-
)
|
|
1681
|
-
);
|
|
1682
|
-
evalSpan?.end({
|
|
1683
|
-
output: result,
|
|
1684
|
-
attributes: {
|
|
1685
|
-
result: !!result
|
|
1686
|
-
}
|
|
1687
|
-
});
|
|
1688
|
-
return result ? index : null;
|
|
1689
|
-
} catch (e) {
|
|
1690
|
-
evalSpan?.error({
|
|
1691
|
-
error: e instanceof Error ? e : new Error(String(e)),
|
|
1692
|
-
attributes: {
|
|
1693
|
-
result: false
|
|
1694
|
-
}
|
|
1695
|
-
});
|
|
1696
|
-
return null;
|
|
1697
|
-
}
|
|
1698
|
-
})
|
|
1699
|
-
)
|
|
1700
|
-
)).filter((index) => index !== null);
|
|
1701
|
-
const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
|
|
1702
|
-
conditionalSpan?.update({
|
|
1703
|
-
attributes: {
|
|
1704
|
-
truthyIndexes,
|
|
1705
|
-
selectedSteps: stepsToRun.map((s) => s.type === "step" ? s.step.id : `control-${s.type}`)
|
|
1706
|
-
}
|
|
1707
|
-
});
|
|
1708
|
-
const results = await Promise.all(
|
|
1709
|
-
stepsToRun.map(async (step, index) => {
|
|
1710
|
-
const currStepResult = stepResults[step.step.id];
|
|
1711
|
-
if (currStepResult && currStepResult.status === "success") {
|
|
1712
|
-
return currStepResult;
|
|
1713
|
-
}
|
|
1714
|
-
const result = await this.executeStep({
|
|
1715
|
-
step: step.step,
|
|
1716
|
-
prevOutput,
|
|
1717
|
-
stepResults,
|
|
1718
|
-
resume,
|
|
1719
|
-
timeTravel,
|
|
1720
|
-
executionContext: {
|
|
1721
|
-
workflowId,
|
|
1722
|
-
runId,
|
|
1723
|
-
executionPath: [...executionContext.executionPath, index],
|
|
1724
|
-
activeStepsPath: executionContext.activeStepsPath,
|
|
1725
|
-
suspendedPaths: executionContext.suspendedPaths,
|
|
1726
|
-
resumeLabels: executionContext.resumeLabels,
|
|
1727
|
-
retryConfig: executionContext.retryConfig,
|
|
1728
|
-
state: executionContext.state
|
|
1729
|
-
},
|
|
1730
|
-
emitter,
|
|
1731
|
-
abortController,
|
|
1732
|
-
requestContext,
|
|
1733
|
-
writableStream,
|
|
1734
|
-
disableScorers,
|
|
1735
|
-
tracingContext: {
|
|
1736
|
-
currentSpan: conditionalSpan
|
|
1737
|
-
}
|
|
1738
|
-
});
|
|
1739
|
-
stepResults[step.step.id] = result;
|
|
1740
|
-
return result;
|
|
1741
|
-
})
|
|
1742
|
-
);
|
|
1743
|
-
const hasFailed = results.find((result) => result.status === "failed");
|
|
1744
|
-
const hasSuspended = results.find((result) => result.status === "suspended");
|
|
1745
|
-
if (hasFailed) {
|
|
1746
|
-
execResults = { status: "failed", error: hasFailed.error };
|
|
1747
|
-
} else if (hasSuspended) {
|
|
1748
|
-
execResults = {
|
|
1749
|
-
status: "suspended",
|
|
1750
|
-
suspendPayload: hasSuspended.suspendPayload,
|
|
1751
|
-
...hasSuspended.suspendOutput ? { suspendOutput: hasSuspended.suspendOutput } : {}
|
|
1752
|
-
};
|
|
1753
|
-
} else {
|
|
1754
|
-
execResults = {
|
|
1755
|
-
status: "success",
|
|
1756
|
-
output: results.reduce((acc, result, index) => {
|
|
1757
|
-
if (result.status === "success") {
|
|
1758
|
-
if ("step" in stepsToRun[index]) {
|
|
1759
|
-
acc[stepsToRun[index].step.id] = result.output;
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
return acc;
|
|
1763
|
-
}, {})
|
|
1764
|
-
};
|
|
1765
|
-
}
|
|
1766
|
-
if (execResults.status === "failed") {
|
|
1767
|
-
conditionalSpan?.error({
|
|
1768
|
-
error: new Error(execResults.error)
|
|
1769
|
-
});
|
|
1770
|
-
} else {
|
|
1771
|
-
conditionalSpan?.end({
|
|
1772
|
-
output: execResults.output || execResults
|
|
1773
|
-
});
|
|
1774
|
-
}
|
|
1775
|
-
return execResults;
|
|
1776
|
-
}
|
|
1777
|
-
};
|
|
1778
1497
|
|
|
1779
1498
|
exports.InngestExecutionEngine = InngestExecutionEngine;
|
|
1499
|
+
exports.InngestPubSub = InngestPubSub;
|
|
1780
1500
|
exports.InngestRun = InngestRun;
|
|
1781
1501
|
exports.InngestWorkflow = InngestWorkflow;
|
|
1502
|
+
exports._compatibilityCheck = _compatibilityCheck;
|
|
1782
1503
|
exports.createStep = createStep;
|
|
1783
1504
|
exports.init = init;
|
|
1784
1505
|
exports.serve = serve;
|