UNPKG

@gguf/claw

Version:

WhatsApp gateway CLI (Baileys web) with Pi RPC agent

126 lines (109 loc) 413 kB
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const a of s)if(a.type==="childList")for(const o of a.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function n(s){const a={};return s.integrity&&(a.integrity=s.integrity),s.referrerPolicy&&(a.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?a.credentials="include":s.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function i(s){if(s.ep)return;s.ep=!0;const a=n(s);fetch(s.href,a)}})();const cn=globalThis,Yi=cn.ShadowRoot&&(cn.ShadyCSS===void 0||cn.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Qi=Symbol(),aa=new WeakMap;let _o=class{constructor(t,n,i){if(this._$cssResult$=!0,i!==Qi)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=n}get styleSheet(){let t=this.o;const n=this.t;if(Yi&&t===void 0){const i=n!==void 0&&n.length===1;i&&(t=aa.get(n)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&aa.set(n,t))}return t}toString(){return this.cssText}};const kr=e=>new _o(typeof e=="string"?e:e+"",void 0,Qi),Ar=(e,...t)=>{const n=e.length===1?e[0]:t.reduce((i,s,a)=>i+(o=>{if(o._$cssResult$===!0)return o.cssText;if(typeof o=="number")return o;throw Error("Value passed to 'css' function must be a 'css' function result: "+o+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+e[a+1],e[0]);return new _o(n,e,Qi)},xr=(e,t)=>{if(Yi)e.adoptedStyleSheets=t.map(n=>n instanceof CSSStyleSheet?n:n.styleSheet);else for(const n of t){const i=document.createElement("style"),s=cn.litNonce;s!==void 0&&i.setAttribute("nonce",s),i.textContent=n.cssText,e.appendChild(i)}},oa=Yi?e=>e:e=>e instanceof CSSStyleSheet?(t=>{let n="";for(const i of t.cssRules)n+=i.cssText;return kr(n)})(e):e;const{is:Sr,defineProperty:_r,getOwnPropertyDescriptor:Cr,getOwnPropertyNames:Er,getOwnPropertySymbols:Tr,getPrototypeOf:Lr}=Object,xn=globalThis,la=xn.trustedTypes,Ir=la?la.emptyScript:"",Rr=xn.reactiveElementPolyfillSupport,_t=(e,t)=>e,pn={toAttribute(e,t){switch(t){case Boolean:e=e?Ir:null;break;case Object:case Array:e=e==null?e:JSON.stringify(e)}return e},fromAttribute(e,t){let n=e;switch(t){case Boolean:n=e!==null;break;case Number:n=e===null?null:Number(e);break;case Object:case Array:try{n=JSON.parse(e)}catch{n=null}}return n}},Ji=(e,t)=>!Sr(e,t),ra={attribute:!0,type:String,converter:pn,reflect:!1,useDefault:!1,hasChanged:Ji};Symbol.metadata??=Symbol("metadata"),xn.litPropertyMetadata??=new WeakMap;let nt=class extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,n=ra){if(n.state&&(n.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((n=Object.create(n)).wrapped=!0),this.elementProperties.set(t,n),!n.noAccessor){const i=Symbol(),s=this.getPropertyDescriptor(t,i,n);s!==void 0&&_r(this.prototype,t,s)}}static getPropertyDescriptor(t,n,i){const{get:s,set:a}=Cr(this.prototype,t)??{get(){return this[n]},set(o){this[n]=o}};return{get:s,set(o){const r=s?.call(this);a?.call(this,o),this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??ra}static _$Ei(){if(this.hasOwnProperty(_t("elementProperties")))return;const t=Lr(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(_t("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(_t("properties"))){const n=this.properties,i=[...Er(n),...Tr(n)];for(const s of i)this.createProperty(s,n[s])}const t=this[Symbol.metadata];if(t!==null){const n=litPropertyMetadata.get(t);if(n!==void 0)for(const[i,s]of n)this.elementProperties.set(i,s)}this._$Eh=new Map;for(const[n,i]of this.elementProperties){const s=this._$Eu(n,i);s!==void 0&&this._$Eh.set(s,n)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const n=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const s of i)n.unshift(oa(s))}else t!==void 0&&n.push(oa(t));return n}static _$Eu(t,n){const i=n.attribute;return i===!1?void 0:typeof i=="string"?i:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(t=>t(this))}addController(t){(this._$EO??=new Set).add(t),this.renderRoot!==void 0&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){const t=new Map,n=this.constructor.elementProperties;for(const i of n.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return xr(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(t=>t.hostConnected?.())}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach(t=>t.hostDisconnected?.())}attributeChangedCallback(t,n,i){this._$AK(t,i)}_$ET(t,n){const i=this.constructor.elementProperties.get(t),s=this.constructor._$Eu(t,i);if(s!==void 0&&i.reflect===!0){const a=(i.converter?.toAttribute!==void 0?i.converter:pn).toAttribute(n,i.type);this._$Em=t,a==null?this.removeAttribute(s):this.setAttribute(s,a),this._$Em=null}}_$AK(t,n){const i=this.constructor,s=i._$Eh.get(t);if(s!==void 0&&this._$Em!==s){const a=i.getPropertyOptions(s),o=typeof a.converter=="function"?{fromAttribute:a.converter}:a.converter?.fromAttribute!==void 0?a.converter:pn;this._$Em=s;const r=o.fromAttribute(n,a.type);this[s]=r??this._$Ej?.get(s)??r,this._$Em=null}}requestUpdate(t,n,i,s=!1,a){if(t!==void 0){const o=this.constructor;if(s===!1&&(a=this[t]),i??=o.getPropertyOptions(t),!((i.hasChanged??Ji)(a,n)||i.useDefault&&i.reflect&&a===this._$Ej?.get(t)&&!this.hasAttribute(o._$Eu(t,i))))return;this.C(t,n,i)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(t,n,{useDefault:i,reflect:s,wrapped:a},o){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,o??n??this[t]),a!==!0||o!==void 0)||(this._$AL.has(t)||(this.hasUpdated||i||(n=void 0),this._$AL.set(t,n)),s===!0&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(n){Promise.reject(n)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[s,a]of this._$Ep)this[s]=a;this._$Ep=void 0}const i=this.constructor.elementProperties;if(i.size>0)for(const[s,a]of i){const{wrapped:o}=a,r=this[s];o!==!0||this._$AL.has(s)||r===void 0||this.C(s,void 0,a,r)}}let t=!1;const n=this._$AL;try{t=this.shouldUpdate(n),t?(this.willUpdate(n),this._$EO?.forEach(i=>i.hostUpdate?.()),this.update(n)):this._$EM()}catch(i){throw t=!1,this._$EM(),i}t&&this._$AE(n)}willUpdate(t){}_$AE(t){this._$EO?.forEach(n=>n.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach(n=>this._$ET(n,this[n])),this._$EM()}updated(t){}firstUpdated(t){}};nt.elementStyles=[],nt.shadowRootOptions={mode:"open"},nt[_t("elementProperties")]=new Map,nt[_t("finalized")]=new Map,Rr?.({ReactiveElement:nt}),(xn.reactiveElementVersions??=[]).push("2.1.2");const Zi=globalThis,ca=e=>e,hn=Zi.trustedTypes,da=hn?hn.createPolicy("lit-html",{createHTML:e=>e}):void 0,Co="$lit$",Ce=`lit$${Math.random().toFixed(9).slice(2)}$`,Eo="?"+Ce,Mr=`<${Eo}>`,Ke=document,Rt=()=>Ke.createComment(""),Mt=e=>e===null||typeof e!="object"&&typeof e!="function",Xi=Array.isArray,Pr=e=>Xi(e)||typeof e?.[Symbol.iterator]=="function",Xn=`[ \f\r]`,ht=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,ua=/-->/g,fa=/>/g,Fe=RegExp(`>|${Xn}(?:([^\\s"'>=/]+)(${Xn}*=${Xn}*(?:[^ \f\r"'\`<>=]|("|')|))|$)`,"g"),ga=/'/g,pa=/"/g,To=/^(?:script|style|textarea|title)$/i,Fr=e=>(t,...n)=>({_$litType$:e,strings:t,values:n}),l=Fr(1),Te=Symbol.for("lit-noChange"),p=Symbol.for("lit-nothing"),ha=new WeakMap,Be=Ke.createTreeWalker(Ke,129);function Lo(e,t){if(!Xi(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return da!==void 0?da.createHTML(t):t}const Nr=(e,t)=>{const n=e.length-1,i=[];let s,a=t===2?"<svg>":t===3?"<math>":"",o=ht;for(let r=0;r<n;r++){const c=e[r];let u,f,g=-1,m=0;for(;m<c.length&&(o.lastIndex=m,f=o.exec(c),f!==null);)m=o.lastIndex,o===ht?f[1]==="!--"?o=ua:f[1]!==void 0?o=fa:f[2]!==void 0?(To.test(f[2])&&(s=RegExp("</"+f[2],"g")),o=Fe):f[3]!==void 0&&(o=Fe):o===Fe?f[0]===">"?(o=s??ht,g=-1):f[1]===void 0?g=-2:(g=o.lastIndex-f[2].length,u=f[1],o=f[3]===void 0?Fe:f[3]==='"'?pa:ga):o===pa||o===ga?o=Fe:o===ua||o===fa?o=ht:(o=Fe,s=void 0);const v=o===Fe&&e[r+1].startsWith("/>")?" ":"";a+=o===ht?c+Mr:g>=0?(i.push(u),c.slice(0,g)+Co+c.slice(g)+Ce+v):c+Ce+(g===-2?r:v)}return[Lo(e,a+(e[n]||"<?>")+(t===2?"</svg>":t===3?"</math>":"")),i]};let $i=class Io{constructor({strings:t,_$litType$:n},i){let s;this.parts=[];let a=0,o=0;const r=t.length-1,c=this.parts,[u,f]=Nr(t,n);if(this.el=Io.createElement(u,i),Be.currentNode=this.el.content,n===2||n===3){const g=this.el.content.firstChild;g.replaceWith(...g.childNodes)}for(;(s=Be.nextNode())!==null&&c.length<r;){if(s.nodeType===1){if(s.hasAttributes())for(const g of s.getAttributeNames())if(g.endsWith(Co)){const m=f[o++],v=s.getAttribute(g).split(Ce),d=/([.?@])?(.*)/.exec(m);c.push({type:1,index:a,name:d[2],strings:v,ctor:d[1]==="."?Or:d[1]==="?"?Br:d[1]==="@"?Ur:_n}),s.removeAttribute(g)}else g.startsWith(Ce)&&(c.push({type:6,index:a}),s.removeAttribute(g));if(To.test(s.tagName)){const g=s.textContent.split(Ce),m=g.length-1;if(m>0){s.textContent=hn?hn.emptyScript:"";for(let v=0;v<m;v++)s.append(g[v],Rt()),Be.nextNode(),c.push({type:2,index:++a});s.append(g[m],Rt())}}}else if(s.nodeType===8)if(s.data===Eo)c.push({type:2,index:a});else{let g=-1;for(;(g=s.data.indexOf(Ce,g+1))!==-1;)c.push({type:7,index:a}),g+=Ce.length-1}a++}}static createElement(t,n){const i=Ke.createElement("template");return i.innerHTML=t,i}};function at(e,t,n=e,i){if(t===Te)return t;let s=i!==void 0?n._$Co?.[i]:n._$Cl;const a=Mt(t)?void 0:t._$litDirective$;return s?.constructor!==a&&(s?._$AO?.(!1),a===void 0?s=void 0:(s=new a(e),s._$AT(e,n,i)),i!==void 0?(n._$Co??=[])[i]=s:n._$Cl=s),s!==void 0&&(t=at(e,s._$AS(e,t.values),s,i)),t}class Dr{constructor(t,n){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=n}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:n},parts:i}=this._$AD,s=(t?.creationScope??Ke).importNode(n,!0);Be.currentNode=s;let a=Be.nextNode(),o=0,r=0,c=i[0];for(;c!==void 0;){if(o===c.index){let u;c.type===2?u=new Sn(a,a.nextSibling,this,t):c.type===1?u=new c.ctor(a,c.name,c.strings,this,t):c.type===6&&(u=new Kr(a,this,t)),this._$AV.push(u),c=i[++r]}o!==c?.index&&(a=Be.nextNode(),o++)}return Be.currentNode=Ke,s}p(t){let n=0;for(const i of this._$AV)i!==void 0&&(i.strings!==void 0?(i._$AI(t,i,n),n+=i.strings.length-2):i._$AI(t[n])),n++}}let Sn=class Ro{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,n,i,s){this.type=2,this._$AH=p,this._$AN=void 0,this._$AA=t,this._$AB=n,this._$AM=i,this.options=s,this._$Cv=s?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const n=this._$AM;return n!==void 0&&t?.nodeType===11&&(t=n.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,n=this){t=at(this,t,n),Mt(t)?t===p||t==null||t===""?(this._$AH!==p&&this._$AR(),this._$AH=p):t!==this._$AH&&t!==Te&&this._(t):t._$litType$!==void 0?this.$(t):t.nodeType!==void 0?this.T(t):Pr(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==p&&Mt(this._$AH)?this._$AA.nextSibling.data=t:this.T(Ke.createTextNode(t)),this._$AH=t}$(t){const{values:n,_$litType$:i}=t,s=typeof i=="number"?this._$AC(t):(i.el===void 0&&(i.el=$i.createElement(Lo(i.h,i.h[0]),this.options)),i);if(this._$AH?._$AD===s)this._$AH.p(n);else{const a=new Dr(s,this),o=a.u(this.options);a.p(n),this.T(o),this._$AH=a}}_$AC(t){let n=ha.get(t.strings);return n===void 0&&ha.set(t.strings,n=new $i(t)),n}k(t){Xi(this._$AH)||(this._$AH=[],this._$AR());const n=this._$AH;let i,s=0;for(const a of t)s===n.length?n.push(i=new Ro(this.O(Rt()),this.O(Rt()),this,this.options)):i=n[s],i._$AI(a),s++;s<n.length&&(this._$AR(i&&i._$AB.nextSibling,s),n.length=s)}_$AR(t=this._$AA.nextSibling,n){for(this._$AP?.(!1,!0,n);t!==this._$AB;){const i=ca(t).nextSibling;ca(t).remove(),t=i}}setConnected(t){this._$AM===void 0&&(this._$Cv=t,this._$AP?.(t))}};class _n{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,n,i,s,a){this.type=1,this._$AH=p,this._$AN=void 0,this.element=t,this.name=n,this._$AM=s,this.options=a,i.length>2||i[0]!==""||i[1]!==""?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=p}_$AI(t,n=this,i,s){const a=this.strings;let o=!1;if(a===void 0)t=at(this,t,n,0),o=!Mt(t)||t!==this._$AH&&t!==Te,o&&(this._$AH=t);else{const r=t;let c,u;for(t=a[0],c=0;c<a.length-1;c++)u=at(this,r[i+c],n,c),u===Te&&(u=this._$AH[c]),o||=!Mt(u)||u!==this._$AH[c],u===p?t=p:t!==p&&(t+=(u??"")+a[c+1]),this._$AH[c]=u}o&&!s&&this.j(t)}j(t){t===p?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}let Or=class extends _n{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===p?void 0:t}},Br=class extends _n{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==p)}},Ur=class extends _n{constructor(t,n,i,s,a){super(t,n,i,s,a),this.type=5}_$AI(t,n=this){if((t=at(this,t,n,0)??p)===Te)return;const i=this._$AH,s=t===p&&i!==p||t.capture!==i.capture||t.once!==i.once||t.passive!==i.passive,a=t!==p&&(i===p||s);s&&this.element.removeEventListener(this.name,this,i),a&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){typeof this._$AH=="function"?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}},Kr=class{constructor(t,n,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=n,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){at(this,t)}};const zr={I:Sn},Hr=Zi.litHtmlPolyfillSupport;Hr?.($i,Sn),(Zi.litHtmlVersions??=[]).push("3.3.2");const jr=(e,t,n)=>{const i=n?.renderBefore??t;let s=i._$litPart$;if(s===void 0){const a=n?.renderBefore??null;i._$litPart$=s=new Sn(t.insertBefore(Rt(),a),a,void 0,n??{})}return s._$AI(e),s};const es=globalThis;let st=class extends nt{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const n=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=jr(n,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return Te}};st._$litElement$=!0,st.finalized=!0,es.litElementHydrateSupport?.({LitElement:st});const Gr=es.litElementPolyfillSupport;Gr?.({LitElement:st});(es.litElementVersions??=[]).push("4.2.2");const Mo=e=>(t,n)=>{n!==void 0?n.addInitializer(()=>{customElements.define(e,t)}):customElements.define(e,t)};const Wr={attribute:!0,type:String,converter:pn,reflect:!1,hasChanged:Ji},qr=(e=Wr,t,n)=>{const{kind:i,metadata:s}=n;let a=globalThis.litPropertyMetadata.get(s);if(a===void 0&&globalThis.litPropertyMetadata.set(s,a=new Map),i==="setter"&&((e=Object.create(e)).wrapped=!0),a.set(n.name,e),i==="accessor"){const{name:o}=n;return{set(r){const c=t.get.call(this);t.set.call(this,r),this.requestUpdate(o,c,e,!0,r)},init(r){return r!==void 0&&this.C(o,void 0,e,r),r}}}if(i==="setter"){const{name:o}=n;return function(r){const c=this[o];t.call(this,r),this.requestUpdate(o,c,e,!0,r)}}throw Error("Unsupported decorator location: "+i)};function Cn(e){return(t,n)=>typeof n=="object"?qr(e,t,n):((i,s,a)=>{const o=s.hasOwnProperty(a);return s.constructor.createProperty(a,i),o?Object.getOwnPropertyDescriptor(s,a):void 0})(e,t,n)}function $(e){return Cn({...e,state:!0,attribute:!1})}async function ne(e,t){if(!(!e.client||!e.connected)&&!e.channelsLoading){e.channelsLoading=!0,e.channelsError=null;try{const n=await e.client.request("channels.status",{probe:t,timeoutMs:8e3});e.channelsSnapshot=n,e.channelsLastSuccess=Date.now()}catch(n){e.channelsError=String(n)}finally{e.channelsLoading=!1}}}async function Vr(e,t){if(!(!e.client||!e.connected||e.whatsappBusy)){e.whatsappBusy=!0;try{const n=await e.client.request("web.login.start",{force:t,timeoutMs:3e4});e.whatsappLoginMessage=n.message??null,e.whatsappLoginQrDataUrl=n.qrDataUrl??null,e.whatsappLoginConnected=null}catch(n){e.whatsappLoginMessage=String(n),e.whatsappLoginQrDataUrl=null,e.whatsappLoginConnected=null}finally{e.whatsappBusy=!1}}}async function Yr(e){if(!(!e.client||!e.connected||e.whatsappBusy)){e.whatsappBusy=!0;try{const t=await e.client.request("web.login.wait",{timeoutMs:12e4});e.whatsappLoginMessage=t.message??null,e.whatsappLoginConnected=t.connected??null,t.connected&&(e.whatsappLoginQrDataUrl=null)}catch(t){e.whatsappLoginMessage=String(t),e.whatsappLoginConnected=null}finally{e.whatsappBusy=!1}}}async function Qr(e){if(!(!e.client||!e.connected||e.whatsappBusy)){e.whatsappBusy=!0;try{await e.client.request("channels.logout",{channel:"whatsapp"}),e.whatsappLoginMessage="Logged out.",e.whatsappLoginQrDataUrl=null,e.whatsappLoginConnected=null}catch(t){e.whatsappLoginMessage=String(t)}finally{e.whatsappBusy=!1}}}function ze(e){return typeof structuredClone=="function"?structuredClone(e):JSON.parse(JSON.stringify(e))}function ot(e){return`${JSON.stringify(e,null,2).trimEnd()} `}function Po(e,t,n){if(t.length===0)return;let i=e;for(let a=0;a<t.length-1;a+=1){const o=t[a],r=t[a+1];if(typeof o=="number"){if(!Array.isArray(i))return;i[o]==null&&(i[o]=typeof r=="number"?[]:{}),i=i[o]}else{if(typeof i!="object"||i==null)return;const c=i;c[o]==null&&(c[o]=typeof r=="number"?[]:{}),i=c[o]}}const s=t[t.length-1];if(typeof s=="number"){Array.isArray(i)&&(i[s]=n);return}typeof i=="object"&&i!=null&&(i[s]=n)}function Fo(e,t){if(t.length===0)return;let n=e;for(let s=0;s<t.length-1;s+=1){const a=t[s];if(typeof a=="number"){if(!Array.isArray(n))return;n=n[a]}else{if(typeof n!="object"||n==null)return;n=n[a]}if(n==null)return}const i=t[t.length-1];if(typeof i=="number"){Array.isArray(n)&&n.splice(i,1);return}typeof n=="object"&&n!=null&&delete n[i]}async function de(e){if(!(!e.client||!e.connected)){e.configLoading=!0,e.lastError=null;try{const t=await e.client.request("config.get",{});Zr(e,t)}catch(t){e.lastError=String(t)}finally{e.configLoading=!1}}}async function No(e){if(!(!e.client||!e.connected)&&!e.configSchemaLoading){e.configSchemaLoading=!0;try{const t=await e.client.request("config.schema",{});Jr(e,t)}catch(t){e.lastError=String(t)}finally{e.configSchemaLoading=!1}}}function Jr(e,t){e.configSchema=t.schema??null,e.configUiHints=t.uiHints??{},e.configSchemaVersion=t.version??null}function Zr(e,t){e.configSnapshot=t;const n=typeof t.raw=="string"?t.raw:t.config&&typeof t.config=="object"?ot(t.config):e.configRaw;!e.configFormDirty||e.configFormMode==="raw"?e.configRaw=n:e.configForm?e.configRaw=ot(e.configForm):e.configRaw=n,e.configValid=typeof t.valid=="boolean"?t.valid:null,e.configIssues=Array.isArray(t.issues)?t.issues:[],e.configFormDirty||(e.configForm=ze(t.config??{}),e.configFormOriginal=ze(t.config??{}),e.configRawOriginal=n)}async function dn(e){if(!(!e.client||!e.connected)){e.configSaving=!0,e.lastError=null;try{const t=e.configFormMode==="form"&&e.configForm?ot(e.configForm):e.configRaw,n=e.configSnapshot?.hash;if(!n){e.lastError="Config hash missing; reload and retry.";return}await e.client.request("config.set",{raw:t,baseHash:n}),e.configFormDirty=!1,await de(e)}catch(t){e.lastError=String(t)}finally{e.configSaving=!1}}}async function Xr(e){if(!(!e.client||!e.connected)){e.configApplying=!0,e.lastError=null;try{const t=e.configFormMode==="form"&&e.configForm?ot(e.configForm):e.configRaw,n=e.configSnapshot?.hash;if(!n){e.lastError="Config hash missing; reload and retry.";return}await e.client.request("config.apply",{raw:t,baseHash:n,sessionKey:e.applySessionKey}),e.configFormDirty=!1,await de(e)}catch(t){e.lastError=String(t)}finally{e.configApplying=!1}}}async function ec(e){if(!(!e.client||!e.connected)){e.updateRunning=!0,e.lastError=null;try{await e.client.request("update.run",{sessionKey:e.applySessionKey})}catch(t){e.lastError=String(t)}finally{e.updateRunning=!1}}}function ie(e,t,n){const i=ze(e.configForm??e.configSnapshot?.config??{});Po(i,t,n),e.configForm=i,e.configFormDirty=!0,e.configFormMode==="form"&&(e.configRaw=ot(i))}function $e(e,t){const n=ze(e.configForm??e.configSnapshot?.config??{});Fo(n,t),e.configForm=n,e.configFormDirty=!0,e.configFormMode==="form"&&(e.configRaw=ot(n))}function tc(e){const{values:t,original:n}=e;return t.name!==n.name||t.displayName!==n.displayName||t.about!==n.about||t.picture!==n.picture||t.banner!==n.banner||t.website!==n.website||t.nip05!==n.nip05||t.lud16!==n.lud16}function nc(e){const{state:t,callbacks:n,accountId:i}=e,s=tc(t),a=(r,c,u={})=>{const{type:f="text",placeholder:g,maxLength:m,help:v}=u,d=t.values[r]??"",y=t.fieldErrors[r],k=`nostr-profile-${r}`;return f==="textarea"?l` <div class="form-field" style="margin-bottom: 12px;"> <label for="${k}" style="display: block; margin-bottom: 4px; font-weight: 500;"> ${c} </label> <textarea id="${k}" .value=${d} placeholder=${g??""} maxlength=${m??2e3} rows="3" style="width: 100%; padding: 8px; border: 1px solid var(--border-color); border-radius: 4px; resize: vertical; font-family: inherit;" @input=${A=>{const _=A.target;n.onFieldChange(r,_.value)}} ?disabled=${t.saving} ></textarea> ${v?l`<div style="font-size: 12px; color: var(--text-muted); margin-top: 2px;">${v}</div>`:p} ${y?l`<div style="font-size: 12px; color: var(--danger-color); margin-top: 2px;">${y}</div>`:p} </div> `:l` <div class="form-field" style="margin-bottom: 12px;"> <label for="${k}" style="display: block; margin-bottom: 4px; font-weight: 500;"> ${c} </label> <input id="${k}" type=${f} .value=${d} placeholder=${g??""} maxlength=${m??256} style="width: 100%; padding: 8px; border: 1px solid var(--border-color); border-radius: 4px;" @input=${A=>{const _=A.target;n.onFieldChange(r,_.value)}} ?disabled=${t.saving} /> ${v?l`<div style="font-size: 12px; color: var(--text-muted); margin-top: 2px;">${v}</div>`:p} ${y?l`<div style="font-size: 12px; color: var(--danger-color); margin-top: 2px;">${y}</div>`:p} </div> `},o=()=>{const r=t.values.picture;return r?l` <div style="margin-bottom: 12px;"> <img src=${r} alt="Profile picture preview" style="max-width: 80px; max-height: 80px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border-color);" @error=${c=>{const u=c.target;u.style.display="none"}} @load=${c=>{const u=c.target;u.style.display="block"}} /> </div> `:p};return l` <div class="nostr-profile-form" style="padding: 16px; background: var(--bg-secondary); border-radius: 8px; margin-top: 12px;"> <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;"> <div style="font-weight: 600; font-size: 16px;">Edit Profile</div> <div style="font-size: 12px; color: var(--text-muted);">Account: ${i}</div> </div> ${t.error?l`<div class="callout danger" style="margin-bottom: 12px;">${t.error}</div>`:p} ${t.success?l`<div class="callout success" style="margin-bottom: 12px;">${t.success}</div>`:p} ${o()} ${a("name","Username",{placeholder:"satoshi",maxLength:256,help:"Short username (e.g., satoshi)"})} ${a("displayName","Display Name",{placeholder:"Satoshi Nakamoto",maxLength:256,help:"Your full display name"})} ${a("about","Bio",{type:"textarea",placeholder:"Tell people about yourself...",maxLength:2e3,help:"A brief bio or description"})} ${a("picture","Avatar URL",{type:"url",placeholder:"https://example.com/avatar.jpg",help:"HTTPS URL to your profile picture"})} ${t.showAdvanced?l` <div style="border-top: 1px solid var(--border-color); padding-top: 12px; margin-top: 12px;"> <div style="font-weight: 500; margin-bottom: 12px; color: var(--text-muted);">Advanced</div> ${a("banner","Banner URL",{type:"url",placeholder:"https://example.com/banner.jpg",help:"HTTPS URL to a banner image"})} ${a("website","Website",{type:"url",placeholder:"https://example.com",help:"Your personal website"})} ${a("nip05","NIP-05 Identifier",{placeholder:"you@example.com",help:"Verifiable identifier (e.g., you@domain.com)"})} ${a("lud16","Lightning Address",{placeholder:"you@getalby.com",help:"Lightning address for tips (LUD-16)"})} </div> `:p} <div style="display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap;"> <button class="btn primary" @click=${n.onSave} ?disabled=${t.saving||!s} > ${t.saving?"Saving...":"Save & Publish"} </button> <button class="btn" @click=${n.onImport} ?disabled=${t.importing||t.saving} > ${t.importing?"Importing...":"Import from Relays"} </button> <button class="btn" @click=${n.onToggleAdvanced} > ${t.showAdvanced?"Hide Advanced":"Show Advanced"} </button> <button class="btn" @click=${n.onCancel} ?disabled=${t.saving} > Cancel </button> </div> ${s?l` <div style="font-size: 12px; color: var(--warning-color); margin-top: 8px"> You have unsaved changes </div> `:p} </div> `}function ic(e){const t={name:e?.name??"",displayName:e?.displayName??"",about:e?.about??"",picture:e?.picture??"",banner:e?.banner??"",website:e?.website??"",nip05:e?.nip05??"",lud16:e?.lud16??""};return{values:t,original:{...t},saving:!1,importing:!1,error:null,success:null,fieldErrors:{},showAdvanced:!!(e?.banner||e?.website||e?.nip05||e?.lud16)}}async function sc(e,t){await Vr(e,t),await ne(e,!0)}async function ac(e){await Yr(e),await ne(e,!0)}async function oc(e){await Qr(e),await ne(e,!0)}async function lc(e){await dn(e),await de(e),await ne(e,!0)}async function rc(e){await de(e),await ne(e,!0)}function cc(e){if(!Array.isArray(e))return{};const t={};for(const n of e){if(typeof n!="string")continue;const[i,...s]=n.split(":");if(!i||s.length===0)continue;const a=i.trim(),o=s.join(":").trim();a&&o&&(t[a]=o)}return t}function Do(e){return(e.channelsSnapshot?.channelAccounts?.nostr??[])[0]?.accountId??e.nostrProfileAccountId??"default"}function Oo(e,t=""){return`/api/channels/nostr/${encodeURIComponent(e)}/profile${t}`}function dc(e,t,n){e.nostrProfileAccountId=t,e.nostrProfileFormState=ic(n??void 0)}function uc(e){e.nostrProfileFormState=null,e.nostrProfileAccountId=null}function fc(e,t,n){const i=e.nostrProfileFormState;i&&(e.nostrProfileFormState={...i,values:{...i.values,[t]:n},fieldErrors:{...i.fieldErrors,[t]:""}})}function gc(e){const t=e.nostrProfileFormState;t&&(e.nostrProfileFormState={...t,showAdvanced:!t.showAdvanced})}async function pc(e){const t=e.nostrProfileFormState;if(!t||t.saving)return;const n=Do(e);e.nostrProfileFormState={...t,saving:!0,error:null,success:null,fieldErrors:{}};try{const i=await fetch(Oo(n),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.values)}),s=await i.json().catch(()=>null);if(!i.ok||s?.ok===!1||!s){const a=s?.error??`Profile update failed (${i.status})`;e.nostrProfileFormState={...t,saving:!1,error:a,success:null,fieldErrors:cc(s?.details)};return}if(!s.persisted){e.nostrProfileFormState={...t,saving:!1,error:"Profile publish failed on all relays.",success:null};return}e.nostrProfileFormState={...t,saving:!1,error:null,success:"Profile published to relays.",fieldErrors:{},original:{...t.values}},await ne(e,!0)}catch(i){e.nostrProfileFormState={...t,saving:!1,error:`Profile update failed: ${String(i)}`,success:null}}}async function hc(e){const t=e.nostrProfileFormState;if(!t||t.importing)return;const n=Do(e);e.nostrProfileFormState={...t,importing:!0,error:null,success:null};try{const i=await fetch(Oo(n,"/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({autoMerge:!0})}),s=await i.json().catch(()=>null);if(!i.ok||s?.ok===!1||!s){const c=s?.error??`Profile import failed (${i.status})`;e.nostrProfileFormState={...t,importing:!1,error:c,success:null};return}const a=s.merged??s.imported??null,o=a?{...t.values,...a}:t.values,r=!!(o.banner||o.website||o.nip05||o.lud16);e.nostrProfileFormState={...t,importing:!1,values:o,error:null,success:s.saved?"Profile imported from relays. Review and publish.":"Profile imported. Review and publish.",showAdvanced:r},s.saved&&await ne(e,!0)}catch(i){e.nostrProfileFormState={...t,importing:!1,error:`Profile import failed: ${String(i)}`,success:null}}}function Bo(e){const t=(e??"").trim();if(!t)return null;const n=t.split(":").filter(Boolean);if(n.length<3||n[0]!=="agent")return null;const i=n[1]?.trim(),s=n.slice(2).join(":");return!i||!s?null:{agentId:i,rest:s}}const ki=450;function Bt(e,t=!1){e.chatScrollFrame&&cancelAnimationFrame(e.chatScrollFrame),e.chatScrollTimeout!=null&&(clearTimeout(e.chatScrollTimeout),e.chatScrollTimeout=null);const n=()=>{const i=e.querySelector(".chat-thread");if(i){const s=getComputedStyle(i).overflowY;if(s==="auto"||s==="scroll"||i.scrollHeight-i.clientHeight>1)return i}return document.scrollingElement??document.documentElement};e.updateComplete.then(()=>{e.chatScrollFrame=requestAnimationFrame(()=>{e.chatScrollFrame=null;const i=n();if(!i)return;const s=i.scrollHeight-i.scrollTop-i.clientHeight,a=t&&!e.chatHasAutoScrolled;if(!(a||e.chatUserNearBottom||s<ki)){e.chatNewMessagesBelow=!0;return}a&&(e.chatHasAutoScrolled=!0),i.scrollTop=i.scrollHeight,e.chatUserNearBottom=!0,e.chatNewMessagesBelow=!1;const r=a?150:120;e.chatScrollTimeout=window.setTimeout(()=>{e.chatScrollTimeout=null;const c=n();if(!c)return;const u=c.scrollHeight-c.scrollTop-c.clientHeight;(a||e.chatUserNearBottom||u<ki)&&(c.scrollTop=c.scrollHeight,e.chatUserNearBottom=!0)},r)})})}function Uo(e,t=!1){e.logsScrollFrame&&cancelAnimationFrame(e.logsScrollFrame),e.updateComplete.then(()=>{e.logsScrollFrame=requestAnimationFrame(()=>{e.logsScrollFrame=null;const n=e.querySelector(".log-stream");if(!n)return;const i=n.scrollHeight-n.scrollTop-n.clientHeight;(t||i<80)&&(n.scrollTop=n.scrollHeight)})})}function vc(e,t){const n=t.currentTarget;if(!n)return;const i=n.scrollHeight-n.scrollTop-n.clientHeight;e.chatUserNearBottom=i<ki,e.chatUserNearBottom&&(e.chatNewMessagesBelow=!1)}function mc(e,t){const n=t.currentTarget;if(!n)return;const i=n.scrollHeight-n.scrollTop-n.clientHeight;e.logsAtBottom=i<80}function va(e){e.chatHasAutoScrolled=!1,e.chatUserNearBottom=!0,e.chatNewMessagesBelow=!1}function yc(e,t){if(e.length===0)return;const n=new Blob([`${e.join(` `)} `],{type:"text/plain"}),i=URL.createObjectURL(n),s=document.createElement("a"),a=new Date().toISOString().slice(0,19).replace(/[:T]/g,"-");s.href=i,s.download=`openclaw-logs-${t}-${a}.log`,s.click(),URL.revokeObjectURL(i)}function bc(e){if(typeof ResizeObserver>"u")return;const t=e.querySelector(".topbar");if(!t)return;const n=()=>{const{height:i}=t.getBoundingClientRect();e.style.setProperty("--topbar-height",`${i}px`)};n(),e.topbarObserver=new ResizeObserver(()=>n()),e.topbarObserver.observe(t)}async function En(e){if(!(!e.client||!e.connected)&&!e.debugLoading){e.debugLoading=!0;try{const[t,n,i,s]=await Promise.all([e.client.request("status",{}),e.client.request("health",{}),e.client.request("models.list",{}),e.client.request("last-heartbeat",{})]);e.debugStatus=t,e.debugHealth=n;const a=i;e.debugModels=Array.isArray(a?.models)?a?.models:[],e.debugHeartbeat=s}catch(t){e.debugCallError=String(t)}finally{e.debugLoading=!1}}}async function wc(e){if(!(!e.client||!e.connected)){e.debugCallError=null,e.debugCallResult=null;try{const t=e.debugCallParams.trim()?JSON.parse(e.debugCallParams):{},n=await e.client.request(e.debugCallMethod.trim(),t);e.debugCallResult=JSON.stringify(n,null,2)}catch(t){e.debugCallError=String(t)}}}const $c=2e3,kc=new Set(["trace","debug","info","warn","error","fatal"]);function Ac(e){if(typeof e!="string")return null;const t=e.trim();if(!t.startsWith("{")||!t.endsWith("}"))return null;try{const n=JSON.parse(t);return!n||typeof n!="object"?null:n}catch{return null}}function xc(e){if(typeof e!="string")return null;const t=e.toLowerCase();return kc.has(t)?t:null}function Sc(e){if(!e.trim())return{raw:e,message:e};try{const t=JSON.parse(e),n=t&&typeof t._meta=="object"&&t._meta!==null?t._meta:null,i=typeof t.time=="string"?t.time:typeof n?.date=="string"?n?.date:null,s=xc(n?.logLevelName??n?.level),a=typeof t[0]=="string"?t[0]:typeof n?.name=="string"?n?.name:null,o=Ac(a);let r=null;o&&(typeof o.subsystem=="string"?r=o.subsystem:typeof o.module=="string"&&(r=o.module)),!r&&a&&a.length<120&&(r=a);let c=null;return typeof t[1]=="string"?c=t[1]:!o&&typeof t[0]=="string"?c=t[0]:typeof t.message=="string"&&(c=t.message),{raw:e,time:i,level:s,subsystem:r,message:c??e,meta:n??void 0}}catch{return{raw:e,message:e}}}async function ts(e,t){if(!(!e.client||!e.connected)&&!(e.logsLoading&&!t?.quiet)){t?.quiet||(e.logsLoading=!0),e.logsError=null;try{const i=await e.client.request("logs.tail",{cursor:t?.reset?void 0:e.logsCursor??void 0,limit:e.logsLimit,maxBytes:e.logsMaxBytes}),a=(Array.isArray(i.lines)?i.lines.filter(r=>typeof r=="string"):[]).map(Sc),o=!!(t?.reset||i.reset||e.logsCursor==null);e.logsEntries=o?a:[...e.logsEntries,...a].slice(-$c),typeof i.cursor=="number"&&(e.logsCursor=i.cursor),typeof i.file=="string"&&(e.logsFile=i.file),e.logsTruncated=!!i.truncated,e.logsLastFetchAt=Date.now()}catch(n){e.logsError=String(n)}finally{t?.quiet||(e.logsLoading=!1)}}}async function Tn(e,t){if(!(!e.client||!e.connected)&&!e.nodesLoading){e.nodesLoading=!0,t?.quiet||(e.lastError=null);try{const n=await e.client.request("node.list",{});e.nodes=Array.isArray(n.nodes)?n.nodes:[]}catch(n){t?.quiet||(e.lastError=String(n))}finally{e.nodesLoading=!1}}}function _c(e){e.nodesPollInterval==null&&(e.nodesPollInterval=window.setInterval(()=>{Tn(e,{quiet:!0})},5e3))}function Cc(e){e.nodesPollInterval!=null&&(clearInterval(e.nodesPollInterval),e.nodesPollInterval=null)}function ns(e){e.logsPollInterval==null&&(e.logsPollInterval=window.setInterval(()=>{e.tab==="logs"&&ts(e,{quiet:!0})},2e3))}function is(e){e.logsPollInterval!=null&&(clearInterval(e.logsPollInterval),e.logsPollInterval=null)}function ss(e){e.debugPollInterval==null&&(e.debugPollInterval=window.setInterval(()=>{e.tab==="debug"&&En(e)},3e3))}function as(e){e.debugPollInterval!=null&&(clearInterval(e.debugPollInterval),e.debugPollInterval=null)}async function Ko(e,t){if(!(!e.client||!e.connected||e.agentIdentityLoading)&&!e.agentIdentityById[t]){e.agentIdentityLoading=!0,e.agentIdentityError=null;try{const n=await e.client.request("agent.identity.get",{agentId:t});n&&(e.agentIdentityById={...e.agentIdentityById,[t]:n})}catch(n){e.agentIdentityError=String(n)}finally{e.agentIdentityLoading=!1}}}async function zo(e,t){if(!e.client||!e.connected||e.agentIdentityLoading)return;const n=t.filter(i=>!e.agentIdentityById[i]);if(n.length!==0){e.agentIdentityLoading=!0,e.agentIdentityError=null;try{for(const i of n){const s=await e.client.request("agent.identity.get",{agentId:i});s&&(e.agentIdentityById={...e.agentIdentityById,[i]:s})}}catch(i){e.agentIdentityError=String(i)}finally{e.agentIdentityLoading=!1}}}async function un(e,t){if(!(!e.client||!e.connected)&&!e.agentSkillsLoading){e.agentSkillsLoading=!0,e.agentSkillsError=null;try{const n=await e.client.request("skills.status",{agentId:t});n&&(e.agentSkillsReport=n,e.agentSkillsAgentId=t)}catch(n){e.agentSkillsError=String(n)}finally{e.agentSkillsLoading=!1}}}async function os(e){if(!(!e.client||!e.connected)&&!e.agentsLoading){e.agentsLoading=!0,e.agentsError=null;try{const t=await e.client.request("agents.list",{});if(t){e.agentsList=t;const n=e.agentsSelectedId,i=t.agents.some(s=>s.id===n);(!n||!i)&&(e.agentsSelectedId=t.defaultId??t.agents[0]?.id??null)}}catch(t){e.agentsError=String(t)}finally{e.agentsLoading=!1}}}const Ec=/<\s*\/?\s*(?:think(?:ing)?|thought|antthinking|final)\b/i,Zt=/<\s*\/?\s*final\b[^<>]*>/gi,ma=/<\s*(\/?)\s*(?:think(?:ing)?|thought|antthinking)\b[^<>]*>/gi;function ya(e){const t=[],n=/(^|\n)(```|~~~)[^\n]*\n[\s\S]*?(?:\n\2(?:\n|$)|$)/g;for(const s of e.matchAll(n)){const a=(s.index??0)+s[1].length;t.push({start:a,end:a+s[0].length-s[1].length})}const i=/`+[^`]+`+/g;for(const s of e.matchAll(i)){const a=s.index??0,o=a+s[0].length;t.some(c=>a>=c.start&&o<=c.end)||t.push({start:a,end:o})}return t.sort((s,a)=>s.start-a.start),t}function ba(e,t){return t.some(n=>e>=n.start&&e<n.end)}function Tc(e,t){return e.trimStart()}function Lc(e,t){if(!e||!Ec.test(e))return e;let n=e;if(Zt.test(n)){Zt.lastIndex=0;const r=[],c=ya(n);for(const u of n.matchAll(Zt)){const f=u.index??0;r.push({start:f,length:u[0].length,inCode:ba(f,c)})}for(let u=r.length-1;u>=0;u--){const f=r[u];f.inCode||(n=n.slice(0,f.start)+n.slice(f.start+f.length))}}else Zt.lastIndex=0;const i=ya(n);ma.lastIndex=0;let s="",a=0,o=!1;for(const r of n.matchAll(ma)){const c=r.index??0,u=r[1]==="/";ba(c,i)||(o?u&&(o=!1):(s+=n.slice(a,c),u||(o=!0)),a=c+r[0].length)}return s+=n.slice(a),Tc(s)}function Pt(e){return!e&&e!==0?"n/a":new Date(e).toLocaleString()}function N(e){if(!e&&e!==0)return"n/a";const t=Date.now()-e,n=Math.abs(t),i=t<0?"from now":"ago",s=Math.round(n/1e3);if(s<60)return t<0?"just now":`${s}s ago`;const a=Math.round(s/60);if(a<60)return`${a}m ${i}`;const o=Math.round(a/60);return o<48?`${o}h ${i}`:`${Math.round(o/24)}d ${i}`}function Ho(e){if(!e&&e!==0)return"n/a";if(e<1e3)return`${e}ms`;const t=Math.round(e/1e3);if(t<60)return`${t}s`;const n=Math.round(t/60);if(n<60)return`${n}m`;const i=Math.round(n/60);return i<48?`${i}h`:`${Math.round(i/24)}d`}function Ai(e){return!e||e.length===0?"none":e.filter(t=>!!(t&&t.trim())).join(", ")}function xi(e,t=120){return e.length<=t?e:`${e.slice(0,Math.max(0,t-1))}…`}function jo(e,t){return e.length<=t?{text:e,truncated:!1,total:e.length}:{text:e.slice(0,Math.max(0,t)),truncated:!0,total:e.length}}function vn(e,t){const n=Number(e);return Number.isFinite(n)?n:t}function ei(e){return Lc(e)}async function Ut(e){if(!(!e.client||!e.connected))try{const t=await e.client.request("cron.status",{});e.cronStatus=t}catch(t){e.cronError=String(t)}}async function Ln(e){if(!(!e.client||!e.connected)&&!e.cronLoading){e.cronLoading=!0,e.cronError=null;try{const t=await e.client.request("cron.list",{includeDisabled:!0});e.cronJobs=Array.isArray(t.jobs)?t.jobs:[]}catch(t){e.cronError=String(t)}finally{e.cronLoading=!1}}}function Ic(e){if(e.scheduleKind==="at"){const n=Date.parse(e.scheduleAt);if(!Number.isFinite(n))throw new Error("Invalid run time.");return{kind:"at",at:new Date(n).toISOString()}}if(e.scheduleKind==="every"){const n=vn(e.everyAmount,0);if(n<=0)throw new Error("Invalid interval amount.");const i=e.everyUnit;return{kind:"every",everyMs:n*(i==="minutes"?6e4:i==="hours"?36e5:864e5)}}const t=e.cronExpr.trim();if(!t)throw new Error("Cron expression required.");return{kind:"cron",expr:t,tz:e.cronTz.trim()||void 0}}function Rc(e){if(e.payloadKind==="systemEvent"){const s=e.payloadText.trim();if(!s)throw new Error("System event text required.");return{kind:"systemEvent",text:s}}const t=e.payloadText.trim();if(!t)throw new Error("Agent message required.");const n={kind:"agentTurn",message:t},i=vn(e.timeoutSeconds,0);return i>0&&(n.timeoutSeconds=i),n}async function Mc(e){if(!(!e.client||!e.connected||e.cronBusy)){e.cronBusy=!0,e.cronError=null;try{const t=Ic(e.cronForm),n=Rc(e.cronForm),i=e.cronForm.sessionTarget==="isolated"&&e.cronForm.payloadKind==="agentTurn"&&e.cronForm.deliveryMode?{mode:e.cronForm.deliveryMode==="announce"?"announce":"none",channel:e.cronForm.deliveryChannel.trim()||"last",to:e.cronForm.deliveryTo.trim()||void 0}:void 0,s=e.cronForm.agentId.trim(),a={name:e.cronForm.name.trim(),description:e.cronForm.description.trim()||void 0,agentId:s||void 0,enabled:e.cronForm.enabled,schedule:t,sessionTarget:e.cronForm.sessionTarget,wakeMode:e.cronForm.wakeMode,payload:n,delivery:i};if(!a.name)throw new Error("Name required.");await e.client.request("cron.add",a),e.cronForm={...e.cronForm,name:"",description:"",payloadText:""},await Ln(e),await Ut(e)}catch(t){e.cronError=String(t)}finally{e.cronBusy=!1}}}async function Pc(e,t,n){if(!(!e.client||!e.connected||e.cronBusy)){e.cronBusy=!0,e.cronError=null;try{await e.client.request("cron.update",{id:t.id,patch:{enabled:n}}),await Ln(e),await Ut(e)}catch(i){e.cronError=String(i)}finally{e.cronBusy=!1}}}async function Fc(e,t){if(!(!e.client||!e.connected||e.cronBusy)){e.cronBusy=!0,e.cronError=null;try{await e.client.request("cron.run",{id:t.id,mode:"force"}),await Go(e,t.id)}catch(n){e.cronError=String(n)}finally{e.cronBusy=!1}}}async function Nc(e,t){if(!(!e.client||!e.connected||e.cronBusy)){e.cronBusy=!0,e.cronError=null;try{await e.client.request("cron.remove",{id:t.id}),e.cronRunsJobId===t.id&&(e.cronRunsJobId=null,e.cronRuns=[]),await Ln(e),await Ut(e)}catch(n){e.cronError=String(n)}finally{e.cronBusy=!1}}}async function Go(e,t){if(!(!e.client||!e.connected))try{const n=await e.client.request("cron.runs",{id:t,limit:50});e.cronRunsJobId=t,e.cronRuns=Array.isArray(n.entries)?n.entries:[]}catch(n){e.cronError=String(n)}}const Wo="openclaw.device.auth.v1";function ls(e){return e.trim()}function Dc(e){if(!Array.isArray(e))return[];const t=new Set;for(const n of e){const i=n.trim();i&&t.add(i)}return[...t].toSorted()}function rs(){try{const e=window.localStorage.getItem(Wo);if(!e)return null;const t=JSON.parse(e);return!t||t.version!==1||!t.deviceId||typeof t.deviceId!="string"||!t.tokens||typeof t.tokens!="object"?null:t}catch{return null}}function qo(e){try{window.localStorage.setItem(Wo,JSON.stringify(e))}catch{}}function Oc(e){const t=rs();if(!t||t.deviceId!==e.deviceId)return null;const n=ls(e.role),i=t.tokens[n];return!i||typeof i.token!="string"?null:i}function Vo(e){const t=ls(e.role),n={version:1,deviceId:e.deviceId,tokens:{}},i=rs();i&&i.deviceId===e.deviceId&&(n.tokens={...i.tokens});const s={token:e.token,role:t,scopes:Dc(e.scopes),updatedAtMs:Date.now()};return n.tokens[t]=s,qo(n),s}function Yo(e){const t=rs();if(!t||t.deviceId!==e.deviceId)return;const n=ls(e.role);if(!t.tokens[n])return;const i={...t,tokens:{...t.tokens}};delete i.tokens[n],qo(i)}const Qo={p:0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,n:0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,h:8n,a:0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,d:0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,Gx:0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Gy:0x6666666666666666666666666666666666666666666666666666666666666658n},{p:Q,n:fn,Gx:wa,Gy:$a,a:ti,d:ni,h:Bc}=Qo,He=32,cs=64,Uc=(...e)=>{"captureStackTrace"in Error&&typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(...e)},G=(e="")=>{const t=new Error(e);throw Uc(t,G),t},Kc=e=>typeof e=="bigint",zc=e=>typeof e=="string",Hc=e=>e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array",Ie=(e,t,n="")=>{const i=Hc(e),s=e?.length,a=t!==void 0;if(!i||a&&s!==t){const o=n&&`"${n}" `,r=a?` of length ${t}`:"",c=i?`length=${s}`:`type=${typeof e}`;G(o+"expected Uint8Array"+r+", got "+c)}return e},In=e=>new Uint8Array(e),Jo=e=>Uint8Array.from(e),Zo=(e,t)=>e.toString(16).padStart(t,"0"),Xo=e=>Array.from(Ie(e)).map(t=>Zo(t,2)).join(""),ke={_0:48,_9:57,A:65,F:70,a:97,f:102},ka=e=>{if(e>=ke._0&&e<=ke._9)return e-ke._0;if(e>=ke.A&&e<=ke.F)return e-(ke.A-10);if(e>=ke.a&&e<=ke.f)return e-(ke.a-10)},el=e=>{const t="hex invalid";if(!zc(e))return G(t);const n=e.length,i=n/2;if(n%2)return G(t);const s=In(i);for(let a=0,o=0;a<i;a++,o+=2){const r=ka(e.charCodeAt(o)),c=ka(e.charCodeAt(o+1));if(r===void 0||c===void 0)return G(t);s[a]=r*16+c}return s},tl=()=>globalThis?.crypto,jc=()=>tl()?.subtle??G("crypto.subtle must be defined, consider polyfill"),Ft=(...e)=>{const t=In(e.reduce((i,s)=>i+Ie(s).length,0));let n=0;return e.forEach(i=>{t.set(i,n),n+=i.length}),t},Gc=(e=He)=>tl().getRandomValues(In(e)),mn=BigInt,Oe=(e,t,n,i="bad number: out of range")=>Kc(e)&&t<=e&&e<n?e:G(i),T=(e,t=Q)=>{const n=e%t;return n>=0n?n:t+n},nl=e=>T(e,fn),Wc=(e,t)=>{(e===0n||t<=0n)&&G("no inverse n="+e+" mod="+t);let n=T(e,t),i=t,s=0n,a=1n;for(;n!==0n;){const o=i/n,r=i%n,c=s-a*o;i=n,n=r,s=a,a=c}return i===1n?T(s,t):G("no inverse")},qc=e=>{const t=ol[e];return typeof t!="function"&&G("hashes."+e+" not set"),t},ii=e=>e instanceof se?e:G("Point expected"),Si=2n**256n;class se{static BASE;static ZERO;X;Y;Z;T;constructor(t,n,i,s){const a=Si;this.X=Oe(t,0n,a),this.Y=Oe(n,0n,a),this.Z=Oe(i,1n,a),this.T=Oe(s,0n,a),Object.freeze(this)}static CURVE(){return Qo}static fromAffine(t){return new se(t.x,t.y,1n,T(t.x*t.y))}static fromBytes(t,n=!1){const i=ni,s=Jo(Ie(t,He)),a=t[31];s[31]=a&-129;const o=sl(s);Oe(o,0n,n?Si:Q);const c=T(o*o),u=T(c-1n),f=T(i*c+1n);let{isValid:g,value:m}=Yc(u,f);g||G("bad point: y not sqrt");const v=(m&1n)===1n,d=(a&128)!==0;return!n&&m===0n&&d&&G("bad point: x==0, isLastByteOdd"),d!==v&&(m=T(-m)),new se(m,o,1n,T(m*o))}static fromHex(t,n){return se.fromBytes(el(t),n)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}assertValidity(){const t=ti,n=ni,i=this;if(i.is0())return G("bad point: ZERO");const{X:s,Y:a,Z:o,T:r}=i,c=T(s*s),u=T(a*a),f=T(o*o),g=T(f*f),m=T(c*t),v=T(f*T(m+u)),d=T(g+T(n*T(c*u)));if(v!==d)return G("bad point: equation left != right (1)");const y=T(s*a),k=T(o*r);return y!==k?G("bad point: equation left != right (2)"):this}equals(t){const{X:n,Y:i,Z:s}=this,{X:a,Y:o,Z:r}=ii(t),c=T(n*r),u=T(a*s),f=T(i*r),g=T(o*s);return c===u&&f===g}is0(){return this.equals(it)}negate(){return new se(T(-this.X),this.Y,this.Z,T(-this.T))}double(){const{X:t,Y:n,Z:i}=this,s=ti,a=T(t*t),o=T(n*n),r=T(2n*T(i*i)),c=T(s*a),u=t+n,f=T(T(u*u)-a-o),g=c+o,m=g-r,v=c-o,d=T(f*m),y=T(g*v),k=T(f*v),A=T(m*g);return new se(d,y,A,k)}add(t){const{X:n,Y:i,Z:s,T:a}=this,{X:o,Y:r,Z:c,T:u}=ii(t),f=ti,g=ni,m=T(n*o),v=T(i*r),d=T(a*g*u),y=T(s*c),k=T((n+i)*(o+r)-m-v),A=T(y-d),_=T(y+d),I=T(v-f*m),x=T(k*A),C=T(_*I),E=T(k*I),D=T(A*_);return new se(x,C,D,E)}subtract(t){return this.add(ii(t).negate())}multiply(t,n=!0){if(!n&&(t===0n||this.is0()))return it;if(Oe(t,1n,fn),t===1n)return this;if(this.equals(je))return od(t).p;let i=it,s=je;for(let a=this;t>0n;a=a.double(),t>>=1n)t&1n?i=i.add(a):n&&(s=s.add(a));return i}multiplyUnsafe(t){return this.multiply(t,!1)}toAffine(){const{X:t,Y:n,Z:i}=this;if(this.equals(it))return{x:0n,y:1n};const s=Wc(i,Q);T(i*s)!==1n&&G("invalid inverse");const a=T(t*s),o=T(n*s);return{x:a,y:o}}toBytes(){const{x:t,y:n}=this.assertValidity().toAffine(),i=il(n);return i[31]|=t&1n?128:0,i}toHex(){return Xo(this.toBytes())}clearCofactor(){return this.multiply(mn(Bc),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let t=this.multiply(fn/2n,!1).double();return fn%2n&&(t=t.add(this)),t.is0()}}const je=new se(wa,$a,1n,T(wa*$a)),it=new se(0n,1n,1n,0n);se.BASE=je;se.ZERO=it;const il=e=>el(Zo(Oe(e,0n,Si),cs)).reverse(),sl=e=>mn("0x"+Xo(Jo(Ie(e)).reverse())),pe=(e,t)=>{let n=e;for(;t-- >0n;)n*=n,n%=Q;return n},Vc=e=>{const n=e*e%Q*e%Q,i=pe(n,2n)*n%Q,s=pe(i,1n)*e%Q,a=pe(s,5n)*s%Q,o=pe(a,10n)*a%Q,r=pe(o,20n)*o%Q,c=pe(r,40n)*r%Q,u=pe(c,80n)*c%Q,f=pe(u,80n)*c%Q,g=pe(f,10n)*a%Q;return{pow_p_5_8:pe(g,2n)*e%Q,b2:n}},Aa=0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n,Yc=(e,t)=>{const n=T(t*t*t),i=T(n*n*t),s=Vc(e*i).pow_p_5_8;let a=T(e*n*s);const o=T(t*a*a),r=a,c=T(a*Aa),u=o===e,f=o===T(-e),g=o===T(-e*Aa);return u&&(a=r),(f||g)&&(a=c),(T(a)&1n)===1n&&(a=T(-a)),{isValid:u||f,value:a}},_i=e=>nl(sl(e)),ds=(...e)=>ol.sha512Async(Ft(...e)),Qc=(...e)=>qc("sha512")(Ft(...e)),al=e=>{const t=e.slice(0,He);t[0]&=248,t[31]&=127,t[31]|=64;const n=e.slice(He,cs),i=_i(t),s=je.multiply(i),a=s.toBytes();return{head:t,prefix:n,scalar:i,point:s,pointBytes:a}},us=e=>ds(Ie(e,He)).then(al),Jc=e=>al(Qc(Ie(e,He))),Zc=e=>us(e).then(t=>t.pointBytes),Xc=e=>ds(e.hashable).then(e.finish),ed=(e,t,n)=>{const{pointBytes:i,scalar:s}=e,a=_i(t),o=je.multiply(a).toBytes();return{hashable:Ft(o,i,n),fi