@wheatley-ai/cli 0.0.0-stage → 0.1.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/LICENSE +15 -0
- package/bin/wheatley.js +2 -0
- package/dist/approvals/gate.js +278 -0
- package/dist/approvals/module.js +21 -0
- package/dist/approvals/policy.js +30 -0
- package/dist/approvals/preview.js +17 -0
- package/dist/approvals/prompt.js +98 -0
- package/dist/approvals/rpc.js +16 -0
- package/dist/approvals/store.js +159 -0
- package/dist/cli/ask.js +94 -0
- package/dist/cli/chat.js +178 -0
- package/dist/cli/client.js +104 -0
- package/dist/cli/daemon.js +35 -0
- package/dist/cli/init.js +72 -0
- package/dist/cli/io.js +45 -0
- package/dist/cli/main.js +206 -0
- package/dist/cli/session.js +86 -0
- package/dist/cli/status.js +46 -0
- package/dist/contracts/approval-gate.js +1 -0
- package/dist/contracts/config-store.js +1 -0
- package/dist/contracts/delivery-outbox.js +1 -0
- package/dist/contracts/errors.js +28 -0
- package/dist/contracts/extension-catalog.js +1 -0
- package/dist/contracts/maintenance-runner.js +1 -0
- package/dist/contracts/memory-store.js +1 -0
- package/dist/contracts/module.js +7 -0
- package/dist/contracts/tool-names.js +43 -0
- package/dist/contracts/trigger-runtime.js +1 -0
- package/dist/contracts/webhook-ingress.js +2 -0
- package/dist/core/agent/agent-store.js +300 -0
- package/dist/core/agent/agent.js +1033 -0
- package/dist/core/agent/gated-models.js +89 -0
- package/dist/core/agent/pi-adapter.js +401 -0
- package/dist/core/agent/policy-gate.js +44 -0
- package/dist/core/builtin-catalog.js +20 -0
- package/dist/core/concurrency-gate.js +87 -0
- package/dist/core/config/atomic-file.js +72 -0
- package/dist/core/config/config-store.js +138 -0
- package/dist/core/config/pending-restart.js +53 -0
- package/dist/core/config/secret-references.js +69 -0
- package/dist/core/config/secret-store.js +147 -0
- package/dist/core/config/validate.js +55 -0
- package/dist/core/config/yaml-patch.js +57 -0
- package/dist/core/daemon-socket.js +96 -0
- package/dist/core/daemon.js +97 -0
- package/dist/core/deployment.js +379 -0
- package/dist/core/error-message.js +4 -0
- package/dist/core/events.js +25 -0
- package/dist/core/logger.js +81 -0
- package/dist/core/models.js +27 -0
- package/dist/core/module.js +42 -0
- package/dist/core/rpc/agent-handlers.js +82 -0
- package/dist/core/rpc/deployment-handlers.js +63 -0
- package/dist/core/rpc/router.js +96 -0
- package/dist/core/server/connection.js +170 -0
- package/dist/core/server/control-server.js +152 -0
- package/dist/core/server/static-files.js +79 -0
- package/dist/core/supervisor.js +215 -0
- package/dist/core/tool-routing.js +41 -0
- package/dist/dashboard/assets/index-C9Rul5vE.css +2 -0
- package/dist/dashboard/assets/index-DXzGGAxQ.js +11 -0
- package/dist/dashboard/assets/sheet-presentation-DMljN0LW.js +1 -0
- package/dist/dashboard/index.html +18 -0
- package/dist/db/database.js +16 -0
- package/dist/db/migrations.js +184 -0
- package/dist/frontends/discord/approvals.js +199 -0
- package/dist/frontends/discord/attachments.js +115 -0
- package/dist/frontends/discord/binding.js +489 -0
- package/dist/frontends/discord/config.js +107 -0
- package/dist/frontends/discord/discord-runtime.js +52 -0
- package/dist/frontends/discord/errors.js +61 -0
- package/dist/frontends/discord/live-runs.js +189 -0
- package/dist/frontends/discord/module.js +39 -0
- package/dist/frontends/discord/recent-ids.js +20 -0
- package/dist/frontends/slack/approval-blocks.js +98 -0
- package/dist/frontends/slack/attachments.js +102 -0
- package/dist/frontends/slack/background-tasks.js +20 -0
- package/dist/frontends/slack/binding.js +405 -0
- package/dist/frontends/slack/bounded.js +9 -0
- package/dist/frontends/slack/chat-id.js +17 -0
- package/dist/frontends/slack/config.js +80 -0
- package/dist/frontends/slack/delivery-errors.js +81 -0
- package/dist/frontends/slack/inbound.js +76 -0
- package/dist/frontends/slack/live-progress.js +190 -0
- package/dist/frontends/slack/manifest.js +66 -0
- package/dist/frontends/slack/outbound.js +160 -0
- package/dist/frontends/slack/schemas.js +99 -0
- package/dist/frontends/slack/signature.js +30 -0
- package/dist/frontends/slack/slack-client.js +60 -0
- package/dist/frontends/slack/slack-frontend.js +38 -0
- package/dist/frontends/slack/state-store.js +112 -0
- package/dist/frontends/telegram/approvals.js +134 -0
- package/dist/frontends/telegram/attachments.js +126 -0
- package/dist/frontends/telegram/binding.js +144 -0
- package/dist/frontends/telegram/chat-key.js +43 -0
- package/dist/frontends/telegram/client.js +88 -0
- package/dist/frontends/telegram/config.js +93 -0
- package/dist/frontends/telegram/delivery.js +215 -0
- package/dist/frontends/telegram/frontend.js +42 -0
- package/dist/frontends/telegram/grammy-client.js +122 -0
- package/dist/frontends/telegram/http-status.js +6 -0
- package/dist/frontends/telegram/inbound.js +149 -0
- package/dist/frontends/telegram/live.js +182 -0
- package/dist/frontends/telegram/markdown.js +103 -0
- package/dist/frontends/telegram/recent-set.js +18 -0
- package/dist/frontends/telegram/serial-queue.js +23 -0
- package/dist/index.js +7 -0
- package/dist/mcp/content.js +61 -0
- package/dist/mcp/mcp-module.js +35 -0
- package/dist/mcp/mcp-tool-provider.js +93 -0
- package/dist/mcp/server-connection.js +297 -0
- package/dist/memory/consolidation.js +260 -0
- package/dist/memory/format.js +5 -0
- package/dist/memory/migrations.js +76 -0
- package/dist/memory/module.js +69 -0
- package/dist/memory/names.js +20 -0
- package/dist/memory/rows.js +22 -0
- package/dist/memory/rpc.js +49 -0
- package/dist/memory/snapshots.js +12 -0
- package/dist/memory/store.js +281 -0
- package/dist/memory/tools.js +158 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/config.d.ts +262 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/config.js +120 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/domain.d.ts +512 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/domain.js +441 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/duration.d.ts +8 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/duration.js +28 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/events.d.ts +234 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/events.js +124 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/index.d.ts +11 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/index.js +11 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/json-rpc.d.ts +81 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/json-rpc.js +157 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/json.d.ts +14 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/json.js +23 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/limits.d.ts +17 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/limits.js +17 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/methods.d.ts +1107 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/methods.js +201 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/rpc-error.d.ts +45 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/rpc-error.js +44 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/validation.d.ts +20 -0
- package/dist/node_modules/@wheatley-ai/protocol/dist/validation.js +11 -0
- package/dist/node_modules/@wheatley-ai/protocol/package.json +14 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/chunk.d.ts +11 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/chunk.js +162 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/commands.d.ts +48 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/commands.js +39 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/delivery-error.d.ts +29 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/delivery-error.js +27 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/frontend.d.ts +236 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/frontend.js +2 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/index.d.ts +10 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/index.js +7 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/json.d.ts +9 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/json.js +2 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/logger.d.ts +18 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/logger.js +2 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/plugin.d.ts +48 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/plugin.js +5 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/schema.d.ts +69 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/schema.js +3 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/tool.d.ts +69 -0
- package/dist/node_modules/@wheatley-ai/sdk/dist/tool.js +3 -0
- package/dist/node_modules/@wheatley-ai/sdk/package.json +11 -0
- package/dist/ops/backup.js +185 -0
- package/dist/ops/cli.js +194 -0
- package/dist/ops/command-runner.js +34 -0
- package/dist/ops/dashboard-assets.js +37 -0
- package/dist/ops/migrate.js +63 -0
- package/dist/ops/module.js +47 -0
- package/dist/ops/paths.js +55 -0
- package/dist/ops/service.js +376 -0
- package/dist/ops/update.js +145 -0
- package/dist/plugins/contributions.js +89 -0
- package/dist/plugins/guards.js +111 -0
- package/dist/plugins/load.js +76 -0
- package/dist/plugins/module.js +31 -0
- package/dist/plugins/provider.js +349 -0
- package/dist/plugins/schema.js +69 -0
- package/dist/skills/disclosure.js +142 -0
- package/dist/skills/discovery.js +120 -0
- package/dist/skills/fs-errors.js +8 -0
- package/dist/skills/read-skill-tool.js +3 -0
- package/dist/skills/skill-file.js +90 -0
- package/dist/skills/skills.js +140 -0
- package/dist/tools/builtin-tools.js +61 -0
- package/dist/tools/input.js +45 -0
- package/dist/tools/paths.js +6 -0
- package/dist/tools/read-file.js +65 -0
- package/dist/tools/shell.js +156 -0
- package/dist/tools/write-file.js +58 -0
- package/dist/triggers/delivery-codec.js +99 -0
- package/dist/triggers/delivery-outbox.js +313 -0
- package/dist/triggers/due-timer.js +14 -0
- package/dist/triggers/errors.js +2 -0
- package/dist/triggers/migrations.js +91 -0
- package/dist/triggers/module.js +106 -0
- package/dist/triggers/rpc.js +35 -0
- package/dist/triggers/schedule.js +52 -0
- package/dist/triggers/sql-row.js +59 -0
- package/dist/triggers/trigger-runtime.js +445 -0
- package/dist/triggers/trigger-tools.js +210 -0
- package/dist/triggers/webhook-ingress.js +212 -0
- package/dist/wiring/agent-services.js +151 -0
- package/dist/wiring/catalog.js +81 -0
- package/dist/wiring/daemon.js +83 -0
- package/dist/wiring/frontend-host.js +268 -0
- package/package.json +50 -3
- package/README.md +0 -3
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import { DISPLAY_NAME_MAX_LENGTH } from "@wheatley-ai/protocol";
|
|
2
|
+
import { chunkMarkdown, DeliveryError, parseCommandText, } from "@wheatley-ai/sdk";
|
|
3
|
+
import { approvalButtons, parseApprovalCustomId, promptContent, promptKey, PromptStore, resolvedContent, } from "./approvals.js";
|
|
4
|
+
import { MAX_FILES_PER_MESSAGE, stageInboundFiles, toUploadPayloads, } from "./attachments.js";
|
|
5
|
+
import { loadDiscordRuntime, NO_MENTIONS } from "./discord-runtime.js";
|
|
6
|
+
import { discordErrorCode, errorText, toDeliveryError, UNKNOWN_MESSAGE_CODE, } from "./errors.js";
|
|
7
|
+
import { DISCORD_MESSAGE_MAX_LENGTH, LiveRuns } from "./live-runs.js";
|
|
8
|
+
import { RecentIds } from "./recent-ids.js";
|
|
9
|
+
/** How many outbound `messageId` values the binding remembers to drop duplicate deliveries. */
|
|
10
|
+
const RECENT_DELIVERY_LIMIT = 1000;
|
|
11
|
+
const OPTION_NAME_UNSAFE = /[^a-z0-9_-]+/gu;
|
|
12
|
+
const DEFAULT_OPTION_NAME = "args";
|
|
13
|
+
/** Derives the Slash Command option name from a command argument hint, for example `<model-id>` to `model-id`. */
|
|
14
|
+
const optionName = (argument) => {
|
|
15
|
+
const name = argument.toLowerCase().replaceAll(OPTION_NAME_UNSAFE, "");
|
|
16
|
+
return name === "" ? DEFAULT_OPTION_NAME : name;
|
|
17
|
+
};
|
|
18
|
+
const displayName = (name) => name.slice(0, DISPLAY_NAME_MAX_LENGTH);
|
|
19
|
+
/** Splits Agent text and files into Discord messages: text chunks first, files on the last chunk or after it. */
|
|
20
|
+
const outboundPayloads = (text, files) => {
|
|
21
|
+
const chunks = text.trim() === "" ? [] : chunkMarkdown(text, DISCORD_MESSAGE_MAX_LENGTH);
|
|
22
|
+
const fileGroups = [];
|
|
23
|
+
for (let start = 0; start < files.length; start += MAX_FILES_PER_MESSAGE) {
|
|
24
|
+
fileGroups.push(files.slice(start, start + MAX_FILES_PER_MESSAGE));
|
|
25
|
+
}
|
|
26
|
+
const lastChunk = chunks.at(-1);
|
|
27
|
+
const [firstGroup, ...otherGroups] = fileGroups;
|
|
28
|
+
const textPayloads = chunks
|
|
29
|
+
.slice(0, -1)
|
|
30
|
+
.map((content) => ({ allowedMentions: NO_MENTIONS, content }));
|
|
31
|
+
if (lastChunk !== undefined) {
|
|
32
|
+
textPayloads.push({
|
|
33
|
+
allowedMentions: NO_MENTIONS,
|
|
34
|
+
content: lastChunk,
|
|
35
|
+
files: firstGroup,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const separateGroups = lastChunk === undefined ? fileGroups : otherGroups;
|
|
39
|
+
return [
|
|
40
|
+
...textPayloads,
|
|
41
|
+
...separateGroups.map((group) => ({
|
|
42
|
+
allowedMentions: NO_MENTIONS,
|
|
43
|
+
files: group,
|
|
44
|
+
})),
|
|
45
|
+
];
|
|
46
|
+
};
|
|
47
|
+
/** The parent channel ID of a thread, or `null` for other channels. */
|
|
48
|
+
const parentOf = (channel) => channel.isThread() ? (channel.parentId ?? null) : null;
|
|
49
|
+
/** The channel of an interaction. Fetches it if discord.js has not cached it, for example a DM channel. */
|
|
50
|
+
const interactionChannel = async (interaction, client) => {
|
|
51
|
+
if (interaction.channel !== null) {
|
|
52
|
+
return interaction.channel;
|
|
53
|
+
}
|
|
54
|
+
return interaction.channelId === null
|
|
55
|
+
? null
|
|
56
|
+
: await client.fetchChannel(interaction.channelId);
|
|
57
|
+
};
|
|
58
|
+
/** Hands a native Slash Command to the Agent and answers the Sender with an ephemeral receipt. */
|
|
59
|
+
const handleSlashCommand = async (interaction, chatId, { discord, sink }) => {
|
|
60
|
+
const spec = sink.commands.find((command) => command.name === interaction.commandName);
|
|
61
|
+
if (spec === undefined) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
await interaction.deferReply({ flags: discord.MessageFlags.Ephemeral });
|
|
65
|
+
const raw = spec.argument === undefined
|
|
66
|
+
? null
|
|
67
|
+
: interaction.options.getString(optionName(spec.argument));
|
|
68
|
+
const args = raw?.trim() ?? "";
|
|
69
|
+
try {
|
|
70
|
+
await sink.command({
|
|
71
|
+
chatId,
|
|
72
|
+
name: spec.name,
|
|
73
|
+
senderDisplayName: displayName(interaction.user.displayName),
|
|
74
|
+
args: args === "" ? undefined : args,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
await interaction.editReply(`Wheatley could not run \`/${spec.name}\`.`);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
await interaction.editReply(`Accepted \`/${spec.name}\`.`);
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* One Discord bot connected to one Agent over the Discord Gateway (ADR 0007, ADR 0012).
|
|
85
|
+
*
|
|
86
|
+
* Chats: a DM channel, a guild channel, and a thread each are a separate Chat whose ID is the Discord channel ID, so
|
|
87
|
+
* a thread maps to `<thread_id>`. A Chat is allowed if its ID, or for a thread the parent channel ID, is in
|
|
88
|
+
* `allowedChatIds`. The binding drops other messages. It logs their Chat ID at `info` level if the message addresses
|
|
89
|
+
* the bot (a DM, a mention, or a reply to the bot), so that busy guild channels do not flood the log (ADR 0012).
|
|
90
|
+
*/
|
|
91
|
+
export class DiscordBinding {
|
|
92
|
+
#config;
|
|
93
|
+
#ctx;
|
|
94
|
+
#token;
|
|
95
|
+
#fetch;
|
|
96
|
+
#loadDiscord;
|
|
97
|
+
#allowed;
|
|
98
|
+
#prompts;
|
|
99
|
+
#delivered = new RecentIds(RECENT_DELIVERY_LIMIT);
|
|
100
|
+
#live;
|
|
101
|
+
#client;
|
|
102
|
+
#connection;
|
|
103
|
+
constructor(config, ctx, token, options) {
|
|
104
|
+
this.#config = config;
|
|
105
|
+
this.#ctx = ctx;
|
|
106
|
+
this.#token = token;
|
|
107
|
+
this.#fetch = options.fetch ?? fetch;
|
|
108
|
+
this.#loadDiscord = options.loadDiscord ?? loadDiscordRuntime;
|
|
109
|
+
this.#allowed = new Set(config.allowedChatIds);
|
|
110
|
+
this.#prompts = new PromptStore(ctx.dataDir);
|
|
111
|
+
this.#live = new LiveRuns({
|
|
112
|
+
editIntervalMs: config.editIntervalMs,
|
|
113
|
+
log: ctx.log,
|
|
114
|
+
mode: config.streaming,
|
|
115
|
+
resolveChannel: async (chatId) => await this.#resolveChannel(chatId),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Loads `discord.js`, logs in, waits for the Gateway `clientReady` event, and registers the built-in commands as
|
|
120
|
+
* Slash Commands: in each `commandGuildIds` guild, or globally if the list is empty.
|
|
121
|
+
*
|
|
122
|
+
* Rejects if the stored Approval prompts cannot load or the login fails. A failed command registration only logs an
|
|
123
|
+
* error, because text commands still work.
|
|
124
|
+
*/
|
|
125
|
+
start = async (sink) => {
|
|
126
|
+
await this.#prompts.load();
|
|
127
|
+
const discord = await this.#loadDiscord();
|
|
128
|
+
const client = discord.createClient({
|
|
129
|
+
intents: [
|
|
130
|
+
discord.GatewayIntentBits.Guilds,
|
|
131
|
+
discord.GatewayIntentBits.GuildMessages,
|
|
132
|
+
discord.GatewayIntentBits.MessageContent,
|
|
133
|
+
discord.GatewayIntentBits.DirectMessages,
|
|
134
|
+
],
|
|
135
|
+
// Discord sends DM channels as partial objects. Without this, discord.js drops DMs.
|
|
136
|
+
partials: [discord.Partials.Channel],
|
|
137
|
+
});
|
|
138
|
+
this.#client = client;
|
|
139
|
+
client.onMessage((message) => {
|
|
140
|
+
void this.#guard("handle a Discord message", async () => {
|
|
141
|
+
await this.#onMessage(message);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
client.onInteraction((interaction) => {
|
|
145
|
+
void this.#guard("handle a Discord interaction", async () => {
|
|
146
|
+
await this.#onInteraction(interaction);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
client.onError((failure) => {
|
|
150
|
+
this.#ctx.log.error("The Discord client reported an error", {
|
|
151
|
+
error: failure.message,
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
const ready = Promise.withResolvers();
|
|
155
|
+
client.onReady(() => {
|
|
156
|
+
ready.resolve(undefined);
|
|
157
|
+
});
|
|
158
|
+
await client.login(this.#token);
|
|
159
|
+
await ready.promise;
|
|
160
|
+
const botId = client.botUserId();
|
|
161
|
+
if (botId === undefined) {
|
|
162
|
+
throw new Error("The Discord client reported ready without a bot user");
|
|
163
|
+
}
|
|
164
|
+
this.#connection = {
|
|
165
|
+
botId,
|
|
166
|
+
botMention: new RegExp(String.raw `<@!?${botId}>\s*`, "gu"),
|
|
167
|
+
client,
|
|
168
|
+
discord,
|
|
169
|
+
sink,
|
|
170
|
+
};
|
|
171
|
+
await this.#registerCommands(sink.commands);
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Delivers durable outbound work. Drops a `messageId` that this binding delivered before.
|
|
175
|
+
*
|
|
176
|
+
* A `message` with a `runId` replaces the draft message of that Run with its first chunk. Rejects with a
|
|
177
|
+
* `DeliveryError`: `permanent` for an unknown, non-text, or not-allowed Chat, a file over the limit, or a Discord
|
|
178
|
+
* 4xx answer such as Missing Access; `retryable` before `start` finishes and for rate limits, 5xx, and network
|
|
179
|
+
* errors.
|
|
180
|
+
*/
|
|
181
|
+
deliver = async (delivery) => {
|
|
182
|
+
if (this.#delivered.has(delivery.messageId)) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
await this.#deliver(delivery);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
throw toDeliveryError(error, `deliver ${delivery.kind} ${delivery.messageId} to Chat ${delivery.chatId}`);
|
|
190
|
+
}
|
|
191
|
+
this.#delivered.add(delivery.messageId);
|
|
192
|
+
};
|
|
193
|
+
/** Shows typing and, in `edit` mode, a throttled draft message. Never throws or blocks. */
|
|
194
|
+
onEvent = (event) => {
|
|
195
|
+
this.#live.onEvent(event);
|
|
196
|
+
};
|
|
197
|
+
/** Stops live views and closes the Gateway connection. Resolves also after a failed `start`. */
|
|
198
|
+
stop = async () => {
|
|
199
|
+
this.#live.dispose();
|
|
200
|
+
const client = this.#client;
|
|
201
|
+
this.#client = undefined;
|
|
202
|
+
this.#connection = undefined;
|
|
203
|
+
try {
|
|
204
|
+
await client?.destroy();
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
this.#ctx.log.warn("The Discord client did not close cleanly", {
|
|
208
|
+
error: errorText(error),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
/** Runs an event handler and logs its failure, because a Gateway event has no caller to report to. */
|
|
213
|
+
async #guard(action, step) {
|
|
214
|
+
try {
|
|
215
|
+
await step();
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
this.#ctx.log.error(`Wheatley could not ${action}`, {
|
|
219
|
+
error: errorText(error),
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
#isAllowed(channel) {
|
|
224
|
+
if (this.#allowed.has(channel.id)) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
const parentId = parentOf(channel);
|
|
228
|
+
return parentId !== null && this.#allowed.has(parentId);
|
|
229
|
+
}
|
|
230
|
+
#logDropped(channel) {
|
|
231
|
+
const parentId = parentOf(channel);
|
|
232
|
+
this.#ctx.log.info("Dropped a Discord message from a Chat that is not in allowedChatIds", { chatId: channel.id, parentId });
|
|
233
|
+
}
|
|
234
|
+
async #registerCommands(commands) {
|
|
235
|
+
const connection = this.#connection;
|
|
236
|
+
if (connection === undefined) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const { discord, client } = connection;
|
|
240
|
+
const data = commands.map((spec) => ({
|
|
241
|
+
description: spec.description,
|
|
242
|
+
name: spec.name,
|
|
243
|
+
options: spec.argument === undefined
|
|
244
|
+
? []
|
|
245
|
+
: [
|
|
246
|
+
{
|
|
247
|
+
description: spec.argument,
|
|
248
|
+
name: optionName(spec.argument),
|
|
249
|
+
required: false,
|
|
250
|
+
type: discord.ApplicationCommandOptionType.String,
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
}));
|
|
254
|
+
try {
|
|
255
|
+
const guildIds = this.#config.commandGuildIds;
|
|
256
|
+
await (guildIds.length === 0
|
|
257
|
+
? client.setCommands(data)
|
|
258
|
+
: Promise.all(guildIds.map(async (guildId) => await client.setCommands(data, guildId))));
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
this.#ctx.log.error("Discord rejected the Slash Command registration", {
|
|
262
|
+
error: errorText(error),
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
#addressesBot(message, botId) {
|
|
267
|
+
if (message.channel.isDMBased()) {
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
if (this.#config.guildMessages === "all") {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
return (message.mentions.users.has(botId) ||
|
|
274
|
+
message.mentions.repliedUser?.id === botId);
|
|
275
|
+
}
|
|
276
|
+
async #onMessage(message) {
|
|
277
|
+
const connection = this.#connection;
|
|
278
|
+
const ignored = message.author.bot || message.system;
|
|
279
|
+
if (connection === undefined || ignored) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (!this.#addressesBot(message, connection.botId)) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const { channel } = message;
|
|
286
|
+
if (!this.#isAllowed(channel)) {
|
|
287
|
+
this.#logDropped(channel);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const chatId = channel.id;
|
|
291
|
+
const text = message.content.replaceAll(connection.botMention, "").trim();
|
|
292
|
+
const senderDisplayName = displayName(message.member?.displayName ?? message.author.displayName);
|
|
293
|
+
const command = message.attachments.size === 0 ? parseCommandText(text) : undefined;
|
|
294
|
+
if (command !== undefined) {
|
|
295
|
+
await connection.sink.command({
|
|
296
|
+
chatId,
|
|
297
|
+
name: command.name,
|
|
298
|
+
senderDisplayName,
|
|
299
|
+
args: command.args,
|
|
300
|
+
});
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const staged = await stageInboundFiles(message.attachments.values(), {
|
|
304
|
+
fetch: this.#fetch,
|
|
305
|
+
maxBytes: this.#ctx.maxAttachmentBytes,
|
|
306
|
+
prefix: `discord-${message.id}`,
|
|
307
|
+
stagingDir: this.#ctx.stagingDir,
|
|
308
|
+
});
|
|
309
|
+
const fullText = [text, ...staged.notes]
|
|
310
|
+
.filter((line) => line !== "")
|
|
311
|
+
.join("\n");
|
|
312
|
+
if (fullText === "" && staged.attachments.length === 0) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
await connection.sink.send({
|
|
316
|
+
chatId,
|
|
317
|
+
senderDisplayName,
|
|
318
|
+
text: fullText,
|
|
319
|
+
attachments: staged.attachments.length === 0 ? undefined : staged.attachments,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
async #onInteraction(interaction) {
|
|
323
|
+
const connection = this.#connection;
|
|
324
|
+
if (connection === undefined) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const isOwn = interaction.isChatInputCommand() ||
|
|
328
|
+
(interaction.isButton() &&
|
|
329
|
+
parseApprovalCustomId(interaction.customId) !== undefined);
|
|
330
|
+
if (!isOwn) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const channel = await interactionChannel(interaction, connection.client);
|
|
334
|
+
if (channel === null) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (!this.#isAllowed(channel)) {
|
|
338
|
+
this.#logDropped(channel);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (interaction.isChatInputCommand()) {
|
|
342
|
+
await handleSlashCommand(interaction, channel.id, connection);
|
|
343
|
+
}
|
|
344
|
+
else if (interaction.isButton()) {
|
|
345
|
+
await this.#onApprovalButton(interaction, channel.id, connection);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
async #onApprovalButton(interaction, chatId, { discord, sink }) {
|
|
349
|
+
const press = parseApprovalCustomId(interaction.customId);
|
|
350
|
+
if (press === undefined) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const prompt = this.#prompts.lookup(press.key);
|
|
354
|
+
if (prompt === undefined) {
|
|
355
|
+
await interaction.reply({
|
|
356
|
+
content: "This Approval is no longer available.",
|
|
357
|
+
flags: discord.MessageFlags.Ephemeral,
|
|
358
|
+
});
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
await interaction.deferUpdate();
|
|
362
|
+
const resolvedBy = displayName(interaction.user.displayName);
|
|
363
|
+
const won = await sink.decide({
|
|
364
|
+
approvalId: prompt.approvalId,
|
|
365
|
+
chatId,
|
|
366
|
+
resolution: { decision: press.decision, resolvedBy },
|
|
367
|
+
});
|
|
368
|
+
if (!won) {
|
|
369
|
+
await interaction.followUp({
|
|
370
|
+
content: "This Approval already ended.",
|
|
371
|
+
flags: discord.MessageFlags.Ephemeral,
|
|
372
|
+
});
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
await interaction.editReply({
|
|
376
|
+
components: [approvalButtons(discord, press.key, true)],
|
|
377
|
+
content: resolvedContent(prompt.record?.content ?? interaction.message.content, press.decision, resolvedBy),
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
#requireConnection() {
|
|
381
|
+
if (this.#connection === undefined) {
|
|
382
|
+
throw new DeliveryError("The Discord binding is not connected", {
|
|
383
|
+
kind: "retryable",
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
return this.#connection;
|
|
387
|
+
}
|
|
388
|
+
async #resolveChannel(chatId) {
|
|
389
|
+
const connection = this.#requireConnection();
|
|
390
|
+
const channel = await connection.client.fetchChannel(chatId);
|
|
391
|
+
if (channel === null || !channel.isSendable()) {
|
|
392
|
+
throw new DeliveryError(`Chat ${chatId} is not a Discord text channel`, {
|
|
393
|
+
kind: "permanent",
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
if (!this.#isAllowed(channel)) {
|
|
397
|
+
throw new DeliveryError(`Chat ${chatId} is not in allowedChatIds`, {
|
|
398
|
+
kind: "permanent",
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
return channel;
|
|
402
|
+
}
|
|
403
|
+
async #deliver(delivery) {
|
|
404
|
+
switch (delivery.kind) {
|
|
405
|
+
case "message": {
|
|
406
|
+
await this.#deliverMessage(delivery);
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
case "approval_requested": {
|
|
410
|
+
await this.#deliverApprovalRequest(delivery);
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
case "approval_resolved": {
|
|
414
|
+
await this.#deliverApprovalResolved(delivery);
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
default: {
|
|
418
|
+
// A Delivery kind from a newer SDK. A retry cannot teach this binding to deliver it.
|
|
419
|
+
const unknownDelivery = delivery;
|
|
420
|
+
throw new DeliveryError(`The Discord binding cannot deliver ${unknownDelivery.kind}`, { kind: "permanent" });
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
async #deliverMessage(delivery) {
|
|
425
|
+
const channel = await this.#resolveChannel(delivery.chatId);
|
|
426
|
+
const files = toUploadPayloads(delivery.attachments ?? [], this.#ctx.maxAttachmentBytes);
|
|
427
|
+
const payloads = outboundPayloads(delivery.text, files);
|
|
428
|
+
const draft = delivery.runId === undefined
|
|
429
|
+
? undefined
|
|
430
|
+
: await this.#live.finalize(delivery.runId);
|
|
431
|
+
const [first, ...rest] = payloads;
|
|
432
|
+
if (draft !== undefined && first === undefined) {
|
|
433
|
+
await draft.delete();
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (draft !== undefined && first !== undefined) {
|
|
437
|
+
await draft.edit(first);
|
|
438
|
+
}
|
|
439
|
+
for (const payload of draft === undefined ? payloads : rest) {
|
|
440
|
+
// oxlint-disable-next-line no-await-in-loop -- Chunks must arrive in order.
|
|
441
|
+
await channel.send(payload);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async #deliverApprovalRequest(delivery) {
|
|
445
|
+
const { discord } = this.#requireConnection();
|
|
446
|
+
const channel = await this.#resolveChannel(delivery.chatId);
|
|
447
|
+
if (this.#prompts.get(delivery.approvalId) !== undefined) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const key = promptKey(delivery.approvalId);
|
|
451
|
+
const content = promptContent(delivery);
|
|
452
|
+
const message = await channel.send({
|
|
453
|
+
allowedMentions: NO_MENTIONS,
|
|
454
|
+
components: [approvalButtons(discord, key, false)],
|
|
455
|
+
content,
|
|
456
|
+
});
|
|
457
|
+
await this.#prompts.put({
|
|
458
|
+
approvalId: delivery.approvalId,
|
|
459
|
+
channelId: channel.id,
|
|
460
|
+
content,
|
|
461
|
+
key,
|
|
462
|
+
messageId: message.id,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
async #deliverApprovalResolved(delivery) {
|
|
466
|
+
const { discord } = this.#requireConnection();
|
|
467
|
+
const record = this.#prompts.get(delivery.approvalId);
|
|
468
|
+
if (record === undefined) {
|
|
469
|
+
this.#ctx.log.warn("No Discord prompt is stored for a resolved Approval", {
|
|
470
|
+
approvalId: delivery.approvalId,
|
|
471
|
+
chatId: delivery.chatId,
|
|
472
|
+
});
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const channel = await this.#resolveChannel(record.channelId);
|
|
476
|
+
try {
|
|
477
|
+
await channel.messages.edit(record.messageId, {
|
|
478
|
+
components: [approvalButtons(discord, record.key, true)],
|
|
479
|
+
content: resolvedContent(record.content, delivery.decision, delivery.resolvedBy, delivery.reason),
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
if (discordErrorCode(error) !== UNKNOWN_MESSAGE_CODE) {
|
|
484
|
+
throw error;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
await this.#prompts.delete(delivery.approvalId);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const GUILD_MESSAGE_MODES = ["mention_or_reply", "all"];
|
|
2
|
+
const STREAMING_MODES = ["edit", "typing"];
|
|
3
|
+
/** The default minimum time between two draft edits (ADR 0012). */
|
|
4
|
+
export const DEFAULT_EDIT_INTERVAL_MS = 1200;
|
|
5
|
+
/** Discord rejects edits faster than this rate for one channel, so smaller intervals only cause rate limits. */
|
|
6
|
+
const MIN_EDIT_INTERVAL_MS = 250;
|
|
7
|
+
const MAX_EDIT_INTERVAL_MS = 60_000;
|
|
8
|
+
const SNOWFLAKE_PATTERN = "^[0-9]{1,25}$";
|
|
9
|
+
const SNOWFLAKE = /^[0-9]{1,25}$/u;
|
|
10
|
+
const snowflakeList = (minItems) => ({
|
|
11
|
+
items: { pattern: SNOWFLAKE_PATTERN, type: "string" },
|
|
12
|
+
minItems,
|
|
13
|
+
type: "array",
|
|
14
|
+
uniqueItems: true,
|
|
15
|
+
});
|
|
16
|
+
const configProperties = {
|
|
17
|
+
allowedChatIds: snowflakeList(1),
|
|
18
|
+
commandGuildIds: snowflakeList(0),
|
|
19
|
+
editIntervalMs: {
|
|
20
|
+
maximum: MAX_EDIT_INTERVAL_MS,
|
|
21
|
+
minimum: MIN_EDIT_INTERVAL_MS,
|
|
22
|
+
type: "integer",
|
|
23
|
+
},
|
|
24
|
+
guildMessages: { enum: [...GUILD_MESSAGE_MODES], type: "string" },
|
|
25
|
+
streaming: { enum: [...STREAMING_MODES], type: "string" },
|
|
26
|
+
tokenSecret: { minLength: 1, type: "string" },
|
|
27
|
+
};
|
|
28
|
+
/** The plain JSON Schema of the `config` object of a `type: discord` Frontend Binding. */
|
|
29
|
+
export const discordConfigSchema = {
|
|
30
|
+
additionalProperties: false,
|
|
31
|
+
properties: configProperties,
|
|
32
|
+
required: ["tokenSecret", "allowedChatIds"],
|
|
33
|
+
type: "object",
|
|
34
|
+
};
|
|
35
|
+
const KNOWN_KEYS = new Set(Object.keys(configProperties));
|
|
36
|
+
const isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
37
|
+
const isString = (value) => typeof value === "string";
|
|
38
|
+
const isInteger = (value) => typeof value === "number" && Number.isInteger(value);
|
|
39
|
+
const isJsonArray = (value) => Array.isArray(value);
|
|
40
|
+
const invalid = (message) => new Error(`Invalid Discord Frontend config: ${message}`);
|
|
41
|
+
const readSnowflakes = (value, key, minItems) => {
|
|
42
|
+
if (value === undefined && minItems === 0) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
if (!isJsonArray(value)) {
|
|
46
|
+
throw invalid(`${key} must be an array of Discord IDs`);
|
|
47
|
+
}
|
|
48
|
+
const ids = [];
|
|
49
|
+
for (const item of value) {
|
|
50
|
+
if (!isString(item) || !SNOWFLAKE.test(item)) {
|
|
51
|
+
throw invalid(`${key} must contain only Discord IDs (digits)`);
|
|
52
|
+
}
|
|
53
|
+
ids.push(item);
|
|
54
|
+
}
|
|
55
|
+
if (ids.length < minItems) {
|
|
56
|
+
throw invalid(`${key} must list at least ${minItems} ID`);
|
|
57
|
+
}
|
|
58
|
+
return [...new Set(ids)];
|
|
59
|
+
};
|
|
60
|
+
const readEnum = (value, key, allowed, fallback) => {
|
|
61
|
+
if (value === undefined) {
|
|
62
|
+
return fallback;
|
|
63
|
+
}
|
|
64
|
+
const match = allowed.find((option) => option === value);
|
|
65
|
+
if (match === undefined) {
|
|
66
|
+
throw invalid(`${key} must be one of ${allowed.join(", ")}`);
|
|
67
|
+
}
|
|
68
|
+
return match;
|
|
69
|
+
};
|
|
70
|
+
const readEditInterval = (value) => {
|
|
71
|
+
if (value === undefined) {
|
|
72
|
+
return DEFAULT_EDIT_INTERVAL_MS;
|
|
73
|
+
}
|
|
74
|
+
const inRange = isInteger(value) &&
|
|
75
|
+
value >= MIN_EDIT_INTERVAL_MS &&
|
|
76
|
+
value <= MAX_EDIT_INTERVAL_MS;
|
|
77
|
+
if (!inRange) {
|
|
78
|
+
throw invalid(`editIntervalMs must be an integer from ${MIN_EDIT_INTERVAL_MS} to ${MAX_EDIT_INTERVAL_MS}`);
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Converts a binding `config` value into `DiscordConfig` and applies the defaults.
|
|
84
|
+
*
|
|
85
|
+
* Throws an `Error` that names the first invalid field, for example an empty `allowedChatIds` list (ADR 0012).
|
|
86
|
+
*/
|
|
87
|
+
export const parseDiscordConfig = (value) => {
|
|
88
|
+
if (!isJsonObject(value)) {
|
|
89
|
+
throw invalid("config must be an object");
|
|
90
|
+
}
|
|
91
|
+
const unknownKey = Object.keys(value).find((key) => !KNOWN_KEYS.has(key));
|
|
92
|
+
if (unknownKey !== undefined) {
|
|
93
|
+
throw invalid(`unknown field ${unknownKey}`);
|
|
94
|
+
}
|
|
95
|
+
const { tokenSecret } = value;
|
|
96
|
+
if (!isString(tokenSecret) || tokenSecret === "") {
|
|
97
|
+
throw invalid("tokenSecret must name a secret");
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
allowedChatIds: readSnowflakes(value.allowedChatIds, "allowedChatIds", 1),
|
|
101
|
+
commandGuildIds: readSnowflakes(value.commandGuildIds, "commandGuildIds", 0),
|
|
102
|
+
editIntervalMs: readEditInterval(value.editIntervalMs),
|
|
103
|
+
guildMessages: readEnum(value.guildMessages, "guildMessages", GUILD_MESSAGE_MODES, "mention_or_reply"),
|
|
104
|
+
streaming: readEnum(value.streaming, "streaming", STREAMING_MODES, "edit"),
|
|
105
|
+
tokenSecret,
|
|
106
|
+
};
|
|
107
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** The `allowedMentions` value that stops a message from pinging anyone. */
|
|
2
|
+
export const NO_MENTIONS = {
|
|
3
|
+
parse: [],
|
|
4
|
+
};
|
|
5
|
+
/** Adapts a `discord.js` client to `DiscordClient`. */
|
|
6
|
+
export const adaptClient = (discord, client) => ({
|
|
7
|
+
botUserId: () => client.user?.id,
|
|
8
|
+
destroy: async () => {
|
|
9
|
+
await client.destroy();
|
|
10
|
+
},
|
|
11
|
+
fetchChannel: async (channelId) => await client.channels.fetch(channelId),
|
|
12
|
+
login: async (token) => {
|
|
13
|
+
await client.login(token);
|
|
14
|
+
},
|
|
15
|
+
onError: (listener) => {
|
|
16
|
+
client.on(discord.Events.Error, listener);
|
|
17
|
+
},
|
|
18
|
+
onInteraction: (listener) => {
|
|
19
|
+
client.on(discord.Events.InteractionCreate, listener);
|
|
20
|
+
},
|
|
21
|
+
onMessage: (listener) => {
|
|
22
|
+
client.on(discord.Events.MessageCreate, listener);
|
|
23
|
+
},
|
|
24
|
+
onReady: (listener) => {
|
|
25
|
+
client.once(discord.Events.ClientReady, () => {
|
|
26
|
+
listener();
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
setCommands: async (commands, guildId) => {
|
|
30
|
+
const { application } = client;
|
|
31
|
+
if (application === null) {
|
|
32
|
+
throw new Error("The Discord client is not ready");
|
|
33
|
+
}
|
|
34
|
+
const stored = guildId === undefined
|
|
35
|
+
? await application.commands.set(commands)
|
|
36
|
+
: await application.commands.set(commands, guildId);
|
|
37
|
+
return stored.size;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
/** Loads `discord.js` on first use, so that Agents without a Discord binding never load it (ADR 0012). */
|
|
41
|
+
export const loadDiscordRuntime = async () => {
|
|
42
|
+
const discord = await import("discord.js");
|
|
43
|
+
return {
|
|
44
|
+
ApplicationCommandOptionType: discord.ApplicationCommandOptionType,
|
|
45
|
+
ButtonStyle: discord.ButtonStyle,
|
|
46
|
+
ComponentType: discord.ComponentType,
|
|
47
|
+
GatewayIntentBits: discord.GatewayIntentBits,
|
|
48
|
+
MessageFlags: discord.MessageFlags,
|
|
49
|
+
Partials: discord.Partials,
|
|
50
|
+
createClient: (options) => adaptClient(discord, new discord.Client(options)),
|
|
51
|
+
};
|
|
52
|
+
};
|