mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-25 23:47:20 +00:00
refactor: finish remaining status helper dedupe
This commit is contained in:
@@ -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