@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,115 @@
|
|
|
1
|
+
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { AgentJamError } from "./errors.js";
|
|
3
|
+
import { readSourceRequest } from "./events.js";
|
|
4
|
+
import { pollSchedule } from "./polling.js";
|
|
5
|
+
import { MemoryWatermarkStore } from "./watermarks.js";
|
|
6
|
+
const namePrefix = "agentjam-";
|
|
7
|
+
const overlapMs = 2 * 60_000;
|
|
8
|
+
/** @internal The header that names the schedule webhook a request was sent to. */
|
|
9
|
+
export const subscriptionHeader = "x-agentjam-subscription";
|
|
10
|
+
/** @internal The header that carries a schedule webhook's secret. */
|
|
11
|
+
export const secretHeader = "x-agentjam-secret";
|
|
12
|
+
const computeSha256 = (text) => createHash("sha256").update(text).digest();
|
|
13
|
+
/** @internal Derives the secret of the schedule webhook named `name` from your agent's `secret`. */
|
|
14
|
+
export const computeWebhookSecret = (secret, name) => createHmac("sha256", secret).update(name).digest("hex");
|
|
15
|
+
/** @internal Checks in constant time whether a request's `received` secret or signature is the `expected` one. */
|
|
16
|
+
export const isMatchingSecret = (received, expected) => received !== null &&
|
|
17
|
+
timingSafeEqual(computeSha256(received), computeSha256(expected));
|
|
18
|
+
/**
|
|
19
|
+
* @internal Sends a JSON request to `provider` through `fetch`.
|
|
20
|
+
*
|
|
21
|
+
* @returns The response's body, or undefined if it's empty or what it names doesn't exist.
|
|
22
|
+
* @throws {AgentJamError} If the provider answers with another error status.
|
|
23
|
+
*/
|
|
24
|
+
export const requestProvider = async (fetch, provider, path, { method = "GET", headers = {}, body } = {}) => {
|
|
25
|
+
const response = await fetch(path, {
|
|
26
|
+
method,
|
|
27
|
+
headers: {
|
|
28
|
+
accept: "application/json",
|
|
29
|
+
"content-type": "application/json",
|
|
30
|
+
...headers,
|
|
31
|
+
},
|
|
32
|
+
...(body && { body: JSON.stringify(body) }),
|
|
33
|
+
});
|
|
34
|
+
if (response.status === 404)
|
|
35
|
+
return undefined;
|
|
36
|
+
const text = await response.text();
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new AgentJamError(`${provider} answered ${response.status} for ${path}: ${text}`);
|
|
39
|
+
}
|
|
40
|
+
return (text === "" ? undefined : JSON.parse(text));
|
|
41
|
+
};
|
|
42
|
+
/** @internal The key a schedule webhook's events are dispatched under. */
|
|
43
|
+
export const constructWebhookKey = (provider, name) => `${provider}:${name}`;
|
|
44
|
+
const constructScheduleWebhook = (schedule, { url, secret }) => {
|
|
45
|
+
const name = `${namePrefix}${computeSha256(schedule.id).toString("hex").slice(0, 16)}`;
|
|
46
|
+
return { name, url, secret: computeWebhookSecret(secret, name) };
|
|
47
|
+
};
|
|
48
|
+
const reconcileSchedule = (reconcile, schedule, context, { watermarks = new MemoryWatermarkStore(), pollIntervalMinutes = 5, onError = console.error, }) => {
|
|
49
|
+
const poll = async (watermark) => {
|
|
50
|
+
const startedAt = new Date().toISOString();
|
|
51
|
+
const { since, checkedAt } = watermark.current;
|
|
52
|
+
const from = Math.max(Date.parse(since), Date.parse(checkedAt) - overlapMs);
|
|
53
|
+
for (const event of await reconcile(new Date(from), schedule, context)) {
|
|
54
|
+
await context.fire(event);
|
|
55
|
+
}
|
|
56
|
+
await watermark.advance({ checkedAt: startedAt });
|
|
57
|
+
};
|
|
58
|
+
const now = new Date().toISOString();
|
|
59
|
+
return pollSchedule({
|
|
60
|
+
schedule,
|
|
61
|
+
watermarks,
|
|
62
|
+
initial: { since: now, checkedAt: now },
|
|
63
|
+
intervalMinutes: pollIntervalMinutes,
|
|
64
|
+
target: `the ${schedule.trigger} events of schedule ${schedule.id}`,
|
|
65
|
+
onError,
|
|
66
|
+
poll,
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* @internal Builds a trigger that gives each schedule its own webhook at the provider while it's active, polls for
|
|
71
|
+
* events a lost webhook would miss when the provider can list them, and removes the webhook once the schedule ends.
|
|
72
|
+
*/
|
|
73
|
+
export const constructManagedTrigger = (subscriber, options) => ({
|
|
74
|
+
description: subscriber.description,
|
|
75
|
+
config: subscriber.config,
|
|
76
|
+
onScheduleActive: async (schedule, context) => {
|
|
77
|
+
const webhook = constructScheduleWebhook(schedule, options);
|
|
78
|
+
await subscriber.subscribe(webhook, schedule, context);
|
|
79
|
+
const polling = subscriber.reconcile &&
|
|
80
|
+
(await reconcileSchedule(subscriber.reconcile, schedule, context, options));
|
|
81
|
+
return {
|
|
82
|
+
eventKeys: [constructWebhookKey(subscriber.provider, webhook.name)],
|
|
83
|
+
stop: async ({ reason }) => {
|
|
84
|
+
polling?.stop();
|
|
85
|
+
if (reason === "ended") {
|
|
86
|
+
await subscriber.unsubscribe(webhook, schedule, context);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* @internal Builds the event source of a provider that sends each schedule webhook's name and secret as headers,
|
|
94
|
+
* reading each verified request's events with `read`.
|
|
95
|
+
*/
|
|
96
|
+
export const constructHeaderWebhooks = (provider, secret, read) => ({
|
|
97
|
+
receive: async (request) => {
|
|
98
|
+
const { headers, body } = await readSourceRequest(request);
|
|
99
|
+
const name = headers.get(subscriptionHeader) ?? "";
|
|
100
|
+
const expected = computeWebhookSecret(secret, name);
|
|
101
|
+
if (!isMatchingSecret(headers.get(secretHeader), expected)) {
|
|
102
|
+
return {
|
|
103
|
+
response: { status: 401, body: "Invalid webhook secret" },
|
|
104
|
+
events: [],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const eventKeys = [constructWebhookKey(provider, name)];
|
|
108
|
+
const events = read(JSON.parse(body));
|
|
109
|
+
return {
|
|
110
|
+
response: { status: 200 },
|
|
111
|
+
events: events.map((event) => ({ type: "event", eventKeys, event })),
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=managedWebhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managedWebhooks.js","sourceRoot":"","sources":["../src/managedWebhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAW5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAkDvD,MAAM,UAAU,GAAG,WAAW,CAAC;AAE/B,MAAM,SAAS,GAAG,CAAC,GAAG,MAAM,CAAC;AAE7B,kFAAkF;AAClF,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AAE5D,qEAAqE;AACrE,MAAM,CAAC,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAEhD,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE,CACrC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;AAE7C,oGAAoG;AAC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;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OAuthConnection, OAuthPresetOptions } from "../connections.js";
|
|
2
|
+
import type { OAuthProfile } from "../providers.js";
|
|
3
|
+
/** How to run Atlassian's OAuth 2.0 (3LO) flow, which asks for consent to Atlassian's API on every link. */
|
|
4
|
+
export declare const atlassianProfile: OAuthProfile;
|
|
5
|
+
/**
|
|
6
|
+
* Connects a skill to a human's Atlassian account, such as for Jira or Confluence, through an OAuth 2.0 (3LO) app.
|
|
7
|
+
* Request `offline_access` among the scopes, or Atlassian issues no refresh token and the grant lapses within an hour.
|
|
8
|
+
* The client settings left out are read from `ATLASSIAN_CLIENT_ID`, `ATLASSIAN_CLIENT_SECRET` and
|
|
9
|
+
* `ATLASSIAN_REDIRECT_URI`.
|
|
10
|
+
*
|
|
11
|
+
* @param options The scopes to request, such as `read:jira-work`, and a token store if the relay holds no grants.
|
|
12
|
+
* @returns A connection to list in a skill's `connections`.
|
|
13
|
+
* @throws {AgentJamError} If a client setting is neither passed nor set in the environment.
|
|
14
|
+
*/
|
|
15
|
+
export declare const atlassianConnection: (options: OAuthPresetOptions & {
|
|
16
|
+
scopes: string[];
|
|
17
|
+
}) => OAuthConnection<"default">;
|
|
18
|
+
//# sourceMappingURL=atlassian.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atlassian.d.ts","sourceRoot":"","sources":["../../src/platforms/atlassian.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAIpD,4GAA4G;AAC5G,eAAO,MAAM,gBAAgB,EAAE,YAQ9B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,YACrB,kBAAkB,GAAG;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,KACjD,eAAe,CAAC,SAAS,CAIzB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { constructStandardProfile } from "../providers.js";
|
|
2
|
+
import { constructOAuthPreset } from "./presets.js";
|
|
3
|
+
/** How to run Atlassian's OAuth 2.0 (3LO) flow, which asks for consent to Atlassian's API on every link. */
|
|
4
|
+
export const atlassianProfile = {
|
|
5
|
+
...constructStandardProfile({
|
|
6
|
+
authorize: "https://auth.atlassian.com/authorize",
|
|
7
|
+
token: "https://auth.atlassian.com/oauth/token",
|
|
8
|
+
params: { audience: "api.atlassian.com", prompt: "consent" },
|
|
9
|
+
}),
|
|
10
|
+
// WARNING: Atlassian's 3LO flow documents no PKCE, so the code exchange relies on the client secret alone.
|
|
11
|
+
pkce: false,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Connects a skill to a human's Atlassian account, such as for Jira or Confluence, through an OAuth 2.0 (3LO) app.
|
|
15
|
+
* Request `offline_access` among the scopes, or Atlassian issues no refresh token and the grant lapses within an hour.
|
|
16
|
+
* The client settings left out are read from `ATLASSIAN_CLIENT_ID`, `ATLASSIAN_CLIENT_SECRET` and
|
|
17
|
+
* `ATLASSIAN_REDIRECT_URI`.
|
|
18
|
+
*
|
|
19
|
+
* @param options The scopes to request, such as `read:jira-work`, and a token store if the relay holds no grants.
|
|
20
|
+
* @returns A connection to list in a skill's `connections`.
|
|
21
|
+
* @throws {AgentJamError} If a client setting is neither passed nor set in the environment.
|
|
22
|
+
*/
|
|
23
|
+
export const atlassianConnection = (options) => constructOAuthPreset({ provider: "atlassian", profile: atlassianProfile, prefix: "ATLASSIAN" }, options);
|
|
24
|
+
//# sourceMappingURL=atlassian.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atlassian.js","sourceRoot":"","sources":["../../src/platforms/atlassian.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,4GAA4G;AAC5G,MAAM,CAAC,MAAM,gBAAgB,GAAiB;IAC5C,GAAG,wBAAwB,CAAC;QAC1B,SAAS,EAAE,sCAAsC;QACjD,KAAK,EAAE,wCAAwC;QAC/C,MAAM,EAAE,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,EAAE,SAAS,EAAE;KAC7D,CAAC;IACF,2GAA2G;IAC3G,IAAI,EAAE,KAAK;CACZ,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,OAAkD,EACtB,EAAE,CAC9B,oBAAoB,CAClB,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,EACzE,OAAO,CACR,CAAC"}
|
|
@@ -1,3 +1,24 @@
|
|
|
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 `datadogWebhooks()`. */
|
|
5
|
+
export type DatadogWebhooksOptions = {
|
|
6
|
+
/** The secret you passed to `datadogTriggers()`. */
|
|
7
|
+
secret: string;
|
|
8
|
+
};
|
|
9
|
+
/** A monitor's alert, warning or recovery, as the `task.event.data` of a `monitor_alert` run. */
|
|
10
|
+
export type DatadogAlertData = {
|
|
11
|
+
monitorId: string;
|
|
12
|
+
title: string;
|
|
13
|
+
status: "firing" | "resolved";
|
|
14
|
+
severity: "critical" | "warning" | "info";
|
|
15
|
+
message: string;
|
|
16
|
+
tags: string[];
|
|
17
|
+
query: string;
|
|
18
|
+
/** The monitor's page in Datadog. */
|
|
19
|
+
url: string;
|
|
20
|
+
changedAt: string;
|
|
21
|
+
};
|
|
1
22
|
/**
|
|
2
23
|
* Connects a skill to a Datadog organization with an API key and a service account's application key, which the
|
|
3
24
|
* human enters in the platform's form and tasks reach through `connectionFetch()`.
|
|
@@ -6,5 +27,28 @@
|
|
|
6
27
|
* @returns A connection to list in a skill's `connections`.
|
|
7
28
|
* @throws {AgentJamError} If an allowed request is invalid, or `descriptions` names a field the connection doesn't ask for.
|
|
8
29
|
*/
|
|
9
|
-
export declare const datadogConnection: ({ allow, descriptions, }?: import("../secrets.js").SecretPresetOptions<"apiKey" | "applicationKey" | "site">) =>
|
|
30
|
+
export declare const datadogConnection: ({ allow, descriptions, }?: import("../secrets.js").SecretPresetOptions<"apiKey" | "applicationKey" | "site">) => SecretConnection;
|
|
31
|
+
/**
|
|
32
|
+
* Reads the webhooks `datadogTriggers()` creates, for `agent.receiveEvents()` at the URL you passed it. It checks
|
|
33
|
+
* each request carries its schedule's secret in constant time, and responds to one that doesn't with a `401`.
|
|
34
|
+
*
|
|
35
|
+
* @param options The secret you passed to `datadogTriggers()`.
|
|
36
|
+
* @returns An event source for Datadog's webhooks.
|
|
37
|
+
*/
|
|
38
|
+
export declare const datadogWebhooks: ({ secret, }: DatadogWebhooksOptions) => EventSource;
|
|
39
|
+
/**
|
|
40
|
+
* Triggers that run a schedule when a Datadog organization's monitors alert, for a skill whose connections include
|
|
41
|
+
* `connection`, with an application key holding the `events_read`, `manage_integrations` and
|
|
42
|
+
* `monitor_notification_rules_write` permissions. Each schedule gets its own webhook and notification rule, which
|
|
43
|
+
* Datadog sends to `url` for `datadogWebhooks()` to read, and a poll of the event stream for any webhook it loses.
|
|
44
|
+
* Both are removed once the schedule ends.
|
|
45
|
+
*
|
|
46
|
+
* @param connection The skill's Datadog connection.
|
|
47
|
+
* @param options Where Datadog sends webhooks, the secret they derive from, and how the fallback polls run.
|
|
48
|
+
* @returns The `monitor_alert` trigger, for a skill's `triggers`.
|
|
49
|
+
*/
|
|
50
|
+
export declare const datadogTriggers: (connection: SecretConnection, options: ManagedWebhooksOptions) => {
|
|
51
|
+
/** A monitor whose tags match `config.scope` alerts, warns or recovers, once per transition. */
|
|
52
|
+
monitor_alert: Trigger;
|
|
53
|
+
};
|
|
10
54
|
//# sourceMappingURL=datadog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datadog.d.ts","sourceRoot":"","sources":["../../src/platforms/datadog.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"datadog.d.ts","sourceRoot":"","sources":["../../src/platforms/datadog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EACV,sBAAsB,EAGvB,MAAM,uBAAuB,CAAC;AAS/B,OAAO,KAAK,EAGV,gBAAgB,EAChB,OAAO,EAIR,MAAM,aAAa,CAAC;AAGrB,uCAAuC;AACvC,MAAM,MAAM,sBAAsB,GAAG;IACnC,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,iGAAiG;AACjG,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC9B,QAAQ,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAwEF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,oIAI5B,CAAC;AAgOH;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,gBAEzB,sBAAsB,KAAG,WACoC,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,eACd,gBAAgB,WACnB,sBAAsB;IAG7B,gGAAgG;;CAwB9D,CAAC"}
|
|
@@ -1,4 +1,25 @@
|
|
|
1
|
+
import { constructHeaderWebhooks, constructManagedTrigger, requestProvider, secretHeader, subscriptionHeader, } from "../managedWebhooks.js";
|
|
2
|
+
import { truncateSummary } from "../polling.js";
|
|
1
3
|
import { constructSecretPreset } from "./presets.js";
|
|
4
|
+
const webhooksPath = "/api/v1/integration/webhooks/configuration/webhooks";
|
|
5
|
+
const variablesPath = "/api/v1/integration/webhooks/configuration/custom-variables";
|
|
6
|
+
const rulesPath = "/api/v2/monitor/notification_rule";
|
|
7
|
+
const maxEventPages = 10;
|
|
8
|
+
const maxMessageLength = 10_000;
|
|
9
|
+
const webhookStates = {
|
|
10
|
+
Triggered: { status: "firing", severity: "critical" },
|
|
11
|
+
Warn: { status: "firing", severity: "warning" },
|
|
12
|
+
Recovered: { status: "resolved", severity: "info" },
|
|
13
|
+
};
|
|
14
|
+
const transitionStates = {
|
|
15
|
+
alert: { status: "firing", severity: "critical" },
|
|
16
|
+
warning: { status: "firing", severity: "warning" },
|
|
17
|
+
"alert recovery": { status: "resolved", severity: "info" },
|
|
18
|
+
"warning recovery": { status: "resolved", severity: "info" },
|
|
19
|
+
};
|
|
20
|
+
const transitionsQuery = `source:alert @monitor.transition.transition_type:(${Object.keys(transitionStates)
|
|
21
|
+
.map((transition) => `"${transition}"`)
|
|
22
|
+
.join(" OR ")})`;
|
|
2
23
|
/**
|
|
3
24
|
* Connects a skill to a Datadog organization with an API key and a service account's application key, which the
|
|
4
25
|
* human enters in the platform's form and tasks reach through `connectionFetch()`.
|
|
@@ -12,4 +33,190 @@ export const datadogConnection = constructSecretPreset("datadog", [
|
|
|
12
33
|
"apiKey",
|
|
13
34
|
"applicationKey",
|
|
14
35
|
]);
|
|
36
|
+
const constructAppUrl = (site) => site.split(".").length === 2 ? `https://app.${site}` : `https://${site}`;
|
|
37
|
+
const constructVariableName = (name) => `${name.toUpperCase().replaceAll("-", "_")}_SECRET`;
|
|
38
|
+
const requestDatadog = (fetch, path, request = {}) => requestProvider(fetch, "Datadog", path, request);
|
|
39
|
+
const upsertResource = async (fetch, path, resource) => {
|
|
40
|
+
const existing = await requestDatadog(fetch, `${path}/${resource.name}`);
|
|
41
|
+
await requestDatadog(fetch, existing ? `${path}/${resource.name}` : path, {
|
|
42
|
+
method: existing ? "PUT" : "POST",
|
|
43
|
+
body: resource,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const findRule = async (fetch, name) => {
|
|
47
|
+
const query = new URLSearchParams({
|
|
48
|
+
filters: JSON.stringify({ text: name }),
|
|
49
|
+
});
|
|
50
|
+
const rules = await requestDatadog(fetch, `${rulesPath}?${query.toString()}`);
|
|
51
|
+
return rules?.data?.find(({ attributes }) => attributes.name === name);
|
|
52
|
+
};
|
|
53
|
+
const upsertRule = async (fetch, name, scope) => {
|
|
54
|
+
const existing = await findRule(fetch, name);
|
|
55
|
+
const attributes = {
|
|
56
|
+
name,
|
|
57
|
+
filter: { scope },
|
|
58
|
+
recipients: [`webhook-${name}`],
|
|
59
|
+
};
|
|
60
|
+
await requestDatadog(fetch, existing ? `${rulesPath}/${existing.id}` : rulesPath, {
|
|
61
|
+
method: existing ? "PATCH" : "POST",
|
|
62
|
+
body: {
|
|
63
|
+
data: {
|
|
64
|
+
type: "monitor-notification-rule",
|
|
65
|
+
...(existing && { id: existing.id }),
|
|
66
|
+
attributes,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const subscribeMonitors = (connection) => async ({ name, url, secret }, { config }, context) => {
|
|
72
|
+
const fetch = context.connectionFetch(connection);
|
|
73
|
+
const { site = "datadoghq.com" } = await context.connectionConfig(connection);
|
|
74
|
+
const variable = constructVariableName(name);
|
|
75
|
+
await upsertResource(fetch, variablesPath, {
|
|
76
|
+
name: variable,
|
|
77
|
+
value: secret,
|
|
78
|
+
is_secret: true,
|
|
79
|
+
});
|
|
80
|
+
await upsertResource(fetch, webhooksPath, {
|
|
81
|
+
name,
|
|
82
|
+
url,
|
|
83
|
+
payload: JSON.stringify({
|
|
84
|
+
eventId: "$ID",
|
|
85
|
+
monitorId: "$ALERT_ID",
|
|
86
|
+
transition: "$ALERT_TRANSITION",
|
|
87
|
+
title: "$EVENT_TITLE",
|
|
88
|
+
message: "$TEXT_ONLY_MSG",
|
|
89
|
+
date: "$DATE",
|
|
90
|
+
query: "$ALERT_QUERY",
|
|
91
|
+
tags: "$TAGS",
|
|
92
|
+
url: `${constructAppUrl(site)}/monitors/$ALERT_ID`,
|
|
93
|
+
}),
|
|
94
|
+
custom_headers: JSON.stringify({
|
|
95
|
+
[subscriptionHeader]: name,
|
|
96
|
+
[secretHeader]: `$${variable}`,
|
|
97
|
+
}),
|
|
98
|
+
encode_as: "json",
|
|
99
|
+
});
|
|
100
|
+
await upsertRule(fetch, name, config.scope);
|
|
101
|
+
};
|
|
102
|
+
const unsubscribeMonitors = (connection) => async ({ name }, _, context) => {
|
|
103
|
+
const fetch = context.connectionFetch(connection);
|
|
104
|
+
const rule = await findRule(fetch, name);
|
|
105
|
+
if (rule) {
|
|
106
|
+
await requestDatadog(fetch, `${rulesPath}/${rule.id}`, {
|
|
107
|
+
method: "DELETE",
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
await requestDatadog(fetch, `${webhooksPath}/${name}`, {
|
|
111
|
+
method: "DELETE",
|
|
112
|
+
});
|
|
113
|
+
await requestDatadog(fetch, `${variablesPath}/${constructVariableName(name)}`, { method: "DELETE" });
|
|
114
|
+
};
|
|
115
|
+
const constructAlertEvent = (eventId, data) => ({
|
|
116
|
+
id: `datadog:${data.monitorId}:${eventId}`,
|
|
117
|
+
summary: truncateSummary(`Datadog monitor ${data.status}: ${data.title}`),
|
|
118
|
+
data: { ...data, message: data.message.slice(0, maxMessageLength) },
|
|
119
|
+
});
|
|
120
|
+
const readDatadogWebhook = (payload) => {
|
|
121
|
+
const { eventId, monitorId, transition, date, tags, ...fields } = payload;
|
|
122
|
+
const state = webhookStates[transition];
|
|
123
|
+
if (!state || !eventId || !monitorId)
|
|
124
|
+
return [];
|
|
125
|
+
return [
|
|
126
|
+
constructAlertEvent(eventId, {
|
|
127
|
+
monitorId,
|
|
128
|
+
title: fields.title,
|
|
129
|
+
...state,
|
|
130
|
+
message: fields.message,
|
|
131
|
+
tags: tags.split(",").filter(Boolean),
|
|
132
|
+
query: fields.query,
|
|
133
|
+
url: fields.url,
|
|
134
|
+
changedAt: new Date(Number(date)).toISOString(),
|
|
135
|
+
}),
|
|
136
|
+
];
|
|
137
|
+
};
|
|
138
|
+
const listEvents = async (fetch, query, since) => {
|
|
139
|
+
const events = [];
|
|
140
|
+
let cursor;
|
|
141
|
+
for (let page = 0; page < maxEventPages; page++) {
|
|
142
|
+
const search = new URLSearchParams({
|
|
143
|
+
"filter[query]": query,
|
|
144
|
+
"filter[from]": String(since.getTime()),
|
|
145
|
+
sort: "timestamp",
|
|
146
|
+
"page[limit]": "1000",
|
|
147
|
+
...(cursor !== undefined && { "page[cursor]": cursor }),
|
|
148
|
+
});
|
|
149
|
+
const found = await requestDatadog(fetch, `/api/v2/events?${search.toString()}`);
|
|
150
|
+
events.push(...(found?.data ?? []));
|
|
151
|
+
cursor = found?.meta?.page?.after;
|
|
152
|
+
if (cursor === undefined)
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
return events;
|
|
156
|
+
};
|
|
157
|
+
const constructTransitionEvents = ({ attributes }, appUrl) => {
|
|
158
|
+
const { title, evt, monitor } = attributes.attributes ?? {};
|
|
159
|
+
const state = transitionStates[monitor?.transition?.transition_type ?? ""];
|
|
160
|
+
if (monitor?.id === undefined || evt?.id === undefined || !state)
|
|
161
|
+
return [];
|
|
162
|
+
return [
|
|
163
|
+
constructAlertEvent(evt.id, {
|
|
164
|
+
monitorId: String(monitor.id),
|
|
165
|
+
title: title ?? monitor.name ?? "",
|
|
166
|
+
...state,
|
|
167
|
+
message: attributes.message ?? "",
|
|
168
|
+
tags: attributes.tags ?? [],
|
|
169
|
+
query: monitor.query ?? "",
|
|
170
|
+
url: `${appUrl}/monitors/${monitor.id}`,
|
|
171
|
+
changedAt: new Date(attributes.timestamp).toISOString(),
|
|
172
|
+
}),
|
|
173
|
+
];
|
|
174
|
+
};
|
|
175
|
+
const reconcileMonitors = (connection) => async (since, { config }, context) => {
|
|
176
|
+
const fetch = context.connectionFetch(connection);
|
|
177
|
+
const { site = "datadoghq.com" } = await context.connectionConfig(connection);
|
|
178
|
+
const query = `${transitionsQuery} (${config.scope})`;
|
|
179
|
+
const events = await listEvents(fetch, query, since);
|
|
180
|
+
return events.flatMap((event) => constructTransitionEvents(event, constructAppUrl(site)));
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Reads the webhooks `datadogTriggers()` creates, for `agent.receiveEvents()` at the URL you passed it. It checks
|
|
184
|
+
* each request carries its schedule's secret in constant time, and responds to one that doesn't with a `401`.
|
|
185
|
+
*
|
|
186
|
+
* @param options The secret you passed to `datadogTriggers()`.
|
|
187
|
+
* @returns An event source for Datadog's webhooks.
|
|
188
|
+
*/
|
|
189
|
+
export const datadogWebhooks = ({ secret, }) => constructHeaderWebhooks("datadog", secret, readDatadogWebhook);
|
|
190
|
+
/**
|
|
191
|
+
* Triggers that run a schedule when a Datadog organization's monitors alert, for a skill whose connections include
|
|
192
|
+
* `connection`, with an application key holding the `events_read`, `manage_integrations` and
|
|
193
|
+
* `monitor_notification_rules_write` permissions. Each schedule gets its own webhook and notification rule, which
|
|
194
|
+
* Datadog sends to `url` for `datadogWebhooks()` to read, and a poll of the event stream for any webhook it loses.
|
|
195
|
+
* Both are removed once the schedule ends.
|
|
196
|
+
*
|
|
197
|
+
* @param connection The skill's Datadog connection.
|
|
198
|
+
* @param options Where Datadog sends webhooks, the secret they derive from, and how the fallback polls run.
|
|
199
|
+
* @returns The `monitor_alert` trigger, for a skill's `triggers`.
|
|
200
|
+
*/
|
|
201
|
+
export const datadogTriggers = (connection, options) => ({
|
|
202
|
+
/** A monitor whose tags match `config.scope` alerts, warns or recovers, once per transition. */
|
|
203
|
+
monitor_alert: constructManagedTrigger({
|
|
204
|
+
provider: "datadog",
|
|
205
|
+
description: "A Datadog monitor whose tags match a scope alerts, warns or recovers",
|
|
206
|
+
config: {
|
|
207
|
+
type: "object",
|
|
208
|
+
properties: {
|
|
209
|
+
scope: {
|
|
210
|
+
type: "string",
|
|
211
|
+
minLength: 1,
|
|
212
|
+
description: "The monitors to watch, by their tags, such as service:checkout AND env:prod",
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
required: ["scope"],
|
|
216
|
+
},
|
|
217
|
+
subscribe: subscribeMonitors(connection),
|
|
218
|
+
unsubscribe: unsubscribeMonitors(connection),
|
|
219
|
+
reconcile: reconcileMonitors(connection),
|
|
220
|
+
}, options),
|
|
221
|
+
});
|
|
15
222
|
//# sourceMappingURL=datadog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datadog.js","sourceRoot":"","sources":["../../src/platforms/datadog.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"datadog.js","sourceRoot":"","sources":["../../src/platforms/datadog.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,eAAe,EACf,YAAY,EACZ,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAUhD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AA8DrD,MAAM,YAAY,GAAG,qDAAqD,CAAC;AAE3E,MAAM,aAAa,GACjB,6DAA6D,CAAC;AAEhE,MAAM,SAAS,GAAG,mCAAmC,CAAC;AAEtD,MAAM,aAAa,GAAG,EAAE,CAAC;AAEzB,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,aAAa,GAAiC;IAClD,SAAS,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE;IACrD,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE;IAC/C,SAAS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d,UAAU,EAAE;gBACV,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,SAAS,EAAE,CAAC;oBACZ,WAAW,EACT,6EAA6E;iBAChF;aACF;YACD,QAAQ,EAAE,CAAC,OAAO,CAAC;SACpB;QACD,SAAS,EAAE,iBAAiB,CAAC,UAAU,CAAC;QACxC,WAAW,EAAE,mBAAmB,CAAC,UAAU,CAAC;QAC5C,SAAS,EAAE,iBAAiB,CAAC,UAAU,CAAC;KACzC,EACD,OAAO,CACR;CACF,CAAmC,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { CredentialSource, OAuthConnection, OAuthPresetOptions } from "../connections.js";
|
|
2
2
|
import type { OAuthProfile } from "../providers.js";
|
|
3
|
-
import type { JsonSchema,
|
|
4
|
-
export
|
|
3
|
+
import type { JsonSchema, Trigger } from "../types.js";
|
|
4
|
+
export type { DiscordEventData, DiscordEventName } from "./discordEvents.js";
|
|
5
|
+
export { connectDiscordGateway, discordIntents, type DiscordCommand, type DiscordGateway, type DiscordGatewayOptions, type DiscordMessageData, } from "./discordGateway.js";
|
|
6
|
+
export type { DiscordCommandData, DiscordComponentData, } from "./discordInteractions.js";
|
|
5
7
|
/** Options for `discordConnection()`. */
|
|
6
8
|
export type DiscordConnectionOptions = OAuthPresetOptions & {
|
|
7
9
|
/** The permissions the bot asks for in the server, as Discord's permission bitfield, such as `"2048"` to send messages. Defaults to none. */
|
|
@@ -31,25 +33,26 @@ export declare const discordProfile: OAuthProfile;
|
|
|
31
33
|
*/
|
|
32
34
|
export declare const discordConnection: ({ permissions, scopes, ...options }?: DiscordConnectionOptions) => OAuthConnection<"default">;
|
|
33
35
|
/**
|
|
34
|
-
* Triggers that run a schedule on
|
|
35
|
-
*
|
|
36
|
-
*
|
|
36
|
+
* Triggers that run a schedule on what `connectDiscordGateway()` dispatches, for a skill whose connections include
|
|
37
|
+
* `connection`: messages, slash commands, components and modals, and one per Gateway event type such as
|
|
38
|
+
* `message_reaction_add`. Every schedule watching one gets its own run, with a `DiscordMessageData`,
|
|
39
|
+
* `DiscordCommandData`, `DiscordComponentData` or `DiscordEventData` as `task.event.data`.
|
|
37
40
|
*
|
|
38
41
|
* @param connection The skill's Discord connection.
|
|
39
|
-
* @returns The
|
|
42
|
+
* @returns The triggers, for a skill's `triggers`.
|
|
40
43
|
*/
|
|
41
44
|
export declare const discordTriggers: (connection: CredentialSource) => {
|
|
42
45
|
/** A message in a channel the bot can read in the server, or only in `config.channel` when the requester sets it. */
|
|
43
46
|
message: {
|
|
44
47
|
description: string;
|
|
45
48
|
config: JsonSchema;
|
|
46
|
-
onScheduleActive: (schedule: TriggerSchedule, context: TriggerContext) => import("../types.js").Awaitable<import("../types.js").TriggerActivation | void>;
|
|
49
|
+
onScheduleActive: (schedule: import("../types.js").TriggerSchedule, context: import("../types.js").TriggerContext) => import("../types.js").Awaitable<import("../types.js").TriggerActivation | void>;
|
|
47
50
|
};
|
|
48
51
|
/** A message that mentions the bot, in any channel of the server or only in `config.channel`. */
|
|
49
52
|
mention: {
|
|
50
53
|
description: string;
|
|
51
54
|
config: JsonSchema;
|
|
52
|
-
onScheduleActive: (schedule: TriggerSchedule, context: TriggerContext) => import("../types.js").Awaitable<import("../types.js").TriggerActivation | void>;
|
|
55
|
+
onScheduleActive: (schedule: import("../types.js").TriggerSchedule, context: import("../types.js").TriggerContext) => import("../types.js").Awaitable<import("../types.js").TriggerActivation | void>;
|
|
53
56
|
};
|
|
54
57
|
/** A direct message to the bot from the human who added it to the server. */
|
|
55
58
|
directMessage: {
|
|
@@ -58,17 +61,62 @@ export declare const discordTriggers: (connection: CredentialSource) => {
|
|
|
58
61
|
type: string;
|
|
59
62
|
properties: {};
|
|
60
63
|
};
|
|
61
|
-
onScheduleActive: (_schedule: TriggerSchedule, context: TriggerContext) => Promise<{
|
|
64
|
+
onScheduleActive: (_schedule: import("../types.js").TriggerSchedule, context: import("../types.js").TriggerContext) => Promise<{
|
|
62
65
|
eventKeys: string[];
|
|
63
66
|
}>;
|
|
64
67
|
};
|
|
65
68
|
/** The slash command `config.name`, run in the server, or in a direct message by the human who added the bot. */
|
|
66
|
-
command:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
command: Trigger;
|
|
70
|
+
/** A click or pick on the component `config.customId`, in the server or the human's direct messages. */
|
|
71
|
+
component: Trigger;
|
|
72
|
+
/** A submission of the modal `config.customId`, in the server or the human's direct messages. */
|
|
73
|
+
modal: Trigger;
|
|
74
|
+
auto_moderation_action_execution: Trigger;
|
|
75
|
+
auto_moderation_rule_create: Trigger;
|
|
76
|
+
auto_moderation_rule_delete: Trigger;
|
|
77
|
+
auto_moderation_rule_update: Trigger;
|
|
78
|
+
channel_create: Trigger;
|
|
79
|
+
channel_delete: Trigger;
|
|
80
|
+
channel_pins_update: Trigger;
|
|
81
|
+
channel_update: Trigger;
|
|
82
|
+
guild_audit_log_entry_create: Trigger;
|
|
83
|
+
guild_ban_add: Trigger;
|
|
84
|
+
guild_ban_remove: Trigger;
|
|
85
|
+
guild_emojis_update: Trigger;
|
|
86
|
+
guild_member_add: Trigger;
|
|
87
|
+
guild_member_remove: Trigger;
|
|
88
|
+
guild_member_update: Trigger;
|
|
89
|
+
guild_role_create: Trigger;
|
|
90
|
+
guild_role_delete: Trigger;
|
|
91
|
+
guild_role_update: Trigger;
|
|
92
|
+
guild_scheduled_event_create: Trigger;
|
|
93
|
+
guild_scheduled_event_delete: Trigger;
|
|
94
|
+
guild_scheduled_event_update: Trigger;
|
|
95
|
+
guild_scheduled_event_user_add: Trigger;
|
|
96
|
+
guild_scheduled_event_user_remove: Trigger;
|
|
97
|
+
guild_stickers_update: Trigger;
|
|
98
|
+
guild_update: Trigger;
|
|
99
|
+
integration_create: Trigger;
|
|
100
|
+
integration_delete: Trigger;
|
|
101
|
+
integration_update: Trigger;
|
|
102
|
+
invite_create: Trigger;
|
|
103
|
+
invite_delete: Trigger;
|
|
104
|
+
message_delete: Trigger;
|
|
105
|
+
message_delete_bulk: Trigger;
|
|
106
|
+
message_poll_vote_add: Trigger;
|
|
107
|
+
message_poll_vote_remove: Trigger;
|
|
108
|
+
message_reaction_add: Trigger;
|
|
109
|
+
message_reaction_remove: Trigger;
|
|
110
|
+
message_reaction_remove_all: Trigger;
|
|
111
|
+
message_reaction_remove_emoji: Trigger;
|
|
112
|
+
message_update: Trigger;
|
|
113
|
+
stage_instance_create: Trigger;
|
|
114
|
+
stage_instance_delete: Trigger;
|
|
115
|
+
stage_instance_update: Trigger;
|
|
116
|
+
thread_create: Trigger;
|
|
117
|
+
thread_delete: Trigger;
|
|
118
|
+
thread_update: Trigger;
|
|
119
|
+
voice_state_update: Trigger;
|
|
120
|
+
webhooks_update: Trigger;
|
|
73
121
|
};
|
|
74
122
|
//# sourceMappingURL=discord.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discord.d.ts","sourceRoot":"","sources":["../../src/platforms/discord.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAW,YAAY,EAAiB,MAAM,iBAAiB,CAAC;AAM5E,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"discord.d.ts","sourceRoot":"","sources":["../../src/platforms/discord.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAW,YAAY,EAAiB,MAAM,iBAAiB,CAAC;AAM5E,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAavD,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,cAAc,E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