




















@@ -24,7 +24,6 @@ import {
2424import type { OpenClawConfig, ReplyToMode } from "openclaw/plugin-sdk/config-runtime";
2525import { loadConfig } from "openclaw/plugin-sdk/config-runtime";
2626import { createConnectedChannelStatusPatch } from "openclaw/plugin-sdk/gateway-runtime";
27-import { getPluginCommandSpecs } from "openclaw/plugin-sdk/plugin-runtime";
2827import { resolveTextChunkLimit } from "openclaw/plugin-sdk/reply-chunking";
2928import {
3029danger,
@@ -110,9 +109,12 @@ type DiscordVoiceManager = import("../voice/manager.js").DiscordVoiceManager;
110109111110type DiscordVoiceRuntimeModule = typeof import("../voice/manager.runtime.js");
112111type DiscordProviderSessionRuntimeModule = typeof import("./provider-session.runtime.js");
112+type GetPluginCommandSpecs =
113+typeof import("openclaw/plugin-sdk/plugin-runtime").getPluginCommandSpecs;
113114114115let discordVoiceRuntimePromise: Promise<DiscordVoiceRuntimeModule> | undefined;
115116let discordProviderSessionRuntimePromise: Promise<DiscordProviderSessionRuntimeModule> | undefined;
117+let pluginRuntimePromise: Promise<typeof import("openclaw/plugin-sdk/plugin-runtime")> | undefined;
116118117119let fetchDiscordApplicationIdForTesting: typeof fetchDiscordApplicationId | undefined;
118120let createDiscordNativeCommandForTesting: typeof createDiscordNativeCommand | undefined;
@@ -130,7 +132,7 @@ let createClientForTesting:
130132plugins: ConstructorParameters<typeof Client>[2],
131133) => Client)
132134| undefined;
133-let getPluginCommandSpecsForTesting: typeof getPluginCommandSpecs | undefined;
135+let getPluginCommandSpecsForTesting: GetPluginCommandSpecs | undefined;
134136let resolveDiscordAccountForTesting: typeof resolveDiscordAccount | undefined;
135137let resolveNativeCommandsEnabledForTesting: typeof resolveNativeCommandsEnabled | undefined;
136138let resolveNativeSkillsEnabledForTesting: typeof resolveNativeSkillsEnabled | undefined;
@@ -155,6 +157,11 @@ async function loadDiscordProviderSessionRuntime(): Promise<DiscordProviderSessi
155157return await discordProviderSessionRuntimePromise;
156158}
157159160+async function loadPluginRuntime() {
161+pluginRuntimePromise ??= import("openclaw/plugin-sdk/plugin-runtime");
162+return await pluginRuntimePromise;
163+}
164+158165function normalizeBooleanForTesting(value: unknown): boolean | undefined {
159166if (typeof value === "boolean") {
160167return value;
@@ -178,17 +185,17 @@ function formatThreadBindingDurationForConfigLabel(durationMs: number): string {
178185return label === "disabled" ? "off" : label;
179186}
180187181-function appendPluginCommandSpecs(params: {
188+async function appendPluginCommandSpecs(params: {
182189commandSpecs: NativeCommandSpec[];
183190runtime: RuntimeEnv;
184-}): NativeCommandSpec[] {
191+}): Promise<NativeCommandSpec[]> {
185192const merged = [...params.commandSpecs];
186193const existingNames = new Set(
187194merged.map((spec) => normalizeLowercaseStringOrEmpty(spec.name)).filter(Boolean),
188195);
189-for (const pluginCommand of (getPluginCommandSpecsForTesting ?? getPluginCommandSpecs)(
190-"discord",
191-)) {
196+const getPluginCommandSpecs =
197+getPluginCommandSpecsForTesting ?? (await loadPluginRuntime()).getPluginCommandSpecs;
198+for (const pluginCommand of getPluginCommandSpecs("discord")) {
192199const normalizedName = normalizeLowercaseStringOrEmpty(pluginCommand.name);
193200if (!normalizedName) {
194201continue;
@@ -740,7 +747,7 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
740747})
741748 : [];
742749if (nativeEnabled) {
743-commandSpecs = appendPluginCommandSpecs({ commandSpecs, runtime });
750+commandSpecs = await appendPluginCommandSpecs({ commandSpecs, runtime });
744751}
745752const initialCommandCount = commandSpecs.length;
746753if (nativeEnabled && nativeSkillsEnabled && commandSpecs.length > maxDiscordCommands) {
@@ -749,7 +756,7 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
749756cfg,
750757{ skillCommands: [], provider: "discord" },
751758);
752-commandSpecs = appendPluginCommandSpecs({ commandSpecs, runtime });
759+commandSpecs = await appendPluginCommandSpecs({ commandSpecs, runtime });
753760runtime.log?.(
754761warn(
755762`discord: ${initialCommandCount} commands exceeds limit; removing per-skill commands and keeping /skill.`,
@@ -1201,7 +1208,7 @@ export const __testing = {
12011208) {
12021209createClientForTesting = mock;
12031210},
1204-setGetPluginCommandSpecs(mock?: typeof getPluginCommandSpecs) {
1211+setGetPluginCommandSpecs(mock?: GetPluginCommandSpecs) {
12051212getPluginCommandSpecsForTesting = mock;
12061213},
12071214setResolveDiscordAccount(mock?: typeof resolveDiscordAccount) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。