@mastra/github-signals 0.2.3 → 0.2.5-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.
- package/CHANGELOG.md +18 -0
- package/dist/index.cjs +73 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -24
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/github-signals
|
|
2
2
|
|
|
3
|
+
## 0.2.5-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed GitHub polling so stopping a poll prevents in-flight work from sending notifications or writing subscription state. ([#20593](https://github.com/mastra-ai/mastra/pull/20593))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`cdd5c33`](https://github.com/mastra-ai/mastra/commit/cdd5c33ac6c7118a9f139e6dc0e14e6a8ae31658), [`d7cf7fa`](https://github.com/mastra-ai/mastra/commit/d7cf7fafc1ae1b50bd8462dd0e6c671a8606db93), [`0f9a448`](https://github.com/mastra-ai/mastra/commit/0f9a448502157e59f7b76f24360ad497168f5ef8), [`289f4ce`](https://github.com/mastra-ai/mastra/commit/289f4ce16e3293370440172132c52ee787cbc09f), [`4f16ff8`](https://github.com/mastra-ai/mastra/commit/4f16ff824bf2f9b0ddc93f210477c10c8a4fb1ab), [`1c67d85`](https://github.com/mastra-ai/mastra/commit/1c67d85e9da8285662f4dbbf47e0378c3fee0747), [`ba24be6`](https://github.com/mastra-ai/mastra/commit/ba24be662439c331ab23a600041f93803c89eca8), [`842b5fe`](https://github.com/mastra-ai/mastra/commit/842b5fe22b6a7fa811bd14e48eb9af523ac989f2), [`80bdf3a`](https://github.com/mastra-ai/mastra/commit/80bdf3ae16ade6ff63bde0cb16fa2df8ab7dd4dd), [`9ba1247`](https://github.com/mastra-ai/mastra/commit/9ba12470c77f1c03642d720ce67e517e878f666e), [`fd96298`](https://github.com/mastra-ai/mastra/commit/fd96298a8367622f4ebfcaa97b5b6c1fbbd14564), [`6a84954`](https://github.com/mastra-ai/mastra/commit/6a84954a2667f85b6d59da652dab1bbff007ccb0), [`52d8ef0`](https://github.com/mastra-ai/mastra/commit/52d8ef03801f1deb7ee48532fc4190dd4a33916c), [`cdd5c33`](https://github.com/mastra-ai/mastra/commit/cdd5c33ac6c7118a9f139e6dc0e14e6a8ae31658), [`efd5c81`](https://github.com/mastra-ai/mastra/commit/efd5c81cc25fde3c2ddd86fc1178deb4ec176e19), [`0976933`](https://github.com/mastra-ai/mastra/commit/0976933142333ec78451feef265b68bcb45aa5e7), [`242b945`](https://github.com/mastra-ai/mastra/commit/242b94558777bfbdeb42cbfea84afff0b6ad0633), [`fea5cae`](https://github.com/mastra-ai/mastra/commit/fea5caedc7e2cfea51784a15e015952692027abf), [`4b59f78`](https://github.com/mastra-ai/mastra/commit/4b59f786cbc9a7d1ef07a07517dbd4b96865e99d), [`7010c5d`](https://github.com/mastra-ai/mastra/commit/7010c5d15728bf9c5dfe4fb6b1bf80ce23bf143a)]:
|
|
10
|
+
- @mastra/core@1.58.0-alpha.3
|
|
11
|
+
|
|
12
|
+
## 0.2.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Fixed duplicate GitHub signal notifications caused by transient mergeability checks and edits to already-observed bot comments. ([#20736](https://github.com/mastra-ai/mastra/pull/20736))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`8d2399b`](https://github.com/mastra-ai/mastra/commit/8d2399b638f8e0945cf2cda0187dbea8dcf0b784), [`c8002da`](https://github.com/mastra-ai/mastra/commit/c8002da7775c468e2965b6ff5f82045450fa8cb9), [`92be47f`](https://github.com/mastra-ai/mastra/commit/92be47fbd26ffccec0e2131ef7c1d9e70dd5ef4a), [`89200ba`](https://github.com/mastra-ai/mastra/commit/89200bafa05444bb7949b363ce7b743e29867561), [`c950138`](https://github.com/mastra-ai/mastra/commit/c950138e72e4f317a40187e3800588731ab790ce), [`810c7e7`](https://github.com/mastra-ai/mastra/commit/810c7e74929989d8b8b5db52cd3af22cd0998af4), [`063c8b2`](https://github.com/mastra-ai/mastra/commit/063c8b2eb14e4e5ca021779bc33e8c3c031c8604), [`f9f9884`](https://github.com/mastra-ai/mastra/commit/f9f98848ee194dc71a787a709ec430b065cdc41b), [`e0904dc`](https://github.com/mastra-ai/mastra/commit/e0904dc538792e54e1806b70172e5900ac49bff4), [`9672fab`](https://github.com/mastra-ai/mastra/commit/9672fabfbcadb961a35c22a2d6722e077f7b24b9), [`f4e964c`](https://github.com/mastra-ai/mastra/commit/f4e964cad57057301d6bed5c55bcdd730175b941), [`1f7bbd7`](https://github.com/mastra-ai/mastra/commit/1f7bbd7785a8d230aad02454ecabeb4a0b2cc96f), [`e47ff36`](https://github.com/mastra-ai/mastra/commit/e47ff36945720f4ee4caa09f6e83514d7d188608), [`64d6781`](https://github.com/mastra-ai/mastra/commit/64d67814bccddd314f7e09643243821e57cb87b6), [`fb9a6ac`](https://github.com/mastra-ai/mastra/commit/fb9a6ac11c9560518742ece60b49d6b062845fd3), [`aa2cec8`](https://github.com/mastra-ai/mastra/commit/aa2cec8501f634d51c2f3ebfb3dd3aa7af8d2ca2), [`c848e65`](https://github.com/mastra-ai/mastra/commit/c848e655a64ff10331a8ceafafe7f18e70a0f092), [`2adf8eb`](https://github.com/mastra-ai/mastra/commit/2adf8eb4a70ed2b6cff2dd39281496ea0e025fac), [`0494489`](https://github.com/mastra-ai/mastra/commit/049448906e4c3d2d615bbe865b073a0d890ddb7c), [`8d1aeb8`](https://github.com/mastra-ai/mastra/commit/8d1aeb8acf7c20c4bb8e4d8e4bdc6569c83ac561), [`8264611`](https://github.com/mastra-ai/mastra/commit/8264611510e421b818bc7395dc2ae4d9c2d518b2), [`d8fa243`](https://github.com/mastra-ai/mastra/commit/d8fa2430d21113e330c4e676ac65e1235cf44f81), [`44fc98b`](https://github.com/mastra-ai/mastra/commit/44fc98b9d1242aa87a3ab44bdce9e9f12c44d8c9), [`f933ba3`](https://github.com/mastra-ai/mastra/commit/f933ba32700e1d0bf143311c1a08f88300b840b6), [`83065bf`](https://github.com/mastra-ai/mastra/commit/83065bfee9e47c3c6f09132a9034501f6cfb69cf), [`0f2ef41`](https://github.com/mastra-ai/mastra/commit/0f2ef4118da022e4f30dac4e9856cc3a8c97671c), [`01b162f`](https://github.com/mastra-ai/mastra/commit/01b162fe435295881aa7ea55f1759407ad5175ad)]:
|
|
19
|
+
- @mastra/core@1.57.0
|
|
20
|
+
|
|
3
21
|
## 0.2.3
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -135,6 +135,9 @@ function getGithubMetadata(threadMetadata) {
|
|
|
135
135
|
...readString(rawSubscription.lastObservedMergeableState) ? { lastObservedMergeableState: readString(rawSubscription.lastObservedMergeableState) } : {},
|
|
136
136
|
...readString(rawSubscription.lastObservedCiState) ? { lastObservedCiState: readString(rawSubscription.lastObservedCiState) } : {},
|
|
137
137
|
...readString(rawSubscription.lastObservedReviewStateHash) ? { lastObservedReviewStateHash: readString(rawSubscription.lastObservedReviewStateHash) } : {},
|
|
138
|
+
...readString(rawSubscription.lastObservedCommentUrl) ? { lastObservedCommentUrl: readString(rawSubscription.lastObservedCommentUrl) } : {},
|
|
139
|
+
...readString(rawSubscription.lastObservedCommentAuthor) ? { lastObservedCommentAuthor: readString(rawSubscription.lastObservedCommentAuthor) } : {},
|
|
140
|
+
...typeof rawSubscription.lastObservedCommentIsBot === "boolean" ? { lastObservedCommentIsBot: rawSubscription.lastObservedCommentIsBot } : {},
|
|
138
141
|
...readString(rawSubscription.lastNotificationAt) ? { lastNotificationAt: readString(rawSubscription.lastNotificationAt) } : {},
|
|
139
142
|
...readString(rawSubscription.lastNotificationKind) ? { lastNotificationKind: readString(rawSubscription.lastNotificationKind) } : {},
|
|
140
143
|
...rawSubscription.lastNotificationPriority === "medium" || rawSubscription.lastNotificationPriority === "high" ? { lastNotificationPriority: rawSubscription.lastNotificationPriority } : {},
|
|
@@ -317,6 +320,16 @@ function normalizeGithubChecksForSnapshot(input) {
|
|
|
317
320
|
function isBotOnlyActivity(snapshot) {
|
|
318
321
|
return snapshot.latestCommentIsBot === true && (!snapshot.ciState || snapshot.ciState === "unknown");
|
|
319
322
|
}
|
|
323
|
+
function isKnownMergeableState(state) {
|
|
324
|
+
return !!state && state.toLowerCase() !== "unknown";
|
|
325
|
+
}
|
|
326
|
+
function hasMeaningfulMergeableStateChange(previous, current) {
|
|
327
|
+
if (!isKnownMergeableState(current) || current === previous) return false;
|
|
328
|
+
return current === "dirty" || previous === "dirty" || isKnownMergeableState(previous);
|
|
329
|
+
}
|
|
330
|
+
function isExistingBotCommentEdit(subscription, snapshot) {
|
|
331
|
+
return snapshot.latestCommentIsBot === true && subscription.lastObservedCommentIsBot === true && !!snapshot.latestCommentUrl && snapshot.latestCommentUrl === subscription.lastObservedCommentUrl && !!snapshot.latestCommentAuthor && snapshot.latestCommentAuthor === subscription.lastObservedCommentAuthor;
|
|
332
|
+
}
|
|
320
333
|
function stringifyEvidence(value) {
|
|
321
334
|
if (typeof value === "string") return value;
|
|
322
335
|
try {
|
|
@@ -378,7 +391,7 @@ function classifyGithubActivityNotification(input) {
|
|
|
378
391
|
priority: "high",
|
|
379
392
|
summary: `${pr} has merge conflicts${input.snapshot.title ? `: ${input.snapshot.title}` : ""}`
|
|
380
393
|
};
|
|
381
|
-
if (input.snapshot.mergeableState && input.subscription.lastObservedMergeableState === "dirty" && input.snapshot.mergeableState !== "dirty") return {
|
|
394
|
+
if (isKnownMergeableState(input.snapshot.mergeableState) && input.subscription.lastObservedMergeableState === "dirty" && input.snapshot.mergeableState !== "dirty") return {
|
|
382
395
|
kind: "pull-request-conflict-resolved",
|
|
383
396
|
priority: "medium",
|
|
384
397
|
summary: `${pr} merge conflicts were resolved`
|
|
@@ -436,9 +449,12 @@ function applySnapshotCursor(subscription, snapshot) {
|
|
|
436
449
|
if (snapshot.threadContentHash) subscription.lastObservedThreadContentHash = snapshot.threadContentHash;
|
|
437
450
|
if (snapshot.headSha) subscription.lastObservedHeadSha = snapshot.headSha;
|
|
438
451
|
if (snapshot.state) subscription.lastObservedState = snapshot.state;
|
|
439
|
-
if (snapshot.mergeableState) subscription.lastObservedMergeableState = snapshot.mergeableState;
|
|
452
|
+
if (isKnownMergeableState(snapshot.mergeableState)) subscription.lastObservedMergeableState = snapshot.mergeableState;
|
|
440
453
|
if (snapshot.ciState) subscription.lastObservedCiState = snapshot.ciState;
|
|
441
454
|
if (snapshot.reviewStateHash) subscription.lastObservedReviewStateHash = snapshot.reviewStateHash;
|
|
455
|
+
if (snapshot.latestCommentUrl) subscription.lastObservedCommentUrl = snapshot.latestCommentUrl;
|
|
456
|
+
if (snapshot.latestCommentAuthor) subscription.lastObservedCommentAuthor = snapshot.latestCommentAuthor;
|
|
457
|
+
if (snapshot.latestCommentIsBot !== void 0) subscription.lastObservedCommentIsBot = snapshot.latestCommentIsBot;
|
|
442
458
|
}
|
|
443
459
|
function parseGitHubRemoteUrl(remoteUrl) {
|
|
444
460
|
const trimmed = remoteUrl.trim().replace(/\.git$/, "");
|
|
@@ -724,6 +740,8 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
724
740
|
#syncClient;
|
|
725
741
|
#repositoryResolver;
|
|
726
742
|
#polling = /* @__PURE__ */ new Map();
|
|
743
|
+
#pollingThreadGenerations = /* @__PURE__ */ new Map();
|
|
744
|
+
#pollingGeneration = 0;
|
|
727
745
|
#permissionCache = /* @__PURE__ */ new Map();
|
|
728
746
|
#agent;
|
|
729
747
|
#agentOptions = {};
|
|
@@ -797,6 +815,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
797
815
|
const key = this.#pollingKey(input);
|
|
798
816
|
for (const [pollingKey, state] of this.#polling.entries()) {
|
|
799
817
|
if (pollingKey === key) continue;
|
|
818
|
+
this.#invalidatePollingThread(pollingKey);
|
|
800
819
|
clearInterval(state.timer);
|
|
801
820
|
this.#polling.delete(pollingKey);
|
|
802
821
|
}
|
|
@@ -820,6 +839,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
820
839
|
}
|
|
821
840
|
stopPollingForThread(input) {
|
|
822
841
|
const key = this.#pollingKey(input);
|
|
842
|
+
this.#invalidatePollingThread(key);
|
|
823
843
|
const state = this.#polling.get(key);
|
|
824
844
|
if (!state) return;
|
|
825
845
|
clearInterval(state.timer);
|
|
@@ -835,6 +855,8 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
835
855
|
return this.#options.pollIntervalMs ?? 3e5;
|
|
836
856
|
}
|
|
837
857
|
stopAllPolling() {
|
|
858
|
+
this.#pollingGeneration++;
|
|
859
|
+
this.#pollingThreadGenerations.clear();
|
|
838
860
|
for (const state of this.#polling.values()) clearInterval(state.timer);
|
|
839
861
|
this.#polling.clear();
|
|
840
862
|
}
|
|
@@ -1028,6 +1050,9 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1028
1050
|
#pollingKey(input) {
|
|
1029
1051
|
return `${input.resourceId}:${input.threadId}`;
|
|
1030
1052
|
}
|
|
1053
|
+
#invalidatePollingThread(key) {
|
|
1054
|
+
this.#pollingThreadGenerations.set(key, (this.#pollingThreadGenerations.get(key) ?? 0) + 1);
|
|
1055
|
+
}
|
|
1031
1056
|
#getNotificationAgent(_input) {
|
|
1032
1057
|
if (this.#agent) return this.#agent;
|
|
1033
1058
|
const agentId = _input?.agentId ?? this.#options.agentId;
|
|
@@ -1047,6 +1072,9 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1047
1072
|
const key = this.#pollingKey(input);
|
|
1048
1073
|
const state = this.#polling.get(key);
|
|
1049
1074
|
if (state?.running) return 0;
|
|
1075
|
+
const generation = this.#pollingGeneration;
|
|
1076
|
+
const threadGeneration = this.#pollingThreadGenerations.get(key) ?? 0;
|
|
1077
|
+
const isCurrentGeneration = () => this.#pollingGeneration === generation && (this.#pollingThreadGenerations.get(key) ?? 0) === threadGeneration;
|
|
1050
1078
|
if (state) state.running = true;
|
|
1051
1079
|
this.#notifyPollingChanged({
|
|
1052
1080
|
threadId: input.threadId,
|
|
@@ -1055,6 +1083,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1055
1083
|
});
|
|
1056
1084
|
try {
|
|
1057
1085
|
const { threadStore, loadedThread } = await this.#loadThread(input);
|
|
1086
|
+
if (!isCurrentGeneration()) return 0;
|
|
1058
1087
|
const githubMetadata = getGithubMetadata(loadedThread.metadata);
|
|
1059
1088
|
if (githubMetadata.subscriptions.length === 0) {
|
|
1060
1089
|
this.stopPollingForThread(input);
|
|
@@ -1071,6 +1100,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1071
1100
|
includeComments: options.includeComments
|
|
1072
1101
|
};
|
|
1073
1102
|
const syncResult = await this.#syncClient.syncPullRequest(syncInput);
|
|
1103
|
+
if (!isCurrentGeneration()) return 0;
|
|
1074
1104
|
let snapshot;
|
|
1075
1105
|
let snapshotError;
|
|
1076
1106
|
if (syncResult.ok) try {
|
|
@@ -1078,7 +1108,9 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1078
1108
|
} catch (error) {
|
|
1079
1109
|
snapshotError = error instanceof Error ? error.message : String(error);
|
|
1080
1110
|
}
|
|
1081
|
-
if (
|
|
1111
|
+
if (!isCurrentGeneration()) return 0;
|
|
1112
|
+
if (snapshot) snapshot = await this.#filterUnauthorizedLatestComment(subscription.owner, subscription.repo, snapshot, isCurrentGeneration);
|
|
1113
|
+
if (!isCurrentGeneration()) return 0;
|
|
1082
1114
|
const nextSubscription = {
|
|
1083
1115
|
...subscription,
|
|
1084
1116
|
updatedAt: now,
|
|
@@ -1093,21 +1125,25 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1093
1125
|
const previousContentHash = subscription.lastObservedContentHash;
|
|
1094
1126
|
const previousThreadContentHash = subscription.lastObservedThreadContentHash;
|
|
1095
1127
|
const previousHeadSha = subscription.lastObservedHeadSha;
|
|
1096
|
-
const
|
|
1128
|
+
const latestCommentTimestampChanged = !!previousGithubUpdatedAt && !!snapshot?.latestCommentUpdatedAt && Date.parse(snapshot.latestCommentUpdatedAt) > Date.parse(previousGithubUpdatedAt);
|
|
1129
|
+
const existingBotCommentEdited = latestCommentTimestampChanged && !!snapshot && isExistingBotCommentEdit(subscription, snapshot);
|
|
1130
|
+
const latestCommentChanged = latestCommentTimestampChanged && !existingBotCommentEdited;
|
|
1097
1131
|
if (snapshot) applySnapshotCursor(nextSubscription, snapshot);
|
|
1098
1132
|
const isFirstObservation = syncResult.ok && snapshot && !previousGithubUpdatedAt && !previousContentHash;
|
|
1099
1133
|
const legacyAggregateChanged = previousContentHash && snapshot?.contentHash && previousContentHash !== snapshot.contentHash && !previousThreadContentHash && !previousHeadSha;
|
|
1100
|
-
const changed = isFirstObservation || syncResult.ok && snapshot && (legacyAggregateChanged || latestCommentChanged || previousThreadContentHash && snapshot.threadContentHash && previousThreadContentHash !== snapshot.threadContentHash || previousHeadSha && snapshot.headSha && previousHeadSha !== snapshot.headSha || subscription.lastObservedState && snapshot.state && subscription.lastObservedState !== snapshot.state || subscription.lastObservedMergeableState
|
|
1134
|
+
const changed = isFirstObservation || syncResult.ok && snapshot && (legacyAggregateChanged || latestCommentChanged || previousThreadContentHash && snapshot.threadContentHash && previousThreadContentHash !== snapshot.threadContentHash && !existingBotCommentEdited || previousHeadSha && snapshot.headSha && previousHeadSha !== snapshot.headSha || subscription.lastObservedState && snapshot.state && subscription.lastObservedState !== snapshot.state || hasMeaningfulMergeableStateChange(subscription.lastObservedMergeableState, snapshot.mergeableState) || subscription.lastObservedCiState && snapshot.ciState && subscription.lastObservedCiState !== snapshot.ciState || subscription.lastObservedReviewStateHash && snapshot.reviewStateHash && subscription.lastObservedReviewStateHash !== snapshot.reviewStateHash);
|
|
1101
1135
|
let shouldKeepSubscription = true;
|
|
1102
|
-
if (changed && snapshot) {
|
|
1136
|
+
if (changed && snapshot && isCurrentGeneration()) {
|
|
1103
1137
|
const notifications = await this.#sendActivityNotifications({
|
|
1104
1138
|
polling: input,
|
|
1105
1139
|
subscription,
|
|
1106
1140
|
snapshot,
|
|
1107
1141
|
previousGithubUpdatedAt,
|
|
1108
1142
|
previousContentHash,
|
|
1109
|
-
latestCommentChanged
|
|
1143
|
+
latestCommentChanged,
|
|
1144
|
+
isCurrentGeneration
|
|
1110
1145
|
});
|
|
1146
|
+
if (!isCurrentGeneration()) return 0;
|
|
1111
1147
|
const primaryNotification = notifications[0];
|
|
1112
1148
|
if (primaryNotification) {
|
|
1113
1149
|
nextSubscription.lastNotificationAt = now;
|
|
@@ -1119,6 +1155,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1119
1155
|
}
|
|
1120
1156
|
if (shouldKeepSubscription) subscriptions.push(nextSubscription);
|
|
1121
1157
|
}
|
|
1158
|
+
if (!isCurrentGeneration()) return 0;
|
|
1122
1159
|
await threadStore.saveThread({ thread: {
|
|
1123
1160
|
...loadedThread,
|
|
1124
1161
|
id: input.threadId,
|
|
@@ -1127,6 +1164,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1127
1164
|
updatedAt: /* @__PURE__ */ new Date(),
|
|
1128
1165
|
metadata: setGithubMetadata(loadedThread.metadata, { subscriptions })
|
|
1129
1166
|
} });
|
|
1167
|
+
if (!isCurrentGeneration()) return 0;
|
|
1130
1168
|
this.#notifySubscriptionsChanged({
|
|
1131
1169
|
threadId: input.threadId,
|
|
1132
1170
|
resourceId: input.resourceId,
|
|
@@ -1134,16 +1172,16 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1134
1172
|
});
|
|
1135
1173
|
if (subscriptions.length === 0) this.stopPollingForThread(input);
|
|
1136
1174
|
return subscriptions.length;
|
|
1137
|
-
} catch (error) {
|
|
1138
|
-
throw error;
|
|
1139
1175
|
} finally {
|
|
1140
1176
|
const latestState = this.#polling.get(key);
|
|
1141
|
-
if (
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1177
|
+
if (isCurrentGeneration()) {
|
|
1178
|
+
if (latestState) latestState.running = false;
|
|
1179
|
+
this.#notifyPollingChanged({
|
|
1180
|
+
threadId: input.threadId,
|
|
1181
|
+
resourceId: input.resourceId,
|
|
1182
|
+
running: false
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1147
1185
|
}
|
|
1148
1186
|
}
|
|
1149
1187
|
#createGithubNotificationInput(input) {
|
|
@@ -1235,18 +1273,19 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1235
1273
|
dedupeSuffix: `baseline:${input.subscription.lastSubscribeSignalId}`
|
|
1236
1274
|
});
|
|
1237
1275
|
}
|
|
1238
|
-
async #isAuthorizedAuthor(owner, repo, user, metadata = {}) {
|
|
1276
|
+
async #isAuthorizedAuthor(owner, repo, user, metadata = {}, isCurrentGeneration) {
|
|
1239
1277
|
if (!user) return false;
|
|
1240
1278
|
const normalizedUser = user.toLowerCase();
|
|
1241
1279
|
if (metadata.isBot === true || metadata.authorType?.toLowerCase() === "bot" || normalizedUser.endsWith("[bot]")) {
|
|
1242
1280
|
if ((this.#options.ignoredBots ?? []).some((bot) => bot.toLowerCase() === normalizedUser)) return false;
|
|
1243
1281
|
return (this.#options.authorizedBots ?? DEFAULT_AUTHORIZED_BOTS).some((bot) => bot.toLowerCase() === normalizedUser);
|
|
1244
1282
|
}
|
|
1245
|
-
const permission = await this.#loadAuthorPermission(owner, repo, user);
|
|
1283
|
+
const permission = await this.#loadAuthorPermission(owner, repo, user, isCurrentGeneration);
|
|
1284
|
+
if (isCurrentGeneration && !isCurrentGeneration()) return false;
|
|
1246
1285
|
const authorizedPermissions = this.#options.authorizedPermissions ?? DEFAULT_AUTHORIZED_PERMISSIONS;
|
|
1247
1286
|
return !!permission && authorizedPermissions.includes(permission);
|
|
1248
1287
|
}
|
|
1249
|
-
async #filterUnauthorizedLatestComment(owner, repo, snapshot) {
|
|
1288
|
+
async #filterUnauthorizedLatestComment(owner, repo, snapshot, isCurrentGeneration) {
|
|
1250
1289
|
const comments = snapshot.latestComments?.length ? snapshot.latestComments : [{
|
|
1251
1290
|
author: snapshot.latestCommentAuthor,
|
|
1252
1291
|
authorType: snapshot.latestCommentAuthorType,
|
|
@@ -1258,10 +1297,11 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1258
1297
|
if (!comments.some((comment) => comment.author)) return snapshot;
|
|
1259
1298
|
if (!comments.some((comment) => comment.body || comment.url || comment.updatedAt)) return snapshot;
|
|
1260
1299
|
for (const comment of comments) {
|
|
1300
|
+
if (isCurrentGeneration && !isCurrentGeneration()) return snapshot;
|
|
1261
1301
|
if (!await this.#isAuthorizedAuthor(owner, repo, comment.author, {
|
|
1262
1302
|
authorType: comment.authorType,
|
|
1263
1303
|
isBot: comment.isBot
|
|
1264
|
-
})) continue;
|
|
1304
|
+
}, isCurrentGeneration)) continue;
|
|
1265
1305
|
return {
|
|
1266
1306
|
...snapshot,
|
|
1267
1307
|
latestCommentAuthor: comment.author,
|
|
@@ -1282,7 +1322,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1282
1322
|
latestCommentUpdatedAt: void 0
|
|
1283
1323
|
};
|
|
1284
1324
|
}
|
|
1285
|
-
async #loadAuthorPermission(owner, repo, user) {
|
|
1325
|
+
async #loadAuthorPermission(owner, repo, user, isCurrentGeneration) {
|
|
1286
1326
|
const cacheKey = `${owner}/${repo}:${user.toLowerCase()}`;
|
|
1287
1327
|
const cached = this.#permissionCache.get(cacheKey);
|
|
1288
1328
|
if (cached && cached.expiresAt > Date.now()) return cached.permission;
|
|
@@ -1307,10 +1347,11 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1307
1347
|
"none"
|
|
1308
1348
|
].includes(raw) ? raw : void 0;
|
|
1309
1349
|
}
|
|
1310
|
-
if (permission) this.#permissionCache.set(cacheKey, {
|
|
1350
|
+
if (permission && (!isCurrentGeneration || isCurrentGeneration())) this.#permissionCache.set(cacheKey, {
|
|
1311
1351
|
permission,
|
|
1312
1352
|
expiresAt: Date.now() + PERMISSION_CACHE_TTL_MS
|
|
1313
1353
|
});
|
|
1354
|
+
if (isCurrentGeneration && !isCurrentGeneration()) return void 0;
|
|
1314
1355
|
return permission;
|
|
1315
1356
|
} catch {
|
|
1316
1357
|
this.#permissionCache.delete(cacheKey);
|
|
@@ -1333,10 +1374,12 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1333
1374
|
for (const notification of notifications.sort(compareGithubActivityNotifications)) {
|
|
1334
1375
|
if (!notification) continue;
|
|
1335
1376
|
if (AUTHOR_GATED_NOTIFICATION_KINDS.has(notification.kind)) {
|
|
1336
|
-
|
|
1377
|
+
const authorized = await this.#isAuthorizedAuthor(input.subscription.owner, input.subscription.repo, input.snapshot.latestCommentAuthor, {
|
|
1337
1378
|
authorType: input.snapshot.latestCommentAuthorType,
|
|
1338
1379
|
isBot: input.snapshot.latestCommentIsBot
|
|
1339
|
-
})
|
|
1380
|
+
}, input.isCurrentGeneration);
|
|
1381
|
+
if (!input.isCurrentGeneration()) return [];
|
|
1382
|
+
if (!authorized) continue;
|
|
1340
1383
|
}
|
|
1341
1384
|
notificationInputs.push(this.#createGithubNotificationInput({
|
|
1342
1385
|
subscription: input.subscription,
|
|
@@ -1353,11 +1396,14 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1353
1396
|
resourceId: input.polling.resourceId,
|
|
1354
1397
|
threadId: input.polling.threadId
|
|
1355
1398
|
};
|
|
1399
|
+
if (!input.isCurrentGeneration()) return [];
|
|
1356
1400
|
const streamOptions = await this.#agentOptions.getNotificationStreamOptions?.(target);
|
|
1401
|
+
if (!input.isCurrentGeneration()) return [];
|
|
1357
1402
|
await agent.sendNotificationSignal(notificationInputs, streamOptions ? {
|
|
1358
1403
|
...target,
|
|
1359
1404
|
ifIdle: { streamOptions }
|
|
1360
1405
|
} : target);
|
|
1406
|
+
if (!input.isCurrentGeneration()) return [];
|
|
1361
1407
|
}
|
|
1362
1408
|
return sent;
|
|
1363
1409
|
}
|
|
@@ -1392,7 +1438,10 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1392
1438
|
...existing?.lastObservedState ? { lastObservedState: existing.lastObservedState } : {},
|
|
1393
1439
|
...existing?.lastObservedMergeableState ? { lastObservedMergeableState: existing.lastObservedMergeableState } : {},
|
|
1394
1440
|
...existing?.lastObservedCiState ? { lastObservedCiState: existing.lastObservedCiState } : {},
|
|
1395
|
-
...existing?.lastObservedReviewStateHash ? { lastObservedReviewStateHash: existing.lastObservedReviewStateHash } : {}
|
|
1441
|
+
...existing?.lastObservedReviewStateHash ? { lastObservedReviewStateHash: existing.lastObservedReviewStateHash } : {},
|
|
1442
|
+
...existing?.lastObservedCommentUrl ? { lastObservedCommentUrl: existing.lastObservedCommentUrl } : {},
|
|
1443
|
+
...existing?.lastObservedCommentAuthor ? { lastObservedCommentAuthor: existing.lastObservedCommentAuthor } : {},
|
|
1444
|
+
...typeof existing?.lastObservedCommentIsBot === "boolean" ? { lastObservedCommentIsBot: existing.lastObservedCommentIsBot } : {}
|
|
1396
1445
|
};
|
|
1397
1446
|
let syncResult;
|
|
1398
1447
|
let baselineSnapshot;
|