UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.48 kB
//!src/shared/browser-pair.ts const BROWSER_PAIR_CODE_ALPHABET=`ABCDEFGHJKLMNPQRSTUVWXYZ23456789`;const BROWSER_PAIR_CODE_RE=/^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{8}$/u;const BROWSER_PAIR_CODE_LENGTH=8;const BROWSER_PAIR_ROUTE_PREFIX=`/__openclaw__/browser-pair`;const BROWSER_PAIR_IDENTITY_REQUIRED_MESSAGE=`Browser-code pairing is unavailable when gateway.roles is configured because this sign-in does not verify a user identity. Use your Gateway's identity-aware sign-in instead, or ask an administrator for the supported sign-in method.`;function buildBrowserPairCode(e){let t=``;for(let n=0;n<BROWSER_PAIR_CODE_LENGTH;n+=1)t+=BROWSER_PAIR_CODE_ALPHABET[e(32)];return t}function normalizeBrowserPairCode(e){const t=e.replace(/[\s-]/gu,``).toUpperCase();return BROWSER_PAIR_CODE_RE.test(t)?t:null}function formatBrowserPairCode(e,t){const n=`${e.slice(0,4)}-${e.slice(4)}`;return t?`${t}:${n}`:n}function splitBrowserPairCodeProfile(e){const t=e.indexOf(`:`);return t<0?{profile:null,code:e}:{profile:e.slice(0,t).trim(),code:e.slice(t+1)}}function formatBrowserPairDeviceId(e){return e.slice(0,8)}function buildBrowserPairPayload(e){return[`openclaw-browser-pair-v1`,e.action,e.deviceId,e.requestId??``].join(` `)}export{formatBrowserPairCode as a,splitBrowserPairCodeProfile as c,buildBrowserPairPayload as i,BROWSER_PAIR_ROUTE_PREFIX as n,formatBrowserPairDeviceId as o,buildBrowserPairCode as r,normalizeBrowserPairCode as s,BROWSER_PAIR_IDENTITY_REQUIRED_MESSAGE as t};