@mastra/factory 0.15.1-alpha.0 → 0.16.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 +41 -3
- package/dist/auth.js +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/boards/index.d.ts +1 -1
- package/dist/boards/index.d.ts.map +1 -1
- package/dist/boards/index.js +2 -2
- package/dist/boards/index.js.map +1 -1
- package/dist/boards/review.d.ts.map +1 -1
- package/dist/boards/review.js +23 -9
- package/dist/boards/review.js.map +1 -1
- package/dist/boards/semantics.d.ts +7 -0
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js +15 -1
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/work.d.ts.map +1 -1
- package/dist/boards/work.js +68 -6
- package/dist/boards/work.js.map +1 -1
- package/dist/capabilities/intake.d.ts +8 -0
- package/dist/capabilities/intake.d.ts.map +1 -1
- package/dist/capabilities/version-control.d.ts +15 -0
- package/dist/capabilities/version-control.d.ts.map +1 -1
- package/dist/factory.d.ts +8 -5
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +136 -53
- package/dist/factory.js.map +1 -1
- package/dist/integrations/base.d.ts +5 -0
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +21 -0
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/routes.js +2 -1
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +41 -42
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +416 -227
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/github/webhook.d.ts +2 -5
- package/dist/integrations/github/webhook.d.ts.map +1 -1
- package/dist/integrations/github/webhook.js +8 -48
- package/dist/integrations/github/webhook.js.map +1 -1
- package/dist/integrations/gitlab/agent-tools.d.ts +14 -0
- package/dist/integrations/gitlab/agent-tools.d.ts.map +1 -0
- package/dist/integrations/gitlab/agent-tools.js +42 -0
- package/dist/integrations/gitlab/agent-tools.js.map +1 -0
- package/dist/integrations/gitlab/api.d.ts +222 -0
- package/dist/integrations/gitlab/api.d.ts.map +1 -0
- package/dist/integrations/gitlab/api.js +274 -0
- package/dist/integrations/gitlab/api.js.map +1 -0
- package/dist/integrations/gitlab/default-rules.d.ts +125 -0
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -0
- package/dist/integrations/gitlab/default-rules.js +172 -0
- package/dist/integrations/gitlab/default-rules.js.map +1 -0
- package/dist/integrations/gitlab/integration.d.ts +138 -0
- package/dist/integrations/gitlab/integration.d.ts.map +1 -0
- package/dist/integrations/gitlab/integration.js +705 -0
- package/dist/integrations/gitlab/integration.js.map +1 -0
- package/dist/integrations/gitlab/issue-reconciler.d.ts +6 -0
- package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -0
- package/dist/integrations/gitlab/issue-reconciler.js +123 -0
- package/dist/integrations/gitlab/issue-reconciler.js.map +1 -0
- package/dist/integrations/gitlab/merge-request-reconciler.d.ts +6 -0
- package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -0
- package/dist/integrations/gitlab/merge-request-reconciler.js +267 -0
- package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -0
- package/dist/integrations/gitlab/reconciler.d.ts +5 -0
- package/dist/integrations/gitlab/reconciler.d.ts.map +1 -0
- package/dist/integrations/gitlab/reconciler.js +31 -0
- package/dist/integrations/gitlab/reconciler.js.map +1 -0
- package/dist/integrations/gitlab/reconciliation-config.d.ts +3 -0
- package/dist/integrations/gitlab/reconciliation-config.d.ts.map +1 -0
- package/dist/integrations/gitlab/reconciliation-config.js +17 -0
- package/dist/integrations/gitlab/reconciliation-config.js.map +1 -0
- package/dist/integrations/gitlab/routes.d.ts +20 -0
- package/dist/integrations/gitlab/routes.d.ts.map +1 -0
- package/dist/integrations/gitlab/routes.js +473 -0
- package/dist/integrations/gitlab/routes.js.map +1 -0
- package/dist/integrations/gitlab/rules.d.ts +35 -0
- package/dist/integrations/gitlab/rules.d.ts.map +1 -0
- package/dist/integrations/gitlab/rules.js +391 -0
- package/dist/integrations/gitlab/rules.js.map +1 -0
- package/dist/integrations/gitlab/session-subscriptions.d.ts +32 -0
- package/dist/integrations/gitlab/session-subscriptions.d.ts.map +1 -0
- package/dist/integrations/gitlab/session-subscriptions.js +192 -0
- package/dist/integrations/gitlab/session-subscriptions.js.map +1 -0
- package/dist/integrations/gitlab/subscriptions.d.ts +70 -0
- package/dist/integrations/gitlab/subscriptions.d.ts.map +1 -0
- package/dist/integrations/gitlab/subscriptions.js +76 -0
- package/dist/integrations/gitlab/subscriptions.js.map +1 -0
- package/dist/integrations/gitlab/version-control.d.ts +16 -0
- package/dist/integrations/gitlab/version-control.d.ts.map +1 -0
- package/dist/integrations/gitlab/version-control.js +622 -0
- package/dist/integrations/gitlab/version-control.js.map +1 -0
- package/dist/integrations/gitlab/webhook-dispatch.d.ts +75 -0
- package/dist/integrations/gitlab/webhook-dispatch.d.ts.map +1 -0
- package/dist/integrations/gitlab/webhook-dispatch.js +235 -0
- package/dist/integrations/gitlab/webhook-dispatch.js.map +1 -0
- package/dist/integrations/gitlab/webhook.d.ts +72 -0
- package/dist/integrations/gitlab/webhook.d.ts.map +1 -0
- package/dist/integrations/gitlab/webhook.js +201 -0
- package/dist/integrations/gitlab/webhook.js.map +1 -0
- package/dist/integrations/incidentio/agent-tools.d.ts +49 -0
- package/dist/integrations/incidentio/agent-tools.d.ts.map +1 -0
- package/dist/integrations/incidentio/agent-tools.js +90 -0
- package/dist/integrations/incidentio/agent-tools.js.map +1 -0
- package/dist/integrations/incidentio/claim.d.ts +8 -0
- package/dist/integrations/incidentio/claim.d.ts.map +1 -0
- package/dist/integrations/incidentio/claim.js +14 -0
- package/dist/integrations/incidentio/claim.js.map +1 -0
- package/dist/integrations/incidentio/default-rules.d.ts +46 -0
- package/dist/integrations/incidentio/default-rules.d.ts.map +1 -0
- package/dist/integrations/incidentio/default-rules.js +66 -0
- package/dist/integrations/incidentio/default-rules.js.map +1 -0
- package/dist/integrations/incidentio/integration.d.ts +48 -2
- package/dist/integrations/incidentio/integration.d.ts.map +1 -1
- package/dist/integrations/incidentio/integration.js +89 -3
- package/dist/integrations/incidentio/integration.js.map +1 -1
- package/dist/integrations/incidentio/issue-reconciler.d.ts +2 -0
- package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/incidentio/issue-reconciler.js +38 -2
- package/dist/integrations/incidentio/issue-reconciler.js.map +1 -1
- package/dist/integrations/incidentio/routes.d.ts +71 -0
- package/dist/integrations/incidentio/routes.d.ts.map +1 -0
- package/dist/integrations/incidentio/routes.js +245 -0
- package/dist/integrations/incidentio/routes.js.map +1 -0
- package/dist/integrations/incidentio/rules.d.ts +55 -0
- package/dist/integrations/incidentio/rules.d.ts.map +1 -0
- package/dist/integrations/incidentio/rules.js +175 -0
- package/dist/integrations/incidentio/rules.js.map +1 -0
- package/dist/integrations/issue-reconciler.d.ts +3 -3
- package/dist/integrations/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/issue-reconciler.js +22 -2
- package/dist/integrations/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/adf.d.ts +26 -0
- package/dist/integrations/jira/adf.d.ts.map +1 -0
- package/dist/integrations/jira/adf.js +73 -0
- package/dist/integrations/jira/adf.js.map +1 -0
- package/dist/integrations/jira/agent-tools.d.ts +45 -0
- package/dist/integrations/jira/agent-tools.d.ts.map +1 -0
- package/dist/integrations/jira/agent-tools.js +87 -0
- package/dist/integrations/jira/agent-tools.js.map +1 -0
- package/dist/integrations/jira/api.d.ts +157 -0
- package/dist/integrations/jira/api.d.ts.map +1 -0
- package/dist/integrations/jira/api.js +141 -0
- package/dist/integrations/jira/api.js.map +1 -0
- package/dist/integrations/jira/claim.d.ts +9 -0
- package/dist/integrations/jira/claim.d.ts.map +1 -0
- package/dist/integrations/jira/claim.js +15 -0
- package/dist/integrations/jira/claim.js.map +1 -0
- package/dist/integrations/jira/default-rules.d.ts +47 -0
- package/dist/integrations/jira/default-rules.d.ts.map +1 -0
- package/dist/integrations/jira/default-rules.js +67 -0
- package/dist/integrations/jira/default-rules.js.map +1 -0
- package/dist/integrations/jira/integration.d.ts +114 -0
- package/dist/integrations/jira/integration.d.ts.map +1 -0
- package/dist/integrations/jira/integration.js +401 -0
- package/dist/integrations/jira/integration.js.map +1 -0
- package/dist/integrations/jira/issue-reconciler.d.ts +10 -0
- package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -0
- package/dist/integrations/jira/issue-reconciler.js +70 -0
- package/dist/integrations/jira/issue-reconciler.js.map +1 -0
- package/dist/integrations/jira/reconciliation-config.d.ts +3 -0
- package/dist/integrations/jira/reconciliation-config.d.ts.map +1 -0
- package/dist/integrations/jira/reconciliation-config.js +17 -0
- package/dist/integrations/jira/reconciliation-config.js.map +1 -0
- package/dist/integrations/jira/routes.d.ts +54 -0
- package/dist/integrations/jira/routes.d.ts.map +1 -0
- package/dist/integrations/jira/routes.js +260 -0
- package/dist/integrations/jira/routes.js.map +1 -0
- package/dist/integrations/jira/rules.d.ts +57 -0
- package/dist/integrations/jira/rules.d.ts.map +1 -0
- package/dist/integrations/jira/rules.js +175 -0
- package/dist/integrations/jira/rules.js.map +1 -0
- package/dist/integrations/linear/claim.d.ts +8 -0
- package/dist/integrations/linear/claim.d.ts.map +1 -0
- package/dist/integrations/linear/claim.js +14 -0
- package/dist/integrations/linear/claim.js.map +1 -0
- package/dist/integrations/linear/default-rules.d.ts +1 -0
- package/dist/integrations/linear/default-rules.d.ts.map +1 -1
- package/dist/integrations/linear/default-rules.js +2 -0
- package/dist/integrations/linear/default-rules.js.map +1 -1
- package/dist/integrations/linear/integration.d.ts +24 -6
- package/dist/integrations/linear/integration.d.ts.map +1 -1
- package/dist/integrations/linear/integration.js +257 -37
- package/dist/integrations/linear/integration.js.map +1 -1
- package/dist/integrations/linear/routes.d.ts +10 -0
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +74 -10
- package/dist/integrations/linear/routes.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +27 -2
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/connect/routes.d.ts +39 -0
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -0
- package/dist/integrations/platform/connect/routes.js +129 -0
- package/dist/integrations/platform/connect/routes.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 +22 -1
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/gitlab/event-worker.d.ts +64 -0
- package/dist/integrations/platform/gitlab/event-worker.d.ts.map +1 -0
- package/dist/integrations/platform/gitlab/event-worker.js +306 -0
- package/dist/integrations/platform/gitlab/event-worker.js.map +1 -0
- package/dist/integrations/platform/gitlab/integration.d.ts +57 -0
- package/dist/integrations/platform/gitlab/integration.d.ts.map +1 -0
- package/dist/integrations/platform/gitlab/integration.js +125 -0
- package/dist/integrations/platform/gitlab/integration.js.map +1 -0
- package/dist/integrations/platform/incidentio/integration.d.ts +61 -4
- package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -1
- package/dist/integrations/platform/incidentio/integration.js +372 -23
- package/dist/integrations/platform/incidentio/integration.js.map +1 -1
- package/dist/integrations/platform/jira/agent-tools.d.ts +36 -0
- package/dist/integrations/platform/jira/agent-tools.d.ts.map +1 -0
- package/dist/integrations/platform/jira/agent-tools.js +85 -0
- package/dist/integrations/platform/jira/agent-tools.js.map +1 -0
- package/dist/integrations/platform/jira/integration.d.ts +65 -0
- package/dist/integrations/platform/jira/integration.d.ts.map +1 -0
- package/dist/integrations/platform/jira/integration.js +540 -0
- package/dist/integrations/platform/jira/integration.js.map +1 -0
- package/dist/integrations/platform/jira/routes.d.ts +55 -0
- package/dist/integrations/platform/jira/routes.d.ts.map +1 -0
- package/dist/integrations/platform/jira/routes.js +274 -0
- package/dist/integrations/platform/jira/routes.js.map +1 -0
- package/dist/integrations/platform/linear/integration.d.ts +34 -1
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
- package/dist/integrations/platform/linear/integration.js +271 -48
- package/dist/integrations/platform/linear/integration.js.map +1 -1
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +3 -3
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/slack/slack.d.ts +2 -0
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +21 -7
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/integrations/subscription-session.d.ts +37 -0
- package/dist/integrations/subscription-session.d.ts.map +1 -0
- package/dist/integrations/subscription-session.js +83 -0
- package/dist/integrations/subscription-session.js.map +1 -0
- package/dist/packages/_internals/workspace/dist/index.js +1 -11
- package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
- package/dist/routes/intake.d.ts.map +1 -1
- package/dist/routes/intake.js +16 -4
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/oauth.js +3 -6
- package/dist/routes/oauth.js.map +1 -1
- package/dist/routes/projects.d.ts +1 -0
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +1 -0
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/source-control-sessions.d.ts +20 -0
- package/dist/routes/source-control-sessions.d.ts.map +1 -0
- package/dist/routes/source-control-sessions.js +319 -0
- package/dist/routes/source-control-sessions.js.map +1 -0
- package/dist/routes/source-control-settings.d.ts +10 -0
- package/dist/routes/source-control-settings.d.ts.map +1 -0
- package/dist/routes/source-control-settings.js +87 -0
- package/dist/routes/source-control-settings.js.map +1 -0
- package/dist/routes/surface.d.ts +3 -3
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +79 -17
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/tenant-credentials.d.ts +8 -0
- package/dist/routes/tenant-credentials.d.ts.map +1 -1
- package/dist/routes/tenant-credentials.js +20 -3
- package/dist/routes/tenant-credentials.js.map +1 -1
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +1 -1
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/dispatch-errors.d.ts.map +1 -1
- package/dist/rules/dispatch-errors.js +8 -0
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +1 -0
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +186 -106
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/index.d.ts +2 -2
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +2 -2
- package/dist/rules/start-coordinator.d.ts +1 -1
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +7 -3
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/terminal-cleanup.d.ts +14 -1
- package/dist/rules/terminal-cleanup.d.ts.map +1 -1
- package/dist/rules/terminal-cleanup.js +20 -0
- package/dist/rules/terminal-cleanup.js.map +1 -1
- package/dist/rules/tools.d.ts +2 -0
- package/dist/rules/tools.d.ts.map +1 -1
- package/dist/rules/tools.js +30 -2
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts +3 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +10 -5
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +136 -3
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +31 -2
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +15 -2
- package/dist/rules/validation.js.map +1 -1
- package/dist/sandbox/git-ref.d.ts +7 -0
- package/dist/sandbox/git-ref.d.ts.map +1 -0
- package/dist/sandbox/git-ref.js +15 -0
- package/dist/sandbox/git-ref.js.map +1 -0
- package/dist/sandbox/session-retirement.js +1 -1
- package/dist/sandbox/workdir.d.ts.map +1 -1
- package/dist/sandbox/workdir.js +6 -6
- package/dist/sandbox/workdir.js.map +1 -1
- package/dist/session/factory-session.d.ts +31 -1
- package/dist/session/factory-session.d.ts.map +1 -1
- package/dist/session/factory-session.js +60 -1
- package/dist/session/factory-session.js.map +1 -1
- package/dist/session/run-audit.d.ts +9 -0
- package/dist/session/run-audit.d.ts.map +1 -1
- package/dist/session/run-audit.js +37 -6
- package/dist/session/run-audit.js.map +1 -1
- package/dist/session/source-control-tools.d.ts +16 -0
- package/dist/session/source-control-tools.d.ts.map +1 -0
- package/dist/session/source-control-tools.js +464 -0
- package/dist/session/source-control-tools.js.map +1 -0
- package/dist/skills/service.d.ts +12 -0
- package/dist/skills/service.d.ts.map +1 -1
- package/dist/skills/service.js +27 -1
- package/dist/skills/service.js.map +1 -1
- package/dist/storage/domains/intake/base.d.ts +18 -0
- package/dist/storage/domains/intake/base.d.ts.map +1 -1
- package/dist/storage/domains/intake/base.js +77 -0
- package/dist/storage/domains/intake/base.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +41 -2
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +159 -12
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/supervisor/session-messaging.d.ts +23 -0
- package/dist/supervisor/session-messaging.d.ts.map +1 -0
- package/dist/supervisor/session-messaging.js +15 -0
- package/dist/supervisor/session-messaging.js.map +1 -0
- package/dist/supervisor/write-tools.d.ts +2 -1
- package/dist/supervisor/write-tools.d.ts.map +1 -1
- package/dist/supervisor/write-tools.js +11 -7
- package/dist/supervisor/write-tools.js.map +1 -1
- package/dist/work-item-branch.d.ts +3 -1
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +26 -6
- package/dist/work-item-branch.js.map +1 -1
- package/dist/workspace.d.ts +15 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +57 -23
- package/dist/workspace.js.map +1 -1
- package/factory-skills/factory-gitlab-rereview/SKILL.md +19 -0
- package/factory-skills/factory-gitlab-review/SKILL.md +30 -0
- package/factory-skills/factory-rereview/SKILL.md +13 -6
- package/factory-skills/factory-review/SKILL.md +13 -6
- package/factory-skills/factory-review/references/archaeology.md +225 -0
- package/factory-skills/factory-review/references/categories/README.md +34 -0
- package/factory-skills/factory-review/references/categories/behavior-change.md +36 -0
- package/factory-skills/factory-review/references/categories/bug-fix.md +37 -0
- package/factory-skills/factory-review/references/categories/docs.md +32 -0
- package/factory-skills/factory-review/references/categories/experimental-flagged.md +34 -0
- package/factory-skills/factory-review/references/categories/infra-tooling.md +37 -0
- package/factory-skills/factory-review/references/categories/internal-capability.md +35 -0
- package/factory-skills/factory-review/references/categories/large-cross-cutting.md +35 -0
- package/factory-skills/factory-review/references/categories/mechanical.md +36 -0
- package/factory-skills/factory-review/references/categories/performance.md +33 -0
- package/factory-skills/factory-review/references/categories/public-api.md +38 -0
- package/factory-skills/factory-review/references/categories/refactor.md +35 -0
- package/factory-skills/factory-review/references/categories/revert.md +31 -0
- package/factory-skills/factory-review/references/categories/schema-storage.md +39 -0
- package/factory-skills/factory-review/references/categories/security.md +35 -0
- package/factory-skills/factory-review/references/categories/tests-only.md +38 -0
- package/package.json +12 -12
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { RequestContext } from '@mastra/core/request-context';
|
|
2
|
+
import type { ApiRoute } from '@mastra/core/server';
|
|
3
|
+
import type { MastraWorker } from '@mastra/core/worker';
|
|
4
|
+
import type { Intake, IntakeIssue } from '../../../capabilities/intake.js';
|
|
5
|
+
import type { RouteAuth } from '../../../routes/route.js';
|
|
6
|
+
import type { FactoryProjectsStorage } from '../../../storage/domains/projects/base.js';
|
|
7
|
+
import type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../../base.js';
|
|
8
|
+
import type { JiraEventRules, JiraRuleOverrides } from '../../jira/default-rules.js';
|
|
9
|
+
import { type PlatformApiClientConfig } from '../api-client.js';
|
|
10
|
+
interface PlatformIntegrationConnection {
|
|
11
|
+
id: string;
|
|
12
|
+
integrationId: string;
|
|
13
|
+
status: 'active' | 'needs_reauth';
|
|
14
|
+
accountLabel: string | null;
|
|
15
|
+
}
|
|
16
|
+
interface JiraIssueReference {
|
|
17
|
+
connectionId: string;
|
|
18
|
+
issueId: string;
|
|
19
|
+
projectId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface PlatformJiraIntegrationConfig {
|
|
22
|
+
clientConfig?: PlatformApiClientConfig;
|
|
23
|
+
/** Per-event replacements; omitted events retain defaults, null disables. */
|
|
24
|
+
rules?: JiraRuleOverrides;
|
|
25
|
+
}
|
|
26
|
+
export declare class PlatformJiraIntegration implements FactoryIntegration {
|
|
27
|
+
#private;
|
|
28
|
+
readonly id = "jira";
|
|
29
|
+
get rules(): JiraEventRules;
|
|
30
|
+
constructor(config?: PlatformJiraIntegrationConfig);
|
|
31
|
+
initialize({ projects, auth }: {
|
|
32
|
+
projects: FactoryProjectsStorage;
|
|
33
|
+
auth: RouteAuth;
|
|
34
|
+
}): void;
|
|
35
|
+
get projects(): FactoryProjectsStorage;
|
|
36
|
+
get authEnabled(): boolean;
|
|
37
|
+
resolveOrgId(resourceId: string): Promise<string | null>;
|
|
38
|
+
clearCaches(): void;
|
|
39
|
+
listConnections(): Promise<PlatformIntegrationConnection[]>;
|
|
40
|
+
hasActiveConnections(): Promise<boolean>;
|
|
41
|
+
readonly intake: Intake;
|
|
42
|
+
listActiveIssues(cursor?: string, sourceIds?: string[], labels?: string[]): Promise<{
|
|
43
|
+
issues: Array<IntakeIssue & {
|
|
44
|
+
sourceId: string;
|
|
45
|
+
externalId: string;
|
|
46
|
+
site: string;
|
|
47
|
+
}>;
|
|
48
|
+
nextCursor: string | null;
|
|
49
|
+
}>;
|
|
50
|
+
workers(ctx: IntegrationContext): MastraWorker[];
|
|
51
|
+
routes(ctx: IntegrationContext): ApiRoute[];
|
|
52
|
+
agentTools(args: {
|
|
53
|
+
requestContext: RequestContext;
|
|
54
|
+
}): Promise<IntegrationTools>;
|
|
55
|
+
diagnostics(): Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
export declare function encodeSourceId(connectionId: string, projectId: string): string;
|
|
58
|
+
export declare function decodeSourceId(sourceId: string): {
|
|
59
|
+
connectionId: string;
|
|
60
|
+
projectId: string;
|
|
61
|
+
} | null;
|
|
62
|
+
export declare function encodeIssueReference(reference: JiraIssueReference): string;
|
|
63
|
+
export declare function decodeIssueReference(value: string): JiraIssueReference | null;
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/jira/integration.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
import { PlatformApiClient, logPlatformInfo, platformApiClientConfigFromEnv } from "../api-client.js";
|
|
2
|
+
import { IssueReconcileWorker } from "../../issue-reconcile-worker.js";
|
|
3
|
+
import { adfToText } from "../../jira/adf.js";
|
|
4
|
+
import { JiraApiClient, JiraApiError } from "../../jira/api.js";
|
|
5
|
+
import { resolveJiraRules } from "../../jira/default-rules.js";
|
|
6
|
+
import { attachJiraRules } from "../../jira/rules.js";
|
|
7
|
+
import { attachJiraIssueReconciler } from "../../jira/issue-reconciler.js";
|
|
8
|
+
import { jiraReconciliationEnabled, jiraReconciliationInterval } from "../../jira/reconciliation-config.js";
|
|
9
|
+
import { buildPlatformJiraAgentTools } from "./agent-tools.js";
|
|
10
|
+
import { buildPlatformJiraRoutes } from "./routes.js";
|
|
11
|
+
//#region src/integrations/platform/jira/integration.ts
|
|
12
|
+
const ISSUE_COMMENTS_MAX_PAGES = 20;
|
|
13
|
+
/** Hard stop for project pagination so a misbehaving `isLast` can't loop forever. */
|
|
14
|
+
const PROJECT_SEARCH_MAX_PAGES = 50;
|
|
15
|
+
const ISSUE_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]*-\d+$/;
|
|
16
|
+
const PLATFORM_JIRA_PROVIDER_CONFIG_KEY = "jira";
|
|
17
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
18
|
+
const JIRA_CONNECTION_TOKEN_PREFIX = "jira-connection:";
|
|
19
|
+
const JIRA_ISSUE_REF_PREFIX = "jira-issue:";
|
|
20
|
+
const JIRA_SOURCE_PREFIX = "jira-project:";
|
|
21
|
+
const STATE_TYPE_TO_CATEGORY = {
|
|
22
|
+
unstarted: "new",
|
|
23
|
+
started: "indeterminate",
|
|
24
|
+
completed: "done"
|
|
25
|
+
};
|
|
26
|
+
function stateTypeFromCategory(key) {
|
|
27
|
+
switch (key) {
|
|
28
|
+
case "new": return "unstarted";
|
|
29
|
+
case "indeterminate": return "started";
|
|
30
|
+
case "done": return "completed";
|
|
31
|
+
default: return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
var PlatformJiraIntegration = class {
|
|
35
|
+
id = "jira";
|
|
36
|
+
#clientConfig;
|
|
37
|
+
#platformClient;
|
|
38
|
+
#endpointHost;
|
|
39
|
+
#cloudIdByConnectionId = /* @__PURE__ */ new Map();
|
|
40
|
+
#siteUrlByConnectionId = /* @__PURE__ */ new Map();
|
|
41
|
+
#projects;
|
|
42
|
+
#auth;
|
|
43
|
+
#orgIdByResourceId = /* @__PURE__ */ new Map();
|
|
44
|
+
#rules;
|
|
45
|
+
get rules() {
|
|
46
|
+
return this.#rules;
|
|
47
|
+
}
|
|
48
|
+
constructor(config = {}) {
|
|
49
|
+
this.#rules = resolveJiraRules(config.rules);
|
|
50
|
+
this.#clientConfig = config.clientConfig ?? platformApiClientConfigFromEnv();
|
|
51
|
+
this.#platformClient = new PlatformApiClient(this.#clientConfig);
|
|
52
|
+
this.#endpointHost = new URL(this.#clientConfig.baseUrl).host;
|
|
53
|
+
}
|
|
54
|
+
initialize({ projects, auth }) {
|
|
55
|
+
this.#projects = projects;
|
|
56
|
+
this.#auth = auth;
|
|
57
|
+
logPlatformInfo("Platform Jira integration initialized", { endpointHost: this.#endpointHost });
|
|
58
|
+
}
|
|
59
|
+
get projects() {
|
|
60
|
+
if (!this.#projects) throw new Error("PlatformJiraIntegration is not initialized — the factory binds storage during prepare().");
|
|
61
|
+
return this.#projects;
|
|
62
|
+
}
|
|
63
|
+
get authEnabled() {
|
|
64
|
+
return this.#auth?.enabled() ?? false;
|
|
65
|
+
}
|
|
66
|
+
async resolveOrgId(resourceId) {
|
|
67
|
+
const cached = this.#orgIdByResourceId.get(resourceId);
|
|
68
|
+
if (cached !== void 0) return cached;
|
|
69
|
+
if (!UUID_PATTERN.test(resourceId)) {
|
|
70
|
+
this.#orgIdByResourceId.set(resourceId, null);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
await this.projects.ensureReady();
|
|
75
|
+
const orgId = (await this.projects.getById({ id: resourceId }))?.orgId ?? null;
|
|
76
|
+
this.#orgIdByResourceId.set(resourceId, orgId);
|
|
77
|
+
return orgId;
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
clearCaches() {
|
|
83
|
+
this.#orgIdByResourceId.clear();
|
|
84
|
+
this.#cloudIdByConnectionId.clear();
|
|
85
|
+
this.#siteUrlByConnectionId.clear();
|
|
86
|
+
}
|
|
87
|
+
async listConnections() {
|
|
88
|
+
const providerKey = encodeURIComponent(PLATFORM_JIRA_PROVIDER_CONFIG_KEY);
|
|
89
|
+
return (await this.#platformClient.request("GET", `/v2/connections?providerKey=${providerKey}`)).connections;
|
|
90
|
+
}
|
|
91
|
+
async hasActiveConnections() {
|
|
92
|
+
return (await this.#activeConnections()).length > 0;
|
|
93
|
+
}
|
|
94
|
+
intake = {
|
|
95
|
+
resolveIntakeDispatch: (input) => this.#resolveIntakeDispatch(input),
|
|
96
|
+
listSources: () => this.#listSources(),
|
|
97
|
+
listItems: (input) => this.#listItems(input),
|
|
98
|
+
listIssues: (input) => this.#listIssues(input),
|
|
99
|
+
getIssue: (input) => this.#getIssue(input),
|
|
100
|
+
createComment: (input) => this.#createComment(input),
|
|
101
|
+
updateIssue: (input) => this.#updateIssue(input)
|
|
102
|
+
};
|
|
103
|
+
async #resolveIntakeDispatch({ externalSource }) {
|
|
104
|
+
if (externalSource.type !== "issue") return null;
|
|
105
|
+
const reference = decodeIssueReference(externalSource.externalId);
|
|
106
|
+
if (!reference) return null;
|
|
107
|
+
return {
|
|
108
|
+
connection: jiraConnection(reference.connectionId),
|
|
109
|
+
...reference.projectId ? { sourceId: encodeSourceId(reference.connectionId, reference.projectId) } : {},
|
|
110
|
+
issueId: reference.issueId
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async #listSources() {
|
|
114
|
+
const sources = [];
|
|
115
|
+
for (const connection of await this.#activeConnections()) {
|
|
116
|
+
const context = await this.#connectionContext(connection);
|
|
117
|
+
let startAt = 0;
|
|
118
|
+
for (let pageCount = 0; pageCount < PROJECT_SEARCH_MAX_PAGES; pageCount++) {
|
|
119
|
+
const page = await context.api.listProjects({ startAt });
|
|
120
|
+
for (const project of page.values) sources.push({
|
|
121
|
+
id: encodeSourceId(connection.id, project.id),
|
|
122
|
+
name: project.name,
|
|
123
|
+
type: "project",
|
|
124
|
+
metadata: {
|
|
125
|
+
key: project.key,
|
|
126
|
+
connectionId: connection.id,
|
|
127
|
+
site: new URL(context.siteUrl).host
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
if (page.isLast || page.values.length === 0) break;
|
|
131
|
+
startAt += page.values.length;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return sources;
|
|
135
|
+
}
|
|
136
|
+
async #listItems({ sourceIds, cursor }) {
|
|
137
|
+
if (sourceIds.length === 0) return {
|
|
138
|
+
items: [],
|
|
139
|
+
nextCursor: null
|
|
140
|
+
};
|
|
141
|
+
const page = await this.listActiveIssues(cursor, sourceIds);
|
|
142
|
+
return {
|
|
143
|
+
items: page.issues.map((issue) => ({
|
|
144
|
+
source: {
|
|
145
|
+
type: "issue",
|
|
146
|
+
externalId: issue.externalId,
|
|
147
|
+
url: issue.url
|
|
148
|
+
},
|
|
149
|
+
sourceId: issue.sourceId,
|
|
150
|
+
title: `${issue.identifier}: ${issue.title}`,
|
|
151
|
+
status: issue.state ?? void 0,
|
|
152
|
+
labels: issue.labels,
|
|
153
|
+
assignee: issue.assignee,
|
|
154
|
+
createdAt: issue.createdAt,
|
|
155
|
+
updatedAt: issue.updatedAt,
|
|
156
|
+
metadata: {
|
|
157
|
+
identifier: issue.identifier,
|
|
158
|
+
issueRef: issue.externalId,
|
|
159
|
+
state: issue.state,
|
|
160
|
+
stateType: issue.stateType,
|
|
161
|
+
priority: issue.priority,
|
|
162
|
+
project: issue.source,
|
|
163
|
+
site: issue.site,
|
|
164
|
+
assignee: issue.assignee,
|
|
165
|
+
assignees: issue.assignees ?? [],
|
|
166
|
+
creator: issue.author,
|
|
167
|
+
author: issue.author,
|
|
168
|
+
labels: issue.labels,
|
|
169
|
+
createdAt: issue.createdAt,
|
|
170
|
+
updatedAt: issue.updatedAt
|
|
171
|
+
}
|
|
172
|
+
})),
|
|
173
|
+
nextCursor: page.nextCursor
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async #listIssues(input) {
|
|
177
|
+
const page = await this.listActiveIssues(input.cursor, input.sourceIds, input.labels);
|
|
178
|
+
return {
|
|
179
|
+
issues: page.issues,
|
|
180
|
+
nextCursor: page.nextCursor
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
async listActiveIssues(cursor, sourceIds = [], labels) {
|
|
184
|
+
const grouped = groupSources(sourceIds);
|
|
185
|
+
if (grouped.length === 0) return {
|
|
186
|
+
issues: [],
|
|
187
|
+
nextCursor: null
|
|
188
|
+
};
|
|
189
|
+
const decodedCursor = decodePageCursor(cursor);
|
|
190
|
+
if (decodedCursor.group >= grouped.length) return {
|
|
191
|
+
issues: [],
|
|
192
|
+
nextCursor: null
|
|
193
|
+
};
|
|
194
|
+
for (let groupIndex = decodedCursor.group; groupIndex < grouped.length; groupIndex++) {
|
|
195
|
+
const group = grouped[groupIndex];
|
|
196
|
+
const context = await this.#connectionContextById(group.connectionId);
|
|
197
|
+
const jql = buildIntakeJql(group.projectIds, labels);
|
|
198
|
+
if (jql === null) continue;
|
|
199
|
+
const page = await context.api.searchIssues({
|
|
200
|
+
jql,
|
|
201
|
+
...groupIndex === decodedCursor.group && decodedCursor.jira ? { nextPageToken: decodedCursor.jira } : {}
|
|
202
|
+
});
|
|
203
|
+
const nextCursor = page.nextPageToken ? encodePageCursor({
|
|
204
|
+
group: groupIndex,
|
|
205
|
+
jira: page.nextPageToken
|
|
206
|
+
}) : groupIndex + 1 < grouped.length ? encodePageCursor({ group: groupIndex + 1 }) : null;
|
|
207
|
+
return {
|
|
208
|
+
issues: page.issues.map((issue) => {
|
|
209
|
+
const projectId = issue.fields.project?.id ?? group.projectIds[0] ?? "";
|
|
210
|
+
return {
|
|
211
|
+
...this.#toIntakeIssue(issue, context.siteUrl),
|
|
212
|
+
sourceId: encodeSourceId(group.connectionId, projectId),
|
|
213
|
+
externalId: encodeIssueReference({
|
|
214
|
+
connectionId: group.connectionId,
|
|
215
|
+
issueId: issue.key,
|
|
216
|
+
projectId
|
|
217
|
+
}),
|
|
218
|
+
site: new URL(context.siteUrl).host
|
|
219
|
+
};
|
|
220
|
+
}),
|
|
221
|
+
nextCursor
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
issues: [],
|
|
226
|
+
nextCursor: null
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
async #getIssue(input) {
|
|
230
|
+
const { context, issue } = await this.#findIssue(input) ?? {};
|
|
231
|
+
if (!context || !issue) return null;
|
|
232
|
+
const { comments, total } = await this.#listAllComments(context.api, issue.key);
|
|
233
|
+
return {
|
|
234
|
+
...this.#toIntakeIssue(issue, context.siteUrl),
|
|
235
|
+
commentCount: total,
|
|
236
|
+
description: issue.fields.description ? adfToText(issue.fields.description) || null : null,
|
|
237
|
+
comments: comments.map((comment) => ({
|
|
238
|
+
author: comment.author?.displayName ?? null,
|
|
239
|
+
body: adfToText(comment.body),
|
|
240
|
+
createdAt: comment.created
|
|
241
|
+
}))
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
async #listAllComments(api, keyOrId) {
|
|
245
|
+
const comments = [];
|
|
246
|
+
let total = 0;
|
|
247
|
+
for (let page = 0; page < ISSUE_COMMENTS_MAX_PAGES; page++) {
|
|
248
|
+
const result = await api.listComments(keyOrId, { startAt: comments.length });
|
|
249
|
+
comments.push(...result.comments);
|
|
250
|
+
total = result.total;
|
|
251
|
+
if (result.comments.length === 0 || comments.length >= total) break;
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
comments,
|
|
255
|
+
total
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
async #createComment(input) {
|
|
259
|
+
const resolved = await this.#resolveRequest(input);
|
|
260
|
+
let key = resolved.issueId;
|
|
261
|
+
if (!ISSUE_KEY_PATTERN.test(key)) try {
|
|
262
|
+
key = (await resolved.context.api.getIssue(key)).key;
|
|
263
|
+
} catch (error) {
|
|
264
|
+
if (error instanceof JiraApiError && error.status === 404) return null;
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
const comment = await resolved.context.api.createComment(key, input.body);
|
|
268
|
+
return {
|
|
269
|
+
id: comment.id,
|
|
270
|
+
url: `${resolved.context.siteUrl}/browse/${key}?focusedCommentId=${comment.id}`
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
async #updateIssue(input) {
|
|
274
|
+
const resolved = await this.#resolveRequest(input);
|
|
275
|
+
let issue;
|
|
276
|
+
try {
|
|
277
|
+
issue = await resolved.context.api.getIssue(resolved.issueId);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
if (error instanceof JiraApiError && error.status === 404) return null;
|
|
280
|
+
throw error;
|
|
281
|
+
}
|
|
282
|
+
if (currentStatusMatches(issue, input.state)) return this.#toIntakeIssue(issue, resolved.context.siteUrl);
|
|
283
|
+
const transition = resolveTransition(await resolved.context.api.listTransitions(issue.key), input.state);
|
|
284
|
+
if (!transition) return null;
|
|
285
|
+
await resolved.context.api.applyTransition(issue.key, transition.id);
|
|
286
|
+
return this.#toIntakeIssue(await resolved.context.api.getIssue(issue.key), resolved.context.siteUrl);
|
|
287
|
+
}
|
|
288
|
+
async #resolveRequest(input) {
|
|
289
|
+
const issueReference = decodeIssueReference(input.issueId);
|
|
290
|
+
const source = input.sourceId ? decodeSourceId(input.sourceId) : null;
|
|
291
|
+
const connectionId = issueReference?.connectionId ?? source?.connectionId ?? connectionIdFromConnection(input.connection);
|
|
292
|
+
const issueId = issueReference?.issueId ?? input.issueId;
|
|
293
|
+
if (connectionId) return {
|
|
294
|
+
context: await this.#connectionContextById(connectionId),
|
|
295
|
+
issueId
|
|
296
|
+
};
|
|
297
|
+
const active = await this.#activeConnections();
|
|
298
|
+
if (active.length !== 1) throw new JiraApiError("Jira issue reference must identify a connection when multiple sites are connected.", 400);
|
|
299
|
+
return {
|
|
300
|
+
context: await this.#connectionContext(active[0]),
|
|
301
|
+
issueId
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Locate an issue for a read. A connection-scoped reference resolves
|
|
306
|
+
* directly; a plain issue key (the agent tool's normal input) is looked up
|
|
307
|
+
* across every active connection so multi-site organizations can still
|
|
308
|
+
* fetch by key — the first site that knows the key wins, which is safe
|
|
309
|
+
* because Jira project-key prefixes make cross-site collisions unlikely and
|
|
310
|
+
* the tool is read-only.
|
|
311
|
+
*/
|
|
312
|
+
async #findIssue(input) {
|
|
313
|
+
const issueReference = decodeIssueReference(input.issueId);
|
|
314
|
+
const source = input.sourceId ? decodeSourceId(input.sourceId) : null;
|
|
315
|
+
const connectionId = issueReference?.connectionId ?? source?.connectionId ?? connectionIdFromConnection(input.connection);
|
|
316
|
+
const issueId = issueReference?.issueId ?? input.issueId;
|
|
317
|
+
const candidates = [];
|
|
318
|
+
if (connectionId) candidates.push(await this.#connectionContextById(connectionId));
|
|
319
|
+
else {
|
|
320
|
+
const active = await this.#activeConnections();
|
|
321
|
+
if (active.length === 0) throw new JiraApiError("Jira connection is unavailable or requires reauthentication.", 401);
|
|
322
|
+
for (const connection of active) candidates.push(await this.#connectionContext(connection));
|
|
323
|
+
}
|
|
324
|
+
let firstError;
|
|
325
|
+
for (const context of candidates) try {
|
|
326
|
+
return {
|
|
327
|
+
context,
|
|
328
|
+
issue: await context.api.getIssue(issueId)
|
|
329
|
+
};
|
|
330
|
+
} catch (error) {
|
|
331
|
+
if (error instanceof JiraApiError && error.status === 404) continue;
|
|
332
|
+
firstError ??= error;
|
|
333
|
+
}
|
|
334
|
+
if (firstError !== void 0) throw firstError;
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
#toIntakeIssue(issue, siteUrl) {
|
|
338
|
+
const { fields } = issue;
|
|
339
|
+
return {
|
|
340
|
+
id: issue.id,
|
|
341
|
+
identifier: issue.key,
|
|
342
|
+
title: fields.summary ?? issue.key,
|
|
343
|
+
url: `${siteUrl}/browse/${issue.key}`,
|
|
344
|
+
author: fields.reporter?.displayName ?? null,
|
|
345
|
+
state: fields.status?.name ?? null,
|
|
346
|
+
stateType: stateTypeFromCategory(fields.status?.statusCategory?.key),
|
|
347
|
+
priority: fields.priority?.name ?? null,
|
|
348
|
+
assignee: fields.assignee?.displayName ?? null,
|
|
349
|
+
source: fields.project?.key ?? null,
|
|
350
|
+
labels: fields.labels ?? [],
|
|
351
|
+
commentCount: null,
|
|
352
|
+
createdAt: fields.created ?? "",
|
|
353
|
+
updatedAt: fields.updated ?? ""
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
async #activeConnections() {
|
|
357
|
+
return (await this.listConnections()).filter((connection) => connection.status === "active");
|
|
358
|
+
}
|
|
359
|
+
async #connectionContextById(connectionId) {
|
|
360
|
+
const connection = (await this.#activeConnections()).find((candidate) => candidate.id === connectionId);
|
|
361
|
+
if (!connection) throw new JiraApiError("Jira connection is unavailable or requires reauthentication.", 401);
|
|
362
|
+
return this.#connectionContext(connection);
|
|
363
|
+
}
|
|
364
|
+
async #cloudId(connectionId) {
|
|
365
|
+
const cached = this.#cloudIdByConnectionId.get(connectionId);
|
|
366
|
+
if (cached) return cached;
|
|
367
|
+
const cloudId = (await this.#platformClient.request("GET", `/v2/connections/${encodeURIComponent(connectionId)}/context`)).connection_config?.cloudId;
|
|
368
|
+
if (typeof cloudId !== "string" || !UUID_PATTERN.test(cloudId)) throw new JiraApiError("Platform Jira connection context is missing a valid cloudId.", 502);
|
|
369
|
+
this.#cloudIdByConnectionId.set(connectionId, cloudId);
|
|
370
|
+
return cloudId;
|
|
371
|
+
}
|
|
372
|
+
async #connectionContext(connection) {
|
|
373
|
+
const proxyBaseUrl = `${this.#clientConfig.baseUrl.replace(/\/+$/, "")}/v2/connections/${encodeURIComponent(connection.id)}/proxy`;
|
|
374
|
+
const cloudId = await this.#cloudId(connection.id);
|
|
375
|
+
const api = new JiraApiClient({
|
|
376
|
+
baseUrl: `${proxyBaseUrl}/ex/jira/${encodeURIComponent(cloudId)}`,
|
|
377
|
+
accessToken: this.#clientConfig.accessToken,
|
|
378
|
+
...this.#clientConfig.fetchImpl ? { fetchImpl: this.#clientConfig.fetchImpl } : {}
|
|
379
|
+
});
|
|
380
|
+
let siteUrl = this.#siteUrlByConnectionId.get(connection.id);
|
|
381
|
+
if (!siteUrl) {
|
|
382
|
+
siteUrl = connection.accountLabel ? normalizeSiteUrl(connection.accountLabel) : normalizeSiteUrl((await api.getServerInfo()).baseUrl);
|
|
383
|
+
this.#siteUrlByConnectionId.set(connection.id, siteUrl);
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
connection,
|
|
387
|
+
api,
|
|
388
|
+
siteUrl
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
workers(ctx) {
|
|
392
|
+
if (!jiraReconciliationEnabled()) return [];
|
|
393
|
+
const reconcile = attachJiraIssueReconciler(this, ctx);
|
|
394
|
+
if (!reconcile) return [];
|
|
395
|
+
const intervalMs = jiraReconciliationInterval();
|
|
396
|
+
return [new IssueReconcileWorker({
|
|
397
|
+
integrationId: this.id,
|
|
398
|
+
reconcile,
|
|
399
|
+
...intervalMs ? { intervalMs } : {}
|
|
400
|
+
})];
|
|
401
|
+
}
|
|
402
|
+
routes(ctx) {
|
|
403
|
+
return buildPlatformJiraRoutes({
|
|
404
|
+
jira: this,
|
|
405
|
+
auth: ctx.auth,
|
|
406
|
+
intake: ctx.storage.intake,
|
|
407
|
+
appDbConfigured: Boolean(ctx.factoryStorage),
|
|
408
|
+
ingestFactoryIssues: attachJiraRules(this, ctx)
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
async agentTools(args) {
|
|
412
|
+
return buildPlatformJiraAgentTools({
|
|
413
|
+
requestContext: args.requestContext,
|
|
414
|
+
jira: this
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
diagnostics() {
|
|
418
|
+
return {
|
|
419
|
+
configured: true,
|
|
420
|
+
mode: "platform",
|
|
421
|
+
endpointHost: this.#endpointHost
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
function jiraConnection(connectionId) {
|
|
426
|
+
return {
|
|
427
|
+
type: "oauth",
|
|
428
|
+
accessToken: `${JIRA_CONNECTION_TOKEN_PREFIX}${connectionId}`
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
function connectionIdFromConnection(connection) {
|
|
432
|
+
if (connection.type !== "oauth" || !connection.accessToken.startsWith(JIRA_CONNECTION_TOKEN_PREFIX)) return null;
|
|
433
|
+
return connection.accessToken.slice(16) || null;
|
|
434
|
+
}
|
|
435
|
+
function encodeSourceId(connectionId, projectId) {
|
|
436
|
+
return `${JIRA_SOURCE_PREFIX}${Buffer.from(JSON.stringify({
|
|
437
|
+
connectionId,
|
|
438
|
+
projectId
|
|
439
|
+
})).toString("base64url")}`;
|
|
440
|
+
}
|
|
441
|
+
function decodeSourceId(sourceId) {
|
|
442
|
+
if (!sourceId.startsWith(JIRA_SOURCE_PREFIX)) return null;
|
|
443
|
+
try {
|
|
444
|
+
const parsed = JSON.parse(Buffer.from(sourceId.slice(13), "base64url").toString("utf8"));
|
|
445
|
+
return typeof parsed.connectionId === "string" && typeof parsed.projectId === "string" ? {
|
|
446
|
+
connectionId: parsed.connectionId,
|
|
447
|
+
projectId: parsed.projectId
|
|
448
|
+
} : null;
|
|
449
|
+
} catch {
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function encodeIssueReference(reference) {
|
|
454
|
+
return `${JIRA_ISSUE_REF_PREFIX}${Buffer.from(JSON.stringify(reference)).toString("base64url")}`;
|
|
455
|
+
}
|
|
456
|
+
function decodeIssueReference(value) {
|
|
457
|
+
if (!value.startsWith(JIRA_ISSUE_REF_PREFIX)) return null;
|
|
458
|
+
try {
|
|
459
|
+
const parsed = JSON.parse(Buffer.from(value.slice(11), "base64url").toString("utf8"));
|
|
460
|
+
if (typeof parsed.connectionId !== "string" || typeof parsed.issueId !== "string") return null;
|
|
461
|
+
return {
|
|
462
|
+
connectionId: parsed.connectionId,
|
|
463
|
+
issueId: parsed.issueId,
|
|
464
|
+
...typeof parsed.projectId === "string" ? { projectId: parsed.projectId } : {}
|
|
465
|
+
};
|
|
466
|
+
} catch {
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function groupSources(sourceIds) {
|
|
471
|
+
const groups = /* @__PURE__ */ new Map();
|
|
472
|
+
for (const sourceId of sourceIds) {
|
|
473
|
+
const source = decodeSourceId(sourceId);
|
|
474
|
+
if (!source) continue;
|
|
475
|
+
const projectIds = groups.get(source.connectionId) ?? /* @__PURE__ */ new Set();
|
|
476
|
+
projectIds.add(source.projectId);
|
|
477
|
+
groups.set(source.connectionId, projectIds);
|
|
478
|
+
}
|
|
479
|
+
return [...groups.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([connectionId, projectIds]) => ({
|
|
480
|
+
connectionId,
|
|
481
|
+
projectIds: [...projectIds].sort()
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
function encodePageCursor(cursor) {
|
|
485
|
+
return Buffer.from(JSON.stringify(cursor)).toString("base64url");
|
|
486
|
+
}
|
|
487
|
+
function decodePageCursor(cursor) {
|
|
488
|
+
if (!cursor) return { group: 0 };
|
|
489
|
+
try {
|
|
490
|
+
const parsed = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
491
|
+
if (!Number.isInteger(parsed.group) || parsed.group < 0) throw new Error();
|
|
492
|
+
return {
|
|
493
|
+
group: parsed.group,
|
|
494
|
+
...typeof parsed.jira === "string" ? { jira: parsed.jira } : {}
|
|
495
|
+
};
|
|
496
|
+
} catch {
|
|
497
|
+
throw new JiraApiError("Jira pagination cursor is invalid.", 400);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function normalizeSiteUrl(value) {
|
|
501
|
+
const candidate = /^https?:\/\//i.test(value) ? value : `https://${value}`;
|
|
502
|
+
let url;
|
|
503
|
+
try {
|
|
504
|
+
url = new URL(candidate);
|
|
505
|
+
} catch {
|
|
506
|
+
throw new JiraApiError("Jira site URL is invalid.", 502);
|
|
507
|
+
}
|
|
508
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw new JiraApiError("Jira site URL is invalid.", 502);
|
|
509
|
+
return url.origin;
|
|
510
|
+
}
|
|
511
|
+
function buildIntakeJql(projectIds, labels) {
|
|
512
|
+
const clauses = [];
|
|
513
|
+
const safeProjects = (projectIds ?? []).map((id) => id.trim()).filter((id) => /^[A-Za-z0-9_]+$/.test(id)).map((id) => /^\d+$/.test(id) ? id : `"${id}"`);
|
|
514
|
+
if (projectIds && safeProjects.length === 0) return null;
|
|
515
|
+
if (safeProjects.length > 0) clauses.push(`project IN (${safeProjects.join(", ")})`);
|
|
516
|
+
clauses.push("statusCategory != Done");
|
|
517
|
+
const safeLabels = [...new Set((labels ?? []).map((label) => label.trim().replace(/["\\]/g, "")).filter(Boolean))];
|
|
518
|
+
if (safeLabels.length > 0) clauses.push(`labels IN (${safeLabels.map((label) => `"${label}"`).join(", ")})`);
|
|
519
|
+
return `${clauses.join(" AND ")} ORDER BY updated DESC`;
|
|
520
|
+
}
|
|
521
|
+
function currentStatusMatches(issue, target) {
|
|
522
|
+
const status = issue.fields.status;
|
|
523
|
+
if (!status) return false;
|
|
524
|
+
if (target.kind === "byName") return status.name.toLowerCase() === target.name.toLowerCase();
|
|
525
|
+
if (target.stateType === "canceled") return status.statusCategory?.key === "done" && /cancel/i.test(status.name);
|
|
526
|
+
return status.statusCategory?.key === STATE_TYPE_TO_CATEGORY[target.stateType];
|
|
527
|
+
}
|
|
528
|
+
function resolveTransition(transitions, target) {
|
|
529
|
+
if (target.kind === "byName") {
|
|
530
|
+
const wanted = target.name.toLowerCase();
|
|
531
|
+
return transitions.find((transition) => transition.to?.name.toLowerCase() === wanted) ?? null;
|
|
532
|
+
}
|
|
533
|
+
if (target.stateType === "canceled") return transitions.find((transition) => transition.to?.statusCategory?.key === "done" && /cancel/i.test(transition.to.name)) ?? null;
|
|
534
|
+
const category = STATE_TYPE_TO_CATEGORY[target.stateType];
|
|
535
|
+
return transitions.find((transition) => transition.to?.statusCategory?.key === category) ?? null;
|
|
536
|
+
}
|
|
537
|
+
//#endregion
|
|
538
|
+
export { PlatformJiraIntegration, decodeIssueReference, decodeSourceId, encodeIssueReference, encodeSourceId };
|
|
539
|
+
|
|
540
|
+
//# sourceMappingURL=integration.js.map
|