@mastra/agent-builder 0.2.4 → 1.0.0-beta.1
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.
- package/CHANGELOG.md +70 -26
- package/dist/agent/index.d.ts +3 -3
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/defaults.d.ts +217 -765
- package/dist/defaults.d.ts.map +1 -1
- package/dist/index.js +110 -106
- package/dist/index.js.map +1 -1
- package/dist/processors/tool-summary.d.ts.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +4 -4
- package/dist/workflows/shared/schema.d.ts +2 -2
- package/dist/workflows/task-planning/schema.d.ts +12 -12
- package/dist/workflows/task-planning/task-planning.d.ts +23 -23
- package/dist/workflows/task-planning/task-planning.d.ts.map +1 -1
- package/dist/workflows/template-builder/template-builder.d.ts +21 -21
- package/dist/workflows/template-builder/template-builder.d.ts.map +1 -1
- package/dist/workflows/workflow-builder/prompts.d.ts +1 -1
- package/dist/workflows/workflow-builder/prompts.d.ts.map +1 -1
- package/dist/workflows/workflow-builder/schema.d.ts +14 -14
- package/dist/workflows/workflow-builder/tools.d.ts +13 -83
- package/dist/workflows/workflow-builder/tools.d.ts.map +1 -1
- package/dist/workflows/workflow-builder/workflow-builder.d.ts +52 -52
- package/dist/workflows/workflow-builder/workflow-builder.d.ts.map +1 -1
- package/package.json +11 -16
package/dist/index.js
CHANGED
|
@@ -501,11 +501,11 @@ async function renameAndCopyFile(sourceFile, targetFile) {
|
|
|
501
501
|
var isValidMastraLanguageModel = (model) => {
|
|
502
502
|
return model && typeof model === "object" && typeof model.modelId === "string";
|
|
503
503
|
};
|
|
504
|
-
var resolveTargetPath = (inputData,
|
|
504
|
+
var resolveTargetPath = (inputData, requestContext) => {
|
|
505
505
|
if (inputData.targetPath) {
|
|
506
506
|
return inputData.targetPath;
|
|
507
507
|
}
|
|
508
|
-
const contextPath =
|
|
508
|
+
const contextPath = requestContext.get("targetPath");
|
|
509
509
|
if (contextPath) {
|
|
510
510
|
return contextPath;
|
|
511
511
|
}
|
|
@@ -674,13 +674,13 @@ var createModelInstance = async (provider, modelId, version = "v2") => {
|
|
|
674
674
|
}
|
|
675
675
|
};
|
|
676
676
|
var resolveModel = async ({
|
|
677
|
-
|
|
677
|
+
requestContext,
|
|
678
678
|
defaultModel = "openai/gpt-4.1",
|
|
679
679
|
projectPath
|
|
680
680
|
}) => {
|
|
681
|
-
const modelFromContext =
|
|
681
|
+
const modelFromContext = requestContext.get("model");
|
|
682
682
|
if (modelFromContext) {
|
|
683
|
-
console.info("Using model from
|
|
683
|
+
console.info("Using model from request context");
|
|
684
684
|
if (isValidMastraLanguageModel(modelFromContext)) {
|
|
685
685
|
return modelFromContext;
|
|
686
686
|
}
|
|
@@ -688,13 +688,13 @@ var resolveModel = async ({
|
|
|
688
688
|
'Invalid model provided. Model must be a MastraLanguageModel instance (e.g., openai("gpt-4"), anthropic("claude-3-5-sonnet"), etc.)'
|
|
689
689
|
);
|
|
690
690
|
}
|
|
691
|
-
const selectedModel =
|
|
691
|
+
const selectedModel = requestContext.get("selectedModel");
|
|
692
692
|
if (selectedModel?.provider && selectedModel?.modelId && projectPath) {
|
|
693
693
|
console.info(`Resolving selected model: ${selectedModel.provider}/${selectedModel.modelId}`);
|
|
694
694
|
const version = await detectAISDKVersion(projectPath);
|
|
695
695
|
const modelInstance = await createModelInstance(selectedModel.provider, selectedModel.modelId, version);
|
|
696
696
|
if (modelInstance) {
|
|
697
|
-
|
|
697
|
+
requestContext.set("model", modelInstance);
|
|
698
698
|
return modelInstance;
|
|
699
699
|
}
|
|
700
700
|
}
|
|
@@ -868,7 +868,7 @@ You have access to an enhanced set of tools based on production coding agent pat
|
|
|
868
868
|
### Task Management
|
|
869
869
|
- **taskManager**: Create and track multi-step coding tasks with states (pending, in_progress, completed, blocked). Use this for complex projects that require systematic progress tracking.
|
|
870
870
|
|
|
871
|
-
### Code Discovery & Analysis
|
|
871
|
+
### Code Discovery & Analysis
|
|
872
872
|
- **codeAnalyzer**: Analyze codebase structure, discover definitions (functions, classes, interfaces), map dependencies, and understand architectural patterns.
|
|
873
873
|
- **smartSearch**: Intelligent search with context awareness, pattern matching, and relevance scoring.
|
|
874
874
|
|
|
@@ -906,12 +906,14 @@ import { LibSQLStore } from '@mastra/libsql';
|
|
|
906
906
|
import { weatherTool } from '../tools/weather-tool';
|
|
907
907
|
|
|
908
908
|
export const weatherAgent = new Agent({
|
|
909
|
+
id: 'weather-agent',
|
|
909
910
|
name: 'Weather Agent',
|
|
910
911
|
instructions: \${instructions},
|
|
911
912
|
model: openai('gpt-4o-mini'),
|
|
912
913
|
tools: { weatherTool },
|
|
913
914
|
memory: new Memory({
|
|
914
915
|
storage: new LibSQLStore({
|
|
916
|
+
id: 'mastra-memory-storage',
|
|
915
917
|
url: 'file:../mastra.db', // ask user what database to use, use this as the default
|
|
916
918
|
}),
|
|
917
919
|
}),
|
|
@@ -940,8 +942,8 @@ export const weatherTool = createTool({
|
|
|
940
942
|
conditions: z.string(),
|
|
941
943
|
location: z.string(),
|
|
942
944
|
}),
|
|
943
|
-
execute: async (
|
|
944
|
-
return await getWeather(
|
|
945
|
+
execute: async (inputData) => {
|
|
946
|
+
return await getWeather(inputData.location);
|
|
945
947
|
},
|
|
946
948
|
});
|
|
947
949
|
\`\`\`
|
|
@@ -959,7 +961,7 @@ const fetchWeather = createStep({
|
|
|
959
961
|
city: z.string().describe('The city to get the weather for'),
|
|
960
962
|
}),
|
|
961
963
|
outputSchema: forecastSchema,
|
|
962
|
-
execute: async (
|
|
964
|
+
execute: async (inputData) => {
|
|
963
965
|
if (!inputData) {
|
|
964
966
|
throw new Error('Input data not found');
|
|
965
967
|
}
|
|
@@ -1013,7 +1015,8 @@ const planActivities = createStep({
|
|
|
1013
1015
|
outputSchema: z.object({
|
|
1014
1016
|
activities: z.string(),
|
|
1015
1017
|
}),
|
|
1016
|
-
execute: async (
|
|
1018
|
+
execute: async (inputData, context) => {
|
|
1019
|
+
const mastra = context?.mastra;
|
|
1017
1020
|
const forecast = inputData;
|
|
1018
1021
|
|
|
1019
1022
|
if (!forecast) {
|
|
@@ -1078,7 +1081,8 @@ export const mastra = new Mastra({
|
|
|
1078
1081
|
workflows: { weatherWorkflow },
|
|
1079
1082
|
agents: { weatherAgent },
|
|
1080
1083
|
storage: new LibSQLStore({
|
|
1081
|
-
|
|
1084
|
+
id: 'mastra-storage',
|
|
1085
|
+
// stores observability, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1082
1086
|
url: ":memory:",
|
|
1083
1087
|
}),
|
|
1084
1088
|
logger: new PinoLogger({
|
|
@@ -1122,8 +1126,8 @@ export const mastra = new Mastra({
|
|
|
1122
1126
|
}).optional(),
|
|
1123
1127
|
error: z.string().optional()
|
|
1124
1128
|
}),
|
|
1125
|
-
execute: async (
|
|
1126
|
-
return await _AgentBuilderDefaults.readFile({ ...
|
|
1129
|
+
execute: async (inputData) => {
|
|
1130
|
+
return await _AgentBuilderDefaults.readFile({ ...inputData, projectPath });
|
|
1127
1131
|
}
|
|
1128
1132
|
}),
|
|
1129
1133
|
writeFile: createTool({
|
|
@@ -1142,8 +1146,8 @@ export const mastra = new Mastra({
|
|
|
1142
1146
|
message: z.string(),
|
|
1143
1147
|
error: z.string().optional()
|
|
1144
1148
|
}),
|
|
1145
|
-
execute: async (
|
|
1146
|
-
return await _AgentBuilderDefaults.writeFile({ ...
|
|
1149
|
+
execute: async (inputData) => {
|
|
1150
|
+
return await _AgentBuilderDefaults.writeFile({ ...inputData, projectPath });
|
|
1147
1151
|
}
|
|
1148
1152
|
}),
|
|
1149
1153
|
listDirectory: createTool({
|
|
@@ -1174,8 +1178,8 @@ export const mastra = new Mastra({
|
|
|
1174
1178
|
message: z.string(),
|
|
1175
1179
|
error: z.string().optional()
|
|
1176
1180
|
}),
|
|
1177
|
-
execute: async (
|
|
1178
|
-
return await _AgentBuilderDefaults.listDirectory({ ...
|
|
1181
|
+
execute: async (inputData) => {
|
|
1182
|
+
return await _AgentBuilderDefaults.listDirectory({ ...inputData, projectPath });
|
|
1179
1183
|
}
|
|
1180
1184
|
}),
|
|
1181
1185
|
executeCommand: createTool({
|
|
@@ -1199,10 +1203,10 @@ export const mastra = new Mastra({
|
|
|
1199
1203
|
executionTime: z.number().optional(),
|
|
1200
1204
|
error: z.string().optional()
|
|
1201
1205
|
}),
|
|
1202
|
-
execute: async (
|
|
1206
|
+
execute: async (inputData) => {
|
|
1203
1207
|
return await _AgentBuilderDefaults.executeCommand({
|
|
1204
|
-
...
|
|
1205
|
-
workingDirectory:
|
|
1208
|
+
...inputData,
|
|
1209
|
+
workingDirectory: inputData.workingDirectory || projectPath
|
|
1206
1210
|
});
|
|
1207
1211
|
}
|
|
1208
1212
|
}),
|
|
@@ -1240,8 +1244,8 @@ export const mastra = new Mastra({
|
|
|
1240
1244
|
),
|
|
1241
1245
|
message: z.string()
|
|
1242
1246
|
}),
|
|
1243
|
-
execute: async (
|
|
1244
|
-
return await _AgentBuilderDefaults.manageTaskList(
|
|
1247
|
+
execute: async (inputData) => {
|
|
1248
|
+
return await _AgentBuilderDefaults.manageTaskList(inputData);
|
|
1245
1249
|
}
|
|
1246
1250
|
}),
|
|
1247
1251
|
// Advanced File Operations
|
|
@@ -1275,8 +1279,8 @@ export const mastra = new Mastra({
|
|
|
1275
1279
|
),
|
|
1276
1280
|
message: z.string()
|
|
1277
1281
|
}),
|
|
1278
|
-
execute: async (
|
|
1279
|
-
return await _AgentBuilderDefaults.performMultiEdit({ ...
|
|
1282
|
+
execute: async (inputData) => {
|
|
1283
|
+
return await _AgentBuilderDefaults.performMultiEdit({ ...inputData, projectPath });
|
|
1280
1284
|
}
|
|
1281
1285
|
}),
|
|
1282
1286
|
replaceLines: createTool({
|
|
@@ -1300,8 +1304,8 @@ export const mastra = new Mastra({
|
|
|
1300
1304
|
backup: z.string().optional(),
|
|
1301
1305
|
error: z.string().optional()
|
|
1302
1306
|
}),
|
|
1303
|
-
execute: async (
|
|
1304
|
-
return await _AgentBuilderDefaults.replaceLines({ ...
|
|
1307
|
+
execute: async (inputData) => {
|
|
1308
|
+
return await _AgentBuilderDefaults.replaceLines({ ...inputData, projectPath });
|
|
1305
1309
|
}
|
|
1306
1310
|
}),
|
|
1307
1311
|
// File diagnostics tool to help debug line replacement issues
|
|
@@ -1329,8 +1333,8 @@ export const mastra = new Mastra({
|
|
|
1329
1333
|
message: z.string(),
|
|
1330
1334
|
error: z.string().optional()
|
|
1331
1335
|
}),
|
|
1332
|
-
execute: async (
|
|
1333
|
-
return await _AgentBuilderDefaults.showFileLines({ ...
|
|
1336
|
+
execute: async (inputData) => {
|
|
1337
|
+
return await _AgentBuilderDefaults.showFileLines({ ...inputData, projectPath });
|
|
1334
1338
|
}
|
|
1335
1339
|
}),
|
|
1336
1340
|
// Enhanced Pattern Search
|
|
@@ -1373,8 +1377,8 @@ export const mastra = new Mastra({
|
|
|
1373
1377
|
patterns: z.array(z.string())
|
|
1374
1378
|
})
|
|
1375
1379
|
}),
|
|
1376
|
-
execute: async (
|
|
1377
|
-
return await _AgentBuilderDefaults.performSmartSearch(
|
|
1380
|
+
execute: async (inputData) => {
|
|
1381
|
+
return await _AgentBuilderDefaults.performSmartSearch(inputData, projectPath);
|
|
1378
1382
|
}
|
|
1379
1383
|
}),
|
|
1380
1384
|
validateCode: createTool({
|
|
@@ -1407,8 +1411,8 @@ export const mastra = new Mastra({
|
|
|
1407
1411
|
validationsFailed: z.array(z.string())
|
|
1408
1412
|
})
|
|
1409
1413
|
}),
|
|
1410
|
-
execute: async (
|
|
1411
|
-
const { projectPath: validationProjectPath, validationType, files } =
|
|
1414
|
+
execute: async (inputData) => {
|
|
1415
|
+
const { projectPath: validationProjectPath, validationType, files } = inputData;
|
|
1412
1416
|
const targetPath = validationProjectPath || projectPath;
|
|
1413
1417
|
return await _AgentBuilderDefaults.validateCode({
|
|
1414
1418
|
projectPath: targetPath,
|
|
@@ -1447,8 +1451,8 @@ export const mastra = new Mastra({
|
|
|
1447
1451
|
suggestions: z.array(z.string()).optional(),
|
|
1448
1452
|
error: z.string().optional()
|
|
1449
1453
|
}),
|
|
1450
|
-
execute: async (
|
|
1451
|
-
return await _AgentBuilderDefaults.webSearch(
|
|
1454
|
+
execute: async (inputData) => {
|
|
1455
|
+
return await _AgentBuilderDefaults.webSearch(inputData);
|
|
1452
1456
|
}
|
|
1453
1457
|
}),
|
|
1454
1458
|
// Task Completion Signaling
|
|
@@ -1477,8 +1481,8 @@ export const mastra = new Mastra({
|
|
|
1477
1481
|
summary: z.string(),
|
|
1478
1482
|
confidence: z.number().min(0).max(100)
|
|
1479
1483
|
}),
|
|
1480
|
-
execute: async (
|
|
1481
|
-
return await _AgentBuilderDefaults.signalCompletion(
|
|
1484
|
+
execute: async (inputData) => {
|
|
1485
|
+
return await _AgentBuilderDefaults.signalCompletion(inputData);
|
|
1482
1486
|
}
|
|
1483
1487
|
}),
|
|
1484
1488
|
manageProject: createTool({
|
|
@@ -1503,8 +1507,8 @@ export const mastra = new Mastra({
|
|
|
1503
1507
|
details: z.string().optional(),
|
|
1504
1508
|
error: z.string().optional()
|
|
1505
1509
|
}),
|
|
1506
|
-
execute: async (
|
|
1507
|
-
const { action, features, packages } =
|
|
1510
|
+
execute: async (inputData) => {
|
|
1511
|
+
const { action, features, packages } = inputData;
|
|
1508
1512
|
try {
|
|
1509
1513
|
switch (action) {
|
|
1510
1514
|
case "create":
|
|
@@ -1565,8 +1569,8 @@ export const mastra = new Mastra({
|
|
|
1565
1569
|
stdout: z.array(z.string()).optional().describe("Server output lines captured during startup"),
|
|
1566
1570
|
error: z.string().optional()
|
|
1567
1571
|
}),
|
|
1568
|
-
execute: async (
|
|
1569
|
-
const { action, port } =
|
|
1572
|
+
execute: async (inputData) => {
|
|
1573
|
+
const { action, port } = inputData;
|
|
1570
1574
|
try {
|
|
1571
1575
|
switch (action) {
|
|
1572
1576
|
case "start":
|
|
@@ -1651,8 +1655,8 @@ export const mastra = new Mastra({
|
|
|
1651
1655
|
url: z.string(),
|
|
1652
1656
|
method: z.string()
|
|
1653
1657
|
}),
|
|
1654
|
-
execute: async (
|
|
1655
|
-
const { method, url, baseUrl, headers, body, timeout } =
|
|
1658
|
+
execute: async (inputData) => {
|
|
1659
|
+
const { method, url, baseUrl, headers, body, timeout } = inputData;
|
|
1656
1660
|
try {
|
|
1657
1661
|
return await _AgentBuilderDefaults.makeHttpRequest({
|
|
1658
1662
|
method,
|
|
@@ -1707,7 +1711,7 @@ export const mastra = new Mastra({
|
|
|
1707
1711
|
/**
|
|
1708
1712
|
* Get tools for a specific mode
|
|
1709
1713
|
*/
|
|
1710
|
-
static async
|
|
1714
|
+
static async listToolsForMode(projectPath, mode = "code-editor") {
|
|
1711
1715
|
const allTools = await _AgentBuilderDefaults.DEFAULT_TOOLS(projectPath);
|
|
1712
1716
|
if (mode === "template") {
|
|
1713
1717
|
return _AgentBuilderDefaults.filterToolsForTemplateBuilder(allTools);
|
|
@@ -3086,7 +3090,8 @@ var ToolSummaryProcessor = class extends MemoryProcessor {
|
|
|
3086
3090
|
constructor({ summaryModel }) {
|
|
3087
3091
|
super({ name: "ToolSummaryProcessor" });
|
|
3088
3092
|
this.summaryAgent = new Agent({
|
|
3089
|
-
|
|
3093
|
+
id: "tool-summary-agent",
|
|
3094
|
+
name: "Tool Summary Agent",
|
|
3090
3095
|
description: "A summary agent that summarizes tool calls and results",
|
|
3091
3096
|
instructions: "You are a summary agent that summarizes tool calls and results",
|
|
3092
3097
|
model: summaryModel
|
|
@@ -3190,7 +3195,7 @@ ${config.instructions}` : "";
|
|
|
3190
3195
|
model: config.model,
|
|
3191
3196
|
tools: async () => {
|
|
3192
3197
|
return {
|
|
3193
|
-
...await AgentBuilderDefaults.
|
|
3198
|
+
...await AgentBuilderDefaults.listToolsForMode(config.projectPath, config.mode),
|
|
3194
3199
|
...config.tools || {}
|
|
3195
3200
|
};
|
|
3196
3201
|
},
|
|
@@ -3214,7 +3219,7 @@ ${config.instructions}` : "";
|
|
|
3214
3219
|
*/
|
|
3215
3220
|
generateLegacy = async (messages, generateOptions = {}) => {
|
|
3216
3221
|
const { maxSteps, ...baseOptions } = generateOptions;
|
|
3217
|
-
const originalInstructions = await this.getInstructions({
|
|
3222
|
+
const originalInstructions = await this.getInstructions({ requestContext: generateOptions?.requestContext });
|
|
3218
3223
|
const additionalInstructions = baseOptions.instructions;
|
|
3219
3224
|
let enhancedInstructions = originalInstructions;
|
|
3220
3225
|
if (additionalInstructions) {
|
|
@@ -3243,7 +3248,7 @@ ${additionalInstructions}`;
|
|
|
3243
3248
|
*/
|
|
3244
3249
|
streamLegacy = async (messages, streamOptions = {}) => {
|
|
3245
3250
|
const { maxSteps, ...baseOptions } = streamOptions;
|
|
3246
|
-
const originalInstructions = await this.getInstructions({
|
|
3251
|
+
const originalInstructions = await this.getInstructions({ requestContext: streamOptions?.requestContext });
|
|
3247
3252
|
const additionalInstructions = baseOptions.instructions;
|
|
3248
3253
|
let enhancedInstructions = originalInstructions;
|
|
3249
3254
|
if (additionalInstructions) {
|
|
@@ -3272,7 +3277,7 @@ ${additionalInstructions}`;
|
|
|
3272
3277
|
*/
|
|
3273
3278
|
async stream(messages, streamOptions) {
|
|
3274
3279
|
const { ...baseOptions } = streamOptions || {};
|
|
3275
|
-
const originalInstructions = await this.getInstructions({
|
|
3280
|
+
const originalInstructions = await this.getInstructions({ requestContext: streamOptions?.requestContext });
|
|
3276
3281
|
const additionalInstructions = baseOptions.instructions;
|
|
3277
3282
|
let enhancedInstructions = originalInstructions;
|
|
3278
3283
|
if (additionalInstructions) {
|
|
@@ -3296,7 +3301,7 @@ ${additionalInstructions}`;
|
|
|
3296
3301
|
}
|
|
3297
3302
|
async generate(messages, options) {
|
|
3298
3303
|
const { ...baseOptions } = options || {};
|
|
3299
|
-
const originalInstructions = await this.getInstructions({
|
|
3304
|
+
const originalInstructions = await this.getInstructions({ requestContext: options?.requestContext });
|
|
3300
3305
|
const additionalInstructions = baseOptions.instructions;
|
|
3301
3306
|
let enhancedInstructions = originalInstructions;
|
|
3302
3307
|
if (additionalInstructions) {
|
|
@@ -3404,14 +3409,15 @@ var discoverUnitsStep = createStep({
|
|
|
3404
3409
|
description: "Discover template units by analyzing the templates directory structure",
|
|
3405
3410
|
inputSchema: CloneTemplateResultSchema,
|
|
3406
3411
|
outputSchema: DiscoveryResultSchema,
|
|
3407
|
-
execute: async ({ inputData,
|
|
3412
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3408
3413
|
const { templateDir } = inputData;
|
|
3409
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3414
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3410
3415
|
const tools = await AgentBuilderDefaults.DEFAULT_TOOLS(templateDir);
|
|
3411
3416
|
console.info("targetPath", targetPath);
|
|
3412
|
-
const model = await resolveModel({
|
|
3417
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
3413
3418
|
try {
|
|
3414
3419
|
const agent = new Agent({
|
|
3420
|
+
id: "mastra-project-discoverer",
|
|
3415
3421
|
model,
|
|
3416
3422
|
instructions: `You are an expert at analyzing Mastra projects.
|
|
3417
3423
|
|
|
@@ -3548,8 +3554,8 @@ var prepareBranchStep = createStep({
|
|
|
3548
3554
|
description: "Create or switch to integration branch before modifications",
|
|
3549
3555
|
inputSchema: PrepareBranchInputSchema,
|
|
3550
3556
|
outputSchema: PrepareBranchResultSchema,
|
|
3551
|
-
execute: async ({ inputData,
|
|
3552
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3557
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3558
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3553
3559
|
try {
|
|
3554
3560
|
const branchName = `feat/install-template-${inputData.slug}`;
|
|
3555
3561
|
await gitCheckoutBranch(branchName, targetPath);
|
|
@@ -3573,10 +3579,10 @@ var packageMergeStep = createStep({
|
|
|
3573
3579
|
description: "Merge template package.json dependencies into target project",
|
|
3574
3580
|
inputSchema: PackageMergeInputSchema,
|
|
3575
3581
|
outputSchema: PackageMergeResultSchema,
|
|
3576
|
-
execute: async ({ inputData,
|
|
3582
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3577
3583
|
console.info("Package merge step starting...");
|
|
3578
3584
|
const { slug, packageInfo } = inputData;
|
|
3579
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3585
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3580
3586
|
try {
|
|
3581
3587
|
const targetPkgPath = join(targetPath, "package.json");
|
|
3582
3588
|
let targetPkgRaw = "{}";
|
|
@@ -3650,9 +3656,9 @@ var installStep = createStep({
|
|
|
3650
3656
|
description: "Install packages based on merged package.json",
|
|
3651
3657
|
inputSchema: InstallInputSchema,
|
|
3652
3658
|
outputSchema: InstallResultSchema,
|
|
3653
|
-
execute: async ({ inputData,
|
|
3659
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3654
3660
|
console.info("Running install step...");
|
|
3655
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3661
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3656
3662
|
try {
|
|
3657
3663
|
await spawnSWPM(targetPath, "install", []);
|
|
3658
3664
|
const lock = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock"].map((f) => join(targetPath, f)).find((f) => existsSync(f));
|
|
@@ -3678,10 +3684,10 @@ var programmaticFileCopyStep = createStep({
|
|
|
3678
3684
|
description: "Programmatically copy template files to target project based on ordered units",
|
|
3679
3685
|
inputSchema: FileCopyInputSchema,
|
|
3680
3686
|
outputSchema: FileCopyResultSchema,
|
|
3681
|
-
execute: async ({ inputData,
|
|
3687
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3682
3688
|
console.info("Programmatic file copy step starting...");
|
|
3683
3689
|
const { orderedUnits, templateDir, commitSha, slug } = inputData;
|
|
3684
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3690
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3685
3691
|
try {
|
|
3686
3692
|
const copiedFiles = [];
|
|
3687
3693
|
const conflicts = [];
|
|
@@ -4030,12 +4036,12 @@ var intelligentMergeStep = createStep({
|
|
|
4030
4036
|
description: "Use AgentBuilder to intelligently merge template files",
|
|
4031
4037
|
inputSchema: IntelligentMergeInputSchema,
|
|
4032
4038
|
outputSchema: IntelligentMergeResultSchema,
|
|
4033
|
-
execute: async ({ inputData,
|
|
4039
|
+
execute: async ({ inputData, requestContext }) => {
|
|
4034
4040
|
console.info("Intelligent merge step starting...");
|
|
4035
4041
|
const { conflicts, copiedFiles, commitSha, slug, templateDir, branchName } = inputData;
|
|
4036
|
-
const targetPath = resolveTargetPath(inputData,
|
|
4042
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
4037
4043
|
try {
|
|
4038
|
-
const model = await resolveModel({
|
|
4044
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
4039
4045
|
const copyFileTool = createTool({
|
|
4040
4046
|
id: "copy-file",
|
|
4041
4047
|
description: "Copy a file from template to target project (use only for edge cases - most files are already copied programmatically).",
|
|
@@ -4048,9 +4054,9 @@ var intelligentMergeStep = createStep({
|
|
|
4048
4054
|
message: z.string(),
|
|
4049
4055
|
error: z.string().optional()
|
|
4050
4056
|
}),
|
|
4051
|
-
execute: async (
|
|
4057
|
+
execute: async (input) => {
|
|
4052
4058
|
try {
|
|
4053
|
-
const { sourcePath, destinationPath } =
|
|
4059
|
+
const { sourcePath, destinationPath } = input;
|
|
4054
4060
|
const resolvedSourcePath = resolve(templateDir, sourcePath);
|
|
4055
4061
|
const resolvedDestinationPath = resolve(targetPath, destinationPath);
|
|
4056
4062
|
if (existsSync(resolvedSourcePath) && !existsSync(dirname(resolvedDestinationPath))) {
|
|
@@ -4298,10 +4304,10 @@ var validationAndFixStep = createStep({
|
|
|
4298
4304
|
description: "Validate the merged template code and fix any issues using a specialized agent",
|
|
4299
4305
|
inputSchema: ValidationFixInputSchema,
|
|
4300
4306
|
outputSchema: ValidationFixResultSchema,
|
|
4301
|
-
execute: async ({ inputData,
|
|
4307
|
+
execute: async ({ inputData, requestContext }) => {
|
|
4302
4308
|
console.info("Validation and fix step starting...");
|
|
4303
4309
|
const { commitSha, slug, orderedUnits, templateDir, copiedFiles, conflictsResolved, maxIterations = 5 } = inputData;
|
|
4304
|
-
const targetPath = resolveTargetPath(inputData,
|
|
4310
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
4305
4311
|
const hasChanges = copiedFiles.length > 0 || conflictsResolved && conflictsResolved.length > 0;
|
|
4306
4312
|
if (!hasChanges) {
|
|
4307
4313
|
console.info("\u23ED\uFE0F Skipping validation - no files copied or conflicts resolved");
|
|
@@ -4321,10 +4327,11 @@ var validationAndFixStep = createStep({
|
|
|
4321
4327
|
);
|
|
4322
4328
|
let currentIteration = 1;
|
|
4323
4329
|
try {
|
|
4324
|
-
const model = await resolveModel({
|
|
4325
|
-
const allTools = await AgentBuilderDefaults.
|
|
4330
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
4331
|
+
const allTools = await AgentBuilderDefaults.listToolsForMode(targetPath, "template");
|
|
4326
4332
|
const validationAgent = new Agent({
|
|
4327
|
-
|
|
4333
|
+
id: "code-validator-fixer",
|
|
4334
|
+
name: "Code Validator Fixer",
|
|
4328
4335
|
description: "Specialized agent for validating and fixing template integration issues",
|
|
4329
4336
|
instructions: `You are a code validation and fixing specialist. Your job is to:
|
|
4330
4337
|
|
|
@@ -4727,7 +4734,7 @@ var agentBuilderTemplateWorkflow = createWorkflow({
|
|
|
4727
4734
|
}).commit();
|
|
4728
4735
|
async function mergeTemplateBySlug(slug, targetPath) {
|
|
4729
4736
|
const template = await getMastraTemplate(slug);
|
|
4730
|
-
const run = await agentBuilderTemplateWorkflow.
|
|
4737
|
+
const run = await agentBuilderTemplateWorkflow.createRun();
|
|
4731
4738
|
return await run.start({
|
|
4732
4739
|
inputData: {
|
|
4733
4740
|
repo: template.githubUrl,
|
|
@@ -5034,7 +5041,7 @@ var planningIterationStep = createStep({
|
|
|
5034
5041
|
outputSchema: PlanningIterationResultSchema,
|
|
5035
5042
|
suspendSchema: PlanningIterationSuspendSchema,
|
|
5036
5043
|
resumeSchema: PlanningIterationResumeSchema,
|
|
5037
|
-
execute: async ({ inputData, resumeData, suspend,
|
|
5044
|
+
execute: async ({ inputData, resumeData, suspend, requestContext }) => {
|
|
5038
5045
|
const {
|
|
5039
5046
|
action,
|
|
5040
5047
|
workflowName,
|
|
@@ -5047,7 +5054,7 @@ var planningIterationStep = createStep({
|
|
|
5047
5054
|
} = inputData;
|
|
5048
5055
|
console.info("Starting planning iteration...");
|
|
5049
5056
|
const qaKey = "workflow-builder-qa";
|
|
5050
|
-
let storedQAPairs =
|
|
5057
|
+
let storedQAPairs = requestContext.get(qaKey) || [];
|
|
5051
5058
|
const newAnswers = { ...userAnswers || {}, ...resumeData?.answers || {} };
|
|
5052
5059
|
if (Object.keys(newAnswers).length > 0) {
|
|
5053
5060
|
storedQAPairs = storedQAPairs.map((pair) => {
|
|
@@ -5060,10 +5067,10 @@ var planningIterationStep = createStep({
|
|
|
5060
5067
|
}
|
|
5061
5068
|
return pair;
|
|
5062
5069
|
});
|
|
5063
|
-
|
|
5070
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5064
5071
|
}
|
|
5065
5072
|
try {
|
|
5066
|
-
const model = await resolveModel({
|
|
5073
|
+
const model = await resolveModel({ requestContext });
|
|
5067
5074
|
const planningAgent = new Agent({
|
|
5068
5075
|
model,
|
|
5069
5076
|
instructions: taskPlanningPrompts.planningAgent.instructions({
|
|
@@ -5094,7 +5101,9 @@ var planningIterationStep = createStep({
|
|
|
5094
5101
|
research
|
|
5095
5102
|
});
|
|
5096
5103
|
const result = await planningAgent.generate(planningPrompt, {
|
|
5097
|
-
|
|
5104
|
+
structuredOutput: {
|
|
5105
|
+
schema: PlanningAgentOutputSchema
|
|
5106
|
+
}
|
|
5098
5107
|
// maxSteps: 15,
|
|
5099
5108
|
});
|
|
5100
5109
|
const planResult = await result.object;
|
|
@@ -5118,7 +5127,7 @@ var planningIterationStep = createStep({
|
|
|
5118
5127
|
answeredAt: null
|
|
5119
5128
|
}));
|
|
5120
5129
|
storedQAPairs = [...storedQAPairs, ...newQAPairs];
|
|
5121
|
-
|
|
5130
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5122
5131
|
console.info(
|
|
5123
5132
|
`Updated Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
|
|
5124
5133
|
);
|
|
@@ -5132,7 +5141,7 @@ var planningIterationStep = createStep({
|
|
|
5132
5141
|
});
|
|
5133
5142
|
}
|
|
5134
5143
|
console.info(`Planning complete with ${planResult.tasks.length} tasks`);
|
|
5135
|
-
|
|
5144
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5136
5145
|
console.info(
|
|
5137
5146
|
`Final Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
|
|
5138
5147
|
);
|
|
@@ -5277,7 +5286,7 @@ const myStep = createStep({
|
|
|
5277
5286
|
- \`mastra\`: Access to Mastra instance (agents, tools, other workflows)
|
|
5278
5287
|
- \`getStepResult(stepInstance)\`: Get results from previous steps
|
|
5279
5288
|
- \`getInitData()\`: Access original workflow input data
|
|
5280
|
-
- \`
|
|
5289
|
+
- \`requestContext\`: Runtime dependency injection context
|
|
5281
5290
|
- \`runCount\`: Number of times this step has run (useful for retries)
|
|
5282
5291
|
|
|
5283
5292
|
### **\u{1F504} CONTROL FLOW METHODS**
|
|
@@ -5356,10 +5365,10 @@ const toolStep = createStep(myTool);
|
|
|
5356
5365
|
|
|
5357
5366
|
// Method 2: Call tool in execute function
|
|
5358
5367
|
const step = createStep({
|
|
5359
|
-
execute: async ({ inputData,
|
|
5368
|
+
execute: async ({ inputData, requestContext }) => {
|
|
5360
5369
|
const result = await myTool.execute({
|
|
5361
5370
|
context: inputData,
|
|
5362
|
-
|
|
5371
|
+
requestContext
|
|
5363
5372
|
});
|
|
5364
5373
|
return result;
|
|
5365
5374
|
}
|
|
@@ -5403,7 +5412,7 @@ export const mastra = new Mastra({
|
|
|
5403
5412
|
sendEmailWorkflow, // Use camelCase for keys
|
|
5404
5413
|
dataProcessingWorkflow
|
|
5405
5414
|
},
|
|
5406
|
-
storage: new LibSQLStore({ url: 'file:./mastra.db' }), // Required for suspend/resume
|
|
5415
|
+
storage: new LibSQLStore({ id: 'mastra-storage', url: 'file:./mastra.db' }), // Required for suspend/resume
|
|
5407
5416
|
});
|
|
5408
5417
|
\`\`\`
|
|
5409
5418
|
|
|
@@ -5451,7 +5460,7 @@ export const mastra = new Mastra({
|
|
|
5451
5460
|
**Running Workflows:**
|
|
5452
5461
|
\`\`\`typescript
|
|
5453
5462
|
// Create and start run
|
|
5454
|
-
const run = await workflow.
|
|
5463
|
+
const run = await workflow.createRun();
|
|
5455
5464
|
const result = await run.start({ inputData: {...} });
|
|
5456
5465
|
|
|
5457
5466
|
// Stream execution for real-time monitoring
|
|
@@ -5475,7 +5484,7 @@ run.watch((event) => console.log(event));
|
|
|
5475
5484
|
- Use workflows as steps: \`.then(otherWorkflow)\`
|
|
5476
5485
|
- Enable complex workflow composition
|
|
5477
5486
|
|
|
5478
|
-
**
|
|
5487
|
+
**Request Context:**
|
|
5479
5488
|
- Pass shared data across all steps
|
|
5480
5489
|
- Enable dependency injection patterns
|
|
5481
5490
|
|
|
@@ -5648,11 +5657,11 @@ var restrictedTaskManager = createTool({
|
|
|
5648
5657
|
),
|
|
5649
5658
|
message: z.string()
|
|
5650
5659
|
}),
|
|
5651
|
-
execute: async (
|
|
5660
|
+
execute: async (input) => {
|
|
5652
5661
|
const adaptedContext = {
|
|
5653
|
-
...
|
|
5654
|
-
action:
|
|
5655
|
-
tasks:
|
|
5662
|
+
...input,
|
|
5663
|
+
action: input.action,
|
|
5664
|
+
tasks: input.tasks?.map((task) => ({
|
|
5656
5665
|
...task,
|
|
5657
5666
|
priority: task.priority || "medium"
|
|
5658
5667
|
}))
|
|
@@ -5667,7 +5676,7 @@ var workflowDiscoveryStep = createStep({
|
|
|
5667
5676
|
description: "Discover existing workflows in the project",
|
|
5668
5677
|
inputSchema: WorkflowBuilderInputSchema,
|
|
5669
5678
|
outputSchema: WorkflowDiscoveryResultSchema,
|
|
5670
|
-
execute: async ({ inputData,
|
|
5679
|
+
execute: async ({ inputData, requestContext: _requestContext }) => {
|
|
5671
5680
|
console.info("Starting workflow discovery...");
|
|
5672
5681
|
const { projectPath = process.cwd() } = inputData;
|
|
5673
5682
|
try {
|
|
@@ -5726,7 +5735,7 @@ var projectDiscoveryStep = createStep({
|
|
|
5726
5735
|
description: "Analyze the project structure and setup",
|
|
5727
5736
|
inputSchema: WorkflowDiscoveryResultSchema,
|
|
5728
5737
|
outputSchema: ProjectDiscoveryResultSchema,
|
|
5729
|
-
execute: async ({ inputData: _inputData,
|
|
5738
|
+
execute: async ({ inputData: _inputData, requestContext: _requestContext }) => {
|
|
5730
5739
|
console.info("Starting project discovery...");
|
|
5731
5740
|
try {
|
|
5732
5741
|
const projectPath = process.cwd();
|
|
@@ -5788,10 +5797,10 @@ var workflowResearchStep = createStep({
|
|
|
5788
5797
|
description: "Research Mastra workflows and gather relevant documentation",
|
|
5789
5798
|
inputSchema: ProjectDiscoveryResultSchema,
|
|
5790
5799
|
outputSchema: WorkflowResearchResultSchema,
|
|
5791
|
-
execute: async ({ inputData,
|
|
5800
|
+
execute: async ({ inputData, requestContext }) => {
|
|
5792
5801
|
console.info("Starting workflow research...");
|
|
5793
5802
|
try {
|
|
5794
|
-
const model = await resolveModel({
|
|
5803
|
+
const model = await resolveModel({ requestContext });
|
|
5795
5804
|
const researchAgent = new Agent({
|
|
5796
5805
|
model,
|
|
5797
5806
|
instructions: workflowBuilderPrompts.researchAgent.instructions,
|
|
@@ -5804,7 +5813,9 @@ var workflowResearchStep = createStep({
|
|
|
5804
5813
|
hasWorkflowsDir: inputData.structure.hasWorkflowsDir
|
|
5805
5814
|
});
|
|
5806
5815
|
const result = await researchAgent.generate(researchPrompt, {
|
|
5807
|
-
|
|
5816
|
+
structuredOutput: {
|
|
5817
|
+
schema: WorkflowResearchResultSchema
|
|
5818
|
+
}
|
|
5808
5819
|
// stopWhen: stepCountIs(10),
|
|
5809
5820
|
});
|
|
5810
5821
|
const researchResult = await result.object;
|
|
@@ -5855,7 +5866,7 @@ var taskExecutionStep = createStep({
|
|
|
5855
5866
|
outputSchema: TaskExecutionResultSchema,
|
|
5856
5867
|
suspendSchema: TaskExecutionSuspendSchema,
|
|
5857
5868
|
resumeSchema: TaskExecutionResumeSchema,
|
|
5858
|
-
execute: async ({ inputData, resumeData, suspend,
|
|
5869
|
+
execute: async ({ inputData, resumeData, suspend, requestContext }) => {
|
|
5859
5870
|
const {
|
|
5860
5871
|
action,
|
|
5861
5872
|
workflowName,
|
|
@@ -5870,7 +5881,7 @@ var taskExecutionStep = createStep({
|
|
|
5870
5881
|
console.info(`Starting task execution for ${action}ing workflow: ${workflowName}`);
|
|
5871
5882
|
console.info(`Executing ${tasks.length} tasks using AgentBuilder stream...`);
|
|
5872
5883
|
try {
|
|
5873
|
-
const model = await resolveModel({
|
|
5884
|
+
const model = await resolveModel({ requestContext });
|
|
5874
5885
|
const currentProjectPath = projectPath || process.cwd();
|
|
5875
5886
|
console.info("Pre-populating taskManager with planned tasks...");
|
|
5876
5887
|
const taskManagerContext = {
|
|
@@ -5915,18 +5926,11 @@ ${workflowBuilderPrompts.validation.instructions}`
|
|
|
5915
5926
|
tasks,
|
|
5916
5927
|
resumeData
|
|
5917
5928
|
});
|
|
5918
|
-
const originalInstructions = await executionAgent.getInstructions({
|
|
5919
|
-
const additionalInstructions = executionAgent.instructions;
|
|
5920
|
-
let enhancedInstructions = originalInstructions;
|
|
5921
|
-
if (additionalInstructions) {
|
|
5922
|
-
enhancedInstructions = `${originalInstructions}
|
|
5923
|
-
|
|
5924
|
-
${additionalInstructions}`;
|
|
5925
|
-
}
|
|
5929
|
+
const originalInstructions = await executionAgent.getInstructions({ requestContext });
|
|
5926
5930
|
const enhancedOptions = {
|
|
5927
5931
|
stopWhen: stepCountIs(100),
|
|
5928
5932
|
temperature: 0.3,
|
|
5929
|
-
instructions:
|
|
5933
|
+
instructions: originalInstructions
|
|
5930
5934
|
};
|
|
5931
5935
|
let finalResult = null;
|
|
5932
5936
|
let allTasksCompleted = false;
|