openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.97 kB
JavaScript
import{n as normalizeDeviceAuthScopes,t as normalizeDeviceAuthRole}from"./device-auth-BxeuYK8r.mjs";
//!src/shared/device-bootstrap-profile.ts
const BOOTSTRAP_HANDOFF_OPERATOR_SCOPES=[`operator.approvals`,`operator.questions`,`operator.read`,`operator.talk.secrets`,`operator.write`];const BOOTSTRAP_HANDOFF_OPERATOR_SCOPE_SET=new Set(BOOTSTRAP_HANDOFF_OPERATOR_SCOPES);const CONTROL_UI_OWNER_BOOTSTRAP_OPERATOR_SCOPES=[`operator.admin`,`operator.approvals`,`operator.pairing`,`operator.questions`,`operator.read`,`operator.talk.secrets`,`operator.write`];const CONTROL_UI_OWNER_BOOTSTRAP_OPERATOR_SCOPE_SET=new Set(CONTROL_UI_OWNER_BOOTSTRAP_OPERATOR_SCOPES);const MOBILE_FULL_ACCESS_OPERATOR_SCOPES=[`operator.admin`,...BOOTSTRAP_HANDOFF_OPERATOR_SCOPES];const MOBILE_FULL_ACCESS_OPERATOR_SCOPE_SET=new Set(MOBILE_FULL_ACCESS_OPERATOR_SCOPES);const VOICE_NODE_OPERATOR_SCOPE_SET=/* @__PURE__ */ new Set([`operator.read`,`operator.talk`]);const PAIRING_SETUP_BOOTSTRAP_PROFILE={roles:[`node`,`operator`],scopes:[...BOOTSTRAP_HANDOFF_OPERATOR_SCOPES]};const CONTROL_UI_OWNER_BOOTSTRAP_PROFILE={roles:[`operator`],scopes:[...CONTROL_UI_OWNER_BOOTSTRAP_OPERATOR_SCOPES],purpose:`control-ui-owner`};const FULL_ACCESS_PAIRING_SETUP_BOOTSTRAP_PROFILE={roles:[`node`,`operator`],scopes:[...MOBILE_FULL_ACCESS_OPERATOR_SCOPES],purpose:`mobile-full`};const NODE_PAIRING_SETUP_BOOTSTRAP_PROFILE={roles:[`node`],scopes:[]};const CLOUD_WORKER_PAIRING_SETUP_BOOTSTRAP_PROFILE={roles:[`node`],scopes:[],purpose:`cloud-worker`};const VOICE_NODE_PAIRING_SETUP_BOOTSTRAP_PROFILE={roles:[`node`,`operator`],scopes:[`operator.read`,`operator.talk`],purpose:`voice-node`};function deviceBootstrapProfilesEqual(e,t){const n=normalizeDeviceBootstrapProfile(e);const r=normalizeDeviceBootstrapProfile(t);return n.purpose===r.purpose&&n.roles.length===r.roles.length&&n.scopes.length===r.scopes.length&&n.roles.every((e,t)=>e===r.roles[t])&&n.scopes.every((e,t)=>e===r.scopes[t])}function isMobilePairingSetupBootstrapProfile(e){return deviceBootstrapProfilesEqual(e,PAIRING_SETUP_BOOTSTRAP_PROFILE)||deviceBootstrapProfilesEqual(e,FULL_ACCESS_PAIRING_SETUP_BOOTSTRAP_PROFILE)}function isNodePairingSetupBootstrapProfile(e){return deviceBootstrapProfilesEqual(e,NODE_PAIRING_SETUP_BOOTSTRAP_PROFILE)||deviceBootstrapProfilesEqual(e,CLOUD_WORKER_PAIRING_SETUP_BOOTSTRAP_PROFILE)}function resolvePairingSetupAccess(e){if(deviceBootstrapProfilesEqual(e,FULL_ACCESS_PAIRING_SETUP_BOOTSTRAP_PROFILE))return`full`;if(isNodePairingSetupBootstrapProfile(e))return`node`;return`limited`}function isVoiceNodePairingSetupBootstrapProfile(e){return deviceBootstrapProfilesEqual(e,VOICE_NODE_PAIRING_SETUP_BOOTSTRAP_PROFILE)}function resolveBootstrapProfileScopesForRole(e,t,n){const r=normalizeDeviceAuthRole(e);const i=normalizeDeviceAuthScopes(Array.from(t));if(r===`operator`){const e=n===`control-ui-owner`?CONTROL_UI_OWNER_BOOTSTRAP_OPERATOR_SCOPE_SET:n===`mobile-full`?MOBILE_FULL_ACCESS_OPERATOR_SCOPE_SET:n===`voice-node`?VOICE_NODE_OPERATOR_SCOPE_SET:BOOTSTRAP_HANDOFF_OPERATOR_SCOPE_SET;return i.filter(t=>e.has(t))}return[]}function resolveBootstrapProfileScopesForRoles(e,t,n){return normalizeDeviceAuthScopes(e.flatMap(e=>resolveBootstrapProfileScopesForRole(e,t,n)))}function resolveDeviceProfileRoleScopes(e,t,n=e.scopes){return resolveBootstrapProfileScopesForRole(t,n,e.purpose)}function resolveDeviceProfileScopes(e,t,n=e.scopes){return resolveBootstrapProfileScopesForRoles(t,n,e.purpose)}function normalizeDeviceBootstrapHandoffProfile(e){const t=normalizeDeviceBootstrapProfile(e);return{roles:t.roles,scopes:resolveBootstrapProfileScopesForRoles(t.roles,t.scopes,t.purpose),...t.purpose?{purpose:t.purpose}:{}}}function normalizeBootstrapRoles(e){if(!Array.isArray(e))return[];const t=/* @__PURE__ */ new Set;for(const n of e){const e=normalizeDeviceAuthRole(n);if(e)t.add(e)}return[...t].toSorted()}function normalizeDeviceBootstrapProfile(e){const t=e?.purpose===`control-ui`||e?.purpose===`control-ui-owner`||e?.purpose===`mobile-full`||e?.purpose===`voice-node`||e?.purpose===`cloud-worker`?e.purpose:void 0;return{roles:normalizeBootstrapRoles(e?.roles),scopes:normalizeDeviceAuthScopes(e?.scopes?[...e.scopes]:[]),...t?{purpose:t}:{}}}export{resolveDeviceProfileScopes as _,NODE_PAIRING_SETUP_BOOTSTRAP_PROFILE as a,deviceBootstrapProfilesEqual as c,isVoiceNodePairingSetupBootstrapProfile as d,normalizeDeviceBootstrapHandoffProfile as f,resolveDeviceProfileRoleScopes as g,resolveBootstrapProfileScopesForRoles as h,FULL_ACCESS_PAIRING_SETUP_BOOTSTRAP_PROFILE as i,isMobilePairingSetupBootstrapProfile as l,resolveBootstrapProfileScopesForRole as m,CLOUD_WORKER_PAIRING_SETUP_BOOTSTRAP_PROFILE as n,PAIRING_SETUP_BOOTSTRAP_PROFILE as o,normalizeDeviceBootstrapProfile as p,CONTROL_UI_OWNER_BOOTSTRAP_PROFILE as r,VOICE_NODE_PAIRING_SETUP_BOOTSTRAP_PROFILE as s,BOOTSTRAP_HANDOFF_OPERATOR_SCOPES as t,isNodePairingSetupBootstrapProfile as u,resolvePairingSetupAccess as v};