fix(discord): dedupe native skill commands by skillName (#17365)

* fix(discord): dedupe native skill commands by skill name

* Changelog: credit Discord skill dedupe

---------

Co-authored-by: yume <yume@yumedeMacBook-Pro.local>
Co-authored-by: Shadow <hi@shadowing.dev>
This commit is contained in:
seewhy
2026-02-16 10:33:51 +08:00
committed by GitHub
parent d9d5b53b42
commit ddcc7a1a5d
3 changed files with 51 additions and 1 deletions

View File

@@ -81,6 +81,26 @@ function summarizeGuilds(entries?: Record<string, unknown>) {
return `${sample.join(", ")}${suffix}`;
}
function dedupeSkillCommandsForDiscord(
skillCommands: ReturnType<typeof listSkillCommandsForAgents>,
) {
const seen = new Set<string>();
const deduped: ReturnType<typeof listSkillCommandsForAgents> = [];
for (const command of skillCommands) {
const key = command.skillName.trim().toLowerCase();
if (!key) {
deduped.push(command);
continue;
}
if (seen.has(key)) {
continue;
}
seen.add(key);
deduped.push(command);
}
return deduped;
}
async function deployDiscordCommands(params: {
client: Client;
runtime: RuntimeEnv;
@@ -355,7 +375,9 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
const maxDiscordCommands = 100;
let skillCommands =
nativeEnabled && nativeSkillsEnabled ? listSkillCommandsForAgents({ cfg }) : [];
nativeEnabled && nativeSkillsEnabled
? dedupeSkillCommandsForDiscord(listSkillCommandsForAgents({ cfg }))
: [];
let commandSpecs = nativeEnabled
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "discord" })
: [];
@@ -648,4 +670,5 @@ async function clearDiscordNativeCommands(params: {
export const __testing = {
createDiscordGatewayPlugin,
dedupeSkillCommandsForDiscord,
};