@mastra/factory 0.27.0 → 0.28.0-alpha.1
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 +215 -41
- package/dist/boards/board-events.d.ts +34 -0
- package/dist/boards/board-events.d.ts.map +1 -0
- package/dist/boards/board-events.js +50 -0
- package/dist/boards/board-events.js.map +1 -0
- package/dist/boards/board-writes.d.ts +86 -0
- package/dist/boards/board-writes.d.ts.map +1 -0
- package/dist/boards/board-writes.js +252 -0
- package/dist/boards/board-writes.js.map +1 -0
- package/dist/boards/define-board.d.ts +16 -5
- package/dist/boards/define-board.d.ts.map +1 -1
- package/dist/boards/define-board.js +30 -8
- package/dist/boards/define-board.js.map +1 -1
- package/dist/boards/index.js +1 -1
- package/dist/boards/intake-routing.d.ts +30 -6
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js +43 -5
- 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 +8 -4
- package/dist/boards/legacy-plan-role.js.map +1 -1
- package/dist/boards/phase-automation.d.ts.map +1 -1
- package/dist/boards/phase-automation.js +7 -2
- package/dist/boards/phase-automation.js.map +1 -1
- package/dist/boards/project-boards.d.ts +18 -7
- package/dist/boards/project-boards.d.ts.map +1 -1
- package/dist/boards/project-boards.js +79 -15
- package/dist/boards/project-boards.js.map +1 -1
- package/dist/boards/stored-board.d.ts +59 -1
- package/dist/boards/stored-board.d.ts.map +1 -1
- package/dist/boards/stored-board.js +219 -7
- package/dist/boards/stored-board.js.map +1 -1
- package/dist/boards/work.js +1 -1
- package/dist/dispatch-wake.d.ts +13 -0
- package/dist/dispatch-wake.d.ts.map +1 -0
- package/dist/dispatch-wake.js +30 -0
- package/dist/dispatch-wake.js.map +1 -0
- package/dist/environment/build-runner.d.ts +1 -1
- package/dist/environment/build-runner.d.ts.map +1 -1
- package/dist/environment/build-runner.js +2 -2
- package/dist/environment/build-workflow.d.ts +1 -1
- package/dist/environment/build-workflow.d.ts.map +1 -1
- package/dist/environment/build-workflow.js +1 -1
- package/dist/environment/build.js +1 -1
- package/dist/factory.d.ts +63 -9
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +237 -59
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -9
- package/dist/integrations/base.d.ts +6 -0
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/channel-thread-announcements.d.ts +5 -0
- package/dist/integrations/channel-thread-announcements.d.ts.map +1 -1
- package/dist/integrations/channel-thread-announcements.js +24 -2
- package/dist/integrations/channel-thread-announcements.js.map +1 -1
- package/dist/integrations/github/acceptance-labels.d.ts +4 -0
- package/dist/integrations/github/acceptance-labels.d.ts.map +1 -1
- package/dist/integrations/github/acceptance-labels.js +1 -1
- package/dist/integrations/github/acceptance-labels.js.map +1 -1
- package/dist/integrations/github/default-rules.d.ts +2 -9
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +7 -6
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/integration.js +2 -2
- package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/github/issue-reconciler.js +17 -1
- package/dist/integrations/github/issue-reconciler.js.map +1 -1
- package/dist/integrations/github/review-status-comment.d.ts +61 -0
- package/dist/integrations/github/review-status-comment.d.ts.map +1 -0
- package/dist/integrations/github/review-status-comment.js +217 -0
- package/dist/integrations/github/review-status-comment.js.map +1 -0
- package/dist/integrations/github/review-status-reporter.d.ts +42 -0
- package/dist/integrations/github/review-status-reporter.d.ts.map +1 -0
- package/dist/integrations/github/review-status-reporter.js +100 -0
- package/dist/integrations/github/review-status-reporter.js.map +1 -0
- package/dist/integrations/github/review-status.d.ts +28 -0
- package/dist/integrations/github/review-status.d.ts.map +1 -0
- package/dist/integrations/github/review-status.js +95 -0
- package/dist/integrations/github/review-status.js.map +1 -0
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +19 -21
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +13 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +80 -9
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.js +1 -1
- package/dist/integrations/github/session-subscriptions.js +3 -3
- package/dist/integrations/github/webhook.js +2 -2
- package/dist/integrations/gitlab/default-rules.d.ts +24 -9
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/default-rules.js +4 -4
- package/dist/integrations/gitlab/default-rules.js.map +1 -1
- package/dist/integrations/gitlab/integration.js +2 -2
- package/dist/integrations/gitlab/issue-reconciler.js +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.js +2 -2
- package/dist/integrations/gitlab/routes.d.ts.map +1 -1
- package/dist/integrations/gitlab/routes.js +2 -4
- package/dist/integrations/gitlab/routes.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts +16 -0
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +71 -6
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/gitlab/session-subscriptions.js +1 -1
- package/dist/integrations/gitlab/webhook-dispatch.js +1 -1
- package/dist/integrations/incidentio/default-rules.d.ts +1 -9
- package/dist/integrations/incidentio/default-rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/default-rules.js +3 -4
- package/dist/integrations/incidentio/default-rules.js.map +1 -1
- package/dist/integrations/incidentio/integration.js +3 -3
- package/dist/integrations/incidentio/routes.d.ts.map +1 -1
- package/dist/integrations/incidentio/routes.js +1 -4
- package/dist/integrations/incidentio/routes.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts +7 -0
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +37 -5
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/jira/default-rules.d.ts +1 -9
- package/dist/integrations/jira/default-rules.d.ts.map +1 -1
- package/dist/integrations/jira/default-rules.js +3 -4
- package/dist/integrations/jira/default-rules.js.map +1 -1
- package/dist/integrations/jira/integration.js +2 -2
- package/dist/integrations/jira/routes.d.ts.map +1 -1
- package/dist/integrations/jira/routes.js +2 -5
- package/dist/integrations/jira/routes.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts +7 -0
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +37 -5
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/default-rules.d.ts +1 -9
- package/dist/integrations/linear/default-rules.d.ts.map +1 -1
- package/dist/integrations/linear/default-rules.js +3 -4
- package/dist/integrations/linear/default-rules.js.map +1 -1
- package/dist/integrations/linear/integration.js +2 -2
- package/dist/integrations/linear/routes.d.ts +21 -1
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +21 -6
- package/dist/integrations/linear/routes.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts +7 -0
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +37 -5
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/connect/routes.d.ts +7 -1
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
- package/dist/integrations/platform/connect/routes.js +42 -5
- package/dist/integrations/platform/connect/routes.js.map +1 -1
- package/dist/integrations/platform/connect/session-tools.d.ts +7 -0
- package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -0
- package/dist/integrations/platform/connect/session-tools.js +30 -0
- package/dist/integrations/platform/connect/session-tools.js.map +1 -0
- package/dist/integrations/platform/github/event-worker.js +1 -1
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +9 -8
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/gitlab/event-worker.js +1 -1
- package/dist/integrations/platform/gitlab/integration.js +2 -2
- package/dist/integrations/platform/incidentio/integration.js +5 -5
- package/dist/integrations/platform/jira/agent-tools.js +1 -1
- package/dist/integrations/platform/jira/integration.js +2 -2
- package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
- package/dist/integrations/platform/jira/routes.js +2 -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 +9 -0
- package/dist/integrations/platform/linear/event-worker.js.map +1 -1
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
- package/dist/integrations/platform/linear/integration.js +150 -48
- package/dist/integrations/platform/linear/integration.js.map +1 -1
- package/dist/integrations/slack/channel-reply-processor.d.ts +2 -0
- package/dist/integrations/slack/channel-reply-processor.d.ts.map +1 -1
- package/dist/integrations/slack/channel-reply-processor.js +6 -1
- package/dist/integrations/slack/channel-reply-processor.js.map +1 -1
- package/dist/integrations/slack/chat-tools.d.ts +16 -0
- package/dist/integrations/slack/chat-tools.d.ts.map +1 -0
- package/dist/integrations/slack/chat-tools.js +215 -0
- package/dist/integrations/slack/chat-tools.js.map +1 -0
- package/dist/integrations/slack/connect-route.d.ts.map +1 -1
- package/dist/integrations/slack/connect-route.js +1 -1
- package/dist/integrations/slack/connect-route.js.map +1 -1
- package/dist/integrations/slack/integration.d.ts +19 -3
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +27 -8
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/slack/run-error-card.js +1 -1
- package/dist/integrations/slack/share-file-tool.d.ts +8 -0
- package/dist/integrations/slack/share-file-tool.d.ts.map +1 -1
- package/dist/integrations/slack/share-file-tool.js +13 -4
- package/dist/integrations/slack/share-file-tool.js.map +1 -1
- package/dist/integrations/slack/slack.d.ts +12 -10
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +113 -46
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/integrations/slack/tool-settings.d.ts +26 -0
- package/dist/integrations/slack/tool-settings.d.ts.map +1 -0
- package/dist/integrations/slack/tool-settings.js +35 -0
- package/dist/integrations/slack/tool-settings.js.map +1 -0
- package/dist/integrations/slack/voice-clips.d.ts +32 -0
- package/dist/integrations/slack/voice-clips.d.ts.map +1 -0
- package/dist/integrations/slack/voice-clips.js +201 -0
- package/dist/integrations/slack/voice-clips.js.map +1 -0
- package/dist/integrations/workos/integration.d.ts.map +1 -1
- package/dist/integrations/workos/integration.js +1 -3
- package/dist/integrations/workos/integration.js.map +1 -1
- package/dist/mcp/events.js +1 -1
- package/dist/mcp/routes.js +2 -2
- package/dist/packages/_internals/workspace/dist/index.js +1 -1
- package/dist/routes/attention-activity.js +1 -1
- package/dist/routes/attention-providers.js +2 -2
- package/dist/routes/attention.js +2 -2
- package/dist/routes/automation-runs.d.ts.map +1 -1
- package/dist/routes/automation-runs.js +2 -5
- package/dist/routes/automation-runs.js.map +1 -1
- package/dist/routes/boards.d.ts +8 -6
- package/dist/routes/boards.d.ts.map +1 -1
- package/dist/routes/boards.js +73 -143
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +6 -11
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/contracts.d.ts +162 -2
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +98 -33
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/fs.d.ts.map +1 -1
- package/dist/routes/fs.js +2 -5
- package/dist/routes/fs.js.map +1 -1
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js +19 -12
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/intake.d.ts.map +1 -1
- package/dist/routes/intake.js +4 -6
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/knowledge.d.ts.map +1 -1
- package/dist/routes/knowledge.js +1 -4
- package/dist/routes/knowledge.js.map +1 -1
- package/dist/routes/oauth.d.ts.map +1 -1
- package/dist/routes/oauth.js +1 -4
- package/dist/routes/oauth.js.map +1 -1
- package/dist/routes/projects.d.ts +3 -0
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +42 -28
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/provider-credentials.d.ts.map +1 -1
- package/dist/routes/provider-credentials.js +6 -0
- package/dist/routes/provider-credentials.js.map +1 -1
- package/dist/routes/route.d.ts +2 -0
- package/dist/routes/route.d.ts.map +1 -1
- package/dist/routes/route.js +5 -1
- package/dist/routes/route.js.map +1 -1
- package/dist/routes/skills.d.ts.map +1 -1
- package/dist/routes/skills.js +2 -5
- package/dist/routes/skills.js.map +1 -1
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +3 -5
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/source-control-settings.d.ts.map +1 -1
- package/dist/routes/source-control-settings.js +3 -2
- package/dist/routes/source-control-settings.js.map +1 -1
- package/dist/routes/surface.d.ts +3 -1
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +27 -17
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/telemetry.js +1 -1
- package/dist/routes/voice.d.ts +48 -0
- package/dist/routes/voice.d.ts.map +1 -0
- package/dist/routes/voice.js +248 -0
- package/dist/routes/voice.js.map +1 -0
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +9 -12
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/decision-applicability.js +1 -1
- package/dist/rules/dispatcher.d.ts +42 -0
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +522 -136
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/event-rules.d.ts +40 -1
- package/dist/rules/event-rules.d.ts.map +1 -1
- package/dist/rules/event-rules.js +59 -1
- package/dist/rules/event-rules.js.map +1 -1
- package/dist/rules/index.js +1 -1
- package/dist/rules/processor.d.ts +2 -0
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +5 -4
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/start-coordinator.js +2 -2
- package/dist/rules/terminal-cleanup.js.map +1 -1
- package/dist/rules/tools.js +5 -5
- package/dist/rules/transition-service.d.ts +9 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +9 -7
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +54 -3
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +2 -0
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +57 -2
- package/dist/rules/validation.js.map +1 -1
- package/dist/sandbox/session-retirement.js +2 -2
- package/dist/sandbox/session-sandbox.js +1 -1
- package/dist/session/credential-policy.d.ts +2 -2
- package/dist/session/credential-policy.d.ts.map +1 -1
- package/dist/session/credential-policy.js +4 -4
- package/dist/session/credential-policy.js.map +1 -1
- package/dist/session/default-model-hydration.d.ts +2 -2
- package/dist/session/default-model-hydration.d.ts.map +1 -1
- package/dist/session/default-model-hydration.js +4 -4
- package/dist/session/default-model-hydration.js.map +1 -1
- package/dist/session/factory-session.js +3 -3
- package/dist/session/self-review-gate.js +1 -1
- package/dist/session/session-threads.d.ts +8 -0
- package/dist/session/session-threads.d.ts.map +1 -1
- package/dist/session/session-threads.js +11 -1
- package/dist/session/session-threads.js.map +1 -1
- package/dist/session/source-control-tools.js +3 -3
- package/dist/skills/catalog.js +1 -1
- package/dist/storage/domains/audit/actions.d.ts +1 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +2 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/audit/domain.d.ts.map +1 -1
- package/dist/storage/domains/audit/domain.js +2 -4
- package/dist/storage/domains/audit/domain.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +32 -1
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +155 -8
- 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 +13 -1
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/comments/base.js +3 -3
- package/dist/storage/domains/comments/domain.js +3 -3
- package/dist/storage/domains/comments/routes.d.ts.map +1 -1
- package/dist/storage/domains/comments/routes.js +2 -4
- package/dist/storage/domains/comments/routes.js.map +1 -1
- package/dist/storage/domains/memory-settings/base.d.ts +0 -8
- package/dist/storage/domains/memory-settings/base.d.ts.map +1 -1
- package/dist/storage/domains/memory-settings/base.js +1 -11
- package/dist/storage/domains/memory-settings/base.js.map +1 -1
- package/dist/storage/domains/projects/base.d.ts +6 -0
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +9 -1
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +20 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +42 -0
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +5 -1
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +23 -0
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/voice-settings/base.d.ts +31 -0
- package/dist/storage/domains/voice-settings/base.d.ts.map +1 -0
- package/dist/storage/domains/voice-settings/base.js +81 -0
- package/dist/storage/domains/voice-settings/base.js.map +1 -0
- package/dist/storage/domains/work-items/base.d.ts +47 -7
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +251 -115
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +6 -1
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
- package/dist/storage/domains/work-items/cards.js +55 -5
- package/dist/storage/domains/work-items/cards.js.map +1 -1
- package/dist/storage/domains/work-items/claimable-work.d.ts +15 -0
- package/dist/storage/domains/work-items/claimable-work.d.ts.map +1 -0
- package/dist/storage/domains/work-items/claimable-work.js +51 -0
- package/dist/storage/domains/work-items/claimable-work.js.map +1 -0
- package/dist/storage/domains/work-items/work-item-schema.d.ts +2 -0
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.js +24 -1
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
- package/dist/timing.d.ts +1 -0
- package/dist/timing.d.ts.map +1 -1
- package/dist/timing.js +1 -1
- package/dist/timing.js.map +1 -1
- package/dist/tools/index.js +2 -2
- package/dist/tools/messaging-tools.js +1 -1
- package/dist/tools/read-tools.d.ts +2 -2
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +10 -9
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/scope.js +1 -1
- package/dist/tools/session-tools.d.ts +1 -1
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +9 -9
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/sessions-state-processor.d.ts +1 -1
- package/dist/tools/sessions-state-processor.d.ts.map +1 -1
- package/dist/tools/sessions-state-processor.js +9 -2
- package/dist/tools/sessions-state-processor.js.map +1 -1
- package/dist/tools/work-item-tools.js +4 -4
- package/dist/voice/rate-limit.d.ts +13 -0
- package/dist/voice/rate-limit.d.ts.map +1 -0
- package/dist/voice/rate-limit.js +36 -0
- package/dist/voice/rate-limit.js.map +1 -0
- package/dist/voice/realtime.d.ts +13 -0
- package/dist/voice/realtime.d.ts.map +1 -0
- package/dist/voice/realtime.js +56 -0
- package/dist/voice/realtime.js.map +1 -0
- package/dist/voice/transcription.d.ts +51 -0
- package/dist/voice/transcription.d.ts.map +1 -0
- package/dist/voice/transcription.js +112 -0
- package/dist/voice/transcription.js.map +1 -0
- package/dist/work-items/create-work-item.js +2 -2
- package/dist/work-items/decision-actions.js +2 -2
- package/dist/work-items/providers/gitlab.js +1 -1
- package/dist/work-items/providers/incidentio.js +1 -1
- package/dist/work-items/providers/index.js +1 -1
- package/dist/work-items/providers/jira.js +1 -1
- package/dist/work-items/providers/linear.js +1 -1
- package/dist/work-items/split-backfill.d.ts +13 -0
- package/dist/work-items/split-backfill.d.ts.map +1 -0
- package/dist/work-items/split-backfill.js +32 -0
- package/dist/work-items/split-backfill.js.map +1 -0
- package/dist/work-items/split-migration.d.ts +39 -2
- package/dist/work-items/split-migration.d.ts.map +1 -1
- package/dist/work-items/split-migration.js +171 -63
- package/dist/work-items/split-migration.js.map +1 -1
- package/dist/workspace.d.ts +2 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +12 -9
- package/dist/workspace.js.map +1 -1
- package/package.json +10 -9
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { FACTORY_TRIAGE_TYPES, externalSourceForWorkItem } from "../../../rules/types.js";
|
|
2
1
|
import { factoryDispatchFailureMetadata } from "../../../rules/dispatch-errors.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { migrateWorkItemSplit } from "../../../work-items/split-migration.js";
|
|
2
|
+
import { FACTORY_TRIAGE_TYPES, externalSourceForWorkItem } from "../../../rules/types.js";
|
|
3
|
+
import { workItemProviderAdapter } from "../../../work-items/providers/index.js";
|
|
4
|
+
import { copyLegacyRows, migrateWorkItemSplit, readLegacyWatermark, readWorkItemSplitMarker, recordWorkItemSplitComplete } from "../../../work-items/split-migration.js";
|
|
6
5
|
import { WORK_ITEM_ACTIVITY_SCHEMA, WORK_ITEM_COMMENTS_SCHEMA, WORK_ITEM_COMMENT_MENTIONS_SCHEMA } from "../comments/schema.js";
|
|
6
|
+
import { BoardScopes, FACTORY_BOARD_VERSIONS_SCHEMA, bumpBoardVersions, readBoardVersion, trackBoardWrites } from "./board-version.js";
|
|
7
7
|
import { Cards, splitCardRows } from "./cards.js";
|
|
8
|
+
import { LEASE_TABLES, trackClaimableWrites } from "./claimable-work.js";
|
|
8
9
|
import { splitCardMetadata } from "../../../work-items/providers/metadata-keys.js";
|
|
9
|
-
import {
|
|
10
|
+
import { FACTORY_BOARD_ITEMS_SCHEMA, FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA, FACTORY_WORK_ITEMS_SCHEMA, FACTORY_WORK_ITEM_SOURCES_SCHEMA, FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA, FACTORY_WORK_ITEM_SPLIT_STATE_SCHEMA, WORK_ITEMS_SCHEMA, primarySource } from "./work-item-schema.js";
|
|
10
11
|
import { createHash } from "crypto";
|
|
11
12
|
import { FactoryStorageDomain, UniqueViolationError } from "@mastra/core/storage";
|
|
12
13
|
// src/storage/domains/work-items/base.ts
|
|
@@ -289,6 +290,13 @@ function priorState(row) {
|
|
|
289
290
|
};
|
|
290
291
|
}
|
|
291
292
|
var WorkItemSplitModeError = class extends Error {};
|
|
293
|
+
const OPEN_PASS_PAGE_SIZE = 500;
|
|
294
|
+
function logSplit(line) {
|
|
295
|
+
console.info(`[factory] ${line}`);
|
|
296
|
+
}
|
|
297
|
+
function sameWatermark(a, b) {
|
|
298
|
+
return a !== null && a.id === b.id && new Date(a.updatedAt).getTime() === new Date(b.updatedAt).getTime();
|
|
299
|
+
}
|
|
292
300
|
var WorkItemRelationError = class extends Error {
|
|
293
301
|
code = "invalid_work_item_relation";
|
|
294
302
|
};
|
|
@@ -403,13 +411,6 @@ function safeJsonParse(value) {
|
|
|
403
411
|
return;
|
|
404
412
|
}
|
|
405
413
|
}
|
|
406
|
-
function deferredDecisionType(decision) {
|
|
407
|
-
return typeof decision.decision.type === "string" ? decision.decision.type : void 0;
|
|
408
|
-
}
|
|
409
|
-
function ingressWasAccepted(row) {
|
|
410
|
-
if (!row || typeof row.result !== "object" || row.result === null || Array.isArray(row.result)) return false;
|
|
411
|
-
return "status" in row.result && row.result.status === "accepted";
|
|
412
|
-
}
|
|
413
414
|
const FACTORY_GOVERNANCE_SCHEMAS = [
|
|
414
415
|
{
|
|
415
416
|
name: "factory_rule_ingress",
|
|
@@ -824,11 +825,24 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
824
825
|
#listCache = /* @__PURE__ */ new Map();
|
|
825
826
|
#listInFlight = /* @__PURE__ */ new Map();
|
|
826
827
|
#attentionChanged = () => {};
|
|
828
|
+
#claimableWorkListeners = /* @__PURE__ */ new Set();
|
|
827
829
|
#isTerminal = () => false;
|
|
828
830
|
#legacyMode = false;
|
|
831
|
+
/**
|
|
832
|
+
* Legacy cards this replica may still have to copy. While pending, lookups by id or source
|
|
833
|
+
* copy a missed card on demand; `since` limits the passes to rows written after the last
|
|
834
|
+
* finished pass.
|
|
835
|
+
*/
|
|
836
|
+
#split = {
|
|
837
|
+
pending: false,
|
|
838
|
+
since: null
|
|
839
|
+
};
|
|
829
840
|
get legacyMode() {
|
|
830
841
|
return this.#legacyMode;
|
|
831
842
|
}
|
|
843
|
+
get legacyBackfillPending() {
|
|
844
|
+
return this.#split.pending;
|
|
845
|
+
}
|
|
832
846
|
constructor() {
|
|
833
847
|
super("work-items");
|
|
834
848
|
}
|
|
@@ -841,10 +855,42 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
841
855
|
this.#attentionChanged = listener;
|
|
842
856
|
}
|
|
843
857
|
/**
|
|
844
|
-
*
|
|
845
|
-
*
|
|
846
|
-
*
|
|
858
|
+
* Fires after any committed write leaves a pending start or deferred decision
|
|
859
|
+
* `pending` or `retry`, so an idle dispatcher can wake instead of polling.
|
|
860
|
+
* Listeners run after the write has committed, so a listener that throws is
|
|
861
|
+
* logged and skipped rather than failing the write or the other listeners.
|
|
862
|
+
* Returns a function that removes the listener.
|
|
847
863
|
*/
|
|
864
|
+
onClaimableWork(listener) {
|
|
865
|
+
this.#claimableWorkListeners.add(listener);
|
|
866
|
+
return () => this.#claimableWorkListeners.delete(listener);
|
|
867
|
+
}
|
|
868
|
+
#claimableWork(scope) {
|
|
869
|
+
for (const listener of this.#claimableWorkListeners) try {
|
|
870
|
+
listener(scope);
|
|
871
|
+
} catch (error) {
|
|
872
|
+
console.error("[factory] claimable-work listener failed", error instanceof Error ? error.message : error);
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* When the next pending start or deferred decision becomes claimable: the earliest
|
|
877
|
+
* `available_at` of a queued row, or `lease_expires_at` of a leased one (a crashed
|
|
878
|
+
* dispatcher's lease is reclaimed once it lapses). `null` when nothing is queued or leased.
|
|
879
|
+
* May be in the past when work is already due.
|
|
880
|
+
*/
|
|
881
|
+
async nextClaimableAt() {
|
|
882
|
+
const earliest = async (table, status, column) => {
|
|
883
|
+
const [row] = await this.#db.findMany(table, { status }, {
|
|
884
|
+
orderBy: [[column, "asc"]],
|
|
885
|
+
limit: 1
|
|
886
|
+
});
|
|
887
|
+
const value = row?.[column];
|
|
888
|
+
return value ? new Date(value).getTime() : void 0;
|
|
889
|
+
};
|
|
890
|
+
const due = (await Promise.all(LEASE_TABLES.flatMap((table) => [earliest(table, { in: ["pending", "retry"] }, "available_at"), earliest(table, "leased", "lease_expires_at")]))).filter((time) => time !== void 0);
|
|
891
|
+
return due.length ? new Date(Math.min(...due)) : null;
|
|
892
|
+
}
|
|
893
|
+
/** Tells the stale-binding sweep which cards sit in a phase their installed board declares terminal. */
|
|
848
894
|
useTerminalPhasePredicate(isTerminal) {
|
|
849
895
|
this.#isTerminal = isTerminal;
|
|
850
896
|
}
|
|
@@ -855,6 +901,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
855
901
|
FACTORY_WORK_ITEMS_SCHEMA,
|
|
856
902
|
FACTORY_WORK_ITEM_SOURCES_SCHEMA,
|
|
857
903
|
FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA,
|
|
904
|
+
FACTORY_WORK_ITEM_SPLIT_STATE_SCHEMA,
|
|
858
905
|
FACTORY_BOARD_ITEMS_SCHEMA,
|
|
859
906
|
FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA,
|
|
860
907
|
FACTORY_BOARD_VERSIONS_SCHEMA,
|
|
@@ -865,12 +912,102 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
865
912
|
FACTORY_WORK_ITEM_SUBSCRIPTIONS_SCHEMA
|
|
866
913
|
]);
|
|
867
914
|
if (this.#legacyMode && await super.ops.findOne(FACTORY_BOARD_ITEMS_SCHEMA.name, {})) throw new WorkItemSplitModeError("MASTRA_FACTORY_WORK_ITEM_SPLIT=dry-run cannot serve a database with migrated board items.");
|
|
868
|
-
|
|
869
|
-
|
|
915
|
+
if (this.#legacyMode) {
|
|
916
|
+
this.#split = {
|
|
917
|
+
pending: false,
|
|
918
|
+
since: null
|
|
919
|
+
};
|
|
920
|
+
await migrateWorkItemSplit(this.storage, {
|
|
921
|
+
dryRun: true,
|
|
922
|
+
ops: super.ops,
|
|
923
|
+
log: logSplit
|
|
924
|
+
});
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
const [marker, newest] = await Promise.all([readWorkItemSplitMarker(super.ops), readLegacyWatermark(super.ops)]);
|
|
928
|
+
const finished = !newest || marker !== null && sameWatermark(marker.watermark, newest);
|
|
929
|
+
this.#split = {
|
|
930
|
+
pending: !finished,
|
|
931
|
+
since: marker?.watermark ?? null
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Copy the legacy cards `isTerminal` rejects, before Factory serves. Terminal cards are left
|
|
936
|
+
* to `backfillLegacyCards`. A no-op once the split finished.
|
|
937
|
+
*/
|
|
938
|
+
async migrateOpenLegacyCards(isTerminal) {
|
|
939
|
+
if (this.#legacyMode || !this.#split.pending) return null;
|
|
940
|
+
return migrateWorkItemSplit(this.storage, {
|
|
870
941
|
ops: super.ops,
|
|
871
|
-
|
|
942
|
+
since: this.#split.since,
|
|
943
|
+
pageSize: OPEN_PASS_PAGE_SIZE,
|
|
944
|
+
include: async (row) => !await isTerminal(toWorkItem(row)),
|
|
945
|
+
label: "boot pass",
|
|
946
|
+
log: logSplit
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Copy every remaining legacy card, then record the newest legacy row seen before the pass
|
|
951
|
+
* began, so later boots skip rows up to it. Skipped cards are logged and count as done: they
|
|
952
|
+
* conflict with newer split state and a rescan would only skip them again.
|
|
953
|
+
*/
|
|
954
|
+
async backfillLegacyCards({ signal } = {}) {
|
|
955
|
+
if (this.#legacyMode || !this.#split.pending) return null;
|
|
956
|
+
const watermark = await readLegacyWatermark(super.ops);
|
|
957
|
+
const report = await migrateWorkItemSplit(this.storage, {
|
|
958
|
+
ops: super.ops,
|
|
959
|
+
since: this.#split.since,
|
|
960
|
+
signal,
|
|
961
|
+
label: "background pass",
|
|
962
|
+
log: logSplit
|
|
963
|
+
});
|
|
964
|
+
if (!report.aborted) {
|
|
965
|
+
await recordWorkItemSplitComplete(super.ops, watermark);
|
|
966
|
+
this.#split = {
|
|
967
|
+
pending: false,
|
|
968
|
+
since: watermark
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
return report;
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Copy the legacy cards filed for these external records, so a lookup that matches on `list()`
|
|
975
|
+
* finds them. A no-op once the split finished.
|
|
976
|
+
*/
|
|
977
|
+
async copyLegacyCards({ orgId, factoryProjectId, sources }) {
|
|
978
|
+
if (this.#legacyMode || !this.#split.pending || !sources.length) return;
|
|
979
|
+
const sourceKeys = new Set(sources.map((source) => externalSourceKey(source)));
|
|
980
|
+
await this.#cards(this.#db, { transaction: false }).findMany({
|
|
981
|
+
org_id: orgId,
|
|
982
|
+
factory_project_id: factoryProjectId,
|
|
983
|
+
source_key: { in: [...sourceKeys] }
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Card row access. While legacy cards remain uncopied, a lookup that misses copies the card:
|
|
988
|
+
* inside the caller's transaction when `ops` is one (a nested transaction would deadlock
|
|
989
|
+
* LibSQL), else in a transaction of its own.
|
|
990
|
+
*/
|
|
991
|
+
#cards(ops, { transaction }) {
|
|
992
|
+
if (this.#legacyMode || !this.#split.pending) return new Cards(ops, this.#legacyMode);
|
|
993
|
+
return new Cards(ops, false, { copy: async (rows) => {
|
|
994
|
+
if (transaction) {
|
|
995
|
+
await copyLegacyRows(ops, rows);
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
try {
|
|
999
|
+
await this.#withTransaction((tx) => copyLegacyRows(tx, rows));
|
|
1000
|
+
} catch (error) {
|
|
1001
|
+
if (!(error instanceof UniqueViolationError)) throw error;
|
|
1002
|
+
}
|
|
1003
|
+
} });
|
|
1004
|
+
}
|
|
1005
|
+
/** Validation reads the split tables only, so a parent still in legacy is copied first. */
|
|
1006
|
+
async #copyLegacyParent(ops, orgId, parentId) {
|
|
1007
|
+
if (parentId && this.#split.pending) await this.#cards(ops, { transaction: true }).findOne({
|
|
1008
|
+
org_id: orgId,
|
|
1009
|
+
id: parentId
|
|
872
1010
|
});
|
|
873
|
-
await this.repairLegacyAttentionState();
|
|
874
1011
|
}
|
|
875
1012
|
/** Refresh source evidence without changing work identity or board concurrency tokens. */
|
|
876
1013
|
async syncWorkItemSource(params) {
|
|
@@ -908,7 +1045,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
908
1045
|
async syncCard({ orgId, id, userId, patch, expectedSourceRevision, fillOnly = false }) {
|
|
909
1046
|
return this.#withTransaction(async (ops) => {
|
|
910
1047
|
let previous = emptyPrior();
|
|
911
|
-
const row = await
|
|
1048
|
+
const row = await this.#cards(ops, { transaction: true }).updateAtomic({
|
|
912
1049
|
org_id: orgId,
|
|
913
1050
|
id
|
|
914
1051
|
}, async (current) => {
|
|
@@ -971,7 +1108,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
971
1108
|
});
|
|
972
1109
|
}
|
|
973
1110
|
async dangerouslyClearAll() {
|
|
974
|
-
await this.#withTransaction((ops) =>
|
|
1111
|
+
await this.#withTransaction((ops) => this.#cards(ops, { transaction: true }).deleteMany({}));
|
|
975
1112
|
await super.ops.deleteMany(FACTORY_WORK_ITEM_SUBSCRIPTIONS_SCHEMA.name, {});
|
|
976
1113
|
await super.ops.deleteMany(FACTORY_BOARD_VERSIONS_SCHEMA.name, {});
|
|
977
1114
|
this.#listCache.clear();
|
|
@@ -981,12 +1118,16 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
981
1118
|
}
|
|
982
1119
|
get ops() {
|
|
983
1120
|
const ops = super.ops;
|
|
984
|
-
return trackBoardWrites(ops, (scope) => bumpBoardVersions(ops, [scope]));
|
|
1121
|
+
return trackClaimableWrites(trackBoardWrites(ops, (scope) => bumpBoardVersions(ops, [scope])), (scope) => this.#claimableWork(scope));
|
|
985
1122
|
}
|
|
986
1123
|
/** `storage.withTransaction`, bumping the board version of every project it wrote once it commits. */
|
|
987
1124
|
async #withTransaction(fn, options) {
|
|
988
1125
|
const changed = new BoardScopes();
|
|
989
|
-
|
|
1126
|
+
let queued = /* @__PURE__ */ new Map();
|
|
1127
|
+
const run = () => {
|
|
1128
|
+
queued = /* @__PURE__ */ new Map();
|
|
1129
|
+
return this.storage.withTransaction((ops) => fn(trackClaimableWrites(trackBoardWrites(ops, changed.add), (scope) => queued.set(`${scope.orgId}\u0000${scope.factoryProjectId}`, scope))), options);
|
|
1130
|
+
};
|
|
990
1131
|
let result;
|
|
991
1132
|
try {
|
|
992
1133
|
result = await run();
|
|
@@ -994,7 +1135,11 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
994
1135
|
if (!(error instanceof UniqueViolationError) || error.collection !== FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA.name) throw error;
|
|
995
1136
|
result = await run();
|
|
996
1137
|
}
|
|
997
|
-
|
|
1138
|
+
try {
|
|
1139
|
+
await bumpBoardVersions(super.ops, changed.values());
|
|
1140
|
+
} finally {
|
|
1141
|
+
for (const scope of queued.values()) this.#claimableWork(scope);
|
|
1142
|
+
}
|
|
998
1143
|
return result;
|
|
999
1144
|
}
|
|
1000
1145
|
async #countRows(collection, where) {
|
|
@@ -1118,7 +1263,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1118
1263
|
return failed ? row : null;
|
|
1119
1264
|
}
|
|
1120
1265
|
async #listWithOps(ops, orgId, factoryProjectId) {
|
|
1121
|
-
return (await
|
|
1266
|
+
return (await this.#cards(ops, { transaction: true }).findMany({
|
|
1122
1267
|
org_id: orgId,
|
|
1123
1268
|
factory_project_id: factoryProjectId
|
|
1124
1269
|
}, { orderBy: [["created_at", "desc"], ["id", "desc"]] })).map(toWorkItem);
|
|
@@ -1189,7 +1334,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1189
1334
|
}
|
|
1190
1335
|
async listByIds({ orgId, factoryProjectId, ids }) {
|
|
1191
1336
|
if (ids.length === 0) return [];
|
|
1192
|
-
return (await
|
|
1337
|
+
return (await this.#cards(this.#db, { transaction: false }).findMany({
|
|
1193
1338
|
org_id: orgId,
|
|
1194
1339
|
factory_project_id: factoryProjectId,
|
|
1195
1340
|
id: { in: [...new Set(ids)] }
|
|
@@ -1201,11 +1346,17 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1201
1346
|
* ponytail: org-wide scan per session delete; JSON-path query if it measures.
|
|
1202
1347
|
*/
|
|
1203
1348
|
async clearSessionReferences({ orgId, sessionId }) {
|
|
1204
|
-
const
|
|
1349
|
+
const rows = await this.#db.findMany(this.#legacyMode ? WORK_ITEMS_SCHEMA.name : FACTORY_BOARD_ITEMS_SCHEMA.name, { org_id: orgId });
|
|
1350
|
+
if (this.#split.pending) {
|
|
1351
|
+
const split = new Set(rows.map((row) => row.id));
|
|
1352
|
+
const legacy = await this.#db.findMany(WORK_ITEMS_SCHEMA.name, { org_id: orgId });
|
|
1353
|
+
rows.push(...legacy.filter((row) => !split.has(row.id)));
|
|
1354
|
+
}
|
|
1355
|
+
const holding = rows.filter((row) => Object.values(row.sessions).some((ref) => ref.sessionId === sessionId));
|
|
1205
1356
|
let cleared = 0;
|
|
1206
1357
|
for (const row of holding) {
|
|
1207
1358
|
let changed = false;
|
|
1208
|
-
await this.#withTransaction((ops) =>
|
|
1359
|
+
await this.#withTransaction((ops) => this.#cards(ops, { transaction: true }).updateAtomic({ id: row.id }, (current) => {
|
|
1209
1360
|
const kept = Object.entries(current.sessions).filter(([, ref]) => ref.sessionId !== sessionId);
|
|
1210
1361
|
if (kept.length === Object.keys(current.sessions).length) return null;
|
|
1211
1362
|
changed = true;
|
|
@@ -1220,7 +1371,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1220
1371
|
return cleared;
|
|
1221
1372
|
}
|
|
1222
1373
|
async getByProjectSource({ orgId, factoryProjectId, source }) {
|
|
1223
|
-
const row = await
|
|
1374
|
+
const row = await this.#cards(this.#db, { transaction: false }).findOne({
|
|
1224
1375
|
org_id: orgId,
|
|
1225
1376
|
factory_project_id: factoryProjectId,
|
|
1226
1377
|
source_key: externalSourceKey(source)
|
|
@@ -1228,7 +1379,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1228
1379
|
return row ? toWorkItem(row) : null;
|
|
1229
1380
|
}
|
|
1230
1381
|
async get({ orgId, id }) {
|
|
1231
|
-
const row = await
|
|
1382
|
+
const row = await this.#cards(this.#db, { transaction: false }).findOne({
|
|
1232
1383
|
org_id: orgId,
|
|
1233
1384
|
id
|
|
1234
1385
|
});
|
|
@@ -1241,7 +1392,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1241
1392
|
* `workspaceId` instead. Ambiguous matches resolve to nothing, not a guess.
|
|
1242
1393
|
*/
|
|
1243
1394
|
async getBySource(source) {
|
|
1244
|
-
const rows = await
|
|
1395
|
+
const rows = await this.#cards(this.#db, { transaction: false }).findMany({ source_key: externalSourceKey(source) });
|
|
1245
1396
|
return rows.length === 1 ? toWorkItem(rows[0]) : null;
|
|
1246
1397
|
}
|
|
1247
1398
|
/**
|
|
@@ -1251,13 +1402,13 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1251
1402
|
* consults this before creating another.
|
|
1252
1403
|
*/
|
|
1253
1404
|
async listBySource({ orgId, source }) {
|
|
1254
|
-
return (await
|
|
1405
|
+
return (await this.#cards(this.#db, { transaction: false }).findMany({
|
|
1255
1406
|
org_id: orgId,
|
|
1256
1407
|
source_key: externalSourceKey(source)
|
|
1257
1408
|
})).map(toWorkItem);
|
|
1258
1409
|
}
|
|
1259
1410
|
async getForProject(orgId, factoryProjectId, id) {
|
|
1260
|
-
const row = await
|
|
1411
|
+
const row = await this.#cards(this.#db, { transaction: false }).findOne({
|
|
1261
1412
|
id,
|
|
1262
1413
|
org_id: orgId,
|
|
1263
1414
|
factory_project_id: factoryProjectId
|
|
@@ -1279,7 +1430,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1279
1430
|
identity: input.ingress.identity
|
|
1280
1431
|
});
|
|
1281
1432
|
if (prior) {
|
|
1282
|
-
const row = await
|
|
1433
|
+
const row = await this.#cards(ops, { transaction: true }).findOne({
|
|
1283
1434
|
id: input.workItemId,
|
|
1284
1435
|
org_id: input.orgId,
|
|
1285
1436
|
factory_project_id: input.factoryProjectId
|
|
@@ -1295,7 +1446,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1295
1446
|
let code = null;
|
|
1296
1447
|
let reason = null;
|
|
1297
1448
|
let result;
|
|
1298
|
-
const updated = await
|
|
1449
|
+
const updated = await this.#cards(ops, { transaction: true }).updateAtomic({
|
|
1299
1450
|
id: input.workItemId,
|
|
1300
1451
|
org_id: input.orgId,
|
|
1301
1452
|
factory_project_id: input.factoryProjectId
|
|
@@ -1440,7 +1591,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1440
1591
|
for (const decision of decisions) {
|
|
1441
1592
|
if (!evaluation || !decision || typeof decision !== "object" || decision.type !== "upsertLinkedWorkItem" || !isWorkItemSource(decision.source) || typeof decision.sourceKey !== "string" || typeof decision.idempotencyKey !== "string") continue;
|
|
1442
1593
|
const materialization = decision;
|
|
1443
|
-
if (await
|
|
1594
|
+
if (await this.#cards(ops, { transaction: true }).findOne({
|
|
1444
1595
|
org_id: input.orgId,
|
|
1445
1596
|
factory_project_id: input.factoryProjectId,
|
|
1446
1597
|
source_key: externalSourceKey(externalSourceForWorkItem(materialization.source, materialization.sourceKey))
|
|
@@ -1466,7 +1617,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1466
1617
|
result
|
|
1467
1618
|
};
|
|
1468
1619
|
}
|
|
1469
|
-
const itemRow = input.workItemId ? await
|
|
1620
|
+
const itemRow = input.workItemId ? await this.#cards(ops, { transaction: true }).findOne({
|
|
1470
1621
|
id: input.workItemId,
|
|
1471
1622
|
org_id: input.orgId,
|
|
1472
1623
|
factory_project_id: input.factoryProjectId
|
|
@@ -1811,6 +1962,30 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1811
1962
|
const row = await this.#completeLease("factory_deferred_decisions", identity, now, "superseded");
|
|
1812
1963
|
return row ? toDeferredDecision(row) : null;
|
|
1813
1964
|
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Hand a leased decision back untouched until `availableAt`: it could not act yet and did
|
|
1967
|
+
* nothing, so the claim is not an attempt and leaves no error behind.
|
|
1968
|
+
*/
|
|
1969
|
+
async postponeDeferredDecision(identity, availableAt, now) {
|
|
1970
|
+
let postponed = false;
|
|
1971
|
+
const row = await this.#db.updateAtomic("factory_deferred_decisions", {
|
|
1972
|
+
id: identity.id,
|
|
1973
|
+
org_id: identity.orgId,
|
|
1974
|
+
factory_project_id: identity.factoryProjectId
|
|
1975
|
+
}, (current) => {
|
|
1976
|
+
if (current.status !== "leased" || current.lease_owner !== identity.ownerId) return null;
|
|
1977
|
+
postponed = true;
|
|
1978
|
+
return {
|
|
1979
|
+
status: "pending",
|
|
1980
|
+
attempts: Math.max(0, Number(current.attempts) - 1),
|
|
1981
|
+
available_at: availableAt,
|
|
1982
|
+
lease_owner: null,
|
|
1983
|
+
lease_expires_at: null,
|
|
1984
|
+
updated_at: now
|
|
1985
|
+
};
|
|
1986
|
+
});
|
|
1987
|
+
return postponed && row ? toDeferredDecision(row) : null;
|
|
1988
|
+
}
|
|
1814
1989
|
async failDeferredDecision(input) {
|
|
1815
1990
|
const row = await this.#failLease("factory_deferred_decisions", input);
|
|
1816
1991
|
if (!row) return null;
|
|
@@ -1869,7 +2044,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1869
2044
|
if (!settled || !row) return null;
|
|
1870
2045
|
const record = toDeferredDecision(row);
|
|
1871
2046
|
await ops.deleteMany("factory_attention_receipts", proposalReceiptFilter(orgId, factoryProjectId, decisionId));
|
|
1872
|
-
if (record.workItemId) await
|
|
2047
|
+
if (record.workItemId) await this.#cards(ops, { transaction: true }).updateAtomic({
|
|
1873
2048
|
org_id: orgId,
|
|
1874
2049
|
id: record.workItemId
|
|
1875
2050
|
}, (current) => current.autonomy_armed_at ? null : { autonomy_armed_at: now });
|
|
@@ -1913,11 +2088,10 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1913
2088
|
status: "superseded",
|
|
1914
2089
|
updated_at: input.supersededAt,
|
|
1915
2090
|
completed_at: input.supersededAt
|
|
1916
|
-
}) : await this.#
|
|
2091
|
+
}) : await this.#supersedeFailedDecision({
|
|
1917
2092
|
orgId: input.orgId,
|
|
1918
2093
|
factoryProjectId: input.factoryProjectId,
|
|
1919
2094
|
decisionId: decision.id,
|
|
1920
|
-
status: "superseded",
|
|
1921
2095
|
now: input.supersededAt
|
|
1922
2096
|
});
|
|
1923
2097
|
if (record) superseded.push(record);
|
|
@@ -1943,7 +2117,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1943
2117
|
if (settled) this.#attentionChanged(settled);
|
|
1944
2118
|
return settled;
|
|
1945
2119
|
}
|
|
1946
|
-
async #
|
|
2120
|
+
async #supersedeFailedDecision({ orgId, factoryProjectId, decisionId, now }) {
|
|
1947
2121
|
const resolved = await this.#withTransaction(async (ops) => {
|
|
1948
2122
|
let resolved = false;
|
|
1949
2123
|
const row = await ops.updateAtomic("factory_deferred_decisions", {
|
|
@@ -1954,7 +2128,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1954
2128
|
if (current.status !== "failed") return null;
|
|
1955
2129
|
resolved = true;
|
|
1956
2130
|
return {
|
|
1957
|
-
status,
|
|
2131
|
+
status: "superseded",
|
|
1958
2132
|
updated_at: now
|
|
1959
2133
|
};
|
|
1960
2134
|
});
|
|
@@ -1981,7 +2155,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
1981
2155
|
* left alone. Returns the cards moved; a second run finds none.
|
|
1982
2156
|
*/
|
|
1983
2157
|
async returnHeldTriageCards() {
|
|
1984
|
-
const held = (await
|
|
2158
|
+
const held = (await this.#cards(this.#db, { transaction: false }).findMany({
|
|
1985
2159
|
board: { in: ["work", null] },
|
|
1986
2160
|
triage_type: { in: FACTORY_TRIAGE_TYPES.filter((type) => type !== "bug") },
|
|
1987
2161
|
accepted_at: null
|
|
@@ -2023,56 +2197,6 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2023
2197
|
}
|
|
2024
2198
|
return moved;
|
|
2025
2199
|
}
|
|
2026
|
-
async repairLegacyAttentionState() {
|
|
2027
|
-
let cursor;
|
|
2028
|
-
const inspectedWorkItems = /* @__PURE__ */ new Set();
|
|
2029
|
-
while (true) {
|
|
2030
|
-
const rows = await this.#db.findMany("factory_deferred_decisions", { status: { in: ["failed", "proposed"] } }, {
|
|
2031
|
-
orderBy: [["created_at", "asc"], ["id", "asc"]],
|
|
2032
|
-
limit: 201,
|
|
2033
|
-
...cursor ? { cursor } : {}
|
|
2034
|
-
});
|
|
2035
|
-
const page = rows.slice(0, ATTENTION_RECEIPT_QUERY_BATCH_SIZE);
|
|
2036
|
-
for (const row of page) {
|
|
2037
|
-
const decision = toDeferredDecision(row);
|
|
2038
|
-
if (decision.status === "failed" && decision.failureOccurrence === 0 && deferredDecisionType(decision) === "transition") {
|
|
2039
|
-
if (ingressWasAccepted(await this.#db.findOne("factory_rule_ingress", {
|
|
2040
|
-
org_id: decision.orgId,
|
|
2041
|
-
factory_project_id: decision.factoryProjectId,
|
|
2042
|
-
identity: `decision:${decision.idempotencyKey}`
|
|
2043
|
-
}))) {
|
|
2044
|
-
await this.#resolveFailedDecision({
|
|
2045
|
-
orgId: decision.orgId,
|
|
2046
|
-
factoryProjectId: decision.factoryProjectId,
|
|
2047
|
-
decisionId: decision.id,
|
|
2048
|
-
status: "succeeded",
|
|
2049
|
-
now: /* @__PURE__ */ new Date()
|
|
2050
|
-
});
|
|
2051
|
-
continue;
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
|
-
if (!decision.workItemId) continue;
|
|
2055
|
-
const itemKey = `${decision.orgId}\0${decision.factoryProjectId}\0${decision.workItemId}`;
|
|
2056
|
-
if (inspectedWorkItems.has(itemKey)) continue;
|
|
2057
|
-
inspectedWorkItems.add(itemKey);
|
|
2058
|
-
const item = await this.get({
|
|
2059
|
-
orgId: decision.orgId,
|
|
2060
|
-
id: decision.workItemId
|
|
2061
|
-
});
|
|
2062
|
-
if (!item || !this.#isTerminal(item)) continue;
|
|
2063
|
-
await this.supersedeDecisionsForWorkItem({
|
|
2064
|
-
orgId: decision.orgId,
|
|
2065
|
-
factoryProjectId: decision.factoryProjectId,
|
|
2066
|
-
workItemId: decision.workItemId,
|
|
2067
|
-
supersededAt: /* @__PURE__ */ new Date()
|
|
2068
|
-
});
|
|
2069
|
-
}
|
|
2070
|
-
const last = page.at(-1);
|
|
2071
|
-
if (rows.length <= ATTENTION_RECEIPT_QUERY_BATCH_SIZE || !last) return;
|
|
2072
|
-
if (!(last.created_at instanceof Date)) throw new Error("Deferred decision created_at is not a timestamp.");
|
|
2073
|
-
cursor = { values: [last.created_at, last.id] };
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
2200
|
/** Requeue the same idempotent terminal effect; non-failed or non-retryable decisions are never rerun. */
|
|
2077
2201
|
async retryDeferredDecision(orgId, factoryProjectId, decisionId, now) {
|
|
2078
2202
|
const retriedRecord = await this.#withTransaction(async (ops) => {
|
|
@@ -2291,12 +2415,13 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2291
2415
|
resource_id: input.sessionId
|
|
2292
2416
|
}, { resource_id: input.resourceId });
|
|
2293
2417
|
}
|
|
2294
|
-
/** List binding history, optionally narrowed to one work
|
|
2418
|
+
/** List binding history, optionally narrowed to one or some work items. */
|
|
2295
2419
|
async listRunBindings(orgId, factoryProjectId, workItemId) {
|
|
2420
|
+
if (Array.isArray(workItemId) && workItemId.length === 0) return [];
|
|
2296
2421
|
return (await this.#db.findMany("factory_run_bindings", {
|
|
2297
2422
|
org_id: orgId,
|
|
2298
2423
|
factory_project_id: factoryProjectId,
|
|
2299
|
-
...workItemId ? { work_item_id: workItemId } : {}
|
|
2424
|
+
...workItemId ? { work_item_id: Array.isArray(workItemId) ? { in: workItemId } : workItemId } : {}
|
|
2300
2425
|
}, { orderBy: [["created_at", "asc"]] })).map(toBinding);
|
|
2301
2426
|
}
|
|
2302
2427
|
async listPendingStarts(orgId, factoryProjectId) {
|
|
@@ -2332,7 +2457,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2332
2457
|
org_id: input.orgId,
|
|
2333
2458
|
factory_project_id: input.factoryProjectId
|
|
2334
2459
|
});
|
|
2335
|
-
const itemRow = bindingRow && await
|
|
2460
|
+
const itemRow = bindingRow && await this.#cards(ops, { transaction: true }).findOne({
|
|
2336
2461
|
id: String(bindingRow.work_item_id),
|
|
2337
2462
|
org_id: input.orgId,
|
|
2338
2463
|
factory_project_id: input.factoryProjectId
|
|
@@ -2351,18 +2476,18 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2351
2476
|
}
|
|
2352
2477
|
const now = /* @__PURE__ */ new Date();
|
|
2353
2478
|
const create = input.workItem.input;
|
|
2354
|
-
let row = input.workItem.id ? await
|
|
2479
|
+
let row = input.workItem.id ? await this.#cards(ops, { transaction: true }).findOne({
|
|
2355
2480
|
id: input.workItem.id,
|
|
2356
2481
|
org_id: input.orgId,
|
|
2357
2482
|
factory_project_id: input.factoryProjectId
|
|
2358
|
-
}) : externalSourceKey(create.externalSource) ? await
|
|
2483
|
+
}) : externalSourceKey(create.externalSource) ? await this.#cards(ops, { transaction: true }).findOne({
|
|
2359
2484
|
org_id: input.orgId,
|
|
2360
2485
|
factory_project_id: input.factoryProjectId,
|
|
2361
2486
|
source_key: externalSourceKey(create.externalSource)
|
|
2362
2487
|
}) : null;
|
|
2363
2488
|
let item;
|
|
2364
2489
|
if (row) {
|
|
2365
|
-
row = await
|
|
2490
|
+
row = await this.#cards(ops, { transaction: true }).updateAtomic({ id: row.id }, (current) => {
|
|
2366
2491
|
return applyUpdate({
|
|
2367
2492
|
current,
|
|
2368
2493
|
userId: input.userId,
|
|
@@ -2372,11 +2497,12 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2372
2497
|
});
|
|
2373
2498
|
item = toRow(row);
|
|
2374
2499
|
} else {
|
|
2375
|
-
if (create.parentWorkItemId)
|
|
2500
|
+
if (create.parentWorkItemId) await this.#copyLegacyParent(ops, input.orgId, create.parentWorkItemId);
|
|
2501
|
+
if (create.parentWorkItemId) validateParentRelation((await this.#cards(ops, { transaction: true }).findMany({
|
|
2376
2502
|
org_id: input.orgId,
|
|
2377
2503
|
factory_project_id: input.factoryProjectId
|
|
2378
2504
|
})).map(toRow), void 0, create.parentWorkItemId);
|
|
2379
|
-
row = await
|
|
2505
|
+
row = await this.#cards(ops, { transaction: true }).insertOne({
|
|
2380
2506
|
org_id: input.orgId,
|
|
2381
2507
|
created_by: input.userId,
|
|
2382
2508
|
factory_project_id: input.factoryProjectId,
|
|
@@ -2502,7 +2628,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2502
2628
|
const key = externalSourceKey(input.externalSource);
|
|
2503
2629
|
const reuse = async () => {
|
|
2504
2630
|
if (!key) return null;
|
|
2505
|
-
const existing = await
|
|
2631
|
+
const existing = await this.#cards(ops, { transaction: true }).findOne({
|
|
2506
2632
|
org_id: orgId,
|
|
2507
2633
|
factory_project_id: factoryProjectId,
|
|
2508
2634
|
source_key: key
|
|
@@ -2514,7 +2640,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2514
2640
|
previous: priorState(existing)
|
|
2515
2641
|
};
|
|
2516
2642
|
let previous = emptyPrior();
|
|
2517
|
-
const updated = await
|
|
2643
|
+
const updated = await this.#cards(ops, { transaction: true }).updateAtomic({
|
|
2518
2644
|
org_id: orgId,
|
|
2519
2645
|
factory_project_id: factoryProjectId,
|
|
2520
2646
|
source_key: key
|
|
@@ -2529,7 +2655,10 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2529
2655
|
parentWorkItemId: input.parentWorkItemId ?? void 0,
|
|
2530
2656
|
metadata: input.metadata
|
|
2531
2657
|
} : fullPatch;
|
|
2532
|
-
if (patch.parentWorkItemId !== void 0)
|
|
2658
|
+
if (patch.parentWorkItemId !== void 0) {
|
|
2659
|
+
await this.#copyLegacyParent(ops, orgId, patch.parentWorkItemId);
|
|
2660
|
+
validateParentRelation(await this.#listWithOps(ops, orgId, factoryProjectId), current.id, patch.parentWorkItemId);
|
|
2661
|
+
}
|
|
2533
2662
|
return {
|
|
2534
2663
|
board: reuseMode === "non-stage" ? current.board : input.board ?? current.board ?? null,
|
|
2535
2664
|
external_source: input.externalSource ?? null,
|
|
@@ -2550,9 +2679,12 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2550
2679
|
if (reused) return reused;
|
|
2551
2680
|
const now = /* @__PURE__ */ new Date();
|
|
2552
2681
|
const stages = input.stages ?? ["intake"];
|
|
2553
|
-
|
|
2682
|
+
if (input.parentWorkItemId != null) {
|
|
2683
|
+
await this.#copyLegacyParent(ops, orgId, input.parentWorkItemId);
|
|
2684
|
+
validateParentRelation(await this.#listWithOps(ops, orgId, factoryProjectId), void 0, input.parentWorkItemId);
|
|
2685
|
+
}
|
|
2554
2686
|
return {
|
|
2555
|
-
item: toWorkItem(await
|
|
2687
|
+
item: toWorkItem(await this.#cards(ops, { transaction: true }).insertOne({
|
|
2556
2688
|
org_id: orgId,
|
|
2557
2689
|
factory_project_id: factoryProjectId,
|
|
2558
2690
|
board: input.board ?? null,
|
|
@@ -2578,17 +2710,18 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2578
2710
|
};
|
|
2579
2711
|
}
|
|
2580
2712
|
async setParentWorkItemIfMissing({ orgId, id, userId, parentWorkItemId }) {
|
|
2581
|
-
const candidate = await
|
|
2713
|
+
const candidate = await this.#cards(this.#db, { transaction: false }).findOne({
|
|
2582
2714
|
org_id: orgId,
|
|
2583
2715
|
id
|
|
2584
2716
|
});
|
|
2585
2717
|
if (!candidate) return null;
|
|
2586
2718
|
return this.#withProjectRelationTransaction(orgId, candidate.factory_project_id, async (ops) => {
|
|
2587
|
-
const row = await
|
|
2719
|
+
const row = await this.#cards(ops, { transaction: true }).updateAtomic({
|
|
2588
2720
|
org_id: orgId,
|
|
2589
2721
|
id
|
|
2590
2722
|
}, async (current) => {
|
|
2591
2723
|
if (current.parent_work_item_id !== null) return current;
|
|
2724
|
+
await this.#copyLegacyParent(ops, orgId, parentWorkItemId);
|
|
2592
2725
|
validateParentRelation(await this.#listWithOps(ops, orgId, current.factory_project_id), current.id, parentWorkItemId);
|
|
2593
2726
|
return applyUpdate({
|
|
2594
2727
|
current,
|
|
@@ -2602,14 +2735,17 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2602
2735
|
async update({ orgId, id, userId, patch, expectedRevision, expectedBoard }) {
|
|
2603
2736
|
const run = async (ops) => {
|
|
2604
2737
|
let previous = emptyPrior();
|
|
2605
|
-
const row = await
|
|
2738
|
+
const row = await this.#cards(ops, { transaction: true }).updateAtomic({
|
|
2606
2739
|
org_id: orgId,
|
|
2607
2740
|
id
|
|
2608
2741
|
}, async (current) => {
|
|
2609
2742
|
previous = priorState(current);
|
|
2610
2743
|
if (expectedBoard !== void 0 && current.board !== expectedBoard) throw new WorkItemUpdateConflictError("board");
|
|
2611
2744
|
if (expectedRevision !== void 0 && current.revision !== expectedRevision) throw new WorkItemUpdateConflictError("revision");
|
|
2612
|
-
if (patch.parentWorkItemId !== void 0)
|
|
2745
|
+
if (patch.parentWorkItemId !== void 0) {
|
|
2746
|
+
await this.#copyLegacyParent(ops, orgId, patch.parentWorkItemId);
|
|
2747
|
+
validateParentRelation(await this.#listWithOps(ops, orgId, current.factory_project_id), current.id, patch.parentWorkItemId);
|
|
2748
|
+
}
|
|
2613
2749
|
return applyUpdate({
|
|
2614
2750
|
current,
|
|
2615
2751
|
userId,
|
|
@@ -2622,7 +2758,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2622
2758
|
} : null;
|
|
2623
2759
|
};
|
|
2624
2760
|
if (patch.parentWorkItemId === void 0) return this.#withTransaction(run);
|
|
2625
|
-
const candidate = await
|
|
2761
|
+
const candidate = await this.#cards(this.#db, { transaction: false }).findOne({
|
|
2626
2762
|
org_id: orgId,
|
|
2627
2763
|
id
|
|
2628
2764
|
});
|
|
@@ -2758,12 +2894,12 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2758
2894
|
...expectedRevision === void 0 ? {} : { revision: expectedRevision },
|
|
2759
2895
|
...expectedUpdatedAt === void 0 ? {} : { updated_at: expectedUpdatedAt }
|
|
2760
2896
|
};
|
|
2761
|
-
const candidate = await
|
|
2897
|
+
const candidate = await this.#cards(this.#db, { transaction: false }).findOne(where);
|
|
2762
2898
|
if (!candidate) return null;
|
|
2763
2899
|
const removed = await this.#withProjectRelationTransaction(orgId, candidate.factory_project_id, async (ops) => {
|
|
2764
|
-
const existing = await
|
|
2900
|
+
const existing = await this.#cards(ops, { transaction: true }).findOne(where);
|
|
2765
2901
|
if (!existing) return null;
|
|
2766
|
-
if (await
|
|
2902
|
+
if (await this.#cards(ops, { transaction: true }).deleteMany(where) === 0) return null;
|
|
2767
2903
|
await this.#purgeFeedState(ops, {
|
|
2768
2904
|
orgId,
|
|
2769
2905
|
factoryProjectId: existing.factory_project_id,
|
|
@@ -2778,7 +2914,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
|
|
|
2778
2914
|
factoryProjectId: existing.factory_project_id,
|
|
2779
2915
|
sourceKeys: [existing.external_source.externalId]
|
|
2780
2916
|
});
|
|
2781
|
-
await
|
|
2917
|
+
await this.#cards(ops, { transaction: true }).updateMany({
|
|
2782
2918
|
org_id: orgId,
|
|
2783
2919
|
parent_work_item_id: id
|
|
2784
2920
|
}, {
|