fix(discord): fix component parsing and modal field typing

This commit is contained in:
Peter Steinberger
2026-02-15 18:47:36 +00:00
parent f92900fc20
commit c118f6c688
3 changed files with 16 additions and 8 deletions

View File

@@ -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,

View File

@@ -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(
{

View File

@@ -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<true> | Guild;
channelName: string;
channelId: string;
}) {
const { guild, channelName, channelId } = params;
return `${guild?.name ?? "Guild"} #${channelName} channel id:${channelId}`;
}