openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.14 kB
JavaScript
import{l as normalizeOptionalString}from"../../string-coerce-CpTFcSwY.mjs";import"../../string-coerce-runtime-BYDH9Quw.mjs";
//!extensions/device-pair/pair-command-auth.ts
const COMMAND_OWNER_PAIRING_SCOPES=[`operator.pairing`];const PAIRING_SCOPE=`operator.pairing`;const ADMIN_SCOPE=`operator.admin`;const TALK_SECRETS_SCOPE=`operator.talk.secrets`;function resolveAuthLabel(e){const t=e.gateway?.auth?.mode;const n=normalizeOptionalString(process.env.OPENCLAW_GATEWAY_TOKEN)??normalizeOptionalString(e.gateway?.auth?.token);const r=normalizeOptionalString(process.env.OPENCLAW_GATEWAY_PASSWORD)??normalizeOptionalString(e.gateway?.auth?.password);if(t===`token`||t===`password`)return resolveRequiredAuthLabel(t,{token:n,password:r});if(n)return{label:`token`};if(r)return{label:`password`};if(t===`trusted-proxy`)return{label:`trusted-proxy`};return{error:`Gateway auth is not configured (no token or password).`}}function resolveRequiredAuthLabel(e,t){return t[e]?{label:e}:{error:`Gateway auth is set to ${e}, but no ${e} is configured.`}}function isInternalGatewayPairingCaller(e){return e.channel===`webchat`||Array.isArray(e.gatewayClientScopes)}function hasPairingPrivilege(e){return e.includes(PAIRING_SCOPE)||e.includes(ADMIN_SCOPE)}function hasSetupHandoffPrivilege(e){return e.includes(TALK_SECRETS_SCOPE)||e.includes(ADMIN_SCOPE)}function resolvePairingCommandAuthState(e){const t=isInternalGatewayPairingCaller(e);if(t){const n=Array.isArray(e.gatewayClientScopes)?e.gatewayClientScopes:[];return{isInternalGatewayCaller:t,isMissingPairingPrivilege:!hasPairingPrivilege(n),isMissingSetupHandoffPrivilege:!hasSetupHandoffPrivilege(n),canIssueFullAccessSetup:n.includes(ADMIN_SCOPE),approvalCallerScopes:n}}if(e.senderIsOwner===true)return{isInternalGatewayCaller:t,isMissingPairingPrivilege:false,isMissingSetupHandoffPrivilege:false,canIssueFullAccessSetup:true,approvalCallerScopes:COMMAND_OWNER_PAIRING_SCOPES};return{isInternalGatewayCaller:t,isMissingPairingPrivilege:true,isMissingSetupHandoffPrivilege:true,canIssueFullAccessSetup:false,approvalCallerScopes:void 0}}export{resolveAuthLabel,resolvePairingCommandAuthState};