@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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AgentJamError } from "../errors.js";
|
|
2
2
|
import { constructStandardProfile, defaultToken, postForm, } from "../providers.js";
|
|
3
|
-
import { constructDiscordKey, directScope,
|
|
3
|
+
import { channelProperty, constructDiscordKey, constructEventTriggers, directScope, readConfigText, readDiscordAccount, } from "./discordEvents.js";
|
|
4
|
+
import { discordApi } from "./discordGateway.js";
|
|
5
|
+
import { constructInteractionTrigger } from "./discordInteractions.js";
|
|
4
6
|
import { constructOAuthPreset } from "./presets.js";
|
|
5
7
|
export { connectDiscordGateway, discordIntents, } from "./discordGateway.js";
|
|
6
8
|
const discordEndpoints = {
|
|
@@ -93,45 +95,24 @@ export const discordConnection = ({ permissions, scopes = [], ...options } = {})
|
|
|
93
95
|
}, { ...options, scopes });
|
|
94
96
|
const channelConfig = {
|
|
95
97
|
type: "object",
|
|
96
|
-
properties: {
|
|
97
|
-
channel: {
|
|
98
|
-
type: "string",
|
|
99
|
-
description: "The id of the channel to watch, such as 1234567890. Leave it out to watch every channel the bot can read.",
|
|
100
|
-
},
|
|
101
|
-
},
|
|
98
|
+
properties: { channel: channelProperty },
|
|
102
99
|
};
|
|
103
|
-
const commandConfig = {
|
|
104
|
-
type: "object",
|
|
105
|
-
properties: {
|
|
106
|
-
name: {
|
|
107
|
-
type: "string",
|
|
108
|
-
description: "The name of the slash command to run on, without its slash, such as standup.",
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
required: ["name"],
|
|
112
|
-
};
|
|
113
|
-
const readDiscordAccount = async ({ account }, connection) => {
|
|
114
|
-
const connected = await account(connection);
|
|
115
|
-
if (!connected) {
|
|
116
|
-
throw new AgentJamError("The schedule has no Discord server connected, so it can't watch Discord");
|
|
117
|
-
}
|
|
118
|
-
return connected;
|
|
119
|
-
};
|
|
120
|
-
const readConfigText = ({ config }, key) => typeof config[key] === "string" ? config[key] : undefined;
|
|
121
100
|
const watchChannel = (kind, connection) => async (schedule, context) => {
|
|
122
101
|
const { id } = await readDiscordAccount(context, connection);
|
|
123
102
|
const channel = readConfigText(schedule, "channel");
|
|
124
103
|
return { eventKeys: [constructDiscordKey(id, kind, channel)] };
|
|
125
104
|
};
|
|
126
105
|
/**
|
|
127
|
-
* Triggers that run a schedule on
|
|
128
|
-
*
|
|
129
|
-
*
|
|
106
|
+
* Triggers that run a schedule on what `connectDiscordGateway()` dispatches, for a skill whose connections include
|
|
107
|
+
* `connection`: messages, slash commands, components and modals, and one per Gateway event type such as
|
|
108
|
+
* `message_reaction_add`. Every schedule watching one gets its own run, with a `DiscordMessageData`,
|
|
109
|
+
* `DiscordCommandData`, `DiscordComponentData` or `DiscordEventData` as `task.event.data`.
|
|
130
110
|
*
|
|
131
111
|
* @param connection The skill's Discord connection.
|
|
132
|
-
* @returns The
|
|
112
|
+
* @returns The triggers, for a skill's `triggers`.
|
|
133
113
|
*/
|
|
134
114
|
export const discordTriggers = (connection) => ({
|
|
115
|
+
...constructEventTriggers(connection),
|
|
135
116
|
/** A message in a channel the bot can read in the server, or only in `config.channel` when the requester sets it. */
|
|
136
117
|
message: {
|
|
137
118
|
description: "A message is posted in a channel the bot can read, or in one channel when `channel` is set",
|
|
@@ -161,24 +142,10 @@ export const discordTriggers = (connection) => ({
|
|
|
161
142
|
},
|
|
162
143
|
},
|
|
163
144
|
/** The slash command `config.name`, run in the server, or in a direct message by the human who added the bot. */
|
|
164
|
-
command:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const name = readConfigText(schedule, "name");
|
|
170
|
-
if (name === undefined) {
|
|
171
|
-
throw new AgentJamError("The schedule names no slash command, so set `name` in its config");
|
|
172
|
-
}
|
|
173
|
-
const direct = subject === undefined
|
|
174
|
-
? []
|
|
175
|
-
: [
|
|
176
|
-
constructDiscordKey(directScope, "command", `${name}:${subject}`),
|
|
177
|
-
];
|
|
178
|
-
return {
|
|
179
|
-
eventKeys: [constructDiscordKey(id, "command", name), ...direct],
|
|
180
|
-
};
|
|
181
|
-
},
|
|
182
|
-
},
|
|
145
|
+
command: constructInteractionTrigger("command", "Someone runs the slash command `name` in the server, or the human who added the bot runs it in a direct message", connection),
|
|
146
|
+
/** A click or pick on the component `config.customId`, in the server or the human's direct messages. */
|
|
147
|
+
component: constructInteractionTrigger("component", "Someone clicks the button or picks from the select menu `customId` in the server, or the human who added the bot does in a direct message", connection),
|
|
148
|
+
/** A submission of the modal `config.customId`, in the server or the human's direct messages. */
|
|
149
|
+
modal: constructInteractionTrigger("modal", "Someone submits the modal `customId` in the server, or the human who added the bot does in a direct message", connection),
|
|
183
150
|
});
|
|
184
151
|
//# sourceMappingURL=discord.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discord.js","sourceRoot":"","sources":["../../src/platforms/discord.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,QAAQ,GACT,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"discord.js","sourceRoot":"","sources":["../../src/platforms/discord.ts"],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AC;YACJ,CAAC;YAED,OAAO;gBACL,SAAS,EAAE;oBACT,mBAAmB,CAAC,WAAW,EAAE,eAAe,EAAE,OAAO,CAAC;iBAC3D;aACF,CAAC;QACJ,CAAC;KACF;IACD,iHAAiH;IACjH,OAAO,EAAE,2BAA2B,CAClC,SAAS,EACT,iHAAiH,EACjH,UAAU,CACX;IACD,wGAAwG;IACxG,SAAS,EAAE,2BAA2B,CACpC,WAAW,EACX,2IAA2I,EAC3I,UAAU,CACX;IACD,iGAAiG;IACjG,KAAK,EAAE,2BAA2B,CAChC,OAAO,EACP,6GAA6G,EAC7G,UAAU,CACX;CACF,CAAmC,CAAC"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type { JsonObject } from "../types.js";
|
|
2
|
+
type FieldReader = (event: JsonObject) => string | undefined;
|
|
3
|
+
declare const discordEventTypes: {
|
|
4
|
+
message_update: {
|
|
5
|
+
description: string;
|
|
6
|
+
channel: FieldReader;
|
|
7
|
+
user: FieldReader;
|
|
8
|
+
};
|
|
9
|
+
message_delete: {
|
|
10
|
+
description: string;
|
|
11
|
+
channel: FieldReader;
|
|
12
|
+
};
|
|
13
|
+
message_delete_bulk: {
|
|
14
|
+
description: string;
|
|
15
|
+
channel: FieldReader;
|
|
16
|
+
};
|
|
17
|
+
message_reaction_add: {
|
|
18
|
+
description: string;
|
|
19
|
+
channel: FieldReader;
|
|
20
|
+
user: FieldReader;
|
|
21
|
+
};
|
|
22
|
+
message_reaction_remove: {
|
|
23
|
+
description: string;
|
|
24
|
+
channel: FieldReader;
|
|
25
|
+
user: FieldReader;
|
|
26
|
+
};
|
|
27
|
+
message_reaction_remove_all: {
|
|
28
|
+
description: string;
|
|
29
|
+
channel: FieldReader;
|
|
30
|
+
};
|
|
31
|
+
message_reaction_remove_emoji: {
|
|
32
|
+
description: string;
|
|
33
|
+
channel: FieldReader;
|
|
34
|
+
};
|
|
35
|
+
message_poll_vote_add: {
|
|
36
|
+
description: string;
|
|
37
|
+
channel: FieldReader;
|
|
38
|
+
user: FieldReader;
|
|
39
|
+
};
|
|
40
|
+
message_poll_vote_remove: {
|
|
41
|
+
description: string;
|
|
42
|
+
channel: FieldReader;
|
|
43
|
+
user: FieldReader;
|
|
44
|
+
};
|
|
45
|
+
channel_create: {
|
|
46
|
+
description: string;
|
|
47
|
+
channel: FieldReader;
|
|
48
|
+
};
|
|
49
|
+
channel_update: {
|
|
50
|
+
description: string;
|
|
51
|
+
channel: FieldReader;
|
|
52
|
+
};
|
|
53
|
+
channel_delete: {
|
|
54
|
+
description: string;
|
|
55
|
+
channel: FieldReader;
|
|
56
|
+
};
|
|
57
|
+
channel_pins_update: {
|
|
58
|
+
description: string;
|
|
59
|
+
channel: FieldReader;
|
|
60
|
+
};
|
|
61
|
+
thread_create: {
|
|
62
|
+
description: string;
|
|
63
|
+
channel: FieldReader;
|
|
64
|
+
user: FieldReader;
|
|
65
|
+
};
|
|
66
|
+
thread_update: {
|
|
67
|
+
description: string;
|
|
68
|
+
channel: FieldReader;
|
|
69
|
+
};
|
|
70
|
+
thread_delete: {
|
|
71
|
+
description: string;
|
|
72
|
+
channel: FieldReader;
|
|
73
|
+
};
|
|
74
|
+
guild_update: {
|
|
75
|
+
description: string;
|
|
76
|
+
guild: FieldReader;
|
|
77
|
+
};
|
|
78
|
+
guild_member_add: {
|
|
79
|
+
description: string;
|
|
80
|
+
user: FieldReader;
|
|
81
|
+
};
|
|
82
|
+
guild_member_update: {
|
|
83
|
+
description: string;
|
|
84
|
+
user: FieldReader;
|
|
85
|
+
};
|
|
86
|
+
guild_member_remove: {
|
|
87
|
+
description: string;
|
|
88
|
+
user: FieldReader;
|
|
89
|
+
};
|
|
90
|
+
guild_ban_add: {
|
|
91
|
+
description: string;
|
|
92
|
+
user: FieldReader;
|
|
93
|
+
};
|
|
94
|
+
guild_ban_remove: {
|
|
95
|
+
description: string;
|
|
96
|
+
user: FieldReader;
|
|
97
|
+
};
|
|
98
|
+
guild_audit_log_entry_create: {
|
|
99
|
+
description: string;
|
|
100
|
+
user: FieldReader;
|
|
101
|
+
};
|
|
102
|
+
guild_role_create: {
|
|
103
|
+
description: string;
|
|
104
|
+
};
|
|
105
|
+
guild_role_update: {
|
|
106
|
+
description: string;
|
|
107
|
+
};
|
|
108
|
+
guild_role_delete: {
|
|
109
|
+
description: string;
|
|
110
|
+
};
|
|
111
|
+
guild_emojis_update: {
|
|
112
|
+
description: string;
|
|
113
|
+
};
|
|
114
|
+
guild_stickers_update: {
|
|
115
|
+
description: string;
|
|
116
|
+
};
|
|
117
|
+
guild_scheduled_event_create: {
|
|
118
|
+
description: string;
|
|
119
|
+
channel: FieldReader;
|
|
120
|
+
user: FieldReader;
|
|
121
|
+
};
|
|
122
|
+
guild_scheduled_event_update: {
|
|
123
|
+
description: string;
|
|
124
|
+
channel: FieldReader;
|
|
125
|
+
user: FieldReader;
|
|
126
|
+
};
|
|
127
|
+
guild_scheduled_event_delete: {
|
|
128
|
+
description: string;
|
|
129
|
+
channel: FieldReader;
|
|
130
|
+
user: FieldReader;
|
|
131
|
+
};
|
|
132
|
+
guild_scheduled_event_user_add: {
|
|
133
|
+
description: string;
|
|
134
|
+
user: FieldReader;
|
|
135
|
+
};
|
|
136
|
+
guild_scheduled_event_user_remove: {
|
|
137
|
+
description: string;
|
|
138
|
+
user: FieldReader;
|
|
139
|
+
};
|
|
140
|
+
invite_create: {
|
|
141
|
+
description: string;
|
|
142
|
+
channel: FieldReader;
|
|
143
|
+
user: FieldReader;
|
|
144
|
+
};
|
|
145
|
+
invite_delete: {
|
|
146
|
+
description: string;
|
|
147
|
+
channel: FieldReader;
|
|
148
|
+
};
|
|
149
|
+
voice_state_update: {
|
|
150
|
+
description: string;
|
|
151
|
+
channel: FieldReader;
|
|
152
|
+
user: FieldReader;
|
|
153
|
+
};
|
|
154
|
+
stage_instance_create: {
|
|
155
|
+
description: string;
|
|
156
|
+
channel: FieldReader;
|
|
157
|
+
};
|
|
158
|
+
stage_instance_update: {
|
|
159
|
+
description: string;
|
|
160
|
+
channel: FieldReader;
|
|
161
|
+
};
|
|
162
|
+
stage_instance_delete: {
|
|
163
|
+
description: string;
|
|
164
|
+
channel: FieldReader;
|
|
165
|
+
};
|
|
166
|
+
webhooks_update: {
|
|
167
|
+
description: string;
|
|
168
|
+
channel: FieldReader;
|
|
169
|
+
};
|
|
170
|
+
integration_create: {
|
|
171
|
+
description: string;
|
|
172
|
+
};
|
|
173
|
+
integration_update: {
|
|
174
|
+
description: string;
|
|
175
|
+
};
|
|
176
|
+
integration_delete: {
|
|
177
|
+
description: string;
|
|
178
|
+
};
|
|
179
|
+
auto_moderation_rule_create: {
|
|
180
|
+
description: string;
|
|
181
|
+
user: FieldReader;
|
|
182
|
+
};
|
|
183
|
+
auto_moderation_rule_update: {
|
|
184
|
+
description: string;
|
|
185
|
+
user: FieldReader;
|
|
186
|
+
};
|
|
187
|
+
auto_moderation_rule_delete: {
|
|
188
|
+
description: string;
|
|
189
|
+
user: FieldReader;
|
|
190
|
+
};
|
|
191
|
+
auto_moderation_action_execution: {
|
|
192
|
+
description: string;
|
|
193
|
+
channel: FieldReader;
|
|
194
|
+
user: FieldReader;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
/** A Gateway event `discordTriggers` has a trigger for, as its lowercased name, such as `message_reaction_add`. */
|
|
198
|
+
export type DiscordEventName = keyof typeof discordEventTypes;
|
|
199
|
+
/** What a schedule's task gets as `task.event.data` when a Discord event type's trigger runs it. */
|
|
200
|
+
export type DiscordEventData = {
|
|
201
|
+
type: DiscordEventName;
|
|
202
|
+
guildId: string;
|
|
203
|
+
/** The channel the event happened in, or a thread's parent channel. */
|
|
204
|
+
channelId: string | null;
|
|
205
|
+
/** The user who caused the event, or who it's about, such as the member who joined. */
|
|
206
|
+
userId: string | null;
|
|
207
|
+
/** The event's fields as Discord sent them. */
|
|
208
|
+
event: JsonObject;
|
|
209
|
+
/** The fields of `event` left out, largest first, to fit an event's size limit. */
|
|
210
|
+
omitted?: string[];
|
|
211
|
+
};
|
|
212
|
+
export {};
|
|
213
|
+
//# sourceMappingURL=discordEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discordEvents.d.ts","sourceRoot":"","sources":["../../src/platforms/discordEvents.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,UAAU,EAKX,MAAM,aAAa,CAAC;AAErB,KAAK,WAAW,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,MAAM,GAAG,SAAS,CAAC;AAwC7D,QAAA,MAAM,iBAAiB;;QAEnB,WAAW;QACX,OAAO;QACP,IAAI;;;QAGJ,WAAW;QACX,OAAO;;;QAGP,WAAW;QACX,OAAO;;;QAGP,WAAW;QACX,OAAO;QACP,IAAI;;;QAGJ,WAAW;QACX,OAAO;QACP,IAAI;;;QAGJ,WAAW;QACX,OAAO;;;QAGP,WAAW;QACX,OAAO;;;QAGP,WAAW;QACX,OAAO;QACP,IAAI;;;QAGJ,WAAW;QACX,OAAO;QACP,IAAI;;;QAEY,WAAW;QAA0B,OAAO;;;QAC5C,WAAW;QAA0B,OAAO;;;QAC5C,WAAW;QAA0B,OAAO;;;QAE5D,WAAW;QACX,OAAO;;;QAGP,WAAW;QACX,OAAO;QACP,IAAI;;;QAGJ,WAAW;QACX,OAAO;;;QAGP,WAAW;QACX,OAAO;;;QAEO,WAAW;QAA2B,KAAK;;;QAEzD,WAAW;QAEX,IAAI;;;QAGJ,WAAW;QAEX,IAAI;;;QAGJ,WAAW;QAEX,IAAI;;;QAGJ,WAAW;QACX,IAAI;;;QAGJ,WAAW;QACX,IAAI;;;QAGJ,WAAW;QAEX,IAAI;;;QAEe,WAAW;;;QACX,WAAW;;;QACX,WAAW;;;QACT,WAAW;;;QACT,WAAW;;;QAElC,WAAW;QACX,OAAO;QACP,IAAI;;;QAGJ,WAAW;QACX,OAAO;QACP,IAAI;;;QAGJ,WAAW;QACX,OAAO;QACP,IAAI;;;QAGJ,WAAW;QACX,IAAI;;;QAGJ,WAAW;QACX,IAAI;;;QAGJ,WAAW;QACX,OAAO;QACP,IAAI;;;QAGJ,WAAW;QACX,OAAO;;;QAGP,WAAW;QACX,OAAO;QACP,IAAI;;;QAGJ,WAAW;QACX,OAAO;;;QAGP,WAAW;QACX,OAAO;;;QAGP,WAAW;QACX,OAAO;;;QAGP,WAAW;QACX,OAAO;;;QAEa,WAAW;;;QACX,WAAW;;;QAE/B,WAAW;;;QAGX,WAAW;QACX,IAAI;;;QAGJ,WAAW;QACX,IAAI;;;QAGJ,WAAW;QACX,IAAI;;;QAGJ,WAAW;QACX,OAAO;QACP,IAAI;;CAEoC,CAAC;AAE7C,mHAAmH;AACnH,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,iBAAiB,CAAC;AAE9D,oGAAoG;AACpG,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,uFAAuF;IACvF,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+CAA+C;IAC/C,KAAK,EAAE,UAAU,CAAC;IAClB,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { AgentJamError } from "../errors.js";
|
|
2
|
+
import { fitLargestFields, maxEventKeyLength } from "../events.js";
|
|
3
|
+
import { truncateSummary } from "../polling.js";
|
|
4
|
+
/** @internal Reads `value` as an object, or an empty one if it isn't. */
|
|
5
|
+
export const readObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
6
|
+
? value
|
|
7
|
+
: {};
|
|
8
|
+
/** @internal Reads the text at `path` in a Discord event. */
|
|
9
|
+
export const readField = (...path) => (event) => {
|
|
10
|
+
const value = path.reduce((field, key) => readObject(field)[key], event);
|
|
11
|
+
return typeof value === "string" ? value : undefined;
|
|
12
|
+
};
|
|
13
|
+
const readChannel = readField("channel_id");
|
|
14
|
+
const readUser = readField("user_id");
|
|
15
|
+
const readMemberUser = readField("user", "id");
|
|
16
|
+
const readCreator = readField("creator_id");
|
|
17
|
+
const readId = readField("id");
|
|
18
|
+
const discordEventTypes = {
|
|
19
|
+
message_update: {
|
|
20
|
+
description: "A message is edited in a channel the bot can read",
|
|
21
|
+
channel: readChannel,
|
|
22
|
+
user: readField("author", "id"),
|
|
23
|
+
},
|
|
24
|
+
message_delete: {
|
|
25
|
+
description: "A message is deleted in a channel the bot can read",
|
|
26
|
+
channel: readChannel,
|
|
27
|
+
},
|
|
28
|
+
message_delete_bulk: {
|
|
29
|
+
description: "Messages are deleted in bulk in a channel the bot can read",
|
|
30
|
+
channel: readChannel,
|
|
31
|
+
},
|
|
32
|
+
message_reaction_add: {
|
|
33
|
+
description: "Someone adds a reaction to a message",
|
|
34
|
+
channel: readChannel,
|
|
35
|
+
user: readUser,
|
|
36
|
+
},
|
|
37
|
+
message_reaction_remove: {
|
|
38
|
+
description: "Someone removes a reaction from a message",
|
|
39
|
+
channel: readChannel,
|
|
40
|
+
user: readUser,
|
|
41
|
+
},
|
|
42
|
+
message_reaction_remove_all: {
|
|
43
|
+
description: "Every reaction is removed from a message",
|
|
44
|
+
channel: readChannel,
|
|
45
|
+
},
|
|
46
|
+
message_reaction_remove_emoji: {
|
|
47
|
+
description: "Every reaction of one emoji is removed from a message",
|
|
48
|
+
channel: readChannel,
|
|
49
|
+
},
|
|
50
|
+
message_poll_vote_add: {
|
|
51
|
+
description: "Someone votes in a poll",
|
|
52
|
+
channel: readChannel,
|
|
53
|
+
user: readUser,
|
|
54
|
+
},
|
|
55
|
+
message_poll_vote_remove: {
|
|
56
|
+
description: "Someone takes back a vote in a poll",
|
|
57
|
+
channel: readChannel,
|
|
58
|
+
user: readUser,
|
|
59
|
+
},
|
|
60
|
+
channel_create: { description: "A channel is created", channel: readId },
|
|
61
|
+
channel_update: { description: "A channel is updated", channel: readId },
|
|
62
|
+
channel_delete: { description: "A channel is deleted", channel: readId },
|
|
63
|
+
channel_pins_update: {
|
|
64
|
+
description: "A message is pinned or unpinned",
|
|
65
|
+
channel: readChannel,
|
|
66
|
+
},
|
|
67
|
+
thread_create: {
|
|
68
|
+
description: "A thread is created, or the bot is added to one",
|
|
69
|
+
channel: readField("parent_id"),
|
|
70
|
+
user: readField("owner_id"),
|
|
71
|
+
},
|
|
72
|
+
thread_update: {
|
|
73
|
+
description: "A thread is updated",
|
|
74
|
+
channel: readField("parent_id"),
|
|
75
|
+
},
|
|
76
|
+
thread_delete: {
|
|
77
|
+
description: "A thread is deleted",
|
|
78
|
+
channel: readField("parent_id"),
|
|
79
|
+
},
|
|
80
|
+
guild_update: { description: "The server is updated", guild: readId },
|
|
81
|
+
guild_member_add: {
|
|
82
|
+
description: "Someone joins the server. Needs the privileged `guildMembers` intent",
|
|
83
|
+
user: readMemberUser,
|
|
84
|
+
},
|
|
85
|
+
guild_member_update: {
|
|
86
|
+
description: "A member of the server is updated, such as their roles. Needs the privileged `guildMembers` intent",
|
|
87
|
+
user: readMemberUser,
|
|
88
|
+
},
|
|
89
|
+
guild_member_remove: {
|
|
90
|
+
description: "Someone leaves or is removed from the server. Needs the privileged `guildMembers` intent",
|
|
91
|
+
user: readMemberUser,
|
|
92
|
+
},
|
|
93
|
+
guild_ban_add: {
|
|
94
|
+
description: "Someone is banned from the server",
|
|
95
|
+
user: readMemberUser,
|
|
96
|
+
},
|
|
97
|
+
guild_ban_remove: {
|
|
98
|
+
description: "Someone is unbanned from the server",
|
|
99
|
+
user: readMemberUser,
|
|
100
|
+
},
|
|
101
|
+
guild_audit_log_entry_create: {
|
|
102
|
+
description: "An entry is added to the server's audit log. Needs the bot to have the View Audit Log permission",
|
|
103
|
+
user: readUser,
|
|
104
|
+
},
|
|
105
|
+
guild_role_create: { description: "A role is created" },
|
|
106
|
+
guild_role_update: { description: "A role is updated" },
|
|
107
|
+
guild_role_delete: { description: "A role is deleted" },
|
|
108
|
+
guild_emojis_update: { description: "The server's emojis change" },
|
|
109
|
+
guild_stickers_update: { description: "The server's stickers change" },
|
|
110
|
+
guild_scheduled_event_create: {
|
|
111
|
+
description: "A scheduled event is created",
|
|
112
|
+
channel: readChannel,
|
|
113
|
+
user: readCreator,
|
|
114
|
+
},
|
|
115
|
+
guild_scheduled_event_update: {
|
|
116
|
+
description: "A scheduled event is updated",
|
|
117
|
+
channel: readChannel,
|
|
118
|
+
user: readCreator,
|
|
119
|
+
},
|
|
120
|
+
guild_scheduled_event_delete: {
|
|
121
|
+
description: "A scheduled event is deleted",
|
|
122
|
+
channel: readChannel,
|
|
123
|
+
user: readCreator,
|
|
124
|
+
},
|
|
125
|
+
guild_scheduled_event_user_add: {
|
|
126
|
+
description: "Someone signs up for a scheduled event",
|
|
127
|
+
user: readUser,
|
|
128
|
+
},
|
|
129
|
+
guild_scheduled_event_user_remove: {
|
|
130
|
+
description: "Someone backs out of a scheduled event",
|
|
131
|
+
user: readUser,
|
|
132
|
+
},
|
|
133
|
+
invite_create: {
|
|
134
|
+
description: "An invite to the server is created",
|
|
135
|
+
channel: readChannel,
|
|
136
|
+
user: readField("inviter", "id"),
|
|
137
|
+
},
|
|
138
|
+
invite_delete: {
|
|
139
|
+
description: "An invite to the server is deleted",
|
|
140
|
+
channel: readChannel,
|
|
141
|
+
},
|
|
142
|
+
voice_state_update: {
|
|
143
|
+
description: "Someone joins, leaves, or moves between voice channels",
|
|
144
|
+
channel: readChannel,
|
|
145
|
+
user: readUser,
|
|
146
|
+
},
|
|
147
|
+
stage_instance_create: {
|
|
148
|
+
description: "A stage starts",
|
|
149
|
+
channel: readChannel,
|
|
150
|
+
},
|
|
151
|
+
stage_instance_update: {
|
|
152
|
+
description: "A stage is updated",
|
|
153
|
+
channel: readChannel,
|
|
154
|
+
},
|
|
155
|
+
stage_instance_delete: {
|
|
156
|
+
description: "A stage ends",
|
|
157
|
+
channel: readChannel,
|
|
158
|
+
},
|
|
159
|
+
webhooks_update: {
|
|
160
|
+
description: "A channel's webhooks change",
|
|
161
|
+
channel: readChannel,
|
|
162
|
+
},
|
|
163
|
+
integration_create: { description: "An integration is added to the server" },
|
|
164
|
+
integration_update: { description: "An integration is updated" },
|
|
165
|
+
integration_delete: {
|
|
166
|
+
description: "An integration is removed from the server",
|
|
167
|
+
},
|
|
168
|
+
auto_moderation_rule_create: {
|
|
169
|
+
description: "An AutoMod rule is created",
|
|
170
|
+
user: readCreator,
|
|
171
|
+
},
|
|
172
|
+
auto_moderation_rule_update: {
|
|
173
|
+
description: "An AutoMod rule is updated",
|
|
174
|
+
user: readCreator,
|
|
175
|
+
},
|
|
176
|
+
auto_moderation_rule_delete: {
|
|
177
|
+
description: "An AutoMod rule is deleted",
|
|
178
|
+
user: readCreator,
|
|
179
|
+
},
|
|
180
|
+
auto_moderation_action_execution: {
|
|
181
|
+
description: "AutoMod acts on a message, such as by blocking it",
|
|
182
|
+
channel: readChannel,
|
|
183
|
+
user: readUser,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
/** @internal Discord's name for the scope of direct messages, which belong to no server. */
|
|
187
|
+
export const directScope = "@me";
|
|
188
|
+
/** @internal Files a Discord event under the server or `directScope` it happened in. */
|
|
189
|
+
export const constructDiscordKey = (scope, kind, detail) => detail === undefined
|
|
190
|
+
? `discord:${scope}:${kind}`
|
|
191
|
+
: `discord:${scope}:${kind}:${detail}`;
|
|
192
|
+
/** @internal The config property that narrows a trigger to one channel. */
|
|
193
|
+
export const channelProperty = {
|
|
194
|
+
type: "string",
|
|
195
|
+
description: "The id of the channel to watch, such as 1234567890. Leave it out to watch every channel the bot can read.",
|
|
196
|
+
};
|
|
197
|
+
/** @internal Reads the server a schedule's Discord connection reaches, refusing a schedule without one. */
|
|
198
|
+
export const readDiscordAccount = async ({ account }, connection) => {
|
|
199
|
+
const connected = await account(connection);
|
|
200
|
+
if (!connected) {
|
|
201
|
+
throw new AgentJamError("The schedule has no Discord server connected, so it can't watch Discord");
|
|
202
|
+
}
|
|
203
|
+
return connected;
|
|
204
|
+
};
|
|
205
|
+
/** @internal Reads the text a schedule's config holds under `key`. */
|
|
206
|
+
export const readConfigText = ({ config }, key) => typeof config[key] === "string" ? config[key] : undefined;
|
|
207
|
+
const eventNames = Object.keys(discordEventTypes);
|
|
208
|
+
const isDiscordEventName = (name) => Object.hasOwn(discordEventTypes, name);
|
|
209
|
+
const constructEventTrigger = (name, connection) => {
|
|
210
|
+
const spec = discordEventTypes[name];
|
|
211
|
+
return {
|
|
212
|
+
description: spec.description,
|
|
213
|
+
config: {
|
|
214
|
+
type: "object",
|
|
215
|
+
properties: spec.channel ? { channel: channelProperty } : {},
|
|
216
|
+
},
|
|
217
|
+
onScheduleActive: async (schedule, context) => {
|
|
218
|
+
const { id } = await readDiscordAccount(context, connection);
|
|
219
|
+
const channel = spec.channel && readConfigText(schedule, "channel");
|
|
220
|
+
return { eventKeys: [constructDiscordKey(id, name, channel)] };
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
/** @internal One trigger per Discord Gateway event type, each running a schedule on that type in its server. */
|
|
225
|
+
export const constructEventTriggers = (connection) => Object.fromEntries(eventNames.map((name) => [name, constructEventTrigger(name, connection)]));
|
|
226
|
+
const summarizeEvent = ({ type, userId, channelId }) => truncateSummary([
|
|
227
|
+
`Discord ${type}`,
|
|
228
|
+
userId && ` by ${userId}`,
|
|
229
|
+
channelId && ` in ${channelId}`,
|
|
230
|
+
]
|
|
231
|
+
.filter(Boolean)
|
|
232
|
+
.join(""));
|
|
233
|
+
/** @internal Reads a Gateway dispatch of `type` under the keys its trigger subscribes schedules to. */
|
|
234
|
+
export const readGatewayEvent = (type, fields, { id, botUserId }) => {
|
|
235
|
+
const name = type.toLowerCase();
|
|
236
|
+
if (!isDiscordEventName(name))
|
|
237
|
+
return [];
|
|
238
|
+
const spec = discordEventTypes[name];
|
|
239
|
+
const event = readObject(fields);
|
|
240
|
+
const guild = (spec.guild ?? readField("guild_id"))(event);
|
|
241
|
+
const user = spec.user?.(event);
|
|
242
|
+
if (guild === undefined || user === botUserId)
|
|
243
|
+
return [];
|
|
244
|
+
const data = {
|
|
245
|
+
type: name,
|
|
246
|
+
guildId: guild,
|
|
247
|
+
channelId: spec.channel?.(event) ?? null,
|
|
248
|
+
userId: user ?? null,
|
|
249
|
+
event,
|
|
250
|
+
};
|
|
251
|
+
const eventKeys = [
|
|
252
|
+
constructDiscordKey(guild, name),
|
|
253
|
+
...(data.channelId === null
|
|
254
|
+
? []
|
|
255
|
+
: [constructDiscordKey(guild, name, data.channelId)]),
|
|
256
|
+
].filter((key) => key.length <= maxEventKeyLength);
|
|
257
|
+
return [
|
|
258
|
+
{
|
|
259
|
+
id,
|
|
260
|
+
eventKeys,
|
|
261
|
+
summary: summarizeEvent(data),
|
|
262
|
+
data: fitLargestFields(event, (kept, omitted) => ({
|
|
263
|
+
...data,
|
|
264
|
+
event: kept,
|
|
265
|
+
...(omitted.length > 0 && { omitted }),
|
|
266
|
+
})),
|
|
267
|
+
},
|
|
268
|
+
];
|
|
269
|
+
};
|
|
270
|
+
//# sourceMappingURL=discordEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discordEvents.js","sourceRoot":"","sources":["../../src/platforms/discordEvents.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAsBhD,yEAAyE;AACzE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAc,EAAc,EAAE,CACvD,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IAClE,CAAC,CAAE,KAAoB;IACvB,CAAC,CAAC,EAAE,CAAC;AAET,6DAA6D;AAC7D,MAA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