perf: reduce plugin runtime startup overhead

This commit is contained in:
Peter Steinberger
2026-03-22 16:32:17 +00:00
parent bb16ab9e08
commit 3fa2300ba1
18 changed files with 309 additions and 172 deletions

View File

@@ -1,15 +1,28 @@
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
import {
listInspectedDirectoryEntriesFromSources,
listResolvedDirectoryEntriesFromSources,
type DirectoryConfigParams,
} from "openclaw/plugin-sdk/directory-runtime";
import { inspectDiscordAccount, type InspectedDiscordAccount } from "./account-inspect.js";
import { mergeDiscordAccountConfig, resolveDefaultDiscordAccountId } from "./accounts.js";
function resolveDiscordDirectoryConfigAccount(
cfg: DirectoryConfigParams["cfg"],
accountId?: string | null,
) {
const resolvedAccountId = normalizeAccountId(accountId ?? resolveDefaultDiscordAccountId(cfg));
const config = mergeDiscordAccountConfig(cfg, resolvedAccountId);
return {
accountId: resolvedAccountId,
config,
dm: config.dm,
};
}
export async function listDiscordDirectoryPeersFromConfig(params: DirectoryConfigParams) {
return listInspectedDirectoryEntriesFromSources({
return listResolvedDirectoryEntriesFromSources({
...params,
kind: "user",
inspectAccount: (cfg, accountId) =>
inspectDiscordAccount({ cfg, accountId }) as InspectedDiscordAccount | null,
resolveAccount: (cfg, accountId) => resolveDiscordDirectoryConfigAccount(cfg, accountId),
resolveSources: (account) => {
const allowFrom = account.config.allowFrom ?? account.config.dm?.allowFrom ?? [];
const guildUsers = Object.values(account.config.guilds ?? {}).flatMap((guild) => [
@@ -27,11 +40,10 @@ export async function listDiscordDirectoryPeersFromConfig(params: DirectoryConfi
}
export async function listDiscordDirectoryGroupsFromConfig(params: DirectoryConfigParams) {
return listInspectedDirectoryEntriesFromSources({
return listResolvedDirectoryEntriesFromSources({
...params,
kind: "group",
inspectAccount: (cfg, accountId) =>
inspectDiscordAccount({ cfg, accountId }) as InspectedDiscordAccount | null,
resolveAccount: (cfg, accountId) => resolveDiscordDirectoryConfigAccount(cfg, accountId),
resolveSources: (account) =>
Object.values(account.config.guilds ?? {}).map((guild) => Object.keys(guild.channels ?? {})),
normalizeId: (raw) => {

View File

@@ -4,7 +4,7 @@ export {
PAIRING_APPROVED_MESSAGE,
projectCredentialSnapshotFields,
resolveConfiguredFromCredentialStatuses,
} from "openclaw/plugin-sdk/discord";
} from "openclaw/plugin-sdk/channel-status";
export {
buildChannelConfigSchema,
getChatChannelMeta,

View File

@@ -5,10 +5,10 @@ import {
} from "openclaw/plugin-sdk/channel-contract";
import type { SlackActionContext } from "./action-runtime.js";
import { handleSlackAction } from "./action-runtime.js";
import { isSlackInteractiveRepliesEnabled } from "./interactive-replies.js";
import { handleSlackMessageAction } from "./message-action-dispatch.js";
import { extractSlackToolSend, listSlackMessageActions } from "./message-actions.js";
import { createSlackMessageToolBlocksSchema } from "./message-tool-schema.js";
import { isSlackInteractiveRepliesEnabled } from "./runtime-api.js";
import { resolveSlackChannelId } from "./targets.js";
type SlackActionInvoke = (

View File

@@ -1,16 +1,29 @@
import { normalizeAccountId } from "openclaw/plugin-sdk/account-resolution";
import {
listInspectedDirectoryEntriesFromSources,
listResolvedDirectoryEntriesFromSources,
type DirectoryConfigParams,
} from "openclaw/plugin-sdk/directory-runtime";
import { inspectSlackAccount, type InspectedSlackAccount } from "./account-inspect.js";
import { mergeSlackAccountConfig, resolveDefaultSlackAccountId } from "./accounts.js";
import { parseSlackTarget } from "./targets.js";
function resolveSlackDirectoryConfigAccount(
cfg: DirectoryConfigParams["cfg"],
accountId?: string | null,
) {
const resolvedAccountId = normalizeAccountId(accountId ?? resolveDefaultSlackAccountId(cfg));
const config = mergeSlackAccountConfig(cfg, resolvedAccountId);
return {
accountId: resolvedAccountId,
config,
dm: config.dm,
};
}
export async function listSlackDirectoryPeersFromConfig(params: DirectoryConfigParams) {
return listInspectedDirectoryEntriesFromSources({
return listResolvedDirectoryEntriesFromSources({
...params,
kind: "user",
inspectAccount: (cfg, accountId) =>
inspectSlackAccount({ cfg, accountId }) as InspectedSlackAccount | null,
resolveAccount: (cfg, accountId) => resolveSlackDirectoryConfigAccount(cfg, accountId),
resolveSources: (account) => {
const allowFrom = account.config.allowFrom ?? account.dm?.allowFrom ?? [];
const channelUsers = Object.values(account.config.channels ?? {}).flatMap(
@@ -32,11 +45,10 @@ export async function listSlackDirectoryPeersFromConfig(params: DirectoryConfigP
}
export async function listSlackDirectoryGroupsFromConfig(params: DirectoryConfigParams) {
return listInspectedDirectoryEntriesFromSources({
return listResolvedDirectoryEntriesFromSources({
...params,
kind: "group",
inspectAccount: (cfg, accountId) =>
inspectSlackAccount({ cfg, accountId }) as InspectedSlackAccount | null,
resolveAccount: (cfg, accountId) => resolveSlackDirectoryConfigAccount(cfg, accountId),
resolveSources: (account) => [Object.keys(account.config.channels ?? {})],
normalizeId: (raw) => {
const normalized = parseSlackTarget(raw, { defaultKind: "channel" });

View File

@@ -1,3 +1,4 @@
import { normalizeAccountId } from "openclaw/plugin-sdk/account-resolution";
import type { ChannelGroupContext } from "openclaw/plugin-sdk/channel-contract";
import {
resolveToolsBySender,
@@ -5,7 +6,7 @@ import {
type GroupToolPolicyConfig,
} from "openclaw/plugin-sdk/channel-policy";
import { normalizeHyphenSlug } from "openclaw/plugin-sdk/core";
import { inspectSlackAccount } from "./account-inspect.js";
import { mergeSlackAccountConfig, resolveDefaultSlackAccountId } from "./accounts.js";
type SlackChannelPolicyEntry = {
requireMention?: boolean;
@@ -16,12 +17,14 @@ type SlackChannelPolicyEntry = {
function resolveSlackChannelPolicyEntry(
params: ChannelGroupContext,
): SlackChannelPolicyEntry | undefined {
const account = inspectSlackAccount({
cfg: params.cfg,
accountId: params.accountId,
});
const channels = (account.channels ?? {}) as Record<string, SlackChannelPolicyEntry>;
if (Object.keys(channels).length === 0) {
const accountId = normalizeAccountId(
params.accountId ?? resolveDefaultSlackAccountId(params.cfg),
);
const channels = mergeSlackAccountConfig(params.cfg, accountId).channels as
| Record<string, SlackChannelPolicyEntry>
| undefined;
const channelMap = channels ?? {};
if (Object.keys(channelMap).length === 0) {
return undefined;
}
const channelId = params.groupId?.trim();
@@ -35,11 +38,11 @@ function resolveSlackChannelPolicyEntry(
normalizedName,
].filter(Boolean);
for (const candidate of candidates) {
if (candidate && channels[candidate]) {
return channels[candidate];
if (candidate && channelMap[candidate]) {
return channelMap[candidate];
}
}
return channels["*"];
return channelMap["*"];
}
function resolveSenderToolsEntry(

View File

@@ -1,9 +1,9 @@
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
import type { ChannelMessageActionContext } from "openclaw/plugin-sdk/channel-contract";
import { normalizeInteractiveReply } from "openclaw/plugin-sdk/interactive-runtime";
import { readNumberParam, readStringParam } from "openclaw/plugin-sdk/param-readers";
import { parseSlackBlocksInput } from "./blocks-input.js";
import { buildSlackInteractiveBlocks } from "./blocks-render.js";
import { readNumberParam, readStringParam } from "./runtime-api.js";
type SlackActionInvoke = (
action: Record<string, unknown>,

View File

@@ -1,19 +1,15 @@
export {
buildComputedAccountStatusSnapshot,
DEFAULT_ACCOUNT_ID,
looksLikeSlackTargetId,
normalizeSlackMessagingTarget,
PAIRING_APPROVED_MESSAGE,
projectCredentialSnapshotFields,
resolveConfiguredFromRequiredCredentialStatuses,
type ChannelPlugin,
type OpenClawConfig,
type SlackAccountConfig,
} from "openclaw/plugin-sdk/slack";
} from "openclaw/plugin-sdk/channel-status";
export { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
export {
listSlackDirectoryGroupsFromConfig,
listSlackDirectoryPeersFromConfig,
} from "./directory-config.js";
looksLikeSlackTargetId,
normalizeSlackMessagingTarget,
} from "openclaw/plugin-sdk/slack-targets";
export type { ChannelPlugin, OpenClawConfig, SlackAccountConfig } from "openclaw/plugin-sdk/slack";
export {
buildChannelConfigSchema,
getChatChannelMeta,
@@ -26,4 +22,3 @@ export {
SlackConfigSchema,
withNormalizedTimestamp,
} from "openclaw/plugin-sdk/slack-core";
export { isSlackInteractiveRepliesEnabled } from "./interactive-replies.js";