openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
72 lines (71 loc) • 3.15 kB
JavaScript
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs";
import { d as redactToolPayloadTextWithConfig } from "./redact-Mj7pppxC.mjs";
import "./session-key-CqAyZeVk.mjs";
import { n as normalizeAccountId } from "./account-id-BqKT3GuY.mjs";
import { l as getActivePluginRegistry } from "./runtime-ezCEpumg.mjs";
import { c as findActiveDegradedSecretOwner, n as SecretSurfaceUnavailableError } from "./runtime-degraded-state-BSnwk5PQ.mjs";
import { t as isChannelAccountExplicitlyDisabled } from "./account-config-enabled-Cg2pOk9t.mjs";
//#region src/channels/status/account-state.ts
function resolveUnavailableChannelAccountSnapshot(e, t) {
const n = normalizeAccountId(t.accountId);
const r = findActiveDegradedSecretOwner("account", `${t.channelId}:${n}`);
const i = t.registry ?? getActivePluginRegistry();
const a = !i?.channels.some(({ plugin: e }) => e.id === t.channelId) && i?.plugins.find((e) => e.enabled && e.status === "error" && e.channelIds.includes(t.channelId));
const o = a && redactToolPayloadTextWithConfig(`Plugin ${a.id} failed: ${a.error}`, e.logging);
const s = r ? new SecretSurfaceUnavailableError(r).message : o && `${truncateUtf16Safe(o, 1e3)}; run openclaw doctor`;
if (!s) return;
const c = a ? void 0 : t.runtime;
return {
...c,
accountId: t.accountId,
enabled: a ? !isChannelAccountExplicitlyDisabled({
cfg: e,
channel: t.channelId,
accountId: n
}) : c?.enabled ?? true,
configured: true,
running: false,
...typeof c?.connected === "boolean" ? { connected: false } : {},
restartPending: false,
lifecycle: "blocked",
stateReason: s,
lastError: s
};
}
function resolveChannelAccountState(e) {
const t = !e.enabled || !e.configured || e.linked === false;
const n = !e.enabled ? "disabled" : !e.configured ? "not configured" : e.linked === false ? "not linked" : e.linked ? "linked" : void 0;
const r = !e.enabled ? e.disabledReason ?? "disabled" : !e.configured ? e.unconfiguredReason ?? "not configured" : e.linked === false ? e.unlinkedReason ?? "not linked" : void 0;
const i = !e.enabled || e.configured ? e.linked : void 0;
return {
displayState: n,
snapshot: {
configured: e.configured,
...typeof i === "boolean" ? { linked: i } : {},
running: !t && e.runtime?.running === true,
...!t && typeof e.runtime?.connected === "boolean" ? { connected: e.runtime.connected } : {},
...r !== void 0 ? { stateReason: r } : {},
lastError: e.runtime?.lastError ?? null
}
};
}
function resolveChannelAccountLinked(e, t) {
return e ? e === "unknown" ? void 0 : e === "linked" : t;
}
const CHANNEL_ACCOUNT_STATE_FIELDS = [
"configured",
"linked",
"running",
"connected",
"stateReason",
"lastError"
];
function applyChannelAccountState(e, t) {
for (const t of CHANNEL_ACCOUNT_STATE_FIELDS) delete e[t];
Object.assign(e, t.snapshot);
}
function projectChannelAccountDisplayState(e, t) {
return e.displayState ?? t ?? "configured";
}
//#endregion
export { resolveUnavailableChannelAccountSnapshot as a, resolveChannelAccountState as i, projectChannelAccountDisplayState as n, resolveChannelAccountLinked as r, applyChannelAccountState as t };