fix: validate tag names in update_forum_post
Return an error listing the invalid tag names and available tags instead of silently ignoring unrecognized tags.
This commit is contained in:
parent
6b9dde03e9
commit
b7e0098987
|
|
@ -376,15 +376,23 @@ export const updateForumPostHandler: ToolHandler = async (args, { client }) => {
|
||||||
if (parent && parent.type === ChannelType.GuildForum) {
|
if (parent && parent.type === ChannelType.GuildForum) {
|
||||||
const forumChannel = parent as ForumChannel;
|
const forumChannel = parent as ForumChannel;
|
||||||
const availableTags = forumChannel.availableTags;
|
const availableTags = forumChannel.availableTags;
|
||||||
const tagIds = tags.map(tagInput => {
|
const resolved: string[] = [];
|
||||||
// Accept either tag name or tag ID
|
const invalid: string[] = [];
|
||||||
|
for (const tagInput of tags) {
|
||||||
const byName = availableTags.find(t => t.name === tagInput);
|
const byName = availableTags.find(t => t.name === tagInput);
|
||||||
if (byName) return byName.id;
|
if (byName) { resolved.push(byName.id); continue; }
|
||||||
const byId = availableTags.find(t => t.id === tagInput);
|
const byId = availableTags.find(t => t.id === tagInput);
|
||||||
if (byId) return byId.id;
|
if (byId) { resolved.push(byId.id); continue; }
|
||||||
return null;
|
invalid.push(tagInput);
|
||||||
}).filter((id): id is string => id !== null);
|
}
|
||||||
editOptions.appliedTags = tagIds;
|
if (invalid.length > 0) {
|
||||||
|
const validNames = availableTags.map(t => t.name).join(', ');
|
||||||
|
return {
|
||||||
|
content: [{ type: "text", text: `Unknown tag(s): ${invalid.join(', ')}. Available tags: ${validNames}` }],
|
||||||
|
isError: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
editOptions.appliedTags = resolved;
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
content: [{ type: "text", text: `Thread's parent channel is not a forum channel. Tags can only be applied to forum posts.` }],
|
content: [{ type: "text", text: `Thread's parent channel is not a forum channel. Tags can only be applied to forum posts.` }],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue