@mastra/factory 0.24.0-alpha.1 → 0.24.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/README.md +106 -4
- package/dist/auth.d.ts +14 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +45 -9
- package/dist/auth.js.map +1 -1
- package/dist/boards/review.d.ts.map +1 -1
- package/dist/boards/review.js +21 -1
- package/dist/boards/review.js.map +1 -1
- package/dist/boards/work-transition-policy.d.ts.map +1 -1
- package/dist/boards/work-transition-policy.js +12 -1
- package/dist/boards/work-transition-policy.js.map +1 -1
- package/dist/boards/work.d.ts +14 -0
- package/dist/boards/work.d.ts.map +1 -1
- package/dist/boards/work.js +70 -7
- package/dist/boards/work.js.map +1 -1
- package/dist/capabilities/version-control.d.ts +26 -0
- package/dist/capabilities/version-control.d.ts.map +1 -1
- package/dist/factory.d.ts +8 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +355 -27
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +1 -1
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +1 -16
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +37 -1
- package/dist/integrations/github/integration.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 +19 -11
- 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 +76 -29
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox-release.d.ts +15 -3
- package/dist/integrations/github/sandbox-release.d.ts.map +1 -1
- package/dist/integrations/github/sandbox-release.js +20 -3
- package/dist/integrations/github/sandbox-release.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +2 -3
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +78 -7
- 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/github/webhook.d.ts +4 -2
- package/dist/integrations/github/webhook.d.ts.map +1 -1
- package/dist/integrations/github/webhook.js +59 -36
- package/dist/integrations/github/webhook.js.map +1 -1
- package/dist/integrations/gitlab/api.d.ts +16 -1
- package/dist/integrations/gitlab/api.d.ts.map +1 -1
- package/dist/integrations/gitlab/api.js +9 -0
- package/dist/integrations/gitlab/api.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.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +28 -21
- 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/gitlab/version-control.d.ts.map +1 -1
- package/dist/integrations/gitlab/version-control.js +37 -3
- package/dist/integrations/gitlab/version-control.js.map +1 -1
- package/dist/integrations/incidentio/intake.d.ts +1 -1
- package/dist/integrations/incidentio/intake.d.ts.map +1 -1
- package/dist/integrations/incidentio/intake.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/platform/connect/routes.d.ts +1 -1
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
- package/dist/integrations/platform/connect/routes.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +27 -1
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/incidentio/integration.d.ts +1 -1
- package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -1
- package/dist/integrations/platform/incidentio/integration.js.map +1 -1
- package/dist/integrations/platform/jira/integration.d.ts +1 -1
- package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
- package/dist/integrations/platform/jira/integration.js.map +1 -1
- package/dist/integrations/platform/linear/event-worker.d.ts +1 -1
- package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/linear/event-worker.js.map +1 -1
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +33 -6
- package/dist/integrations/slack/integration.js.map +1 -1
- 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 +137 -64
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/integrations/subscription-session.d.ts +14 -0
- package/dist/integrations/subscription-session.d.ts.map +1 -1
- package/dist/integrations/subscription-session.js +30 -16
- package/dist/integrations/subscription-session.js.map +1 -1
- package/dist/mcp/disconnect.d.ts +10 -0
- package/dist/mcp/disconnect.d.ts.map +1 -0
- package/dist/mcp/disconnect.js +44 -0
- package/dist/mcp/disconnect.js.map +1 -0
- package/dist/mcp/routes.d.ts +46 -0
- package/dist/mcp/routes.d.ts.map +1 -0
- package/dist/mcp/routes.js +243 -0
- package/dist/mcp/routes.js.map +1 -0
- package/dist/provider-display-name.d.ts +2 -0
- package/dist/provider-display-name.d.ts.map +1 -0
- package/dist/provider-display-name.js +16 -0
- package/dist/provider-display-name.js.map +1 -0
- package/dist/review-verdict.d.ts +11 -0
- package/dist/review-verdict.d.ts.map +1 -1
- package/dist/review-verdict.js +16 -1
- package/dist/review-verdict.js.map +1 -1
- package/dist/routes/attention-activity.d.ts.map +1 -1
- package/dist/routes/attention-activity.js +5 -2
- package/dist/routes/attention-activity.js.map +1 -1
- package/dist/routes/attention-providers.d.ts +0 -1
- package/dist/routes/attention-providers.d.ts.map +1 -1
- package/dist/routes/attention-providers.js +5 -6
- package/dist/routes/attention-providers.js.map +1 -1
- package/dist/routes/config.d.ts +44 -5
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +181 -58
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +4 -0
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +3 -1
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/custom-provider-source.d.ts +8 -0
- package/dist/routes/custom-provider-source.d.ts.map +1 -1
- package/dist/routes/custom-provider-source.js +22 -1
- package/dist/routes/custom-provider-source.js.map +1 -1
- package/dist/routes/oauth.js +1 -1
- 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 +1 -1
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/provider-credentials.d.ts +7 -2
- package/dist/routes/provider-credentials.d.ts.map +1 -1
- package/dist/routes/provider-credentials.js +30 -8
- package/dist/routes/provider-credentials.js.map +1 -1
- package/dist/routes/skills.d.ts +2 -4
- package/dist/routes/skills.d.ts.map +1 -1
- package/dist/routes/skills.js +19 -65
- package/dist/routes/skills.js.map +1 -1
- package/dist/routes/source-control-sessions.d.ts +9 -1
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +131 -7
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +3 -2
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +7 -3
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +60 -120
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/binding-context.js +7 -7
- package/dist/rules/binding-context.js.map +1 -1
- package/dist/rules/dispatch-errors.d.ts.map +1 -1
- package/dist/rules/dispatch-errors.js +12 -0
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +8 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +117 -12
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +2 -1
- 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.d.ts.map +1 -1
- package/dist/rules/tools.js +82 -3
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts +17 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +25 -0
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +2 -4
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +1 -4
- package/dist/rules/types.js.map +1 -1
- package/dist/sandbox/local-factory-sandbox.d.ts.map +1 -1
- package/dist/sandbox/local-factory-sandbox.js +1 -0
- package/dist/sandbox/local-factory-sandbox.js.map +1 -1
- package/dist/sandbox/session-retirement.d.ts +27 -3
- package/dist/sandbox/session-retirement.d.ts.map +1 -1
- package/dist/sandbox/session-retirement.js +158 -20
- package/dist/sandbox/session-retirement.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/channel-reply-processor.d.ts +36 -0
- package/dist/session/channel-reply-processor.d.ts.map +1 -0
- package/dist/session/channel-reply-processor.js +46 -0
- package/dist/session/channel-reply-processor.js.map +1 -0
- package/dist/session/channel-session-link-processor.d.ts +39 -0
- package/dist/session/channel-session-link-processor.d.ts.map +1 -0
- package/dist/session/channel-session-link-processor.js +100 -0
- package/dist/session/channel-session-link-processor.js.map +1 -0
- package/dist/session/credential-policy.d.ts +1 -1
- package/dist/session/credential-policy.d.ts.map +1 -1
- package/dist/session/credential-policy.js +7 -6
- 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 +19 -1
- package/dist/session/factory-session.d.ts.map +1 -1
- package/dist/session/factory-session.js +5 -2
- 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 +1 -1
- package/dist/session/memory-settings-hydration.js.map +1 -1
- package/dist/session/reply-credential-processor.d.ts +15 -0
- package/dist/session/reply-credential-processor.d.ts.map +1 -0
- package/dist/session/reply-credential-processor.js +38 -0
- package/dist/session/reply-credential-processor.js.map +1 -0
- package/dist/session/resource-migration.d.ts +87 -0
- package/dist/session/resource-migration.d.ts.map +1 -0
- package/dist/session/resource-migration.js +163 -0
- package/dist/session/resource-migration.js.map +1 -0
- package/dist/session/run-audit.d.ts +24 -0
- package/dist/session/run-audit.d.ts.map +1 -1
- package/dist/session/run-audit.js +93 -7
- package/dist/session/run-audit.js.map +1 -1
- package/dist/session/session-threads.d.ts +49 -0
- package/dist/session/session-threads.d.ts.map +1 -0
- package/dist/session/session-threads.js +70 -0
- package/dist/session/session-threads.js.map +1 -0
- package/dist/session/source-control-tools.d.ts +19 -1
- package/dist/session/source-control-tools.d.ts.map +1 -1
- package/dist/session/source-control-tools.js +78 -11
- package/dist/session/source-control-tools.js.map +1 -1
- package/dist/session/thinking-default.d.ts.map +1 -1
- package/dist/session/thinking-default.js +3 -4
- 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/work-item-repository.d.ts +1 -1
- package/dist/session/work-item-repository.d.ts.map +1 -1
- package/dist/session/work-item-repository.js.map +1 -1
- package/dist/skills/service.d.ts +6 -8
- package/dist/skills/service.d.ts.map +1 -1
- package/dist/skills/service.js +3 -3
- package/dist/skills/service.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/domain.js +1 -1
- package/dist/storage/domains/filesystem/base.d.ts +4 -0
- package/dist/storage/domains/filesystem/base.d.ts.map +1 -1
- package/dist/storage/domains/filesystem/base.js +5 -0
- package/dist/storage/domains/filesystem/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/projects/base.d.ts +6 -0
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +12 -0
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +28 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +48 -0
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +8 -0
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +13 -1
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +79 -7
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +172 -30
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/timing.d.ts +23 -0
- package/dist/timing.d.ts.map +1 -1
- package/dist/timing.js +85 -6
- package/dist/timing.js.map +1 -1
- package/dist/tools/annotations.d.ts +7 -0
- package/dist/tools/annotations.d.ts.map +1 -0
- package/dist/tools/annotations.js +102 -0
- package/dist/tools/annotations.js.map +1 -0
- package/dist/tools/approval-tools.d.ts +15 -0
- package/dist/tools/approval-tools.d.ts.map +1 -0
- package/dist/tools/approval-tools.js +79 -0
- package/dist/tools/approval-tools.js.map +1 -0
- package/dist/tools/deliver.d.ts +71 -0
- package/dist/tools/deliver.d.ts.map +1 -0
- package/dist/tools/deliver.js +129 -0
- package/dist/tools/deliver.js.map +1 -0
- package/dist/tools/index.d.ts +30 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +36 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/messaging-tools.d.ts +28 -0
- package/dist/tools/messaging-tools.d.ts.map +1 -0
- package/dist/tools/messaging-tools.js +396 -0
- package/dist/tools/messaging-tools.js.map +1 -0
- package/dist/tools/permissions.d.ts +31 -0
- package/dist/tools/permissions.d.ts.map +1 -0
- package/dist/tools/permissions.js +48 -0
- package/dist/tools/permissions.js.map +1 -0
- package/dist/tools/read-tools.d.ts +30 -0
- package/dist/tools/read-tools.d.ts.map +1 -0
- package/dist/tools/read-tools.js +293 -0
- package/dist/tools/read-tools.js.map +1 -0
- package/dist/tools/reports.d.ts +174 -0
- package/dist/tools/reports.d.ts.map +1 -0
- package/dist/tools/reports.js +380 -0
- package/dist/tools/reports.js.map +1 -0
- package/dist/tools/run-watch.d.ts +46 -0
- package/dist/tools/run-watch.d.ts.map +1 -0
- package/dist/tools/run-watch.js +102 -0
- package/dist/tools/run-watch.js.map +1 -0
- package/dist/tools/scope.d.ts +54 -0
- package/dist/tools/scope.d.ts.map +1 -0
- package/dist/tools/scope.js +87 -0
- package/dist/tools/scope.js.map +1 -0
- package/dist/tools/session-tools.d.ts +43 -0
- package/dist/tools/session-tools.d.ts.map +1 -0
- package/dist/tools/session-tools.js +410 -0
- package/dist/tools/session-tools.js.map +1 -0
- package/dist/tools/sessions-state-processor.d.ts +41 -0
- package/dist/tools/sessions-state-processor.d.ts.map +1 -0
- package/dist/tools/sessions-state-processor.js +190 -0
- package/dist/tools/sessions-state-processor.js.map +1 -0
- package/dist/tools/side-sessions.d.ts +53 -0
- package/dist/tools/side-sessions.d.ts.map +1 -0
- package/dist/tools/side-sessions.js +83 -0
- package/dist/tools/side-sessions.js.map +1 -0
- package/dist/tools/work-item-tools.d.ts +28 -0
- package/dist/tools/work-item-tools.d.ts.map +1 -0
- package/dist/tools/work-item-tools.js +342 -0
- package/dist/tools/work-item-tools.js.map +1 -0
- package/dist/work-items/create-work-item.d.ts +55 -0
- package/dist/work-items/create-work-item.d.ts.map +1 -0
- package/dist/work-items/create-work-item.js +101 -0
- package/dist/work-items/create-work-item.js.map +1 -0
- package/dist/work-items/decision-actions.d.ts +42 -0
- package/dist/work-items/decision-actions.d.ts.map +1 -0
- package/dist/work-items/decision-actions.js +70 -0
- package/dist/work-items/decision-actions.js.map +1 -0
- package/dist/workspace.d.ts +1 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +15 -7
- package/dist/workspace.js.map +1 -1
- package/factory-skills/factory-gitlab-rereview/SKILL.md +1 -1
- package/factory-skills/factory-gitlab-review/SKILL.md +1 -1
- package/factory-skills/factory-plan/SKILL.md +4 -4
- package/factory-skills/factory-rereview/SKILL.md +3 -1
- package/factory-skills/factory-review/SKILL.md +3 -1
- package/factory-skills/factory-self-review/SKILL.md +46 -0
- package/package.json +14 -14
package/dist/factory.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { timedPhase } from "./timing.js";
|
|
2
|
-
import { buildAuthDisabledRoutes, buildAuthRoutes, createFactoryAuthGate, createFactoryRouteAuth, factoryUserOrgId, getFactoryAuthOrgId, getFactoryAuthUserFromContext, getFactoryAuthUserId } from "./auth.js";
|
|
1
|
+
import { createRequestTimingMiddleware, factoryTimingEnabled, instrumentAsyncMethods, timedPhase } from "./timing.js";
|
|
2
|
+
import { buildAuthDisabledRoutes, buildAuthRoutes, createFactoryAuthGate, createFactoryInteractiveMarker, createFactoryRouteAuth, factoryUserOrgId, getFactoryAuthOrgId, getFactoryAuthUserFromContext, getFactoryAuthUserId } from "./auth.js";
|
|
3
3
|
import { assertFactoryConfigVersion } from "./rules/validation.js";
|
|
4
|
-
import { isTerminalWorkItem } from "./boards/semantics.js";
|
|
4
|
+
import { boardForWorkItem, isTerminalWorkItem } from "./boards/semantics.js";
|
|
5
5
|
import { createBoardRegistry } from "./boards/registry.js";
|
|
6
6
|
import "./boards/index.js";
|
|
7
7
|
import { isValidGitRef } from "./sandbox/git-ref.js";
|
|
@@ -21,32 +21,41 @@ import { PlatformApiClient, platformApiClientConfigFromEnv } from "./integration
|
|
|
21
21
|
import { buildPlatformConnectRoutes } from "./integrations/platform/connect/routes.js";
|
|
22
22
|
import { observeSessionFirstExec } from "./session/first-exec-capture.js";
|
|
23
23
|
import { observeSessionFilesystem } from "./session/filesystem-capture.js";
|
|
24
|
+
import { sessionMemoryResourceId, sessionStampCounts } from "./session/session-threads.js";
|
|
24
25
|
import { createPlaintextFactorySecretEncryption } from "./secret-encryption.js";
|
|
25
26
|
import { ModelCredentialsStorage } from "./storage/domains/credentials/base.js";
|
|
26
27
|
import { createTenantCredentialPrimer, primeTenantCredentials, registerTenantCredentialResolver } from "./routes/tenant-credentials.js";
|
|
27
|
-
import {
|
|
28
|
+
import { hasResolvedOrg } from "./session/org-seed.js";
|
|
29
|
+
import { createSessionAsRowOwner, prepareSessionRunContext } from "./integrations/subscription-session.js";
|
|
28
30
|
import { PlatformGithubIntegration } from "./integrations/platform/github/integration.js";
|
|
29
31
|
import { PlatformGitLabIntegration } from "./integrations/platform/gitlab/integration.js";
|
|
30
32
|
import { PlatformIncidentioIntegration } from "./integrations/platform/incidentio/integration.js";
|
|
31
33
|
import { PlatformJiraIntegration } from "./integrations/platform/jira/integration.js";
|
|
32
34
|
import { PlatformLinearIntegration } from "./integrations/platform/linear/integration.js";
|
|
33
35
|
import { FactoryProjectsStorage } from "./storage/domains/projects/base.js";
|
|
36
|
+
import { SourceControlStorage } from "./storage/domains/source-control/base.js";
|
|
37
|
+
import { createSourceControlSessionLookup } from "./session/factory-session.js";
|
|
38
|
+
import { AuditStorage } from "./storage/domains/audit/base.js";
|
|
39
|
+
import { resolveFactoryToolScope } from "./tools/scope.js";
|
|
40
|
+
import { deliverFactorySessionNotification } from "./tools/deliver.js";
|
|
41
|
+
import { createSessionApprovalNotifier, createSessionRunEndReporter, createStageChangeNotifier, createWorkItemRunEndReporter } from "./tools/reports.js";
|
|
34
42
|
import { resolveFactoryCredentialTenant } from "./session/credential-policy.js";
|
|
35
43
|
import { hydrateSessionMemorySettings, layerPersonalMemorySettings } from "./session/memory-settings-hydration.js";
|
|
36
44
|
import { MemorySettingsStorage, factoryMemorySettingsUserId } from "./storage/domains/memory-settings/base.js";
|
|
37
45
|
import { resolveDeploymentModelProviders } from "./routes/config.js";
|
|
38
|
-
import {
|
|
46
|
+
import { observeSessionRunEnd } from "./session/run-audit.js";
|
|
47
|
+
import { observeSessionRunReports } from "./tools/run-watch.js";
|
|
48
|
+
import { applyFactoryToolPermissions } from "./tools/permissions.js";
|
|
49
|
+
import { createFactoryTools } from "./tools/index.js";
|
|
50
|
+
import { buildFactoryMcpRoutes, resolveMcpAuthorizationServers } from "./mcp/routes.js";
|
|
51
|
+
import { createCustomProvidersPrimer, primeCustomProvidersForRequestContext, registerCustomProvidersSource } from "./routes/custom-provider-source.js";
|
|
39
52
|
import { ProjectRoutes } from "./routes/projects.js";
|
|
40
|
-
import { SourceControlStorage } from "./storage/domains/source-control/base.js";
|
|
41
|
-
import { createSourceControlSessionLookup } from "./session/factory-session.js";
|
|
42
53
|
import { FactoryTransitionService } from "./rules/transition-service.js";
|
|
43
|
-
import { AuditStorage } from "./storage/domains/audit/base.js";
|
|
44
54
|
import { AuditDomain } from "./storage/domains/audit/domain.js";
|
|
45
55
|
import { QueueHealthStorage } from "./storage/domains/queue-health/base.js";
|
|
46
56
|
import { assembleFactoryApiRoutes, buildIntegrationContext } from "./routes/surface.js";
|
|
47
57
|
import { TelemetryRoutes } from "./routes/telemetry.js";
|
|
48
58
|
import { readFactorySessionScope, resolveFactorySessionAddress } from "./rules/binding-context.js";
|
|
49
|
-
import { observeSessionRunEnd } from "./session/run-audit.js";
|
|
50
59
|
import { FactoryFeedReader } from "./storage/domains/comments/feed-context.js";
|
|
51
60
|
import { FactoryDecisionDispatcher } from "./rules/dispatcher.js";
|
|
52
61
|
import { FactoryPhaseStateProcessor, reportMemorySettingsUnavailable } from "./rules/processor.js";
|
|
@@ -56,11 +65,16 @@ import { createFactoryTransitionTools } from "./rules/tools.js";
|
|
|
56
65
|
import { CallbackFactorySandbox } from "./sandbox/callback-factory-sandbox.js";
|
|
57
66
|
import { SessionRetirementCoordinator } from "./sandbox/session-retirement.js";
|
|
58
67
|
import { handleServerError } from "./server-error.js";
|
|
68
|
+
import { FactoryChannelReplyProcessor } from "./session/channel-reply-processor.js";
|
|
69
|
+
import { FactoryChannelSessionLinkProcessor } from "./session/channel-session-link-processor.js";
|
|
59
70
|
import { hydrateSessionDefaultModel } from "./session/default-model-hydration.js";
|
|
60
71
|
import { observeSessionFirstMessage } from "./session/first-message-capture.js";
|
|
61
72
|
import { LiveSessions } from "./session/live-sessions.js";
|
|
73
|
+
import { FactoryReplyCredentialProcessor } from "./session/reply-credential-processor.js";
|
|
74
|
+
import { migrateSessionResources } from "./session/resource-migration.js";
|
|
62
75
|
import { createSourceControlTools } from "./session/source-control-tools.js";
|
|
63
76
|
import { readFactoryThinkingLevel, resolveFactoryThinkingLevel } from "./session/thinking-default.js";
|
|
77
|
+
import { observeSessionThreadStamp } from "./session/thread-session-stamp.js";
|
|
64
78
|
import { observeSessionThreadTitle } from "./session/thread-title-mirror.js";
|
|
65
79
|
import { createSpaStaticMiddleware, resolveUiDistDir } from "./spa-static.js";
|
|
66
80
|
import { createStateSigner } from "./state-signing.js";
|
|
@@ -72,9 +86,12 @@ import { CustomProvidersStorage } from "./storage/domains/custom-providers/base.
|
|
|
72
86
|
import { FilesystemStorage } from "./storage/domains/filesystem/base.js";
|
|
73
87
|
import { IntegrationStorage } from "./storage/domains/integrations/base.js";
|
|
74
88
|
import { ModelDefaultsStorage } from "./storage/domains/model-defaults/base.js";
|
|
89
|
+
import { FactorySessionsStateProcessor } from "./tools/sessions-state-processor.js";
|
|
90
|
+
import { RequestContext } from "@mastra/core/request-context";
|
|
75
91
|
import { hasAuthInit, isUserProvider } from "@mastra/core/server";
|
|
76
92
|
import { MastraAuthStudio } from "@mastra/auth-studio";
|
|
77
93
|
import { prepareAgentControllerMount } from "@mastra/code-sdk";
|
|
94
|
+
import { getDynamicMemory } from "@mastra/code-sdk/agents/memory";
|
|
78
95
|
import { AgentControllerChannels } from "@mastra/core/channels";
|
|
79
96
|
import { EventEmitterPubSub } from "@mastra/core/events";
|
|
80
97
|
import { describeFactorySandbox, isFactorySandbox } from "@mastra/core/workspace";
|
|
@@ -100,6 +117,12 @@ import { describeFactorySandbox, isFactorySandbox } from "@mastra/core/workspace
|
|
|
100
117
|
* and the storage domains those capabilities require.
|
|
101
118
|
*/
|
|
102
119
|
const CONTROLLER_ID = "code";
|
|
120
|
+
/** Why a wake couldn't be run as its Factory session's owner. */
|
|
121
|
+
const WAKE_OWNER_UNRESOLVED = {
|
|
122
|
+
"session-not-found": "no Factory session row names its owner",
|
|
123
|
+
"organization-unresolved": "its owner's organization is unresolved",
|
|
124
|
+
"organization-mismatch": "its owner's organization doesn't match"
|
|
125
|
+
};
|
|
103
126
|
function hasPlatformCredentials() {
|
|
104
127
|
return Boolean(process.env.MASTRA_PLATFORM_ACCESS_TOKEN?.trim() || process.env.MASTRA_PLATFORM_SECRET_KEY?.trim());
|
|
105
128
|
}
|
|
@@ -199,6 +222,7 @@ var MastraFactory = class {
|
|
|
199
222
|
#configVersion;
|
|
200
223
|
#prepared;
|
|
201
224
|
#dispatcher;
|
|
225
|
+
#startCoordinator;
|
|
202
226
|
#factoryProcessor;
|
|
203
227
|
/** Environment builds through the sandbox's `builds`; undefined when the sandbox has none. */
|
|
204
228
|
#environmentBuilds;
|
|
@@ -233,7 +257,7 @@ var MastraFactory = class {
|
|
|
233
257
|
this.#preparing = true;
|
|
234
258
|
const publicOrigin = (this.#config.publicUrl ?? "http://localhost:4111").replace(/\/+$/, "");
|
|
235
259
|
const allowedOrigins = (this.#config.allowedOrigins ?? []).map((o) => o.replace(/\/+$/, "")).filter(Boolean);
|
|
236
|
-
const storage = this.#config.storage;
|
|
260
|
+
const storage = instrumentAsyncMethods(this.#config.storage, "storage");
|
|
237
261
|
const vector = this.#config.vector;
|
|
238
262
|
const pubsub = this.#config.pubsub;
|
|
239
263
|
const eventBus = pubsub ?? new EventEmitterPubSub();
|
|
@@ -243,6 +267,8 @@ var MastraFactory = class {
|
|
|
243
267
|
const secretEncryption = this.#config.secretEncryption ?? createPlaintextFactorySecretEncryption();
|
|
244
268
|
const deploymentModelProviders = resolveDeploymentModelProviders(this.#config.deploymentModelProviders);
|
|
245
269
|
const routeAuth = createFactoryRouteAuth(auth);
|
|
270
|
+
const mcpConfig = this.#config.mcp;
|
|
271
|
+
const mcpAuthorizationServers = mcpConfig === false || mcpConfig?.enabled === false ? [] : resolveMcpAuthorizationServers(auth?.name, mcpConfig);
|
|
246
272
|
const integrations = [...this.#config.integrations ?? []];
|
|
247
273
|
const explicitGithub = integrations.some((integration) => integration.id === "github");
|
|
248
274
|
let installedPlatformGithub = false;
|
|
@@ -349,7 +375,8 @@ var MastraFactory = class {
|
|
|
349
375
|
});
|
|
350
376
|
if (integration.versionControl && integrationSourceControl) integration.versionControl.initialize({ storage: integrationSourceControl });
|
|
351
377
|
}
|
|
352
|
-
const
|
|
378
|
+
const sourceControlHandles = [.../* @__PURE__ */ new Set(["github", ...integrations.filter((integration) => integration.versionControl).map(({ id }) => id)])].map((id) => sourceControlStorage.forIntegration(id));
|
|
379
|
+
const sourceControlSessions = createSourceControlSessionLookup(sourceControlHandles);
|
|
353
380
|
if (auth) registerTenantCredentialResolver(modelCredentialsStorage, deploymentModelProviders, (requestContext) => resolveFactoryCredentialTenant(requestContext, {
|
|
354
381
|
projects: factoryProjectsStorage,
|
|
355
382
|
sourceControl: sourceControlSessions,
|
|
@@ -371,11 +398,32 @@ var MastraFactory = class {
|
|
|
371
398
|
});
|
|
372
399
|
const intakeReady = integrations.some((integration) => integration.intake !== void 0) && storage.isDomainReady("intake");
|
|
373
400
|
const factoryReady = storage.isDomainReady("projects") && storage.isDomainReady("work-items");
|
|
401
|
+
if (storage.isDomainReady("source-control") && storage.isDomainReady("work-items")) await timedPhase("prepare.migrate.sessionResources", async () => {
|
|
402
|
+
try {
|
|
403
|
+
const mastraStorage = storage.getMastraStorage();
|
|
404
|
+
const memory = await mastraStorage.getStore("memory");
|
|
405
|
+
if (!memory) return;
|
|
406
|
+
const sessionMemory = getDynamicMemory(mastraStorage, vector);
|
|
407
|
+
await migrateSessionResources({
|
|
408
|
+
sessions: sourceControlStorage,
|
|
409
|
+
workItems: workItemsStorage,
|
|
410
|
+
...storage.isDomainReady("integrations") ? { integrations: integrationStorage } : {},
|
|
411
|
+
memory,
|
|
412
|
+
threads: sessionMemory({ requestContext: new RequestContext() })
|
|
413
|
+
});
|
|
414
|
+
await sessionMemory.settled();
|
|
415
|
+
} catch (error) {
|
|
416
|
+
console.warn(`[factory] session resource migration stopped early: ${error instanceof Error ? error.message : error}`);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
374
419
|
const knowledgeEnabled = this.#config.knowledge !== void 0 || process.env.MASTRACODE_EXPERIMENTAL_SUBCONSCIOUS === "1";
|
|
375
420
|
const githubIntegration = integrations.find((integration) => integration.id === "github");
|
|
376
421
|
const gitlabIntegration = integrations.find((integration) => integration.id === "gitlab" && integration.intake && integration.versionControl);
|
|
377
422
|
const workItemsReady = storage.isDomainReady("work-items");
|
|
378
|
-
const sessionRetirement = sandboxConfig && storage.isDomainReady("source-control") ? new SessionRetirementCoordinator({
|
|
423
|
+
const sessionRetirement = sandboxConfig && storage.isDomainReady("source-control") ? new SessionRetirementCoordinator({
|
|
424
|
+
invalidateSession: (sessionId) => workspaceRegistry.invalidateSession(sessionId),
|
|
425
|
+
sandbox: sandboxConfig
|
|
426
|
+
}) : void 0;
|
|
379
427
|
const retireTerminalSessions = sessionRetirement && workItemsReady ? async ({ orgId, workItemId }) => {
|
|
380
428
|
const item = await workItemsStorage.get({
|
|
381
429
|
orgId,
|
|
@@ -402,11 +450,73 @@ var MastraFactory = class {
|
|
|
402
450
|
abortSession: async (binding) => {
|
|
403
451
|
const controller = this.#prepared?.base.controller;
|
|
404
452
|
if (!controller) return;
|
|
405
|
-
const session = await controller.
|
|
453
|
+
const session = await controller.getSession(binding.sessionId);
|
|
406
454
|
if (session?.stream.isActive()) session.abort();
|
|
407
455
|
},
|
|
408
456
|
...retireTerminalSessions ? { releaseSandboxes: retireTerminalSessions } : {}
|
|
409
457
|
}) : void 0;
|
|
458
|
+
const factoryMessaging = async () => {
|
|
459
|
+
const controller = this.#prepared?.base.controller;
|
|
460
|
+
const notifications = await controller?.getMastra()?.getStorage()?.getStore("notifications");
|
|
461
|
+
return controller && notifications ? {
|
|
462
|
+
controller,
|
|
463
|
+
notifications
|
|
464
|
+
} : null;
|
|
465
|
+
};
|
|
466
|
+
const factoryReporting = async () => {
|
|
467
|
+
const messaging = await factoryMessaging();
|
|
468
|
+
if (!messaging) return null;
|
|
469
|
+
return {
|
|
470
|
+
notifications: messaging.notifications,
|
|
471
|
+
deliver: (target, notification, options) => deliverFactorySessionNotification({
|
|
472
|
+
controller: messaging.controller,
|
|
473
|
+
sessions: sourceControlSessions,
|
|
474
|
+
runs: workItemsStorage,
|
|
475
|
+
target,
|
|
476
|
+
notification,
|
|
477
|
+
...options
|
|
478
|
+
})
|
|
479
|
+
};
|
|
480
|
+
};
|
|
481
|
+
const sessionReports = {
|
|
482
|
+
sessions: sourceControlSessions,
|
|
483
|
+
workItems: workItemsStorage,
|
|
484
|
+
reporting: factoryReporting
|
|
485
|
+
};
|
|
486
|
+
const reportSessionRunEnd = createSessionRunEndReporter(sessionReports);
|
|
487
|
+
const resolveWakeSession = async ({ resourceId, threadId, thread }) => {
|
|
488
|
+
const stamp = (thread === void 0 ? await this.#prepared?.base.controller.queryThreadById({ threadId }) : thread)?.metadata?.factorySessionId;
|
|
489
|
+
const candidates = [.../* @__PURE__ */ new Set([
|
|
490
|
+
typeof stamp === "string" ? stamp : "",
|
|
491
|
+
threadId,
|
|
492
|
+
resourceId
|
|
493
|
+
])].filter(Boolean);
|
|
494
|
+
for (const sessionId of candidates) {
|
|
495
|
+
const row = await sourceControlSessions.getBySessionId(sessionId);
|
|
496
|
+
if (row && (!(sessionId !== threadId && sessionId !== resourceId) || sessionStampCounts(row, resourceId)) && (resourceId === sessionId || resourceId === await sessionMemoryResourceId(this.#prepared?.base.controller, row, workItemsStorage))) return {
|
|
497
|
+
sessionId,
|
|
498
|
+
row
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
return {
|
|
502
|
+
sessionId: threadId,
|
|
503
|
+
row: null
|
|
504
|
+
};
|
|
505
|
+
};
|
|
506
|
+
const failWake = async ({ sessionId, threadId }, reason) => {
|
|
507
|
+
const message = `Factory session ${sessionId} can't be woken as its owner: ${reason}.`;
|
|
508
|
+
await reportSessionRunEnd({
|
|
509
|
+
sessionId,
|
|
510
|
+
threadId,
|
|
511
|
+
since: /* @__PURE__ */ new Date(),
|
|
512
|
+
outcome: {
|
|
513
|
+
status: "failed",
|
|
514
|
+
reason: message,
|
|
515
|
+
failureCode: "wake-owner-unresolved"
|
|
516
|
+
}
|
|
517
|
+
}).catch((error) => console.warn("[factory] Unable to report a failed wake.", error));
|
|
518
|
+
throw new Error(message);
|
|
519
|
+
};
|
|
410
520
|
const onTerminalStage = terminalCleanup ? (args) => terminalCleanup({
|
|
411
521
|
orgId: args.orgId,
|
|
412
522
|
factoryProjectId: args.factoryProjectId,
|
|
@@ -426,9 +536,42 @@ var MastraFactory = class {
|
|
|
426
536
|
id: factoryProjectId
|
|
427
537
|
}))?.autoApprovePlans ?? false;
|
|
428
538
|
},
|
|
539
|
+
selfReviewEnabled: async ({ orgId, factoryProjectId }) => {
|
|
540
|
+
await factoryProjectsStorage.ensureReady();
|
|
541
|
+
return (await factoryProjectsStorage.get({
|
|
542
|
+
orgId,
|
|
543
|
+
id: factoryProjectId
|
|
544
|
+
}))?.selfReviewEnabled ?? false;
|
|
545
|
+
},
|
|
429
546
|
...onTerminalStage ? { onTerminalStage } : {},
|
|
547
|
+
onTransitionCommitted: createStageChangeNotifier({
|
|
548
|
+
workItems: workItemsStorage,
|
|
549
|
+
reporting: factoryReporting
|
|
550
|
+
}),
|
|
430
551
|
...githubIntegration ? { onAccepted: (args) => reconcileGithubAcceptanceLabels(githubIntegration, sourceControlStorage.forIntegration(githubIntegration.id), args) } : {}
|
|
431
552
|
}) : void 0;
|
|
553
|
+
const factoryToolDeps = {
|
|
554
|
+
workItems: workItemsStorage,
|
|
555
|
+
comments: workItemCommentsStorage,
|
|
556
|
+
feed: commentsDomain,
|
|
557
|
+
audit: auditStorage,
|
|
558
|
+
boards: this.#boards,
|
|
559
|
+
transitionService,
|
|
560
|
+
auditRecorder: auditDomain,
|
|
561
|
+
sessions: sourceControlSessions,
|
|
562
|
+
sessionModel: {
|
|
563
|
+
projects: factoryProjectsStorage,
|
|
564
|
+
modelDefaults: modelDefaultsStorage,
|
|
565
|
+
...auth ? { tenantCatalog: {
|
|
566
|
+
credentials: modelCredentialsStorage,
|
|
567
|
+
customProviders: customProvidersStorage,
|
|
568
|
+
deploymentProviders: deploymentModelProviders
|
|
569
|
+
} } : {}
|
|
570
|
+
},
|
|
571
|
+
intake: intakeStorage,
|
|
572
|
+
startCoordinator: () => this.#startCoordinator,
|
|
573
|
+
messaging: factoryMessaging
|
|
574
|
+
};
|
|
432
575
|
this.#environmentBuilds = this.#sandbox?.builds ? new EnvironmentBuildRunner({
|
|
433
576
|
sandbox: this.#sandbox,
|
|
434
577
|
projects: factoryProjectsStorage,
|
|
@@ -503,7 +646,7 @@ var MastraFactory = class {
|
|
|
503
646
|
...sessionRetirement ? { sessionRetirement } : {},
|
|
504
647
|
...workItemsReady ? {
|
|
505
648
|
workItems: workItemsStorage,
|
|
506
|
-
controller: {
|
|
649
|
+
controller: { getSession: async (sessionId) => this.#prepared?.base.controller.getSession(sessionId) }
|
|
507
650
|
} : {}
|
|
508
651
|
});
|
|
509
652
|
const loadMemorySettings = async ({ requestContext, binding }) => {
|
|
@@ -569,6 +712,7 @@ var MastraFactory = class {
|
|
|
569
712
|
coAuthor: { name: "mastra-platform[bot]" },
|
|
570
713
|
...this.#config.disableBuiltinTools?.length ? { disableBuiltinTools: this.#config.disableBuiltinTools } : {},
|
|
571
714
|
modes: false,
|
|
715
|
+
subagents: [],
|
|
572
716
|
resolveDefaultThinkingLevel: ({ requestContext }) => resolveFactoryThinkingLevel(requestContext, {
|
|
573
717
|
projects: factoryProjectsStorage,
|
|
574
718
|
sourceControl: sourceControlSessions
|
|
@@ -587,14 +731,78 @@ var MastraFactory = class {
|
|
|
587
731
|
workspaceRegistry
|
|
588
732
|
}),
|
|
589
733
|
disableGithubSignals: true,
|
|
590
|
-
prepareWakeRequestContext: async ({ requestContext, resourceId }) => {
|
|
591
|
-
if (!storage.isDomainReady("source-control"))
|
|
592
|
-
|
|
734
|
+
prepareWakeRequestContext: async ({ requestContext, resourceId, threadId }) => {
|
|
735
|
+
if (!storage.isDomainReady("source-control")) {
|
|
736
|
+
if (auth) await failWake({
|
|
737
|
+
sessionId: threadId,
|
|
738
|
+
threadId
|
|
739
|
+
}, "session storage is not ready");
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const { sessionId, row } = await resolveWakeSession({
|
|
743
|
+
resourceId,
|
|
744
|
+
threadId
|
|
745
|
+
});
|
|
746
|
+
if (!row) {
|
|
747
|
+
if (auth) await failWake({
|
|
748
|
+
sessionId,
|
|
749
|
+
threadId
|
|
750
|
+
}, WAKE_OWNER_UNRESOLVED["session-not-found"]);
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
const prepared = await prepareSessionRunContext(requestContext, sessionId, { sessions: sourceControlSessions });
|
|
754
|
+
if (prepared !== "prepared") {
|
|
755
|
+
if (auth) await failWake({
|
|
756
|
+
sessionId,
|
|
757
|
+
threadId
|
|
758
|
+
}, WAKE_OWNER_UNRESOLVED[prepared]);
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
await primeCustomProvidersForRequestContext(requestContext);
|
|
593
762
|
},
|
|
763
|
+
...auth ? { resumeWakeSession: async ({ resourceId, threadId }) => {
|
|
764
|
+
const controller = this.#prepared?.base.controller;
|
|
765
|
+
if (!controller) return failWake({
|
|
766
|
+
sessionId: threadId,
|
|
767
|
+
threadId
|
|
768
|
+
}, "the Factory is not started");
|
|
769
|
+
const thread = await controller.queryThreadById({ threadId });
|
|
770
|
+
if (!thread || thread.resourceId !== resourceId) return failWake({
|
|
771
|
+
sessionId: threadId,
|
|
772
|
+
threadId
|
|
773
|
+
}, `thread ${threadId} is not the session's`);
|
|
774
|
+
const { sessionId, row } = storage.isDomainReady("source-control") ? await resolveWakeSession({
|
|
775
|
+
resourceId,
|
|
776
|
+
threadId,
|
|
777
|
+
thread
|
|
778
|
+
}) : {
|
|
779
|
+
sessionId: threadId,
|
|
780
|
+
row: null
|
|
781
|
+
};
|
|
782
|
+
if (!row?.factoryProjectId) return failWake({
|
|
783
|
+
sessionId,
|
|
784
|
+
threadId
|
|
785
|
+
}, WAKE_OWNER_UNRESOLVED["session-not-found"]);
|
|
786
|
+
if (!hasResolvedOrg(row.orgId)) return failWake({
|
|
787
|
+
sessionId,
|
|
788
|
+
threadId
|
|
789
|
+
}, WAKE_OWNER_UNRESOLVED["organization-unresolved"]);
|
|
790
|
+
if (await controller.getSession(sessionId)) return;
|
|
791
|
+
await createSessionAsRowOwner(controller, {
|
|
792
|
+
sessionId,
|
|
793
|
+
ownerResourceId: resourceId,
|
|
794
|
+
row,
|
|
795
|
+
tags: {
|
|
796
|
+
factoryProjectId: row.factoryProjectId,
|
|
797
|
+
...row.projectRepositoryId ? { projectRepositoryId: row.projectRepositoryId } : {}
|
|
798
|
+
},
|
|
799
|
+
threadId
|
|
800
|
+
});
|
|
801
|
+
} } : {},
|
|
594
802
|
disableSettingsOmSeed: true,
|
|
595
803
|
hostInstructions: async ({ requestContext }) => {
|
|
596
804
|
const context = requestContext.get("controller");
|
|
597
|
-
if (context?.threadId && context.
|
|
805
|
+
if (context?.threadId && context.sessionId) {
|
|
598
806
|
const current = context.getState();
|
|
599
807
|
if (!(Boolean(current.factoryProjectId) && Boolean(current.factoryOrgId) && typeof current.untrustedCheckout === "boolean")) {
|
|
600
808
|
const recovered = await resolveFactorySessionAddress({
|
|
@@ -621,10 +829,31 @@ var MastraFactory = class {
|
|
|
621
829
|
...mastraStorageBackend ? { storageBackend: mastraStorageBackend } : {},
|
|
622
830
|
...this.#config.knowledge ? { knowledge: this.#config.knowledge } : {},
|
|
623
831
|
inputProcessors: async ({ requestContext }) => {
|
|
832
|
+
const channelReplyProcessor = new FactoryChannelReplyProcessor();
|
|
624
833
|
const environmentProcessor = new FactoryEnvironmentStateProcessor();
|
|
834
|
+
const sessionsProcessor = workItemsStorage && storage.isDomainReady("source-control") ? [new FactorySessionsStateProcessor({
|
|
835
|
+
authEnabled: routeAuth.enabled(),
|
|
836
|
+
sessions: sourceControlSessions,
|
|
837
|
+
projects: factoryProjectsStorage,
|
|
838
|
+
workItems: workItemsStorage,
|
|
839
|
+
boards: this.#boards,
|
|
840
|
+
isRunning: async (sessionId) => {
|
|
841
|
+
return (await this.#prepared?.base.controller.getSession(sessionId))?.stream.isActive() ?? false;
|
|
842
|
+
},
|
|
843
|
+
lastActivity: async (threadId) => {
|
|
844
|
+
const thread = await this.#prepared?.base.controller.queryThreadById({ threadId });
|
|
845
|
+
return thread?.updatedAt ? new Date(thread.updatedAt) : null;
|
|
846
|
+
},
|
|
847
|
+
notifications: async () => (await factoryMessaging())?.notifications ?? null
|
|
848
|
+
})] : [];
|
|
625
849
|
if (factoryProcessor) {
|
|
626
850
|
await factoryProcessor.prepareMemorySettings(requestContext);
|
|
627
|
-
return [
|
|
851
|
+
return [
|
|
852
|
+
channelReplyProcessor,
|
|
853
|
+
environmentProcessor,
|
|
854
|
+
...sessionsProcessor,
|
|
855
|
+
factoryProcessor
|
|
856
|
+
];
|
|
628
857
|
}
|
|
629
858
|
try {
|
|
630
859
|
await loadMemorySettings({
|
|
@@ -634,8 +863,13 @@ var MastraFactory = class {
|
|
|
634
863
|
} catch (error) {
|
|
635
864
|
reportMemorySettingsUnavailable(requestContext, error instanceof Error ? error.message : String(error));
|
|
636
865
|
}
|
|
637
|
-
return [
|
|
866
|
+
return [
|
|
867
|
+
channelReplyProcessor,
|
|
868
|
+
environmentProcessor,
|
|
869
|
+
...sessionsProcessor
|
|
870
|
+
];
|
|
638
871
|
},
|
|
872
|
+
outputProcessors: [new FactoryChannelSessionLinkProcessor(), new FactoryReplyCredentialProcessor()],
|
|
639
873
|
...vector ? { vector } : {},
|
|
640
874
|
...toolIntegrations.length > 0 || sourceControlToolProviders.length > 0 || workItemsStorage && transitionService ? { extraTools: async ({ requestContext }) => {
|
|
641
875
|
const tools = {};
|
|
@@ -651,7 +885,55 @@ var MastraFactory = class {
|
|
|
651
885
|
if (storage.isDomainReady("source-control")) mergeTools("source-control", await createSourceControlTools({
|
|
652
886
|
requestContext,
|
|
653
887
|
providers: sourceControlToolProviders,
|
|
654
|
-
audit: auditDomain
|
|
888
|
+
audit: auditDomain,
|
|
889
|
+
testChecksEnabled: async ({ orgId, factoryProjectId }) => {
|
|
890
|
+
await factoryProjectsStorage.ensureReady();
|
|
891
|
+
return (await factoryProjectsStorage.get({
|
|
892
|
+
orgId,
|
|
893
|
+
id: factoryProjectId
|
|
894
|
+
}))?.reviewTestChecksEnabled ?? false;
|
|
895
|
+
},
|
|
896
|
+
...workItemsStorage ? {
|
|
897
|
+
selfReviewApprovedHead: async () => {
|
|
898
|
+
const resolution = await resolveFactorySessionAddress({
|
|
899
|
+
requestContext,
|
|
900
|
+
storage: workItemsStorage
|
|
901
|
+
});
|
|
902
|
+
if (!resolution) return void 0;
|
|
903
|
+
const binding = resolution.binding ?? await workItemsStorage.findActiveRunBinding(resolution.address);
|
|
904
|
+
if (!binding) return void 0;
|
|
905
|
+
const item = await workItemsStorage.get({
|
|
906
|
+
orgId: binding.orgId,
|
|
907
|
+
id: binding.workItemId
|
|
908
|
+
});
|
|
909
|
+
if (!item || boardForWorkItem(item) !== "work") return void 0;
|
|
910
|
+
if (typeof item.metadata?.openPullRequestNumber === "number") return void 0;
|
|
911
|
+
if (item.metadata?.selfReviewVerdict === void 0) {
|
|
912
|
+
await factoryProjectsStorage.ensureReady();
|
|
913
|
+
if (!(await factoryProjectsStorage.get({
|
|
914
|
+
orgId: binding.orgId,
|
|
915
|
+
id: binding.factoryProjectId
|
|
916
|
+
}))?.selfReviewEnabled) return void 0;
|
|
917
|
+
}
|
|
918
|
+
const sha = item.metadata?.selfReviewedHeadSha;
|
|
919
|
+
return item.metadata?.selfReviewVerdict === "approve" && typeof sha === "string" ? sha : null;
|
|
920
|
+
},
|
|
921
|
+
boundChangeRequestId: async () => {
|
|
922
|
+
const resolution = await resolveFactorySessionAddress({
|
|
923
|
+
requestContext,
|
|
924
|
+
storage: workItemsStorage
|
|
925
|
+
});
|
|
926
|
+
if (!resolution) return void 0;
|
|
927
|
+
const binding = resolution.binding ?? await workItemsStorage.findActiveRunBinding(resolution.address);
|
|
928
|
+
if (binding?.role !== "review") return void 0;
|
|
929
|
+
const source = (await workItemsStorage.get({
|
|
930
|
+
orgId: binding.orgId,
|
|
931
|
+
id: binding.workItemId
|
|
932
|
+
}))?.externalSource;
|
|
933
|
+
if (!source || !/pull-request|merge-request/.test(source.type)) return void 0;
|
|
934
|
+
return /(\d+)$/.exec(source.externalId)?.[1];
|
|
935
|
+
}
|
|
936
|
+
} : {}
|
|
655
937
|
}));
|
|
656
938
|
if (workItemsStorage && transitionService) {
|
|
657
939
|
mergeTools("factory", await createFactoryTransitionTools({
|
|
@@ -668,6 +950,19 @@ var MastraFactory = class {
|
|
|
668
950
|
uiOrigin: reviewSourceUiOrigin,
|
|
669
951
|
...storage.isDomainReady("source-control") ? { sessions: sourceControlSessions } : {}
|
|
670
952
|
}));
|
|
953
|
+
if (storage.isDomainReady("source-control")) {
|
|
954
|
+
const scope = await resolveFactoryToolScope({
|
|
955
|
+
requestContext,
|
|
956
|
+
authEnabled: routeAuth.enabled(),
|
|
957
|
+
sessions: sourceControlSessions,
|
|
958
|
+
projects: factoryProjectsStorage,
|
|
959
|
+
workItems: workItemsStorage
|
|
960
|
+
});
|
|
961
|
+
if (scope) mergeTools("factory-tools", createFactoryTools({
|
|
962
|
+
scope,
|
|
963
|
+
deps: factoryToolDeps
|
|
964
|
+
}));
|
|
965
|
+
}
|
|
671
966
|
}
|
|
672
967
|
for (const { integration, ready, ensureReady } of toolIntegrations) {
|
|
673
968
|
if (!ready && ensureReady) try {
|
|
@@ -718,6 +1013,14 @@ var MastraFactory = class {
|
|
|
718
1013
|
} : {},
|
|
719
1014
|
buildApiRoutes: ({ controller, authStorage }) => [
|
|
720
1015
|
...auth ? buildAuthRoutes(auth, { publicUrl: publicOrigin }) : buildAuthDisabledRoutes(),
|
|
1016
|
+
...auth && mcpAuthorizationServers.length > 0 ? buildFactoryMcpRoutes({
|
|
1017
|
+
auth: routeAuth,
|
|
1018
|
+
publicOrigin,
|
|
1019
|
+
authorizationServers: mcpAuthorizationServers,
|
|
1020
|
+
projects: factoryProjectsStorage,
|
|
1021
|
+
sourceControls: sourceControlHandles,
|
|
1022
|
+
tools: factoryToolDeps
|
|
1023
|
+
}) : [],
|
|
721
1024
|
...new TelemetryRoutes({
|
|
722
1025
|
auth: routeAuth,
|
|
723
1026
|
providerName: auth?.name,
|
|
@@ -751,7 +1054,8 @@ var MastraFactory = class {
|
|
|
751
1054
|
configVersion,
|
|
752
1055
|
boardRegistry: this.#boards,
|
|
753
1056
|
factoryTransitionService: transitionService,
|
|
754
|
-
onFactoryRuntime: ({ transitionService: runtimeTransitionService, prepareBinding }) => {
|
|
1057
|
+
onFactoryRuntime: ({ transitionService: runtimeTransitionService, startCoordinator, prepareBinding }) => {
|
|
1058
|
+
this.#startCoordinator = startCoordinator;
|
|
755
1059
|
this.#dispatcher ??= new FactoryDecisionDispatcher({
|
|
756
1060
|
controller,
|
|
757
1061
|
transitionService: runtimeTransitionService,
|
|
@@ -787,6 +1091,10 @@ var MastraFactory = class {
|
|
|
787
1091
|
tenant,
|
|
788
1092
|
credentials: modelCredentialsStorage
|
|
789
1093
|
}),
|
|
1094
|
+
reportRunEnd: createWorkItemRunEndReporter({
|
|
1095
|
+
workItems: storage.getDomain("work-items"),
|
|
1096
|
+
reporting: factoryReporting
|
|
1097
|
+
}),
|
|
790
1098
|
resolveLinkedWorkItemParentId: async ({ orgId, factoryProjectId, decision }) => {
|
|
791
1099
|
if (decision.source !== "github-pr") return null;
|
|
792
1100
|
const repositoryId = decision.metadata?.githubRepositoryId;
|
|
@@ -818,18 +1126,25 @@ var MastraFactory = class {
|
|
|
818
1126
|
const onError = { onError: handleServerError };
|
|
819
1127
|
const uiDist = resolveUiDistDir();
|
|
820
1128
|
const spa = uiDist ? [createSpaStaticMiddleware(uiDist)] : [];
|
|
1129
|
+
const timing = factoryTimingEnabled ? [createRequestTimingMiddleware()] : [];
|
|
821
1130
|
if (!auth) return {
|
|
822
|
-
middleware: [
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
1131
|
+
middleware: [
|
|
1132
|
+
...timing,
|
|
1133
|
+
createFactoryInteractiveMarker(),
|
|
1134
|
+
createCustomProvidersPrimer({
|
|
1135
|
+
auth: routeAuth,
|
|
1136
|
+
storage: customProvidersStorage,
|
|
1137
|
+
authEnabled: false
|
|
1138
|
+
}),
|
|
1139
|
+
...spa
|
|
1140
|
+
],
|
|
827
1141
|
...cors,
|
|
828
1142
|
...onError
|
|
829
1143
|
};
|
|
830
1144
|
return {
|
|
831
1145
|
auth,
|
|
832
1146
|
middleware: [
|
|
1147
|
+
...timing,
|
|
833
1148
|
createFactoryAuthGate(auth),
|
|
834
1149
|
createTenantCredentialPrimer({
|
|
835
1150
|
auth: routeAuth,
|
|
@@ -847,6 +1162,7 @@ var MastraFactory = class {
|
|
|
847
1162
|
};
|
|
848
1163
|
}
|
|
849
1164
|
}));
|
|
1165
|
+
const notifyApprovalRequested = createSessionApprovalNotifier(sessionReports);
|
|
850
1166
|
prepared.base.controller.onSessionCreated((session) => {
|
|
851
1167
|
observeSessionFilesystem(session, {
|
|
852
1168
|
filesystem: filesystemStorage,
|
|
@@ -856,6 +1172,17 @@ var MastraFactory = class {
|
|
|
856
1172
|
observeSessionFirstExec(session, { sourceControl: { sessions: sourceControlSessions } });
|
|
857
1173
|
observeSessionThreadTitle(session, { sourceControl: { sessions: sourceControlSessions } });
|
|
858
1174
|
observeSessionRunEnd(session, { audit: auditDomain });
|
|
1175
|
+
observeSessionRunReports(session, (outcome, since) => reportSessionRunEnd({
|
|
1176
|
+
sessionId: session.identity.getId(),
|
|
1177
|
+
threadId: session.thread.getId(),
|
|
1178
|
+
outcome,
|
|
1179
|
+
since
|
|
1180
|
+
}), { onApprovalRequested: (request) => notifyApprovalRequested({
|
|
1181
|
+
sessionId: session.identity.getId(),
|
|
1182
|
+
threadId: session.thread.getId(),
|
|
1183
|
+
...request
|
|
1184
|
+
}) });
|
|
1185
|
+
observeSessionThreadStamp(session);
|
|
859
1186
|
});
|
|
860
1187
|
prepared.base.controller.onSessionCreated((session) => hydrateSessionMemorySettings(session, { sourceControl: { sessions: sourceControlSessions } }), { blocking: true });
|
|
861
1188
|
prepared.base.controller.onSessionCreated((session) => hydrateSessionDefaultModel(session, {
|
|
@@ -864,6 +1191,7 @@ var MastraFactory = class {
|
|
|
864
1191
|
workItems: workItemsStorage,
|
|
865
1192
|
modelDefaults: modelDefaultsStorage
|
|
866
1193
|
}), { blocking: true });
|
|
1194
|
+
prepared.base.controller.onSessionCreated((session) => applyFactoryToolPermissions(session, { sessions: sourceControlSessions }), { blocking: true });
|
|
867
1195
|
this.#prepared = prepared;
|
|
868
1196
|
this.#factoryProcessor = factoryProcessor;
|
|
869
1197
|
const channelRegistrations = integrationRegistrations.filter(({ integration, ready }) => ready && integration.channels);
|