@mastra/code-sdk 1.0.3-alpha.0 → 1.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/dist/acp/agent.js +155 -167
- package/dist/acp/agent.js.map +1 -1
- package/dist/acp/event-mapper.js +193 -168
- package/dist/acp/event-mapper.js.map +1 -1
- package/dist/acp/index.js +60 -49
- package/dist/acp/index.js.map +1 -1
- package/dist/acp/server.js +31 -30
- package/dist/acp/server.js.map +1 -1
- package/dist/acp.js +1 -4
- package/dist/agents/credential-resolver.js +40 -29
- package/dist/agents/credential-resolver.js.map +1 -1
- package/dist/agents/custom-provider-source.js +16 -9
- package/dist/agents/custom-provider-source.js.map +1 -1
- package/dist/agents/instructions.js +27 -36
- package/dist/agents/instructions.js.map +1 -1
- package/dist/agents/mastracode-gateway.js +355 -428
- package/dist/agents/mastracode-gateway.js.map +1 -1
- package/dist/agents/memory.js +87 -78
- package/dist/agents/memory.js.map +1 -1
- package/dist/agents/model.js +114 -119
- package/dist/agents/model.js.map +1 -1
- package/dist/agents/modes/build.js +12 -13
- package/dist/agents/modes/build.js.map +1 -1
- package/dist/agents/modes/explore.js +14 -13
- package/dist/agents/modes/explore.js.map +1 -1
- package/dist/agents/modes/plan.js +14 -15
- package/dist/agents/modes/plan.js.map +1 -1
- package/dist/agents/prompts/agent-instructions.js +78 -69
- package/dist/agents/prompts/agent-instructions.js.map +1 -1
- package/dist/agents/prompts/build.js +19 -16
- package/dist/agents/prompts/build.js.map +1 -1
- package/dist/agents/prompts/fast.js +8 -4
- package/dist/agents/prompts/fast.js.map +1 -1
- package/dist/agents/prompts/index.js +48 -47
- package/dist/agents/prompts/index.js.map +1 -1
- package/dist/agents/prompts/model.js +6 -5
- package/dist/agents/prompts/model.js.map +1 -1
- package/dist/agents/prompts/plan.js +20 -16
- package/dist/agents/prompts/plan.js.map +1 -1
- package/dist/agents/prompts/tool-guidance.js +77 -109
- package/dist/agents/prompts/tool-guidance.js.map +1 -1
- package/dist/agents/sandbox-filesystem.js +245 -259
- package/dist/agents/sandbox-filesystem.js.map +1 -1
- package/dist/agents/sandbox-reattach.js +9 -11
- package/dist/agents/sandbox-reattach.js.map +1 -1
- package/dist/agents/thread-caveman-state.js +92 -81
- package/dist/agents/thread-caveman-state.js.map +1 -1
- package/dist/agents/tool-availability.js +62 -80
- package/dist/agents/tool-availability.js.map +1 -1
- package/dist/agents/tools.js +99 -139
- package/dist/agents/tools.js.map +1 -1
- package/dist/agents/workspace.js +232 -225
- package/dist/agents/workspace.js.map +1 -1
- package/dist/analytics.js +139 -128
- package/dist/analytics.js.map +1 -1
- package/dist/auth/authorization-input.js +39 -25
- package/dist/auth/authorization-input.js.map +1 -1
- package/dist/auth/device-code.js +112 -80
- package/dist/auth/device-code.js.map +1 -1
- package/dist/auth/index.js +2 -9
- package/dist/auth/pkce.js +27 -16
- package/dist/auth/pkce.js.map +1 -1
- package/dist/auth/providers/anthropic.js +107 -93
- package/dist/auth/providers/anthropic.js.map +1 -1
- package/dist/auth/providers/github-copilot.js +304 -293
- package/dist/auth/providers/github-copilot.js.map +1 -1
- package/dist/auth/providers/openai-codex.js +442 -460
- package/dist/auth/providers/openai-codex.js.map +1 -1
- package/dist/auth/providers/xai.js +179 -145
- package/dist/auth/providers/xai.js.map +1 -1
- package/dist/auth/storage.js +182 -175
- package/dist/auth/storage.js.map +1 -1
- package/dist/auth/types.js +1 -1
- package/dist/clipboard/index.js +206 -172
- package/dist/clipboard/index.js.map +1 -1
- package/dist/constants.js +11 -16
- package/dist/constants.js.map +1 -1
- package/dist/error-classification.js +19 -11
- package/dist/error-classification.js.map +1 -1
- package/dist/evals/context-builder.js +145 -104
- package/dist/evals/context-builder.js.map +1 -1
- package/dist/evals/index.js +4 -7
- package/dist/evals/scorers/classify-command.js +62 -41
- package/dist/evals/scorers/classify-command.js.map +1 -1
- package/dist/evals/scorers/efficiency.js +239 -181
- package/dist/evals/scorers/efficiency.js.map +1 -1
- package/dist/evals/scorers/extract-tools.js +51 -47
- package/dist/evals/scorers/extract-tools.js.map +1 -1
- package/dist/evals/scorers/index.js +1 -5
- package/dist/evals/scorers/outcome.js +321 -212
- package/dist/evals/scorers/outcome.js.map +1 -1
- package/dist/goal-manager.js +266 -261
- package/dist/goal-manager.js.map +1 -1
- package/dist/goal-signal.js +14 -13
- package/dist/goal-signal.js.map +1 -1
- package/dist/headless/cli.js +153 -154
- package/dist/headless/cli.js.map +1 -1
- package/dist/headless/flags.js +180 -178
- package/dist/headless/flags.js.map +1 -1
- package/dist/headless/format.js +72 -71
- package/dist/headless/format.js.map +1 -1
- package/dist/headless/index.js +5 -31
- package/dist/headless/policy.js +35 -31
- package/dist/headless/policy.js.map +1 -1
- package/dist/headless/run-mc.js +332 -334
- package/dist/headless/run-mc.js.map +1 -1
- package/dist/headless/types.js +16 -7
- package/dist/headless/types.js.map +1 -1
- package/dist/hooks/config.js +56 -61
- package/dist/hooks/config.js.map +1 -1
- package/dist/hooks/executor.js +118 -116
- package/dist/hooks/executor.js.map +1 -1
- package/dist/hooks/index.js +4 -15
- package/dist/hooks/manager.js +221 -280
- package/dist/hooks/manager.js.map +1 -1
- package/dist/hooks/types.js +5 -4
- package/dist/hooks/types.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +632 -712
- package/dist/index.js.map +1 -1
- package/dist/ipc/ipc-reporter.js +19 -22
- package/dist/ipc/ipc-reporter.js.map +1 -1
- package/dist/lsp/client.js +248 -306
- package/dist/lsp/client.js.map +1 -1
- package/dist/lsp/index.js +1 -6
- package/dist/lsp/language.js +39 -43
- package/dist/lsp/language.js.map +1 -1
- package/dist/lsp/manager.js +78 -93
- package/dist/lsp/manager.js.map +1 -1
- package/dist/lsp/server.js +151 -120
- package/dist/lsp/server.js.map +1 -1
- package/dist/lsp/workspace.js +50 -47
- package/dist/lsp/workspace.js.map +1 -1
- package/dist/mcp/config.js +210 -199
- package/dist/mcp/config.js.map +1 -1
- package/dist/mcp/index.js +2 -9
- package/dist/mcp/manager.js +482 -475
- package/dist/mcp/manager.js.map +1 -1
- package/dist/mcp/types.js +1 -1
- package/dist/onboarding/custom-packs.js +14 -17
- package/dist/onboarding/custom-packs.js.map +1 -1
- package/dist/onboarding/custom-providers.js +22 -20
- package/dist/onboarding/custom-providers.js.map +1 -1
- package/dist/onboarding/index.d.ts +1 -1
- package/dist/onboarding/index.d.ts.map +1 -1
- package/dist/onboarding/index.js +3 -21
- package/dist/onboarding/om-settings.d.ts +5 -0
- package/dist/onboarding/om-settings.d.ts.map +1 -1
- package/dist/onboarding/om-settings.js +41 -20
- package/dist/onboarding/om-settings.js.map +1 -1
- package/dist/onboarding/packs.d.ts +4 -6
- package/dist/onboarding/packs.d.ts.map +1 -1
- package/dist/onboarding/packs.js +154 -105
- package/dist/onboarding/packs.js.map +1 -1
- package/dist/onboarding/settings.js +575 -517
- package/dist/onboarding/settings.js.map +1 -1
- package/dist/permissions.js +112 -99
- package/dist/permissions.js.map +1 -1
- package/dist/plugin.js +21 -23
- package/dist/plugin.js.map +1 -1
- package/dist/plugins/dependencies.js +64 -87
- package/dist/plugins/dependencies.js.map +1 -1
- package/dist/plugins/install.js +159 -169
- package/dist/plugins/install.js.map +1 -1
- package/dist/plugins/loader.js +170 -185
- package/dist/plugins/loader.js.map +1 -1
- package/dist/plugins/manager.js +374 -380
- package/dist/plugins/manager.js.map +1 -1
- package/dist/plugins/manifest.js +38 -63
- package/dist/plugins/manifest.js.map +1 -1
- package/dist/plugins/package-link.js +48 -64
- package/dist/plugins/package-link.js.map +1 -1
- package/dist/plugins/paths.js +18 -19
- package/dist/plugins/paths.js.map +1 -1
- package/dist/plugins/registry.js +97 -81
- package/dist/plugins/registry.js.map +1 -1
- package/dist/plugins/scaffold.js +62 -98
- package/dist/plugins/scaffold.js.map +1 -1
- package/dist/plugins/types.js +1 -1
- package/dist/processors/plan-rejection-abort.js +45 -44
- package/dist/processors/plan-rejection-abort.js.map +1 -1
- package/dist/providers/amazon-bedrock-gateway.js +134 -125
- package/dist/providers/amazon-bedrock-gateway.js.map +1 -1
- package/dist/providers/amazon-bedrock.js +68 -47
- package/dist/providers/amazon-bedrock.js.map +1 -1
- package/dist/providers/claude-max.js +153 -133
- package/dist/providers/claude-max.js.map +1 -1
- package/dist/providers/github-copilot.js +232 -230
- package/dist/providers/github-copilot.js.map +1 -1
- package/dist/providers/openai-codex.js +271 -260
- package/dist/providers/openai-codex.js.map +1 -1
- package/dist/providers/xai.js +57 -50
- package/dist/providers/xai.js.map +1 -1
- package/dist/schema.js +91 -89
- package/dist/schema.js.map +1 -1
- package/dist/theme-palette.js +18 -14
- package/dist/theme-palette.js.map +1 -1
- package/dist/tool-names.js +46 -37
- package/dist/tool-names.js.map +1 -1
- package/dist/tools/index.js +2 -8
- package/dist/tools/request-sandbox-access.js +71 -80
- package/dist/tools/request-sandbox-access.js.map +1 -1
- package/dist/tools/utils.js +26 -16
- package/dist/tools/utils.js.map +1 -1
- package/dist/tools/web-search.js +51 -55
- package/dist/tools/web-search.js.map +1 -1
- package/dist/utils/binaries.js +65 -61
- package/dist/utils/binaries.js.map +1 -1
- package/dist/utils/debug-log.js +51 -47
- package/dist/utils/debug-log.js.map +1 -1
- package/dist/utils/errors.js +157 -192
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/gateway-sync.js +49 -37
- package/dist/utils/gateway-sync.js.map +1 -1
- package/dist/utils/path-security.js +7 -6
- package/dist/utils/path-security.js.map +1 -1
- package/dist/utils/plan-diff.js +58 -39
- package/dist/utils/plan-diff.js.map +1 -1
- package/dist/utils/plans.js +92 -74
- package/dist/utils/plans.js.map +1 -1
- package/dist/utils/project.js +318 -256
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/signals-pubsub.js +117 -99
- package/dist/utils/signals-pubsub.js.map +1 -1
- package/dist/utils/slash-command-loader.js +118 -154
- package/dist/utils/slash-command-loader.js.map +1 -1
- package/dist/utils/slash-command-processor.js +92 -83
- package/dist/utils/slash-command-processor.js.map +1 -1
- package/dist/utils/stdin-pipe.js +87 -63
- package/dist/utils/stdin-pipe.js.map +1 -1
- package/dist/utils/storage-factory.js +104 -84
- package/dist/utils/storage-factory.js.map +1 -1
- package/dist/utils/storage-maintenance.js +249 -211
- package/dist/utils/storage-maintenance.js.map +1 -1
- package/dist/utils/thread-lock.js +96 -92
- package/dist/utils/thread-lock.js.map +1 -1
- package/dist/utils/token-estimator.js +12 -12
- package/dist/utils/token-estimator.js.map +1 -1
- package/dist/utils/update-check.d.ts +1 -1
- package/dist/utils/update-check.js +341 -259
- package/dist/utils/update-check.js.map +1 -1
- package/dist/voice/stt-registry.js +131 -113
- package/dist/voice/stt-registry.js.map +1 -1
- package/package.json +11 -11
- package/dist/acp.js.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/types.js.map +0 -1
- package/dist/evals/index.js.map +0 -1
- package/dist/evals/scorers/index.js.map +0 -1
- package/dist/headless/index.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/lsp/index.js.map +0 -1
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/types.js.map +0 -1
- package/dist/onboarding/index.js.map +0 -1
- package/dist/plugins/types.js.map +0 -1
- package/dist/tools/index.js.map +0 -1
package/dist/agents/model.js
CHANGED
|
@@ -1,136 +1,131 @@
|
|
|
1
1
|
import { loadSettings } from "../onboarding/settings.js";
|
|
2
|
+
import { hasCredentialStoreProvider, resolveCredentialStore, resolveTenantFromRequestContext, setCredentialStoreProvider } from "./credential-resolver.js";
|
|
2
3
|
import { AMAZON_BEDROCK_GATEWAY_ID, createAmazonBedrockGateway } from "../providers/amazon-bedrock-gateway.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
MASTRA_GATEWAY_PREFIX,
|
|
7
|
-
MASTRACODE_GATEWAY_ID,
|
|
8
|
-
MastraCodeGateway,
|
|
9
|
-
reloadAuthStorage,
|
|
10
|
-
stripMastraGatewayPrefix
|
|
11
|
-
} from "./mastracode-gateway.js";
|
|
12
|
-
import {
|
|
13
|
-
getAnthropicApiKey,
|
|
14
|
-
getOpenAIApiKey,
|
|
15
|
-
MASTRACODE_GATEWAY_ID as MASTRACODE_GATEWAY_ID2,
|
|
16
|
-
MastraCodeGateway as MastraCodeGateway2,
|
|
17
|
-
remapOpenAIModelForCodexOAuth,
|
|
18
|
-
resolveAuth
|
|
19
|
-
} from "./mastracode-gateway.js";
|
|
20
|
-
import {
|
|
21
|
-
setCredentialStoreProvider,
|
|
22
|
-
hasCredentialStoreProvider,
|
|
23
|
-
resolveTenantFromRequestContext
|
|
24
|
-
} from "./credential-resolver.js";
|
|
25
|
-
import {
|
|
26
|
-
setCustomProvidersSource,
|
|
27
|
-
hasCustomProvidersSource,
|
|
28
|
-
resolveCustomProviders as resolveCustomProviders2
|
|
29
|
-
} from "./custom-provider-source.js";
|
|
4
|
+
import { hasCustomProvidersSource, resolveCustomProviders, setCustomProvidersSource } from "./custom-provider-source.js";
|
|
5
|
+
import { MASTRACODE_GATEWAY_ID, MASTRA_GATEWAY_PREFIX, MastraCodeGateway, getAnthropicApiKey, getOpenAIApiKey, reloadAuthStorage, remapOpenAIModelForCodexOAuth, resolveAuth, stripMastraGatewayPrefix } from "./mastracode-gateway.js";
|
|
6
|
+
//#region src/agents/model.ts
|
|
30
7
|
function getAgentControllerHeaders(requestContext) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
8
|
+
const agentControllerContext = requestContext?.get("controller");
|
|
9
|
+
const headers = {
|
|
10
|
+
...agentControllerContext?.threadId ? { "x-thread-id": agentControllerContext.threadId } : {},
|
|
11
|
+
...agentControllerContext?.resourceId ? { "x-resource-id": agentControllerContext.resourceId } : {}
|
|
12
|
+
};
|
|
13
|
+
return Object.keys(headers).length > 0 ? headers : void 0;
|
|
37
14
|
}
|
|
38
15
|
function createMastraCodeGateway(options) {
|
|
39
|
-
|
|
16
|
+
return new MastraCodeGateway(options);
|
|
40
17
|
}
|
|
41
18
|
function createMastraCodeModelCatalogProvider(gateway) {
|
|
42
|
-
|
|
19
|
+
return gateway instanceof MastraCodeGateway ? gateway.createModelCatalogProvider() : MastraCodeGateway.createModelCatalogProvider(gateway);
|
|
43
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Placeholder for future model ID normalization.
|
|
23
|
+
* Currently returns the input unchanged, but exists as a seam
|
|
24
|
+
* for aliasing, casing fixes, or validation in the future.
|
|
25
|
+
*/
|
|
44
26
|
function resolveModelId(modelId) {
|
|
45
|
-
|
|
27
|
+
return modelId;
|
|
46
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Resolve a model ID to the correct provider instance.
|
|
31
|
+
* Shared by the main agent, observer, and reflector.
|
|
32
|
+
*
|
|
33
|
+
* - For anthropic/* models: Uses stored OAuth credentials when present, otherwise direct API key
|
|
34
|
+
* - For openai/* models: Uses OAuth when configured, otherwise direct API key from AuthStorage
|
|
35
|
+
* - For moonshotai/* models: Uses Moonshot AI Anthropic-compatible endpoint
|
|
36
|
+
* - For all other providers: Uses Mastra's model router (models.dev gateway)
|
|
37
|
+
*/
|
|
47
38
|
function resolveModel(modelId, options) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
headers
|
|
100
|
-
});
|
|
39
|
+
reloadAuthStorage();
|
|
40
|
+
const headers = getAgentControllerHeaders(options?.requestContext);
|
|
41
|
+
const settings = loadSettings();
|
|
42
|
+
const bedrockLegacyPrefix = `${MASTRACODE_GATEWAY_ID}/amazon-bedrock/`;
|
|
43
|
+
const normalizedInput = modelId.startsWith(bedrockLegacyPrefix) ? modelId.slice(MASTRACODE_GATEWAY_ID.length + 1) : modelId;
|
|
44
|
+
const isMastraGatewayModel = normalizedInput.startsWith(MASTRA_GATEWAY_PREFIX);
|
|
45
|
+
const normalizedModelId = stripMastraGatewayPrefix(normalizedInput);
|
|
46
|
+
const [providerId, ...modelParts] = normalizedModelId.split("/");
|
|
47
|
+
const bareModelId = modelParts.join("/");
|
|
48
|
+
if (!providerId || !bareModelId) throw new Error(`Invalid model id: ${modelId}`);
|
|
49
|
+
if (providerId === "amazon-bedrock") {
|
|
50
|
+
const bedrockGateway = createAmazonBedrockGateway();
|
|
51
|
+
const routerId = `${AMAZON_BEDROCK_GATEWAY_ID}/${bareModelId}`;
|
|
52
|
+
const auth = bedrockGateway.resolveAuth({
|
|
53
|
+
gatewayId: AMAZON_BEDROCK_GATEWAY_ID,
|
|
54
|
+
providerId: AMAZON_BEDROCK_GATEWAY_ID,
|
|
55
|
+
modelId: bareModelId,
|
|
56
|
+
routerId
|
|
57
|
+
});
|
|
58
|
+
return bedrockGateway.resolveLanguageModel({
|
|
59
|
+
providerId: AMAZON_BEDROCK_GATEWAY_ID,
|
|
60
|
+
modelId: bareModelId,
|
|
61
|
+
apiKey: auth?.apiKey ?? "",
|
|
62
|
+
headers
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const routerId = `${MASTRACODE_GATEWAY_ID}/${normalizedModelId}`;
|
|
66
|
+
const mgApiKey = MastraCodeGateway.getMastraGatewayApiKey();
|
|
67
|
+
const rawGatewayBase = settings.memoryGateway?.baseUrl ?? process.env["MASTRA_GATEWAY_URL"] ?? "https://gateway-api.mastra.ai";
|
|
68
|
+
const credentialStore = resolveCredentialStore(options?.requestContext);
|
|
69
|
+
const customProviders = resolveCustomProviders(options?.requestContext) ?? settings.customProviders;
|
|
70
|
+
const gateway = createMastraCodeGateway({
|
|
71
|
+
mastraGatewayBaseUrl: rawGatewayBase.replace(/\/+$/, "").replace(/\/v1$/, ""),
|
|
72
|
+
mastraGatewayApiKey: mgApiKey,
|
|
73
|
+
routeThroughMastraGateway: Boolean(mgApiKey && isMastraGatewayModel),
|
|
74
|
+
thinkingLevel: options?.thinkingLevel,
|
|
75
|
+
customProviders,
|
|
76
|
+
credentialStore
|
|
77
|
+
});
|
|
78
|
+
const auth = gateway.resolveAuth({
|
|
79
|
+
gatewayId: MASTRACODE_GATEWAY_ID,
|
|
80
|
+
providerId,
|
|
81
|
+
modelId: bareModelId,
|
|
82
|
+
routerId
|
|
83
|
+
});
|
|
84
|
+
return gateway.resolveLanguageModel({
|
|
85
|
+
providerId,
|
|
86
|
+
modelId: bareModelId,
|
|
87
|
+
apiKey: auth?.apiKey ?? mgApiKey ?? "",
|
|
88
|
+
headers
|
|
89
|
+
});
|
|
101
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Dynamic model function that reads the current model from controller state.
|
|
93
|
+
* This allows runtime model switching via the /models picker.
|
|
94
|
+
*/
|
|
102
95
|
function getDynamicModel({ requestContext }) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
96
|
+
const agentControllerContext = requestContext.get("controller");
|
|
97
|
+
const modelId = agentControllerContext?.session?.modelId;
|
|
98
|
+
if (!modelId) throw new Error("No model selected. Use /models to select a model first.");
|
|
99
|
+
const thinkingLevel = agentControllerContext?.state?.thinkingLevel;
|
|
100
|
+
return resolveModel(modelId, {
|
|
101
|
+
thinkingLevel,
|
|
102
|
+
remapForCodexOAuth: true,
|
|
103
|
+
requestContext
|
|
104
|
+
});
|
|
110
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Goal judge model resolver for the agent's `goal.judge` config. Resolves the
|
|
108
|
+
* configured goal judge model through mastracode's gateway so provider
|
|
109
|
+
* credentials (stored in auth storage, not just env) are injected — a bare model
|
|
110
|
+
* id handed to core's default model router would fail to find the API key.
|
|
111
|
+
*
|
|
112
|
+
* Returns `undefined` when no judge model is configured, which keeps the goal
|
|
113
|
+
* step a complete no-op (the goal mechanism requires a judge to do anything).
|
|
114
|
+
*
|
|
115
|
+
* `settingsPath` must be the same source `createMastraCode()` reads from so the
|
|
116
|
+
* judge model and the goal budget (`goalMaxTurns`) come from one config — with a
|
|
117
|
+
* custom `settingsPath` a bare `loadSettings()` here could read a different file
|
|
118
|
+
* and silently turn the goal step into a no-op.
|
|
119
|
+
*/
|
|
111
120
|
function getGoalJudgeModel({ requestContext }, settingsPath) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
const judgeModelId = loadSettings(settingsPath).models.goalJudgeModel;
|
|
122
|
+
if (!judgeModelId) return void 0;
|
|
123
|
+
return resolveModel(judgeModelId, {
|
|
124
|
+
remapForCodexOAuth: true,
|
|
125
|
+
requestContext
|
|
126
|
+
});
|
|
115
127
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
createMastraCodeGateway,
|
|
120
|
-
createMastraCodeModelCatalogProvider,
|
|
121
|
-
getAnthropicApiKey,
|
|
122
|
-
getDynamicModel,
|
|
123
|
-
getGoalJudgeModel,
|
|
124
|
-
getOpenAIApiKey,
|
|
125
|
-
hasCredentialStoreProvider,
|
|
126
|
-
hasCustomProvidersSource,
|
|
127
|
-
remapOpenAIModelForCodexOAuth,
|
|
128
|
-
resolveAuth,
|
|
129
|
-
resolveCustomProviders2 as resolveCustomProviders,
|
|
130
|
-
resolveModel,
|
|
131
|
-
resolveModelId,
|
|
132
|
-
resolveTenantFromRequestContext,
|
|
133
|
-
setCredentialStoreProvider,
|
|
134
|
-
setCustomProvidersSource
|
|
135
|
-
};
|
|
128
|
+
//#endregion
|
|
129
|
+
export { MASTRACODE_GATEWAY_ID, MastraCodeGateway, createMastraCodeGateway, createMastraCodeModelCatalogProvider, getAnthropicApiKey, getDynamicModel, getGoalJudgeModel, getOpenAIApiKey, hasCredentialStoreProvider, hasCustomProvidersSource, remapOpenAIModelForCodexOAuth, resolveAuth, resolveCustomProviders, resolveModel, resolveModelId, resolveTenantFromRequestContext, setCredentialStoreProvider, setCustomProvidersSource };
|
|
130
|
+
|
|
136
131
|
//# sourceMappingURL=model.js.map
|
package/dist/agents/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/agents/model.ts"],"sourcesContent":["import type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport type { GatewayLanguageModel, MastraModelGatewayInterface } from '@mastra/core/llm';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { loadSettings } from '../onboarding/settings.js';\nimport { AMAZON_BEDROCK_GATEWAY_ID, createAmazonBedrockGateway } from '../providers/amazon-bedrock-gateway.js';\nimport type { ThinkingLevel } from '../providers/openai-codex.js';\nimport { resolveCredentialStore } from './credential-resolver.js';\nimport { resolveCustomProviders } from './custom-provider-source.js';\nimport {\n MASTRA_GATEWAY_PREFIX,\n MASTRACODE_GATEWAY_ID,\n MastraCodeGateway,\n reloadAuthStorage,\n stripMastraGatewayPrefix,\n} from './mastracode-gateway.js';\nimport type { MastraCodeGatewayOptions } from './mastracode-gateway.js';\n\nexport {\n getAnthropicApiKey,\n getOpenAIApiKey,\n MASTRACODE_GATEWAY_ID,\n MastraCodeGateway,\n remapOpenAIModelForCodexOAuth,\n resolveAuth,\n} from './mastracode-gateway.js';\nexport type { MastraCodeCustomProvider, MastraCodeGatewayOptions } from './mastracode-gateway.js';\nexport {\n setCredentialStoreProvider,\n hasCredentialStoreProvider,\n resolveTenantFromRequestContext,\n} from './credential-resolver.js';\nexport type { CredentialTenant, CredentialStoreProvider } from './credential-resolver.js';\nexport {\n setCustomProvidersSource,\n hasCustomProvidersSource,\n resolveCustomProviders,\n} from './custom-provider-source.js';\nexport type { CustomProvidersSource } from './custom-provider-source.js';\n\ntype ResolvedModel = GatewayLanguageModel;\ntype ModelRequestHeaders = Record<string, string>;\n\nfunction getAgentControllerHeaders(requestContext?: RequestContext): ModelRequestHeaders | undefined {\n const agentControllerContext = requestContext?.get('controller') as AgentControllerRequestContext<any> | undefined;\n const headers = {\n ...(agentControllerContext?.threadId ? { 'x-thread-id': agentControllerContext.threadId } : {}),\n ...(agentControllerContext?.resourceId ? { 'x-resource-id': agentControllerContext.resourceId } : {}),\n };\n\n return Object.keys(headers).length > 0 ? headers : undefined;\n}\n\nexport function createMastraCodeGateway(options: MastraCodeGatewayOptions): MastraCodeGateway {\n return new MastraCodeGateway(options);\n}\n\nexport function createMastraCodeModelCatalogProvider(gateway: MastraModelGatewayInterface) {\n return gateway instanceof MastraCodeGateway\n ? gateway.createModelCatalogProvider()\n : MastraCodeGateway.createModelCatalogProvider(gateway);\n}\n\n/**\n * Placeholder for future model ID normalization.\n * Currently returns the input unchanged, but exists as a seam\n * for aliasing, casing fixes, or validation in the future.\n */\nexport function resolveModelId(modelId: string): string {\n return modelId;\n}\n\n/**\n * Resolve a model ID to the correct provider instance.\n * Shared by the main agent, observer, and reflector.\n *\n * - For anthropic/* models: Uses stored OAuth credentials when present, otherwise direct API key\n * - For openai/* models: Uses OAuth when configured, otherwise direct API key from AuthStorage\n * - For moonshotai/* models: Uses Moonshot AI Anthropic-compatible endpoint\n * - For all other providers: Uses Mastra's model router (models.dev gateway)\n */\nexport function resolveModel(\n modelId: string,\n options?: { thinkingLevel?: ThinkingLevel; remapForCodexOAuth?: boolean; requestContext?: RequestContext },\n): GatewayLanguageModel {\n reloadAuthStorage();\n const headers = getAgentControllerHeaders(options?.requestContext);\n const settings = loadSettings();\n // Bedrock was previously cataloged under the MastraCode gateway namespace\n // (`mastracode/amazon-bedrock/<model>`). Normalize any legacy saved ids to the\n // standalone `amazon-bedrock/<model>` form so they resolve through the\n // dedicated Bedrock gateway.\n const bedrockLegacyPrefix = `${MASTRACODE_GATEWAY_ID}/amazon-bedrock/`;\n const normalizedInput = modelId.startsWith(bedrockLegacyPrefix)\n ? modelId.slice(MASTRACODE_GATEWAY_ID.length + 1)\n : modelId;\n const isMastraGatewayModel = normalizedInput.startsWith(MASTRA_GATEWAY_PREFIX);\n const normalizedModelId = stripMastraGatewayPrefix(normalizedInput);\n const [providerId, ...modelParts] = normalizedModelId.split('/');\n const bareModelId = modelParts.join('/');\n if (!providerId || !bareModelId) {\n throw new Error(`Invalid model id: ${modelId}`);\n }\n\n if (providerId === AMAZON_BEDROCK_GATEWAY_ID) {\n const bedrockGateway = createAmazonBedrockGateway();\n const routerId = `${AMAZON_BEDROCK_GATEWAY_ID}/${bareModelId}`;\n const auth = bedrockGateway.resolveAuth({\n gatewayId: AMAZON_BEDROCK_GATEWAY_ID,\n providerId: AMAZON_BEDROCK_GATEWAY_ID,\n modelId: bareModelId,\n routerId,\n });\n return bedrockGateway.resolveLanguageModel({\n providerId: AMAZON_BEDROCK_GATEWAY_ID,\n modelId: bareModelId,\n apiKey: auth?.apiKey ?? '',\n headers,\n });\n }\n\n const routerId = `${MASTRACODE_GATEWAY_ID}/${normalizedModelId}`;\n\n const mgApiKey = MastraCodeGateway.getMastraGatewayApiKey();\n const rawGatewayBase =\n settings.memoryGateway?.baseUrl ?? process.env['MASTRA_GATEWAY_URL'] ?? 'https://gateway-api.mastra.ai';\n // Deployed web registers a per-tenant credential store provider; when the\n // request carries an authenticated tenant, resolve credentials through the\n // caller's own store (user > org > env). Undefined = global AuthStorage.\n const credentialStore = resolveCredentialStore(options?.requestContext);\n // Deployed web registers a custom providers source (DB-backed, tenant\n // scoped); when registered it is authoritative and settings.json custom\n // providers are ignored. Undefined = local settings-based behavior.\n const customProviders = resolveCustomProviders(options?.requestContext) ?? settings.customProviders;\n const gateway = createMastraCodeGateway({\n mastraGatewayBaseUrl: rawGatewayBase.replace(/\\/+$/, '').replace(/\\/v1$/, ''),\n mastraGatewayApiKey: mgApiKey,\n routeThroughMastraGateway: Boolean(mgApiKey && isMastraGatewayModel),\n thinkingLevel: options?.thinkingLevel,\n customProviders,\n credentialStore,\n });\n\n const auth = gateway.resolveAuth({\n gatewayId: MASTRACODE_GATEWAY_ID,\n providerId,\n modelId: bareModelId,\n routerId,\n });\n\n return gateway.resolveLanguageModel({\n providerId,\n modelId: bareModelId,\n apiKey: auth?.apiKey ?? mgApiKey ?? '',\n headers,\n });\n}\n\n/**\n * Dynamic model function that reads the current model from controller state.\n * This allows runtime model switching via the /models picker.\n */\nexport function getDynamicModel({ requestContext }: { requestContext: RequestContext }): ResolvedModel {\n const agentControllerContext = requestContext.get('controller') as AgentControllerRequestContext<any> | undefined;\n\n const modelId = agentControllerContext?.session?.modelId;\n if (!modelId) {\n throw new Error('No model selected. Use /models to select a model first.');\n }\n\n const thinkingLevel = agentControllerContext?.state?.thinkingLevel as ThinkingLevel | undefined;\n\n return resolveModel(modelId, { thinkingLevel, remapForCodexOAuth: true, requestContext });\n}\n\n/**\n * Goal judge model resolver for the agent's `goal.judge` config. Resolves the\n * configured goal judge model through mastracode's gateway so provider\n * credentials (stored in auth storage, not just env) are injected — a bare model\n * id handed to core's default model router would fail to find the API key.\n *\n * Returns `undefined` when no judge model is configured, which keeps the goal\n * step a complete no-op (the goal mechanism requires a judge to do anything).\n *\n * `settingsPath` must be the same source `createMastraCode()` reads from so the\n * judge model and the goal budget (`goalMaxTurns`) come from one config — with a\n * custom `settingsPath` a bare `loadSettings()` here could read a different file\n * and silently turn the goal step into a no-op.\n */\nexport function getGoalJudgeModel(\n { requestContext }: { requestContext: RequestContext },\n settingsPath?: string,\n): ResolvedModel | undefined {\n const judgeModelId = loadSettings(settingsPath).models.goalJudgeModel;\n if (!judgeModelId) return undefined;\n return resolveModel(judgeModelId, { remapForCodexOAuth: true, requestContext });\n}\n"],"mappings":"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","names":["MASTRACODE_GATEWAY_ID","MastraCodeGateway","resolveCustomProviders","routerId","auth"]}
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/agents/model.ts"],"sourcesContent":["import type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport type { GatewayLanguageModel, MastraModelGatewayInterface } from '@mastra/core/llm';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport { loadSettings } from '../onboarding/settings.js';\nimport { AMAZON_BEDROCK_GATEWAY_ID, createAmazonBedrockGateway } from '../providers/amazon-bedrock-gateway.js';\nimport type { ThinkingLevel } from '../providers/openai-codex.js';\nimport { resolveCredentialStore } from './credential-resolver.js';\nimport { resolveCustomProviders } from './custom-provider-source.js';\nimport {\n MASTRA_GATEWAY_PREFIX,\n MASTRACODE_GATEWAY_ID,\n MastraCodeGateway,\n reloadAuthStorage,\n stripMastraGatewayPrefix,\n} from './mastracode-gateway.js';\nimport type { MastraCodeGatewayOptions } from './mastracode-gateway.js';\n\nexport {\n getAnthropicApiKey,\n getOpenAIApiKey,\n MASTRACODE_GATEWAY_ID,\n MastraCodeGateway,\n remapOpenAIModelForCodexOAuth,\n resolveAuth,\n} from './mastracode-gateway.js';\nexport type { MastraCodeCustomProvider, MastraCodeGatewayOptions } from './mastracode-gateway.js';\nexport {\n setCredentialStoreProvider,\n hasCredentialStoreProvider,\n resolveTenantFromRequestContext,\n} from './credential-resolver.js';\nexport type { CredentialTenant, CredentialStoreProvider } from './credential-resolver.js';\nexport {\n setCustomProvidersSource,\n hasCustomProvidersSource,\n resolveCustomProviders,\n} from './custom-provider-source.js';\nexport type { CustomProvidersSource } from './custom-provider-source.js';\n\ntype ResolvedModel = GatewayLanguageModel;\ntype ModelRequestHeaders = Record<string, string>;\n\nfunction getAgentControllerHeaders(requestContext?: RequestContext): ModelRequestHeaders | undefined {\n const agentControllerContext = requestContext?.get('controller') as AgentControllerRequestContext<any> | undefined;\n const headers = {\n ...(agentControllerContext?.threadId ? { 'x-thread-id': agentControllerContext.threadId } : {}),\n ...(agentControllerContext?.resourceId ? { 'x-resource-id': agentControllerContext.resourceId } : {}),\n };\n\n return Object.keys(headers).length > 0 ? headers : undefined;\n}\n\nexport function createMastraCodeGateway(options: MastraCodeGatewayOptions): MastraCodeGateway {\n return new MastraCodeGateway(options);\n}\n\nexport function createMastraCodeModelCatalogProvider(gateway: MastraModelGatewayInterface) {\n return gateway instanceof MastraCodeGateway\n ? gateway.createModelCatalogProvider()\n : MastraCodeGateway.createModelCatalogProvider(gateway);\n}\n\n/**\n * Placeholder for future model ID normalization.\n * Currently returns the input unchanged, but exists as a seam\n * for aliasing, casing fixes, or validation in the future.\n */\nexport function resolveModelId(modelId: string): string {\n return modelId;\n}\n\n/**\n * Resolve a model ID to the correct provider instance.\n * Shared by the main agent, observer, and reflector.\n *\n * - For anthropic/* models: Uses stored OAuth credentials when present, otherwise direct API key\n * - For openai/* models: Uses OAuth when configured, otherwise direct API key from AuthStorage\n * - For moonshotai/* models: Uses Moonshot AI Anthropic-compatible endpoint\n * - For all other providers: Uses Mastra's model router (models.dev gateway)\n */\nexport function resolveModel(\n modelId: string,\n options?: { thinkingLevel?: ThinkingLevel; remapForCodexOAuth?: boolean; requestContext?: RequestContext },\n): GatewayLanguageModel {\n reloadAuthStorage();\n const headers = getAgentControllerHeaders(options?.requestContext);\n const settings = loadSettings();\n // Bedrock was previously cataloged under the MastraCode gateway namespace\n // (`mastracode/amazon-bedrock/<model>`). Normalize any legacy saved ids to the\n // standalone `amazon-bedrock/<model>` form so they resolve through the\n // dedicated Bedrock gateway.\n const bedrockLegacyPrefix = `${MASTRACODE_GATEWAY_ID}/amazon-bedrock/`;\n const normalizedInput = modelId.startsWith(bedrockLegacyPrefix)\n ? modelId.slice(MASTRACODE_GATEWAY_ID.length + 1)\n : modelId;\n const isMastraGatewayModel = normalizedInput.startsWith(MASTRA_GATEWAY_PREFIX);\n const normalizedModelId = stripMastraGatewayPrefix(normalizedInput);\n const [providerId, ...modelParts] = normalizedModelId.split('/');\n const bareModelId = modelParts.join('/');\n if (!providerId || !bareModelId) {\n throw new Error(`Invalid model id: ${modelId}`);\n }\n\n if (providerId === AMAZON_BEDROCK_GATEWAY_ID) {\n const bedrockGateway = createAmazonBedrockGateway();\n const routerId = `${AMAZON_BEDROCK_GATEWAY_ID}/${bareModelId}`;\n const auth = bedrockGateway.resolveAuth({\n gatewayId: AMAZON_BEDROCK_GATEWAY_ID,\n providerId: AMAZON_BEDROCK_GATEWAY_ID,\n modelId: bareModelId,\n routerId,\n });\n return bedrockGateway.resolveLanguageModel({\n providerId: AMAZON_BEDROCK_GATEWAY_ID,\n modelId: bareModelId,\n apiKey: auth?.apiKey ?? '',\n headers,\n });\n }\n\n const routerId = `${MASTRACODE_GATEWAY_ID}/${normalizedModelId}`;\n\n const mgApiKey = MastraCodeGateway.getMastraGatewayApiKey();\n const rawGatewayBase =\n settings.memoryGateway?.baseUrl ?? process.env['MASTRA_GATEWAY_URL'] ?? 'https://gateway-api.mastra.ai';\n // Deployed web registers a per-tenant credential store provider; when the\n // request carries an authenticated tenant, resolve credentials through the\n // caller's own store (user > org > env). Undefined = global AuthStorage.\n const credentialStore = resolveCredentialStore(options?.requestContext);\n // Deployed web registers a custom providers source (DB-backed, tenant\n // scoped); when registered it is authoritative and settings.json custom\n // providers are ignored. Undefined = local settings-based behavior.\n const customProviders = resolveCustomProviders(options?.requestContext) ?? settings.customProviders;\n const gateway = createMastraCodeGateway({\n mastraGatewayBaseUrl: rawGatewayBase.replace(/\\/+$/, '').replace(/\\/v1$/, ''),\n mastraGatewayApiKey: mgApiKey,\n routeThroughMastraGateway: Boolean(mgApiKey && isMastraGatewayModel),\n thinkingLevel: options?.thinkingLevel,\n customProviders,\n credentialStore,\n });\n\n const auth = gateway.resolveAuth({\n gatewayId: MASTRACODE_GATEWAY_ID,\n providerId,\n modelId: bareModelId,\n routerId,\n });\n\n return gateway.resolveLanguageModel({\n providerId,\n modelId: bareModelId,\n apiKey: auth?.apiKey ?? mgApiKey ?? '',\n headers,\n });\n}\n\n/**\n * Dynamic model function that reads the current model from controller state.\n * This allows runtime model switching via the /models picker.\n */\nexport function getDynamicModel({ requestContext }: { requestContext: RequestContext }): ResolvedModel {\n const agentControllerContext = requestContext.get('controller') as AgentControllerRequestContext<any> | undefined;\n\n const modelId = agentControllerContext?.session?.modelId;\n if (!modelId) {\n throw new Error('No model selected. Use /models to select a model first.');\n }\n\n const thinkingLevel = agentControllerContext?.state?.thinkingLevel as ThinkingLevel | undefined;\n\n return resolveModel(modelId, { thinkingLevel, remapForCodexOAuth: true, requestContext });\n}\n\n/**\n * Goal judge model resolver for the agent's `goal.judge` config. Resolves the\n * configured goal judge model through mastracode's gateway so provider\n * credentials (stored in auth storage, not just env) are injected — a bare model\n * id handed to core's default model router would fail to find the API key.\n *\n * Returns `undefined` when no judge model is configured, which keeps the goal\n * step a complete no-op (the goal mechanism requires a judge to do anything).\n *\n * `settingsPath` must be the same source `createMastraCode()` reads from so the\n * judge model and the goal budget (`goalMaxTurns`) come from one config — with a\n * custom `settingsPath` a bare `loadSettings()` here could read a different file\n * and silently turn the goal step into a no-op.\n */\nexport function getGoalJudgeModel(\n { requestContext }: { requestContext: RequestContext },\n settingsPath?: string,\n): ResolvedModel | undefined {\n const judgeModelId = loadSettings(settingsPath).models.goalJudgeModel;\n if (!judgeModelId) return undefined;\n return resolveModel(judgeModelId, { remapForCodexOAuth: true, requestContext });\n}\n"],"mappings":"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"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
//#region src/agents/modes/build.ts
|
|
1
2
|
const buildMode = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
id: "build",
|
|
4
|
+
name: "Build",
|
|
5
|
+
description: "Task execution with write capabilities. Use for 'implement feature X', 'fix bug Y', 'refactor module Z'.",
|
|
6
|
+
instructions: `You are a focused execution agent. Your job is to complete a specific, well-defined task by making the necessary changes to the codebase.
|
|
6
7
|
|
|
7
8
|
## Rules
|
|
8
9
|
- You have FULL ACCESS to read, write, and execute within your task scope.
|
|
9
10
|
- Stay focused on the specific task given. Do not make unrelated changes.
|
|
10
|
-
- Read files before modifying them
|
|
11
|
+
- Read files before modifying them — use view first, then string_replace_lsp or write_file.
|
|
11
12
|
- Verify your changes work by running relevant tests or checking for errors.
|
|
12
13
|
|
|
13
14
|
## Tool Strategy
|
|
@@ -19,7 +20,7 @@ const buildMode = {
|
|
|
19
20
|
## Workflow
|
|
20
21
|
. Understand the task and explore relevant code
|
|
21
22
|
. For complex tasks (3+ steps): track progress internally and summarize it in your final answer
|
|
22
|
-
. Make changes incrementally
|
|
23
|
+
. Make changes incrementally — verify each change before moving on
|
|
23
24
|
. Run tests or type-check to verify
|
|
24
25
|
|
|
25
26
|
## Efficiency
|
|
@@ -34,12 +35,10 @@ End with a structured summary:
|
|
|
34
35
|
. **Changes**: Files modified/created
|
|
35
36
|
. **Verification**: How you verified it works
|
|
36
37
|
. **Notes**: Follow-up needed (if any)`,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
default: true
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
export {
|
|
43
|
-
buildMode
|
|
38
|
+
defaultModelId: "openai/gpt-5.5",
|
|
39
|
+
metadata: { default: true }
|
|
44
40
|
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { buildMode };
|
|
43
|
+
|
|
45
44
|
//# sourceMappingURL=build.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/agents/modes/build.ts"],"sourcesContent":["/**\n * Execute subagent — focused task execution with write capabilities.\n *\n * This subagent is given a specific implementation task and uses both\n * read and write tools to complete it. It can modify files, run commands,\n * and perform actual development work within a constrained scope.\n */\nimport type { AgentControllerMode } from '@mastra/core/agent-controller';\n\nexport const buildMode: AgentControllerMode = {\n id: 'build',\n name: 'Build',\n description:\n \"Task execution with write capabilities. Use for 'implement feature X', 'fix bug Y', 'refactor module Z'.\",\n instructions: `You are a focused execution agent. Your job is to complete a specific, well-defined task by making the necessary changes to the codebase.\n\n## Rules\n- You have FULL ACCESS to read, write, and execute within your task scope.\n- Stay focused on the specific task given. Do not make unrelated changes.\n- Read files before modifying them — use view first, then string_replace_lsp or write_file.\n- Verify your changes work by running relevant tests or checking for errors.\n\n## Tool Strategy\n- **Read first**: Always view a file before editing it\n- **Edit precisely**: Use string_replace_lsp with enough context to match uniquely\n- **Use specialized tools**: Prefer view/search_content/find_files over shell commands for reading\n- **Parallelize**: Make independent tool calls together (e.g., view multiple files at once)\n\n## Workflow\n. Understand the task and explore relevant code\n. For complex tasks (3+ steps): track progress internally and summarize it in your final answer\n. Make changes incrementally — verify each change before moving on\n. Run tests or type-check to verify\n\n## Efficiency\nYour output returns to the parent agent. Be concise:\n- Don't repeat file contents in your response\n- Summarize what changed, don't narrate each step\n- Keep your final summary under 300 words\n\n## Output Format\nEnd with a structured summary:\n. **Completed**: What you implemented (1-2 sentences)\n. **Changes**: Files modified/created\n. **Verification**: How you verified it works\n. **Notes**: Follow-up needed (if any)`,\n defaultModelId: 'openai/gpt-5.5',\n metadata: {\n default: true,\n },\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.js","names":[],"sources":["../../../src/agents/modes/build.ts"],"sourcesContent":["/**\n * Execute subagent — focused task execution with write capabilities.\n *\n * This subagent is given a specific implementation task and uses both\n * read and write tools to complete it. It can modify files, run commands,\n * and perform actual development work within a constrained scope.\n */\nimport type { AgentControllerMode } from '@mastra/core/agent-controller';\n\nexport const buildMode: AgentControllerMode = {\n id: 'build',\n name: 'Build',\n description:\n \"Task execution with write capabilities. Use for 'implement feature X', 'fix bug Y', 'refactor module Z'.\",\n instructions: `You are a focused execution agent. Your job is to complete a specific, well-defined task by making the necessary changes to the codebase.\n\n## Rules\n- You have FULL ACCESS to read, write, and execute within your task scope.\n- Stay focused on the specific task given. Do not make unrelated changes.\n- Read files before modifying them — use view first, then string_replace_lsp or write_file.\n- Verify your changes work by running relevant tests or checking for errors.\n\n## Tool Strategy\n- **Read first**: Always view a file before editing it\n- **Edit precisely**: Use string_replace_lsp with enough context to match uniquely\n- **Use specialized tools**: Prefer view/search_content/find_files over shell commands for reading\n- **Parallelize**: Make independent tool calls together (e.g., view multiple files at once)\n\n## Workflow\n. Understand the task and explore relevant code\n. For complex tasks (3+ steps): track progress internally and summarize it in your final answer\n. Make changes incrementally — verify each change before moving on\n. Run tests or type-check to verify\n\n## Efficiency\nYour output returns to the parent agent. Be concise:\n- Don't repeat file contents in your response\n- Summarize what changed, don't narrate each step\n- Keep your final summary under 300 words\n\n## Output Format\nEnd with a structured summary:\n. **Completed**: What you implemented (1-2 sentences)\n. **Changes**: Files modified/created\n. **Verification**: How you verified it works\n. **Notes**: Follow-up needed (if any)`,\n defaultModelId: 'openai/gpt-5.5',\n metadata: {\n default: true,\n },\n};\n"],"mappings":";AASA,MAAa,YAAiC;CAC5C,IAAI;CACJ,MAAM;CACN,aACE;CACF,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCd,gBAAgB;CAChB,UAAU,EACR,SAAS,KACX;AACF"}
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { EXPLORE_MODE_AVAILABLE_TOOLS } from "../tool-availability.js";
|
|
2
|
+
//#region src/agents/modes/explore.ts
|
|
2
3
|
const fastMode = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
id: "fast",
|
|
5
|
+
name: "Explore",
|
|
6
|
+
description: "Read-only codebase exploration. Use for questions like 'find all usages of X', 'how does module Y work'.",
|
|
7
|
+
defaultModelId: "openai/gpt-5.4-mini",
|
|
8
|
+
instructions: `You are an expert code explorer. Your job is to investigate a codebase and answer a specific question or gather specific information.
|
|
8
9
|
|
|
9
10
|
## Rules
|
|
10
11
|
- You have READ-ONLY access. You cannot modify files or run commands.
|
|
11
|
-
- Be thorough
|
|
12
|
+
- Be thorough — search broadly first, then drill into relevant files.
|
|
12
13
|
- After gathering enough information, produce a clear, concise summary of your findings.
|
|
13
14
|
|
|
14
15
|
## Tool Strategy
|
|
15
16
|
- **Start broad**: Use find_files (glob) to understand project structure
|
|
16
|
-
- **Search smart**: Use search_content (grep) with specific patterns
|
|
17
|
-
- **Read efficiently**: Use view with view_range for large files
|
|
17
|
+
- **Search smart**: Use search_content (grep) with specific patterns — avoid overly broad searches
|
|
18
|
+
- **Read efficiently**: Use view with view_range for large files — don't read entire files if you only need a section
|
|
18
19
|
- **Parallelize**: Make multiple independent tool calls in one round when exploring different areas
|
|
19
20
|
|
|
20
21
|
## Efficiency
|
|
21
22
|
Your output returns to the parent agent. Be concise:
|
|
22
|
-
- Don't include raw file contents in your response
|
|
23
|
+
- Don't include raw file contents in your response — summarize what you found
|
|
23
24
|
- Reference files by path and line number, not by copying code
|
|
24
25
|
- If a search returns many results, report the count and key examples, not every match
|
|
25
26
|
|
|
@@ -30,9 +31,9 @@ End with a structured summary:
|
|
|
30
31
|
. **Details**: Additional context if needed
|
|
31
32
|
|
|
32
33
|
Keep your summary under 300 words.`,
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
export {
|
|
36
|
-
fastMode
|
|
34
|
+
availableTools: [...EXPLORE_MODE_AVAILABLE_TOOLS]
|
|
37
35
|
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { fastMode };
|
|
38
|
+
|
|
38
39
|
//# sourceMappingURL=explore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/agents/modes/explore.ts"],"sourcesContent":["/**\n * Explore subagent — read-only codebase exploration.\n *\n * This subagent is given a focused task (e.g., \"find all usages of X\",\n * \"understand how module Y works\") and uses read-only tools to explore\n * the codebase, then returns a concise summary of its findings.\n */\nimport type { AgentControllerMode } from '@mastra/core/agent-controller';\nimport { EXPLORE_MODE_AVAILABLE_TOOLS } from '../tool-availability.js';\n\nexport const fastMode: AgentControllerMode = {\n id: 'fast',\n name: 'Explore',\n description:\n \"Read-only codebase exploration. Use for questions like 'find all usages of X', 'how does module Y work'.\",\n defaultModelId: 'openai/gpt-5.4-mini',\n instructions: `You are an expert code explorer. Your job is to investigate a codebase and answer a specific question or gather specific information.\n\n## Rules\n- You have READ-ONLY access. You cannot modify files or run commands.\n- Be thorough — search broadly first, then drill into relevant files.\n- After gathering enough information, produce a clear, concise summary of your findings.\n\n## Tool Strategy\n- **Start broad**: Use find_files (glob) to understand project structure\n- **Search smart**: Use search_content (grep) with specific patterns — avoid overly broad searches\n- **Read efficiently**: Use view with view_range for large files — don't read entire files if you only need a section\n- **Parallelize**: Make multiple independent tool calls in one round when exploring different areas\n\n## Efficiency\nYour output returns to the parent agent. Be concise:\n- Don't include raw file contents in your response — summarize what you found\n- Reference files by path and line number, not by copying code\n- If a search returns many results, report the count and key examples, not every match\n\n## Output Format\nEnd with a structured summary:\n. **Answer**: Direct answer to the question (1-2 sentences)\n. **Key Files**: Most relevant files with line numbers\n. **Details**: Additional context if needed\n\nKeep your summary under 300 words.`,\n\n availableTools: [...EXPLORE_MODE_AVAILABLE_TOOLS],\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"explore.js","names":[],"sources":["../../../src/agents/modes/explore.ts"],"sourcesContent":["/**\n * Explore subagent — read-only codebase exploration.\n *\n * This subagent is given a focused task (e.g., \"find all usages of X\",\n * \"understand how module Y works\") and uses read-only tools to explore\n * the codebase, then returns a concise summary of its findings.\n */\nimport type { AgentControllerMode } from '@mastra/core/agent-controller';\nimport { EXPLORE_MODE_AVAILABLE_TOOLS } from '../tool-availability.js';\n\nexport const fastMode: AgentControllerMode = {\n id: 'fast',\n name: 'Explore',\n description:\n \"Read-only codebase exploration. Use for questions like 'find all usages of X', 'how does module Y work'.\",\n defaultModelId: 'openai/gpt-5.4-mini',\n instructions: `You are an expert code explorer. Your job is to investigate a codebase and answer a specific question or gather specific information.\n\n## Rules\n- You have READ-ONLY access. You cannot modify files or run commands.\n- Be thorough — search broadly first, then drill into relevant files.\n- After gathering enough information, produce a clear, concise summary of your findings.\n\n## Tool Strategy\n- **Start broad**: Use find_files (glob) to understand project structure\n- **Search smart**: Use search_content (grep) with specific patterns — avoid overly broad searches\n- **Read efficiently**: Use view with view_range for large files — don't read entire files if you only need a section\n- **Parallelize**: Make multiple independent tool calls in one round when exploring different areas\n\n## Efficiency\nYour output returns to the parent agent. Be concise:\n- Don't include raw file contents in your response — summarize what you found\n- Reference files by path and line number, not by copying code\n- If a search returns many results, report the count and key examples, not every match\n\n## Output Format\nEnd with a structured summary:\n. **Answer**: Direct answer to the question (1-2 sentences)\n. **Key Files**: Most relevant files with line numbers\n. **Details**: Additional context if needed\n\nKeep your summary under 300 words.`,\n\n availableTools: [...EXPLORE_MODE_AVAILABLE_TOOLS],\n};\n"],"mappings":";;AAUA,MAAa,WAAgC;CAC3C,IAAI;CACJ,MAAM;CACN,aACE;CACF,gBAAgB;CAChB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;CA2Bd,gBAAgB,CAAC,GAAG,4BAA4B;AAClD"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { PLAN_MODE_AVAILABLE_TOOLS } from "../tool-availability.js";
|
|
2
|
+
//#region src/agents/modes/plan.ts
|
|
2
3
|
const planMode = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
id: "plan",
|
|
5
|
+
name: "Plan",
|
|
6
|
+
transitionsTo: "build",
|
|
7
|
+
defaultModelId: "openai/gpt-5.5",
|
|
8
|
+
description: "Read-only analysis and planning. Use for 'create an implementation plan for X', 'analyze the architecture of Y'.",
|
|
9
|
+
instructions: `You are an expert software architect and planner. Your job is to analyze a codebase and produce a detailed implementation plan for a given task.
|
|
9
10
|
|
|
10
11
|
## Rules
|
|
11
12
|
- You have READ-ONLY access to the project. You cannot modify project files or run commands.
|
|
12
13
|
- The one exception is plan files: you can create and edit markdown files inside \`.mastracode/plans/\` using \`write_file\`, \`view\`, and \`string_replace_lsp\`. You may not write anywhere else.
|
|
13
14
|
- First, explore the codebase to understand existing patterns, architecture, and conventions.
|
|
14
|
-
- Produce a concrete, actionable plan
|
|
15
|
+
- Produce a concrete, actionable plan — not vague suggestions.
|
|
15
16
|
|
|
16
17
|
## Tool Strategy
|
|
17
18
|
- **Discover structure**: Use find_files (glob) to understand project layout and find relevant files
|
|
@@ -23,16 +24,14 @@ const planMode = {
|
|
|
23
24
|
- Write your plan to a markdown file under \`.mastracode/plans/\` (e.g. \`.mastracode/plans/add-dark-mode.md\`) using \`write_file\`, then call \`submit_plan({ path })\` with the path to that file (never the plan body).
|
|
24
25
|
- Start the file with a \`# Title\` heading describing the plan.
|
|
25
26
|
- Reuse the same file while iterating on the same plan; only create a new file for a genuinely different plan so each plan stays available to review.
|
|
26
|
-
- Do NOT output the plan as text
|
|
27
|
+
- Do NOT output the plan as text — it MUST live in the plan file.
|
|
27
28
|
- Be concise: reference files by path and line number, don't include raw contents.
|
|
28
29
|
- Focus on actionable details, not general observations.
|
|
29
30
|
- To revise after "Request changes", edit the same file in place with \`string_replace_lsp\`, and call \`submit_plan\` again with the same path.`,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
availableTools: [...PLAN_MODE_AVAILABLE_TOOLS]
|
|
34
|
-
};
|
|
35
|
-
export {
|
|
36
|
-
planMode
|
|
31
|
+
metadata: { default: false },
|
|
32
|
+
availableTools: [...PLAN_MODE_AVAILABLE_TOOLS]
|
|
37
33
|
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { planMode };
|
|
36
|
+
|
|
38
37
|
//# sourceMappingURL=plan.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/agents/modes/plan.ts"],"sourcesContent":["/**\n * Plan mode — read-only analysis and planning.\n */\nimport type { AgentControllerMode } from '@mastra/core/agent-controller';\nimport { PLAN_MODE_AVAILABLE_TOOLS } from '../tool-availability.js';\n\nexport const planMode: AgentControllerMode = {\n id: 'plan',\n name: 'Plan',\n transitionsTo: 'build',\n defaultModelId: 'openai/gpt-5.5',\n description:\n \"Read-only analysis and planning. Use for 'create an implementation plan for X', 'analyze the architecture of Y'.\",\n instructions: `You are an expert software architect and planner. Your job is to analyze a codebase and produce a detailed implementation plan for a given task.\n\n## Rules\n- You have READ-ONLY access to the project. You cannot modify project files or run commands.\n- The one exception is plan files: you can create and edit markdown files inside \\`.mastracode/plans/\\` using \\`write_file\\`, \\`view\\`, and \\`string_replace_lsp\\`. You may not write anywhere else.\n- First, explore the codebase to understand existing patterns, architecture, and conventions.\n- Produce a concrete, actionable plan — not vague suggestions.\n\n## Tool Strategy\n- **Discover structure**: Use find_files (glob) to understand project layout and find relevant files\n- **Find patterns**: Use search_content (grep) to locate existing implementations, imports, and conventions\n- **Understand deeply**: Use view with view_range to read specific sections of key files\n- **Parallelize**: Make multiple independent tool calls when exploring different areas\n\n## Plan Delivery\n- Write your plan to a markdown file under \\`.mastracode/plans/\\` (e.g. \\`.mastracode/plans/add-dark-mode.md\\`) using \\`write_file\\`, then call \\`submit_plan({ path })\\` with the path to that file (never the plan body).\n- Start the file with a \\`# Title\\` heading describing the plan.\n- Reuse the same file while iterating on the same plan; only create a new file for a genuinely different plan so each plan stays available to review.\n- Do NOT output the plan as text — it MUST live in the plan file.\n- Be concise: reference files by path and line number, don't include raw contents.\n- Focus on actionable details, not general observations.\n- To revise after \"Request changes\", edit the same file in place with \\`string_replace_lsp\\`, and call \\`submit_plan\\` again with the same path.`,\n\n metadata: {\n default: false,\n },\n\n availableTools: [...PLAN_MODE_AVAILABLE_TOOLS],\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plan.js","names":[],"sources":["../../../src/agents/modes/plan.ts"],"sourcesContent":["/**\n * Plan mode — read-only analysis and planning.\n */\nimport type { AgentControllerMode } from '@mastra/core/agent-controller';\nimport { PLAN_MODE_AVAILABLE_TOOLS } from '../tool-availability.js';\n\nexport const planMode: AgentControllerMode = {\n id: 'plan',\n name: 'Plan',\n transitionsTo: 'build',\n defaultModelId: 'openai/gpt-5.5',\n description:\n \"Read-only analysis and planning. Use for 'create an implementation plan for X', 'analyze the architecture of Y'.\",\n instructions: `You are an expert software architect and planner. Your job is to analyze a codebase and produce a detailed implementation plan for a given task.\n\n## Rules\n- You have READ-ONLY access to the project. You cannot modify project files or run commands.\n- The one exception is plan files: you can create and edit markdown files inside \\`.mastracode/plans/\\` using \\`write_file\\`, \\`view\\`, and \\`string_replace_lsp\\`. You may not write anywhere else.\n- First, explore the codebase to understand existing patterns, architecture, and conventions.\n- Produce a concrete, actionable plan — not vague suggestions.\n\n## Tool Strategy\n- **Discover structure**: Use find_files (glob) to understand project layout and find relevant files\n- **Find patterns**: Use search_content (grep) to locate existing implementations, imports, and conventions\n- **Understand deeply**: Use view with view_range to read specific sections of key files\n- **Parallelize**: Make multiple independent tool calls when exploring different areas\n\n## Plan Delivery\n- Write your plan to a markdown file under \\`.mastracode/plans/\\` (e.g. \\`.mastracode/plans/add-dark-mode.md\\`) using \\`write_file\\`, then call \\`submit_plan({ path })\\` with the path to that file (never the plan body).\n- Start the file with a \\`# Title\\` heading describing the plan.\n- Reuse the same file while iterating on the same plan; only create a new file for a genuinely different plan so each plan stays available to review.\n- Do NOT output the plan as text — it MUST live in the plan file.\n- Be concise: reference files by path and line number, don't include raw contents.\n- Focus on actionable details, not general observations.\n- To revise after \"Request changes\", edit the same file in place with \\`string_replace_lsp\\`, and call \\`submit_plan\\` again with the same path.`,\n\n metadata: {\n default: false,\n },\n\n availableTools: [...PLAN_MODE_AVAILABLE_TOOLS],\n};\n"],"mappings":";;AAMA,MAAa,WAAgC;CAC3C,IAAI;CACJ,MAAM;CACN,eAAe;CACf,gBAAgB;CAChB,aACE;CACF,cAAc;;;;;;;;;;;;;;;;;;;;;;CAuBd,UAAU,EACR,SAAS,MACX;CAEA,gBAAgB,CAAC,GAAG,yBAAyB;AAC/C"}
|