@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,271 @@
1
+ import { IncidentioApiClient, IncidentioApiError } from "../../incidentio/api.js";
2
+ import { INCIDENTIO_FOLLOW_UPS_SOURCE_ID, INCIDENTIO_INCIDENTS_SOURCE_ID, createIncidentioIntake } from "../../incidentio/intake.js";
3
+ import { PlatformIntakeCapability } from "../foundation/intake.js";
4
+ import { CONNECT_PROXY_TOKEN } from "../platform-connect.js";
5
+ // src/integrations/platform/incidentio/intake.ts
6
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
7
+ const CONNECTION_TOKEN_PREFIX = "incidentio-connection:";
8
+ const SCOPED_SOURCE_PREFIX = "incidentio-source:";
9
+ const BASE_SOURCE_IDS = [INCIDENTIO_INCIDENTS_SOURCE_ID, INCIDENTIO_FOLLOW_UPS_SOURCE_ID];
10
+ function encodeScopedSourceId(connectionId, sourceId) {
11
+ return `${SCOPED_SOURCE_PREFIX}${Buffer.from(JSON.stringify({
12
+ connectionId,
13
+ sourceId
14
+ })).toString("base64url")}`;
15
+ }
16
+ function decodeScopedSourceId(value) {
17
+ if (!value.startsWith(SCOPED_SOURCE_PREFIX)) return null;
18
+ try {
19
+ const parsed = JSON.parse(Buffer.from(value.slice(18), "base64url").toString("utf8"));
20
+ return typeof parsed.connectionId === "string" && typeof parsed.sourceId === "string" ? {
21
+ connectionId: parsed.connectionId,
22
+ sourceId: parsed.sourceId
23
+ } : null;
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+ /**
29
+ * Base (per-connection) source ids selected for a connection. Scoped ids
30
+ * select their own connection; legacy unscoped ids (`incidentio:incidents`)
31
+ * from pre-discovery deploys apply to every connection.
32
+ */
33
+ function baseSourceIdsFor(connectionId, sourceIds) {
34
+ const selected = /* @__PURE__ */ new Set();
35
+ for (const sourceId of sourceIds) {
36
+ const scoped = decodeScopedSourceId(sourceId);
37
+ if (scoped) {
38
+ if (scoped.connectionId === connectionId) selected.add(scoped.sourceId);
39
+ continue;
40
+ }
41
+ if (BASE_SOURCE_IDS.includes(sourceId)) selected.add(sourceId);
42
+ }
43
+ return [...selected];
44
+ }
45
+ function encodePageCursor(cursor) {
46
+ return Buffer.from(JSON.stringify(cursor)).toString("base64url");
47
+ }
48
+ function decodePageCursor(cursor) {
49
+ if (!cursor) return null;
50
+ try {
51
+ const parsed = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
52
+ if (typeof parsed.connectionId !== "string" || !parsed.connectionId) return null;
53
+ return {
54
+ connectionId: parsed.connectionId,
55
+ ...typeof parsed.inner === "string" && parsed.inner ? { inner: parsed.inner } : {}
56
+ };
57
+ } catch {
58
+ return null;
59
+ }
60
+ }
61
+ /**
62
+ * The Platform incident.io intake: every active connection's incident.io
63
+ * intake, aggregated, with source ids scoped to their connection.
64
+ */
65
+ var PlatformIncidentioIntake = class extends PlatformIntakeCapability {
66
+ #incidentio;
67
+ #intakeByConnectionId = /* @__PURE__ */ new Map();
68
+ constructor(incidentio) {
69
+ super(incidentio, CONNECTION_TOKEN_PREFIX);
70
+ this.#incidentio = incidentio;
71
+ }
72
+ clearCaches() {
73
+ this.#intakeByConnectionId.clear();
74
+ }
75
+ notConnectedError() {
76
+ return new IncidentioApiError("incident.io connection is unavailable or requires reauthentication.", 401);
77
+ }
78
+ #connectionIntake(connectionId) {
79
+ const cached = this.#intakeByConnectionId.get(connectionId);
80
+ if (cached) return cached;
81
+ const proxyBaseUrl = this.#incidentio.binding.proxyBaseUrl(connectionId);
82
+ const intake = createIncidentioIntake({
83
+ api: new IncidentioApiClient({
84
+ baseUrl: proxyBaseUrl,
85
+ accessToken: CONNECT_PROXY_TOKEN,
86
+ projectId: null,
87
+ fetchImpl: this.#incidentio.binding.proxyFetch()
88
+ }),
89
+ connection: this.connectionCredential(connectionId)
90
+ });
91
+ this.#intakeByConnectionId.set(connectionId, intake);
92
+ return intake;
93
+ }
94
+ async #connectionContexts() {
95
+ return (await this.#incidentio.activeConnections()).map((connection) => ({
96
+ connection,
97
+ intake: this.#connectionIntake(connection.id)
98
+ }));
99
+ }
100
+ /**
101
+ * Resolve the intake for an explicit connection token, or fall back to the
102
+ * sole active connection so legacy single-connection callers keep working.
103
+ *
104
+ * A caller-supplied connection token is only a claim: the id it carries
105
+ * must match a connection the deployment actually discovered as active
106
+ * before any proxy request is minted with the Platform credential.
107
+ */
108
+ async #intakeForConnection(connection) {
109
+ const connectionId = this.connectionIdOf(connection);
110
+ if (connectionId) {
111
+ await this.activeConnectionById(connectionId);
112
+ return {
113
+ intake: this.#connectionIntake(connectionId),
114
+ connection: this.connectionCredential(connectionId)
115
+ };
116
+ }
117
+ const active = await this.#incidentio.activeConnections();
118
+ if (active.length === 1) {
119
+ const soleId = active[0].id;
120
+ return {
121
+ intake: this.#connectionIntake(soleId),
122
+ connection: this.connectionCredential(soleId)
123
+ };
124
+ }
125
+ throw new IncidentioApiError(active.length === 0 ? "incident.io connection is unavailable or requires reauthentication." : "incident.io request must identify a connection when multiple accounts are connected.", active.length === 0 ? 401 : 400);
126
+ }
127
+ async resolveIntakeDispatch(input) {
128
+ if (input.externalSource.type !== "issue") return null;
129
+ const externalId = input.externalSource.externalId;
130
+ const contexts = await this.#connectionContexts();
131
+ if (contexts.length === 0) return null;
132
+ if (contexts.length === 1) {
133
+ const resolved = await contexts[0].intake.resolveIntakeDispatch?.(input);
134
+ return resolved ? this.#scopeResolvedDispatch(contexts[0].connection.id, resolved) : null;
135
+ }
136
+ let firstError;
137
+ for (const context of contexts) try {
138
+ if (!await context.intake.getIssue({
139
+ connection: this.connectionCredential(context.connection.id),
140
+ issueId: externalId
141
+ })) continue;
142
+ const resolved = await context.intake.resolveIntakeDispatch?.(input);
143
+ return resolved ? this.#scopeResolvedDispatch(context.connection.id, resolved) : null;
144
+ } catch (error) {
145
+ if (error instanceof IncidentioApiError && error.status === 404) continue;
146
+ firstError ??= error;
147
+ }
148
+ if (firstError !== void 0) throw firstError;
149
+ return null;
150
+ }
151
+ #scopeResolvedDispatch(connectionId, resolved) {
152
+ return {
153
+ ...resolved,
154
+ connection: this.connectionCredential(connectionId),
155
+ ...resolved.sourceId ? { sourceId: encodeScopedSourceId(connectionId, resolved.sourceId) } : {}
156
+ };
157
+ }
158
+ async listSources(_input) {
159
+ const contexts = await this.#connectionContexts();
160
+ const sources = [];
161
+ for (const context of contexts) {
162
+ const account = context.connection.accountLabel;
163
+ const inner = await context.intake.listSources({
164
+ orgId: "",
165
+ userId: ""
166
+ });
167
+ for (const source of inner) sources.push({
168
+ ...source,
169
+ id: encodeScopedSourceId(context.connection.id, source.id),
170
+ name: contexts.length > 1 && account ? `${source.name} (${account})` : source.name,
171
+ metadata: {
172
+ ...source.metadata ?? {},
173
+ connectionId: context.connection.id,
174
+ ...account ? { account } : {}
175
+ }
176
+ });
177
+ }
178
+ return sources;
179
+ }
180
+ async listItems(input) {
181
+ if (input.sourceIds.length === 0) return {
182
+ items: [],
183
+ nextCursor: null
184
+ };
185
+ const contexts = await this.#connectionContexts();
186
+ const cursor = decodePageCursor(input.cursor);
187
+ let startIndex = 0;
188
+ let exactMatch = false;
189
+ if (cursor) {
190
+ const index = contexts.findIndex((context) => context.connection.id === cursor.connectionId);
191
+ exactMatch = index !== -1;
192
+ startIndex = exactMatch ? index : contexts.findIndex((context) => context.connection.id.localeCompare(cursor.connectionId) > 0);
193
+ if (startIndex === -1) return {
194
+ items: [],
195
+ nextCursor: null
196
+ };
197
+ }
198
+ for (let index = startIndex; index < contexts.length; index++) {
199
+ const context = contexts[index];
200
+ const baseSourceIds = baseSourceIdsFor(context.connection.id, input.sourceIds);
201
+ if (baseSourceIds.length === 0) continue;
202
+ const page = await context.intake.listItems({
203
+ orgId: input.orgId,
204
+ userId: input.userId,
205
+ sourceIds: baseSourceIds,
206
+ ...index === startIndex && exactMatch && cursor?.inner ? { cursor: cursor.inner } : {}
207
+ });
208
+ const nextCursor = page.nextCursor ? encodePageCursor({
209
+ connectionId: context.connection.id,
210
+ inner: page.nextCursor
211
+ }) : index + 1 < contexts.length ? encodePageCursor({ connectionId: contexts[index + 1].connection.id }) : null;
212
+ return {
213
+ items: page.items.map((item) => ({
214
+ ...item,
215
+ sourceId: encodeScopedSourceId(context.connection.id, item.sourceId),
216
+ metadata: {
217
+ ...item.metadata ?? {},
218
+ connectionId: context.connection.id
219
+ }
220
+ })),
221
+ nextCursor
222
+ };
223
+ }
224
+ return {
225
+ items: [],
226
+ nextCursor: null
227
+ };
228
+ }
229
+ async listIssues(input) {
230
+ const resolved = await this.#intakeForConnection(input.connection);
231
+ const connectionId = this.connectionIdOf(resolved.connection);
232
+ const baseSourceIds = connectionId ? baseSourceIdsFor(connectionId, input.sourceIds) : input.sourceIds.map((sourceId) => decodeScopedSourceId(sourceId)?.sourceId ?? sourceId);
233
+ return resolved.intake.listIssues({
234
+ ...input,
235
+ connection: resolved.connection,
236
+ sourceIds: baseSourceIds
237
+ });
238
+ }
239
+ async getIssue(input) {
240
+ const resolved = await this.#intakeForConnection(input.connection);
241
+ return resolved.intake.getIssue({
242
+ ...this.#withBaseSource(input),
243
+ connection: resolved.connection
244
+ });
245
+ }
246
+ async createComment(input) {
247
+ const resolved = await this.#intakeForConnection(input.connection);
248
+ return resolved.intake.createComment({
249
+ ...this.#withBaseSource(input),
250
+ connection: resolved.connection
251
+ });
252
+ }
253
+ async updateIssue(input) {
254
+ const resolved = await this.#intakeForConnection(input.connection);
255
+ return resolved.intake.updateIssue({
256
+ ...this.#withBaseSource(input),
257
+ connection: resolved.connection
258
+ });
259
+ }
260
+ #withBaseSource(input) {
261
+ if (!input.sourceId) return input;
262
+ const scoped = decodeScopedSourceId(input.sourceId);
263
+ return scoped ? {
264
+ ...input,
265
+ sourceId: scoped.sourceId
266
+ } : input;
267
+ }
268
+ };
269
+ export { PlatformIncidentioIntake, UUID_RE, decodeScopedSourceId, encodeScopedSourceId };
270
+
271
+ //# sourceMappingURL=intake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intake.js","names":[],"sources":["../../../../src/integrations/platform/incidentio/intake.ts"],"sourcesContent":["import 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 ListIntakeSourcesInput,\n ResolveIntakeDispatchInput,\n ResolvedIntakeDispatch,\n UpdateIntakeIssueInput,\n} from '../../../capabilities/intake.js';\nimport { IncidentioApiClient, IncidentioApiError } from '../../incidentio/api.js';\nimport {\n createIncidentioIntake,\n INCIDENTIO_FOLLOW_UPS_SOURCE_ID,\n INCIDENTIO_INCIDENTS_SOURCE_ID,\n} from '../../incidentio/intake.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 { PlatformIncidentioIntegration } from './integration.js';\n\nexport const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nconst CONNECTION_TOKEN_PREFIX = 'incidentio-connection:';\nconst SCOPED_SOURCE_PREFIX = 'incidentio-source:';\nconst BASE_SOURCE_IDS = [INCIDENTIO_INCIDENTS_SOURCE_ID, INCIDENTIO_FOLLOW_UPS_SOURCE_ID] as const;\n\ninterface ScopedSourceId {\n connectionId: string;\n sourceId: string;\n}\n\n/** An intake plus the exact inner connection it was resolved for, so operations discover active connections once. */\ninterface ResolvedIncidentioIntake {\n intake: Intake;\n connection: IntegrationConnection;\n}\n\ninterface AggregatePageCursor {\n /** Connection ID the cursor points at; keyed by ID so the active list can change between pages. */\n connectionId: string;\n inner?: string;\n}\n\nexport function encodeScopedSourceId(connectionId: string, sourceId: string): string {\n return `${SCOPED_SOURCE_PREFIX}${Buffer.from(JSON.stringify({ connectionId, sourceId })).toString('base64url')}`;\n}\n\nexport function decodeScopedSourceId(value: string): ScopedSourceId | null {\n if (!value.startsWith(SCOPED_SOURCE_PREFIX)) return null;\n try {\n const parsed = JSON.parse(\n Buffer.from(value.slice(SCOPED_SOURCE_PREFIX.length), 'base64url').toString('utf8'),\n ) as Record<string, unknown>;\n return typeof parsed.connectionId === 'string' && typeof parsed.sourceId === 'string'\n ? { connectionId: parsed.connectionId, sourceId: parsed.sourceId }\n : null;\n } catch {\n return null;\n }\n}\n\n/**\n * Base (per-connection) source ids selected for a connection. Scoped ids\n * select their own connection; legacy unscoped ids (`incidentio:incidents`)\n * from pre-discovery deploys apply to every connection.\n */\nfunction baseSourceIdsFor(connectionId: string, sourceIds: string[]): string[] {\n const selected = new Set<string>();\n for (const sourceId of sourceIds) {\n const scoped = decodeScopedSourceId(sourceId);\n if (scoped) {\n if (scoped.connectionId === connectionId) selected.add(scoped.sourceId);\n continue;\n }\n if ((BASE_SOURCE_IDS as readonly string[]).includes(sourceId)) selected.add(sourceId);\n }\n return [...selected];\n}\n\nfunction encodePageCursor(cursor: AggregatePageCursor): string {\n return Buffer.from(JSON.stringify(cursor)).toString('base64url');\n}\n\nfunction decodePageCursor(cursor: string | undefined): AggregatePageCursor | null {\n if (!cursor) return null;\n try {\n const parsed = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8')) as Partial<AggregatePageCursor>;\n if (typeof parsed.connectionId !== 'string' || !parsed.connectionId) return null;\n return {\n connectionId: parsed.connectionId,\n ...(typeof parsed.inner === 'string' && parsed.inner ? { inner: parsed.inner } : {}),\n };\n } catch {\n return null;\n }\n}\n\ninterface IncidentioConnectionContext {\n connection: PlatformConnection;\n intake: Intake;\n}\n\n/**\n * The Platform incident.io intake: every active connection's incident.io\n * intake, aggregated, with source ids scoped to their connection.\n */\nexport class PlatformIncidentioIntake extends PlatformIntakeCapability {\n readonly #incidentio: PlatformIncidentioIntegration;\n readonly #intakeByConnectionId = new Map<string, Intake>();\n\n constructor(incidentio: PlatformIncidentioIntegration) {\n super(incidentio, CONNECTION_TOKEN_PREFIX);\n this.#incidentio = incidentio;\n }\n\n clearCaches(): void {\n this.#intakeByConnectionId.clear();\n }\n\n protected notConnectedError(): IncidentioApiError {\n return new IncidentioApiError('incident.io connection is unavailable or requires reauthentication.', 401);\n }\n\n #connectionIntake(connectionId: string): Intake {\n const cached = this.#intakeByConnectionId.get(connectionId);\n if (cached) return cached;\n const proxyBaseUrl = this.#incidentio.binding.proxyBaseUrl(connectionId);\n const intake = createIncidentioIntake({\n api: new IncidentioApiClient({\n baseUrl: proxyBaseUrl,\n accessToken: CONNECT_PROXY_TOKEN,\n // Connect sets the project header; the API client must not add its own.\n projectId: null,\n fetchImpl: this.#incidentio.binding.proxyFetch(),\n }),\n connection: this.connectionCredential(connectionId),\n });\n this.#intakeByConnectionId.set(connectionId, intake);\n return intake;\n }\n\n async #connectionContexts(): Promise<IncidentioConnectionContext[]> {\n return (await this.#incidentio.activeConnections()).map(connection => ({\n connection,\n intake: this.#connectionIntake(connection.id),\n }));\n }\n\n /**\n * Resolve the intake for an explicit connection token, or fall back to the\n * sole active connection so legacy single-connection callers keep working.\n *\n * A caller-supplied connection token is only a claim: the id it carries\n * must match a connection the deployment actually discovered as active\n * before any proxy request is minted with the Platform credential.\n */\n async #intakeForConnection(connection: IntegrationConnection): Promise<ResolvedIncidentioIntake> {\n const connectionId = this.connectionIdOf(connection);\n if (connectionId) {\n await this.activeConnectionById(connectionId);\n return { intake: this.#connectionIntake(connectionId), connection: this.connectionCredential(connectionId) };\n }\n const active = await this.#incidentio.activeConnections();\n if (active.length === 1) {\n const soleId = active[0]!.id;\n return { intake: this.#connectionIntake(soleId), connection: this.connectionCredential(soleId) };\n }\n throw new IncidentioApiError(\n active.length === 0\n ? 'incident.io connection is unavailable or requires reauthentication.'\n : 'incident.io request must identify a connection when multiple accounts are connected.',\n active.length === 0 ? 401 : 400,\n );\n }\n\n async resolveIntakeDispatch(input: ResolveIntakeDispatchInput): Promise<ResolvedIntakeDispatch | null> {\n if (input.externalSource.type !== 'issue') return null;\n const externalId = input.externalSource.externalId;\n const contexts = await this.#connectionContexts();\n if (contexts.length === 0) return null;\n if (contexts.length === 1) {\n const resolved = await contexts[0]!.intake.resolveIntakeDispatch?.(input);\n return resolved ? this.#scopeResolvedDispatch(contexts[0]!.connection.id, resolved) : null;\n }\n // Multiple accounts: item references carry no connection id, so probe\n // each connection for the item — first account that knows it wins\n // (incident.io ids are globally unique ULIDs, collisions are not a\n // practical concern and this capability is read-mostly).\n let firstError: unknown;\n for (const context of contexts) {\n try {\n const issue = await context.intake.getIssue({\n connection: this.connectionCredential(context.connection.id),\n issueId: externalId,\n });\n if (!issue) continue;\n const resolved = await context.intake.resolveIntakeDispatch?.(input);\n return resolved ? this.#scopeResolvedDispatch(context.connection.id, resolved) : null;\n } catch (error) {\n if (error instanceof IncidentioApiError && error.status === 404) continue;\n firstError ??= error;\n }\n }\n if (firstError !== undefined) throw firstError;\n return null;\n }\n\n #scopeResolvedDispatch(connectionId: string, resolved: ResolvedIntakeDispatch): ResolvedIntakeDispatch {\n return {\n ...resolved,\n connection: this.connectionCredential(connectionId),\n ...(resolved.sourceId ? { sourceId: encodeScopedSourceId(connectionId, resolved.sourceId) } : {}),\n };\n }\n\n async listSources(_input: ListIntakeSourcesInput): Promise<IntakeSource[]> {\n const contexts = await this.#connectionContexts();\n const sources: IntakeSource[] = [];\n for (const context of contexts) {\n const account = context.connection.accountLabel;\n const inner = await context.intake.listSources({ orgId: '', userId: '' });\n for (const source of inner) {\n sources.push({\n ...source,\n id: encodeScopedSourceId(context.connection.id, source.id),\n name: contexts.length > 1 && account ? `${source.name} (${account})` : source.name,\n metadata: {\n ...(source.metadata ?? {}),\n connectionId: context.connection.id,\n ...(account ? { account } : {}),\n },\n });\n }\n }\n return sources;\n }\n\n async listItems(input: ListIntakeItemsInput): Promise<IntakeItemPage> {\n if (input.sourceIds.length === 0) return { items: [], nextCursor: null };\n const contexts = await this.#connectionContexts();\n const cursor = decodePageCursor(input.cursor);\n\n // Resume by connection ID: the active list can change between pages, so an\n // index would replay or skip connections. When the cursor's connection is\n // gone, resume at its sorted successor and drop the inner cursor.\n let startIndex = 0;\n let exactMatch = false;\n if (cursor) {\n const index = contexts.findIndex(context => context.connection.id === cursor.connectionId);\n exactMatch = index !== -1;\n startIndex = exactMatch\n ? index\n : contexts.findIndex(context => context.connection.id.localeCompare(cursor.connectionId) > 0);\n if (startIndex === -1) return { items: [], nextCursor: null };\n }\n\n for (let index = startIndex; index < contexts.length; index++) {\n const context = contexts[index]!;\n const baseSourceIds = baseSourceIdsFor(context.connection.id, input.sourceIds);\n if (baseSourceIds.length === 0) continue;\n const page = await context.intake.listItems({\n orgId: input.orgId,\n userId: input.userId,\n sourceIds: baseSourceIds,\n ...(index === startIndex && exactMatch && cursor?.inner ? { cursor: cursor.inner } : {}),\n });\n const nextCursor = page.nextCursor\n ? encodePageCursor({ connectionId: context.connection.id, inner: page.nextCursor })\n : index + 1 < contexts.length\n ? encodePageCursor({ connectionId: contexts[index + 1]!.connection.id })\n : null;\n return {\n items: page.items.map(item => ({\n ...item,\n sourceId: encodeScopedSourceId(context.connection.id, item.sourceId),\n metadata: { ...(item.metadata ?? {}), connectionId: context.connection.id },\n })),\n nextCursor,\n };\n }\n return { items: [], nextCursor: null };\n }\n\n async listIssues(input: ListIntakeIssuesInput): Promise<{ issues: IntakeIssue[]; nextCursor: string | null }> {\n const resolved = await this.#intakeForConnection(input.connection);\n // Scope to the connection that was actually resolved (which may be the\n // sole-connection fallback), so a source id scoped to a different\n // connection is dropped instead of being read against this one.\n const connectionId = this.connectionIdOf(resolved.connection);\n const baseSourceIds = connectionId\n ? baseSourceIdsFor(connectionId, input.sourceIds)\n : input.sourceIds.map(sourceId => decodeScopedSourceId(sourceId)?.sourceId ?? sourceId);\n return resolved.intake.listIssues({\n ...input,\n connection: resolved.connection,\n sourceIds: baseSourceIds,\n });\n }\n\n async getIssue(input: GetIntakeIssueInput): Promise<IntakeIssueDetail | null> {\n const resolved = await this.#intakeForConnection(input.connection);\n return resolved.intake.getIssue({\n ...this.#withBaseSource(input),\n connection: resolved.connection,\n });\n }\n\n async createComment(input: CreateIntakeCommentInput): Promise<CreatedIntakeComment | null> {\n const resolved = await this.#intakeForConnection(input.connection);\n return resolved.intake.createComment({\n ...this.#withBaseSource(input),\n connection: resolved.connection,\n });\n }\n\n async updateIssue(input: UpdateIntakeIssueInput): Promise<IntakeIssue | null> {\n const resolved = await this.#intakeForConnection(input.connection);\n return resolved.intake.updateIssue({\n ...this.#withBaseSource(input),\n connection: resolved.connection,\n });\n }\n\n #withBaseSource<T extends { sourceId?: string }>(input: T): T {\n if (!input.sourceId) return input;\n const scoped = decodeScopedSourceId(input.sourceId);\n return scoped ? { ...input, sourceId: scoped.sourceId } : input;\n }\n}\n"],"mappings":";;;;;AA4BA,MAAa,UAAU;AACvB,MAAM,0BAA0B;AAChC,MAAM,uBAAuB;AAC7B,MAAM,kBAAkB,CAAC,gCAAgC,+BAA+B;AAmBxF,SAAgB,qBAAqB,cAAsB,UAA0B;CACnF,OAAO,GAAG,uBAAuB,OAAO,KAAK,KAAK,UAAU;EAAE;EAAc;CAAS,CAAC,CAAC,CAAC,CAAC,SAAS,WAAW;AAC/G;AAEA,SAAgB,qBAAqB,OAAsC;CACzE,IAAI,CAAC,MAAM,WAAW,oBAAoB,GAAG,OAAO;CACpD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AAO;EAAS,IAAI;CAC5D;AACF"}
@@ -1,33 +1,24 @@
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 } from '../../../capabilities/intake.js';
5
3
  import type { RouteAuth } from '../../../routes/route.js';
6
4
  import type { IntakeStorage } from '../../../storage/domains/intake/base.js';
7
5
  import type { FactoryProjectsStorage } from '../../../storage/domains/projects/base.js';
8
- import type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../../base.js';
6
+ import type { IntegrationContext, IntegrationTools } from '../../base.js';
9
7
  import type { IncidentioEventRules, IncidentioRuleOverrides } from '../../incidentio/default-rules.js';
10
- import type { PlatformApiClientConfig } from '../api-client.js';
8
+ import type { IssueReconciler } from '../../issue-reconciler.js';
9
+ import { PlatformConnectIntegration } from '../foundation/integration.js';
10
+ import type { PlatformConnectOption } from '../platform-connect.js';
11
+ import { PlatformIncidentioIntake } from './intake.js';
12
+ export { decodeScopedSourceId, encodeScopedSourceId } from './intake.js';
11
13
  export interface PlatformIncidentioIntegrationConfig {
12
- clientConfig?: PlatformApiClientConfig;
14
+ /** The Connect client, or options to build one; defaults to the platform environment. */
15
+ connect?: PlatformConnectOption;
13
16
  /** Per-event replacements for the default Factory incident.io rules. */
14
17
  rules?: IncidentioRuleOverrides;
15
18
  }
16
- interface PlatformIntegrationConnection {
17
- id: string;
18
- integrationId: string;
19
- status: 'active' | 'needs_reauth';
20
- accountLabel: string | null;
21
- }
22
- interface ScopedSourceId {
23
- connectionId: string;
24
- sourceId: string;
25
- }
26
- export declare function encodeScopedSourceId(connectionId: string, sourceId: string): string;
27
- export declare function decodeScopedSourceId(value: string): ScopedSourceId | null;
28
- export declare class PlatformIncidentioIntegration implements FactoryIntegration {
19
+ export declare class PlatformIncidentioIntegration extends PlatformConnectIntegration {
29
20
  #private;
30
- readonly id = "incidentio";
21
+ readonly intake: PlatformIncidentioIntake;
31
22
  constructor(config?: PlatformIncidentioIntegrationConfig);
32
23
  /** Event rules driving automatic follow-up materialization and close handling. */
33
24
  get rules(): IncidentioEventRules;
@@ -56,13 +47,11 @@ export declare class PlatformIncidentioIntegration implements FactoryIntegration
56
47
  agentTools(args: {
57
48
  requestContext: RequestContext;
58
49
  }): Promise<IntegrationTools>;
59
- listConnections(): Promise<PlatformIntegrationConnection[]>;
60
50
  hasActiveConnections(): Promise<boolean>;
61
51
  clearCaches(): void;
62
- readonly intake: Intake;
63
52
  /** Scoped ids name their base source; legacy unscoped ids are the base source. */
64
53
  isFollowUpSource(sourceId: string): boolean;
65
- workers(ctx: IntegrationContext): MastraWorker[];
54
+ protected reconcile(ctx: IntegrationContext): IssueReconciler | null;
66
55
  /**
67
56
  * The integration's HTTP surface: `/web/incidentio/*` Mastra `apiRoutes`
68
57
  * (status + follow-up listing/detail for Intake), aggregated across every
@@ -71,5 +60,4 @@ export declare class PlatformIncidentioIntegration implements FactoryIntegration
71
60
  routes(ctx: IntegrationContext): ApiRoute[];
72
61
  diagnostics(): Record<string, unknown>;
73
62
  }
74
- export {};
75
63
  //# sourceMappingURL=integration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/incidentio/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,EAUP,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,KAAK,EAAE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