@mastra/inngest 1.8.4 → 1.8.5
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 +18 -0
- package/dist/{connect-CrcddA94.cjs → connect-0KhA4iVJ.cjs} +263 -182
- package/dist/connect-0KhA4iVJ.cjs.map +1 -0
- package/dist/{connect-EcSaEWsZ.js → connect-DyLW0LAE.js} +263 -182
- package/dist/connect-DyLW0LAE.js.map +1 -0
- package/dist/connect.cjs +1 -1
- package/dist/connect.js +1 -1
- package/dist/execution-engine.d.ts +3 -0
- package/dist/execution-engine.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/nested-workflow-output.d.ts +30 -0
- package/dist/nested-workflow-output.d.ts.map +1 -0
- package/dist/workflow.d.ts +5 -0
- package/dist/workflow.d.ts.map +1 -1
- package/package.json +8 -7
- package/dist/__tests__/adapters/_utils.d.ts +0 -18
- package/dist/__tests__/adapters/_utils.d.ts.map +0 -1
- package/dist/__tests__/durable-agent.test.utils.d.ts +0 -43
- package/dist/__tests__/durable-agent.test.utils.d.ts.map +0 -1
- package/dist/connect-CrcddA94.cjs.map +0 -1
- package/dist/connect-EcSaEWsZ.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/inngest
|
|
2
2
|
|
|
3
|
+
## 1.8.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed nested Inngest workflows retaining unused input and step history in parent run state. ([#19217](https://github.com/mastra-ai/mastra/pull/19217))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`8d2399b`](https://github.com/mastra-ai/mastra/commit/8d2399b638f8e0945cf2cda0187dbea8dcf0b784), [`c8002da`](https://github.com/mastra-ai/mastra/commit/c8002da7775c468e2965b6ff5f82045450fa8cb9), [`92be47f`](https://github.com/mastra-ai/mastra/commit/92be47fbd26ffccec0e2131ef7c1d9e70dd5ef4a), [`89200ba`](https://github.com/mastra-ai/mastra/commit/89200bafa05444bb7949b363ce7b743e29867561), [`c950138`](https://github.com/mastra-ai/mastra/commit/c950138e72e4f317a40187e3800588731ab790ce), [`810c7e7`](https://github.com/mastra-ai/mastra/commit/810c7e74929989d8b8b5db52cd3af22cd0998af4), [`063c8b2`](https://github.com/mastra-ai/mastra/commit/063c8b2eb14e4e5ca021779bc33e8c3c031c8604), [`f9f9884`](https://github.com/mastra-ai/mastra/commit/f9f98848ee194dc71a787a709ec430b065cdc41b), [`e0904dc`](https://github.com/mastra-ai/mastra/commit/e0904dc538792e54e1806b70172e5900ac49bff4), [`9672fab`](https://github.com/mastra-ai/mastra/commit/9672fabfbcadb961a35c22a2d6722e077f7b24b9), [`f4e964c`](https://github.com/mastra-ai/mastra/commit/f4e964cad57057301d6bed5c55bcdd730175b941), [`1f7bbd7`](https://github.com/mastra-ai/mastra/commit/1f7bbd7785a8d230aad02454ecabeb4a0b2cc96f), [`e47ff36`](https://github.com/mastra-ai/mastra/commit/e47ff36945720f4ee4caa09f6e83514d7d188608), [`64d6781`](https://github.com/mastra-ai/mastra/commit/64d67814bccddd314f7e09643243821e57cb87b6), [`fb9a6ac`](https://github.com/mastra-ai/mastra/commit/fb9a6ac11c9560518742ece60b49d6b062845fd3), [`aa2cec8`](https://github.com/mastra-ai/mastra/commit/aa2cec8501f634d51c2f3ebfb3dd3aa7af8d2ca2), [`c848e65`](https://github.com/mastra-ai/mastra/commit/c848e655a64ff10331a8ceafafe7f18e70a0f092), [`2adf8eb`](https://github.com/mastra-ai/mastra/commit/2adf8eb4a70ed2b6cff2dd39281496ea0e025fac), [`0494489`](https://github.com/mastra-ai/mastra/commit/049448906e4c3d2d615bbe865b073a0d890ddb7c), [`8d1aeb8`](https://github.com/mastra-ai/mastra/commit/8d1aeb8acf7c20c4bb8e4d8e4bdc6569c83ac561), [`8264611`](https://github.com/mastra-ai/mastra/commit/8264611510e421b818bc7395dc2ae4d9c2d518b2), [`d8fa243`](https://github.com/mastra-ai/mastra/commit/d8fa2430d21113e330c4e676ac65e1235cf44f81), [`44fc98b`](https://github.com/mastra-ai/mastra/commit/44fc98b9d1242aa87a3ab44bdce9e9f12c44d8c9), [`f933ba3`](https://github.com/mastra-ai/mastra/commit/f933ba32700e1d0bf143311c1a08f88300b840b6), [`83065bf`](https://github.com/mastra-ai/mastra/commit/83065bfee9e47c3c6f09132a9034501f6cfb69cf), [`0f2ef41`](https://github.com/mastra-ai/mastra/commit/0f2ef4118da022e4f30dac4e9856cc3a8c97671c), [`01b162f`](https://github.com/mastra-ai/mastra/commit/01b162fe435295881aa7ea55f1759407ad5175ad)]:
|
|
10
|
+
- @mastra/core@1.57.0
|
|
11
|
+
|
|
12
|
+
## 1.8.5-alpha.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Fixed nested Inngest workflows retaining unused input and step history in parent run state. ([#19217](https://github.com/mastra-ai/mastra/pull/19217))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`c8002da`](https://github.com/mastra-ai/mastra/commit/c8002da7775c468e2965b6ff5f82045450fa8cb9)]:
|
|
19
|
+
- @mastra/core@1.56.1-alpha.0
|
|
20
|
+
|
|
3
21
|
## 1.8.4
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -9,6 +9,58 @@ let _mastra_core_events = require("@mastra/core/events");
|
|
|
9
9
|
let inngest_realtime = require("inngest/realtime");
|
|
10
10
|
let stream_web = require("stream/web");
|
|
11
11
|
let _mastra_core_stream = require("@mastra/core/stream");
|
|
12
|
+
//#region src/nested-workflow-output.ts
|
|
13
|
+
const NESTED_WORKFLOW_OUTPUT_MODE = {
|
|
14
|
+
DEFAULT: "default",
|
|
15
|
+
COMPACT: "compact"
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes an optional nested workflow output mode to an explicit mode.
|
|
19
|
+
*
|
|
20
|
+
* @param mode - The output mode requested by the invoking workflow.
|
|
21
|
+
* @returns The requested compact mode, or the default mode when compact output was not requested.
|
|
22
|
+
*/
|
|
23
|
+
function resolveNestedWorkflowOutputMode(mode = NESTED_WORKFLOW_OUTPUT_MODE.DEFAULT) {
|
|
24
|
+
return mode === NESTED_WORKFLOW_OUTPUT_MODE.COMPACT ? NESTED_WORKFLOW_OUTPUT_MODE.COMPACT : NESTED_WORKFLOW_OUTPUT_MODE.DEFAULT;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Keeps only the status-specific fields consumed by a parent workflow after
|
|
28
|
+
* `step.invoke()`. Suspended results retain steps so the parent can construct
|
|
29
|
+
* the nested resume path; completed results do not carry the child input or
|
|
30
|
+
* internal step history into the parent's memoized run state.
|
|
31
|
+
*
|
|
32
|
+
* @param result - The complete result returned by the nested workflow.
|
|
33
|
+
* @returns The status-specific fields required by the invoking parent workflow.
|
|
34
|
+
*/
|
|
35
|
+
function compactNestedWorkflowResult(result) {
|
|
36
|
+
switch (result.status) {
|
|
37
|
+
case "success": return {
|
|
38
|
+
status: result.status,
|
|
39
|
+
result: result.result,
|
|
40
|
+
state: result.state
|
|
41
|
+
};
|
|
42
|
+
case "failed": return {
|
|
43
|
+
status: result.status,
|
|
44
|
+
error: result.error,
|
|
45
|
+
state: result.state
|
|
46
|
+
};
|
|
47
|
+
case "tripwire": return {
|
|
48
|
+
status: result.status,
|
|
49
|
+
tripwire: result.tripwire,
|
|
50
|
+
state: result.state
|
|
51
|
+
};
|
|
52
|
+
case "suspended": return {
|
|
53
|
+
status: result.status,
|
|
54
|
+
steps: result.steps,
|
|
55
|
+
state: result.state
|
|
56
|
+
};
|
|
57
|
+
case "paused": return {
|
|
58
|
+
status: result.status,
|
|
59
|
+
state: result.state
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
12
64
|
//#region src/execution-engine.ts
|
|
13
65
|
function isNonRetryableStepFailure(error) {
|
|
14
66
|
if (error instanceof _mastra_core_error.MastraNonRetryableError || error instanceof inngest.NonRetriableError) return true;
|
|
@@ -258,6 +310,9 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
258
310
|
/**
|
|
259
311
|
* Execute nested InngestWorkflow using inngestStep.invoke() for durability.
|
|
260
312
|
* This MUST be called directly (not inside step.run()) due to Inngest constraints.
|
|
313
|
+
*
|
|
314
|
+
* @param params - The nested workflow step and its current execution state.
|
|
315
|
+
* @returns The nested workflow step result, or null when the step is not an Inngest workflow.
|
|
261
316
|
*/
|
|
262
317
|
async executeWorkflowStep(params) {
|
|
263
318
|
if (!(params.step instanceof InngestWorkflow)) return null;
|
|
@@ -304,6 +359,7 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
304
359
|
resumePath: nestedResumeStepId ? snapshot?.suspendedPaths?.[nestedResumeStepId] : void 0
|
|
305
360
|
},
|
|
306
361
|
outputOptions: { includeState: true },
|
|
362
|
+
nestedWorkflowOutputMode: NESTED_WORKFLOW_OUTPUT_MODE.COMPACT,
|
|
307
363
|
perStep,
|
|
308
364
|
tracingOptions: nestedTracingContext,
|
|
309
365
|
actor
|
|
@@ -334,6 +390,7 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
334
390
|
requestContext: forwardedRequestContext,
|
|
335
391
|
runId: executionContext.runId,
|
|
336
392
|
outputOptions: { includeState: true },
|
|
393
|
+
nestedWorkflowOutputMode: NESTED_WORKFLOW_OUTPUT_MODE.COMPACT,
|
|
337
394
|
perStep,
|
|
338
395
|
tracingOptions: nestedTracingContext,
|
|
339
396
|
actor
|
|
@@ -350,6 +407,7 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
350
407
|
initialState: executionContext.state ?? {},
|
|
351
408
|
requestContext: forwardedRequestContext,
|
|
352
409
|
outputOptions: { includeState: true },
|
|
410
|
+
nestedWorkflowOutputMode: NESTED_WORKFLOW_OUTPUT_MODE.COMPACT,
|
|
353
411
|
perStep,
|
|
354
412
|
tracingOptions: nestedTracingContext,
|
|
355
413
|
actor
|
|
@@ -360,17 +418,15 @@ var InngestExecutionEngine = class extends _mastra_core_workflows.DefaultExecuti
|
|
|
360
418
|
executionContext.state = invokeResp.result.state;
|
|
361
419
|
}
|
|
362
420
|
} catch (e) {
|
|
363
|
-
const errorCause = e
|
|
364
|
-
if (errorCause && typeof errorCause === "object") {
|
|
421
|
+
const errorCause = e && typeof e === "object" && "cause" in e ? e.cause : void 0;
|
|
422
|
+
if (errorCause && typeof errorCause === "object" && "status" in errorCause && errorCause.status === "failed") {
|
|
365
423
|
result = errorCause;
|
|
366
|
-
runId = errorCause.runId
|
|
424
|
+
runId = "runId" in errorCause && typeof errorCause.runId === "string" ? errorCause.runId : (0, crypto$1.randomUUID)();
|
|
367
425
|
} else {
|
|
368
426
|
runId = (0, crypto$1.randomUUID)();
|
|
369
427
|
result = {
|
|
370
428
|
status: "failed",
|
|
371
|
-
error: e instanceof Error ? e : new Error(String(e))
|
|
372
|
-
steps: {},
|
|
373
|
-
input: inputData
|
|
429
|
+
error: e instanceof Error ? e : new Error(String(e))
|
|
374
430
|
};
|
|
375
431
|
}
|
|
376
432
|
}
|
|
@@ -1511,197 +1567,222 @@ var InngestWorkflow = class extends _mastra_core_workflows.Workflow {
|
|
|
1511
1567
|
});
|
|
1512
1568
|
return this.cronFunction;
|
|
1513
1569
|
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Gets the durable Inngest function that executes this workflow.
|
|
1572
|
+
*
|
|
1573
|
+
* @returns The memoized Inngest function for this workflow.
|
|
1574
|
+
*/
|
|
1514
1575
|
getFunction() {
|
|
1515
1576
|
if (this.function) return this.function;
|
|
1516
|
-
this.function = this.inngest.createFunction(
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
return observability.startSpan({
|
|
1536
|
-
type: _mastra_core_observability.SpanType.WORKFLOW_RUN,
|
|
1537
|
-
name: `workflow run: '${this.id}'`,
|
|
1538
|
-
entityType: _mastra_core_observability.EntityType.WORKFLOW_RUN,
|
|
1539
|
-
entityId: this.id,
|
|
1540
|
-
entityName: this.id,
|
|
1541
|
-
input: inputData,
|
|
1542
|
-
metadata: {
|
|
1543
|
-
resourceId,
|
|
1544
|
-
runId
|
|
1545
|
-
},
|
|
1546
|
-
tracingPolicy,
|
|
1547
|
-
tracingOptions,
|
|
1548
|
-
requestContext
|
|
1549
|
-
})?.exportSpan();
|
|
1550
|
-
});
|
|
1551
|
-
const engine = new InngestExecutionEngine(this.#mastra, step, attempt, this.options);
|
|
1552
|
-
let result;
|
|
1553
|
-
try {
|
|
1554
|
-
result = await engine.execute({
|
|
1555
|
-
workflowId: this.id,
|
|
1556
|
-
runId,
|
|
1557
|
-
resourceId,
|
|
1558
|
-
graph: this.executionGraph,
|
|
1559
|
-
serializedStepGraph: this.serializedStepGraph,
|
|
1560
|
-
input: inputData,
|
|
1561
|
-
initialState,
|
|
1562
|
-
pubsub,
|
|
1563
|
-
retryConfig: this.retryConfig,
|
|
1564
|
-
requestContext,
|
|
1565
|
-
actor,
|
|
1566
|
-
resume,
|
|
1567
|
-
timeTravel,
|
|
1568
|
-
perStep,
|
|
1569
|
-
format,
|
|
1570
|
-
abortController: new AbortController(),
|
|
1571
|
-
workflowSpan: void 0,
|
|
1572
|
-
tracingIds: workflowSpanData ? {
|
|
1573
|
-
traceId: workflowSpanData.traceId,
|
|
1574
|
-
workflowSpanId: workflowSpanData.id
|
|
1575
|
-
} : void 0,
|
|
1576
|
-
outputOptions,
|
|
1577
|
-
outputWriter: async (chunk) => {
|
|
1578
|
-
try {
|
|
1579
|
-
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
1580
|
-
type: "watch",
|
|
1581
|
-
runId,
|
|
1582
|
-
data: chunk
|
|
1583
|
-
});
|
|
1584
|
-
} catch (err) {
|
|
1585
|
-
this.logger.debug?.("Failed to publish watch event:", err);
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1577
|
+
this.function = this.inngest.createFunction(
|
|
1578
|
+
{
|
|
1579
|
+
id: `workflow.${this.id}`,
|
|
1580
|
+
retries: 0,
|
|
1581
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
1582
|
+
triggers: { event: `workflow.${this.id}` },
|
|
1583
|
+
...this.flowControlConfig
|
|
1584
|
+
},
|
|
1585
|
+
/**
|
|
1586
|
+
* Executes a workflow invocation from its Inngest trigger event.
|
|
1587
|
+
*
|
|
1588
|
+
* @param context - The Inngest event, durable step tools, and current attempt.
|
|
1589
|
+
* @returns The workflow result and run identifier returned to Inngest.
|
|
1590
|
+
*/
|
|
1591
|
+
async ({ event, step, attempt }) => {
|
|
1592
|
+
let { inputData, initialState, runId, resourceId, resume, outputOptions, format, timeTravel, perStep, tracingOptions, actor, nestedWorkflowOutputMode: requestedNestedWorkflowOutputMode } = event.data;
|
|
1593
|
+
const shouldCompactNestedWorkflowOutput = resolveNestedWorkflowOutputMode(requestedNestedWorkflowOutputMode) === NESTED_WORKFLOW_OUTPUT_MODE.COMPACT;
|
|
1594
|
+
if (!runId) runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
1595
|
+
return (0, crypto$1.randomUUID)();
|
|
1588
1596
|
});
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1597
|
+
const defaultPubsub = new InngestPubSub(this.inngest, this.id);
|
|
1598
|
+
const pubsub = this.#pubsubFactory?.(defaultPubsub) ?? defaultPubsub;
|
|
1599
|
+
const requestContext = new _mastra_core_di.RequestContext(Object.entries(event.data.requestContext ?? {}));
|
|
1600
|
+
const mastra = this.#mastra;
|
|
1601
|
+
const tracingPolicy = this.options.tracingPolicy;
|
|
1602
|
+
const workflowSpanData = await step.run(`workflow.${this.id}.span.start`, async () => {
|
|
1603
|
+
const observability = mastra?.observability?.getSelectedInstance({ requestContext });
|
|
1604
|
+
if (!observability) return void 0;
|
|
1605
|
+
return observability.startSpan({
|
|
1606
|
+
type: _mastra_core_observability.SpanType.WORKFLOW_RUN,
|
|
1607
|
+
name: `workflow run: '${this.id}'`,
|
|
1608
|
+
entityType: _mastra_core_observability.EntityType.WORKFLOW_RUN,
|
|
1609
|
+
entityId: this.id,
|
|
1610
|
+
entityName: this.id,
|
|
1611
|
+
input: inputData,
|
|
1612
|
+
metadata: {
|
|
1613
|
+
resourceId,
|
|
1614
|
+
runId
|
|
1615
|
+
},
|
|
1616
|
+
tracingPolicy,
|
|
1617
|
+
tracingOptions,
|
|
1618
|
+
requestContext
|
|
1619
|
+
})?.exportSpan();
|
|
1620
|
+
});
|
|
1621
|
+
const engine = new InngestExecutionEngine(this.#mastra, step, attempt, this.options);
|
|
1622
|
+
let result;
|
|
1623
|
+
try {
|
|
1624
|
+
result = await engine.execute({
|
|
1616
1625
|
workflowId: this.id,
|
|
1626
|
+
runId,
|
|
1617
1627
|
resourceId,
|
|
1628
|
+
graph: this.executionGraph,
|
|
1629
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
1618
1630
|
input: inputData,
|
|
1631
|
+
initialState,
|
|
1632
|
+
pubsub,
|
|
1633
|
+
retryConfig: this.retryConfig,
|
|
1619
1634
|
requestContext,
|
|
1620
|
-
|
|
1635
|
+
actor,
|
|
1636
|
+
resume,
|
|
1637
|
+
timeTravel,
|
|
1638
|
+
perStep,
|
|
1639
|
+
format,
|
|
1640
|
+
abortController: new AbortController(),
|
|
1641
|
+
workflowSpan: void 0,
|
|
1642
|
+
tracingIds: workflowSpanData ? {
|
|
1643
|
+
traceId: workflowSpanData.traceId,
|
|
1644
|
+
workflowSpanId: workflowSpanData.id
|
|
1645
|
+
} : void 0,
|
|
1646
|
+
outputOptions,
|
|
1647
|
+
outputWriter: async (chunk) => {
|
|
1648
|
+
try {
|
|
1649
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
1650
|
+
type: "watch",
|
|
1651
|
+
runId,
|
|
1652
|
+
data: chunk
|
|
1653
|
+
});
|
|
1654
|
+
} catch (err) {
|
|
1655
|
+
this.logger.debug?.("Failed to publish watch event:", err);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1621
1658
|
});
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1659
|
+
} catch (executionError) {
|
|
1660
|
+
result = {
|
|
1661
|
+
status: "failed",
|
|
1662
|
+
steps: {},
|
|
1663
|
+
state: initialState ?? {},
|
|
1664
|
+
error: executionError instanceof Error ? executionError : new Error(String(executionError))
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
const returnedResult = shouldCompactNestedWorkflowOutput ? compactNestedWorkflowResult(result) : result;
|
|
1668
|
+
let finalizeError;
|
|
1669
|
+
let finalizeErrored = false;
|
|
1670
|
+
try {
|
|
1671
|
+
/**
|
|
1672
|
+
* Finalizes workflow lifecycle reporting in a memoized Inngest step.
|
|
1673
|
+
*
|
|
1674
|
+
* @returns The workflow result, or only its status for compact nested invocations.
|
|
1675
|
+
*/
|
|
1676
|
+
const finalizeWorkflow = async () => {
|
|
1677
|
+
if (result.status === "failed" && inputData?.__workflowKind === "durable-agent" && inputData?.runId) {
|
|
1678
|
+
const error = result.error instanceof Error ? result.error : new Error(String(result.error));
|
|
1679
|
+
try {
|
|
1680
|
+
await (0, _mastra_core_agent_durable.emitErrorEvent)(pubsub, inputData.runId, error);
|
|
1681
|
+
} catch (e) {
|
|
1682
|
+
this.logger.debug?.("Failed to emit error event:", e);
|
|
1683
|
+
}
|
|
1634
1684
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1685
|
+
if (result.status !== "paused") await engine.invokeLifecycleCallbacksInternal({
|
|
1686
|
+
status: result.status,
|
|
1687
|
+
result: "result" in result ? result.result : void 0,
|
|
1688
|
+
error: "error" in result ? result.error : void 0,
|
|
1689
|
+
steps: result.steps,
|
|
1690
|
+
tripwire: "tripwire" in result ? result.tripwire : void 0,
|
|
1691
|
+
runId,
|
|
1692
|
+
workflowId: this.id,
|
|
1693
|
+
resourceId,
|
|
1694
|
+
input: inputData,
|
|
1695
|
+
requestContext,
|
|
1696
|
+
state: result.state ?? initialState ?? {}
|
|
1697
|
+
});
|
|
1698
|
+
if (workflowSpanData) {
|
|
1699
|
+
const observability = mastra?.observability?.getSelectedInstance({ requestContext });
|
|
1700
|
+
if (observability) {
|
|
1701
|
+
const workflowSpan = observability.rebuildSpan(workflowSpanData);
|
|
1702
|
+
if (result.status === "failed") workflowSpan.error({
|
|
1703
|
+
error: result.error instanceof Error ? result.error : new Error(String(result.error)),
|
|
1704
|
+
attributes: { status: "failed" }
|
|
1705
|
+
});
|
|
1706
|
+
else workflowSpan.end({
|
|
1707
|
+
output: result.status === "success" ? result.result : void 0,
|
|
1708
|
+
attributes: { status: result.status }
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
if (this.options.shouldPersistSnapshot({
|
|
1713
|
+
workflowStatus: result.status,
|
|
1714
|
+
stepResults: result.steps
|
|
1715
|
+
})) {
|
|
1716
|
+
const workflowsStore = await mastra?.getStorage()?.getStore("workflows");
|
|
1717
|
+
if (workflowsStore) {
|
|
1718
|
+
let existingSnapshot;
|
|
1719
|
+
if (result.status === "suspended") existingSnapshot = await workflowsStore.loadWorkflowSnapshot({
|
|
1720
|
+
workflowName: this.id,
|
|
1721
|
+
runId
|
|
1722
|
+
}) ?? void 0;
|
|
1723
|
+
await workflowsStore.persistWorkflowSnapshot({
|
|
1724
|
+
workflowName: this.id,
|
|
1652
1725
|
runId,
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1726
|
+
resourceId,
|
|
1727
|
+
snapshot: {
|
|
1728
|
+
runId,
|
|
1729
|
+
status: result.status,
|
|
1730
|
+
value: result.state ?? initialState ?? {},
|
|
1731
|
+
context: toSnapshotContext(result.steps),
|
|
1732
|
+
activePaths: [],
|
|
1733
|
+
activeStepsPath: {},
|
|
1734
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
1735
|
+
suspendedPaths: existingSnapshot?.suspendedPaths ?? {},
|
|
1736
|
+
waitingPaths: {},
|
|
1737
|
+
resumeLabels: existingSnapshot?.resumeLabels ?? result.resumeLabels ?? {},
|
|
1738
|
+
result: result.status === "success" ? toSnapshotResult(result.result) : void 0,
|
|
1739
|
+
error: result.status === "failed" ? result.error : void 0,
|
|
1740
|
+
timestamp: Date.now()
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
try {
|
|
1746
|
+
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
1747
|
+
type: "watch",
|
|
1748
|
+
runId,
|
|
1749
|
+
data: {
|
|
1750
|
+
type: "workflow-finish",
|
|
1751
|
+
payload: {
|
|
1752
|
+
status: result.status,
|
|
1753
|
+
result: result.status === "success" ? result.result : void 0,
|
|
1754
|
+
error: result.status === "failed" ? result.error : void 0
|
|
1755
|
+
}
|
|
1665
1756
|
}
|
|
1666
1757
|
});
|
|
1758
|
+
} catch (publishError) {
|
|
1759
|
+
this.logger.debug?.("Failed to publish workflow-finish event:", publishError);
|
|
1667
1760
|
}
|
|
1761
|
+
if (result.status === "failed") throw new inngest.NonRetriableError(`Workflow failed`, { cause: shouldCompactNestedWorkflowOutput ? {
|
|
1762
|
+
...returnedResult,
|
|
1763
|
+
runId
|
|
1764
|
+
} : result });
|
|
1765
|
+
return shouldCompactNestedWorkflowOutput ? { status: result.status } : result;
|
|
1766
|
+
};
|
|
1767
|
+
await step.run(`workflow.${this.id}.finalize`, finalizeWorkflow);
|
|
1768
|
+
} catch (error) {
|
|
1769
|
+
finalizeErrored = true;
|
|
1770
|
+
finalizeError = error;
|
|
1771
|
+
} finally {
|
|
1772
|
+
const observability = mastra?.observability?.getSelectedInstance({ requestContext });
|
|
1773
|
+
if (observability) try {
|
|
1774
|
+
await observability.flush();
|
|
1775
|
+
} catch (flushError) {
|
|
1776
|
+
this.logger.debug?.("Failed to flush observability:", flushError);
|
|
1668
1777
|
}
|
|
1669
|
-
try {
|
|
1670
|
-
await pubsub.publish(`workflow.events.v2.${runId}`, {
|
|
1671
|
-
type: "watch",
|
|
1672
|
-
runId,
|
|
1673
|
-
data: {
|
|
1674
|
-
type: "workflow-finish",
|
|
1675
|
-
payload: {
|
|
1676
|
-
status: result.status,
|
|
1677
|
-
result: result.status === "success" ? result.result : void 0,
|
|
1678
|
-
error: result.status === "failed" ? result.error : void 0
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
});
|
|
1682
|
-
} catch (publishError) {
|
|
1683
|
-
this.logger.debug?.("Failed to publish workflow-finish event:", publishError);
|
|
1684
|
-
}
|
|
1685
|
-
if (result.status === "failed") throw new inngest.NonRetriableError(`Workflow failed`, { cause: result });
|
|
1686
|
-
return result;
|
|
1687
|
-
});
|
|
1688
|
-
} catch (error) {
|
|
1689
|
-
finalizeErrored = true;
|
|
1690
|
-
finalizeError = error;
|
|
1691
|
-
} finally {
|
|
1692
|
-
const observability = mastra?.observability?.getSelectedInstance({ requestContext });
|
|
1693
|
-
if (observability) try {
|
|
1694
|
-
await observability.flush();
|
|
1695
|
-
} catch (flushError) {
|
|
1696
|
-
this.logger.debug?.("Failed to flush observability:", flushError);
|
|
1697
1778
|
}
|
|
1779
|
+
if (finalizeErrored) throw finalizeError;
|
|
1780
|
+
return {
|
|
1781
|
+
result: returnedResult,
|
|
1782
|
+
runId
|
|
1783
|
+
};
|
|
1698
1784
|
}
|
|
1699
|
-
|
|
1700
|
-
return {
|
|
1701
|
-
result,
|
|
1702
|
-
runId
|
|
1703
|
-
};
|
|
1704
|
-
});
|
|
1785
|
+
);
|
|
1705
1786
|
return this.function;
|
|
1706
1787
|
}
|
|
1707
1788
|
getNestedFunctions(steps) {
|
|
@@ -1824,4 +1905,4 @@ Object.defineProperty(exports, "connect", {
|
|
|
1824
1905
|
}
|
|
1825
1906
|
});
|
|
1826
1907
|
|
|
1827
|
-
//# sourceMappingURL=connect-
|
|
1908
|
+
//# sourceMappingURL=connect-0KhA4iVJ.cjs.map
|