openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
75 lines (74 loc) • 2.78 kB
JavaScript
import { t as asBoolean } from "./boolean-2vRuVafy.mjs";
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs";
import { r as resolveChannelAccount } from "./account-resolution-D7u1J1M0.mjs";
import { r as hasConfiguredUnavailableCredentialStatus } from "./account-snapshot-fields-B0Zypjh2.mjs";
import { o as resolveChannelAccountConfigured, s as resolveChannelAccountEnabled } from "./account-summary-RVgW5Dlx.mjs";
import { t as inspectChannelAccount } from "./account-inspection-BR5sYFpp.mjs";
//#region src/gateway/health/account-context.ts
const PUBLIC_IMESSAGE_FULL_DISK_ACCESS_ERROR = "imsg cannot access ~/Library/Messages/chat.db. Grant Full Disk Access to the Gateway/launcher process and restart Gateway.";
function buildNonSensitiveProbeFailure(e, t) {
const n = asNullableRecord(t);
if (e !== "imessage" || !n || n.ok !== false) return;
if (typeof n.error !== "string") return;
const r = n.error.trim().replaceAll(/\/Users\/[^/\s]+\/Library\/Messages\/chat\.db/g, "~/Library/Messages/chat.db");
if (!/\bimsg\b/i.test(r) || !r.includes("~/Library/Messages/chat.db") || !/\bFull Disk Access\b/i.test(r)) return;
return {
ok: false,
error: PUBLIC_IMESSAGE_FULL_DISK_ACCESS_ERROR
};
}
async function resolveHealthAccountContext(e) {
const t = [];
let n;
try {
n = await inspectChannelAccount(e);
} catch (n) {
t.push(`${e.plugin.id}:${e.accountId}: failed to inspect account (${formatErrorMessage(n)}).`);
}
const r = asNullableRecord(n);
const i = asBoolean(r?.enabled);
const a = asBoolean(r?.configured);
let o;
if (i !== false && !hasConfiguredUnavailableCredentialStatus(n)) try {
o = await resolveChannelAccount(e);
} catch (n) {
t.push(`${e.plugin.id}:${e.accountId}: failed to resolve account (${formatErrorMessage(n)}).`);
}
if (o === null || o === void 0) return {
probeAccount: void 0,
inspectedAccount: n,
enabled: i ?? false,
configured: a,
diagnostics: t
};
let s = asBoolean(asNullableRecord(o)?.enabled) ?? true;
try {
s = resolveChannelAccountEnabled({
plugin: e.plugin,
account: o,
cfg: e.cfg
});
} catch (n) {
t.push(`${e.plugin.id}:${e.accountId}: failed to evaluate enabled state (${formatErrorMessage(n)}).`);
}
let c = asBoolean(asNullableRecord(o)?.configured) ?? true;
try {
c = await resolveChannelAccountConfigured({
plugin: e.plugin,
account: o,
cfg: e.cfg
});
} catch (n) {
t.push(`${e.plugin.id}:${e.accountId}: failed to evaluate configured state (${formatErrorMessage(n)}).`);
}
return {
probeAccount: o,
inspectedAccount: n,
enabled: s,
configured: c,
diagnostics: t
};
}
//#endregion
export { resolveHealthAccountContext as n, buildNonSensitiveProbeFailure as t };