openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.74 kB
JavaScript
import{n as e,r as t}from"./rolldown-runtime-8BhlS34s.js";import{Ru as n}from"./control-ui-core-BncvAZjR.js";import{sn as r}from"./ui-DuRgK6kL.js";import{G as i,H as a,J as o,K as s,U as c,X as l,Z as u,q as d}from"./control-ui-boot-shared-em9-jnbz.js";import{a as f,o as p}from"./state-DYR1Gs_f.js";var m,h;function g(){return(g=e((()=>{u(),m=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(d(e),i(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),l(r)}update(e){return s(this),this.iHash.update(e),this}digestInto(e){s(this),o(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()}},h=(()=>{let e=((e,t,n)=>new m(e,t).update(n).digest());return e.create=(e,t)=>new m(e,t),e})()})))()}var _=t({resumeFirstRunActivation:()=>T});function v(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 y(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,o=a?``:e.gateway.snapshot.hello?.auth?.deviceToken;if(!a&&!o)return null;let s=[t.gatewayUrl,t.agentId,t.modelRef??``,t.kind,String(t.deadlineMs),i.token,i.password,i.bootstrapToken,i.bootstrapProfile??``,o??``,...t.modelTarget?[t.modelTarget]:[],...t.wizard?[t.wizard.sessionId,t.wizard.authChoice,t.wizard.authKind??``]:[]],l=new TextEncoder,u=s.map(e=>`${l.encode(e).length}:${e}`).join(`|`);return Array.from(h(c,l.encode(r.privateKey),l.encode(u))).map(e=>e.toString(16).padStart(2,`0`)).join(``)}catch{return null}}function b(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 x(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 b(i),null;let{owner:o,...s}=a;return y(e,s,i)===o?a:(b(i),null)}catch{return b(i),null}}function S(e){return Date.now()+f(e)+O}function C(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??S(t.kind)},a=y(e,n,i);if(!a)return null;let o={...n,owner:a};return i.setItem(E,JSON.stringify(o)),o}catch{return null}}function w(e){let t=n();t&&b(t,e)}function T(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()&&x(o)!==null&&e.redirect(),a()}var E,D,O,k;function A(){return(A=e((()=>{g(),a(),p(),E=`openclaw.modelSetup.pendingActivation.v1`,D=`openclaw-device-identity-v1`,O=5e3,k=new Set})))()}export{C as a,A as i,S as n,x as o,_ as r,v as s,w as t};