openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.43 kB
JavaScript
import{n as e,r as t}from"./rolldown-runtime-8BhlS34s.js";import{Ku as n}from"./control-ui-core-CBJ5efDh.js";import{rn as r}from"./ui-CmSP4d14.js";import{$ as i,Q as a,X as o,Y as s,et as c,it as l,nt as u,rt as d,tt as f}from"./control-ui-boot-shared-VLPz5vN2.js";import{a as p,o as m}from"./state-Bjk4TzHh.js";var h,g;function _(){return(_=e((()=>{l(),h=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(c(e),a(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),d(r)}update(e){return i(this),this.iHash.update(e),this}digestInto(e){i(this),f(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()}},g=(()=>{let e=((e,t,n)=>new h(e,t).update(n).digest());return e.create=(e,t)=>new h(e,t),e})()})))()}var v=t({readFirstRunActivationReceipt:()=>S});function y(e){let t=t=>{t.key===E&&t.newValue===null&&t.oldValue&&e(t.oldValue)};return k.add(e),window.addEventListener(`storage`,t),()=>{k.delete(e),window.removeEventListener(`storage`,t)}}function b(e,t,n){try{let r=JSON.parse(n.getItem(D)??`null`);if(r?.version!==1||typeof r.privateKey!=`string`||!r.privateKey)return null;let i=e.gateway.connection,a=i.token||i.password||i.bootstrapToken,s=a?``:e.gateway.snapshot.hello?.auth?.deviceToken;if(!a&&!s)return null;let c=[t.gatewayUrl,t.agentId,t.modelRef??``,t.kind,String(t.deadlineMs),i.token,i.password,i.bootstrapToken,i.bootstrapProfile??``,s??``,...t.modelTarget?[t.modelTarget]:[],...t.wizard?[t.wizard.sessionId,t.wizard.authChoice,t.wizard.authKind??``]:[]],l=new TextEncoder,d=c.map(e=>`${l.encode(e).length}:${e}`).join(`|`);return u(g(o,l.encode(r.privateKey),l.encode(d)))}catch{return null}}function x(e,t){try{let n=e.getItem(E);if((t===void 0||t&&n===JSON.stringify(t))&&(e.removeItem(E),n))for(let e of k)e(n)}catch{}}function S(e,t){let i=n();if(!i||e.gateway.snapshot.phase!==`connected`)return null;try{let n=i.getItem(E);if(!n||t&&n!==JSON.stringify(t))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!==r(e.gateway.connection.gatewayUrl)||a.agentId!==(e.agentSelection.state.selectedId??``))return x(i),null;let{owner:o,...s}=a;return b(e,s,i)===o?a:(x(i),null)}catch{return x(i),null}}function C(e){return Date.now()+p(e)+O}function w(e,t){let i=n();if(!i||e.gateway.snapshot.phase!==`connected`)return null;try{let n={version:1,gatewayUrl:r(e.gateway.connection.gatewayUrl),agentId:e.agentSelection.state.selectedId??``,modelRef:t.modelRef??null,...t.modelTarget?{modelTarget:t.modelTarget}:{},...t.wizard?{wizard:t.wizard}:{},kind:t.kind,deadlineMs:t.deadlineMs??C(t.kind)},a=b(e,n,i);if(!a)return null;let o={...n,owner:a};return i.setItem(E,JSON.stringify(o)),o}catch{return null}}function T(e){let t=n();t&&x(t,e)}var E,D,O,k;function A(){return(A=e((()=>{_(),s(),l(),m(),E=`openclaw.modelSetup.pendingActivation.v1`,D=`openclaw-device-identity-v1`,O=5e3,k=new Set})))()}export{w as a,A as i,C as n,S as o,v as r,y as s,T as t};