@mastra/temporal 0.0.0-observe-20260504181920

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 (45) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/LICENSE.md +30 -0
  3. package/README.md +107 -0
  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 +132 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +130 -0
  13. package/dist/index.js.map +1 -0
  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 +16 -0
  21. package/dist/plugin.d.ts.map +1 -0
  22. package/dist/run.d.ts +24 -0
  23. package/dist/run.d.ts.map +1 -0
  24. package/dist/temporal-workflow-runtime.mjs +295 -0
  25. package/dist/transforms/activities.d.ts +11 -0
  26. package/dist/transforms/activities.d.ts.map +1 -0
  27. package/dist/transforms/shared.d.ts +23 -0
  28. package/dist/transforms/shared.d.ts.map +1 -0
  29. package/dist/transforms/temporal-workflow-runtime.d.mts +92 -0
  30. package/dist/transforms/temporal-workflow-runtime.d.mts.map +1 -0
  31. package/dist/transforms/workflows.d.ts +20 -0
  32. package/dist/transforms/workflows.d.ts.map +1 -0
  33. package/dist/types.d.ts +4 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/utils.d.ts +2 -0
  36. package/dist/utils.d.ts.map +1 -0
  37. package/dist/worker.cjs +1336 -0
  38. package/dist/worker.cjs.map +1 -0
  39. package/dist/worker.d.ts +2 -0
  40. package/dist/worker.d.ts.map +1 -0
  41. package/dist/worker.js +1310 -0
  42. package/dist/worker.js.map +1 -0
  43. package/dist/workflow.d.ts +27 -0
  44. package/dist/workflow.d.ts.map +1 -0
  45. package/package.json +95 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,89 @@
1
+ # @mastra/temporal
2
+
3
+ ## 0.0.0-observe-20260504181920
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
+ ```
35
+
36
+ ### Patch Changes
37
+
38
+ - Updated dependencies [[`6dcd65f`](https://github.com/mastra-ai/mastra/commit/6dcd65f2a34069e6dc43ba35f1d11119b9b40bef), [`86c0298`](https://github.com/mastra-ai/mastra/commit/86c0298e647306423c842f9d5ac827bd616bd13d), [`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`ca28c23`](https://github.com/mastra-ai/mastra/commit/ca28c232a2f18801a6cf20fe053479237b4d4fb0), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`7fce309`](https://github.com/mastra-ai/mastra/commit/7fce30912b14170bfc41f0ac736cca0f39fe0cd4), [`1c2dda8`](https://github.com/mastra-ai/mastra/commit/1c2dda805fbfccc0abf55d4cb20cc34402dc3f0c), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`7997c2e`](https://github.com/mastra-ai/mastra/commit/7997c2e55ddd121562a4098cd8d2b89c68433bf1), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`e97ccb9`](https://github.com/mastra-ai/mastra/commit/e97ccb900f8b7a390ce82c9f8eb8d6eb2c5e3777), [`c5daf48`](https://github.com/mastra-ai/mastra/commit/c5daf48556e98c46ae06caf00f92c249912007e9), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`cd96779`](https://github.com/mastra-ai/mastra/commit/cd9677937f113b2856dc8b9f3d4bdabcee58bb2e), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d)]:
39
+ - @mastra/core@0.0.0-observe-20260504181920
40
+ - @mastra/deployer@0.0.0-observe-20260504181920
41
+
42
+ ## 0.1.0-alpha.2
43
+
44
+ ### Patch Changes
45
+
46
+ - Updated dependencies [[`ca28c23`](https://github.com/mastra-ai/mastra/commit/ca28c232a2f18801a6cf20fe053479237b4d4fb0)]:
47
+ - @mastra/core@1.32.0-alpha.3
48
+ - @mastra/deployer@1.32.0-alpha.3
49
+
50
+ ## 0.1.0-alpha.1
51
+
52
+ ### Patch Changes
53
+
54
+ - 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)]:
55
+ - @mastra/core@1.32.0-alpha.2
56
+ - @mastra/deployer@1.32.0-alpha.2
57
+
58
+ ## 0.1.0-alpha.0
59
+
60
+ ### Minor Changes
61
+
62
+ - Added the new `@mastra/temporal` package for running Mastra workflows on Temporal. ([#15789](https://github.com/mastra-ai/mastra/pull/15789))
63
+
64
+ **What changed**
65
+ - Added `init()` to create Temporal-backed Mastra workflows and steps.
66
+ - Added `MastraPlugin` to bundle workflow code for Temporal workers and load generated activities.
67
+ - Added `debug: true` support to write transformed workflow modules and emitted bundles to `.mastra/temporal`.
68
+
69
+ **Example**
70
+
71
+ ```ts
72
+ import { init } from '@mastra/temporal';
73
+ import { MastraPlugin } from '@mastra/temporal/worker';
74
+ import { Client, Connection } from '@temporalio/client';
75
+ import { Worker } from '@temporalio/worker';
76
+
77
+ const connection = await Connection.connect();
78
+ const client = new Client({ connection });
79
+ const { createWorkflow, createStep } = init({ client, taskQueue: 'mastra' });
80
+
81
+ const step = createStep({ id: 'hello', execute: async () => 'world' });
82
+ export const helloWorkflow = createWorkflow({ id: 'hello-workflow' }).then(step);
83
+
84
+ await Worker.create({
85
+ connection,
86
+ taskQueue: 'mastra',
87
+ plugins: [new MastraPlugin({ src: import.meta.resolve('./mastra/index.ts') })],
88
+ });
89
+ ```
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 ADDED
@@ -0,0 +1,107 @@
1
+ # @mastra/temporal
2
+
3
+ Run Mastra workflows on [Temporal](https://temporal.io/) with a workflow authoring API that stays close to standard Mastra workflows.
4
+
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"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+
3
+ var chunkDYBSPLCJ_cjs = require('./chunk-DYBSPLCJ.cjs');
4
+ var workflows = require('@mastra/core/workflows');
5
+
6
+ var TemporalRun = class extends workflows.Run {
7
+ client;
8
+ taskQueue;
9
+ constructor(params, temporalParams) {
10
+ super(params);
11
+ this.client = temporalParams.client;
12
+ this.taskQueue = temporalParams.taskQueue;
13
+ }
14
+ async start(args = {}) {
15
+ const input = await this._validateInput(args.inputData);
16
+ const initialState = await this._validateInitialState(args.initialState);
17
+ await this._validateRequestContext(args.requestContext);
18
+ try {
19
+ const handle = await this.client.workflow.start(chunkDYBSPLCJ_cjs.toWorkflowType(this.workflowId), {
20
+ taskQueue: this.taskQueue,
21
+ workflowId: this.runId,
22
+ args: [
23
+ {
24
+ inputData: input,
25
+ initialState,
26
+ requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},
27
+ runId: this.runId,
28
+ resourceId: this.resourceId,
29
+ outputOptions: args.outputOptions,
30
+ tracingOptions: args.tracingOptions,
31
+ perStep: args.perStep
32
+ }
33
+ ]
34
+ });
35
+ const result = await handle.result();
36
+ return {
37
+ status: "success",
38
+ input,
39
+ result,
40
+ state: initialState,
41
+ steps: {}
42
+ };
43
+ } catch (error) {
44
+ return {
45
+ status: "failed",
46
+ input,
47
+ error: error instanceof Error ? error : new Error(String(error)),
48
+ state: initialState,
49
+ steps: {}
50
+ };
51
+ }
52
+ }
53
+ async startAsync(args = {}) {
54
+ const input = await this._validateInput(args.inputData);
55
+ const initialState = await this._validateInitialState(args.initialState);
56
+ await this._validateRequestContext(args.requestContext);
57
+ await this.client.workflow.start(chunkDYBSPLCJ_cjs.toWorkflowType(this.workflowId), {
58
+ taskQueue: this.taskQueue,
59
+ workflowId: this.runId,
60
+ args: [
61
+ {
62
+ inputData: input,
63
+ initialState,
64
+ requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},
65
+ runId: this.runId,
66
+ resourceId: this.resourceId,
67
+ outputOptions: args.outputOptions,
68
+ tracingOptions: args.tracingOptions,
69
+ perStep: args.perStep
70
+ }
71
+ ]
72
+ });
73
+ return { runId: this.runId };
74
+ }
75
+ };
76
+
77
+ // src/workflow.ts
78
+ var TemporalWorkflow = class extends workflows.Workflow {
79
+ temporalClient;
80
+ taskQueue;
81
+ startToCloseTimeout;
82
+ constructor(params, temporalParams) {
83
+ super(params);
84
+ this.engineType = "temporal";
85
+ this.temporalClient = temporalParams.client;
86
+ this.taskQueue = temporalParams.taskQueue;
87
+ this.startToCloseTimeout = temporalParams.startToCloseTimeout ?? "1 minute";
88
+ }
89
+ async createRun(options) {
90
+ const runId = options?.runId ?? crypto.randomUUID();
91
+ const run = new TemporalRun(
92
+ {
93
+ workflowId: this.id,
94
+ runId,
95
+ resourceId: options?.resourceId,
96
+ stateSchema: this.stateSchema,
97
+ inputSchema: this.inputSchema,
98
+ requestContextSchema: this.requestContextSchema,
99
+ executionEngine: this.executionEngine,
100
+ executionGraph: this.executionGraph,
101
+ mastra: this.mastra,
102
+ retryConfig: this.retryConfig,
103
+ serializedStepGraph: this.serializedStepGraph,
104
+ disableScorers: options?.disableScorers,
105
+ tracingPolicy: this.options.tracingPolicy,
106
+ workflowSteps: this.steps,
107
+ validateInputs: this.options.validateInputs,
108
+ workflowEngineType: this.engineType,
109
+ cleanup: void 0
110
+ },
111
+ {
112
+ client: this.temporalClient,
113
+ taskQueue: this.taskQueue
114
+ }
115
+ );
116
+ this.runs.set(runId, run);
117
+ return run;
118
+ }
119
+ };
120
+ function createWorkflow(config, temporal) {
121
+ return new TemporalWorkflow(config, temporal);
122
+ }
123
+ function init(temporalParams) {
124
+ return {
125
+ createWorkflow: (config) => createWorkflow(config, temporalParams),
126
+ createStep: workflows.createStep
127
+ };
128
+ }
129
+
130
+ exports.init = init;
131
+ //# sourceMappingURL=index.cjs.map
132
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/run.ts","../src/workflow.ts"],"names":["Run","toWorkflowType","Workflow","createStep"],"mappings":";;;;;AAaO,IAAM,WAAA,GAAN,cAcGA,aAAA,CAA0E;AAAA,EACjE,MAAA;AAAA,EACA,SAAA;AAAA,EAEjB,WAAA,CACE,QACA,cAAA,EAIA;AACA,IAAA,KAAA,CAAM,MAAM,CAAA;AAEZ,IAAA,IAAA,CAAK,SAAS,cAAA,CAAe,MAAA;AAC7B,IAAA,IAAA,CAAK,YAAY,cAAA,CAAe,SAAA;AAAA,EAClC;AAAA,EAEA,MAAM,KAAA,CAAM,IAAA,GAA8D,EAAC,EAAG;AAC5E,IAAA,MAAM,KAAA,GAAQ,MAAM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AACA,EAAA,OAAO,IAAI,gBAAA,CAAwF,MAAA,EAAQ,QAAQ,CAAA;AACrH;AAEO,SAAS,KAAK,cAAA,EAAwC;AAC3D,EAAA,OAAO;AAAA,IACL,cAAA,EAAgB,CAQd,MAAA,KACG,cAAA,CAA8E,QAAQ,cAAc,CAAA;AAAA,gBACzGC;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import type { RequestContext } from '@mastra/core/di';\nimport { Run } from '@mastra/core/workflows';\nimport type { Step, WorkflowResult, WorkflowRunStartOptions } from '@mastra/core/workflows';\nimport type { Client } from '@temporalio/client';\nimport type { TemporalEngineType } from './types';\nimport { toWorkflowType } from './utils';\n\ntype TemporalRunStartArgs<TState, TInput, TRequestContext> = {\n inputData?: TInput;\n initialState?: TState;\n requestContext?: RequestContext<TRequestContext>;\n} & WorkflowRunStartOptions;\n\nexport class TemporalRun<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext> {\n private readonly client: Client;\n private readonly taskQueue: string;\n\n constructor(\n params: ConstructorParameters<typeof Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>>[0],\n temporalParams: {\n client: Client;\n taskQueue: string;\n },\n ) {\n super(params);\n\n this.client = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n }\n\n async start(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const input = await this._validateInput(args.inputData);\n const initialState = await this._validateInitialState(args.initialState);\n await this._validateRequestContext(args.requestContext as RequestContext<unknown> | undefined);\n\n try {\n const handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n },\n ],\n });\n const result = await handle.result();\n\n return {\n status: 'success',\n input: input as TInput,\n result: result as TOutput,\n state: initialState,\n steps: {},\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n } catch (error) {\n return {\n status: 'failed',\n input: input as TInput,\n error: error instanceof Error ? error : new Error(String(error)),\n state: initialState,\n steps: {},\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n }\n }\n\n async startAsync(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const input = await this._validateInput(args.inputData);\n const initialState = await this._validateInitialState(args.initialState);\n await this._validateRequestContext(args.requestContext as RequestContext<unknown> | undefined);\n\n await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n },\n ],\n });\n\n return { runId: this.runId };\n }\n}\n","import { Workflow, createStep } from '@mastra/core/workflows';\nimport type { Step, WorkflowConfig } from '@mastra/core/workflows';\nimport type { Client } from '@temporalio/client';\nimport { TemporalRun } from './run';\nimport type { TemporalEngineType } from './types';\n\nexport type TemporalWorkflowParams = {\n client: Client;\n taskQueue: string;\n startToCloseTimeout?: string;\n};\n\nexport class TemporalWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TPrevSchema = TInput,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Workflow<TemporalEngineType, TSteps, TWorkflowId, TState, TInput, TOutput, TPrevSchema, TRequestContext> {\n private readonly temporalClient: Client;\n readonly taskQueue: string;\n readonly startToCloseTimeout: string;\n\n constructor(\n params: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporalParams: TemporalWorkflowParams,\n ) {\n super(params);\n\n this.engineType = 'temporal';\n this.temporalClient = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n this.startToCloseTimeout = temporalParams.startToCloseTimeout ?? '1 minute';\n }\n\n async createRun(options?: { runId?: string; resourceId?: string; disableScorers?: boolean }) {\n const runId = options?.runId ?? crypto.randomUUID();\n const run = new TemporalRun<TSteps, TState, TInput, TOutput, TRequestContext>(\n {\n workflowId: this.id,\n runId,\n resourceId: options?.resourceId,\n stateSchema: this.stateSchema,\n inputSchema: this.inputSchema,\n requestContextSchema: this.requestContextSchema,\n executionEngine: this.executionEngine,\n executionGraph: this.executionGraph,\n mastra: this.mastra,\n retryConfig: this.retryConfig,\n serializedStepGraph: this.serializedStepGraph,\n disableScorers: options?.disableScorers,\n tracingPolicy: this.options.tracingPolicy,\n workflowSteps: this.steps,\n validateInputs: this.options.validateInputs,\n workflowEngineType: this.engineType,\n cleanup: undefined,\n },\n {\n client: this.temporalClient,\n taskQueue: this.taskQueue,\n },\n );\n\n this.runs.set(runId, run);\n return run;\n }\n}\n\nexport function createWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n>(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporal: TemporalWorkflowParams,\n) {\n return new TemporalWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TInput, TRequestContext>(config, temporal);\n}\n\nexport function init(temporalParams: TemporalWorkflowParams) {\n return {\n createWorkflow: <\n TWorkflowId extends string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TSteps extends Step[] = Step[],\n TRequestContext extends Record<string, any> | unknown = unknown,\n >(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n ) => createWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TRequestContext>(config, temporalParams),\n createStep,\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export { init } from './workflow.js';
2
+ export type { TemporalWorkflowParams, TemporalWorkflow } from './workflow.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,YAAY,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,130 @@
1
+ import { toWorkflowType } from './chunk-BF6TR7JX.js';
2
+ import { createStep, Workflow, Run } from '@mastra/core/workflows';
3
+
4
+ var TemporalRun = class extends Run {
5
+ client;
6
+ taskQueue;
7
+ constructor(params, temporalParams) {
8
+ super(params);
9
+ this.client = temporalParams.client;
10
+ this.taskQueue = temporalParams.taskQueue;
11
+ }
12
+ async start(args = {}) {
13
+ const input = await this._validateInput(args.inputData);
14
+ const initialState = await this._validateInitialState(args.initialState);
15
+ await this._validateRequestContext(args.requestContext);
16
+ try {
17
+ const handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {
18
+ taskQueue: this.taskQueue,
19
+ workflowId: this.runId,
20
+ args: [
21
+ {
22
+ inputData: input,
23
+ initialState,
24
+ requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},
25
+ runId: this.runId,
26
+ resourceId: this.resourceId,
27
+ outputOptions: args.outputOptions,
28
+ tracingOptions: args.tracingOptions,
29
+ perStep: args.perStep
30
+ }
31
+ ]
32
+ });
33
+ const result = await handle.result();
34
+ return {
35
+ status: "success",
36
+ input,
37
+ result,
38
+ state: initialState,
39
+ steps: {}
40
+ };
41
+ } catch (error) {
42
+ return {
43
+ status: "failed",
44
+ input,
45
+ error: error instanceof Error ? error : new Error(String(error)),
46
+ state: initialState,
47
+ steps: {}
48
+ };
49
+ }
50
+ }
51
+ async startAsync(args = {}) {
52
+ const input = await this._validateInput(args.inputData);
53
+ const initialState = await this._validateInitialState(args.initialState);
54
+ await this._validateRequestContext(args.requestContext);
55
+ await this.client.workflow.start(toWorkflowType(this.workflowId), {
56
+ taskQueue: this.taskQueue,
57
+ workflowId: this.runId,
58
+ args: [
59
+ {
60
+ inputData: input,
61
+ initialState,
62
+ requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},
63
+ runId: this.runId,
64
+ resourceId: this.resourceId,
65
+ outputOptions: args.outputOptions,
66
+ tracingOptions: args.tracingOptions,
67
+ perStep: args.perStep
68
+ }
69
+ ]
70
+ });
71
+ return { runId: this.runId };
72
+ }
73
+ };
74
+
75
+ // src/workflow.ts
76
+ var TemporalWorkflow = class extends Workflow {
77
+ temporalClient;
78
+ taskQueue;
79
+ startToCloseTimeout;
80
+ constructor(params, temporalParams) {
81
+ super(params);
82
+ this.engineType = "temporal";
83
+ this.temporalClient = temporalParams.client;
84
+ this.taskQueue = temporalParams.taskQueue;
85
+ this.startToCloseTimeout = temporalParams.startToCloseTimeout ?? "1 minute";
86
+ }
87
+ async createRun(options) {
88
+ const runId = options?.runId ?? crypto.randomUUID();
89
+ const run = new TemporalRun(
90
+ {
91
+ workflowId: this.id,
92
+ runId,
93
+ resourceId: options?.resourceId,
94
+ stateSchema: this.stateSchema,
95
+ inputSchema: this.inputSchema,
96
+ requestContextSchema: this.requestContextSchema,
97
+ executionEngine: this.executionEngine,
98
+ executionGraph: this.executionGraph,
99
+ mastra: this.mastra,
100
+ retryConfig: this.retryConfig,
101
+ serializedStepGraph: this.serializedStepGraph,
102
+ disableScorers: options?.disableScorers,
103
+ tracingPolicy: this.options.tracingPolicy,
104
+ workflowSteps: this.steps,
105
+ validateInputs: this.options.validateInputs,
106
+ workflowEngineType: this.engineType,
107
+ cleanup: void 0
108
+ },
109
+ {
110
+ client: this.temporalClient,
111
+ taskQueue: this.taskQueue
112
+ }
113
+ );
114
+ this.runs.set(runId, run);
115
+ return run;
116
+ }
117
+ };
118
+ function createWorkflow(config, temporal) {
119
+ return new TemporalWorkflow(config, temporal);
120
+ }
121
+ function init(temporalParams) {
122
+ return {
123
+ createWorkflow: (config) => createWorkflow(config, temporalParams),
124
+ createStep
125
+ };
126
+ }
127
+
128
+ export { init };
129
+ //# sourceMappingURL=index.js.map
130
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/run.ts","../src/workflow.ts"],"names":[],"mappings":";;;AAaO,IAAM,WAAA,GAAN,cAcG,GAAA,CAA0E;AAAA,EACjE,MAAA;AAAA,EACA,SAAA;AAAA,EAEjB,WAAA,CACE,QACA,cAAA,EAIA;AACA,IAAA,KAAA,CAAM,MAAM,CAAA;AAEZ,IAAA,IAAA,CAAK,SAAS,cAAA,CAAe,MAAA;AAC7B,IAAA,IAAA,CAAK,YAAY,cAAA,CAAe,SAAA;AAAA,EAClC;AAAA,EAEA,MAAM,KAAA,CAAM,IAAA,GAA8D,EAAC,EAAG;AAC5E,IAAA,MAAM,KAAA,GAAQ,MAAM,IAAA,CAAK,cAAA,CAAe,KAAK,SAAS,CAAA;AACtD,IAAA,MAAM,YAAA,GAAe,MAAM,IAAA,CAAK,qBAAA,CAAsB,KAAK,YAAY,CAAA;AACvE,IAAA,MAAM,IAAA,CAAK,uBAAA,CAAwB,IAAA,CAAK,cAAqD,CAAA;AAE7F,IAAA,IAAI;AACF,MAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,MAAA,CAAO,SAAS,KAAA,CAAM,cAAA,CAAe,IAAA,CAAK,UAAU,CAAA,EAAG;AAA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A,QACE,YAAY,IAAA,CAAK,EAAA;AAAA,QACjB,KAAA;AAAA,QACA,YAAY,OAAA,EAAS,UAAA;AAAA,QACrB,aAAa,IAAA,CAAK,WAAA;AAAA,QAClB,aAAa,IAAA,CAAK,WAAA;AAAA,QAClB,sBAAsB,IAAA,CAAK,oBAAA;AAAA,QAC3B,iBAAiB,IAAA,CAAK,eAAA;AAAA,QACtB,gBAAgB,IAAA,CAAK,cAAA;AAAA,QACrB,QAAQ,IAAA,CAAK,MAAA;AAAA,QACb,aAAa,IAAA,CAAK,WAAA;AAAA,QAClB,qBAAqB,IAAA,CAAK,mBAAA;AAAA,QAC1B,gBAAgB,OAAA,EAAS,cAAA;AAAA,QACzB,aAAA,EAAe,KAAK,OAAA,CAAQ,aAAA;AAAA,QAC5B,eAAe,IAAA,CAAK,KAAA;AAAA,QACpB,cAAA,EAAgB,KAAK,OAAA,CAAQ,cAAA;AAAA,QAC7B,oBAAoB,IAAA,CAAK,UAAA;AAAA,QACzB,OAAA,EAAS;AAAA,OACX;AAAA,MACA;AAAA,QACE,QAAQ,IAAA,CAAK,cAAA;AAAA,QACb,WAAW,IAAA,CAAK;AAAA;AAClB,KACF;AAEA,IAAA,IAAA,CAAK,IAAA,CAAK,GAAA,CAAI,KAAA,EAAO,GAAG,CAAA;AACxB,IAAA,OAAO,GAAA;AAAA,EACT;AACF,CAAA;AAEO,SAAS,cAAA,CAgBd,QACA,QAAA,EACA;AACA,EAAA,OAAO,IAAI,gBAAA,CAAwF,MAAA,EAAQ,QAAQ,CAAA;AACrH;AAEO,SAAS,KAAK,cAAA,EAAwC;AAC3D,EAAA,OAAO;AAAA,IACL,cAAA,EAAgB,CAQd,MAAA,KACG,cAAA,CAA8E,QAAQ,cAAc,CAAA;AAAA,IACzG;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { RequestContext } from '@mastra/core/di';\nimport { Run } from '@mastra/core/workflows';\nimport type { Step, WorkflowResult, WorkflowRunStartOptions } from '@mastra/core/workflows';\nimport type { Client } from '@temporalio/client';\nimport type { TemporalEngineType } from './types';\nimport { toWorkflowType } from './utils';\n\ntype TemporalRunStartArgs<TState, TInput, TRequestContext> = {\n inputData?: TInput;\n initialState?: TState;\n requestContext?: RequestContext<TRequestContext>;\n} & WorkflowRunStartOptions;\n\nexport class TemporalRun<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext> {\n private readonly client: Client;\n private readonly taskQueue: string;\n\n constructor(\n params: ConstructorParameters<typeof Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>>[0],\n temporalParams: {\n client: Client;\n taskQueue: string;\n },\n ) {\n super(params);\n\n this.client = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n }\n\n async start(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const input = await this._validateInput(args.inputData);\n const initialState = await this._validateInitialState(args.initialState);\n await this._validateRequestContext(args.requestContext as RequestContext<unknown> | undefined);\n\n try {\n const handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n },\n ],\n });\n const result = await handle.result();\n\n return {\n status: 'success',\n input: input as TInput,\n result: result as TOutput,\n state: initialState,\n steps: {},\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n } catch (error) {\n return {\n status: 'failed',\n input: input as TInput,\n error: error instanceof Error ? error : new Error(String(error)),\n state: initialState,\n steps: {},\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n }\n }\n\n async startAsync(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const input = await this._validateInput(args.inputData);\n const initialState = await this._validateInitialState(args.initialState);\n await this._validateRequestContext(args.requestContext as RequestContext<unknown> | undefined);\n\n await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n },\n ],\n });\n\n return { runId: this.runId };\n }\n}\n","import { Workflow, createStep } from '@mastra/core/workflows';\nimport type { Step, WorkflowConfig } from '@mastra/core/workflows';\nimport type { Client } from '@temporalio/client';\nimport { TemporalRun } from './run';\nimport type { TemporalEngineType } from './types';\n\nexport type TemporalWorkflowParams = {\n client: Client;\n taskQueue: string;\n startToCloseTimeout?: string;\n};\n\nexport class TemporalWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TPrevSchema = TInput,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Workflow<TemporalEngineType, TSteps, TWorkflowId, TState, TInput, TOutput, TPrevSchema, TRequestContext> {\n private readonly temporalClient: Client;\n readonly taskQueue: string;\n readonly startToCloseTimeout: string;\n\n constructor(\n params: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporalParams: TemporalWorkflowParams,\n ) {\n super(params);\n\n this.engineType = 'temporal';\n this.temporalClient = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n this.startToCloseTimeout = temporalParams.startToCloseTimeout ?? '1 minute';\n }\n\n async createRun(options?: { runId?: string; resourceId?: string; disableScorers?: boolean }) {\n const runId = options?.runId ?? crypto.randomUUID();\n const run = new TemporalRun<TSteps, TState, TInput, TOutput, TRequestContext>(\n {\n workflowId: this.id,\n runId,\n resourceId: options?.resourceId,\n stateSchema: this.stateSchema,\n inputSchema: this.inputSchema,\n requestContextSchema: this.requestContextSchema,\n executionEngine: this.executionEngine,\n executionGraph: this.executionGraph,\n mastra: this.mastra,\n retryConfig: this.retryConfig,\n serializedStepGraph: this.serializedStepGraph,\n disableScorers: options?.disableScorers,\n tracingPolicy: this.options.tracingPolicy,\n workflowSteps: this.steps,\n validateInputs: this.options.validateInputs,\n workflowEngineType: this.engineType,\n cleanup: undefined,\n },\n {\n client: this.temporalClient,\n taskQueue: this.taskQueue,\n },\n );\n\n this.runs.set(runId, run);\n return run;\n }\n}\n\nexport function createWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n>(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporal: TemporalWorkflowParams,\n) {\n return new TemporalWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TInput, TRequestContext>(config, temporal);\n}\n\nexport function init(temporalParams: TemporalWorkflowParams) {\n return {\n createWorkflow: <\n TWorkflowId extends string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TSteps extends Step[] = Step[],\n TRequestContext extends Record<string, any> | unknown = unknown,\n >(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n ) => createWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TRequestContext>(config, temporalParams),\n createStep,\n };\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import { Bundler } from '@mastra/deployer/bundler';
2
+
3
+ // src/mastra-deployer.ts
4
+ var BuildBundler = class extends Bundler {
5
+ constructor() {
6
+ super("Temporal");
7
+ this.platform = process.versions?.bun ? "neutral" : "node";
8
+ }
9
+ async getUserBundlerOptions(mastraEntryFile, outputDirectory) {
10
+ const bundlerOptions = await super.getUserBundlerOptions(mastraEntryFile, outputDirectory);
11
+ return {
12
+ ...bundlerOptions,
13
+ externals: true,
14
+ sourcemap: true
15
+ };
16
+ }
17
+ getEnvFiles() {
18
+ return Promise.resolve([]);
19
+ }
20
+ installDependencies() {
21
+ return Promise.resolve();
22
+ }
23
+ copyPublic() {
24
+ return Promise.resolve();
25
+ }
26
+ writePackageJson() {
27
+ return Promise.resolve();
28
+ }
29
+ async bundle(entryFile, outputDirectory, { toolsPaths, projectRoot }) {
30
+ return this._bundle(entryFile, entryFile, { outputDirectory, projectRoot }, toolsPaths);
31
+ }
32
+ async lint(entryFile, outputDirectory, toolsPaths) {
33
+ await super.lint(entryFile, outputDirectory, toolsPaths);
34
+ }
35
+ };
36
+
37
+ export { BuildBundler };
38
+ //# sourceMappingURL=mastra-deployer-UCBGECM5.js.map
39
+ //# sourceMappingURL=mastra-deployer-UCBGECM5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mastra-deployer.ts"],"names":[],"mappings":";;;AAGO,IAAM,YAAA,GAAN,cAA2B,OAAA,CAAQ;AAAA,EACxC,WAAA,GAAc;AACZ,IAAA,KAAA,CAAM,UAAU,CAAA;AAChB,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA,CAAQ,QAAA,EAAU,GAAA,GAAM,SAAA,GAAY,MAAA;AAAA,EACtD;AAAA,EAEA,MAAgB,qBAAA,CACd,eAAA,EACA,eAAA,EACyC;AACzC,IAAA,MAAM,cAAA,GAAiB,MAAM,KAAA,CAAM,qBAAA,CAAsB,iBAAiB,eAAe,CAAA;AAEzF,IAAA,OAAO;AAAA,MACL,GAAG,cAAA;AAAA,MACH,SAAA,EAAW,IAAA;AAAA,MACX,SAAA,EAAW;AAAA,KACb;AAAA,EACF;AAAA,EAEA,WAAA,GAAiC;AAC/B,IAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,EAAE,CAAA;AAAA,EAC3B;AAAA,EAEU,mBAAA,GAAqC;AAC7C,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AAAA,EAEU,UAAA,GAA4B;AACpC,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AAAA,EAEA,gBAAA,GAAkC;AAChC,IAAA,OAAO,QAAQ,OAAA,EAAQ;AAAA,EACzB;AAAA,EAEA,MAAM,MAAA,CACJ,SAAA,EACA,iBACA,EAAE,UAAA,EAAY,aAAY,EACX;AACf,IAAA,OAAO,IAAA,CAAK,QAAQ,SAAA,EAAW,SAAA,EAAW,EAAE,eAAA,EAAiB,WAAA,IAAe,UAAU,CAAA;AAAA,EACxF;AAAA,EAEA,MAAM,IAAA,CAAK,SAAA,EAAmB,eAAA,EAAyB,UAAA,EAAkD;AACvG,IAAA,MAAM,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,eAAA,EAAiB,UAAU,CAAA;AAAA,EACzD;AACF","file":"mastra-deployer-UCBGECM5.js","sourcesContent":["import type { Config } from '@mastra/core/mastra';\nimport { Bundler } from '@mastra/deployer/bundler';\n\nexport class BuildBundler extends Bundler {\n constructor() {\n super('Temporal');\n this.platform = process.versions?.bun ? 'neutral' : 'node';\n }\n\n protected async getUserBundlerOptions(\n mastraEntryFile: string,\n outputDirectory: string,\n ): Promise<NonNullable<Config['bundler']>> {\n const bundlerOptions = await super.getUserBundlerOptions(mastraEntryFile, outputDirectory);\n\n return {\n ...bundlerOptions,\n externals: true,\n sourcemap: true,\n };\n }\n\n getEnvFiles(): Promise<string[]> {\n return Promise.resolve([]);\n }\n\n protected installDependencies(): Promise<void> {\n return Promise.resolve();\n }\n\n protected copyPublic(): Promise<void> {\n return Promise.resolve();\n }\n\n writePackageJson(): Promise<void> {\n return Promise.resolve();\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n return this._bundle(entryFile, entryFile, { outputDirectory, projectRoot }, toolsPaths);\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n }\n}\n"]}