@mastra/agent-builder 0.0.1-alpha.1 → 0.0.1-alpha.2

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 (73) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/agent/index.d.ts +5885 -0
  3. package/dist/agent/index.d.ts.map +1 -0
  4. package/dist/defaults.d.ts +6529 -0
  5. package/dist/defaults.d.ts.map +1 -0
  6. package/dist/index.d.ts +4 -4
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +1810 -36
  9. package/dist/index.js.map +1 -0
  10. package/dist/processors/tool-summary.d.ts +29 -0
  11. package/dist/processors/tool-summary.d.ts.map +1 -0
  12. package/dist/processors/write-file.d.ts +10 -0
  13. package/dist/processors/write-file.d.ts.map +1 -0
  14. package/dist/types.d.ts +1121 -0
  15. package/dist/types.d.ts.map +1 -0
  16. package/dist/utils.d.ts +63 -0
  17. package/dist/utils.d.ts.map +1 -0
  18. package/dist/workflows/index.d.ts +5 -0
  19. package/dist/workflows/index.d.ts.map +1 -0
  20. package/dist/workflows/shared/schema.d.ts +139 -0
  21. package/dist/workflows/shared/schema.d.ts.map +1 -0
  22. package/dist/workflows/task-planning/prompts.d.ts +37 -0
  23. package/dist/workflows/task-planning/prompts.d.ts.map +1 -0
  24. package/dist/workflows/task-planning/schema.d.ts +548 -0
  25. package/dist/workflows/task-planning/schema.d.ts.map +1 -0
  26. package/dist/workflows/task-planning/task-planning.d.ts +992 -0
  27. package/dist/workflows/task-planning/task-planning.d.ts.map +1 -0
  28. package/dist/workflows/template-builder/template-builder.d.ts +1910 -0
  29. package/dist/workflows/template-builder/template-builder.d.ts.map +1 -0
  30. package/dist/workflows/workflow-builder/prompts.d.ts +44 -0
  31. package/dist/workflows/workflow-builder/prompts.d.ts.map +1 -0
  32. package/dist/workflows/workflow-builder/schema.d.ts +1170 -0
  33. package/dist/workflows/workflow-builder/schema.d.ts.map +1 -0
  34. package/dist/workflows/workflow-builder/tools.d.ts +309 -0
  35. package/dist/workflows/workflow-builder/tools.d.ts.map +1 -0
  36. package/dist/workflows/workflow-builder/workflow-builder.d.ts +2714 -0
  37. package/dist/workflows/workflow-builder/workflow-builder.d.ts.map +1 -0
  38. package/dist/workflows/workflow-map.d.ts +3735 -0
  39. package/dist/workflows/workflow-map.d.ts.map +1 -0
  40. package/package.json +20 -9
  41. package/.turbo/turbo-build.log +0 -12
  42. package/dist/_tsup-dts-rollup.d.cts +0 -14933
  43. package/dist/_tsup-dts-rollup.d.ts +0 -14933
  44. package/dist/index.cjs +0 -4357
  45. package/dist/index.d.cts +0 -4
  46. package/eslint.config.js +0 -11
  47. package/integration-tests/CHANGELOG.md +0 -9
  48. package/integration-tests/README.md +0 -154
  49. package/integration-tests/docker-compose.yml +0 -39
  50. package/integration-tests/package.json +0 -38
  51. package/integration-tests/src/agent-template-behavior.test.ts +0 -103
  52. package/integration-tests/src/fixtures/minimal-mastra-project/env.example +0 -6
  53. package/integration-tests/src/fixtures/minimal-mastra-project/package.json +0 -17
  54. package/integration-tests/src/fixtures/minimal-mastra-project/src/mastra/agents/weather.ts +0 -34
  55. package/integration-tests/src/fixtures/minimal-mastra-project/src/mastra/index.ts +0 -15
  56. package/integration-tests/src/fixtures/minimal-mastra-project/src/mastra/mcp/index.ts +0 -46
  57. package/integration-tests/src/fixtures/minimal-mastra-project/src/mastra/tools/weather.ts +0 -14
  58. package/integration-tests/src/fixtures/minimal-mastra-project/tsconfig.json +0 -17
  59. package/integration-tests/src/template-integration.test.ts +0 -312
  60. package/integration-tests/tsconfig.json +0 -9
  61. package/integration-tests/vitest.config.ts +0 -18
  62. package/src/agent/index.ts +0 -187
  63. package/src/agent-builder.test.ts +0 -313
  64. package/src/defaults.ts +0 -2876
  65. package/src/index.ts +0 -3
  66. package/src/processors/tool-summary.ts +0 -145
  67. package/src/processors/write-file.ts +0 -17
  68. package/src/types.ts +0 -305
  69. package/src/utils.ts +0 -409
  70. package/src/workflows/index.ts +0 -1
  71. package/src/workflows/template-builder.ts +0 -1682
  72. package/tsconfig.json +0 -5
  73. package/vitest.config.ts +0 -11
@@ -1,313 +0,0 @@
1
- import type { MastraLanguageModel } from '@mastra/core/agent';
2
- import { RuntimeContext } from '@mastra/core/runtime-context';
3
- import { describe, it, expect, vi } from 'vitest';
4
- import { AgentBuilderDefaults } from './defaults';
5
- import { ToolSummaryProcessor } from './processors/tool-summary';
6
- import { AgentBuilder } from './index';
7
-
8
- // Mock the openai model for testing
9
- const mockModel = {
10
- modelId: 'gpt-4',
11
- provider: 'openai',
12
- } as MastraLanguageModel;
13
-
14
- // Mock config with required properties
15
- const mockConfig = {
16
- model: mockModel,
17
- projectPath: '/test/project',
18
- summaryModel: mockModel,
19
- };
20
-
21
- describe('AgentBuilder', () => {
22
- describe('AgentBuilderDefaults', () => {
23
- it('should have default instructions', () => {
24
- expect(AgentBuilderDefaults.DEFAULT_INSTRUCTIONS()).toContain('Mastra Expert Agent');
25
- });
26
-
27
- it('should have default memory config', () => {
28
- expect(AgentBuilderDefaults.DEFAULT_MEMORY_CONFIG).toEqual({
29
- lastMessages: 20,
30
- });
31
- });
32
-
33
- it('should have default tools', async () => {
34
- const tools = await AgentBuilderDefaults.DEFAULT_TOOLS('test');
35
- expect(tools).toHaveProperty('manageProject');
36
- expect(tools).toHaveProperty('multiEdit');
37
- expect(tools).toHaveProperty('validateCode');
38
- });
39
- });
40
-
41
- describe('AgentBuilder class', () => {
42
- it('should create an instance with basic config', () => {
43
- const builder = new AgentBuilder({
44
- model: mockModel,
45
- projectPath: '/test/project',
46
- });
47
-
48
- expect(builder).toBeInstanceOf(AgentBuilder);
49
- expect(builder.id).toBe('agent-builder');
50
- expect(builder.name).toBe('agent-builder');
51
- });
52
-
53
- it('should have access to default tools', () => {
54
- const builder = new AgentBuilder({
55
- model: mockModel,
56
- projectPath: '/test/project',
57
- });
58
-
59
- const tools = builder.getTools({ runtimeContext: new RuntimeContext() });
60
- expect(tools).toBeDefined();
61
- });
62
-
63
- it('should combine custom instructions with default instructions', () => {
64
- const customInstructions = 'Custom instructions for testing';
65
- const builder = new AgentBuilder({
66
- model: mockModel,
67
- instructions: customInstructions,
68
- projectPath: '/test/project',
69
- });
70
-
71
- // Since instructions are private, we can't directly test them,
72
- // but we can verify the builder was created successfully
73
- expect(builder).toBeInstanceOf(AgentBuilder);
74
- });
75
-
76
- it('should merge custom tools with default tools', () => {
77
- const customTool = {
78
- id: 'custom-tool',
79
- description: 'A custom tool for testing',
80
- execute: vi.fn().mockResolvedValue({ success: true }),
81
- };
82
-
83
- const builder = new AgentBuilder({
84
- model: mockModel,
85
- tools: {
86
- customTool,
87
- },
88
- projectPath: '/test/project',
89
- });
90
-
91
- expect(builder).toBeInstanceOf(AgentBuilder);
92
- });
93
- });
94
-
95
- describe('AgentBuilder.defaultConfig', () => {
96
- it('should return default configuration', () => {
97
- const defaultConfig = AgentBuilder.defaultConfig('/test/project');
98
-
99
- expect(defaultConfig).toHaveProperty('instructions');
100
- expect(defaultConfig).toHaveProperty('memoryConfig');
101
- expect(defaultConfig).toHaveProperty('tools');
102
- expect(defaultConfig.memoryConfig).toEqual(AgentBuilderDefaults.DEFAULT_MEMORY_CONFIG);
103
- });
104
- });
105
-
106
- describe('AgentBuilder.createWithDefaults', () => {
107
- it('should create an instance with merged default settings', () => {
108
- const builder = new AgentBuilder({
109
- model: mockModel,
110
- memoryConfig: {
111
- maxMessages: 50, // Override default
112
- },
113
- projectPath: '/test/project',
114
- });
115
-
116
- expect(builder).toBeInstanceOf(AgentBuilder);
117
- });
118
- });
119
-
120
- describe('generateAgent method', () => {
121
- it('should be defined and callable', async () => {
122
- const builder = new AgentBuilder(mockConfig);
123
-
124
- expect(builder.generateAgent).toBeDefined();
125
- expect(typeof builder.generateAgent).toBe('function');
126
- });
127
- });
128
-
129
- describe('ToolSummaryProcessor', () => {
130
- it('should cache tool call summaries', async () => {
131
- const processor = new ToolSummaryProcessor({ summaryModel: mockModel });
132
-
133
- // Check initial cache is empty
134
- const initialStats = processor.getCacheStats();
135
- expect(initialStats.size).toBe(0);
136
-
137
- // Create a mock tool call
138
- const mockToolCall = {
139
- toolName: 'testTool',
140
- args: { param1: 'value1', param2: 'value2' },
141
- };
142
-
143
- // Test cache key generation
144
- const cacheKey = processor.createCacheKey(mockToolCall);
145
- expect(cacheKey).toBe('testTool:{"param1":"value1","param2":"value2"}');
146
-
147
- // Test cache clearing
148
- processor.clearCache();
149
- const clearedStats = processor.getCacheStats();
150
- expect(clearedStats.size).toBe(0);
151
- });
152
-
153
- it('should create consistent cache keys for same arguments', () => {
154
- const processor = new ToolSummaryProcessor({ summaryModel: mockModel });
155
-
156
- const toolCall1 = {
157
- toolName: 'myTool',
158
- args: { a: 1, b: 2 },
159
- };
160
-
161
- const toolCall2 = {
162
- toolName: 'myTool',
163
- args: { b: 2, a: 1 }, // Different order
164
- };
165
-
166
- const key1 = processor.createCacheKey(toolCall1);
167
- const key2 = processor.createCacheKey(toolCall2);
168
-
169
- // Should be same key despite different argument order
170
- expect(key1).toBe(key2);
171
- expect(key1).toBe('myTool:{"a":1,"b":2}');
172
- });
173
-
174
- it('should use Promise.allSettled for resilient parallel processing', async () => {
175
- // This test verifies that the ToolSummaryProcessor uses Promise.allSettled
176
- // instead of Promise.all, so that one failed summary doesn't break all summaries
177
-
178
- const processor = new ToolSummaryProcessor({ summaryModel: mockModel });
179
-
180
- // Test that the processor handles empty messages gracefully
181
- const emptyMessages: any[] = [];
182
- const result = await processor.process(emptyMessages);
183
- expect(result).toEqual([]);
184
-
185
- // Test that the processor doesn't throw when processing messages
186
- // (the actual resilience testing would require more complex mocking,
187
- // but this ensures the basic structure works)
188
- const basicMessages = [
189
- {
190
- role: 'user' as const,
191
- content: 'Hello',
192
- },
193
- ];
194
-
195
- const basicResult = await processor.process(basicMessages);
196
- expect(basicResult).toHaveLength(1);
197
- expect(basicResult[0].content).toBe('Hello');
198
- });
199
- });
200
-
201
- describe('Server Management Tools', () => {
202
- it('should have manageServer and httpRequest tools available', async () => {
203
- const builder = new AgentBuilder(mockConfig);
204
- const tools = await builder.getTools({ runtimeContext: new RuntimeContext() });
205
-
206
- expect(tools.manageServer).toBeDefined();
207
- expect(tools.httpRequest).toBeDefined();
208
- });
209
-
210
- it('should validate manageServer tool schema', () => {
211
- expect(AgentBuilderDefaults.checkMastraServerStatus).toBeDefined();
212
- expect(AgentBuilderDefaults.startMastraServer).toBeDefined();
213
- expect(AgentBuilderDefaults.stopMastraServer).toBeDefined();
214
- expect(AgentBuilderDefaults.makeHttpRequest).toBeDefined();
215
- });
216
-
217
- it('should handle server stop with no running process', async () => {
218
- // Mock exec to return "No process found"
219
- const mockExec = vi.fn().mockResolvedValue({ stdout: 'No process found' });
220
- const originalExec = require('child_process').exec;
221
-
222
- try {
223
- require('child_process').exec = mockExec;
224
-
225
- const result = await AgentBuilderDefaults.stopMastraServer({ port: 9999 });
226
-
227
- expect(result.success).toBe(true);
228
- expect(result.status).toBe('stopped');
229
- expect(result.message).toContain('No Mastra server found running on port 9999');
230
- } finally {
231
- require('child_process').exec = originalExec;
232
- }
233
- });
234
- });
235
-
236
- describe('Code Validation', () => {
237
- it('should have validateCode method', () => {
238
- expect(AgentBuilderDefaults.validateCode).toBeDefined();
239
- expect(AgentBuilderDefaults.parseESLintErrors).toBeDefined();
240
- });
241
-
242
- it('should include full TypeScript output in validation errors', () => {
243
- // Since we're now passing through raw TypeScript output,
244
- // we just need to verify the validateCode method includes it
245
- expect(AgentBuilderDefaults.validateCode).toBeDefined();
246
-
247
- // The actual validation testing would require a real TypeScript project,
248
- // but we can verify the method exists and handles errors properly
249
- const mockTsOutput = `src/test.ts(10,5): error TS2322: Type 'string' is not assignable to type 'number'.
250
- src/another.ts(20,15): warning TS2345: Argument of type 'null' is not assignable to parameter of type 'string'.
251
- Found 2 errors in 2 files.`;
252
-
253
- // This output would now be included directly in the error message
254
- // for the agent to interpret, rather than being parsed into structured errors
255
- expect(mockTsOutput).toContain('error TS2322');
256
- expect(mockTsOutput).toContain('Found 2 errors');
257
- });
258
-
259
- it('should parse ESLint errors correctly', () => {
260
- const eslintResults = [
261
- {
262
- filePath: '/path/to/file.ts',
263
- messages: [
264
- {
265
- ruleId: 'no-unused-vars',
266
- severity: 2,
267
- message: "'unusedVar' is defined but never used.",
268
- line: 5,
269
- column: 10,
270
- },
271
- {
272
- ruleId: 'prefer-const',
273
- severity: 1,
274
- message: "'data' is never reassigned. Use 'const' instead of 'let'.",
275
- line: 8,
276
- column: 3,
277
- },
278
- ],
279
- },
280
- ];
281
-
282
- const errors = AgentBuilderDefaults.parseESLintErrors(eslintResults);
283
-
284
- expect(errors).toHaveLength(2);
285
- expect(errors[0]).toEqual({
286
- type: 'eslint',
287
- severity: 'error',
288
- message: "'unusedVar' is defined but never used.",
289
- file: '/path/to/file.ts',
290
- line: 5,
291
- column: 10,
292
- code: 'no-unused-vars',
293
- });
294
- expect(errors[1]).toEqual({
295
- type: 'eslint',
296
- severity: 'warning',
297
- message: "'data' is never reassigned. Use 'const' instead of 'let'.",
298
- file: '/path/to/file.ts',
299
- line: 8,
300
- column: 3,
301
- code: 'prefer-const',
302
- });
303
- });
304
-
305
- it('should include validation workflow in instructions', () => {
306
- const instructions = AgentBuilderDefaults.DEFAULT_INSTRUCTIONS('/test/path');
307
-
308
- expect(instructions).toContain('validateCode');
309
- expect(instructions).toContain('Run \`validateCode\` with types and lint checks');
310
- expect(instructions).toContain('Re-validate until clean');
311
- });
312
- });
313
- });