@mastra/temporal 0.0.0 → 0.1.0-alpha.1
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 +41 -0
- package/LICENSE.md +30 -0
- package/README.md +104 -2
- package/dist/chunk-BF6TR7JX.js +9 -0
- package/dist/chunk-BF6TR7JX.js.map +1 -0
- package/dist/chunk-DYBSPLCJ.cjs +11 -0
- package/dist/chunk-DYBSPLCJ.cjs.map +1 -0
- package/dist/index.cjs +3 -946
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -920
- package/dist/index.js.map +1 -1
- package/dist/mastra-deployer-UCBGECM5.js +39 -0
- package/dist/mastra-deployer-UCBGECM5.js.map +1 -0
- package/dist/mastra-deployer-YVT5GB5G.cjs +41 -0
- package/dist/mastra-deployer-YVT5GB5G.cjs.map +1 -0
- package/dist/mastra-deployer.d.ts +16 -0
- package/dist/mastra-deployer.d.ts.map +1 -0
- package/dist/plugin.d.ts +13 -15
- package/dist/plugin.d.ts.map +1 -1
- package/dist/temporal-workflow-runtime.mjs +295 -0
- package/dist/transforms/activities.d.ts +4 -3
- package/dist/transforms/activities.d.ts.map +1 -1
- package/dist/transforms/shared.d.ts +2 -7
- package/dist/transforms/shared.d.ts.map +1 -1
- package/dist/transforms/temporal-workflow-runtime.d.mts +7 -0
- package/dist/transforms/temporal-workflow-runtime.d.mts.map +1 -1
- package/dist/transforms/workflows.d.ts +3 -11
- package/dist/transforms/workflows.d.ts.map +1 -1
- package/dist/worker.cjs +1336 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.ts +2 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +1310 -0
- package/dist/worker.js.map +1 -0
- package/package.json +30 -24
- package/dist/__tests__/__fixtures__/before/index.d.ts +0 -11
- package/dist/__tests__/__fixtures__/before/index.d.ts.map +0 -1
- package/dist/__tests__/__fixtures__/before/weather-workflow.d.ts +0 -8
- package/dist/__tests__/__fixtures__/before/weather-workflow.d.ts.map +0 -1
- package/dist/transforms/__fixtures__/activities/weather-workflow/input.d.ts +0 -8
- package/dist/transforms/__fixtures__/activities/weather-workflow/input.d.ts.map +0 -1
- package/dist/transforms/__fixtures__/activities/weather-workflow/output.d.ts +0 -3
- package/dist/transforms/__fixtures__/activities/weather-workflow/output.d.ts.map +0 -1
- package/dist/transforms/__fixtures__/workflow/weather-workflow/input.d.ts +0 -8
- package/dist/transforms/__fixtures__/workflow/weather-workflow/input.d.ts.map +0 -1
- package/dist/transforms/__fixtures__/workflow/weather-workflow/output.d.ts +0 -2
- package/dist/transforms/__fixtures__/workflow/weather-workflow/output.d.ts.map +0 -1
- package/dist/webpack-loader.cjs +0 -856
- package/dist/webpack-loader.cjs.map +0 -1
- package/dist/webpack-loader.d.ts +0 -8
- package/dist/webpack-loader.d.ts.map +0 -1
- package/dist/webpack-plugin.d.ts +0 -18
- package/dist/webpack-plugin.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
1
|
# @mastra/temporal
|
|
2
|
+
|
|
3
|
+
## 0.1.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`86c0298`](https://github.com/mastra-ai/mastra/commit/86c0298e647306423c842f9d5ac827bd616bd13d), [`7fce309`](https://github.com/mastra-ai/mastra/commit/7fce30912b14170bfc41f0ac736cca0f39fe0cd4), [`7997c2e`](https://github.com/mastra-ai/mastra/commit/7997c2e55ddd121562a4098cd8d2b89c68433bf1), [`e97ccb9`](https://github.com/mastra-ai/mastra/commit/e97ccb900f8b7a390ce82c9f8eb8d6eb2c5e3777), [`c5daf48`](https://github.com/mastra-ai/mastra/commit/c5daf48556e98c46ae06caf00f92c249912007e9), [`cd96779`](https://github.com/mastra-ai/mastra/commit/cd9677937f113b2856dc8b9f3d4bdabcee58bb2e)]:
|
|
8
|
+
- @mastra/core@1.32.0-alpha.2
|
|
9
|
+
- @mastra/deployer@1.32.0-alpha.2
|
|
10
|
+
|
|
11
|
+
## 0.1.0-alpha.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- Added the new `@mastra/temporal` package for running Mastra workflows on Temporal. ([#15789](https://github.com/mastra-ai/mastra/pull/15789))
|
|
16
|
+
|
|
17
|
+
**What changed**
|
|
18
|
+
- Added `init()` to create Temporal-backed Mastra workflows and steps.
|
|
19
|
+
- Added `MastraPlugin` to bundle workflow code for Temporal workers and load generated activities.
|
|
20
|
+
- Added `debug: true` support to write transformed workflow modules and emitted bundles to `.mastra/temporal`.
|
|
21
|
+
|
|
22
|
+
**Example**
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { init } from '@mastra/temporal';
|
|
26
|
+
import { MastraPlugin } from '@mastra/temporal/worker';
|
|
27
|
+
import { Client, Connection } from '@temporalio/client';
|
|
28
|
+
import { Worker } from '@temporalio/worker';
|
|
29
|
+
|
|
30
|
+
const connection = await Connection.connect();
|
|
31
|
+
const client = new Client({ connection });
|
|
32
|
+
const { createWorkflow, createStep } = init({ client, taskQueue: 'mastra' });
|
|
33
|
+
|
|
34
|
+
const step = createStep({ id: 'hello', execute: async () => 'world' });
|
|
35
|
+
export const helloWorkflow = createWorkflow({ id: 'hello-workflow' }).then(step);
|
|
36
|
+
|
|
37
|
+
await Worker.create({
|
|
38
|
+
connection,
|
|
39
|
+
taskQueue: 'mastra',
|
|
40
|
+
plugins: [new MastraPlugin({ src: import.meta.resolve('./mastra/index.ts') })],
|
|
41
|
+
});
|
|
42
|
+
```
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
16
|
+
# Apache License 2.0
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
19
|
+
|
|
20
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
you may not use this file except in compliance with the License.
|
|
22
|
+
You may obtain a copy of the License at
|
|
23
|
+
|
|
24
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
|
|
26
|
+
Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
See the License for the specific language governing permissions and
|
|
30
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,5 +1,107 @@
|
|
|
1
1
|
# @mastra/temporal
|
|
2
2
|
|
|
3
|
-
Mastra
|
|
3
|
+
Run Mastra workflows on [Temporal](https://temporal.io/) with a workflow authoring API that stays close to standard Mastra workflows.
|
|
4
4
|
|
|
5
|
-
> **
|
|
5
|
+
> **Experimental:** `@mastra/temporal` is under active development and is not ready for production use yet.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mastra/temporal @temporalio/client @temporalio/worker @temporalio/envconfig
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Define a Temporal-backed workflow
|
|
14
|
+
|
|
15
|
+
The following example demonstrates the same pattern used in the `temporal-snapshot` app: create a Temporal client, call `init()`, and define workflows with `createWorkflow()` and `createStep()`.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { init } from '@mastra/temporal';
|
|
20
|
+
import { loadClientConnectConfig } from '@temporalio/envconfig';
|
|
21
|
+
import { Client, Connection } from '@temporalio/client';
|
|
22
|
+
|
|
23
|
+
const config = loadClientConnectConfig();
|
|
24
|
+
const connection = await Connection.connect(config.connectionOptions);
|
|
25
|
+
const client = new Client({ connection });
|
|
26
|
+
|
|
27
|
+
const { createWorkflow, createStep } = init({
|
|
28
|
+
client,
|
|
29
|
+
taskQueue: 'mastra',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const fetchWeather = createStep({
|
|
33
|
+
id: 'fetch-weather',
|
|
34
|
+
inputSchema: z.object({ city: z.string() }),
|
|
35
|
+
outputSchema: z.object({ forecast: z.string() }),
|
|
36
|
+
execute: async ({ inputData }) => {
|
|
37
|
+
return {
|
|
38
|
+
forecast: `Sunny in ${inputData.city}`,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const weatherWorkflow = createWorkflow({
|
|
44
|
+
id: 'weather-workflow',
|
|
45
|
+
inputSchema: z.object({ city: z.string() }),
|
|
46
|
+
outputSchema: z.object({ forecast: z.string() }),
|
|
47
|
+
}).then(fetchWeather);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Register the workflow in your Mastra entry file
|
|
51
|
+
|
|
52
|
+
`MastraPlugin` precompiles your Mastra entry file into dedicated workflow and activity modules before Temporal starts. Point the plugin at the file where your `Mastra` instance registers workflows.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
56
|
+
import { weatherWorkflow } from './workflows/weather-workflow';
|
|
57
|
+
|
|
58
|
+
export const mastra = new Mastra({
|
|
59
|
+
workflows: { weatherWorkflow },
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Start a Temporal worker
|
|
64
|
+
|
|
65
|
+
Create a worker, install `MastraPlugin`, and call `await plugin.init()` before `Worker.create()`. Use the Mastra entry file as `src`.
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { NativeConnection, Worker } from '@temporalio/worker';
|
|
69
|
+
import { MastraPlugin } from '@mastra/temporal/worker';
|
|
70
|
+
|
|
71
|
+
const connection = await NativeConnection.connect({
|
|
72
|
+
address: 'localhost:7233',
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const plugin = new MastraPlugin({
|
|
76
|
+
src: import.meta.resolve('./mastra/index.ts'),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
await plugin.init();
|
|
80
|
+
|
|
81
|
+
const worker = await Worker.create({
|
|
82
|
+
connection,
|
|
83
|
+
namespace: 'default',
|
|
84
|
+
taskQueue: 'mastra',
|
|
85
|
+
plugins: [plugin],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
await worker.run();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## How it works
|
|
92
|
+
|
|
93
|
+
- `init({ client, taskQueue })`: Returns `createWorkflow()` and `createStep()` helpers for Temporal-backed Mastra workflows.
|
|
94
|
+
- `MastraPlugin({ src })`: Point it at the Mastra entry file that registers workflows.
|
|
95
|
+
- `await plugin.init()`: Precompiles the Mastra app into `node_modules/.mastra/output/index.mjs`, then generates `node_modules/.mastra/workflow.mjs` for workflow bundling and `node_modules/.mastra/activities.mjs` for activity execution before the Temporal worker starts.
|
|
96
|
+
- Generated activities: The plugin extracts `createStep()` handlers into `node_modules/.mastra/activities.mjs` and wires them into the worker automatically.
|
|
97
|
+
- `debug: true`: Writes emitted workflow bundles to `node_modules/.mastra` for inspection.
|
|
98
|
+
|
|
99
|
+
## Notes
|
|
100
|
+
|
|
101
|
+
- Workflow ids must be statically defined so the transformer can derive Temporal export names.
|
|
102
|
+
- The plugin expects `src` to point to the Mastra entry file that registers workflows in `new Mastra({ workflows: ... })`.
|
|
103
|
+
- Call `await plugin.init()` before `Worker.create()` so the compiled workflow entry is ready when Temporal configures the worker and bundler.
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
Apache-2.0
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
function toWorkflowType(id) {
|
|
3
|
+
const camelCased = id.replace(/[-_]+([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
4
|
+
return camelCased.endsWith("Workflow") ? camelCased : `${camelCased}Workflow`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { toWorkflowType };
|
|
8
|
+
//# sourceMappingURL=chunk-BF6TR7JX.js.map
|
|
9
|
+
//# sourceMappingURL=chunk-BF6TR7JX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"names":[],"mappings":";AAAO,SAAS,eAAe,EAAA,EAAY;AACzC,EAAA,MAAM,UAAA,GAAa,GAAG,OAAA,CAAQ,qBAAA,EAAuB,CAAC,CAAA,EAAG,IAAA,KAAiB,IAAA,CAAK,WAAA,EAAa,CAAA;AAC5F,EAAA,OAAO,WAAW,QAAA,CAAS,UAAU,CAAA,GAAI,UAAA,GAAa,GAAG,UAAU,CAAA,QAAA,CAAA;AACrE","file":"chunk-BF6TR7JX.js","sourcesContent":["export function toWorkflowType(id: string) {\n const camelCased = id.replace(/[-_]+([a-zA-Z0-9])/g, (_, char: string) => char.toUpperCase());\n return camelCased.endsWith('Workflow') ? camelCased : `${camelCased}Workflow`;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils.ts
|
|
4
|
+
function toWorkflowType(id) {
|
|
5
|
+
const camelCased = id.replace(/[-_]+([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
6
|
+
return camelCased.endsWith("Workflow") ? camelCased : `${camelCased}Workflow`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
exports.toWorkflowType = toWorkflowType;
|
|
10
|
+
//# sourceMappingURL=chunk-DYBSPLCJ.cjs.map
|
|
11
|
+
//# sourceMappingURL=chunk-DYBSPLCJ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAO,SAAS,eAAe,EAAA,EAAY;AACzC,EAAA,MAAM,UAAA,GAAa,GAAG,OAAA,CAAQ,qBAAA,EAAuB,CAAC,CAAA,EAAG,IAAA,KAAiB,IAAA,CAAK,WAAA,EAAa,CAAA;AAC5F,EAAA,OAAO,WAAW,QAAA,CAAS,UAAU,CAAA,GAAI,UAAA,GAAa,GAAG,UAAU,CAAA,QAAA,CAAA;AACrE","file":"chunk-DYBSPLCJ.cjs","sourcesContent":["export function toWorkflowType(id: string) {\n const camelCased = id.replace(/[-_]+([a-zA-Z0-9])/g, (_, char: string) => char.toUpperCase());\n return camelCased.endsWith('Workflow') ? camelCased : `${camelCased}Workflow`;\n}\n"]}
|