@mastra/factory 0.30.0 → 0.31.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -10
- package/dist/factory.d.ts +12 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +72 -31
- package/dist/factory.js.map +1 -1
- package/dist/integrations/gitlab/api.d.ts +3 -2
- package/dist/integrations/gitlab/api.d.ts.map +1 -1
- package/dist/integrations/gitlab/api.js +12 -9
- package/dist/integrations/gitlab/api.js.map +1 -1
- package/dist/integrations/issue-reconcile-worker.d.ts +5 -0
- package/dist/integrations/issue-reconcile-worker.d.ts.map +1 -1
- package/dist/integrations/issue-reconcile-worker.js +17 -1
- package/dist/integrations/issue-reconcile-worker.js.map +1 -1
- package/dist/integrations/platform/connect/routes.d.ts +22 -13
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
- package/dist/integrations/platform/connect/routes.js +63 -64
- package/dist/integrations/platform/connect/routes.js.map +1 -1
- package/dist/integrations/platform/foundation/connect-binding.d.ts +125 -0
- package/dist/integrations/platform/foundation/connect-binding.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/connect-binding.js +252 -0
- package/dist/integrations/platform/foundation/connect-binding.js.map +1 -0
- package/dist/integrations/platform/foundation/connect-event-poller.d.ts +49 -0
- package/dist/integrations/platform/foundation/connect-event-poller.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/connect-event-poller.js +304 -0
- package/dist/integrations/platform/foundation/connect-event-poller.js.map +1 -0
- package/dist/integrations/platform/foundation/connect-events.d.ts +31 -0
- package/dist/integrations/platform/foundation/connect-events.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/connect-events.js +7 -0
- package/dist/integrations/platform/foundation/connect-events.js.map +1 -0
- package/dist/integrations/platform/foundation/index.d.ts +10 -0
- package/dist/integrations/platform/foundation/index.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/index.js +6 -0
- package/dist/integrations/platform/foundation/intake.d.ts +39 -0
- package/dist/integrations/platform/foundation/intake.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/intake.js +45 -0
- package/dist/integrations/platform/foundation/intake.js.map +1 -0
- package/dist/integrations/platform/foundation/integration.d.ts +84 -0
- package/dist/integrations/platform/foundation/integration.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/integration.js +107 -0
- package/dist/integrations/platform/foundation/integration.js.map +1 -0
- package/dist/integrations/platform/github/event-worker.d.ts +2 -2
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +4 -8
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +3 -0
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +131 -70
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/gitlab/connect-events.d.ts +22 -0
- package/dist/integrations/platform/gitlab/connect-events.d.ts.map +1 -0
- package/dist/integrations/platform/gitlab/connect-events.js +49 -0
- package/dist/integrations/platform/gitlab/connect-events.js.map +1 -0
- package/dist/integrations/platform/gitlab/integration.d.ts +24 -15
- package/dist/integrations/platform/gitlab/integration.d.ts.map +1 -1
- package/dist/integrations/platform/gitlab/integration.js +61 -26
- package/dist/integrations/platform/gitlab/integration.js.map +1 -1
- package/dist/integrations/platform/incidentio/intake.d.ts +33 -0
- package/dist/integrations/platform/incidentio/intake.d.ts.map +1 -0
- package/dist/integrations/platform/incidentio/intake.js +271 -0
- package/dist/integrations/platform/incidentio/intake.js.map +1 -0
- package/dist/integrations/platform/incidentio/integration.d.ts +11 -23
- package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -1
- package/dist/integrations/platform/incidentio/integration.js +27 -297
- package/dist/integrations/platform/incidentio/integration.js.map +1 -1
- package/dist/integrations/platform/jira/intake.d.ts +60 -0
- package/dist/integrations/platform/jira/intake.d.ts.map +1 -0
- package/dist/integrations/platform/jira/intake.js +445 -0
- package/dist/integrations/platform/jira/intake.js.map +1 -0
- package/dist/integrations/platform/jira/integration.d.ts +13 -37
- package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
- package/dist/integrations/platform/jira/integration.js +29 -468
- package/dist/integrations/platform/jira/integration.js.map +1 -1
- package/dist/integrations/platform/linear/event-worker.d.ts +2 -2
- package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/linear/event-worker.js +5 -9
- package/dist/integrations/platform/linear/event-worker.js.map +1 -1
- package/dist/integrations/platform/linear/integration.d.ts +3 -1
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
- package/dist/integrations/platform/linear/integration.js +9 -9
- package/dist/integrations/platform/linear/integration.js.map +1 -1
- package/dist/integrations/platform/logging.d.ts +6 -0
- package/dist/integrations/platform/logging.d.ts.map +1 -0
- package/dist/integrations/platform/logging.js +25 -0
- package/dist/integrations/platform/logging.js.map +1 -0
- package/dist/integrations/platform/platform-connect.d.ts +38 -0
- package/dist/integrations/platform/platform-connect.d.ts.map +1 -0
- package/dist/integrations/platform/platform-connect.js +109 -0
- package/dist/integrations/platform/platform-connect.js.map +1 -0
- package/dist/integrations/platform/vanta/integration.d.ts +12 -18
- package/dist/integrations/platform/vanta/integration.d.ts.map +1 -1
- package/dist/integrations/platform/vanta/integration.js +38 -38
- package/dist/integrations/platform/vanta/integration.js.map +1 -1
- package/dist/memory-embedder.d.ts +11 -0
- package/dist/memory-embedder.d.ts.map +1 -0
- package/dist/memory-embedder.js +19 -0
- package/dist/memory-embedder.js.map +1 -0
- package/dist/metrics/config.d.ts +1 -1
- package/dist/metrics/config.d.ts.map +1 -1
- package/dist/metrics/config.js +1 -0
- package/dist/metrics/config.js.map +1 -1
- package/dist/metrics/index.js +2 -2
- package/dist/metrics/index.js.map +1 -1
- package/dist/metrics/sandbox.d.ts +3 -3
- package/dist/metrics/sandbox.js +13 -13
- package/dist/metrics/sandbox.js.map +1 -1
- package/dist/metrics/session.d.ts +28 -0
- package/dist/metrics/session.d.ts.map +1 -0
- package/dist/metrics/session.js +76 -0
- package/dist/metrics/session.js.map +1 -0
- package/dist/routes/source-control-sessions.d.ts +5 -0
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +65 -7
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +5 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +1 -0
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts +29 -1
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +156 -23
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/public-failure-reason.js +1 -1
- package/dist/rules/public-failure-reason.js.map +1 -1
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +33 -9
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +2 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +4 -2
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/work-item-branch.d.ts +7 -1
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +9 -1
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/card-facts.d.ts.map +1 -1
- package/dist/work-items/card-facts.js +2 -2
- package/dist/work-items/card-facts.js.map +1 -1
- package/package.json +9 -9
- package/dist/integrations/platform/api-client.d.ts +0 -34
- package/dist/integrations/platform/api-client.d.ts.map +0 -1
- package/dist/integrations/platform/api-client.js +0 -186
- package/dist/integrations/platform/api-client.js.map +0 -1
- package/dist/integrations/platform/gitlab/event-worker.d.ts +0 -64
- package/dist/integrations/platform/gitlab/event-worker.d.ts.map +0 -1
- package/dist/integrations/platform/gitlab/event-worker.js +0 -304
- package/dist/integrations/platform/gitlab/event-worker.js.map +0 -1
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { parseGitLabWebhookBody, processGitLabWebhook } from "../../gitlab/webhook.js";
|
|
2
|
-
import { PlatformApiError } from "../api-client.js";
|
|
3
|
-
import { NoopLeaseProvider, isLeaseProvider } from "@mastra/core/events";
|
|
4
|
-
import { MastraWorker } from "@mastra/core/worker";
|
|
5
|
-
// src/integrations/platform/gitlab/event-worker.ts
|
|
6
|
-
const DEFAULT_POLL_INTERVAL_MS = 2e4;
|
|
7
|
-
const EVENT_PAGE_SIZE = 500;
|
|
8
|
-
/**
|
|
9
|
-
* Pages drained per connection per cycle. A connection that never runs dry
|
|
10
|
-
* (a busy group webhook, or a backlog after downtime) hands over to the next
|
|
11
|
-
* connection after this many pages and resumes from its saved cursor next tick.
|
|
12
|
-
*/
|
|
13
|
-
const MAX_PAGES_PER_CONNECTION_PER_CYCLE = 10;
|
|
14
|
-
const MIN_LEASE_TTL_MS = 3e4;
|
|
15
|
-
const CURSOR_ORG_ID = "__platform_gitlab_event_worker__";
|
|
16
|
-
const CURSOR_USER_ID = "worker";
|
|
17
|
-
const DELIVERY_ID_PREFIX = "platform";
|
|
18
|
-
/**
|
|
19
|
-
* Tails the Platform event log for every active GitLab connection and feeds
|
|
20
|
-
* each stored webhook body through the same ingress the direct
|
|
21
|
-
* `/web/gitlab/webhook` route uses. A Platform-managed connection has no
|
|
22
|
-
* project webhook pointing at Factory, so this is how issue, note, merge
|
|
23
|
-
* request and push events reach the rules engine and subscribed sessions.
|
|
24
|
-
*
|
|
25
|
-
* One replica polls at a time (lease). Each connection keeps its own cursor,
|
|
26
|
-
* persisted only after a whole page has been processed, so a crash mid-page
|
|
27
|
-
* replays the page rather than losing it; replay handling in the rules ingress
|
|
28
|
-
* and the delivery-id dedupe keys make that safe.
|
|
29
|
-
*/
|
|
30
|
-
var PlatformGitLabEventWorker = class extends MastraWorker {
|
|
31
|
-
name = "platform-gitlab-events";
|
|
32
|
-
#client;
|
|
33
|
-
#controller;
|
|
34
|
-
#gitlab;
|
|
35
|
-
#storage;
|
|
36
|
-
#listConnections;
|
|
37
|
-
#ingestFactoryEvent;
|
|
38
|
-
#intervalMs;
|
|
39
|
-
#now;
|
|
40
|
-
#process;
|
|
41
|
-
#leaseOwner = globalThis.crypto.randomUUID();
|
|
42
|
-
#running = false;
|
|
43
|
-
#timer;
|
|
44
|
-
#leaseRenewalTimer;
|
|
45
|
-
#inFlight;
|
|
46
|
-
#leaseProvider = NoopLeaseProvider;
|
|
47
|
-
#leaseTtlMs;
|
|
48
|
-
#hasLease = false;
|
|
49
|
-
#startedAt = 0;
|
|
50
|
-
#settings = {
|
|
51
|
-
version: 1,
|
|
52
|
-
connections: {}
|
|
53
|
-
};
|
|
54
|
-
constructor(config) {
|
|
55
|
-
super();
|
|
56
|
-
this.#client = config.client;
|
|
57
|
-
this.#controller = config.controller;
|
|
58
|
-
this.#gitlab = config.gitlab;
|
|
59
|
-
this.#storage = config.storage;
|
|
60
|
-
this.#listConnections = config.listConnections;
|
|
61
|
-
this.#ingestFactoryEvent = config.ingestFactoryEvent;
|
|
62
|
-
this.#intervalMs = config.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
63
|
-
if (!Number.isFinite(this.#intervalMs) || this.#intervalMs <= 0) throw new Error("Platform GitLab event polling interval must be a positive number.");
|
|
64
|
-
this.#leaseTtlMs = Math.max(MIN_LEASE_TTL_MS, this.#intervalMs * 3);
|
|
65
|
-
this.#now = config.now ?? Date.now;
|
|
66
|
-
this.#process = config.process ?? processGitLabWebhook;
|
|
67
|
-
}
|
|
68
|
-
async init(deps) {
|
|
69
|
-
await super.init(deps);
|
|
70
|
-
this.#leaseProvider = getLeaseProvider(deps.pubsub);
|
|
71
|
-
}
|
|
72
|
-
async start() {
|
|
73
|
-
if (this.#running) return;
|
|
74
|
-
if (!this.deps) throw new Error("PlatformGitLabEventWorker: call init() before start()");
|
|
75
|
-
this.#startedAt = this.#now() - 1;
|
|
76
|
-
this.#settings = normalizeSettings(await this.#storage.settings.get(CURSOR_ORG_ID, CURSOR_USER_ID));
|
|
77
|
-
this.#running = true;
|
|
78
|
-
this.deps.logger.debug("Platform GitLab event polling started", {
|
|
79
|
-
intervalMs: this.#intervalMs,
|
|
80
|
-
leaseTtlMs: this.#leaseTtlMs
|
|
81
|
-
});
|
|
82
|
-
this.#schedule(0);
|
|
83
|
-
}
|
|
84
|
-
async stop() {
|
|
85
|
-
if (!this.#running) return;
|
|
86
|
-
this.#running = false;
|
|
87
|
-
if (this.#timer) clearTimeout(this.#timer);
|
|
88
|
-
this.#timer = void 0;
|
|
89
|
-
this.#stopLeaseRenewal();
|
|
90
|
-
await this.#inFlight;
|
|
91
|
-
if (this.#hasLease) {
|
|
92
|
-
await this.#leaseProvider.releaseLease(this.#leaseKey(), this.#leaseOwner).catch(() => void 0);
|
|
93
|
-
this.#hasLease = false;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
get isRunning() {
|
|
97
|
-
return this.#running;
|
|
98
|
-
}
|
|
99
|
-
#schedule(delayMs) {
|
|
100
|
-
if (!this.#running) return;
|
|
101
|
-
this.#timer = setTimeout(() => {
|
|
102
|
-
this.#timer = void 0;
|
|
103
|
-
const run = this.#tick();
|
|
104
|
-
this.#inFlight = run;
|
|
105
|
-
run.finally(() => {
|
|
106
|
-
if (this.#inFlight === run) this.#inFlight = void 0;
|
|
107
|
-
});
|
|
108
|
-
}, delayMs);
|
|
109
|
-
this.#timer.unref?.();
|
|
110
|
-
}
|
|
111
|
-
async #tick() {
|
|
112
|
-
let nextDelay = this.#intervalMs;
|
|
113
|
-
try {
|
|
114
|
-
if (!await this.#ensureLease()) return;
|
|
115
|
-
nextDelay = await this.#poll();
|
|
116
|
-
} catch (error) {
|
|
117
|
-
nextDelay = retryDelay(error, this.#intervalMs);
|
|
118
|
-
this.deps?.logger.error("Platform GitLab event polling cycle failed", {
|
|
119
|
-
error: error instanceof Error ? error.message : String(error),
|
|
120
|
-
retryInMs: nextDelay
|
|
121
|
-
});
|
|
122
|
-
} finally {
|
|
123
|
-
this.#schedule(nextDelay);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async #ensureLease() {
|
|
127
|
-
if (this.#hasLease) return true;
|
|
128
|
-
const result = await this.#leaseProvider.acquireLease(this.#leaseKey(), this.#leaseOwner, this.#leaseTtlMs);
|
|
129
|
-
this.#hasLease = result.acquired;
|
|
130
|
-
if (this.#hasLease) this.#startLeaseRenewal();
|
|
131
|
-
return this.#hasLease;
|
|
132
|
-
}
|
|
133
|
-
#startLeaseRenewal() {
|
|
134
|
-
if (this.#leaseRenewalTimer) return;
|
|
135
|
-
this.#leaseRenewalTimer = setInterval(() => {
|
|
136
|
-
this.#leaseProvider.renewLease(this.#leaseKey(), this.#leaseOwner, this.#leaseTtlMs).then((renewed) => {
|
|
137
|
-
if (!renewed) {
|
|
138
|
-
this.#hasLease = false;
|
|
139
|
-
this.#stopLeaseRenewal();
|
|
140
|
-
}
|
|
141
|
-
}).catch((error) => {
|
|
142
|
-
this.#hasLease = false;
|
|
143
|
-
this.#stopLeaseRenewal();
|
|
144
|
-
this.deps?.logger.warn("Platform GitLab event polling lease renewal failed", { error: error instanceof Error ? error.message : String(error) });
|
|
145
|
-
});
|
|
146
|
-
}, Math.floor(this.#leaseTtlMs / 3));
|
|
147
|
-
this.#leaseRenewalTimer.unref?.();
|
|
148
|
-
}
|
|
149
|
-
#stopLeaseRenewal() {
|
|
150
|
-
if (this.#leaseRenewalTimer) clearInterval(this.#leaseRenewalTimer);
|
|
151
|
-
this.#leaseRenewalTimer = void 0;
|
|
152
|
-
}
|
|
153
|
-
async #poll() {
|
|
154
|
-
const connections = (await this.#listConnections()).filter((connection) => connection.status === "active");
|
|
155
|
-
let retryInMs = this.#intervalMs;
|
|
156
|
-
for (const connection of connections) {
|
|
157
|
-
if (!this.#running || !this.#hasLease) break;
|
|
158
|
-
try {
|
|
159
|
-
await this.#pollConnection(connection.id);
|
|
160
|
-
} catch (error) {
|
|
161
|
-
if (error instanceof PlatformApiError && (error.status === 401 || error.status === 404)) {
|
|
162
|
-
this.deps?.logger.warn("Platform GitLab connection needs reauthorization; skipped this cycle", {
|
|
163
|
-
connectionId: connection.id,
|
|
164
|
-
status: error.status
|
|
165
|
-
});
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
const delay = retryDelay(error, this.#intervalMs);
|
|
169
|
-
retryInMs = Math.max(retryInMs, delay);
|
|
170
|
-
this.deps?.logger.error("Platform GitLab connection event polling failed", {
|
|
171
|
-
connectionId: connection.id,
|
|
172
|
-
error: error instanceof Error ? error.message : String(error),
|
|
173
|
-
retryInMs: delay
|
|
174
|
-
});
|
|
175
|
-
if (error instanceof PlatformApiError && error.status === 429) break;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return retryInMs;
|
|
179
|
-
}
|
|
180
|
-
async #pollConnection(connectionId) {
|
|
181
|
-
if (!this.#settings.connections[connectionId]) {
|
|
182
|
-
this.#settings.connections[connectionId] = { afterEventId: `${this.#startedAt}-0` };
|
|
183
|
-
await this.#saveSettings();
|
|
184
|
-
}
|
|
185
|
-
for (let pageIndex = 0; this.#running && this.#hasLease; pageIndex += 1) {
|
|
186
|
-
if (pageIndex >= MAX_PAGES_PER_CONNECTION_PER_CYCLE) {
|
|
187
|
-
this.deps?.logger.debug("Platform GitLab connection page budget reached; resuming next cycle", {
|
|
188
|
-
connectionId,
|
|
189
|
-
pages: pageIndex
|
|
190
|
-
});
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
const cursor = this.#settings.connections[connectionId];
|
|
194
|
-
const query = new URLSearchParams({
|
|
195
|
-
afterEventId: cursor.afterEventId,
|
|
196
|
-
limit: String(EVENT_PAGE_SIZE)
|
|
197
|
-
});
|
|
198
|
-
const pollStartedAt = performance.now();
|
|
199
|
-
const page = await this.#client.request("GET", `/v2/connections/${encodeURIComponent(connectionId)}/events?${query}`);
|
|
200
|
-
this.deps?.logger.debug("Platform GitLab connection event poll completed", {
|
|
201
|
-
connectionId,
|
|
202
|
-
eventCount: page.events.length,
|
|
203
|
-
latencyMs: Math.round(performance.now() - pollStartedAt)
|
|
204
|
-
});
|
|
205
|
-
if (page.events.length === 0 || !page.nextCursor) return;
|
|
206
|
-
for (const event of page.events) {
|
|
207
|
-
if (!this.#running || !this.#hasLease) return;
|
|
208
|
-
await this.#processEvent(connectionId, event);
|
|
209
|
-
}
|
|
210
|
-
if (page.nextCursor === cursor.afterEventId) return;
|
|
211
|
-
if (!this.#hasLease) return;
|
|
212
|
-
this.#settings.connections[connectionId] = { afterEventId: page.nextCursor };
|
|
213
|
-
await this.#saveSettings();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
async #processEvent(connectionId, event) {
|
|
217
|
-
if (!event.id) {
|
|
218
|
-
this.deps?.logger.warn("Platform GitLab event log returned an event without an id", { connectionId });
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
const deliveryId = `${DELIVERY_ID_PREFIX}:${connectionId}:${event.id}`;
|
|
222
|
-
const parsed = parseGitLabWebhookBody(event.payload, deliveryId);
|
|
223
|
-
if (!parsed) {
|
|
224
|
-
this.deps?.logger.debug("Platform GitLab event ignored: unsupported or malformed body", {
|
|
225
|
-
connectionId,
|
|
226
|
-
eventId: event.id,
|
|
227
|
-
eventType: event.eventType
|
|
228
|
-
});
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const result = await this.#process(parsed, {
|
|
232
|
-
ingestFactoryEvent: this.#ingestFactoryEvent,
|
|
233
|
-
controller: this.#controller,
|
|
234
|
-
gitlab: this.#gitlab,
|
|
235
|
-
sourceConnectionId: connectionId,
|
|
236
|
-
onConnectionMismatch: (subscription) => {
|
|
237
|
-
this.deps?.logger.debug("Platform GitLab event skipped: subscription belongs to another connection", {
|
|
238
|
-
deliveryId,
|
|
239
|
-
subscriptionId: subscription.id,
|
|
240
|
-
subscriptionConnectionId: subscription.data.installationExternalId
|
|
241
|
-
});
|
|
242
|
-
},
|
|
243
|
-
onTargetSkipped: (subscription) => {
|
|
244
|
-
this.deps?.logger.debug("Platform GitLab event skipped: thread is not held here", {
|
|
245
|
-
deliveryId,
|
|
246
|
-
subscriptionId: subscription.id,
|
|
247
|
-
threadId: subscription.threadId
|
|
248
|
-
});
|
|
249
|
-
},
|
|
250
|
-
onSenderRejected: (notification) => {
|
|
251
|
-
this.deps?.logger.debug("Platform GitLab event dropped: sender not authorized", {
|
|
252
|
-
deliveryId,
|
|
253
|
-
repository: notification.metadata.projectPath,
|
|
254
|
-
sender: notification.metadata.sender,
|
|
255
|
-
kind: notification.kind
|
|
256
|
-
});
|
|
257
|
-
},
|
|
258
|
-
onTargetError: (subscription, error) => {
|
|
259
|
-
this.deps?.logger.error("Platform GitLab event delivery failed for a subscription", {
|
|
260
|
-
deliveryId,
|
|
261
|
-
subscriptionId: subscription.id,
|
|
262
|
-
resourceId: subscription.resourceId,
|
|
263
|
-
threadId: subscription.threadId,
|
|
264
|
-
error: error instanceof Error ? error.message : String(error)
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
if (result.status !== 202) this.deps?.logger.warn("Platform GitLab event was not accepted by the webhook processor", {
|
|
269
|
-
connectionId,
|
|
270
|
-
deliveryId,
|
|
271
|
-
status: result.status
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
async #saveSettings() {
|
|
275
|
-
await this.#storage.settings.save(CURSOR_ORG_ID, CURSOR_USER_ID, this.#settings);
|
|
276
|
-
}
|
|
277
|
-
#leaseKey() {
|
|
278
|
-
return `${this.name}:${this.#storage.integrationId}`;
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
function getLeaseProvider(pubsub) {
|
|
282
|
-
const getProvider = pubsub.getLeaseProvider;
|
|
283
|
-
if (typeof getProvider === "function") return getProvider.call(pubsub) ?? NoopLeaseProvider;
|
|
284
|
-
return isLeaseProvider(pubsub) ? pubsub : NoopLeaseProvider;
|
|
285
|
-
}
|
|
286
|
-
function normalizeSettings(value) {
|
|
287
|
-
if (!value || value.version !== 1 || !value.connections || typeof value.connections !== "object") return {
|
|
288
|
-
version: 1,
|
|
289
|
-
connections: {}
|
|
290
|
-
};
|
|
291
|
-
const connections = {};
|
|
292
|
-
for (const [connectionId, cursor] of Object.entries(value.connections)) if (typeof cursor?.afterEventId === "string" && cursor.afterEventId.length > 0) connections[connectionId] = { afterEventId: cursor.afterEventId };
|
|
293
|
-
return {
|
|
294
|
-
version: 1,
|
|
295
|
-
connections
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
function retryDelay(error, fallbackMs) {
|
|
299
|
-
if (error instanceof PlatformApiError && error.status === 429 && error.retryAfterSeconds !== null) return Math.max(fallbackMs, error.retryAfterSeconds * 1e3);
|
|
300
|
-
return fallbackMs;
|
|
301
|
-
}
|
|
302
|
-
export { PlatformGitLabEventWorker };
|
|
303
|
-
|
|
304
|
-
//# sourceMappingURL=event-worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-worker.js","names":[],"sources":["../../../../src/integrations/platform/gitlab/event-worker.ts"],"sourcesContent":["import type { MountedMastraCode } from '@mastra/code-sdk';\nimport { isLeaseProvider, NoopLeaseProvider } from '@mastra/core/events';\nimport type { LeaseProvider, PubSub } from '@mastra/core/events';\nimport { MastraWorker } from '@mastra/core/worker';\nimport type { WorkerDeps } from '@mastra/core/worker';\n\nimport type { IntegrationStorageHandle } from '../../../storage/domains/integrations/base.js';\nimport type { GitLabWebhookDispatchIntegration } from '../../gitlab/webhook-dispatch.js';\nimport { parseGitLabWebhookBody, processGitLabWebhook } from '../../gitlab/webhook.js';\nimport type { ParsedGitLabWebhook } from '../../gitlab/webhook.js';\nimport type { PlatformApiClient } from '../api-client.js';\nimport { PlatformApiError } from '../api-client.js';\n\nconst DEFAULT_POLL_INTERVAL_MS = 20_000;\nconst EVENT_PAGE_SIZE = 500;\n/**\n * Pages drained per connection per cycle. A connection that never runs dry\n * (a busy group webhook, or a backlog after downtime) hands over to the next\n * connection after this many pages and resumes from its saved cursor next tick.\n */\nconst MAX_PAGES_PER_CONNECTION_PER_CYCLE = 10;\nconst MIN_LEASE_TTL_MS = 30_000;\nconst CURSOR_ORG_ID = '__platform_gitlab_event_worker__';\nconst CURSOR_USER_ID = 'worker';\nconst DELIVERY_ID_PREFIX = 'platform';\n\ntype PlatformGitLabEventWorkerSettings = {\n version: 1;\n connections: Record<string, { afterEventId: string }>;\n};\n\nexport type PlatformGitLabEventStorage = IntegrationStorageHandle<\n Record<string, unknown>,\n PlatformGitLabEventWorkerSettings,\n Record<string, unknown>\n>;\n\n/** One row of the Platform integration event log. */\nexport interface IntegrationEventEntry {\n id: string;\n timestamp: number;\n integrationId: string;\n eventType: string;\n sourceEventId: string | null;\n payload: unknown;\n}\n\nexport interface PlatformGitLabEventConnection {\n id: string;\n status: 'active' | 'needs_reauth';\n}\n\nexport type PlatformGitLabEventDispatchIntegration = GitLabWebhookDispatchIntegration;\n\nexport interface PlatformGitLabEventWorkerConfig {\n client: PlatformApiClient;\n controller: MountedMastraCode['controller'];\n gitlab: PlatformGitLabEventDispatchIntegration;\n storage: PlatformGitLabEventStorage;\n /** Platform connections to tail; only `active` ones are polled. */\n listConnections: () => Promise<PlatformGitLabEventConnection[]>;\n ingestFactoryEvent?: (event: ParsedGitLabWebhook) => Promise<unknown>;\n intervalMs?: number;\n now?: () => number;\n process?: typeof processGitLabWebhook;\n}\n\n/**\n * Tails the Platform event log for every active GitLab connection and feeds\n * each stored webhook body through the same ingress the direct\n * `/web/gitlab/webhook` route uses. A Platform-managed connection has no\n * project webhook pointing at Factory, so this is how issue, note, merge\n * request and push events reach the rules engine and subscribed sessions.\n *\n * One replica polls at a time (lease). Each connection keeps its own cursor,\n * persisted only after a whole page has been processed, so a crash mid-page\n * replays the page rather than losing it; replay handling in the rules ingress\n * and the delivery-id dedupe keys make that safe.\n */\nexport class PlatformGitLabEventWorker extends MastraWorker {\n readonly name = 'platform-gitlab-events';\n\n readonly #client: PlatformApiClient;\n readonly #controller: MountedMastraCode['controller'];\n readonly #gitlab: PlatformGitLabEventDispatchIntegration;\n readonly #storage: PlatformGitLabEventStorage;\n readonly #listConnections: () => Promise<PlatformGitLabEventConnection[]>;\n readonly #ingestFactoryEvent: ((event: ParsedGitLabWebhook) => Promise<unknown>) | undefined;\n readonly #intervalMs: number;\n readonly #now: () => number;\n readonly #process: typeof processGitLabWebhook;\n readonly #leaseOwner = globalThis.crypto.randomUUID();\n\n #running = false;\n #timer: ReturnType<typeof setTimeout> | undefined;\n #leaseRenewalTimer: ReturnType<typeof setInterval> | undefined;\n #inFlight: Promise<void> | undefined;\n #leaseProvider: LeaseProvider = NoopLeaseProvider;\n #leaseTtlMs: number;\n #hasLease = false;\n #startedAt = 0;\n #settings: PlatformGitLabEventWorkerSettings = { version: 1, connections: {} };\n\n constructor(config: PlatformGitLabEventWorkerConfig) {\n super();\n this.#client = config.client;\n this.#controller = config.controller;\n this.#gitlab = config.gitlab;\n this.#storage = config.storage;\n this.#listConnections = config.listConnections;\n this.#ingestFactoryEvent = config.ingestFactoryEvent;\n this.#intervalMs = config.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n if (!Number.isFinite(this.#intervalMs) || this.#intervalMs <= 0) {\n throw new Error('Platform GitLab event polling interval must be a positive number.');\n }\n this.#leaseTtlMs = Math.max(MIN_LEASE_TTL_MS, this.#intervalMs * 3);\n this.#now = config.now ?? Date.now;\n this.#process = config.process ?? processGitLabWebhook;\n }\n\n async init(deps: WorkerDeps): Promise<void> {\n await super.init(deps);\n this.#leaseProvider = getLeaseProvider(deps.pubsub);\n }\n\n async start(): Promise<void> {\n if (this.#running) return;\n if (!this.deps) throw new Error('PlatformGitLabEventWorker: call init() before start()');\n\n this.#startedAt = this.#now() - 1;\n this.#settings = normalizeSettings(await this.#storage.settings.get(CURSOR_ORG_ID, CURSOR_USER_ID));\n this.#running = true;\n this.deps.logger.debug('Platform GitLab event polling started', {\n intervalMs: this.#intervalMs,\n leaseTtlMs: this.#leaseTtlMs,\n });\n this.#schedule(0);\n }\n\n async stop(): Promise<void> {\n if (!this.#running) return;\n this.#running = false;\n if (this.#timer) clearTimeout(this.#timer);\n this.#timer = undefined;\n this.#stopLeaseRenewal();\n await this.#inFlight;\n if (this.#hasLease) {\n await this.#leaseProvider.releaseLease(this.#leaseKey(), this.#leaseOwner).catch(() => undefined);\n this.#hasLease = false;\n }\n }\n\n get isRunning(): boolean {\n return this.#running;\n }\n\n #schedule(delayMs: number): void {\n if (!this.#running) return;\n this.#timer = setTimeout(() => {\n this.#timer = undefined;\n const run = this.#tick();\n this.#inFlight = run;\n void run.finally(() => {\n if (this.#inFlight === run) this.#inFlight = undefined;\n });\n }, delayMs);\n this.#timer.unref?.();\n }\n\n async #tick(): Promise<void> {\n let nextDelay = this.#intervalMs;\n try {\n if (!(await this.#ensureLease())) return;\n nextDelay = await this.#poll();\n } catch (error) {\n nextDelay = retryDelay(error, this.#intervalMs);\n this.deps?.logger.error('Platform GitLab event polling cycle failed', {\n error: error instanceof Error ? error.message : String(error),\n retryInMs: nextDelay,\n });\n } finally {\n this.#schedule(nextDelay);\n }\n }\n\n async #ensureLease(): Promise<boolean> {\n if (this.#hasLease) return true;\n const result = await this.#leaseProvider.acquireLease(this.#leaseKey(), this.#leaseOwner, this.#leaseTtlMs);\n this.#hasLease = result.acquired;\n if (this.#hasLease) this.#startLeaseRenewal();\n return this.#hasLease;\n }\n\n #startLeaseRenewal(): void {\n if (this.#leaseRenewalTimer) return;\n this.#leaseRenewalTimer = setInterval(\n () => {\n void this.#leaseProvider\n .renewLease(this.#leaseKey(), this.#leaseOwner, this.#leaseTtlMs)\n .then(renewed => {\n if (!renewed) {\n this.#hasLease = false;\n this.#stopLeaseRenewal();\n }\n })\n .catch(error => {\n this.#hasLease = false;\n this.#stopLeaseRenewal();\n this.deps?.logger.warn('Platform GitLab event polling lease renewal failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n });\n },\n Math.floor(this.#leaseTtlMs / 3),\n );\n this.#leaseRenewalTimer.unref?.();\n }\n\n #stopLeaseRenewal(): void {\n if (this.#leaseRenewalTimer) clearInterval(this.#leaseRenewalTimer);\n this.#leaseRenewalTimer = undefined;\n }\n\n async #poll(): Promise<number> {\n const connections = (await this.#listConnections()).filter(connection => connection.status === 'active');\n let retryInMs = this.#intervalMs;\n\n for (const connection of connections) {\n if (!this.#running || !this.#hasLease) break;\n try {\n await this.#pollConnection(connection.id);\n } catch (error) {\n if (error instanceof PlatformApiError && (error.status === 401 || error.status === 404)) {\n // Platform no longer serves this connection (revoked, expired or\n // deleted). Its status will read needs_reauth on the next listing;\n // nothing to retry here, so the other connections keep flowing.\n this.deps?.logger.warn('Platform GitLab connection needs reauthorization; skipped this cycle', {\n connectionId: connection.id,\n status: error.status,\n });\n continue;\n }\n const delay = retryDelay(error, this.#intervalMs);\n retryInMs = Math.max(retryInMs, delay);\n this.deps?.logger.error('Platform GitLab connection event polling failed', {\n connectionId: connection.id,\n error: error instanceof Error ? error.message : String(error),\n retryInMs: delay,\n });\n if (error instanceof PlatformApiError && error.status === 429) break;\n }\n }\n return retryInMs;\n }\n\n async #pollConnection(connectionId: string): Promise<void> {\n if (!this.#settings.connections[connectionId]) {\n // Event ids are Redis stream ids (`<unix ms>-<sequence>`), so a\n // synthesized id at start time skips history the same way the GitHub\n // worker's start timestamp does. Events that arrived before Factory was\n // deployed are not work Factory was asked to do.\n this.#settings.connections[connectionId] = { afterEventId: `${this.#startedAt}-0` };\n await this.#saveSettings();\n }\n\n for (let pageIndex = 0; this.#running && this.#hasLease; pageIndex += 1) {\n if (pageIndex >= MAX_PAGES_PER_CONNECTION_PER_CYCLE) {\n this.deps?.logger.debug('Platform GitLab connection page budget reached; resuming next cycle', {\n connectionId,\n pages: pageIndex,\n });\n return;\n }\n const cursor: { afterEventId: string } = this.#settings.connections[connectionId]!;\n const query = new URLSearchParams({ afterEventId: cursor.afterEventId, limit: String(EVENT_PAGE_SIZE) });\n const pollStartedAt = performance.now();\n const page = await this.#client.request<{ events: IntegrationEventEntry[]; nextCursor: string | null }>(\n 'GET',\n `/v2/connections/${encodeURIComponent(connectionId)}/events?${query}`,\n );\n this.deps?.logger.debug('Platform GitLab connection event poll completed', {\n connectionId,\n eventCount: page.events.length,\n latencyMs: Math.round(performance.now() - pollStartedAt),\n });\n if (page.events.length === 0 || !page.nextCursor) return;\n\n for (const event of page.events) {\n if (!this.#running || !this.#hasLease) return;\n await this.#processEvent(connectionId, event);\n }\n\n if (page.nextCursor === cursor.afterEventId) return;\n // A replica that lost its lease while processing this page must not\n // write a cursor over one the new holder has already advanced. The\n // page is replayed there; delivery is deduplicated by delivery id.\n if (!this.#hasLease) return;\n this.#settings.connections[connectionId] = { afterEventId: page.nextCursor };\n await this.#saveSettings();\n }\n }\n\n async #processEvent(connectionId: string, event: IntegrationEventEntry): Promise<void> {\n if (!event.id) {\n this.deps?.logger.warn('Platform GitLab event log returned an event without an id', { connectionId });\n return;\n }\n const deliveryId = `${DELIVERY_ID_PREFIX}:${connectionId}:${event.id}`;\n const parsed = parseGitLabWebhookBody(event.payload, deliveryId);\n if (!parsed) {\n // Pipelines, deployments, wiki edits and the like: acknowledged and\n // dropped, exactly as the direct route treats an unsupported event header.\n this.deps?.logger.debug('Platform GitLab event ignored: unsupported or malformed body', {\n connectionId,\n eventId: event.id,\n eventType: event.eventType,\n });\n return;\n }\n\n const result = await this.#process(parsed, {\n ingestFactoryEvent: this.#ingestFactoryEvent,\n controller: this.#controller,\n // The integration supplies subscription storage and the project-member\n // trust check, so the dispatcher's default author gate applies unchanged.\n gitlab: this.#gitlab,\n sourceConnectionId: connectionId,\n onConnectionMismatch: subscription => {\n // Expected whenever two connections reach the same project: the\n // event is delivered by the connection that created the subscription.\n this.deps?.logger.debug('Platform GitLab event skipped: subscription belongs to another connection', {\n deliveryId,\n subscriptionId: subscription.id,\n subscriptionConnectionId: subscription.data.installationExternalId,\n });\n },\n onTargetSkipped: subscription => {\n // Routine when a subscription's thread belongs to another deployment,\n // so this stays at debug rather than warning on a loop.\n this.deps?.logger.debug('Platform GitLab event skipped: thread is not held here', {\n deliveryId,\n subscriptionId: subscription.id,\n threadId: subscription.threadId,\n });\n },\n onSenderRejected: notification => {\n this.deps?.logger.debug('Platform GitLab event dropped: sender not authorized', {\n deliveryId,\n repository: notification.metadata.projectPath,\n sender: notification.metadata.sender,\n kind: notification.kind,\n });\n },\n onTargetError: (subscription, error) => {\n this.deps?.logger.error('Platform GitLab event delivery failed for a subscription', {\n deliveryId,\n subscriptionId: subscription.id,\n resourceId: subscription.resourceId,\n threadId: subscription.threadId,\n error: error instanceof Error ? error.message : String(error),\n });\n },\n });\n if (result.status !== 202) {\n this.deps?.logger.warn('Platform GitLab event was not accepted by the webhook processor', {\n connectionId,\n deliveryId,\n status: result.status,\n });\n }\n }\n\n async #saveSettings(): Promise<void> {\n await this.#storage.settings.save(CURSOR_ORG_ID, CURSOR_USER_ID, this.#settings);\n }\n\n #leaseKey(): string {\n return `${this.name}:${this.#storage.integrationId}`;\n }\n}\n\nfunction getLeaseProvider(pubsub: PubSub): LeaseProvider {\n const getProvider = (pubsub as PubSub & { getLeaseProvider?: () => LeaseProvider | undefined }).getLeaseProvider;\n if (typeof getProvider === 'function') return getProvider.call(pubsub) ?? NoopLeaseProvider;\n return isLeaseProvider(pubsub) ? pubsub : NoopLeaseProvider;\n}\n\nfunction normalizeSettings(value: PlatformGitLabEventWorkerSettings | null): PlatformGitLabEventWorkerSettings {\n if (!value || value.version !== 1 || !value.connections || typeof value.connections !== 'object') {\n return { version: 1, connections: {} };\n }\n const connections: PlatformGitLabEventWorkerSettings['connections'] = {};\n for (const [connectionId, cursor] of Object.entries(value.connections)) {\n if (typeof cursor?.afterEventId === 'string' && cursor.afterEventId.length > 0) {\n connections[connectionId] = { afterEventId: cursor.afterEventId };\n }\n }\n return { version: 1, connections };\n}\n\nfunction retryDelay(error: unknown, fallbackMs: number): number {\n if (error instanceof PlatformApiError && error.status === 429 && error.retryAfter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