mastra 0.1.57-alpha.95 → 0.1.57-alpha.96

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.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/commands/create/utils.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,mBAAmB;;EA6D/B,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/commands/create/utils.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,mBAAmB;;EA8D/B,CAAC"}
@@ -51,6 +51,7 @@ export const createMastraProject = async () => {
51
51
  await exec(`echo output.txt >> .gitignore`);
52
52
  await exec(`echo node_modules >> .gitignore`);
53
53
  await exec(`echo dist >> .gitignore`);
54
+ await exec(`echo .mastra >> .gitignore`);
54
55
  s.stop('.gitignore added');
55
56
  p.outro('Project created successfully');
56
57
  logger.break();
@@ -1 +1 @@
1
- {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAqGA,wBAAsB,GAAG,CAAC,EACxB,IAAI,EACJ,GAAG,EACH,GAAG,EACH,SAAS,GACV,EAAE;IACD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,iBA4HA"}
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AA0KA,wBAAsB,GAAG,CAAC,EACxB,IAAI,EACJ,GAAG,EACH,GAAG,EACH,SAAS,GACV,EAAE;IACD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,iBAkEA"}
@@ -13,19 +13,11 @@ import { EXPRESS_SERVER } from './deploy/server.js';
13
13
  const __filename = fileURLToPath(import.meta.url);
14
14
  const __dirname = path.dirname(__filename);
15
15
  let currentServerProcess;
16
- async function rebundleAndRestart(dirPath, dotMastraPath, port, toolsDirs) {
17
- if (currentServerProcess) {
18
- console.log('Stopping current server...');
19
- currentServerProcess.kill();
20
- await new Promise(resolve => setTimeout(resolve, 1000));
21
- }
22
- /*
23
- Bundle mastra
24
- */
16
+ let isRestarting = false;
17
+ const bundleMastra = async (dirPath) => {
25
18
  await bundle(dirPath, { buildName: 'Mastra' });
26
- /*
27
- Bundle tools
28
- */
19
+ };
20
+ const bundleTools = async (dirPath, dotMastraPath, toolsDirs) => {
29
21
  const defaultToolsPath = path.join(dirPath, 'tools');
30
22
  const toolsPaths = [...(toolsDirs?.split(',').map(tool => path.join(process.cwd(), tool)) || []), defaultToolsPath];
31
23
  const toolPathsWithFileNames = (await Promise.all(toolsPaths.map(async (toolPath) => {
@@ -60,8 +52,12 @@ async function rebundleAndRestart(dirPath, dotMastraPath, port, toolsDirs) {
60
52
  const MASTRA_TOOLS_PATH = toolPathsWithFileNames?.length
61
53
  ? toolPathsWithFileNames.map(tool => path.join(dotMastraPath, 'tools', `${tool.name}.mjs`)).join(',')
62
54
  : undefined;
55
+ return MASTRA_TOOLS_PATH;
56
+ };
57
+ const startServer = async (dotMastraPath, port, MASTRA_TOOLS_PATH) => {
63
58
  try {
64
- console.log('Restarting server...');
59
+ // Restart server
60
+ console.log('Starting server...');
65
61
  currentServerProcess = execa('node', ['server.mjs'], {
66
62
  cwd: dotMastraPath,
67
63
  env: {
@@ -71,8 +67,34 @@ async function rebundleAndRestart(dirPath, dotMastraPath, port, toolsDirs) {
71
67
  stdio: 'inherit',
72
68
  reject: false,
73
69
  });
74
- if (currentServerProcess.failed) {
75
- console.error('Server failed to restart with error:', currentServerProcess.stderr);
70
+ // Wait for server to be ready
71
+ await new Promise(resolve => setTimeout(resolve, 1000));
72
+ // Send refresh signal
73
+ try {
74
+ await fetch(`http://localhost:${port}/__refresh`, {
75
+ method: 'POST',
76
+ headers: {
77
+ 'Content-Type': 'application/json',
78
+ },
79
+ });
80
+ }
81
+ catch (err) {
82
+ // Retry after another second
83
+ await new Promise(resolve => setTimeout(resolve, 1500));
84
+ try {
85
+ await fetch(`http://localhost:${port}/__refresh`, {
86
+ method: 'POST',
87
+ headers: {
88
+ 'Content-Type': 'application/json',
89
+ },
90
+ });
91
+ }
92
+ catch (retryErr) {
93
+ // Ignore retry errors
94
+ }
95
+ }
96
+ if (currentServerProcess.exitCode !== null) {
97
+ console.error('Server failed to start with error:', currentServerProcess.stderr);
76
98
  return;
77
99
  }
78
100
  }
@@ -83,12 +105,48 @@ async function rebundleAndRestart(dirPath, dotMastraPath, port, toolsDirs) {
83
105
  if (execaError.stdout)
84
106
  console.error('Server output:', execaError.stdout);
85
107
  }
108
+ };
109
+ async function rebundleAndRestart(dirPath, dotMastraPath, port, envFile, toolsDirs) {
110
+ if (isRestarting) {
111
+ return;
112
+ }
113
+ isRestarting = true;
114
+ try {
115
+ // If current server process is running, stop it
116
+ if (currentServerProcess) {
117
+ console.log('Stopping current server...');
118
+ currentServerProcess.kill();
119
+ await new Promise(resolve => setTimeout(resolve, 1000));
120
+ }
121
+ config({ path: envFile });
122
+ /*
123
+ Bundle mastra
124
+ */
125
+ await bundleMastra(dirPath);
126
+ /*
127
+ Bundle tools
128
+ */
129
+ const MASTRA_TOOLS_PATH = await bundleTools(dirPath, dotMastraPath, toolsDirs);
130
+ /*
131
+ Bundle server
132
+ */
133
+ writeFileSync(join(dotMastraPath, 'index.mjs'), EXPRESS_SERVER);
134
+ await bundleServer(join(dotMastraPath, 'index.mjs'));
135
+ /*
136
+ Start server
137
+ */
138
+ await startServer(dotMastraPath, port, MASTRA_TOOLS_PATH);
139
+ }
140
+ finally {
141
+ isRestarting = false;
142
+ }
86
143
  }
87
144
  export async function dev({ port, env, dir, toolsDirs, }) {
88
145
  const dotMastraPath = join(process.cwd(), '.mastra');
89
146
  const playgroundServePath = join(dotMastraPath, 'playground');
90
147
  const key = env[0]?.name;
91
148
  const value = env[0]?.value;
149
+ let envFile = '';
92
150
  /*
93
151
  Copy playground dist files
94
152
  */
@@ -100,7 +158,7 @@ export async function dev({ port, env, dir, toolsDirs, }) {
100
158
  */
101
159
  try {
102
160
  const fileService = new FileService();
103
- const envFile = fileService.getFirstExistingFile(['.env.development', '.env']);
161
+ envFile = fileService.getFirstExistingFile(['.env.development', '.env']);
104
162
  config({ path: envFile });
105
163
  }
106
164
  catch (err) {
@@ -112,86 +170,32 @@ export async function dev({ port, env, dir, toolsDirs, }) {
112
170
  Bundle mastra
113
171
  */
114
172
  const dirPath = dir || path.join(process.cwd(), 'src/mastra');
115
- await bundle(dirPath, { buildName: 'Mastra' });
173
+ const envPaths = [path.join(process.cwd(), '.env'), path.join(process.cwd(), '.env.development')];
174
+ await bundleMastra(dirPath);
116
175
  /*
117
176
  Bundle tools
118
177
  */
119
- const defaultToolsPath = path.join(dirPath, 'tools');
120
- const toolsPaths = [...(toolsDirs?.split(',').map(tool => path.join(process.cwd(), tool)) || []), defaultToolsPath];
121
- const toolPathsWithFileNames = (await Promise.all(toolsPaths.map(async (toolPath) => {
122
- try {
123
- const files = await fs.readdir(toolPath);
124
- return files.map(file => {
125
- const fullPath = path.join(toolPath, file);
126
- const fileName = path.parse(file).name;
127
- const name = fileName === 'index' ? path.basename(path.dirname(fullPath)) : fileName;
128
- return {
129
- path: toolPath,
130
- name,
131
- fileName,
132
- };
133
- });
134
- }
135
- catch (err) {
136
- if (toolPath === defaultToolsPath) {
137
- return [];
138
- }
139
- console.warn(`Error reading tools directory ${toolPath}:`, err);
140
- return [];
141
- }
142
- }))).flat();
143
- for (const { path, name, fileName } of toolPathsWithFileNames) {
144
- await bundle(path, {
145
- outfile: join(dotMastraPath, 'tools', `${name}.mjs`),
146
- entryFile: fileName,
147
- buildName: `${name}`,
148
- });
149
- }
178
+ const MASTRA_TOOLS_PATH = await bundleTools(dirPath, dotMastraPath, toolsDirs);
150
179
  /*
151
180
  Bundle server
152
181
  */
153
182
  writeFileSync(join(dotMastraPath, 'index.mjs'), EXPRESS_SERVER);
154
183
  await bundleServer(join(dotMastraPath, 'index.mjs'));
155
- const MASTRA_TOOLS_PATH = toolPathsWithFileNames?.length
156
- ? toolPathsWithFileNames.map(tool => path.join(dotMastraPath, 'tools', `${tool.name}.mjs`)).join(',')
157
- : undefined;
158
- try {
159
- console.log('Starting server...');
160
- currentServerProcess = execa('node', ['server.mjs'], {
161
- cwd: dotMastraPath,
162
- env: {
163
- PORT: port.toString() || '4111',
164
- MASTRA_TOOLS_PATH,
165
- },
166
- stdio: 'inherit',
167
- reject: false,
168
- });
169
- if (currentServerProcess.failed) {
170
- console.error('Server failed to start with error:', currentServerProcess.stderr);
171
- process.exit(1);
184
+ await startServer(dotMastraPath, port, MASTRA_TOOLS_PATH);
185
+ const watcher = watch([dirPath, ...envPaths], {
186
+ persistent: true,
187
+ ignoreInitial: true,
188
+ });
189
+ watcher.on('change', async () => {
190
+ console.log(`Changes detected, rebundling and restarting server...`);
191
+ await rebundleAndRestart(dirPath, dotMastraPath, port, envFile, toolsDirs);
192
+ });
193
+ process.on('SIGINT', () => {
194
+ console.log('Stopping server...');
195
+ if (currentServerProcess) {
196
+ currentServerProcess.kill();
172
197
  }
173
- const watcher = watch(dirPath, {
174
- persistent: true,
175
- });
176
- watcher.on('change', async () => {
177
- console.log(`Changes detected`);
178
- await rebundleAndRestart(dirPath, dotMastraPath, port, toolsDirs);
179
- });
180
- process.on('SIGINT', () => {
181
- console.log('Stopping server...');
182
- if (currentServerProcess) {
183
- currentServerProcess.kill();
184
- }
185
- watcher.close();
186
- process.exit(0);
187
- });
188
- }
189
- catch (err) {
190
- const execaError = err;
191
- if (execaError.stderr)
192
- console.error('Server error output:', execaError.stderr);
193
- if (execaError.stdout)
194
- console.error('Server output:', execaError.stdout);
195
- process.exit(1);
196
- }
198
+ watcher.close();
199
+ process.exit(0);
200
+ });
197
201
  }
@@ -1 +1 @@
1
- {"version":3,"file":"express-server.d.ts","sourceRoot":"","sources":["../../src/templates/express-server.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAmhCzC,eAAO,MAAM,OAAO,oBAAkB,CAAC;AAQvC,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"express-server.d.ts","sourceRoot":"","sources":["../../src/templates/express-server.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAsjCzC,eAAO,MAAM,OAAO,oBAAkB,CAAC;AAQvC,eAAe,OAAO,CAAC"}
@@ -24,6 +24,36 @@ const tools = toolImports.reduce((acc, toolModule) => {
24
24
  }, {});
25
25
  const app = express();
26
26
  app.use(express.json());
27
+ // Store connected SSE clients
28
+ let clients = [];
29
+ // SSE endpoint for refresh notifications
30
+ app.get('/refresh-events', (req, res) => {
31
+ res.setHeader('Content-Type', 'text/event-stream');
32
+ res.setHeader('Cache-Control', 'no-cache');
33
+ res.setHeader('Connection', 'keep-alive');
34
+ res.setHeader('Access-Control-Allow-Origin', '*');
35
+ // Send initial connection message
36
+ res.write('data: connected\n\n');
37
+ // Add client to list
38
+ clients.push(res);
39
+ // Remove client when connection closes
40
+ req.on('close', () => {
41
+ clients = clients.filter(client => client !== res);
42
+ });
43
+ });
44
+ // Trigger refresh for all clients
45
+ app.post('/__refresh', (_req, res) => {
46
+ clients.forEach(client => {
47
+ try {
48
+ client.write('data: refresh\n\n');
49
+ }
50
+ catch (err) {
51
+ // Remove failed clients
52
+ clients = clients.filter(c => c !== client);
53
+ }
54
+ });
55
+ res.sendStatus(200);
56
+ });
27
57
  // Swagger configuration
28
58
  const options = {
29
59
  info: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastra",
3
- "version": "0.1.57-alpha.95",
3
+ "version": "0.1.57-alpha.96",
4
4
  "license": "MIT",
5
5
  "description": "cli for mastra",
6
6
  "type": "module",
@@ -24,73 +24,34 @@
24
24
  "dependencies": {
25
25
  "@clack/prompts": "^0.8.2",
26
26
  "@dagrejs/dagre": "^1.1.4",
27
- "@hookform/resolvers": "^3.9.0",
28
- "@radix-ui/react-alert-dialog": "^1.1.2",
29
- "@radix-ui/react-checkbox": "^1.1.1",
30
- "@radix-ui/react-collapsible": "^1.1.0",
31
- "@radix-ui/react-dialog": "^1.1.3",
32
- "@radix-ui/react-dropdown-menu": "^2.1.1",
33
- "@radix-ui/react-form": "^0.1.1",
34
- "@radix-ui/react-label": "^2.1.0",
35
- "@radix-ui/react-popover": "^1.1.1",
36
- "@radix-ui/react-radio-group": "^1.2.1",
37
- "@radix-ui/react-scroll-area": "^1.2.2",
38
- "@radix-ui/react-select": "^2.1.3",
39
- "@radix-ui/react-slot": "^1.1.0",
40
- "@radix-ui/react-switch": "^1.1.2",
41
- "@radix-ui/react-tabs": "^1.1.2",
42
- "@radix-ui/react-tooltip": "^1.1.2",
43
27
  "@swc/core": "^1.9.3",
44
- "@tanstack/react-virtual": "^3.10.4",
45
28
  "@types/figlet": "^1.7.0",
46
- "@xyflow/react": "^12.3.6",
47
29
  "chokidar": "^4.0.3",
48
- "class-variance-authority": "^0.7.1",
49
- "clsx": "^2.1.1",
50
- "cmdk": "^1.0.0",
51
30
  "commander": "^12.1.0",
52
31
  "cosmiconfig": "^9.0.0",
53
- "date-fns": "^4.1.0",
54
32
  "dotenv": "^16.3.1",
55
33
  "esbuild": "^0.24.0",
56
34
  "execa": "^9.3.1",
57
35
  "express": "^4.21.1",
58
36
  "express-jsdoc-swagger": "^1.8.0",
59
37
  "figlet": "^1.8.0",
60
- "framer-motion": "^11.13.5",
61
38
  "fs-extra": "^11.2.0",
62
39
  "is-port-reachable": "^4.0.0",
63
40
  "itty-router": "^5.0.18",
64
41
  "json-schema-to-zod": "^2.5.0",
65
- "lucide-react": "^0.468.0",
66
42
  "memfs": "^4.14.0",
67
- "next-themes": "^0.4.4",
68
43
  "picocolors": "^1.1.1",
69
44
  "posthog-node": "^4.3.1",
70
45
  "prettier": "^3.3.3",
71
- "prism-react-renderer": "^2.4.0",
72
46
  "prompt": "^1.3.0",
73
- "react": "^18.3.1",
74
- "react-code-block": "^1.0.0",
75
- "react-day-picker": "^9.0.8",
76
- "react-dom": "^18.3.1",
77
- "react-hook-form": "^7.53.0",
78
- "react-markdown": "^9.0.1",
79
- "react-router": "^7.0.2",
80
- "remark-gfm": "^4.0.0",
81
- "remeda": "^2.17.4",
82
47
  "serverless-http": "^3.1.1",
83
48
  "shiki": "^1.24.2",
84
- "sonner": "^1.7.1",
85
49
  "superjson": "^2.2.2",
86
50
  "swr": "^2.2.5",
87
- "tailwind-merge": "^2.5.5",
88
- "tailwindcss-animate": "^1.0.7",
89
51
  "tcp-port-used": "^1.0.2",
90
52
  "tsconfig-paths": "^4.2.0",
91
53
  "type-fest": "^4.30.0",
92
54
  "typescript": "^5.5.4",
93
- "use-debounce": "^10.0.3",
94
55
  "yocto-spinner": "^0.1.1",
95
56
  "zod": "^3.24.1",
96
57
  "zod-to-json-schema": "^3.24.1",
@@ -101,17 +62,8 @@
101
62
  "@types/fs-extra": "^11.0.4",
102
63
  "@types/node": "^22.10.0",
103
64
  "@types/prompt": "^1.1.8",
104
- "@types/react": "^18",
105
- "@types/react-dom": "^18",
106
65
  "@types/tcp-port-used": "^1.0.4",
107
- "@vitejs/plugin-react": "^4.3.4",
108
- "autoprefixer": "^10.4.20",
109
66
  "cpy-cli": "^5.0.0",
110
- "eslint-plugin-react-hooks": "^5.0.0",
111
- "eslint-plugin-react-refresh": "^0.4.14",
112
- "postcss": "^8.4.49",
113
- "tailwindcss": "^3.4.16",
114
- "vite": "^6.0.3",
115
67
  "vitest": "^2.1.8"
116
68
  },
117
69
  "scripts": {
@@ -119,8 +71,8 @@
119
71
  "build:tsc": "tsc",
120
72
  "build:dev": "npx tsc --watch",
121
73
  "copy-starter-files": "cpy 'src/starter-files/**/*' dist/starter-files",
122
- "build:playground": "cd src/playground && vite build",
123
- "dev:playground": "cd src/playground && vite",
74
+ "build:playground": "cd src/playground && pnpm build",
75
+ "dev:playground": "cd src/playground && pnpm dev",
124
76
  "init": "npx tsx src/index.ts init",
125
77
  "dev": "npx tsx src/index.ts dev",
126
78
  "test": "vitest run",