@mastra/deployer 0.10.0 → 0.10.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,7 +32,7 @@ import { getTelemetryHandler as getTelemetryHandler$1, storeTelemetryHandler as
32
32
  import { executeAgentToolHandler as executeAgentToolHandler$1, getToolsHandler as getToolsHandler$1, getToolByIdHandler as getToolByIdHandler$1, executeToolHandler as executeToolHandler$1 } from '@mastra/server/handlers/tools';
33
33
  import { upsertVectors as upsertVectors$1, createIndex as createIndex$1, queryVectors as queryVectors$1, listIndexes as listIndexes$1, describeIndex as describeIndex$1, deleteIndex as deleteIndex$1 } from '@mastra/server/handlers/vector';
34
34
  import { getSpeakersHandler as getSpeakersHandler$1, generateSpeechHandler, transcribeSpeechHandler } from '@mastra/server/handlers/voice';
35
- import { getWorkflowsHandler as getWorkflowsHandler$1, getWorkflowByIdHandler as getWorkflowByIdHandler$1, getWorkflowRunsHandler as getWorkflowRunsHandler$1, resumeWorkflowHandler as resumeWorkflowHandler$1, resumeAsyncWorkflowHandler as resumeAsyncWorkflowHandler$1, createWorkflowRunHandler as createWorkflowRunHandler$1, startAsyncWorkflowHandler as startAsyncWorkflowHandler$1, startWorkflowRunHandler as startWorkflowRunHandler$1, watchWorkflowHandler as watchWorkflowHandler$1 } from '@mastra/server/handlers/workflows';
35
+ import { streamWorkflowHandler as streamWorkflowHandler$1, getWorkflowsHandler as getWorkflowsHandler$1, getWorkflowByIdHandler as getWorkflowByIdHandler$1, getWorkflowRunsHandler as getWorkflowRunsHandler$1, resumeWorkflowHandler as resumeWorkflowHandler$1, resumeAsyncWorkflowHandler as resumeAsyncWorkflowHandler$1, createWorkflowRunHandler as createWorkflowRunHandler$1, startAsyncWorkflowHandler as startAsyncWorkflowHandler$1, startWorkflowRunHandler as startWorkflowRunHandler$1, watchWorkflowHandler as watchWorkflowHandler$1 } from '@mastra/server/handlers/workflows';
36
36
 
37
37
  // src/server/index.ts
38
38
  var RequestError = class extends Error {
@@ -4174,16 +4174,16 @@ function watchWorkflowHandler(c2) {
4174
4174
  workflowId,
4175
4175
  runId
4176
4176
  });
4177
+ const reader = result.getReader();
4177
4178
  stream4.onAbort(() => {
4178
- if (!result.locked) {
4179
- return result.cancel();
4180
- }
4179
+ void reader.cancel("request aborted");
4181
4180
  });
4182
- for await (const chunk of result) {
4183
- await stream4.write(chunk.toString() + "");
4181
+ let chunkResult;
4182
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
4183
+ await stream4.write(JSON.stringify(chunkResult.value) + "");
4184
4184
  }
4185
4185
  } catch (err) {
4186
- console.log(err);
4186
+ mastra.getLogger().error("Error in watch stream: " + (err?.message ?? "Unknown error"));
4187
4187
  }
4188
4188
  },
4189
4189
  async (err) => {
@@ -4194,6 +4194,46 @@ function watchWorkflowHandler(c2) {
4194
4194
  return handleError(error, "Error watching workflow");
4195
4195
  }
4196
4196
  }
4197
+ async function streamWorkflowHandler(c2) {
4198
+ try {
4199
+ const mastra = c2.get("mastra");
4200
+ const logger2 = mastra.getLogger();
4201
+ const workflowId = c2.req.param("workflowId");
4202
+ const runtimeContext = c2.get("runtimeContext");
4203
+ const { inputData, runtimeContext: runtimeContextFromRequest } = await c2.req.json();
4204
+ const runId = c2.req.query("runId");
4205
+ return stream(
4206
+ c2,
4207
+ async (stream4) => {
4208
+ try {
4209
+ const result = streamWorkflowHandler$1({
4210
+ mastra,
4211
+ workflowId,
4212
+ runId,
4213
+ inputData,
4214
+ runtimeContext,
4215
+ runtimeContextFromRequest
4216
+ });
4217
+ const reader = result.stream.getReader();
4218
+ stream4.onAbort(() => {
4219
+ void reader.cancel("request aborted");
4220
+ });
4221
+ let chunkResult;
4222
+ while ((chunkResult = await reader.read()) && !chunkResult.done) {
4223
+ await stream4.write(JSON.stringify(chunkResult.value) + "");
4224
+ }
4225
+ } catch (err) {
4226
+ console.log(err);
4227
+ }
4228
+ },
4229
+ async (err) => {
4230
+ logger2.error("Error in workflow stream: " + err?.message);
4231
+ }
4232
+ );
4233
+ } catch (error) {
4234
+ return handleError(error, "Error streaming workflow");
4235
+ }
4236
+ }
4197
4237
  async function resumeAsyncWorkflowHandler(c2) {
4198
4238
  try {
4199
4239
  const mastra = c2.get("mastra");
@@ -5495,7 +5535,7 @@ async function createHonoServer(mastra, options = {}) {
5495
5535
  executeAgentToolHandler
5496
5536
  );
5497
5537
  app.post(
5498
- "/api/mcp/:serverId/mcp",
5538
+ "/api/servers/:serverId/mcp",
5499
5539
  bodyLimit(bodyLimitOptions),
5500
5540
  h({
5501
5541
  description: "Send a message to an MCP server using Streamable HTTP",
@@ -5522,8 +5562,8 @@ async function createHonoServer(mastra, options = {}) {
5522
5562
  }),
5523
5563
  getMcpServerMessageHandler
5524
5564
  );
5525
- const mcpSseBasePath = "/api/mcp/:serverId/sse";
5526
- const mcpSseMessagePath = "/api/mcp/:serverId/messages";
5565
+ const mcpSseBasePath = "/api/servers/:serverId/sse";
5566
+ const mcpSseMessagePath = "/api/servers/:serverId/messages";
5527
5567
  app.get(
5528
5568
  mcpSseBasePath,
5529
5569
  h({
@@ -6280,7 +6320,7 @@ async function createHonoServer(mastra, options = {}) {
6280
6320
  {
6281
6321
  name: "runId",
6282
6322
  in: "query",
6283
- required: false,
6323
+ required: true,
6284
6324
  schema: { type: "string" }
6285
6325
  }
6286
6326
  ],
@@ -6293,6 +6333,53 @@ async function createHonoServer(mastra, options = {}) {
6293
6333
  }),
6294
6334
  watchLegacyWorkflowHandler
6295
6335
  );
6336
+ app.post(
6337
+ "/api/workflows/:workflowId/stream",
6338
+ h({
6339
+ description: "Stream workflow in real-time",
6340
+ parameters: [
6341
+ {
6342
+ name: "workflowId",
6343
+ in: "path",
6344
+ required: true,
6345
+ schema: { type: "string" }
6346
+ },
6347
+ {
6348
+ name: "runId",
6349
+ in: "query",
6350
+ required: false,
6351
+ schema: { type: "string" }
6352
+ }
6353
+ ],
6354
+ requestBody: {
6355
+ required: true,
6356
+ content: {
6357
+ "application/json": {
6358
+ schema: {
6359
+ type: "object",
6360
+ properties: {
6361
+ inputData: { type: "object" },
6362
+ runtimeContext: {
6363
+ type: "object",
6364
+ description: "Runtime context for the workflow execution"
6365
+ }
6366
+ }
6367
+ }
6368
+ }
6369
+ }
6370
+ },
6371
+ responses: {
6372
+ 200: {
6373
+ description: "vNext workflow run started"
6374
+ },
6375
+ 404: {
6376
+ description: "vNext workflow not found"
6377
+ }
6378
+ },
6379
+ tags: ["vNextWorkflows"]
6380
+ }),
6381
+ streamWorkflowHandler
6382
+ );
6296
6383
  app.get(
6297
6384
  "/api/workflows",
6298
6385
  h({
@@ -7005,7 +7092,7 @@ async function createNodeServer(mastra, options = {}) {
7005
7092
  {
7006
7093
  fetch: app.fetch,
7007
7094
  port,
7008
- hostname: serverOptions?.host
7095
+ hostname: serverOptions?.host ?? "localhost"
7009
7096
  },
7010
7097
  () => {
7011
7098
  const logger2 = mastra.getLogger();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer",
3
- "version": "0.10.0",
3
+ "version": "0.10.1-alpha.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
@@ -100,6 +100,7 @@
100
100
  "esbuild": "^0.25.1",
101
101
  "find-workspaces": "^0.3.1",
102
102
  "fs-extra": "^11.3.0",
103
+ "globby": "^14.1.0",
103
104
  "hono": "^4.7.4",
104
105
  "resolve-from": "^5.0.0",
105
106
  "rollup": "^4.35.0",
@@ -107,7 +108,7 @@
107
108
  "rollup-plugin-node-externals": "^8.0.0",
108
109
  "typescript-paths": "^1.5.1",
109
110
  "zod": "^3.24.3",
110
- "@mastra/server": "^0.10.0"
111
+ "@mastra/server": "^0.10.1-alpha.0"
111
112
  },
112
113
  "devDependencies": {
113
114
  "@hono/node-server": "^1.13.8",
@@ -127,8 +128,8 @@
127
128
  "typescript": "^5.8.2",
128
129
  "vitest": "^2.1.9",
129
130
  "@internal/lint": "0.0.6",
130
- "@mastra/core": "0.10.0",
131
- "@mastra/mcp": "^0.10.0"
131
+ "@mastra/mcp": "^0.10.1-alpha.0",
132
+ "@mastra/core": "0.10.1-alpha.1"
132
133
  },
133
134
  "peerDependencies": {
134
135
  "@mastra/core": "^0.10.0"
@@ -1,255 +0,0 @@
1
- 'use strict';
2
-
3
- var babel = require('@babel/core');
4
- var rollup = require('rollup');
5
- var esbuild = require('rollup-plugin-esbuild');
6
- var commonjs = require('@rollup/plugin-commonjs');
7
-
8
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
-
10
- function _interopNamespace(e) {
11
- if (e && e.__esModule) return e;
12
- var n = Object.create(null);
13
- if (e) {
14
- Object.keys(e).forEach(function (k) {
15
- if (k !== 'default') {
16
- var d = Object.getOwnPropertyDescriptor(e, k);
17
- Object.defineProperty(n, k, d.get ? d : {
18
- enumerable: true,
19
- get: function () { return e[k]; }
20
- });
21
- }
22
- });
23
- }
24
- n.default = e;
25
- return Object.freeze(n);
26
- }
27
-
28
- var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
29
- var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
30
- var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
31
-
32
- // src/build/telemetry.ts
33
- function removeAllOptionsFromMastraExcept(result, option) {
34
- const t = babel__namespace.default.types;
35
- return {
36
- name: "remove-all-except-" + option + "-config",
37
- visitor: {
38
- ExportNamedDeclaration: {
39
- // remove all exports
40
- exit(path) {
41
- path.remove();
42
- }
43
- },
44
- NewExpression(path, state) {
45
- const varDeclaratorPath = path.findParent((path2) => t.isVariableDeclarator(path2.node));
46
- if (!varDeclaratorPath) {
47
- return;
48
- }
49
- const parentNode = path.parentPath.node;
50
- if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
51
- return;
52
- }
53
- let mastraArgs = t.objectExpression([]);
54
- if (t.isObjectExpression(path.node.arguments[0])) {
55
- mastraArgs = path.node.arguments[0];
56
- }
57
- let telemetry = mastraArgs.properties.find(
58
- // @ts-ignore
59
- (prop) => prop.key.name === option
60
- );
61
- let telemetryValue = t.objectExpression([]);
62
- const programPath = path.scope.getProgramParent().path;
63
- if (!programPath) {
64
- return;
65
- }
66
- if (telemetry && t.isObjectProperty(telemetry) && t.isExpression(telemetry.value)) {
67
- result.hasCustomConfig = true;
68
- telemetryValue = telemetry.value;
69
- if (t.isIdentifier(telemetry.value) && telemetry.value.name === option) {
70
- const telemetryBinding = state.file.scope.getBinding(option);
71
- if (telemetryBinding && t.isVariableDeclarator(telemetryBinding.path.node)) {
72
- const id = path.scope.generateUidIdentifier(option);
73
- telemetryBinding.path.replaceWith(t.variableDeclarator(id, telemetryBinding.path.node.init));
74
- telemetryValue = id;
75
- }
76
- }
77
- }
78
- const exportDeclaration = t.exportNamedDeclaration(
79
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), telemetryValue)]),
80
- []
81
- );
82
- programPath.node.body.push(exportDeclaration);
83
- }
84
- }
85
- };
86
- }
87
-
88
- // src/build/babel/remove-all-options-telemetry.ts
89
- function removeAllOptionsExceptTelemetry(result) {
90
- return removeAllOptionsFromMastraExcept(result, "telemetry");
91
- }
92
- function removeNonReferencedNodes() {
93
- const t = babel__namespace.default.types;
94
- return {
95
- name: "remove-non-referenced-nodes",
96
- visitor: {
97
- Program(path) {
98
- const scope = path.scope;
99
- const currentBody = path.get("body");
100
- const filteredBody = currentBody.filter((childPath) => {
101
- if (childPath.isExportDeclaration()) {
102
- return true;
103
- }
104
- if (childPath.isVariableDeclaration()) {
105
- return childPath.node.declarations.some((decl) => {
106
- if (!t.isIdentifier(decl.id)) {
107
- return false;
108
- }
109
- const name = decl.id.name;
110
- const binding = scope.getBinding(name);
111
- return binding && (binding.referenced || binding.referencePaths.length > 0);
112
- });
113
- }
114
- if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {
115
- if (!t.isIdentifier(childPath.node.id)) {
116
- return false;
117
- }
118
- const name = childPath.node.id.name;
119
- const binding = scope.getBinding(name);
120
- return binding && (binding.referenced || binding.referencePaths.length > 0);
121
- }
122
- if (childPath.isImportDeclaration()) {
123
- return childPath.node.specifiers.some((specifier) => {
124
- const importedName = specifier.local.name;
125
- const binding = scope.getBinding(importedName);
126
- return binding && (binding.referenced || binding.referencePaths.length > 0);
127
- });
128
- }
129
- return false;
130
- });
131
- path.set(
132
- "body",
133
- filteredBody.map((p) => p.node)
134
- );
135
- }
136
- }
137
- };
138
- }
139
-
140
- // src/build/plugins/remove-unused-references.ts
141
- function recursiveRemoveNonReferencedNodes(code) {
142
- return new Promise(async (resolve, reject) => {
143
- babel__namespace.transform(
144
- code,
145
- {
146
- babelrc: false,
147
- configFile: false,
148
- plugins: [removeNonReferencedNodes()]
149
- },
150
- (err, result) => {
151
- if (err) {
152
- return reject(err);
153
- }
154
- if (result && result.code !== code) {
155
- return recursiveRemoveNonReferencedNodes(result.code).then(resolve, reject);
156
- }
157
- resolve({
158
- code: result.code,
159
- map: result.map
160
- });
161
- }
162
- );
163
- });
164
- }
165
-
166
- // src/build/telemetry.ts
167
- function getTelemetryBundler(entryFile, result) {
168
- return rollup.rollup({
169
- logLevel: "silent",
170
- input: {
171
- "telemetry-config": entryFile
172
- },
173
- treeshake: "smallest",
174
- plugins: [
175
- // transpile typescript to something we understand
176
- esbuild__default.default({
177
- target: "node20",
178
- platform: "node",
179
- minify: false
180
- }),
181
- commonjs__default.default({
182
- extensions: [".js", ".ts"],
183
- strictRequires: "strict",
184
- transformMixedEsModules: true,
185
- ignoreTryCatch: false
186
- }),
187
- {
188
- name: "get-telemetry-config",
189
- transform(code, id) {
190
- if (id !== entryFile) {
191
- return;
192
- }
193
- return new Promise((resolve, reject) => {
194
- babel__namespace.transform(
195
- code,
196
- {
197
- babelrc: false,
198
- configFile: false,
199
- filename: id,
200
- plugins: [removeAllOptionsExceptTelemetry(result)]
201
- },
202
- (err, result2) => {
203
- if (err) {
204
- return reject(err);
205
- }
206
- resolve({
207
- code: result2.code,
208
- map: result2.map
209
- });
210
- }
211
- );
212
- });
213
- }
214
- },
215
- // let esbuild remove all unused imports
216
- esbuild__default.default({
217
- target: "node20",
218
- platform: "node",
219
- minify: false
220
- }),
221
- {
222
- name: "cleanup",
223
- transform(code, id) {
224
- if (id !== entryFile) {
225
- return;
226
- }
227
- return recursiveRemoveNonReferencedNodes(code);
228
- }
229
- },
230
- // let esbuild remove all unused imports
231
- esbuild__default.default({
232
- target: "node20",
233
- platform: "node",
234
- minify: false
235
- })
236
- ]
237
- });
238
- }
239
- async function writeTelemetryConfig(entryFile, outputDir) {
240
- const result = {
241
- hasCustomConfig: false
242
- };
243
- const bundle = await getTelemetryBundler(entryFile, result);
244
- const { output } = await bundle.write({
245
- dir: outputDir,
246
- format: "es",
247
- entryFileNames: "[name].mjs"
248
- });
249
- const externals = output[0].imports.filter((x) => !x.startsWith("./"));
250
- return { ...result, externalDependencies: externals };
251
- }
252
-
253
- exports.recursiveRemoveNonReferencedNodes = recursiveRemoveNonReferencedNodes;
254
- exports.removeAllOptionsFromMastraExcept = removeAllOptionsFromMastraExcept;
255
- exports.writeTelemetryConfig = writeTelemetryConfig;
@@ -1,228 +0,0 @@
1
- import * as babel from '@babel/core';
2
- import babel__default from '@babel/core';
3
- import { rollup } from 'rollup';
4
- import esbuild from 'rollup-plugin-esbuild';
5
- import commonjs from '@rollup/plugin-commonjs';
6
-
7
- // src/build/telemetry.ts
8
- function removeAllOptionsFromMastraExcept(result, option) {
9
- const t = babel__default.types;
10
- return {
11
- name: "remove-all-except-" + option + "-config",
12
- visitor: {
13
- ExportNamedDeclaration: {
14
- // remove all exports
15
- exit(path) {
16
- path.remove();
17
- }
18
- },
19
- NewExpression(path, state) {
20
- const varDeclaratorPath = path.findParent((path2) => t.isVariableDeclarator(path2.node));
21
- if (!varDeclaratorPath) {
22
- return;
23
- }
24
- const parentNode = path.parentPath.node;
25
- if (!t.isVariableDeclarator(parentNode) || !t.isIdentifier(parentNode.id) || parentNode.id.name !== "mastra") {
26
- return;
27
- }
28
- let mastraArgs = t.objectExpression([]);
29
- if (t.isObjectExpression(path.node.arguments[0])) {
30
- mastraArgs = path.node.arguments[0];
31
- }
32
- let telemetry = mastraArgs.properties.find(
33
- // @ts-ignore
34
- (prop) => prop.key.name === option
35
- );
36
- let telemetryValue = t.objectExpression([]);
37
- const programPath = path.scope.getProgramParent().path;
38
- if (!programPath) {
39
- return;
40
- }
41
- if (telemetry && t.isObjectProperty(telemetry) && t.isExpression(telemetry.value)) {
42
- result.hasCustomConfig = true;
43
- telemetryValue = telemetry.value;
44
- if (t.isIdentifier(telemetry.value) && telemetry.value.name === option) {
45
- const telemetryBinding = state.file.scope.getBinding(option);
46
- if (telemetryBinding && t.isVariableDeclarator(telemetryBinding.path.node)) {
47
- const id = path.scope.generateUidIdentifier(option);
48
- telemetryBinding.path.replaceWith(t.variableDeclarator(id, telemetryBinding.path.node.init));
49
- telemetryValue = id;
50
- }
51
- }
52
- }
53
- const exportDeclaration = t.exportNamedDeclaration(
54
- t.variableDeclaration("const", [t.variableDeclarator(t.identifier(option), telemetryValue)]),
55
- []
56
- );
57
- programPath.node.body.push(exportDeclaration);
58
- }
59
- }
60
- };
61
- }
62
-
63
- // src/build/babel/remove-all-options-telemetry.ts
64
- function removeAllOptionsExceptTelemetry(result) {
65
- return removeAllOptionsFromMastraExcept(result, "telemetry");
66
- }
67
- function removeNonReferencedNodes() {
68
- const t = babel__default.types;
69
- return {
70
- name: "remove-non-referenced-nodes",
71
- visitor: {
72
- Program(path) {
73
- const scope = path.scope;
74
- const currentBody = path.get("body");
75
- const filteredBody = currentBody.filter((childPath) => {
76
- if (childPath.isExportDeclaration()) {
77
- return true;
78
- }
79
- if (childPath.isVariableDeclaration()) {
80
- return childPath.node.declarations.some((decl) => {
81
- if (!t.isIdentifier(decl.id)) {
82
- return false;
83
- }
84
- const name = decl.id.name;
85
- const binding = scope.getBinding(name);
86
- return binding && (binding.referenced || binding.referencePaths.length > 0);
87
- });
88
- }
89
- if (childPath.isFunctionDeclaration() || childPath.isClassDeclaration()) {
90
- if (!t.isIdentifier(childPath.node.id)) {
91
- return false;
92
- }
93
- const name = childPath.node.id.name;
94
- const binding = scope.getBinding(name);
95
- return binding && (binding.referenced || binding.referencePaths.length > 0);
96
- }
97
- if (childPath.isImportDeclaration()) {
98
- return childPath.node.specifiers.some((specifier) => {
99
- const importedName = specifier.local.name;
100
- const binding = scope.getBinding(importedName);
101
- return binding && (binding.referenced || binding.referencePaths.length > 0);
102
- });
103
- }
104
- return false;
105
- });
106
- path.set(
107
- "body",
108
- filteredBody.map((p) => p.node)
109
- );
110
- }
111
- }
112
- };
113
- }
114
-
115
- // src/build/plugins/remove-unused-references.ts
116
- function recursiveRemoveNonReferencedNodes(code) {
117
- return new Promise(async (resolve, reject) => {
118
- babel.transform(
119
- code,
120
- {
121
- babelrc: false,
122
- configFile: false,
123
- plugins: [removeNonReferencedNodes()]
124
- },
125
- (err, result) => {
126
- if (err) {
127
- return reject(err);
128
- }
129
- if (result && result.code !== code) {
130
- return recursiveRemoveNonReferencedNodes(result.code).then(resolve, reject);
131
- }
132
- resolve({
133
- code: result.code,
134
- map: result.map
135
- });
136
- }
137
- );
138
- });
139
- }
140
-
141
- // src/build/telemetry.ts
142
- function getTelemetryBundler(entryFile, result) {
143
- return rollup({
144
- logLevel: "silent",
145
- input: {
146
- "telemetry-config": entryFile
147
- },
148
- treeshake: "smallest",
149
- plugins: [
150
- // transpile typescript to something we understand
151
- esbuild({
152
- target: "node20",
153
- platform: "node",
154
- minify: false
155
- }),
156
- commonjs({
157
- extensions: [".js", ".ts"],
158
- strictRequires: "strict",
159
- transformMixedEsModules: true,
160
- ignoreTryCatch: false
161
- }),
162
- {
163
- name: "get-telemetry-config",
164
- transform(code, id) {
165
- if (id !== entryFile) {
166
- return;
167
- }
168
- return new Promise((resolve, reject) => {
169
- babel.transform(
170
- code,
171
- {
172
- babelrc: false,
173
- configFile: false,
174
- filename: id,
175
- plugins: [removeAllOptionsExceptTelemetry(result)]
176
- },
177
- (err, result2) => {
178
- if (err) {
179
- return reject(err);
180
- }
181
- resolve({
182
- code: result2.code,
183
- map: result2.map
184
- });
185
- }
186
- );
187
- });
188
- }
189
- },
190
- // let esbuild remove all unused imports
191
- esbuild({
192
- target: "node20",
193
- platform: "node",
194
- minify: false
195
- }),
196
- {
197
- name: "cleanup",
198
- transform(code, id) {
199
- if (id !== entryFile) {
200
- return;
201
- }
202
- return recursiveRemoveNonReferencedNodes(code);
203
- }
204
- },
205
- // let esbuild remove all unused imports
206
- esbuild({
207
- target: "node20",
208
- platform: "node",
209
- minify: false
210
- })
211
- ]
212
- });
213
- }
214
- async function writeTelemetryConfig(entryFile, outputDir) {
215
- const result = {
216
- hasCustomConfig: false
217
- };
218
- const bundle = await getTelemetryBundler(entryFile, result);
219
- const { output } = await bundle.write({
220
- dir: outputDir,
221
- format: "es",
222
- entryFileNames: "[name].mjs"
223
- });
224
- const externals = output[0].imports.filter((x) => !x.startsWith("./"));
225
- return { ...result, externalDependencies: externals };
226
- }
227
-
228
- export { recursiveRemoveNonReferencedNodes, removeAllOptionsFromMastraExcept, writeTelemetryConfig };