@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,353 @@
1
+ 'use strict';
2
+
3
+ var alias = require('@rollup/plugin-alias');
4
+ var commonjs = require('@rollup/plugin-commonjs');
5
+ var json = require('@rollup/plugin-json');
6
+ var nodeResolve = require('@rollup/plugin-node-resolve');
7
+ var url = require('url');
8
+ var rollup = require('rollup');
9
+ var esbuild = require('rollup-plugin-esbuild');
10
+ var babel = require('@babel/core');
11
+ var load = require('@neon-rs/load');
12
+ var detectLibc = require('detect-libc');
13
+ var path = require('path');
14
+ var fsExtra = require('fs-extra/esm');
15
+ var helperModuleImports = require('@babel/helper-module-imports');
16
+ var process$1 = require('process');
17
+
18
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
+
20
+ function _interopNamespace(e) {
21
+ if (e && e.__esModule) return e;
22
+ var n = Object.create(null);
23
+ if (e) {
24
+ Object.keys(e).forEach(function (k) {
25
+ if (k !== 'default') {
26
+ var d = Object.getOwnPropertyDescriptor(e, k);
27
+ Object.defineProperty(n, k, d.get ? d : {
28
+ enumerable: true,
29
+ get: function () { return e[k]; }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ n.default = e;
35
+ return Object.freeze(n);
36
+ }
37
+
38
+ var alias__default = /*#__PURE__*/_interopDefault(alias);
39
+ var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
40
+ var json__default = /*#__PURE__*/_interopDefault(json);
41
+ var nodeResolve__default = /*#__PURE__*/_interopDefault(nodeResolve);
42
+ var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
43
+ var babel__namespace = /*#__PURE__*/_interopNamespace(babel);
44
+ var fsExtra__default = /*#__PURE__*/_interopDefault(fsExtra);
45
+
46
+ // src/build/bundler.ts
47
+ function rewriteLibsqlImport() {
48
+ const t = babel__namespace.default.types;
49
+ let hasReplaced = false;
50
+ return {
51
+ name: "rewrite-libsql-import",
52
+ visitor: {
53
+ FunctionDeclaration(path) {
54
+ if (path.node.id?.name === "requireNative" && !hasReplaced) {
55
+ hasReplaced = true;
56
+ const createRequire = helperModuleImports.addNamed(path, "createRequire", "module");
57
+ const requireIdentifier = t.identifier("require");
58
+ path.replaceWith(
59
+ t.functionDeclaration(
60
+ t.identifier("requireNative"),
61
+ [],
62
+ t.blockStatement([
63
+ t.variableDeclaration("const", [
64
+ t.variableDeclarator(
65
+ requireIdentifier,
66
+ t.callExpression(createRequire, [
67
+ t.memberExpression(
68
+ t.metaProperty(t.identifier("import"), t.identifier("meta")),
69
+ t.identifier("url")
70
+ )
71
+ ])
72
+ )
73
+ ]),
74
+ t.returnStatement(t.callExpression(requireIdentifier, [t.stringLiteral("./libsql.node")]))
75
+ ])
76
+ )
77
+ );
78
+ }
79
+ }
80
+ }
81
+ };
82
+ }
83
+
84
+ // src/build/plugins/fix-libsql.ts
85
+ function libSqlFix() {
86
+ return {
87
+ name: "libSqlFix",
88
+ transform(code, id) {
89
+ if (!id.includes("\\libsql\\index.js") && !id.includes("/libsql/index.js")) {
90
+ return null;
91
+ }
92
+ return new Promise((resolve2, reject) => {
93
+ babel__namespace.transform(
94
+ code,
95
+ {
96
+ babelrc: false,
97
+ configFile: false,
98
+ filename: id,
99
+ plugins: [rewriteLibsqlImport]
100
+ },
101
+ (err, result) => {
102
+ if (err) {
103
+ return reject(err);
104
+ }
105
+ resolve2({
106
+ code: result.code,
107
+ map: result.map
108
+ });
109
+ }
110
+ );
111
+ });
112
+ },
113
+ async generateBundle({ file, dir }) {
114
+ if (!file && !dir) {
115
+ throw new Error("No output options were given.");
116
+ }
117
+ const outputDirectory = dir || path.dirname(file);
118
+ let target = load.currentTarget();
119
+ if (detectLibc.familySync() == detectLibc.GLIBC) {
120
+ switch (target) {
121
+ case "linux-x64-musl":
122
+ target = "linux-x64-gnu";
123
+ break;
124
+ case "linux-arm64-musl":
125
+ target = "linux-arm64-gnu";
126
+ break;
127
+ }
128
+ }
129
+ const fileToCopy = await this.resolve(`@libsql/${target}/index.node`);
130
+ if (fileToCopy) {
131
+ await fsExtra__default.default.copy(fileToCopy.id, path.join(outputDirectory, "libsql.node"));
132
+ }
133
+ }
134
+ };
135
+ }
136
+ function removeDeployer() {
137
+ const t = babel__namespace.default.types;
138
+ let mastraClass = null;
139
+ return {
140
+ name: "remove-deployer",
141
+ visitor: {
142
+ ImportDeclaration(path) {
143
+ if ((path.node.source.value === "@mastra/core" || path.node.source.value === "@mastra/core/mastra") && path.node.specifiers) {
144
+ const mastraObj = path.node.specifiers.find(
145
+ (p) => t.isImportSpecifier(p) && t.isIdentifier(p.imported) && p.imported.name === "Mastra"
146
+ );
147
+ if (mastraObj?.local?.name) {
148
+ mastraClass = mastraObj.local.name;
149
+ }
150
+ }
151
+ },
152
+ NewExpression(path, state) {
153
+ if (mastraClass && t.isIdentifier(path.node.callee) && path.node.callee.name === mastraClass && !state.hasReplaced) {
154
+ state.hasReplaced = true;
155
+ const newMastraObj = t.cloneNode(path.node);
156
+ if (t.isObjectExpression(newMastraObj.arguments[0]) && newMastraObj.arguments[0].properties?.[0]) {
157
+ newMastraObj.arguments[0].properties = newMastraObj.arguments[0].properties.filter(
158
+ (prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name !== "deployer"
159
+ );
160
+ path.replaceWith(newMastraObj);
161
+ }
162
+ }
163
+ }
164
+ }
165
+ };
166
+ }
167
+
168
+ // src/build/plugins/remove-deployer.ts
169
+ function removeDeployer2(mastraEntry) {
170
+ return {
171
+ name: "remove-deployer",
172
+ transform(code, id) {
173
+ if (id !== mastraEntry) {
174
+ return;
175
+ }
176
+ return new Promise((resolve2, reject) => {
177
+ babel__namespace.transform(
178
+ code,
179
+ {
180
+ babelrc: false,
181
+ configFile: false,
182
+ filename: id,
183
+ plugins: [removeDeployer]
184
+ },
185
+ (err, result) => {
186
+ if (err) {
187
+ return reject(err);
188
+ }
189
+ resolve2({
190
+ code: result.code,
191
+ map: result.map
192
+ });
193
+ }
194
+ );
195
+ });
196
+ }
197
+ };
198
+ }
199
+ function getTelemetryMachineFile() {
200
+ switch (process$1.platform) {
201
+ case "darwin":
202
+ return "getMachineId-darwin";
203
+ case "linux":
204
+ return "getMachineId-linux";
205
+ case "freebsd":
206
+ return "getMachineId-bsd";
207
+ case "win32":
208
+ return "getMachineId-win";
209
+ default:
210
+ return "getMachineId-unsupported";
211
+ }
212
+ }
213
+ function telemetryFix() {
214
+ return {
215
+ name: "telemetry-fix",
216
+ transform(code, id) {
217
+ if (id.includes("require-in-the-middle")) {
218
+ return code.replace(
219
+ `const path = require('path')`,
220
+ `const path = require('path');
221
+ const { createRequire } = require('module');
222
+ const realRequire = createRequire(import.meta.url)`
223
+ ).replaceAll(`require.resolve`, `realRequire.resolve`);
224
+ }
225
+ },
226
+ resolveId(id, importer) {
227
+ if (id === "./machine-id/getMachineId" && importer) {
228
+ return { id: path.resolve(path.dirname(importer), `./machine-id/${getTelemetryMachineFile()}.js`) };
229
+ }
230
+ if (id === "formdata-node") {
231
+ return { id: "formdata-node", external: false };
232
+ }
233
+ },
234
+ load(id) {
235
+ if (id.startsWith("formdata-node")) {
236
+ return "export default {};";
237
+ }
238
+ return null;
239
+ }
240
+ };
241
+ }
242
+
243
+ // src/build/bundler.ts
244
+ async function getInputOptions(entryFile, analyzedBundleInfo, platform2) {
245
+ let nodeResolvePlugin = platform2 === "node" ? nodeResolve__default.default({
246
+ preferBuiltins: true,
247
+ exportConditions: ["node", "import", "require"],
248
+ mainFields: ["module", "main"]
249
+ }) : nodeResolve__default.default({
250
+ preferBuiltins: false,
251
+ exportConditions: ["browser", "import", "require"],
252
+ mainFields: ["module", "main"],
253
+ browser: true
254
+ });
255
+ const externals = Array.from(analyzedBundleInfo.externalDependencies).concat(["@mastra/core/hooks"]);
256
+ return {
257
+ logLevel: process.env.MASTRA_BUNDLER_DEBUG === "true" ? "debug" : "silent",
258
+ treeshake: true,
259
+ preserveSymlinks: true,
260
+ external: externals,
261
+ plugins: [
262
+ telemetryFix(),
263
+ libSqlFix(),
264
+ {
265
+ name: "alias-optimized-deps",
266
+ // @ts-ignore
267
+ resolveId(id) {
268
+ if (!analyzedBundleInfo.dependencies.has(id)) {
269
+ return null;
270
+ }
271
+ const isInvalidChunk = analyzedBundleInfo.invalidChunks.has(analyzedBundleInfo.dependencies.get(id));
272
+ if (isInvalidChunk) {
273
+ return {
274
+ id,
275
+ external: true
276
+ };
277
+ }
278
+ return {
279
+ id: ".mastra/.build/" + analyzedBundleInfo.dependencies.get(id),
280
+ external: false
281
+ };
282
+ }
283
+ },
284
+ alias__default.default({
285
+ entries: [
286
+ {
287
+ find: /^\#server$/,
288
+ replacement: url.fileURLToPath(undefined("@mastra/deployer/server")).replaceAll("\\", "/")
289
+ },
290
+ { find: /^\#mastra$/, replacement: entryFile.replaceAll("\\", "/") }
291
+ ]
292
+ }),
293
+ esbuild__default.default({
294
+ target: "node20",
295
+ platform: platform2,
296
+ minify: false,
297
+ define: {
298
+ "process.env.NODE_ENV": JSON.stringify("production")
299
+ }
300
+ }),
301
+ commonjs__default.default({
302
+ extensions: [".js", ".ts"],
303
+ transformMixedEsModules: true,
304
+ esmExternals(id) {
305
+ return externals.includes(id);
306
+ }
307
+ }),
308
+ nodeResolvePlugin,
309
+ // for debugging
310
+ // {
311
+ // name: 'logger',
312
+ // //@ts-ignore
313
+ // resolveId(id, ...args) {
314
+ // console.log({ id, args });
315
+ // },
316
+ // // @ts-ignore
317
+ // transform(code, id) {
318
+ // if (code.includes('class Duplexify ')) {
319
+ // console.log({ duplex: id });
320
+ // }
321
+ // },
322
+ // },
323
+ json__default.default(),
324
+ removeDeployer2(entryFile),
325
+ // treeshake unused imports
326
+ esbuild__default.default({
327
+ include: entryFile,
328
+ target: "node20",
329
+ platform: platform2,
330
+ minify: false
331
+ })
332
+ ].filter(Boolean)
333
+ };
334
+ }
335
+ async function createBundler(inputOptions, outputOptions) {
336
+ const bundler = await rollup.rollup(inputOptions);
337
+ return {
338
+ write: () => {
339
+ return bundler.write({
340
+ ...outputOptions,
341
+ format: "esm",
342
+ entryFileNames: "[name].mjs",
343
+ chunkFileNames: "[name].mjs"
344
+ });
345
+ },
346
+ close: () => {
347
+ return bundler.close();
348
+ }
349
+ };
350
+ }
351
+
352
+ exports.createBundler = createBundler;
353
+ exports.getInputOptions = getInputOptions;
@@ -0,0 +1,2 @@
1
+ export { getInputOptions } from '../_tsup-dts-rollup.cjs';
2
+ export { createBundler } from '../_tsup-dts-rollup.cjs';
@@ -0,0 +1,2 @@
1
+ export { getInputOptions } from '../_tsup-dts-rollup.js';
2
+ export { createBundler } from '../_tsup-dts-rollup.js';
@@ -0,0 +1,2 @@
1
+ export { createBundler, getInputOptions } from '../chunk-DTSFVNIF.js';
2
+ import '../chunk-YNXJO2XU.js';