@mastra/code-sdk 1.15.0-alpha.0 → 1.15.0-alpha.10
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 +59 -23
- 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 +25 -25
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,27 @@ 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 getWakeStreamOptions = async ({ resourceId, threadId }) => {
|
|
426
|
-
const
|
|
427
|
-
|
|
433
|
+
const getWakeStreamOptions = async ({ resourceId, threadId, owner }) => {
|
|
434
|
+
const wake = owner ?? await findWakeSession(controller, liveSessions, {
|
|
435
|
+
resourceId,
|
|
436
|
+
threadId
|
|
437
|
+
});
|
|
438
|
+
if (!wake || wake === FOREIGN_THREAD) return void 0;
|
|
439
|
+
const { session } = wake;
|
|
428
440
|
const targetThread = await session.thread.getById({ threadId });
|
|
429
441
|
const metadata = targetThread?.resourceId === resourceId ? targetThread.metadata : void 0;
|
|
430
442
|
const modes = controller.listModes();
|
|
@@ -493,6 +505,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
493
505
|
isThreadActive: () => session.thread.getId() === threadId,
|
|
494
506
|
threadId,
|
|
495
507
|
resourceId,
|
|
508
|
+
sessionId: session.identity.getId(),
|
|
496
509
|
session: {
|
|
497
510
|
id: session.identity.getId(),
|
|
498
511
|
ownerId: session.identity.getOwnerId(),
|
|
@@ -692,10 +705,25 @@ async function createMastraCodeAgentController(config) {
|
|
|
692
705
|
notifications: { deliveryPolicy: { decide: async (input) => {
|
|
693
706
|
const decision = defaultNotificationDeliveryDecision(input);
|
|
694
707
|
if (!input.record.resourceId) return decision;
|
|
695
|
-
const
|
|
708
|
+
const target = {
|
|
696
709
|
resourceId: input.record.resourceId,
|
|
697
710
|
threadId: input.record.threadId
|
|
698
|
-
}
|
|
711
|
+
};
|
|
712
|
+
let owner = await findWakeSession(controller, liveSessions, target, notificationDispatchLeases);
|
|
713
|
+
if (!owner && config?.resumeWakeSession && (decision.action === "deliver" || decision.action === "summarize")) {
|
|
714
|
+
await config.resumeWakeSession(target);
|
|
715
|
+
owner = await findWakeSession(controller, liveSessions, target, notificationDispatchLeases);
|
|
716
|
+
if (!owner) throw new Error(`No session owns resource ${target.resourceId} to run its wake on thread ${target.threadId}.`);
|
|
717
|
+
}
|
|
718
|
+
if (owner === FOREIGN_THREAD) return {
|
|
719
|
+
...decision,
|
|
720
|
+
hold: true
|
|
721
|
+
};
|
|
722
|
+
const streamOptions = owner ? await getWakeStreamOptions({
|
|
723
|
+
resourceId: input.record.resourceId,
|
|
724
|
+
threadId: input.record.threadId,
|
|
725
|
+
owner
|
|
726
|
+
}) : void 0;
|
|
699
727
|
const withOptions = streamOptions ? {
|
|
700
728
|
...decision,
|
|
701
729
|
streamOptions
|
|
@@ -703,7 +731,8 @@ async function createMastraCodeAgentController(config) {
|
|
|
703
731
|
if (!ownsNotificationDispatch) return withOptions;
|
|
704
732
|
return shouldHoldNotificationDelivery({
|
|
705
733
|
resourceId: input.record.resourceId,
|
|
706
|
-
|
|
734
|
+
scope: owner?.scope,
|
|
735
|
+
ownedHere: owner !== void 0,
|
|
707
736
|
dispatcher: notificationDispatcher
|
|
708
737
|
}) ? {
|
|
709
738
|
...withOptions,
|
|
@@ -749,11 +778,17 @@ async function createMastraCodeAgentController(config) {
|
|
|
749
778
|
const configured = config.inputProcessors({ requestContext });
|
|
750
779
|
return configured instanceof Promise ? configured.then(resolveProcessors) : resolveProcessors(configured);
|
|
751
780
|
},
|
|
752
|
-
outputProcessors: () =>
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
781
|
+
outputProcessors: ({ requestContext }) => {
|
|
782
|
+
const resolveProcessors = (configured) => [
|
|
783
|
+
new CyberRefusalHandler(),
|
|
784
|
+
...configured,
|
|
785
|
+
...readPluginProcessors().output.map((entry) => entry.value),
|
|
786
|
+
...pluginSignalLane?.getOutputProcessors() ?? []
|
|
787
|
+
];
|
|
788
|
+
if (typeof config?.outputProcessors !== "function") return resolveProcessors(config?.outputProcessors ?? []);
|
|
789
|
+
const configured = config.outputProcessors({ requestContext });
|
|
790
|
+
return configured instanceof Promise ? configured.then(resolveProcessors) : resolveProcessors(configured);
|
|
791
|
+
},
|
|
757
792
|
errorProcessors: [
|
|
758
793
|
new ProviderHistoryCompat(),
|
|
759
794
|
new CyberRefusalHandler(),
|
|
@@ -903,7 +938,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
903
938
|
...backgroundToolsEnabled ? { backgroundTasks: {
|
|
904
939
|
enabled: true,
|
|
905
940
|
recoverStaleTasksOnStart: false,
|
|
906
|
-
...createBackgroundCompletionCallbacks(() =>
|
|
941
|
+
...createBackgroundCompletionCallbacks(() => sessionRouter, backgroundCompletionEvents)
|
|
907
942
|
} } : {},
|
|
908
943
|
observability,
|
|
909
944
|
memory,
|
|
@@ -914,7 +949,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
914
949
|
defaultObserverModelId: DEFAULT_OM_MODEL_ID,
|
|
915
950
|
reflectorModel: "auto",
|
|
916
951
|
defaultReflectorModelId: DEFAULT_OM_MODEL_ID,
|
|
917
|
-
resolveAutoModelId: ({ currentModelId }) => resolveAutoOMModelId(currentModelId)
|
|
952
|
+
resolveAutoModelId: ({ currentModelId }) => resolveAutoOMModelId(currentModelId, canUseProvider)
|
|
918
953
|
},
|
|
919
954
|
agent: codeAgent,
|
|
920
955
|
subagents,
|
|
@@ -1281,6 +1316,7 @@ async function prepareAgentControllerMount(config) {
|
|
|
1281
1316
|
const finalize = async () => {
|
|
1282
1317
|
await controller.init();
|
|
1283
1318
|
validateExperimentalAgent(codeAgent, controller.getMastra());
|
|
1319
|
+
setCredentialLogger(controller.getMastra()?.getLogger());
|
|
1284
1320
|
if (weOwnTheMastra) {
|
|
1285
1321
|
const mastra = controller.getMastra();
|
|
1286
1322
|
if (mastra) await registerWorkflowBuilderPrimitives(mastra, {
|