@agentjam/sdk 0.5.0 → 0.7.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/dist/adapters/ai.d.ts +1 -1
- package/dist/adapters/ai.d.ts.map +1 -1
- package/dist/adapters/anthropic.d.ts +1 -1
- package/dist/adapters/anthropic.d.ts.map +1 -1
- package/dist/adapters/openai.d.ts +1 -1
- package/dist/adapters/openai.d.ts.map +1 -1
- package/dist/adapters/openaiAgents.d.ts +1 -1
- package/dist/adapters/openaiAgents.d.ts.map +1 -1
- package/dist/adapters/shared.d.ts +2 -2
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +6 -2
- package/dist/adapters/shared.js.map +1 -1
- package/dist/agent.d.ts +73 -5
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +140 -10
- package/dist/agent.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +27 -0
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/managedWebhooks.d.ts +15 -0
- package/dist/managedWebhooks.d.ts.map +1 -0
- package/dist/managedWebhooks.js +115 -0
- package/dist/managedWebhooks.js.map +1 -0
- package/dist/platforms/atlassian.d.ts +18 -0
- package/dist/platforms/atlassian.d.ts.map +1 -0
- package/dist/platforms/atlassian.js +24 -0
- package/dist/platforms/atlassian.js.map +1 -0
- package/dist/platforms/datadog.d.ts +45 -1
- package/dist/platforms/datadog.d.ts.map +1 -1
- package/dist/platforms/datadog.js +207 -0
- package/dist/platforms/datadog.js.map +1 -1
- package/dist/platforms/discord.d.ts +64 -16
- package/dist/platforms/discord.d.ts.map +1 -1
- package/dist/platforms/discord.js +15 -48
- package/dist/platforms/discord.js.map +1 -1
- package/dist/platforms/discordEvents.d.ts +213 -0
- package/dist/platforms/discordEvents.d.ts.map +1 -0
- package/dist/platforms/discordEvents.js +270 -0
- package/dist/platforms/discordEvents.js.map +1 -0
- package/dist/platforms/discordGateway.d.ts +14 -14
- package/dist/platforms/discordGateway.d.ts.map +1 -1
- package/dist/platforms/discordGateway.js +29 -45
- package/dist/platforms/discordGateway.js.map +1 -1
- package/dist/platforms/discordInteractions.d.ts +35 -0
- package/dist/platforms/discordInteractions.d.ts.map +1 -0
- package/dist/platforms/discordInteractions.js +125 -0
- package/dist/platforms/discordInteractions.js.map +1 -0
- package/dist/platforms/github.d.ts +45 -13
- package/dist/platforms/github.d.ts.map +1 -1
- package/dist/platforms/github.js +20 -40
- package/dist/platforms/github.js.map +1 -1
- package/dist/platforms/githubApi.d.ts +2 -0
- package/dist/platforms/githubApi.d.ts.map +1 -0
- package/dist/platforms/githubApi.js +38 -0
- package/dist/platforms/githubApi.js.map +1 -0
- package/dist/platforms/githubEvents.d.ts +160 -0
- package/dist/platforms/githubEvents.d.ts.map +1 -0
- package/dist/platforms/githubEvents.js +446 -0
- package/dist/platforms/githubEvents.js.map +1 -0
- package/dist/platforms/grafana.d.ts +47 -1
- package/dist/platforms/grafana.d.ts.map +1 -1
- package/dist/platforms/grafana.js +187 -0
- package/dist/platforms/grafana.js.map +1 -1
- package/dist/platforms/pagerduty.d.ts +59 -0
- package/dist/platforms/pagerduty.d.ts.map +1 -0
- package/dist/platforms/pagerduty.js +175 -0
- package/dist/platforms/pagerduty.js.map +1 -0
- package/dist/platforms/sentry.d.ts +35 -17
- package/dist/platforms/sentry.d.ts.map +1 -1
- package/dist/platforms/sentry.js +48 -25
- package/dist/platforms/sentry.js.map +1 -1
- package/dist/platforms/sentryApi.d.ts +3 -0
- package/dist/platforms/sentryApi.d.ts.map +1 -0
- package/dist/platforms/sentryApi.js +29 -0
- package/dist/platforms/sentryApi.js.map +1 -0
- package/dist/platforms/sentryEvents.d.ts +64 -0
- package/dist/platforms/sentryEvents.d.ts.map +1 -0
- package/dist/platforms/sentryEvents.js +183 -0
- package/dist/platforms/sentryEvents.js.map +1 -0
- package/dist/platforms/slack.d.ts +69 -33
- package/dist/platforms/slack.d.ts.map +1 -1
- package/dist/platforms/slack.js +29 -36
- package/dist/platforms/slack.js.map +1 -1
- package/dist/platforms/slackEvents.d.ts +204 -0
- package/dist/platforms/slackEvents.d.ts.map +1 -0
- package/dist/platforms/slackEvents.js +241 -0
- package/dist/platforms/slackEvents.js.map +1 -0
- package/dist/platforms/slackInteractions.d.ts +79 -0
- package/dist/platforms/slackInteractions.d.ts.map +1 -0
- package/dist/platforms/slackInteractions.js +160 -0
- package/dist/platforms/slackInteractions.js.map +1 -0
- package/dist/protocol.d.ts +163 -6
- package/dist/protocol.d.ts.map +1 -1
- package/dist/relay/frames.d.ts +52 -2
- package/dist/relay/frames.d.ts.map +1 -1
- package/dist/relay/frames.js +2 -0
- package/dist/relay/frames.js.map +1 -1
- package/dist/relay/payments.d.ts +8 -3
- package/dist/relay/payments.d.ts.map +1 -1
- package/dist/relay/payments.js +20 -2
- package/dist/relay/payments.js.map +1 -1
- package/dist/relay/relay.d.ts +44 -5
- package/dist/relay/relay.d.ts.map +1 -1
- package/dist/relay/remote.d.ts.map +1 -1
- package/dist/relay/remote.js +65 -8
- package/dist/relay/remote.js.map +1 -1
- package/dist/relay/schedules.d.ts +2 -1
- package/dist/relay/schedules.d.ts.map +1 -1
- package/dist/relay/schedules.js +13 -3
- package/dist/relay/schedules.js.map +1 -1
- package/dist/tasks/outgoing.d.ts.map +1 -1
- package/dist/tasks/outgoing.js +1 -0
- package/dist/tasks/outgoing.js.map +1 -1
- package/dist/tasks/scheduled.d.ts +18 -8
- package/dist/tasks/scheduled.d.ts.map +1 -1
- package/dist/tasks/scheduled.js +77 -20
- package/dist/tasks/scheduled.js.map +1 -1
- package/dist/tasks/triggers.d.ts +11 -3
- package/dist/tasks/triggers.d.ts.map +1 -1
- package/dist/tasks/triggers.js +30 -11
- package/dist/tasks/triggers.js.map +1 -1
- package/dist/tools/delegations.d.ts +17 -0
- package/dist/tools/delegations.d.ts.map +1 -0
- package/dist/tools/delegations.js +67 -0
- package/dist/tools/delegations.js.map +1 -0
- package/dist/tools/inputs.d.ts +62 -0
- package/dist/tools/inputs.d.ts.map +1 -0
- package/dist/tools/inputs.js +143 -0
- package/dist/tools/inputs.js.map +1 -0
- package/dist/tools/network.d.ts +10 -0
- package/dist/tools/network.d.ts.map +1 -0
- package/dist/tools/network.js +435 -0
- package/dist/tools/network.js.map +1 -0
- package/dist/tools/schedules.d.ts +43 -0
- package/dist/tools/schedules.d.ts.map +1 -0
- package/dist/tools/schedules.js +337 -0
- package/dist/tools/schedules.js.map +1 -0
- package/dist/tools/shared.d.ts +152 -0
- package/dist/tools/shared.d.ts.map +1 -0
- package/dist/tools/shared.js +151 -0
- package/dist/tools/shared.js.map +1 -0
- package/package.json +9 -1
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { AgentJamError } from "../errors.js";
|
|
2
|
+
import { fitLargestFields, maxEventKeyLength, maxEventKeys, } from "../events.js";
|
|
3
|
+
import { truncateSummary } from "../polling.js";
|
|
4
|
+
import { constructGitHubError, fetchGitHub, getRepository, githubApi, repositoryProperty, } from "./githubApi.js";
|
|
5
|
+
const readObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
6
|
+
? value
|
|
7
|
+
: undefined;
|
|
8
|
+
const readText = (object, key) => {
|
|
9
|
+
const value = object?.[key];
|
|
10
|
+
return typeof value === "string" ? value : undefined;
|
|
11
|
+
};
|
|
12
|
+
const readNumber = (object, key) => {
|
|
13
|
+
const value = object?.[key];
|
|
14
|
+
return typeof value === "number" ? value : undefined;
|
|
15
|
+
};
|
|
16
|
+
const constructComparePath = (payload) => {
|
|
17
|
+
const repository = readText(readObject(payload.repository), "full_name");
|
|
18
|
+
const before = readText(payload, "before");
|
|
19
|
+
const after = readText(payload, "after");
|
|
20
|
+
if (!repository || !before || !after)
|
|
21
|
+
return undefined;
|
|
22
|
+
return `/repos/${repository}/compare/${before}...${after}`;
|
|
23
|
+
};
|
|
24
|
+
const githubEvents = {
|
|
25
|
+
commit_comment: {
|
|
26
|
+
description: "A commit or diff is commented on in a GitHub repository",
|
|
27
|
+
actions: ["created"],
|
|
28
|
+
},
|
|
29
|
+
create: { description: "A branch or tag is created in a GitHub repository" },
|
|
30
|
+
delete: { description: "A branch or tag is deleted in a GitHub repository" },
|
|
31
|
+
fork: { description: "A GitHub repository is forked" },
|
|
32
|
+
gollum: {
|
|
33
|
+
description: "A wiki page of a GitHub repository is created or updated",
|
|
34
|
+
},
|
|
35
|
+
installation_target: {
|
|
36
|
+
description: "The account a GitHub App is installed on is renamed",
|
|
37
|
+
scope: "account",
|
|
38
|
+
actions: ["renamed"],
|
|
39
|
+
},
|
|
40
|
+
issue_comment: {
|
|
41
|
+
description: "A comment on an issue or pull request in a GitHub repository is created, edited, deleted, pinned, or unpinned",
|
|
42
|
+
actions: ["created", "deleted", "edited", "pinned", "unpinned"],
|
|
43
|
+
},
|
|
44
|
+
issue_dependencies: {
|
|
45
|
+
description: "An issue's dependency, such as blocked by or blocking, is added or removed in a GitHub repository",
|
|
46
|
+
actions: [
|
|
47
|
+
"blocked_by_added",
|
|
48
|
+
"blocked_by_removed",
|
|
49
|
+
"blocking_added",
|
|
50
|
+
"blocking_removed",
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
issue_relates_to: {
|
|
54
|
+
description: "A related issue is added to or removed from an issue in a GitHub repository",
|
|
55
|
+
actions: ["relates_to_added", "relates_to_removed"],
|
|
56
|
+
},
|
|
57
|
+
issues: {
|
|
58
|
+
description: "An issue in a GitHub repository is opened, edited, closed, assigned, labeled, or otherwise changed",
|
|
59
|
+
actions: [
|
|
60
|
+
"assigned",
|
|
61
|
+
"closed",
|
|
62
|
+
"deleted",
|
|
63
|
+
"demilestoned",
|
|
64
|
+
"edited",
|
|
65
|
+
"field_added",
|
|
66
|
+
"field_removed",
|
|
67
|
+
"labeled",
|
|
68
|
+
"locked",
|
|
69
|
+
"milestoned",
|
|
70
|
+
"opened",
|
|
71
|
+
"pinned",
|
|
72
|
+
"reopened",
|
|
73
|
+
"status_changed",
|
|
74
|
+
"transferred",
|
|
75
|
+
"typed",
|
|
76
|
+
"unassigned",
|
|
77
|
+
"unlabeled",
|
|
78
|
+
"unlocked",
|
|
79
|
+
"unpinned",
|
|
80
|
+
"untyped",
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
label: {
|
|
84
|
+
description: "A label of a GitHub repository is created, edited, deleted, archived, or unarchived",
|
|
85
|
+
actions: ["archived", "created", "deleted", "edited", "unarchived"],
|
|
86
|
+
},
|
|
87
|
+
merge_group: {
|
|
88
|
+
description: "A pull request joins a GitHub repository's merge queue, which requests its checks, or its merge group is destroyed",
|
|
89
|
+
actions: ["checks_requested", "destroyed"],
|
|
90
|
+
},
|
|
91
|
+
meta: {
|
|
92
|
+
description: "The webhook of the agent's GitHub App or repository is deleted",
|
|
93
|
+
scope: "global",
|
|
94
|
+
actions: ["deleted"],
|
|
95
|
+
},
|
|
96
|
+
milestone: {
|
|
97
|
+
description: "A milestone of a GitHub repository is created, opened, closed, edited, or deleted",
|
|
98
|
+
actions: ["closed", "created", "deleted", "edited", "opened"],
|
|
99
|
+
},
|
|
100
|
+
public: { description: "A GitHub repository changes from private to public" },
|
|
101
|
+
pull_request: {
|
|
102
|
+
description: "A pull request in a GitHub repository is opened, edited, closed, synchronized, labeled, or otherwise changed",
|
|
103
|
+
actions: [
|
|
104
|
+
"assigned",
|
|
105
|
+
"auto_merge_disabled",
|
|
106
|
+
"auto_merge_enabled",
|
|
107
|
+
"closed",
|
|
108
|
+
"converted_to_draft",
|
|
109
|
+
"demilestoned",
|
|
110
|
+
"dequeued",
|
|
111
|
+
"edited",
|
|
112
|
+
"enqueued",
|
|
113
|
+
"labeled",
|
|
114
|
+
"locked",
|
|
115
|
+
"milestoned",
|
|
116
|
+
"opened",
|
|
117
|
+
"ready_for_review",
|
|
118
|
+
"reopened",
|
|
119
|
+
"review_request_removed",
|
|
120
|
+
"review_requested",
|
|
121
|
+
"stacked",
|
|
122
|
+
"synchronize",
|
|
123
|
+
"unassigned",
|
|
124
|
+
"unlabeled",
|
|
125
|
+
"unlocked",
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
pull_request_review: {
|
|
129
|
+
description: "A pull request review is submitted, edited, or dismissed in a GitHub repository",
|
|
130
|
+
actions: ["dismissed", "edited", "submitted"],
|
|
131
|
+
},
|
|
132
|
+
pull_request_review_comment: {
|
|
133
|
+
description: "A comment on a pull request's diff is created, edited, or deleted in a GitHub repository",
|
|
134
|
+
actions: ["created", "deleted", "edited"],
|
|
135
|
+
},
|
|
136
|
+
pull_request_review_thread: {
|
|
137
|
+
description: "A pull request review thread is resolved or unresolved in a GitHub repository",
|
|
138
|
+
actions: ["resolved", "unresolved"],
|
|
139
|
+
},
|
|
140
|
+
push: {
|
|
141
|
+
description: "Commits or tags are pushed to a GitHub repository",
|
|
142
|
+
refetch: { commits: { path: constructComparePath, pick: "commits" } },
|
|
143
|
+
},
|
|
144
|
+
release: {
|
|
145
|
+
description: "A release of a GitHub repository is created, edited, published, unpublished, or deleted",
|
|
146
|
+
actions: [
|
|
147
|
+
"created",
|
|
148
|
+
"deleted",
|
|
149
|
+
"edited",
|
|
150
|
+
"prereleased",
|
|
151
|
+
"published",
|
|
152
|
+
"released",
|
|
153
|
+
"unpublished",
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
repository: {
|
|
157
|
+
description: "A GitHub repository is created, deleted, archived, unarchived, publicized, privatized, edited, renamed, or transferred",
|
|
158
|
+
actions: [
|
|
159
|
+
"archived",
|
|
160
|
+
"created",
|
|
161
|
+
"deleted",
|
|
162
|
+
"edited",
|
|
163
|
+
"privatized",
|
|
164
|
+
"publicized",
|
|
165
|
+
"renamed",
|
|
166
|
+
"transferred",
|
|
167
|
+
"unarchived",
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
repository_dispatch: {
|
|
171
|
+
description: "A repository dispatch is sent to a GitHub repository",
|
|
172
|
+
actions: "custom",
|
|
173
|
+
},
|
|
174
|
+
security_advisory: {
|
|
175
|
+
description: "A GitHub-reviewed global security advisory is published, updated, or withdrawn",
|
|
176
|
+
scope: "global",
|
|
177
|
+
actions: ["published", "updated", "withdrawn"],
|
|
178
|
+
},
|
|
179
|
+
star: {
|
|
180
|
+
description: "A GitHub repository is starred or unstarred",
|
|
181
|
+
actions: ["created", "deleted"],
|
|
182
|
+
},
|
|
183
|
+
sub_issues: {
|
|
184
|
+
description: "A sub-issue or parent issue is added or removed in a GitHub repository",
|
|
185
|
+
actions: [
|
|
186
|
+
"parent_issue_added",
|
|
187
|
+
"parent_issue_removed",
|
|
188
|
+
"sub_issue_added",
|
|
189
|
+
"sub_issue_removed",
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
watch: {
|
|
193
|
+
description: "Someone stars a GitHub repository",
|
|
194
|
+
actions: ["started"],
|
|
195
|
+
},
|
|
196
|
+
workflow_dispatch: {
|
|
197
|
+
description: "A GitHub Actions workflow is run manually in a GitHub repository",
|
|
198
|
+
},
|
|
199
|
+
workflow_job: {
|
|
200
|
+
description: "A GitHub Actions workflow job is queued, waiting, in progress, or completed in a GitHub repository",
|
|
201
|
+
actions: ["completed", "in_progress", "queued", "waiting"],
|
|
202
|
+
},
|
|
203
|
+
workflow_run: {
|
|
204
|
+
description: "A GitHub Actions workflow run is requested, in progress, or completed in a GitHub repository",
|
|
205
|
+
actions: ["completed", "in_progress", "requested"],
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
const eventNames = Object.keys(githubEvents);
|
|
209
|
+
const accountProperty = {
|
|
210
|
+
type: "string",
|
|
211
|
+
pattern: "^[A-Za-z0-9-]{1,39}$",
|
|
212
|
+
description: "The login of the GitHub user or organization the app is installed on",
|
|
213
|
+
};
|
|
214
|
+
const scopeConfigs = {
|
|
215
|
+
repository: {
|
|
216
|
+
properties: { repository: repositoryProperty },
|
|
217
|
+
required: ["repository"],
|
|
218
|
+
},
|
|
219
|
+
account: { properties: { account: accountProperty }, required: ["account"] },
|
|
220
|
+
global: { properties: {} },
|
|
221
|
+
};
|
|
222
|
+
const goneStatuses = new Set([404, 410]);
|
|
223
|
+
const isGitHubEventName = (name) => Object.hasOwn(githubEvents, name);
|
|
224
|
+
const findSpec = (name) => githubEvents[name];
|
|
225
|
+
const isGitHubApiUrl = (url) => URL.canParse(url) && new URL(url).origin === githubApi;
|
|
226
|
+
const constructScopePrefix = (scope) => {
|
|
227
|
+
switch (scope.kind) {
|
|
228
|
+
case "repository":
|
|
229
|
+
return `github:${scope.id}`;
|
|
230
|
+
case "account":
|
|
231
|
+
return `github:account:${scope.id}`;
|
|
232
|
+
case "global":
|
|
233
|
+
return "github";
|
|
234
|
+
default: {
|
|
235
|
+
const unknown = scope;
|
|
236
|
+
throw new AgentJamError(`Unknown GitHub event scope: ${JSON.stringify(unknown)}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
const constructEventKey = (name, scope, action) => `${constructScopePrefix(scope)}:${name}${action === undefined ? "" : `.${action}`}`;
|
|
241
|
+
const constructActionsProperty = (actions) => ({
|
|
242
|
+
type: "array",
|
|
243
|
+
items: actions === "custom"
|
|
244
|
+
? { type: "string", minLength: 1, maxLength: 100 }
|
|
245
|
+
: { type: "string", enum: [...actions] },
|
|
246
|
+
minItems: 1,
|
|
247
|
+
maxItems: maxEventKeys,
|
|
248
|
+
uniqueItems: true,
|
|
249
|
+
description: actions === "custom"
|
|
250
|
+
? "The event types of the dispatches to run on. Leave it out to run on every dispatch"
|
|
251
|
+
: "The actions to run on. Leave it out to run on every action",
|
|
252
|
+
});
|
|
253
|
+
const constructEventConfig = ({ scope = "repository", actions, }) => {
|
|
254
|
+
const { properties, required } = scopeConfigs[scope];
|
|
255
|
+
return {
|
|
256
|
+
type: "object",
|
|
257
|
+
properties: {
|
|
258
|
+
...properties,
|
|
259
|
+
...(actions && { actions: constructActionsProperty(actions) }),
|
|
260
|
+
},
|
|
261
|
+
...(required && { required }),
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
const getAccountId = async (token, account) => {
|
|
265
|
+
const path = `/users/${encodeURIComponent(account)}`;
|
|
266
|
+
const response = await fetchGitHub(token, path);
|
|
267
|
+
if (goneStatuses.has(response.status)) {
|
|
268
|
+
throw new AgentJamError(`GitHub has no account named ${account}, so it can't be watched`);
|
|
269
|
+
}
|
|
270
|
+
if (!response.ok)
|
|
271
|
+
throw await constructGitHubError(response, path);
|
|
272
|
+
const { id } = (await response.json());
|
|
273
|
+
return id;
|
|
274
|
+
};
|
|
275
|
+
const resolveScheduleScope = async (scope, { config }, readToken) => {
|
|
276
|
+
switch (scope) {
|
|
277
|
+
case "repository": {
|
|
278
|
+
const { id } = await getRepository(await readToken(), String(config.repository));
|
|
279
|
+
return { kind: "repository", id };
|
|
280
|
+
}
|
|
281
|
+
case "account": {
|
|
282
|
+
const id = await getAccountId(await readToken(), String(config.account));
|
|
283
|
+
return { kind: "account", id };
|
|
284
|
+
}
|
|
285
|
+
case "global":
|
|
286
|
+
return { kind: "global" };
|
|
287
|
+
default: {
|
|
288
|
+
const unknown = scope;
|
|
289
|
+
throw new AgentJamError(`Unknown GitHub event scope: ${String(unknown)}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
const constructEventTrigger = (name, connection) => {
|
|
294
|
+
const spec = findSpec(name);
|
|
295
|
+
return {
|
|
296
|
+
description: spec.description,
|
|
297
|
+
config: constructEventConfig(spec),
|
|
298
|
+
onScheduleActive: async (schedule, { credentials }) => {
|
|
299
|
+
const scope = await resolveScheduleScope(spec.scope ?? "repository", schedule, () => credentials(connection));
|
|
300
|
+
const actions = schedule.config.actions;
|
|
301
|
+
const eventKeys = actions === undefined
|
|
302
|
+
? [constructEventKey(name, scope)]
|
|
303
|
+
: actions.map((action) => constructEventKey(name, scope, action));
|
|
304
|
+
return { eventKeys };
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
/** @internal One trigger per GitHub webhook event, named after it. */
|
|
309
|
+
export const constructEventTriggers = (connection) => Object.fromEntries(eventNames.map((name) => [name, constructEventTrigger(name, connection)]));
|
|
310
|
+
const readDeliveryScope = (scope, payload) => {
|
|
311
|
+
if (scope === "global")
|
|
312
|
+
return { kind: "global" };
|
|
313
|
+
const id = readNumber(readObject(payload[scope]), "id");
|
|
314
|
+
return id === undefined ? undefined : { kind: scope, id };
|
|
315
|
+
};
|
|
316
|
+
const readSubject = (payload) => {
|
|
317
|
+
const item = readObject(payload.pull_request) ?? readObject(payload.issue);
|
|
318
|
+
if (item)
|
|
319
|
+
return `#${String(item.number)} ${String(item.title)}`;
|
|
320
|
+
return (readText(readObject(payload.release), "tag_name") ??
|
|
321
|
+
readText(readObject(payload.workflow_run), "name") ??
|
|
322
|
+
readText(readObject(payload.workflow_job), "name") ??
|
|
323
|
+
readText(readObject(payload.security_advisory), "summary") ??
|
|
324
|
+
readText(payload, "ref"));
|
|
325
|
+
};
|
|
326
|
+
const summarizeEvent = ({ event, action, repository, sender, payload, }) => {
|
|
327
|
+
const subject = readSubject(payload);
|
|
328
|
+
const parts = [
|
|
329
|
+
event,
|
|
330
|
+
action && ` ${action}`,
|
|
331
|
+
repository && ` in ${repository}`,
|
|
332
|
+
sender && ` by ${sender}`,
|
|
333
|
+
subject && `: ${subject}`,
|
|
334
|
+
];
|
|
335
|
+
return truncateSummary(parts.filter(Boolean).join(""));
|
|
336
|
+
};
|
|
337
|
+
const findRefetchUrl = (spec, field, payload) => {
|
|
338
|
+
const url = readText(readObject(payload[field]), "url");
|
|
339
|
+
if (url !== undefined && isGitHubApiUrl(url))
|
|
340
|
+
return url;
|
|
341
|
+
const path = spec.refetch?.[field]?.path(payload);
|
|
342
|
+
return path === undefined ? null : new URL(path, githubApi).href;
|
|
343
|
+
};
|
|
344
|
+
/** Leaves the largest fields out of a payload too large for an event's data, until the data fits. */
|
|
345
|
+
const fitEventData = (data, spec) => fitLargestFields(data.payload, (payload, omitted) => ({
|
|
346
|
+
...data,
|
|
347
|
+
payload,
|
|
348
|
+
...(omitted.length > 0 && {
|
|
349
|
+
omitted: Object.fromEntries(omitted.map((field) => [
|
|
350
|
+
field,
|
|
351
|
+
findRefetchUrl(spec, field, data.payload),
|
|
352
|
+
])),
|
|
353
|
+
}),
|
|
354
|
+
}));
|
|
355
|
+
/** @internal Reads a delivery of the webhook event `name` under the keys its trigger subscribes schedules to. */
|
|
356
|
+
export const readEventDelivery = (name, deliveryId, payload) => {
|
|
357
|
+
if (!isGitHubEventName(name))
|
|
358
|
+
return [];
|
|
359
|
+
const spec = findSpec(name);
|
|
360
|
+
const scope = readDeliveryScope(spec.scope ?? "repository", payload);
|
|
361
|
+
if (!scope)
|
|
362
|
+
return [];
|
|
363
|
+
const action = readText(payload, "action") ?? null;
|
|
364
|
+
const repository = readObject(payload.repository);
|
|
365
|
+
const data = {
|
|
366
|
+
event: name,
|
|
367
|
+
action,
|
|
368
|
+
deliveryId,
|
|
369
|
+
repository: readText(repository, "full_name") ?? null,
|
|
370
|
+
repositoryId: readNumber(repository, "id") ?? null,
|
|
371
|
+
sender: readText(readObject(payload.sender), "login") ?? null,
|
|
372
|
+
payload,
|
|
373
|
+
};
|
|
374
|
+
const eventKeys = [
|
|
375
|
+
constructEventKey(name, scope),
|
|
376
|
+
...(action === null ? [] : [constructEventKey(name, scope, action)]),
|
|
377
|
+
].filter((key) => key.length <= maxEventKeyLength);
|
|
378
|
+
return [
|
|
379
|
+
{
|
|
380
|
+
type: "event",
|
|
381
|
+
eventKeys,
|
|
382
|
+
event: {
|
|
383
|
+
id: `github:delivery:${deliveryId}`,
|
|
384
|
+
summary: summarizeEvent(data),
|
|
385
|
+
data: fitEventData(data, spec),
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
];
|
|
389
|
+
};
|
|
390
|
+
const isGitHubEventData = (data) => typeof data?.event === "string" &&
|
|
391
|
+
isGitHubEventName(data.event) &&
|
|
392
|
+
typeof data.deliveryId === "string" &&
|
|
393
|
+
readObject(data.payload) !== undefined;
|
|
394
|
+
const isRefetchable = (entry) => entry[1] !== null;
|
|
395
|
+
/** Fetches a field left out of a payload, or resolves to undefined once GitHub no longer has it. */
|
|
396
|
+
const fetchOmitted = async (token, url, pick) => {
|
|
397
|
+
const response = await fetchGitHub(token, url);
|
|
398
|
+
if (goneStatuses.has(response.status))
|
|
399
|
+
return undefined;
|
|
400
|
+
if (!response.ok)
|
|
401
|
+
throw await constructGitHubError(response, url);
|
|
402
|
+
const body = await response.json();
|
|
403
|
+
return pick === undefined ? body : readObject(body)?.[pick];
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* Reads the GitHub webhook event that started a run of one of `githubTriggers()`' event triggers. When its payload
|
|
407
|
+
* was too large to carry whole, it fetches the fields left out with the schedule's token through `connection`.
|
|
408
|
+
*
|
|
409
|
+
* @param task The run, as `onTask` receives it.
|
|
410
|
+
* @param connection The skill's GitHub connection.
|
|
411
|
+
* @returns The event, with every field GitHub still has back in its `payload`.
|
|
412
|
+
* @throws {AgentJamError} If the run didn't start on a GitHub webhook event, or GitHub refused a request.
|
|
413
|
+
*/
|
|
414
|
+
export const readGitHubEvent = async (task, connection) => {
|
|
415
|
+
const data = task.event?.data;
|
|
416
|
+
if (!isGitHubEventData(data)) {
|
|
417
|
+
throw new AgentJamError("The task's event isn't a GitHub webhook event");
|
|
418
|
+
}
|
|
419
|
+
const { omitted: left = {}, ...event } = data;
|
|
420
|
+
const omitted = Object.entries(left);
|
|
421
|
+
const refetchable = omitted.filter(isRefetchable);
|
|
422
|
+
if (refetchable.length === 0)
|
|
423
|
+
return data;
|
|
424
|
+
const foreign = refetchable.find(([, url]) => !isGitHubApiUrl(url));
|
|
425
|
+
if (foreign) {
|
|
426
|
+
throw new AgentJamError(`Refusing to send a GitHub token to ${foreign[1]}`);
|
|
427
|
+
}
|
|
428
|
+
const token = await task.credentials(connection);
|
|
429
|
+
const { refetch } = findSpec(data.event);
|
|
430
|
+
const restored = await Promise.all(refetchable.map(async ([field, url]) => ({
|
|
431
|
+
field,
|
|
432
|
+
value: await fetchOmitted(token, url, refetch?.[field]?.pick),
|
|
433
|
+
})));
|
|
434
|
+
const found = restored.filter(({ value }) => value !== undefined);
|
|
435
|
+
const missing = omitted.filter(([field]) => found.every((entry) => entry.field !== field));
|
|
436
|
+
const payload = {
|
|
437
|
+
...data.payload,
|
|
438
|
+
...Object.fromEntries(found.map(({ field, value }) => [field, value])),
|
|
439
|
+
};
|
|
440
|
+
return {
|
|
441
|
+
...event,
|
|
442
|
+
payload,
|
|
443
|
+
...(missing.length > 0 && { omitted: Object.fromEntries(missing) }),
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
//# sourceMappingURL=githubEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"githubEvents.js","sourceRoot":"","sources":["../../src/platforms/githubEvents.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAQhD,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,SAAS,EACT,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAwBxB,MAAM,UAAU,GAAG,CAAC,KAAc,EAA0B,EAAE,CAC5D,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IAClE,CAAC,CAAE,KAAoB;IACvB,CAAC,CAAC,SAAS,CAAC;AAEhB,MAAM,QAAQ,GAAG,CAAC,MAA8B,EAAE,GAAW,EAAE,EAAE;IAC/D,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC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E,CAAC;IAEF,OAAO;QACL,GAAG,KAAK;QACR,OAAO;QACP,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;KACxC,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
import type { EventSource } from "../events.js";
|
|
2
|
+
import type { ManagedWebhooksOptions } from "../managedWebhooks.js";
|
|
3
|
+
import type { SecretConnection, Trigger } from "../types.js";
|
|
4
|
+
/** Options for `grafanaWebhooks()`. */
|
|
5
|
+
export type GrafanaWebhooksOptions = {
|
|
6
|
+
/** The secret you passed to `grafanaTriggers()`. */
|
|
7
|
+
secret: string;
|
|
8
|
+
};
|
|
9
|
+
/** An alert that started or stopped firing, as the `task.event.data` of an `alert` run. */
|
|
10
|
+
export type GrafanaAlertData = {
|
|
11
|
+
status: "firing" | "resolved";
|
|
12
|
+
/** The alert's `alertname` label. */
|
|
13
|
+
title: string;
|
|
14
|
+
/** The alert's labels, leaving out Grafana's own, which start with `__`. */
|
|
15
|
+
labels: Record<string, string>;
|
|
16
|
+
annotations: Record<string, string>;
|
|
17
|
+
fingerprint: string;
|
|
18
|
+
startsAt: string;
|
|
19
|
+
endsAt: string;
|
|
20
|
+
/** The alert rule's page in Grafana. */
|
|
21
|
+
url?: string;
|
|
22
|
+
};
|
|
1
23
|
/**
|
|
2
24
|
* Connects a skill to a Grafana instance with a service account token, which the human enters in the platform's form
|
|
3
25
|
* and tasks reach through `connectionFetch()`.
|
|
@@ -6,5 +28,29 @@
|
|
|
6
28
|
* @returns A connection to list in a skill's `connections`.
|
|
7
29
|
* @throws {AgentJamError} If an allowed request is invalid, or `descriptions` names a field the connection doesn't ask for.
|
|
8
30
|
*/
|
|
9
|
-
export declare const grafanaConnection: ({ allow, descriptions, }?: import("../secrets.js").SecretPresetOptions<"baseUrl" | "token">) =>
|
|
31
|
+
export declare const grafanaConnection: ({ allow, descriptions, }?: import("../secrets.js").SecretPresetOptions<"baseUrl" | "token">) => SecretConnection;
|
|
32
|
+
/**
|
|
33
|
+
* Reads the webhooks `grafanaTriggers()` creates, for `agent.receiveEvents()` at the URL you passed it. It checks
|
|
34
|
+
* each request's signature with its schedule's secret in constant time, and responds to one that isn't signed in the
|
|
35
|
+
* last five minutes with a `401`.
|
|
36
|
+
*
|
|
37
|
+
* @param options The secret you passed to `grafanaTriggers()`.
|
|
38
|
+
* @returns An event source for Grafana's webhooks.
|
|
39
|
+
*/
|
|
40
|
+
export declare const grafanaWebhooks: ({ secret, }: GrafanaWebhooksOptions) => EventSource;
|
|
41
|
+
/**
|
|
42
|
+
* Triggers that run a schedule when a Grafana instance's alerts fire or resolve, for a skill whose connections
|
|
43
|
+
* include `connection`, with a service account token allowed to write notification settings, such as an Editor's.
|
|
44
|
+
* Each schedule gets its own webhook contact point and a notification policy that copies it the alerts it watches
|
|
45
|
+
* before the rest of the policy tree routes them as before, plus a poll of firing alerts for any webhook it loses.
|
|
46
|
+
* Both are removed once the schedule ends.
|
|
47
|
+
*
|
|
48
|
+
* @param connection The skill's Grafana connection.
|
|
49
|
+
* @param options Where Grafana sends webhooks, the secret they derive from, and how the fallback polls run.
|
|
50
|
+
* @returns The `alert` trigger, for a skill's `triggers`.
|
|
51
|
+
*/
|
|
52
|
+
export declare const grafanaTriggers: (connection: SecretConnection, options: ManagedWebhooksOptions) => {
|
|
53
|
+
/** An alert matching `config.matchers` starts or stops firing. */
|
|
54
|
+
alert: Trigger;
|
|
55
|
+
};
|
|
10
56
|
//# sourceMappingURL=grafana.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grafana.d.ts","sourceRoot":"","sources":["../../src/platforms/grafana.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"grafana.d.ts","sourceRoot":"","sources":["../../src/platforms/grafana.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EACV,sBAAsB,EAGvB,MAAM,uBAAuB,CAAC;AAS/B,OAAO,KAAK,EAEV,gBAAgB,EAChB,OAAO,EAIR,MAAM,aAAa,CAAC;AAGrB,uCAAuC;AACvC,MAAM,MAAM,sBAAsB,GAAG;IACnC,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,2FAA2F;AAC3F,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC9B,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAkCF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,mHAG5B,CAAC;AA2LH;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,gBAEzB,sBAAsB,KAAG,WAyB1B,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,eACd,gBAAgB,WACnB,sBAAsB;IAG7B,kEAAkE;;CAqBhC,CAAC"}
|