UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.89 kB
import{r as asNullableRecord}from"./record-coerce-BTbqdJ3-.mjs";import{n as sanitizeForLog}from"./ansi-54CEWBZf.mjs";import"./session-key-BPgKfU2m.mjs";import{t as DEFAULT_ACCOUNT_ID}from"./account-id-3yqrEsRn.mjs";import{r as theme}from"./theme-DS2CtI9X.mjs";import{n as formatTimeAgo}from"./format-relative-CyNS0X3c.mjs";import{r as hasConfiguredUnavailableCredentialStatus}from"./account-snapshot-fields-Dt8EOHJC.mjs";import{a as formatChannelAllowFrom,t as buildChannelAccountNotes}from"./account-summary-lwAo0b5h.mjs";import{n as resolveInspectedChannelAccount}from"./account-inspection-iqk7WB2T.mjs";import{t as formatChannelStatusState}from"./status-state-DnUMt8ht.mjs"; //!src/infra/channel-summary.ts async function buildChannelSummary(e,t){const n=[];const{colorize:r=false,includeAllowFrom:i=false}=t??{};const a=t?.sourceConfig??e;const o=await(await import(`./read-only-DqlMkH3y.mjs`)).listReadOnlyChannelPluginsForConfigAsync(e,{activationSourceConfig:a,includeSetupFallbackPlugins:false});for(const t of o){const o=t.config.listAccountIds(e);const s=t.config.defaultAccountId?.(e)??o[0]??`default`;const c=o.length>0?o:[s];const l=[];for(const n of c){const r=await resolveInspectedChannelAccount({plugin:t,cfg:e,sourceConfig:a,accountId:n});l.push({accountId:n,...r})}const u=l.filter(e=>e.configured);const d=l.some(e=>e.enabled);const f=l.some(e=>e.enabled&&e.configured===void 0);const p=l.find(e=>e.accountId===s)??l[0];const m=p?.kind===`resolved`&&t.status?.buildChannelSummary?await t.status.buildChannelSummary({account:p.account,cfg:e,defaultAccountId:s,snapshot:p.snapshot}):p?.snapshot;const h=asNullableRecord(m);const g=h&&typeof h.statusState===`string`?h.statusState:null;const _=h&&typeof h.linked===`boolean`?h.linked:null;const v=h&&typeof h.configured===`boolean`?h.configured:u.length>0;const y=!d?`disabled`:f?`configuration status unavailable`:g?formatChannelStatusState(g):_!==null?_?`linked`:`not linked`:v?`configured`:`not configured`;const b=y===`linked`||y===`configured`?theme.success:y===`not linked`||y===`auth stabilizing`?theme.error:theme.muted;let x=`${sanitizeForLog(t.meta.label??t.id).trim()||t.id}: ${y}`;const S=h&&typeof h.authAgeMs===`number`?h.authAgeMs:null;const C=h?.self;if(C?.e164)x+=` ${C.e164}`;if(S!=null&&S>=0)x+=` auth ${formatTimeAgo(S)}`;n.push(r?b(x):x);for(const r of u){const a=r.snapshot;const o=buildChannelAccountNotes(a,r.kind===`unavailable`||hasConfiguredUnavailableCredentialStatus(r.account)?`secret unavailable in this command path`:void 0);if(i&&a.allowFrom?.length){const n=formatChannelAllowFrom({plugin:t,cfg:e,accountId:a.accountId,allowFrom:a.allowFrom}).slice(0,2);if(n.length>0)o.push(`allow:${n.join(`,`)}`)}const s=r.accountId||`default`;const c=r.snapshot.name?.trim();const l=c?`${s} (${c})`:s;n.push(` - ${l}${o.length?` (${o.join(`, `)})`:``}`)}}return n}export{buildChannelSummary as t};