@mastra/temporal 0.2.11-alpha.0 → 0.2.11-alpha.2

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/dist/worker.cjs CHANGED
@@ -1,511 +1,346 @@
1
- 'use strict';
2
-
3
- var chunkDYBSPLCJ_cjs = require('./chunk-DYBSPLCJ.cjs');
4
- var fs = require('fs');
5
- var promises = require('fs/promises');
6
- var path = require('path');
7
- var url = require('url');
8
- var generator = require('@babel/generator');
9
- var parser = require('@babel/parser');
10
- var t3 = require('@babel/types');
11
- var rollup = require('rollup');
12
-
13
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
14
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
-
16
- function _interopNamespace(e) {
17
- if (e && e.__esModule) return e;
18
- var n = Object.create(null);
19
- if (e) {
20
- Object.keys(e).forEach(function (k) {
21
- if (k !== 'default') {
22
- var d = Object.getOwnPropertyDescriptor(e, k);
23
- Object.defineProperty(n, k, d.get ? d : {
24
- enumerable: true,
25
- get: function () { return e[k]; }
26
- });
27
- }
28
- });
29
- }
30
- n.default = e;
31
- return Object.freeze(n);
32
- }
33
-
34
- var path__default = /*#__PURE__*/_interopDefault(path);
35
- var t3__namespace = /*#__PURE__*/_interopNamespace(t3);
36
-
37
- var parserPlugins = ["typescript", "jsx", "decorators-legacy"];
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ const require_utils = require("./utils-D94W1i81.cjs");
25
+ let fs = require("fs");
26
+ let fs_promises = require("fs/promises");
27
+ let path = require("path");
28
+ path = __toESM(path, 1);
29
+ let url = require("url");
30
+ let _babel_generator = require("@babel/generator");
31
+ let _babel_parser = require("@babel/parser");
32
+ let _babel_types = require("@babel/types");
33
+ _babel_types = __toESM(_babel_types, 1);
34
+ let rollup = require("rollup");
35
+ //#region src/transforms/shared.ts
36
+ const parserPlugins = [
37
+ "typescript",
38
+ "jsx",
39
+ "decorators-legacy"
40
+ ];
38
41
  function parseModule(filePath, sourceText) {
39
- if (!sourceText) {
40
- sourceText = fs.readFileSync(filePath, "utf8");
41
- }
42
- return parser.parse(sourceText, {
43
- sourceType: "module",
44
- plugins: parserPlugins,
45
- sourceFilename: filePath
46
- });
42
+ if (!sourceText) sourceText = (0, fs.readFileSync)(filePath, "utf8");
43
+ return (0, _babel_parser.parse)(sourceText, {
44
+ sourceType: "module",
45
+ plugins: parserPlugins,
46
+ sourceFilename: filePath
47
+ });
47
48
  }
48
49
  function isIdentifierNamed(node, name) {
49
- return t3__namespace.isIdentifier(node) && node.name === name;
50
+ return _babel_types.isIdentifier(node) && node.name === name;
50
51
  }
51
52
  function isTemporalHelperModule(source) {
52
- return typeof source === "string" && /(^|\/)temporal\.(ts|tsx|js|jsx|mts|mjs)$/.test(source);
53
+ return typeof source === "string" && /(^|\/)temporal\.(ts|tsx|js|jsx|mts|mjs)$/.test(source);
53
54
  }
54
- var strippedExternalModules = /* @__PURE__ */ new Set(["@temporalio/client", "@temporalio/envconfig"]);
55
+ const strippedExternalModules = /* @__PURE__ */ new Set(["@temporalio/client", "@temporalio/envconfig"]);
55
56
  function isStrippedExternalModule(source) {
56
- return typeof source === "string" && strippedExternalModules.has(source);
57
+ return typeof source === "string" && strippedExternalModules.has(source);
57
58
  }
58
59
  function collectImportedNames(statement) {
59
- const names = /* @__PURE__ */ new Set();
60
- for (const specifier of statement.specifiers) {
61
- if (t3__namespace.isImportDefaultSpecifier(specifier) || t3__namespace.isImportNamespaceSpecifier(specifier) || t3__namespace.isImportSpecifier(specifier)) {
62
- if (t3__namespace.isIdentifier(specifier.local)) {
63
- names.add(specifier.local.name);
64
- }
65
- }
66
- }
67
- return names;
60
+ const names = /* @__PURE__ */ new Set();
61
+ for (const specifier of statement.specifiers) if (_babel_types.isImportDefaultSpecifier(specifier) || _babel_types.isImportNamespaceSpecifier(specifier) || _babel_types.isImportSpecifier(specifier)) {
62
+ if (_babel_types.isIdentifier(specifier.local)) names.add(specifier.local.name);
63
+ }
64
+ return names;
68
65
  }
69
66
  function nodeReferencesName(node, names) {
70
- let found = false;
71
- walk(node, (current) => {
72
- if (t3__namespace.isIdentifier(current) && names.has(current.name)) {
73
- found = true;
74
- return false;
75
- }
76
- });
77
- return found;
67
+ let found = false;
68
+ walk(node, (current) => {
69
+ if (_babel_types.isIdentifier(current) && names.has(current.name)) {
70
+ found = true;
71
+ return false;
72
+ }
73
+ });
74
+ return found;
78
75
  }
79
76
  function isWorkflowHelperDestructure(declaration) {
80
- if (!t3__namespace.isObjectPattern(declaration.id)) {
81
- return false;
82
- }
83
- return declaration.id.properties.some(
84
- (property) => t3__namespace.isObjectProperty(property) && !property.computed && t3__namespace.isIdentifier(property.value) && (property.value.name === "createStep" || property.value.name === "createWorkflow")
85
- );
77
+ if (!_babel_types.isObjectPattern(declaration.id)) return false;
78
+ return declaration.id.properties.some((property) => _babel_types.isObjectProperty(property) && !property.computed && _babel_types.isIdentifier(property.value) && (property.value.name === "createStep" || property.value.name === "createWorkflow"));
86
79
  }
87
80
  function isCreateWorkflowCall(node) {
88
- return t3__namespace.isCallExpression(node) && isIdentifierNamed(node.callee, "createWorkflow");
81
+ return _babel_types.isCallExpression(node) && isIdentifierNamed(node.callee, "createWorkflow");
89
82
  }
90
83
  function isCreateStepCall(node) {
91
- return t3__namespace.isCallExpression(node) && isIdentifierNamed(node.callee, "createStep");
84
+ return _babel_types.isCallExpression(node) && isIdentifierNamed(node.callee, "createStep");
92
85
  }
93
86
  function getObjectPropertyName(property) {
94
- if (property.computed) {
95
- return null;
96
- }
97
- if (t3__namespace.isIdentifier(property.key)) {
98
- return property.key.name;
99
- }
100
- if (t3__namespace.isStringLiteral(property.key)) {
101
- return property.key.value;
102
- }
103
- return null;
87
+ if (property.computed) return null;
88
+ if (_babel_types.isIdentifier(property.key)) return property.key.name;
89
+ if (_babel_types.isStringLiteral(property.key)) return property.key.value;
90
+ return null;
104
91
  }
105
92
  function walk(node, visitor) {
106
- if (!node) {
107
- return;
108
- }
109
- const result = visitor(node);
110
- if (result === false) {
111
- return;
112
- }
113
- const keys = t3__namespace.VISITOR_KEYS[node.type] ?? [];
114
- for (const key of keys) {
115
- const value = node[key];
116
- if (Array.isArray(value)) {
117
- for (const child of value) {
118
- if (child && typeof child.type === "string") {
119
- walk(child, visitor);
120
- }
121
- }
122
- continue;
123
- }
124
- if (value && typeof value.type === "string") {
125
- walk(value, visitor);
126
- }
127
- }
93
+ if (!node) return;
94
+ if (visitor(node) === false) return;
95
+ const keys = _babel_types.VISITOR_KEYS[node.type] ?? [];
96
+ for (const key of keys) {
97
+ const value = node[key];
98
+ if (Array.isArray(value)) {
99
+ for (const child of value) if (child && typeof child.type === "string") walk(child, visitor);
100
+ continue;
101
+ }
102
+ if (value && typeof value.type === "string") walk(value, visitor);
103
+ }
128
104
  }
129
105
  function hasCreateWorkflowCall(node) {
130
- let found = false;
131
- walk(node, (current) => {
132
- if (isCreateWorkflowCall(current)) {
133
- found = true;
134
- return false;
135
- }
136
- });
137
- return found;
106
+ let found = false;
107
+ walk(node, (current) => {
108
+ if (isCreateWorkflowCall(current)) {
109
+ found = true;
110
+ return false;
111
+ }
112
+ });
113
+ return found;
138
114
  }
139
115
  function getStepNameFromCall(node) {
140
- const stepId = getCreateStepId(node);
141
- if (!stepId) {
142
- return null;
143
- }
144
- return stepId.replace(/[^a-zA-Z0-9]+(.)/g, (_match, char) => char.toUpperCase()).replace(/^[^a-zA-Z_$]+/, "").replace(/^(.)/, (char) => char.toLowerCase());
116
+ const stepId = getCreateStepId(node);
117
+ if (!stepId) return null;
118
+ return stepId.replace(/[^a-zA-Z0-9]+(.)/g, (_match, char) => char.toUpperCase()).replace(/^[^a-zA-Z_$]+/, "").replace(/^(.)/, (char) => char.toLowerCase());
145
119
  }
146
120
  function createExportedStepStatement(name, initializer) {
147
- return t3__namespace.exportNamedDeclaration(
148
- t3__namespace.variableDeclaration("const", [t3__namespace.variableDeclarator(t3__namespace.identifier(name), t3__namespace.cloneNode(initializer, true))])
149
- );
121
+ return _babel_types.exportNamedDeclaration(_babel_types.variableDeclaration("const", [_babel_types.variableDeclarator(_babel_types.identifier(name), _babel_types.cloneNode(initializer, true))]));
150
122
  }
151
123
  function collectInlineCreateSteps(node, seenNames, statements, onStep) {
152
- walk(node, (current) => {
153
- if (!isCreateStepCall(current)) {
154
- return;
155
- }
156
- const stepName = getStepNameFromCall(current);
157
- if (!stepName || seenNames.has(stepName)) {
158
- return false;
159
- }
160
- seenNames.add(stepName);
161
- onStep?.(stepName, current);
162
- statements.push(createExportedStepStatement(stepName, current));
163
- return false;
164
- });
124
+ walk(node, (current) => {
125
+ if (!isCreateStepCall(current)) return;
126
+ const stepName = getStepNameFromCall(current);
127
+ if (!stepName || seenNames.has(stepName)) return false;
128
+ seenNames.add(stepName);
129
+ onStep?.(stepName, current);
130
+ statements.push(createExportedStepStatement(stepName, current));
131
+ return false;
132
+ });
165
133
  }
166
134
  function getReturnedCreateStepCall(node) {
167
- if (!node) {
168
- return null;
169
- }
170
- if (t3__namespace.isArrowFunctionExpression(node) && !t3__namespace.isBlockStatement(node.body)) {
171
- return t3__namespace.isCallExpression(node.body) && isIdentifierNamed(node.body.callee, "createStep") ? node.body : null;
172
- }
173
- if (!t3__namespace.isFunctionDeclaration(node) && !t3__namespace.isFunctionExpression(node) && !t3__namespace.isArrowFunctionExpression(node)) {
174
- return null;
175
- }
176
- if (!t3__namespace.isBlockStatement(node.body)) {
177
- return null;
178
- }
179
- for (const statement of node.body.body) {
180
- if (t3__namespace.isReturnStatement(statement) && t3__namespace.isCallExpression(statement.argument) && isIdentifierNamed(statement.argument.callee, "createStep")) {
181
- return statement.argument;
182
- }
183
- }
184
- return null;
135
+ if (!node) return null;
136
+ if (_babel_types.isArrowFunctionExpression(node) && !_babel_types.isBlockStatement(node.body)) return _babel_types.isCallExpression(node.body) && isIdentifierNamed(node.body.callee, "createStep") ? node.body : null;
137
+ if (!_babel_types.isFunctionDeclaration(node) && !_babel_types.isFunctionExpression(node) && !_babel_types.isArrowFunctionExpression(node)) return null;
138
+ if (!_babel_types.isBlockStatement(node.body)) return null;
139
+ for (const statement of node.body.body) if (_babel_types.isReturnStatement(statement) && _babel_types.isCallExpression(statement.argument) && isIdentifierNamed(statement.argument.callee, "createStep")) return statement.argument;
140
+ return null;
185
141
  }
186
- function collectCreateStepFactoryBindings(program3) {
187
- const factories = /* @__PURE__ */ new Map();
188
- for (const statement of program3.body) {
189
- const declaration = t3__namespace.isExportNamedDeclaration(statement) ? statement.declaration : statement;
190
- if (t3__namespace.isFunctionDeclaration(declaration) && declaration.id) {
191
- const createStepCall = getReturnedCreateStepCall(declaration);
192
- if (createStepCall) {
193
- factories.set(declaration.id.name, createStepCall);
194
- }
195
- continue;
196
- }
197
- if (!t3__namespace.isVariableDeclaration(declaration)) {
198
- continue;
199
- }
200
- for (const declarator of declaration.declarations) {
201
- if (!t3__namespace.isIdentifier(declarator.id) || !declarator.init) {
202
- continue;
203
- }
204
- const createStepCall = getReturnedCreateStepCall(declarator.init);
205
- if (createStepCall) {
206
- factories.set(declarator.id.name, createStepCall);
207
- }
208
- }
209
- }
210
- return factories;
142
+ function collectCreateStepFactoryBindings(program) {
143
+ const factories = /* @__PURE__ */ new Map();
144
+ for (const statement of program.body) {
145
+ const declaration = _babel_types.isExportNamedDeclaration(statement) ? statement.declaration : statement;
146
+ if (_babel_types.isFunctionDeclaration(declaration) && declaration.id) {
147
+ const createStepCall = getReturnedCreateStepCall(declaration);
148
+ if (createStepCall) factories.set(declaration.id.name, createStepCall);
149
+ continue;
150
+ }
151
+ if (!_babel_types.isVariableDeclaration(declaration)) continue;
152
+ for (const declarator of declaration.declarations) {
153
+ if (!_babel_types.isIdentifier(declarator.id) || !declarator.init) continue;
154
+ const createStepCall = getReturnedCreateStepCall(declarator.init);
155
+ if (createStepCall) factories.set(declarator.id.name, createStepCall);
156
+ }
157
+ }
158
+ return factories;
211
159
  }
212
160
  function getCreateStepCallFromExpression(node, factoryBindings) {
213
- if (!node) {
214
- return null;
215
- }
216
- if (t3__namespace.isCallExpression(node)) {
217
- if (isIdentifierNamed(node.callee, "createStep")) {
218
- return node;
219
- }
220
- if (t3__namespace.isIdentifier(node.callee)) {
221
- return factoryBindings.get(node.callee.name) ?? null;
222
- }
223
- }
224
- const returnedCreateStepCall = getReturnedCreateStepCall(node);
225
- if (returnedCreateStepCall) {
226
- return returnedCreateStepCall;
227
- }
228
- return null;
161
+ if (!node) return null;
162
+ if (_babel_types.isCallExpression(node)) {
163
+ if (isIdentifierNamed(node.callee, "createStep")) return node;
164
+ if (_babel_types.isIdentifier(node.callee)) return factoryBindings.get(node.callee.name) ?? null;
165
+ }
166
+ const returnedCreateStepCall = getReturnedCreateStepCall(node);
167
+ if (returnedCreateStepCall) return returnedCreateStepCall;
168
+ return null;
229
169
  }
230
170
  function getCreateStepId(node) {
231
- if (!node || !isCreateStepCall(node)) {
232
- return null;
233
- }
234
- const [config] = node.arguments;
235
- if (!t3__namespace.isObjectExpression(config)) {
236
- return null;
237
- }
238
- for (const property of config.properties) {
239
- if (!t3__namespace.isObjectProperty(property) && !t3__namespace.isObjectMethod(property)) {
240
- continue;
241
- }
242
- if (getObjectPropertyName(property) !== "id") {
243
- continue;
244
- }
245
- const value = t3__namespace.isObjectMethod(property) ? null : property.value;
246
- return t3__namespace.isStringLiteral(value) ? value.value : null;
247
- }
248
- return null;
171
+ if (!node || !isCreateStepCall(node)) return null;
172
+ const [config] = node.arguments;
173
+ if (!_babel_types.isObjectExpression(config)) return null;
174
+ for (const property of config.properties) {
175
+ if (!_babel_types.isObjectProperty(property) && !_babel_types.isObjectMethod(property)) continue;
176
+ if (getObjectPropertyName(property) !== "id") continue;
177
+ const value = _babel_types.isObjectMethod(property) ? null : property.value;
178
+ return _babel_types.isStringLiteral(value) ? value.value : null;
179
+ }
180
+ return null;
249
181
  }
250
182
  function shouldCountIdentifierAsReference(parent, key) {
251
- if (!parent) {
252
- return true;
253
- }
254
- if ((t3__namespace.isObjectProperty(parent) || t3__namespace.isObjectMethod(parent)) && key === "key" && !parent.computed) {
255
- return false;
256
- }
257
- if (t3__namespace.isMemberExpression(parent) && key === "property" && !parent.computed) {
258
- return false;
259
- }
260
- if (t3__namespace.isVariableDeclarator(parent) && key === "id") {
261
- return false;
262
- }
263
- if ((t3__namespace.isFunctionDeclaration(parent) || t3__namespace.isFunctionExpression(parent) || t3__namespace.isArrowFunctionExpression(parent)) && key === "params") {
264
- return false;
265
- }
266
- if ((t3__namespace.isFunctionDeclaration(parent) || t3__namespace.isFunctionExpression(parent) || t3__namespace.isClassDeclaration(parent)) && key === "id") {
267
- return false;
268
- }
269
- if ((t3__namespace.isImportSpecifier(parent) || t3__namespace.isImportDefaultSpecifier(parent) || t3__namespace.isImportNamespaceSpecifier(parent)) && (key === "local" || key === "imported")) {
270
- return false;
271
- }
272
- if (t3__namespace.isExportSpecifier(parent) && key === "exported") {
273
- return false;
274
- }
275
- if (t3__namespace.isLabeledStatement(parent) && key === "label") {
276
- return false;
277
- }
278
- if (t3__namespace.isCatchClause(parent) && key === "param") {
279
- return false;
280
- }
281
- if (t3__namespace.isRestElement(parent) && key === "argument") {
282
- return false;
283
- }
284
- if (t3__namespace.isAssignmentPattern(parent) && key === "left") {
285
- return false;
286
- }
287
- if (t3__namespace.isTSPropertySignature(parent) || t3__namespace.isTSMethodSignature(parent) || t3__namespace.isTSInterfaceHeritage(parent)) {
288
- return false;
289
- }
290
- return true;
183
+ if (!parent) return true;
184
+ if ((_babel_types.isObjectProperty(parent) || _babel_types.isObjectMethod(parent)) && key === "key" && !parent.computed) return false;
185
+ if (_babel_types.isMemberExpression(parent) && key === "property" && !parent.computed) return false;
186
+ if (_babel_types.isVariableDeclarator(parent) && key === "id") return false;
187
+ if ((_babel_types.isFunctionDeclaration(parent) || _babel_types.isFunctionExpression(parent) || _babel_types.isArrowFunctionExpression(parent)) && key === "params") return false;
188
+ if ((_babel_types.isFunctionDeclaration(parent) || _babel_types.isFunctionExpression(parent) || _babel_types.isClassDeclaration(parent)) && key === "id") return false;
189
+ if ((_babel_types.isImportSpecifier(parent) || _babel_types.isImportDefaultSpecifier(parent) || _babel_types.isImportNamespaceSpecifier(parent)) && (key === "local" || key === "imported")) return false;
190
+ if (_babel_types.isExportSpecifier(parent) && key === "exported") return false;
191
+ if (_babel_types.isLabeledStatement(parent) && key === "label") return false;
192
+ if (_babel_types.isCatchClause(parent) && key === "param") return false;
193
+ if (_babel_types.isRestElement(parent) && key === "argument") return false;
194
+ if (_babel_types.isAssignmentPattern(parent) && key === "left") return false;
195
+ if (_babel_types.isTSPropertySignature(parent) || _babel_types.isTSMethodSignature(parent) || _babel_types.isTSInterfaceHeritage(parent)) return false;
196
+ return true;
291
197
  }
292
198
  function collectRuntimeReferencedIdentifiers(node) {
293
- const refs = /* @__PURE__ */ new Set();
294
- const visit = (current, parent, key) => {
295
- if (!current) {
296
- return;
297
- }
298
- if (current.type.startsWith("TS")) {
299
- return;
300
- }
301
- if (t3__namespace.isIdentifier(current)) {
302
- if (shouldCountIdentifierAsReference(parent, key)) {
303
- refs.add(current.name);
304
- }
305
- return;
306
- }
307
- for (const visitorKey of t3__namespace.VISITOR_KEYS[current.type] ?? []) {
308
- const value = current[visitorKey];
309
- if (Array.isArray(value)) {
310
- value.forEach((child) => {
311
- if (t3__namespace.isNode(child)) {
312
- visit(child, current, visitorKey);
313
- }
314
- });
315
- continue;
316
- }
317
- if (t3__namespace.isNode(value)) {
318
- visit(value, current, visitorKey);
319
- }
320
- }
321
- };
322
- visit(node, null, null);
323
- return refs;
199
+ const refs = /* @__PURE__ */ new Set();
200
+ const visit = (current, parent, key) => {
201
+ if (!current) return;
202
+ if (current.type.startsWith("TS")) return;
203
+ if (_babel_types.isIdentifier(current)) {
204
+ if (shouldCountIdentifierAsReference(parent, key)) refs.add(current.name);
205
+ return;
206
+ }
207
+ for (const visitorKey of _babel_types.VISITOR_KEYS[current.type] ?? []) {
208
+ const value = current[visitorKey];
209
+ if (Array.isArray(value)) {
210
+ value.forEach((child) => {
211
+ if (_babel_types.isNode(child)) visit(child, current, visitorKey);
212
+ });
213
+ continue;
214
+ }
215
+ if (_babel_types.isNode(value)) visit(value, current, visitorKey);
216
+ }
217
+ };
218
+ visit(node, null, null);
219
+ return refs;
324
220
  }
325
221
  function pruneUnusedTopLevelBindings(statements) {
326
- const bindings = /* @__PURE__ */ new Map();
327
- const liveStatements = /* @__PURE__ */ new Set();
328
- const queue = [];
329
- const markLive = (statementIndex) => {
330
- if (liveStatements.has(statementIndex)) {
331
- return;
332
- }
333
- liveStatements.add(statementIndex);
334
- queue.push(statementIndex);
335
- };
336
- statements.forEach((statement, statementIndex) => {
337
- if (t3__namespace.isImportDeclaration(statement)) {
338
- for (const specifier of statement.specifiers) {
339
- bindings.set(specifier.local.name, { refs: /* @__PURE__ */ new Set(), statementIndex });
340
- }
341
- return;
342
- }
343
- if (t3__namespace.isVariableDeclaration(statement)) {
344
- for (const declaration of statement.declarations) {
345
- if (t3__namespace.isIdentifier(declaration.id)) {
346
- bindings.set(declaration.id.name, {
347
- refs: declaration.init ? collectRuntimeReferencedIdentifiers(declaration.init) : /* @__PURE__ */ new Set(),
348
- statementIndex
349
- });
350
- }
351
- }
352
- return;
353
- }
354
- if (t3__namespace.isExportNamedDeclaration(statement) && t3__namespace.isVariableDeclaration(statement.declaration)) {
355
- for (const declaration of statement.declaration.declarations) {
356
- if (t3__namespace.isIdentifier(declaration.id)) {
357
- bindings.set(declaration.id.name, {
358
- refs: declaration.init ? collectRuntimeReferencedIdentifiers(declaration.init) : /* @__PURE__ */ new Set(),
359
- statementIndex
360
- });
361
- }
362
- }
363
- markLive(statementIndex);
364
- return;
365
- }
366
- markLive(statementIndex);
367
- });
368
- while (queue.length > 0) {
369
- const statementIndex = queue.pop();
370
- const statement = statements[statementIndex];
371
- if (!statement) {
372
- continue;
373
- }
374
- const refs = /* @__PURE__ */ new Set();
375
- if (t3__namespace.isImportDeclaration(statement)) {
376
- continue;
377
- }
378
- if (t3__namespace.isVariableDeclaration(statement)) {
379
- for (const declaration of statement.declarations) {
380
- if (declaration.init) {
381
- for (const ref of collectRuntimeReferencedIdentifiers(declaration.init)) {
382
- refs.add(ref);
383
- }
384
- }
385
- }
386
- } else if (t3__namespace.isExportNamedDeclaration(statement) && t3__namespace.isVariableDeclaration(statement.declaration)) {
387
- for (const declaration of statement.declaration.declarations) {
388
- if (declaration.init) {
389
- for (const ref of collectRuntimeReferencedIdentifiers(declaration.init)) {
390
- refs.add(ref);
391
- }
392
- }
393
- }
394
- } else {
395
- for (const ref of collectRuntimeReferencedIdentifiers(statement)) {
396
- refs.add(ref);
397
- }
398
- }
399
- for (const ref of refs) {
400
- const binding = bindings.get(ref);
401
- if (binding) {
402
- markLive(binding.statementIndex);
403
- }
404
- }
405
- }
406
- const prunedStatements = [];
407
- statements.forEach((statement, statementIndex) => {
408
- if (!liveStatements.has(statementIndex)) {
409
- return;
410
- }
411
- if (t3__namespace.isImportDeclaration(statement)) {
412
- const specifiers = statement.specifiers.filter(
413
- (specifier) => liveStatements.has(bindings.get(specifier.local.name)?.statementIndex ?? -1)
414
- );
415
- if (specifiers.length > 0) {
416
- prunedStatements.push(t3__namespace.importDeclaration(specifiers, statement.source));
417
- }
418
- return;
419
- }
420
- if (t3__namespace.isVariableDeclaration(statement)) {
421
- const declarations = statement.declarations.filter(
422
- (declaration) => !t3__namespace.isIdentifier(declaration.id) || liveStatements.has(bindings.get(declaration.id.name)?.statementIndex ?? -1)
423
- );
424
- if (declarations.length > 0) {
425
- prunedStatements.push(t3__namespace.variableDeclaration(statement.kind, declarations));
426
- }
427
- return;
428
- }
429
- if (t3__namespace.isExportNamedDeclaration(statement) && t3__namespace.isVariableDeclaration(statement.declaration)) {
430
- const declarations = statement.declaration.declarations.filter(
431
- (declaration) => !t3__namespace.isIdentifier(declaration.id) || liveStatements.has(bindings.get(declaration.id.name)?.statementIndex ?? -1)
432
- );
433
- if (declarations.length > 0) {
434
- prunedStatements.push(
435
- t3__namespace.exportNamedDeclaration(t3__namespace.variableDeclaration(statement.declaration.kind, declarations))
436
- );
437
- }
438
- return;
439
- }
440
- prunedStatements.push(statement);
441
- });
442
- return prunedStatements;
222
+ const bindings = /* @__PURE__ */ new Map();
223
+ const liveStatements = /* @__PURE__ */ new Set();
224
+ const queue = [];
225
+ const markLive = (statementIndex) => {
226
+ if (liveStatements.has(statementIndex)) return;
227
+ liveStatements.add(statementIndex);
228
+ queue.push(statementIndex);
229
+ };
230
+ statements.forEach((statement, statementIndex) => {
231
+ if (_babel_types.isImportDeclaration(statement)) {
232
+ for (const specifier of statement.specifiers) bindings.set(specifier.local.name, {
233
+ refs: /* @__PURE__ */ new Set(),
234
+ statementIndex
235
+ });
236
+ return;
237
+ }
238
+ if (_babel_types.isVariableDeclaration(statement)) {
239
+ for (const declaration of statement.declarations) if (_babel_types.isIdentifier(declaration.id)) bindings.set(declaration.id.name, {
240
+ refs: declaration.init ? collectRuntimeReferencedIdentifiers(declaration.init) : /* @__PURE__ */ new Set(),
241
+ statementIndex
242
+ });
243
+ return;
244
+ }
245
+ if (_babel_types.isExportNamedDeclaration(statement) && _babel_types.isVariableDeclaration(statement.declaration)) {
246
+ for (const declaration of statement.declaration.declarations) if (_babel_types.isIdentifier(declaration.id)) bindings.set(declaration.id.name, {
247
+ refs: declaration.init ? collectRuntimeReferencedIdentifiers(declaration.init) : /* @__PURE__ */ new Set(),
248
+ statementIndex
249
+ });
250
+ markLive(statementIndex);
251
+ return;
252
+ }
253
+ markLive(statementIndex);
254
+ });
255
+ while (queue.length > 0) {
256
+ const statement = statements[queue.pop()];
257
+ if (!statement) continue;
258
+ const refs = /* @__PURE__ */ new Set();
259
+ if (_babel_types.isImportDeclaration(statement)) continue;
260
+ if (_babel_types.isVariableDeclaration(statement)) {
261
+ for (const declaration of statement.declarations) if (declaration.init) for (const ref of collectRuntimeReferencedIdentifiers(declaration.init)) refs.add(ref);
262
+ } else if (_babel_types.isExportNamedDeclaration(statement) && _babel_types.isVariableDeclaration(statement.declaration)) {
263
+ for (const declaration of statement.declaration.declarations) if (declaration.init) for (const ref of collectRuntimeReferencedIdentifiers(declaration.init)) refs.add(ref);
264
+ } else for (const ref of collectRuntimeReferencedIdentifiers(statement)) refs.add(ref);
265
+ for (const ref of refs) {
266
+ const binding = bindings.get(ref);
267
+ if (binding) markLive(binding.statementIndex);
268
+ }
269
+ }
270
+ const prunedStatements = [];
271
+ statements.forEach((statement, statementIndex) => {
272
+ if (!liveStatements.has(statementIndex)) return;
273
+ if (_babel_types.isImportDeclaration(statement)) {
274
+ const specifiers = statement.specifiers.filter((specifier) => liveStatements.has(bindings.get(specifier.local.name)?.statementIndex ?? -1));
275
+ if (specifiers.length > 0) prunedStatements.push(_babel_types.importDeclaration(specifiers, statement.source));
276
+ return;
277
+ }
278
+ if (_babel_types.isVariableDeclaration(statement)) {
279
+ const declarations = statement.declarations.filter((declaration) => !_babel_types.isIdentifier(declaration.id) || liveStatements.has(bindings.get(declaration.id.name)?.statementIndex ?? -1));
280
+ if (declarations.length > 0) prunedStatements.push(_babel_types.variableDeclaration(statement.kind, declarations));
281
+ return;
282
+ }
283
+ if (_babel_types.isExportNamedDeclaration(statement) && _babel_types.isVariableDeclaration(statement.declaration)) {
284
+ const declarations = statement.declaration.declarations.filter((declaration) => !_babel_types.isIdentifier(declaration.id) || liveStatements.has(bindings.get(declaration.id.name)?.statementIndex ?? -1));
285
+ if (declarations.length > 0) prunedStatements.push(_babel_types.exportNamedDeclaration(_babel_types.variableDeclaration(statement.declaration.kind, declarations)));
286
+ return;
287
+ }
288
+ prunedStatements.push(statement);
289
+ });
290
+ return prunedStatements;
443
291
  }
444
-
445
- // src/transforms/activities.ts
292
+ //#endregion
293
+ //#region src/transforms/activities.ts
446
294
  function normalizeImportPath(importPath, extension) {
447
- const normalizedPath = importPath.split(path__default.default.sep).join("/");
448
- const pathWithExtension = extension === ".mjs" || extension === ".cjs" ? normalizedPath : normalizedPath.replace(/\.[cm]?[jt]sx?$/, "");
449
- return pathWithExtension.startsWith(".") ? pathWithExtension : `./${pathWithExtension}`;
295
+ const normalizedPath = importPath.split(path.default.sep).join("/");
296
+ const pathWithExtension = extension === ".mjs" || extension === ".cjs" ? normalizedPath : normalizedPath.replace(/\.[cm]?[jt]sx?$/, "");
297
+ return pathWithExtension.startsWith(".") ? pathWithExtension : `./${pathWithExtension}`;
450
298
  }
451
299
  function rebaseModulePath(modulePath, sourceFilePath, outputFilePath) {
452
- if (!modulePath.startsWith(".")) {
453
- return modulePath;
454
- }
455
- const resolvedPath = path__default.default.resolve(path__default.default.dirname(sourceFilePath), modulePath);
456
- const relativePath = path__default.default.relative(path__default.default.dirname(outputFilePath), resolvedPath);
457
- return normalizeImportPath(relativePath, path__default.default.extname(resolvedPath));
300
+ if (!modulePath.startsWith(".")) return modulePath;
301
+ const resolvedPath = path.default.resolve(path.default.dirname(sourceFilePath), modulePath);
302
+ return normalizeImportPath(path.default.relative(path.default.dirname(outputFilePath), resolvedPath), path.default.extname(resolvedPath));
458
303
  }
459
304
  function collectWorkflowBindingNames(ast) {
460
- const workflowNames = /* @__PURE__ */ new Set();
461
- for (const statement of ast.program.body) {
462
- if (!t3__namespace.isVariableDeclaration(statement) && !(t3__namespace.isExportNamedDeclaration(statement) && t3__namespace.isVariableDeclaration(statement.declaration))) {
463
- continue;
464
- }
465
- const declarationStatement = t3__namespace.isVariableDeclaration(statement) ? statement : statement.declaration;
466
- for (const declaration of declarationStatement.declarations) {
467
- if (t3__namespace.isIdentifier(declaration.id) && declaration.init && hasCreateWorkflowCall(declaration.init)) {
468
- workflowNames.add(declaration.id.name);
469
- }
470
- }
471
- }
472
- return workflowNames;
305
+ const workflowNames = /* @__PURE__ */ new Set();
306
+ for (const statement of ast.program.body) {
307
+ if (!_babel_types.isVariableDeclaration(statement) && !(_babel_types.isExportNamedDeclaration(statement) && _babel_types.isVariableDeclaration(statement.declaration))) continue;
308
+ const declarationStatement = _babel_types.isVariableDeclaration(statement) ? statement : statement.declaration;
309
+ for (const declaration of declarationStatement.declarations) if (_babel_types.isIdentifier(declaration.id) && declaration.init && hasCreateWorkflowCall(declaration.init)) workflowNames.add(declaration.id.name);
310
+ }
311
+ return workflowNames;
473
312
  }
474
313
  function isMastraDeclaration(declaration) {
475
- return t3__namespace.isIdentifier(declaration.id) && declaration.id.name === "mastra";
314
+ return _babel_types.isIdentifier(declaration.id) && declaration.id.name === "mastra";
476
315
  }
477
316
  function removeStrippedReferencesFromMastraInitializer(init, strippedNames) {
478
- const clonedInit = t3__namespace.cloneNode(init, true);
479
- if (!t3__namespace.isNewExpression(clonedInit) && !t3__namespace.isCallExpression(clonedInit)) {
480
- return clonedInit;
481
- }
482
- const config = clonedInit.arguments[0];
483
- if (!t3__namespace.isObjectExpression(config)) {
484
- return clonedInit;
485
- }
486
- config.properties = config.properties.filter((property) => !nodeReferencesName(property, strippedNames));
487
- return clonedInit;
317
+ const clonedInit = _babel_types.cloneNode(init, true);
318
+ if (!_babel_types.isNewExpression(clonedInit) && !_babel_types.isCallExpression(clonedInit)) return clonedInit;
319
+ const config = clonedInit.arguments[0];
320
+ if (!_babel_types.isObjectExpression(config)) return clonedInit;
321
+ config.properties = config.properties.filter((property) => !nodeReferencesName(property, strippedNames));
322
+ return clonedInit;
488
323
  }
489
324
  function createPreservedDeclaration(declaration, strippedNames) {
490
- if (!isMastraDeclaration(declaration) || !declaration.init) {
491
- return t3__namespace.cloneNode(declaration, true);
492
- }
493
- return t3__namespace.variableDeclarator(
494
- t3__namespace.cloneNode(declaration.id, true),
495
- removeStrippedReferencesFromMastraInitializer(declaration.init, strippedNames)
496
- );
325
+ if (!isMastraDeclaration(declaration) || !declaration.init) return _babel_types.cloneNode(declaration, true);
326
+ return _babel_types.variableDeclarator(_babel_types.cloneNode(declaration.id, true), removeStrippedReferencesFromMastraInitializer(declaration.init, strippedNames));
497
327
  }
498
328
  function hasLocalMastraBinding(ast) {
499
- return ast.program.body.some((statement) => {
500
- const declaration = t3__namespace.isExportNamedDeclaration(statement) ? statement.declaration : statement;
501
- if (!t3__namespace.isVariableDeclaration(declaration)) {
502
- return false;
503
- }
504
- return declaration.declarations.some((declarator) => t3__namespace.isIdentifier(declarator.id, { name: "mastra" }));
505
- });
329
+ return ast.program.body.some((statement) => {
330
+ const declaration = _babel_types.isExportNamedDeclaration(statement) ? statement.declaration : statement;
331
+ if (!_babel_types.isVariableDeclaration(declaration)) return false;
332
+ return declaration.declarations.some((declarator) => _babel_types.isIdentifier(declarator.id, { name: "mastra" }));
333
+ });
506
334
  }
507
335
  function createTemporalActivitiesHelperStatements(mastraImportPath, hasMastraBinding) {
508
- const helperSource = hasMastraBinding ? `
336
+ return (0, _babel_parser.parse)(mastraImportPath ? `
337
+ function createStep(args) {
338
+ return async (params) => {
339
+ const { mastra } = await import(${JSON.stringify(mastraImportPath)});
340
+ return args.execute({ ...params, mastra });
341
+ };
342
+ }
343
+ ` : hasMastraBinding ? `
509
344
  function createStep(args) {
510
345
  return async (params) => {
511
346
  return args.execute({ ...params, mastra });
@@ -517,947 +352,711 @@ function createTemporalActivitiesHelperStatements(mastraImportPath, hasMastraBin
517
352
  return args.execute(params);
518
353
  };
519
354
  }
520
- `;
521
- return parser.parse(helperSource, {
522
- sourceType: "module",
523
- plugins: parserPlugins
524
- }).program.body;
355
+ `, {
356
+ sourceType: "module",
357
+ plugins: parserPlugins
358
+ }).program.body;
525
359
  }
526
360
  async function buildTemporalActivitiesModule(entryFile, outputDirectory, outputFileName) {
527
- const activityBindings = [];
528
- const seenActivityBindingNames = /* @__PURE__ */ new Set();
529
- const addActivityBinding = (exportName, call) => {
530
- const stepId = getCreateStepId(call);
531
- if (!stepId || seenActivityBindingNames.has(exportName)) {
532
- return;
533
- }
534
- seenActivityBindingNames.add(exportName);
535
- activityBindings.push({ exportName, stepId });
536
- };
537
- const bundle = await rollup.rollup({
538
- input: entryFile,
539
- treeshake: "smallest",
540
- logLevel: "silent",
541
- plugins: [
542
- {
543
- name: "temporal-workflow-transform",
544
- transform(code, id) {
545
- const ast = parser.parse(code, {
546
- sourceType: "module",
547
- plugins: parserPlugins,
548
- sourceFilename: id
549
- });
550
- const statements = [];
551
- const seenNames = /* @__PURE__ */ new Set();
552
- const strippedNames = /* @__PURE__ */ new Set();
553
- const workflowBindingNames = collectWorkflowBindingNames(ast);
554
- const stepFactoryBindings = collectCreateStepFactoryBindings(ast.program);
555
- const sourceFilePath = id;
556
- const hasMastraBinding = hasLocalMastraBinding(ast);
557
- let helperInserted = false;
558
- const ensureHelperInserted = () => {
559
- if (helperInserted) {
560
- return;
561
- }
562
- statements.push(...createTemporalActivitiesHelperStatements(null, hasMastraBinding));
563
- helperInserted = true;
564
- };
565
- for (const statement of ast.program.body) {
566
- if (t3__namespace.isImportDeclaration(statement)) {
567
- if (statement.source.value === "@mastra/core/workflows") {
568
- const retainedSpecifiers = statement.specifiers.filter(
569
- (specifier) => !(t3__namespace.isImportSpecifier(specifier) && t3__namespace.isIdentifier(specifier.imported) && (specifier.imported.name === "createStep" || specifier.imported.name === "createWorkflow"))
570
- );
571
- if (retainedSpecifiers.length > 0) {
572
- statements.push(t3__namespace.importDeclaration(retainedSpecifiers, t3__namespace.stringLiteral(statement.source.value)));
573
- }
574
- continue;
575
- }
576
- if (isTemporalHelperModule(statement.source.value) || isStrippedExternalModule(statement.source.value)) {
577
- for (const name of collectImportedNames(statement)) {
578
- strippedNames.add(name);
579
- }
580
- continue;
581
- }
582
- const rewrittenSource = rebaseModulePath(statement.source.value, sourceFilePath, id);
583
- if (rewrittenSource === statement.source.value) {
584
- statements.push(statement);
585
- } else {
586
- statements.push(
587
- t3__namespace.importDeclaration(
588
- statement.specifiers.map((specifier) => t3__namespace.cloneNode(specifier, true)),
589
- t3__namespace.stringLiteral(rewrittenSource)
590
- )
591
- );
592
- }
593
- continue;
594
- }
595
- if (t3__namespace.isFunctionDeclaration(statement) || t3__namespace.isClassDeclaration(statement) || t3__namespace.isTSTypeAliasDeclaration(statement) || t3__namespace.isTSInterfaceDeclaration(statement) || t3__namespace.isTSEnumDeclaration(statement)) {
596
- ensureHelperInserted();
597
- statements.push(statement);
598
- continue;
599
- }
600
- if (t3__namespace.isExpressionStatement(statement) && nodeReferencesName(statement, strippedNames)) {
601
- continue;
602
- }
603
- ensureHelperInserted();
604
- if (t3__namespace.isVariableDeclaration(statement)) {
605
- const declarations = [];
606
- for (const declaration of statement.declarations) {
607
- if (isWorkflowHelperDestructure(declaration)) {
608
- continue;
609
- }
610
- if (declaration.init && nodeReferencesName(declaration.init, strippedNames) && !isMastraDeclaration(declaration)) {
611
- if (t3__namespace.isIdentifier(declaration.id)) {
612
- strippedNames.add(declaration.id.name);
613
- }
614
- continue;
615
- }
616
- if (!t3__namespace.isIdentifier(declaration.id) || !declaration.init) {
617
- declarations.push(createPreservedDeclaration(declaration, strippedNames));
618
- continue;
619
- }
620
- const createStepCall = getCreateStepCallFromExpression(declaration.init, stepFactoryBindings);
621
- if (createStepCall) {
622
- const isFactoryCall = t3__namespace.isCallExpression(declaration.init) && t3__namespace.isIdentifier(declaration.init.callee) && stepFactoryBindings.has(declaration.init.callee.name);
623
- if (isFactoryCall) {
624
- seenNames.add(declaration.id.name);
625
- addActivityBinding(declaration.id.name, createStepCall);
626
- statements.push(
627
- t3__namespace.exportNamedDeclaration(t3__namespace.variableDeclaration(statement.kind, [t3__namespace.cloneNode(declaration, true)]))
628
- );
629
- continue;
630
- }
631
- if (isCreateStepCall(declaration.init)) {
632
- seenNames.add(declaration.id.name);
633
- addActivityBinding(declaration.id.name, createStepCall);
634
- statements.push(createExportedStepStatement(declaration.id.name, createStepCall));
635
- continue;
636
- }
637
- }
638
- if (hasCreateWorkflowCall(declaration.init)) {
639
- workflowBindingNames.add(declaration.id.name);
640
- strippedNames.add(declaration.id.name);
641
- collectInlineCreateSteps(declaration.init, seenNames, statements, addActivityBinding);
642
- continue;
643
- }
644
- declarations.push(createPreservedDeclaration(declaration, strippedNames));
645
- }
646
- if (declarations.length > 0) {
647
- statements.push(
648
- t3__namespace.variableDeclaration(
649
- statement.kind,
650
- declarations.map((declaration) => t3__namespace.cloneNode(declaration, true))
651
- )
652
- );
653
- }
654
- continue;
655
- }
656
- if (t3__namespace.isExportNamedDeclaration(statement) && t3__namespace.isVariableDeclaration(statement.declaration)) {
657
- const exportedDeclarations = [];
658
- const localDeclarations = [];
659
- for (const declaration of statement.declaration.declarations) {
660
- if (isWorkflowHelperDestructure(declaration)) {
661
- continue;
662
- }
663
- if (declaration.init && nodeReferencesName(declaration.init, strippedNames) && !isMastraDeclaration(declaration)) {
664
- if (t3__namespace.isIdentifier(declaration.id)) {
665
- strippedNames.add(declaration.id.name);
666
- }
667
- continue;
668
- }
669
- if (!t3__namespace.isIdentifier(declaration.id) || !declaration.init) {
670
- exportedDeclarations.push(createPreservedDeclaration(declaration, strippedNames));
671
- continue;
672
- }
673
- const createStepCall = getCreateStepCallFromExpression(declaration.init, stepFactoryBindings);
674
- if (createStepCall) {
675
- const isFactoryCall = t3__namespace.isCallExpression(declaration.init) && t3__namespace.isIdentifier(declaration.init.callee) && stepFactoryBindings.has(declaration.init.callee.name);
676
- if (isFactoryCall) {
677
- seenNames.add(declaration.id.name);
678
- addActivityBinding(declaration.id.name, createStepCall);
679
- exportedDeclarations.push(createPreservedDeclaration(declaration, strippedNames));
680
- continue;
681
- }
682
- if (isCreateStepCall(declaration.init)) {
683
- seenNames.add(declaration.id.name);
684
- addActivityBinding(declaration.id.name, createStepCall);
685
- statements.push(createExportedStepStatement(declaration.id.name, createStepCall));
686
- continue;
687
- }
688
- }
689
- if (hasCreateWorkflowCall(declaration.init)) {
690
- workflowBindingNames.add(declaration.id.name);
691
- strippedNames.add(declaration.id.name);
692
- collectInlineCreateSteps(declaration.init, seenNames, statements, addActivityBinding);
693
- continue;
694
- }
695
- if (declaration.id.name === "mastra") {
696
- localDeclarations.push(createPreservedDeclaration(declaration, strippedNames));
697
- continue;
698
- }
699
- exportedDeclarations.push(createPreservedDeclaration(declaration, strippedNames));
700
- }
701
- if (localDeclarations.length > 0) {
702
- statements.push(
703
- t3__namespace.variableDeclaration(
704
- statement.declaration.kind,
705
- localDeclarations.map((declaration) => t3__namespace.cloneNode(declaration, true))
706
- )
707
- );
708
- }
709
- if (exportedDeclarations.length > 0) {
710
- statements.push(
711
- t3__namespace.exportNamedDeclaration(
712
- t3__namespace.variableDeclaration(
713
- statement.declaration.kind,
714
- exportedDeclarations.map((declaration) => t3__namespace.cloneNode(declaration, true))
715
- )
716
- )
717
- );
718
- }
719
- continue;
720
- }
721
- if (t3__namespace.isExpressionStatement(statement)) {
722
- if (nodeReferencesName(statement, workflowBindingNames) || nodeReferencesName(statement, strippedNames)) {
723
- collectInlineCreateSteps(statement, seenNames, statements, addActivityBinding);
724
- continue;
725
- }
726
- collectInlineCreateSteps(statement, seenNames, statements, addActivityBinding);
727
- continue;
728
- }
729
- if (t3__namespace.isExportNamedDeclaration(statement)) {
730
- if (t3__namespace.isFunctionDeclaration(statement.declaration) || t3__namespace.isClassDeclaration(statement.declaration) || t3__namespace.isTSTypeAliasDeclaration(statement.declaration) || t3__namespace.isTSInterfaceDeclaration(statement.declaration) || t3__namespace.isTSEnumDeclaration(statement.declaration)) {
731
- ensureHelperInserted();
732
- statements.push(statement);
733
- continue;
734
- }
735
- if (statement.declaration == null && statement.source == null) {
736
- const retainedSpecifiers = statement.specifiers.filter(
737
- (specifier) => t3__namespace.isExportSpecifier(specifier) && t3__namespace.isIdentifier(specifier.local) && specifier.local.name !== "mastra" && !workflowBindingNames.has(specifier.local.name) && !seenNames.has(specifier.local.name)
738
- );
739
- if (retainedSpecifiers.length > 0) {
740
- statements.push(t3__namespace.exportNamedDeclaration(null, retainedSpecifiers));
741
- }
742
- continue;
743
- }
744
- if (statement.declaration == null && statement.source) {
745
- const mastraSpecifiers = statement.specifiers.filter(
746
- (specifier) => t3__namespace.isExportSpecifier(specifier) && t3__namespace.isIdentifier(specifier.exported, { name: "mastra" }) && t3__namespace.isIdentifier(specifier.local, { name: "mastra" })
747
- );
748
- if (mastraSpecifiers.length > 0) {
749
- statements.push(
750
- t3__namespace.importDeclaration(
751
- [t3__namespace.importSpecifier(t3__namespace.identifier("mastra"), t3__namespace.identifier("mastra"))],
752
- t3__namespace.stringLiteral(rebaseModulePath(statement.source.value, sourceFilePath, id))
753
- )
754
- );
755
- }
756
- continue;
757
- }
758
- collectInlineCreateSteps(statement, seenNames, statements, addActivityBinding);
759
- continue;
760
- }
761
- if (t3__namespace.isExportDefaultDeclaration(statement)) {
762
- if (t3__namespace.isIdentifier(statement.declaration) && workflowBindingNames.has(statement.declaration.name)) {
763
- continue;
764
- }
765
- collectInlineCreateSteps(statement, seenNames, statements, addActivityBinding);
766
- continue;
767
- }
768
- statements.push(statement);
769
- }
770
- ensureHelperInserted();
771
- const transformedSource = generator.generate(t3__namespace.file(t3__namespace.program(pruneUnusedTopLevelBindings(statements), [], "module")), {
772
- sourceMaps: true
773
- });
774
- return {
775
- code: transformedSource.code,
776
- map: transformedSource.map ? { ...transformedSource.map, file: transformedSource.map.file ?? void 0 } : void 0
777
- };
778
- }
779
- }
780
- ]
781
- });
782
- try {
783
- const baseName = path.basename(outputFileName);
784
- const { output } = await bundle.write({
785
- dir: outputDirectory,
786
- entryFileNames: outputFileName,
787
- chunkFileNames: `${baseName}-[hash].mjs`,
788
- format: "esm",
789
- sourcemap: "inline"
790
- });
791
- return {
792
- outputPath: path.join(outputDirectory, output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName),
793
- activityBindings
794
- };
795
- } finally {
796
- await bundle.close();
797
- }
361
+ const activityBindings = [];
362
+ const seenActivityBindingNames = /* @__PURE__ */ new Set();
363
+ const addActivityBinding = (exportName, call) => {
364
+ const stepId = getCreateStepId(call);
365
+ if (!stepId || seenActivityBindingNames.has(exportName)) return;
366
+ seenActivityBindingNames.add(exportName);
367
+ activityBindings.push({
368
+ exportName,
369
+ stepId
370
+ });
371
+ };
372
+ const bundle = await (0, rollup.rollup)({
373
+ input: entryFile,
374
+ treeshake: "smallest",
375
+ logLevel: "silent",
376
+ plugins: [{
377
+ name: "temporal-workflow-transform",
378
+ transform(code, id) {
379
+ const ast = (0, _babel_parser.parse)(code, {
380
+ sourceType: "module",
381
+ plugins: parserPlugins,
382
+ sourceFilename: id
383
+ });
384
+ const statements = [];
385
+ const seenNames = /* @__PURE__ */ new Set();
386
+ const strippedNames = /* @__PURE__ */ new Set();
387
+ const workflowBindingNames = collectWorkflowBindingNames(ast);
388
+ const stepFactoryBindings = collectCreateStepFactoryBindings(ast.program);
389
+ const sourceFilePath = id;
390
+ const hasMastraBinding = hasLocalMastraBinding(ast);
391
+ let helperInserted = false;
392
+ const ensureHelperInserted = () => {
393
+ if (helperInserted) return;
394
+ statements.push(...createTemporalActivitiesHelperStatements(null, hasMastraBinding));
395
+ helperInserted = true;
396
+ };
397
+ for (const statement of ast.program.body) {
398
+ if (_babel_types.isImportDeclaration(statement)) {
399
+ if (statement.source.value === "@mastra/core/workflows") {
400
+ const retainedSpecifiers = statement.specifiers.filter((specifier) => !(_babel_types.isImportSpecifier(specifier) && _babel_types.isIdentifier(specifier.imported) && (specifier.imported.name === "createStep" || specifier.imported.name === "createWorkflow")));
401
+ if (retainedSpecifiers.length > 0) statements.push(_babel_types.importDeclaration(retainedSpecifiers, _babel_types.stringLiteral(statement.source.value)));
402
+ continue;
403
+ }
404
+ if (isTemporalHelperModule(statement.source.value) || isStrippedExternalModule(statement.source.value)) {
405
+ for (const name of collectImportedNames(statement)) strippedNames.add(name);
406
+ continue;
407
+ }
408
+ const rewrittenSource = rebaseModulePath(statement.source.value, sourceFilePath, id);
409
+ if (rewrittenSource === statement.source.value) statements.push(statement);
410
+ else statements.push(_babel_types.importDeclaration(statement.specifiers.map((specifier) => _babel_types.cloneNode(specifier, true)), _babel_types.stringLiteral(rewrittenSource)));
411
+ continue;
412
+ }
413
+ if (_babel_types.isFunctionDeclaration(statement) || _babel_types.isClassDeclaration(statement) || _babel_types.isTSTypeAliasDeclaration(statement) || _babel_types.isTSInterfaceDeclaration(statement) || _babel_types.isTSEnumDeclaration(statement)) {
414
+ ensureHelperInserted();
415
+ statements.push(statement);
416
+ continue;
417
+ }
418
+ if (_babel_types.isExpressionStatement(statement) && nodeReferencesName(statement, strippedNames)) continue;
419
+ ensureHelperInserted();
420
+ if (_babel_types.isVariableDeclaration(statement)) {
421
+ const declarations = [];
422
+ for (const declaration of statement.declarations) {
423
+ if (isWorkflowHelperDestructure(declaration)) continue;
424
+ if (declaration.init && nodeReferencesName(declaration.init, strippedNames) && !isMastraDeclaration(declaration)) {
425
+ if (_babel_types.isIdentifier(declaration.id)) strippedNames.add(declaration.id.name);
426
+ continue;
427
+ }
428
+ if (!_babel_types.isIdentifier(declaration.id) || !declaration.init) {
429
+ declarations.push(createPreservedDeclaration(declaration, strippedNames));
430
+ continue;
431
+ }
432
+ const createStepCall = getCreateStepCallFromExpression(declaration.init, stepFactoryBindings);
433
+ if (createStepCall) {
434
+ if (_babel_types.isCallExpression(declaration.init) && _babel_types.isIdentifier(declaration.init.callee) && stepFactoryBindings.has(declaration.init.callee.name)) {
435
+ seenNames.add(declaration.id.name);
436
+ addActivityBinding(declaration.id.name, createStepCall);
437
+ statements.push(_babel_types.exportNamedDeclaration(_babel_types.variableDeclaration(statement.kind, [_babel_types.cloneNode(declaration, true)])));
438
+ continue;
439
+ }
440
+ if (isCreateStepCall(declaration.init)) {
441
+ seenNames.add(declaration.id.name);
442
+ addActivityBinding(declaration.id.name, createStepCall);
443
+ statements.push(createExportedStepStatement(declaration.id.name, createStepCall));
444
+ continue;
445
+ }
446
+ }
447
+ if (hasCreateWorkflowCall(declaration.init)) {
448
+ workflowBindingNames.add(declaration.id.name);
449
+ strippedNames.add(declaration.id.name);
450
+ collectInlineCreateSteps(declaration.init, seenNames, statements, addActivityBinding);
451
+ continue;
452
+ }
453
+ declarations.push(createPreservedDeclaration(declaration, strippedNames));
454
+ }
455
+ if (declarations.length > 0) statements.push(_babel_types.variableDeclaration(statement.kind, declarations.map((declaration) => _babel_types.cloneNode(declaration, true))));
456
+ continue;
457
+ }
458
+ if (_babel_types.isExportNamedDeclaration(statement) && _babel_types.isVariableDeclaration(statement.declaration)) {
459
+ const exportedDeclarations = [];
460
+ const localDeclarations = [];
461
+ for (const declaration of statement.declaration.declarations) {
462
+ if (isWorkflowHelperDestructure(declaration)) continue;
463
+ if (declaration.init && nodeReferencesName(declaration.init, strippedNames) && !isMastraDeclaration(declaration)) {
464
+ if (_babel_types.isIdentifier(declaration.id)) strippedNames.add(declaration.id.name);
465
+ continue;
466
+ }
467
+ if (!_babel_types.isIdentifier(declaration.id) || !declaration.init) {
468
+ exportedDeclarations.push(createPreservedDeclaration(declaration, strippedNames));
469
+ continue;
470
+ }
471
+ const createStepCall = getCreateStepCallFromExpression(declaration.init, stepFactoryBindings);
472
+ if (createStepCall) {
473
+ if (_babel_types.isCallExpression(declaration.init) && _babel_types.isIdentifier(declaration.init.callee) && stepFactoryBindings.has(declaration.init.callee.name)) {
474
+ seenNames.add(declaration.id.name);
475
+ addActivityBinding(declaration.id.name, createStepCall);
476
+ exportedDeclarations.push(createPreservedDeclaration(declaration, strippedNames));
477
+ continue;
478
+ }
479
+ if (isCreateStepCall(declaration.init)) {
480
+ seenNames.add(declaration.id.name);
481
+ addActivityBinding(declaration.id.name, createStepCall);
482
+ statements.push(createExportedStepStatement(declaration.id.name, createStepCall));
483
+ continue;
484
+ }
485
+ }
486
+ if (hasCreateWorkflowCall(declaration.init)) {
487
+ workflowBindingNames.add(declaration.id.name);
488
+ strippedNames.add(declaration.id.name);
489
+ collectInlineCreateSteps(declaration.init, seenNames, statements, addActivityBinding);
490
+ continue;
491
+ }
492
+ if (declaration.id.name === "mastra") {
493
+ localDeclarations.push(createPreservedDeclaration(declaration, strippedNames));
494
+ continue;
495
+ }
496
+ exportedDeclarations.push(createPreservedDeclaration(declaration, strippedNames));
497
+ }
498
+ if (localDeclarations.length > 0) statements.push(_babel_types.variableDeclaration(statement.declaration.kind, localDeclarations.map((declaration) => _babel_types.cloneNode(declaration, true))));
499
+ if (exportedDeclarations.length > 0) statements.push(_babel_types.exportNamedDeclaration(_babel_types.variableDeclaration(statement.declaration.kind, exportedDeclarations.map((declaration) => _babel_types.cloneNode(declaration, true)))));
500
+ continue;
501
+ }
502
+ if (_babel_types.isExpressionStatement(statement)) {
503
+ if (nodeReferencesName(statement, workflowBindingNames) || nodeReferencesName(statement, strippedNames)) {
504
+ collectInlineCreateSteps(statement, seenNames, statements, addActivityBinding);
505
+ continue;
506
+ }
507
+ collectInlineCreateSteps(statement, seenNames, statements, addActivityBinding);
508
+ continue;
509
+ }
510
+ if (_babel_types.isExportNamedDeclaration(statement)) {
511
+ if (_babel_types.isFunctionDeclaration(statement.declaration) || _babel_types.isClassDeclaration(statement.declaration) || _babel_types.isTSTypeAliasDeclaration(statement.declaration) || _babel_types.isTSInterfaceDeclaration(statement.declaration) || _babel_types.isTSEnumDeclaration(statement.declaration)) {
512
+ ensureHelperInserted();
513
+ statements.push(statement);
514
+ continue;
515
+ }
516
+ if (statement.declaration == null && statement.source == null) {
517
+ const retainedSpecifiers = statement.specifiers.filter((specifier) => _babel_types.isExportSpecifier(specifier) && _babel_types.isIdentifier(specifier.local) && specifier.local.name !== "mastra" && !workflowBindingNames.has(specifier.local.name) && !seenNames.has(specifier.local.name));
518
+ if (retainedSpecifiers.length > 0) statements.push(_babel_types.exportNamedDeclaration(null, retainedSpecifiers));
519
+ continue;
520
+ }
521
+ if (statement.declaration == null && statement.source) {
522
+ if (statement.specifiers.filter((specifier) => _babel_types.isExportSpecifier(specifier) && _babel_types.isIdentifier(specifier.exported, { name: "mastra" }) && _babel_types.isIdentifier(specifier.local, { name: "mastra" })).length > 0) statements.push(_babel_types.importDeclaration([_babel_types.importSpecifier(_babel_types.identifier("mastra"), _babel_types.identifier("mastra"))], _babel_types.stringLiteral(rebaseModulePath(statement.source.value, sourceFilePath, id))));
523
+ continue;
524
+ }
525
+ collectInlineCreateSteps(statement, seenNames, statements, addActivityBinding);
526
+ continue;
527
+ }
528
+ if (_babel_types.isExportDefaultDeclaration(statement)) {
529
+ if (_babel_types.isIdentifier(statement.declaration) && workflowBindingNames.has(statement.declaration.name)) continue;
530
+ collectInlineCreateSteps(statement, seenNames, statements, addActivityBinding);
531
+ continue;
532
+ }
533
+ statements.push(statement);
534
+ }
535
+ ensureHelperInserted();
536
+ const transformedSource = (0, _babel_generator.generate)(_babel_types.file(_babel_types.program(pruneUnusedTopLevelBindings(statements), [], "module")), { sourceMaps: true });
537
+ return {
538
+ code: transformedSource.code,
539
+ map: transformedSource.map ? {
540
+ ...transformedSource.map,
541
+ file: transformedSource.map.file ?? void 0
542
+ } : void 0
543
+ };
544
+ }
545
+ }]
546
+ });
547
+ try {
548
+ const baseName = (0, path.basename)(outputFileName);
549
+ const { output } = await bundle.write({
550
+ dir: outputDirectory,
551
+ entryFileNames: outputFileName,
552
+ chunkFileNames: `${baseName}-[hash].mjs`,
553
+ format: "esm",
554
+ sourcemap: "inline"
555
+ });
556
+ return {
557
+ outputPath: (0, path.join)(outputDirectory, output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName),
558
+ activityBindings
559
+ };
560
+ } finally {
561
+ await bundle.close();
562
+ }
798
563
  }
564
+ //#endregion
565
+ //#region src/transforms/workflows.ts
566
+ /**
567
+ * Temporal workflow types must be static so the loader can deterministically map
568
+ * a source workflow to the runtime export name used by the worker.
569
+ */
799
570
  function getWorkflowIdMetadata(workflowConfig, workflowName, filePath) {
800
- for (const property of workflowConfig.properties) {
801
- if (!t3__namespace.isObjectProperty(property) || getObjectPropertyName(property) !== "id") {
802
- continue;
803
- }
804
- if (!t3__namespace.isExpression(property.value)) {
805
- break;
806
- }
807
- if (t3__namespace.isStringLiteral(property.value)) {
808
- return {
809
- expression: t3__namespace.cloneNode(property.value, true),
810
- workflowId: property.value.value
811
- };
812
- }
813
- if (t3__namespace.isTemplateLiteral(property.value) && property.value.expressions.length === 0) {
814
- return {
815
- expression: t3__namespace.cloneNode(property.value, true),
816
- workflowId: property.value.quasis[0]?.value.cooked ?? ""
817
- };
818
- }
819
- throw new Error(`Workflow id must be a static string for ${workflowName} in ${filePath}`);
820
- }
821
- throw new Error(`Unable to determine workflow id for ${workflowName} in ${filePath}`);
571
+ for (const property of workflowConfig.properties) {
572
+ if (!_babel_types.isObjectProperty(property) || getObjectPropertyName(property) !== "id") continue;
573
+ if (!_babel_types.isExpression(property.value)) break;
574
+ if (_babel_types.isStringLiteral(property.value)) return {
575
+ expression: _babel_types.cloneNode(property.value, true),
576
+ workflowId: property.value.value
577
+ };
578
+ if (_babel_types.isTemplateLiteral(property.value) && property.value.expressions.length === 0) return {
579
+ expression: _babel_types.cloneNode(property.value, true),
580
+ workflowId: property.value.quasis[0]?.value.cooked ?? ""
581
+ };
582
+ throw new Error(`Workflow id must be a static string for ${workflowName} in ${filePath}`);
583
+ }
584
+ throw new Error(`Unable to determine workflow id for ${workflowName} in ${filePath}`);
822
585
  }
586
+ /**
587
+ * The helper runtime lives in its own `.mjs` module so it can be linted and unit-tested
588
+ * like normal code. We parse that file directly here instead of using `Function#toString()`,
589
+ * which keeps fixture output stable under Vitest/Vite instrumentation.
590
+ */
823
591
  function createTemporalWorkflowHelperStatements() {
824
- const temporalWorkflowRuntimeSource = fs.readFileSync(
825
- new URL("./temporal-workflow-runtime.mjs", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('worker.cjs', document.baseURI).href))),
826
- "utf8"
827
- );
828
- const helperProgram = parser.parse(temporalWorkflowRuntimeSource, {
829
- sourceType: "module",
830
- plugins: parserPlugins
831
- }).program.body;
832
- return helperProgram.flatMap((statement) => {
833
- if (t3__namespace.isExportNamedDeclaration(statement) && statement.declaration) {
834
- return [statement.declaration];
835
- }
836
- return [statement];
837
- });
592
+ return (0, _babel_parser.parse)((0, fs.readFileSync)(new URL("./temporal-workflow-runtime.mjs", require("url").pathToFileURL(__filename).href), "utf8"), {
593
+ sourceType: "module",
594
+ plugins: parserPlugins
595
+ }).program.body.flatMap((statement) => {
596
+ if (_babel_types.isExportNamedDeclaration(statement) && statement.declaration) return [statement.declaration];
597
+ return [statement];
598
+ });
838
599
  }
839
- function getTemporalWorkflowRuntimeOptions(program3) {
840
- for (const statement of program3.body) {
841
- const declarationStatement = t3__namespace.isVariableDeclaration(statement) ? statement : t3__namespace.isExportNamedDeclaration(statement) && t3__namespace.isVariableDeclaration(statement.declaration) ? statement.declaration : null;
842
- if (!declarationStatement) {
843
- continue;
844
- }
845
- for (const declaration of declarationStatement.declarations) {
846
- if (!isWorkflowHelperDestructure(declaration) || !t3__namespace.isCallExpression(declaration.init)) {
847
- continue;
848
- }
849
- const [temporalParams] = declaration.init.arguments;
850
- if (!temporalParams || !t3__namespace.isObjectExpression(temporalParams)) {
851
- continue;
852
- }
853
- for (const property of temporalParams.properties) {
854
- if (t3__namespace.isObjectProperty(property) && getObjectPropertyName(property) === "startToCloseTimeout" && t3__namespace.isExpression(property.value)) {
855
- return t3__namespace.objectExpression([
856
- t3__namespace.objectProperty(t3__namespace.identifier("startToCloseTimeout"), t3__namespace.cloneNode(property.value, true))
857
- ]);
858
- }
859
- }
860
- }
861
- }
600
+ function getTemporalWorkflowRuntimeOptions(program) {
601
+ for (const statement of program.body) {
602
+ const declarationStatement = _babel_types.isVariableDeclaration(statement) ? statement : _babel_types.isExportNamedDeclaration(statement) && _babel_types.isVariableDeclaration(statement.declaration) ? statement.declaration : null;
603
+ if (!declarationStatement) continue;
604
+ for (const declaration of declarationStatement.declarations) {
605
+ if (!isWorkflowHelperDestructure(declaration) || !_babel_types.isCallExpression(declaration.init)) continue;
606
+ const [temporalParams] = declaration.init.arguments;
607
+ if (!temporalParams || !_babel_types.isObjectExpression(temporalParams)) continue;
608
+ for (const property of temporalParams.properties) if (_babel_types.isObjectProperty(property) && getObjectPropertyName(property) === "startToCloseTimeout" && _babel_types.isExpression(property.value)) return _babel_types.objectExpression([_babel_types.objectProperty(_babel_types.identifier("startToCloseTimeout"), _babel_types.cloneNode(property.value, true))]);
609
+ }
610
+ }
862
611
  }
612
+ /**
613
+ * Walks a chained workflow expression like `createWorkflow(...).then(...).commit()`
614
+ * back to its root `createWorkflow(...)` call while preserving method order.
615
+ */
863
616
  function parseWorkflowChain(node) {
864
- const methods = [];
865
- let current = node;
866
- while (t3__namespace.isCallExpression(current) && t3__namespace.isMemberExpression(current.callee) && !current.callee.computed) {
867
- if (!t3__namespace.isIdentifier(current.callee.property)) {
868
- return null;
869
- }
870
- methods.unshift({
871
- name: current.callee.property.name,
872
- args: current.arguments
873
- });
874
- current = current.callee.object;
875
- }
876
- if (!isCreateWorkflowCall(current)) {
877
- return null;
878
- }
879
- return {
880
- createWorkflowCall: current,
881
- methods
882
- };
617
+ const methods = [];
618
+ let current = node;
619
+ while (_babel_types.isCallExpression(current) && _babel_types.isMemberExpression(current.callee) && !current.callee.computed) {
620
+ if (!_babel_types.isIdentifier(current.callee.property)) return null;
621
+ methods.unshift({
622
+ name: current.callee.property.name,
623
+ args: current.arguments
624
+ });
625
+ current = current.callee.object;
626
+ }
627
+ if (!isCreateWorkflowCall(current)) return null;
628
+ return {
629
+ createWorkflowCall: current,
630
+ methods
631
+ };
883
632
  }
884
- function collectStepBindings(program3) {
885
- const stepBindings = /* @__PURE__ */ new Map();
886
- const stepFactoryBindings = collectCreateStepFactoryBindings(program3);
887
- for (const [factoryName, createStepCall] of stepFactoryBindings) {
888
- const stepId = getCreateStepId(createStepCall);
889
- if (stepId) {
890
- stepBindings.set(factoryName, stepId);
891
- }
892
- }
893
- for (const statement of program3.body) {
894
- if (!t3__namespace.isVariableDeclaration(statement) && !(t3__namespace.isExportNamedDeclaration(statement) && t3__namespace.isVariableDeclaration(statement.declaration))) {
895
- continue;
896
- }
897
- const declarationStatement = t3__namespace.isVariableDeclaration(statement) ? statement : statement.declaration;
898
- for (const declaration of declarationStatement.declarations) {
899
- if (!t3__namespace.isIdentifier(declaration.id) || !declaration.init) {
900
- continue;
901
- }
902
- const createStepCall = getCreateStepCallFromExpression(declaration.init, stepFactoryBindings);
903
- const stepId = getCreateStepId(createStepCall);
904
- if (stepId) {
905
- stepBindings.set(declaration.id.name, stepId);
906
- }
907
- }
908
- }
909
- return stepBindings;
633
+ /**
634
+ * Maps local `const someStep = createStep({ id: 'some-step' })` bindings to their
635
+ * runtime ids so later chain rewriting can replace identifier references with ids.
636
+ */
637
+ function collectStepBindings(program) {
638
+ const stepBindings = /* @__PURE__ */ new Map();
639
+ const stepFactoryBindings = collectCreateStepFactoryBindings(program);
640
+ for (const [factoryName, createStepCall] of stepFactoryBindings) {
641
+ const stepId = getCreateStepId(createStepCall);
642
+ if (stepId) stepBindings.set(factoryName, stepId);
643
+ }
644
+ for (const statement of program.body) {
645
+ if (!_babel_types.isVariableDeclaration(statement) && !(_babel_types.isExportNamedDeclaration(statement) && _babel_types.isVariableDeclaration(statement.declaration))) continue;
646
+ const declarationStatement = _babel_types.isVariableDeclaration(statement) ? statement : statement.declaration;
647
+ for (const declaration of declarationStatement.declarations) {
648
+ if (!_babel_types.isIdentifier(declaration.id) || !declaration.init) continue;
649
+ const stepId = getCreateStepId(getCreateStepCallFromExpression(declaration.init, stepFactoryBindings));
650
+ if (stepId) stepBindings.set(declaration.id.name, stepId);
651
+ }
652
+ }
653
+ return stepBindings;
910
654
  }
911
- function collectWorkflowBindings(program3, filePath) {
912
- const workflowBindings = /* @__PURE__ */ new Map();
913
- for (const statement of program3.body) {
914
- if (!t3__namespace.isVariableDeclaration(statement) && !(t3__namespace.isExportNamedDeclaration(statement) && t3__namespace.isVariableDeclaration(statement.declaration))) {
915
- continue;
916
- }
917
- const declarationStatement = t3__namespace.isVariableDeclaration(statement) ? statement : statement.declaration;
918
- for (const declaration of declarationStatement.declarations) {
919
- if (!t3__namespace.isIdentifier(declaration.id) || !declaration.init) {
920
- continue;
921
- }
922
- const workflowChain = parseWorkflowChain(declaration.init);
923
- const [workflowConfig] = workflowChain?.createWorkflowCall.arguments ?? [];
924
- if (!workflowChain || !workflowConfig || !t3__namespace.isObjectExpression(workflowConfig)) {
925
- continue;
926
- }
927
- const { workflowId } = getWorkflowIdMetadata(workflowConfig, declaration.id.name, filePath);
928
- workflowBindings.set(declaration.id.name, chunkDYBSPLCJ_cjs.toWorkflowType(workflowId));
929
- }
930
- }
931
- return workflowBindings;
655
+ function collectWorkflowBindings(program, filePath) {
656
+ const workflowBindings = /* @__PURE__ */ new Map();
657
+ for (const statement of program.body) {
658
+ if (!_babel_types.isVariableDeclaration(statement) && !(_babel_types.isExportNamedDeclaration(statement) && _babel_types.isVariableDeclaration(statement.declaration))) continue;
659
+ const declarationStatement = _babel_types.isVariableDeclaration(statement) ? statement : statement.declaration;
660
+ for (const declaration of declarationStatement.declarations) {
661
+ if (!_babel_types.isIdentifier(declaration.id) || !declaration.init) continue;
662
+ const workflowChain = parseWorkflowChain(declaration.init);
663
+ const [workflowConfig] = workflowChain?.createWorkflowCall.arguments ?? [];
664
+ if (!workflowChain || !workflowConfig || !_babel_types.isObjectExpression(workflowConfig)) continue;
665
+ const { workflowId } = getWorkflowIdMetadata(workflowConfig, declaration.id.name, filePath);
666
+ workflowBindings.set(declaration.id.name, require_utils.toWorkflowType(workflowId));
667
+ }
668
+ }
669
+ return workflowBindings;
932
670
  }
671
+ /**
672
+ * Accepts the few AST node shapes we allow as "step references" in workflow chains
673
+ * and normalizes them to a single step id string.
674
+ */
933
675
  function getWorkflowStepName(node, stepBindings) {
934
- if (!node) {
935
- return null;
936
- }
937
- if (t3__namespace.isIdentifier(node)) {
938
- return stepBindings.get(node.name) ?? node.name;
939
- }
940
- if (t3__namespace.isStringLiteral(node)) {
941
- return node.value;
942
- }
943
- if (t3__namespace.isCallExpression(node) && t3__namespace.isIdentifier(node.callee)) {
944
- return stepBindings.get(node.callee.name) ?? getCreateStepId(node);
945
- }
946
- return getCreateStepId(node);
676
+ if (!node) return null;
677
+ if (_babel_types.isIdentifier(node)) return stepBindings.get(node.name) ?? node.name;
678
+ if (_babel_types.isStringLiteral(node)) return node.value;
679
+ if (_babel_types.isCallExpression(node) && _babel_types.isIdentifier(node.callee)) return stepBindings.get(node.callee.name) ?? getCreateStepId(node);
680
+ return getCreateStepId(node);
947
681
  }
682
+ /**
683
+ * Normalizes fluent workflow builder calls into the simpler Temporal runtime shape.
684
+ *
685
+ * Most step references collapse down to step ids so the generated workflow can call
686
+ * activities by id instead of keeping the original `createStep` definitions around.
687
+ */
948
688
  function rewriteChainMethod(method, filePath, workflowName, stepBindings, workflowBindings) {
949
- const argNode = (index) => method.args[index];
950
- const rewritten = (args, name = method.name) => ({ name, args });
951
- switch (method.name) {
952
- case "then": {
953
- const arg = argNode(0);
954
- if (t3__namespace.isIdentifier(arg)) {
955
- const workflowType = workflowBindings.get(arg.name);
956
- if (workflowType) {
957
- return rewritten([t3__namespace.stringLiteral(workflowType)], "thenWorkflow");
958
- }
959
- }
960
- const name = getWorkflowStepName(arg, stepBindings);
961
- if (!name) {
962
- throw new Error(
963
- `.then() in ${workflowName} (${filePath}) must take a step or workflow identifier (inline createStep calls are not supported)`
964
- );
965
- }
966
- return rewritten([t3__namespace.stringLiteral(name)]);
967
- }
968
- case "sleep": {
969
- const arg = argNode(0);
970
- if (t3__namespace.isNumericLiteral(arg)) {
971
- return rewritten([t3__namespace.cloneNode(arg, true)]);
972
- }
973
- const name = getWorkflowStepName(arg, stepBindings);
974
- if (!name) {
975
- throw new Error(`.sleep() in ${workflowName} (${filePath}) must be a numeric literal or an identifier`);
976
- }
977
- return rewritten([t3__namespace.stringLiteral(name)]);
978
- }
979
- case "sleepUntil": {
980
- const arg = argNode(0);
981
- if (t3__namespace.isNewExpression(arg) && t3__namespace.isIdentifier(arg.callee) && arg.callee.name === "Date") {
982
- return rewritten([t3__namespace.cloneNode(arg, true)]);
983
- }
984
- if (t3__namespace.isStringLiteral(arg) || t3__namespace.isNumericLiteral(arg)) {
985
- return rewritten([t3__namespace.cloneNode(arg, true)]);
986
- }
987
- const name = getWorkflowStepName(arg, stepBindings);
988
- if (!name) {
989
- throw new Error(
990
- `.sleepUntil() in ${workflowName} (${filePath}) must be a Date, string/number literal, or an identifier`
991
- );
992
- }
993
- return rewritten([t3__namespace.stringLiteral(name)]);
994
- }
995
- case "parallel": {
996
- const arg = argNode(0);
997
- if (!t3__namespace.isArrayExpression(arg)) {
998
- throw new Error(`.parallel() in ${workflowName} (${filePath}) requires an array literal argument`);
999
- }
1000
- const names = arg.elements.map((el) => getWorkflowStepName(el, stepBindings));
1001
- if (names.some((n) => !n)) {
1002
- throw new Error(`Unable to determine step names inside .parallel() in ${workflowName} (${filePath})`);
1003
- }
1004
- return rewritten([t3__namespace.arrayExpression(names.map((n) => t3__namespace.stringLiteral(n)))]);
1005
- }
1006
- case "branch": {
1007
- const arg = argNode(0);
1008
- if (!t3__namespace.isArrayExpression(arg)) {
1009
- throw new Error(
1010
- `.branch() in ${workflowName} (${filePath}) requires an array literal of [condition, step] pairs`
1011
- );
1012
- }
1013
- const pairs = arg.elements.map((pair) => {
1014
- if (!t3__namespace.isArrayExpression(pair) || pair.elements.length !== 2) {
1015
- throw new Error(
1016
- `.branch() pair in ${workflowName} (${filePath}) must be a 2-element array [condition, step]`
1017
- );
1018
- }
1019
- const condName = getWorkflowStepName(pair.elements[0], stepBindings);
1020
- const stepName = getWorkflowStepName(pair.elements[1], stepBindings);
1021
- if (!condName || !stepName) {
1022
- throw new Error(`.branch() condition and step in ${workflowName} (${filePath}) must be identifiers`);
1023
- }
1024
- return t3__namespace.arrayExpression([t3__namespace.stringLiteral(condName), t3__namespace.stringLiteral(stepName)]);
1025
- });
1026
- return rewritten([t3__namespace.arrayExpression(pairs)]);
1027
- }
1028
- case "dowhile":
1029
- case "dountil": {
1030
- const stepName = getWorkflowStepName(argNode(0), stepBindings);
1031
- const condName = getWorkflowStepName(argNode(1), stepBindings);
1032
- if (!stepName || !condName) {
1033
- throw new Error(`.${method.name}() in ${workflowName} (${filePath}) must take (step, condition) identifiers`);
1034
- }
1035
- return rewritten([t3__namespace.stringLiteral(stepName), t3__namespace.stringLiteral(condName)]);
1036
- }
1037
- case "foreach": {
1038
- const stepName = getWorkflowStepName(argNode(0), stepBindings);
1039
- if (!stepName) {
1040
- throw new Error(`.foreach() in ${workflowName} (${filePath}) must take a step identifier`);
1041
- }
1042
- const args = [t3__namespace.stringLiteral(stepName)];
1043
- const optsArg = method.args[1];
1044
- if (optsArg && t3__namespace.isExpression(optsArg)) {
1045
- args.push(t3__namespace.cloneNode(optsArg, true));
1046
- }
1047
- return rewritten(args);
1048
- }
1049
- case "commit":
1050
- return rewritten([]);
1051
- default:
1052
- throw new Error(`Unsupported workflow chain method .${method.name}() in ${workflowName} (${filePath})`);
1053
- }
689
+ const argNode = (index) => method.args[index];
690
+ const rewritten = (args, name = method.name) => ({
691
+ name,
692
+ args
693
+ });
694
+ switch (method.name) {
695
+ case "then": {
696
+ const arg = argNode(0);
697
+ if (_babel_types.isIdentifier(arg)) {
698
+ const workflowType = workflowBindings.get(arg.name);
699
+ if (workflowType) return rewritten([_babel_types.stringLiteral(workflowType)], "thenWorkflow");
700
+ }
701
+ const name = getWorkflowStepName(arg, stepBindings);
702
+ if (!name) throw new Error(`.then() in ${workflowName} (${filePath}) must take a step or workflow identifier (inline createStep calls are not supported)`);
703
+ return rewritten([_babel_types.stringLiteral(name)]);
704
+ }
705
+ case "sleep": {
706
+ const arg = argNode(0);
707
+ if (_babel_types.isNumericLiteral(arg)) return rewritten([_babel_types.cloneNode(arg, true)]);
708
+ const name = getWorkflowStepName(arg, stepBindings);
709
+ if (!name) throw new Error(`.sleep() in ${workflowName} (${filePath}) must be a numeric literal or an identifier`);
710
+ return rewritten([_babel_types.stringLiteral(name)]);
711
+ }
712
+ case "sleepUntil": {
713
+ const arg = argNode(0);
714
+ if (_babel_types.isNewExpression(arg) && _babel_types.isIdentifier(arg.callee) && arg.callee.name === "Date") return rewritten([_babel_types.cloneNode(arg, true)]);
715
+ if (_babel_types.isStringLiteral(arg) || _babel_types.isNumericLiteral(arg)) return rewritten([_babel_types.cloneNode(arg, true)]);
716
+ const name = getWorkflowStepName(arg, stepBindings);
717
+ if (!name) throw new Error(`.sleepUntil() in ${workflowName} (${filePath}) must be a Date, string/number literal, or an identifier`);
718
+ return rewritten([_babel_types.stringLiteral(name)]);
719
+ }
720
+ case "parallel": {
721
+ const arg = argNode(0);
722
+ if (!_babel_types.isArrayExpression(arg)) throw new Error(`.parallel() in ${workflowName} (${filePath}) requires an array literal argument`);
723
+ const names = arg.elements.map((el) => getWorkflowStepName(el, stepBindings));
724
+ if (names.some((n) => !n)) throw new Error(`Unable to determine step names inside .parallel() in ${workflowName} (${filePath})`);
725
+ return rewritten([_babel_types.arrayExpression(names.map((n) => _babel_types.stringLiteral(n)))]);
726
+ }
727
+ case "branch": {
728
+ const arg = argNode(0);
729
+ if (!_babel_types.isArrayExpression(arg)) throw new Error(`.branch() in ${workflowName} (${filePath}) requires an array literal of [condition, step] pairs`);
730
+ const pairs = arg.elements.map((pair) => {
731
+ if (!_babel_types.isArrayExpression(pair) || pair.elements.length !== 2) throw new Error(`.branch() pair in ${workflowName} (${filePath}) must be a 2-element array [condition, step]`);
732
+ const condName = getWorkflowStepName(pair.elements[0], stepBindings);
733
+ const stepName = getWorkflowStepName(pair.elements[1], stepBindings);
734
+ if (!condName || !stepName) throw new Error(`.branch() condition and step in ${workflowName} (${filePath}) must be identifiers`);
735
+ return _babel_types.arrayExpression([_babel_types.stringLiteral(condName), _babel_types.stringLiteral(stepName)]);
736
+ });
737
+ return rewritten([_babel_types.arrayExpression(pairs)]);
738
+ }
739
+ case "dowhile":
740
+ case "dountil": {
741
+ const stepName = getWorkflowStepName(argNode(0), stepBindings);
742
+ const condName = getWorkflowStepName(argNode(1), stepBindings);
743
+ if (!stepName || !condName) throw new Error(`.${method.name}() in ${workflowName} (${filePath}) must take (step, condition) identifiers`);
744
+ return rewritten([_babel_types.stringLiteral(stepName), _babel_types.stringLiteral(condName)]);
745
+ }
746
+ case "foreach": {
747
+ const stepName = getWorkflowStepName(argNode(0), stepBindings);
748
+ if (!stepName) throw new Error(`.foreach() in ${workflowName} (${filePath}) must take a step identifier`);
749
+ const args = [_babel_types.stringLiteral(stepName)];
750
+ const optsArg = method.args[1];
751
+ if (optsArg && _babel_types.isExpression(optsArg)) args.push(_babel_types.cloneNode(optsArg, true));
752
+ return rewritten(args);
753
+ }
754
+ case "commit": return rewritten([]);
755
+ default: throw new Error(`Unsupported workflow chain method .${method.name}() in ${workflowName} (${filePath})`);
756
+ }
1054
757
  }
1055
758
  function getExportedName(node) {
1056
- return t3__namespace.isIdentifier(node) ? node.name : node.value;
759
+ return _babel_types.isIdentifier(node) ? node.name : node.value;
1057
760
  }
761
+ /**
762
+ * Materializes one transformed workflow export.
763
+ *
764
+ * Instead of preserving the original `const workflow = createWorkflow(...)` shape,
765
+ * we emit a deterministic exported function whose name matches Temporal's runtime
766
+ * lookup and whose body delegates into the injected helper runtime.
767
+ */
1058
768
  function createTemporalWorkflowStatements(exportName, workflowId, methods, filePath, includeCommit, stepBindings, workflowBindings, runtimeOptions) {
1059
- const createWorkflowArgs = [t3__namespace.cloneNode(workflowId, true)];
1060
- if (runtimeOptions) {
1061
- createWorkflowArgs.push(t3__namespace.cloneNode(runtimeOptions, true));
1062
- }
1063
- let expression = t3__namespace.callExpression(t3__namespace.identifier("createWorkflow"), createWorkflowArgs);
1064
- for (const method of methods) {
1065
- const rewrittenMethod = rewriteChainMethod(method, filePath, exportName, stepBindings, workflowBindings);
1066
- expression = t3__namespace.callExpression(
1067
- t3__namespace.memberExpression(expression, t3__namespace.identifier(rewrittenMethod.name)),
1068
- rewrittenMethod.args
1069
- );
1070
- }
1071
- if (includeCommit && !methods.some((m) => m.name === "commit")) {
1072
- expression = t3__namespace.callExpression(t3__namespace.memberExpression(expression, t3__namespace.identifier("commit")), []);
1073
- }
1074
- const argsParam = t3__namespace.identifier("args");
1075
- const lambda = t3__namespace.arrowFunctionExpression(
1076
- [argsParam],
1077
- t3__namespace.blockStatement([t3__namespace.returnStatement(t3__namespace.callExpression(expression, [t3__namespace.identifier("args")]))])
1078
- );
1079
- const declaration = t3__namespace.variableDeclaration("const", [t3__namespace.variableDeclarator(t3__namespace.identifier(exportName), lambda)]);
1080
- return [t3__namespace.exportNamedDeclaration(declaration)];
769
+ const createWorkflowArgs = [_babel_types.cloneNode(workflowId, true)];
770
+ if (runtimeOptions) createWorkflowArgs.push(_babel_types.cloneNode(runtimeOptions, true));
771
+ let expression = _babel_types.callExpression(_babel_types.identifier("createWorkflow"), createWorkflowArgs);
772
+ for (const method of methods) {
773
+ const rewrittenMethod = rewriteChainMethod(method, filePath, exportName, stepBindings, workflowBindings);
774
+ expression = _babel_types.callExpression(_babel_types.memberExpression(expression, _babel_types.identifier(rewrittenMethod.name)), rewrittenMethod.args);
775
+ }
776
+ if (includeCommit && !methods.some((m) => m.name === "commit")) expression = _babel_types.callExpression(_babel_types.memberExpression(expression, _babel_types.identifier("commit")), []);
777
+ const argsParam = _babel_types.identifier("args");
778
+ const lambda = _babel_types.arrowFunctionExpression([argsParam], _babel_types.blockStatement([_babel_types.returnStatement(_babel_types.callExpression(expression, [_babel_types.identifier("args")]))]));
779
+ const declaration = _babel_types.variableDeclaration("const", [_babel_types.variableDeclarator(_babel_types.identifier(exportName), lambda)]);
780
+ return [_babel_types.exportNamedDeclaration(declaration)];
1081
781
  }
1082
782
  function getTemporalWorkflowExportFromDeclaration(declaration, filePath) {
1083
- if (!t3__namespace.isIdentifier(declaration.id) || !declaration.init) {
1084
- return null;
1085
- }
1086
- const workflowChain = parseWorkflowChain(declaration.init);
1087
- if (!workflowChain) {
1088
- return null;
1089
- }
1090
- const [workflowConfig] = workflowChain.createWorkflowCall.arguments;
1091
- if (!workflowConfig || !t3__namespace.isObjectExpression(workflowConfig)) {
1092
- throw new Error(`Unable to determine workflow config for ${declaration.id.name} in ${filePath}`);
1093
- }
1094
- const { workflowId } = getWorkflowIdMetadata(workflowConfig, declaration.id.name, filePath);
1095
- return {
1096
- exportName: chunkDYBSPLCJ_cjs.toWorkflowType(workflowId),
1097
- workflowId
1098
- };
783
+ if (!_babel_types.isIdentifier(declaration.id) || !declaration.init) return null;
784
+ const workflowChain = parseWorkflowChain(declaration.init);
785
+ if (!workflowChain) return null;
786
+ const [workflowConfig] = workflowChain.createWorkflowCall.arguments;
787
+ if (!workflowConfig || !_babel_types.isObjectExpression(workflowConfig)) throw new Error(`Unable to determine workflow config for ${declaration.id.name} in ${filePath}`);
788
+ const { workflowId } = getWorkflowIdMetadata(workflowConfig, declaration.id.name, filePath);
789
+ return {
790
+ exportName: require_utils.toWorkflowType(workflowId),
791
+ workflowId
792
+ };
1099
793
  }
1100
794
  function getVariableDeclarationFromStatement(statement) {
1101
- if (t3__namespace.isVariableDeclaration(statement)) {
1102
- return statement;
1103
- }
1104
- if (t3__namespace.isExportNamedDeclaration(statement) && t3__namespace.isVariableDeclaration(statement.declaration)) {
1105
- return statement.declaration;
1106
- }
1107
- return null;
795
+ if (_babel_types.isVariableDeclaration(statement)) return statement;
796
+ if (_babel_types.isExportNamedDeclaration(statement) && _babel_types.isVariableDeclaration(statement.declaration)) return statement.declaration;
797
+ return null;
1108
798
  }
1109
799
  function getCommittedWorkflowName(statement) {
1110
- if (!t3__namespace.isExpressionStatement(statement)) {
1111
- return null;
1112
- }
1113
- const { expression } = statement;
1114
- if (!t3__namespace.isCallExpression(expression) || !t3__namespace.isMemberExpression(expression.callee) || expression.callee.computed || !isIdentifierNamed(expression.callee.property, "commit") || !t3__namespace.isIdentifier(expression.callee.object)) {
1115
- return null;
1116
- }
1117
- return expression.callee.object.name;
800
+ if (!_babel_types.isExpressionStatement(statement)) return null;
801
+ const { expression } = statement;
802
+ if (!_babel_types.isCallExpression(expression) || !_babel_types.isMemberExpression(expression.callee) || expression.callee.computed || !isIdentifierNamed(expression.callee.property, "commit") || !_babel_types.isIdentifier(expression.callee.object)) return null;
803
+ return expression.callee.object.name;
1118
804
  }
1119
- function createWorkflowTransformState(program3, filePath) {
1120
- return {
1121
- statements: [...createTemporalWorkflowHelperStatements()],
1122
- workflowNames: /* @__PURE__ */ new Set(),
1123
- committedWorkflowNames: /* @__PURE__ */ new Set(),
1124
- inlineExportedWorkflowNames: /* @__PURE__ */ new Set(),
1125
- strippedNames: /* @__PURE__ */ new Set(),
1126
- stepBindings: collectStepBindings(program3),
1127
- workflowBindings: collectWorkflowBindings(program3, filePath),
1128
- workflowExports: [],
1129
- runtimeOptions: getTemporalWorkflowRuntimeOptions(program3)
1130
- };
805
+ function createWorkflowTransformState(program, filePath) {
806
+ return {
807
+ statements: [...createTemporalWorkflowHelperStatements()],
808
+ workflowNames: /* @__PURE__ */ new Set(),
809
+ committedWorkflowNames: /* @__PURE__ */ new Set(),
810
+ inlineExportedWorkflowNames: /* @__PURE__ */ new Set(),
811
+ strippedNames: /* @__PURE__ */ new Set(),
812
+ stepBindings: collectStepBindings(program),
813
+ workflowBindings: collectWorkflowBindings(program, filePath),
814
+ workflowExports: [],
815
+ runtimeOptions: getTemporalWorkflowRuntimeOptions(program)
816
+ };
1131
817
  }
1132
818
  function collectWorkflowDeclarationMetadata(statement, state) {
1133
- const declarationStatement = getVariableDeclarationFromStatement(statement);
1134
- if (!declarationStatement) {
1135
- return;
1136
- }
1137
- for (const declaration of declarationStatement.declarations) {
1138
- if (!t3__namespace.isIdentifier(declaration.id) || !declaration.init) {
1139
- continue;
1140
- }
1141
- if (!parseWorkflowChain(declaration.init)) {
1142
- continue;
1143
- }
1144
- state.workflowNames.add(declaration.id.name);
1145
- if (t3__namespace.isExportNamedDeclaration(statement)) {
1146
- state.inlineExportedWorkflowNames.add(declaration.id.name);
1147
- }
1148
- }
819
+ const declarationStatement = getVariableDeclarationFromStatement(statement);
820
+ if (!declarationStatement) return;
821
+ for (const declaration of declarationStatement.declarations) {
822
+ if (!_babel_types.isIdentifier(declaration.id) || !declaration.init) continue;
823
+ if (!parseWorkflowChain(declaration.init)) continue;
824
+ state.workflowNames.add(declaration.id.name);
825
+ if (_babel_types.isExportNamedDeclaration(statement)) state.inlineExportedWorkflowNames.add(declaration.id.name);
826
+ }
1149
827
  }
1150
828
  function collectWorkflowExportMetadata(statement, state) {
1151
- if (t3__namespace.isExportNamedDeclaration(statement) && statement.declaration == null && statement.source == null) {
1152
- for (const specifier of statement.specifiers) {
1153
- if (!t3__namespace.isExportSpecifier(specifier) || !t3__namespace.isIdentifier(specifier.local)) {
1154
- continue;
1155
- }
1156
- if (!state.workflowNames.has(specifier.local.name)) {
1157
- continue;
1158
- }
1159
- if (getExportedName(specifier.exported) === specifier.local.name) {
1160
- state.inlineExportedWorkflowNames.add(specifier.local.name);
1161
- }
1162
- }
1163
- }
829
+ if (_babel_types.isExportNamedDeclaration(statement) && statement.declaration == null && statement.source == null) for (const specifier of statement.specifiers) {
830
+ if (!_babel_types.isExportSpecifier(specifier) || !_babel_types.isIdentifier(specifier.local)) continue;
831
+ if (!state.workflowNames.has(specifier.local.name)) continue;
832
+ if (getExportedName(specifier.exported) === specifier.local.name) state.inlineExportedWorkflowNames.add(specifier.local.name);
833
+ }
1164
834
  }
1165
- function collectWorkflowTransformMetadata(program3, state) {
1166
- for (const statement of program3.body) {
1167
- collectWorkflowDeclarationMetadata(statement, state);
1168
- const committedWorkflowName = getCommittedWorkflowName(statement);
1169
- if (committedWorkflowName) {
1170
- state.committedWorkflowNames.add(committedWorkflowName);
1171
- }
1172
- collectWorkflowExportMetadata(statement, state);
1173
- }
835
+ function collectWorkflowTransformMetadata(program, state) {
836
+ for (const statement of program.body) {
837
+ collectWorkflowDeclarationMetadata(statement, state);
838
+ const committedWorkflowName = getCommittedWorkflowName(statement);
839
+ if (committedWorkflowName) state.committedWorkflowNames.add(committedWorkflowName);
840
+ collectWorkflowExportMetadata(statement, state);
841
+ }
1174
842
  }
1175
843
  function rewriteWorkflowImportDeclaration(statement, state) {
1176
- if (statement.source.value === "@mastra/core/workflows") {
1177
- const retainedSpecifiers = statement.specifiers.filter(
1178
- (specifier) => !(t3__namespace.isImportSpecifier(specifier) && t3__namespace.isIdentifier(specifier.imported) && (specifier.imported.name === "createWorkflow" || specifier.imported.name === "createStep"))
1179
- );
1180
- if (retainedSpecifiers.length > 0) {
1181
- state.statements.push(t3__namespace.importDeclaration(retainedSpecifiers, t3__namespace.stringLiteral(statement.source.value)));
1182
- }
1183
- return;
1184
- }
1185
- if (isTemporalHelperModule(statement.source.value) || isStrippedExternalModule(statement.source.value)) {
1186
- for (const name of collectImportedNames(statement)) {
1187
- state.strippedNames.add(name);
1188
- }
1189
- return;
1190
- }
1191
- state.statements.push(statement);
844
+ if (statement.source.value === "@mastra/core/workflows") {
845
+ const retainedSpecifiers = statement.specifiers.filter((specifier) => !(_babel_types.isImportSpecifier(specifier) && _babel_types.isIdentifier(specifier.imported) && (specifier.imported.name === "createWorkflow" || specifier.imported.name === "createStep")));
846
+ if (retainedSpecifiers.length > 0) state.statements.push(_babel_types.importDeclaration(retainedSpecifiers, _babel_types.stringLiteral(statement.source.value)));
847
+ return;
848
+ }
849
+ if (isTemporalHelperModule(statement.source.value) || isStrippedExternalModule(statement.source.value)) {
850
+ for (const name of collectImportedNames(statement)) state.strippedNames.add(name);
851
+ return;
852
+ }
853
+ state.statements.push(statement);
1192
854
  }
1193
855
  function getNormalizedWorkflowBindingName(name, state) {
1194
- if (!state.workflowNames.has(name)) {
1195
- return null;
1196
- }
1197
- return state.workflowBindings.get(name) ?? name;
856
+ if (!state.workflowNames.has(name)) return null;
857
+ return state.workflowBindings.get(name) ?? name;
1198
858
  }
1199
859
  function rewriteWorkflowNamedExport(statement, state) {
1200
- if (statement.source != null) {
1201
- return;
1202
- }
1203
- const retainedSpecifiers = statement.specifiers.flatMap((specifier) => {
1204
- if (!t3__namespace.isExportSpecifier(specifier) || !t3__namespace.isIdentifier(specifier.local)) {
1205
- return [];
1206
- }
1207
- const normalizedLocalName = getNormalizedWorkflowBindingName(specifier.local.name, state);
1208
- if (!normalizedLocalName || getExportedName(specifier.exported) === specifier.local.name) {
1209
- return [];
1210
- }
1211
- return [t3__namespace.exportSpecifier(t3__namespace.identifier(normalizedLocalName), t3__namespace.cloneNode(specifier.exported))];
1212
- });
1213
- if (retainedSpecifiers.length > 0) {
1214
- state.statements.push(t3__namespace.exportNamedDeclaration(null, retainedSpecifiers));
1215
- }
860
+ if (statement.source != null) return;
861
+ const retainedSpecifiers = statement.specifiers.flatMap((specifier) => {
862
+ if (!_babel_types.isExportSpecifier(specifier) || !_babel_types.isIdentifier(specifier.local)) return [];
863
+ const normalizedLocalName = getNormalizedWorkflowBindingName(specifier.local.name, state);
864
+ if (!normalizedLocalName || getExportedName(specifier.exported) === specifier.local.name) return [];
865
+ return [_babel_types.exportSpecifier(_babel_types.identifier(normalizedLocalName), _babel_types.cloneNode(specifier.exported))];
866
+ });
867
+ if (retainedSpecifiers.length > 0) state.statements.push(_babel_types.exportNamedDeclaration(null, retainedSpecifiers));
1216
868
  }
1217
869
  function rewriteWorkflowVariableDeclaration(statement, filePath, state) {
1218
- const declarationStatement = getVariableDeclarationFromStatement(statement);
1219
- if (!declarationStatement) {
1220
- return;
1221
- }
1222
- const declarations = [];
1223
- for (const declaration of declarationStatement.declarations) {
1224
- if (isWorkflowHelperDestructure(declaration)) {
1225
- continue;
1226
- }
1227
- if (t3__namespace.isIdentifier(declaration.id) && state.stepBindings.has(declaration.id.name)) {
1228
- state.strippedNames.add(declaration.id.name);
1229
- continue;
1230
- }
1231
- if (!t3__namespace.isIdentifier(declaration.id) || !declaration.init) {
1232
- declarations.push(declaration);
1233
- continue;
1234
- }
1235
- const workflowChain = parseWorkflowChain(declaration.init);
1236
- if (!workflowChain && nodeReferencesName(declaration.init, state.strippedNames)) {
1237
- state.strippedNames.add(declaration.id.name);
1238
- continue;
1239
- }
1240
- if (!workflowChain) {
1241
- declarations.push(declaration);
1242
- continue;
1243
- }
1244
- const [workflowConfig] = workflowChain.createWorkflowCall.arguments;
1245
- if (!workflowConfig || !t3__namespace.isObjectExpression(workflowConfig)) {
1246
- throw new Error(`Unable to determine workflow config for ${declaration.id.name} in ${filePath}`);
1247
- }
1248
- const { expression: workflowId } = getWorkflowIdMetadata(workflowConfig, declaration.id.name, filePath);
1249
- const workflowExport = getTemporalWorkflowExportFromDeclaration(declaration, filePath);
1250
- if (!workflowExport) {
1251
- throw new Error(`Unable to determine workflow export for ${declaration.id.name} in ${filePath}`);
1252
- }
1253
- const { exportName } = workflowExport;
1254
- state.workflowExports.push(workflowExport);
1255
- state.statements.push(
1256
- ...createTemporalWorkflowStatements(
1257
- exportName,
1258
- workflowId,
1259
- workflowChain.methods,
1260
- filePath,
1261
- state.committedWorkflowNames.has(declaration.id.name),
1262
- state.stepBindings,
1263
- state.workflowBindings,
1264
- state.runtimeOptions
1265
- )
1266
- );
1267
- }
1268
- if (declarations.length > 0) {
1269
- const cloned = declarations.map((declaration) => t3__namespace.cloneNode(declaration, true));
1270
- state.statements.push(t3__namespace.variableDeclaration(declarationStatement.kind, cloned));
1271
- }
870
+ const declarationStatement = getVariableDeclarationFromStatement(statement);
871
+ if (!declarationStatement) return;
872
+ const declarations = [];
873
+ for (const declaration of declarationStatement.declarations) {
874
+ if (isWorkflowHelperDestructure(declaration)) continue;
875
+ if (_babel_types.isIdentifier(declaration.id) && state.stepBindings.has(declaration.id.name)) {
876
+ state.strippedNames.add(declaration.id.name);
877
+ continue;
878
+ }
879
+ if (!_babel_types.isIdentifier(declaration.id) || !declaration.init) {
880
+ declarations.push(declaration);
881
+ continue;
882
+ }
883
+ const workflowChain = parseWorkflowChain(declaration.init);
884
+ if (!workflowChain && nodeReferencesName(declaration.init, state.strippedNames)) {
885
+ state.strippedNames.add(declaration.id.name);
886
+ continue;
887
+ }
888
+ if (!workflowChain) {
889
+ declarations.push(declaration);
890
+ continue;
891
+ }
892
+ const [workflowConfig] = workflowChain.createWorkflowCall.arguments;
893
+ if (!workflowConfig || !_babel_types.isObjectExpression(workflowConfig)) throw new Error(`Unable to determine workflow config for ${declaration.id.name} in ${filePath}`);
894
+ const { expression: workflowId } = getWorkflowIdMetadata(workflowConfig, declaration.id.name, filePath);
895
+ const workflowExport = getTemporalWorkflowExportFromDeclaration(declaration, filePath);
896
+ if (!workflowExport) throw new Error(`Unable to determine workflow export for ${declaration.id.name} in ${filePath}`);
897
+ const { exportName } = workflowExport;
898
+ state.workflowExports.push(workflowExport);
899
+ state.statements.push(...createTemporalWorkflowStatements(exportName, workflowId, workflowChain.methods, filePath, state.committedWorkflowNames.has(declaration.id.name), state.stepBindings, state.workflowBindings, state.runtimeOptions));
900
+ }
901
+ if (declarations.length > 0) {
902
+ const cloned = declarations.map((declaration) => _babel_types.cloneNode(declaration, true));
903
+ state.statements.push(_babel_types.variableDeclaration(declarationStatement.kind, cloned));
904
+ }
1272
905
  }
1273
906
  function rewriteWorkflowStatement(statement, filePath, state) {
1274
- if (t3__namespace.isImportDeclaration(statement)) {
1275
- rewriteWorkflowImportDeclaration(statement, state);
1276
- return;
1277
- }
1278
- if (getCommittedWorkflowName(statement)) {
1279
- return;
1280
- }
1281
- if (t3__namespace.isExportNamedDeclaration(statement)) {
1282
- if (statement.declaration == null) {
1283
- rewriteWorkflowNamedExport(statement, state);
1284
- return;
1285
- }
1286
- if (t3__namespace.isVariableDeclaration(statement.declaration)) {
1287
- rewriteWorkflowVariableDeclaration(statement, filePath, state);
1288
- return;
1289
- }
1290
- state.statements.push(statement.declaration);
1291
- return;
1292
- }
1293
- if (t3__namespace.isExportDefaultDeclaration(statement) && t3__namespace.isIdentifier(statement.declaration)) {
1294
- const normalizedLocalName = getNormalizedWorkflowBindingName(statement.declaration.name, state);
1295
- if (normalizedLocalName) {
1296
- state.statements.push(t3__namespace.exportDefaultDeclaration(t3__namespace.identifier(normalizedLocalName)));
1297
- }
1298
- return;
1299
- }
1300
- if (getVariableDeclarationFromStatement(statement)) {
1301
- rewriteWorkflowVariableDeclaration(statement, filePath, state);
1302
- return;
1303
- }
1304
- state.statements.push(statement);
907
+ if (_babel_types.isImportDeclaration(statement)) {
908
+ rewriteWorkflowImportDeclaration(statement, state);
909
+ return;
910
+ }
911
+ if (getCommittedWorkflowName(statement)) return;
912
+ if (_babel_types.isExportNamedDeclaration(statement)) {
913
+ if (statement.declaration == null) {
914
+ rewriteWorkflowNamedExport(statement, state);
915
+ return;
916
+ }
917
+ if (_babel_types.isVariableDeclaration(statement.declaration)) {
918
+ rewriteWorkflowVariableDeclaration(statement, filePath, state);
919
+ return;
920
+ }
921
+ state.statements.push(statement.declaration);
922
+ return;
923
+ }
924
+ if (_babel_types.isExportDefaultDeclaration(statement) && _babel_types.isIdentifier(statement.declaration)) {
925
+ const normalizedLocalName = getNormalizedWorkflowBindingName(statement.declaration.name, state);
926
+ if (normalizedLocalName) state.statements.push(_babel_types.exportDefaultDeclaration(_babel_types.identifier(normalizedLocalName)));
927
+ return;
928
+ }
929
+ if (getVariableDeclarationFromStatement(statement)) {
930
+ rewriteWorkflowVariableDeclaration(statement, filePath, state);
931
+ return;
932
+ }
933
+ state.statements.push(statement);
1305
934
  }
1306
935
  async function finalizeWorkflowModule(state) {
1307
- const transformedSource = generator.generate(t3__namespace.file(t3__namespace.program(pruneUnusedTopLevelBindings(state.statements), [], "module")), {
1308
- sourceMaps: true
1309
- });
1310
- return {
1311
- ...transformedSource,
1312
- workflows: state.workflowExports
1313
- };
936
+ return {
937
+ ...(0, _babel_generator.generate)(_babel_types.file(_babel_types.program(pruneUnusedTopLevelBindings(state.statements), [], "module")), { sourceMaps: true }),
938
+ workflows: state.workflowExports
939
+ };
1314
940
  }
941
+ /**
942
+ * Transforms a user-authored workflow module into a Temporal-friendly module:
943
+ * - strips Mastra/Temporal setup that cannot run in the workflow sandbox
944
+ * - rewrites fluent workflow chains into deterministic exported functions
945
+ * - returns registry metadata so the entry module can re-export the right names
946
+ */
1315
947
  async function buildTemporalWorkflowModule(entryFile, outputDirectory, outputFileName) {
1316
- const bundle = await rollup.rollup({
1317
- input: entryFile,
1318
- treeshake: "smallest",
1319
- logLevel: "silent",
1320
- plugins: [
1321
- {
1322
- name: "temporal-workflow-transform",
1323
- transform(code, id) {
1324
- const ast = parseModule(id, code);
1325
- const state = createWorkflowTransformState(ast.program, id);
1326
- collectWorkflowTransformMetadata(ast.program, state);
1327
- for (const statement of ast.program.body) {
1328
- rewriteWorkflowStatement(statement, id, state);
1329
- }
1330
- return finalizeWorkflowModule(state);
1331
- }
1332
- }
1333
- ]
1334
- });
1335
- try {
1336
- const baseName = path.basename(outputFileName);
1337
- const { output } = await bundle.write({
1338
- dir: outputDirectory,
1339
- entryFileNames: outputFileName,
1340
- chunkFileNames: `${baseName}-[hash].mjs`,
1341
- format: "esm",
1342
- sourcemap: "inline"
1343
- });
1344
- return {
1345
- outputPath: path.join(outputDirectory, output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName)
1346
- };
1347
- } finally {
1348
- await bundle.close();
1349
- }
948
+ const bundle = await (0, rollup.rollup)({
949
+ input: entryFile,
950
+ treeshake: "smallest",
951
+ logLevel: "silent",
952
+ plugins: [{
953
+ name: "temporal-workflow-transform",
954
+ transform(code, id) {
955
+ const ast = parseModule(id, code);
956
+ const state = createWorkflowTransformState(ast.program, id);
957
+ collectWorkflowTransformMetadata(ast.program, state);
958
+ for (const statement of ast.program.body) rewriteWorkflowStatement(statement, id, state);
959
+ return finalizeWorkflowModule(state);
960
+ }
961
+ }]
962
+ });
963
+ try {
964
+ const baseName = (0, path.basename)(outputFileName);
965
+ const { output } = await bundle.write({
966
+ dir: outputDirectory,
967
+ entryFileNames: outputFileName,
968
+ chunkFileNames: `${baseName}-[hash].mjs`,
969
+ format: "esm",
970
+ sourcemap: "inline"
971
+ });
972
+ return { outputPath: (0, path.join)(outputDirectory, output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName) };
973
+ } finally {
974
+ await bundle.close();
975
+ }
1350
976
  }
1351
-
1352
- // src/plugin.ts
1353
- var CACHE_PATH = "node_modules/.mastra";
1354
- var WORKFLOW_FILE_NAME = "workflow.mjs";
1355
- var ACTIVITIES_FILE_NAME = "activities.mjs";
1356
- var ACTIVITY_BINDINGS_FILE_NAME = "activity-bindings.json";
977
+ //#endregion
978
+ //#region src/plugin.ts
979
+ const CACHE_PATH = "node_modules/.mastra";
980
+ const WORKFLOW_FILE_NAME = "workflow.mjs";
981
+ const ACTIVITIES_FILE_NAME = "activities.mjs";
982
+ const ACTIVITY_BINDINGS_FILE_NAME = "activity-bindings.json";
1357
983
  function getGeneratedWorkflowModulePath(outputDir) {
1358
- return path__default.default.join(outputDir, WORKFLOW_FILE_NAME);
984
+ return path.default.join(outputDir, WORKFLOW_FILE_NAME);
1359
985
  }
1360
986
  function getGeneratedActivitiesModulePath(outputDir) {
1361
- return path__default.default.join(outputDir, ACTIVITIES_FILE_NAME);
987
+ return path.default.join(outputDir, ACTIVITIES_FILE_NAME);
1362
988
  }
1363
989
  function getActivityBindingsPath(outputDir) {
1364
- return path__default.default.join(outputDir, ACTIVITY_BINDINGS_FILE_NAME);
990
+ return path.default.join(outputDir, ACTIVITY_BINDINGS_FILE_NAME);
1365
991
  }
1366
992
  var MastraPlugin = class {
1367
- #prebuildPath = null;
1368
- #compiledActivitiesModules = /* @__PURE__ */ new Map();
1369
- name = "Mastra";
1370
- constructor() {
1371
- }
1372
- async #bundleMastra(entryFile, projectRoot, outputDirectory) {
1373
- const { BuildBundler } = await import('./mastra-deployer-YVT5GB5G.cjs');
1374
- const normalizedEntryFile = entryFile.startsWith("file:/") ? url.fileURLToPath(entryFile) : entryFile;
1375
- const mastraBundler = new BuildBundler();
1376
- await mastraBundler.prepare(outputDirectory);
1377
- await mastraBundler.bundle(normalizedEntryFile, outputDirectory, {
1378
- toolsPaths: [],
1379
- projectRoot
1380
- });
1381
- return path__default.default.join(outputDirectory, "output", "index.mjs");
1382
- }
1383
- async prebuild({
1384
- entryFile,
1385
- projectRoot = process.cwd()
1386
- }) {
1387
- const temporalOutputDir = path__default.default.resolve(projectRoot, CACHE_PATH);
1388
- const compiledEntryPath = await this.#bundleMastra(entryFile, projectRoot, temporalOutputDir);
1389
- await buildTemporalWorkflowModule(compiledEntryPath, temporalOutputDir, WORKFLOW_FILE_NAME);
1390
- const { activityBindings } = await buildTemporalActivitiesModule(
1391
- compiledEntryPath,
1392
- temporalOutputDir,
1393
- ACTIVITIES_FILE_NAME
1394
- );
1395
- await promises.writeFile(getActivityBindingsPath(temporalOutputDir), JSON.stringify(activityBindings, null, 2), "utf8");
1396
- this.#prebuildPath = temporalOutputDir;
1397
- return this.getTemporalWorkerOptions(temporalOutputDir);
1398
- }
1399
- #loadActivityBindings(activityBindingsPath) {
1400
- try {
1401
- const bindings = JSON.parse(fs.readFileSync(activityBindingsPath, "utf8"));
1402
- return bindings;
1403
- } catch (error) {
1404
- throw new Error(`MastraPlugin.prebuild() must be called before use, or ${activityBindingsPath} must exist`, {
1405
- cause: error
1406
- });
1407
- }
1408
- }
1409
- #loadCompiledActivitiesModule(activitiesModulePath) {
1410
- const cachedModule = this.#compiledActivitiesModules.get(activitiesModulePath);
1411
- if (cachedModule) {
1412
- return cachedModule;
1413
- }
1414
- const modulePromise = import(`${url.pathToFileURL(activitiesModulePath).href}?t=${Date.now()}`);
1415
- this.#compiledActivitiesModules.set(activitiesModulePath, modulePromise);
1416
- return modulePromise;
1417
- }
1418
- #generateActivityBindings(activityBindings, compiledActivitiesPath) {
1419
- const generatedActivities = {};
1420
- for (const binding of activityBindings) {
1421
- if (generatedActivities[binding.stepId]) {
1422
- continue;
1423
- }
1424
- generatedActivities[binding.stepId] = async (...args) => {
1425
- const activityModule = await this.#loadCompiledActivitiesModule(compiledActivitiesPath);
1426
- const activity = activityModule[binding.exportName];
1427
- if (typeof activity !== "function") {
1428
- throw new Error(`Unable to load activity '${binding.exportName}' from ${compiledActivitiesPath}`);
1429
- }
1430
- return activity(...args);
1431
- };
1432
- }
1433
- return generatedActivities;
1434
- }
1435
- getTemporalWorkerOptions(temporalOutputDir) {
1436
- const workflowOutputPath = getGeneratedWorkflowModulePath(temporalOutputDir);
1437
- const activitiesOutputPath = getGeneratedActivitiesModulePath(temporalOutputDir);
1438
- const activityBindings = this.#loadActivityBindings(getActivityBindingsPath(temporalOutputDir));
1439
- return {
1440
- workflowsPath: workflowOutputPath,
1441
- // workflowBundle: {
1442
- // codePath: workflowOutputPath,
1443
- // sourceMapPath: `${workflowOutputPath}.map`,
1444
- // },
1445
- activities: this.#generateActivityBindings(activityBindings, activitiesOutputPath)
1446
- };
1447
- }
1448
- configureWorker(options) {
1449
- const augmentedOptions = Object.assign({}, options);
1450
- if (this.#prebuildPath) {
1451
- Object.assign(augmentedOptions, this.getTemporalWorkerOptions(this.#prebuildPath));
1452
- } else {
1453
- if (!options.workflowsPath || !options.activities) {
1454
- throw new Error("MastraPlugin.prebuild() must be called before use");
1455
- }
1456
- }
1457
- return augmentedOptions;
1458
- }
993
+ #prebuildPath = null;
994
+ #compiledActivitiesModules = /* @__PURE__ */ new Map();
995
+ name = "Mastra";
996
+ constructor() {}
997
+ async #bundleMastra(entryFile, projectRoot, outputDirectory) {
998
+ const { BuildBundler } = await Promise.resolve().then(() => require("./mastra-deployer-D6fHvmFM.cjs"));
999
+ const normalizedEntryFile = entryFile.startsWith("file:/") ? (0, url.fileURLToPath)(entryFile) : entryFile;
1000
+ const mastraBundler = new BuildBundler();
1001
+ await mastraBundler.prepare(outputDirectory);
1002
+ await mastraBundler.bundle(normalizedEntryFile, outputDirectory, {
1003
+ toolsPaths: [],
1004
+ projectRoot
1005
+ });
1006
+ return path.default.join(outputDirectory, "output", "index.mjs");
1007
+ }
1008
+ async prebuild({ entryFile, projectRoot = process.cwd() }) {
1009
+ const temporalOutputDir = path.default.resolve(projectRoot, CACHE_PATH);
1010
+ const compiledEntryPath = await this.#bundleMastra(entryFile, projectRoot, temporalOutputDir);
1011
+ await buildTemporalWorkflowModule(compiledEntryPath, temporalOutputDir, WORKFLOW_FILE_NAME);
1012
+ const { activityBindings } = await buildTemporalActivitiesModule(compiledEntryPath, temporalOutputDir, ACTIVITIES_FILE_NAME);
1013
+ await (0, fs_promises.writeFile)(getActivityBindingsPath(temporalOutputDir), JSON.stringify(activityBindings, null, 2), "utf8");
1014
+ this.#prebuildPath = temporalOutputDir;
1015
+ return this.getTemporalWorkerOptions(temporalOutputDir);
1016
+ }
1017
+ #loadActivityBindings(activityBindingsPath) {
1018
+ try {
1019
+ return JSON.parse((0, fs.readFileSync)(activityBindingsPath, "utf8"));
1020
+ } catch (error) {
1021
+ throw new Error(`MastraPlugin.prebuild() must be called before use, or ${activityBindingsPath} must exist`, { cause: error });
1022
+ }
1023
+ }
1024
+ #loadCompiledActivitiesModule(activitiesModulePath) {
1025
+ const cachedModule = this.#compiledActivitiesModules.get(activitiesModulePath);
1026
+ if (cachedModule) return cachedModule;
1027
+ const modulePromise = import(`${(0, url.pathToFileURL)(activitiesModulePath).href}?t=${Date.now()}`);
1028
+ this.#compiledActivitiesModules.set(activitiesModulePath, modulePromise);
1029
+ return modulePromise;
1030
+ }
1031
+ #generateActivityBindings(activityBindings, compiledActivitiesPath) {
1032
+ const generatedActivities = {};
1033
+ for (const binding of activityBindings) {
1034
+ if (generatedActivities[binding.stepId]) continue;
1035
+ generatedActivities[binding.stepId] = async (...args) => {
1036
+ const activity = (await this.#loadCompiledActivitiesModule(compiledActivitiesPath))[binding.exportName];
1037
+ if (typeof activity !== "function") throw new Error(`Unable to load activity '${binding.exportName}' from ${compiledActivitiesPath}`);
1038
+ return activity(...args);
1039
+ };
1040
+ }
1041
+ return generatedActivities;
1042
+ }
1043
+ getTemporalWorkerOptions(temporalOutputDir) {
1044
+ const workflowOutputPath = getGeneratedWorkflowModulePath(temporalOutputDir);
1045
+ const activitiesOutputPath = getGeneratedActivitiesModulePath(temporalOutputDir);
1046
+ const activityBindings = this.#loadActivityBindings(getActivityBindingsPath(temporalOutputDir));
1047
+ return {
1048
+ workflowsPath: workflowOutputPath,
1049
+ activities: this.#generateActivityBindings(activityBindings, activitiesOutputPath)
1050
+ };
1051
+ }
1052
+ configureWorker(options) {
1053
+ const augmentedOptions = Object.assign({}, options);
1054
+ if (this.#prebuildPath) Object.assign(augmentedOptions, this.getTemporalWorkerOptions(this.#prebuildPath));
1055
+ else if (!options.workflowsPath || !options.activities) throw new Error("MastraPlugin.prebuild() must be called before use");
1056
+ return augmentedOptions;
1057
+ }
1459
1058
  };
1460
-
1059
+ //#endregion
1461
1060
  exports.MastraPlugin = MastraPlugin;
1462
- //# sourceMappingURL=worker.cjs.map
1061
+
1463
1062
  //# sourceMappingURL=worker.cjs.map