fix: enforce Discord agent component DM auth (#11254) (thanks @thedudeabidesai)

This commit is contained in:
Shadow
2026-02-10 00:25:23 -06:00
committed by Shadow
parent f17c978f5c
commit 4537ebc43a
5 changed files with 659 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { Client } from "@buape/carbon";
import { Client, type BaseMessageInteractiveComponent } from "@buape/carbon";
import { GatewayIntents, GatewayPlugin } from "@buape/carbon/gateway";
import { Routes } from "discord-api-types/v10";
import { inspect } from "node:util";
@@ -26,6 +26,7 @@ import { fetchDiscordApplicationId } from "../probe.js";
import { resolveDiscordChannelAllowlist } from "../resolve-channels.js";
import { resolveDiscordUserAllowlist } from "../resolve-users.js";
import { normalizeDiscordToken } from "../token.js";
import { createAgentComponentButton, createAgentSelectMenu } from "./agent-components.js";
import { createExecApprovalButton, DiscordExecApprovalHandler } from "./exec-approvals.js";
import { registerGateway, unregisterGateway } from "./gateway-registry.js";
import {
@@ -474,7 +475,10 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
})
: null;
const components = [
const agentComponentsConfig = discordCfg.agentComponents ?? {};
const agentComponentsEnabled = agentComponentsConfig.enabled ?? true;
const components: BaseMessageInteractiveComponent[] = [
createDiscordCommandArgFallbackButton({
cfg,
discordConfig: discordCfg,
@@ -487,6 +491,27 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
components.push(createExecApprovalButton({ handler: execApprovalsHandler }));
}
if (agentComponentsEnabled) {
components.push(
createAgentComponentButton({
cfg,
accountId: account.accountId,
guildEntries,
allowFrom,
dmPolicy,
}),
);
components.push(
createAgentSelectMenu({
cfg,
accountId: account.accountId,
guildEntries,
allowFrom,
dmPolicy,
}),
);
}
const client = new Client(
{
baseUrl: "http://localhost",