diff --git a/extensions/discord/src/monitor/model-picker-preferences.ts b/extensions/discord/src/monitor/model-picker-preferences.ts index 02f3eecfbb..75e648bce2 100644 --- a/extensions/discord/src/monitor/model-picker-preferences.ts +++ b/extensions/discord/src/monitor/model-picker-preferences.ts @@ -29,6 +29,28 @@ type ModelPickerPreferencesStore = { entries: Record; }; +function sanitizePreferenceEntries(entries: unknown): Record { + if (!entries || typeof entries !== "object") { + return {}; + } + const normalizedEntries: Record = {}; + for (const [key, value] of Object.entries(entries)) { + if (!value || typeof value !== "object") { + continue; + } + const typedValue = value as { + recent?: unknown; + updatedAt?: unknown; + }; + const recent = Array.isArray(typedValue.recent) + ? typedValue.recent.filter((item: unknown): item is string => typeof item === "string") + : []; + const updatedAt = typeof typedValue.updatedAt === "string" ? typedValue.updatedAt : ""; + normalizedEntries[key] = { recent, updatedAt }; + } + return normalizedEntries; +} + export type DiscordModelPickerPreferenceScope = { accountId?: string; guildId?: string; @@ -103,7 +125,7 @@ async function readPreferencesStore(filePath: string): Promise { const acknowledge = vi.fn().mockResolvedValue(undefined); const reply = vi.fn().mockResolvedValue(undefined); const update = vi.fn().mockResolvedValue(undefined); + const baseInteraction = createComponentButtonInteraction().interaction as unknown as Record< + string, + unknown + >; const interaction = { - ...(createComponentButtonInteraction().interaction as unknown), + ...baseInteraction, acknowledge, reply, update, - } as ButtonInteraction; + } as unknown as ButtonInteraction; await button.run(interaction, { cid: "btn_1" } as ComponentData); @@ -821,11 +825,15 @@ describe("discord component interactions", () => { const button = createDiscordComponentButton(createComponentContext()); const acknowledge = vi.fn().mockResolvedValue(undefined); const followUp = vi.fn().mockResolvedValue(undefined); + const baseInteraction = createComponentButtonInteraction().interaction as unknown as Record< + string, + unknown + >; const interaction = { - ...(createComponentButtonInteraction().interaction as unknown), + ...baseInteraction, acknowledge, followUp, - } as ButtonInteraction; + } as unknown as ButtonInteraction; await button.run(interaction, { cid: "btn_1" } as ComponentData); diff --git a/src/agents/tools/message-tool.ts b/src/agents/tools/message-tool.ts index f74f3a309e..f8cfdb1238 100644 --- a/src/agents/tools/message-tool.ts +++ b/src/agents/tools/message-tool.ts @@ -586,7 +586,7 @@ function buildMessageToolDescription(options?: { }); if (channelActions.length > 0) { // Always include "send" as a base action - const allActions = new Set(["send", ...channelActions]); + const allActions = new Set(["send", ...channelActions]); const actionList = Array.from(allActions).toSorted().join(", "); let desc = `${baseDescription} Current channel (${currentChannel}) supports: ${actionList}.`; @@ -609,7 +609,7 @@ function buildMessageToolDescription(options?: { requesterSenderId: resolvedOptions.requesterSenderId, }); if (actions.length > 0) { - const all = new Set(["send", ...actions]); + const all = new Set(["send", ...actions]); otherChannels.push(`${plugin.id} (${Array.from(all).toSorted().join(", ")})`); } }