@mastra/code-sdk 1.15.0-alpha.9 → 1.15.0
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/dist/acp/agent.js +2 -1
- package/dist/acp/agent.js.map +1 -1
- package/dist/acp/event-mapper.js +0 -2
- package/dist/acp/event-mapper.js.map +1 -1
- package/dist/acp.js +1 -2
- package/dist/agent-connections/registry.js.map +1 -1
- package/dist/agent-connections/signal-provider.js.map +1 -1
- package/dist/agent-connections/state-processor.js.map +1 -1
- package/dist/agent-connections/tools.js +26 -24
- package/dist/agent-connections/tools.js.map +1 -1
- package/dist/agents/background-completion.d.ts +15 -2
- package/dist/agents/background-completion.d.ts.map +1 -1
- package/dist/agents/background-completion.js +19 -2
- package/dist/agents/background-completion.js.map +1 -1
- package/dist/agents/instructions.js +3 -2
- package/dist/agents/instructions.js.map +1 -1
- package/dist/agents/mastracode-gateway.js +35 -27
- package/dist/agents/mastracode-gateway.js.map +1 -1
- package/dist/agents/memory.d.ts.map +1 -1
- package/dist/agents/memory.js +17 -3
- package/dist/agents/memory.js.map +1 -1
- package/dist/agents/prompts/agent-instructions.js +1 -1
- package/dist/agents/prompts/agent-instructions.js.map +1 -1
- package/dist/agents/prompts/index.js +3 -2
- package/dist/agents/prompts/index.js.map +1 -1
- package/dist/agents/prompts/plan.js +2 -1
- package/dist/agents/prompts/plan.js.map +1 -1
- package/dist/agents/sandbox-filesystem.d.ts +28 -0
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -1
- package/dist/agents/sandbox-filesystem.js +81 -2
- package/dist/agents/sandbox-filesystem.js.map +1 -1
- package/dist/agents/tools.d.ts.map +1 -1
- package/dist/agents/tools.js +18 -12
- package/dist/agents/tools.js.map +1 -1
- package/dist/agents/workspace.js +2 -1
- package/dist/agents/workspace.js.map +1 -1
- package/dist/auth/account-rotation-processor.js +2 -1
- package/dist/auth/account-rotation-processor.js.map +1 -1
- package/dist/auth/providers/anthropic.js +2 -2
- package/dist/auth/providers/anthropic.js.map +1 -1
- package/dist/auth/providers/github-copilot.js +1 -1
- package/dist/auth/providers/github-copilot.js.map +1 -1
- package/dist/auth/providers/openai-codex.js +3 -2
- package/dist/auth/providers/openai-codex.js.map +1 -1
- package/dist/auth/providers/xai.js +1 -1
- package/dist/auth/providers/xai.js.map +1 -1
- package/dist/clipboard/index.js +5 -4
- package/dist/clipboard/index.js.map +1 -1
- package/dist/evals/context-builder.js +1 -3
- package/dist/evals/context-builder.js.map +1 -1
- package/dist/evals/scorers/outcome.js +2 -1
- package/dist/evals/scorers/outcome.js.map +1 -1
- package/dist/factory/remote-controller.js.map +1 -1
- package/dist/factory/remote-session.d.ts +1 -1
- package/dist/factory/remote-session.d.ts.map +1 -1
- package/dist/factory/remote-session.js +15 -13
- package/dist/factory/remote-session.js.map +1 -1
- package/dist/headless/cli.js +2 -1
- package/dist/headless/cli.js.map +1 -1
- package/dist/headless/run-mc.js +9 -9
- package/dist/headless/run-mc.js.map +1 -1
- package/dist/hooks/executor.js +3 -1
- package/dist/hooks/executor.js.map +1 -1
- package/dist/hooks/manager.js +40 -26
- package/dist/hooks/manager.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -21
- package/dist/index.js.map +1 -1
- package/dist/knowledge-inspector.js +2 -2
- package/dist/knowledge-inspector.js.map +1 -1
- package/dist/lsp/server.js +4 -2
- package/dist/lsp/server.js.map +1 -1
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +14 -2
- package/dist/mcp/manager.js.map +1 -1
- package/dist/onboarding/settings.js +5 -2
- package/dist/onboarding/settings.js.map +1 -1
- package/dist/platform/index.js +5 -3
- package/dist/platform/index.js.map +1 -1
- package/dist/plugins/loader.js +3 -1
- package/dist/plugins/loader.js.map +1 -1
- package/dist/plugins/manager.js +2 -1
- package/dist/plugins/manager.js.map +1 -1
- package/dist/plugins/package-link.js.map +1 -1
- package/dist/plugins/scaffold.js +4 -2
- package/dist/plugins/scaffold.js.map +1 -1
- package/dist/plugins/signal-lane.js.map +1 -1
- package/dist/process-memory-diagnostics.js +2 -1
- package/dist/process-memory-diagnostics.js.map +1 -1
- package/dist/providers/amazon-bedrock-gateway.js +2 -1
- package/dist/providers/amazon-bedrock-gateway.js.map +1 -1
- package/dist/providers/amazon-bedrock.js +2 -2
- package/dist/providers/amazon-bedrock.js.map +1 -1
- package/dist/providers/claude-max.js +13 -9
- package/dist/providers/claude-max.js.map +1 -1
- package/dist/providers/github-copilot-gateway.js.map +1 -1
- package/dist/providers/github-copilot.js +13 -12
- package/dist/providers/github-copilot.js.map +1 -1
- package/dist/providers/openai-codex.js +14 -11
- package/dist/providers/openai-codex.js.map +1 -1
- package/dist/providers/provider-thinking.js.map +1 -1
- package/dist/providers/thinking-request.js +1 -1
- package/dist/providers/thinking-request.js.map +1 -1
- package/dist/schedules/run-script.js +1 -1
- package/dist/schedules/run-script.js.map +1 -1
- package/dist/schedules/scheduler.js.map +1 -1
- package/dist/tools/request-sandbox-access.js +7 -5
- package/dist/tools/request-sandbox-access.js.map +1 -1
- package/dist/tools/utils.js +3 -1
- package/dist/tools/utils.js.map +1 -1
- package/dist/tools/web-search.d.ts +13 -11
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +21 -15
- package/dist/tools/web-search.js.map +1 -1
- package/dist/utils/debug-log.js +2 -2
- package/dist/utils/debug-log.js.map +1 -1
- package/dist/utils/gateway-sync.js +1 -1
- package/dist/utils/gateway-sync.js.map +1 -1
- package/dist/utils/local-observability.d.ts +1 -1
- package/dist/utils/local-observability.d.ts.map +1 -1
- package/dist/utils/local-observability.js +1 -1
- package/dist/utils/local-observability.js.map +1 -1
- package/dist/utils/prune-cli.js +10 -8
- package/dist/utils/prune-cli.js.map +1 -1
- package/dist/utils/signals-pubsub.js.map +1 -1
- package/dist/utils/slash-command-processor.js +1 -1
- package/dist/utils/slash-command-processor.js.map +1 -1
- package/dist/utils/stdin-pipe.js +1 -1
- package/dist/utils/stdin-pipe.js.map +1 -1
- package/dist/utils/storage-factory.d.ts.map +1 -1
- package/dist/utils/storage-factory.js +1 -1
- package/dist/utils/storage-factory.js.map +1 -1
- package/dist/utils/storage-maintenance.js +1 -1
- package/dist/utils/storage-maintenance.js.map +1 -1
- package/dist/utils/update-check.js +2 -1
- package/dist/utils/update-check.js.map +1 -1
- package/dist/utils/wake-session.d.ts +1 -1
- package/dist/utils/wake-session.d.ts.map +1 -1
- package/dist/utils/wake-session.js +8 -1
- package/dist/utils/wake-session.js.map +1 -1
- package/dist/workflows/register-primitives.js +1 -1
- package/dist/workflows/register-primitives.js.map +1 -1
- package/package.json +19 -19
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ import { setAuthStorage as setAuthStorage$1 } from "./providers/claude-max.js";
|
|
|
21
21
|
import { setAuthStorage as setAuthStorage$2 } from "./providers/github-copilot.js";
|
|
22
22
|
import { setAuthStorage as setAuthStorage$3 } from "./providers/kimi-coding.js";
|
|
23
23
|
import { setAuthStorage as setAuthStorage$4 } from "./providers/xai.js";
|
|
24
|
-
import { createMastraCodeGateway, getDynamicModel, getGoalJudgeModel, resolveModel } from "./agents/model.js";
|
|
24
|
+
import { canUseProvider, createMastraCodeGateway, getDynamicModel, getGoalJudgeModel, resolveModel } from "./agents/model.js";
|
|
25
25
|
import { getDynamicMemory, hasSubconsciousTools } from "./agents/memory.js";
|
|
26
26
|
import { buildMode } from "./agents/modes/build.js";
|
|
27
27
|
import { fastMode } from "./agents/modes/explore.js";
|
|
@@ -87,7 +87,6 @@ import { DEFAULT_GOAL_JUDGE_PROMPT } from "@mastra/core/tools";
|
|
|
87
87
|
import { GithubSignals } from "@mastra/github-signals";
|
|
88
88
|
import { LibSQLStore, LibSQLVector } from "@mastra/libsql";
|
|
89
89
|
import { MastraPlatformExporter, MastraStorageExporter, Observability, SensitiveDataFilter } from "@mastra/observability";
|
|
90
|
-
import { PostgresStore } from "@mastra/pg";
|
|
91
90
|
//#region src/index.ts
|
|
92
91
|
const CODE_AGENT_ID = "code-agent";
|
|
93
92
|
const MASTRACODE_TRANSIENT_CONNECTION_MAX_RETRIES = 10;
|
|
@@ -228,7 +227,7 @@ function hasAncestorClassNamed(value, className) {
|
|
|
228
227
|
function resolveInjectedStorageBackend(storage, configuredBackend) {
|
|
229
228
|
if (configuredBackend) return configuredBackend;
|
|
230
229
|
if (storage instanceof LibSQLStore || hasAncestorClassNamed(storage, "LibSQLStore")) return "libsql";
|
|
231
|
-
if (
|
|
230
|
+
if (hasAncestorClassNamed(storage, "PostgresStore")) return "pg";
|
|
232
231
|
throw new Error("storageBackend is required when injecting a custom storage instance.");
|
|
233
232
|
}
|
|
234
233
|
/** Whether the model router would resolve `modelId` through a gateway outside `sdkGatewayIds`. */
|
|
@@ -247,6 +246,10 @@ async function createMastraCodeAgentController(config) {
|
|
|
247
246
|
const modeless = config?.modes === false;
|
|
248
247
|
let activeSession;
|
|
249
248
|
const liveSessions = /* @__PURE__ */ new Set();
|
|
249
|
+
const sessionRouter = {
|
|
250
|
+
getSession: (sessionId) => controller.getSession(sessionId),
|
|
251
|
+
listLiveSessions: () => liveSessions
|
|
252
|
+
};
|
|
250
253
|
let pluginRuntimeController;
|
|
251
254
|
if (configDir !== ".mastracode") validateConfigDirName(configDir);
|
|
252
255
|
if (!config?.disableEnvFile) try {
|
|
@@ -280,8 +283,9 @@ async function createMastraCodeAgentController(config) {
|
|
|
280
283
|
});
|
|
281
284
|
}
|
|
282
285
|
const mgApiKey = process.env["MASTRA_GATEWAY_API_KEY"] ?? storedGatewayKey;
|
|
286
|
+
const mastraGatewayBaseUrl = (process.env["MASTRA_GATEWAY_URL"] ?? storedGatewayUrl ?? "https://gateway-api.mastra.ai").replace(/\/+$/, "").replace(/\/v1$/, "");
|
|
283
287
|
const mastraCodeGateway = createMastraCodeGateway({
|
|
284
|
-
mastraGatewayBaseUrl
|
|
288
|
+
mastraGatewayBaseUrl,
|
|
285
289
|
mastraGatewayApiKey: mgApiKey,
|
|
286
290
|
routeThroughMastraGateway: false,
|
|
287
291
|
settingsPath: config?.settingsPath
|
|
@@ -426,6 +430,14 @@ async function createMastraCodeAgentController(config) {
|
|
|
426
430
|
owner: `${ownerId}:${process.pid}:${randomUUID()}`,
|
|
427
431
|
onError: (error) => console.warn("Notification dispatch failed:", error)
|
|
428
432
|
});
|
|
433
|
+
const resolveWakeOwner = async (target, leases) => {
|
|
434
|
+
const owner = await findWakeSession(controller, liveSessions, target, leases);
|
|
435
|
+
if (owner || !config?.resumeWakeSession) return owner;
|
|
436
|
+
await config.resumeWakeSession(target);
|
|
437
|
+
const resumed = await findWakeSession(controller, liveSessions, target, leases);
|
|
438
|
+
if (!resumed) throw new Error(`No session owns resource ${target.resourceId} to run its wake on thread ${target.threadId}.`);
|
|
439
|
+
return resumed;
|
|
440
|
+
};
|
|
429
441
|
const getWakeStreamOptions = async ({ resourceId, threadId, owner }) => {
|
|
430
442
|
const wake = owner ?? await findWakeSession(controller, liveSessions, {
|
|
431
443
|
resourceId,
|
|
@@ -501,6 +513,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
501
513
|
isThreadActive: () => session.thread.getId() === threadId,
|
|
502
514
|
threadId,
|
|
503
515
|
resourceId,
|
|
516
|
+
sessionId: session.identity.getId(),
|
|
504
517
|
session: {
|
|
505
518
|
id: session.identity.getId(),
|
|
506
519
|
ownerId: session.identity.getOwnerId(),
|
|
@@ -554,7 +567,11 @@ async function createMastraCodeAgentController(config) {
|
|
|
554
567
|
resourceId: schedule.resourceId,
|
|
555
568
|
threadId: schedule.threadId
|
|
556
569
|
};
|
|
557
|
-
const
|
|
570
|
+
const owner = await resolveWakeOwner(target);
|
|
571
|
+
const streamOptions = owner && owner !== FOREIGN_THREAD ? await getWakeStreamOptions({
|
|
572
|
+
...target,
|
|
573
|
+
owner
|
|
574
|
+
}) : void 0;
|
|
558
575
|
const accepted = await codeAgent.sendSignal({
|
|
559
576
|
type: "user",
|
|
560
577
|
tagName: "user",
|
|
@@ -565,7 +582,8 @@ async function createMastraCodeAgentController(config) {
|
|
|
565
582
|
ifActive: { behavior: "deliver" },
|
|
566
583
|
ifIdle: {
|
|
567
584
|
behavior: "wake",
|
|
568
|
-
...streamOptions ? { streamOptions } : {}
|
|
585
|
+
...streamOptions ? { streamOptions } : {},
|
|
586
|
+
...owner === FOREIGN_THREAD ? { requireClaimedOwner: true } : {}
|
|
569
587
|
}
|
|
570
588
|
}).accepted;
|
|
571
589
|
if (accepted.action === "blocked" || accepted.action === "discard") throw new Error(`the agent did not accept the prompt (${accepted.action})`);
|
|
@@ -628,12 +646,13 @@ async function createMastraCodeAgentController(config) {
|
|
|
628
646
|
const projectPath = state?.projectPath ?? project.rootPath;
|
|
629
647
|
const untrusted = state?.untrustedCheckout === true && typeof state?.baseRef === "string";
|
|
630
648
|
const roots = sessionInstructionRoots(projectPath, state?.instructionRoots);
|
|
631
|
-
|
|
649
|
+
const sources = loadSessionInstructions({
|
|
632
650
|
workingDir: projectPath,
|
|
633
651
|
instructionRoots: state?.instructionRoots,
|
|
634
652
|
untrustedCheckout: untrusted,
|
|
635
653
|
baseRef: untrusted ? state?.baseRef : void 0
|
|
636
|
-
})
|
|
654
|
+
});
|
|
655
|
+
return instructionSourcePaths(sources, roots);
|
|
637
656
|
}
|
|
638
657
|
})
|
|
639
658
|
];
|
|
@@ -675,15 +694,16 @@ async function createMastraCodeAgentController(config) {
|
|
|
675
694
|
return NO_PLUGIN_PROCESSORS;
|
|
676
695
|
}
|
|
677
696
|
};
|
|
678
|
-
const
|
|
697
|
+
const baseCodeAgent = createCodingAgent({
|
|
679
698
|
id: CODE_AGENT_ID,
|
|
680
699
|
name: "Code Agent",
|
|
681
700
|
workspace: void 0,
|
|
682
701
|
instructions: async ({ requestContext }) => {
|
|
683
702
|
const configured = config?.hostInstructions;
|
|
703
|
+
const hostInstructions = typeof configured === "function" ? await configured({ requestContext }) : configured;
|
|
684
704
|
return getDynamicInstructions({
|
|
685
705
|
requestContext,
|
|
686
|
-
hostInstructions
|
|
706
|
+
hostInstructions,
|
|
687
707
|
coAuthor: config?.coAuthor,
|
|
688
708
|
hasSubconscious,
|
|
689
709
|
hasSubagents: subagents.length > 0,
|
|
@@ -691,7 +711,8 @@ async function createMastraCodeAgentController(config) {
|
|
|
691
711
|
});
|
|
692
712
|
},
|
|
693
713
|
model: withCredentialTenantPreparation(async (ctx) => {
|
|
694
|
-
const
|
|
714
|
+
const controller = ctx.requestContext.get("controller");
|
|
715
|
+
const hasSessionLevel = isThinkingLevelSetting(controller?.state?.thinkingLevel);
|
|
695
716
|
return getDynamicModel(ctx, config?.settingsPath, {
|
|
696
717
|
modeless,
|
|
697
718
|
defaultThinkingLevel: hasSessionLevel ? void 0 : await config?.resolveDefaultThinkingLevel?.(ctx)
|
|
@@ -704,12 +725,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
704
725
|
resourceId: input.record.resourceId,
|
|
705
726
|
threadId: input.record.threadId
|
|
706
727
|
};
|
|
707
|
-
|
|
708
|
-
if (!owner && config?.resumeWakeSession && (decision.action === "deliver" || decision.action === "summarize")) {
|
|
709
|
-
await config.resumeWakeSession(target);
|
|
710
|
-
owner = await findWakeSession(controller, liveSessions, target, notificationDispatchLeases);
|
|
711
|
-
if (!owner) throw new Error(`No session owns resource ${target.resourceId} to run its wake on thread ${target.threadId}.`);
|
|
712
|
-
}
|
|
728
|
+
const owner = decision.action === "deliver" || decision.action === "summarize" ? await resolveWakeOwner(target, notificationDispatchLeases) : await findWakeSession(controller, liveSessions, target, notificationDispatchLeases);
|
|
713
729
|
if (owner === FOREIGN_THREAD) return {
|
|
714
730
|
...decision,
|
|
715
731
|
hold: true
|
|
@@ -815,7 +831,8 @@ async function createMastraCodeAgentController(config) {
|
|
|
815
831
|
})
|
|
816
832
|
],
|
|
817
833
|
maxProcessorRetries: MASTRACODE_MAX_PROCESSOR_RETRIES
|
|
818
|
-
})
|
|
834
|
+
});
|
|
835
|
+
const codeAgent = wrapExperimentalAgent(baseCodeAgent, experimentalAgent);
|
|
819
836
|
const planMode = createPlanMode(!disabledBuiltinTools.has("submit_plan"));
|
|
820
837
|
const defaultModes = [
|
|
821
838
|
{
|
|
@@ -842,7 +859,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
842
859
|
];
|
|
843
860
|
const intervalHandlers = config?.intervalHandlers ?? [{
|
|
844
861
|
id: "gateway-sync",
|
|
845
|
-
intervalMs:
|
|
862
|
+
intervalMs: 3e5,
|
|
846
863
|
immediate: false,
|
|
847
864
|
handler: () => syncGateways()
|
|
848
865
|
}];
|
|
@@ -933,7 +950,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
933
950
|
...backgroundToolsEnabled ? { backgroundTasks: {
|
|
934
951
|
enabled: true,
|
|
935
952
|
recoverStaleTasksOnStart: false,
|
|
936
|
-
...createBackgroundCompletionCallbacks(() =>
|
|
953
|
+
...createBackgroundCompletionCallbacks(() => sessionRouter, backgroundCompletionEvents)
|
|
937
954
|
} } : {},
|
|
938
955
|
observability,
|
|
939
956
|
memory,
|
|
@@ -944,7 +961,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
944
961
|
defaultObserverModelId: DEFAULT_OM_MODEL_ID,
|
|
945
962
|
reflectorModel: "auto",
|
|
946
963
|
defaultReflectorModelId: DEFAULT_OM_MODEL_ID,
|
|
947
|
-
resolveAutoModelId: ({ currentModelId }) => resolveAutoOMModelId(currentModelId)
|
|
964
|
+
resolveAutoModelId: ({ currentModelId }) => resolveAutoOMModelId(currentModelId, canUseProvider)
|
|
948
965
|
},
|
|
949
966
|
agent: codeAgent,
|
|
950
967
|
subagents,
|