@mastra/deployer 0.0.0-commonjs-20250227130920

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/.turbo/turbo-build.log +41 -0
  2. package/CHANGELOG.md +897 -0
  3. package/LICENSE +44 -0
  4. package/README.md +159 -0
  5. package/dist/_tsup-dts-rollup.d.cts +360 -0
  6. package/dist/_tsup-dts-rollup.d.ts +360 -0
  7. package/dist/build/analyze.cjs +367 -0
  8. package/dist/build/analyze.d.cts +1 -0
  9. package/dist/build/analyze.d.ts +1 -0
  10. package/dist/build/analyze.js +2 -0
  11. package/dist/build/bundler.cjs +353 -0
  12. package/dist/build/bundler.d.cts +2 -0
  13. package/dist/build/bundler.d.ts +2 -0
  14. package/dist/build/bundler.js +2 -0
  15. package/dist/build/index.cjs +1146 -0
  16. package/dist/build/index.d.cts +10 -0
  17. package/dist/build/index.d.ts +10 -0
  18. package/dist/build/index.js +5 -0
  19. package/dist/bundler/index.cjs +999 -0
  20. package/dist/bundler/index.d.cts +1 -0
  21. package/dist/bundler/index.d.ts +1 -0
  22. package/dist/bundler/index.js +5 -0
  23. package/dist/chunk-3ONBKVC4.js +113 -0
  24. package/dist/chunk-AXS5WSIK.js +290 -0
  25. package/dist/chunk-DTSFVNIF.js +260 -0
  26. package/dist/chunk-JMH7HCD6.js +274 -0
  27. package/dist/chunk-SGK37ZWD.js +254 -0
  28. package/dist/chunk-YNXJO2XU.js +69 -0
  29. package/dist/index.cjs +1229 -0
  30. package/dist/index.d.cts +6 -0
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.js +131 -0
  33. package/dist/server/index.cjs +4930 -0
  34. package/dist/server/index.d.cts +2 -0
  35. package/dist/server/index.d.ts +2 -0
  36. package/dist/server/index.js +4923 -0
  37. package/dist/templates/instrumentation-template.js +86 -0
  38. package/eslint.config.js +6 -0
  39. package/global.d.ts +0 -0
  40. package/package.json +112 -0
  41. package/public/templates/instrumentation-template.js +86 -0
  42. package/src/build/analyze.ts +279 -0
  43. package/src/build/babel/fix-libsql.ts +41 -0
  44. package/src/build/babel/get-deployer.ts +54 -0
  45. package/src/build/babel/get-telemetry-config.ts +62 -0
  46. package/src/build/babel/remove-deployer.ts +43 -0
  47. package/src/build/bundle.ts +139 -0
  48. package/src/build/bundler.ts +135 -0
  49. package/src/build/deployer.ts +67 -0
  50. package/src/build/deps.ts +149 -0
  51. package/src/build/env.ts +76 -0
  52. package/src/build/fs.ts +66 -0
  53. package/src/build/index.ts +7 -0
  54. package/src/build/isNodeBuiltin.ts +7 -0
  55. package/src/build/plugins/fix-libsql.ts +69 -0
  56. package/src/build/plugins/hono-alias.ts +17 -0
  57. package/src/build/plugins/pino.ts +93 -0
  58. package/src/build/plugins/remove-deployer.ts +37 -0
  59. package/src/build/plugins/telemetry-fix.ts +54 -0
  60. package/src/build/telemetry.ts +76 -0
  61. package/src/build/utils.ts +12 -0
  62. package/src/build/watcher.ts +43 -0
  63. package/src/bundler/index.ts +144 -0
  64. package/src/deploy/base.ts +30 -0
  65. package/src/deploy/index.ts +2 -0
  66. package/src/deploy/log.ts +61 -0
  67. package/src/index.ts +3 -0
  68. package/src/server/handlers/agents.ts +209 -0
  69. package/src/server/handlers/client.ts +36 -0
  70. package/src/server/handlers/error.ts +29 -0
  71. package/src/server/handlers/logs.ts +53 -0
  72. package/src/server/handlers/memory.ts +196 -0
  73. package/src/server/handlers/prompt.ts +128 -0
  74. package/src/server/handlers/root.ts +6 -0
  75. package/src/server/handlers/telemetry.ts +48 -0
  76. package/src/server/handlers/tools.ts +114 -0
  77. package/src/server/handlers/utils.ts +15 -0
  78. package/src/server/handlers/vector.ts +149 -0
  79. package/src/server/handlers/workflows.ts +119 -0
  80. package/src/server/index.ts +1355 -0
  81. package/src/server/openapi.json +434 -0
  82. package/src/server/openapi.script.js +22 -0
  83. package/src/server/types.ts +4 -0
  84. package/src/server/welcome.ts +105 -0
  85. package/tsconfig.json +5 -0
  86. package/vitest.config.ts +8 -0
@@ -0,0 +1,367 @@
1
+ 'use strict';
2
+
3
+ var commonjs = require('@rollup/plugin-commonjs');
4
+ var json = require('@rollup/plugin-json');
5
+ var nodeResolve = require('@rollup/plugin-node-resolve');
6
+ var virtual = require('@rollup/plugin-virtual');
7
+ var fs = require('fs');
8
+ var url = require('url');
9
+ var rollup = require('rollup');
10
+ var esbuild = require('rollup-plugin-esbuild');
11
+ var module$1 = require('module');
12
+ var babel = require('@babel/core');
13
+
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 commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
35
+ var json__default = /*#__PURE__*/_interopDefault(json);
36
+ var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
37
+ var virtual__default = /*#__PURE__*/_interopDefault(virtual);
38
+ var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
39
+ var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
40
+
41
+ // src/build/analyze.ts
42
+ function isNodeBuiltin(dep) {
43
+ const [pkg] = dep.split("/");
44
+ return dep.startsWith("node:") || module$1.builtinModules.includes(dep) || module$1.builtinModules.includes(pkg);
45
+ }
46
+ function aliasHono() {
47
+ return {
48
+ name: "hono-alias",
49
+ resolveId(id) {
50
+ if (!id.startsWith("@hono/") && !id.startsWith("hono/") && id !== "hono" && id !== "hono-openapi") {
51
+ return;
52
+ }
53
+ const path = undefined(id);
54
+ return url.fileURLToPath(path);
55
+ }
56
+ };
57
+ }
58
+
59
+ // src/build/plugins/pino.ts
60
+ function pino() {
61
+ const workerFiles = [
62
+ {
63
+ id: "thread-stream-worker",
64
+ file: "pino-thread-stream-worker"
65
+ },
66
+ {
67
+ id: "pino-worker",
68
+ file: "pino-worker"
69
+ },
70
+ {
71
+ id: "pino/file",
72
+ file: "pino-file"
73
+ },
74
+ {
75
+ id: "pino-pretty",
76
+ file: "pino-pretty"
77
+ }
78
+ ];
79
+ const fileReferences = /* @__PURE__ */ new Map();
80
+ return {
81
+ name: "rollup-plugin-pino",
82
+ async resolveId(id, importee) {
83
+ if (id === "pino") {
84
+ const resolvedPino = await this.resolve(id, importee);
85
+ if (resolvedPino) {
86
+ await Promise.all(
87
+ workerFiles.map(async (file) => {
88
+ const resolvedEntry = await this.resolve(file.id, resolvedPino.id);
89
+ if (!resolvedEntry) {
90
+ return null;
91
+ }
92
+ const reference = this.emitFile({
93
+ type: "chunk",
94
+ id: resolvedEntry.id,
95
+ name: `${file.file}`
96
+ });
97
+ fileReferences.set(file.id, reference);
98
+ })
99
+ );
100
+ }
101
+ }
102
+ },
103
+ renderChunk(code, chunk) {
104
+ if (chunk.type === "chunk" && chunk.isEntry && fileReferences.size && chunk.name === "index") {
105
+ const importRegex = /^(?:import(?:["'\s]*[\w*${}\n\r\t, ]+from\s*)?["'\s].+[;"'\s]*)$/gm;
106
+ const codeToInject = `globalThis.__bundlerPathsOverrides = {
107
+ ${Array.from(fileReferences.entries()).map(([key, file]) => {
108
+ return '"' + key + '": import.meta.ROLLUP_FILE_URL_' + file;
109
+ }).join(",\n")}
110
+ };`;
111
+ const matches = Array.from(code.matchAll(importRegex));
112
+ if (matches.length > 0) {
113
+ const lastImport = matches[matches.length - 1];
114
+ const lastImportEnd = lastImport.index + lastImport[0].length;
115
+ const newCode = code.slice(0, lastImportEnd) + "\n\n" + codeToInject + "\n\n" + code.slice(lastImportEnd);
116
+ return {
117
+ code: newCode,
118
+ map: null
119
+ };
120
+ }
121
+ return {
122
+ code: `${codeToInject}
123
+
124
+ ${code}`,
125
+ map: null
126
+ };
127
+ }
128
+ }
129
+ };
130
+ }
131
+ function removeDeployer() {
132
+ const t = babel__namespace.default.types;
133
+ let mastraClass = null;
134
+ return {
135
+ name: "remove-deployer",
136
+ visitor: {
137
+ ImportDeclaration(path) {
138
+ if ((path.node.source.value === "@mastra/core" || path.node.source.value === "@mastra/core/mastra") && path.node.specifiers) {
139
+ const mastraObj = path.node.specifiers.find(
140
+ (p) => t.isImportSpecifier(p) && t.isIdentifier(p.imported) && p.imported.name === "Mastra"
141
+ );
142
+ if (mastraObj?.local?.name) {
143
+ mastraClass = mastraObj.local.name;
144
+ }
145
+ }
146
+ },
147
+ NewExpression(path, state) {
148
+ if (mastraClass && t.isIdentifier(path.node.callee) && path.node.callee.name === mastraClass && !state.hasReplaced) {
149
+ state.hasReplaced = true;
150
+ const newMastraObj = t.cloneNode(path.node);
151
+ if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
152
+ newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
153
+ (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name !== "deployer"
154
+ );
155
+ path.replaceWith(newMastraObj);
156
+ }
157
+ }
158
+ }
159
+ }
160
+ };
161
+ }
162
+
163
+ // src/build/plugins/remove-deployer.ts
164
+ function removeDeployer2(mastraEntry) {
165
+ return {
166
+ name: "remove-deployer",
167
+ transform(code, id) {
168
+ if (id !== mastraEntry) {
169
+ return;
170
+ }
171
+ return new Promise((resolve, reject) => {
172
+ babel__namespace.transform(
173
+ code,
174
+ {
175
+ babelrc: false,
176
+ configFile: false,
177
+ filename: id,
178
+ plugins: [removeDeployer]
179
+ },
180
+ (err, result) => {
181
+ if (err) {
182
+ return reject(err);
183
+ }
184
+ resolve({
185
+ code: result.code,
186
+ map: result.map
187
+ });
188
+ }
189
+ );
190
+ });
191
+ }
192
+ };
193
+ }
194
+
195
+ // src/build/analyze.ts
196
+ async function analyze(entry, mastraEntry, isVirtualFile, platform, logger) {
197
+ logger.info("Analyzing dependencies...");
198
+ let virtualPlugin = null;
199
+ if (isVirtualFile) {
200
+ virtualPlugin = virtual__default.default({
201
+ "#entry": entry
202
+ });
203
+ entry = "#entry";
204
+ }
205
+ const optimizerBundler = await rollup.rollup({
206
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
207
+ input: isVirtualFile ? "#entry" : entry,
208
+ treeshake: true,
209
+ preserveSymlinks: true,
210
+ plugins: [
211
+ virtualPlugin,
212
+ {
213
+ name: "custom-alias-resolver",
214
+ resolveId(id) {
215
+ if (id === "#server") {
216
+ return url.fileURLToPath(undefined("@mastra/deployer/server")).replaceAll("\\", "/");
217
+ }
218
+ if (id === "#mastra") {
219
+ return mastraEntry.replaceAll("\\", "/");
220
+ }
221
+ }
222
+ },
223
+ json__default.default(),
224
+ commonjs__default.default({
225
+ strictRequires: "debug",
226
+ ignoreTryCatch: false,
227
+ transformMixedEsModules: true,
228
+ extensions: [".js", ".ts"]
229
+ }),
230
+ esbuild__default.default({
231
+ target: "node20",
232
+ platform,
233
+ minify: false
234
+ }),
235
+ removeDeployer2(mastraEntry),
236
+ esbuild__default.default({
237
+ target: "node20",
238
+ platform,
239
+ minify: false
240
+ })
241
+ ].filter(Boolean)
242
+ });
243
+ const { output } = await optimizerBundler.generate({
244
+ format: "esm",
245
+ inlineDynamicImports: true
246
+ });
247
+ await optimizerBundler.close();
248
+ const depsToOptimize = new Map(Object.entries(output[0].importedBindings));
249
+ for (const dep of depsToOptimize.keys()) {
250
+ if (isNodeBuiltin(dep)) {
251
+ depsToOptimize.delete(dep);
252
+ }
253
+ }
254
+ return depsToOptimize;
255
+ }
256
+ async function bundleExternals(depsToOptimize, outputDir, logger) {
257
+ logger.info("Optimizing dependencies...");
258
+ logger.debug(
259
+ `${Array.from(depsToOptimize.keys()).map((key) => `- ${key}`).join("\n")}`
260
+ );
261
+ const reverseVirtualReferenceMap = /* @__PURE__ */ new Map();
262
+ const virtualDependencies = /* @__PURE__ */ new Map();
263
+ for (const [dep, exports] of depsToOptimize.entries()) {
264
+ const name = dep.replaceAll("/", "-");
265
+ reverseVirtualReferenceMap.set(name, dep);
266
+ const virtualFile = [];
267
+ let exportStringBuilder = [];
268
+ for (const local of exports) {
269
+ if (local === "*") {
270
+ virtualFile.push(`export * from '${dep}';`);
271
+ } else if (local === "default") {
272
+ virtualFile.push(`export * from '${dep}';`);
273
+ } else {
274
+ exportStringBuilder.push(local);
275
+ }
276
+ }
277
+ if (exportStringBuilder.length > 0) {
278
+ virtualFile.push(`export { ${exportStringBuilder.join(", ")} } from '${dep}';`);
279
+ }
280
+ virtualDependencies.set(dep, {
281
+ name,
282
+ virtual: virtualFile.join("\n")
283
+ });
284
+ }
285
+ const bundler = await rollup.rollup({
286
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
287
+ input: Array.from(virtualDependencies.entries()).reduce(
288
+ (acc, [dep, virtualDep]) => {
289
+ acc[virtualDep.name] = `#virtual-${dep}`;
290
+ return acc;
291
+ },
292
+ {}
293
+ ),
294
+ // this dependency breaks the build, so we need to exclude it
295
+ // TODO actually fix this so we don't need to exclude it
296
+ external: ["jsdom"],
297
+ treeshake: "smallest",
298
+ preserveSymlinks: true,
299
+ plugins: [
300
+ virtual__default.default(
301
+ Array.from(virtualDependencies.entries()).reduce(
302
+ (acc, [dep, virtualDep]) => {
303
+ acc[`#virtual-${dep}`] = virtualDep.virtual;
304
+ return acc;
305
+ },
306
+ {}
307
+ )
308
+ ),
309
+ pino(),
310
+ commonjs__default.default({
311
+ strictRequires: "strict",
312
+ transformMixedEsModules: true,
313
+ ignoreTryCatch: false
314
+ }),
315
+ nodeResolve__default.default({
316
+ preferBuiltins: true,
317
+ exportConditions: ["node", "import", "require"],
318
+ mainFields: ["module", "main"]
319
+ }),
320
+ // hono is imported from deployer, so we need to resolve from here instead of the project root
321
+ aliasHono(),
322
+ json__default.default()
323
+ ].filter(Boolean)
324
+ });
325
+ const { output } = await bundler.write({
326
+ format: "esm",
327
+ dir: outputDir,
328
+ entryFileNames: "[name].mjs",
329
+ chunkFileNames: "[name].mjs"
330
+ });
331
+ await bundler.close();
332
+ return { output, reverseVirtualReferenceMap };
333
+ }
334
+ async function validateOutput(output, reverseVirtualReferenceMap, outputDir, logger) {
335
+ const result = {
336
+ invalidChunks: /* @__PURE__ */ new Set(),
337
+ dependencies: /* @__PURE__ */ new Map(),
338
+ externalDependencies: /* @__PURE__ */ new Set()
339
+ };
340
+ for (const file of output) {
341
+ if (file.type === "asset") {
342
+ continue;
343
+ }
344
+ try {
345
+ logger.debug(`Validating if ${file.fileName} is a valid module.`);
346
+ if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
347
+ result.dependencies.set(reverseVirtualReferenceMap.get(file.name), file.fileName);
348
+ }
349
+ await import(`file:${outputDir}/${file.fileName}`);
350
+ } catch (err) {
351
+ result.invalidChunks.add(file.fileName);
352
+ if (file.isEntry && reverseVirtualReferenceMap.has(file.name)) {
353
+ result.externalDependencies.add(reverseVirtualReferenceMap.get(file.name));
354
+ }
355
+ }
356
+ }
357
+ return result;
358
+ }
359
+ async function analyzeBundle(entry, mastraEntry, outputDir, platform, logger) {
360
+ const isVirtualFile = entry.includes("\n") || !fs.existsSync(entry);
361
+ const depsToOptimize = await analyze(entry, mastraEntry, isVirtualFile, platform, logger);
362
+ const { output, reverseVirtualReferenceMap } = await bundleExternals(depsToOptimize, outputDir, logger);
363
+ const result = await validateOutput(output, reverseVirtualReferenceMap, outputDir, logger);
364
+ return result;
365
+ }
366
+
367
+ exports.analyzeBundle = analyzeBundle;
@@ -0,0 +1 @@
1
+ export { analyzeBundle } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1 @@
1
+ export { analyzeBundle } from '../_tsup-dts-rollup.js';
@@ -0,0 +1,2 @@
1
+ export { analyzeBundle } from '../chunk-JMH7HCD6.js';
2
+ import '../chunk-YNXJO2XU.js';