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

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 +25 -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 +29 -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
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './agent';
2
- export * from './workflows';
3
- export * from './defaults';
@@ -1,145 +0,0 @@
1
- import type { CoreMessage, MastraLanguageModel } from '@mastra/core';
2
- import { Agent, MemoryProcessor } from '@mastra/core';
3
-
4
- /**
5
- * Summarizes tool calls and caches results to avoid re-summarizing identical calls
6
- */
7
- export class ToolSummaryProcessor extends MemoryProcessor {
8
- private summaryAgent: Agent;
9
- private summaryCache: Map<string, string> = new Map();
10
-
11
- constructor({ summaryModel }: { summaryModel: MastraLanguageModel }) {
12
- super({ name: 'ToolSummaryProcessor' });
13
- this.summaryAgent = new Agent({
14
- name: 'ToolSummaryAgent',
15
- description: 'A summary agent that summarizes tool calls and results',
16
- instructions: 'You are a summary agent that summarizes tool calls and results',
17
- model: summaryModel,
18
- });
19
- }
20
-
21
- /**
22
- * Creates a cache key from tool call arguments
23
- */
24
- public createCacheKey(toolCall: any): string {
25
- if (!toolCall) return 'unknown';
26
-
27
- // Create a deterministic key from tool name and arguments
28
- const toolName = toolCall.toolName || 'unknown';
29
- const args = toolCall.args || {};
30
-
31
- // Sort keys for consistent hashing
32
- const sortedArgs = Object.keys(args)
33
- .sort()
34
- .reduce((result: Record<string, any>, key) => {
35
- result[key] = args[key];
36
- return result;
37
- }, {});
38
-
39
- return `${toolName}:${JSON.stringify(sortedArgs)}`;
40
- }
41
-
42
- /**
43
- * Clears the summary cache
44
- */
45
- public clearCache(): void {
46
- this.summaryCache.clear();
47
- }
48
-
49
- /**
50
- * Gets cache statistics
51
- */
52
- public getCacheStats(): { size: number; keys: string[] } {
53
- return {
54
- size: this.summaryCache.size,
55
- keys: Array.from(this.summaryCache.keys()),
56
- };
57
- }
58
-
59
- async process(messages: CoreMessage[]): Promise<CoreMessage[]> {
60
- // Collect all tool calls that need summarization
61
- const summaryTasks: Array<{
62
- content: any;
63
- promise: Promise<any>;
64
- cacheKey: string;
65
- }> = [];
66
-
67
- // First pass: collect all tool results that need summarization
68
- for (const message of messages) {
69
- if (
70
- message.role === 'tool' &&
71
- Array.isArray(message.content) &&
72
- message.content.length > 0 &&
73
- message.content?.some(content => content.type === 'tool-result')
74
- ) {
75
- for (const content of message.content) {
76
- if (content.type === 'tool-result') {
77
- const assistantMessageWithToolCall = messages.find(
78
- message =>
79
- message.role === 'assistant' &&
80
- Array.isArray(message.content) &&
81
- message.content.length > 0 &&
82
- message.content?.some(
83
- assistantContent =>
84
- assistantContent.type === 'tool-call' && assistantContent.toolCallId === content.toolCallId,
85
- ),
86
- );
87
- const toolCall = Array.isArray(assistantMessageWithToolCall?.content)
88
- ? assistantMessageWithToolCall?.content.find(
89
- assistantContent =>
90
- assistantContent.type === 'tool-call' && assistantContent.toolCallId === content.toolCallId,
91
- )
92
- : null;
93
-
94
- const cacheKey = this.createCacheKey(toolCall);
95
- const cachedSummary = this.summaryCache.get(cacheKey);
96
-
97
- if (cachedSummary) {
98
- // Use cached summary immediately
99
- content.result = `Tool call summary: ${cachedSummary}`;
100
- } else {
101
- // Create a promise for this summary (but don't await yet)
102
- const summaryPromise = this.summaryAgent.generate(
103
- `Summarize the following tool call: ${JSON.stringify(toolCall)} and result: ${JSON.stringify(content)}`,
104
- );
105
-
106
- summaryTasks.push({
107
- content,
108
- promise: summaryPromise,
109
- cacheKey,
110
- });
111
- }
112
- }
113
- }
114
- }
115
- }
116
-
117
- // Execute all non-cached summaries in parallel
118
- if (summaryTasks.length > 0) {
119
- const summaryResults = await Promise.allSettled(summaryTasks.map(task => task.promise));
120
-
121
- // Apply the results back to the content and cache them
122
- summaryTasks.forEach((task, index) => {
123
- const result = summaryResults[index];
124
- if (!result) return;
125
-
126
- if (result.status === 'fulfilled') {
127
- const summaryResult = result.value;
128
- const summaryText = summaryResult.text;
129
-
130
- // Cache the summary for future use
131
- this.summaryCache.set(task.cacheKey, summaryText);
132
-
133
- // Apply to content
134
- task.content.result = `Tool call summary: ${summaryText}`;
135
- } else if (result.status === 'rejected') {
136
- // Handle failed summary - use fallback or log error
137
- console.warn(`Failed to generate summary for tool call:`, result.reason);
138
- task.content.result = `Tool call summary: [Summary generation failed]`;
139
- }
140
- });
141
- }
142
-
143
- return messages;
144
- }
145
- }
@@ -1,17 +0,0 @@
1
- import { writeFile } from 'fs/promises';
2
- import { MemoryProcessor } from '@mastra/core';
3
- import type { CoreMessage } from '@mastra/core';
4
-
5
- export class WriteToDiskProcessor extends MemoryProcessor {
6
- private prefix: string;
7
-
8
- constructor({ prefix = 'messages' }: { prefix?: string } = {}) {
9
- super({ name: 'WriteToDiskProcessor' });
10
- this.prefix = prefix;
11
- }
12
-
13
- async process(messages: CoreMessage[]): Promise<CoreMessage[]> {
14
- await writeFile(`${this.prefix}-${Date.now()}-${process.pid}.json`, JSON.stringify(messages, null, 2));
15
- return messages;
16
- }
17
- }
package/src/types.ts DELETED
@@ -1,305 +0,0 @@
1
- import type { MastraLanguageModel, ToolsInput } from '@mastra/core/agent';
2
- import type { MastraStorage } from '@mastra/core/storage';
3
- import type { MastraVector } from '@mastra/core/vector';
4
- import { z } from 'zod';
5
-
6
- /**
7
- * Configuration options for the AgentBuilder
8
- */
9
- export interface AgentBuilderConfig {
10
- /** The language model to use for agent generation */
11
- model: MastraLanguageModel;
12
- /** Storage provider for memory (optional) */
13
- storage?: MastraStorage;
14
- /** Vector provider for memory (optional) */
15
- vectorProvider?: MastraVector;
16
- /** Additional tools to include beyond the default set */
17
- tools?: ToolsInput;
18
- /** Custom instructions to append to the default system prompt */
19
- instructions?: string;
20
- /** Memory configuration options */
21
- memoryConfig?: {
22
- maxMessages?: number;
23
- tokenLimit?: number;
24
- };
25
- /** Project path */
26
- projectPath: string;
27
- /** Summary model */
28
- summaryModel?: MastraLanguageModel;
29
- /** Mode */
30
- mode?: 'template' | 'code-editor';
31
- }
32
-
33
- /**
34
- * Options for generating agents with AgentBuilder
35
- */
36
- export interface GenerateAgentOptions {
37
- /** Runtime context for the generation */
38
- runtimeContext?: any;
39
- /** Output format preference */
40
- outputFormat?: 'code' | 'explanation' | 'both';
41
- }
42
-
43
- /**
44
- * Project management action types
45
- */
46
- export type ProjectAction = 'create' | 'install' | 'upgrade' | 'check';
47
-
48
- /**
49
- * Project types that can be created
50
- */
51
- export type ProjectType = 'standalone' | 'api' | 'nextjs';
52
-
53
- /**
54
- * Package manager options
55
- */
56
- export type PackageManager = 'npm' | 'pnpm' | 'yarn';
57
-
58
- /**
59
- * Validation types for code validation
60
- */
61
- export type ValidationType = 'types' | 'schemas' | 'tests' | 'integration';
62
-
63
- // Processing order for units (lower index = higher priority)
64
- export const UNIT_KINDS = ['mcp-server', 'tool', 'workflow', 'agent', 'integration', 'network', 'other'] as const;
65
-
66
- // Types for the merge template workflow
67
- export type UnitKind = (typeof UNIT_KINDS)[number];
68
-
69
- export interface TemplateUnit {
70
- kind: UnitKind;
71
- id: string;
72
- file: string;
73
- }
74
-
75
- export interface TemplateManifest {
76
- slug: string;
77
- ref?: string;
78
- description?: string;
79
- units: TemplateUnit[];
80
- }
81
-
82
- export interface MergePlan {
83
- slug: string;
84
- commitSha: string;
85
- templateDir: string;
86
- units: TemplateUnit[];
87
- }
88
-
89
- // Schema definitions
90
- export const TemplateUnitSchema = z.object({
91
- kind: z.enum(UNIT_KINDS),
92
- id: z.string(),
93
- file: z.string(),
94
- });
95
-
96
- export const TemplateManifestSchema = z.object({
97
- slug: z.string(),
98
- ref: z.string().optional(),
99
- description: z.string().optional(),
100
- units: z.array(TemplateUnitSchema),
101
- });
102
-
103
- export const AgentBuilderInputSchema = z.object({
104
- repo: z.string().describe('Git URL or local path of the template repo'),
105
- ref: z.string().optional().describe('Tag/branch/commit to checkout (defaults to main/master)'),
106
- slug: z.string().optional().describe('Slug for branch/scripts; defaults to inferred from repo'),
107
- targetPath: z.string().optional().describe('Project path to merge into; defaults to current directory'),
108
- });
109
-
110
- export const MergePlanSchema = z.object({
111
- slug: z.string(),
112
- commitSha: z.string(),
113
- templateDir: z.string(),
114
- units: z.array(TemplateUnitSchema),
115
- });
116
-
117
- // File copy schemas and types
118
- export const CopiedFileSchema = z.object({
119
- source: z.string(),
120
- destination: z.string(),
121
- unit: z.object({
122
- kind: z.enum(UNIT_KINDS),
123
- id: z.string(),
124
- }),
125
- });
126
-
127
- export const ConflictSchema = z.object({
128
- unit: z.object({
129
- kind: z.enum(UNIT_KINDS),
130
- id: z.string(),
131
- }),
132
- issue: z.string(),
133
- sourceFile: z.string(),
134
- targetFile: z.string(),
135
- });
136
-
137
- export const FileCopyInputSchema = z.object({
138
- orderedUnits: z.array(TemplateUnitSchema),
139
- templateDir: z.string(),
140
- commitSha: z.string(),
141
- slug: z.string(),
142
- targetPath: z.string().optional(),
143
- });
144
-
145
- export const FileCopyResultSchema = z.object({
146
- success: z.boolean(),
147
- copiedFiles: z.array(CopiedFileSchema),
148
- conflicts: z.array(ConflictSchema),
149
- message: z.string(),
150
- error: z.string().optional(),
151
- });
152
-
153
- // Intelligent merge schemas and types
154
- export const ConflictResolutionSchema = z.object({
155
- unit: z.object({
156
- kind: z.enum(UNIT_KINDS),
157
- id: z.string(),
158
- }),
159
- issue: z.string(),
160
- resolution: z.string(),
161
- });
162
-
163
- export const IntelligentMergeInputSchema = z.object({
164
- conflicts: z.array(ConflictSchema),
165
- copiedFiles: z.array(CopiedFileSchema),
166
- templateDir: z.string(),
167
- commitSha: z.string(),
168
- slug: z.string(),
169
- targetPath: z.string().optional(),
170
- branchName: z.string().optional(),
171
- });
172
-
173
- export const IntelligentMergeResultSchema = z.object({
174
- success: z.boolean(),
175
- applied: z.boolean(),
176
- message: z.string(),
177
- conflictsResolved: z.array(ConflictResolutionSchema),
178
- error: z.string().optional(),
179
- });
180
-
181
- // Validation schemas and types
182
- export const ValidationResultsSchema = z.object({
183
- valid: z.boolean(),
184
- errorsFixed: z.number(),
185
- remainingErrors: z.number(),
186
- });
187
-
188
- export const ValidationFixInputSchema = z.object({
189
- commitSha: z.string(),
190
- slug: z.string(),
191
- targetPath: z.string().optional(),
192
- templateDir: z.string(),
193
- orderedUnits: z.array(TemplateUnitSchema),
194
- copiedFiles: z.array(CopiedFileSchema),
195
- conflictsResolved: z.array(ConflictResolutionSchema).optional(),
196
- maxIterations: z.number().optional().default(5),
197
- });
198
-
199
- export const ValidationFixResultSchema = z.object({
200
- success: z.boolean(),
201
- applied: z.boolean(),
202
- message: z.string(),
203
- validationResults: ValidationResultsSchema,
204
- error: z.string().optional(),
205
- });
206
-
207
- // Final workflow result schema
208
- export const ApplyResultSchema = z.object({
209
- success: z.boolean(),
210
- applied: z.boolean(),
211
- branchName: z.string().optional(),
212
- message: z.string(),
213
- validationResults: ValidationResultsSchema.optional(),
214
- error: z.string().optional(),
215
- errors: z.array(z.string()).optional(),
216
- stepResults: z
217
- .object({
218
- cloneSuccess: z.boolean().optional(),
219
- analyzeSuccess: z.boolean().optional(),
220
- discoverSuccess: z.boolean().optional(),
221
- orderSuccess: z.boolean().optional(),
222
- prepareBranchSuccess: z.boolean().optional(),
223
- packageMergeSuccess: z.boolean().optional(),
224
- installSuccess: z.boolean().optional(),
225
- copySuccess: z.boolean().optional(),
226
- mergeSuccess: z.boolean().optional(),
227
- validationSuccess: z.boolean().optional(),
228
- filesCopied: z.number(),
229
- conflictsSkipped: z.number(),
230
- conflictsResolved: z.number(),
231
- })
232
- .optional(),
233
- });
234
-
235
- export const CloneTemplateResultSchema = z.object({
236
- templateDir: z.string(),
237
- commitSha: z.string(),
238
- slug: z.string(),
239
- success: z.boolean().optional(),
240
- error: z.string().optional(),
241
- });
242
-
243
- // Package analysis schemas and types
244
- export const PackageAnalysisSchema = z.object({
245
- name: z.string().optional(),
246
- version: z.string().optional(),
247
- description: z.string().optional(),
248
- dependencies: z.record(z.string()).optional(),
249
- devDependencies: z.record(z.string()).optional(),
250
- peerDependencies: z.record(z.string()).optional(),
251
- scripts: z.record(z.string()).optional(),
252
- success: z.boolean().optional(),
253
- error: z.string().optional(),
254
- });
255
-
256
- // Discovery step schemas and types
257
- export const DiscoveryResultSchema = z.object({
258
- units: z.array(TemplateUnitSchema),
259
- success: z.boolean().optional(),
260
- error: z.string().optional(),
261
- });
262
-
263
- // Unit ordering schemas and types
264
- export const OrderedUnitsSchema = z.object({
265
- orderedUnits: z.array(TemplateUnitSchema),
266
- success: z.boolean().optional(),
267
- error: z.string().optional(),
268
- });
269
-
270
- // Package merge schemas and types
271
- export const PackageMergeInputSchema = z.object({
272
- commitSha: z.string(),
273
- slug: z.string(),
274
- targetPath: z.string().optional(),
275
- packageInfo: PackageAnalysisSchema,
276
- });
277
-
278
- export const PackageMergeResultSchema = z.object({
279
- success: z.boolean(),
280
- applied: z.boolean(),
281
- message: z.string(),
282
- error: z.string().optional(),
283
- });
284
-
285
- // Install schemas and types
286
- export const InstallInputSchema = z.object({
287
- targetPath: z.string().describe('Path to the project to install packages in'),
288
- });
289
-
290
- export const InstallResultSchema = z.object({
291
- success: z.boolean(),
292
- error: z.string().optional(),
293
- });
294
-
295
- export const PrepareBranchInputSchema = z.object({
296
- slug: z.string(),
297
- commitSha: z.string().optional(), // from clone-template if relevant
298
- targetPath: z.string().optional(),
299
- });
300
-
301
- export const PrepareBranchResultSchema = z.object({
302
- branchName: z.string(),
303
- success: z.boolean().optional(),
304
- error: z.string().optional(),
305
- });