@mastra/agent-builder 0.0.0-monorepo-binary-20251013210052 → 0.0.0-netlify-no-bundle-20251127120354
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 +212 -4
- 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 +163 -137
- package/dist/index.js.map +1 -1
- package/dist/processors/tool-summary.d.ts +10 -5
- 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 +12 -10
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Agent, tryGenerateWithJsonFallback, tryStreamWithJsonFallback } from '@mastra/core/agent';
|
|
2
2
|
import { Memory } from '@mastra/memory';
|
|
3
|
-
import { TokenLimiter } from '@mastra/memory/processors';
|
|
4
3
|
import { exec as exec$1, execFile as execFile$1, spawn as spawn$1 } from 'child_process';
|
|
5
4
|
import { mkdtemp, rm, readFile, writeFile, readdir, mkdir, copyFile, stat } from 'fs/promises';
|
|
6
5
|
import { join, resolve, basename, extname, dirname, isAbsolute, relative } from 'path';
|
|
@@ -11,7 +10,6 @@ import { existsSync, readFileSync } from 'fs';
|
|
|
11
10
|
import { createRequire } from 'module';
|
|
12
11
|
import { promisify } from 'util';
|
|
13
12
|
import { ModelRouterLanguageModel } from '@mastra/core/llm';
|
|
14
|
-
import { MemoryProcessor } from '@mastra/core/memory';
|
|
15
13
|
import { tmpdir } from 'os';
|
|
16
14
|
import { openai } from '@ai-sdk/openai';
|
|
17
15
|
import { createStep, createWorkflow } from '@mastra/core/workflows';
|
|
@@ -501,11 +499,11 @@ async function renameAndCopyFile(sourceFile, targetFile) {
|
|
|
501
499
|
var isValidMastraLanguageModel = (model) => {
|
|
502
500
|
return model && typeof model === "object" && typeof model.modelId === "string";
|
|
503
501
|
};
|
|
504
|
-
var resolveTargetPath = (inputData,
|
|
502
|
+
var resolveTargetPath = (inputData, requestContext) => {
|
|
505
503
|
if (inputData.targetPath) {
|
|
506
504
|
return inputData.targetPath;
|
|
507
505
|
}
|
|
508
|
-
const contextPath =
|
|
506
|
+
const contextPath = requestContext.get("targetPath");
|
|
509
507
|
if (contextPath) {
|
|
510
508
|
return contextPath;
|
|
511
509
|
}
|
|
@@ -674,13 +672,13 @@ var createModelInstance = async (provider, modelId, version = "v2") => {
|
|
|
674
672
|
}
|
|
675
673
|
};
|
|
676
674
|
var resolveModel = async ({
|
|
677
|
-
|
|
675
|
+
requestContext,
|
|
678
676
|
defaultModel = "openai/gpt-4.1",
|
|
679
677
|
projectPath
|
|
680
678
|
}) => {
|
|
681
|
-
const modelFromContext =
|
|
679
|
+
const modelFromContext = requestContext.get("model");
|
|
682
680
|
if (modelFromContext) {
|
|
683
|
-
console.info("Using model from
|
|
681
|
+
console.info("Using model from request context");
|
|
684
682
|
if (isValidMastraLanguageModel(modelFromContext)) {
|
|
685
683
|
return modelFromContext;
|
|
686
684
|
}
|
|
@@ -688,13 +686,13 @@ var resolveModel = async ({
|
|
|
688
686
|
'Invalid model provided. Model must be a MastraLanguageModel instance (e.g., openai("gpt-4"), anthropic("claude-3-5-sonnet"), etc.)'
|
|
689
687
|
);
|
|
690
688
|
}
|
|
691
|
-
const selectedModel =
|
|
689
|
+
const selectedModel = requestContext.get("selectedModel");
|
|
692
690
|
if (selectedModel?.provider && selectedModel?.modelId && projectPath) {
|
|
693
691
|
console.info(`Resolving selected model: ${selectedModel.provider}/${selectedModel.modelId}`);
|
|
694
692
|
const version = await detectAISDKVersion(projectPath);
|
|
695
693
|
const modelInstance = await createModelInstance(selectedModel.provider, selectedModel.modelId, version);
|
|
696
694
|
if (modelInstance) {
|
|
697
|
-
|
|
695
|
+
requestContext.set("model", modelInstance);
|
|
698
696
|
return modelInstance;
|
|
699
697
|
}
|
|
700
698
|
}
|
|
@@ -868,7 +866,7 @@ You have access to an enhanced set of tools based on production coding agent pat
|
|
|
868
866
|
### Task Management
|
|
869
867
|
- **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
868
|
|
|
871
|
-
### Code Discovery & Analysis
|
|
869
|
+
### Code Discovery & Analysis
|
|
872
870
|
- **codeAnalyzer**: Analyze codebase structure, discover definitions (functions, classes, interfaces), map dependencies, and understand architectural patterns.
|
|
873
871
|
- **smartSearch**: Intelligent search with context awareness, pattern matching, and relevance scoring.
|
|
874
872
|
|
|
@@ -906,12 +904,14 @@ import { LibSQLStore } from '@mastra/libsql';
|
|
|
906
904
|
import { weatherTool } from '../tools/weather-tool';
|
|
907
905
|
|
|
908
906
|
export const weatherAgent = new Agent({
|
|
907
|
+
id: 'weather-agent',
|
|
909
908
|
name: 'Weather Agent',
|
|
910
909
|
instructions: \${instructions},
|
|
911
910
|
model: openai('gpt-4o-mini'),
|
|
912
911
|
tools: { weatherTool },
|
|
913
912
|
memory: new Memory({
|
|
914
913
|
storage: new LibSQLStore({
|
|
914
|
+
id: 'mastra-memory-storage',
|
|
915
915
|
url: 'file:../mastra.db', // ask user what database to use, use this as the default
|
|
916
916
|
}),
|
|
917
917
|
}),
|
|
@@ -940,8 +940,8 @@ export const weatherTool = createTool({
|
|
|
940
940
|
conditions: z.string(),
|
|
941
941
|
location: z.string(),
|
|
942
942
|
}),
|
|
943
|
-
execute: async (
|
|
944
|
-
return await getWeather(
|
|
943
|
+
execute: async (inputData) => {
|
|
944
|
+
return await getWeather(inputData.location);
|
|
945
945
|
},
|
|
946
946
|
});
|
|
947
947
|
\`\`\`
|
|
@@ -959,7 +959,7 @@ const fetchWeather = createStep({
|
|
|
959
959
|
city: z.string().describe('The city to get the weather for'),
|
|
960
960
|
}),
|
|
961
961
|
outputSchema: forecastSchema,
|
|
962
|
-
execute: async (
|
|
962
|
+
execute: async (inputData) => {
|
|
963
963
|
if (!inputData) {
|
|
964
964
|
throw new Error('Input data not found');
|
|
965
965
|
}
|
|
@@ -1013,7 +1013,8 @@ const planActivities = createStep({
|
|
|
1013
1013
|
outputSchema: z.object({
|
|
1014
1014
|
activities: z.string(),
|
|
1015
1015
|
}),
|
|
1016
|
-
execute: async (
|
|
1016
|
+
execute: async (inputData, context) => {
|
|
1017
|
+
const mastra = context?.mastra;
|
|
1017
1018
|
const forecast = inputData;
|
|
1018
1019
|
|
|
1019
1020
|
if (!forecast) {
|
|
@@ -1078,7 +1079,8 @@ export const mastra = new Mastra({
|
|
|
1078
1079
|
workflows: { weatherWorkflow },
|
|
1079
1080
|
agents: { weatherAgent },
|
|
1080
1081
|
storage: new LibSQLStore({
|
|
1081
|
-
|
|
1082
|
+
id: 'mastra-storage',
|
|
1083
|
+
// stores observability, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1082
1084
|
url: ":memory:",
|
|
1083
1085
|
}),
|
|
1084
1086
|
logger: new PinoLogger({
|
|
@@ -1122,8 +1124,8 @@ export const mastra = new Mastra({
|
|
|
1122
1124
|
}).optional(),
|
|
1123
1125
|
error: z.string().optional()
|
|
1124
1126
|
}),
|
|
1125
|
-
execute: async (
|
|
1126
|
-
return await _AgentBuilderDefaults.readFile({ ...
|
|
1127
|
+
execute: async (inputData) => {
|
|
1128
|
+
return await _AgentBuilderDefaults.readFile({ ...inputData, projectPath });
|
|
1127
1129
|
}
|
|
1128
1130
|
}),
|
|
1129
1131
|
writeFile: createTool({
|
|
@@ -1142,8 +1144,8 @@ export const mastra = new Mastra({
|
|
|
1142
1144
|
message: z.string(),
|
|
1143
1145
|
error: z.string().optional()
|
|
1144
1146
|
}),
|
|
1145
|
-
execute: async (
|
|
1146
|
-
return await _AgentBuilderDefaults.writeFile({ ...
|
|
1147
|
+
execute: async (inputData) => {
|
|
1148
|
+
return await _AgentBuilderDefaults.writeFile({ ...inputData, projectPath });
|
|
1147
1149
|
}
|
|
1148
1150
|
}),
|
|
1149
1151
|
listDirectory: createTool({
|
|
@@ -1174,8 +1176,8 @@ export const mastra = new Mastra({
|
|
|
1174
1176
|
message: z.string(),
|
|
1175
1177
|
error: z.string().optional()
|
|
1176
1178
|
}),
|
|
1177
|
-
execute: async (
|
|
1178
|
-
return await _AgentBuilderDefaults.listDirectory({ ...
|
|
1179
|
+
execute: async (inputData) => {
|
|
1180
|
+
return await _AgentBuilderDefaults.listDirectory({ ...inputData, projectPath });
|
|
1179
1181
|
}
|
|
1180
1182
|
}),
|
|
1181
1183
|
executeCommand: createTool({
|
|
@@ -1199,10 +1201,10 @@ export const mastra = new Mastra({
|
|
|
1199
1201
|
executionTime: z.number().optional(),
|
|
1200
1202
|
error: z.string().optional()
|
|
1201
1203
|
}),
|
|
1202
|
-
execute: async (
|
|
1204
|
+
execute: async (inputData) => {
|
|
1203
1205
|
return await _AgentBuilderDefaults.executeCommand({
|
|
1204
|
-
...
|
|
1205
|
-
workingDirectory:
|
|
1206
|
+
...inputData,
|
|
1207
|
+
workingDirectory: inputData.workingDirectory || projectPath
|
|
1206
1208
|
});
|
|
1207
1209
|
}
|
|
1208
1210
|
}),
|
|
@@ -1240,8 +1242,8 @@ export const mastra = new Mastra({
|
|
|
1240
1242
|
),
|
|
1241
1243
|
message: z.string()
|
|
1242
1244
|
}),
|
|
1243
|
-
execute: async (
|
|
1244
|
-
return await _AgentBuilderDefaults.manageTaskList(
|
|
1245
|
+
execute: async (inputData) => {
|
|
1246
|
+
return await _AgentBuilderDefaults.manageTaskList(inputData);
|
|
1245
1247
|
}
|
|
1246
1248
|
}),
|
|
1247
1249
|
// Advanced File Operations
|
|
@@ -1275,8 +1277,8 @@ export const mastra = new Mastra({
|
|
|
1275
1277
|
),
|
|
1276
1278
|
message: z.string()
|
|
1277
1279
|
}),
|
|
1278
|
-
execute: async (
|
|
1279
|
-
return await _AgentBuilderDefaults.performMultiEdit({ ...
|
|
1280
|
+
execute: async (inputData) => {
|
|
1281
|
+
return await _AgentBuilderDefaults.performMultiEdit({ ...inputData, projectPath });
|
|
1280
1282
|
}
|
|
1281
1283
|
}),
|
|
1282
1284
|
replaceLines: createTool({
|
|
@@ -1300,8 +1302,8 @@ export const mastra = new Mastra({
|
|
|
1300
1302
|
backup: z.string().optional(),
|
|
1301
1303
|
error: z.string().optional()
|
|
1302
1304
|
}),
|
|
1303
|
-
execute: async (
|
|
1304
|
-
return await _AgentBuilderDefaults.replaceLines({ ...
|
|
1305
|
+
execute: async (inputData) => {
|
|
1306
|
+
return await _AgentBuilderDefaults.replaceLines({ ...inputData, projectPath });
|
|
1305
1307
|
}
|
|
1306
1308
|
}),
|
|
1307
1309
|
// File diagnostics tool to help debug line replacement issues
|
|
@@ -1329,8 +1331,8 @@ export const mastra = new Mastra({
|
|
|
1329
1331
|
message: z.string(),
|
|
1330
1332
|
error: z.string().optional()
|
|
1331
1333
|
}),
|
|
1332
|
-
execute: async (
|
|
1333
|
-
return await _AgentBuilderDefaults.showFileLines({ ...
|
|
1334
|
+
execute: async (inputData) => {
|
|
1335
|
+
return await _AgentBuilderDefaults.showFileLines({ ...inputData, projectPath });
|
|
1334
1336
|
}
|
|
1335
1337
|
}),
|
|
1336
1338
|
// Enhanced Pattern Search
|
|
@@ -1373,8 +1375,8 @@ export const mastra = new Mastra({
|
|
|
1373
1375
|
patterns: z.array(z.string())
|
|
1374
1376
|
})
|
|
1375
1377
|
}),
|
|
1376
|
-
execute: async (
|
|
1377
|
-
return await _AgentBuilderDefaults.performSmartSearch(
|
|
1378
|
+
execute: async (inputData) => {
|
|
1379
|
+
return await _AgentBuilderDefaults.performSmartSearch(inputData, projectPath);
|
|
1378
1380
|
}
|
|
1379
1381
|
}),
|
|
1380
1382
|
validateCode: createTool({
|
|
@@ -1407,8 +1409,8 @@ export const mastra = new Mastra({
|
|
|
1407
1409
|
validationsFailed: z.array(z.string())
|
|
1408
1410
|
})
|
|
1409
1411
|
}),
|
|
1410
|
-
execute: async (
|
|
1411
|
-
const { projectPath: validationProjectPath, validationType, files } =
|
|
1412
|
+
execute: async (inputData) => {
|
|
1413
|
+
const { projectPath: validationProjectPath, validationType, files } = inputData;
|
|
1412
1414
|
const targetPath = validationProjectPath || projectPath;
|
|
1413
1415
|
return await _AgentBuilderDefaults.validateCode({
|
|
1414
1416
|
projectPath: targetPath,
|
|
@@ -1447,8 +1449,8 @@ export const mastra = new Mastra({
|
|
|
1447
1449
|
suggestions: z.array(z.string()).optional(),
|
|
1448
1450
|
error: z.string().optional()
|
|
1449
1451
|
}),
|
|
1450
|
-
execute: async (
|
|
1451
|
-
return await _AgentBuilderDefaults.webSearch(
|
|
1452
|
+
execute: async (inputData) => {
|
|
1453
|
+
return await _AgentBuilderDefaults.webSearch(inputData);
|
|
1452
1454
|
}
|
|
1453
1455
|
}),
|
|
1454
1456
|
// Task Completion Signaling
|
|
@@ -1477,8 +1479,8 @@ export const mastra = new Mastra({
|
|
|
1477
1479
|
summary: z.string(),
|
|
1478
1480
|
confidence: z.number().min(0).max(100)
|
|
1479
1481
|
}),
|
|
1480
|
-
execute: async (
|
|
1481
|
-
return await _AgentBuilderDefaults.signalCompletion(
|
|
1482
|
+
execute: async (inputData) => {
|
|
1483
|
+
return await _AgentBuilderDefaults.signalCompletion(inputData);
|
|
1482
1484
|
}
|
|
1483
1485
|
}),
|
|
1484
1486
|
manageProject: createTool({
|
|
@@ -1503,8 +1505,8 @@ export const mastra = new Mastra({
|
|
|
1503
1505
|
details: z.string().optional(),
|
|
1504
1506
|
error: z.string().optional()
|
|
1505
1507
|
}),
|
|
1506
|
-
execute: async (
|
|
1507
|
-
const { action, features, packages } =
|
|
1508
|
+
execute: async (inputData) => {
|
|
1509
|
+
const { action, features, packages } = inputData;
|
|
1508
1510
|
try {
|
|
1509
1511
|
switch (action) {
|
|
1510
1512
|
case "create":
|
|
@@ -1565,8 +1567,8 @@ export const mastra = new Mastra({
|
|
|
1565
1567
|
stdout: z.array(z.string()).optional().describe("Server output lines captured during startup"),
|
|
1566
1568
|
error: z.string().optional()
|
|
1567
1569
|
}),
|
|
1568
|
-
execute: async (
|
|
1569
|
-
const { action, port } =
|
|
1570
|
+
execute: async (inputData) => {
|
|
1571
|
+
const { action, port } = inputData;
|
|
1570
1572
|
try {
|
|
1571
1573
|
switch (action) {
|
|
1572
1574
|
case "start":
|
|
@@ -1651,8 +1653,8 @@ export const mastra = new Mastra({
|
|
|
1651
1653
|
url: z.string(),
|
|
1652
1654
|
method: z.string()
|
|
1653
1655
|
}),
|
|
1654
|
-
execute: async (
|
|
1655
|
-
const { method, url, baseUrl, headers, body, timeout } =
|
|
1656
|
+
execute: async (inputData) => {
|
|
1657
|
+
const { method, url, baseUrl, headers, body, timeout } = inputData;
|
|
1656
1658
|
try {
|
|
1657
1659
|
return await _AgentBuilderDefaults.makeHttpRequest({
|
|
1658
1660
|
method,
|
|
@@ -1707,7 +1709,7 @@ export const mastra = new Mastra({
|
|
|
1707
1709
|
/**
|
|
1708
1710
|
* Get tools for a specific mode
|
|
1709
1711
|
*/
|
|
1710
|
-
static async
|
|
1712
|
+
static async listToolsForMode(projectPath, mode = "code-editor") {
|
|
1711
1713
|
const allTools = await _AgentBuilderDefaults.DEFAULT_TOOLS(projectPath);
|
|
1712
1714
|
if (mode === "template") {
|
|
1713
1715
|
return _AgentBuilderDefaults.filterToolsForTemplateBuilder(allTools);
|
|
@@ -3080,13 +3082,15 @@ export const mastra = new Mastra({
|
|
|
3080
3082
|
}
|
|
3081
3083
|
}
|
|
3082
3084
|
};
|
|
3083
|
-
var ToolSummaryProcessor = class
|
|
3085
|
+
var ToolSummaryProcessor = class {
|
|
3086
|
+
id = "tool-summary-processor";
|
|
3087
|
+
name = "ToolSummaryProcessor";
|
|
3084
3088
|
summaryAgent;
|
|
3085
3089
|
summaryCache = /* @__PURE__ */ new Map();
|
|
3086
3090
|
constructor({ summaryModel }) {
|
|
3087
|
-
super({ name: "ToolSummaryProcessor" });
|
|
3088
3091
|
this.summaryAgent = new Agent({
|
|
3089
|
-
|
|
3092
|
+
id: "tool-summary-agent",
|
|
3093
|
+
name: "Tool Summary Agent",
|
|
3090
3094
|
description: "A summary agent that summarizes tool calls and results",
|
|
3091
3095
|
instructions: "You are a summary agent that summarizes tool calls and results",
|
|
3092
3096
|
model: summaryModel
|
|
@@ -3120,30 +3124,37 @@ var ToolSummaryProcessor = class extends MemoryProcessor {
|
|
|
3120
3124
|
keys: Array.from(this.summaryCache.keys())
|
|
3121
3125
|
};
|
|
3122
3126
|
}
|
|
3123
|
-
async
|
|
3127
|
+
async processInput({
|
|
3128
|
+
messages,
|
|
3129
|
+
messageList: _messageList
|
|
3130
|
+
}) {
|
|
3124
3131
|
const summaryTasks = [];
|
|
3125
3132
|
for (const message of messages) {
|
|
3126
|
-
if (message.
|
|
3127
|
-
for (
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
(assistantContent) => assistantContent.type === "tool-call" && assistantContent.toolCallId === content.toolCallId
|
|
3132
|
-
)
|
|
3133
|
-
);
|
|
3134
|
-
const toolCall = Array.isArray(assistantMessageWithToolCall?.content) ? assistantMessageWithToolCall?.content.find(
|
|
3135
|
-
(assistantContent) => assistantContent.type === "tool-call" && assistantContent.toolCallId === content.toolCallId
|
|
3136
|
-
) : null;
|
|
3137
|
-
const cacheKey = this.createCacheKey(toolCall);
|
|
3133
|
+
if (message.content.format === 2 && message.content.parts) {
|
|
3134
|
+
for (let partIndex = 0; partIndex < message.content.parts.length; partIndex++) {
|
|
3135
|
+
const part = message.content.parts[partIndex];
|
|
3136
|
+
if (part && part.type === "tool-invocation" && part.toolInvocation?.state === "result") {
|
|
3137
|
+
const cacheKey = this.createCacheKey(part.toolInvocation);
|
|
3138
3138
|
const cachedSummary = this.summaryCache.get(cacheKey);
|
|
3139
3139
|
if (cachedSummary) {
|
|
3140
|
-
content.
|
|
3140
|
+
message.content.parts[partIndex] = {
|
|
3141
|
+
type: "tool-invocation",
|
|
3142
|
+
toolInvocation: {
|
|
3143
|
+
state: "result",
|
|
3144
|
+
step: part.toolInvocation.step,
|
|
3145
|
+
toolCallId: part.toolInvocation.toolCallId,
|
|
3146
|
+
toolName: part.toolInvocation.toolName,
|
|
3147
|
+
args: part.toolInvocation.args,
|
|
3148
|
+
result: `Tool call summary: ${cachedSummary}`
|
|
3149
|
+
}
|
|
3150
|
+
};
|
|
3141
3151
|
} else {
|
|
3142
3152
|
const summaryPromise = this.summaryAgent.generate(
|
|
3143
|
-
`Summarize the following tool call: ${JSON.stringify(
|
|
3153
|
+
`Summarize the following tool call: ${JSON.stringify(part.toolInvocation)}`
|
|
3144
3154
|
);
|
|
3145
3155
|
summaryTasks.push({
|
|
3146
|
-
|
|
3156
|
+
message,
|
|
3157
|
+
partIndex,
|
|
3147
3158
|
promise: summaryPromise,
|
|
3148
3159
|
cacheKey
|
|
3149
3160
|
});
|
|
@@ -3161,10 +3172,24 @@ var ToolSummaryProcessor = class extends MemoryProcessor {
|
|
|
3161
3172
|
const summaryResult = result.value;
|
|
3162
3173
|
const summaryText = summaryResult.text;
|
|
3163
3174
|
this.summaryCache.set(task.cacheKey, summaryText);
|
|
3164
|
-
task.content.
|
|
3175
|
+
if (task.message.content.format === 2 && task.message.content.parts) {
|
|
3176
|
+
const part = task.message.content.parts[task.partIndex];
|
|
3177
|
+
if (part && part.type === "tool-invocation" && part.toolInvocation?.state === "result") {
|
|
3178
|
+
task.message.content.parts[task.partIndex] = {
|
|
3179
|
+
type: "tool-invocation",
|
|
3180
|
+
toolInvocation: {
|
|
3181
|
+
state: "result",
|
|
3182
|
+
step: part.toolInvocation.step,
|
|
3183
|
+
toolCallId: part.toolInvocation.toolCallId,
|
|
3184
|
+
toolName: part.toolInvocation.toolName,
|
|
3185
|
+
args: part.toolInvocation.args,
|
|
3186
|
+
result: `Tool call summary: ${summaryText}`
|
|
3187
|
+
}
|
|
3188
|
+
};
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3165
3191
|
} else if (result.status === "rejected") {
|
|
3166
3192
|
console.warn(`Failed to generate summary for tool call:`, result.reason);
|
|
3167
|
-
task.content.result = `Tool call summary: [Summary generation failed]`;
|
|
3168
3193
|
}
|
|
3169
3194
|
});
|
|
3170
3195
|
}
|
|
@@ -3184,26 +3209,26 @@ var AgentBuilder = class extends Agent {
|
|
|
3184
3209
|
${config.instructions}` : "";
|
|
3185
3210
|
const combinedInstructions = additionalInstructions + AgentBuilderDefaults.DEFAULT_INSTRUCTIONS(config.projectPath);
|
|
3186
3211
|
const agentConfig = {
|
|
3212
|
+
id: "agent-builder",
|
|
3187
3213
|
name: "agent-builder",
|
|
3188
3214
|
description: "An AI agent specialized in generating Mastra agents, tools, and workflows from natural language requirements.",
|
|
3189
3215
|
instructions: combinedInstructions,
|
|
3190
3216
|
model: config.model,
|
|
3191
3217
|
tools: async () => {
|
|
3192
3218
|
return {
|
|
3193
|
-
...await AgentBuilderDefaults.
|
|
3219
|
+
...await AgentBuilderDefaults.listToolsForMode(config.projectPath, config.mode),
|
|
3194
3220
|
...config.tools || {}
|
|
3195
3221
|
};
|
|
3196
3222
|
},
|
|
3197
3223
|
memory: new Memory({
|
|
3198
|
-
options: AgentBuilderDefaults.DEFAULT_MEMORY_CONFIG
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
})
|
|
3224
|
+
options: AgentBuilderDefaults.DEFAULT_MEMORY_CONFIG
|
|
3225
|
+
}),
|
|
3226
|
+
inputProcessors: [
|
|
3227
|
+
// use the write to disk processor to debug the agent's context
|
|
3228
|
+
// new WriteToDiskProcessor({ prefix: 'before-filter' }),
|
|
3229
|
+
new ToolSummaryProcessor({ summaryModel: config.summaryModel || config.model })
|
|
3230
|
+
// new WriteToDiskProcessor({ prefix: 'after-filter' }),
|
|
3231
|
+
]
|
|
3207
3232
|
};
|
|
3208
3233
|
super(agentConfig);
|
|
3209
3234
|
this.builderConfig = config;
|
|
@@ -3214,7 +3239,7 @@ ${config.instructions}` : "";
|
|
|
3214
3239
|
*/
|
|
3215
3240
|
generateLegacy = async (messages, generateOptions = {}) => {
|
|
3216
3241
|
const { maxSteps, ...baseOptions } = generateOptions;
|
|
3217
|
-
const originalInstructions = await this.getInstructions({
|
|
3242
|
+
const originalInstructions = await this.getInstructions({ requestContext: generateOptions?.requestContext });
|
|
3218
3243
|
const additionalInstructions = baseOptions.instructions;
|
|
3219
3244
|
let enhancedInstructions = originalInstructions;
|
|
3220
3245
|
if (additionalInstructions) {
|
|
@@ -3243,7 +3268,7 @@ ${additionalInstructions}`;
|
|
|
3243
3268
|
*/
|
|
3244
3269
|
streamLegacy = async (messages, streamOptions = {}) => {
|
|
3245
3270
|
const { maxSteps, ...baseOptions } = streamOptions;
|
|
3246
|
-
const originalInstructions = await this.getInstructions({
|
|
3271
|
+
const originalInstructions = await this.getInstructions({ requestContext: streamOptions?.requestContext });
|
|
3247
3272
|
const additionalInstructions = baseOptions.instructions;
|
|
3248
3273
|
let enhancedInstructions = originalInstructions;
|
|
3249
3274
|
if (additionalInstructions) {
|
|
@@ -3272,7 +3297,7 @@ ${additionalInstructions}`;
|
|
|
3272
3297
|
*/
|
|
3273
3298
|
async stream(messages, streamOptions) {
|
|
3274
3299
|
const { ...baseOptions } = streamOptions || {};
|
|
3275
|
-
const originalInstructions = await this.getInstructions({
|
|
3300
|
+
const originalInstructions = await this.getInstructions({ requestContext: streamOptions?.requestContext });
|
|
3276
3301
|
const additionalInstructions = baseOptions.instructions;
|
|
3277
3302
|
let enhancedInstructions = originalInstructions;
|
|
3278
3303
|
if (additionalInstructions) {
|
|
@@ -3296,7 +3321,7 @@ ${additionalInstructions}`;
|
|
|
3296
3321
|
}
|
|
3297
3322
|
async generate(messages, options) {
|
|
3298
3323
|
const { ...baseOptions } = options || {};
|
|
3299
|
-
const originalInstructions = await this.getInstructions({
|
|
3324
|
+
const originalInstructions = await this.getInstructions({ requestContext: options?.requestContext });
|
|
3300
3325
|
const additionalInstructions = baseOptions.instructions;
|
|
3301
3326
|
let enhancedInstructions = originalInstructions;
|
|
3302
3327
|
if (additionalInstructions) {
|
|
@@ -3404,14 +3429,15 @@ var discoverUnitsStep = createStep({
|
|
|
3404
3429
|
description: "Discover template units by analyzing the templates directory structure",
|
|
3405
3430
|
inputSchema: CloneTemplateResultSchema,
|
|
3406
3431
|
outputSchema: DiscoveryResultSchema,
|
|
3407
|
-
execute: async ({ inputData,
|
|
3432
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3408
3433
|
const { templateDir } = inputData;
|
|
3409
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3434
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3410
3435
|
const tools = await AgentBuilderDefaults.DEFAULT_TOOLS(templateDir);
|
|
3411
3436
|
console.info("targetPath", targetPath);
|
|
3412
|
-
const model = await resolveModel({
|
|
3437
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
3413
3438
|
try {
|
|
3414
3439
|
const agent = new Agent({
|
|
3440
|
+
id: "mastra-project-discoverer",
|
|
3415
3441
|
model,
|
|
3416
3442
|
instructions: `You are an expert at analyzing Mastra projects.
|
|
3417
3443
|
|
|
@@ -3548,8 +3574,8 @@ var prepareBranchStep = createStep({
|
|
|
3548
3574
|
description: "Create or switch to integration branch before modifications",
|
|
3549
3575
|
inputSchema: PrepareBranchInputSchema,
|
|
3550
3576
|
outputSchema: PrepareBranchResultSchema,
|
|
3551
|
-
execute: async ({ inputData,
|
|
3552
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3577
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3578
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3553
3579
|
try {
|
|
3554
3580
|
const branchName = `feat/install-template-${inputData.slug}`;
|
|
3555
3581
|
await gitCheckoutBranch(branchName, targetPath);
|
|
@@ -3573,10 +3599,10 @@ var packageMergeStep = createStep({
|
|
|
3573
3599
|
description: "Merge template package.json dependencies into target project",
|
|
3574
3600
|
inputSchema: PackageMergeInputSchema,
|
|
3575
3601
|
outputSchema: PackageMergeResultSchema,
|
|
3576
|
-
execute: async ({ inputData,
|
|
3602
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3577
3603
|
console.info("Package merge step starting...");
|
|
3578
3604
|
const { slug, packageInfo } = inputData;
|
|
3579
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3605
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3580
3606
|
try {
|
|
3581
3607
|
const targetPkgPath = join(targetPath, "package.json");
|
|
3582
3608
|
let targetPkgRaw = "{}";
|
|
@@ -3650,9 +3676,9 @@ var installStep = createStep({
|
|
|
3650
3676
|
description: "Install packages based on merged package.json",
|
|
3651
3677
|
inputSchema: InstallInputSchema,
|
|
3652
3678
|
outputSchema: InstallResultSchema,
|
|
3653
|
-
execute: async ({ inputData,
|
|
3679
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3654
3680
|
console.info("Running install step...");
|
|
3655
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3681
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3656
3682
|
try {
|
|
3657
3683
|
await spawnSWPM(targetPath, "install", []);
|
|
3658
3684
|
const lock = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock"].map((f) => join(targetPath, f)).find((f) => existsSync(f));
|
|
@@ -3678,10 +3704,10 @@ var programmaticFileCopyStep = createStep({
|
|
|
3678
3704
|
description: "Programmatically copy template files to target project based on ordered units",
|
|
3679
3705
|
inputSchema: FileCopyInputSchema,
|
|
3680
3706
|
outputSchema: FileCopyResultSchema,
|
|
3681
|
-
execute: async ({ inputData,
|
|
3707
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3682
3708
|
console.info("Programmatic file copy step starting...");
|
|
3683
3709
|
const { orderedUnits, templateDir, commitSha, slug } = inputData;
|
|
3684
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3710
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3685
3711
|
try {
|
|
3686
3712
|
const copiedFiles = [];
|
|
3687
3713
|
const conflicts = [];
|
|
@@ -4030,12 +4056,12 @@ var intelligentMergeStep = createStep({
|
|
|
4030
4056
|
description: "Use AgentBuilder to intelligently merge template files",
|
|
4031
4057
|
inputSchema: IntelligentMergeInputSchema,
|
|
4032
4058
|
outputSchema: IntelligentMergeResultSchema,
|
|
4033
|
-
execute: async ({ inputData,
|
|
4059
|
+
execute: async ({ inputData, requestContext }) => {
|
|
4034
4060
|
console.info("Intelligent merge step starting...");
|
|
4035
4061
|
const { conflicts, copiedFiles, commitSha, slug, templateDir, branchName } = inputData;
|
|
4036
|
-
const targetPath = resolveTargetPath(inputData,
|
|
4062
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
4037
4063
|
try {
|
|
4038
|
-
const model = await resolveModel({
|
|
4064
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
4039
4065
|
const copyFileTool = createTool({
|
|
4040
4066
|
id: "copy-file",
|
|
4041
4067
|
description: "Copy a file from template to target project (use only for edge cases - most files are already copied programmatically).",
|
|
@@ -4048,9 +4074,9 @@ var intelligentMergeStep = createStep({
|
|
|
4048
4074
|
message: z.string(),
|
|
4049
4075
|
error: z.string().optional()
|
|
4050
4076
|
}),
|
|
4051
|
-
execute: async (
|
|
4077
|
+
execute: async (input) => {
|
|
4052
4078
|
try {
|
|
4053
|
-
const { sourcePath, destinationPath } =
|
|
4079
|
+
const { sourcePath, destinationPath } = input;
|
|
4054
4080
|
const resolvedSourcePath = resolve(templateDir, sourcePath);
|
|
4055
4081
|
const resolvedDestinationPath = resolve(targetPath, destinationPath);
|
|
4056
4082
|
if (existsSync(resolvedSourcePath) && !existsSync(dirname(resolvedDestinationPath))) {
|
|
@@ -4298,10 +4324,10 @@ var validationAndFixStep = createStep({
|
|
|
4298
4324
|
description: "Validate the merged template code and fix any issues using a specialized agent",
|
|
4299
4325
|
inputSchema: ValidationFixInputSchema,
|
|
4300
4326
|
outputSchema: ValidationFixResultSchema,
|
|
4301
|
-
execute: async ({ inputData,
|
|
4327
|
+
execute: async ({ inputData, requestContext }) => {
|
|
4302
4328
|
console.info("Validation and fix step starting...");
|
|
4303
4329
|
const { commitSha, slug, orderedUnits, templateDir, copiedFiles, conflictsResolved, maxIterations = 5 } = inputData;
|
|
4304
|
-
const targetPath = resolveTargetPath(inputData,
|
|
4330
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
4305
4331
|
const hasChanges = copiedFiles.length > 0 || conflictsResolved && conflictsResolved.length > 0;
|
|
4306
4332
|
if (!hasChanges) {
|
|
4307
4333
|
console.info("\u23ED\uFE0F Skipping validation - no files copied or conflicts resolved");
|
|
@@ -4321,10 +4347,11 @@ var validationAndFixStep = createStep({
|
|
|
4321
4347
|
);
|
|
4322
4348
|
let currentIteration = 1;
|
|
4323
4349
|
try {
|
|
4324
|
-
const model = await resolveModel({
|
|
4325
|
-
const allTools = await AgentBuilderDefaults.
|
|
4350
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
4351
|
+
const allTools = await AgentBuilderDefaults.listToolsForMode(targetPath, "template");
|
|
4326
4352
|
const validationAgent = new Agent({
|
|
4327
|
-
|
|
4353
|
+
id: "code-validator-fixer",
|
|
4354
|
+
name: "Code Validator Fixer",
|
|
4328
4355
|
description: "Specialized agent for validating and fixing template integration issues",
|
|
4329
4356
|
instructions: `You are a code validation and fixing specialist. Your job is to:
|
|
4330
4357
|
|
|
@@ -4727,7 +4754,7 @@ var agentBuilderTemplateWorkflow = createWorkflow({
|
|
|
4727
4754
|
}).commit();
|
|
4728
4755
|
async function mergeTemplateBySlug(slug, targetPath) {
|
|
4729
4756
|
const template = await getMastraTemplate(slug);
|
|
4730
|
-
const run = await agentBuilderTemplateWorkflow.
|
|
4757
|
+
const run = await agentBuilderTemplateWorkflow.createRun();
|
|
4731
4758
|
return await run.start({
|
|
4732
4759
|
inputData: {
|
|
4733
4760
|
repo: template.githubUrl,
|
|
@@ -5034,7 +5061,7 @@ var planningIterationStep = createStep({
|
|
|
5034
5061
|
outputSchema: PlanningIterationResultSchema,
|
|
5035
5062
|
suspendSchema: PlanningIterationSuspendSchema,
|
|
5036
5063
|
resumeSchema: PlanningIterationResumeSchema,
|
|
5037
|
-
execute: async ({ inputData, resumeData, suspend,
|
|
5064
|
+
execute: async ({ inputData, resumeData, suspend, requestContext }) => {
|
|
5038
5065
|
const {
|
|
5039
5066
|
action,
|
|
5040
5067
|
workflowName,
|
|
@@ -5047,7 +5074,7 @@ var planningIterationStep = createStep({
|
|
|
5047
5074
|
} = inputData;
|
|
5048
5075
|
console.info("Starting planning iteration...");
|
|
5049
5076
|
const qaKey = "workflow-builder-qa";
|
|
5050
|
-
let storedQAPairs =
|
|
5077
|
+
let storedQAPairs = requestContext.get(qaKey) || [];
|
|
5051
5078
|
const newAnswers = { ...userAnswers || {}, ...resumeData?.answers || {} };
|
|
5052
5079
|
if (Object.keys(newAnswers).length > 0) {
|
|
5053
5080
|
storedQAPairs = storedQAPairs.map((pair) => {
|
|
@@ -5060,11 +5087,12 @@ var planningIterationStep = createStep({
|
|
|
5060
5087
|
}
|
|
5061
5088
|
return pair;
|
|
5062
5089
|
});
|
|
5063
|
-
|
|
5090
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5064
5091
|
}
|
|
5065
5092
|
try {
|
|
5066
|
-
const model = await resolveModel({
|
|
5093
|
+
const model = await resolveModel({ requestContext });
|
|
5067
5094
|
const planningAgent = new Agent({
|
|
5095
|
+
id: "workflow-planning-agent",
|
|
5068
5096
|
model,
|
|
5069
5097
|
instructions: taskPlanningPrompts.planningAgent.instructions({
|
|
5070
5098
|
storedQAPairs
|
|
@@ -5094,7 +5122,9 @@ var planningIterationStep = createStep({
|
|
|
5094
5122
|
research
|
|
5095
5123
|
});
|
|
5096
5124
|
const result = await planningAgent.generate(planningPrompt, {
|
|
5097
|
-
|
|
5125
|
+
structuredOutput: {
|
|
5126
|
+
schema: PlanningAgentOutputSchema
|
|
5127
|
+
}
|
|
5098
5128
|
// maxSteps: 15,
|
|
5099
5129
|
});
|
|
5100
5130
|
const planResult = await result.object;
|
|
@@ -5118,7 +5148,7 @@ var planningIterationStep = createStep({
|
|
|
5118
5148
|
answeredAt: null
|
|
5119
5149
|
}));
|
|
5120
5150
|
storedQAPairs = [...storedQAPairs, ...newQAPairs];
|
|
5121
|
-
|
|
5151
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5122
5152
|
console.info(
|
|
5123
5153
|
`Updated Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
|
|
5124
5154
|
);
|
|
@@ -5132,7 +5162,7 @@ var planningIterationStep = createStep({
|
|
|
5132
5162
|
});
|
|
5133
5163
|
}
|
|
5134
5164
|
console.info(`Planning complete with ${planResult.tasks.length} tasks`);
|
|
5135
|
-
|
|
5165
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5136
5166
|
console.info(
|
|
5137
5167
|
`Final Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
|
|
5138
5168
|
);
|
|
@@ -5277,7 +5307,7 @@ const myStep = createStep({
|
|
|
5277
5307
|
- \`mastra\`: Access to Mastra instance (agents, tools, other workflows)
|
|
5278
5308
|
- \`getStepResult(stepInstance)\`: Get results from previous steps
|
|
5279
5309
|
- \`getInitData()\`: Access original workflow input data
|
|
5280
|
-
- \`
|
|
5310
|
+
- \`requestContext\`: Runtime dependency injection context
|
|
5281
5311
|
- \`runCount\`: Number of times this step has run (useful for retries)
|
|
5282
5312
|
|
|
5283
5313
|
### **\u{1F504} CONTROL FLOW METHODS**
|
|
@@ -5356,10 +5386,10 @@ const toolStep = createStep(myTool);
|
|
|
5356
5386
|
|
|
5357
5387
|
// Method 2: Call tool in execute function
|
|
5358
5388
|
const step = createStep({
|
|
5359
|
-
execute: async ({ inputData,
|
|
5389
|
+
execute: async ({ inputData, requestContext }) => {
|
|
5360
5390
|
const result = await myTool.execute({
|
|
5361
5391
|
context: inputData,
|
|
5362
|
-
|
|
5392
|
+
requestContext
|
|
5363
5393
|
});
|
|
5364
5394
|
return result;
|
|
5365
5395
|
}
|
|
@@ -5403,7 +5433,7 @@ export const mastra = new Mastra({
|
|
|
5403
5433
|
sendEmailWorkflow, // Use camelCase for keys
|
|
5404
5434
|
dataProcessingWorkflow
|
|
5405
5435
|
},
|
|
5406
|
-
storage: new LibSQLStore({ url: 'file:./mastra.db' }), // Required for suspend/resume
|
|
5436
|
+
storage: new LibSQLStore({ id: 'mastra-storage', url: 'file:./mastra.db' }), // Required for suspend/resume
|
|
5407
5437
|
});
|
|
5408
5438
|
\`\`\`
|
|
5409
5439
|
|
|
@@ -5451,7 +5481,7 @@ export const mastra = new Mastra({
|
|
|
5451
5481
|
**Running Workflows:**
|
|
5452
5482
|
\`\`\`typescript
|
|
5453
5483
|
// Create and start run
|
|
5454
|
-
const run = await workflow.
|
|
5484
|
+
const run = await workflow.createRun();
|
|
5455
5485
|
const result = await run.start({ inputData: {...} });
|
|
5456
5486
|
|
|
5457
5487
|
// Stream execution for real-time monitoring
|
|
@@ -5475,7 +5505,7 @@ run.watch((event) => console.log(event));
|
|
|
5475
5505
|
- Use workflows as steps: \`.then(otherWorkflow)\`
|
|
5476
5506
|
- Enable complex workflow composition
|
|
5477
5507
|
|
|
5478
|
-
**
|
|
5508
|
+
**Request Context:**
|
|
5479
5509
|
- Pass shared data across all steps
|
|
5480
5510
|
- Enable dependency injection patterns
|
|
5481
5511
|
|
|
@@ -5648,11 +5678,11 @@ var restrictedTaskManager = createTool({
|
|
|
5648
5678
|
),
|
|
5649
5679
|
message: z.string()
|
|
5650
5680
|
}),
|
|
5651
|
-
execute: async (
|
|
5681
|
+
execute: async (input) => {
|
|
5652
5682
|
const adaptedContext = {
|
|
5653
|
-
...
|
|
5654
|
-
action:
|
|
5655
|
-
tasks:
|
|
5683
|
+
...input,
|
|
5684
|
+
action: input.action,
|
|
5685
|
+
tasks: input.tasks?.map((task) => ({
|
|
5656
5686
|
...task,
|
|
5657
5687
|
priority: task.priority || "medium"
|
|
5658
5688
|
}))
|
|
@@ -5667,7 +5697,7 @@ var workflowDiscoveryStep = createStep({
|
|
|
5667
5697
|
description: "Discover existing workflows in the project",
|
|
5668
5698
|
inputSchema: WorkflowBuilderInputSchema,
|
|
5669
5699
|
outputSchema: WorkflowDiscoveryResultSchema,
|
|
5670
|
-
execute: async ({ inputData,
|
|
5700
|
+
execute: async ({ inputData, requestContext: _requestContext }) => {
|
|
5671
5701
|
console.info("Starting workflow discovery...");
|
|
5672
5702
|
const { projectPath = process.cwd() } = inputData;
|
|
5673
5703
|
try {
|
|
@@ -5726,7 +5756,7 @@ var projectDiscoveryStep = createStep({
|
|
|
5726
5756
|
description: "Analyze the project structure and setup",
|
|
5727
5757
|
inputSchema: WorkflowDiscoveryResultSchema,
|
|
5728
5758
|
outputSchema: ProjectDiscoveryResultSchema,
|
|
5729
|
-
execute: async ({ inputData: _inputData,
|
|
5759
|
+
execute: async ({ inputData: _inputData, requestContext: _requestContext }) => {
|
|
5730
5760
|
console.info("Starting project discovery...");
|
|
5731
5761
|
try {
|
|
5732
5762
|
const projectPath = process.cwd();
|
|
@@ -5788,11 +5818,12 @@ var workflowResearchStep = createStep({
|
|
|
5788
5818
|
description: "Research Mastra workflows and gather relevant documentation",
|
|
5789
5819
|
inputSchema: ProjectDiscoveryResultSchema,
|
|
5790
5820
|
outputSchema: WorkflowResearchResultSchema,
|
|
5791
|
-
execute: async ({ inputData,
|
|
5821
|
+
execute: async ({ inputData, requestContext }) => {
|
|
5792
5822
|
console.info("Starting workflow research...");
|
|
5793
5823
|
try {
|
|
5794
|
-
const model = await resolveModel({
|
|
5824
|
+
const model = await resolveModel({ requestContext });
|
|
5795
5825
|
const researchAgent = new Agent({
|
|
5826
|
+
id: "workflow-research-agent",
|
|
5796
5827
|
model,
|
|
5797
5828
|
instructions: workflowBuilderPrompts.researchAgent.instructions,
|
|
5798
5829
|
name: "Workflow Research Agent"
|
|
@@ -5804,7 +5835,9 @@ var workflowResearchStep = createStep({
|
|
|
5804
5835
|
hasWorkflowsDir: inputData.structure.hasWorkflowsDir
|
|
5805
5836
|
});
|
|
5806
5837
|
const result = await researchAgent.generate(researchPrompt, {
|
|
5807
|
-
|
|
5838
|
+
structuredOutput: {
|
|
5839
|
+
schema: WorkflowResearchResultSchema
|
|
5840
|
+
}
|
|
5808
5841
|
// stopWhen: stepCountIs(10),
|
|
5809
5842
|
});
|
|
5810
5843
|
const researchResult = await result.object;
|
|
@@ -5855,7 +5888,7 @@ var taskExecutionStep = createStep({
|
|
|
5855
5888
|
outputSchema: TaskExecutionResultSchema,
|
|
5856
5889
|
suspendSchema: TaskExecutionSuspendSchema,
|
|
5857
5890
|
resumeSchema: TaskExecutionResumeSchema,
|
|
5858
|
-
execute: async ({ inputData, resumeData, suspend,
|
|
5891
|
+
execute: async ({ inputData, resumeData, suspend, requestContext }) => {
|
|
5859
5892
|
const {
|
|
5860
5893
|
action,
|
|
5861
5894
|
workflowName,
|
|
@@ -5870,7 +5903,7 @@ var taskExecutionStep = createStep({
|
|
|
5870
5903
|
console.info(`Starting task execution for ${action}ing workflow: ${workflowName}`);
|
|
5871
5904
|
console.info(`Executing ${tasks.length} tasks using AgentBuilder stream...`);
|
|
5872
5905
|
try {
|
|
5873
|
-
const model = await resolveModel({
|
|
5906
|
+
const model = await resolveModel({ requestContext });
|
|
5874
5907
|
const currentProjectPath = projectPath || process.cwd();
|
|
5875
5908
|
console.info("Pre-populating taskManager with planned tasks...");
|
|
5876
5909
|
const taskManagerContext = {
|
|
@@ -5915,18 +5948,11 @@ ${workflowBuilderPrompts.validation.instructions}`
|
|
|
5915
5948
|
tasks,
|
|
5916
5949
|
resumeData
|
|
5917
5950
|
});
|
|
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
|
-
}
|
|
5951
|
+
const originalInstructions = await executionAgent.getInstructions({ requestContext });
|
|
5926
5952
|
const enhancedOptions = {
|
|
5927
5953
|
stopWhen: stepCountIs(100),
|
|
5928
5954
|
temperature: 0.3,
|
|
5929
|
-
instructions:
|
|
5955
|
+
instructions: originalInstructions
|
|
5930
5956
|
};
|
|
5931
5957
|
let finalResult = null;
|
|
5932
5958
|
let allTasksCompleted = false;
|