@amd-gaia/agent-ui 0.26.0-rc.13 → 0.26.0-rc.15
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.
- package/assets/tray-iconTemplate.png +0 -0
- package/assets/tray-iconTemplate@2x.png +0 -0
- package/dist/assets/{AdvancedSettings-BoC1tuaH.js → AdvancedSettings-DBTNzH7K.js} +1 -1
- package/dist/assets/{ConnectorsPane-DbsiVn90.js → ConnectorsPane-10jS6xLA.js} +1 -1
- package/dist/assets/{DocumentLibrary-CTJeAYzK.js → DocumentLibrary-cThIBsTi.js} +1 -1
- package/dist/assets/{FileBrowser-BmXmrO_H.js → FileBrowser-TlXAnuMz.js} +1 -1
- package/dist/assets/{MemoryDashboard-B0WUgGUQ.js → MemoryDashboard-C-qhmLse.js} +1 -1
- package/dist/assets/{MobileAccessModal-Ce_pSNV0.js → MobileAccessModal-Bo6LvTRA.js} +1 -1
- package/dist/assets/{ScheduleManager-DBmyJkoF.js → ScheduleManager-BEwxv5Ds.js} +1 -1
- package/dist/assets/{api-Dz-kUmy_.js → api-C8FnUvs-.js} +1 -1
- package/dist/assets/{index-BGIyiDas.js → index-CRMb93uM.js} +6 -6
- package/dist/assets/index-Dq2z3aor.css +1 -0
- package/dist/assets/{useT-B4DSIvt0.js → useT-ZJ2CrF0T.js} +2 -2
- package/dist/assets/{zap-D7Qg7Qny.js → zap-C7ZhX0aQ.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/sw.js +1 -1
- package/main.cjs +10 -0
- package/package.json +1 -1
- package/services/appimage-launcher.cjs +116 -0
- package/services/tray-manager.cjs +4 -13
- package/assets/tray-icon-active.png +0 -0
- package/assets/tray-icon-active@2x.png +0 -0
- package/dist/assets/index-JCP-qf3I.css +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ConnectorsPane-
|
|
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-B4DSIvt0.js";import{$ as H,$n as U,$t as W,A as G,An as se,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 ot,Vn as st,Vt as ct,W as lt,Wn as ut,Wt as dt,X as ft,Xn as pt,Xt as mt,Y as ht,Yn as gt,Z as _t,Zn as vt,Zt as yt,_ as bt,_t as xt,a as St,an as Ct,b as wt,bt as Tt,c as Et,cn as Dt,ct as Ot,d as kt,dn as At,dt as jt,en as Mt,er as Nt,et as Pt,fn as Ft,ft as It,g as Lt,gt as Rt,h as zt,ht as Bt,i as Vt,in as Ht,it as Ut,j as Wt,jn as Gt,jt as Kt,k as qt,kn as Jt,kt as Yt,l as Xt,ln as Zt,lt as Qt,m as $t,mn as en,mt as tn,nn,nr as rn,nt as an,o as on,on as sn,ot as cn,p as ln,pt as un,q as dn,qn as fn,qt as pn,r as mn,rn as hn,rt as gn,s as _n,sn as vn,st as yn,t as bn,tn as xn,tr as Sn,tt as Cn,u as wn,un as Tn,ut as En,v as Dn,vt as On,w as kn,x as An,xn as jn,yt as Mn,z as Nn,zn as Pn,zt as Fn}from"./api-Dz-kUmy_.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 In=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}}}})),Ln=n(((e,t)=>{t.exports=In()})),Rn=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`})),zn=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=Rn()})),Bn=n((e=>{var t=Ln(),n=f(),r=zn();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,W={pending:!1,data:null,method:null,action:null},G=[],se=-1;function ce(e){return{current:e}}function le(e){0>se||(e.current=G[se],G[se]=null,se--)}function ue(e,t){se++,G[se]=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=W)}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(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ConnectorsPane-10jS6xLA.js","./rolldown-runtime-XKyaHtl9.js","./useT-ZJ2CrF0T.js","./api-C8FnUvs-.js","./ConnectorsPane-B1lwOGL5.css","./AdvancedSettings-DBTNzH7K.js","./MemoryDashboard-C-qhmLse.js","./zap-C7ZhX0aQ.js","./MemoryDashboard-DwrWAXi6.css","./ScheduleManager-BEwxv5Ds.js","./ScheduleManager-CjHJ4NbD.css","./DocumentLibrary-cThIBsTi.js","./DocumentLibrary-CM6o8j2T.css","./FileBrowser-TlXAnuMz.js","./FileBrowser-Cna3BsT7.css","./MobileAccessModal-Bo6LvTRA.js","./MobileAccessModal-BkVDm3YG.css"])))=>i.map(i=>d[i]);
|
|
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-ZJ2CrF0T.js";import{$ as H,$n as U,$t as W,A as G,An as se,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 ot,Vn as st,Vt as ct,W as lt,Wn as ut,Wt as dt,X as ft,Xn as pt,Xt as mt,Y as ht,Yn as gt,Z as _t,Zn as vt,Zt as yt,_ as bt,_t as xt,a as St,an as Ct,b as wt,bt as Tt,c as Et,cn as Dt,ct as Ot,d as kt,dn as At,dt as jt,en as Mt,er as Nt,et as Pt,fn as Ft,ft as It,g as Lt,gt as Rt,h as zt,ht as Bt,i as Vt,in as Ht,it as Ut,j as Wt,jn as Gt,jt as Kt,k as qt,kn as Jt,kt as Yt,l as Xt,ln as Zt,lt as Qt,m as $t,mn as en,mt as tn,nn,nr as rn,nt as an,o as on,on as sn,ot as cn,p as ln,pt as un,q as dn,qn as fn,qt as pn,r as mn,rn as hn,rt as gn,s as _n,sn as vn,st as yn,t as bn,tn as xn,tr as Sn,tt as Cn,u as wn,un as Tn,ut as En,v as Dn,vt as On,w as kn,x as An,xn as jn,yt as Mn,z as Nn,zn as Pn,zt as Fn}from"./api-C8FnUvs-.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 In=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}}}})),Ln=n(((e,t)=>{t.exports=In()})),Rn=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`})),zn=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=Rn()})),Bn=n((e=>{var t=Ln(),n=f(),r=zn();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,W={pending:!1,data:null,method:null,action:null},G=[],se=-1;function ce(e){return{current:e}}function le(e){0>se||(e.current=G[se],G[se]=null,se--)}function ue(e,t){se++,G[se]=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=W)}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(`
|
|
5
5
|
`),l=s.split(`
|
|
@@ -57,14 +57,14 @@ 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();us();let m=(0,Y.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,Y.useMemo)(()=>e.role===`assistant`&&!t?VC(e.content):null,[e.content,e.role,t]),v=(0,Y.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,Y.useState)(!1),[S,C]=(0,Y.useState)(!1),w=e.role===`user`&&gy(e.content),[E,O]=(0,Y.useState)(!1),k=(0,Y.useId)(),A=(0,Y.useRef)(null),j=(0,Y.useRef)(!1),M=(0,Y.useCallback)(()=>{E&&(j.current=!0),O(!E)},[E]);(0,Y.useEffect)(()=>{!E&&j.current&&(j.current=!1,A.current?.scrollIntoView?.({block:`nearest`}))},[E]);let N=(0,Y.useRef)(null),F=(0,Y.useRef)(null);(0,Y.useEffect)(()=>()=>{N.current&&clearTimeout(N.current),F.current&&clearTimeout(F.current)},[]);let I=(0,Y.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,Y.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,Y.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(Ia,{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?hr:Vr,{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(uo,{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(q,{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(oo,{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(Ba,{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:fs(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,Y.createContext)(!1);function GC({lang:e,code:t}){let n=T(),[r,i]=(0,Y.useState)(!1),[a,o]=(0,Y.useState)(!1),s=(0,Y.useContext)(WC),c=(0,Y.useId)(),l=hy(t),u=l>(s?20:25),d=u&&!a,f=(0,Y.useRef)(null);(0,Y.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]);let p=(0,Y.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?hr:Vr,{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(),On(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(xi,{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,Y.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(_i,{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(Y.Fragment,{children:QC(e.slice(l,t.start))},`t${l}`)),c.push(t.node),l=t.end;return l<e.length&&c.push(P(Y.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,Y.useContext)($C),n=T(),r=Y.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(Y.Fragment,{children:r},`s${a}`)}if(i=null,Y.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,Y.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=Y.Children.toArray(e)[0];if(Y.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,Y.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,libraryNotices:e.libraryNotices||e.library_notices||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,Y.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(hr,{size:14,"aria-hidden":`true`}):e===2?P(fa,{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}function Rw(e,t){let n=e.tool||``,r=e.tool_label||n,{addNotification:i,notifications:a}=$s.getState(),o=e.confirm_id?a.find(t=>t.id===e.confirm_id):void 0;if(o){!o.response&&o.dismissed&&$s.setState(e=>({notifications:e.notifications.map(e=>e.id===o.id?{...e,dismissed:!1}:e)}));return}let s=n===Us,c=s&&Xs(a,t,e.args);i({id:e.confirm_id??`perm-${Date.now()}`,type:`permission_request`,agentId:t,sessionId:t,agentName:`GAIA`,title:s?Ks(e.args,c):n===`trust_project_folder`?`Trust this folder's instructions and skills?`:`Allow ${r}?`,message:s?Gs(e.args,c):n===`trust_project_folder`?`GAIA would put this folder's CLAUDE.md, AGENTS.md and skills in the model's prompt, now and every time you work in it.`:`GAIA needs your OK before ${r}.`,timestamp:Date.now(),read:!1,dismissed:!1,priority:`high`,tool:n,toolArgs:e.args,confirmId:e.confirm_id,alwaysScope:typeof e.always_scope==`string`?e.always_scope:void 0,alwaysLabel:typeof e.always_label==`string`&&e.always_label?e.always_label:void 0,toolLabel:e.tool_label||void 0,risk:typeof e.risk==`string`?e.risk:void 0,summary:typeof e.summary==`string`&&e.summary?e.summary:void 0,pathFollowUp:c||void 0,timeoutSeconds:e.timeout_seconds})}function zw(e,t,n){let r=e.tool||`unknown tool`,i=e.reason||e.message||e.content||`Tool execution was blocked by governance policy.`;return{id:e.receipt_id??n,type:`policy_alert`,agentId:t,agentName:`GAIA`,title:`Blocked: ${r} is restricted by policy.`,message:i,timestamp:Date.now(),read:!1,dismissed:!1,priority:`critical`,tool:r,decision:e.decision||`BLOCK`,reason:i,ruleIds:e.rule_ids??[],policyVersion:e.policy_version,receiptId:e.receipt_id}}function Bw(e){let t={result:e.summary||e.title||`Done`,active:!1,success:e.success!==!1,latencyMs:e.latency_ms};return e.command_output&&(t.commandOutput={command:e.command_output.command,stdout:e.command_output.stdout,stderr:e.command_output.stderr,returnCode:e.command_output.return_code,expectedExit:e.command_output.expected_exit,cwd:e.command_output.cwd,durationSeconds:e.command_output.duration_seconds,truncated:e.command_output.truncated}),e.mcp_output?.text&&(t.mcpOutput=e.mcp_output),e.result_data?.chunks&&e.result_data.chunks.length>0&&(t.retrievalChunks=e.result_data.chunks.map(e=>({id:e.id,source:e.source,sourcePath:e.sourcePath,page:e.page,score:e.score,preview:e.preview,content:e.content}))),e.result_data?.type===`file_list`&&e.result_data.files?.length>0&&(t.fileList={files:e.result_data.files,total:e.result_data.total??e.result_data.files.length}),t}var Vw=5e3,Hw=2e3,Uw=3e4,Ww=6e4;function Gw(e){return e?.init_state===`initializing`?!e.init_tasks||e.init_tasks.some(e=>e.status===`pending`||e.status===`running`):!1}function Kw(e){return e.lemonade_running?`up`:e.lemonade_error?`unresponsive`:`down`}function qw(e){return e.kind===`slow`||e.kind===`error`||e.kind===`ok`&&Kw(e.status)===`unresponsive`}function Jw(e){let t=e.kind===`ok`?e.status.download_progress?.state:void 0;return t===`downloading`||t===`starting`}function Yw(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(),Ww);try{return{kind:`ok`,status:await Pt(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=qw(t)?n+1:0,r=Jw(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?Hw:Vw)*2**n,Uw),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 Xw=1e3,Zw=15e3,Qw=null,$w=null,eT=Xw,tT=0,nT=null;function rT(){if(Qw)return Qw;let e=Date.now();return Qw=xn().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(()=>{Qw=null}),Qw}function iT(){let e=k.getState();return e.isStreaming||e.runningSessionIds.length>0}function aT(){return iT()?(eT=Xw,Xw):(eT=Math.min(eT*2,Zw),eT)}function oT(e){rT().then(()=>{e===tT&&($w=setTimeout(()=>oT(e),aT()))})}function sT(){nT&&($w&&clearTimeout($w),$w=null,eT=Xw,oT(++tT))}function cT(){nT?.();let e=k.subscribe((e,t)=>{e.isStreaming&&!t.isStreaming&&sT()}),t=()=>sT();window.addEventListener(`focus`,t);let n=()=>{tT++,$w&&clearTimeout($w),$w=null,e(),window.removeEventListener(`focus`,t),nT===n&&(nT=null)};return nT=n,eT=Xw,oT(++tT),n}var lT=3e3,uT=new Set,dT=new Map,fT=new Set,pT=null;function mT(e,t=Date.now()){dT.set(e,t)}function hT(e){let t=k.getState();return t.activeRunsAt>0&&t.activeRunsAt>=(dT.get(e)??0)&&!t.runningSessionIds.includes(e)&&!t.queuedSessionIds.includes(e)}function gT(e){return fT.add(e),()=>{fT.delete(e),pT?.()}}function _T(e){return e instanceof Error?KS(e)??(e.message||`Unknown error`):String(e)}function vT(e){let t=e?.httpStatus;return typeof t==`number`?t:void 0}function yT(e){let t=vT(e);return t===409||t===429}function bT(e){d.chat.warn(`Chat ${e} no longer exists; dropping its queued messages`),k.getState().updateQueue(e,()=>[])}function xT(e){k.getState().setQueueHold(e,!0),setTimeout(()=>k.getState().setQueueHold(e,!1),lT)}function ST(e,t,n){return vT(n)===409&&(d.chat.info(`Chat ${e} was busy; queueing the message to try again`),k.getState().updateQueue(e,e=>ee(e,t,`queued`)),xT(e),!0)}async function CT(e,t,n){let r=k.getState;if(uT.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)){uT.add(e);try{if(a){let t;try{t=await Ht(e)}catch(t){if(vT(t)===409){d.chat.info(`Chat ${e} is answering again; its queue waits for that turn to end`);return}if(vT(t)===404){bT(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: ${_T(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:_T(e)}}if(o.kind===`accepted`){mT(e),r().updateQueue(e,e=>ie(e,i.id)),sT();return}if(o.kind===`busy`){d.chat.info(`Queued message found chat ${e} busy; holding it`),r().updateQueue(e,e=>ne(e,i.id)),xT(e);return}if(o.kind===`gone`){bT(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{uT.delete(e)}}}function wT(e){return e.type!==`status`||e.phase!==`waiting`}var TT=(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=>{wT(e)&&s()},onDone:s,onError:e=>{US(e)?s():yT(e)?o({kind:`busy`}):vT(e)===404?o({kind:`gone`}):o({kind:`failed`,error:_T(e)})}}),a&&i.abort()});function ET(e=TT){let t=()=>{let t=k.getState();if(!Gw(t.systemStatus))for(let n of Object.keys(t.messageQueues))!fT.has(n)&&hT(n)&&CT(n,e,()=>!fT.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 pT=t,t(),()=>{n(),pT===t&&(pT=null)}}var DT=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`]),OT=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 kT(e){let t=e.lastIndexOf(`.`);return t<0?``:e.slice(t).toLowerCase()}function AT(e){return DT.has(kT(e))}function jT(e){let t=kT(e);return DT.has(t)||OT.has(t)}var MT=`https://github.com/amd/gaia/issues/new`,NT=[{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:DT,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:OT,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 PT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;for(let e of NT)if(e.extensions.has(t))return e;return null}var FT=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 IT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;return FT.has(t)}function LT(){let e=navigator.userAgent;return`**Environment:**\n- GAIA Version: 0.26.0rc13\n- Platform: ${navigator.platform||`unknown`}\n- User Agent: ${e}\n- Interface: Agent UI (Web)`}function RT(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?_`,``,`---`,LT(),``,`_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,libraryNotices:e.libraryNotices||e.library_notices||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,Y.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(hr,{size:14,"aria-hidden":`true`}):e===2?P(fa,{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}function Rw(e,t){let n=e.tool||``,r=e.tool_label||n,{addNotification:i,notifications:a}=$s.getState(),o=e.confirm_id?a.find(t=>t.id===e.confirm_id):void 0;if(o){!o.response&&o.dismissed&&$s.setState(e=>({notifications:e.notifications.map(e=>e.id===o.id?{...e,dismissed:!1}:e)}));return}let s=n===Us,c=s&&Xs(a,t,e.args);i({id:e.confirm_id??`perm-${Date.now()}`,type:`permission_request`,agentId:t,sessionId:t,agentName:`GAIA`,title:s?Ks(e.args,c):n===`trust_project_folder`?`Trust this folder's instructions and skills?`:`Allow ${r}?`,message:s?Gs(e.args,c):n===`trust_project_folder`?`GAIA would put this folder's CLAUDE.md, AGENTS.md and skills in the model's prompt, now and every time you work in it.`:`GAIA needs your OK before ${r}.`,timestamp:Date.now(),read:!1,dismissed:!1,priority:`high`,tool:n,toolArgs:e.args,confirmId:e.confirm_id,alwaysScope:typeof e.always_scope==`string`?e.always_scope:void 0,alwaysLabel:typeof e.always_label==`string`&&e.always_label?e.always_label:void 0,toolLabel:e.tool_label||void 0,risk:typeof e.risk==`string`?e.risk:void 0,summary:typeof e.summary==`string`&&e.summary?e.summary:void 0,pathFollowUp:c||void 0,timeoutSeconds:e.timeout_seconds})}function zw(e,t,n){let r=e.tool||`unknown tool`,i=e.reason||e.message||e.content||`Tool execution was blocked by governance policy.`;return{id:e.receipt_id??n,type:`policy_alert`,agentId:t,agentName:`GAIA`,title:`Blocked: ${r} is restricted by policy.`,message:i,timestamp:Date.now(),read:!1,dismissed:!1,priority:`critical`,tool:r,decision:e.decision||`BLOCK`,reason:i,ruleIds:e.rule_ids??[],policyVersion:e.policy_version,receiptId:e.receipt_id}}function Bw(e){let t={result:e.summary||e.title||`Done`,active:!1,success:e.success!==!1,latencyMs:e.latency_ms};return e.command_output&&(t.commandOutput={command:e.command_output.command,stdout:e.command_output.stdout,stderr:e.command_output.stderr,returnCode:e.command_output.return_code,expectedExit:e.command_output.expected_exit,cwd:e.command_output.cwd,durationSeconds:e.command_output.duration_seconds,truncated:e.command_output.truncated}),e.mcp_output?.text&&(t.mcpOutput=e.mcp_output),e.result_data?.chunks&&e.result_data.chunks.length>0&&(t.retrievalChunks=e.result_data.chunks.map(e=>({id:e.id,source:e.source,sourcePath:e.sourcePath,page:e.page,score:e.score,preview:e.preview,content:e.content}))),e.result_data?.type===`file_list`&&e.result_data.files?.length>0&&(t.fileList={files:e.result_data.files,total:e.result_data.total??e.result_data.files.length}),t}var Vw=5e3,Hw=2e3,Uw=3e4,Ww=6e4;function Gw(e){return e?.init_state===`initializing`?!e.init_tasks||e.init_tasks.some(e=>e.status===`pending`||e.status===`running`):!1}function Kw(e){return e.lemonade_running?`up`:e.lemonade_error?`unresponsive`:`down`}function qw(e){return e.kind===`slow`||e.kind===`error`||e.kind===`ok`&&Kw(e.status)===`unresponsive`}function Jw(e){let t=e.kind===`ok`?e.status.download_progress?.state:void 0;return t===`downloading`||t===`starting`}function Yw(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(),Ww);try{return{kind:`ok`,status:await Pt(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=qw(t)?n+1:0,r=Jw(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?Hw:Vw)*2**n,Uw),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 Xw=1e3,Zw=15e3,Qw=null,$w=null,eT=Xw,tT=0,nT=null;function rT(){if(Qw)return Qw;let e=Date.now();return Qw=xn().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(()=>{Qw=null}),Qw}function iT(){let e=k.getState();return e.isStreaming||e.runningSessionIds.length>0}function aT(){return iT()?(eT=Xw,Xw):(eT=Math.min(eT*2,Zw),eT)}function oT(e){rT().then(()=>{e===tT&&($w=setTimeout(()=>oT(e),aT()))})}function sT(){nT&&($w&&clearTimeout($w),$w=null,eT=Xw,oT(++tT))}function cT(){nT?.();let e=k.subscribe((e,t)=>{e.isStreaming&&!t.isStreaming&&sT()}),t=()=>sT();window.addEventListener(`focus`,t);let n=()=>{tT++,$w&&clearTimeout($w),$w=null,e(),window.removeEventListener(`focus`,t),nT===n&&(nT=null)};return nT=n,eT=Xw,oT(++tT),n}var lT=3e3,uT=new Set,dT=new Map,fT=new Set,pT=null;function mT(e,t=Date.now()){dT.set(e,t)}function hT(e){let t=k.getState();return t.activeRunsAt>0&&t.activeRunsAt>=(dT.get(e)??0)&&!t.runningSessionIds.includes(e)&&!t.queuedSessionIds.includes(e)}function gT(e){return fT.add(e),()=>{fT.delete(e),pT?.()}}function _T(e){return e instanceof Error?KS(e)??(e.message||`Unknown error`):String(e)}function vT(e){let t=e?.httpStatus;return typeof t==`number`?t:void 0}function yT(e){let t=vT(e);return t===409||t===429}function bT(e){d.chat.warn(`Chat ${e} no longer exists; dropping its queued messages`),k.getState().updateQueue(e,()=>[])}function xT(e){k.getState().setQueueHold(e,!0),setTimeout(()=>k.getState().setQueueHold(e,!1),lT)}function ST(e,t,n){return vT(n)===409&&(d.chat.info(`Chat ${e} was busy; queueing the message to try again`),k.getState().updateQueue(e,e=>ee(e,t,`queued`)),xT(e),!0)}async function CT(e,t,n){let r=k.getState;if(uT.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)){uT.add(e);try{if(a){let t;try{t=await Ht(e)}catch(t){if(vT(t)===409){d.chat.info(`Chat ${e} is answering again; its queue waits for that turn to end`);return}if(vT(t)===404){bT(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: ${_T(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:_T(e)}}if(o.kind===`accepted`){mT(e),r().updateQueue(e,e=>ie(e,i.id)),sT();return}if(o.kind===`busy`){d.chat.info(`Queued message found chat ${e} busy; holding it`),r().updateQueue(e,e=>ne(e,i.id)),xT(e);return}if(o.kind===`gone`){bT(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{uT.delete(e)}}}function wT(e){return e.type!==`status`||e.phase!==`waiting`}var TT=(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=>{wT(e)&&s()},onDone:s,onError:e=>{US(e)?s():yT(e)?o({kind:`busy`}):vT(e)===404?o({kind:`gone`}):o({kind:`failed`,error:_T(e)})}}),a&&i.abort()});function ET(e=TT){let t=()=>{let t=k.getState();if(!Gw(t.systemStatus))for(let n of Object.keys(t.messageQueues))!fT.has(n)&&hT(n)&&CT(n,e,()=>!fT.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 pT=t,t(),()=>{n(),pT===t&&(pT=null)}}var DT=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`]),OT=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 kT(e){let t=e.lastIndexOf(`.`);return t<0?``:e.slice(t).toLowerCase()}function AT(e){return DT.has(kT(e))}function jT(e){let t=kT(e);return DT.has(t)||OT.has(t)}var MT=`https://github.com/amd/gaia/issues/new`,NT=[{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:DT,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:OT,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 PT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;for(let e of NT)if(e.extensions.has(t))return e;return null}var FT=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 IT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;return FT.has(t)}function LT(){let e=navigator.userAgent;return`**Environment:**\n- GAIA Version: 0.26.0rc15\n- Platform: ${navigator.platform||`unknown`}\n- User Agent: ${e}\n- Interface: Agent UI (Web)`}function RT(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?_`,``,`---`,LT(),``,`_Submitted from GAIA Agent UI_`].join(`
|
|
61
61
|
`);return`${MT}?${new URLSearchParams({title:`[Feature] ${e}`,body:n,labels:`enhancement,agent-ui`}).toString()}`}function zT(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?_`,``,`---`,LT(),``,`_Submitted from GAIA Agent UI_`].join(`
|
|
62
|
-
`);return`${MT}?${new URLSearchParams({title:`[Bug] ${e}`,body:n,labels:`bug,agent-ui`}).toString()}`}var BT={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 VT(e,t){return e.startsWith(t)?e.slice(t.length).trim():e}function HT({filename:e,error:t,status:n,kind:r,onDismiss:i,timeout:a=15e3}){let o=(0,Y.useRef)(null);(0,Y.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?PT(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=Tr,h=r?BT[r]:void 0;return h?(d=`"${e}" can't be read`,f=h,p=null,m=q):n===404?(d=`"${e}" doesn't exist`,f=VT(t,`File not found:`),p=null,m=q):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=q):l&&c?(d=`${c.label} files not supported`,f=c.message,p=RT(c.featureTitle),m=q):l&&!s?(d=`"${e}" has no file extension`,f=VT(t,`File type not allowed:`),p=null,m=q):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=RT(`Support ${s} file indexing`),m=q):u?(d=`Connection error`,f=`Could not reach the GAIA server. Make sure the backend is running.`,p=zT(`Upload connection error for ${e}`),m=Tr):(d=`Failed to index "${e}"`,f=t||`An unexpected error occurred during indexing.`,p=zT(`Indexing error: ${t.slice(0,80)}`),m=sr),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(J,{size:14})})]})}function UT(e,t){let n=e=>t.some(t=>t.id===e&&!(`error`in t)&&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 WT(e,t){let n=e=>t.some(t=>t.id===e&&!(`error`in t)&&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 GT=4e3;function KT({content:e,onRetry:t}){let[n,r]=(0,Y.useState)([]),[i,a]=(0,Y.useState)(!1),o=(0,Y.useCallback)(()=>{he().then(e=>r(e.connectors||[])).catch(e=>d.ui.warn(`ConnectorRetryBanner: connector fetch failed`,e))},[]),s=UT(e,n);if((0,Y.useEffect)(()=>{o();let e=()=>o();return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[o]),(0,Y.useEffect)(()=>{if(s)return;let e=setInterval(o,GT);return()=>clearInterval(e)},[s,o]),!s||i)return null;let c=WT(e,n);return V(`div`,{className:`connector-retry-banner`,role:`status`,children:[P(kr,{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(Ia,{size:12}),P(`span`,{children:`Ask again`})]}),P(`button`,{type:`button`,className:`connector-retry-banner__dismiss`,onClick:()=>a(!0),"aria-label":`Dismiss`,children:`×`})]})}function qT(e){return e.isMedia?AT(e.name)?hi:li:_i}var JT=240,YT=1e5;function XT({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,Y.useRef)(null),g=d??h,_=(0,Y.useRef)(null),v=!!s,y=e.trim().length>0||c.hasUploaded,b=c.compose(e.trim()).length,x=b>YT,S=!v&&(!i||o)&&!c.uploading&&y&&!x,C=s||l||m(`composer.placeholder`);(0,Y.useLayoutEffect)(()=>{let e=g.current;if(!e)return;let t=()=>{e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,JT)}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,Y.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),S&&n())},[S,n]),E=(0,Y.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=qT(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(J,{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(Pa,{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(Zn,{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(oo,{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(Zn,{size:16})})]})]})]})}var ZT=8,QT=8;function $T({label:e,warning:t,children:n,id:r,pinned:i=!1,onUnpin:a,tabIndex:o}){let s=(0,Y.useId)(),c=r??s,l=(0,Y.useRef)(null),u=(0,Y.useRef)(null),[d,f]=(0,Y.useState)(!1),p=d||i,[m,h]=(0,Y.useState)(null);return(0,Y.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+ZT+t.width<=r-QT?(a=n.right+ZT,o=e.top+e.height/2-t.height/2):n.left-ZT-t.width>=QT?(a=n.left-ZT-t.width,o=e.top+e.height/2-t.height/2):(a=Math.min(Math.max(QT,e.right-t.width),r-QT-t.width),o=e.top-ZT-t.height>=QT?e.top-ZT-t.height:e.bottom+ZT),o=Math.min(Math.max(QT,o),i-QT-t.height),h({left:a,top:o})},[p]),(0,Y.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(Ui,{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 eE(e){return e<.1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function tE(e,t=z){return e?t(`settings.price.perMillion`,{input:eE(e.input_per_million),output:eE(e.output_per_million)}):t(`settings.price.unknown`)}function nE(e){return`$${e.toFixed(2)}`}var rE=2e3,iE=`waiting_for_os_permission`,aE=5;function oE(e,t){let n=e.rank?`#${e.rank} ${e.note??``}`.trim():null;return t?[n,tE(e.price)].filter(e=>!!e):[Cs(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 sE({m:e,onDownload:t,busy:n}){if(Es(e)){let t=Math.round(e.download_progress?.percent??0);return V(`span`,{className:`model-state is-downloading`,title:`Downloading, ${t}%`,children:[P(K,{size:12,className:`spin`,"aria-hidden":`true`}),` `,t,`%`]})}let r=Ts(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:Ss.not_downloaded,tabIndex:-1,children:P(Yr,{size:13,"aria-hidden":`true`})}):r===`loaded`?P(`span`,{className:`model-state is-loaded`,role:`img`,"aria-label":Ss.loaded,title:Ss.loaded}):P(`span`,{className:`model-state is-ready`,title:Ss.downloaded,children:`Ready`})}function cE(){let e=T(),t=ls(e=>e.active),n=ls(e=>e.select),r=ls(e=>e.queued),i=ls(e=>e.queue),a=ls(e=>e.queueError),o=ls(e=>e.rememberNames);ls(e=>e.names);let s=gs(),c=k(e=>_s(t,e.sessions,e.currentSessionId)),l=k(e=>e.isStreaming),u=k(e=>e.openSettings),d=(0,Y.useRef)(null),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(null),[g,_]=(0,Y.useState)(0),[v,y]=(0,Y.useState)(null),[b,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(null),[w,E]=(0,Y.useState)(null),[D,O]=(0,Y.useState)(null),[A,j]=(0,Y.useState)(0),[M,N]=(0,Y.useState)(null),F=(0,Y.useRef)(0),I=(0,Y.useRef)(null),L=(0,Y.useId)(),ee=(0,Y.useRef)(null),R=(0,Y.useRef)(null),[z,B]=(0,Y.useState)(null),[te,ne]=(0,Y.useState)(null),re=(0,Y.useCallback)(()=>ne(null),[]),ie=(0,Y.useCallback)(()=>p(!1),[]),ae=(0,Y.useRef)(!1),oe=(0,Y.useCallback)(async(t=!1)=>{t||(ae.current=!1,y(null),h(null));try{let{providers:n,lemonade_error:r}=await En();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 Qt(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,Y.useEffect)(()=>{f&&(x(null),B(null),ne(null),oe())},[f,oe]),(0,Y.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,Y.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(Es)),W=!!m?.some(e=>e.provider.key_state===iE);(0,Y.useEffect)(()=>{if(!(f||D)||!(U||D||W))return;let e=setInterval(()=>{oe(!0)},rE);return()=>clearInterval(e)},[f,U,D,W,oe]);let G=(0,Y.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]),se=(0,Y.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,Y.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>=aE),r=m.flatMap(e=>e.models).find(t=>t.id===e);if(!r){if(!n())return;O(null),N(`${fs(e)} is no longer in the model list, so it wasn't switched to.`);return}if(Es(r)){F.current=0;return}let i=r.download_progress;if(i?.state===`error`)O(null),N(`Downloading ${fs(e)} failed: ${i.message??`no reason given`}`);else if(i?.state!==`complete`&&Ts(r)===`not_downloaded`){if(!n())return;O(null),N(`The download of ${fs(e)} never started. Try the download button again.`)}else O(null),se(e,t).then(t=>{t&&N(`${fs(e)} downloaded, but switching to it failed: ${t}`)})},[m,D,A,se]);let ce=m?.flatMap(({provider:e,models:t})=>[...e.remote&&!e.models_discovered?[`key:${e.id}`]:[],...t.filter(e=>S===null&&!Es(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?Lr:s?Gr:jr,me=c?fs(c):`Model`,he=`${me}${s?` · ${s.label}`:``}`,ge=Object.fromEntries((m??[]).map(e=>[e.provider.id,bs(e.models)])),_e=t?.downloaded===!1&&c===t.model,ve=M||a||(r?`${fs(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`):hs);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:[`→ `,fs(r),` next`]}),_e&&P(Yr,{size:12,"aria-label":`Not downloaded`}),M&&P(Tr,{size:12,"aria-label":`Model switch failed`}),P(_r,{size:12,"aria-hidden":`true`})]}),V(zo,{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?fs(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(K,{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===iE?V(`div`,{className:`popover-message`,role:`status`,children:[P(K,{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(Gi,{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=ds(r??t?.model,n.id),a=!e.remote&&Ts(n)===`not_downloaded`,o=ge[e.id][n.id],s=oE(n,e.remote),c=`${L}-info-${e.id}-${n.id}`;return V(Y.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}),G(n.id)):(O(null),se(n.id,e))},disabled:S!==null||Es(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(K,{size:13,className:`spin`}):i?P(hr,{size:13}):null}),P(`span`,{className:`popover-item-body`,children:P(`span`,{className:`popover-item-title`,children:o})})]}),V($T,{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(sE,{m:n,busy:w!==null,onDownload:()=>void G(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:()=>se(b.model,b.provider),children:[`Use `,fs(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($i,{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 lE(e,t,n){if(e==null||!t(e))throw Error(`the server sent no ${n}`);return e}var uE=e=>e.startsWith(`.`);function dE({onPick:e,onClose:t}){let n=T(),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1);Lo(!0,t);let p=(0,Y.useRef)(null);sS(p,!0);let m=(0,Y.useCallback)(e=>{u(!0),c(null),Promise.resolve().then(()=>kt(e)).then(e=>{let t=lE(e,e=>Array.isArray(e.entries),`folder listing`);i(t),o(t.current_path)}).catch(e=>c(e instanceof bn?e.detail||e.message:String(e))).finally(()=>u(!1))},[]);(0,Y.useEffect)(()=>m(),[m]);let h=r?.entries.filter(e=>e.type===`folder`)??[],g=d?h:h.filter(e=>!uE(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(J,{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(Zn,{size:13,"aria-hidden":`true`}),` `,n(`pick.up`)]})}),g.map(e=>P(`li`,{children:V(`button`,{type:`button`,onClick:()=>m(e.path),children:[P(Di,{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(K,{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 fE(e){let[t,n]=(0,Y.useState)(!1),[r,i]=(0,Y.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(dE,{onPick:t=>{n(!1),e(t)},onClose:()=>n(!1)}):null,error:r}}var pE=new Map;function mE(e){let t=pE.get(e);return t||(t={env:null,error:null,inFlight:null,version:0,listeners:new Set},pE.set(e,t)),t}function hE(e,t,n){let r=mE(e);r.env=t??r.env,r.error=n,r.listeners.forEach(e=>e())}function gE(e){let t=mE(e);if(t.inFlight)return t.inFlight;let n=t.version;return t.inFlight=Promise.resolve().then(()=>Ne(e)).then(r=>{let i=lE(r,e=>Array.isArray(e.folders),`chat's environment`);t.version===n&&hE(e,i,null)}).catch(t=>hE(e,null,t instanceof Error?t.message:String(t))).finally(()=>{t.inFlight=null}),t.inFlight}function _E(e){let[,t]=(0,Y.useState)(0);(0,Y.useEffect)(()=>{let n=mE(e),r=()=>t(e=>e+1);return n.listeners.add(r),!n.env&&!n.inFlight&&gE(e),()=>{n.listeners.delete(r)}},[e]);let n=(0,Y.useCallback)(()=>gE(e),[e]),r=(0,Y.useCallback)(async t=>{let n=await t();return mE(e).version+=1,hE(e,n,null),n},[e]),i=mE(e);return{env:i.env,error:i.error,refresh:n,change:r}}var vE=e=>e.split(/[\\/]/).filter(Boolean).pop()??e;function yE({folder:e,disabled:t}){let n=k(e=>e.draftFolder),r=k(e=>e.setDraftFolder),{open:i,picker:a,error:o}=fE(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 ${vE(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(Di,{size:13,"aria-hidden":`true`}),P(`span`,{className:`new-chat-folder-name`,dir:`auto`,children:n?`${e.name} + ${vE(n)}`:e.name}),P(_r,{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 ${vE(n)}`,title:`Don't add this folder`,children:P(J,{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(Di,{size:13,"aria-hidden":`true`}),P(`span`,{className:`new-chat-folder-name`,dir:`auto`,children:e.name})]})}function bE({sessionId:e,onOpen:t}){let{env:n}=_E(e),r=n?.folders.find(e=>e.source===`working_folder`);if(!r)return null;let i=vE(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(Di,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:i})]})}var xE=`gaia:permission-mode`;function SE(e,t){window.dispatchEvent(new CustomEvent(xE,{detail:{sessionId:e,mode:t}}))}function CE(e,t){let n=(0,Y.useRef)(t);n.current=t,(0,Y.useEffect)(()=>{if(!e)return;let t=t=>{let r=t.detail;r?.sessionId===e&&n.current(r.mode)};return window.addEventListener(xE,t),()=>window.removeEventListener(xE,t)},[e])}var wE=[{mode:`ask`,label:`perm.ask`,note:`perm.askNote`},{mode:`full_access`,label:`perm.full`,note:`perm.fullNote`}];function TE({sessionId:e,disabled:t}){let n=T(),r=k(e=>e.draftPermissionMode),i=k(e=>e.setDraftPermissionMode),[a,o]=(0,Y.useState)(e?`ask`:r),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(null),p=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{if(!e){o(r);return}let t=!1;return Ct(e).then(e=>{t||o(e.mode)}).catch(e=>{t||f(Ix(e))}),()=>{t=!0}},[e,r]),CE(e,o);let m=(0,Y.useCallback)(async t=>{if(t===`full_access`&&!l)u(!0);else{f(null);try{if(e){let n=(await Ft(e,t)).mode;o(n),SE(e,n)}else i(t),o(t);c(!1)}catch(t){f(Ix(t)),e&&Ct(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?Ka:Ja;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(_r,{size:12,"aria-hidden":`true`})]}),V(zo,{open:s,onClose:()=>c(!1),anchor:p,label:n(`env.permission`),children:[wE.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(hr,{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 EE={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 DE(e,t){return e?EE.queued:t?`GAIA is still busy in this chat. Trying again in a few seconds.`:`Sending next.`}function OE({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(Tr,{size:12,"aria-hidden":`true`}):e.state===`queued`?P(Fr,{size:12,"aria-hidden":`true`}):P(Ur,{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||DE(i,a):EE[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(Ba,{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(J,{size:12})})]},e.id))})}var kE=e=>e.toLocaleString(`en-US`);function AE({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:kE(e)}),dir:`ltr`,children:n})}function jE({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 ME({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 NE=(e,t)=>t>0?Math.round(e/t*100):0,PE=(e,t)=>{let n=NE(e,t);return n===0&&e>0?`<1`:String(n)},FE=(e,t)=>t&&e!=null?Math.floor(e/t*100):null,IE=256;function LE(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:xs(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 RE({label:e,children:t,hint:n}){return V(`div`,{className:`cp-row`,title:n,children:[P(`dt`,{children:e}),P(`dd`,{children:t})]})}function zE({t:e}){let t=T();if(e.model_seconds==null||e.gaia_seconds==null)return V(RE,{label:t(`ctx.took`),children:[P(jE,{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(RE,{label:t(`ctx.took`),hint:t(`ctx.tookHint`),children:P(jE,{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:`${NE(t.s,e.wall_seconds)}%`}},t.key))}),V(`dl`,{className:`cp-rows cp-indent`,children:[P(RE,{label:t(`ctx.inModel`),children:P(jE,{s:e.model_seconds})}),P(RE,{label:t(`ctx.inGaia`),hint:t(`ctx.inGaiaHint`),children:P(jE,{s:e.gaia_seconds})}),n.slice(1).filter(e=>e.s>0).map(e=>V(RE,{label:`· ${e.label}`,children:[P(`span`,{className:`swatch cp-time-${e.key}`,"aria-hidden":`true`}),` `,P(jE,{s:e.s})]},e.key))]})]})}function BE({why:e}){let t=T();return P(`span`,{className:`cp-unknown`,title:e,children:t(`ctx.unknown`)})}var VE={server:`ctx.src.server`,client:`ctx.src.client`};function HE(e,t){return e?t(VE[e]):void 0}function UE({turn:e}){let t=T(),n=FE(e.tokens_cached,e.tokens_in),r=e.unknown??{},i=e.tools.map(e=>`${e.name??t(`ctx.toolOutside`)}: ${e.seconds??`?`} s`).join(`
|
|
62
|
+
`);return`${MT}?${new URLSearchParams({title:`[Bug] ${e}`,body:n,labels:`bug,agent-ui`}).toString()}`}var BT={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 VT(e,t){return e.startsWith(t)?e.slice(t.length).trim():e}function HT({filename:e,error:t,status:n,kind:r,onDismiss:i,timeout:a=15e3}){let o=(0,Y.useRef)(null);(0,Y.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?PT(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=Tr,h=r?BT[r]:void 0;return h?(d=`"${e}" can't be read`,f=h,p=null,m=q):n===404?(d=`"${e}" doesn't exist`,f=VT(t,`File not found:`),p=null,m=q):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=q):l&&c?(d=`${c.label} files not supported`,f=c.message,p=RT(c.featureTitle),m=q):l&&!s?(d=`"${e}" has no file extension`,f=VT(t,`File type not allowed:`),p=null,m=q):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=RT(`Support ${s} file indexing`),m=q):u?(d=`Connection error`,f=`Could not reach the GAIA server. Make sure the backend is running.`,p=zT(`Upload connection error for ${e}`),m=Tr):(d=`Failed to index "${e}"`,f=t||`An unexpected error occurred during indexing.`,p=zT(`Indexing error: ${t.slice(0,80)}`),m=sr),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(J,{size:14})})]})}function UT(e,t){let n=e=>t.some(t=>t.id===e&&!(`error`in t)&&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 WT(e,t){let n=e=>t.some(t=>t.id===e&&!(`error`in t)&&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 GT=4e3;function KT({content:e,onRetry:t}){let[n,r]=(0,Y.useState)([]),[i,a]=(0,Y.useState)(!1),o=(0,Y.useCallback)(()=>{he().then(e=>r(e.connectors||[])).catch(e=>d.ui.warn(`ConnectorRetryBanner: connector fetch failed`,e))},[]),s=UT(e,n);if((0,Y.useEffect)(()=>{o();let e=()=>o();return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[o]),(0,Y.useEffect)(()=>{if(s)return;let e=setInterval(o,GT);return()=>clearInterval(e)},[s,o]),!s||i)return null;let c=WT(e,n);return V(`div`,{className:`connector-retry-banner`,role:`status`,children:[P(kr,{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(Ia,{size:12}),P(`span`,{children:`Ask again`})]}),P(`button`,{type:`button`,className:`connector-retry-banner__dismiss`,onClick:()=>a(!0),"aria-label":`Dismiss`,children:`×`})]})}function qT(e){return e.isMedia?AT(e.name)?hi:li:_i}var JT=240,YT=1e5;function XT({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,Y.useRef)(null),g=d??h,_=(0,Y.useRef)(null),v=!!s,y=e.trim().length>0||c.hasUploaded,b=c.compose(e.trim()).length,x=b>YT,S=!v&&(!i||o)&&!c.uploading&&y&&!x,C=s||l||m(`composer.placeholder`);(0,Y.useLayoutEffect)(()=>{let e=g.current;if(!e)return;let t=()=>{e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,JT)}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,Y.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),S&&n())},[S,n]),E=(0,Y.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=qT(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(J,{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(Pa,{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(Zn,{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(oo,{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(Zn,{size:16})})]})]})]})}var ZT=8,QT=8;function $T({label:e,warning:t,children:n,id:r,pinned:i=!1,onUnpin:a,tabIndex:o}){let s=(0,Y.useId)(),c=r??s,l=(0,Y.useRef)(null),u=(0,Y.useRef)(null),[d,f]=(0,Y.useState)(!1),p=d||i,[m,h]=(0,Y.useState)(null);return(0,Y.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+ZT+t.width<=r-QT?(a=n.right+ZT,o=e.top+e.height/2-t.height/2):n.left-ZT-t.width>=QT?(a=n.left-ZT-t.width,o=e.top+e.height/2-t.height/2):(a=Math.min(Math.max(QT,e.right-t.width),r-QT-t.width),o=e.top-ZT-t.height>=QT?e.top-ZT-t.height:e.bottom+ZT),o=Math.min(Math.max(QT,o),i-QT-t.height),h({left:a,top:o})},[p]),(0,Y.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(Ui,{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 eE(e){return e<.1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function tE(e,t=z){return e?t(`settings.price.perMillion`,{input:eE(e.input_per_million),output:eE(e.output_per_million)}):t(`settings.price.unknown`)}function nE(e){return`$${e.toFixed(2)}`}var rE=2e3,iE=`waiting_for_os_permission`,aE=5;function oE(e,t){let n=e.rank?`#${e.rank} ${e.note??``}`.trim():null;return t?[n,tE(e.price)].filter(e=>!!e):[Cs(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 sE({m:e,onDownload:t,busy:n}){if(Es(e)){let t=Math.round(e.download_progress?.percent??0);return V(`span`,{className:`model-state is-downloading`,title:`Downloading, ${t}%`,children:[P(K,{size:12,className:`spin`,"aria-hidden":`true`}),` `,t,`%`]})}let r=Ts(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:Ss.not_downloaded,tabIndex:-1,children:P(Yr,{size:13,"aria-hidden":`true`})}):r===`loaded`?P(`span`,{className:`model-state is-loaded`,role:`img`,"aria-label":Ss.loaded,title:Ss.loaded}):P(`span`,{className:`model-state is-ready`,title:Ss.downloaded,children:`Ready`})}function cE(){let e=T(),t=ls(e=>e.active),n=ls(e=>e.select),r=ls(e=>e.queued),i=r??t?.model,a=ls(e=>e.queue),o=ls(e=>e.queueError),s=ls(e=>e.rememberNames);ls(e=>e.names);let c=gs(),l=k(e=>_s(t,e.sessions,e.currentSessionId)),u=k(e=>e.isStreaming),d=k(e=>e.openSettings),f=(0,Y.useRef)(null),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(0),[x,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),[E,D]=(0,Y.useState)(null),[O,A]=(0,Y.useState)(null),[j,M]=(0,Y.useState)(null),[N,F]=(0,Y.useState)(0),[I,L]=(0,Y.useState)(null),ee=(0,Y.useRef)(0),R=(0,Y.useRef)(null),z=(0,Y.useId)(),B=(0,Y.useRef)(null),te=(0,Y.useRef)(null),[ne,re]=(0,Y.useState)(null),[ie,ae]=(0,Y.useState)(null),oe=(0,Y.useCallback)(()=>ae(null),[]),H=(0,Y.useCallback)(()=>m(!1),[]),U=(0,Y.useRef)(!1),W=(0,Y.useRef)(null),G=(0,Y.useCallback)(async(t=!1)=>{t||(U.current=!1,S(null),g(null));try{let{providers:n,lemonade_error:r}=await En();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 Qt(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)}}}));s(a.flatMap(e=>e.models)),b(a.flatMap(e=>e.models).filter(e=>e.available===!1).length),t||(U.current=!0),g(a.map(e=>({...e,models:e.models.filter(e=>e.available!==!1)})))}catch(e){S(Ix(e))}},[s,e]);(0,Y.useEffect)(()=>{p&&(w(null),v(!1),re(null),ae(null),G())},[p,G]),(0,Y.useEffect)(()=>{if(!p||!h||!U.current)return;let e=B.current?.querySelector(`[role="option"][tabindex="0"]`);e&&(U.current=!1,e.focus(),e.scrollIntoView?.({block:`nearest`}))},[p,h]),(0,Y.useEffect)(()=>{let e=W.current;if(!p||!h||!e||!_)return;let t=h.find(t=>t.provider.id===e)?.models.find(e=>e.rank===null&&!ds(i,e.id));if(!t)return;let n=Array.from(B.current?.querySelectorAll(`[role="option"]`)??[]).find(e=>e.dataset.row===t.id);n&&(W.current=null,re(t.id),n.focus(),n.scrollIntoView?.({block:`nearest`}))},[p,h,_,i]),(0,Y.useEffect)(()=>{C&&te.current?.scrollIntoView?.({block:`nearest`})},[C]);let se=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return;let t=Array.from(B.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(),ae(t=>e.key===`i`&&t===r?null:r);return}case`ArrowLeft`:e.preventDefault(),ae(null);return;default:return}e.preventDefault(),t[r].focus(),t[r].scrollIntoView?.({block:`nearest`})},ce=!!h?.some(e=>e.models.some(Es)),le=!!h?.some(e=>e.provider.key_state===iE);(0,Y.useEffect)(()=>{if(!(p||j)||!(ce||j||le))return;let e=setInterval(()=>{G(!0)},rE);return()=>clearInterval(e)},[p,ce,j,le,G]);let ue=(0,Y.useCallback)(async e=>{A(e),F(e=>e+1),S(null);try{await fe(e),await G(!0)}catch(t){M(t=>t?.model===e?null:t),S(Ix(t))}finally{A(null),F(e=>e-1)}},[G]),de=(0,Y.useCallback)(async(e,r)=>{if(r.remote&&!t?.remote&&C?.model!==e)return w({model:e,provider:r}),null;if(w(null),u)return a(e===t?.model?null:e),m(!1),null;D(e),S(null);try{return await n(e),L(null),m(!1),null}catch(e){let t=Ix(e);return S(t),t}finally{D(null)}},[t?.model,t?.remote,C,a,n,u]);(0,Y.useEffect)(()=>{if(!j||!h||N>0)return;let{model:e,provider:t}=j,n=()=>(R.current!==h&&(R.current=h,ee.current+=1),ee.current>=aE),r=h.flatMap(e=>e.models).find(t=>t.id===e);if(!r){if(!n())return;M(null),L(`${fs(e)} is no longer in the model list, so it wasn't switched to.`);return}if(Es(r)){ee.current=0;return}let i=r.download_progress;if(i?.state===`error`)M(null),L(`Downloading ${fs(e)} failed: ${i.message??`no reason given`}`);else if(i?.state!==`complete`&&Ts(r)===`not_downloaded`){if(!n())return;M(null),L(`The download of ${fs(e)} never started. Try the download button again.`)}else M(null),de(e,t).then(t=>{t&&L(`${fs(e)} downloaded, but switching to it failed: ${t}`)})},[h,j,N,de]);let pe=(e,t)=>e.id===`fireworks`&&!_&&t.some(e=>e.rank!==null),me=(e,t)=>pe(e,t)?t.filter(e=>e.rank!==null||ds(i,e.id)):t,he=(e,t)=>pe(e,t)&&t.some(e=>e.rank===null&&!ds(i,e.id)),ge=h?.flatMap(({provider:e,models:t})=>[...e.remote&&!e.models_discovered?[`key:${e.id}`]:[],...me(e,t).filter(e=>E===null&&!Es(e)).map(e=>e.id),...he(e,t)?[`showall:${e.id}`]:[]])??[],_e=ne&&ge.includes(ne)?ne:i&&ge.includes(i)?i:ge[0],ve=e=>({role:`option`,tabIndex:e===_e?0:-1,"data-row":e,onFocus:()=>re(e),onBlur:()=>ae(null)}),ye=c?.remote?Lr:c?Gr:jr,be=l?fs(l):`Model`,xe=`${be}${c?` · ${c.label}`:``}`,Se=Object.fromEntries((h??[]).map(e=>[e.provider.id,bs(e.models)])),Ce=t?.downloaded===!1&&l===t.model,we=I||o||(r?`${fs(r)} is used from your next message.`:t?.config_error?t.config_error:Ce?`${be} isn't downloaded yet. Open the list to download it.`:c?c.description?.replace(/`/g,``)??(c.remote?`Runs on ${c.label} — chat history leaves this PC`:`Runs on this PC`):hs);return V(`div`,{className:`composer-chip-wrap`,children:[V(`button`,{ref:f,type:`button`,className:`composer-chip${Ce||o||I?` is-warning`:``}`,onClick:()=>m(e=>!e),"aria-haspopup":`dialog`,"aria-expanded":p,title:we,children:[P(ye,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:xe}),r&&V(`span`,{className:`composer-chip-next`,children:[`→ `,fs(r),` next`]}),Ce&&P(Yr,{size:12,"aria-label":`Not downloaded`}),I&&P(Tr,{size:12,"aria-label":`Model switch failed`}),P(_r,{size:12,"aria-hidden":`true`})]}),V(zo,{open:p,onClose:H,anchor:f,label:`Choose a model`,align:`end`,children:[u&&V(`div`,{className:`popover-message`,role:`status`,children:[`This reply keeps `,l?fs(l):`its model`,`. A model you pick here is used from your next message.`]}),I&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:I}),o&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:o}),x&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:x}),!h&&!x&&V(`div`,{className:`popover-message`,children:[P(K,{size:13,className:`spin`}),` Loading models…`]}),h&&P(`div`,{ref:B,role:`listbox`,"aria-label":`Models`,onKeyDown:se,children:h.map(({provider:n,models:i,error:a})=>V(`div`,{role:`group`,"aria-labelledby":`${z}-${n.id}`,children:[P(`div`,{className:`popover-heading`,id:`${z}-${n.id}`,children:n.name}),a&&P(`div`,{className:`popover-message is-error`,children:a}),n.key_state===iE?V(`div`,{className:`popover-message`,role:`status`,children:[P(K,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n.key_message]}):n.remote&&!n.models_discovered&&V(`button`,{type:`button`,className:`popover-item`,...ve(`key:${n.id}`),"aria-selected":!1,onClick:()=>{m(!1),d(`model`,n.id)},children:[P(`span`,{className:`popover-item-check`,children:P(Gi,{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 `,n.name,` in Settings`]})]})]}),!a&&i.length===0&&n.models_discovered!==!1&&P(`div`,{className:`popover-message`,children:`No models yet.`}),me(n,i).map(e=>{let i=ds(r??t?.model,e.id),a=!n.remote&&Ts(e)===`not_downloaded`,o=Se[n.id][e.id],s=oE(e,n.remote),c=`${z}-info-${n.id}-${e.id}`;return V(Y.Fragment,{children:[V(`div`,{className:`popover-row`,children:[V(`button`,{type:`button`,className:`popover-item`,onClick:()=>{a?(ee.current=0,L(null),M({model:e.id,provider:n}),ue(e.id)):(M(null),de(e.id,n))},disabled:E!==null||Es(e),...ve(e.id),"aria-selected":i,"aria-describedby":ie===e.id?c:void 0,children:[P(`span`,{className:`popover-item-check`,"aria-hidden":`true`,children:E===e.id?P(K,{size:13,className:`spin`}):i?P(hr,{size:13}):null}),P(`span`,{className:`popover-item-body`,children:P(`span`,{className:`popover-item-title is-model`,children:o})})]}),V($T,{label:`About ${o}`,warning:!!e.placement?.warning,id:c,pinned:ie===e.id,onUnpin:oe,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))}),e.placement?.warning&&P(`ul`,{className:`info-bubble-lines`,children:P(`li`,{className:`is-warning`,children:e.placement.warning})}),P(`div`,{className:`info-bubble-id`,children:e.id})]}),P(`span`,{className:`popover-row-state`,children:!n.remote&&P(sE,{m:e,busy:O!==null,onDownload:()=>void ue(e.id)})})]}),C?.model===e.id&&C.provider.id===n.id&&V(`div`,{ref:te,className:`popover-message`,role:`alert`,children:[C.provider.privacy_notice,` `,V(`button`,{type:`button`,className:`link-btn`,onClick:()=>de(C.model,C.provider),children:[`Use `,fs(C.model)]})]})]},e.id)}),he(n,i)&&V(`button`,{type:`button`,className:`popover-item`,...ve(`showall:${n.id}`),"aria-selected":!1,onClick:()=>{W.current=n.id,v(!0)},children:[P(`span`,{className:`popover-item-check`}),P(`span`,{className:`popover-item-body`,children:P(`span`,{className:`popover-item-title`,children:e(`settings.model.showAll`)})})]})]},n.id))}),y>0&&V(`button`,{type:`button`,className:`popover-item`,onClick:()=>{m(!1),d(`model`)},children:[P(`span`,{className:`popover-item-check`}),P(`span`,{className:`popover-item-body`,children:V(`span`,{className:`popover-item-note`,children:[y,` `,y===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:()=>{m(!1),d(`model`)},children:[P(`span`,{className:`popover-item-check`,children:P($i,{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:()=>{m(!1),d(`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 lE(e,t,n){if(e==null||!t(e))throw Error(`the server sent no ${n}`);return e}var uE=e=>e.startsWith(`.`);function dE({onPick:e,onClose:t}){let n=T(),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1);Lo(!0,t);let p=(0,Y.useRef)(null);sS(p,!0);let m=(0,Y.useCallback)(e=>{u(!0),c(null),Promise.resolve().then(()=>kt(e)).then(e=>{let t=lE(e,e=>Array.isArray(e.entries),`folder listing`);i(t),o(t.current_path)}).catch(e=>c(e instanceof bn?e.detail||e.message:String(e))).finally(()=>u(!1))},[]);(0,Y.useEffect)(()=>m(),[m]);let h=r?.entries.filter(e=>e.type===`folder`)??[],g=d?h:h.filter(e=>!uE(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(J,{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(Zn,{size:13,"aria-hidden":`true`}),` `,n(`pick.up`)]})}),g.map(e=>P(`li`,{children:V(`button`,{type:`button`,onClick:()=>m(e.path),children:[P(Di,{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(K,{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 fE(e){let[t,n]=(0,Y.useState)(!1),[r,i]=(0,Y.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(dE,{onPick:t=>{n(!1),e(t)},onClose:()=>n(!1)}):null,error:r}}var pE=new Map;function mE(e){let t=pE.get(e);return t||(t={env:null,error:null,inFlight:null,version:0,listeners:new Set},pE.set(e,t)),t}function hE(e,t,n){let r=mE(e);r.env=t??r.env,r.error=n,r.listeners.forEach(e=>e())}function gE(e){let t=mE(e);if(t.inFlight)return t.inFlight;let n=t.version;return t.inFlight=Promise.resolve().then(()=>Ne(e)).then(r=>{let i=lE(r,e=>Array.isArray(e.folders),`chat's environment`);t.version===n&&hE(e,i,null)}).catch(t=>hE(e,null,t instanceof Error?t.message:String(t))).finally(()=>{t.inFlight=null}),t.inFlight}function _E(e){let[,t]=(0,Y.useState)(0);(0,Y.useEffect)(()=>{let n=mE(e),r=()=>t(e=>e+1);return n.listeners.add(r),!n.env&&!n.inFlight&&gE(e),()=>{n.listeners.delete(r)}},[e]);let n=(0,Y.useCallback)(()=>gE(e),[e]),r=(0,Y.useCallback)(async t=>{let n=await t();return mE(e).version+=1,hE(e,n,null),n},[e]),i=mE(e);return{env:i.env,error:i.error,refresh:n,change:r}}var vE=e=>e.split(/[\\/]/).filter(Boolean).pop()??e;function yE({folder:e,disabled:t}){let n=k(e=>e.draftFolder),r=k(e=>e.setDraftFolder),{open:i,picker:a,error:o}=fE(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 ${vE(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(Di,{size:13,"aria-hidden":`true`}),P(`span`,{className:`new-chat-folder-name`,dir:`auto`,children:n?`${e.name} + ${vE(n)}`:e.name}),P(_r,{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 ${vE(n)}`,title:`Don't add this folder`,children:P(J,{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(Di,{size:13,"aria-hidden":`true`}),P(`span`,{className:`new-chat-folder-name`,dir:`auto`,children:e.name})]})}function bE({sessionId:e,onOpen:t}){let{env:n}=_E(e),r=n?.folders.find(e=>e.source===`working_folder`);if(!r)return null;let i=vE(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(Di,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:i})]})}var xE=`gaia:permission-mode`;function SE(e,t){window.dispatchEvent(new CustomEvent(xE,{detail:{sessionId:e,mode:t}}))}function CE(e,t){let n=(0,Y.useRef)(t);n.current=t,(0,Y.useEffect)(()=>{if(!e)return;let t=t=>{let r=t.detail;r?.sessionId===e&&n.current(r.mode)};return window.addEventListener(xE,t),()=>window.removeEventListener(xE,t)},[e])}var wE=[{mode:`ask`,label:`perm.ask`,note:`perm.askNote`},{mode:`full_access`,label:`perm.full`,note:`perm.fullNote`}];function TE({sessionId:e,disabled:t}){let n=T(),r=k(e=>e.draftPermissionMode),i=k(e=>e.setDraftPermissionMode),[a,o]=(0,Y.useState)(e?`ask`:r),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(null),p=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{if(!e){o(r);return}let t=!1;return Ct(e).then(e=>{t||o(e.mode)}).catch(e=>{t||f(Ix(e))}),()=>{t=!0}},[e,r]),CE(e,o);let m=(0,Y.useCallback)(async t=>{if(t===`full_access`&&!l)u(!0);else{f(null);try{if(e){let n=(await Ft(e,t)).mode;o(n),SE(e,n)}else i(t),o(t);c(!1)}catch(t){f(Ix(t)),e&&Ct(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?Ka:Ja;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(_r,{size:12,"aria-hidden":`true`})]}),V(zo,{open:s,onClose:()=>c(!1),anchor:p,label:n(`env.permission`),children:[wE.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(hr,{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 EE={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 DE(e,t){return e?EE.queued:t?`GAIA is still busy in this chat. Trying again in a few seconds.`:`Sending next.`}function OE({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(Tr,{size:12,"aria-hidden":`true`}):e.state===`queued`?P(Fr,{size:12,"aria-hidden":`true`}):P(Ur,{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||DE(i,a):EE[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(Ba,{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(J,{size:12})})]},e.id))})}var kE=e=>e.toLocaleString(`en-US`);function AE({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:kE(e)}),dir:`ltr`,children:n})}function jE({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 ME({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 NE=(e,t)=>t>0?Math.round(e/t*100):0,PE=(e,t)=>{let n=NE(e,t);return n===0&&e>0?`<1`:String(n)},FE=(e,t)=>t&&e!=null?Math.floor(e/t*100):null,IE=256;function LE(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:xs(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 RE({label:e,children:t,hint:n}){return V(`div`,{className:`cp-row`,title:n,children:[P(`dt`,{children:e}),P(`dd`,{children:t})]})}function zE({t:e}){let t=T();if(e.model_seconds==null||e.gaia_seconds==null)return V(RE,{label:t(`ctx.took`),children:[P(jE,{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(RE,{label:t(`ctx.took`),hint:t(`ctx.tookHint`),children:P(jE,{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:`${NE(t.s,e.wall_seconds)}%`}},t.key))}),V(`dl`,{className:`cp-rows cp-indent`,children:[P(RE,{label:t(`ctx.inModel`),children:P(jE,{s:e.model_seconds})}),P(RE,{label:t(`ctx.inGaia`),hint:t(`ctx.inGaiaHint`),children:P(jE,{s:e.gaia_seconds})}),n.slice(1).filter(e=>e.s>0).map(e=>V(RE,{label:`· ${e.label}`,children:[P(`span`,{className:`swatch cp-time-${e.key}`,"aria-hidden":`true`}),` `,P(jE,{s:e.s})]},e.key))]})]})}function BE({why:e}){let t=T();return P(`span`,{className:`cp-unknown`,title:e,children:t(`ctx.unknown`)})}var VE={server:`ctx.src.server`,client:`ctx.src.client`};function HE(e,t){return e?t(VE[e]):void 0}function UE({turn:e}){let t=T(),n=FE(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(zE,{t:e.time}),V(`dl`,{className:`cp-rows`,children:[P(RE,{label:t(`ctx.firstWord`),hint:HE(e.first_token_source,t),children:e.first_token_seconds==null?P(BE,{why:r.first_token_seconds}):V(D.Fragment,{children:[t.bare(`ctx.in`),` `,P(jE,{s:e.first_token_seconds})]})}),P(RE,{label:t(`ctx.readingPrompt`),hint:t(`ctx.readingHint`),children:e.tokens_new!=null&&e.tokens_new<IE?P(`span`,{title:t(`ctx.tooFewTitle`),children:t(`ctx.onlyNew`,{n:e.tokens_new})}):e.prefill_tokens_per_second==null?P(BE,{why:r.prefill_tokens_per_second}):V(D.Fragment,{children:[P(ME,{r:e.prefill_tokens_per_second}),e.prefill_source===`client`&&P(`span`,{className:`cp-chip`,title:t(`ctx.approxTitle`),children:t(`ctx.approx`)})]})}),P(RE,{label:t(`ctx.writing`),hint:HE(e.generation_source,t)??t(`ctx.writingHint`),children:e.generation_tokens_per_second==null?P(BE,{why:r.generation_tokens_per_second}):P(ME,{r:e.generation_tokens_per_second})}),P(RE,{label:t(`ctx.tokensInOut`),hint:r.tokens,children:V(`span`,{dir:`ltr`,children:[P(AE,{n:e.tokens_in}),` → `,P(AE,{n:e.tokens_out})]})}),P(RE,{label:t(`ctx.cache`),hint:t(`ctx.cacheHint`),children:e.tokens_cached==null?P(BE,{why:r.tokens_cached}):V(D.Fragment,{children:[P(AE,{n:e.tokens_cached}),n!=null&&` (${n}%)`]})}),P(RE,{label:t(`ctx.modelCalls`),children:e.model_calls}),P(RE,{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(jE,{s:e.tool_seconds_total??0})]})}),P(RE,{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(`
|
|
64
64
|
`),children:[e.loads.length,` · `,P(jE,{s:e.loads.reduce((e,t)=>e+t.seconds,0)})]})}),P(RE,{label:t(`rail.cost`),children:P(WE,{cost:e.cost})})]})]})}function WE({cost:e}){let t=T();return e.kind===`local`?P(`span`,{title:t(`ctx.costLocalTitle`),children:t(`ctx.costLocal`)}):e.kind===`unreported`?P(`span`,{className:`cp-unknown`,children:t(`ctx.costUnreported`)}):e.kind===`estimate`&&e.usd!=null?P(`span`,{title:t(`ctx.listPriceTitle`,{usd:e.usd}),children:t(`ctx.about`,{usd:e.usd<.01?e.usd.toFixed(4):e.usd.toFixed(2)})}):P(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)})}function GE({totals:e}){let t=T(),n=FE(e.tokens_cached,e.tokens_in),r=P(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)});return V(`dl`,{className:`cp-rows`,children:[P(RE,{label:t(`ctx.turns`),children:e.turns}),P(RE,{label:t(`ctx.totalTime`),children:P(jE,{s:e.wall_seconds})}),P(RE,{label:t(`ctx.inModel`),children:P(jE,{s:e.model_seconds})}),P(RE,{label:t(`ctx.inGaia`),children:P(jE,{s:e.gaia_seconds})}),P(RE,{label:t(`ctx.tokensInOut`),children:V(`span`,{dir:`ltr`,children:[P(AE,{n:e.tokens_in}),` → `,P(AE,{n:e.tokens_out})]})}),P(RE,{label:t(`ctx.cache`),children:e.tokens_cached==null?r:V(D.Fragment,{children:[P(AE,{n:e.tokens_cached}),n!=null&&` (${n}%)`]})}),P(RE,{label:t(`ctx.toolCalls`),children:e.tool_calls??r}),P(RE,{label:t(`ctx.loads`),children:e.loads===0?t(`ctx.none`):V(D.Fragment,{children:[e.loads,` · `,P(jE,{s:e.load_seconds})]})}),P(RE,{label:t(`rail.cost`),children:e.usd==null?r:e.unpriced_turns>0?P(`span`,{title:t(`ctx.unpricedTitle`,{n:e.unpriced_turns}),children:t(`ctx.unpriced`,{usd:e.usd.toFixed(2),n:e.unpriced_turns})}):e.usd===0?`$0`:t(`ctx.about`,{usd:e.usd.toFixed(2)})})]})}function KE({usage:e}){let t=T(),n=e.context_state?.put_away,r=e.context_state?.summarized;return V(`div`,{className:`cp-full`,children:[V(`dl`,{className:`cp-rows`,children:[P(RE,{label:t(`ctx.live`),children:P(AE,{n:e.used})}),n&&n.results>0&&V(RE,{label:t(`ctx.putAway`),hint:t(`ctx.putAwayHint`),children:[t.plural(`ctx.results`,n.results),` · `,P(AE,{n:n.tokens})]}),r&&r.turns>0&&V(RE,{label:t(`ctx.summarized`),hint:t(`ctx.summarizedHint`),children:[t.plural(`ctx.earlier`,r.turns),` · `,P(AE,{n:r.tokens}),` → `,P(AE,{n:r.summary_tokens})]})]}),r&&r.turns>0&&P(`p`,{className:`cp-note cp-summarized`,children:t(`ctx.summarizedNote`)}),e.at_risk.length>0&&P(`p`,{className:`cp-warning`,role:`status`,children:t(`ctx.filling`)})]})}function qE({sessionId:e,busy:t,onUsage:n}){let r=T(),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),[h,_]=(0,Y.useState)(`turn`),v=(0,Y.useRef)(n);v.current=n;let y=(0,Y.useCallback)(()=>{let t=!1,n=(n,r)=>i=>{t||(d.chat.error(`Could not read the ${n} for session=${e}`,i),r(i instanceof Error?i.message:String(i)))};return hn(e).then(e=>{t||(e.available?(a(e),s(null),v.current?.(e)):(a(null),s(e.reason)),f(null))}).catch(n(`context usage`,f)),nn(e).then(e=>{t||(l(e),m(null))}).catch(n(`performance`,m)),()=>{t=!0}},[e]);(0,Y.useEffect)(()=>y(),[y]);let b=(0,Y.useRef)(t);(0,Y.useEffect)(()=>{let e=b.current&&!t;return b.current=t,e?y():void 0},[t,y]);let x=c?.turns[c.turns.length-1]??null,S=x&&x.message_id===c?.latest_message_id?x:null,C=i?Math.max(0,i.window-i.used):0;return V(D.Fragment,{children:[V(`section`,{"aria-labelledby":`cp-context`,children:[P(`h3`,{id:`cp-context`,children:r(`ctx.context`)}),u&&P(`p`,{className:`cp-error`,role:`alert`,children:u}),!i&&!u&&P(`p`,{className:`cp-note`,children:o??r(`ctx.measuring`)}),i&&V(D.Fragment,{children:[V(`p`,{className:`cp-lead`,children:[P(`strong`,{children:r(`ctx.used`,{pct:NE(i.used,i.window)})}),` · `,P(AE,{n:i.used}),` `,r.bare(`ctx.of`),` `,P(AE,{n:i.window}),` `,r.bare(`ctx.tokensWord`),i.model&&V(D.Fragment,{children:[` · `,P(`span`,{className:`cp-model`,dir:`ltr`,children:i.model})]}),i.model_window!=null&&i.model_window>i.window&&V(`span`,{className:`cp-window-note`,title:r(`ctx.windowTitle`),children:[` `,`· `,r.bare(`ctx.gaiaUses`),` `,P(AE,{n:i.window}),` `,r.bare(`ctx.ofModel`),` `,P(AE,{n:i.model_window})]}),i.tokenizer&&!i.tokenizer.exact&&P(`span`,{className:`cp-chip`,title:i.tokenizer.reason,children:r(`ctx.approx`)})]}),P(`div`,{className:`cp-stack`,"aria-hidden":`true`,children:(i.categories??[]).map(e=>P(`span`,{className:`cp-cat-${e.key}`,style:{width:`${e.tokens/i.window*100}%`}},e.key))}),V(`dl`,{className:`cp-rows`,children:[(i.categories??[]).map(e=>V(`div`,{className:`cp-row`,children:[V(`dt`,{children:[P(`span`,{className:`swatch cp-cat-${e.key}`,"aria-hidden":`true`}),e.label]}),V(`dd`,{children:[P(AE,{n:e.tokens}),` `,V(`span`,{className:`cp-pct`,children:[PE(e.tokens,i.window),`%`]})]})]},e.key)),V(`div`,{className:`cp-row is-quiet`,children:[V(`dt`,{children:[P(`span`,{className:`swatch cp-cat-free`,"aria-hidden":`true`}),r(`ctx.freeRow`)]}),V(`dd`,{children:[P(AE,{n:C}),` `,V(`span`,{className:`cp-pct`,children:[NE(C,i.window),`%`]})]})]}),V(`div`,{className:`cp-row is-quiet cp-indent`,children:[P(`dt`,{children:r(`ctx.reserve`)}),P(`dd`,{children:P(AE,{n:Math.min(C,i.reply_reserve)})})]})]}),V(`p`,{className:`cp-note`,children:[i.tokenizer?.exact?r(`ctx.exactTokenizer`,{model:i.tokenizer.model}):r(`ctx.estimated`,{reason:i.tokenizer?.reason??g(`ctx.sharedTokenizer`)}),S?.last_prompt_tokens!=null&&V(D.Fragment,{children:[` `,r(`ctx.lastRequest`,{n:kE(S.last_prompt_tokens)})]})]}),i.tool_loading&&i.tool_loading.on_demand.length>0&&V(`details`,{className:`cp-details`,children:[P(`summary`,{children:r(`ctx.onDemand`,{n:i.tool_loading.on_demand.length})}),P(`p`,{className:`cp-note`,children:r(`ctx.sentNow`,{n:i.tool_loading.loaded.length})}),P(`ul`,{className:`cp-tools`,children:i.tool_loading.on_demand.map(e=>P(`li`,{children:e},e))})]}),P(KE,{usage:i})]})]}),V(`section`,{"aria-labelledby":`cp-hood`,children:[V(`div`,{className:`cp-section-head`,children:[P(`h3`,{id:`cp-hood`,children:r(`ctx.hood`)}),V(`div`,{className:`cp-toggle`,role:`group`,"aria-label":r(`ctx.show`),children:[P(`button`,{type:`button`,"aria-pressed":h===`turn`,onClick:()=>_(`turn`),children:r(`ctx.lastTurn`)}),P(`button`,{type:`button`,"aria-pressed":h===`chat`,onClick:()=>_(`chat`),children:r(`sp.title`)})]})]}),c&&V(`dl`,{className:`cp-rows`,children:[P(RE,{label:r(`env.runsOn`),hint:c.now.error??void 0,children:LE(c.now,r)}),c.now.provider===`local`&&V(RE,{label:r(`ctx.memory`),hint:r(`ctx.memoryHint`),children:[c.now.weights_gb==null?P(`span`,{className:`cp-unknown`,children:r(`ctx.unknown`)}):V(D.Fragment,{children:[r(`ctx.gbModel`,{gb:c.now.weights_gb.toFixed(1)}),c.now.kv_cache_gb!=null&&` + ${r(`ctx.gbCache`,{gb:c.now.kv_cache_gb.toFixed(1)})}`]}),` · `,c.now.free_gb==null?P(`span`,{className:`cp-unknown`,children:r(`ctx.freeUnknown`)}):r(`env.free`,{gb:c.now.free_gb.toFixed(1)})]})]}),p&&P(`p`,{className:`cp-error`,role:`alert`,children:p}),!c&&!p&&P(`p`,{className:`cp-note`,children:r(`ctx.measuring`)}),c&&h===`turn`&&(S?P(UE,{turn:S}):P(`p`,{className:`cp-note`,children:c.latest_message_id==null?r(`ctx.afterNext`):V(D.Fragment,{children:[r.bare(`ctx.latestAnswer`),` `,P(`span`,{className:`cp-unknown`,children:r(`ctx.unknown`)}),`. `,r.bare(`ctx.notMeasured`)]})})),c&&h===`chat`&&P(GE,{totals:c.totals})]})]})}function JE({sessionId:e,busy:t,onClose:n,onUsage:r}){let i=T(),a=(0,Y.useRef)(null),o=(0,Y.useRef)(n);o.current=n,(0,Y.useEffect)(()=>{a.current?.focus()},[]),Lo(!0,(0,Y.useCallback)(()=>o.current(),[]));let s=(0,Y.useRef)(null);return sS(s,!0),P(`div`,{className:`cp-overlay`,onClick:n,children:V(`aside`,{ref:s,className:`cp-sheet`,role:`dialog`,"aria-modal":`true`,"aria-label":i(`ctx.sheetAria`),onClick:e=>e.stopPropagation(),children:[V(`header`,{className:`cp-header`,children:[P(`h2`,{children:i(`sp.section.context`)}),P(`button`,{ref:a,type:`button`,className:`cp-icon`,onClick:n,"aria-label":i(`sp.closeShort`),children:P(J,{size:16})})]}),P(`div`,{className:`cp-body`,children:P(qE,{sessionId:e,busy:t,onUsage:r})})]})})}function YE(e){return e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(+(e<1e4))}K`:`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`}var XE=[{key:`system`,label:`ctx.meter.part.system`},{key:`tools`,label:`ctx.meter.part.tools`},{key:`documents`,label:`ctx.meter.part.documents`},{key:`history`,label:`ctx.meter.part.history`},{key:`query`,label:`ctx.meter.part.query`}];function ZE({usage:e,unavailable:t,sessionId:n,busy:r=!1,onUsage:i,onDetails:a}){let o=T(),s=(0,Y.useRef)(null),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(!1),f=u&&n?P(JE,{sessionId:n,busy:r,onUsage:i,onClose:()=>d(!1)}):null;if(!e)return t?V(`span`,{className:`context-meter is-empty`,title:t,children:[P(`span`,{className:`context-meter-bar`,"aria-hidden":`true`,children:P(`span`,{style:{width:0}})}),P(`span`,{className:`context-meter-label`,children:o(`ctx.context`)})]}):null;let p=Math.min(100,Math.round(e.used/e.window*100)),m=e.at_risk.length>0,g=Math.max(0,e.window-e.used-e.reply_reserve),_=e.model_window!=null&&e.model_window>e.window?e.model_window:null,v=_?{gaia:YE(e.window),model:YE(_)}:null;return V(`div`,{className:`composer-chip-wrap context-meter-wrap`,children:[V(`button`,{ref:s,type:`button`,className:`context-meter${m?` is-warning`:``}`,onClick:()=>l(e=>!e),"aria-expanded":c,"aria-label":o.compose(t=>{let n=t(`ctx.meter.aria`,{pct:p,used:YE(e.used),window:YE(e.window)});return v?`${n} (${t(`ctx.meter.capNote`,v)})`:n}),title:v?o(`ctx.meter.titleCapped`,v):o(`ctx.meter.title`),children:[P(`span`,{className:`context-meter-bar`,"aria-hidden":`true`,children:P(`span`,{style:{width:`${p}%`}})}),P(`span`,{className:`context-meter-label`,children:V(`bdi`,{dir:`ltr`,children:[p,`%`]})})]}),P(zo,{open:c,onClose:()=>l(!1),anchor:s,label:o(`ctx.meter.window`),align:`end`,children:V(`div`,{className:`context-meter-panel`,children:[V(`div`,{className:`context-meter-head`,children:[P(`strong`,{children:P(`bdi`,{dir:`ltr`,children:YE(e.used)})}),` `,o.bare(`ctx.of`),` `,P(`bdi`,{dir:`ltr`,children:YE(e.window)}),` `,o.bare(`ctx.tokensWord`),v&&V(`span`,{className:`context-meter-cap`,title:o(`ctx.windowTitle`),children:[` · `,o.bare(`ctx.gaiaUses`),` `,P(`bdi`,{dir:`ltr`,children:v.gaia}),` `,o.bare(`ctx.ofModel`),` `,P(`bdi`,{dir:`ltr`,children:v.model})]})]}),P(`div`,{className:`context-meter-stack`,"aria-hidden":`true`,children:XE.map(({key:t})=>P(`span`,{className:`part-${t}`,style:{width:`${e[t]/e.window*100}%`}},t))}),V(`dl`,{className:`context-meter-rows`,children:[XE.filter(({key:t})=>t!==`query`||e.query>0).map(({key:t,label:n})=>V(`div`,{className:`context-meter-row`,children:[V(`dt`,{children:[P(`span`,{className:`swatch part-${t}`,"aria-hidden":`true`}),o(n)]}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:YE(e[t])})})]},t)),V(`div`,{className:`context-meter-row is-quiet`,children:[P(`dt`,{children:o(`ctx.meter.reserve`)}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:YE(e.reply_reserve)})})]}),V(`div`,{className:`context-meter-row is-quiet`,children:[P(`dt`,{children:o(`ctx.freeRow`)}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:YE(g)})})]})]}),P(`p`,{className:`context-meter-note`,children:o.compose(t=>[t(h(`ctx.meter.inView`,e.turns_in_view),{n:e.turns_in_view}),e.turns_hidden>0?t(h(`ctx.meter.hidden`,e.turns_hidden),{n:e.turns_hidden}):``,`. `,t(e.tokenizer?.exact?`ctx.meter.exact`:`ctx.meter.estimates`),` `,t(`ctx.meter.saved`)].join(``))}),n&&P(`button`,{type:`button`,className:`context-meter-details`,onClick:()=>{l(!1),a?a():d(!0)},children:o(`ctx.meter.details`)})]})}),f]})}function QE({usage:e}){let t=T();if(!e||e.at_risk.length===0)return null;let n=e.at_risk.length;return V(`div`,{className:`context-warning`,role:`status`,children:[P(q,{size:13,"aria-hidden":`true`}),V(`span`,{children:[t.plural(`ctx.meter.warning`,n),` `,e.at_risk.map((e,t)=>V(`span`,{children:[t>0&&`, `,P(`q`,{children:e})]},t)),`. `,t(`ctx.meter.warningSaved`)]})]})}function $E(e){return`$${e>0&&e<.01?e.toFixed(4):e.toFixed(2)}`}function eD(e=new Date){let t=new Date(e);return t.setHours(0,0,0,0),t.toISOString()}function tD({sessionId:e,busy:t}){let n=T(),r=ls(e=>e.active),i=k(e=>_s(r,e.sessions,e.currentSessionId)),a=k(e=>e.openSettings),o=(0,Y.useRef)(null),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(null),f=(0,Y.useCallback)(()=>c(!1),[]),p=(0,Y.useCallback)(()=>{let t=!1;return(async()=>{try{let n=await ze(e,eD(),i??null);t||u(n??null)}catch(n){t||d.chat.error(`Could not read cloud spending for session=${e}`,n)}})(),()=>{t=!0}},[e,i]);(0,Y.useEffect)(()=>p(),[p]);let m=(0,Y.useRef)(t);if((0,Y.useEffect)(()=>{let e=m.current&&!t;return m.current=t,e?p():void 0},[t,p]),(0,Y.useEffect)(()=>s?p():void 0,[s,p]),(0,Y.useEffect)(()=>{let e,t=()=>{e?.(),e=p()};return window.addEventListener(`focus`,t),()=>{window.removeEventListener(`focus`,t),e?.()}},[p]),!l?.paid||l.model!==(i??null))return null;let{chat:h,today:g}=l,_=e=>`${e.unpriced_answers>0?`≥ `:``}${$E(e.usd)}`,v=h.unpriced_answers+g.unpriced_answers>0,y=[...h.items].reverse(),b=e=>new Date(e).toLocaleTimeString(te(n),{hour:`numeric`,minute:`2-digit`});return V(`div`,{className:`composer-chip-wrap spend-meter-wrap`,children:[V(`button`,{ref:o,type:`button`,className:`context-meter spend-meter`,onClick:()=>c(e=>!e),"aria-expanded":s,"aria-label":n(`spend.aria`,{chat:_(h),today:_(g)}),title:n(v?`spend.titleExcluded`:`spend.title`),children:[P(`bdi`,{dir:`ltr`,children:_(h)}),V(`span`,{className:`spend-meter-today`,children:[`· `,n.bare(`spend.today`),` `,P(`bdi`,{dir:`ltr`,children:_(g)})]})]}),P(zo,{open:s,onClose:f,anchor:o,label:n(`spend.window`),align:`end`,children:V(`div`,{className:`context-meter-panel spend-meter-panel`,children:[V(`dl`,{className:`context-meter-rows`,children:[V(`div`,{className:`context-meter-row`,children:[P(`dt`,{children:n(`spend.thisChat`)}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:_(h)})})]}),V(`div`,{className:`context-meter-row`,children:[P(`dt`,{children:n.plural(`spend.todayChats`,g.chats)}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:_(g)})})]})]}),v&&P(`p`,{className:`context-meter-note spend-meter-excluded`,role:`note`,children:n(`spend.excluded`,{chat:h.unpriced_answers,today:g.unpriced_answers})}),y.length>0&&V(D.Fragment,{children:[P(`div`,{className:`spend-meter-heading`,children:n(`spend.perAnswer`)}),P(`dl`,{className:`context-meter-rows spend-meter-answers`,children:y.map(e=>V(`div`,{className:`context-meter-row`,children:[P(`dt`,{children:P(`bdi`,{dir:`ltr`,children:b(e.created_at)})}),P(`dd`,{children:e.kind===`estimate`&&e.usd!=null?P(`bdi`,{dir:`ltr`,children:$E(e.usd)}):P(`span`,{className:`spend-meter-unknown`,children:n(e.kind===`unreported`?`ctx.costUnreported`:`ctx.unknown`)})})]},e.message_id))})]}),P(`p`,{className:`context-meter-note`,children:n(`spend.note`)}),P(`button`,{type:`button`,className:`context-meter-details`,onClick:()=>{c(!1),a(`model`)},children:n(`spend.month`)})]})})]})}async function nD(){let{providers:e,lemonade_error:t}=await En();if(t)throw Error(t);return(await Promise.all(e.filter(e=>!e.remote).map(e=>Qt(e.id)))).flatMap(e=>e.models.filter(e=>e.downloaded).map(e=>({id:e.id,name:e.display_name??fs(e.id)})))}function rD({answeredBy:e,onPick:t}){let n=(0,Y.useRef)(null),r=T(),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),u=(0,Y.useCallback)(async()=>{s(null),l(null);try{s(await nD())}catch(e){l(e instanceof Error?e.message:String(e))}},[]);(0,Y.useEffect)(()=>{i&&u()},[i,u]);let d=o?.filter(t=>t.id!==e)??[];return V(D.Fragment,{children:[P(`button`,{ref:n,type:`button`,className:`msg-action-btn`,onClick:()=>a(e=>!e),title:r(`retry.button`),"aria-label":r(`retry.button`),"aria-expanded":i,children:P(Qa,{size:12})}),P(zo,{open:i,onClose:()=>a(!1),anchor:n,label:`Retry with`,placement:`below`,align:`end`,children:V(`div`,{className:`retry-menu`,children:[P(`div`,{className:`retry-menu-head`,children:r(`retry.head`)}),c&&P(`div`,{className:`retry-menu-error`,role:`alert`,children:c}),!c&&o===null&&V(`div`,{className:`retry-menu-empty`,children:[P(K,{size:12,className:`spin`,"aria-hidden":`true`}),` Loading models…`]}),o!==null&&d.length===0&&P(`div`,{className:`retry-menu-empty`,children:`No other model is downloaded on this PC. Add one in Settings → Model.`}),d.map(e=>P(`button`,{type:`button`,className:`retry-menu-item`,title:e.id,onClick:()=>{a(!1),t(e.id)},children:e.name},e.id))]})})]})}function iD(e){return e!=null&&e>0?`${(e/1e3).toFixed(1)} s`:null}function aD({parts:e}){let t=e.filter(Boolean);return t.length?P(`div`,{className:`compare-meta`,children:t.join(` · `)}):null}function oD({original:e,originalModel:t,originalLatencyMs:n,state:r,keeping:i,onKeep:a,onClose:o}){us();let s=r.status===`ready`?r.result.model:r.model,c=e.stats?.tokens_per_second;return V(`section`,{className:`answer-compare`,"aria-label":`Compare answers`,children:[V(`header`,{className:`answer-compare-head`,children:[P(`span`,{children:`Compare answers`}),P(`button`,{type:`button`,className:`msg-action-btn`,onClick:o,"aria-label":`Close comparison`,disabled:!!i,children:P(J,{size:12})})]}),V(`div`,{className:`answer-compare-cols`,children:[V(`article`,{className:`compare-col`,"aria-label":`Answer from ${t??`the original model`}`,children:[P(`h4`,{children:t?fs(t):`Original answer`}),P(aD,{parts:[iD(n),c?`${c} tok/s`:null]}),P(`div`,{className:`compare-body`,children:P(cw,{content:e.content})}),P(`button`,{type:`button`,className:`compare-keep`,onClick:()=>a(`original`),disabled:!!i||r.status===`running`,children:i===`original`?`Keeping…`:`Keep this answer`})]}),V(`article`,{className:`compare-col`,"aria-label":`Answer from ${s}`,children:[P(`h4`,{children:fs(s)}),r.status===`running`&&V(`div`,{className:`compare-wait`,children:[P(K,{size:14,className:`spin`,"aria-hidden":`true`}),V(`span`,{children:[`Loading `,fs(s),`, then answering from the same evidence. Tools are not run again.`]})]}),r.status===`failed`&&P(`div`,{className:`compare-error`,role:`alert`,children:r.error}),r.status===`ready`&&V(D.Fragment,{children:[P(aD,{parts:[`${r.result.stats.seconds.toFixed(1)} s`,r.result.stats.load_seconds>=1?`incl. ${r.result.stats.load_seconds.toFixed(1)} s loading`:null,r.result.stats.tokens_per_second?`${r.result.stats.tokens_per_second} tok/s`:null]}),P(`div`,{className:`compare-body`,children:P(cw,{content:r.result.content})}),P(`button`,{type:`button`,className:`compare-keep`,onClick:()=>a(`retry`),disabled:!!i,children:i===`retry`?`Keeping…`:`Keep this answer`})]})]})]})]})}var sD=`gaia.sessionPanel.open`,cD=`gaia.sessionPanel.width`,lD=`gaia.sessionPanel.sections`,uD={answer:!0,environment:!0,context:!1,outputs:!0,changes:!0,skills:!0,tools:!1};function dD(e,t,n){try{let r=window.localStorage.getItem(e);return r==null?n:t(r)}catch(t){return d.ui.warn(`Session panel setting ${e} unavailable; using the default`,t),n}}function fD(e,t){try{window.localStorage.setItem(e,t)}catch(t){d.ui.warn(`Could not remember session panel setting ${e}`,t)}}function pD(e){let t=typeof window<`u`?Math.floor(window.innerWidth*.5):640;return Math.round(Math.max(280,Math.min(e,640,Math.max(280,t))))}function mD(){return{open:dD(sD,e=>e!==`0`,!0),width:pD(dD(cD,e=>Number(e)||320,320)),sections:{...uD,...dD(lD,e=>JSON.parse(e),{})}}}var hD=p((e,t)=>({...mD(),overlayOpen:!1,focus:null,setOpen:t=>{fD(sD,t?`1`:`0`),e({open:t})},setOverlayOpen:t=>e({overlayOpen:t}),setWidth:t=>{let n=pD(t);fD(cD,String(n)),e({width:n})},setSection:(n,r)=>{let i={...t().sections,[n]:r};fD(lD,JSON.stringify(i)),e({sections:i})},reveal:n=>{let r={...t().sections,[n]:!0};fD(lD,JSON.stringify(r)),fD(sD,`1`),e({sections:r,open:!0,overlayOpen:!0,focus:{section:n,nonce:Date.now()}})},reload:()=>e({...mD(),overlayOpen:!1,focus:null})}));function gD(e,t){if(t)return e.some(e=>e.turnSummary)?{kind:`busy`}:null;let n=e[e.length-1];return!n||n.role!==`assistant`||!n.turnSummary?null:{kind:`turn`,turn:n}}function _D(e){let t=e.live_data?.attempted??0;return t>0&&(e.live_data?.failed??0)>=t}function vD(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function yD(e,t,n){let r=[];return t&&t.length>0&&r.push(e(h(`rail.pages`,t.length),{list:t.join(`, `)})),r.push(e(h(`rail.passages`,n),{n})),r.join(` · `)}function bD(e,t=z,n=!1){let{cost:r}=e;return r.kind===`local`?t(`rail.costLocal`):r.kind===`unreported`?t(n?`rail.costUnreportedStopped`:`rail.costUnreported`):r.kind===`estimate`&&typeof r.usd==`number`?t(`rail.costAbout`,{usd:r.usd<.01?r.usd.toFixed(4):r.usd.toFixed(2)}):t(e.model?`rail.costUnknownModel`:`rail.costUnknown`)}function xD(e){return e instanceof bn?e.detail||e.message:e instanceof Error?e.message:String(e)}function SD({messages:e,busy:t=!1}){let n=T(),r=gD(e,t);if(!r)return null;let i=r.kind===`turn`?r.turn.turnSummary??null:null,a=i?_D(i):!1;return V(`div`,{className:`side-rail-body`,children:[!i&&P(`p`,{className:`side-rail-pending`,role:`status`,children:n(`rail.pending`)}),a&&V(`div`,{className:`side-rail-warn`,role:`status`,children:[P(q,{size:14,"aria-hidden":`true`}),V(`div`,{children:[P(`strong`,{children:n(`rail.noLive`)}),P(`span`,{children:n(`rail.noLiveWhy`)})]})]}),i&&(i.error?P(`p`,{className:`side-rail-error`,role:`alert`,children:n(`rail.error`,{error:i.error})}):V(D.Fragment,{children:[P(wD,{summary:i}),P(DD,{summary:i}),P(OD,{summary:i,stopped:r.kind===`turn`&&!!r.turn.stopState})]}))]})}function CD({title:e,children:t}){let[n,r]=(0,Y.useState)(!0);return V(`section`,{className:`side-rail-section`,children:[V(`button`,{type:`button`,className:`side-rail-section-head`,onClick:()=>r(!n),"aria-expanded":n,children:[P(xr,{size:12,className:`side-rail-chevron${n?` open`:``}`,"aria-hidden":`true`}),e]}),n&&P(`div`,{className:`side-rail-section-body`,children:t})]})}function wD({summary:e}){let t=T(),n=e.pages??[],r=e.documents??[];return n.length===0&&r.length===0?null:P(CD,{title:t(`rail.sources`),children:V(`ul`,{className:`side-rail-list`,children:[n.map(e=>V(`li`,{className:`side-rail-item`,children:[P(Fi,{size:13,className:`side-rail-item-icon`,"aria-hidden":`true`}),V(`div`,{className:`side-rail-item-text`,children:[V(`a`,{href:Xh(e.url)||void 0,target:`_blank`,rel:`noopener noreferrer`,className:`side-rail-link`,title:e.url,children:[P(`span`,{className:`side-rail-link-text`,children:e.title||vD(e.url)}),P($r,{size:10,"aria-hidden":`true`,className:`side-rail-link-icon`})]}),V(`span`,{className:`side-rail-meta`,children:[vD(e.url),e.kind===`search_result`?` · ${t(`rail.searchResult`)}`:``]})]})]},e.url)),r.map(e=>{let n=e.passages??0;return V(`li`,{className:`side-rail-item`,children:[P(_i,{size:13,className:`side-rail-item-icon`,"aria-hidden":`true`}),V(`div`,{className:`side-rail-item-text`,children:[P(`span`,{className:`side-rail-name`,title:e.name,dir:`auto`,children:e.name}),P(`span`,{className:`side-rail-meta`,children:t.compose(t=>yD(t,e.pages,n))})]})]},e.path)})]})})}var TD=4e3;function ED(e){let t=e.join(`
|
|
65
65
|
`),[n,r]=(0,Y.useState)(()=>new Map),[i,a]=(0,Y.useState)(null);return(0,Y.useEffect)(()=>{if(!t)return;let e=t.split(`
|
|
66
66
|
`),n=!1,i=()=>{document.visibilityState!==`hidden`&&Xe(e).then(e=>{n||(r(new Map(e.files.map(e=>[e.path,e]))),a(null))},e=>{n||(d.ui.warn(`Could not re-check the files this turn wrote`,e),a(xD(e)))})};i();let o=window.setInterval(i,TD);return window.addEventListener(`focus`,i),()=>{n=!0,window.clearInterval(o),window.removeEventListener(`focus`,i)}},[t]),{status:n,error:i}}function DD({summary:e}){let t=T(),n=e.files??[],[r,i]=(0,Y.useState)(null),{status:a,error:o}=ED(n.map(e=>e.path));if(n.length===0)return null;let s=(e,n)=>{i(null),e.catch(e=>{d.ui.error(`Failed to open ${n}`,e),i(t(`sp.couldntOpen`,{name:n,error:xD(e)}))})};return V(CD,{title:t(`rail.files`),children:[P(`ul`,{className:`side-rail-list`,children:n.map(e=>{let n=a.get(e.path);if(n?.exists===!1)return V(`li`,{className:`side-rail-item side-rail-item-gone`,children:[P(_i,{size:13,className:`side-rail-item-icon`,"aria-hidden":`true`}),V(`div`,{className:`side-rail-item-text`,children:[P(`span`,{className:`side-rail-name`,title:e.path,children:e.name}),P(`span`,{className:`side-rail-meta`,children:t(`sp.gone`)})]})]},e.path);let r=n?.exists===!0&&typeof n.mtime==`number`&&typeof e.mtime==`number`&&n.mtime!==e.mtime;return V(`li`,{className:`side-rail-item`,children:[P(_i,{size:13,className:`side-rail-item-icon`,"aria-hidden":`true`}),V(`div`,{className:`side-rail-item-text`,children:[P(`span`,{className:`side-rail-name`,title:e.path,children:e.name}),r&&P(`span`,{className:`side-rail-meta`,children:t(`rail.changedSince`)}),V(`span`,{className:`side-rail-actions`,children:[e.openable&&P(`button`,{type:`button`,className:`side-rail-action`,onClick:()=>s(xt(e.path),e.name),children:t(`sp.open`)}),V(`button`,{type:`button`,className:`side-rail-action`,onClick:()=>s(On(e.path,!0),e.name),children:[P(xi,{size:11,"aria-hidden":`true`}),t(`sp.showInFolder`)]})]})]})]},e.path)})}),r&&P(`p`,{className:`side-rail-error`,role:`alert`,children:r}),o&&P(`p`,{className:`side-rail-error`,children:t(`rail.checkFailed`,{error:o})})]})}function OD({summary:e,stopped:t}){let n=T();us();let{model:r}=e,i=e.sites??[],a=(e.documents??[]).length>0;return P(CD,{title:n(`rail.thisTurn`),children:V(`dl`,{className:`side-rail-facts`,children:[P(`dt`,{children:n(`rail.model`)}),V(`dd`,{children:[r?V(`span`,{className:`side-rail-where${r.remote?` remote`:``}`,children:[r.remote?P(Lr,{size:12,"aria-hidden":`true`}):P(ma,{size:12,"aria-hidden":`true`}),r.remote?n(`rail.cloudModel`,{name:r.provider_name}):n(`rail.thisPc`)]}):P(`span`,{className:`side-rail-where`,children:n(`rail.notReported`)}),r?.name&&P(`span`,{className:`side-rail-meta`,title:r.name,dir:`ltr`,children:fs(r.name)})]}),a&&V(D.Fragment,{children:[P(`dt`,{children:n(`rail.documents`)}),P(`dd`,{children:r?.remote?n(`rail.docsSent`,{provider:r.provider_name}):n(r?`rail.docsLocal`:`rail.docsSearched`)})]}),P(`dt`,{children:n(`rail.websites`)}),P(`dd`,{children:i.length>0?P(`span`,{dir:`ltr`,children:i.join(`, `)}):n(`rail.noSites`)}),P(`dt`,{children:n(`rail.cost`)}),P(`dd`,{children:bD(e,n,t)})]})})}function kD({id:e,title:t,summary:n,children:r}){let i=hD(t=>t.sections[e]),a=hD(e=>e.setSection),o=hD(e=>e.focus),s=(0,Y.useRef)(null),c=`sp-section-${e}`;return(0,Y.useEffect)(()=>{o?.section===e&&s.current?.scrollIntoView?.({block:`start`,behavior:Mx()})},[o,e]),V(`section`,{ref:s,className:`sp-section`,"aria-labelledby":`${c}-title`,children:[P(`h3`,{className:`sp-section-heading`,children:V(`button`,{type:`button`,id:`${c}-title`,className:`sp-section-head`,"aria-expanded":i,"aria-controls":c,onClick:()=>a(e,!i),children:[P(xr,{size:13,className:`sp-chevron${i?` is-open`:``}`,"aria-hidden":`true`}),P(`span`,{className:`sp-section-title`,children:t}),n!=null&&P(`span`,{className:`sp-section-summary`,children:n})]})}),i&&P(`div`,{id:c,className:`sp-section-body`,children:r})]})}function AD(e,t){let n=(0,Y.useRef)(e),r=(0,Y.useRef)(t);r.current=t,(0,Y.useEffect)(()=>{let t=n.current&&!e;n.current=e,t&&r.current()},[e])}var jD=`gaia:mobile-access-request`,MD=`gaia:mobile-access-state`;function ND(e){window.dispatchEvent(new CustomEvent(jD,{detail:e}))}function PD(e){window.dispatchEvent(new CustomEvent(MD,{detail:e}))}function FD(e,t){let n=(0,Y.useRef)(t);n.current=t,(0,Y.useEffect)(()=>{let t=e=>n.current(!!e.detail);return window.addEventListener(e,t),()=>window.removeEventListener(e,t)},[e])}var ID=e=>FD(jD,e),LD=e=>FD(MD,e);function RD({checked:e,onChange:t,label:n,text:r,disabled:i}){return V(`span`,{className:`sp-switch-wrap`,children:[P(`button`,{type:`button`,role:`switch`,"aria-checked":e,"aria-label":n,className:`sp-switch${e?` is-on`:``}`,onClick:()=>t(!e),disabled:i,children:P(`span`,{className:`sp-switch-knob`,"aria-hidden":`true`})}),r&&P(`span`,{className:`sp-state-text`,children:r})]})}var zD={added:`env.source.added`,gaia_documents:`env.source.gaia_documents`,scratch:`env.source.scratch`,document:`env.source.document`,working_folder:`env.source.working_folder`,approved:`env.source.approved`,allowed_paths:`env.source.allowed_paths`},BD=3;function VD(e){let t=e.split(/[\\/]/).filter(Boolean);return t[t.length-1]??e}function HD({sessionId:e,busy:t}){let n=T(),{env:r}=_E(e),i=r&&!r.internet?n(`env.offline`):null;return V(kD,{id:`environment`,title:n(`env.title`),summary:i,children:[P(GD,{sessionId:e,busy:t}),P(KD,{sessionId:e}),P(qD,{sessionId:e}),P(JD,{}),P(YD,{sessionId:e})]})}function UD({label:e,children:t}){return V(`div`,{className:`sp-env-row`,children:[P(`div`,{className:`sp-env-label`,children:e}),P(`div`,{className:`sp-env-value`,children:t})]})}function WD(e,t){let n=e=>e.toLowerCase().replace(/^user\./,``);return n(e)===n(t)}function GD({sessionId:e,busy:t}){let n=T(),r=gs(),i=ls(e=>e.active),a=k(t=>_s(i,t.sessions,e)),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),u=r?.remote===!0,f=(0,Y.useCallback)(()=>{u||Promise.resolve().then(()=>ot()).then(e=>{s(lE(e,e=>typeof e.state==`string`,`model status`)),l(null)}).catch(e=>{d.ui.warn(`Could not read where the local model runs`,e),l(Ix(e))})},[u]);if((0,Y.useEffect)(f,[f]),AD(t,f),u)return V(UD,{label:n(`env.runsOn`),children:[V(`span`,{className:`sp-place is-remote`,children:[P(Lr,{size:13,"aria-hidden":`true`}),` `,n(`env.cloudPlace`,{name:r?.label??``})]}),r?.description&&P(`span`,{className:`sp-meta`,children:r.description})]});if(!r)return P(UD,{label:n(`env.runsOn`),children:P(`span`,{className:`sp-meta`,title:hs,children:n(`env.notKnownYet`)})});let p=!!(o?.model&&a&&!WD(o.model,a)),m=p?null:o?.memory;return V(UD,{label:n(`env.runsOn`),children:[V(`span`,{className:`sp-place`,children:[P(ma,{size:13,"aria-hidden":`true`}),` `,n(`env.thisPc`),!p&&o?.placement?.label?` · ${o.placement.label}`:``]}),p?P(`span`,{className:`sp-meta`,children:n(`env.notLoaded`,{model:fs(a)})}):o?.display_name&&V(`span`,{className:`sp-meta`,dir:`ltr`,children:[o.display_name,o.state===`loaded`?``:` · ${o.state}`]}),m&&V(`span`,{className:`sp-meta`,children:[m.model_gb==null?n(`env.inUseUnknown`):n(`env.inUse`,{gb:m.model_gb.toFixed(1)}),m.free_gb==null?``:` · ${n(`env.free`,{gb:m.free_gb.toFixed(1)})}`]}),(c||o?.error)&&P(`span`,{className:`sp-error`,children:c??o?.error})]})}function KD({sessionId:e}){let t=T(),{env:n,error:r,change:i}=_E(e),a=k(t=>t.sessions.find(t=>t.id===e)?.agent_type===`gaia`),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!1),f=async(e,t)=>{l(e),s(null);try{await t()}catch(e){s(Ix(e))}finally{l(null)}},p=t=>f(t.path,()=>i(()=>ge(e,t.path))),{open:m,picker:h,error:g}=fE(t=>{f(t,()=>i(()=>on(e,t)))}),_=n?.folders.filter(e=>e.kind===`folder`)??[],v=n?.folders.filter(e=>e.kind===`file`)??[],y=u?v:v.slice(0,BD),b=!n||!n.enforced,x=e=>V(`li`,{className:`sp-scope-item`,children:[e.kind===`folder`?P(Di,{size:13,className:`sp-item-icon`,"aria-hidden":`true`}):P(yi,{size:13,className:`sp-item-icon`,"aria-hidden":`true`}),V(`div`,{className:`sp-item-text`,children:[P(`span`,{className:`sp-item-name`,dir:`auto`,title:e.path,children:VD(e.path)}),V(`span`,{className:`sp-meta`,title:e.path,children:[t(zD[e.source]),` · `,P(`span`,{className:`sp-item-path`,dir:`ltr`,children:e.path})]})]}),e.removable&&!b&&P(`button`,{type:`button`,className:`btn-icon-sm sp-item-remove`,onClick:()=>void p(e),disabled:c!==null,"aria-label":t(`env.remove`,{path:e.path}),title:t(`env.removeShort`),children:P(J,{size:12})})]},e.path);return V(UD,{label:n&&!n.enforced?t(`env.reach`):t(`env.readWrite`),children:[!n&&!r&&P(`span`,{className:`sp-meta`,children:t(`sp.checking`)}),n&&!n.enforced&&P(`span`,{className:`sp-meta`,children:t(a?`env.flagshipScope`:`env.agentScope`)}),r&&P(`span`,{className:`sp-error`,children:t(`env.foldersError`,{error:r})}),n&&V(D.Fragment,{children:[n.folders.length===0&&P(`span`,{className:`sp-meta`,children:t(`env.nothing`)}),V(`ul`,{className:`sp-list`,children:[_.map(x),y.map(x)]}),v.length>BD&&P(`button`,{type:`button`,className:`link-btn sp-more`,onClick:()=>d(e=>!e),children:u?t(`env.fewerFiles`):t(`env.allFiles`,{n:v.length})}),!n.enforced&&P(`span`,{className:`sp-meta`,children:t(`env.ownProcess`)}),n.removed.length>0&&P(`span`,{className:`sp-meta`,children:t(`env.removed`,{names:n.removed.map(VD).join(`, `)})}),!b&&V(`button`,{type:`button`,className:`sp-action`,onClick:()=>m(),disabled:c!==null,children:[P(Ci,{size:12,"aria-hidden":`true`}),` `,t(`env.addFolder`)]})]}),(o??g)&&P(`span`,{className:`sp-error`,role:`alert`,children:o??g}),h]})}function qD({sessionId:e}){let t=T(),{env:n,change:r,refresh:i}=_E(e),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(!1);if(!n)return null;let l=async t=>{c(!0),o(null);try{await r(()=>ye(e,t))}catch(e){o(Ix(e)),i()}finally{c(!1)}};return n.internet_enforced?V(UD,{label:t(`env.internet`),children:[P(RD,{checked:n.internet,onChange:e=>void l(e),disabled:s,label:t(`env.internetFor`),text:n.internet?t(`env.on`):t(`env.offBlocked`)}),a&&P(`span`,{className:`sp-error`,role:`alert`,children:a})]}):P(UD,{label:t(`env.internet`),children:P(`span`,{className:`sp-state-text`,children:n.internet?t(`env.on`):t(`env.off`)})})}function JD(){let e=T(),[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!1),[a,o]=(0,Y.useState)(null),s=(0,Y.useCallback)(()=>{Promise.resolve().then(()=>Cn()).then(e=>{n(lE(e,e=>typeof e.active==`boolean`,`phone access status`)),o(null)}).catch(e=>o(Ix(e)))},[]);(0,Y.useEffect)(s,[s]),LD(()=>{i(!1),s()});let c=t?.active===!0;return V(UD,{label:e(`env.phone`),children:[P(RD,{checked:c,onChange:e=>{i(!0),ND(e)},disabled:r,label:e(`env.phone`),text:e(r?c?`env.stopping`:`env.starting`:c?`env.on`:`env.off`)}),c&&V(`span`,{className:`sp-meta`,children:[P(eo,{size:12,"aria-hidden":`true`}),` `,t?.device?e(`env.phoneConnected`,{name:t.device.name}):e(`env.noPhone`)]}),c&&P(`button`,{type:`button`,className:`sp-action`,onClick:()=>ND(!0),children:e(`env.qr`)}),(a||t?.error)&&P(`span`,{className:`sp-error`,children:a??t?.error})]})}function YD({sessionId:e}){let t=T(),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{let t=!0;return Promise.resolve().then(()=>Ct(e)).then(e=>{t&&r(lE(e,e=>typeof e.mode==`string`,`permission mode`).mode)}).catch(e=>{t&&s(Ix(e))}),()=>{t=!1}},[e]),CE(e,r);let c=async t=>{a(!1),s(null);try{let n=(await Ft(e,t)).mode;r(n),SE(e,n)}catch(e){s(Ix(e))}},l=wE.find(e=>e.mode===n)?.note;return V(UD,{label:t(`env.permission`),children:[P(`div`,{className:`sp-segmented`,role:`radiogroup`,"aria-label":t(`env.permission`),children:wE.map(e=>V(`button`,{type:`button`,role:`radio`,"aria-checked":n===e.mode,className:n===e.mode?`is-selected`:void 0,onClick:()=>e.mode===`full_access`?a(!0):void c(e.mode),children:[e.mode===`full_access`?P(Ka,{size:12,"aria-hidden":`true`}):P(Ja,{size:12,"aria-hidden":`true`}),e.mode===`ask`?t(`env.ask`):t(e.label)]},e.mode))}),l&&P(`span`,{className:`sp-meta`,children:t(l)}),i&&V(`span`,{className:`sp-confirm`,role:`alert`,children:[t(`env.fullAccessWarn`),P(`button`,{type:`button`,className:`sp-action is-warning`,onClick:()=>void c(`full_access`),children:t(`env.turnOn`)}),P(`button`,{type:`button`,className:`sp-action`,onClick:()=>a(!1),children:t(`sp.cancel`)})]}),o&&P(`span`,{className:`sp-error`,role:`alert`,children:o})]})}var XD={file:{label:`out.kind.file`,Icon:_i},export:{label:`out.kind.export`,Icon:di},image:{label:`out.kind.image`,Icon:zi},document:{label:`out.kind.document`,Icon:Zi},memory:{label:`out.kind.memory`,Icon:ar},schedule:{label:`out.kind.schedule`,Icon:lr}},ZD={created:`out.change.created`,edited:`out.change.edited`,deleted:`out.change.deleted`};function QD(e,t,n){if(!e)return null;let r=Date.parse(`${e.replace(` `,`T`)}Z`);if(Number.isNaN(r))return null;let i=Math.max(0,Math.round((t-r)/1e3));return i<60?{key:`out.justNow`}:i<3600?{key:`out.minAgo`,params:{n:Math.floor(i/60)}}:i<86400?{key:`out.hAgo`,params:{n:Math.floor(i/3600)}}:new Date(r).toLocaleDateString(n,{month:`short`,day:`numeric`})}function $D(e){return e.state===`undone`?`out.undone`:e.state===`gone`?`sp.gone`:null}function eO({sessionId:e,busy:t,onJumpToMessage:n}){let r=T();return P(kD,{id:`outputs`,title:r(`out.title`),children:P(tO,{sessionId:e,busy:t,onJumpToMessage:n})})}function tO({sessionId:e,busy:t,onJumpToMessage:n}){let r=T(),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,f]=(0,Y.useState)(!1),p=(0,Y.useCallback)(()=>{let t=!0;return Promise.resolve().then(()=>Ae(e)).then(e=>{t&&(a(lE(e,e=>Array.isArray(e.items),`list of outputs`).items),s(null))}).catch(n=>{t&&(d.ui.warn(`Could not list what session=${e} produced`,n),s(Fx(n)))}),()=>{t=!1}},[e]);(0,Y.useEffect)(p,[p]),AD(t,p),Wx(e,p);let m=(e,t)=>{l(null),e.catch(e=>l(r(`sp.couldntOpen`,{name:t,error:Fx(e)})))};if(o)return P(`p`,{className:`sp-error`,children:r(`out.listError`,{error:o})});if(!i)return P(`p`,{className:`sp-meta`,children:r(`sp.checking`)});if(i.length===0)return P(`p`,{className:`sp-meta`,children:r(`out.empty`)});let h=u?i:i.slice(0,5);return V(D.Fragment,{children:[P(`ul`,{className:`sp-list`,"aria-label":r(`out.listLabel`),children:h.map(e=>{let{label:t,Icon:i}=XD[e.kind],a=$D(e),o=e.change&&e.kind!==`document`?ZD[e.change]:void 0,s=QD(e.created_at,Date.now(),te(r)),c=r.compose(e=>[o?e(`out.kindChanged`,{kind:g(t),change:g(o)}):e(t),s==null?``:typeof s==`string`?s:e(s.key,s.params),a?e(a):``].filter(Boolean).join(` · `));return V(`li`,{className:`sp-output${e.state===`present`?``:` is-inactive`}`,children:[P(i,{size:13,className:`sp-item-icon`,"aria-hidden":`true`}),V(`div`,{className:`sp-item-text`,children:[P(`span`,{className:`sp-item-name`,dir:`auto`,title:e.path??e.name,children:e.name}),P(`span`,{className:`sp-meta`,children:c}),V(`span`,{className:`sp-item-actions`,children:[e.message_id!=null&&V(`button`,{type:`button`,className:`sp-action`,onClick:()=>{n(e.message_id)||l(r(`out.notLoaded`))},"aria-label":r(`out.goToAria`,{name:e.name}),children:[P(Ur,{size:11,"aria-hidden":`true`}),` `,r(`sp.goToTurn`)]}),e.openable&&e.path&&P(`button`,{type:`button`,className:`sp-action`,onClick:()=>m(xt(e.path),e.name),children:r(`sp.open`)}),e.revealable&&e.path&&V(`button`,{type:`button`,className:`sp-action`,onClick:()=>m(On(e.path,!0),e.name),children:[P(xi,{size:11,"aria-hidden":`true`}),` `,r(`sp.showInFolder`)]})]})]})]},e.id)})}),i.length>5&&P(`button`,{type:`button`,className:`link-btn sp-more`,onClick:()=>f(e=>!e),children:u?r(`out.fewer`):r(`out.more`,{n:i.length-5})}),c&&P(`p`,{className:`sp-error`,role:`alert`,children:c})]})}function nO(e,t,n=`${t}s`){return`${e} ${e===1?t:n}`}function rO(e){let t=e.split(/[\\/]/).filter(Boolean);return t[t.length-1]??e}var iO=e=>g(e===1?`chg.files.one`:`chg.files.other`,{n:e});function aO(e,t=z){let{files:n,additions:r,deletions:i}=e.totals;return t(`chg.total`,{files:iO(n),add:r,del:i})}var oO={edited:`Edited`,created:`Created`,deleted:`Deleted`},sO={edited:`chg.edited`,created:`chg.created`,deleted:`chg.deleted`};function cO({sessionId:e,busy:t,onJumpToMessage:n}){let r=T(),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),u=(0,Y.useCallback)(()=>{Promise.resolve().then(()=>ft(e)).then(e=>{a(lE(e,e=>Array.isArray(e.files),`list of this chat's changes`)),s(null)}).catch(t=>{d.ui.warn(`Could not total what session=${e} changed`,t),s(Fx(t))})},[e]);(0,Y.useEffect)(u,[u]),AD(t,()=>{l(null),u()}),Wx(e,u);let f=!i||i.files.length===0;return!o&&f&&!c?null:V(kD,{id:`changes`,title:r(`chg.title`),summary:i&&!f?r(`chg.summary`,{files:iO(i.totals.files),add:i.totals.additions,del:i.totals.deletions}):null,children:[o&&P(`p`,{className:`sp-error`,children:r(`chg.error`,{error:o})}),i&&!f&&P(lO,{sessionId:e,busy:t,changes:i,onChanged:u,onUndone:l,onJumpToMessage:n}),f&&c&&P(`p`,{className:`sp-ok`,role:`status`,children:c})]})}function lO({sessionId:e,busy:t,changes:n,onChanged:r,onUndone:i,onJumpToMessage:a}){let o=T(),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(`idle`),[d,f]=(0,Y.useState)(null),p=n.files.length,m=async t=>{u(`working`),f(null);try{let n=await we(e,t),r=[];n.restored.length&&r.push(`restored ${nO(n.restored.length,`file`)}`),n.removed.length&&r.push(`removed ${nO(n.removed.length,`new file`)}`);let a=`Undone: ${r.join(`, `)||`no files needed changing`}.`;n.kept_folders.length&&(a+=` Kept ${nO(n.kept_folders.length,`folder`)} the chat created, because they now hold other files.`),f(a),u(`done`),i(a),Ux(e),await Bx(e)}catch(e){let t=e?.reason===`conflict`;f(Ix(e)),u(t?`conflict`:`idle`)}};return V(`div`,{className:`sp-changes`,children:[V(`p`,{className:`sp-changes-total`,"aria-live":`polite`,children:[P(`strong`,{children:aO(n,o)}),n.totals.uncounted>0&&V(`span`,{className:`sp-meta`,children:[` · `,o.plural(`chg.uncounted`,n.totals.uncounted)]})]}),n.pending&&P(`p`,{className:`sp-meta`,children:o(`chg.pending`)}),P(`ul`,{className:`sp-list`,children:n.files.map(e=>{let t=e.message_ids[e.message_ids.length-1];return V(`li`,{className:`sp-change`,children:[V(`div`,{className:`sp-item-text`,children:[P(`span`,{className:`sp-item-name`,dir:`auto`,title:e.path,children:rO(e.path)}),V(`span`,{className:`sp-meta`,children:[o(sO[e.change]),e.additions!=null&&V(D.Fragment,{children:[` · `,V(`span`,{className:`sp-add`,children:[`+`,e.additions]}),` `,V(`span`,{className:`sp-del`,children:[`−`,e.deletions]})]}),e.message_ids.length>1&&` · ${o(`chg.turns`,{n:e.message_ids.length})}`]}),e.changed_since&&V(`span`,{className:`sp-warn-text`,children:[P(q,{size:11,"aria-hidden":`true`}),` `,o(`chg.outside`,{when:e.changed_since})]})]}),t!=null&&P(`button`,{type:`button`,className:`btn-icon-sm`,onClick:()=>a(t),"aria-label":o(`chg.goToLast`,{name:rO(e.path)}),title:o(`sp.goToTurn`),children:P(Ur,{size:12})})]},e.path)})}),n.incomplete&&V(`p`,{className:`sp-warn-text`,role:`note`,children:[P(q,{size:11,"aria-hidden":`true`}),` `,$x(n.untracked,{inChat:!0,undo:`Undo all`})]}),V(`div`,{className:`sp-actions-row`,children:[V(`button`,{type:`button`,className:`sp-action`,onClick:()=>c(!0),children:[P(ai,{size:12,"aria-hidden":`true`}),` `,o(`chg.review`)]}),l!==`confirm`&&l!==`conflict`&&V(`button`,{type:`button`,className:`sp-action`,onClick:()=>u(`confirm`),disabled:l===`working`||t,title:t?o(`chg.wait`):void 0,children:[P(mo,{size:12,"aria-hidden":`true`}),` `,o(l===`working`?`chg.undoing`:`chg.undoAll`)]})]}),l===`confirm`&&V(`div`,{className:`sp-confirm`,role:`group`,"aria-label":o(`chg.confirmLabel`),children:[o(p===1?`chg.confirm.one`:`chg.confirm.other`,{files:iO(p)}),V(`span`,{className:`sp-actions-row`,children:[P(`button`,{type:`button`,className:`sp-action is-danger`,onClick:()=>void m(!1),children:o(`chg.undoAll`)}),P(`button`,{type:`button`,className:`sp-action`,onClick:()=>u(`idle`),children:o(`sp.cancel`)})]})]}),d&&V(`div`,{className:l===`done`?`sp-ok`:`sp-error`,role:l===`done`?`status`:`alert`,children:[d,l===`conflict`&&V(`span`,{className:`sp-actions-row`,children:[P(`button`,{type:`button`,className:`sp-action is-danger`,onClick:()=>void m(!0),children:o(`chg.undoAnyway`)}),P(`button`,{type:`button`,className:`sp-action`,onClick:()=>{u(`idle`),f(null)},children:o(`chg.keep`)})]})]}),P(fO,{sessionId:e,busy:t,onCommitted:r}),s&&P(dO,{changes:n,onClose:()=>c(!1)})]})}function uO(e){if(e.too_large)return`Too large to show: ${e.before_size} → ${e.after_size} bytes.`;if(e.binary)return`Binary file: ${e.before_size} → ${e.after_size} bytes. No text diff.`;if(e.truncated)return`Diff shortened: the change is too long to show in full.`}function dO({changes:e,onClose:t}){Lo(!0,t);let n=(0,Y.useRef)(null);return sS(n,!0),P(`div`,{ref:n,className:`modal-overlay`,onClick:t,role:`dialog`,"aria-modal":`true`,"aria-label":`Review this chat's changes`,children:V(`div`,{className:`modal-panel changes-review`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`modal-header`,children:[V(`h3`,{children:[`Changes in this chat · `,aO(e)]}),P(`button`,{type:`button`,className:`btn-icon`,onClick:t,"aria-label":`Close`,children:P(J,{size:18})})]}),P(`div`,{className:`modal-body changes-review-body`,children:e.files.map(e=>P(`section`,{className:`changes-review-file`,children:P(ax,{data:{title:e.path,badge:oO[e.change],note:uO(e),unified:e.binary||e.too_large?``:e.unified}})},e.path))})]})})}function fO({sessionId:e,busy:t,onCommitted:n}){let r=T(),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),f=(0,Y.useCallback)(()=>{Promise.resolve().then(()=>_t(e)).then(e=>{a(lE(e,e=>Array.isArray(e.repos),`list of git repositories`)),s(null)}).catch(e=>s(Fx(e)))},[e]);return(0,Y.useEffect)(f,[f]),AD(t,f),Wx(e,f),o?P(`p`,{className:`sp-error`,children:r(`chg.gitError`,{error:o})}):!i||!i.available||i.repos.length===0?null:V(`div`,{className:`sp-git`,children:[i.repos.map(e=>V(`div`,{className:`sp-git-repo`,children:[V(`span`,{className:`sp-meta`,title:e.root,children:[P(ki,{size:12,"aria-hidden":`true`}),` `,rO(e.root),` · `,e.branch,e.uncommitted.length===0&&e.files.length>0&&` · committed`]}),V(`span`,{className:`sp-actions-row`,children:[V(`button`,{type:`button`,className:`sp-action`,disabled:t||e.uncommitted.length===0,onClick:()=>{d(null),l({kind:`commit`,repo:e})},children:[P(ji,{size:12,"aria-hidden":`true`}),` Commit…`]}),V(`button`,{type:`button`,className:`sp-action`,disabled:t||e.pr_blocked!=null,title:e.pr_blocked??void 0,onClick:()=>{d(null),l({kind:`pr`,repo:e})},children:[P(Ni,{size:12,"aria-hidden":`true`}),` Create PR…`]})]}),e.pr_blocked&&P(`span`,{className:`sp-meta`,children:e.pr_blocked})]},e.root)),u&&P(`p`,{className:`sp-ok`,role:`status`,children:u}),c&&P(pO,{sessionId:e,kind:c.kind,repo:c.repo,onClose:()=>l(null),onDone:e=>{l(null),d(e),f(),n()}})]})}function pO({sessionId:e,kind:t,repo:n,onClose:r,onDone:i}){let[a,o]=(0,Y.useState)(n.draft.title),[s,c]=(0,Y.useState)(n.draft.body),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(null);Lo(!0,r,!l);let p=(0,Y.useRef)(null);sS(p,!0);let m=async()=>{u(!0),f(null);try{if(t===`commit`){let t=await $t(e,n.root,`${a.trim()}\n\n${s.trim()}`.trim());i(`Committed ${nO(t.files.length,`file`)} as ${t.commit}.`)}else i(`Opened ${(await Lt(e,n.root,a,s)).url}`)}catch(e){f(Ix(e)),u(!1)}},h=t===`commit`?n.uncommitted:n.files;return P(`div`,{className:`modal-overlay`,onClick:l?void 0:r,children:V(`div`,{ref:p,className:`modal-panel sp-git-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t===`commit`?`Commit this chat’s changes`:`Create a pull request`,onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`modal-header`,children:[P(`h3`,{children:t===`commit`?`Commit this chat’s changes`:`Create a pull request`}),P(`button`,{type:`button`,className:`btn-icon`,onClick:r,disabled:l,"aria-label":`Close`,children:P(J,{size:18})})]}),V(`div`,{className:`modal-body sp-git-body`,children:[P(`p`,{className:`sp-meta`,children:t===`commit`?`In ${n.root} on ${n.branch}. Only the files below are committed; anything else you changed stays as it is.`:`Pushes ${n.branch} to ${n.remote} (never forced), then opens a pull request with GitHub's gh tool.`}),V(`label`,{className:`sp-field`,children:[P(`span`,{children:t===`commit`?`Summary`:`Title`}),P(`input`,{value:a,onChange:e=>o(e.target.value),disabled:l})]}),V(`label`,{className:`sp-field`,children:[P(`span`,{children:t===`commit`?`Details`:`Description`}),P(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:7,disabled:l})]}),V(`div`,{className:`sp-meta`,children:[nO(h.length,`file`),`: `,h.join(`, `)]}),t===`commit`&&n.ignored.length>0&&V(`div`,{className:`sp-meta`,children:[`Left out, because git ignores `,n.ignored.length===1?`it`:`them`,`: `,n.ignored.join(`, `)]}),d&&P(`p`,{className:`sp-error`,role:`alert`,children:d})]}),V(`div`,{className:`sp-picker-actions`,children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:r,disabled:l,children:`Cancel`}),V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void m(),disabled:l||!a.trim(),children:[l&&P(K,{size:13,className:`spin`,"aria-hidden":`true`}),t===`commit`?`Commit ${nO(h.length,`file`)}`:`Push and open PR`]})]})]})})}var mO={mcp:`tools.cat.mcp`,skill:`tools.cat.skill`,agent:`tools.cat.agent`};function hO(e,t){let n=mO[e];return n?t(n):e.replace(/_/g,` `)}function gO(e){let t=new Map;for(let n of e){let e=t.get(n.category);e?e.push(n):t.set(n.category,[n])}return[...t.entries()]}function _O(e){return e.split(`
|
|
67
|
-
`,1)[0].trim()}function vO({sessionId:e,busy:t}){let n=T();return P(kD,{id:`tools`,title:n(`tools.title`),children:P(yO,{sessionId:e,busy:t})})}function yO({sessionId:e,busy:t}){let n=T(),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(null),s=(0,Y.useCallback)(()=>{let t=!0;return Promise.resolve().then(()=>Ie(e)).then(e=>{t&&(i(lE(e,e=>Array.isArray(e.tools),`list of tools`).tools),o(null))}).catch(n=>{if(!t)return;let r=n.httpStatus,a=n.detail;d.ui.warn(`Could not list the tools of session=${e}`,n),i(null),o({notRunning:r===409,text:a||Fx(n)})}),()=>{t=!1}},[e]);return(0,Y.useEffect)(s,[s]),AD(t,s),a?.notRunning?P(`p`,{className:`sp-meta`,role:`status`,children:n(`tools.notRunning`)}):a?P(`p`,{className:`sp-error`,role:`alert`,children:n(`tools.listError`,{error:a.text})}):r?r.length===0?P(`p`,{className:`sp-meta`,children:n(`tools.empty`)}):P(`div`,{className:`sp-tools`,"aria-label":n(`tools.listLabel`),role:`group`,children:gO(r).map(([e,t])=>{let r=hO(e,n);return V(`section`,{className:`sp-tool-group`,"aria-label":r,children:[V(`h4`,{className:`sp-tool-group-title`,children:[r,` `,P(`span`,{className:`sp-meta`,children:t.length})]}),P(`ul`,{className:`sp-list`,children:t.map(e=>V(`li`,{className:`sp-tool`,children:[P(`code`,{className:`sp-item-name`,dir:`ltr`,children:e.name}),e.description&&P(`span`,{className:`sp-meta`,title:e.description,children:_O(e.description)})]},e.name))})]},e)})}):P(`p`,{className:`sp-meta`,children:n(`sp.checking`)})}var bO={model:`skills.how.model`,auto:`skills.how.auto`,always:`skills.how.always`};function xO({sessionId:e,busy:t}){let n=T();return P(kD,{id:`skills`,title:n(`skills.title`),children:P(SO,{sessionId:e,busy:t})})}function SO({sessionId:e,busy:t}){let n=T(),r=k(e=>e.skillUses),[i,a]=(0,Y.useState)(void 0),[o,s]=(0,Y.useState)(null),c=(0,Y.useCallback)(()=>{let t=!0;return Promise.resolve().then(()=>Ie(e)).then(e=>{if(!t)return;let n=lE(e,e=>e.skills===null||Array.isArray(e.skills),`list of skills`);a(n.skills??null),s(null)}).catch(n=>{if(!t)return;let r=n.httpStatus,i=n.detail;d.ui.warn(`Could not list the skills of session=${e}`,n),a(void 0),s({notRunning:r===409,text:i||(n instanceof Error?n.message:String(n))})}),()=>{t=!1}},[e]);return(0,Y.useEffect)(c,[c,r]),AD(t,c),o?.notRunning?P(`p`,{className:`sp-meta`,role:`status`,children:n(`skills.notRunning`)}):o?P(`p`,{className:`sp-error`,children:n(`skills.listError`,{error:o.text})}):i===void 0?P(`p`,{className:`sp-meta`,children:n(`sp.checking`)}):i===null?P(`p`,{className:`sp-meta`,children:n(`skills.notReported`)}):i.length===0?P(`p`,{className:`sp-meta`,children:n(`skills.empty`)}):P(`ul`,{className:`sp-list`,"aria-label":n(`skills.listLabel`),children:i.map(e=>V(`li`,{className:`sp-tool sp-skill`,children:[V(`span`,{className:`sp-skill-name`,children:[P(no,{size:12,"aria-hidden":`true`}),P(`code`,{className:`sp-item-name`,dir:`ltr`,children:e.name})]}),P(`span`,{className:`sp-meta`,children:n(bO[e.how]??`skills.how.always`)})]},e.name))})}var CO=`(max-width: 1099px)`,wO=16;function TO({sessionId:e,messages:t,busy:n,onUsage:r,onJumpToMessage:i}){let a=T(),o=Bc(CO),s=hD(e=>o?e.overlayOpen:e.open),c=hD(e=>e.width),l=hD(e=>e.setWidth),u=hD(e=>e.setOpen),d=hD(e=>e.setOverlayOpen),f=hD(e=>e.focus),p=(0,Y.useRef)(null),[m,h]=(0,Y.useState)(null),g=(0,Y.useCallback)(()=>{o?d(!1):u(!1)},[o,u,d]);Lo(s&&o,g);let _=(0,Y.useRef)(null);sS(_,s&&o),(0,Y.useEffect)(()=>{s&&o&&p.current?.focus()},[s,o]),(0,Y.useEffect)(()=>{f&&o&&d(!0)},[f,o,d]);let v=(0,Y.useCallback)(e=>{if(e.button!==0)return;e.preventDefault();let t=e.clientX,n=c,r=e.currentTarget;r.setPointerCapture?.(e.pointerId);let i=getComputedStyle(r).direction===`rtl`?-1:1,a=n,o=e=>{a=pD(n+i*(t-e.clientX)),h(a)},s=()=>{r.removeEventListener(`pointermove`,o),r.removeEventListener(`pointerup`,s),r.removeEventListener(`pointercancel`,s),h(null),l(a)};r.addEventListener(`pointermove`,o),r.addEventListener(`pointerup`,s),r.addEventListener(`pointercancel`,s)},[l,c]),y=(0,Y.useCallback)(e=>{let t=getComputedStyle(e.currentTarget).direction===`rtl`?-16:wO,n={ArrowLeft:c+t,ArrowRight:c-t,Home:280,End:640}[e.key];n!==void 0&&(e.preventDefault(),l(n))},[l,c]);if(!s)return null;let b=m??c,x=gD(t,n);return V(D.Fragment,{children:[o&&P(`div`,{className:`sp-backdrop`,onClick:g,"aria-hidden":`true`}),V(`aside`,{ref:_,className:`session-panel ${o?`is-overlay`:`is-docked`}`,style:o?void 0:{width:b},"aria-label":a(`sp.label`),role:o?`dialog`:`complementary`,"aria-modal":o?!0:void 0,children:[!o&&P(`div`,{className:`sp-resize${m==null?``:` is-dragging`}`,role:`separator`,"aria-orientation":`vertical`,"aria-label":a(`sp.resize`),"aria-valuemin":280,"aria-valuemax":640,"aria-valuenow":b,tabIndex:0,onPointerDown:v,onKeyDown:y,onDoubleClick:()=>l(320)}),V(`header`,{className:`sp-header`,children:[P(`h2`,{className:`sp-title`,children:a(`sp.title`)}),P(`button`,{ref:p,type:`button`,className:`btn-icon-sm`,onClick:g,"aria-label":a(`sp.close`),title:a(`sp.closeShort`),children:P(o?J:ba,{size:14})})]}),V(`div`,{className:`sp-body`,children:[x&&P(kD,{id:`answer`,title:a(`sp.section.answer`),children:P(SD,{messages:t,busy:n})}),P(HD,{sessionId:e,busy:n}),P(kD,{id:`context`,title:a(`sp.section.context`),children:P(`div`,{className:`sp-context`,children:P(qE,{sessionId:e,busy:n,onUsage:r})})}),P(eO,{sessionId:e,busy:n,onJumpToMessage:i}),P(cO,{sessionId:e,busy:n,onJumpToMessage:i}),P(xO,{sessionId:e,busy:n}),P(vO,{sessionId:e,busy:n})]})]})]})}function EO({messages:e,busy:t}){let n=T(),r=Bc(CO),i=hD(e=>r?e.overlayOpen:e.open),a=hD(e=>e.setOpen),o=hD(e=>e.setOverlayOpen),s=gD(e,t),c=!i&&s?.kind===`turn`&&s.turn.turnSummary?_D(s.turn.turnSummary):!1,l=n(i?`sp.hide`:c?`sp.showWarn`:`sp.show`);return P(`button`,{type:`button`,className:`btn-icon-sm sp-toggle${i?` active`:``}${c?` is-warn`:``}`,onClick:()=>r?o(!i):a(!i),"aria-label":l,"aria-pressed":i,title:l,children:P(c?q:i?ba:Sa,{size:15})})}function DO({isPrivate:e,onToggle:t}){return P(`button`,{className:`btn-icon-sm task-header-private`,onClick:t,title:e?`Turn off private chat. This chat isn't saved to memory.`:`Turn on private chat. It won't be saved to memory.`,"aria-label":e?`Turn off private chat`:`Turn on private chat`,"data-private":e?`true`:void 0,children:P(e?ti:ri,{size:15})})}function OO({sessionId:e}){let t=k(t=>t.sessions.find(t=>t.id===e)),n=k(e=>e.documents),r=k(e=>e.setShowDocLibrary),i=k(e=>e.updateSessionInList),[a,o]=(0,Y.useState)(!1),s=new Set(t?.document_ids??[]),c=n.filter(e=>s.has(e.id)),l=(0,Y.useCallback)(async(t,r)=>{t.stopPropagation();let a=n.find(e=>e.id===r);d.doc.info(`Detaching document from session: ${a?.filename||r}`);try{await kn(e,r);let t=(k.getState().sessions.find(t=>t.id===e)?.document_ids??[]).filter(e=>e!==r);i(e,{document_ids:t}),t.length<=3&&o(!1),d.doc.info(`Detached document from session: ${a?.filename||r}`)}catch(e){d.doc.error(`Failed to detach document: ${a?.filename||r}`,e)}},[n,e,i]);if(c.length===0)return null;let u=[...c].sort((e,t)=>{let n=e.last_accessed_at||e.indexed_at||``;return(t.last_accessed_at||t.indexed_at||``).localeCompare(n)}),f=a?u:u.slice(0,3),p=u.length-3;return V(`div`,{className:`doc-context-bar${a?` doc-context-expanded`:``}`,"aria-label":`${c.length} indexed document${c.length===1?``:`s`}`,children:[P(kr,{size:12,className:`doc-context-icon`,"aria-hidden":`true`}),V(`button`,{type:`button`,className:`doc-context-label`,onClick:()=>r(!0),title:`Manage documents`,children:[c.length,` indexed`]}),V(`div`,{className:`doc-context-pills${a?` doc-context-pills-expanded`:``}`,children:[f.map(e=>V(`span`,{className:`doc-pill`,title:e.filepath||e.filename,children:[P(_i,{size:9,className:`doc-pill-icon`,"aria-hidden":`true`}),P(`span`,{className:`doc-pill-name`,dir:`auto`,children:e.filename}),P(`button`,{className:`doc-pill-remove`,onClick:t=>l(t,e.id),"aria-label":`Remove ${e.filename} from this chat`,children:P(J,{size:10})})]},e.id)),!a&&p>0&&V(`button`,{className:`doc-pill-more`,onClick:e=>{e.stopPropagation(),o(!0)},children:[`+`,p,` more`]}),a&&p>0&&P(`button`,{className:`doc-pill-collapse`,onClick:e=>{e.stopPropagation(),o(!1)},children:`show less`})]})]})}var kO=5e3;function AO(e){let[t,n]=(0,Y.useState)({usage:null,error:null});return(0,Y.useEffect)(()=>{if(!e)return;let t,r=null,i=!1,a=e=>{i||document.hidden||(t=setTimeout(o,e))};async function o(){r=new AbortController;try{let e=await dn(r.signal);if(i)return;n({usage:e,error:null}),a(e.interval_ms)}catch(e){if(i||r.signal.aborted)return;d.ui.warn(`Could not read resource usage`,e),n(t=>({usage:t.usage,error:e instanceof Error?e.message:String(e)})),a(kO)}}let s=()=>{document.hidden?(clearTimeout(t),r?.abort()):(clearTimeout(t),o())};return o(),document.addEventListener(`visibilitychange`,s),()=>{i=!0,clearTimeout(t),r?.abort(),document.removeEventListener(`visibilitychange`,s)}},[e]),e?t:{usage:null,error:null}}var jO=1024**3;function MO(e){return(e/jO).toFixed(1)}function NO(e){return`${Math.round(e)}%`}var PO=[[1e9,`Gbps`],[1e6,`Mbps`],[1e3,`Kbps`]];function FO(e){return PO.find(([t])=>e>=t)??PO[PO.length-1]}function IO(e,[t]){let n=e/t;return n<.05?`0`:n>=100?n.toFixed(0):n.toFixed(1)}function LO(e){let t=Math.max(1e5,...e),n=10**Math.floor(Math.log10(t));return[1,2,5,10].find(e=>t<=e*n)*n}function RO(e,t){let n=e.slice(-60),r=60-n.length;return n.map((e,n)=>[(r+n)/59*100,98-Math.max(0,Math.min(t,e))/t*96])}function zO(e){return e.map(([e,t],n)=>`${n?`L`:`M`}${e.toFixed(2)} ${t.toFixed(2)}`).join(` `)}function BO({values:e,max:t=100,dashed:n}){let r=RO(e,t),i=zO(r),a=r.length>1?`${i} L100 100 L${r[0][0].toFixed(2)} 100 Z`:``,o=n?RO(n,t):[];return V(`svg`,{className:`resource-spark`,viewBox:`0 0 100 100`,preserveAspectRatio:`none`,"aria-hidden":`true`,children:[P(`path`,{className:`resource-spark-grid`,d:`M0 25H100M0 50H100M0 75H100M25 0V100M50 0V100M75 0V100`,vectorEffect:`non-scaling-stroke`}),a&&P(`path`,{className:`resource-spark-area`,d:a}),r.length>1&&P(`path`,{className:`resource-spark-line`,d:i,vectorEffect:`non-scaling-stroke`}),o.length>1&&P(`path`,{className:`resource-spark-line is-dashed`,d:zO(o),vectorEffect:`non-scaling-stroke`})]})}var VO={gpu:`resources.gpu`,npu:`resources.npu`,ethernet:`resources.ethernet`,wifi:`resources.wifi`,network:`resources.network`};function HO(e,t,n){let r=e(VO[t.kind]),i=n.filter(e=>e.kind===t.kind);return i.length>1?e(`resources.numbered`,{label:r,n:i.indexOf(t)}):r}function UO(e){let t=FO(e);return`${IO(e,t)} ${t[1]}`}function WO(e,t,n,r){return{key:`${t}-unavailable`,tone:t,label:n,value:``,detail:e(`resources.unavailable`),title:e(`resources.unavailableWhy`,{label:n,reason:r}),history:[]}}function GO(e,t){let n=[];if(t.cpu){let r=t.cpu.ghz==null?void 0:`${t.cpu.ghz.toFixed(2)} GHz`;n.push({key:`cpu`,tone:`cpu`,label:e(`resources.cpu`),value:NO(t.cpu.percent),detail:r,title:[e(`resources.cpu`),NO(t.cpu.percent),r].filter(Boolean).join(` · `),history:t.cpu.history})}if(t.memory){let r=t.memory,i=`${MO(r.used_bytes)}/${MO(r.total_bytes)} GB`;n.push({key:`memory`,tone:`memory`,label:e(`resources.memory`),value:NO(r.percent),detail:i,title:`${e(`resources.memory`)} · ${i} (${NO(r.percent)})`,history:r.history})}let r=t.devices??[];for(let t of r){let i=t.memory_used_bytes==null?void 0:`${MO(t.memory_used_bytes)} GB`;n.push({key:t.id,tone:t.kind,label:HO(e,t,r),value:NO(t.percent),detail:i,name:t.name,title:[t.name,NO(t.percent),i&&e(`resources.inUse`,{size:i})].filter(Boolean).join(` · `),history:t.history})}t.devices_error&&n.push(WO(e,`gpu`,e(`resources.gpu`),t.devices_error));let i=t.networks??[];for(let t of i){let r=FO(Math.max(t.send_bps,t.recv_bps)),a=IO(t.send_bps,r),o=IO(t.recv_bps,r);n.push({key:t.id,tone:`network`,label:HO(e,t,i),value:``,detail:`${e(`resources.sendRecv`,{send:a,recv:o})} ${r[1]}`,name:t.name,title:[t.name,t.description,e(`resources.send`,{rate:UO(t.send_bps)}),e(`resources.receive`,{rate:UO(t.recv_bps)})].join(` · `),history:t.recv_history,dashed:t.send_history,max:LO([...t.recv_history,...t.send_history])})}return t.networks_error&&n.push(WO(e,`network`,e(`resources.network`),t.networks_error)),n}function KO({onClose:e}){let t=T(),{usage:n,error:r}=AO(!0),i=n?.ready?GO(t,n):[];return V(`section`,{className:`resource-strip`,"aria-label":t(`resources.region`),children:[i.length>0?P(`ul`,{className:`resource-tiles${r?` is-stale`:``}`,children:i.map(e=>V(`li`,{className:`resource-tile tone-${e.tone}`,title:e.title,children:[P(BO,{values:e.history,max:e.max,dashed:e.dashed}),V(`span`,{className:`resource-text`,children:[V(`span`,{className:`resource-label`,children:[e.label,e.name&&P(`span`,{className:`resource-sr-only`,children:` (${e.name})`})]}),V(`span`,{className:`resource-reading`,children:[e.value&&P(`bdi`,{dir:`ltr`,className:`resource-value`,children:e.value}),e.detail&&P(`bdi`,{dir:`ltr`,className:`resource-detail`,children:e.detail})]})]})]},e.key))}):P(`p`,{className:`resource-status`,role:`status`,children:t(r?`resources.error`:`resources.reading`)}),r&&i.length>0&&P(`p`,{className:`resource-status is-error`,role:`status`,title:r,children:t(`resources.error`)}),P(`button`,{type:`button`,className:`btn-icon-sm resource-close`,onClick:e,"aria-label":t(`resources.hide`),title:t(`resources.hide`),children:P(J,{size:14,"aria-hidden":`true`})})]})}function qO({sessionId:e}){let t=T(),{env:n,change:r}=_E(e),[i,a]=(0,Y.useState)(null);return!n||n.internet?null:V(`div`,{className:`offline-notice`,role:`status`,children:[P(bo,{size:13,"aria-hidden":`true`}),V(`span`,{children:[t(`offline.text`),i&&V(`span`,{className:`offline-notice-error`,children:[` `,t(`offline.error`,{error:i})]})]}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>{a(null),r(()=>ye(e,!0)).catch(e=>{a(e instanceof bn?e.detail||e.message:String(e))})},children:t(`offline.turnOn`)})]})}function JO({message:e,onDismiss:t}){return e?V(`div`,{className:`export-error-bar`,role:`alert`,children:[P(`span`,{children:e}),P(`button`,{type:`button`,className:`btn-icon-sm`,onClick:t,"aria-label":`Dismiss export error`,children:P(J,{size:13})})]}):null}var YO=`gaia.resourceMonitor.visible`;function XO(){try{return window.localStorage.getItem(YO)!==`0`}catch(e){return d.ui.warn(`Resource usage setting unavailable; showing it`,e),!0}}var ZO=p(e=>({visible:XO(),setVisible:t=>{try{window.localStorage.setItem(YO,t?`1`:`0`)}catch(e){d.ui.warn(`Could not remember the resource usage setting`,e)}e({visible:t})},reload:()=>e({visible:XO()})}));function QO(){return`screenshot-${new Date().toISOString().slice(0,19).replace(/[T:]/g,`-`)}.png`}function $O(){let e=T(),[t,n]=(0,Y.useState)([]),r=(0,Y.useRef)(!0),i=(0,Y.useRef)(new Map);(0,Y.useEffect)(()=>(r.current=!0,()=>{r.current=!1}),[]);let a=(0,Y.useCallback)(async e=>{let t=new AbortController;i.current.set(e.id,t);try{let i=e.isMedia?await yt(e.file,t=>{r.current&&n(n=>n.map(n=>n.id===e.id?{...n,progress:t}:n))},t.signal):await mt(e.file);if(!r.current)return;n(t=>t.map(t=>t.id===e.id?{...t,uploading:!1,uploaded:!0,serverUrl:i.url}:t))}catch(i){if(t.signal.aborted||(d.chat.error(`Upload failed: ${e.name}`,i),!r.current))return;let a=i instanceof Error?i.message:`Upload failed`;n(t=>t.map(t=>t.id===e.id?{...t,uploading:!1,error:a}:t))}finally{i.current.delete(e.id)}},[]),o=(0,Y.useCallback)(e=>{for(let t of e){let e=t.type.startsWith(`image/`),r={id:`attach-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,file:t,name:t.name||(e?QO():`file`),url:e?URL.createObjectURL(t):``,uploading:!0,uploaded:!1,isImage:e,isMedia:jT(t.name)};n(e=>[...e,r]),a(r)}},[a]),s=(0,Y.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>e!==null);return t.length!==0&&(e.preventDefault(),o(t),!0)},[o]),c=(0,Y.useCallback)(e=>{i.current.get(e)?.abort(),n(t=>{let n=t.find(t=>t.id===e);return n?.url&&URL.revokeObjectURL(n.url),t.filter(t=>t.id!==e)})},[]),l=(0,Y.useCallback)(()=>{n(e=>(e.forEach(e=>{e.url&&URL.revokeObjectURL(e.url)}),[]))},[]),u=(0,Y.useCallback)(n=>{let r=t.filter(e=>e.uploaded&&e.serverUrl).map(e=>{let t=e.name.replace(/[[\]]/g,` `).trim();return e.isImage?``:`[${t}](${e.serverUrl})`}).join(`
|
|
67
|
+
`,1)[0].trim()}function vO({sessionId:e,busy:t}){let n=T();return P(kD,{id:`tools`,title:n(`tools.title`),children:P(yO,{sessionId:e,busy:t})})}function yO({sessionId:e,busy:t}){let n=T(),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(null),s=(0,Y.useCallback)(()=>{let t=!0;return Promise.resolve().then(()=>Ie(e)).then(e=>{t&&(i(lE(e,e=>Array.isArray(e.tools),`list of tools`).tools),o(null))}).catch(n=>{if(!t)return;let r=n.httpStatus,a=n.detail;d.ui.warn(`Could not list the tools of session=${e}`,n),i(null),o({notRunning:r===409,text:a||Fx(n)})}),()=>{t=!1}},[e]);return(0,Y.useEffect)(s,[s]),AD(t,s),a?.notRunning?P(`p`,{className:`sp-meta`,role:`status`,children:n(`tools.notRunning`)}):a?P(`p`,{className:`sp-error`,role:`alert`,children:n(`tools.listError`,{error:a.text})}):r?r.length===0?P(`p`,{className:`sp-meta`,children:n(`tools.empty`)}):P(`div`,{className:`sp-tools`,"aria-label":n(`tools.listLabel`),role:`group`,children:gO(r).map(([e,t])=>{let r=hO(e,n);return V(`section`,{className:`sp-tool-group`,"aria-label":r,children:[V(`h4`,{className:`sp-tool-group-title`,children:[r,` `,P(`span`,{className:`sp-meta`,children:t.length})]}),P(`ul`,{className:`sp-list`,children:t.map(e=>V(`li`,{className:`sp-tool`,children:[P(`code`,{className:`sp-item-name`,dir:`ltr`,children:e.name}),e.description&&P(`span`,{className:`sp-meta`,title:e.description,children:_O(e.description)})]},e.name))})]},e)})}):P(`p`,{className:`sp-meta`,children:n(`sp.checking`)})}var bO={model:`skills.how.model`,auto:`skills.how.auto`,always:`skills.how.always`};function xO({sessionId:e,busy:t}){let n=T();return P(kD,{id:`skills`,title:n(`skills.title`),children:P(SO,{sessionId:e,busy:t})})}function SO({sessionId:e,busy:t}){let n=T(),r=k(e=>e.skillUses),[i,a]=(0,Y.useState)(void 0),[o,s]=(0,Y.useState)(null),c=(0,Y.useCallback)(()=>{let t=!0;return Promise.resolve().then(()=>Ie(e)).then(e=>{if(!t)return;let n=lE(e,e=>e.skills===null||Array.isArray(e.skills),`list of skills`);a(n.skills??null),s(null)}).catch(n=>{if(!t)return;let r=n.httpStatus,i=n.detail;d.ui.warn(`Could not list the skills of session=${e}`,n),a(void 0),s({notRunning:r===409,text:i||(n instanceof Error?n.message:String(n))})}),()=>{t=!1}},[e]);return(0,Y.useEffect)(c,[c,r]),AD(t,c),o?.notRunning?P(`p`,{className:`sp-meta`,role:`status`,children:n(`skills.notRunning`)}):o?P(`p`,{className:`sp-error`,children:n(`skills.listError`,{error:o.text})}):i===void 0?P(`p`,{className:`sp-meta`,children:n(`sp.checking`)}):i===null?P(`p`,{className:`sp-meta`,children:n(`skills.notReported`)}):i.length===0?P(`p`,{className:`sp-meta`,children:n(`skills.empty`)}):P(`ul`,{className:`sp-list`,"aria-label":n(`skills.listLabel`),children:i.map(e=>V(`li`,{className:`sp-tool sp-skill`,children:[V(`span`,{className:`sp-skill-name`,children:[P(no,{size:12,"aria-hidden":`true`}),P(`code`,{className:`sp-item-name`,dir:`ltr`,children:e.name})]}),P(`span`,{className:`sp-meta`,children:n(bO[e.how]??`skills.how.always`)})]},e.name))})}var CO=`(max-width: 1099px)`,wO=16;function TO({sessionId:e,messages:t,busy:n,onUsage:r,onJumpToMessage:i}){let a=T(),o=Bc(CO),s=hD(e=>o?e.overlayOpen:e.open),c=hD(e=>e.width),l=hD(e=>e.setWidth),u=hD(e=>e.setOpen),d=hD(e=>e.setOverlayOpen),f=hD(e=>e.focus),p=(0,Y.useRef)(null),[m,h]=(0,Y.useState)(null),g=(0,Y.useCallback)(()=>{o?d(!1):u(!1)},[o,u,d]);Lo(s&&o,g);let _=(0,Y.useRef)(null);sS(_,s&&o),(0,Y.useEffect)(()=>{s&&o&&p.current?.focus()},[s,o]),(0,Y.useEffect)(()=>{f&&o&&d(!0)},[f,o,d]);let v=(0,Y.useCallback)(e=>{if(e.button!==0)return;e.preventDefault();let t=e.clientX,n=c,r=e.currentTarget;r.setPointerCapture?.(e.pointerId);let i=getComputedStyle(r).direction===`rtl`?-1:1,a=n,o=e=>{a=pD(n+i*(t-e.clientX)),h(a)},s=()=>{r.removeEventListener(`pointermove`,o),r.removeEventListener(`pointerup`,s),r.removeEventListener(`pointercancel`,s),h(null),l(a)};r.addEventListener(`pointermove`,o),r.addEventListener(`pointerup`,s),r.addEventListener(`pointercancel`,s)},[l,c]),y=(0,Y.useCallback)(e=>{let t=getComputedStyle(e.currentTarget).direction===`rtl`?-16:wO,n={ArrowLeft:c+t,ArrowRight:c-t,Home:280,End:640}[e.key];n!==void 0&&(e.preventDefault(),l(n))},[l,c]);if(!s)return null;let b=m??c,x=gD(t,n);return V(D.Fragment,{children:[o&&P(`div`,{className:`sp-backdrop`,onClick:g,"aria-hidden":`true`}),V(`aside`,{ref:_,className:`session-panel ${o?`is-overlay`:`is-docked`}`,style:o?void 0:{width:b},"aria-label":a(`sp.label`),role:o?`dialog`:`complementary`,"aria-modal":o?!0:void 0,children:[!o&&P(`div`,{className:`sp-resize${m==null?``:` is-dragging`}`,role:`separator`,"aria-orientation":`vertical`,"aria-label":a(`sp.resize`),"aria-valuemin":280,"aria-valuemax":640,"aria-valuenow":b,tabIndex:0,onPointerDown:v,onKeyDown:y,onDoubleClick:()=>l(320)}),V(`header`,{className:`sp-header`,children:[P(`h2`,{className:`sp-title`,children:a(`sp.title`)}),P(`button`,{ref:p,type:`button`,className:`btn-icon-sm`,onClick:g,"aria-label":a(`sp.close`),title:a(`sp.closeShort`),children:P(o?J:ba,{size:14})})]}),V(`div`,{className:`sp-body`,children:[x&&P(kD,{id:`answer`,title:a(`sp.section.answer`),children:P(SD,{messages:t,busy:n})}),P(HD,{sessionId:e,busy:n}),P(kD,{id:`context`,title:a(`sp.section.context`),children:P(`div`,{className:`sp-context`,children:P(qE,{sessionId:e,busy:n,onUsage:r})})}),P(eO,{sessionId:e,busy:n,onJumpToMessage:i}),P(cO,{sessionId:e,busy:n,onJumpToMessage:i}),P(xO,{sessionId:e,busy:n}),P(vO,{sessionId:e,busy:n})]})]})]})}function EO({messages:e,busy:t}){let n=T(),r=Bc(CO),i=hD(e=>r?e.overlayOpen:e.open),a=hD(e=>e.setOpen),o=hD(e=>e.setOverlayOpen),s=gD(e,t),c=!i&&s?.kind===`turn`&&s.turn.turnSummary?_D(s.turn.turnSummary):!1,l=n(i?`sp.hide`:c?`sp.showWarn`:`sp.show`);return P(`button`,{type:`button`,className:`btn-icon-sm sp-toggle${i?` active`:``}${c?` is-warn`:``}`,onClick:()=>r?o(!i):a(!i),"aria-label":l,"aria-pressed":i,title:l,children:P(c?q:i?ba:Sa,{size:15})})}function DO({isPrivate:e,onToggle:t}){return P(`button`,{className:`btn-icon-sm task-header-private`,onClick:t,title:e?`Turn off private chat. This chat isn't saved to memory.`:`Turn on private chat. It won't be saved to memory.`,"aria-label":e?`Turn off private chat`:`Turn on private chat`,"data-private":e?`true`:void 0,children:P(e?ti:ri,{size:15})})}function OO({sessionId:e}){let t=k(t=>t.sessions.find(t=>t.id===e)),n=k(e=>e.documents),r=k(e=>e.setShowDocLibrary),i=k(e=>e.updateSessionInList),[a,o]=(0,Y.useState)(!1),s=new Set(t?.document_ids??[]),c=n.filter(e=>s.has(e.id)),l=(0,Y.useCallback)(async(t,r)=>{t.stopPropagation();let a=n.find(e=>e.id===r);d.doc.info(`Detaching document from session: ${a?.filename||r}`);try{await kn(e,r);let t=(k.getState().sessions.find(t=>t.id===e)?.document_ids??[]).filter(e=>e!==r);i(e,{document_ids:t}),t.length<=3&&o(!1),d.doc.info(`Detached document from session: ${a?.filename||r}`)}catch(e){d.doc.error(`Failed to detach document: ${a?.filename||r}`,e)}},[n,e,i]);if(c.length===0)return null;let u=[...c].sort((e,t)=>{let n=e.last_accessed_at||e.indexed_at||``;return(t.last_accessed_at||t.indexed_at||``).localeCompare(n)}),f=a?u:u.slice(0,3),p=u.length-3;return V(`div`,{className:`doc-context-bar${a?` doc-context-expanded`:``}`,"aria-label":`${c.length} indexed document${c.length===1?``:`s`}`,children:[P(kr,{size:12,className:`doc-context-icon`,"aria-hidden":`true`}),V(`button`,{type:`button`,className:`doc-context-label`,onClick:()=>r(!0),title:`Manage documents`,children:[c.length,` indexed`]}),V(`div`,{className:`doc-context-pills${a?` doc-context-pills-expanded`:``}`,children:[f.map(e=>V(`span`,{className:`doc-pill`,title:e.filepath||e.filename,children:[P(_i,{size:9,className:`doc-pill-icon`,"aria-hidden":`true`}),P(`span`,{className:`doc-pill-name`,dir:`auto`,children:e.filename}),P(`button`,{className:`doc-pill-remove`,onClick:t=>l(t,e.id),"aria-label":`Remove ${e.filename} from this chat`,children:P(J,{size:10})})]},e.id)),!a&&p>0&&V(`button`,{className:`doc-pill-more`,onClick:e=>{e.stopPropagation(),o(!0)},children:[`+`,p,` more`]}),a&&p>0&&P(`button`,{className:`doc-pill-collapse`,onClick:e=>{e.stopPropagation(),o(!1)},children:`show less`})]})]})}var kO=5e3;function AO(e){let[t,n]=(0,Y.useState)({usage:null,error:null});return(0,Y.useEffect)(()=>{if(!e)return;let t,r=null,i=!1,a=e=>{i||document.hidden||(t=setTimeout(o,e))};async function o(){r=new AbortController;try{let e=await dn(r.signal);if(i)return;n({usage:e,error:null}),a(e.interval_ms)}catch(e){if(i||r.signal.aborted)return;d.ui.warn(`Could not read resource usage`,e),n(t=>({usage:t.usage,error:e instanceof Error?e.message:String(e)})),a(kO)}}let s=()=>{document.hidden?(clearTimeout(t),r?.abort()):(clearTimeout(t),o())};return o(),document.addEventListener(`visibilitychange`,s),()=>{i=!0,clearTimeout(t),r?.abort(),document.removeEventListener(`visibilitychange`,s)}},[e]),e?t:{usage:null,error:null}}var jO=1024**3;function MO(e){return(e/jO).toFixed(1)}function NO(e){return`${Math.round(e)}%`}var PO=[[1e9,`Gbps`],[1e6,`Mbps`],[1e3,`Kbps`]];function FO(e){return PO.find(([t])=>e>=t)??PO[PO.length-1]}function IO(e,[t]){let n=e/t;return n<.05?`0`:n>=100?n.toFixed(0):n.toFixed(1)}function LO(e){let t=Math.max(1e5,...e),n=10**Math.floor(Math.log10(t));return[1,2,5,10].find(e=>t<=e*n)*n}function RO(e,t){let n=e.slice(-60),r=60-n.length;return n.map((e,n)=>[(r+n)/59*100,98-Math.max(0,Math.min(t,e))/t*96])}function zO(e){return e.map(([e,t],n)=>`${n?`L`:`M`}${e.toFixed(2)} ${t.toFixed(2)}`).join(` `)}function BO({values:e,max:t=100,dashed:n}){let r=RO(e,t),i=zO(r),a=r.length>1?`${i} L100 100 L${r[0][0].toFixed(2)} 100 Z`:``,o=n?RO(n,t):[];return V(`svg`,{className:`resource-spark`,viewBox:`0 0 100 100`,preserveAspectRatio:`none`,"aria-hidden":`true`,children:[P(`path`,{className:`resource-spark-grid`,d:`M0 25H100M0 50H100M0 75H100M25 0V100M50 0V100M75 0V100`,vectorEffect:`non-scaling-stroke`}),a&&P(`path`,{className:`resource-spark-area`,d:a}),r.length>1&&P(`path`,{className:`resource-spark-line`,d:i,vectorEffect:`non-scaling-stroke`}),o.length>1&&P(`path`,{className:`resource-spark-line is-dashed`,d:zO(o),vectorEffect:`non-scaling-stroke`})]})}var VO={gpu:`resources.gpu`,npu:`resources.npu`,ethernet:`resources.ethernet`,wifi:`resources.wifi`,network:`resources.network`};function HO(e,t,n){let r=e(VO[t.kind]),i=n.filter(e=>e.kind===t.kind);return i.length>1?e(`resources.numbered`,{label:r,n:i.indexOf(t)}):r}function UO(e){let t=FO(e);return`${IO(e,t)} ${t[1]}`}function WO(e,t,n,r){return{key:`${t}-unavailable`,tone:t,label:n,value:``,detail:e(`resources.unavailable`),title:e(`resources.unavailableWhy`,{label:n,reason:r}),history:[]}}function GO(e,t){let n=[];if(t.cpu){let r=t.cpu.ghz==null?void 0:`${t.cpu.ghz.toFixed(2)} GHz`;n.push({key:`cpu`,tone:`cpu`,label:e(`resources.cpu`),value:NO(t.cpu.percent),detail:r,title:[e(`resources.cpu`),NO(t.cpu.percent),r].filter(Boolean).join(` · `),history:t.cpu.history})}if(t.memory){let r=t.memory,i=`${MO(r.used_bytes)}/${MO(r.total_bytes)} GB`;n.push({key:`memory`,tone:`memory`,label:e(`resources.memory`),value:NO(r.percent),detail:i,title:`${e(`resources.memory`)} · ${i} (${NO(r.percent)})`,history:r.history})}let r=t.devices??[];for(let t of r){let i=t.memory_used_bytes==null?void 0:`${MO(t.memory_used_bytes)} GB`;n.push({key:t.id,tone:t.kind,label:HO(e,t,r),value:NO(t.percent),detail:i,name:t.name,title:[t.name,NO(t.percent),i&&e(`resources.inUse`,{size:i})].filter(Boolean).join(` · `),history:t.history})}t.devices_error&&n.push(WO(e,`gpu`,e(`resources.gpu`),t.devices_error)),t.npus_error&&n.push(WO(e,`npu`,e(`resources.npu`),t.npus_error));let i=t.networks??[];for(let t of i){let r=FO(Math.max(t.send_bps,t.recv_bps)),a=IO(t.send_bps,r),o=IO(t.recv_bps,r);n.push({key:t.id,tone:`network`,label:HO(e,t,i),value:``,detail:`${e(`resources.sendRecv`,{send:a,recv:o})} ${r[1]}`,name:t.name,title:[t.name,t.description,e(`resources.send`,{rate:UO(t.send_bps)}),e(`resources.receive`,{rate:UO(t.recv_bps)})].join(` · `),history:t.recv_history,dashed:t.send_history,max:LO([...t.recv_history,...t.send_history])})}return t.networks_error&&n.push(WO(e,`network`,e(`resources.network`),t.networks_error)),n}function KO({onClose:e}){let t=T(),{usage:n,error:r}=AO(!0),i=n?.ready?GO(t,n):[];return V(`section`,{className:`resource-strip`,"aria-label":t(`resources.region`),children:[i.length>0?P(`ul`,{className:`resource-tiles${r?` is-stale`:``}`,children:i.map(e=>V(`li`,{className:`resource-tile tone-${e.tone}`,title:e.title,children:[P(BO,{values:e.history,max:e.max,dashed:e.dashed}),V(`span`,{className:`resource-text`,children:[V(`span`,{className:`resource-label`,children:[e.label,e.name&&P(`span`,{className:`resource-sr-only`,children:` (${e.name})`})]}),V(`span`,{className:`resource-reading`,children:[e.value&&P(`bdi`,{dir:`ltr`,className:`resource-value`,children:e.value}),e.detail&&P(`bdi`,{dir:`ltr`,className:`resource-detail`,children:e.detail})]})]})]},e.key))}):P(`p`,{className:`resource-status`,role:`status`,children:t(r?`resources.error`:`resources.reading`)}),r&&i.length>0&&P(`p`,{className:`resource-status is-error`,role:`status`,title:r,children:t(`resources.error`)}),P(`button`,{type:`button`,className:`btn-icon-sm resource-close`,onClick:e,"aria-label":t(`resources.hide`),title:t(`resources.hide`),children:P(J,{size:14,"aria-hidden":`true`})})]})}function qO({sessionId:e}){let t=T(),{env:n,change:r}=_E(e),[i,a]=(0,Y.useState)(null);return!n||n.internet?null:V(`div`,{className:`offline-notice`,role:`status`,children:[P(bo,{size:13,"aria-hidden":`true`}),V(`span`,{children:[t(`offline.text`),i&&V(`span`,{className:`offline-notice-error`,children:[` `,t(`offline.error`,{error:i})]})]}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>{a(null),r(()=>ye(e,!0)).catch(e=>{a(e instanceof bn?e.detail||e.message:String(e))})},children:t(`offline.turnOn`)})]})}function JO({message:e,onDismiss:t}){return e?V(`div`,{className:`export-error-bar`,role:`alert`,children:[P(`span`,{children:e}),P(`button`,{type:`button`,className:`btn-icon-sm`,onClick:t,"aria-label":`Dismiss export error`,children:P(J,{size:13})})]}):null}var YO=`gaia.resourceMonitor.visible`;function XO(){try{return window.localStorage.getItem(YO)!==`0`}catch(e){return d.ui.warn(`Resource usage setting unavailable; showing it`,e),!0}}var ZO=p(e=>({visible:XO(),setVisible:t=>{try{window.localStorage.setItem(YO,t?`1`:`0`)}catch(e){d.ui.warn(`Could not remember the resource usage setting`,e)}e({visible:t})},reload:()=>e({visible:XO()})}));function QO(){return`screenshot-${new Date().toISOString().slice(0,19).replace(/[T:]/g,`-`)}.png`}function $O(){let e=T(),[t,n]=(0,Y.useState)([]),r=(0,Y.useRef)(!0),i=(0,Y.useRef)(new Map);(0,Y.useEffect)(()=>(r.current=!0,()=>{r.current=!1}),[]);let a=(0,Y.useCallback)(async e=>{let t=new AbortController;i.current.set(e.id,t);try{let i=e.isMedia?await yt(e.file,t=>{r.current&&n(n=>n.map(n=>n.id===e.id?{...n,progress:t}:n))},t.signal):await mt(e.file);if(!r.current)return;n(t=>t.map(t=>t.id===e.id?{...t,uploading:!1,uploaded:!0,serverUrl:i.url}:t))}catch(i){if(t.signal.aborted||(d.chat.error(`Upload failed: ${e.name}`,i),!r.current))return;let a=i instanceof Error?i.message:`Upload failed`;n(t=>t.map(t=>t.id===e.id?{...t,uploading:!1,error:a}:t))}finally{i.current.delete(e.id)}},[]),o=(0,Y.useCallback)(e=>{for(let t of e){let e=t.type.startsWith(`image/`),r={id:`attach-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,file:t,name:t.name||(e?QO():`file`),url:e?URL.createObjectURL(t):``,uploading:!0,uploaded:!1,isImage:e,isMedia:jT(t.name)};n(e=>[...e,r]),a(r)}},[a]),s=(0,Y.useCallback)(e=>{let t=Array.from(e.clipboardData?.items??[]).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>e!==null);return t.length!==0&&(e.preventDefault(),o(t),!0)},[o]),c=(0,Y.useCallback)(e=>{i.current.get(e)?.abort(),n(t=>{let n=t.find(t=>t.id===e);return n?.url&&URL.revokeObjectURL(n.url),t.filter(t=>t.id!==e)})},[]),l=(0,Y.useCallback)(()=>{n(e=>(e.forEach(e=>{e.url&&URL.revokeObjectURL(e.url)}),[]))},[]),u=(0,Y.useCallback)(n=>{let r=t.filter(e=>e.uploaded&&e.serverUrl).map(e=>{let t=e.name.replace(/[[\]]/g,` `).trim();return e.isImage?``:`[${t}](${e.serverUrl})`}).join(`
|
|
68
68
|
`);if(!r)return n;let i=n||(t.some(e=>e.uploaded&&e.isMedia)?e(`composer.mediaPrompt`):``);return i?`${i}\n\n${r}`:r},[t,e]);return{attachments:t,addFiles:o,handlePaste:s,remove:c,clear:l,hasUploaded:t.some(e=>e.uploaded),hasImage:t.some(e=>e.uploaded&&e.isImage),uploading:t.some(e=>e.uploading),compose:u}}function ek({sessionId:e,isStreaming:t,isStale:n,setMessages:r,refreshContext:i}){let[a,o]=(0,Y.useState)(null),s=a?.state.status===`running`,c=(0,Y.useRef)(!1);c.current=s;let l=(0,Y.useRef)(a);l.current=a,(0,Y.useEffect)(()=>{o(null)},[e]);let u=(0,Y.useCallback)((r,i)=>{t||c.current||(d.chat.info(`Retrying message ${r.id} with ${i}`),o({messageId:r.id,state:{status:`running`,model:i},keeping:null}),Dt(e,r.id,i).then(e=>{n()||o(t=>t&&t.messageId===r.id?{...t,state:{status:`ready`,result:e}}:t)}).catch(e=>{d.chat.error(`Retry with ${i} failed`,e),!n()&&o(t=>t&&t.messageId===r.id?{...t,state:{status:`failed`,model:i,error:e instanceof Error?e.message:String(e)}}:t)}))},[e,t,n]),f=(0,Y.useCallback)(async t=>{if(!a)return;let{messageId:s}=a;o({...a,keeping:t});try{let a=await W(e,s,t);if(n())return;if(a.kept===`retry`){let e=a.stats;r(k.getState().messages.map(t=>t.id===s?{...t,content:a.content,stats:{...t.stats,...e,tokens_per_second:e.tokens_per_second??0,time_to_first_token:e.time_to_first_token??0,input_tokens:e.input_tokens??0,output_tokens:e.output_tokens??0,retried:!0}}:t)),i()}o(null)}catch(e){if(d.chat.error(`Could not keep the chosen answer`,e),n())return;o(t=>t&&{...t,keeping:null,state:{status:`failed`,model:t.state.status===`ready`?t.state.result.model:t.state.model,error:e instanceof Error?e.message:String(e)}})}},[a,e,r,n,i]);return{comparison:a,comparing:s,comparingRef:c,handleRetryWith:u,handleKeepAnswer:f,handleCloseComparison:(0,Y.useCallback)(()=>{a?.state.status===`ready`?f(`original`):o(null)},[a,f]),closeForNewTurn:(0,Y.useCallback)(()=>{let t=l.current;t&&(t.state.status===`ready`&&W(e,t.messageId,`original`).catch(e=>d.chat.error(`Could not close the answer comparison`,e)),o(null))},[e])}}function tk(e,t){let[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{r(null),a(null)},[e]);let o=(0,Y.useCallback)(()=>{hn(e).then(e=>{t()||(e.available?(r(e),a(null)):(r(null),a(e.reason)))}).catch(t=>d.chat.error(`Could not measure the context for session=${e}`,t))},[e,t]);return(0,Y.useEffect)(()=>{o()},[o]),{contextUsage:n,contextUnavailable:i,refreshContext:o,showContextUsage:(0,Y.useCallback)(e=>{r(e),a(null)},[])}}function nk(e,t){return(0,Y.useCallback)(n=>{let r=e.current?.querySelector(`[data-message-id="${n}"]`);if(!r)return!1;let i=r.previousElementSibling,a=i?.dataset.role===`user`?i:r;return t.current=!1,a.scrollIntoView?.({block:`start`,behavior:Mx()}),r.classList.add(`msg-jump-target`),window.setTimeout(()=>r.classList.remove(`msg-jump-target`),1600),!0},[e,t])}var rk=1,ik=80,ak=500,ok=new Set([`PageUp`,`ArrowUp`,`Home`]),sk=new Set([`PageDown`,`ArrowDown`,`End`]);function ck(e,t,n){let r=(0,Y.useRef)(0),i=(0,Y.useRef)(0),a=(0,Y.useRef)(0),o=(0,Y.useRef)(!1),s=(0,Y.useCallback)(()=>o.current||Date.now()-a.current<ak,[]),c=(0,Y.useCallback)(()=>{a.current=Date.now()},[]),l=(0,Y.useCallback)(()=>{a.current=0},[]),u=(0,Y.useCallback)(()=>{let a=e.current;if(!a)return;let o=a.scrollHeight-a.scrollTop-a.clientHeight,c=i.current,l=a.scrollTop<r.current&&s();r.current=a.scrollTop,i.current=o,o<=rk?t.current=!0:l?t.current=!1:o<=ik&&o<c&&(t.current=!0),n(o)},[e,t,n,s]),d=(0,Y.useCallback)(e=>{e.deltaY<0?c():e.deltaY>0&&l()},[c,l]),f=(0,Y.useCallback)(e=>{e.target===e.currentTarget&&(o.current=!0)},[]);return(0,Y.useEffect)(()=>{let e=()=>{o.current=!1},t=e=>{let t=e.target;t instanceof Element&&t.closest(`input, textarea, select, [contenteditable="true"]`)||(ok.has(e.key)||e.key===` `&&e.shiftKey?c():(sk.has(e.key)||e.key===` `)&&l())};return window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`keydown`,t)}},[c,l]),{userScrolling:s,clearUserScroll:l,listProps:{onScroll:u,onWheel:d,onTouchMove:c,onPointerDown:f}}}function lk(e,t){let[n,r]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{r(null)},[e]);let i=(0,Y.useCallback)(()=>r(null),[]);return{exportChat:(0,Y.useCallback)(async()=>{r(null);try{let n=await He(e),r=new Blob([n.content],{type:`text/markdown`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=`${(t||`chat`).replace(/[/\\:*?"<>|]/g,`_`).slice(0,100)}.md`,a.click(),URL.revokeObjectURL(i)}catch(e){d.chat.error(`Export failed`,e),r(e instanceof bn?`Couldn't export this chat: GAIA's backend returned an error (HTTP ${e.httpStatus}). Try Export again; if it keeps failing, check the backend log.`:`Couldn't export this chat because GAIA's backend isn't reachable. Try Export again once GAIA is answering.`)}},[e,t]),exportError:n,clearExportError:i}}var uk=5200;function dk(e=uk){let[t,n]=(0,Y.useState)(null),r=(0,Y.useRef)(null),i=(0,Y.useCallback)(()=>{r.current&&=(clearTimeout(r.current),null)},[]),a=(0,Y.useCallback)(()=>{i(),n(null)},[i]),o=(0,Y.useCallback)(t=>{i(),n(t),r.current=setTimeout(()=>{r.current=null,n(null)},e)},[i,e]);return(0,Y.useEffect)(()=>i,[i]),{policyToast:t,showPolicyToast:o,dismissPolicyToast:a}}var fk=`gaia`;function pk(e){return e.some(e=>e.id===fk)}function mk(e){let t=e;return t?.httpStatus===422&&`${typeof t.detail==`string`?t.detail:``} ${typeof t.message==`string`?t.message:``}`.includes(`Unknown agent_type '${fk}'`)}var hk=new Set([``,`new chat`,`new task`,`untitled`,`untitled session`,`chat`]);function gk(e){return hk.has((e??``).trim().toLowerCase())}function _k(e,t){let n=k.getState(),r=n.sessions.find(t=>t.id===e)?.document_ids??[],i=t.filter(e=>!r.includes(e));i.length>0&&n.updateSessionInList(e,{document_ids:[...r,...i]})}function vk(e,t){if(t.length===0)return;let n=k.getState(),r=new Set(t.map(e=>e.id));n.setDocuments([...t,...n.documents.filter(e=>!r.has(e.id))]),_k(e,t.map(e=>e.id))}async function yk(e,t){for(let n of t){d.doc.info(`Dropped on chat view: ${n.name}`);try{let t=await ke(n);if(e&&t?.id)try{await Xt(e,t.id),_k(e,[t.id]),d.doc.info(`Auto-attached "${n.name}" to session ${e}`)}catch(e){d.doc.warn(`Could not attach dropped document to session: ${e}`)}}catch(e){d.doc.error(`Upload failed: ${n.name}`,e)}}try{let e=await Ot();k.getState().setDocuments(e.documents||[])}catch(e){d.doc.error(`Could not refresh the document list after a drop`,e)}}function bk(e,t){let n=()=>typeof document<`u`&&document.visibilityState===`hidden`,r=setInterval(()=>{n()||e()},t),i=()=>{n()||e()};return document.addEventListener(`visibilitychange`,i),()=>{clearInterval(r),document.removeEventListener(`visibilitychange`,i)}}function xk(e){let t=()=>typeof document<`u`&&document.visibilityState===`hidden`,n=t()?null:e(),r=()=>{t()?(n?.(),n=null):n||=e()};return document.addEventListener(`visibilitychange`,r),()=>{document.removeEventListener(`visibilitychange`,r),n?.(),n=null}}var Sk=2e3,Ck=9e4;function wk(){let e=T(),[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(`idle`),[s,c]=(0,Y.useState)(null),l=(0,Y.useRef)(!0),u=(0,Y.useCallback)(async()=>{try{let e=await ot();return l.current&&n(e),e}catch(e){return l.current&&c(e instanceof Error?e.message:String(e)),null}},[]);(0,Y.useEffect)(()=>(l.current=!0,u(),ce().then(e=>{l.current&&i(e)}).catch(e=>{l.current&&c(e instanceof Error?e.message:String(e))}),()=>{l.current=!1}),[u]);let d=(0,Y.useCallback)(async()=>{c(null);let e=await u();e&&o(e.state===`stopped`?`still_down`:`back`)},[u]),f=(0,Y.useCallback)(async()=>{o(`starting`),c(null);try{await Ue(!1)}catch(e){if(!l.current)return;c(e instanceof Error?e.message:String(e)),o(`idle`);return}let e=Date.now()+Ck;for(;l.current&&Date.now()<e;){await new Promise(e=>setTimeout(e,Sk));let e=await u();if(!l.current)return;if(e?.restart_error){c(e.restart_error),o(`idle`);return}if(e&&e.state!==`stopped`&&!e.restarting){o(`back`);return}}l.current&&o(`still_down`)},[u]),p=(0,Y.useCallback)(async()=>{o(`switching`),c(null);try{let e=await Ee({mode:`gaia`});if(!l.current)return;i(e),o(`back`)}catch(e){if(!l.current)return;c(e instanceof Error?e.message:String(e)),o(`idle`)}},[]),m=a===`starting`||a===`switching`,h=t?.owner===`gaia`,g=!h&&r?.mode===`external`&&r.source!==`env`;return a===`back`?P(`div`,{className:`server-down-notice server-down-notice--ok`,role:`status`,children:P(`p`,{children:e(`serverDown.back`)})}):V(`div`,{className:`server-down-notice`,role:`alert`,children:[V(`strong`,{className:`server-down-notice__title`,children:[P(q,{size:14,"aria-hidden":`true`}),` `,e(`serverDown.title`)]}),P(`p`,{children:e(`serverDown.body`)}),t&&!h&&!g&&P(`p`,{children:e(`serverDown.notOurs`)}),a===`still_down`&&P(`p`,{children:e(`serverDown.stillDown`)}),s&&P(`p`,{children:P(`bdi`,{dir:`ltr`,className:`server-down-notice__raw`,children:s})}),V(`div`,{className:`server-down-notice__actions`,children:[h&&P(`button`,{type:`button`,className:`btn-primary`,disabled:m,onClick:()=>void f(),children:a===`starting`?V(D.Fragment,{children:[P(K,{size:13,className:`btn-spinner`,"aria-hidden":`true`}),` `,e(`serverDown.starting`)]}):e(`serverDown.start`)}),g&&P(`button`,{type:`button`,className:`btn-primary`,disabled:m,onClick:()=>void p(),children:a===`switching`?V(D.Fragment,{children:[P(K,{size:13,className:`btn-spinner`,"aria-hidden":`true`}),` `,e(`serverDown.switching`)]}):e(`serverDown.useOwn`)}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:m,onClick:()=>void d(),children:e(`settings.key.checkAgain`)})]})]})}function Tk(e,t=``){let[n,r]=(0,Y.useState)(()=>e&&Sn(e)||t),i=(0,Y.useRef)(e);return(0,Y.useEffect)(()=>{i.current!==e&&(i.current=e,r(e?Sn(e):``))},[e]),(0,Y.useEffect)(()=>{e&&i.current===e&&rn(e,n)},[e,n]),[n,r]}function Ek(e,t){return Tk(t?null:U(e))}var Dk=new Set([`tool_start`,`tool_end`,`tool_result`]),Ok=`Connection lost. Reconnecting`,kk=15e3,Ak=[],jk=new Map;function Mk({text:e}){return P(`div`,{className:`history-notice`,role:`note`,children:e})}function Nk({notices:e}){return P(`div`,{className:`library-notices`,role:`note`,children:e.map((e,t)=>P(`div`,{dir:`auto`,children:e},`${t}-${e}`))})}function Pk({sessionId:e}){let t=T(),{sessions:n,messages:r,setMessages:i,addMessage:o,removeMessage:s,removeMessagesFrom:c,updateSessionInList:l,isStreaming:u,streamingContent:f,setStreaming:p,setStreamContent:m,clearStreamContent:h,agentSteps:g,addAgentStep:_,updateLastAgentStep:v,appendThinkingContent:b,updateLastToolStep:x,clearAgentSteps:S,cards:C,appendCard:w,clearCards:E,setDocuments:O,setShowFileBrowser:A,isLoadingMessages:j,setLoadingMessages:M,systemStatus:N}=k(),F=$s(e=>e.addNotification),L=$s(e=>e.showPanel),R=$s(e=>e.setShowPanel),z=$s(e=>e.setTypeFilter),B=k(t=>t.pendingPrompt?.sessionId===e?t.pendingPrompt:null),te=k(e=>e.liveStatus),ne=k(pw),oe=k(e=>e.awaitingUser),H=k(t=>Object.values(t.liveQuestions).some(t=>t.sessionId===e)),U=$s(t=>nc(e)(t)!==null),W=n.find(t=>t.id===e),[G,se]=Ek(e,W?.private),[ce,le]=(0,Y.useState)(!1),[ue,de]=(0,Y.useState)(``),[fe,pe]=(0,Y.useState)(!1),[me,he]=(0,Y.useState)(!1),ge=$O(),[_e,ve]=(0,Y.useState)(null),{policyToast:ye,showPolicyToast:be,dismissPolicyToast:xe}=dk(),[Ce,we]=(0,Y.useState)(null),{exportChat:Te,exportError:Ee,clearExportError:De}=lk(e,W?.title),Oe=W?.agent_type&&W.agent_type!==`gaia`?W.agent_type:null,[ke,Ae]=(0,Y.useState)(!1),[je,Me]=(0,Y.useState)(null),Ne=(0,Y.useRef)(``),Pe=(0,Y.useRef)([]),Fe=(0,Y.useRef)([]),Ie=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>{f&&(Ne.current=f)},[f]),(0,Y.useEffect)(()=>{g.length>0&&(Pe.current=g.map(e=>({...e,active:!1})))},[g]),(0,Y.useEffect)(()=>{C.length>0&&(Fe.current=[...C])},[C]),Ew(),(0,Y.useEffect)(()=>{if(!u&&Ie.current){Ae(!0);let e=setTimeout(()=>{Ae(!1),Ne.current=``,Pe.current=[],Fe.current=[]},350);return()=>clearTimeout(e)}Ie.current=u},[u]);let Le=(0,Y.useRef)(null),Re=(0,Y.useRef)(null),ze=(0,Y.useRef)(null),Be=(0,Y.useRef)(null),He=(0,Y.useRef)(0),Ue=(0,Y.useRef)(!1),We=(0,Y.useRef)(0),Ge=(0,Y.useRef)(null),[Ke,qe]=(0,Y.useState)(!1),Je=(0,Y.useRef)(!1),Xe=(0,Y.useRef)(null),Ze=(0,Y.useRef)(null),Qe=(0,Y.useRef)(0),$e=(0,Y.useRef)(!1),et=(0,Y.useRef)(()=>{}),tt=(0,Y.useRef)(!1),nt=k(t=>t.messageQueues[e]??Ak),it=(0,Y.useCallback)(t=>k.getState().updateQueue(e,t),[e]),at=(0,Y.useRef)(!1),[ot,st]=(0,Y.useState)(!1),ut=(0,Y.useRef)(!1),dt=(0,Y.useRef)(!1),ft=(0,Y.useRef)(u);ft.current=u;let pt=k(t=>!!t.queueHolds[e]),mt=(0,Y.useRef)(``),gt=(0,Y.useRef)(null),_t=(0,Y.useRef)(null),vt=(0,Y.useRef)(0),yt=(0,Y.useRef)(!0),{userScrolling:bt,clearUserScroll:xt,listProps:St}=ck(Re,yt,e=>he(e>200)),Ct=(0,Y.useCallback)(()=>k.getState().currentSessionId!==e,[e]),Tt=(0,Y.useCallback)(()=>{gt.current=null,!Ct()&&mt.current&&m(mt.current)},[m,Ct]),Et=(0,Y.useRef)(0),Dt=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{d.chat.info(`ChatView mounted for session=${e}, loading messages...`);let t=d.chat.time();M(!0);let n=!1,r=!1,a=async(a=!1)=>{if(n||r)return;r=!0;let o=Dt.current;try{if(!a){if(k.getState().isStreaming)return;let t=await rt(e);if(n||t===Et.current||k.getState().isStreaming)return}let r=await lt(e);if(n)return;let s=yw(r.messages);a&&Dt.current!==o?Et.current=s.length:a?(i(s),Et.current=s.length,d.chat.timed(`Loaded ${s.length} message(s) for session=${e}`,t)):s.length!==Et.current&&!k.getState().isStreaming&&(d.chat.info(`Messages changed externally: ${Et.current} -> ${s.length}`),i(Cw(k.getState().messages,s)),Et.current=s.length)}catch(t){if(n)return;a&&(d.chat.error(`Failed to load messages for session=${e}`,t),i([]))}finally{r=!1,!n&&a&&M(!1)}};a(!0);let o=bk(()=>a(!1),3e3);return()=>{n=!0,o()}},[e,i,M]),(0,Y.useEffect)(()=>{Ot().then(e=>O(e.documents||[])).catch(e=>d.doc.error(`Could not load the document list`,e))},[O]);let kt=(0,Y.useRef)(!0),At=(0,Y.useRef)(!1),jt=Gw(N);(0,Y.useEffect)(()=>(kt.current=!0,()=>{kt.current=!1}),[]),(0,Y.useEffect)(()=>{let e=B?.text;!e||k.getState().isLoadingMessages||jt||(k.getState().setPendingPrompt(null),At.current=!0,setTimeout(()=>{At.current=!1,kt.current&&et.current(e,{opening:!0})},0))},[B,j,jt]),(0,Y.useEffect)(()=>{if(!yt.current)return;let e=Date.now()-vt.current,t=()=>{yt.current&&!bt()&&(vt.current=Date.now(),Le.current?.scrollIntoView({behavior:`instant`}))};e>=100&&t(),_t.current&&clearTimeout(_t.current),_t.current=setTimeout(t,100)},[r,f,g]),(0,Y.useEffect)(()=>{ze.current?.focus()},[e]),(0,Y.useEffect)(()=>{at.current=!1},[e]);let{contextUsage:Mt,contextUnavailable:Nt,refreshContext:Pt,showContextUsage:Ft}=tk(e,Ct),{comparison:It,comparing:Lt,comparingRef:Rt,handleRetryWith:zt,handleKeepAnswer:Bt,handleCloseComparison:Vt,closeForNewTurn:Ht}=ek({sessionId:e,isStreaming:u,isStale:Ct,setMessages:i,refreshContext:Pt});(0,Y.useEffect)(()=>()=>{ft.current&&mT(e),Be.current&&!dt.current&&Be.current.abort(),Be.current&&=null,Xe.current&&=(clearTimeout(Xe.current),null),Je.current=!1,Ze.current=null,qe(!1),gt.current!==null&&(cancelAnimationFrame(gt.current),gt.current=null),_t.current&&=(clearTimeout(_t.current),null),Ge.current&&=(clearTimeout(Ge.current),null),xe(),mt.current=``,k.getState().resetStreaming()},[e]),(0,Y.useEffect)(()=>{Ce&&L&&(document.getElementById(ww(Ce))?.scrollIntoView({behavior:Mx(),block:`center`}),we(null))},[Ce,L]);let Ut=hD(e=>e.width),Wt=hD(e=>e.reveal),Gt=ZO(e=>e.visible),Kt=ZO(e=>e.setVisible),qt=(0,Y.useRef)(null),Jt=(0,Y.useCallback)(()=>{Kt(!1),qt.current?.focus()},[Kt]),Yt=nk(Re,yt),Xt=(0,Y.useCallback)(()=>{yt.current=!0,xt(),Le.current?.scrollIntoView({behavior:Mx()})},[xt]),Zt=(0,Y.useCallback)(()=>{Je.current||(Je.current=!0,at.current=!0,qe(!0),$s.getState().dismissSessionPrompts(e),k.getState().closeSessionQuestions(e),d.stream.warn(`User stopped generation; waiting for the server to close the turn`),Ye(e).catch(e=>{d.stream.error(`Stop request failed; waiting for the stream to close`,e)}),Ge.current?(clearTimeout(Ge.current),Ge.current=null,Ze.current?.()):Xe.current=setTimeout(()=>{d.stream.error(`No closing event ${kk}ms after Stop; closing the turn locally (session=${e})`),Ze.current?.()},kk))},[e]);(0,Y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&u&&!Fo(e)&&(e.preventDefault(),Zt())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,Zt]);let Qt=(0,Y.useCallback)(async(t,n)=>{let r=n?.attach===!0,a=n?.queued===!0,c=r?n?.reconnect??0:0,f=!r&&t===void 0,g=(f?G:t??``).trim(),C=f&&ge.hasUploaded,T=f&&ge.hasImage,D=()=>{if(!f)return g;let e=ge.compose(g);return se(``),ge.clear(),ze.current?.focus(),e};yt.current=!0;let O=Gw(N),A=e=>{a&&n?.onQueuedOutcome?.(e)};if(!r&&Oe){d.chat.warn(`Send blocked: chat ${e} belongs to the retired "${Oe}" agent`),A({kind:`failed`,error:`This chat's "${Oe}" agent was retired, so it cannot take new messages.`});return}let j=!n?.opening&&(k.getState().messageQueues[e]??Ak).length>0;if(r){if(u&&!c)return}else if(!a&&(g||C)&&!O&&(u||Rt.current||j)){let e=D();it(t=>ee(t,e,`queued`));return}else if(!g&&!C||u||O){A({kind:`busy`}),!g&&!C&&d.chat.debug(`Send blocked: empty message`),u&&d.chat.debug(`Send blocked: already streaming`),O&&d.chat.debug(`Send blocked: system initializing`);return}if(!r&&!a&&(!Uo(`chat`)||T&&!Uo(`vision`))){if(tt.current)return;tt.current=!0;try{if(!await Ko(`chat`)||T&&!await Ko(`vision`))return}finally{tt.current=!1}}let M=g,P=null;if(r)d.chat.info(`Re-attaching to background run for session=${e}${c?` (reconnect ${c})`:``}`);else{M=D(),d.chat.info(`Sending message to session=${e}`,{length:M.length,preview:M.slice(0,80)}),Ht();let t={id:Date.now(),session_id:e,role:`user`,content:M,created_at:new Date().toISOString(),rag_sources:null};o(t),P=t,Dt.current+=1}c||(We.current=0),p(!0),h(),S(),E(),Qe.current=0,$e.current=!1,c&&k.getState().setLiveStatus(`${Ok} (attempt ${c} of 3)…`),d.stream.info(`Starting agent stream...`);let L=d.stream.time(),R=``,z;Me(null);let B=!1;ut.current=!1,r||st(!1);let te=null,V=!a;dt.current=a;let ne=e=>{V||(V=!0,dt.current=!1,n?.onQueuedOutcome?.(e),e.kind===`accepted`&&Ct()&&te?.abort())},ie=r||!!W&&!gk(W.title),ae=()=>{ne({kind:`accepted`}),!ie&&(ie=!0,ht(e).then(t=>l(e,{title:t.title})).catch(e=>d.chat.warn(`Could not refresh the chat title`,e)))};mt.current=``,Je.current=!1,qe(!1);let oe=()=>{Xe.current&&=(clearTimeout(Xe.current),null),Je.current=!1,Ze.current=null,qe(!1)},H=()=>{let{agentSteps:e,cards:t}=k.getState();return{steps:e.map(e=>({...e,active:!1})),cards:[...t]}};Ze.current=()=>{if(B)return;B=!0,Ue.current=!0,He.current=Date.now(),oe(),ne({kind:`failed`,error:`Stopped before GAIA confirmed it got this message.`}),Be.current?.abort(),Be.current=null,gt.current!==null&&(cancelAnimationFrame(gt.current),gt.current=null);let t=mt.current||k.getState().streamingContent;if(mt.current=``,Ct())return;let{steps:n,cards:r}=H();o({id:Date.now()+1,session_id:e,role:`assistant`,content:t,created_at:new Date().toISOString(),rag_sources:null,agentSteps:n.length>0?n:void 0,cards:r.length>0?r:void 0,stopState:`unconfirmed`}),p(!1),h(),S(),E()};let U={onConnected:()=>{if(Ct())return;let e=k.getState();(e.liveStatus===`Waiting for GAIA to start this answer…`||e.liveStatus?.startsWith(Ok))&&e.setLiveStatus(null)},onChunk:t=>{if(ae(),Ct())return;k.getState().awaitingUser&&k.getState().setAwaitingUser(!1);let n=t.content||``;if(n&&$s.getState().dismissSessionPrompts(e),n){if(t.type===`answer`)R=n;else{$e.current&&=(R.length>0&&(R+=`
|
|
69
69
|
|
|
70
70
|
`),!1),R+=n;let e=k.getState().agentSteps,t=e[e.length-1];t?.type===`thinking`&&t.active&&v({active:!1,latencyMs:Date.now()-t.timestamp})}let e=R.replace(hw,``).trim();if(e=gw(e),e){let t=e.lastIndexOf(`{`);if(t>-1){let n=e.slice(t);/^\{\s*"(?:thought|answer|goal|tool)"/.test(n)&&(n.match(/\{/g)||[]).length>(n.match(/\}/g)||[]).length&&(e=e.slice(0,t).trim())}}mt.current=e,gt.current===null&&(gt.current=requestAnimationFrame(Tt))}},onAgentEvent:t=>{if((t.type!==`status`||t.phase!==`waiting`)&&ae(),t.type===`followup_taken`&&t.text){let n=t.text;if(it(e=>re(e,n)),Ct())return;o({id:Date.now(),session_id:e,role:`user`,content:n,created_at:new Date().toISOString(),rag_sources:null});return}if(t.type===`followup_unavailable`){Ct()||st(!0);return}if(t.type===`followup_returned`){let e=t.texts??[];it(t=>y(t,e));return}if(Ct())return;if(t.type===`context_usage`){Ft(t);return}let n=t.type===`permission_request`||t.type===`needs_input`;if(k.getState().awaitingUser!==n&&k.getState().setAwaitingUser(n),Dk.has(t.type)&&$s.getState().dismissSessionPrompts(e),t.type===`permission_request`){Rw(t,e);return}if(t.type===`needs_confirmation`){w({render:`needs_confirmation`,data:{action:typeof t.action==`string`?t.action:``,summary:typeof t.summary==`string`?t.summary:``}});return}if(t.type===`needs_input`){if(!t.request_id){console.error(`[ChatView] needs_input event missing request_id, ignoring`);return}k.getState().openQuestion(t.request_id,e,typeof t.timeout_seconds==`number`?t.timeout_seconds:null),w({render:`needs_input`,data:{session_id:e,request_id:t.request_id,question:typeof t.question==`string`?t.question:``,options:Array.isArray(t.options)?t.options:[],allow_free_text:t.allow_free_text!==!1,sensitive:!!t.sensitive}});return}if(t.type===`policy_alert`){let n=zw(t,e,`policy-${Date.now()}-${Qe.current+1}`);F(n);let r=dw(t,Qe);r&&_(r),be({tool:n.tool,receiptId:t.receipt_id});return}if((t.type===`tool_end`||t.type===`tool_result`)&&k.getState().livePhase===`tool`&&k.getState().setLiveStatus(null),t.type===`tool_end`){x({active:!1,success:t.success!==!1});return}if(t.type===`tool_result`){typeof t.render==`string`&&t.render.length>0&&w({render:t.render,data:t.data}),x(Bw(t));return}if(t.type===`tool_args`){let e=!!t.args&&Object.keys(t.args).length>0,n=t.detail||(e?JSON.stringify(t.args):``);x({...n?{detail:n}:{},...t.narration?{narration:t.narration}:{}});let r=k.getState(),i=[...r.agentSteps].reverse().find(e=>e.type===`tool`);t.narration&&i?.active&&r.livePhase===`tool`&&r.setLiveStatus(Iy(i,I()),`tool`);return}if(t.type===`skill_use`){k.getState().addSkillStep(t.how===`model`?null:dw(t,Qe));return}if(t.type===`commentary`){R=``,$e.current=!1,mt.current=``,m(``);let e=dw(t,Qe);e&&_(e);return}if(t.retracts_answer&&(R=``,$e.current=!1,mt.current=``,m(``),t.type===`status`)){let e=dw({type:`status`,status:`warning`,message:I()(`live.answerRestarted`)},Qe);e&&_(e);return}if(t.type===`thinking`){let e=k.getState().agentSteps,n=e[e.length-1];if(n&&n.type===`thinking`){b(t.content||``);return}let r=dw(t,Qe);r&&_(r);return}if(t.type===`status`){if(t.status===`history_cut`){z=(t.message||``).trim()||void 0,Me(z??null);return}mw(t,Qe);return}if(t.type===`step`||t.type===`agent_error`&&_w(t,k.getState().agentSteps))return;let r=dw(t,Qe);r&&(_(r),t.type===`tool_start`&&($e.current=!0,k.getState().setLiveStatus(Iy(r,I()),`tool`)))},onDone:t=>{if(ae(),$s.getState().dismissSessionPrompts(e),k.getState().closeSessionQuestions(e),B)return;B=!0;let n=t.cancelled===!0?`stopped`:Je.current&&t.message_id==null?`unconfirmed`:void 0;if(oe(),gt.current!==null&&(cancelAnimationFrame(gt.current),gt.current=null),mt.current=``,vk(e,t.documents_added??[]),Ct())return;He.current=Date.now(),ut.current=!0;let a=k.getState();a.setRunningSessions(a.runningSessionIds.filter(t=>t!==e));let s=t.content||R;d.chat.timed(`Agent response complete: ${s.length} chars${n?` (${n})`:``}`,L);let{steps:c,cards:l}=H(),u=c.some(e=>e.type===`policy_alert`);if(s||u||n){Et.current=k.getState().messages.length+1;let r={id:t.message_id||Date.now()+1,session_id:e,role:`assistant`,content:s,created_at:new Date().toISOString(),rag_sources:null,agentSteps:c.length>0?c:void 0,stats:t.stats||void 0,turnSummary:t.turn_summary||void 0,cards:l.length>0?l:void 0,stopState:n,historyNotice:z,libraryNotices:t.library_notices,failure:t.failed?t.failure:void 0};z&&jk.set(r.id,z),o(r);let i=ES.getState();i.settings?.auto&&Tw(r)&&i.read(`${e}:${r.id}`,FC(s))}p(!1),h(),S(),E(),ze.current&&ze.current.focus(),setTimeout(()=>{lt(e).then(t=>{if(Ct()||k.getState().isStreaming)return;let n=k.getState().messages,a=n.filter(e=>e.cards&&e.cards.length>0),c=yw(t.messages).map(e=>{let t=a.find(t=>t.id===e.id||t.role===e.role&&t.content===e.content);return{...e,cards:t?.cards??e.cards,stopState:e.stopState??n.find(t=>t.id===e.id)?.stopState,failure:e.failure??n.find(t=>t.id===e.id)?.failure}});i(c),Et.current=c.length,r&&!s&&c[c.length-1]?.role===`user`&&o({id:Date.now()+2,session_id:e,role:`assistant`,content:HS,created_at:new Date().toISOString(),rag_sources:null})}).catch(t=>d.chat.error(`Could not refresh messages for session=${e}`,t))},300)},onError:t=>{let n=US(t),i=V&&!r&&!n&&!!P&&ST(e,M,t);if(!V||i){if(n)ae();else{if(ne(yT(t)?{kind:`busy`}:{kind:`failed`,error:$S(t).text}),He.current=Date.now(),oe(),gt.current!==null&&(cancelAnimationFrame(gt.current),gt.current=null),mt.current=``,Ct())return;d.chat.info(`Queued message for session=${e} not taken: ${t.message}`),P&&s(P.id),ut.current=!0,p(!1),h(),S(),E();return}}if(n&&Je.current&&!B){d.chat.warn(`Stream for session=${e} was lost while stopping; closing the turn locally`),Ze.current?.();return}if(n&&!kt.current)return;if(n&&!B&&!Ct()&&We.current<3){let n=++We.current,r=VS[n-1]??0;d.chat.warn(`Stream for session=${e} lost (${t.name}); reconnecting in ${r}ms (${n}/3)`),k.getState().setLiveStatus(`${Ok} (attempt ${n} of 3)…`);let i=()=>{Ge.current=null,!(!kt.current||Ct()||Je.current)&&et.current(void 0,{attach:!0,reconnect:n})};r>0?Ge.current=setTimeout(i,r):i();return}He.current=Date.now(),$s.getState().dismissSessionPrompts(e),k.getState().closeSessionQuestions(e);let a=Je.current;if(oe(),gt.current!==null&&(cancelAnimationFrame(gt.current),gt.current=null),mt.current=``,Ct())return;if(n||(ut.current=!0),d.chat.error(`Chat error for session=${e}`,t),a){let{steps:n,cards:r}=H();o({id:Date.now()+2,session_id:e,role:`assistant`,content:R,created_at:new Date().toISOString(),rag_sources:null,agentSteps:n.length>0?n:void 0,cards:r.length>0?r:void 0,stopState:`stopped`,stopError:t.message||`Unknown error`}),Et.current=k.getState().messages.length,p(!1),h(),S(),E();return}let{kind:c,text:l}=$S(t),u=c===`stream`?l:l+`
|
|
@@ -78,6 +78,6 @@ Error generating stack: `+e.message+`
|
|
|
78
78
|
`);return(0,Y.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 xM=1e9,SM={downloading:0,verifying:1,failed:2,ready:3,unchecked:3,cancelled:4,queued:5,skipped:6};function CM(e){return e.roles.includes(`embedding`)?0:e.roles.includes(`chat`)?1:2}function wM(e){return[...e].filter(e=>e.state!==`skipped`).sort((e,t)=>SM[e.state]-SM[t.state]||CM(e)-CM(t))}var TM=/^\s*(Downloading:|Downloaded\b|\[[=\-\s>#]*\])/;function EM(e){return e.some(e=>e.trim()&&!TM.test(e))}var DM={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 OM(e){return e?e.state===`running`||e.state===`verifying`||!!e.models?.some(e=>e.state===`downloading`||e.state===`queued`||e.state===`verifying`):!1}function kM(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 AM({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,Y.useId)(),h=(0,Y.useId)(),[g,_]=(0,Y.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(DM[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(hr,{size:14}):e.state===`failed`?P(Tr,{size:14}):e.state===`cancelled`?P(wa,{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`&&EM(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(xr,{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`&&EM(v)&&P(bM,{lines:v,id:h,className:`dl-log`}),e.state===`failed`&&V(`div`,{className:`dl-fail`,children:[P(`p`,{className:`dl-error`,id:m,children:kM(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(Ba,{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(Ba,{size:13,"aria-hidden":`true`}),` `,p(`setup.progress.retry`)]})})]})}function jM({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=$A(),m=(0,Y.useMemo)(()=>wM(e.models??[]),[e.models]),h=(0,Y.useRef)(new Map),g=(0,Y.useRef)(new Map),_=(0,Y.useRef)(new BS),v=(0,Y.useRef)(!1),[y,b]=(0,Y.useState)(()=>Date.now()),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.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,Y.useState)(``),[k,A]=(0,Y.useState)(``),j=(0,Y.useRef)(null),M=e.state===`verifying`||e.state!==`running`&&m.some(e=>e.state===`verifying`),N=(0,Y.useRef)(new Map);(0,Y.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,Y.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,Y.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(DM[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=OM(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)>xM?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(AM,{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(Xj,{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(Zj,{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(Zj,{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 MM=[`check`,`download`,`test`],NM={root:`setup-report`,button:`btn-secondary setup-report-button`,hint:`setup-hint`,error:`setup-error`};function PM({run:e,before:t={}}){let n=T(),[r,i]=(0,Y.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=MM.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(xr,{size:13,className:i?`is-open`:``,"aria-hidden":`true`}),` `,n(`setup.logs.${e}`)]}),i&&P(bM,{lines:t,className:`setup-log-pre`})]},e)}),P(rC,{classes:NM,note:n(`setup.logs.reportNote`)})]})}function FM(){let e=T(),t=k(e=>e.locale),n=k(e=>e.setLocale);return V(`label`,{className:`setup-language`,children:[P(qi,{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 IM={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`]},LM={cancelled:`setup.npu.fixError.cancelled`,timeout:`setup.npu.fixError.timeout`,not_authorized:`setup.npu.fixError.notAuthorized`,no_pkexec:`setup.npu.fixError.noPkexec`};function RM({problem:e}){let t=T(),n=IM[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 zM({problems:e,disabled:t,onRecheck:n,id:r=`setup-npu-problems`}){let i=T(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.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 bn?e.body?.code:void 0,r=n&&n in LM?LM[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(RM,{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 BM(){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 VM({plan:e,selection:t,onSelection:n,disabled:r=!1,onRecheck:i}){let a=T(),o=nj(e),s=e.npu?.present&&!e.npu.ready?e.npu.problems:[],c=s.length?void 0:o.find(e=>aj(e)&&e.gaia_model&&e.chat_choice&&e.fits!==!1)??o.find(e=>aj(e)&&e.chat_choice&&e.downloaded&&!oj(e)),l=!s.length&&!c&&o.some(e=>aj(e)&&e.fit_code===`npu`),u=!!o.find(e=>e.id===t.defaultChat&&aj(e)),d=xj(e).defaultChat,f=d&&!o.find(e=>e.id===d&&aj(e))?d:o.find(e=>e.chat_choice&&e.gaia_model&&e.support===`verified`&&!aj(e))?.id,p=e=>{e===`npu`&&c&&!u&&n(dj(t,o,c.id)),e===`gpu`&&u&&f&&n(dj(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(zM,{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 HM=({children:e})=>P(`bdi`,{dir:`ltr`,children:e});function UM({label:e,children:t}){return V(`div`,{className:`found-row`,children:[P(`dt`,{children:e}),P(`dd`,{children:t})]})}function WM(e){return e.family?`${e.name} (${e.family})`:e.name}var GM=[[`llamacpp`,`llama.cpp`],[`flm`,`FastFlowLM`],[`whispercpp`,`whisper.cpp`],[`kokoro`,`Kokoro`],[`sd-cpp`,`stable-diffusion.cpp`]],KM=new Set([`llamacpp`,`flm`]);function qM(e){let t=[];for(let[n,r]of GM){let i=(e.backends??[]).find(e=>e.recipe===n&&e.default);i&&i.state!==`unsupported`&&t.push({name:r,b:i})}return t}function JM(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 YM={release:`release`,release_candidate:`release candidate`,local:`local build`,source:`from source`};function XM(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=qM(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:JM(n?.gaia_build,n?.gaia_version),build:n?.gaia_build?.kind??null,software:[JM(n?.gaia_build,n?.gaia_version)?`GAIA ${JM(n?.gaia_build,n?.gaia_version)}`:null,n?.lemonade_version?`Lemonade ${n.lemonade_version}`:null,...o.filter(({b:e})=>KM.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 ZM={installed:`installed`,update_required:`installed, updates on first use`},QM=e=>e.state===`installed`||e.state===`update_required`,$M={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 eN(e,t){let n=XM(e,t),r=e.lemonade.mode===`external`?`the user's own`:`GAIA's own`;return[`GAIA: ${n.gaia??`unknown`}${n.build?`, ${YM[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}`:``} (${ZM[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(WM).join(`; `)||t?.gpu_name||`none found`}`,`NPU: ${n.npus.map(WM).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 tN({plan:e,hardware:t,onChangeMemory:n}){let r=T(),i=XM(e,t),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),d=async e=>{u(null);try{await On(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,Y.useRef)(null);(0,Y.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(eN(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`?hr:Vr,{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(UM,{label:r(`setup.found.runsOn`),children:[i.runsOn?P(HM,{children:i.runsOn}):f,i.npu&&P(`span`,{className:`found-chip`,children:P(HM,{children:`NPU`})})]}),V(UM,{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(HM,{children:i.totalMemory}):f:P(HM,{children:$(e.capacity_gb)}),n&&P(`button`,{type:`button`,className:`link-btn found-link`,onClick:n,children:r(`setup.found.changeMemory`)})]}),P(UM,{label:r(`setup.found.space`),children:i.freeGb==null?f:P(HM,{children:$(i.freeGb)})}),V(UM,{label:r(`setup.found.software`),children:[i.software.length?P(HM,{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(xi,{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(Tr,{size:13,"aria-hidden":`true`}),` `,r(`setup.found.noticed`)]}),P(`ul`,{children:p.map(e=>P(`li`,{children:P(HM,{children:e})},e))})]}),V(`button`,{type:`button`,className:`setup-log-toggle found-more`,onClick:()=>o(e=>!e),"aria-expanded":a,children:[P(xr,{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(UM,{label:P(HM,{children:`GAIA`}),children:[i.gaia?P(HM,{children:i.gaia}):f,i.build&&i.build!==`release`&&P(`span`,{className:`found-chip`,children:r(`setup.found.build.${i.build}`)})]}),P(UM,{label:r(`setup.found.agent`),children:i.sys?.agent_version?P(HM,{children:i.sys.agent_version}):P(`span`,{className:`found-muted`,children:r(`setup.found.agentLater`)})}),V(UM,{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(HM,{children:i.sys.lemonade_version})]}),e.lemonade.url&&P(`span`,{className:`found-sub`,children:P(HM,{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(HM,{children:e})}),P(`td`,{children:P(HM,{children:t.backend})}),P(`td`,{children:P(HM,{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($M[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(HM,{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(UM,{label:r(`setup.found.os`),children:i.sys?.os??t?.os?P(HM,{children:i.sys?.os??t?.os}):f}),V(UM,{label:r(`setup.found.cpu`),children:[i.cpu||i.sys?.processor?P(HM,{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(UM,{label:r(`setup.found.gpu`),children:i.gpus.length?P(HM,{children:i.gpus.map(WM).join(`; `)}):P(`span`,{className:`found-muted`,children:r(`setup.found.none`)})}),P(UM,{label:r(`setup.found.npu`),children:i.npus.length?P(HM,{children:i.npus.map(WM).join(`; `)}):P(`span`,{className:`found-muted`,children:r(`setup.found.none`)})})]})]})]})}function nN({state:e}){return e===`done`?P(hr,{size:13,"aria-hidden":`true`}):e===`active`?P(K,{size:13,className:`spin`,"aria-hidden":`true`}):P(e===`failed`?J:e===`question`?jr:Nr,{size:13,"aria-hidden":`true`})}function rN({hardware:e,hardwareError:t,plan:n,serverRun:r,awaitingChoice:i=!1}){let a=T(),[o,s]=(0,Y.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(nN,{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(hr,{size:13,"aria-hidden":`true`}),P(`span`,{className:`setup-result-label`,children:a(`setup.checks.allPassed`,{n:String(g.length)})}),P(xr,{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 iN({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(hr,{size:13,"aria-hidden":`true`}):e.status===`active`?P(K,{size:13,className:`spin`,"aria-hidden":`true`}):e.status===`failed`?P(Tr,{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 aN={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 oN(e,t){return t(`setup.test.job.${e}`)}function sN({state:e}){return e===`passed`?P(hr,{size:13,"aria-hidden":`true`}):e===`running`?P(K,{size:13,className:`spin`,"aria-hidden":`true`}):P(e===`failed`?J:e===`skipped`?fa:Nr,{size:13,"aria-hidden":`true`})}function cN(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 lN({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,Y.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(sN,{state:e.state}),V(`span`,{className:`setup-result-label`,children:[oN(e.job,l),e.subject&&V(`bdi`,{className:`setup-result-model`,children:[` `,n[e.subject]??e.subject]})]}),P(`span`,{className:`setup-result-value`,children:cN(e,l)}),e.error&&V(`div`,{className:`setup-result-error`,children:[P(`p`,{children:l(e.kind===`broken`&&!s?`setup.test.why.brokenYours`:aN[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(sN,{state:`failed`}),P(`span`,{className:`setup-result-label`,children:oN(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(sN,{state:`waiting`}),P(`span`,{className:`setup-result-label`,children:oN(e,l)}),P(`span`,{className:`setup-result-value`,children:l(`setup.test.waiting`)})]},e))]})]}),e.state===`verifying`&&o&&P(Xj,{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(Xj,{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(Zj,{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 uN=`https://app.fireworks.ai/settings/users/api-keys`,dN=`https://amd-gaia.ai/docs/guides/llm-gateway`,fN=[{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 pN(e,t){return N(e.title)?t(e.title):e.title}var mN=1e3,hN=`gaia-setup-choice`;function gN(){try{let e=localStorage.getItem(hN);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 _N(e){try{localStorage.setItem(hN,e)}catch(e){console.warn(`[SetupScreen] could not save the provider choice; a reload will ask again`,e)}}var vN=[`ok`,`needs_key`,`too_old`];function yN({onChosen:e,onNothingToOffer:t,onFound:n,canInstallOwn:r=!0}){let i=T(),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)([]),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(null),E=(0,Y.useRef)(!0),O=(0,Y.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&&vN.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,Y.useEffect)(()=>(E.current=!0,O(),()=>{E.current=!1}),[O]);let k=(0,Y.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){JA(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(Xj,{children:[V(`button`,{type:`button`,className:`btn-secondary`,disabled:d,onClick:()=>void O(),children:[d&&P(K,{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(K,{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(xr,{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(xN,{text:x})),V(Xj,{children:[V(`button`,{type:`submit`,form:`setup-lemonade-form`,className:`btn-secondary`,disabled:!!y||h&&!p.trim(),children:[y===`external`&&P(K,{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(K,{size:13,className:`spin`}),` `,i(`setup.offer.useOwn`)]})]})]})}function bN({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(Xj,{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 xN({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 SN({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 CN=[`check`,`plan`,`key`,`models`,`gpu`,`download`,`test`,`ready`];function wN(e){return e instanceof Error?e.message:String(e)}function TN({onReady:e,onClose:t}){let n=T(),r=ls(e=>e.refresh),i=ls(e=>e.select),[a,o]=(0,Y.useState)(`local`),[s,c]=(0,Y.useState)(`check`),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(`models`),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(()=>new Set([`check`])),y=(0,Y.useRef)(`check`),[b,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(null),[w,E]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(null),[A,j]=(0,Y.useState)(null),[M,N]=(0,Y.useState)(``),[F,I]=(0,Y.useState)({busy:!1,error:null,done:!1}),[L,ee]=(0,Y.useState)(null),[R,z]=(0,Y.useState)(null),[B,te]=(0,Y.useState)(null),[ne,re]=(0,Y.useState)(null),[ie,ae]=(0,Y.useState)(null),[oe,H]=(0,Y.useState)(null),[U,W]=(0,Y.useState)(!1),[G,le]=(0,Y.useState)(null),[ue,de]=(0,Y.useState)(!1),[fe,pe]=(0,Y.useState)(!1),[me,he]=(0,Y.useState)(null),[ge,_e]=(0,Y.useState)(!1),[ve,ye]=(0,Y.useState)(null),[be,xe]=(0,Y.useState)([]),[Se,we]=(0,Y.useState)([]),[Ee,De]=(0,Y.useState)([]),[Oe,ke]=(0,Y.useState)(!1),[Ae,je]=(0,Y.useState)(!1),Me=(0,Y.useRef)({gaiaLemonade:!1,options:{}}),Ne=(0,Y.useRef)(null),Pe=(0,Y.useRef)(!1),Fe=(0,Y.useRef)(!1),[Ie,Re]=(0,Y.useState)(!1),[ze,Ve]=(0,Y.useState)(!1),He=(0,Y.useCallback)(()=>Ve(!0),[]),[Ue,We]=(0,Y.useState)(null),[Ge,Ke]=(0,Y.useState)(null),qe=(0,Y.useRef)(!0);(0,Y.useEffect)(()=>(qe.current=!0,()=>{qe.current=!1}),[]);let{network:Je,providers:Ye,recheck:Xe}=mM(),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,ot=w&&!w.server_only?w:null,ct=w?.state===`running`||w?.state===`verifying`,lt=ot?.state===`ready`,dt=OM(w),ft=!(ot?.models??[]).some(e=>e.state===`downloading`||e.state===`queued`)&&((ot?.tests?.length??0)>0||ot?.state===`verifying`),mt=(0,Y.useCallback)(()=>{C(null),st().then(x).catch(e=>C(wN(e)))},[]),ht=(0,Y.useRef)(0),_t=(0,Y.useCallback)(async()=>{let e=++ht.current;z(null);try{let t=await Ce();return e===ht.current?(ee(t),t):null}catch(t){return e===ht.current&&z(wN(t)),null}},[]),yt=(0,Y.useCallback)(async()=>{try{let e=await Pn();qe.current&&H(e??null)}catch(e){console.warn(`[SetupScreen] GPU memory could not be read; the step stays hidden`,e)}},[]),bt=t!=null;(0,Y.useEffect)(()=>{ce().then(e=>ke(e.source===`config`)).catch(e=>console.warn(`[SetupScreen] could not read which Lemonade GAIA uses`,e)),mt(),_t(),it().then(e=>{(e.state!==`idle`||e.models?.length)&&(bt&&e.state!==`running`&&e.state!==`verifying`||(E(e),e.server_only||c(`download`),e.skip_chat_model&&o(gN()===`amd`?`amd`:`fireworks`)))}).catch(e=>j(wN(e))).finally(()=>Re(!0))},[mt,_t,bt]),(0,Y.useEffect)(()=>{L?.catalog&&L.lemonade.reachable&&(te(e=>e??_j(L)),yt(),!w&&L.catalog.some(e=>e.partial&&e.selected)&&_e(!0))},[L,yt,w]);let xt=(0,Y.useCallback)(()=>{Ne.current&&clearInterval(Ne.current),Ne.current=null},[]),St=(w?.models??[]).filter(e=>e.state===`failed`&&e.error_kind===`disk_full`).length;(0,Y.useEffect)(()=>{St>0&&_t()},[St,_t]);let Ct=(0,Y.useCallback)(async()=>{try{let e=await it();if(k(null),e.state===`idle`&&!e.models?.length){E(null),c(`plan`),je(!0),_t();return}E(e)}catch(e){k(wN(e))}},[_t,n]);(0,Y.useEffect)(()=>(!dt&&!O||(Ne.current=setInterval(()=>{Ct()},mN)),xt),[dt,O,Ct,xt]),(0,Y.useEffect)(()=>{at&&at.state===`ready`&&(mt(),_t())},[at,at?.state,mt,_t]),(0,Y.useEffect)(()=>{lt&&(mt(),_t().then(e=>{e&&ae(e)}),yt())},[lt,mt,_t,yt]);let wt=(0,Y.useRef)(!1),Tt=(0,Y.useCallback)(async(e=!1,t={})=>{if(wt.current)return!1;wt.current=!0,j(null),he(null),_e(!1),je(!1);try{_N(a),Me.current={gaiaLemonade:e,options:t};let n=await vt(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=gt(e);if(t)return le({kind:`server`,detail:t,then:`run`}),!1;if(e instanceof bn&&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(wN(e)),!1}finally{wt.current=!1}},[a,rt]);(0,Y.useEffect)(()=>{s===`check`&&Ie&&ze&&L&&!L.lemonade.reachable&&!w&&!Pe.current&&(Pe.current=!0,Tt(!1,{serverOnly:!0}))},[s,Ie,ze,L,w,Tt]);let Et=!!(B&&L?.catalog&&L.lemonade.reachable&&(b||S)),Dt=(0,Y.useCallback)(()=>{let{gaiaLemonade:e,options:t}=Me.current;Tt(e,t)},[Tt]),Ot=(0,Y.useCallback)((e,t=L)=>{re(t);let n=t&&B&&!rt?Dj(t,B):[];return Tt(!1,{acknowledgeLowDisk:e,keepTrying:U,extraModels:n})},[L,B,rt,U,Tt]),[kt,At]=(0,Y.useState)(!1),jt=(0,Y.useRef)(!1),Mt=(0,Y.useCallback)(async(e,t=ue)=>{if(!L||!B||jt.current)return;he(null),At(e);let r=nj(L),i=rt?[]:Tj(r,B).filter(e=>!e.downloaded||e.id===B.defaultChat),a=i.find(oj);if(a){let e=a.id===B.defaultChat?`setup.models.cantRun.chat`:`setup.models.cantRun.other`;he(n(e,{name:a.name,why:Fj(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),jt.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=gt(e);if(t){le({kind:`server`,detail:t,then:`chat`});return}throw e}if(!rt){await BM();let e=pj(r,B);e!==(n.vision_model??null)&&(n=await Be(e));for(let e of Ej(n,B))n=await pt(e.id,e.skipped)}ee(n),await Ot(e,n)}catch(e){he(wN(e))}finally{jt.current=!1,pe(!1)}}},[L,B,rt,ue,Ot,n]),Nt=(0,Y.useCallback)(e=>{he(null),s===`download`?g(e===y.current?null:e):(g(null),c(e===`test`||e===`ready`?`download`:e))},[s]),Pt=(0,Y.useCallback)(()=>{h??o(`local`),Nt(`plan`)},[Nt,h]),Ft=(0,Y.useCallback)(()=>{ct&&h!=null||(o(`local`),u(!0),Nt(`models`))},[Nt,ct,h]),It=(0,Y.useCallback)(()=>{ct&&h!=null||(u(!1),o(gN()===`amd`?`amd`:`fireworks`),Nt(`key`))},[Nt,ct,h]),Lt=!!oe?.applies,Rt=(0,Y.useCallback)(()=>{Nt((h??s)===`gpu`?d:`plan`)},[d,Nt,h,s]),Bt=(0,Y.useCallback)(e=>{f(e),Nt(`gpu`)},[Nt]),Vt=(0,Y.useRef)({prev:null,next:null});(0,Y.useEffect)(()=>{let e=e=>{if(!e.altKey||G||(e.target instanceof Element?e.target:null)?.closest(`input, textarea, select, [contenteditable="true"]`))return;let t=e.key===`ArrowLeft`?Vt.current.prev:e.key===`ArrowRight`?Vt.current.next:null;t&&(e.preventDefault(),Nt(t))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[Nt,G]);let Ht=(0,Y.useCallback)(async()=>{try{await se(),await Ct()}catch(e){he(wN(e))}},[Ct]),Ut=(0,Y.useCallback)(async(e,t)=>{he(null),pe(!0);try{t===`verify`&&await fn(e),t===`disk_full`&&_t();try{E(await Te(e,{keepTrying:U}))}catch(t){let n=gt(t);if(!n)throw t;le({kind:`server`,detail:n,then:`retry`,id:e})}}catch(e){he(wN(e))}finally{pe(!1)}},[U,_t]),Wt=(0,Y.useCallback)(async e=>{he(null),pe(!0);try{L?.catalog?.find(t=>t.id===e)?.planned&&ee(await pt(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)?yj(t,nj(L),e,!1):t)}catch(e){he(wN(e))}finally{pe(!1)}},[L]),Gt=(0,Y.useCallback)(async()=>{await Ht(),Dt()},[Ht,Dt]),Kt=(0,Y.useCallback)(async()=>{if(!ct){I({busy:!0,error:null,done:!1});try{await zt(a,{api_key:!Oe&&M||void 0},e=>I({busy:!0,error:null,done:!1,waiting:e}),()=>!qe.current);let{models:e}=await Qt(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}),Ot(!1)}catch(e){I({busy:!1,error:wN(e),done:!1})}}},[a,M,i,Oe,Ot,n,ct]),qt=(0,Y.useCallback)(e=>{_N(e),o(e),I({busy:!1,error:null,done:!1})},[]);(0,Y.useEffect)(()=>{if(!lt||Se.length===0||Fe.current)return;let e=Se;Fe.current=!0,Tt(!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))])})},[lt,Se,U,Tt]);let Jt=lt&&Se.length===0,Yt=rt?ve:ot?.chat_model??(L&&!L.decided_after_server?L.chat_model.id:null),Xt=(0,Y.useCallback)(async t=>{he(null);try{!rt&&Yt&&await i(Yt),await r()}catch(e){he(wN(e));return}e(t)},[Yt,rt,e,r,i]);(0,Y.useEffect)(()=>{Jt&&ut().then(e=>xe(e.cards)).catch(e=>console.warn(`[SetupScreen] no first tasks to offer`,e))},[Jt]);let Zt=(0,Y.useMemo)(()=>{let e={};for(let t of L?.catalog??[])e[t.id]=t.name;return e},[L]),$t=w?.state===`failed`||w?.state===`cancelled`,en=ot&&(ot.state===`failed`||ot.state===`cancelled`)&&(ot.models??[]).length>0&&(ot.models??[]).every(e=>e.state===`ready`||e.state===`skipped`||e.state===`verifying`||e.state===`unchecked`)&&!dt,tn=!!ot&&$t&&!ot.problem&&Object.values(ot.components??{}).includes(`failed`),nn=nj(L),rn=B?Sj(nn,B):[],an=L&&B?wj(L,B):null,on=nn.find(e=>e.id===B?.defaultChat),sn=!!b&&!b.compatible&&b.blockers.length>0,cn=Jt?`ready`:s===`download`&&ft?`test`:s;y.current=cn;let ln=h??cn;(0,Y.useEffect)(()=>{v(e=>e.has(ln)?e:new Set(e).add(ln))},[ln]);let un=(0,Y.useRef)(!0);(0,Y.useEffect)(()=>{if(un.current){un.current=!1;return}let e=document.querySelector(`.setup-inner`);e&&(e.scrollTop=0),document.getElementById(`setup-title`)?.focus({preventScroll:!0})},[ln]);let dn=[{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`}],pn=e=>e===`models`||e===`key`?`plan`:e===`gpu`?d===`check`?`check`:`plan`:e,mn=rt?`key`:l?`models`:`plan`,hn=dn.findIndex(e=>e.id===pn(cn)),gn=e=>e===`download`||e===`test`||e===`ready`,_n=[];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`;_n.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&&_n.push(`Couldn't read this PC: ${S}`);Ue&&(_n.push(`Found your Lemonade${Ue.version?` ${Ue.version}`:``} at ${Ue.url}`),_n.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)?_n.push(L.lemonade.reachable?`Model server answering at ${L.lemonade.url??`its address`}`:`No model server answering yet`):R&&_n.push(`Couldn't read the model list: ${R}`);let vn=(e,t)=>t<=hn||_.has(e)&&!gn(e),yn=dn.map((e,t)=>({id:e.id,label:e.label,status:t<hn?`done`:t>hn?`pending`:cn===`ready`?`done`:$t&&(cn===`download`||cn===`test`||cn===`check`)?`failed`:ct&&(cn===`download`||cn===`test`)?`active`:`current`,shown:e.id===pn(ln),onOpen:e.id!==pn(ln)&&vn(e.id,t)?()=>Nt(e.id===`plan`?mn:e.id):void 0})),xn=dn.findIndex(e=>e.id===pn(ln)),Sn=ln===`gpu`&&d===`check`?.5:CN.indexOf(ln),Cn=(0,Y.useRef)(Sn),wn=(0,Y.useRef)(`forward`);Cn.current!==Sn&&(wn.current=Sn>Cn.current?`forward`:`back`,Cn.current=Sn);let Tn=ln===`gpu`?d:ln===`models`||ln===`key`?`plan`:xn>0?dn[xn-1].id===`plan`?mn:dn[xn-1].id:null,En=(ln!==`gpu`&&xn>=0&&xn<dn.length-1&&vn(dn[xn+1].id,xn+1)?dn[xn+1].id:null)??(h==null?ln===`check`&&Et?`plan`:ln===`gpu`?d:null:null);Vt.current={prev:Tn,next:En};let Dn=ln===`gpu`||ln===`models`||ln===`key`,On=h!=null&&ct,kn=[`server`];rt||kn.push(`chat`),!rt&&B&&lj(nn,B)&&kn.push(`vision`),B&&nn.some(e=>ij(e)&&B.ticked.has(e.id))&&kn.push(`embedding`);for(let e of nn)B&&sj(e)&&B.ticked.has(e.id)&&!e.downloaded&&kn.push(e.roles[0]);kn.push(`agent`);let An=B&&!rt?nn.filter(e=>sj(e)&&!B.ticked.has(e.id)&&!e.downloaded&&(cj(on)||!e.roles.includes(`image_creation`))):[],jn=nn.find(e=>e.fit_code===`memory`&&e.chat_choice&&e.support===`verified`);return V(`main`,{className:`setup`,"aria-labelledby":`setup-title`,children:[P(iN,{steps:yn}),P(Yj,{value:p,children:V(`div`,{className:`setup-pane`,children:[V(`div`,{className:`setup-inner`,children:[xn>=0&&V(`nav`,{className:`setup-topnav`,"aria-label":n(`setup.nav.label`),children:[P(`button`,{type:`button`,className:`setup-arrow`,onClick:()=>Tn&&Nt(Tn),disabled:!Tn,"aria-label":n(`setup.nav.prev`),children:P(yr,{size:16,"aria-hidden":`true`})}),P(`button`,{type:`button`,className:`setup-arrow`,onClick:()=>En&&Nt(En),disabled:!En,"aria-label":n(`setup.nav.next`),children:P(xr,{size:16,"aria-hidden":`true`})}),P(`span`,{children:P(`bdi`,{children:n(`setup.nav.stepOf`,{n:String(xn+1),total:String(dn.length)})})}),h!=null&&h!==cn&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>g(null),children:n.compose(e=>e(`setup.nav.toLive`,{step:e(dn.find(e=>e.id===cn)?.key??`setup.download.step`)}))}),P(FM,{})]}),ge&&s!==`download`&&V(`div`,{className:`setup-banner`,role:`status`,children:[P(Ui,{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-${wn.current}`,children:[ln===`check`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(Et?`setup.check.headingDone`:`setup.check.heading`)}),P(`p`,{className:`setup-lede`,children:n(Et?`setup.check.ledeDone`:`setup.check.lede`)}),P(rN,{hardware:b,hardwareError:S,plan:L,serverRun:at,awaitingChoice:!!Ue&&!ze}),Et&&L&&P(tN,{plan:L,hardware:b,onChangeMemory:Lt&&h==null?()=>Bt(`check`):void 0}),Et&&h==null&&!(Ue&&!ze)&&P(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>Nt(`plan`),children:n(`setup.continue`)})}),at&&$t&&V(D.Fragment,{children:[P(SN,{run:at}),at.problem?P(bN,{problem:at.problem,onRetry:()=>void Tt(!1,{serverOnly:!0}),onUseGaia:()=>void Tt(!0,{serverOnly:!0})}):P(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Tt(!!at.gaia_lemonade,{serverOnly:!0}),children:n(`setup.tryAgain`)})})]}),R&&!L&&V(D.Fragment,{children:[P(xN,{text:R}),V(Xj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void Tt(!1,{keepTrying:U}),children:n(`setup.models.useRecommended`)}),P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void _t(),children:n(`setup.tryAgain`)})]}),P(`p`,{className:`setup-hint`,children:n(`setup.models.useRecommendedNote`)})]}),A&&P(xN,{text:A}),A&&!at&&L&&!L.lemonade.reachable&&P(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Tt(!1,{serverOnly:!0}),children:n(`setup.tryAgain`)})}),Ie&&L&&(!L.lemonade.reachable&&!at||Et&&h==null&&L.lemonade.mode!==`external`)&&P(yN,{onNothingToOffer:He,canInstallOwn:!L.lemonade.reachable&&!at,onFound:We,onChosen:e=>{ke(e===`external`),Ke(e),Ve(!0),mt(),_t()}})]}),ln===`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:on?.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:$(Cj(L,B).downloadGb??0)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.plan.runsOn`)}),P(`dd`,{children:P(`bdi`,{children:on&&aj(on)?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:Cj(L,B).afterGb==null?`—`:$(Math.max(0,Cj(L,B).afterGb))})})]})]}),V(`ul`,{className:`setup-reasons`,children:[!B.chatChosen&&P(`li`,{children:n(`setup.plan.why.evaluated`)}),on?.need_gb!=null&&on.capacity_gb!=null&&on.fits&&P(`li`,{children:n(`setup.plan.why.fits`,{need:NS(on.need_gb),have:NS(on.capacity_gb)})}),P(`li`,{children:n(`setup.plan.why.private`)}),on&&aj(on)&&P(`li`,{children:n(`setup.plan.why.noImagesNpu`)}),jn&&jn.id!==on?.id&&jn.need_gb!=null&&jn.capacity_gb!=null&&P(`li`,{children:n(`setup.plan.why.bigger`,{name:jn.name,need:NS(jn.need_gb),have:NS(jn.capacity_gb)})})]}),P(Xj,{children:V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>an?le({kind:`low_disk`}):void Mt(!1),disabled:fe||sn||On,children:[fe&&P(K,{size:13,className:`spin`,"aria-hidden":`true`}),` `,rn.length?n(`setup.plan.start`):n(`setup.plan.startNoDownload`)]})}),V(`div`,{className:`setup-row`,children:[P(`button`,{type:`button`,className:`link-btn`,onClick:Ft,disabled:On,children:n(`setup.plan.customize`)}),P(`button`,{type:`button`,className:`link-btn`,onClick:It,disabled:On,children:n(`setup.plan.cloud`)}),t&&P(`button`,{type:`button`,className:`link-btn`,onClick:t,children:n(`setup.backToGaia`)})]}),sn&&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
|
-
`)})]})]}),an&&P(`p`,{className:`setup-error`,role:`alert`,children:n(`setup.summary.short`,{need:$(an.needGb),free:$(an.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(an.freeUpGb)})}),(me??A)&&P(xN,{text:me??A})]}),V(`details`,{className:`setup-disclosure`,children:[P(`summary`,{children:n(`setup.plan.whatDownloads`)}),P(yM,{plan:L,models:rn})]})]}),ln===`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(oM,{status:oe,onStatus:H,mode:`setup`,headingId:`setup-title`,names:Zt,onBack:Rt,onSkip:()=>Nt(d),onContinue:()=>Nt(d)})]}),ln===`models`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.models.title`)}),L&&B&&P(VM,{plan:L,selection:B,onSelection:te,disabled:fe||On,onRecheck:()=>void _t()}),Lt&&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:()=>Bt(`models`),disabled:fe||On,children:n(`setup.found.changeMemory`)})]}),P(sM,{plan:L,planError:R,onRetryPlan:()=>void _t(),onUseRecommended:()=>void Tt(!1,{keepTrying:U}),selection:B,onSelection:te,cloud:!1,keepTrying:U,onKeepTrying:W,onBack:Rt,onContinue:e=>void Mt(e),busy:fe||On,error:me??A})]}),ln===`key`&&V(`form`,{id:`setup-key-form`,onSubmit:e=>{e.preventDefault(),Kt()},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:fN.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:()=>qt(e.id),disabled:F.busy||tt(e.id),title:et(e.id)?n(`settings.privacy.localOnlyBlocked`):void 0,children:[P(Lr,{size:16,"aria-hidden":`true`}),V(`span`,{children:[P(`span`,{className:`setup-choice-title`,children:P(`bdi`,{children:pN(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:uN,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:dN,target:`_blank`,rel:`noreferrer`,children:n(`setup.key.gatewayHelp`)})})}),!et(a)&&P(YA,{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(Xj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:Pt,disabled:F.busy,children:n(`setup.back`)}),V(`button`,{type:`submit`,form:`setup-key-form`,className:`btn-primary`,disabled:F.busy||tt(a)||On,children:[F.busy&&P(K,{size:13,className:`spin`}),` `,n(`setup.key.connect`)]})]})]}),ln===`download`&&!ot&&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(K,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.starting`)]})]}),ln===`download`&&ot&&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(yM,{plan:L,run:ot,onRetry:Dt,retryDisabled:fe})}),(ot.models?.length??0)>0?P(`div`,{className:O?`is-stale`:void 0,children:P(jM,{status:{...ot,overall:Oj(ot,ne??L)},names:Zt,freeGb:L?.disk?.free_gb??null,onCancel:()=>void Ht(),onRetry:(e,t)=>void Ut(e,t),onResume:e=>void Ut(e,null),onResumeAll:Dt,onSkip:e=>void Wt(e),onRestart:()=>void Gt(),busy:fe||!!O,retryLater:ct,labelledBy:`setup-title`})}):ct?V(`p`,{className:`setup-hint`,role:`status`,children:[P(K,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.working`)]}):null,An.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:An.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(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Ct(),children:n(`setup.reconnect`)})})]}),$t&&en&&!tn&&ot.state===`failed`&&!ot.model_failed&&(ot.problem?P(bN,{problem:ot.problem,onRetry:Dt,onUseGaia:()=>void Tt(!0,Me.current.options)}):V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:n(`setup.download.stoppedBeforeCheck`)}),ot.error&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:ot.error})]})]})),$t&&en&&!tn&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.download.finishNote`)}),P(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:Dt,disabled:fe,children:n(`setup.finish`)})})]}),$t&&!en&&!tn&&!(ot.models??[]).some(e=>e.state===`failed`||e.state===`cancelled`)&&V(D.Fragment,{children:[P(SN,{run:ot}),ot.problem?P(bN,{problem:ot.problem,onRetry:Dt,onUseGaia:()=>void Tt(!0,Me.current.options)}):P(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Tt(!!ot.gaia_lemonade,Me.current.options),children:n(`setup.tryAgain`)})})]}),(me||A)&&P(xN,{text:me??A})]}),ln===`test`&&ot&&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(lN,{run:ot,expected:kn,names:Zt,catalog:nn,onRetry:Dt,onChooseAnother:rt?void 0:Ft,onCancel:()=>void Ht(),onDownloadAgain:L?.lemonade.mode===`external`?void 0:e=>void Ut(e,`verify`),busy:fe}),$t&&ot.error&&!(ot.tests??[]).some(e=>e.error===ot.error)&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:ot.error})]}),(me||A)&&P(xN,{text:me??A})]}),ln===`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:Yt&&P(`p`,{children:n(rt?`setup.ready.answersCloud`:`setup.ready.answersLocal`,{model:rt?ys(Yt):Zt[Yt]??ie?.catalog?.find(e=>e.id===Yt)?.name??ys(Yt)})})}),P(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Xt(),autoFocus:!0,children:n(`setup.ready.start`)})}),!rt&&ie&&P(cM,{plan:ie,chatModel:Yt,gpu:oe}),A&&P(xN,{text:A}),(ot?.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&&!G&&P(`p`,{className:`setup-failed-extra`,role:`alert`,children:n(`setup.ready.extraNotFetched`,{names:Ee.map(e=>Zt[e]??e).join(`, `)})}),be.length>0&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.ready.tasks`)}),P(pM,{cards:be,onPick:e=>void Xt(e)})]})]})]})]},ln),t&&!ct&&ln!==`plan`&&ln!==`ready`&&P(`div`,{className:`setup-row`,children:P(`button`,{type:`button`,className:`link-btn setup-close`,onClick:t,children:n(`setup.backToGaia`)})}),On&&(Dn||ln===`plan`)&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.nav.runGoing`)}),P(PM,{run:w,before:{check:_n}})]}),P(`div`,{className:`setup-footer`,ref:m})]})}),G?.kind===`no_fit`&&P(Zj,{title:G.models.length===1?n(`setup.confirm.noFitOne`,{name:G.models[0].name}):n(`setup.confirm.noFitMany`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.pickSmaller`),onConfirm:()=>{le(null),de(!0),Mt(kt,!0)},onCancel:()=>le(null),children:G.models.map(e=>V(`p`,{children:[P(`bdi`,{children:e.name}),`: `,Fj(e,n)]},e.id))}),G?.kind===`low_disk`&&an&&P(Zj,{title:n(`setup.confirm.lowDiskTitle`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{le(null),Mt(!0)},onCancel:()=>{le(null),Ft()},children:P(`p`,{children:n(`setup.summary.short`,{need:$(an.needGb),free:$(an.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(an.freeUpGb)})})}),G?.kind===`server`&&P(Zj,{title:G.detail.code===`low_disk`?n(`setup.confirm.lowDiskTitle`):n(`setup.confirm.noFitServerTitle`),confirmLabel:G.detail.code===`low_disk`?n(`setup.confirm.downloadAnyway`):n(`setup.confirm.useAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{let e=G;if(le(null),e.then===`chat`)de(!0),Mt(kt,!0);else if(e.then===`retry`)Te(e.id,{keepTrying:U,acknowledgeLowDisk:!0}).then(E).catch(e=>he(wN(e)));else{let{gaiaLemonade:e,options:t}=Me.current;Tt(e,{...t,acknowledgeLowDisk:!0})}},onCancel:()=>{let e=G;le(null),e.then!==`retry`&&!lt&&Ft()},children:P(`p`,{children:G.detail.message})})]})}function EN(e,t,n){let r=(0,Y.useRef)(n);(0,Y.useEffect)(()=>{r.current=n});let i=(0,Y.useRef)(!1),a=(0,Y.useRef)(null);if(t&&!i.current){let e=document.activeElement;a.current=e instanceof HTMLElement?e:null}(0,Y.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 DN({title:e,titleId:t,count:n,hint:r,defaultOpen:i=!1,forceOpen:a=!1,children:o}){let[s,c]=(0,Y.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(_r,{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 ON=g(Ec()?`settings.desktop.menuBar`:`settings.desktop.tray`),kN=[{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`}],AN=new Set([`startMinimized`]),jN={minimizeToTray:`settings.desktop.keepRunningNoTray`};function MN(e){return e?.reason===`no-host`?`settings.desktop.noTray`:e?.reason===`check-failed`?`settings.desktop.noTrayCheckFailed`:null}function NN(){let e=T(),t=window.gaiaAPI?.tray,[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null);(0,Y.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,Y.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=MN(i);return P(DN,{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`)}),kN.map(({key:t,label:r,hint:i})=>{let a=AN.has(t)?d:null,o=d&&jN[t]||i;return V(`div`,{children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(r,{tray:ON})}),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:ON})}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,id:`desktop-${t}-hint`,children:a?e(a):e(o,{tray:ON})})]},t)}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o})]})})}function PN(){return window.gaiaUpdater}var FN={status:`idle`,version:null,progress:0,releaseNotes:null,error:null,currentVersion:null,pinnedVersion:null,autoUpdate:!1,includePrereleases:!1};function IN(){let[e,t]=(0,Y.useState)({...FN});return(0,Y.useEffect)(()=>{let e=PN();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 LN=`gaia-update-error:`;function RN(e,t){let n=`update.err.${e}`;return N(n)?g(n,t??{}):null}function zN(e){let t=e instanceof Error?e.message:String(e),n=t.indexOf(LN);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=RN(r.code,r.params)??r.message??r.code,a=r.note&&RN(r.note.code,r.note.params);return a?g(`update.err.withNote`,{error:i,note:a}):i}function BN(e,t){let n=zN(e);return typeof n==`object`?t(n.ref,n.params):String(n)}function VN(){return window.gaiaUpdater}function HN({onClose:e}){let t=T(),[n,r]=(0,Y.useState)({kind:`loading`}),i=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let e=VN();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.`})},[]),Lo(!0,e),sS(i,!0),(0,Y.useEffect)(()=>{let e=i.current;e&&e.querySelector(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`)?.focus()},[]),(0,Y.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=VN();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:zN(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 UN=`https://github.com/amd/gaia/releases`;function WN(e){return/^\d+\.\d+\.\d+-/.test(e??``)}function GN(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 KN(){let e=IN(),t=T(),n=PN(),[r,i]=(0,Y.useState)(!1),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.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:zN(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`)})} ${GN(e,t)}`,m=[`available`,`downloaded`,`error`].includes(e.status)||!!e.pinnedVersion||!!e.installFailed||!!e.configError||!!a;return P(DN,{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`),WN(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:UN})}),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(HN,{onClose:()=>c(!1)})]})})}var qN=[{value:`light`,label:`settings.theme.light`},{value:`dark`,label:`settings.theme.dark`},{value:`system`,label:`settings.theme.system`}],JN={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`},YN=[[`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 XN(){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=ZO(e=>e.visible),u=ZO(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:qN.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(DN,{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(JN[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(NN,{}),P(KN,{}),P(DN,{title:e(`settings.shortcuts`),children:P(`dl`,{className:`shortcut-list`,children:YN.map(([t,n])=>V(`div`,{className:`shortcut-row`,children:[P(`dt`,{children:P(`kbd`,{children:Ac(t)})}),P(`dd`,{children:e(n)})]},t))})})]})}function ZN(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 $N(e){return!!e&&!e.lemonade_running&&(QN(e.start_command)||QN(e.start_instruction))}function eP({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 tP({message:e,onRetry:t}){let n=T(),r=k(e=>$N(e.systemStatus));return ZN(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(eP,{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(_r,{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 nP({onAdded:e}){let t=T(),[n,r]=(0,Y.useState)(``),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),f=(0,Y.useRef)(``),p=(0,Y.useCallback)(async e=>{let t=n.trim();f.current=t,l(`check`),d(null);try{let n=await ln(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,Y.useCallback)(async()=>{l(`add`),d(null);try{let{report:o}=await St(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(K,{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(hr,{size:13,"aria-label":t(`settings.custom.passed`)}):P(J,{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(hr,{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(q,{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(K,{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(tP,{message:u})]})}function rP(e){return e instanceof Error?e.message:String(e)}function iP(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function aP({downloadsSlot:e}){let t=T(),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(null),b=Rs(e=>e.status),x=Rs(e=>e.started),S=(0,Y.useMemo)(()=>Fs(b,x),[b,x]),C=Rs(e=>e.error),w=Rs(e=>e.refresh),E=Rs(e=>e.enqueue),O=Rs(e=>e.cancel),k=(0,Y.useCallback)(async(e=!1)=>{a(null);try{let t=await Ce();r(t),s(n=>e||!n?_j(t):n)}catch(e){a(rP(e))}},[]);(0,Y.useEffect)(()=>{k(!0),w(),(async()=>{try{_(await Pn()??null)}catch(e){y(rP(e))}})()},[k,w]);let A=(S?.models??[]).filter(e=>e.state===`ready`).map(e=>e.id).join(`,`),j=(0,Y.useRef)(A);(0,Y.useEffect)(()=>{A!==j.current&&(j.current=A,k(!0))},[A,k]);let M=(0,Y.useMemo)(()=>{let e={};for(let t of S?.models??[])e[t.id]=t;return e},[S]),N=(0,Y.useMemo)(()=>{let e={};for(let t of n?.catalog??[])e[t.id]=t.name;return e},[n]),F=(0,Y.useMemo)(()=>n?_j(n):null,[n]),I=nj(n),L=n&&o?Sj(I,o).filter(e=>M[e.id]?.state!==`downloading`):[],ee=L.reduce((e,t)=>e+(t.size_gb??0),0),R=!!n&&!!o&&!!F&&(!iP(o.ticked,F.ticked)||o.defaultChat!==F.defaultChat||L.length>0),z=(0,Y.useCallback)(async(e,i)=>{if(!n||!o)return;if(p(null),!e){let e=Tj(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=wj(n,o);if(a&&!i)l({kind:`low_disk`,message:a.drop?t(`setup.summary.shortDrop`,{need:$(a.needGb),free:$(a.freeGb),drive:zj(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:zj(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=gt(e);if(t){l({kind:`server`,detail:t});return}throw e}for(let e of Ej(i,o))i=await pt(e.id,e.skipped);let a=Sj(nj(i),o).map(e=>e.id).filter(e=>M[e]?.state!==`downloading`);r(i),s({...o,defaultChat:i.chat_model.id}),ls.getState().refresh(),a.length&&await E(a,{acknowledgeLowDisk:!0}),p({ok:!0,text:t(`settings.models.applied`)})}catch(e){p({ok:!1,text:rP(e)})}finally{d(!1)}}},[n,o,I,m,M,E,t]),B=(0,Y.useCallback)(async e=>{l(null),d(!0),p(null);try{let n=await fn(e.id);Wo(),r(n),s(_j(n)),p({ok:!0,text:t(`settings.models.removed`,{name:e.name,size:$(n.freed_gb)})})}catch(e){p({ok:!1,text:rP(e)})}finally{d(!1)}},[t]),te=(0,Y.useCallback)((e,t)=>{(async()=>{try{t===`verify`&&await fn(e),await E([e])}catch(e){p({ok:!1,text:rP(e)})}})()},[E]),ne=!!S&&(S.models?.length??0)>0&&(OM(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(jM,{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(DN,{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(tP,{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(K,{size:13,className:`spin`,"aria-hidden":`true`}),` `,t(`setup.models.loading`)]}),n&&n.lemonade.reachable&&o&&V(D.Fragment,{children:[P(Vj,{plan:n,selection:o,onToggle:(e,t)=>s(yj(o,I,e,t)),onDefaultChat:e=>s(bj(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(Rj,{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(K,{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(tP,{message:f.text})]})}),(g?.applies||v&&!ZN(v))&&P(DN,{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(oM,{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(Zj,{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:rj(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(Zj,{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}),`: `,Fj(e,t)]},e.id))}),c?.kind===`low_disk`&&P(Zj,{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(Zj,{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 oP=`auto`;function sP({model:e}){let t=T(),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(null);(0,Y.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,Y.useCallback)(async n=>{s(!0),a(null),l(null);try{let i=await Ke(e,n===oP?null:Number(n));r(i);let a={name:i.display_name,size:i.chosen?ws(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 ZN(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(K,{size:13,className:`spin`}),` `,t(`settings.ctx.checking`)]});let d=n.chosen==null?oP: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:oP,children:n.automatic?t.bare(`settings.ctx.automaticAt`,{size:ws(n.automatic)}):t.bare(`settings.ctx.automatic`)}),n.options.map(e=>P(`option`,{value:String(e),children:t.bare(`settings.ctx.tokens`,{size:ws(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(_r,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.ctx.about`)]}),P(`span`,{className:`settings-hint`,children:t(`settings.ctx.explain`,{size:ws(n.max_fit),name:n.display_name,memory:n.memory_source})})]}),f&&P(`span`,{className:`settings-hint`,children:t(`settings.ctx.loadedAt`,{size:ws(n.loaded_ctx)})}),o&&V(`span`,{className:`settings-hint`,children:[P(K,{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 cP({row:e,providerName:t,choices:n,labels:r,disabled:i,onSwitch:a}){let o=T(),s=ls(e=>e.active),c=s?.model??null,l=!!s?.remote,u=n.some(e=>ds(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||fs(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:ws(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=>ds(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(sP,{model:c})]})}function lP({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=Es(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(_r,{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:tE(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(zM,{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(K,{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(hr,{size:13,"aria-hidden":`true`}),` `,f(`settings.model.inUse`)]}):e.available===!1?null:p?V(`span`,{className:`model-row-current`,children:[P(K,{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(K,{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(K,{size:13,className:`spin`}):null,` `,f(`settings.model.download`)]})]})]})}function uP(){let e=T(),[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(!1),l=(0,Y.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,Y.useEffect)(()=>{l(H)},[l]),!t)return r?P(`p`,{className:`settings-error`,role:`alert`,children:r}):V(`p`,{className:`settings-hint`,children:[P(K,{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:nE(t.total_usd)})}),u!=null&&V(D.Fragment,{children:[` `,e(`settings.spend.ofLimit`,{limit:nE(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(q,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.near`)]}),t.state===`reached`&&V(`div`,{className:`spending-warning`,role:`alert`,children:[V(`p`,{children:[P(q,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.reached`)]}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void l(_n),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(K,{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 dP=2e3;function fP(e,t){return e.key_source===`environment`?t(`settings.key.setIn`,{name:e.env_var??``}):`••••••••••••••••••••${e.key_hint?` ${e.key_hint}`:``}`}function pP(){let e=T(),t=ls(e=>e.active),n=ls(e=>e.select),r=ls(e=>e.refresh),i=ls(e=>e.rememberNames),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(null),l=k(e=>e.settingsProvider),[u,d]=(0,Y.useState)(l??t?.provider??`local`),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(null),[g,_]=(0,Y.useState)(``),[v,y]=(0,Y.useState)(!1),[b,x]=(0,Y.useState)(``),[S,C]=(0,Y.useState)(!1),[w,E]=(0,Y.useState)(!1),[O,A]=(0,Y.useState)({base_url:``,auth_header_name:``,auth_header_prefix:``}),[j,M]=(0,Y.useState)(null),[N,F]=(0,Y.useState)(null),[I,L]=(0,Y.useState)(null),[ee,R]=(0,Y.useState)(null),[z,B]=(0,Y.useState)(!1),[te,ne]=(0,Y.useState)(null),[re,ie]=(0,Y.useState)(null),ae=(0,Y.useRef)(u);ae.current=u;let oe=(0,Y.useRef)(!0);(0,Y.useEffect)(()=>(oe.current=!0,()=>{oe.current=!1}),[]);let H=a?.find(e=>e.id===u)??null,U=e=>e?.network?.reachable===!1,W=e=>!!e?.blocked,G=!!H&&!W(H)&&(!H.remote||!!H.models_discovered),se=(0,Y.useCallback)(async()=>{c(null);try{let e=await En();o(e.providers),e.lemonade_error&&c(e.lemonade_error)}catch(e){c(e instanceof Error?e.message:String(e))}},[]),ce=(0,Y.useCallback)(async(t,n=!1)=>{n||(p(null),h(null));try{let n=await Qt(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,Y.useEffect)(()=>{se()},[se]);let le=!!a?.some(e=>e.key_state===`waiting_for_os_permission`);(0,Y.useEffect)(()=>{if(!le)return;let e=setInterval(()=>{se()},dP);return()=>clearInterval(e)},[le,se]);let ue=t?.provider;(0,Y.useEffect)(()=>{ue&&!l&&d(ue)},[ue,l]),(0,Y.useEffect)(()=>{x(``),C(!1),E(!1),L(null),_(``),y(!1),B(!1)},[u]),(0,Y.useEffect)(()=>{G?ce(u):p(null)},[u,G,ce]);let de=(0,Y.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 zt(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 se()}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,se,H,e]),pe=(0,Y.useCallback)(async()=>{M(`forget`),E(!1),L(null);try{await qt(u),L({ok:!0,text:e(`settings.key.cleared`)}),await se(),await r()}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[u,se,r,e]),me=(0,Y.useCallback)(async t=>{M(t),L(null);try{await n(t),L({ok:!0,text:e(`settings.model.switched`,{name:fs(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,Y.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,Y.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,Y.useCallback)(async t=>{L({ok:!0,text:e(`settings.model.added`,{name:t})}),B(!0),await ce(`local`,!0)},[ce,e]),ve=!!f?.some(Es);(0,Y.useEffect)(()=>{if(ve)return()=>{r()}},[ve,r]),(0,Y.useEffect)(()=>{if(u!==`local`||!ve)return;let e=setInterval(()=>{ce(`local`,!0)},dP);return()=>clearInterval(e)},[ve,u,ce]);let ye=t?.model,be=f?.find(e=>ds(ye,e.id));(0,Y.useEffect)(()=>{be&&ne(be)},[be]);let xe=(0,Y.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=bs(f??[]),ke=!!g.trim(),Ae=e=>ds(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(lP,{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(cP,{row:be??(ds(te?.id,t?.model)?te:null),providerName:a?.find(e=>e.id===t?.provider)?.name??null,choices:G?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)||W(t)?` is-disabled`:``}`,onClick:()=>d(t.id),disabled:(U(t)||W(t))&&u!==t.id,title:W(t)?e(`settings.privacy.localOnlyBlocked`):U(t)?t.network?.detail??void 0:void 0,children:[t.remote?P(Lr,{size:14,"aria-hidden":`true`}):P(Gr,{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(tP,{message:s,onRetry:()=>{se(),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(_r,{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&&!G&&V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,children:e(`settings.model.prices`)}),P(YA,{provider:H.id})]}),W(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 se(),children:e(`settings.key.checkAgain`)})]}),H.remote&&!U(H)&&!W(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 ${G?`settings-ok`:`settings-error`}`,children:e(G?`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:fP(H,e),"aria-label":e(`settings.key.savedAria`,{name:H.name})}),!G&&V(`button`,{type:`submit`,className:`btn-primary`,disabled:j!==null,children:[j===`connect`?P(K,{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(uo,{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(K,{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&&!G&&!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(tP,{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}),G&&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&&ZN(m))&&P(tP,{message:m}),!f&&!m&&V(`p`,{className:`settings-hint`,children:[P(K,{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(DN,{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(DN,{title:e(`settings.model.groupAvailable`),count:Ne.length,defaultOpen:Me.length===0,forceOpen:ke||z||Ne.some(Es),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(DN,{title:e(`settings.model.groupUnavailable`),count:De.length,forceOpen:ke,children:P(`ul`,{className:`model-list`,children:De.map(Le)})})]}),je&&G&&P(DN,{title:e(`settings.custom.title`),children:P(nP,{onAdded:e=>void _e(e)})}),je&&G&&P(aP,{downloadsSlot:re}),H.remote&&P(uP,{})]})]})}function mP(){let e=T(),t=k(e=>e.sessions),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(null),u=(0,Y.useCallback)(async()=>{l(null);try{let e=await sn();r(e.sessions),a(e.default_mode),k.getState().setDefaultPermissionMode(e.default_mode)}catch(e){l(e instanceof Error?e.message:String(e))}},[]);(0,Y.useEffect)(()=>{u()},[u]);let d=(0,Y.useCallback)(async e=>{l(null);try{await e(),await u()}catch(e){l(e instanceof Error?e.message:String(e))}},[u]),f=(0,Y.useCallback)(async e=>{s(!1),await d(()=>At(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(_r,{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(DN,{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 Ft(t.session_id,`ask`)).mode;SE(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(()=>Zt(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(()=>Zt(t.session_id)),children:e(`settings.permissions.revokeAll`)})]},t.session_id))})]})}var hP={path:`~/.gaia/skills`},gP=[{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:hP},{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 _P({onUseSkill:e}){let t=T(),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)({}),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(``);(0,Y.useEffect)(()=>{let e=!1;return un().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=>gP.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(_r,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:t(`settings.skills.how`,hP)})]}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o}),!n&&!o&&V(`p`,{className:`settings-hint`,children:[P(K,{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?gP.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(DN,{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 vP(){let e=T(),t=k(e=>e.setShowMemoryDashboard),n=k(e=>e.closeSettings),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{vA().then(i).catch(e=>o(e instanceof Error?e.message:String(e)))},[]);let l=(0,Y.useCallback)(async()=>{if(r){c(!0),o(null);try{i(await yA({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 yP(e,t,n){if(!/^\d+$/.test(e.trim()))return!1;let r=Number(e);return r>=t&&r<=n}function bP(e){return e<1048576?`${Math.ceil(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}function xP(){let e=T(),[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(``),[a,o]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{gn().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,Y.useState)({days:!1,mb:!1}),p=!yP(r,1,365)||d.days,m=!yP(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 pn(Number(r),Number(a));n(t),c({ok:!0,text:e(`settings.undo.saved`)})}catch(t){let n=t instanceof bn&&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:bP(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 SP={root:`settings-report`,button:`btn-secondary`,hint:`settings-hint`,error:`settings-error`};function CP(){let e=T(),t=k(e=>e.sessions),n=k(e=>e.removeSession),r=gs(),i=k(e=>e.systemStatus?.data_dir),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!1),p=(0,Y.useRef)(null);(0,Y.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]),(0,Y.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,Y.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,Y.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:SP})]}),P(DN,{title:e(`settings.privacy.undo`),children:P(xP,{})}),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 wP=[{id:`needs_approval`,label:`settings.alerts.approval`},{id:`question`,label:`settings.alerts.question`},{id:`finished`,label:`settings.alerts.finished`}],TP=[{value:`banner`,label:`settings.alerts.banner`},{value:`badge`,label:`settings.alerts.badge`},{value:`off`,label:`settings.alerts.off`}],EP=[0,10,20,30,50];function DP(){return typeof Notification>`u`?`unsupported`:Notification.permission}function OP(){let e=T(),t=uc(),n=!!window.gaiaAPI,[r,i]=(0,Y.useState)(DP),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:[wP.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:TP.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(DP())})},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:EP.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 kP=[50,75,100,125,150,175,200],AP=[{accent:`american`,gender:`female`},{accent:`american`,gender:`male`},{accent:`british`,gender:`female`},{accent:`british`,gender:`male`}],jP=`settings:preview`,MP=`Hello, I'm GAIA. This is how I'll read my replies to you.`;function NP(e){return e instanceof bn?e.detail||e.message:String(e)}function PP(){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===jP),o=ES(e=>e.messageId===jP&&e.status===`loading`),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{pS().then(n).catch(e=>c(NP(e)))},[n]);let p=e=>{f(!0),u(null),ES.getState().messageId===jP&&i(),mS(e).then(n).catch(e=>u(NP(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:AP.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(jP,MP),children:[o?P(K,{size:13,className:`spin`}):P(a?oo:vo,{size:13}),e(a?`readAloud.stop`:`readAloud.settings.preview`)]})]}),P(`span`,{className:`settings-hint`,children:e(`readAloud.settings.englishOnly`)}),P(kS,{messageId:jP})]}),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:(kP.includes(t.speed)?kP:[...kP,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(K,{size:13,className:`spin`}),` `,e(`settings.loading`)]})}function FP(){let e=T(),t=k(e=>e.openSettings),n=k(e=>e.closeSettings),r=k(e=>e.runSetupAgain),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{Ce().then(a).catch(e=>l(e instanceof Error?e.message:String(e))),st().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(xr,{size:14,className:`settings-setup-chevron`,"aria-hidden":`true`})]},e.label))]},e.title)),u&&P(Zj,{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 IP=class extends Y.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidUpdate(e){this.state.hasError&&e.resetKey!==this.props.resetKey&&this.setState({hasError:!1})}componentDidCatch(e,t){console.error(`[ErrorBoundary] ${this.props.area} failed to render:`,e,t.componentStack)}render(){return this.state.hasError?P(LP,{variant:this.props.variant??`fill`,onRetry:()=>this.setState({hasError:!1})}):this.props.children}};function LP({onRetry:e,variant:t}){let n=T();return V(`div`,{role:`alert`,className:`error-boundary error-boundary-${t}`,children:[P(`p`,{className:`error-boundary-title`,children:n(`errorBoundary.title`)}),P(`p`,{className:`error-boundary-body`,children:n(t===`window`?`errorBoundary.bodyWindow`:`errorBoundary.body`)}),V(`div`,{className:`error-boundary-actions`,children:[P(`button`,{type:`button`,className:`btn-primary`,onClick:e,children:n(`errorBoundary.retry`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>window.location.reload(),children:n(`errorBoundary.reload`)})]})]})}var RP=`modulepreload`,zP=function(e,t){return new URL(e,t).href},BP={},VP=function(e){return e.pathname.endsWith(`.css`)},HP=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},UP=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=zP(t,n);let r=s(t),i=VP(r);return HP(BP,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`:RP,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)})},WP=(0,Y.lazy)(()=>UP(()=>import(`./ConnectorsPane-DbsiVn90.js`).then(e=>({default:e.ConnectorsPane})),__vite__mapDeps([0,1,2,3,4]),import.meta.url)),GP=(0,Y.lazy)(()=>UP(()=>import(`./AdvancedSettings-BoC1tuaH.js`).then(e=>({default:e.AdvancedSettings})),__vite__mapDeps([5,1,2,3]),import.meta.url)),KP=[`general`,`setup`,`model`,`permissions`,`skills`,`connectors`,`memory`,`notifications`,`voice`,`privacy`,`advanced`];function qP({onUseSkill:e}){let t=T(),n=k(e=>e.settingsSection),r=k(e=>e.openSettings),i=k(e=>e.closeSettings),a=(0,Y.useRef)(null),o=n!==null;if(Lo(o,i),sS(a,o),EN(a,o,()=>a.current?.querySelector(`.settings-nav-item.is-active`)),!n)return null;let s=(()=>{switch(n){case`general`:return P(XN,{});case`setup`:return P(FP,{});case`model`:return P(pP,{});case`permissions`:return P(mP,{});case`skills`:return P(_P,{onUseSkill:t=>{i(),e(t)}});case`connectors`:return P(WP,{});case`memory`:return P(vP,{});case`notifications`:return P(OP,{});case`voice`:return P(PP,{});case`privacy`:return P(CP,{});case`advanced`:return P(GP,{})}})();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`)}),KP.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(J,{size:18})}),P(`div`,{className:`settings-scroll`,children:P(IP,{area:`settings.${n}`,children:P(Y.Suspense,{fallback:V(`p`,{className:`settings-hint`,children:[P(K,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),children:s})},n)})]})]})})}var JP=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 YP(e){let t=window.gaiaAPI?.backend;if(!t)return()=>{};let n=t=>{let n=JP.getState().lifecycle?.status;JP.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 XP(e,t){let[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(null),c=(0,Y.useRef)(null),l=(0,Y.useRef)(null),u=(0,Y.useRef)(null),f=(0,Y.useCallback)(()=>{c.current&&=(clearTimeout(c.current),null),l.current&&=(clearTimeout(l.current),null),u.current&&=(clearInterval(u.current),null)},[]);(0,Y.useEffect)(()=>f,[f]);let p=(0,Y.useCallback)((e,t)=>{u.current&&clearInterval(u.current),u.current=setInterval(async()=>{try{let n=await Pt();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{}},Rc)},[]),m=e??`Gemma-4-E4B-it-GGUF`;return(0,Y.useEffect)(()=>s(null),[m]),{isLoadingModel:n,isDownloadingModel:i,downloadError:o,loadModel:(0,Y.useCallback)(async(e,t)=>{let n=e??m,i=t??32768;r(!0);try{if(!await Bt(n,i)){r(!1);return}d.system.info(`Load model triggered: ${n} (ctx=${i})`),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>r(!1),Ic),p(n,`load`)}catch(e){d.system.error(`Failed to trigger model load`,e),r(!1)}},[m,t,p]),downloadModel:(0,Y.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),Lc),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 ZP({onRetry:e,label:t,busyLabel:n=`Checking…`}){let[r,i]=(0,Y.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 QP(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function $P({lifecycle:e}){let t=T(),n=JP(e=>e.restart),r=JP(e=>e.restartError),i=e.status===`restarting`,[a,o]=(0,Y.useState)(()=>Date.now());if((0,Y.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(K,{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:QP(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(q,{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(ZP,{onRetry:n,label:t(`banner.restartButton`),busyLabel:t(`banner.restartingShort`)})]})}function eF({onRetry:e,backendSlow:t=!1,backendError:n=null}){let r=T(),{backendConnected:i,systemStatus:a,currentSessionId:o,messages:s}=k(),c=JP(e=>e.lifecycle),[l,u]=(0,Y.useState)(!1),d=!!o&&s.length>0,f=a?.default_model_name??`Gemma-4-E4B-it-GGUF`,{isDownloadingModel:p,downloadError:m,downloadModel:h}=XP(f),g=ls(e=>e.pickLoad),_=ls(e=>e.retryPickLoad),v=ls(e=>e.dismissPickLoad);us();let y=(0,Y.useRef)(a?.lemonade_running),b=(0,Y.useRef)(a?.model_downloaded),x=(0,Y.useRef)(a?.context_size_sufficient),S=(0,Y.useRef)(a?.expected_model_loaded);if((0,Y.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($P,{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?q:Yr,{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(K,{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(J,{size:14})})]})}if(g){let e=fs(g.model);return g.error?V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{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(ZP,{onRetry:_,label:r(`banner.pickLoad.retry`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:v,"aria-label":r(`banner.dismiss`),children:P(J,{size:14})})]}):V(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(K,{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(Gw(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(K,{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(bo,{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(ZP,{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(q,{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(ZP,{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(q,{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(ZP,{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(q,{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(ZP,{onRetry:e,label:`Check again`})]});if(a&&!a.lemonade_running){let t=Kw(a)===`unresponsive`,n=$N(a);return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{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(eP,{className:`connection-banner__retry`}),e&&P(ZP,{onRetry:e,label:r(`settings.key.checkAgain`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(J,{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(Yi,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`LLM context window is too small (`,t.toLocaleString(),` tokens;`,` `,Pc.toLocaleString(),` required).`,` `,P(`span`,{className:`connection-banner__hint`,children:`Reload it with a larger context in Settings → Advanced.`})]}),e&&P(ZP,{onRetry:e,label:`Check again`}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(J,{size:14})})]})}return null}function tF(){let e=IN(),t=T(),[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(null),o=(0,Y.useCallback)(e=>{let n=PN();n&&(a(null),n[e]().catch(n=>{d.system.error(`Update ${e} failed`,n),a(BN(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(q,{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(J,{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(q,{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(J,{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(Yr,{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(Yr,{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(J,{size:11})})]}):e.status===`downloaded`?V(`div`,{className:`update-chip update-chip--ready`,role:`status`,"aria-live":`polite`,children:[P(Ia,{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(q,{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(J,{size:11})})]}):null}var nF={permission_request:{icon:P(Ka,{size:16}),colorClass:`notif-type-permission`},policy_alert:{icon:P(Ka,{size:16}),colorClass:`notif-type-policy`},security_alert:{icon:P(q,{size:16}),colorClass:`notif-type-security`},status_change:{icon:P(Dr,{size:16}),colorClass:`notif-type-status`},info:{icon:P(Ui,{size:16}),colorClass:`notif-type-info`},error:{icon:P(Tr,{size:16}),colorClass:`notif-type-error`}};function rF(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 iF({onClose:e}){let t=T(),n=$s(Ao(tc)),r=$s(ec),i=$s(e=>e.markRead),a=$s(e=>e.markAllRead),o=$s(e=>e.clearAll),s=$s(e=>e.dismiss),c=$s(e=>e.respondToPermission),l=$s(e=>e.typeFilter),u=$s(e=>e.setTypeFilter),d=(0,Y.useCallback)(e=>{i(e)},[i]),f=(0,Y.useCallback)(e=>{c(e.id,`allow`).catch(e=>console.error(`[NotificationCenter] allow failed:`,e))},[c]),p=(0,Y.useCallback)(e=>{c(e.id,`deny`).catch(e=>console.error(`[NotificationCenter] deny failed:`,e))},[c]);Lo(!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(J,{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(tr,{size:40,strokeWidth:1.2}),P(`span`,{children:t(`notifications.empty`)})]}):n.map(e=>{let n=nF[e.type],r=e.type===`permission_request`&&e.tool?qs(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:rF(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(hr,{size:14}),t(`notifications.approve`)]}),V(`button`,{className:`notification-action-btn notification-action-deny`,onClick:t=>{t.stopPropagation(),p(e)},children:[P(J,{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(J,{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(hr,{size:14}),t(`notifications.markAllRead`)]}),V(`button`,{className:`notification-footer-btn notification-footer-clear`,onClick:o,children:[P(uo,{size:14}),t(`notifications.clear`)]})]})]})}var aF=1500,oF=e=>new Promise(t=>setTimeout(t,e));async function sF({onProgress:e,isCancelled:t=()=>!1,pollMs:n=aF}={}){try{await cn(fk)}catch(e){if(e?.httpStatus!==409)throw e;let t=await Wt(fk).catch(()=>null);if(!t||t.status===`completed`||t.status===`failed`)throw e}for(;!t();){let t=await Wt(fk);if(e?.(t),t.status===`completed`)return;if(t.status===`failed`)throw Error(t.error||`The GAIA agent could not be installed.`);await oF(n)}}function cF({onInstalled:e,noBuild:t=!1}){let n=T(),[r,i]=(0,Y.useState)({kind:`idle`}),a=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>()=>{a.current=!0},[]);let o=(0,Y.useCallback)(async()=>{i({kind:`installing`,percent:0});try{if(await sF({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 lF(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 uF(e,t){let{addNotification:n}=$s.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 dF=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 jt()).schedules||[],r=t().errorCounts;r&&uF(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 bt(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 dt(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:lF(n,`Failed to update schedule`)})}},runScheduleNow:async t=>{try{let n=await Yt(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:lF(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:lF(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})})),fF=new Set([`loading_model`,`downloading_model`,`model_retry`,`waiting`]),pF=5;function mF(e,t){return{id:e,title:t.get(e)?.title??`Untitled chat`}}function hF(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=>({...mF(e,t),reason:`approval`}));n&&e.awaitingUser&&!a.has(e.currentSessionId)&&o.push({...mF(e.currentSessionId,t),reason:`answer`});for(let[n,r]of Object.entries(e.awaitingBySession))o.some(e=>e.id===n)||o.push({...mF(n,t),reason:r===`question`?`answer`:`approval`});let s=n&&!e.awaitingUser&&e.livePhase&&fF.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,pF).map(e=>mF(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=>mF(e,t)),needsYou:o,recent:u}}function gF(e){let t=(0,Y.useRef)(e);t.current=e,(0,Y.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:$s.getState().notifications},a=r;if(r=i,a&&Object.keys(i).every(e=>i[e]===a[e]))return;let o=hF(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=$s.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 _F(){(0,Y.useEffect)(()=>{let e=window.gaiaAPI;if(!e)return;let t=$s.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 vF(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 yF(){let[e,t]=(0,Y.useState)(null);return(0,Y.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 bF(){_F();let e=k(e=>e.runningSessionIds),t=k(e=>e.awaitingBySession),n=k(e=>e.sessions),r=k(e=>e.currentSessionId),i=$s(Ao(rc)),a=uc(),o=yF(),s=(0,Y.useRef)(null),c=_c(e,t,i),l=JSON.stringify(c);(0,Y.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 vc(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`||xc(s,r,i))&&(o=!0,t===`banner`)){if(c!==`finished`){let{title:t,body:n}=bc(c,e);vF(s,t,n)}else ht(s).then(e=>{k.getState().updateSessionInList(s,e);let{title:t,body:n}=bc(c,e);vF(s,t,n)}).catch(t=>{d.system.error(`Could not read how chat ${s} ended`,t);let{title:n,body:r}=bc(c,{...e,last_run_status:null});vF(s,n,r)})}}if(o){if(a.sound)try{wc()}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=Sc(n,c,a.modes,r);(0,Y.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&&Cc(o,a.batteryFloor);(0,Y.useEffect)(()=>{window.gaiaAPI?.power.setKeepAwake(f).catch(e=>d.system.error(`Could not change keep-awake`,e))},[f])}function xF(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 SF(e){return e.replace(/-/g,``).slice(0,7)}function CF(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 wF(e,t,n){return!e||t&&(e===t||e===SF(t))?null:n.some(t=>t.id===e)?e:CF(n,e)}function TF(e){return new URLSearchParams(e.search).get(`session`)||e.hash.replace(/^#/,``)||null}var EF=`gaia:last-session`;function DF(e){try{e?localStorage.setItem(EF,e):localStorage.removeItem(EF)}catch(e){d.ui.warn(`Could not save the open chat for the next launch`,e)}}function OF(){try{return localStorage.getItem(EF)}catch(e){return d.ui.warn(`Could not read the chat open at last launch`,e),null}}var kF=1e3,AF=3e4;function jF(e,{initialMs:t=kF,maxMs:n=AF,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 MF(e,t,n){return e&&!t&&!n}var NF=(0,Y.lazy)(()=>UP(()=>import(`./MemoryDashboard-B0WUgGUQ.js`).then(e=>({default:e.MemoryDashboard})),__vite__mapDeps([6,1,2,7,8]),import.meta.url)),PF=(0,Y.lazy)(()=>UP(()=>import(`./ScheduleManager-DBmyJkoF.js`).then(e=>({default:e.ScheduleManager})),__vite__mapDeps([9,1,2,7,3,10]),import.meta.url)),FF=(0,Y.lazy)(()=>UP(()=>import(`./DocumentLibrary-CTJeAYzK.js`).then(e=>({default:e.DocumentLibrary})),__vite__mapDeps([11,1,2,3,12]),import.meta.url)),IF=(0,Y.lazy)(()=>UP(()=>import(`./FileBrowser-BmXmrO_H.js`).then(e=>({default:e.FileBrowser})),__vite__mapDeps([13,1,2,3,14]),import.meta.url)),LF=(0,Y.lazy)(()=>UP(()=>import(`./MobileAccessModal-Ce_pSNV0.js`).then(e=>({default:e.MobileAccessModal})),__vite__mapDeps([15,1,2,3,16]),import.meta.url)),RF=3,zF=3e5,BF=6e3,VF=6e4,HF=e=>e instanceof TypeError,UF=e=>new Promise(t=>setTimeout(t,e)),WF=3e5,GF=class extends Error{};async function KF(){let e=Date.now()+WF;for(;;){let t=await it();if(t.state===`ready`)return;if(t.state===`failed`||t.state===`cancelled`)throw new GF(t.error||I().bare(`setup.upgrading.stopped`));if(Date.now()>=e)throw Error(I().bare(`setup.upgrading.slow`));await UF(kF)}}function qF(){return P(`div`,{className:`loading-spinner`,role:`status`,"aria-label":`Loading`})}var JF=e=>e===1||e%10==0;function YF(){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=ls(e=>e.restoreNotice),E=ls(e=>e.dismissRestoreNotice),D=$s(e=>e.showPanel),O=k(e=>e.systemStatus?.initialized===!0),A=(0,Y.useRef)(!1),j=$s(e=>e.setShowPanel);(0,Y.useEffect)(()=>{if(!w?.ok)return;let e=setTimeout(E,BF);return()=>clearTimeout(e)},[w,E]);let[M,N]=(0,Y.useState)({state:`checking`}),F=k(e=>e.setupAgain),I=k(e=>e.runSetupAgain),ee=(0,Y.useRef)(M);ee.current=M;let[R,z]=(0,Y.useState)(!1),B=(0,Y.useRef)(R);B.current=R;let[te,ne]=(0,Y.useState)(!1),[re,ie]=(0,Y.useState)(!1),ae=te||R&&!pk(v),oe=(0,Y.useRef)(ae);oe.current=ae;let[H,W]=(0,Y.useState)(null),[G,se]=(0,Y.useState)(``),[ce,le]=(0,Y.useState)(0),[de,fe]=(0,Y.useState)(!1),[pe,me]=(0,Y.useState)(!1),[he,ge]=(0,Y.useState)(null),[_e,ve]=(0,Y.useState)(null),ye=(0,Y.useRef)(async()=>{}),be=(0,Y.useRef)(async()=>{}),xe=(0,Y.useCallback)(async(e=!1,t=!1)=>{e||N({state:`checking`});let n=0;try{for(;;){await ls.getState().refresh();let e=!!ls.getState().active?.remote,r;try{r=await Gt(e)}catch(e){if(!t||!HF(e)||n>=VF)throw e;await UF(kF),n+=kF;continue}if(!r.ready&&r.stage===`upgrade`){N({state:`upgrading`});let t=await it();(!t.upgrade_embedded||t.state!==`running`&&t.state!==`verifying`)&&await vt(e,!1,{upgradeEmbedded:!0}),await KF(),r=await Gt(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 GF){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,Y.useRef)(0),Ce=(0,Y.useCallback)(async()=>{let e=++Se.current,t=(await yn()).agents||[];e===Se.current&&(_(t),z(!0),pk(t)&&ne(!1))},[_]),we=(0,Y.useCallback)(()=>{let e=B.current;z(!1),Ce().catch(t=>{d.api.warn(`Agent list unavailable after setup`,t),e&&z(!0)})},[Ce]);(0,Y.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,Y.useCallback)(async()=>{b((await sn()).default_mode)},[b]),Ee=(0,Y.useRef)([]);(0,Y.useEffect)(()=>{m(`0.26.0rc13`),xe(!1,!0);let e=[jF(Ce,{onError:(e,t)=>{JF(t)&&d.api.warn(`Agent list unavailable (attempt ${t}); retrying`,e)}}),jF(Te,{onError:(e,t)=>{JF(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,Y.useCallback)(()=>{Ee.current.forEach(e=>e.kick()),ls.getState().retryNow(),be.current();let e=ee.current;e.state===`unknown`&&!e.upgradeFailed&&xe(!0)},[xe]),Oe=(0,Y.useRef)(De);Oe.current=De;let ke=(0,Y.useRef)(0),Ae=(0,Y.useRef)(0),je=(0,Y.useRef)(null),Me=(0,Y.useRef)(!1),[Ne,Pe]=(0,Y.useState)(!1),[Fe,Ie]=(0,Y.useState)(null),Le=(0,Y.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>=zF){Pe(!1),g(!1),h(null);return}g(!0),(Me.current||Ae.current>=RF)&&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>=RF||!n?.lemonade_running?h(t):h({...n,download_progress:t.download_progress})},[g,h]),Re=(0,Y.useRef)(Le);Re.current=Le;let[ze]=(0,Y.useState)(()=>Yw(e=>Re.current(e))),Be=ze.check;ye.current=Be,(0,Y.useEffect)(()=>xk(ze.start),[ze]),(0,Y.useEffect)(()=>YP(()=>{Be()}),[Be]);let Ve=(0,Y.useRef)(``);(0,Y.useEffect)(()=>{let e=e=>It().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
|
+
`)})]})]}),an&&P(`p`,{className:`setup-error`,role:`alert`,children:n(`setup.summary.short`,{need:$(an.needGb),free:$(an.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(an.freeUpGb)})}),(me??A)&&P(xN,{text:me??A})]}),V(`details`,{className:`setup-disclosure`,children:[P(`summary`,{children:n(`setup.plan.whatDownloads`)}),P(yM,{plan:L,models:rn})]})]}),ln===`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(oM,{status:oe,onStatus:H,mode:`setup`,headingId:`setup-title`,names:Zt,onBack:Rt,onSkip:()=>Nt(d),onContinue:()=>Nt(d)})]}),ln===`models`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.models.title`)}),L&&B&&P(VM,{plan:L,selection:B,onSelection:te,disabled:fe||On,onRecheck:()=>void _t()}),Lt&&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:()=>Bt(`models`),disabled:fe||On,children:n(`setup.found.changeMemory`)})]}),P(sM,{plan:L,planError:R,onRetryPlan:()=>void _t(),onUseRecommended:()=>void Tt(!1,{keepTrying:U}),selection:B,onSelection:te,cloud:!1,keepTrying:U,onKeepTrying:W,onBack:Rt,onContinue:e=>void Mt(e),busy:fe||On,error:me??A})]}),ln===`key`&&V(`form`,{id:`setup-key-form`,onSubmit:e=>{e.preventDefault(),Kt()},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:fN.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:()=>qt(e.id),disabled:F.busy||tt(e.id),title:et(e.id)?n(`settings.privacy.localOnlyBlocked`):void 0,children:[P(Lr,{size:16,"aria-hidden":`true`}),V(`span`,{children:[P(`span`,{className:`setup-choice-title`,children:P(`bdi`,{children:pN(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:uN,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:dN,target:`_blank`,rel:`noreferrer`,children:n(`setup.key.gatewayHelp`)})})}),!et(a)&&P(YA,{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(Xj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:Pt,disabled:F.busy,children:n(`setup.back`)}),V(`button`,{type:`submit`,form:`setup-key-form`,className:`btn-primary`,disabled:F.busy||tt(a)||On,children:[F.busy&&P(K,{size:13,className:`spin`}),` `,n(`setup.key.connect`)]})]})]}),ln===`download`&&!ot&&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(K,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.starting`)]})]}),ln===`download`&&ot&&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(yM,{plan:L,run:ot,onRetry:Dt,retryDisabled:fe})}),(ot.models?.length??0)>0?P(`div`,{className:O?`is-stale`:void 0,children:P(jM,{status:{...ot,overall:Oj(ot,ne??L)},names:Zt,freeGb:L?.disk?.free_gb??null,onCancel:()=>void Ht(),onRetry:(e,t)=>void Ut(e,t),onResume:e=>void Ut(e,null),onResumeAll:Dt,onSkip:e=>void Wt(e),onRestart:()=>void Gt(),busy:fe||!!O,retryLater:ct,labelledBy:`setup-title`})}):ct?V(`p`,{className:`setup-hint`,role:`status`,children:[P(K,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.working`)]}):null,An.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:An.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(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Ct(),children:n(`setup.reconnect`)})})]}),$t&&en&&!tn&&ot.state===`failed`&&!ot.model_failed&&(ot.problem?P(bN,{problem:ot.problem,onRetry:Dt,onUseGaia:()=>void Tt(!0,Me.current.options)}):V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:n(`setup.download.stoppedBeforeCheck`)}),ot.error&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:ot.error})]})]})),$t&&en&&!tn&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.download.finishNote`)}),P(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:Dt,disabled:fe,children:n(`setup.finish`)})})]}),$t&&!en&&!tn&&!(ot.models??[]).some(e=>e.state===`failed`||e.state===`cancelled`)&&V(D.Fragment,{children:[P(SN,{run:ot}),ot.problem?P(bN,{problem:ot.problem,onRetry:Dt,onUseGaia:()=>void Tt(!0,Me.current.options)}):P(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Tt(!!ot.gaia_lemonade,Me.current.options),children:n(`setup.tryAgain`)})})]}),(me||A)&&P(xN,{text:me??A})]}),ln===`test`&&ot&&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(lN,{run:ot,expected:kn,names:Zt,catalog:nn,onRetry:Dt,onChooseAnother:rt?void 0:Ft,onCancel:()=>void Ht(),onDownloadAgain:L?.lemonade.mode===`external`?void 0:e=>void Ut(e,`verify`),busy:fe}),$t&&ot.error&&!(ot.tests??[]).some(e=>e.error===ot.error)&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:ot.error})]}),(me||A)&&P(xN,{text:me??A})]}),ln===`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:Yt&&P(`p`,{children:n(rt?`setup.ready.answersCloud`:`setup.ready.answersLocal`,{model:rt?ys(Yt):Zt[Yt]??ie?.catalog?.find(e=>e.id===Yt)?.name??ys(Yt)})})}),P(Xj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Xt(),autoFocus:!0,children:n(`setup.ready.start`)})}),!rt&&ie&&P(cM,{plan:ie,chatModel:Yt,gpu:oe}),A&&P(xN,{text:A}),(ot?.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&&!G&&P(`p`,{className:`setup-failed-extra`,role:`alert`,children:n(`setup.ready.extraNotFetched`,{names:Ee.map(e=>Zt[e]??e).join(`, `)})}),be.length>0&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.ready.tasks`)}),P(pM,{cards:be,onPick:e=>void Xt(e)})]})]})]})]},ln),t&&!ct&&ln!==`plan`&&ln!==`ready`&&P(`div`,{className:`setup-row`,children:P(`button`,{type:`button`,className:`link-btn setup-close`,onClick:t,children:n(`setup.backToGaia`)})}),On&&(Dn||ln===`plan`)&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.nav.runGoing`)}),P(PM,{run:w,before:{check:_n}})]}),P(`div`,{className:`setup-footer`,ref:m})]})}),G?.kind===`no_fit`&&P(Zj,{title:G.models.length===1?n(`setup.confirm.noFitOne`,{name:G.models[0].name}):n(`setup.confirm.noFitMany`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.pickSmaller`),onConfirm:()=>{le(null),de(!0),Mt(kt,!0)},onCancel:()=>le(null),children:G.models.map(e=>V(`p`,{children:[P(`bdi`,{children:e.name}),`: `,Fj(e,n)]},e.id))}),G?.kind===`low_disk`&&an&&P(Zj,{title:n(`setup.confirm.lowDiskTitle`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{le(null),Mt(!0)},onCancel:()=>{le(null),Ft()},children:P(`p`,{children:n(`setup.summary.short`,{need:$(an.needGb),free:$(an.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(an.freeUpGb)})})}),G?.kind===`server`&&P(Zj,{title:G.detail.code===`low_disk`?n(`setup.confirm.lowDiskTitle`):n(`setup.confirm.noFitServerTitle`),confirmLabel:G.detail.code===`low_disk`?n(`setup.confirm.downloadAnyway`):n(`setup.confirm.useAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{let e=G;if(le(null),e.then===`chat`)de(!0),Mt(kt,!0);else if(e.then===`retry`)Te(e.id,{keepTrying:U,acknowledgeLowDisk:!0}).then(E).catch(e=>he(wN(e)));else{let{gaiaLemonade:e,options:t}=Me.current;Tt(e,{...t,acknowledgeLowDisk:!0})}},onCancel:()=>{let e=G;le(null),e.then!==`retry`&&!lt&&Ft()},children:P(`p`,{children:G.detail.message})})]})}function EN(e,t,n){let r=(0,Y.useRef)(n);(0,Y.useEffect)(()=>{r.current=n});let i=(0,Y.useRef)(!1),a=(0,Y.useRef)(null);if(t&&!i.current){let e=document.activeElement;a.current=e instanceof HTMLElement?e:null}(0,Y.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 DN({title:e,titleId:t,count:n,hint:r,defaultOpen:i=!1,forceOpen:a=!1,children:o}){let[s,c]=(0,Y.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(_r,{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 ON=g(Ec()?`settings.desktop.menuBar`:`settings.desktop.tray`),kN=[{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`}],AN=new Set([`startMinimized`]),jN={minimizeToTray:`settings.desktop.keepRunningNoTray`};function MN(e){return e?.reason===`no-host`?`settings.desktop.noTray`:e?.reason===`check-failed`?`settings.desktop.noTrayCheckFailed`:null}function NN(){let e=T(),t=window.gaiaAPI?.tray,[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null);(0,Y.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,Y.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=MN(i);return P(DN,{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`)}),kN.map(({key:t,label:r,hint:i})=>{let a=AN.has(t)?d:null,o=d&&jN[t]||i;return V(`div`,{children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(r,{tray:ON})}),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:ON})}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,id:`desktop-${t}-hint`,children:a?e(a):e(o,{tray:ON})})]},t)}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o})]})})}function PN(){return window.gaiaUpdater}var FN={status:`idle`,version:null,progress:0,releaseNotes:null,error:null,currentVersion:null,pinnedVersion:null,autoUpdate:!1,includePrereleases:!1};function IN(){let[e,t]=(0,Y.useState)({...FN});return(0,Y.useEffect)(()=>{let e=PN();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 LN=`gaia-update-error:`;function RN(e,t){let n=`update.err.${e}`;return N(n)?g(n,t??{}):null}function zN(e){let t=e instanceof Error?e.message:String(e),n=t.indexOf(LN);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=RN(r.code,r.params)??r.message??r.code,a=r.note&&RN(r.note.code,r.note.params);return a?g(`update.err.withNote`,{error:i,note:a}):i}function BN(e,t){let n=zN(e);return typeof n==`object`?t(n.ref,n.params):String(n)}function VN(){return window.gaiaUpdater}function HN({onClose:e}){let t=T(),[n,r]=(0,Y.useState)({kind:`loading`}),i=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let e=VN();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.`})},[]),Lo(!0,e),sS(i,!0),(0,Y.useEffect)(()=>{let e=i.current;e&&e.querySelector(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`)?.focus()},[]),(0,Y.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=VN();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:zN(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 UN=`https://github.com/amd/gaia/releases`;function WN(e){return/^\d+\.\d+\.\d+-/.test(e??``)}function GN(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 KN(){let e=IN(),t=T(),n=PN(),[r,i]=(0,Y.useState)(!1),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.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:zN(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`)})} ${GN(e,t)}`,m=[`available`,`downloaded`,`error`].includes(e.status)||!!e.pinnedVersion||!!e.installFailed||!!e.configError||!!a;return P(DN,{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`),WN(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:UN})}),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(HN,{onClose:()=>c(!1)})]})})}var qN=[{value:`light`,label:`settings.theme.light`},{value:`dark`,label:`settings.theme.dark`},{value:`system`,label:`settings.theme.system`}],JN={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`},YN=[[`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 XN(){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=ZO(e=>e.visible),u=ZO(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:qN.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(DN,{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(JN[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(NN,{}),P(KN,{}),P(DN,{title:e(`settings.shortcuts`),children:P(`dl`,{className:`shortcut-list`,children:YN.map(([t,n])=>V(`div`,{className:`shortcut-row`,children:[P(`dt`,{children:P(`kbd`,{children:Ac(t)})}),P(`dd`,{children:e(n)})]},t))})})]})}function ZN(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 $N(e){return!!e&&!e.lemonade_running&&(QN(e.start_command)||QN(e.start_instruction))}function eP({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 tP({message:e,onRetry:t}){let n=T(),r=k(e=>$N(e.systemStatus));return ZN(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(eP,{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(_r,{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 nP({onAdded:e}){let t=T(),[n,r]=(0,Y.useState)(``),[i,a]=(0,Y.useState)(``),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),f=(0,Y.useRef)(``),p=(0,Y.useCallback)(async e=>{let t=n.trim();f.current=t,l(`check`),d(null);try{let n=await ln(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,Y.useCallback)(async()=>{l(`add`),d(null);try{let{report:o}=await St(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(K,{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(hr,{size:13,"aria-label":t(`settings.custom.passed`)}):P(J,{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(hr,{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(q,{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(K,{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(tP,{message:u})]})}function rP(e){return e instanceof Error?e.message:String(e)}function iP(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function aP({downloadsSlot:e}){let t=T(),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(null),b=Rs(e=>e.status),x=Rs(e=>e.started),S=(0,Y.useMemo)(()=>Fs(b,x),[b,x]),C=Rs(e=>e.error),w=Rs(e=>e.refresh),E=Rs(e=>e.enqueue),O=Rs(e=>e.cancel),k=(0,Y.useCallback)(async(e=!1)=>{a(null);try{let t=await Ce();r(t),s(n=>e||!n?_j(t):n)}catch(e){a(rP(e))}},[]);(0,Y.useEffect)(()=>{k(!0),w(),(async()=>{try{_(await Pn()??null)}catch(e){y(rP(e))}})()},[k,w]);let A=(S?.models??[]).filter(e=>e.state===`ready`).map(e=>e.id).join(`,`),j=(0,Y.useRef)(A);(0,Y.useEffect)(()=>{A!==j.current&&(j.current=A,k(!0))},[A,k]);let M=(0,Y.useMemo)(()=>{let e={};for(let t of S?.models??[])e[t.id]=t;return e},[S]),N=(0,Y.useMemo)(()=>{let e={};for(let t of n?.catalog??[])e[t.id]=t.name;return e},[n]),F=(0,Y.useMemo)(()=>n?_j(n):null,[n]),I=nj(n),L=n&&o?Sj(I,o).filter(e=>M[e.id]?.state!==`downloading`):[],ee=L.reduce((e,t)=>e+(t.size_gb??0),0),R=!!n&&!!o&&!!F&&(!iP(o.ticked,F.ticked)||o.defaultChat!==F.defaultChat||L.length>0),z=(0,Y.useCallback)(async(e,i)=>{if(!n||!o)return;if(p(null),!e){let e=Tj(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=wj(n,o);if(a&&!i)l({kind:`low_disk`,message:a.drop?t(`setup.summary.shortDrop`,{need:$(a.needGb),free:$(a.freeGb),drive:zj(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:zj(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=gt(e);if(t){l({kind:`server`,detail:t});return}throw e}for(let e of Ej(i,o))i=await pt(e.id,e.skipped);let a=Sj(nj(i),o).map(e=>e.id).filter(e=>M[e]?.state!==`downloading`);r(i),s({...o,defaultChat:i.chat_model.id}),ls.getState().refresh(),a.length&&await E(a,{acknowledgeLowDisk:!0}),p({ok:!0,text:t(`settings.models.applied`)})}catch(e){p({ok:!1,text:rP(e)})}finally{d(!1)}}},[n,o,I,m,M,E,t]),B=(0,Y.useCallback)(async e=>{l(null),d(!0),p(null);try{let n=await fn(e.id);Wo(),r(n),s(_j(n)),p({ok:!0,text:t(`settings.models.removed`,{name:e.name,size:$(n.freed_gb)})})}catch(e){p({ok:!1,text:rP(e)})}finally{d(!1)}},[t]),te=(0,Y.useCallback)((e,t)=>{(async()=>{try{t===`verify`&&await fn(e),await E([e])}catch(e){p({ok:!1,text:rP(e)})}})()},[E]),ne=!!S&&(S.models?.length??0)>0&&(OM(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(jM,{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(DN,{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(tP,{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(K,{size:13,className:`spin`,"aria-hidden":`true`}),` `,t(`setup.models.loading`)]}),n&&n.lemonade.reachable&&o&&V(D.Fragment,{children:[P(Vj,{plan:n,selection:o,onToggle:(e,t)=>s(yj(o,I,e,t)),onDefaultChat:e=>s(bj(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(Rj,{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(K,{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(tP,{message:f.text})]})}),(g?.applies||v&&!ZN(v))&&P(DN,{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(oM,{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(Zj,{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:rj(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(Zj,{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}),`: `,Fj(e,t)]},e.id))}),c?.kind===`low_disk`&&P(Zj,{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(Zj,{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 oP=`auto`;function sP({model:e}){let t=T(),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(null);(0,Y.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,Y.useCallback)(async n=>{s(!0),a(null),l(null);try{let i=await Ke(e,n===oP?null:Number(n));r(i);let a={name:i.display_name,size:i.chosen?ws(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 ZN(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(K,{size:13,className:`spin`}),` `,t(`settings.ctx.checking`)]});let d=n.chosen==null?oP: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:oP,children:n.automatic?t.bare(`settings.ctx.automaticAt`,{size:ws(n.automatic)}):t.bare(`settings.ctx.automatic`)}),n.options.map(e=>P(`option`,{value:String(e),children:t.bare(`settings.ctx.tokens`,{size:ws(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(_r,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.ctx.about`)]}),P(`span`,{className:`settings-hint`,children:t(`settings.ctx.explain`,{size:ws(n.max_fit),name:n.display_name,memory:n.memory_source})})]}),f&&P(`span`,{className:`settings-hint`,children:t(`settings.ctx.loadedAt`,{size:ws(n.loaded_ctx)})}),o&&V(`span`,{className:`settings-hint`,children:[P(K,{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 cP({row:e,providerName:t,choices:n,labels:r,disabled:i,onSwitch:a}){let o=T(),s=ls(e=>e.active),c=s?.model??null,l=!!s?.remote,u=n.some(e=>ds(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||fs(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:ws(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=>ds(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(sP,{model:c})]})}function lP({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=Es(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(_r,{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:tE(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(zM,{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(K,{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(hr,{size:13,"aria-hidden":`true`}),` `,f(`settings.model.inUse`)]}):e.available===!1?null:p?V(`span`,{className:`model-row-current`,children:[P(K,{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(K,{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(K,{size:13,className:`spin`}):null,` `,f(`settings.model.download`)]})]})]})}function uP(){let e=T(),[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(!1),l=(0,Y.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,Y.useEffect)(()=>{l(H)},[l]),!t)return r?P(`p`,{className:`settings-error`,role:`alert`,children:r}):V(`p`,{className:`settings-hint`,children:[P(K,{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:nE(t.total_usd)})}),u!=null&&V(D.Fragment,{children:[` `,e(`settings.spend.ofLimit`,{limit:nE(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(q,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.near`)]}),t.state===`reached`&&V(`div`,{className:`spending-warning`,role:`alert`,children:[V(`p`,{children:[P(q,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.reached`)]}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void l(_n),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(K,{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 dP=2e3;function fP(e,t){return e.key_source===`environment`?t(`settings.key.setIn`,{name:e.env_var??``}):`••••••••••••••••••••${e.key_hint?` ${e.key_hint}`:``}`}function pP(){let e=T(),t=ls(e=>e.active),n=ls(e=>e.select),r=ls(e=>e.refresh),i=ls(e=>e.rememberNames),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(null),l=k(e=>e.settingsProvider),[u,d]=(0,Y.useState)(l??t?.provider??`local`),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(null),[g,_]=(0,Y.useState)(``),[v,y]=(0,Y.useState)(!1),[b,x]=(0,Y.useState)(``),[S,C]=(0,Y.useState)(!1),[w,E]=(0,Y.useState)(!1),[O,A]=(0,Y.useState)({base_url:``,auth_header_name:``,auth_header_prefix:``}),[j,M]=(0,Y.useState)(null),[N,F]=(0,Y.useState)(null),[I,L]=(0,Y.useState)(null),[ee,R]=(0,Y.useState)(null),[z,B]=(0,Y.useState)(!1),[te,ne]=(0,Y.useState)(null),[re,ie]=(0,Y.useState)(null),ae=(0,Y.useRef)(u);ae.current=u;let oe=(0,Y.useRef)(!0);(0,Y.useEffect)(()=>(oe.current=!0,()=>{oe.current=!1}),[]);let H=a?.find(e=>e.id===u)??null,U=e=>e?.network?.reachable===!1,W=e=>!!e?.blocked,G=!!H&&!W(H)&&(!H.remote||!!H.models_discovered),se=(0,Y.useCallback)(async()=>{c(null);try{let e=await En();o(e.providers),e.lemonade_error&&c(e.lemonade_error)}catch(e){c(e instanceof Error?e.message:String(e))}},[]),ce=(0,Y.useCallback)(async(t,n=!1)=>{n||(p(null),h(null));try{let n=await Qt(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,Y.useEffect)(()=>{se()},[se]);let le=!!a?.some(e=>e.key_state===`waiting_for_os_permission`);(0,Y.useEffect)(()=>{if(!le)return;let e=setInterval(()=>{se()},dP);return()=>clearInterval(e)},[le,se]);let ue=t?.provider;(0,Y.useEffect)(()=>{ue&&!l&&d(ue)},[ue,l]),(0,Y.useEffect)(()=>{x(``),C(!1),E(!1),L(null),_(``),y(!1),B(!1)},[u]),(0,Y.useEffect)(()=>{G?ce(u):p(null)},[u,G,ce]);let de=(0,Y.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 zt(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 se()}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,se,H,e]),pe=(0,Y.useCallback)(async()=>{M(`forget`),E(!1),L(null);try{await qt(u),L({ok:!0,text:e(`settings.key.cleared`)}),await se(),await r()}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[u,se,r,e]),me=(0,Y.useCallback)(async t=>{M(t),L(null);try{await n(t),L({ok:!0,text:e(`settings.model.switched`,{name:fs(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,Y.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,Y.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,Y.useCallback)(async t=>{L({ok:!0,text:e(`settings.model.added`,{name:t})}),B(!0),await ce(`local`,!0)},[ce,e]),ve=!!f?.some(Es);(0,Y.useEffect)(()=>{if(ve)return()=>{r()}},[ve,r]),(0,Y.useEffect)(()=>{if(u!==`local`||!ve)return;let e=setInterval(()=>{ce(`local`,!0)},dP);return()=>clearInterval(e)},[ve,u,ce]);let ye=t?.model,be=f?.find(e=>ds(ye,e.id));(0,Y.useEffect)(()=>{be&&ne(be)},[be]);let xe=(0,Y.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=bs(f??[]),ke=!!g.trim(),Ae=e=>ds(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(lP,{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(cP,{row:be??(ds(te?.id,t?.model)?te:null),providerName:a?.find(e=>e.id===t?.provider)?.name??null,choices:G?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)||W(t)?` is-disabled`:``}`,onClick:()=>d(t.id),disabled:(U(t)||W(t))&&u!==t.id,title:W(t)?e(`settings.privacy.localOnlyBlocked`):U(t)?t.network?.detail??void 0:void 0,children:[t.remote?P(Lr,{size:14,"aria-hidden":`true`}):P(Gr,{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(tP,{message:s,onRetry:()=>{se(),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(_r,{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&&!G&&V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,children:e(`settings.model.prices`)}),P(YA,{provider:H.id})]}),W(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 se(),children:e(`settings.key.checkAgain`)})]}),H.remote&&!U(H)&&!W(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 ${G?`settings-ok`:`settings-error`}`,children:e(G?`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:fP(H,e),"aria-label":e(`settings.key.savedAria`,{name:H.name})}),!G&&V(`button`,{type:`submit`,className:`btn-primary`,disabled:j!==null,children:[j===`connect`?P(K,{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(uo,{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(K,{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&&!G&&!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(tP,{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}),G&&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&&ZN(m))&&P(tP,{message:m}),!f&&!m&&V(`p`,{className:`settings-hint`,children:[P(K,{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(DN,{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(DN,{title:e(`settings.model.groupAvailable`),count:Ne.length,defaultOpen:Me.length===0,forceOpen:ke||z||Ne.some(Es),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(DN,{title:e(`settings.model.groupUnavailable`),count:De.length,forceOpen:ke,children:P(`ul`,{className:`model-list`,children:De.map(Le)})})]}),je&&G&&P(DN,{title:e(`settings.custom.title`),children:P(nP,{onAdded:e=>void _e(e)})}),je&&G&&P(aP,{downloadsSlot:re}),H.remote&&P(uP,{})]})]})}function mP(){let e=T(),t=k(e=>e.sessions),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(null),u=(0,Y.useCallback)(async()=>{l(null);try{let e=await sn();r(e.sessions),a(e.default_mode),k.getState().setDefaultPermissionMode(e.default_mode)}catch(e){l(e instanceof Error?e.message:String(e))}},[]);(0,Y.useEffect)(()=>{u()},[u]);let d=(0,Y.useCallback)(async e=>{l(null);try{await e(),await u()}catch(e){l(e instanceof Error?e.message:String(e))}},[u]),f=(0,Y.useCallback)(async e=>{s(!1),await d(()=>At(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(_r,{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(DN,{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 Ft(t.session_id,`ask`)).mode;SE(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(()=>Zt(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(()=>Zt(t.session_id)),children:e(`settings.permissions.revokeAll`)})]},t.session_id))})]})}var hP={path:`~/.gaia/skills`},gP=[{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:hP},{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 _P({onUseSkill:e}){let t=T(),[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)({}),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(``);(0,Y.useEffect)(()=>{let e=!1;return un().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=>gP.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(_r,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:t(`settings.skills.how`,hP)})]}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o}),!n&&!o&&V(`p`,{className:`settings-hint`,children:[P(K,{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?gP.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(DN,{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 vP(){let e=T(),t=k(e=>e.setShowMemoryDashboard),n=k(e=>e.closeSettings),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{vA().then(i).catch(e=>o(e instanceof Error?e.message:String(e)))},[]);let l=(0,Y.useCallback)(async()=>{if(r){c(!0),o(null);try{i(await yA({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 yP(e,t,n){if(!/^\d+$/.test(e.trim()))return!1;let r=Number(e);return r>=t&&r<=n}function bP(e){return e<1048576?`${Math.ceil(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}function xP(){let e=T(),[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(``),[a,o]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{gn().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,Y.useState)({days:!1,mb:!1}),p=!yP(r,1,365)||d.days,m=!yP(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 pn(Number(r),Number(a));n(t),c({ok:!0,text:e(`settings.undo.saved`)})}catch(t){let n=t instanceof bn&&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:bP(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 SP={root:`settings-report`,button:`btn-secondary`,hint:`settings-hint`,error:`settings-error`};function CP(){let e=T(),t=k(e=>e.sessions),n=k(e=>e.removeSession),r=gs(),i=k(e=>e.systemStatus?.data_dir),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!1),p=(0,Y.useRef)(null);(0,Y.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]),(0,Y.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,Y.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,Y.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:SP})]}),P(DN,{title:e(`settings.privacy.undo`),children:P(xP,{})}),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 wP=[{id:`needs_approval`,label:`settings.alerts.approval`},{id:`question`,label:`settings.alerts.question`},{id:`finished`,label:`settings.alerts.finished`}],TP=[{value:`banner`,label:`settings.alerts.banner`},{value:`badge`,label:`settings.alerts.badge`},{value:`off`,label:`settings.alerts.off`}],EP=[0,10,20,30,50];function DP(){return typeof Notification>`u`?`unsupported`:Notification.permission}function OP(){let e=T(),t=uc(),n=!!window.gaiaAPI,[r,i]=(0,Y.useState)(DP),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:[wP.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:TP.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(DP())})},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:EP.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 kP=[50,75,100,125,150,175,200],AP=[{accent:`american`,gender:`female`},{accent:`american`,gender:`male`},{accent:`british`,gender:`female`},{accent:`british`,gender:`male`}],jP=`settings:preview`,MP=`Hello, I'm GAIA. This is how I'll read my replies to you.`;function NP(e){return e instanceof bn?e.detail||e.message:String(e)}function PP(){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===jP),o=ES(e=>e.messageId===jP&&e.status===`loading`),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{pS().then(n).catch(e=>c(NP(e)))},[n]);let p=e=>{f(!0),u(null),ES.getState().messageId===jP&&i(),mS(e).then(n).catch(e=>u(NP(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:AP.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(jP,MP),children:[o?P(K,{size:13,className:`spin`}):P(a?oo:vo,{size:13}),e(a?`readAloud.stop`:`readAloud.settings.preview`)]})]}),P(`span`,{className:`settings-hint`,children:e(`readAloud.settings.englishOnly`)}),P(kS,{messageId:jP})]}),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:(kP.includes(t.speed)?kP:[...kP,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(K,{size:13,className:`spin`}),` `,e(`settings.loading`)]})}function FP(){let e=T(),t=k(e=>e.openSettings),n=k(e=>e.closeSettings),r=k(e=>e.runSetupAgain),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{Ce().then(a).catch(e=>l(e instanceof Error?e.message:String(e))),st().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(xr,{size:14,className:`settings-setup-chevron`,"aria-hidden":`true`})]},e.label))]},e.title)),u&&P(Zj,{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 IP=class extends Y.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidUpdate(e){this.state.hasError&&e.resetKey!==this.props.resetKey&&this.setState({hasError:!1})}componentDidCatch(e,t){console.error(`[ErrorBoundary] ${this.props.area} failed to render:`,e,t.componentStack)}render(){return this.state.hasError?P(LP,{variant:this.props.variant??`fill`,onRetry:()=>this.setState({hasError:!1})}):this.props.children}};function LP({onRetry:e,variant:t}){let n=T();return V(`div`,{role:`alert`,className:`error-boundary error-boundary-${t}`,children:[P(`p`,{className:`error-boundary-title`,children:n(`errorBoundary.title`)}),P(`p`,{className:`error-boundary-body`,children:n(t===`window`?`errorBoundary.bodyWindow`:`errorBoundary.body`)}),V(`div`,{className:`error-boundary-actions`,children:[P(`button`,{type:`button`,className:`btn-primary`,onClick:e,children:n(`errorBoundary.retry`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>window.location.reload(),children:n(`errorBoundary.reload`)})]})]})}var RP=`modulepreload`,zP=function(e,t){return new URL(e,t).href},BP={},VP=function(e){return e.pathname.endsWith(`.css`)},HP=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},UP=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=zP(t,n);let r=s(t),i=VP(r);return HP(BP,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`:RP,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)})},WP=(0,Y.lazy)(()=>UP(()=>import(`./ConnectorsPane-10jS6xLA.js`).then(e=>({default:e.ConnectorsPane})),__vite__mapDeps([0,1,2,3,4]),import.meta.url)),GP=(0,Y.lazy)(()=>UP(()=>import(`./AdvancedSettings-DBTNzH7K.js`).then(e=>({default:e.AdvancedSettings})),__vite__mapDeps([5,1,2,3]),import.meta.url)),KP=[`general`,`setup`,`model`,`permissions`,`skills`,`connectors`,`memory`,`notifications`,`voice`,`privacy`,`advanced`];function qP({onUseSkill:e}){let t=T(),n=k(e=>e.settingsSection),r=k(e=>e.openSettings),i=k(e=>e.closeSettings),a=(0,Y.useRef)(null),o=n!==null;if(Lo(o,i),sS(a,o),EN(a,o,()=>a.current?.querySelector(`.settings-nav-item.is-active`)),!n)return null;let s=(()=>{switch(n){case`general`:return P(XN,{});case`setup`:return P(FP,{});case`model`:return P(pP,{});case`permissions`:return P(mP,{});case`skills`:return P(_P,{onUseSkill:t=>{i(),e(t)}});case`connectors`:return P(WP,{});case`memory`:return P(vP,{});case`notifications`:return P(OP,{});case`voice`:return P(PP,{});case`privacy`:return P(CP,{});case`advanced`:return P(GP,{})}})();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`)}),KP.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(J,{size:18})}),P(`div`,{className:`settings-scroll`,children:P(IP,{area:`settings.${n}`,children:P(Y.Suspense,{fallback:V(`p`,{className:`settings-hint`,children:[P(K,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),children:s})},n)})]})]})})}var JP=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 YP(e){let t=window.gaiaAPI?.backend;if(!t)return()=>{};let n=t=>{let n=JP.getState().lifecycle?.status;JP.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 XP(e,t){let[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(null),c=(0,Y.useRef)(null),l=(0,Y.useRef)(null),u=(0,Y.useRef)(null),f=(0,Y.useCallback)(()=>{c.current&&=(clearTimeout(c.current),null),l.current&&=(clearTimeout(l.current),null),u.current&&=(clearInterval(u.current),null)},[]);(0,Y.useEffect)(()=>f,[f]);let p=(0,Y.useCallback)((e,t)=>{u.current&&clearInterval(u.current),u.current=setInterval(async()=>{try{let n=await Pt();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{}},Rc)},[]),m=e??`Gemma-4-E4B-it-GGUF`;return(0,Y.useEffect)(()=>s(null),[m]),{isLoadingModel:n,isDownloadingModel:i,downloadError:o,loadModel:(0,Y.useCallback)(async(e,t)=>{let n=e??m,i=t??32768;r(!0);try{if(!await Bt(n,i)){r(!1);return}d.system.info(`Load model triggered: ${n} (ctx=${i})`),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>r(!1),Ic),p(n,`load`)}catch(e){d.system.error(`Failed to trigger model load`,e),r(!1)}},[m,t,p]),downloadModel:(0,Y.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),Lc),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 ZP({onRetry:e,label:t,busyLabel:n=`Checking…`}){let[r,i]=(0,Y.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 QP(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function $P({lifecycle:e}){let t=T(),n=JP(e=>e.restart),r=JP(e=>e.restartError),i=e.status===`restarting`,[a,o]=(0,Y.useState)(()=>Date.now());if((0,Y.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(K,{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:QP(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(q,{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(ZP,{onRetry:n,label:t(`banner.restartButton`),busyLabel:t(`banner.restartingShort`)})]})}function eF({onRetry:e,backendSlow:t=!1,backendError:n=null}){let r=T(),{backendConnected:i,systemStatus:a,currentSessionId:o,messages:s}=k(),c=JP(e=>e.lifecycle),[l,u]=(0,Y.useState)(!1),d=!!o&&s.length>0,f=a?.default_model_name??`Gemma-4-E4B-it-GGUF`,{isDownloadingModel:p,downloadError:m,downloadModel:h}=XP(f),g=ls(e=>e.pickLoad),_=ls(e=>e.retryPickLoad),v=ls(e=>e.dismissPickLoad);us();let y=(0,Y.useRef)(a?.lemonade_running),b=(0,Y.useRef)(a?.model_downloaded),x=(0,Y.useRef)(a?.context_size_sufficient),S=(0,Y.useRef)(a?.expected_model_loaded);if((0,Y.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($P,{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?q:Yr,{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(K,{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(J,{size:14})})]})}if(g){let e=fs(g.model);return g.error?V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{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(ZP,{onRetry:_,label:r(`banner.pickLoad.retry`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:v,"aria-label":r(`banner.dismiss`),children:P(J,{size:14})})]}):V(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(K,{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(Gw(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(K,{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(bo,{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(ZP,{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(q,{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(ZP,{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(q,{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(ZP,{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(q,{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(ZP,{onRetry:e,label:`Check again`})]});if(a&&!a.lemonade_running){let t=Kw(a)===`unresponsive`,n=$N(a);return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{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(eP,{className:`connection-banner__retry`}),e&&P(ZP,{onRetry:e,label:r(`settings.key.checkAgain`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(J,{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(Yi,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`LLM context window is too small (`,t.toLocaleString(),` tokens;`,` `,Pc.toLocaleString(),` required).`,` `,P(`span`,{className:`connection-banner__hint`,children:`Reload it with a larger context in Settings → Advanced.`})]}),e&&P(ZP,{onRetry:e,label:`Check again`}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(J,{size:14})})]})}return null}function tF(){let e=IN(),t=T(),[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(null),o=(0,Y.useCallback)(e=>{let n=PN();n&&(a(null),n[e]().catch(n=>{d.system.error(`Update ${e} failed`,n),a(BN(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(q,{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(J,{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(q,{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(J,{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(Yr,{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(Yr,{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(J,{size:11})})]}):e.status===`downloaded`?V(`div`,{className:`update-chip update-chip--ready`,role:`status`,"aria-live":`polite`,children:[P(Ia,{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(q,{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(J,{size:11})})]}):null}var nF={permission_request:{icon:P(Ka,{size:16}),colorClass:`notif-type-permission`},policy_alert:{icon:P(Ka,{size:16}),colorClass:`notif-type-policy`},security_alert:{icon:P(q,{size:16}),colorClass:`notif-type-security`},status_change:{icon:P(Dr,{size:16}),colorClass:`notif-type-status`},info:{icon:P(Ui,{size:16}),colorClass:`notif-type-info`},error:{icon:P(Tr,{size:16}),colorClass:`notif-type-error`}};function rF(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 iF({onClose:e}){let t=T(),n=$s(Ao(tc)),r=$s(ec),i=$s(e=>e.markRead),a=$s(e=>e.markAllRead),o=$s(e=>e.clearAll),s=$s(e=>e.dismiss),c=$s(e=>e.respondToPermission),l=$s(e=>e.typeFilter),u=$s(e=>e.setTypeFilter),d=(0,Y.useCallback)(e=>{i(e)},[i]),f=(0,Y.useCallback)(e=>{c(e.id,`allow`).catch(e=>console.error(`[NotificationCenter] allow failed:`,e))},[c]),p=(0,Y.useCallback)(e=>{c(e.id,`deny`).catch(e=>console.error(`[NotificationCenter] deny failed:`,e))},[c]);Lo(!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(J,{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(tr,{size:40,strokeWidth:1.2}),P(`span`,{children:t(`notifications.empty`)})]}):n.map(e=>{let n=nF[e.type],r=e.type===`permission_request`&&e.tool?qs(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:rF(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(hr,{size:14}),t(`notifications.approve`)]}),V(`button`,{className:`notification-action-btn notification-action-deny`,onClick:t=>{t.stopPropagation(),p(e)},children:[P(J,{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(J,{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(hr,{size:14}),t(`notifications.markAllRead`)]}),V(`button`,{className:`notification-footer-btn notification-footer-clear`,onClick:o,children:[P(uo,{size:14}),t(`notifications.clear`)]})]})]})}var aF=1500,oF=e=>new Promise(t=>setTimeout(t,e));async function sF({onProgress:e,isCancelled:t=()=>!1,pollMs:n=aF}={}){try{await cn(fk)}catch(e){if(e?.httpStatus!==409)throw e;let t=await Wt(fk).catch(()=>null);if(!t||t.status===`completed`||t.status===`failed`)throw e}for(;!t();){let t=await Wt(fk);if(e?.(t),t.status===`completed`)return;if(t.status===`failed`)throw Error(t.error||`The GAIA agent could not be installed.`);await oF(n)}}function cF({onInstalled:e,noBuild:t=!1}){let n=T(),[r,i]=(0,Y.useState)({kind:`idle`}),a=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>()=>{a.current=!0},[]);let o=(0,Y.useCallback)(async()=>{i({kind:`installing`,percent:0});try{if(await sF({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 lF(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 uF(e,t){let{addNotification:n}=$s.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 dF=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 jt()).schedules||[],r=t().errorCounts;r&&uF(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 bt(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 dt(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:lF(n,`Failed to update schedule`)})}},runScheduleNow:async t=>{try{let n=await Yt(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:lF(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:lF(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})})),fF=new Set([`loading_model`,`downloading_model`,`model_retry`,`waiting`]),pF=5;function mF(e,t){return{id:e,title:t.get(e)?.title??`Untitled chat`}}function hF(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=>({...mF(e,t),reason:`approval`}));n&&e.awaitingUser&&!a.has(e.currentSessionId)&&o.push({...mF(e.currentSessionId,t),reason:`answer`});for(let[n,r]of Object.entries(e.awaitingBySession))o.some(e=>e.id===n)||o.push({...mF(n,t),reason:r===`question`?`answer`:`approval`});let s=n&&!e.awaitingUser&&e.livePhase&&fF.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,pF).map(e=>mF(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=>mF(e,t)),needsYou:o,recent:u}}function gF(e){let t=(0,Y.useRef)(e);t.current=e,(0,Y.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:$s.getState().notifications},a=r;if(r=i,a&&Object.keys(i).every(e=>i[e]===a[e]))return;let o=hF(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=$s.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 _F(){(0,Y.useEffect)(()=>{let e=window.gaiaAPI;if(!e)return;let t=$s.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 vF(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 yF(){let[e,t]=(0,Y.useState)(null);return(0,Y.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 bF(){_F();let e=k(e=>e.runningSessionIds),t=k(e=>e.awaitingBySession),n=k(e=>e.sessions),r=k(e=>e.currentSessionId),i=$s(Ao(rc)),a=uc(),o=yF(),s=(0,Y.useRef)(null),c=_c(e,t,i),l=JSON.stringify(c);(0,Y.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 vc(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`||xc(s,r,i))&&(o=!0,t===`banner`)){if(c!==`finished`){let{title:t,body:n}=bc(c,e);vF(s,t,n)}else ht(s).then(e=>{k.getState().updateSessionInList(s,e);let{title:t,body:n}=bc(c,e);vF(s,t,n)}).catch(t=>{d.system.error(`Could not read how chat ${s} ended`,t);let{title:n,body:r}=bc(c,{...e,last_run_status:null});vF(s,n,r)})}}if(o){if(a.sound)try{wc()}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=Sc(n,c,a.modes,r);(0,Y.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&&Cc(o,a.batteryFloor);(0,Y.useEffect)(()=>{window.gaiaAPI?.power.setKeepAwake(f).catch(e=>d.system.error(`Could not change keep-awake`,e))},[f])}function xF(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 SF(e){return e.replace(/-/g,``).slice(0,7)}function CF(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 wF(e,t,n){return!e||t&&(e===t||e===SF(t))?null:n.some(t=>t.id===e)?e:CF(n,e)}function TF(e){return new URLSearchParams(e.search).get(`session`)||e.hash.replace(/^#/,``)||null}var EF=`gaia:last-session`;function DF(e){try{e?localStorage.setItem(EF,e):localStorage.removeItem(EF)}catch(e){d.ui.warn(`Could not save the open chat for the next launch`,e)}}function OF(){try{return localStorage.getItem(EF)}catch(e){return d.ui.warn(`Could not read the chat open at last launch`,e),null}}var kF=1e3,AF=3e4;function jF(e,{initialMs:t=kF,maxMs:n=AF,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 MF(e,t,n){return e&&!t&&!n}var NF=(0,Y.lazy)(()=>UP(()=>import(`./MemoryDashboard-C-qhmLse.js`).then(e=>({default:e.MemoryDashboard})),__vite__mapDeps([6,1,2,7,8]),import.meta.url)),PF=(0,Y.lazy)(()=>UP(()=>import(`./ScheduleManager-BEwxv5Ds.js`).then(e=>({default:e.ScheduleManager})),__vite__mapDeps([9,1,2,7,3,10]),import.meta.url)),FF=(0,Y.lazy)(()=>UP(()=>import(`./DocumentLibrary-cThIBsTi.js`).then(e=>({default:e.DocumentLibrary})),__vite__mapDeps([11,1,2,3,12]),import.meta.url)),IF=(0,Y.lazy)(()=>UP(()=>import(`./FileBrowser-TlXAnuMz.js`).then(e=>({default:e.FileBrowser})),__vite__mapDeps([13,1,2,3,14]),import.meta.url)),LF=(0,Y.lazy)(()=>UP(()=>import(`./MobileAccessModal-Bo6LvTRA.js`).then(e=>({default:e.MobileAccessModal})),__vite__mapDeps([15,1,2,3,16]),import.meta.url)),RF=3,zF=3e5,BF=6e3,VF=6e4,HF=e=>e instanceof TypeError,UF=e=>new Promise(t=>setTimeout(t,e)),WF=3e5,GF=class extends Error{};async function KF(){let e=Date.now()+WF;for(;;){let t=await it();if(t.state===`ready`)return;if(t.state===`failed`||t.state===`cancelled`)throw new GF(t.error||I().bare(`setup.upgrading.stopped`));if(Date.now()>=e)throw Error(I().bare(`setup.upgrading.slow`));await UF(kF)}}function qF(){return P(`div`,{className:`loading-spinner`,role:`status`,"aria-label":`Loading`})}var JF=e=>e===1||e%10==0;function YF(){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=ls(e=>e.restoreNotice),E=ls(e=>e.dismissRestoreNotice),D=$s(e=>e.showPanel),O=k(e=>e.systemStatus?.initialized===!0),A=(0,Y.useRef)(!1),j=$s(e=>e.setShowPanel);(0,Y.useEffect)(()=>{if(!w?.ok)return;let e=setTimeout(E,BF);return()=>clearTimeout(e)},[w,E]);let[M,N]=(0,Y.useState)({state:`checking`}),F=k(e=>e.setupAgain),I=k(e=>e.runSetupAgain),ee=(0,Y.useRef)(M);ee.current=M;let[R,z]=(0,Y.useState)(!1),B=(0,Y.useRef)(R);B.current=R;let[te,ne]=(0,Y.useState)(!1),[re,ie]=(0,Y.useState)(!1),ae=te||R&&!pk(v),oe=(0,Y.useRef)(ae);oe.current=ae;let[H,W]=(0,Y.useState)(null),[G,se]=(0,Y.useState)(``),[ce,le]=(0,Y.useState)(0),[de,fe]=(0,Y.useState)(!1),[pe,me]=(0,Y.useState)(!1),[he,ge]=(0,Y.useState)(null),[_e,ve]=(0,Y.useState)(null),ye=(0,Y.useRef)(async()=>{}),be=(0,Y.useRef)(async()=>{}),xe=(0,Y.useCallback)(async(e=!1,t=!1)=>{e||N({state:`checking`});let n=0;try{for(;;){await ls.getState().refresh();let e=!!ls.getState().active?.remote,r;try{r=await Gt(e)}catch(e){if(!t||!HF(e)||n>=VF)throw e;await UF(kF),n+=kF;continue}if(!r.ready&&r.stage===`upgrade`){N({state:`upgrading`});let t=await it();(!t.upgrade_embedded||t.state!==`running`&&t.state!==`verifying`)&&await vt(e,!1,{upgradeEmbedded:!0}),await KF(),r=await Gt(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 GF){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,Y.useRef)(0),Ce=(0,Y.useCallback)(async()=>{let e=++Se.current,t=(await yn()).agents||[];e===Se.current&&(_(t),z(!0),pk(t)&&ne(!1))},[_]),we=(0,Y.useCallback)(()=>{let e=B.current;z(!1),Ce().catch(t=>{d.api.warn(`Agent list unavailable after setup`,t),e&&z(!0)})},[Ce]);(0,Y.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,Y.useCallback)(async()=>{b((await sn()).default_mode)},[b]),Ee=(0,Y.useRef)([]);(0,Y.useEffect)(()=>{m(`0.26.0rc15`),xe(!1,!0);let e=[jF(Ce,{onError:(e,t)=>{JF(t)&&d.api.warn(`Agent list unavailable (attempt ${t}); retrying`,e)}}),jF(Te,{onError:(e,t)=>{JF(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,Y.useCallback)(()=>{Ee.current.forEach(e=>e.kick()),ls.getState().retryNow(),be.current();let e=ee.current;e.state===`unknown`&&!e.upgradeFailed&&xe(!0)},[xe]),Oe=(0,Y.useRef)(De);Oe.current=De;let ke=(0,Y.useRef)(0),Ae=(0,Y.useRef)(0),je=(0,Y.useRef)(null),Me=(0,Y.useRef)(!1),[Ne,Pe]=(0,Y.useState)(!1),[Fe,Ie]=(0,Y.useState)(null),Le=(0,Y.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>=zF){Pe(!1),g(!1),h(null);return}g(!0),(Me.current||Ae.current>=RF)&&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>=RF||!n?.lemonade_running?h(t):h({...n,download_progress:t.download_progress})},[g,h]),Re=(0,Y.useRef)(Le);Re.current=Le;let[ze]=(0,Y.useState)(()=>Yw(e=>Re.current(e))),Be=ze.check;ye.current=Be,(0,Y.useEffect)(()=>xk(ze.start),[ze]),(0,Y.useEffect)(()=>YP(()=>{Be()}),[Be]);let Ve=(0,Y.useRef)(``);(0,Y.useEffect)(()=>{let e=e=>It().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=ls.getState().active?.model;a&&r.some(e=>e.effective_model&&e.effective_model!==a)&&ls.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,Y.useEffect)(()=>cT(),[]),(0,Y.useEffect)(()=>{let e=()=>{dF.getState().loadSchedules()};e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[]),(0,Y.useEffect)(()=>ET(),[]),bF();let He=(0,Y.useRef)(!1),Ue=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>{let e=()=>{let e=TF(window.location),{currentSessionId:t,sessions:n}=k.getState(),i=wF(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||Sn(`new-chat`))return;let{sessions:t}=k.getState(),n=wF(OF(),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,Y.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,Y.useEffect)(()=>{if(He.current&&DF(t),t){let e=SF(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,Y.useCallback)(async e=>{if(W(null),!await Ko(`chat`))return se(e),!1;let t=k.getState(),n;try{n=await Dn({title:`New Task`,agent_type:fk,document_ids:t.draftDocumentIds,private:t.draftPrivate,folders:t.draftFolder?[t.draftFolder]:[]})}catch(e){throw mk(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 Ft(n.id,t.draftPermissionMode)}catch(e){o=e}return Nt(Je),o&&!n.private&&rn(U(n.id),e),i(n),r(n.id),a([]),se(``),o?(W(`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,Y.useCallback)(()=>{let e=k.getState(),t=e.currentSessionId;t&&Mc(t,e)&&Nc(t),e.setShowMemoryDashboard(!1),e.setShowSchedules(!1),Ue.current=!0,r(null),a([]),le(e=>e+1)},[r,a]);gF({openChat:(0,Y.useCallback)(e=>{let t=k.getState();t.closeSettings(),e!==t.currentSessionId&&(Nc(t.currentSessionId),a([])),r(e)},[r,a]),newChat:(0,Y.useCallback)(()=>{k.getState().closeSettings(),Ge()},[Ge]),refreshStatus:()=>void Be()});let Ke=(0,Y.useCallback)(e=>{Ge(),We(`Load the \`${e}\` skill, then tell me briefly what it lets you do.`).catch(e=>W(e instanceof Error?e.message:String(e)))},[Ge,We]),qe=(0,Y.useCallback)(e=>{N({state:`ready`}),we(),Be(),e&&(e.needs_input?se(e.prompt):We(e.prompt).catch(e=>W(e instanceof Error?e.message:String(e))))},[Be,We,we]),Ye=(0,Y.useCallback)(()=>{N({state:`ready`}),Be()},[Be]);(0,Y.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,Y.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,Y.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,Y.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,Y.useEffect)(()=>{Cn().then(e=>me(e.active===!0)).catch(e=>d.system.debug(`Mobile access unavailable`,e))},[]);let Xe=(0,Y.useCallback)(async()=>{if(fe(!0),ge(null),pe)ve(null);else try{let e=await Fn(),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,Y.useCallback)(async()=>{try{await ue(),me(!1),fe(!1)}catch(e){ge(e instanceof Error?e.message:`Could not stop mobile access`)}},[]);ID(e=>{e?Xe():Ze()}),(0,Y.useEffect)(()=>{PD(pe)},[pe]);let Qe=Bc(`(max-width: 768px)`),$e=MF(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(TN,{onReady:e=>{I(!1),qe(e)},onClose:e}),P(qA,{}),P(tF,{})]})}let et=c?P(Y.Suspense,{fallback:P(qF,{}),children:P(NF,{})}):t?P(Pk,{sessionId:t},t):P(HA,{onSend:We,initialText:G,focusRequest:ce},G);return V(`div`,{className:`app`,children:[!u&&P(`button`,{className:`sidebar-toggle`,onClick:()=>p(!0),"aria-label":`Open sidebar`,children:P(ca,{size:18})}),P(`div`,{className:`sidebar-overlay ${u?`visible`:``}`,onClick:()=>p(!1),"aria-hidden":`true`}),P(IP,{area:`sidebar`,variant:`compact`,children:P(sl,{onNewChat:Ge,onMobileAccess:Qe?void 0:()=>void Xe(),tunnelActive:pe})}),V(`div`,{className:`main-content`,children:[M.state===`ready`&&P(eF,{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(zs,{placement:`main`}),ae&&P(cF,{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(J,{size:14})})]}),P(IP,{resetKey:c?`memory`:t??`new-${ce}`,area:`main`,children:et})]}),l&&P(Y.Suspense,{fallback:null,children:P(PF,{})}),o&&P(Y.Suspense,{fallback:null,children:P(FF,{})}),s&&P(Y.Suspense,{fallback:null,children:P(IF,{onStartChat:We})}),D&&P(`div`,{className:`notification-center-popover`,children:P(iF,{onClose:()=>j(!1)})}),de&&P(Y.Suspense,{fallback:null,children:P(LF,{isOpen:de,onClose:()=>fe(!1),onStop:()=>void Ze(),error:he,setupCommands:_e,onRetry:()=>void Xe()})}),S&&P(qP,{onUseSkill:Ke}),P(qA,{}),P(tF,{}),H&&V(`div`,{className:`toast toast-dismissible`,role:`alert`,children:[P(`span`,{children:H}),P(`button`,{type:`button`,className:`toast-dismiss`,onClick:()=>W(null),"aria-label":e(`banner.dismiss`),children:P(J,{size:14,"aria-hidden":`true`})})]})]})}var XF=`agent-refresh`,ZF={"pre-checks":`engine.stage.preChecks`,"ensure-uv":`engine.stage.ensureUv`,"create-venv":`engine.stage.createVenv`,"install-package":`engine.stage.installPackage`,verify:`engine.stage.verify`,[XF]:`engine.stage.agentRefresh`,start:`engine.stage.start`},QF={disk:`engine.hint.disk`,network:`engine.hint.network`,tls:`engine.hint.tls`,locked:`engine.hint.locked`,daemon:`engine.hint.daemon`};function $F(e,t){if(!e)return t(`engine.stage.neutral`);let n=ZF[e];return n?t(n):(console.warn(`[EngineInstallScreen] install stage "${e}" has no label`),t(`engine.stage.neutral`))}function eI(e,t){return e.reason?t(QF[e.reason]):t(e.stage===XF?`engine.hint.agent`:`engine.hint.other`)}function tI(e){return e.reason===`locked`&&e.lockedBy?.length?e.lockedBy:null}function nI(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 rI({status:e}){let t=T(),n=$F(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 iI({error:e,busy:t,notice:n,onRetry:r,onCloseLockers:i,onContinue:a,onRevert:o,onOpenLog:s}){let c=T(),l=tI(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:nI(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:eI(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===XF&&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 aI(){let e=T(),[t,n]=(0,Y.useState)({phase:`running`,stage:null,percent:null,message:``,error:null}),[r,i]=(0,Y.useState)(!1),[a,o]=(0,Y.useState)(null),s=(0,Y.useCallback)(e=>{console.error(`[EngineInstallScreen] the desktop app did not answer`,e),o(e instanceof Error?e.message:String(e))},[]);(0,Y.useEffect)(()=>{let e=window.gaiaInstall,t=e.onProgress(n);return e.status().then(n).catch(s),t},[s]);let c=(0,Y.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.retry().catch(s).finally(()=>i(!1))},[s]),l=(0,Y.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.closeLockingPrograms().catch(s).finally(()=>i(!1))},[s]),u=(0,Y.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.continueWithoutAgentUpdate().catch(s).finally(()=>i(!1))},[s]),d=(0,Y.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.revert().then(e=>{e||i(!1)}).catch(e=>{s(e),i(!1)})},[s]),f=(0,Y.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===XF?`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(iI,{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(rI,{status:t}),a&&P(`p`,{className:`engine-error`,role:`alert`,children:P(`bdi`,{dir:`ltr`,children:a})})]})]})})})}function oI(){return!!window.gaiaInstall&&new URLSearchParams(window.location.search).get(`engine`)===`install`}async function sI(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}}Hs(),u();var cI=localStorage.getItem(`gaia-chat-theme`);S(x(cI===`light`||cI===`dark`?cI:`system`));var lI=k.getState();i(lI.palette,lI.customColors,lI.theme),s(lI.locale),C(),l(),wo.createRoot(document.getElementById(`root`)).render(P(Y.StrictMode,{children:P(IP,{area:`app`,variant:`window`,children:oI()?P(aI,{}):P(YF,{})})})),window.addEventListener(`load`,()=>{sI({isProduction:!0,protocol:window.location.protocol,serviceWorker:`serviceWorker`in navigator?navigator.serviceWorker:void 0})});export{Xh as $,iA as A,ri as At,dA as B,Dr as Bt,eA as C,ra as Ct,SA as D,xi as Dt,nA as E,Di as Et,CA as F,Gr as Ft,yA as G,_r as Gt,xA as H,Cr as Ht,mA as I,Vr as It,PT as J,Zn as Jt,BT as K,hr as Kt,hA as L,Fr as Lt,Xk as M,Zr as Mt,rA as N,Yr as Nt,Qk as O,yi as Ot,sA as P,qr as Pt,Jh as Q,uA as R,Nr as Rt,tA as S,K as St,cA as T,Li as Tt,EA as U,xr as Ut,pA as V,Tr as Vt,aA as W,yr as Wt,IS as X,IT as Y,sS as Z,_A as _,Ia as _t,tP as a,Ko as at,$k as b,wa as bt,$N as c,So as ct,JA as d,q as dt,Uh as et,NA as f,uo as ft,gA as g,Ba as gt,bA as h,Ha as ht,UP as i,fs as it,vA as j,$r as jt,Zk as k,_i as kt,DN as l,go as lt,DA as m,eo as mt,dF as n,Pc as nt,eP as o,Lo as ot,TA as p,no as pt,HT as q,ar as qt,XP as r,Dc as rt,QN as s,J as st,xF as t,Fc as tt,EN as u,mo as ut,lA as v,Pa as vt,oA as w,$i as wt,OA as x,ma as xt,wA as y,Oa as yt,fA as z,kr as zt};
|