@amd-gaia/agent-ui 0.26.0-rc.5 → 0.26.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ConnectorsPane-C4Nf75r4.js","./rolldown-runtime-XKyaHtl9.js","./useT-9bLwAbF7.js","./api-c2Hja8UA.js","./ConnectorsPane-Dq8E0HKa.css","./AdvancedSettings-BnWw0T2Y.js","./MemoryDashboard-DJWkELvL.js","./zap-gjTc4oQN.js","./MemoryDashboard-DwrWAXi6.css","./ScheduleManager-xx9Mhex5.js","./ScheduleManager-CjHJ4NbD.css","./DocumentLibrary-DA1FKyAu.js","./DocumentLibrary-CM6o8j2T.css","./FileBrowser-CODR0L_L.js","./FileBrowser-Cna3BsT7.css","./MobileAccessModal-D1jnQ_9R.js","./MobileAccessModal-BkVDm3YG.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ConnectorsPane-BfS5fSIl.js","./rolldown-runtime-XKyaHtl9.js","./useT-9bLwAbF7.js","./api-c2Hja8UA.js","./ConnectorsPane-Dq8E0HKa.css","./AdvancedSettings-8tGuuocd.js","./MemoryDashboard-D3BSEWvI.js","./zap-gjTc4oQN.js","./MemoryDashboard-DwrWAXi6.css","./ScheduleManager-BwuPu7-w.js","./ScheduleManager-CjHJ4NbD.css","./DocumentLibrary-V2n1obTR.js","./DocumentLibrary-CM6o8j2T.css","./FileBrowser-D5gu5VB9.js","./FileBrowser-Cna3BsT7.css","./MobileAccessModal-DGKfraeR.js","./MobileAccessModal-BkVDm3YG.css"])))=>i.map(i=>d[i]);
2
2
  import{n as e,r as t,t as n}from"./rolldown-runtime-XKyaHtl9.js";import{A as r,B as i,C as a,D as o,E as s,F as c,G as l,H as u,I as d,J as f,K as p,L as m,M as h,N as g,O as _,R as v,S as y,T as b,U as x,V as S,W as C,_ as w,a as T,b as E,c as D,d as O,f as k,g as A,h as j,j as M,k as N,l as P,m as F,n as I,o as L,p as ee,q as R,r as z,s as B,t as te,u as V,v as ne,w as re,x as ie,y as ae,z as oe}from"./useT-9bLwAbF7.js";import{$ as H,$n as U,$t as se,A as W,An as G,B as ce,Bn as le,Bt as ue,C as de,D as fe,Dt as pe,E as me,En as he,Et as ge,F as _e,Fn as ve,Ft as ye,G as be,Gn as xe,Gt as Se,Hn as Ce,Ht as we,In as Te,It as Ee,J as De,Jn as Oe,Jt as ke,K as Ae,Kn as je,Kt as Me,L as Ne,Ln as Pe,Lt as Fe,M as Ie,Mn as Le,Mt as Re,N as ze,Nn as Be,Nt as Ve,O as He,Ot as Ue,P as We,Pn as Ge,Pt as Ke,Q as qe,Qn as Je,Qt as Ye,R as Xe,Rn as Ze,Rt as Qe,S as $e,St as et,T as tt,Tt as nt,U as rt,Un as it,Ut as at,V as K,Vn as ot,Vt as st,W as ct,Wn as lt,Wt as ut,X as dt,Xn as ft,Xt as pt,Y as mt,Yn as ht,Z as gt,Zn as _t,Zt as vt,_ as yt,_t as bt,a as xt,an as St,b as Ct,bt as wt,c as Tt,cn as Et,ct as Dt,d as Ot,dn as kt,dt as At,en as jt,er as Mt,et as Nt,fn as Pt,ft as Ft,g as It,gt as Lt,h as Rt,ht as zt,i as Bt,in as Vt,it as Ht,j as Ut,jn as Wt,jt as Gt,k as Kt,kn as qt,kt as Jt,l as Yt,ln as Xt,lt as Zt,m as Qt,mn as $t,mt as en,nn as tn,nr as nn,nt as rn,o as an,on,ot as sn,p as cn,pt as ln,q as un,qn as dn,qt as fn,r as pn,rn as mn,rt as hn,s as gn,sn as _n,st as vn,t as yn,tn as bn,tr as xn,tt as Sn,u as Cn,un as wn,ut as Tn,v as En,vt as Dn,w as On,x as kn,xn as An,yt as jn,z as Mn,zn as Nn,zt as Pn}from"./api-c2Hja8UA.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Fn=n((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),In=n(((e,t)=>{t.exports=Fn()})),Ln=n((e=>{var t=f();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`),o=Symbol.for(`react.recoverable`),s=Symbol.for(`react.optimistic_key`);function c(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:r===s?s:``+r,children:e,containerInfo:t,implementation:n}}var l=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function u(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.browser=function(e){return{$$typeof:o,_reason:e}},e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return c(e,t,null,r)},e.flushSync=function(e){var t=l.T,n=i.p;try{if(l.T=null,i.p=2,e)return e()}finally{l.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=u(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=u(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return l.H.useFormState(e,t,n)},e.useFormStatus=function(){return l.H.useHostTransitionStatus()},e.version=`19.3.1`})),Rn=n(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=Ln()})),zn=n((e=>{var t=In(),n=f(),r=Rn();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){for(var t=e,n=t;n&&!n.alternate;)t=n,t.flags&4098&&(e=t.return),n=t.return;for(;t.return;)t=t.return;return t.tag===3?e:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}function p(e,t,n,r,i,a){for(;e!==null;){if((e.tag===5||e.tag===27||e.tag===6)&&n(e,r,i,a)||(e.tag!==22||e.memoizedState===null)&&(t||e.tag!==5&&e.tag!==27)&&p(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function m(e){for(e=e.return;e!==null;){if(e.tag===3||e.tag===5||e.tag===27)return e;e=e.return}return null}function h(e){var t=!1;for(e=e.return;e!==null&&(e.tag===4&&(t=!0),e.tag!==3&&e.tag!==5&&e.tag!==27);)e=e.return;return t}function g(e){var t=[null,null],n=m(e);return n===null||_(t,e,n.child,{foundSelf:!1}),t}function _(e,t,n,r){for(;n!==null;){if(n===t)r.foundSelf=!0;else if(n.tag===5||n.tag===27||n.tag===6){if(r.foundSelf)return e[1]=n,!0;e[0]=n}else if((n.tag!==22||n.memoizedState===null)&&_(e,t,n.child,r))return!0;n=n.sibling}return!1}function v(e){switch(e.tag){case 5:case 27:case 6:return e.stateNode;case 3:return e.stateNode.containerInfo;default:throw Error(i(559))}}var y=null,b=null;function x(e,t,n){return e===n||e===t&&(y=e,!0)}function S(e,t,n){return e===n?(b=e,!1):e===t&&(b!==null&&(y=e),!0)}function C(e){if(e===null)return null;do e=e===null?null:e.return;while(e&&e.tag!==5&&e.tag!==27&&e.tag!==3);return e||null}function w(e,t,n){for(var r=0,i=e;i;i=n(i))r++;i=0;for(var a=t;a;a=n(a))i++;for(;0<r-i;)e=n(e),r--;for(;0<i-r;)t=n(t),i--;for(;r--;){if(e===t||t!==null&&e===t.alternate)return e;e=n(e),t=n(t)}return null}var T=Object.assign,E=Symbol.for(`react.element`),D=Symbol.for(`react.transitional.element`),O=Symbol.for(`react.portal`),k=Symbol.for(`react.fragment`),A=Symbol.for(`react.strict_mode`),j=Symbol.for(`react.profiler`),M=Symbol.for(`react.consumer`),N=Symbol.for(`react.context`),P=Symbol.for(`react.forward_ref`),F=Symbol.for(`react.suspense`),I=Symbol.for(`react.suspense_list`),L=Symbol.for(`react.memo`),ee=Symbol.for(`react.lazy`),R=Symbol.for(`react.activity`),z=Symbol.for(`react.legacy_hidden`),B=Symbol.for(`react.memo_cache_sentinel`),te=Symbol.for(`react.view_transition`),V=Symbol.for(`react.recoverable`),ne=Symbol.iterator;function re(e){return typeof e!=`object`||!e?null:(e=ne&&e[ne]||e[`@@iterator`],typeof e==`function`?e:null)}var ie=Symbol.for(`react.client.reference`);function ae(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===ie?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case k:return`Fragment`;case j:return`Profiler`;case A:return`StrictMode`;case F:return`Suspense`;case I:return`SuspenseList`;case R:return`Activity`;case te:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case O:return`Portal`;case N:return e.displayName||`Context`;case M:return(e._context.displayName||`Context`)+`.Consumer`;case P:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case L:return t=e.displayName||null,t===null?ae(e.type)||`Memo`:t;case ee:t=e._payload,e=e._init;try{return ae(e(t))}catch{}}return null}var oe=Array.isArray,H=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,U=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,se={pending:!1,data:null,method:null,action:null},W=[],G=-1;function ce(e){return{current:e}}function le(e){0>G||(e.current=W[G],W[G]=null,G--)}function ue(e,t){G++,W[G]=e.current,e.current=t}var de=ce(null),fe=ce(null),pe=ce(null),me=ce(null);function he(e,t){switch(ue(pe,t),ue(fe,e),ue(de,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?dp(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=dp(t),e=fp(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}le(de),ue(de,e)}function ge(){le(de),le(fe),le(pe)}function _e(e){var t=e.memoizedState;t!==null&&(ch._currentValue=t.memoizedState,ue(me,e)),t=de.current;var n=fp(t,e.type);t!==n&&(ue(fe,e),ue(de,n))}function ve(e){fe.current===e&&(le(de),le(fe)),me.current===e&&(le(me),ch._currentValue=se)}var ye,be;function xe(e){if(ye===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);ye=t&&t[1]||``,be=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+ye+e+be}var Se=!1;function Ce(e,t){if(!e||Se)return``;Se=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}n=!1;try{var i=Object.getOwnPropertyDescriptor(e.prototype,`props`);Object.defineProperty(e.prototype,"props",{configurable:!0,set:function(){throw Error()}}),n=!0,new e}finally{n&&(i===void 0?delete e.prototype.props:Object.defineProperty(e.prototype,"props",i))}}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
@@ -57,7 +57,7 @@ Error generating stack: `+e.message+`
57
57
  `)}function LC(e,t){return e?new Date(e).toLocaleString(te(t),{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`,second:`2-digit`,hour12:!0}):``}var RC=`Cancelled.`,zC=[[`This answer was interrupted when GAIA closed. Send again to retry.`,`msg.cutOff.interrupted`],[`This answer was interrupted before it finished. Send again to retry.`,`msg.cutOff.cancelled`],[`This answer ended before GAIA could save a reply. Send again to retry.`,`msg.cutOff.noReply`]],BC=/(?:^|\n\n)Before it stopped, it had started these tools: (.+)\.$/;function VC(e){let t=e.trim(),n=zC.find(([e])=>t.endsWith(e));if(!n)return null;t=t.slice(0,-n[0].length).trimEnd();let r=BC.exec(t);return r&&(t=t.slice(0,r.index).trimEnd()),{body:t,notice:n[1],tools:r?r[1]:null}}function HC(e,t){return t?`stopped`:VC(e)?`interrupted`:void 0}function UC({message:e,isStreaming:t,agentSteps:n,agentStepsActive:r,cards:i,onDelete:a,onResend:o,extraActions:s,onTryAgain:c,latencyMs:l,liveStatus:u,toolStatus:d,awaitingUser:f}){let p=T();ls();let m=(0,X.useMemo)(()=>e.role===`assistant`&&!t&&n?CC(n,e.content):{steps:n,echoed:!1},[n,e.content,e.role,t]),h=e.role===`assistant`&&(m.echoed||e.failed===!0||xC(e.content)),g=e.role===`assistant`?e.stopState??(e.content.trim()===RC?`stopped`:void 0):void 0,_=(0,X.useMemo)(()=>e.role===`assistant`&&!t?VC(e.content):null,[e.content,e.role,t]),v=(0,X.useMemo)(()=>e.role===`user`?e.content:FC(_?_.body:e.content,!!t),[e.content,e.role,t,_]),y=`${e.session_id}:${e.id}`,[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(!1),w=e.role===`user`&&gy(e.content),[E,O]=(0,X.useState)(!1),k=(0,X.useId)(),A=(0,X.useRef)(null),j=(0,X.useRef)(!1),M=(0,X.useCallback)(()=>{E&&(j.current=!0),O(!E)},[E]);(0,X.useEffect)(()=>{!E&&j.current&&(j.current=!1,A.current?.scrollIntoView?.({block:`nearest`}))},[E]);let N=(0,X.useRef)(null),F=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{N.current&&clearTimeout(N.current),F.current&&clearTimeout(F.current)},[]);let I=(0,X.useCallback)(()=>{if(navigator.clipboard?.writeText)navigator.clipboard.writeText(e.content).catch(()=>{});else{let t=document.createElement(`textarea`);t.value=e.content,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t)}x(!0),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>x(!1),2e3)},[e.content]),L=(0,X.useCallback)(()=>{S?(C(!1),F.current&&clearTimeout(F.current),a?.(e.id)):(C(!0),F.current&&clearTimeout(F.current),F.current=setTimeout(()=>C(!1),3e3))},[S,e.id,a]),ee=(0,X.useCallback)(()=>{o?.(e)},[e,o]),R=e.created_at?p(e.role===`user`?`msg.sent`:`msg.replied`,{time:LC(e.created_at,p)}):void 0;return P(`div`,{className:`msg msg-${e.role} ${h?`msg-error`:``}`,title:R,children:V(`div`,{className:`msg-inner`,children:[V(`div`,{className:`msg-header`,children:[P(`div`,{className:`msg-header-left`}),!t&&V(`div`,{className:`msg-actions`,children:[e.role===`user`&&o&&P(`button`,{className:`msg-action-btn`,onClick:ee,title:p(`msg.resend`),"aria-label":p(`msg.resend`),children:P(Fa,{size:12})}),s,e.role===`assistant`&&!h&&v.trim()&&P(DS,{messageId:y,content:v}),P(`button`,{className:`msg-copy ${b?`copied`:``}`,onClick:I,title:p(b?`msg.copied`:`msg.copy`),"aria-label":p(b?`msg.copiedAria`:`msg.copy`),children:P(b?mr:Br,{size:12})}),a&&P(`button`,{className:`msg-action-btn msg-delete ${S?`confirm`:``}`,onClick:L,title:p(S?`msg.confirmDelete`:`msg.delete`),"aria-label":p(S?`msg.confirmDeleteAria`:`msg.delete`),children:P(lo,{size:12})})]})]}),V(`div`,{className:`msg-body`,children:[e.role===`assistant`&&(m.steps&&m.steps.length>0||t)&&P(nb,{steps:m.steps??[],isActive:r??!1,running:!!t,awaitingUser:f,toolStatus:t?d:null,answer:t?void 0:v,liveLine:t&&P(_C,{active:!!r||!v,label:u,awaitingUser:f})}),h&&V(`div`,{className:`error-banner`,children:[P(J,{size:14}),P(`span`,{children:p(`msg.error`)})]}),(e.cards??i)?.map((e,t)=>P(vx,{render:e.render,data:e.data},t)),w?V(D.Fragment,{children:[P(`div`,{ref:A,id:k,className:`msg-collapsible${E?``:` is-collapsed`}`,children:P(cw,{content:v})}),P(vy,{expanded:E,onToggle:M,controls:k,collapsedLabel:p.hint(p(`msg.showAll`),_y(e.content)),expandedLabel:p(`msg.showLess`),className:`msg-expand-toggle`})]}):!(g&&v.trim()===RC)&&P(cw,{content:v,showCursor:t&&!!v&&!r,isStreaming:t}),g&&V(`div`,{className:`msg-stopped${g===`unconfirmed`||e.stopError?` is-unconfirmed`:``}`,role:`note`,children:[P(ao,{size:9,fill:`currentColor`,"aria-hidden":`true`}),P(`span`,{children:g===`unconfirmed`?p(`msg.stoppedUnconfirmed`):e.stopError?p(`msg.stoppedError`,{error:e.stopError}):p(`msg.stopped`)})]}),_&&P(`p`,{className:`msg-cut-off`,role:`note`,children:p.compose(e=>_.tools?`${e(`msg.cutOff.toolsRan`,{tools:_.tools})} ${e(_.notice)}`:e(_.notice))}),c&&!t&&V(`button`,{type:`button`,className:`msg-try-again`,onClick:c,children:[P(za,{size:12,"aria-hidden":`true`}),p(`msg.tryAgain`)]}),e.role===`assistant`&&!t&&(tC(e.content)||tC(e.failureText??``))&&P(rC,{classes:bC,note:p(`msg.reportNote`)}),e.role===`assistant`&&!t&&wb(v)&&P(Ob,{content:v}),e.role===`assistant`&&!t&&(e.stats||l!=null||e.created_at)&&V(`div`,{className:`msg-stats`,"aria-label":p(`msg.about`),children:[e.created_at&&P(`span`,{className:`msg-stats-ts`,title:p(`msg.timestamp`),children:LC(e.created_at,p)}),e.stats?.retried&&e.stats.model&&P(`span`,{title:`This answer was kept from Retry with… (${e.stats.model})`,children:ds(e.stats.model)}),P(Dx,{latencyMs:l,stats:e.stats,ended:HC(e.content,g)})]}),e.role===`assistant`&&!t&&e.id>0&&e.session_id&&P(fS,{sessionId:e.session_id,messageId:e.id}),e.role===`assistant`&&P(OS,{messageId:y}),e.role===`assistant`&&P(kS,{messageId:y})]})]})})}var WC=(0,X.createContext)(!1);function GC({lang:e,code:t}){let n=T(),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(!1),s=(0,X.useContext)(WC),c=(0,X.useId)(),l=hy(t),u=l>(s?20:25),d=u&&!a,f=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]);let p=(0,X.useCallback)(()=>{if(navigator.clipboard?.writeText)navigator.clipboard.writeText(t).catch(()=>{});else{let e=document.createElement(`textarea`);e.value=t,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}i(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>i(!1),2e3)},[t]);return V(`div`,{className:`code-block${d?` is-collapsed`:``}`,dir:`ltr`,children:[V(`div`,{className:`code-header`,children:[P(`span`,{className:`code-lang`,children:e||`code`}),V(`button`,{className:`code-copy ${r?`copied`:``}`,onClick:p,title:n(r?`msg.copied`:`code.copy`),"aria-label":n(r?`msg.copiedAria`:`code.copyAria`),children:[P(r?mr:Br,{size:13}),P(`span`,{children:n(r?`code.copied`:`code.copy`)})]})]}),P(`pre`,{id:c,children:P(`code`,{children:t})}),u&&P(vy,{expanded:a,onToggle:()=>o(e=>!e),controls:c,collapsedLabel:`Expand (${l.toLocaleString(`en-US`)} lines)`,expandedLabel:`Collapse`,className:`code-expand-toggle`})]})}var KC=/(?<=["\u201c])[A-Z]:[\\/][^*?"<>|\r\n\u201c\u201d]+(?=["\u201d])|\b[A-Z]:[\\/](?=[^\s*?"<>|,;)}\]\\/])(?:[^\s*?"<>|,;)}\]\\/]+(?:(?: +(?:[^\s*?"<>|,;:)}\]\\/]+|\([^\s*?"<>|,;:)}\]\\/]+\)))+\\|[\\/]))*(?:(?:[^\s*?"<>|,;:.)}\]\\/]+ +){1,2}[^\s*?"<>|,;)}\]\\/]+\.[A-Za-z0-9]{1,5}\b|[^\s*?"<>|,;)}\]\\/]+)?/gi,qC=/[.:!']+$/,JC=RegExp(`^(?:${KC.source})$`,`i`);function YC(e){if(typeof e!=`string`)return null;let t=e.trim();return JC.test(t)?t:null}function XC({path:e}){let t=t=>{t.preventDefault(),Dn(e).catch(e=>{d.ui.error(`Failed to open path`,e)})};return V(`span`,{className:`file-path-link`,dir:`ltr`,onClick:t,title:`Open in file explorer: ${e}`,role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),t(e))},children:[P(bi,{size:12,className:`file-path-icon`}),e]})}function ZC(e){return[...e.matchAll(new RegExp(KC.source,`gi`))].map(t=>{let n=t.index+t[0].length,r=`"“`.includes(e[t.index-1]??`
58
58
  `)&&`"”`.includes(e[n]??`
59
59
  `);return{start:t.index,path:r?t[0]:t[0].replace(qC,``)}})}function QC(e){let t=[],n=0;for(let{start:r,path:i}of ZC(e))r>n&&t.push(e.slice(n,r)),t.push(P(XC,{path:i},r)),n=r+i.length;return t.length===0?e:(n<e.length&&t.push(e.slice(n)),P(D.Fragment,{children:t}))}var $C=(0,X.createContext)(cC([]));function ew({doc:e,page:t,t:n}){return V(`a`,{className:`citation-link`,href:me(e.id,t),target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,title:t?n(`citation.openPage`,{page:t}):n(`citation.open`,{name:e.filename}),"data-doc-id":e.id,"data-page":t,children:[P(gi,{size:12,className:`citation-icon`,"aria-hidden":`true`}),e.filename]})}function tw({doc:e,page:t,label:n,t:r}){return P(`a`,{className:`citation-page`,href:me(e.id,t),target:`_blank`,rel:`noopener noreferrer`,title:r(`citation.openPage`,{page:t}),"data-doc-id":e.id,"data-page":t,children:n})}function nw(e,t){let n=uC(e,t)[0];return gC(n?t.slice(0,n.start):t)}function rw(e,t,n,r){let i=ZC(e),a=uC(t,e).filter(e=>!i.some(t=>t.start<e.start&&e.start<t.start+t.path.length)),o=[],s=(t,r,i)=>{for(let a of r){let r=i+a.start,s=i+a.end;o.push({start:r,end:s,node:P(tw,{doc:t,page:a.page,label:e.slice(r,s),t:n},`p${r}`)})}};if(r&&s(r,gC(e.slice(0,a[0]?.start??e.length)),0),a.forEach((t,r)=>{let i=gC(e.slice(t.end,a[r+1]?.start??e.length));o.push({start:t.start,end:t.end,node:P(ew,{doc:t.doc,page:i[0]?.page,t:n},`c${t.start}`)}),s(t.doc,i,t.end)}),o.length===0)return QC(e);o.sort((e,t)=>e.start-t.start);let c=[],l=0;for(let t of o)t.start>l&&c.push(P(X.Fragment,{children:QC(e.slice(l,t.start))},`t${l}`)),c.push(t.node),l=t.end;return l<e.length&&c.push(P(X.Fragment,{children:QC(e.slice(l))},`t${l}`)),P(D.Fragment,{children:c})}function iw(e,t){return typeof t==`string`?lC(e,t):null}function aw({children:e}){let t=(0,X.useContext)($C),n=T(),r=X.Children.toArray(e),i=null,a=r.map((e,a)=>{if(typeof e==`string`){let r=rw(e,t,n,i);return i=null,P(X.Fragment,{children:r},`s${a}`)}if(i=null,X.isValidElement(e)&&e.type===ow){let o=iw(t,e.props.children);if(o){let e=r[a+1],s=typeof e==`string`?nw(t,e):[];return i=o,P(ew,{doc:o,page:s[0]?.page,t:n},`k${a}`)}}return e});return P(D.Fragment,{children:a})}function ow({className:e,children:t,node:n,...r}){let i=(0,X.useContext)($C),a=T(),o=iw(i,t);if(o)return P(ew,{doc:o,t:a});let s=YC(t);return s?P(XC,{path:s}):P(`code`,{className:`inline-code`,dir:`ltr`,...r,children:t})}var sw={code:ow,pre({children:e}){let t=X.Children.toArray(e)[0];if(X.isValidElement(t)&&(t.type===`code`||t.props?.className!==void 0||typeof t.props?.children==`string`)){let e=t.props,n=e?.className||``,r=/language-([\w-]+)/.exec(n),i=String(e?.children||``).replace(/\n$/,``),a=r?.[1]||``;return P(GC,{lang:a,code:i})}return P(`pre`,{dir:`ltr`,children:e})},table({children:e}){return P(`div`,{className:`md-table-wrap`,children:P(`table`,{className:`md-table`,dir:`auto`,children:e})})},a({href:e,children:t}){return P(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`md-link`,children:t})},p({children:e}){return P(`p`,{className:`md-p`,dir:`auto`,children:P(aw,{children:e})})},h1({children:e}){return P(`h2`,{className:`md-h2`,dir:`auto`,children:P(aw,{children:e})})},h2({children:e}){return P(`h3`,{className:`md-h3`,dir:`auto`,children:P(aw,{children:e})})},h3({children:e}){return P(`h4`,{className:`md-h4`,dir:`auto`,children:P(aw,{children:e})})},h4({children:e}){return P(`h5`,{className:`md-h4`,dir:`auto`,children:P(aw,{children:e})})},ul({children:e}){return P(`ul`,{className:`md-ul`,dir:`auto`,children:e})},ol({children:e,start:t}){return P(`ol`,{className:`md-ol`,start:t,dir:`auto`,children:e})},li({children:e}){return P(`li`,{className:`md-li`,dir:`auto`,children:P(aw,{children:e})})},blockquote({children:e}){return P(`blockquote`,{className:`md-blockquote`,dir:`auto`,children:P(aw,{children:e})})},hr(){return P(`hr`,{className:`md-hr`})},td({children:e}){return P(`td`,{dir:`auto`,children:P(aw,{children:e})})},th({children:e}){return P(`th`,{dir:`auto`,children:P(aw,{children:e})})}};function cw({content:e,showCursor:t,isStreaming:n=!1}){let r=k(e=>e.documents),i=(0,X.useMemo)(()=>cC(r),[r]);return!e&&!t?null:!e&&t?P(`span`,{className:`cursor`}):P(WC.Provider,{value:n,children:P($C.Provider,{value:i,children:V(`div`,{className:`md-content`,children:[P(Uh,{remarkPlugins:[Xv,ty,ry],disallowedElements:[...Jh],urlTransform:Xh,components:sw,children:e}),t&&P(`span`,{className:`cursor`})]})})})}function lw(e){return e.type===`status`&&e.status===`working`&&!e.phase&&(e.message??``).startsWith(`Model is processing`)}function uw(e){return e.phase===`loading_tools`?I()(`chat.loadingTools`):(e.message||``).trim()}function dw(e,t){let n=++t.current,r=Date.now();switch(e.type){case`thinking`:return{id:n,type:`thinking`,label:`Thinking`,detail:e.content,active:!0,timestamp:r};case`commentary`:return{id:n,type:`commentary`,label:`Commentary`,detail:e.content,active:!1,timestamp:r};case`tool_start`:return{id:n,type:`tool`,label:`Using tool`,tool:e.tool,detail:e.detail,narration:e.narration,active:!0,timestamp:r,mcpServer:e.mcp_server,mcpServerLabel:e.mcp_server_label,mcpTool:e.mcp_tool};case`skill_use`:return{id:n,type:`tool`,label:`Using tool`,tool:`use_skill`,detail:e.skill,narration:`Using skill: ${e.skill}`,active:!1,success:!0,timestamp:r};case`plan`:return{id:n,type:`plan`,label:`Created plan`,planSteps:e.steps,planNarrations:e.step_narrations,currentStep:e.current_step,active:!1,success:!0,timestamp:r};case`step`:return{id:n,type:`status`,label:`Step ${e.step}${e.total?` of ${e.total}`:``}`,active:!0,timestamp:r};case`status`:return e.message?.startsWith(`Agent: `)?null:{id:n,type:`status`,label:e.message||e.status||`Working`,active:e.status===`working`,...e.status===`warning`?{success:!1}:{},timestamp:r};case`agent_error`:return{id:n,type:`error`,label:`Error`,detail:e.content,success:!1,active:!1,timestamp:r};case`policy_alert`:{let t=e.tool||`unknown tool`,i=e.reason||e.message||e.content||`Tool execution was blocked by governance policy.`;return{id:n,type:`policy_alert`,label:`Policy blocked ${t}`,detail:i,tool:t,decision:e.decision||`BLOCK`,reason:i,ruleIds:e.rule_ids??[],policyVersion:e.policy_version,receiptId:e.receipt_id,success:!1,active:!1,timestamp:r}}default:return null}}var fw=new Set([`tool`,`waiting`]);function pw(e){return e.livePhase&&!fw.has(e.livePhase)?e.liveStatus:null}function mw(e,t){let n=k.getState(),r=e.status,i=uw(e);if(e.phase===`recording_found`&&e.section!=null){n.addRecordingSection({section:e.section,sections:e.sections??e.section,start:e.start??``,end:e.end??``,summary:e.summary??``,items:e.items??[]});return}if(e.phase===`recording`&&e.stage!=null){n.setRecordingStage(e.stage,{state:e.state??0,percent:e.percent,etaSeconds:e.eta_seconds});return}if(e.phase&&i&&n.setLiveStatus(i,e.phase),e.phase===`waiting`||lw(e)||i.toLowerCase().startsWith(`executing `)||r!==`working`&&r!==`warning`&&r!==`info`)return;let a=n.agentSteps[n.agentSteps.length-1];if(a&&a.type===`status`&&a.active){n.updateLastAgentStep({label:i||`Working`,detail:i});return}if(a&&a.type===`thinking`&&a.active){n.updateLastAgentStep({label:i||`Thinking`});return}let o=dw({...e,message:i},t);o&&n.addAgentStep(o)}var hw=/\s*\{\s*"?(?:tool|thought|goal)"?\s*:\s*"[^"]*"[^}]*(?:"?tool_args"?\s*:\s*\{[^}]*\})?\s*\}/g;function gw(e){let t=e.trim();if(!t.startsWith(`{`)||!t.includes(`"thought"`)&&!t.includes(`"answer"`)&&!t.includes(`"goal"`))return e;try{let e=JSON.parse(t);if(e.answer!==void 0)return String(e.answer)}catch{}let n=t.indexOf(`"answer"`);if(n===-1)return``;let r=t.indexOf(`:`,n+8);if(r===-1)return``;let i=r+1;for(;i<t.length&&/\s/.test(t[i]);)i++;if(i>=t.length||t[i]!==`"`)return``;let a=t.slice(i+1);return a.endsWith(`"}`)?a=a.slice(0,-2):a.endsWith(`"`)&&(a=a.slice(0,-1)),a.replace(/\\"/g,`"`).replace(/\\n/g,`
60
- `).replace(/\\\\/g,`\\`)}function _w(e,t){if(e.type!==`agent_error`||e.recoverable!==!0)return!1;let n=t[t.length-1];return!n||n.type!==`tool`?!1:n.success===!1||!!n.active&&n.success==null}function vw(e){let t=(e||[]).filter(e=>typeof e.render==`string`&&e.render.length>0).map(e=>({render:e.render,data:e.data}));return t.length>0?t:void 0}function yw(e){return(e||[]).map(e=>{let t=e.agentSteps||e.agent_steps||void 0;return{...e,agentSteps:t,cards:e.cards||vw(t),stats:e.stats||e.inference_stats||void 0,turnSummary:e.turnSummary||e.turn_summary||void 0,stopState:e.stopState??(e.stopped?`stopped`:void 0)}})}function bw(e,t,n){let r=e.find(e=>e.id===n.id&&e.role===`user`);if(r)return r;let i=t.findIndex(e=>e.id===n.id);if(i<0)throw Error(`Message ${n.id} is no longer in this chat.`);let a=new Set(e.map(e=>e.id)),o=i-1;for(;o>=0&&!a.has(t[o].id);)o--;let s=o<0?0:e.findIndex(e=>e.id===t[o].id)+1,c=e.slice(s).filter(e=>e.role===`user`),l=0;for(let e of t.slice(o+1,i))e.role===`user`&&c[l]?.content===e.content&&l++;return c[l]?.content===n.content?c[l]:null}function xw(e,t){return!!e&&e.role===`assistant`&&!!t.failureText&&e.content.trim()===t.failureText.trim()}function Sw(e,t,n){let r=e.slice(e.findIndex(e=>e.id===t.id)+1);return r.length===0||r.length===1&&(r[0].id===n.id||xw(r[0],n))}function Cw(e,t){let n=e[e.length-1],r=t[t.length-1];if(!n?.failed||!xw(r,n))return t;let i=e=>[...e].reverse().find(e=>e.role===`user`)?.content;return i(e)===i(t)?[...t.slice(0,-1),{...r,failed:!0,failureText:n.failureText}]:t}function ww(e){return`policy-receipt-${encodeURIComponent(e)}`}function Tw(e){let t=e.content.trim();return!t||e.stopState||e.failed||e.failure||xC(t)?!1:!CC(e.agentSteps??[],t).echoed}function Ew(){(0,X.useEffect)(()=>{let e=!0,t=async()=>{try{let t=await pS();e&&t&&ES.getState().setSettings(t)}catch(e){d.ui.error(`Could not load the read-aloud settings; replies will not be read automatically`,e)}};return t(),window.addEventListener(`focus`,t),()=>{e=!1,window.removeEventListener(`focus`,t)}},[])}var Dw=[`download`,`decode`,`transcribe`,`voices`,`prepare`,`analyze`],Ow=0,kw=5;function Aw(e,t){return e==null?``:e<60?t(`recording.leftUnderMinute`):t(`recording.leftMinutes`,{minutes:Math.ceil(e/60)})}function jw(e){return Dw.map((e,t)=>t).filter(t=>t!==Ow&&t!==kw||t in e)}function Mw({state:e}){return e===1?P(mr,{size:14,"aria-hidden":`true`}):e===2?P(da,{size:14,"aria-hidden":`true`}):P(`span`,{className:`recording-progress-dot`,"aria-hidden":`true`})}function Nw({index:e,stage:t}){let n=T(),r=n(`recording.stage.${Dw[e]}`),i=t?.state===0,a=t?.percent,o=i?Aw(t?.etaSeconds,n):``,s=t?.state===2?n(`recording.skipped`):o;return V(`li`,{className:`recording-progress-row${i?` is-running`:``}${t?``:` is-waiting`}${t?.state===1?` is-done`:``}`,children:[P(`span`,{className:`recording-progress-mark`,children:P(Mw,{state:t?.state})}),P(`span`,{className:`recording-progress-label`,children:r}),i&&a!=null&&V(`bdi`,{className:`recording-progress-percent`,dir:`ltr`,children:[a,`%`]}),s&&P(`span`,{className:`recording-progress-left`,children:s}),i&&P(`div`,{className:`recording-progress-track${a==null?` is-indeterminate`:``}`,role:`progressbar`,"aria-label":r,"aria-valuemin":a==null?void 0:0,"aria-valuemax":a==null?void 0:100,"aria-valuenow":a??void 0,children:P(`div`,{className:`recording-progress-fill`,style:a==null?void 0:{inlineSize:`${a}%`}})})]})}var Pw=120;function Fw(e){let t=[];return Object.values(e).sort((e,t)=>e.section-t.section).map(e=>{let n=e.items.filter(e=>{let n=e.title.trim().toLowerCase(),r=t.some(t=>t.title===n&&Math.abs(t.seconds-e.seconds)<Pw);return r||t.push({title:n,seconds:e.seconds}),!r});return{...e,items:n}})}function Iw({sections:e}){let t=T(),n=Fw(e),r=n[0]?.sections??0;return V(`section`,{className:`recording-found`,"aria-label":t(`recording.found.title`),children:[V(`h4`,{className:`recording-found-title`,children:[t(`recording.found.title`),P(`span`,{className:`recording-found-count`,children:t(`recording.found.count`,{done:n.length,total:r})})]}),n.map(e=>V(`div`,{className:`recording-found-section`,children:[V(`p`,{className:`recording-found-span`,children:[V(`bdi`,{dir:`ltr`,className:`recording-found-time`,children:[e.start,`–`,e.end]}),e.summary&&P(`span`,{dir:`auto`,children:e.summary})]}),e.items.length>0&&P(`ul`,{className:`recording-found-items`,children:e.items.map(e=>V(`li`,{children:[P(`bdi`,{dir:`ltr`,className:`recording-found-time`,children:e.start}),P(`span`,{dir:`auto`,children:e.title})]},`${e.seconds}-${e.title}`))})]},e.section))]})}function Lw(){let e=T(),t=k(e=>e.recordingStages),n=k(e=>e.recordingSections);return t?V(`section`,{className:`recording-progress`,"aria-label":e(`recording.title`),children:[P(`ol`,{className:`recording-progress-list`,children:jw(t).map(e=>P(Nw,{index:e,stage:t[e]},e))}),n&&P(Iw,{sections:n})]}):null}var Rw=5e3,zw=2e3,Bw=3e4,Vw=6e4;function Hw(e){return e?.init_state===`initializing`?!e.init_tasks||e.init_tasks.some(e=>e.status===`pending`||e.status===`running`):!1}function Uw(e){return e.lemonade_running?`up`:e.lemonade_error?`unresponsive`:`down`}function Ww(e){return e.kind===`slow`||e.kind===`error`||e.kind===`ok`&&Uw(e.status)===`unresponsive`}function Gw(e){let t=e.kind===`ok`?e.status.download_progress?.state:void 0;return t===`downloading`||t===`starting`}function Kw(e){let t=null,n=0,r=!1,i=null,a=0,o=null,s=async()=>{let e={controller:new AbortController,cancelled:!1};o=e;let{controller:t}=e,n=setTimeout(()=>t.abort(),Vw);try{return{kind:`ok`,status:await Nt(t.signal)}}catch(n){if(e.cancelled)return null;if(t.signal.aborted)return{kind:`slow`};let r=n?.httpStatus;return r===504?{kind:`slow`}:n?.name===`ApiError`&&typeof r==`number`&&r!==502?{kind:`error`,httpStatus:r,message:n.message}:{kind:`unreachable`,error:n}}finally{clearTimeout(n),o===e&&(o=null)}},c=()=>{if(t)return t;let i=s().then(t=>{if(t!==null){n=Ww(t)?n+1:0,r=Gw(t);try{e(t)}catch(e){d.system.error(`Could not apply the system status; the next poll will try again`,e)}}}).finally(()=>{t===i&&(t=null)});return t=i,i},l=()=>Math.min((r?zw:Rw)*2**n,Bw),u=e=>{c().finally(()=>{e===a&&(i=setTimeout(()=>u(e),l()))})};return{check:c,start:()=>{let e=++a;return u(e),()=>{e===a&&(a++,i&&clearTimeout(i),i=null,o&&(o.cancelled=!0,o.controller.abort(),o=null,t=null))}}}}var qw=1e3,Jw=15e3,Yw=null,Xw=null,Zw=qw,Qw=0,$w=null;function eT(){if(Yw)return Yw;let e=Date.now();return Yw=bn().then(t=>k.getState().setActiveRuns(t,e)).catch(e=>{d.api.warn(`Could not read which chats are running`,e),Px(e)&&k.getState().loseActiveRuns()}).finally(()=>{Yw=null}),Yw}function tT(){let e=k.getState();return e.isStreaming||e.runningSessionIds.length>0}function nT(){return tT()?(Zw=qw,qw):(Zw=Math.min(Zw*2,Jw),Zw)}function rT(e){eT().then(()=>{e===Qw&&(Xw=setTimeout(()=>rT(e),nT()))})}function iT(){$w&&(Xw&&clearTimeout(Xw),Xw=null,Zw=qw,rT(++Qw))}function aT(){$w?.();let e=k.subscribe((e,t)=>{e.isStreaming&&!t.isStreaming&&iT()}),t=()=>iT();window.addEventListener(`focus`,t);let n=()=>{Qw++,Xw&&clearTimeout(Xw),Xw=null,e(),window.removeEventListener(`focus`,t),$w===n&&($w=null)};return $w=n,Zw=qw,rT(++Qw),n}var oT=3e3,sT=new Set,cT=new Map,lT=new Set,uT=null;function dT(e,t=Date.now()){cT.set(e,t)}function fT(e){let t=k.getState();return t.activeRunsAt>0&&t.activeRunsAt>=(cT.get(e)??0)&&!t.runningSessionIds.includes(e)&&!t.queuedSessionIds.includes(e)}function pT(e){return lT.add(e),()=>{lT.delete(e),uT?.()}}function mT(e){return e instanceof Error?KS(e)??(e.message||`Unknown error`):String(e)}function hT(e){let t=e?.httpStatus;return typeof t==`number`?t:void 0}function gT(e){let t=hT(e);return t===409||t===429}function _T(e){d.chat.warn(`Chat ${e} no longer exists; dropping its queued messages`),k.getState().updateQueue(e,()=>[])}function vT(e){k.getState().setQueueHold(e,!0),setTimeout(()=>k.getState().setQueueHold(e,!1),oT)}function yT(e,t,n){return hT(n)===409&&(d.chat.info(`Chat ${e} was busy; queueing the message to try again`),k.getState().updateQueue(e,e=>ee(e,t,`queued`)),vT(e),!0)}async function bT(e,t,n){let r=k.getState;if(sT.has(e)||r().queueHolds[e])return;let i=r().messageQueues[e]??[];if(i.some(e=>e.state===`sending`))return;let a=A(i);if(a||w(i)){sT.add(e);try{if(a){let t;try{t=await Vt(e)}catch(t){if(hT(t)===409){d.chat.info(`Chat ${e} is answering again; its queue waits for that turn to end`);return}if(hT(t)===404){_T(e);return}d.chat.error(`Could not learn what chat ${e}'s last reply did with the messages added to it`,t),r().updateQueue(e,e=>F(e,`GAIA could not say whether it read this message: ${mT(t)}`));return}r().updateQueue(e,e=>E(e,t))}let i=w(r().messageQueues[e]??[]);if(!i||!n())return;r().updateQueue(e,e=>ae(e,i.id,`queued`,`starting`));let o;try{o=await t(e,i.text)}catch(e){o={kind:`failed`,error:mT(e)}}if(o.kind===`accepted`){dT(e),r().updateQueue(e,e=>ie(e,i.id)),iT();return}if(o.kind===`busy`){d.chat.info(`Queued message found chat ${e} busy; holding it`),r().updateQueue(e,e=>ne(e,i.id)),vT(e);return}if(o.kind===`gone`){_T(e);return}d.chat.error(`Queued message for chat ${e} was not sent: ${o.error}`),r().updateQueue(e,e=>ne(e,i.id,o.error))}finally{sT.delete(e)}}}function xT(e){return e.type!==`status`||e.phase!==`waiting`}var ST=(e,t)=>new Promise(n=>{let r=!1,i=null,a=!1,o=e=>{r||(r=!0,e.kind===`accepted`&&(i?i.abort():a=!0),n(e))},s=()=>o({kind:`accepted`});d.chat.info(`Sending queued message for chat ${e} in the background`),i=Ve(e,t,{onChunk:s,onAgentEvent:e=>{xT(e)&&s()},onDone:s,onError:e=>{US(e)?s():gT(e)?o({kind:`busy`}):hT(e)===404?o({kind:`gone`}):o({kind:`failed`,error:mT(e)})}}),a&&i.abort()});function CT(e=ST){let t=()=>{let t=k.getState();if(!Hw(t.systemStatus))for(let n of Object.keys(t.messageQueues))!lT.has(n)&&fT(n)&&bT(n,e,()=>!lT.has(n))},n=k.subscribe((e,n)=>{(e.messageQueues!==n.messageQueues||e.queueHolds!==n.queueHolds||e.activeRunsAt!==n.activeRunsAt||e.runningSessionIds!==n.runningSessionIds||e.systemStatus!==n.systemStatus)&&t()});return uT=t,t(),()=>{n(),uT===t&&(uT=null)}}var wT=new Set([`.3g2`,`.3gp`,`.asf`,`.avi`,`.divx`,`.f4v`,`.flv`,`.m2ts`,`.m2v`,`.m4v`,`.mkv`,`.mov`,`.mp4`,`.mpeg`,`.mpg`,`.mts`,`.mxf`,`.ogv`,`.rm`,`.rmvb`,`.vob`,`.webm`,`.wmv`]),TT=new Set([`.aac`,`.ac3`,`.aif`,`.aiff`,`.amr`,`.ape`,`.au`,`.caf`,`.dts`,`.eac3`,`.flac`,`.m4a`,`.m4b`,`.mka`,`.mp2`,`.mp3`,`.oga`,`.ogg`,`.opus`,`.spx`,`.wav`,`.wma`,`.wv`]);function ET(e){let t=e.lastIndexOf(`.`);return t<0?``:e.slice(t).toLowerCase()}function DT(e){return wT.has(ET(e))}function OT(e){let t=ET(e);return wT.has(t)||TT.has(t)}var kT=`https://github.com/amd/gaia/issues/new`,AT=[{label:`Image`,extensions:new Set([`.ico`,`.heic`,`.heif`]),message:`This image format cannot be indexed.`,alternatives:[`Convert it to PNG or JPEG — GAIA reads the text in those images`],featureTitle:`Support HEIC and ICO image indexing`},{label:`Video`,extensions:wT,message:`Video files can't go in the document library.`,alternatives:[`Attach the video to a chat, and GAIA will transcribe it`],featureTitle:`Support video files in the document library`},{label:`Audio`,extensions:TT,message:`Audio files can't go in the document library.`,alternatives:[`Attach the recording to a chat, and GAIA will transcribe it`],featureTitle:`Support audio files in the document library`},{label:`Archive`,extensions:new Set([`.zip`,`.rar`,`.7z`,`.tar`,`.gz`,`.bz2`,`.xz`,`.tgz`]),message:`Archive files must be extracted before indexing.`,alternatives:[`Extract the archive contents to a folder`,`Then index the folder or individual files from the Document Library`],featureTitle:`Support automatic archive extraction for indexing`},{label:`Executable`,extensions:new Set([`.exe`,`.msi`,`.dll`,`.so`,`.app`,`.dmg`,`.bin`,`.com`]),message:`Executable and binary files cannot be indexed.`,alternatives:[`Index source code files (.py, .js, .ts, .java, etc.) instead`,`Index documentation or README files from the project`],featureTitle:`Support binary file analysis`},{label:`Database`,extensions:new Set([`.sqlite`,`.db`,`.mdb`,`.accdb`,`.dbf`]),message:`Database files are not supported for direct indexing.`,alternatives:[`Export data to CSV or JSON format, then index those files`,`Use SQL queries to extract relevant data to a text file`],featureTitle:`Support database file indexing`},{label:`Microsoft Office`,extensions:new Set([`.doc`,`.ppt`,`.xls`]),message:`Legacy Office formats (.doc, legacy PowerPoint .ppt, legacy Excel .xls) are not supported — GAIA reads only the modern XML-based formats. Modern Word (.docx), PowerPoint (.pptx), and Excel (.xlsx) are supported.`,alternatives:[`Re-save as .docx — GAIA indexes modern Word documents directly`,`Save modern PowerPoint as .pptx — GAIA indexes .pptx directly`,`Re-save legacy .xls workbooks as .xlsx — GAIA supports modern Excel files`],featureTitle:`Support legacy Microsoft Office (doc, ppt, xls) indexing`}];function jT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;for(let e of AT)if(e.extensions.has(t))return e;return null}var MT=new Set(`.pdf,.pptx,.docx,.epub,.png,.jpg,.jpeg,.webp,.bmp,.gif,.tif,.tiff,.txt,.md,.mdx,.markdown,.rst,.csv,.json,.xlsx,.html,.htm,.xml,.svg,.yaml,.yml,.py,.js,.ts,.java,.c,.cpp,.h,.rs,.go,.rb,.sh,.bat,.ps1,.log,.cfg,.ini,.toml`.split(`,`));function NT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;return MT.has(t)}function PT(){let e=navigator.userAgent;return`**Environment:**\n- GAIA Version: 0.26.0rc5\n- Platform: ${navigator.platform||`unknown`}\n- User Agent: ${e}\n- Interface: Agent UI (Web)`}function FT(e,t){let n=[`## Feature Description`,``,t||`I would like GAIA to support: **${e}**`,``,`## Use Case`,``,`_Describe how you would use this feature:_`,``,`## Current Workaround`,``,`_Is there a workaround you are currently using?_`,``,`---`,PT(),``,`_Submitted from GAIA Agent UI_`].join(`
60
+ `).replace(/\\\\/g,`\\`)}function _w(e,t){if(e.type!==`agent_error`||e.recoverable!==!0)return!1;let n=t[t.length-1];return!n||n.type!==`tool`?!1:n.success===!1||!!n.active&&n.success==null}function vw(e){let t=(e||[]).filter(e=>typeof e.render==`string`&&e.render.length>0).map(e=>({render:e.render,data:e.data}));return t.length>0?t:void 0}function yw(e){return(e||[]).map(e=>{let t=e.agentSteps||e.agent_steps||void 0;return{...e,agentSteps:t,cards:e.cards||vw(t),stats:e.stats||e.inference_stats||void 0,turnSummary:e.turnSummary||e.turn_summary||void 0,stopState:e.stopState??(e.stopped?`stopped`:void 0)}})}function bw(e,t,n){let r=e.find(e=>e.id===n.id&&e.role===`user`);if(r)return r;let i=t.findIndex(e=>e.id===n.id);if(i<0)throw Error(`Message ${n.id} is no longer in this chat.`);let a=new Set(e.map(e=>e.id)),o=i-1;for(;o>=0&&!a.has(t[o].id);)o--;let s=o<0?0:e.findIndex(e=>e.id===t[o].id)+1,c=e.slice(s).filter(e=>e.role===`user`),l=0;for(let e of t.slice(o+1,i))e.role===`user`&&c[l]?.content===e.content&&l++;return c[l]?.content===n.content?c[l]:null}function xw(e,t){return!!e&&e.role===`assistant`&&!!t.failureText&&e.content.trim()===t.failureText.trim()}function Sw(e,t,n){let r=e.slice(e.findIndex(e=>e.id===t.id)+1);return r.length===0||r.length===1&&(r[0].id===n.id||xw(r[0],n))}function Cw(e,t){let n=e[e.length-1],r=t[t.length-1];if(!n?.failed||!xw(r,n))return t;let i=e=>[...e].reverse().find(e=>e.role===`user`)?.content;return i(e)===i(t)?[...t.slice(0,-1),{...r,failed:!0,failureText:n.failureText}]:t}function ww(e){return`policy-receipt-${encodeURIComponent(e)}`}function Tw(e){let t=e.content.trim();return!t||e.stopState||e.failed||e.failure||xC(t)?!1:!CC(e.agentSteps??[],t).echoed}function Ew(){(0,X.useEffect)(()=>{let e=!0,t=async()=>{try{let t=await pS();e&&t&&ES.getState().setSettings(t)}catch(e){d.ui.error(`Could not load the read-aloud settings; replies will not be read automatically`,e)}};return t(),window.addEventListener(`focus`,t),()=>{e=!1,window.removeEventListener(`focus`,t)}},[])}var Dw=[`download`,`decode`,`transcribe`,`voices`,`prepare`,`analyze`],Ow=0,kw=5;function Aw(e,t){return e==null?``:e<60?t(`recording.leftUnderMinute`):t(`recording.leftMinutes`,{minutes:Math.ceil(e/60)})}function jw(e){return Dw.map((e,t)=>t).filter(t=>t!==Ow&&t!==kw||t in e)}function Mw({state:e}){return e===1?P(mr,{size:14,"aria-hidden":`true`}):e===2?P(da,{size:14,"aria-hidden":`true`}):P(`span`,{className:`recording-progress-dot`,"aria-hidden":`true`})}function Nw({index:e,stage:t}){let n=T(),r=n(`recording.stage.${Dw[e]}`),i=t?.state===0,a=t?.percent,o=i?Aw(t?.etaSeconds,n):``,s=t?.state===2?n(`recording.skipped`):o;return V(`li`,{className:`recording-progress-row${i?` is-running`:``}${t?``:` is-waiting`}${t?.state===1?` is-done`:``}`,children:[P(`span`,{className:`recording-progress-mark`,children:P(Mw,{state:t?.state})}),P(`span`,{className:`recording-progress-label`,children:r}),i&&a!=null&&V(`bdi`,{className:`recording-progress-percent`,dir:`ltr`,children:[a,`%`]}),s&&P(`span`,{className:`recording-progress-left`,children:s}),i&&P(`div`,{className:`recording-progress-track${a==null?` is-indeterminate`:``}`,role:`progressbar`,"aria-label":r,"aria-valuemin":a==null?void 0:0,"aria-valuemax":a==null?void 0:100,"aria-valuenow":a??void 0,children:P(`div`,{className:`recording-progress-fill`,style:a==null?void 0:{inlineSize:`${a}%`}})})]})}var Pw=120;function Fw(e){let t=[];return Object.values(e).sort((e,t)=>e.section-t.section).map(e=>{let n=e.items.filter(e=>{let n=e.title.trim().toLowerCase(),r=t.some(t=>t.title===n&&Math.abs(t.seconds-e.seconds)<Pw);return r||t.push({title:n,seconds:e.seconds}),!r});return{...e,items:n}})}function Iw({sections:e}){let t=T(),n=Fw(e),r=n[0]?.sections??0;return V(`section`,{className:`recording-found`,"aria-label":t(`recording.found.title`),children:[V(`h4`,{className:`recording-found-title`,children:[t(`recording.found.title`),P(`span`,{className:`recording-found-count`,children:t(`recording.found.count`,{done:n.length,total:r})})]}),n.map(e=>V(`div`,{className:`recording-found-section`,children:[V(`p`,{className:`recording-found-span`,children:[V(`bdi`,{dir:`ltr`,className:`recording-found-time`,children:[e.start,`–`,e.end]}),e.summary&&P(`span`,{dir:`auto`,children:e.summary})]}),e.items.length>0&&P(`ul`,{className:`recording-found-items`,children:e.items.map(e=>V(`li`,{children:[P(`bdi`,{dir:`ltr`,className:`recording-found-time`,children:e.start}),P(`span`,{dir:`auto`,children:e.title})]},`${e.seconds}-${e.title}`))})]},e.section))]})}function Lw(){let e=T(),t=k(e=>e.recordingStages),n=k(e=>e.recordingSections);return t?V(`section`,{className:`recording-progress`,"aria-label":e(`recording.title`),children:[P(`ol`,{className:`recording-progress-list`,children:jw(t).map(e=>P(Nw,{index:e,stage:t[e]},e))}),n&&P(Iw,{sections:n})]}):null}var Rw=5e3,zw=2e3,Bw=3e4,Vw=6e4;function Hw(e){return e?.init_state===`initializing`?!e.init_tasks||e.init_tasks.some(e=>e.status===`pending`||e.status===`running`):!1}function Uw(e){return e.lemonade_running?`up`:e.lemonade_error?`unresponsive`:`down`}function Ww(e){return e.kind===`slow`||e.kind===`error`||e.kind===`ok`&&Uw(e.status)===`unresponsive`}function Gw(e){let t=e.kind===`ok`?e.status.download_progress?.state:void 0;return t===`downloading`||t===`starting`}function Kw(e){let t=null,n=0,r=!1,i=null,a=0,o=null,s=async()=>{let e={controller:new AbortController,cancelled:!1};o=e;let{controller:t}=e,n=setTimeout(()=>t.abort(),Vw);try{return{kind:`ok`,status:await Nt(t.signal)}}catch(n){if(e.cancelled)return null;if(t.signal.aborted)return{kind:`slow`};let r=n?.httpStatus;return r===504?{kind:`slow`}:n?.name===`ApiError`&&typeof r==`number`&&r!==502?{kind:`error`,httpStatus:r,message:n.message}:{kind:`unreachable`,error:n}}finally{clearTimeout(n),o===e&&(o=null)}},c=()=>{if(t)return t;let i=s().then(t=>{if(t!==null){n=Ww(t)?n+1:0,r=Gw(t);try{e(t)}catch(e){d.system.error(`Could not apply the system status; the next poll will try again`,e)}}}).finally(()=>{t===i&&(t=null)});return t=i,i},l=()=>Math.min((r?zw:Rw)*2**n,Bw),u=e=>{c().finally(()=>{e===a&&(i=setTimeout(()=>u(e),l()))})};return{check:c,start:()=>{let e=++a;return u(e),()=>{e===a&&(a++,i&&clearTimeout(i),i=null,o&&(o.cancelled=!0,o.controller.abort(),o=null,t=null))}}}}var qw=1e3,Jw=15e3,Yw=null,Xw=null,Zw=qw,Qw=0,$w=null;function eT(){if(Yw)return Yw;let e=Date.now();return Yw=bn().then(t=>k.getState().setActiveRuns(t,e)).catch(e=>{d.api.warn(`Could not read which chats are running`,e),Px(e)&&k.getState().loseActiveRuns()}).finally(()=>{Yw=null}),Yw}function tT(){let e=k.getState();return e.isStreaming||e.runningSessionIds.length>0}function nT(){return tT()?(Zw=qw,qw):(Zw=Math.min(Zw*2,Jw),Zw)}function rT(e){eT().then(()=>{e===Qw&&(Xw=setTimeout(()=>rT(e),nT()))})}function iT(){$w&&(Xw&&clearTimeout(Xw),Xw=null,Zw=qw,rT(++Qw))}function aT(){$w?.();let e=k.subscribe((e,t)=>{e.isStreaming&&!t.isStreaming&&iT()}),t=()=>iT();window.addEventListener(`focus`,t);let n=()=>{Qw++,Xw&&clearTimeout(Xw),Xw=null,e(),window.removeEventListener(`focus`,t),$w===n&&($w=null)};return $w=n,Zw=qw,rT(++Qw),n}var oT=3e3,sT=new Set,cT=new Map,lT=new Set,uT=null;function dT(e,t=Date.now()){cT.set(e,t)}function fT(e){let t=k.getState();return t.activeRunsAt>0&&t.activeRunsAt>=(cT.get(e)??0)&&!t.runningSessionIds.includes(e)&&!t.queuedSessionIds.includes(e)}function pT(e){return lT.add(e),()=>{lT.delete(e),uT?.()}}function mT(e){return e instanceof Error?KS(e)??(e.message||`Unknown error`):String(e)}function hT(e){let t=e?.httpStatus;return typeof t==`number`?t:void 0}function gT(e){let t=hT(e);return t===409||t===429}function _T(e){d.chat.warn(`Chat ${e} no longer exists; dropping its queued messages`),k.getState().updateQueue(e,()=>[])}function vT(e){k.getState().setQueueHold(e,!0),setTimeout(()=>k.getState().setQueueHold(e,!1),oT)}function yT(e,t,n){return hT(n)===409&&(d.chat.info(`Chat ${e} was busy; queueing the message to try again`),k.getState().updateQueue(e,e=>ee(e,t,`queued`)),vT(e),!0)}async function bT(e,t,n){let r=k.getState;if(sT.has(e)||r().queueHolds[e])return;let i=r().messageQueues[e]??[];if(i.some(e=>e.state===`sending`))return;let a=A(i);if(a||w(i)){sT.add(e);try{if(a){let t;try{t=await Vt(e)}catch(t){if(hT(t)===409){d.chat.info(`Chat ${e} is answering again; its queue waits for that turn to end`);return}if(hT(t)===404){_T(e);return}d.chat.error(`Could not learn what chat ${e}'s last reply did with the messages added to it`,t),r().updateQueue(e,e=>F(e,`GAIA could not say whether it read this message: ${mT(t)}`));return}r().updateQueue(e,e=>E(e,t))}let i=w(r().messageQueues[e]??[]);if(!i||!n())return;r().updateQueue(e,e=>ae(e,i.id,`queued`,`starting`));let o;try{o=await t(e,i.text)}catch(e){o={kind:`failed`,error:mT(e)}}if(o.kind===`accepted`){dT(e),r().updateQueue(e,e=>ie(e,i.id)),iT();return}if(o.kind===`busy`){d.chat.info(`Queued message found chat ${e} busy; holding it`),r().updateQueue(e,e=>ne(e,i.id)),vT(e);return}if(o.kind===`gone`){_T(e);return}d.chat.error(`Queued message for chat ${e} was not sent: ${o.error}`),r().updateQueue(e,e=>ne(e,i.id,o.error))}finally{sT.delete(e)}}}function xT(e){return e.type!==`status`||e.phase!==`waiting`}var ST=(e,t)=>new Promise(n=>{let r=!1,i=null,a=!1,o=e=>{r||(r=!0,e.kind===`accepted`&&(i?i.abort():a=!0),n(e))},s=()=>o({kind:`accepted`});d.chat.info(`Sending queued message for chat ${e} in the background`),i=Ve(e,t,{onChunk:s,onAgentEvent:e=>{xT(e)&&s()},onDone:s,onError:e=>{US(e)?s():gT(e)?o({kind:`busy`}):hT(e)===404?o({kind:`gone`}):o({kind:`failed`,error:mT(e)})}}),a&&i.abort()});function CT(e=ST){let t=()=>{let t=k.getState();if(!Hw(t.systemStatus))for(let n of Object.keys(t.messageQueues))!lT.has(n)&&fT(n)&&bT(n,e,()=>!lT.has(n))},n=k.subscribe((e,n)=>{(e.messageQueues!==n.messageQueues||e.queueHolds!==n.queueHolds||e.activeRunsAt!==n.activeRunsAt||e.runningSessionIds!==n.runningSessionIds||e.systemStatus!==n.systemStatus)&&t()});return uT=t,t(),()=>{n(),uT===t&&(uT=null)}}var wT=new Set([`.3g2`,`.3gp`,`.asf`,`.avi`,`.divx`,`.f4v`,`.flv`,`.m2ts`,`.m2v`,`.m4v`,`.mkv`,`.mov`,`.mp4`,`.mpeg`,`.mpg`,`.mts`,`.mxf`,`.ogv`,`.rm`,`.rmvb`,`.vob`,`.webm`,`.wmv`]),TT=new Set([`.aac`,`.ac3`,`.aif`,`.aiff`,`.amr`,`.ape`,`.au`,`.caf`,`.dts`,`.eac3`,`.flac`,`.m4a`,`.m4b`,`.mka`,`.mp2`,`.mp3`,`.oga`,`.ogg`,`.opus`,`.spx`,`.wav`,`.wma`,`.wv`]);function ET(e){let t=e.lastIndexOf(`.`);return t<0?``:e.slice(t).toLowerCase()}function DT(e){return wT.has(ET(e))}function OT(e){let t=ET(e);return wT.has(t)||TT.has(t)}var kT=`https://github.com/amd/gaia/issues/new`,AT=[{label:`Image`,extensions:new Set([`.ico`,`.heic`,`.heif`]),message:`This image format cannot be indexed.`,alternatives:[`Convert it to PNG or JPEG — GAIA reads the text in those images`],featureTitle:`Support HEIC and ICO image indexing`},{label:`Video`,extensions:wT,message:`Video files can't go in the document library.`,alternatives:[`Attach the video to a chat, and GAIA will transcribe it`],featureTitle:`Support video files in the document library`},{label:`Audio`,extensions:TT,message:`Audio files can't go in the document library.`,alternatives:[`Attach the recording to a chat, and GAIA will transcribe it`],featureTitle:`Support audio files in the document library`},{label:`Archive`,extensions:new Set([`.zip`,`.rar`,`.7z`,`.tar`,`.gz`,`.bz2`,`.xz`,`.tgz`]),message:`Archive files must be extracted before indexing.`,alternatives:[`Extract the archive contents to a folder`,`Then index the folder or individual files from the Document Library`],featureTitle:`Support automatic archive extraction for indexing`},{label:`Executable`,extensions:new Set([`.exe`,`.msi`,`.dll`,`.so`,`.app`,`.dmg`,`.bin`,`.com`]),message:`Executable and binary files cannot be indexed.`,alternatives:[`Index source code files (.py, .js, .ts, .java, etc.) instead`,`Index documentation or README files from the project`],featureTitle:`Support binary file analysis`},{label:`Database`,extensions:new Set([`.sqlite`,`.db`,`.mdb`,`.accdb`,`.dbf`]),message:`Database files are not supported for direct indexing.`,alternatives:[`Export data to CSV or JSON format, then index those files`,`Use SQL queries to extract relevant data to a text file`],featureTitle:`Support database file indexing`},{label:`Microsoft Office`,extensions:new Set([`.doc`,`.ppt`,`.xls`]),message:`Legacy Office formats (.doc, legacy PowerPoint .ppt, legacy Excel .xls) are not supported — GAIA reads only the modern XML-based formats. Modern Word (.docx), PowerPoint (.pptx), and Excel (.xlsx) are supported.`,alternatives:[`Re-save as .docx — GAIA indexes modern Word documents directly`,`Save modern PowerPoint as .pptx — GAIA indexes .pptx directly`,`Re-save legacy .xls workbooks as .xlsx — GAIA supports modern Excel files`],featureTitle:`Support legacy Microsoft Office (doc, ppt, xls) indexing`}];function jT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;for(let e of AT)if(e.extensions.has(t))return e;return null}var MT=new Set(`.pdf,.pptx,.docx,.epub,.png,.jpg,.jpeg,.webp,.bmp,.gif,.tif,.tiff,.txt,.md,.mdx,.markdown,.rst,.csv,.json,.xlsx,.html,.htm,.xml,.svg,.yaml,.yml,.py,.js,.ts,.java,.c,.cpp,.h,.rs,.go,.rb,.sh,.bat,.ps1,.log,.cfg,.ini,.toml`.split(`,`));function NT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;return MT.has(t)}function PT(){let e=navigator.userAgent;return`**Environment:**\n- GAIA Version: 0.26.0rc6\n- Platform: ${navigator.platform||`unknown`}\n- User Agent: ${e}\n- Interface: Agent UI (Web)`}function FT(e,t){let n=[`## Feature Description`,``,t||`I would like GAIA to support: **${e}**`,``,`## Use Case`,``,`_Describe how you would use this feature:_`,``,`## Current Workaround`,``,`_Is there a workaround you are currently using?_`,``,`---`,PT(),``,`_Submitted from GAIA Agent UI_`].join(`
61
61
  `);return`${kT}?${new URLSearchParams({title:`[Feature] ${e}`,body:n,labels:`enhancement,agent-ui`}).toString()}`}function IT(e,t){let n=[`## Bug Description`,``,t||e,``,`## Steps to Reproduce`,``,`1. Open GAIA Agent UI`,`2. _Describe what you did:_`,`3. `,``,`## Expected Behavior`,``,`_What did you expect to happen?_`,``,`## Actual Behavior`,``,`_What happened instead?_`,``,`---`,PT(),``,`_Submitted from GAIA Agent UI_`].join(`
62
62
  `);return`${kT}?${new URLSearchParams({title:`[Bug] ${e}`,body:n,labels:`bug,agent-ui`}).toString()}`}var LT={corrupted:`The file looks damaged. Re-download or re-export it, then index the new copy.`,encrypted:`The PDF needs a password to open. Save a copy without the password, then index that.`,empty:`The PDF has no readable text, which usually means it is a scan. Run OCR on it, then index it again.`,empty_file:`This file is empty. Add content to it, then index it again.`,unsupported_workbook:`This is an old .xls workbook or has a password. Open it in Excel, save a copy as .xlsx without a password, then index that.`};function RT(e,t){return e.startsWith(t)?e.slice(t.length).trim():e}function zT({filename:e,error:t,status:n,kind:r,onDismiss:i,timeout:a=15e3}){let o=(0,X.useRef)(null);(0,X.useEffect)(()=>(a>0&&(o.current=setTimeout(i,a)),()=>{o.current&&clearTimeout(o.current)}),[i,a]);let s=e.includes(`.`)?`.`+e.split(`.`).pop()?.toLowerCase():``,c=s?jT(s):null,l=t.toLowerCase().includes(`unsupported file type`)||t.toLowerCase().includes(`not supported for indexing`)||t.toLowerCase().includes(`file type not allowed`)||c!==null,u=t.toLowerCase().includes(`fetch`)||t.toLowerCase().includes(`network`)||t.toLowerCase().includes(`connect`),d,f,p,m=wr,h=r?LT[r]:void 0;return h?(d=`"${e}" can't be read`,f=h,p=null,m=J):n===404?(d=`"${e}" doesn't exist`,f=RT(t,`File not found:`),p=null,m=J):n===403?(d=`GAIA can't read files in that location`,f=`${t} Or drop the file here instead (up to 20 MB) and GAIA keeps its own copy.`,p=null,m=J):l&&c?(d=`${c.label} files not supported`,f=c.message,p=FT(c.featureTitle),m=J):l&&!s?(d=`"${e}" has no file extension`,f=RT(t,`File type not allowed:`),p=null,m=J):l?(d=`File type not supported: ${s}`,f=`This file format cannot be indexed. Supported: PDF, DOCX, PPTX, XLSX, EPUB, images (PNG, JPG, WEBP, ...), TXT, MD, CSV, JSON, HTML, XML, YAML, and 30+ code file formats.`,p=FT(`Support ${s} file indexing`),m=J):u?(d=`Connection error`,f=`Could not reach the GAIA server. Make sure the backend is running.`,p=IT(`Upload connection error for ${e}`),m=wr):(d=`Failed to index "${e}"`,f=t||`An unexpected error occurred during indexing.`,p=IT(`Indexing error: ${t.slice(0,80)}`),m=or),V(`div`,{className:`upload-error-toast`,role:`alert`,children:[P(m,{size:16}),V(`div`,{className:`upload-error-content`,children:[P(`div`,{className:`upload-error-title`,children:d}),V(`div`,{className:`upload-error-detail`,children:[f,p&&` `,p===null?null:l?P(`a`,{href:p,target:`_blank`,rel:`noopener noreferrer`,children:`Request this feature →`}):P(`a`,{href:p,target:`_blank`,rel:`noopener noreferrer`,children:`Report this issue →`})]})]}),P(`button`,{className:`upload-error-dismiss`,onClick:i,"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}function BT(e,t){let n=e=>t.some(t=>t.id===e&&t.configured),r=Tb(e);return r===`google`?n(`google`):r===`microsoft`?n(`microsoft`):r===`microsoft_work`?n(`microsoft_work`):n(`google`)||n(`microsoft`)||n(`microsoft_work`)}function VT(e,t){let n=e=>t.some(t=>t.id===e&&t.configured),r=Tb(e);return r===`google`?`Google`:r===`microsoft`?`Microsoft`:r===`microsoft_work`?`Microsoft 365`:n(`google`)?`Google`:n(`microsoft`)?`Microsoft`:n(`microsoft_work`)?`Microsoft 365`:`Google`}var HT=4e3;function UT({content:e,onRetry:t}){let[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(!1),o=(0,X.useCallback)(()=>{he().then(e=>r(e.connectors||[])).catch(e=>d.ui.warn(`ConnectorRetryBanner: connector fetch failed`,e))},[]),s=BT(e,n);if((0,X.useEffect)(()=>{o();let e=()=>o();return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[o]),(0,X.useEffect)(()=>{if(s)return;let e=setInterval(o,HT);return()=>clearInterval(e)},[s,o]),!s||i)return null;let c=VT(e,n);return V(`div`,{className:`connector-retry-banner`,role:`status`,children:[P(Or,{size:14,className:`connector-retry-banner__icon`}),V(`span`,{className:`connector-retry-banner__text`,children:[c,` connected since this reply — ask again to run it now.`]}),V(`button`,{type:`button`,className:`connector-retry-banner__btn`,onClick:()=>{a(!0),t()},children:[P(Fa,{size:12}),P(`span`,{children:`Ask again`})]}),P(`button`,{type:`button`,className:`connector-retry-banner__dismiss`,onClick:()=>a(!0),"aria-label":`Dismiss`,children:`×`})]})}function WT(e){return e.isMedia?DT(e.name)?mi:ci:gi}var GT=240,KT=1e5;function qT({value:e,onChange:t,onSubmit:n,onStop:r,streaming:i=!1,stopping:a=!1,queueWhileStreaming:o=!1,disabledReason:s,attachments:c,placeholder:l,autoFocus:u,inputRef:d,leftControls:f,rightControls:p}){let m=T(),h=(0,X.useRef)(null),g=d??h,_=(0,X.useRef)(null),v=!!s,y=e.trim().length>0||c.hasUploaded,b=c.compose(e.trim()).length,x=b>KT,S=!v&&(!i||o)&&!c.uploading&&y&&!x,C=s||l||m(`composer.placeholder`);(0,X.useLayoutEffect)(()=>{let e=g.current;if(!e)return;let t=()=>{e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,GT)}px`};if(t(),typeof ResizeObserver>`u`)return;let n=e.clientWidth,r=new ResizeObserver(()=>{e.clientWidth!==n&&(n=e.clientWidth,t())});return r.observe(e),()=>r.disconnect()},[e,C,g]);let w=(0,X.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),S&&n())},[S,n]),E=(0,X.useCallback)(e=>{e.dataTransfer?.files?.length&&(e.preventDefault(),e.stopPropagation(),c.addFiles(Array.from(e.dataTransfer.files)))},[c]);return V(`div`,{className:`composer${v?` composer-disabled`:``}`,onDrop:E,onDragOver:e=>{e.dataTransfer?.types?.includes(`Files`)&&e.preventDefault()},children:[c.attachments.length>0&&P(`ul`,{className:`composer-attachments`,"aria-label":m(`composer.attached`),children:c.attachments.map(e=>{let t=WT(e);return V(`li`,{className:`composer-attachment${e.error?` has-error`:``}${e.isMedia?` is-media`:``}`,children:[e.isImage&&e.url?P(`img`,{src:e.url,alt:``,className:`composer-attachment-thumb`}):P(t,{size:14,"aria-hidden":`true`}),P(`span`,{className:`composer-attachment-name`,title:e.name,dir:`auto`,children:e.name}),e.uploading&&P(`span`,{className:`composer-attachment-state`,children:e.progress===void 0?m(`composer.uploading`):m(`composer.uploadingPercent`,{percent:e.progress})}),e.uploaded&&e.isMedia&&P(`span`,{className:`composer-attachment-state`,children:m(`composer.mediaReady`)}),e.error&&P(`span`,{className:`composer-attachment-state`,role:`alert`,title:e.error,children:e.error}),P(`button`,{type:`button`,className:`composer-icon-btn`,onClick:()=>c.remove(e.id),"aria-label":m(`composer.remove`,{name:e.name}),children:P(Y,{size:12})})]},e.id)})}),P(`textarea`,{ref:g,className:`composer-input`,value:e,onChange:e=>t(e.target.value),onKeyDown:w,onPaste:e=>{c.handlePaste(e)},placeholder:C,rows:1,disabled:v,autoFocus:u,"aria-label":m(`composer.message`),dir:`auto`}),x&&V(`p`,{className:`composer-limit-error`,role:`alert`,children:[m(`composer.tooLong`,{sent:b.toLocaleString(),max:1e5.toLocaleString()}),` `,m(`composer.tooLongHint`)]}),V(`div`,{className:`composer-row`,children:[V(`div`,{className:`composer-row-left`,children:[P(`button`,{type:`button`,className:`composer-icon-btn`,onClick:()=>_.current?.click(),disabled:v,"aria-label":m(`composer.attach`),title:m(`composer.attach`),children:P(Na,{size:16})}),P(`input`,{ref:_,type:`file`,multiple:!0,hidden:!0,onChange:e=>{e.target.files&&c.addFiles(Array.from(e.target.files)),e.target.value=``}}),f]}),V(`div`,{className:`composer-row-right`,children:[p,i&&o&&y&&P(`button`,{type:`button`,className:`composer-send`,onClick:n,disabled:!S,"aria-label":m(`composer.queue`),title:m(`composer.queueTitle`),children:P(Xn,{size:16})}),i?P(`button`,{type:`button`,className:`composer-send is-stop`,onClick:r,disabled:a,"aria-label":m(`composer.stop`),title:a?m(`composer.stopping`):m.hint(m(`composer.stop`),`Esc`),children:P(ao,{size:12,fill:`currentColor`})}):P(`button`,{type:`button`,className:`composer-send`,onClick:n,disabled:!S,"aria-label":m(`composer.send`),title:m.hint(m(`composer.send`),`Enter`),children:P(Xn,{size:16})})]})]})]})}var JT=8,YT=8;function XT({label:e,warning:t,children:n,id:r,pinned:i=!1,onUnpin:a,tabIndex:o}){let s=(0,X.useId)(),c=r??s,l=(0,X.useRef)(null),u=(0,X.useRef)(null),[d,f]=(0,X.useState)(!1),p=d||i,[m,h]=(0,X.useState)(null);return(0,X.useLayoutEffect)(()=>{if(!p){h(null);return}let e=l.current?.getBoundingClientRect(),t=u.current?.getBoundingClientRect(),n=l.current?.closest(`[role="dialog"]`)?.getBoundingClientRect()??e;if(!e||!t||!n)return;let r=window.innerWidth,i=window.innerHeight,a,o;n.right+JT+t.width<=r-YT?(a=n.right+JT,o=e.top+e.height/2-t.height/2):n.left-JT-t.width>=YT?(a=n.left-JT-t.width,o=e.top+e.height/2-t.height/2):(a=Math.min(Math.max(YT,e.right-t.width),r-YT-t.width),o=e.top-JT-t.height>=YT?e.top-JT-t.height:e.bottom+JT),o=Math.min(Math.max(YT,o),i-YT-t.height),h({left:a,top:o})},[p]),(0,X.useEffect)(()=>{if(!p)return;let e=()=>{f(!1),a?.()};return window.addEventListener(`scroll`,e,!0),()=>window.removeEventListener(`scroll`,e,!0)},[p,a]),V(D.Fragment,{children:[P(`button`,{ref:l,type:`button`,className:`info-bubble-icon${t?` is-warning`:``}`,"aria-label":e,tabIndex:o,"aria-describedby":p?c:void 0,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),onFocus:()=>f(!0),onBlur:()=>f(!1),onClick:e=>{e.stopPropagation(),f(e=>!e)},onKeyDown:e=>{e.key===`Escape`&&p&&(e.stopPropagation(),f(!1))},children:P(Hi,{size:13,"aria-hidden":`true`})}),p&&(0,eS.createPortal)(P(`div`,{ref:u,id:c,role:`tooltip`,className:`info-bubble`,style:m?{left:m.left,top:m.top}:{left:0,top:0,visibility:`hidden`},children:n}),document.body)]})}function ZT(e){return e<.1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function QT(e,t=z){return e?t(`settings.price.perMillion`,{input:ZT(e.input_per_million),output:ZT(e.output_per_million)}):t(`settings.price.unknown`)}function $T(e){return`$${e.toFixed(2)}`}var eE=2e3,tE=`waiting_for_os_permission`,nE=5;function rE(e,t){let n=e.rank?`#${e.rank} ${e.note??``}`.trim():null;return t?[n,QT(e.price)].filter(e=>!!e):[Ss(e.placement),e.size_gb?`${e.size_gb} GB`:null,e.tokens_per_second?`${Math.round(e.tokens_per_second)} tok/s on this PC`:null,n,e.custom?`added by you`:null].filter(e=>!!e)}function iE({m:e,onDownload:t,busy:n}){if(Ts(e)){let t=Math.round(e.download_progress?.percent??0);return V(`span`,{className:`model-state is-downloading`,title:`Downloading, ${t}%`,children:[P(q,{size:12,className:`spin`,"aria-hidden":`true`}),` `,t,`%`]})}let r=ws(e);return r===`not_downloaded`?P(`button`,{type:`button`,className:`model-state-btn`,onClick:e=>{e.stopPropagation(),t()},disabled:n,"aria-label":`Download ${e.display_name??e.id}`,title:xs.not_downloaded,tabIndex:-1,children:P(Jr,{size:13,"aria-hidden":`true`})}):r===`loaded`?P(`span`,{className:`model-state is-loaded`,role:`img`,"aria-label":xs.loaded,title:xs.loaded}):P(`span`,{className:`model-state is-ready`,title:xs.downloaded,children:`Ready`})}function aE(){let e=T(),t=cs(e=>e.active),n=cs(e=>e.select),r=cs(e=>e.queued),i=cs(e=>e.queue),a=cs(e=>e.queueError),o=cs(e=>e.rememberNames);cs(e=>e.names);let s=hs(),c=k(e=>gs(t,e.sessions,e.currentSessionId)),l=k(e=>e.isStreaming),u=k(e=>e.openSettings),d=(0,X.useRef)(null),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(0),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(null),[A,j]=(0,X.useState)(0),[M,N]=(0,X.useState)(null),F=(0,X.useRef)(0),I=(0,X.useRef)(null),L=(0,X.useId)(),ee=(0,X.useRef)(null),R=(0,X.useRef)(null),[z,B]=(0,X.useState)(null),[te,ne]=(0,X.useState)(null),re=(0,X.useCallback)(()=>ne(null),[]),ie=(0,X.useCallback)(()=>p(!1),[]),ae=(0,X.useRef)(!1),oe=(0,X.useCallback)(async(t=!1)=>{t||(ae.current=!1,y(null),h(null));try{let{providers:n,lemonade_error:r}=await Tn();if(r)throw Error(r);let i=n.filter(e=>!e.remote||e.models_discovered||e.id===`fireworks`||e.registered),a=await Promise.all(i.map(async t=>{if(t.blocked)return{provider:t,models:[],error:e(`settings.privacy.localOnlyBlocked`)};if(t.remote&&!t.models_discovered)return{provider:t,models:[]};try{let n=await Zt(t.id);return{provider:t,models:n.models,error:n.blocked?e(`settings.privacy.localOnlyBlocked`):void 0}}catch(e){return{provider:t,models:[],error:Ix(e)}}}));o(a.flatMap(e=>e.models)),_(a.flatMap(e=>e.models).filter(e=>e.available===!1).length),t||(ae.current=!0),h(a.map(e=>({...e,models:e.models.filter(e=>e.available!==!1)})))}catch(e){y(Ix(e))}},[o,e]);(0,X.useEffect)(()=>{f&&(x(null),B(null),ne(null),oe())},[f,oe]),(0,X.useEffect)(()=>{if(!f||!m||!ae.current)return;let e=ee.current?.querySelector(`[role="option"][tabindex="0"]`);e&&(ae.current=!1,e.focus(),e.scrollIntoView?.({block:`nearest`}))},[f,m]),(0,X.useEffect)(()=>{b&&R.current?.scrollIntoView?.({block:`nearest`})},[b]);let H=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return;let t=Array.from(ee.current?.querySelectorAll(`[role="option"]:not(:disabled)`)??[]);if(!t.length)return;let n=t.indexOf(document.activeElement),r;switch(e.key){case`ArrowDown`:r=n<0?0:Math.min(n+1,t.length-1);break;case`ArrowUp`:r=n<0?t.length-1:Math.max(n-1,0);break;case`Home`:r=0;break;case`End`:r=t.length-1;break;case`ArrowRight`:case`i`:{let r=n<0?void 0:t[n].dataset.row;if(!r)return;e.preventDefault(),ne(t=>e.key===`i`&&t===r?null:r);return}case`ArrowLeft`:e.preventDefault(),ne(null);return;default:return}e.preventDefault(),t[r].focus(),t[r].scrollIntoView?.({block:`nearest`})},U=!!m?.some(e=>e.models.some(Ts)),se=!!m?.some(e=>e.provider.key_state===tE);(0,X.useEffect)(()=>{if(!(f||D)||!(U||D||se))return;let e=setInterval(()=>{oe(!0)},eE);return()=>clearInterval(e)},[f,U,D,se,oe]);let W=(0,X.useCallback)(async e=>{E(e),j(e=>e+1),y(null);try{await fe(e),await oe(!0)}catch(t){O(t=>t?.model===e?null:t),y(Ix(t))}finally{E(null),j(e=>e-1)}},[oe]),G=(0,X.useCallback)(async(e,r)=>{if(r.remote&&!t?.remote&&b?.model!==e)return x({model:e,provider:r}),null;if(x(null),l)return i(e===t?.model?null:e),p(!1),null;C(e),y(null);try{return await n(e),N(null),p(!1),null}catch(e){let t=Ix(e);return y(t),t}finally{C(null)}},[t?.model,t?.remote,b,i,n,l]);(0,X.useEffect)(()=>{if(!D||!m||A>0)return;let{model:e,provider:t}=D,n=()=>(I.current!==m&&(I.current=m,F.current+=1),F.current>=nE),r=m.flatMap(e=>e.models).find(t=>t.id===e);if(!r){if(!n())return;O(null),N(`${ds(e)} is no longer in the model list, so it wasn't switched to.`);return}if(Ts(r)){F.current=0;return}let i=r.download_progress;if(i?.state===`error`)O(null),N(`Downloading ${ds(e)} failed: ${i.message??`no reason given`}`);else if(i?.state!==`complete`&&ws(r)===`not_downloaded`){if(!n())return;O(null),N(`The download of ${ds(e)} never started. Try the download button again.`)}else O(null),G(e,t).then(t=>{t&&N(`${ds(e)} downloaded, but switching to it failed: ${t}`)})},[m,D,A,G]);let ce=m?.flatMap(({provider:e,models:t})=>[...e.remote&&!e.models_discovered?[`key:${e.id}`]:[],...t.filter(e=>S===null&&!Ts(e)).map(e=>e.id)])??[],le=r??t?.model,ue=z&&ce.includes(z)?z:le&&ce.includes(le)?le:ce[0],de=e=>({role:`option`,tabIndex:e===ue?0:-1,"data-row":e,onFocus:()=>B(e),onBlur:()=>ne(null)}),pe=s?.remote?Ir:s?Wr:Ar,me=c?ds(c):`Model`,he=`${me}${s?` · ${s.label}`:``}`,ge=Object.fromEntries((m??[]).map(e=>[e.provider.id,ys(e.models)])),_e=t?.downloaded===!1&&c===t.model,ve=M||a||(r?`${ds(r)} is used from your next message.`:t?.config_error?t.config_error:_e?`${me} isn't downloaded yet. Open the list to download it.`:s?s.description?.replace(/`/g,``)??(s.remote?`Runs on ${s.label} — chat history leaves this PC`:`Runs on this PC`):ms);return V(`div`,{className:`composer-chip-wrap`,children:[V(`button`,{ref:d,type:`button`,className:`composer-chip${_e||a||M?` is-warning`:``}`,onClick:()=>p(e=>!e),"aria-haspopup":`dialog`,"aria-expanded":f,title:ve,children:[P(pe,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:he}),r&&V(`span`,{className:`composer-chip-next`,children:[`→ `,ds(r),` next`]}),_e&&P(Jr,{size:12,"aria-label":`Not downloaded`}),M&&P(wr,{size:12,"aria-label":`Model switch failed`}),P(gr,{size:12,"aria-hidden":`true`})]}),V(Ro,{open:f,onClose:ie,anchor:d,label:`Choose a model`,align:`end`,children:[l&&V(`div`,{className:`popover-message`,role:`status`,children:[`This reply keeps `,c?ds(c):`its model`,`. A model you pick here is used from your next message.`]}),M&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:M}),a&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:a}),v&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:v}),!m&&!v&&V(`div`,{className:`popover-message`,children:[P(q,{size:13,className:`spin`}),` Loading models…`]}),m&&P(`div`,{ref:ee,role:`listbox`,"aria-label":`Models`,onKeyDown:H,children:m.map(({provider:e,models:n,error:i})=>V(`div`,{role:`group`,"aria-labelledby":`${L}-${e.id}`,children:[P(`div`,{className:`popover-heading`,id:`${L}-${e.id}`,children:e.name}),i&&P(`div`,{className:`popover-message is-error`,children:i}),e.key_state===tE?V(`div`,{className:`popover-message`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,e.key_message]}):e.remote&&!e.models_discovered&&V(`button`,{type:`button`,className:`popover-item`,...de(`key:${e.id}`),"aria-selected":!1,onClick:()=>{p(!1),u(`model`,e.id)},children:[P(`span`,{className:`popover-item-check`,children:P(Wi,{size:13,"aria-hidden":`true`})}),V(`span`,{className:`popover-item-body`,children:[P(`span`,{className:`popover-item-title`,children:`Add your key`}),V(`span`,{className:`popover-item-note`,children:[`Connect `,e.name,` in Settings`]})]})]}),!i&&n.length===0&&e.models_discovered!==!1&&P(`div`,{className:`popover-message`,children:`No models yet.`}),n.map(n=>{let i=us(r??t?.model,n.id),a=!e.remote&&ws(n)===`not_downloaded`,o=ge[e.id][n.id],s=rE(n,e.remote),c=`${L}-info-${e.id}-${n.id}`;return V(X.Fragment,{children:[V(`div`,{className:`popover-row`,children:[V(`button`,{type:`button`,className:`popover-item`,onClick:()=>{a?(F.current=0,N(null),O({model:n.id,provider:e}),W(n.id)):(O(null),G(n.id,e))},disabled:S!==null||Ts(n),...de(n.id),"aria-selected":i,"aria-describedby":te===n.id?c:void 0,children:[P(`span`,{className:`popover-item-check`,"aria-hidden":`true`,children:S===n.id?P(q,{size:13,className:`spin`}):i?P(mr,{size:13}):null}),P(`span`,{className:`popover-item-body`,children:P(`span`,{className:`popover-item-title`,children:o})})]}),V(XT,{label:`About ${o}`,warning:!!n.placement?.warning,id:c,pinned:te===n.id,onUnpin:re,tabIndex:-1,children:[P(`div`,{className:`info-bubble-title`,children:o}),s.length>0&&P(`ul`,{className:`info-bubble-lines`,children:s.map(e=>P(`li`,{children:e},e))}),n.placement?.warning&&P(`ul`,{className:`info-bubble-lines`,children:P(`li`,{className:`is-warning`,children:n.placement.warning})}),P(`div`,{className:`info-bubble-id`,children:n.id})]}),P(`span`,{className:`popover-row-state`,children:!e.remote&&P(iE,{m:n,busy:w!==null,onDownload:()=>void W(n.id)})})]}),b?.model===n.id&&b.provider.id===e.id&&V(`div`,{ref:R,className:`popover-message`,role:`alert`,children:[b.provider.privacy_notice,` `,V(`button`,{type:`button`,className:`link-btn`,onClick:()=>G(b.model,b.provider),children:[`Use `,ds(b.model)]})]})]},n.id)})]},e.id))}),g>0&&V(`button`,{type:`button`,className:`popover-item`,onClick:()=>{p(!1),u(`model`)},children:[P(`span`,{className:`popover-item-check`}),P(`span`,{className:`popover-item-body`,children:V(`span`,{className:`popover-item-note`,children:[g,` `,g===1?`model isn’t`:`models aren’t`,` available on this PC — see why in Settings`]})})]}),P(`div`,{className:`popover-divider`}),V(`button`,{type:`button`,className:`popover-item`,onClick:()=>{p(!1),u(`model`)},children:[P(`span`,{className:`popover-item-check`,children:P(Qi,{size:13,"aria-hidden":`true`})}),V(`span`,{className:`popover-item-body`,children:[P(`span`,{className:`popover-item-title`,children:`Add a model from a link…`}),P(`span`,{className:`popover-item-note`,children:`Any GGUF chat model on Hugging Face`})]})]}),V(`button`,{type:`button`,className:`popover-item`,onClick:()=>{p(!1),u(`model`)},children:[P(`span`,{className:`popover-item-check`}),P(`span`,{className:`popover-item-body`,children:P(`span`,{className:`popover-item-title`,children:`Providers and keys…`})})]})]})]})}function oE(e,t,n){if(e==null||!t(e))throw Error(`the server sent no ${n}`);return e}var sE=e=>e.startsWith(`.`);function cE({onPick:e,onClose:t}){let n=T(),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1);Io(!0,t);let p=(0,X.useRef)(null);sS(p,!0);let m=(0,X.useCallback)(e=>{u(!0),c(null),Promise.resolve().then(()=>Ot(e)).then(e=>{let t=oE(e,e=>Array.isArray(e.entries),`folder listing`);i(t),o(t.current_path)}).catch(e=>c(e instanceof yn?e.detail||e.message:String(e))).finally(()=>u(!1))},[]);(0,X.useEffect)(()=>m(),[m]);let h=r?.entries.filter(e=>e.type===`folder`)??[],g=d?h:h.filter(e=>!sE(e.name));return P(`div`,{className:`modal-overlay`,onClick:t,children:V(`div`,{ref:p,className:`modal-panel sp-picker`,role:`dialog`,"aria-modal":`true`,"aria-label":n(`pick.label`),onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`modal-header`,children:[P(`h3`,{children:n(`pick.title`)}),P(`button`,{type:`button`,className:`btn-icon`,onClick:t,"aria-label":n(`sp.closeShort`),children:P(Y,{size:18})})]}),V(`div`,{className:`modal-body sp-picker-body`,children:[P(`p`,{className:`sp-meta`,children:n(`pick.note`)}),V(`form`,{className:`sp-picker-path`,onSubmit:e=>{e.preventDefault(),a.trim()&&m(a.trim())},children:[P(`input`,{value:a,onChange:e=>o(e.target.value),"aria-label":n(`pick.path`),spellCheck:!1,dir:`ltr`}),P(`button`,{type:`submit`,className:`sp-action`,children:n(`pick.go`)})]}),r&&V(`div`,{className:`sp-picker-quick`,children:[r.quick_links.map(e=>P(`button`,{type:`button`,className:`sp-action`,onClick:()=>m(e.path),children:e.name},e.path)),V(`label`,{className:`sp-picker-hidden`,children:[P(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),n(`pick.showHidden`)]})]}),V(`ul`,{className:`sp-picker-list`,"aria-busy":l,children:[r?.parent_path&&P(`li`,{children:V(`button`,{type:`button`,onClick:()=>m(r.parent_path??void 0),children:[P(Xn,{size:13,"aria-hidden":`true`}),` `,n(`pick.up`)]})}),g.map(e=>P(`li`,{children:V(`button`,{type:`button`,onClick:()=>m(e.path),children:[P(Ei,{size:13,"aria-hidden":`true`}),` `,e.name]})},e.path)),r&&g.length===0&&P(`li`,{className:`sp-meta`,children:n(h.length>0?`pick.onlyHidden`:`pick.none`)}),l&&V(`li`,{className:`sp-meta`,children:[P(q,{size:12,className:`spin`,"aria-hidden":`true`}),` `,n(`pick.loading`)]})]}),s&&P(`p`,{className:`sp-error`,role:`alert`,children:s})]}),V(`div`,{className:`sp-picker-actions`,children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:t,children:n(`sp.cancel`)}),P(`button`,{type:`button`,className:`btn-primary`,disabled:!r,onClick:()=>r&&e(r.current_path),children:n(`pick.use`)})]})]})})}function lE(e){let[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(null);return{open:t=>{i(null);let r=window.gaiaAPI?.dialog;r?r.pickFolder(t).then(t=>{t&&e(t)}).catch(e=>i(`Couldn't open the folder picker: ${e instanceof Error?e.message:String(e)}`)):n(!0)},picker:t?P(cE,{onPick:t=>{n(!1),e(t)},onClose:()=>n(!1)}):null,error:r}}var uE=new Map;function dE(e){let t=uE.get(e);return t||(t={env:null,error:null,inFlight:null,version:0,listeners:new Set},uE.set(e,t)),t}function fE(e,t,n){let r=dE(e);r.env=t??r.env,r.error=n,r.listeners.forEach(e=>e())}function pE(e){let t=dE(e);if(t.inFlight)return t.inFlight;let n=t.version;return t.inFlight=Promise.resolve().then(()=>Ne(e)).then(r=>{let i=oE(r,e=>Array.isArray(e.folders),`chat's environment`);t.version===n&&fE(e,i,null)}).catch(t=>fE(e,null,t instanceof Error?t.message:String(t))).finally(()=>{t.inFlight=null}),t.inFlight}function mE(e){let[,t]=(0,X.useState)(0);(0,X.useEffect)(()=>{let n=dE(e),r=()=>t(e=>e+1);return n.listeners.add(r),!n.env&&!n.inFlight&&pE(e),()=>{n.listeners.delete(r)}},[e]);let n=(0,X.useCallback)(()=>pE(e),[e]),r=(0,X.useCallback)(async t=>{let n=await t();return dE(e).version+=1,fE(e,n,null),n},[e]),i=dE(e);return{env:i.env,error:i.error,refresh:n,change:r}}var hE=e=>e.split(/[\\/]/).filter(Boolean).pop()??e;function gE({folder:e,disabled:t}){let n=k(e=>e.draftFolder),r=k(e=>e.setDraftFolder),{open:i,picker:a,error:o}=lE(r),s=e.gaia_folder?`GAIA works in its own folder, ${e.path}.`:`GAIA works in ${e.path}.`;return e.choosable?V(D.Fragment,{children:[V(`button`,{type:`button`,className:`new-chat-folder is-button${n?` is-on`:``}`,onClick:()=>i(e.path),disabled:t,"aria-haspopup":`dialog`,"aria-label":n?`Folder for this chat: ${e.name}, plus ${hE(n)}`:`Folder for this chat: ${e.name}`,title:n?`This chat can read and write ${n}. Click to pick another folder.`:`${s} Click to give this chat another folder.`,children:[P(Ei,{size:13,"aria-hidden":`true`}),P(`span`,{className:`new-chat-folder-name`,dir:`auto`,children:n?`${e.name} + ${hE(n)}`:e.name}),P(gr,{size:12,"aria-hidden":`true`})]}),n&&P(`button`,{type:`button`,className:`btn-icon-sm new-chat-folder-clear`,onClick:()=>r(null),disabled:t,"aria-label":`Don't give this chat ${hE(n)}`,title:`Don't add this folder`,children:P(Y,{size:12})}),o&&P(`span`,{className:`new-chat-folder-error`,role:`alert`,children:o}),a]}):V(`span`,{className:`new-chat-folder`,title:e.gaia_folder?`${s} Attach a file or start GAIA from a project folder to work there.`:s,children:[P(Ei,{size:13,"aria-hidden":`true`}),P(`span`,{className:`new-chat-folder-name`,dir:`auto`,children:e.name})]})}function _E({sessionId:e,onOpen:t}){let{env:n}=mE(e),r=n?.folders.find(e=>e.source===`working_folder`);if(!r)return null;let i=hE(r.path);return V(`button`,{type:`button`,className:`composer-chip folder-chip`,title:`GAIA works in ${r.path}`,"aria-label":`Working folder ${i}, show the chat's folders`,onClick:t,children:[P(Ei,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:i})]})}var vE=`gaia:permission-mode`;function yE(e,t){window.dispatchEvent(new CustomEvent(vE,{detail:{sessionId:e,mode:t}}))}function bE(e,t){let n=(0,X.useRef)(t);n.current=t,(0,X.useEffect)(()=>{if(!e)return;let t=t=>{let r=t.detail;r?.sessionId===e&&n.current(r.mode)};return window.addEventListener(vE,t),()=>window.removeEventListener(vE,t)},[e])}var xE=[{mode:`ask`,label:`perm.ask`,note:`perm.askNote`},{mode:`full_access`,label:`perm.full`,note:`perm.fullNote`}];function SE({sessionId:e,disabled:t}){let n=T(),r=k(e=>e.draftPermissionMode),i=k(e=>e.setDraftPermissionMode),[a,o]=(0,X.useState)(e?`ask`:r),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),p=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(!e){o(r);return}let t=!1;return St(e).then(e=>{t||o(e.mode)}).catch(e=>{t||f(Ix(e))}),()=>{t=!0}},[e,r]),bE(e,o);let m=(0,X.useCallback)(async t=>{if(t===`full_access`&&!l)u(!0);else{f(null);try{if(e){let n=(await Pt(e,t)).mode;o(n),yE(e,n)}else i(t),o(t);c(!1)}catch(t){f(Ix(t)),e&&St(e).then(e=>o(e.mode)).catch(e=>f(t=>`${t??``} Couldn't re-read the saved mode: ${Ix(e)}`.trim()))}finally{u(!1)}}},[l,e,i]),h=a===`full_access`,_=h?Ga:qa;return V(`div`,{className:`composer-chip-wrap`,children:[V(`button`,{ref:p,type:`button`,className:`composer-chip${h?` is-warning`:``}`,onClick:()=>{u(!1),c(e=>!e)},disabled:t,"aria-haspopup":`dialog`,"aria-expanded":s,"aria-label":n(`perm.chipAria`,{mode:g(h?`perm.fullLower`:`perm.askLower`)}),children:[P(_,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:n(h?`perm.full`:`env.ask`)}),P(gr,{size:12,"aria-hidden":`true`})]}),V(Ro,{open:s,onClose:()=>c(!1),anchor:p,label:n(`env.permission`),children:[xE.map(e=>V(`button`,{type:`button`,className:`popover-item`,onClick:()=>m(e.mode),"aria-pressed":a===e.mode,children:[P(`span`,{className:`popover-item-check`,"aria-hidden":`true`,children:a===e.mode&&P(mr,{size:13})}),V(`span`,{className:`popover-item-body`,children:[P(`span`,{className:`popover-item-title`,children:n(e.label)}),P(`span`,{className:`popover-item-note`,children:n(e.note)})]})]},e.mode)),l&&V(`div`,{className:`popover-message`,role:`alert`,children:[n(`env.fullAccessWarn`),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:()=>m(`full_access`),children:n(`env.turnOn`)})]}),d&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:d})]})]})}var CE={sending:`Adding to the running reply…`,delivered:`Added to the running reply. GAIA reads it at its next step.`,queued:`Queued. Sends when this reply ends.`};function wE(e,t){return e?CE.queued:t?`GAIA is still busy in this chat. Trying again in a few seconds.`:`Sending next.`}function TE({items:e,onRemove:t,onSteer:n,onRetry:r,replying:i=!0,busyRetry:a=!1}){let o=e.filter(e=>e.state!==`starting`);return o.length===0?null:P(`ul`,{className:`queued-messages`,"aria-label":`Messages waiting to send`,"aria-live":`polite`,children:o.map(e=>V(`li`,{className:`queued-message is-${e.state}`,children:[e.state===`failed`?P(wr,{size:12,"aria-hidden":`true`}):e.state===`queued`?P(Pr,{size:12,"aria-hidden":`true`}):P(Hr,{size:12,"aria-hidden":`true`}),P(`span`,{className:`queued-message-text`,title:e.text,children:e.text}),P(`span`,{className:`queued-message-state`,title:e.error,children:e.state===`failed`?`Not sent. ${e.error??``}`.trim():e.state===`queued`?i&&e.note||wE(i,a):CE[e.state]}),e.state===`failed`&&V(`button`,{type:`button`,className:`queued-message-steer`,onClick:()=>r(e.id),"aria-label":`Send again: ${e.text}`,children:[P(za,{size:11,"aria-hidden":`true`}),` Send again`]}),e.state===`queued`&&n&&P(`button`,{type:`button`,className:`queued-message-steer`,onClick:()=>n(e.id),title:`GAIA reads it at its next step, without starting over. It may not answer it separately.`,children:`Add to this reply`}),(e.state===`queued`||e.state===`failed`)&&P(`button`,{type:`button`,className:`queued-message-remove`,onClick:()=>t(e.id),"aria-label":`Remove queued message: ${e.text}`,title:`Remove`,children:P(Y,{size:12})})]},e.id))})}var EE=e=>e.toLocaleString(`en-US`);function DE({n:e}){let t=T();if(e==null)return P(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)});let n=e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(+(e<1e4))}K`:`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`;return P(`span`,{title:t(`ctx.tokens`,{n:EE(e)}),dir:`ltr`,children:n})}function OE({s:e}){let t=T();if(e==null)return P(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)});let n=e<.1?e===0?`0 s`:`<0.1 s`:e<10?`${e.toFixed(1)} s`:`${Math.round(e)} s`;return P(`span`,{title:`${(e*1e3).toFixed(0)} ms`,dir:`ltr`,children:n})}function kE({r:e}){let t=T();return e==null?P(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)}):P(`span`,{title:t(`ctx.rateTitle`,{n:e}),children:t(`ctx.rate`,{n:Math.round(e).toLocaleString(`en-US`)})})}var AE=(e,t)=>t>0?Math.round(e/t*100):0,jE=(e,t)=>{let n=AE(e,t);return n===0&&e>0?`<1`:String(n)},ME=(e,t)=>t&&e!=null?Math.floor(e/t*100):null,NE=256;function PE(e,t=z){if(e.provider===`unknown`)return t(`ctx.unknown`);if(e.provider===`cloud`)return t(`ctx.cloud`);if(e.provider!==`local`)return t(`ctx.cloudVia`,{provider:bs(e.provider)});if(!e.device)return e.loaded===!1?t(`ctx.notLoadedNow`):t(`ctx.unknown`);let n=e.device.toUpperCase(),r=e.backend===`npu`?`FLM`:e.backend;return r&&r!==e.device?`${n} · ${r.charAt(0).toUpperCase()}${r.slice(1)}`:n}function FE({label:e,children:t,hint:n}){return V(`div`,{className:`cp-row`,title:n,children:[P(`dt`,{children:e}),P(`dd`,{children:t})]})}function IE({t:e}){let t=T();if(e.model_seconds==null||e.gaia_seconds==null)return V(FE,{label:t(`ctx.took`),children:[P(OE,{s:e.wall_seconds}),` · `,t.bare(`ctx.split`),` `,P(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)})]});let n=[{key:`model`,label:t(`ctx.inModel`),s:e.model_seconds},{key:`tools`,label:t(`ctx.runningTools`),s:e.tool_seconds},{key:`waiting`,label:t(`ctx.waitingOnYou`),s:e.waiting_seconds},{key:`gaia`,label:t(`ctx.gaiaItself`),s:e.own_seconds??0}];return V(D.Fragment,{children:[P(FE,{label:t(`ctx.took`),hint:t(`ctx.tookHint`),children:P(OE,{s:e.wall_seconds})}),P(`div`,{className:`cp-stack`,"aria-hidden":`true`,children:n.map(t=>P(`span`,{className:`cp-time-${t.key}`,style:{width:`${AE(t.s,e.wall_seconds)}%`}},t.key))}),V(`dl`,{className:`cp-rows cp-indent`,children:[P(FE,{label:t(`ctx.inModel`),children:P(OE,{s:e.model_seconds})}),P(FE,{label:t(`ctx.inGaia`),hint:t(`ctx.inGaiaHint`),children:P(OE,{s:e.gaia_seconds})}),n.slice(1).filter(e=>e.s>0).map(e=>V(FE,{label:`· ${e.label}`,children:[P(`span`,{className:`swatch cp-time-${e.key}`,"aria-hidden":`true`}),` `,P(OE,{s:e.s})]},e.key))]})]})}function LE({why:e}){let t=T();return P(`span`,{className:`cp-unknown`,title:e,children:t(`ctx.unknown`)})}var RE={server:`ctx.src.server`,client:`ctx.src.client`};function zE(e,t){return e?t(RE[e]):void 0}function BE({turn:e}){let t=T(),n=ME(e.tokens_cached,e.tokens_in),r=e.unknown??{},i=e.tools.map(e=>`${e.name??t(`ctx.toolOutside`)}: ${e.seconds??`?`} s`).join(`
63
63
  `);return V(D.Fragment,{children:[P(IE,{t:e.time}),V(`dl`,{className:`cp-rows`,children:[P(FE,{label:t(`ctx.firstWord`),hint:zE(e.first_token_source,t),children:e.first_token_seconds==null?P(LE,{why:r.first_token_seconds}):V(D.Fragment,{children:[t.bare(`ctx.in`),` `,P(OE,{s:e.first_token_seconds})]})}),P(FE,{label:t(`ctx.readingPrompt`),hint:t(`ctx.readingHint`),children:e.tokens_new!=null&&e.tokens_new<NE?P(`span`,{title:t(`ctx.tooFewTitle`),children:t(`ctx.onlyNew`,{n:e.tokens_new})}):e.prefill_tokens_per_second==null?P(LE,{why:r.prefill_tokens_per_second}):V(D.Fragment,{children:[P(kE,{r:e.prefill_tokens_per_second}),e.prefill_source===`client`&&P(`span`,{className:`cp-chip`,title:t(`ctx.approxTitle`),children:t(`ctx.approx`)})]})}),P(FE,{label:t(`ctx.writing`),hint:zE(e.generation_source,t)??t(`ctx.writingHint`),children:e.generation_tokens_per_second==null?P(LE,{why:r.generation_tokens_per_second}):P(kE,{r:e.generation_tokens_per_second})}),P(FE,{label:t(`ctx.tokensInOut`),hint:r.tokens,children:V(`span`,{dir:`ltr`,children:[P(DE,{n:e.tokens_in}),` → `,P(DE,{n:e.tokens_out})]})}),P(FE,{label:t(`ctx.cache`),hint:t(`ctx.cacheHint`),children:e.tokens_cached==null?P(LE,{why:r.tokens_cached}):V(D.Fragment,{children:[P(DE,{n:e.tokens_cached}),n!=null&&` (${n}%)`]})}),P(FE,{label:t(`ctx.modelCalls`),children:e.model_calls}),P(FE,{label:t(`ctx.toolCalls`),hint:i||void 0,children:e.tool_calls===0&&!e.tool_seconds_total?t(`ctx.none`):V(D.Fragment,{children:[e.tool_calls,` · `,P(OE,{s:e.tool_seconds_total??0})]})}),P(FE,{label:t(`ctx.loads`),children:e.loads.length===0?t(`ctx.none`):V(`span`,{title:e.loads.map(e=>`${e.model}${e.replaced?.length?` replaced ${e.replaced.join(`, `)}`:``}: ${e.seconds} s`).join(`
@@ -78,6 +78,6 @@ Error generating stack: `+e.message+`
78
78
  `);return(0,X.useEffect)(()=>{let e=r.current;e&&i.current&&(e.scrollTop=e.scrollHeight)},[a]),P(`pre`,{ref:r,id:n,className:t,dir:`ltr`,tabIndex:0,onScroll:e=>{let t=e.currentTarget;i.current=t.scrollHeight-t.scrollTop-t.clientHeight<8},children:a})}var gM=1e9,_M={downloading:0,verifying:1,failed:2,ready:3,unchecked:3,cancelled:4,queued:5,skipped:6};function vM(e){return e.roles.includes(`embedding`)?0:e.roles.includes(`chat`)?1:2}function yM(e){return[...e].filter(e=>e.state!==`skipped`).sort((e,t)=>_M[e.state]-_M[t.state]||vM(e)-vM(t))}var bM=/^\s*(Downloading:|Downloaded\b|\[[=\-\s>#]*\])/;function xM(e){return e.some(e=>e.trim()&&!bM.test(e))}var SM={queued:`setup.state.queued`,downloading:`setup.state.downloading`,verifying:`setup.state.verifying`,ready:`setup.state.ready`,failed:`setup.state.failed`,skipped:`setup.state.skipped`,cancelled:`setup.state.cancelled`,unchecked:`setup.state.unchecked`};function CM(e){return e?e.state===`running`||e.state===`verifying`||!!e.models?.some(e=>e.state===`downloading`||e.state===`queued`||e.state===`verifying`):!1}function wM(e,t,n,r){switch(e.error_kind){case`network`:return r(`setup.fail.network`,{name:t});case`disk_full`:{let i=Math.max(0,e.bytes_total-e.bytes_done)/1e9,a=n==null?i:Math.max(.1,i-n);return r(`setup.fail.diskFull`,{name:t,done:PS(e.bytes_done),need:$(a)})}case`verify`:return r(`setup.fail.verify`,{name:t});case`memory`:return r(`setup.fail.testMemory`,{name:t});case`stuck`:return r(`setup.fail.testStuck`,{name:t});case`answer`:return r(`setup.fail.testAnswer`,{name:t});case`window`:return r(`setup.fail.testWindow`,{name:t});case`path_too_long`:return r(`setup.fail.pathTooLong`,{name:t});default:return r(`setup.fail.lemonade`,{name:t})}}function TM({model:e,name:t,estimate:n,now:r,freeGb:i,onRetry:a,onResume:o,onSkip:s,onRestart:c,busy:l,retryLater:u,checking:d,checkingFor:f}){let p=T(),m=(0,X.useId)(),h=(0,X.useId)(),[g,_]=(0,X.useState)(!1),v=e.log??[],y=e.bytes_total>0?Math.min(100,e.bytes_done/e.bytes_total*100):e.state===`ready`?100:0,b=p(SM[e.state]),x=e.retrying_until?Math.max(0,Math.round(e.retrying_until-r/1e3)):0,S=e.state===`downloading`&&!x?n?.stalledFor??0:0,C=e.state===`verifying`&&d||e.state===`downloading`&&!x&&S<15,w;if(e.state===`downloading`){let t=IS(p.locale,e.bytes_total>0?`${PS(e.bytes_done)} / ${PS(e.bytes_total)}`:PS(e.bytes_done));if(x>0)w=p(`setup.progress.retrying`,{n:String(x)});else if(S>=60)w=p(`setup.progress.stuck`);else if(S>=15)w=p(`setup.progress.stalled`,{n:`15`});else if(n?.speed&&n.eta!=null){let{speed:e,eta:r}=n;w=p.compose(n=>`${t} · ${IS(p.locale,FS(e))} · ${LS(r,n)}`)}else w=p.compose(e=>`${t} · ${e(`setup.progress.estimating`)}`)}else w=e.state===`verifying`?d?f>=10?p(`setup.progress.checkingFor`,{n:String(f)}):p(`setup.progress.checkingLoad`):p(`setup.progress.waitingCheck`):e.state===`ready`?e.bytes_total?PS(e.bytes_total):``:e.state===`unchecked`?p(`setup.progress.unchecked`):e.state===`cancelled`?e.bytes_done>0?p(`setup.progress.keptPartial`,{done:PS(e.bytes_done)}):``:e.state===`queued`&&e.bytes_total?PS(e.bytes_total):``;let E=e.state===`downloading`?p.compose(t=>[t(`setup.progress.percent`,{n:String(Math.floor(y))}),e.bytes_total?t(`setup.progress.of`,{done:PS(e.bytes_done),total:PS(e.bytes_total)}):null,n?.eta==null?null:RS(n.eta,t)].filter(Boolean).join(`, `)):b;return V(`li`,{className:`dl-row is-${e.state}${C?` is-live`:``}${S>=15?` is-stalled`:``}`,children:[V(`div`,{className:`dl-row-head`,children:[P(`span`,{className:`dl-icon`,"aria-hidden":`true`,children:e.state===`ready`||e.state===`unchecked`?P(mr,{size:14}):e.state===`failed`?P(wr,{size:14}):e.state===`cancelled`?P(Ca,{size:13}):P(`span`,{className:`dl-dot`})}),P(`span`,{className:`dl-name`,children:P(`bdi`,{title:e.id,children:t})}),P(`span`,{className:`dl-state`,children:b}),e.state===`downloading`&&V(`bdi`,{className:`dl-pct`,children:[Math.floor(y),`%`]}),e.state!==`failed`&&xM(v)&&P(`button`,{type:`button`,className:`dl-log-toggle`,onClick:()=>_(e=>!e),"aria-expanded":g,"aria-controls":h,"aria-label":p(`setup.progress.logFor`,{name:t}),title:p(`setup.progress.logFor`,{name:t}),children:P(br,{size:14,className:g?`is-open`:``,"aria-hidden":`true`})})]}),P(`div`,{className:`dl-track`,role:`progressbar`,"aria-label":p(`setup.progress.rowLabel`,{name:t,state:b}),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":C&&e.state===`verifying`?void 0:Math.floor(y),"aria-valuetext":E,children:P(`span`,{className:`dl-fill`,style:{inlineSize:`${e.state===`verifying`?100:y}%`}})}),w&&P(`p`,{className:`dl-detail`,children:P(`bdi`,{children:w})}),g&&e.state!==`failed`&&xM(v)&&P(hM,{lines:v,id:h,className:`dl-log`}),e.state===`failed`&&V(`div`,{className:`dl-fail`,children:[P(`p`,{className:`dl-error`,id:m,children:wM(e,t,i,p)}),(v.length>0||e.error)&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:p(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:v.length>0?v.join(`
79
79
  `):e.error})]}),u?P(`p`,{className:`dl-detail`,children:p(`setup.progress.retryLater`)}):V(`div`,{className:`setup-row`,children:[a&&V(`button`,{type:`button`,className:`btn-primary`,disabled:l,onClick:()=>a(e.id,e.error_kind),"aria-describedby":m,children:[P(za,{size:13,"aria-hidden":`true`}),` `,p(`setup.progress.retry`)]}),s&&P(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:()=>s(e.id),children:p(`setup.progress.skipModel`)})]})]}),e.state===`cancelled`&&o&&P(`div`,{className:`setup-row`,children:P(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:()=>o(e.id),children:p(`setup.progress.resume`)})}),S>=60&&c&&P(`div`,{className:`setup-row`,children:V(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:c,children:[P(za,{size:13,"aria-hidden":`true`}),` `,p(`setup.progress.retry`)]})})]})}function EM({status:e,names:t,freeGb:n=null,onCancel:r,onRetry:i,onResume:a,onResumeAll:o,onSkip:s,onRestart:c,busy:l=!1,retryLater:u=!1,labelledBy:d}){let f=T(),p=JA(),m=(0,X.useMemo)(()=>yM(e.models??[]),[e.models]),h=(0,X.useRef)(new Map),g=(0,X.useRef)(new Map),_=(0,X.useRef)(new BS),v=(0,X.useRef)(!1),[y,b]=(0,X.useState)(()=>Date.now()),[x,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(null),E=i&&((e,t)=>{let n=m.find(t=>t.id===e);t===`verify`&&n?w(n):i(e,t)}),[D,O]=(0,X.useState)(``),[k,A]=(0,X.useState)(``),j=(0,X.useRef)(null),M=e.state===`verifying`||e.state!==`running`&&m.some(e=>e.state===`verifying`),N=(0,X.useRef)(new Map);(0,X.useEffect)(()=>{if(!p||!(m.some(e=>e.retrying_until)||M))return;let e=setInterval(()=>b(Date.now()),1e3);return()=>clearInterval(e)},[m,p,M]);let F=e.overall,{estimates:I,overallEstimate:L}=(0,X.useMemo)(()=>{let e=Date.now(),t={};for(let n of m){if(n.state!==`downloading`){h.current.delete(n.id);continue}let r=h.current.get(n.id),i=n.downloaded_before_gb??null;(!r||g.current.get(n.id)!==i)&&(r=new BS,h.current.set(n.id,r),g.current.set(n.id,i)),t[n.id]=r.update(n.bytes_done,n.bytes_total,e)}let n=m.some(e=>e.state===`downloading`);n&&!v.current&&(_.current=new BS),v.current=n;let r=m.filter(e=>e.state===`downloading`||e.state===`queued`).reduce((e,t)=>e+Math.max(0,t.bytes_total-t.bytes_done),0);return{estimates:t,overallEstimate:n&&F?_.current.update(F.bytes_done,F.bytes_done+r,e):void 0}},[m,F]);(0,X.useEffect)(()=>{let e=new Map(m.map(e=>[e.id,e.state])),n=Math.floor((F?.percent??0)/25),r=j.current;if(j.current={states:e,quarter:n},!r)return;let i=[];for(let e of m){if(r.states.get(e.id)===e.state)continue;let n=t[e.id]??e.id;e.state===`failed`?A(f(`setup.progress.announceFailed`,{name:n})):i.push(f(`setup.progress.announceState`,{name:n,state:f(SM[e.state])}))}n>r.quarter&&n>0&&n<4&&i.push(f(`setup.progress.announceOverall`,{n:String(n*25)})),i.length&&O(i.join(`. `))},[m,F?.percent,t,f]);let ee=e=>{if(!M)return N.current.delete(e),0;let t=Date.now(),n=N.current.get(e)??t;return N.current.set(e,n),Math.floor((t-n)/1e3)},R=CM(e),z=m.filter(e=>e.state===`cancelled`),B=F?.failed??m.filter(e=>e.state===`failed`).length,te=F?.percent??0,ne=()=>{(F?.bytes_done??0)>gM?S(!0):r?.()},re=f.compose(e=>[e(`setup.progress.overallPct`,{n:String(te)}),F&&F.bytes_total>0?e(`setup.progress.of`,{done:PS(F.bytes_done),total:PS(F.bytes_total)}):null,R&&L?.speed?IS(f.locale,FS(L.speed)):null,R?L?.eta==null?e(`setup.progress.estimating`):e(`setup.progress.left`,{eta:LS(L.eta,e)}):null,B>0?e(`setup.progress.failedCount`,{n:String(B)}):null].filter(Boolean).join(` · `));return V(`section`,{className:`dl${p?``:` is-paused`}`,"aria-labelledby":d,children:[V(`div`,{className:`dl-overall`,children:[P(`p`,{className:`dl-overall-line`,children:P(`bdi`,{children:re})}),P(`div`,{className:`dl-track is-overall${m.some(e=>e.state===`downloading`)?` is-live`:``}`,role:`progressbar`,"aria-label":f(`setup.progress.overallLabel`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":te,"aria-valuetext":f(`setup.progress.percent`,{n:String(te)}),children:P(`span`,{className:`dl-fill`,style:{inlineSize:`${te}%`}})})]}),P(`ul`,{className:`dl-list`,children:m.map(e=>P(TM,{model:e,name:t[e.id]??e.id,estimate:I[e.id],now:y,freeGb:n,onRetry:E,onResume:R?void 0:a,onSkip:s,onRestart:c,busy:l,retryLater:u,checking:M,checkingFor:ee(e.id)},e.id))}),R&&P(`p`,{className:`setup-hint dl-controls`,children:f(`setup.progress.keepsGoing`)}),(R&&r||!R&&z.length>0&&o)&&V(Gj,{children:[R&&r&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:ne,disabled:l,children:f(`setup.progress.cancel`)}),!R&&z.length>0&&o&&P(`button`,{type:`button`,className:`btn-primary`,onClick:o,disabled:l,children:f(`setup.progress.resumeAll`)})]}),P(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:D}),P(`span`,{className:`visually-hidden`,role:`alert`,children:k}),x&&P(Kj,{title:f(`setup.progress.cancelTitle`),confirmLabel:f(`setup.progress.cancelConfirm`),cancelLabel:f(`setup.progress.cancelKeep`),onConfirm:()=>{S(!1),r?.()},onCancel:()=>S(!1),children:P(`p`,{children:f(`setup.progress.cancelBody`)})}),C&&P(Kj,{title:f(`setup.redownload.title`,{name:t[C.id]??C.id}),confirmLabel:f(`setup.redownload.confirm`),cancelLabel:f(`setup.redownload.keep`),onConfirm:()=>{let e=C;w(null),i?.(e.id,`verify`)},onCancel:()=>w(null),children:P(`p`,{children:f(`setup.redownload.body`,{name:t[C.id]??C.id,size:PS(C.bytes_total)})})})]})}var DM=[`check`,`download`,`test`],OM={root:`setup-report`,button:`btn-secondary setup-report-button`,hint:`setup-hint`,error:`setup-error`};function kM({run:e,before:t={}}){let n=T(),[r,i]=(0,X.useState)(()=>new Set),a=e=>i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),o=n=>[...t[n]??[],...e?.logs?.[n]??[]],s=DM.filter(e=>o(e).length>0);return V(`section`,{className:`setup-logs`,"aria-label":n(`setup.logs.title`),children:[s.map(e=>{let t=o(e),i=r.has(e);return V(`div`,{className:`setup-log`,children:[V(`button`,{type:`button`,className:`setup-log-toggle`,onClick:()=>a(e),"aria-expanded":i,children:[P(br,{size:13,className:i?`is-open`:``,"aria-hidden":`true`}),` `,n(`setup.logs.${e}`)]}),i&&P(hM,{lines:t,className:`setup-log-pre`})]},e)}),P(rC,{classes:OM,note:n(`setup.logs.reportNote`)})]})}function AM(){let e=T(),t=k(e=>e.locale),n=k(e=>e.setLocale);return V(`label`,{className:`setup-language`,children:[P(Ki,{size:14,"aria-hidden":`true`}),P(`span`,{className:`visually-hidden`,children:e(`settings.language`)}),P(`select`,{value:t,onChange:e=>n(e.target.value),children:b.map(({meta:e})=>P(`option`,{value:e.code,lang:e.code,dir:e.dir,children:M(e)},e.code))})]})}var jM={driver:[`setup.npu.problem.driver`,`setup.npu.fix.driver`],device:[`setup.npu.problem.device`,`setup.npu.fix.device`],firmware:[`setup.npu.problem.firmware`,`setup.npu.fix.firmware`],access:[`setup.npu.problem.access`,`setup.npu.fix.access`],memlock:[`setup.npu.problem.memlock`,`setup.npu.fix.memlock`],runtime:[`setup.npu.problem.runtime`,`setup.npu.fix.runtime`]},MM={cancelled:`setup.npu.fixError.cancelled`,timeout:`setup.npu.fixError.timeout`,not_authorized:`setup.npu.fixError.notAuthorized`,no_pkexec:`setup.npu.fixError.noPkexec`};function NM({problem:e}){let t=T(),n=jM[e.code];if(!n)return V(`li`,{children:[P(`strong`,{children:e.title}),` `,e.fix]});let r=e.params,i=n[1];e.code===`access`&&r.group&&(i=`setup.npu.fix.accessGroup`);let a=n[0];return e.code===`memlock`&&r.fix===`restart`&&(a=`setup.npu.problem.memlockStill`,i=`setup.npu.fix.memlockRestart`),e.code===`memlock`&&r.fix===`stuck`&&(a=`setup.npu.problem.memlockStuck`,i=`setup.npu.fix.memlockStuck`),V(`li`,{children:[P(`strong`,{children:t(a,{device:r.device??``,limit:r.limit??``,version:r.version??``,detail:r.detail??``})}),` `,t(i,{group:r.group??``})]})}function PM({problems:e,disabled:t,onRecheck:n,id:r=`setup-npu-problems`}){let i=T(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),l=e.some(e=>e.code===`memlock`&&e.params.fix===`apply`),u=async(e,t)=>{o(!0),c(null);try{await e(),n?.()}catch(e){let n=e instanceof yn?e.body?.code:void 0,r=n&&n in MM?MM[n]:t;c(i(r))}finally{o(!1)}};return V(`div`,{className:`setup-npu-problems`,id:r,role:`note`,children:[P(`p`,{children:i(`setup.npu.notReady`)}),P(`ul`,{children:e.map(e=>P(NM,{problem:e},e.code))}),P(`p`,{className:`setup-hint`,children:i(`setup.npu.meanwhile`)}),s&&P(`p`,{className:`setup-npu-error`,role:`alert`,children:s}),V(`div`,{className:`setup-npu-actions`,children:[l&&P(`button`,{type:`button`,className:`btn-primary`,disabled:t||a,onClick:()=>void u(Ze,`setup.npu.fixError.failed`),children:i(`setup.npu.fixMemlock`)}),n&&P(`button`,{type:`button`,className:`btn-secondary`,disabled:t||a,onClick:()=>void u(xe,`setup.npu.recheckFailed`),children:i(`setup.npu.recheck`)})]})]})}async function FM(){let e=await be();e.reachable&&(e.available_backends??[]).some(e=>e.name===`vulkan`)&&(e.preferred_backend??e.default_backend)!==`vulkan`&&await Fe(`vulkan`)}function IM({plan:e,selection:t,onSelection:n,disabled:r=!1,onRecheck:i}){let a=T(),o=ZA(e),s=e.npu?.present&&!e.npu.ready?e.npu.problems:[],c=s.length?void 0:o.find(e=>ej(e)&&e.gaia_model&&e.chat_choice&&e.fits!==!1)??o.find(e=>ej(e)&&e.chat_choice&&e.downloaded&&!tj(e)),l=!s.length&&!c&&o.some(e=>ej(e)&&e.fit_code===`npu`),u=!!o.find(e=>e.id===t.defaultChat&&ej(e)),d=gj(e).defaultChat,f=d&&!o.find(e=>e.id===d&&ej(e))?d:o.find(e=>e.chat_choice&&e.gaia_model&&e.support===`verified`&&!ej(e))?.id,p=e=>{e===`npu`&&c&&!u&&n(oj(t,o,c.id)),e===`gpu`&&u&&f&&n(oj(t,o,f))},m=[{id:`gpu`,label:a(`setup.backend.gpu`)},...c?[{id:`npu`,label:a(`setup.backend.npu`)}]:[],...s.length?[{id:`npu`,label:a(`setup.backend.npu`),unavailable:!0}]:[]],h=u?`npu`:`gpu`;return V(`section`,{className:`setup-backend`,"aria-labelledby":`setup-backend-title`,children:[P(`h3`,{className:`mc-job-title`,id:`setup-backend-title`,children:a(`setup.backend.title`)}),P(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`setup-backend-title`,children:m.map(e=>P(`button`,{type:`button`,role:`radio`,"aria-checked":h===e.id,"aria-describedby":e.unavailable?`setup-npu-problems`:void 0,className:h===e.id?`is-active`:``,disabled:r||e.unavailable,onClick:()=>p(e.id),children:P(`bdi`,{children:e.label})},e.id))}),s.length>0?P(PM,{problems:s,disabled:r,onRecheck:i}):P(`p`,{className:`setup-hint`,children:a(c?`setup.backend.hint`:l?`setup.backend.hintNpuUnusable`:`setup.backend.hintNoNpu`)})]})}var LM=({children:e})=>P(`bdi`,{dir:`ltr`,children:e});function RM({label:e,children:t}){return V(`div`,{className:`found-row`,children:[P(`dt`,{children:e}),P(`dd`,{children:t})]})}function zM(e){return e.family?`${e.name} (${e.family})`:e.name}var BM=[[`llamacpp`,`llama.cpp`],[`flm`,`FastFlowLM`],[`whispercpp`,`whisper.cpp`],[`kokoro`,`Kokoro`],[`sd-cpp`,`stable-diffusion.cpp`]],VM=new Set([`llamacpp`,`flm`]);function HM(e){let t=[];for(let[n,r]of BM){let i=(e.backends??[]).find(e=>e.recipe===n&&e.default);i&&i.state!==`unsupported`&&t.push({name:r,b:i})}return t}function UM(e,t){return e?e.kind===`release_candidate`&&e.rc?`${e.version.replace(/rc\d+$/,``)} RC ${e.rc}`:e.kind===`source`&&e.commit?`${e.version} (${e.commit})`:e.version:t??null}var WM={release:`release`,release_candidate:`release candidate`,local:`local build`,source:`from source`};function GM(e,t){let n=e.system,r=e=>(n?.devices??[]).filter(t=>t.available&&e(t.kind)),i=r(e=>e.endsWith(`gpu`)),a=r(e=>e.endsWith(`npu`)),o=HM(e);return{sys:n,cpu:r(e=>e===`cpu`)[0],gpus:i,npus:a,runsOn:i[0]?.name??t?.gpu_name??null,npu:a[0]??null,runtimes:o,gaia:UM(n?.gaia_build,n?.gaia_version),build:n?.gaia_build?.kind??null,software:[UM(n?.gaia_build,n?.gaia_version)?`GAIA ${UM(n?.gaia_build,n?.gaia_version)}`:null,n?.lemonade_version?`Lemonade ${n.lemonade_version}`:null,...o.filter(({b:e})=>VM.has(e.recipe)&&qM(e)).map(({name:e,b:t})=>`${e} ${t.version??t.backend}`)].filter(e=>!!e),totalMemory:MS(n?.physical_memory,t?.ram_gb),freeGb:e.disk?.free_gb??t?.disk_free_gb??null,modelsPath:e.disk?.path??null,gaiaHome:n?.gaia_home??null}}var KM={installed:`installed`,update_required:`installed, updates on first use`},qM=e=>e.state===`installed`||e.state===`update_required`,JM={chat:`setup.job.chat`,vision:`setup.job.vision`,embedding:`setup.job.documents`,speech:`setup.job.speech`,voice:`setup.job.voice`,image_creation:`setup.job.images`};function YM(e,t){let n=GM(e,t),r=e.lemonade.mode===`external`?`the user's own`:`GAIA's own`;return[`GAIA: ${n.gaia??`unknown`}${n.build?`, ${WM[n.build]}`:``} (agent ${n.sys?.agent_version??`not installed yet`})`,`Model server: ${r} Lemonade ${n.sys?.lemonade_version??`(version not reported)`}${e.lemonade.url?` at ${e.lemonade.url}`:``}`,...n.runtimes.map(({name:e,b:t})=>`${e}: ${t.backend}${t.version?` ${t.version}`:``} (${KM[t.state??``]??`not installed`})`),`OS: ${n.sys?.os??t?.os??`unknown`}`,`Processor: ${n.cpu?.name??n.sys?.processor??`unknown`}${n.cpu?.cores?` (${n.cpu.cores} cores, ${n.cpu.threads??n.cpu.cores} threads)`:``}`,`Graphics: ${n.gpus.map(zM).join(`; `)||t?.gpu_name||`none found`}`,`NPU: ${n.npus.map(zM).join(`; `)||`none found`}`,`Memory: ${n.totalMemory??`unknown`}${e.capacity_gb==null?``:`, ${$(e.capacity_gb)} for models${e.memory_source?` (${e.memory_source})`:``}`}`,`Models folder: ${n.modelsPath??`unknown`}${n.freeGb==null?``:` (${$(n.freeGb)} free)`}`,`GAIA data and logs: ${n.gaiaHome??`unknown`}`].join(`
80
80
  `)}function XM({plan:e,hardware:t,onChangeMemory:n}){let r=T(),i=GM(e,t),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),d=async e=>{u(null);try{await Dn(e,!1)}catch(e){u(r(`setup.found.openFailed`,{error:e instanceof Error?e.message:String(e)}))}},f=P(`span`,{className:`found-muted`,children:r(`setup.found.unknown`)}),p=[...t?.blockers??[],...(t?.warnings??[]).filter(e=>t?.lemonade_running||!/\bNPU\b/.test(e))],m=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{m.current&&clearTimeout(m.current)},[]);let h=e=>{c(e),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>c(null),2e3)};return V(`section`,{className:`setup-card found`,"aria-label":r(`setup.found.title`),children:[V(`div`,{className:`found-head`,children:[P(`h3`,{className:`mc-job-title`,children:r(`setup.found.title`)}),P(`button`,{type:`button`,className:`found-copy`,onClick:()=>{navigator.clipboard.writeText(YM(e,t)).then(()=>h(`done`),e=>{console.warn(`[DetectedSummary] could not copy the details`,e),h(`failed`)})},"aria-label":r(`setup.found.copy`),title:r(`setup.found.copy`),children:P(s===`done`?mr:Br,{size:14,"aria-hidden":`true`})}),s&&P(`span`,{className:`found-copied`,role:`status`,children:r(s===`done`?`setup.found.copied`:`setup.found.copyFailed`)})]}),V(`dl`,{className:`found-glance`,children:[V(RM,{label:r(`setup.found.runsOn`),children:[i.runsOn?P(LM,{children:i.runsOn}):f,i.npu&&P(`span`,{className:`found-chip`,children:P(LM,{children:`NPU`})})]}),V(RM,{label:r(`setup.found.memory`),children:[e.capacity_gb!=null&&i.totalMemory?r(`setup.found.memoryOf`,{size:$(e.capacity_gb),total:i.totalMemory}):e.capacity_gb==null?i.totalMemory?P(LM,{children:i.totalMemory}):f:P(LM,{children:$(e.capacity_gb)}),n&&P(`button`,{type:`button`,className:`link-btn found-link`,onClick:n,children:r(`setup.found.changeMemory`)})]}),P(RM,{label:r(`setup.found.space`),children:i.freeGb==null?f:P(LM,{children:$(i.freeGb)})}),V(RM,{label:r(`setup.found.software`),children:[i.software.length?P(LM,{children:i.software.join(` · `)}):f,i.build&&i.build!==`release`&&P(`span`,{className:`found-chip`,children:r(`setup.found.build.${i.build}`)})]})]}),V(`div`,{className:`found-paths`,children:[[[`setup.found.modelsFolder`,i.modelsPath],[`setup.found.gaiaFolder`,i.gaiaHome]].map(([e,t])=>t&&V(`button`,{type:`button`,className:`link-btn found-open`,onClick:()=>void d(t),title:t,children:[P(bi,{size:13,"aria-hidden":`true`}),` `,r(e)]},e)),l&&P(`p`,{className:`setup-error`,role:`alert`,children:l})]}),p.length>0&&V(`details`,{className:`dl-details found-warnings`,children:[V(`summary`,{children:[P(wr,{size:13,"aria-hidden":`true`}),` `,r(`setup.found.noticed`)]}),P(`ul`,{children:p.map(e=>P(`li`,{children:P(LM,{children:e})},e))})]}),V(`button`,{type:`button`,className:`setup-log-toggle found-more`,onClick:()=>o(e=>!e),"aria-expanded":a,children:[P(br,{size:13,className:a?`is-open`:``,"aria-hidden":`true`}),` `,r(`setup.found.details`)]}),a&&V(`div`,{className:`found-details`,children:[P(`h4`,{className:`found-group`,children:r(`setup.found.software`)}),V(`dl`,{className:`found-list`,children:[V(RM,{label:P(LM,{children:`GAIA`}),children:[i.gaia?P(LM,{children:i.gaia}):f,i.build&&i.build!==`release`&&P(`span`,{className:`found-chip`,children:r(`setup.found.build.${i.build}`)})]}),P(RM,{label:r(`setup.found.agent`),children:i.sys?.agent_version?P(LM,{children:i.sys.agent_version}):P(`span`,{className:`found-muted`,children:r(`setup.found.agentLater`)})}),V(RM,{label:r(`setup.found.server`),children:[e.lemonade.mode===`external`?r(`setup.found.serverYours`):r(`setup.found.serverOwn`),i.sys?.lemonade_version&&V(D.Fragment,{children:[` `,P(LM,{children:i.sys.lemonade_version})]}),e.lemonade.url&&P(`span`,{className:`found-sub`,children:P(LM,{children:e.lemonade.url})})]})]}),P(`h4`,{className:`found-group`,children:r(`setup.found.runtime`)}),i.runtimes.length?P(`div`,{className:`found-table-wrap`,children:V(`table`,{className:`found-table`,children:[P(`thead`,{className:`visually-hidden`,children:V(`tr`,{children:[P(`th`,{scope:`col`,children:r(`setup.found.col.runtime`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.device`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.version`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.state`)})]})}),P(`tbody`,{children:i.runtimes.map(({name:e,b:t})=>V(`tr`,{children:[P(`th`,{scope:`row`,children:P(LM,{children:e})}),P(`td`,{children:P(LM,{children:t.backend})}),P(`td`,{children:P(LM,{children:t.version??``})}),P(`td`,{className:qM(t)?`is-installed`:void 0,children:r(qM(t)?`setup.pc.backend.installed`:`setup.pc.backend.available`)})]},t.recipe))})]})}):P(`p`,{className:`found-muted`,children:r(`setup.found.unknown`)}),P(`h4`,{className:`found-group`,children:r(`setup.found.models`)}),(e.catalog??[]).length?P(`div`,{className:`found-table-wrap`,children:V(`table`,{className:`found-table`,children:[P(`thead`,{className:`visually-hidden`,children:V(`tr`,{children:[P(`th`,{scope:`col`,children:r(`setup.found.col.model`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.job`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.tested`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.size`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.state`)})]})}),P(`tbody`,{children:(e.catalog??[]).map(e=>V(`tr`,{children:[P(`th`,{scope:`row`,title:e.id,children:P(`bdi`,{children:e.name})}),P(`td`,{children:e.roles.map(e=>r(JM[e])).join(` · `)}),V(`td`,{children:[e.support===`verified`&&P(`span`,{className:`mc-chip is-verified`,children:r(`setup.label.verified`)}),e.support===`untested`&&P(`span`,{className:`mc-chip is-untested`,children:r(`setup.label.untested`)})]}),P(`td`,{children:P(LM,{children:e.full_size_gb??e.size_gb?$(e.full_size_gb??e.size_gb):``})}),P(`td`,{className:e.downloaded?`is-installed`:void 0,children:r(e.downloaded?`setup.models.status.onPc`:`setup.found.notDownloaded`)})]},e.id))})]})}):P(`p`,{className:`found-muted`,children:r(`setup.found.unknown`)}),P(`h4`,{className:`found-group`,children:r(`setup.found.hardware`)}),V(`dl`,{className:`found-list`,children:[P(RM,{label:r(`setup.found.os`),children:i.sys?.os??t?.os?P(LM,{children:i.sys?.os??t?.os}):f}),V(RM,{label:r(`setup.found.cpu`),children:[i.cpu||i.sys?.processor?P(LM,{children:i.cpu?.name??i.sys?.processor}):f,i.cpu?.cores?P(`span`,{className:`found-sub`,children:r(`setup.found.cores`,{cores:String(i.cpu.cores),threads:String(i.cpu.threads??i.cpu.cores)})}):null]}),P(RM,{label:r(`setup.found.gpu`),children:i.gpus.length?P(LM,{children:i.gpus.map(zM).join(`; `)}):P(`span`,{className:`found-muted`,children:r(`setup.found.none`)})}),P(RM,{label:r(`setup.found.npu`),children:i.npus.length?P(LM,{children:i.npus.map(zM).join(`; `)}):P(`span`,{className:`found-muted`,children:r(`setup.found.none`)})})]})]})]})}function ZM({state:e}){return e===`done`?P(mr,{size:13,"aria-hidden":`true`}):e===`active`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):P(e===`failed`?Y:e===`question`?Ar:Mr,{size:13,"aria-hidden":`true`})}function QM({hardware:e,hardwareError:t,plan:n,serverRun:r,awaitingChoice:i=!1}){let a=T(),[o,s]=(0,X.useState)(!1),c=!!n?.lemonade.reachable,l=r?.state===`failed`||r?.state===`cancelled`,u=a(n?.lemonade.mode===`external`?`setup.found.serverYours`:`setup.found.serverOwn`),d=n?.system?.lemonade_version?a(`setup.checks.serverFound`,{version:n.system.lemonade_version,whose:u}):u,f=e?`done`:t?`failed`:`active`,p=[e?.gpu_name,e?.npu_detected?a(`setup.checks.npu`):null].filter(Boolean).join(` · `),m=t?null:n?.capacity_gb==null?c?MS(n?.system?.physical_memory,e?.ram_gb):null:$(n.capacity_gb),h=t?`failed`:m?`done`:l?`failed`:i?`waiting`:`active`,g=[{id:`device`,label:a(`setup.checks.device`),value:t?`${a(`setup.system.unread`)} ${t}`:p||null,state:f},{id:`memory`,label:a(`setup.found.memory`),value:m,state:h},{id:`disk`,label:a(`setup.checks.disk`),value:e?.disk_free_gb==null?null:a(`setup.checks.diskValue`,{size:IS(a.locale,`${Math.round(e.disk_free_gb)} GB`)}),state:f},{id:`server`,label:a(`setup.checks.server`),value:c?d:i?a(`setup.checks.serverChoose`):null,state:c?`done`:l?`failed`:i?`question`:e?`active`:`waiting`},{id:`models`,label:a(`setup.checks.backends`),value:c&&n?.catalog?a(`setup.checks.backendsValue`,{models:String(n.catalog.length),downloaded:String(n.catalog.filter(e=>e.downloaded).length)}):null,state:c&&n?.catalog?`done`:c?`active`:`waiting`}],_=g.filter(e=>e.state===`done`).length,v=Math.round(_/g.length*100),y=P(`ul`,{className:`setup-rows`,id:`setup-check-rows`,children:g.map(e=>V(`li`,{className:`setup-result is-${e.state}`,children:[P(ZM,{state:e.state}),P(`span`,{className:`setup-result-label`,children:e.label}),e.value&&P(`bdi`,{className:`setup-result-value`,children:e.value})]},e.id))});return _===g.length?V(`section`,{className:`setup-card setup-checks-done`,"aria-label":a(`setup.check.title`),children:[P(`p`,{className:`setup-result is-done`,role:`status`,children:V(`button`,{type:`button`,className:`setup-checks-toggle`,"aria-expanded":o,"aria-controls":`setup-check-rows`,onClick:()=>s(e=>!e),children:[P(mr,{size:13,"aria-hidden":`true`}),P(`span`,{className:`setup-result-label`,children:a(`setup.checks.allPassed`,{n:String(g.length)})}),P(br,{size:13,className:o?`is-open`:``,"aria-hidden":`true`})]})}),o&&y]}):V(`section`,{className:`setup-card`,"aria-label":a(`setup.check.title`),children:[V(`div`,{className:`setup-bar-head`,children:[P(`span`,{children:a(`setup.checks.count`,{done:String(_),total:String(g.length)})}),V(`bdi`,{dir:`ltr`,children:[v,`%`]})]}),P(`progress`,{className:`setup-progress`,max:100,value:v,"aria-label":a(`setup.check.title`)}),y]})}function $M({steps:e}){let t=T();return V(`nav`,{className:`setup-rail`,"aria-label":t(`setup.rail.label`),children:[P(`p`,{className:`setup-rail-title`,children:t(`setup.title`)}),P(`ol`,{className:`setup-rail-list`,children:e.map((e,t)=>{let n=e.status===`done`?P(mr,{size:13,"aria-hidden":`true`}):e.status===`active`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):e.status===`failed`?P(wr,{size:13,"aria-hidden":`true`}):t+1,r=V(D.Fragment,{children:[P(`span`,{className:`setup-rail-num`,children:n}),P(`span`,{children:e.label})]}),i=`setup-rail-step is-${e.status}${e.shown?` is-shown`:``}`,a=e.shown?`step`:void 0;return P(`li`,{children:e.onOpen?P(`button`,{type:`button`,className:i,onClick:e.onOpen,children:r}):P(`span`,{className:i,"aria-current":a,children:r})},e.id)})})]})}var eN={memory:`setup.test.why.memory`,broken:`setup.test.why.broken`,stuck:`setup.test.why.stuck`,missing:`setup.test.why.missing`,agent:`setup.test.why.agent`,answer:`setup.test.why.answer`,window:`setup.test.why.window`};function tN(e,t){return t(`setup.test.job.${e}`)}function nN({state:e}){return e===`passed`?P(mr,{size:13,"aria-hidden":`true`}):e===`running`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):P(e===`failed`?Y:e===`skipped`?da:Mr,{size:13,"aria-hidden":`true`})}function rN(e,t){return e.state===`running`?t(`setup.test.running`):e.state===`failed`?t(`setup.test.failed`):e.state===`skipped`?t(`setup.test.skipped`):e.seconds==null?t(`setup.test.passed`):t(`setup.test.passedIn`,{seconds:String(Math.round(e.seconds))})}function iN({run:e,expected:t,names:n,catalog:r,onRetry:i,onChooseAnother:a,onCancel:o,onDownloadAgain:s,busy:c}){let l=T(),u=e.tests??[],d=new Set(u.map(e=>e.job)),f=t.filter(e=>!d.has(e)),p=u.filter(e=>e.state!==`running`).length,m=Math.max(u.length+f.length,1),h=Math.round(p/m*100),g=u.filter(e=>e.state===`failed`).filter(e=>!r.find(t=>t.id===e.subject)?.roles.some(e=>[`speech`,`voice`,`image_creation`].includes(e))),_=e.state===`failed`||e.state===`cancelled`,v=s?[...new Set(g.filter(e=>e.kind===`broken`&&e.subject).map(e=>e.subject))]:[],[y,b]=(0,X.useState)(null),x=r.find(e=>e.id===y)?.full_size_gb,S=_&&e.components?.agent===`failed`,C=g.some(e=>e.subject&&e.kind!==`missing`);return V(D.Fragment,{children:[V(`section`,{className:`setup-card`,"aria-label":l(`setup.test.title`),children:[V(`div`,{className:`setup-bar-head`,children:[P(`span`,{children:l(`setup.test.count`,{done:String(p),total:String(m)})}),V(`bdi`,{dir:`ltr`,children:[h,`%`]})]}),P(`progress`,{className:`setup-progress`,max:100,value:h,"aria-label":l(`setup.test.title`)}),V(`ul`,{className:`setup-rows`,children:[u.map(e=>V(`li`,{className:`setup-result is-${e.state}`,children:[P(nN,{state:e.state}),V(`span`,{className:`setup-result-label`,children:[tN(e.job,l),e.subject&&V(`bdi`,{className:`setup-result-model`,children:[` `,n[e.subject]??e.subject]})]}),P(`span`,{className:`setup-result-value`,children:rN(e,l)}),e.error&&V(`div`,{className:`setup-result-error`,children:[P(`p`,{children:l(e.kind===`broken`&&!s?`setup.test.why.brokenYours`:eN[e.kind??``]??`setup.test.why.other`)}),V(`details`,{className:`dl-details`,children:[P(`summary`,{children:l(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:e.error})]})]})]},`${e.job}:${e.subject??``}`)),f.map(e=>e===`agent`&&S?V(`li`,{className:`setup-result is-failed`,children:[P(nN,{state:`failed`}),P(`span`,{className:`setup-result-label`,children:tN(e,l)}),P(`span`,{className:`setup-result-value`,children:l(`setup.test.failed`)}),P(`div`,{className:`setup-result-error`,children:P(`p`,{children:l(`setup.test.why.hub`)})})]},e):V(`li`,{className:`setup-result is-waiting`,children:[P(nN,{state:`waiting`}),P(`span`,{className:`setup-result-label`,children:tN(e,l)}),P(`span`,{className:`setup-result-value`,children:l(`setup.test.waiting`)})]},e))]})]}),e.state===`verifying`&&o&&P(Gj,{children:P(`button`,{type:`button`,className:`btn-secondary`,onClick:o,disabled:c,children:l(`setup.progress.cancel`)})}),_&&V(`div`,{className:`setup-failure`,role:`alert`,children:[P(`p`,{children:e.state===`cancelled`?l(`setup.test.cancelled`):g.some(e=>e.kind===`memory`)?l(`setup.test.failedMemory`):l(`setup.test.failedHelp`)}),V(Gj,{children:[C&&a&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:a,disabled:c,children:l(`setup.test.chooseAnother`)}),P(`button`,{type:`button`,className:v.length?`btn-secondary`:`btn-primary`,onClick:i,disabled:c,children:l(`setup.test.tryAgain`)}),v.map(e=>P(`button`,{type:`button`,className:`btn-primary setup-wrap-btn`,onClick:()=>b(e),disabled:c,children:v.length===1?l(`setup.test.downloadItAgain`):l(`setup.test.downloadAgain`,{name:n[e]??e})},e))]})]}),y&&P(Kj,{title:l(`setup.redownload.title`,{name:n[y]??y}),confirmLabel:l(`setup.redownload.confirm`),cancelLabel:l(`setup.redownload.keep`),onConfirm:()=>{let e=y;b(null),s?.(e)},onCancel:()=>b(null),children:P(`p`,{children:l(`setup.redownload.body`,{name:n[y]??y,size:x==null?``:$(x)})})})]})}var aN=`https://app.fireworks.ai/settings/users/api-keys`,oN=`https://amd-gaia.ai/docs/guides/llm-gateway`,sN=[{id:`local`,title:`setup.where.local`,note:`setup.where.localNote`},{id:`fireworks`,title:`Fireworks AI`,note:`setup.where.fireworksNote`},{id:`amd`,title:`AMD LLM Gateway`,note:`setup.where.amdNote`}];function cN(e,t){return N(e.title)?t(e.title):e.title}var lN=1e3,uN=`gaia-setup-choice`;function dN(){try{let e=localStorage.getItem(uN);return e===`local`||e===`fireworks`||e===`amd`?e:null}catch(e){return console.warn(`[SetupScreen] could not read the saved provider choice`,e),null}}function fN(e){try{localStorage.setItem(uN,e)}catch(e){console.warn(`[SetupScreen] could not save the provider choice; a reload will ask again`,e)}}var pN=[`ok`,`needs_key`,`too_old`];function mN({onChosen:e,onNothingToOffer:t,onFound:n,canInstallOwn:r=!0}){let i=T(),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)([]),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!1),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),E=(0,X.useRef)(!0),O=(0,X.useCallback)(async()=>{c(null);try{let e=await ce();if(!e.offer){t?.();return}f(!0);let{found:r,unchecked:i=[]}=await tt();if(!E.current)return;u(r?[]:i),r&&pN.includes(r.status)?(o({target:e,found:r}),n?.(r),g(r.status===`needs_key`),r.status===`too_old`&&t?.()):i.length===0&&t?.()}catch(e){E.current&&c(e instanceof Error?e.message:String(e))}finally{E.current&&f(!1)}},[t,n]);(0,X.useEffect)(()=>(E.current=!0,O(),()=>{E.current=!1}),[O]);let k=(0,X.useCallback)(async t=>{if(a){b(t),S(null);try{await Ee(t===`external`?{mode:t,base_url:a.found.url,api_key:p.trim()||void 0}:{mode:t}),m(``),w(t),e(t)}catch(e){UA(e)&&g(!0),S(e instanceof Error?e.message:String(e))}finally{b(null)}}},[a,p,e]);if(s||l.length>0)return V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:s?i(`setup.offer.checkFailed`):i(`setup.offer.noAnswer`,{url:l.join(`, `)})}),s&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:i(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:s})]}),V(Gj,{children:[V(`button`,{type:`button`,className:`btn-secondary`,disabled:d,onClick:()=>void O(),children:[d&&P(q,{size:13,className:`spin`}),` `,i(`setup.offer.checkAgain`)]}),t&&r&&P(`button`,{type:`button`,className:`btn-primary`,disabled:d,onClick:t,children:i(`setup.offer.useOwn`)})]})]});if(!a)return d?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,i(`setup.offer.looking`)]}):null;let{target:A,found:j}=a;return C?P(`p`,{className:`setup-hint`,role:`status`,children:C===`external`?i(`setup.offer.usingYours`,{url:j.url}):i(`setup.offer.usingOwn`)}):j.status===`too_old`?V(`p`,{className:`setup-hint`,role:`status`,children:[i(`setup.offer.tooOld`),` `,V(`bdi`,{dir:`ltr`,className:`setup-choice-note`,children:[`Lemonade `,j.version??``,` · `,j.url]})]}):V(`form`,{id:`setup-lemonade-form`,className:`setup-lemonade`,"aria-label":i(`setup.offer.label`),onSubmit:e=>{e.preventDefault(),k(`external`)},children:[P(`span`,{className:`setup-choice-title`,children:i(`setup.offer.title`)}),P(`span`,{className:`setup-choice-note`,children:V(`bdi`,{dir:`ltr`,children:[`Lemonade`,j.version?` ${j.version}`:``,` · `,j.url]})}),V(`button`,{type:`button`,className:`setup-log-toggle setup-offer-more`,onClick:()=>v(e=>!e),"aria-expanded":_,"aria-controls":`setup-offer-detail`,children:[P(br,{size:13,className:_?`is-open`:``,"aria-hidden":`true`}),` `,i(`setup.offer.whatGaiaDoes`)]}),_&&P(`p`,{className:`setup-choice-note`,id:`setup-offer-detail`,children:i(`setup.offer.whatGaiaDoesText`)}),h&&P(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,value:p,onChange:e=>m(e.target.value),placeholder:i(`setup.offer.keyPlaceholder`),"aria-label":i(`setup.offer.keyLabel`)}),x&&(h?P(`p`,{className:`setup-error`,role:`alert`,children:i(`setup.offer.keyRejected`)}):P(gN,{text:x})),V(Gj,{children:[V(`button`,{type:`submit`,form:`setup-lemonade-form`,className:`btn-secondary`,disabled:!!y||h&&!p.trim(),children:[y===`external`&&P(q,{size:13,className:`spin`}),` `,i(`setup.offer.useMine`)]}),V(`button`,{type:`button`,className:`btn-primary`,disabled:!!y,onClick:()=>void k(`gaia`),children:[y===`gaia`&&P(q,{size:13,className:`spin`}),` `,i(`setup.offer.useOwn`)]})]})]})}function hN({problem:e,onRetry:t,onUseGaia:n}){let r=T(),i=e.kind===`server_too_old`&&e.use_gaia;return V(D.Fragment,{children:[e.start&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:r(`setup.server.howToStart`)}),P(`pre`,{dir:`ltr`,children:e.start})]}),V(Gj,{children:[P(`button`,{type:`button`,className:i?`btn-secondary`:`btn-primary`,onClick:t,children:r(`setup.tryAgain`)}),e.use_gaia&&P(`button`,{type:`button`,className:i?`btn-primary`:`btn-secondary`,onClick:n,children:r(`setup.server.useGaia`)})]}),e.use_gaia&&P(`p`,{className:`setup-hint`,children:r(`setup.server.useGaiaNote`)}),e.use_gaia&&e.env_url&&P(`p`,{className:`setup-hint`,children:r(`setup.server.envIgnoredNote`,{url:e.env_url})})]})}function gN({text:e}){let t=T();return V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:t(`setup.failedLead`)}),V(`details`,{className:`dl-details`,children:[P(`summary`,{children:t(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:e})]})]})}function _N({run:e}){let t=T();return e.problem?V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:t(e.problem.kind===`server_too_old`?`setup.server.tooOld`:`setup.server.unreachable`)}),V(`details`,{className:`dl-details`,children:[P(`summary`,{children:t(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:e.problem.message})]})]}):V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:t(e.components?.server===`failed`?`setup.server.ownFailed`:`setup.stopped`)}),e.error&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:t(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:e.error})]})]})}var vN=[`check`,`plan`,`key`,`models`,`gpu`,`download`,`test`,`ready`];function yN(e){return e instanceof Error?e.message:String(e)}function bN({onReady:e,onClose:t}){let n=T(),r=cs(e=>e.refresh),i=cs(e=>e.select),[a,o]=(0,X.useState)(`local`),[s,c]=(0,X.useState)(`check`),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(`models`),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(()=>new Set([`check`])),y=(0,X.useRef)(`check`),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),[O,k]=(0,X.useState)(null),[A,j]=(0,X.useState)(null),[M,N]=(0,X.useState)(``),[F,I]=(0,X.useState)({busy:!1,error:null,done:!1}),[L,ee]=(0,X.useState)(null),[R,z]=(0,X.useState)(null),[B,te]=(0,X.useState)(null),[ne,re]=(0,X.useState)(null),[ie,ae]=(0,X.useState)(null),[oe,H]=(0,X.useState)(null),[U,se]=(0,X.useState)(!1),[W,le]=(0,X.useState)(null),[ue,de]=(0,X.useState)(!1),[fe,pe]=(0,X.useState)(!1),[me,he]=(0,X.useState)(null),[ge,_e]=(0,X.useState)(!1),[ve,ye]=(0,X.useState)(null),[be,xe]=(0,X.useState)([]),[Se,we]=(0,X.useState)([]),[Ee,De]=(0,X.useState)([]),[Oe,ke]=(0,X.useState)(!1),[Ae,je]=(0,X.useState)(!1),Me=(0,X.useRef)({gaiaLemonade:!1,options:{}}),Ne=(0,X.useRef)(null),Pe=(0,X.useRef)(!1),Fe=(0,X.useRef)(!1),[Ie,Re]=(0,X.useState)(!1),[ze,Ve]=(0,X.useState)(!1),He=(0,X.useCallback)(()=>Ve(!0),[]),[Ue,We]=(0,X.useState)(null),[Ge,Ke]=(0,X.useState)(null),qe=(0,X.useRef)(!0);(0,X.useEffect)(()=>(qe.current=!0,()=>{qe.current=!1}),[]);let{network:Je,providers:Ye,recheck:Xe}=lM(),Ze=e=>Ye.find(t=>t.id===e),Qe=Ze(a),$e=Qe?.key_source===`environment`&&Qe.key_hint?Qe:void 0,et=e=>!!Ze(e)?.blocked,tt=e=>et(e)||e===`amd`&&Je?.reachable===!1,nt=e=>et(e)?n(`settings.privacy.localOnlyBlocked`):n(`setup.key.gatewayOff`),rt=a!==`local`,at=w?.server_only?w:null,K=w&&!w.server_only?w:null,st=w?.state===`running`||w?.state===`verifying`,ct=K?.state===`ready`,ut=CM(w),dt=!(K?.models??[]).some(e=>e.state===`downloading`||e.state===`queued`)&&((K?.tests?.length??0)>0||K?.state===`verifying`),pt=(0,X.useCallback)(()=>{C(null),ot().then(x).catch(e=>C(yN(e)))},[]),mt=(0,X.useRef)(0),gt=(0,X.useCallback)(async()=>{let e=++mt.current;z(null);try{let t=await Ce();return e===mt.current?(ee(t),t):null}catch(t){return e===mt.current&&z(yN(t)),null}},[]),vt=(0,X.useCallback)(async()=>{try{let e=await Nn();qe.current&&H(e??null)}catch(e){console.warn(`[SetupScreen] GPU memory could not be read; the step stays hidden`,e)}},[]),yt=t!=null;(0,X.useEffect)(()=>{ce().then(e=>ke(e.source===`config`)).catch(e=>console.warn(`[SetupScreen] could not read which Lemonade GAIA uses`,e)),pt(),gt(),it().then(e=>{(e.state!==`idle`||e.models?.length)&&(yt&&e.state!==`running`&&e.state!==`verifying`||(E(e),e.server_only||c(`download`),e.skip_chat_model&&o(dN()===`amd`?`amd`:`fireworks`)))}).catch(e=>j(yN(e))).finally(()=>Re(!0))},[pt,gt,yt]),(0,X.useEffect)(()=>{L?.catalog&&L.lemonade.reachable&&(te(e=>e??fj(L)),vt(),!w&&L.catalog.some(e=>e.partial&&e.selected)&&_e(!0))},[L,vt,w]);let bt=(0,X.useCallback)(()=>{Ne.current&&clearInterval(Ne.current),Ne.current=null},[]),xt=(w?.models??[]).filter(e=>e.state===`failed`&&e.error_kind===`disk_full`).length;(0,X.useEffect)(()=>{xt>0&&gt()},[xt,gt]);let St=(0,X.useCallback)(async()=>{try{let e=await it();if(k(null),e.state===`idle`&&!e.models?.length){E(null),c(`plan`),je(!0),gt();return}E(e)}catch(e){k(yN(e))}},[gt,n]);(0,X.useEffect)(()=>(!ut&&!O||(Ne.current=setInterval(()=>{St()},lN)),bt),[ut,O,St,bt]),(0,X.useEffect)(()=>{at&&at.state===`ready`&&(pt(),gt())},[at,at?.state,pt,gt]),(0,X.useEffect)(()=>{ct&&(pt(),gt().then(e=>{e&&ae(e)}),vt())},[ct,pt,gt,vt]);let Ct=(0,X.useRef)(!1),wt=(0,X.useCallback)(async(e=!1,t={})=>{if(Ct.current)return!1;Ct.current=!0,j(null),he(null),_e(!1),je(!1);try{fN(a),Me.current={gaiaLemonade:e,options:t};let n=await _t(rt,e,t);E(n),g(null);let r=t.extraModels??[];return r.length&&De(e=>e.filter(e=>!r.includes(e))),t.serverOnly||c(`download`),e&&ke(!1),!0}catch(e){let t=ht(e);if(t)return le({kind:`server`,detail:t,then:`run`}),!1;if(e instanceof yn&&e.httpStatus===409){let e=await it().catch(()=>null);if(e&&(e.state===`running`||e.state===`verifying`))return E(e),g(null),e.server_only||c(`download`),!0}return j(yN(e)),!1}finally{Ct.current=!1}},[a,rt]);(0,X.useEffect)(()=>{s===`check`&&Ie&&ze&&L&&!L.lemonade.reachable&&!w&&!Pe.current&&(Pe.current=!0,wt(!1,{serverOnly:!0}))},[s,Ie,ze,L,w,wt]);let Tt=!!(B&&L?.catalog&&L.lemonade.reachable&&(b||S)),Et=(0,X.useCallback)(()=>{let{gaiaLemonade:e,options:t}=Me.current;wt(e,t)},[wt]),Dt=(0,X.useCallback)((e,t=L)=>{re(t);let n=t&&B&&!rt?Sj(t,B):[];return wt(!1,{acknowledgeLowDisk:e,keepTrying:U,extraModels:n})},[L,B,rt,U,wt]),[Ot,kt]=(0,X.useState)(!1),At=(0,X.useRef)(!1),jt=(0,X.useCallback)(async(e,t=ue)=>{if(!L||!B||At.current)return;he(null),kt(e);let r=ZA(L),i=rt?[]:bj(r,B).filter(e=>!e.downloaded||e.id===B.defaultChat),a=i.find(tj);if(a){let e=a.id===B.defaultChat?`setup.models.cantRun.chat`:`setup.models.cantRun.other`;he(n(e,{name:a.name,why:Aj(a,n)}))}else if(!rt&&!t&&i.length>0&&i.every(e=>e.need_gb!=null))le({kind:`no_fit`,models:i});else{pe(!0),At.current=!0;try{let n=L;if(!rt&&B.defaultChat&&B.defaultChat!==n.chat_model.id)try{n=await Le(B.defaultChat,t)}catch(e){let t=ht(e);if(t){le({kind:`server`,detail:t,then:`chat`});return}throw e}if(!rt){await FM();let e=cj(r,B);e!==(n.vision_model??null)&&(n=await Be(e));for(let e of xj(n,B))n=await ft(e.id,e.skipped)}ee(n),await Dt(e,n)}catch(e){he(yN(e))}finally{At.current=!1,pe(!1)}}},[L,B,rt,ue,Dt,n]),Mt=(0,X.useCallback)(e=>{he(null),s===`download`?g(e===y.current?null:e):(g(null),c(e===`test`||e===`ready`?`download`:e))},[s]),Nt=(0,X.useCallback)(()=>{h??o(`local`),Mt(`plan`)},[Mt,h]),Pt=(0,X.useCallback)(()=>{st&&h!=null||(o(`local`),u(!0),Mt(`models`))},[Mt,st,h]),Ft=(0,X.useCallback)(()=>{st&&h!=null||(u(!1),o(dN()===`amd`?`amd`:`fireworks`),Mt(`key`))},[Mt,st,h]),It=!!oe?.applies,Lt=(0,X.useCallback)(()=>{Mt((h??s)===`gpu`?d:`plan`)},[d,Mt,h,s]),zt=(0,X.useCallback)(e=>{f(e),Mt(`gpu`)},[Mt]),Bt=(0,X.useRef)({prev:null,next:null});(0,X.useEffect)(()=>{let e=e=>{if(!e.altKey||W||(e.target instanceof Element?e.target:null)?.closest(`input, textarea, select, [contenteditable="true"]`))return;let t=e.key===`ArrowLeft`?Bt.current.prev:e.key===`ArrowRight`?Bt.current.next:null;t&&(e.preventDefault(),Mt(t))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[Mt,W]);let Vt=(0,X.useCallback)(async()=>{try{await G(),await St()}catch(e){he(yN(e))}},[St]),Ht=(0,X.useCallback)(async(e,t)=>{he(null),pe(!0);try{t===`verify`&&await dn(e),t===`disk_full`&&gt();try{E(await Te(e,{keepTrying:U}))}catch(t){let n=ht(t);if(!n)throw t;le({kind:`server`,detail:n,then:`retry`,id:e})}}catch(e){he(yN(e))}finally{pe(!1)}},[U,gt]),Ut=(0,X.useCallback)(async e=>{he(null),pe(!0);try{L?.catalog?.find(t=>t.id===e)?.planned&&ee(await ft(e,!0)),E(t=>t&&{...t,models:t.models?.map(t=>t.id===e?{...t,state:`skipped`}:t)});let{options:t}=Me.current;Me.current.options={...t,extraModels:t.extraModels?.filter(t=>t!==e)},te(t=>t&&t.ticked.has(e)?mj(t,ZA(L),e,!1):t)}catch(e){he(yN(e))}finally{pe(!1)}},[L]),Wt=(0,X.useCallback)(async()=>{await Vt(),Et()},[Vt,Et]),Gt=(0,X.useCallback)(async()=>{if(!st){I({busy:!0,error:null,done:!1});try{await Rt(a,{api_key:!Oe&&M||void 0},e=>I({busy:!0,error:null,done:!1,waiting:e}),()=>!qe.current);let{models:e}=await Zt(a),t=e.find(e=>e.rank===1)??e[0];if(!t)throw Error(n(`setup.key.noModels`));await i(t.id),ye(t.id),N(``),I({busy:!1,error:null,done:!0}),Dt(!1)}catch(e){I({busy:!1,error:yN(e),done:!1})}}},[a,M,i,Oe,Dt,n,st]),Kt=(0,X.useCallback)(e=>{fN(e),o(e),I({busy:!1,error:null,done:!1})},[]);(0,X.useEffect)(()=>{if(!ct||Se.length===0||Fe.current)return;let e=Se;Fe.current=!0,wt(!1,{keepTrying:U,extraModels:e}).then(t=>{Fe.current=!1,we(t=>t.filter(t=>!e.includes(t))),t||De(t=>[...t,...e.filter(e=>!t.includes(e))])})},[ct,Se,U,wt]);let qt=ct&&Se.length===0,Jt=rt?ve:K?.chat_model??(L&&!L.decided_after_server?L.chat_model.id:null),Yt=(0,X.useCallback)(async t=>{he(null);try{!rt&&Jt&&await i(Jt),await r()}catch(e){he(yN(e));return}e(t)},[Jt,rt,e,r,i]);(0,X.useEffect)(()=>{qt&&lt().then(e=>xe(e.cards)).catch(e=>console.warn(`[SetupScreen] no first tasks to offer`,e))},[qt]);let Xt=(0,X.useMemo)(()=>{let e={};for(let t of L?.catalog??[])e[t.id]=t.name;return e},[L]),Qt=w?.state===`failed`||w?.state===`cancelled`,$t=K&&(K.state===`failed`||K.state===`cancelled`)&&(K.models??[]).length>0&&(K.models??[]).every(e=>e.state===`ready`||e.state===`skipped`||e.state===`verifying`||e.state===`unchecked`)&&!ut,en=!!K&&Qt&&!K.problem&&Object.values(K.components??{}).includes(`failed`),tn=ZA(L),nn=B?_j(tn,B):[],rn=L&&B?yj(L,B):null,an=tn.find(e=>e.id===B?.defaultChat),on=!!b&&!b.compatible&&b.blockers.length>0,sn=qt?`ready`:s===`download`&&dt?`test`:s;y.current=sn;let cn=h??sn;(0,X.useEffect)(()=>{v(e=>e.has(cn)?e:new Set(e).add(cn))},[cn]);let ln=(0,X.useRef)(!0);(0,X.useEffect)(()=>{if(ln.current){ln.current=!1;return}let e=document.querySelector(`.setup-inner`);e&&(e.scrollTop=0),document.getElementById(`setup-title`)?.focus({preventScroll:!0})},[cn]);let un=[{id:`check`,label:n(`setup.check.title`),key:`setup.check.title`},{id:`plan`,label:n(`setup.plan.step`),key:`setup.plan.step`},{id:`download`,label:n(`setup.download.step`),key:`setup.download.step`},{id:`test`,label:n(`setup.test.step`),key:`setup.test.step`},{id:`ready`,label:n(`setup.ready.step`),key:`setup.ready.step`}],fn=e=>e===`models`||e===`key`?`plan`:e===`gpu`?d===`check`?`check`:`plan`:e,pn=rt?`key`:l?`models`:`plan`,mn=un.findIndex(e=>e.id===fn(sn)),hn=e=>e===`download`||e===`test`||e===`ready`,gn=[];if(b){let e=[L?.system?.physical_memory?`${MS(L.system.physical_memory,null)} installed`:null,b.ram_gb==null?null:`${b.ram_gb} GB the OS can use`].filter(Boolean).join(`, `),t=b.disk_free_gb==null?null:`${Math.round(b.disk_free_gb)} GB free on disk`;gn.push(`This PC: ${[b.gpu_name,b.npu_detected?`NPU`:null].filter(Boolean).join(`, `)||`no GPU reported`}`+[e,t].filter(Boolean).map(e=>`; ${e}`).join(``))}else S&&gn.push(`Couldn't read this PC: ${S}`);Ue&&(gn.push(`Found your Lemonade${Ue.version?` ${Ue.version}`:``} at ${Ue.url}`),gn.push(Ge===`external`?`You chose your own Lemonade`:Ge===`gaia`?`You chose GAIA's own Lemonade`:`Waiting for you to choose which Lemonade GAIA uses`)),L&&(!Ue||Ge)?gn.push(L.lemonade.reachable?`Model server answering at ${L.lemonade.url??`its address`}`:`No model server answering yet`):R&&gn.push(`Couldn't read the model list: ${R}`);let _n=(e,t)=>t<=mn||_.has(e)&&!hn(e),vn=un.map((e,t)=>({id:e.id,label:e.label,status:t<mn?`done`:t>mn?`pending`:sn===`ready`?`done`:Qt&&(sn===`download`||sn===`test`||sn===`check`)?`failed`:st&&(sn===`download`||sn===`test`)?`active`:`current`,shown:e.id===fn(cn),onOpen:e.id!==fn(cn)&&_n(e.id,t)?()=>Mt(e.id===`plan`?pn:e.id):void 0})),bn=un.findIndex(e=>e.id===fn(cn)),xn=cn===`gpu`&&d===`check`?.5:vN.indexOf(cn),Sn=(0,X.useRef)(xn),Cn=(0,X.useRef)(`forward`);Sn.current!==xn&&(Cn.current=xn>Sn.current?`forward`:`back`,Sn.current=xn);let wn=cn===`gpu`?d:cn===`models`||cn===`key`?`plan`:bn>0?un[bn-1].id===`plan`?pn:un[bn-1].id:null,Tn=(cn!==`gpu`&&bn>=0&&bn<un.length-1&&_n(un[bn+1].id,bn+1)?un[bn+1].id:null)??(h==null?cn===`check`&&Tt?`plan`:cn===`gpu`?d:null:null);Bt.current={prev:wn,next:Tn};let En=cn===`gpu`||cn===`models`||cn===`key`,Dn=h!=null&&st,On=[`server`];rt||On.push(`chat`),!rt&&B&&ij(tn,B)&&On.push(`vision`),B&&tn.some(e=>$A(e)&&B.ticked.has(e.id))&&On.push(`embedding`);for(let e of tn)B&&nj(e)&&B.ticked.has(e.id)&&!e.downloaded&&On.push(e.roles[0]);On.push(`agent`);let kn=B&&!rt?tn.filter(e=>nj(e)&&!B.ticked.has(e.id)&&!e.downloaded&&(rj(an)||!e.roles.includes(`image_creation`))):[],An=tn.find(e=>e.fit_code===`memory`&&e.chat_choice&&e.support===`verified`);return V(`main`,{className:`setup`,"aria-labelledby":`setup-title`,children:[P($M,{steps:vn}),P(Wj,{value:p,children:V(`div`,{className:`setup-pane`,children:[V(`div`,{className:`setup-inner`,children:[bn>=0&&V(`nav`,{className:`setup-topnav`,"aria-label":n(`setup.nav.label`),children:[P(`button`,{type:`button`,className:`setup-arrow`,onClick:()=>wn&&Mt(wn),disabled:!wn,"aria-label":n(`setup.nav.prev`),children:P(vr,{size:16,"aria-hidden":`true`})}),P(`button`,{type:`button`,className:`setup-arrow`,onClick:()=>Tn&&Mt(Tn),disabled:!Tn,"aria-label":n(`setup.nav.next`),children:P(br,{size:16,"aria-hidden":`true`})}),P(`span`,{children:P(`bdi`,{children:n(`setup.nav.stepOf`,{n:String(bn+1),total:String(un.length)})})}),h!=null&&h!==sn&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>g(null),children:n.compose(e=>e(`setup.nav.toLive`,{step:e(un.find(e=>e.id===sn)?.key??`setup.download.step`)}))}),P(AM,{})]}),ge&&s!==`download`&&V(`div`,{className:`setup-banner`,role:`status`,children:[P(Hi,{size:14,"aria-hidden":`true`}),P(`span`,{children:n(`setup.resume.banner`)})]}),Ae&&s!==`download`&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.interrupted`)}),V(`div`,{className:`setup-stage is-${Cn.current}`,children:[cn===`check`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(Tt?`setup.check.headingDone`:`setup.check.heading`)}),P(`p`,{className:`setup-lede`,children:n(Tt?`setup.check.ledeDone`:`setup.check.lede`)}),P(QM,{hardware:b,hardwareError:S,plan:L,serverRun:at,awaitingChoice:!!Ue&&!ze}),Tt&&L&&P(XM,{plan:L,hardware:b,onChangeMemory:It&&h==null?()=>zt(`check`):void 0}),Tt&&h==null&&!(Ue&&!ze)&&P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>Mt(`plan`),children:n(`setup.continue`)})}),at&&Qt&&V(D.Fragment,{children:[P(_N,{run:at}),at.problem?P(hN,{problem:at.problem,onRetry:()=>void wt(!1,{serverOnly:!0}),onUseGaia:()=>void wt(!0,{serverOnly:!0})}):P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void wt(!!at.gaia_lemonade,{serverOnly:!0}),children:n(`setup.tryAgain`)})})]}),R&&!L&&V(D.Fragment,{children:[P(gN,{text:R}),V(Gj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void wt(!1,{keepTrying:U}),children:n(`setup.models.useRecommended`)}),P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void gt(),children:n(`setup.tryAgain`)})]}),P(`p`,{className:`setup-hint`,children:n(`setup.models.useRecommendedNote`)})]}),A&&P(gN,{text:A}),A&&!at&&L&&!L.lemonade.reachable&&P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void wt(!1,{serverOnly:!0}),children:n(`setup.tryAgain`)})}),Ie&&L&&(!L.lemonade.reachable&&!at||Tt&&h==null&&L.lemonade.mode!==`external`)&&P(mN,{onNothingToOffer:He,canInstallOwn:!L.lemonade.reachable&&!at,onFound:We,onChosen:e=>{ke(e===`external`),Ke(e),Ve(!0),pt(),gt()}})]}),cn===`plan`&&L&&B&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.plan.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.plan.lede`)}),V(`section`,{className:`setup-hero`,"aria-label":n(`setup.plan.label`),children:[P(`p`,{className:`setup-eyebrow`,children:B.chatChosen?n(`setup.plan.yours`):n(`setup.plan.recommended`)}),P(`p`,{className:`setup-hero-title`,children:P(`bdi`,{children:n(`setup.plan.run`,{name:an?.name??``})})}),V(`dl`,{className:`setup-facts`,children:[V(`div`,{children:[P(`dt`,{children:n(`setup.summary.download`)}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:$(vj(L,B).downloadGb??0)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.plan.runsOn`)}),P(`dd`,{children:P(`bdi`,{children:an&&ej(an)?n(`setup.checks.npu`):b?.gpu_name??n(`setup.plan.cpu`)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.plan.diskAfter`)}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:vj(L,B).afterGb==null?`—`:$(Math.max(0,vj(L,B).afterGb))})})]})]}),V(`ul`,{className:`setup-reasons`,children:[!B.chatChosen&&P(`li`,{children:n(`setup.plan.why.evaluated`)}),an?.need_gb!=null&&an.capacity_gb!=null&&an.fits&&P(`li`,{children:n(`setup.plan.why.fits`,{need:NS(an.need_gb),have:NS(an.capacity_gb)})}),P(`li`,{children:n(`setup.plan.why.private`)}),an&&ej(an)&&P(`li`,{children:n(`setup.plan.why.noImagesNpu`)}),An&&An.id!==an?.id&&An.need_gb!=null&&An.capacity_gb!=null&&P(`li`,{children:n(`setup.plan.why.bigger`,{name:An.name,need:NS(An.need_gb),have:NS(An.capacity_gb)})})]}),P(Gj,{children:V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>rn?le({kind:`low_disk`}):void jt(!1),disabled:fe||on||Dn,children:[fe&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,nn.length?n(`setup.plan.start`):n(`setup.plan.startNoDownload`)]})}),V(`div`,{className:`setup-row`,children:[P(`button`,{type:`button`,className:`link-btn`,onClick:Pt,disabled:Dn,children:n(`setup.plan.customize`)}),P(`button`,{type:`button`,className:`link-btn`,onClick:Ft,disabled:Dn,children:n(`setup.plan.cloud`)}),t&&P(`button`,{type:`button`,className:`link-btn`,onClick:t,children:n(`setup.backToGaia`)})]}),on&&V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:n(`setup.blocked`)}),V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:b?.blockers.join(`
81
- `)})]})]}),rn&&P(`p`,{className:`setup-error`,role:`alert`,children:n(`setup.summary.short`,{need:$(rn.needGb),free:$(rn.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(rn.freeUpGb)})}),(me??A)&&P(gN,{text:me??A})]}),V(`details`,{className:`setup-disclosure`,children:[P(`summary`,{children:n(`setup.plan.whatDownloads`)}),P(mM,{plan:L,models:nn})]})]}),cn===`gpu`&&oe&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.gpu.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.gpu.lede`)}),P(tM,{status:oe,onStatus:H,mode:`setup`,headingId:`setup-title`,names:Xt,onBack:Lt,onSkip:()=>Mt(d),onContinue:()=>Mt(d)})]}),cn===`models`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.models.title`)}),L&&B&&P(IM,{plan:L,selection:B,onSelection:te,disabled:fe||Dn,onRecheck:()=>void gt()}),It&&oe?.total_gb!=null&&oe.gpu_gb!=null&&V(`p`,{className:`setup-hint setup-gpu-option`,children:[n(`setup.models.gpu`,{gpu:$(oe.gpu_gb),total:$(oe.total_gb)}),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:()=>zt(`models`),disabled:fe||Dn,children:n(`setup.found.changeMemory`)})]}),P(nM,{plan:L,planError:R,onRetryPlan:()=>void gt(),onUseRecommended:()=>void wt(!1,{keepTrying:U}),selection:B,onSelection:te,cloud:!1,keepTrying:U,onKeepTrying:se,onBack:Lt,onContinue:e=>void jt(e),busy:fe||Dn,error:me??A})]}),cn===`key`&&V(`form`,{id:`setup-key-form`,onSubmit:e=>{e.preventDefault(),Gt()},className:`setup-form`,children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.key.title`)}),P(`div`,{className:`setup-choices`,role:`radiogroup`,"aria-label":n(`setup.key.provider`),children:sN.filter(e=>e.id!==`local`).map(e=>V(`button`,{type:`button`,role:`radio`,"aria-checked":a===e.id,className:`setup-choice${a===e.id?` is-active`:``}${tt(e.id)?` is-disabled`:``}`,onClick:()=>Kt(e.id),disabled:F.busy||tt(e.id),title:et(e.id)?n(`settings.privacy.localOnlyBlocked`):void 0,children:[P(Ir,{size:16,"aria-hidden":`true`}),V(`span`,{children:[P(`span`,{className:`setup-choice-title`,children:P(`bdi`,{children:cN(e,n)})}),P(`span`,{className:`setup-choice-note`,children:tt(e.id)?nt(e.id):n(e.note)})]})]},e.id))}),Je?.reachable===!1&&P(`button`,{type:`button`,className:`link-btn setup-start`,onClick:Xe,children:n(`setup.key.checkAgain`)}),et(a)&&P(`p`,{className:`setup-a11y-alert`,role:`alert`,children:n(`settings.privacy.localOnlyBlocked`)}),a===`fireworks`&&!Oe&&!et(a)&&V(`section`,{className:`setup-card`,children:[P(`h3`,{className:`mc-job-title`,children:n(`setup.key.getOne`)}),V(`ol`,{className:`setup-key-steps`,children:[P(`li`,{children:P(`a`,{href:aN,target:`_blank`,rel:`noreferrer`,children:n(`setup.key.step1`)})}),P(`li`,{children:n(`setup.key.step2`)}),P(`li`,{children:n(`setup.key.step3`)})]})]}),a===`amd`&&!Oe&&!et(a)&&P(`section`,{className:`setup-card`,children:P(`p`,{className:`setup-hint`,children:P(`a`,{href:oN,target:`_blank`,rel:`noreferrer`,children:n(`setup.key.gatewayHelp`)})})}),!et(a)&&P(WA,{provider:a,limit:3}),P(`p`,{className:`setup-hint`,children:n(Oe?`setup.key.usersServer`:`setup.key.where`)}),P(`div`,{className:`setup-row`,children:!Oe&&P(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,value:M,onChange:e=>N(e.target.value),placeholder:n(`setup.key.placeholder`),"aria-label":n(`setup.key.label`)})}),$e&&!Oe&&!M&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.key.foundEnv`,{name:$e.name,hint:$e.key_hint??``})}),F.busy&&!F.waiting&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.key.testing`)}),F.busy&&F.waiting&&P(`p`,{className:`setup-hint`,role:`status`,children:F.waiting}),F.error&&P(`p`,{className:`setup-error`,role:`alert`,children:F.error}),V(Gj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:Nt,disabled:F.busy,children:n(`setup.back`)}),V(`button`,{type:`submit`,form:`setup-key-form`,className:`btn-primary`,disabled:F.busy||tt(a)||Dn,children:[F.busy&&P(q,{size:13,className:`spin`}),` `,n(`setup.key.connect`)]})]})]}),cn===`download`&&!K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.download.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.download.lede`)}),V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.starting`)]})]}),cn===`download`&&K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.download.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.download.lede`)}),L&&P(`section`,{className:`setup-card`,"aria-label":n(`setup.contents.title`),children:P(mM,{plan:L,run:K,onRetry:Et,retryDisabled:fe})}),(K.models?.length??0)>0?P(`div`,{className:O?`is-stale`:void 0,children:P(EM,{status:{...K,overall:Cj(K,ne??L)},names:Xt,freeGb:L?.disk?.free_gb??null,onCancel:()=>void Vt(),onRetry:(e,t)=>void Ht(e,t),onResume:e=>void Ht(e,null),onResumeAll:Et,onSkip:e=>void Ut(e),onRestart:()=>void Wt(),busy:fe||!!O,retryLater:st,labelledBy:`setup-title`})}):st?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.working`)]}):null,kn.length>0&&V(`section`,{className:`setup-card`,"aria-label":n(`setup.optional.title`),children:[P(`h3`,{className:`mc-job-title`,children:n(`setup.optional.title`)}),P(`p`,{className:`setup-hint`,children:n(`setup.optional.lede`)}),P(`ul`,{className:`setup-rows`,children:kn.map(e=>{let t=Se.includes(e.id);return V(`li`,{className:`setup-result is-waiting`,children:[P(`span`,{className:`setup-result-label`,children:n(`setup.purpose.${e.roles[0]}`)}),V(`span`,{className:`setup-result-value`,children:[P(`bdi`,{dir:`ltr`,children:e.size_gb==null?n(`setup.contents.sizeOnDownload`):$(e.size_gb)}),P(`button`,{type:`button`,className:`btn-secondary`,"aria-pressed":t,onClick:()=>we(n=>t?n.filter(t=>t!==e.id):[...n,e.id]),children:n(t?`setup.optional.added`:`setup.optional.add`)})]})]},e.id)})})]}),O&&V(D.Fragment,{children:[P(`p`,{className:`setup-error`,role:`alert`,children:n(`setup.lostContact`,{error:O})}),P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void St(),children:n(`setup.reconnect`)})})]}),Qt&&$t&&!en&&K.state===`failed`&&!K.model_failed&&(K.problem?P(hN,{problem:K.problem,onRetry:Et,onUseGaia:()=>void wt(!0,Me.current.options)}):V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:n(`setup.download.stoppedBeforeCheck`)}),K.error&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:K.error})]})]})),Qt&&$t&&!en&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.download.finishNote`)}),P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:Et,disabled:fe,children:n(`setup.finish`)})})]}),Qt&&!$t&&!en&&!(K.models??[]).some(e=>e.state===`failed`||e.state===`cancelled`)&&V(D.Fragment,{children:[P(_N,{run:K}),K.problem?P(hN,{problem:K.problem,onRetry:Et,onUseGaia:()=>void wt(!0,Me.current.options)}):P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void wt(!!K.gaia_lemonade,Me.current.options),children:n(`setup.tryAgain`)})})]}),(me||A)&&P(gN,{text:me??A})]}),cn===`test`&&K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.test.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.test.lede`)}),P(iN,{run:K,expected:On,names:Xt,catalog:tn,onRetry:Et,onChooseAnother:rt?void 0:Pt,onCancel:()=>void Vt(),onDownloadAgain:L?.lemonade.mode===`external`?void 0:e=>void Ht(e,`verify`),busy:fe}),Qt&&K.error&&!(K.tests??[]).some(e=>e.error===K.error)&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:K.error})]}),(me||A)&&P(gN,{text:me??A})]}),cn===`ready`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.ready.heading`)}),V(`div`,{className:`setup-done`,role:`status`,children:[P(`div`,{className:`setup-done-head`,children:Jt&&P(`p`,{children:n(rt?`setup.ready.answersCloud`:`setup.ready.answersLocal`,{model:rt?vs(Jt):Xt[Jt]??ie?.catalog?.find(e=>e.id===Jt)?.name??vs(Jt)})})}),P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Yt(),autoFocus:!0,children:n(`setup.ready.start`)})}),!rt&&ie&&P(rM,{plan:ie,chatModel:Jt,gpu:oe}),A&&P(gN,{text:A}),(K?.tests??[]).filter(e=>e.state===`failed`).map(e=>P(`p`,{className:`setup-failed-extra`,role:`alert`,children:n(`setup.ready.extraFailed`,{job:n(`setup.test.job.${e.job}`)})},`${e.job}:${e.subject??``}`)),Ee.length>0&&!W&&P(`p`,{className:`setup-failed-extra`,role:`alert`,children:n(`setup.ready.extraNotFetched`,{names:Ee.map(e=>Xt[e]??e).join(`, `)})}),be.length>0&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.ready.tasks`)}),P(cM,{cards:be,onPick:e=>void Yt(e)})]})]})]})]},cn),t&&!st&&cn!==`plan`&&cn!==`ready`&&P(`div`,{className:`setup-row`,children:P(`button`,{type:`button`,className:`link-btn setup-close`,onClick:t,children:n(`setup.backToGaia`)})}),Dn&&(En||cn===`plan`)&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.nav.runGoing`)}),P(kM,{run:w,before:{check:gn}})]}),P(`div`,{className:`setup-footer`,ref:m})]})}),W?.kind===`no_fit`&&P(Kj,{title:W.models.length===1?n(`setup.confirm.noFitOne`,{name:W.models[0].name}):n(`setup.confirm.noFitMany`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.pickSmaller`),onConfirm:()=>{le(null),de(!0),jt(Ot,!0)},onCancel:()=>le(null),children:W.models.map(e=>V(`p`,{children:[P(`bdi`,{children:e.name}),`: `,Aj(e,n)]},e.id))}),W?.kind===`low_disk`&&rn&&P(Kj,{title:n(`setup.confirm.lowDiskTitle`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{le(null),jt(!0)},onCancel:()=>{le(null),Pt()},children:P(`p`,{children:n(`setup.summary.short`,{need:$(rn.needGb),free:$(rn.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(rn.freeUpGb)})})}),W?.kind===`server`&&P(Kj,{title:W.detail.code===`low_disk`?n(`setup.confirm.lowDiskTitle`):n(`setup.confirm.noFitServerTitle`),confirmLabel:W.detail.code===`low_disk`?n(`setup.confirm.downloadAnyway`):n(`setup.confirm.useAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{let e=W;if(le(null),e.then===`chat`)de(!0),jt(Ot,!0);else if(e.then===`retry`)Te(e.id,{keepTrying:U,acknowledgeLowDisk:!0}).then(E).catch(e=>he(yN(e)));else{let{gaiaLemonade:e,options:t}=Me.current;wt(e,{...t,acknowledgeLowDisk:!0})}},onCancel:()=>{let e=W;le(null),e.then!==`retry`&&!ct&&Pt()},children:P(`p`,{children:W.detail.message})})]})}function xN(e,t,n){let r=(0,X.useRef)(n);(0,X.useEffect)(()=>{r.current=n});let i=(0,X.useRef)(!1),a=(0,X.useRef)(null);if(t&&!i.current){let e=document.activeElement;a.current=e instanceof HTMLElement?e:null}(0,X.useEffect)(()=>{if(!t)return;i.current=!0;let n=a.current,o=e.current;if(o&&!o.contains(document.activeElement)){let e=r.current?.()??oS(o)[0];e?e.focus():(o.hasAttribute(`tabindex`)||o.setAttribute(`tabindex`,`-1`),o.focus())}return()=>{i.current=!1;let e=document.activeElement;(!e||e===document.body||o?.contains(e))&&n?.isConnected&&n.focus()}},[e,t])}function SN({title:e,titleId:t,count:n,hint:r,defaultOpen:i=!1,forceOpen:a=!1,children:o}){let[s,c]=(0,X.useState)(i);return V(`details`,{className:`settings-disclosure`,open:s||a,onToggle:e=>{a||c(e.currentTarget.open)},children:[V(`summary`,{onClick:e=>{a&&e.preventDefault()},children:[P(gr,{size:15,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),V(`span`,{className:`settings-disclosure-text`,children:[P(`span`,{className:`settings-disclosure-title`,id:t,tabIndex:t?-1:void 0,children:e}),r&&P(`span`,{className:`settings-disclosure-hint`,children:r})]}),n!=null&&P(`bdi`,{dir:`ltr`,className:`settings-disclosure-count`,children:n})]}),P(`div`,{className:`settings-disclosure-body`,children:o})]})}var CN=g(Tc()?`settings.desktop.menuBar`:`settings.desktop.tray`),wN=[{key:`minimizeToTray`,label:`settings.desktop.keepRunning`,hint:`settings.desktop.keepRunningHint`},{key:`startOnLogin`,label:`settings.desktop.startOnLogin`,hint:`settings.desktop.startOnLoginHint`},{key:`startMinimized`,label:`settings.desktop.startMinimized`,hint:`settings.desktop.startMinimizedHint`}],TN=new Set([`startMinimized`]),EN={minimizeToTray:`settings.desktop.keepRunningNoTray`};function DN(e){return e?.reason===`no-host`?`settings.desktop.noTray`:e?.reason===`check-failed`?`settings.desktop.noTrayCheckFailed`:null}function ON(){let e=T(),t=window.gaiaAPI?.tray,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null);(0,X.useEffect)(()=>{t&&t.getConfig().then(e=>{r(e.tray),a(e.host)}).catch(t=>s(e(`settings.desktop.readFailed`,{reason:t instanceof Error?t.message:String(t)})))},[t,e]);let u=(0,X.useCallback)(async e=>{if(t&&n&&c===null){l(e),s(null);try{let i=await t.setConfig({tray:{[e]:!n[e]}});r(i.tray),a(i.host)}catch(e){s(e instanceof Error?e.message:String(e))}finally{l(null)}}},[t,n,c]);if(!t)return null;let d=DN(i);return P(SN,{title:e(`settings.desktop.title`),children:V(`div`,{className:`settings-field`,role:`group`,"aria-labelledby":`desktop-app-label`,children:[P(`span`,{className:`settings-label`,id:`desktop-app-label`,children:e(`settings.desktop.title`)}),wN.map(({key:t,label:r,hint:i})=>{let a=TN.has(t)?d:null,o=d&&EN[t]||i;return V(`div`,{children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(r,{tray:CN})}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,role:`switch`,checked:!a&&!!n?.[t],"aria-describedby":`desktop-${t}-hint`,onChange:()=>void u(t),disabled:!!a||!n||c!==null&&c!==t,"aria-busy":c===t,"aria-label":e(r,{tray:CN})}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,id:`desktop-${t}-hint`,children:a?e(a):e(o,{tray:CN})})]},t)}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o})]})})}function kN(){return window.gaiaUpdater}var AN={status:`idle`,version:null,progress:0,releaseNotes:null,error:null,currentVersion:null,pinnedVersion:null,autoUpdate:!1,includePrereleases:!1};function jN(){let[e,t]=(0,X.useState)({...AN});return(0,X.useEffect)(()=>{let e=kN();if(!e)return;let n=!0;e.getStatus().then(e=>{n&&e&&t(e)}).catch(()=>{});let r=e.onStatusChange(e=>{n&&e&&t(e)});return()=>{n=!1;try{r()}catch{}}},[]),e}var MN=`gaia-update-error:`;function NN(e,t){let n=`update.err.${e}`;return N(n)?g(n,t??{}):null}function PN(e){let t=e instanceof Error?e.message:String(e),n=t.indexOf(MN);if(n<0)return t.replace(/^Error invoking remote method '[^']+': (?:Error: )?/,``);let r;try{r=JSON.parse(t.slice(n+18))}catch{return t.slice(0,n)+t.slice(n+18)}let i=NN(r.code,r.params)??r.message??r.code,a=r.note&&NN(r.note.code,r.note.params);return a?g(`update.err.withNote`,{error:i,note:a}):i}function FN(e,t){let n=PN(e);return typeof n==`object`?t(n.ref,n.params):String(n)}function IN(){return window.gaiaUpdater}function LN({onClose:e}){let t=T(),[n,r]=(0,X.useState)({kind:`loading`}),i=(0,X.useRef)(null);(0,X.useEffect)(()=>{let e=IN();e?e.listReleases().then(e=>{r(Array.isArray(e)?{kind:`list`,releases:e}:{kind:`error`,message:e.error})}).catch(()=>{r({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})}):r({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})},[]),Io(!0,e),sS(i,!0),(0,X.useEffect)(()=>{let e=i.current;e&&e.querySelector(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`)?.focus()},[]),(0,X.useEffect)(()=>{let e=i.current;if(!e)return;function t(t){if(t.key!==`Tab`||!e)return;let n=e.querySelectorAll(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`);if(n.length===0)return;let r=n[0],i=n[n.length-1];t.shiftKey?document.activeElement===r&&(t.preventDefault(),i?.focus()):document.activeElement===i&&(t.preventDefault(),r?.focus())}return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[]);function a(e,t){e.isCurrent||r({kind:`confirm`,release:e,releases:t})}async function o(n){r({kind:`installing`});let i=IN();if(!i)r({kind:`error`,message:t(`update.picker.noBridge`)});else try{await i.installVersion(n.tag),e()}catch(e){r({kind:`error`,message:t(`update.picker.failed`,{reason:PN(e)})})}}function s(e){if(!e)return``;try{return new Date(e).toLocaleDateString(te(t),{year:`numeric`,month:`short`,day:`numeric`})}catch{return e}}return P(`div`,{className:`version-picker-overlay`,onClick:t=>{t.target===t.currentTarget&&e()},children:V(`div`,{className:`version-picker-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`update.picker.title`),ref:i,children:[V(`div`,{className:`version-picker-header`,children:[P(`h3`,{children:t(`update.picker.title`)}),P(`button`,{className:`version-picker-close`,onClick:e,"aria-label":t(`update.picker.close`),type:`button`,children:`×`})]}),V(`div`,{className:`version-picker-body`,children:[n.kind===`loading`&&V(`div`,{className:`version-picker-loading`,"aria-busy":`true`,children:[P(`span`,{className:`version-picker-spinner`}),t(`update.picker.loading`)]}),n.kind===`error`&&V(`div`,{className:`version-picker-error`,children:[P(`p`,{children:n.message}),P(`p`,{children:P(`a`,{href:`https://github.com/amd/gaia/releases`,target:`_blank`,rel:`noreferrer`,children:t(`update.picker.browse`)})})]}),n.kind===`list`&&P(`ul`,{className:`version-picker-list`,role:`listbox`,"aria-label":t(`update.picker.listAria`),children:n.releases.map(e=>P(`li`,{children:V(`button`,{type:`button`,className:`version-picker-row`,"data-version":e.version,"aria-label":e.isCurrent?t(`update.picker.rowInstalled`,{version:e.version}):e.isPinned?t(`update.picker.rowPinned`,{version:e.version}):e.version,"aria-disabled":e.isCurrent?`true`:`false`,onClick:()=>a(e,n.releases),disabled:e.isCurrent,children:[P(`span`,{className:`vp-version`,children:e.version}),P(`span`,{className:`vp-date`,children:s(e.date)}),e.isCurrent&&P(`span`,{className:`vp-badge vp-badge-current`,children:t(`update.picker.installed`)}),e.isPinned&&!e.isCurrent&&P(`span`,{className:`vp-badge vp-badge-pinned`,children:t(`update.picker.pinned`)}),!e.isCurrent&&P(`span`,{className:`vp-arrow`,"aria-hidden":`true`,children:`›`})]})},e.tag))}),n.kind===`list`&&V(`p`,{className:`version-picker-more`,children:[t(`update.picker.recent`,{n:n.releases.length}),` `,P(`a`,{href:`https://github.com/amd/gaia/releases`,target:`_blank`,rel:`noreferrer`,children:t(`update.picker.browseAll`)})]}),n.kind===`confirm`&&V(`div`,{className:`version-picker-confirm`,children:[P(`p`,{children:t(`update.picker.confirm`,{version:n.release.version})}),P(`p`,{className:`vp-confirm-note`,children:t(`update.picker.confirmNote`,{version:n.release.version})}),V(`div`,{className:`vp-confirm-actions`,children:[P(`button`,{type:`button`,className:`vp-btn-cancel`,onClick:()=>r({kind:`list`,releases:n.releases}),children:t(`update.picker.back`)}),P(`button`,{type:`button`,className:`vp-btn-confirm`,onClick:()=>o(n.release),children:t(`update.picker.install`)})]})]}),n.kind===`installing`&&V(`div`,{className:`version-picker-loading`,"aria-busy":`true`,children:[P(`span`,{className:`version-picker-spinner`}),t(`update.picker.starting`)]})]})]})})}var RN=`https://github.com/amd/gaia/releases`;function zN(e){return/^\d+\.\d+\.\d+-/.test(e??``)}function BN(e,t){let n=e.version??``;switch(e.status){case`checking`:return t(`update.status.checking`);case`available`:return t(`update.status.available`,{version:n});case`downloading`:return e.preparing?t(`update.status.preparing`,{version:n}):t(`update.status.downloading`,{version:n,pct:e.progress});case`downloaded`:return t(`update.status.downloaded`,{version:n});case`error`:return t(`update.status.error`,{reason:e.error??t(`update.status.unknownError`)});case`no-channel`:return e.error??t(`update.status.noChannel`);case`disabled`:return t(`update.status.disabled`);default:return t(`update.status.upToDate`)}}function VN(){let e=jN(),t=T(),n=kN(),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1);if(!n)return null;async function l(e,r){if(n){i(!0),o(null);try{await r(n)}catch(n){d.system.error(`${e} failed`,n),o(t(`update.settings.failed`,{action:g(e),reason:PN(n)}))}finally{i(!1)}}}let u=e.status===`disabled`,f=r||e.status===`checking`||e.status===`downloading`,p=`${t(`update.settings.running`,{version:e.currentVersion??t(`update.settings.unknownVersion`)})} ${BN(e,t)}`,m=[`available`,`downloaded`,`error`].includes(e.status)||!!e.pinnedVersion||!!e.installFailed||!!e.configError||!!a;return P(SN,{title:t(`update.settings.title`),titleId:`updates-label`,hint:p,forceOpen:m,children:V(`div`,{className:`settings-field`,role:`group`,"aria-labelledby":`updates-label`,children:[P(`p`,{className:`visually-hidden`,role:`status`,children:p}),V(`label`,{className:`setting-row`,children:[P(`span`,{children:t(`update.settings.auto`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,role:`switch`,checked:e.autoUpdate,"aria-describedby":`updates-auto-hint`,"aria-label":t(`update.settings.auto`),"aria-busy":r,disabled:u,onChange:()=>{r||l(`update.action.saveAuto`,t=>t.setAutoUpdate(!e.autoUpdate))}}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,id:`updates-auto-hint`,children:t(`update.settings.autoHint`)}),V(`label`,{className:`setting-row`,children:[P(`span`,{children:t(`update.settings.rc`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,role:`switch`,checked:!!e.includePrereleases,"aria-describedby":`updates-rc-hint`,"aria-label":t(`update.settings.rc`),"aria-busy":r,disabled:u,onChange:()=>{r||l(`update.action.saveRc`,t=>t.setIncludePrereleases(!e.includePrereleases))}}),P(`span`,{className:`toggle-track`})]})]}),V(`p`,{className:`settings-hint`,id:`updates-rc-hint`,children:[t(`update.settings.rcHint`),zN(e.currentVersion)&&` ${t(`update.settings.rcHintRunning`)}`]}),e.pinnedVersion&&V(`p`,{className:`settings-hint`,children:[t(`update.settings.pinned`,{version:e.pinnedVersion}),` `,P(`button`,{type:`button`,className:`btn-secondary`,disabled:r,onClick:()=>void l(`update.action.resume`,e=>e.resumeUpdates()),children:t(`update.settings.unpin`)})]}),V(`div`,{className:`setting-actions`,children:[e.status===`available`&&!e.pinnedVersion&&P(`button`,{type:`button`,className:`btn-primary`,disabled:r,onClick:()=>void l(`update.action.download`,e=>e.downloadUpdate()),children:t(`update.settings.updateTo`,{version:e.version??``})}),e.status===`downloaded`&&P(`button`,{type:`button`,className:`btn-primary`,disabled:r,onClick:()=>void l(`update.action.restart`,e=>e.restart()),children:t(`update.settings.restart`)}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:f||u,onClick:()=>void l(`update.action.check`,e=>e.check()),children:t(`update.settings.check`)}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:f||u,onClick:()=>c(!0),children:t(`update.settings.pick`)}),e.previousVersion&&P(`button`,{type:`button`,className:`btn-secondary`,"aria-describedby":`updates-back-hint`,disabled:f||u,onClick:()=>void l(`update.action.goBack`,e=>e.revertUpdate()),children:t(`update.settings.goBack`,{version:e.previousVersion})})]}),e.previousVersion&&P(`p`,{className:`settings-hint`,id:`updates-back-hint`,children:t(`update.settings.goBackHint`)}),e.installFailed&&P(`p`,{className:`settings-error`,role:`alert`,children:t(`update.settings.installFailed`,{...e.installFailed,url:RN})}),e.lastCheckError&&P(`p`,{className:`settings-hint`,children:t(`update.settings.lastCheckError`,{reason:e.lastCheckError})}),e.configError&&P(`p`,{className:`settings-error`,role:`alert`,children:e.configError}),a&&P(`p`,{className:`settings-error`,role:`alert`,children:a}),s&&P(LN,{onClose:()=>c(!1)})]})})}var HN=[{value:`light`,label:`settings.theme.light`},{value:`dark`,label:`settings.theme.dark`},{value:`system`,label:`settings.theme.system`}],UN={default:`palette.default`,stone:`palette.stone`,marble:`palette.marble`,glacier:`palette.glacier`,forest:`palette.forest`,sage:`palette.sage`,basalt:`palette.basalt`,gold:`palette.gold`,dusk:`palette.dusk`,custom:`settings.colors.custom`},WN=[[`Enter`,`settings.shortcut.send`],[`Shift+Enter`,`settings.shortcut.newLine`],[`Esc`,`settings.shortcut.stop`],[`Mod+Shift+O`,`settings.shortcut.newChat`],[`Mod+K`,`settings.shortcut.search`],[`Mod+B`,`settings.shortcut.sidebar`],[`Mod+,`,`settings.shortcut.settings`]];function GN(){let e=T(),t=k(e=>e.locale),n=k(e=>e.setLocale),r=k(e=>e.themePreference),i=k(e=>e.setThemePreference),a=k(e=>e.palette),o=k(e=>e.setPalette),s=k(e=>e.customColors),c=k(e=>e.setCustomColors),l=qO(e=>e.visible),u=qO(e=>e.setVisible),d=e=>t=>c({...s,[e]:t.target.value.toUpperCase()});return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.general`)}),V(`div`,{className:`settings-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`ui-language`,children:e(`settings.language`)}),P(`select`,{id:`ui-language`,className:`settings-input`,value:t,onChange:e=>n(e.target.value),children:b.map(({meta:e})=>P(`option`,{value:e.code,lang:e.code,dir:e.dir,children:M(e)},e.code))}),P(`span`,{className:`settings-hint`,children:e(`settings.languageHint`)})]}),V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,id:`appearance-label`,children:e(`settings.appearance`)}),P(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`appearance-label`,children:HN.map(t=>P(`button`,{type:`button`,role:`radio`,"aria-checked":r===t.value,className:r===t.value?`is-active`:``,onClick:()=>i(t.value),children:e(t.label)},t.value))})]}),V(`div`,{className:`settings-field`,children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`resources.settings`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),"aria-label":e(`resources.settings`),"aria-describedby":`resources-hint`}),P(`span`,{className:`toggle-track`})]})]}),P(`span`,{className:`settings-hint`,id:`resources-hint`,children:e(`resources.settingsHint`)})]}),V(SN,{title:e(`settings.colors`),titleId:`palette-label`,defaultOpen:a===`custom`,children:[V(`div`,{className:`palette-grid`,role:`radiogroup`,"aria-labelledby":`palette-label`,children:[oe.map(t=>V(`button`,{type:`button`,role:`radio`,"aria-checked":a===t.id,className:`palette-tile${a===t.id?` is-active`:``}`,onClick:()=>o(t.id),children:[P(`span`,{className:`palette-swatch`,"aria-hidden":`true`,children:t.swatch.map(e=>P(`i`,{style:{background:e}},e))}),e(UN[t.id])]},t.id)),V(`button`,{type:`button`,role:`radio`,"aria-checked":a===`custom`,className:`palette-tile${a===`custom`?` is-active`:``}`,onClick:()=>o(`custom`),children:[V(`span`,{className:`palette-swatch`,"aria-hidden":`true`,children:[P(`i`,{style:{background:s.base}}),P(`i`,{style:{background:s.accent}})]}),e(`settings.colors.custom`)]})]}),a===`custom`&&V(`div`,{className:`palette-custom`,children:[V(`label`,{className:`palette-color`,htmlFor:`custom-accent`,children:[P(`input`,{id:`custom-accent`,type:`color`,value:s.accent,onChange:d(`accent`)}),V(`span`,{children:[e(`settings.colors.accent`),P(`small`,{children:e(`settings.colors.accentHint`)})]})]}),V(`label`,{className:`palette-color`,htmlFor:`custom-base`,children:[P(`input`,{id:`custom-base`,type:`color`,value:s.base,onChange:d(`base`)}),V(`span`,{children:[e(`settings.colors.base`),P(`small`,{children:e(`settings.colors.baseHint`)})]})]}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>c(v),children:e(`settings.colors.reset`)}),P(`p`,{className:`settings-hint`,children:e(`settings.colors.hint`)})]})]}),P(ON,{}),P(VN,{}),P(SN,{title:e(`settings.shortcuts`),children:P(`dl`,{className:`shortcut-list`,children:WN.map(([t,n])=>V(`div`,{className:`shortcut-row`,children:[P(`dt`,{children:P(`kbd`,{children:kc(t)})}),P(`dd`,{children:e(n)})]},t))})})]})}function KN(e){return/not reachable|not answering|model server at|ConnectionPool|NewConnectionError|Connection refused|Max retries/i.test(e)}function qN(e){return/gaia init/i.test(e??``)}function JN(e){return!!e&&!e.lemonade_running&&(qN(e.start_command)||qN(e.start_instruction))}function YN({className:e=`btn-secondary`}){let t=T();return P(`button`,{type:`button`,className:e,onClick:()=>window.dispatchEvent(new CustomEvent(`gaia:set-up-local`)),children:t(`settings.errors.setUpLocal`)})}function XN({message:e,onRetry:t}){let n=T(),r=k(e=>JN(e.systemStatus));return KN(e)?V(`div`,{className:`settings-notice`,role:`alert`,children:[P(`strong`,{children:n(r?`settings.errors.notInstalledTitle`:`settings.errors.serverDownTitle`)}),P(`p`,{children:n(r?`settings.errors.notInstalled`:`settings.errors.serverDown`)}),r&&P(YN,{className:`btn-primary`}),t&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:t,children:n(`settings.key.checkAgain`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,n(`settings.errors.details`)]}),P(`bdi`,{dir:`ltr`,className:`settings-notice-raw`,children:e})]})]}):P(`p`,{className:`settings-error`,role:`alert`,children:e})}function ZN({onAdded:e}){let t=T(),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),f=(0,X.useRef)(``),p=(0,X.useCallback)(async e=>{let t=n.trim();f.current=t,l(`check`),d(null);try{let n=await cn(t,e);if(f.current!==t)return;s(n),a(n.file??e)}catch(e){if(f.current!==t)return;s(null),d(e instanceof Error?e.message:String(e))}finally{l(null)}},[n]),m=(0,X.useCallback)(async()=>{l(`add`),d(null);try{let{report:o}=await xt(n.trim(),i);r(``),a(``),s(null),e(o.display_name??o.model_id??t(`settings.custom.theModel`))}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(null)}},[e,i,n,t]);return V(`form`,{className:`settings-field custom-model-add`,onSubmit:e=>{e.preventDefault(),p(``)},children:[P(`label`,{className:`visually-hidden`,htmlFor:`custom-model-url`,children:t(`settings.custom.title`)}),P(`span`,{className:`settings-hint`,children:t(`settings.custom.hint`)}),V(`div`,{className:`settings-row`,children:[P(`input`,{id:`custom-model-url`,className:`settings-input`,type:`url`,inputMode:`url`,dir:`ltr`,spellCheck:!1,autoComplete:`off`,value:n,readOnly:c!==null,onChange:e=>{r(e.target.value),s(null),a(``),f.current=``},placeholder:`https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF`}),V(`button`,{type:`submit`,className:`btn-secondary`,disabled:c!==null||!n.trim(),children:[c===`check`?P(q,{size:13,className:`spin`}):null,` `,t(`settings.custom.check`)]})]}),o&&(()=>{let e=P(`ul`,{className:`custom-model-checks`,"aria-label":t(`settings.custom.checks`),children:o.checks.map(e=>V(`li`,{className:e.ok?`is-ok`:`is-failed`,children:[e.ok?P(mr,{size:13,"aria-label":t(`settings.custom.passed`)}):P(Y,{size:13,"aria-label":t(`settings.custom.failed`)}),V(`bdi`,{children:[P(`strong`,{children:e.label}),` — `,e.detail]})]},e.id))});return o.ok?V(`details`,{className:`custom-model-checks-summary`,children:[V(`summary`,{children:[P(mr,{size:13,"aria-hidden":`true`}),` `,t(`settings.custom.allPassed`,{n:o.checks.length})]}),e]}):e})(),o&&o.warnings.length>0&&P(`ul`,{className:`custom-model-checks`,"aria-label":t(`settings.custom.warnings`),children:o.warnings.map(e=>V(`li`,{className:`is-warning`,children:[P(J,{size:13,"aria-label":t(`settings.custom.warning`)}),` `,P(`bdi`,{children:e})]},e))}),o&&o.variants.length>1&&V(`div`,{className:`settings-row`,children:[P(`label`,{className:`settings-hint`,htmlFor:`custom-model-quant`,children:t(`settings.custom.quantization`)}),P(`select`,{id:`custom-model-quant`,className:`settings-input`,value:i,onChange:e=>void p(e.target.value),disabled:c!==null,children:o.variants.map(e=>V(`option`,{value:e.file,children:[e.quant,` · `,e.size_gb,` GB`,e.fits?``:` · ${t.bare(`settings.custom.tooLarge`)}`]},e.file))})]}),o?.ok&&V(`div`,{className:`settings-row`,children:[V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void m(),disabled:c!==null,children:[c===`add`?P(q,{size:13,className:`spin`}):null,` `,t(`settings.custom.add`,{name:o.display_name??``})]}),P(`span`,{className:`settings-hint`,children:t(`settings.model.sizeDownload`,{size:`${o.size_gb} GB`})})]}),u&&P(XN,{message:u})]})}function QN(e){return e instanceof Error?e.message:String(e)}function $N(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function eP({downloadsSlot:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),b=Ls(e=>e.status),x=Ls(e=>e.started),S=(0,X.useMemo)(()=>Ps(b,x),[b,x]),C=Ls(e=>e.error),w=Ls(e=>e.refresh),E=Ls(e=>e.enqueue),O=Ls(e=>e.cancel),k=(0,X.useCallback)(async(e=!1)=>{a(null);try{let t=await Ce();r(t),s(n=>e||!n?fj(t):n)}catch(e){a(QN(e))}},[]);(0,X.useEffect)(()=>{k(!0),w(),(async()=>{try{_(await Nn()??null)}catch(e){y(QN(e))}})()},[k,w]);let A=(S?.models??[]).filter(e=>e.state===`ready`).map(e=>e.id).join(`,`),j=(0,X.useRef)(A);(0,X.useEffect)(()=>{A!==j.current&&(j.current=A,k(!0))},[A,k]);let M=(0,X.useMemo)(()=>{let e={};for(let t of S?.models??[])e[t.id]=t;return e},[S]),N=(0,X.useMemo)(()=>{let e={};for(let t of n?.catalog??[])e[t.id]=t.name;return e},[n]),F=(0,X.useMemo)(()=>n?fj(n):null,[n]),I=ZA(n),L=n&&o?_j(I,o).filter(e=>M[e.id]?.state!==`downloading`):[],ee=L.reduce((e,t)=>e+(t.size_gb??0),0),R=!!n&&!!o&&!!F&&(!$N(o.ticked,F.ticked)||o.defaultChat!==F.defaultChat||L.length>0),z=(0,X.useCallback)(async(e,i)=>{if(!n||!o)return;if(p(null),!e){let e=bj(I,o).filter(e=>!e.downloaded||e.id===o.defaultChat);if(e.length>0&&e.every(e=>e.need_gb!=null)){l({kind:`no_fit`,models:e});return}}let a=yj(n,o);if(a&&!i)l({kind:`low_disk`,message:a.drop?t(`setup.summary.shortDrop`,{need:$(a.needGb),free:$(a.freeGb),drive:Pj(n.disk?.path??null)??t(`setup.summary.theDrive`),freeUp:$(a.freeUpGb),name:a.drop.name,saves:$(a.drop.size_gb??0)}):t(`setup.summary.short`,{need:$(a.needGb),free:$(a.freeGb),drive:Pj(n.disk?.path??null)??t(`setup.summary.theDrive`),freeUp:$(a.freeUpGb)})});else{d(!0);try{let i=n;if(o.defaultChat&&o.defaultChat!==i.chat_model.id)try{i=await Le(o.defaultChat,e||m)}catch(e){let t=ht(e);if(t){l({kind:`server`,detail:t});return}throw e}for(let e of xj(i,o))i=await ft(e.id,e.skipped);let a=_j(ZA(i),o).map(e=>e.id).filter(e=>M[e]?.state!==`downloading`);r(i),s({...o,defaultChat:i.chat_model.id}),cs.getState().refresh(),a.length&&await E(a,{acknowledgeLowDisk:!0}),p({ok:!0,text:t(`settings.models.applied`)})}catch(e){p({ok:!1,text:QN(e)})}finally{d(!1)}}},[n,o,I,m,M,E,t]),B=(0,X.useCallback)(async e=>{l(null),d(!0),p(null);try{let n=await dn(e.id);Uo(),r(n),s(fj(n)),p({ok:!0,text:t(`settings.models.removed`,{name:e.name,size:$(n.freed_gb)})})}catch(e){p({ok:!1,text:QN(e)})}finally{d(!1)}},[t]),te=(0,X.useCallback)((e,t)=>{(async()=>{try{t===`verify`&&await dn(e),await E([e])}catch(e){p({ok:!1,text:QN(e)})}})()},[E]),ne=!!S&&(S.models?.length??0)>0&&(CM(S)||S.models.some(e=>e.state!==`skipped`))&&S&&V(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-downloads-title`,children:[P(`span`,{className:`settings-label`,id:`settings-downloads-title`,children:t(`settings.models.downloads`)}),P(EM,{status:S,names:N,freeGb:n?.disk?.free_gb??null,onCancel:()=>void O(),onRetry:te,onResume:e=>void E([e]),onResumeAll:()=>void E((S.models??[]).filter(e=>e.state===`cancelled`).map(e=>e.id))}),C&&P(`p`,{className:`settings-error`,role:`alert`,children:C})]});return V(D.Fragment,{children:[P(SN,{title:t(`settings.models.manage`),hint:t(`settings.models.manageHint`),forceOpen:!!i||f?.ok===!1,children:V(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-models-title`,children:[P(`span`,{className:`visually-hidden`,id:`settings-models-title`,children:t(`settings.models.title`)}),P(`p`,{className:`settings-hint`,children:t(`settings.models.lede`)}),i&&P(XN,{message:i}),n&&!n.lemonade.reachable&&P(`p`,{className:`settings-hint`,children:t(`settings.models.unavailable`)}),!n&&!i&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,t(`setup.models.loading`)]}),n&&n.lemonade.reachable&&o&&V(D.Fragment,{children:[P(Ij,{plan:n,selection:o,onToggle:(e,t)=>s(mj(o,I,e,t)),onDefaultChat:e=>s(hj(o,I,e)),labelledBy:`settings-models-title`,place:`settings`,disabled:u,progress:M,rowActions:e=>e.downloaded&&e.id!==o.defaultChat?P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>l({kind:`remove`,entry:e}),disabled:u||M[e.id]?.state===`downloading`,"aria-label":t(`settings.models.removeAria`,{name:e.name}),children:t(`settings.models.remove`)}):null}),P(Nj,{plan:n,selection:o}),P(`div`,{className:`models-apply`,children:V(`button`,{type:`button`,className:`btn-primary`,disabled:!R||u,onClick:()=>void z(!1,!1),children:[u&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),u?t(`settings.models.applying`):L.length>0?t(`settings.models.applyDownload`,{size:$(Math.round(ee*10)/10)}):t(`settings.models.apply`)]})})]}),f?.ok&&P(`p`,{className:`settings-ok`,role:`status`,children:f.text}),f&&!f.ok&&P(XN,{message:f.text})]})}),(g?.applies||v&&!KN(v))&&P(SN,{title:t(`gpu.settingsTitle`),titleId:`settings-gpu-title`,defaultOpen:!!g?.pending||!!v,children:V(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-gpu-title`,children:[v&&P(`p`,{className:`settings-error`,role:`alert`,children:v}),g?.applies&&P(tM,{status:g,onStatus:_,mode:`settings`,names:N,headingId:`settings-gpu-title`})]})}),e?(0,eS.createPortal)(ne,e):e===void 0&&ne,c?.kind===`remove`&&P(Kj,{title:t(`settings.models.removeTitle`,{name:c.entry.name}),confirmLabel:t(`settings.models.removeConfirm`),cancelLabel:t(`settings.models.keep`),danger:!0,onConfirm:()=>void B(c.entry),onCancel:()=>l(null),children:P(`p`,{children:QA(c.entry)?t(`settings.models.removeVision`,{size:$(c.entry.full_size_gb??0)}):t(`settings.models.removeBody`,{size:$(c.entry.full_size_gb??0)})})}),c?.kind===`no_fit`&&P(Kj,{title:c.models.length===1?t(`setup.confirm.noFitOne`,{name:c.models[0].name}):t(`setup.confirm.noFitMany`),confirmLabel:t(`setup.confirm.downloadAnyway`),cancelLabel:t(`setup.confirm.pickSmaller`),onConfirm:()=>{l(null),h(!0),z(!0,!1)},onCancel:()=>l(null),children:c.models.map(e=>V(`p`,{children:[P(`bdi`,{children:e.name}),`: `,Aj(e,t)]},e.id))}),c?.kind===`low_disk`&&P(Kj,{title:t(`setup.confirm.lowDiskTitle`),confirmLabel:t(`setup.confirm.downloadAnyway`),cancelLabel:t(`setup.confirm.changeModels`),onConfirm:()=>{l(null),z(!0,!0)},onCancel:()=>l(null),children:P(`p`,{children:c.message})}),c?.kind===`server`&&P(Kj,{title:t(`setup.confirm.noFitServerTitle`),confirmLabel:t(`setup.confirm.useAnyway`),cancelLabel:t(`setup.confirm.changeModels`),onConfirm:()=>{l(null),h(!0),z(!0,!1)},onCancel:()=>l(null),children:P(`p`,{children:c.detail.message})})]})}var tP=`auto`;function nP({model:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null);(0,X.useEffect)(()=>{r(null),a(null),l(null),_e(e).then(r).catch(e=>a(e instanceof Error?e.message:String(e)))},[e]);let u=(0,X.useCallback)(async n=>{s(!0),a(null),l(null);try{let i=await Ke(e,n===tP?null:Number(n));r(i);let a={name:i.display_name,size:i.chosen?Cs(i.chosen):g(`settings.ctx.automaticSize`)},o=i.reload?.reason;i.reload?.started?l(t(`settings.ctx.reloading`,a)):l(o===`already_loaded`?t(`settings.ctx.alreadyLoaded`,a):o===`warm_up`?t(`settings.ctx.warmUp`,a):o===`busy`?t(`settings.ctx.busy`,a):o===`not_gaias_server`?t(`settings.ctx.ownServer`,a):t(o===`restarting`?`settings.ctx.restarting`:`settings.ctx.nextLoad`))}catch(e){a(e instanceof Error?e.message:String(e))}finally{s(!1)}},[e,t]);if(i&&!n)return KN(i)?P(`p`,{className:`settings-hint`,children:t(`settings.ctx.serverDown`)}):P(`p`,{className:`settings-error`,role:`alert`,children:i});if(!n)return V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.ctx.checking`)]});let d=n.chosen==null?tP:String(n.chosen),f=n.chosen!=null&&n.loaded_ctx!=null&&n.loaded_ctx!==n.chosen;return V(D.Fragment,{children:[V(`div`,{className:`model-in-use-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`ctx-size`,children:t(`settings.ctx.label`)}),V(`select`,{id:`ctx-size`,className:`settings-input`,value:d,onChange:e=>void u(e.target.value),disabled:o||n.options.length===0,children:[P(`option`,{value:tP,children:n.automatic?t.bare(`settings.ctx.automaticAt`,{size:Cs(n.automatic)}):t.bare(`settings.ctx.automatic`)}),n.options.map(e=>P(`option`,{value:String(e),children:t.bare(`settings.ctx.tokens`,{size:Cs(e)})},e))]})]}),n.note&&P(`span`,{className:`settings-hint`,children:P(`bdi`,{children:n.note})}),!n.note&&!!n.max_fit&&V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.ctx.about`)]}),P(`span`,{className:`settings-hint`,children:t(`settings.ctx.explain`,{size:Cs(n.max_fit),name:n.display_name,memory:n.memory_source})})]}),f&&P(`span`,{className:`settings-hint`,children:t(`settings.ctx.loadedAt`,{size:Cs(n.loaded_ctx)})}),o&&V(`span`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.ctx.applying`)]}),c&&P(`p`,{className:`settings-ok`,role:`status`,children:c}),i&&P(`p`,{className:`settings-error`,role:`alert`,children:i})]})}function rP({row:e,providerName:t,choices:n,labels:r,disabled:i,onSwitch:a}){let o=T(),s=cs(e=>e.active),c=s?.model??null,l=!!s?.remote,u=n.some(e=>us(c,e.id)),d=s?.downloaded??e?.downloaded,f=l?null:e?.state===`loaded`?o(`settings.model.loaded`):d===!0?o(`settings.model.downloaded`):d===!1?o(`settings.model.notDownloaded`):null,p=e?.placement?.device;return V(`section`,{className:`settings-card model-in-use`,"aria-label":o(`settings.model.inUseTitle`),children:[P(`span`,{className:`model-in-use-label`,children:o(`settings.model.inUseTitle`)}),c?P(`bdi`,{className:`model-in-use-name`,title:c,children:e?.display_name||s?.display_name||ds(c)}):P(`span`,{className:`settings-hint`,children:o(`settings.model.noneInUse`)}),s?.config_error&&P(`p`,{className:`settings-error`,role:`alert`,children:P(`bdi`,{children:s.config_error})}),c&&!l&&e?.available===!1&&P(`p`,{className:`settings-error`,role:`alert`,children:o(`settings.model.inUseCantRun`)}),c&&V(`span`,{className:`model-chips`,children:[l&&P(`span`,{className:`model-badge is-device`,children:o(`settings.model.cloud`)}),l&&t&&P(`bdi`,{className:`model-badge is-ready`,children:t}),p&&P(`span`,{className:`model-badge is-device`,children:p.toUpperCase()}),f&&P(`span`,{className:`model-badge ${e?.state===`loaded`?`is-loaded`:`is-ready`}`,children:f}),e?.fits===!0&&P(`span`,{className:`model-badge is-fit`,children:o(`settings.model.fits`)}),!!e?.size_gb&&V(`bdi`,{dir:`ltr`,className:`model-badge is-size`,children:[e.size_gb,` GB`]}),l&&!!e?.context_length&&P(`span`,{className:`model-badge is-ready`,children:o(`settings.model.contextChip`,{size:Cs(e.context_length)})})]}),(n.length>1||n.length===1&&!u)&&V(`div`,{className:`model-in-use-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`model-switch`,children:o(`settings.model.switch`)}),V(`select`,{id:`model-switch`,className:`settings-input`,value:u?n.find(e=>us(c,e.id))?.id:``,onChange:e=>a(e.target.value),disabled:i,children:[!u&&P(`option`,{value:``,disabled:!0,children:o.bare(`settings.model.switchPlaceholder`)}),n.map(e=>P(`option`,{value:e.id,children:r[e.id]},e.id))]})]}),c&&!l&&s?.downloaded!==!1&&P(nP,{model:c})]})}function iP({model:e,label:t,current:n,remote:r,busy:i,confirmingRemove:a,onUse:o,onDownload:s,onAskRemove:c,onKeep:l,onRemove:u,onNpuRecheck:d}){let f=T(),p=Ts(e)?e.download_progress:null,m=e.placement?.label,h=f.compose(t=>[m&&(e.placement?.source===`expected`?t(`settings.model.expected`,{label:m}):m),e.size_gb?t(e.downloaded?`settings.model.sizeOnDisk`:`settings.model.sizeDownload`,{size:`${e.size_gb} GB`}):null,e.tokens_per_second?t(`settings.model.speed`,{speed:`${Math.round(e.tokens_per_second)} tok/s`}):null,!e.placement&&e.context_length?t(`settings.model.contextTokens`,{size:e.context_length.toLocaleString()}):null].filter(Boolean).join(` · `)),g=!!(e.display_name||h||e.evidence||e.custom&&e.source_url);return V(`li`,{className:`model-row${n?` is-current`:``}`,children:[V(`div`,{className:`model-row-text`,children:[P(`bdi`,{className:`model-row-name`,title:e.id,children:t}),V(`div`,{className:`model-chips`,children:[e.placement?.device&&P(`span`,{className:`model-badge is-device`,children:e.placement.device.toUpperCase()}),e.rank&&V(`span`,{className:`model-badge is-rank`,children:[V(`bdi`,{dir:`ltr`,children:[`#`,e.rank]}),` `,e.note]}),e.state===`loaded`&&P(`span`,{className:`model-badge is-loaded`,children:f(`settings.model.loaded`)}),e.fits===!0&&e.available!==!1&&P(`span`,{className:`model-badge is-fit`,children:f(`settings.model.fits`)}),e.custom&&P(`span`,{className:`model-badge is-custom`,children:f(`settings.model.custom`)}),!!e.size_gb&&V(`bdi`,{dir:`ltr`,className:`model-badge is-size`,children:[e.size_gb,` GB`]}),g&&V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,f(`settings.model.details`)]}),e.display_name&&P(`span`,{className:`model-row-meta`,children:P(`bdi`,{children:e.id})}),h&&P(`span`,{className:`model-row-meta`,children:h}),e.evidence&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.measured`,{evidence:e.evidence})}),e.custom&&e.source_url&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.from`,{url:e.source_url})})]})]}),r&&P(`span`,{className:`model-row-meta${e.price?``:` is-unknown-price`}`,children:QT(e.price,f)}),e.placement?.warning&&P(`span`,{className:`model-row-meta is-warning`,role:`alert`,children:P(`bdi`,{children:e.placement.warning})}),e.npu_problems?.length?P(PM,{problems:e.npu_problems,disabled:i!==null,onRecheck:d,id:`npu-problems-${e.id}`}):e.unavailable_reason&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.cantRun`,{reason:e.unavailable_reason})}),p&&P(`progress`,{max:100,value:p.percent,"aria-label":f(`settings.model.downloadingAria`,{name:t})})]}),V(`div`,{className:`model-row-actions`,children:[e.custom&&!n&&!p&&(a?V(D.Fragment,{children:[V(`button`,{type:`button`,className:`btn-danger`,onClick:u,disabled:i!==null,children:[i===`rm:${e.id}`?P(q,{size:13,className:`spin`}):null,e.downloaded?f(`settings.model.removeDownload`):f(`settings.models.remove`)]}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:l,disabled:i!==null,children:f(`settings.models.keep`)})]}):P(`button`,{type:`button`,className:`btn-secondary`,onClick:c,disabled:i!==null,"aria-label":f(`settings.models.removeAria`,{name:t}),children:f(`settings.models.remove`)})),n&&e.available===!1?P(`span`,{className:`model-row-current is-blocked`,children:f(`settings.model.inUseBlocked`)}):n?V(`span`,{className:`model-row-current`,children:[P(mr,{size:13,"aria-hidden":`true`}),` `,f(`settings.model.inUse`)]}):e.available===!1?null:p?V(`span`,{className:`model-row-current`,children:[P(q,{size:13,className:`spin`}),` `,p.message?P(`bdi`,{children:p.message}):V(`bdi`,{dir:`ltr`,children:[Math.round(p.percent),`%`]})]}):e.downloaded?V(`button`,{type:`button`,className:`btn-secondary`,onClick:o,disabled:i!==null,"aria-label":f(`settings.model.useAria`,{name:t}),children:[i===e.id?P(q,{size:13,className:`spin`}):null,` `,f(`settings.model.use`)]}):V(`button`,{type:`button`,className:`btn-secondary`,onClick:s,disabled:i!==null,"aria-label":f(`settings.model.downloadAria`,{name:t}),children:[i===`dl:${e.id}`?P(q,{size:13,className:`spin`}):null,` `,f(`settings.model.download`)]})]})]})}function aP(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(!1),l=(0,X.useCallback)(async e=>{c(!0),i(null);try{let t=await e();n(t),o(t.limit_usd==null?``:String(t.limit_usd))}catch(e){i(e instanceof Error?e.message:String(e))}finally{c(!1)}},[]);if((0,X.useEffect)(()=>{l(H)},[l]),!t)return r?P(`p`,{className:`settings-error`,role:`alert`,children:r}):V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.spend.loading`)]});let u=t.limit_usd,d=a.trim()===``?null:Number(a),f=d===null||Number.isFinite(d)&&d>0,p=d!==u;return V(`section`,{className:`settings-field spending`,"aria-label":e(`settings.spend.aria`),children:[P(`span`,{className:`settings-label`,children:e(`settings.spend.title`)}),V(`p`,{className:`spending-total`,children:[P(`bdi`,{dir:`ltr`,children:P(`strong`,{children:$T(t.total_usd)})}),u!=null&&V(D.Fragment,{children:[` `,e(`settings.spend.ofLimit`,{limit:$T(u)})]}),V(`span`,{className:`settings-hint`,children:[` · `,e.plural(`settings.spend.turns`,t.turns)]})]}),t.unpriced_turns>0&&P(`p`,{className:`settings-hint`,children:e.plural(`settings.spend.unpriced`,t.unpriced_turns)}),t.unreported_turns>0&&P(`p`,{className:`settings-hint`,children:e.plural(`settings.spend.unreported`,t.unreported_turns)}),t.state===`near`&&V(`p`,{className:`spending-warning`,role:`status`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.near`)]}),t.state===`reached`&&V(`div`,{className:`spending-warning`,role:`alert`,children:[V(`p`,{children:[P(J,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.reached`)]}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void l(gn),children:e(`settings.spend.allow`)})]}),t.state===`allowed_over`&&P(`p`,{className:`settings-hint`,children:e(`settings.spend.allowed`)}),V(`form`,{className:`settings-row`,onSubmit:e=>{e.preventDefault(),f&&p&&l(()=>Qe(d))},children:[P(`label`,{className:`spending-limit-label`,htmlFor:`spend-limit`,children:e(`settings.spend.limit`)}),P(`input`,{id:`spend-limit`,className:`settings-input`,type:`number`,min:`0.01`,step:`0.01`,inputMode:`decimal`,placeholder:e.bare(`settings.spend.noLimit`),value:a,onChange:e=>o(e.target.value),"aria-invalid":!f}),V(`button`,{type:`submit`,className:`btn-secondary`,disabled:s||!f||!p,children:[s?P(q,{size:13,className:`spin`}):null,` `,e(`settings.advanced.save`)]}),u!=null&&P(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void l(()=>Qe(null)),children:e(`settings.spend.removeLimit`)})]}),P(`span`,{className:`settings-hint`,children:e(`settings.spend.how`)}),r&&P(`p`,{className:`settings-error`,role:`alert`,children:r})]})}var oP=2e3;function sP(e,t){return e.key_source===`environment`?t(`settings.key.setIn`,{name:e.env_var??``}):`••••••••••••••••••••${e.key_hint?` ${e.key_hint}`:``}`}function cP(){let e=T(),t=cs(e=>e.active),n=cs(e=>e.select),r=cs(e=>e.refresh),i=cs(e=>e.rememberNames),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),l=k(e=>e.settingsProvider),[u,d]=(0,X.useState)(l??t?.provider??`local`),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(!1),[w,E]=(0,X.useState)(!1),[O,A]=(0,X.useState)({base_url:``,auth_header_name:``,auth_header_prefix:``}),[j,M]=(0,X.useState)(null),[N,F]=(0,X.useState)(null),[I,L]=(0,X.useState)(null),[ee,R]=(0,X.useState)(null),[z,B]=(0,X.useState)(!1),[te,ne]=(0,X.useState)(null),[re,ie]=(0,X.useState)(null),ae=(0,X.useRef)(u);ae.current=u;let oe=(0,X.useRef)(!0);(0,X.useEffect)(()=>(oe.current=!0,()=>{oe.current=!1}),[]);let H=a?.find(e=>e.id===u)??null,U=e=>e?.network?.reachable===!1,se=e=>!!e?.blocked,W=!!H&&!se(H)&&(!H.remote||!!H.models_discovered),G=(0,X.useCallback)(async()=>{c(null);try{let e=await Tn();o(e.providers),e.lemonade_error&&c(e.lemonade_error)}catch(e){c(e instanceof Error?e.message:String(e))}},[]),ce=(0,X.useCallback)(async(t,n=!1)=>{n||(p(null),h(null));try{let n=await Zt(t);i(n.models),p(n.models),F(n.memory_gb?`${n.memory_gb} GB (${n.memory_source})`:n.capacity_error??null),n.blocked&&h(e(`settings.privacy.localOnlyBlocked`))}catch(e){h(e instanceof Error?e.message:String(e))}},[i,e]);(0,X.useEffect)(()=>{G()},[G]);let le=!!a?.some(e=>e.key_state===`waiting_for_os_permission`);(0,X.useEffect)(()=>{if(!le)return;let e=setInterval(()=>{G()},oP);return()=>clearInterval(e)},[le,G]);let ue=t?.provider;(0,X.useEffect)(()=>{ue&&!l&&d(ue)},[ue,l]),(0,X.useEffect)(()=>{x(``),C(!1),E(!1),L(null),_(``),y(!1),B(!1)},[u]),(0,X.useEffect)(()=>{W?ce(u):p(null)},[u,W,ce]);let de=(0,X.useCallback)(async()=>{if(H){M(`connect`),L(null);try{let t=u===`amd`?{api_key:b||void 0,...Object.fromEntries(Object.entries(O).filter(([,e])=>e!==``))}:{api_key:b||void 0},n=()=>!oe.current||ae.current!==u,r=await Rt(u,t,e=>{n()||L({ok:!0,text:e})},n);if(n())return;x(``),C(!1),L({ok:!0,text:r.remember_error?e(`settings.key.sessionOnly`,{reason:r.remember_error}):r.known_models?e(`settings.key.knownModels`,{name:H.name}):r.remembered?e(`settings.key.kept`):e(`settings.key.connectedDone`)}),await G()}catch(e){oe.current&&ae.current===u&&L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{oe.current&&M(null)}}},[O,u,b,G,H,e]),pe=(0,X.useCallback)(async()=>{M(`forget`),E(!1),L(null);try{await Kt(u),L({ok:!0,text:e(`settings.key.cleared`)}),await G(),await r()}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[u,G,r,e]),me=(0,X.useCallback)(async t=>{M(t),L(null);try{await n(t),L({ok:!0,text:e(`settings.model.switched`,{name:ds(t)})}),await ce(u,!0)}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[u,ce,n,e]),he=(0,X.useCallback)(async e=>{M(`dl:${e}`),L(null),B(!1);try{await fe(e),await ce(`local`,!0)}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[ce]),ge=(0,X.useCallback)(async t=>{M(`rm:${t}`),L(null);try{let n=await nt(t);R(null);let i=n.cleared.includes(`last_model`)?`settings.model.removedLast`:n.cleared.includes(`default_model`)?`settings.model.removedDefault`:`settings.model.removed`;L({ok:!0,text:e(i,{name:n.display_name})}),await ce(`local`,!0),await r()}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[ce,r,e]),_e=(0,X.useCallback)(async t=>{L({ok:!0,text:e(`settings.model.added`,{name:t})}),B(!0),await ce(`local`,!0)},[ce,e]),ve=!!f?.some(Ts);(0,X.useEffect)(()=>{if(ve)return()=>{r()}},[ve,r]),(0,X.useEffect)(()=>{if(u!==`local`||!ve)return;let e=setInterval(()=>{ce(`local`,!0)},oP);return()=>clearInterval(e)},[ve,u,ce]);let ye=t?.model,be=f?.find(e=>us(ye,e.id));(0,X.useEffect)(()=>{be&&ne(be)},[be]);let xe=(0,X.useMemo)(()=>{let e=g.trim().toLowerCase();return(f??[]).filter(t=>!e||t.id.toLowerCase().includes(e)||(t.display_name??``).toLowerCase().includes(e))},[f,g]),Se=xe.filter(e=>e.available!==!1),Ce=u===`fireworks`&&!v&&!g.trim()&&Se.some(e=>e.rank!==null),we=e=>e.rank!==null||e.id===t?.model,Te=Ce?Se.filter(we):Se,Ee=Ce?Se.filter(e=>!we(e)):[],De=xe.filter(e=>e.available===!1),Oe=ys(f??[]),ke=!!g.trim(),Ae=e=>us(t?.model,e.id),je=H?.id===`local`,Me=Te.filter(e=>e.downloaded).sort((e,t)=>Number(Ae(t))-Number(Ae(e))),Ne=Te.filter(e=>!e.downloaded),Pe=(f??[]).filter(e=>e.available!==!1&&e.downloaded),Fe=Pe.filter(we),Ie=u===`fireworks`&&Fe.some(e=>e.rank!==null)?Fe:Pe,Le=e=>P(iP,{model:e,label:Oe[e.id],current:Ae(e),remote:!!H?.remote,busy:j,confirmingRemove:ee===e.id,onUse:()=>void me(e.id),onDownload:()=>void he(e.id),onAskRemove:()=>R(e.id),onKeep:()=>R(null),onRemove:()=>void ge(e.id),onNpuRecheck:()=>void ce(u,!0)},e.id);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.model`)}),P(rP,{row:be??(us(te?.id,t?.model)?te:null),providerName:a?.find(e=>e.id===t?.provider)?.name??null,choices:W?Ie:[],labels:Oe,disabled:j!==null,onSwitch:e=>void me(e)}),P(`div`,{className:`provider-tabs`,role:`radiogroup`,"aria-label":e(`settings.model.whereRuns`),children:(a??[{id:`local`,name:`Local`,remote:!1}]).map(t=>V(`button`,{type:`button`,role:`radio`,"aria-checked":u===t.id,className:`provider-tab${u===t.id?` is-active`:``}${U(t)||se(t)?` is-disabled`:``}`,onClick:()=>d(t.id),disabled:(U(t)||se(t))&&u!==t.id,title:se(t)?e(`settings.privacy.localOnlyBlocked`):U(t)?t.network?.detail??void 0:void 0,children:[t.remote?P(Ir,{size:14,"aria-hidden":`true`}):P(Wr,{size:14,"aria-hidden":`true`}),P(`span`,{children:t.name}),t.remote&&t.models_discovered&&P(`span`,{className:`provider-tab-dot`,"aria-label":e(`settings.key.connectedDot`)})]},t.id))}),s&&P(XN,{message:s,onRetry:()=>{G(),ce(u)}}),H&&V(`section`,{className:`settings-card`,"aria-label":H.name,children:[H.remote&&P(`p`,{className:`settings-note`,children:P(`bdi`,{children:H.privacy_notice})}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,e(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:e(`settings.model.lede`)}),je&&P(`p`,{className:`settings-hint`,children:P(`bdi`,{children:H.privacy_notice})}),je&&P(`p`,{className:`settings-hint`,children:e(`settings.model.devices`)}),je&&N&&P(`p`,{className:`settings-hint`,children:e(`settings.model.memory`,{memory:N})})]}),H.remote&&!W&&V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,children:e(`settings.model.prices`)}),P(WA,{provider:H.id})]}),se(H)&&P(`div`,{className:`settings-field`,children:P(`p`,{className:`settings-error`,role:`alert`,children:e(`settings.privacy.localOnlyBlocked`)})}),U(H)&&V(`div`,{className:`settings-field`,children:[P(`p`,{className:`settings-error`,role:`alert`,children:H.network?.detail}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void G(),children:e(`settings.key.checkAgain`)})]}),H.remote&&!U(H)&&!se(H)&&V(`form`,{className:`settings-field`,onSubmit:e=>{e.preventDefault(),de()},children:[V(`div`,{className:`settings-row settings-row-between`,children:[P(`span`,{className:`settings-label`,children:e(`settings.key.title`)}),H.key_source&&P(`span`,{className:`settings-key-status ${W?`settings-ok`:`settings-error`}`,children:e(W?`settings.key.connected`:`settings.key.notConnected`)})]}),!H.key_source&&P(`span`,{className:`settings-hint`,children:H.key_state===`waiting_for_os_permission`?H.key_message??e(`settings.key.waitingOs`):e(`settings.key.none`)}),H.id===`amd`&&(!H.key_source||S)&&V(`div`,{className:`settings-grid`,children:[P(`input`,{className:`settings-input`,placeholder:e(`settings.key.gatewayPlaceholder`),value:O.base_url,onChange:e=>A({...O,base_url:e.target.value}),"aria-label":e(`settings.key.gatewayUrl`)}),P(`input`,{className:`settings-input`,placeholder:e(`settings.key.headerPlaceholder`),value:O.auth_header_name,onChange:e=>A({...O,auth_header_name:e.target.value}),"aria-label":e(`settings.key.headerName`)})]}),H.key_source&&!S?V(`div`,{className:`settings-row`,children:[P(`input`,{className:`settings-input settings-key-masked`,readOnly:!0,value:sP(H,e),"aria-label":e(`settings.key.savedAria`,{name:H.name})}),!W&&V(`button`,{type:`submit`,className:`btn-primary`,disabled:j!==null,children:[j===`connect`?P(q,{size:13,className:`spin`}):null,e(`settings.key.reconnect`)]}),(H.key_source!==`environment`||H.key_from_gaia_env)&&(w?V(D.Fragment,{children:[P(`span`,{className:`settings-hint`,children:e(`settings.key.removeAsk`)}),P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void pe(),disabled:j!==null,children:e(`settings.models.remove`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>E(!1),children:e(`settings.models.keep`)})]}):V(D.Fragment,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>C(!0),disabled:j!==null,children:e(`settings.key.replace`)}),H.key_source!==`environment`&&P(`button`,{type:`button`,className:`btn-secondary settings-key-remove`,onClick:()=>E(!0),disabled:j!==null,"aria-label":e(`settings.key.remove`),title:e(`settings.key.remove`),children:P(lo,{size:14,"aria-hidden":`true`})})]}))]}):V(`div`,{className:`settings-row`,children:[P(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,spellCheck:!1,autoFocus:S,value:b,onChange:e=>x(e.target.value),placeholder:e(S?`settings.key.pasteNew`:`settings.key.paste`),"aria-label":e(`settings.key.fieldAria`,{name:H.name})}),V(`button`,{type:`submit`,className:`btn-primary`,disabled:j!==null||!b,children:[j===`connect`?P(q,{size:13,className:`spin`}):null,e(S?`settings.key.save`:`settings.key.connect`)]}),S&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{x(``),C(!1)},disabled:j!==null,children:e(`settings.key.cancel`)})]}),H.key_source&&!W&&!H.error&&!S&&P(`p`,{className:`settings-hint`,children:e(`settings.key.notConnectedHint`,{name:H.name})}),H.error&&P(`p`,{className:`settings-error`,role:`alert`,children:H.error})]}),I?.ok&&P(`p`,{className:`settings-ok`,role:`status`,children:I.text}),I&&!I.ok&&P(XN,{message:I.text}),H.known_models&&P(`p`,{className:`settings-hint`,role:`status`,children:e(`settings.key.knownList`,{name:H.name})}),je&&P(`div`,{className:`models-downloads-slot`,ref:ie}),W&&V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,children:e(`settings.model.models`)}),(f?.length??0)>6&&P(`input`,{className:`settings-input`,type:`search`,value:g,onChange:e=>_(e.target.value),placeholder:e(`settings.model.search`),"aria-label":e(`settings.model.search`)}),m&&!(s&&KN(m))&&P(XN,{message:m}),!f&&!m&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.loading`)]}),f&&xe.length===0&&!m&&P(`p`,{className:`settings-hint`,children:e(ke||!je?`settings.model.noMatch`:`settings.model.noModels`)}),je?V(D.Fragment,{children:[Me.length>0&&P(SN,{title:e(`settings.model.groupDownloaded`),count:Me.length,defaultOpen:!0,forceOpen:ke,children:P(`ul`,{className:`model-list`,children:Me.map(Le)})}),Ne.length>0&&P(SN,{title:e(`settings.model.groupAvailable`),count:Ne.length,defaultOpen:Me.length===0,forceOpen:ke||z||Ne.some(Ts),children:P(`ul`,{className:`model-list`,children:Ne.map(Le)})})]}):P(`ul`,{className:`model-list`,children:Te.map(Le)}),Ce&&Ee.length>0&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>y(!0),children:e(`settings.model.showAll`)}),u===`fireworks`&&v&&!ke&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>y(!1),children:e(`settings.model.showRecommended`)}),De.length>0&&P(SN,{title:e(`settings.model.groupUnavailable`),count:De.length,forceOpen:ke,children:P(`ul`,{className:`model-list`,children:De.map(Le)})})]}),je&&W&&P(SN,{title:e(`settings.custom.title`),children:P(ZN,{onAdded:e=>void _e(e)})}),je&&W&&P(eP,{downloadsSlot:re}),H.remote&&P(aP,{})]})]})}function lP(){let e=T(),t=k(e=>e.sessions),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null),u=(0,X.useCallback)(async()=>{l(null);try{let e=await on();r(e.sessions),a(e.default_mode),k.getState().setDefaultPermissionMode(e.default_mode)}catch(e){l(e instanceof Error?e.message:String(e))}},[]);(0,X.useEffect)(()=>{u()},[u]);let d=(0,X.useCallback)(async e=>{l(null);try{await e(),await u()}catch(e){l(e instanceof Error?e.message:String(e))}},[u]),f=(0,X.useCallback)(async e=>{s(!1),await d(()=>kt(e))},[d]),p=()=>{i===`full_access`?f(`ask`):s(e=>!e)},m=e=>t.find(t=>t.id===e)?.title??e;return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.permissions`)}),P(`p`,{className:`settings-pane-lede`,children:e(`settings.permissions.lede`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,e(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:e(`settings.permissions.perChat`)})]}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.permissions.newChats`),children:[V(`label`,{className:`setting-row`,children:[P(`span`,{className:`settings-label`,children:e(`settings.permissions.fullAccess`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:i===`full_access`,onChange:p,disabled:i===null,"aria-label":e(`settings.permissions.fullAccess`)}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,children:e(i===`full_access`?`settings.permissions.on`:`settings.permissions.off`)}),o&&V(`div`,{className:`settings-warning`,role:`alert`,children:[P(`p`,{children:e(`settings.permissions.warning`)}),V(`div`,{className:`settings-row`,children:[P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void f(`full_access`),children:e(`settings.permissions.turnOn`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>s(!1),children:e(`settings.key.cancel`)})]})]})]}),c&&P(`p`,{className:`settings-error`,role:`alert`,children:c}),n&&n.length===0&&P(`p`,{className:`settings-hint`,children:e(`settings.permissions.none`)}),!!n?.length&&P(SN,{title:e(`settings.permissions.chats`),count:n.length,defaultOpen:!0,children:n.map(t=>V(`section`,{className:`settings-field permission-chat`,"aria-label":m(t.session_id),children:[V(`div`,{className:`settings-row settings-row-between`,children:[P(`bdi`,{className:`settings-label`,children:m(t.session_id)}),t.mode===`full_access`&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>d(async()=>{let e=(await Pt(t.session_id,`ask`)).mode;yE(t.session_id,e)}),children:e(`settings.permissions.turnOff`)})]}),t.grants.length>0&&P(`ul`,{className:`grant-list`,children:t.grants.map(n=>V(`li`,{className:`grant-row`,children:[P(`code`,{children:n.label}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>d(()=>Xt(t.session_id,n.key)),"aria-label":e(`settings.permissions.revokeAria`,{name:n.label}),children:e(`settings.permissions.revoke`)})]},n.key))}),t.grants.length>1&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>d(()=>Xt(t.session_id)),children:e(`settings.permissions.revokeAll`)})]},t.session_id))})]})}var uP={path:`~/.gaia/skills`},dP=[{source:`agent-bundled`,title:`settings.skills.bundled`,note:`settings.skills.bundledNote`},{source:`user`,title:`settings.skills.yours`,note:`settings.skills.yoursNote`,empty:`settings.skills.yoursEmpty`,params:uP},{source:`claude-project`,title:`settings.skills.project`,note:`settings.skills.projectNote`,params:{path:`.claude/skills`}},{source:`claude-import`,title:`settings.skills.import`,note:`settings.skills.importNote`}];function fP({onUseSkill:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)({}),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(``);(0,X.useEffect)(()=>{let e=!1;return ln().then(t=>{e||(r(t.skills),a(t.invalid))}).catch(t=>{e||s(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let u=c.trim().toLowerCase(),d=(n??[]).filter(e=>!u||e.name.toLowerCase().includes(u)||e.description.toLowerCase().includes(u)),f=n?.every(e=>dP.some(t=>t.source===e.source))??!1,p=n=>V(`li`,{className:`skill-row`,children:[V(`div`,{className:`skill-row-text`,children:[V(`span`,{className:`skill-row-name`,children:[n.name,n.version&&V(`span`,{className:`skill-row-meta`,children:[` v`,n.version]}),n.always_on&&V(`span`,{className:`skill-row-meta`,children:[` · `,t(`settings.skills.alwaysOn`)]})]}),P(`span`,{className:`skill-row-desc`,children:P(`bdi`,{children:n.description})})]}),!n.always_on&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>e(n.name),"aria-label":t(`settings.skills.useAria`,{name:n.name}),children:t(`settings.model.use`)})]},n.name);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:t(`settings.section.skills`)}),P(`p`,{className:`settings-pane-lede`,children:t(`settings.skills.lede`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:t(`settings.skills.how`,uP)})]}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o}),!n&&!o&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),n&&n.length>6&&P(`input`,{className:`settings-input`,type:`search`,value:c,onChange:e=>l(e.target.value),placeholder:t(`settings.skills.search`),"aria-label":t(`settings.skills.search`)}),n&&n.length===0&&P(`p`,{className:`settings-hint`,children:t(`settings.skills.none`)}),f?dP.map(e=>{let r=d.filter(t=>t.source===e.source),i=(n??[]).filter(t=>t.source===e.source).length;return r.length===0&&(u||!e.empty)?null:P(SN,{title:t(e.title),count:i,hint:t(e.note,e.params),defaultOpen:e.source===`user`,forceOpen:!!u,children:P(`section`,{"aria-label":t(e.title),children:r.length===0?P(`p`,{className:`settings-hint`,children:e.empty&&t(e.empty,e.params)}):P(`ul`,{className:`skill-list`,children:r.map(p)})})},e.source)}):P(`ul`,{className:`skill-list`,children:d.map(p)}),Object.keys(i).length>0&&V(`div`,{className:`settings-card`,role:`alert`,children:[P(`span`,{className:`settings-label`,children:t(`settings.skills.skipped`)}),P(`ul`,{className:`grant-list`,children:Object.entries(i).map(([e,t])=>V(`li`,{children:[P(`bdi`,{dir:`ltr`,children:P(`code`,{children:e})}),` — `,P(`bdi`,{children:t})]},e))})]})]})}function pP(){let e=T(),t=k(e=>e.setShowMemoryDashboard),n=k(e=>e.closeSettings),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1);(0,X.useEffect)(()=>{pA().then(i).catch(e=>o(e instanceof Error?e.message:String(e)))},[]);let l=(0,X.useCallback)(async()=>{if(r){c(!0),o(null);try{i(await mA({memory_enabled:!r.memory_enabled}))}catch(e){o(e instanceof Error?e.message:String(e))}finally{c(!1)}}},[r]);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.memory`)}),P(`p`,{className:`settings-pane-lede`,children:e(`settings.memory.lede`)}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.section.memory`),children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.memory.remember`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:!!r?.memory_enabled,onChange:()=>void l(),disabled:!r||s,"aria-label":e(`settings.memory.remember`)}),P(`span`,{className:`toggle-track`})]})]}),a&&P(`p`,{className:`settings-error`,role:`alert`,children:a}),V(`div`,{className:`settings-row settings-row-between`,children:[P(`span`,{className:`settings-hint`,children:e(`settings.memory.dashboardHint`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{n(),t(!0)},children:e(`settings.memory.dashboard`)})]})]})]})}function mP(e,t,n){if(!/^\d+$/.test(e.trim()))return!1;let r=Number(e);return r>=t&&r<=n}function hP(e){return e<1048576?`${Math.ceil(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}function gP(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1);(0,X.useEffect)(()=>{hn().then(e=>{n(e),i(String(e.retention_days)),o(String(e.max_mb))},t=>c({ok:!1,text:e(`settings.undo.readFailed`,{reason:t instanceof Error?t.message:String(t)})}))},[e]);let[d,f]=(0,X.useState)({days:!1,mb:!1}),p=!mP(r,1,365)||d.days,m=!mP(a,10,1e5)||d.mb,h=t!==null&&(r!==String(t.retention_days)||a!==String(t.max_mb)),g=async()=>{if(!(p||m)){u(!0),c(null);try{let t=await fn(Number(r),Number(a));n(t),c({ok:!0,text:e(`settings.undo.saved`)})}catch(t){let n=t instanceof yn&&t.httpStatus===422?t.fields:[],r=n.includes(`retention_days`),i=n.includes(`max_mb`);r||i?(f({days:r,mb:i}),c({ok:!1,text:e(`settings.undo.fix`)})):c({ok:!1,text:t instanceof Error?t.message:String(t)})}finally{u(!1)}}};return V(`div`,{className:`settings-field`,"aria-label":e(`settings.privacy.undo`),children:[P(`span`,{className:`settings-label`,children:e(`settings.privacy.undo`)}),P(`p`,{className:`settings-hint`,children:e(`settings.undo.hint`)}),t&&V(D.Fragment,{children:[V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`undo-days`,children:e(`settings.undo.days`)}),P(`input`,{id:`undo-days`,type:`number`,className:`model-input undo-history-input`,min:1,max:365,value:r,"aria-invalid":p,"aria-describedby":p?`undo-days-error`:void 0,onChange:e=>{i(e.target.value),f(e=>({...e,days:!1}))}})]}),p&&P(`p`,{id:`undo-days-error`,className:`settings-error`,children:e(`settings.undo.daysError`)}),V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`undo-mb`,children:e(`settings.undo.mb`)}),P(`input`,{id:`undo-mb`,type:`number`,className:`model-input undo-history-input`,min:10,max:1e5,value:a,"aria-invalid":m,"aria-describedby":m?`undo-mb-error`:void 0,onChange:e=>{o(e.target.value),f(e=>({...e,mb:!1}))}})]}),m&&P(`p`,{id:`undo-mb-error`,className:`settings-error`,children:e(`settings.undo.mbError`)}),V(`div`,{className:`setting-row setting-row-path`,children:[P(`span`,{children:e(`settings.undo.inUse`)}),V(`span`,{children:[e.plural(`settings.undo.used`,t.turns,{size:hP(t.used_bytes)}),` `,P(`bdi`,{dir:`ltr`,children:P(`code`,{className:`setting-path`,children:t.path})})]})]}),P(`button`,{type:`button`,className:`btn-model-save`,onClick:()=>void g(),disabled:!h||l||p||m,children:e(l?`settings.models.applying`:`settings.advanced.save`)})]}),s&&P(`p`,{className:s.ok?`settings-ok`:`settings-error`,role:s.ok?`status`:`alert`,children:s.text})]})}var _P={root:`settings-report`,button:`btn-secondary`,hint:`settings-hint`,error:`settings-error`};function vP(){let e=T(),t=k(e=>e.sessions),n=k(e=>e.removeSession),r=hs(),i=k(e=>e.systemStatus?.data_dir),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),p=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]),(0,X.useEffect)(()=>{let e=!0;return qe().then(t=>{e&&u(t.network_policy===`local_ai_only`)}).catch(t=>{e&&c({ok:!1,text:t instanceof Error?t.message:String(t)})}),()=>{e=!1}},[]);let m=(0,X.useCallback)(async()=>{if(l===null||d)return;let t=l,n=!t;u(n),f(!0),c(null);try{let t=await Me({network_policy:n?`local_ai_only`:`cloud_allowed`});u(t.network_policy===`local_ai_only`);let r=t.policy_notices??[],i=r.some(e=>e.severity===`warning`),a=r.length?r.map(t=>t.code===`users_server_keeps_keys`?e(`settings.privacy.usersServerKeepsKeys`,{url:t.url??``}):t.code===`runtime_keys_not_dropped`?e(`settings.privacy.runtimeKeysNotDropped`,{reason:t.reason??``}):t.code===`saved_models_not_checked`?e(`settings.privacy.savedModelsNotChecked`,{reason:t.reason??``}):e(`settings.privacy.policyNoticeUnknown`)).join(` `):e(n?`settings.privacy.localOnlyOn`:`settings.privacy.localOnlyOff`);c({ok:!i,text:a})}catch(e){u(t),c({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{f(!1)}},[l,d,e]),h=(0,X.useCallback)(async()=>{if(!a){o(!0),p.current=setTimeout(()=>o(!1),4e3);return}o(!1);let r=[];for(let e of t)try{await de(e.id),n(e.id)}catch(t){r.push(`${e.title}: ${t instanceof Error?t.message:t}`)}c(r.length?{ok:!1,text:e(`settings.privacy.deleteFailed`,{n:r.length,reason:r.join(`; `)})}:{ok:!0,text:e(`settings.privacy.deleted`)})},[a,n,t,e]);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.privacy`)}),P(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.localOnlyTitle`),children:V(`div`,{className:`settings-row settings-row-between`,children:[V(`div`,{children:[P(`strong`,{children:e(`settings.privacy.localOnlyTitle`)}),P(`p`,{className:`settings-hint`,children:e(`settings.privacy.localOnlyHint`)})]}),P(`button`,{type:`button`,role:`switch`,"aria-checked":l===!0,"aria-label":e(`settings.privacy.localOnlyTitle`),className:l?`is-active`:``,onClick:()=>void m(),disabled:l===null||d,children:e(l?`settings.privacy.localOnlyOnLabel`:`settings.privacy.localOnlyOffLabel`)})]})}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.whereTitle`),children:[P(`p`,{className:`settings-note`,children:e(`settings.privacy.stays`)}),P(`p`,{className:r?.remote?`settings-note`:`settings-hint`,children:r?.remote?e(`settings.privacy.remote`,{name:r.label}):e(r?`settings.privacy.local`:`settings.privacy.unknown`)}),i&&V(`div`,{className:`setting-row setting-row-path`,children:[P(`span`,{children:e(`settings.privacy.dataFolder`)}),P(`bdi`,{dir:`ltr`,className:`setting-path`,children:i})]})]}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.reportTitle`),children:[P(`p`,{className:`settings-note`,children:e(`settings.privacy.reportNote`)}),P(rC,{classes:_P})]}),P(SN,{title:e(`settings.privacy.undo`),children:P(gP,{})}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.deleteTitle`),children:[P(`p`,{className:`danger-warning`,children:t.length===0?e(`settings.privacy.nothingToDelete`):e(`settings.privacy.deleteWarning`)}),P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void h(),disabled:t.length===0,children:e(a?`settings.privacy.deleteConfirm`:`settings.privacy.delete`)})]}),s&&P(`p`,{className:s.ok?`settings-ok`:`settings-error`,role:s.ok?`status`:`alert`,children:s.text})]})}var yP=[{id:`needs_approval`,label:`settings.alerts.approval`},{id:`question`,label:`settings.alerts.question`},{id:`finished`,label:`settings.alerts.finished`}],bP=[{value:`banner`,label:`settings.alerts.banner`},{value:`badge`,label:`settings.alerts.badge`},{value:`off`,label:`settings.alerts.off`}],xP=[0,10,20,30,50];function SP(){return typeof Notification>`u`?`unsupported`:Notification.permission}function CP(){let e=T(),t=lc(),n=!!window.gaiaAPI,[r,i]=(0,X.useState)(SP),a=Object.values(t.modes).includes(`banner`);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.notifications`)}),P(`p`,{className:`settings-pane-lede`,children:e(`settings.alerts.lede`)}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.alerts.when`),children:[yP.map(n=>V(`div`,{className:`setting-row`,children:[P(`span`,{id:`alert-${n.id}`,children:e(n.label)}),P(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`alert-${n.id}`,children:bP.map(r=>P(`button`,{type:`button`,role:`radio`,"aria-checked":t.modes[n.id]===r.value,className:t.modes[n.id]===r.value?`is-active`:``,onClick:()=>t.setMode(n.id,r.value),children:e(r.label)},r.value))})]},n.id)),!n&&a&&r!==`granted`&&(r==="default"?P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{Notification.requestPermission().then(i).catch(e=>{console.error(`[alerts] Notification permission request failed`,e),i(SP())})},children:e(`settings.alerts.allow`)}):P(`p`,{className:`settings-error`,role:`alert`,children:e(r===`unsupported`?`settings.alerts.unsupported`:`settings.alerts.blocked`)})),V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.alerts.sound`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.sound,onChange:()=>t.update({sound:!t.sound}),"aria-label":e(`settings.alerts.sound`)}),P(`span`,{className:`toggle-track`})]})]}),n&&V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.alerts.flash`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.flash,onChange:()=>t.update({flash:!t.flash}),"aria-label":e(`settings.alerts.flash`)}),P(`span`,{className:`toggle-track`})]})]})]}),V(`section`,{className:`settings-card`,"aria-labelledby":`keep-awake-title`,children:[P(`h3`,{className:`settings-label`,id:`keep-awake-title`,children:e(`settings.alerts.keepAwakeTitle`)}),n?V(D.Fragment,{children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.alerts.keepAwake`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.keepAwake,onChange:()=>t.update({keepAwake:!t.keepAwake}),"aria-label":e(`settings.alerts.keepAwake`)}),P(`span`,{className:`toggle-track`})]})]}),V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`battery-floor`,children:e(`settings.alerts.battery`)}),P(`select`,{id:`battery-floor`,className:`settings-input settings-select-compact`,value:t.batteryFloor,disabled:!t.keepAwake,onChange:e=>t.update({batteryFloor:Number(e.target.value)}),children:xP.map(t=>P(`option`,{value:t,children:t===0?e.bare(`settings.alerts.never`):`${t}%`},t))})]}),P(`p`,{className:`settings-hint`,children:e(`settings.alerts.screen`)})]}):P(`p`,{className:`settings-hint`,children:e(`settings.alerts.desktopOnly`)})]})]})}var wP=[50,75,100,125,150,175,200],TP=[{accent:`american`,gender:`female`},{accent:`american`,gender:`male`},{accent:`british`,gender:`female`},{accent:`british`,gender:`male`}],EP=`settings:preview`,DP=`Hello, I'm GAIA. This is how I'll read my replies to you.`;function OP(e){return e instanceof yn?e.detail||e.message:String(e)}function kP(){let e=T(),t=ES(e=>e.settings),n=ES(e=>e.setSettings),r=ES(e=>e.read),i=ES(e=>e.stop),a=ES(e=>e.messageId===EP),o=ES(e=>e.messageId===EP&&e.status===`loading`),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1);(0,X.useEffect)(()=>{pS().then(n).catch(e=>c(OP(e)))},[n]);let p=e=>{f(!0),u(null),ES.getState().messageId===EP&&i(),mS(e).then(n).catch(e=>u(OP(e))).finally(()=>f(!1))};return s?V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.voice`)}),P(`p`,{className:`settings-error`,role:`alert`,children:e(`readAloud.settings.loadFailed`,{reason:s})})]}):t?V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.voice`)}),P(`p`,{className:`settings-pane-lede`,children:e(`readAloud.settings.lede`)}),V(`div`,{className:`settings-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`read-aloud-voice`,children:e(`readAloud.settings.voice`)}),V(`div`,{className:`read-aloud-voice-row`,children:[P(`select`,{id:`read-aloud-voice`,className:`settings-input`,value:t.voice,disabled:d,onChange:e=>p({voice:e.target.value}),children:TP.map(n=>P(`optgroup`,{label:e(`readAloud.group.${n.accent}.${n.gender}`),children:t.voices.filter(e=>e.accent===n.accent&&e.gender===n.gender).map(e=>P(`option`,{value:e.id,lang:`en`,children:e.name},e.id))},`${n.accent}-${n.gender}`))}),V(`button`,{type:`button`,className:`btn-secondary`,"aria-pressed":a,disabled:d,onClick:()=>a?i():void r(EP,DP),children:[o?P(q,{size:13,className:`spin`}):P(a?ao:_o,{size:13}),e(a?`readAloud.stop`:`readAloud.settings.preview`)]})]}),P(`span`,{className:`settings-hint`,children:e(`readAloud.settings.englishOnly`)}),P(kS,{messageId:EP})]}),V(`div`,{className:`settings-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`read-aloud-speed`,children:e(`readAloud.settings.speed`)}),P(`select`,{id:`read-aloud-speed`,className:`settings-input`,value:t.speed,disabled:d,onChange:e=>p({speed:Number(e.target.value)}),children:(wP.includes(t.speed)?wP:[...wP,t.speed].sort((e,t)=>e-t)).map(t=>P(`option`,{value:t,children:t===100?e.bare(`readAloud.settings.normalSpeed`):`⁦${(t/100).toLocaleString(e.locale)}×⁩`},t))})]}),V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`readAloud.settings.auto`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.auto,disabled:d,onChange:()=>p({auto:!t.auto}),"aria-label":e(`readAloud.settings.auto`)}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,children:e(`readAloud.settings.shared`)}),l&&P(`p`,{className:`settings-error`,role:`alert`,children:e(`readAloud.settings.saveFailed`,{reason:l})})]}):V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.loading`)]})}function AP(){let e=T(),t=k(e=>e.openSettings),n=k(e=>e.closeSettings),r=k(e=>e.runSetupAgain),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1);(0,X.useEffect)(()=>{Ce().then(a).catch(e=>l(e instanceof Error?e.message:String(e))),ot().then(s).catch(e=>l(e instanceof Error?e.message:String(e)))},[]);let f=i?.catalog?.find(e=>e.id===i.chat_model.id),p=(i?.catalog??[]).filter(e=>e.downloaded),m=p.reduce((e,t)=>e+(t.full_size_gb??0),0),h=[o?.gpu_name,o?.npu_detected?e(`setup.checks.npu`):null].filter(Boolean).join(` · `),g=[{title:e(`settings.setup.where`),rows:[{label:e(`settings.setup.chatRuns`),value:f?.name??null,section:`model`},{label:e(`settings.setup.cloudKeys`),value:null,section:`model`}]},{title:e(`setup.pc.step`),rows:[{label:e(`settings.setup.detected`),value:[h,o?.ram_gb==null?null:`${o.ram_gb} GB`].filter(Boolean).join(` · `)||null,section:`advanced`},{label:e(`settings.setup.server`),value:i?.lemonade.mode===`external`?e(`settings.setup.serverYours`):e(`settings.setup.serverOwn`),section:`advanced`},{label:e(`setup.gpu.title`),value:null,section:`model`}]},{title:e(`setup.models.step`),rows:[{label:e(`settings.setup.models`),value:i?.catalog?e(`settings.setup.modelsValue`,{n:String(p.length),size:$(m)}):null,section:`model`},{label:e(`settings.setup.context`),value:null,section:`model`}]},{title:e(`settings.setup.after`),rows:[{label:e(`settings.section.connectors`),value:null,section:`connectors`},{label:e(`settings.section.memory`),value:null,section:`memory`},{label:e(`settings.language`),value:null,section:`general`},{label:e(`settings.setup.signIn`),value:null,section:`general`}]}];return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.setup`)}),P(`p`,{className:`settings-hint`,children:e(`settings.setup.lede`)}),V(`div`,{className:`settings-setup-status`,children:[V(`span`,{children:[P(`strong`,{children:e(`settings.setup.ready`)}),f&&V(`span`,{className:`settings-hint`,children:[` `,P(`bdi`,{children:e(`settings.setup.running`,{name:f.name})})]})]}),P(`button`,{type:`button`,className:`btn-secondary`,"data-testid":`setup-run-again`,onClick:()=>d(!0),children:e(`settings.setup.runAgain`)})]}),c&&P(`p`,{className:`setup-error`,role:`alert`,children:c}),g.map(e=>V(`section`,{className:`settings-setup-group`,"aria-label":e.title,children:[P(`h3`,{className:`settings-label`,children:e.title}),e.rows.map(e=>V(`button`,{type:`button`,className:`settings-setup-row`,onClick:()=>t(e.section),children:[V(`span`,{children:[P(`span`,{className:`settings-setup-row-label`,children:e.label}),e.value&&P(`bdi`,{className:`settings-hint settings-setup-row-value`,children:e.value})]}),P(br,{size:14,className:`settings-setup-chevron`,"aria-hidden":`true`})]},e.label))]},e.title)),u&&P(Kj,{title:e(`settings.setup.confirmTitle`),confirmLabel:e(`settings.setup.confirmYes`),cancelLabel:e(`setup.again.notNow`),onConfirm:()=>{d(!1),n(),r(!0)},onCancel:()=>d(!1),children:P(`p`,{children:e(`settings.setup.confirmBody`)})})]})}var jP=`modulepreload`,MP=function(e,t){return new URL(e,t).href},NP={},PP=function(e){return e.pathname.endsWith(`.css`)},FP=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},IP=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=MP(t,n);let r=s(t),i=PP(r);return FP(NP,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:jP,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},LP=(0,X.lazy)(()=>IP(()=>import(`./ConnectorsPane-C4Nf75r4.js`).then(e=>({default:e.ConnectorsPane})),__vite__mapDeps([0,1,2,3,4]),import.meta.url)),RP=(0,X.lazy)(()=>IP(()=>import(`./AdvancedSettings-BnWw0T2Y.js`).then(e=>({default:e.AdvancedSettings})),__vite__mapDeps([5,1,2,3]),import.meta.url)),zP=[`general`,`setup`,`model`,`permissions`,`skills`,`connectors`,`memory`,`notifications`,`voice`,`privacy`,`advanced`];function BP({onUseSkill:e}){let t=T(),n=k(e=>e.settingsSection),r=k(e=>e.openSettings),i=k(e=>e.closeSettings),a=(0,X.useRef)(null),o=n!==null;if(Io(o,i),sS(a,o),xN(a,o,()=>a.current?.querySelector(`.settings-nav-item.is-active`)),!n)return null;let s=(()=>{switch(n){case`general`:return P(GN,{});case`setup`:return P(AP,{});case`model`:return P(cP,{});case`permissions`:return P(lP,{});case`skills`:return P(fP,{onUseSkill:t=>{i(),e(t)}});case`connectors`:return P(LP,{});case`memory`:return P(pP,{});case`notifications`:return P(CP,{});case`voice`:return P(kP,{});case`privacy`:return P(vP,{});case`advanced`:return P(RP,{})}})();return P(`div`,{className:`settings-overlay`,onMouseDown:e=>{e.target===e.currentTarget&&i()},children:V(`div`,{ref:a,className:`settings-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`settings.title`),children:[V(`nav`,{className:`settings-nav`,"aria-label":t(`settings.sections`),children:[P(`h1`,{className:`settings-nav-title`,children:t(`settings.title`)}),zP.map(e=>P(`button`,{type:`button`,"data-section":e,className:`settings-nav-item${n===e?` is-active`:``}`,"aria-current":n===e?`page`:void 0,onClick:t=>{t.currentTarget.focus(),r(e)},children:t(`settings.section.${e}`)},e))]}),V(`div`,{className:`settings-body`,children:[P(`button`,{type:`button`,className:`settings-close`,onClick:i,"aria-label":t(`settings.close`),children:P(Y,{size:18})}),P(`div`,{className:`settings-scroll`,children:P(X.Suspense,{fallback:V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),children:s})})]})]})})}var VP=p((e,t)=>({lifecycle:null,restartError:null,apply:n=>{n.apiBase&&B(n.apiBase),e({lifecycle:n,restartError:n.status===`running`?null:t().restartError})},restart:async()=>{let n=window.gaiaAPI?.backend;if(!n)throw Error(`Restart GAIA needs the desktop app.`);e({restartError:null});try{t().apply(await n.restart())}catch(t){d.system.error(`Restart GAIA failed`,t),e({restartError:t instanceof Error?t.message:String(t)})}}}));function HP(e){let t=window.gaiaAPI?.backend;if(!t)return()=>{};let n=t=>{let n=VP.getState().lifecycle?.status;VP.getState().apply(t),t.status===`running`&&n&&n!==`running`&&e()},r=t.onState(n);return t.getState().then(n).catch(e=>d.system.error(`Could not read the backend state from the desktop app`,e)),r}function UP(e,t){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(null),c=(0,X.useRef)(null),l=(0,X.useRef)(null),u=(0,X.useRef)(null),f=(0,X.useCallback)(()=>{c.current&&=(clearTimeout(c.current),null),l.current&&=(clearTimeout(l.current),null),u.current&&=(clearInterval(u.current),null)},[]);(0,X.useEffect)(()=>f,[f]);let p=(0,X.useCallback)((e,t)=>{u.current&&clearInterval(u.current),u.current=setInterval(async()=>{try{let n=await Nt();t===`load`?n.model_loaded?.toLowerCase()===e.toLowerCase()&&(r(!1),c.current&&=(clearTimeout(c.current),null),u.current&&=(clearInterval(u.current),null)):(n.model_downloaded===!0||n.model_loaded?.toLowerCase()===e.toLowerCase())&&(a(!1),l.current&&=(clearTimeout(l.current),null),u.current&&=(clearInterval(u.current),null))}catch{}},Lc)},[]),m=e??`Gemma-4-E4B-it-GGUF`;return(0,X.useEffect)(()=>s(null),[m]),{isLoadingModel:n,isDownloadingModel:i,downloadError:o,loadModel:(0,X.useCallback)(async(e,t)=>{let n=e??m,i=t??32768;r(!0);try{if(!await zt(n,i)){r(!1);return}d.system.info(`Load model triggered: ${n} (ctx=${i})`),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>r(!1),Fc),p(n,`load`)}catch(e){d.system.error(`Failed to trigger model load`,e),r(!1)}},[m,t,p]),downloadModel:(0,X.useCallback)(async(e=!1,t,n=!1)=>{let r=t??m;a(!0),s(null);try{await fe(r,e,n),d.system.info(`Download model triggered: ${r} (force=${e})`),l.current&&clearTimeout(l.current),l.current=setTimeout(()=>a(!1),Ic),p(r,`download`)}catch(e){d.system.error(`Failed to trigger model download`,e),s(e instanceof Error?e.message:String(e)),a(!1)}},[m,p])}}function WP({onRetry:e,label:t,busyLabel:n=`Checking…`}){let[r,i]=(0,X.useState)(!1);return P(`button`,{className:`connection-banner__retry`,onClick:()=>{i(!0),Promise.resolve(e()).finally(()=>i(!1))},disabled:r,children:r?n:t})}function GP(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function KP({lifecycle:e}){let t=T(),n=VP(e=>e.restart),r=VP(e=>e.restartError),i=e.status===`restarting`,[a,o]=(0,X.useState)(()=>Date.now());if((0,X.useEffect)(()=>{if(!i)return;o(Date.now());let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[i]),i){let n=e.since?Math.max(0,Math.floor((a-e.since)/1e3)):0;return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t(`banner.restarting`),` `,P(`bdi`,{dir:`ltr`,className:`connection-banner__timer`,children:GP(n)}),` `,P(`span`,{className:`connection-banner__hint`,children:t(`banner.restartingHint`)})]})]})}return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t(`banner.restartStopped`),` `,P(`span`,{className:`connection-banner__hint`,children:r?t(`banner.restartFailed`,{error:r}):t(`banner.restartStoppedHint`)})]}),P(WP,{onRetry:n,label:t(`banner.restartButton`),busyLabel:t(`banner.restartingShort`)})]})}function qP({onRetry:e,backendSlow:t=!1,backendError:n=null}){let r=T(),{backendConnected:i,systemStatus:a,currentSessionId:o,messages:s}=k(),c=VP(e=>e.lifecycle),[l,u]=(0,X.useState)(!1),d=!!o&&s.length>0,f=a?.default_model_name??`Gemma-4-E4B-it-GGUF`,{isDownloadingModel:p,downloadError:m,downloadModel:h}=UP(f),g=cs(e=>e.pickLoad),_=cs(e=>e.retryPickLoad),v=cs(e=>e.dismissPickLoad);ls();let y=(0,X.useRef)(a?.lemonade_running),b=(0,X.useRef)(a?.model_downloaded),x=(0,X.useRef)(a?.context_size_sufficient),S=(0,X.useRef)(a?.expected_model_loaded);if((0,X.useEffect)(()=>{if(d)return;let e=a?.lemonade_running,t=a?.model_downloaded,n=a?.context_size_sufficient,r=a?.expected_model_loaded,i=!1;y.current!==e&&(y.current=e,e===!1&&(i=!0)),b.current!==t&&(b.current=t,t===!1&&(i=!0)),x.current!==n&&(x.current=n,n===!1&&(i=!0)),S.current!==r&&(S.current=r,r===!1&&(i=!0)),i&&u(!1)},[a,d]),c&&c.status!==`running`)return P(KP,{lifecycle:c});let C=a?.download_progress??null,w=C?.model_name||f;if(p||C?.state===`downloading`||C?.state===`starting`||C?.state===`error`){let e=C?.total_bytes?`${(C.total_bytes/1e9).toFixed(1)} GB`:`large download`,t=C?.state===`error`;return V(`div`,{className:`connection-banner ${t?`connection-banner--error`:`connection-banner--warning`}`,role:t?`alert`:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(t?J:Jr,{size:16})}),P(`div`,{className:`connection-banner__text`,dir:`auto`,children:t?V(D.Fragment,{children:[`Download of `,P(`strong`,{children:w}),` failed.`,` `,(m??C?.message)&&P(`span`,{className:`connection-banner__hint`,children:m??C?.message})]}):V(D.Fragment,{children:[`Downloading `,P(`strong`,{children:w}),` (`,e,`).`,C?.state===`downloading`&&C.file&&V(D.Fragment,{children:[` `,V(`span`,{className:`connection-banner__hint`,children:[`File `,C.file_index,` / `,C.total_files,`: `,P(`code`,{children:C.file})]})]})]})}),t?P(`button`,{className:`connection-banner__retry`,onClick:()=>h(!1,w,!a?.model_loaded),children:`Retry`}):P(`span`,{className:`connection-banner__loading connection-banner__progress`,children:C&&C.state===`downloading`&&C.total_bytes>0?V(D.Fragment,{children:[P(`span`,{className:`connection-banner__progress-bar`,role:`progressbar`,"aria-valuenow":C.percent,"aria-valuemin":0,"aria-valuemax":100,"aria-label":`Download progress`,children:P(`span`,{className:`connection-banner__progress-fill`,style:{width:`${C.percent}%`}})}),V(`span`,{className:`connection-banner__progress-label`,children:[C.percent,`% ·`,` `,(C.downloaded_bytes/1e9).toFixed(2),` /`,` `,(C.total_bytes/1e9).toFixed(2),` GB`]})]}):V(D.Fragment,{children:[P(q,{size:13,className:`connection-banner__spinner`}),C?.state===`starting`?C.message??`Starting download…`:`Downloading…`]})}),t&&P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}if(g){let e=ds(g.model);return g.error?V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.pickLoad.failed`,{model:e}),` `,P(`span`,{className:`connection-banner__hint`,dir:`auto`,children:g.error.key?r(g.error.key,{reason:g.error.reason}):g.error.reason})]}),P(WP,{onRetry:_,label:r(`banner.pickLoad.retry`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:v,"aria-label":r(`banner.dismiss`),children:P(Y,{size:14})})]}):V(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.pickLoad.loading`,{model:e}),` `,P(`bdi`,{dir:`ltr`,children:r(`banner.pickLoad.seconds`,{s:g.seconds})}),` `,P(`span`,{className:`connection-banner__hint`,children:r(`banner.pickLoad.canType`)})]})]})}if(Hw(a)&&!t&&!n){let e=a?.init_tasks?.find(e=>e.status===`running`)?.name||`Preparing AI system`;return V(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[e,V(`span`,{className:`thinking-dots`,children:[P(`span`,{children:`.`}),P(`span`,{children:`.`}),P(`span`,{children:`.`})]})]})]})}if(l||d)return null;if(!i)return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(yo,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.unreachable`),` `,P(`span`,{className:`connection-banner__hint`,children:r(`banner.unreachableHint`)})]}),e&&P(WP,{onRetry:e,label:`Retry`})]});if(n)return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA's backend answered with an error (`,n,`).`,` `,P(`span`,{className:`connection-banner__hint`,children:`It may be overloaded. GAIA keeps checking; if it lasts, restart GAIA.`})]}),e&&P(WP,{onRetry:e,label:`Check again`})]});if(t)return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA is slow to answer.`,` `,P(`span`,{className:`connection-banner__hint`,children:`It may be busy with another chat or app. GAIA keeps checking.`})]}),e&&P(WP,{onRetry:e,label:`Check again`})]});if(a?.config_error)return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA settings could not be loaded.`,` `,P(`span`,{className:`connection-banner__hint`,children:a.config_error})]}),e&&P(WP,{onRetry:e,label:`Check again`})]});if(a&&!a.lemonade_running){let t=Uw(a)===`unresponsive`,n=JN(a);return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t?`The model server is not answering (${a.lemonade_error}). It may be busy with another app or loading a model.`:r(`banner.serverStopped`),` `,n?P(`span`,{className:`connection-banner__hint`,children:r(`banner.finishSetup`)}):a.start_command?V(`span`,{className:`connection-banner__hint`,children:[t?`If it stays this way, restart it: `:`To start it by hand, run `,P(`code`,{children:a.start_command})]}):a.start_instruction&&P(`span`,{className:`connection-banner__hint`,children:a.start_instruction})]}),n&&P(YN,{className:`connection-banner__retry`}),e&&P(WP,{onRetry:e,label:r(`settings.key.checkAgain`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}if(a&&a.lemonade_running&&a.model_loaded&&a.context_size_sufficient===!1){let t=a.model_context_size??0;return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(Ji,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`LLM context window is too small (`,t.toLocaleString(),` tokens;`,` `,Nc.toLocaleString(),` required).`,` `,P(`span`,{className:`connection-banner__hint`,children:`Reload it with a larger context in Settings → Advanced.`})]}),e&&P(WP,{onRetry:e,label:`Check again`}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}return null}function JP(){let e=jN(),t=T(),[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(null),o=(0,X.useCallback)(e=>{let n=kN();n&&(a(null),n[e]().catch(n=>{d.system.error(`Update ${e} failed`,n),a(FN(n,t))}))},[t]);if(n)return null;let s=e.installFailed?t(`update.chip.installFailedDetail`,e.installFailed):null,c=e.status===`downloading`||e.status===`downloaded`;if(e.startFailed&&e.previousVersion&&!c)return V(`div`,{className:`update-chip update-chip--error`,role:`status`,children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,title:i??void 0,children:t(i?`update.chip.updateFailed`:`update.chip.startFailed`)}),P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`revertUpdate`),children:t(`update.chip.goBack`,{version:e.previousVersion})}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]});let l=e.status===`available`||e.status===`downloaded`;if(s&&!l)return V(`div`,{className:`update-chip update-chip--error`,role:`status`,title:s??void 0,children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:t(`update.chip.installFailed`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]});if(e.status===`idle`||e.status===`checking`||e.status===`disabled`||e.status===`no-channel`)return null;if(e.status===`downloading`){let n=Math.max(0,Math.min(100,e.progress));return V(`div`,{className:`update-chip update-chip--downloading`,role:`status`,"aria-live":`polite`,title:t(`update.chip.downloadingTitle`,{version:e.version??``}),children:[P(Jr,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:e.preparing?t(`update.chip.preparing`):t(`update.chip.downloading`,{pct:n})})]})}return e.status===`available`?V(`div`,{className:`update-chip update-chip--available`,role:`status`,title:i||s||e.releaseNotes||t(`update.chip.availableTitle`),children:[P(Jr,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:i?t(`update.chip.updateFailed`):s?t(`update.chip.installFailed`):t(`update.chip.available`,{version:e.version??``})}),!e.pinnedVersion&&P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`downloadUpdate`),children:t(`update.chip.updateNow`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismiss`),children:P(Y,{size:11})})]}):e.status===`downloaded`?V(`div`,{className:`update-chip update-chip--ready`,role:`status`,"aria-live":`polite`,children:[P(Fa,{size:13,className:`update-chip__icon`}),P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`restart`),title:i||s||t(`update.chip.restartTitle`),children:t(i?`update.chip.restartFailed`:s?`update.chip.installFailedRetry`:`update.chip.ready`)})]}):e.status===`error`?V(`div`,{className:`update-chip update-chip--error`,role:`status`,title:e.error||t(`update.chip.checkFailed`),children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:t(`update.chip.checkFailed`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]}):null}var YP={permission_request:{icon:P(Ga,{size:16}),colorClass:`notif-type-permission`},policy_alert:{icon:P(Ga,{size:16}),colorClass:`notif-type-policy`},security_alert:{icon:P(J,{size:16}),colorClass:`notif-type-security`},status_change:{icon:P(Er,{size:16}),colorClass:`notif-type-status`},info:{icon:P(Hi,{size:16}),colorClass:`notif-type-info`},error:{icon:P(wr,{size:16}),colorClass:`notif-type-error`}};function XP(e,t){let n=Date.now()-e,r=Math.floor(n/1e3);if(r<60)return t(`time.justNow`);let i=Math.floor(r/60);if(i<60)return t(`time.minutesAgo`,{n:i});let a=Math.floor(i/60);if(a<24)return t(`time.hoursAgo`,{n:a});let o=Math.floor(a/24);return o<7?t(`time.daysAgo`,{n:o}):new Date(e).toLocaleDateString(te(t),{month:`short`,day:`numeric`})}function ZP({onClose:e}){let t=T(),n=Qs(ko(ec)),r=Qs($s),i=Qs(e=>e.markRead),a=Qs(e=>e.markAllRead),o=Qs(e=>e.clearAll),s=Qs(e=>e.dismiss),c=Qs(e=>e.respondToPermission),l=Qs(e=>e.typeFilter),u=Qs(e=>e.setTypeFilter),d=(0,X.useCallback)(e=>{i(e)},[i]),f=(0,X.useCallback)(e=>{c(e.id,`allow`).catch(e=>console.error(`[NotificationCenter] allow failed:`,e))},[c]),p=(0,X.useCallback)(e=>{c(e.id,`deny`).catch(e=>console.error(`[NotificationCenter] deny failed:`,e))},[c]);Io(!0,e);let m=[{key:null,label:t(`notifications.filter.all`)},{key:`permission_request`,label:t(`notifications.filter.permissions`)},{key:`policy_alert`,label:t(`notifications.filter.policy`)},{key:`error`,label:t(`notifications.filter.errors`)},{key:`security_alert`,label:t(`notifications.filter.security`)},{key:`status_change`,label:t(`notifications.filter.status`)},{key:`info`,label:t(`notifications.filter.info`)}];return V(`div`,{className:`notification-center`,role:`dialog`,"aria-label":t(`notifications.dialogAria`),children:[V(`div`,{className:`notification-center-header`,children:[V(`div`,{className:`notification-center-title-row`,children:[P(`h2`,{className:`notification-center-title`,children:t(`notifications.title`)}),r>0&&P(`span`,{className:`notification-center-badge`,children:r})]}),P(`button`,{className:`btn-icon notification-center-close`,onClick:e,"aria-label":t(`notifications.close`),children:P(Y,{size:18})})]}),P(`div`,{className:`notification-filter-bar`,role:`tablist`,"aria-label":t(`notifications.filterAria`),children:m.map(e=>P(`button`,{role:`tab`,"aria-selected":l===e.key,className:`notification-filter-tab ${l===e.key?`active`:``}`,onClick:()=>u(e.key),children:e.label},e.key??`all`))}),P(`div`,{className:`notification-list`,children:n.length===0?V(`div`,{className:`notification-empty`,children:[P(er,{size:40,strokeWidth:1.2}),P(`span`,{children:t(`notifications.empty`)})]}):n.map(e=>{let n=YP[e.type],r=e.type===`permission_request`&&e.tool?Ks(e,t,iy):null;return V(`div`,{className:`notification-item ${e.read?``:`unread`} ${n.colorClass}`,id:e.type===`policy_alert`&&e.receiptId?`policy-receipt-${encodeURIComponent(e.receiptId)}`:void 0,onClick:()=>d(e.id),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&d(e.id)},children:[!e.read&&P(`span`,{className:`notification-unread-dot`}),P(`span`,{className:`notification-icon`,children:n.icon}),V(`div`,{className:`notification-content`,children:[V(`div`,{className:`notification-content-header`,children:[P(`span`,{className:`notification-agent`,dir:`auto`,children:e.agentName}),P(`span`,{className:`notification-time`,children:XP(e.timestamp,t)})]}),r?V(D.Fragment,{children:[P(`span`,{className:`notification-title`,children:P(sy,{text:r.heading})}),P(`span`,{className:`notification-message`,children:P(sy,{text:r.question})})]}):V(D.Fragment,{children:[e.title&&P(`span`,{className:`notification-title`,children:e.title}),P(`span`,{className:`notification-message`,children:e.message})]}),e.type===`permission_request`&&e.tool&&e.tool!==`allow_path_access`&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.tool`),`: `,P(`code`,{dir:`ltr`,children:e.tool})]}),e.type===`policy_alert`&&V(`div`,{className:`notification-policy-details`,children:[e.tool&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.tool`),`: `,P(`code`,{dir:`ltr`,children:e.tool})]}),e.reason&&V(`span`,{className:`notification-policy-reason`,children:[t(`notifications.reason`),`: `,e.reason]}),e.ruleIds&&e.ruleIds.length>0&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.rules`),`: `,P(`code`,{dir:`ltr`,children:e.ruleIds.join(`, `)})]}),e.policyVersion&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.policy`),`: `,P(`code`,{dir:`ltr`,children:e.policyVersion})]}),V(`span`,{className:`notification-tool`,children:[t(`activity.policy.receipt`),`:`,` `,e.receiptId?P(`code`,{dir:`ltr`,children:e.receiptId}):P(`em`,{children:t(`activity.policy.receiptUnavailable`)})]})]}),e.type===`permission_request`&&!e.response&&V(`div`,{className:`notification-actions`,children:[V(`button`,{className:`notification-action-btn notification-action-allow`,onClick:t=>{t.stopPropagation(),f(e)},children:[P(mr,{size:14}),t(`notifications.approve`)]}),V(`button`,{className:`notification-action-btn notification-action-deny`,onClick:t=>{t.stopPropagation(),p(e)},children:[P(Y,{size:14}),t(`notifications.deny`)]})]}),e.type===`permission_request`&&e.response&&P(`span`,{className:`notification-response-badge ${e.response===`allow`?`response-allow`:`response-deny`}`,children:e.response===`allow`?t(`notifications.approved`):t(`notifications.denied`)})]}),P(`button`,{className:`notification-dismiss`,onClick:t=>{t.stopPropagation(),s(e.id)},"aria-label":t(`notifications.dismiss`),children:P(Y,{size:14})})]},e.id)})}),n.length>0&&V(`div`,{className:`notification-center-footer`,children:[V(`button`,{className:`notification-footer-btn`,onClick:a,disabled:r===0,children:[P(mr,{size:14}),t(`notifications.markAllRead`)]}),V(`button`,{className:`notification-footer-btn notification-footer-clear`,onClick:o,children:[P(lo,{size:14}),t(`notifications.clear`)]})]})]})}var QP=1500,$P=e=>new Promise(t=>setTimeout(t,e));async function eF({onProgress:e,isCancelled:t=()=>!1,pollMs:n=QP}={}){try{await sn(ck)}catch(e){if(e?.httpStatus!==409)throw e;let t=await Ut(ck).catch(()=>null);if(!t||t.status===`completed`||t.status===`failed`)throw e}for(;!t();){let t=await Ut(ck);if(e?.(t),t.status===`completed`)return;if(t.status===`failed`)throw Error(t.error||`The GAIA agent could not be installed.`);await $P(n)}}function tF({onInstalled:e,noBuild:t=!1}){let n=T(),[r,i]=(0,X.useState)({kind:`idle`}),a=(0,X.useRef)(!1);(0,X.useEffect)(()=>()=>{a.current=!0},[]);let o=(0,X.useCallback)(async()=>{i({kind:`installing`,percent:0});try{if(await eF({isCancelled:()=>a.current,onProgress:e=>{a.current||i({kind:`installing`,percent:e.percent??0})}}),a.current)return;await e(),a.current||i({kind:`idle`})}catch(e){a.current||i({kind:`failed`,error:e instanceof Error?e.message:String(e)})}},[e]);return t?P(`div`,{className:`app-notice is-warning`,role:`status`,children:P(`span`,{children:n(`agentNotice.noBuild`)})}):V(`div`,{className:`app-notice is-warning`,role:`status`,children:[r.kind===`installing`?P(`span`,{children:n(`agentNotice.installing`,{percent:Math.round(r.percent)})}):r.kind===`failed`?P(`span`,{children:n(`agentNotice.failed`,{error:r.error})}):P(`span`,{children:n(`agentNotice.missing`)}),r.kind!==`installing`&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>void o(),children:r.kind===`failed`?n(`agentNotice.retry`):n(`agentNotice.install`)})]})}function nF(e,t){if(!(e instanceof Error))return t;let n=e.message,r=n.match(/API \d+: (.+)/);if(r)try{let e=JSON.parse(r[1]);if(e.detail)return e.detail}catch{}return n}function rF(e,t){let{addNotification:n}=Qs.getState();for(let r of t)r.error_count<=(e[r.id]??0)||!r.last_error||n({id:`schedule-error-${r.id}-${r.error_count}`,type:`error`,agentId:`scheduler`,agentName:`GAIA`,title:`Scheduled task "${r.name}" failed`,message:r.last_error,timestamp:Date.now(),read:!1,dismissed:!1,priority:`high`,...r.session_id?{sessionId:r.session_id}:{}})}var iF=p((e,t)=>({schedules:[],loading:!1,error:null,actionError:null,selectedSchedule:null,results:[],resultsLoading:!1,errorCounts:null,loadSchedules:async()=>{t().schedules.length===0&&!t().error&&e({loading:!0}),e({error:null});try{let n=(await At()).schedules||[],r=t().errorCounts;r&&rF(r,n),e({schedules:n,loading:!1,errorCounts:Object.fromEntries(n.map(e=>[e.id,e.error_count]))})}catch(t){d.api.error(`Failed to load schedules`,t),e({error:`Failed to load schedules`,loading:!1})}},createSchedule:async(t,n,r)=>{try{let i=await yt(t,n,r);e(e=>({schedules:[...e.schedules,i],actionError:null}))}catch(e){throw d.api.error(`Failed to create schedule`,e),e}},updateScheduleStatus:async(t,n)=>{try{let r=await ut(t,n);e(e=>({schedules:e.schedules.map(e=>e.name===t?r:e),actionError:null}))}catch(n){d.api.error(`Failed to update schedule "${t}"`,n),e({actionError:nF(n,`Failed to update schedule`)})}},runScheduleNow:async t=>{try{let n=await Jt(t);e(e=>({schedules:e.schedules.map(e=>e.name===t?n:e),actionError:null}))}catch(n){d.api.error(`Failed to run schedule "${t}" now`,n),e({actionError:nF(n,`Could not run the schedule now`)})}},deleteSchedule:async t=>{try{await $e(t),e(e=>({schedules:e.schedules.filter(e=>e.name!==t),selectedSchedule:e.selectedSchedule===t?null:e.selectedSchedule,actionError:null}))}catch(n){d.api.error(`Failed to delete schedule "${t}"`,n),e({actionError:nF(n,`Failed to delete schedule`)})}},selectSchedule:n=>{e({selectedSchedule:n,results:[],resultsLoading:!1}),n&&t().loadResults(n)},loadResults:async n=>{e({resultsLoading:!0});try{let r=await De(n);if(t().selectedSchedule!==n)return;e({results:r.results||[],resultsLoading:!1})}catch(r){if(d.api.error(`Failed to load results for "${n}"`,r),t().selectedSchedule!==n)return;e({results:[],resultsLoading:!1})}},dismissActionError:()=>e({actionError:null})})),aF=new Set([`loading_model`,`downloading_model`,`model_retry`,`waiting`]),oF=5;function sF(e,t){return{id:e,title:t.get(e)?.title??`Untitled chat`}}function cF(e){let t=new Map(e.sessions.map(e=>[e.id,e])),n=e.isStreaming&&e.currentSessionId!==null,r=[...e.runningSessionIds];n&&!r.includes(e.currentSessionId)&&r.push(e.currentSessionId);let i=new Set(r),a=new Set(e.notifications.filter(e=>e.type===`permission_request`&&!e.response&&!e.dismissed&&e.sessionId&&i.has(e.sessionId)).map(e=>e.sessionId)),o=[...a].map(e=>({...sF(e,t),reason:`approval`}));n&&e.awaitingUser&&!a.has(e.currentSessionId)&&o.push({...sF(e.currentSessionId,t),reason:`answer`});for(let[n,r]of Object.entries(e.awaitingBySession))o.some(e=>e.id===n)||o.push({...sF(n,t),reason:r===`question`?`answer`:`approval`});let s=n&&!e.awaitingUser&&e.livePhase&&aF.has(e.livePhase)?e.liveStatus:null,c=e.systemStatus,l=null;if(c?.default_model_is_cloud&&c.default_model_name)l={name:c.default_model_name,where:`cloud`};else if(c?.model_loaded){let e=c.model_labels?.includes(`cloud`),t=c.model_device&&c.model_device!==`none`?c.model_device:null;l={name:c.model_loaded,where:e?`cloud`:t}}let u=[...e.sessions].sort((e,t)=>t.updated_at.localeCompare(e.updated_at)).slice(0,oF).map(e=>sF(e.id,t));return{backendConnected:e.backendConnected,modelServerRunning:c&&!c.default_model_is_cloud?c.lemonade_running:null,model:l,waitingOnModel:s||null,running:r.map(e=>sF(e,t)),needsYou:o,recent:u}}function lF(e){let t=(0,X.useRef)(e);t.current=e,(0,X.useEffect)(()=>{let e=window.gaiaAPI?.tray;if(!e)return;let n=``,r=null,i=()=>{let t=k.getState(),i={backendConnected:t.backendConnected,systemStatus:t.systemStatus,sessions:t.sessions,runningSessionIds:t.runningSessionIds,awaitingBySession:t.awaitingBySession,currentSessionId:t.currentSessionId,isStreaming:t.isStreaming,awaitingUser:t.awaitingUser,liveStatus:t.liveStatus,livePhase:t.livePhase,notifications:Qs.getState().notifications},a=r;if(r=i,a&&Object.keys(i).every(e=>i[e]===a[e]))return;let o=cF(i),s=JSON.stringify(o);s!==n&&(n=s,e.setActivity(o).catch(e=>{n=``,d.system.error(`The tray could not take the app state`,e)}))};i();let a=k.subscribe(i),o=Qs.subscribe(i),s=e.onCommand(e=>{switch(e.type){case`open-chat`:t.current.openChat(e.sessionId);break;case`new-chat`:t.current.newChat();break;case`open-settings`:k.getState().openSettings(e.section);break;case`refresh-status`:t.current.refreshStatus();break;default:d.system.error(`Unknown tray command`,e)}});return()=>{a(),o(),s()}},[])}function uF(){(0,X.useEffect)(()=>{let e=window.gaiaAPI;if(!e)return;let t=Qs.getState().addNotification,n=[e.notification.onNotification(t),e.notification.onPermissionRequest(t),e.tray.onNavigate(e=>{let t=typeof e==`string`&&e.startsWith(`session:`)?e.slice(8):null;if(!t)return;let n=k.getState();n.currentSessionId!==t&&n.setMessages([]),n.setCurrentSession(t)})];return()=>n.forEach(e=>e())},[])}function dF(e,t,n){let r=window.gaiaAPI;if(r){r.notification.show({title:t,body:n,sessionId:e}).then(e=>{e||d.system.warn(`This OS has no desktop notifications; the badge still counts it.`)}).catch(e=>d.system.error(`Could not show the desktop notification`,e));return}if(typeof Notification>`u`){d.system.warn(`This browser has no notifications; the alert was not shown.`);return}if(Notification.permission!==`granted`){d.system.warn(`Browser notifications are ${Notification.permission}; allow them in Settings → Notifications.`);return}let i=new Notification(t,{body:n,tag:`gaia-${e}`});i.onclick=()=>{window.focus(),k.getState().setCurrentSession(e)}}function fF(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=navigator;if(!e.getBattery)return;let n=null,r=()=>{n&&t({charging:n.charging,level:n.level})};return e.getBattery().then(e=>{n=e,r(),e.addEventListener(`levelchange`,r),e.addEventListener(`chargingchange`,r)}).catch(e=>d.system.warn(`Battery level unavailable; keep-awake ignores the battery policy.`,e)),()=>{n?.removeEventListener(`levelchange`,r),n?.removeEventListener(`chargingchange`,r)}},[]),e}function pF(){uF();let e=k(e=>e.runningSessionIds),t=k(e=>e.awaitingBySession),n=k(e=>e.sessions),r=k(e=>e.currentSessionId),i=Qs(ko(nc)),a=lc(),o=fF(),s=(0,X.useRef)(null),c=gc(e,t,i),l=JSON.stringify(c);(0,X.useEffect)(()=>{let e=JSON.parse(l),t=s.current;if(s.current=e,t===null)return;let{sessions:n,currentSessionId:r}=k.getState(),i=document.hasFocus(),o=!1;for(let{sessionId:s,event:c}of _c(t,e)){let e=n.find(e=>e.id===s);if(e?.kind===`eval`||e?.kind===`scheduled`)continue;let t=a.modes[c];if(!(t===`off`||bc(s,r,i))&&(o=!0,t===`banner`)){if(c!==`finished`){let{title:t,body:n}=yc(c,e);dF(s,t,n)}else mt(s).then(e=>{k.getState().updateSessionInList(s,e);let{title:t,body:n}=yc(c,e);dF(s,t,n)}).catch(t=>{d.system.error(`Could not read how chat ${s} ended`,t);let{title:n,body:r}=yc(c,{...e,last_run_status:null});dF(s,n,r)})}}if(o){if(a.sound)try{Cc()}catch(e){d.system.warn(`Alert sound not played`,e)}a.flash&&!i&&window.gaiaAPI&&window.gaiaAPI.notification.flash().catch(e=>d.system.error(`Could not flash the taskbar button`,e))}},[l,a.modes,a.sound,a.flash]);let u=xc(n,c,a.modes,r);(0,X.useEffect)(()=>{window.gaiaAPI?.notification.setAttentionCount(u).catch(e=>d.system.error(`Could not update the taskbar badge`,e))},[u]);let f=a.keepAwake&&e.length>0&&Sc(o,a.batteryFloor);(0,X.useEffect)(()=>{window.gaiaAPI?.power.setKeepAwake(f).catch(e=>d.system.error(`Could not change keep-awake`,e))},[f])}function mF(e){if(e<=0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.min(Math.floor(Math.log(e)/Math.log(t)),n.length-1);return parseFloat((e/t**r).toFixed(1))+` `+n[r]}function hF(e){return e.replace(/-/g,``).slice(0,7)}function gF(e,t){let n=t.replace(/^#/,``).toLowerCase();if(!n||n.length<4)return null;let r=e.find(e=>e.id.replace(/-/g,``).toLowerCase().startsWith(n));return r?r.id:null}function _F(e,t,n){return!e||t&&(e===t||e===hF(t))?null:n.some(t=>t.id===e)?e:gF(n,e)}function vF(e){return new URLSearchParams(e.search).get(`session`)||e.hash.replace(/^#/,``)||null}var yF=`gaia:last-session`;function bF(e){try{e?localStorage.setItem(yF,e):localStorage.removeItem(yF)}catch(e){d.ui.warn(`Could not save the open chat for the next launch`,e)}}function xF(){try{return localStorage.getItem(yF)}catch(e){return d.ui.warn(`Could not read the chat open at last launch`,e),null}}var SF=1e3,CF=3e4;function wF(e,{initialMs:t=SF,maxMs:n=CF,onError:r}={}){let i=t,a=0,o=null,s=!1,c=!1,l=!1,u=()=>{l||c||s||(o&&=(clearTimeout(o),null),s=!0,a+=1,e().then(()=>{c=!0}).catch(e=>{l||(r?.(e,a),o=setTimeout(()=>{o=null,u()},i),i=Math.min(i*2,n))}).finally(()=>{s=!1}))};return u(),{kick:()=>{o&&u()},stop:()=>{l=!0,o&&clearTimeout(o),o=null},done:()=>c}}function TF(e,t,n){return e&&!t&&!n}var EF=(0,X.lazy)(()=>IP(()=>import(`./MemoryDashboard-DJWkELvL.js`).then(e=>({default:e.MemoryDashboard})),__vite__mapDeps([6,1,2,7,8]),import.meta.url)),DF=(0,X.lazy)(()=>IP(()=>import(`./ScheduleManager-xx9Mhex5.js`).then(e=>({default:e.ScheduleManager})),__vite__mapDeps([9,1,2,7,3,10]),import.meta.url)),OF=(0,X.lazy)(()=>IP(()=>import(`./DocumentLibrary-DA1FKyAu.js`).then(e=>({default:e.DocumentLibrary})),__vite__mapDeps([11,1,2,3,12]),import.meta.url)),kF=(0,X.lazy)(()=>IP(()=>import(`./FileBrowser-CODR0L_L.js`).then(e=>({default:e.FileBrowser})),__vite__mapDeps([13,1,2,3,14]),import.meta.url)),AF=(0,X.lazy)(()=>IP(()=>import(`./MobileAccessModal-D1jnQ_9R.js`).then(e=>({default:e.MobileAccessModal})),__vite__mapDeps([15,1,2,3,16]),import.meta.url)),jF=3,MF=3e5,NF=6e3,PF=6e4,FF=e=>e instanceof TypeError,IF=e=>new Promise(t=>setTimeout(t,e)),LF=3e5,RF=class extends Error{};async function zF(){let e=Date.now()+LF;for(;;){let t=await it();if(t.state===`ready`)return;if(t.state===`failed`||t.state===`cancelled`)throw new RF(t.error||I().bare(`setup.upgrading.stopped`));if(Date.now()>=e)throw Error(I().bare(`setup.upgrading.slow`));await IF(SF)}}function BF(){return P(`div`,{className:`loading-spinner`,role:`status`,"aria-label":`Loading`})}var VF=e=>e===1||e%10==0;function HF(){let e=T(),t=k(e=>e.currentSessionId),n=k(e=>e.setSessions),r=k(e=>e.setCurrentSession),i=k(e=>e.addSession),a=k(e=>e.setMessages),o=k(e=>e.showDocLibrary),s=k(e=>e.showFileBrowser),c=k(e=>e.showMemoryDashboard),l=k(e=>e.showSchedules),u=k(e=>e.sidebarOpen),f=k(e=>e.sidebarCollapsed),p=k(e=>e.setSidebarOpen),h=k(e=>e.setSystemStatus),g=k(e=>e.setBackendConnected),_=k(e=>e.setAgents),v=k(e=>e.agents),y=k(e=>e.setPendingPrompt),b=k(e=>e.setDefaultPermissionMode),x=k(e=>e.openSettings),S=k(e=>e.settingsSection),C=k(e=>e.syncSystemTheme),w=cs(e=>e.restoreNotice),E=cs(e=>e.dismissRestoreNotice),D=Qs(e=>e.showPanel),O=k(e=>e.systemStatus?.initialized===!0),A=(0,X.useRef)(!1),j=Qs(e=>e.setShowPanel);(0,X.useEffect)(()=>{if(!w?.ok)return;let e=setTimeout(E,NF);return()=>clearTimeout(e)},[w,E]);let[M,N]=(0,X.useState)({state:`checking`}),F=k(e=>e.setupAgain),I=k(e=>e.runSetupAgain),ee=(0,X.useRef)(M);ee.current=M;let[R,z]=(0,X.useState)(!1),B=(0,X.useRef)(R);B.current=R;let[te,ne]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(!1),ae=te||R&&!lk(v),oe=(0,X.useRef)(ae);oe.current=ae;let[H,se]=(0,X.useState)(null),[W,G]=(0,X.useState)(``),[ce,le]=(0,X.useState)(0),[de,fe]=(0,X.useState)(!1),[pe,me]=(0,X.useState)(!1),[he,ge]=(0,X.useState)(null),[_e,ve]=(0,X.useState)(null),ye=(0,X.useRef)(async()=>{}),be=(0,X.useRef)(async()=>{}),xe=(0,X.useCallback)(async(e=!1,t=!1)=>{e||N({state:`checking`});let n=0;try{for(;;){await cs.getState().refresh();let e=!!cs.getState().active?.remote,r;try{r=await Wt(e)}catch(e){if(!t||!FF(e)||n>=PF)throw e;await IF(SF),n+=SF;continue}if(!r.ready&&r.stage===`upgrade`){N({state:`upgrading`});let t=await it();(!t.upgrade_embedded||t.state!==`running`&&t.state!==`verifying`)&&await _t(e,!1,{upgradeEmbedded:!0}),await zF(),r=await Wt(e)}n>0&&await Promise.all([ye.current(),be.current()]),ie(!!r.no_agent_build),N(r.ready?{state:`ready`}:{state:`needed`,check:r});return}}catch(e){let t=e instanceof Error?e.message:String(e);if(e instanceof RF){d.system.warn(`Updating the local model server failed`,e),N({state:`unknown`,error:t,upgradeFailed:!0});return}d.system.warn(`Setup check could not be answered`,e),N({state:`unknown`,error:t})}},[]),Se=(0,X.useRef)(0),Ce=(0,X.useCallback)(async()=>{let e=++Se.current,t=(await vn()).agents||[];e===Se.current&&(_(t),z(!0),lk(t)&&ne(!1))},[_]),we=(0,X.useCallback)(()=>{let e=B.current;z(!1),Ce().catch(t=>{d.api.warn(`Agent list unavailable after setup`,t),e&&z(!0)})},[Ce]);(0,X.useEffect)(()=>{let e=()=>{oe.current&&Ce().catch(e=>d.api.warn(`Agent list unavailable`,e))};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[Ce]);let Te=(0,X.useCallback)(async()=>{b((await on()).default_mode)},[b]),Ee=(0,X.useRef)([]);(0,X.useEffect)(()=>{m(`0.26.0rc5`),xe(!1,!0);let e=[wF(Ce,{onError:(e,t)=>{VF(t)&&d.api.warn(`Agent list unavailable (attempt ${t}); retrying`,e)}}),wF(Te,{onError:(e,t)=>{VF(t)&&d.api.warn(`Default permission mode unavailable (attempt ${t}); retrying`,e)}})];return Ee.current=e,()=>e.forEach(e=>e.stop())},[xe,Ce,Te]);let De=(0,X.useCallback)(()=>{Ee.current.forEach(e=>e.kick()),cs.getState().retryNow(),be.current();let e=ee.current;e.state===`unknown`&&!e.upgradeFailed&&xe(!0)},[xe]),Oe=(0,X.useRef)(De);Oe.current=De;let ke=(0,X.useRef)(0),Ae=(0,X.useRef)(0),je=(0,X.useRef)(null),Me=(0,X.useRef)(!1),[Ne,Pe]=(0,X.useState)(!1),[Fe,Ie]=(0,X.useState)(null),Le=(0,X.useCallback)(e=>{if(e.kind===`unreachable`){d.system.warn(`System status check failed`,e.error),Me.current=!0,Ae.current=0,je.current=null,Pe(!1),Ie(null),g(!1),h(null);return}if(e.kind===`error`){d.system.warn(`System status answered HTTP ${e.httpStatus}`,e.message),Me.current&&Oe.current(),Me.current=!1,Ae.current=0,je.current=null,Pe(!1),Ie(`HTTP ${e.httpStatus}: ${e.message}`),g(!0);return}if(e.kind===`slow`){if(Ae.current+=1,je.current??=Date.now(),Ie(null),d.system.warn(`System status did not answer in time (${Ae.current} in a row)`),Date.now()-je.current>=MF){Pe(!1),g(!1),h(null);return}g(!0),(Me.current||Ae.current>=jF)&&Pe(!0);return}let{status:t}=e;Me.current&&Oe.current(),Me.current=!1,Ae.current=0,je.current=null,Pe(!1),Ie(null),g(!0),ke.current=t.lemonade_running?0:ke.current+1;let n=k.getState().systemStatus;t.lemonade_running||ke.current>=jF||!n?.lemonade_running?h(t):h({...n,download_progress:t.download_progress})},[g,h]),Re=(0,X.useRef)(Le);Re.current=Le;let[ze]=(0,X.useState)(()=>Kw(e=>Re.current(e))),Be=ze.check;ye.current=Be,(0,X.useEffect)(()=>_k(ze.start),[ze]),(0,X.useEffect)(()=>HP(()=>{Be()}),[Be]);let Ve=(0,X.useRef)(``);(0,X.useEffect)(()=>{let e=e=>Ft().then(t=>{let r=t.sessions||[];if(!e&&r.length===0&&k.getState().sessions.length>0)return;let i=r.map(e=>`${e.id}|${e.updated_at}|${e.title}|${e.inference_remote}|${e.inference_provider}|${e.inference_description}|${e.effective_model}|${e.unread}|${e.pinned}|${e.last_run_status}|${e.kind}`).join(`
81
+ `)})]})]}),rn&&P(`p`,{className:`setup-error`,role:`alert`,children:n(`setup.summary.short`,{need:$(rn.needGb),free:$(rn.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(rn.freeUpGb)})}),(me??A)&&P(gN,{text:me??A})]}),V(`details`,{className:`setup-disclosure`,children:[P(`summary`,{children:n(`setup.plan.whatDownloads`)}),P(mM,{plan:L,models:nn})]})]}),cn===`gpu`&&oe&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.gpu.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.gpu.lede`)}),P(tM,{status:oe,onStatus:H,mode:`setup`,headingId:`setup-title`,names:Xt,onBack:Lt,onSkip:()=>Mt(d),onContinue:()=>Mt(d)})]}),cn===`models`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.models.title`)}),L&&B&&P(IM,{plan:L,selection:B,onSelection:te,disabled:fe||Dn,onRecheck:()=>void gt()}),It&&oe?.total_gb!=null&&oe.gpu_gb!=null&&V(`p`,{className:`setup-hint setup-gpu-option`,children:[n(`setup.models.gpu`,{gpu:$(oe.gpu_gb),total:$(oe.total_gb)}),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:()=>zt(`models`),disabled:fe||Dn,children:n(`setup.found.changeMemory`)})]}),P(nM,{plan:L,planError:R,onRetryPlan:()=>void gt(),onUseRecommended:()=>void wt(!1,{keepTrying:U}),selection:B,onSelection:te,cloud:!1,keepTrying:U,onKeepTrying:se,onBack:Lt,onContinue:e=>void jt(e),busy:fe||Dn,error:me??A})]}),cn===`key`&&V(`form`,{id:`setup-key-form`,onSubmit:e=>{e.preventDefault(),Gt()},className:`setup-form`,children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.key.title`)}),P(`div`,{className:`setup-choices`,role:`radiogroup`,"aria-label":n(`setup.key.provider`),children:sN.filter(e=>e.id!==`local`).map(e=>V(`button`,{type:`button`,role:`radio`,"aria-checked":a===e.id,className:`setup-choice${a===e.id?` is-active`:``}${tt(e.id)?` is-disabled`:``}`,onClick:()=>Kt(e.id),disabled:F.busy||tt(e.id),title:et(e.id)?n(`settings.privacy.localOnlyBlocked`):void 0,children:[P(Ir,{size:16,"aria-hidden":`true`}),V(`span`,{children:[P(`span`,{className:`setup-choice-title`,children:P(`bdi`,{children:cN(e,n)})}),P(`span`,{className:`setup-choice-note`,children:tt(e.id)?nt(e.id):n(e.note)})]})]},e.id))}),Je?.reachable===!1&&P(`button`,{type:`button`,className:`link-btn setup-start`,onClick:Xe,children:n(`setup.key.checkAgain`)}),et(a)&&P(`p`,{className:`setup-a11y-alert`,role:`alert`,children:n(`settings.privacy.localOnlyBlocked`)}),a===`fireworks`&&!Oe&&!et(a)&&V(`section`,{className:`setup-card`,children:[P(`h3`,{className:`mc-job-title`,children:n(`setup.key.getOne`)}),V(`ol`,{className:`setup-key-steps`,children:[P(`li`,{children:P(`a`,{href:aN,target:`_blank`,rel:`noreferrer`,children:n(`setup.key.step1`)})}),P(`li`,{children:n(`setup.key.step2`)}),P(`li`,{children:n(`setup.key.step3`)})]})]}),a===`amd`&&!Oe&&!et(a)&&P(`section`,{className:`setup-card`,children:P(`p`,{className:`setup-hint`,children:P(`a`,{href:oN,target:`_blank`,rel:`noreferrer`,children:n(`setup.key.gatewayHelp`)})})}),!et(a)&&P(WA,{provider:a,limit:3}),P(`p`,{className:`setup-hint`,children:n(Oe?`setup.key.usersServer`:`setup.key.where`)}),P(`div`,{className:`setup-row`,children:!Oe&&P(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,value:M,onChange:e=>N(e.target.value),placeholder:n(`setup.key.placeholder`),"aria-label":n(`setup.key.label`)})}),$e&&!Oe&&!M&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.key.foundEnv`,{name:$e.name,hint:$e.key_hint??``})}),F.busy&&!F.waiting&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.key.testing`)}),F.busy&&F.waiting&&P(`p`,{className:`setup-hint`,role:`status`,children:F.waiting}),F.error&&P(`p`,{className:`setup-error`,role:`alert`,children:F.error}),V(Gj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:Nt,disabled:F.busy,children:n(`setup.back`)}),V(`button`,{type:`submit`,form:`setup-key-form`,className:`btn-primary`,disabled:F.busy||tt(a)||Dn,children:[F.busy&&P(q,{size:13,className:`spin`}),` `,n(`setup.key.connect`)]})]})]}),cn===`download`&&!K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.download.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.download.lede`)}),V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.starting`)]})]}),cn===`download`&&K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.download.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.download.lede`)}),L&&P(`section`,{className:`setup-card`,"aria-label":n(`setup.contents.title`),children:P(mM,{plan:L,run:K,onRetry:Et,retryDisabled:fe})}),(K.models?.length??0)>0?P(`div`,{className:O?`is-stale`:void 0,children:P(EM,{status:{...K,overall:Cj(K,ne??L)},names:Xt,freeGb:L?.disk?.free_gb??null,onCancel:()=>void Vt(),onRetry:(e,t)=>void Ht(e,t),onResume:e=>void Ht(e,null),onResumeAll:Et,onSkip:e=>void Ut(e),onRestart:()=>void Wt(),busy:fe||!!O,retryLater:st,labelledBy:`setup-title`})}):st?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.working`)]}):null,kn.length>0&&V(`section`,{className:`setup-card`,"aria-label":n(`setup.optional.title`),children:[P(`h3`,{className:`mc-job-title`,children:n(`setup.optional.title`)}),P(`p`,{className:`setup-hint`,children:n(`setup.optional.lede`)}),P(`ul`,{className:`setup-rows`,children:kn.map(e=>{let t=Se.includes(e.id);return V(`li`,{className:`setup-result is-waiting`,children:[P(`span`,{className:`setup-result-label`,children:n(`setup.purpose.${e.roles[0]}`)}),V(`span`,{className:`setup-result-value`,children:[P(`bdi`,{dir:`ltr`,children:e.size_gb==null?n(`setup.contents.sizeOnDownload`):$(e.size_gb)}),P(`button`,{type:`button`,className:`btn-secondary`,"aria-pressed":t,onClick:()=>we(n=>t?n.filter(t=>t!==e.id):[...n,e.id]),children:n(t?`setup.optional.added`:`setup.optional.add`)})]})]},e.id)})})]}),O&&V(D.Fragment,{children:[P(`p`,{className:`setup-error`,role:`alert`,children:n(`setup.lostContact`,{error:O})}),P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void St(),children:n(`setup.reconnect`)})})]}),Qt&&$t&&!en&&K.state===`failed`&&!K.model_failed&&(K.problem?P(hN,{problem:K.problem,onRetry:Et,onUseGaia:()=>void wt(!0,Me.current.options)}):V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:n(`setup.download.stoppedBeforeCheck`)}),K.error&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:K.error})]})]})),Qt&&$t&&!en&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.download.finishNote`)}),P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:Et,disabled:fe,children:n(`setup.finish`)})})]}),Qt&&!$t&&!en&&!(K.models??[]).some(e=>e.state===`failed`||e.state===`cancelled`)&&V(D.Fragment,{children:[P(_N,{run:K}),K.problem?P(hN,{problem:K.problem,onRetry:Et,onUseGaia:()=>void wt(!0,Me.current.options)}):P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void wt(!!K.gaia_lemonade,Me.current.options),children:n(`setup.tryAgain`)})})]}),(me||A)&&P(gN,{text:me??A})]}),cn===`test`&&K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.test.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.test.lede`)}),P(iN,{run:K,expected:On,names:Xt,catalog:tn,onRetry:Et,onChooseAnother:rt?void 0:Pt,onCancel:()=>void Vt(),onDownloadAgain:L?.lemonade.mode===`external`?void 0:e=>void Ht(e,`verify`),busy:fe}),Qt&&K.error&&!(K.tests??[]).some(e=>e.error===K.error)&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:K.error})]}),(me||A)&&P(gN,{text:me??A})]}),cn===`ready`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.ready.heading`)}),V(`div`,{className:`setup-done`,role:`status`,children:[P(`div`,{className:`setup-done-head`,children:Jt&&P(`p`,{children:n(rt?`setup.ready.answersCloud`:`setup.ready.answersLocal`,{model:rt?vs(Jt):Xt[Jt]??ie?.catalog?.find(e=>e.id===Jt)?.name??vs(Jt)})})}),P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Yt(),autoFocus:!0,children:n(`setup.ready.start`)})}),!rt&&ie&&P(rM,{plan:ie,chatModel:Jt,gpu:oe}),A&&P(gN,{text:A}),(K?.tests??[]).filter(e=>e.state===`failed`).map(e=>P(`p`,{className:`setup-failed-extra`,role:`alert`,children:n(`setup.ready.extraFailed`,{job:n(`setup.test.job.${e.job}`)})},`${e.job}:${e.subject??``}`)),Ee.length>0&&!W&&P(`p`,{className:`setup-failed-extra`,role:`alert`,children:n(`setup.ready.extraNotFetched`,{names:Ee.map(e=>Xt[e]??e).join(`, `)})}),be.length>0&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.ready.tasks`)}),P(cM,{cards:be,onPick:e=>void Yt(e)})]})]})]})]},cn),t&&!st&&cn!==`plan`&&cn!==`ready`&&P(`div`,{className:`setup-row`,children:P(`button`,{type:`button`,className:`link-btn setup-close`,onClick:t,children:n(`setup.backToGaia`)})}),Dn&&(En||cn===`plan`)&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.nav.runGoing`)}),P(kM,{run:w,before:{check:gn}})]}),P(`div`,{className:`setup-footer`,ref:m})]})}),W?.kind===`no_fit`&&P(Kj,{title:W.models.length===1?n(`setup.confirm.noFitOne`,{name:W.models[0].name}):n(`setup.confirm.noFitMany`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.pickSmaller`),onConfirm:()=>{le(null),de(!0),jt(Ot,!0)},onCancel:()=>le(null),children:W.models.map(e=>V(`p`,{children:[P(`bdi`,{children:e.name}),`: `,Aj(e,n)]},e.id))}),W?.kind===`low_disk`&&rn&&P(Kj,{title:n(`setup.confirm.lowDiskTitle`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{le(null),jt(!0)},onCancel:()=>{le(null),Pt()},children:P(`p`,{children:n(`setup.summary.short`,{need:$(rn.needGb),free:$(rn.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(rn.freeUpGb)})})}),W?.kind===`server`&&P(Kj,{title:W.detail.code===`low_disk`?n(`setup.confirm.lowDiskTitle`):n(`setup.confirm.noFitServerTitle`),confirmLabel:W.detail.code===`low_disk`?n(`setup.confirm.downloadAnyway`):n(`setup.confirm.useAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{let e=W;if(le(null),e.then===`chat`)de(!0),jt(Ot,!0);else if(e.then===`retry`)Te(e.id,{keepTrying:U,acknowledgeLowDisk:!0}).then(E).catch(e=>he(yN(e)));else{let{gaiaLemonade:e,options:t}=Me.current;wt(e,{...t,acknowledgeLowDisk:!0})}},onCancel:()=>{let e=W;le(null),e.then!==`retry`&&!ct&&Pt()},children:P(`p`,{children:W.detail.message})})]})}function xN(e,t,n){let r=(0,X.useRef)(n);(0,X.useEffect)(()=>{r.current=n});let i=(0,X.useRef)(!1),a=(0,X.useRef)(null);if(t&&!i.current){let e=document.activeElement;a.current=e instanceof HTMLElement?e:null}(0,X.useEffect)(()=>{if(!t)return;i.current=!0;let n=a.current,o=e.current;if(o&&!o.contains(document.activeElement)){let e=r.current?.()??oS(o)[0];e?e.focus():(o.hasAttribute(`tabindex`)||o.setAttribute(`tabindex`,`-1`),o.focus())}return()=>{i.current=!1;let e=document.activeElement;(!e||e===document.body||o?.contains(e))&&n?.isConnected&&n.focus()}},[e,t])}function SN({title:e,titleId:t,count:n,hint:r,defaultOpen:i=!1,forceOpen:a=!1,children:o}){let[s,c]=(0,X.useState)(i);return V(`details`,{className:`settings-disclosure`,open:s||a,onToggle:e=>{a||c(e.currentTarget.open)},children:[V(`summary`,{onClick:e=>{a&&e.preventDefault()},children:[P(gr,{size:15,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),V(`span`,{className:`settings-disclosure-text`,children:[P(`span`,{className:`settings-disclosure-title`,id:t,tabIndex:t?-1:void 0,children:e}),r&&P(`span`,{className:`settings-disclosure-hint`,children:r})]}),n!=null&&P(`bdi`,{dir:`ltr`,className:`settings-disclosure-count`,children:n})]}),P(`div`,{className:`settings-disclosure-body`,children:o})]})}var CN=g(Tc()?`settings.desktop.menuBar`:`settings.desktop.tray`),wN=[{key:`minimizeToTray`,label:`settings.desktop.keepRunning`,hint:`settings.desktop.keepRunningHint`},{key:`startOnLogin`,label:`settings.desktop.startOnLogin`,hint:`settings.desktop.startOnLoginHint`},{key:`startMinimized`,label:`settings.desktop.startMinimized`,hint:`settings.desktop.startMinimizedHint`}],TN=new Set([`startMinimized`]),EN={minimizeToTray:`settings.desktop.keepRunningNoTray`};function DN(e){return e?.reason===`no-host`?`settings.desktop.noTray`:e?.reason===`check-failed`?`settings.desktop.noTrayCheckFailed`:null}function ON(){let e=T(),t=window.gaiaAPI?.tray,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null);(0,X.useEffect)(()=>{t&&t.getConfig().then(e=>{r(e.tray),a(e.host)}).catch(t=>s(e(`settings.desktop.readFailed`,{reason:t instanceof Error?t.message:String(t)})))},[t,e]);let u=(0,X.useCallback)(async e=>{if(t&&n&&c===null){l(e),s(null);try{let i=await t.setConfig({tray:{[e]:!n[e]}});r(i.tray),a(i.host)}catch(e){s(e instanceof Error?e.message:String(e))}finally{l(null)}}},[t,n,c]);if(!t)return null;let d=DN(i);return P(SN,{title:e(`settings.desktop.title`),children:V(`div`,{className:`settings-field`,role:`group`,"aria-labelledby":`desktop-app-label`,children:[P(`span`,{className:`settings-label`,id:`desktop-app-label`,children:e(`settings.desktop.title`)}),wN.map(({key:t,label:r,hint:i})=>{let a=TN.has(t)?d:null,o=d&&EN[t]||i;return V(`div`,{children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(r,{tray:CN})}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,role:`switch`,checked:!a&&!!n?.[t],"aria-describedby":`desktop-${t}-hint`,onChange:()=>void u(t),disabled:!!a||!n||c!==null&&c!==t,"aria-busy":c===t,"aria-label":e(r,{tray:CN})}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,id:`desktop-${t}-hint`,children:a?e(a):e(o,{tray:CN})})]},t)}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o})]})})}function kN(){return window.gaiaUpdater}var AN={status:`idle`,version:null,progress:0,releaseNotes:null,error:null,currentVersion:null,pinnedVersion:null,autoUpdate:!1,includePrereleases:!1};function jN(){let[e,t]=(0,X.useState)({...AN});return(0,X.useEffect)(()=>{let e=kN();if(!e)return;let n=!0;e.getStatus().then(e=>{n&&e&&t(e)}).catch(()=>{});let r=e.onStatusChange(e=>{n&&e&&t(e)});return()=>{n=!1;try{r()}catch{}}},[]),e}var MN=`gaia-update-error:`;function NN(e,t){let n=`update.err.${e}`;return N(n)?g(n,t??{}):null}function PN(e){let t=e instanceof Error?e.message:String(e),n=t.indexOf(MN);if(n<0)return t.replace(/^Error invoking remote method '[^']+': (?:Error: )?/,``);let r;try{r=JSON.parse(t.slice(n+18))}catch{return t.slice(0,n)+t.slice(n+18)}let i=NN(r.code,r.params)??r.message??r.code,a=r.note&&NN(r.note.code,r.note.params);return a?g(`update.err.withNote`,{error:i,note:a}):i}function FN(e,t){let n=PN(e);return typeof n==`object`?t(n.ref,n.params):String(n)}function IN(){return window.gaiaUpdater}function LN({onClose:e}){let t=T(),[n,r]=(0,X.useState)({kind:`loading`}),i=(0,X.useRef)(null);(0,X.useEffect)(()=>{let e=IN();e?e.listReleases().then(e=>{r(Array.isArray(e)?{kind:`list`,releases:e}:{kind:`error`,message:e.error})}).catch(()=>{r({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})}):r({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})},[]),Io(!0,e),sS(i,!0),(0,X.useEffect)(()=>{let e=i.current;e&&e.querySelector(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`)?.focus()},[]),(0,X.useEffect)(()=>{let e=i.current;if(!e)return;function t(t){if(t.key!==`Tab`||!e)return;let n=e.querySelectorAll(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`);if(n.length===0)return;let r=n[0],i=n[n.length-1];t.shiftKey?document.activeElement===r&&(t.preventDefault(),i?.focus()):document.activeElement===i&&(t.preventDefault(),r?.focus())}return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[]);function a(e,t){e.isCurrent||r({kind:`confirm`,release:e,releases:t})}async function o(n){r({kind:`installing`});let i=IN();if(!i)r({kind:`error`,message:t(`update.picker.noBridge`)});else try{await i.installVersion(n.tag),e()}catch(e){r({kind:`error`,message:t(`update.picker.failed`,{reason:PN(e)})})}}function s(e){if(!e)return``;try{return new Date(e).toLocaleDateString(te(t),{year:`numeric`,month:`short`,day:`numeric`})}catch{return e}}return P(`div`,{className:`version-picker-overlay`,onClick:t=>{t.target===t.currentTarget&&e()},children:V(`div`,{className:`version-picker-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`update.picker.title`),ref:i,children:[V(`div`,{className:`version-picker-header`,children:[P(`h3`,{children:t(`update.picker.title`)}),P(`button`,{className:`version-picker-close`,onClick:e,"aria-label":t(`update.picker.close`),type:`button`,children:`×`})]}),V(`div`,{className:`version-picker-body`,children:[n.kind===`loading`&&V(`div`,{className:`version-picker-loading`,"aria-busy":`true`,children:[P(`span`,{className:`version-picker-spinner`}),t(`update.picker.loading`)]}),n.kind===`error`&&V(`div`,{className:`version-picker-error`,children:[P(`p`,{children:n.message}),P(`p`,{children:P(`a`,{href:`https://github.com/amd/gaia/releases`,target:`_blank`,rel:`noreferrer`,children:t(`update.picker.browse`)})})]}),n.kind===`list`&&P(`ul`,{className:`version-picker-list`,role:`listbox`,"aria-label":t(`update.picker.listAria`),children:n.releases.map(e=>P(`li`,{children:V(`button`,{type:`button`,className:`version-picker-row`,"data-version":e.version,"aria-label":e.isCurrent?t(`update.picker.rowInstalled`,{version:e.version}):e.isPinned?t(`update.picker.rowPinned`,{version:e.version}):e.version,"aria-disabled":e.isCurrent?`true`:`false`,onClick:()=>a(e,n.releases),disabled:e.isCurrent,children:[P(`span`,{className:`vp-version`,children:e.version}),P(`span`,{className:`vp-date`,children:s(e.date)}),e.isCurrent&&P(`span`,{className:`vp-badge vp-badge-current`,children:t(`update.picker.installed`)}),e.isPinned&&!e.isCurrent&&P(`span`,{className:`vp-badge vp-badge-pinned`,children:t(`update.picker.pinned`)}),!e.isCurrent&&P(`span`,{className:`vp-arrow`,"aria-hidden":`true`,children:`›`})]})},e.tag))}),n.kind===`list`&&V(`p`,{className:`version-picker-more`,children:[t(`update.picker.recent`,{n:n.releases.length}),` `,P(`a`,{href:`https://github.com/amd/gaia/releases`,target:`_blank`,rel:`noreferrer`,children:t(`update.picker.browseAll`)})]}),n.kind===`confirm`&&V(`div`,{className:`version-picker-confirm`,children:[P(`p`,{children:t(`update.picker.confirm`,{version:n.release.version})}),P(`p`,{className:`vp-confirm-note`,children:t(`update.picker.confirmNote`,{version:n.release.version})}),V(`div`,{className:`vp-confirm-actions`,children:[P(`button`,{type:`button`,className:`vp-btn-cancel`,onClick:()=>r({kind:`list`,releases:n.releases}),children:t(`update.picker.back`)}),P(`button`,{type:`button`,className:`vp-btn-confirm`,onClick:()=>o(n.release),children:t(`update.picker.install`)})]})]}),n.kind===`installing`&&V(`div`,{className:`version-picker-loading`,"aria-busy":`true`,children:[P(`span`,{className:`version-picker-spinner`}),t(`update.picker.starting`)]})]})]})})}var RN=`https://github.com/amd/gaia/releases`;function zN(e){return/^\d+\.\d+\.\d+-/.test(e??``)}function BN(e,t){let n=e.version??``;switch(e.status){case`checking`:return t(`update.status.checking`);case`available`:return t(`update.status.available`,{version:n});case`downloading`:return e.preparing?t(`update.status.preparing`,{version:n}):t(`update.status.downloading`,{version:n,pct:e.progress});case`downloaded`:return t(`update.status.downloaded`,{version:n});case`error`:return t(`update.status.error`,{reason:e.error??t(`update.status.unknownError`)});case`no-channel`:return e.error??t(`update.status.noChannel`);case`disabled`:return t(`update.status.disabled`);default:return t(`update.status.upToDate`)}}function VN(){let e=jN(),t=T(),n=kN(),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1);if(!n)return null;async function l(e,r){if(n){i(!0),o(null);try{await r(n)}catch(n){d.system.error(`${e} failed`,n),o(t(`update.settings.failed`,{action:g(e),reason:PN(n)}))}finally{i(!1)}}}let u=e.status===`disabled`,f=r||e.status===`checking`||e.status===`downloading`,p=`${t(`update.settings.running`,{version:e.currentVersion??t(`update.settings.unknownVersion`)})} ${BN(e,t)}`,m=[`available`,`downloaded`,`error`].includes(e.status)||!!e.pinnedVersion||!!e.installFailed||!!e.configError||!!a;return P(SN,{title:t(`update.settings.title`),titleId:`updates-label`,hint:p,forceOpen:m,children:V(`div`,{className:`settings-field`,role:`group`,"aria-labelledby":`updates-label`,children:[P(`p`,{className:`visually-hidden`,role:`status`,children:p}),V(`label`,{className:`setting-row`,children:[P(`span`,{children:t(`update.settings.auto`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,role:`switch`,checked:e.autoUpdate,"aria-describedby":`updates-auto-hint`,"aria-label":t(`update.settings.auto`),"aria-busy":r,disabled:u,onChange:()=>{r||l(`update.action.saveAuto`,t=>t.setAutoUpdate(!e.autoUpdate))}}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,id:`updates-auto-hint`,children:t(`update.settings.autoHint`)}),V(`label`,{className:`setting-row`,children:[P(`span`,{children:t(`update.settings.rc`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,role:`switch`,checked:!!e.includePrereleases,"aria-describedby":`updates-rc-hint`,"aria-label":t(`update.settings.rc`),"aria-busy":r,disabled:u,onChange:()=>{r||l(`update.action.saveRc`,t=>t.setIncludePrereleases(!e.includePrereleases))}}),P(`span`,{className:`toggle-track`})]})]}),V(`p`,{className:`settings-hint`,id:`updates-rc-hint`,children:[t(`update.settings.rcHint`),zN(e.currentVersion)&&` ${t(`update.settings.rcHintRunning`)}`]}),e.pinnedVersion&&V(`p`,{className:`settings-hint`,children:[t(`update.settings.pinned`,{version:e.pinnedVersion}),` `,P(`button`,{type:`button`,className:`btn-secondary`,disabled:r,onClick:()=>void l(`update.action.resume`,e=>e.resumeUpdates()),children:t(`update.settings.unpin`)})]}),V(`div`,{className:`setting-actions`,children:[e.status===`available`&&!e.pinnedVersion&&P(`button`,{type:`button`,className:`btn-primary`,disabled:r,onClick:()=>void l(`update.action.download`,e=>e.downloadUpdate()),children:t(`update.settings.updateTo`,{version:e.version??``})}),e.status===`downloaded`&&P(`button`,{type:`button`,className:`btn-primary`,disabled:r,onClick:()=>void l(`update.action.restart`,e=>e.restart()),children:t(`update.settings.restart`)}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:f||u,onClick:()=>void l(`update.action.check`,e=>e.check()),children:t(`update.settings.check`)}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:f||u,onClick:()=>c(!0),children:t(`update.settings.pick`)}),e.previousVersion&&P(`button`,{type:`button`,className:`btn-secondary`,"aria-describedby":`updates-back-hint`,disabled:f||u,onClick:()=>void l(`update.action.goBack`,e=>e.revertUpdate()),children:t(`update.settings.goBack`,{version:e.previousVersion})})]}),e.previousVersion&&P(`p`,{className:`settings-hint`,id:`updates-back-hint`,children:t(`update.settings.goBackHint`)}),e.installFailed&&P(`p`,{className:`settings-error`,role:`alert`,children:t(`update.settings.installFailed`,{...e.installFailed,url:RN})}),e.lastCheckError&&P(`p`,{className:`settings-hint`,children:t(`update.settings.lastCheckError`,{reason:e.lastCheckError})}),e.configError&&P(`p`,{className:`settings-error`,role:`alert`,children:e.configError}),a&&P(`p`,{className:`settings-error`,role:`alert`,children:a}),s&&P(LN,{onClose:()=>c(!1)})]})})}var HN=[{value:`light`,label:`settings.theme.light`},{value:`dark`,label:`settings.theme.dark`},{value:`system`,label:`settings.theme.system`}],UN={default:`palette.default`,stone:`palette.stone`,marble:`palette.marble`,glacier:`palette.glacier`,forest:`palette.forest`,sage:`palette.sage`,basalt:`palette.basalt`,gold:`palette.gold`,dusk:`palette.dusk`,custom:`settings.colors.custom`},WN=[[`Enter`,`settings.shortcut.send`],[`Shift+Enter`,`settings.shortcut.newLine`],[`Esc`,`settings.shortcut.stop`],[`Mod+Shift+O`,`settings.shortcut.newChat`],[`Mod+K`,`settings.shortcut.search`],[`Mod+B`,`settings.shortcut.sidebar`],[`Mod+,`,`settings.shortcut.settings`]];function GN(){let e=T(),t=k(e=>e.locale),n=k(e=>e.setLocale),r=k(e=>e.themePreference),i=k(e=>e.setThemePreference),a=k(e=>e.palette),o=k(e=>e.setPalette),s=k(e=>e.customColors),c=k(e=>e.setCustomColors),l=qO(e=>e.visible),u=qO(e=>e.setVisible),d=e=>t=>c({...s,[e]:t.target.value.toUpperCase()});return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.general`)}),V(`div`,{className:`settings-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`ui-language`,children:e(`settings.language`)}),P(`select`,{id:`ui-language`,className:`settings-input`,value:t,onChange:e=>n(e.target.value),children:b.map(({meta:e})=>P(`option`,{value:e.code,lang:e.code,dir:e.dir,children:M(e)},e.code))}),P(`span`,{className:`settings-hint`,children:e(`settings.languageHint`)})]}),V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,id:`appearance-label`,children:e(`settings.appearance`)}),P(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`appearance-label`,children:HN.map(t=>P(`button`,{type:`button`,role:`radio`,"aria-checked":r===t.value,className:r===t.value?`is-active`:``,onClick:()=>i(t.value),children:e(t.label)},t.value))})]}),V(`div`,{className:`settings-field`,children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`resources.settings`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),"aria-label":e(`resources.settings`),"aria-describedby":`resources-hint`}),P(`span`,{className:`toggle-track`})]})]}),P(`span`,{className:`settings-hint`,id:`resources-hint`,children:e(`resources.settingsHint`)})]}),V(SN,{title:e(`settings.colors`),titleId:`palette-label`,defaultOpen:a===`custom`,children:[V(`div`,{className:`palette-grid`,role:`radiogroup`,"aria-labelledby":`palette-label`,children:[oe.map(t=>V(`button`,{type:`button`,role:`radio`,"aria-checked":a===t.id,className:`palette-tile${a===t.id?` is-active`:``}`,onClick:()=>o(t.id),children:[P(`span`,{className:`palette-swatch`,"aria-hidden":`true`,children:t.swatch.map(e=>P(`i`,{style:{background:e}},e))}),e(UN[t.id])]},t.id)),V(`button`,{type:`button`,role:`radio`,"aria-checked":a===`custom`,className:`palette-tile${a===`custom`?` is-active`:``}`,onClick:()=>o(`custom`),children:[V(`span`,{className:`palette-swatch`,"aria-hidden":`true`,children:[P(`i`,{style:{background:s.base}}),P(`i`,{style:{background:s.accent}})]}),e(`settings.colors.custom`)]})]}),a===`custom`&&V(`div`,{className:`palette-custom`,children:[V(`label`,{className:`palette-color`,htmlFor:`custom-accent`,children:[P(`input`,{id:`custom-accent`,type:`color`,value:s.accent,onChange:d(`accent`)}),V(`span`,{children:[e(`settings.colors.accent`),P(`small`,{children:e(`settings.colors.accentHint`)})]})]}),V(`label`,{className:`palette-color`,htmlFor:`custom-base`,children:[P(`input`,{id:`custom-base`,type:`color`,value:s.base,onChange:d(`base`)}),V(`span`,{children:[e(`settings.colors.base`),P(`small`,{children:e(`settings.colors.baseHint`)})]})]}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>c(v),children:e(`settings.colors.reset`)}),P(`p`,{className:`settings-hint`,children:e(`settings.colors.hint`)})]})]}),P(ON,{}),P(VN,{}),P(SN,{title:e(`settings.shortcuts`),children:P(`dl`,{className:`shortcut-list`,children:WN.map(([t,n])=>V(`div`,{className:`shortcut-row`,children:[P(`dt`,{children:P(`kbd`,{children:kc(t)})}),P(`dd`,{children:e(n)})]},t))})})]})}function KN(e){return/not reachable|not answering|model server at|ConnectionPool|NewConnectionError|Connection refused|Max retries/i.test(e)}function qN(e){return/gaia init/i.test(e??``)}function JN(e){return!!e&&!e.lemonade_running&&(qN(e.start_command)||qN(e.start_instruction))}function YN({className:e=`btn-secondary`}){let t=T();return P(`button`,{type:`button`,className:e,onClick:()=>window.dispatchEvent(new CustomEvent(`gaia:set-up-local`)),children:t(`settings.errors.setUpLocal`)})}function XN({message:e,onRetry:t}){let n=T(),r=k(e=>JN(e.systemStatus));return KN(e)?V(`div`,{className:`settings-notice`,role:`alert`,children:[P(`strong`,{children:n(r?`settings.errors.notInstalledTitle`:`settings.errors.serverDownTitle`)}),P(`p`,{children:n(r?`settings.errors.notInstalled`:`settings.errors.serverDown`)}),r&&P(YN,{className:`btn-primary`}),t&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:t,children:n(`settings.key.checkAgain`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,n(`settings.errors.details`)]}),P(`bdi`,{dir:`ltr`,className:`settings-notice-raw`,children:e})]})]}):P(`p`,{className:`settings-error`,role:`alert`,children:e})}function ZN({onAdded:e}){let t=T(),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),f=(0,X.useRef)(``),p=(0,X.useCallback)(async e=>{let t=n.trim();f.current=t,l(`check`),d(null);try{let n=await cn(t,e);if(f.current!==t)return;s(n),a(n.file??e)}catch(e){if(f.current!==t)return;s(null),d(e instanceof Error?e.message:String(e))}finally{l(null)}},[n]),m=(0,X.useCallback)(async()=>{l(`add`),d(null);try{let{report:o}=await xt(n.trim(),i);r(``),a(``),s(null),e(o.display_name??o.model_id??t(`settings.custom.theModel`))}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(null)}},[e,i,n,t]);return V(`form`,{className:`settings-field custom-model-add`,onSubmit:e=>{e.preventDefault(),p(``)},children:[P(`label`,{className:`visually-hidden`,htmlFor:`custom-model-url`,children:t(`settings.custom.title`)}),P(`span`,{className:`settings-hint`,children:t(`settings.custom.hint`)}),V(`div`,{className:`settings-row`,children:[P(`input`,{id:`custom-model-url`,className:`settings-input`,type:`url`,inputMode:`url`,dir:`ltr`,spellCheck:!1,autoComplete:`off`,value:n,readOnly:c!==null,onChange:e=>{r(e.target.value),s(null),a(``),f.current=``},placeholder:`https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF`}),V(`button`,{type:`submit`,className:`btn-secondary`,disabled:c!==null||!n.trim(),children:[c===`check`?P(q,{size:13,className:`spin`}):null,` `,t(`settings.custom.check`)]})]}),o&&(()=>{let e=P(`ul`,{className:`custom-model-checks`,"aria-label":t(`settings.custom.checks`),children:o.checks.map(e=>V(`li`,{className:e.ok?`is-ok`:`is-failed`,children:[e.ok?P(mr,{size:13,"aria-label":t(`settings.custom.passed`)}):P(Y,{size:13,"aria-label":t(`settings.custom.failed`)}),V(`bdi`,{children:[P(`strong`,{children:e.label}),` — `,e.detail]})]},e.id))});return o.ok?V(`details`,{className:`custom-model-checks-summary`,children:[V(`summary`,{children:[P(mr,{size:13,"aria-hidden":`true`}),` `,t(`settings.custom.allPassed`,{n:o.checks.length})]}),e]}):e})(),o&&o.warnings.length>0&&P(`ul`,{className:`custom-model-checks`,"aria-label":t(`settings.custom.warnings`),children:o.warnings.map(e=>V(`li`,{className:`is-warning`,children:[P(J,{size:13,"aria-label":t(`settings.custom.warning`)}),` `,P(`bdi`,{children:e})]},e))}),o&&o.variants.length>1&&V(`div`,{className:`settings-row`,children:[P(`label`,{className:`settings-hint`,htmlFor:`custom-model-quant`,children:t(`settings.custom.quantization`)}),P(`select`,{id:`custom-model-quant`,className:`settings-input`,value:i,onChange:e=>void p(e.target.value),disabled:c!==null,children:o.variants.map(e=>V(`option`,{value:e.file,children:[e.quant,` · `,e.size_gb,` GB`,e.fits?``:` · ${t.bare(`settings.custom.tooLarge`)}`]},e.file))})]}),o?.ok&&V(`div`,{className:`settings-row`,children:[V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void m(),disabled:c!==null,children:[c===`add`?P(q,{size:13,className:`spin`}):null,` `,t(`settings.custom.add`,{name:o.display_name??``})]}),P(`span`,{className:`settings-hint`,children:t(`settings.model.sizeDownload`,{size:`${o.size_gb} GB`})})]}),u&&P(XN,{message:u})]})}function QN(e){return e instanceof Error?e.message:String(e)}function $N(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function eP({downloadsSlot:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),b=Ls(e=>e.status),x=Ls(e=>e.started),S=(0,X.useMemo)(()=>Ps(b,x),[b,x]),C=Ls(e=>e.error),w=Ls(e=>e.refresh),E=Ls(e=>e.enqueue),O=Ls(e=>e.cancel),k=(0,X.useCallback)(async(e=!1)=>{a(null);try{let t=await Ce();r(t),s(n=>e||!n?fj(t):n)}catch(e){a(QN(e))}},[]);(0,X.useEffect)(()=>{k(!0),w(),(async()=>{try{_(await Nn()??null)}catch(e){y(QN(e))}})()},[k,w]);let A=(S?.models??[]).filter(e=>e.state===`ready`).map(e=>e.id).join(`,`),j=(0,X.useRef)(A);(0,X.useEffect)(()=>{A!==j.current&&(j.current=A,k(!0))},[A,k]);let M=(0,X.useMemo)(()=>{let e={};for(let t of S?.models??[])e[t.id]=t;return e},[S]),N=(0,X.useMemo)(()=>{let e={};for(let t of n?.catalog??[])e[t.id]=t.name;return e},[n]),F=(0,X.useMemo)(()=>n?fj(n):null,[n]),I=ZA(n),L=n&&o?_j(I,o).filter(e=>M[e.id]?.state!==`downloading`):[],ee=L.reduce((e,t)=>e+(t.size_gb??0),0),R=!!n&&!!o&&!!F&&(!$N(o.ticked,F.ticked)||o.defaultChat!==F.defaultChat||L.length>0),z=(0,X.useCallback)(async(e,i)=>{if(!n||!o)return;if(p(null),!e){let e=bj(I,o).filter(e=>!e.downloaded||e.id===o.defaultChat);if(e.length>0&&e.every(e=>e.need_gb!=null)){l({kind:`no_fit`,models:e});return}}let a=yj(n,o);if(a&&!i)l({kind:`low_disk`,message:a.drop?t(`setup.summary.shortDrop`,{need:$(a.needGb),free:$(a.freeGb),drive:Pj(n.disk?.path??null)??t(`setup.summary.theDrive`),freeUp:$(a.freeUpGb),name:a.drop.name,saves:$(a.drop.size_gb??0)}):t(`setup.summary.short`,{need:$(a.needGb),free:$(a.freeGb),drive:Pj(n.disk?.path??null)??t(`setup.summary.theDrive`),freeUp:$(a.freeUpGb)})});else{d(!0);try{let i=n;if(o.defaultChat&&o.defaultChat!==i.chat_model.id)try{i=await Le(o.defaultChat,e||m)}catch(e){let t=ht(e);if(t){l({kind:`server`,detail:t});return}throw e}for(let e of xj(i,o))i=await ft(e.id,e.skipped);let a=_j(ZA(i),o).map(e=>e.id).filter(e=>M[e]?.state!==`downloading`);r(i),s({...o,defaultChat:i.chat_model.id}),cs.getState().refresh(),a.length&&await E(a,{acknowledgeLowDisk:!0}),p({ok:!0,text:t(`settings.models.applied`)})}catch(e){p({ok:!1,text:QN(e)})}finally{d(!1)}}},[n,o,I,m,M,E,t]),B=(0,X.useCallback)(async e=>{l(null),d(!0),p(null);try{let n=await dn(e.id);Uo(),r(n),s(fj(n)),p({ok:!0,text:t(`settings.models.removed`,{name:e.name,size:$(n.freed_gb)})})}catch(e){p({ok:!1,text:QN(e)})}finally{d(!1)}},[t]),te=(0,X.useCallback)((e,t)=>{(async()=>{try{t===`verify`&&await dn(e),await E([e])}catch(e){p({ok:!1,text:QN(e)})}})()},[E]),ne=!!S&&(S.models?.length??0)>0&&(CM(S)||S.models.some(e=>e.state!==`skipped`))&&S&&V(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-downloads-title`,children:[P(`span`,{className:`settings-label`,id:`settings-downloads-title`,children:t(`settings.models.downloads`)}),P(EM,{status:S,names:N,freeGb:n?.disk?.free_gb??null,onCancel:()=>void O(),onRetry:te,onResume:e=>void E([e]),onResumeAll:()=>void E((S.models??[]).filter(e=>e.state===`cancelled`).map(e=>e.id))}),C&&P(`p`,{className:`settings-error`,role:`alert`,children:C})]});return V(D.Fragment,{children:[P(SN,{title:t(`settings.models.manage`),hint:t(`settings.models.manageHint`),forceOpen:!!i||f?.ok===!1,children:V(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-models-title`,children:[P(`span`,{className:`visually-hidden`,id:`settings-models-title`,children:t(`settings.models.title`)}),P(`p`,{className:`settings-hint`,children:t(`settings.models.lede`)}),i&&P(XN,{message:i}),n&&!n.lemonade.reachable&&P(`p`,{className:`settings-hint`,children:t(`settings.models.unavailable`)}),!n&&!i&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,t(`setup.models.loading`)]}),n&&n.lemonade.reachable&&o&&V(D.Fragment,{children:[P(Ij,{plan:n,selection:o,onToggle:(e,t)=>s(mj(o,I,e,t)),onDefaultChat:e=>s(hj(o,I,e)),labelledBy:`settings-models-title`,place:`settings`,disabled:u,progress:M,rowActions:e=>e.downloaded&&e.id!==o.defaultChat?P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>l({kind:`remove`,entry:e}),disabled:u||M[e.id]?.state===`downloading`,"aria-label":t(`settings.models.removeAria`,{name:e.name}),children:t(`settings.models.remove`)}):null}),P(Nj,{plan:n,selection:o}),P(`div`,{className:`models-apply`,children:V(`button`,{type:`button`,className:`btn-primary`,disabled:!R||u,onClick:()=>void z(!1,!1),children:[u&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),u?t(`settings.models.applying`):L.length>0?t(`settings.models.applyDownload`,{size:$(Math.round(ee*10)/10)}):t(`settings.models.apply`)]})})]}),f?.ok&&P(`p`,{className:`settings-ok`,role:`status`,children:f.text}),f&&!f.ok&&P(XN,{message:f.text})]})}),(g?.applies||v&&!KN(v))&&P(SN,{title:t(`gpu.settingsTitle`),titleId:`settings-gpu-title`,defaultOpen:!!g?.pending||!!v,children:V(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-gpu-title`,children:[v&&P(`p`,{className:`settings-error`,role:`alert`,children:v}),g?.applies&&P(tM,{status:g,onStatus:_,mode:`settings`,names:N,headingId:`settings-gpu-title`})]})}),e?(0,eS.createPortal)(ne,e):e===void 0&&ne,c?.kind===`remove`&&P(Kj,{title:t(`settings.models.removeTitle`,{name:c.entry.name}),confirmLabel:t(`settings.models.removeConfirm`),cancelLabel:t(`settings.models.keep`),danger:!0,onConfirm:()=>void B(c.entry),onCancel:()=>l(null),children:P(`p`,{children:QA(c.entry)?t(`settings.models.removeVision`,{size:$(c.entry.full_size_gb??0)}):t(`settings.models.removeBody`,{size:$(c.entry.full_size_gb??0)})})}),c?.kind===`no_fit`&&P(Kj,{title:c.models.length===1?t(`setup.confirm.noFitOne`,{name:c.models[0].name}):t(`setup.confirm.noFitMany`),confirmLabel:t(`setup.confirm.downloadAnyway`),cancelLabel:t(`setup.confirm.pickSmaller`),onConfirm:()=>{l(null),h(!0),z(!0,!1)},onCancel:()=>l(null),children:c.models.map(e=>V(`p`,{children:[P(`bdi`,{children:e.name}),`: `,Aj(e,t)]},e.id))}),c?.kind===`low_disk`&&P(Kj,{title:t(`setup.confirm.lowDiskTitle`),confirmLabel:t(`setup.confirm.downloadAnyway`),cancelLabel:t(`setup.confirm.changeModels`),onConfirm:()=>{l(null),z(!0,!0)},onCancel:()=>l(null),children:P(`p`,{children:c.message})}),c?.kind===`server`&&P(Kj,{title:t(`setup.confirm.noFitServerTitle`),confirmLabel:t(`setup.confirm.useAnyway`),cancelLabel:t(`setup.confirm.changeModels`),onConfirm:()=>{l(null),h(!0),z(!0,!1)},onCancel:()=>l(null),children:P(`p`,{children:c.detail.message})})]})}var tP=`auto`;function nP({model:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null);(0,X.useEffect)(()=>{r(null),a(null),l(null),_e(e).then(r).catch(e=>a(e instanceof Error?e.message:String(e)))},[e]);let u=(0,X.useCallback)(async n=>{s(!0),a(null),l(null);try{let i=await Ke(e,n===tP?null:Number(n));r(i);let a={name:i.display_name,size:i.chosen?Cs(i.chosen):g(`settings.ctx.automaticSize`)},o=i.reload?.reason;i.reload?.started?l(t(`settings.ctx.reloading`,a)):l(o===`already_loaded`?t(`settings.ctx.alreadyLoaded`,a):o===`warm_up`?t(`settings.ctx.warmUp`,a):o===`busy`?t(`settings.ctx.busy`,a):o===`not_gaias_server`?t(`settings.ctx.ownServer`,a):t(o===`restarting`?`settings.ctx.restarting`:`settings.ctx.nextLoad`))}catch(e){a(e instanceof Error?e.message:String(e))}finally{s(!1)}},[e,t]);if(i&&!n)return KN(i)?P(`p`,{className:`settings-hint`,children:t(`settings.ctx.serverDown`)}):P(`p`,{className:`settings-error`,role:`alert`,children:i});if(!n)return V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.ctx.checking`)]});let d=n.chosen==null?tP:String(n.chosen),f=n.chosen!=null&&n.loaded_ctx!=null&&n.loaded_ctx!==n.chosen;return V(D.Fragment,{children:[V(`div`,{className:`model-in-use-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`ctx-size`,children:t(`settings.ctx.label`)}),V(`select`,{id:`ctx-size`,className:`settings-input`,value:d,onChange:e=>void u(e.target.value),disabled:o||n.options.length===0,children:[P(`option`,{value:tP,children:n.automatic?t.bare(`settings.ctx.automaticAt`,{size:Cs(n.automatic)}):t.bare(`settings.ctx.automatic`)}),n.options.map(e=>P(`option`,{value:String(e),children:t.bare(`settings.ctx.tokens`,{size:Cs(e)})},e))]})]}),n.note&&P(`span`,{className:`settings-hint`,children:P(`bdi`,{children:n.note})}),!n.note&&!!n.max_fit&&V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.ctx.about`)]}),P(`span`,{className:`settings-hint`,children:t(`settings.ctx.explain`,{size:Cs(n.max_fit),name:n.display_name,memory:n.memory_source})})]}),f&&P(`span`,{className:`settings-hint`,children:t(`settings.ctx.loadedAt`,{size:Cs(n.loaded_ctx)})}),o&&V(`span`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.ctx.applying`)]}),c&&P(`p`,{className:`settings-ok`,role:`status`,children:c}),i&&P(`p`,{className:`settings-error`,role:`alert`,children:i})]})}function rP({row:e,providerName:t,choices:n,labels:r,disabled:i,onSwitch:a}){let o=T(),s=cs(e=>e.active),c=s?.model??null,l=!!s?.remote,u=n.some(e=>us(c,e.id)),d=s?.downloaded??e?.downloaded,f=l?null:e?.state===`loaded`?o(`settings.model.loaded`):d===!0?o(`settings.model.downloaded`):d===!1?o(`settings.model.notDownloaded`):null,p=e?.placement?.device;return V(`section`,{className:`settings-card model-in-use`,"aria-label":o(`settings.model.inUseTitle`),children:[P(`span`,{className:`model-in-use-label`,children:o(`settings.model.inUseTitle`)}),c?P(`bdi`,{className:`model-in-use-name`,title:c,children:e?.display_name||s?.display_name||ds(c)}):P(`span`,{className:`settings-hint`,children:o(`settings.model.noneInUse`)}),s?.config_error&&P(`p`,{className:`settings-error`,role:`alert`,children:P(`bdi`,{children:s.config_error})}),c&&!l&&e?.available===!1&&P(`p`,{className:`settings-error`,role:`alert`,children:o(`settings.model.inUseCantRun`)}),c&&V(`span`,{className:`model-chips`,children:[l&&P(`span`,{className:`model-badge is-device`,children:o(`settings.model.cloud`)}),l&&t&&P(`bdi`,{className:`model-badge is-ready`,children:t}),p&&P(`span`,{className:`model-badge is-device`,children:p.toUpperCase()}),f&&P(`span`,{className:`model-badge ${e?.state===`loaded`?`is-loaded`:`is-ready`}`,children:f}),e?.fits===!0&&P(`span`,{className:`model-badge is-fit`,children:o(`settings.model.fits`)}),!!e?.size_gb&&V(`bdi`,{dir:`ltr`,className:`model-badge is-size`,children:[e.size_gb,` GB`]}),l&&!!e?.context_length&&P(`span`,{className:`model-badge is-ready`,children:o(`settings.model.contextChip`,{size:Cs(e.context_length)})})]}),(n.length>1||n.length===1&&!u)&&V(`div`,{className:`model-in-use-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`model-switch`,children:o(`settings.model.switch`)}),V(`select`,{id:`model-switch`,className:`settings-input`,value:u?n.find(e=>us(c,e.id))?.id:``,onChange:e=>a(e.target.value),disabled:i,children:[!u&&P(`option`,{value:``,disabled:!0,children:o.bare(`settings.model.switchPlaceholder`)}),n.map(e=>P(`option`,{value:e.id,children:r[e.id]},e.id))]})]}),c&&!l&&s?.downloaded!==!1&&P(nP,{model:c})]})}function iP({model:e,label:t,current:n,remote:r,busy:i,confirmingRemove:a,onUse:o,onDownload:s,onAskRemove:c,onKeep:l,onRemove:u,onNpuRecheck:d}){let f=T(),p=Ts(e)?e.download_progress:null,m=e.placement?.label,h=f.compose(t=>[m&&(e.placement?.source===`expected`?t(`settings.model.expected`,{label:m}):m),e.size_gb?t(e.downloaded?`settings.model.sizeOnDisk`:`settings.model.sizeDownload`,{size:`${e.size_gb} GB`}):null,e.tokens_per_second?t(`settings.model.speed`,{speed:`${Math.round(e.tokens_per_second)} tok/s`}):null,!e.placement&&e.context_length?t(`settings.model.contextTokens`,{size:e.context_length.toLocaleString()}):null].filter(Boolean).join(` · `)),g=!!(e.display_name||h||e.evidence||e.custom&&e.source_url);return V(`li`,{className:`model-row${n?` is-current`:``}`,children:[V(`div`,{className:`model-row-text`,children:[P(`bdi`,{className:`model-row-name`,title:e.id,children:t}),V(`div`,{className:`model-chips`,children:[e.placement?.device&&P(`span`,{className:`model-badge is-device`,children:e.placement.device.toUpperCase()}),e.rank&&V(`span`,{className:`model-badge is-rank`,children:[V(`bdi`,{dir:`ltr`,children:[`#`,e.rank]}),` `,e.note]}),e.state===`loaded`&&P(`span`,{className:`model-badge is-loaded`,children:f(`settings.model.loaded`)}),e.fits===!0&&e.available!==!1&&P(`span`,{className:`model-badge is-fit`,children:f(`settings.model.fits`)}),e.custom&&P(`span`,{className:`model-badge is-custom`,children:f(`settings.model.custom`)}),!!e.size_gb&&V(`bdi`,{dir:`ltr`,className:`model-badge is-size`,children:[e.size_gb,` GB`]}),g&&V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,f(`settings.model.details`)]}),e.display_name&&P(`span`,{className:`model-row-meta`,children:P(`bdi`,{children:e.id})}),h&&P(`span`,{className:`model-row-meta`,children:h}),e.evidence&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.measured`,{evidence:e.evidence})}),e.custom&&e.source_url&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.from`,{url:e.source_url})})]})]}),r&&P(`span`,{className:`model-row-meta${e.price?``:` is-unknown-price`}`,children:QT(e.price,f)}),e.placement?.warning&&P(`span`,{className:`model-row-meta is-warning`,role:`alert`,children:P(`bdi`,{children:e.placement.warning})}),e.npu_problems?.length?P(PM,{problems:e.npu_problems,disabled:i!==null,onRecheck:d,id:`npu-problems-${e.id}`}):e.unavailable_reason&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.cantRun`,{reason:e.unavailable_reason})}),p&&P(`progress`,{max:100,value:p.percent,"aria-label":f(`settings.model.downloadingAria`,{name:t})})]}),V(`div`,{className:`model-row-actions`,children:[e.custom&&!n&&!p&&(a?V(D.Fragment,{children:[V(`button`,{type:`button`,className:`btn-danger`,onClick:u,disabled:i!==null,children:[i===`rm:${e.id}`?P(q,{size:13,className:`spin`}):null,e.downloaded?f(`settings.model.removeDownload`):f(`settings.models.remove`)]}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:l,disabled:i!==null,children:f(`settings.models.keep`)})]}):P(`button`,{type:`button`,className:`btn-secondary`,onClick:c,disabled:i!==null,"aria-label":f(`settings.models.removeAria`,{name:t}),children:f(`settings.models.remove`)})),n&&e.available===!1?P(`span`,{className:`model-row-current is-blocked`,children:f(`settings.model.inUseBlocked`)}):n?V(`span`,{className:`model-row-current`,children:[P(mr,{size:13,"aria-hidden":`true`}),` `,f(`settings.model.inUse`)]}):e.available===!1?null:p?V(`span`,{className:`model-row-current`,children:[P(q,{size:13,className:`spin`}),` `,p.message?P(`bdi`,{children:p.message}):V(`bdi`,{dir:`ltr`,children:[Math.round(p.percent),`%`]})]}):e.downloaded?V(`button`,{type:`button`,className:`btn-secondary`,onClick:o,disabled:i!==null,"aria-label":f(`settings.model.useAria`,{name:t}),children:[i===e.id?P(q,{size:13,className:`spin`}):null,` `,f(`settings.model.use`)]}):V(`button`,{type:`button`,className:`btn-secondary`,onClick:s,disabled:i!==null,"aria-label":f(`settings.model.downloadAria`,{name:t}),children:[i===`dl:${e.id}`?P(q,{size:13,className:`spin`}):null,` `,f(`settings.model.download`)]})]})]})}function aP(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(!1),l=(0,X.useCallback)(async e=>{c(!0),i(null);try{let t=await e();n(t),o(t.limit_usd==null?``:String(t.limit_usd))}catch(e){i(e instanceof Error?e.message:String(e))}finally{c(!1)}},[]);if((0,X.useEffect)(()=>{l(H)},[l]),!t)return r?P(`p`,{className:`settings-error`,role:`alert`,children:r}):V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.spend.loading`)]});let u=t.limit_usd,d=a.trim()===``?null:Number(a),f=d===null||Number.isFinite(d)&&d>0,p=d!==u;return V(`section`,{className:`settings-field spending`,"aria-label":e(`settings.spend.aria`),children:[P(`span`,{className:`settings-label`,children:e(`settings.spend.title`)}),V(`p`,{className:`spending-total`,children:[P(`bdi`,{dir:`ltr`,children:P(`strong`,{children:$T(t.total_usd)})}),u!=null&&V(D.Fragment,{children:[` `,e(`settings.spend.ofLimit`,{limit:$T(u)})]}),V(`span`,{className:`settings-hint`,children:[` · `,e.plural(`settings.spend.turns`,t.turns)]})]}),t.unpriced_turns>0&&P(`p`,{className:`settings-hint`,children:e.plural(`settings.spend.unpriced`,t.unpriced_turns)}),t.unreported_turns>0&&P(`p`,{className:`settings-hint`,children:e.plural(`settings.spend.unreported`,t.unreported_turns)}),t.state===`near`&&V(`p`,{className:`spending-warning`,role:`status`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.near`)]}),t.state===`reached`&&V(`div`,{className:`spending-warning`,role:`alert`,children:[V(`p`,{children:[P(J,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.reached`)]}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void l(gn),children:e(`settings.spend.allow`)})]}),t.state===`allowed_over`&&P(`p`,{className:`settings-hint`,children:e(`settings.spend.allowed`)}),V(`form`,{className:`settings-row`,onSubmit:e=>{e.preventDefault(),f&&p&&l(()=>Qe(d))},children:[P(`label`,{className:`spending-limit-label`,htmlFor:`spend-limit`,children:e(`settings.spend.limit`)}),P(`input`,{id:`spend-limit`,className:`settings-input`,type:`number`,min:`0.01`,step:`0.01`,inputMode:`decimal`,placeholder:e.bare(`settings.spend.noLimit`),value:a,onChange:e=>o(e.target.value),"aria-invalid":!f}),V(`button`,{type:`submit`,className:`btn-secondary`,disabled:s||!f||!p,children:[s?P(q,{size:13,className:`spin`}):null,` `,e(`settings.advanced.save`)]}),u!=null&&P(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void l(()=>Qe(null)),children:e(`settings.spend.removeLimit`)})]}),P(`span`,{className:`settings-hint`,children:e(`settings.spend.how`)}),r&&P(`p`,{className:`settings-error`,role:`alert`,children:r})]})}var oP=2e3;function sP(e,t){return e.key_source===`environment`?t(`settings.key.setIn`,{name:e.env_var??``}):`••••••••••••••••••••${e.key_hint?` ${e.key_hint}`:``}`}function cP(){let e=T(),t=cs(e=>e.active),n=cs(e=>e.select),r=cs(e=>e.refresh),i=cs(e=>e.rememberNames),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),l=k(e=>e.settingsProvider),[u,d]=(0,X.useState)(l??t?.provider??`local`),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(!1),[w,E]=(0,X.useState)(!1),[O,A]=(0,X.useState)({base_url:``,auth_header_name:``,auth_header_prefix:``}),[j,M]=(0,X.useState)(null),[N,F]=(0,X.useState)(null),[I,L]=(0,X.useState)(null),[ee,R]=(0,X.useState)(null),[z,B]=(0,X.useState)(!1),[te,ne]=(0,X.useState)(null),[re,ie]=(0,X.useState)(null),ae=(0,X.useRef)(u);ae.current=u;let oe=(0,X.useRef)(!0);(0,X.useEffect)(()=>(oe.current=!0,()=>{oe.current=!1}),[]);let H=a?.find(e=>e.id===u)??null,U=e=>e?.network?.reachable===!1,se=e=>!!e?.blocked,W=!!H&&!se(H)&&(!H.remote||!!H.models_discovered),G=(0,X.useCallback)(async()=>{c(null);try{let e=await Tn();o(e.providers),e.lemonade_error&&c(e.lemonade_error)}catch(e){c(e instanceof Error?e.message:String(e))}},[]),ce=(0,X.useCallback)(async(t,n=!1)=>{n||(p(null),h(null));try{let n=await Zt(t);i(n.models),p(n.models),F(n.memory_gb?`${n.memory_gb} GB (${n.memory_source})`:n.capacity_error??null),n.blocked&&h(e(`settings.privacy.localOnlyBlocked`))}catch(e){h(e instanceof Error?e.message:String(e))}},[i,e]);(0,X.useEffect)(()=>{G()},[G]);let le=!!a?.some(e=>e.key_state===`waiting_for_os_permission`);(0,X.useEffect)(()=>{if(!le)return;let e=setInterval(()=>{G()},oP);return()=>clearInterval(e)},[le,G]);let ue=t?.provider;(0,X.useEffect)(()=>{ue&&!l&&d(ue)},[ue,l]),(0,X.useEffect)(()=>{x(``),C(!1),E(!1),L(null),_(``),y(!1),B(!1)},[u]),(0,X.useEffect)(()=>{W?ce(u):p(null)},[u,W,ce]);let de=(0,X.useCallback)(async()=>{if(H){M(`connect`),L(null);try{let t=u===`amd`?{api_key:b||void 0,...Object.fromEntries(Object.entries(O).filter(([,e])=>e!==``))}:{api_key:b||void 0},n=()=>!oe.current||ae.current!==u,r=await Rt(u,t,e=>{n()||L({ok:!0,text:e})},n);if(n())return;x(``),C(!1),L({ok:!0,text:r.remember_error?e(`settings.key.sessionOnly`,{reason:r.remember_error}):r.known_models?e(`settings.key.knownModels`,{name:H.name}):r.remembered?e(`settings.key.kept`):e(`settings.key.connectedDone`)}),await G()}catch(e){oe.current&&ae.current===u&&L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{oe.current&&M(null)}}},[O,u,b,G,H,e]),pe=(0,X.useCallback)(async()=>{M(`forget`),E(!1),L(null);try{await Kt(u),L({ok:!0,text:e(`settings.key.cleared`)}),await G(),await r()}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[u,G,r,e]),me=(0,X.useCallback)(async t=>{M(t),L(null);try{await n(t),L({ok:!0,text:e(`settings.model.switched`,{name:ds(t)})}),await ce(u,!0)}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[u,ce,n,e]),he=(0,X.useCallback)(async e=>{M(`dl:${e}`),L(null),B(!1);try{await fe(e),await ce(`local`,!0)}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[ce]),ge=(0,X.useCallback)(async t=>{M(`rm:${t}`),L(null);try{let n=await nt(t);R(null);let i=n.cleared.includes(`last_model`)?`settings.model.removedLast`:n.cleared.includes(`default_model`)?`settings.model.removedDefault`:`settings.model.removed`;L({ok:!0,text:e(i,{name:n.display_name})}),await ce(`local`,!0),await r()}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[ce,r,e]),_e=(0,X.useCallback)(async t=>{L({ok:!0,text:e(`settings.model.added`,{name:t})}),B(!0),await ce(`local`,!0)},[ce,e]),ve=!!f?.some(Ts);(0,X.useEffect)(()=>{if(ve)return()=>{r()}},[ve,r]),(0,X.useEffect)(()=>{if(u!==`local`||!ve)return;let e=setInterval(()=>{ce(`local`,!0)},oP);return()=>clearInterval(e)},[ve,u,ce]);let ye=t?.model,be=f?.find(e=>us(ye,e.id));(0,X.useEffect)(()=>{be&&ne(be)},[be]);let xe=(0,X.useMemo)(()=>{let e=g.trim().toLowerCase();return(f??[]).filter(t=>!e||t.id.toLowerCase().includes(e)||(t.display_name??``).toLowerCase().includes(e))},[f,g]),Se=xe.filter(e=>e.available!==!1),Ce=u===`fireworks`&&!v&&!g.trim()&&Se.some(e=>e.rank!==null),we=e=>e.rank!==null||e.id===t?.model,Te=Ce?Se.filter(we):Se,Ee=Ce?Se.filter(e=>!we(e)):[],De=xe.filter(e=>e.available===!1),Oe=ys(f??[]),ke=!!g.trim(),Ae=e=>us(t?.model,e.id),je=H?.id===`local`,Me=Te.filter(e=>e.downloaded).sort((e,t)=>Number(Ae(t))-Number(Ae(e))),Ne=Te.filter(e=>!e.downloaded),Pe=(f??[]).filter(e=>e.available!==!1&&e.downloaded),Fe=Pe.filter(we),Ie=u===`fireworks`&&Fe.some(e=>e.rank!==null)?Fe:Pe,Le=e=>P(iP,{model:e,label:Oe[e.id],current:Ae(e),remote:!!H?.remote,busy:j,confirmingRemove:ee===e.id,onUse:()=>void me(e.id),onDownload:()=>void he(e.id),onAskRemove:()=>R(e.id),onKeep:()=>R(null),onRemove:()=>void ge(e.id),onNpuRecheck:()=>void ce(u,!0)},e.id);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.model`)}),P(rP,{row:be??(us(te?.id,t?.model)?te:null),providerName:a?.find(e=>e.id===t?.provider)?.name??null,choices:W?Ie:[],labels:Oe,disabled:j!==null,onSwitch:e=>void me(e)}),P(`div`,{className:`provider-tabs`,role:`radiogroup`,"aria-label":e(`settings.model.whereRuns`),children:(a??[{id:`local`,name:`Local`,remote:!1}]).map(t=>V(`button`,{type:`button`,role:`radio`,"aria-checked":u===t.id,className:`provider-tab${u===t.id?` is-active`:``}${U(t)||se(t)?` is-disabled`:``}`,onClick:()=>d(t.id),disabled:(U(t)||se(t))&&u!==t.id,title:se(t)?e(`settings.privacy.localOnlyBlocked`):U(t)?t.network?.detail??void 0:void 0,children:[t.remote?P(Ir,{size:14,"aria-hidden":`true`}):P(Wr,{size:14,"aria-hidden":`true`}),P(`span`,{children:t.name}),t.remote&&t.models_discovered&&P(`span`,{className:`provider-tab-dot`,"aria-label":e(`settings.key.connectedDot`)})]},t.id))}),s&&P(XN,{message:s,onRetry:()=>{G(),ce(u)}}),H&&V(`section`,{className:`settings-card`,"aria-label":H.name,children:[H.remote&&P(`p`,{className:`settings-note`,children:P(`bdi`,{children:H.privacy_notice})}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,e(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:e(`settings.model.lede`)}),je&&P(`p`,{className:`settings-hint`,children:P(`bdi`,{children:H.privacy_notice})}),je&&P(`p`,{className:`settings-hint`,children:e(`settings.model.devices`)}),je&&N&&P(`p`,{className:`settings-hint`,children:e(`settings.model.memory`,{memory:N})})]}),H.remote&&!W&&V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,children:e(`settings.model.prices`)}),P(WA,{provider:H.id})]}),se(H)&&P(`div`,{className:`settings-field`,children:P(`p`,{className:`settings-error`,role:`alert`,children:e(`settings.privacy.localOnlyBlocked`)})}),U(H)&&V(`div`,{className:`settings-field`,children:[P(`p`,{className:`settings-error`,role:`alert`,children:H.network?.detail}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void G(),children:e(`settings.key.checkAgain`)})]}),H.remote&&!U(H)&&!se(H)&&V(`form`,{className:`settings-field`,onSubmit:e=>{e.preventDefault(),de()},children:[V(`div`,{className:`settings-row settings-row-between`,children:[P(`span`,{className:`settings-label`,children:e(`settings.key.title`)}),H.key_source&&P(`span`,{className:`settings-key-status ${W?`settings-ok`:`settings-error`}`,children:e(W?`settings.key.connected`:`settings.key.notConnected`)})]}),!H.key_source&&P(`span`,{className:`settings-hint`,children:H.key_state===`waiting_for_os_permission`?H.key_message??e(`settings.key.waitingOs`):e(`settings.key.none`)}),H.id===`amd`&&(!H.key_source||S)&&V(`div`,{className:`settings-grid`,children:[P(`input`,{className:`settings-input`,placeholder:e(`settings.key.gatewayPlaceholder`),value:O.base_url,onChange:e=>A({...O,base_url:e.target.value}),"aria-label":e(`settings.key.gatewayUrl`)}),P(`input`,{className:`settings-input`,placeholder:e(`settings.key.headerPlaceholder`),value:O.auth_header_name,onChange:e=>A({...O,auth_header_name:e.target.value}),"aria-label":e(`settings.key.headerName`)})]}),H.key_source&&!S?V(`div`,{className:`settings-row`,children:[P(`input`,{className:`settings-input settings-key-masked`,readOnly:!0,value:sP(H,e),"aria-label":e(`settings.key.savedAria`,{name:H.name})}),!W&&V(`button`,{type:`submit`,className:`btn-primary`,disabled:j!==null,children:[j===`connect`?P(q,{size:13,className:`spin`}):null,e(`settings.key.reconnect`)]}),(H.key_source!==`environment`||H.key_from_gaia_env)&&(w?V(D.Fragment,{children:[P(`span`,{className:`settings-hint`,children:e(`settings.key.removeAsk`)}),P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void pe(),disabled:j!==null,children:e(`settings.models.remove`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>E(!1),children:e(`settings.models.keep`)})]}):V(D.Fragment,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>C(!0),disabled:j!==null,children:e(`settings.key.replace`)}),H.key_source!==`environment`&&P(`button`,{type:`button`,className:`btn-secondary settings-key-remove`,onClick:()=>E(!0),disabled:j!==null,"aria-label":e(`settings.key.remove`),title:e(`settings.key.remove`),children:P(lo,{size:14,"aria-hidden":`true`})})]}))]}):V(`div`,{className:`settings-row`,children:[P(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,spellCheck:!1,autoFocus:S,value:b,onChange:e=>x(e.target.value),placeholder:e(S?`settings.key.pasteNew`:`settings.key.paste`),"aria-label":e(`settings.key.fieldAria`,{name:H.name})}),V(`button`,{type:`submit`,className:`btn-primary`,disabled:j!==null||!b,children:[j===`connect`?P(q,{size:13,className:`spin`}):null,e(S?`settings.key.save`:`settings.key.connect`)]}),S&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{x(``),C(!1)},disabled:j!==null,children:e(`settings.key.cancel`)})]}),H.key_source&&!W&&!H.error&&!S&&P(`p`,{className:`settings-hint`,children:e(`settings.key.notConnectedHint`,{name:H.name})}),H.error&&P(`p`,{className:`settings-error`,role:`alert`,children:H.error})]}),I?.ok&&P(`p`,{className:`settings-ok`,role:`status`,children:I.text}),I&&!I.ok&&P(XN,{message:I.text}),H.known_models&&P(`p`,{className:`settings-hint`,role:`status`,children:e(`settings.key.knownList`,{name:H.name})}),je&&P(`div`,{className:`models-downloads-slot`,ref:ie}),W&&V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,children:e(`settings.model.models`)}),(f?.length??0)>6&&P(`input`,{className:`settings-input`,type:`search`,value:g,onChange:e=>_(e.target.value),placeholder:e(`settings.model.search`),"aria-label":e(`settings.model.search`)}),m&&!(s&&KN(m))&&P(XN,{message:m}),!f&&!m&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.loading`)]}),f&&xe.length===0&&!m&&P(`p`,{className:`settings-hint`,children:e(ke||!je?`settings.model.noMatch`:`settings.model.noModels`)}),je?V(D.Fragment,{children:[Me.length>0&&P(SN,{title:e(`settings.model.groupDownloaded`),count:Me.length,defaultOpen:!0,forceOpen:ke,children:P(`ul`,{className:`model-list`,children:Me.map(Le)})}),Ne.length>0&&P(SN,{title:e(`settings.model.groupAvailable`),count:Ne.length,defaultOpen:Me.length===0,forceOpen:ke||z||Ne.some(Ts),children:P(`ul`,{className:`model-list`,children:Ne.map(Le)})})]}):P(`ul`,{className:`model-list`,children:Te.map(Le)}),Ce&&Ee.length>0&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>y(!0),children:e(`settings.model.showAll`)}),u===`fireworks`&&v&&!ke&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>y(!1),children:e(`settings.model.showRecommended`)}),De.length>0&&P(SN,{title:e(`settings.model.groupUnavailable`),count:De.length,forceOpen:ke,children:P(`ul`,{className:`model-list`,children:De.map(Le)})})]}),je&&W&&P(SN,{title:e(`settings.custom.title`),children:P(ZN,{onAdded:e=>void _e(e)})}),je&&W&&P(eP,{downloadsSlot:re}),H.remote&&P(aP,{})]})]})}function lP(){let e=T(),t=k(e=>e.sessions),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null),u=(0,X.useCallback)(async()=>{l(null);try{let e=await on();r(e.sessions),a(e.default_mode),k.getState().setDefaultPermissionMode(e.default_mode)}catch(e){l(e instanceof Error?e.message:String(e))}},[]);(0,X.useEffect)(()=>{u()},[u]);let d=(0,X.useCallback)(async e=>{l(null);try{await e(),await u()}catch(e){l(e instanceof Error?e.message:String(e))}},[u]),f=(0,X.useCallback)(async e=>{s(!1),await d(()=>kt(e))},[d]),p=()=>{i===`full_access`?f(`ask`):s(e=>!e)},m=e=>t.find(t=>t.id===e)?.title??e;return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.permissions`)}),P(`p`,{className:`settings-pane-lede`,children:e(`settings.permissions.lede`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,e(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:e(`settings.permissions.perChat`)})]}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.permissions.newChats`),children:[V(`label`,{className:`setting-row`,children:[P(`span`,{className:`settings-label`,children:e(`settings.permissions.fullAccess`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:i===`full_access`,onChange:p,disabled:i===null,"aria-label":e(`settings.permissions.fullAccess`)}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,children:e(i===`full_access`?`settings.permissions.on`:`settings.permissions.off`)}),o&&V(`div`,{className:`settings-warning`,role:`alert`,children:[P(`p`,{children:e(`settings.permissions.warning`)}),V(`div`,{className:`settings-row`,children:[P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void f(`full_access`),children:e(`settings.permissions.turnOn`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>s(!1),children:e(`settings.key.cancel`)})]})]})]}),c&&P(`p`,{className:`settings-error`,role:`alert`,children:c}),n&&n.length===0&&P(`p`,{className:`settings-hint`,children:e(`settings.permissions.none`)}),!!n?.length&&P(SN,{title:e(`settings.permissions.chats`),count:n.length,defaultOpen:!0,children:n.map(t=>V(`section`,{className:`settings-field permission-chat`,"aria-label":m(t.session_id),children:[V(`div`,{className:`settings-row settings-row-between`,children:[P(`bdi`,{className:`settings-label`,children:m(t.session_id)}),t.mode===`full_access`&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>d(async()=>{let e=(await Pt(t.session_id,`ask`)).mode;yE(t.session_id,e)}),children:e(`settings.permissions.turnOff`)})]}),t.grants.length>0&&P(`ul`,{className:`grant-list`,children:t.grants.map(n=>V(`li`,{className:`grant-row`,children:[P(`code`,{children:n.label}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>d(()=>Xt(t.session_id,n.key)),"aria-label":e(`settings.permissions.revokeAria`,{name:n.label}),children:e(`settings.permissions.revoke`)})]},n.key))}),t.grants.length>1&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>d(()=>Xt(t.session_id)),children:e(`settings.permissions.revokeAll`)})]},t.session_id))})]})}var uP={path:`~/.gaia/skills`},dP=[{source:`agent-bundled`,title:`settings.skills.bundled`,note:`settings.skills.bundledNote`},{source:`user`,title:`settings.skills.yours`,note:`settings.skills.yoursNote`,empty:`settings.skills.yoursEmpty`,params:uP},{source:`claude-project`,title:`settings.skills.project`,note:`settings.skills.projectNote`,params:{path:`.claude/skills`}},{source:`claude-import`,title:`settings.skills.import`,note:`settings.skills.importNote`}];function fP({onUseSkill:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)({}),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(``);(0,X.useEffect)(()=>{let e=!1;return ln().then(t=>{e||(r(t.skills),a(t.invalid))}).catch(t=>{e||s(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let u=c.trim().toLowerCase(),d=(n??[]).filter(e=>!u||e.name.toLowerCase().includes(u)||e.description.toLowerCase().includes(u)),f=n?.every(e=>dP.some(t=>t.source===e.source))??!1,p=n=>V(`li`,{className:`skill-row`,children:[V(`div`,{className:`skill-row-text`,children:[V(`span`,{className:`skill-row-name`,children:[n.name,n.version&&V(`span`,{className:`skill-row-meta`,children:[` v`,n.version]}),n.always_on&&V(`span`,{className:`skill-row-meta`,children:[` · `,t(`settings.skills.alwaysOn`)]})]}),P(`span`,{className:`skill-row-desc`,children:P(`bdi`,{children:n.description})})]}),!n.always_on&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>e(n.name),"aria-label":t(`settings.skills.useAria`,{name:n.name}),children:t(`settings.model.use`)})]},n.name);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:t(`settings.section.skills`)}),P(`p`,{className:`settings-pane-lede`,children:t(`settings.skills.lede`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:t(`settings.skills.how`,uP)})]}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o}),!n&&!o&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),n&&n.length>6&&P(`input`,{className:`settings-input`,type:`search`,value:c,onChange:e=>l(e.target.value),placeholder:t(`settings.skills.search`),"aria-label":t(`settings.skills.search`)}),n&&n.length===0&&P(`p`,{className:`settings-hint`,children:t(`settings.skills.none`)}),f?dP.map(e=>{let r=d.filter(t=>t.source===e.source),i=(n??[]).filter(t=>t.source===e.source).length;return r.length===0&&(u||!e.empty)?null:P(SN,{title:t(e.title),count:i,hint:t(e.note,e.params),defaultOpen:e.source===`user`,forceOpen:!!u,children:P(`section`,{"aria-label":t(e.title),children:r.length===0?P(`p`,{className:`settings-hint`,children:e.empty&&t(e.empty,e.params)}):P(`ul`,{className:`skill-list`,children:r.map(p)})})},e.source)}):P(`ul`,{className:`skill-list`,children:d.map(p)}),Object.keys(i).length>0&&V(`div`,{className:`settings-card`,role:`alert`,children:[P(`span`,{className:`settings-label`,children:t(`settings.skills.skipped`)}),P(`ul`,{className:`grant-list`,children:Object.entries(i).map(([e,t])=>V(`li`,{children:[P(`bdi`,{dir:`ltr`,children:P(`code`,{children:e})}),` — `,P(`bdi`,{children:t})]},e))})]})]})}function pP(){let e=T(),t=k(e=>e.setShowMemoryDashboard),n=k(e=>e.closeSettings),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1);(0,X.useEffect)(()=>{pA().then(i).catch(e=>o(e instanceof Error?e.message:String(e)))},[]);let l=(0,X.useCallback)(async()=>{if(r){c(!0),o(null);try{i(await mA({memory_enabled:!r.memory_enabled}))}catch(e){o(e instanceof Error?e.message:String(e))}finally{c(!1)}}},[r]);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.memory`)}),P(`p`,{className:`settings-pane-lede`,children:e(`settings.memory.lede`)}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.section.memory`),children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.memory.remember`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:!!r?.memory_enabled,onChange:()=>void l(),disabled:!r||s,"aria-label":e(`settings.memory.remember`)}),P(`span`,{className:`toggle-track`})]})]}),a&&P(`p`,{className:`settings-error`,role:`alert`,children:a}),V(`div`,{className:`settings-row settings-row-between`,children:[P(`span`,{className:`settings-hint`,children:e(`settings.memory.dashboardHint`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{n(),t(!0)},children:e(`settings.memory.dashboard`)})]})]})]})}function mP(e,t,n){if(!/^\d+$/.test(e.trim()))return!1;let r=Number(e);return r>=t&&r<=n}function hP(e){return e<1048576?`${Math.ceil(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}function gP(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1);(0,X.useEffect)(()=>{hn().then(e=>{n(e),i(String(e.retention_days)),o(String(e.max_mb))},t=>c({ok:!1,text:e(`settings.undo.readFailed`,{reason:t instanceof Error?t.message:String(t)})}))},[e]);let[d,f]=(0,X.useState)({days:!1,mb:!1}),p=!mP(r,1,365)||d.days,m=!mP(a,10,1e5)||d.mb,h=t!==null&&(r!==String(t.retention_days)||a!==String(t.max_mb)),g=async()=>{if(!(p||m)){u(!0),c(null);try{let t=await fn(Number(r),Number(a));n(t),c({ok:!0,text:e(`settings.undo.saved`)})}catch(t){let n=t instanceof yn&&t.httpStatus===422?t.fields:[],r=n.includes(`retention_days`),i=n.includes(`max_mb`);r||i?(f({days:r,mb:i}),c({ok:!1,text:e(`settings.undo.fix`)})):c({ok:!1,text:t instanceof Error?t.message:String(t)})}finally{u(!1)}}};return V(`div`,{className:`settings-field`,"aria-label":e(`settings.privacy.undo`),children:[P(`span`,{className:`settings-label`,children:e(`settings.privacy.undo`)}),P(`p`,{className:`settings-hint`,children:e(`settings.undo.hint`)}),t&&V(D.Fragment,{children:[V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`undo-days`,children:e(`settings.undo.days`)}),P(`input`,{id:`undo-days`,type:`number`,className:`model-input undo-history-input`,min:1,max:365,value:r,"aria-invalid":p,"aria-describedby":p?`undo-days-error`:void 0,onChange:e=>{i(e.target.value),f(e=>({...e,days:!1}))}})]}),p&&P(`p`,{id:`undo-days-error`,className:`settings-error`,children:e(`settings.undo.daysError`)}),V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`undo-mb`,children:e(`settings.undo.mb`)}),P(`input`,{id:`undo-mb`,type:`number`,className:`model-input undo-history-input`,min:10,max:1e5,value:a,"aria-invalid":m,"aria-describedby":m?`undo-mb-error`:void 0,onChange:e=>{o(e.target.value),f(e=>({...e,mb:!1}))}})]}),m&&P(`p`,{id:`undo-mb-error`,className:`settings-error`,children:e(`settings.undo.mbError`)}),V(`div`,{className:`setting-row setting-row-path`,children:[P(`span`,{children:e(`settings.undo.inUse`)}),V(`span`,{children:[e.plural(`settings.undo.used`,t.turns,{size:hP(t.used_bytes)}),` `,P(`bdi`,{dir:`ltr`,children:P(`code`,{className:`setting-path`,children:t.path})})]})]}),P(`button`,{type:`button`,className:`btn-model-save`,onClick:()=>void g(),disabled:!h||l||p||m,children:e(l?`settings.models.applying`:`settings.advanced.save`)})]}),s&&P(`p`,{className:s.ok?`settings-ok`:`settings-error`,role:s.ok?`status`:`alert`,children:s.text})]})}var _P={root:`settings-report`,button:`btn-secondary`,hint:`settings-hint`,error:`settings-error`};function vP(){let e=T(),t=k(e=>e.sessions),n=k(e=>e.removeSession),r=hs(),i=k(e=>e.systemStatus?.data_dir),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),p=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]),(0,X.useEffect)(()=>{let e=!0;return qe().then(t=>{e&&u(t.network_policy===`local_ai_only`)}).catch(t=>{e&&c({ok:!1,text:t instanceof Error?t.message:String(t)})}),()=>{e=!1}},[]);let m=(0,X.useCallback)(async()=>{if(l===null||d)return;let t=l,n=!t;u(n),f(!0),c(null);try{let t=await Me({network_policy:n?`local_ai_only`:`cloud_allowed`});u(t.network_policy===`local_ai_only`);let r=t.policy_notices??[],i=r.some(e=>e.severity===`warning`),a=r.length?r.map(t=>t.code===`users_server_keeps_keys`?e(`settings.privacy.usersServerKeepsKeys`,{url:t.url??``}):t.code===`runtime_keys_not_dropped`?e(`settings.privacy.runtimeKeysNotDropped`,{reason:t.reason??``}):t.code===`saved_models_not_checked`?e(`settings.privacy.savedModelsNotChecked`,{reason:t.reason??``}):e(`settings.privacy.policyNoticeUnknown`)).join(` `):e(n?`settings.privacy.localOnlyOn`:`settings.privacy.localOnlyOff`);c({ok:!i,text:a})}catch(e){u(t),c({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{f(!1)}},[l,d,e]),h=(0,X.useCallback)(async()=>{if(!a){o(!0),p.current=setTimeout(()=>o(!1),4e3);return}o(!1);let r=[];for(let e of t)try{await de(e.id),n(e.id)}catch(t){r.push(`${e.title}: ${t instanceof Error?t.message:t}`)}c(r.length?{ok:!1,text:e(`settings.privacy.deleteFailed`,{n:r.length,reason:r.join(`; `)})}:{ok:!0,text:e(`settings.privacy.deleted`)})},[a,n,t,e]);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.privacy`)}),P(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.localOnlyTitle`),children:V(`div`,{className:`settings-row settings-row-between`,children:[V(`div`,{children:[P(`strong`,{children:e(`settings.privacy.localOnlyTitle`)}),P(`p`,{className:`settings-hint`,children:e(`settings.privacy.localOnlyHint`)})]}),P(`button`,{type:`button`,role:`switch`,"aria-checked":l===!0,"aria-label":e(`settings.privacy.localOnlyTitle`),className:l?`is-active`:``,onClick:()=>void m(),disabled:l===null||d,children:e(l?`settings.privacy.localOnlyOnLabel`:`settings.privacy.localOnlyOffLabel`)})]})}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.whereTitle`),children:[P(`p`,{className:`settings-note`,children:e(`settings.privacy.stays`)}),P(`p`,{className:r?.remote?`settings-note`:`settings-hint`,children:r?.remote?e(`settings.privacy.remote`,{name:r.label}):e(r?`settings.privacy.local`:`settings.privacy.unknown`)}),i&&V(`div`,{className:`setting-row setting-row-path`,children:[P(`span`,{children:e(`settings.privacy.dataFolder`)}),P(`bdi`,{dir:`ltr`,className:`setting-path`,children:i})]})]}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.reportTitle`),children:[P(`p`,{className:`settings-note`,children:e(`settings.privacy.reportNote`)}),P(rC,{classes:_P})]}),P(SN,{title:e(`settings.privacy.undo`),children:P(gP,{})}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.deleteTitle`),children:[P(`p`,{className:`danger-warning`,children:t.length===0?e(`settings.privacy.nothingToDelete`):e(`settings.privacy.deleteWarning`)}),P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void h(),disabled:t.length===0,children:e(a?`settings.privacy.deleteConfirm`:`settings.privacy.delete`)})]}),s&&P(`p`,{className:s.ok?`settings-ok`:`settings-error`,role:s.ok?`status`:`alert`,children:s.text})]})}var yP=[{id:`needs_approval`,label:`settings.alerts.approval`},{id:`question`,label:`settings.alerts.question`},{id:`finished`,label:`settings.alerts.finished`}],bP=[{value:`banner`,label:`settings.alerts.banner`},{value:`badge`,label:`settings.alerts.badge`},{value:`off`,label:`settings.alerts.off`}],xP=[0,10,20,30,50];function SP(){return typeof Notification>`u`?`unsupported`:Notification.permission}function CP(){let e=T(),t=lc(),n=!!window.gaiaAPI,[r,i]=(0,X.useState)(SP),a=Object.values(t.modes).includes(`banner`);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.notifications`)}),P(`p`,{className:`settings-pane-lede`,children:e(`settings.alerts.lede`)}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.alerts.when`),children:[yP.map(n=>V(`div`,{className:`setting-row`,children:[P(`span`,{id:`alert-${n.id}`,children:e(n.label)}),P(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`alert-${n.id}`,children:bP.map(r=>P(`button`,{type:`button`,role:`radio`,"aria-checked":t.modes[n.id]===r.value,className:t.modes[n.id]===r.value?`is-active`:``,onClick:()=>t.setMode(n.id,r.value),children:e(r.label)},r.value))})]},n.id)),!n&&a&&r!==`granted`&&(r==="default"?P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{Notification.requestPermission().then(i).catch(e=>{console.error(`[alerts] Notification permission request failed`,e),i(SP())})},children:e(`settings.alerts.allow`)}):P(`p`,{className:`settings-error`,role:`alert`,children:e(r===`unsupported`?`settings.alerts.unsupported`:`settings.alerts.blocked`)})),V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.alerts.sound`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.sound,onChange:()=>t.update({sound:!t.sound}),"aria-label":e(`settings.alerts.sound`)}),P(`span`,{className:`toggle-track`})]})]}),n&&V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.alerts.flash`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.flash,onChange:()=>t.update({flash:!t.flash}),"aria-label":e(`settings.alerts.flash`)}),P(`span`,{className:`toggle-track`})]})]})]}),V(`section`,{className:`settings-card`,"aria-labelledby":`keep-awake-title`,children:[P(`h3`,{className:`settings-label`,id:`keep-awake-title`,children:e(`settings.alerts.keepAwakeTitle`)}),n?V(D.Fragment,{children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.alerts.keepAwake`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.keepAwake,onChange:()=>t.update({keepAwake:!t.keepAwake}),"aria-label":e(`settings.alerts.keepAwake`)}),P(`span`,{className:`toggle-track`})]})]}),V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`battery-floor`,children:e(`settings.alerts.battery`)}),P(`select`,{id:`battery-floor`,className:`settings-input settings-select-compact`,value:t.batteryFloor,disabled:!t.keepAwake,onChange:e=>t.update({batteryFloor:Number(e.target.value)}),children:xP.map(t=>P(`option`,{value:t,children:t===0?e.bare(`settings.alerts.never`):`${t}%`},t))})]}),P(`p`,{className:`settings-hint`,children:e(`settings.alerts.screen`)})]}):P(`p`,{className:`settings-hint`,children:e(`settings.alerts.desktopOnly`)})]})]})}var wP=[50,75,100,125,150,175,200],TP=[{accent:`american`,gender:`female`},{accent:`american`,gender:`male`},{accent:`british`,gender:`female`},{accent:`british`,gender:`male`}],EP=`settings:preview`,DP=`Hello, I'm GAIA. This is how I'll read my replies to you.`;function OP(e){return e instanceof yn?e.detail||e.message:String(e)}function kP(){let e=T(),t=ES(e=>e.settings),n=ES(e=>e.setSettings),r=ES(e=>e.read),i=ES(e=>e.stop),a=ES(e=>e.messageId===EP),o=ES(e=>e.messageId===EP&&e.status===`loading`),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1);(0,X.useEffect)(()=>{pS().then(n).catch(e=>c(OP(e)))},[n]);let p=e=>{f(!0),u(null),ES.getState().messageId===EP&&i(),mS(e).then(n).catch(e=>u(OP(e))).finally(()=>f(!1))};return s?V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.voice`)}),P(`p`,{className:`settings-error`,role:`alert`,children:e(`readAloud.settings.loadFailed`,{reason:s})})]}):t?V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.voice`)}),P(`p`,{className:`settings-pane-lede`,children:e(`readAloud.settings.lede`)}),V(`div`,{className:`settings-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`read-aloud-voice`,children:e(`readAloud.settings.voice`)}),V(`div`,{className:`read-aloud-voice-row`,children:[P(`select`,{id:`read-aloud-voice`,className:`settings-input`,value:t.voice,disabled:d,onChange:e=>p({voice:e.target.value}),children:TP.map(n=>P(`optgroup`,{label:e(`readAloud.group.${n.accent}.${n.gender}`),children:t.voices.filter(e=>e.accent===n.accent&&e.gender===n.gender).map(e=>P(`option`,{value:e.id,lang:`en`,children:e.name},e.id))},`${n.accent}-${n.gender}`))}),V(`button`,{type:`button`,className:`btn-secondary`,"aria-pressed":a,disabled:d,onClick:()=>a?i():void r(EP,DP),children:[o?P(q,{size:13,className:`spin`}):P(a?ao:_o,{size:13}),e(a?`readAloud.stop`:`readAloud.settings.preview`)]})]}),P(`span`,{className:`settings-hint`,children:e(`readAloud.settings.englishOnly`)}),P(kS,{messageId:EP})]}),V(`div`,{className:`settings-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`read-aloud-speed`,children:e(`readAloud.settings.speed`)}),P(`select`,{id:`read-aloud-speed`,className:`settings-input`,value:t.speed,disabled:d,onChange:e=>p({speed:Number(e.target.value)}),children:(wP.includes(t.speed)?wP:[...wP,t.speed].sort((e,t)=>e-t)).map(t=>P(`option`,{value:t,children:t===100?e.bare(`readAloud.settings.normalSpeed`):`⁦${(t/100).toLocaleString(e.locale)}×⁩`},t))})]}),V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`readAloud.settings.auto`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.auto,disabled:d,onChange:()=>p({auto:!t.auto}),"aria-label":e(`readAloud.settings.auto`)}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,children:e(`readAloud.settings.shared`)}),l&&P(`p`,{className:`settings-error`,role:`alert`,children:e(`readAloud.settings.saveFailed`,{reason:l})})]}):V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.loading`)]})}function AP(){let e=T(),t=k(e=>e.openSettings),n=k(e=>e.closeSettings),r=k(e=>e.runSetupAgain),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1);(0,X.useEffect)(()=>{Ce().then(a).catch(e=>l(e instanceof Error?e.message:String(e))),ot().then(s).catch(e=>l(e instanceof Error?e.message:String(e)))},[]);let f=i?.catalog?.find(e=>e.id===i.chat_model.id),p=(i?.catalog??[]).filter(e=>e.downloaded),m=p.reduce((e,t)=>e+(t.full_size_gb??0),0),h=[o?.gpu_name,o?.npu_detected?e(`setup.checks.npu`):null].filter(Boolean).join(` · `),g=[{title:e(`settings.setup.where`),rows:[{label:e(`settings.setup.chatRuns`),value:f?.name??null,section:`model`},{label:e(`settings.setup.cloudKeys`),value:null,section:`model`}]},{title:e(`setup.pc.step`),rows:[{label:e(`settings.setup.detected`),value:[h,o?.ram_gb==null?null:`${o.ram_gb} GB`].filter(Boolean).join(` · `)||null,section:`advanced`},{label:e(`settings.setup.server`),value:i?.lemonade.mode===`external`?e(`settings.setup.serverYours`):e(`settings.setup.serverOwn`),section:`advanced`},{label:e(`setup.gpu.title`),value:null,section:`model`}]},{title:e(`setup.models.step`),rows:[{label:e(`settings.setup.models`),value:i?.catalog?e(`settings.setup.modelsValue`,{n:String(p.length),size:$(m)}):null,section:`model`},{label:e(`settings.setup.context`),value:null,section:`model`}]},{title:e(`settings.setup.after`),rows:[{label:e(`settings.section.connectors`),value:null,section:`connectors`},{label:e(`settings.section.memory`),value:null,section:`memory`},{label:e(`settings.language`),value:null,section:`general`},{label:e(`settings.setup.signIn`),value:null,section:`general`}]}];return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.setup`)}),P(`p`,{className:`settings-hint`,children:e(`settings.setup.lede`)}),V(`div`,{className:`settings-setup-status`,children:[V(`span`,{children:[P(`strong`,{children:e(`settings.setup.ready`)}),f&&V(`span`,{className:`settings-hint`,children:[` `,P(`bdi`,{children:e(`settings.setup.running`,{name:f.name})})]})]}),P(`button`,{type:`button`,className:`btn-secondary`,"data-testid":`setup-run-again`,onClick:()=>d(!0),children:e(`settings.setup.runAgain`)})]}),c&&P(`p`,{className:`setup-error`,role:`alert`,children:c}),g.map(e=>V(`section`,{className:`settings-setup-group`,"aria-label":e.title,children:[P(`h3`,{className:`settings-label`,children:e.title}),e.rows.map(e=>V(`button`,{type:`button`,className:`settings-setup-row`,onClick:()=>t(e.section),children:[V(`span`,{children:[P(`span`,{className:`settings-setup-row-label`,children:e.label}),e.value&&P(`bdi`,{className:`settings-hint settings-setup-row-value`,children:e.value})]}),P(br,{size:14,className:`settings-setup-chevron`,"aria-hidden":`true`})]},e.label))]},e.title)),u&&P(Kj,{title:e(`settings.setup.confirmTitle`),confirmLabel:e(`settings.setup.confirmYes`),cancelLabel:e(`setup.again.notNow`),onConfirm:()=>{d(!1),n(),r(!0)},onCancel:()=>d(!1),children:P(`p`,{children:e(`settings.setup.confirmBody`)})})]})}var jP=`modulepreload`,MP=function(e,t){return new URL(e,t).href},NP={},PP=function(e){return e.pathname.endsWith(`.css`)},FP=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},IP=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=MP(t,n);let r=s(t),i=PP(r);return FP(NP,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:jP,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},LP=(0,X.lazy)(()=>IP(()=>import(`./ConnectorsPane-BfS5fSIl.js`).then(e=>({default:e.ConnectorsPane})),__vite__mapDeps([0,1,2,3,4]),import.meta.url)),RP=(0,X.lazy)(()=>IP(()=>import(`./AdvancedSettings-8tGuuocd.js`).then(e=>({default:e.AdvancedSettings})),__vite__mapDeps([5,1,2,3]),import.meta.url)),zP=[`general`,`setup`,`model`,`permissions`,`skills`,`connectors`,`memory`,`notifications`,`voice`,`privacy`,`advanced`];function BP({onUseSkill:e}){let t=T(),n=k(e=>e.settingsSection),r=k(e=>e.openSettings),i=k(e=>e.closeSettings),a=(0,X.useRef)(null),o=n!==null;if(Io(o,i),sS(a,o),xN(a,o,()=>a.current?.querySelector(`.settings-nav-item.is-active`)),!n)return null;let s=(()=>{switch(n){case`general`:return P(GN,{});case`setup`:return P(AP,{});case`model`:return P(cP,{});case`permissions`:return P(lP,{});case`skills`:return P(fP,{onUseSkill:t=>{i(),e(t)}});case`connectors`:return P(LP,{});case`memory`:return P(pP,{});case`notifications`:return P(CP,{});case`voice`:return P(kP,{});case`privacy`:return P(vP,{});case`advanced`:return P(RP,{})}})();return P(`div`,{className:`settings-overlay`,onMouseDown:e=>{e.target===e.currentTarget&&i()},children:V(`div`,{ref:a,className:`settings-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`settings.title`),children:[V(`nav`,{className:`settings-nav`,"aria-label":t(`settings.sections`),children:[P(`h1`,{className:`settings-nav-title`,children:t(`settings.title`)}),zP.map(e=>P(`button`,{type:`button`,"data-section":e,className:`settings-nav-item${n===e?` is-active`:``}`,"aria-current":n===e?`page`:void 0,onClick:t=>{t.currentTarget.focus(),r(e)},children:t(`settings.section.${e}`)},e))]}),V(`div`,{className:`settings-body`,children:[P(`button`,{type:`button`,className:`settings-close`,onClick:i,"aria-label":t(`settings.close`),children:P(Y,{size:18})}),P(`div`,{className:`settings-scroll`,children:P(X.Suspense,{fallback:V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),children:s})})]})]})})}var VP=p((e,t)=>({lifecycle:null,restartError:null,apply:n=>{n.apiBase&&B(n.apiBase),e({lifecycle:n,restartError:n.status===`running`?null:t().restartError})},restart:async()=>{let n=window.gaiaAPI?.backend;if(!n)throw Error(`Restart GAIA needs the desktop app.`);e({restartError:null});try{t().apply(await n.restart())}catch(t){d.system.error(`Restart GAIA failed`,t),e({restartError:t instanceof Error?t.message:String(t)})}}}));function HP(e){let t=window.gaiaAPI?.backend;if(!t)return()=>{};let n=t=>{let n=VP.getState().lifecycle?.status;VP.getState().apply(t),t.status===`running`&&n&&n!==`running`&&e()},r=t.onState(n);return t.getState().then(n).catch(e=>d.system.error(`Could not read the backend state from the desktop app`,e)),r}function UP(e,t){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(null),c=(0,X.useRef)(null),l=(0,X.useRef)(null),u=(0,X.useRef)(null),f=(0,X.useCallback)(()=>{c.current&&=(clearTimeout(c.current),null),l.current&&=(clearTimeout(l.current),null),u.current&&=(clearInterval(u.current),null)},[]);(0,X.useEffect)(()=>f,[f]);let p=(0,X.useCallback)((e,t)=>{u.current&&clearInterval(u.current),u.current=setInterval(async()=>{try{let n=await Nt();t===`load`?n.model_loaded?.toLowerCase()===e.toLowerCase()&&(r(!1),c.current&&=(clearTimeout(c.current),null),u.current&&=(clearInterval(u.current),null)):(n.model_downloaded===!0||n.model_loaded?.toLowerCase()===e.toLowerCase())&&(a(!1),l.current&&=(clearTimeout(l.current),null),u.current&&=(clearInterval(u.current),null))}catch{}},Lc)},[]),m=e??`Gemma-4-E4B-it-GGUF`;return(0,X.useEffect)(()=>s(null),[m]),{isLoadingModel:n,isDownloadingModel:i,downloadError:o,loadModel:(0,X.useCallback)(async(e,t)=>{let n=e??m,i=t??32768;r(!0);try{if(!await zt(n,i)){r(!1);return}d.system.info(`Load model triggered: ${n} (ctx=${i})`),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>r(!1),Fc),p(n,`load`)}catch(e){d.system.error(`Failed to trigger model load`,e),r(!1)}},[m,t,p]),downloadModel:(0,X.useCallback)(async(e=!1,t,n=!1)=>{let r=t??m;a(!0),s(null);try{await fe(r,e,n),d.system.info(`Download model triggered: ${r} (force=${e})`),l.current&&clearTimeout(l.current),l.current=setTimeout(()=>a(!1),Ic),p(r,`download`)}catch(e){d.system.error(`Failed to trigger model download`,e),s(e instanceof Error?e.message:String(e)),a(!1)}},[m,p])}}function WP({onRetry:e,label:t,busyLabel:n=`Checking…`}){let[r,i]=(0,X.useState)(!1);return P(`button`,{className:`connection-banner__retry`,onClick:()=>{i(!0),Promise.resolve(e()).finally(()=>i(!1))},disabled:r,children:r?n:t})}function GP(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function KP({lifecycle:e}){let t=T(),n=VP(e=>e.restart),r=VP(e=>e.restartError),i=e.status===`restarting`,[a,o]=(0,X.useState)(()=>Date.now());if((0,X.useEffect)(()=>{if(!i)return;o(Date.now());let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[i]),i){let n=e.since?Math.max(0,Math.floor((a-e.since)/1e3)):0;return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t(`banner.restarting`),` `,P(`bdi`,{dir:`ltr`,className:`connection-banner__timer`,children:GP(n)}),` `,P(`span`,{className:`connection-banner__hint`,children:t(`banner.restartingHint`)})]})]})}return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t(`banner.restartStopped`),` `,P(`span`,{className:`connection-banner__hint`,children:r?t(`banner.restartFailed`,{error:r}):t(`banner.restartStoppedHint`)})]}),P(WP,{onRetry:n,label:t(`banner.restartButton`),busyLabel:t(`banner.restartingShort`)})]})}function qP({onRetry:e,backendSlow:t=!1,backendError:n=null}){let r=T(),{backendConnected:i,systemStatus:a,currentSessionId:o,messages:s}=k(),c=VP(e=>e.lifecycle),[l,u]=(0,X.useState)(!1),d=!!o&&s.length>0,f=a?.default_model_name??`Gemma-4-E4B-it-GGUF`,{isDownloadingModel:p,downloadError:m,downloadModel:h}=UP(f),g=cs(e=>e.pickLoad),_=cs(e=>e.retryPickLoad),v=cs(e=>e.dismissPickLoad);ls();let y=(0,X.useRef)(a?.lemonade_running),b=(0,X.useRef)(a?.model_downloaded),x=(0,X.useRef)(a?.context_size_sufficient),S=(0,X.useRef)(a?.expected_model_loaded);if((0,X.useEffect)(()=>{if(d)return;let e=a?.lemonade_running,t=a?.model_downloaded,n=a?.context_size_sufficient,r=a?.expected_model_loaded,i=!1;y.current!==e&&(y.current=e,e===!1&&(i=!0)),b.current!==t&&(b.current=t,t===!1&&(i=!0)),x.current!==n&&(x.current=n,n===!1&&(i=!0)),S.current!==r&&(S.current=r,r===!1&&(i=!0)),i&&u(!1)},[a,d]),c&&c.status!==`running`)return P(KP,{lifecycle:c});let C=a?.download_progress??null,w=C?.model_name||f;if(p||C?.state===`downloading`||C?.state===`starting`||C?.state===`error`){let e=C?.total_bytes?`${(C.total_bytes/1e9).toFixed(1)} GB`:`large download`,t=C?.state===`error`;return V(`div`,{className:`connection-banner ${t?`connection-banner--error`:`connection-banner--warning`}`,role:t?`alert`:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(t?J:Jr,{size:16})}),P(`div`,{className:`connection-banner__text`,dir:`auto`,children:t?V(D.Fragment,{children:[`Download of `,P(`strong`,{children:w}),` failed.`,` `,(m??C?.message)&&P(`span`,{className:`connection-banner__hint`,children:m??C?.message})]}):V(D.Fragment,{children:[`Downloading `,P(`strong`,{children:w}),` (`,e,`).`,C?.state===`downloading`&&C.file&&V(D.Fragment,{children:[` `,V(`span`,{className:`connection-banner__hint`,children:[`File `,C.file_index,` / `,C.total_files,`: `,P(`code`,{children:C.file})]})]})]})}),t?P(`button`,{className:`connection-banner__retry`,onClick:()=>h(!1,w,!a?.model_loaded),children:`Retry`}):P(`span`,{className:`connection-banner__loading connection-banner__progress`,children:C&&C.state===`downloading`&&C.total_bytes>0?V(D.Fragment,{children:[P(`span`,{className:`connection-banner__progress-bar`,role:`progressbar`,"aria-valuenow":C.percent,"aria-valuemin":0,"aria-valuemax":100,"aria-label":`Download progress`,children:P(`span`,{className:`connection-banner__progress-fill`,style:{width:`${C.percent}%`}})}),V(`span`,{className:`connection-banner__progress-label`,children:[C.percent,`% ·`,` `,(C.downloaded_bytes/1e9).toFixed(2),` /`,` `,(C.total_bytes/1e9).toFixed(2),` GB`]})]}):V(D.Fragment,{children:[P(q,{size:13,className:`connection-banner__spinner`}),C?.state===`starting`?C.message??`Starting download…`:`Downloading…`]})}),t&&P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}if(g){let e=ds(g.model);return g.error?V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.pickLoad.failed`,{model:e}),` `,P(`span`,{className:`connection-banner__hint`,dir:`auto`,children:g.error.key?r(g.error.key,{reason:g.error.reason}):g.error.reason})]}),P(WP,{onRetry:_,label:r(`banner.pickLoad.retry`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:v,"aria-label":r(`banner.dismiss`),children:P(Y,{size:14})})]}):V(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.pickLoad.loading`,{model:e}),` `,P(`bdi`,{dir:`ltr`,children:r(`banner.pickLoad.seconds`,{s:g.seconds})}),` `,P(`span`,{className:`connection-banner__hint`,children:r(`banner.pickLoad.canType`)})]})]})}if(Hw(a)&&!t&&!n){let e=a?.init_tasks?.find(e=>e.status===`running`)?.name||`Preparing AI system`;return V(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[e,V(`span`,{className:`thinking-dots`,children:[P(`span`,{children:`.`}),P(`span`,{children:`.`}),P(`span`,{children:`.`})]})]})]})}if(l||d)return null;if(!i)return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(yo,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.unreachable`),` `,P(`span`,{className:`connection-banner__hint`,children:r(`banner.unreachableHint`)})]}),e&&P(WP,{onRetry:e,label:`Retry`})]});if(n)return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA's backend answered with an error (`,n,`).`,` `,P(`span`,{className:`connection-banner__hint`,children:`It may be overloaded. GAIA keeps checking; if it lasts, restart GAIA.`})]}),e&&P(WP,{onRetry:e,label:`Check again`})]});if(t)return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA is slow to answer.`,` `,P(`span`,{className:`connection-banner__hint`,children:`It may be busy with another chat or app. GAIA keeps checking.`})]}),e&&P(WP,{onRetry:e,label:`Check again`})]});if(a?.config_error)return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA settings could not be loaded.`,` `,P(`span`,{className:`connection-banner__hint`,children:a.config_error})]}),e&&P(WP,{onRetry:e,label:`Check again`})]});if(a&&!a.lemonade_running){let t=Uw(a)===`unresponsive`,n=JN(a);return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t?`The model server is not answering (${a.lemonade_error}). It may be busy with another app or loading a model.`:r(`banner.serverStopped`),` `,n?P(`span`,{className:`connection-banner__hint`,children:r(`banner.finishSetup`)}):a.start_command?V(`span`,{className:`connection-banner__hint`,children:[t?`If it stays this way, restart it: `:`To start it by hand, run `,P(`code`,{children:a.start_command})]}):a.start_instruction&&P(`span`,{className:`connection-banner__hint`,children:a.start_instruction})]}),n&&P(YN,{className:`connection-banner__retry`}),e&&P(WP,{onRetry:e,label:r(`settings.key.checkAgain`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}if(a&&a.lemonade_running&&a.model_loaded&&a.context_size_sufficient===!1){let t=a.model_context_size??0;return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(Ji,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`LLM context window is too small (`,t.toLocaleString(),` tokens;`,` `,Nc.toLocaleString(),` required).`,` `,P(`span`,{className:`connection-banner__hint`,children:`Reload it with a larger context in Settings → Advanced.`})]}),e&&P(WP,{onRetry:e,label:`Check again`}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}return null}function JP(){let e=jN(),t=T(),[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(null),o=(0,X.useCallback)(e=>{let n=kN();n&&(a(null),n[e]().catch(n=>{d.system.error(`Update ${e} failed`,n),a(FN(n,t))}))},[t]);if(n)return null;let s=e.installFailed?t(`update.chip.installFailedDetail`,e.installFailed):null,c=e.status===`downloading`||e.status===`downloaded`;if(e.startFailed&&e.previousVersion&&!c)return V(`div`,{className:`update-chip update-chip--error`,role:`status`,children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,title:i??void 0,children:t(i?`update.chip.updateFailed`:`update.chip.startFailed`)}),P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`revertUpdate`),children:t(`update.chip.goBack`,{version:e.previousVersion})}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]});let l=e.status===`available`||e.status===`downloaded`;if(s&&!l)return V(`div`,{className:`update-chip update-chip--error`,role:`status`,title:s??void 0,children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:t(`update.chip.installFailed`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]});if(e.status===`idle`||e.status===`checking`||e.status===`disabled`||e.status===`no-channel`)return null;if(e.status===`downloading`){let n=Math.max(0,Math.min(100,e.progress));return V(`div`,{className:`update-chip update-chip--downloading`,role:`status`,"aria-live":`polite`,title:t(`update.chip.downloadingTitle`,{version:e.version??``}),children:[P(Jr,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:e.preparing?t(`update.chip.preparing`):t(`update.chip.downloading`,{pct:n})})]})}return e.status===`available`?V(`div`,{className:`update-chip update-chip--available`,role:`status`,title:i||s||e.releaseNotes||t(`update.chip.availableTitle`),children:[P(Jr,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:i?t(`update.chip.updateFailed`):s?t(`update.chip.installFailed`):t(`update.chip.available`,{version:e.version??``})}),!e.pinnedVersion&&P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`downloadUpdate`),children:t(`update.chip.updateNow`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismiss`),children:P(Y,{size:11})})]}):e.status===`downloaded`?V(`div`,{className:`update-chip update-chip--ready`,role:`status`,"aria-live":`polite`,children:[P(Fa,{size:13,className:`update-chip__icon`}),P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`restart`),title:i||s||t(`update.chip.restartTitle`),children:t(i?`update.chip.restartFailed`:s?`update.chip.installFailedRetry`:`update.chip.ready`)})]}):e.status===`error`?V(`div`,{className:`update-chip update-chip--error`,role:`status`,title:e.error||t(`update.chip.checkFailed`),children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:t(`update.chip.checkFailed`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]}):null}var YP={permission_request:{icon:P(Ga,{size:16}),colorClass:`notif-type-permission`},policy_alert:{icon:P(Ga,{size:16}),colorClass:`notif-type-policy`},security_alert:{icon:P(J,{size:16}),colorClass:`notif-type-security`},status_change:{icon:P(Er,{size:16}),colorClass:`notif-type-status`},info:{icon:P(Hi,{size:16}),colorClass:`notif-type-info`},error:{icon:P(wr,{size:16}),colorClass:`notif-type-error`}};function XP(e,t){let n=Date.now()-e,r=Math.floor(n/1e3);if(r<60)return t(`time.justNow`);let i=Math.floor(r/60);if(i<60)return t(`time.minutesAgo`,{n:i});let a=Math.floor(i/60);if(a<24)return t(`time.hoursAgo`,{n:a});let o=Math.floor(a/24);return o<7?t(`time.daysAgo`,{n:o}):new Date(e).toLocaleDateString(te(t),{month:`short`,day:`numeric`})}function ZP({onClose:e}){let t=T(),n=Qs(ko(ec)),r=Qs($s),i=Qs(e=>e.markRead),a=Qs(e=>e.markAllRead),o=Qs(e=>e.clearAll),s=Qs(e=>e.dismiss),c=Qs(e=>e.respondToPermission),l=Qs(e=>e.typeFilter),u=Qs(e=>e.setTypeFilter),d=(0,X.useCallback)(e=>{i(e)},[i]),f=(0,X.useCallback)(e=>{c(e.id,`allow`).catch(e=>console.error(`[NotificationCenter] allow failed:`,e))},[c]),p=(0,X.useCallback)(e=>{c(e.id,`deny`).catch(e=>console.error(`[NotificationCenter] deny failed:`,e))},[c]);Io(!0,e);let m=[{key:null,label:t(`notifications.filter.all`)},{key:`permission_request`,label:t(`notifications.filter.permissions`)},{key:`policy_alert`,label:t(`notifications.filter.policy`)},{key:`error`,label:t(`notifications.filter.errors`)},{key:`security_alert`,label:t(`notifications.filter.security`)},{key:`status_change`,label:t(`notifications.filter.status`)},{key:`info`,label:t(`notifications.filter.info`)}];return V(`div`,{className:`notification-center`,role:`dialog`,"aria-label":t(`notifications.dialogAria`),children:[V(`div`,{className:`notification-center-header`,children:[V(`div`,{className:`notification-center-title-row`,children:[P(`h2`,{className:`notification-center-title`,children:t(`notifications.title`)}),r>0&&P(`span`,{className:`notification-center-badge`,children:r})]}),P(`button`,{className:`btn-icon notification-center-close`,onClick:e,"aria-label":t(`notifications.close`),children:P(Y,{size:18})})]}),P(`div`,{className:`notification-filter-bar`,role:`tablist`,"aria-label":t(`notifications.filterAria`),children:m.map(e=>P(`button`,{role:`tab`,"aria-selected":l===e.key,className:`notification-filter-tab ${l===e.key?`active`:``}`,onClick:()=>u(e.key),children:e.label},e.key??`all`))}),P(`div`,{className:`notification-list`,children:n.length===0?V(`div`,{className:`notification-empty`,children:[P(er,{size:40,strokeWidth:1.2}),P(`span`,{children:t(`notifications.empty`)})]}):n.map(e=>{let n=YP[e.type],r=e.type===`permission_request`&&e.tool?Ks(e,t,iy):null;return V(`div`,{className:`notification-item ${e.read?``:`unread`} ${n.colorClass}`,id:e.type===`policy_alert`&&e.receiptId?`policy-receipt-${encodeURIComponent(e.receiptId)}`:void 0,onClick:()=>d(e.id),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&d(e.id)},children:[!e.read&&P(`span`,{className:`notification-unread-dot`}),P(`span`,{className:`notification-icon`,children:n.icon}),V(`div`,{className:`notification-content`,children:[V(`div`,{className:`notification-content-header`,children:[P(`span`,{className:`notification-agent`,dir:`auto`,children:e.agentName}),P(`span`,{className:`notification-time`,children:XP(e.timestamp,t)})]}),r?V(D.Fragment,{children:[P(`span`,{className:`notification-title`,children:P(sy,{text:r.heading})}),P(`span`,{className:`notification-message`,children:P(sy,{text:r.question})})]}):V(D.Fragment,{children:[e.title&&P(`span`,{className:`notification-title`,children:e.title}),P(`span`,{className:`notification-message`,children:e.message})]}),e.type===`permission_request`&&e.tool&&e.tool!==`allow_path_access`&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.tool`),`: `,P(`code`,{dir:`ltr`,children:e.tool})]}),e.type===`policy_alert`&&V(`div`,{className:`notification-policy-details`,children:[e.tool&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.tool`),`: `,P(`code`,{dir:`ltr`,children:e.tool})]}),e.reason&&V(`span`,{className:`notification-policy-reason`,children:[t(`notifications.reason`),`: `,e.reason]}),e.ruleIds&&e.ruleIds.length>0&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.rules`),`: `,P(`code`,{dir:`ltr`,children:e.ruleIds.join(`, `)})]}),e.policyVersion&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.policy`),`: `,P(`code`,{dir:`ltr`,children:e.policyVersion})]}),V(`span`,{className:`notification-tool`,children:[t(`activity.policy.receipt`),`:`,` `,e.receiptId?P(`code`,{dir:`ltr`,children:e.receiptId}):P(`em`,{children:t(`activity.policy.receiptUnavailable`)})]})]}),e.type===`permission_request`&&!e.response&&V(`div`,{className:`notification-actions`,children:[V(`button`,{className:`notification-action-btn notification-action-allow`,onClick:t=>{t.stopPropagation(),f(e)},children:[P(mr,{size:14}),t(`notifications.approve`)]}),V(`button`,{className:`notification-action-btn notification-action-deny`,onClick:t=>{t.stopPropagation(),p(e)},children:[P(Y,{size:14}),t(`notifications.deny`)]})]}),e.type===`permission_request`&&e.response&&P(`span`,{className:`notification-response-badge ${e.response===`allow`?`response-allow`:`response-deny`}`,children:e.response===`allow`?t(`notifications.approved`):t(`notifications.denied`)})]}),P(`button`,{className:`notification-dismiss`,onClick:t=>{t.stopPropagation(),s(e.id)},"aria-label":t(`notifications.dismiss`),children:P(Y,{size:14})})]},e.id)})}),n.length>0&&V(`div`,{className:`notification-center-footer`,children:[V(`button`,{className:`notification-footer-btn`,onClick:a,disabled:r===0,children:[P(mr,{size:14}),t(`notifications.markAllRead`)]}),V(`button`,{className:`notification-footer-btn notification-footer-clear`,onClick:o,children:[P(lo,{size:14}),t(`notifications.clear`)]})]})]})}var QP=1500,$P=e=>new Promise(t=>setTimeout(t,e));async function eF({onProgress:e,isCancelled:t=()=>!1,pollMs:n=QP}={}){try{await sn(ck)}catch(e){if(e?.httpStatus!==409)throw e;let t=await Ut(ck).catch(()=>null);if(!t||t.status===`completed`||t.status===`failed`)throw e}for(;!t();){let t=await Ut(ck);if(e?.(t),t.status===`completed`)return;if(t.status===`failed`)throw Error(t.error||`The GAIA agent could not be installed.`);await $P(n)}}function tF({onInstalled:e,noBuild:t=!1}){let n=T(),[r,i]=(0,X.useState)({kind:`idle`}),a=(0,X.useRef)(!1);(0,X.useEffect)(()=>()=>{a.current=!0},[]);let o=(0,X.useCallback)(async()=>{i({kind:`installing`,percent:0});try{if(await eF({isCancelled:()=>a.current,onProgress:e=>{a.current||i({kind:`installing`,percent:e.percent??0})}}),a.current)return;await e(),a.current||i({kind:`idle`})}catch(e){a.current||i({kind:`failed`,error:e instanceof Error?e.message:String(e)})}},[e]);return t?P(`div`,{className:`app-notice is-warning`,role:`status`,children:P(`span`,{children:n(`agentNotice.noBuild`)})}):V(`div`,{className:`app-notice is-warning`,role:`status`,children:[r.kind===`installing`?P(`span`,{children:n(`agentNotice.installing`,{percent:Math.round(r.percent)})}):r.kind===`failed`?P(`span`,{children:n(`agentNotice.failed`,{error:r.error})}):P(`span`,{children:n(`agentNotice.missing`)}),r.kind!==`installing`&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>void o(),children:r.kind===`failed`?n(`agentNotice.retry`):n(`agentNotice.install`)})]})}function nF(e,t){if(!(e instanceof Error))return t;let n=e.message,r=n.match(/API \d+: (.+)/);if(r)try{let e=JSON.parse(r[1]);if(e.detail)return e.detail}catch{}return n}function rF(e,t){let{addNotification:n}=Qs.getState();for(let r of t)r.error_count<=(e[r.id]??0)||!r.last_error||n({id:`schedule-error-${r.id}-${r.error_count}`,type:`error`,agentId:`scheduler`,agentName:`GAIA`,title:`Scheduled task "${r.name}" failed`,message:r.last_error,timestamp:Date.now(),read:!1,dismissed:!1,priority:`high`,...r.session_id?{sessionId:r.session_id}:{}})}var iF=p((e,t)=>({schedules:[],loading:!1,error:null,actionError:null,selectedSchedule:null,results:[],resultsLoading:!1,errorCounts:null,loadSchedules:async()=>{t().schedules.length===0&&!t().error&&e({loading:!0}),e({error:null});try{let n=(await At()).schedules||[],r=t().errorCounts;r&&rF(r,n),e({schedules:n,loading:!1,errorCounts:Object.fromEntries(n.map(e=>[e.id,e.error_count]))})}catch(t){d.api.error(`Failed to load schedules`,t),e({error:`Failed to load schedules`,loading:!1})}},createSchedule:async(t,n,r)=>{try{let i=await yt(t,n,r);e(e=>({schedules:[...e.schedules,i],actionError:null}))}catch(e){throw d.api.error(`Failed to create schedule`,e),e}},updateScheduleStatus:async(t,n)=>{try{let r=await ut(t,n);e(e=>({schedules:e.schedules.map(e=>e.name===t?r:e),actionError:null}))}catch(n){d.api.error(`Failed to update schedule "${t}"`,n),e({actionError:nF(n,`Failed to update schedule`)})}},runScheduleNow:async t=>{try{let n=await Jt(t);e(e=>({schedules:e.schedules.map(e=>e.name===t?n:e),actionError:null}))}catch(n){d.api.error(`Failed to run schedule "${t}" now`,n),e({actionError:nF(n,`Could not run the schedule now`)})}},deleteSchedule:async t=>{try{await $e(t),e(e=>({schedules:e.schedules.filter(e=>e.name!==t),selectedSchedule:e.selectedSchedule===t?null:e.selectedSchedule,actionError:null}))}catch(n){d.api.error(`Failed to delete schedule "${t}"`,n),e({actionError:nF(n,`Failed to delete schedule`)})}},selectSchedule:n=>{e({selectedSchedule:n,results:[],resultsLoading:!1}),n&&t().loadResults(n)},loadResults:async n=>{e({resultsLoading:!0});try{let r=await De(n);if(t().selectedSchedule!==n)return;e({results:r.results||[],resultsLoading:!1})}catch(r){if(d.api.error(`Failed to load results for "${n}"`,r),t().selectedSchedule!==n)return;e({results:[],resultsLoading:!1})}},dismissActionError:()=>e({actionError:null})})),aF=new Set([`loading_model`,`downloading_model`,`model_retry`,`waiting`]),oF=5;function sF(e,t){return{id:e,title:t.get(e)?.title??`Untitled chat`}}function cF(e){let t=new Map(e.sessions.map(e=>[e.id,e])),n=e.isStreaming&&e.currentSessionId!==null,r=[...e.runningSessionIds];n&&!r.includes(e.currentSessionId)&&r.push(e.currentSessionId);let i=new Set(r),a=new Set(e.notifications.filter(e=>e.type===`permission_request`&&!e.response&&!e.dismissed&&e.sessionId&&i.has(e.sessionId)).map(e=>e.sessionId)),o=[...a].map(e=>({...sF(e,t),reason:`approval`}));n&&e.awaitingUser&&!a.has(e.currentSessionId)&&o.push({...sF(e.currentSessionId,t),reason:`answer`});for(let[n,r]of Object.entries(e.awaitingBySession))o.some(e=>e.id===n)||o.push({...sF(n,t),reason:r===`question`?`answer`:`approval`});let s=n&&!e.awaitingUser&&e.livePhase&&aF.has(e.livePhase)?e.liveStatus:null,c=e.systemStatus,l=null;if(c?.default_model_is_cloud&&c.default_model_name)l={name:c.default_model_name,where:`cloud`};else if(c?.model_loaded){let e=c.model_labels?.includes(`cloud`),t=c.model_device&&c.model_device!==`none`?c.model_device:null;l={name:c.model_loaded,where:e?`cloud`:t}}let u=[...e.sessions].sort((e,t)=>t.updated_at.localeCompare(e.updated_at)).slice(0,oF).map(e=>sF(e.id,t));return{backendConnected:e.backendConnected,modelServerRunning:c&&!c.default_model_is_cloud?c.lemonade_running:null,model:l,waitingOnModel:s||null,running:r.map(e=>sF(e,t)),needsYou:o,recent:u}}function lF(e){let t=(0,X.useRef)(e);t.current=e,(0,X.useEffect)(()=>{let e=window.gaiaAPI?.tray;if(!e)return;let n=``,r=null,i=()=>{let t=k.getState(),i={backendConnected:t.backendConnected,systemStatus:t.systemStatus,sessions:t.sessions,runningSessionIds:t.runningSessionIds,awaitingBySession:t.awaitingBySession,currentSessionId:t.currentSessionId,isStreaming:t.isStreaming,awaitingUser:t.awaitingUser,liveStatus:t.liveStatus,livePhase:t.livePhase,notifications:Qs.getState().notifications},a=r;if(r=i,a&&Object.keys(i).every(e=>i[e]===a[e]))return;let o=cF(i),s=JSON.stringify(o);s!==n&&(n=s,e.setActivity(o).catch(e=>{n=``,d.system.error(`The tray could not take the app state`,e)}))};i();let a=k.subscribe(i),o=Qs.subscribe(i),s=e.onCommand(e=>{switch(e.type){case`open-chat`:t.current.openChat(e.sessionId);break;case`new-chat`:t.current.newChat();break;case`open-settings`:k.getState().openSettings(e.section);break;case`refresh-status`:t.current.refreshStatus();break;default:d.system.error(`Unknown tray command`,e)}});return()=>{a(),o(),s()}},[])}function uF(){(0,X.useEffect)(()=>{let e=window.gaiaAPI;if(!e)return;let t=Qs.getState().addNotification,n=[e.notification.onNotification(t),e.notification.onPermissionRequest(t),e.tray.onNavigate(e=>{let t=typeof e==`string`&&e.startsWith(`session:`)?e.slice(8):null;if(!t)return;let n=k.getState();n.currentSessionId!==t&&n.setMessages([]),n.setCurrentSession(t)})];return()=>n.forEach(e=>e())},[])}function dF(e,t,n){let r=window.gaiaAPI;if(r){r.notification.show({title:t,body:n,sessionId:e}).then(e=>{e||d.system.warn(`This OS has no desktop notifications; the badge still counts it.`)}).catch(e=>d.system.error(`Could not show the desktop notification`,e));return}if(typeof Notification>`u`){d.system.warn(`This browser has no notifications; the alert was not shown.`);return}if(Notification.permission!==`granted`){d.system.warn(`Browser notifications are ${Notification.permission}; allow them in Settings → Notifications.`);return}let i=new Notification(t,{body:n,tag:`gaia-${e}`});i.onclick=()=>{window.focus(),k.getState().setCurrentSession(e)}}function fF(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=navigator;if(!e.getBattery)return;let n=null,r=()=>{n&&t({charging:n.charging,level:n.level})};return e.getBattery().then(e=>{n=e,r(),e.addEventListener(`levelchange`,r),e.addEventListener(`chargingchange`,r)}).catch(e=>d.system.warn(`Battery level unavailable; keep-awake ignores the battery policy.`,e)),()=>{n?.removeEventListener(`levelchange`,r),n?.removeEventListener(`chargingchange`,r)}},[]),e}function pF(){uF();let e=k(e=>e.runningSessionIds),t=k(e=>e.awaitingBySession),n=k(e=>e.sessions),r=k(e=>e.currentSessionId),i=Qs(ko(nc)),a=lc(),o=fF(),s=(0,X.useRef)(null),c=gc(e,t,i),l=JSON.stringify(c);(0,X.useEffect)(()=>{let e=JSON.parse(l),t=s.current;if(s.current=e,t===null)return;let{sessions:n,currentSessionId:r}=k.getState(),i=document.hasFocus(),o=!1;for(let{sessionId:s,event:c}of _c(t,e)){let e=n.find(e=>e.id===s);if(e?.kind===`eval`||e?.kind===`scheduled`)continue;let t=a.modes[c];if(!(t===`off`||bc(s,r,i))&&(o=!0,t===`banner`)){if(c!==`finished`){let{title:t,body:n}=yc(c,e);dF(s,t,n)}else mt(s).then(e=>{k.getState().updateSessionInList(s,e);let{title:t,body:n}=yc(c,e);dF(s,t,n)}).catch(t=>{d.system.error(`Could not read how chat ${s} ended`,t);let{title:n,body:r}=yc(c,{...e,last_run_status:null});dF(s,n,r)})}}if(o){if(a.sound)try{Cc()}catch(e){d.system.warn(`Alert sound not played`,e)}a.flash&&!i&&window.gaiaAPI&&window.gaiaAPI.notification.flash().catch(e=>d.system.error(`Could not flash the taskbar button`,e))}},[l,a.modes,a.sound,a.flash]);let u=xc(n,c,a.modes,r);(0,X.useEffect)(()=>{window.gaiaAPI?.notification.setAttentionCount(u).catch(e=>d.system.error(`Could not update the taskbar badge`,e))},[u]);let f=a.keepAwake&&e.length>0&&Sc(o,a.batteryFloor);(0,X.useEffect)(()=>{window.gaiaAPI?.power.setKeepAwake(f).catch(e=>d.system.error(`Could not change keep-awake`,e))},[f])}function mF(e){if(e<=0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.min(Math.floor(Math.log(e)/Math.log(t)),n.length-1);return parseFloat((e/t**r).toFixed(1))+` `+n[r]}function hF(e){return e.replace(/-/g,``).slice(0,7)}function gF(e,t){let n=t.replace(/^#/,``).toLowerCase();if(!n||n.length<4)return null;let r=e.find(e=>e.id.replace(/-/g,``).toLowerCase().startsWith(n));return r?r.id:null}function _F(e,t,n){return!e||t&&(e===t||e===hF(t))?null:n.some(t=>t.id===e)?e:gF(n,e)}function vF(e){return new URLSearchParams(e.search).get(`session`)||e.hash.replace(/^#/,``)||null}var yF=`gaia:last-session`;function bF(e){try{e?localStorage.setItem(yF,e):localStorage.removeItem(yF)}catch(e){d.ui.warn(`Could not save the open chat for the next launch`,e)}}function xF(){try{return localStorage.getItem(yF)}catch(e){return d.ui.warn(`Could not read the chat open at last launch`,e),null}}var SF=1e3,CF=3e4;function wF(e,{initialMs:t=SF,maxMs:n=CF,onError:r}={}){let i=t,a=0,o=null,s=!1,c=!1,l=!1,u=()=>{l||c||s||(o&&=(clearTimeout(o),null),s=!0,a+=1,e().then(()=>{c=!0}).catch(e=>{l||(r?.(e,a),o=setTimeout(()=>{o=null,u()},i),i=Math.min(i*2,n))}).finally(()=>{s=!1}))};return u(),{kick:()=>{o&&u()},stop:()=>{l=!0,o&&clearTimeout(o),o=null},done:()=>c}}function TF(e,t,n){return e&&!t&&!n}var EF=(0,X.lazy)(()=>IP(()=>import(`./MemoryDashboard-D3BSEWvI.js`).then(e=>({default:e.MemoryDashboard})),__vite__mapDeps([6,1,2,7,8]),import.meta.url)),DF=(0,X.lazy)(()=>IP(()=>import(`./ScheduleManager-BwuPu7-w.js`).then(e=>({default:e.ScheduleManager})),__vite__mapDeps([9,1,2,7,3,10]),import.meta.url)),OF=(0,X.lazy)(()=>IP(()=>import(`./DocumentLibrary-V2n1obTR.js`).then(e=>({default:e.DocumentLibrary})),__vite__mapDeps([11,1,2,3,12]),import.meta.url)),kF=(0,X.lazy)(()=>IP(()=>import(`./FileBrowser-D5gu5VB9.js`).then(e=>({default:e.FileBrowser})),__vite__mapDeps([13,1,2,3,14]),import.meta.url)),AF=(0,X.lazy)(()=>IP(()=>import(`./MobileAccessModal-DGKfraeR.js`).then(e=>({default:e.MobileAccessModal})),__vite__mapDeps([15,1,2,3,16]),import.meta.url)),jF=3,MF=3e5,NF=6e3,PF=6e4,FF=e=>e instanceof TypeError,IF=e=>new Promise(t=>setTimeout(t,e)),LF=3e5,RF=class extends Error{};async function zF(){let e=Date.now()+LF;for(;;){let t=await it();if(t.state===`ready`)return;if(t.state===`failed`||t.state===`cancelled`)throw new RF(t.error||I().bare(`setup.upgrading.stopped`));if(Date.now()>=e)throw Error(I().bare(`setup.upgrading.slow`));await IF(SF)}}function BF(){return P(`div`,{className:`loading-spinner`,role:`status`,"aria-label":`Loading`})}var VF=e=>e===1||e%10==0;function HF(){let e=T(),t=k(e=>e.currentSessionId),n=k(e=>e.setSessions),r=k(e=>e.setCurrentSession),i=k(e=>e.addSession),a=k(e=>e.setMessages),o=k(e=>e.showDocLibrary),s=k(e=>e.showFileBrowser),c=k(e=>e.showMemoryDashboard),l=k(e=>e.showSchedules),u=k(e=>e.sidebarOpen),f=k(e=>e.sidebarCollapsed),p=k(e=>e.setSidebarOpen),h=k(e=>e.setSystemStatus),g=k(e=>e.setBackendConnected),_=k(e=>e.setAgents),v=k(e=>e.agents),y=k(e=>e.setPendingPrompt),b=k(e=>e.setDefaultPermissionMode),x=k(e=>e.openSettings),S=k(e=>e.settingsSection),C=k(e=>e.syncSystemTheme),w=cs(e=>e.restoreNotice),E=cs(e=>e.dismissRestoreNotice),D=Qs(e=>e.showPanel),O=k(e=>e.systemStatus?.initialized===!0),A=(0,X.useRef)(!1),j=Qs(e=>e.setShowPanel);(0,X.useEffect)(()=>{if(!w?.ok)return;let e=setTimeout(E,NF);return()=>clearTimeout(e)},[w,E]);let[M,N]=(0,X.useState)({state:`checking`}),F=k(e=>e.setupAgain),I=k(e=>e.runSetupAgain),ee=(0,X.useRef)(M);ee.current=M;let[R,z]=(0,X.useState)(!1),B=(0,X.useRef)(R);B.current=R;let[te,ne]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(!1),ae=te||R&&!lk(v),oe=(0,X.useRef)(ae);oe.current=ae;let[H,se]=(0,X.useState)(null),[W,G]=(0,X.useState)(``),[ce,le]=(0,X.useState)(0),[de,fe]=(0,X.useState)(!1),[pe,me]=(0,X.useState)(!1),[he,ge]=(0,X.useState)(null),[_e,ve]=(0,X.useState)(null),ye=(0,X.useRef)(async()=>{}),be=(0,X.useRef)(async()=>{}),xe=(0,X.useCallback)(async(e=!1,t=!1)=>{e||N({state:`checking`});let n=0;try{for(;;){await cs.getState().refresh();let e=!!cs.getState().active?.remote,r;try{r=await Wt(e)}catch(e){if(!t||!FF(e)||n>=PF)throw e;await IF(SF),n+=SF;continue}if(!r.ready&&r.stage===`upgrade`){N({state:`upgrading`});let t=await it();(!t.upgrade_embedded||t.state!==`running`&&t.state!==`verifying`)&&await _t(e,!1,{upgradeEmbedded:!0}),await zF(),r=await Wt(e)}n>0&&await Promise.all([ye.current(),be.current()]),ie(!!r.no_agent_build),N(r.ready?{state:`ready`}:{state:`needed`,check:r});return}}catch(e){let t=e instanceof Error?e.message:String(e);if(e instanceof RF){d.system.warn(`Updating the local model server failed`,e),N({state:`unknown`,error:t,upgradeFailed:!0});return}d.system.warn(`Setup check could not be answered`,e),N({state:`unknown`,error:t})}},[]),Se=(0,X.useRef)(0),Ce=(0,X.useCallback)(async()=>{let e=++Se.current,t=(await vn()).agents||[];e===Se.current&&(_(t),z(!0),lk(t)&&ne(!1))},[_]),we=(0,X.useCallback)(()=>{let e=B.current;z(!1),Ce().catch(t=>{d.api.warn(`Agent list unavailable after setup`,t),e&&z(!0)})},[Ce]);(0,X.useEffect)(()=>{let e=()=>{oe.current&&Ce().catch(e=>d.api.warn(`Agent list unavailable`,e))};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[Ce]);let Te=(0,X.useCallback)(async()=>{b((await on()).default_mode)},[b]),Ee=(0,X.useRef)([]);(0,X.useEffect)(()=>{m(`0.26.0rc6`),xe(!1,!0);let e=[wF(Ce,{onError:(e,t)=>{VF(t)&&d.api.warn(`Agent list unavailable (attempt ${t}); retrying`,e)}}),wF(Te,{onError:(e,t)=>{VF(t)&&d.api.warn(`Default permission mode unavailable (attempt ${t}); retrying`,e)}})];return Ee.current=e,()=>e.forEach(e=>e.stop())},[xe,Ce,Te]);let De=(0,X.useCallback)(()=>{Ee.current.forEach(e=>e.kick()),cs.getState().retryNow(),be.current();let e=ee.current;e.state===`unknown`&&!e.upgradeFailed&&xe(!0)},[xe]),Oe=(0,X.useRef)(De);Oe.current=De;let ke=(0,X.useRef)(0),Ae=(0,X.useRef)(0),je=(0,X.useRef)(null),Me=(0,X.useRef)(!1),[Ne,Pe]=(0,X.useState)(!1),[Fe,Ie]=(0,X.useState)(null),Le=(0,X.useCallback)(e=>{if(e.kind===`unreachable`){d.system.warn(`System status check failed`,e.error),Me.current=!0,Ae.current=0,je.current=null,Pe(!1),Ie(null),g(!1),h(null);return}if(e.kind===`error`){d.system.warn(`System status answered HTTP ${e.httpStatus}`,e.message),Me.current&&Oe.current(),Me.current=!1,Ae.current=0,je.current=null,Pe(!1),Ie(`HTTP ${e.httpStatus}: ${e.message}`),g(!0);return}if(e.kind===`slow`){if(Ae.current+=1,je.current??=Date.now(),Ie(null),d.system.warn(`System status did not answer in time (${Ae.current} in a row)`),Date.now()-je.current>=MF){Pe(!1),g(!1),h(null);return}g(!0),(Me.current||Ae.current>=jF)&&Pe(!0);return}let{status:t}=e;Me.current&&Oe.current(),Me.current=!1,Ae.current=0,je.current=null,Pe(!1),Ie(null),g(!0),ke.current=t.lemonade_running?0:ke.current+1;let n=k.getState().systemStatus;t.lemonade_running||ke.current>=jF||!n?.lemonade_running?h(t):h({...n,download_progress:t.download_progress})},[g,h]),Re=(0,X.useRef)(Le);Re.current=Le;let[ze]=(0,X.useState)(()=>Kw(e=>Re.current(e))),Be=ze.check;ye.current=Be,(0,X.useEffect)(()=>_k(ze.start),[ze]),(0,X.useEffect)(()=>HP(()=>{Be()}),[Be]);let Ve=(0,X.useRef)(``);(0,X.useEffect)(()=>{let e=e=>Ft().then(t=>{let r=t.sessions||[];if(!e&&r.length===0&&k.getState().sessions.length>0)return;let i=r.map(e=>`${e.id}|${e.updated_at}|${e.title}|${e.inference_remote}|${e.inference_provider}|${e.inference_description}|${e.effective_model}|${e.unread}|${e.pinned}|${e.last_run_status}|${e.kind}`).join(`
82
82
  `);if(i===Ve.current)return;Ve.current=i,n(r);let a=cs.getState().active?.model;a&&r.some(e=>e.effective_model&&e.effective_model!==a)&&cs.getState().refresh()}).catch(t=>{e&&d.system.error(`Could not load chats`,t)});be.current=()=>e(!1),e(!0);let t=setInterval(()=>void e(!1),5e3);return()=>clearInterval(t)},[n]),(0,X.useEffect)(()=>aT(),[]),(0,X.useEffect)(()=>{let e=()=>{iF.getState().loadSchedules()};e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[]),(0,X.useEffect)(()=>CT(),[]),pF();let He=(0,X.useRef)(!1),Ue=(0,X.useRef)(!1);(0,X.useEffect)(()=>{let e=()=>{let e=vF(window.location),{currentSessionId:t,sessions:n}=k.getState(),i=_F(e,t,n);return i&&(r(i),a([])),i},t=()=>{if(He.current||(He.current=!0,e()||k.getState().currentSessionId))return;if(window.location.hash){window.history.replaceState(null,``,window.location.pathname+window.location.search);return}if(Ue.current||xn(`new-chat`))return;let{sessions:t}=k.getState(),n=_F(xF(),null,t);n&&(r(n),a([]))},n=k.subscribe(e=>{e.sessions.length>0&&t()});return k.getState().sessions.length>0&&t(),window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{n(),window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[r,a]),(0,X.useEffect)(()=>{let e=null,t=2e3,n=!1,i=null,o=()=>{n||(e=new EventSource(`${L()}/sessions/events`),e.onopen=()=>{t=2e3},e.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch(e){d.api.warn(`Malformed session event`,e);return}t.type===`set_active_session`&&t.session_id&&t.session_id!==k.getState().currentSessionId&&(r(t.session_id),a([]))},e.onerror=()=>{e?.close(),e=null,!n&&(i=setTimeout(o,t),t=Math.min(t*2,3e4))})};return o(),()=>{n=!0,i&&clearTimeout(i),e?.close()}},[r,a]),(0,X.useEffect)(()=>{if(He.current&&bF(t),t){let e=hF(t);window.location.hash!==`#${e}`&&window.history.replaceState(null,``,`#${e}`)}else He.current&&window.location.hash&&window.history.replaceState(null,``,window.location.pathname+window.location.search)},[t]);let We=(0,X.useCallback)(async e=>{if(se(null),!await Go(`chat`))return G(e),!1;let t=k.getState(),n;try{n=await En({title:`New Task`,agent_type:ck,document_ids:t.draftDocumentIds,private:t.draftPrivate,folders:t.draftFolder?[t.draftFolder]:[]})}catch(e){throw uk(e)?(ne(!0),Error(`The GAIA agent isn't installed. Install it from the notice above, then send again.`)):e}oe.current&&(ne(!1),Ce().catch(e=>d.api.warn(`Agent list unavailable`,e))),t.defaultPermissionModeKnown||(await Te().catch(e=>d.api.warn(`Default permission mode unavailable; using the chip's mode`,e)),t=k.getState()),t.clearDraftDocuments(),t.setDraftPrivate(!1),t.setDraftFolder(null);let o=null;try{await Pt(n.id,t.draftPermissionMode)}catch(e){o=e}return Mt(Je),o&&!n.private&&nn(U(n.id),e),i(n),r(n.id),a([]),G(``),o?(se(`The chat was created, but its permission mode could not be set, so your message was not sent${n.private?``:` — it is in the chat's box`}: ${o instanceof Error?o.message:o}`),!1):(t.resetDraftPermissionMode(),y({sessionId:n.id,text:e}),!0)},[i,r,a,y,Ce,Te]),Ge=(0,X.useCallback)(()=>{let e=k.getState(),t=e.currentSessionId;t&&jc(t,e)&&Mc(t),e.setShowMemoryDashboard(!1),e.setShowSchedules(!1),Ue.current=!0,r(null),a([]),le(e=>e+1)},[r,a]);lF({openChat:(0,X.useCallback)(e=>{let t=k.getState();t.closeSettings(),e!==t.currentSessionId&&(Mc(t.currentSessionId),a([])),r(e)},[r,a]),newChat:(0,X.useCallback)(()=>{k.getState().closeSettings(),Ge()},[Ge]),refreshStatus:()=>void Be()});let Ke=(0,X.useCallback)(e=>{Ge(),We(`Load the \`${e}\` skill, then tell me briefly what it lets you do.`).catch(e=>se(e instanceof Error?e.message:String(e)))},[Ge,We]),qe=(0,X.useCallback)(e=>{N({state:`ready`}),we(),Be(),e&&(e.needs_input?G(e.prompt):We(e.prompt).catch(e=>se(e instanceof Error?e.message:String(e))))},[Be,We,we]),Ye=(0,X.useCallback)(()=>{N({state:`ready`}),Be()},[Be]);(0,X.useEffect)(()=>{let e=()=>{k.getState().closeSettings(),N({state:`addingLocal`})};return window.addEventListener(`gaia:set-up-local`,e),()=>window.removeEventListener(`gaia:set-up-local`,e)},[]),(0,X.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&(e.shiftKey&&e.key.toLowerCase()===`o`?(e.preventDefault(),Ge()):!e.shiftKey&&e.key.toLowerCase()===`k`?(e.preventDefault(),window.dispatchEvent(new CustomEvent(`gaia:focus-search`))):!e.shiftKey&&e.key.toLowerCase()===`b`?(e.preventDefault(),k.getState().toggleSidebarCollapsed()):!e.shiftKey&&e.key===`,`&&(e.preventDefault(),x()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Ge,x]),(0,X.useEffect)(()=>{let e=window.matchMedia?.(`(max-width: 768px)`);if(!e)return;let t=()=>p(!e.matches);return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[p]),(0,X.useEffect)(()=>{if(typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(prefers-color-scheme: light)`);return e.addEventListener(`change`,C),()=>e.removeEventListener(`change`,C)},[C]),(0,X.useEffect)(()=>{Sn().then(e=>me(e.active===!0)).catch(e=>d.system.debug(`Mobile access unavailable`,e))},[]);let Xe=(0,X.useCallback)(async()=>{if(fe(!0),ge(null),pe)ve(null);else try{let e=await Pn(),t=e.reason===`ngrok_not_installed`;if(ve(t?e.installCommands??[]:null),t)return;e.error?ge(e.error):me(!0)}catch(e){ve(null),ge(e instanceof Error?e.message:`Could not start mobile access`)}},[pe]),Ze=(0,X.useCallback)(async()=>{try{await ue(),me(!1),fe(!1)}catch(e){ge(e instanceof Error?e.message:`Could not stop mobile access`)}},[]);ND(e=>{e?Xe():Ze()}),(0,X.useEffect)(()=>{jD(pe)},[pe]);let Qe=typeof window<`u`&&window.innerWidth<=768,$e=TF(M.state===`checking`,O,A.current);if(!$e&&M.state!==`needed`&&(A.current=!0),$e)return P(`div`,{className:`app`,children:V(`main`,{className:`startup`,role:`status`,"aria-label":`Starting GAIA`,children:[P(`div`,{className:`loading-spinner`,"aria-hidden":`true`}),P(`p`,{className:`startup-text`,children:`Starting GAIA…`})]})});if(M.state===`upgrading`)return P(`div`,{className:`app`,children:V(`main`,{className:`startup`,role:`status`,"aria-live":`polite`,"aria-label":e(`setup.upgrading.notice`),children:[P(`div`,{className:`loading-spinner`,"aria-hidden":`true`}),P(`p`,{className:`startup-text`,children:e(`setup.upgrading.notice`)})]})});if(M.state===`needed`||M.state===`addingLocal`||F){let e=F?()=>I(!1):M.state===`addingLocal`?Ye:void 0;return V(`div`,{className:`app`,children:[P(bN,{onReady:e=>{I(!1),qe(e)},onClose:e}),P(HA,{}),P(JP,{})]})}let et=c?P(X.Suspense,{fallback:P(BF,{}),children:P(EF,{})}):t?P(kk,{sessionId:t},t):P(LA,{onSend:We,initialText:W,focusRequest:ce},W);return V(`div`,{className:`app`,children:[!u&&P(`button`,{className:`sidebar-toggle`,onClick:()=>p(!0),"aria-label":`Open sidebar`,children:P(sa,{size:18})}),P(`div`,{className:`sidebar-overlay ${u?`visible`:``}`,onClick:()=>p(!1),"aria-hidden":`true`}),P(ol,{onNewChat:Ge,onMobileAccess:Qe?void 0:()=>void Xe(),tunnelActive:pe}),V(`div`,{className:`main-content`,children:[M.state===`ready`&&P(qP,{onRetry:Be,backendSlow:Ne,backendError:Fe}),M.state===`unknown`&&(M.upgradeFailed?V(`div`,{className:`app-notice is-warning`,role:`status`,children:[P(`span`,{children:e(`setup.upgrading.failed`,{error:M.error})}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>void xe(),children:e(`setup.upgrading.retry`)})]}):V(`div`,{className:`app-notice is-warning`,role:`status`,children:[P(`span`,{children:e(`setup.unknown.failed`,{error:M.error})}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>void xe(),children:e(`setup.unknown.retry`)})]})),(!u||f)&&P(Rs,{placement:`main`}),ae&&P(tF,{onInstalled:Ce,noBuild:re}),w&&V(`div`,{className:`app-notice${w.ok?``:` is-warning`}`,role:`status`,children:[P(`span`,{children:w.message}),!w.ok&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>{E(),x(`model`)},children:`Pick a model`}),P(`button`,{type:`button`,className:`app-notice-close`,onClick:E,"aria-label":`Dismiss`,children:P(Y,{size:14})})]}),et]}),l&&P(X.Suspense,{fallback:null,children:P(DF,{})}),o&&P(X.Suspense,{fallback:null,children:P(OF,{})}),s&&P(X.Suspense,{fallback:null,children:P(kF,{onStartChat:We})}),D&&P(`div`,{className:`notification-center-popover`,children:P(ZP,{onClose:()=>j(!1)})}),de&&P(X.Suspense,{fallback:null,children:P(AF,{isOpen:de,onClose:()=>fe(!1),onStop:()=>void Ze(),error:he,setupCommands:_e,onRetry:()=>void Xe()})}),S&&P(BP,{onUseSkill:Ke}),P(HA,{}),P(JP,{}),H&&P(`div`,{className:`toast`,role:`alert`,children:H})]})}var UF=`agent-refresh`,WF={"pre-checks":`engine.stage.preChecks`,"ensure-uv":`engine.stage.ensureUv`,"create-venv":`engine.stage.createVenv`,"install-package":`engine.stage.installPackage`,verify:`engine.stage.verify`,[UF]:`engine.stage.agentRefresh`,start:`engine.stage.start`},GF={disk:`engine.hint.disk`,network:`engine.hint.network`,tls:`engine.hint.tls`,locked:`engine.hint.locked`,daemon:`engine.hint.daemon`};function KF(e,t){if(!e)return t(`engine.stage.neutral`);let n=WF[e];return n?t(n):(console.warn(`[EngineInstallScreen] install stage "${e}" has no label`),t(`engine.stage.neutral`))}function qF(e,t){return e.reason?t(GF[e.reason]):t(e.stage===UF?`engine.hint.agent`:`engine.hint.other`)}function JF(e){return e.reason===`locked`&&e.lockedBy?.length?e.lockedBy:null}function YF(e,t){let n=e.name??String(e.pid),r=e.folder;return e.isGaia?r?t(`engine.locked.gaia`,{name:n,folder:r}):t(`engine.locked.gaiaNoFolder`,{name:n}):r?t(`engine.locked.other`,{name:n,folder:r}):t(`engine.locked.otherNoFolder`,{name:n})}function XF({status:e}){let t=T(),n=KF(e.stage,t);return V(`div`,{className:`engine-progress`,role:`status`,children:[V(`div`,{className:`engine-progress-head`,children:[P(`span`,{children:n}),e.percent!==null&&V(`bdi`,{dir:`ltr`,children:[e.percent,`%`]})]}),P(`progress`,{className:`engine-bar`,"aria-label":n,max:100,value:e.percent??void 0})]})}function ZF({error:e,busy:t,notice:n,onRetry:r,onCloseLockers:i,onContinue:a,onRevert:o,onOpenLog:s}){let c=T(),l=JF(e),u=l!==null&&l.every(e=>e.isGaia),d=(l?.length??0)>1;return V(`div`,{className:`engine-failure`,children:[V(`div`,{role:`alert`,children:[l?V(D.Fragment,{children:[l.map(e=>P(`p`,{className:`engine-hint`,children:YF(e,c)},e.pid)),!u&&P(`p`,{className:`engine-hint`,children:c(d?`engine.locked.closeThenMany`:`engine.locked.closeThen`)})]}):P(`p`,{className:`engine-hint`,children:qF(e,c)}),P(`p`,{className:`engine-error`,children:P(`bdi`,{dir:`ltr`,children:e.message})})]}),u&&P(`button`,{type:`button`,className:`btn-primary engine-retry`,disabled:t,onClick:i,autoFocus:!0,children:c(d?`engine.locked.closeMany`:`engine.locked.close`)}),P(`button`,{type:`button`,className:`${u?`btn-secondary`:`btn-primary`} engine-retry`,disabled:t,onClick:r,autoFocus:!u,children:c(`engine.tryAgain`)}),e.stage===UF&&P(`button`,{type:`button`,className:`btn-secondary engine-retry`,disabled:t,onClick:a,children:c(`engine.continueWithout`)}),e.previousVersion&&P(`button`,{type:`button`,className:`btn-secondary engine-retry`,disabled:t,onClick:o,children:c(`update.chip.goBack`,{version:e.previousVersion})}),n&&P(`p`,{className:`engine-error`,role:`alert`,children:P(`bdi`,{dir:`ltr`,children:n})}),V(`details`,{className:`engine-details`,children:[P(`summary`,{children:c(`engine.details`)}),P(`pre`,{className:`engine-log`,dir:`ltr`,children:e.logTail.join(`
83
83
  `)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:s,children:c(`engine.openLog`)})]})]})}function QF(){let e=T(),[t,n]=(0,X.useState)({phase:`running`,stage:null,percent:null,message:``,error:null}),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(null),s=(0,X.useCallback)(e=>{console.error(`[EngineInstallScreen] the desktop app did not answer`,e),o(e instanceof Error?e.message:String(e))},[]);(0,X.useEffect)(()=>{let e=window.gaiaInstall,t=e.onProgress(n);return e.status().then(n).catch(s),t},[s]);let c=(0,X.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.retry().catch(s).finally(()=>i(!1))},[s]),l=(0,X.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.closeLockingPrograms().catch(s).finally(()=>i(!1))},[s]),u=(0,X.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.continueWithoutAgentUpdate().catch(s).finally(()=>i(!1))},[s]),d=(0,X.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.revert().then(e=>{e||i(!1)}).catch(e=>{s(e),i(!1)})},[s]),f=(0,X.useCallback)(()=>{o(null),window.gaiaInstall.openLogFile().then(e=>{e.ok||o(e.message)}).catch(s)},[s]),{error:p}=t,m=t.phase===`failed`&&p,h=e(m?p.stage===UF?`engine.failed.agentTitle`:`engine.failed.title`:`engine.title`);return P(`div`,{className:`app`,children:P(`main`,{className:`engine`,children:V(`div`,{className:`engine-inner`,children:[P(`h1`,{className:`engine-title`,children:h}),m?P(ZF,{error:p,busy:r,notice:a,onRetry:c,onCloseLockers:l,onContinue:u,onRevert:d,onOpenLog:f}):V(D.Fragment,{children:[P(`p`,{className:`engine-lede`,children:e(`engine.lede`)}),P(XF,{status:t}),a&&P(`p`,{className:`engine-error`,role:`alert`,children:P(`bdi`,{dir:`ltr`,children:a})})]})]})})})}function $F(){return!!window.gaiaInstall&&new URLSearchParams(window.location.search).get(`engine`)===`install`}async function eI(e){if(!e.isProduction||e.protocol!==`https:`&&e.protocol!==`http:`||!e.serviceWorker)return!1;try{return await e.serviceWorker.register(`./sw.js`,{scope:`./`}),!0}catch(e){return console.error(`[pwa] Service worker registration failed, so the UI is not cached for an installed app:`,e),!1}}Vs(),u();var tI=localStorage.getItem(`gaia-chat-theme`);S(x(tI===`light`||tI===`dark`?tI:`system`));var nI=k.getState();i(nI.palette,nI.customColors,nI.theme),s(nI.locale),C(),l(),Co.createRoot(document.getElementById(`root`)).render(P(X.StrictMode,{children:$F()?P(QF,{}):P(HF,{})})),window.addEventListener(`load`,()=>{eI({isProduction:!0,protocol:window.location.protocol,serviceWorker:`serviceWorker`in navigator?navigator.serviceWorker:void 0})});export{Uh as $,$k as A,Qr as At,oA as B,wr as Bt,Yk as C,Qi as Ct,_A as D,vi as Dt,Zk as E,bi as Et,vA as F,Br as Ft,mA as G,mr as Gt,gA as H,br as Ht,lA as I,Pr as It,jT as J,LT as K,ir as Kt,uA as L,Mr as Lt,Gk as M,Jr as Mt,Qk as N,Kr as Nt,qk as O,gi as Ot,nA as P,Wr as Pt,Xh as Q,aA as R,Or as Rt,Xk as S,na as St,rA as T,Ei as Tt,xA as U,vr as Ut,cA as V,Sr as Vt,eA as W,gr as Wt,sS as X,NT as Y,Jh as Z,fA as _,Na as _t,XN as a,Io as at,Jk as b,pa as bt,JN as c,ho as ct,UA as d,lo as dt,Pc as et,OA as f,to as ft,dA as g,Fa as gt,hA as h,za as ht,IP as i,Go as it,pA as j,Xr as jt,Kk as k,ni as kt,SN as l,po as lt,SA as m,Va as mt,iF as n,Ec as nt,YN as o,Y as ot,bA as p,$a as pt,zT as q,Xn as qt,UP as r,ds as rt,qN as s,xo as st,mF as t,Nc as tt,xN as u,J as ut,iA as v,Da as vt,tA as w,Ii as wt,CA as x,q as xt,yA as y,Ca as yt,sA as z,Er as zt};