fix(check): repair monitor and message tool types

This commit is contained in:
Peter Steinberger
2026-04-06 14:54:55 +01:00
parent 9fa5b413f0
commit c817e6d388
3 changed files with 37 additions and 7 deletions
@@ -29,6 +29,28 @@ type ModelPickerPreferencesStore = {
entries: Record<string, ModelPickerPreferencesEntry>;
};
function sanitizePreferenceEntries(entries: unknown): Record<string, ModelPickerPreferencesEntry> {
if (!entries || typeof entries !== "object") {
return {};
}
const normalizedEntries: Record<string, ModelPickerPreferencesEntry> = {};
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<ModelPickerPrefer
}
return {
version: 1,
entries: value.entries && typeof value.entries === "object" ? value.entries : {},
entries: sanitizePreferenceEntries(value.entries),
};
}
+12 -4
View File
@@ -770,12 +770,16 @@ describe("discord component interactions", () => {
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);
+2 -2
View File
@@ -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<ChannelMessageActionName | "send">(["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<ChannelMessageActionName | "send">(["send", ...actions]);
otherChannels.push(`${plugin.id} (${Array.from(all).toSorted().join(", ")})`);
}
}