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
@@ -2,8 +2,21 @@ import express from 'express';
2
2
  import { join } from 'path';
3
3
  import serverless from 'serverless-http';
4
4
  import { stringify } from 'superjson';
5
+ import { pathToFileURL } from 'url';
5
6
  import zodToJsonSchema from 'zod-to-json-schema';
6
7
  const { mastra } = await import(join(process.cwd(), 'mastra.mjs'));
8
+ const mastraToolsPaths = process.env.MASTRA_TOOLS_PATH;
9
+ const toolImports = mastraToolsPaths
10
+ ? await Promise.all(mastraToolsPaths.split(',').map(async (toolPath) => {
11
+ return import(pathToFileURL(toolPath).href);
12
+ }))
13
+ : [];
14
+ const tools = toolImports.reduce((acc, toolModule) => {
15
+ Object.entries(toolModule).forEach(([key, tool]) => {
16
+ acc[key] = tool;
17
+ });
18
+ return acc;
19
+ }, {});
7
20
  const app = express();
8
21
  app.use(express.json());
9
22
  const validateBody = async (body) => {
@@ -24,7 +37,24 @@ app.get('/', (_req, res) => {
24
37
  app.get('/api/agents', async (_req, res) => {
25
38
  try {
26
39
  const agents = mastra.getAgents();
27
- res.json(agents);
40
+ const serializedAgents = Object.entries(agents).reduce((acc, [_id, _agent]) => {
41
+ const agent = _agent;
42
+ const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc, [key, tool]) => {
43
+ const _tool = tool;
44
+ acc[key] = {
45
+ ..._tool,
46
+ inputSchema: _tool.inputSchema ? stringify(zodToJsonSchema(_tool.inputSchema)) : undefined,
47
+ outputSchema: _tool.outputSchema ? stringify(zodToJsonSchema(_tool.outputSchema)) : undefined,
48
+ };
49
+ return acc;
50
+ }, {});
51
+ acc[_id] = {
52
+ ...agent,
53
+ tools: serializedAgentTools,
54
+ };
55
+ return acc;
56
+ }, {});
57
+ res.json(serializedAgents);
28
58
  }
29
59
  catch (error) {
30
60
  const apiError = error;
@@ -37,7 +67,19 @@ app.get('/api/agents/:agentId', async (req, res) => {
37
67
  try {
38
68
  const agentId = req.params.agentId;
39
69
  const agent = mastra.getAgent(agentId);
40
- res.json(agent);
70
+ const serializedAgentTools = Object.entries(agent?.tools || {}).reduce((acc, [key, tool]) => {
71
+ const _tool = tool;
72
+ acc[key] = {
73
+ ..._tool,
74
+ inputSchema: _tool.inputSchema ? stringify(zodToJsonSchema(_tool.inputSchema)) : undefined,
75
+ outputSchema: _tool.outputSchema ? stringify(zodToJsonSchema(_tool.outputSchema)) : undefined,
76
+ };
77
+ return acc;
78
+ }, {});
79
+ res.json({
80
+ ...agent,
81
+ tools: serializedAgentTools,
82
+ });
41
83
  }
42
84
  catch (error) {
43
85
  const apiError = error;
@@ -46,11 +88,11 @@ app.get('/api/agents/:agentId', async (req, res) => {
46
88
  return;
47
89
  }
48
90
  });
49
- app.post('/api/agents/:agentId/text', async (req, res) => {
91
+ app.post('/api/agents/:agentId/generate', async (req, res) => {
50
92
  try {
51
93
  const agentId = req.params.agentId;
52
94
  const agent = mastra.getAgent(agentId);
53
- const messages = req.body.messages;
95
+ const { messages, threadId, resourceid } = req.body;
54
96
  const { ok, errorResponse } = await validateBody({
55
97
  messages,
56
98
  });
@@ -58,11 +100,7 @@ app.post('/api/agents/:agentId/text', async (req, res) => {
58
100
  res.status(400).json({ error: errorResponse });
59
101
  return;
60
102
  }
61
- if (!Array.isArray(messages)) {
62
- res.status(400).json({ error: { messages: 'Messages should be an array' } });
63
- return;
64
- }
65
- const result = await agent.generate(messages);
103
+ const result = await agent.generate(messages, { threadId, resourceid });
66
104
  res.json(result);
67
105
  }
68
106
  catch (error) {
@@ -76,7 +114,7 @@ app.post('/api/agents/:agentId/stream', async (req, res) => {
76
114
  try {
77
115
  const agentId = req.params.agentId;
78
116
  const agent = mastra.getAgent(agentId);
79
- const messages = req.body.messages;
117
+ const { messages, threadId, resourceid } = req.body;
80
118
  const { ok, errorResponse } = await validateBody({
81
119
  messages,
82
120
  });
@@ -84,11 +122,10 @@ app.post('/api/agents/:agentId/stream', async (req, res) => {
84
122
  res.status(400).json({ error: errorResponse });
85
123
  return;
86
124
  }
87
- if (!Array.isArray(messages)) {
88
- res.status(400).json({ error: { messages: 'Messages should be an array' } });
89
- return;
90
- }
91
- const streamResult = await agent.generate(messages, { stream: true });
125
+ const streamResult = await agent.stream(messages, {
126
+ threadId,
127
+ resourceid,
128
+ });
92
129
  streamResult.pipeDataStreamToResponse(res);
93
130
  }
94
131
  catch (error) {
@@ -102,8 +139,7 @@ app.post('/api/agents/:agentId/text-object', async (req, res) => {
102
139
  try {
103
140
  const agentId = req.params.agentId;
104
141
  const agent = mastra.getAgent(agentId);
105
- const messages = req.body.messages;
106
- const schema = req.body.schema;
142
+ const { messages, schema, threadId, resourceid } = req.body;
107
143
  const { ok, errorResponse } = await validateBody({
108
144
  messages,
109
145
  schema,
@@ -112,11 +148,7 @@ app.post('/api/agents/:agentId/text-object', async (req, res) => {
112
148
  res.status(400).json({ error: errorResponse });
113
149
  return;
114
150
  }
115
- if (!Array.isArray(messages)) {
116
- res.status(400).json({ error: { messages: 'Messages should be an array' } });
117
- return;
118
- }
119
- const result = await agent.generate(messages, { schema });
151
+ const result = await agent.generate(messages, { output: schema, threadId, resourceid });
120
152
  res.json(result);
121
153
  }
122
154
  catch (error) {
@@ -132,8 +164,7 @@ app.post('/api/agents/:agentId/stream-object', async (req, res) => {
132
164
  try {
133
165
  const agentId = req.params.agentId;
134
166
  const agent = mastra.getAgent(agentId);
135
- const messages = req.body.messages;
136
- const schema = req.body.schema;
167
+ const { messages, schema, threadId, resourceid } = req.body;
137
168
  const { ok, errorResponse } = await validateBody({
138
169
  messages,
139
170
  schema,
@@ -142,11 +173,7 @@ app.post('/api/agents/:agentId/stream-object', async (req, res) => {
142
173
  res.status(400).json({ error: errorResponse });
143
174
  return;
144
175
  }
145
- if (!Array.isArray(messages)) {
146
- res.status(400).json({ error: { messages: 'Messages should be an array' } });
147
- return;
148
- }
149
- const streamResult = await agent.generate(messages, { schema, stream: true });
176
+ const streamResult = await agent.stream(messages, { output: schema, threadId, resourceid });
150
177
  streamResult.pipeTextStreamToResponse(res);
151
178
  }
152
179
  catch (error) {
@@ -158,9 +185,31 @@ app.post('/api/agents/:agentId/stream-object', async (req, res) => {
158
185
  return;
159
186
  }
160
187
  });
188
+ app.post('/api/agents/:agentId/tools/:toolId/execute', async (req, res) => {
189
+ try {
190
+ const agentId = req.params.agentId;
191
+ const toolId = req.params.toolId;
192
+ const agent = mastra.getAgent(agentId);
193
+ const tool = Object.values(agent?.tools || {}).find((tool) => tool.id === toolId);
194
+ const result = await tool.execute({
195
+ context: {
196
+ ...req.body,
197
+ },
198
+ mastra,
199
+ runId: agentId,
200
+ });
201
+ res.json(result);
202
+ }
203
+ catch (error) {
204
+ const apiError = error;
205
+ console.error('Error executing tool', apiError);
206
+ res.status(apiError.status || 500).json({ error: apiError.message || 'Error executing tool' });
207
+ return;
208
+ }
209
+ });
161
210
  app.get('/api/workflows', async (_req, res) => {
162
211
  try {
163
- const workflows = mastra.getWorkflows();
212
+ const workflows = mastra.getWorkflows({ serialized: true });
164
213
  res.json(workflows);
165
214
  }
166
215
  catch (error) {
@@ -175,9 +224,23 @@ app.get('/api/workflows/:workflowId', async (req, res) => {
175
224
  const workflowId = req.params.workflowId;
176
225
  const workflow = mastra.getWorkflow(workflowId);
177
226
  const triggerSchema = workflow.triggerSchema;
227
+ const stepGraph = workflow.stepGraph;
228
+ const stepSubscriberGraph = workflow.stepSubscriberGraph;
229
+ const serializedSteps = Object.entries(workflow.steps).reduce((acc, [key, step]) => {
230
+ const _step = step;
231
+ acc[key] = {
232
+ ..._step,
233
+ inputSchema: _step.inputSchema ? stringify(zodToJsonSchema(_step.inputSchema)) : undefined,
234
+ outputSchema: _step.outputSchema ? stringify(zodToJsonSchema(_step.outputSchema)) : undefined,
235
+ };
236
+ return acc;
237
+ }, {});
178
238
  res.json({
179
239
  ...workflow,
180
240
  triggerSchema: triggerSchema ? stringify(zodToJsonSchema(triggerSchema)) : undefined,
241
+ steps: serializedSteps,
242
+ stepGraph,
243
+ stepSubscriberGraph,
181
244
  });
182
245
  }
183
246
  catch (error) {
@@ -190,8 +253,7 @@ app.get('/api/workflows/:workflowId', async (req, res) => {
190
253
  app.post('/api/workflows/:workflowId/execute', async (req, res) => {
191
254
  try {
192
255
  const workflowId = req.params.workflowId;
193
- const workflow = mastra.workflows.get(workflowId);
194
- console.log('req.body', req.body);
256
+ const workflow = mastra.getWorkflow(workflowId);
195
257
  const result = await workflow.execute(req.body);
196
258
  res.json(result);
197
259
  }
@@ -202,14 +264,35 @@ app.post('/api/workflows/:workflowId/execute', async (req, res) => {
202
264
  return;
203
265
  }
204
266
  });
205
- app.get('/api/memory/threads/get-by-resourceid/:resourceid', async (req, res) => {
267
+ app.get('/api/memory/status', async (_req, res) => {
206
268
  try {
207
- const resourceid = req.params.resourceid;
269
+ const memory = mastra.memory;
270
+ if (!memory) {
271
+ res.json({ result: false });
272
+ return;
273
+ }
274
+ res.json({ result: true });
275
+ }
276
+ catch (error) {
277
+ const apiError = error;
278
+ console.error('Error getting memory status', apiError);
279
+ res.status(apiError.status || 500).json({ error: apiError.message || 'Error getting memory status' });
280
+ return;
281
+ }
282
+ });
283
+ app.get('/api/memory/threads', async (req, res) => {
284
+ try {
285
+ const resourceid = req.query.resourceid;
208
286
  const memory = mastra.memory;
209
287
  if (!memory) {
210
288
  res.status(400).json({ error: 'Memory is not initialized' });
211
289
  return;
212
290
  }
291
+ const { ok, errorResponse } = await validateBody({ resourceid });
292
+ if (!ok) {
293
+ res.status(400).json({ error: errorResponse });
294
+ return;
295
+ }
213
296
  const threads = await memory.getThreadsByResourceId({ resourceid });
214
297
  res.json(threads);
215
298
  }
@@ -485,4 +568,86 @@ app.post('/api/syncs/:syncId/execute', async (req, res) => {
485
568
  return;
486
569
  }
487
570
  });
571
+ app.get('/api/logs', async (_req, res) => {
572
+ try {
573
+ const logs = await mastra.getLogs();
574
+ res.json(logs);
575
+ }
576
+ catch (error) {
577
+ const apiError = error;
578
+ console.error('Error getting logs', apiError);
579
+ res.status(apiError.status || 500).json({ error: apiError.message || 'Error getting logs' });
580
+ return;
581
+ }
582
+ });
583
+ app.get('/api/logs/:runId', async (req, res) => {
584
+ try {
585
+ const runId = req.params.runId;
586
+ const logs = await mastra.getLogsByRunId(runId);
587
+ res.json(logs);
588
+ }
589
+ catch (error) {
590
+ const apiError = error;
591
+ console.error('Error getting logs', apiError);
592
+ res.status(apiError.status || 500).json({ error: apiError.message || 'Error getting logs' });
593
+ return;
594
+ }
595
+ });
596
+ app.get('/api/tools', async (_req, res) => {
597
+ if (tools) {
598
+ const serializedTools = Object.entries(tools).reduce((acc, [id, _tool]) => {
599
+ const tool = _tool;
600
+ acc[id] = {
601
+ ...tool,
602
+ inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,
603
+ outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,
604
+ };
605
+ return acc;
606
+ }, {});
607
+ res.json(serializedTools);
608
+ }
609
+ else {
610
+ res.status(200).json({});
611
+ }
612
+ });
613
+ app.get('/api/tools/:toolId', async (req, res) => {
614
+ const toolId = req.params.toolId;
615
+ const tool = Object.values(tools || {}).find((tool) => tool.id === toolId);
616
+ if (tool) {
617
+ const serializedTool = {
618
+ ...tool,
619
+ inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,
620
+ outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,
621
+ };
622
+ res.json(serializedTool);
623
+ }
624
+ else {
625
+ res.status(404).json({ error: 'Tool not found' });
626
+ }
627
+ });
628
+ app.post('/api/tools/:toolId/execute', async (req, res) => {
629
+ try {
630
+ const toolId = req.params.toolId;
631
+ const tool = Object.values(tools || {}).find((tool) => tool.id === toolId);
632
+ if (!tool) {
633
+ res.status(404).json({ error: 'Tool not found' });
634
+ return;
635
+ }
636
+ const { input } = req.body;
637
+ const result = await tool.execute({
638
+ context: {
639
+ ...input,
640
+ },
641
+ mastra,
642
+ runId: mastra.runId,
643
+ });
644
+ res.json(result);
645
+ }
646
+ catch (error) {
647
+ const apiError = error;
648
+ console.error('Error executing tool', apiError);
649
+ res.status(apiError.status || 500).json({ error: apiError.message || 'Error executing tool' });
650
+ return;
651
+ }
652
+ });
488
653
  export const handler = serverless(app);
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/templates/worker.ts"],"names":[],"mappings":"AAwBA,UAAU,gBAAgB;IACxB,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACvC,sBAAsB,IAAI,IAAI,CAAC;CAChC;;mBAk0BsB,OAAO,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,gBAAgB;;AADlF,wBAQE"}
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/templates/worker.ts"],"names":[],"mappings":"AA0CA,UAAU,gBAAgB;IACxB,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACvC,sBAAsB,IAAI,IAAI,CAAC;CAChC;;mBAshCsB,OAAO,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,gBAAgB;;AADlF,wBAQE"}