UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.73 kB
import{r as truncateUtf16Safe}from"./utf16-slice-DA3Mllbx.mjs";import{f as redactToolPayloadTextWithConfig}from"./redact-BT59pdZ_.mjs";import"./session-key-BPgKfU2m.mjs";import{n as normalizeAccountId}from"./account-id-3yqrEsRn.mjs";import{l as getActivePluginRegistry}from"./runtime-Cl6PvJHC.mjs";import{c as findActiveDegradedSecretOwner,n as SecretSurfaceUnavailableError}from"./runtime-degraded-state-DZJvpZUM.mjs";import{t as isChannelAccountExplicitlyDisabled}from"./account-config-enabled-C_81S4y1.mjs"; //!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`}export{resolveUnavailableChannelAccountSnapshot as a,resolveChannelAccountState as i,projectChannelAccountDisplayState as n,resolveChannelAccountLinked as r,applyChannelAccountState as t};