@mastra/factory 0.28.0-alpha.1 → 0.28.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 +363 -162
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +12 -6
- package/dist/auth.js.map +1 -1
- package/dist/boards/board-events.d.ts +23 -3
- package/dist/boards/board-events.d.ts.map +1 -1
- package/dist/boards/board-events.js +44 -7
- package/dist/boards/board-events.js.map +1 -1
- package/dist/boards/board-writes.d.ts +2 -2
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +23 -9
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/card-facts.d.ts +3 -1
- package/dist/boards/card-facts.d.ts.map +1 -1
- package/dist/boards/card-facts.js +30 -4
- package/dist/boards/card-facts.js.map +1 -1
- package/dist/boards/default-board.d.ts +7 -0
- package/dist/boards/default-board.d.ts.map +1 -0
- package/dist/boards/default-board.js +10 -0
- package/dist/boards/default-board.js.map +1 -0
- package/dist/boards/define-board.d.ts +40 -18
- package/dist/boards/define-board.d.ts.map +1 -1
- package/dist/boards/define-board.js +64 -42
- package/dist/boards/define-board.js.map +1 -1
- package/dist/boards/index.d.ts +6 -9
- package/dist/boards/index.d.ts.map +1 -1
- package/dist/boards/index.js +6 -20
- package/dist/boards/intake-routing.d.ts +29 -9
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js +72 -20
- package/dist/boards/intake-routing.js.map +1 -1
- package/dist/boards/legacy-plan-role.d.ts.map +1 -1
- package/dist/boards/legacy-plan-role.js +7 -2
- package/dist/boards/legacy-plan-role.js.map +1 -1
- package/dist/boards/phase-automation.d.ts +7 -0
- package/dist/boards/phase-automation.d.ts.map +1 -1
- package/dist/boards/phase-automation.js +16 -5
- package/dist/boards/phase-automation.js.map +1 -1
- package/dist/boards/phase-runner.d.ts +18 -10
- package/dist/boards/phase-runner.d.ts.map +1 -1
- package/dist/boards/phase-runner.js +39 -34
- package/dist/boards/phase-runner.js.map +1 -1
- package/dist/boards/project-boards.d.ts +57 -11
- package/dist/boards/project-boards.d.ts.map +1 -1
- package/dist/boards/project-boards.js +161 -34
- package/dist/boards/project-boards.js.map +1 -1
- package/dist/boards/registry.d.ts +7 -1
- package/dist/boards/registry.d.ts.map +1 -1
- package/dist/boards/registry.js +19 -4
- package/dist/boards/registry.js.map +1 -1
- package/dist/boards/relocate.d.ts +1 -1
- package/dist/boards/relocate.d.ts.map +1 -1
- package/dist/boards/relocate.js +3 -2
- package/dist/boards/relocate.js.map +1 -1
- package/dist/boards/review.d.ts +5 -2
- package/dist/boards/review.d.ts.map +1 -1
- package/dist/boards/review.js +12 -11
- package/dist/boards/review.js.map +1 -1
- package/dist/boards/semantics.d.ts +160 -20
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js +255 -23
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/stored-board.d.ts +32 -18
- package/dist/boards/stored-board.d.ts.map +1 -1
- package/dist/boards/stored-board.js +31 -97
- package/dist/boards/stored-board.js.map +1 -1
- package/dist/boards/work-migrations.d.ts +43 -0
- package/dist/boards/work-migrations.d.ts.map +1 -0
- package/dist/boards/work-migrations.js +353 -0
- package/dist/boards/work-migrations.js.map +1 -0
- package/dist/boards/work-routes.d.ts +58 -0
- package/dist/boards/work-routes.d.ts.map +1 -0
- package/dist/boards/work-routes.js +270 -0
- package/dist/boards/work-routes.js.map +1 -0
- package/dist/boards/work-seeds.d.ts +9 -0
- package/dist/boards/work-seeds.d.ts.map +1 -0
- package/dist/boards/work-seeds.js +56 -0
- package/dist/boards/work-seeds.js.map +1 -0
- package/dist/boards/work.d.ts +8 -19
- package/dist/boards/work.d.ts.map +1 -1
- package/dist/boards/work.js +33 -281
- package/dist/boards/work.js.map +1 -1
- package/dist/capabilities/version-control.d.ts +6 -1
- package/dist/capabilities/version-control.d.ts.map +1 -1
- package/dist/environment/build-runner.d.ts.map +1 -1
- package/dist/environment/build-runner.js +2 -2
- package/dist/environment/build-runner.js.map +1 -1
- package/dist/environment/build-schedule.js +1 -1
- package/dist/environment/build-schedule.js.map +1 -1
- package/dist/environment/build-workflow.d.ts.map +1 -1
- package/dist/environment/build-workflow.js +6 -5
- package/dist/environment/build-workflow.js.map +1 -1
- package/dist/environment/build.d.ts +17 -4
- package/dist/environment/build.d.ts.map +1 -1
- package/dist/environment/build.js +35 -10
- package/dist/environment/build.js.map +1 -1
- package/dist/environment/heads.d.ts +1 -1
- package/dist/environment/heads.d.ts.map +1 -1
- package/dist/environment/heads.js +4 -1
- package/dist/environment/heads.js.map +1 -1
- package/dist/environment/repository-access.d.ts +13 -0
- package/dist/environment/repository-access.d.ts.map +1 -0
- package/dist/environment/repository-access.js +55 -0
- package/dist/environment/repository-access.js.map +1 -0
- package/dist/factory.d.ts +34 -7
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +161 -133
- package/dist/factory.js.map +1 -1
- package/dist/feed-events.d.ts +4 -4
- package/dist/feed-events.d.ts.map +1 -1
- package/dist/feed-events.js +6 -6
- package/dist/feed-events.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/integrations/base.d.ts +6 -13
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/closing-references.d.ts +15 -0
- package/dist/integrations/closing-references.d.ts.map +1 -0
- package/dist/integrations/closing-references.js +69 -0
- package/dist/integrations/closing-references.js.map +1 -0
- package/dist/integrations/github/default-rules.d.ts +15 -66
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +129 -73
- 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 +7 -3
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/github/issue-reconciler.js +5 -3
- package/dist/integrations/github/issue-reconciler.js.map +1 -1
- package/dist/integrations/github/provenance.js +1 -1
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/pull-request-source.d.ts +8 -0
- package/dist/integrations/github/pull-request-source.d.ts.map +1 -0
- package/dist/integrations/github/pull-request-source.js +17 -0
- package/dist/integrations/github/pull-request-source.js.map +1 -0
- package/dist/integrations/github/reconcile-worker.d.ts +5 -1
- package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
- package/dist/integrations/github/reconcile-worker.js +39 -6
- package/dist/integrations/github/reconcile-worker.js.map +1 -1
- package/dist/integrations/github/review-status-reporter.d.ts.map +1 -1
- package/dist/integrations/github/review-status-reporter.js +7 -3
- package/dist/integrations/github/review-status-reporter.js.map +1 -1
- package/dist/integrations/github/routes.d.ts +4 -3
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +10 -87
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +79 -7
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +426 -102
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +10 -2
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +20 -4
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/github/session-subscriptions.js +2 -2
- package/dist/integrations/github/session-subscriptions.js.map +1 -1
- package/dist/integrations/github/token-refresh.d.ts +2 -1
- package/dist/integrations/github/token-refresh.d.ts.map +1 -1
- package/dist/integrations/github/token-refresh.js.map +1 -1
- package/dist/integrations/gitlab/agent-tools.js +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts +73 -31
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/default-rules.js +106 -43
- package/dist/integrations/gitlab/default-rules.js.map +1 -1
- package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/gitlab/issue-reconciler.js +2 -1
- package/dist/integrations/gitlab/issue-reconciler.js.map +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.js +12 -5
- package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
- package/dist/integrations/gitlab/routes.d.ts.map +1 -1
- package/dist/integrations/gitlab/routes.js +1 -3
- package/dist/integrations/gitlab/routes.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts +6 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +119 -30
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/gitlab/session-subscriptions.js +1 -1
- package/dist/integrations/incidentio/agent-tools.js +6 -6
- package/dist/integrations/incidentio/agent-tools.js.map +1 -1
- package/dist/integrations/incidentio/default-rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/default-rules.js +3 -3
- package/dist/integrations/incidentio/default-rules.js.map +1 -1
- package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/incidentio/issue-reconciler.js +2 -1
- package/dist/integrations/incidentio/issue-reconciler.js.map +1 -1
- package/dist/integrations/incidentio/routes.d.ts +2 -2
- package/dist/integrations/incidentio/routes.d.ts.map +1 -1
- package/dist/integrations/incidentio/routes.js +10 -13
- package/dist/integrations/incidentio/routes.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts +4 -4
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +18 -14
- package/dist/integrations/incidentio/rules.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/agent-tools.js +1 -1
- package/dist/integrations/jira/binding-scope.d.ts +5 -6
- package/dist/integrations/jira/binding-scope.d.ts.map +1 -1
- package/dist/integrations/jira/binding-scope.js +9 -11
- package/dist/integrations/jira/binding-scope.js.map +1 -1
- package/dist/integrations/jira/default-rules.d.ts.map +1 -1
- package/dist/integrations/jira/default-rules.js +3 -3
- package/dist/integrations/jira/default-rules.js.map +1 -1
- package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/jira/issue-reconciler.js +2 -1
- package/dist/integrations/jira/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/routes.d.ts.map +1 -1
- package/dist/integrations/jira/routes.js +3 -5
- package/dist/integrations/jira/routes.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts +4 -4
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +18 -14
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/agent-tools.d.ts +9 -1
- package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
- package/dist/integrations/linear/agent-tools.js +81 -3
- package/dist/integrations/linear/agent-tools.js.map +1 -1
- package/dist/integrations/linear/default-rules.d.ts.map +1 -1
- package/dist/integrations/linear/default-rules.js +3 -3
- package/dist/integrations/linear/default-rules.js.map +1 -1
- package/dist/integrations/linear/integration.d.ts +4 -1
- package/dist/integrations/linear/integration.d.ts.map +1 -1
- package/dist/integrations/linear/integration.js +21 -1
- package/dist/integrations/linear/integration.js.map +1 -1
- package/dist/integrations/linear/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/linear/issue-reconciler.js +2 -1
- package/dist/integrations/linear/issue-reconciler.js.map +1 -1
- package/dist/integrations/linear/routes.d.ts +2 -1
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +15 -17
- package/dist/integrations/linear/routes.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts +4 -4
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +16 -15
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/connect/session-tools.d.ts +5 -0
- package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -1
- package/dist/integrations/platform/connect/session-tools.js +5 -0
- package/dist/integrations/platform/connect/session-tools.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.d.ts +4 -1
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +39 -3
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +8 -0
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +143 -93
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/jira/agent-tools.js +1 -1
- package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
- package/dist/integrations/platform/jira/routes.js +3 -5
- package/dist/integrations/platform/jira/routes.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 +1 -1
- package/dist/integrations/platform/linear/event-worker.js.map +1 -1
- package/dist/integrations/platform/linear/integration.d.ts +1 -1
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
- package/dist/integrations/platform/linear/integration.js +6 -5
- package/dist/integrations/platform/linear/integration.js.map +1 -1
- package/dist/integrations/slack/chat-tools.js +1 -1
- package/dist/integrations/slack/integration.d.ts +0 -2
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +7 -9
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/slack/reply-tool.js +1 -1
- package/dist/integrations/slack/run-error-card.js +1 -0
- package/dist/integrations/slack/run-error-card.js.map +1 -1
- package/dist/integrations/slack/share-file-tool.js +1 -1
- package/dist/integrations/slack/slack.d.ts +13 -22
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +22 -83
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/links.d.ts +1 -2
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +4 -4
- package/dist/links.js.map +1 -1
- package/dist/mcp/routes.js +3 -3
- package/dist/mcp/routes.js.map +1 -1
- package/dist/provider-display-name.d.ts.map +1 -1
- package/dist/provider-display-name.js +1 -0
- package/dist/provider-display-name.js.map +1 -1
- package/dist/routes/attention-parked.d.ts +1 -0
- package/dist/routes/attention-parked.d.ts.map +1 -1
- package/dist/routes/attention-parked.js +2 -2
- package/dist/routes/attention-parked.js.map +1 -1
- package/dist/routes/attention-providers.d.ts +0 -25
- package/dist/routes/attention-providers.d.ts.map +1 -1
- package/dist/routes/attention-providers.js +2 -150
- package/dist/routes/attention-providers.js.map +1 -1
- package/dist/routes/attention.d.ts +0 -2
- package/dist/routes/attention.d.ts.map +1 -1
- package/dist/routes/attention.js +2 -13
- package/dist/routes/attention.js.map +1 -1
- package/dist/routes/automation-runs.d.ts +5 -1
- package/dist/routes/automation-runs.d.ts.map +1 -1
- package/dist/routes/automation-runs.js +15 -0
- package/dist/routes/automation-runs.js.map +1 -1
- package/dist/routes/board-snapshot.d.ts +21 -0
- package/dist/routes/board-snapshot.d.ts.map +1 -0
- package/dist/routes/board-snapshot.js +58 -0
- package/dist/routes/board-snapshot.js.map +1 -0
- package/dist/routes/boards.d.ts +2 -2
- package/dist/routes/boards.d.ts.map +1 -1
- package/dist/routes/boards.js +1 -17
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/config.d.ts +11 -1
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +120 -22
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +257 -51
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +131 -40
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/feed-events.d.ts +15 -0
- package/dist/routes/feed-events.d.ts.map +1 -0
- package/dist/routes/feed-events.js +68 -0
- package/dist/routes/feed-events.js.map +1 -0
- package/dist/routes/fs.d.ts +4 -0
- package/dist/routes/fs.d.ts.map +1 -1
- package/dist/routes/fs.js +8 -4
- package/dist/routes/fs.js.map +1 -1
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js +6 -1
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/intake.d.ts +0 -23
- package/dist/routes/intake.d.ts.map +1 -1
- package/dist/routes/intake.js +13 -309
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/knowledge.js +1 -1
- package/dist/routes/mastra-gateway.d.ts +19 -0
- package/dist/routes/mastra-gateway.d.ts.map +1 -0
- package/dist/routes/mastra-gateway.js +120 -0
- package/dist/routes/mastra-gateway.js.map +1 -0
- package/dist/routes/projects.d.ts +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +74 -58
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/provider-credentials.d.ts +6 -1
- package/dist/routes/provider-credentials.d.ts.map +1 -1
- package/dist/routes/provider-credentials.js +42 -7
- package/dist/routes/provider-credentials.js.map +1 -1
- package/dist/routes/route.d.ts +6 -0
- package/dist/routes/route.d.ts.map +1 -1
- package/dist/routes/route.js.map +1 -1
- package/dist/routes/running-packages.d.ts +13 -0
- package/dist/routes/running-packages.d.ts.map +1 -0
- package/dist/routes/running-packages.js +45 -0
- package/dist/routes/running-packages.js.map +1 -0
- package/dist/routes/sandbox-envs.d.ts +26 -0
- package/dist/routes/sandbox-envs.d.ts.map +1 -0
- package/dist/routes/sandbox-envs.js +180 -0
- package/dist/routes/sandbox-envs.js.map +1 -0
- package/dist/routes/session-access.d.ts.map +1 -1
- package/dist/routes/session-access.js +12 -3
- package/dist/routes/session-access.js.map +1 -1
- package/dist/routes/surface.d.ts +10 -8
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +105 -42
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/tenant-credentials.d.ts.map +1 -1
- package/dist/routes/tenant-credentials.js +5 -1
- package/dist/routes/tenant-credentials.js.map +1 -1
- package/dist/routes/work-items.d.ts +0 -3
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +94 -12
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/binding-context.d.ts.map +1 -1
- package/dist/rules/binding-context.js +1 -0
- package/dist/rules/binding-context.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +0 -9
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +362 -69
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/event-rules.d.ts +33 -2
- package/dist/rules/event-rules.d.ts.map +1 -1
- package/dist/rules/event-rules.js +46 -11
- package/dist/rules/event-rules.js.map +1 -1
- package/dist/rules/index.d.ts +2 -4
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +2 -3
- package/dist/rules/phase-goal.d.ts +54 -0
- package/dist/rules/phase-goal.d.ts.map +1 -0
- package/dist/rules/phase-goal.js +70 -0
- package/dist/rules/phase-goal.js.map +1 -0
- package/dist/rules/phase-tools.d.ts +11 -0
- package/dist/rules/phase-tools.d.ts.map +1 -0
- package/dist/rules/phase-tools.js +19 -0
- package/dist/rules/phase-tools.js.map +1 -0
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +116 -15
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/review-source-tool.d.ts +4 -1
- package/dist/rules/review-source-tool.d.ts.map +1 -1
- package/dist/rules/review-source-tool.js +24 -4
- package/dist/rules/review-source-tool.js.map +1 -1
- package/dist/rules/rule-group.d.ts +1 -1
- package/dist/rules/rule-group.d.ts.map +1 -1
- package/dist/rules/rule-group.js +15 -6
- package/dist/rules/rule-group.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts +5 -1
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +9 -3
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/tools.d.ts.map +1 -1
- package/dist/rules/tools.js +39 -28
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts +4 -10
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +61 -55
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +86 -36
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +5 -41
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +32 -2
- package/dist/rules/validation.js.map +1 -1
- package/dist/run-error.d.ts +1 -1
- package/dist/run-error.d.ts.map +1 -1
- package/dist/run-error.js +38 -5
- package/dist/run-error.js.map +1 -1
- package/dist/sandbox/sandbox-env-cache.d.ts +33 -0
- package/dist/sandbox/sandbox-env-cache.d.ts.map +1 -0
- package/dist/sandbox/sandbox-env-cache.js +140 -0
- package/dist/sandbox/sandbox-env-cache.js.map +1 -0
- package/dist/sandbox/sandbox-env.d.ts +77 -0
- package/dist/sandbox/sandbox-env.d.ts.map +1 -0
- package/dist/sandbox/sandbox-env.js +130 -0
- package/dist/sandbox/sandbox-env.js.map +1 -0
- package/dist/secret-encryption.d.ts +21 -0
- package/dist/secret-encryption.d.ts.map +1 -1
- package/dist/secret-encryption.js +31 -4
- package/dist/secret-encryption.js.map +1 -1
- package/dist/session/live-sessions.d.ts +11 -4
- package/dist/session/live-sessions.d.ts.map +1 -1
- package/dist/session/live-sessions.js +41 -10
- package/dist/session/live-sessions.js.map +1 -1
- package/dist/session/self-review-gate.d.ts +6 -4
- package/dist/session/self-review-gate.d.ts.map +1 -1
- package/dist/session/self-review-gate.js +9 -12
- package/dist/session/self-review-gate.js.map +1 -1
- package/dist/session/session-threads.d.ts +2 -3
- package/dist/session/session-threads.d.ts.map +1 -1
- package/dist/session/session-threads.js.map +1 -1
- package/dist/session/source-control-tools.d.ts +39 -13
- package/dist/session/source-control-tools.d.ts.map +1 -1
- package/dist/session/source-control-tools.js +55 -61
- package/dist/session/source-control-tools.js.map +1 -1
- package/dist/session/work-item-state-processor.d.ts +24 -0
- package/dist/session/work-item-state-processor.d.ts.map +1 -0
- package/dist/session/work-item-state-processor.js +275 -0
- package/dist/session/work-item-state-processor.js.map +1 -0
- package/dist/storage/domains/audit/actions.d.ts +2 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +5 -4
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +85 -32
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +120 -131
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
- package/dist/storage/domains/boards/schemas.js +12 -0
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/channel-identity/base.d.ts +0 -4
- package/dist/storage/domains/channel-identity/base.d.ts.map +1 -1
- package/dist/storage/domains/channel-identity/base.js +0 -7
- package/dist/storage/domains/channel-identity/base.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +5 -45
- package/dist/storage/domains/intake/base.d.ts.map +1 -1
- package/dist/storage/domains/intake/base.js +11 -89
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts +17 -9
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +15 -7
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/sandbox-envs/base.d.ts +70 -0
- package/dist/storage/domains/sandbox-envs/base.d.ts.map +1 -0
- package/dist/storage/domains/sandbox-envs/base.js +227 -0
- package/dist/storage/domains/sandbox-envs/base.js.map +1 -0
- package/dist/storage/domains/work-items/base.d.ts +62 -22
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +231 -146
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/board-version.d.ts +6 -2
- package/dist/storage/domains/work-items/board-version.d.ts.map +1 -1
- package/dist/storage/domains/work-items/board-version.js +20 -9
- package/dist/storage/domains/work-items/board-version.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +28 -5
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
- package/dist/storage/domains/work-items/cards.js +156 -23
- package/dist/storage/domains/work-items/cards.js.map +1 -1
- package/dist/storage/domains/work-items/legacy-review.d.ts +63 -0
- package/dist/storage/domains/work-items/legacy-review.d.ts.map +1 -0
- package/dist/storage/domains/work-items/legacy-review.js +109 -0
- package/dist/storage/domains/work-items/legacy-review.js.map +1 -0
- package/dist/storage/domains/work-items/metrics.d.ts +12 -4
- package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
- package/dist/storage/domains/work-items/metrics.js +14 -32
- package/dist/storage/domains/work-items/metrics.js.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.d.ts +4 -2
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.js +59 -26
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
- package/dist/tools/approval-tools.d.ts.map +1 -1
- package/dist/tools/approval-tools.js +28 -9
- package/dist/tools/approval-tools.js.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/messaging-tools.d.ts +3 -0
- package/dist/tools/messaging-tools.d.ts.map +1 -1
- package/dist/tools/messaging-tools.js +2 -1
- package/dist/tools/messaging-tools.js.map +1 -1
- package/dist/tools/read-tools.d.ts +8 -4
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +86 -37
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/reports.d.ts +1 -0
- package/dist/tools/reports.d.ts.map +1 -1
- package/dist/tools/reports.js +2 -1
- package/dist/tools/reports.js.map +1 -1
- package/dist/tools/run-watch.d.ts +1 -1
- package/dist/tools/run-watch.d.ts.map +1 -1
- package/dist/tools/run-watch.js +1 -0
- package/dist/tools/run-watch.js.map +1 -1
- package/dist/tools/sandbox-tools.js +1 -1
- package/dist/tools/session-tools.js +1 -1
- package/dist/tools/sessions-state-processor.d.ts +2 -0
- package/dist/tools/sessions-state-processor.d.ts.map +1 -1
- package/dist/tools/sessions-state-processor.js +4 -2
- package/dist/tools/sessions-state-processor.js.map +1 -1
- package/dist/tools/side-sessions.d.ts +2 -0
- package/dist/tools/side-sessions.d.ts.map +1 -1
- package/dist/tools/side-sessions.js +2 -1
- package/dist/tools/side-sessions.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts +0 -3
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +10 -20
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-item-branch.d.ts +13 -0
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +16 -1
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/create-work-item.d.ts +6 -0
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +28 -3
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/description-context.d.ts +5 -0
- package/dist/work-items/description-context.d.ts.map +1 -0
- package/dist/work-items/description-context.js +17 -0
- package/dist/work-items/description-context.js.map +1 -0
- package/dist/work-items/providers/base.d.ts +4 -1
- package/dist/work-items/providers/base.d.ts.map +1 -1
- package/dist/work-items/providers/base.js +6 -1
- package/dist/work-items/providers/base.js.map +1 -1
- package/dist/work-items/providers/github.d.ts.map +1 -1
- package/dist/work-items/providers/github.js +2 -1
- package/dist/work-items/providers/github.js.map +1 -1
- package/dist/work-items/providers/gitlab.d.ts.map +1 -1
- package/dist/work-items/providers/gitlab.js +2 -1
- package/dist/work-items/providers/gitlab.js.map +1 -1
- package/dist/work-items/providers/jira.d.ts.map +1 -1
- package/dist/work-items/providers/jira.js +3 -2
- package/dist/work-items/providers/jira.js.map +1 -1
- package/dist/work-items/providers/linear.d.ts.map +1 -1
- package/dist/work-items/providers/linear.js +3 -2
- package/dist/work-items/providers/linear.js.map +1 -1
- package/dist/work-items/providers/types.d.ts +6 -0
- package/dist/work-items/providers/types.d.ts.map +1 -1
- package/dist/work-items/related-cards.d.ts +21 -0
- package/dist/work-items/related-cards.d.ts.map +1 -0
- package/dist/work-items/related-cards.js +45 -0
- package/dist/work-items/related-cards.js.map +1 -0
- package/dist/work-items/split-migration.d.ts.map +1 -1
- package/dist/work-items/split-migration.js +8 -8
- package/dist/work-items/split-migration.js.map +1 -1
- package/dist/workspace.d.ts +3 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +122 -45
- package/dist/workspace.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +13 -11
- package/factory-skills/factory-build/SKILL.md +64 -0
- package/factory-skills/factory-gitlab-rereview/SKILL.md +4 -4
- package/factory-skills/factory-gitlab-review/SKILL.md +6 -6
- package/factory-skills/factory-plan/SKILL.md +8 -10
- package/factory-skills/factory-rereview/SKILL.md +74 -28
- package/factory-skills/factory-review/SKILL.md +85 -29
- package/factory-skills/factory-self-review/SKILL.md +32 -13
- package/factory-skills/factory-triage/SKILL.md +36 -32
- package/package.json +12 -12
- package/dist/boards/index.js.map +0 -1
- package/dist/boards/pull-request-review.d.ts +0 -14
- package/dist/boards/pull-request-review.d.ts.map +0 -1
- package/dist/boards/pull-request-review.js +0 -81
- package/dist/boards/pull-request-review.js.map +0 -1
- package/dist/boards/work-tool-rules.d.ts +0 -8
- package/dist/boards/work-tool-rules.d.ts.map +0 -1
- package/dist/boards/work-tool-rules.js +0 -19
- package/dist/boards/work-tool-rules.js.map +0 -1
- package/dist/integrations/slack/emoji-shortcodes.generated.d.ts +0 -8
- package/dist/integrations/slack/emoji-shortcodes.generated.d.ts.map +0 -1
- package/dist/integrations/slack/emoji-shortcodes.generated.js +0 -1984
- package/dist/integrations/slack/emoji-shortcodes.generated.js.map +0 -1
- package/dist/integrations/slack/emoji.d.ts +0 -3
- package/dist/integrations/slack/emoji.d.ts.map +0 -1
- package/dist/integrations/slack/emoji.js +0 -11
- package/dist/integrations/slack/emoji.js.map +0 -1
- package/dist/integrations/slack/feed-publisher.d.ts +0 -26
- package/dist/integrations/slack/feed-publisher.d.ts.map +0 -1
- package/dist/integrations/slack/feed-publisher.js +0 -43
- package/dist/integrations/slack/feed-publisher.js.map +0 -1
- package/dist/routes/attention-activity.d.ts +0 -23
- package/dist/routes/attention-activity.d.ts.map +0 -1
- package/dist/routes/attention-activity.js +0 -154
- package/dist/routes/attention-activity.js.map +0 -1
- package/dist/rules/resolve.d.ts +0 -15
- package/dist/rules/resolve.d.ts.map +0 -1
- package/dist/rules/resolve.js +0 -22
- package/dist/rules/resolve.js.map +0 -1
- package/dist/storage/domains/comments/activity.d.ts +0 -40
- package/dist/storage/domains/comments/activity.d.ts.map +0 -1
- package/dist/storage/domains/comments/activity.js +0 -93
- package/dist/storage/domains/comments/activity.js.map +0 -1
- package/dist/storage/domains/comments/actor.d.ts +0 -51
- package/dist/storage/domains/comments/actor.d.ts.map +0 -1
- package/dist/storage/domains/comments/actor.js +0 -37
- package/dist/storage/domains/comments/actor.js.map +0 -1
- package/dist/storage/domains/comments/base.d.ts +0 -245
- package/dist/storage/domains/comments/base.d.ts.map +0 -1
- package/dist/storage/domains/comments/base.js +0 -539
- package/dist/storage/domains/comments/base.js.map +0 -1
- package/dist/storage/domains/comments/domain.d.ts +0 -135
- package/dist/storage/domains/comments/domain.d.ts.map +0 -1
- package/dist/storage/domains/comments/domain.js +0 -284
- package/dist/storage/domains/comments/domain.js.map +0 -1
- package/dist/storage/domains/comments/feed-context.d.ts +0 -22
- package/dist/storage/domains/comments/feed-context.d.ts.map +0 -1
- package/dist/storage/domains/comments/feed-context.js +0 -88
- package/dist/storage/domains/comments/feed-context.js.map +0 -1
- package/dist/storage/domains/comments/feed-sync.d.ts +0 -21
- package/dist/storage/domains/comments/feed-sync.d.ts.map +0 -1
- package/dist/storage/domains/comments/feed-sync.js +0 -1
- package/dist/storage/domains/comments/parse.d.ts +0 -23
- package/dist/storage/domains/comments/parse.d.ts.map +0 -1
- package/dist/storage/domains/comments/parse.js +0 -89
- package/dist/storage/domains/comments/parse.js.map +0 -1
- package/dist/storage/domains/comments/routes.d.ts +0 -24
- package/dist/storage/domains/comments/routes.d.ts.map +0 -1
- package/dist/storage/domains/comments/routes.js +0 -299
- package/dist/storage/domains/comments/routes.js.map +0 -1
- package/dist/storage/domains/comments/schema.d.ts +0 -5
- package/dist/storage/domains/comments/schema.d.ts.map +0 -1
- package/dist/storage/domains/comments/schema.js +0 -178
- package/dist/storage/domains/comments/schema.js.map +0 -1
- package/dist/storage/domains/comments/wire.d.ts +0 -40
- package/dist/storage/domains/comments/wire.d.ts.map +0 -1
- package/dist/storage/domains/comments/wire.js +0 -36
- package/dist/storage/domains/comments/wire.js.map +0 -1
- package/factory-skills/factory-complete-issue/SKILL.md +0 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-schedule.js","names":[],"sources":["../../src/environment/build-schedule.ts"],"sourcesContent":["/**\n * The per-project cron that fires the `factory-environment-build` workflow,\n * kept in core `Schedules` (one row per project) rather than a factory\n * column: the scheduler owns firing, claims and the run trigger log, factory\n * only creates, pauses, resumes and reads the row.\n */\n\nimport type { AnySchedule, Schedules, WorkflowSchedule } from '@mastra/core/schedules';\nimport { validateCron } from '@mastra/core/workflows';\nimport { ENVIRONMENT_BUILD_WORKFLOW_ID } from './build-workflow.js';\n\nexport const SCHEDULES_UNAVAILABLE_ERROR_ID = 'SCHEDULES_NO_SCHEDULES_STORAGE';\n\n/**\n * The project's schedule id in its stored form. Core normalizes a created\n * id to `schedule_<slug>` and resolves a bare id to `agent_<slug>` on reads,\n * so factory always addresses the row by the normalized id (a project id is\n * a lower-case uuid, which slugifies to itself).\n */\nexport function scheduleIdFor(projectId: string): string {\n return `schedule_factory-environment-build-${projectId}`;\n}\n\nexport interface EnvironmentBuildSchedule {\n enabled: boolean;\n cron: string | null;\n timezone: string | null;\n}\n\nexport type ScheduleService = Pick<Schedules, 'create' | 'get' | 'list' | 'update' | 'pause' | 'resume' | 'delete'>;\n\nfunction isSchedulesUnavailable(error: unknown): boolean {\n return (\n typeof error === 'object' && error !== null && (error as { id?: unknown }).id === SCHEDULES_UNAVAILABLE_ERROR_ID\n );\n}\n\n/**\n * Whether the host's storage implements the schedules domain. `mastra.schedules`\n * never throws on access; the missing store surfaces on the first call.\n */\nexport async function probeSchedulesAvailable(schedules: ScheduleService): Promise<boolean> {\n try {\n await schedules.list({ workflowId: ENVIRONMENT_BUILD_WORKFLOW_ID });\n return true;\n } catch (error) {\n if (isSchedulesUnavailable(error)) return false;\n throw error;\n }\n}\n\n/** `undefined` when the cron parses; otherwise the validator's message. */\nexport function invalidCronMessage(cron: string, timezone?: string): string | undefined {\n try {\n validateCron(cron, timezone);\n return undefined;\n } catch (error) {\n return error instanceof Error ? error.message : String(error);\n }\n}\n\nfunction isWorkflowSchedule(schedule: AnySchedule | null): schedule is WorkflowSchedule {\n return schedule !== null && schedule.agentId === undefined;\n}\n\nfunction toView(schedule: WorkflowSchedule | null): EnvironmentBuildSchedule {\n if (!schedule) return { enabled: false, cron: null, timezone: null };\n return { enabled: schedule.status === 'active', cron: schedule.cron, timezone: schedule.timezone ?? null };\n}\n\n/** The project's build schedule as the environment reports it. */\nexport async function readSchedule(schedules: ScheduleService, projectId: string): Promise<EnvironmentBuildSchedule> {\n const schedule = await schedules.get(scheduleIdFor(projectId));\n return toView(isWorkflowSchedule(schedule) ? schedule : null);\n}\n\n/**\n * Create, update, pause or resume the project's schedule so it matches\n * `input`. Disabling a project that never had a schedule creates nothing.\n */\nexport async function ensureSchedule(\n schedules: ScheduleService,\n projectId: string,\n input: { enabled: boolean; cron: string; timezone?: string },\n): Promise<EnvironmentBuildSchedule> {\n const id = scheduleIdFor(projectId);\n const existing = await schedules.get(id);\n const current = isWorkflowSchedule(existing) ? existing : null;\n if (!current) {\n if (!input.enabled) return toView(null);\n const created = await schedules.create({\n id,\n workflowId: ENVIRONMENT_BUILD_WORKFLOW_ID,\n cron: input.cron,\n ...(input.timezone ? { timezone: input.timezone } : {}),\n inputData: { projectId, trigger: 'schedule' },\n resourceId: projectId,\n });\n return toView(created);\n }\n const timingChanged = current.cron !== input.cron || (current.timezone ?? undefined) !== input.timezone;\n let next: AnySchedule = current;\n if (timingChanged) {\n next = await schedules.update(current.id, {\n cron: input.cron,\n ...(input.timezone ? { timezone: input.timezone } : {}),\n });\n }\n if (input.enabled && next.status === 'paused') next = await schedules.resume(current.id);\n if (!input.enabled && next.status === 'active') next = await schedules.pause(current.id);\n return toView(isWorkflowSchedule(next) ? next : null);\n}\n"],"mappings":";;;AAWA,MAAa,iCAAiC;;;;;;;AAQ9C,SAAgB,cAAc,WAA2B;CACvD,OAAO,sCAAsC;AAC/C;AAUA,SAAS,uBAAuB,OAAyB;CACvD,OACE,OAAO,UAAU,YAAY,UAAU,QAAS,MAA2B,OAAA;AAE/E;;;;;AAMA,eAAsB,wBAAwB,WAA8C;CAC1F,IAAI;EACF,MAAM,UAAU,KAAK,EAAE,YAAY,8BAA8B,CAAC;EAClE,OAAO;CACT,SAAS,OAAO;EACd,IAAI,uBAAuB,KAAK,GAAG,OAAO;EAC1C,MAAM;CACR;AACF;;AAGA,SAAgB,mBAAmB,MAAc,UAAuC;CACtF,IAAI;EACF,aAAa,MAAM,QAAQ;EAC3B;CACF,SAAS,OAAO;EACd,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CAC9D;AACF;AAEA,SAAS,mBAAmB,UAA4D;CACtF,OAAO,aAAa,QAAQ,SAAS,YAAY,KAAA;AACnD;AAEA,SAAS,OAAO,UAA6D;CAC3E,IAAI,CAAC,UAAU,OAAO;EAAE,SAAS;EAAO,MAAM;EAAM,UAAU;CAAK;CACnE,OAAO;EAAE,SAAS,SAAS,WAAW;EAAU,MAAM,SAAS;EAAM,UAAU,SAAS,YAAY;CAAK;
|
|
1
|
+
{"version":3,"file":"build-schedule.js","names":[],"sources":["../../src/environment/build-schedule.ts"],"sourcesContent":["/**\n * The per-project cron that fires the `factory-environment-build` workflow,\n * kept in core `Schedules` (one row per project) rather than a factory\n * column: the scheduler owns firing, claims and the run trigger log, factory\n * only creates, pauses, resumes and reads the row.\n */\n\nimport type { AnySchedule, Schedules, WorkflowSchedule } from '@mastra/core/schedules';\nimport { validateCron } from '@mastra/core/workflows';\nimport { ENVIRONMENT_BUILD_WORKFLOW_ID } from './build-workflow.js';\n\nexport const SCHEDULES_UNAVAILABLE_ERROR_ID = 'SCHEDULES_NO_SCHEDULES_STORAGE';\n\n/**\n * The project's schedule id in its stored form. Core normalizes a created\n * id to `schedule_<slug>` and resolves a bare id to `agent_<slug>` on reads,\n * so factory always addresses the row by the normalized id (a project id is\n * a lower-case uuid, which slugifies to itself).\n */\nexport function scheduleIdFor(projectId: string): string {\n return `schedule_factory-environment-build-${projectId}`;\n}\n\nexport interface EnvironmentBuildSchedule {\n enabled: boolean;\n cron: string | null;\n timezone: string | null;\n}\n\nexport type ScheduleService = Pick<Schedules, 'create' | 'get' | 'list' | 'update' | 'pause' | 'resume' | 'delete'>;\n\nfunction isSchedulesUnavailable(error: unknown): boolean {\n return (\n typeof error === 'object' && error !== null && (error as { id?: unknown }).id === SCHEDULES_UNAVAILABLE_ERROR_ID\n );\n}\n\n/**\n * Whether the host's storage implements the schedules domain. `mastra.schedules`\n * never throws on access; the missing store surfaces on the first call.\n */\nexport async function probeSchedulesAvailable(schedules: ScheduleService): Promise<boolean> {\n try {\n await schedules.list({ workflowId: ENVIRONMENT_BUILD_WORKFLOW_ID });\n return true;\n } catch (error) {\n if (isSchedulesUnavailable(error)) return false;\n throw error;\n }\n}\n\n/** `undefined` when the cron parses; otherwise the validator's message. */\nexport function invalidCronMessage(cron: string, timezone?: string): string | undefined {\n try {\n validateCron(cron, timezone);\n return undefined;\n } catch (error) {\n return error instanceof Error ? error.message : String(error);\n }\n}\n\nfunction isWorkflowSchedule(schedule: AnySchedule | null): schedule is WorkflowSchedule {\n return schedule !== null && schedule.agentId === undefined;\n}\n\nfunction toView(schedule: WorkflowSchedule | null): EnvironmentBuildSchedule {\n if (!schedule) return { enabled: false, cron: null, timezone: null };\n return { enabled: schedule.status === 'active', cron: schedule.cron ?? null, timezone: schedule.timezone ?? null };\n}\n\n/** The project's build schedule as the environment reports it. */\nexport async function readSchedule(schedules: ScheduleService, projectId: string): Promise<EnvironmentBuildSchedule> {\n const schedule = await schedules.get(scheduleIdFor(projectId));\n return toView(isWorkflowSchedule(schedule) ? schedule : null);\n}\n\n/**\n * Create, update, pause or resume the project's schedule so it matches\n * `input`. Disabling a project that never had a schedule creates nothing.\n */\nexport async function ensureSchedule(\n schedules: ScheduleService,\n projectId: string,\n input: { enabled: boolean; cron: string; timezone?: string },\n): Promise<EnvironmentBuildSchedule> {\n const id = scheduleIdFor(projectId);\n const existing = await schedules.get(id);\n const current = isWorkflowSchedule(existing) ? existing : null;\n if (!current) {\n if (!input.enabled) return toView(null);\n const created = await schedules.create({\n id,\n workflowId: ENVIRONMENT_BUILD_WORKFLOW_ID,\n cron: input.cron,\n ...(input.timezone ? { timezone: input.timezone } : {}),\n inputData: { projectId, trigger: 'schedule' },\n resourceId: projectId,\n });\n return toView(created);\n }\n const timingChanged = current.cron !== input.cron || (current.timezone ?? undefined) !== input.timezone;\n let next: AnySchedule = current;\n if (timingChanged) {\n next = await schedules.update(current.id, {\n cron: input.cron,\n ...(input.timezone ? { timezone: input.timezone } : {}),\n });\n }\n if (input.enabled && next.status === 'paused') next = await schedules.resume(current.id);\n if (!input.enabled && next.status === 'active') next = await schedules.pause(current.id);\n return toView(isWorkflowSchedule(next) ? next : null);\n}\n"],"mappings":";;;AAWA,MAAa,iCAAiC;;;;;;;AAQ9C,SAAgB,cAAc,WAA2B;CACvD,OAAO,sCAAsC;AAC/C;AAUA,SAAS,uBAAuB,OAAyB;CACvD,OACE,OAAO,UAAU,YAAY,UAAU,QAAS,MAA2B,OAAA;AAE/E;;;;;AAMA,eAAsB,wBAAwB,WAA8C;CAC1F,I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M;CAC/F,IAAI,OAAoB;CACxB,IAAI,eACF,OAAO,MAAM,UAAU,OAAO,QAAQ,IAAI;EACxC,MAAM,MAAM;EACZ,GAAI,MAAM,WAAW,EAAE,UAAU,MAAM,SAAS,IAAI,CAAC;CACvD,CAAC;CAEH,IAAI,MAAM,WAAW,KAAK,WAAW,UAAU,OAAO,MAAM,UAAU,OAAO,QAAQ,EAAE;CACvF,IAAI,CAAC,MAAM,WAAW,KAAK,WAAW,UAAU,OAAO,MAAM,UAAU,MAAM,QAAQ,EAAE;CACvF,OAAO,OAAO,mBAAmB,IAAI,IAAI,OAAO,IAAI;AACtD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-workflow.d.ts","sourceRoot":"","sources":["../../src/environment/build-workflow.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"build-workflow.d.ts","sourceRoot":"","sources":["../../src/environment/build-workflow.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,OAAO,KAAK,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAEhF,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AACzE,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAC5C,eAAO,MAAM,iBAAiB,QAAc,CAAC;AAE7C,eAAO,MAAM,2BAA2B;;;;;;;iBAGtC,CAAC;AAWH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;iBAOvC,CAAC;AAEH,MAAM,MAAM,8BAA8B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAE1F,MAAM,WAAW,+BAA+B;IAC9C,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kGAAkG;IAClG,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,KAAK,IAAI,CAAC;CACrE;AAED,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,oBAAoB,EAC1B,OAAO,GAAE,+BAAoC;;;;;;;;;;;;;;;eA0F9C"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { maskSandboxEnvValues } from "../sandbox/sandbox-env.js";
|
|
1
2
|
import { resolveProjectEnvironment } from "../workspace.js";
|
|
2
|
-
import { ENVIRONMENT_BUILD_TRIGGERS,
|
|
3
|
+
import { ENVIRONMENT_BUILD_TRIGGERS, environmentBuildContextWithEnv, errorReason, redactCredentials, runEnvironmentBuild } from "./build.js";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import { createStep, createWorkflow } from "@mastra/core/workflows";
|
|
5
6
|
// src/environment/build-workflow.ts
|
|
@@ -80,7 +81,7 @@ function createEnvironmentBuildWorkflow(deps, options = {}) {
|
|
|
80
81
|
status: "unknown"
|
|
81
82
|
};
|
|
82
83
|
const environment = await resolveProjectEnvironment(deps.sourceControl.storage, project);
|
|
83
|
-
const ctx =
|
|
84
|
+
const { ctx } = await environmentBuildContextWithEnv(project, environment, heads, deps.sourceControl.versionControl, deps.sandboxEnvs);
|
|
84
85
|
const startedAt = now().getTime();
|
|
85
86
|
try {
|
|
86
87
|
for (;;) {
|
|
@@ -108,12 +109,12 @@ function createEnvironmentBuildWorkflow(deps, options = {}) {
|
|
|
108
109
|
factoryProjectId: project.id,
|
|
109
110
|
buildId: result.buildId,
|
|
110
111
|
status: build.status,
|
|
111
|
-
...build.error ? { reason: redactCredentials(build.error) } : {}
|
|
112
|
+
...build.error ? { reason: maskSandboxEnvValues(redactCredentials(build.error), ctx.buildEnv) } : {}
|
|
112
113
|
});
|
|
113
114
|
return {
|
|
114
115
|
...result,
|
|
115
116
|
status: build.status,
|
|
116
|
-
...build.error ? { reason: redactCredentials(build.error) } : {}
|
|
117
|
+
...build.error ? { reason: maskSandboxEnvValues(redactCredentials(build.error), ctx.buildEnv) } : {}
|
|
117
118
|
};
|
|
118
119
|
}
|
|
119
120
|
if (now().getTime() - startedAt >= maxWaitMs) return {
|
|
@@ -124,7 +125,7 @@ function createEnvironmentBuildWorkflow(deps, options = {}) {
|
|
|
124
125
|
await sleep(pollMs);
|
|
125
126
|
}
|
|
126
127
|
} catch (error) {
|
|
127
|
-
const reason = errorReason(error);
|
|
128
|
+
const reason = maskSandboxEnvValues(errorReason(error), ctx.buildEnv);
|
|
128
129
|
deps.logger?.info("environment build status read failed", {
|
|
129
130
|
factoryProjectId: project.id,
|
|
130
131
|
reason
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-workflow.js","names":[],"sources":["../../src/environment/build-workflow.ts"],"sourcesContent":["/**\n * The `factory-environment-build` workflow: step one decides and starts a\n * build (`runEnvironmentBuild`), step two polls the provider until the build\n * settles and pins the active template on the project row. Registered by\n * `MastraFactory.prepare()` only when the sandbox has `builds`, and driven by\n * the Build now route, the per-project cron schedule and the GitHub push\n * hand-off. Saving settings never starts it.\n */\n\nimport { createStep, createWorkflow } from '@mastra/core/workflows';\nimport { z } from 'zod';\nimport { resolveProjectEnvironment } from '../workspace.js';\nimport {\n ENVIRONMENT_BUILD_TRIGGERS,\n
|
|
1
|
+
{"version":3,"file":"build-workflow.js","names":[],"sources":["../../src/environment/build-workflow.ts"],"sourcesContent":["/**\n * The `factory-environment-build` workflow: step one decides and starts a\n * build (`runEnvironmentBuild`), step two polls the provider until the build\n * settles and pins the active template on the project row. Registered by\n * `MastraFactory.prepare()` only when the sandbox has `builds`, and driven by\n * the Build now route, the per-project cron schedule and the GitHub push\n * hand-off. Saving settings never starts it.\n */\n\nimport { createStep, createWorkflow } from '@mastra/core/workflows';\nimport { z } from 'zod';\nimport { maskSandboxEnvValues } from '../sandbox/sandbox-env.js';\nimport { resolveProjectEnvironment } from '../workspace.js';\nimport {\n ENVIRONMENT_BUILD_TRIGGERS,\n environmentBuildContextWithEnv,\n errorReason,\n redactCredentials,\n runEnvironmentBuild,\n} from './build.js';\nimport type { EnvironmentBuildDeps, EnvironmentBuildOutcome } from './build.js';\n\nexport const ENVIRONMENT_BUILD_WORKFLOW_ID = 'factory-environment-build';\nexport const DEFAULT_BUILD_POLL_MS = 15_000;\nexport const MAX_BUILD_WAIT_MS = 30 * 60_000;\n\nexport const environmentBuildInputSchema = z.object({\n projectId: z.string().min(1),\n trigger: z.enum(ENVIRONMENT_BUILD_TRIGGERS),\n});\n\nconst startOutputSchema = z.object({\n projectId: z.string(),\n outcome: z.enum(['started', 'skipped', 'unavailable', 'failed']),\n buildId: z.string().optional(),\n templateId: z.string().optional(),\n reason: z.string().optional(),\n heads: z.record(z.string(), z.string()).optional(),\n});\n\nexport const environmentBuildOutputSchema = z.object({\n outcome: z.enum(['started', 'skipped', 'unavailable', 'failed']),\n buildId: z.string().optional(),\n templateId: z.string().optional(),\n reason: z.string().optional(),\n /** Where the started build ended: `ready`, `failed`, or `unknown` when the provider lost it or the wait ran out. */\n status: z.enum(['ready', 'failed', 'unknown']).optional(),\n});\n\nexport type EnvironmentBuildWorkflowResult = z.infer<typeof environmentBuildOutputSchema>;\n\nexport interface EnvironmentBuildWorkflowOptions {\n sleep?: (ms: number) => Promise<void>;\n pollMs?: number;\n maxWaitMs?: number;\n /** Called with the first step's answer so a caller can return it without waiting for the poll. */\n onStart?: (runId: string, outcome: EnvironmentBuildOutcome) => void;\n}\n\nexport function createEnvironmentBuildWorkflow(\n deps: EnvironmentBuildDeps,\n options: EnvironmentBuildWorkflowOptions = {},\n) {\n const sleep = options.sleep ?? (ms => new Promise<void>(resolve => setTimeout(resolve, ms)));\n const pollMs = options.pollMs ?? DEFAULT_BUILD_POLL_MS;\n const maxWaitMs = options.maxWaitMs ?? MAX_BUILD_WAIT_MS;\n const now = deps.now ?? (() => new Date());\n\n const start = createStep({\n id: 'start',\n inputSchema: environmentBuildInputSchema,\n outputSchema: startOutputSchema,\n execute: async ({ inputData, runId }) => {\n const outcome = await runEnvironmentBuild(deps, inputData);\n options.onStart?.(runId, outcome);\n return { projectId: inputData.projectId, ...outcome };\n },\n });\n\n const awaitBuild = createStep({\n id: 'await-build',\n inputSchema: startOutputSchema,\n outputSchema: environmentBuildOutputSchema,\n execute: async ({ inputData }): Promise<EnvironmentBuildWorkflowResult> => {\n const { projectId, heads, ...result } = inputData;\n if (result.outcome !== 'started' || !result.buildId || !heads) return result;\n const builds = deps.sandbox?.builds;\n const project = await deps.projects.getById({ id: projectId });\n if (!builds || !deps.sourceControl || !project) return { ...result, status: 'unknown' };\n const environment = await resolveProjectEnvironment(deps.sourceControl.storage, project);\n const { ctx } = await environmentBuildContextWithEnv(\n project,\n environment,\n heads,\n deps.sourceControl.versionControl,\n deps.sandboxEnvs,\n );\n const startedAt = now().getTime();\n try {\n for (;;) {\n const build = await builds.get(ctx, environment.settings, result.buildId);\n if (build.status === 'ready') {\n const templateId = build.templateId ?? result.templateId ?? result.buildId;\n // A newer run may have replaced `last_build_id` while this one\n // polled; the pin is skipped then so the stale image never wins.\n const pinned = await deps.projects.pinActiveTemplate({\n id: project.id,\n buildId: result.buildId,\n templateId,\n heads,\n });\n deps.logger?.info(pinned ? 'environment build ready' : 'environment build ready but superseded', {\n factoryProjectId: project.id,\n templateId,\n });\n return { ...result, templateId, status: 'ready' };\n }\n if (build.status === 'failed' || build.status === 'unknown') {\n deps.logger?.info('environment build did not complete', {\n factoryProjectId: project.id,\n buildId: result.buildId,\n status: build.status,\n ...(build.error ? { reason: maskSandboxEnvValues(redactCredentials(build.error), ctx.buildEnv) } : {}),\n });\n return {\n ...result,\n status: build.status,\n ...(build.error ? { reason: maskSandboxEnvValues(redactCredentials(build.error), ctx.buildEnv) } : {}),\n };\n }\n if (now().getTime() - startedAt >= maxWaitMs) {\n return { ...result, status: 'unknown', reason: 'Build wait timed out.' };\n }\n await sleep(pollMs);\n }\n } catch (error) {\n const reason = maskSandboxEnvValues(errorReason(error), ctx.buildEnv);\n deps.logger?.info('environment build status read failed', { factoryProjectId: project.id, reason });\n return { ...result, status: 'unknown', reason };\n }\n },\n });\n\n return createWorkflow({\n id: ENVIRONMENT_BUILD_WORKFLOW_ID,\n inputSchema: environmentBuildInputSchema,\n outputSchema: environmentBuildOutputSchema,\n })\n .then(start)\n .then(awaitBuild)\n .commit();\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAa,gCAAgC;AAC7C,MAAa,wBAAwB;AACrC,MAAa,oBAAoB;AAEjC,MAAa,8BAA8B,EAAE,OAAO;CAClD,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAC3B,SAAS,EAAE,KAAK,0BAA0B;AAC5C,CAAC;AAED,MAAM,oBAAoB,EAAE,OAAO;CACjC,WAAW,EAAE,OAAO;CACpB,SAAS,EAAE,KAAK;EAAC;EAAW;EAAW;EAAe;CAAQ,CAAC;CAC/D,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS;CAChC,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;CAC5B,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS;AACnD,CAAC;AAED,MAAa,+BAA+B,EAAE,OAAO;CACnD,SAAS,EAAE,KAAK;EAAC;EAAW;EAAW;EAAe;CAAQ,CAAC;CAC/D,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS;CAChC,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS;;CAE5B,QAAQ,EAAE,KAAK;EAAC;EAAS;EAAU;CAAS,CAAC,CAAC,CAAC,SAAS;AAC1D,CAAC;AAYD,SAAgB,+BACd,MACA,UAA2C,CAAC,GAC5C;CACA,MAAM,QAAQ,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;OAChB;OACA;MACF,CAAC;MACD,KAAK,QAAQ,KAAK,SAAS,4BAA4B,0CAA0C;OAC/F,kBAAkB,QAAQ;OAC1B;MACF,CAAC;MACD,OAAO;OAAE,GAAG;OAAQ;OAAY,QAAQ;MAAQ;KAClD;KACA,IAAI,MAAM,WAAW,YAAY,MAAM,WAAW,WAAW;MAC3D,KAAK,QAAQ,KAAK,sCAAsC;OACtD,kBAAkB,QAAQ;OAC1B,SAAS,OAAO;OAChB,QAAQ,MAAM;OACd,GAAI,MAAM,QAAQ,EAAE,QAAQ,qBAAqB,kBAAkB,MAAM,KAAK,GAAG,IAAI,QAAQ,EAAE,IAAI,CAAC;MACtG,CAAC;MACD,OAAO;OACL,GAAG;OACH,QAAQ,MAAM;OACd,GAAI,MAAM,QAAQ,EAAE,QAAQ,qBAAqB,kBAAkB,MAAM,KAAK,GAAG,IAAI,QAAQ,EAAE,IAAI,CAAC;MACtG;KACF;KACA,IAAI,IAAI,CAAC,CAAC,QAAQ,IAAI,aAAa,WACjC,OAAO;MAAE,GAAG;MAAQ,QAAQ;MAAW,QAAQ;KAAwB;KAEzE,MAAM,MAAM,MAAM;IACpB;GACF,SAAS,OAAO;IACd,MAAM,SAAS,qBAAqB,YAAY,KAAK,GAAG,IAAI,QAAQ;IACpE,KAAK,QAAQ,KAAK,wCAAwC;KAAE,kBAAkB,QAAQ;KAAI;IAAO,CAAC;IAClG,OAAO;KAAE,GAAG;KAAQ,QAAQ;KAAW;IAAO;GAChD;EACF;CACF,CAAC;CAED,OAAO,eAAe;EACpB,IAAI;EACJ,aAAa;EACb,cAAc;CAChB,CAAC,CAAC,CACC,KAAK,KAAK,CAAC,CACX,KAAK,UAAU,CAAC,CAChB,OAAO;AACZ"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type { FactorySandbox, FactorySandboxContext } from '@mastra/core/workspace';
|
|
10
10
|
import type { VersionControl } from '../capabilities/version-control.js';
|
|
11
11
|
import type { FactoryProject, FactoryProjectsStorage } from '../storage/domains/projects/base.js';
|
|
12
|
+
import type { SandboxEnvStore } from '../storage/domains/sandbox-envs/base.js';
|
|
12
13
|
import type { SourceControlStorageHandle } from '../storage/domains/source-control/base.js';
|
|
13
14
|
import type { SessionEnvironment } from '../workspace.js';
|
|
14
15
|
import type { EnvironmentHeads } from './heads.js';
|
|
@@ -16,7 +17,7 @@ export declare const ENVIRONMENT_BUILD_TRIGGERS: readonly ['manual', 'schedule',
|
|
|
16
17
|
export type EnvironmentBuildTrigger = (typeof ENVIRONMENT_BUILD_TRIGGERS)[number];
|
|
17
18
|
export interface EnvironmentBuildSourceControl {
|
|
18
19
|
storage: Pick<SourceControlStorageHandle, 'projectRepositories' | 'repositories'>;
|
|
19
|
-
versionControl: Pick<VersionControl, 'getRepositoryAccess'>;
|
|
20
|
+
versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>;
|
|
20
21
|
}
|
|
21
22
|
export interface EnvironmentBuildDeps {
|
|
22
23
|
/** The factory's normalized sandbox; builds are unavailable without its `builds`. */
|
|
@@ -24,6 +25,8 @@ export interface EnvironmentBuildDeps {
|
|
|
24
25
|
projects: Pick<FactoryProjectsStorage, 'getById' | 'claimBuildAttempt' | 'claimBuildStart' | 'renewBuildStart' | 'releaseBuildStart' | 'pinActiveTemplate'>;
|
|
25
26
|
/** Absent when the factory has no source-control integration to resolve heads with. */
|
|
26
27
|
sourceControl: EnvironmentBuildSourceControl | undefined;
|
|
28
|
+
/** The Factory's sandbox environment variables; Build ones reach the template build. */
|
|
29
|
+
sandboxEnvs?: Pick<SandboxEnvStore, 'resolve'>;
|
|
27
30
|
logger?: {
|
|
28
31
|
info: (msg: string, meta?: Record<string, unknown>) => void;
|
|
29
32
|
};
|
|
@@ -57,14 +60,24 @@ export declare function errorReason(error: unknown): string;
|
|
|
57
60
|
* session id, with heads served from `heads` so the provider never resolves
|
|
58
61
|
* them itself.
|
|
59
62
|
*/
|
|
60
|
-
export declare function environmentBuildContext(project: Pick<FactoryProject, 'id' | 'orgId' | 'name'>, environment: SessionEnvironment, heads: EnvironmentHeads, versionControl: Pick<VersionControl, 'getRepositoryAccess'>): FactorySandboxContext;
|
|
63
|
+
export declare function environmentBuildContext(project: Pick<FactoryProject, 'id' | 'orgId' | 'name'>, environment: SessionEnvironment, heads: EnvironmentHeads, versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>): FactorySandboxContext;
|
|
64
|
+
/**
|
|
65
|
+
* {@link environmentBuildContext} with the Factory's Build variables, plus the
|
|
66
|
+
* build revision for {@link environmentBuildInputs}. Every build path (start,
|
|
67
|
+
* status read, poll) goes through this so all of them name the same template.
|
|
68
|
+
*/
|
|
69
|
+
export declare function environmentBuildContextWithEnv(project: Pick<FactoryProject, 'id' | 'orgId' | 'name'>, environment: SessionEnvironment, heads: EnvironmentHeads, versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>, sandboxEnvs: Pick<SandboxEnvStore, 'resolve'> | undefined): Promise<{
|
|
70
|
+
ctx: FactorySandboxContext;
|
|
71
|
+
buildEnvRevision: string | undefined;
|
|
72
|
+
}>;
|
|
61
73
|
/**
|
|
62
74
|
* Fingerprint of everything a build bakes into the template besides the
|
|
63
75
|
* repository heads: provider settings, the repositories and their order,
|
|
64
76
|
* their setup commands, the workspace setup command and the working
|
|
65
|
-
* directory
|
|
77
|
+
* directory, and the Build variables' revision (a random id, never a value).
|
|
78
|
+
* A schedule or push skips a ready build only while this matches.
|
|
66
79
|
*/
|
|
67
|
-
export declare function environmentBuildInputs(environment: SessionEnvironment): string;
|
|
80
|
+
export declare function environmentBuildInputs(environment: SessionEnvironment, buildEnvRevision?: string): string;
|
|
68
81
|
/**
|
|
69
82
|
* The current head of every environment repository's template branch, keyed
|
|
70
83
|
* by slug. The template clones the repository default branch (a link's own
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/environment/build.ts"],"names":[],"mappings":"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AAqB,GAAG,uBAAuB,CAAC,GACpF,qBAAqB,CAgBvB;AAED;;;;GAIG;AACH,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC,EACtD,WAAW,EAAE,kBAAkB,EAC/B,KAAK,EAAE,gBAAgB,EACvB,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,qBAAqB,GAAG,uBAAuB,CAAC,EACrF,WAAW,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,GAAG,SAAS,GACxD,OAAO,CAAC;IAAE,GAAG,EAAE,qBAAqB,CAAC;IAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC,CAS/E;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAczG;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,aAAa,EAAE,6BAA6B,EAC5C,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,EACtC,WAAW,EAAE,kBAAkB,GAC9B,OAAO,CAAC,gBAAgB,CAAC,CAS3B;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,QAAc,CAAC;AAKhD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,oBAAoB,EAC1B,KAAK,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,uBAAuB,CAAA;CAAE,GAC7D,OAAO,CAAC,uBAAuB,CAAC,CAuMlC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { maskSandboxEnvValues, resolveSandboxEnv, sandboxBuildContext } from "../sandbox/sandbox-env.js";
|
|
1
2
|
import { environmentSandboxContext, resolveProjectEnvironment } from "../workspace.js";
|
|
2
3
|
import { headsChanged, recordedHeadResolver, resolveCurrentHeads } from "./heads.js";
|
|
4
|
+
import { groupedRepositoryAccess } from "./repository-access.js";
|
|
3
5
|
import { createHash, randomUUID } from "crypto";
|
|
4
6
|
// src/environment/build.ts
|
|
5
7
|
/**
|
|
@@ -37,24 +39,45 @@ function errorReason(error) {
|
|
|
37
39
|
* them itself.
|
|
38
40
|
*/
|
|
39
41
|
function environmentBuildContext(project, environment, heads, versionControl) {
|
|
42
|
+
const repositoryAccess = groupedRepositoryAccess(versionControl, project.orgId, environment.repos.map((repo) => repo.repositoryId));
|
|
40
43
|
return {
|
|
41
44
|
sessionId: environmentBuildSessionId(project.id),
|
|
42
45
|
factoryId: project.id,
|
|
43
46
|
factoryName: project.name,
|
|
44
47
|
...environmentSandboxContext(environment, {
|
|
45
48
|
orgId: project.orgId,
|
|
46
|
-
getRepositoryAccess: (args) =>
|
|
49
|
+
getRepositoryAccess: (args) => repositoryAccess(args.repositoryId),
|
|
47
50
|
resolveHead: recordedHeadResolver(heads)
|
|
48
51
|
})
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
/**
|
|
55
|
+
* {@link environmentBuildContext} with the Factory's Build variables, plus the
|
|
56
|
+
* build revision for {@link environmentBuildInputs}. Every build path (start,
|
|
57
|
+
* status read, poll) goes through this so all of them name the same template.
|
|
58
|
+
*/
|
|
59
|
+
async function environmentBuildContextWithEnv(project, environment, heads, versionControl, sandboxEnvs) {
|
|
60
|
+
const env = sandboxEnvs ? await resolveSandboxEnv(sandboxEnvs, {
|
|
61
|
+
orgId: project.orgId,
|
|
62
|
+
projectId: project.id
|
|
63
|
+
}) : void 0;
|
|
64
|
+
const build = sandboxBuildContext(env);
|
|
65
|
+
return {
|
|
66
|
+
ctx: {
|
|
67
|
+
...environmentBuildContext(project, environment, heads, versionControl),
|
|
68
|
+
...build
|
|
69
|
+
},
|
|
70
|
+
buildEnvRevision: build.buildEnvRevision
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
52
74
|
* Fingerprint of everything a build bakes into the template besides the
|
|
53
75
|
* repository heads: provider settings, the repositories and their order,
|
|
54
76
|
* their setup commands, the workspace setup command and the working
|
|
55
|
-
* directory
|
|
77
|
+
* directory, and the Build variables' revision (a random id, never a value).
|
|
78
|
+
* A schedule or push skips a ready build only while this matches.
|
|
56
79
|
*/
|
|
57
|
-
function environmentBuildInputs(environment) {
|
|
80
|
+
function environmentBuildInputs(environment, buildEnvRevision) {
|
|
58
81
|
const inputs = {
|
|
59
82
|
settings: environment.settings,
|
|
60
83
|
workspaceSetupCommand: environment.workspaceSetupCommand ?? null,
|
|
@@ -63,7 +86,8 @@ function environmentBuildInputs(environment) {
|
|
|
63
86
|
repositoryId: repo.repositoryId,
|
|
64
87
|
templateBranch: repo.templateBranch,
|
|
65
88
|
setupCommand: repo.setupCommand ?? null
|
|
66
|
-
}))
|
|
89
|
+
})),
|
|
90
|
+
...buildEnvRevision ? { buildEnvRevision } : {}
|
|
67
91
|
};
|
|
68
92
|
return createHash("sha256").update(JSON.stringify(inputs)).digest("hex");
|
|
69
93
|
}
|
|
@@ -173,8 +197,8 @@ async function runEnvironmentBuild(deps, input) {
|
|
|
173
197
|
resolved,
|
|
174
198
|
now: now()
|
|
175
199
|
});
|
|
176
|
-
const failed = async (error, changes) => {
|
|
177
|
-
const reason = errorReason(error);
|
|
200
|
+
const failed = async (error, changes, buildEnv) => {
|
|
201
|
+
const reason = maskSandboxEnvValues(errorReason(error), buildEnv);
|
|
178
202
|
await release(changes);
|
|
179
203
|
deps.logger?.info("environment build failed", {
|
|
180
204
|
factoryProjectId: initial.id,
|
|
@@ -203,8 +227,9 @@ async function runEnvironmentBuild(deps, input) {
|
|
|
203
227
|
};
|
|
204
228
|
}
|
|
205
229
|
heads = await resolveEnvironmentHeads(sourceControl, project, environment);
|
|
206
|
-
|
|
207
|
-
|
|
230
|
+
const built = await environmentBuildContextWithEnv(project, environment, heads, sourceControl.versionControl, deps.sandboxEnvs);
|
|
231
|
+
ctx = built.ctx;
|
|
232
|
+
buildInputs = environmentBuildInputs(environment, built.buildEnvRevision);
|
|
208
233
|
if (claim.uncertain) {
|
|
209
234
|
if (builds.list) {
|
|
210
235
|
const running = (await builds.list(ctx, environment.settings)).find((build) => build.status === "pending" || build.status === "building");
|
|
@@ -288,7 +313,7 @@ async function runEnvironmentBuild(deps, input) {
|
|
|
288
313
|
lastBuildHeads: null,
|
|
289
314
|
lastBuildInputs: null,
|
|
290
315
|
...attempted
|
|
291
|
-
});
|
|
316
|
+
}, ctx.buildEnv);
|
|
292
317
|
}
|
|
293
318
|
const log = {
|
|
294
319
|
factoryProjectId: project.id,
|
|
@@ -342,6 +367,6 @@ async function runEnvironmentBuild(deps, input) {
|
|
|
342
367
|
clearInterval(renewal);
|
|
343
368
|
}
|
|
344
369
|
}
|
|
345
|
-
export { BUILD_START_LEASE_MS, ENVIRONMENT_BUILD_TRIGGERS, environmentBuildContext, environmentBuildInputs, environmentBuildSessionId, errorReason, redactCredentials, resolveEnvironmentHeads, runEnvironmentBuild };
|
|
370
|
+
export { BUILD_START_LEASE_MS, ENVIRONMENT_BUILD_TRIGGERS, environmentBuildContext, environmentBuildContextWithEnv, environmentBuildInputs, environmentBuildSessionId, errorReason, redactCredentials, resolveEnvironmentHeads, runEnvironmentBuild };
|
|
346
371
|
|
|
347
372
|
//# sourceMappingURL=build.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","names":[],"sources":["../../src/environment/build.ts"],"sourcesContent":["/**\n * One proactive environment build: decide whether a trigger should build,\n * hand the sandbox's `builds` capability a context identical to a session's,\n * and record the started build on the project row. Polling the build to its\n * end and pinning the active template is the workflow's second step\n * (`build-workflow.ts`), so a request that only needs the start answer never\n * waits on the provider.\n */\n\nimport { createHash, randomUUID } from 'node:crypto';\n\nimport type { FactorySandbox, FactorySandboxContext } from '@mastra/core/workspace';\nimport type { VersionControl } from '../capabilities/version-control.js';\nimport type { FactoryProject, FactoryProjectsStorage } from '../storage/domains/projects/base.js';\nimport type { SourceControlStorageHandle } from '../storage/domains/source-control/base.js';\nimport { environmentSandboxContext, resolveProjectEnvironment } from '../workspace.js';\nimport type { SessionEnvironment } from '../workspace.js';\nimport { headsChanged, recordedHeadResolver, resolveCurrentHeads } from './heads.js';\nimport type { EnvironmentHeads } from './heads.js';\n\nexport const ENVIRONMENT_BUILD_TRIGGERS = ['manual', 'schedule', 'push'] as const;\nexport type EnvironmentBuildTrigger = (typeof ENVIRONMENT_BUILD_TRIGGERS)[number];\n\nexport interface EnvironmentBuildSourceControl {\n storage: Pick<SourceControlStorageHandle, 'projectRepositories' | 'repositories'>;\n versionControl: Pick<VersionControl, 'getRepositoryAccess'>;\n}\n\nexport interface EnvironmentBuildDeps {\n /** The factory's normalized sandbox; builds are unavailable without its `builds`. */\n sandbox: FactorySandbox | undefined;\n projects: Pick<\n FactoryProjectsStorage,\n 'getById' | 'claimBuildAttempt' | 'claimBuildStart' | 'renewBuildStart' | 'releaseBuildStart' | 'pinActiveTemplate'\n >;\n /** Absent when the factory has no source-control integration to resolve heads with. */\n sourceControl: EnvironmentBuildSourceControl | undefined;\n logger?: { info: (msg: string, meta?: Record<string, unknown>) => void };\n now?: () => Date;\n /** How often a run renews its build-start lease; a third of `BUILD_START_LEASE_MS` by default. */\n leaseRenewMs?: number;\n /** Waits between tries at recording a started build. */\n sleep?: (ms: number) => Promise<void>;\n}\n\nexport interface EnvironmentBuildOutcome {\n outcome: 'started' | 'skipped' | 'unavailable' | 'failed';\n buildId?: string;\n templateId?: string;\n /** Why nothing started: `debounced`, `starting` (another run is starting a build), `in_progress`, `unchanged`, `unresolved` (a lapsed run may have started a build the provider cannot list), `no_environment`, `no_builds`, `no_source_control`; why a run failed: `not_recorded`, `superseded`, or an error. */\n reason?: string;\n /** The heads the started build pins; the workflow stores them once the build is ready. */\n heads?: EnvironmentHeads;\n}\n\n/** The synthetic session id a project's build runs under; never a session. */\nexport function environmentBuildSessionId(projectId: string): string {\n return `environment-build:${projectId}`;\n}\n\n/**\n * A build or setup error may echo a clone URL or a token; strip URL userinfo\n * and GitHub token shapes before the message is stored, logged or shown.\n */\nexport function redactCredentials(message: string): string {\n return message.replace(/\\/\\/[^/\\s@]+@/g, '//***@').replace(/\\b(?:gh[pousr]|github_pat)_[A-Za-z0-9_]+/g, '***');\n}\n\n/** An error's message with credentials redacted, safe to log, store or return. */\nexport function errorReason(error: unknown): string {\n return redactCredentials(error instanceof Error ? error.message : String(error));\n}\n\n/**\n * The context an environment build (or a read of its status) hands the\n * provider: the same list form a session boots with, under the build's own\n * session id, with heads served from `heads` so the provider never resolves\n * them itself.\n */\nexport function environmentBuildContext(\n project: Pick<FactoryProject, 'id' | 'orgId' | 'name'>,\n environment: SessionEnvironment,\n heads: EnvironmentHeads,\n versionControl: Pick<VersionControl, 'getRepositoryAccess'>,\n): FactorySandboxContext {\n return {\n sessionId: environmentBuildSessionId(project.id),\n factoryId: project.id,\n factoryName: project.name,\n ...environmentSandboxContext(environment, {\n orgId: project.orgId,\n getRepositoryAccess: args => versionControl.getRepositoryAccess(args),\n resolveHead: recordedHeadResolver(heads),\n }),\n };\n}\n\n/**\n * Fingerprint of everything a build bakes into the template besides the\n * repository heads: provider settings, the repositories and their order,\n * their setup commands, the workspace setup command and the working\n * directory. A schedule or push skips a ready build only while this matches.\n */\nexport function environmentBuildInputs(environment: SessionEnvironment): string {\n const inputs = {\n settings: environment.settings,\n workspaceSetupCommand: environment.workspaceSetupCommand ?? null,\n workingDirectory: environment.workingDirectory ?? null,\n repos: environment.repos.map(repo => ({\n repositoryId: repo.repositoryId,\n templateBranch: repo.templateBranch,\n setupCommand: repo.setupCommand ?? null,\n })),\n };\n return createHash('sha256').update(JSON.stringify(inputs)).digest('hex');\n}\n\n/**\n * The current head of every environment repository's template branch, keyed\n * by slug. The template clones the repository default branch (a link's own\n * branch is the session's base, checked out after boot), so that is the\n * branch a build pins; sessions let the provider resolve the same head.\n */\nexport async function resolveEnvironmentHeads(\n sourceControl: EnvironmentBuildSourceControl,\n project: Pick<FactoryProject, 'orgId'>,\n environment: SessionEnvironment,\n): Promise<EnvironmentHeads> {\n return resolveCurrentHeads(sourceControl, {\n orgId: project.orgId,\n repositories: environment.repos.map(repo => ({\n id: repo.repositoryId,\n slug: repo.slug,\n branch: repo.templateBranch,\n })),\n });\n}\n\n/**\n * How long a build-start lease lasts without renewal. The run holding it\n * renews it every third of that while it works, so a lease lapses only when\n * its run died or stalled.\n */\nexport const BUILD_START_LEASE_MS = 10 * 60_000;\n\n/** Tries at recording a started build before the run leaves its lease to lapse. */\nconst RECORD_ATTEMPTS = 5;\n\n/**\n * Start a build for `projectId` when `trigger` calls for one. Every trigger\n * takes the project's build-start lease before reading build state and renews\n * it until the started build is recorded, so overlapping manual, scheduled and\n * push runs never both start a build, however long the provider takes; a run\n * that finds the lease held skips as `starting`. Every trigger skips while the\n * last build is still running; `schedule` and `push` also skip when the last\n * build is ready and neither a head nor any other template input changed;\n * `manual` otherwise always builds. A `push` that would build then takes the\n * leading-edge debounce claim, so only a push that starts a build opens the\n * window. Saving settings never builds.\n *\n * Taking over a lapsed lease leaves the start uncertain: the lapsed run may\n * have started a build it never recorded. The mark persists until resolved.\n * While it stands, a provider that lists builds is asked for a running one\n * (and every trigger skips as `in_progress` on it); with a provider that\n * cannot list, every trigger skips as `unresolved`.\n *\n * The result is written as the lease is released, and only while this run\n * still holds it. A failed `builds.start` clears the last build id, so a later\n * `schedule` or `push` cannot mistake the previous ready build for the current\n * template; any other error keeps a running build's id. A started build whose\n * recording keeps failing yields `failed` (`not_recorded`) with the lease left\n * to lapse rather than released, and a run that lost its lease while the\n * provider started yields `failed` (`superseded`); neither is polled or pinned.\n */\nexport async function runEnvironmentBuild(\n deps: EnvironmentBuildDeps,\n input: { projectId: string; trigger: EnvironmentBuildTrigger },\n): Promise<EnvironmentBuildOutcome> {\n const builds = deps.sandbox?.builds;\n if (!builds) return { outcome: 'unavailable', reason: 'no_builds' };\n if (!deps.sourceControl) return { outcome: 'unavailable', reason: 'no_source_control' };\n const sourceControl = deps.sourceControl;\n const initial = await deps.projects.getById({ id: input.projectId });\n if (!initial) return { outcome: 'skipped', reason: 'no_environment' };\n const now = deps.now ?? (() => new Date());\n const sleep = deps.sleep ?? ((ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms)));\n\n const pushDebounced = (project: FactoryProject, at: Date) =>\n project.lastPushBuildAt !== null &&\n at.getTime() - project.lastPushBuildAt.getTime() < project.buildPushDebounceMinutes * 60_000;\n if (input.trigger === 'push' && pushDebounced(initial, now())) return { outcome: 'skipped', reason: 'debounced' };\n\n const token = randomUUID();\n const lease = { id: initial.id, token, leaseMs: BUILD_START_LEASE_MS };\n const claim = await deps.projects.claimBuildStart({ ...lease, now: now() });\n if (!claim.claimed) return { outcome: 'skipped', reason: 'starting' };\n let held = true;\n const renewal = setInterval(\n () => {\n deps.projects.renewBuildStart({ ...lease, now: now() }).then(\n renewed => {\n if (!renewed) held = false;\n },\n // A failed renewal is retried on the next tick; the lease outlasts two misses.\n () => {},\n );\n },\n deps.leaseRenewMs ?? BUILD_START_LEASE_MS / 3,\n );\n renewal.unref?.();\n\n const attempted = { lastBuildAttemptedAt: now() };\n // Set once this run has reconciled an uncertain start, or builds past it.\n let resolved = false;\n const release = (changes: Parameters<EnvironmentBuildDeps['projects']['releaseBuildStart']>[0]['changes'] = {}) =>\n deps.projects.releaseBuildStart({ id: initial.id, token, changes, resolved, now: now() });\n const failed = async (error: unknown, changes: Parameters<typeof release>[0]) => {\n const reason = errorReason(error);\n await release(changes);\n deps.logger?.info('environment build failed', { factoryProjectId: initial.id, trigger: input.trigger, reason });\n return { outcome: 'failed', reason } satisfies EnvironmentBuildOutcome;\n };\n\n try {\n let project: FactoryProject;\n let environment: SessionEnvironment;\n let heads: EnvironmentHeads;\n let ctx: FactorySandboxContext;\n let buildInputs: string;\n try {\n // Read build state only once this run holds the lease, so a run that\n // finished while this one waited has already recorded its build.\n project = (await deps.projects.getById({ id: initial.id })) ?? initial;\n environment = await resolveProjectEnvironment(sourceControl.storage, project);\n if (environment.repos.length === 0) {\n await release();\n return { outcome: 'skipped', reason: 'no_environment' };\n }\n heads = await resolveEnvironmentHeads(sourceControl, project, environment);\n ctx = environmentBuildContext(project, environment, heads, sourceControl.versionControl);\n buildInputs = environmentBuildInputs(environment);\n\n if (claim.uncertain) {\n // A run whose lease lapsed may have reached the provider before it\n // died; a build it left running is never raced by a second one. The\n // mark stays until that build is gone, since its inputs are unknown.\n if (builds.list) {\n const listed = await builds.list(ctx, environment.settings);\n const running = listed.find(build => build.status === 'pending' || build.status === 'building');\n if (running) {\n await release();\n return { outcome: 'skipped', reason: 'in_progress', buildId: running.buildId };\n }\n resolved = true;\n } else {\n // Without history the earlier start can never be reconciled, so no\n // trigger starts another build beside it.\n await release();\n return { outcome: 'skipped', reason: 'unresolved' };\n }\n }\n\n if (project.lastBuildId) {\n const last = await builds.get(ctx, environment.settings, project.lastBuildId);\n // Two runs polling one template fight over it (each poll resubmits its\n // own definition and the provider cancels the other), so a running\n // build is never joined by a second one, whatever asked.\n if (last.status === 'pending' || last.status === 'building') {\n await release();\n return { outcome: 'skipped', reason: 'in_progress', buildId: project.lastBuildId };\n }\n // A ready build whose poll ran out or died with its host was never\n // pinned; pin it now so the skip below compares against what it built.\n let pinnedHeads = project.activeTemplateHeads;\n const lastTemplateId = last.templateId ?? project.lastBuildId;\n if (last.status === 'ready' && project.lastBuildHeads && project.activeTemplateId !== lastTemplateId) {\n const pinned = await deps.projects.pinActiveTemplate({\n id: project.id,\n buildId: project.lastBuildId,\n templateId: lastTemplateId,\n heads: project.lastBuildHeads,\n });\n if (pinned) pinnedHeads = project.lastBuildHeads;\n }\n if (\n (input.trigger === 'schedule' || input.trigger === 'push') &&\n last.status === 'ready' &&\n !headsChanged(pinnedHeads, heads) &&\n project.lastBuildInputs === buildInputs\n ) {\n await release();\n return { outcome: 'skipped', reason: 'unchanged' };\n }\n }\n } catch (error) {\n return await failed(error, attempted);\n }\n\n // A run that lost its lease while reading must not start beside its successor.\n if (!held) return { outcome: 'skipped', reason: 'starting' };\n\n if (input.trigger === 'push') {\n // Claimed only now, so a push that skipped above never closes the window.\n let claimed: boolean;\n try {\n claimed = await deps.projects.claimBuildAttempt({\n id: project.id,\n debounceMinutes: project.buildPushDebounceMinutes,\n now: now(),\n });\n } catch (error) {\n return await failed(error, {});\n }\n if (!claimed) {\n await release();\n return { outcome: 'skipped', reason: 'debounced' };\n }\n }\n\n let started: Awaited<ReturnType<typeof builds.start>>;\n try {\n started = await builds.start(ctx, environment.settings);\n } catch (error) {\n // Only a failed start clears the last build: the previous one no longer\n // describes the template this project wants.\n return await failed(error, { lastBuildId: null, lastBuildHeads: null, lastBuildInputs: null, ...attempted });\n }\n\n // The provider has started the build: from here on, no error clears it.\n const log = { factoryProjectId: project.id, trigger: input.trigger, buildId: started.buildId };\n const changes = { lastBuildId: started.buildId, lastBuildHeads: heads, lastBuildInputs: buildInputs, ...attempted };\n let recorded: boolean | undefined;\n for (let attempt = 1; recorded === undefined; attempt++) {\n try {\n recorded = await release(changes);\n } catch (error) {\n if (attempt >= RECORD_ATTEMPTS) {\n // Keep the lease: it lapses once renewal stops, and the run that\n // takes it over looks for this build at the provider first.\n deps.logger?.info('environment build started but not recorded', { ...log, reason: errorReason(error) });\n return { outcome: 'failed', reason: 'not_recorded', buildId: started.buildId };\n }\n await sleep(1000 * 2 ** (attempt - 1));\n }\n }\n if (!recorded) {\n // A newer run took the lease while the provider started this build; the\n // project tracks that run's build, so this one is never polled or pinned.\n deps.logger?.info('environment build superseded', log);\n return { outcome: 'failed', reason: 'superseded', buildId: started.buildId };\n }\n try {\n deps.logger?.info('environment build started', { ...log, templateId: started.templateId });\n } catch {\n // Logging never turns a recorded build into a failure.\n }\n return {\n outcome: 'started',\n buildId: started.buildId,\n ...(started.templateId ? { templateId: started.templateId } : {}),\n heads,\n };\n } finally {\n clearInterval(renewal);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAa,6BAA6B;CAAC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EAGA,MAAM,MAAM;GAAE,kBAAkB,QAAQ;GAAI,SAAS,MAAM;GAAS,SAAS,QAAQ;EAAQ;EAC7F,MAAM,UAAU;GAAE,aAAa,QAAQ;GAAS,gBAAgB;GAAO,iBAAiB;GAAa,GAAG;EAAU;EAClH,IAAI;EACJ,KAAK,IAAI,UAAU,GAAG,aAAa,KAAA,GAAW,WAC5C,IAAI;GACF,WAAW,MAAM,QAAQ,OAAO;EAClC,SAAS,OAAO;GACd,IAAI,WAAW,iBAAiB;IAG9B,KAAK,QAAQ,KAAK,8CAA8C;KAAE,GAAG;KAAK,QAAQ,YAAY,KAAK;IAAE,CAAC;IACtG,OAAO;KAAE,SAAS;KAAU,QAAQ;KAAgB,SAAS,QAAQ;IAAQ;GAC/E;GACA,MAAM,MAAM,MAAO,MAAM,UAAU,EAAE;EACvC;EAEF,IAAI,CAAC,UAAU;GAGb,KAAK,QAAQ,KAAK,gCAAgC,GAAG;GACrD,OAAO;IAAE,SAAS;IAAU,QAAQ;IAAc,SAAS,QAAQ;GAAQ;EAC7E;EACA,IAAI;GACF,KAAK,QAAQ,KAAK,6BAA6B;IAAE,GAAG;IAAK,YAAY,QAAQ;GAAW,CAAC;EAC3F,QAAQ,CAER;EACA,OAAO;GACL,SAAS;GACT,SAAS,QAAQ;GACjB,GAAI,QAAQ,aAAa,EAAE,YAAY,QAAQ,WAAW,IAAI,CAAC;GAC/D;EACF;CACF,UAAU;EACR,cAAc,OAAO;CACvB;AACF"}
|
|
1
|
+
{"version":3,"file":"build.js","names":[],"sources":["../../src/environment/build.ts"],"sourcesContent":["/**\n * One proactive environment build: decide whether a trigger should build,\n * hand the sandbox's `builds` capability a context identical to a session's,\n * and record the started build on the project row. Polling the build to its\n * end and pinning the active template is the workflow's second step\n * (`build-workflow.ts`), so a request that only needs the start answer never\n * waits on the provider.\n */\n\nimport { createHash, randomUUID } from 'node:crypto';\n\nimport type { FactorySandbox, FactorySandboxContext } from '@mastra/core/workspace';\nimport type { VersionControl } from '../capabilities/version-control.js';\nimport { maskSandboxEnvValues, resolveSandboxEnv, sandboxBuildContext } from '../sandbox/sandbox-env.js';\nimport type { FactoryProject, FactoryProjectsStorage } from '../storage/domains/projects/base.js';\nimport type { SandboxEnvStore } from '../storage/domains/sandbox-envs/base.js';\nimport type { SourceControlStorageHandle } from '../storage/domains/source-control/base.js';\nimport { environmentSandboxContext, resolveProjectEnvironment } from '../workspace.js';\nimport type { SessionEnvironment } from '../workspace.js';\nimport { headsChanged, recordedHeadResolver, resolveCurrentHeads } from './heads.js';\nimport type { EnvironmentHeads } from './heads.js';\nimport { groupedRepositoryAccess } from './repository-access.js';\n\nexport const ENVIRONMENT_BUILD_TRIGGERS = ['manual', 'schedule', 'push'] as const;\nexport type EnvironmentBuildTrigger = (typeof ENVIRONMENT_BUILD_TRIGGERS)[number];\n\nexport interface EnvironmentBuildSourceControl {\n storage: Pick<SourceControlStorageHandle, 'projectRepositories' | 'repositories'>;\n versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>;\n}\n\nexport interface EnvironmentBuildDeps {\n /** The factory's normalized sandbox; builds are unavailable without its `builds`. */\n sandbox: FactorySandbox | undefined;\n projects: Pick<\n FactoryProjectsStorage,\n 'getById' | 'claimBuildAttempt' | 'claimBuildStart' | 'renewBuildStart' | 'releaseBuildStart' | 'pinActiveTemplate'\n >;\n /** Absent when the factory has no source-control integration to resolve heads with. */\n sourceControl: EnvironmentBuildSourceControl | undefined;\n /** The Factory's sandbox environment variables; Build ones reach the template build. */\n sandboxEnvs?: Pick<SandboxEnvStore, 'resolve'>;\n logger?: { info: (msg: string, meta?: Record<string, unknown>) => void };\n now?: () => Date;\n /** How often a run renews its build-start lease; a third of `BUILD_START_LEASE_MS` by default. */\n leaseRenewMs?: number;\n /** Waits between tries at recording a started build. */\n sleep?: (ms: number) => Promise<void>;\n}\n\nexport interface EnvironmentBuildOutcome {\n outcome: 'started' | 'skipped' | 'unavailable' | 'failed';\n buildId?: string;\n templateId?: string;\n /** Why nothing started: `debounced`, `starting` (another run is starting a build), `in_progress`, `unchanged`, `unresolved` (a lapsed run may have started a build the provider cannot list), `no_environment`, `no_builds`, `no_source_control`; why a run failed: `not_recorded`, `superseded`, or an error. */\n reason?: string;\n /** The heads the started build pins; the workflow stores them once the build is ready. */\n heads?: EnvironmentHeads;\n}\n\n/** The synthetic session id a project's build runs under; never a session. */\nexport function environmentBuildSessionId(projectId: string): string {\n return `environment-build:${projectId}`;\n}\n\n/**\n * A build or setup error may echo a clone URL or a token; strip URL userinfo\n * and GitHub token shapes before the message is stored, logged or shown.\n */\nexport function redactCredentials(message: string): string {\n return message.replace(/\\/\\/[^/\\s@]+@/g, '//***@').replace(/\\b(?:gh[pousr]|github_pat)_[A-Za-z0-9_]+/g, '***');\n}\n\n/** An error's message with credentials redacted, safe to log, store or return. */\nexport function errorReason(error: unknown): string {\n return redactCredentials(error instanceof Error ? error.message : String(error));\n}\n\n/**\n * The context an environment build (or a read of its status) hands the\n * provider: the same list form a session boots with, under the build's own\n * session id, with heads served from `heads` so the provider never resolves\n * them itself.\n */\nexport function environmentBuildContext(\n project: Pick<FactoryProject, 'id' | 'orgId' | 'name'>,\n environment: SessionEnvironment,\n heads: EnvironmentHeads,\n versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>,\n): FactorySandboxContext {\n const repositoryAccess = groupedRepositoryAccess(\n versionControl,\n project.orgId,\n environment.repos.map(repo => repo.repositoryId),\n );\n return {\n sessionId: environmentBuildSessionId(project.id),\n factoryId: project.id,\n factoryName: project.name,\n ...environmentSandboxContext(environment, {\n orgId: project.orgId,\n getRepositoryAccess: args => repositoryAccess(args.repositoryId),\n resolveHead: recordedHeadResolver(heads),\n }),\n };\n}\n\n/**\n * {@link environmentBuildContext} with the Factory's Build variables, plus the\n * build revision for {@link environmentBuildInputs}. Every build path (start,\n * status read, poll) goes through this so all of them name the same template.\n */\nexport async function environmentBuildContextWithEnv(\n project: Pick<FactoryProject, 'id' | 'orgId' | 'name'>,\n environment: SessionEnvironment,\n heads: EnvironmentHeads,\n versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>,\n sandboxEnvs: Pick<SandboxEnvStore, 'resolve'> | undefined,\n): Promise<{ ctx: FactorySandboxContext; buildEnvRevision: string | undefined }> {\n const env = sandboxEnvs\n ? await resolveSandboxEnv(sandboxEnvs, { orgId: project.orgId, projectId: project.id })\n : undefined;\n const build = sandboxBuildContext(env);\n return {\n ctx: { ...environmentBuildContext(project, environment, heads, versionControl), ...build },\n buildEnvRevision: build.buildEnvRevision,\n };\n}\n\n/**\n * Fingerprint of everything a build bakes into the template besides the\n * repository heads: provider settings, the repositories and their order,\n * their setup commands, the workspace setup command and the working\n * directory, and the Build variables' revision (a random id, never a value).\n * A schedule or push skips a ready build only while this matches.\n */\nexport function environmentBuildInputs(environment: SessionEnvironment, buildEnvRevision?: string): string {\n const inputs = {\n settings: environment.settings,\n workspaceSetupCommand: environment.workspaceSetupCommand ?? null,\n workingDirectory: environment.workingDirectory ?? null,\n repos: environment.repos.map(repo => ({\n repositoryId: repo.repositoryId,\n templateBranch: repo.templateBranch,\n setupCommand: repo.setupCommand ?? null,\n })),\n // Only when set, so fingerprints recorded before Build variables existed still match.\n ...(buildEnvRevision ? { buildEnvRevision } : {}),\n };\n return createHash('sha256').update(JSON.stringify(inputs)).digest('hex');\n}\n\n/**\n * The current head of every environment repository's template branch, keyed\n * by slug. The template clones the repository default branch (a link's own\n * branch is the session's base, checked out after boot), so that is the\n * branch a build pins; sessions let the provider resolve the same head.\n */\nexport async function resolveEnvironmentHeads(\n sourceControl: EnvironmentBuildSourceControl,\n project: Pick<FactoryProject, 'orgId'>,\n environment: SessionEnvironment,\n): Promise<EnvironmentHeads> {\n return resolveCurrentHeads(sourceControl, {\n orgId: project.orgId,\n repositories: environment.repos.map(repo => ({\n id: repo.repositoryId,\n slug: repo.slug,\n branch: repo.templateBranch,\n })),\n });\n}\n\n/**\n * How long a build-start lease lasts without renewal. The run holding it\n * renews it every third of that while it works, so a lease lapses only when\n * its run died or stalled.\n */\nexport const BUILD_START_LEASE_MS = 10 * 60_000;\n\n/** Tries at recording a started build before the run leaves its lease to lapse. */\nconst RECORD_ATTEMPTS = 5;\n\n/**\n * Start a build for `projectId` when `trigger` calls for one. Every trigger\n * takes the project's build-start lease before reading build state and renews\n * it until the started build is recorded, so overlapping manual, scheduled and\n * push runs never both start a build, however long the provider takes; a run\n * that finds the lease held skips as `starting`. Every trigger skips while the\n * last build is still running; `schedule` and `push` also skip when the last\n * build is ready and neither a head nor any other template input changed;\n * `manual` otherwise always builds. A `push` that would build then takes the\n * leading-edge debounce claim, so only a push that starts a build opens the\n * window. Saving settings never builds.\n *\n * Taking over a lapsed lease leaves the start uncertain: the lapsed run may\n * have started a build it never recorded. The mark persists until resolved.\n * While it stands, a provider that lists builds is asked for a running one\n * (and every trigger skips as `in_progress` on it); with a provider that\n * cannot list, every trigger skips as `unresolved`.\n *\n * The result is written as the lease is released, and only while this run\n * still holds it. A failed `builds.start` clears the last build id, so a later\n * `schedule` or `push` cannot mistake the previous ready build for the current\n * template; any other error keeps a running build's id. A started build whose\n * recording keeps failing yields `failed` (`not_recorded`) with the lease left\n * to lapse rather than released, and a run that lost its lease while the\n * provider started yields `failed` (`superseded`); neither is polled or pinned.\n */\nexport async function runEnvironmentBuild(\n deps: EnvironmentBuildDeps,\n input: { projectId: string; trigger: EnvironmentBuildTrigger },\n): Promise<EnvironmentBuildOutcome> {\n const builds = deps.sandbox?.builds;\n if (!builds) return { outcome: 'unavailable', reason: 'no_builds' };\n if (!deps.sourceControl) return { outcome: 'unavailable', reason: 'no_source_control' };\n const sourceControl = deps.sourceControl;\n const initial = await deps.projects.getById({ id: input.projectId });\n if (!initial) return { outcome: 'skipped', reason: 'no_environment' };\n const now = deps.now ?? (() => new Date());\n const sleep = deps.sleep ?? ((ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms)));\n\n const pushDebounced = (project: FactoryProject, at: Date) =>\n project.lastPushBuildAt !== null &&\n at.getTime() - project.lastPushBuildAt.getTime() < project.buildPushDebounceMinutes * 60_000;\n if (input.trigger === 'push' && pushDebounced(initial, now())) return { outcome: 'skipped', reason: 'debounced' };\n\n const token = randomUUID();\n const lease = { id: initial.id, token, leaseMs: BUILD_START_LEASE_MS };\n const claim = await deps.projects.claimBuildStart({ ...lease, now: now() });\n if (!claim.claimed) return { outcome: 'skipped', reason: 'starting' };\n let held = true;\n const renewal = setInterval(\n () => {\n deps.projects.renewBuildStart({ ...lease, now: now() }).then(\n renewed => {\n if (!renewed) held = false;\n },\n // A failed renewal is retried on the next tick; the lease outlasts two misses.\n () => {},\n );\n },\n deps.leaseRenewMs ?? BUILD_START_LEASE_MS / 3,\n );\n renewal.unref?.();\n\n const attempted = { lastBuildAttemptedAt: now() };\n // Set once this run has reconciled an uncertain start, or builds past it.\n let resolved = false;\n const release = (changes: Parameters<EnvironmentBuildDeps['projects']['releaseBuildStart']>[0]['changes'] = {}) =>\n deps.projects.releaseBuildStart({ id: initial.id, token, changes, resolved, now: now() });\n const failed = async (error: unknown, changes: Parameters<typeof release>[0], buildEnv?: Record<string, string>) => {\n const reason = maskSandboxEnvValues(errorReason(error), buildEnv);\n await release(changes);\n deps.logger?.info('environment build failed', { factoryProjectId: initial.id, trigger: input.trigger, reason });\n return { outcome: 'failed', reason } satisfies EnvironmentBuildOutcome;\n };\n\n try {\n let project: FactoryProject;\n let environment: SessionEnvironment;\n let heads: EnvironmentHeads;\n let ctx: FactorySandboxContext;\n let buildInputs: string;\n try {\n // Read build state only once this run holds the lease, so a run that\n // finished while this one waited has already recorded its build.\n project = (await deps.projects.getById({ id: initial.id })) ?? initial;\n environment = await resolveProjectEnvironment(sourceControl.storage, project);\n if (environment.repos.length === 0) {\n await release();\n return { outcome: 'skipped', reason: 'no_environment' };\n }\n heads = await resolveEnvironmentHeads(sourceControl, project, environment);\n const built = await environmentBuildContextWithEnv(\n project,\n environment,\n heads,\n sourceControl.versionControl,\n deps.sandboxEnvs,\n );\n ctx = built.ctx;\n buildInputs = environmentBuildInputs(environment, built.buildEnvRevision);\n\n if (claim.uncertain) {\n // A run whose lease lapsed may have reached the provider before it\n // died; a build it left running is never raced by a second one. The\n // mark stays until that build is gone, since its inputs are unknown.\n if (builds.list) {\n const listed = await builds.list(ctx, environment.settings);\n const running = listed.find(build => build.status === 'pending' || build.status === 'building');\n if (running) {\n await release();\n return { outcome: 'skipped', reason: 'in_progress', buildId: running.buildId };\n }\n resolved = true;\n } else {\n // Without history the earlier start can never be reconciled, so no\n // trigger starts another build beside it.\n await release();\n return { outcome: 'skipped', reason: 'unresolved' };\n }\n }\n\n if (project.lastBuildId) {\n const last = await builds.get(ctx, environment.settings, project.lastBuildId);\n // Two runs polling one template fight over it (each poll resubmits its\n // own definition and the provider cancels the other), so a running\n // build is never joined by a second one, whatever asked.\n if (last.status === 'pending' || last.status === 'building') {\n await release();\n return { outcome: 'skipped', reason: 'in_progress', buildId: project.lastBuildId };\n }\n // A ready build whose poll ran out or died with its host was never\n // pinned; pin it now so the skip below compares against what it built.\n let pinnedHeads = project.activeTemplateHeads;\n const lastTemplateId = last.templateId ?? project.lastBuildId;\n if (last.status === 'ready' && project.lastBuildHeads && project.activeTemplateId !== lastTemplateId) {\n const pinned = await deps.projects.pinActiveTemplate({\n id: project.id,\n buildId: project.lastBuildId,\n templateId: lastTemplateId,\n heads: project.lastBuildHeads,\n });\n if (pinned) pinnedHeads = project.lastBuildHeads;\n }\n if (\n (input.trigger === 'schedule' || input.trigger === 'push') &&\n last.status === 'ready' &&\n !headsChanged(pinnedHeads, heads) &&\n project.lastBuildInputs === buildInputs\n ) {\n await release();\n return { outcome: 'skipped', reason: 'unchanged' };\n }\n }\n } catch (error) {\n return await failed(error, attempted);\n }\n\n // A run that lost its lease while reading must not start beside its successor.\n if (!held) return { outcome: 'skipped', reason: 'starting' };\n\n if (input.trigger === 'push') {\n // Claimed only now, so a push that skipped above never closes the window.\n let claimed: boolean;\n try {\n claimed = await deps.projects.claimBuildAttempt({\n id: project.id,\n debounceMinutes: project.buildPushDebounceMinutes,\n now: now(),\n });\n } catch (error) {\n return await failed(error, {});\n }\n if (!claimed) {\n await release();\n return { outcome: 'skipped', reason: 'debounced' };\n }\n }\n\n let started: Awaited<ReturnType<typeof builds.start>>;\n try {\n started = await builds.start(ctx, environment.settings);\n } catch (error) {\n // Only a failed start clears the last build: the previous one no longer\n // describes the template this project wants.\n return await failed(\n error,\n { lastBuildId: null, lastBuildHeads: null, lastBuildInputs: null, ...attempted },\n ctx.buildEnv,\n );\n }\n\n // The provider has started the build: from here on, no error clears it.\n const log = { factoryProjectId: project.id, trigger: input.trigger, buildId: started.buildId };\n const changes = { lastBuildId: started.buildId, lastBuildHeads: heads, lastBuildInputs: buildInputs, ...attempted };\n let recorded: boolean | undefined;\n for (let attempt = 1; recorded === undefined; attempt++) {\n try {\n recorded = await release(changes);\n } catch (error) {\n if (attempt >= RECORD_ATTEMPTS) {\n // Keep the lease: it lapses once renewal stops, and the run that\n // takes it over looks for this build at the provider first.\n deps.logger?.info('environment build started but not recorded', { ...log, reason: errorReason(error) });\n return { outcome: 'failed', reason: 'not_recorded', buildId: started.buildId };\n }\n await sleep(1000 * 2 ** (attempt - 1));\n }\n }\n if (!recorded) {\n // A newer run took the lease while the provider started this build; the\n // project tracks that run's build, so this one is never polled or pinned.\n deps.logger?.info('environment build superseded', log);\n return { outcome: 'failed', reason: 'superseded', buildId: started.buildId };\n }\n try {\n deps.logger?.info('environment build started', { ...log, templateId: started.templateId });\n } catch {\n // Logging never turns a recorded build into a failure.\n }\n return {\n outcome: 'started',\n buildId: started.buildId,\n ...(started.templateId ? { templateId: started.templateId } : {}),\n heads,\n };\n } finally {\n clearInterval(renewal);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAa,6BAA6B;CAAC;CAAU;CAAY;AAAM;;AAsCvE,SAAgB,0BAA0B,WAA2B;CACnE,OAAO,qBAAqB;AAC9B;;;;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,SAAS;GACT,SAAS,QAAQ;GACjB,GAAI,QAAQ,aAAa,EAAE,YAAY,QAAQ,WAAW,IAAI,CAAC;GAC/D;EACF;CACF,UAAU;EACR,cAAc,OAAO;CACvB;AACF"}
|
|
@@ -28,7 +28,7 @@ export interface HeadRepository {
|
|
|
28
28
|
}
|
|
29
29
|
/** Current head of every repository's pinned ref, keyed by slug. Throws when any lookup fails. */
|
|
30
30
|
export declare function resolveCurrentHeads(github: {
|
|
31
|
-
versionControl: Pick<VersionControl, 'getRepositoryAccess'>;
|
|
31
|
+
versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>;
|
|
32
32
|
}, input: {
|
|
33
33
|
orgId: string;
|
|
34
34
|
repositories: HeadRepository[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heads.d.ts","sourceRoot":"","sources":["../../src/environment/heads.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"heads.d.ts","sourceRoot":"","sources":["../../src/environment/heads.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAIzE,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEtD,sHAAsH;AACtH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkBjE;AAED,8GAA8G;AAC9G,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,SAAS,CAOlG;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,gBAAgB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAM/G;AAED,gIAAgI;AAChI,wBAAgB,YAAY,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAMlG;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,oFAAoF;IACpF,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,kGAAkG;AAClG,wBAAsB,mBAAmB,CACvC,MAAM,EAAE;IAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,qBAAqB,GAAG,uBAAuB,CAAC,CAAA;CAAE,EACjG,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,cAAc,EAAE,CAAA;CAAE,GACvD,OAAO,CAAC,gBAAgB,CAAC,CAoB3B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getBranchHead } from "../integrations/github/commits.js";
|
|
2
|
+
import { groupedRepositoryAccess } from "./repository-access.js";
|
|
2
3
|
// src/environment/heads.ts
|
|
3
4
|
/** `owner/repo` from a clone URL in any common spelling, lower-cased, `.git` stripped; undefined when unparseable. */
|
|
4
5
|
function cloneUrlSlug(cloneUrl) {
|
|
@@ -43,8 +44,10 @@ function headsChanged(recorded, current) {
|
|
|
43
44
|
}
|
|
44
45
|
/** Current head of every repository's pinned ref, keyed by slug. Throws when any lookup fails. */
|
|
45
46
|
async function resolveCurrentHeads(github, input) {
|
|
47
|
+
const repositoryAccess = groupedRepositoryAccess(github.versionControl, input.orgId, input.repositories.map((repository) => repository.id));
|
|
48
|
+
const grouped = { versionControl: { getRepositoryAccess: ({ repositoryId }) => repositoryAccess(repositoryId) } };
|
|
46
49
|
const heads = {};
|
|
47
|
-
for (const repository of input.repositories) heads[repository.slug] = await getBranchHead(
|
|
50
|
+
for (const repository of input.repositories) heads[repository.slug] = await getBranchHead(grouped, {
|
|
48
51
|
orgId: input.orgId,
|
|
49
52
|
repository: {
|
|
50
53
|
id: repository.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heads.js","names":[],"sources":["../../src/environment/heads.ts"],"sourcesContent":["/**\n * Which commit each environment repository pins to.\n *\n * The repo templates key `resolveHead` by clone URL; the factory records heads\n * by repository slug. These helpers translate between the two and decide\n * whether a set of current heads differs from the recorded one.\n */\n\nimport type { VersionControl } from '../capabilities/version-control.js';\nimport { getBranchHead } from '../integrations/github/commits.js';\n\nexport type EnvironmentHeads = Record<string, string>;\n\n/** `owner/repo` from a clone URL in any common spelling, lower-cased, `.git` stripped; undefined when unparseable. */\nexport function cloneUrlSlug(cloneUrl: string): string | undefined {\n let path: string;\n const scp = /^[^@/]+@[^:/]+:(.+)$/.exec(cloneUrl.trim());\n if (scp) {\n path = scp[1]!;\n } else {\n try {\n path = new URL(cloneUrl.trim()).pathname;\n } catch {\n return undefined;\n }\n }\n const parts = path\n .replace(/\\.git$/i, '')\n .split('/')\n .filter(Boolean);\n if (parts.length < 2) return undefined;\n return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`.toLowerCase();\n}\n\n/** The environment slug a clone URL names, in the environment's own spelling; undefined when none matches. */\nexport function matchEnvironmentSlug(cloneUrl: string, slugs: Iterable<string>): string | undefined {\n const wanted = cloneUrlSlug(cloneUrl);\n if (!wanted) return undefined;\n for (const slug of slugs) {\n if (slug.toLowerCase() === wanted) return slug;\n }\n return undefined;\n}\n\n/**\n * A `resolveHead` that answers from recorded heads only: the template pins to\n * what the last build used, so its identity moves when a build does. A URL\n * outside the recorded set resolves undefined and the template falls back to\n * its own lookup for that repository.\n */\nexport function recordedHeadResolver(heads: EnvironmentHeads): (cloneUrl: string) => Promise<string | undefined> {\n const slugs = Object.keys(heads);\n return async cloneUrl => {\n const slug = matchEnvironmentSlug(cloneUrl, slugs);\n return slug ? heads[slug] : undefined;\n };\n}\n\n/** True when any repository's current head differs from the recorded one, or either side names a repository the other lacks. */\nexport function headsChanged(recorded: EnvironmentHeads | null, current: EnvironmentHeads): boolean {\n if (!recorded) return true;\n const recordedKeys = Object.keys(recorded);\n const currentKeys = Object.keys(current);\n if (recordedKeys.length !== currentKeys.length) return true;\n return currentKeys.some(slug => recorded[slug] !== current[slug]);\n}\n\nexport interface HeadRepository {\n id: string;\n slug: string;\n /** The ref the environment pins: the link's branch, else the repository default. */\n branch: string;\n}\n\n/** Current head of every repository's pinned ref, keyed by slug. Throws when any lookup fails. */\nexport async function resolveCurrentHeads(\n github: { versionControl: Pick<VersionControl, 'getRepositoryAccess'> },\n input: { orgId: string; repositories: HeadRepository[] },\n): Promise<EnvironmentHeads> {\n const heads: EnvironmentHeads = {};\n for (const repository of input.repositories) {\n heads[repository.slug] = await getBranchHead(
|
|
1
|
+
{"version":3,"file":"heads.js","names":[],"sources":["../../src/environment/heads.ts"],"sourcesContent":["/**\n * Which commit each environment repository pins to.\n *\n * The repo templates key `resolveHead` by clone URL; the factory records heads\n * by repository slug. These helpers translate between the two and decide\n * whether a set of current heads differs from the recorded one.\n */\n\nimport type { VersionControl } from '../capabilities/version-control.js';\nimport { getBranchHead } from '../integrations/github/commits.js';\nimport { groupedRepositoryAccess } from './repository-access.js';\n\nexport type EnvironmentHeads = Record<string, string>;\n\n/** `owner/repo` from a clone URL in any common spelling, lower-cased, `.git` stripped; undefined when unparseable. */\nexport function cloneUrlSlug(cloneUrl: string): string | undefined {\n let path: string;\n const scp = /^[^@/]+@[^:/]+:(.+)$/.exec(cloneUrl.trim());\n if (scp) {\n path = scp[1]!;\n } else {\n try {\n path = new URL(cloneUrl.trim()).pathname;\n } catch {\n return undefined;\n }\n }\n const parts = path\n .replace(/\\.git$/i, '')\n .split('/')\n .filter(Boolean);\n if (parts.length < 2) return undefined;\n return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`.toLowerCase();\n}\n\n/** The environment slug a clone URL names, in the environment's own spelling; undefined when none matches. */\nexport function matchEnvironmentSlug(cloneUrl: string, slugs: Iterable<string>): string | undefined {\n const wanted = cloneUrlSlug(cloneUrl);\n if (!wanted) return undefined;\n for (const slug of slugs) {\n if (slug.toLowerCase() === wanted) return slug;\n }\n return undefined;\n}\n\n/**\n * A `resolveHead` that answers from recorded heads only: the template pins to\n * what the last build used, so its identity moves when a build does. A URL\n * outside the recorded set resolves undefined and the template falls back to\n * its own lookup for that repository.\n */\nexport function recordedHeadResolver(heads: EnvironmentHeads): (cloneUrl: string) => Promise<string | undefined> {\n const slugs = Object.keys(heads);\n return async cloneUrl => {\n const slug = matchEnvironmentSlug(cloneUrl, slugs);\n return slug ? heads[slug] : undefined;\n };\n}\n\n/** True when any repository's current head differs from the recorded one, or either side names a repository the other lacks. */\nexport function headsChanged(recorded: EnvironmentHeads | null, current: EnvironmentHeads): boolean {\n if (!recorded) return true;\n const recordedKeys = Object.keys(recorded);\n const currentKeys = Object.keys(current);\n if (recordedKeys.length !== currentKeys.length) return true;\n return currentKeys.some(slug => recorded[slug] !== current[slug]);\n}\n\nexport interface HeadRepository {\n id: string;\n slug: string;\n /** The ref the environment pins: the link's branch, else the repository default. */\n branch: string;\n}\n\n/** Current head of every repository's pinned ref, keyed by slug. Throws when any lookup fails. */\nexport async function resolveCurrentHeads(\n github: { versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'> },\n input: { orgId: string; repositories: HeadRepository[] },\n): Promise<EnvironmentHeads> {\n const repositoryAccess = groupedRepositoryAccess(\n github.versionControl,\n input.orgId,\n input.repositories.map(repository => repository.id),\n );\n const grouped = {\n versionControl: {\n getRepositoryAccess: ({ repositoryId }: { repositoryId: string }) => repositoryAccess(repositoryId),\n },\n };\n const heads: EnvironmentHeads = {};\n for (const repository of input.repositories) {\n heads[repository.slug] = await getBranchHead(grouped, {\n orgId: input.orgId,\n repository: { id: repository.id, slug: repository.slug },\n branch: repository.branch,\n });\n }\n return heads;\n}\n"],"mappings":";;;;AAeA,SAAgB,aAAa,UAAsC;CACjE,IAAI;CACJ,MAAM,MAAM,uBAAuB,KAAK,S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AC7B,MAAM,WAAW,QAAQ,MAAM,cAAc,SAAS;EACpD,OAAO,MAAM;EACb,YAAY;GAAE,IAAI,WAAW;GAAI,MAAM,WAAW;EAAK;EACvD,QAAQ,WAAW;CACrB,CAAC;CAEH,OAAO;AACT"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RepositoryAccess, VersionControl } from '../capabilities/version-control.js';
|
|
2
|
+
/**
|
|
3
|
+
* Access to each of an environment's repositories, minted a group at a time.
|
|
4
|
+
* Asking for one repository asks for its group of up to ten, so a provider
|
|
5
|
+
* that can grant a group mints one token for it and serves every repository in
|
|
6
|
+
* it from that token, instead of minting one per repository (eleven
|
|
7
|
+
* repositories: two mints, not eleven). The group token stays with these
|
|
8
|
+
* callers: a plain `getRepositoryAccess` elsewhere still gets a token for its
|
|
9
|
+
* own repository only. A group the provider can't grant falls back to the
|
|
10
|
+
* repository's own token.
|
|
11
|
+
*/
|
|
12
|
+
export declare function groupedRepositoryAccess(versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>, orgId: string, repositoryIds: readonly string[], now?: () => number): (repositoryId: string) => Promise<RepositoryAccess>;
|
|
13
|
+
//# sourceMappingURL=repository-access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository-access.d.ts","sourceRoot":"","sources":["../../src/environment/repository-access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,gBAAgB,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAa/G;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,qBAAqB,GAAG,uBAAuB,CAAC,EACrF,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,GAAG,GAAE,MAAM,MAAiB,GAC3B,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CA+BrD"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/environment/repository-access.ts
|
|
2
|
+
/** The most repositories one Platform GitHub token can name. */
|
|
3
|
+
const REPOSITORIES_PER_TOKEN = 10;
|
|
4
|
+
/**
|
|
5
|
+
* How long a group the provider refused or failed to mint is skipped. A failed
|
|
6
|
+
* group mint is often a rate limit, so retrying it for every repository in the
|
|
7
|
+
* group would add requests exactly when there is no budget for them.
|
|
8
|
+
*/
|
|
9
|
+
const GROUP_RETRY_AFTER_MS = 6e4;
|
|
10
|
+
/**
|
|
11
|
+
* Access to each of an environment's repositories, minted a group at a time.
|
|
12
|
+
* Asking for one repository asks for its group of up to ten, so a provider
|
|
13
|
+
* that can grant a group mints one token for it and serves every repository in
|
|
14
|
+
* it from that token, instead of minting one per repository (eleven
|
|
15
|
+
* repositories: two mints, not eleven). The group token stays with these
|
|
16
|
+
* callers: a plain `getRepositoryAccess` elsewhere still gets a token for its
|
|
17
|
+
* own repository only. A group the provider can't grant falls back to the
|
|
18
|
+
* repository's own token.
|
|
19
|
+
*/
|
|
20
|
+
function groupedRepositoryAccess(versionControl, orgId, repositoryIds, now = Date.now) {
|
|
21
|
+
const ids = [...new Set(repositoryIds)];
|
|
22
|
+
const groups = [];
|
|
23
|
+
for (let i = 0; i < ids.length; i += REPOSITORIES_PER_TOKEN) groups.push(ids.slice(i, i + REPOSITORIES_PER_TOKEN));
|
|
24
|
+
const skipUntil = /* @__PURE__ */ new Map();
|
|
25
|
+
const pending = /* @__PURE__ */ new Map();
|
|
26
|
+
const groupAccess = (group, getRepositoriesAccess) => {
|
|
27
|
+
let request = pending.get(group);
|
|
28
|
+
if (!request) {
|
|
29
|
+
request = getRepositoriesAccess({
|
|
30
|
+
orgId,
|
|
31
|
+
repositoryIds: group
|
|
32
|
+
}).catch(() => void 0).then((access) => {
|
|
33
|
+
if (!access) skipUntil.set(group, now() + GROUP_RETRY_AFTER_MS);
|
|
34
|
+
return access;
|
|
35
|
+
}).finally(() => pending.delete(group));
|
|
36
|
+
pending.set(group, request);
|
|
37
|
+
}
|
|
38
|
+
return request;
|
|
39
|
+
};
|
|
40
|
+
return async (repositoryId) => {
|
|
41
|
+
const group = groups.find((candidate) => candidate.includes(repositoryId));
|
|
42
|
+
const getRepositoriesAccess = versionControl.getRepositoriesAccess?.bind(versionControl);
|
|
43
|
+
if (group && group.length > 1 && getRepositoriesAccess && (skipUntil.get(group) ?? 0) <= now()) {
|
|
44
|
+
const own = (await groupAccess(group, getRepositoriesAccess))?.repositories?.[repositoryId];
|
|
45
|
+
if (own) return own;
|
|
46
|
+
}
|
|
47
|
+
return versionControl.getRepositoryAccess({
|
|
48
|
+
orgId,
|
|
49
|
+
repositoryId
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { groupedRepositoryAccess };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=repository-access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository-access.js","names":[],"sources":["../../src/environment/repository-access.ts"],"sourcesContent":["import type { RepositoriesAccess, RepositoryAccess, VersionControl } from '../capabilities/version-control.js';\n\ntype GetRepositoriesAccess = NonNullable<VersionControl['getRepositoriesAccess']>;\n\n/** The most repositories one Platform GitHub token can name. */\nconst REPOSITORIES_PER_TOKEN = 10;\n/**\n * How long a group the provider refused or failed to mint is skipped. A failed\n * group mint is often a rate limit, so retrying it for every repository in the\n * group would add requests exactly when there is no budget for them.\n */\nconst GROUP_RETRY_AFTER_MS = 60_000;\n\n/**\n * Access to each of an environment's repositories, minted a group at a time.\n * Asking for one repository asks for its group of up to ten, so a provider\n * that can grant a group mints one token for it and serves every repository in\n * it from that token, instead of minting one per repository (eleven\n * repositories: two mints, not eleven). The group token stays with these\n * callers: a plain `getRepositoryAccess` elsewhere still gets a token for its\n * own repository only. A group the provider can't grant falls back to the\n * repository's own token.\n */\nexport function groupedRepositoryAccess(\n versionControl: Pick<VersionControl, 'getRepositoryAccess' | 'getRepositoriesAccess'>,\n orgId: string,\n repositoryIds: readonly string[],\n now: () => number = Date.now,\n): (repositoryId: string) => Promise<RepositoryAccess> {\n const ids = [...new Set(repositoryIds)];\n const groups: string[][] = [];\n for (let i = 0; i < ids.length; i += REPOSITORIES_PER_TOKEN) groups.push(ids.slice(i, i + REPOSITORIES_PER_TOKEN));\n const skipUntil = new Map<string[], number>();\n const pending = new Map<string[], Promise<RepositoriesAccess | undefined>>();\n const groupAccess = (group: string[], getRepositoriesAccess: GetRepositoriesAccess) => {\n let request = pending.get(group);\n if (!request) {\n // Best-effort: the repository's own token still works without it.\n request = getRepositoriesAccess({ orgId, repositoryIds: group })\n .catch(() => undefined)\n .then(access => {\n if (!access) skipUntil.set(group, now() + GROUP_RETRY_AFTER_MS);\n return access;\n })\n .finally(() => pending.delete(group));\n pending.set(group, request);\n }\n return request;\n };\n return async repositoryId => {\n const group = groups.find(candidate => candidate.includes(repositoryId));\n const getRepositoriesAccess = versionControl.getRepositoriesAccess?.bind(versionControl);\n if (group && group.length > 1 && getRepositoriesAccess && (skipUntil.get(group) ?? 0) <= now()) {\n // Parallel callers share one group request.\n const own = (await groupAccess(group, getRepositoriesAccess))?.repositories?.[repositoryId];\n if (own) return own;\n }\n return versionControl.getRepositoryAccess({ orgId, repositoryId });\n };\n}\n"],"mappings":";;AAKA,MAAM,yBAAyB;;;;;;AAM/B,MAAM,uBAAuB;;;;;;;;;;;AAY7B,SAAgB,wBACd,gBACA,OACA,eACA,MAAoB,KAAK,KAC4B;CACrD,MAAM,MAAM,CAAC,GAAG,IAAI,IAAI,aAAa,CAAC;CACtC,MAAM,SAAqB,CAAC;CAC5B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK,wBAAwB,OAAO,KAAK,IAAI,MAAM,GAAG,IAAI,sBAAsB,CAAC;CACjH,MAAM,4BAAY,IAAI,IAAsB;CAC5C,MAAM,0BAAU,IAAI,IAAuD;CAC3E,MAAM,eAAe,OAAiB,0BAAiD;EACrF,IAAI,UAAU,QA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