refactor: share more computed channel status adapters

This commit is contained in:
Peter Steinberger 2026-03-22 23:23:35 +00:00
parent 72bfaf6ee2
commit d9a2666ee1
4 changed files with 58 additions and 61 deletions

View File

@ -21,12 +21,12 @@ import {
} from "openclaw/plugin-sdk/directory-runtime";
import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
import { createRuntimeOutboundDelegates } from "openclaw/plugin-sdk/outbound-runtime";
import { createComputedAccountStatusAdapter } from "openclaw/plugin-sdk/status-helpers";
import type { ChannelMeta, ChannelPlugin, ClawdbotConfig } from "../runtime-api.js";
import {
buildChannelConfigSchema,
buildProbeChannelStatusSummary,
createActionGate,
buildRuntimeAccountStatusSnapshot,
createDefaultChannelRuntimeState,
DEFAULT_ACCOUNT_ID,
PAIRING_APPROVED_MESSAGE,
@ -924,7 +924,7 @@ export const feishuPlugin: ChannelPlugin<ResolvedFeishuAccount, FeishuProbeResul
}),
}),
}),
status: {
status: createComputedAccountStatusAdapter<ResolvedFeishuAccount, FeishuProbeResult>({
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID, { port: null }),
buildChannelSummary: ({ snapshot }) =>
buildProbeChannelStatusSummary(snapshot, {
@ -932,20 +932,18 @@ export const feishuPlugin: ChannelPlugin<ResolvedFeishuAccount, FeishuProbeResul
}),
probeAccount: async ({ account }) =>
await (await loadFeishuChannelRuntime()).probeFeishu(account),
buildAccountSnapshot: ({ account, runtime, probe }) =>
buildRuntimeAccountStatusSnapshot(
{ runtime, probe },
{
accountId: account.accountId,
enabled: account.enabled,
configured: account.configured,
name: account.name,
appId: account.appId,
domain: account.domain,
port: runtime?.port ?? null,
},
),
},
resolveAccountSnapshot: ({ account, runtime }) => ({
accountId: account.accountId,
enabled: account.enabled,
configured: account.configured,
name: account.name,
extra: {
appId: account.appId,
domain: account.domain,
port: runtime?.port ?? null,
},
}),
}),
gateway: {
startAccount: async (ctx) => {
const { monitorFeishuProvider } = await import("./monitor.js");

View File

@ -16,7 +16,10 @@ import {
listResolvedDirectoryEntriesFromSources,
} from "openclaw/plugin-sdk/directory-runtime";
import { runStoppablePassiveMonitor } from "openclaw/plugin-sdk/extension-shared";
import { createDefaultChannelRuntimeState } from "openclaw/plugin-sdk/status-helpers";
import {
createComputedAccountStatusAdapter,
createDefaultChannelRuntimeState,
} from "openclaw/plugin-sdk/status-helpers";
import {
listIrcAccountIds,
resolveDefaultIrcAccountId,
@ -34,7 +37,6 @@ import {
import { resolveIrcGroupMatch, resolveIrcRequireMention } from "./policy.js";
import { probeIrc } from "./probe.js";
import {
buildBaseAccountStatusSnapshot,
buildBaseChannelStatusSummary,
buildChannelConfigSchema,
createAccountStatusSink,
@ -253,7 +255,7 @@ export const ircPlugin: ChannelPlugin<ResolvedIrcAccount, IrcProbe> = createChat
return entries.map((entry) => ({ ...entry, name: entry.id }));
},
}),
status: {
status: createComputedAccountStatusAdapter<ResolvedIrcAccount, IrcProbe>({
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
buildChannelSummary: ({ account, snapshot }) => ({
...buildBaseChannelStatusSummary(snapshot),
@ -266,18 +268,20 @@ export const ircPlugin: ChannelPlugin<ResolvedIrcAccount, IrcProbe> = createChat
}),
probeAccount: async ({ cfg, account, timeoutMs }) =>
probeIrc(cfg as CoreConfig, { accountId: account.accountId, timeoutMs }),
buildAccountSnapshot: ({ account, runtime, probe }) =>
buildBaseAccountStatusSnapshot(
{ account, runtime, probe },
{
host: account.host,
port: account.port,
tls: account.tls,
nick: account.nick,
passwordSource: account.passwordSource,
},
),
},
resolveAccountSnapshot: ({ account }) => ({
accountId: account.accountId,
name: account.name,
enabled: account.enabled,
configured: account.configured,
extra: {
host: account.host,
port: account.port,
tls: account.tls,
nick: account.nick,
passwordSource: account.passwordSource,
},
}),
}),
gateway: {
startAccount: async (ctx) => {
const account = ctx.account;

View File

@ -19,10 +19,10 @@ import {
} from "openclaw/plugin-sdk/directory-runtime";
import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
import { createRuntimeOutboundDelegates } from "openclaw/plugin-sdk/outbound-runtime";
import { createComputedAccountStatusAdapter } from "openclaw/plugin-sdk/status-helpers";
import type { ChannelMessageActionName, ChannelPlugin, OpenClawConfig } from "../runtime-api.js";
import {
buildProbeChannelStatusSummary,
buildRuntimeAccountStatusSnapshot,
buildChannelConfigSchema,
createDefaultChannelRuntimeState,
DEFAULT_ACCOUNT_ID,
@ -409,7 +409,7 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsRe
return null as never;
},
},
status: {
status: createComputedAccountStatusAdapter<ResolvedMSTeamsAccount, ProbeMSTeamsResult>({
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID, { port: null }),
buildChannelSummary: ({ snapshot }) =>
buildProbeChannelStatusSummary(snapshot, {
@ -451,17 +451,15 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsRe
}
return lines;
},
buildAccountSnapshot: ({ account, runtime, probe }) =>
buildRuntimeAccountStatusSnapshot(
{ runtime, probe },
{
accountId: account.accountId,
enabled: account.enabled,
configured: account.configured,
port: runtime?.port ?? null,
},
),
},
resolveAccountSnapshot: ({ account, runtime }) => ({
accountId: account.accountId,
enabled: account.enabled,
configured: account.configured,
extra: {
port: runtime?.port ?? null,
},
}),
}),
gateway: {
startAccount: async (ctx) => {
const { monitorMSTeamsProvider } = await import("./index.js");

View File

@ -19,7 +19,10 @@ import { createChatChannelPlugin } from "openclaw/plugin-sdk/core";
import { createChannelDirectoryAdapter } from "openclaw/plugin-sdk/directory-runtime";
import { listResolvedDirectoryUserEntriesFromAllowFrom } from "openclaw/plugin-sdk/directory-runtime";
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
import { createDefaultChannelRuntimeState } from "openclaw/plugin-sdk/status-helpers";
import {
createComputedAccountStatusAdapter,
createDefaultChannelRuntimeState,
} from "openclaw/plugin-sdk/status-helpers";
import {
listZaloAccountIds,
resolveDefaultZaloAccountId,
@ -30,7 +33,6 @@ import { zaloMessageActions } from "./actions.js";
import { ZaloConfigSchema } from "./config-schema.js";
import type { ZaloProbeResult } from "./probe.js";
import {
buildBaseAccountStatusSnapshot,
buildChannelConfigSchema,
buildTokenChannelStatusSummary,
DEFAULT_ACCOUNT_ID,
@ -200,32 +202,27 @@ export const zaloPlugin: ChannelPlugin<ResolvedZaloAccount, ZaloProbeResult> =
}),
listGroups: async () => [],
}),
status: {
status: createComputedAccountStatusAdapter<ResolvedZaloAccount, ZaloProbeResult>({
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
collectStatusIssues: collectZaloStatusIssues,
buildChannelSummary: ({ snapshot }) => buildTokenChannelStatusSummary(snapshot),
probeAccount: async ({ account, timeoutMs }) =>
await (await loadZaloChannelRuntime()).probeZaloAccount({ account, timeoutMs }),
buildAccountSnapshot: ({ account, runtime }) => {
resolveAccountSnapshot: ({ account }) => {
const configured = Boolean(account.token?.trim());
return buildBaseAccountStatusSnapshot(
{
account: {
accountId: account.accountId,
name: account.name,
enabled: account.enabled,
configured,
},
runtime,
},
{
return {
accountId: account.accountId,
name: account.name,
enabled: account.enabled,
configured,
extra: {
tokenSource: account.tokenSource,
mode: account.config.webhookUrl ? "webhook" : "polling",
dmPolicy: account.config.dmPolicy ?? "pairing",
},
);
};
},
},
}),
gateway: {
startAccount: async (ctx) =>
await (await loadZaloChannelRuntime()).startZaloGatewayAccount(ctx),