@mastra/code-sdk 1.15.0-alpha.1 → 1.15.0-alpha.11
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.d.ts.map +1 -1
- package/dist/acp/agent.js +1 -1
- package/dist/acp/agent.js.map +1 -1
- package/dist/acp/event-mapper.d.ts.map +1 -1
- package/dist/acp/event-mapper.js +1 -1
- package/dist/acp/event-mapper.js.map +1 -1
- package/dist/agent-connections/signal-provider.d.ts +1 -1
- package/dist/agent-connections/signal-provider.d.ts.map +1 -1
- package/dist/agent-connections/signal-provider.js.map +1 -1
- package/dist/agent-connections/state-processor.d.ts +2 -2
- package/dist/agent-connections/state-processor.d.ts.map +1 -1
- package/dist/agent-connections/state-processor.js.map +1 -1
- package/dist/agent-connections/thread-state.d.ts +1 -1
- package/dist/agent-connections/thread-state.d.ts.map +1 -1
- package/dist/agent-connections/thread-state.js.map +1 -1
- package/dist/agent-connections/tools.d.ts.map +1 -1
- package/dist/agent-connections/tools.js +1 -1
- 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/credential-resolver.d.ts +6 -0
- package/dist/agents/credential-resolver.d.ts.map +1 -1
- package/dist/agents/credential-resolver.js +13 -4
- package/dist/agents/credential-resolver.js.map +1 -1
- package/dist/agents/memory.d.ts.map +1 -1
- package/dist/agents/memory.js +1 -1
- package/dist/agents/memory.js.map +1 -1
- package/dist/agents/sandbox-filesystem.d.ts +32 -10
- package/dist/agents/sandbox-filesystem.d.ts.map +1 -1
- package/dist/agents/sandbox-filesystem.js +208 -66
- package/dist/agents/sandbox-filesystem.js.map +1 -1
- package/dist/agents/workspace.d.ts.map +1 -1
- package/dist/agents/workspace.js +1 -0
- package/dist/agents/workspace.js.map +1 -1
- package/dist/experimental-agent.d.ts +1 -1
- package/dist/experimental-agent.d.ts.map +1 -1
- package/dist/experimental-agent.js.map +1 -1
- package/dist/factory/client.d.ts +41 -0
- package/dist/factory/client.d.ts.map +1 -0
- package/dist/factory/client.js +98 -0
- package/dist/factory/client.js.map +1 -0
- package/dist/factory/remote-controller.d.ts +34 -0
- package/dist/factory/remote-controller.d.ts.map +1 -0
- package/dist/factory/remote-controller.js +43 -0
- package/dist/factory/remote-controller.js.map +1 -0
- package/dist/factory/remote-session.d.ts +210 -0
- package/dist/factory/remote-session.d.ts.map +1 -0
- package/dist/factory/remote-session.js +420 -0
- package/dist/factory/remote-session.js.map +1 -0
- package/dist/headless/cli.d.ts +7 -0
- package/dist/headless/cli.d.ts.map +1 -1
- package/dist/headless/cli.js +19 -3
- package/dist/headless/cli.js.map +1 -1
- package/dist/headless/flags.d.ts.map +1 -1
- package/dist/headless/flags.js +2 -1
- package/dist/headless/flags.js.map +1 -1
- package/dist/headless/format.d.ts +2 -0
- package/dist/headless/format.d.ts.map +1 -1
- package/dist/headless/format.js +13 -1
- package/dist/headless/format.js.map +1 -1
- package/dist/headless/run-mc.d.ts.map +1 -1
- package/dist/headless/run-mc.js +48 -20
- package/dist/headless/run-mc.js.map +1 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -25
- package/dist/index.js.map +1 -1
- package/dist/onboarding/pack-activation.d.ts +2 -11
- package/dist/onboarding/pack-activation.d.ts.map +1 -1
- package/dist/onboarding/pack-activation.js.map +1 -1
- package/dist/onboarding/settings.d.ts +18 -0
- package/dist/onboarding/settings.d.ts.map +1 -1
- package/dist/onboarding/settings.js +28 -3
- package/dist/onboarding/settings.js.map +1 -1
- package/dist/platform/index.d.ts +74 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +200 -0
- package/dist/platform/index.js.map +1 -0
- package/dist/process-memory-diagnostics.d.ts +2 -1
- package/dist/process-memory-diagnostics.d.ts.map +1 -1
- package/dist/process-memory-diagnostics.js.map +1 -1
- package/dist/providers/model-ids.d.ts +1 -0
- package/dist/providers/model-ids.d.ts.map +1 -1
- package/dist/providers/model-ids.js +6 -4
- package/dist/providers/model-ids.js.map +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js.map +1 -1
- package/dist/tools/workflows/create-workflow.d.ts.map +1 -1
- package/dist/tools/workflows/create-workflow.js +5 -1
- package/dist/tools/workflows/create-workflow.js.map +1 -1
- package/dist/utils/local-observability.d.ts +19 -0
- package/dist/utils/local-observability.d.ts.map +1 -0
- package/dist/utils/local-observability.js +57 -0
- package/dist/utils/local-observability.js.map +1 -0
- package/dist/utils/notification-dispatch.d.ts +27 -12
- package/dist/utils/notification-dispatch.d.ts.map +1 -1
- package/dist/utils/notification-dispatch.js +46 -24
- package/dist/utils/notification-dispatch.js.map +1 -1
- package/dist/utils/signals-pubsub.d.ts +5 -3
- package/dist/utils/signals-pubsub.d.ts.map +1 -1
- package/dist/utils/signals-pubsub.js +8 -6
- package/dist/utils/signals-pubsub.js.map +1 -1
- package/dist/utils/wake-session.d.ts +44 -0
- package/dist/utils/wake-session.d.ts.map +1 -0
- package/dist/utils/wake-session.js +86 -0
- package/dist/utils/wake-session.js.map +1 -0
- package/dist/workflows/register-primitives.js +4 -1
- package/dist/workflows/register-primitives.js.map +1 -1
- package/package.json +23 -23
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { createSessionThreadAdvertisement } from "./agent-connections/session-ad
|
|
|
11
11
|
import { AgentConnectionsSignalProvider } from "./agent-connections/signal-provider.js";
|
|
12
12
|
import { createBackgroundCompletionEvents } from "./agents/background-completion-events.js";
|
|
13
13
|
import { createBackgroundCompletionCallbacks } from "./agents/background-completion.js";
|
|
14
|
-
import { hasCredentialStoreProvider, withCredentialTenantPreparation } from "./agents/credential-resolver.js";
|
|
14
|
+
import { hasCredentialStoreProvider, setCredentialLogger, withCredentialTenantPreparation } from "./agents/credential-resolver.js";
|
|
15
15
|
import { getDynamicWorkspace, getGoalJudgeTools } from "./agents/workspace.js";
|
|
16
16
|
import { createGitRefReminderReader, instructionSourcePaths, loadSessionInstructions, sessionInstructionRoots } from "./agents/prompts/agent-instructions.js";
|
|
17
17
|
import { getDynamicInstructions } from "./agents/instructions.js";
|
|
@@ -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";
|
|
@@ -54,12 +54,14 @@ import { stateSchema } from "./schema.js";
|
|
|
54
54
|
import { mastraBrand } from "./theme-palette.js";
|
|
55
55
|
import { DiscardingScoresStorage } from "./utils/discarding-scores-storage.js";
|
|
56
56
|
import { syncGateways } from "./utils/gateway-sync.js";
|
|
57
|
+
import { openLocalObservabilityStore } from "./utils/local-observability.js";
|
|
57
58
|
import { registerSessionAndWaitForMaintenance, unregisterSession } from "./utils/maintenance-lock.js";
|
|
58
59
|
import { createSignalsPubSub } from "./utils/signals-pubsub.js";
|
|
59
60
|
import { createResourceNotificationDispatcher, shouldHoldNotificationDelivery } from "./utils/notification-dispatch.js";
|
|
60
61
|
import { DEFAULT_RETENTION, createStorageMaintenance, resolveLocalDbFiles } from "./utils/storage-maintenance.js";
|
|
61
62
|
import { createStorage, createVectorStore } from "./utils/storage-factory.js";
|
|
62
63
|
import { acquireThreadLock, releaseThreadLock } from "./utils/thread-lock.js";
|
|
64
|
+
import { FOREIGN_THREAD, findWakeSession, sessionLeaseScopes } from "./utils/wake-session.js";
|
|
63
65
|
import { registerWorkflowBuilderPrimitives } from "./workflows/register-primitives.js";
|
|
64
66
|
import { autoApprovePolicy, denyPolicy, permissionModeToPolicy } from "./headless/policy.js";
|
|
65
67
|
import { runMC } from "./headless/run-mc.js";
|
|
@@ -82,7 +84,6 @@ import { RequestContext } from "@mastra/core/request-context";
|
|
|
82
84
|
import { TaskSignalProvider } from "@mastra/core/signals";
|
|
83
85
|
import { MastraCompositeStore } from "@mastra/core/storage";
|
|
84
86
|
import { DEFAULT_GOAL_JUDGE_PROMPT } from "@mastra/core/tools";
|
|
85
|
-
import { DuckDBStore } from "@mastra/duckdb";
|
|
86
87
|
import { GithubSignals } from "@mastra/github-signals";
|
|
87
88
|
import { LibSQLStore, LibSQLVector } from "@mastra/libsql";
|
|
88
89
|
import { MastraPlatformExporter, MastraStorageExporter, Observability, SensitiveDataFilter } from "@mastra/observability";
|
|
@@ -246,6 +247,10 @@ async function createMastraCodeAgentController(config) {
|
|
|
246
247
|
const modeless = config?.modes === false;
|
|
247
248
|
let activeSession;
|
|
248
249
|
const liveSessions = /* @__PURE__ */ new Set();
|
|
250
|
+
const sessionRouter = {
|
|
251
|
+
getSession: (sessionId) => controller.getSession(sessionId),
|
|
252
|
+
listLiveSessions: () => liveSessions
|
|
253
|
+
};
|
|
249
254
|
let pluginRuntimeController;
|
|
250
255
|
if (configDir !== ".mastracode") validateConfigDirName(configDir);
|
|
251
256
|
if (!config?.disableEnvFile) try {
|
|
@@ -322,11 +327,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
322
327
|
let observabilityDomain;
|
|
323
328
|
let observabilityWarning;
|
|
324
329
|
if (globalSettings.observability.localTracing) try {
|
|
325
|
-
const observabilityDuckDB =
|
|
326
|
-
id: "mastra-code-observability",
|
|
327
|
-
path: getObservabilityDatabasePath()
|
|
328
|
-
});
|
|
329
|
-
await observabilityDuckDB.db.getConnection();
|
|
330
|
+
const { store: observabilityDuckDB } = await openLocalObservabilityStore(getObservabilityDatabasePath());
|
|
330
331
|
observabilityDomain = observabilityDuckDB.observability;
|
|
331
332
|
} catch (err) {
|
|
332
333
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -415,16 +416,35 @@ async function createMastraCodeAgentController(config) {
|
|
|
415
416
|
const efficiencyScorer = createEfficiencyScorer();
|
|
416
417
|
const ownsNotificationDispatch = !configuredPubSub;
|
|
417
418
|
const dispatchLeasePubSub = ownsNotificationDispatch && !ownSignalsPubSub && process.platform !== "win32" ? createSignalsPubSub(project.resourceId) : void 0;
|
|
419
|
+
const notificationDispatchLeases = ownsNotificationDispatch ? (ownSignalsPubSub ?? dispatchLeasePubSub)?.getLeaseProvider() : void 0;
|
|
418
420
|
const notificationDispatcher = createResourceNotificationDispatcher({
|
|
419
421
|
getMastra: () => controller.getMastra(),
|
|
420
|
-
|
|
421
|
-
|
|
422
|
+
getSessionScopes: async () => (await Promise.all([...liveSessions].map(async (session) => {
|
|
423
|
+
const resourceId = session.identity.getResourceId();
|
|
424
|
+
return (await sessionLeaseScopes(session)).map((scope) => ({
|
|
425
|
+
resourceId,
|
|
426
|
+
scope
|
|
427
|
+
}));
|
|
428
|
+
}))).flat(),
|
|
429
|
+
leases: notificationDispatchLeases,
|
|
422
430
|
owner: `${ownerId}:${process.pid}:${randomUUID()}`,
|
|
423
431
|
onError: (error) => console.warn("Notification dispatch failed:", error)
|
|
424
432
|
});
|
|
425
|
-
const
|
|
426
|
-
const
|
|
427
|
-
if (!
|
|
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
|
+
};
|
|
441
|
+
const getWakeStreamOptions = async ({ resourceId, threadId, owner }) => {
|
|
442
|
+
const wake = owner ?? await findWakeSession(controller, liveSessions, {
|
|
443
|
+
resourceId,
|
|
444
|
+
threadId
|
|
445
|
+
});
|
|
446
|
+
if (!wake || wake === FOREIGN_THREAD) return void 0;
|
|
447
|
+
const { session } = wake;
|
|
428
448
|
const targetThread = await session.thread.getById({ threadId });
|
|
429
449
|
const metadata = targetThread?.resourceId === resourceId ? targetThread.metadata : void 0;
|
|
430
450
|
const modes = controller.listModes();
|
|
@@ -493,6 +513,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
493
513
|
isThreadActive: () => session.thread.getId() === threadId,
|
|
494
514
|
threadId,
|
|
495
515
|
resourceId,
|
|
516
|
+
sessionId: session.identity.getId(),
|
|
496
517
|
session: {
|
|
497
518
|
id: session.identity.getId(),
|
|
498
519
|
ownerId: session.identity.getOwnerId(),
|
|
@@ -546,7 +567,11 @@ async function createMastraCodeAgentController(config) {
|
|
|
546
567
|
resourceId: schedule.resourceId,
|
|
547
568
|
threadId: schedule.threadId
|
|
548
569
|
};
|
|
549
|
-
const
|
|
570
|
+
const owner = await resolveWakeOwner(target);
|
|
571
|
+
const streamOptions = owner && owner !== FOREIGN_THREAD ? await getWakeStreamOptions({
|
|
572
|
+
...target,
|
|
573
|
+
owner
|
|
574
|
+
}) : void 0;
|
|
550
575
|
const accepted = await codeAgent.sendSignal({
|
|
551
576
|
type: "user",
|
|
552
577
|
tagName: "user",
|
|
@@ -557,7 +582,8 @@ async function createMastraCodeAgentController(config) {
|
|
|
557
582
|
ifActive: { behavior: "deliver" },
|
|
558
583
|
ifIdle: {
|
|
559
584
|
behavior: "wake",
|
|
560
|
-
...streamOptions ? { streamOptions } : {}
|
|
585
|
+
...streamOptions ? { streamOptions } : {},
|
|
586
|
+
...owner === FOREIGN_THREAD ? { requireClaimedOwner: true } : {}
|
|
561
587
|
}
|
|
562
588
|
}).accepted;
|
|
563
589
|
if (accepted.action === "blocked" || accepted.action === "discard") throw new Error(`the agent did not accept the prompt (${accepted.action})`);
|
|
@@ -692,10 +718,20 @@ async function createMastraCodeAgentController(config) {
|
|
|
692
718
|
notifications: { deliveryPolicy: { decide: async (input) => {
|
|
693
719
|
const decision = defaultNotificationDeliveryDecision(input);
|
|
694
720
|
if (!input.record.resourceId) return decision;
|
|
695
|
-
const
|
|
721
|
+
const target = {
|
|
696
722
|
resourceId: input.record.resourceId,
|
|
697
723
|
threadId: input.record.threadId
|
|
698
|
-
}
|
|
724
|
+
};
|
|
725
|
+
const owner = decision.action === "deliver" || decision.action === "summarize" ? await resolveWakeOwner(target, notificationDispatchLeases) : await findWakeSession(controller, liveSessions, target, notificationDispatchLeases);
|
|
726
|
+
if (owner === FOREIGN_THREAD) return {
|
|
727
|
+
...decision,
|
|
728
|
+
hold: true
|
|
729
|
+
};
|
|
730
|
+
const streamOptions = owner ? await getWakeStreamOptions({
|
|
731
|
+
resourceId: input.record.resourceId,
|
|
732
|
+
threadId: input.record.threadId,
|
|
733
|
+
owner
|
|
734
|
+
}) : void 0;
|
|
699
735
|
const withOptions = streamOptions ? {
|
|
700
736
|
...decision,
|
|
701
737
|
streamOptions
|
|
@@ -703,7 +739,8 @@ async function createMastraCodeAgentController(config) {
|
|
|
703
739
|
if (!ownsNotificationDispatch) return withOptions;
|
|
704
740
|
return shouldHoldNotificationDelivery({
|
|
705
741
|
resourceId: input.record.resourceId,
|
|
706
|
-
|
|
742
|
+
scope: owner?.scope,
|
|
743
|
+
ownedHere: owner !== void 0,
|
|
707
744
|
dispatcher: notificationDispatcher
|
|
708
745
|
}) ? {
|
|
709
746
|
...withOptions,
|
|
@@ -749,11 +786,17 @@ async function createMastraCodeAgentController(config) {
|
|
|
749
786
|
const configured = config.inputProcessors({ requestContext });
|
|
750
787
|
return configured instanceof Promise ? configured.then(resolveProcessors) : resolveProcessors(configured);
|
|
751
788
|
},
|
|
752
|
-
outputProcessors: () =>
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
789
|
+
outputProcessors: ({ requestContext }) => {
|
|
790
|
+
const resolveProcessors = (configured) => [
|
|
791
|
+
new CyberRefusalHandler(),
|
|
792
|
+
...configured,
|
|
793
|
+
...readPluginProcessors().output.map((entry) => entry.value),
|
|
794
|
+
...pluginSignalLane?.getOutputProcessors() ?? []
|
|
795
|
+
];
|
|
796
|
+
if (typeof config?.outputProcessors !== "function") return resolveProcessors(config?.outputProcessors ?? []);
|
|
797
|
+
const configured = config.outputProcessors({ requestContext });
|
|
798
|
+
return configured instanceof Promise ? configured.then(resolveProcessors) : resolveProcessors(configured);
|
|
799
|
+
},
|
|
757
800
|
errorProcessors: [
|
|
758
801
|
new ProviderHistoryCompat(),
|
|
759
802
|
new CyberRefusalHandler(),
|
|
@@ -903,7 +946,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
903
946
|
...backgroundToolsEnabled ? { backgroundTasks: {
|
|
904
947
|
enabled: true,
|
|
905
948
|
recoverStaleTasksOnStart: false,
|
|
906
|
-
...createBackgroundCompletionCallbacks(() =>
|
|
949
|
+
...createBackgroundCompletionCallbacks(() => sessionRouter, backgroundCompletionEvents)
|
|
907
950
|
} } : {},
|
|
908
951
|
observability,
|
|
909
952
|
memory,
|
|
@@ -914,7 +957,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
914
957
|
defaultObserverModelId: DEFAULT_OM_MODEL_ID,
|
|
915
958
|
reflectorModel: "auto",
|
|
916
959
|
defaultReflectorModelId: DEFAULT_OM_MODEL_ID,
|
|
917
|
-
resolveAutoModelId: ({ currentModelId }) => resolveAutoOMModelId(currentModelId)
|
|
960
|
+
resolveAutoModelId: ({ currentModelId }) => resolveAutoOMModelId(currentModelId, canUseProvider)
|
|
918
961
|
},
|
|
919
962
|
agent: codeAgent,
|
|
920
963
|
subagents,
|
|
@@ -1281,6 +1324,7 @@ async function prepareAgentControllerMount(config) {
|
|
|
1281
1324
|
const finalize = async () => {
|
|
1282
1325
|
await controller.init();
|
|
1283
1326
|
validateExperimentalAgent(codeAgent, controller.getMastra());
|
|
1327
|
+
setCredentialLogger(controller.getMastra()?.getLogger());
|
|
1284
1328
|
if (weOwnTheMastra) {
|
|
1285
1329
|
const mastra = controller.getMastra();
|
|
1286
1330
|
if (mastra) await registerWorkflowBuilderPrimitives(mastra, {
|