@mastra/temporal 0.3.5 → 0.4.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 +33 -0
- package/LICENSE.md +6 -4
- package/README.md +4 -10
- package/dist/plugin.d.ts +7 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/worker.cjs +26 -4
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +26 -4
- package/dist/worker.js.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @mastra/temporal
|
|
2
2
|
|
|
3
|
+
## 0.4.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Improved Temporal worker setup so `MastraPlugin` compiles the Mastra entry file automatically when the worker is configured. ([#22438](https://github.com/mastra-ai/mastra/pull/22438))
|
|
8
|
+
|
|
9
|
+
Before:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const plugin = new MastraPlugin();
|
|
13
|
+
await plugin.prebuild({ entryFile: import.meta.resolve('./mastra/index.ts') });
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
After:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
const plugin = new MastraPlugin(import.meta.resolve('./mastra/index.ts'));
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [[`078affd`](https://github.com/mastra-ai/mastra/commit/078affdaea57ac5e95a77e9e7b197d1878190684), [`9e3403e`](https://github.com/mastra-ai/mastra/commit/9e3403e9868240cb18841898e84cf008ebd7a87e), [`791bf5e`](https://github.com/mastra-ai/mastra/commit/791bf5e81cd27e2e1cff66122f1380ab8a3dda41)]:
|
|
25
|
+
- @mastra/core@1.63.1-alpha.1
|
|
26
|
+
- @mastra/deployer@1.63.1-alpha.1
|
|
27
|
+
|
|
28
|
+
## 0.3.6-alpha.0
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [[`bae1502`](https://github.com/mastra-ai/mastra/commit/bae150254b06a4da6964d7c137af97f336362359)]:
|
|
33
|
+
- @mastra/core@1.63.1-alpha.0
|
|
34
|
+
- @mastra/deployer@1.63.1-alpha.0
|
|
35
|
+
|
|
3
36
|
## 0.3.5
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
package/LICENSE.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
Portions of this software are licensed as follows:
|
|
2
2
|
|
|
3
|
-
- All content that resides under any directory named
|
|
3
|
+
- All content that resides under any directory named `ee/` within this
|
|
4
4
|
repository, including but not limited to:
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
|
|
5
|
+
- `@mastra/core/auth/ee`
|
|
6
|
+
- `@mastra/core/agent-builder/ee`
|
|
7
|
+
- `@mastra/editor/ee`
|
|
8
|
+
|
|
9
|
+
is licensed under the license defined in [`ee/LICENSE`](https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE).
|
|
8
10
|
|
|
9
11
|
- All third-party components incorporated into the Mastra Software are
|
|
10
12
|
licensed under the original license provided by the owner of the
|
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ export const mastra = new Mastra({
|
|
|
62
62
|
|
|
63
63
|
## Start a Temporal worker
|
|
64
64
|
|
|
65
|
-
Create a worker
|
|
65
|
+
Create a worker and pass the Mastra entry file to `MastraPlugin`.
|
|
66
66
|
|
|
67
67
|
```ts
|
|
68
68
|
import { NativeConnection, Worker } from '@temporalio/worker';
|
|
@@ -72,11 +72,7 @@ const connection = await NativeConnection.connect({
|
|
|
72
72
|
address: 'localhost:7233',
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
const plugin = new MastraPlugin(
|
|
76
|
-
src: import.meta.resolve('./mastra/index.ts'),
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
await plugin.init();
|
|
75
|
+
const plugin = new MastraPlugin(import.meta.resolve('./mastra/index.ts'));
|
|
80
76
|
|
|
81
77
|
const worker = await Worker.create({
|
|
82
78
|
connection,
|
|
@@ -91,16 +87,14 @@ await worker.run();
|
|
|
91
87
|
## How it works
|
|
92
88
|
|
|
93
89
|
- `init({ client, taskQueue })`: Returns `createWorkflow()` and `createStep()` helpers for Temporal-backed Mastra workflows.
|
|
94
|
-
- `MastraPlugin(
|
|
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.
|
|
90
|
+
- `MastraPlugin(entryFile)`: Points the plugin at the Mastra entry file that registers workflows and compiles it when the worker is configured.
|
|
96
91
|
- Generated activities: The plugin extracts `createStep()` handlers into `node_modules/.mastra/activities.mjs` and wires them into the worker automatically.
|
|
97
92
|
- `debug: true`: Writes emitted workflow bundles to `node_modules/.mastra` for inspection.
|
|
98
93
|
|
|
99
94
|
## Notes
|
|
100
95
|
|
|
101
96
|
- Workflow ids must be statically defined so the transformer can derive Temporal export names.
|
|
102
|
-
- The plugin expects `
|
|
103
|
-
- Call `await plugin.init()` before `Worker.create()` so the compiled workflow entry is ready when Temporal configures the worker and bundler.
|
|
97
|
+
- The plugin expects `entryFile` to point to the Mastra entry file that registers workflows in `new Mastra({ workflows: ... })`.
|
|
104
98
|
|
|
105
99
|
## License
|
|
106
100
|
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { WorkerOptions, WorkerPlugin } from '@temporalio/worker';
|
|
2
2
|
export declare class MastraPlugin implements WorkerPlugin {
|
|
3
3
|
#private;
|
|
4
|
+
private readonly entryFile;
|
|
5
|
+
private readonly projectRoot;
|
|
4
6
|
name: string;
|
|
5
|
-
constructor();
|
|
7
|
+
constructor(entryFile: string, projectRoot?: string);
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Please use the constructor params instead.
|
|
10
|
+
*/
|
|
6
11
|
prebuild({ entryFile, projectRoot, }: {
|
|
7
12
|
entryFile: string;
|
|
8
13
|
projectRoot?: string;
|
|
@@ -11,6 +16,6 @@ export declare class MastraPlugin implements WorkerPlugin {
|
|
|
11
16
|
workflowsPath: WorkerOptions['workflowsPath'];
|
|
12
17
|
activities: WorkerOptions['activities'];
|
|
13
18
|
};
|
|
14
|
-
configureWorker(options: WorkerOptions): WorkerOptions
|
|
19
|
+
configureWorker(options: WorkerOptions): Promise<WorkerOptions>;
|
|
15
20
|
}
|
|
16
21
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAsBtE,qBAAa,YAAa,YAAW,YAAY;;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAsBtE,qBAAa,YAAa,YAAW,YAAY;;IAO7C,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAJ9B,IAAI,SAAY;gBAGG,SAAS,EAAE,MAAM,EACjB,WAAW,GAAE,MAAsB;IAgBtD;;OAEG;IACG,QAAQ,CAAC,EACb,SAAS,EACT,WAA2B,GAC5B,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAwE7D,wBAAwB,CAAC,iBAAiB,EAAE,MAAM,GAAG;QAEnD,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;QAC9C,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;KACzC;IAeK,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;CAoBtE"}
|
package/dist/worker.cjs
CHANGED
|
@@ -990,10 +990,16 @@ function getActivityBindingsPath(outputDir) {
|
|
|
990
990
|
return path.default.join(outputDir, ACTIVITY_BINDINGS_FILE_NAME);
|
|
991
991
|
}
|
|
992
992
|
var MastraPlugin = class {
|
|
993
|
+
entryFile;
|
|
994
|
+
projectRoot;
|
|
993
995
|
#prebuildPath = null;
|
|
996
|
+
#prebuildPromise = null;
|
|
994
997
|
#compiledActivitiesModules = /* @__PURE__ */ new Map();
|
|
995
998
|
name = "Mastra";
|
|
996
|
-
constructor() {
|
|
999
|
+
constructor(entryFile, projectRoot = process.cwd()) {
|
|
1000
|
+
this.entryFile = entryFile;
|
|
1001
|
+
this.projectRoot = projectRoot;
|
|
1002
|
+
}
|
|
997
1003
|
async #bundleMastra(entryFile, projectRoot, outputDirectory) {
|
|
998
1004
|
const { BuildBundler } = await Promise.resolve().then(() => require("./mastra-deployer-D6fHvmFM.cjs"));
|
|
999
1005
|
const normalizedEntryFile = entryFile.startsWith("file:/") ? (0, url.fileURLToPath)(entryFile) : entryFile;
|
|
@@ -1005,7 +1011,13 @@ var MastraPlugin = class {
|
|
|
1005
1011
|
});
|
|
1006
1012
|
return path.default.join(outputDirectory, "output", "index.mjs");
|
|
1007
1013
|
}
|
|
1014
|
+
/**
|
|
1015
|
+
* @deprecated Please use the constructor params instead.
|
|
1016
|
+
*/
|
|
1008
1017
|
async prebuild({ entryFile, projectRoot = process.cwd() }) {
|
|
1018
|
+
return this.#prebuild(entryFile, projectRoot);
|
|
1019
|
+
}
|
|
1020
|
+
async #prebuild(entryFile, projectRoot) {
|
|
1009
1021
|
const temporalOutputDir = path.default.resolve(projectRoot, CACHE_PATH);
|
|
1010
1022
|
const compiledEntryPath = await this.#bundleMastra(entryFile, projectRoot, temporalOutputDir);
|
|
1011
1023
|
await buildTemporalWorkflowModule(compiledEntryPath, temporalOutputDir, WORKFLOW_FILE_NAME);
|
|
@@ -1049,10 +1061,20 @@ var MastraPlugin = class {
|
|
|
1049
1061
|
activities: this.#generateActivityBindings(activityBindings, activitiesOutputPath)
|
|
1050
1062
|
};
|
|
1051
1063
|
}
|
|
1052
|
-
configureWorker(options) {
|
|
1064
|
+
async configureWorker(options) {
|
|
1053
1065
|
const augmentedOptions = Object.assign({}, options);
|
|
1054
|
-
if (this.#prebuildPath)
|
|
1055
|
-
|
|
1066
|
+
if (!this.#prebuildPath) {
|
|
1067
|
+
this.#prebuildPromise ??= this.#prebuild(this.entryFile, this.projectRoot).catch((error) => {
|
|
1068
|
+
this.#prebuildPromise = null;
|
|
1069
|
+
throw error;
|
|
1070
|
+
});
|
|
1071
|
+
await this.#prebuildPromise;
|
|
1072
|
+
}
|
|
1073
|
+
const generatedOptions = this.getTemporalWorkerOptions(this.#prebuildPath);
|
|
1074
|
+
Object.assign(augmentedOptions, generatedOptions, { activities: {
|
|
1075
|
+
...options.activities,
|
|
1076
|
+
...generatedOptions.activities
|
|
1077
|
+
} });
|
|
1056
1078
|
return augmentedOptions;
|
|
1057
1079
|
}
|
|
1058
1080
|
};
|