openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.29 kB
JavaScript
import{t as isNamedOperatorRoleEnforcementEnabled}from"./operator-role-enforcement-FsaRvImR.mjs";import{t as captureGatewayIngressPersonPrincipal}from"./remote-ingress-principal-admission-Bparz-HR.mjs";import"./gateway-config-runtime-EiUpvSz9.mjs";import"./gateway-ingress-C729p7tR.mjs";import{n as RelayError}from"./protocol-Cfda5t_C.mjs";
//!extensions/mcp-relay/src/caller.ts
function relayCaller(e,t){if(!e||e.connect.role!==`operator`)throw new RelayError(`unavailable`,`Reconnect to the Control UI to manage connected apps.`);const n=e.connect.scopes??[];const r=n.includes(`operator.admin`);const i=r||n.includes(`operator.write`);const a=[.../* @__PURE__ */ new Set([...n,...i?[`operator.read`,`operator.write`]:[]])];if(isNamedOperatorRoleEnforcementEnabled(t)||t.gateway?.auth?.mode===`trusted-proxy`||e.internal?.openclawIdPrincipal?.kind===`member`||e.internal?.operatorRoleActor?.kind===`operator`){const t=e.authenticatedUserProfile;const n=e.internal?.operatorRoleActor;if(!t||n?.kind===`system`||n?.kind===`operator`&&n.profileId!==t.profileId)throw new RelayError(`unavailable`,`Sign in as a person and use the Connected apps tab to pair this Gateway.`);return{principal:captureGatewayIngressPersonPrincipal(e),principalLabel:t.displayName??`Gateway user`,ceiling:a,canAdmin:r,canPair:i}}return{principal:{kind:`owner`},principalLabel:`Gateway owner`,ceiling:a,canAdmin:r,canPair:r}}function ownsGrant(e,t){return t.principal.kind===`owner`?e.principal.kind===`owner`:e.principal.kind!==`owner`&&t.principal.profileId===e.principal.profileId}function consentAuthority(e,t){if(!e.canPair)throw new RelayError(`unavailable`,`Your Gateway role cannot connect apps. Ask your administrator for access.`);const n=t??[`operator.read`,`operator.write`].filter(t=>e.ceiling.includes(t));if(!Array.isArray(n)||n.length===0||n.length>64||!n.every(t=>typeof t===`string`&&e.ceiling.includes(t)))throw new RelayError(`invalid_params`,`Choose access permitted by your current Gateway role.`);return{principal:e.principal,principalLabel:e.principalLabel,ceiling:[...new Set(n)]}}function relayPrincipalForDisplay(e){return e.kind===`delegated-person`?{kind:`person`,profileId:e.profileId}:e}export{relayPrincipalForDisplay as i,ownsGrant as n,relayCaller as r,consentAuthority as t};