@mastra/factory 0.24.0-alpha.9 → 0.25.0-alpha.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/README.md +40 -13
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +18 -4
- package/dist/auth.js.map +1 -1
- package/dist/boards/review.d.ts.map +1 -1
- package/dist/boards/review.js +3 -2
- package/dist/boards/review.js.map +1 -1
- package/dist/environment/build-runner.js +2 -1
- package/dist/environment/build-runner.js.map +1 -1
- package/dist/environment/build-workflow.js +1 -1
- package/dist/environment/build-workflow.js.map +1 -1
- package/dist/environment/build.js +16 -14
- package/dist/environment/build.js.map +1 -1
- package/dist/factory.d.ts +3 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +172 -88
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +15 -2
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/github/app-identity.js.map +1 -1
- package/dist/integrations/github/integration.js +1 -1
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/reconcile-worker.js +1 -1
- package/dist/integrations/github/reconcile-worker.js.map +1 -1
- package/dist/integrations/github/routes.d.ts +1 -1
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +24 -13
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +53 -9
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.js +2 -2
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/github/session-subscriptions.d.ts.map +1 -1
- package/dist/integrations/github/session-subscriptions.js +1 -2
- package/dist/integrations/github/session-subscriptions.js.map +1 -1
- package/dist/integrations/github/subscriptions.d.ts +7 -4
- package/dist/integrations/github/subscriptions.d.ts.map +1 -1
- package/dist/integrations/github/subscriptions.js +5 -5
- package/dist/integrations/github/subscriptions.js.map +1 -1
- package/dist/integrations/gitlab/api.js.map +1 -1
- package/dist/integrations/gitlab/integration.js.map +1 -1
- package/dist/integrations/gitlab/reconciliation-config.js +2 -1
- package/dist/integrations/gitlab/reconciliation-config.js.map +1 -1
- package/dist/integrations/gitlab/routes.d.ts.map +1 -1
- package/dist/integrations/gitlab/routes.js +10 -6
- package/dist/integrations/gitlab/routes.js.map +1 -1
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/gitlab/session-subscriptions.d.ts.map +1 -1
- package/dist/integrations/gitlab/session-subscriptions.js +1 -2
- package/dist/integrations/gitlab/session-subscriptions.js.map +1 -1
- package/dist/integrations/gitlab/subscriptions.d.ts +7 -4
- package/dist/integrations/gitlab/subscriptions.d.ts.map +1 -1
- package/dist/integrations/gitlab/subscriptions.js +5 -5
- package/dist/integrations/gitlab/subscriptions.js.map +1 -1
- package/dist/integrations/incidentio/api.js.map +1 -1
- package/dist/integrations/incidentio/integration.js.map +1 -1
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/issue-reconcile-worker.js +1 -1
- package/dist/integrations/issue-reconcile-worker.js.map +1 -1
- package/dist/integrations/issue-reconciler.js +1 -1
- package/dist/integrations/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/api.js.map +1 -1
- package/dist/integrations/jira/integration.js.map +1 -1
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
- package/dist/integrations/linear/agent-tools.js.map +1 -1
- package/dist/integrations/linear/integration.js.map +1 -1
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/api-client.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +1 -1
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.js +2 -2
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/gitlab/event-worker.js.map +1 -1
- package/dist/integrations/platform/gitlab/integration.js.map +1 -1
- package/dist/integrations/platform/incidentio/integration.js +2 -1
- package/dist/integrations/platform/incidentio/integration.js.map +1 -1
- package/dist/integrations/platform/jira/integration.js.map +1 -1
- package/dist/integrations/platform/linear/event-worker.js +1 -1
- package/dist/integrations/platform/linear/event-worker.js.map +1 -1
- package/dist/integrations/platform/linear/integration.js.map +1 -1
- package/dist/{session → integrations/slack}/channel-reply-processor.d.ts +11 -9
- package/dist/integrations/slack/channel-reply-processor.d.ts.map +1 -0
- package/dist/integrations/slack/channel-reply-processor.js +61 -0
- package/dist/integrations/slack/channel-reply-processor.js.map +1 -0
- package/dist/integrations/slack/channel-session-link-processor.d.ts.map +1 -0
- package/dist/{session → integrations/slack}/channel-session-link-processor.js +14 -4
- package/dist/integrations/slack/channel-session-link-processor.js.map +1 -0
- package/dist/integrations/slack/connect-route.js +1 -1
- package/dist/integrations/slack/connect-route.js.map +1 -1
- package/dist/integrations/slack/feed-publisher.js +1 -1
- package/dist/integrations/slack/feed-publisher.js.map +1 -1
- package/dist/integrations/slack/integration.d.ts +25 -1
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +56 -6
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/slack/reply-reminder-processor.d.ts +23 -0
- package/dist/integrations/slack/reply-reminder-processor.d.ts.map +1 -0
- package/dist/integrations/slack/reply-reminder-processor.js +58 -0
- package/dist/integrations/slack/reply-reminder-processor.js.map +1 -0
- package/dist/integrations/slack/reply-tool.d.ts +31 -0
- package/dist/integrations/slack/reply-tool.d.ts.map +1 -0
- package/dist/integrations/slack/reply-tool.js +203 -0
- package/dist/integrations/slack/reply-tool.js.map +1 -0
- package/dist/integrations/slack/share-file-tool.d.ts +45 -0
- package/dist/integrations/slack/share-file-tool.d.ts.map +1 -0
- package/dist/integrations/slack/share-file-tool.js +106 -0
- package/dist/integrations/slack/share-file-tool.js.map +1 -0
- package/dist/integrations/slack/slack.d.ts +16 -5
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +141 -40
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/integrations/subscription-session.d.ts +0 -1
- package/dist/integrations/subscription-session.d.ts.map +1 -1
- package/dist/integrations/subscription-session.js +1 -4
- package/dist/integrations/subscription-session.js.map +1 -1
- package/dist/integrations/workos/integration.js.map +1 -1
- package/dist/mcp/events.d.ts +73 -0
- package/dist/mcp/events.d.ts.map +1 -0
- package/dist/mcp/events.js +158 -0
- package/dist/mcp/events.js.map +1 -0
- package/dist/mcp/routes.d.ts +0 -1
- package/dist/mcp/routes.d.ts.map +1 -1
- package/dist/mcp/routes.js +31 -4
- package/dist/mcp/routes.js.map +1 -1
- package/dist/packages/_internals/workspace/dist/index.js +18 -1
- package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
- package/dist/platform-auth-host.d.ts.map +1 -1
- package/dist/platform-auth-host.js +1 -1
- package/dist/platform-auth-host.js.map +1 -1
- package/dist/routes/attention-activity.js.map +1 -1
- package/dist/routes/attention-parked.js.map +1 -1
- package/dist/routes/attention-providers.js.map +1 -1
- package/dist/routes/automation-runs.js.map +1 -1
- package/dist/routes/config.d.ts +8 -7
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +70 -28
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +2 -0
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +2 -2
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/custom-provider-source.js.map +1 -1
- package/dist/routes/fs.d.ts +31 -23
- package/dist/routes/fs.d.ts.map +1 -1
- package/dist/routes/fs.js +218 -64
- package/dist/routes/fs.js.map +1 -1
- package/dist/routes/intake.js +2 -1
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/knowledge.js +1 -1
- package/dist/routes/knowledge.js.map +1 -1
- package/dist/routes/oauth.js +3 -2
- package/dist/routes/oauth.js.map +1 -1
- package/dist/routes/projects.d.ts +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +33 -31
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/provider-credentials.d.ts.map +1 -1
- package/dist/routes/provider-credentials.js +6 -1
- package/dist/routes/provider-credentials.js.map +1 -1
- package/dist/routes/session-access.d.ts +60 -0
- package/dist/routes/session-access.d.ts.map +1 -0
- package/dist/routes/session-access.js +202 -0
- package/dist/routes/session-access.js.map +1 -0
- package/dist/routes/skills.d.ts +2 -4
- package/dist/routes/skills.d.ts.map +1 -1
- package/dist/routes/skills.js +23 -68
- package/dist/routes/skills.js.map +1 -1
- package/dist/routes/source-control-sessions.d.ts +8 -1
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +239 -19
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +7 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +20 -8
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/tenant-credentials.js.map +1 -1
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/binding-context.js +11 -9
- package/dist/rules/binding-context.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +21 -13
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts +2 -2
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +3 -3
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts +4 -0
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +36 -4
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/tools.js +2 -2
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/sandbox/callback-factory-sandbox.js.map +1 -1
- package/dist/sandbox/local-factory-sandbox.js.map +1 -1
- package/dist/sandbox/session-retirement.d.ts +11 -0
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +38 -1
- package/dist/sandbox/session-retirement.js.map +1 -1
- package/dist/sandbox/session-sandbox.d.ts +2 -0
- package/dist/sandbox/session-sandbox.d.ts.map +1 -1
- package/dist/sandbox/session-sandbox.js +5 -1
- package/dist/sandbox/session-sandbox.js.map +1 -1
- package/dist/secret-encryption.d.ts.map +1 -1
- package/dist/secret-encryption.js +65 -25
- package/dist/secret-encryption.js.map +1 -1
- package/dist/session/credential-policy.d.ts +4 -2
- package/dist/session/credential-policy.d.ts.map +1 -1
- package/dist/session/credential-policy.js +18 -7
- package/dist/session/credential-policy.js.map +1 -1
- package/dist/session/default-model-hydration.d.ts +1 -0
- package/dist/session/default-model-hydration.d.ts.map +1 -1
- package/dist/session/default-model-hydration.js +3 -2
- package/dist/session/default-model-hydration.js.map +1 -1
- package/dist/session/environment-state-processor.js +1 -1
- package/dist/session/environment-state-processor.js.map +1 -1
- package/dist/session/factory-session.d.ts.map +1 -1
- package/dist/session/factory-session.js +14 -1
- package/dist/session/factory-session.js.map +1 -1
- package/dist/session/filesystem-capture.d.ts +3 -3
- package/dist/session/filesystem-capture.d.ts.map +1 -1
- package/dist/session/filesystem-capture.js +16 -17
- package/dist/session/filesystem-capture.js.map +1 -1
- package/dist/session/first-exec-capture.d.ts +1 -1
- package/dist/session/first-exec-capture.d.ts.map +1 -1
- package/dist/session/first-exec-capture.js +1 -1
- package/dist/session/first-exec-capture.js.map +1 -1
- package/dist/session/first-message-capture.d.ts +1 -1
- package/dist/session/first-message-capture.d.ts.map +1 -1
- package/dist/session/first-message-capture.js +1 -1
- package/dist/session/first-message-capture.js.map +1 -1
- package/dist/session/live-sessions.d.ts +1 -1
- package/dist/session/live-sessions.js +1 -1
- package/dist/session/live-sessions.js.map +1 -1
- package/dist/session/memory-settings-hydration.d.ts +1 -1
- package/dist/session/memory-settings-hydration.d.ts.map +1 -1
- package/dist/session/memory-settings-hydration.js +2 -1
- package/dist/session/memory-settings-hydration.js.map +1 -1
- package/dist/session/resource-migration.d.ts +105 -0
- package/dist/session/resource-migration.d.ts.map +1 -0
- package/dist/session/resource-migration.js +195 -0
- package/dist/session/resource-migration.js.map +1 -0
- package/dist/session/run-audit.d.ts +1 -0
- package/dist/session/run-audit.d.ts.map +1 -1
- package/dist/session/run-audit.js +7 -2
- package/dist/session/run-audit.js.map +1 -1
- package/dist/session/session-threads.d.ts +63 -0
- package/dist/session/session-threads.d.ts.map +1 -0
- package/dist/session/session-threads.js +97 -0
- package/dist/session/session-threads.js.map +1 -0
- package/dist/session/source-control-tools.js +8 -8
- package/dist/session/source-control-tools.js.map +1 -1
- package/dist/session/thinking-default.d.ts +6 -13
- package/dist/session/thinking-default.d.ts.map +1 -1
- package/dist/session/thinking-default.js +19 -24
- package/dist/session/thinking-default.js.map +1 -1
- package/dist/session/thread-session-stamp.d.ts +21 -0
- package/dist/session/thread-session-stamp.d.ts.map +1 -0
- package/dist/session/thread-session-stamp.js +20 -0
- package/dist/session/thread-session-stamp.js.map +1 -0
- package/dist/session/thread-title-mirror.d.ts +1 -1
- package/dist/session/thread-title-mirror.d.ts.map +1 -1
- package/dist/session/thread-title-mirror.js +1 -1
- package/dist/session/thread-title-mirror.js.map +1 -1
- package/dist/session-owner-signal.d.ts +2 -0
- package/dist/session-owner-signal.d.ts.map +1 -0
- package/dist/session-owner-signal.js +6 -0
- package/dist/session-owner-signal.js.map +1 -0
- package/dist/skills/service.d.ts +11 -14
- package/dist/skills/service.d.ts.map +1 -1
- package/dist/skills/service.js +12 -22
- package/dist/skills/service.js.map +1 -1
- package/dist/spa-static.js.map +1 -1
- package/dist/state-signing.js +1 -1
- package/dist/state-signing.js.map +1 -1
- package/dist/storage/domains/audit/actions.d.ts +1 -0
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +2 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -1
- package/dist/storage/domains/audit/agent-audit.js +2 -2
- package/dist/storage/domains/audit/agent-audit.js.map +1 -1
- package/dist/storage/domains/audit/base.d.ts +18 -2
- package/dist/storage/domains/audit/base.d.ts.map +1 -1
- package/dist/storage/domains/audit/base.js +22 -4
- package/dist/storage/domains/audit/base.js.map +1 -1
- package/dist/storage/domains/audit/domain.js.map +1 -1
- package/dist/storage/domains/channel-identity/base.js.map +1 -1
- package/dist/storage/domains/comments/base.js.map +1 -1
- package/dist/storage/domains/comments/domain.js.map +1 -1
- package/dist/storage/domains/comments/feed-context.js.map +1 -1
- package/dist/storage/domains/credentials/base.js.map +1 -1
- package/dist/storage/domains/custom-providers/base.js.map +1 -1
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/integrations/base.d.ts +8 -0
- package/dist/storage/domains/integrations/base.d.ts.map +1 -1
- package/dist/storage/domains/integrations/base.js +7 -0
- package/dist/storage/domains/integrations/base.js.map +1 -1
- package/dist/storage/domains/memory-settings/base.js.map +1 -1
- package/dist/storage/domains/model-defaults/base.d.ts +8 -0
- package/dist/storage/domains/model-defaults/base.d.ts.map +1 -1
- package/dist/storage/domains/model-defaults/base.js +18 -0
- package/dist/storage/domains/model-defaults/base.js.map +1 -1
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/queue-health/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +44 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +109 -3
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +23 -1
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +35 -0
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +14 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +25 -1
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/board-version.js.map +1 -1
- package/dist/storage/domains/work-items/metrics.js.map +1 -1
- package/dist/tools/approval-tools.js +1 -1
- package/dist/tools/approval-tools.js.map +1 -1
- package/dist/tools/deliver.d.ts +8 -5
- package/dist/tools/deliver.d.ts.map +1 -1
- package/dist/tools/deliver.js +22 -8
- package/dist/tools/deliver.js.map +1 -1
- package/dist/tools/messaging-tools.d.ts +1 -1
- package/dist/tools/messaging-tools.d.ts.map +1 -1
- package/dist/tools/messaging-tools.js +203 -72
- package/dist/tools/messaging-tools.js.map +1 -1
- package/dist/tools/permissions.d.ts +1 -1
- package/dist/tools/permissions.d.ts.map +1 -1
- package/dist/tools/permissions.js +3 -2
- package/dist/tools/permissions.js.map +1 -1
- package/dist/tools/reports.d.ts.map +1 -1
- package/dist/tools/reports.js +10 -3
- package/dist/tools/reports.js.map +1 -1
- package/dist/tools/run-watch.d.ts +2 -0
- package/dist/tools/run-watch.d.ts.map +1 -1
- package/dist/tools/run-watch.js +42 -2
- package/dist/tools/run-watch.js.map +1 -1
- package/dist/tools/sandbox-tools.d.ts +12 -0
- package/dist/tools/sandbox-tools.d.ts.map +1 -0
- package/dist/tools/sandbox-tools.js +40 -0
- package/dist/tools/sandbox-tools.js.map +1 -0
- package/dist/tools/scope.d.ts +2 -1
- package/dist/tools/scope.d.ts.map +1 -1
- package/dist/tools/scope.js +5 -7
- package/dist/tools/scope.js.map +1 -1
- package/dist/tools/session-tools.d.ts +1 -1
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +39 -18
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/sessions-state-processor.js +2 -2
- package/dist/tools/sessions-state-processor.js.map +1 -1
- package/dist/tools/side-sessions.d.ts +1 -1
- package/dist/tools/side-sessions.d.ts.map +1 -1
- package/dist/tools/side-sessions.js +1 -1
- package/dist/tools/side-sessions.js.map +1 -1
- package/dist/work-item-branch.d.ts +11 -3
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +34 -9
- package/dist/work-item-branch.js.map +1 -1
- package/dist/workspace.d.ts +7 -3
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +32 -17
- package/dist/workspace.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +2 -2
- package/package.json +16 -15
- package/dist/session/channel-reply-processor.d.ts.map +0 -1
- package/dist/session/channel-reply-processor.js +0 -46
- package/dist/session/channel-reply-processor.js.map +0 -1
- package/dist/session/channel-session-link-processor.d.ts.map +0 -1
- package/dist/session/channel-session-link-processor.js.map +0 -1
- /package/dist/{session → integrations/slack}/channel-session-link-processor.d.ts +0 -0
package/dist/factory.js
CHANGED
|
@@ -19,8 +19,10 @@ import { recordFactoryPullRequestProvenance, resolveFactoryPullRequestParentWork
|
|
|
19
19
|
import { dismissStaleFactoryReviews } from "./integrations/github/stale-reviews.js";
|
|
20
20
|
import { PlatformApiClient, platformApiClientConfigFromEnv } from "./integrations/platform/api-client.js";
|
|
21
21
|
import { buildPlatformConnectRoutes } from "./integrations/platform/connect/routes.js";
|
|
22
|
+
import { createSessionAccessGuard } from "./routes/session-access.js";
|
|
22
23
|
import { observeSessionFirstExec } from "./session/first-exec-capture.js";
|
|
23
24
|
import { observeSessionFilesystem } from "./session/filesystem-capture.js";
|
|
25
|
+
import { sessionMemoryResourceId, sessionStampCounts } from "./session/session-threads.js";
|
|
24
26
|
import { createPlaintextFactorySecretEncryption } from "./secret-encryption.js";
|
|
25
27
|
import { ModelCredentialsStorage } from "./storage/domains/credentials/base.js";
|
|
26
28
|
import { createTenantCredentialPrimer, primeTenantCredentials, registerTenantCredentialResolver } from "./routes/tenant-credentials.js";
|
|
@@ -64,14 +66,14 @@ import { createFactoryTransitionTools } from "./rules/tools.js";
|
|
|
64
66
|
import { CallbackFactorySandbox } from "./sandbox/callback-factory-sandbox.js";
|
|
65
67
|
import { SessionRetirementCoordinator } from "./sandbox/session-retirement.js";
|
|
66
68
|
import { handleServerError } from "./server-error.js";
|
|
67
|
-
import { FactoryChannelReplyProcessor } from "./session/channel-reply-processor.js";
|
|
68
|
-
import { FactoryChannelSessionLinkProcessor } from "./session/channel-session-link-processor.js";
|
|
69
69
|
import { hydrateSessionDefaultModel } from "./session/default-model-hydration.js";
|
|
70
70
|
import { observeSessionFirstMessage } from "./session/first-message-capture.js";
|
|
71
71
|
import { LiveSessions } from "./session/live-sessions.js";
|
|
72
72
|
import { FactoryReplyCredentialProcessor } from "./session/reply-credential-processor.js";
|
|
73
|
+
import { migrateSessionResources, privatizeOwnerResourceSessions } from "./session/resource-migration.js";
|
|
73
74
|
import { createSourceControlTools } from "./session/source-control-tools.js";
|
|
74
|
-
import {
|
|
75
|
+
import { resolveFactoryThinkingLevel } from "./session/thinking-default.js";
|
|
76
|
+
import { observeSessionThreadStamp } from "./session/thread-session-stamp.js";
|
|
75
77
|
import { observeSessionThreadTitle } from "./session/thread-title-mirror.js";
|
|
76
78
|
import { createSpaStaticMiddleware, resolveUiDistDir } from "./spa-static.js";
|
|
77
79
|
import { createStateSigner } from "./state-signing.js";
|
|
@@ -83,10 +85,13 @@ import { CustomProvidersStorage } from "./storage/domains/custom-providers/base.
|
|
|
83
85
|
import { FilesystemStorage } from "./storage/domains/filesystem/base.js";
|
|
84
86
|
import { IntegrationStorage } from "./storage/domains/integrations/base.js";
|
|
85
87
|
import { ModelDefaultsStorage } from "./storage/domains/model-defaults/base.js";
|
|
88
|
+
import { createFactorySandboxTools } from "./tools/sandbox-tools.js";
|
|
86
89
|
import { FactorySessionsStateProcessor } from "./tools/sessions-state-processor.js";
|
|
90
|
+
import { RequestContext } from "@mastra/core/request-context";
|
|
87
91
|
import { hasAuthInit, isUserProvider } from "@mastra/core/server";
|
|
88
92
|
import { MastraAuthStudio } from "@mastra/auth-studio";
|
|
89
93
|
import { prepareAgentControllerMount } from "@mastra/code-sdk";
|
|
94
|
+
import { getDynamicMemory } from "@mastra/code-sdk/agents/memory";
|
|
90
95
|
import { AgentControllerChannels } from "@mastra/core/channels";
|
|
91
96
|
import { EventEmitterPubSub } from "@mastra/core/events";
|
|
92
97
|
import { describeFactorySandbox, isFactorySandbox } from "@mastra/core/workspace";
|
|
@@ -112,6 +117,12 @@ import { describeFactorySandbox, isFactorySandbox } from "@mastra/core/workspace
|
|
|
112
117
|
* and the storage domains those capabilities require.
|
|
113
118
|
*/
|
|
114
119
|
const CONTROLLER_ID = "code";
|
|
120
|
+
/**
|
|
121
|
+
* Providers whose sandbox a session's agent may recreate itself. Each needs
|
|
122
|
+
* its `destroy()` to leave the instance able to start a fresh VM, proven
|
|
123
|
+
* against the real provider.
|
|
124
|
+
*/
|
|
125
|
+
const SELF_RECREATE_SANDBOX_PROVIDERS = /* @__PURE__ */ new Set(["platform"]);
|
|
115
126
|
/** Why a wake couldn't be run as its Factory session's owner. */
|
|
116
127
|
const WAKE_OWNER_UNRESOLVED = {
|
|
117
128
|
"session-not-found": "no Factory session row names its owner",
|
|
@@ -123,53 +134,18 @@ function hasPlatformCredentials() {
|
|
|
123
134
|
}
|
|
124
135
|
/**
|
|
125
136
|
* Default auth provider — `MastraAuthStudio`, which proxies identity to the
|
|
126
|
-
* shared Mastra platform API
|
|
127
|
-
* `MASTRA_ORGANIZATION_ID`,
|
|
128
|
-
* this helper only derives a cookie-domain fallback from the factory's
|
|
129
|
-
* `publicUrl`.
|
|
130
|
-
*
|
|
131
|
-
* Cookie-domain resolution (Studio picks the first that wins):
|
|
132
|
-
* 1. explicit `MASTRA_COOKIE_DOMAIN` env, if set;
|
|
133
|
-
* 2. `.mastra.ai` when `sharedApiUrl` is on `.mastra.ai`;
|
|
134
|
-
* 3. this parent-domain fallback derived from `publicUrl` — so a deploy on
|
|
135
|
-
* `https://foo.mastra.cloud` mints cookies with `Domain=.mastra.cloud`
|
|
136
|
-
* without the caller wiring the env var by hand.
|
|
137
|
-
* 4. otherwise host-only (no `Domain=`), which is correct for `localhost`.
|
|
138
|
-
*/
|
|
139
|
-
function buildDefaultStudioAuth(publicUrl) {
|
|
140
|
-
return new MastraAuthStudio({ cookieDomain: parentDomainFromPublicUrl(publicUrl) });
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Derive a parent cookie domain from `publicUrl` by stripping the leftmost
|
|
144
|
-
* label — the same shape platform-API's env injection uses (see
|
|
145
|
-
* `platform/servers/api/src/lib/studio-env-vars.ts`: `.${routingDomain.replace(/^[^.]+\./, '')}`).
|
|
137
|
+
* shared Mastra platform API and resolves its own env (`MASTRA_SHARED_API_URL`,
|
|
138
|
+
* `MASTRA_ORGANIZATION_ID`, ...).
|
|
146
139
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* falls through to host-only cookies. Callers that need a different scope
|
|
154
|
-
* pass `MASTRA_COOKIE_DOMAIN` explicitly (Studio honors that first).
|
|
140
|
+
* The session cookie is **host-only** (`__Host-wos-session` on secure
|
|
141
|
+
* deployments). No parent `Domain` (e.g. `.mastra.cloud`) is derived from
|
|
142
|
+
* `publicUrl`: a parent-scoped session cookie is sent by the browser to every
|
|
143
|
+
* host under that parent, including other tenants' deployments. Callers that
|
|
144
|
+
* really want a domain-scoped cookie pass their own `MastraAuthStudio` (with
|
|
145
|
+
* `cookieDomain`) via `auth:`.
|
|
155
146
|
*/
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (hostname.includes(":")) return true;
|
|
159
|
-
return /^\d+(?:\.\d+){3}$/.test(hostname);
|
|
160
|
-
}
|
|
161
|
-
function parentDomainFromPublicUrl(publicUrl) {
|
|
162
|
-
let hostname;
|
|
163
|
-
try {
|
|
164
|
-
hostname = new URL(publicUrl).hostname.toLowerCase();
|
|
165
|
-
} catch {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (hostname === "localhost" || isIpLiteral(hostname)) return void 0;
|
|
169
|
-
for (const parent of KNOWN_PLATFORM_COOKIE_PARENTS) {
|
|
170
|
-
if (hostname === parent) return void 0;
|
|
171
|
-
if (hostname.endsWith(`.${parent}`)) return `.${parent}`;
|
|
172
|
-
}
|
|
147
|
+
function buildDefaultStudioAuth() {
|
|
148
|
+
return new MastraAuthStudio();
|
|
173
149
|
}
|
|
174
150
|
/** A session parking or being answered is inbox news, so the registry bumps the project's feed. */
|
|
175
151
|
function liveSessionsTouchingTheFeed(controller, eventBus) {
|
|
@@ -221,6 +197,8 @@ var MastraFactory = class {
|
|
|
221
197
|
#factoryProcessor;
|
|
222
198
|
/** Environment builds through the sandbox's `builds`; undefined when the sandbox has none. */
|
|
223
199
|
#environmentBuilds;
|
|
200
|
+
/** The background session resource migration; resolves `true` when it moved run bindings. */
|
|
201
|
+
#sessionResourceMigration;
|
|
224
202
|
#preparing = false;
|
|
225
203
|
constructor(config) {
|
|
226
204
|
if (!config?.storage) throw new Error("MastraFactory: 'storage' is required. Pass a FactoryStorage backend — e.g. new PgFactoryStorage({ connectionString }) from '@mastra/pg' for deployments, or new LibSQLFactoryStorage({ url }) from '@mastra/libsql' for local dev.");
|
|
@@ -257,13 +235,14 @@ var MastraFactory = class {
|
|
|
257
235
|
const pubsub = this.#config.pubsub;
|
|
258
236
|
const eventBus = pubsub ?? new EventEmitterPubSub();
|
|
259
237
|
const configuredAuth = this.#config.auth;
|
|
260
|
-
const auth = configuredAuth === null ? void 0 : configuredAuth ?? buildDefaultStudioAuth(
|
|
238
|
+
const auth = configuredAuth === null ? void 0 : configuredAuth ?? buildDefaultStudioAuth();
|
|
261
239
|
if (auth && !this.#config.secretEncryption) console.warn("[factory] auth is enabled but 'secretEncryption' is not configured. Persisted model credentials, custom-provider API keys, and integration secrets will be stored as plaintext. Provide 'secretEncryption' (e.g. via FACTORY_CREDENTIAL_ENCRYPTION_KEY) to encrypt them at rest.");
|
|
262
240
|
const secretEncryption = this.#config.secretEncryption ?? createPlaintextFactorySecretEncryption();
|
|
263
241
|
const deploymentModelProviders = resolveDeploymentModelProviders(this.#config.deploymentModelProviders);
|
|
264
242
|
const routeAuth = createFactoryRouteAuth(auth);
|
|
265
243
|
const mcpConfig = this.#config.mcp;
|
|
266
244
|
const mcpAuthorizationServers = mcpConfig === false || mcpConfig?.enabled === false ? [] : resolveMcpAuthorizationServers(auth?.name, mcpConfig);
|
|
245
|
+
const mcpEnabled = Boolean(auth) && mcpAuthorizationServers.length > 0;
|
|
267
246
|
const integrations = [...this.#config.integrations ?? []];
|
|
268
247
|
const explicitGithub = integrations.some((integration) => integration.id === "github");
|
|
269
248
|
let installedPlatformGithub = false;
|
|
@@ -366,7 +345,8 @@ var MastraFactory = class {
|
|
|
366
345
|
projects: factoryProjectsStorage,
|
|
367
346
|
auth: routeAuth,
|
|
368
347
|
intake: intakeStorage,
|
|
369
|
-
...integrationSourceControl ? { sourceControl: integrationSourceControl } : {}
|
|
348
|
+
...integrationSourceControl ? { sourceControl: integrationSourceControl } : {},
|
|
349
|
+
channels: () => this.#prepared?.base.controller.getChannels()
|
|
370
350
|
});
|
|
371
351
|
if (integration.versionControl && integrationSourceControl) integration.versionControl.initialize({ storage: integrationSourceControl });
|
|
372
352
|
}
|
|
@@ -393,6 +373,31 @@ var MastraFactory = class {
|
|
|
393
373
|
});
|
|
394
374
|
const intakeReady = integrations.some((integration) => integration.intake !== void 0) && storage.isDomainReady("intake");
|
|
395
375
|
const factoryReady = storage.isDomainReady("projects") && storage.isDomainReady("work-items");
|
|
376
|
+
if (storage.isDomainReady("source-control") && storage.isDomainReady("work-items")) this.#sessionResourceMigration = timedPhase("background.migrate.sessionResources", async () => {
|
|
377
|
+
try {
|
|
378
|
+
const mastraStorage = storage.getMastraStorage();
|
|
379
|
+
const memory = await mastraStorage.getStore("memory");
|
|
380
|
+
if (!memory) return false;
|
|
381
|
+
const sessionMemory = getDynamicMemory(mastraStorage, vector);
|
|
382
|
+
const report = await migrateSessionResources({
|
|
383
|
+
sessions: sourceControlStorage,
|
|
384
|
+
workItems: workItemsStorage,
|
|
385
|
+
...storage.isDomainReady("integrations") ? { integrations: integrationStorage } : {},
|
|
386
|
+
memory,
|
|
387
|
+
threads: sessionMemory({ requestContext: new RequestContext() })
|
|
388
|
+
});
|
|
389
|
+
await sessionMemory.settled();
|
|
390
|
+
await privatizeOwnerResourceSessions({
|
|
391
|
+
sessions: sourceControlStorage,
|
|
392
|
+
workItems: workItemsStorage,
|
|
393
|
+
memory
|
|
394
|
+
});
|
|
395
|
+
return report.runBindings > 0;
|
|
396
|
+
} catch (error) {
|
|
397
|
+
console.warn(`[factory] session resource migration stopped early: ${error instanceof Error ? error.message : error}`);
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
});
|
|
396
401
|
const knowledgeEnabled = this.#config.knowledge !== void 0 || process.env.MASTRACODE_EXPERIMENTAL_SUBCONSCIOUS === "1";
|
|
397
402
|
const githubIntegration = integrations.find((integration) => integration.id === "github");
|
|
398
403
|
const gitlabIntegration = integrations.find((integration) => integration.id === "gitlab" && integration.intake && integration.versionControl);
|
|
@@ -427,7 +432,7 @@ var MastraFactory = class {
|
|
|
427
432
|
abortSession: async (binding) => {
|
|
428
433
|
const controller = this.#prepared?.base.controller;
|
|
429
434
|
if (!controller) return;
|
|
430
|
-
const session = await controller.
|
|
435
|
+
const session = await controller.getSession(binding.sessionId);
|
|
431
436
|
if (session?.stream.isActive()) session.abort();
|
|
432
437
|
},
|
|
433
438
|
...retireTerminalSessions ? { releaseSandboxes: retireTerminalSessions } : {}
|
|
@@ -448,6 +453,7 @@ var MastraFactory = class {
|
|
|
448
453
|
deliver: (target, notification, options) => deliverFactorySessionNotification({
|
|
449
454
|
controller: messaging.controller,
|
|
450
455
|
sessions: sourceControlSessions,
|
|
456
|
+
runs: workItemsStorage,
|
|
451
457
|
target,
|
|
452
458
|
notification,
|
|
453
459
|
...options
|
|
@@ -460,10 +466,29 @@ var MastraFactory = class {
|
|
|
460
466
|
reporting: factoryReporting
|
|
461
467
|
};
|
|
462
468
|
const reportSessionRunEnd = createSessionRunEndReporter(sessionReports);
|
|
463
|
-
const
|
|
464
|
-
const
|
|
469
|
+
const resolveWakeSession = async ({ resourceId, threadId, thread }) => {
|
|
470
|
+
const stamp = (thread === void 0 ? await this.#prepared?.base.controller.queryThreadById({ threadId }) : thread)?.metadata?.factorySessionId;
|
|
471
|
+
const candidates = [.../* @__PURE__ */ new Set([
|
|
472
|
+
typeof stamp === "string" ? stamp : "",
|
|
473
|
+
threadId,
|
|
474
|
+
resourceId
|
|
475
|
+
])].filter(Boolean);
|
|
476
|
+
for (const sessionId of candidates) {
|
|
477
|
+
const row = await sourceControlSessions.getBySessionId(sessionId);
|
|
478
|
+
if (row && (!(sessionId !== threadId && sessionId !== resourceId) || sessionStampCounts(row, resourceId)) && (resourceId === sessionId || resourceId === await sessionMemoryResourceId(this.#prepared?.base.controller, row, workItemsStorage))) return {
|
|
479
|
+
sessionId,
|
|
480
|
+
row
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
return {
|
|
484
|
+
sessionId: threadId,
|
|
485
|
+
row: null
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
const failWake = async ({ sessionId, threadId }, reason) => {
|
|
489
|
+
const message = `Factory session ${sessionId} can't be woken as its owner: ${reason}.`;
|
|
465
490
|
await reportSessionRunEnd({
|
|
466
|
-
sessionId
|
|
491
|
+
sessionId,
|
|
467
492
|
threadId,
|
|
468
493
|
since: /* @__PURE__ */ new Date(),
|
|
469
494
|
outcome: {
|
|
@@ -603,7 +628,7 @@ var MastraFactory = class {
|
|
|
603
628
|
...sessionRetirement ? { sessionRetirement } : {},
|
|
604
629
|
...workItemsReady ? {
|
|
605
630
|
workItems: workItemsStorage,
|
|
606
|
-
controller: {
|
|
631
|
+
controller: { getSession: async (sessionId) => this.#prepared?.base.controller.getSession(sessionId) }
|
|
607
632
|
} : {}
|
|
608
633
|
});
|
|
609
634
|
const loadMemorySettings = async ({ requestContext, binding }) => {
|
|
@@ -635,12 +660,18 @@ var MastraFactory = class {
|
|
|
635
660
|
}
|
|
636
661
|
requestContext.set("mastra__factoryMemorySettings", layerPersonalMemorySettings(record, personal));
|
|
637
662
|
};
|
|
663
|
+
const resolveDefaultThinkingLevel = (requestContext) => resolveFactoryThinkingLevel(requestContext, {
|
|
664
|
+
projects: factoryProjectsStorage,
|
|
665
|
+
sourceControl: sourceControlSessions,
|
|
666
|
+
workItems: workItemsStorage,
|
|
667
|
+
modelDefaults: modelDefaultsStorage
|
|
668
|
+
});
|
|
638
669
|
const factoryProcessor = workItemsReady ? new FactoryPhaseStateProcessor({
|
|
639
670
|
configVersion,
|
|
640
671
|
storage: workItemsStorage,
|
|
641
672
|
boards: this.#boards,
|
|
642
673
|
loadMemorySettings,
|
|
643
|
-
|
|
674
|
+
defaultThinkingLevel: resolveDefaultThinkingLevel,
|
|
644
675
|
...transitionService ? { transitionService } : {},
|
|
645
676
|
...githubIntegration ? { recordPullRequestProvenance: (input) => recordFactoryPullRequestProvenance(githubIntegration, sourceControlStorage.forIntegration("github"), integrationStorage.forIntegration("github"), workItemsStorage, input) } : {},
|
|
646
677
|
messageReader: { listMessages: async (input) => {
|
|
@@ -658,6 +689,7 @@ var MastraFactory = class {
|
|
|
658
689
|
if (proto.constructor?.name === "LibSQLFactoryStorage") return "libsql";
|
|
659
690
|
}
|
|
660
691
|
})();
|
|
692
|
+
const integrationInputProcessors = integrations.flatMap((integration) => integration.processors?.input ?? []);
|
|
661
693
|
const toolIntegrations = integrationRegistrations.filter(({ integration }) => integration.agentTools || integration.sessionTools);
|
|
662
694
|
const sourceControlToolProviders = integrations.flatMap((integration) => integration.versionControl ? [{
|
|
663
695
|
id: integration.id,
|
|
@@ -666,13 +698,12 @@ var MastraFactory = class {
|
|
|
666
698
|
}] : []);
|
|
667
699
|
const prepared = await timedPhase("prepare.controllerMount", () => prepareAgentControllerMount({
|
|
668
700
|
controllerId: CONTROLLER_ID,
|
|
701
|
+
browser: this.#config.browser,
|
|
669
702
|
coAuthor: { name: "mastra-platform[bot]" },
|
|
670
703
|
...this.#config.disableBuiltinTools?.length ? { disableBuiltinTools: this.#config.disableBuiltinTools } : {},
|
|
671
704
|
modes: false,
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
sourceControl: sourceControlSessions
|
|
675
|
-
}),
|
|
705
|
+
subagents: [],
|
|
706
|
+
resolveDefaultThinkingLevel: ({ requestContext }) => resolveDefaultThinkingLevel(requestContext),
|
|
676
707
|
workspace: createWorkspaceFactory({
|
|
677
708
|
...sandboxConfig ? { sandbox: sandboxConfig } : {},
|
|
678
709
|
...this.#config.sandboxStart ? { sandboxStart: this.#config.sandboxStart } : {},
|
|
@@ -690,15 +721,26 @@ var MastraFactory = class {
|
|
|
690
721
|
prepareWakeRequestContext: async ({ requestContext, resourceId, threadId }) => {
|
|
691
722
|
if (!storage.isDomainReady("source-control")) {
|
|
692
723
|
if (auth) await failWake({
|
|
693
|
-
|
|
724
|
+
sessionId: threadId,
|
|
694
725
|
threadId
|
|
695
726
|
}, "session storage is not ready");
|
|
696
727
|
return;
|
|
697
728
|
}
|
|
698
|
-
const
|
|
729
|
+
const { sessionId, row } = await resolveWakeSession({
|
|
730
|
+
resourceId,
|
|
731
|
+
threadId
|
|
732
|
+
});
|
|
733
|
+
if (!row) {
|
|
734
|
+
if (auth) await failWake({
|
|
735
|
+
sessionId,
|
|
736
|
+
threadId
|
|
737
|
+
}, WAKE_OWNER_UNRESOLVED["session-not-found"]);
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
const prepared = await prepareSessionRunContext(requestContext, sessionId, { sessions: sourceControlSessions });
|
|
699
741
|
if (prepared !== "prepared") {
|
|
700
742
|
if (auth) await failWake({
|
|
701
|
-
|
|
743
|
+
sessionId,
|
|
702
744
|
threadId
|
|
703
745
|
}, WAKE_OWNER_UNRESOLVED[prepared]);
|
|
704
746
|
return;
|
|
@@ -708,26 +750,33 @@ var MastraFactory = class {
|
|
|
708
750
|
...auth ? { resumeWakeSession: async ({ resourceId, threadId }) => {
|
|
709
751
|
const controller = this.#prepared?.base.controller;
|
|
710
752
|
if (!controller) return failWake({
|
|
711
|
-
|
|
753
|
+
sessionId: threadId,
|
|
712
754
|
threadId
|
|
713
755
|
}, "the Factory is not started");
|
|
714
756
|
const thread = await controller.queryThreadById({ threadId });
|
|
715
757
|
if (!thread || thread.resourceId !== resourceId) return failWake({
|
|
716
|
-
|
|
758
|
+
sessionId: threadId,
|
|
717
759
|
threadId
|
|
718
760
|
}, `thread ${threadId} is not the session's`);
|
|
719
|
-
const row = storage.isDomainReady("source-control") ? await
|
|
720
|
-
if (!row?.factoryProjectId) return failWake({
|
|
761
|
+
const { sessionId, row } = storage.isDomainReady("source-control") ? await resolveWakeSession({
|
|
721
762
|
resourceId,
|
|
763
|
+
threadId,
|
|
764
|
+
thread
|
|
765
|
+
}) : {
|
|
766
|
+
sessionId: threadId,
|
|
767
|
+
row: null
|
|
768
|
+
};
|
|
769
|
+
if (!row?.factoryProjectId) return failWake({
|
|
770
|
+
sessionId,
|
|
722
771
|
threadId
|
|
723
772
|
}, WAKE_OWNER_UNRESOLVED["session-not-found"]);
|
|
724
773
|
if (!hasResolvedOrg(row.orgId)) return failWake({
|
|
725
|
-
|
|
774
|
+
sessionId,
|
|
726
775
|
threadId
|
|
727
776
|
}, WAKE_OWNER_UNRESOLVED["organization-unresolved"]);
|
|
728
|
-
if (await controller.
|
|
777
|
+
if (await controller.getSession(sessionId)) return;
|
|
729
778
|
await createSessionAsRowOwner(controller, {
|
|
730
|
-
sessionId
|
|
779
|
+
sessionId,
|
|
731
780
|
ownerResourceId: resourceId,
|
|
732
781
|
row,
|
|
733
782
|
tags: {
|
|
@@ -740,7 +789,7 @@ var MastraFactory = class {
|
|
|
740
789
|
disableSettingsOmSeed: true,
|
|
741
790
|
hostInstructions: async ({ requestContext }) => {
|
|
742
791
|
const context = requestContext.get("controller");
|
|
743
|
-
if (context?.threadId && context.
|
|
792
|
+
if (context?.threadId && context.sessionId) {
|
|
744
793
|
const current = context.getState();
|
|
745
794
|
if (!(Boolean(current.factoryProjectId) && Boolean(current.factoryOrgId) && typeof current.untrustedCheckout === "boolean")) {
|
|
746
795
|
const recovered = await resolveFactorySessionAddress({
|
|
@@ -767,7 +816,6 @@ var MastraFactory = class {
|
|
|
767
816
|
...mastraStorageBackend ? { storageBackend: mastraStorageBackend } : {},
|
|
768
817
|
...this.#config.knowledge ? { knowledge: this.#config.knowledge } : {},
|
|
769
818
|
inputProcessors: async ({ requestContext }) => {
|
|
770
|
-
const channelReplyProcessor = new FactoryChannelReplyProcessor();
|
|
771
819
|
const environmentProcessor = new FactoryEnvironmentStateProcessor();
|
|
772
820
|
const sessionsProcessor = workItemsStorage && storage.isDomainReady("source-control") ? [new FactorySessionsStateProcessor({
|
|
773
821
|
authEnabled: routeAuth.enabled(),
|
|
@@ -776,7 +824,7 @@ var MastraFactory = class {
|
|
|
776
824
|
workItems: workItemsStorage,
|
|
777
825
|
boards: this.#boards,
|
|
778
826
|
isRunning: async (sessionId) => {
|
|
779
|
-
return (await this.#prepared?.base.controller.
|
|
827
|
+
return (await this.#prepared?.base.controller.getSession(sessionId))?.stream.isActive() ?? false;
|
|
780
828
|
},
|
|
781
829
|
lastActivity: async (threadId) => {
|
|
782
830
|
const thread = await this.#prepared?.base.controller.queryThreadById({ threadId });
|
|
@@ -787,7 +835,7 @@ var MastraFactory = class {
|
|
|
787
835
|
if (factoryProcessor) {
|
|
788
836
|
await factoryProcessor.prepareMemorySettings(requestContext);
|
|
789
837
|
return [
|
|
790
|
-
|
|
838
|
+
...integrationInputProcessors,
|
|
791
839
|
environmentProcessor,
|
|
792
840
|
...sessionsProcessor,
|
|
793
841
|
factoryProcessor
|
|
@@ -802,14 +850,14 @@ var MastraFactory = class {
|
|
|
802
850
|
reportMemorySettingsUnavailable(requestContext, error instanceof Error ? error.message : String(error));
|
|
803
851
|
}
|
|
804
852
|
return [
|
|
805
|
-
|
|
853
|
+
...integrationInputProcessors,
|
|
806
854
|
environmentProcessor,
|
|
807
855
|
...sessionsProcessor
|
|
808
856
|
];
|
|
809
857
|
},
|
|
810
|
-
outputProcessors: [
|
|
858
|
+
outputProcessors: [...integrations.flatMap((integration) => integration.processors?.output ?? []), new FactoryReplyCredentialProcessor()],
|
|
811
859
|
...vector ? { vector } : {},
|
|
812
|
-
|
|
860
|
+
extraTools: async ({ requestContext }) => {
|
|
813
861
|
const tools = {};
|
|
814
862
|
const toolOwners = /* @__PURE__ */ new Map();
|
|
815
863
|
const mergeTools = (ownerId, contributed) => {
|
|
@@ -896,10 +944,16 @@ var MastraFactory = class {
|
|
|
896
944
|
projects: factoryProjectsStorage,
|
|
897
945
|
workItems: workItemsStorage
|
|
898
946
|
});
|
|
899
|
-
if (scope)
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
947
|
+
if (scope) {
|
|
948
|
+
mergeTools("factory-tools", createFactoryTools({
|
|
949
|
+
scope,
|
|
950
|
+
deps: factoryToolDeps
|
|
951
|
+
}));
|
|
952
|
+
if (sessionRetirement && sandboxConfig && SELF_RECREATE_SANDBOX_PROVIDERS.has(sandboxConfig.provider)) mergeTools("factory-sandbox-tools", createFactorySandboxTools(scope, {
|
|
953
|
+
sessions: sourceControlSessions,
|
|
954
|
+
resetSandbox: (input) => sessionRetirement.resetSessionSandbox(input)
|
|
955
|
+
}));
|
|
956
|
+
}
|
|
903
957
|
}
|
|
904
958
|
}
|
|
905
959
|
for (const { integration, ready, ensureReady } of toolIntegrations) {
|
|
@@ -912,7 +966,7 @@ var MastraFactory = class {
|
|
|
912
966
|
if (integration.sessionTools) mergeTools(integration.id, integration.sessionTools({ requestContext }));
|
|
913
967
|
}
|
|
914
968
|
return tools;
|
|
915
|
-
}
|
|
969
|
+
},
|
|
916
970
|
postToolObserver: async (toolContext) => {
|
|
917
971
|
const requestContext = toolContext.context?.requestContext;
|
|
918
972
|
if (requestContext) await observeAgentGitAction({
|
|
@@ -951,7 +1005,7 @@ var MastraFactory = class {
|
|
|
951
1005
|
} : {},
|
|
952
1006
|
buildApiRoutes: ({ controller, authStorage }) => [
|
|
953
1007
|
...auth ? buildAuthRoutes(auth, { publicUrl: publicOrigin }) : buildAuthDisabledRoutes(),
|
|
954
|
-
...
|
|
1008
|
+
...mcpEnabled ? buildFactoryMcpRoutes({
|
|
955
1009
|
auth: routeAuth,
|
|
956
1010
|
publicOrigin,
|
|
957
1011
|
authorizationServers: mcpAuthorizationServers,
|
|
@@ -978,6 +1032,14 @@ var MastraFactory = class {
|
|
|
978
1032
|
sandbox: sandboxConfig,
|
|
979
1033
|
...environmentBuilds ? { onRepositoryPush: environmentBuilds.onRepositoryPush } : {},
|
|
980
1034
|
sessionRetirement,
|
|
1035
|
+
moveThread: async ({ threadId, resourceId }) => {
|
|
1036
|
+
const sessionMemory = getDynamicMemory(storage.getMastraStorage(), vector);
|
|
1037
|
+
await sessionMemory({ requestContext: new RequestContext() }).updateThreadResourceId({
|
|
1038
|
+
threadId,
|
|
1039
|
+
resourceId
|
|
1040
|
+
});
|
|
1041
|
+
await sessionMemory.settled();
|
|
1042
|
+
},
|
|
981
1043
|
factoryStorage: storage,
|
|
982
1044
|
integrationStorage,
|
|
983
1045
|
sourceControlStorage,
|
|
@@ -987,6 +1049,7 @@ var MastraFactory = class {
|
|
|
987
1049
|
intakeReady,
|
|
988
1050
|
factoryReady,
|
|
989
1051
|
knowledgeEnabled,
|
|
1052
|
+
mcpEnabled,
|
|
990
1053
|
deploymentModelProviders,
|
|
991
1054
|
knowledgeKey: this.#config.knowledge?.key,
|
|
992
1055
|
configVersion,
|
|
@@ -1057,10 +1120,19 @@ var MastraFactory = class {
|
|
|
1057
1120
|
}) : []
|
|
1058
1121
|
],
|
|
1059
1122
|
buildServerConfig: () => {
|
|
1060
|
-
const
|
|
1123
|
+
const mcpCors = {
|
|
1124
|
+
allowHeaders: [
|
|
1125
|
+
"Mcp-Protocol-Version",
|
|
1126
|
+
"Mcp-Method",
|
|
1127
|
+
"Mcp-Name"
|
|
1128
|
+
],
|
|
1129
|
+
exposeHeaders: ["WWW-Authenticate"]
|
|
1130
|
+
};
|
|
1131
|
+
const cors = { cors: allowedOrigins.length ? {
|
|
1061
1132
|
origin: allowedOrigins,
|
|
1062
|
-
credentials: true
|
|
1063
|
-
|
|
1133
|
+
credentials: true,
|
|
1134
|
+
...mcpCors
|
|
1135
|
+
} : mcpCors };
|
|
1064
1136
|
const onError = { onError: handleServerError };
|
|
1065
1137
|
const uiDist = resolveUiDistDir();
|
|
1066
1138
|
const spa = uiDist ? [createSpaStaticMiddleware(uiDist)] : [];
|
|
@@ -1084,6 +1156,16 @@ var MastraFactory = class {
|
|
|
1084
1156
|
middleware: [
|
|
1085
1157
|
...timing,
|
|
1086
1158
|
createFactoryAuthGate(auth),
|
|
1159
|
+
createSessionAccessGuard({
|
|
1160
|
+
auth: routeAuth,
|
|
1161
|
+
sessions: sourceControlSessions,
|
|
1162
|
+
projects: { get: async (args) => {
|
|
1163
|
+
if (!storage.isDomainReady("projects")) return null;
|
|
1164
|
+
await factoryProjectsStorage.ensureReady();
|
|
1165
|
+
return factoryProjectsStorage.get(args);
|
|
1166
|
+
} },
|
|
1167
|
+
controller: () => this.#prepared?.base.controller
|
|
1168
|
+
}),
|
|
1087
1169
|
createTenantCredentialPrimer({
|
|
1088
1170
|
auth: routeAuth,
|
|
1089
1171
|
credentials: modelCredentialsStorage
|
|
@@ -1111,15 +1193,16 @@ var MastraFactory = class {
|
|
|
1111
1193
|
observeSessionThreadTitle(session, { sourceControl: { sessions: sourceControlSessions } });
|
|
1112
1194
|
observeSessionRunEnd(session, { audit: auditDomain });
|
|
1113
1195
|
observeSessionRunReports(session, (outcome, since) => reportSessionRunEnd({
|
|
1114
|
-
sessionId: session.identity.
|
|
1196
|
+
sessionId: session.identity.getId(),
|
|
1115
1197
|
threadId: session.thread.getId(),
|
|
1116
1198
|
outcome,
|
|
1117
1199
|
since
|
|
1118
1200
|
}), { onApprovalRequested: (request) => notifyApprovalRequested({
|
|
1119
|
-
sessionId: session.identity.
|
|
1201
|
+
sessionId: session.identity.getId(),
|
|
1120
1202
|
threadId: session.thread.getId(),
|
|
1121
1203
|
...request
|
|
1122
1204
|
}) });
|
|
1205
|
+
observeSessionThreadStamp(session);
|
|
1123
1206
|
});
|
|
1124
1207
|
prepared.base.controller.onSessionCreated((session) => hydrateSessionMemorySettings(session, { sourceControl: { sessions: sourceControlSessions } }), { blocking: true });
|
|
1125
1208
|
prepared.base.controller.onSessionCreated((session) => hydrateSessionDefaultModel(session, {
|
|
@@ -1208,6 +1291,7 @@ var MastraFactory = class {
|
|
|
1208
1291
|
await timedPhase("finalize.controller", () => this.#prepared.finalize());
|
|
1209
1292
|
await this.#environmentBuilds?.probeSchedules();
|
|
1210
1293
|
await timedPhase("finalize.reconcileBoundThreads", () => this.#factoryProcessor?.reconcileAllBoundThreads() ?? Promise.resolve());
|
|
1294
|
+
this.#sessionResourceMigration?.then((movedRunBindings) => movedRunBindings ? this.#factoryProcessor?.reconcileAllBoundThreads() : void 0).catch((error) => console.warn(`[factory] reconciling bound threads after the session resource migration failed: ${error instanceof Error ? error.message : error}`));
|
|
1211
1295
|
this.#dispatcher?.start();
|
|
1212
1296
|
}
|
|
1213
1297
|
/** Stop Factory-owned background dispatch before the host process shuts down. */
|