@mastra/temporal 0.0.0 → 0.1.0-alpha.0

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE.md +30 -0
  3. package/README.md +104 -2
  4. package/dist/chunk-BF6TR7JX.js +9 -0
  5. package/dist/chunk-BF6TR7JX.js.map +1 -0
  6. package/dist/chunk-DYBSPLCJ.cjs +11 -0
  7. package/dist/chunk-DYBSPLCJ.cjs.map +1 -0
  8. package/dist/index.cjs +3 -946
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.ts +0 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +2 -920
  13. package/dist/index.js.map +1 -1
  14. package/dist/mastra-deployer-UCBGECM5.js +39 -0
  15. package/dist/mastra-deployer-UCBGECM5.js.map +1 -0
  16. package/dist/mastra-deployer-YVT5GB5G.cjs +41 -0
  17. package/dist/mastra-deployer-YVT5GB5G.cjs.map +1 -0
  18. package/dist/mastra-deployer.d.ts +16 -0
  19. package/dist/mastra-deployer.d.ts.map +1 -0
  20. package/dist/plugin.d.ts +13 -15
  21. package/dist/plugin.d.ts.map +1 -1
  22. package/dist/temporal-workflow-runtime.mjs +295 -0
  23. package/dist/transforms/activities.d.ts +4 -3
  24. package/dist/transforms/activities.d.ts.map +1 -1
  25. package/dist/transforms/shared.d.ts +2 -7
  26. package/dist/transforms/shared.d.ts.map +1 -1
  27. package/dist/transforms/temporal-workflow-runtime.d.mts +7 -0
  28. package/dist/transforms/temporal-workflow-runtime.d.mts.map +1 -1
  29. package/dist/transforms/workflows.d.ts +3 -11
  30. package/dist/transforms/workflows.d.ts.map +1 -1
  31. package/dist/worker.cjs +1336 -0
  32. package/dist/worker.cjs.map +1 -0
  33. package/dist/worker.d.ts +2 -0
  34. package/dist/worker.d.ts.map +1 -0
  35. package/dist/worker.js +1310 -0
  36. package/dist/worker.js.map +1 -0
  37. package/package.json +30 -24
  38. package/dist/__tests__/__fixtures__/before/index.d.ts +0 -11
  39. package/dist/__tests__/__fixtures__/before/index.d.ts.map +0 -1
  40. package/dist/__tests__/__fixtures__/before/weather-workflow.d.ts +0 -8
  41. package/dist/__tests__/__fixtures__/before/weather-workflow.d.ts.map +0 -1
  42. package/dist/transforms/__fixtures__/activities/weather-workflow/input.d.ts +0 -8
  43. package/dist/transforms/__fixtures__/activities/weather-workflow/input.d.ts.map +0 -1
  44. package/dist/transforms/__fixtures__/activities/weather-workflow/output.d.ts +0 -3
  45. package/dist/transforms/__fixtures__/activities/weather-workflow/output.d.ts.map +0 -1
  46. package/dist/transforms/__fixtures__/workflow/weather-workflow/input.d.ts +0 -8
  47. package/dist/transforms/__fixtures__/workflow/weather-workflow/input.d.ts.map +0 -1
  48. package/dist/transforms/__fixtures__/workflow/weather-workflow/output.d.ts +0 -2
  49. package/dist/transforms/__fixtures__/workflow/weather-workflow/output.d.ts.map +0 -1
  50. package/dist/webpack-loader.cjs +0 -856
  51. package/dist/webpack-loader.cjs.map +0 -1
  52. package/dist/webpack-loader.d.ts +0 -8
  53. package/dist/webpack-loader.d.ts.map +0 -1
  54. package/dist/webpack-plugin.d.ts +0 -18
  55. package/dist/webpack-plugin.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1 +1,34 @@
1
1
  # @mastra/temporal
2
+
3
+ ## 0.1.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added the new `@mastra/temporal` package for running Mastra workflows on Temporal. ([#15789](https://github.com/mastra-ai/mastra/pull/15789))
8
+
9
+ **What changed**
10
+ - Added `init()` to create Temporal-backed Mastra workflows and steps.
11
+ - Added `MastraPlugin` to bundle workflow code for Temporal workers and load generated activities.
12
+ - Added `debug: true` support to write transformed workflow modules and emitted bundles to `.mastra/temporal`.
13
+
14
+ **Example**
15
+
16
+ ```ts
17
+ import { init } from '@mastra/temporal';
18
+ import { MastraPlugin } from '@mastra/temporal/worker';
19
+ import { Client, Connection } from '@temporalio/client';
20
+ import { Worker } from '@temporalio/worker';
21
+
22
+ const connection = await Connection.connect();
23
+ const client = new Client({ connection });
24
+ const { createWorkflow, createStep } = init({ client, taskQueue: 'mastra' });
25
+
26
+ const step = createStep({ id: 'hello', execute: async () => 'world' });
27
+ export const helloWorkflow = createWorkflow({ id: 'hello-workflow' }).then(step);
28
+
29
+ await Worker.create({
30
+ connection,
31
+ taskQueue: 'mastra',
32
+ plugins: [new MastraPlugin({ src: import.meta.resolve('./mastra/index.ts') })],
33
+ });
34
+ ```
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 workflow engine integration with [Temporal](https://temporal.io/) for durable execution.
3
+ Run Mastra workflows on [Temporal](https://temporal.io/) with a workflow authoring API that stays close to standard Mastra workflows.
4
4
 
5
- > **Work in progress** – this package is under active development and not yet ready for production use.
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"]}