openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.38 kB
JavaScript
import{n as e,r as t}from"./rolldown-runtime-CNOWq4Kh.js";import{Aa as n,el as r,lo as i}from"./control-ui-connection-Bfj9beF_.js";import{GM as a,HM as o,JM as s,KM as c,VM as l,WM as u,XM as d,YM as f,qM as p}from"./control-ui-boot-shared-DFTSUQQ0.js";import{a as m,s as h}from"./state-DiRAAGiU.js";var g,_;function v(){return(v=e((()=>{d(),g=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(c(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),f(r)}update(e){return a(this),this.iHash.update(e),this}digestInto(e){a(this),p(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()}},_=(()=>{let e=((e,t,n)=>new g(e,t).update(n).digest());return e.create=(e,t)=>new g(e,t),e})()})))()}var y=t({readFirstRunActivationReceipt:()=>C});function b(e){let t=t=>{t.key===D&&t.newValue===null&&t.oldValue&&e(t.oldValue)};A.add(e);let n=i(window,`storage`,{handleEvent:t});return()=>{A.delete(e),n()}}function x(e,t,n){try{let r=JSON.parse(n.getItem(O)??`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,c=a?``:e.gateway.snapshot.hello?.auth?.deviceToken;if(!a&&!c)return null;let l=[t.gatewayUrl,t.agentId,t.modelRef??``,t.kind,String(t.deadlineMs),i.token,i.password,i.bootstrapToken,i.bootstrapProfile??``,c??``,...t.modelTarget?[t.modelTarget]:[],...t.wizard?[t.wizard.sessionId,t.wizard.authChoice,t.wizard.authKind??``]:[]],u=new TextEncoder,d=l.map(e=>`${u.encode(e).length}:${e}`).join(`|`);return s(_(o,u.encode(r.privateKey),u.encode(d)))}catch{return null}}function S(e,t){try{let n=e.getItem(D);if((t===void 0||t&&n===JSON.stringify(t))&&(e.removeItem(D),n))for(let e of A)e(n)}catch{}}function C(e,t){let i=n();if(!i||e.gateway.snapshot.phase!==`connected`)return null;try{let n=i.getItem(D);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 S(i),null;let{owner:o,...s}=a;return x(e,s,i)===o?a:(S(i),null)}catch{return S(i),null}}function w(e){return Date.now()+m(e)+k}function T(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??w(t.kind)},a=x(e,n,i);if(!a)return null;let o={...n,owner:a};return i.setItem(D,JSON.stringify(o)),o}catch{return null}}function E(e){let t=n();t&&S(t,e)}var D,O,k,A;function j(){return(j=e((()=>{v(),l(),d(),h(),D=`openclaw.modelSetup.pendingActivation.v1`,O=`openclaw-device-identity-v1`,k=5e3,A=new Set})))()}export{T as a,j as i,w as n,C as o,y as r,b as s,E as t};