@mastra/factory 0.30.0-alpha.4 → 0.31.0-alpha.0

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.
Files changed (148) hide show
  1. package/README.md +32 -10
  2. package/dist/factory.d.ts +12 -1
  3. package/dist/factory.d.ts.map +1 -1
  4. package/dist/factory.js +72 -31
  5. package/dist/factory.js.map +1 -1
  6. package/dist/integrations/gitlab/api.d.ts +3 -2
  7. package/dist/integrations/gitlab/api.d.ts.map +1 -1
  8. package/dist/integrations/gitlab/api.js +12 -9
  9. package/dist/integrations/gitlab/api.js.map +1 -1
  10. package/dist/integrations/issue-reconcile-worker.d.ts +5 -0
  11. package/dist/integrations/issue-reconcile-worker.d.ts.map +1 -1
  12. package/dist/integrations/issue-reconcile-worker.js +17 -1
  13. package/dist/integrations/issue-reconcile-worker.js.map +1 -1
  14. package/dist/integrations/platform/connect/routes.d.ts +22 -13
  15. package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
  16. package/dist/integrations/platform/connect/routes.js +63 -64
  17. package/dist/integrations/platform/connect/routes.js.map +1 -1
  18. package/dist/integrations/platform/foundation/connect-binding.d.ts +125 -0
  19. package/dist/integrations/platform/foundation/connect-binding.d.ts.map +1 -0
  20. package/dist/integrations/platform/foundation/connect-binding.js +252 -0
  21. package/dist/integrations/platform/foundation/connect-binding.js.map +1 -0
  22. package/dist/integrations/platform/foundation/connect-event-poller.d.ts +49 -0
  23. package/dist/integrations/platform/foundation/connect-event-poller.d.ts.map +1 -0
  24. package/dist/integrations/platform/foundation/connect-event-poller.js +304 -0
  25. package/dist/integrations/platform/foundation/connect-event-poller.js.map +1 -0
  26. package/dist/integrations/platform/foundation/connect-events.d.ts +31 -0
  27. package/dist/integrations/platform/foundation/connect-events.d.ts.map +1 -0
  28. package/dist/integrations/platform/foundation/connect-events.js +7 -0
  29. package/dist/integrations/platform/foundation/connect-events.js.map +1 -0
  30. package/dist/integrations/platform/foundation/index.d.ts +10 -0
  31. package/dist/integrations/platform/foundation/index.d.ts.map +1 -0
  32. package/dist/integrations/platform/foundation/index.js +6 -0
  33. package/dist/integrations/platform/foundation/intake.d.ts +39 -0
  34. package/dist/integrations/platform/foundation/intake.d.ts.map +1 -0
  35. package/dist/integrations/platform/foundation/intake.js +45 -0
  36. package/dist/integrations/platform/foundation/intake.js.map +1 -0
  37. package/dist/integrations/platform/foundation/integration.d.ts +84 -0
  38. package/dist/integrations/platform/foundation/integration.d.ts.map +1 -0
  39. package/dist/integrations/platform/foundation/integration.js +107 -0
  40. package/dist/integrations/platform/foundation/integration.js.map +1 -0
  41. package/dist/integrations/platform/github/event-worker.d.ts +2 -2
  42. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  43. package/dist/integrations/platform/github/event-worker.js +4 -8
  44. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  45. package/dist/integrations/platform/github/integration.d.ts +3 -0
  46. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  47. package/dist/integrations/platform/github/integration.js +131 -70
  48. package/dist/integrations/platform/github/integration.js.map +1 -1
  49. package/dist/integrations/platform/gitlab/connect-events.d.ts +22 -0
  50. package/dist/integrations/platform/gitlab/connect-events.d.ts.map +1 -0
  51. package/dist/integrations/platform/gitlab/connect-events.js +49 -0
  52. package/dist/integrations/platform/gitlab/connect-events.js.map +1 -0
  53. package/dist/integrations/platform/gitlab/integration.d.ts +24 -15
  54. package/dist/integrations/platform/gitlab/integration.d.ts.map +1 -1
  55. package/dist/integrations/platform/gitlab/integration.js +61 -26
  56. package/dist/integrations/platform/gitlab/integration.js.map +1 -1
  57. package/dist/integrations/platform/incidentio/intake.d.ts +33 -0
  58. package/dist/integrations/platform/incidentio/intake.d.ts.map +1 -0
  59. package/dist/integrations/platform/incidentio/intake.js +271 -0
  60. package/dist/integrations/platform/incidentio/intake.js.map +1 -0
  61. package/dist/integrations/platform/incidentio/integration.d.ts +11 -23
  62. package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -1
  63. package/dist/integrations/platform/incidentio/integration.js +27 -297
  64. package/dist/integrations/platform/incidentio/integration.js.map +1 -1
  65. package/dist/integrations/platform/jira/intake.d.ts +60 -0
  66. package/dist/integrations/platform/jira/intake.d.ts.map +1 -0
  67. package/dist/integrations/platform/jira/intake.js +445 -0
  68. package/dist/integrations/platform/jira/intake.js.map +1 -0
  69. package/dist/integrations/platform/jira/integration.d.ts +13 -37
  70. package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
  71. package/dist/integrations/platform/jira/integration.js +29 -468
  72. package/dist/integrations/platform/jira/integration.js.map +1 -1
  73. package/dist/integrations/platform/linear/event-worker.d.ts +2 -2
  74. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
  75. package/dist/integrations/platform/linear/event-worker.js +5 -9
  76. package/dist/integrations/platform/linear/event-worker.js.map +1 -1
  77. package/dist/integrations/platform/linear/integration.d.ts +3 -1
  78. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  79. package/dist/integrations/platform/linear/integration.js +9 -9
  80. package/dist/integrations/platform/linear/integration.js.map +1 -1
  81. package/dist/integrations/platform/logging.d.ts +6 -0
  82. package/dist/integrations/platform/logging.d.ts.map +1 -0
  83. package/dist/integrations/platform/logging.js +25 -0
  84. package/dist/integrations/platform/logging.js.map +1 -0
  85. package/dist/integrations/platform/platform-connect.d.ts +38 -0
  86. package/dist/integrations/platform/platform-connect.d.ts.map +1 -0
  87. package/dist/integrations/platform/platform-connect.js +109 -0
  88. package/dist/integrations/platform/platform-connect.js.map +1 -0
  89. package/dist/integrations/platform/vanta/integration.d.ts +12 -18
  90. package/dist/integrations/platform/vanta/integration.d.ts.map +1 -1
  91. package/dist/integrations/platform/vanta/integration.js +38 -38
  92. package/dist/integrations/platform/vanta/integration.js.map +1 -1
  93. package/dist/memory-embedder.d.ts +11 -0
  94. package/dist/memory-embedder.d.ts.map +1 -0
  95. package/dist/memory-embedder.js +19 -0
  96. package/dist/memory-embedder.js.map +1 -0
  97. package/dist/metrics/config.d.ts +1 -1
  98. package/dist/metrics/config.d.ts.map +1 -1
  99. package/dist/metrics/config.js +1 -0
  100. package/dist/metrics/config.js.map +1 -1
  101. package/dist/metrics/index.js +2 -2
  102. package/dist/metrics/index.js.map +1 -1
  103. package/dist/metrics/sandbox.d.ts +3 -3
  104. package/dist/metrics/sandbox.js +13 -13
  105. package/dist/metrics/sandbox.js.map +1 -1
  106. package/dist/metrics/session.d.ts +28 -0
  107. package/dist/metrics/session.d.ts.map +1 -0
  108. package/dist/metrics/session.js +76 -0
  109. package/dist/metrics/session.js.map +1 -0
  110. package/dist/routes/source-control-sessions.d.ts +5 -0
  111. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  112. package/dist/routes/source-control-sessions.js +65 -7
  113. package/dist/routes/source-control-sessions.js.map +1 -1
  114. package/dist/routes/surface.d.ts +5 -0
  115. package/dist/routes/surface.d.ts.map +1 -1
  116. package/dist/routes/surface.js +1 -0
  117. package/dist/routes/surface.js.map +1 -1
  118. package/dist/rules/dispatcher.d.ts.map +1 -1
  119. package/dist/rules/dispatcher.js.map +1 -1
  120. package/dist/rules/processor.d.ts +29 -1
  121. package/dist/rules/processor.d.ts.map +1 -1
  122. package/dist/rules/processor.js +156 -23
  123. package/dist/rules/processor.js.map +1 -1
  124. package/dist/rules/public-failure-reason.js +1 -1
  125. package/dist/rules/public-failure-reason.js.map +1 -1
  126. package/dist/rules/transition-service.d.ts.map +1 -1
  127. package/dist/rules/transition-service.js +33 -9
  128. package/dist/rules/transition-service.js.map +1 -1
  129. package/dist/storage/domains/work-items/base.d.ts +2 -0
  130. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  131. package/dist/storage/domains/work-items/base.js +4 -2
  132. package/dist/storage/domains/work-items/base.js.map +1 -1
  133. package/dist/work-item-branch.d.ts +7 -1
  134. package/dist/work-item-branch.d.ts.map +1 -1
  135. package/dist/work-item-branch.js +9 -1
  136. package/dist/work-item-branch.js.map +1 -1
  137. package/dist/work-items/card-facts.d.ts.map +1 -1
  138. package/dist/work-items/card-facts.js +2 -2
  139. package/dist/work-items/card-facts.js.map +1 -1
  140. package/package.json +13 -13
  141. package/dist/integrations/platform/api-client.d.ts +0 -34
  142. package/dist/integrations/platform/api-client.d.ts.map +0 -1
  143. package/dist/integrations/platform/api-client.js +0 -186
  144. package/dist/integrations/platform/api-client.js.map +0 -1
  145. package/dist/integrations/platform/gitlab/event-worker.d.ts +0 -64
  146. package/dist/integrations/platform/gitlab/event-worker.d.ts.map +0 -1
  147. package/dist/integrations/platform/gitlab/event-worker.js +0 -304
  148. package/dist/integrations/platform/gitlab/event-worker.js.map +0 -1
@@ -0,0 +1,445 @@
1
+ import { adfToText } from "../../jira/adf.js";
2
+ import { JiraApiClient, JiraApiError } from "../../jira/api.js";
3
+ import { buildIntakeJql, unfilteredJiraScopes } from "../../jira/intake-jql.js";
4
+ import { PlatformIntakeCapability } from "../foundation/intake.js";
5
+ import { CONNECT_PROXY_TOKEN } from "../platform-connect.js";
6
+ // src/integrations/platform/jira/intake.ts
7
+ const ISSUE_COMMENTS_MAX_PAGES = 20;
8
+ /** Hard stop for project pagination so a misbehaving `isLast` can't loop forever. */
9
+ const PROJECT_SEARCH_MAX_PAGES = 50;
10
+ const ISSUE_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]*-\d+$/;
11
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
12
+ const JIRA_CONNECTION_TOKEN_PREFIX = "jira-connection:";
13
+ const JIRA_ISSUE_REF_PREFIX = "jira-issue:";
14
+ const JIRA_SOURCE_PREFIX = "jira-project:";
15
+ const STATE_TYPE_TO_CATEGORY = {
16
+ unstarted: "new",
17
+ started: "indeterminate",
18
+ completed: "done"
19
+ };
20
+ function stateTypeFromCategory(key) {
21
+ switch (key) {
22
+ case "new": return "unstarted";
23
+ case "indeterminate": return "started";
24
+ case "done": return "completed";
25
+ default: return null;
26
+ }
27
+ }
28
+ /** The Platform Jira intake: Jira projects as sources, reached through each connection's proxy. */
29
+ var PlatformJiraIntake = class extends PlatformIntakeCapability {
30
+ bindingLabelFilters = true;
31
+ #jira;
32
+ #cloudIdByConnectionId = /* @__PURE__ */ new Map();
33
+ #siteUrlByConnectionId = /* @__PURE__ */ new Map();
34
+ constructor(jira) {
35
+ super(jira, JIRA_CONNECTION_TOKEN_PREFIX);
36
+ this.#jira = jira;
37
+ }
38
+ clearCaches() {
39
+ this.#cloudIdByConnectionId.clear();
40
+ this.#siteUrlByConnectionId.clear();
41
+ }
42
+ async resolveIntakeDispatch({ externalSource }) {
43
+ if (externalSource.type !== "issue") return null;
44
+ const reference = decodeIssueReference(externalSource.externalId);
45
+ if (!reference) return null;
46
+ return {
47
+ connection: this.connectionCredential(reference.connectionId),
48
+ ...reference.projectId ? { sourceId: encodeSourceId(reference.connectionId, reference.projectId) } : {},
49
+ issueId: reference.issueId
50
+ };
51
+ }
52
+ async listSources(_input) {
53
+ const sources = [];
54
+ for (const connection of await this.#activeConnections()) {
55
+ const context = await this.#connectionContext(connection);
56
+ let startAt = 0;
57
+ for (let pageCount = 0; pageCount < PROJECT_SEARCH_MAX_PAGES; pageCount++) {
58
+ const page = await context.api.listProjects({ startAt });
59
+ for (const project of page.values) sources.push({
60
+ id: encodeSourceId(connection.id, project.id),
61
+ name: project.name,
62
+ type: "project",
63
+ metadata: {
64
+ key: project.key,
65
+ connectionId: connection.id,
66
+ site: new URL(context.siteUrl).host
67
+ }
68
+ });
69
+ if (page.isLast || page.values.length === 0) break;
70
+ startAt += page.values.length;
71
+ }
72
+ }
73
+ return sources;
74
+ }
75
+ async listItems({ sourceIds, cursor }) {
76
+ if (sourceIds.length === 0) return {
77
+ items: [],
78
+ nextCursor: null
79
+ };
80
+ const page = await this.#jira.listActiveIssues(cursor, unfilteredJiraScopes(sourceIds));
81
+ return {
82
+ items: page.issues.map((issue) => ({
83
+ source: {
84
+ type: "issue",
85
+ externalId: issue.externalId,
86
+ url: issue.url
87
+ },
88
+ sourceId: issue.sourceId,
89
+ title: `${issue.identifier}: ${issue.title}`,
90
+ status: issue.state ?? void 0,
91
+ labels: issue.labels,
92
+ assignee: issue.assignee,
93
+ createdAt: issue.createdAt,
94
+ updatedAt: issue.updatedAt,
95
+ metadata: {
96
+ identifier: issue.identifier,
97
+ issueRef: issue.externalId,
98
+ state: issue.state,
99
+ stateType: issue.stateType,
100
+ priority: issue.priority,
101
+ project: issue.source,
102
+ site: issue.site,
103
+ assignee: issue.assignee,
104
+ assignees: issue.assignees ?? [],
105
+ creator: issue.author,
106
+ author: issue.author,
107
+ labels: issue.labels,
108
+ createdAt: issue.createdAt,
109
+ updatedAt: issue.updatedAt
110
+ }
111
+ })),
112
+ nextCursor: page.nextCursor
113
+ };
114
+ }
115
+ async listIssues(input) {
116
+ const page = await this.#jira.listActiveIssues(input.cursor, unfilteredJiraScopes(input.sourceIds ?? []), input.labels);
117
+ return {
118
+ issues: page.issues,
119
+ nextCursor: page.nextCursor
120
+ };
121
+ }
122
+ /**
123
+ * One page of active issues across connections. Each scope's `projectId` is
124
+ * an encoded Platform source id; sources are grouped per connection and each
125
+ * group runs one JQL built from only that connection's projects.
126
+ */
127
+ async listActiveIssues(cursor, scopes = [], labels) {
128
+ const grouped = groupSources(scopes);
129
+ if (grouped.length === 0) return {
130
+ issues: [],
131
+ nextCursor: null
132
+ };
133
+ const decodedCursor = decodePageCursor(cursor);
134
+ if (decodedCursor.group >= grouped.length) return {
135
+ issues: [],
136
+ nextCursor: null
137
+ };
138
+ for (let groupIndex = decodedCursor.group; groupIndex < grouped.length; groupIndex++) {
139
+ const group = grouped[groupIndex];
140
+ const context = await this.#connectionContextById(group.connectionId);
141
+ const jql = buildIntakeJql(group.scopes, labels);
142
+ if (jql === null) continue;
143
+ const page = await context.api.searchIssues({
144
+ jql,
145
+ ...groupIndex === decodedCursor.group && decodedCursor.jira ? { nextPageToken: decodedCursor.jira } : {}
146
+ });
147
+ const nextCursor = page.nextPageToken ? encodePageCursor({
148
+ group: groupIndex,
149
+ jira: page.nextPageToken
150
+ }) : groupIndex + 1 < grouped.length ? encodePageCursor({ group: groupIndex + 1 }) : null;
151
+ return {
152
+ issues: page.issues.map((issue) => {
153
+ const projectId = issue.fields.project?.id ?? group.scopes[0]?.projectId ?? "";
154
+ return {
155
+ ...this.#toIntakeIssue(issue, context.siteUrl),
156
+ sourceId: encodeSourceId(group.connectionId, projectId),
157
+ externalId: encodeIssueReference({
158
+ connectionId: group.connectionId,
159
+ issueId: issue.key,
160
+ projectId
161
+ }),
162
+ site: new URL(context.siteUrl).host
163
+ };
164
+ }),
165
+ nextCursor
166
+ };
167
+ }
168
+ return {
169
+ issues: [],
170
+ nextCursor: null
171
+ };
172
+ }
173
+ async getIssue(input) {
174
+ const { context, issue } = await this.#findIssue(input) ?? {};
175
+ if (!context || !issue) return null;
176
+ const { comments, total } = await this.#listAllComments(context.api, issue.key);
177
+ return {
178
+ ...this.#toIntakeIssue(issue, context.siteUrl),
179
+ commentCount: total,
180
+ description: issue.fields.description ? adfToText(issue.fields.description) || null : null,
181
+ comments: comments.map((comment) => ({
182
+ author: comment.author?.displayName ?? null,
183
+ body: adfToText(comment.body),
184
+ createdAt: comment.created
185
+ }))
186
+ };
187
+ }
188
+ async #listAllComments(api, keyOrId) {
189
+ const comments = [];
190
+ let total = 0;
191
+ for (let page = 0; page < ISSUE_COMMENTS_MAX_PAGES; page++) {
192
+ const result = await api.listComments(keyOrId, { startAt: comments.length });
193
+ comments.push(...result.comments);
194
+ total = result.total;
195
+ if (result.comments.length === 0 || comments.length >= total) break;
196
+ }
197
+ return {
198
+ comments,
199
+ total
200
+ };
201
+ }
202
+ async createComment(input) {
203
+ const resolved = await this.#resolveRequest(input);
204
+ let key = resolved.issueId;
205
+ if (!ISSUE_KEY_PATTERN.test(key)) try {
206
+ key = (await resolved.context.api.getIssue(key)).key;
207
+ } catch (error) {
208
+ if (error instanceof JiraApiError && error.status === 404) return null;
209
+ throw error;
210
+ }
211
+ let comment;
212
+ try {
213
+ comment = await resolved.context.api.createComment(key, input.body);
214
+ } catch (error) {
215
+ if (error instanceof JiraApiError && error.status === 404) return null;
216
+ throw error;
217
+ }
218
+ return {
219
+ id: comment.id,
220
+ url: `${resolved.context.siteUrl}/browse/${key}?focusedCommentId=${comment.id}`
221
+ };
222
+ }
223
+ async updateIssue(input) {
224
+ const resolved = await this.#resolveRequest(input);
225
+ let issue;
226
+ try {
227
+ issue = await resolved.context.api.getIssue(resolved.issueId);
228
+ } catch (error) {
229
+ if (error instanceof JiraApiError && error.status === 404) return null;
230
+ throw error;
231
+ }
232
+ if (currentStatusMatches(issue, input.state)) return this.#toIntakeIssue(issue, resolved.context.siteUrl);
233
+ const transition = resolveTransition(await resolved.context.api.listTransitions(issue.key), input.state);
234
+ if (!transition) return null;
235
+ await resolved.context.api.applyTransition(issue.key, transition.id);
236
+ return this.#toIntakeIssue(await resolved.context.api.getIssue(issue.key), resolved.context.siteUrl);
237
+ }
238
+ async #resolveRequest(input) {
239
+ const issueReference = decodeIssueReference(input.issueId);
240
+ const source = input.sourceId ? decodeSourceId(input.sourceId) : null;
241
+ const connectionId = issueReference?.connectionId ?? source?.connectionId ?? this.connectionIdOf(input.connection);
242
+ const issueId = issueReference?.issueId ?? input.issueId;
243
+ if (connectionId) return {
244
+ context: await this.#connectionContextById(connectionId),
245
+ issueId
246
+ };
247
+ const active = await this.#activeConnections();
248
+ if (active.length !== 1) throw new JiraApiError("Jira issue reference must identify a connection when multiple sites are connected.", 400);
249
+ return {
250
+ context: await this.#connectionContext(active[0]),
251
+ issueId
252
+ };
253
+ }
254
+ /**
255
+ * Locate an issue for a read. A connection-scoped reference resolves
256
+ * directly; a plain issue key (the agent tool's normal input) is looked up
257
+ * across every active connection so multi-site organizations can still
258
+ * fetch by key — the first site that knows the key wins, which is safe
259
+ * because Jira project-key prefixes make cross-site collisions unlikely and
260
+ * the tool is read-only.
261
+ */
262
+ async #findIssue(input) {
263
+ const issueReference = decodeIssueReference(input.issueId);
264
+ const source = input.sourceId ? decodeSourceId(input.sourceId) : null;
265
+ if (issueReference && source && (issueReference.connectionId !== source.connectionId || issueReference.projectId !== void 0 && issueReference.projectId !== source.projectId)) return null;
266
+ const connectionId = issueReference?.connectionId ?? source?.connectionId ?? this.connectionIdOf(input.connection);
267
+ const issueId = issueReference?.issueId ?? input.issueId;
268
+ const projectId = issueReference?.projectId ?? source?.projectId;
269
+ const candidates = [];
270
+ if (connectionId) candidates.push(await this.#connectionContextById(connectionId));
271
+ else {
272
+ const active = await this.#activeConnections();
273
+ if (active.length === 0) throw new JiraApiError("Jira connection is unavailable or requires reauthentication.", 401);
274
+ for (const connection of active) candidates.push(await this.#connectionContext(connection));
275
+ }
276
+ let firstError;
277
+ for (const context of candidates) try {
278
+ const issue = await context.api.getIssue(issueId);
279
+ if (projectId && issue.fields.project?.id !== projectId) return null;
280
+ return {
281
+ context,
282
+ issue
283
+ };
284
+ } catch (error) {
285
+ if (error instanceof JiraApiError && error.status === 404) continue;
286
+ firstError ??= error;
287
+ }
288
+ if (firstError !== void 0) throw firstError;
289
+ return null;
290
+ }
291
+ #toIntakeIssue(issue, siteUrl) {
292
+ const { fields } = issue;
293
+ return {
294
+ id: issue.id,
295
+ identifier: issue.key,
296
+ title: fields.summary ?? issue.key,
297
+ url: `${siteUrl}/browse/${issue.key}`,
298
+ author: fields.reporter?.displayName ?? null,
299
+ state: fields.status?.name ?? null,
300
+ stateType: stateTypeFromCategory(fields.status?.statusCategory?.key),
301
+ priority: fields.priority?.name ?? null,
302
+ assignee: fields.assignee?.displayName ?? null,
303
+ source: fields.project?.key ?? null,
304
+ labels: fields.labels ?? [],
305
+ commentCount: null,
306
+ createdAt: fields.created ?? "",
307
+ updatedAt: fields.updated ?? ""
308
+ };
309
+ }
310
+ async #activeConnections() {
311
+ return (await this.#jira.listConnections()).filter((connection) => connection.status === "active");
312
+ }
313
+ async #connectionContextById(connectionId) {
314
+ return this.#connectionContext(await this.activeConnectionById(connectionId));
315
+ }
316
+ notConnectedError() {
317
+ return new JiraApiError("Jira connection is unavailable or requires reauthentication.", 401);
318
+ }
319
+ async #cloudId(connectionId) {
320
+ const cached = this.#cloudIdByConnectionId.get(connectionId);
321
+ if (cached) return cached;
322
+ const cloudId = (await this.#jira.connect.getContext(connectionId)).connection_config?.cloudId;
323
+ if (typeof cloudId !== "string" || !UUID_PATTERN.test(cloudId)) throw new JiraApiError("Platform Jira connection context is missing a valid cloudId.", 502);
324
+ this.#cloudIdByConnectionId.set(connectionId, cloudId);
325
+ return cloudId;
326
+ }
327
+ async #connectionContext(connection) {
328
+ const proxyBaseUrl = this.#jira.binding.proxyBaseUrl(connection.id);
329
+ const cloudId = await this.#cloudId(connection.id);
330
+ const api = new JiraApiClient({
331
+ baseUrl: `${proxyBaseUrl}/ex/jira/${encodeURIComponent(cloudId)}`,
332
+ accessToken: CONNECT_PROXY_TOKEN,
333
+ fetchImpl: this.#jira.binding.proxyFetch()
334
+ });
335
+ let siteUrl = this.#siteUrlByConnectionId.get(connection.id);
336
+ if (!siteUrl) {
337
+ siteUrl = connection.accountLabel ? normalizeSiteUrl(connection.accountLabel) : normalizeSiteUrl((await api.getServerInfo()).baseUrl);
338
+ this.#siteUrlByConnectionId.set(connection.id, siteUrl);
339
+ }
340
+ return {
341
+ connection,
342
+ api,
343
+ siteUrl
344
+ };
345
+ }
346
+ };
347
+ function encodeSourceId(connectionId, projectId) {
348
+ return `${JIRA_SOURCE_PREFIX}${Buffer.from(JSON.stringify({
349
+ connectionId,
350
+ projectId
351
+ })).toString("base64url")}`;
352
+ }
353
+ function decodeSourceId(sourceId) {
354
+ if (!sourceId.startsWith(JIRA_SOURCE_PREFIX)) return null;
355
+ try {
356
+ const parsed = JSON.parse(Buffer.from(sourceId.slice(13), "base64url").toString("utf8"));
357
+ return typeof parsed.connectionId === "string" && typeof parsed.projectId === "string" ? {
358
+ connectionId: parsed.connectionId,
359
+ projectId: parsed.projectId
360
+ } : null;
361
+ } catch {
362
+ return null;
363
+ }
364
+ }
365
+ function encodeIssueReference(reference) {
366
+ return `${JIRA_ISSUE_REF_PREFIX}${Buffer.from(JSON.stringify(reference)).toString("base64url")}`;
367
+ }
368
+ function decodeIssueReference(value) {
369
+ if (!value.startsWith(JIRA_ISSUE_REF_PREFIX)) return null;
370
+ try {
371
+ const parsed = JSON.parse(Buffer.from(value.slice(11), "base64url").toString("utf8"));
372
+ if (typeof parsed.connectionId !== "string" || typeof parsed.issueId !== "string") return null;
373
+ return {
374
+ connectionId: parsed.connectionId,
375
+ issueId: parsed.issueId,
376
+ ...typeof parsed.projectId === "string" ? { projectId: parsed.projectId } : {}
377
+ };
378
+ } catch {
379
+ return null;
380
+ }
381
+ }
382
+ /** A Platform source scope: `projectId` is the encoded source id, decoded per connection here. */
383
+ function groupSources(scopes) {
384
+ const groups = /* @__PURE__ */ new Map();
385
+ for (const scope of scopes) {
386
+ const source = decodeSourceId(scope.projectId);
387
+ if (!source) continue;
388
+ const projects = groups.get(source.connectionId) ?? /* @__PURE__ */ new Map();
389
+ if (!projects.has(source.projectId)) projects.set(source.projectId, {
390
+ ...scope,
391
+ projectId: source.projectId
392
+ });
393
+ groups.set(source.connectionId, projects);
394
+ }
395
+ return [...groups.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([connectionId, projects]) => ({
396
+ connectionId,
397
+ scopes: [...projects.values()].sort((left, right) => left.projectId.localeCompare(right.projectId))
398
+ }));
399
+ }
400
+ function encodePageCursor(cursor) {
401
+ return Buffer.from(JSON.stringify(cursor)).toString("base64url");
402
+ }
403
+ function decodePageCursor(cursor) {
404
+ if (!cursor) return { group: 0 };
405
+ try {
406
+ const parsed = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
407
+ if (!Number.isInteger(parsed.group) || parsed.group < 0) throw new Error();
408
+ return {
409
+ group: parsed.group,
410
+ ...typeof parsed.jira === "string" ? { jira: parsed.jira } : {}
411
+ };
412
+ } catch {
413
+ throw new JiraApiError("Jira pagination cursor is invalid.", 400);
414
+ }
415
+ }
416
+ function normalizeSiteUrl(value) {
417
+ const candidate = /^https?:\/\//i.test(value) ? value : `https://${value}`;
418
+ let url;
419
+ try {
420
+ url = new URL(candidate);
421
+ } catch {
422
+ throw new JiraApiError("Jira site URL is invalid.", 502);
423
+ }
424
+ if (url.protocol !== "http:" && url.protocol !== "https:") throw new JiraApiError("Jira site URL is invalid.", 502);
425
+ return url.origin;
426
+ }
427
+ function currentStatusMatches(issue, target) {
428
+ const status = issue.fields.status;
429
+ if (!status) return false;
430
+ if (target.kind === "byName") return status.name.toLowerCase() === target.name.toLowerCase();
431
+ if (target.stateType === "canceled") return status.statusCategory?.key === "done" && /cancel/i.test(status.name);
432
+ return status.statusCategory?.key === STATE_TYPE_TO_CATEGORY[target.stateType];
433
+ }
434
+ function resolveTransition(transitions, target) {
435
+ if (target.kind === "byName") {
436
+ const wanted = target.name.toLowerCase();
437
+ return transitions.find((transition) => transition.to?.name.toLowerCase() === wanted) ?? null;
438
+ }
439
+ if (target.stateType === "canceled") return transitions.find((transition) => transition.to?.statusCategory?.key === "done" && /cancel/i.test(transition.to.name)) ?? null;
440
+ const category = STATE_TYPE_TO_CATEGORY[target.stateType];
441
+ return transitions.find((transition) => transition.to?.statusCategory?.key === category) ?? null;
442
+ }
443
+ export { JIRA_CONNECTION_TOKEN_PREFIX, PlatformJiraIntake, UUID_PATTERN, decodeIssueReference, decodeSourceId, encodeIssueReference, encodeSourceId };
444
+
445
+ //# sourceMappingURL=intake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intake.js","names":[],"sources":["../../../../src/integrations/platform/jira/intake.ts"],"sourcesContent":["import type {\n CreateIntakeCommentInput,\n CreatedIntakeComment,\n GetIntakeIssueInput,\n IntakeIssue,\n IntakeIssueDetail,\n IntakeItemPage,\n IntakeSource,\n ListIntakeIssuesInput,\n ListIntakeItemsInput,\n ListIntakeSourcesInput,\n ResolveIntakeDispatchInput,\n ResolvedIntakeDispatch,\n UpdateIntakeIssueInput,\n} from '../../../capabilities/intake.js';\nimport { adfToText } from '../../jira/adf.js';\nimport type { JiraComment, JiraIssue, JiraTransition } from '../../jira/api.js';\nimport { JiraApiClient, JiraApiError } from '../../jira/api.js';\nimport { buildIntakeJql, unfilteredJiraScopes } from '../../jira/intake-jql.js';\nimport type { JiraIntakeScope } from '../../jira/intake-jql.js';\nimport type { PlatformConnection } from '../foundation/connect-binding.js';\nimport { PlatformIntakeCapability } from '../foundation/intake.js';\nimport { CONNECT_PROXY_TOKEN } from '../platform-connect.js';\nimport type { PlatformJiraIntegration } from './integration.js';\n\ninterface JiraConnectionContext {\n connection: PlatformConnection;\n api: JiraApiClient;\n siteUrl: string;\n}\n\nexport interface 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+$/;\nexport const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nexport const 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\n/** One page of active Jira issues across connections. */\nexport interface JiraActiveIssuePage {\n issues: Array<IntakeIssue & { sourceId: string; externalId: string; site: string }>;\n nextCursor: string | null;\n}\n\n/** The Platform Jira intake: Jira projects as sources, reached through each connection's proxy. */\nexport class PlatformJiraIntake extends PlatformIntakeCapability {\n readonly bindingLabelFilters = true;\n readonly #jira: PlatformJiraIntegration;\n readonly #cloudIdByConnectionId = new Map<string, string>();\n readonly #siteUrlByConnectionId = new Map<string, string>();\n\n constructor(jira: PlatformJiraIntegration) {\n super(jira, JIRA_CONNECTION_TOKEN_PREFIX);\n this.#jira = jira;\n }\n\n clearCaches(): void {\n this.#cloudIdByConnectionId.clear();\n this.#siteUrlByConnectionId.clear();\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: this.connectionCredential(reference.connectionId),\n ...(reference.projectId ? { sourceId: encodeSourceId(reference.connectionId, reference.projectId) } : {}),\n issueId: reference.issueId,\n };\n }\n\n async listSources(_input: ListIntakeSourcesInput): 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.#jira.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.#jira.listActiveIssues(\n input.cursor,\n unfilteredJiraScopes(input.sourceIds ?? []),\n input.labels,\n );\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 = issueReference?.connectionId ?? source?.connectionId ?? this.connectionIdOf(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 = issueReference?.connectionId ?? source?.connectionId ?? this.connectionIdOf(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<PlatformConnection[]> {\n return (await this.#jira.listConnections()).filter(connection => connection.status === 'active');\n }\n\n async #connectionContextById(connectionId: string): Promise<JiraConnectionContext> {\n return this.#connectionContext(await this.activeConnectionById(connectionId));\n }\n\n protected notConnectedError(): JiraApiError {\n return new JiraApiError('Jira connection is unavailable or requires reauthentication.', 401);\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.#jira.connect.getContext(connectionId);\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: PlatformConnection): Promise<JiraConnectionContext> {\n const proxyBaseUrl = this.#jira.binding.proxyBaseUrl(connection.id);\n const cloudId = await this.#cloudId(connection.id);\n const api = new JiraApiClient({\n baseUrl: `${proxyBaseUrl}/ex/jira/${encodeURIComponent(cloudId)}`,\n accessToken: CONNECT_PROXY_TOKEN,\n fetchImpl: this.#jira.binding.proxyFetch(),\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\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":";;;;;;AA0CA,MAAM,2BAA2B;;AAGjC,MAAM,2BAA2B;AACjC,MAAM,oBAAoB;AAC1B,MAAa,eAAe;AAC5B,MAAa,+BAA+B;AAC5C,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;;AASA,IAAa,qBAAb,cAAwC,yBAAyB;CAC/D,sBAA+B;CAC/B;CACA,yCAAkC,IAAI,IAAoB;CAC1D,yCAAkC,IAAI,IAAoB;CAE1D,YAAY,MAA+B;EACzC,MAAM,MAAM,4BAA4B;EACxC,KAAK,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AgB,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,32 +1,25 @@
1
1
  import type { RequestContext } from '@mastra/core/request-context';
2
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
3
  import type { RouteAuth } from '../../../routes/route.js';
6
4
  import type { FactoryProjectsStorage } from '../../../storage/domains/projects/base.js';
7
- import type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../../base.js';
5
+ import type { IntegrationContext, IntegrationTools } from '../../base.js';
6
+ import type { IssueReconciler } from '../../issue-reconciler.js';
8
7
  import type { JiraEventRules, JiraRuleOverrides } from '../../jira/default-rules.js';
9
8
  import type { JiraIntakeScope } from '../../jira/intake-jql.js';
10
- import type { PlatformApiClientConfig } from '../api-client.js';
11
- interface PlatformIntegrationConnection {
12
- id: string;
13
- integrationId: string;
14
- status: 'active' | 'needs_reauth';
15
- accountLabel: string | null;
16
- }
17
- interface JiraIssueReference {
18
- connectionId: string;
19
- issueId: string;
20
- projectId?: string;
21
- }
9
+ import { PlatformConnectIntegration } from '../foundation/integration.js';
10
+ import type { PlatformConnectOption } from '../platform-connect.js';
11
+ import { PlatformJiraIntake } from './intake.js';
12
+ import type { JiraActiveIssuePage } from './intake.js';
13
+ export { decodeIssueReference, decodeSourceId, encodeIssueReference, encodeSourceId } from './intake.js';
22
14
  export interface PlatformJiraIntegrationConfig {
23
- clientConfig?: PlatformApiClientConfig;
15
+ /** The Connect client, or options to build one; defaults to the platform environment. */
16
+ connect?: PlatformConnectOption;
24
17
  /** Per-event replacements; omitted events retain defaults, null disables. */
25
18
  rules?: JiraRuleOverrides;
26
19
  }
27
- export declare class PlatformJiraIntegration implements FactoryIntegration {
20
+ export declare class PlatformJiraIntegration extends PlatformConnectIntegration {
28
21
  #private;
29
- readonly id = "jira";
22
+ readonly intake: PlatformJiraIntake;
30
23
  get rules(): JiraEventRules;
31
24
  constructor(config?: PlatformJiraIntegrationConfig);
32
25
  initialize({ projects, auth }: {
@@ -37,35 +30,18 @@ export declare class PlatformJiraIntegration implements FactoryIntegration {
37
30
  get authEnabled(): boolean;
38
31
  resolveOrgId(resourceId: string): Promise<string | null>;
39
32
  clearCaches(): void;
40
- listConnections(): Promise<PlatformIntegrationConnection[]>;
41
33
  hasActiveConnections(): Promise<boolean>;
42
- readonly intake: Intake;
43
34
  /**
44
35
  * One page of active issues across connections. Each scope's `projectId` is
45
36
  * an encoded Platform source id; sources are grouped per connection and each
46
37
  * group runs one JQL built from only that connection's projects.
47
38
  */
48
- listActiveIssues(cursor?: string, scopes?: JiraIntakeScope[], labels?: string[]): Promise<{
49
- issues: Array<IntakeIssue & {
50
- sourceId: string;
51
- externalId: string;
52
- site: string;
53
- }>;
54
- nextCursor: string | null;
55
- }>;
56
- workers(ctx: IntegrationContext): MastraWorker[];
39
+ listActiveIssues(cursor?: string, scopes?: JiraIntakeScope[], labels?: string[]): Promise<JiraActiveIssuePage>;
40
+ protected reconcile(ctx: IntegrationContext): IssueReconciler | null;
57
41
  routes(ctx: IntegrationContext): ApiRoute[];
58
42
  agentTools(args: {
59
43
  requestContext: RequestContext;
60
44
  }): Promise<IntegrationTools>;
61
45
  diagnostics(): Record<string, unknown>;
62
46
  }
63
- export declare function encodeSourceId(connectionId: string, projectId: string): string;
64
- export declare function decodeSourceId(sourceId: string): {
65
- connectionId: string;
66
- projectId: string;
67
- } | null;
68
- export declare function encodeIssueReference(reference: JiraIssueReference): string;
69
- export declare function decodeIssueReference(value: string): JiraIssueReference | null;
70
- export {};
71
47
  //# sourceMappingURL=integration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/jira/integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGxD,OAAO,KAAK,EAIV,MAAM,EACN,WAAW,EASZ,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAK9F,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGrF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAIhE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAIhE,UAAU,6BAA6B;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,QAAQ,GAAG,cAAc,CAAC;IAClC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAaD,UAAU,kBAAkB;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAqCD,MAAM,WAAW,6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