openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.16 kB
JavaScript
import{l as normalizeOptionalString,o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{a as asOptionalRecord}from"./record-coerce-BTbqdJ3-.mjs";import{t as isBlockedObjectKey}from"./prototype-keys-Dc7Yq32J.mjs";import{n as normalizeAccountId,r as normalizeOptionalAccountId}from"./account-id-3yqrEsRn.mjs";import{r as snapshotReaderSlot}from"./plugin-metadata-snapshot-readers-CE3oQsjj.mjs";
//!src/routing/account-lookup.ts
function resolveChannelAccountKey(e,t,n,r,i,a){return resolveAccountKey(e,t,r,i,{...a,channelId:n})}function resolveChannelAccountEntry(e,t,n,r,i){const a=resolveChannelAccountKey(e,t,n,r,i);return a===void 0?void 0:e?.[a]}function resolveAccountEntry(e,t){const n=resolveAccountKey(e,t);return n===void 0?void 0:e?.[n]}function resolveNormalizedAccountEntry(e,t,n,r){const i=resolveAccountKey(e,t,n,r);return i===void 0?void 0:e?.[i]}function resolveAccountKey(e,t,n,r,i){const a=r??(i?.channelId?snapshotReaderSlot.getCurrentPluginMetadataSnapshot?.({allowScopedSnapshot:true,allowWorkspaceScopedSnapshot:true})?.owners.channelAccountKeyPolicies?.get(i.channelId):void 0);const o=a?normalizeAccountId:n;const s=o??normalizeLowercaseStringOrEmpty;if(i?.allowMissing&&(isBlockedObjectKey(normalizeLowercaseStringOrEmpty(t))||isBlockedObjectKey(s(t))))throw new Error(`Account id "${t}" is reserved. Choose a different account id.`);const c=a?s(t):t;const l=i?.allowMissing?c:void 0;if(!e||typeof e!==`object`)return l;if(Object.hasOwn(e,c)&&(!o||!isBlockedObjectKey(c)))return c;const u=s(c);const d=normalizeLowercaseStringOrEmpty(c);let f;for(const t of Object.keys(e)){if(o&&isBlockedObjectKey(t))continue;if(a&&normalizeLowercaseStringOrEmpty(t)===d)return t;const n=s(t);if((!o||Boolean(normalizeOptionalAccountId(t))&&!isBlockedObjectKey(n))&&n===u){if(!a)return t;const n=asOptionalRecord(e[t]);if(f===void 0&&n&&Object.hasOwn(n,a.canonicalAliasesRequireOwnField)&&normalizeOptionalString(n[a.canonicalAliasesRequireOwnField]))f=t}}return f??l}export{resolveNormalizedAccountEntry as a,resolveChannelAccountKey as i,resolveAccountKey as n,resolveChannelAccountEntry as r,resolveAccountEntry as t};