mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 09:21:35 +07:00
refactor: finish remaining status helper dedupe
This commit is contained in:
@@ -207,18 +207,11 @@ export const nextcloudTalkPlugin: ChannelPlugin<ResolvedNextcloudTalkAccount> =
|
||||
lastStopAt: null,
|
||||
lastError: null,
|
||||
},
|
||||
buildChannelSummary: ({ snapshot }) => {
|
||||
const base = buildBaseChannelStatusSummary(snapshot);
|
||||
return {
|
||||
configured: base.configured,
|
||||
buildChannelSummary: ({ snapshot }) =>
|
||||
buildBaseChannelStatusSummary(snapshot, {
|
||||
secretSource: snapshot.secretSource ?? "none",
|
||||
running: base.running,
|
||||
mode: "webhook",
|
||||
lastStartAt: base.lastStartAt,
|
||||
lastStopAt: base.lastStopAt,
|
||||
lastError: base.lastError,
|
||||
};
|
||||
},
|
||||
}),
|
||||
buildAccountSnapshot: ({ account, runtime }) => {
|
||||
const configured = Boolean(account.secret?.trim() && account.baseUrl?.trim());
|
||||
return buildRuntimeAccountStatusSnapshot(
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
buildTrafficStatusSummary,
|
||||
} from "openclaw/plugin-sdk/extension-shared";
|
||||
import {
|
||||
buildComputedAccountStatusSnapshot,
|
||||
buildChannelConfigSchema,
|
||||
collectStatusIssuesFromLastError,
|
||||
createPreCryptoDirectDmAuthorizer,
|
||||
@@ -249,19 +250,21 @@ export const nostrPlugin: ChannelPlugin<ResolvedNostrAccount> = {
|
||||
buildPassiveChannelStatusSummary(snapshot, {
|
||||
publicKey: snapshot.publicKey ?? null,
|
||||
}),
|
||||
buildAccountSnapshot: ({ account, runtime }) => ({
|
||||
accountId: account.accountId,
|
||||
name: account.name,
|
||||
enabled: account.enabled,
|
||||
configured: account.configured,
|
||||
publicKey: account.publicKey,
|
||||
profile: account.profile,
|
||||
running: runtime?.running ?? false,
|
||||
lastStartAt: runtime?.lastStartAt ?? null,
|
||||
lastStopAt: runtime?.lastStopAt ?? null,
|
||||
lastError: runtime?.lastError ?? null,
|
||||
...buildTrafficStatusSummary(runtime),
|
||||
}),
|
||||
buildAccountSnapshot: ({ account, runtime }) =>
|
||||
buildComputedAccountStatusSnapshot(
|
||||
{
|
||||
accountId: account.accountId,
|
||||
name: account.name,
|
||||
enabled: account.enabled,
|
||||
configured: account.configured,
|
||||
runtime,
|
||||
},
|
||||
{
|
||||
publicKey: account.publicKey,
|
||||
profile: account.profile,
|
||||
...buildTrafficStatusSummary(runtime),
|
||||
},
|
||||
),
|
||||
},
|
||||
|
||||
gateway: {
|
||||
|
||||
@@ -369,12 +369,12 @@ export const signalPlugin: ChannelPlugin<ResolvedSignalAccount> = {
|
||||
status: {
|
||||
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
|
||||
collectStatusIssues: (accounts) => collectStatusIssuesFromLastError("signal", accounts),
|
||||
buildChannelSummary: ({ snapshot }) => ({
|
||||
...buildBaseChannelStatusSummary(snapshot),
|
||||
baseUrl: snapshot.baseUrl ?? null,
|
||||
probe: snapshot.probe,
|
||||
lastProbeAt: snapshot.lastProbeAt ?? null,
|
||||
}),
|
||||
buildChannelSummary: ({ snapshot }) =>
|
||||
buildBaseChannelStatusSummary(snapshot, {
|
||||
baseUrl: snapshot.baseUrl ?? null,
|
||||
probe: snapshot.probe,
|
||||
lastProbeAt: snapshot.lastProbeAt ?? null,
|
||||
}),
|
||||
probeAccount: async ({ account, timeoutMs }) => {
|
||||
const baseUrl = account.baseUrl;
|
||||
return await getSignalRuntime().channel.signal.probeSignal(baseUrl, timeoutMs);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
|
||||
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
|
||||
import { createHybridChannelConfigAdapter } from "openclaw/plugin-sdk/channel-config-helpers";
|
||||
import type { ChannelAccountSnapshot } from "openclaw/plugin-sdk/channel-contract";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import type { ChannelPlugin } from "openclaw/plugin-sdk/core";
|
||||
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
||||
import { createRuntimeOutboundDelegates } from "openclaw/plugin-sdk/outbound-runtime";
|
||||
import { buildComputedAccountStatusSnapshot } from "openclaw/plugin-sdk/tlon";
|
||||
import { tlonChannelConfigSchema } from "./config-schema.js";
|
||||
import { resolveTlonOutboundSessionRoute } from "./session-route.js";
|
||||
import {
|
||||
@@ -154,23 +154,21 @@ export const tlonPlugin: ChannelPlugin = {
|
||||
}
|
||||
return await (await loadTlonChannelRuntime()).probeTlonAccount(account as never);
|
||||
},
|
||||
buildAccountSnapshot: ({ account, runtime, probe }) => {
|
||||
// Tlon-specific snapshot with ship/url for status display
|
||||
const snapshot = {
|
||||
accountId: account.accountId,
|
||||
name: account.name,
|
||||
enabled: account.enabled,
|
||||
configured: account.configured,
|
||||
ship: account.ship,
|
||||
url: account.url,
|
||||
running: runtime?.running ?? false,
|
||||
lastStartAt: runtime?.lastStartAt ?? null,
|
||||
lastStopAt: runtime?.lastStopAt ?? null,
|
||||
lastError: runtime?.lastError ?? null,
|
||||
probe,
|
||||
};
|
||||
return snapshot as ChannelAccountSnapshot;
|
||||
},
|
||||
buildAccountSnapshot: ({ account, runtime, probe }) =>
|
||||
buildComputedAccountStatusSnapshot(
|
||||
{
|
||||
accountId: account.accountId,
|
||||
name: account.name,
|
||||
enabled: account.enabled,
|
||||
configured: account.configured,
|
||||
runtime,
|
||||
probe,
|
||||
},
|
||||
{
|
||||
ship: account.ship,
|
||||
url: account.url,
|
||||
},
|
||||
),
|
||||
},
|
||||
gateway: {
|
||||
startAccount: async (ctx) =>
|
||||
|
||||
@@ -27,6 +27,7 @@ export type { PluginRuntime } from "../plugins/runtime/types.js";
|
||||
export type { OpenClawPluginApi } from "../plugins/types.js";
|
||||
export { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js";
|
||||
export {
|
||||
buildComputedAccountStatusSnapshot,
|
||||
collectStatusIssuesFromLastError,
|
||||
createDefaultChannelRuntimeState,
|
||||
} from "./status-helpers.js";
|
||||
|
||||
@@ -66,6 +66,28 @@ describe("buildBaseChannelStatusSummary", () => {
|
||||
lastError: "boom",
|
||||
});
|
||||
});
|
||||
|
||||
it("merges extra fields into the normalized channel summary", () => {
|
||||
expect(
|
||||
buildBaseChannelStatusSummary(
|
||||
{
|
||||
configured: true,
|
||||
},
|
||||
{
|
||||
mode: "webhook",
|
||||
secretSource: "env",
|
||||
},
|
||||
),
|
||||
).toEqual({
|
||||
configured: true,
|
||||
mode: "webhook",
|
||||
secretSource: "env",
|
||||
running: false,
|
||||
lastStartAt: null,
|
||||
lastStopAt: null,
|
||||
lastError: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildBaseAccountStatusSnapshot", () => {
|
||||
|
||||
@@ -41,15 +41,19 @@ export function createDefaultChannelRuntimeState<T extends Record<string, unknow
|
||||
}
|
||||
|
||||
/** Normalize a channel-level status summary so missing lifecycle fields become explicit nulls. */
|
||||
export function buildBaseChannelStatusSummary(snapshot: {
|
||||
configured?: boolean | null;
|
||||
running?: boolean | null;
|
||||
lastStartAt?: number | null;
|
||||
lastStopAt?: number | null;
|
||||
lastError?: string | null;
|
||||
}) {
|
||||
export function buildBaseChannelStatusSummary<TExtra extends StatusSnapshotExtra>(
|
||||
snapshot: {
|
||||
configured?: boolean | null;
|
||||
running?: boolean | null;
|
||||
lastStartAt?: number | null;
|
||||
lastStopAt?: number | null;
|
||||
lastError?: string | null;
|
||||
},
|
||||
extra?: TExtra,
|
||||
) {
|
||||
return {
|
||||
configured: snapshot.configured ?? false,
|
||||
...(extra ?? ({} as TExtra)),
|
||||
running: snapshot.running ?? false,
|
||||
lastStartAt: snapshot.lastStartAt ?? null,
|
||||
lastStopAt: snapshot.lastStopAt ?? null,
|
||||
@@ -71,8 +75,7 @@ export function buildProbeChannelStatusSummary<TExtra extends Record<string, unk
|
||||
extra?: TExtra,
|
||||
) {
|
||||
return {
|
||||
...buildBaseChannelStatusSummary(snapshot),
|
||||
...(extra ?? ({} as TExtra)),
|
||||
...buildBaseChannelStatusSummary(snapshot, extra),
|
||||
probe: snapshot.probe,
|
||||
lastProbeAt: snapshot.lastProbeAt ?? null,
|
||||
};
|
||||
|
||||
@@ -26,6 +26,7 @@ export type { PluginRuntime } from "../plugins/runtime/types.js";
|
||||
export type { OpenClawPluginApi } from "../plugins/types.js";
|
||||
export { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
||||
export type { RuntimeEnv } from "../runtime.js";
|
||||
export { buildComputedAccountStatusSnapshot } from "./status-helpers.js";
|
||||
export { formatDocsLink } from "../terminal/links.js";
|
||||
export type { WizardPrompter } from "../wizard/prompts.js";
|
||||
export { createLoggerBackedRuntime } from "./runtime.js";
|
||||
|
||||
Reference in New Issue
Block a user