mastra 0.1.57-unstable.56 → 0.1.57-unstable.88

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 (94) hide show
  1. package/dist/commands/create/create.d.ts +8 -0
  2. package/dist/commands/create/create.d.ts.map +1 -0
  3. package/dist/commands/create/create.js +35 -0
  4. package/dist/commands/create/utils.d.ts +4 -0
  5. package/dist/commands/create/utils.d.ts.map +1 -0
  6. package/dist/commands/create/utils.js +58 -0
  7. package/dist/commands/deploy/cloudflare/index.d.ts.map +1 -1
  8. package/dist/commands/deploy/cloudflare/index.js +2 -0
  9. package/dist/commands/deploy/deployer.d.ts +4 -2
  10. package/dist/commands/deploy/deployer.d.ts.map +1 -1
  11. package/dist/commands/deploy/deployer.js +4 -4
  12. package/dist/commands/deploy/index.d.ts +2 -1
  13. package/dist/commands/deploy/index.d.ts.map +1 -1
  14. package/dist/commands/deploy/index.js +2 -2
  15. package/dist/commands/deploy/netlify/index.d.ts.map +1 -1
  16. package/dist/commands/deploy/netlify/index.js +2 -0
  17. package/dist/commands/deploy/vercel/index.d.ts +2 -1
  18. package/dist/commands/deploy/vercel/index.d.ts.map +1 -1
  19. package/dist/commands/deploy/vercel/index.js +4 -1
  20. package/dist/commands/dev.d.ts +1 -7
  21. package/dist/commands/dev.d.ts.map +1 -1
  22. package/dist/commands/dev.js +117 -12
  23. package/dist/commands/engine/down.d.ts +1 -1
  24. package/dist/commands/engine/down.d.ts.map +1 -1
  25. package/dist/commands/engine/down.js +3 -2
  26. package/dist/commands/engine/up.d.ts +1 -1
  27. package/dist/commands/engine/up.d.ts.map +1 -1
  28. package/dist/commands/engine/up.js +3 -2
  29. package/dist/commands/init/init.d.ts +2 -2
  30. package/dist/commands/init/init.d.ts.map +1 -1
  31. package/dist/commands/init/init.js +33 -9
  32. package/dist/commands/init/utils.d.ts +21 -9
  33. package/dist/commands/init/utils.d.ts.map +1 -1
  34. package/dist/commands/init/utils.js +64 -74
  35. package/dist/index.d.ts +2 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +57 -57
  38. package/dist/services/service.deps.d.ts +1 -0
  39. package/dist/services/service.deps.d.ts.map +1 -1
  40. package/dist/services/service.deps.js +8 -0
  41. package/dist/services/service.docker.d.ts +1 -0
  42. package/dist/services/service.docker.d.ts.map +1 -1
  43. package/dist/services/service.docker.js +20 -0
  44. package/dist/src/starter-files/config.ts +28 -0
  45. package/dist/src/starter-files/mastra-pg.docker-compose.yaml +15 -0
  46. package/dist/src/starter-files/tools.ts +95 -0
  47. package/dist/src/starter-files/workflow.ts +173 -0
  48. package/dist/templates/express-server.d.ts.map +1 -1
  49. package/dist/templates/express-server.js +70 -43
  50. package/dist/templates/netlify.d.ts.map +1 -1
  51. package/dist/templates/netlify.js +199 -34
  52. package/dist/templates/worker.d.ts.map +1 -1
  53. package/dist/templates/worker.js +255 -35
  54. package/dist/utils/bundle.d.ts +4 -1
  55. package/dist/utils/bundle.d.ts.map +1 -1
  56. package/dist/utils/bundle.js +28 -13
  57. package/package.json +7 -3
  58. package/src/playground/dist/assets/dark-plus-C3mMm8J8.js +1 -0
  59. package/src/playground/dist/assets/erb-BgreK6rt.js +1 -0
  60. package/src/playground/dist/assets/{gdresource-D_y5yz_M.js → gdresource-NFcQ0Q3Z.js} +1 -1
  61. package/src/playground/dist/assets/gdscript-BVlVXSjx.js +1 -0
  62. package/src/playground/dist/assets/{hcl-Cztwc-HH.js → hcl-_Zu0RE-q.js} +1 -1
  63. package/src/playground/dist/assets/index-BiEU7Tmg.js +389 -0
  64. package/src/playground/dist/assets/index-Cke4BidO.js +13 -0
  65. package/src/playground/dist/assets/light-plus-B7mTdjB0.js +1 -0
  66. package/src/playground/dist/assets/{monokai-CQWsIgnU.js → monokai-D4h5O-jR.js} +1 -1
  67. package/src/playground/dist/assets/prisma-CZzQMiei.js +1 -0
  68. package/src/playground/dist/assets/red-bN70gL4F.js +1 -0
  69. package/src/playground/dist/assets/rst-BCmapc_q.js +1 -0
  70. package/src/playground/dist/assets/ruby-DsC6krmi.js +1 -0
  71. package/src/playground/dist/assets/{solarized-dark-CmY0Y6Yh.js → solarized-dark-DXbdFlpD.js} +1 -1
  72. package/src/playground/dist/assets/{solarized-light-DZQMDcrx.js → solarized-light-L9t79GZl.js} +1 -1
  73. package/src/playground/dist/assets/style-7CS44jOg.css +1 -0
  74. package/src/playground/dist/assets/twig-CvAdjvFj.js +1 -0
  75. package/src/playground/dist/assets/{vue-html-x3hEOujm.js → vue-html-59TQSa_j.js} +1 -1
  76. package/src/playground/dist/assets/vue-srE0XGv_.js +1 -0
  77. package/src/playground/dist/index.html +2 -2
  78. package/src/starter-files/tools.ts +88 -14
  79. package/src/starter-files/workflow.ts +160 -21
  80. package/src/playground/dist/assets/dark-plus-B74Y8nHz.js +0 -1
  81. package/src/playground/dist/assets/erb-DuefeV9w.js +0 -1
  82. package/src/playground/dist/assets/gdscript-BIguuW30.js +0 -1
  83. package/src/playground/dist/assets/index-CzqDlQul.js +0 -13
  84. package/src/playground/dist/assets/index-qFy09kRJ.js +0 -360
  85. package/src/playground/dist/assets/light-plus-w1el_4yc.js +0 -1
  86. package/src/playground/dist/assets/prisma-DFIOpqzz.js +0 -1
  87. package/src/playground/dist/assets/red-2pWuV6-S.js +0 -1
  88. package/src/playground/dist/assets/rst-BtGMdPX_.js +0 -1
  89. package/src/playground/dist/assets/ruby-C8Yez0Ov.js +0 -1
  90. package/src/playground/dist/assets/style-x_8NJ6Q9.css +0 -1
  91. package/src/playground/dist/assets/twig-DN6YEzOP.js +0 -1
  92. package/src/playground/dist/assets/vue-xldAUJov.js +0 -1
  93. package/src/starter-files/api.ts +0 -11
  94. package/src/starter-files/framework-utils.ts +0 -33
@@ -0,0 +1,95 @@
1
+ import { createTool } from '@mastra/core';
2
+ import { z } from 'zod';
3
+
4
+ interface WeatherResponse {
5
+ current: {
6
+ time: string;
7
+ temperature_2m: number;
8
+ apparent_temperature: number;
9
+ relative_humidity_2m: number;
10
+ wind_speed_10m: number;
11
+ wind_gusts_10m: number;
12
+ weather_code: number;
13
+ };
14
+ }
15
+
16
+ export const weatherTool = createTool({
17
+ id: 'get-weather',
18
+ description: 'Get current weather for a location',
19
+ inputSchema: z.object({
20
+ location: z.string().describe('City name'),
21
+ }),
22
+ outputSchema: z.object({
23
+ temperature: z.number(),
24
+ feelsLike: z.number(),
25
+ humidity: z.number(),
26
+ windSpeed: z.number(),
27
+ windGust: z.number(),
28
+ conditions: z.string(),
29
+ location: z.string(),
30
+ }),
31
+ execute: async ({ context }) => {
32
+ return await getWeather(context.location);
33
+ },
34
+ });
35
+
36
+ const getWeather = async (location: string) => {
37
+ const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
38
+ const geocodingResponse = await fetch(geocodingUrl);
39
+ const geocodingData = await geocodingResponse.json();
40
+
41
+ if (!geocodingData.results?.[0]) {
42
+ throw new Error(`Location '${location}' not found`);
43
+ }
44
+
45
+ const { latitude, longitude, name } = geocodingData.results[0];
46
+
47
+ const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,wind_gusts_10m,weather_code`;
48
+
49
+ const response = await fetch(weatherUrl);
50
+ const data: WeatherResponse = await response.json();
51
+
52
+ return {
53
+ temperature: data.current.temperature_2m,
54
+ feelsLike: data.current.apparent_temperature,
55
+ humidity: data.current.relative_humidity_2m,
56
+ windSpeed: data.current.wind_speed_10m,
57
+ windGust: data.current.wind_gusts_10m,
58
+ conditions: getWeatherCondition(data.current.weather_code),
59
+ location: name,
60
+ };
61
+ };
62
+
63
+ function getWeatherCondition(code: number): string {
64
+ const conditions: Record<number, string> = {
65
+ 0: 'Clear sky',
66
+ 1: 'Mainly clear',
67
+ 2: 'Partly cloudy',
68
+ 3: 'Overcast',
69
+ 45: 'Foggy',
70
+ 48: 'Depositing rime fog',
71
+ 51: 'Light drizzle',
72
+ 53: 'Moderate drizzle',
73
+ 55: 'Dense drizzle',
74
+ 56: 'Light freezing drizzle',
75
+ 57: 'Dense freezing drizzle',
76
+ 61: 'Slight rain',
77
+ 63: 'Moderate rain',
78
+ 65: 'Heavy rain',
79
+ 66: 'Light freezing rain',
80
+ 67: 'Heavy freezing rain',
81
+ 71: 'Slight snow fall',
82
+ 73: 'Moderate snow fall',
83
+ 75: 'Heavy snow fall',
84
+ 77: 'Snow grains',
85
+ 80: 'Slight rain showers',
86
+ 81: 'Moderate rain showers',
87
+ 82: 'Violent rain showers',
88
+ 85: 'Slight snow showers',
89
+ 86: 'Heavy snow showers',
90
+ 95: 'Thunderstorm',
91
+ 96: 'Thunderstorm with slight hail',
92
+ 99: 'Thunderstorm with heavy hail',
93
+ };
94
+ return conditions[code] || 'Unknown';
95
+ }
@@ -0,0 +1,173 @@
1
+ import { Step, Workflow } from '@mastra/core';
2
+ import { z } from 'zod';
3
+
4
+ const fetchWeather = new Step({
5
+ id: 'fetch-weather',
6
+ description: 'Fetches weather forecast for a given city',
7
+ inputSchema: z.object({
8
+ city: z.string().describe('The city to get the weather for'),
9
+ }),
10
+ execute: async ({ context }) => {
11
+ const triggerData = context.machineContext?.getStepPayload<{ city: string }>('trigger');
12
+
13
+ if (!triggerData) {
14
+ throw new Error('Trigger data not found');
15
+ }
16
+
17
+ const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(triggerData.city)}&count=1`;
18
+ const geocodingResponse = await fetch(geocodingUrl);
19
+ const geocodingData = await geocodingResponse.json();
20
+
21
+ if (!geocodingData.results?.[0]) {
22
+ throw new Error(`Location '${triggerData.city}' not found`);
23
+ }
24
+
25
+ const { latitude, longitude, name } = geocodingData.results[0];
26
+
27
+ const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=temperature_2m_max,temperature_2m_min,precipitation_probability_mean,weathercode&timezone=auto`;
28
+ const response = await fetch(weatherUrl);
29
+ const data = await response.json();
30
+
31
+ const forecast = data.daily.time.map((date: string, index: number) => ({
32
+ date,
33
+ maxTemp: data.daily.temperature_2m_max[index],
34
+ minTemp: data.daily.temperature_2m_min[index],
35
+ precipitationChance: data.daily.precipitation_probability_mean[index],
36
+ condition: getWeatherCondition(data.daily.weathercode[index]),
37
+ location: name,
38
+ }));
39
+
40
+ return forecast;
41
+ },
42
+ });
43
+
44
+ const forecastSchema = z.array(
45
+ z.object({
46
+ date: z.string(),
47
+ maxTemp: z.number(),
48
+ minTemp: z.number(),
49
+ precipitationChance: z.number(),
50
+ condition: z.string(),
51
+ location: z.string(),
52
+ }),
53
+ );
54
+
55
+ const planActivities = new Step({
56
+ id: 'plan-activities',
57
+ description: 'Suggests activities based on weather conditions',
58
+ inputSchema: forecastSchema,
59
+ execute: async ({ context, mastra }) => {
60
+ const forecast = context.machineContext?.getStepPayload<z.infer<typeof forecastSchema>>('fetch-weather');
61
+
62
+ if (!forecast) {
63
+ throw new Error('Forecast data not found');
64
+ }
65
+
66
+ const prompt = `Based on the following weather forecast for ${forecast[0].location}, suggest appropriate activities:
67
+ ${JSON.stringify(forecast, null, 2)}
68
+ `;
69
+
70
+ if (!mastra?.llm) {
71
+ throw new Error('Mastra not found');
72
+ }
73
+
74
+ const llm = mastra.llm({
75
+ provider: 'OPEN_AI',
76
+ name: 'gpt-4o',
77
+ });
78
+
79
+ const response = await llm.stream([
80
+ {
81
+ role: 'system',
82
+ content: `You are a local activities and travel expert who excels at weather-based planning. Analyze the weather data and provide practical activity recommendations.
83
+
84
+ For each day in the forecast, structure your response exactly as follows:
85
+
86
+ 📅 [Day, Month Date, Year]
87
+ ═══════════════════════════
88
+
89
+ 🌡️ WEATHER SUMMARY
90
+ • Conditions: [brief description]
91
+ • Temperature: [X°C/Y°F to A°C/B°F]
92
+ • Precipitation: [X% chance]
93
+
94
+ 🌅 MORNING ACTIVITIES
95
+ Outdoor:
96
+ • [Activity Name] - [Brief description including specific location/route]
97
+ Best timing: [specific time range]
98
+ Note: [relevant weather consideration]
99
+
100
+ 🌞 AFTERNOON ACTIVITIES
101
+ Outdoor:
102
+ • [Activity Name] - [Brief description including specific location/route]
103
+ Best timing: [specific time range]
104
+ Note: [relevant weather consideration]
105
+
106
+ 🏠 INDOOR ALTERNATIVES
107
+ • [Activity Name] - [Brief description including specific venue]
108
+ Ideal for: [weather condition that would trigger this alternative]
109
+
110
+ ⚠️ SPECIAL CONSIDERATIONS
111
+ • [Any relevant weather warnings, UV index, wind conditions, etc.]
112
+
113
+ Guidelines:
114
+ - Suggest 2-3 time-specific outdoor activities per day
115
+ - Include 1-2 indoor backup options
116
+ - For precipitation >50%, lead with indoor activities
117
+ - All activities must be specific to the location
118
+ - Include specific venues, trails, or locations
119
+ - Consider activity intensity based on temperature
120
+ - Keep descriptions concise but informative
121
+
122
+ Maintain this exact formatting for consistency, using the emoji and section headers as shown.`,
123
+ },
124
+ {
125
+ role: 'user',
126
+ content: prompt,
127
+ },
128
+ ]);
129
+
130
+ for await (const chunk of response.textStream) {
131
+ process.stdout.write(chunk);
132
+ }
133
+
134
+ return {
135
+ activities: response.text,
136
+ };
137
+ },
138
+ });
139
+
140
+ function getWeatherCondition(code: number): string {
141
+ const conditions: Record<number, string> = {
142
+ 0: 'Clear sky',
143
+ 1: 'Mainly clear',
144
+ 2: 'Partly cloudy',
145
+ 3: 'Overcast',
146
+ 45: 'Foggy',
147
+ 48: 'Depositing rime fog',
148
+ 51: 'Light drizzle',
149
+ 53: 'Moderate drizzle',
150
+ 55: 'Dense drizzle',
151
+ 61: 'Slight rain',
152
+ 63: 'Moderate rain',
153
+ 65: 'Heavy rain',
154
+ 71: 'Slight snow fall',
155
+ 73: 'Moderate snow fall',
156
+ 75: 'Heavy snow fall',
157
+ 95: 'Thunderstorm',
158
+ };
159
+ return conditions[code] || 'Unknown';
160
+ }
161
+
162
+ const weatherWorkflow = new Workflow({
163
+ name: 'weather-workflow',
164
+ triggerSchema: z.object({
165
+ city: z.string().describe('The city to get the weather for'),
166
+ }),
167
+ })
168
+ .step(fetchWeather)
169
+ .then(planActivities);
170
+
171
+ weatherWorkflow.commit();
172
+
173
+ export { weatherWorkflow };
@@ -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;AAm/BzC,eAAO,MAAM,OAAO,oBAAkB,CAAC;AAOvC,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;AAmhCzC,eAAO,MAAM,OAAO,oBAAkB,CAAC;AAQvC,eAAe,OAAO,CAAC"}
@@ -4,13 +4,17 @@ import _path, { join } from 'path';
4
4
  import serverless from 'serverless-http';
5
5
  import { stringify } from 'superjson';
6
6
  import { fileURLToPath as _fileURLToPath } from 'url';
7
+ import { pathToFileURL } from 'url';
7
8
  import zodToJsonSchema from 'zod-to-json-schema';
8
9
  const ___filename = _fileURLToPath(import.meta.url);
9
10
  const ___dirname = _path.dirname(___filename);
10
- const { mastra } = await import(join(process.cwd(), 'mastra.mjs'));
11
+ const mastraPath = pathToFileURL(join(process.cwd(), 'mastra.mjs')).href;
12
+ const { mastra } = await import(mastraPath);
11
13
  const mastraToolsPaths = process.env.MASTRA_TOOLS_PATH;
12
14
  const toolImports = mastraToolsPaths
13
- ? await Promise.all(mastraToolsPaths.split(',').map(toolPath => import(toolPath)))
15
+ ? await Promise.all(mastraToolsPaths.split(',').map(async (toolPath) => {
16
+ return import(pathToFileURL(toolPath).href);
17
+ }))
14
18
  : [];
15
19
  const tools = toolImports.reduce((acc, toolModule) => {
16
20
  Object.entries(toolModule).forEach(([key, tool]) => {
@@ -129,7 +133,7 @@ app.get('/api/agents', async (_req, res) => {
129
133
  }
130
134
  });
131
135
  /**
132
- * POST /api/agents/{agentId}/text
136
+ * POST /api/agents/{agentId}/generate
133
137
  * @summary Send text messages to agent
134
138
  * @tags Agent
135
139
  * @param {string} agentId.path.required - Agent identifier
@@ -138,11 +142,11 @@ app.get('/api/agents', async (_req, res) => {
138
142
  * @return {Error} 400 - Validation error
139
143
  * @return {Error} 500 - Server error
140
144
  */
141
- app.post('/api/agents/:agentId/text', async (req, res) => {
145
+ app.post('/api/agents/:agentId/generate', async (req, res) => {
142
146
  try {
143
147
  const agentId = req.params.agentId;
144
148
  const agent = mastra.getAgent(agentId);
145
- const messages = req.body.messages;
149
+ const { messages, threadId, resourceid } = req.body;
146
150
  const { ok, errorResponse } = await validateBody({
147
151
  messages,
148
152
  });
@@ -150,12 +154,12 @@ app.post('/api/agents/:agentId/text', async (req, res) => {
150
154
  res.status(400).json({ error: errorResponse });
151
155
  return;
152
156
  }
153
- if (!Array.isArray(messages)) {
154
- res.status(400).json({ error: { messages: 'Messages should be an array' } });
155
- return;
156
- }
157
- const result = await agent.generate(messages);
158
- res.json(result);
157
+ const result = await agent.generate(messages, { threadId, resourceid });
158
+ const textResult = {
159
+ text: result.text,
160
+ agent: agent.name,
161
+ };
162
+ res.json(textResult);
159
163
  }
160
164
  catch (error) {
161
165
  const apiError = error;
@@ -178,7 +182,7 @@ app.post('/api/agents/:agentId/stream', async (req, res) => {
178
182
  try {
179
183
  const agentId = req.params.agentId;
180
184
  const agent = mastra.getAgent(agentId);
181
- const messages = req.body.messages;
185
+ const { messages, threadId, resourceid } = req.body;
182
186
  const { ok, errorResponse } = await validateBody({
183
187
  messages,
184
188
  });
@@ -186,12 +190,9 @@ app.post('/api/agents/:agentId/stream', async (req, res) => {
186
190
  res.status(400).json({ error: errorResponse });
187
191
  return;
188
192
  }
189
- if (!Array.isArray(messages)) {
190
- res.status(400).json({ error: { messages: 'Messages should be an array' } });
191
- return;
192
- }
193
- const streamResult = await agent.generate(messages, {
194
- stream: true,
193
+ const streamResult = await agent.stream(messages, {
194
+ threadId,
195
+ resourceid,
195
196
  });
196
197
  streamResult.pipeDataStreamToResponse(res);
197
198
  }
@@ -216,8 +217,7 @@ app.post('/api/agents/:agentId/text-object', async (req, res) => {
216
217
  try {
217
218
  const agentId = req.params.agentId;
218
219
  const agent = mastra.getAgent(agentId);
219
- const messages = req.body.messages;
220
- const schema = req.body.schema;
220
+ const { messages, schema, threadId, resourceid } = req.body;
221
221
  const { ok, errorResponse } = await validateBody({
222
222
  messages,
223
223
  schema,
@@ -226,12 +226,12 @@ app.post('/api/agents/:agentId/text-object', async (req, res) => {
226
226
  res.status(400).json({ error: errorResponse });
227
227
  return;
228
228
  }
229
- if (!Array.isArray(messages)) {
230
- res.status(400).json({ error: { messages: 'Messages should be an array' } });
231
- return;
232
- }
233
- const result = await agent.generate(messages, { schema });
234
- res.json(result);
229
+ const result = await agent.generate(messages, { output: schema, threadId, resourceid });
230
+ const objectResult = {
231
+ object: result.object,
232
+ agent: result.agent,
233
+ };
234
+ res.json(objectResult);
235
235
  }
236
236
  catch (error) {
237
237
  const apiError = error;
@@ -256,8 +256,7 @@ app.post('/api/agents/:agentId/stream-object', async (req, res) => {
256
256
  try {
257
257
  const agentId = req.params.agentId;
258
258
  const agent = mastra.getAgent(agentId);
259
- const messages = req.body.messages;
260
- const schema = req.body.schema;
259
+ const { messages, schema, threadId, resourceid } = req.body;
261
260
  const { ok, errorResponse } = await validateBody({
262
261
  messages,
263
262
  schema,
@@ -266,11 +265,7 @@ app.post('/api/agents/:agentId/stream-object', async (req, res) => {
266
265
  res.status(400).json({ error: errorResponse });
267
266
  return;
268
267
  }
269
- if (!Array.isArray(messages)) {
270
- res.status(400).json({ error: { messages: 'Messages should be an array' } });
271
- return;
272
- }
273
- const streamResult = await agent.generate(messages, { schema, stream: true });
268
+ const streamResult = await agent.stream(messages, { output: schema, threadId, resourceid });
274
269
  streamResult.pipeTextStreamToResponse(res);
275
270
  }
276
271
  catch (error) {
@@ -323,7 +318,7 @@ app.post('/api/agents/:agentId/tools/:toolId/execute', async (req, res) => {
323
318
  */
324
319
  app.get('/api/workflows', async (_req, res) => {
325
320
  try {
326
- const workflows = mastra.getWorkflows();
321
+ const workflows = mastra.getWorkflows({ serialized: true });
327
322
  res.json(workflows);
328
323
  }
329
324
  catch (error) {
@@ -358,7 +353,7 @@ app.get('/api/workflows/:workflowId', async (req, res) => {
358
353
  return acc;
359
354
  }, {});
360
355
  res.json({
361
- ...workflow,
356
+ name: workflow.name,
362
357
  triggerSchema: triggerSchema ? stringify(zodToJsonSchema(triggerSchema)) : undefined,
363
358
  steps: serializedSteps,
364
359
  stepGraph,
@@ -377,7 +372,7 @@ app.get('/api/workflows/:workflowId', async (req, res) => {
377
372
  * @summary Execute a workflow
378
373
  * @tags Workflow
379
374
  * @param {string} workflowId.path.required - Workflow identifier
380
- * @param {object} request.body.required - Workflow input data
375
+ * @param {object} request.body.required - Workflow trigger data
381
376
  * @return {object} 200 - Workflow execution result
382
377
  * @return {Error} 500 - Server error
383
378
  */
@@ -385,8 +380,11 @@ app.post('/api/workflows/:workflowId/execute', async (req, res) => {
385
380
  try {
386
381
  const workflowId = req.params.workflowId;
387
382
  const workflow = mastra.getWorkflow(workflowId);
388
- const result = await workflow.execute(req.body);
389
- res.json(result);
383
+ const result = await workflow.execute({ triggerData: req.body });
384
+ res.json({
385
+ results: result?.results ?? {},
386
+ workflow: workflowId,
387
+ });
390
388
  }
391
389
  catch (error) {
392
390
  const apiError = error;
@@ -396,22 +394,50 @@ app.post('/api/workflows/:workflowId/execute', async (req, res) => {
396
394
  }
397
395
  });
398
396
  /**
399
- * GET /api/memory/threads/get-by-resourceid/{resourceid}
400
- * @summary Get threads by resource ID
397
+ * GET /api/memory/status
398
+ * @summary Get memory status
401
399
  * @tags Memory
402
- * @param {string} resourceid.path.required - Resource identifier
400
+ * @return {object} 200 - Memory status
401
+ * @return {Error} 500 - Server error
402
+ */
403
+ app.get('/api/memory/status', async (_req, res) => {
404
+ try {
405
+ const memory = mastra.memory;
406
+ if (!memory) {
407
+ res.json({ result: false });
408
+ return;
409
+ }
410
+ res.json({ result: true });
411
+ }
412
+ catch (error) {
413
+ const apiError = error;
414
+ console.error('Error getting memory status', apiError);
415
+ res.status(apiError.status || 500).json({ error: apiError.message || 'Error getting memory status' });
416
+ return;
417
+ }
418
+ });
419
+ /**
420
+ * GET /api/memory/threads
421
+ * @summary Get threads
422
+ * @tags Memory
423
+ * @param {string} resourceid.query.required - Resource identifier
403
424
  * @return {Thread[]} 200 - Array of threads
404
425
  * @return {Error} 400 - Memory not initialized
405
426
  * @return {Error} 500 - Server error
406
427
  */
407
- app.get('/api/memory/threads/get-by-resourceid/:resourceid', async (req, res) => {
428
+ app.get('/api/memory/threads', async (req, res) => {
408
429
  try {
409
- const resourceid = req.params.resourceid;
430
+ const resourceid = req.query.resourceid;
410
431
  const memory = mastra.memory;
411
432
  if (!memory) {
412
433
  res.status(400).json({ error: 'Memory is not initialized' });
413
434
  return;
414
435
  }
436
+ const { ok, errorResponse } = await validateBody({ resourceid });
437
+ if (!ok) {
438
+ res.status(400).json({ error: errorResponse });
439
+ return;
440
+ }
415
441
  const threads = await memory.getThreadsByResourceId({ resourceid });
416
442
  res.json(threads);
417
443
  }
@@ -931,5 +957,6 @@ export const handler = serverless(app);
931
957
  app.listen(process.env.PORT || 4111, () => {
932
958
  console.log(`🦄Server running on port ${process.env.PORT || 4111}`);
933
959
  console.log(`📚 Open API documentation available at http://localhost:${process.env.PORT || 4111}/openapi.json`);
960
+ console.log(`👨‍💻 Playground available at http://localhost:${process.env.PORT || 4111}/`);
934
961
  });
935
962
  export default handler;
@@ -1 +1 @@
1
- {"version":3,"file":"netlify.d.ts","sourceRoot":"","sources":["../../src/templates/netlify.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AA4iBzC,eAAO,MAAM,OAAO,oBAAkB,CAAC"}
1
+ {"version":3,"file":"netlify.d.ts","sourceRoot":"","sources":["../../src/templates/netlify.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AA0tBzC,eAAO,MAAM,OAAO,oBAAkB,CAAC"}