refactor(status): reuse plugin-sdk status helpers

This commit is contained in:
Peter Steinberger
2026-02-15 19:35:58 +00:00
parent bdfa2b490b
commit 342e9cac03
4 changed files with 22 additions and 76 deletions

View File

@@ -1,5 +1,10 @@
import type { ChannelMeta, ChannelPlugin, ClawdbotConfig } from "openclaw/plugin-sdk"; import type { ChannelMeta, ChannelPlugin, ClawdbotConfig } from "openclaw/plugin-sdk";
import { DEFAULT_ACCOUNT_ID, PAIRING_APPROVED_MESSAGE } from "openclaw/plugin-sdk"; import {
buildBaseChannelStatusSummary,
createDefaultChannelRuntimeState,
DEFAULT_ACCOUNT_ID,
PAIRING_APPROVED_MESSAGE,
} from "openclaw/plugin-sdk";
import type { ResolvedFeishuAccount, FeishuConfig } from "./types.js"; import type { ResolvedFeishuAccount, FeishuConfig } from "./types.js";
import { import {
resolveFeishuAccount, resolveFeishuAccount,
@@ -303,20 +308,9 @@ export const feishuPlugin: ChannelPlugin<ResolvedFeishuAccount> = {
}, },
outbound: feishuOutbound, outbound: feishuOutbound,
status: { status: {
defaultRuntime: { defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID, { port: null }),
accountId: DEFAULT_ACCOUNT_ID,
running: false,
lastStartAt: null,
lastStopAt: null,
lastError: null,
port: null,
},
buildChannelSummary: ({ snapshot }) => ({ buildChannelSummary: ({ snapshot }) => ({
configured: snapshot.configured ?? false, ...buildBaseChannelStatusSummary(snapshot),
running: snapshot.running ?? false,
lastStartAt: snapshot.lastStartAt ?? null,
lastStopAt: snapshot.lastStopAt ?? null,
lastError: snapshot.lastError ?? null,
port: snapshot.port ?? null, port: snapshot.port ?? null,
probe: snapshot.probe, probe: snapshot.probe,
lastProbeAt: snapshot.lastProbeAt ?? null, lastProbeAt: snapshot.lastProbeAt ?? null,

View File

@@ -1,6 +1,8 @@
import type { ChannelMessageActionName, ChannelPlugin, OpenClawConfig } from "openclaw/plugin-sdk"; import type { ChannelMessageActionName, ChannelPlugin, OpenClawConfig } from "openclaw/plugin-sdk";
import { import {
buildBaseChannelStatusSummary,
buildChannelConfigSchema, buildChannelConfigSchema,
createDefaultChannelRuntimeState,
DEFAULT_ACCOUNT_ID, DEFAULT_ACCOUNT_ID,
MSTeamsConfigSchema, MSTeamsConfigSchema,
PAIRING_APPROVED_MESSAGE, PAIRING_APPROVED_MESSAGE,
@@ -415,20 +417,9 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount> = {
}, },
outbound: msteamsOutbound, outbound: msteamsOutbound,
status: { status: {
defaultRuntime: { defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID, { port: null }),
accountId: DEFAULT_ACCOUNT_ID,
running: false,
lastStartAt: null,
lastStopAt: null,
lastError: null,
port: null,
},
buildChannelSummary: ({ snapshot }) => ({ buildChannelSummary: ({ snapshot }) => ({
configured: snapshot.configured ?? false, ...buildBaseChannelStatusSummary(snapshot),
running: snapshot.running ?? false,
lastStartAt: snapshot.lastStartAt ?? null,
lastStopAt: snapshot.lastStopAt ?? null,
lastError: snapshot.lastError ?? null,
port: snapshot.port ?? null, port: snapshot.port ?? null,
probe: snapshot.probe, probe: snapshot.probe,
lastProbeAt: snapshot.lastProbeAt ?? null, lastProbeAt: snapshot.lastProbeAt ?? null,

View File

@@ -1,5 +1,7 @@
import { import {
buildChannelConfigSchema, buildChannelConfigSchema,
collectStatusIssuesFromLastError,
createDefaultChannelRuntimeState,
DEFAULT_ACCOUNT_ID, DEFAULT_ACCOUNT_ID,
formatPairingApproveHint, formatPairingApproveHint,
type ChannelPlugin, type ChannelPlugin,
@@ -157,28 +159,8 @@ export const nostrPlugin: ChannelPlugin<ResolvedNostrAccount> = {
}, },
status: { status: {
defaultRuntime: { defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
accountId: DEFAULT_ACCOUNT_ID, collectStatusIssues: (accounts) => collectStatusIssuesFromLastError("nostr", accounts),
running: false,
lastStartAt: null,
lastStopAt: null,
lastError: null,
},
collectStatusIssues: (accounts) =>
accounts.flatMap((account) => {
const lastError = typeof account.lastError === "string" ? account.lastError.trim() : "";
if (!lastError) {
return [];
}
return [
{
channel: "nostr",
accountId: account.accountId,
kind: "runtime" as const,
message: `Channel error: ${lastError}`,
},
];
}),
buildChannelSummary: ({ snapshot }) => ({ buildChannelSummary: ({ snapshot }) => ({
configured: snapshot.configured ?? false, configured: snapshot.configured ?? false,
publicKey: snapshot.publicKey ?? null, publicKey: snapshot.publicKey ?? null,

View File

@@ -1,6 +1,9 @@
import { import {
applyAccountNameToChannelSection, applyAccountNameToChannelSection,
buildBaseChannelStatusSummary,
buildChannelConfigSchema, buildChannelConfigSchema,
collectStatusIssuesFromLastError,
createDefaultChannelRuntimeState,
DEFAULT_ACCOUNT_ID, DEFAULT_ACCOUNT_ID,
deleteAccountFromConfigSection, deleteAccountFromConfigSection,
formatPairingApproveHint, formatPairingApproveHint,
@@ -249,35 +252,11 @@ export const signalPlugin: ChannelPlugin<ResolvedSignalAccount> = {
}, },
}, },
status: { status: {
defaultRuntime: { defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
accountId: DEFAULT_ACCOUNT_ID, collectStatusIssues: (accounts) => collectStatusIssuesFromLastError("signal", accounts),
running: false,
lastStartAt: null,
lastStopAt: null,
lastError: null,
},
collectStatusIssues: (accounts) =>
accounts.flatMap((account) => {
const lastError = typeof account.lastError === "string" ? account.lastError.trim() : "";
if (!lastError) {
return [];
}
return [
{
channel: "signal",
accountId: account.accountId,
kind: "runtime",
message: `Channel error: ${lastError}`,
},
];
}),
buildChannelSummary: ({ snapshot }) => ({ buildChannelSummary: ({ snapshot }) => ({
configured: snapshot.configured ?? false, ...buildBaseChannelStatusSummary(snapshot),
baseUrl: snapshot.baseUrl ?? null, baseUrl: snapshot.baseUrl ?? null,
running: snapshot.running ?? false,
lastStartAt: snapshot.lastStartAt ?? null,
lastStopAt: snapshot.lastStopAt ?? null,
lastError: snapshot.lastError ?? null,
probe: snapshot.probe, probe: snapshot.probe,
lastProbeAt: snapshot.lastProbeAt ?? null, lastProbeAt: snapshot.lastProbeAt ?? null,
}), }),