From 2b450ab629fc6c91974bb72209e840ef29e099b7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 28 Mar 2026 03:26:37 +0000 Subject: [PATCH] refactor: move discord system events onto channel runtime --- extensions/discord/src/monitor/agent-components.ts | 2 +- extensions/discord/src/monitor/listeners.ts | 2 +- .../src/monitor/message-handler.preflight.ts | 3 +-- extensions/discord/src/monitor/monitor.test.ts | 13 +++++++++++++ src/plugin-sdk/channel-runtime.ts | 1 + 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/extensions/discord/src/monitor/agent-components.ts b/extensions/discord/src/monitor/agent-components.ts index 32a7242415c..85f415f54cd 100644 --- a/extensions/discord/src/monitor/agent-components.ts +++ b/extensions/discord/src/monitor/agent-components.ts @@ -24,6 +24,7 @@ import { resolveEnvelopeFormatOptions, } from "openclaw/plugin-sdk/channel-inbound"; import { createChannelReplyPipeline } from "openclaw/plugin-sdk/channel-reply-pipeline"; +import { enqueueSystemEvent } from "openclaw/plugin-sdk/channel-runtime"; import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime"; import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/config-runtime"; import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/config-runtime"; @@ -36,7 +37,6 @@ import { resolvePluginConversationBindingApproval, } from "openclaw/plugin-sdk/conversation-runtime"; import { recordInboundSession } from "openclaw/plugin-sdk/conversation-runtime"; -import { enqueueSystemEvent } from "openclaw/plugin-sdk/infra-runtime"; import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime"; import { dispatchPluginInteractiveHandler, diff --git a/extensions/discord/src/monitor/listeners.ts b/extensions/discord/src/monitor/listeners.ts index 71034741cce..dbad78a686d 100644 --- a/extensions/discord/src/monitor/listeners.ts +++ b/extensions/discord/src/monitor/listeners.ts @@ -8,8 +8,8 @@ import { ThreadUpdateListener, type User, } from "@buape/carbon"; +import { enqueueSystemEvent } from "openclaw/plugin-sdk/channel-runtime"; import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime"; -import { enqueueSystemEvent } from "openclaw/plugin-sdk/infra-runtime"; import { resolveAgentRoute } from "openclaw/plugin-sdk/routing"; import { createSubsystemLogger, diff --git a/extensions/discord/src/monitor/message-handler.preflight.ts b/extensions/discord/src/monitor/message-handler.preflight.ts index 8f70fa463af..04657d8eef4 100644 --- a/extensions/discord/src/monitor/message-handler.preflight.ts +++ b/extensions/discord/src/monitor/message-handler.preflight.ts @@ -7,7 +7,7 @@ import { matchesMentionWithExplicit, resolveMentionGatingWithBypass, } from "openclaw/plugin-sdk/channel-inbound"; -import { recordChannelActivity } from "openclaw/plugin-sdk/channel-runtime"; +import { enqueueSystemEvent, recordChannelActivity } from "openclaw/plugin-sdk/channel-runtime"; import { resolveControlCommandGate } from "openclaw/plugin-sdk/command-auth"; import { hasControlCommand } from "openclaw/plugin-sdk/command-auth"; import { shouldHandleTextCommands } from "openclaw/plugin-sdk/command-auth"; @@ -15,7 +15,6 @@ import { loadConfig } from "openclaw/plugin-sdk/config-runtime"; import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/config-runtime"; import type { SessionBindingRecord } from "openclaw/plugin-sdk/conversation-runtime"; import * as conversationRuntime from "openclaw/plugin-sdk/conversation-runtime"; -import { enqueueSystemEvent } from "openclaw/plugin-sdk/infra-runtime"; import { recordPendingHistoryEntryIfEnabled, type HistoryEntry, diff --git a/extensions/discord/src/monitor/monitor.test.ts b/extensions/discord/src/monitor/monitor.test.ts index e54ae02279f..6a90dbae1fa 100644 --- a/extensions/discord/src/monitor/monitor.test.ts +++ b/extensions/discord/src/monitor/monitor.test.ts @@ -77,6 +77,19 @@ async function createInfraRuntimeMock( vi.mock("openclaw/plugin-sdk/infra-runtime", createInfraRuntimeMock); vi.mock("openclaw/plugin-sdk/infra-runtime.js", createInfraRuntimeMock); +async function createChannelRuntimeMock( + importOriginal: () => Promise, +) { + const actual = await importOriginal(); + return { + ...actual, + enqueueSystemEvent: (...args: unknown[]) => enqueueSystemEventMock(...args), + }; +} + +vi.mock("openclaw/plugin-sdk/channel-runtime", createChannelRuntimeMock); +vi.mock("openclaw/plugin-sdk/channel-runtime.js", createChannelRuntimeMock); + vi.mock("openclaw/plugin-sdk/reply-runtime", async (importOriginal) => { const actual = await importOriginal(); return { diff --git a/src/plugin-sdk/channel-runtime.ts b/src/plugin-sdk/channel-runtime.ts index 33e52aed961..bc15df49749 100644 --- a/src/plugin-sdk/channel-runtime.ts +++ b/src/plugin-sdk/channel-runtime.ts @@ -11,6 +11,7 @@ export * from "../channels/plugins/normalize/whatsapp.js"; export * from "../channels/plugins/outbound/interactive.js"; export * from "../channels/plugins/whatsapp-heartbeat.js"; export * from "../polls.js"; +export { enqueueSystemEvent } from "../infra/system-events.js"; export { recordChannelActivity } from "../infra/channel-activity.js"; export { isWhatsAppGroupJid,