UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

97 lines (96 loc) • 4.28 kB
import { a as asOptionalRecord } from "./record-coerce-TIsquoVR.mjs"; import { r as truncateUtf16Safe } from "./utf16-slice-D_ngcYKd.mjs"; import { x as redactToolPayloadTextWithConfig } from "./redact-BV3wTtTv.mjs"; import "./session-key-DY3MOX4N.mjs"; import { n as normalizeAccountId } from "./account-id-ifCOO7_9.mjs"; import { l as getActivePluginRegistry } from "./runtime-U4i1bMh7.mjs"; import { c as findActiveDegradedSecretOwner, n as SecretSurfaceUnavailableError } from "./runtime-degraded-state-Dyd8aD2x.mjs"; import { r as resolveChannelAccountEntry } from "./account-lookup-BAaS-Jak.mjs"; //#region src/channels/account-config-enabled.ts /** Reads an operator's explicit disable without resolving an operational account. */ function isChannelAccountExplicitlyDisabled(params) { const channel = asOptionalRecord(params.cfg.channels?.[params.channel]); const account = asOptionalRecord(resolveChannelAccountEntry(asOptionalRecord(channel?.accounts), params.accountId, params.channel)); return channel?.enabled === false || account?.enabled === false; } //#endregion //#region src/channels/status/account-state.ts function resolveUnavailableChannelAccountSnapshot(cfg, params) { const accountId = normalizeAccountId(params.accountId); const owner = findActiveDegradedSecretOwner("account", `${params.channelId}:${accountId}`); const registry = params.registry ?? getActivePluginRegistry(); const failedPlugin = !registry?.channels.some(({ plugin }) => plugin.id === params.channelId) && registry?.plugins.find((plugin) => plugin.enabled && plugin.status === "error" && plugin.channelIds.includes(params.channelId)); const pluginError = failedPlugin && redactToolPayloadTextWithConfig(`Plugin ${failedPlugin.id} failed: ${failedPlugin.error}`, cfg.logging); const lastError = owner ? new SecretSurfaceUnavailableError(owner).message : pluginError && `${truncateUtf16Safe(pluginError, 1e3)}; run openclaw doctor`; if (!lastError) return; const runtime = failedPlugin ? void 0 : params.runtime; return { ...runtime, accountId: params.accountId, enabled: failedPlugin ? !isChannelAccountExplicitlyDisabled({ cfg, channel: params.channelId, accountId }) : runtime?.enabled ?? true, configured: true, running: false, ...typeof runtime?.connected === "boolean" ? { connected: false } : {}, restartPending: false, lifecycle: "blocked", stateReason: lastError, lastError }; } function resolveChannelAccountState(input) { const lastError = input.runtime?.lastError ?? null; if (!input.enabled) return { displayState: "disabled", snapshot: { configured: input.configured, ...typeof input.linked === "boolean" ? { linked: input.linked } : {}, running: false, stateReason: input.disabledReason ?? "disabled", lastError } }; if (!input.configured || input.linked === false) return { displayState: input.configured ? "not linked" : "not configured", snapshot: { configured: input.configured, ...input.configured ? { linked: false } : {}, running: false, stateReason: input.configured ? input.unlinkedReason ?? "not linked" : input.unconfiguredReason ?? "not configured", lastError } }; return { displayState: input.linked ? "linked" : void 0, snapshot: { configured: true, ...input.linked ? { linked: true } : {}, running: input.runtime?.running === true, ...typeof input.runtime?.connected === "boolean" ? { connected: input.runtime.connected } : {}, lastError } }; } function resolveChannelAccountLinked(state, fallback) { return state ? state === "unknown" ? void 0 : state === "linked" : fallback; } const CHANNEL_ACCOUNT_STATE_FIELDS = [ "configured", "linked", "running", "connected", "stateReason", "lastError" ]; function applyChannelAccountState(snapshot, state) { for (const field of CHANNEL_ACCOUNT_STATE_FIELDS) delete snapshot[field]; Object.assign(snapshot, state.snapshot); } function projectChannelAccountDisplayState(state, fallback) { return state.displayState ?? fallback ?? "configured"; } //#endregion export { resolveUnavailableChannelAccountSnapshot as a, resolveChannelAccountState as i, projectChannelAccountDisplayState as n, isChannelAccountExplicitlyDisabled as o, resolveChannelAccountLinked as r, applyChannelAccountState as t };