mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 21:23:23 +00:00
perf(test): narrow discord monitor runtime seams
This commit is contained in:
@@ -23,29 +23,17 @@ import {
|
||||
formatInboundEnvelope,
|
||||
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";
|
||||
import { resolveOpenProviderRuntimeGroupPolicy } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { readSessionUpdatedAt, resolveStorePath } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/dangerous-name-runtime";
|
||||
import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/markdown-table-runtime";
|
||||
import { resolveOpenProviderRuntimeGroupPolicy } from "openclaw/plugin-sdk/runtime-group-policy";
|
||||
import { readSessionUpdatedAt, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
|
||||
import type { DiscordAccountConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import {
|
||||
buildPluginBindingResolvedText,
|
||||
parsePluginBindingApprovalCustomId,
|
||||
resolvePluginConversationBindingApproval,
|
||||
} from "openclaw/plugin-sdk/conversation-runtime";
|
||||
import { recordInboundSession } from "openclaw/plugin-sdk/conversation-runtime";
|
||||
import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
|
||||
import {
|
||||
dispatchPluginInteractiveHandler,
|
||||
type PluginInteractiveDiscordHandlerContext,
|
||||
} from "openclaw/plugin-sdk/plugin-runtime";
|
||||
import { resolveChunkMode, resolveTextChunkLimit } from "openclaw/plugin-sdk/reply-runtime";
|
||||
import { finalizeInboundContext } from "openclaw/plugin-sdk/reply-runtime";
|
||||
import { dispatchReplyWithBufferedBlockDispatcher } from "openclaw/plugin-sdk/reply-runtime";
|
||||
import { createReplyReferencePlanner } from "openclaw/plugin-sdk/reply-runtime";
|
||||
import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
|
||||
import { createNonExitingRuntime, type RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
|
||||
import { logDebug, logError } from "openclaw/plugin-sdk/text-runtime";
|
||||
@@ -59,7 +47,6 @@ import {
|
||||
type DiscordComponentEntry,
|
||||
type DiscordModalEntry,
|
||||
} from "../components.js";
|
||||
import { editDiscordComponentMessage } from "../send.components.js";
|
||||
import {
|
||||
AGENT_BUTTON_KEY,
|
||||
AGENT_SELECT_KEY,
|
||||
@@ -102,7 +89,47 @@ import {
|
||||
} from "./inbound-context.js";
|
||||
import { buildDirectLabel, buildGuildLabel } from "./reply-context.js";
|
||||
import { deliverDiscordReply } from "./reply-delivery.js";
|
||||
import { sendTyping } from "./typing.js";
|
||||
|
||||
let conversationRuntimePromise:
|
||||
| Promise<typeof import("openclaw/plugin-sdk/conversation-runtime")>
|
||||
| undefined;
|
||||
let pluginRuntimePromise: Promise<typeof import("openclaw/plugin-sdk/plugin-runtime")> | undefined;
|
||||
let replyRuntimePromise: Promise<typeof import("openclaw/plugin-sdk/reply-runtime")> | undefined;
|
||||
let replyPipelineRuntimePromise:
|
||||
| Promise<typeof import("openclaw/plugin-sdk/channel-reply-pipeline")>
|
||||
| undefined;
|
||||
let sendComponentsRuntimePromise: Promise<typeof import("../send.components.js")> | undefined;
|
||||
let typingRuntimePromise: Promise<typeof import("./typing.js")> | undefined;
|
||||
|
||||
async function loadConversationRuntime() {
|
||||
conversationRuntimePromise ??= import("openclaw/plugin-sdk/conversation-runtime");
|
||||
return await conversationRuntimePromise;
|
||||
}
|
||||
|
||||
async function loadPluginRuntime() {
|
||||
pluginRuntimePromise ??= import("openclaw/plugin-sdk/plugin-runtime");
|
||||
return await pluginRuntimePromise;
|
||||
}
|
||||
|
||||
async function loadReplyRuntime() {
|
||||
replyRuntimePromise ??= import("openclaw/plugin-sdk/reply-runtime");
|
||||
return await replyRuntimePromise;
|
||||
}
|
||||
|
||||
async function loadReplyPipelineRuntime() {
|
||||
replyPipelineRuntimePromise ??= import("openclaw/plugin-sdk/channel-reply-pipeline");
|
||||
return await replyPipelineRuntimePromise;
|
||||
}
|
||||
|
||||
async function loadSendComponentsRuntime() {
|
||||
sendComponentsRuntimePromise ??= import("../send.components.js");
|
||||
return await sendComponentsRuntimePromise;
|
||||
}
|
||||
|
||||
async function loadTypingRuntime() {
|
||||
typingRuntimePromise ??= import("./typing.js");
|
||||
return await typingRuntimePromise;
|
||||
}
|
||||
|
||||
function resolveComponentGroupPolicy(
|
||||
ctx: AgentComponentContext,
|
||||
@@ -218,8 +245,14 @@ async function dispatchPluginDiscordInteractiveEvent(params: {
|
||||
});
|
||||
},
|
||||
};
|
||||
const pluginBindingApproval = parsePluginBindingApprovalCustomId(params.data);
|
||||
const conversationRuntime = await loadConversationRuntime();
|
||||
const pluginBindingApproval = conversationRuntime.parsePluginBindingApprovalCustomId(params.data);
|
||||
if (pluginBindingApproval) {
|
||||
const { buildPluginBindingResolvedText, resolvePluginConversationBindingApproval } =
|
||||
conversationRuntime;
|
||||
if (!pluginBindingApproval) {
|
||||
return "unmatched";
|
||||
}
|
||||
try {
|
||||
await respond.acknowledge();
|
||||
} catch {
|
||||
@@ -233,6 +266,7 @@ async function dispatchPluginDiscordInteractiveEvent(params: {
|
||||
const approvalMessageId = params.messageId?.trim() || params.interaction.message?.id?.trim();
|
||||
if (approvalMessageId) {
|
||||
try {
|
||||
const { editDiscordComponentMessage } = await loadSendComponentsRuntime();
|
||||
await editDiscordComponentMessage(
|
||||
normalizedConversationId,
|
||||
approvalMessageId,
|
||||
@@ -259,6 +293,7 @@ async function dispatchPluginDiscordInteractiveEvent(params: {
|
||||
}
|
||||
return "handled";
|
||||
}
|
||||
const { dispatchPluginInteractiveHandler } = await loadPluginRuntime();
|
||||
const dispatched = await dispatchPluginInteractiveHandler({
|
||||
channel: "discord",
|
||||
data: params.data,
|
||||
@@ -398,6 +433,22 @@ async function dispatchDiscordComponentEvent(params: {
|
||||
envelope: envelopeOptions,
|
||||
});
|
||||
|
||||
const {
|
||||
createReplyReferencePlanner,
|
||||
dispatchReplyWithBufferedBlockDispatcher,
|
||||
finalizeInboundContext,
|
||||
resolveChunkMode,
|
||||
resolveTextChunkLimit,
|
||||
recordInboundSession,
|
||||
} = await (async () => {
|
||||
const replyRuntime = await loadReplyRuntime();
|
||||
const conversationRuntime = await loadConversationRuntime();
|
||||
return {
|
||||
...replyRuntime,
|
||||
recordInboundSession: conversationRuntime.recordInboundSession,
|
||||
};
|
||||
})();
|
||||
|
||||
const ctxPayload = finalizeInboundContext({
|
||||
Body: combinedBody,
|
||||
BodyForAgent: eventText,
|
||||
@@ -463,6 +514,7 @@ async function dispatchDiscordComponentEvent(params: {
|
||||
|
||||
const deliverTarget = `channel:${interactionCtx.channelId}`;
|
||||
const typingChannelId = interactionCtx.channelId;
|
||||
const { createChannelReplyPipeline } = await loadReplyPipelineRuntime();
|
||||
const { onModelSelected, ...replyPipeline } = createChannelReplyPipeline({
|
||||
cfg: ctx.cfg,
|
||||
agentId,
|
||||
@@ -519,6 +571,7 @@ async function dispatchDiscordComponentEvent(params: {
|
||||
},
|
||||
onReplyStart: async () => {
|
||||
try {
|
||||
const { sendTyping } = await loadTypingRuntime();
|
||||
await sendTyping({ client: interaction.client, channelId: typingChannelId });
|
||||
} catch (err) {
|
||||
logVerbose(`discord: typing failed for component reply: ${String(err)}`);
|
||||
|
||||
@@ -16,7 +16,7 @@ import { createChannelReplyPipeline } from "openclaw/plugin-sdk/channel-reply-pi
|
||||
import {
|
||||
resolveCommandAuthorizedFromAuthorizers,
|
||||
resolveNativeCommandSessionTargets,
|
||||
} from "openclaw/plugin-sdk/command-auth";
|
||||
} from "openclaw/plugin-sdk/command-auth-native";
|
||||
import {
|
||||
buildCommandTextFromArgs,
|
||||
findCommandByNativeName,
|
||||
@@ -30,10 +30,10 @@ import {
|
||||
type CommandArgValues,
|
||||
type CommandArgs,
|
||||
type NativeCommandSpec,
|
||||
} from "openclaw/plugin-sdk/command-auth";
|
||||
} from "openclaw/plugin-sdk/native-command-registry";
|
||||
import type { OpenClawConfig, loadConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { resolveOpenProviderRuntimeGroupPolicy } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/dangerous-name-runtime";
|
||||
import { resolveOpenProviderRuntimeGroupPolicy } from "openclaw/plugin-sdk/runtime-group-policy";
|
||||
import { buildPairingReply } from "openclaw/plugin-sdk/conversation-runtime";
|
||||
import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
|
||||
import * as pluginRuntime from "openclaw/plugin-sdk/plugin-runtime";
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
resolveOpenProviderRuntimeGroupPolicy,
|
||||
resolveDefaultGroupPolicy,
|
||||
warnMissingProviderGroupPolicyFallbackOnce,
|
||||
} from "openclaw/plugin-sdk/config-runtime";
|
||||
} from "openclaw/plugin-sdk/runtime-group-policy";
|
||||
import { createConnectedChannelStatusPatch } from "openclaw/plugin-sdk/gateway-runtime";
|
||||
import { getPluginCommandSpecs } from "openclaw/plugin-sdk/plugin-runtime";
|
||||
import { resolveTextChunkLimit } from "openclaw/plugin-sdk/reply-runtime";
|
||||
|
||||
16
package.json
16
package.json
@@ -139,6 +139,10 @@
|
||||
"types": "./dist/plugin-sdk/runtime-config-snapshot.d.ts",
|
||||
"default": "./dist/plugin-sdk/runtime-config-snapshot.js"
|
||||
},
|
||||
"./plugin-sdk/runtime-group-policy": {
|
||||
"types": "./dist/plugin-sdk/runtime-group-policy.d.ts",
|
||||
"default": "./dist/plugin-sdk/runtime-group-policy.js"
|
||||
},
|
||||
"./plugin-sdk/ssrf-runtime": {
|
||||
"types": "./dist/plugin-sdk/ssrf-runtime.d.ts",
|
||||
"default": "./dist/plugin-sdk/ssrf-runtime.js"
|
||||
@@ -315,6 +319,10 @@
|
||||
"types": "./dist/plugin-sdk/boolean-param.d.ts",
|
||||
"default": "./dist/plugin-sdk/boolean-param.js"
|
||||
},
|
||||
"./plugin-sdk/dangerous-name-runtime": {
|
||||
"types": "./dist/plugin-sdk/dangerous-name-runtime.d.ts",
|
||||
"default": "./dist/plugin-sdk/dangerous-name-runtime.js"
|
||||
},
|
||||
"./plugin-sdk/cloudflare-ai-gateway": {
|
||||
"types": "./dist/plugin-sdk/cloudflare-ai-gateway.d.ts",
|
||||
"default": "./dist/plugin-sdk/cloudflare-ai-gateway.js"
|
||||
@@ -691,6 +699,10 @@
|
||||
"types": "./dist/plugin-sdk/models-provider-runtime.d.ts",
|
||||
"default": "./dist/plugin-sdk/models-provider-runtime.js"
|
||||
},
|
||||
"./plugin-sdk/native-command-registry": {
|
||||
"types": "./dist/plugin-sdk/native-command-registry.d.ts",
|
||||
"default": "./dist/plugin-sdk/native-command-registry.js"
|
||||
},
|
||||
"./plugin-sdk/nextcloud-talk": {
|
||||
"types": "./dist/plugin-sdk/nextcloud-talk.d.ts",
|
||||
"default": "./dist/plugin-sdk/nextcloud-talk.js"
|
||||
@@ -867,6 +879,10 @@
|
||||
"types": "./dist/plugin-sdk/sglang.d.ts",
|
||||
"default": "./dist/plugin-sdk/sglang.js"
|
||||
},
|
||||
"./plugin-sdk/session-store-runtime": {
|
||||
"types": "./dist/plugin-sdk/session-store-runtime.d.ts",
|
||||
"default": "./dist/plugin-sdk/session-store-runtime.js"
|
||||
},
|
||||
"./plugin-sdk/state-paths": {
|
||||
"types": "./dist/plugin-sdk/state-paths.d.ts",
|
||||
"default": "./dist/plugin-sdk/state-paths.js"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"outbound-runtime",
|
||||
"infra-runtime",
|
||||
"runtime-config-snapshot",
|
||||
"runtime-group-policy",
|
||||
"ssrf-runtime",
|
||||
"media-runtime",
|
||||
"media-understanding-runtime",
|
||||
@@ -68,6 +69,7 @@
|
||||
"browser-runtime",
|
||||
"browser-support",
|
||||
"boolean-param",
|
||||
"dangerous-name-runtime",
|
||||
"cloudflare-ai-gateway",
|
||||
"byteplus",
|
||||
"chutes",
|
||||
@@ -162,6 +164,7 @@
|
||||
"mistral",
|
||||
"msteams",
|
||||
"models-provider-runtime",
|
||||
"native-command-registry",
|
||||
"nextcloud-talk",
|
||||
"nvidia",
|
||||
"nostr",
|
||||
@@ -206,6 +209,7 @@
|
||||
"status-helpers",
|
||||
"speech",
|
||||
"sglang",
|
||||
"session-store-runtime",
|
||||
"state-paths",
|
||||
"synthetic",
|
||||
"telegram-account",
|
||||
|
||||
4
src/plugin-sdk/dangerous-name-runtime.ts
Normal file
4
src/plugin-sdk/dangerous-name-runtime.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export {
|
||||
isDangerousNameMatchingEnabled,
|
||||
resolveDangerousNameMatchingEnabled,
|
||||
} from "../config/dangerous-name-matching.js";
|
||||
17
src/plugin-sdk/native-command-registry.ts
Normal file
17
src/plugin-sdk/native-command-registry.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export {
|
||||
buildCommandTextFromArgs,
|
||||
findCommandByNativeName,
|
||||
listChatCommands,
|
||||
listNativeCommandSpecsForConfig,
|
||||
parseCommandArgs,
|
||||
resolveCommandArgChoices,
|
||||
resolveCommandArgMenu,
|
||||
serializeCommandArgs,
|
||||
} from "../auto-reply/commands-registry.js";
|
||||
export type {
|
||||
ChatCommandDefinition,
|
||||
CommandArgDefinition,
|
||||
CommandArgValues,
|
||||
CommandArgs,
|
||||
NativeCommandSpec,
|
||||
} from "../auto-reply/commands-registry.js";
|
||||
7
src/plugin-sdk/runtime-group-policy.ts
Normal file
7
src/plugin-sdk/runtime-group-policy.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export {
|
||||
GROUP_POLICY_BLOCKED_LABEL,
|
||||
resolveAllowlistProviderRuntimeGroupPolicy,
|
||||
resolveDefaultGroupPolicy,
|
||||
resolveOpenProviderRuntimeGroupPolicy,
|
||||
warnMissingProviderGroupPolicyFallbackOnce,
|
||||
} from "../config/runtime-group-policy.js";
|
||||
4
src/plugin-sdk/session-store-runtime.ts
Normal file
4
src/plugin-sdk/session-store-runtime.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export {
|
||||
readSessionUpdatedAt,
|
||||
resolveStorePath,
|
||||
} from "../config/sessions.js";
|
||||
Reference in New Issue
Block a user