openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.74 kB
JavaScript
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{r as normalizeOptionalAccountId}from"./account-id-3yqrEsRn.mjs";import{r as assertSecretOwnerAvailable}from"./runtime-degraded-state-DZJvpZUM.mjs";import{t as getChannelPlugin}from"./registry-CpNh6QcT.mjs";import{r as resolveChannelAccount,t as channelHasConfiguredState}from"./account-resolution-BMEKSThh.mjs";import"./plugins-DxOycUNJ.mjs";import{r as listRuntimeVisibleChannelPlugins}from"./runtime-visible-channels-Cx_NfvRz.mjs";import{i as resolveChannelDefaultAccountId}from"./helpers-1A2j6LGz.mjs";import{t as isChannelAccountExplicitlyDisabled}from"./account-config-enabled-C_81S4y1.mjs";import{s as resolveChannelAccountEnabled}from"./account-summary-lwAo0b5h.mjs";import{r as resolveOutboundChannelPlugin}from"./channel-resolution-DC4uO43j.mjs";import{t as MessageActionDeniedError}from"./message-action-denial-Ce14s7W0.mjs";import{t as isAccountEnabled}from"./account-enabled-YsTp1izZ.mjs";import{t as isConfiguredChannel}from"./channel-selection-DA2EgjK_.mjs";
//!src/infra/outbound/message-account-selection.ts
async function validateExplicitMessageAccountSelection(e){const t=normalizeOptionalString(e.accountId);if(!t)return;const n=normalizeOptionalAccountId(t);if(!n)throw new MessageActionDeniedError(`Invalid account ID "${t}".`,`message_account_invalid`,`message-account:valid`);const r=normalizeOptionalString(e.channel);if(!r)return n;const i=e.plugin??resolveOutboundChannelPlugin({channel:r,cfg:e.cfg})??getChannelPlugin(r);if(!i)return n;let a=i.config.listAccountIds(e.cfg).find(e=>normalizeOptionalAccountId(e)===n);if(!a){const t=resolveChannelDefaultAccountId({plugin:i,cfg:e.cfg});if(normalizeOptionalAccountId(t)===n)a=t}if(!a)throw new MessageActionDeniedError(`Unknown account "${t}" for channel ${r}.`,`message_account_unknown`,`message-account:known`);const assertAccountEnabled=t=>{if(isChannelAccountExplicitlyDisabled({cfg:e.cfg,channel:i.id,accountId:a})||t&&!t())throw new MessageActionDeniedError(`Account "${a}" for channel ${r} is disabled.`,`message_account_disabled`,`message-account:enabled`)};assertAccountEnabled();if(e.checkResolvedAccount!==false){assertSecretOwnerAvailable(`account`,`${i.id}:${n}`);const t=await resolveChannelAccount({plugin:i,cfg:e.cfg,accountId:n});assertSecretOwnerAvailable(`account`,`${i.id}:${n}`);assertAccountEnabled(()=>resolveChannelAccountEnabled({plugin:i,account:t,cfg:e.cfg}))}return n}async function isPotentialConfiguredMessageChannel(e){const t=e.cfg.channels?.[e.plugin.id];if(!Array.isArray(t)&&!isAccountEnabled(t))return false;if(isConfiguredChannel(e.cfg,e.plugin.id))return true;try{return await channelHasConfiguredState({plugin:e.plugin,cfg:e.cfg,env:process.env})===true}catch{return false}}async function resolveMessageBroadcastAccountPlan(e){const t=await validateExplicitMessageAccountSelection({cfg:e.cfg,accountId:e.accountId,checkResolvedAccount:false});if(!t)return;const n=[];for(const t of listRuntimeVisibleChannelPlugins())if(resolveOutboundChannelPlugin({channel:t.id,cfg:e.cfg})&&await isPotentialConfiguredMessageChannel({cfg:e.cfg,plugin:t}))n.push(t);const r=[];for(const i of n)try{await validateExplicitMessageAccountSelection({cfg:e.cfg,channel:i.id,accountId:t,plugin:i,checkResolvedAccount:false});const n=i.config.inspectAccount?.(e.cfg,t);const a=n??await resolveChannelAccount({plugin:i,cfg:e.cfg,accountId:t});if(a!==void 0&&(n!=null?isAccountEnabled(n):resolveChannelAccountEnabled({plugin:i,account:a,cfg:e.cfg})))r.push(i.id)}catch{}return{accountId:t,candidateChannels:n.map(e=>e.id),secretChannels:r}}export{resolveMessageBroadcastAccountPlan as n,validateExplicitMessageAccountSelection as r,isPotentialConfiguredMessageChannel as t};