UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 5.29 kB
import{o as roleScopesAllow,t as intersectOperatorScopes}from"./operator-scope-compat-TmgAKmD2.mjs";import{n as parseUserChannelAuthorizationReference}from"./user-channel-authorization-reference-D35qfDsY.mjs";import{_ as resolveOperatorRoleSelection,h as resolveOperatorRolePolicyForAssignment}from"./operator-role-policy-g-dxw0h4.mjs";import{t as isNamedOperatorRoleEnforcementEnabled}from"./operator-role-enforcement-FsaRvImR.mjs";import{c as resolveUserChannelAuthorizationPolicy,l as resolveUserChannelIdentity}from"./user-channel-identities-vR3MDQL2.mjs";import{a as prepareUserChannelIdentityAuthority,t as authorizeCanonicalUserChannelIdentity}from"./user-channel-identity-operations-BbYvG0PX.mjs";import{n as GatewayOperatorAccessDeniedError,o as resolvePreparedGatewayOperatorAccessAuthority,r as hasCurrentGatewayOperatorAccess,s as resumeGatewayOperatorAccessGrant}from"./operator-access-policy-lm0chPjw.mjs";import{t as resolveIdentityOperatorScopes}from"./operator-identity-scopes-DxmAiLZL.mjs"; //!src/gateway/channel-operator-authority.ts function resolveChannelOperatorAdminAuthority(e,t,n={}){const r=resolveChannelOperatorIdentityFacts(e,t,n);return r&&captureLinkedOperatorAdmin(e,r.linked,r.isCurrent)?.authority}function resolveUpdateChannelOperatorAdminIdentityAuthority(e,t,n={}){const r=resolveChannelOperatorIdentityFacts(e,t,n);return r&&captureLinkedOperatorAdminIdentity(e,r.linked,r.isCurrent)}function resolveChannelOperatorIdentityFacts(e,t,n){if(!isNamedOperatorRoleEnforcementEnabled(e)&&!e.gateway?.auth?.identityScopes)return;const r={...t};const i=resolveUserChannelIdentity(r,n);if(!i)return;return{linked:i,isCurrent:(t=e)=>{const a=resolveUserChannelIdentity(r,n);const o=isNamedOperatorRoleEnforcementEnabled(t)&&Object.keys(t.gateway?.roles?.assignments?.byGithubLogin??{}).length>0&&resolveOperatorRoleSelection(i.profileId,i.role,t,i.githubLogin??null).roleSource!==`assigned`;return a!==void 0&&a.profileId===i.profileId&&a.role===i.role&&(!o||a.githubLogin===i.githubLogin)&&i.emails.every(e=>a.emails.includes(e))&&i.loginIdentities.every(e=>a.loginIdentities.includes(e))}}}function resolveLinkedOperatorScopes(e,t){const n=resolveOperatorRolePolicyForAssignment(t.profileId,t.role,e,t.githubLogin??null)?.scopes;const r=[...new Set(t.loginIdentities.flatMap(t=>resolveIdentityOperatorScopes(t,e.gateway?.auth?.identityScopes)))];return r.length?intersectOperatorScopes(r,n??r):n??[]}function captureLinkedOperatorAdminIdentity(e,t,n,r=true){const i=resolveLinkedOperatorScopes(e,t);if(!i.length||r&&!i.includes(`operator.admin`))return;const a=resolveOperatorRolePolicyForAssignment(t.profileId,t.role,e,t.githubLogin??null)?.accessPolicyPlugin;let o=true;const isCurrent=e=>{o&&=n(e)&&roleScopesAllow({role:`operator`,requestedScopes:i,allowedScopes:resolveLinkedOperatorScopes(e,t)})&&resolveOperatorRolePolicyForAssignment(t.profileId,t.role,e,t.githubLogin??null)?.accessPolicyPlugin===a;return o};return isCurrent(e)?{profileId:t.profileId,isCurrent}:void 0}function captureLinkedOperatorAdmin(e,t,n,r,i=true){const a=captureLinkedOperatorAdminIdentity(e,t,n,i);if(!a)return;try{const i=r?null:resolvePreparedGatewayOperatorAccessAuthority({...t,githubLogin:t.githubLogin??null,isCurrent:()=>n(e)},e);let o=true;const isCurrent=e=>{o&&=a.isCurrent(e)&&hasCurrentGatewayOperatorAccess(i);if(o&&r){resumeGatewayOperatorAccessGrant({profileId:t.profileId,emails:t.emails,githubAccountIds:t.githubAccountIds,assignedRole:t.role,githubLogin:t.githubLogin??null},e,r.grant);o&&=n(e)}return o};return isCurrent(e)?{authority:{profileId:t.profileId,isCurrent,...i?{signal:i.signal}:{}},grant:i===null?null:i.gatewayAccessGrant}:void 0}catch(e){if(e instanceof GatewayOperatorAccessDeniedError)return;throw e}}async function prepareChannelOperatorIdentity(e,t,n,r){if(!isNamedOperatorRoleEnforcementEnabled(e)&&!e.gateway?.auth?.identityScopes)return;const i=`identity`in t?t.identity:t;const a=resolveUserChannelAuthorizationPolicy(e.gateway);const o=`version`in i?parseUserChannelAuthorizationReference(i):void 0;if(`version`in i&&!o)return;const s=`identity`in t?t.prepared:await prepareUserChannelIdentityAuthority(`version`in i?{authorizationId:i.id,policy:a}:i,n);if(!s)return;const c=captureLinkedOperatorAdmin(e,s.linked,s.isCurrent,s.linked.authorization,r);if(!c)return;const l=s.linked.authorization;const assertCurrent=()=>{if(!c.authority.isCurrent(e))throw new GatewayOperatorAccessDeniedError};const u=l?.reference??(!(`version`in i)&&c.grant!==void 0?await authorizeCanonicalUserChannelIdentity({action:`authorize`,identity:i,profileId:s.linked.profileId,policy:a,grant:c.grant},{...n,assertCurrent}):void 0);assertCurrent();return{...c.authority,recoveryReference:u,operatorProfile:{profileId:s.linked.profileId,assignedRole:s.linked.role,githubLogin:s.linked.githubLogin??null,scopes:resolveLinkedOperatorScopes(e,s.linked),gatewayAccessGrant:c.grant}}}function prepareChannelOperatorAuthority(e,t,n={}){return prepareChannelOperatorIdentity(e,t,n,false)}function prepareChannelOperatorAdmin(e,t,n={}){return prepareChannelOperatorIdentity(e,t,n,true)}export{resolveUpdateChannelOperatorAdminIdentityAuthority as i,prepareChannelOperatorAuthority as n,resolveChannelOperatorAdminAuthority as r,prepareChannelOperatorAdmin as t};