@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/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Agent } from '@mastra/core/agent';
|
|
2
|
+
import type { MastraScorers } from '@mastra/core/evals';
|
|
2
3
|
import type { ToolExecutionContext } from '@mastra/core/tools';
|
|
4
|
+
import type { DynamicArgument } from '@mastra/core/types';
|
|
3
5
|
import type { Step, AgentStepOptions, StepParams, ToolStep } from '@mastra/core/workflows';
|
|
4
6
|
import { Workflow } from '@mastra/core/workflows';
|
|
5
7
|
import type { Inngest } from 'inngest';
|
|
@@ -17,6 +19,8 @@ export declare function createStep<TStepId extends string, TStepOutput extends z
|
|
|
17
19
|
structuredOutput: {
|
|
18
20
|
schema: TStepOutput;
|
|
19
21
|
};
|
|
22
|
+
retries?: number;
|
|
23
|
+
scorers?: DynamicArgument<MastraScorers>;
|
|
20
24
|
}): Step<TStepId, any, z.ZodObject<{
|
|
21
25
|
prompt: z.ZodString;
|
|
22
26
|
}>, TStepOutput, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
@@ -24,8 +28,14 @@ export declare function createStep<TStepId extends string, TStepInput extends z.
|
|
|
24
28
|
prompt: z.ZodString;
|
|
25
29
|
}>, TStepOutput extends z.ZodObject<{
|
|
26
30
|
text: z.ZodString;
|
|
27
|
-
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any>, agentOptions?: AgentStepOptions
|
|
28
|
-
|
|
31
|
+
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any>, agentOptions?: AgentStepOptions & {
|
|
32
|
+
retries?: number;
|
|
33
|
+
scorers?: DynamicArgument<MastraScorers>;
|
|
34
|
+
}): Step<TStepId, any, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
35
|
+
export declare function createStep<TSchemaIn extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>, TResumeSchema extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>, TContext extends ToolExecutionContext<TSuspendSchema, TResumeSchema>>(tool: ToolStep<TSchemaIn, TSuspendSchema, TResumeSchema, TSchemaOut, TContext>, toolOptions?: {
|
|
36
|
+
retries?: number;
|
|
37
|
+
scorers?: DynamicArgument<MastraScorers>;
|
|
38
|
+
}): Step<string, any, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
29
39
|
export declare function init(inngest: Inngest): {
|
|
30
40
|
createWorkflow<TWorkflowId extends string = string, TState extends z.ZodObject<any> = z.ZodObject<any, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
31
41
|
[x: string]: any;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,a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E,iBAAiB,CAAC,QACzD;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,GACpB,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC;kBAgB1D,WAAW,SAAS,MAAM,WAC1B,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC;;;;QAC/B,MAAM,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,sCAC7B,OAAO,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,sCAC9B,MAAM,SAAS,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,EAAE,+DASzE,WAAW,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,qBAExB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,QACrF;QAAE,EAAE,EAAE,WAAW,CAAA;KAAE,GACxB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC;EAe5F"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Agent } from '@mastra/core/agent';
|
|
1
2
|
import { Tool } from '@mastra/core/tools';
|
|
2
3
|
import { DefaultExecutionEngine, createTimeTravelExecutionParams, Run, hydrateSerializedStepErrors, Workflow } from '@mastra/core/workflows';
|
|
3
4
|
import { PUBSUB_SYMBOL, STREAM_FORMAT_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
import { randomUUID } from 'crypto';
|
|
6
7
|
import { RequestContext } from '@mastra/core/di';
|
|
7
|
-
import {
|
|
8
|
+
import { NonRetriableError } from 'inngest';
|
|
8
9
|
import { getErrorFromUnknown } from '@mastra/core/error';
|
|
9
10
|
import { subscribe } from '@inngest/realtime';
|
|
10
11
|
import { PubSub } from '@mastra/core/events';
|
|
@@ -58,38 +59,46 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
58
59
|
* After retries exhausted, error propagates here and we return a failed result.
|
|
59
60
|
*/
|
|
60
61
|
async executeStepWithRetry(stepId, runStep, params) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} catch (e) {
|
|
65
|
-
const cause = e?.cause;
|
|
66
|
-
if (cause?.status === "failed") {
|
|
67
|
-
params.stepSpan?.error({
|
|
68
|
-
error: e,
|
|
69
|
-
attributes: { status: "failed" }
|
|
70
|
-
});
|
|
71
|
-
if (cause.error && !(cause.error instanceof Error)) {
|
|
72
|
-
cause.error = getErrorFromUnknown(cause.error, { serializeStack: false });
|
|
73
|
-
}
|
|
74
|
-
return { ok: false, error: cause };
|
|
62
|
+
for (let i = 0; i < params.retries + 1; i++) {
|
|
63
|
+
if (i > 0 && params.delay) {
|
|
64
|
+
await new Promise((resolve) => setTimeout(resolve, params.delay));
|
|
75
65
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
66
|
+
try {
|
|
67
|
+
const result = await this.wrapDurableOperation(stepId, runStep);
|
|
68
|
+
return { ok: true, result };
|
|
69
|
+
} catch (e) {
|
|
70
|
+
if (i === params.retries) {
|
|
71
|
+
const cause = e?.cause;
|
|
72
|
+
if (cause?.status === "failed") {
|
|
73
|
+
params.stepSpan?.error({
|
|
74
|
+
error: e,
|
|
75
|
+
attributes: { status: "failed" }
|
|
76
|
+
});
|
|
77
|
+
if (cause.error && !(cause.error instanceof Error)) {
|
|
78
|
+
cause.error = getErrorFromUnknown(cause.error, { serializeStack: false });
|
|
79
|
+
}
|
|
80
|
+
return { ok: false, error: cause };
|
|
81
|
+
}
|
|
82
|
+
const errorInstance = getErrorFromUnknown(e, {
|
|
83
|
+
serializeStack: false,
|
|
84
|
+
fallbackMessage: "Unknown step execution error"
|
|
85
|
+
});
|
|
86
|
+
params.stepSpan?.error({
|
|
87
|
+
error: errorInstance,
|
|
88
|
+
attributes: { status: "failed" }
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
error: {
|
|
93
|
+
status: "failed",
|
|
94
|
+
error: errorInstance,
|
|
95
|
+
endedAt: Date.now()
|
|
96
|
+
}
|
|
97
|
+
};
|
|
90
98
|
}
|
|
91
|
-
}
|
|
99
|
+
}
|
|
92
100
|
}
|
|
101
|
+
return { ok: false, error: { status: "failed", error: new Error("Unknown error"), endedAt: Date.now() } };
|
|
93
102
|
}
|
|
94
103
|
/**
|
|
95
104
|
* Use Inngest's sleep primitive for durability
|
|
@@ -108,24 +117,11 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
108
117
|
* If retryConfig is provided, throws RetryAfterError INSIDE step.run() to trigger
|
|
109
118
|
* Inngest's step-level retry mechanism (not function-level retry).
|
|
110
119
|
*/
|
|
111
|
-
async wrapDurableOperation(operationId, operationFn
|
|
120
|
+
async wrapDurableOperation(operationId, operationFn) {
|
|
112
121
|
return this.inngestStep.run(operationId, async () => {
|
|
113
122
|
try {
|
|
114
123
|
return await operationFn();
|
|
115
124
|
} catch (e) {
|
|
116
|
-
if (retryConfig) {
|
|
117
|
-
const errorInstance = getErrorFromUnknown(e, {
|
|
118
|
-
serializeStack: false,
|
|
119
|
-
fallbackMessage: "Unknown step execution error"
|
|
120
|
-
});
|
|
121
|
-
throw new RetryAfterError(errorInstance.message, retryConfig.delay, {
|
|
122
|
-
cause: {
|
|
123
|
-
status: "failed",
|
|
124
|
-
error: errorInstance,
|
|
125
|
-
endedAt: Date.now()
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
125
|
throw e;
|
|
130
126
|
}
|
|
131
127
|
});
|
|
@@ -1037,9 +1033,6 @@ var InngestRun = class extends Run {
|
|
|
1037
1033
|
});
|
|
1038
1034
|
return this.streamOutput;
|
|
1039
1035
|
}
|
|
1040
|
-
streamVNext(args = {}) {
|
|
1041
|
-
return this.stream(args);
|
|
1042
|
-
}
|
|
1043
1036
|
timeTravelStream({
|
|
1044
1037
|
inputData,
|
|
1045
1038
|
resumeData,
|
|
@@ -1130,9 +1123,11 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1130
1123
|
#mastra;
|
|
1131
1124
|
inngest;
|
|
1132
1125
|
function;
|
|
1126
|
+
cronFunction;
|
|
1133
1127
|
flowControlConfig;
|
|
1128
|
+
cronConfig;
|
|
1134
1129
|
constructor(params, inngest) {
|
|
1135
|
-
const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
|
|
1130
|
+
const { concurrency, rateLimit, throttle, debounce, priority, cron, inputData, initialState, ...workflowParams } = params;
|
|
1136
1131
|
super(workflowParams);
|
|
1137
1132
|
this.engineType = "inngest";
|
|
1138
1133
|
const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
|
|
@@ -1141,6 +1136,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1141
1136
|
this.flowControlConfig = flowControlEntries.length > 0 ? Object.fromEntries(flowControlEntries) : void 0;
|
|
1142
1137
|
this.#mastra = params.mastra;
|
|
1143
1138
|
this.inngest = inngest;
|
|
1139
|
+
if (cron) {
|
|
1140
|
+
this.cronConfig = { cron, inputData, initialState };
|
|
1141
|
+
}
|
|
1144
1142
|
}
|
|
1145
1143
|
async listWorkflowRuns(args) {
|
|
1146
1144
|
const storage = this.#mastra?.getStorage();
|
|
@@ -1154,19 +1152,6 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1154
1152
|
}
|
|
1155
1153
|
return workflowsStore.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
1156
1154
|
}
|
|
1157
|
-
async getWorkflowRunById(runId) {
|
|
1158
|
-
const storage = this.#mastra?.getStorage();
|
|
1159
|
-
if (!storage) {
|
|
1160
|
-
this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
|
|
1161
|
-
return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
|
|
1162
|
-
}
|
|
1163
|
-
const workflowsStore = await storage.getStore("workflows");
|
|
1164
|
-
if (!workflowsStore) {
|
|
1165
|
-
return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
|
|
1166
|
-
}
|
|
1167
|
-
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
|
|
1168
|
-
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
1169
|
-
}
|
|
1170
1155
|
__registerMastra(mastra) {
|
|
1171
1156
|
super.__registerMastra(mastra);
|
|
1172
1157
|
this.#mastra = mastra;
|
|
@@ -1210,10 +1195,11 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1210
1195
|
workflowStatus: run.workflowRunStatus,
|
|
1211
1196
|
stepResults: {}
|
|
1212
1197
|
});
|
|
1213
|
-
const
|
|
1198
|
+
const existingRun = await this.getWorkflowRunById(runIdToUse, {
|
|
1214
1199
|
withNestedWorkflows: false
|
|
1215
1200
|
});
|
|
1216
|
-
|
|
1201
|
+
const existsInStorage = existingRun && !existingRun.isFromInMemory;
|
|
1202
|
+
if (!existsInStorage && shouldPersistSnapshot) {
|
|
1217
1203
|
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
1218
1204
|
await workflowsStore?.persistWorkflowSnapshot({
|
|
1219
1205
|
workflowName: this.id,
|
|
@@ -1238,6 +1224,30 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1238
1224
|
}
|
|
1239
1225
|
return run;
|
|
1240
1226
|
}
|
|
1227
|
+
//createCronFunction is only called if cronConfig.cron is defined.
|
|
1228
|
+
createCronFunction() {
|
|
1229
|
+
if (this.cronFunction) {
|
|
1230
|
+
return this.cronFunction;
|
|
1231
|
+
}
|
|
1232
|
+
this.cronFunction = this.inngest.createFunction(
|
|
1233
|
+
{
|
|
1234
|
+
id: `workflow.${this.id}.cron`,
|
|
1235
|
+
retries: 0,
|
|
1236
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
1237
|
+
...this.flowControlConfig
|
|
1238
|
+
},
|
|
1239
|
+
{ cron: this.cronConfig?.cron ?? "" },
|
|
1240
|
+
async () => {
|
|
1241
|
+
const run = await this.createRun();
|
|
1242
|
+
const result = await run.start({
|
|
1243
|
+
inputData: this.cronConfig?.inputData,
|
|
1244
|
+
initialState: this.cronConfig?.initialState
|
|
1245
|
+
});
|
|
1246
|
+
return { result, runId: run.runId };
|
|
1247
|
+
}
|
|
1248
|
+
);
|
|
1249
|
+
return this.cronFunction;
|
|
1250
|
+
}
|
|
1241
1251
|
getFunction() {
|
|
1242
1252
|
if (this.function) {
|
|
1243
1253
|
return this.function;
|
|
@@ -1245,7 +1255,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1245
1255
|
this.function = this.inngest.createFunction(
|
|
1246
1256
|
{
|
|
1247
1257
|
id: `workflow.${this.id}`,
|
|
1248
|
-
retries:
|
|
1258
|
+
retries: 0,
|
|
1249
1259
|
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
1250
1260
|
// Spread flow control configuration
|
|
1251
1261
|
...this.flowControlConfig
|
|
@@ -1320,7 +1330,11 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1320
1330
|
});
|
|
1321
1331
|
}
|
|
1322
1332
|
getFunctions() {
|
|
1323
|
-
return [
|
|
1333
|
+
return [
|
|
1334
|
+
this.getFunction(),
|
|
1335
|
+
...this.cronConfig?.cron ? [this.createCronFunction()] : [],
|
|
1336
|
+
...this.getNestedFunctions(this.executionGraph.steps)
|
|
1337
|
+
];
|
|
1324
1338
|
}
|
|
1325
1339
|
};
|
|
1326
1340
|
function serve({
|
|
@@ -1352,21 +1366,14 @@ function serve({
|
|
|
1352
1366
|
var _compatibilityCheck = true;
|
|
1353
1367
|
|
|
1354
1368
|
// src/index.ts
|
|
1355
|
-
function
|
|
1356
|
-
|
|
1357
|
-
}
|
|
1358
|
-
function isTool(params) {
|
|
1359
|
-
return params instanceof Tool;
|
|
1360
|
-
}
|
|
1361
|
-
function isInngestWorkflow(params) {
|
|
1362
|
-
return params instanceof InngestWorkflow;
|
|
1363
|
-
}
|
|
1364
|
-
function createStep(params, agentOptions) {
|
|
1365
|
-
if (isInngestWorkflow(params)) {
|
|
1369
|
+
function createStep(params, agentOrToolOptions) {
|
|
1370
|
+
if (params instanceof InngestWorkflow) {
|
|
1366
1371
|
return params;
|
|
1367
1372
|
}
|
|
1368
|
-
if (
|
|
1369
|
-
const
|
|
1373
|
+
if (params instanceof Agent) {
|
|
1374
|
+
const options = agentOrToolOptions;
|
|
1375
|
+
const outputSchema = options?.structuredOutput?.schema ?? z.object({ text: z.string() });
|
|
1376
|
+
const { retries, scorers, ...agentOptions } = options ?? {};
|
|
1370
1377
|
return {
|
|
1371
1378
|
id: params.name,
|
|
1372
1379
|
description: params.getDescription(),
|
|
@@ -1376,6 +1383,8 @@ function createStep(params, agentOptions) {
|
|
|
1376
1383
|
// threadId: z.string().optional(),
|
|
1377
1384
|
}),
|
|
1378
1385
|
outputSchema,
|
|
1386
|
+
retries,
|
|
1387
|
+
scorers,
|
|
1379
1388
|
execute: async ({
|
|
1380
1389
|
inputData,
|
|
1381
1390
|
runId,
|
|
@@ -1471,7 +1480,8 @@ function createStep(params, agentOptions) {
|
|
|
1471
1480
|
component: params.component
|
|
1472
1481
|
};
|
|
1473
1482
|
}
|
|
1474
|
-
if (
|
|
1483
|
+
if (params instanceof Tool) {
|
|
1484
|
+
const toolOpts = agentOrToolOptions;
|
|
1475
1485
|
if (!params.inputSchema || !params.outputSchema) {
|
|
1476
1486
|
throw new Error("Tool must have input and output schemas defined");
|
|
1477
1487
|
}
|
|
@@ -1483,6 +1493,8 @@ function createStep(params, agentOptions) {
|
|
|
1483
1493
|
outputSchema: params.outputSchema,
|
|
1484
1494
|
suspendSchema: params.suspendSchema,
|
|
1485
1495
|
resumeSchema: params.resumeSchema,
|
|
1496
|
+
retries: toolOpts?.retries,
|
|
1497
|
+
scorers: toolOpts?.scorers,
|
|
1486
1498
|
execute: async ({
|
|
1487
1499
|
inputData,
|
|
1488
1500
|
mastra,
|
|
@@ -1520,6 +1532,8 @@ function createStep(params, agentOptions) {
|
|
|
1520
1532
|
outputSchema: params.outputSchema,
|
|
1521
1533
|
resumeSchema: params.resumeSchema,
|
|
1522
1534
|
suspendSchema: params.suspendSchema,
|
|
1535
|
+
retries: params.retries,
|
|
1536
|
+
scorers: params.scorers,
|
|
1523
1537
|
execute: params.execute
|
|
1524
1538
|
};
|
|
1525
1539
|
}
|