refactor: dedupe bluebubbles status record helper

This commit is contained in:
Peter Steinberger
2026-04-06 22:52:56 +01:00
parent 0b7f6fa9d0
commit 29163a8caa

View File

@@ -1,4 +1,5 @@
import { collectIssuesForEnabledAccounts } from "openclaw/plugin-sdk/status-helpers";
import { asRecord } from "./monitor-normalize.js";
import type { ChannelAccountSnapshot } from "./runtime-api.js";
type BlueBubblesAccountStatus = {
@@ -17,10 +18,6 @@ type BlueBubblesProbeResult = {
error?: string | null;
};
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null;
}
function asString(value: unknown): string | null {
return typeof value === "string" && value.length > 0 ? value : null;
}
@@ -28,28 +25,30 @@ function asString(value: unknown): string | null {
function readBlueBubblesAccountStatus(
value: ChannelAccountSnapshot,
): BlueBubblesAccountStatus | null {
if (!isRecord(value)) {
const record = asRecord(value);
if (!record) {
return null;
}
return {
accountId: value.accountId,
enabled: value.enabled,
configured: value.configured,
running: value.running,
baseUrl: value.baseUrl,
lastError: value.lastError,
probe: value.probe,
accountId: record.accountId,
enabled: record.enabled,
configured: record.configured,
running: record.running,
baseUrl: record.baseUrl,
lastError: record.lastError,
probe: record.probe,
};
}
function readBlueBubblesProbeResult(value: unknown): BlueBubblesProbeResult | null {
if (!isRecord(value)) {
const record = asRecord(value);
if (!record) {
return null;
}
return {
ok: typeof value.ok === "boolean" ? value.ok : undefined,
status: typeof value.status === "number" ? value.status : null,
error: asString(value.error) ?? null,
ok: typeof record.ok === "boolean" ? record.ok : undefined,
status: typeof record.status === "number" ? record.status : null,
error: asString(record.error) ?? null,
};
}