@mastra/inngest 1.0.0-beta.10 → 1.0.0-beta.11
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 +106 -0
- package/dist/execution-engine.d.ts +1 -3
- package/dist/execution-engine.d.ts.map +1 -1
- package/dist/index.cjs +92 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +93 -79
- package/dist/index.js.map +1 -1
- package/dist/run.d.ts +0 -13
- package/dist/run.d.ts.map +1 -1
- package/dist/types.d.ts +7 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/workflow.d.ts +4 -2
- package/dist/workflow.d.ts.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,111 @@
|
|
|
1
1
|
# @mastra/inngest
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add support for `retries` and `scorers` parameters across all `createStep` overloads.
|
|
8
|
+
([#11495](https://github.com/mastra-ai/mastra/pull/11495))
|
|
9
|
+
|
|
10
|
+
The `createStep` function now includes support for the `retries` and `scorers` fields across all step creation patterns, enabling step-level retry configuration and AI evaluation support for regular steps, agent-based steps, and tool-based steps.
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { init } from '@mastra/inngest';
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
|
|
16
|
+
const { createStep } = init(inngest);
|
|
17
|
+
|
|
18
|
+
// 1. Regular step with retries
|
|
19
|
+
const regularStep = createStep({
|
|
20
|
+
id: 'api-call',
|
|
21
|
+
inputSchema: z.object({ url: z.string() }),
|
|
22
|
+
outputSchema: z.object({ data: z.any() }),
|
|
23
|
+
retries: 3, // ← Will retry up to 3 times on failure
|
|
24
|
+
execute: async ({ inputData }) => {
|
|
25
|
+
const response = await fetch(inputData.url);
|
|
26
|
+
return { data: await response.json() };
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// 2. Agent step with retries and scorers
|
|
31
|
+
const agentStep = createStep(myAgent, {
|
|
32
|
+
retries: 3,
|
|
33
|
+
scorers: [{ id: 'accuracy-scorer', scorer: myAccuracyScorer }],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 3. Tool step with retries and scorers
|
|
37
|
+
const toolStep = createStep(myTool, {
|
|
38
|
+
retries: 2,
|
|
39
|
+
scorers: [{ id: 'quality-scorer', scorer: myQualityScorer }],
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
This change ensures API consistency across all `createStep` overloads. All step types now support retry and evaluation configurations.
|
|
44
|
+
|
|
45
|
+
This is a non-breaking change - steps without these parameters continue to work exactly as before.
|
|
46
|
+
|
|
47
|
+
Fixes #9351
|
|
48
|
+
|
|
49
|
+
- Remove `streamVNext`, `resumeStreamVNext`, and `observeStreamVNext` methods, call `stream`, `resumeStream` and `observeStream` directly ([#11499](https://github.com/mastra-ai/mastra/pull/11499))
|
|
50
|
+
|
|
51
|
+
```diff
|
|
52
|
+
+ const run = await workflow.createRun({ runId: '123' });
|
|
53
|
+
- const stream = await run.streamVNext({ inputData: { ... } });
|
|
54
|
+
+ const stream = await run.stream({ inputData: { ... } });
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- Unified `getWorkflowRunById` and `getWorkflowRunExecutionResult` into a single API that returns `WorkflowState` with both metadata and execution state. ([#11429](https://github.com/mastra-ai/mastra/pull/11429))
|
|
58
|
+
|
|
59
|
+
**What changed:**
|
|
60
|
+
- `getWorkflowRunById` now returns a unified `WorkflowState` object containing metadata (runId, workflowName, resourceId, createdAt, updatedAt) along with processed execution state (status, result, error, payload, steps)
|
|
61
|
+
- Added optional `fields` parameter to request only specific fields for better performance
|
|
62
|
+
- Added optional `withNestedWorkflows` parameter to control nested workflow step inclusion
|
|
63
|
+
- Removed `getWorkflowRunExecutionResult` - use `getWorkflowRunById` instead (breaking change)
|
|
64
|
+
- Removed `/execution-result` API endpoints from server (breaking change)
|
|
65
|
+
- Removed `runExecutionResult()` method from client SDK (breaking change)
|
|
66
|
+
- Removed `GetWorkflowRunExecutionResultResponse` type from client SDK (breaking change)
|
|
67
|
+
|
|
68
|
+
**Before:**
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// Had to call two different methods for different data
|
|
72
|
+
const run = await workflow.getWorkflowRunById(runId); // Returns raw WorkflowRun with snapshot
|
|
73
|
+
const result = await workflow.getWorkflowRunExecutionResult(runId); // Returns processed execution state
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**After:**
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// Single method returns everything
|
|
80
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
81
|
+
// Returns: { runId, workflowName, resourceId, createdAt, updatedAt, status, result, error, payload, steps }
|
|
82
|
+
|
|
83
|
+
// Request only specific fields for better performance (avoids expensive step fetching)
|
|
84
|
+
const status = await workflow.getWorkflowRunById(runId, { fields: ['status'] });
|
|
85
|
+
|
|
86
|
+
// Skip nested workflow steps for faster response
|
|
87
|
+
const run = await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Why:** The previous API required calling two separate methods to get complete workflow run information. This unification simplifies the API surface and gives users control over performance - fetching all steps (especially nested workflows) can be expensive, so the `fields` and `withNestedWorkflows` options let users request only what they need.
|
|
91
|
+
|
|
92
|
+
- Add cron scheduling support to Inngest workflows. Workflows can now be automatically triggered on a schedule by adding a `cron` property along with optional `inputData` and `initialState`: ([#11518](https://github.com/mastra-ai/mastra/pull/11518))
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
const workflow = createWorkflow({
|
|
96
|
+
id: 'scheduled-workflow',
|
|
97
|
+
inputSchema: z.object({ value: z.string() }),
|
|
98
|
+
outputSchema: z.object({ result: z.string() }),
|
|
99
|
+
steps: [step1],
|
|
100
|
+
cron: '0 0 * * *', // Run daily at midnight
|
|
101
|
+
inputData: { value: 'scheduled-run' }, // Optional inputData for the scheduled workflow run
|
|
102
|
+
initialState: { count: 0 }, // Optional initialState for the scheduled workflow run
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- Updated dependencies [[`d2d3e22`](https://github.com/mastra-ai/mastra/commit/d2d3e22a419ee243f8812a84e3453dd44365ecb0), [`bc72b52`](https://github.com/mastra-ai/mastra/commit/bc72b529ee4478fe89ecd85a8be47ce0127b82a0), [`05b8bee`](https://github.com/mastra-ai/mastra/commit/05b8bee9e50e6c2a4a2bf210eca25ee212ca24fa), [`c042bd0`](https://github.com/mastra-ai/mastra/commit/c042bd0b743e0e86199d0cb83344ca7690e34a9c), [`940a2b2`](https://github.com/mastra-ai/mastra/commit/940a2b27480626ed7e74f55806dcd2181c1dd0c2), [`e0941c3`](https://github.com/mastra-ai/mastra/commit/e0941c3d7fc75695d5d258e7008fd5d6e650800c), [`0c0580a`](https://github.com/mastra-ai/mastra/commit/0c0580a42f697cd2a7d5973f25bfe7da9055038a), [`28f5f89`](https://github.com/mastra-ai/mastra/commit/28f5f89705f2409921e3c45178796c0e0d0bbb64), [`e601b27`](https://github.com/mastra-ai/mastra/commit/e601b272c70f3a5ecca610373aa6223012704892), [`3d3366f`](https://github.com/mastra-ai/mastra/commit/3d3366f31683e7137d126a3a57174a222c5801fb), [`5a4953f`](https://github.com/mastra-ai/mastra/commit/5a4953f7d25bb15ca31ed16038092a39cb3f98b3), [`eb9e522`](https://github.com/mastra-ai/mastra/commit/eb9e522ce3070a405e5b949b7bf5609ca51d7fe2), [`20e6f19`](https://github.com/mastra-ai/mastra/commit/20e6f1971d51d3ff6dd7accad8aaaae826d540ed), [`4f0b3c6`](https://github.com/mastra-ai/mastra/commit/4f0b3c66f196c06448487f680ccbb614d281e2f7), [`74c4f22`](https://github.com/mastra-ai/mastra/commit/74c4f22ed4c71e72598eacc346ba95cdbc00294f), [`81b6a8f`](https://github.com/mastra-ai/mastra/commit/81b6a8ff79f49a7549d15d66624ac1a0b8f5f971), [`e4d366a`](https://github.com/mastra-ai/mastra/commit/e4d366aeb500371dd4210d6aa8361a4c21d87034), [`a4f010b`](https://github.com/mastra-ai/mastra/commit/a4f010b22e4355a5fdee70a1fe0f6e4a692cc29e), [`73b0bb3`](https://github.com/mastra-ai/mastra/commit/73b0bb394dba7c9482eb467a97ab283dbc0ef4db), [`5627a8c`](https://github.com/mastra-ai/mastra/commit/5627a8c6dc11fe3711b3fa7a6ffd6eb34100a306), [`3ff45d1`](https://github.com/mastra-ai/mastra/commit/3ff45d10e0c80c5335a957ab563da72feb623520), [`251df45`](https://github.com/mastra-ai/mastra/commit/251df4531407dfa46d805feb40ff3fb49769f455), [`f894d14`](https://github.com/mastra-ai/mastra/commit/f894d148946629af7b1f452d65a9cf864cec3765), [`c2b9547`](https://github.com/mastra-ai/mastra/commit/c2b9547bf435f56339f23625a743b2147ab1c7a6), [`580b592`](https://github.com/mastra-ai/mastra/commit/580b5927afc82fe460dfdf9a38a902511b6b7e7f), [`58e3931`](https://github.com/mastra-ai/mastra/commit/58e3931af9baa5921688566210f00fb0c10479fa), [`08bb631`](https://github.com/mastra-ai/mastra/commit/08bb631ae2b14684b2678e3549d0b399a6f0561e), [`4fba91b`](https://github.com/mastra-ai/mastra/commit/4fba91bec7c95911dc28e369437596b152b04cd0), [`12b0cc4`](https://github.com/mastra-ai/mastra/commit/12b0cc4077d886b1a552637dedb70a7ade93528c)]:
|
|
107
|
+
- @mastra/core@1.0.0-beta.20
|
|
108
|
+
|
|
3
109
|
## 1.0.0-beta.10
|
|
4
110
|
|
|
5
111
|
### Minor Changes
|
|
@@ -58,9 +58,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
58
58
|
* If retryConfig is provided, throws RetryAfterError INSIDE step.run() to trigger
|
|
59
59
|
* Inngest's step-level retry mechanism (not function-level retry).
|
|
60
60
|
*/
|
|
61
|
-
wrapDurableOperation<T>(operationId: string, operationFn: () => Promise<T
|
|
62
|
-
delay: number;
|
|
63
|
-
}): Promise<T>;
|
|
61
|
+
wrapDurableOperation<T>(operationId: string, operationFn: () => Promise<T>): Promise<T>;
|
|
64
62
|
/**
|
|
65
63
|
* Provide Inngest step primitive in engine context
|
|
66
64
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-engine.d.ts","sourceRoot":"","sources":["../src/execution-engine.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAmC,MAAM,wBAAwB,CAAC;AACjG,OAAO,KAAK,EACV,gBAAgB,EAChB,IAAI,EACJ,UAAU,EAEV,sBAAsB,EACtB,yBAAyB,EAE1B,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"execution-engine.d.ts","sourceRoot":"","sources":["../src/execution-engine.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAmC,MAAM,wBAAwB,CAAC;AACjG,OAAO,KAAK,EACV,gBAAgB,EAChB,IAAI,EACJ,UAAU,EAEV,sBAAsB,EACtB,yBAAyB,EAE1B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGpD,qBAAa,sBAAuB,SAAQ,sBAAsB;IAChE,OAAO,CAAC,WAAW,C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CAAC,EAAE,MAAM,CAAC;SAChB,CAAC;QACF,UAAU,CAAC,EAAE,yBAAyB,CAAC;QACvC,UAAU,EAAE,GAAG,CAAC;QAChB,SAAS,EAAE,GAAG,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;CA6QnD"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var agent = require('@mastra/core/agent');
|
|
3
4
|
var tools = require('@mastra/core/tools');
|
|
4
5
|
var workflows = require('@mastra/core/workflows');
|
|
5
6
|
var _constants = require('@mastra/core/workflows/_constants');
|
|
@@ -60,38 +61,46 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
60
61
|
* After retries exhausted, error propagates here and we return a failed result.
|
|
61
62
|
*/
|
|
62
63
|
async executeStepWithRetry(stepId, runStep, params) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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 });
|
|
75
|
-
}
|
|
76
|
-
return { ok: false, error: cause };
|
|
64
|
+
for (let i = 0; i < params.retries + 1; i++) {
|
|
65
|
+
if (i > 0 && params.delay) {
|
|
66
|
+
await new Promise((resolve) => setTimeout(resolve, params.delay));
|
|
77
67
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
68
|
+
try {
|
|
69
|
+
const result = await this.wrapDurableOperation(stepId, runStep);
|
|
70
|
+
return { ok: true, result };
|
|
71
|
+
} catch (e) {
|
|
72
|
+
if (i === params.retries) {
|
|
73
|
+
const cause = e?.cause;
|
|
74
|
+
if (cause?.status === "failed") {
|
|
75
|
+
params.stepSpan?.error({
|
|
76
|
+
error: e,
|
|
77
|
+
attributes: { status: "failed" }
|
|
78
|
+
});
|
|
79
|
+
if (cause.error && !(cause.error instanceof Error)) {
|
|
80
|
+
cause.error = error.getErrorFromUnknown(cause.error, { serializeStack: false });
|
|
81
|
+
}
|
|
82
|
+
return { ok: false, error: cause };
|
|
83
|
+
}
|
|
84
|
+
const errorInstance = error.getErrorFromUnknown(e, {
|
|
85
|
+
serializeStack: false,
|
|
86
|
+
fallbackMessage: "Unknown step execution error"
|
|
87
|
+
});
|
|
88
|
+
params.stepSpan?.error({
|
|
89
|
+
error: errorInstance,
|
|
90
|
+
attributes: { status: "failed" }
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
ok: false,
|
|
94
|
+
error: {
|
|
95
|
+
status: "failed",
|
|
96
|
+
error: errorInstance,
|
|
97
|
+
endedAt: Date.now()
|
|
98
|
+
}
|
|
99
|
+
};
|
|
92
100
|
}
|
|
93
|
-
}
|
|
101
|
+
}
|
|
94
102
|
}
|
|
103
|
+
return { ok: false, error: { status: "failed", error: new Error("Unknown error"), endedAt: Date.now() } };
|
|
95
104
|
}
|
|
96
105
|
/**
|
|
97
106
|
* Use Inngest's sleep primitive for durability
|
|
@@ -110,24 +119,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
110
119
|
* If retryConfig is provided, throws RetryAfterError INSIDE step.run() to trigger
|
|
111
120
|
* Inngest's step-level retry mechanism (not function-level retry).
|
|
112
121
|
*/
|
|
113
|
-
async wrapDurableOperation(operationId, operationFn
|
|
122
|
+
async wrapDurableOperation(operationId, operationFn) {
|
|
114
123
|
return this.inngestStep.run(operationId, async () => {
|
|
115
124
|
try {
|
|
116
125
|
return await operationFn();
|
|
117
126
|
} 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
127
|
throw e;
|
|
132
128
|
}
|
|
133
129
|
});
|
|
@@ -1039,9 +1035,6 @@ var InngestRun = class extends workflows.Run {
|
|
|
1039
1035
|
});
|
|
1040
1036
|
return this.streamOutput;
|
|
1041
1037
|
}
|
|
1042
|
-
streamVNext(args = {}) {
|
|
1043
|
-
return this.stream(args);
|
|
1044
|
-
}
|
|
1045
1038
|
timeTravelStream({
|
|
1046
1039
|
inputData,
|
|
1047
1040
|
resumeData,
|
|
@@ -1132,9 +1125,11 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1132
1125
|
#mastra;
|
|
1133
1126
|
inngest;
|
|
1134
1127
|
function;
|
|
1128
|
+
cronFunction;
|
|
1135
1129
|
flowControlConfig;
|
|
1130
|
+
cronConfig;
|
|
1136
1131
|
constructor(params, inngest) {
|
|
1137
|
-
const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
|
|
1132
|
+
const { concurrency, rateLimit, throttle, debounce, priority, cron, inputData, initialState, ...workflowParams } = params;
|
|
1138
1133
|
super(workflowParams);
|
|
1139
1134
|
this.engineType = "inngest";
|
|
1140
1135
|
const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
|
|
@@ -1143,6 +1138,9 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1143
1138
|
this.flowControlConfig = flowControlEntries.length > 0 ? Object.fromEntries(flowControlEntries) : void 0;
|
|
1144
1139
|
this.#mastra = params.mastra;
|
|
1145
1140
|
this.inngest = inngest;
|
|
1141
|
+
if (cron) {
|
|
1142
|
+
this.cronConfig = { cron, inputData, initialState };
|
|
1143
|
+
}
|
|
1146
1144
|
}
|
|
1147
1145
|
async listWorkflowRuns(args) {
|
|
1148
1146
|
const storage = this.#mastra?.getStorage();
|
|
@@ -1156,19 +1154,6 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1156
1154
|
}
|
|
1157
1155
|
return workflowsStore.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
1158
1156
|
}
|
|
1159
|
-
async getWorkflowRunById(runId) {
|
|
1160
|
-
const storage = this.#mastra?.getStorage();
|
|
1161
|
-
if (!storage) {
|
|
1162
|
-
this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
|
|
1163
|
-
return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
|
|
1164
|
-
}
|
|
1165
|
-
const workflowsStore = await storage.getStore("workflows");
|
|
1166
|
-
if (!workflowsStore) {
|
|
1167
|
-
return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
|
|
1168
|
-
}
|
|
1169
|
-
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
|
|
1170
|
-
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
1171
|
-
}
|
|
1172
1157
|
__registerMastra(mastra) {
|
|
1173
1158
|
super.__registerMastra(mastra);
|
|
1174
1159
|
this.#mastra = mastra;
|
|
@@ -1212,10 +1197,11 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1212
1197
|
workflowStatus: run.workflowRunStatus,
|
|
1213
1198
|
stepResults: {}
|
|
1214
1199
|
});
|
|
1215
|
-
const
|
|
1200
|
+
const existingRun = await this.getWorkflowRunById(runIdToUse, {
|
|
1216
1201
|
withNestedWorkflows: false
|
|
1217
1202
|
});
|
|
1218
|
-
|
|
1203
|
+
const existsInStorage = existingRun && !existingRun.isFromInMemory;
|
|
1204
|
+
if (!existsInStorage && shouldPersistSnapshot) {
|
|
1219
1205
|
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
1220
1206
|
await workflowsStore?.persistWorkflowSnapshot({
|
|
1221
1207
|
workflowName: this.id,
|
|
@@ -1240,6 +1226,30 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1240
1226
|
}
|
|
1241
1227
|
return run;
|
|
1242
1228
|
}
|
|
1229
|
+
//createCronFunction is only called if cronConfig.cron is defined.
|
|
1230
|
+
createCronFunction() {
|
|
1231
|
+
if (this.cronFunction) {
|
|
1232
|
+
return this.cronFunction;
|
|
1233
|
+
}
|
|
1234
|
+
this.cronFunction = this.inngest.createFunction(
|
|
1235
|
+
{
|
|
1236
|
+
id: `workflow.${this.id}.cron`,
|
|
1237
|
+
retries: 0,
|
|
1238
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
1239
|
+
...this.flowControlConfig
|
|
1240
|
+
},
|
|
1241
|
+
{ cron: this.cronConfig?.cron ?? "" },
|
|
1242
|
+
async () => {
|
|
1243
|
+
const run = await this.createRun();
|
|
1244
|
+
const result = await run.start({
|
|
1245
|
+
inputData: this.cronConfig?.inputData,
|
|
1246
|
+
initialState: this.cronConfig?.initialState
|
|
1247
|
+
});
|
|
1248
|
+
return { result, runId: run.runId };
|
|
1249
|
+
}
|
|
1250
|
+
);
|
|
1251
|
+
return this.cronFunction;
|
|
1252
|
+
}
|
|
1243
1253
|
getFunction() {
|
|
1244
1254
|
if (this.function) {
|
|
1245
1255
|
return this.function;
|
|
@@ -1247,7 +1257,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1247
1257
|
this.function = this.inngest.createFunction(
|
|
1248
1258
|
{
|
|
1249
1259
|
id: `workflow.${this.id}`,
|
|
1250
|
-
retries:
|
|
1260
|
+
retries: 0,
|
|
1251
1261
|
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
1252
1262
|
// Spread flow control configuration
|
|
1253
1263
|
...this.flowControlConfig
|
|
@@ -1322,7 +1332,11 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1322
1332
|
});
|
|
1323
1333
|
}
|
|
1324
1334
|
getFunctions() {
|
|
1325
|
-
return [
|
|
1335
|
+
return [
|
|
1336
|
+
this.getFunction(),
|
|
1337
|
+
...this.cronConfig?.cron ? [this.createCronFunction()] : [],
|
|
1338
|
+
...this.getNestedFunctions(this.executionGraph.steps)
|
|
1339
|
+
];
|
|
1326
1340
|
}
|
|
1327
1341
|
};
|
|
1328
1342
|
function serve({
|
|
@@ -1354,21 +1368,14 @@ function serve({
|
|
|
1354
1368
|
var _compatibilityCheck = true;
|
|
1355
1369
|
|
|
1356
1370
|
// src/index.ts
|
|
1357
|
-
function
|
|
1358
|
-
|
|
1359
|
-
}
|
|
1360
|
-
function isTool(params) {
|
|
1361
|
-
return params instanceof tools.Tool;
|
|
1362
|
-
}
|
|
1363
|
-
function isInngestWorkflow(params) {
|
|
1364
|
-
return params instanceof InngestWorkflow;
|
|
1365
|
-
}
|
|
1366
|
-
function createStep(params, agentOptions) {
|
|
1367
|
-
if (isInngestWorkflow(params)) {
|
|
1371
|
+
function createStep(params, agentOrToolOptions) {
|
|
1372
|
+
if (params instanceof InngestWorkflow) {
|
|
1368
1373
|
return params;
|
|
1369
1374
|
}
|
|
1370
|
-
if (
|
|
1371
|
-
const
|
|
1375
|
+
if (params instanceof agent.Agent) {
|
|
1376
|
+
const options = agentOrToolOptions;
|
|
1377
|
+
const outputSchema = options?.structuredOutput?.schema ?? zod.z.object({ text: zod.z.string() });
|
|
1378
|
+
const { retries, scorers, ...agentOptions } = options ?? {};
|
|
1372
1379
|
return {
|
|
1373
1380
|
id: params.name,
|
|
1374
1381
|
description: params.getDescription(),
|
|
@@ -1378,6 +1385,8 @@ function createStep(params, agentOptions) {
|
|
|
1378
1385
|
// threadId: z.string().optional(),
|
|
1379
1386
|
}),
|
|
1380
1387
|
outputSchema,
|
|
1388
|
+
retries,
|
|
1389
|
+
scorers,
|
|
1381
1390
|
execute: async ({
|
|
1382
1391
|
inputData,
|
|
1383
1392
|
runId,
|
|
@@ -1473,7 +1482,8 @@ function createStep(params, agentOptions) {
|
|
|
1473
1482
|
component: params.component
|
|
1474
1483
|
};
|
|
1475
1484
|
}
|
|
1476
|
-
if (
|
|
1485
|
+
if (params instanceof tools.Tool) {
|
|
1486
|
+
const toolOpts = agentOrToolOptions;
|
|
1477
1487
|
if (!params.inputSchema || !params.outputSchema) {
|
|
1478
1488
|
throw new Error("Tool must have input and output schemas defined");
|
|
1479
1489
|
}
|
|
@@ -1485,6 +1495,8 @@ function createStep(params, agentOptions) {
|
|
|
1485
1495
|
outputSchema: params.outputSchema,
|
|
1486
1496
|
suspendSchema: params.suspendSchema,
|
|
1487
1497
|
resumeSchema: params.resumeSchema,
|
|
1498
|
+
retries: toolOpts?.retries,
|
|
1499
|
+
scorers: toolOpts?.scorers,
|
|
1488
1500
|
execute: async ({
|
|
1489
1501
|
inputData,
|
|
1490
1502
|
mastra,
|
|
@@ -1522,6 +1534,8 @@ function createStep(params, agentOptions) {
|
|
|
1522
1534
|
outputSchema: params.outputSchema,
|
|
1523
1535
|
resumeSchema: params.resumeSchema,
|
|
1524
1536
|
suspendSchema: params.suspendSchema,
|
|
1537
|
+
retries: params.retries,
|
|
1538
|
+
scorers: params.scorers,
|
|
1525
1539
|
execute: params.execute
|
|
1526
1540
|
};
|
|
1527
1541
|
}
|