openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.44 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{l as isRecord,r as asNullableRecord}from"./record-coerce-BTbqdJ3-.mjs";import{f as normalizeStringEntries}from"./string-normalization-D_oBUpO3.mjs";import{t as asBoolean}from"./boolean-Dt_JCqyW.mjs";import"./utils-Dlk0IYAa.mjs";import{n as describeChannelAccount}from"./account-resolution-BMEKSThh.mjs";import{o as projectSafeChannelAccountSnapshotFields,s as redactChannelStatusSummaryBaseUrl}from"./account-snapshot-fields-Dt8EOHJC.mjs";import{i as resolveChannelAccountState,t as applyChannelAccountState}from"./account-state--nk_6U8k.mjs";import{a as buildRuntimeAccountStatusSnapshot}from"./status-helpers-BjQONSrT.mjs";
//!src/channels/account-summary.ts
function buildChannelAccountSnapshotFromRuntime(e){return{...buildRuntimeAccountStatusSnapshot({runtime:e}),...projectSafeChannelAccountSnapshotFields(e),accountId:e.accountId,enabled:e.enabled,configured:e.configured,stateReason:e.stateReason}}function buildChannelAccountSnapshotFromInspection(e){const t=asNullableRecord(e.account);const n=asBoolean(t?.enabled)??e.runtime?.enabled??true;const r=asBoolean(t?.configured)??e.runtime?.configured;const i={...buildRuntimeAccountStatusSnapshot(e),lastInboundAt:e.runtime?.lastInboundAt??null,lastOutboundAt:e.runtime?.lastOutboundAt??null,...projectSafeChannelAccountSnapshotFields(e.account),...e.runtime,...e.probe!==void 0?{probe:e.probe}:{},accountId:normalizeOptionalString(t?.accountId)??e.accountId,enabled:n,configured:r};if(r===void 0){i.stateReason=n?`configuration status unavailable`:`disabled`;if(!n)i.running=false;return redactChannelStatusSummaryBaseUrl(i)}const a=normalizeOptionalString(t?.stateReason);applyChannelAccountState(i,resolveChannelAccountState({enabled:n,configured:r,linked:i.linked,runtime:i,disabledReason:a,unconfiguredReason:a}));return redactChannelStatusSummaryBaseUrl(i)}async function buildChannelAccountSummary(e){const t=await describeChannelAccount(e);return redactChannelStatusSummaryBaseUrl({enabled:e.enabled,configured:e.configured,...projectSafeChannelAccountSnapshotFields(e.account),...t,accountId:e.accountId})}function formatChannelAllowFrom(e){if(e.plugin.config.formatAllowFrom)return e.plugin.config.formatAllowFrom({cfg:e.cfg,accountId:e.accountId,allowFrom:e.allowFrom});return normalizeStringEntries(e.allowFrom)}function buildChannelAccountNotes(e,t){const n=[[`token`,e.tokenSource],[`bot`,e.botTokenSource],[`app`,e.appTokenSource],[`signing`,e.signingSecretSource]].flatMap(([e,t])=>t&&t!==`none`?[`${e}:${t}`]:[]);return[e.enabled===false?`disabled`:void 0,e.dmPolicy?`dm:${e.dmPolicy}`:void 0,...n,t,e.baseUrl,e.port!=null?`port:${e.port}`:void 0,e.cliPath?`cli:${e.cliPath}`:void 0,e.dbPath?`db:${e.dbPath}`:void 0].filter(e=>Boolean(e))}function resolveChannelAccountEnabled(e){if(e.plugin.config.isEnabled)return e.plugin.config.isEnabled(e.account,e.cfg);return(isRecord(e.account)?e.account.enabled:void 0)!==false}async function resolveChannelAccountConfigured(e){if(e.plugin.config.isConfigured)return await e.plugin.config.isConfigured(e.account,e.cfg);return(isRecord(e.account)?e.account.configured:void 0)!==false}export{formatChannelAllowFrom as a,buildChannelAccountSummary as i,buildChannelAccountSnapshotFromInspection as n,resolveChannelAccountConfigured as o,buildChannelAccountSnapshotFromRuntime as r,resolveChannelAccountEnabled as s,buildChannelAccountNotes as t};