UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 3.51 kB
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{g as normalizeUniqueStringEntries}from"./string-normalization-D_oBUpO3.mjs";import"./session-key-BPgKfU2m.mjs";import{n as normalizeAccountId,r as normalizeOptionalAccountId,t as DEFAULT_ACCOUNT_ID}from"./account-id-3yqrEsRn.mjs";import{n as resolveMergedAccountConfig}from"./channel-account-config-DFPObbzi.mjs"; //!src/channels/plugins/account-helpers.ts function createAccountListHelpers(e,t){function hasImplicitDefaultAccount(n){const r=n.channels?.[e];return Boolean(t?.hasImplicitDefaultAccount?.(n)||t?.implicitDefaultAccount?.channelKeys?.some(e=>hasConfiguredAccountValue(r?.[e]))||t?.implicitDefaultAccount?.envVars?.some(e=>hasConfiguredAccountValue(process.env[e])))}function resolveConfiguredDefaultAccountId(t){const n=t.channels?.[e];return normalizeOptionalAccountId(typeof n?.defaultAccount===`string`?n.defaultAccount:void 0)}function listConfiguredAccountIds(n){const r=(n.channels?.[e])?.accounts;if(!r||typeof r!==`object`)return[];const i=Object.keys(r).filter(Boolean);const a=t?.normalizeAccountId;if(!a)return i;return normalizeUniqueStringEntries(i.map(e=>a(e)))}function listAccountIds(e){return listCombinedAccountIds({configuredAccountIds:listConfiguredAccountIds(e),additionalAccountIds:t?.additionalAccountIds?.(e),implicitAccountId:t?.resolveImplicitAccountId?t.resolveImplicitAccountId(e):hasImplicitDefaultAccount(e)?DEFAULT_ACCOUNT_ID:void 0,fallbackAccountIdWhenEmpty:t?.fallbackAccountIdWhenEmpty===false?void 0:t?.fallbackAccountIdWhenEmpty??`default`})}function resolveDefaultAccountId(e){return resolveListedDefaultAccountId({accountIds:listAccountIds(e),configuredDefaultAccountId:resolveConfiguredDefaultAccountId(e),allowUnlistedDefaultAccount:t?.allowUnlistedDefaultAccount})}return{listConfiguredAccountIds,listAccountIds,resolveDefaultAccountId,resolveAccountConfig:(n,r)=>{const i=n.channels?.[e];const a=i?.accounts;return resolveMergedAccountConfig({channelConfig:i,channelId:e,accounts:a,accountId:r,omitKeys:t?.omitKeys,normalizeAccountId:t?.normalizeAccountId,nestedObjectKeys:t?.nestedObjectKeys})}}}function hasConfiguredAccountValue(e){if(typeof e===`string`)return e.trim().length>0;return e!==void 0&&e!==null}function listCombinedAccountIds(e){const t=new Set([...e.configuredAccountIds,...e.additionalAccountIds??[],...e.implicitAccountId?[e.implicitAccountId]:[]].filter(Boolean));if(t.size===0&&e.fallbackAccountIdWhenEmpty)return[e.fallbackAccountIdWhenEmpty];return[...t].toSorted((e,t)=>e.localeCompare(t))}function resolveListedDefaultAccountId(e){const t=e.configuredDefaultAccountId;const n=e.normalizeListedAccountId??normalizeAccountId;if(t&&(e.allowUnlistedDefaultAccount||e.accountIds.some(e=>n(e)===t)))return t;if(e.accountIds.includes(`default`))return DEFAULT_ACCOUNT_ID;if(e.ambiguousFallbackAccountId&&e.accountIds.length>1)return e.ambiguousFallbackAccountId;return e.accountIds[0]??`default`}function describeAccountSnapshot(e){return{accountId:e.account.accountId??`default`,name:normalizeOptionalString(e.account.name),enabled:e.account.enabled!==false,configured:e.configured,...e.extra}}function describeWebhookAccountSnapshot(e){return describeAccountSnapshot({account:e.account,configured:e.configured,extra:{mode:e.mode??`webhook`,...e.extra}})}export{listCombinedAccountIds as a,hasConfiguredAccountValue as i,describeAccountSnapshot as n,resolveListedDefaultAccountId as o,describeWebhookAccountSnapshot as r,createAccountListHelpers as t};