fix(ci): make discord doctor loading bundler-safe

This commit is contained in:
Vincent Koc 2026-04-05 09:48:04 +01:00
parent 48653c2031
commit 19e97193d3
1 changed files with 4 additions and 19 deletions

View File

@ -1,4 +1,3 @@
import { createJiti } from "jiti";
import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
import { formatAllowFromLowercase } from "openclaw/plugin-sdk/allow-from";
import { adaptScopedAccountAccessor } from "openclaw/plugin-sdk/channel-config-helpers";
@ -13,6 +12,7 @@ import {
} from "./accounts.js";
import { getChatChannelMeta, type ChannelPlugin } from "./channel-api.js";
import { DiscordChannelConfigSchema } from "./config-schema.js";
import { normalizeCompatibilityConfig } from "./doctor-contract.js";
import { DISCORD_LEGACY_CONFIG_RULES } from "./doctor-shared.js";
import {
collectRuntimeConfigAssignments,
@ -29,40 +29,25 @@ export const DISCORD_CHANNEL = "discord" as const;
type DiscordDoctorModule = typeof import("./doctor.js");
let discordDoctorModulePromise: Promise<DiscordDoctorModule> | undefined;
let discordDoctorLoader: ReturnType<typeof createJiti> | undefined;
let cachedDiscordDoctorModule: DiscordDoctorModule | undefined;
async function loadDiscordDoctorModule(): Promise<DiscordDoctorModule> {
discordDoctorModulePromise ??= import("./doctor.js");
return await discordDoctorModulePromise;
}
function loadDiscordDoctorModuleSync(): DiscordDoctorModule {
if (cachedDiscordDoctorModule) {
return cachedDiscordDoctorModule;
}
discordDoctorLoader ??= createJiti(import.meta.url, { interopDefault: true });
cachedDiscordDoctorModule = discordDoctorLoader("./doctor.js") as DiscordDoctorModule;
return cachedDiscordDoctorModule;
}
const discordDoctor: ChannelDoctorAdapter = {
dmAllowFromMode: "topOrNested",
groupModel: "route",
groupAllowFromFallbackToAllowFrom: false,
warnOnEmptyGroupSenderAllowlist: false,
legacyConfigRules: DISCORD_LEGACY_CONFIG_RULES,
normalizeCompatibilityConfig: (params) =>
loadDiscordDoctorModuleSync().discordDoctor.normalizeCompatibilityConfig?.(params) ?? {
config: params.cfg,
changes: [],
},
normalizeCompatibilityConfig,
collectPreviewWarnings: async (params) =>
(await loadDiscordDoctorModule()).discordDoctor.collectPreviewWarnings?.(params) ?? [],
collectMutableAllowlistWarnings: async (params) =>
(await loadDiscordDoctorModule()).discordDoctor.collectMutableAllowlistWarnings?.(params) ?? [],
repairConfig: (params) =>
loadDiscordDoctorModuleSync().discordDoctor.repairConfig?.(params) ?? {
repairConfig: async (params) =>
(await loadDiscordDoctorModule()).discordDoctor.repairConfig?.(params) ?? {
config: params.cfg,
changes: [],
},