UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

130 lines (129 loc) • 6.58 kB
import { n as normalizeDeviceAuthScopes, t as normalizeDeviceAuthRole } from "./device-auth-Cu5vRDvP.mjs"; //#region src/shared/device-bootstrap-profile.ts /** Operator scopes allowed to cross the short-lived bootstrap handoff boundary. */ 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); /** Full browser-owner scopes allowed only by the host-issued Control UI profile. */ 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); /** Full native-mobile operator scopes allowed only by the closed mobile setup profile. */ 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"]); /** Existing least-privilege setup-code/QR profile. */ const PAIRING_SETUP_BOOTSTRAP_PROFILE = { roles: ["node", "operator"], scopes: [...BOOTSTRAP_HANDOFF_OPERATOR_SCOPES] }; /** Full browser-owner profile issued only by dashboard and graphical onboarding. */ const CONTROL_UI_OWNER_BOOTSTRAP_PROFILE = { roles: ["operator"], scopes: [...CONTROL_UI_OWNER_BOOTSTRAP_OPERATOR_SCOPES], purpose: "control-ui-owner" }; /** Full native-mobile setup profile for explicitly authorized setup surfaces. */ const FULL_ACCESS_PAIRING_SETUP_BOOTSTRAP_PROFILE = { roles: ["node", "operator"], scopes: [...MOBILE_FULL_ACCESS_OPERATOR_SCOPES], purpose: "mobile-full" }; /** Node-only setup profile for companions that never act as operators. */ const NODE_PAIRING_SETUP_BOOTSTRAP_PROFILE = { roles: ["node"], scopes: [] }; /** Environment-owned node profile removed when its cloud lease is released. */ const CLOUD_WORKER_PAIRING_SETUP_BOOTSTRAP_PROFILE = { roles: ["node"], scopes: [], purpose: "cloud-worker" }; /** Room/embedded voice profile: node capabilities plus least-privilege Talk RPCs. */ const VOICE_NODE_PAIRING_SETUP_BOOTSTRAP_PROFILE = { roles: ["node", "operator"], scopes: ["operator.read", "operator.talk"], purpose: "voice-node" }; /** Compare normalized bootstrap profiles, including their closed purpose. */ 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); } /** Resolve the subset of requested scopes a bootstrap profile may carry for one role. */ 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 []; } /** Resolve bounded bootstrap handoff scopes across a role set. */ 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); } /** Normalize a requested bootstrap profile and strip scopes outside the handoff allowlist. */ 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(); } /** Normalize caller-provided bootstrap roles/scopes without applying handoff bounds. */ 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 } : {} }; } //#endregion 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 };