@mastra/agent-builder 0.0.0-rag-chunk-extract-llm-option-20250926183645 → 0.0.0-remove-unused-model-providers-api-20251030210744
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 +181 -4
- package/dist/agent/index.d.ts +4 -4
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/defaults.d.ts +16 -16
- package/dist/defaults.d.ts.map +1 -1
- package/dist/index.js +84 -105
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +5 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/workflows/task-planning/schema.d.ts +4 -4
- package/dist/workflows/task-planning/task-planning.d.ts +23 -11
- package/dist/workflows/task-planning/task-planning.d.ts.map +1 -1
- package/dist/workflows/template-builder/template-builder.d.ts +100 -20
- 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/schema.d.ts +12 -12
- package/dist/workflows/workflow-builder/tools.d.ts +1 -1
- package/dist/workflows/workflow-builder/workflow-builder.d.ts +68 -36
- package/dist/workflows/workflow-builder/workflow-builder.d.ts.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Agent } from '@mastra/core/agent';
|
|
1
|
+
import { Agent, tryGenerateWithJsonFallback, tryStreamWithJsonFallback } from '@mastra/core/agent';
|
|
2
2
|
import { Memory } from '@mastra/memory';
|
|
3
3
|
import { TokenLimiter } from '@mastra/memory/processors';
|
|
4
4
|
import { exec as exec$1, execFile as execFile$1, spawn as spawn$1 } from 'child_process';
|
|
@@ -10,7 +10,7 @@ import { z } from 'zod';
|
|
|
10
10
|
import { existsSync, readFileSync } from 'fs';
|
|
11
11
|
import { createRequire } from 'module';
|
|
12
12
|
import { promisify } from 'util';
|
|
13
|
-
import {
|
|
13
|
+
import { ModelRouterLanguageModel } from '@mastra/core/llm';
|
|
14
14
|
import { MemoryProcessor } from '@mastra/core/memory';
|
|
15
15
|
import { tmpdir } from 'os';
|
|
16
16
|
import { openai } from '@ai-sdk/openai';
|
|
@@ -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
|
}
|
|
@@ -658,31 +658,9 @@ var createModelInstance = async (provider, modelId, version = "v2") => {
|
|
|
658
658
|
const { google } = await import('@ai-sdk/google');
|
|
659
659
|
return google(modelId);
|
|
660
660
|
}
|
|
661
|
-
},
|
|
662
|
-
v2: {
|
|
663
|
-
openai: async () => {
|
|
664
|
-
const { openai: openai2 } = await import('@ai-sdk/openai-v5');
|
|
665
|
-
return openai2(modelId);
|
|
666
|
-
},
|
|
667
|
-
anthropic: async () => {
|
|
668
|
-
const { anthropic } = await import('@ai-sdk/anthropic-v5');
|
|
669
|
-
return anthropic(modelId);
|
|
670
|
-
},
|
|
671
|
-
groq: async () => {
|
|
672
|
-
const { groq } = await import('@ai-sdk/groq-v5');
|
|
673
|
-
return groq(modelId);
|
|
674
|
-
},
|
|
675
|
-
xai: async () => {
|
|
676
|
-
const { xai } = await import('@ai-sdk/xai-v5');
|
|
677
|
-
return xai(modelId);
|
|
678
|
-
},
|
|
679
|
-
google: async () => {
|
|
680
|
-
const { google } = await import('@ai-sdk/google-v5');
|
|
681
|
-
return google(modelId);
|
|
682
|
-
}
|
|
683
661
|
}
|
|
684
662
|
};
|
|
685
|
-
const providerFn = providerMap[version][provider];
|
|
663
|
+
const providerFn = version === `v1` ? providerMap[version][provider] : () => new ModelRouterLanguageModel(`${provider}/${modelId}`);
|
|
686
664
|
if (!providerFn) {
|
|
687
665
|
console.error(`Unsupported provider: ${provider}`);
|
|
688
666
|
return null;
|
|
@@ -696,13 +674,13 @@ var createModelInstance = async (provider, modelId, version = "v2") => {
|
|
|
696
674
|
}
|
|
697
675
|
};
|
|
698
676
|
var resolveModel = async ({
|
|
699
|
-
|
|
700
|
-
defaultModel = openai
|
|
677
|
+
requestContext,
|
|
678
|
+
defaultModel = "openai/gpt-4.1",
|
|
701
679
|
projectPath
|
|
702
680
|
}) => {
|
|
703
|
-
const modelFromContext =
|
|
681
|
+
const modelFromContext = requestContext.get("model");
|
|
704
682
|
if (modelFromContext) {
|
|
705
|
-
console.info("Using model from
|
|
683
|
+
console.info("Using model from request context");
|
|
706
684
|
if (isValidMastraLanguageModel(modelFromContext)) {
|
|
707
685
|
return modelFromContext;
|
|
708
686
|
}
|
|
@@ -710,18 +688,18 @@ var resolveModel = async ({
|
|
|
710
688
|
'Invalid model provided. Model must be a MastraLanguageModel instance (e.g., openai("gpt-4"), anthropic("claude-3-5-sonnet"), etc.)'
|
|
711
689
|
);
|
|
712
690
|
}
|
|
713
|
-
const selectedModel =
|
|
691
|
+
const selectedModel = requestContext.get("selectedModel");
|
|
714
692
|
if (selectedModel?.provider && selectedModel?.modelId && projectPath) {
|
|
715
693
|
console.info(`Resolving selected model: ${selectedModel.provider}/${selectedModel.modelId}`);
|
|
716
694
|
const version = await detectAISDKVersion(projectPath);
|
|
717
695
|
const modelInstance = await createModelInstance(selectedModel.provider, selectedModel.modelId, version);
|
|
718
696
|
if (modelInstance) {
|
|
719
|
-
|
|
697
|
+
requestContext.set("model", modelInstance);
|
|
720
698
|
return modelInstance;
|
|
721
699
|
}
|
|
722
700
|
}
|
|
723
701
|
console.info("Using default model");
|
|
724
|
-
return defaultModel;
|
|
702
|
+
return typeof defaultModel === `string` ? new ModelRouterLanguageModel(defaultModel) : defaultModel;
|
|
725
703
|
};
|
|
726
704
|
|
|
727
705
|
// src/defaults.ts
|
|
@@ -890,7 +868,7 @@ You have access to an enhanced set of tools based on production coding agent pat
|
|
|
890
868
|
### Task Management
|
|
891
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.
|
|
892
870
|
|
|
893
|
-
### Code Discovery & Analysis
|
|
871
|
+
### Code Discovery & Analysis
|
|
894
872
|
- **codeAnalyzer**: Analyze codebase structure, discover definitions (functions, classes, interfaces), map dependencies, and understand architectural patterns.
|
|
895
873
|
- **smartSearch**: Intelligent search with context awareness, pattern matching, and relevance scoring.
|
|
896
874
|
|
|
@@ -1100,7 +1078,7 @@ export const mastra = new Mastra({
|
|
|
1100
1078
|
workflows: { weatherWorkflow },
|
|
1101
1079
|
agents: { weatherAgent },
|
|
1102
1080
|
storage: new LibSQLStore({
|
|
1103
|
-
// stores
|
|
1081
|
+
// stores observability, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1104
1082
|
url: ":memory:",
|
|
1105
1083
|
}),
|
|
1106
1084
|
logger: new PinoLogger({
|
|
@@ -1729,7 +1707,7 @@ export const mastra = new Mastra({
|
|
|
1729
1707
|
/**
|
|
1730
1708
|
* Get tools for a specific mode
|
|
1731
1709
|
*/
|
|
1732
|
-
static async
|
|
1710
|
+
static async listToolsForMode(projectPath, mode = "code-editor") {
|
|
1733
1711
|
const allTools = await _AgentBuilderDefaults.DEFAULT_TOOLS(projectPath);
|
|
1734
1712
|
if (mode === "template") {
|
|
1735
1713
|
return _AgentBuilderDefaults.filterToolsForTemplateBuilder(allTools);
|
|
@@ -3212,7 +3190,7 @@ ${config.instructions}` : "";
|
|
|
3212
3190
|
model: config.model,
|
|
3213
3191
|
tools: async () => {
|
|
3214
3192
|
return {
|
|
3215
|
-
...await AgentBuilderDefaults.
|
|
3193
|
+
...await AgentBuilderDefaults.listToolsForMode(config.projectPath, config.mode),
|
|
3216
3194
|
...config.tools || {}
|
|
3217
3195
|
};
|
|
3218
3196
|
},
|
|
@@ -3234,9 +3212,9 @@ ${config.instructions}` : "";
|
|
|
3234
3212
|
* Enhanced generate method with AgentBuilder-specific configuration
|
|
3235
3213
|
* Overrides the base Agent generate method to provide additional project context
|
|
3236
3214
|
*/
|
|
3237
|
-
|
|
3215
|
+
generateLegacy = async (messages, generateOptions = {}) => {
|
|
3238
3216
|
const { maxSteps, ...baseOptions } = generateOptions;
|
|
3239
|
-
const originalInstructions = await this.getInstructions({
|
|
3217
|
+
const originalInstructions = await this.getInstructions({ requestContext: generateOptions?.requestContext });
|
|
3240
3218
|
const additionalInstructions = baseOptions.instructions;
|
|
3241
3219
|
let enhancedInstructions = originalInstructions;
|
|
3242
3220
|
if (additionalInstructions) {
|
|
@@ -3257,15 +3235,15 @@ ${additionalInstructions}`;
|
|
|
3257
3235
|
this.logger.debug(`[AgentBuilder:${this.name}] Starting generation with enhanced context`, {
|
|
3258
3236
|
projectPath: this.builderConfig.projectPath
|
|
3259
3237
|
});
|
|
3260
|
-
return super.
|
|
3238
|
+
return super.generateLegacy(messages, enhancedOptions);
|
|
3261
3239
|
};
|
|
3262
3240
|
/**
|
|
3263
3241
|
* Enhanced stream method with AgentBuilder-specific configuration
|
|
3264
3242
|
* Overrides the base Agent stream method to provide additional project context
|
|
3265
3243
|
*/
|
|
3266
|
-
|
|
3244
|
+
streamLegacy = async (messages, streamOptions = {}) => {
|
|
3267
3245
|
const { maxSteps, ...baseOptions } = streamOptions;
|
|
3268
|
-
const originalInstructions = await this.getInstructions({
|
|
3246
|
+
const originalInstructions = await this.getInstructions({ requestContext: streamOptions?.requestContext });
|
|
3269
3247
|
const additionalInstructions = baseOptions.instructions;
|
|
3270
3248
|
let enhancedInstructions = originalInstructions;
|
|
3271
3249
|
if (additionalInstructions) {
|
|
@@ -3286,15 +3264,15 @@ ${additionalInstructions}`;
|
|
|
3286
3264
|
this.logger.debug(`[AgentBuilder:${this.name}] Starting streaming with enhanced context`, {
|
|
3287
3265
|
projectPath: this.builderConfig.projectPath
|
|
3288
3266
|
});
|
|
3289
|
-
return super.
|
|
3267
|
+
return super.streamLegacy(messages, enhancedOptions);
|
|
3290
3268
|
};
|
|
3291
3269
|
/**
|
|
3292
3270
|
* Enhanced stream method with AgentBuilder-specific configuration
|
|
3293
3271
|
* Overrides the base Agent stream method to provide additional project context
|
|
3294
3272
|
*/
|
|
3295
|
-
async
|
|
3273
|
+
async stream(messages, streamOptions) {
|
|
3296
3274
|
const { ...baseOptions } = streamOptions || {};
|
|
3297
|
-
const originalInstructions = await this.getInstructions({
|
|
3275
|
+
const originalInstructions = await this.getInstructions({ requestContext: streamOptions?.requestContext });
|
|
3298
3276
|
const additionalInstructions = baseOptions.instructions;
|
|
3299
3277
|
let enhancedInstructions = originalInstructions;
|
|
3300
3278
|
if (additionalInstructions) {
|
|
@@ -3314,11 +3292,11 @@ ${additionalInstructions}`;
|
|
|
3314
3292
|
this.logger.debug(`[AgentBuilder:${this.name}] Starting streaming with enhanced context`, {
|
|
3315
3293
|
projectPath: this.builderConfig.projectPath
|
|
3316
3294
|
});
|
|
3317
|
-
return super.
|
|
3295
|
+
return super.stream(messages, enhancedOptions);
|
|
3318
3296
|
}
|
|
3319
|
-
async
|
|
3297
|
+
async generate(messages, options) {
|
|
3320
3298
|
const { ...baseOptions } = options || {};
|
|
3321
|
-
const originalInstructions = await this.getInstructions({
|
|
3299
|
+
const originalInstructions = await this.getInstructions({ requestContext: options?.requestContext });
|
|
3322
3300
|
const additionalInstructions = baseOptions.instructions;
|
|
3323
3301
|
let enhancedInstructions = originalInstructions;
|
|
3324
3302
|
if (additionalInstructions) {
|
|
@@ -3338,7 +3316,7 @@ ${additionalInstructions}`;
|
|
|
3338
3316
|
this.logger.debug(`[AgentBuilder:${this.name}] Starting streaming with enhanced context`, {
|
|
3339
3317
|
projectPath: this.builderConfig.projectPath
|
|
3340
3318
|
});
|
|
3341
|
-
return super.
|
|
3319
|
+
return super.generate(messages, enhancedOptions);
|
|
3342
3320
|
}
|
|
3343
3321
|
};
|
|
3344
3322
|
var cloneTemplateStep = createStep({
|
|
@@ -3426,12 +3404,12 @@ var discoverUnitsStep = createStep({
|
|
|
3426
3404
|
description: "Discover template units by analyzing the templates directory structure",
|
|
3427
3405
|
inputSchema: CloneTemplateResultSchema,
|
|
3428
3406
|
outputSchema: DiscoveryResultSchema,
|
|
3429
|
-
execute: async ({ inputData,
|
|
3407
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3430
3408
|
const { templateDir } = inputData;
|
|
3431
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3409
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3432
3410
|
const tools = await AgentBuilderDefaults.DEFAULT_TOOLS(templateDir);
|
|
3433
3411
|
console.info("targetPath", targetPath);
|
|
3434
|
-
const model = await resolveModel({
|
|
3412
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
3435
3413
|
try {
|
|
3436
3414
|
const agent = new Agent({
|
|
3437
3415
|
model,
|
|
@@ -3491,10 +3469,12 @@ Return the actual exported names of the units, as well as the file names.`,
|
|
|
3491
3469
|
networks: z.array(z.object({ name: z.string(), file: z.string() })).optional(),
|
|
3492
3470
|
other: z.array(z.object({ name: z.string(), file: z.string() })).optional()
|
|
3493
3471
|
});
|
|
3494
|
-
const result = isV2 ? await agent
|
|
3495
|
-
|
|
3472
|
+
const result = isV2 ? await tryGenerateWithJsonFallback(agent, prompt, {
|
|
3473
|
+
structuredOutput: {
|
|
3474
|
+
schema: output
|
|
3475
|
+
},
|
|
3496
3476
|
maxSteps: 100
|
|
3497
|
-
}) : await agent.
|
|
3477
|
+
}) : await agent.generateLegacy(prompt, {
|
|
3498
3478
|
experimental_output: output,
|
|
3499
3479
|
maxSteps: 100
|
|
3500
3480
|
});
|
|
@@ -3568,8 +3548,8 @@ var prepareBranchStep = createStep({
|
|
|
3568
3548
|
description: "Create or switch to integration branch before modifications",
|
|
3569
3549
|
inputSchema: PrepareBranchInputSchema,
|
|
3570
3550
|
outputSchema: PrepareBranchResultSchema,
|
|
3571
|
-
execute: async ({ inputData,
|
|
3572
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3551
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3552
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3573
3553
|
try {
|
|
3574
3554
|
const branchName = `feat/install-template-${inputData.slug}`;
|
|
3575
3555
|
await gitCheckoutBranch(branchName, targetPath);
|
|
@@ -3593,10 +3573,10 @@ var packageMergeStep = createStep({
|
|
|
3593
3573
|
description: "Merge template package.json dependencies into target project",
|
|
3594
3574
|
inputSchema: PackageMergeInputSchema,
|
|
3595
3575
|
outputSchema: PackageMergeResultSchema,
|
|
3596
|
-
execute: async ({ inputData,
|
|
3576
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3597
3577
|
console.info("Package merge step starting...");
|
|
3598
3578
|
const { slug, packageInfo } = inputData;
|
|
3599
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3579
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3600
3580
|
try {
|
|
3601
3581
|
const targetPkgPath = join(targetPath, "package.json");
|
|
3602
3582
|
let targetPkgRaw = "{}";
|
|
@@ -3670,9 +3650,9 @@ var installStep = createStep({
|
|
|
3670
3650
|
description: "Install packages based on merged package.json",
|
|
3671
3651
|
inputSchema: InstallInputSchema,
|
|
3672
3652
|
outputSchema: InstallResultSchema,
|
|
3673
|
-
execute: async ({ inputData,
|
|
3653
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3674
3654
|
console.info("Running install step...");
|
|
3675
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3655
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3676
3656
|
try {
|
|
3677
3657
|
await spawnSWPM(targetPath, "install", []);
|
|
3678
3658
|
const lock = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock"].map((f) => join(targetPath, f)).find((f) => existsSync(f));
|
|
@@ -3698,10 +3678,10 @@ var programmaticFileCopyStep = createStep({
|
|
|
3698
3678
|
description: "Programmatically copy template files to target project based on ordered units",
|
|
3699
3679
|
inputSchema: FileCopyInputSchema,
|
|
3700
3680
|
outputSchema: FileCopyResultSchema,
|
|
3701
|
-
execute: async ({ inputData,
|
|
3681
|
+
execute: async ({ inputData, requestContext }) => {
|
|
3702
3682
|
console.info("Programmatic file copy step starting...");
|
|
3703
3683
|
const { orderedUnits, templateDir, commitSha, slug } = inputData;
|
|
3704
|
-
const targetPath = resolveTargetPath(inputData,
|
|
3684
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
3705
3685
|
try {
|
|
3706
3686
|
const copiedFiles = [];
|
|
3707
3687
|
const conflicts = [];
|
|
@@ -4050,12 +4030,12 @@ var intelligentMergeStep = createStep({
|
|
|
4050
4030
|
description: "Use AgentBuilder to intelligently merge template files",
|
|
4051
4031
|
inputSchema: IntelligentMergeInputSchema,
|
|
4052
4032
|
outputSchema: IntelligentMergeResultSchema,
|
|
4053
|
-
execute: async ({ inputData,
|
|
4033
|
+
execute: async ({ inputData, requestContext }) => {
|
|
4054
4034
|
console.info("Intelligent merge step starting...");
|
|
4055
4035
|
const { conflicts, copiedFiles, commitSha, slug, templateDir, branchName } = inputData;
|
|
4056
|
-
const targetPath = resolveTargetPath(inputData,
|
|
4036
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
4057
4037
|
try {
|
|
4058
|
-
const model = await resolveModel({
|
|
4038
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
4059
4039
|
const copyFileTool = createTool({
|
|
4060
4040
|
id: "copy-file",
|
|
4061
4041
|
description: "Copy a file from template to target project (use only for edge cases - most files are already copied programmatically).",
|
|
@@ -4240,7 +4220,7 @@ For each task:
|
|
|
4240
4220
|
Start by listing your tasks and work through them systematically!
|
|
4241
4221
|
`;
|
|
4242
4222
|
const isV2 = model.specificationVersion === "v2";
|
|
4243
|
-
const result = isV2 ? await agentBuilder.
|
|
4223
|
+
const result = isV2 ? await agentBuilder.stream(prompt) : await agentBuilder.streamLegacy(prompt);
|
|
4244
4224
|
const actualResolutions = [];
|
|
4245
4225
|
for await (const chunk of result.fullStream) {
|
|
4246
4226
|
if (chunk.type === "step-finish" || chunk.type === "step-start") {
|
|
@@ -4318,10 +4298,10 @@ var validationAndFixStep = createStep({
|
|
|
4318
4298
|
description: "Validate the merged template code and fix any issues using a specialized agent",
|
|
4319
4299
|
inputSchema: ValidationFixInputSchema,
|
|
4320
4300
|
outputSchema: ValidationFixResultSchema,
|
|
4321
|
-
execute: async ({ inputData,
|
|
4301
|
+
execute: async ({ inputData, requestContext }) => {
|
|
4322
4302
|
console.info("Validation and fix step starting...");
|
|
4323
4303
|
const { commitSha, slug, orderedUnits, templateDir, copiedFiles, conflictsResolved, maxIterations = 5 } = inputData;
|
|
4324
|
-
const targetPath = resolveTargetPath(inputData,
|
|
4304
|
+
const targetPath = resolveTargetPath(inputData, requestContext);
|
|
4325
4305
|
const hasChanges = copiedFiles.length > 0 || conflictsResolved && conflictsResolved.length > 0;
|
|
4326
4306
|
if (!hasChanges) {
|
|
4327
4307
|
console.info("\u23ED\uFE0F Skipping validation - no files copied or conflicts resolved");
|
|
@@ -4341,8 +4321,8 @@ var validationAndFixStep = createStep({
|
|
|
4341
4321
|
);
|
|
4342
4322
|
let currentIteration = 1;
|
|
4343
4323
|
try {
|
|
4344
|
-
const model = await resolveModel({
|
|
4345
|
-
const allTools = await AgentBuilderDefaults.
|
|
4324
|
+
const model = await resolveModel({ requestContext, projectPath: targetPath, defaultModel: openai("gpt-4.1") });
|
|
4325
|
+
const allTools = await AgentBuilderDefaults.listToolsForMode(targetPath, "template");
|
|
4346
4326
|
const validationAgent = new Agent({
|
|
4347
4327
|
name: "code-validator-fixer",
|
|
4348
4328
|
description: "Specialized agent for validating and fixing template integration issues",
|
|
@@ -4482,9 +4462,11 @@ Start by running validateCode with all validation types to get a complete pictur
|
|
|
4482
4462
|
Previous iterations may have fixed some issues, so start by re-running validateCode to see the current state, then fix any remaining issues.`;
|
|
4483
4463
|
const isV2 = model.specificationVersion === "v2";
|
|
4484
4464
|
const output = z.object({ success: z.boolean() });
|
|
4485
|
-
const result = isV2 ? await validationAgent
|
|
4486
|
-
|
|
4487
|
-
|
|
4465
|
+
const result = isV2 ? await tryStreamWithJsonFallback(validationAgent, iterationPrompt, {
|
|
4466
|
+
structuredOutput: {
|
|
4467
|
+
schema: output
|
|
4468
|
+
}
|
|
4469
|
+
}) : await validationAgent.streamLegacy(iterationPrompt, {
|
|
4488
4470
|
experimental_output: output
|
|
4489
4471
|
});
|
|
4490
4472
|
let iterationErrors = 0;
|
|
@@ -5052,7 +5034,7 @@ var planningIterationStep = createStep({
|
|
|
5052
5034
|
outputSchema: PlanningIterationResultSchema,
|
|
5053
5035
|
suspendSchema: PlanningIterationSuspendSchema,
|
|
5054
5036
|
resumeSchema: PlanningIterationResumeSchema,
|
|
5055
|
-
execute: async ({ inputData, resumeData, suspend,
|
|
5037
|
+
execute: async ({ inputData, resumeData, suspend, requestContext }) => {
|
|
5056
5038
|
const {
|
|
5057
5039
|
action,
|
|
5058
5040
|
workflowName,
|
|
@@ -5065,7 +5047,7 @@ var planningIterationStep = createStep({
|
|
|
5065
5047
|
} = inputData;
|
|
5066
5048
|
console.info("Starting planning iteration...");
|
|
5067
5049
|
const qaKey = "workflow-builder-qa";
|
|
5068
|
-
let storedQAPairs =
|
|
5050
|
+
let storedQAPairs = requestContext.get(qaKey) || [];
|
|
5069
5051
|
const newAnswers = { ...userAnswers || {}, ...resumeData?.answers || {} };
|
|
5070
5052
|
if (Object.keys(newAnswers).length > 0) {
|
|
5071
5053
|
storedQAPairs = storedQAPairs.map((pair) => {
|
|
@@ -5078,10 +5060,10 @@ var planningIterationStep = createStep({
|
|
|
5078
5060
|
}
|
|
5079
5061
|
return pair;
|
|
5080
5062
|
});
|
|
5081
|
-
|
|
5063
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5082
5064
|
}
|
|
5083
5065
|
try {
|
|
5084
|
-
const model = await resolveModel({
|
|
5066
|
+
const model = await resolveModel({ requestContext });
|
|
5085
5067
|
const planningAgent = new Agent({
|
|
5086
5068
|
model,
|
|
5087
5069
|
instructions: taskPlanningPrompts.planningAgent.instructions({
|
|
@@ -5111,8 +5093,10 @@ var planningIterationStep = createStep({
|
|
|
5111
5093
|
projectStructure,
|
|
5112
5094
|
research
|
|
5113
5095
|
});
|
|
5114
|
-
const result = await planningAgent.
|
|
5115
|
-
|
|
5096
|
+
const result = await planningAgent.generate(planningPrompt, {
|
|
5097
|
+
structuredOutput: {
|
|
5098
|
+
schema: PlanningAgentOutputSchema
|
|
5099
|
+
}
|
|
5116
5100
|
// maxSteps: 15,
|
|
5117
5101
|
});
|
|
5118
5102
|
const planResult = await result.object;
|
|
@@ -5136,7 +5120,7 @@ var planningIterationStep = createStep({
|
|
|
5136
5120
|
answeredAt: null
|
|
5137
5121
|
}));
|
|
5138
5122
|
storedQAPairs = [...storedQAPairs, ...newQAPairs];
|
|
5139
|
-
|
|
5123
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5140
5124
|
console.info(
|
|
5141
5125
|
`Updated Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
|
|
5142
5126
|
);
|
|
@@ -5150,7 +5134,7 @@ var planningIterationStep = createStep({
|
|
|
5150
5134
|
});
|
|
5151
5135
|
}
|
|
5152
5136
|
console.info(`Planning complete with ${planResult.tasks.length} tasks`);
|
|
5153
|
-
|
|
5137
|
+
requestContext.set(qaKey, storedQAPairs);
|
|
5154
5138
|
console.info(
|
|
5155
5139
|
`Final Q&A state: ${storedQAPairs.length} total question-answer pairs, ${storedQAPairs.filter((p) => p.answer).length} answered`
|
|
5156
5140
|
);
|
|
@@ -5295,7 +5279,7 @@ const myStep = createStep({
|
|
|
5295
5279
|
- \`mastra\`: Access to Mastra instance (agents, tools, other workflows)
|
|
5296
5280
|
- \`getStepResult(stepInstance)\`: Get results from previous steps
|
|
5297
5281
|
- \`getInitData()\`: Access original workflow input data
|
|
5298
|
-
- \`
|
|
5282
|
+
- \`requestContext\`: Runtime dependency injection context
|
|
5299
5283
|
- \`runCount\`: Number of times this step has run (useful for retries)
|
|
5300
5284
|
|
|
5301
5285
|
### **\u{1F504} CONTROL FLOW METHODS**
|
|
@@ -5374,10 +5358,10 @@ const toolStep = createStep(myTool);
|
|
|
5374
5358
|
|
|
5375
5359
|
// Method 2: Call tool in execute function
|
|
5376
5360
|
const step = createStep({
|
|
5377
|
-
execute: async ({ inputData,
|
|
5361
|
+
execute: async ({ inputData, requestContext }) => {
|
|
5378
5362
|
const result = await myTool.execute({
|
|
5379
5363
|
context: inputData,
|
|
5380
|
-
|
|
5364
|
+
requestContext
|
|
5381
5365
|
});
|
|
5382
5366
|
return result;
|
|
5383
5367
|
}
|
|
@@ -5493,7 +5477,7 @@ run.watch((event) => console.log(event));
|
|
|
5493
5477
|
- Use workflows as steps: \`.then(otherWorkflow)\`
|
|
5494
5478
|
- Enable complex workflow composition
|
|
5495
5479
|
|
|
5496
|
-
**
|
|
5480
|
+
**Request Context:**
|
|
5497
5481
|
- Pass shared data across all steps
|
|
5498
5482
|
- Enable dependency injection patterns
|
|
5499
5483
|
|
|
@@ -5685,7 +5669,7 @@ var workflowDiscoveryStep = createStep({
|
|
|
5685
5669
|
description: "Discover existing workflows in the project",
|
|
5686
5670
|
inputSchema: WorkflowBuilderInputSchema,
|
|
5687
5671
|
outputSchema: WorkflowDiscoveryResultSchema,
|
|
5688
|
-
execute: async ({ inputData,
|
|
5672
|
+
execute: async ({ inputData, requestContext: _requestContext }) => {
|
|
5689
5673
|
console.info("Starting workflow discovery...");
|
|
5690
5674
|
const { projectPath = process.cwd() } = inputData;
|
|
5691
5675
|
try {
|
|
@@ -5744,7 +5728,7 @@ var projectDiscoveryStep = createStep({
|
|
|
5744
5728
|
description: "Analyze the project structure and setup",
|
|
5745
5729
|
inputSchema: WorkflowDiscoveryResultSchema,
|
|
5746
5730
|
outputSchema: ProjectDiscoveryResultSchema,
|
|
5747
|
-
execute: async ({ inputData: _inputData,
|
|
5731
|
+
execute: async ({ inputData: _inputData, requestContext: _requestContext }) => {
|
|
5748
5732
|
console.info("Starting project discovery...");
|
|
5749
5733
|
try {
|
|
5750
5734
|
const projectPath = process.cwd();
|
|
@@ -5806,10 +5790,10 @@ var workflowResearchStep = createStep({
|
|
|
5806
5790
|
description: "Research Mastra workflows and gather relevant documentation",
|
|
5807
5791
|
inputSchema: ProjectDiscoveryResultSchema,
|
|
5808
5792
|
outputSchema: WorkflowResearchResultSchema,
|
|
5809
|
-
execute: async ({ inputData,
|
|
5793
|
+
execute: async ({ inputData, requestContext }) => {
|
|
5810
5794
|
console.info("Starting workflow research...");
|
|
5811
5795
|
try {
|
|
5812
|
-
const model = await resolveModel({
|
|
5796
|
+
const model = await resolveModel({ requestContext });
|
|
5813
5797
|
const researchAgent = new Agent({
|
|
5814
5798
|
model,
|
|
5815
5799
|
instructions: workflowBuilderPrompts.researchAgent.instructions,
|
|
@@ -5821,8 +5805,10 @@ var workflowResearchStep = createStep({
|
|
|
5821
5805
|
dependencies: inputData.dependencies,
|
|
5822
5806
|
hasWorkflowsDir: inputData.structure.hasWorkflowsDir
|
|
5823
5807
|
});
|
|
5824
|
-
const result = await researchAgent.
|
|
5825
|
-
|
|
5808
|
+
const result = await researchAgent.generate(researchPrompt, {
|
|
5809
|
+
structuredOutput: {
|
|
5810
|
+
schema: WorkflowResearchResultSchema
|
|
5811
|
+
}
|
|
5826
5812
|
// stopWhen: stepCountIs(10),
|
|
5827
5813
|
});
|
|
5828
5814
|
const researchResult = await result.object;
|
|
@@ -5873,7 +5859,7 @@ var taskExecutionStep = createStep({
|
|
|
5873
5859
|
outputSchema: TaskExecutionResultSchema,
|
|
5874
5860
|
suspendSchema: TaskExecutionSuspendSchema,
|
|
5875
5861
|
resumeSchema: TaskExecutionResumeSchema,
|
|
5876
|
-
execute: async ({ inputData, resumeData, suspend,
|
|
5862
|
+
execute: async ({ inputData, resumeData, suspend, requestContext }) => {
|
|
5877
5863
|
const {
|
|
5878
5864
|
action,
|
|
5879
5865
|
workflowName,
|
|
@@ -5888,7 +5874,7 @@ var taskExecutionStep = createStep({
|
|
|
5888
5874
|
console.info(`Starting task execution for ${action}ing workflow: ${workflowName}`);
|
|
5889
5875
|
console.info(`Executing ${tasks.length} tasks using AgentBuilder stream...`);
|
|
5890
5876
|
try {
|
|
5891
|
-
const model = await resolveModel({
|
|
5877
|
+
const model = await resolveModel({ requestContext });
|
|
5892
5878
|
const currentProjectPath = projectPath || process.cwd();
|
|
5893
5879
|
console.info("Pre-populating taskManager with planned tasks...");
|
|
5894
5880
|
const taskManagerContext = {
|
|
@@ -5933,18 +5919,11 @@ ${workflowBuilderPrompts.validation.instructions}`
|
|
|
5933
5919
|
tasks,
|
|
5934
5920
|
resumeData
|
|
5935
5921
|
});
|
|
5936
|
-
const originalInstructions = await executionAgent.getInstructions({
|
|
5937
|
-
const additionalInstructions = executionAgent.instructions;
|
|
5938
|
-
let enhancedInstructions = originalInstructions;
|
|
5939
|
-
if (additionalInstructions) {
|
|
5940
|
-
enhancedInstructions = `${originalInstructions}
|
|
5941
|
-
|
|
5942
|
-
${additionalInstructions}`;
|
|
5943
|
-
}
|
|
5922
|
+
const originalInstructions = await executionAgent.getInstructions({ requestContext });
|
|
5944
5923
|
const enhancedOptions = {
|
|
5945
5924
|
stopWhen: stepCountIs(100),
|
|
5946
5925
|
temperature: 0.3,
|
|
5947
|
-
instructions:
|
|
5926
|
+
instructions: originalInstructions
|
|
5948
5927
|
};
|
|
5949
5928
|
let finalResult = null;
|
|
5950
5929
|
let allTasksCompleted = false;
|
|
@@ -5973,7 +5952,7 @@ ${additionalInstructions}`;
|
|
|
5973
5952
|
})}
|
|
5974
5953
|
|
|
5975
5954
|
${workflowBuilderPrompts.validation.instructions}`;
|
|
5976
|
-
const stream = await executionAgent.
|
|
5955
|
+
const stream = await executionAgent.stream(iterationPrompt, {
|
|
5977
5956
|
structuredOutput: {
|
|
5978
5957
|
schema: TaskExecutionIterationInputSchema(tasks.length),
|
|
5979
5958
|
model
|