From c118f6c6883a465d9da4d8ae22fcabcae889bc0e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 18:47:36 +0000 Subject: [PATCH] fix(discord): fix component parsing and modal field typing --- src/agents/tools/discord-actions-messaging.ts | 1 + .../plugins/actions/discord/handle-action.ts | 17 ++++++++++------- src/discord/monitor/reply-context.ts | 6 +++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/agents/tools/discord-actions-messaging.ts b/src/agents/tools/discord-actions-messaging.ts index 1097d48a00..6f2552c9ff 100644 --- a/src/agents/tools/discord-actions-messaging.ts +++ b/src/agents/tools/discord-actions-messaging.ts @@ -1,6 +1,7 @@ import type { AgentToolResult } from "@mariozechner/pi-agent-core"; import type { DiscordActionConfig } from "../../config/config.js"; import type { DiscordSendComponents, DiscordSendEmbeds } from "../../discord/send.shared.js"; +import { readDiscordComponentSpec } from "../../discord/components.js"; import { createThreadDiscord, deleteMessageDiscord, diff --git a/src/channels/plugins/actions/discord/handle-action.ts b/src/channels/plugins/actions/discord/handle-action.ts index 87c5cb9abf..469b4a7da8 100644 --- a/src/channels/plugins/actions/discord/handle-action.ts +++ b/src/channels/plugins/actions/discord/handle-action.ts @@ -34,8 +34,17 @@ export async function handleDiscordMessageAction( if (action === "send") { const to = readStringParam(params, "to", { required: true }); + const asVoice = params.asVoice === true; + const rawComponents = params.components; + const components = + rawComponents && + (Array.isArray(rawComponents) || + typeof rawComponents === "function" || + (typeof rawComponents === "object" && !Array.isArray(rawComponents))) + ? rawComponents + : undefined; const content = readStringParam(params, "message", { - required: true, + required: !asVoice && !components, allowEmpty: true, }); // Support media, path, and filePath for media URL @@ -44,14 +53,8 @@ export async function handleDiscordMessageAction( readStringParam(params, "path", { trim: false }) ?? readStringParam(params, "filePath", { trim: false }); const replyTo = readStringParam(params, "replyTo"); - const rawComponents = params.components; - const components = - Array.isArray(rawComponents) || typeof rawComponents === "function" - ? rawComponents - : undefined; const rawEmbeds = params.embeds; const embeds = Array.isArray(rawEmbeds) ? rawEmbeds : undefined; - const asVoice = params.asVoice === true; const silent = params.silent === true; return await handleDiscordAction( { diff --git a/src/discord/monitor/reply-context.ts b/src/discord/monitor/reply-context.ts index 69df5a2e96..16866254ae 100644 --- a/src/discord/monitor/reply-context.ts +++ b/src/discord/monitor/reply-context.ts @@ -43,7 +43,11 @@ export function buildDirectLabel(author: User, tagOverride?: string) { return `${username ?? "unknown"} user id:${author.id}`; } -export function buildGuildLabel(params: { guild?: Guild; channelName: string; channelId: string }) { +export function buildGuildLabel(params: { + guild?: Guild | Guild; + channelName: string; + channelId: string; +}) { const { guild, channelName, channelId } = params; return `${guild?.name ?? "Guild"} #${channelName} channel id:${channelId}`; }