@mastra/factory 0.30.0 → 0.31.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 +32 -10
- package/dist/factory.d.ts +12 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +72 -31
- package/dist/factory.js.map +1 -1
- package/dist/integrations/gitlab/api.d.ts +3 -2
- package/dist/integrations/gitlab/api.d.ts.map +1 -1
- package/dist/integrations/gitlab/api.js +12 -9
- package/dist/integrations/gitlab/api.js.map +1 -1
- package/dist/integrations/issue-reconcile-worker.d.ts +5 -0
- package/dist/integrations/issue-reconcile-worker.d.ts.map +1 -1
- package/dist/integrations/issue-reconcile-worker.js +17 -1
- package/dist/integrations/issue-reconcile-worker.js.map +1 -1
- package/dist/integrations/platform/connect/routes.d.ts +22 -13
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
- package/dist/integrations/platform/connect/routes.js +63 -64
- package/dist/integrations/platform/connect/routes.js.map +1 -1
- package/dist/integrations/platform/foundation/connect-binding.d.ts +125 -0
- package/dist/integrations/platform/foundation/connect-binding.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/connect-binding.js +252 -0
- package/dist/integrations/platform/foundation/connect-binding.js.map +1 -0
- package/dist/integrations/platform/foundation/connect-event-poller.d.ts +49 -0
- package/dist/integrations/platform/foundation/connect-event-poller.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/connect-event-poller.js +304 -0
- package/dist/integrations/platform/foundation/connect-event-poller.js.map +1 -0
- package/dist/integrations/platform/foundation/connect-events.d.ts +31 -0
- package/dist/integrations/platform/foundation/connect-events.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/connect-events.js +7 -0
- package/dist/integrations/platform/foundation/connect-events.js.map +1 -0
- package/dist/integrations/platform/foundation/index.d.ts +10 -0
- package/dist/integrations/platform/foundation/index.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/index.js +6 -0
- package/dist/integrations/platform/foundation/intake.d.ts +39 -0
- package/dist/integrations/platform/foundation/intake.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/intake.js +45 -0
- package/dist/integrations/platform/foundation/intake.js.map +1 -0
- package/dist/integrations/platform/foundation/integration.d.ts +84 -0
- package/dist/integrations/platform/foundation/integration.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/integration.js +107 -0
- package/dist/integrations/platform/foundation/integration.js.map +1 -0
- package/dist/integrations/platform/github/event-worker.d.ts +2 -2
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +4 -8
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +3 -0
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +131 -70
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/gitlab/connect-events.d.ts +22 -0
- package/dist/integrations/platform/gitlab/connect-events.d.ts.map +1 -0
- package/dist/integrations/platform/gitlab/connect-events.js +49 -0
- package/dist/integrations/platform/gitlab/connect-events.js.map +1 -0
- package/dist/integrations/platform/gitlab/integration.d.ts +24 -15
- package/dist/integrations/platform/gitlab/integration.d.ts.map +1 -1
- package/dist/integrations/platform/gitlab/integration.js +61 -26
- package/dist/integrations/platform/gitlab/integration.js.map +1 -1
- package/dist/integrations/platform/incidentio/intake.d.ts +33 -0
- package/dist/integrations/platform/incidentio/intake.d.ts.map +1 -0
- package/dist/integrations/platform/incidentio/intake.js +271 -0
- package/dist/integrations/platform/incidentio/intake.js.map +1 -0
- package/dist/integrations/platform/incidentio/integration.d.ts +11 -23
- package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -1
- package/dist/integrations/platform/incidentio/integration.js +27 -297
- package/dist/integrations/platform/incidentio/integration.js.map +1 -1
- package/dist/integrations/platform/jira/intake.d.ts +60 -0
- package/dist/integrations/platform/jira/intake.d.ts.map +1 -0
- package/dist/integrations/platform/jira/intake.js +445 -0
- package/dist/integrations/platform/jira/intake.js.map +1 -0
- package/dist/integrations/platform/jira/integration.d.ts +13 -37
- package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
- package/dist/integrations/platform/jira/integration.js +29 -468
- package/dist/integrations/platform/jira/integration.js.map +1 -1
- package/dist/integrations/platform/linear/event-worker.d.ts +2 -2
- package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/linear/event-worker.js +5 -9
- package/dist/integrations/platform/linear/event-worker.js.map +1 -1
- package/dist/integrations/platform/linear/integration.d.ts +3 -1
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
- package/dist/integrations/platform/linear/integration.js +9 -9
- package/dist/integrations/platform/linear/integration.js.map +1 -1
- package/dist/integrations/platform/logging.d.ts +6 -0
- package/dist/integrations/platform/logging.d.ts.map +1 -0
- package/dist/integrations/platform/logging.js +25 -0
- package/dist/integrations/platform/logging.js.map +1 -0
- package/dist/integrations/platform/platform-connect.d.ts +38 -0
- package/dist/integrations/platform/platform-connect.d.ts.map +1 -0
- package/dist/integrations/platform/platform-connect.js +109 -0
- package/dist/integrations/platform/platform-connect.js.map +1 -0
- package/dist/integrations/platform/vanta/integration.d.ts +12 -18
- package/dist/integrations/platform/vanta/integration.d.ts.map +1 -1
- package/dist/integrations/platform/vanta/integration.js +38 -38
- package/dist/integrations/platform/vanta/integration.js.map +1 -1
- package/dist/memory-embedder.d.ts +11 -0
- package/dist/memory-embedder.d.ts.map +1 -0
- package/dist/memory-embedder.js +19 -0
- package/dist/memory-embedder.js.map +1 -0
- package/dist/metrics/config.d.ts +1 -1
- package/dist/metrics/config.d.ts.map +1 -1
- package/dist/metrics/config.js +1 -0
- package/dist/metrics/config.js.map +1 -1
- package/dist/metrics/index.js +2 -2
- package/dist/metrics/index.js.map +1 -1
- package/dist/metrics/sandbox.d.ts +3 -3
- package/dist/metrics/sandbox.js +13 -13
- package/dist/metrics/sandbox.js.map +1 -1
- package/dist/metrics/session.d.ts +28 -0
- package/dist/metrics/session.d.ts.map +1 -0
- package/dist/metrics/session.js +76 -0
- package/dist/metrics/session.js.map +1 -0
- package/dist/routes/source-control-sessions.d.ts +5 -0
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +65 -7
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +5 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +1 -0
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts +29 -1
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +156 -23
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/public-failure-reason.js +1 -1
- package/dist/rules/public-failure-reason.js.map +1 -1
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +33 -9
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +2 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +4 -2
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/work-item-branch.d.ts +7 -1
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +9 -1
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/card-facts.d.ts.map +1 -1
- package/dist/work-items/card-facts.js +2 -2
- package/dist/work-items/card-facts.js.map +1 -1
- package/package.json +9 -9
- package/dist/integrations/platform/api-client.d.ts +0 -34
- package/dist/integrations/platform/api-client.d.ts.map +0 -1
- package/dist/integrations/platform/api-client.js +0 -186
- package/dist/integrations/platform/api-client.js.map +0 -1
- package/dist/integrations/platform/gitlab/event-worker.d.ts +0 -64
- package/dist/integrations/platform/gitlab/event-worker.d.ts.map +0 -1
- package/dist/integrations/platform/gitlab/event-worker.js +0 -304
- package/dist/integrations/platform/gitlab/event-worker.js.map +0 -1
|
@@ -1,43 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { adfToText } from "../../jira/adf.js";
|
|
3
|
-
import { JiraApiClient, JiraApiError } from "../../jira/api.js";
|
|
1
|
+
import { DEFAULT_ISSUE_RECONCILE_INTERVAL_MS } from "../../issue-reconcile-worker.js";
|
|
4
2
|
import { resolveJiraRules } from "../../jira/default-rules.js";
|
|
5
|
-
import { buildIntakeJql, unfilteredJiraScopes } from "../../jira/intake-jql.js";
|
|
6
3
|
import { attachJiraIssueReconciler } from "../../jira/issue-reconciler.js";
|
|
7
4
|
import { jiraReconciliationInterval } from "../../jira/reconciliation-config.js";
|
|
8
|
-
import {
|
|
5
|
+
import { PlatformConnectIntegration } from "../foundation/integration.js";
|
|
6
|
+
import { logPlatformBootInfo } from "../logging.js";
|
|
9
7
|
import { buildPlatformJiraAgentTools } from "./agent-tools.js";
|
|
8
|
+
import { PlatformJiraIntake, UUID_PATTERN, decodeIssueReference, decodeSourceId, encodeIssueReference, encodeSourceId } from "./intake.js";
|
|
10
9
|
import { buildPlatformJiraRoutes } from "./routes.js";
|
|
11
10
|
// 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
11
|
const PLATFORM_JIRA_PROVIDER_CONFIG_KEY = "jira";
|
|
17
|
-
|
|
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;
|
|
12
|
+
var PlatformJiraIntegration = class extends PlatformConnectIntegration {
|
|
38
13
|
#endpointHost;
|
|
39
|
-
|
|
40
|
-
#siteUrlByConnectionId = /* @__PURE__ */ new Map();
|
|
14
|
+
intake = new PlatformJiraIntake(this);
|
|
41
15
|
#projects;
|
|
42
16
|
#auth;
|
|
43
17
|
#orgIdByResourceId = /* @__PURE__ */ new Map();
|
|
@@ -46,10 +20,22 @@ var PlatformJiraIntegration = class {
|
|
|
46
20
|
return this.#rules;
|
|
47
21
|
}
|
|
48
22
|
constructor(config = {}) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
23
|
+
const rules = resolveJiraRules(config.rules);
|
|
24
|
+
const intervalMs = jiraReconciliationInterval();
|
|
25
|
+
super({
|
|
26
|
+
id: "jira",
|
|
27
|
+
providerKeys: [PLATFORM_JIRA_PROVIDER_CONFIG_KEY],
|
|
28
|
+
...config.connect ? { connect: config.connect } : {},
|
|
29
|
+
linkOrgConnectionsAtBoot: true,
|
|
30
|
+
connectProviders: [{
|
|
31
|
+
provider: "jira",
|
|
32
|
+
integrationId: PLATFORM_JIRA_PROVIDER_CONFIG_KEY
|
|
33
|
+
}],
|
|
34
|
+
...intervalMs ? { reconcileIntervalMs: intervalMs } : {},
|
|
35
|
+
reconcileDefaultIntervalMs: DEFAULT_ISSUE_RECONCILE_INTERVAL_MS
|
|
36
|
+
});
|
|
37
|
+
this.#rules = rules;
|
|
38
|
+
this.#endpointHost = new URL(this.connect.baseUrl).host;
|
|
53
39
|
}
|
|
54
40
|
initialize({ projects, auth }) {
|
|
55
41
|
this.#projects = projects;
|
|
@@ -81,339 +67,21 @@ var PlatformJiraIntegration = class {
|
|
|
81
67
|
}
|
|
82
68
|
clearCaches() {
|
|
83
69
|
this.#orgIdByResourceId.clear();
|
|
84
|
-
this
|
|
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;
|
|
70
|
+
this.intake.clearCaches();
|
|
90
71
|
}
|
|
91
72
|
async hasActiveConnections() {
|
|
92
|
-
return (await this
|
|
93
|
-
}
|
|
94
|
-
intake = {
|
|
95
|
-
bindingLabelFilters: true,
|
|
96
|
-
resolveIntakeDispatch: (input) => this.#resolveIntakeDispatch(input),
|
|
97
|
-
listSources: () => this.#listSources(),
|
|
98
|
-
listItems: (input) => this.#listItems(input),
|
|
99
|
-
listIssues: (input) => this.#listIssues(input),
|
|
100
|
-
getIssue: (input) => this.#getIssue(input),
|
|
101
|
-
createComment: (input) => this.#createComment(input),
|
|
102
|
-
updateIssue: (input) => this.#updateIssue(input)
|
|
103
|
-
};
|
|
104
|
-
async #resolveIntakeDispatch({ externalSource }) {
|
|
105
|
-
if (externalSource.type !== "issue") return null;
|
|
106
|
-
const reference = decodeIssueReference(externalSource.externalId);
|
|
107
|
-
if (!reference) return null;
|
|
108
|
-
return {
|
|
109
|
-
connection: jiraConnection(reference.connectionId),
|
|
110
|
-
...reference.projectId ? { sourceId: encodeSourceId(reference.connectionId, reference.projectId) } : {},
|
|
111
|
-
issueId: reference.issueId
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
async #listSources() {
|
|
115
|
-
const sources = [];
|
|
116
|
-
for (const connection of await this.#activeConnections()) {
|
|
117
|
-
const context = await this.#connectionContext(connection);
|
|
118
|
-
let startAt = 0;
|
|
119
|
-
for (let pageCount = 0; pageCount < PROJECT_SEARCH_MAX_PAGES; pageCount++) {
|
|
120
|
-
const page = await context.api.listProjects({ startAt });
|
|
121
|
-
for (const project of page.values) sources.push({
|
|
122
|
-
id: encodeSourceId(connection.id, project.id),
|
|
123
|
-
name: project.name,
|
|
124
|
-
type: "project",
|
|
125
|
-
metadata: {
|
|
126
|
-
key: project.key,
|
|
127
|
-
connectionId: connection.id,
|
|
128
|
-
site: new URL(context.siteUrl).host
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
if (page.isLast || page.values.length === 0) break;
|
|
132
|
-
startAt += page.values.length;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return sources;
|
|
136
|
-
}
|
|
137
|
-
async #listItems({ sourceIds, cursor }) {
|
|
138
|
-
if (sourceIds.length === 0) return {
|
|
139
|
-
items: [],
|
|
140
|
-
nextCursor: null
|
|
141
|
-
};
|
|
142
|
-
const page = await this.listActiveIssues(cursor, unfilteredJiraScopes(sourceIds));
|
|
143
|
-
return {
|
|
144
|
-
items: page.issues.map((issue) => ({
|
|
145
|
-
source: {
|
|
146
|
-
type: "issue",
|
|
147
|
-
externalId: issue.externalId,
|
|
148
|
-
url: issue.url
|
|
149
|
-
},
|
|
150
|
-
sourceId: issue.sourceId,
|
|
151
|
-
title: `${issue.identifier}: ${issue.title}`,
|
|
152
|
-
status: issue.state ?? void 0,
|
|
153
|
-
labels: issue.labels,
|
|
154
|
-
assignee: issue.assignee,
|
|
155
|
-
createdAt: issue.createdAt,
|
|
156
|
-
updatedAt: issue.updatedAt,
|
|
157
|
-
metadata: {
|
|
158
|
-
identifier: issue.identifier,
|
|
159
|
-
issueRef: issue.externalId,
|
|
160
|
-
state: issue.state,
|
|
161
|
-
stateType: issue.stateType,
|
|
162
|
-
priority: issue.priority,
|
|
163
|
-
project: issue.source,
|
|
164
|
-
site: issue.site,
|
|
165
|
-
assignee: issue.assignee,
|
|
166
|
-
assignees: issue.assignees ?? [],
|
|
167
|
-
creator: issue.author,
|
|
168
|
-
author: issue.author,
|
|
169
|
-
labels: issue.labels,
|
|
170
|
-
createdAt: issue.createdAt,
|
|
171
|
-
updatedAt: issue.updatedAt
|
|
172
|
-
}
|
|
173
|
-
})),
|
|
174
|
-
nextCursor: page.nextCursor
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
async #listIssues(input) {
|
|
178
|
-
const page = await this.listActiveIssues(input.cursor, unfilteredJiraScopes(input.sourceIds ?? []), input.labels);
|
|
179
|
-
return {
|
|
180
|
-
issues: page.issues,
|
|
181
|
-
nextCursor: page.nextCursor
|
|
182
|
-
};
|
|
73
|
+
return (await this.listConnections()).some((connection) => connection.status === "active");
|
|
183
74
|
}
|
|
184
75
|
/**
|
|
185
76
|
* One page of active issues across connections. Each scope's `projectId` is
|
|
186
77
|
* an encoded Platform source id; sources are grouped per connection and each
|
|
187
78
|
* group runs one JQL built from only that connection's projects.
|
|
188
79
|
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (grouped.length === 0) return {
|
|
192
|
-
issues: [],
|
|
193
|
-
nextCursor: null
|
|
194
|
-
};
|
|
195
|
-
const decodedCursor = decodePageCursor(cursor);
|
|
196
|
-
if (decodedCursor.group >= grouped.length) return {
|
|
197
|
-
issues: [],
|
|
198
|
-
nextCursor: null
|
|
199
|
-
};
|
|
200
|
-
for (let groupIndex = decodedCursor.group; groupIndex < grouped.length; groupIndex++) {
|
|
201
|
-
const group = grouped[groupIndex];
|
|
202
|
-
const context = await this.#connectionContextById(group.connectionId);
|
|
203
|
-
const jql = buildIntakeJql(group.scopes, labels);
|
|
204
|
-
if (jql === null) continue;
|
|
205
|
-
const page = await context.api.searchIssues({
|
|
206
|
-
jql,
|
|
207
|
-
...groupIndex === decodedCursor.group && decodedCursor.jira ? { nextPageToken: decodedCursor.jira } : {}
|
|
208
|
-
});
|
|
209
|
-
const nextCursor = page.nextPageToken ? encodePageCursor({
|
|
210
|
-
group: groupIndex,
|
|
211
|
-
jira: page.nextPageToken
|
|
212
|
-
}) : groupIndex + 1 < grouped.length ? encodePageCursor({ group: groupIndex + 1 }) : null;
|
|
213
|
-
return {
|
|
214
|
-
issues: page.issues.map((issue) => {
|
|
215
|
-
const projectId = issue.fields.project?.id ?? group.scopes[0]?.projectId ?? "";
|
|
216
|
-
return {
|
|
217
|
-
...this.#toIntakeIssue(issue, context.siteUrl),
|
|
218
|
-
sourceId: encodeSourceId(group.connectionId, projectId),
|
|
219
|
-
externalId: encodeIssueReference({
|
|
220
|
-
connectionId: group.connectionId,
|
|
221
|
-
issueId: issue.key,
|
|
222
|
-
projectId
|
|
223
|
-
}),
|
|
224
|
-
site: new URL(context.siteUrl).host
|
|
225
|
-
};
|
|
226
|
-
}),
|
|
227
|
-
nextCursor
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
issues: [],
|
|
232
|
-
nextCursor: null
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
async #getIssue(input) {
|
|
236
|
-
const { context, issue } = await this.#findIssue(input) ?? {};
|
|
237
|
-
if (!context || !issue) return null;
|
|
238
|
-
const { comments, total } = await this.#listAllComments(context.api, issue.key);
|
|
239
|
-
return {
|
|
240
|
-
...this.#toIntakeIssue(issue, context.siteUrl),
|
|
241
|
-
commentCount: total,
|
|
242
|
-
description: issue.fields.description ? adfToText(issue.fields.description) || null : null,
|
|
243
|
-
comments: comments.map((comment) => ({
|
|
244
|
-
author: comment.author?.displayName ?? null,
|
|
245
|
-
body: adfToText(comment.body),
|
|
246
|
-
createdAt: comment.created
|
|
247
|
-
}))
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
async #listAllComments(api, keyOrId) {
|
|
251
|
-
const comments = [];
|
|
252
|
-
let total = 0;
|
|
253
|
-
for (let page = 0; page < ISSUE_COMMENTS_MAX_PAGES; page++) {
|
|
254
|
-
const result = await api.listComments(keyOrId, { startAt: comments.length });
|
|
255
|
-
comments.push(...result.comments);
|
|
256
|
-
total = result.total;
|
|
257
|
-
if (result.comments.length === 0 || comments.length >= total) break;
|
|
258
|
-
}
|
|
259
|
-
return {
|
|
260
|
-
comments,
|
|
261
|
-
total
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
async #createComment(input) {
|
|
265
|
-
const resolved = await this.#resolveRequest(input);
|
|
266
|
-
let key = resolved.issueId;
|
|
267
|
-
if (!ISSUE_KEY_PATTERN.test(key)) try {
|
|
268
|
-
key = (await resolved.context.api.getIssue(key)).key;
|
|
269
|
-
} catch (error) {
|
|
270
|
-
if (error instanceof JiraApiError && error.status === 404) return null;
|
|
271
|
-
throw error;
|
|
272
|
-
}
|
|
273
|
-
let comment;
|
|
274
|
-
try {
|
|
275
|
-
comment = await resolved.context.api.createComment(key, input.body);
|
|
276
|
-
} catch (error) {
|
|
277
|
-
if (error instanceof JiraApiError && error.status === 404) return null;
|
|
278
|
-
throw error;
|
|
279
|
-
}
|
|
280
|
-
return {
|
|
281
|
-
id: comment.id,
|
|
282
|
-
url: `${resolved.context.siteUrl}/browse/${key}?focusedCommentId=${comment.id}`
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
async #updateIssue(input) {
|
|
286
|
-
const resolved = await this.#resolveRequest(input);
|
|
287
|
-
let issue;
|
|
288
|
-
try {
|
|
289
|
-
issue = await resolved.context.api.getIssue(resolved.issueId);
|
|
290
|
-
} catch (error) {
|
|
291
|
-
if (error instanceof JiraApiError && error.status === 404) return null;
|
|
292
|
-
throw error;
|
|
293
|
-
}
|
|
294
|
-
if (currentStatusMatches(issue, input.state)) return this.#toIntakeIssue(issue, resolved.context.siteUrl);
|
|
295
|
-
const transition = resolveTransition(await resolved.context.api.listTransitions(issue.key), input.state);
|
|
296
|
-
if (!transition) return null;
|
|
297
|
-
await resolved.context.api.applyTransition(issue.key, transition.id);
|
|
298
|
-
return this.#toIntakeIssue(await resolved.context.api.getIssue(issue.key), resolved.context.siteUrl);
|
|
299
|
-
}
|
|
300
|
-
async #resolveRequest(input) {
|
|
301
|
-
const issueReference = decodeIssueReference(input.issueId);
|
|
302
|
-
const source = input.sourceId ? decodeSourceId(input.sourceId) : null;
|
|
303
|
-
const connectionId = issueReference?.connectionId ?? source?.connectionId ?? connectionIdFromConnection(input.connection);
|
|
304
|
-
const issueId = issueReference?.issueId ?? input.issueId;
|
|
305
|
-
if (connectionId) return {
|
|
306
|
-
context: await this.#connectionContextById(connectionId),
|
|
307
|
-
issueId
|
|
308
|
-
};
|
|
309
|
-
const active = await this.#activeConnections();
|
|
310
|
-
if (active.length !== 1) throw new JiraApiError("Jira issue reference must identify a connection when multiple sites are connected.", 400);
|
|
311
|
-
return {
|
|
312
|
-
context: await this.#connectionContext(active[0]),
|
|
313
|
-
issueId
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Locate an issue for a read. A connection-scoped reference resolves
|
|
318
|
-
* directly; a plain issue key (the agent tool's normal input) is looked up
|
|
319
|
-
* across every active connection so multi-site organizations can still
|
|
320
|
-
* fetch by key — the first site that knows the key wins, which is safe
|
|
321
|
-
* because Jira project-key prefixes make cross-site collisions unlikely and
|
|
322
|
-
* the tool is read-only.
|
|
323
|
-
*/
|
|
324
|
-
async #findIssue(input) {
|
|
325
|
-
const issueReference = decodeIssueReference(input.issueId);
|
|
326
|
-
const source = input.sourceId ? decodeSourceId(input.sourceId) : null;
|
|
327
|
-
if (issueReference && source && (issueReference.connectionId !== source.connectionId || issueReference.projectId !== void 0 && issueReference.projectId !== source.projectId)) return null;
|
|
328
|
-
const connectionId = issueReference?.connectionId ?? source?.connectionId ?? connectionIdFromConnection(input.connection);
|
|
329
|
-
const issueId = issueReference?.issueId ?? input.issueId;
|
|
330
|
-
const projectId = issueReference?.projectId ?? source?.projectId;
|
|
331
|
-
const candidates = [];
|
|
332
|
-
if (connectionId) candidates.push(await this.#connectionContextById(connectionId));
|
|
333
|
-
else {
|
|
334
|
-
const active = await this.#activeConnections();
|
|
335
|
-
if (active.length === 0) throw new JiraApiError("Jira connection is unavailable or requires reauthentication.", 401);
|
|
336
|
-
for (const connection of active) candidates.push(await this.#connectionContext(connection));
|
|
337
|
-
}
|
|
338
|
-
let firstError;
|
|
339
|
-
for (const context of candidates) try {
|
|
340
|
-
const issue = await context.api.getIssue(issueId);
|
|
341
|
-
if (projectId && issue.fields.project?.id !== projectId) return null;
|
|
342
|
-
return {
|
|
343
|
-
context,
|
|
344
|
-
issue
|
|
345
|
-
};
|
|
346
|
-
} catch (error) {
|
|
347
|
-
if (error instanceof JiraApiError && error.status === 404) continue;
|
|
348
|
-
firstError ??= error;
|
|
349
|
-
}
|
|
350
|
-
if (firstError !== void 0) throw firstError;
|
|
351
|
-
return null;
|
|
80
|
+
listActiveIssues(cursor, scopes = [], labels) {
|
|
81
|
+
return this.intake.listActiveIssues(cursor, scopes, labels);
|
|
352
82
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
return {
|
|
356
|
-
id: issue.id,
|
|
357
|
-
identifier: issue.key,
|
|
358
|
-
title: fields.summary ?? issue.key,
|
|
359
|
-
url: `${siteUrl}/browse/${issue.key}`,
|
|
360
|
-
author: fields.reporter?.displayName ?? null,
|
|
361
|
-
state: fields.status?.name ?? null,
|
|
362
|
-
stateType: stateTypeFromCategory(fields.status?.statusCategory?.key),
|
|
363
|
-
priority: fields.priority?.name ?? null,
|
|
364
|
-
assignee: fields.assignee?.displayName ?? null,
|
|
365
|
-
source: fields.project?.key ?? null,
|
|
366
|
-
labels: fields.labels ?? [],
|
|
367
|
-
commentCount: null,
|
|
368
|
-
createdAt: fields.created ?? "",
|
|
369
|
-
updatedAt: fields.updated ?? ""
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
async #activeConnections() {
|
|
373
|
-
return (await this.listConnections()).filter((connection) => connection.status === "active");
|
|
374
|
-
}
|
|
375
|
-
async #connectionContextById(connectionId) {
|
|
376
|
-
const connection = (await this.#activeConnections()).find((candidate) => candidate.id === connectionId);
|
|
377
|
-
if (!connection) throw new JiraApiError("Jira connection is unavailable or requires reauthentication.", 401);
|
|
378
|
-
return this.#connectionContext(connection);
|
|
379
|
-
}
|
|
380
|
-
async #cloudId(connectionId) {
|
|
381
|
-
const cached = this.#cloudIdByConnectionId.get(connectionId);
|
|
382
|
-
if (cached) return cached;
|
|
383
|
-
const cloudId = (await this.#platformClient.request("GET", `/v2/connections/${encodeURIComponent(connectionId)}/context`)).connection_config?.cloudId;
|
|
384
|
-
if (typeof cloudId !== "string" || !UUID_PATTERN.test(cloudId)) throw new JiraApiError("Platform Jira connection context is missing a valid cloudId.", 502);
|
|
385
|
-
this.#cloudIdByConnectionId.set(connectionId, cloudId);
|
|
386
|
-
return cloudId;
|
|
387
|
-
}
|
|
388
|
-
async #connectionContext(connection) {
|
|
389
|
-
const proxyBaseUrl = `${this.#clientConfig.baseUrl.replace(/\/+$/, "")}/v2/connections/${encodeURIComponent(connection.id)}/proxy`;
|
|
390
|
-
const cloudId = await this.#cloudId(connection.id);
|
|
391
|
-
const api = new JiraApiClient({
|
|
392
|
-
baseUrl: `${proxyBaseUrl}/ex/jira/${encodeURIComponent(cloudId)}`,
|
|
393
|
-
accessToken: this.#clientConfig.accessToken,
|
|
394
|
-
...this.#clientConfig.projectId ? { projectId: this.#clientConfig.projectId } : {},
|
|
395
|
-
...this.#clientConfig.fetchImpl ? { fetchImpl: this.#clientConfig.fetchImpl } : {}
|
|
396
|
-
});
|
|
397
|
-
let siteUrl = this.#siteUrlByConnectionId.get(connection.id);
|
|
398
|
-
if (!siteUrl) {
|
|
399
|
-
siteUrl = connection.accountLabel ? normalizeSiteUrl(connection.accountLabel) : normalizeSiteUrl((await api.getServerInfo()).baseUrl);
|
|
400
|
-
this.#siteUrlByConnectionId.set(connection.id, siteUrl);
|
|
401
|
-
}
|
|
402
|
-
return {
|
|
403
|
-
connection,
|
|
404
|
-
api,
|
|
405
|
-
siteUrl
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
workers(ctx) {
|
|
409
|
-
const reconcile = attachJiraIssueReconciler(this, ctx);
|
|
410
|
-
if (!reconcile) return [];
|
|
411
|
-
const intervalMs = jiraReconciliationInterval();
|
|
412
|
-
return [new IssueReconcileWorker({
|
|
413
|
-
integrationId: this.id,
|
|
414
|
-
reconcile,
|
|
415
|
-
...intervalMs ? { intervalMs } : {}
|
|
416
|
-
})];
|
|
83
|
+
reconcile(ctx) {
|
|
84
|
+
return attachJiraIssueReconciler(this, ctx) ?? null;
|
|
417
85
|
}
|
|
418
86
|
routes(ctx) {
|
|
419
87
|
return buildPlatformJiraRoutes({
|
|
@@ -432,118 +100,11 @@ var PlatformJiraIntegration = class {
|
|
|
432
100
|
}
|
|
433
101
|
diagnostics() {
|
|
434
102
|
return {
|
|
435
|
-
|
|
436
|
-
mode: "platform",
|
|
103
|
+
...super.diagnostics(),
|
|
437
104
|
endpointHost: this.#endpointHost
|
|
438
105
|
};
|
|
439
106
|
}
|
|
440
107
|
};
|
|
441
|
-
function jiraConnection(connectionId) {
|
|
442
|
-
return {
|
|
443
|
-
type: "oauth",
|
|
444
|
-
accessToken: `${JIRA_CONNECTION_TOKEN_PREFIX}${connectionId}`
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
function connectionIdFromConnection(connection) {
|
|
448
|
-
if (connection.type !== "oauth" || !connection.accessToken.startsWith(JIRA_CONNECTION_TOKEN_PREFIX)) return null;
|
|
449
|
-
return connection.accessToken.slice(16) || null;
|
|
450
|
-
}
|
|
451
|
-
function encodeSourceId(connectionId, projectId) {
|
|
452
|
-
return `${JIRA_SOURCE_PREFIX}${Buffer.from(JSON.stringify({
|
|
453
|
-
connectionId,
|
|
454
|
-
projectId
|
|
455
|
-
})).toString("base64url")}`;
|
|
456
|
-
}
|
|
457
|
-
function decodeSourceId(sourceId) {
|
|
458
|
-
if (!sourceId.startsWith(JIRA_SOURCE_PREFIX)) return null;
|
|
459
|
-
try {
|
|
460
|
-
const parsed = JSON.parse(Buffer.from(sourceId.slice(13), "base64url").toString("utf8"));
|
|
461
|
-
return typeof parsed.connectionId === "string" && typeof parsed.projectId === "string" ? {
|
|
462
|
-
connectionId: parsed.connectionId,
|
|
463
|
-
projectId: parsed.projectId
|
|
464
|
-
} : null;
|
|
465
|
-
} catch {
|
|
466
|
-
return null;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
function encodeIssueReference(reference) {
|
|
470
|
-
return `${JIRA_ISSUE_REF_PREFIX}${Buffer.from(JSON.stringify(reference)).toString("base64url")}`;
|
|
471
|
-
}
|
|
472
|
-
function decodeIssueReference(value) {
|
|
473
|
-
if (!value.startsWith(JIRA_ISSUE_REF_PREFIX)) return null;
|
|
474
|
-
try {
|
|
475
|
-
const parsed = JSON.parse(Buffer.from(value.slice(11), "base64url").toString("utf8"));
|
|
476
|
-
if (typeof parsed.connectionId !== "string" || typeof parsed.issueId !== "string") return null;
|
|
477
|
-
return {
|
|
478
|
-
connectionId: parsed.connectionId,
|
|
479
|
-
issueId: parsed.issueId,
|
|
480
|
-
...typeof parsed.projectId === "string" ? { projectId: parsed.projectId } : {}
|
|
481
|
-
};
|
|
482
|
-
} catch {
|
|
483
|
-
return null;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
/** A Platform source scope: `projectId` is the encoded source id, decoded per connection here. */
|
|
487
|
-
function groupSources(scopes) {
|
|
488
|
-
const groups = /* @__PURE__ */ new Map();
|
|
489
|
-
for (const scope of scopes) {
|
|
490
|
-
const source = decodeSourceId(scope.projectId);
|
|
491
|
-
if (!source) continue;
|
|
492
|
-
const projects = groups.get(source.connectionId) ?? /* @__PURE__ */ new Map();
|
|
493
|
-
if (!projects.has(source.projectId)) projects.set(source.projectId, {
|
|
494
|
-
...scope,
|
|
495
|
-
projectId: source.projectId
|
|
496
|
-
});
|
|
497
|
-
groups.set(source.connectionId, projects);
|
|
498
|
-
}
|
|
499
|
-
return [...groups.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([connectionId, projects]) => ({
|
|
500
|
-
connectionId,
|
|
501
|
-
scopes: [...projects.values()].sort((left, right) => left.projectId.localeCompare(right.projectId))
|
|
502
|
-
}));
|
|
503
|
-
}
|
|
504
|
-
function encodePageCursor(cursor) {
|
|
505
|
-
return Buffer.from(JSON.stringify(cursor)).toString("base64url");
|
|
506
|
-
}
|
|
507
|
-
function decodePageCursor(cursor) {
|
|
508
|
-
if (!cursor) return { group: 0 };
|
|
509
|
-
try {
|
|
510
|
-
const parsed = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
511
|
-
if (!Number.isInteger(parsed.group) || parsed.group < 0) throw new Error();
|
|
512
|
-
return {
|
|
513
|
-
group: parsed.group,
|
|
514
|
-
...typeof parsed.jira === "string" ? { jira: parsed.jira } : {}
|
|
515
|
-
};
|
|
516
|
-
} catch {
|
|
517
|
-
throw new JiraApiError("Jira pagination cursor is invalid.", 400);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
function normalizeSiteUrl(value) {
|
|
521
|
-
const candidate = /^https?:\/\//i.test(value) ? value : `https://${value}`;
|
|
522
|
-
let url;
|
|
523
|
-
try {
|
|
524
|
-
url = new URL(candidate);
|
|
525
|
-
} catch {
|
|
526
|
-
throw new JiraApiError("Jira site URL is invalid.", 502);
|
|
527
|
-
}
|
|
528
|
-
if (url.protocol !== "http:" && url.protocol !== "https:") throw new JiraApiError("Jira site URL is invalid.", 502);
|
|
529
|
-
return url.origin;
|
|
530
|
-
}
|
|
531
|
-
function currentStatusMatches(issue, target) {
|
|
532
|
-
const status = issue.fields.status;
|
|
533
|
-
if (!status) return false;
|
|
534
|
-
if (target.kind === "byName") return status.name.toLowerCase() === target.name.toLowerCase();
|
|
535
|
-
if (target.stateType === "canceled") return status.statusCategory?.key === "done" && /cancel/i.test(status.name);
|
|
536
|
-
return status.statusCategory?.key === STATE_TYPE_TO_CATEGORY[target.stateType];
|
|
537
|
-
}
|
|
538
|
-
function resolveTransition(transitions, target) {
|
|
539
|
-
if (target.kind === "byName") {
|
|
540
|
-
const wanted = target.name.toLowerCase();
|
|
541
|
-
return transitions.find((transition) => transition.to?.name.toLowerCase() === wanted) ?? null;
|
|
542
|
-
}
|
|
543
|
-
if (target.stateType === "canceled") return transitions.find((transition) => transition.to?.statusCategory?.key === "done" && /cancel/i.test(transition.to.name)) ?? null;
|
|
544
|
-
const category = STATE_TYPE_TO_CATEGORY[target.stateType];
|
|
545
|
-
return transitions.find((transition) => transition.to?.statusCategory?.key === category) ?? null;
|
|
546
|
-
}
|
|
547
108
|
export { PlatformJiraIntegration, decodeIssueReference, decodeSourceId, encodeIssueReference, encodeSourceId };
|
|
548
109
|
|
|
549
110
|
//# sourceMappingURL=integration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.js","names":[],"sources":["../../../../src/integrations/platform/jira/integration.ts"],"sourcesContent":["import type { RequestContext } from '@mastra/core/request-context';\nimport type { ApiRoute } from '@mastra/core/server';\nimport type { MastraWorker } from '@mastra/core/worker';\n\nimport type { IntegrationConnection } from '../../../capabilities/connection.js';\nimport type {\n CreateIntakeCommentInput,\n CreatedIntakeComment,\n GetIntakeIssueInput,\n Intake,\n IntakeIssue,\n IntakeIssueDetail,\n IntakeItemPage,\n IntakeSource,\n ListIntakeIssuesInput,\n ListIntakeItemsInput,\n ResolveIntakeDispatchInput,\n ResolvedIntakeDispatch,\n UpdateIntakeIssueInput,\n} from '../../../capabilities/intake.js';\nimport type { RouteAuth } from '../../../routes/route.js';\nimport type { FactoryProjectsStorage } from '../../../storage/domains/projects/base.js';\nimport type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../../base.js';\nimport { IssueReconcileWorker } from '../../issue-reconcile-worker.js';\nimport { adfToText } from '../../jira/adf.js';\nimport type { JiraComment, JiraIssue, JiraTransition } from '../../jira/api.js';\nimport { JiraApiClient, JiraApiError } from '../../jira/api.js';\nimport type { JiraEventRules, JiraRuleOverrides } from '../../jira/default-rules.js';\nimport { resolveJiraRules } from '../../jira/default-rules.js';\nimport { buildIntakeJql, unfilteredJiraScopes } from '../../jira/intake-jql.js';\nimport type { JiraIntakeScope } from '../../jira/intake-jql.js';\nimport { attachJiraIssueReconciler } from '../../jira/issue-reconciler.js';\nimport { jiraReconciliationInterval } from '../../jira/reconciliation-config.js';\nimport { logPlatformBootInfo, PlatformApiClient, platformApiClientConfigFromEnv } from '../api-client.js';\nimport type { PlatformApiClientConfig } from '../api-client.js';\nimport { buildPlatformJiraAgentTools } from './agent-tools.js';\nimport { buildPlatformJiraRoutes } from './routes.js';\n\ninterface PlatformIntegrationConnection {\n id: string;\n integrationId: string;\n status: 'active' | 'needs_reauth';\n accountLabel: string | null;\n}\n\ninterface JiraConnectionContext {\n connection: PlatformIntegrationConnection;\n api: JiraApiClient;\n siteUrl: string;\n}\n\ninterface PlatformConnectionContextResponse {\n connection_config: Record<string, unknown> | null;\n metadata: Record<string, unknown> | null;\n}\n\ninterface JiraIssueReference {\n connectionId: string;\n issueId: string;\n projectId?: string;\n}\n\ninterface JiraPageCursor {\n group: number;\n jira?: string;\n}\n\nconst ISSUE_COMMENTS_MAX_PAGES = 20;\n\n/** Hard stop for project pagination so a misbehaving `isLast` can't loop forever. */\nconst PROJECT_SEARCH_MAX_PAGES = 50;\nconst ISSUE_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]*-\\d+$/;\nconst PLATFORM_JIRA_PROVIDER_CONFIG_KEY = 'jira';\nconst UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nconst JIRA_CONNECTION_TOKEN_PREFIX = 'jira-connection:';\nconst JIRA_ISSUE_REF_PREFIX = 'jira-issue:';\nconst JIRA_SOURCE_PREFIX = 'jira-project:';\n\nconst STATE_TYPE_TO_CATEGORY: Record<'unstarted' | 'started' | 'completed', string> = {\n unstarted: 'new',\n started: 'indeterminate',\n completed: 'done',\n};\n\nfunction stateTypeFromCategory(key: string | undefined): string | null {\n switch (key) {\n case 'new':\n return 'unstarted';\n case 'indeterminate':\n return 'started';\n case 'done':\n return 'completed';\n default:\n return null;\n }\n}\n\nexport interface PlatformJiraIntegrationConfig {\n clientConfig?: PlatformApiClientConfig;\n /** Per-event replacements; omitted events retain defaults, null disables. */\n rules?: JiraRuleOverrides;\n}\n\nexport class PlatformJiraIntegration implements FactoryIntegration {\n readonly id = 'jira';\n readonly #clientConfig: PlatformApiClientConfig;\n readonly #platformClient: PlatformApiClient;\n readonly #endpointHost: string;\n readonly #cloudIdByConnectionId = new Map<string, string>();\n readonly #siteUrlByConnectionId = new Map<string, string>();\n #projects: FactoryProjectsStorage | undefined;\n #auth: RouteAuth | undefined;\n readonly #orgIdByResourceId = new Map<string, string | null>();\n\n readonly #rules: JiraEventRules;\n\n get rules(): JiraEventRules {\n return this.#rules;\n }\n\n constructor(config: PlatformJiraIntegrationConfig = {}) {\n this.#rules = resolveJiraRules(config.rules);\n this.#clientConfig = config.clientConfig ?? platformApiClientConfigFromEnv();\n this.#platformClient = new PlatformApiClient(this.#clientConfig);\n this.#endpointHost = new URL(this.#clientConfig.baseUrl).host;\n }\n\n initialize({ projects, auth }: { projects: FactoryProjectsStorage; auth: RouteAuth }): void {\n this.#projects = projects;\n this.#auth = auth;\n logPlatformBootInfo('Platform Jira integration initialized', { endpointHost: this.#endpointHost });\n }\n\n get projects(): FactoryProjectsStorage {\n if (!this.#projects)\n throw new Error('PlatformJiraIntegration is not initialized — the factory binds storage during prepare().');\n return this.#projects;\n }\n\n get authEnabled(): boolean {\n return this.#auth?.enabled() ?? false;\n }\n\n async resolveOrgId(resourceId: string): Promise<string | null> {\n const cached = this.#orgIdByResourceId.get(resourceId);\n if (cached !== undefined) return cached;\n if (!UUID_PATTERN.test(resourceId)) {\n this.#orgIdByResourceId.set(resourceId, null);\n return null;\n }\n try {\n await this.projects.ensureReady();\n const project = await this.projects.getById({ id: resourceId });\n const orgId = project?.orgId ?? null;\n this.#orgIdByResourceId.set(resourceId, orgId);\n return orgId;\n } catch {\n return null;\n }\n }\n\n clearCaches(): void {\n this.#orgIdByResourceId.clear();\n this.#cloudIdByConnectionId.clear();\n this.#siteUrlByConnectionId.clear();\n }\n\n async listConnections(): Promise<PlatformIntegrationConnection[]> {\n const providerKey = encodeURIComponent(PLATFORM_JIRA_PROVIDER_CONFIG_KEY);\n const result = await this.#platformClient.request<{ connections: PlatformIntegrationConnection[] }>(\n 'GET',\n `/v2/connections?providerKey=${providerKey}`,\n );\n return result.connections;\n }\n\n async hasActiveConnections(): Promise<boolean> {\n return (await this.#activeConnections()).length > 0;\n }\n\n readonly intake: Intake = {\n bindingLabelFilters: true,\n resolveIntakeDispatch: input => this.#resolveIntakeDispatch(input),\n listSources: () => this.#listSources(),\n listItems: input => this.#listItems(input),\n listIssues: input => this.#listIssues(input),\n getIssue: input => this.#getIssue(input),\n createComment: input => this.#createComment(input),\n updateIssue: input => this.#updateIssue(input),\n };\n\n async #resolveIntakeDispatch({ externalSource }: ResolveIntakeDispatchInput): Promise<ResolvedIntakeDispatch | null> {\n if (externalSource.type !== 'issue') return null;\n const reference = decodeIssueReference(externalSource.externalId);\n if (!reference) return null;\n return {\n connection: jiraConnection(reference.connectionId),\n ...(reference.projectId ? { sourceId: encodeSourceId(reference.connectionId, reference.projectId) } : {}),\n issueId: reference.issueId,\n };\n }\n\n async #listSources(): Promise<IntakeSource[]> {\n const sources: IntakeSource[] = [];\n for (const connection of await this.#activeConnections()) {\n const context = await this.#connectionContext(connection);\n let startAt = 0;\n for (let pageCount = 0; pageCount < PROJECT_SEARCH_MAX_PAGES; pageCount++) {\n const page = await context.api.listProjects({ startAt });\n for (const project of page.values) {\n sources.push({\n id: encodeSourceId(connection.id, project.id),\n name: project.name,\n type: 'project',\n metadata: {\n key: project.key,\n connectionId: connection.id,\n site: new URL(context.siteUrl).host,\n },\n });\n }\n if (page.isLast || page.values.length === 0) break;\n startAt += page.values.length;\n }\n }\n return sources;\n }\n\n async #listItems({ sourceIds, cursor }: ListIntakeItemsInput): Promise<IntakeItemPage> {\n if (sourceIds.length === 0) return { items: [], nextCursor: null };\n const page = await this.listActiveIssues(cursor, unfilteredJiraScopes(sourceIds));\n return {\n items: page.issues.map(issue => ({\n source: { type: 'issue', externalId: issue.externalId, url: issue.url },\n sourceId: issue.sourceId,\n title: `${issue.identifier}: ${issue.title}`,\n status: issue.state ?? undefined,\n labels: issue.labels,\n assignee: issue.assignee,\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n metadata: {\n identifier: issue.identifier,\n issueRef: issue.externalId,\n state: issue.state,\n stateType: issue.stateType,\n priority: issue.priority,\n project: issue.source,\n site: issue.site,\n assignee: issue.assignee,\n assignees: issue.assignees ?? [],\n creator: issue.author,\n author: issue.author,\n labels: issue.labels,\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n },\n })),\n nextCursor: page.nextCursor,\n };\n }\n\n async #listIssues(input: ListIntakeIssuesInput): Promise<{ issues: IntakeIssue[]; nextCursor: string | null }> {\n const page = await this.listActiveIssues(input.cursor, unfilteredJiraScopes(input.sourceIds ?? []), input.labels);\n return { issues: page.issues, nextCursor: page.nextCursor };\n }\n\n /**\n * One page of active issues across connections. Each scope's `projectId` is\n * an encoded Platform source id; sources are grouped per connection and each\n * group runs one JQL built from only that connection's projects.\n */\n async listActiveIssues(\n cursor?: string,\n scopes: JiraIntakeScope[] = [],\n labels?: string[],\n ): Promise<{\n issues: Array<IntakeIssue & { sourceId: string; externalId: string; site: string }>;\n nextCursor: string | null;\n }> {\n const grouped = groupSources(scopes);\n if (grouped.length === 0) return { issues: [], nextCursor: null };\n const decodedCursor = decodePageCursor(cursor);\n if (decodedCursor.group >= grouped.length) return { issues: [], nextCursor: null };\n\n for (let groupIndex = decodedCursor.group; groupIndex < grouped.length; groupIndex++) {\n const group = grouped[groupIndex]!;\n const context = await this.#connectionContextById(group.connectionId);\n const jql = buildIntakeJql(group.scopes, labels);\n if (jql === null) continue;\n const page = await context.api.searchIssues({\n jql,\n ...(groupIndex === decodedCursor.group && decodedCursor.jira ? { nextPageToken: decodedCursor.jira } : {}),\n });\n const nextCursor = page.nextPageToken\n ? encodePageCursor({ group: groupIndex, jira: page.nextPageToken })\n : groupIndex + 1 < grouped.length\n ? encodePageCursor({ group: groupIndex + 1 })\n : null;\n return {\n issues: page.issues.map(issue => {\n const projectId = issue.fields.project?.id ?? group.scopes[0]?.projectId ?? '';\n return {\n ...this.#toIntakeIssue(issue, context.siteUrl),\n sourceId: encodeSourceId(group.connectionId, projectId),\n externalId: encodeIssueReference({ connectionId: group.connectionId, issueId: issue.key, projectId }),\n site: new URL(context.siteUrl).host,\n };\n }),\n nextCursor,\n };\n }\n return { issues: [], nextCursor: null };\n }\n\n async #getIssue(input: GetIntakeIssueInput): Promise<IntakeIssueDetail | null> {\n const { context, issue } = (await this.#findIssue(input)) ?? {};\n if (!context || !issue) return null;\n const { comments, total } = await this.#listAllComments(context.api, issue.key);\n return {\n ...this.#toIntakeIssue(issue, context.siteUrl),\n commentCount: total,\n description: issue.fields.description ? adfToText(issue.fields.description) || null : null,\n comments: comments.map(comment => ({\n author: comment.author?.displayName ?? null,\n body: adfToText(comment.body),\n createdAt: comment.created,\n })),\n };\n }\n\n async #listAllComments(api: JiraApiClient, keyOrId: string): Promise<{ comments: JiraComment[]; total: number }> {\n const comments: JiraComment[] = [];\n let total = 0;\n for (let page = 0; page < ISSUE_COMMENTS_MAX_PAGES; page++) {\n const result = await api.listComments(keyOrId, { startAt: comments.length });\n comments.push(...result.comments);\n total = result.total;\n if (result.comments.length === 0 || comments.length >= total) break;\n }\n return { comments, total };\n }\n\n async #createComment(input: CreateIntakeCommentInput): Promise<CreatedIntakeComment | null> {\n const resolved = await this.#resolveRequest(input);\n let key = resolved.issueId;\n if (!ISSUE_KEY_PATTERN.test(key)) {\n try {\n key = (await resolved.context.api.getIssue(key)).key;\n } catch (error) {\n if (error instanceof JiraApiError && error.status === 404) return null;\n throw error;\n }\n }\n let comment;\n try {\n comment = await resolved.context.api.createComment(key, input.body);\n } catch (error) {\n if (error instanceof JiraApiError && error.status === 404) return null;\n throw error;\n }\n return {\n id: comment.id,\n url: `${resolved.context.siteUrl}/browse/${key}?focusedCommentId=${comment.id}`,\n };\n }\n\n async #updateIssue(input: UpdateIntakeIssueInput): Promise<IntakeIssue | null> {\n const resolved = await this.#resolveRequest(input);\n let issue: JiraIssue;\n try {\n issue = await resolved.context.api.getIssue(resolved.issueId);\n } catch (error) {\n if (error instanceof JiraApiError && error.status === 404) return null;\n throw error;\n }\n if (currentStatusMatches(issue, input.state)) return this.#toIntakeIssue(issue, resolved.context.siteUrl);\n const transitions = await resolved.context.api.listTransitions(issue.key);\n const transition = resolveTransition(transitions, input.state);\n if (!transition) return null;\n await resolved.context.api.applyTransition(issue.key, transition.id);\n return this.#toIntakeIssue(await resolved.context.api.getIssue(issue.key), resolved.context.siteUrl);\n }\n\n async #resolveRequest(input: GetIntakeIssueInput): Promise<{ context: JiraConnectionContext; issueId: string }> {\n const issueReference = decodeIssueReference(input.issueId);\n const source = input.sourceId ? decodeSourceId(input.sourceId) : null;\n const connectionId =\n issueReference?.connectionId ?? source?.connectionId ?? connectionIdFromConnection(input.connection);\n const issueId = issueReference?.issueId ?? input.issueId;\n if (connectionId) return { context: await this.#connectionContextById(connectionId), issueId };\n const active = await this.#activeConnections();\n if (active.length !== 1) {\n throw new JiraApiError('Jira issue reference must identify a connection when multiple sites are connected.', 400);\n }\n return { context: await this.#connectionContext(active[0]!), issueId };\n }\n\n /**\n * Locate an issue for a read. A connection-scoped reference resolves\n * directly; a plain issue key (the agent tool's normal input) is looked up\n * across every active connection so multi-site organizations can still\n * fetch by key — the first site that knows the key wins, which is safe\n * because Jira project-key prefixes make cross-site collisions unlikely and\n * the tool is read-only.\n */\n async #findIssue(input: GetIntakeIssueInput): Promise<{ context: JiraConnectionContext; issue: JiraIssue } | null> {\n const issueReference = decodeIssueReference(input.issueId);\n const source = input.sourceId ? decodeSourceId(input.sourceId) : null;\n // A reference that names a different connection or project than the source scope\n // cannot widen that scope.\n if (\n issueReference &&\n source &&\n (issueReference.connectionId !== source.connectionId ||\n (issueReference.projectId !== undefined && issueReference.projectId !== source.projectId))\n ) {\n return null;\n }\n const connectionId =\n issueReference?.connectionId ?? source?.connectionId ?? connectionIdFromConnection(input.connection);\n const issueId = issueReference?.issueId ?? input.issueId;\n const projectId = issueReference?.projectId ?? source?.projectId;\n\n const candidates: JiraConnectionContext[] = [];\n if (connectionId) {\n candidates.push(await this.#connectionContextById(connectionId));\n } else {\n const active = await this.#activeConnections();\n if (active.length === 0) {\n throw new JiraApiError('Jira connection is unavailable or requires reauthentication.', 401);\n }\n for (const connection of active) candidates.push(await this.#connectionContext(connection));\n }\n\n let firstError: unknown;\n for (const context of candidates) {\n try {\n const issue = await context.api.getIssue(issueId);\n // A reference scoped to a project only resolves issues that live in that project.\n if (projectId && issue.fields.project?.id !== projectId) return null;\n return { context, issue };\n } catch (error) {\n if (error instanceof JiraApiError && error.status === 404) continue;\n firstError ??= error;\n }\n }\n // Not found anywhere. If a site failed for a non-404 reason, surface that\n // failure instead of a silent \"not found\".\n if (firstError !== undefined) throw firstError;\n return null;\n }\n\n #toIntakeIssue(issue: JiraIssue, siteUrl: string): IntakeIssue {\n const { fields } = issue;\n return {\n id: issue.id,\n identifier: issue.key,\n title: fields.summary ?? issue.key,\n url: `${siteUrl}/browse/${issue.key}`,\n author: fields.reporter?.displayName ?? null,\n state: fields.status?.name ?? null,\n stateType: stateTypeFromCategory(fields.status?.statusCategory?.key),\n priority: fields.priority?.name ?? null,\n assignee: fields.assignee?.displayName ?? null,\n source: fields.project?.key ?? null,\n labels: fields.labels ?? [],\n commentCount: null,\n createdAt: fields.created ?? '',\n updatedAt: fields.updated ?? '',\n };\n }\n\n async #activeConnections(): Promise<PlatformIntegrationConnection[]> {\n return (await this.listConnections()).filter(connection => connection.status === 'active');\n }\n\n async #connectionContextById(connectionId: string): Promise<JiraConnectionContext> {\n const connection = (await this.#activeConnections()).find(candidate => candidate.id === connectionId);\n if (!connection) {\n throw new JiraApiError('Jira connection is unavailable or requires reauthentication.', 401);\n }\n return this.#connectionContext(connection);\n }\n\n async #cloudId(connectionId: string): Promise<string> {\n const cached = this.#cloudIdByConnectionId.get(connectionId);\n if (cached) return cached;\n\n const context = await this.#platformClient.request<PlatformConnectionContextResponse>(\n 'GET',\n `/v2/connections/${encodeURIComponent(connectionId)}/context`,\n );\n const cloudId = context.connection_config?.cloudId;\n if (typeof cloudId !== 'string' || !UUID_PATTERN.test(cloudId)) {\n throw new JiraApiError('Platform Jira connection context is missing a valid cloudId.', 502);\n }\n this.#cloudIdByConnectionId.set(connectionId, cloudId);\n return cloudId;\n }\n\n async #connectionContext(connection: PlatformIntegrationConnection): Promise<JiraConnectionContext> {\n const proxyBaseUrl = `${this.#clientConfig.baseUrl.replace(/\\/+$/, '')}/v2/connections/${encodeURIComponent(\n connection.id,\n )}/proxy`;\n const cloudId = await this.#cloudId(connection.id);\n const api = new JiraApiClient({\n baseUrl: `${proxyBaseUrl}/ex/jira/${encodeURIComponent(cloudId)}`,\n accessToken: this.#clientConfig.accessToken,\n ...(this.#clientConfig.projectId ? { projectId: this.#clientConfig.projectId } : {}),\n ...(this.#clientConfig.fetchImpl ? { fetchImpl: this.#clientConfig.fetchImpl } : {}),\n });\n let siteUrl = this.#siteUrlByConnectionId.get(connection.id);\n if (!siteUrl) {\n siteUrl = connection.accountLabel\n ? normalizeSiteUrl(connection.accountLabel)\n : normalizeSiteUrl((await api.getServerInfo()).baseUrl);\n this.#siteUrlByConnectionId.set(connection.id, siteUrl);\n }\n return { connection, api, siteUrl };\n }\n\n workers(ctx: IntegrationContext): MastraWorker[] {\n const reconcile = attachJiraIssueReconciler(this, ctx);\n if (!reconcile) return [];\n const intervalMs = jiraReconciliationInterval();\n return [\n new IssueReconcileWorker({\n integrationId: this.id,\n reconcile,\n ...(intervalMs ? { intervalMs } : {}),\n }),\n ];\n }\n\n routes(ctx: IntegrationContext): ApiRoute[] {\n return buildPlatformJiraRoutes({\n jira: this,\n auth: ctx.auth,\n intake: ctx.storage.intake,\n workItems: ctx.runtime?.workItems,\n appDbConfigured: Boolean(ctx.factoryStorage),\n });\n }\n\n async agentTools(args: { requestContext: RequestContext }): Promise<IntegrationTools> {\n return buildPlatformJiraAgentTools({ requestContext: args.requestContext, jira: this });\n }\n\n diagnostics(): Record<string, unknown> {\n return { configured: true, mode: 'platform', endpointHost: this.#endpointHost };\n }\n}\n\nfunction jiraConnection(connectionId: string): IntegrationConnection {\n return { type: 'oauth', accessToken: `${JIRA_CONNECTION_TOKEN_PREFIX}${connectionId}` };\n}\n\nfunction connectionIdFromConnection(connection: IntegrationConnection): string | null {\n if (connection.type !== 'oauth' || !connection.accessToken.startsWith(JIRA_CONNECTION_TOKEN_PREFIX)) return null;\n return connection.accessToken.slice(JIRA_CONNECTION_TOKEN_PREFIX.length) || null;\n}\n\nexport function encodeSourceId(connectionId: string, projectId: string): string {\n return `${JIRA_SOURCE_PREFIX}${Buffer.from(JSON.stringify({ connectionId, projectId })).toString('base64url')}`;\n}\n\nexport function decodeSourceId(sourceId: string): { connectionId: string; projectId: string } | null {\n if (!sourceId.startsWith(JIRA_SOURCE_PREFIX)) return null;\n try {\n const parsed = JSON.parse(\n Buffer.from(sourceId.slice(JIRA_SOURCE_PREFIX.length), 'base64url').toString('utf8'),\n ) as Record<string, unknown>;\n return typeof parsed.connectionId === 'string' && typeof parsed.projectId === 'string'\n ? { connectionId: parsed.connectionId, projectId: parsed.projectId }\n : null;\n } catch {\n return null;\n }\n}\n\nexport function encodeIssueReference(reference: JiraIssueReference): string {\n return `${JIRA_ISSUE_REF_PREFIX}${Buffer.from(JSON.stringify(reference)).toString('base64url')}`;\n}\n\nexport function decodeIssueReference(value: string): JiraIssueReference | null {\n if (!value.startsWith(JIRA_ISSUE_REF_PREFIX)) return null;\n try {\n const parsed = JSON.parse(\n Buffer.from(value.slice(JIRA_ISSUE_REF_PREFIX.length), 'base64url').toString('utf8'),\n ) as Record<string, unknown>;\n if (typeof parsed.connectionId !== 'string' || typeof parsed.issueId !== 'string') return null;\n return {\n connectionId: parsed.connectionId,\n issueId: parsed.issueId,\n ...(typeof parsed.projectId === 'string' ? { projectId: parsed.projectId } : {}),\n };\n } catch {\n return null;\n }\n}\n\n/** A Platform source scope: `projectId` is the encoded source id, decoded per connection here. */\nfunction groupSources(scopes: JiraIntakeScope[]): Array<{ connectionId: string; scopes: JiraIntakeScope[] }> {\n const groups = new Map<string, Map<string, JiraIntakeScope>>();\n for (const scope of scopes) {\n const source = decodeSourceId(scope.projectId);\n if (!source) continue;\n const projects = groups.get(source.connectionId) ?? new Map<string, JiraIntakeScope>();\n if (!projects.has(source.projectId)) projects.set(source.projectId, { ...scope, projectId: source.projectId });\n groups.set(source.connectionId, projects);\n }\n return [...groups.entries()]\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([connectionId, projects]) => ({\n connectionId,\n scopes: [...projects.values()].sort((left, right) => left.projectId.localeCompare(right.projectId)),\n }));\n}\n\nfunction encodePageCursor(cursor: JiraPageCursor): string {\n return Buffer.from(JSON.stringify(cursor)).toString('base64url');\n}\n\nfunction decodePageCursor(cursor: string | undefined): JiraPageCursor {\n if (!cursor) return { group: 0 };\n try {\n const parsed = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8')) as Record<string, unknown>;\n if (!Number.isInteger(parsed.group) || (parsed.group as number) < 0) throw new Error();\n return {\n group: parsed.group as number,\n ...(typeof parsed.jira === 'string' ? { jira: parsed.jira } : {}),\n };\n } catch {\n throw new JiraApiError('Jira pagination cursor is invalid.', 400);\n }\n}\n\nfunction normalizeSiteUrl(value: string): string {\n const candidate = /^https?:\\/\\//i.test(value) ? value : `https://${value}`;\n // `accountLabel` is free-form Platform data — an unparsable value must\n // surface as the classified 502 the routes already handle, not a raw\n // TypeError escaping the connection context.\n let url: URL;\n try {\n url = new URL(candidate);\n } catch {\n throw new JiraApiError('Jira site URL is invalid.', 502);\n }\n if (url.protocol !== 'http:' && url.protocol !== 'https:') throw new JiraApiError('Jira site URL is invalid.', 502);\n return url.origin;\n}\n\nfunction currentStatusMatches(issue: JiraIssue, target: UpdateIntakeIssueInput['state']): boolean {\n const status = issue.fields.status;\n if (!status) return false;\n if (target.kind === 'byName') return status.name.toLowerCase() === target.name.toLowerCase();\n if (target.stateType === 'canceled') return status.statusCategory?.key === 'done' && /cancel/i.test(status.name);\n return status.statusCategory?.key === STATE_TYPE_TO_CATEGORY[target.stateType];\n}\n\nfunction resolveTransition(\n transitions: JiraTransition[],\n target: UpdateIntakeIssueInput['state'],\n): JiraTransition | null {\n if (target.kind === 'byName') {\n const wanted = target.name.toLowerCase();\n return transitions.find(transition => transition.to?.name.toLowerCase() === wanted) ?? null;\n }\n if (target.stateType === 'canceled') {\n return (\n transitions.find(\n transition => transition.to?.statusCategory?.key === 'done' && /cancel/i.test(transition.to.name),\n ) ?? null\n );\n }\n const category = STATE_TYPE_TO_CATEGORY[target.stateType];\n return transitions.find(transition => transition.to?.statusCategory?.key === category) ?? null;\n}\n"],"mappings":";;;;;;;;;;;AAmEA,MAAM,2BAA2B;;AAGjC,MAAM,2BAA2B;AACjC,MAAM,oBAAoB;AAC1B,MAAM,oCAAoC;AAC1C,MAAM,eAAe;AACrB,MAAM,+BAA+B;AACrC,MAAM,wBAAwB;AAC9B,MAAM,qBAAqB;AAE3B,MAAM,yBAAgF;CACpF,WAAW;CACX,SAAS;CACT,WAAW;AACb;AAEA,SAAS,sBAAsB,KAAwC;CACrE,QAAQ,KAAR;EACE,KAAK,OACH,OAAO;EACT,KAAK,iBACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAQA,IAAa,0BAAb,MAAmE;CACjE,KAAc;CACd;CACA;CACA;CACA,yCAAkC,IAAI,IAAoB;CAC1D,yCAAkC,IAAI,IAAoB;CAC1D;CACA;CACA,qCAA8B,IAAI,IAA2B;CAE7D;CAEA,IAAI,QAAwB;EAC1B,OA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AU,KAAK,OAAO,IAAI;CAC/G,OAAO,OAAO,gBAAgB,QAAQ,uBAAuB,OAAO;AACtE;AAEA,SAAS,kBACP,aACA,QACuB;CACvB,IAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,SAAS,OAAO,KAAK,YAAY;EACvC,OAAO,YAAY,MAAK,eAAc,WAAW,IAAI,KAAK,YAAY,MAAM,MAAM,KAAK;CACzF;CACA,IAAI,OAAO,cAAc,YACvB,OACE,YAAY,MACV,eAAc,WAAW,IAAI,gBAAgB,QAAQ,UAAU,UAAU,KAAK,WAAW,GAAG,IAAI,CAClG,KAAK;CAGT,MAAM,WAAW,uBAAuB,OAAO;CAC/C,OAAO,YAAY,MAAK,eAAc,WAAW,IAAI,gBAAgB,QAAQ,QAAQ,KAAK;AAC5F"}
|
|
1
|
+
{"version":3,"file":"integration.js","names":[],"sources":["../../../../src/integrations/platform/jira/integration.ts"],"sourcesContent":["import type { RequestContext } from '@mastra/core/request-context';\nimport type { ApiRoute } from '@mastra/core/server';\n\nimport type { RouteAuth } from '../../../routes/route.js';\nimport type { FactoryProjectsStorage } from '../../../storage/domains/projects/base.js';\nimport type { IntegrationContext, IntegrationTools } from '../../base.js';\nimport { DEFAULT_ISSUE_RECONCILE_INTERVAL_MS } from '../../issue-reconcile-worker.js';\nimport type { IssueReconciler } from '../../issue-reconciler.js';\nimport type { JiraEventRules, JiraRuleOverrides } from '../../jira/default-rules.js';\nimport { resolveJiraRules } from '../../jira/default-rules.js';\nimport type { JiraIntakeScope } from '../../jira/intake-jql.js';\nimport { attachJiraIssueReconciler } from '../../jira/issue-reconciler.js';\nimport { jiraReconciliationInterval } from '../../jira/reconciliation-config.js';\nimport { PlatformConnectIntegration } from '../foundation/integration.js';\nimport { logPlatformBootInfo } from '../logging.js';\nimport type { PlatformConnectOption } from '../platform-connect.js';\nimport { buildPlatformJiraAgentTools } from './agent-tools.js';\nimport { PlatformJiraIntake, UUID_PATTERN } from './intake.js';\nimport type { JiraActiveIssuePage } from './intake.js';\nimport { buildPlatformJiraRoutes } from './routes.js';\n\nexport { decodeIssueReference, decodeSourceId, encodeIssueReference, encodeSourceId } from './intake.js';\n\nconst PLATFORM_JIRA_PROVIDER_CONFIG_KEY = 'jira';\n\nexport interface PlatformJiraIntegrationConfig {\n /** The Connect client, or options to build one; defaults to the platform environment. */\n connect?: PlatformConnectOption;\n /** Per-event replacements; omitted events retain defaults, null disables. */\n rules?: JiraRuleOverrides;\n}\n\nexport class PlatformJiraIntegration extends PlatformConnectIntegration {\n readonly #endpointHost: string;\n readonly intake = new PlatformJiraIntake(this);\n #projects: FactoryProjectsStorage | undefined;\n #auth: RouteAuth | undefined;\n readonly #orgIdByResourceId = new Map<string, string | null>();\n\n readonly #rules: JiraEventRules;\n\n get rules(): JiraEventRules {\n return this.#rules;\n }\n\n constructor(config: PlatformJiraIntegrationConfig = {}) {\n const rules = resolveJiraRules(config.rules);\n const intervalMs = jiraReconciliationInterval();\n super({\n id: 'jira',\n providerKeys: [PLATFORM_JIRA_PROVIDER_CONFIG_KEY],\n ...(config.connect ? { connect: config.connect } : {}),\n linkOrgConnectionsAtBoot: true,\n connectProviders: [{ provider: 'jira', integrationId: PLATFORM_JIRA_PROVIDER_CONFIG_KEY }],\n ...(intervalMs ? { reconcileIntervalMs: intervalMs } : {}),\n reconcileDefaultIntervalMs: DEFAULT_ISSUE_RECONCILE_INTERVAL_MS,\n });\n this.#rules = rules;\n this.#endpointHost = new URL(this.connect.baseUrl).host;\n }\n\n initialize({ projects, auth }: { projects: FactoryProjectsStorage; auth: RouteAuth }): void {\n this.#projects = projects;\n this.#auth = auth;\n logPlatformBootInfo('Platform Jira integration initialized', { endpointHost: this.#endpointHost });\n }\n\n get projects(): FactoryProjectsStorage {\n if (!this.#projects)\n throw new Error('PlatformJiraIntegration is not initialized — the factory binds storage during prepare().');\n return this.#projects;\n }\n\n get authEnabled(): boolean {\n return this.#auth?.enabled() ?? false;\n }\n\n async resolveOrgId(resourceId: string): Promise<string | null> {\n const cached = this.#orgIdByResourceId.get(resourceId);\n if (cached !== undefined) return cached;\n if (!UUID_PATTERN.test(resourceId)) {\n this.#orgIdByResourceId.set(resourceId, null);\n return null;\n }\n try {\n await this.projects.ensureReady();\n const project = await this.projects.getById({ id: resourceId });\n const orgId = project?.orgId ?? null;\n this.#orgIdByResourceId.set(resourceId, orgId);\n return orgId;\n } catch {\n return null;\n }\n }\n\n clearCaches(): void {\n this.#orgIdByResourceId.clear();\n this.intake.clearCaches();\n }\n\n async hasActiveConnections(): Promise<boolean> {\n return (await this.listConnections()).some(connection => connection.status === 'active');\n }\n\n /**\n * One page of active issues across connections. Each scope's `projectId` is\n * an encoded Platform source id; sources are grouped per connection and each\n * group runs one JQL built from only that connection's projects.\n */\n listActiveIssues(cursor?: string, scopes: JiraIntakeScope[] = [], labels?: string[]): Promise<JiraActiveIssuePage> {\n return this.intake.listActiveIssues(cursor, scopes, labels);\n }\n\n protected override reconcile(ctx: IntegrationContext): IssueReconciler | null {\n return attachJiraIssueReconciler(this, ctx) ?? null;\n }\n\n routes(ctx: IntegrationContext): ApiRoute[] {\n return buildPlatformJiraRoutes({\n jira: this,\n auth: ctx.auth,\n intake: ctx.storage.intake,\n workItems: ctx.runtime?.workItems,\n appDbConfigured: Boolean(ctx.factoryStorage),\n });\n }\n\n async agentTools(args: { requestContext: RequestContext }): Promise<IntegrationTools> {\n return buildPlatformJiraAgentTools({ requestContext: args.requestContext, jira: this });\n }\n\n override diagnostics(): Record<string, unknown> {\n return { ...super.diagnostics(), endpointHost: this.#endpointHost };\n }\n}\n"],"mappings":";;;;;;;;;;AAuBA,MAAM,oCAAoC;AAS1C,IAAa,0BAAb,cAA6C,2BAA2B;CACtE;CACA,SAAkB,IAAI,mBAAmB,IAAI;CAC7C;CACA;CACA,qCAA8B,IAAI,IAA2B;CAE7D;CAEA,IAAI,QAAwB;EAC1B,OAAO,KAAK;CACd;CAEA,YAAY,SAAwC,CAAC,GAAG;EACtD,MAAM,QAAQ,iBAAiB,OA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