openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.72 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{tn as t}from"./control-ui-foundation-ZY_Flbbd.js";import{Su as n}from"./control-ui-core-3P365fbR.js";import{at as r,dt as i,ft as a,gt as o,ht as s,pt as c,rt as l,ut as u}from"./control-ui-boot-shared-DBJri5ri.js";import{a as d,o as f}from"./state-rFA9s-wO.js";var p,m;function h(){return(h=e((()=>{o(),p=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(a(e),u(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`expected Hash instance`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),s(r)}update(e){return i(this),this.iHash.update(e),this}digestInto(e){i(this),c(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o,canXOF:s}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.canXOF=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},m=(()=>{let e=((e,t,n)=>new p(e,t).update(n).digest());return e.create=(e,t)=>new p(e,t),e})()})))()}function g(e){let t=t=>{t.key===w&&t.newValue===null&&t.oldValue&&e(t.oldValue)};return D.add(e),window.addEventListener(`storage`,t),()=>{D.delete(e),window.removeEventListener(`storage`,t)}}function _(e,t,n){try{let i=JSON.parse(n.getItem(T)??`null`);if(i?.version!==1||typeof i.privateKey!=`string`||!i.privateKey)return null;let a=e.gateway.connection,o=a.token||a.password||a.bootstrapToken,s=o?``:e.gateway.snapshot.hello?.auth?.deviceToken;if(!o&&!s)return null;let c=[t.gatewayUrl,t.agentId,t.modelRef??``,t.kind,String(t.deadlineMs),a.token,a.password,a.bootstrapToken,a.bootstrapProfile??``,s??``,...t.modelTarget?[t.modelTarget]:[],...t.wizard?[t.wizard.sessionId,t.wizard.authChoice,t.wizard.authKind??``]:[]],l=new TextEncoder,u=c.map(e=>`${l.encode(e).length}:${e}`).join(`|`);return Array.from(m(r,l.encode(i.privateKey),l.encode(u))).map(e=>e.toString(16).padStart(2,`0`)).join(``)}catch{return null}}function v(e,t){try{let n=e.getItem(w);if((t===void 0||t&&n===JSON.stringify(t))&&(e.removeItem(w),n))for(let e of D)e(n)}catch{}}function y(e,r){let i=n();if(!i||e.gateway.snapshot.phase!==`connected`)return null;try{let n=i.getItem(w);if(!n||r&&n!==JSON.stringify(r))return null;let a=JSON.parse(n);if(a?.version!==1||typeof a.gatewayUrl!=`string`||typeof a.agentId!=`string`||a.modelRef!==null&&typeof a.modelRef!=`string`||a.modelTarget!==void 0&&a.modelTarget!==`utility`||a.wizard!==void 0&&(a.kind!==`provider-auth`||!a.wizard||typeof a.wizard.sessionId!=`string`||!a.wizard.sessionId||typeof a.wizard.authChoice!=`string`||!a.wizard.authChoice||a.wizard.authKind!==void 0&&a.wizard.authKind!==`secret`&&a.wizard.authKind!==`oauth`&&a.wizard.authKind!==`device-code`)||typeof a.kind!=`string`||typeof a.deadlineMs!=`number`||!Number.isFinite(a.deadlineMs)||a.deadlineMs<=Date.now()||typeof a.owner!=`string`||a.gatewayUrl!==t(e.gateway.connection.gatewayUrl)||a.agentId!==(e.agentSelection.state.selectedId??``))return v(i),null;let{owner:o,...s}=a;return _(e,s,i)===o?a:(v(i),null)}catch{return v(i),null}}function b(e){return Date.now()+d(e)+E}function x(e,r){let i=n();if(!i||e.gateway.snapshot.phase!==`connected`)return null;try{let n={version:1,gatewayUrl:t(e.gateway.connection.gatewayUrl),agentId:e.agentSelection.state.selectedId??``,modelRef:r.modelRef??null,...r.modelTarget?{modelTarget:r.modelTarget}:{},...r.wizard?{wizard:r.wizard}:{},kind:r.kind,deadlineMs:r.deadlineMs??b(r.kind)},a=_(e,n,i);if(!a)return null;let o={...n,owner:a};return i.setItem(w,JSON.stringify(o)),o}catch{return null}}function S(e){let t=n();t&&v(t,e)}function C(e,t,n,r,i,a){let{context:o}=e,s=o.gateway.snapshot;!i()&&s.phase===`connected`&&s.client===t.client&&s.hello===t.hello&&o.gateway.connectionRevision===n&&(o.agentSelection.state.selectedId?.trim()||null)===r&&e.isStillDefaultLanding()&&y(o)!==null&&e.redirect(),a()}var w,T,E,D;function O(){return(O=e((()=>{h(),l(),f(),w=`openclaw.modelSetup.pendingActivation.v1`,T=`openclaw-device-identity-v1`,E=5e3,D=new Set})))()}export{y as a,x as i,b as n,C as o,O as r,g as s,S as t};