@mastra/inngest 1.0.0-beta.11 → 1.0.0-beta.12
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 +81 -0
- package/dist/__tests__/adapters/_utils.d.ts +18 -0
- package/dist/__tests__/adapters/_utils.d.ts.map +1 -0
- package/dist/execution-engine.d.ts +13 -0
- package/dist/execution-engine.d.ts.map +1 -1
- package/dist/index.cjs +26 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -11
- package/dist/index.js.map +1 -1
- package/dist/serve.d.ts +66 -3
- package/dist/serve.d.ts.map +1 -1
- package/dist/workflow.d.ts.map +1 -1
- package/package.json +17 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,86 @@
|
|
|
1
1
|
# @mastra/inngest
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.12
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `createServe` factory function to support multiple web framework adapters for Inngest workflows. ([#11667](https://github.com/mastra-ai/mastra/pull/11667))
|
|
8
|
+
|
|
9
|
+
Previously, the `serve` function only supported Hono. Now you can use any framework adapter provided by the Inngest package (Express, Fastify, Koa, Next.js, and more).
|
|
10
|
+
|
|
11
|
+
**Before (Hono only)**
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { serve } from '@mastra/inngest';
|
|
15
|
+
|
|
16
|
+
// Only worked with Hono
|
|
17
|
+
app.all('/api/inngest', c => serve({ mastra, inngest })(c));
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**After (any framework)**
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { createServe } from '@mastra/inngest';
|
|
24
|
+
import { serve as expressAdapter } from 'inngest/express';
|
|
25
|
+
import { serve as fastifyAdapter } from 'inngest/fastify';
|
|
26
|
+
|
|
27
|
+
// Express
|
|
28
|
+
app.use('/api/inngest', createServe(expressAdapter)({ mastra, inngest }));
|
|
29
|
+
|
|
30
|
+
// Fastify
|
|
31
|
+
fastify.route({
|
|
32
|
+
method: ['GET', 'POST', 'PUT'],
|
|
33
|
+
url: '/api/inngest',
|
|
34
|
+
handler: createServe(fastifyAdapter)({ mastra, inngest }),
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The existing `serve` export remains available for backward compatibility with Hono.
|
|
39
|
+
|
|
40
|
+
Fixes #10053
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- Add additional context to workflow `onFinish` and `onError` callbacks ([#11705](https://github.com/mastra-ai/mastra/pull/11705))
|
|
45
|
+
|
|
46
|
+
The `onFinish` and `onError` lifecycle callbacks now receive additional properties:
|
|
47
|
+
- `runId` - The unique identifier for the workflow run
|
|
48
|
+
- `workflowId` - The workflow's identifier
|
|
49
|
+
- `resourceId` - Optional resource identifier (if provided when creating the run)
|
|
50
|
+
- `getInitData()` - Function that returns the initial input data passed to the workflow
|
|
51
|
+
- `mastra` - The Mastra instance (if workflow is registered with Mastra)
|
|
52
|
+
- `requestContext` - Request-scoped context data
|
|
53
|
+
- `logger` - The workflow's logger instance
|
|
54
|
+
- `state` - The workflow's current state object
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
const workflow = createWorkflow({
|
|
58
|
+
id: 'order-processing',
|
|
59
|
+
inputSchema: z.object({ orderId: z.string() }),
|
|
60
|
+
outputSchema: z.object({ status: z.string() }),
|
|
61
|
+
options: {
|
|
62
|
+
onFinish: async ({ runId, workflowId, getInitData, logger, state, mastra }) => {
|
|
63
|
+
const inputData = getInitData();
|
|
64
|
+
logger.info(`Workflow ${workflowId} run ${runId} completed`, {
|
|
65
|
+
orderId: inputData.orderId,
|
|
66
|
+
finalState: state,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Access other Mastra components if needed
|
|
70
|
+
const agent = mastra?.getAgent('notification-agent');
|
|
71
|
+
},
|
|
72
|
+
onError: async ({ runId, workflowId, error, logger, requestContext }) => {
|
|
73
|
+
logger.error(`Workflow ${workflowId} run ${runId} failed: ${error?.message}`);
|
|
74
|
+
// Access request context for additional debugging
|
|
75
|
+
const userId = requestContext.get('userId');
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
- Updated dependencies [[`08766f1`](https://github.com/mastra-ai/mastra/commit/08766f15e13ac0692fde2a8bd366c2e16e4321df), [`ae8baf7`](https://github.com/mastra-ai/mastra/commit/ae8baf7d8adcb0ff9dac11880400452bc49b33ff), [`cfabdd4`](https://github.com/mastra-ai/mastra/commit/cfabdd4aae7a726b706942d6836eeca110fb6267), [`a0e437f`](https://github.com/mastra-ai/mastra/commit/a0e437fac561b28ee719e0302d72b2f9b4c138f0), [`bec5efd`](https://github.com/mastra-ai/mastra/commit/bec5efde96653ccae6604e68c696d1bc6c1a0bf5), [`9eedf7d`](https://github.com/mastra-ai/mastra/commit/9eedf7de1d6e0022a2f4e5e9e6fe1ec468f9b43c)]:
|
|
82
|
+
- @mastra/core@1.0.0-beta.21
|
|
83
|
+
|
|
3
84
|
## 1.0.0-beta.11
|
|
4
85
|
|
|
5
86
|
### Patch Changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
2
|
+
import { Inngest } from 'inngest';
|
|
3
|
+
import type { InngestWorkflow } from '../../workflow.js';
|
|
4
|
+
export declare const INNGEST_PORT = 4000;
|
|
5
|
+
export declare const HANDLER_PORT = 4001;
|
|
6
|
+
export declare function createTestInngest(id: string): Inngest<{
|
|
7
|
+
id: string;
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function resetInngest(): Promise<void>;
|
|
11
|
+
export declare function waitForInngestSync(ms?: number): Promise<void>;
|
|
12
|
+
export interface TestWorkflowResult {
|
|
13
|
+
workflow: InngestWorkflow<any, any, any>;
|
|
14
|
+
mastra: Mastra;
|
|
15
|
+
inngest: Inngest;
|
|
16
|
+
}
|
|
17
|
+
export declare function createTestWorkflow(adapterId: string): TestWorkflowResult;
|
|
18
|
+
//# sourceMappingURL=_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_utils.d.ts","sourceRoot":"","sources":["../../../src/__tests__/adapters/_utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAIlC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM;;;GAK3C;AAED,wBAAsB,YAAY,kBAIjC;AAED,wBAAsB,kBAAkB,CAAC,EAAE,SAAO,iBAEjD;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,CA0CxE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RequestContext } from '@mastra/core/di';
|
|
1
2
|
import type { SerializedError } from '@mastra/core/error';
|
|
2
3
|
import type { PubSub } from '@mastra/core/events';
|
|
3
4
|
import type { Mastra } from '@mastra/core/mastra';
|
|
@@ -73,6 +74,12 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
73
74
|
error?: any;
|
|
74
75
|
steps: Record<string, any>;
|
|
75
76
|
tripwire?: any;
|
|
77
|
+
runId: string;
|
|
78
|
+
workflowId: string;
|
|
79
|
+
resourceId?: string;
|
|
80
|
+
input?: any;
|
|
81
|
+
requestContext: RequestContext;
|
|
82
|
+
state: Record<string, any>;
|
|
76
83
|
}): Promise<void>;
|
|
77
84
|
/**
|
|
78
85
|
* Actually invoke the lifecycle callbacks. Called from workflow.ts finalize step.
|
|
@@ -83,6 +90,12 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
83
90
|
error?: any;
|
|
84
91
|
steps: Record<string, any>;
|
|
85
92
|
tripwire?: any;
|
|
93
|
+
runId: string;
|
|
94
|
+
workflowId: string;
|
|
95
|
+
resourceId?: string;
|
|
96
|
+
input?: any;
|
|
97
|
+
requestContext: RequestContext;
|
|
98
|
+
state: Record<string, any>;
|
|
86
99
|
}): Promise<void>;
|
|
87
100
|
/**
|
|
88
101
|
* Execute nested InngestWorkflow using inngestStep.invoke() for durability.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-engine.d.ts","sourceRoot":"","sources":["../src/execution-engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"execution-engine.d.ts","sourceRoot":"","sources":["../src/execution-engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,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,CAA+B;IAClD,OAAO,CAAC,eAA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C,CAAC;KAC5B,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjB;;;OAGG;IACG,mBAAmB,CAAC,MAAM,EAAE;QAChC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAC7B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAC5D,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,MAAM,CAAC,EAAE;YACP,KAAK,EAAE,MAAM,EAAE,CAAC;YAChB,aAAa,EAAE,GAAG,CAAC;YACnB,KAAK,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
|
@@ -1271,6 +1271,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1271
1271
|
});
|
|
1272
1272
|
}
|
|
1273
1273
|
const pubsub = new InngestPubSub(this.inngest, this.id, publish);
|
|
1274
|
+
const requestContext = new di.RequestContext(Object.entries(event.data.requestContext ?? {}));
|
|
1274
1275
|
const engine = new InngestExecutionEngine(this.#mastra, step, attempt, this.options);
|
|
1275
1276
|
const result = await engine.execute({
|
|
1276
1277
|
workflowId: this.id,
|
|
@@ -1282,7 +1283,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1282
1283
|
initialState,
|
|
1283
1284
|
pubsub,
|
|
1284
1285
|
retryConfig: this.retryConfig,
|
|
1285
|
-
requestContext
|
|
1286
|
+
requestContext,
|
|
1286
1287
|
resume,
|
|
1287
1288
|
timeTravel,
|
|
1288
1289
|
perStep,
|
|
@@ -1304,7 +1305,19 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1304
1305
|
});
|
|
1305
1306
|
await step.run(`workflow.${this.id}.finalize`, async () => {
|
|
1306
1307
|
if (result.status !== "paused") {
|
|
1307
|
-
await engine.invokeLifecycleCallbacksInternal(
|
|
1308
|
+
await engine.invokeLifecycleCallbacksInternal({
|
|
1309
|
+
status: result.status,
|
|
1310
|
+
result: "result" in result ? result.result : void 0,
|
|
1311
|
+
error: "error" in result ? result.error : void 0,
|
|
1312
|
+
steps: result.steps,
|
|
1313
|
+
tripwire: "tripwire" in result ? result.tripwire : void 0,
|
|
1314
|
+
runId,
|
|
1315
|
+
workflowId: this.id,
|
|
1316
|
+
resourceId,
|
|
1317
|
+
input: inputData,
|
|
1318
|
+
requestContext,
|
|
1319
|
+
state: result.state ?? initialState ?? {}
|
|
1320
|
+
});
|
|
1308
1321
|
}
|
|
1309
1322
|
if (result.status === "failed") {
|
|
1310
1323
|
throw new inngest.NonRetriableError(`Workflow failed`, {
|
|
@@ -1339,12 +1352,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
1339
1352
|
];
|
|
1340
1353
|
}
|
|
1341
1354
|
};
|
|
1342
|
-
function
|
|
1343
|
-
mastra,
|
|
1344
|
-
inngest,
|
|
1345
|
-
functions: userFunctions = [],
|
|
1346
|
-
registerOptions
|
|
1347
|
-
}) {
|
|
1355
|
+
function prepareServeOptions({ mastra, inngest, functions: userFunctions = [], registerOptions }) {
|
|
1348
1356
|
const wfs = mastra.listWorkflows();
|
|
1349
1357
|
const workflowFunctions = Array.from(
|
|
1350
1358
|
new Set(
|
|
@@ -1357,12 +1365,19 @@ function serve({
|
|
|
1357
1365
|
})
|
|
1358
1366
|
)
|
|
1359
1367
|
);
|
|
1360
|
-
return
|
|
1368
|
+
return {
|
|
1361
1369
|
...registerOptions,
|
|
1362
1370
|
client: inngest,
|
|
1363
1371
|
functions: [...workflowFunctions, ...userFunctions]
|
|
1364
|
-
}
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
function createServe(adapter) {
|
|
1375
|
+
return (options) => {
|
|
1376
|
+
const serveOptions = prepareServeOptions(options);
|
|
1377
|
+
return adapter(serveOptions);
|
|
1378
|
+
};
|
|
1365
1379
|
}
|
|
1380
|
+
var serve = createServe(hono.serve);
|
|
1366
1381
|
|
|
1367
1382
|
// src/types.ts
|
|
1368
1383
|
var _compatibilityCheck = true;
|
|
@@ -1584,6 +1599,7 @@ exports.InngestPubSub = InngestPubSub;
|
|
|
1584
1599
|
exports.InngestRun = InngestRun;
|
|
1585
1600
|
exports.InngestWorkflow = InngestWorkflow;
|
|
1586
1601
|
exports._compatibilityCheck = _compatibilityCheck;
|
|
1602
|
+
exports.createServe = createServe;
|
|
1587
1603
|
exports.createStep = createStep;
|
|
1588
1604
|
exports.init = init;
|
|
1589
1605
|
exports.serve = serve;
|