@amd-gaia/agent-ui 0.26.0-rc.10 → 0.26.0-rc.12
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/dist/assets/{AdvancedSettings-w9D1AXlP.js → AdvancedSettings-BfZmpLHF.js} +1 -1
- package/dist/assets/{ConnectorsPane-BxnbIY7k.js → ConnectorsPane-BOj8VFq4.js} +1 -1
- package/dist/assets/{DocumentLibrary-BwCg6OBt.js → DocumentLibrary-Bx1pci4R.js} +1 -1
- package/dist/assets/{FileBrowser-ZQ8nEd3a.js → FileBrowser-CjvNU8QP.js} +1 -1
- package/dist/assets/{MemoryDashboard-DDIIbL38.js → MemoryDashboard-J8lGJ5sQ.js} +1 -1
- package/dist/assets/{MobileAccessModal-DgmEaSve.js → MobileAccessModal-B-TmXjst.js} +1 -1
- package/dist/assets/{ScheduleManager-5ISmwd1h.js → ScheduleManager-DDolvLap.js} +1 -1
- package/dist/assets/{api-B8v2Xp8S.js → api-B28uXBhs.js} +1 -1
- package/dist/assets/{index--tVNC0Jc.js → index-CxKwyrz_.js} +13 -13
- package/dist/assets/index-JCP-qf3I.css +1 -0
- package/dist/assets/{useT-ByY7OhOj.js → useT-BfwsR95A.js} +2 -2
- package/dist/assets/{zap-D6QQWCNv.js → zap-BvXNJAin.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/sw.js +1 -1
- package/package.json +1 -1
- package/dist/assets/index-r-CFg5BV.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-ByY7OhOj.js";import{$ as H,$n as U,$t as se,A as W,An as G,B as ce,Bn as le,Bt as ue,C as de,D as fe,Dt as pe,E as me,En as he,Et as ge,F as _e,Fn as ve,Ft as ye,G as be,Gn as xe,Gt as Se,Hn as Ce,Ht as we,In as Te,It as Ee,J as De,Jn as Oe,Jt as ke,K as Ae,Kn as je,Kt as Me,L as Ne,Ln as Pe,Lt as Fe,M as Ie,Mn as Le,Mt as Re,N as ze,Nn as Be,Nt as Ve,O as He,Ot as Ue,P as We,Pn as Ge,Pt as Ke,Q as qe,Qn as Je,Qt as Ye,R as Xe,Rn as Ze,Rt as Qe,S as $e,St as et,T as tt,Tt as nt,U as rt,Un as it,Ut as at,V as K,Vn as ot,Vt as st,W as ct,Wn as lt,Wt as ut,X as dt,Xn as ft,Xt as pt,Y as mt,Yn as ht,Z as gt,Zn as _t,Zt as vt,_ as yt,_t as bt,a as xt,an as St,b as Ct,bt as wt,c as Tt,cn as Et,ct as Dt,d as Ot,dn as kt,dt as At,en as jt,er as Mt,et as Nt,fn as Pt,ft as Ft,g as It,gt as Lt,h as Rt,ht as zt,i as Bt,in as Vt,it as Ht,j as Ut,jn as Wt,jt as Gt,k as Kt,kn as qt,kt as Jt,l as Yt,ln as Xt,lt as Zt,m as Qt,mn as $t,mt as en,nn as tn,nr as nn,nt as rn,o as an,on,ot as sn,p as cn,pt as ln,q as un,qn as dn,qt as fn,r as pn,rn as mn,rt as hn,s as gn,sn as _n,st as vn,t as yn,tn as bn,tr as xn,tt as Sn,u as Cn,un as wn,ut as Tn,v as En,vt as Dn,w as On,x as kn,xn as An,yt as jn,z as Mn,zn as Nn,zt as Pn}from"./api-B8v2Xp8S.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Fn=n((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),In=n(((e,t)=>{t.exports=Fn()})),Ln=n((e=>{var t=f();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`),o=Symbol.for(`react.recoverable`),s=Symbol.for(`react.optimistic_key`);function c(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:r===s?s:``+r,children:e,containerInfo:t,implementation:n}}var l=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function u(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.browser=function(e){return{$$typeof:o,_reason:e}},e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return c(e,t,null,r)},e.flushSync=function(e){var t=l.T,n=i.p;try{if(l.T=null,i.p=2,e)return e()}finally{l.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=u(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=u(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return l.H.useFormState(e,t,n)},e.useFormStatus=function(){return l.H.useHostTransitionStatus()},e.version=`19.3.1`})),Rn=n(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=Ln()})),zn=n((e=>{var t=In(),n=f(),r=Rn();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){for(var t=e,n=t;n&&!n.alternate;)t=n,t.flags&4098&&(e=t.return),n=t.return;for(;t.return;)t=t.return;return t.tag===3?e:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}function p(e,t,n,r,i,a){for(;e!==null;){if((e.tag===5||e.tag===27||e.tag===6)&&n(e,r,i,a)||(e.tag!==22||e.memoizedState===null)&&(t||e.tag!==5&&e.tag!==27)&&p(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function m(e){for(e=e.return;e!==null;){if(e.tag===3||e.tag===5||e.tag===27)return e;e=e.return}return null}function h(e){var t=!1;for(e=e.return;e!==null&&(e.tag===4&&(t=!0),e.tag!==3&&e.tag!==5&&e.tag!==27);)e=e.return;return t}function g(e){var t=[null,null],n=m(e);return n===null||_(t,e,n.child,{foundSelf:!1}),t}function _(e,t,n,r){for(;n!==null;){if(n===t)r.foundSelf=!0;else if(n.tag===5||n.tag===27||n.tag===6){if(r.foundSelf)return e[1]=n,!0;e[0]=n}else if((n.tag!==22||n.memoizedState===null)&&_(e,t,n.child,r))return!0;n=n.sibling}return!1}function v(e){switch(e.tag){case 5:case 27:case 6:return e.stateNode;case 3:return e.stateNode.containerInfo;default:throw Error(i(559))}}var y=null,b=null;function x(e,t,n){return e===n||e===t&&(y=e,!0)}function S(e,t,n){return e===n?(b=e,!1):e===t&&(b!==null&&(y=e),!0)}function C(e){if(e===null)return null;do e=e===null?null:e.return;while(e&&e.tag!==5&&e.tag!==27&&e.tag!==3);return e||null}function w(e,t,n){for(var r=0,i=e;i;i=n(i))r++;i=0;for(var a=t;a;a=n(a))i++;for(;0<r-i;)e=n(e),r--;for(;0<i-r;)t=n(t),i--;for(;r--;){if(e===t||t!==null&&e===t.alternate)return e;e=n(e),t=n(t)}return null}var T=Object.assign,E=Symbol.for(`react.element`),D=Symbol.for(`react.transitional.element`),O=Symbol.for(`react.portal`),k=Symbol.for(`react.fragment`),A=Symbol.for(`react.strict_mode`),j=Symbol.for(`react.profiler`),M=Symbol.for(`react.consumer`),N=Symbol.for(`react.context`),P=Symbol.for(`react.forward_ref`),F=Symbol.for(`react.suspense`),I=Symbol.for(`react.suspense_list`),L=Symbol.for(`react.memo`),ee=Symbol.for(`react.lazy`),R=Symbol.for(`react.activity`),z=Symbol.for(`react.legacy_hidden`),B=Symbol.for(`react.memo_cache_sentinel`),te=Symbol.for(`react.view_transition`),V=Symbol.for(`react.recoverable`),ne=Symbol.iterator;function re(e){return typeof e!=`object`||!e?null:(e=ne&&e[ne]||e[`@@iterator`],typeof e==`function`?e:null)}var ie=Symbol.for(`react.client.reference`);function ae(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===ie?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case k:return`Fragment`;case j:return`Profiler`;case A:return`StrictMode`;case F:return`Suspense`;case I:return`SuspenseList`;case R:return`Activity`;case te:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case O:return`Portal`;case N:return e.displayName||`Context`;case M:return(e._context.displayName||`Context`)+`.Consumer`;case P:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case L:return t=e.displayName||null,t===null?ae(e.type)||`Memo`:t;case ee:t=e._payload,e=e._init;try{return ae(e(t))}catch{}}return null}var oe=Array.isArray,H=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,U=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,se={pending:!1,data:null,method:null,action:null},W=[],G=-1;function ce(e){return{current:e}}function le(e){0>G||(e.current=W[G],W[G]=null,G--)}function ue(e,t){G++,W[G]=e.current,e.current=t}var de=ce(null),fe=ce(null),pe=ce(null),me=ce(null);function he(e,t){switch(ue(pe,t),ue(fe,e),ue(de,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?dp(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=dp(t),e=fp(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}le(de),ue(de,e)}function ge(){le(de),le(fe),le(pe)}function _e(e){var t=e.memoizedState;t!==null&&(ch._currentValue=t.memoizedState,ue(me,e)),t=de.current;var n=fp(t,e.type);t!==n&&(ue(fe,e),ue(de,n))}function ve(e){fe.current===e&&(le(de),le(fe)),me.current===e&&(le(me),ch._currentValue=se)}var ye,be;function xe(e){if(ye===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);ye=t&&t[1]||``,be=-1<e.stack.indexOf(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ConnectorsPane-BOj8VFq4.js","./rolldown-runtime-XKyaHtl9.js","./useT-BfwsR95A.js","./api-B28uXBhs.js","./ConnectorsPane-B1lwOGL5.css","./AdvancedSettings-BfZmpLHF.js","./MemoryDashboard-J8lGJ5sQ.js","./zap-BvXNJAin.js","./MemoryDashboard-DwrWAXi6.css","./ScheduleManager-DDolvLap.js","./ScheduleManager-CjHJ4NbD.css","./DocumentLibrary-Bx1pci4R.js","./DocumentLibrary-CM6o8j2T.css","./FileBrowser-CjvNU8QP.js","./FileBrowser-Cna3BsT7.css","./MobileAccessModal-B-TmXjst.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-BfwsR95A.js";import{$ as H,$n as U,$t as se,A as W,An as G,B as ce,Bn as le,Bt as ue,C as de,D as fe,Dt as pe,E as me,En as he,Et as ge,F as _e,Fn as ve,Ft as ye,G as be,Gn as xe,Gt as Se,Hn as Ce,Ht as we,In as Te,It as Ee,J as De,Jn as Oe,Jt as ke,K as Ae,Kn as je,Kt as Me,L as Ne,Ln as Pe,Lt as Fe,M as Ie,Mn as Le,Mt as Re,N as ze,Nn as Be,Nt as Ve,O as He,Ot as Ue,P as We,Pn as Ge,Pt as Ke,Q as qe,Qn as Je,Qt as Ye,R as Xe,Rn as Ze,Rt as Qe,S as $e,St as et,T as tt,Tt as nt,U as rt,Un as it,Ut as at,V as K,Vn as ot,Vt as st,W as ct,Wn as lt,Wt as ut,X as dt,Xn as ft,Xt as pt,Y as mt,Yn as ht,Z as gt,Zn as _t,Zt as vt,_ as yt,_t as bt,a as xt,an as St,b as Ct,bt as wt,c as Tt,cn as Et,ct as Dt,d as Ot,dn as kt,dt as At,en as jt,er as Mt,et as Nt,fn as Pt,ft as Ft,g as It,gt as Lt,h as Rt,ht as zt,i as Bt,in as Vt,it as Ht,j as Ut,jn as Wt,jt as Gt,k as Kt,kn as qt,kt as Jt,l as Yt,ln as Xt,lt as Zt,m as Qt,mn as $t,mt as en,nn as tn,nr as nn,nt as rn,o as an,on,ot as sn,p as cn,pt as ln,q as un,qn as dn,qt as fn,r as pn,rn as mn,rt as hn,s as gn,sn as _n,st as vn,t as yn,tn as bn,tr as xn,tt as Sn,u as Cn,un as wn,ut as Tn,v as En,vt as Dn,w as On,x as kn,xn as An,yt as jn,z as Mn,zn as Nn,zt as Pn}from"./api-B28uXBhs.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Fn=n((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),In=n(((e,t)=>{t.exports=Fn()})),Ln=n((e=>{var t=f();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`),o=Symbol.for(`react.recoverable`),s=Symbol.for(`react.optimistic_key`);function c(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:r===s?s:``+r,children:e,containerInfo:t,implementation:n}}var l=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function u(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.browser=function(e){return{$$typeof:o,_reason:e}},e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return c(e,t,null,r)},e.flushSync=function(e){var t=l.T,n=i.p;try{if(l.T=null,i.p=2,e)return e()}finally{l.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=u(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=u(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return l.H.useFormState(e,t,n)},e.useFormStatus=function(){return l.H.useHostTransitionStatus()},e.version=`19.3.1`})),Rn=n(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=Ln()})),zn=n((e=>{var t=In(),n=f(),r=Rn();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){for(var t=e,n=t;n&&!n.alternate;)t=n,t.flags&4098&&(e=t.return),n=t.return;for(;t.return;)t=t.return;return t.tag===3?e:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}function p(e,t,n,r,i,a){for(;e!==null;){if((e.tag===5||e.tag===27||e.tag===6)&&n(e,r,i,a)||(e.tag!==22||e.memoizedState===null)&&(t||e.tag!==5&&e.tag!==27)&&p(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function m(e){for(e=e.return;e!==null;){if(e.tag===3||e.tag===5||e.tag===27)return e;e=e.return}return null}function h(e){var t=!1;for(e=e.return;e!==null&&(e.tag===4&&(t=!0),e.tag!==3&&e.tag!==5&&e.tag!==27);)e=e.return;return t}function g(e){var t=[null,null],n=m(e);return n===null||_(t,e,n.child,{foundSelf:!1}),t}function _(e,t,n,r){for(;n!==null;){if(n===t)r.foundSelf=!0;else if(n.tag===5||n.tag===27||n.tag===6){if(r.foundSelf)return e[1]=n,!0;e[0]=n}else if((n.tag!==22||n.memoizedState===null)&&_(e,t,n.child,r))return!0;n=n.sibling}return!1}function v(e){switch(e.tag){case 5:case 27:case 6:return e.stateNode;case 3:return e.stateNode.containerInfo;default:throw Error(i(559))}}var y=null,b=null;function x(e,t,n){return e===n||e===t&&(y=e,!0)}function S(e,t,n){return e===n?(b=e,!1):e===t&&(b!==null&&(y=e),!0)}function C(e){if(e===null)return null;do e=e===null?null:e.return;while(e&&e.tag!==5&&e.tag!==27&&e.tag!==3);return e||null}function w(e,t,n){for(var r=0,i=e;i;i=n(i))r++;i=0;for(var a=t;a;a=n(a))i++;for(;0<r-i;)e=n(e),r--;for(;0<i-r;)t=n(t),i--;for(;r--;){if(e===t||t!==null&&e===t.alternate)return e;e=n(e),t=n(t)}return null}var T=Object.assign,E=Symbol.for(`react.element`),D=Symbol.for(`react.transitional.element`),O=Symbol.for(`react.portal`),k=Symbol.for(`react.fragment`),A=Symbol.for(`react.strict_mode`),j=Symbol.for(`react.profiler`),M=Symbol.for(`react.consumer`),N=Symbol.for(`react.context`),P=Symbol.for(`react.forward_ref`),F=Symbol.for(`react.suspense`),I=Symbol.for(`react.suspense_list`),L=Symbol.for(`react.memo`),ee=Symbol.for(`react.lazy`),R=Symbol.for(`react.activity`),z=Symbol.for(`react.legacy_hidden`),B=Symbol.for(`react.memo_cache_sentinel`),te=Symbol.for(`react.view_transition`),V=Symbol.for(`react.recoverable`),ne=Symbol.iterator;function re(e){return typeof e!=`object`||!e?null:(e=ne&&e[ne]||e[`@@iterator`],typeof e==`function`?e:null)}var ie=Symbol.for(`react.client.reference`);function ae(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===ie?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case k:return`Fragment`;case j:return`Profiler`;case A:return`StrictMode`;case F:return`Suspense`;case I:return`SuspenseList`;case R:return`Activity`;case te:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case O:return`Portal`;case N:return e.displayName||`Context`;case M:return(e._context.displayName||`Context`)+`.Consumer`;case P:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case L:return t=e.displayName||null,t===null?ae(e.type)||`Memo`:t;case ee:t=e._payload,e=e._init;try{return ae(e(t))}catch{}}return null}var oe=Array.isArray,H=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,U=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,se={pending:!1,data:null,method:null,action:null},W=[],G=-1;function ce(e){return{current:e}}function le(e){0>G||(e.current=W[G],W[G]=null,G--)}function ue(e,t){G++,W[G]=e.current,e.current=t}var de=ce(null),fe=ce(null),pe=ce(null),me=ce(null);function he(e,t){switch(ue(pe,t),ue(fe,e),ue(de,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?dp(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=dp(t),e=fp(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}le(de),ue(de,e)}function ge(){le(de),le(fe),le(pe)}function _e(e){var t=e.memoizedState;t!==null&&(ch._currentValue=t.memoizedState,ue(me,e)),t=de.current;var n=fp(t,e.type);t!==n&&(ue(fe,e),ue(de,n))}function ve(e){fe.current===e&&(le(de),le(fe)),me.current===e&&(le(me),ch._currentValue=se)}var ye,be;function xe(e){if(ye===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);ye=t&&t[1]||``,be=-1<e.stack.indexOf(`
|
|
3
3
|
at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
|
|
4
4
|
`+ye+e+be}var Se=!1;function Ce(e,t){if(!e||Se)return``;Se=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}n=!1;try{var i=Object.getOwnPropertyDescriptor(e.prototype,`props`);Object.defineProperty(e.prototype,"props",{configurable:!0,set:function(){throw Error()}}),n=!0,new e}finally{n&&(i===void 0?delete e.prototype.props:Object.defineProperty(e.prototype,"props",i))}}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
|
|
5
5
|
`),l=s.split(`
|
|
@@ -57,7 +57,7 @@ Error generating stack: `+e.message+`
|
|
|
57
57
|
`)}function LC(e,t){return e?new Date(e).toLocaleString(te(t),{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`,second:`2-digit`,hour12:!0}):``}var RC=`Cancelled.`,zC=[[`This answer was interrupted when GAIA closed. Send again to retry.`,`msg.cutOff.interrupted`],[`This answer was interrupted before it finished. Send again to retry.`,`msg.cutOff.cancelled`],[`This answer ended before GAIA could save a reply. Send again to retry.`,`msg.cutOff.noReply`]],BC=/(?:^|\n\n)Before it stopped, it had started these tools: (.+)\.$/;function VC(e){let t=e.trim(),n=zC.find(([e])=>t.endsWith(e));if(!n)return null;t=t.slice(0,-n[0].length).trimEnd();let r=BC.exec(t);return r&&(t=t.slice(0,r.index).trimEnd()),{body:t,notice:n[1],tools:r?r[1]:null}}function HC(e,t){return t?`stopped`:VC(e)?`interrupted`:void 0}function UC({message:e,isStreaming:t,agentSteps:n,agentStepsActive:r,cards:i,onDelete:a,onResend:o,extraActions:s,onTryAgain:c,latencyMs:l,liveStatus:u,toolStatus:d,awaitingUser:f}){let p=T();ls();let m=(0,X.useMemo)(()=>e.role===`assistant`&&!t&&n?CC(n,e.content):{steps:n,echoed:!1},[n,e.content,e.role,t]),h=e.role===`assistant`&&(m.echoed||e.failed===!0||xC(e.content)),g=e.role===`assistant`?e.stopState??(e.content.trim()===RC?`stopped`:void 0):void 0,_=(0,X.useMemo)(()=>e.role===`assistant`&&!t?VC(e.content):null,[e.content,e.role,t]),v=(0,X.useMemo)(()=>e.role===`user`?e.content:FC(_?_.body:e.content,!!t),[e.content,e.role,t,_]),y=`${e.session_id}:${e.id}`,[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(!1),w=e.role===`user`&&gy(e.content),[E,O]=(0,X.useState)(!1),k=(0,X.useId)(),A=(0,X.useRef)(null),j=(0,X.useRef)(!1),M=(0,X.useCallback)(()=>{E&&(j.current=!0),O(!E)},[E]);(0,X.useEffect)(()=>{!E&&j.current&&(j.current=!1,A.current?.scrollIntoView?.({block:`nearest`}))},[E]);let N=(0,X.useRef)(null),F=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{N.current&&clearTimeout(N.current),F.current&&clearTimeout(F.current)},[]);let I=(0,X.useCallback)(()=>{if(navigator.clipboard?.writeText)navigator.clipboard.writeText(e.content).catch(()=>{});else{let t=document.createElement(`textarea`);t.value=e.content,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t)}x(!0),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>x(!1),2e3)},[e.content]),L=(0,X.useCallback)(()=>{S?(C(!1),F.current&&clearTimeout(F.current),a?.(e.id)):(C(!0),F.current&&clearTimeout(F.current),F.current=setTimeout(()=>C(!1),3e3))},[S,e.id,a]),ee=(0,X.useCallback)(()=>{o?.(e)},[e,o]),R=e.created_at?p(e.role===`user`?`msg.sent`:`msg.replied`,{time:LC(e.created_at,p)}):void 0;return P(`div`,{className:`msg msg-${e.role} ${h?`msg-error`:``}`,title:R,children:V(`div`,{className:`msg-inner`,children:[V(`div`,{className:`msg-header`,children:[P(`div`,{className:`msg-header-left`}),!t&&V(`div`,{className:`msg-actions`,children:[e.role===`user`&&o&&P(`button`,{className:`msg-action-btn`,onClick:ee,title:p(`msg.resend`),"aria-label":p(`msg.resend`),children:P(Fa,{size:12})}),s,e.role===`assistant`&&!h&&v.trim()&&P(DS,{messageId:y,content:v}),P(`button`,{className:`msg-copy ${b?`copied`:``}`,onClick:I,title:p(b?`msg.copied`:`msg.copy`),"aria-label":p(b?`msg.copiedAria`:`msg.copy`),children:P(b?mr:Br,{size:12})}),a&&P(`button`,{className:`msg-action-btn msg-delete ${S?`confirm`:``}`,onClick:L,title:p(S?`msg.confirmDelete`:`msg.delete`),"aria-label":p(S?`msg.confirmDeleteAria`:`msg.delete`),children:P(lo,{size:12})})]})]}),V(`div`,{className:`msg-body`,children:[e.role===`assistant`&&(m.steps&&m.steps.length>0||t)&&P(nb,{steps:m.steps??[],isActive:r??!1,running:!!t,awaitingUser:f,toolStatus:t?d:null,answer:t?void 0:v,liveLine:t&&P(_C,{active:!!r||!v,label:u,awaitingUser:f})}),h&&V(`div`,{className:`error-banner`,children:[P(J,{size:14}),P(`span`,{children:p(`msg.error`)})]}),(e.cards??i)?.map((e,t)=>P(vx,{render:e.render,data:e.data},t)),w?V(D.Fragment,{children:[P(`div`,{ref:A,id:k,className:`msg-collapsible${E?``:` is-collapsed`}`,children:P(cw,{content:v})}),P(vy,{expanded:E,onToggle:M,controls:k,collapsedLabel:p.hint(p(`msg.showAll`),_y(e.content)),expandedLabel:p(`msg.showLess`),className:`msg-expand-toggle`})]}):!(g&&v.trim()===RC)&&P(cw,{content:v,showCursor:t&&!!v&&!r,isStreaming:t}),g&&V(`div`,{className:`msg-stopped${g===`unconfirmed`||e.stopError?` is-unconfirmed`:``}`,role:`note`,children:[P(ao,{size:9,fill:`currentColor`,"aria-hidden":`true`}),P(`span`,{children:g===`unconfirmed`?p(`msg.stoppedUnconfirmed`):e.stopError?p(`msg.stoppedError`,{error:e.stopError}):p(`msg.stopped`)})]}),_&&P(`p`,{className:`msg-cut-off`,role:`note`,children:p.compose(e=>_.tools?`${e(`msg.cutOff.toolsRan`,{tools:_.tools})} ${e(_.notice)}`:e(_.notice))}),c&&!t&&V(`button`,{type:`button`,className:`msg-try-again`,onClick:c,children:[P(za,{size:12,"aria-hidden":`true`}),p(`msg.tryAgain`)]}),e.role===`assistant`&&!t&&(tC(e.content)||tC(e.failureText??``))&&P(rC,{classes:bC,note:p(`msg.reportNote`)}),e.role===`assistant`&&!t&&wb(v)&&P(Ob,{content:v}),e.role===`assistant`&&!t&&(e.stats||l!=null||e.created_at)&&V(`div`,{className:`msg-stats`,"aria-label":p(`msg.about`),children:[e.created_at&&P(`span`,{className:`msg-stats-ts`,title:p(`msg.timestamp`),children:LC(e.created_at,p)}),e.stats?.retried&&e.stats.model&&P(`span`,{title:`This answer was kept from Retry with… (${e.stats.model})`,children:ds(e.stats.model)}),P(Dx,{latencyMs:l,stats:e.stats,ended:HC(e.content,g)})]}),e.role===`assistant`&&!t&&e.id>0&&e.session_id&&P(fS,{sessionId:e.session_id,messageId:e.id}),e.role===`assistant`&&P(OS,{messageId:y}),e.role===`assistant`&&P(kS,{messageId:y})]})]})})}var WC=(0,X.createContext)(!1);function GC({lang:e,code:t}){let n=T(),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(!1),s=(0,X.useContext)(WC),c=(0,X.useId)(),l=hy(t),u=l>(s?20:25),d=u&&!a,f=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]);let p=(0,X.useCallback)(()=>{if(navigator.clipboard?.writeText)navigator.clipboard.writeText(t).catch(()=>{});else{let e=document.createElement(`textarea`);e.value=t,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}i(!0),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>i(!1),2e3)},[t]);return V(`div`,{className:`code-block${d?` is-collapsed`:``}`,dir:`ltr`,children:[V(`div`,{className:`code-header`,children:[P(`span`,{className:`code-lang`,children:e||`code`}),V(`button`,{className:`code-copy ${r?`copied`:``}`,onClick:p,title:n(r?`msg.copied`:`code.copy`),"aria-label":n(r?`msg.copiedAria`:`code.copyAria`),children:[P(r?mr:Br,{size:13}),P(`span`,{children:n(r?`code.copied`:`code.copy`)})]})]}),P(`pre`,{id:c,children:P(`code`,{children:t})}),u&&P(vy,{expanded:a,onToggle:()=>o(e=>!e),controls:c,collapsedLabel:`Expand (${l.toLocaleString(`en-US`)} lines)`,expandedLabel:`Collapse`,className:`code-expand-toggle`})]})}var KC=/(?<=["\u201c])[A-Z]:[\\/][^*?"<>|\r\n\u201c\u201d]+(?=["\u201d])|\b[A-Z]:[\\/](?=[^\s*?"<>|,;)}\]\\/])(?:[^\s*?"<>|,;)}\]\\/]+(?:(?: +(?:[^\s*?"<>|,;:)}\]\\/]+|\([^\s*?"<>|,;:)}\]\\/]+\)))+\\|[\\/]))*(?:(?:[^\s*?"<>|,;:.)}\]\\/]+ +){1,2}[^\s*?"<>|,;)}\]\\/]+\.[A-Za-z0-9]{1,5}\b|[^\s*?"<>|,;)}\]\\/]+)?/gi,qC=/[.:!']+$/,JC=RegExp(`^(?:${KC.source})$`,`i`);function YC(e){if(typeof e!=`string`)return null;let t=e.trim();return JC.test(t)?t:null}function XC({path:e}){let t=t=>{t.preventDefault(),Dn(e).catch(e=>{d.ui.error(`Failed to open path`,e)})};return V(`span`,{className:`file-path-link`,dir:`ltr`,onClick:t,title:`Open in file explorer: ${e}`,role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),t(e))},children:[P(bi,{size:12,className:`file-path-icon`}),e]})}function ZC(e){return[...e.matchAll(new RegExp(KC.source,`gi`))].map(t=>{let n=t.index+t[0].length,r=`"“`.includes(e[t.index-1]??`
|
|
58
58
|
`)&&`"”`.includes(e[n]??`
|
|
59
59
|
`);return{start:t.index,path:r?t[0]:t[0].replace(qC,``)}})}function QC(e){let t=[],n=0;for(let{start:r,path:i}of ZC(e))r>n&&t.push(e.slice(n,r)),t.push(P(XC,{path:i},r)),n=r+i.length;return t.length===0?e:(n<e.length&&t.push(e.slice(n)),P(D.Fragment,{children:t}))}var $C=(0,X.createContext)(cC([]));function ew({doc:e,page:t,t:n}){return V(`a`,{className:`citation-link`,href:me(e.id,t),target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,title:t?n(`citation.openPage`,{page:t}):n(`citation.open`,{name:e.filename}),"data-doc-id":e.id,"data-page":t,children:[P(gi,{size:12,className:`citation-icon`,"aria-hidden":`true`}),e.filename]})}function tw({doc:e,page:t,label:n,t:r}){return P(`a`,{className:`citation-page`,href:me(e.id,t),target:`_blank`,rel:`noopener noreferrer`,title:r(`citation.openPage`,{page:t}),"data-doc-id":e.id,"data-page":t,children:n})}function nw(e,t){let n=uC(e,t)[0];return gC(n?t.slice(0,n.start):t)}function rw(e,t,n,r){let i=ZC(e),a=uC(t,e).filter(e=>!i.some(t=>t.start<e.start&&e.start<t.start+t.path.length)),o=[],s=(t,r,i)=>{for(let a of r){let r=i+a.start,s=i+a.end;o.push({start:r,end:s,node:P(tw,{doc:t,page:a.page,label:e.slice(r,s),t:n},`p${r}`)})}};if(r&&s(r,gC(e.slice(0,a[0]?.start??e.length)),0),a.forEach((t,r)=>{let i=gC(e.slice(t.end,a[r+1]?.start??e.length));o.push({start:t.start,end:t.end,node:P(ew,{doc:t.doc,page:i[0]?.page,t:n},`c${t.start}`)}),s(t.doc,i,t.end)}),o.length===0)return QC(e);o.sort((e,t)=>e.start-t.start);let c=[],l=0;for(let t of o)t.start>l&&c.push(P(X.Fragment,{children:QC(e.slice(l,t.start))},`t${l}`)),c.push(t.node),l=t.end;return l<e.length&&c.push(P(X.Fragment,{children:QC(e.slice(l))},`t${l}`)),P(D.Fragment,{children:c})}function iw(e,t){return typeof t==`string`?lC(e,t):null}function aw({children:e}){let t=(0,X.useContext)($C),n=T(),r=X.Children.toArray(e),i=null,a=r.map((e,a)=>{if(typeof e==`string`){let r=rw(e,t,n,i);return i=null,P(X.Fragment,{children:r},`s${a}`)}if(i=null,X.isValidElement(e)&&e.type===ow){let o=iw(t,e.props.children);if(o){let e=r[a+1],s=typeof e==`string`?nw(t,e):[];return i=o,P(ew,{doc:o,page:s[0]?.page,t:n},`k${a}`)}}return e});return P(D.Fragment,{children:a})}function ow({className:e,children:t,node:n,...r}){let i=(0,X.useContext)($C),a=T(),o=iw(i,t);if(o)return P(ew,{doc:o,t:a});let s=YC(t);return s?P(XC,{path:s}):P(`code`,{className:`inline-code`,dir:`ltr`,...r,children:t})}var sw={code:ow,pre({children:e}){let t=X.Children.toArray(e)[0];if(X.isValidElement(t)&&(t.type===`code`||t.props?.className!==void 0||typeof t.props?.children==`string`)){let e=t.props,n=e?.className||``,r=/language-([\w-]+)/.exec(n),i=String(e?.children||``).replace(/\n$/,``),a=r?.[1]||``;return P(GC,{lang:a,code:i})}return P(`pre`,{dir:`ltr`,children:e})},table({children:e}){return P(`div`,{className:`md-table-wrap`,children:P(`table`,{className:`md-table`,dir:`auto`,children:e})})},a({href:e,children:t}){return P(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`md-link`,children:t})},p({children:e}){return P(`p`,{className:`md-p`,dir:`auto`,children:P(aw,{children:e})})},h1({children:e}){return P(`h2`,{className:`md-h2`,dir:`auto`,children:P(aw,{children:e})})},h2({children:e}){return P(`h3`,{className:`md-h3`,dir:`auto`,children:P(aw,{children:e})})},h3({children:e}){return P(`h4`,{className:`md-h4`,dir:`auto`,children:P(aw,{children:e})})},h4({children:e}){return P(`h5`,{className:`md-h4`,dir:`auto`,children:P(aw,{children:e})})},ul({children:e}){return P(`ul`,{className:`md-ul`,dir:`auto`,children:e})},ol({children:e,start:t}){return P(`ol`,{className:`md-ol`,start:t,dir:`auto`,children:e})},li({children:e}){return P(`li`,{className:`md-li`,dir:`auto`,children:P(aw,{children:e})})},blockquote({children:e}){return P(`blockquote`,{className:`md-blockquote`,dir:`auto`,children:P(aw,{children:e})})},hr(){return P(`hr`,{className:`md-hr`})},td({children:e}){return P(`td`,{dir:`auto`,children:P(aw,{children:e})})},th({children:e}){return P(`th`,{dir:`auto`,children:P(aw,{children:e})})}};function cw({content:e,showCursor:t,isStreaming:n=!1}){let r=k(e=>e.documents),i=(0,X.useMemo)(()=>cC(r),[r]);return!e&&!t?null:!e&&t?P(`span`,{className:`cursor`}):P(WC.Provider,{value:n,children:P($C.Provider,{value:i,children:V(`div`,{className:`md-content`,children:[P(Uh,{remarkPlugins:[Xv,ty,ry],disallowedElements:[...Jh],urlTransform:Xh,components:sw,children:e}),t&&P(`span`,{className:`cursor`})]})})})}function lw(e){return e.type===`status`&&e.status===`working`&&!e.phase&&(e.message??``).startsWith(`Model is processing`)}function uw(e){return e.phase===`loading_tools`?I()(`chat.loadingTools`):(e.message||``).trim()}function dw(e,t){let n=++t.current,r=Date.now();switch(e.type){case`thinking`:return{id:n,type:`thinking`,label:`Thinking`,detail:e.content,active:!0,timestamp:r};case`commentary`:return{id:n,type:`commentary`,label:`Commentary`,detail:e.content,active:!1,timestamp:r};case`tool_start`:return{id:n,type:`tool`,label:`Using tool`,tool:e.tool,detail:e.detail,narration:e.narration,active:!0,timestamp:r,mcpServer:e.mcp_server,mcpServerLabel:e.mcp_server_label,mcpTool:e.mcp_tool};case`skill_use`:return{id:n,type:`tool`,label:`Using tool`,tool:`use_skill`,detail:e.skill,narration:`Using skill: ${e.skill}`,active:!1,success:!0,timestamp:r};case`plan`:return{id:n,type:`plan`,label:`Created plan`,planSteps:e.steps,planNarrations:e.step_narrations,currentStep:e.current_step,active:!1,success:!0,timestamp:r};case`step`:return{id:n,type:`status`,label:`Step ${e.step}${e.total?` of ${e.total}`:``}`,active:!0,timestamp:r};case`status`:return e.message?.startsWith(`Agent: `)?null:{id:n,type:`status`,label:e.message||e.status||`Working`,active:e.status===`working`,...e.status===`warning`?{success:!1}:{},timestamp:r};case`agent_error`:return{id:n,type:`error`,label:`Error`,detail:e.content,success:!1,active:!1,timestamp:r};case`policy_alert`:{let t=e.tool||`unknown tool`,i=e.reason||e.message||e.content||`Tool execution was blocked by governance policy.`;return{id:n,type:`policy_alert`,label:`Policy blocked ${t}`,detail:i,tool:t,decision:e.decision||`BLOCK`,reason:i,ruleIds:e.rule_ids??[],policyVersion:e.policy_version,receiptId:e.receipt_id,success:!1,active:!1,timestamp:r}}default:return null}}var fw=new Set([`tool`,`waiting`]);function pw(e){return e.livePhase&&!fw.has(e.livePhase)?e.liveStatus:null}function mw(e,t){let n=k.getState(),r=e.status,i=uw(e);if(e.phase===`recording_found`&&e.section!=null){n.addRecordingSection({section:e.section,sections:e.sections??e.section,start:e.start??``,end:e.end??``,summary:e.summary??``,items:e.items??[]});return}if(e.phase===`recording`&&e.stage!=null){n.setRecordingStage(e.stage,{state:e.state??0,percent:e.percent,etaSeconds:e.eta_seconds});return}if(e.phase&&i&&n.setLiveStatus(i,e.phase),e.phase===`waiting`||lw(e)||i.toLowerCase().startsWith(`executing `)||r!==`working`&&r!==`warning`&&r!==`info`)return;let a=n.agentSteps[n.agentSteps.length-1];if(a&&a.type===`status`&&a.active){n.updateLastAgentStep({label:i||`Working`,detail:i});return}if(a&&a.type===`thinking`&&a.active){n.updateLastAgentStep({label:i||`Thinking`});return}let o=dw({...e,message:i},t);o&&n.addAgentStep(o)}var hw=/\s*\{\s*"?(?:tool|thought|goal)"?\s*:\s*"[^"]*"[^}]*(?:"?tool_args"?\s*:\s*\{[^}]*\})?\s*\}/g;function gw(e){let t=e.trim();if(!t.startsWith(`{`)||!t.includes(`"thought"`)&&!t.includes(`"answer"`)&&!t.includes(`"goal"`))return e;try{let e=JSON.parse(t);if(e.answer!==void 0)return String(e.answer)}catch{}let n=t.indexOf(`"answer"`);if(n===-1)return``;let r=t.indexOf(`:`,n+8);if(r===-1)return``;let i=r+1;for(;i<t.length&&/\s/.test(t[i]);)i++;if(i>=t.length||t[i]!==`"`)return``;let a=t.slice(i+1);return a.endsWith(`"}`)?a=a.slice(0,-2):a.endsWith(`"`)&&(a=a.slice(0,-1)),a.replace(/\\"/g,`"`).replace(/\\n/g,`
|
|
60
|
-
`).replace(/\\\\/g,`\\`)}function _w(e,t){if(e.type!==`agent_error`||e.recoverable!==!0)return!1;let n=t[t.length-1];return!n||n.type!==`tool`?!1:n.success===!1||!!n.active&&n.success==null}function vw(e){let t=(e||[]).filter(e=>typeof e.render==`string`&&e.render.length>0).map(e=>({render:e.render,data:e.data}));return t.length>0?t:void 0}function yw(e){return(e||[]).map(e=>{let t=e.agentSteps||e.agent_steps||void 0;return{...e,agentSteps:t,cards:e.cards||vw(t),stats:e.stats||e.inference_stats||void 0,turnSummary:e.turnSummary||e.turn_summary||void 0,stopState:e.stopState??(e.stopped?`stopped`:void 0)}})}function bw(e,t,n){let r=e.find(e=>e.id===n.id&&e.role===`user`);if(r)return r;let i=t.findIndex(e=>e.id===n.id);if(i<0)throw Error(`Message ${n.id} is no longer in this chat.`);let a=new Set(e.map(e=>e.id)),o=i-1;for(;o>=0&&!a.has(t[o].id);)o--;let s=o<0?0:e.findIndex(e=>e.id===t[o].id)+1,c=e.slice(s).filter(e=>e.role===`user`),l=0;for(let e of t.slice(o+1,i))e.role===`user`&&c[l]?.content===e.content&&l++;return c[l]?.content===n.content?c[l]:null}function xw(e,t){return!!e&&e.role===`assistant`&&!!t.failureText&&e.content.trim()===t.failureText.trim()}function Sw(e,t,n){let r=e.slice(e.findIndex(e=>e.id===t.id)+1);return r.length===0||r.length===1&&(r[0].id===n.id||xw(r[0],n))}function Cw(e,t){let n=e[e.length-1],r=t[t.length-1];if(!n?.failed||!xw(r,n))return t;let i=e=>[...e].reverse().find(e=>e.role===`user`)?.content;return i(e)===i(t)?[...t.slice(0,-1),{...r,failed:!0,failureText:n.failureText}]:t}function ww(e){return`policy-receipt-${encodeURIComponent(e)}`}function Tw(e){let t=e.content.trim();return!t||e.stopState||e.failed||e.failure||xC(t)?!1:!CC(e.agentSteps??[],t).echoed}function Ew(){(0,X.useEffect)(()=>{let e=!0,t=async()=>{try{let t=await pS();e&&t&&ES.getState().setSettings(t)}catch(e){d.ui.error(`Could not load the read-aloud settings; replies will not be read automatically`,e)}};return t(),window.addEventListener(`focus`,t),()=>{e=!1,window.removeEventListener(`focus`,t)}},[])}var Dw=[`download`,`decode`,`transcribe`,`voices`,`prepare`,`analyze`],Ow=0,kw=5;function Aw(e,t){return e==null?``:e<60?t(`recording.leftUnderMinute`):t(`recording.leftMinutes`,{minutes:Math.ceil(e/60)})}function jw(e){return Dw.map((e,t)=>t).filter(t=>t!==Ow&&t!==kw||t in e)}function Mw({state:e}){return e===1?P(mr,{size:14,"aria-hidden":`true`}):e===2?P(da,{size:14,"aria-hidden":`true`}):P(`span`,{className:`recording-progress-dot`,"aria-hidden":`true`})}function Nw({index:e,stage:t}){let n=T(),r=n(`recording.stage.${Dw[e]}`),i=t?.state===0,a=t?.percent,o=i?Aw(t?.etaSeconds,n):``,s=t?.state===2?n(`recording.skipped`):o;return V(`li`,{className:`recording-progress-row${i?` is-running`:``}${t?``:` is-waiting`}${t?.state===1?` is-done`:``}`,children:[P(`span`,{className:`recording-progress-mark`,children:P(Mw,{state:t?.state})}),P(`span`,{className:`recording-progress-label`,children:r}),i&&a!=null&&V(`bdi`,{className:`recording-progress-percent`,dir:`ltr`,children:[a,`%`]}),s&&P(`span`,{className:`recording-progress-left`,children:s}),i&&P(`div`,{className:`recording-progress-track${a==null?` is-indeterminate`:``}`,role:`progressbar`,"aria-label":r,"aria-valuemin":a==null?void 0:0,"aria-valuemax":a==null?void 0:100,"aria-valuenow":a??void 0,children:P(`div`,{className:`recording-progress-fill`,style:a==null?void 0:{inlineSize:`${a}%`}})})]})}var Pw=120;function Fw(e){let t=[];return Object.values(e).sort((e,t)=>e.section-t.section).map(e=>{let n=e.items.filter(e=>{let n=e.title.trim().toLowerCase(),r=t.some(t=>t.title===n&&Math.abs(t.seconds-e.seconds)<Pw);return r||t.push({title:n,seconds:e.seconds}),!r});return{...e,items:n}})}function Iw({sections:e}){let t=T(),n=Fw(e),r=n[0]?.sections??0;return V(`section`,{className:`recording-found`,"aria-label":t(`recording.found.title`),children:[V(`h4`,{className:`recording-found-title`,children:[t(`recording.found.title`),P(`span`,{className:`recording-found-count`,children:t(`recording.found.count`,{done:n.length,total:r})})]}),n.map(e=>V(`div`,{className:`recording-found-section`,children:[V(`p`,{className:`recording-found-span`,children:[V(`bdi`,{dir:`ltr`,className:`recording-found-time`,children:[e.start,`–`,e.end]}),e.summary&&P(`span`,{dir:`auto`,children:e.summary})]}),e.items.length>0&&P(`ul`,{className:`recording-found-items`,children:e.items.map(e=>V(`li`,{children:[P(`bdi`,{dir:`ltr`,className:`recording-found-time`,children:e.start}),P(`span`,{dir:`auto`,children:e.title})]},`${e.seconds}-${e.title}`))})]},e.section))]})}function Lw(){let e=T(),t=k(e=>e.recordingStages),n=k(e=>e.recordingSections);return t?V(`section`,{className:`recording-progress`,"aria-label":e(`recording.title`),children:[P(`ol`,{className:`recording-progress-list`,children:jw(t).map(e=>P(Nw,{index:e,stage:t[e]},e))}),n&&P(Iw,{sections:n})]}):null}var Rw=5e3,zw=2e3,Bw=3e4,Vw=6e4;function Hw(e){return e?.init_state===`initializing`?!e.init_tasks||e.init_tasks.some(e=>e.status===`pending`||e.status===`running`):!1}function Uw(e){return e.lemonade_running?`up`:e.lemonade_error?`unresponsive`:`down`}function Ww(e){return e.kind===`slow`||e.kind===`error`||e.kind===`ok`&&Uw(e.status)===`unresponsive`}function Gw(e){let t=e.kind===`ok`?e.status.download_progress?.state:void 0;return t===`downloading`||t===`starting`}function Kw(e){let t=null,n=0,r=!1,i=null,a=0,o=null,s=async()=>{let e={controller:new AbortController,cancelled:!1};o=e;let{controller:t}=e,n=setTimeout(()=>t.abort(),Vw);try{return{kind:`ok`,status:await Nt(t.signal)}}catch(n){if(e.cancelled)return null;if(t.signal.aborted)return{kind:`slow`};let r=n?.httpStatus;return r===504?{kind:`slow`}:n?.name===`ApiError`&&typeof r==`number`&&r!==502?{kind:`error`,httpStatus:r,message:n.message}:{kind:`unreachable`,error:n}}finally{clearTimeout(n),o===e&&(o=null)}},c=()=>{if(t)return t;let i=s().then(t=>{if(t!==null){n=Ww(t)?n+1:0,r=Gw(t);try{e(t)}catch(e){d.system.error(`Could not apply the system status; the next poll will try again`,e)}}}).finally(()=>{t===i&&(t=null)});return t=i,i},l=()=>Math.min((r?zw:Rw)*2**n,Bw),u=e=>{c().finally(()=>{e===a&&(i=setTimeout(()=>u(e),l()))})};return{check:c,start:()=>{let e=++a;return u(e),()=>{e===a&&(a++,i&&clearTimeout(i),i=null,o&&(o.cancelled=!0,o.controller.abort(),o=null,t=null))}}}}var qw=1e3,Jw=15e3,Yw=null,Xw=null,Zw=qw,Qw=0,$w=null;function eT(){if(Yw)return Yw;let e=Date.now();return Yw=bn().then(t=>k.getState().setActiveRuns(t,e)).catch(e=>{d.api.warn(`Could not read which chats are running`,e),Px(e)&&k.getState().loseActiveRuns()}).finally(()=>{Yw=null}),Yw}function tT(){let e=k.getState();return e.isStreaming||e.runningSessionIds.length>0}function nT(){return tT()?(Zw=qw,qw):(Zw=Math.min(Zw*2,Jw),Zw)}function rT(e){eT().then(()=>{e===Qw&&(Xw=setTimeout(()=>rT(e),nT()))})}function iT(){$w&&(Xw&&clearTimeout(Xw),Xw=null,Zw=qw,rT(++Qw))}function aT(){$w?.();let e=k.subscribe((e,t)=>{e.isStreaming&&!t.isStreaming&&iT()}),t=()=>iT();window.addEventListener(`focus`,t);let n=()=>{Qw++,Xw&&clearTimeout(Xw),Xw=null,e(),window.removeEventListener(`focus`,t),$w===n&&($w=null)};return $w=n,Zw=qw,rT(++Qw),n}var oT=3e3,sT=new Set,cT=new Map,lT=new Set,uT=null;function dT(e,t=Date.now()){cT.set(e,t)}function fT(e){let t=k.getState();return t.activeRunsAt>0&&t.activeRunsAt>=(cT.get(e)??0)&&!t.runningSessionIds.includes(e)&&!t.queuedSessionIds.includes(e)}function pT(e){return lT.add(e),()=>{lT.delete(e),uT?.()}}function mT(e){return e instanceof Error?KS(e)??(e.message||`Unknown error`):String(e)}function hT(e){let t=e?.httpStatus;return typeof t==`number`?t:void 0}function gT(e){let t=hT(e);return t===409||t===429}function _T(e){d.chat.warn(`Chat ${e} no longer exists; dropping its queued messages`),k.getState().updateQueue(e,()=>[])}function vT(e){k.getState().setQueueHold(e,!0),setTimeout(()=>k.getState().setQueueHold(e,!1),oT)}function yT(e,t,n){return hT(n)===409&&(d.chat.info(`Chat ${e} was busy; queueing the message to try again`),k.getState().updateQueue(e,e=>ee(e,t,`queued`)),vT(e),!0)}async function bT(e,t,n){let r=k.getState;if(sT.has(e)||r().queueHolds[e])return;let i=r().messageQueues[e]??[];if(i.some(e=>e.state===`sending`))return;let a=A(i);if(a||w(i)){sT.add(e);try{if(a){let t;try{t=await Vt(e)}catch(t){if(hT(t)===409){d.chat.info(`Chat ${e} is answering again; its queue waits for that turn to end`);return}if(hT(t)===404){_T(e);return}d.chat.error(`Could not learn what chat ${e}'s last reply did with the messages added to it`,t),r().updateQueue(e,e=>F(e,`GAIA could not say whether it read this message: ${mT(t)}`));return}r().updateQueue(e,e=>E(e,t))}let i=w(r().messageQueues[e]??[]);if(!i||!n())return;r().updateQueue(e,e=>ae(e,i.id,`queued`,`starting`));let o;try{o=await t(e,i.text)}catch(e){o={kind:`failed`,error:mT(e)}}if(o.kind===`accepted`){dT(e),r().updateQueue(e,e=>ie(e,i.id)),iT();return}if(o.kind===`busy`){d.chat.info(`Queued message found chat ${e} busy; holding it`),r().updateQueue(e,e=>ne(e,i.id)),vT(e);return}if(o.kind===`gone`){_T(e);return}d.chat.error(`Queued message for chat ${e} was not sent: ${o.error}`),r().updateQueue(e,e=>ne(e,i.id,o.error))}finally{sT.delete(e)}}}function xT(e){return e.type!==`status`||e.phase!==`waiting`}var ST=(e,t)=>new Promise(n=>{let r=!1,i=null,a=!1,o=e=>{r||(r=!0,e.kind===`accepted`&&(i?i.abort():a=!0),n(e))},s=()=>o({kind:`accepted`});d.chat.info(`Sending queued message for chat ${e} in the background`),i=Ve(e,t,{onChunk:s,onAgentEvent:e=>{xT(e)&&s()},onDone:s,onError:e=>{US(e)?s():gT(e)?o({kind:`busy`}):hT(e)===404?o({kind:`gone`}):o({kind:`failed`,error:mT(e)})}}),a&&i.abort()});function CT(e=ST){let t=()=>{let t=k.getState();if(!Hw(t.systemStatus))for(let n of Object.keys(t.messageQueues))!lT.has(n)&&fT(n)&&bT(n,e,()=>!lT.has(n))},n=k.subscribe((e,n)=>{(e.messageQueues!==n.messageQueues||e.queueHolds!==n.queueHolds||e.activeRunsAt!==n.activeRunsAt||e.runningSessionIds!==n.runningSessionIds||e.systemStatus!==n.systemStatus)&&t()});return uT=t,t(),()=>{n(),uT===t&&(uT=null)}}var wT=new Set([`.3g2`,`.3gp`,`.asf`,`.avi`,`.divx`,`.f4v`,`.flv`,`.m2ts`,`.m2v`,`.m4v`,`.mkv`,`.mov`,`.mp4`,`.mpeg`,`.mpg`,`.mts`,`.mxf`,`.ogv`,`.rm`,`.rmvb`,`.vob`,`.webm`,`.wmv`]),TT=new Set([`.aac`,`.ac3`,`.aif`,`.aiff`,`.amr`,`.ape`,`.au`,`.caf`,`.dts`,`.eac3`,`.flac`,`.m4a`,`.m4b`,`.mka`,`.mp2`,`.mp3`,`.oga`,`.ogg`,`.opus`,`.spx`,`.wav`,`.wma`,`.wv`]);function ET(e){let t=e.lastIndexOf(`.`);return t<0?``:e.slice(t).toLowerCase()}function DT(e){return wT.has(ET(e))}function OT(e){let t=ET(e);return wT.has(t)||TT.has(t)}var kT=`https://github.com/amd/gaia/issues/new`,AT=[{label:`Image`,extensions:new Set([`.ico`,`.heic`,`.heif`]),message:`This image format cannot be indexed.`,alternatives:[`Convert it to PNG or JPEG — GAIA reads the text in those images`],featureTitle:`Support HEIC and ICO image indexing`},{label:`Video`,extensions:wT,message:`Video files can't go in the document library.`,alternatives:[`Attach the video to a chat, and GAIA will transcribe it`],featureTitle:`Support video files in the document library`},{label:`Audio`,extensions:TT,message:`Audio files can't go in the document library.`,alternatives:[`Attach the recording to a chat, and GAIA will transcribe it`],featureTitle:`Support audio files in the document library`},{label:`Archive`,extensions:new Set([`.zip`,`.rar`,`.7z`,`.tar`,`.gz`,`.bz2`,`.xz`,`.tgz`]),message:`Archive files must be extracted before indexing.`,alternatives:[`Extract the archive contents to a folder`,`Then index the folder or individual files from the Document Library`],featureTitle:`Support automatic archive extraction for indexing`},{label:`Executable`,extensions:new Set([`.exe`,`.msi`,`.dll`,`.so`,`.app`,`.dmg`,`.bin`,`.com`]),message:`Executable and binary files cannot be indexed.`,alternatives:[`Index source code files (.py, .js, .ts, .java, etc.) instead`,`Index documentation or README files from the project`],featureTitle:`Support binary file analysis`},{label:`Database`,extensions:new Set([`.sqlite`,`.db`,`.mdb`,`.accdb`,`.dbf`]),message:`Database files are not supported for direct indexing.`,alternatives:[`Export data to CSV or JSON format, then index those files`,`Use SQL queries to extract relevant data to a text file`],featureTitle:`Support database file indexing`},{label:`Microsoft Office`,extensions:new Set([`.doc`,`.ppt`,`.xls`]),message:`Legacy Office formats (.doc, legacy PowerPoint .ppt, legacy Excel .xls) are not supported — GAIA reads only the modern XML-based formats. Modern Word (.docx), PowerPoint (.pptx), and Excel (.xlsx) are supported.`,alternatives:[`Re-save as .docx — GAIA indexes modern Word documents directly`,`Save modern PowerPoint as .pptx — GAIA indexes .pptx directly`,`Re-save legacy .xls workbooks as .xlsx — GAIA supports modern Excel files`],featureTitle:`Support legacy Microsoft Office (doc, ppt, xls) indexing`}];function jT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;for(let e of AT)if(e.extensions.has(t))return e;return null}var MT=new Set(`.pdf,.pptx,.docx,.epub,.png,.jpg,.jpeg,.webp,.bmp,.gif,.tif,.tiff,.txt,.md,.mdx,.markdown,.rst,.csv,.json,.xlsx,.html,.htm,.xml,.svg,.yaml,.yml,.py,.js,.ts,.java,.c,.cpp,.h,.rs,.go,.rb,.sh,.bat,.ps1,.log,.cfg,.ini,.toml`.split(`,`));function NT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;return MT.has(t)}function PT(){let e=navigator.userAgent;return`**Environment:**\n- GAIA Version: 0.26.0rc10\n- Platform: ${navigator.platform||`unknown`}\n- User Agent: ${e}\n- Interface: Agent UI (Web)`}function FT(e,t){let n=[`## Feature Description`,``,t||`I would like GAIA to support: **${e}**`,``,`## Use Case`,``,`_Describe how you would use this feature:_`,``,`## Current Workaround`,``,`_Is there a workaround you are currently using?_`,``,`---`,PT(),``,`_Submitted from GAIA Agent UI_`].join(`
|
|
60
|
+
`).replace(/\\\\/g,`\\`)}function _w(e,t){if(e.type!==`agent_error`||e.recoverable!==!0)return!1;let n=t[t.length-1];return!n||n.type!==`tool`?!1:n.success===!1||!!n.active&&n.success==null}function vw(e){let t=(e||[]).filter(e=>typeof e.render==`string`&&e.render.length>0).map(e=>({render:e.render,data:e.data}));return t.length>0?t:void 0}function yw(e){return(e||[]).map(e=>{let t=e.agentSteps||e.agent_steps||void 0;return{...e,agentSteps:t,cards:e.cards||vw(t),stats:e.stats||e.inference_stats||void 0,turnSummary:e.turnSummary||e.turn_summary||void 0,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,X.useEffect)(()=>{let e=!0,t=async()=>{try{let t=await pS();e&&t&&ES.getState().setSettings(t)}catch(e){d.ui.error(`Could not load the read-aloud settings; replies will not be read automatically`,e)}};return t(),window.addEventListener(`focus`,t),()=>{e=!1,window.removeEventListener(`focus`,t)}},[])}var Dw=[`download`,`decode`,`transcribe`,`voices`,`prepare`,`analyze`],Ow=0,kw=5;function Aw(e,t){return e==null?``:e<60?t(`recording.leftUnderMinute`):t(`recording.leftMinutes`,{minutes:Math.ceil(e/60)})}function jw(e){return Dw.map((e,t)=>t).filter(t=>t!==Ow&&t!==kw||t in e)}function Mw({state:e}){return e===1?P(mr,{size:14,"aria-hidden":`true`}):e===2?P(da,{size:14,"aria-hidden":`true`}):P(`span`,{className:`recording-progress-dot`,"aria-hidden":`true`})}function Nw({index:e,stage:t}){let n=T(),r=n(`recording.stage.${Dw[e]}`),i=t?.state===0,a=t?.percent,o=i?Aw(t?.etaSeconds,n):``,s=t?.state===2?n(`recording.skipped`):o;return V(`li`,{className:`recording-progress-row${i?` is-running`:``}${t?``:` is-waiting`}${t?.state===1?` is-done`:``}`,children:[P(`span`,{className:`recording-progress-mark`,children:P(Mw,{state:t?.state})}),P(`span`,{className:`recording-progress-label`,children:r}),i&&a!=null&&V(`bdi`,{className:`recording-progress-percent`,dir:`ltr`,children:[a,`%`]}),s&&P(`span`,{className:`recording-progress-left`,children:s}),i&&P(`div`,{className:`recording-progress-track${a==null?` is-indeterminate`:``}`,role:`progressbar`,"aria-label":r,"aria-valuemin":a==null?void 0:0,"aria-valuemax":a==null?void 0:100,"aria-valuenow":a??void 0,children:P(`div`,{className:`recording-progress-fill`,style:a==null?void 0:{inlineSize:`${a}%`}})})]})}var Pw=120;function Fw(e){let t=[];return Object.values(e).sort((e,t)=>e.section-t.section).map(e=>{let n=e.items.filter(e=>{let n=e.title.trim().toLowerCase(),r=t.some(t=>t.title===n&&Math.abs(t.seconds-e.seconds)<Pw);return r||t.push({title:n,seconds:e.seconds}),!r});return{...e,items:n}})}function Iw({sections:e}){let t=T(),n=Fw(e),r=n[0]?.sections??0;return V(`section`,{className:`recording-found`,"aria-label":t(`recording.found.title`),children:[V(`h4`,{className:`recording-found-title`,children:[t(`recording.found.title`),P(`span`,{className:`recording-found-count`,children:t(`recording.found.count`,{done:n.length,total:r})})]}),n.map(e=>V(`div`,{className:`recording-found-section`,children:[V(`p`,{className:`recording-found-span`,children:[V(`bdi`,{dir:`ltr`,className:`recording-found-time`,children:[e.start,`–`,e.end]}),e.summary&&P(`span`,{dir:`auto`,children:e.summary})]}),e.items.length>0&&P(`ul`,{className:`recording-found-items`,children:e.items.map(e=>V(`li`,{children:[P(`bdi`,{dir:`ltr`,className:`recording-found-time`,children:e.start}),P(`span`,{dir:`auto`,children:e.title})]},`${e.seconds}-${e.title}`))})]},e.section))]})}function Lw(){let e=T(),t=k(e=>e.recordingStages),n=k(e=>e.recordingSections);return t?V(`section`,{className:`recording-progress`,"aria-label":e(`recording.title`),children:[P(`ol`,{className:`recording-progress-list`,children:jw(t).map(e=>P(Nw,{index:e,stage:t[e]},e))}),n&&P(Iw,{sections:n})]}):null}var Rw=5e3,zw=2e3,Bw=3e4,Vw=6e4;function Hw(e){return e?.init_state===`initializing`?!e.init_tasks||e.init_tasks.some(e=>e.status===`pending`||e.status===`running`):!1}function Uw(e){return e.lemonade_running?`up`:e.lemonade_error?`unresponsive`:`down`}function Ww(e){return e.kind===`slow`||e.kind===`error`||e.kind===`ok`&&Uw(e.status)===`unresponsive`}function Gw(e){let t=e.kind===`ok`?e.status.download_progress?.state:void 0;return t===`downloading`||t===`starting`}function Kw(e){let t=null,n=0,r=!1,i=null,a=0,o=null,s=async()=>{let e={controller:new AbortController,cancelled:!1};o=e;let{controller:t}=e,n=setTimeout(()=>t.abort(),Vw);try{return{kind:`ok`,status:await Nt(t.signal)}}catch(n){if(e.cancelled)return null;if(t.signal.aborted)return{kind:`slow`};let r=n?.httpStatus;return r===504?{kind:`slow`}:n?.name===`ApiError`&&typeof r==`number`&&r!==502?{kind:`error`,httpStatus:r,message:n.message}:{kind:`unreachable`,error:n}}finally{clearTimeout(n),o===e&&(o=null)}},c=()=>{if(t)return t;let i=s().then(t=>{if(t!==null){n=Ww(t)?n+1:0,r=Gw(t);try{e(t)}catch(e){d.system.error(`Could not apply the system status; the next poll will try again`,e)}}}).finally(()=>{t===i&&(t=null)});return t=i,i},l=()=>Math.min((r?zw:Rw)*2**n,Bw),u=e=>{c().finally(()=>{e===a&&(i=setTimeout(()=>u(e),l()))})};return{check:c,start:()=>{let e=++a;return u(e),()=>{e===a&&(a++,i&&clearTimeout(i),i=null,o&&(o.cancelled=!0,o.controller.abort(),o=null,t=null))}}}}var qw=1e3,Jw=15e3,Yw=null,Xw=null,Zw=qw,Qw=0,$w=null;function eT(){if(Yw)return Yw;let e=Date.now();return Yw=bn().then(t=>k.getState().setActiveRuns(t,e)).catch(e=>{d.api.warn(`Could not read which chats are running`,e),Px(e)&&k.getState().loseActiveRuns()}).finally(()=>{Yw=null}),Yw}function tT(){let e=k.getState();return e.isStreaming||e.runningSessionIds.length>0}function nT(){return tT()?(Zw=qw,qw):(Zw=Math.min(Zw*2,Jw),Zw)}function rT(e){eT().then(()=>{e===Qw&&(Xw=setTimeout(()=>rT(e),nT()))})}function iT(){$w&&(Xw&&clearTimeout(Xw),Xw=null,Zw=qw,rT(++Qw))}function aT(){$w?.();let e=k.subscribe((e,t)=>{e.isStreaming&&!t.isStreaming&&iT()}),t=()=>iT();window.addEventListener(`focus`,t);let n=()=>{Qw++,Xw&&clearTimeout(Xw),Xw=null,e(),window.removeEventListener(`focus`,t),$w===n&&($w=null)};return $w=n,Zw=qw,rT(++Qw),n}var oT=3e3,sT=new Set,cT=new Map,lT=new Set,uT=null;function dT(e,t=Date.now()){cT.set(e,t)}function fT(e){let t=k.getState();return t.activeRunsAt>0&&t.activeRunsAt>=(cT.get(e)??0)&&!t.runningSessionIds.includes(e)&&!t.queuedSessionIds.includes(e)}function pT(e){return lT.add(e),()=>{lT.delete(e),uT?.()}}function mT(e){return e instanceof Error?KS(e)??(e.message||`Unknown error`):String(e)}function hT(e){let t=e?.httpStatus;return typeof t==`number`?t:void 0}function gT(e){let t=hT(e);return t===409||t===429}function _T(e){d.chat.warn(`Chat ${e} no longer exists; dropping its queued messages`),k.getState().updateQueue(e,()=>[])}function vT(e){k.getState().setQueueHold(e,!0),setTimeout(()=>k.getState().setQueueHold(e,!1),oT)}function yT(e,t,n){return hT(n)===409&&(d.chat.info(`Chat ${e} was busy; queueing the message to try again`),k.getState().updateQueue(e,e=>ee(e,t,`queued`)),vT(e),!0)}async function bT(e,t,n){let r=k.getState;if(sT.has(e)||r().queueHolds[e])return;let i=r().messageQueues[e]??[];if(i.some(e=>e.state===`sending`))return;let a=A(i);if(a||w(i)){sT.add(e);try{if(a){let t;try{t=await Vt(e)}catch(t){if(hT(t)===409){d.chat.info(`Chat ${e} is answering again; its queue waits for that turn to end`);return}if(hT(t)===404){_T(e);return}d.chat.error(`Could not learn what chat ${e}'s last reply did with the messages added to it`,t),r().updateQueue(e,e=>F(e,`GAIA could not say whether it read this message: ${mT(t)}`));return}r().updateQueue(e,e=>E(e,t))}let i=w(r().messageQueues[e]??[]);if(!i||!n())return;r().updateQueue(e,e=>ae(e,i.id,`queued`,`starting`));let o;try{o=await t(e,i.text)}catch(e){o={kind:`failed`,error:mT(e)}}if(o.kind===`accepted`){dT(e),r().updateQueue(e,e=>ie(e,i.id)),iT();return}if(o.kind===`busy`){d.chat.info(`Queued message found chat ${e} busy; holding it`),r().updateQueue(e,e=>ne(e,i.id)),vT(e);return}if(o.kind===`gone`){_T(e);return}d.chat.error(`Queued message for chat ${e} was not sent: ${o.error}`),r().updateQueue(e,e=>ne(e,i.id,o.error))}finally{sT.delete(e)}}}function xT(e){return e.type!==`status`||e.phase!==`waiting`}var ST=(e,t)=>new Promise(n=>{let r=!1,i=null,a=!1,o=e=>{r||(r=!0,e.kind===`accepted`&&(i?i.abort():a=!0),n(e))},s=()=>o({kind:`accepted`});d.chat.info(`Sending queued message for chat ${e} in the background`),i=Ve(e,t,{onChunk:s,onAgentEvent:e=>{xT(e)&&s()},onDone:s,onError:e=>{US(e)?s():gT(e)?o({kind:`busy`}):hT(e)===404?o({kind:`gone`}):o({kind:`failed`,error:mT(e)})}}),a&&i.abort()});function CT(e=ST){let t=()=>{let t=k.getState();if(!Hw(t.systemStatus))for(let n of Object.keys(t.messageQueues))!lT.has(n)&&fT(n)&&bT(n,e,()=>!lT.has(n))},n=k.subscribe((e,n)=>{(e.messageQueues!==n.messageQueues||e.queueHolds!==n.queueHolds||e.activeRunsAt!==n.activeRunsAt||e.runningSessionIds!==n.runningSessionIds||e.systemStatus!==n.systemStatus)&&t()});return uT=t,t(),()=>{n(),uT===t&&(uT=null)}}var wT=new Set([`.3g2`,`.3gp`,`.asf`,`.avi`,`.divx`,`.f4v`,`.flv`,`.m2ts`,`.m2v`,`.m4v`,`.mkv`,`.mov`,`.mp4`,`.mpeg`,`.mpg`,`.mts`,`.mxf`,`.ogv`,`.rm`,`.rmvb`,`.vob`,`.webm`,`.wmv`]),TT=new Set([`.aac`,`.ac3`,`.aif`,`.aiff`,`.amr`,`.ape`,`.au`,`.caf`,`.dts`,`.eac3`,`.flac`,`.m4a`,`.m4b`,`.mka`,`.mp2`,`.mp3`,`.oga`,`.ogg`,`.opus`,`.spx`,`.wav`,`.wma`,`.wv`]);function ET(e){let t=e.lastIndexOf(`.`);return t<0?``:e.slice(t).toLowerCase()}function DT(e){return wT.has(ET(e))}function OT(e){let t=ET(e);return wT.has(t)||TT.has(t)}var kT=`https://github.com/amd/gaia/issues/new`,AT=[{label:`Image`,extensions:new Set([`.ico`,`.heic`,`.heif`]),message:`This image format cannot be indexed.`,alternatives:[`Convert it to PNG or JPEG — GAIA reads the text in those images`],featureTitle:`Support HEIC and ICO image indexing`},{label:`Video`,extensions:wT,message:`Video files can't go in the document library.`,alternatives:[`Attach the video to a chat, and GAIA will transcribe it`],featureTitle:`Support video files in the document library`},{label:`Audio`,extensions:TT,message:`Audio files can't go in the document library.`,alternatives:[`Attach the recording to a chat, and GAIA will transcribe it`],featureTitle:`Support audio files in the document library`},{label:`Archive`,extensions:new Set([`.zip`,`.rar`,`.7z`,`.tar`,`.gz`,`.bz2`,`.xz`,`.tgz`]),message:`Archive files must be extracted before indexing.`,alternatives:[`Extract the archive contents to a folder`,`Then index the folder or individual files from the Document Library`],featureTitle:`Support automatic archive extraction for indexing`},{label:`Executable`,extensions:new Set([`.exe`,`.msi`,`.dll`,`.so`,`.app`,`.dmg`,`.bin`,`.com`]),message:`Executable and binary files cannot be indexed.`,alternatives:[`Index source code files (.py, .js, .ts, .java, etc.) instead`,`Index documentation or README files from the project`],featureTitle:`Support binary file analysis`},{label:`Database`,extensions:new Set([`.sqlite`,`.db`,`.mdb`,`.accdb`,`.dbf`]),message:`Database files are not supported for direct indexing.`,alternatives:[`Export data to CSV or JSON format, then index those files`,`Use SQL queries to extract relevant data to a text file`],featureTitle:`Support database file indexing`},{label:`Microsoft Office`,extensions:new Set([`.doc`,`.ppt`,`.xls`]),message:`Legacy Office formats (.doc, legacy PowerPoint .ppt, legacy Excel .xls) are not supported — GAIA reads only the modern XML-based formats. Modern Word (.docx), PowerPoint (.pptx), and Excel (.xlsx) are supported.`,alternatives:[`Re-save as .docx — GAIA indexes modern Word documents directly`,`Save modern PowerPoint as .pptx — GAIA indexes .pptx directly`,`Re-save legacy .xls workbooks as .xlsx — GAIA supports modern Excel files`],featureTitle:`Support legacy Microsoft Office (doc, ppt, xls) indexing`}];function jT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;for(let e of AT)if(e.extensions.has(t))return e;return null}var MT=new Set(`.pdf,.pptx,.docx,.epub,.png,.jpg,.jpeg,.webp,.bmp,.gif,.tif,.tiff,.txt,.md,.mdx,.markdown,.rst,.csv,.json,.xlsx,.html,.htm,.xml,.svg,.yaml,.yml,.py,.js,.ts,.java,.c,.cpp,.h,.rs,.go,.rb,.sh,.bat,.ps1,.log,.cfg,.ini,.toml`.split(`,`));function NT(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;return MT.has(t)}function PT(){let e=navigator.userAgent;return`**Environment:**\n- GAIA Version: 0.26.0rc12\n- Platform: ${navigator.platform||`unknown`}\n- User Agent: ${e}\n- Interface: Agent UI (Web)`}function FT(e,t){let n=[`## Feature Description`,``,t||`I would like GAIA to support: **${e}**`,``,`## Use Case`,``,`_Describe how you would use this feature:_`,``,`## Current Workaround`,``,`_Is there a workaround you are currently using?_`,``,`---`,PT(),``,`_Submitted from GAIA Agent UI_`].join(`
|
|
61
61
|
`);return`${kT}?${new URLSearchParams({title:`[Feature] ${e}`,body:n,labels:`enhancement,agent-ui`}).toString()}`}function IT(e,t){let n=[`## Bug Description`,``,t||e,``,`## Steps to Reproduce`,``,`1. Open GAIA Agent UI`,`2. _Describe what you did:_`,`3. `,``,`## Expected Behavior`,``,`_What did you expect to happen?_`,``,`## Actual Behavior`,``,`_What happened instead?_`,``,`---`,PT(),``,`_Submitted from GAIA Agent UI_`].join(`
|
|
62
62
|
`);return`${kT}?${new URLSearchParams({title:`[Bug] ${e}`,body:n,labels:`bug,agent-ui`}).toString()}`}var LT={corrupted:`The file looks damaged. Re-download or re-export it, then index the new copy.`,encrypted:`The PDF needs a password to open. Save a copy without the password, then index that.`,empty:`The PDF has no readable text, which usually means it is a scan. Run OCR on it, then index it again.`,empty_file:`This file is empty. Add content to it, then index it again.`,unsupported_workbook:`This is an old .xls workbook or has a password. Open it in Excel, save a copy as .xlsx without a password, then index that.`};function RT(e,t){return e.startsWith(t)?e.slice(t.length).trim():e}function zT({filename:e,error:t,status:n,kind:r,onDismiss:i,timeout:a=15e3}){let o=(0,X.useRef)(null);(0,X.useEffect)(()=>(a>0&&(o.current=setTimeout(i,a)),()=>{o.current&&clearTimeout(o.current)}),[i,a]);let s=e.includes(`.`)?`.`+e.split(`.`).pop()?.toLowerCase():``,c=s?jT(s):null,l=t.toLowerCase().includes(`unsupported file type`)||t.toLowerCase().includes(`not supported for indexing`)||t.toLowerCase().includes(`file type not allowed`)||c!==null,u=t.toLowerCase().includes(`fetch`)||t.toLowerCase().includes(`network`)||t.toLowerCase().includes(`connect`),d,f,p,m=wr,h=r?LT[r]:void 0;return h?(d=`"${e}" can't be read`,f=h,p=null,m=J):n===404?(d=`"${e}" doesn't exist`,f=RT(t,`File not found:`),p=null,m=J):n===403?(d=`GAIA can't read files in that location`,f=`${t} Or drop the file here instead (up to 20 MB) and GAIA keeps its own copy.`,p=null,m=J):l&&c?(d=`${c.label} files not supported`,f=c.message,p=FT(c.featureTitle),m=J):l&&!s?(d=`"${e}" has no file extension`,f=RT(t,`File type not allowed:`),p=null,m=J):l?(d=`File type not supported: ${s}`,f=`This file format cannot be indexed. Supported: PDF, DOCX, PPTX, XLSX, EPUB, images (PNG, JPG, WEBP, ...), TXT, MD, CSV, JSON, HTML, XML, YAML, and 30+ code file formats.`,p=FT(`Support ${s} file indexing`),m=J):u?(d=`Connection error`,f=`Could not reach the GAIA server. Make sure the backend is running.`,p=IT(`Upload connection error for ${e}`),m=wr):(d=`Failed to index "${e}"`,f=t||`An unexpected error occurred during indexing.`,p=IT(`Indexing error: ${t.slice(0,80)}`),m=or),V(`div`,{className:`upload-error-toast`,role:`alert`,children:[P(m,{size:16}),V(`div`,{className:`upload-error-content`,children:[P(`div`,{className:`upload-error-title`,children:d}),V(`div`,{className:`upload-error-detail`,children:[f,p&&` `,p===null?null:l?P(`a`,{href:p,target:`_blank`,rel:`noopener noreferrer`,children:`Request this feature →`}):P(`a`,{href:p,target:`_blank`,rel:`noopener noreferrer`,children:`Report this issue →`})]})]}),P(`button`,{className:`upload-error-dismiss`,onClick:i,"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}function BT(e,t){let n=e=>t.some(t=>t.id===e&&!(`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 VT(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 HT=4e3;function UT({content:e,onRetry:t}){let[n,r]=(0,X.useState)([]),[i,a]=(0,X.useState)(!1),o=(0,X.useCallback)(()=>{he().then(e=>r(e.connectors||[])).catch(e=>d.ui.warn(`ConnectorRetryBanner: connector fetch failed`,e))},[]),s=BT(e,n);if((0,X.useEffect)(()=>{o();let e=()=>o();return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[o]),(0,X.useEffect)(()=>{if(s)return;let e=setInterval(o,HT);return()=>clearInterval(e)},[s,o]),!s||i)return null;let c=VT(e,n);return V(`div`,{className:`connector-retry-banner`,role:`status`,children:[P(Or,{size:14,className:`connector-retry-banner__icon`}),V(`span`,{className:`connector-retry-banner__text`,children:[c,` connected since this reply — ask again to run it now.`]}),V(`button`,{type:`button`,className:`connector-retry-banner__btn`,onClick:()=>{a(!0),t()},children:[P(Fa,{size:12}),P(`span`,{children:`Ask again`})]}),P(`button`,{type:`button`,className:`connector-retry-banner__dismiss`,onClick:()=>a(!0),"aria-label":`Dismiss`,children:`×`})]})}function WT(e){return e.isMedia?DT(e.name)?mi:ci:gi}var GT=240,KT=1e5;function qT({value:e,onChange:t,onSubmit:n,onStop:r,streaming:i=!1,stopping:a=!1,queueWhileStreaming:o=!1,disabledReason:s,attachments:c,placeholder:l,autoFocus:u,inputRef:d,leftControls:f,rightControls:p}){let m=T(),h=(0,X.useRef)(null),g=d??h,_=(0,X.useRef)(null),v=!!s,y=e.trim().length>0||c.hasUploaded,b=c.compose(e.trim()).length,x=b>KT,S=!v&&(!i||o)&&!c.uploading&&y&&!x,C=s||l||m(`composer.placeholder`);(0,X.useLayoutEffect)(()=>{let e=g.current;if(!e)return;let t=()=>{e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,GT)}px`};if(t(),typeof ResizeObserver>`u`)return;let n=e.clientWidth,r=new ResizeObserver(()=>{e.clientWidth!==n&&(n=e.clientWidth,t())});return r.observe(e),()=>r.disconnect()},[e,C,g]);let w=(0,X.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),S&&n())},[S,n]),E=(0,X.useCallback)(e=>{e.dataTransfer?.files?.length&&(e.preventDefault(),e.stopPropagation(),c.addFiles(Array.from(e.dataTransfer.files)))},[c]);return V(`div`,{className:`composer${v?` composer-disabled`:``}`,onDrop:E,onDragOver:e=>{e.dataTransfer?.types?.includes(`Files`)&&e.preventDefault()},children:[c.attachments.length>0&&P(`ul`,{className:`composer-attachments`,"aria-label":m(`composer.attached`),children:c.attachments.map(e=>{let t=WT(e);return V(`li`,{className:`composer-attachment${e.error?` has-error`:``}${e.isMedia?` is-media`:``}`,children:[e.isImage&&e.url?P(`img`,{src:e.url,alt:``,className:`composer-attachment-thumb`}):P(t,{size:14,"aria-hidden":`true`}),P(`span`,{className:`composer-attachment-name`,title:e.name,dir:`auto`,children:e.name}),e.uploading&&P(`span`,{className:`composer-attachment-state`,children:e.progress===void 0?m(`composer.uploading`):m(`composer.uploadingPercent`,{percent:e.progress})}),e.uploaded&&e.isMedia&&P(`span`,{className:`composer-attachment-state`,children:m(`composer.mediaReady`)}),e.error&&P(`span`,{className:`composer-attachment-state`,role:`alert`,title:e.error,children:e.error}),P(`button`,{type:`button`,className:`composer-icon-btn`,onClick:()=>c.remove(e.id),"aria-label":m(`composer.remove`,{name:e.name}),children:P(Y,{size:12})})]},e.id)})}),P(`textarea`,{ref:g,className:`composer-input`,value:e,onChange:e=>t(e.target.value),onKeyDown:w,onPaste:e=>{c.handlePaste(e)},placeholder:C,rows:1,disabled:v,autoFocus:u,"aria-label":m(`composer.message`),dir:`auto`}),x&&V(`p`,{className:`composer-limit-error`,role:`alert`,children:[m(`composer.tooLong`,{sent:b.toLocaleString(),max:1e5.toLocaleString()}),` `,m(`composer.tooLongHint`)]}),V(`div`,{className:`composer-row`,children:[V(`div`,{className:`composer-row-left`,children:[P(`button`,{type:`button`,className:`composer-icon-btn`,onClick:()=>_.current?.click(),disabled:v,"aria-label":m(`composer.attach`),title:m(`composer.attach`),children:P(Na,{size:16})}),P(`input`,{ref:_,type:`file`,multiple:!0,hidden:!0,onChange:e=>{e.target.files&&c.addFiles(Array.from(e.target.files)),e.target.value=``}}),f]}),V(`div`,{className:`composer-row-right`,children:[p,i&&o&&y&&P(`button`,{type:`button`,className:`composer-send`,onClick:n,disabled:!S,"aria-label":m(`composer.queue`),title:m(`composer.queueTitle`),children:P(Xn,{size:16})}),i?P(`button`,{type:`button`,className:`composer-send is-stop`,onClick:r,disabled:a,"aria-label":m(`composer.stop`),title:a?m(`composer.stopping`):m.hint(m(`composer.stop`),`Esc`),children:P(ao,{size:12,fill:`currentColor`})}):P(`button`,{type:`button`,className:`composer-send`,onClick:n,disabled:!S,"aria-label":m(`composer.send`),title:m.hint(m(`composer.send`),`Enter`),children:P(Xn,{size:16})})]})]})]})}var JT=8,YT=8;function XT({label:e,warning:t,children:n,id:r,pinned:i=!1,onUnpin:a,tabIndex:o}){let s=(0,X.useId)(),c=r??s,l=(0,X.useRef)(null),u=(0,X.useRef)(null),[d,f]=(0,X.useState)(!1),p=d||i,[m,h]=(0,X.useState)(null);return(0,X.useLayoutEffect)(()=>{if(!p){h(null);return}let e=l.current?.getBoundingClientRect(),t=u.current?.getBoundingClientRect(),n=l.current?.closest(`[role="dialog"]`)?.getBoundingClientRect()??e;if(!e||!t||!n)return;let r=window.innerWidth,i=window.innerHeight,a,o;n.right+JT+t.width<=r-YT?(a=n.right+JT,o=e.top+e.height/2-t.height/2):n.left-JT-t.width>=YT?(a=n.left-JT-t.width,o=e.top+e.height/2-t.height/2):(a=Math.min(Math.max(YT,e.right-t.width),r-YT-t.width),o=e.top-JT-t.height>=YT?e.top-JT-t.height:e.bottom+JT),o=Math.min(Math.max(YT,o),i-YT-t.height),h({left:a,top:o})},[p]),(0,X.useEffect)(()=>{if(!p)return;let e=()=>{f(!1),a?.()};return window.addEventListener(`scroll`,e,!0),()=>window.removeEventListener(`scroll`,e,!0)},[p,a]),V(D.Fragment,{children:[P(`button`,{ref:l,type:`button`,className:`info-bubble-icon${t?` is-warning`:``}`,"aria-label":e,tabIndex:o,"aria-describedby":p?c:void 0,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),onFocus:()=>f(!0),onBlur:()=>f(!1),onClick:e=>{e.stopPropagation(),f(e=>!e)},onKeyDown:e=>{e.key===`Escape`&&p&&(e.stopPropagation(),f(!1))},children:P(Hi,{size:13,"aria-hidden":`true`})}),p&&(0,eS.createPortal)(P(`div`,{ref:u,id:c,role:`tooltip`,className:`info-bubble`,style:m?{left:m.left,top:m.top}:{left:0,top:0,visibility:`hidden`},children:n}),document.body)]})}function ZT(e){return e<.1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function QT(e,t=z){return e?t(`settings.price.perMillion`,{input:ZT(e.input_per_million),output:ZT(e.output_per_million)}):t(`settings.price.unknown`)}function $T(e){return`$${e.toFixed(2)}`}var eE=2e3,tE=`waiting_for_os_permission`,nE=5;function rE(e,t){let n=e.rank?`#${e.rank} ${e.note??``}`.trim():null;return t?[n,QT(e.price)].filter(e=>!!e):[Ss(e.placement),e.size_gb?`${e.size_gb} GB`:null,e.tokens_per_second?`${Math.round(e.tokens_per_second)} tok/s on this PC`:null,n,e.custom?`added by you`:null].filter(e=>!!e)}function iE({m:e,onDownload:t,busy:n}){if(Ts(e)){let t=Math.round(e.download_progress?.percent??0);return V(`span`,{className:`model-state is-downloading`,title:`Downloading, ${t}%`,children:[P(q,{size:12,className:`spin`,"aria-hidden":`true`}),` `,t,`%`]})}let r=ws(e);return r===`not_downloaded`?P(`button`,{type:`button`,className:`model-state-btn`,onClick:e=>{e.stopPropagation(),t()},disabled:n,"aria-label":`Download ${e.display_name??e.id}`,title:xs.not_downloaded,tabIndex:-1,children:P(Jr,{size:13,"aria-hidden":`true`})}):r===`loaded`?P(`span`,{className:`model-state is-loaded`,role:`img`,"aria-label":xs.loaded,title:xs.loaded}):P(`span`,{className:`model-state is-ready`,title:xs.downloaded,children:`Ready`})}function aE(){let e=T(),t=cs(e=>e.active),n=cs(e=>e.select),r=cs(e=>e.queued),i=cs(e=>e.queue),a=cs(e=>e.queueError),o=cs(e=>e.rememberNames);cs(e=>e.names);let s=hs(),c=k(e=>gs(t,e.sessions,e.currentSessionId)),l=k(e=>e.isStreaming),u=k(e=>e.openSettings),d=(0,X.useRef)(null),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(0),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(null),[A,j]=(0,X.useState)(0),[M,N]=(0,X.useState)(null),F=(0,X.useRef)(0),I=(0,X.useRef)(null),L=(0,X.useId)(),ee=(0,X.useRef)(null),R=(0,X.useRef)(null),[z,B]=(0,X.useState)(null),[te,ne]=(0,X.useState)(null),re=(0,X.useCallback)(()=>ne(null),[]),ie=(0,X.useCallback)(()=>p(!1),[]),ae=(0,X.useRef)(!1),oe=(0,X.useCallback)(async(t=!1)=>{t||(ae.current=!1,y(null),h(null));try{let{providers:n,lemonade_error:r}=await Tn();if(r)throw Error(r);let i=n.filter(e=>!e.remote||e.models_discovered||e.id===`fireworks`||e.registered),a=await Promise.all(i.map(async t=>{if(t.blocked)return{provider:t,models:[],error:e(`settings.privacy.localOnlyBlocked`)};if(t.remote&&!t.models_discovered)return{provider:t,models:[]};try{let n=await Zt(t.id);return{provider:t,models:n.models,error:n.blocked?e(`settings.privacy.localOnlyBlocked`):void 0}}catch(e){return{provider:t,models:[],error:Ix(e)}}}));o(a.flatMap(e=>e.models)),_(a.flatMap(e=>e.models).filter(e=>e.available===!1).length),t||(ae.current=!0),h(a.map(e=>({...e,models:e.models.filter(e=>e.available!==!1)})))}catch(e){y(Ix(e))}},[o,e]);(0,X.useEffect)(()=>{f&&(x(null),B(null),ne(null),oe())},[f,oe]),(0,X.useEffect)(()=>{if(!f||!m||!ae.current)return;let e=ee.current?.querySelector(`[role="option"][tabindex="0"]`);e&&(ae.current=!1,e.focus(),e.scrollIntoView?.({block:`nearest`}))},[f,m]),(0,X.useEffect)(()=>{b&&R.current?.scrollIntoView?.({block:`nearest`})},[b]);let H=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return;let t=Array.from(ee.current?.querySelectorAll(`[role="option"]:not(:disabled)`)??[]);if(!t.length)return;let n=t.indexOf(document.activeElement),r;switch(e.key){case`ArrowDown`:r=n<0?0:Math.min(n+1,t.length-1);break;case`ArrowUp`:r=n<0?t.length-1:Math.max(n-1,0);break;case`Home`:r=0;break;case`End`:r=t.length-1;break;case`ArrowRight`:case`i`:{let r=n<0?void 0:t[n].dataset.row;if(!r)return;e.preventDefault(),ne(t=>e.key===`i`&&t===r?null:r);return}case`ArrowLeft`:e.preventDefault(),ne(null);return;default:return}e.preventDefault(),t[r].focus(),t[r].scrollIntoView?.({block:`nearest`})},U=!!m?.some(e=>e.models.some(Ts)),se=!!m?.some(e=>e.provider.key_state===tE);(0,X.useEffect)(()=>{if(!(f||D)||!(U||D||se))return;let e=setInterval(()=>{oe(!0)},eE);return()=>clearInterval(e)},[f,U,D,se,oe]);let W=(0,X.useCallback)(async e=>{E(e),j(e=>e+1),y(null);try{await fe(e),await oe(!0)}catch(t){O(t=>t?.model===e?null:t),y(Ix(t))}finally{E(null),j(e=>e-1)}},[oe]),G=(0,X.useCallback)(async(e,r)=>{if(r.remote&&!t?.remote&&b?.model!==e)return x({model:e,provider:r}),null;if(x(null),l)return i(e===t?.model?null:e),p(!1),null;C(e),y(null);try{return await n(e),N(null),p(!1),null}catch(e){let t=Ix(e);return y(t),t}finally{C(null)}},[t?.model,t?.remote,b,i,n,l]);(0,X.useEffect)(()=>{if(!D||!m||A>0)return;let{model:e,provider:t}=D,n=()=>(I.current!==m&&(I.current=m,F.current+=1),F.current>=nE),r=m.flatMap(e=>e.models).find(t=>t.id===e);if(!r){if(!n())return;O(null),N(`${ds(e)} is no longer in the model list, so it wasn't switched to.`);return}if(Ts(r)){F.current=0;return}let i=r.download_progress;if(i?.state===`error`)O(null),N(`Downloading ${ds(e)} failed: ${i.message??`no reason given`}`);else if(i?.state!==`complete`&&ws(r)===`not_downloaded`){if(!n())return;O(null),N(`The download of ${ds(e)} never started. Try the download button again.`)}else O(null),G(e,t).then(t=>{t&&N(`${ds(e)} downloaded, but switching to it failed: ${t}`)})},[m,D,A,G]);let ce=m?.flatMap(({provider:e,models:t})=>[...e.remote&&!e.models_discovered?[`key:${e.id}`]:[],...t.filter(e=>S===null&&!Ts(e)).map(e=>e.id)])??[],le=r??t?.model,ue=z&&ce.includes(z)?z:le&&ce.includes(le)?le:ce[0],de=e=>({role:`option`,tabIndex:e===ue?0:-1,"data-row":e,onFocus:()=>B(e),onBlur:()=>ne(null)}),pe=s?.remote?Ir:s?Wr:Ar,me=c?ds(c):`Model`,he=`${me}${s?` · ${s.label}`:``}`,ge=Object.fromEntries((m??[]).map(e=>[e.provider.id,ys(e.models)])),_e=t?.downloaded===!1&&c===t.model,ve=M||a||(r?`${ds(r)} is used from your next message.`:t?.config_error?t.config_error:_e?`${me} isn't downloaded yet. Open the list to download it.`:s?s.description?.replace(/`/g,``)??(s.remote?`Runs on ${s.label} — chat history leaves this PC`:`Runs on this PC`):ms);return V(`div`,{className:`composer-chip-wrap`,children:[V(`button`,{ref:d,type:`button`,className:`composer-chip${_e||a||M?` is-warning`:``}`,onClick:()=>p(e=>!e),"aria-haspopup":`dialog`,"aria-expanded":f,title:ve,children:[P(pe,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:he}),r&&V(`span`,{className:`composer-chip-next`,children:[`→ `,ds(r),` next`]}),_e&&P(Jr,{size:12,"aria-label":`Not downloaded`}),M&&P(wr,{size:12,"aria-label":`Model switch failed`}),P(gr,{size:12,"aria-hidden":`true`})]}),V(Ro,{open:f,onClose:ie,anchor:d,label:`Choose a model`,align:`end`,children:[l&&V(`div`,{className:`popover-message`,role:`status`,children:[`This reply keeps `,c?ds(c):`its model`,`. A model you pick here is used from your next message.`]}),M&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:M}),a&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:a}),v&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:v}),!m&&!v&&V(`div`,{className:`popover-message`,children:[P(q,{size:13,className:`spin`}),` Loading models…`]}),m&&P(`div`,{ref:ee,role:`listbox`,"aria-label":`Models`,onKeyDown:H,children:m.map(({provider:e,models:n,error:i})=>V(`div`,{role:`group`,"aria-labelledby":`${L}-${e.id}`,children:[P(`div`,{className:`popover-heading`,id:`${L}-${e.id}`,children:e.name}),i&&P(`div`,{className:`popover-message is-error`,children:i}),e.key_state===tE?V(`div`,{className:`popover-message`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,e.key_message]}):e.remote&&!e.models_discovered&&V(`button`,{type:`button`,className:`popover-item`,...de(`key:${e.id}`),"aria-selected":!1,onClick:()=>{p(!1),u(`model`,e.id)},children:[P(`span`,{className:`popover-item-check`,children:P(Wi,{size:13,"aria-hidden":`true`})}),V(`span`,{className:`popover-item-body`,children:[P(`span`,{className:`popover-item-title`,children:`Add your key`}),V(`span`,{className:`popover-item-note`,children:[`Connect `,e.name,` in Settings`]})]})]}),!i&&n.length===0&&e.models_discovered!==!1&&P(`div`,{className:`popover-message`,children:`No models yet.`}),n.map(n=>{let i=us(r??t?.model,n.id),a=!e.remote&&ws(n)===`not_downloaded`,o=ge[e.id][n.id],s=rE(n,e.remote),c=`${L}-info-${e.id}-${n.id}`;return V(X.Fragment,{children:[V(`div`,{className:`popover-row`,children:[V(`button`,{type:`button`,className:`popover-item`,onClick:()=>{a?(F.current=0,N(null),O({model:n.id,provider:e}),W(n.id)):(O(null),G(n.id,e))},disabled:S!==null||Ts(n),...de(n.id),"aria-selected":i,"aria-describedby":te===n.id?c:void 0,children:[P(`span`,{className:`popover-item-check`,"aria-hidden":`true`,children:S===n.id?P(q,{size:13,className:`spin`}):i?P(mr,{size:13}):null}),P(`span`,{className:`popover-item-body`,children:P(`span`,{className:`popover-item-title`,children:o})})]}),V(XT,{label:`About ${o}`,warning:!!n.placement?.warning,id:c,pinned:te===n.id,onUnpin:re,tabIndex:-1,children:[P(`div`,{className:`info-bubble-title`,children:o}),s.length>0&&P(`ul`,{className:`info-bubble-lines`,children:s.map(e=>P(`li`,{children:e},e))}),n.placement?.warning&&P(`ul`,{className:`info-bubble-lines`,children:P(`li`,{className:`is-warning`,children:n.placement.warning})}),P(`div`,{className:`info-bubble-id`,children:n.id})]}),P(`span`,{className:`popover-row-state`,children:!e.remote&&P(iE,{m:n,busy:w!==null,onDownload:()=>void W(n.id)})})]}),b?.model===n.id&&b.provider.id===e.id&&V(`div`,{ref:R,className:`popover-message`,role:`alert`,children:[b.provider.privacy_notice,` `,V(`button`,{type:`button`,className:`link-btn`,onClick:()=>G(b.model,b.provider),children:[`Use `,ds(b.model)]})]})]},n.id)})]},e.id))}),g>0&&V(`button`,{type:`button`,className:`popover-item`,onClick:()=>{p(!1),u(`model`)},children:[P(`span`,{className:`popover-item-check`}),P(`span`,{className:`popover-item-body`,children:V(`span`,{className:`popover-item-note`,children:[g,` `,g===1?`model isn’t`:`models aren’t`,` available on this PC — see why in Settings`]})})]}),P(`div`,{className:`popover-divider`}),V(`button`,{type:`button`,className:`popover-item`,onClick:()=>{p(!1),u(`model`)},children:[P(`span`,{className:`popover-item-check`,children:P(Qi,{size:13,"aria-hidden":`true`})}),V(`span`,{className:`popover-item-body`,children:[P(`span`,{className:`popover-item-title`,children:`Add a model from a link…`}),P(`span`,{className:`popover-item-note`,children:`Any GGUF chat model on Hugging Face`})]})]}),V(`button`,{type:`button`,className:`popover-item`,onClick:()=>{p(!1),u(`model`)},children:[P(`span`,{className:`popover-item-check`}),P(`span`,{className:`popover-item-body`,children:P(`span`,{className:`popover-item-title`,children:`Providers and keys…`})})]})]})]})}function oE(e,t,n){if(e==null||!t(e))throw Error(`the server sent no ${n}`);return e}var sE=e=>e.startsWith(`.`);function cE({onPick:e,onClose:t}){let n=T(),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1);Io(!0,t);let p=(0,X.useRef)(null);sS(p,!0);let m=(0,X.useCallback)(e=>{u(!0),c(null),Promise.resolve().then(()=>Ot(e)).then(e=>{let t=oE(e,e=>Array.isArray(e.entries),`folder listing`);i(t),o(t.current_path)}).catch(e=>c(e instanceof yn?e.detail||e.message:String(e))).finally(()=>u(!1))},[]);(0,X.useEffect)(()=>m(),[m]);let h=r?.entries.filter(e=>e.type===`folder`)??[],g=d?h:h.filter(e=>!sE(e.name));return P(`div`,{className:`modal-overlay`,onClick:t,children:V(`div`,{ref:p,className:`modal-panel sp-picker`,role:`dialog`,"aria-modal":`true`,"aria-label":n(`pick.label`),onClick:e=>e.stopPropagation(),children:[V(`div`,{className:`modal-header`,children:[P(`h3`,{children:n(`pick.title`)}),P(`button`,{type:`button`,className:`btn-icon`,onClick:t,"aria-label":n(`sp.closeShort`),children:P(Y,{size:18})})]}),V(`div`,{className:`modal-body sp-picker-body`,children:[P(`p`,{className:`sp-meta`,children:n(`pick.note`)}),V(`form`,{className:`sp-picker-path`,onSubmit:e=>{e.preventDefault(),a.trim()&&m(a.trim())},children:[P(`input`,{value:a,onChange:e=>o(e.target.value),"aria-label":n(`pick.path`),spellCheck:!1,dir:`ltr`}),P(`button`,{type:`submit`,className:`sp-action`,children:n(`pick.go`)})]}),r&&V(`div`,{className:`sp-picker-quick`,children:[r.quick_links.map(e=>P(`button`,{type:`button`,className:`sp-action`,onClick:()=>m(e.path),children:e.name},e.path)),V(`label`,{className:`sp-picker-hidden`,children:[P(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),n(`pick.showHidden`)]})]}),V(`ul`,{className:`sp-picker-list`,"aria-busy":l,children:[r?.parent_path&&P(`li`,{children:V(`button`,{type:`button`,onClick:()=>m(r.parent_path??void 0),children:[P(Xn,{size:13,"aria-hidden":`true`}),` `,n(`pick.up`)]})}),g.map(e=>P(`li`,{children:V(`button`,{type:`button`,onClick:()=>m(e.path),children:[P(Ei,{size:13,"aria-hidden":`true`}),` `,e.name]})},e.path)),r&&g.length===0&&P(`li`,{className:`sp-meta`,children:n(h.length>0?`pick.onlyHidden`:`pick.none`)}),l&&V(`li`,{className:`sp-meta`,children:[P(q,{size:12,className:`spin`,"aria-hidden":`true`}),` `,n(`pick.loading`)]})]}),s&&P(`p`,{className:`sp-error`,role:`alert`,children:s})]}),V(`div`,{className:`sp-picker-actions`,children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:t,children:n(`sp.cancel`)}),P(`button`,{type:`button`,className:`btn-primary`,disabled:!r,onClick:()=>r&&e(r.current_path),children:n(`pick.use`)})]})]})})}function lE(e){let[t,n]=(0,X.useState)(!1),[r,i]=(0,X.useState)(null);return{open:t=>{i(null);let r=window.gaiaAPI?.dialog;r?r.pickFolder(t).then(t=>{t&&e(t)}).catch(e=>i(`Couldn't open the folder picker: ${e instanceof Error?e.message:String(e)}`)):n(!0)},picker:t?P(cE,{onPick:t=>{n(!1),e(t)},onClose:()=>n(!1)}):null,error:r}}var uE=new Map;function dE(e){let t=uE.get(e);return t||(t={env:null,error:null,inFlight:null,version:0,listeners:new Set},uE.set(e,t)),t}function fE(e,t,n){let r=dE(e);r.env=t??r.env,r.error=n,r.listeners.forEach(e=>e())}function pE(e){let t=dE(e);if(t.inFlight)return t.inFlight;let n=t.version;return t.inFlight=Promise.resolve().then(()=>Ne(e)).then(r=>{let i=oE(r,e=>Array.isArray(e.folders),`chat's environment`);t.version===n&&fE(e,i,null)}).catch(t=>fE(e,null,t instanceof Error?t.message:String(t))).finally(()=>{t.inFlight=null}),t.inFlight}function mE(e){let[,t]=(0,X.useState)(0);(0,X.useEffect)(()=>{let n=dE(e),r=()=>t(e=>e+1);return n.listeners.add(r),!n.env&&!n.inFlight&&pE(e),()=>{n.listeners.delete(r)}},[e]);let n=(0,X.useCallback)(()=>pE(e),[e]),r=(0,X.useCallback)(async t=>{let n=await t();return dE(e).version+=1,fE(e,n,null),n},[e]),i=dE(e);return{env:i.env,error:i.error,refresh:n,change:r}}var hE=e=>e.split(/[\\/]/).filter(Boolean).pop()??e;function gE({folder:e,disabled:t}){let n=k(e=>e.draftFolder),r=k(e=>e.setDraftFolder),{open:i,picker:a,error:o}=lE(r),s=e.gaia_folder?`GAIA works in its own folder, ${e.path}.`:`GAIA works in ${e.path}.`;return e.choosable?V(D.Fragment,{children:[V(`button`,{type:`button`,className:`new-chat-folder is-button${n?` is-on`:``}`,onClick:()=>i(e.path),disabled:t,"aria-haspopup":`dialog`,"aria-label":n?`Folder for this chat: ${e.name}, plus ${hE(n)}`:`Folder for this chat: ${e.name}`,title:n?`This chat can read and write ${n}. Click to pick another folder.`:`${s} Click to give this chat another folder.`,children:[P(Ei,{size:13,"aria-hidden":`true`}),P(`span`,{className:`new-chat-folder-name`,dir:`auto`,children:n?`${e.name} + ${hE(n)}`:e.name}),P(gr,{size:12,"aria-hidden":`true`})]}),n&&P(`button`,{type:`button`,className:`btn-icon-sm new-chat-folder-clear`,onClick:()=>r(null),disabled:t,"aria-label":`Don't give this chat ${hE(n)}`,title:`Don't add this folder`,children:P(Y,{size:12})}),o&&P(`span`,{className:`new-chat-folder-error`,role:`alert`,children:o}),a]}):V(`span`,{className:`new-chat-folder`,title:e.gaia_folder?`${s} Attach a file or start GAIA from a project folder to work there.`:s,children:[P(Ei,{size:13,"aria-hidden":`true`}),P(`span`,{className:`new-chat-folder-name`,dir:`auto`,children:e.name})]})}function _E({sessionId:e,onOpen:t}){let{env:n}=mE(e),r=n?.folders.find(e=>e.source===`working_folder`);if(!r)return null;let i=hE(r.path);return V(`button`,{type:`button`,className:`composer-chip folder-chip`,title:`GAIA works in ${r.path}`,"aria-label":`Working folder ${i}, show the chat's folders`,onClick:t,children:[P(Ei,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:i})]})}var vE=`gaia:permission-mode`;function yE(e,t){window.dispatchEvent(new CustomEvent(vE,{detail:{sessionId:e,mode:t}}))}function bE(e,t){let n=(0,X.useRef)(t);n.current=t,(0,X.useEffect)(()=>{if(!e)return;let t=t=>{let r=t.detail;r?.sessionId===e&&n.current(r.mode)};return window.addEventListener(vE,t),()=>window.removeEventListener(vE,t)},[e])}var xE=[{mode:`ask`,label:`perm.ask`,note:`perm.askNote`},{mode:`full_access`,label:`perm.full`,note:`perm.fullNote`}];function SE({sessionId:e,disabled:t}){let n=T(),r=k(e=>e.draftPermissionMode),i=k(e=>e.setDraftPermissionMode),[a,o]=(0,X.useState)(e?`ask`:r),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null),p=(0,X.useRef)(null);(0,X.useEffect)(()=>{if(!e){o(r);return}let t=!1;return St(e).then(e=>{t||o(e.mode)}).catch(e=>{t||f(Ix(e))}),()=>{t=!0}},[e,r]),bE(e,o);let m=(0,X.useCallback)(async t=>{if(t===`full_access`&&!l)u(!0);else{f(null);try{if(e){let n=(await Pt(e,t)).mode;o(n),yE(e,n)}else i(t),o(t);c(!1)}catch(t){f(Ix(t)),e&&St(e).then(e=>o(e.mode)).catch(e=>f(t=>`${t??``} Couldn't re-read the saved mode: ${Ix(e)}`.trim()))}finally{u(!1)}}},[l,e,i]),h=a===`full_access`,_=h?Ga:qa;return V(`div`,{className:`composer-chip-wrap`,children:[V(`button`,{ref:p,type:`button`,className:`composer-chip${h?` is-warning`:``}`,onClick:()=>{u(!1),c(e=>!e)},disabled:t,"aria-haspopup":`dialog`,"aria-expanded":s,"aria-label":n(`perm.chipAria`,{mode:g(h?`perm.fullLower`:`perm.askLower`)}),children:[P(_,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:n(h?`perm.full`:`env.ask`)}),P(gr,{size:12,"aria-hidden":`true`})]}),V(Ro,{open:s,onClose:()=>c(!1),anchor:p,label:n(`env.permission`),children:[xE.map(e=>V(`button`,{type:`button`,className:`popover-item`,onClick:()=>m(e.mode),"aria-pressed":a===e.mode,children:[P(`span`,{className:`popover-item-check`,"aria-hidden":`true`,children:a===e.mode&&P(mr,{size:13})}),V(`span`,{className:`popover-item-body`,children:[P(`span`,{className:`popover-item-title`,children:n(e.label)}),P(`span`,{className:`popover-item-note`,children:n(e.note)})]})]},e.mode)),l&&V(`div`,{className:`popover-message`,role:`alert`,children:[n(`env.fullAccessWarn`),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:()=>m(`full_access`),children:n(`env.turnOn`)})]}),d&&P(`div`,{className:`popover-message is-error`,role:`alert`,children:d})]})]})}var CE={sending:`Adding to the running reply…`,delivered:`Added to the running reply. GAIA reads it at its next step.`,queued:`Queued. Sends when this reply ends.`};function wE(e,t){return e?CE.queued:t?`GAIA is still busy in this chat. Trying again in a few seconds.`:`Sending next.`}function TE({items:e,onRemove:t,onSteer:n,onRetry:r,replying:i=!0,busyRetry:a=!1}){let o=e.filter(e=>e.state!==`starting`);return o.length===0?null:P(`ul`,{className:`queued-messages`,"aria-label":`Messages waiting to send`,"aria-live":`polite`,children:o.map(e=>V(`li`,{className:`queued-message is-${e.state}`,children:[e.state===`failed`?P(wr,{size:12,"aria-hidden":`true`}):e.state===`queued`?P(Pr,{size:12,"aria-hidden":`true`}):P(Hr,{size:12,"aria-hidden":`true`}),P(`span`,{className:`queued-message-text`,title:e.text,children:e.text}),P(`span`,{className:`queued-message-state`,title:e.error,children:e.state===`failed`?`Not sent. ${e.error??``}`.trim():e.state===`queued`?i&&e.note||wE(i,a):CE[e.state]}),e.state===`failed`&&V(`button`,{type:`button`,className:`queued-message-steer`,onClick:()=>r(e.id),"aria-label":`Send again: ${e.text}`,children:[P(za,{size:11,"aria-hidden":`true`}),` Send again`]}),e.state===`queued`&&n&&P(`button`,{type:`button`,className:`queued-message-steer`,onClick:()=>n(e.id),title:`GAIA reads it at its next step, without starting over. It may not answer it separately.`,children:`Add to this reply`}),(e.state===`queued`||e.state===`failed`)&&P(`button`,{type:`button`,className:`queued-message-remove`,onClick:()=>t(e.id),"aria-label":`Remove queued message: ${e.text}`,title:`Remove`,children:P(Y,{size:12})})]},e.id))})}var EE=e=>e.toLocaleString(`en-US`);function DE({n:e}){let t=T();if(e==null)return P(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)});let n=e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(+(e<1e4))}K`:`${(e/1e6).toFixed(1).replace(/\.0$/,``)}M`;return P(`span`,{title:t(`ctx.tokens`,{n:EE(e)}),dir:`ltr`,children:n})}function OE({s:e}){let t=T();if(e==null)return P(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)});let n=e<.1?e===0?`0 s`:`<0.1 s`:e<10?`${e.toFixed(1)} s`:`${Math.round(e)} s`;return P(`span`,{title:`${(e*1e3).toFixed(0)} ms`,dir:`ltr`,children:n})}function kE({r:e}){let t=T();return e==null?P(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)}):P(`span`,{title:t(`ctx.rateTitle`,{n:e}),children:t(`ctx.rate`,{n:Math.round(e).toLocaleString(`en-US`)})})}var AE=(e,t)=>t>0?Math.round(e/t*100):0,jE=(e,t)=>{let n=AE(e,t);return n===0&&e>0?`<1`:String(n)},ME=(e,t)=>t&&e!=null?Math.floor(e/t*100):null,NE=256;function PE(e,t=z){if(e.provider===`unknown`)return t(`ctx.unknown`);if(e.provider===`cloud`)return t(`ctx.cloud`);if(e.provider!==`local`)return t(`ctx.cloudVia`,{provider:bs(e.provider)});if(!e.device)return e.loaded===!1?t(`ctx.notLoadedNow`):t(`ctx.unknown`);let n=e.device.toUpperCase(),r=e.backend===`npu`?`FLM`:e.backend;return r&&r!==e.device?`${n} · ${r.charAt(0).toUpperCase()}${r.slice(1)}`:n}function FE({label:e,children:t,hint:n}){return V(`div`,{className:`cp-row`,title:n,children:[P(`dt`,{children:e}),P(`dd`,{children:t})]})}function IE({t:e}){let t=T();if(e.model_seconds==null||e.gaia_seconds==null)return V(FE,{label:t(`ctx.took`),children:[P(OE,{s:e.wall_seconds}),` · `,t.bare(`ctx.split`),` `,P(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)})]});let n=[{key:`model`,label:t(`ctx.inModel`),s:e.model_seconds},{key:`tools`,label:t(`ctx.runningTools`),s:e.tool_seconds},{key:`waiting`,label:t(`ctx.waitingOnYou`),s:e.waiting_seconds},{key:`gaia`,label:t(`ctx.gaiaItself`),s:e.own_seconds??0}];return V(D.Fragment,{children:[P(FE,{label:t(`ctx.took`),hint:t(`ctx.tookHint`),children:P(OE,{s:e.wall_seconds})}),P(`div`,{className:`cp-stack`,"aria-hidden":`true`,children:n.map(t=>P(`span`,{className:`cp-time-${t.key}`,style:{width:`${AE(t.s,e.wall_seconds)}%`}},t.key))}),V(`dl`,{className:`cp-rows cp-indent`,children:[P(FE,{label:t(`ctx.inModel`),children:P(OE,{s:e.model_seconds})}),P(FE,{label:t(`ctx.inGaia`),hint:t(`ctx.inGaiaHint`),children:P(OE,{s:e.gaia_seconds})}),n.slice(1).filter(e=>e.s>0).map(e=>V(FE,{label:`· ${e.label}`,children:[P(`span`,{className:`swatch cp-time-${e.key}`,"aria-hidden":`true`}),` `,P(OE,{s:e.s})]},e.key))]})]})}function LE({why:e}){let t=T();return P(`span`,{className:`cp-unknown`,title:e,children:t(`ctx.unknown`)})}var RE={server:`ctx.src.server`,client:`ctx.src.client`};function zE(e,t){return e?t(RE[e]):void 0}function BE({turn:e}){let t=T(),n=ME(e.tokens_cached,e.tokens_in),r=e.unknown??{},i=e.tools.map(e=>`${e.name??t(`ctx.toolOutside`)}: ${e.seconds??`?`} s`).join(`
|
|
63
63
|
`);return V(D.Fragment,{children:[P(IE,{t:e.time}),V(`dl`,{className:`cp-rows`,children:[P(FE,{label:t(`ctx.firstWord`),hint:zE(e.first_token_source,t),children:e.first_token_seconds==null?P(LE,{why:r.first_token_seconds}):V(D.Fragment,{children:[t.bare(`ctx.in`),` `,P(OE,{s:e.first_token_seconds})]})}),P(FE,{label:t(`ctx.readingPrompt`),hint:t(`ctx.readingHint`),children:e.tokens_new!=null&&e.tokens_new<NE?P(`span`,{title:t(`ctx.tooFewTitle`),children:t(`ctx.onlyNew`,{n:e.tokens_new})}):e.prefill_tokens_per_second==null?P(LE,{why:r.prefill_tokens_per_second}):V(D.Fragment,{children:[P(kE,{r:e.prefill_tokens_per_second}),e.prefill_source===`client`&&P(`span`,{className:`cp-chip`,title:t(`ctx.approxTitle`),children:t(`ctx.approx`)})]})}),P(FE,{label:t(`ctx.writing`),hint:zE(e.generation_source,t)??t(`ctx.writingHint`),children:e.generation_tokens_per_second==null?P(LE,{why:r.generation_tokens_per_second}):P(kE,{r:e.generation_tokens_per_second})}),P(FE,{label:t(`ctx.tokensInOut`),hint:r.tokens,children:V(`span`,{dir:`ltr`,children:[P(DE,{n:e.tokens_in}),` → `,P(DE,{n:e.tokens_out})]})}),P(FE,{label:t(`ctx.cache`),hint:t(`ctx.cacheHint`),children:e.tokens_cached==null?P(LE,{why:r.tokens_cached}):V(D.Fragment,{children:[P(DE,{n:e.tokens_cached}),n!=null&&` (${n}%)`]})}),P(FE,{label:t(`ctx.modelCalls`),children:e.model_calls}),P(FE,{label:t(`ctx.toolCalls`),hint:i||void 0,children:e.tool_calls===0&&!e.tool_seconds_total?t(`ctx.none`):V(D.Fragment,{children:[e.tool_calls,` · `,P(OE,{s:e.tool_seconds_total??0})]})}),P(FE,{label:t(`ctx.loads`),children:e.loads.length===0?t(`ctx.none`):V(`span`,{title:e.loads.map(e=>`${e.model}${e.replaced?.length?` replaced ${e.replaced.join(`, `)}`:``}: ${e.seconds} s`).join(`
|
|
@@ -65,19 +65,19 @@ Error generating stack: `+e.message+`
|
|
|
65
65
|
`),[n,r]=(0,X.useState)(()=>new Map),[i,a]=(0,X.useState)(null);return(0,X.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(vD(e)))})};i();let o=window.setInterval(i,SD);return window.addEventListener(`focus`,i),()=>{n=!0,window.clearInterval(o),window.removeEventListener(`focus`,i)}},[t]),{status:n,error:i}}function wD({summary:e}){let t=T(),n=e.files??[],[r,i]=(0,X.useState)(null),{status:a,error:o}=CD(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:vD(e)}))})};return V(bD,{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(gi,{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(gi,{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(bt(e.path),e.name),children:t(`sp.open`)}),V(`button`,{type:`button`,className:`side-rail-action`,onClick:()=>s(Dn(e.path,!0),e.name),children:[P(bi,{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 TD({summary:e,stopped:t}){let n=T();ls();let{model:r}=e,i=e.sites??[],a=(e.documents??[]).length>0;return P(bD,{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(Ir,{size:12,"aria-hidden":`true`}):P(pa,{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:ds(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:_D(e,n,t)})]})})}function ED({id:e,title:t,summary:n,children:r}){let i=fD(t=>t.sections[e]),a=fD(e=>e.setSection),o=fD(e=>e.focus),s=(0,X.useRef)(null),c=`sp-section-${e}`;return(0,X.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(br,{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 DD(e,t){let n=(0,X.useRef)(e),r=(0,X.useRef)(t);r.current=t,(0,X.useEffect)(()=>{let t=n.current&&!e;n.current=e,t&&r.current()},[e])}var OD=`gaia:mobile-access-request`,kD=`gaia:mobile-access-state`;function AD(e){window.dispatchEvent(new CustomEvent(OD,{detail:e}))}function jD(e){window.dispatchEvent(new CustomEvent(kD,{detail:e}))}function MD(e,t){let n=(0,X.useRef)(t);n.current=t,(0,X.useEffect)(()=>{let t=e=>n.current(!!e.detail);return window.addEventListener(e,t),()=>window.removeEventListener(e,t)},[e])}var ND=e=>MD(OD,e),PD=e=>MD(kD,e);function FD({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 ID={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`},LD=3;function RD(e){let t=e.split(/[\\/]/).filter(Boolean);return t[t.length-1]??e}function zD({sessionId:e,busy:t}){let n=T(),{env:r}=mE(e),i=r&&!r.internet?n(`env.offline`):null;return V(ED,{id:`environment`,title:n(`env.title`),summary:i,children:[P(HD,{sessionId:e,busy:t}),P(UD,{sessionId:e}),P(WD,{sessionId:e}),P(GD,{}),P(KD,{sessionId:e})]})}function BD({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 VD(e,t){let n=e=>e.toLowerCase().replace(/^user\./,``);return n(e)===n(t)}function HD({sessionId:e,busy:t}){let n=T(),r=hs(),i=cs(e=>e.active),a=k(t=>gs(i,t.sessions,e)),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),u=r?.remote===!0,f=(0,X.useCallback)(()=>{u||Promise.resolve().then(()=>K()).then(e=>{s(oE(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,X.useEffect)(f,[f]),DD(t,f),u)return V(BD,{label:n(`env.runsOn`),children:[V(`span`,{className:`sp-place is-remote`,children:[P(Ir,{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(BD,{label:n(`env.runsOn`),children:P(`span`,{className:`sp-meta`,title:ms,children:n(`env.notKnownYet`)})});let p=!!(o?.model&&a&&!VD(o.model,a)),m=p?null:o?.memory;return V(BD,{label:n(`env.runsOn`),children:[V(`span`,{className:`sp-place`,children:[P(pa,{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:ds(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 UD({sessionId:e}){let t=T(),{env:n,error:r,change:i}=mE(e),a=k(t=>t.sessions.find(t=>t.id===e)?.agent_type===`gaia`),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.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}=lE(t=>{f(t,()=>i(()=>an(e,t)))}),_=n?.folders.filter(e=>e.kind===`folder`)??[],v=n?.folders.filter(e=>e.kind===`file`)??[],y=u?v:v.slice(0,LD),b=!n||!n.enforced,x=e=>V(`li`,{className:`sp-scope-item`,children:[e.kind===`folder`?P(Ei,{size:13,className:`sp-item-icon`,"aria-hidden":`true`}):P(vi,{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:RD(e.path)}),V(`span`,{className:`sp-meta`,title:e.path,children:[t(ID[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(Y,{size:12})})]},e.path);return V(BD,{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>LD&&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(RD).join(`, `)})}),!b&&V(`button`,{type:`button`,className:`sp-action`,onClick:()=>m(),disabled:c!==null,children:[P(Si,{size:12,"aria-hidden":`true`}),` `,t(`env.addFolder`)]})]}),(o??g)&&P(`span`,{className:`sp-error`,role:`alert`,children:o??g}),h]})}function WD({sessionId:e}){let t=T(),{env:n,change:r,refresh:i}=mE(e),[a,o]=(0,X.useState)(null),[s,c]=(0,X.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(BD,{label:t(`env.internet`),children:[P(FD,{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(BD,{label:t(`env.internet`),children:P(`span`,{className:`sp-state-text`,children:n.internet?t(`env.on`):t(`env.off`)})})}function GD(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(null),s=(0,X.useCallback)(()=>{Promise.resolve().then(()=>Sn()).then(e=>{n(oE(e,e=>typeof e.active==`boolean`,`phone access status`)),o(null)}).catch(e=>o(Ix(e)))},[]);(0,X.useEffect)(s,[s]),PD(()=>{i(!1),s()});let c=t?.active===!0;return V(BD,{label:e(`env.phone`),children:[P(FD,{checked:c,onChange:e=>{i(!0),AD(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($a,{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:()=>AD(!0),children:e(`env.qr`)}),(a||t?.error)&&P(`span`,{className:`sp-error`,children:a??t?.error})]})}function KD({sessionId:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(null);(0,X.useEffect)(()=>{let t=!0;return Promise.resolve().then(()=>St(e)).then(e=>{t&&r(oE(e,e=>typeof e.mode==`string`,`permission mode`).mode)}).catch(e=>{t&&s(Ix(e))}),()=>{t=!1}},[e]),bE(e,r);let c=async t=>{a(!1),s(null);try{let n=(await Pt(e,t)).mode;r(n),yE(e,n)}catch(e){s(Ix(e))}},l=xE.find(e=>e.mode===n)?.note;return V(BD,{label:t(`env.permission`),children:[P(`div`,{className:`sp-segmented`,role:`radiogroup`,"aria-label":t(`env.permission`),children:xE.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(Ga,{size:12,"aria-hidden":`true`}):P(qa,{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 qD={file:{label:`out.kind.file`,Icon:gi},export:{label:`out.kind.export`,Icon:ui},image:{label:`out.kind.image`,Icon:Ri},document:{label:`out.kind.document`,Icon:Xi},memory:{label:`out.kind.memory`,Icon:ir},schedule:{label:`out.kind.schedule`,Icon:cr}},JD={created:`out.change.created`,edited:`out.change.edited`,deleted:`out.change.deleted`};function YD(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 XD(e){return e.state===`undone`?`out.undone`:e.state===`gone`?`sp.gone`:null}function ZD({sessionId:e,busy:t,onJumpToMessage:n}){let r=T();return P(ED,{id:`outputs`,title:r(`out.title`),children:P(QD,{sessionId:e,busy:t,onJumpToMessage:n})})}function QD({sessionId:e,busy:t,onJumpToMessage:n}){let r=T(),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(!1),p=(0,X.useCallback)(()=>{let t=!0;return Promise.resolve().then(()=>Ae(e)).then(e=>{t&&(a(oE(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,X.useEffect)(p,[p]),DD(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}=qD[e.kind],a=XD(e),o=e.change&&e.kind!==`document`?JD[e.change]:void 0,s=YD(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(Hr,{size:11,"aria-hidden":`true`}),` `,r(`sp.goToTurn`)]}),e.openable&&e.path&&P(`button`,{type:`button`,className:`sp-action`,onClick:()=>m(bt(e.path),e.name),children:r(`sp.open`)}),e.revealable&&e.path&&V(`button`,{type:`button`,className:`sp-action`,onClick:()=>m(Dn(e.path,!0),e.name),children:[P(bi,{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 $D(e,t,n=`${t}s`){return`${e} ${e===1?t:n}`}function eO(e){let t=e.split(/[\\/]/).filter(Boolean);return t[t.length-1]??e}var tO=e=>g(e===1?`chg.files.one`:`chg.files.other`,{n:e});function nO(e,t=z){let{files:n,additions:r,deletions:i}=e.totals;return t(`chg.total`,{files:tO(n),add:r,del:i})}var rO={edited:`Edited`,created:`Created`,deleted:`Deleted`},iO={edited:`chg.edited`,created:`chg.created`,deleted:`chg.deleted`};function aO({sessionId:e,busy:t,onJumpToMessage:n}){let r=T(),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),u=(0,X.useCallback)(()=>{Promise.resolve().then(()=>dt(e)).then(e=>{a(oE(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,X.useEffect)(u,[u]),DD(t,()=>{l(null),u()}),Wx(e,u);let f=!i||i.files.length===0;return!o&&f&&!c?null:V(ED,{id:`changes`,title:r(`chg.title`),summary:i&&!f?r(`chg.summary`,{files:tO(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(oO,{sessionId:e,busy:t,changes:i,onChanged:u,onUndone:l,onJumpToMessage:n}),f&&c&&P(`p`,{className:`sp-ok`,role:`status`,children:c})]})}function oO({sessionId:e,busy:t,changes:n,onChanged:r,onUndone:i,onJumpToMessage:a}){let o=T(),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(`idle`),[d,f]=(0,X.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 ${$D(n.restored.length,`file`)}`),n.removed.length&&r.push(`removed ${$D(n.removed.length,`new file`)}`);let a=`Undone: ${r.join(`, `)||`no files needed changing`}.`;n.kept_folders.length&&(a+=` Kept ${$D(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:nO(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:eO(e.path)}),V(`span`,{className:`sp-meta`,children:[o(iO[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(J,{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:eO(e.path)}),title:o(`sp.goToTurn`),children:P(Hr,{size:12})})]},e.path)})}),n.incomplete&&V(`p`,{className:`sp-warn-text`,role:`note`,children:[P(J,{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(ii,{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(po,{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:tO(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(lO,{sessionId:e,busy:t,onCommitted:r}),s&&P(cO,{changes:n,onClose:()=>c(!1)})]})}function sO(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 cO({changes:e,onClose:t}){Io(!0,t);let n=(0,X.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 · `,nO(e)]}),P(`button`,{type:`button`,className:`btn-icon`,onClick:t,"aria-label":`Close`,children:P(Y,{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:rO[e.change],note:sO(e),unified:e.binary||e.too_large?``:e.unified}})},e.path))})]})})}function lO({sessionId:e,busy:t,onCommitted:n}){let r=T(),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),f=(0,X.useCallback)(()=>{Promise.resolve().then(()=>gt(e)).then(e=>{a(oE(e,e=>Array.isArray(e.repos),`list of git repositories`)),s(null)}).catch(e=>s(Fx(e)))},[e]);return(0,X.useEffect)(f,[f]),DD(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(Oi,{size:12,"aria-hidden":`true`}),` `,eO(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(Ai,{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(Mi,{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(uO,{sessionId:e,kind:c.kind,repo:c.repo,onClose:()=>l(null),onDone:e=>{l(null),d(e),f(),n()}})]})}function uO({sessionId:e,kind:t,repo:n,onClose:r,onDone:i}){let[a,o]=(0,X.useState)(n.draft.title),[s,c]=(0,X.useState)(n.draft.body),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(null);Io(!0,r,!l);let p=(0,X.useRef)(null);sS(p,!0);let m=async()=>{u(!0),f(null);try{if(t===`commit`){let t=await Qt(e,n.root,`${a.trim()}\n\n${s.trim()}`.trim());i(`Committed ${$D(t.files.length,`file`)} as ${t.commit}.`)}else i(`Opened ${(await It(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(Y,{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:[$D(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(q,{size:13,className:`spin`,"aria-hidden":`true`}),t===`commit`?`Commit ${$D(h.length,`file`)}`:`Push and open PR`]})]})]})})}var dO={mcp:`tools.cat.mcp`,skill:`tools.cat.skill`,agent:`tools.cat.agent`};function fO(e,t){let n=dO[e];return n?t(n):e.replace(/_/g,` `)}function pO(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 mO(e){return e.split(`
|
|
67
67
|
`,1)[0].trim()}function hO({sessionId:e,busy:t}){let n=T();return P(ED,{id:`tools`,title:n(`tools.title`),children:P(gO,{sessionId:e,busy:t})})}function gO({sessionId:e,busy:t}){let n=T(),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(null),s=(0,X.useCallback)(()=>{let t=!0;return Promise.resolve().then(()=>Ie(e)).then(e=>{t&&(i(oE(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,X.useEffect)(s,[s]),DD(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:pO(r).map(([e,t])=>{let r=fO(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:mO(e.description)})]},e.name))})]},e)})}):P(`p`,{className:`sp-meta`,children:n(`sp.checking`)})}var _O={model:`skills.how.model`,auto:`skills.how.auto`,always:`skills.how.always`};function vO({sessionId:e,busy:t}){let n=T();return P(ED,{id:`skills`,title:n(`skills.title`),children:P(yO,{sessionId:e,busy:t})})}function yO({sessionId:e,busy:t}){let n=T(),r=k(e=>e.skillUses),[i,a]=(0,X.useState)(void 0),[o,s]=(0,X.useState)(null),c=(0,X.useCallback)(()=>{let t=!0;return Promise.resolve().then(()=>Ie(e)).then(e=>{if(!t)return;let n=oE(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,X.useEffect)(c,[c,r]),DD(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(to,{size:12,"aria-hidden":`true`}),P(`code`,{className:`sp-item-name`,dir:`ltr`,children:e.name})]}),P(`span`,{className:`sp-meta`,children:n(_O[e.how]??`skills.how.always`)})]},e.name))})}var bO=`(max-width: 1099px)`,xO=16;function SO({sessionId:e,messages:t,busy:n,onUsage:r,onJumpToMessage:i}){let a=T(),o=zc(bO),s=fD(e=>o?e.overlayOpen:e.open),c=fD(e=>e.width),l=fD(e=>e.setWidth),u=fD(e=>e.setOpen),d=fD(e=>e.setOverlayOpen),f=fD(e=>e.focus),p=(0,X.useRef)(null),[m,h]=(0,X.useState)(null),g=(0,X.useCallback)(()=>{o?d(!1):u(!1)},[o,u,d]);Io(s&&o,g);let _=(0,X.useRef)(null);sS(_,s&&o),(0,X.useEffect)(()=>{s&&o&&p.current?.focus()},[s,o]),(0,X.useEffect)(()=>{f&&o&&d(!0)},[f,o,d]);let v=(0,X.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=uD(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,X.useCallback)(e=>{let t=getComputedStyle(e.currentTarget).direction===`rtl`?-16:xO,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=pD(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?Y:ya,{size:14})})]}),V(`div`,{className:`sp-body`,children:[x&&P(ED,{id:`answer`,title:a(`sp.section.answer`),children:P(yD,{messages:t,busy:n})}),P(zD,{sessionId:e,busy:n}),P(ED,{id:`context`,title:a(`sp.section.context`),children:P(`div`,{className:`sp-context`,children:P(WE,{sessionId:e,busy:n,onUsage:r})})}),P(ZD,{sessionId:e,busy:n,onJumpToMessage:i}),P(aO,{sessionId:e,busy:n,onJumpToMessage:i}),P(vO,{sessionId:e,busy:n}),P(hO,{sessionId:e,busy:n})]})]})]})}function CO({messages:e,busy:t}){let n=T(),r=zc(bO),i=fD(e=>r?e.overlayOpen:e.open),a=fD(e=>e.setOpen),o=fD(e=>e.setOverlayOpen),s=pD(e,t),c=!i&&s?.kind===`turn`&&s.turn.turnSummary?mD(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?J:i?ya:xa,{size:15})})}function wO({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?ei:ni,{size:15})})}var TO=5e3;function EO(e){let[t,n]=(0,X.useState)({usage:null,error:null});return(0,X.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 un(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(TO)}}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 DO=1024**3;function OO(e){return(e/DO).toFixed(1)}function kO(e){return`${Math.round(e)}%`}var AO=[[1e9,`Gbps`],[1e6,`Mbps`],[1e3,`Kbps`]];function jO(e){return AO.find(([t])=>e>=t)??AO[AO.length-1]}function MO(e,[t]){let n=e/t;return n<.05?`0`:n>=100?n.toFixed(0):n.toFixed(1)}function NO(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 PO(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 FO(e){return e.map(([e,t],n)=>`${n?`L`:`M`}${e.toFixed(2)} ${t.toFixed(2)}`).join(` `)}function IO({values:e,max:t=100,dashed:n}){let r=PO(e,t),i=FO(r),a=r.length>1?`${i} L100 100 L${r[0][0].toFixed(2)} 100 Z`:``,o=n?PO(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:FO(o),vectorEffect:`non-scaling-stroke`})]})}var LO={gpu:`resources.gpu`,npu:`resources.npu`,ethernet:`resources.ethernet`,wifi:`resources.wifi`,network:`resources.network`};function RO(e,t,n){let r=e(LO[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 zO(e){let t=jO(e);return`${MO(e,t)} ${t[1]}`}function BO(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 VO(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:kO(t.cpu.percent),detail:r,title:[e(`resources.cpu`),kO(t.cpu.percent),r].filter(Boolean).join(` · `),history:t.cpu.history})}if(t.memory){let r=t.memory,i=`${OO(r.used_bytes)}/${OO(r.total_bytes)} GB`;n.push({key:`memory`,tone:`memory`,label:e(`resources.memory`),value:kO(r.percent),detail:i,title:`${e(`resources.memory`)} · ${i} (${kO(r.percent)})`,history:r.history})}let r=t.devices??[];for(let t of r){let i=t.memory_used_bytes==null?void 0:`${OO(t.memory_used_bytes)} GB`;n.push({key:t.id,tone:t.kind,label:RO(e,t,r),value:kO(t.percent),detail:i,name:t.name,title:[t.name,kO(t.percent),i&&e(`resources.inUse`,{size:i})].filter(Boolean).join(` · `),history:t.history})}t.devices_error&&n.push(BO(e,`gpu`,e(`resources.gpu`),t.devices_error));let i=t.networks??[];for(let t of i){let r=jO(Math.max(t.send_bps,t.recv_bps)),a=MO(t.send_bps,r),o=MO(t.recv_bps,r);n.push({key:t.id,tone:`network`,label:RO(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:zO(t.send_bps)}),e(`resources.receive`,{rate:zO(t.recv_bps)})].join(` · `),history:t.recv_history,dashed:t.send_history,max:NO([...t.recv_history,...t.send_history])})}return t.networks_error&&n.push(BO(e,`network`,e(`resources.network`),t.networks_error)),n}function HO({onClose:e}){let t=T(),{usage:n,error:r}=EO(!0),i=n?.ready?VO(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(IO,{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(Y,{size:14,"aria-hidden":`true`})})]})}function UO({sessionId:e}){let t=T(),{env:n,change:r}=mE(e),[i,a]=(0,X.useState)(null);return!n||n.internet?null:V(`div`,{className:`offline-notice`,role:`status`,children:[P(yo,{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 yn?e.detail||e.message:String(e))})},children:t(`offline.turnOn`)})]})}function WO({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(Y,{size:13})})]}):null}var GO=`gaia.resourceMonitor.visible`;function KO(){try{return window.localStorage.getItem(GO)!==`0`}catch(e){return d.ui.warn(`Resource usage setting unavailable; showing it`,e),!0}}var qO=p(e=>({visible:KO(),setVisible:t=>{try{window.localStorage.setItem(GO,t?`1`:`0`)}catch(e){d.ui.warn(`Could not remember the resource usage setting`,e)}e({visible:t})},reload:()=>e({visible:KO()})}));function JO(){return`screenshot-${new Date().toISOString().slice(0,19).replace(/[T:]/g,`-`)}.png`}function YO(){let e=T(),[t,n]=(0,X.useState)([]),r=(0,X.useRef)(!0),i=(0,X.useRef)(new Map);(0,X.useEffect)(()=>(r.current=!0,()=>{r.current=!1}),[]);let a=(0,X.useCallback)(async e=>{let t=new AbortController;i.current.set(e.id,t);try{let i=e.isMedia?await vt(e.file,t=>{r.current&&n(n=>n.map(n=>n.id===e.id?{...n,progress:t}:n))},t.signal):await pt(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,X.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?JO():`file`),url:e?URL.createObjectURL(t):``,uploading:!0,uploaded:!1,isImage:e,isMedia:OT(t.name)};n(e=>[...e,r]),a(r)}},[a]),s=(0,X.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,X.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,X.useCallback)(()=>{n(e=>(e.forEach(e=>{e.url&&URL.revokeObjectURL(e.url)}),[]))},[]),u=(0,X.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
|
-
`);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 XO({sessionId:e,isStreaming:t,isStale:n,setMessages:r,refreshContext:i}){let[a,o]=(0,X.useState)(null),s=a?.state.status===`running`,c=(0,X.useRef)(!1);c.current=s;let l=(0,X.useRef)(a);l.current=a,(0,X.useEffect)(()=>{o(null)},[e]);let u=(0,X.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}),Et(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,X.useCallback)(async t=>{if(!a)return;let{messageId:s}=a;o({...a,keeping:t});try{let a=await se(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,X.useCallback)(()=>{a?.state.status===`ready`?f(`original`):o(null)},[a,f]),closeForNewTurn:(0,X.useCallback)(()=>{let t=l.current;t&&(t.state.status===`ready`&&se(e,t.messageId,`original`).catch(e=>d.chat.error(`Could not close the answer comparison`,e)),o(null))},[e])}}function ZO(e,t){let[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null);(0,X.useEffect)(()=>{r(null),a(null)},[e]);let o=(0,X.useCallback)(()=>{mn(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,X.useEffect)(()=>{o()},[o]),{contextUsage:n,contextUnavailable:i,refreshContext:o,showContextUsage:(0,X.useCallback)(e=>{r(e),a(null)},[])}}function QO(e,t){return(0,X.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 $O=1,ek=80,tk=500,nk=new Set([`PageUp`,`ArrowUp`,`Home`]),rk=new Set([`PageDown`,`ArrowDown`,`End`]);function ik(e,t,n){let r=(0,X.useRef)(0),i=(0,X.useRef)(0),a=(0,X.useRef)(0),o=(0,X.useRef)(!1),s=(0,X.useCallback)(()=>o.current||Date.now()-a.current<tk,[]),c=(0,X.useCallback)(()=>{a.current=Date.now()},[]),l=(0,X.useCallback)(()=>{a.current=0},[]),u=(0,X.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<=$O?t.current=!0:l?t.current=!1:o<=ek&&o<c&&(t.current=!0),n(o)},[e,t,n,s]),d=(0,X.useCallback)(e=>{e.deltaY<0?c():e.deltaY>0&&l()},[c,l]),f=(0,X.useCallback)(e=>{e.target===e.currentTarget&&(o.current=!0)},[]);return(0,X.useEffect)(()=>{let e=()=>{o.current=!1},t=e=>{let t=e.target;t instanceof Element&&t.closest(`input, textarea, select, [contenteditable="true"]`)||(nk.has(e.key)||e.key===` `&&e.shiftKey?c():(rk.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 ak(e,t){let[n,r]=(0,X.useState)(null);(0,X.useEffect)(()=>{r(null)},[e]);let i=(0,X.useCallback)(()=>r(null),[]);return{exportChat:(0,X.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 yn?`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 ok=5200;function sk(e=ok){let[t,n]=(0,X.useState)(null),r=(0,X.useRef)(null),i=(0,X.useCallback)(()=>{r.current&&=(clearTimeout(r.current),null)},[]),a=(0,X.useCallback)(()=>{i(),n(null)},[i]),o=(0,X.useCallback)(t=>{i(),n(t),r.current=setTimeout(()=>{r.current=null,n(null)},e)},[i,e]);return(0,X.useEffect)(()=>i,[i]),{policyToast:t,showPolicyToast:o,dismissPolicyToast:a}}var ck=`gaia`;function lk(e){return e.some(e=>e.id===ck)}function uk(e){let t=e;return t?.httpStatus===422&&`${typeof t.detail==`string`?t.detail:``} ${typeof t.message==`string`?t.message:``}`.includes(`Unknown agent_type '${ck}'`)}var dk=new Set([``,`new chat`,`new task`,`untitled`,`untitled session`,`chat`]);function fk(e){return dk.has((e??``).trim().toLowerCase())}function pk(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 mk(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))]),pk(e,t.map(e=>e.id))}async function hk(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 Yt(e,t.id),pk(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 Dt();k.getState().setDocuments(e.documents||[])}catch(e){d.doc.error(`Could not refresh the document list after a drop`,e)}}function gk(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 _k(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 vk=2e3,yk=9e4;function bk(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(`idle`),[s,c]=(0,X.useState)(null),l=(0,X.useRef)(!0),u=(0,X.useCallback)(async()=>{try{let e=await K();return l.current&&n(e),e}catch(e){return l.current&&c(e instanceof Error?e.message:String(e)),null}},[]);(0,X.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,X.useCallback)(async()=>{c(null);let e=await u();e&&o(e.state===`stopped`?`still_down`:`back`)},[u]),f=(0,X.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()+yk;for(;l.current&&Date.now()<e;){await new Promise(e=>setTimeout(e,vk));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,X.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(J,{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(q,{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(q,{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 xk(e,t=``){let[n,r]=(0,X.useState)(()=>e&&xn(e)||t),i=(0,X.useRef)(e);return(0,X.useEffect)(()=>{i.current!==e&&(i.current=e,r(e?xn(e):``))},[e]),(0,X.useEffect)(()=>{e&&i.current===e&&nn(e,n)},[e,n]),[n,r]}function Sk(e,t){return xk(t?null:U(e))}var Ck=new Set([`tool_start`,`tool_end`,`tool_result`]),wk=`Connection lost. Reconnecting`,Tk=15e3,Ek=[],Dk=new Map;function Ok({text:e}){return P(`div`,{className:`history-notice`,role:`note`,children:e})}function kk({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,documents:O,setDocuments:A,setShowDocLibrary:j,setShowFileBrowser:M,isLoadingMessages:N,setLoadingMessages:F,systemStatus:L}=k(),R=Qs(e=>e.addNotification),z=Qs(e=>e.showPanel),B=Qs(e=>e.setShowPanel),te=Qs(e=>e.setTypeFilter),ne=k(t=>t.pendingPrompt?.sessionId===e?t.pendingPrompt:null),oe=k(e=>e.liveStatus),H=k(pw),U=k(e=>e.awaitingUser),se=k(t=>Object.values(t.liveQuestions).some(t=>t.sessionId===e)),W=Qs(t=>tc(e)(t)!==null),G=n.find(t=>t.id===e),ce=new Set(G?.document_ids??[]),le=O.filter(e=>ce.has(e.id)),[ue,de]=Sk(e,G?.private),[fe,pe]=(0,X.useState)(!1),[me,he]=(0,X.useState)(``),[ge,_e]=(0,X.useState)(!1),[ve,ye]=(0,X.useState)(!1),be=YO(),[xe,Ce]=(0,X.useState)(!1),[we,Te]=(0,X.useState)(null),{policyToast:Ee,showPolicyToast:De,dismissPolicyToast:Oe}=sk(),[ke,Ae]=(0,X.useState)(null),{exportChat:je,exportError:Me,clearExportError:Ne}=ak(e,G?.title),Pe=G?.agent_type&&G.agent_type!==`gaia`?G.agent_type:null,[Fe,Ie]=(0,X.useState)(!1),[Le,Re]=(0,X.useState)(null),ze=(0,X.useRef)(``),Be=(0,X.useRef)([]),He=(0,X.useRef)([]),Ue=(0,X.useRef)(!1);(0,X.useEffect)(()=>{f&&(ze.current=f)},[f]),(0,X.useEffect)(()=>{g.length>0&&(Be.current=g.map(e=>({...e,active:!1})))},[g]),(0,X.useEffect)(()=>{C.length>0&&(He.current=[...C])},[C]),Ew(),(0,X.useEffect)(()=>{if(!u&&Ue.current){Ie(!0);let e=setTimeout(()=>{Ie(!1),ze.current=``,Be.current=[],He.current=[]},350);return()=>clearTimeout(e)}Ue.current=u},[u]);let We=(0,X.useRef)(null),Ge=(0,X.useRef)(null),Ke=(0,X.useRef)(null),qe=(0,X.useRef)(null),Je=(0,X.useRef)(0),Xe=(0,X.useRef)(!1),Ze=(0,X.useRef)(0),Qe=(0,X.useRef)(null),[$e,et]=(0,X.useState)(!1),tt=(0,X.useRef)(!1),nt=(0,X.useRef)(null),it=(0,X.useRef)(null),at=(0,X.useRef)(0),K=(0,X.useRef)(!1),ot=(0,X.useRef)(()=>{}),lt=(0,X.useRef)(!1),ut=k(t=>t.messageQueues[e]??Ek),dt=(0,X.useCallback)(t=>k.getState().updateQueue(e,t),[e]),ft=(0,X.useRef)(!1),[pt,ht]=(0,X.useState)(!1),gt=(0,X.useRef)(!1),_t=(0,X.useRef)(!1),vt=(0,X.useRef)(u);vt.current=u;let yt=k(t=>!!t.queueHolds[e]),bt=(0,X.useRef)(``),xt=(0,X.useRef)(null),St=(0,X.useRef)(null),wt=(0,X.useRef)(0),Tt=(0,X.useRef)(!0),{userScrolling:Et,clearUserScroll:Ot,listProps:kt}=ik(Ge,Tt,e=>ye(e>200)),At=(0,X.useCallback)(()=>k.getState().currentSessionId!==e,[e]),jt=(0,X.useCallback)(()=>{xt.current=null,!At()&&bt.current&&m(bt.current)},[m,At]),Mt=(0,X.useRef)(0),Nt=(0,X.useRef)(0);(0,X.useEffect)(()=>{d.chat.info(`ChatView mounted for session=${e}, loading messages...`);let t=d.chat.time();F(!0);let n=!1,r=!1,a=async(a=!1)=>{if(n||r)return;r=!0;let o=Nt.current;try{if(!a){if(k.getState().isStreaming)return;let t=await rt(e);if(n||t===Mt.current||k.getState().isStreaming)return}let r=await ct(e);if(n)return;let s=yw(r.messages);a&&Nt.current!==o?Mt.current=s.length:a?(i(s),Mt.current=s.length,d.chat.timed(`Loaded ${s.length} message(s) for session=${e}`,t)):s.length!==Mt.current&&!k.getState().isStreaming&&(d.chat.info(`Messages changed externally: ${Mt.current} -> ${s.length}`),i(Cw(k.getState().messages,s)),Mt.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&&F(!1)}};a(!0);let o=gk(()=>a(!1),3e3);return()=>{n=!0,o()}},[e,i,F]),(0,X.useEffect)(()=>{Dt().then(e=>A(e.documents||[])).catch(e=>d.doc.error(`Could not load the document list`,e))},[A]);let Pt=(0,X.useRef)(!0),Ft=(0,X.useRef)(!1),It=Hw(L);(0,X.useEffect)(()=>(Pt.current=!0,()=>{Pt.current=!1}),[]),(0,X.useEffect)(()=>{let e=ne?.text;!e||k.getState().isLoadingMessages||It||(k.getState().setPendingPrompt(null),Ft.current=!0,setTimeout(()=>{Ft.current=!1,Pt.current&&ot.current(e,{opening:!0})},0))},[ne,N,It]),(0,X.useEffect)(()=>{if(!Tt.current)return;let e=Date.now()-wt.current,t=()=>{Tt.current&&!Et()&&(wt.current=Date.now(),We.current?.scrollIntoView({behavior:`instant`}))};e>=100&&t(),St.current&&clearTimeout(St.current),St.current=setTimeout(t,100)},[r,f,g]),(0,X.useEffect)(()=>{Ke.current?.focus()},[e]),(0,X.useEffect)(()=>{ft.current=!1},[e]);let{contextUsage:Lt,contextUnavailable:Rt,refreshContext:zt,showContextUsage:Bt}=ZO(e,At),{comparison:Vt,comparing:Ht,comparingRef:Ut,handleRetryWith:Wt,handleKeepAnswer:Gt,handleCloseComparison:Kt,closeForNewTurn:qt}=XO({sessionId:e,isStreaming:u,isStale:At,setMessages:i,refreshContext:zt});(0,X.useEffect)(()=>()=>{vt.current&&dT(e),qe.current&&!_t.current&&qe.current.abort(),qe.current&&=null,nt.current&&=(clearTimeout(nt.current),null),tt.current=!1,it.current=null,et(!1),xt.current!==null&&(cancelAnimationFrame(xt.current),xt.current=null),St.current&&=(clearTimeout(St.current),null),Qe.current&&=(clearTimeout(Qe.current),null),Oe(),bt.current=``,k.getState().resetStreaming()},[e]),(0,X.useEffect)(()=>{ke&&z&&(document.getElementById(ww(ke))?.scrollIntoView({behavior:Mx(),block:`center`}),Ae(null))},[ke,z]);let Jt=fD(e=>e.width),Yt=fD(e=>e.reveal),Xt=qO(e=>e.visible),Zt=qO(e=>e.setVisible),Qt=(0,X.useRef)(null),$t=(0,X.useCallback)(()=>{Zt(!1),Qt.current?.focus()},[Zt]),en=QO(Ge,Tt),tn=(0,X.useCallback)(()=>{Tt.current=!0,Ot(),We.current?.scrollIntoView({behavior:Mx()})},[Ot]),nn=(0,X.useCallback)(()=>{tt.current||(tt.current=!0,ft.current=!0,et(!0),Qs.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)}),Qe.current?(clearTimeout(Qe.current),Qe.current=null,it.current?.()):nt.current=setTimeout(()=>{d.stream.error(`No closing event ${Tk}ms after Stop; closing the turn locally (session=${e})`),it.current?.()},Tk))},[e]);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&u&&!Po(e)&&(e.preventDefault(),nn())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,nn]);let rn=(0,X.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?ue:t??``).trim(),C=f&&be.hasUploaded,T=f&&be.hasImage,D=()=>{if(!f)return g;let e=be.compose(g);return de(``),be.clear(),Ke.current?.focus(),e};Tt.current=!0;let O=Hw(L),A=e=>{a&&n?.onQueuedOutcome?.(e)};if(!r&&Pe){d.chat.warn(`Send blocked: chat ${e} belongs to the retired "${Pe}" agent`),A({kind:`failed`,error:`This chat's "${Pe}" agent was retired, so it cannot take new messages.`});return}let j=!n?.opening&&(k.getState().messageQueues[e]??Ek).length>0;if(r){if(u&&!c)return}else if(!a&&(g||C)&&!O&&(u||Ut.current||j)){let e=D();dt(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&&(!Ho(`chat`)||T&&!Ho(`vision`))){if(lt.current)return;lt.current=!0;try{if(!await Go(`chat`)||T&&!await Go(`vision`))return}finally{lt.current=!1}}let M=g,N=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)}),qt();let t={id:Date.now(),session_id:e,role:`user`,content:M,created_at:new Date().toISOString(),rag_sources:null};o(t),N=t,Nt.current+=1}c||(Ze.current=0),p(!0),h(),S(),E(),at.current=0,K.current=!1,c&&k.getState().setLiveStatus(`${wk} (attempt ${c} of 3)…`),d.stream.info(`Starting agent stream...`);let P=d.stream.time(),F=``,z;Re(null);let B=!1;gt.current=!1,r||ht(!1);let te=null,V=!a;_t.current=a;let ne=e=>{V||(V=!0,_t.current=!1,n?.onQueuedOutcome?.(e),e.kind===`accepted`&&At()&&te?.abort())},ie=r||!!G&&!fk(G.title),ae=()=>{ne({kind:`accepted`}),!ie&&(ie=!0,mt(e).then(t=>l(e,{title:t.title})).catch(e=>d.chat.warn(`Could not refresh the chat title`,e)))};bt.current=``,tt.current=!1,et(!1);let oe=()=>{nt.current&&=(clearTimeout(nt.current),null),tt.current=!1,it.current=null,et(!1)},H=()=>{let{agentSteps:e,cards:t}=k.getState();return{steps:e.map(e=>({...e,active:!1})),cards:[...t]}};it.current=()=>{if(B)return;B=!0,Xe.current=!0,Je.current=Date.now(),oe(),ne({kind:`failed`,error:`Stopped before GAIA confirmed it got this message.`}),qe.current?.abort(),qe.current=null,xt.current!==null&&(cancelAnimationFrame(xt.current),xt.current=null);let t=bt.current||k.getState().streamingContent;if(bt.current=``,At())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(At())return;let e=k.getState();(e.liveStatus===`Waiting for GAIA to start this answer…`||e.liveStatus?.startsWith(wk))&&e.setLiveStatus(null)},onChunk:t=>{if(ae(),At())return;k.getState().awaitingUser&&k.getState().setAwaitingUser(!1);let n=t.content||``;if(n&&Qs.getState().dismissSessionPrompts(e),n){if(t.type===`answer`)F=n;else{K.current&&=(F.length>0&&(F+=`
|
|
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 XO({sessionId:e,isStreaming:t,isStale:n,setMessages:r,refreshContext:i}){let[a,o]=(0,X.useState)(null),s=a?.state.status===`running`,c=(0,X.useRef)(!1);c.current=s;let l=(0,X.useRef)(a);l.current=a,(0,X.useEffect)(()=>{o(null)},[e]);let u=(0,X.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}),Et(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,X.useCallback)(async t=>{if(!a)return;let{messageId:s}=a;o({...a,keeping:t});try{let a=await se(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,X.useCallback)(()=>{a?.state.status===`ready`?f(`original`):o(null)},[a,f]),closeForNewTurn:(0,X.useCallback)(()=>{let t=l.current;t&&(t.state.status===`ready`&&se(e,t.messageId,`original`).catch(e=>d.chat.error(`Could not close the answer comparison`,e)),o(null))},[e])}}function ZO(e,t){let[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null);(0,X.useEffect)(()=>{r(null),a(null)},[e]);let o=(0,X.useCallback)(()=>{mn(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,X.useEffect)(()=>{o()},[o]),{contextUsage:n,contextUnavailable:i,refreshContext:o,showContextUsage:(0,X.useCallback)(e=>{r(e),a(null)},[])}}function QO(e,t){return(0,X.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 $O=1,ek=80,tk=500,nk=new Set([`PageUp`,`ArrowUp`,`Home`]),rk=new Set([`PageDown`,`ArrowDown`,`End`]);function ik(e,t,n){let r=(0,X.useRef)(0),i=(0,X.useRef)(0),a=(0,X.useRef)(0),o=(0,X.useRef)(!1),s=(0,X.useCallback)(()=>o.current||Date.now()-a.current<tk,[]),c=(0,X.useCallback)(()=>{a.current=Date.now()},[]),l=(0,X.useCallback)(()=>{a.current=0},[]),u=(0,X.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<=$O?t.current=!0:l?t.current=!1:o<=ek&&o<c&&(t.current=!0),n(o)},[e,t,n,s]),d=(0,X.useCallback)(e=>{e.deltaY<0?c():e.deltaY>0&&l()},[c,l]),f=(0,X.useCallback)(e=>{e.target===e.currentTarget&&(o.current=!0)},[]);return(0,X.useEffect)(()=>{let e=()=>{o.current=!1},t=e=>{let t=e.target;t instanceof Element&&t.closest(`input, textarea, select, [contenteditable="true"]`)||(nk.has(e.key)||e.key===` `&&e.shiftKey?c():(rk.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 ak(e,t){let[n,r]=(0,X.useState)(null);(0,X.useEffect)(()=>{r(null)},[e]);let i=(0,X.useCallback)(()=>r(null),[]);return{exportChat:(0,X.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 yn?`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 ok=5200;function sk(e=ok){let[t,n]=(0,X.useState)(null),r=(0,X.useRef)(null),i=(0,X.useCallback)(()=>{r.current&&=(clearTimeout(r.current),null)},[]),a=(0,X.useCallback)(()=>{i(),n(null)},[i]),o=(0,X.useCallback)(t=>{i(),n(t),r.current=setTimeout(()=>{r.current=null,n(null)},e)},[i,e]);return(0,X.useEffect)(()=>i,[i]),{policyToast:t,showPolicyToast:o,dismissPolicyToast:a}}var ck=`gaia`;function lk(e){return e.some(e=>e.id===ck)}function uk(e){let t=e;return t?.httpStatus===422&&`${typeof t.detail==`string`?t.detail:``} ${typeof t.message==`string`?t.message:``}`.includes(`Unknown agent_type '${ck}'`)}var dk=new Set([``,`new chat`,`new task`,`untitled`,`untitled session`,`chat`]);function fk(e){return dk.has((e??``).trim().toLowerCase())}function pk(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 mk(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))]),pk(e,t.map(e=>e.id))}async function hk(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 Yt(e,t.id),pk(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 Dt();k.getState().setDocuments(e.documents||[])}catch(e){d.doc.error(`Could not refresh the document list after a drop`,e)}}function gk(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 _k(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 vk=2e3,yk=9e4;function bk(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(`idle`),[s,c]=(0,X.useState)(null),l=(0,X.useRef)(!0),u=(0,X.useCallback)(async()=>{try{let e=await K();return l.current&&n(e),e}catch(e){return l.current&&c(e instanceof Error?e.message:String(e)),null}},[]);(0,X.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,X.useCallback)(async()=>{c(null);let e=await u();e&&o(e.state===`stopped`?`still_down`:`back`)},[u]),f=(0,X.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()+yk;for(;l.current&&Date.now()<e;){await new Promise(e=>setTimeout(e,vk));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,X.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(J,{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(q,{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(q,{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 xk(e,t=``){let[n,r]=(0,X.useState)(()=>e&&xn(e)||t),i=(0,X.useRef)(e);return(0,X.useEffect)(()=>{i.current!==e&&(i.current=e,r(e?xn(e):``))},[e]),(0,X.useEffect)(()=>{e&&i.current===e&&nn(e,n)},[e,n]),[n,r]}function Sk(e,t){return xk(t?null:U(e))}var Ck=new Set([`tool_start`,`tool_end`,`tool_result`]),wk=`Connection lost. Reconnecting`,Tk=15e3,Ek=[],Dk=new Map;function Ok({text:e}){return P(`div`,{className:`history-notice`,role:`note`,children:e})}function kk({notices:e}){return P(`div`,{className:`library-notices`,role:`note`,children:e.map((e,t)=>P(`div`,{dir:`auto`,children:e},`${t}-${e}`))})}function Ak({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,documents:O,setDocuments:A,setShowDocLibrary:j,setShowFileBrowser:M,isLoadingMessages:N,setLoadingMessages:F,systemStatus:L}=k(),R=Qs(e=>e.addNotification),z=Qs(e=>e.showPanel),B=Qs(e=>e.setShowPanel),te=Qs(e=>e.setTypeFilter),ne=k(t=>t.pendingPrompt?.sessionId===e?t.pendingPrompt:null),oe=k(e=>e.liveStatus),H=k(pw),U=k(e=>e.awaitingUser),se=k(t=>Object.values(t.liveQuestions).some(t=>t.sessionId===e)),W=Qs(t=>tc(e)(t)!==null),G=n.find(t=>t.id===e),ce=new Set(G?.document_ids??[]),le=O.filter(e=>ce.has(e.id)),[ue,de]=Sk(e,G?.private),[fe,pe]=(0,X.useState)(!1),[me,he]=(0,X.useState)(``),[ge,_e]=(0,X.useState)(!1),[ve,ye]=(0,X.useState)(!1),be=YO(),[xe,Ce]=(0,X.useState)(!1),[we,Te]=(0,X.useState)(null),{policyToast:Ee,showPolicyToast:De,dismissPolicyToast:Oe}=sk(),[ke,Ae]=(0,X.useState)(null),{exportChat:je,exportError:Me,clearExportError:Ne}=ak(e,G?.title),Pe=G?.agent_type&&G.agent_type!==`gaia`?G.agent_type:null,[Fe,Ie]=(0,X.useState)(!1),[Le,Re]=(0,X.useState)(null),ze=(0,X.useRef)(``),Be=(0,X.useRef)([]),He=(0,X.useRef)([]),Ue=(0,X.useRef)(!1);(0,X.useEffect)(()=>{f&&(ze.current=f)},[f]),(0,X.useEffect)(()=>{g.length>0&&(Be.current=g.map(e=>({...e,active:!1})))},[g]),(0,X.useEffect)(()=>{C.length>0&&(He.current=[...C])},[C]),Ew(),(0,X.useEffect)(()=>{if(!u&&Ue.current){Ie(!0);let e=setTimeout(()=>{Ie(!1),ze.current=``,Be.current=[],He.current=[]},350);return()=>clearTimeout(e)}Ue.current=u},[u]);let We=(0,X.useRef)(null),Ge=(0,X.useRef)(null),Ke=(0,X.useRef)(null),qe=(0,X.useRef)(null),Je=(0,X.useRef)(0),Xe=(0,X.useRef)(!1),Ze=(0,X.useRef)(0),Qe=(0,X.useRef)(null),[$e,et]=(0,X.useState)(!1),tt=(0,X.useRef)(!1),nt=(0,X.useRef)(null),it=(0,X.useRef)(null),at=(0,X.useRef)(0),K=(0,X.useRef)(!1),ot=(0,X.useRef)(()=>{}),lt=(0,X.useRef)(!1),ut=k(t=>t.messageQueues[e]??Ek),dt=(0,X.useCallback)(t=>k.getState().updateQueue(e,t),[e]),ft=(0,X.useRef)(!1),[pt,ht]=(0,X.useState)(!1),gt=(0,X.useRef)(!1),_t=(0,X.useRef)(!1),vt=(0,X.useRef)(u);vt.current=u;let yt=k(t=>!!t.queueHolds[e]),bt=(0,X.useRef)(``),xt=(0,X.useRef)(null),St=(0,X.useRef)(null),wt=(0,X.useRef)(0),Tt=(0,X.useRef)(!0),{userScrolling:Et,clearUserScroll:Ot,listProps:kt}=ik(Ge,Tt,e=>ye(e>200)),At=(0,X.useCallback)(()=>k.getState().currentSessionId!==e,[e]),jt=(0,X.useCallback)(()=>{xt.current=null,!At()&&bt.current&&m(bt.current)},[m,At]),Mt=(0,X.useRef)(0),Nt=(0,X.useRef)(0);(0,X.useEffect)(()=>{d.chat.info(`ChatView mounted for session=${e}, loading messages...`);let t=d.chat.time();F(!0);let n=!1,r=!1,a=async(a=!1)=>{if(n||r)return;r=!0;let o=Nt.current;try{if(!a){if(k.getState().isStreaming)return;let t=await rt(e);if(n||t===Mt.current||k.getState().isStreaming)return}let r=await ct(e);if(n)return;let s=yw(r.messages);a&&Nt.current!==o?Mt.current=s.length:a?(i(s),Mt.current=s.length,d.chat.timed(`Loaded ${s.length} message(s) for session=${e}`,t)):s.length!==Mt.current&&!k.getState().isStreaming&&(d.chat.info(`Messages changed externally: ${Mt.current} -> ${s.length}`),i(Cw(k.getState().messages,s)),Mt.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&&F(!1)}};a(!0);let o=gk(()=>a(!1),3e3);return()=>{n=!0,o()}},[e,i,F]),(0,X.useEffect)(()=>{Dt().then(e=>A(e.documents||[])).catch(e=>d.doc.error(`Could not load the document list`,e))},[A]);let Pt=(0,X.useRef)(!0),Ft=(0,X.useRef)(!1),It=Hw(L);(0,X.useEffect)(()=>(Pt.current=!0,()=>{Pt.current=!1}),[]),(0,X.useEffect)(()=>{let e=ne?.text;!e||k.getState().isLoadingMessages||It||(k.getState().setPendingPrompt(null),Ft.current=!0,setTimeout(()=>{Ft.current=!1,Pt.current&&ot.current(e,{opening:!0})},0))},[ne,N,It]),(0,X.useEffect)(()=>{if(!Tt.current)return;let e=Date.now()-wt.current,t=()=>{Tt.current&&!Et()&&(wt.current=Date.now(),We.current?.scrollIntoView({behavior:`instant`}))};e>=100&&t(),St.current&&clearTimeout(St.current),St.current=setTimeout(t,100)},[r,f,g]),(0,X.useEffect)(()=>{Ke.current?.focus()},[e]),(0,X.useEffect)(()=>{ft.current=!1},[e]);let{contextUsage:Lt,contextUnavailable:Rt,refreshContext:zt,showContextUsage:Bt}=ZO(e,At),{comparison:Vt,comparing:Ht,comparingRef:Ut,handleRetryWith:Wt,handleKeepAnswer:Gt,handleCloseComparison:Kt,closeForNewTurn:qt}=XO({sessionId:e,isStreaming:u,isStale:At,setMessages:i,refreshContext:zt});(0,X.useEffect)(()=>()=>{vt.current&&dT(e),qe.current&&!_t.current&&qe.current.abort(),qe.current&&=null,nt.current&&=(clearTimeout(nt.current),null),tt.current=!1,it.current=null,et(!1),xt.current!==null&&(cancelAnimationFrame(xt.current),xt.current=null),St.current&&=(clearTimeout(St.current),null),Qe.current&&=(clearTimeout(Qe.current),null),Oe(),bt.current=``,k.getState().resetStreaming()},[e]),(0,X.useEffect)(()=>{ke&&z&&(document.getElementById(ww(ke))?.scrollIntoView({behavior:Mx(),block:`center`}),Ae(null))},[ke,z]);let Jt=fD(e=>e.width),Yt=fD(e=>e.reveal),Xt=qO(e=>e.visible),Zt=qO(e=>e.setVisible),Qt=(0,X.useRef)(null),$t=(0,X.useCallback)(()=>{Zt(!1),Qt.current?.focus()},[Zt]),en=QO(Ge,Tt),tn=(0,X.useCallback)(()=>{Tt.current=!0,Ot(),We.current?.scrollIntoView({behavior:Mx()})},[Ot]),nn=(0,X.useCallback)(()=>{tt.current||(tt.current=!0,ft.current=!0,et(!0),Qs.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)}),Qe.current?(clearTimeout(Qe.current),Qe.current=null,it.current?.()):nt.current=setTimeout(()=>{d.stream.error(`No closing event ${Tk}ms after Stop; closing the turn locally (session=${e})`),it.current?.()},Tk))},[e]);(0,X.useEffect)(()=>{let e=e=>{e.key===`Escape`&&u&&!Po(e)&&(e.preventDefault(),nn())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,nn]);let rn=(0,X.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?ue:t??``).trim(),C=f&&be.hasUploaded,T=f&&be.hasImage,D=()=>{if(!f)return g;let e=be.compose(g);return de(``),be.clear(),Ke.current?.focus(),e};Tt.current=!0;let O=Hw(L),A=e=>{a&&n?.onQueuedOutcome?.(e)};if(!r&&Pe){d.chat.warn(`Send blocked: chat ${e} belongs to the retired "${Pe}" agent`),A({kind:`failed`,error:`This chat's "${Pe}" agent was retired, so it cannot take new messages.`});return}let j=!n?.opening&&(k.getState().messageQueues[e]??Ek).length>0;if(r){if(u&&!c)return}else if(!a&&(g||C)&&!O&&(u||Ut.current||j)){let e=D();dt(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&&(!Ho(`chat`)||T&&!Ho(`vision`))){if(lt.current)return;lt.current=!0;try{if(!await Go(`chat`)||T&&!await Go(`vision`))return}finally{lt.current=!1}}let M=g,N=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)}),qt();let t={id:Date.now(),session_id:e,role:`user`,content:M,created_at:new Date().toISOString(),rag_sources:null};o(t),N=t,Nt.current+=1}c||(Ze.current=0),p(!0),h(),S(),E(),at.current=0,K.current=!1,c&&k.getState().setLiveStatus(`${wk} (attempt ${c} of 3)…`),d.stream.info(`Starting agent stream...`);let P=d.stream.time(),F=``,z;Re(null);let B=!1;gt.current=!1,r||ht(!1);let te=null,V=!a;_t.current=a;let ne=e=>{V||(V=!0,_t.current=!1,n?.onQueuedOutcome?.(e),e.kind===`accepted`&&At()&&te?.abort())},ie=r||!!G&&!fk(G.title),ae=()=>{ne({kind:`accepted`}),!ie&&(ie=!0,mt(e).then(t=>l(e,{title:t.title})).catch(e=>d.chat.warn(`Could not refresh the chat title`,e)))};bt.current=``,tt.current=!1,et(!1);let oe=()=>{nt.current&&=(clearTimeout(nt.current),null),tt.current=!1,it.current=null,et(!1)},H=()=>{let{agentSteps:e,cards:t}=k.getState();return{steps:e.map(e=>({...e,active:!1})),cards:[...t]}};it.current=()=>{if(B)return;B=!0,Xe.current=!0,Je.current=Date.now(),oe(),ne({kind:`failed`,error:`Stopped before GAIA confirmed it got this message.`}),qe.current?.abort(),qe.current=null,xt.current!==null&&(cancelAnimationFrame(xt.current),xt.current=null);let t=bt.current||k.getState().streamingContent;if(bt.current=``,At())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(At())return;let e=k.getState();(e.liveStatus===`Waiting for GAIA to start this answer…`||e.liveStatus?.startsWith(wk))&&e.setLiveStatus(null)},onChunk:t=>{if(ae(),At())return;k.getState().awaitingUser&&k.getState().setAwaitingUser(!1);let n=t.content||``;if(n&&Qs.getState().dismissSessionPrompts(e),n){if(t.type===`answer`)F=n;else{K.current&&=(F.length>0&&(F+=`
|
|
69
69
|
|
|
70
|
-
`),!1),F+=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=F.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())}}bt.current=e,xt.current===null&&(xt.current=requestAnimationFrame(jt))}},onAgentEvent:t=>{if((t.type!==`status`||t.phase!==`waiting`)&&ae(),t.type===`followup_taken`&&t.text){let n=t.text;if(dt(e=>re(e,n)),At())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`){At()||ht(!0);return}if(t.type===`followup_returned`){let e=t.texts??[];dt(t=>y(t,e));return}if(At())return;if(t.type===`context_usage`){Bt(t);return}let n=t.type===`permission_request`||t.type===`needs_input`;if(k.getState().awaitingUser!==n&&k.getState().setAwaitingUser(n),Ck.has(t.type)&&Qs.getState().dismissSessionPrompts(e),t.type===`permission_request`){let n=t.tool||``,r=t.tool_label||n,{addNotification:i,notifications:a}=Qs.getState(),o=t.confirm_id?a.find(e=>e.id===t.confirm_id):void 0;if(o){!o.response&&o.dismissed&&Qs.setState(e=>({notifications:e.notifications.map(e=>e.id===o.id?{...e,dismissed:!1}:e)}));return}let s=n===Hs,c=s&&Ys(a,e,t.args);i({id:t.confirm_id??`perm-${Date.now()}`,type:`permission_request`,agentId:e,sessionId:e,agentName:`GAIA`,title:s?Gs(t.args,c):`Allow ${r}?`,message:s?Ws(t.args,c):`GAIA needs your OK before ${r}.`,timestamp:Date.now(),read:!1,dismissed:!1,priority:`high`,tool:n,toolArgs:t.args,confirmId:t.confirm_id,alwaysScope:typeof t.always_scope==`string`?t.always_scope:void 0,alwaysLabel:typeof t.always_label==`string`&&t.always_label?t.always_label:void 0,toolLabel:t.tool_label||void 0,risk:typeof t.risk==`string`?t.risk:void 0,summary:typeof t.summary==`string`&&t.summary?t.summary:void 0,pathFollowUp:c||void 0,timeoutSeconds:t.timeout_seconds});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=t.tool||`unknown tool`,r=t.reason||t.message||t.content||`Tool execution was blocked by governance policy.`,i={id:t.receipt_id??`policy-${Date.now()}-${at.current+1}`,type:`policy_alert`,agentId:e,agentName:`GAIA`,title:`Blocked: ${n} is restricted by policy.`,message:r,timestamp:Date.now(),read:!1,dismissed:!1,priority:`critical`,tool:n,decision:t.decision||`BLOCK`,reason:r,ruleIds:t.rule_ids??[],policyVersion:t.policy_version,receiptId:t.receipt_id};R(i);let a=dw(t,at);a&&_(a),De({tool:n,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});let e={result:t.summary||t.title||`Done`,active:!1,success:t.success!==!1,latencyMs:t.latency_ms};t.command_output&&(e.commandOutput={command:t.command_output.command,stdout:t.command_output.stdout,stderr:t.command_output.stderr,returnCode:t.command_output.return_code,expectedExit:t.command_output.expected_exit,cwd:t.command_output.cwd,durationSeconds:t.command_output.duration_seconds,truncated:t.command_output.truncated}),t.mcp_output?.text&&(e.mcpOutput=t.mcp_output),t.result_data?.chunks&&t.result_data.chunks.length>0&&(e.retrievalChunks=t.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}))),t.result_data?.type===`file_list`&&t.result_data.files?.length>0&&(e.fileList={files:t.result_data.files,total:t.result_data.total??t.result_data.files.length}),x(e);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,at));return}if(t.type===`commentary`){F=``,K.current=!1,bt.current=``,m(``);let e=dw(t,at);e&&_(e);return}if(t.retracts_answer&&(F=``,K.current=!1,bt.current=``,m(``),t.type===`status`)){let e=dw({type:`status`,status:`warning`,message:I()(`live.answerRestarted`)},at);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,at);r&&_(r);return}if(t.type===`status`){if(t.status===`history_cut`){z=(t.message||``).trim()||void 0,Re(z??null);return}mw(t,at);return}if(t.type===`step`||t.type===`agent_error`&&_w(t,k.getState().agentSteps))return;let r=dw(t,at);r&&(_(r),t.type===`tool_start`&&(K.current=!0,k.getState().setLiveStatus(Iy(r,I()),`tool`)))},onDone:t=>{if(ae(),Qs.getState().dismissSessionPrompts(e),k.getState().closeSessionQuestions(e),B)return;B=!0;let n=t.cancelled===!0?`stopped`:tt.current&&t.message_id==null?`unconfirmed`:void 0;if(oe(),xt.current!==null&&(cancelAnimationFrame(xt.current),xt.current=null),bt.current=``,mk(e,t.documents_added??[]),At())return;Je.current=Date.now(),gt.current=!0;let a=k.getState();a.setRunningSessions(a.runningSessionIds.filter(t=>t!==e));let s=t.content||F;d.chat.timed(`Agent response complete: ${s.length} chars${n?` (${n})`:``}`,P);let{steps:c,cards:l}=H(),u=c.some(e=>e.type===`policy_alert`);if(s||u||n){Mt.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,failure:t.failed?t.failure:void 0};z&&Dk.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(),Ke.current&&Ke.current.focus(),setTimeout(()=>{ct(e).then(t=>{if(At()||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),Mt.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&&!!N&&yT(e,M,t);if(!V||i){if(n)ae();else{if(ne(gT(t)?{kind:`busy`}:{kind:`failed`,error:$S(t).text}),Je.current=Date.now(),oe(),xt.current!==null&&(cancelAnimationFrame(xt.current),xt.current=null),bt.current=``,At())return;d.chat.info(`Queued message for session=${e} not taken: ${t.message}`),N&&s(N.id),gt.current=!0,p(!1),h(),S(),E();return}}if(n&&tt.current&&!B){d.chat.warn(`Stream for session=${e} was lost while stopping; closing the turn locally`),it.current?.();return}if(n&&!Pt.current)return;if(n&&!B&&!At()&&Ze.current<3){let n=++Ze.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(`${wk} (attempt ${n} of 3)…`);let i=()=>{Qe.current=null,!(!Pt.current||At()||tt.current)&&ot.current(void 0,{attach:!0,reconnect:n})};r>0?Qe.current=setTimeout(i,r):i();return}Je.current=Date.now(),Qs.getState().dismissSessionPrompts(e),k.getState().closeSessionQuestions(e);let a=tt.current;if(oe(),xt.current!==null&&(cancelAnimationFrame(xt.current),xt.current=null),bt.current=``,At())return;if(n||(gt.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:F,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`}),Mt.current=k.getState().messages.length,p(!1),h(),S(),E();return}let{kind:c,text:l}=$S(t),u=c===`stream`?l:l+`
|
|
70
|
+
`),!1),F+=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=F.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())}}bt.current=e,xt.current===null&&(xt.current=requestAnimationFrame(jt))}},onAgentEvent:t=>{if((t.type!==`status`||t.phase!==`waiting`)&&ae(),t.type===`followup_taken`&&t.text){let n=t.text;if(dt(e=>re(e,n)),At())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`){At()||ht(!0);return}if(t.type===`followup_returned`){let e=t.texts??[];dt(t=>y(t,e));return}if(At())return;if(t.type===`context_usage`){Bt(t);return}let n=t.type===`permission_request`||t.type===`needs_input`;if(k.getState().awaitingUser!==n&&k.getState().setAwaitingUser(n),Ck.has(t.type)&&Qs.getState().dismissSessionPrompts(e),t.type===`permission_request`){let n=t.tool||``,r=t.tool_label||n,{addNotification:i,notifications:a}=Qs.getState(),o=t.confirm_id?a.find(e=>e.id===t.confirm_id):void 0;if(o){!o.response&&o.dismissed&&Qs.setState(e=>({notifications:e.notifications.map(e=>e.id===o.id?{...e,dismissed:!1}:e)}));return}let s=n===Hs,c=s&&Ys(a,e,t.args);i({id:t.confirm_id??`perm-${Date.now()}`,type:`permission_request`,agentId:e,sessionId:e,agentName:`GAIA`,title:s?Gs(t.args,c):`Allow ${r}?`,message:s?Ws(t.args,c):`GAIA needs your OK before ${r}.`,timestamp:Date.now(),read:!1,dismissed:!1,priority:`high`,tool:n,toolArgs:t.args,confirmId:t.confirm_id,alwaysScope:typeof t.always_scope==`string`?t.always_scope:void 0,alwaysLabel:typeof t.always_label==`string`&&t.always_label?t.always_label:void 0,toolLabel:t.tool_label||void 0,risk:typeof t.risk==`string`?t.risk:void 0,summary:typeof t.summary==`string`&&t.summary?t.summary:void 0,pathFollowUp:c||void 0,timeoutSeconds:t.timeout_seconds});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=t.tool||`unknown tool`,r=t.reason||t.message||t.content||`Tool execution was blocked by governance policy.`,i={id:t.receipt_id??`policy-${Date.now()}-${at.current+1}`,type:`policy_alert`,agentId:e,agentName:`GAIA`,title:`Blocked: ${n} is restricted by policy.`,message:r,timestamp:Date.now(),read:!1,dismissed:!1,priority:`critical`,tool:n,decision:t.decision||`BLOCK`,reason:r,ruleIds:t.rule_ids??[],policyVersion:t.policy_version,receiptId:t.receipt_id};R(i);let a=dw(t,at);a&&_(a),De({tool:n,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});let e={result:t.summary||t.title||`Done`,active:!1,success:t.success!==!1,latencyMs:t.latency_ms};t.command_output&&(e.commandOutput={command:t.command_output.command,stdout:t.command_output.stdout,stderr:t.command_output.stderr,returnCode:t.command_output.return_code,expectedExit:t.command_output.expected_exit,cwd:t.command_output.cwd,durationSeconds:t.command_output.duration_seconds,truncated:t.command_output.truncated}),t.mcp_output?.text&&(e.mcpOutput=t.mcp_output),t.result_data?.chunks&&t.result_data.chunks.length>0&&(e.retrievalChunks=t.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}))),t.result_data?.type===`file_list`&&t.result_data.files?.length>0&&(e.fileList={files:t.result_data.files,total:t.result_data.total??t.result_data.files.length}),x(e);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,at));return}if(t.type===`commentary`){F=``,K.current=!1,bt.current=``,m(``);let e=dw(t,at);e&&_(e);return}if(t.retracts_answer&&(F=``,K.current=!1,bt.current=``,m(``),t.type===`status`)){let e=dw({type:`status`,status:`warning`,message:I()(`live.answerRestarted`)},at);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,at);r&&_(r);return}if(t.type===`status`){if(t.status===`history_cut`){z=(t.message||``).trim()||void 0,Re(z??null);return}mw(t,at);return}if(t.type===`step`||t.type===`agent_error`&&_w(t,k.getState().agentSteps))return;let r=dw(t,at);r&&(_(r),t.type===`tool_start`&&(K.current=!0,k.getState().setLiveStatus(Iy(r,I()),`tool`)))},onDone:t=>{if(ae(),Qs.getState().dismissSessionPrompts(e),k.getState().closeSessionQuestions(e),B)return;B=!0;let n=t.cancelled===!0?`stopped`:tt.current&&t.message_id==null?`unconfirmed`:void 0;if(oe(),xt.current!==null&&(cancelAnimationFrame(xt.current),xt.current=null),bt.current=``,mk(e,t.documents_added??[]),At())return;Je.current=Date.now(),gt.current=!0;let a=k.getState();a.setRunningSessions(a.runningSessionIds.filter(t=>t!==e));let s=t.content||F;d.chat.timed(`Agent response complete: ${s.length} chars${n?` (${n})`:``}`,P);let{steps:c,cards:l}=H(),u=c.some(e=>e.type===`policy_alert`);if(s||u||n){Mt.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&&Dk.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(),Ke.current&&Ke.current.focus(),setTimeout(()=>{ct(e).then(t=>{if(At()||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),Mt.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&&!!N&&yT(e,M,t);if(!V||i){if(n)ae();else{if(ne(gT(t)?{kind:`busy`}:{kind:`failed`,error:$S(t).text}),Je.current=Date.now(),oe(),xt.current!==null&&(cancelAnimationFrame(xt.current),xt.current=null),bt.current=``,At())return;d.chat.info(`Queued message for session=${e} not taken: ${t.message}`),N&&s(N.id),gt.current=!0,p(!1),h(),S(),E();return}}if(n&&tt.current&&!B){d.chat.warn(`Stream for session=${e} was lost while stopping; closing the turn locally`),it.current?.();return}if(n&&!Pt.current)return;if(n&&!B&&!At()&&Ze.current<3){let n=++Ze.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(`${wk} (attempt ${n} of 3)…`);let i=()=>{Qe.current=null,!(!Pt.current||At()||tt.current)&&ot.current(void 0,{attach:!0,reconnect:n})};r>0?Qe.current=setTimeout(i,r):i();return}Je.current=Date.now(),Qs.getState().dismissSessionPrompts(e),k.getState().closeSessionQuestions(e);let a=tt.current;if(oe(),xt.current!==null&&(cancelAnimationFrame(xt.current),xt.current=null),bt.current=``,At())return;if(n||(gt.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:F,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`}),Mt.current=k.getState().messages.length,p(!1),h(),S(),E();return}let{kind:c,text:l}=$S(t),u=c===`stream`?l:l+`
|
|
71
71
|
|
|
72
72
|
---
|
|
73
73
|
*Unexpected error?* [Report it on GitHub](${IT((t.message||``).slice(0,80))})`,f={id:Date.now()+2,session_id:e,role:`assistant`,content:u,created_at:new Date().toISOString(),rag_sources:null,failed:!GS(t),failureText:t.message||void 0};o(f),p(!1),h(),S(),E()}},se=r?Cn(e,U):Ve(e,M,U);te=se,qe.current=se},[ue,be,u,e,G,Pe,o,s,i,p,jt,h,l,_,v,b,x,S,w,E,R,At]);ot.current=rn;let an=k(t=>t.runningSessionIds.includes(e)),on=k(e=>e.activeRunsAt>Je.current);(0,X.useEffect)(()=>{eT()},[e]),(0,X.useEffect)(()=>{an?!on||u||Xe.current||(d.chat.info(`Resuming live view of background run for session=${e}`),ot.current(void 0,{attach:!0})):Xe.current=!1},[e,an,on,u]),(0,X.useEffect)(()=>{let e=e=>{let t=e.detail?.text;typeof t==`string`&&t.trim()&&ot.current(t)};return window.addEventListener(`gaia:send-message`,e),()=>window.removeEventListener(`gaia:send-message`,e)},[]),(0,X.useEffect)(()=>{!u&&Ke.current&&Ke.current.focus()},[u]);let sn=(0,X.useCallback)(async t=>{u||(d.chat.info(`Deleting message ${t} from session=${e}`),Te(t),setTimeout(async()=>{s(t),Te(null);try{await Ct(e,t)}catch(n){d.chat.error(`Failed to delete message ${t}`,n),ct(e).then(e=>{At()||i(yw(e.messages))}).catch(t=>d.chat.error(`Could not reload messages for session=${e}`,t))}},250))},[e,u,s,i,At]),cn=(0,X.useRef)(!1),ln=(0,X.useCallback)(async(n,r)=>{if(u||n.role!==`user`||cn.current)return;cn.current=!0;let a=n.content;d.chat.info(`Resending message ${n.id} from session=${e}`,{preview:a.slice(0,80)});try{let t=await ct(e);if(At())return;let o=yw(t.messages),s=bw(o,k.getState().messages,n);if(s&&r&&!Sw(o,s,r)){d.chat.info(`Message ${n.id} was answered since it failed; not resending`),i(o),Mt.current=o.length;return}if(s&&await kn(e,s.id),At()){let{sessions:t,pendingDeleteIds:n}=k.getState();t.some(t=>t.id===e)&&!n.includes(e)&&dt(e=>ee(e,a,`queued`));return}}catch(r){d.chat.error(`Could not resend message ${n.id} in session=${e}`,r);let i=r instanceof Error?$S(r):null,a=i?.kind===`connection`||i?.kind===`timeout`;R({id:`resend-failed-${e}-${Date.now()}`,type:`error`,agentId:e,agentName:`GAIA`,title:t(`chatError.resendFailed`),message:a?i.text:t(`chatError.resendStale`),timestamp:Date.now(),read:!1,dismissed:!1,priority:`high`,sessionId:e});return}finally{cn.current=!1}c(n.id),rn(a)},[e,u,c,i,dt,rn,At,R,t]);(0,X.useEffect)(()=>pT(e),[e]);let un=k(()=>fT(e)),dn=(0,X.useCallback)((e,t)=>new Promise(e=>{ot.current(t,{queued:!0,onQueuedOutcome:e})}),[]),fn=u||Ht;(0,X.useEffect)(()=>{if(!fn){if(ft.current){ft.current=!1;let e=ut.map(e=>e.text);e.length&&(dt(()=>[]),de(t=>[t.trim(),...e].filter(Boolean).join(`
|
|
74
74
|
|
|
75
|
-
`)))}else ut.length===0||yt||N||ne||Ft.current||Pe||It||At()||!gt.current&&!un||bT(e,dn,()=>Pt.current&&!At()&&!k.getState().isStreaming&&!Ut.current)}},[fn,ut,yt,un,N,ne,Pe,It,e,dn,At]);let pn=(0,X.useRef)(!1);(0,X.useEffect)(()=>{pn.current&&!fn&&zt(),pn.current=fn},[fn,zt]);let mn=(0,X.useCallback)(t=>{let n=ut.find(e=>e.id===t&&e.state===`queued`);n&&u&&(dt(e=>ae(e,t,`queued`,`sending`)),wn(e,n.text).then(()=>dt(e=>ae(e,t,`sending`,`delivered`))).catch(e=>{d.chat.info(`Follow-up not taken by the running reply; it stays queued: ${e instanceof Error?e.message:e}`),dt(e=>a(e,t))}))},[ut,u,e,dt]),hn=(0,X.useCallback)(()=>{for(let e=r.length-1;e>=0;e--)if(r[e].role===`user`){ln(r[e]);return}},[r,ln]),gn=(0,X.useCallback)(e=>{let t=r.indexOf(e);for(let n=t-1;n>=0;n--)if(r[n].role===`user`){ln(r[n],e);return}},[r,ln]),_n=()=>{he(G?.title||``),pe(!0)},vn=async()=>{let t=me.trim().slice(0,200).trim();t&&me!==G?.title&&t!==G?.title&&(await Se(e,{title:t,title_is_custom:!0}),l(e,{title:t})),pe(!1)},yn=(0,X.useCallback)(async()=>{if(e)try{let t=await st(e);l(e,{private:t.private})}catch(e){d.ui.warn(`Failed to toggle private mode`,e)}},[e,l]),bn=(0,X.useCallback)(async(t,n)=>{t.stopPropagation();let r=O.find(e=>e.id===n);d.doc.info(`Detaching document from session: ${r?.filename||n}`);try{await On(e,n);let t=(k.getState().sessions.find(t=>t.id===e)?.document_ids??[]).filter(e=>e!==n);l(e,{document_ids:t}),t.length<=3&&Ce(!1),d.doc.info(`Detached document from session: ${r?.filename||n}`)}catch(e){d.doc.error(`Failed to detach document: ${r?.filename||n}`,e)}},[O,e,l]),xn=(0,X.useCallback)(async t=>{if(t.preventDefault(),t.stopPropagation(),_e(!1),t.dataTransfer.files.length===0)return;let n=Array.from(t.dataTransfer.files),r=n.filter(e=>OT(e.name));r.length>0&&be.addFiles(r);let i=n.filter(e=>!OT(e.name));i.length!==0&&await Go(`embedding`)&&await hk(e,i)},[e,be]),Sn=e=>{e.preventDefault(),e.stopPropagation(),_e(!0)},Tn=e=>{e.preventDefault(),e.stopPropagation(),_e(!1)},En=r.length>0?r[r.length-1]:void 0,Dn=!u&&!N&&En?.role===`assistant`&&wb(En.content),An=(0,X.useMemo)(()=>{let e=new Map,t;for(let n of r)if(n.role===`user`&&n.created_at)t=new Date(n.created_at).getTime();else if(n.role===`assistant`&&n.created_at&&t!==void 0){let r=new Date(n.created_at).getTime();r>t&&e.set(n.id,r-t),t=void 0}return e},[r]),jn=Pe?`This chat used the retired "${Pe}" agent and is read-only. Start a new chat.`:Hw(L)?Rc:null;return V(`main`,{className:`task-view ${ge?`drag-active`:``}`,style:{"--session-panel-w":`${Jt}px`},onDrop:xn,onDragOver:Sn,onDragLeave:Tn,"aria-label":G?.title||`Chat`,children:[V(`header`,{className:`task-header`,children:[P(`div`,{className:`task-header-left`,children:fe?P(`input`,{className:`title-edit`,value:me,maxLength:200,onChange:e=>he(e.target.value),onBlur:vn,onKeyDown:e=>{e.key===`Enter`&&vn(),e.key===`Escape`&&(e.preventDefault(),pe(!1))},...Ao,autoFocus:!0,"aria-label":`Chat title`,dir:`auto`}):V(`button`,{type:`button`,className:`task-title`,onClick:_n,title:t(`row.rename`),children:[P(`span`,{children:G?.title||t(`sidebar.newChat`)}),P(Ta,{size:12,"aria-hidden":`true`,className:`task-title-edit`})]})}),V(`div`,{className:`task-header-right`,children:[P(`button`,{ref:Qt,className:`btn-icon-sm task-header-resources`,onClick:()=>Zt(!Xt),"aria-pressed":Xt,"aria-label":t(`resources.toggle`),title:t(Xt?`resources.hide`:`resources.show`),children:P(Hn,{size:15,"aria-hidden":`true`})}),P(wO,{isPrivate:!!G?.private,onToggle:yn}),P(`button`,{className:`btn-icon-sm`,onClick:()=>M(!0),title:`Browse files on this PC`,"aria-label":`Browse files on this PC`,children:P(wi,{size:15})}),P(`button`,{className:`btn-icon-sm`,onClick:je,title:`Export as Markdown`,"aria-label":`Export chat`,children:P(Jr,{size:15})}),P(CO,{messages:r,busy:u})]})]}),Xt&&P(HO,{onClose:$t}),le.length>0&&(()=>{let e=[...le].sort((e,t)=>{let n=e.last_accessed_at||e.indexed_at||``;return(t.last_accessed_at||t.indexed_at||``).localeCompare(n)}),t=xe?e:e.slice(0,3),n=e.length-3;return V(`div`,{className:`doc-context-bar${xe?` doc-context-expanded`:``}`,"aria-label":`${le.length} indexed document${le.length===1?``:`s`}`,children:[P(Or,{size:12,className:`doc-context-icon`,"aria-hidden":`true`}),V(`button`,{type:`button`,className:`doc-context-label`,onClick:()=>j(!0),title:`Manage documents`,children:[le.length,` indexed`]}),V(`div`,{className:`doc-context-pills${xe?` doc-context-pills-expanded`:``}`,children:[t.map(e=>V(`span`,{className:`doc-pill`,title:e.filepath||e.filename,children:[P(gi,{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=>bn(t,e.id),"aria-label":`Remove ${e.filename} from this chat`,children:P(Y,{size:10})})]},e.id)),!xe&&n>0&&V(`button`,{className:`doc-pill-more`,onClick:e=>{e.stopPropagation(),Ce(!0)},children:[`+`,n,` more`]}),xe&&n>0&&P(`button`,{className:`doc-pill-collapse`,onClick:e=>{e.stopPropagation(),Ce(!1)},children:`show less`})]})]})})(),P(`div`,{className:`messages-scroll`,ref:Ge,...kt,children:V(`div`,{className:`messages-column`,children:[N&&P(`div`,{className:`skeleton-messages`,"aria-label":`Loading messages`,children:[0,1,2].map(e=>P(`div`,{className:`skeleton-msg`,children:V(`div`,{className:`skeleton-lines`,children:[P(`div`,{className:`skeleton-line`}),P(`div`,{className:`skeleton-line`}),e!==2&&P(`div`,{className:`skeleton-line`})]})},e))}),r.map((e,t)=>{if(Fe&&e.role===`assistant`&&t===r.length-1)return null;let n=e.role===`assistant`?e.historyNotice??Dk.get(e.id):void 0,i=e.role===`assistant`&&HC(e.content,e.stopState)===`interrupted`,a=(e.failed===!0||i)&&!fn&&!Pe&&!Fe&&t===r.length-1,o=!a&&!fn&&!Vt&&!Pe&&!Fe&&e.role===`assistant`&&t===r.length-1&&!e.stopState&&!e.failed&&!xC(e.content),s=e.stats?.seconds==null?An.get(e.id):e.stats.seconds*1e3;return V(`div`,{className:we===e.id?`msg-deleting`:void 0,"data-message-id":e.id,"data-role":e.role,children:[n&&P(Ok,{text:n}),P(UC,{message:e,agentSteps:e.role===`assistant`?e.agentSteps:void 0,onDelete:fn?void 0:sn,onResend:!fn&&e.role===`user`&&!Pe?ln:void 0,extraActions:o?P(eD,{answeredBy:e.stats?.model??G?.effective_model,onPick:t=>Wt(e,t)}):void 0,onTryAgain:a?()=>gn(e):void 0,latencyMs:s}),e.failure===`model_server_down`&&t===r.length-1&&!fn&&P(bk,{}),Vt?.messageId===e.id&&P(rD,{original:e,originalModel:e.stats?.model??G?.effective_model,originalLatencyMs:s,state:Vt.state,keeping:Vt.keeping,onKeep:e=>{Gt(e)},onClose:Kt})]},e.id)}),(u||Fe)&&Le&&P(Ok,{text:Le}),u&&P(Lw,{}),(u||Fe)&&P(`div`,{className:`streaming-bubble ${Fe?`stream-ending`:`stream-active`}`,children:P(UC,{message:{id:-1,session_id:e,role:`assistant`,content:(u?f:ze.current)||``,created_at:``,rag_sources:null},isStreaming:u,agentSteps:u?g:Be.current,agentStepsActive:u&&g.some(e=>e.active),cards:u?C:He.current,liveStatus:u?oe:null,toolStatus:u?H:null,awaitingUser:u&&(U||se||W)})}),P(`div`,{ref:We})]})}),P(SO,{sessionId:e,messages:r,busy:fn,onUsage:Bt,onJumpToMessage:en}),ve&&P(`button`,{className:`scroll-bottom-btn`,onClick:tn,title:`Scroll to bottom`,"aria-label":`Scroll to bottom`,children:P(Kn,{size:16})}),ge&&V(`div`,{className:`drag-overlay`,children:[P(ho,{size:32,strokeWidth:1.5,"aria-hidden":`true`}),P(`span`,{children:`Drop files to index them for this chat`})]}),Ee&&V(`div`,{className:`toast policy-alert-toast`,role:`alert`,children:[V(`span`,{children:[`Blocked: `,Ee.tool,` is restricted by policy.`]}),Ee.receiptId?P(`button`,{type:`button`,className:`policy-alert-toast-link`,onClick:()=>{let e=Ee.receiptId;e&&(te(`policy_alert`),B(!0),Ae(e))},children:`View receipt`}):P(`span`,{className:`policy-alert-toast-missing`,children:`Receipt unavailable`})]}),P(`div`,{className:`input-area`,children:V(`div`,{className:`input-column`,children:[P(WO,{message:Me,onDismiss:Ne}),Dn&&En&&P(UT,{content:En.content,onRetry:hn}),P(fy,{sessionId:e}),P(YE,{usage:Lt}),P(UO,{sessionId:e}),ne&&It&&P(`ul`,{className:`queued-messages`,"aria-label":t(`composer.heldLabel`),"aria-live":`polite`,children:V(`li`,{className:`queued-message is-queued`,children:[P(Pr,{size:12,"aria-hidden":`true`}),P(`span`,{className:`queued-message-text`,title:ne.text,children:ne.text}),P(`span`,{className:`queued-message-state`,children:t(`composer.heldUntilStarted`)})]})}),P(TE,{items:ut,onRemove:e=>dt(t=>ie(t,e)),onRetry:e=>dt(t=>ae(t,e,`failed`,`queued`)),onSteer:u&&!$e&&!pt?mn:void 0,replying:u,busyRetry:!!yt}),P(qT,{value:ue,onChange:de,onSubmit:()=>rn(),onStop:nn,streaming:u,stopping:$e,queueWhileStreaming:!0,disabledReason:jn,attachments:be,inputRef:Ke,placeholder:u?t(`composer.queueNext`):r.length===0?t(`composer.placeholder`):t(`composer.reply`),leftControls:P(SE,{sessionId:e,disabled:!!Pe}),rightControls:V(D.Fragment,{children:[P(JE,{usage:Lt,unavailable:Rt,sessionId:e,busy:fn,onUsage:Bt,onDetails:()=>Yt(`context`)}),P(QE,{sessionId:e,busy:fn}),P(_E,{sessionId:e,onOpen:()=>Yt(`environment`)}),P(aE,{})]})})]})})]})}var Ak=1.1,jk=60,Mk=110,Nk=24,Pk=2.4,Fk=Math.PI*2,Ik=(e,t,n)=>{let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)};function Lk(e){let t=e;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}var Rk=class{cols=0;rows=0;w=0;h=0;ox=0;oy=0;time=0;energy=new Float32Array;offset=new Float32Array;mask=new Float32Array;phase=new Float32Array;waves=[];ripples=[];waveIn=1.5;dragIn=0;activity=`idle`;progress=0;pointer=null;exit=null;done=!1;settled=!1;rand;constructor(e=7){this.rand=Lk(e)}get cleared(){return this.done}get dissolving(){return this.exit!==null||this.done}resize(e,t,n){this.w=e,this.h=t,this.cols=Math.ceil(e/30),this.rows=Math.ceil(t/30),this.ox=(e-this.cols*30)/2,this.oy=(t-this.rows*30)/2;let r=this.cols*this.rows;this.energy=new Float32Array(r),this.offset=new Float32Array(r*2),this.phase=Float32Array.from({length:r},()=>this.rand()*Fk),this.setHole(n)}setHole(e){this.mask.length!==this.cols*this.rows&&(this.mask=new Float32Array(this.cols*this.rows));for(let t=0;t<this.rows;t++)for(let n=0;n<this.cols;n++){let[r,i]=this.center(n,t),a=Math.hypot((r-e.cx)/e.rx,(i-e.cy)/e.ry);this.mask[t*this.cols+n]=(.3+.7*Ik(.75,1.5,a))*Ik(0,50,i)*Ik(0,50,this.h-i)}}setActivity(e){e!==this.activity&&(this.activity=e,this.waveIn=0)}setProgress(e){this.progress=Math.min(1,Math.max(0,e))}setPointer(e,t,n,r=0){this.pointer={x:e,y:t,down:n,speed:r}}clearPointer(){this.pointer=null}ripple(e,t,n){this.ripples.length>24&&this.ripples.shift(),this.ripples.push({x:e,y:t,r:0,t:0,life:1.2+n*.6,strength:n,speed:150+this.rand()*50,phase:this.rand()*Fk})}dissolve(e,t){this.ripple(e,t,1);let n=Math.hypot(Math.max(e,this.w-e),Math.max(t,this.h-t))*1.15;this.exit={x:e,y:t,t:0,reach:n,phase:this.rand()*Fk},this.done=!1}restore(){this.exit=null,this.done=!1,this.settled=!1,this.energy.fill(0),this.offset.fill(0),this.ripples=[],this.waves=[]}energyAt(e,t){return this.energy[t*this.cols+e]}offsetAt(e,t){let n=t*this.cols+e;return[this.offset[n*2],this.offset[n*2+1]]}center(e,t){return[this.ox+(e+.5)*30,this.oy+(t+.5)*30]}step(e){if(this.done)return!1;if(this.settled&&this.activity===`idle`&&!this.pointer&&!this.ripples.length&&!this.waves.length&&!this.exit&&this.waveIn>e)return this.waveIn-=e,!1;this.time+=e;let t=this.time,n=this.cols+this.rows*.6;if(this.waveIn-=e,this.waveIn<=0){if(this.activity===`loading`)this.waveIn=.9+this.rand()*.5,this.waves.push({front:-3,speed:14+this.rand()*6,dir:1,span:n,strength:.5+this.rand()*.2});else if(this.activity===`idle`){this.waveIn=3+this.rand()*4;let e=this.rand()<.5?1:-1;this.waves.push({front:e>0?-3:n+3,speed:7+this.rand()*4,dir:e,span:n,strength:.45})}else this.waveIn=1}let r=this.pointer;r?.down&&(this.dragIn-=e,this.dragIn<=0&&(this.dragIn=.12,this.ripple(r.x,r.y,.7)));let i=Math.exp(-e*Pk),a=Math.min(1,e*14),o=Math.min(1,e*9),s=r?jk+Math.min(80,r.speed*.08):0,c=r?.5+Math.min(.45,r.speed/2e3):0,l=this.activity===`download`?this.progress*this.rows:-1,{cols:u,rows:d,energy:f,offset:p}=this,m=0,h=0;for(let e=0;e<d;e++)for(let n=0;n<u;n++){let g=e*u+n,[_,v]=this.center(n,e),y=f[g]*i,b=0,x=0,S=0,C=.55+.45*Math.sin(n*1.7+e*2.3+t*.6),w=n+e*.6+.9*Math.sin(e*.45+t*.8)+.5*Math.sin(n*.21-t*1.1);for(let e of this.waves){let t=1-Math.abs(w-e.front)/1.5;t>0&&(b=Math.max(b,t*e.strength*C))}for(let e of this.ripples){let t=_-e.x,n=v-e.y,r=Math.hypot(t,n)||1;if(Math.abs(r-e.r)>Nk+.11*e.r)continue;let i=Math.atan2(n,t),a=e.r*(1+.07*Math.sin(5*i+e.phase)+.04*Math.sin(9*i-e.phase*2)),o=1-Math.abs(r-a)/Nk;if(o<=0)continue;let s=(1-e.t/e.life)**1.3;b=Math.max(b,o*.85*e.strength*s),x+=t/r*o*7*e.strength*s,S+=n/r*o*7*e.strength*s}if(r){let e=_-r.x,t=v-r.y,n=Math.hypot(e,t)||1;if(n<s&&(b=Math.max(b,(1-n/s)**1.4*c)),n<Mk){let i=(1-n/Mk)**2*(10+Math.min(10,r.speed/120));x+=e/n*i,S+=t/n*i}}let T=0;if(l>=0){let r=l-(d-1-e+.5+.35*Math.sin(n*.55+t*2.1)+.2*Math.sin(n*1.31-t*1.3));r>0&&(T=.16),r>-1&&r<1&&(b=Math.max(b,(1-Math.abs(r))*(.45+.35*Math.sin(t*3+this.phase[g]))))}f[g]=Math.max(T,b>y?y+(b-y)*a:y),p[g*2]+=(x-p[g*2])*o,p[g*2+1]+=(S-p[g*2+1])*o,m=Math.max(m,f[g]),h=Math.max(h,Math.abs(p[g*2]),Math.abs(p[g*2+1]))}return this.settled=m<.04&&h<.05,this.waves=this.waves.filter(t=>(t.front+=t.dir*t.speed*e,t.front>=-4&&t.front<=t.span+4)),this.ripples=this.ripples.filter(t=>(t.t+=e,t.r+=t.speed*e*(1-.35*t.t/t.life),t.t<t.life)),this.exit&&(this.exit.t+=e,this.exit.t>=1.1&&(this.exit=null,this.done=!0)),!0}draw(e,t){if(e.clearRect(0,0,this.w,this.h),this.done)return;let{cols:n,rows:r,energy:i,offset:a,mask:o}=this,s=t.dark?.17:.14;e.lineWidth=1;for(let c=0;c<r;c++)for(let r=0;r<n;r++){let l=c*n+r,[u,d]=this.center(r,c),f=u+a[l*2],p=d+a[l*2+1],m=i[l],h=o[l];if(m<.04){e.fillStyle=t.fg,e.globalAlpha=s*h,e.fillRect(f-1,p-1,2,2);continue}let g=2+m*19,_=Math.max(1,6-m*3);e.beginPath(),e.roundRect(f-g/2,p-g/2,g,g,_),e.fillStyle=t.accent,e.globalAlpha=(.12+m*.22)*h,e.fill(),e.strokeStyle=t.accent,e.globalAlpha=m*.5*h,e.stroke()}this.exit&&this.drawExit(e,t),e.globalAlpha=1}drawExit(e,t){let n=this.exit,r=Math.min(1,n.t/Ak),i=(1-(1-r)**3)*n.reach,a=new Path2D;for(let e=0;e<=180;e++){let t=e/180*Fk,r=i*(1+.06*Math.sin(3*t+n.phase+n.t*1.5)+.03*Math.sin(5*t-n.phase*1.7-n.t*2.2)),o=n.x+Math.cos(t)*r,s=n.y+Math.sin(t)*r;e?a.lineTo(o,s):a.moveTo(o,s)}a.closePath(),e.globalAlpha=1,e.globalCompositeOperation=`destination-out`,e.fill(a),e.globalCompositeOperation=`source-over`,e.strokeStyle=t.accent,e.lineWidth=1.4,e.globalAlpha=.55*(1-r)**.7,e.stroke(a)}},zk=90;function Bk(){let e=getComputedStyle(document.documentElement);return{fg:e.getPropertyValue(`--text-primary`).trim(),accent:e.getPropertyValue(`--accent-solid`).trim(),dark:document.documentElement.getAttribute(`data-theme`)===`dark`}}function Vk(e,t,n){let r=e.getBoundingClientRect();return r.width?{cx:r.left-t.left+r.width/2,cy:r.top-t.top+r.height/2,rx:r.width/2+n,ry:r.height/2+n+10}:null}function Hk({activity:e,progress:t=0,pulse:n,docked:r,contentRef:i,composerRef:a}){let o=(0,X.useRef)(null),s=(0,X.useRef)(null),c=(0,X.useRef)(null),l=(0,X.useRef)(()=>{}),u=(0,X.useRef)(()=>{}),f=(0,X.useRef)(r),p=(0,X.useRef)({value:n,at:0});f.current=r,(0,X.useEffect)(()=>{let e=o.current,t=e?.parentElement;if(!e||!t)return;let n=e.getContext(`2d`);if(!n){d.ui.warn(`New-chat background is off: the browser gave no 2D canvas context (often low graphics memory).`);return}c.current=t;let r=new Rk;s.current=r;let p=typeof window.matchMedia==`function`?window.matchMedia(kx):null,m=Bk(),h=0,g=0,_=!1,v=``,y={x:0,y:0,at:0,speed:0},b=()=>r.draw(n,m),x=(e,t=!1)=>{let n=f.current?a.current:i.current,r=(n&&Vk(n,e,f.current?24:40))??{cx:e.width/2,cy:e.height/2,rx:1,ry:1},o=`${Math.round(r.cx)},${Math.round(r.cy)},${Math.round(r.rx)},${Math.round(r.ry)}`;return t||o!==v?(v=o,r):null},S=()=>{let i=t.getBoundingClientRect();if(!i.width||!i.height)return;let a=Math.min(2,window.devicePixelRatio||1);e.width=Math.round(i.width*a),e.height=Math.round(i.height*a),n.setTransform(a,0,0,a,0,0),r.resize(i.width,i.height,x(i,!0)),b()},C=e=>{if(h=requestAnimationFrame(C),e-g<31.833333333333336)return;let n=Math.min(.1,(e-g)/1e3);g=e;let i=x(t.getBoundingClientRect());i&&r.setHole(i),e-y.at>80&&(y.speed*=.8),(r.step(n)||i)&&b(),r.cleared&&T()},w=()=>{_||document.hidden||p?.matches||r.cleared||(_=!0,g=performance.now(),h=requestAnimationFrame(C))},T=()=>{_=!1,cancelAnimationFrame(h)};l.current=w,u.current=()=>{let e=x(t.getBoundingClientRect());e&&r.setHole(e),_||b()};let E=()=>document.hidden?T():w(),D=()=>{T(),b(),w()},O=()=>{m=Bk(),b()},k=e=>{let n=t.getBoundingClientRect(),i=e.clientX-n.left,a=e.clientY-n.top,o=performance.now();if(y.at&&o>y.at){let e=Math.hypot(i-y.x,a-y.y)/((o-y.at)/1e3);y.speed+=(Math.min(4e3,e)-y.speed)*.35}Object.assign(y,{x:i,y:a,at:o});let s=e.target instanceof Element&&e.target.closest(`button, a, input, textarea, .composer`);r.setPointer(i,a,(e.buttons&1)==1&&!s,y.speed)},A=()=>{y.at=0,y.speed=0,r.clearPointer()},j=typeof ResizeObserver>`u`?null:new ResizeObserver(S);j?.observe(t,{box:`border-box`});let M=new MutationObserver(O);return M.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`,`data-palette`,`style`]}),document.addEventListener(`visibilitychange`,E),p?.addEventListener(`change`,D),t.addEventListener(`pointermove`,k),t.addEventListener(`pointerleave`,A),S(),w(),()=>{T(),j?.disconnect(),M.disconnect(),document.removeEventListener(`visibilitychange`,E),p?.removeEventListener(`change`,D),t.removeEventListener(`pointermove`,k),t.removeEventListener(`pointerleave`,A),s.current=null,l.current=()=>{},u.current=()=>{}}},[i,a]);let m=(0,X.useCallback)(()=>{let e=c.current,t=a.current;if(!e||!t)return null;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return[r.left-n.left+r.width/2,r.top-n.top+r.height/2]},[a]);return(0,X.useEffect)(()=>{let t=s.current;if(t){if(t.setActivity(e),e===`sending`){let e=m();e&&t.dissolve(...e)}else t.dissolving&&(t.restore(),l.current())}},[e,m]),(0,X.useEffect)(()=>{s.current?.setProgress(t)},[t]),(0,X.useEffect)(()=>{u.current()},[r]),(0,X.useEffect)(()=>{let e=p.current;if(n===e.value)return;let t=performance.now();if(e.value=n,t-e.at<zk)return;e.at=t;let r=m();r&&s.current?.ripple(...r,.45)},[n,m]),P(`canvas`,{ref:o,className:`npu-backdrop`,"aria-hidden":`true`})}async function Uk(e,t,n){let r=`${L()}${t}`,i={};e!==`GET`&&(i[`X-Gaia-UI`]=`1`),n!==void 0&&(i[`Content-Type`]=`application/json`);let a={method:e,headers:Object.keys(i).length>0?i:void 0,body:n===void 0?void 0:JSON.stringify(n)},o=await fetch(r,a);if(!o.ok){let e=await o.text().catch(()=>``),t=e;try{t=JSON.parse(e).detail||e}catch{}throw Error(t||`Memory API error (HTTP ${o.status})`)}if(o.status!==204&&(o.headers.get(`content-type`)||``).includes(`application/json`))return o.json()}function Wk(e){let t=[];for(let[n,r]of Object.entries(e))if(r!=null&&r!==``){if(Array.isArray(r))for(let e of r)t.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(e))}`);else t.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(r))}`)}return t.length?`?${t.join(`&`)}`:``}function Gk(){return Uk(`GET`,`/memory/stats`)}function Kk(e=30){return Uk(`GET`,`/memory/activity?days=${e}`)}function qk(e={}){return Uk(`GET`,`/memory/knowledge${Wk(e)}`)}function Jk(e){return Uk(`POST`,`/memory/knowledge`,e)}function Yk(e,t){return Uk(`PUT`,`/memory/knowledge/${encodeURIComponent(e)}`,t)}function Xk(e){return Uk(`DELETE`,`/memory/knowledge/${encodeURIComponent(e)}`)}function Zk(){return Uk(`GET`,`/memory/entities`)}function Qk(){return Uk(`GET`,`/memory/tools`)}function $k(e=20){return Uk(`GET`,`/memory/conversations?limit=${e}`)}function eA(e,t=20){return Uk(`GET`,`/memory/conversations/search?query=${encodeURIComponent(e)}&limit=${t}`)}function tA(e){return Uk(`GET`,`/memory/conversations/${encodeURIComponent(e)}`)}function nA(e=7){return Uk(`GET`,`/memory/upcoming?days=${e}`)}function rA(){return Uk(`GET`,`/memory/embedding-coverage`)}function iA(){return Uk(`POST`,`/memory/consolidate`)}function aA(){return Uk(`POST`,`/memory/rebuild-embeddings`)}function oA(){return Uk(`POST`,`/memory/reconcile`)}function sA(){return Uk(`POST`,`/memory/rebuild-fts`)}function cA(){return Uk(`POST`,`/memory/refresh-system-context`)}function lA(){return new EventSource(`${L()}/memory/stream-discovery`)}function uA(e){return new EventSource(`${L()}/memory/stream-inference?include_browser=${e}`)}function dA(e){return Uk(`POST`,`/memory/commit-discovery`,{items:e})}function fA(e){return Uk(`POST`,`/memory/commit-inference`,{insights:e})}function pA(){return Uk(`GET`,`/memory/settings`)}function mA(e){return Uk(`PUT`,`/memory/settings`,e)}function hA(){return Uk(`DELETE`,`/memory/all`)}function gA(){return Uk(`POST`,`/memory/reinitialize`)}function _A(){return Uk(`GET`,`/goals/stats`)}function vA(e={}){return Uk(`GET`,`/goals${Wk(e)}`)}function yA(e){return Uk(`POST`,`/goals`,e)}function bA(e){return Uk(`PUT`,`/goals/${encodeURIComponent(e)}/approve`)}function xA(e){return Uk(`PUT`,`/goals/${encodeURIComponent(e)}/reject`)}function SA(e){return Uk(`PUT`,`/goals/${encodeURIComponent(e)}/cancel`)}function CA(e){return Uk(`DELETE`,`/goals/${encodeURIComponent(e)}`)}function wA({disabled:e}){let t=T(),n=k(e=>e.draftPrivate),r=k(e=>e.setDraftPrivate),i=k(e=>e.settingsSection!==null),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{if(i)return;let e=!1;return pA().then(t=>{e||(o(t.memory_enabled),c(!1))}).catch(t=>{e||(d.ui.error(`Could not read the memory setting for the Private chip`,t),o(null),c(!0))}),()=>{e=!0}},[i]),(0,X.useEffect)(()=>{a===!1&&n&&r(!1)},[a,n,r]),a===!1?V(`button`,{type:`button`,className:`composer-chip composer-chip-memory is-unavailable`,disabled:!0,"aria-label":t(`composer.memoryOff`),title:t(`composer.memoryOffTitle`),children:[P(ei,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:t(`composer.memoryOff`)})]}):V(`button`,{type:`button`,className:`composer-chip composer-chip-memory${n?` is-on`:``}`,onClick:()=>r(!n),disabled:e,"aria-label":t(n?`composer.privateOff`:`composer.privateOn`),title:t(n?`composer.privateOffTitle`:s?`composer.memoryUnknownTitle`:`composer.privateOnTitle`),children:[P(n?ei:ni,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:t(n?`composer.private`:s?`composer.memoryUnknown`:`composer.memoryOn`)})]})}var TA=1e3;function EA(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=!1,n,r=a=>{e||(a.state===`warming`?(t({seconds:Math.floor(a.elapsed_seconds??0),model:a.model??null,device:a.device??null}),n=setTimeout(()=>{Ht().then(r,i)},TA)):t(null))},i=n=>{e||(d.system.warn(`Warm-up status unavailable`,n),t(null))};return pe().then(r,i),()=>{e=!0,n&&clearTimeout(n)}},[]),e}function DA(e){return e===`gpu`?`your GPU`:e===`npu`?`your NPU`:e===`cpu`?`the CPU`:null}function OA(e){return e<1?`under 1 GB`:`${e.toFixed(1)} GB`}var kA=15e3;function AA(e=new Date,t=z){let n=e.getHours();return t(`newChat.greeting.${n<5?`evening`:n<12?`morning`:n<18?`afternoon`:`evening`}`)}var jA={gpu:`device.gpu`,npu:`device.npu`,cpu:`device.cpu`};function MA({seconds:e,model:t,device:n},r=z){if(!t)return r(`newChat.warmup.ready`,{s:e});let i=ds(t),a=n?jA[n]:void 0;if(a)return r(`newChat.warmup.loadingOn`,{model:i,where:g(a),s:e});let o=DA(n);return o?r(`newChat.warmup.loadingOn`,{model:i,where:o,s:e}):r(`newChat.warmup.loading`,{model:i,s:e})}function NA({detail:e,onRetry:t}){let n=T(),[r,i]=(0,X.useState)(!1);return V(`div`,{className:`new-chat-note`,children:[V(`p`,{children:[n(`newChat.assistantUnavailable`),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:t,children:n(`newChat.tryAgain`)})]}),V(`button`,{type:`button`,className:`new-chat-details`,"aria-expanded":r,onClick:()=>i(e=>!e),children:[P(br,{size:12,className:r?`is-open`:``,"aria-hidden":`true`}),` `,n(`newChat.details`)]}),r&&P(`pre`,{className:`new-chat-details-text`,children:e})]})}function PA(){let{documents:e,draftDocumentIds:t,addDraftDocuments:n}=k.getState();n(e.filter(e=>e.indexing_status===`complete`&&!t.includes(e.id)).map(e=>e.id))}function FA(){let e=T(),t=k(e=>e.documents),n=k(e=>e.draftDocumentIds),r=k(e=>e.removeDraftDocument),i=k(e=>e.setShowDocLibrary),a=t.filter(e=>n.includes(e.id)),o=t.filter(e=>e.indexing_status===`complete`&&!n.includes(e.id));if(!a.length&&!o.length)return null;let s=o.length;return V(`div`,{className:`new-chat-docs`,children:[a.length>0&&P(`ul`,{className:`new-chat-doc-list`,"aria-label":e(`newChat.docs.forChat`),children:a.map(t=>V(`li`,{className:`new-chat-doc`,children:[P(gi,{size:12,"aria-hidden":`true`}),P(`span`,{dir:`auto`,children:t.filename}),P(`button`,{type:`button`,className:`new-chat-doc-remove`,onClick:()=>r(t.id),"aria-label":e(`newChat.docs.dontAttach`,{name:t.filename}),children:P(Y,{size:12,"aria-hidden":`true`})})]},t.id))}),s>0&&V(`p`,{className:`new-chat-note`,children:[a.length?e.plural(`newChat.docs.more`,s):e.plural(`newChat.docs.library`,s),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:PA,children:s===1?e(`newChat.docs.attachIt`):e(`newChat.docs.attachAll`,{n:s})}),s>1&&V(D.Fragment,{children:[` · `,P(`button`,{type:`button`,className:`link-btn`,onClick:()=>i(!0),children:e(`newChat.docs.choose`)})]})]})]})}function IA({error:e}){let t=T(),n=k(e=>e.openSettings);return V(`div`,{className:`new-chat-setup-failed`,role:`alert`,children:[P(`p`,{className:`new-chat-setup-failed-title`,children:t(`newChat.setupFailed.title`)}),P(`p`,{className:`new-chat-setup-failed-error`,children:e}),V(`p`,{children:[t(`newChat.setupFailed.hint`),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:()=>n(`model`),children:t(`newChat.setupFailed.choose`)})]})]})}function LA({onSend:e,initialText:t=``,focusRequest:n=0}){let r=T(),i=k(e=>Hw(e.systemStatus)),a=k(e=>e.systemStatus?.download_progress??null),o=k(e=>e.systemStatus?.model_loaded?null:e.systemStatus?.setup_error??null),s=cs(e=>!!e.active?.remote),[c,l]=xk(Je,t),[u,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),y=(0,X.useRef)(null),b=(0,X.useRef)(null),x=(0,X.useRef)(null),S=YO(),C=EA();ls();let w=(0,X.useRef)(!0),E=(0,X.useCallback)((e=!1)=>{e||v(null),lt().then(e=>{w.current&&(g(e),v(e.skills_error??null))}).catch(e=>{d.api.warn(`New-chat start screen unavailable`,e),w.current&&v(Ix(e))})},[]);(0,X.useEffect)(()=>(w.current=!0,E(),()=>{w.current=!1}),[E]),(0,X.useEffect)(()=>{Dt().then(e=>k.getState().setDocuments(e.documents||[])).catch(e=>d.api.warn(`Document library unavailable; not offering its documents`,e))},[]),(0,X.useEffect)(()=>{if(_)return gk(()=>E(!0),kA)},[_,E]);let O=(0,X.useRef)(!1),A=(0,X.useRef)([]),M=(0,X.useCallback)(async(t,n=``)=>{if(t){if(O.current)A.current.push(n||t),l(``);else{O.current=!0,m(!0),f(null),l(``);try{let n=await e(t);S.clear();let r=A.current.splice(0),i=k.getState().currentSessionId;if(r.length>0&&i){let e=(e,t)=>n===!1?[...e,{...j(t,`failed`),error:`The first message was not sent.`}]:ee(e,t,`queued`);k.getState().updateQueue(i,t=>r.reduce(e,t))}}catch(e){let r=A.current.splice(0);l([n||t,...r].join(`
|
|
75
|
+
`)))}else ut.length===0||yt||N||ne||Ft.current||Pe||It||At()||!gt.current&&!un||bT(e,dn,()=>Pt.current&&!At()&&!k.getState().isStreaming&&!Ut.current)}},[fn,ut,yt,un,N,ne,Pe,It,e,dn,At]);let pn=(0,X.useRef)(!1);(0,X.useEffect)(()=>{pn.current&&!fn&&zt(),pn.current=fn},[fn,zt]);let mn=(0,X.useCallback)(t=>{let n=ut.find(e=>e.id===t&&e.state===`queued`);n&&u&&(dt(e=>ae(e,t,`queued`,`sending`)),wn(e,n.text).then(()=>dt(e=>ae(e,t,`sending`,`delivered`))).catch(e=>{d.chat.info(`Follow-up not taken by the running reply; it stays queued: ${e instanceof Error?e.message:e}`),dt(e=>a(e,t))}))},[ut,u,e,dt]),hn=(0,X.useCallback)(()=>{for(let e=r.length-1;e>=0;e--)if(r[e].role===`user`){ln(r[e]);return}},[r,ln]),gn=(0,X.useCallback)(e=>{let t=r.indexOf(e);for(let n=t-1;n>=0;n--)if(r[n].role===`user`){ln(r[n],e);return}},[r,ln]),_n=()=>{he(G?.title||``),pe(!0)},vn=async()=>{let t=me.trim().slice(0,200).trim();t&&me!==G?.title&&t!==G?.title&&(await Se(e,{title:t,title_is_custom:!0}),l(e,{title:t})),pe(!1)},yn=(0,X.useCallback)(async()=>{if(e)try{let t=await st(e);l(e,{private:t.private})}catch(e){d.ui.warn(`Failed to toggle private mode`,e)}},[e,l]),bn=(0,X.useCallback)(async(t,n)=>{t.stopPropagation();let r=O.find(e=>e.id===n);d.doc.info(`Detaching document from session: ${r?.filename||n}`);try{await On(e,n);let t=(k.getState().sessions.find(t=>t.id===e)?.document_ids??[]).filter(e=>e!==n);l(e,{document_ids:t}),t.length<=3&&Ce(!1),d.doc.info(`Detached document from session: ${r?.filename||n}`)}catch(e){d.doc.error(`Failed to detach document: ${r?.filename||n}`,e)}},[O,e,l]),xn=(0,X.useCallback)(async t=>{if(t.preventDefault(),t.stopPropagation(),_e(!1),t.dataTransfer.files.length===0)return;let n=Array.from(t.dataTransfer.files),r=n.filter(e=>OT(e.name));r.length>0&&be.addFiles(r);let i=n.filter(e=>!OT(e.name));i.length!==0&&await Go(`embedding`)&&await hk(e,i)},[e,be]),Sn=e=>{e.preventDefault(),e.stopPropagation(),_e(!0)},Tn=e=>{e.preventDefault(),e.stopPropagation(),_e(!1)},En=r.length>0?r[r.length-1]:void 0,Dn=!u&&!N&&En?.role===`assistant`&&wb(En.content),An=(0,X.useMemo)(()=>{let e=new Map,t;for(let n of r)if(n.role===`user`&&n.created_at)t=new Date(n.created_at).getTime();else if(n.role===`assistant`&&n.created_at&&t!==void 0){let r=new Date(n.created_at).getTime();r>t&&e.set(n.id,r-t),t=void 0}return e},[r]),jn=Pe?`This chat used the retired "${Pe}" agent and is read-only. Start a new chat.`:Hw(L)?Rc:null;return V(`main`,{className:`task-view ${ge?`drag-active`:``}`,style:{"--session-panel-w":`${Jt}px`},onDrop:xn,onDragOver:Sn,onDragLeave:Tn,"aria-label":G?.title||`Chat`,children:[V(`header`,{className:`task-header`,children:[P(`div`,{className:`task-header-left`,children:fe?P(`input`,{className:`title-edit`,value:me,maxLength:200,onChange:e=>he(e.target.value),onBlur:vn,onKeyDown:e=>{e.key===`Enter`&&vn(),e.key===`Escape`&&(e.preventDefault(),pe(!1))},...Ao,autoFocus:!0,"aria-label":`Chat title`,dir:`auto`}):V(`button`,{type:`button`,className:`task-title`,onClick:_n,title:t(`row.rename`),children:[P(`span`,{children:G?.title||t(`sidebar.newChat`)}),P(Ta,{size:12,"aria-hidden":`true`,className:`task-title-edit`})]})}),V(`div`,{className:`task-header-right`,children:[P(`button`,{ref:Qt,className:`btn-icon-sm task-header-resources`,onClick:()=>Zt(!Xt),"aria-pressed":Xt,"aria-label":t(`resources.toggle`),title:t(Xt?`resources.hide`:`resources.show`),children:P(Hn,{size:15,"aria-hidden":`true`})}),P(wO,{isPrivate:!!G?.private,onToggle:yn}),P(`button`,{className:`btn-icon-sm`,onClick:()=>M(!0),title:`Browse files on this PC`,"aria-label":`Browse files on this PC`,children:P(wi,{size:15})}),P(`button`,{className:`btn-icon-sm`,onClick:je,title:`Export as Markdown`,"aria-label":`Export chat`,children:P(Jr,{size:15})}),P(CO,{messages:r,busy:u})]})]}),Xt&&P(HO,{onClose:$t}),le.length>0&&(()=>{let e=[...le].sort((e,t)=>{let n=e.last_accessed_at||e.indexed_at||``;return(t.last_accessed_at||t.indexed_at||``).localeCompare(n)}),t=xe?e:e.slice(0,3),n=e.length-3;return V(`div`,{className:`doc-context-bar${xe?` doc-context-expanded`:``}`,"aria-label":`${le.length} indexed document${le.length===1?``:`s`}`,children:[P(Or,{size:12,className:`doc-context-icon`,"aria-hidden":`true`}),V(`button`,{type:`button`,className:`doc-context-label`,onClick:()=>j(!0),title:`Manage documents`,children:[le.length,` indexed`]}),V(`div`,{className:`doc-context-pills${xe?` doc-context-pills-expanded`:``}`,children:[t.map(e=>V(`span`,{className:`doc-pill`,title:e.filepath||e.filename,children:[P(gi,{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=>bn(t,e.id),"aria-label":`Remove ${e.filename} from this chat`,children:P(Y,{size:10})})]},e.id)),!xe&&n>0&&V(`button`,{className:`doc-pill-more`,onClick:e=>{e.stopPropagation(),Ce(!0)},children:[`+`,n,` more`]}),xe&&n>0&&P(`button`,{className:`doc-pill-collapse`,onClick:e=>{e.stopPropagation(),Ce(!1)},children:`show less`})]})]})})(),P(`div`,{className:`messages-scroll`,ref:Ge,...kt,children:V(`div`,{className:`messages-column`,children:[N&&P(`div`,{className:`skeleton-messages`,"aria-label":`Loading messages`,children:[0,1,2].map(e=>P(`div`,{className:`skeleton-msg`,children:V(`div`,{className:`skeleton-lines`,children:[P(`div`,{className:`skeleton-line`}),P(`div`,{className:`skeleton-line`}),e!==2&&P(`div`,{className:`skeleton-line`})]})},e))}),r.map((e,t)=>{if(Fe&&e.role===`assistant`&&t===r.length-1)return null;let n=e.role===`assistant`?e.historyNotice??Dk.get(e.id):void 0,i=e.role===`assistant`&&HC(e.content,e.stopState)===`interrupted`,a=(e.failed===!0||i)&&!fn&&!Pe&&!Fe&&t===r.length-1,o=!a&&!fn&&!Vt&&!Pe&&!Fe&&e.role===`assistant`&&t===r.length-1&&!e.stopState&&!e.failed&&!xC(e.content),s=e.stats?.seconds==null?An.get(e.id):e.stats.seconds*1e3;return V(`div`,{className:we===e.id?`msg-deleting`:void 0,"data-message-id":e.id,"data-role":e.role,children:[n&&P(Ok,{text:n}),e.libraryNotices&&e.libraryNotices.length>0&&P(kk,{notices:e.libraryNotices}),P(UC,{message:e,agentSteps:e.role===`assistant`?e.agentSteps:void 0,onDelete:fn?void 0:sn,onResend:!fn&&e.role===`user`&&!Pe?ln:void 0,extraActions:o?P(eD,{answeredBy:e.stats?.model??G?.effective_model,onPick:t=>Wt(e,t)}):void 0,onTryAgain:a?()=>gn(e):void 0,latencyMs:s}),e.failure===`model_server_down`&&t===r.length-1&&!fn&&P(bk,{}),Vt?.messageId===e.id&&P(rD,{original:e,originalModel:e.stats?.model??G?.effective_model,originalLatencyMs:s,state:Vt.state,keeping:Vt.keeping,onKeep:e=>{Gt(e)},onClose:Kt})]},e.id)}),(u||Fe)&&Le&&P(Ok,{text:Le}),u&&P(Lw,{}),(u||Fe)&&P(`div`,{className:`streaming-bubble ${Fe?`stream-ending`:`stream-active`}`,children:P(UC,{message:{id:-1,session_id:e,role:`assistant`,content:(u?f:ze.current)||``,created_at:``,rag_sources:null},isStreaming:u,agentSteps:u?g:Be.current,agentStepsActive:u&&g.some(e=>e.active),cards:u?C:He.current,liveStatus:u?oe:null,toolStatus:u?H:null,awaitingUser:u&&(U||se||W)})}),P(`div`,{ref:We})]})}),P(SO,{sessionId:e,messages:r,busy:fn,onUsage:Bt,onJumpToMessage:en}),ve&&P(`button`,{className:`scroll-bottom-btn`,onClick:tn,title:`Scroll to bottom`,"aria-label":`Scroll to bottom`,children:P(Kn,{size:16})}),ge&&V(`div`,{className:`drag-overlay`,children:[P(ho,{size:32,strokeWidth:1.5,"aria-hidden":`true`}),P(`span`,{children:`Drop files to index them for this chat`})]}),Ee&&V(`div`,{className:`toast policy-alert-toast`,role:`alert`,children:[V(`span`,{children:[`Blocked: `,Ee.tool,` is restricted by policy.`]}),Ee.receiptId?P(`button`,{type:`button`,className:`policy-alert-toast-link`,onClick:()=>{let e=Ee.receiptId;e&&(te(`policy_alert`),B(!0),Ae(e))},children:`View receipt`}):P(`span`,{className:`policy-alert-toast-missing`,children:`Receipt unavailable`})]}),P(`div`,{className:`input-area`,children:V(`div`,{className:`input-column`,children:[P(WO,{message:Me,onDismiss:Ne}),Dn&&En&&P(UT,{content:En.content,onRetry:hn}),P(fy,{sessionId:e}),P(YE,{usage:Lt}),P(UO,{sessionId:e}),ne&&It&&P(`ul`,{className:`queued-messages`,"aria-label":t(`composer.heldLabel`),"aria-live":`polite`,children:V(`li`,{className:`queued-message is-queued`,children:[P(Pr,{size:12,"aria-hidden":`true`}),P(`span`,{className:`queued-message-text`,title:ne.text,children:ne.text}),P(`span`,{className:`queued-message-state`,children:t(`composer.heldUntilStarted`)})]})}),P(TE,{items:ut,onRemove:e=>dt(t=>ie(t,e)),onRetry:e=>dt(t=>ae(t,e,`failed`,`queued`)),onSteer:u&&!$e&&!pt?mn:void 0,replying:u,busyRetry:!!yt}),P(qT,{value:ue,onChange:de,onSubmit:()=>rn(),onStop:nn,streaming:u,stopping:$e,queueWhileStreaming:!0,disabledReason:jn,attachments:be,inputRef:Ke,placeholder:u?t(`composer.queueNext`):r.length===0?t(`composer.placeholder`):t(`composer.reply`),leftControls:P(SE,{sessionId:e,disabled:!!Pe}),rightControls:V(D.Fragment,{children:[P(JE,{usage:Lt,unavailable:Rt,sessionId:e,busy:fn,onUsage:Bt,onDetails:()=>Yt(`context`)}),P(QE,{sessionId:e,busy:fn}),P(_E,{sessionId:e,onOpen:()=>Yt(`environment`)}),P(aE,{})]})})]})})]})}var jk=1.1,Mk=60,Nk=110,Pk=24,Fk=2.4,Ik=Math.PI*2,Lk=(e,t,n)=>{let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)};function Rk(e){let t=e;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}var zk=class{cols=0;rows=0;w=0;h=0;ox=0;oy=0;time=0;energy=new Float32Array;offset=new Float32Array;mask=new Float32Array;phase=new Float32Array;waves=[];ripples=[];waveIn=1.5;dragIn=0;activity=`idle`;progress=0;pointer=null;exit=null;done=!1;settled=!1;rand;constructor(e=7){this.rand=Rk(e)}get cleared(){return this.done}get dissolving(){return this.exit!==null||this.done}resize(e,t,n){this.w=e,this.h=t,this.cols=Math.ceil(e/30),this.rows=Math.ceil(t/30),this.ox=(e-this.cols*30)/2,this.oy=(t-this.rows*30)/2;let r=this.cols*this.rows;this.energy=new Float32Array(r),this.offset=new Float32Array(r*2),this.phase=Float32Array.from({length:r},()=>this.rand()*Ik),this.setHole(n)}setHole(e){this.mask.length!==this.cols*this.rows&&(this.mask=new Float32Array(this.cols*this.rows));for(let t=0;t<this.rows;t++)for(let n=0;n<this.cols;n++){let[r,i]=this.center(n,t),a=Math.hypot((r-e.cx)/e.rx,(i-e.cy)/e.ry);this.mask[t*this.cols+n]=(.3+.7*Lk(.75,1.5,a))*Lk(0,50,i)*Lk(0,50,this.h-i)}}setActivity(e){e!==this.activity&&(this.activity=e,this.waveIn=0)}setProgress(e){this.progress=Math.min(1,Math.max(0,e))}setPointer(e,t,n,r=0){this.pointer={x:e,y:t,down:n,speed:r}}clearPointer(){this.pointer=null}ripple(e,t,n){this.ripples.length>24&&this.ripples.shift(),this.ripples.push({x:e,y:t,r:0,t:0,life:1.2+n*.6,strength:n,speed:150+this.rand()*50,phase:this.rand()*Ik})}dissolve(e,t){this.ripple(e,t,1);let n=Math.hypot(Math.max(e,this.w-e),Math.max(t,this.h-t))*1.15;this.exit={x:e,y:t,t:0,reach:n,phase:this.rand()*Ik},this.done=!1}restore(){this.exit=null,this.done=!1,this.settled=!1,this.energy.fill(0),this.offset.fill(0),this.ripples=[],this.waves=[]}energyAt(e,t){return this.energy[t*this.cols+e]}offsetAt(e,t){let n=t*this.cols+e;return[this.offset[n*2],this.offset[n*2+1]]}center(e,t){return[this.ox+(e+.5)*30,this.oy+(t+.5)*30]}step(e){if(this.done)return!1;if(this.settled&&this.activity===`idle`&&!this.pointer&&!this.ripples.length&&!this.waves.length&&!this.exit&&this.waveIn>e)return this.waveIn-=e,!1;this.time+=e;let t=this.time,n=this.cols+this.rows*.6;if(this.waveIn-=e,this.waveIn<=0){if(this.activity===`loading`)this.waveIn=.9+this.rand()*.5,this.waves.push({front:-3,speed:14+this.rand()*6,dir:1,span:n,strength:.5+this.rand()*.2});else if(this.activity===`idle`){this.waveIn=3+this.rand()*4;let e=this.rand()<.5?1:-1;this.waves.push({front:e>0?-3:n+3,speed:7+this.rand()*4,dir:e,span:n,strength:.45})}else this.waveIn=1}let r=this.pointer;r?.down&&(this.dragIn-=e,this.dragIn<=0&&(this.dragIn=.12,this.ripple(r.x,r.y,.7)));let i=Math.exp(-e*Fk),a=Math.min(1,e*14),o=Math.min(1,e*9),s=r?Mk+Math.min(80,r.speed*.08):0,c=r?.5+Math.min(.45,r.speed/2e3):0,l=this.activity===`download`?this.progress*this.rows:-1,{cols:u,rows:d,energy:f,offset:p}=this,m=0,h=0;for(let e=0;e<d;e++)for(let n=0;n<u;n++){let g=e*u+n,[_,v]=this.center(n,e),y=f[g]*i,b=0,x=0,S=0,C=.55+.45*Math.sin(n*1.7+e*2.3+t*.6),w=n+e*.6+.9*Math.sin(e*.45+t*.8)+.5*Math.sin(n*.21-t*1.1);for(let e of this.waves){let t=1-Math.abs(w-e.front)/1.5;t>0&&(b=Math.max(b,t*e.strength*C))}for(let e of this.ripples){let t=_-e.x,n=v-e.y,r=Math.hypot(t,n)||1;if(Math.abs(r-e.r)>Pk+.11*e.r)continue;let i=Math.atan2(n,t),a=e.r*(1+.07*Math.sin(5*i+e.phase)+.04*Math.sin(9*i-e.phase*2)),o=1-Math.abs(r-a)/Pk;if(o<=0)continue;let s=(1-e.t/e.life)**1.3;b=Math.max(b,o*.85*e.strength*s),x+=t/r*o*7*e.strength*s,S+=n/r*o*7*e.strength*s}if(r){let e=_-r.x,t=v-r.y,n=Math.hypot(e,t)||1;if(n<s&&(b=Math.max(b,(1-n/s)**1.4*c)),n<Nk){let i=(1-n/Nk)**2*(10+Math.min(10,r.speed/120));x+=e/n*i,S+=t/n*i}}let T=0;if(l>=0){let r=l-(d-1-e+.5+.35*Math.sin(n*.55+t*2.1)+.2*Math.sin(n*1.31-t*1.3));r>0&&(T=.16),r>-1&&r<1&&(b=Math.max(b,(1-Math.abs(r))*(.45+.35*Math.sin(t*3+this.phase[g]))))}f[g]=Math.max(T,b>y?y+(b-y)*a:y),p[g*2]+=(x-p[g*2])*o,p[g*2+1]+=(S-p[g*2+1])*o,m=Math.max(m,f[g]),h=Math.max(h,Math.abs(p[g*2]),Math.abs(p[g*2+1]))}return this.settled=m<.04&&h<.05,this.waves=this.waves.filter(t=>(t.front+=t.dir*t.speed*e,t.front>=-4&&t.front<=t.span+4)),this.ripples=this.ripples.filter(t=>(t.t+=e,t.r+=t.speed*e*(1-.35*t.t/t.life),t.t<t.life)),this.exit&&(this.exit.t+=e,this.exit.t>=1.1&&(this.exit=null,this.done=!0)),!0}draw(e,t){if(e.clearRect(0,0,this.w,this.h),this.done)return;let{cols:n,rows:r,energy:i,offset:a,mask:o}=this,s=t.dark?.17:.14;e.lineWidth=1;for(let c=0;c<r;c++)for(let r=0;r<n;r++){let l=c*n+r,[u,d]=this.center(r,c),f=u+a[l*2],p=d+a[l*2+1],m=i[l],h=o[l];if(m<.04){e.fillStyle=t.fg,e.globalAlpha=s*h,e.fillRect(f-1,p-1,2,2);continue}let g=2+m*19,_=Math.max(1,6-m*3);e.beginPath(),e.roundRect(f-g/2,p-g/2,g,g,_),e.fillStyle=t.accent,e.globalAlpha=(.12+m*.22)*h,e.fill(),e.strokeStyle=t.accent,e.globalAlpha=m*.5*h,e.stroke()}this.exit&&this.drawExit(e,t),e.globalAlpha=1}drawExit(e,t){let n=this.exit,r=Math.min(1,n.t/jk),i=(1-(1-r)**3)*n.reach,a=new Path2D;for(let e=0;e<=180;e++){let t=e/180*Ik,r=i*(1+.06*Math.sin(3*t+n.phase+n.t*1.5)+.03*Math.sin(5*t-n.phase*1.7-n.t*2.2)),o=n.x+Math.cos(t)*r,s=n.y+Math.sin(t)*r;e?a.lineTo(o,s):a.moveTo(o,s)}a.closePath(),e.globalAlpha=1,e.globalCompositeOperation=`destination-out`,e.fill(a),e.globalCompositeOperation=`source-over`,e.strokeStyle=t.accent,e.lineWidth=1.4,e.globalAlpha=.55*(1-r)**.7,e.stroke(a)}},Bk=90;function Vk(){let e=getComputedStyle(document.documentElement);return{fg:e.getPropertyValue(`--text-primary`).trim(),accent:e.getPropertyValue(`--accent-solid`).trim(),dark:document.documentElement.getAttribute(`data-theme`)===`dark`}}function Hk(e,t,n){let r=e.getBoundingClientRect();return r.width?{cx:r.left-t.left+r.width/2,cy:r.top-t.top+r.height/2,rx:r.width/2+n,ry:r.height/2+n+10}:null}function Uk({activity:e,progress:t=0,pulse:n,docked:r,contentRef:i,composerRef:a}){let o=(0,X.useRef)(null),s=(0,X.useRef)(null),c=(0,X.useRef)(null),l=(0,X.useRef)(()=>{}),u=(0,X.useRef)(()=>{}),f=(0,X.useRef)(r),p=(0,X.useRef)({value:n,at:0});f.current=r,(0,X.useEffect)(()=>{let e=o.current,t=e?.parentElement;if(!e||!t)return;let n=e.getContext(`2d`);if(!n){d.ui.warn(`New-chat background is off: the browser gave no 2D canvas context (often low graphics memory).`);return}c.current=t;let r=new zk;s.current=r;let p=typeof window.matchMedia==`function`?window.matchMedia(kx):null,m=Vk(),h=0,g=0,_=!1,v=``,y={x:0,y:0,at:0,speed:0},b=()=>r.draw(n,m),x=(e,t=!1)=>{let n=f.current?a.current:i.current,r=(n&&Hk(n,e,f.current?24:40))??{cx:e.width/2,cy:e.height/2,rx:1,ry:1},o=`${Math.round(r.cx)},${Math.round(r.cy)},${Math.round(r.rx)},${Math.round(r.ry)}`;return t||o!==v?(v=o,r):null},S=()=>{let i=t.getBoundingClientRect();if(!i.width||!i.height)return;let a=Math.min(2,window.devicePixelRatio||1);e.width=Math.round(i.width*a),e.height=Math.round(i.height*a),n.setTransform(a,0,0,a,0,0),r.resize(i.width,i.height,x(i,!0)),b()},C=e=>{if(h=requestAnimationFrame(C),e-g<31.833333333333336)return;let n=Math.min(.1,(e-g)/1e3);g=e;let i=x(t.getBoundingClientRect());i&&r.setHole(i),e-y.at>80&&(y.speed*=.8),(r.step(n)||i)&&b(),r.cleared&&T()},w=()=>{_||document.hidden||p?.matches||r.cleared||(_=!0,g=performance.now(),h=requestAnimationFrame(C))},T=()=>{_=!1,cancelAnimationFrame(h)};l.current=w,u.current=()=>{let e=x(t.getBoundingClientRect());e&&r.setHole(e),_||b()};let E=()=>document.hidden?T():w(),D=()=>{T(),b(),w()},O=()=>{m=Vk(),b()},k=e=>{let n=t.getBoundingClientRect(),i=e.clientX-n.left,a=e.clientY-n.top,o=performance.now();if(y.at&&o>y.at){let e=Math.hypot(i-y.x,a-y.y)/((o-y.at)/1e3);y.speed+=(Math.min(4e3,e)-y.speed)*.35}Object.assign(y,{x:i,y:a,at:o});let s=e.target instanceof Element&&e.target.closest(`button, a, input, textarea, .composer`);r.setPointer(i,a,(e.buttons&1)==1&&!s,y.speed)},A=()=>{y.at=0,y.speed=0,r.clearPointer()},j=typeof ResizeObserver>`u`?null:new ResizeObserver(S);j?.observe(t,{box:`border-box`});let M=new MutationObserver(O);return M.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`,`data-palette`,`style`]}),document.addEventListener(`visibilitychange`,E),p?.addEventListener(`change`,D),t.addEventListener(`pointermove`,k),t.addEventListener(`pointerleave`,A),S(),w(),()=>{T(),j?.disconnect(),M.disconnect(),document.removeEventListener(`visibilitychange`,E),p?.removeEventListener(`change`,D),t.removeEventListener(`pointermove`,k),t.removeEventListener(`pointerleave`,A),s.current=null,l.current=()=>{},u.current=()=>{}}},[i,a]);let m=(0,X.useCallback)(()=>{let e=c.current,t=a.current;if(!e||!t)return null;let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return[r.left-n.left+r.width/2,r.top-n.top+r.height/2]},[a]);return(0,X.useEffect)(()=>{let t=s.current;if(t){if(t.setActivity(e),e===`sending`){let e=m();e&&t.dissolve(...e)}else t.dissolving&&(t.restore(),l.current())}},[e,m]),(0,X.useEffect)(()=>{s.current?.setProgress(t)},[t]),(0,X.useEffect)(()=>{u.current()},[r]),(0,X.useEffect)(()=>{let e=p.current;if(n===e.value)return;let t=performance.now();if(e.value=n,t-e.at<Bk)return;e.at=t;let r=m();r&&s.current?.ripple(...r,.45)},[n,m]),P(`canvas`,{ref:o,className:`npu-backdrop`,"aria-hidden":`true`})}async function Wk(e,t,n){let r=`${L()}${t}`,i={};e!==`GET`&&(i[`X-Gaia-UI`]=`1`),n!==void 0&&(i[`Content-Type`]=`application/json`);let a={method:e,headers:Object.keys(i).length>0?i:void 0,body:n===void 0?void 0:JSON.stringify(n)},o=await fetch(r,a);if(!o.ok){let e=await o.text().catch(()=>``),t=e;try{t=JSON.parse(e).detail||e}catch{}throw Error(t||`Memory API error (HTTP ${o.status})`)}if(o.status!==204&&(o.headers.get(`content-type`)||``).includes(`application/json`))return o.json()}function Gk(e){let t=[];for(let[n,r]of Object.entries(e))if(r!=null&&r!==``){if(Array.isArray(r))for(let e of r)t.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(e))}`);else t.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(r))}`)}return t.length?`?${t.join(`&`)}`:``}function Kk(){return Wk(`GET`,`/memory/stats`)}function qk(e=30){return Wk(`GET`,`/memory/activity?days=${e}`)}function Jk(e={}){return Wk(`GET`,`/memory/knowledge${Gk(e)}`)}function Yk(e){return Wk(`POST`,`/memory/knowledge`,e)}function Xk(e,t){return Wk(`PUT`,`/memory/knowledge/${encodeURIComponent(e)}`,t)}function Zk(e){return Wk(`DELETE`,`/memory/knowledge/${encodeURIComponent(e)}`)}function Qk(){return Wk(`GET`,`/memory/entities`)}function $k(){return Wk(`GET`,`/memory/tools`)}function eA(e=20){return Wk(`GET`,`/memory/conversations?limit=${e}`)}function tA(e,t=20){return Wk(`GET`,`/memory/conversations/search?query=${encodeURIComponent(e)}&limit=${t}`)}function nA(e){return Wk(`GET`,`/memory/conversations/${encodeURIComponent(e)}`)}function rA(e=7){return Wk(`GET`,`/memory/upcoming?days=${e}`)}function iA(){return Wk(`GET`,`/memory/embedding-coverage`)}function aA(){return Wk(`POST`,`/memory/consolidate`)}function oA(){return Wk(`POST`,`/memory/rebuild-embeddings`)}function sA(){return Wk(`POST`,`/memory/reconcile`)}function cA(){return Wk(`POST`,`/memory/rebuild-fts`)}function lA(){return Wk(`POST`,`/memory/refresh-system-context`)}function uA(){return new EventSource(`${L()}/memory/stream-discovery`)}function dA(e){return new EventSource(`${L()}/memory/stream-inference?include_browser=${e}`)}function fA(e){return Wk(`POST`,`/memory/commit-discovery`,{items:e})}function pA(e){return Wk(`POST`,`/memory/commit-inference`,{insights:e})}function mA(){return Wk(`GET`,`/memory/settings`)}function hA(e){return Wk(`PUT`,`/memory/settings`,e)}function gA(){return Wk(`DELETE`,`/memory/all`)}function _A(){return Wk(`POST`,`/memory/reinitialize`)}function vA(){return Wk(`GET`,`/goals/stats`)}function yA(e={}){return Wk(`GET`,`/goals${Gk(e)}`)}function bA(e){return Wk(`POST`,`/goals`,e)}function xA(e){return Wk(`PUT`,`/goals/${encodeURIComponent(e)}/approve`)}function SA(e){return Wk(`PUT`,`/goals/${encodeURIComponent(e)}/reject`)}function CA(e){return Wk(`PUT`,`/goals/${encodeURIComponent(e)}/cancel`)}function wA(e){return Wk(`DELETE`,`/goals/${encodeURIComponent(e)}`)}function TA({disabled:e}){let t=T(),n=k(e=>e.draftPrivate),r=k(e=>e.setDraftPrivate),i=k(e=>e.settingsSection!==null),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1);return(0,X.useEffect)(()=>{if(i)return;let e=!1;return mA().then(t=>{e||(o(t.memory_enabled),c(!1))}).catch(t=>{e||(d.ui.error(`Could not read the memory setting for the Private chip`,t),o(null),c(!0))}),()=>{e=!0}},[i]),(0,X.useEffect)(()=>{a===!1&&n&&r(!1)},[a,n,r]),a===!1?V(`button`,{type:`button`,className:`composer-chip composer-chip-memory is-unavailable`,disabled:!0,"aria-label":t(`composer.memoryOff`),title:t(`composer.memoryOffTitle`),children:[P(ei,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:t(`composer.memoryOff`)})]}):V(`button`,{type:`button`,className:`composer-chip composer-chip-memory${n?` is-on`:``}`,onClick:()=>r(!n),disabled:e,"aria-label":t(n?`composer.privateOff`:`composer.privateOn`),title:t(n?`composer.privateOffTitle`:s?`composer.memoryUnknownTitle`:`composer.privateOnTitle`),children:[P(n?ei:ni,{size:13,"aria-hidden":`true`}),P(`span`,{className:`composer-chip-label`,dir:`auto`,children:t(n?`composer.private`:s?`composer.memoryUnknown`:`composer.memoryOn`)})]})}var EA=1e3;function DA(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=!1,n,r=a=>{e||(a.state===`warming`?(t({seconds:Math.floor(a.elapsed_seconds??0),model:a.model??null,device:a.device??null}),n=setTimeout(()=>{Ht().then(r,i)},EA)):t(null))},i=n=>{e||(d.system.warn(`Warm-up status unavailable`,n),t(null))};return pe().then(r,i),()=>{e=!0,n&&clearTimeout(n)}},[]),e}function OA(e){return e===`gpu`?`your GPU`:e===`npu`?`your NPU`:e===`cpu`?`the CPU`:null}function kA(e){return e<1?`under 1 GB`:`${e.toFixed(1)} GB`}var AA=15e3;function jA(e=new Date,t=z){let n=e.getHours();return t(`newChat.greeting.${n<5?`evening`:n<12?`morning`:n<18?`afternoon`:`evening`}`)}var MA={gpu:`device.gpu`,npu:`device.npu`,cpu:`device.cpu`};function NA({seconds:e,model:t,device:n},r=z){if(!t)return r(`newChat.warmup.ready`,{s:e});let i=ds(t),a=n?MA[n]:void 0;if(a)return r(`newChat.warmup.loadingOn`,{model:i,where:g(a),s:e});let o=OA(n);return o?r(`newChat.warmup.loadingOn`,{model:i,where:o,s:e}):r(`newChat.warmup.loading`,{model:i,s:e})}function PA({detail:e,onRetry:t}){let n=T(),[r,i]=(0,X.useState)(!1);return V(`div`,{className:`new-chat-note`,children:[V(`p`,{children:[n(`newChat.assistantUnavailable`),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:t,children:n(`newChat.tryAgain`)})]}),V(`button`,{type:`button`,className:`new-chat-details`,"aria-expanded":r,onClick:()=>i(e=>!e),children:[P(br,{size:12,className:r?`is-open`:``,"aria-hidden":`true`}),` `,n(`newChat.details`)]}),r&&P(`pre`,{className:`new-chat-details-text`,children:e})]})}function FA(){let{documents:e,draftDocumentIds:t,addDraftDocuments:n}=k.getState();n(e.filter(e=>e.indexing_status===`complete`&&!t.includes(e.id)).map(e=>e.id))}function IA(){let e=T(),t=k(e=>e.documents),n=k(e=>e.draftDocumentIds),r=k(e=>e.removeDraftDocument),i=k(e=>e.setShowDocLibrary),a=t.filter(e=>n.includes(e.id)),o=t.filter(e=>e.indexing_status===`complete`&&!n.includes(e.id));if(!a.length&&!o.length)return null;let s=o.length;return V(`div`,{className:`new-chat-docs`,children:[a.length>0&&P(`ul`,{className:`new-chat-doc-list`,"aria-label":e(`newChat.docs.forChat`),children:a.map(t=>V(`li`,{className:`new-chat-doc`,children:[P(gi,{size:12,"aria-hidden":`true`}),P(`span`,{dir:`auto`,children:t.filename}),P(`button`,{type:`button`,className:`new-chat-doc-remove`,onClick:()=>r(t.id),"aria-label":e(`newChat.docs.dontAttach`,{name:t.filename}),children:P(Y,{size:12,"aria-hidden":`true`})})]},t.id))}),s>0&&V(`p`,{className:`new-chat-note`,children:[a.length?e.plural(`newChat.docs.more`,s):e.plural(`newChat.docs.library`,s),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:FA,children:s===1?e(`newChat.docs.attachIt`):e(`newChat.docs.attachAll`,{n:s})}),s>1&&V(D.Fragment,{children:[` · `,P(`button`,{type:`button`,className:`link-btn`,onClick:()=>i(!0),children:e(`newChat.docs.choose`)})]})]})]})}function LA({error:e}){let t=T(),n=k(e=>e.openSettings);return V(`div`,{className:`new-chat-setup-failed`,role:`alert`,children:[P(`p`,{className:`new-chat-setup-failed-title`,children:t(`newChat.setupFailed.title`)}),P(`p`,{className:`new-chat-setup-failed-error`,children:e}),V(`p`,{children:[t(`newChat.setupFailed.hint`),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:()=>n(`model`),children:t(`newChat.setupFailed.choose`)})]})]})}function RA({onSend:e,initialText:t=``,focusRequest:n=0}){let r=T(),i=k(e=>Hw(e.systemStatus)),a=k(e=>e.systemStatus?.download_progress??null),o=k(e=>e.systemStatus?.model_loaded?null:e.systemStatus?.setup_error??null),s=cs(e=>!!e.active?.remote),[c,l]=xk(Je,t),[u,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(null),y=(0,X.useRef)(null),b=(0,X.useRef)(null),x=(0,X.useRef)(null),S=YO(),C=DA();ls();let w=(0,X.useRef)(!0),E=(0,X.useCallback)((e=!1)=>{e||v(null),lt().then(e=>{w.current&&(g(e),v(e.skills_error??null))}).catch(e=>{d.api.warn(`New-chat start screen unavailable`,e),w.current&&v(Ix(e))})},[]);(0,X.useEffect)(()=>(w.current=!0,E(),()=>{w.current=!1}),[E]),(0,X.useEffect)(()=>{Dt().then(e=>k.getState().setDocuments(e.documents||[])).catch(e=>d.api.warn(`Document library unavailable; not offering its documents`,e))},[]),(0,X.useEffect)(()=>{if(_)return gk(()=>E(!0),AA)},[_,E]);let O=(0,X.useRef)(!1),A=(0,X.useRef)([]),M=(0,X.useCallback)(async(t,n=``)=>{if(t){if(O.current)A.current.push(n||t),l(``);else{O.current=!0,m(!0),f(null),l(``);try{let n=await e(t);S.clear();let r=A.current.splice(0),i=k.getState().currentSessionId;if(r.length>0&&i){let e=(e,t)=>n===!1?[...e,{...j(t,`failed`),error:`The first message was not sent.`}]:ee(e,t,`queued`);k.getState().updateQueue(i,t=>r.reduce(e,t))}}catch(e){let r=A.current.splice(0);l([n||t,...r].join(`
|
|
76
76
|
|
|
77
|
-
`)),f(Ix(e))}finally{O.current=!1,m(!1)}}}},[S,e]),N=(0,X.useCallback)(()=>M(S.compose(c.trim()),c.trim()),[S,M,c]);(0,X.useEffect)(()=>{n&&y.current?.focus()},[n]);let F=c.length>0||p,I=(0,X.useRef)(null);(0,X.useLayoutEffect)(()=>{let e=b.current;if(!e)return;typeof e.getAnimations==`function`&&e.getAnimations().forEach(e=>e.cancel());let t=e.getBoundingClientRect().top,n=I.current;if(I.current={top:t,docked:F},!n||n.docked===F||jx()||typeof e.animate!=`function`)return;let r=getComputedStyle(document.documentElement).getPropertyValue(`--ease`).trim();if(!r)throw Error(`Motion token --ease is not set; check styles/index.css.`);e.animate([{transform:`translateY(${n.top-t}px)`},{transform:`none`}],{duration:Ax(`--duration-spring`),easing:r})});let L=a?.state===`starting`||a?.state===`downloading`,R=p?`sending`:L?`download`:i||C!==null?`loading`:`idle`,z=h?.working_folder;return V(`main`,{className:`new-chat${F?` is-docked`:``}`,"aria-label":r(`newChat.label`),children:[P(Hk,{activity:R,progress:(a?.percent??0)/100,pulse:c.length,docked:F,contentRef:b,composerRef:x}),V(`div`,{className:`new-chat-inner`,ref:b,children:[P(`h1`,{className:`new-chat-greeting`,"aria-hidden":F,children:AA(new Date,r)}),o&&!s&&P(IA,{error:o}),P(`div`,{ref:x,children:P(qT,{value:c,onChange:l,onSubmit:N,attachments:S,disabledReason:i?r(`composer.starting`):null,autoFocus:!0,inputRef:y,leftControls:V(D.Fragment,{children:[P(SE,{sessionId:null}),P(wA,{disabled:p})]}),rightControls:P(aE,{})})}),P(`div`,{className:`new-chat-meta`,children:z&&P(gE,{folder:z,disabled:i||p})}),P(FA,{}),C!==null&&!i&&P(`p`,{className:`new-chat-warmup`,role:`status`,children:MA(C,r)}),u&&P(`p`,{className:`new-chat-error`,role:`alert`,children:u}),_&&P(NA,{detail:_,onRetry:()=>E()})]})]})}var RA=1e3,zA=15,BA=5,VA=new Map;function HA(){let e=T(),t=Wo(e=>e.need),n=Wo(e=>e.settle),r=(0,X.useRef)(null),i=(0,X.useRef)(null),a=(0,X.useRef)(0),o=(0,X.useRef)(0),s=(0,X.useRef)(null);s.current=t;let[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(!1),g=(0,X.useCallback)(()=>{i.current&&clearInterval(i.current),i.current=null},[]);(0,X.useEffect)(()=>(l(null),d(!1),p(null),h(!1),g),[t,g]);let _=(0,X.useCallback)(()=>{g(),u&&t?.model&&G(t.model.id).catch(e=>console.warn(`[ModelNeededDialog] could not cancel the download`,e)),n(!1)},[u,t,n,g]);Io(!!t,_),sS(r,!!t);let v=(0,X.useCallback)(async r=>{if(!t?.model)return;let c=t,u=t.model.id,f=(VA.get(u)??0)+1;VA.set(u,f),p(null),d(!0),a.current=0,o.current=0;try{await Te(u,{acknowledgeLowDisk:r})}catch(e){if(s.current!==c)return;d(!1),p(e instanceof Error?e.message:String(e)),e instanceof yn&&e.body?.code===`low_disk`&&h(!0);return}s.current===c?(g(),i.current=setInterval(()=>{it().then(t=>{if(s.current!==c){g();return}o.current=0;let r=t.models?.find(e=>e.id===u);if(r)r.bytes_total>0&&l(Math.floor(r.bytes_done*100/r.bytes_total)),r.state===`ready`||r.state===`verifying`?(g(),n(!0)):(r.state===`failed`||r.state===`cancelled`)&&(g(),d(!1),p(r.error??e(`modelNeeded.failed`)));else{if(++a.current<zA)return;g(),d(!1),p(e(`modelNeeded.failed`))}}).catch(e=>{s.current===c?++o.current<BA||(g(),d(!1),p(e instanceof Error?e.message:String(e))):g()})},RA)):VA.get(u)===f&&G(u).catch(e=>console.warn(`[ModelNeededDialog] could not cancel the download`,e))},[t,n,g,e]);if(t?.off)return(0,eS.createPortal)(P(`div`,{className:`model-needed-overlay`,children:V(`div`,{ref:r,className:`model-needed`,role:`dialog`,"aria-modal":`true`,"aria-label":e(`modelNeeded.off.${t.off}.title`),children:[P(`h2`,{className:`model-needed-title`,children:e(`modelNeeded.off.${t.off}.title`)}),P(`p`,{className:`model-needed-from`,children:e(`modelNeeded.off.${t.off}.body`)}),V(`div`,{className:`model-needed-actions`,children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:_,children:e(`modelNeeded.notNow`)}),P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>n(!0),children:e(`modelNeeded.off.send`)})]})]})}),document.body);if(!t?.model)return null;let{model:y,job:b,disk_free_gb:x}=t,S=y.size_gb!=null&&x!=null&&y.size_gb>x,C=S||m;return(0,eS.createPortal)(P(`div`,{className:`model-needed-overlay`,children:V(`div`,{ref:r,className:`model-needed`,role:`dialog`,"aria-modal":`true`,"aria-label":e(`modelNeeded.dialog`),children:[P(`h2`,{className:`model-needed-title`,children:e(`modelNeeded.title.${b}`)}),V(`p`,{className:`model-needed-line`,children:[P(`bdi`,{children:y.name}),y.size_gb!=null&&V(D.Fragment,{children:[`, `,P(`bdi`,{dir:`ltr`,children:$(y.size_gb)})]}),x!=null&&V(D.Fragment,{children:[` · `,e(`modelNeeded.free`),` `,P(`bdi`,{dir:`ltr`,children:$(x)})]})]}),y.source&&V(`p`,{className:`model-needed-from`,children:[e(`setup.contents.from`),` `,P(`bdi`,{dir:`ltr`,children:y.source})]}),P(`p`,{className:`model-needed-from`,children:e(`modelNeeded.waits`)}),u&&(c==null?V(`p`,{role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,e(`modelNeeded.starting`)]}):P(`progress`,{className:`setup-progress`,max:100,value:c,"aria-label":e(`modelNeeded.dialog`)})),S&&!u&&P(`p`,{className:`setup-error`,role:`alert`,children:e(`modelNeeded.lowDisk`,{need:$(y.size_gb??0),free:$(x??0),freeUp:$((y.size_gb??0)-(x??0))})}),f&&P(`p`,{className:`setup-error`,role:`alert`,children:f}),V(`div`,{className:`model-needed-actions`,children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:_,children:e(`modelNeeded.notNow`)}),P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void v(C),disabled:u,children:e(C?`setup.confirm.downloadAnyway`:f?`setup.tryAgain`:`modelNeeded.download`)})]})]})}),document.body)}function UA(e){let t=e?.reason;return t===`needs_key`||t===`bad_key`}function WA({provider:e,limit:t}){let n=T(),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(null);if((0,X.useEffect)(()=>{i(null),o(null),We(e).then(i).catch(e=>o(e instanceof Error?e.message:String(e)))},[e]),a)return P(`p`,{className:`settings-error`,role:`alert`,children:n(`settings.price.loadFailed`,{reason:a})});if(!r)return V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,n(`settings.price.loading`)]});if(r.models.length===0)return V(`p`,{className:`settings-hint cloud-prices-note`,children:[n(`settings.price.unknownSentence`),` `,P(`bdi`,{children:r.note})]});let s=t?r.models.slice(0,t):r.models;return V(`div`,{className:`cloud-prices`,"aria-label":n(`settings.model.prices`),children:[P(`ul`,{className:`cloud-prices-list`,children:s.map(e=>V(`li`,{children:[V(`span`,{className:`cloud-prices-name`,children:[P(`bdi`,{children:e.name}),e.note&&V(`span`,{className:`cloud-prices-note`,children:[` · `,P(`bdi`,{children:e.note})]})]}),P(`span`,{className:`cloud-prices-price`,children:QT(e.price,n)})]},e.model))}),V(`span`,{className:`settings-hint`,children:[P(`bdi`,{children:r.source}),`. `,n(`settings.price.payProvider`)]})]})}function GA(){return zc(kx)}function KA(e,t=150){let n=GA(),[r,i]=(0,X.useState)(e),a=(0,X.useRef)(e);return(0,X.useEffect)(()=>{if(n||typeof requestAnimationFrame!=`function`){a.current=e,i(e);return}let r=a.current,o=performance.now(),s=0,c=n=>{let l=Math.min(1,(n-o)/t),u=1-(1-l)**3,d=r+(e-r)*u;a.current=d,i(d),l<1&&(s=requestAnimationFrame(c))};return s=requestAnimationFrame(c),()=>cancelAnimationFrame(s)},[e,t,n]),r}function qA(e,t){let[n,r]=(0,X.useState)(e);return(0,X.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function JA(){let[e,t]=(0,X.useState)(()=>typeof document>`u`||document.visibilityState!==`hidden`);return(0,X.useEffect)(()=>{let e=()=>t(document.visibilityState!==`hidden`);return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]),e}var YA=180;function XA({open:e,children:t}){let[n,r]=(0,X.useState)(e),[i,a]=(0,X.useState)(e),o=(0,X.useRef)(t);return e&&(o.current=t),(0,X.useEffect)(()=>{if(e){r(!0);let e=requestAnimationFrame(()=>a(!0));return()=>cancelAnimationFrame(e)}a(!1);let t=setTimeout(()=>r(!1),YA);return()=>clearTimeout(t)},[e]),n?P(`div`,{className:`reveal${i?` is-open`:``}`,"aria-hidden":!e||void 0,children:P(`div`,{className:`reveal-inner`,children:e?t:o.current})}):null}var ZA=e=>e?.catalog??[],QA=e=>e.roles.includes(`vision`),$A=e=>e.roles.includes(`embedding`),ej=e=>e.recipe===`flm`,tj=e=>e.fits===!1&&(e.fit_code===`npu`||e.fit_code===`backend`),nj=e=>e.support===null,rj=e=>e?.feature_tier!==`compact`;function ij(e,t){let n=e.find(e=>e.id===t.defaultChat);return n&&ej(n)||t.vision===`none`?null:t.vision?t.vision:n?.reads_images?n.id:e.find(e=>QA(e)&&e.gaia_model)?.id??null}function aj(e,t){let n=ij(t,e),r=new Set(e.ticked),i=new Set(e.unticked);for(let a of t)QA(a)&&a.id!==e.defaultChat&&(a.id===n?(r.add(a.id),i.delete(a.id)):a.downloaded||(r.delete(a.id),i.add(a.id)));return{...e,ticked:r,unticked:i}}function oj(e,t,n){let r=new Set(e.ticked),i=t.find(t=>t.id===e.defaultChat);i&&!i.downloaded&&r.delete(i.id);let a=t.find(e=>e.id===n);if(a?.downloaded||r.add(n),!rj(a))for(let e of t)e.roles.includes(`image_creation`)&&r.delete(e.id);return aj({...e,ticked:r,defaultChat:n,chatChosen:!0,vision:null},t)}function sj(e,t,n){return aj({...e,vision:n},t)}function cj(e,t){if(t.vision===`none`)return null;let n=ij(e,t),r=e.find(e=>e.id===t.defaultChat);return r&&ej(r)||n===(r?.reads_images?r.id:e.find(e=>QA(e)&&e.gaia_model)?.id)?null:n}function lj(e){return e.filter(e=>e.gaia_model&&(e.planned||e.recommended||e.downloaded||e.partial))}function uj(e){let t=new Set(lj(e).map(e=>e.id));return e.filter(e=>e.gaia_model&&!t.has(e.id))}function dj(e){return e.filter(e=>!e.gaia_model&&e.downloaded)}function fj(e){let t=ZA(e),n=new Set(t.filter(e=>e.selected||e.gaia_model&&e.downloaded&&!e.skipped).map(e=>e.id)),r=!t.find(t=>t.id===e.chat_model.id)?.reads_images&&t.some(e=>QA(e)&&e.gaia_model&&e.skipped);return aj({ticked:n,defaultChat:e.chat_model.id,unticked:new Set,chatChosen:e.chat_model.user_set,vision:e.vision_model??(r?`none`:null)},t)}function pj(e,t){return e.filter(e=>e.chat_choice&&(t.has(e.id)||e.downloaded))}function mj(e,t,n,r){let i=new Set(e.ticked),a=new Set(e.unticked);r?(i.add(n),a.delete(n)):(i.delete(n),a.add(n));let o=pj(t,i),s=e.defaultChat;if(!s||!o.some(e=>e.id===s)){let e=t.find(e=>e.id===n);s=r&&e?.chat_choice?n:(o.find(e=>e.recommended)??o[0])?.id??null}return{...e,ticked:i,defaultChat:s,unticked:a}}function hj(e,t,n){let r=t.find(e=>e.id===n)?.downloaded;return{...e,defaultChat:n,chatChosen:!0,ticked:r?e.ticked:new Set([...e.ticked,n])}}function gj(e){let t=ZA(e),n=new Set(t.filter(e=>e.recommended||e.gaia_model&&e.downloaded).map(e=>e.id)),r=pj(t,n);return aj({ticked:n,defaultChat:e.recommended_model&&r.some(t=>t.id===e.recommended_model)?e.recommended_model:(r.find(e=>e.recommended)??r[0])?.id??null,unticked:new Set,chatChosen:!1,vision:null},t)}function _j(e,t){return e.filter(e=>t.ticked.has(e.id)&&!e.downloaded).sort((e,t)=>(t.size_gb??0)-(e.size_gb??0))}function vj(e,t){let n=_j(ZA(e),t).map(e=>e.size_gb),r=n.every(e=>e!=null)?wj(n.reduce((e,t)=>e+t,0)):null,i=e.disk?.free_gb??null;return{downloadGb:r,freeGb:i,afterGb:r!=null&&i!=null?wj(i-r):null}}function yj(e,t){let{downloadGb:n,freeGb:r}=vj(e,t);return n==null||r==null||n<=r?null:{needGb:n,freeGb:r,freeUpGb:wj(n-r),drop:_j(ZA(e),t).find(e=>e.size_gb!=null&&n-e.size_gb<=r)??null}}function bj(e,t){return e.filter(e=>e.fits===!1&&(t.ticked.has(e.id)||e.id===t.defaultChat))}function xj(e,t){let n=[];for(let r of ZA(e)){if(!r.planned){r.skipped&&t.ticked.has(r.id)&&n.push({id:r.id,skipped:!1});continue}if(r.id===e.chat_model.id){r.skipped&&n.push({id:r.id,skipped:!1});continue}let i=t.ticked.has(r.id);!i&&!r.skipped&&n.push({id:r.id,skipped:!0}),i&&r.skipped&&n.push({id:r.id,skipped:!1})}return n}function Sj(e,t){return ZA(e).filter(e=>t.ticked.has(e.id)&&!e.planned&&!e.downloaded).map(e=>e.id)}function Cj(e,t){let n=(e.models??[]).filter(e=>e.state!==`skipped`);if(!t?.catalog||n.length===0)return e.overall;let r=0,i=0;for(let e of n){let n=t.catalog.find(t=>t.id===e.id),a=n?.downloaded?0:n?.size_gb==null?e.bytes_total:Math.min(e.bytes_total||1/0,n.size_gb*1e9),o=Math.max(0,e.bytes_total-a);i+=a,r+=e.state===`ready`||e.state===`verifying`?a:Math.min(a,Math.max(0,e.bytes_done-o))}return{bytes_done:r,bytes_total:i,speed_bps:e.overall?.speed_bps??0,eta_s:null,percent:i>0?Math.floor(r*100/i):100,failed:n.filter(e=>e.state===`failed`).length}}function wj(e){return Math.round(e*10)/10}var Tj=6;function Ej(e,t){let n=[];return e.chat_choice&&!$A(e)&&n.push(t(`setup.models.purpose.chat`)),QA(e)&&n.push(t(`setup.models.purpose.vision`)),$A(e)&&n.push(t(`setup.models.purpose.documents`)),n}function Dj(e,t){return $A(e)?t(`setup.models.line.documents`):QA(e)?t(`setup.models.line.vision`):t(`setup.models.line.chat`)}function Oj(e,t){return e.downloaded?t(`setup.models.status.onPc`):e.size_gb==null?t(`setup.models.status.sizeUnknown`):e.partial?t(`setup.models.status.partial`,{size:$(e.size_gb)}):t(`setup.models.status.download`,{size:$(e.size_gb)})}function kj(e,t){return e.fits!==!0||e.need_gb==null||e.capacity_gb==null?null:t(`setup.models.fit.ok`,{need:NS(e.need_gb),have:NS(e.capacity_gb)})}function Aj(e,t){return e.fit_code===`npu`?t(`setup.models.warn.npu`):e.fit_code===`backend`?t(`setup.models.warn.backend`):e.need_gb!=null&&e.capacity_gb!=null?t(`setup.models.warn.tooBig`,{need:NS(e.need_gb),have:NS(e.capacity_gb)}):t(`setup.models.warn.tooBigNoNumbers`)}function jj(e,t,n){return!QA(e)&&!$A(e)?null:n===`settings`?e.downloaded?t(`settings.models.warn.kept`,{name:e.name}):t(QA(e)?`settings.models.warn.vision`:`settings.models.warn.documents`,{name:e.name}):t(QA(e)?`setup.models.warn.vision`:`setup.models.warn.documents`,{name:e.name})}function Mj({entry:e,ticked:t,onToggle:n,disabled:r,progress:i,actions:a,place:o}){let s=T(),c=(0,X.useId)(),l=e.fits===!1,u=t?null:jj(e,s,o),d=i?.state===`downloading`&&i.bytes_total>0,f=l?Aj(e,s):u,p=[`${c}-status`,`${c}-note`,f?`${c}-warn`:null].filter(Boolean).join(` `);return V(`li`,{className:`mc-row${t?` is-ticked`:``}${f?` has-warning`:``}`,children:[V(`div`,{className:`mc-row-top`,children:[V(`label`,{className:`mc-row-main`,children:[P(`input`,{type:`checkbox`,className:`mc-input`,checked:t,disabled:r,onChange:e=>n(e.target.checked),"aria-describedby":p}),P(`span`,{className:`mc-box`,"aria-hidden":`true`,children:P(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,children:P(`path`,{className:`mc-tick`,d:`M3.5 8.5l3 3 6-7`})})}),V(`span`,{className:`mc-text`,children:[V(`span`,{className:`mc-name-line`,children:[P(`bdi`,{className:`mc-name`,title:e.id,children:e.name}),V(`span`,{className:`mc-chips`,children:[Ej(e,s).map(e=>P(`span`,{className:`mc-chip`,children:e},e)),ej(e)&&P(`span`,{className:`mc-chip is-npu`,children:s(`setup.models.npu`)})]})]}),V(`span`,{className:`mc-status`,id:`${c}-status`,children:[d?s(`setup.models.status.downloading`,{done:PS(i.bytes_done),total:PS(i.bytes_total)}):Oj(e,s),e.recommended&&P(`span`,{className:`mc-pill`,children:s(`setup.models.recommended`)}),e.fits===null&&V(`span`,{className:`mc-chip is-unknown`,children:[P(Ar,{size:11,"aria-hidden":`true`}),` `,s(`setup.models.fitUnknown`)]})]}),P(`span`,{className:`mc-note`,id:`${c}-note`,children:s.compose(t=>[Dj(e,t),kj(e,t),e.fits===null?t(`setup.models.fit.unknown`):null].filter(Boolean).join(` `))})]})]}),a&&P(`span`,{className:`mc-actions`,children:a})]}),d&&P(`progress`,{className:`mc-mini-progress`,max:i.bytes_total,value:i.bytes_done,"aria-label":s(`setup.progress.rowLabel`,{name:e.name,state:s(`setup.state.downloading`)})}),P(XA,{open:!!f,children:V(`p`,{className:`mc-warn${l?` is-big`:``}`,role:`note`,id:`${c}-warn`,children:[P(J,{size:13,"aria-hidden":`true`}),P(`span`,{children:f})]})})]})}function Nj({plan:e,selection:t}){let n=T(),{downloadGb:r,freeGb:i,afterGb:a}=vj(e,t),o=yj(e,t),s=KA(r??0),c=KA(a??0),l=Pj(e.disk?.path??null),u=r!=null&&i?Math.min(1,r/i):0,d=qA(r==null?n(`setup.summary.spokenUnknown`):a==null?n(`setup.summary.spokenNoDisk`,{download:$(r)}):n(`setup.summary.spoken`,{download:$(r),after:$(Math.max(0,a))}),600);return V(`div`,{className:`mc-summary${o?` is-warn`:``}`,role:`group`,"aria-label":n(`setup.summary.label`),children:[V(`div`,{className:`mc-summary-stats`,children:[V(`span`,{className:`mc-stat`,children:[P(`span`,{className:`mc-stat-label`,children:n(`setup.summary.download`)}),P(`bdi`,{className:`mc-stat-value`,children:r==null?n(`setup.summary.sizeUnknown`):$(Fj(s))})]}),V(`span`,{className:`mc-stat`,children:[V(`span`,{className:`mc-stat-label`,children:[P(Ii,{size:12,"aria-hidden":`true`}),` `,l?n(`setup.summary.freeOn`,{drive:l}):n(`setup.summary.free`)]}),P(`bdi`,{className:`mc-stat-value`,children:i==null?n(`setup.summary.freeUnknown`):$(i)})]}),a!=null&&!o&&V(`span`,{className:`mc-stat`,children:[P(`span`,{className:`mc-stat-label`,children:n(`setup.summary.after`)}),P(`bdi`,{className:`mc-stat-value`,children:$(Math.max(0,Fj(c)))})]})]}),i!=null&&P(`div`,{className:`mc-disk`,"aria-hidden":`true`,children:P(`span`,{className:`mc-disk-fill`,style:{inlineSize:`${(u*100).toFixed(1)}%`}})}),P(XA,{open:!!o,children:o&&V(`p`,{className:`mc-disk-warn`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),P(`span`,{children:o.drop?n(`setup.summary.shortDrop`,{need:$(o.needGb),free:$(o.freeGb),drive:l??n(`setup.summary.theDrive`),freeUp:$(o.freeUpGb),name:o.drop.name,saves:$(o.drop.size_gb??0)}):n(`setup.summary.short`,{need:$(o.needGb),free:$(o.freeGb),drive:l??n(`setup.summary.theDrive`),freeUp:$(o.freeUpGb)})})]})}),P(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:d})]})}function Pj(e){if(!e)return null;let t=/^([A-Za-z]:)[\\/]/.exec(e);return t?t[1]:e}function Fj(e){return Math.round(e*10)/10}function Ij({plan:e,selection:t,onToggle:n,onDefaultChat:r,labelledBy:i,cloud:a,disabled:o,progress:s,rowActions:c,place:l=`setup`}){let u=T(),d=ZA(e),[f,p]=(0,X.useState)(``),m=(0,X.useId)(),h=a?d.filter($A):lj(d),g=a?[]:uj(d),_=a?[]:dj(d),v=(0,X.useMemo)(()=>{let e=f.trim().toLowerCase();return e?_.filter(t=>t.id.toLowerCase().includes(e)||t.name.toLowerCase().includes(e)):_},[_,f]),y=pj(d,t.ticked),b=e=>P(Mj,{entry:e,ticked:t.ticked.has(e.id),onToggle:t=>n(e.id,t),disabled:o,progress:s?.[e.id],actions:c?.(e),place:l},e.id);return V(`div`,{className:`mc`,children:[P(`ul`,{className:`mc-list`,role:`group`,"aria-labelledby":i,children:h.map(b)}),a?P(`p`,{className:`setup-hint`,children:u(`setup.models.cloudNote`)}):P(`p`,{className:`mc-foot`,children:u(`setup.models.neverDeletes`)}),g.length>0&&V(`details`,{className:`mc-more`,children:[P(`summary`,{children:u(`setup.models.more`,{n:String(g.length)})}),P(`ul`,{className:`mc-list`,role:`group`,"aria-label":u(`setup.models.moreLabel`),children:g.map(b)})]}),_.length>0&&V(`details`,{className:`mc-more`,children:[P(`summary`,{children:u(`setup.models.installed`,{n:String(_.length)})}),_.length>Tj&&P(`input`,{className:`settings-input mc-search`,type:`search`,value:f,onChange:e=>p(e.target.value),placeholder:u(`setup.models.search`),"aria-label":u(`setup.models.search`)}),P(`ul`,{className:`mc-list`,role:`radiogroup`,"aria-label":u(`setup.models.installedLabel`),children:v.map(e=>P(`li`,{className:`mc-row is-installed${t.defaultChat===e.id?` is-ticked`:``}`,children:V(`label`,{className:`mc-row-main`,children:[P(`input`,{type:`radio`,name:`${m}-installed`,className:`mc-radio`,checked:t.defaultChat===e.id,disabled:o,onChange:()=>r(e.id)}),V(`span`,{className:`mc-text`,children:[V(`span`,{className:`mc-name-line`,children:[P(`bdi`,{className:`mc-name`,title:e.id,children:e.name}),V(`span`,{className:`mc-chips`,children:[P(`span`,{className:`mc-chip`,children:u(`setup.models.purpose.chat`)}),ej(e)&&P(`span`,{className:`mc-chip is-npu`,children:u(`setup.models.npu`)})]})]}),V(`span`,{className:`mc-status`,children:[u(`setup.models.status.onPc`),` · `,u(`setup.models.useAsDefault`)]})]})]})},e.id))})]}),!a&&V(`div`,{className:`mc-default`,children:[P(`label`,{htmlFor:m,className:`mc-default-label`,children:u(`setup.models.defaultChat`)}),V(`select`,{id:m,className:`settings-input mc-select`,value:t.defaultChat??``,disabled:o||y.length===0,onChange:e=>r(e.target.value),children:[y.length===0&&P(`option`,{value:``,children:u.bare(`setup.models.noChat`)}),y.map(e=>V(`option`,{value:e.id,children:[e.name,ej(e)?` (${u(`setup.models.npu`)})`:``]},e.id))]})]})]})}function Lj(){let e=T();return V(`div`,{className:`mc`,"aria-busy":`true`,children:[V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,e(`setup.models.loading`)]}),P(`ul`,{className:`mc-list`,"aria-hidden":`true`,children:[0,1,2].map(e=>P(`li`,{className:`mc-row is-skeleton`,children:P(`span`,{className:`mc-skeleton`})},e))})]})}function Rj({entry:e}){let t=T();return e.support===`verified`?P(`span`,{className:`mc-chip is-verified`,children:t(`setup.label.verified`)}):e.support===`untested`?P(`span`,{className:`mc-chip is-untested`,children:t(`setup.label.untested`)}):null}function zj({name:e,entry:t,checked:n,recommended:r,disabled:i,onPick:a,children:o}){let s=T();return P(`li`,{className:`mc-row${n?` is-ticked`:``}`,children:V(`label`,{className:`mc-row-main`,children:[P(`input`,{type:`radio`,className:`mc-radio`,name:e,checked:n,disabled:i||tj(t),onChange:a}),V(`span`,{className:`mc-text`,children:[V(`span`,{className:`mc-name-line`,children:[P(`span`,{className:`mc-name`,title:t.id,children:P(`bdi`,{children:t.name})}),V(`span`,{className:`mc-chips`,children:[r&&P(`span`,{className:`mc-pill`,children:s(`setup.models.recommended`)}),P(Rj,{entry:t}),ej(t)&&P(`bdi`,{className:`mc-chip is-npu`,children:s(`setup.models.npu`)})]})]}),P(`span`,{className:`mc-status`,children:Oj(t,s)}),t.fits===!1&&V(`span`,{className:`mc-warn is-big`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,Aj(t,s)]}),o]})]})})}function Bj({label:e,note:t,size:n,checked:r,disabled:i,warning:a,chips:o,onChange:s}){return P(`li`,{className:`mc-row${r?` is-ticked`:``}${i?` is-off`:``}`,children:V(`label`,{className:`mc-row-main`,children:[P(`input`,{type:`checkbox`,className:`mc-input`,checked:r,disabled:i,onChange:e=>s(e.target.checked)}),P(`span`,{className:`mc-box`,"aria-hidden":`true`,children:P(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,children:P(`path`,{className:`mc-tick`,d:`M3.5 8.5l3 3 6-7`})})}),V(`span`,{className:`mc-text`,children:[V(`span`,{className:`mc-name-line`,children:[P(`span`,{className:`mc-name`,children:P(`bdi`,{children:e})}),P(`span`,{className:`mc-chips`,children:o})]}),P(`span`,{className:`mc-status`,children:P(`bdi`,{dir:`ltr`,children:n})}),P(`span`,{className:`mc-note`,children:t}),a&&V(`span`,{className:`mc-warn`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,a]})]})]})})}function Vj({plan:e,selection:t,onSelection:n,disabled:r}){let i=T(),a=(0,X.useId)(),o=ZA(e),[s,c]=(0,X.useState)(!1),l=o.find(e=>e.id===t.defaultChat),u=!!l&&ej(l),d=o.filter(e=>e.chat_choice&&!$A(e)&&(e.gaia_model||e.downloaded)&&ej(e)===u),f=d.filter(e=>e.support===`verified`),p=d.filter(e=>e.support!==`verified`),m=ij(o,t),h=!!l?.reads_images,g=o.filter(e=>QA(e)&&e.id!==l?.id),_=o.find($A),v=e=>o.find(t=>nj(t)&&t.roles.includes(e)),y=e=>e.downloaded?i(`setup.models.status.onPc`):e.size_gb==null?i(`setup.contents.sizeOnDownload`):$(e.size_gb),b=(e,r)=>n(mj(t,o,e,r)),x=e=>n(oj(t,o,e)),S=e=>n(sj(t,o,e)),C=v(`speech`),w=v(`voice`),E=v(`image_creation`),O=rj(l),k=l?.support===`untested`;return V(`div`,{className:`mc`,children:[V(`section`,{className:`mc-job`,"aria-labelledby":`${a}-chat`,children:[P(`h3`,{className:`mc-job-title`,id:`${a}-chat`,children:i(`setup.job.chat`)}),P(`p`,{className:`setup-hint`,children:i(`setup.job.verifiedNote`)}),P(`ul`,{className:`mc-list`,role:`radiogroup`,"aria-labelledby":`${a}-chat`,children:f.map(n=>P(zj,{name:`${a}-chat-model`,entry:n,checked:n.id===t.defaultChat,recommended:n.id===e.recommended_model,disabled:r,onPick:()=>x(n.id)},n.id))}),p.length>0&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:i(`setup.job.untestedNote`)}),P(`ul`,{className:`mc-list`,role:`radiogroup`,"aria-labelledby":`${a}-chat`,children:p.map(e=>P(zj,{name:`${a}-chat-model`,entry:e,checked:e.id===t.defaultChat,recommended:!1,disabled:r,onPick:()=>x(e.id)},e.id))})]}),k&&V(`p`,{className:`mc-warn`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,i(`setup.job.untestedPicked`)]})]}),V(`section`,{className:`mc-job`,"aria-labelledby":`${a}-vision`,children:[P(`h3`,{className:`mc-job-title`,id:`${a}-vision`,children:i(`setup.job.vision`)}),u?P(`p`,{className:`setup-hint`,role:`note`,children:i(`setup.job.visionOffNpu`,{name:l?.name??``})}):h?V(`div`,{className:`setup-card`,children:[V(`p`,{className:`mc-job-line`,children:[P(`bdi`,{children:i(`setup.job.visionBuiltIn`,{name:l?.name??``})}),P(`span`,{className:`setup-ok`,children:i(`setup.job.nothingMore`)})]}),P(`button`,{type:`button`,className:`link-btn`,"aria-expanded":s,onClick:()=>c(e=>!e),children:i(s?`setup.job.hideVision`:`setup.job.otherVision`)})]}):P(`p`,{className:`setup-hint`,children:i(`setup.job.visionNeeded`,{name:l?.name??``})}),!u&&(!h||s)&&V(`ul`,{className:`mc-list`,role:`radiogroup`,"aria-labelledby":`${a}-vision`,children:[g.map(e=>P(zj,{name:`${a}-vision-model`,entry:e,checked:m===e.id,recommended:!h&&e.gaia_model&&e.support===`verified`,disabled:r,onPick:()=>S(e.id)},e.id)),P(`li`,{className:`mc-row${m===null?` is-ticked`:``}`,children:V(`label`,{className:`mc-row-main`,children:[P(`input`,{type:`radio`,className:`mc-radio`,name:`${a}-vision-model`,checked:h?m===l?.id:m===null,disabled:r,onChange:()=>S(h?null:`none`)}),V(`span`,{className:`mc-text`,children:[P(`span`,{className:`mc-name`,children:i(h?`setup.job.useChatForVision`:`setup.job.skipVision`)}),m===null&&!h&&V(`span`,{className:`mc-warn`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,i(`setup.job.skipVisionNote`)]})]})]})})]})]}),_&&V(`section`,{className:`mc-job`,"aria-labelledby":`${a}-docs`,children:[P(`h3`,{className:`mc-job-title`,id:`${a}-docs`,children:i(`setup.job.documents`)}),P(`ul`,{className:`mc-list`,children:P(Bj,{label:_.name,note:i(`setup.models.line.documents`),size:y(_),checked:t.ticked.has(_.id),disabled:r,warning:t.ticked.has(_.id)?null:i(`setup.job.documentsOff`),chips:V(D.Fragment,{children:[P(`span`,{className:`mc-pill`,children:i(`setup.models.recommended`)}),P(Rj,{entry:_})]}),onChange:e=>b(_.id,e)})})]}),V(`section`,{className:`mc-job`,"aria-labelledby":`${a}-extras`,children:[P(`h3`,{className:`mc-job-title`,id:`${a}-extras`,children:i(`setup.job.extras`)}),P(`p`,{className:`setup-hint`,children:i(`setup.job.extrasNote`)}),V(`ul`,{className:`mc-list`,children:[C&&P(Bj,{label:i(`setup.job.speech`),note:i(`setup.job.speechNote`),size:y(C),checked:t.ticked.has(C.id),disabled:r,onChange:e=>b(C.id,e)}),w&&P(Bj,{label:i(`setup.job.voice`),note:i(`setup.job.voiceNote`),size:y(w),checked:t.ticked.has(w.id),disabled:r,onChange:e=>b(w.id,e)}),E&&P(Bj,{label:i(`setup.job.images`),note:i(`setup.job.imagesNote`),size:y(E),checked:t.ticked.has(E.id),disabled:r||!O,warning:O?null:i(`setup.job.imagesBlocked`,{name:l?.name??``}),onChange:e=>b(E.id,e)})]})]}),P(Hj,{plan:e,selection:t})]})}function Hj({plan:e,selection:t}){let n=T(),r=ZA(e),i=e=>r.find(t=>t.id===e)?.name??e??n(`setup.get.off`),a=e=>r.find(n=>nj(n)&&n.roles.includes(e)&&t.ticked.has(n.id)),o=r.find(e=>$A(e)&&t.ticked.has(e.id)),s=r.find(e=>e.id===t.defaultChat),c=ij(r,t),l=[a(`speech`)&&n(`setup.job.speech`),a(`voice`)&&n(`setup.job.voice`)].filter(Boolean).join(`, `);return V(`section`,{className:`setup-card`,"aria-label":n(`setup.get.title`),children:[P(`h3`,{className:`mc-job-title`,children:n(`setup.get.title`)}),V(`dl`,{className:`setup-summary-list`,children:[V(`div`,{children:[P(`dt`,{children:n(`setup.job.chat`)}),P(`dd`,{children:P(`bdi`,{children:i(t.defaultChat)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.job.vision`)}),P(`dd`,{children:P(`bdi`,{children:s&&ej(s)?n(`setup.get.offNpu`):c?i(c):n(`setup.get.off`)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.job.documents`)}),P(`dd`,{children:P(`bdi`,{children:o?o.name:n(`setup.get.off`)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.get.voice`)}),P(`dd`,{children:l||n(`setup.get.off`)})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.job.images`)}),P(`dd`,{children:rj(s)?a(`image_creation`)?n(`setup.get.on`):n(`setup.get.off`):n(`setup.get.notAvailable`)})]})]})]})}var Uj=(0,X.createContext)(void 0),Wj=Uj.Provider;function Gj({children:e}){let t=(0,X.useContext)(Uj);return t===void 0?P(`div`,{className:`setup-row setup-nav`,children:e}):t===null?null:(0,eS.createPortal)(P(`div`,{className:`setup-footer-row`,children:e}),t)}function Kj({title:e,children:t,confirmLabel:n,cancelLabel:r,onConfirm:i,onCancel:a,danger:o,busy:s}){let c=(0,X.useRef)(null),l=(0,X.useRef)(null),u=(0,X.useId)(),d=(0,X.useId)();return sS(c,!0),(0,X.useEffect)(()=>{let e=document.activeElement;return l.current?.focus(),()=>e?.focus?.()},[]),Io(!0,a,!s),(0,eS.createPortal)(P(`div`,{className:`confirm-overlay`,children:V(`div`,{ref:c,className:`confirm-sheet`,role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":u,"aria-describedby":t?d:void 0,children:[P(`h2`,{id:u,className:`confirm-title`,children:e}),t&&P(`div`,{id:d,className:`confirm-body`,children:t}),V(`div`,{className:`confirm-actions`,children:[P(`button`,{ref:l,type:`button`,className:`btn-secondary`,onClick:a,disabled:s,children:r}),P(`button`,{type:`button`,className:o?`btn-danger`:`btn-primary`,onClick:i,disabled:s,children:n})]})]})}),document.body)}function qj(e){return e===`windows`?`Windows`:e===`linux`?`Linux`:e}function Jj(e){let t=/^Run:\s*(.+)$/.exec(e)??/^(sudo .+)$/.exec(e);return t?t[1].trim():null}function Yj(e,t){return e.setting&&Math.abs(e.setting.current_gb-t)<.05&&e.gpu_gb!=null?e.gpu_gb:e.presets?.find(e=>Math.abs(e.setting_gb-t)<.05)?.gpu_gb??null}function Xj(e,t,n=!1){return t==null?e(n?`gpu.appliedAny`:`gpu.pending.restartAny`):e(n?`gpu.applied`:`gpu.pending.restart`,{gb:$(t)})}function Zj(e){e.focus({preventScroll:!0});for(let t=e.parentElement;t;t=t.parentElement){let n=getComputedStyle(t).overflowY;if(n!==`auto`&&n!==`scroll`)continue;let r=e.getBoundingClientRect().top-t.getBoundingClientRect().top;(r<0||r>t.clientHeight-40)&&(t.scrollTop+=r-16);return}}function Qj(e){return e instanceof Error?e.message:String(e)}function $j({status:e,targetGpuGb:t}){let n=T(),r=e=>Math.round(e*10),i=r(e.total_gb??0),a=r(e.gpu_gb??0),o=t!=null&&r(t)>a?r(t):null,s=o==null?0:o-a,c=Math.max(0,i-a-s),l=e=>$(e/10),u=e=>i>0?Math.min(100,e/i*100):0,d=e.pending?.state===`took_effect`;return V(`div`,{className:`gpu-split`,children:[V(`div`,{className:`gpu-bar${d?` is-new`:``}`,role:`img`,"aria-label":o==null?n(`gpu.split.aria`,{cpu:l(c),gpu:l(a)}):n(`gpu.split.ariaTarget`,{cpu:l(c),gpu:l(o),now:l(a)}),children:[P(`span`,{className:`gpu-seg is-gpu`,style:{inlineSize:`${u(a)}%`}}),P(`span`,{className:`gpu-seg is-target`,style:{inlineSize:`${u(s)}%`}}),P(`span`,{className:`gpu-seg is-cpu`}),o!=null&&P(`span`,{className:`gpu-marker`,style:{insetInlineStart:`${u(o)}%`}})]}),V(`div`,{className:`gpu-legend`,"aria-hidden":`true`,children:[P(`span`,{className:`gpu-key is-gpu`,children:P(`bdi`,{children:n(`gpu.split.gpu`,{gb:l(a)})})}),o!=null&&P(`span`,{className:`gpu-key is-target`,children:P(`bdi`,{children:n(`gpu.split.added`,{gb:l(s)})})}),P(`span`,{className:`gpu-key is-cpu`,children:P(`bdi`,{children:n(`gpu.split.cpu`,{gb:l(c)})})})]})]})}function eM({presets:e,value:t,onChange:n,recommended:r,max:i,disabled:a}){let o=T(),s=(0,X.useRef)([]),c=Math.max(0,e.findIndex(e=>e.setting_gb===t));return P(`div`,{className:`gpu-presets`,role:`radiogroup`,"aria-label":o(`gpu.presets.label`),onKeyDown:t=>{let r=t.key===`ArrowRight`||t.key===`ArrowDown`?1:t.key===`ArrowLeft`||t.key===`ArrowUp`?-1:0;if(!r)return;t.preventDefault();let i=getComputedStyle(t.currentTarget).direction===`rtl`,a=(t.key===`ArrowRight`||t.key===`ArrowLeft`)&&i?-r:r,o=(c+a+e.length)%e.length;n(e[o].setting_gb),s.current[o]?.focus()},children:e.map((e,l)=>V(`button`,{ref:e=>{s.current[l]=e},type:`button`,role:`radio`,"aria-checked":e.setting_gb===t,tabIndex:l===c?0:-1,className:`gpu-preset${e.setting_gb===t?` is-active`:``}`,disabled:a,onClick:()=>n(e.setting_gb),children:[P(`bdi`,{children:o(`gpu.presets.gpu`,{gb:$(e.gpu_gb)})}),e.setting_gb===r&&V(D.Fragment,{children:[` `,P(`span`,{className:`gpu-tag is-recommended`,children:o(`gpu.presets.recommended`)})]}),e.setting_gb===i&&V(D.Fragment,{children:[` `,P(`span`,{className:`gpu-tag is-max`,children:o(`gpu.presets.max`)})]})]},e.setting_gb))})}function tM({status:e,onStatus:t,mode:n,names:r,onSkip:i,onContinue:a,onBack:o,headingId:s}){let c=T(),l=(0,X.useCallback)(()=>{let e=s?document.getElementById(s):null;e&&Zj(e)},[s]);(0,X.useEffect)(()=>{n===`setup`&&l()},[n,l]);let u=(0,X.useId)(),d=e.presets??[],[f,p]=(0,X.useState)(e.recommended_setting_gb??d[0]?.setting_gb??null),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(void 0),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),[O,k]=(0,X.useState)(null),A=d.find(e=>e.setting_gb===f)??null,j=e.recommended_setting_gb??null,M=d.length>0&&d[d.length-1].setting_gb===e.setting?.max_gb?d[d.length-1].setting_gb:null,N=A&&e.total_gb!=null?Math.max(0,e.total_gb-A.gpu_gb):null,F=j==null?(e.models??[]).find(e=>e.default&&e.fits_now):void 0,I=(A?.unlocks??[]).slice(0,2).map(e=>r[e]??e),L=e.pending??null,ee=e.method===`apply`,R=e.guided_value!==null,z=(0,X.useCallback)(async()=>{h(!0),_(null),C(`steps`),E(null);try{let e=await Nn(f??void 0);y(e.guided_value),_(e.guided_value===null?[]:e.guided_steps??[])}catch(e){y(void 0),_([]),E({kind:`error`,message:Qj(e)})}finally{C(null)}},[f]),B=async()=>{if(f!=null){x(null),C(`apply`),E(null);try{t(await qt(f)),E({kind:`applied`})}catch(e){let t=e instanceof yn&&e.httpStatus===403;E(t?{kind:`denied`}:{kind:`error`,message:Qj(e)}),t&&l()}finally{C(null)}}},te=async()=>{x(null),C(`revert`),E(null);try{t(await Oe()),E({kind:`applied`})}catch(e){E(e instanceof yn&&e.httpStatus===403?{kind:`denied`}:{kind:`error`,message:Qj(e)})}finally{C(null)}},ne=async()=>{if(f!=null){C(`done`),E(null);try{t(await je(f)),h(!1)}catch(e){E({kind:`error`,message:Qj(e)})}finally{C(null)}}},re=async()=>{C(`keep`),E(null);try{t(await ve())}catch(e){E({kind:`error`,message:Qj(e)})}finally{C(null)}},ie=async e=>{try{await navigator.clipboard.writeText(e),k(e)}catch(e){E({kind:`error`,message:c(`gpu.copyFailed`,{reason:Qj(e)})})}},ae=L?.state===`restart_required`;return V(`div`,{className:`gpu`,children:[P(`p`,{className:`setup-hint`,children:c(`gpu.body`,{total:$(e.total_gb??0),gpu:$(e.gpu_gb??0)})}),P($j,{status:e,targetGpuGb:!ae&&!m?A?.gpu_gb??null:null}),L?.state===`took_effect`&&V(`div`,{className:`gpu-notice is-ok`,role:`status`,children:[P(mr,{size:14,"aria-hidden":`true`}),P(`span`,{children:c(`gpu.pending.tookEffect`,{gb:$(e.gpu_gb??0)})}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void re(),disabled:S!==null,children:c(`gpu.ok`)})]}),ae&&V(`div`,{className:`gpu-notice`,role:`status`,children:[P(Hi,{size:14,"aria-hidden":`true`}),P(`span`,{children:c.compose(t=>[Xj(t,Yj(e,L.setting_gb),w?.kind===`applied`),t(`gpu.pending.restartHow`),n===`setup`?t(`gpu.pending.downloadsFirst`):null].filter(Boolean).join(` `))}),L.source===`guided`&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void re(),disabled:S!==null,children:c(`gpu.keep`,{gb:$(e.gpu_gb??0)})})]}),L?.state===`not_applied`&&V(`div`,{className:`gpu-notice is-warn`,role:`status`,children:[P(J,{size:14,"aria-hidden":`true`}),P(`span`,{children:c(`gpu.pending.notApplied`,{gb:$(e.gpu_gb??0)})}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void re(),disabled:S!==null,children:c(`gpu.keep`,{gb:$(e.gpu_gb??0)})})]}),!ae&&!m&&d.length>0&&V(D.Fragment,{children:[F&&V(`p`,{className:`gpu-unlock is-keep`,children:[P(mr,{size:13,"aria-hidden":`true`}),` `,c(`gpu.keepRecommended`,{model:r[F.id]??F.id})]}),P(eM,{presets:d,value:f,onChange:p,recommended:j,max:M,disabled:S!==null}),A&&P(`p`,{className:`gpu-unlock`,children:I.length>0?c(I.length>1?`gpu.unlock.two`:`gpu.unlock.one`,{gb:$(A.gpu_gb),a:I[0],b:I[1]??``}):c(`gpu.unlock.none`,{gb:$(A.gpu_gb)})}),A&&A.setting_gb===M&&N!=null&&V(`p`,{className:`gpu-unlock is-warn`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,c(`gpu.maxWarn`,{cpu:$(N),os:qj(e.os)})]}),P(`p`,{className:`setup-hint`,children:c.compose(t=>`${t(`gpu.reserve`,{gb:$(e.reserve_gb??16),os:qj(e.os)})} ${t(`gpu.needs`)}`)}),!ee&&e.method_reason&&P(`p`,{className:`setup-hint`,children:P(`bdi`,{dir:`ltr`,children:e.method_reason})})]}),!ae&&!m&&d.length===0&&P(`p`,{className:`setup-hint`,children:c(`gpu.noPresets`)}),m&&V(`div`,{className:`gpu-guided`,children:[A&&P(`p`,{className:`setup-hint`,id:u,children:c(`gpu.guided.lede`,{gb:$(A.gpu_gb)})}),g===null?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,c(`gpu.guided.loading`)]}):v===null?P(`p`,{className:`setup-hint`,children:c(`gpu.noPresets`)}):P(`ol`,{className:`gpu-steps`,"aria-labelledby":u,children:g.map(e=>{let t=Jj(e);return V(`li`,{children:[P(`span`,{children:e}),t&&V(`button`,{type:`button`,className:`btn-secondary gpu-copy`,onClick:()=>void ie(t),"aria-label":c(`gpu.copyAria`,{what:t}),children:[P(O===t?mr:Br,{size:12,"aria-hidden":`true`}),c(O===t?`gpu.copied`:`gpu.copy`)]})]},e)})}),V(Gj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>h(!1),disabled:S!==null,children:c(`gpu.guided.back`)}),!ee&&v!==null&&V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void ne(),disabled:S!==null||f==null,children:[S===`done`&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,c(`gpu.guided.done`)]})]})]}),S===`apply`||S===`revert`?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,c(`gpu.waiting`)]}):null,w?.kind===`denied`&&V(`div`,{className:`gpu-notice is-warn`,role:`alert`,children:[P(J,{size:14,"aria-hidden":`true`}),P(`span`,{children:c(`gpu.denied`)})]}),w?.kind===`error`&&P(`p`,{className:`setup-error`,role:`alert`,children:w.message}),!m&&(()=>{let t=!ae&&ee&&d.length>0&&P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>x(`apply`),disabled:S!==null||f==null,children:w?.kind===`denied`||L?.state===`not_applied`?c(`gpu.tryAgain`):c(`gpu.apply`)}),r=!ae&&d.length>0&&R&&P(`button`,{type:`button`,className:ee?`btn-secondary`:`btn-primary`,onClick:()=>void z(),disabled:S!==null,children:c(`gpu.showMe`)});return n===`setup`?V(Gj,{children:[o&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:o,children:c(`setup.back`)}),ae?a&&P(`button`,{type:`button`,className:`btn-primary`,onClick:a,autoFocus:!0,children:c(`setup.continue`)}):V(D.Fragment,{children:[i&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:i,disabled:S!==null,children:c(`gpu.skip`)}),ee?V(D.Fragment,{children:[r,t]}):r]})]}):V(`div`,{className:`setup-row gpu-actions`,children:[t,r,e.revert?.available&&V(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>x(`revert`),disabled:S!==null,children:[P(La,{size:13,"aria-hidden":`true`}),` `,c(`gpu.undo`)]})]})})(),b===`apply`&&f!=null&&V(Kj,{title:A?c(`gpu.consent.title`,{gb:$(A.gpu_gb)}):c(`gpu.consent.titleAny`),confirmLabel:c(`setup.continue`),cancelLabel:c(`setup.cancel`),onConfirm:()=>void B(),onCancel:()=>x(null),children:[P(`p`,{children:A?c(`gpu.consent.body`,{name:e.setting?.name??``,gb:$(A.gpu_gb)}):c(`gpu.consent.bodyAny`,{name:e.setting?.name??``})}),P(`p`,{className:`confirm-note`,children:c(`gpu.consent.saved`,{gb:$(e.gpu_gb??0)})})]}),b===`revert`&&P(Kj,{title:c(`gpu.revert.title`),confirmLabel:c(`setup.continue`),cancelLabel:c(`setup.cancel`),onConfirm:()=>void te(),onCancel:()=>x(null),children:P(`p`,{children:c(`gpu.revert.body`)})})]})}function nM({plan:e,planError:t,onRetryPlan:n,onUseRecommended:r,selection:i,onSelection:a,cloud:o,keepTrying:s,onKeepTrying:c,onBack:l,onContinue:u,busy:d,error:f}){let p=T(),m=(0,X.useRef)(null),[h,g]=(0,X.useState)(!1),_=!!e&&!!i&&!!e.catalog,v=(0,X.useRef)(null);if(_&&v.current===null&&(v.current=!o&&_j(ZA(e),i).length===0&&!!i.defaultChat&&ZA(e).some(e=>e.downloaded)),(0,X.useEffect)(()=>{_&&m.current?.querySelector(`input:not([disabled])`)?.focus()},[_,h]),t&&!_)return V(`div`,{className:`setup-models-error`,children:[P(`p`,{className:`setup-error`,role:`alert`,children:p(`setup.models.listFailed`,{reason:t})}),V(`div`,{className:`setup-row`,children:[P(`button`,{type:`button`,className:`btn-primary`,onClick:n,children:p(`setup.tryAgain`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:r,children:p(`setup.models.useRecommended`)})]}),P(`p`,{className:`setup-hint`,children:p(`setup.models.useRecommendedNote`)})]});if(!_)return P(Lj,{});let y=ZA(e),b=_j(y,i),x=!o&&!i.defaultChat,S=yj(e,i),C=o?[]:y.filter(e=>e.fits===!1&&i.ticked.has(e.id)),w=!h&&!!v.current&&b.length===0,E=p(S?`setup.continueAnyway`:`setup.continue`);return w?V(`div`,{className:`setup-present`,role:`status`,children:[V(`p`,{children:[P(mr,{size:14,"aria-hidden":`true`}),` `,p(`setup.models.allPresent`)]}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>g(!0),children:p(`setup.models.change`)}),V(Gj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:l,disabled:d,children:p(`setup.back`)}),V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>u(!1),disabled:d,children:[d&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,p(`setup.finish`)]})]}),f&&P(`p`,{className:`setup-error`,role:`alert`,children:f})]}):V(`div`,{className:`setup-models`,ref:m,children:[P(`p`,{className:`setup-hint`,children:p(`setup.job.lede`)}),P(Vj,{plan:e,selection:i,onSelection:a,disabled:d}),!o&&P(`button`,{type:`button`,className:`link-btn setup-reset`,onClick:()=>a(gj(e)),disabled:d,children:p(`setup.models.resetRecommended`)}),V(`div`,{className:`setup-models-footer`,children:[P(Nj,{plan:e,selection:i}),V(`label`,{className:`setup-keep-trying`,children:[P(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),disabled:d}),P(`span`,{children:p(`setup.keepTrying`)})]}),P(XA,{open:x,children:P(`p`,{className:`setup-error`,id:`setup-no-chat`,children:p(`setup.models.noChatReason`)})}),C.length>0&&P(`span`,{className:`visually-hidden`,children:C.map(e=>Aj(e,p)).join(` `)}),f&&P(`p`,{className:`setup-error`,role:`alert`,children:f}),V(Gj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:l,disabled:d,children:p(`setup.back`)}),V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>u(!!S),disabled:d||x,"aria-describedby":x?`setup-no-chat`:void 0,children:[d&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,E]})]})]})]})}function rM({plan:e,chatModel:t,gpu:n}){let r=T();if(!e?.catalog)return null;let i=e.catalog,a=e=>e?i.find(t=>t.id===e)?.name??e:null,o=ij(i,{ticked:new Set,unticked:new Set,chatChosen:!1,defaultChat:t,vision:e.vision_model??null}),s=i.find(e=>e.id===o)??i.find(e=>QA(e)&&e.gaia_model),c=i.find(e=>$A(e)&&e.downloaded),l=i.filter(e=>e.gaia_model&&e.planned&&e.skipped),u=n?.pending,d=i.find(e=>e.id===t);return V(`dl`,{className:`setup-summary-list`,children:[t&&V(`div`,{children:[P(`dt`,{children:r(`setup.ready.chat`)}),V(`dd`,{children:[P(`bdi`,{children:a(t)}),d?.recipe===`flm`?` (${r(`setup.models.npu`)})`:``]})]}),V(`div`,{children:[P(`dt`,{children:r(`setup.ready.vision`)}),P(`dd`,{children:s?.downloaded?P(`bdi`,{children:s.name}):r(`setup.ready.visionOff`,{name:s?.name??`Gemma-4-E4B-it`})})]}),c&&V(`div`,{children:[P(`dt`,{children:r(`setup.ready.documents`)}),P(`dd`,{children:P(`bdi`,{children:c.name})})]}),l.length>0&&V(`div`,{children:[P(`dt`,{children:r(`setup.ready.notInstalled`)}),P(`dd`,{children:l.map(e=>e.name).join(`, `)})]}),u?.state===`restart_required`&&V(`div`,{className:`is-warn`,children:[P(`dt`,{children:r(`setup.ready.gpu`)}),V(`dd`,{children:[P(J,{size:13,"aria-hidden":`true`}),` `,Xj(r,n?Yj(n,u.setting_gb):null)]})]}),u?.state===`took_effect`&&V(`div`,{children:[P(`dt`,{children:r(`setup.ready.gpu`)}),P(`dd`,{children:n?.gpu_gb==null?r(`setup.ready.gpuChanged`):r(`setup.ready.gpuNow`,{gb:$(n.gpu_gb)})})]})]})}function iM(e){if(e.skill===`document-brief`){let t=/^(\d+) /.exec(e.note)?.[1];return t?{n:Number(t)}:void 0}if(e.skill===`coding`){let t=/^In (.+)$/.exec(e.note)?.[1];return t?{folder:t}:void 0}}function aM(e,t,n,r){let i=`${n}.one`,a=`${n}.other`,o=N(i)&&N(a)&&typeof r?.n==`number`?r.n===1?i:a:n;return!N(o)||c[o].includes(`{`)&&!r?t:z(o,r)===t?e(o,r):t}function oM(e,t){return{title:aM(t,e.title,`card.${e.skill}.title`),note:aM(t,e.note,`card.${e.skill}.note`,iM(e))}}function sM({text:e}){let t=o(e);return t.length===1?P(D.Fragment,{children:e}):P(D.Fragment,{children:t.map((e,t)=>P(`span`,{className:`start-card-part`,children:e},t))})}function cM({cards:e,onPick:t,disabled:n}){let r=T();return e.length===0?null:P(`ul`,{className:`start-cards`,"aria-label":r(`newChat.cardsLabel`),children:e.map(e=>{let{title:i,note:a}=oM(e,r);return P(`li`,{children:V(`button`,{type:`button`,className:`start-card`,onClick:()=>t(e),disabled:n,title:e.needs_input?`${e.prompt}…`:e.prompt,children:[V(`span`,{className:`start-card-title`,children:[i,P(Jn,{size:13,"aria-hidden":`true`})]}),P(`span`,{className:`start-card-note`,children:P(sM,{text:a})})]})},e.skill)})})}function lM(){let[e,t]=(0,X.useState)(null),[n,r]=(0,X.useState)([]),i=(0,X.useCallback)(()=>{Promise.resolve(Tn()).then(e=>{t(e?.providers?.find(e=>e.id===`amd`)?.network??null),r(e?.providers??[])}).catch(e=>{console.warn(`[useGatewayNetwork] could not check the AMD gateway`,e),t(null)})},[]);return(0,X.useEffect)(i,[i]),{network:e,providers:n,recheck:i}}function uM(e,t,n){return t===`active`?n(`setup.contents.working`):t===`done`?n(`setup.contents.ready`):t===`failed`?n(`setup.contents.failed`):e.installed?n(`setup.contents.alreadyHere`):n(`setup.contents.waiting`)}function dM(e,t){return e==null?t(`setup.contents.sizeOnDownload`):$(e)}function fM({state:e}){return e===`done`?P(mr,{size:13,"aria-hidden":`true`}):e===`active`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):P(e===`failed`?Y:Mr,{size:13,"aria-hidden":`true`})}function pM({id:e,error:t,transient:n,onRetry:r,disabled:i}){let a=T(),o=a(`setup.component.${e}`);return V(`div`,{className:`setup-content-failure`,role:`alert`,children:[P(`p`,{children:a(n?`setup.contents.failedNetwork`:`setup.contents.failedOther`,{name:o})}),t&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:a(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:t})]}),r&&P(`button`,{type:`button`,className:`btn-primary`,onClick:r,disabled:i,"aria-label":a(`setup.contents.retryNamed`,{name:o}),children:a(`setup.progress.retry`)})]})}function mM({plan:e,run:t,models:n=[],onRetry:r,retryDisabled:i}){let a=T();return V(`ul`,{className:`setup-contents`,children:[(e.components??[]).map(e=>{let n=t?.components?.[e.id],o=t!=null&&t.state!==`running`&&t.state!==`verifying`,s=n===`active`&&o?void 0:n;return V(`li`,{className:`setup-content is-${s??(e.installed?`done`:`waiting`)}`,children:[P(`span`,{className:`setup-content-icon`,children:P(fM,{state:s??(e.installed?`done`:void 0)})}),V(`span`,{className:`setup-content-main`,children:[P(`span`,{className:`setup-content-name`,children:a(`setup.component.${e.id}`)}),P(`span`,{className:`setup-content-note`,children:a(`setup.component.${e.id}Note`)}),V(`span`,{className:`setup-content-from`,children:[a(`setup.contents.from`),` `,P(`bdi`,{dir:`ltr`,children:e.source})]})]}),V(`span`,{className:`setup-content-side`,children:[P(`bdi`,{dir:`ltr`,children:dM(e.size_gb,a)}),P(`span`,{children:uM(e,s,a)})]}),s===`failed`&&o&&!t?.problem&&P(pM,{id:e.id,error:t?.error,transient:t?.component_kinds?.[e.id]===`transient`,onRetry:r,disabled:i})]},e.id)}),n.map(e=>V(`li`,{className:`setup-content is-waiting`,children:[P(`span`,{className:`setup-content-icon`,children:P(fM,{state:void 0})}),V(`span`,{className:`setup-content-main`,children:[P(`span`,{className:`setup-content-name`,children:P(`bdi`,{children:e.name})}),P(`span`,{className:`setup-content-note`,children:e.roles.map(e=>a(`setup.purpose.${e}`)).join(` · `)}),e.source&&V(`span`,{className:`setup-content-from`,children:[a(`setup.contents.from`),` `,P(`bdi`,{dir:`ltr`,children:e.source})]})]}),P(`span`,{className:`setup-content-side`,children:P(`bdi`,{dir:`ltr`,children:dM(e.size_gb,a)})})]},e.id))]})}function hM({lines:e,className:t,id:n}){let r=(0,X.useRef)(null),i=(0,X.useRef)(!0),a=e.join(`
|
|
78
|
-
`);return(0,X.useEffect)(()=>{let e=r.current;e&&i.current&&(e.scrollTop=e.scrollHeight)},[a]),P(`pre`,{ref:r,id:n,className:t,dir:`ltr`,tabIndex:0,onScroll:e=>{let t=e.currentTarget;i.current=t.scrollHeight-t.scrollTop-t.clientHeight<8},children:a})}var
|
|
79
|
-
`):e.error})]}),u?P(`p`,{className:`dl-detail`,children:p(`setup.progress.retryLater`)}):V(`div`,{className:`setup-row`,children:[a&&V(`button`,{type:`button`,className:`btn-primary`,disabled:l,onClick:()=>a(e.id,e.error_kind),"aria-describedby":m,children:[P(za,{size:13,"aria-hidden":`true`}),` `,p(`setup.progress.retry`)]}),s&&P(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:()=>s(e.id),children:p(`setup.progress.skipModel`)})]})]}),e.state===`cancelled`&&o&&P(`div`,{className:`setup-row`,children:P(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:()=>o(e.id),children:p(`setup.progress.resume`)})}),S>=60&&c&&P(`div`,{className:`setup-row`,children:V(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:c,children:[P(za,{size:13,"aria-hidden":`true`}),` `,p(`setup.progress.retry`)]})})]})}function EM({status:e,names:t,freeGb:n=null,onCancel:r,onRetry:i,onResume:a,onResumeAll:o,onSkip:s,onRestart:c,busy:l=!1,retryLater:u=!1,labelledBy:d}){let f=T(),p=JA(),m=(0,X.useMemo)(()=>yM(e.models??[]),[e.models]),h=(0,X.useRef)(new Map),g=(0,X.useRef)(new Map),_=(0,X.useRef)(new BS),v=(0,X.useRef)(!1),[y,b]=(0,X.useState)(()=>Date.now()),[x,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(null),E=i&&((e,t)=>{let n=m.find(t=>t.id===e);t===`verify`&&n?w(n):i(e,t)}),[D,O]=(0,X.useState)(``),[k,A]=(0,X.useState)(``),j=(0,X.useRef)(null),M=e.state===`verifying`||e.state!==`running`&&m.some(e=>e.state===`verifying`),N=(0,X.useRef)(new Map);(0,X.useEffect)(()=>{if(!p||!(m.some(e=>e.retrying_until)||M))return;let e=setInterval(()=>b(Date.now()),1e3);return()=>clearInterval(e)},[m,p,M]);let F=e.overall,{estimates:I,overallEstimate:L}=(0,X.useMemo)(()=>{let e=Date.now(),t={};for(let n of m){if(n.state!==`downloading`){h.current.delete(n.id);continue}let r=h.current.get(n.id),i=n.downloaded_before_gb??null;(!r||g.current.get(n.id)!==i)&&(r=new BS,h.current.set(n.id,r),g.current.set(n.id,i)),t[n.id]=r.update(n.bytes_done,n.bytes_total,e)}let n=m.some(e=>e.state===`downloading`);n&&!v.current&&(_.current=new BS),v.current=n;let r=m.filter(e=>e.state===`downloading`||e.state===`queued`).reduce((e,t)=>e+Math.max(0,t.bytes_total-t.bytes_done),0);return{estimates:t,overallEstimate:n&&F?_.current.update(F.bytes_done,F.bytes_done+r,e):void 0}},[m,F]);(0,X.useEffect)(()=>{let e=new Map(m.map(e=>[e.id,e.state])),n=Math.floor((F?.percent??0)/25),r=j.current;if(j.current={states:e,quarter:n},!r)return;let i=[];for(let e of m){if(r.states.get(e.id)===e.state)continue;let n=t[e.id]??e.id;e.state===`failed`?A(f(`setup.progress.announceFailed`,{name:n})):i.push(f(`setup.progress.announceState`,{name:n,state:f(SM[e.state])}))}n>r.quarter&&n>0&&n<4&&i.push(f(`setup.progress.announceOverall`,{n:String(n*25)})),i.length&&O(i.join(`. `))},[m,F?.percent,t,f]);let ee=e=>{if(!M)return N.current.delete(e),0;let t=Date.now(),n=N.current.get(e)??t;return N.current.set(e,n),Math.floor((t-n)/1e3)},R=CM(e),z=m.filter(e=>e.state===`cancelled`),B=F?.failed??m.filter(e=>e.state===`failed`).length,te=F?.percent??0,ne=()=>{(F?.bytes_done??0)>gM?S(!0):r?.()},re=f.compose(e=>[e(`setup.progress.overallPct`,{n:String(te)}),F&&F.bytes_total>0?e(`setup.progress.of`,{done:PS(F.bytes_done),total:PS(F.bytes_total)}):null,R&&L?.speed?IS(f.locale,FS(L.speed)):null,R?L?.eta==null?e(`setup.progress.estimating`):e(`setup.progress.left`,{eta:LS(L.eta,e)}):null,B>0?e(`setup.progress.failedCount`,{n:String(B)}):null].filter(Boolean).join(` · `));return V(`section`,{className:`dl${p?``:` is-paused`}`,"aria-labelledby":d,children:[V(`div`,{className:`dl-overall`,children:[P(`p`,{className:`dl-overall-line`,children:P(`bdi`,{children:re})}),P(`div`,{className:`dl-track is-overall${m.some(e=>e.state===`downloading`)?` is-live`:``}`,role:`progressbar`,"aria-label":f(`setup.progress.overallLabel`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":te,"aria-valuetext":f(`setup.progress.percent`,{n:String(te)}),children:P(`span`,{className:`dl-fill`,style:{inlineSize:`${te}%`}})})]}),P(`ul`,{className:`dl-list`,children:m.map(e=>P(TM,{model:e,name:t[e.id]??e.id,estimate:I[e.id],now:y,freeGb:n,onRetry:E,onResume:R?void 0:a,onSkip:s,onRestart:c,busy:l,retryLater:u,checking:M,checkingFor:ee(e.id)},e.id))}),R&&P(`p`,{className:`setup-hint dl-controls`,children:f(`setup.progress.keepsGoing`)}),(R&&r||!R&&z.length>0&&o)&&V(Gj,{children:[R&&r&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:ne,disabled:l,children:f(`setup.progress.cancel`)}),!R&&z.length>0&&o&&P(`button`,{type:`button`,className:`btn-primary`,onClick:o,disabled:l,children:f(`setup.progress.resumeAll`)})]}),P(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:D}),P(`span`,{className:`visually-hidden`,role:`alert`,children:k}),x&&P(Kj,{title:f(`setup.progress.cancelTitle`),confirmLabel:f(`setup.progress.cancelConfirm`),cancelLabel:f(`setup.progress.cancelKeep`),onConfirm:()=>{S(!1),r?.()},onCancel:()=>S(!1),children:P(`p`,{children:f(`setup.progress.cancelBody`)})}),C&&P(Kj,{title:f(`setup.redownload.title`,{name:t[C.id]??C.id}),confirmLabel:f(`setup.redownload.confirm`),cancelLabel:f(`setup.redownload.keep`),onConfirm:()=>{let e=C;w(null),i?.(e.id,`verify`)},onCancel:()=>w(null),children:P(`p`,{children:f(`setup.redownload.body`,{name:t[C.id]??C.id,size:PS(C.bytes_total)})})})]})}var DM=[`check`,`download`,`test`],OM={root:`setup-report`,button:`btn-secondary setup-report-button`,hint:`setup-hint`,error:`setup-error`};function kM({run:e,before:t={}}){let n=T(),[r,i]=(0,X.useState)(()=>new Set),a=e=>i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),o=n=>[...t[n]??[],...e?.logs?.[n]??[]],s=DM.filter(e=>o(e).length>0);return V(`section`,{className:`setup-logs`,"aria-label":n(`setup.logs.title`),children:[s.map(e=>{let t=o(e),i=r.has(e);return V(`div`,{className:`setup-log`,children:[V(`button`,{type:`button`,className:`setup-log-toggle`,onClick:()=>a(e),"aria-expanded":i,children:[P(br,{size:13,className:i?`is-open`:``,"aria-hidden":`true`}),` `,n(`setup.logs.${e}`)]}),i&&P(hM,{lines:t,className:`setup-log-pre`})]},e)}),P(rC,{classes:OM,note:n(`setup.logs.reportNote`)})]})}function AM(){let e=T(),t=k(e=>e.locale),n=k(e=>e.setLocale);return V(`label`,{className:`setup-language`,children:[P(Ki,{size:14,"aria-hidden":`true`}),P(`span`,{className:`visually-hidden`,children:e(`settings.language`)}),P(`select`,{value:t,onChange:e=>n(e.target.value),children:b.map(({meta:e})=>P(`option`,{value:e.code,lang:e.code,dir:e.dir,children:M(e)},e.code))})]})}var jM={driver:[`setup.npu.problem.driver`,`setup.npu.fix.driver`],device:[`setup.npu.problem.device`,`setup.npu.fix.device`],firmware:[`setup.npu.problem.firmware`,`setup.npu.fix.firmware`],access:[`setup.npu.problem.access`,`setup.npu.fix.access`],memlock:[`setup.npu.problem.memlock`,`setup.npu.fix.memlock`],runtime:[`setup.npu.problem.runtime`,`setup.npu.fix.runtime`]},MM={cancelled:`setup.npu.fixError.cancelled`,timeout:`setup.npu.fixError.timeout`,not_authorized:`setup.npu.fixError.notAuthorized`,no_pkexec:`setup.npu.fixError.noPkexec`};function NM({problem:e}){let t=T(),n=jM[e.code];if(!n)return V(`li`,{children:[P(`strong`,{children:e.title}),` `,e.fix]});let r=e.params,i=n[1];e.code===`access`&&r.group&&(i=`setup.npu.fix.accessGroup`);let a=n[0];return e.code===`memlock`&&r.fix===`restart`&&(a=`setup.npu.problem.memlockStill`,i=`setup.npu.fix.memlockRestart`),e.code===`memlock`&&r.fix===`stuck`&&(a=`setup.npu.problem.memlockStuck`,i=`setup.npu.fix.memlockStuck`),V(`li`,{children:[P(`strong`,{children:t(a,{device:r.device??``,limit:r.limit??``,version:r.version??``,detail:r.detail??``})}),` `,t(i,{group:r.group??``})]})}function PM({problems:e,disabled:t,onRecheck:n,id:r=`setup-npu-problems`}){let i=T(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),l=e.some(e=>e.code===`memlock`&&e.params.fix===`apply`),u=async(e,t)=>{o(!0),c(null);try{await e(),n?.()}catch(e){let n=e instanceof yn?e.body?.code:void 0,r=n&&n in MM?MM[n]:t;c(i(r))}finally{o(!1)}};return V(`div`,{className:`setup-npu-problems`,id:r,role:`note`,children:[P(`p`,{children:i(`setup.npu.notReady`)}),P(`ul`,{children:e.map(e=>P(NM,{problem:e},e.code))}),P(`p`,{className:`setup-hint`,children:i(`setup.npu.meanwhile`)}),s&&P(`p`,{className:`setup-npu-error`,role:`alert`,children:s}),V(`div`,{className:`setup-npu-actions`,children:[l&&P(`button`,{type:`button`,className:`btn-primary`,disabled:t||a,onClick:()=>void u(Ze,`setup.npu.fixError.failed`),children:i(`setup.npu.fixMemlock`)}),n&&P(`button`,{type:`button`,className:`btn-secondary`,disabled:t||a,onClick:()=>void u(xe,`setup.npu.recheckFailed`),children:i(`setup.npu.recheck`)})]})]})}async function FM(){let e=await be();e.reachable&&(e.available_backends??[]).some(e=>e.name===`vulkan`)&&(e.preferred_backend??e.default_backend)!==`vulkan`&&await Fe(`vulkan`)}function IM({plan:e,selection:t,onSelection:n,disabled:r=!1,onRecheck:i}){let a=T(),o=ZA(e),s=e.npu?.present&&!e.npu.ready?e.npu.problems:[],c=s.length?void 0:o.find(e=>ej(e)&&e.gaia_model&&e.chat_choice&&e.fits!==!1)??o.find(e=>ej(e)&&e.chat_choice&&e.downloaded&&!tj(e)),l=!s.length&&!c&&o.some(e=>ej(e)&&e.fit_code===`npu`),u=!!o.find(e=>e.id===t.defaultChat&&ej(e)),d=gj(e).defaultChat,f=d&&!o.find(e=>e.id===d&&ej(e))?d:o.find(e=>e.chat_choice&&e.gaia_model&&e.support===`verified`&&!ej(e))?.id,p=e=>{e===`npu`&&c&&!u&&n(oj(t,o,c.id)),e===`gpu`&&u&&f&&n(oj(t,o,f))},m=[{id:`gpu`,label:a(`setup.backend.gpu`)},...c?[{id:`npu`,label:a(`setup.backend.npu`)}]:[],...s.length?[{id:`npu`,label:a(`setup.backend.npu`),unavailable:!0}]:[]],h=u?`npu`:`gpu`;return V(`section`,{className:`setup-backend`,"aria-labelledby":`setup-backend-title`,children:[P(`h3`,{className:`mc-job-title`,id:`setup-backend-title`,children:a(`setup.backend.title`)}),P(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`setup-backend-title`,children:m.map(e=>P(`button`,{type:`button`,role:`radio`,"aria-checked":h===e.id,"aria-describedby":e.unavailable?`setup-npu-problems`:void 0,className:h===e.id?`is-active`:``,disabled:r||e.unavailable,onClick:()=>p(e.id),children:P(`bdi`,{children:e.label})},e.id))}),s.length>0?P(PM,{problems:s,disabled:r,onRecheck:i}):P(`p`,{className:`setup-hint`,children:a(c?`setup.backend.hint`:l?`setup.backend.hintNpuUnusable`:`setup.backend.hintNoNpu`)})]})}var LM=({children:e})=>P(`bdi`,{dir:`ltr`,children:e});function RM({label:e,children:t}){return V(`div`,{className:`found-row`,children:[P(`dt`,{children:e}),P(`dd`,{children:t})]})}function zM(e){return e.family?`${e.name} (${e.family})`:e.name}var BM=[[`llamacpp`,`llama.cpp`],[`flm`,`FastFlowLM`],[`whispercpp`,`whisper.cpp`],[`kokoro`,`Kokoro`],[`sd-cpp`,`stable-diffusion.cpp`]],VM=new Set([`llamacpp`,`flm`]);function HM(e){let t=[];for(let[n,r]of BM){let i=(e.backends??[]).find(e=>e.recipe===n&&e.default);i&&i.state!==`unsupported`&&t.push({name:r,b:i})}return t}function UM(e,t){return e?e.kind===`release_candidate`&&e.rc?`${e.version.replace(/rc\d+$/,``)} RC ${e.rc}`:e.kind===`source`&&e.commit?`${e.version} (${e.commit})`:e.version:t??null}var WM={release:`release`,release_candidate:`release candidate`,local:`local build`,source:`from source`};function GM(e,t){let n=e.system,r=e=>(n?.devices??[]).filter(t=>t.available&&e(t.kind)),i=r(e=>e.endsWith(`gpu`)),a=r(e=>e.endsWith(`npu`)),o=HM(e);return{sys:n,cpu:r(e=>e===`cpu`)[0],gpus:i,npus:a,runsOn:i[0]?.name??t?.gpu_name??null,npu:a[0]??null,runtimes:o,gaia:UM(n?.gaia_build,n?.gaia_version),build:n?.gaia_build?.kind??null,software:[UM(n?.gaia_build,n?.gaia_version)?`GAIA ${UM(n?.gaia_build,n?.gaia_version)}`:null,n?.lemonade_version?`Lemonade ${n.lemonade_version}`:null,...o.filter(({b:e})=>VM.has(e.recipe)&&qM(e)).map(({name:e,b:t})=>`${e} ${t.version??t.backend}`)].filter(e=>!!e),totalMemory:MS(n?.physical_memory,t?.ram_gb),freeGb:e.disk?.free_gb??t?.disk_free_gb??null,modelsPath:e.disk?.path??null,gaiaHome:n?.gaia_home??null}}var KM={installed:`installed`,update_required:`installed, updates on first use`},qM=e=>e.state===`installed`||e.state===`update_required`,JM={chat:`setup.job.chat`,vision:`setup.job.vision`,embedding:`setup.job.documents`,speech:`setup.job.speech`,voice:`setup.job.voice`,image_creation:`setup.job.images`};function YM(e,t){let n=GM(e,t),r=e.lemonade.mode===`external`?`the user's own`:`GAIA's own`;return[`GAIA: ${n.gaia??`unknown`}${n.build?`, ${WM[n.build]}`:``} (agent ${n.sys?.agent_version??`not installed yet`})`,`Model server: ${r} Lemonade ${n.sys?.lemonade_version??`(version not reported)`}${e.lemonade.url?` at ${e.lemonade.url}`:``}`,...n.runtimes.map(({name:e,b:t})=>`${e}: ${t.backend}${t.version?` ${t.version}`:``} (${KM[t.state??``]??`not installed`})`),`OS: ${n.sys?.os??t?.os??`unknown`}`,`Processor: ${n.cpu?.name??n.sys?.processor??`unknown`}${n.cpu?.cores?` (${n.cpu.cores} cores, ${n.cpu.threads??n.cpu.cores} threads)`:``}`,`Graphics: ${n.gpus.map(zM).join(`; `)||t?.gpu_name||`none found`}`,`NPU: ${n.npus.map(zM).join(`; `)||`none found`}`,`Memory: ${n.totalMemory??`unknown`}${e.capacity_gb==null?``:`, ${$(e.capacity_gb)} for models${e.memory_source?` (${e.memory_source})`:``}`}`,`Models folder: ${n.modelsPath??`unknown`}${n.freeGb==null?``:` (${$(n.freeGb)} free)`}`,`GAIA data and logs: ${n.gaiaHome??`unknown`}`].join(`
|
|
80
|
-
`)}function XM({plan:e,hardware:t,onChangeMemory:n}){let r=T(),i=GM(e,t),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),d=async e=>{u(null);try{await Dn(e,!1)}catch(e){u(r(`setup.found.openFailed`,{error:e instanceof Error?e.message:String(e)}))}},f=P(`span`,{className:`found-muted`,children:r(`setup.found.unknown`)}),p=[...t?.blockers??[],...(t?.warnings??[]).filter(e=>t?.lemonade_running||!/\bNPU\b/.test(e))],m=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{m.current&&clearTimeout(m.current)},[]);let h=e=>{c(e),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>c(null),2e3)};return V(`section`,{className:`setup-card found`,"aria-label":r(`setup.found.title`),children:[V(`div`,{className:`found-head`,children:[P(`h3`,{className:`mc-job-title`,children:r(`setup.found.title`)}),P(`button`,{type:`button`,className:`found-copy`,onClick:()=>{navigator.clipboard.writeText(YM(e,t)).then(()=>h(`done`),e=>{console.warn(`[DetectedSummary] could not copy the details`,e),h(`failed`)})},"aria-label":r(`setup.found.copy`),title:r(`setup.found.copy`),children:P(s===`done`?mr:Br,{size:14,"aria-hidden":`true`})}),s&&P(`span`,{className:`found-copied`,role:`status`,children:r(s===`done`?`setup.found.copied`:`setup.found.copyFailed`)})]}),V(`dl`,{className:`found-glance`,children:[V(RM,{label:r(`setup.found.runsOn`),children:[i.runsOn?P(LM,{children:i.runsOn}):f,i.npu&&P(`span`,{className:`found-chip`,children:P(LM,{children:`NPU`})})]}),V(RM,{label:r(`setup.found.memory`),children:[e.capacity_gb!=null&&i.totalMemory?r(`setup.found.memoryOf`,{size:$(e.capacity_gb),total:i.totalMemory}):e.capacity_gb==null?i.totalMemory?P(LM,{children:i.totalMemory}):f:P(LM,{children:$(e.capacity_gb)}),n&&P(`button`,{type:`button`,className:`link-btn found-link`,onClick:n,children:r(`setup.found.changeMemory`)})]}),P(RM,{label:r(`setup.found.space`),children:i.freeGb==null?f:P(LM,{children:$(i.freeGb)})}),V(RM,{label:r(`setup.found.software`),children:[i.software.length?P(LM,{children:i.software.join(` · `)}):f,i.build&&i.build!==`release`&&P(`span`,{className:`found-chip`,children:r(`setup.found.build.${i.build}`)})]})]}),V(`div`,{className:`found-paths`,children:[[[`setup.found.modelsFolder`,i.modelsPath],[`setup.found.gaiaFolder`,i.gaiaHome]].map(([e,t])=>t&&V(`button`,{type:`button`,className:`link-btn found-open`,onClick:()=>void d(t),title:t,children:[P(bi,{size:13,"aria-hidden":`true`}),` `,r(e)]},e)),l&&P(`p`,{className:`setup-error`,role:`alert`,children:l})]}),p.length>0&&V(`details`,{className:`dl-details found-warnings`,children:[V(`summary`,{children:[P(wr,{size:13,"aria-hidden":`true`}),` `,r(`setup.found.noticed`)]}),P(`ul`,{children:p.map(e=>P(`li`,{children:P(LM,{children:e})},e))})]}),V(`button`,{type:`button`,className:`setup-log-toggle found-more`,onClick:()=>o(e=>!e),"aria-expanded":a,children:[P(br,{size:13,className:a?`is-open`:``,"aria-hidden":`true`}),` `,r(`setup.found.details`)]}),a&&V(`div`,{className:`found-details`,children:[P(`h4`,{className:`found-group`,children:r(`setup.found.software`)}),V(`dl`,{className:`found-list`,children:[V(RM,{label:P(LM,{children:`GAIA`}),children:[i.gaia?P(LM,{children:i.gaia}):f,i.build&&i.build!==`release`&&P(`span`,{className:`found-chip`,children:r(`setup.found.build.${i.build}`)})]}),P(RM,{label:r(`setup.found.agent`),children:i.sys?.agent_version?P(LM,{children:i.sys.agent_version}):P(`span`,{className:`found-muted`,children:r(`setup.found.agentLater`)})}),V(RM,{label:r(`setup.found.server`),children:[e.lemonade.mode===`external`?r(`setup.found.serverYours`):r(`setup.found.serverOwn`),i.sys?.lemonade_version&&V(D.Fragment,{children:[` `,P(LM,{children:i.sys.lemonade_version})]}),e.lemonade.url&&P(`span`,{className:`found-sub`,children:P(LM,{children:e.lemonade.url})})]})]}),P(`h4`,{className:`found-group`,children:r(`setup.found.runtime`)}),i.runtimes.length?P(`div`,{className:`found-table-wrap`,children:V(`table`,{className:`found-table`,children:[P(`thead`,{className:`visually-hidden`,children:V(`tr`,{children:[P(`th`,{scope:`col`,children:r(`setup.found.col.runtime`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.device`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.version`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.state`)})]})}),P(`tbody`,{children:i.runtimes.map(({name:e,b:t})=>V(`tr`,{children:[P(`th`,{scope:`row`,children:P(LM,{children:e})}),P(`td`,{children:P(LM,{children:t.backend})}),P(`td`,{children:P(LM,{children:t.version??``})}),P(`td`,{className:qM(t)?`is-installed`:void 0,children:r(qM(t)?`setup.pc.backend.installed`:`setup.pc.backend.available`)})]},t.recipe))})]})}):P(`p`,{className:`found-muted`,children:r(`setup.found.unknown`)}),P(`h4`,{className:`found-group`,children:r(`setup.found.models`)}),(e.catalog??[]).length?P(`div`,{className:`found-table-wrap`,children:V(`table`,{className:`found-table`,children:[P(`thead`,{className:`visually-hidden`,children:V(`tr`,{children:[P(`th`,{scope:`col`,children:r(`setup.found.col.model`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.job`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.tested`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.size`)}),P(`th`,{scope:`col`,children:r(`setup.found.col.state`)})]})}),P(`tbody`,{children:(e.catalog??[]).map(e=>V(`tr`,{children:[P(`th`,{scope:`row`,title:e.id,children:P(`bdi`,{children:e.name})}),P(`td`,{children:e.roles.map(e=>r(JM[e])).join(` · `)}),V(`td`,{children:[e.support===`verified`&&P(`span`,{className:`mc-chip is-verified`,children:r(`setup.label.verified`)}),e.support===`untested`&&P(`span`,{className:`mc-chip is-untested`,children:r(`setup.label.untested`)})]}),P(`td`,{children:P(LM,{children:e.full_size_gb??e.size_gb?$(e.full_size_gb??e.size_gb):``})}),P(`td`,{className:e.downloaded?`is-installed`:void 0,children:r(e.downloaded?`setup.models.status.onPc`:`setup.found.notDownloaded`)})]},e.id))})]})}):P(`p`,{className:`found-muted`,children:r(`setup.found.unknown`)}),P(`h4`,{className:`found-group`,children:r(`setup.found.hardware`)}),V(`dl`,{className:`found-list`,children:[P(RM,{label:r(`setup.found.os`),children:i.sys?.os??t?.os?P(LM,{children:i.sys?.os??t?.os}):f}),V(RM,{label:r(`setup.found.cpu`),children:[i.cpu||i.sys?.processor?P(LM,{children:i.cpu?.name??i.sys?.processor}):f,i.cpu?.cores?P(`span`,{className:`found-sub`,children:r(`setup.found.cores`,{cores:String(i.cpu.cores),threads:String(i.cpu.threads??i.cpu.cores)})}):null]}),P(RM,{label:r(`setup.found.gpu`),children:i.gpus.length?P(LM,{children:i.gpus.map(zM).join(`; `)}):P(`span`,{className:`found-muted`,children:r(`setup.found.none`)})}),P(RM,{label:r(`setup.found.npu`),children:i.npus.length?P(LM,{children:i.npus.map(zM).join(`; `)}):P(`span`,{className:`found-muted`,children:r(`setup.found.none`)})})]})]})]})}function ZM({state:e}){return e===`done`?P(mr,{size:13,"aria-hidden":`true`}):e===`active`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):P(e===`failed`?Y:e===`question`?Ar:Mr,{size:13,"aria-hidden":`true`})}function QM({hardware:e,hardwareError:t,plan:n,serverRun:r,awaitingChoice:i=!1}){let a=T(),[o,s]=(0,X.useState)(!1),c=!!n?.lemonade.reachable,l=r?.state===`failed`||r?.state===`cancelled`,u=a(n?.lemonade.mode===`external`?`setup.found.serverYours`:`setup.found.serverOwn`),d=n?.system?.lemonade_version?a(`setup.checks.serverFound`,{version:n.system.lemonade_version,whose:u}):u,f=e?`done`:t?`failed`:`active`,p=[e?.gpu_name,e?.npu_detected?a(`setup.checks.npu`):null].filter(Boolean).join(` · `),m=t?null:n?.capacity_gb==null?c?MS(n?.system?.physical_memory,e?.ram_gb):null:$(n.capacity_gb),h=t?`failed`:m?`done`:l?`failed`:i?`waiting`:`active`,g=[{id:`device`,label:a(`setup.checks.device`),value:t?`${a(`setup.system.unread`)} ${t}`:p||null,state:f},{id:`memory`,label:a(`setup.found.memory`),value:m,state:h},{id:`disk`,label:a(`setup.checks.disk`),value:e?.disk_free_gb==null?null:a(`setup.checks.diskValue`,{size:IS(a.locale,`${Math.round(e.disk_free_gb)} GB`)}),state:f},{id:`server`,label:a(`setup.checks.server`),value:c?d:i?a(`setup.checks.serverChoose`):null,state:c?`done`:l?`failed`:i?`question`:e?`active`:`waiting`},{id:`models`,label:a(`setup.checks.backends`),value:c&&n?.catalog?a(`setup.checks.backendsValue`,{models:String(n.catalog.length),downloaded:String(n.catalog.filter(e=>e.downloaded).length)}):null,state:c&&n?.catalog?`done`:c?`active`:`waiting`}],_=g.filter(e=>e.state===`done`).length,v=Math.round(_/g.length*100),y=P(`ul`,{className:`setup-rows`,id:`setup-check-rows`,children:g.map(e=>V(`li`,{className:`setup-result is-${e.state}`,children:[P(ZM,{state:e.state}),P(`span`,{className:`setup-result-label`,children:e.label}),e.value&&P(`bdi`,{className:`setup-result-value`,children:e.value})]},e.id))});return _===g.length?V(`section`,{className:`setup-card setup-checks-done`,"aria-label":a(`setup.check.title`),children:[P(`p`,{className:`setup-result is-done`,role:`status`,children:V(`button`,{type:`button`,className:`setup-checks-toggle`,"aria-expanded":o,"aria-controls":`setup-check-rows`,onClick:()=>s(e=>!e),children:[P(mr,{size:13,"aria-hidden":`true`}),P(`span`,{className:`setup-result-label`,children:a(`setup.checks.allPassed`,{n:String(g.length)})}),P(br,{size:13,className:o?`is-open`:``,"aria-hidden":`true`})]})}),o&&y]}):V(`section`,{className:`setup-card`,"aria-label":a(`setup.check.title`),children:[V(`div`,{className:`setup-bar-head`,children:[P(`span`,{children:a(`setup.checks.count`,{done:String(_),total:String(g.length)})}),V(`bdi`,{dir:`ltr`,children:[v,`%`]})]}),P(`progress`,{className:`setup-progress`,max:100,value:v,"aria-label":a(`setup.check.title`)}),y]})}function $M({steps:e}){let t=T();return V(`nav`,{className:`setup-rail`,"aria-label":t(`setup.rail.label`),children:[P(`p`,{className:`setup-rail-title`,children:t(`setup.title`)}),P(`ol`,{className:`setup-rail-list`,children:e.map((e,t)=>{let n=e.status===`done`?P(mr,{size:13,"aria-hidden":`true`}):e.status===`active`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):e.status===`failed`?P(wr,{size:13,"aria-hidden":`true`}):t+1,r=V(D.Fragment,{children:[P(`span`,{className:`setup-rail-num`,children:n}),P(`span`,{children:e.label})]}),i=`setup-rail-step is-${e.status}${e.shown?` is-shown`:``}`,a=e.shown?`step`:void 0;return P(`li`,{children:e.onOpen?P(`button`,{type:`button`,className:i,onClick:e.onOpen,children:r}):P(`span`,{className:i,"aria-current":a,children:r})},e.id)})})]})}var eN={memory:`setup.test.why.memory`,broken:`setup.test.why.broken`,stuck:`setup.test.why.stuck`,missing:`setup.test.why.missing`,agent:`setup.test.why.agent`,answer:`setup.test.why.answer`,window:`setup.test.why.window`};function tN(e,t){return t(`setup.test.job.${e}`)}function nN({state:e}){return e===`passed`?P(mr,{size:13,"aria-hidden":`true`}):e===`running`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):P(e===`failed`?Y:e===`skipped`?da:Mr,{size:13,"aria-hidden":`true`})}function rN(e,t){return e.state===`running`?t(`setup.test.running`):e.state===`failed`?t(`setup.test.failed`):e.state===`skipped`?t(`setup.test.skipped`):e.seconds==null?t(`setup.test.passed`):t(`setup.test.passedIn`,{seconds:String(Math.round(e.seconds))})}function iN({run:e,expected:t,names:n,catalog:r,onRetry:i,onChooseAnother:a,onCancel:o,onDownloadAgain:s,busy:c}){let l=T(),u=e.tests??[],d=new Set(u.map(e=>e.job)),f=t.filter(e=>!d.has(e)),p=u.filter(e=>e.state!==`running`).length,m=Math.max(u.length+f.length,1),h=Math.round(p/m*100),g=u.filter(e=>e.state===`failed`).filter(e=>!r.find(t=>t.id===e.subject)?.roles.some(e=>[`speech`,`voice`,`image_creation`].includes(e))),_=e.state===`failed`||e.state===`cancelled`,v=s?[...new Set(g.filter(e=>e.kind===`broken`&&e.subject).map(e=>e.subject))]:[],[y,b]=(0,X.useState)(null),x=r.find(e=>e.id===y)?.full_size_gb,S=_&&e.components?.agent===`failed`,C=g.some(e=>e.subject&&e.kind!==`missing`);return V(D.Fragment,{children:[V(`section`,{className:`setup-card`,"aria-label":l(`setup.test.title`),children:[V(`div`,{className:`setup-bar-head`,children:[P(`span`,{children:l(`setup.test.count`,{done:String(p),total:String(m)})}),V(`bdi`,{dir:`ltr`,children:[h,`%`]})]}),P(`progress`,{className:`setup-progress`,max:100,value:h,"aria-label":l(`setup.test.title`)}),V(`ul`,{className:`setup-rows`,children:[u.map(e=>V(`li`,{className:`setup-result is-${e.state}`,children:[P(nN,{state:e.state}),V(`span`,{className:`setup-result-label`,children:[tN(e.job,l),e.subject&&V(`bdi`,{className:`setup-result-model`,children:[` `,n[e.subject]??e.subject]})]}),P(`span`,{className:`setup-result-value`,children:rN(e,l)}),e.error&&V(`div`,{className:`setup-result-error`,children:[P(`p`,{children:l(e.kind===`broken`&&!s?`setup.test.why.brokenYours`:eN[e.kind??``]??`setup.test.why.other`)}),V(`details`,{className:`dl-details`,children:[P(`summary`,{children:l(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:e.error})]})]})]},`${e.job}:${e.subject??``}`)),f.map(e=>e===`agent`&&S?V(`li`,{className:`setup-result is-failed`,children:[P(nN,{state:`failed`}),P(`span`,{className:`setup-result-label`,children:tN(e,l)}),P(`span`,{className:`setup-result-value`,children:l(`setup.test.failed`)}),P(`div`,{className:`setup-result-error`,children:P(`p`,{children:l(`setup.test.why.hub`)})})]},e):V(`li`,{className:`setup-result is-waiting`,children:[P(nN,{state:`waiting`}),P(`span`,{className:`setup-result-label`,children:tN(e,l)}),P(`span`,{className:`setup-result-value`,children:l(`setup.test.waiting`)})]},e))]})]}),e.state===`verifying`&&o&&P(Gj,{children:P(`button`,{type:`button`,className:`btn-secondary`,onClick:o,disabled:c,children:l(`setup.progress.cancel`)})}),_&&V(`div`,{className:`setup-failure`,role:`alert`,children:[P(`p`,{children:e.state===`cancelled`?l(`setup.test.cancelled`):g.some(e=>e.kind===`memory`)?l(`setup.test.failedMemory`):l(`setup.test.failedHelp`)}),V(Gj,{children:[C&&a&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:a,disabled:c,children:l(`setup.test.chooseAnother`)}),P(`button`,{type:`button`,className:v.length?`btn-secondary`:`btn-primary`,onClick:i,disabled:c,children:l(`setup.test.tryAgain`)}),v.map(e=>P(`button`,{type:`button`,className:`btn-primary setup-wrap-btn`,onClick:()=>b(e),disabled:c,children:v.length===1?l(`setup.test.downloadItAgain`):l(`setup.test.downloadAgain`,{name:n[e]??e})},e))]})]}),y&&P(Kj,{title:l(`setup.redownload.title`,{name:n[y]??y}),confirmLabel:l(`setup.redownload.confirm`),cancelLabel:l(`setup.redownload.keep`),onConfirm:()=>{let e=y;b(null),s?.(e)},onCancel:()=>b(null),children:P(`p`,{children:l(`setup.redownload.body`,{name:n[y]??y,size:x==null?``:$(x)})})})]})}var aN=`https://app.fireworks.ai/settings/users/api-keys`,oN=`https://amd-gaia.ai/docs/guides/llm-gateway`,sN=[{id:`local`,title:`setup.where.local`,note:`setup.where.localNote`},{id:`fireworks`,title:`Fireworks AI`,note:`setup.where.fireworksNote`},{id:`amd`,title:`AMD LLM Gateway`,note:`setup.where.amdNote`}];function cN(e,t){return N(e.title)?t(e.title):e.title}var lN=1e3,uN=`gaia-setup-choice`;function dN(){try{let e=localStorage.getItem(uN);return e===`local`||e===`fireworks`||e===`amd`?e:null}catch(e){return console.warn(`[SetupScreen] could not read the saved provider choice`,e),null}}function fN(e){try{localStorage.setItem(uN,e)}catch(e){console.warn(`[SetupScreen] could not save the provider choice; a reload will ask again`,e)}}var pN=[`ok`,`needs_key`,`too_old`];function mN({onChosen:e,onNothingToOffer:t,onFound:n,canInstallOwn:r=!0}){let i=T(),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)([]),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!1),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),E=(0,X.useRef)(!0),O=(0,X.useCallback)(async()=>{c(null);try{let e=await ce();if(!e.offer){t?.();return}f(!0);let{found:r,unchecked:i=[]}=await tt();if(!E.current)return;u(r?[]:i),r&&pN.includes(r.status)?(o({target:e,found:r}),n?.(r),g(r.status===`needs_key`),r.status===`too_old`&&t?.()):i.length===0&&t?.()}catch(e){E.current&&c(e instanceof Error?e.message:String(e))}finally{E.current&&f(!1)}},[t,n]);(0,X.useEffect)(()=>(E.current=!0,O(),()=>{E.current=!1}),[O]);let k=(0,X.useCallback)(async t=>{if(a){b(t),S(null);try{await Ee(t===`external`?{mode:t,base_url:a.found.url,api_key:p.trim()||void 0}:{mode:t}),m(``),w(t),e(t)}catch(e){UA(e)&&g(!0),S(e instanceof Error?e.message:String(e))}finally{b(null)}}},[a,p,e]);if(s||l.length>0)return V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:s?i(`setup.offer.checkFailed`):i(`setup.offer.noAnswer`,{url:l.join(`, `)})}),s&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:i(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:s})]}),V(Gj,{children:[V(`button`,{type:`button`,className:`btn-secondary`,disabled:d,onClick:()=>void O(),children:[d&&P(q,{size:13,className:`spin`}),` `,i(`setup.offer.checkAgain`)]}),t&&r&&P(`button`,{type:`button`,className:`btn-primary`,disabled:d,onClick:t,children:i(`setup.offer.useOwn`)})]})]});if(!a)return d?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,i(`setup.offer.looking`)]}):null;let{target:A,found:j}=a;return C?P(`p`,{className:`setup-hint`,role:`status`,children:C===`external`?i(`setup.offer.usingYours`,{url:j.url}):i(`setup.offer.usingOwn`)}):j.status===`too_old`?V(`p`,{className:`setup-hint`,role:`status`,children:[i(`setup.offer.tooOld`),` `,V(`bdi`,{dir:`ltr`,className:`setup-choice-note`,children:[`Lemonade `,j.version??``,` · `,j.url]})]}):V(`form`,{id:`setup-lemonade-form`,className:`setup-lemonade`,"aria-label":i(`setup.offer.label`),onSubmit:e=>{e.preventDefault(),k(`external`)},children:[P(`span`,{className:`setup-choice-title`,children:i(`setup.offer.title`)}),P(`span`,{className:`setup-choice-note`,children:V(`bdi`,{dir:`ltr`,children:[`Lemonade`,j.version?` ${j.version}`:``,` · `,j.url]})}),V(`button`,{type:`button`,className:`setup-log-toggle setup-offer-more`,onClick:()=>v(e=>!e),"aria-expanded":_,"aria-controls":`setup-offer-detail`,children:[P(br,{size:13,className:_?`is-open`:``,"aria-hidden":`true`}),` `,i(`setup.offer.whatGaiaDoes`)]}),_&&P(`p`,{className:`setup-choice-note`,id:`setup-offer-detail`,children:i(`setup.offer.whatGaiaDoesText`)}),h&&P(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,value:p,onChange:e=>m(e.target.value),placeholder:i(`setup.offer.keyPlaceholder`),"aria-label":i(`setup.offer.keyLabel`)}),x&&(h?P(`p`,{className:`setup-error`,role:`alert`,children:i(`setup.offer.keyRejected`)}):P(gN,{text:x})),V(Gj,{children:[V(`button`,{type:`submit`,form:`setup-lemonade-form`,className:`btn-secondary`,disabled:!!y||h&&!p.trim(),children:[y===`external`&&P(q,{size:13,className:`spin`}),` `,i(`setup.offer.useMine`)]}),V(`button`,{type:`button`,className:`btn-primary`,disabled:!!y,onClick:()=>void k(`gaia`),children:[y===`gaia`&&P(q,{size:13,className:`spin`}),` `,i(`setup.offer.useOwn`)]})]})]})}function hN({problem:e,onRetry:t,onUseGaia:n}){let r=T(),i=e.kind===`server_too_old`&&e.use_gaia;return V(D.Fragment,{children:[e.start&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:r(`setup.server.howToStart`)}),P(`pre`,{dir:`ltr`,children:e.start})]}),V(Gj,{children:[P(`button`,{type:`button`,className:i?`btn-secondary`:`btn-primary`,onClick:t,children:r(`setup.tryAgain`)}),e.use_gaia&&P(`button`,{type:`button`,className:i?`btn-primary`:`btn-secondary`,onClick:n,children:r(`setup.server.useGaia`)})]}),e.use_gaia&&P(`p`,{className:`setup-hint`,children:r(`setup.server.useGaiaNote`)}),e.use_gaia&&e.env_url&&P(`p`,{className:`setup-hint`,children:r(`setup.server.envIgnoredNote`,{url:e.env_url})})]})}function gN({text:e}){let t=T();return V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:t(`setup.failedLead`)}),V(`details`,{className:`dl-details`,children:[P(`summary`,{children:t(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:e})]})]})}function _N({run:e}){let t=T();return e.problem?V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:t(e.problem.kind===`server_too_old`?`setup.server.tooOld`:`setup.server.unreachable`)}),V(`details`,{className:`dl-details`,children:[P(`summary`,{children:t(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:e.problem.message})]})]}):V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:t(e.components?.server===`failed`?`setup.server.ownFailed`:`setup.stopped`)}),e.error&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:t(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:e.error})]})]})}var vN=[`check`,`plan`,`key`,`models`,`gpu`,`download`,`test`,`ready`];function yN(e){return e instanceof Error?e.message:String(e)}function bN({onReady:e,onClose:t}){let n=T(),r=cs(e=>e.refresh),i=cs(e=>e.select),[a,o]=(0,X.useState)(`local`),[s,c]=(0,X.useState)(`check`),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(`models`),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(()=>new Set([`check`])),y=(0,X.useRef)(`check`),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),[O,k]=(0,X.useState)(null),[A,j]=(0,X.useState)(null),[M,N]=(0,X.useState)(``),[F,I]=(0,X.useState)({busy:!1,error:null,done:!1}),[L,ee]=(0,X.useState)(null),[R,z]=(0,X.useState)(null),[B,te]=(0,X.useState)(null),[ne,re]=(0,X.useState)(null),[ie,ae]=(0,X.useState)(null),[oe,H]=(0,X.useState)(null),[U,se]=(0,X.useState)(!1),[W,le]=(0,X.useState)(null),[ue,de]=(0,X.useState)(!1),[fe,pe]=(0,X.useState)(!1),[me,he]=(0,X.useState)(null),[ge,_e]=(0,X.useState)(!1),[ve,ye]=(0,X.useState)(null),[be,xe]=(0,X.useState)([]),[Se,we]=(0,X.useState)([]),[Ee,De]=(0,X.useState)([]),[Oe,ke]=(0,X.useState)(!1),[Ae,je]=(0,X.useState)(!1),Me=(0,X.useRef)({gaiaLemonade:!1,options:{}}),Ne=(0,X.useRef)(null),Pe=(0,X.useRef)(!1),Fe=(0,X.useRef)(!1),[Ie,Re]=(0,X.useState)(!1),[ze,Ve]=(0,X.useState)(!1),He=(0,X.useCallback)(()=>Ve(!0),[]),[Ue,We]=(0,X.useState)(null),[Ge,Ke]=(0,X.useState)(null),qe=(0,X.useRef)(!0);(0,X.useEffect)(()=>(qe.current=!0,()=>{qe.current=!1}),[]);let{network:Je,providers:Ye,recheck:Xe}=lM(),Ze=e=>Ye.find(t=>t.id===e),Qe=Ze(a),$e=Qe?.key_source===`environment`&&Qe.key_hint?Qe:void 0,et=e=>!!Ze(e)?.blocked,tt=e=>et(e)||e===`amd`&&Je?.reachable===!1,nt=e=>et(e)?n(`settings.privacy.localOnlyBlocked`):n(`setup.key.gatewayOff`),rt=a!==`local`,at=w?.server_only?w:null,K=w&&!w.server_only?w:null,st=w?.state===`running`||w?.state===`verifying`,ct=K?.state===`ready`,ut=CM(w),dt=!(K?.models??[]).some(e=>e.state===`downloading`||e.state===`queued`)&&((K?.tests?.length??0)>0||K?.state===`verifying`),pt=(0,X.useCallback)(()=>{C(null),ot().then(x).catch(e=>C(yN(e)))},[]),mt=(0,X.useRef)(0),gt=(0,X.useCallback)(async()=>{let e=++mt.current;z(null);try{let t=await Ce();return e===mt.current?(ee(t),t):null}catch(t){return e===mt.current&&z(yN(t)),null}},[]),vt=(0,X.useCallback)(async()=>{try{let e=await Nn();qe.current&&H(e??null)}catch(e){console.warn(`[SetupScreen] GPU memory could not be read; the step stays hidden`,e)}},[]),yt=t!=null;(0,X.useEffect)(()=>{ce().then(e=>ke(e.source===`config`)).catch(e=>console.warn(`[SetupScreen] could not read which Lemonade GAIA uses`,e)),pt(),gt(),it().then(e=>{(e.state!==`idle`||e.models?.length)&&(yt&&e.state!==`running`&&e.state!==`verifying`||(E(e),e.server_only||c(`download`),e.skip_chat_model&&o(dN()===`amd`?`amd`:`fireworks`)))}).catch(e=>j(yN(e))).finally(()=>Re(!0))},[pt,gt,yt]),(0,X.useEffect)(()=>{L?.catalog&&L.lemonade.reachable&&(te(e=>e??fj(L)),vt(),!w&&L.catalog.some(e=>e.partial&&e.selected)&&_e(!0))},[L,vt,w]);let bt=(0,X.useCallback)(()=>{Ne.current&&clearInterval(Ne.current),Ne.current=null},[]),xt=(w?.models??[]).filter(e=>e.state===`failed`&&e.error_kind===`disk_full`).length;(0,X.useEffect)(()=>{xt>0&>()},[xt,gt]);let St=(0,X.useCallback)(async()=>{try{let e=await it();if(k(null),e.state===`idle`&&!e.models?.length){E(null),c(`plan`),je(!0),gt();return}E(e)}catch(e){k(yN(e))}},[gt,n]);(0,X.useEffect)(()=>(!ut&&!O||(Ne.current=setInterval(()=>{St()},lN)),bt),[ut,O,St,bt]),(0,X.useEffect)(()=>{at&&at.state===`ready`&&(pt(),gt())},[at,at?.state,pt,gt]),(0,X.useEffect)(()=>{ct&&(pt(),gt().then(e=>{e&&ae(e)}),vt())},[ct,pt,gt,vt]);let Ct=(0,X.useRef)(!1),wt=(0,X.useCallback)(async(e=!1,t={})=>{if(Ct.current)return!1;Ct.current=!0,j(null),he(null),_e(!1),je(!1);try{fN(a),Me.current={gaiaLemonade:e,options:t};let n=await _t(rt,e,t);E(n),g(null);let r=t.extraModels??[];return r.length&&De(e=>e.filter(e=>!r.includes(e))),t.serverOnly||c(`download`),e&&ke(!1),!0}catch(e){let t=ht(e);if(t)return le({kind:`server`,detail:t,then:`run`}),!1;if(e instanceof yn&&e.httpStatus===409){let e=await it().catch(()=>null);if(e&&(e.state===`running`||e.state===`verifying`))return E(e),g(null),e.server_only||c(`download`),!0}return j(yN(e)),!1}finally{Ct.current=!1}},[a,rt]);(0,X.useEffect)(()=>{s===`check`&&Ie&&ze&&L&&!L.lemonade.reachable&&!w&&!Pe.current&&(Pe.current=!0,wt(!1,{serverOnly:!0}))},[s,Ie,ze,L,w,wt]);let Tt=!!(B&&L?.catalog&&L.lemonade.reachable&&(b||S)),Et=(0,X.useCallback)(()=>{let{gaiaLemonade:e,options:t}=Me.current;wt(e,t)},[wt]),Dt=(0,X.useCallback)((e,t=L)=>{re(t);let n=t&&B&&!rt?Sj(t,B):[];return wt(!1,{acknowledgeLowDisk:e,keepTrying:U,extraModels:n})},[L,B,rt,U,wt]),[Ot,kt]=(0,X.useState)(!1),At=(0,X.useRef)(!1),jt=(0,X.useCallback)(async(e,t=ue)=>{if(!L||!B||At.current)return;he(null),kt(e);let r=ZA(L),i=rt?[]:bj(r,B).filter(e=>!e.downloaded||e.id===B.defaultChat),a=i.find(tj);if(a){let e=a.id===B.defaultChat?`setup.models.cantRun.chat`:`setup.models.cantRun.other`;he(n(e,{name:a.name,why:Aj(a,n)}))}else if(!rt&&!t&&i.length>0&&i.every(e=>e.need_gb!=null))le({kind:`no_fit`,models:i});else{pe(!0),At.current=!0;try{let n=L;if(!rt&&B.defaultChat&&B.defaultChat!==n.chat_model.id)try{n=await Le(B.defaultChat,t)}catch(e){let t=ht(e);if(t){le({kind:`server`,detail:t,then:`chat`});return}throw e}if(!rt){await FM();let e=cj(r,B);e!==(n.vision_model??null)&&(n=await Be(e));for(let e of xj(n,B))n=await ft(e.id,e.skipped)}ee(n),await Dt(e,n)}catch(e){he(yN(e))}finally{At.current=!1,pe(!1)}}},[L,B,rt,ue,Dt,n]),Mt=(0,X.useCallback)(e=>{he(null),s===`download`?g(e===y.current?null:e):(g(null),c(e===`test`||e===`ready`?`download`:e))},[s]),Nt=(0,X.useCallback)(()=>{h??o(`local`),Mt(`plan`)},[Mt,h]),Pt=(0,X.useCallback)(()=>{st&&h!=null||(o(`local`),u(!0),Mt(`models`))},[Mt,st,h]),Ft=(0,X.useCallback)(()=>{st&&h!=null||(u(!1),o(dN()===`amd`?`amd`:`fireworks`),Mt(`key`))},[Mt,st,h]),It=!!oe?.applies,Lt=(0,X.useCallback)(()=>{Mt((h??s)===`gpu`?d:`plan`)},[d,Mt,h,s]),zt=(0,X.useCallback)(e=>{f(e),Mt(`gpu`)},[Mt]),Bt=(0,X.useRef)({prev:null,next:null});(0,X.useEffect)(()=>{let e=e=>{if(!e.altKey||W||(e.target instanceof Element?e.target:null)?.closest(`input, textarea, select, [contenteditable="true"]`))return;let t=e.key===`ArrowLeft`?Bt.current.prev:e.key===`ArrowRight`?Bt.current.next:null;t&&(e.preventDefault(),Mt(t))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[Mt,W]);let Vt=(0,X.useCallback)(async()=>{try{await G(),await St()}catch(e){he(yN(e))}},[St]),Ht=(0,X.useCallback)(async(e,t)=>{he(null),pe(!0);try{t===`verify`&&await dn(e),t===`disk_full`&>();try{E(await Te(e,{keepTrying:U}))}catch(t){let n=ht(t);if(!n)throw t;le({kind:`server`,detail:n,then:`retry`,id:e})}}catch(e){he(yN(e))}finally{pe(!1)}},[U,gt]),Ut=(0,X.useCallback)(async e=>{he(null),pe(!0);try{L?.catalog?.find(t=>t.id===e)?.planned&&ee(await ft(e,!0)),E(t=>t&&{...t,models:t.models?.map(t=>t.id===e?{...t,state:`skipped`}:t)});let{options:t}=Me.current;Me.current.options={...t,extraModels:t.extraModels?.filter(t=>t!==e)},te(t=>t&&t.ticked.has(e)?mj(t,ZA(L),e,!1):t)}catch(e){he(yN(e))}finally{pe(!1)}},[L]),Wt=(0,X.useCallback)(async()=>{await Vt(),Et()},[Vt,Et]),Gt=(0,X.useCallback)(async()=>{if(!st){I({busy:!0,error:null,done:!1});try{await Rt(a,{api_key:!Oe&&M||void 0},e=>I({busy:!0,error:null,done:!1,waiting:e}),()=>!qe.current);let{models:e}=await Zt(a),t=e.find(e=>e.rank===1)??e[0];if(!t)throw Error(n(`setup.key.noModels`));await i(t.id),ye(t.id),N(``),I({busy:!1,error:null,done:!0}),Dt(!1)}catch(e){I({busy:!1,error:yN(e),done:!1})}}},[a,M,i,Oe,Dt,n,st]),Kt=(0,X.useCallback)(e=>{fN(e),o(e),I({busy:!1,error:null,done:!1})},[]);(0,X.useEffect)(()=>{if(!ct||Se.length===0||Fe.current)return;let e=Se;Fe.current=!0,wt(!1,{keepTrying:U,extraModels:e}).then(t=>{Fe.current=!1,we(t=>t.filter(t=>!e.includes(t))),t||De(t=>[...t,...e.filter(e=>!t.includes(e))])})},[ct,Se,U,wt]);let qt=ct&&Se.length===0,Jt=rt?ve:K?.chat_model??(L&&!L.decided_after_server?L.chat_model.id:null),Yt=(0,X.useCallback)(async t=>{he(null);try{!rt&&Jt&&await i(Jt),await r()}catch(e){he(yN(e));return}e(t)},[Jt,rt,e,r,i]);(0,X.useEffect)(()=>{qt&<().then(e=>xe(e.cards)).catch(e=>console.warn(`[SetupScreen] no first tasks to offer`,e))},[qt]);let Xt=(0,X.useMemo)(()=>{let e={};for(let t of L?.catalog??[])e[t.id]=t.name;return e},[L]),Qt=w?.state===`failed`||w?.state===`cancelled`,$t=K&&(K.state===`failed`||K.state===`cancelled`)&&(K.models??[]).length>0&&(K.models??[]).every(e=>e.state===`ready`||e.state===`skipped`||e.state===`verifying`||e.state===`unchecked`)&&!ut,en=!!K&&Qt&&!K.problem&&Object.values(K.components??{}).includes(`failed`),tn=ZA(L),nn=B?_j(tn,B):[],rn=L&&B?yj(L,B):null,an=tn.find(e=>e.id===B?.defaultChat),on=!!b&&!b.compatible&&b.blockers.length>0,sn=qt?`ready`:s===`download`&&dt?`test`:s;y.current=sn;let cn=h??sn;(0,X.useEffect)(()=>{v(e=>e.has(cn)?e:new Set(e).add(cn))},[cn]);let ln=(0,X.useRef)(!0);(0,X.useEffect)(()=>{if(ln.current){ln.current=!1;return}let e=document.querySelector(`.setup-inner`);e&&(e.scrollTop=0),document.getElementById(`setup-title`)?.focus({preventScroll:!0})},[cn]);let un=[{id:`check`,label:n(`setup.check.title`),key:`setup.check.title`},{id:`plan`,label:n(`setup.plan.step`),key:`setup.plan.step`},{id:`download`,label:n(`setup.download.step`),key:`setup.download.step`},{id:`test`,label:n(`setup.test.step`),key:`setup.test.step`},{id:`ready`,label:n(`setup.ready.step`),key:`setup.ready.step`}],fn=e=>e===`models`||e===`key`?`plan`:e===`gpu`?d===`check`?`check`:`plan`:e,pn=rt?`key`:l?`models`:`plan`,mn=un.findIndex(e=>e.id===fn(sn)),hn=e=>e===`download`||e===`test`||e===`ready`,gn=[];if(b){let e=[L?.system?.physical_memory?`${MS(L.system.physical_memory,null)} installed`:null,b.ram_gb==null?null:`${b.ram_gb} GB the OS can use`].filter(Boolean).join(`, `),t=b.disk_free_gb==null?null:`${Math.round(b.disk_free_gb)} GB free on disk`;gn.push(`This PC: ${[b.gpu_name,b.npu_detected?`NPU`:null].filter(Boolean).join(`, `)||`no GPU reported`}`+[e,t].filter(Boolean).map(e=>`; ${e}`).join(``))}else S&&gn.push(`Couldn't read this PC: ${S}`);Ue&&(gn.push(`Found your Lemonade${Ue.version?` ${Ue.version}`:``} at ${Ue.url}`),gn.push(Ge===`external`?`You chose your own Lemonade`:Ge===`gaia`?`You chose GAIA's own Lemonade`:`Waiting for you to choose which Lemonade GAIA uses`)),L&&(!Ue||Ge)?gn.push(L.lemonade.reachable?`Model server answering at ${L.lemonade.url??`its address`}`:`No model server answering yet`):R&&gn.push(`Couldn't read the model list: ${R}`);let _n=(e,t)=>t<=mn||_.has(e)&&!hn(e),vn=un.map((e,t)=>({id:e.id,label:e.label,status:t<mn?`done`:t>mn?`pending`:sn===`ready`?`done`:Qt&&(sn===`download`||sn===`test`||sn===`check`)?`failed`:st&&(sn===`download`||sn===`test`)?`active`:`current`,shown:e.id===fn(cn),onOpen:e.id!==fn(cn)&&_n(e.id,t)?()=>Mt(e.id===`plan`?pn:e.id):void 0})),bn=un.findIndex(e=>e.id===fn(cn)),xn=cn===`gpu`&&d===`check`?.5:vN.indexOf(cn),Sn=(0,X.useRef)(xn),Cn=(0,X.useRef)(`forward`);Sn.current!==xn&&(Cn.current=xn>Sn.current?`forward`:`back`,Sn.current=xn);let wn=cn===`gpu`?d:cn===`models`||cn===`key`?`plan`:bn>0?un[bn-1].id===`plan`?pn:un[bn-1].id:null,Tn=(cn!==`gpu`&&bn>=0&&bn<un.length-1&&_n(un[bn+1].id,bn+1)?un[bn+1].id:null)??(h==null?cn===`check`&&Tt?`plan`:cn===`gpu`?d:null:null);Bt.current={prev:wn,next:Tn};let En=cn===`gpu`||cn===`models`||cn===`key`,Dn=h!=null&&st,On=[`server`];rt||On.push(`chat`),!rt&&B&&ij(tn,B)&&On.push(`vision`),B&&tn.some(e=>$A(e)&&B.ticked.has(e.id))&&On.push(`embedding`);for(let e of tn)B&&nj(e)&&B.ticked.has(e.id)&&!e.downloaded&&On.push(e.roles[0]);On.push(`agent`);let kn=B&&!rt?tn.filter(e=>nj(e)&&!B.ticked.has(e.id)&&!e.downloaded&&(rj(an)||!e.roles.includes(`image_creation`))):[],An=tn.find(e=>e.fit_code===`memory`&&e.chat_choice&&e.support===`verified`);return V(`main`,{className:`setup`,"aria-labelledby":`setup-title`,children:[P($M,{steps:vn}),P(Wj,{value:p,children:V(`div`,{className:`setup-pane`,children:[V(`div`,{className:`setup-inner`,children:[bn>=0&&V(`nav`,{className:`setup-topnav`,"aria-label":n(`setup.nav.label`),children:[P(`button`,{type:`button`,className:`setup-arrow`,onClick:()=>wn&&Mt(wn),disabled:!wn,"aria-label":n(`setup.nav.prev`),children:P(vr,{size:16,"aria-hidden":`true`})}),P(`button`,{type:`button`,className:`setup-arrow`,onClick:()=>Tn&&Mt(Tn),disabled:!Tn,"aria-label":n(`setup.nav.next`),children:P(br,{size:16,"aria-hidden":`true`})}),P(`span`,{children:P(`bdi`,{children:n(`setup.nav.stepOf`,{n:String(bn+1),total:String(un.length)})})}),h!=null&&h!==sn&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>g(null),children:n.compose(e=>e(`setup.nav.toLive`,{step:e(un.find(e=>e.id===sn)?.key??`setup.download.step`)}))}),P(AM,{})]}),ge&&s!==`download`&&V(`div`,{className:`setup-banner`,role:`status`,children:[P(Hi,{size:14,"aria-hidden":`true`}),P(`span`,{children:n(`setup.resume.banner`)})]}),Ae&&s!==`download`&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.interrupted`)}),V(`div`,{className:`setup-stage is-${Cn.current}`,children:[cn===`check`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(Tt?`setup.check.headingDone`:`setup.check.heading`)}),P(`p`,{className:`setup-lede`,children:n(Tt?`setup.check.ledeDone`:`setup.check.lede`)}),P(QM,{hardware:b,hardwareError:S,plan:L,serverRun:at,awaitingChoice:!!Ue&&!ze}),Tt&&L&&P(XM,{plan:L,hardware:b,onChangeMemory:It&&h==null?()=>zt(`check`):void 0}),Tt&&h==null&&!(Ue&&!ze)&&P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>Mt(`plan`),children:n(`setup.continue`)})}),at&&Qt&&V(D.Fragment,{children:[P(_N,{run:at}),at.problem?P(hN,{problem:at.problem,onRetry:()=>void wt(!1,{serverOnly:!0}),onUseGaia:()=>void wt(!0,{serverOnly:!0})}):P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void wt(!!at.gaia_lemonade,{serverOnly:!0}),children:n(`setup.tryAgain`)})})]}),R&&!L&&V(D.Fragment,{children:[P(gN,{text:R}),V(Gj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void wt(!1,{keepTrying:U}),children:n(`setup.models.useRecommended`)}),P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void gt(),children:n(`setup.tryAgain`)})]}),P(`p`,{className:`setup-hint`,children:n(`setup.models.useRecommendedNote`)})]}),A&&P(gN,{text:A}),A&&!at&&L&&!L.lemonade.reachable&&P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void wt(!1,{serverOnly:!0}),children:n(`setup.tryAgain`)})}),Ie&&L&&(!L.lemonade.reachable&&!at||Tt&&h==null&&L.lemonade.mode!==`external`)&&P(mN,{onNothingToOffer:He,canInstallOwn:!L.lemonade.reachable&&!at,onFound:We,onChosen:e=>{ke(e===`external`),Ke(e),Ve(!0),pt(),gt()}})]}),cn===`plan`&&L&&B&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.plan.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.plan.lede`)}),V(`section`,{className:`setup-hero`,"aria-label":n(`setup.plan.label`),children:[P(`p`,{className:`setup-eyebrow`,children:B.chatChosen?n(`setup.plan.yours`):n(`setup.plan.recommended`)}),P(`p`,{className:`setup-hero-title`,children:P(`bdi`,{children:n(`setup.plan.run`,{name:an?.name??``})})}),V(`dl`,{className:`setup-facts`,children:[V(`div`,{children:[P(`dt`,{children:n(`setup.summary.download`)}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:$(vj(L,B).downloadGb??0)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.plan.runsOn`)}),P(`dd`,{children:P(`bdi`,{children:an&&ej(an)?n(`setup.checks.npu`):b?.gpu_name??n(`setup.plan.cpu`)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.plan.diskAfter`)}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:vj(L,B).afterGb==null?`—`:$(Math.max(0,vj(L,B).afterGb))})})]})]}),V(`ul`,{className:`setup-reasons`,children:[!B.chatChosen&&P(`li`,{children:n(`setup.plan.why.evaluated`)}),an?.need_gb!=null&&an.capacity_gb!=null&&an.fits&&P(`li`,{children:n(`setup.plan.why.fits`,{need:NS(an.need_gb),have:NS(an.capacity_gb)})}),P(`li`,{children:n(`setup.plan.why.private`)}),an&&ej(an)&&P(`li`,{children:n(`setup.plan.why.noImagesNpu`)}),An&&An.id!==an?.id&&An.need_gb!=null&&An.capacity_gb!=null&&P(`li`,{children:n(`setup.plan.why.bigger`,{name:An.name,need:NS(An.need_gb),have:NS(An.capacity_gb)})})]}),P(Gj,{children:V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>rn?le({kind:`low_disk`}):void jt(!1),disabled:fe||on||Dn,children:[fe&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,nn.length?n(`setup.plan.start`):n(`setup.plan.startNoDownload`)]})}),V(`div`,{className:`setup-row`,children:[P(`button`,{type:`button`,className:`link-btn`,onClick:Pt,disabled:Dn,children:n(`setup.plan.customize`)}),P(`button`,{type:`button`,className:`link-btn`,onClick:Ft,disabled:Dn,children:n(`setup.plan.cloud`)}),t&&P(`button`,{type:`button`,className:`link-btn`,onClick:t,children:n(`setup.backToGaia`)})]}),on&&V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:n(`setup.blocked`)}),V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:b?.blockers.join(`
|
|
81
|
-
`)})]})]}),rn&&P(`p`,{className:`setup-error`,role:`alert`,children:n(`setup.summary.short`,{need:$(rn.needGb),free:$(rn.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(rn.freeUpGb)})}),(me??A)&&P(gN,{text:me??A})]}),V(`details`,{className:`setup-disclosure`,children:[P(`summary`,{children:n(`setup.plan.whatDownloads`)}),P(mM,{plan:L,models:nn})]})]}),cn===`gpu`&&oe&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.gpu.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.gpu.lede`)}),P(tM,{status:oe,onStatus:H,mode:`setup`,headingId:`setup-title`,names:Xt,onBack:Lt,onSkip:()=>Mt(d),onContinue:()=>Mt(d)})]}),cn===`models`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.models.title`)}),L&&B&&P(IM,{plan:L,selection:B,onSelection:te,disabled:fe||Dn,onRecheck:()=>void gt()}),It&&oe?.total_gb!=null&&oe.gpu_gb!=null&&V(`p`,{className:`setup-hint setup-gpu-option`,children:[n(`setup.models.gpu`,{gpu:$(oe.gpu_gb),total:$(oe.total_gb)}),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:()=>zt(`models`),disabled:fe||Dn,children:n(`setup.found.changeMemory`)})]}),P(nM,{plan:L,planError:R,onRetryPlan:()=>void gt(),onUseRecommended:()=>void wt(!1,{keepTrying:U}),selection:B,onSelection:te,cloud:!1,keepTrying:U,onKeepTrying:se,onBack:Lt,onContinue:e=>void jt(e),busy:fe||Dn,error:me??A})]}),cn===`key`&&V(`form`,{id:`setup-key-form`,onSubmit:e=>{e.preventDefault(),Gt()},className:`setup-form`,children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.key.title`)}),P(`div`,{className:`setup-choices`,role:`radiogroup`,"aria-label":n(`setup.key.provider`),children:sN.filter(e=>e.id!==`local`).map(e=>V(`button`,{type:`button`,role:`radio`,"aria-checked":a===e.id,className:`setup-choice${a===e.id?` is-active`:``}${tt(e.id)?` is-disabled`:``}`,onClick:()=>Kt(e.id),disabled:F.busy||tt(e.id),title:et(e.id)?n(`settings.privacy.localOnlyBlocked`):void 0,children:[P(Ir,{size:16,"aria-hidden":`true`}),V(`span`,{children:[P(`span`,{className:`setup-choice-title`,children:P(`bdi`,{children:cN(e,n)})}),P(`span`,{className:`setup-choice-note`,children:tt(e.id)?nt(e.id):n(e.note)})]})]},e.id))}),Je?.reachable===!1&&P(`button`,{type:`button`,className:`link-btn setup-start`,onClick:Xe,children:n(`setup.key.checkAgain`)}),et(a)&&P(`p`,{className:`setup-a11y-alert`,role:`alert`,children:n(`settings.privacy.localOnlyBlocked`)}),a===`fireworks`&&!Oe&&!et(a)&&V(`section`,{className:`setup-card`,children:[P(`h3`,{className:`mc-job-title`,children:n(`setup.key.getOne`)}),V(`ol`,{className:`setup-key-steps`,children:[P(`li`,{children:P(`a`,{href:aN,target:`_blank`,rel:`noreferrer`,children:n(`setup.key.step1`)})}),P(`li`,{children:n(`setup.key.step2`)}),P(`li`,{children:n(`setup.key.step3`)})]})]}),a===`amd`&&!Oe&&!et(a)&&P(`section`,{className:`setup-card`,children:P(`p`,{className:`setup-hint`,children:P(`a`,{href:oN,target:`_blank`,rel:`noreferrer`,children:n(`setup.key.gatewayHelp`)})})}),!et(a)&&P(WA,{provider:a,limit:3}),P(`p`,{className:`setup-hint`,children:n(Oe?`setup.key.usersServer`:`setup.key.where`)}),P(`div`,{className:`setup-row`,children:!Oe&&P(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,value:M,onChange:e=>N(e.target.value),placeholder:n(`setup.key.placeholder`),"aria-label":n(`setup.key.label`)})}),$e&&!Oe&&!M&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.key.foundEnv`,{name:$e.name,hint:$e.key_hint??``})}),F.busy&&!F.waiting&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.key.testing`)}),F.busy&&F.waiting&&P(`p`,{className:`setup-hint`,role:`status`,children:F.waiting}),F.error&&P(`p`,{className:`setup-error`,role:`alert`,children:F.error}),V(Gj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:Nt,disabled:F.busy,children:n(`setup.back`)}),V(`button`,{type:`submit`,form:`setup-key-form`,className:`btn-primary`,disabled:F.busy||tt(a)||Dn,children:[F.busy&&P(q,{size:13,className:`spin`}),` `,n(`setup.key.connect`)]})]})]}),cn===`download`&&!K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.download.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.download.lede`)}),V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.starting`)]})]}),cn===`download`&&K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.download.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.download.lede`)}),L&&P(`section`,{className:`setup-card`,"aria-label":n(`setup.contents.title`),children:P(mM,{plan:L,run:K,onRetry:Et,retryDisabled:fe})}),(K.models?.length??0)>0?P(`div`,{className:O?`is-stale`:void 0,children:P(EM,{status:{...K,overall:Cj(K,ne??L)},names:Xt,freeGb:L?.disk?.free_gb??null,onCancel:()=>void Vt(),onRetry:(e,t)=>void Ht(e,t),onResume:e=>void Ht(e,null),onResumeAll:Et,onSkip:e=>void Ut(e),onRestart:()=>void Wt(),busy:fe||!!O,retryLater:st,labelledBy:`setup-title`})}):st?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.working`)]}):null,kn.length>0&&V(`section`,{className:`setup-card`,"aria-label":n(`setup.optional.title`),children:[P(`h3`,{className:`mc-job-title`,children:n(`setup.optional.title`)}),P(`p`,{className:`setup-hint`,children:n(`setup.optional.lede`)}),P(`ul`,{className:`setup-rows`,children:kn.map(e=>{let t=Se.includes(e.id);return V(`li`,{className:`setup-result is-waiting`,children:[P(`span`,{className:`setup-result-label`,children:n(`setup.purpose.${e.roles[0]}`)}),V(`span`,{className:`setup-result-value`,children:[P(`bdi`,{dir:`ltr`,children:e.size_gb==null?n(`setup.contents.sizeOnDownload`):$(e.size_gb)}),P(`button`,{type:`button`,className:`btn-secondary`,"aria-pressed":t,onClick:()=>we(n=>t?n.filter(t=>t!==e.id):[...n,e.id]),children:n(t?`setup.optional.added`:`setup.optional.add`)})]})]},e.id)})})]}),O&&V(D.Fragment,{children:[P(`p`,{className:`setup-error`,role:`alert`,children:n(`setup.lostContact`,{error:O})}),P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void St(),children:n(`setup.reconnect`)})})]}),Qt&&$t&&!en&&K.state===`failed`&&!K.model_failed&&(K.problem?P(hN,{problem:K.problem,onRetry:Et,onUseGaia:()=>void wt(!0,Me.current.options)}):V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:n(`setup.download.stoppedBeforeCheck`)}),K.error&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:K.error})]})]})),Qt&&$t&&!en&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.download.finishNote`)}),P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:Et,disabled:fe,children:n(`setup.finish`)})})]}),Qt&&!$t&&!en&&!(K.models??[]).some(e=>e.state===`failed`||e.state===`cancelled`)&&V(D.Fragment,{children:[P(_N,{run:K}),K.problem?P(hN,{problem:K.problem,onRetry:Et,onUseGaia:()=>void wt(!0,Me.current.options)}):P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void wt(!!K.gaia_lemonade,Me.current.options),children:n(`setup.tryAgain`)})})]}),(me||A)&&P(gN,{text:me??A})]}),cn===`test`&&K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.test.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.test.lede`)}),P(iN,{run:K,expected:On,names:Xt,catalog:tn,onRetry:Et,onChooseAnother:rt?void 0:Pt,onCancel:()=>void Vt(),onDownloadAgain:L?.lemonade.mode===`external`?void 0:e=>void Ht(e,`verify`),busy:fe}),Qt&&K.error&&!(K.tests??[]).some(e=>e.error===K.error)&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:K.error})]}),(me||A)&&P(gN,{text:me??A})]}),cn===`ready`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.ready.heading`)}),V(`div`,{className:`setup-done`,role:`status`,children:[P(`div`,{className:`setup-done-head`,children:Jt&&P(`p`,{children:n(rt?`setup.ready.answersCloud`:`setup.ready.answersLocal`,{model:rt?vs(Jt):Xt[Jt]??ie?.catalog?.find(e=>e.id===Jt)?.name??vs(Jt)})})}),P(Gj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Yt(),autoFocus:!0,children:n(`setup.ready.start`)})}),!rt&&ie&&P(rM,{plan:ie,chatModel:Jt,gpu:oe}),A&&P(gN,{text:A}),(K?.tests??[]).filter(e=>e.state===`failed`).map(e=>P(`p`,{className:`setup-failed-extra`,role:`alert`,children:n(`setup.ready.extraFailed`,{job:n(`setup.test.job.${e.job}`)})},`${e.job}:${e.subject??``}`)),Ee.length>0&&!W&&P(`p`,{className:`setup-failed-extra`,role:`alert`,children:n(`setup.ready.extraNotFetched`,{names:Ee.map(e=>Xt[e]??e).join(`, `)})}),be.length>0&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.ready.tasks`)}),P(cM,{cards:be,onPick:e=>void Yt(e)})]})]})]})]},cn),t&&!st&&cn!==`plan`&&cn!==`ready`&&P(`div`,{className:`setup-row`,children:P(`button`,{type:`button`,className:`link-btn setup-close`,onClick:t,children:n(`setup.backToGaia`)})}),Dn&&(En||cn===`plan`)&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.nav.runGoing`)}),P(kM,{run:w,before:{check:gn}})]}),P(`div`,{className:`setup-footer`,ref:m})]})}),W?.kind===`no_fit`&&P(Kj,{title:W.models.length===1?n(`setup.confirm.noFitOne`,{name:W.models[0].name}):n(`setup.confirm.noFitMany`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.pickSmaller`),onConfirm:()=>{le(null),de(!0),jt(Ot,!0)},onCancel:()=>le(null),children:W.models.map(e=>V(`p`,{children:[P(`bdi`,{children:e.name}),`: `,Aj(e,n)]},e.id))}),W?.kind===`low_disk`&&rn&&P(Kj,{title:n(`setup.confirm.lowDiskTitle`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{le(null),jt(!0)},onCancel:()=>{le(null),Pt()},children:P(`p`,{children:n(`setup.summary.short`,{need:$(rn.needGb),free:$(rn.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(rn.freeUpGb)})})}),W?.kind===`server`&&P(Kj,{title:W.detail.code===`low_disk`?n(`setup.confirm.lowDiskTitle`):n(`setup.confirm.noFitServerTitle`),confirmLabel:W.detail.code===`low_disk`?n(`setup.confirm.downloadAnyway`):n(`setup.confirm.useAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{let e=W;if(le(null),e.then===`chat`)de(!0),jt(Ot,!0);else if(e.then===`retry`)Te(e.id,{keepTrying:U,acknowledgeLowDisk:!0}).then(E).catch(e=>he(yN(e)));else{let{gaiaLemonade:e,options:t}=Me.current;wt(e,{...t,acknowledgeLowDisk:!0})}},onCancel:()=>{let e=W;le(null),e.then!==`retry`&&!ct&&Pt()},children:P(`p`,{children:W.detail.message})})]})}function xN(e,t,n){let r=(0,X.useRef)(n);(0,X.useEffect)(()=>{r.current=n});let i=(0,X.useRef)(!1),a=(0,X.useRef)(null);if(t&&!i.current){let e=document.activeElement;a.current=e instanceof HTMLElement?e:null}(0,X.useEffect)(()=>{if(!t)return;i.current=!0;let n=a.current,o=e.current;if(o&&!o.contains(document.activeElement)){let e=r.current?.()??oS(o)[0];e?e.focus():(o.hasAttribute(`tabindex`)||o.setAttribute(`tabindex`,`-1`),o.focus())}return()=>{i.current=!1;let e=document.activeElement;(!e||e===document.body||o?.contains(e))&&n?.isConnected&&n.focus()}},[e,t])}function SN({title:e,titleId:t,count:n,hint:r,defaultOpen:i=!1,forceOpen:a=!1,children:o}){let[s,c]=(0,X.useState)(i);return V(`details`,{className:`settings-disclosure`,open:s||a,onToggle:e=>{a||c(e.currentTarget.open)},children:[V(`summary`,{onClick:e=>{a&&e.preventDefault()},children:[P(gr,{size:15,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),V(`span`,{className:`settings-disclosure-text`,children:[P(`span`,{className:`settings-disclosure-title`,id:t,tabIndex:t?-1:void 0,children:e}),r&&P(`span`,{className:`settings-disclosure-hint`,children:r})]}),n!=null&&P(`bdi`,{dir:`ltr`,className:`settings-disclosure-count`,children:n})]}),P(`div`,{className:`settings-disclosure-body`,children:o})]})}var CN=g(Tc()?`settings.desktop.menuBar`:`settings.desktop.tray`),wN=[{key:`minimizeToTray`,label:`settings.desktop.keepRunning`,hint:`settings.desktop.keepRunningHint`},{key:`startOnLogin`,label:`settings.desktop.startOnLogin`,hint:`settings.desktop.startOnLoginHint`},{key:`startMinimized`,label:`settings.desktop.startMinimized`,hint:`settings.desktop.startMinimizedHint`}],TN=new Set([`startMinimized`]),EN={minimizeToTray:`settings.desktop.keepRunningNoTray`};function DN(e){return e?.reason===`no-host`?`settings.desktop.noTray`:e?.reason===`check-failed`?`settings.desktop.noTrayCheckFailed`:null}function ON(){let e=T(),t=window.gaiaAPI?.tray,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null);(0,X.useEffect)(()=>{t&&t.getConfig().then(e=>{r(e.tray),a(e.host)}).catch(t=>s(e(`settings.desktop.readFailed`,{reason:t instanceof Error?t.message:String(t)})))},[t,e]);let u=(0,X.useCallback)(async e=>{if(t&&n&&c===null){l(e),s(null);try{let i=await t.setConfig({tray:{[e]:!n[e]}});r(i.tray),a(i.host)}catch(e){s(e instanceof Error?e.message:String(e))}finally{l(null)}}},[t,n,c]);if(!t)return null;let d=DN(i);return P(SN,{title:e(`settings.desktop.title`),children:V(`div`,{className:`settings-field`,role:`group`,"aria-labelledby":`desktop-app-label`,children:[P(`span`,{className:`settings-label`,id:`desktop-app-label`,children:e(`settings.desktop.title`)}),wN.map(({key:t,label:r,hint:i})=>{let a=TN.has(t)?d:null,o=d&&EN[t]||i;return V(`div`,{children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(r,{tray:CN})}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,role:`switch`,checked:!a&&!!n?.[t],"aria-describedby":`desktop-${t}-hint`,onChange:()=>void u(t),disabled:!!a||!n||c!==null&&c!==t,"aria-busy":c===t,"aria-label":e(r,{tray:CN})}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,id:`desktop-${t}-hint`,children:a?e(a):e(o,{tray:CN})})]},t)}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o})]})})}function kN(){return window.gaiaUpdater}var AN={status:`idle`,version:null,progress:0,releaseNotes:null,error:null,currentVersion:null,pinnedVersion:null,autoUpdate:!1,includePrereleases:!1};function jN(){let[e,t]=(0,X.useState)({...AN});return(0,X.useEffect)(()=>{let e=kN();if(!e)return;let n=!0;e.getStatus().then(e=>{n&&e&&t(e)}).catch(()=>{});let r=e.onStatusChange(e=>{n&&e&&t(e)});return()=>{n=!1;try{r()}catch{}}},[]),e}var MN=`gaia-update-error:`;function NN(e,t){let n=`update.err.${e}`;return N(n)?g(n,t??{}):null}function PN(e){let t=e instanceof Error?e.message:String(e),n=t.indexOf(MN);if(n<0)return t.replace(/^Error invoking remote method '[^']+': (?:Error: )?/,``);let r;try{r=JSON.parse(t.slice(n+18))}catch{return t.slice(0,n)+t.slice(n+18)}let i=NN(r.code,r.params)??r.message??r.code,a=r.note&&NN(r.note.code,r.note.params);return a?g(`update.err.withNote`,{error:i,note:a}):i}function FN(e,t){let n=PN(e);return typeof n==`object`?t(n.ref,n.params):String(n)}function IN(){return window.gaiaUpdater}function LN({onClose:e}){let t=T(),[n,r]=(0,X.useState)({kind:`loading`}),i=(0,X.useRef)(null);(0,X.useEffect)(()=>{let e=IN();e?e.listReleases().then(e=>{r(Array.isArray(e)?{kind:`list`,releases:e}:{kind:`error`,message:e.error})}).catch(()=>{r({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})}):r({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})},[]),Io(!0,e),sS(i,!0),(0,X.useEffect)(()=>{let e=i.current;e&&e.querySelector(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`)?.focus()},[]),(0,X.useEffect)(()=>{let e=i.current;if(!e)return;function t(t){if(t.key!==`Tab`||!e)return;let n=e.querySelectorAll(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`);if(n.length===0)return;let r=n[0],i=n[n.length-1];t.shiftKey?document.activeElement===r&&(t.preventDefault(),i?.focus()):document.activeElement===i&&(t.preventDefault(),r?.focus())}return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[]);function a(e,t){e.isCurrent||r({kind:`confirm`,release:e,releases:t})}async function o(n){r({kind:`installing`});let i=IN();if(!i)r({kind:`error`,message:t(`update.picker.noBridge`)});else try{await i.installVersion(n.tag),e()}catch(e){r({kind:`error`,message:t(`update.picker.failed`,{reason:PN(e)})})}}function s(e){if(!e)return``;try{return new Date(e).toLocaleDateString(te(t),{year:`numeric`,month:`short`,day:`numeric`})}catch{return e}}return P(`div`,{className:`version-picker-overlay`,onClick:t=>{t.target===t.currentTarget&&e()},children:V(`div`,{className:`version-picker-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`update.picker.title`),ref:i,children:[V(`div`,{className:`version-picker-header`,children:[P(`h3`,{children:t(`update.picker.title`)}),P(`button`,{className:`version-picker-close`,onClick:e,"aria-label":t(`update.picker.close`),type:`button`,children:`×`})]}),V(`div`,{className:`version-picker-body`,children:[n.kind===`loading`&&V(`div`,{className:`version-picker-loading`,"aria-busy":`true`,children:[P(`span`,{className:`version-picker-spinner`}),t(`update.picker.loading`)]}),n.kind===`error`&&V(`div`,{className:`version-picker-error`,children:[P(`p`,{children:n.message}),P(`p`,{children:P(`a`,{href:`https://github.com/amd/gaia/releases`,target:`_blank`,rel:`noreferrer`,children:t(`update.picker.browse`)})})]}),n.kind===`list`&&P(`ul`,{className:`version-picker-list`,role:`listbox`,"aria-label":t(`update.picker.listAria`),children:n.releases.map(e=>P(`li`,{children:V(`button`,{type:`button`,className:`version-picker-row`,"data-version":e.version,"aria-label":e.isCurrent?t(`update.picker.rowInstalled`,{version:e.version}):e.isPinned?t(`update.picker.rowPinned`,{version:e.version}):e.version,"aria-disabled":e.isCurrent?`true`:`false`,onClick:()=>a(e,n.releases),disabled:e.isCurrent,children:[P(`span`,{className:`vp-version`,children:e.version}),P(`span`,{className:`vp-date`,children:s(e.date)}),e.isCurrent&&P(`span`,{className:`vp-badge vp-badge-current`,children:t(`update.picker.installed`)}),e.isPinned&&!e.isCurrent&&P(`span`,{className:`vp-badge vp-badge-pinned`,children:t(`update.picker.pinned`)}),!e.isCurrent&&P(`span`,{className:`vp-arrow`,"aria-hidden":`true`,children:`›`})]})},e.tag))}),n.kind===`list`&&V(`p`,{className:`version-picker-more`,children:[t(`update.picker.recent`,{n:n.releases.length}),` `,P(`a`,{href:`https://github.com/amd/gaia/releases`,target:`_blank`,rel:`noreferrer`,children:t(`update.picker.browseAll`)})]}),n.kind===`confirm`&&V(`div`,{className:`version-picker-confirm`,children:[P(`p`,{children:t(`update.picker.confirm`,{version:n.release.version})}),P(`p`,{className:`vp-confirm-note`,children:t(`update.picker.confirmNote`,{version:n.release.version})}),V(`div`,{className:`vp-confirm-actions`,children:[P(`button`,{type:`button`,className:`vp-btn-cancel`,onClick:()=>r({kind:`list`,releases:n.releases}),children:t(`update.picker.back`)}),P(`button`,{type:`button`,className:`vp-btn-confirm`,onClick:()=>o(n.release),children:t(`update.picker.install`)})]})]}),n.kind===`installing`&&V(`div`,{className:`version-picker-loading`,"aria-busy":`true`,children:[P(`span`,{className:`version-picker-spinner`}),t(`update.picker.starting`)]})]})]})})}var RN=`https://github.com/amd/gaia/releases`;function zN(e){return/^\d+\.\d+\.\d+-/.test(e??``)}function BN(e,t){let n=e.version??``;switch(e.status){case`checking`:return t(`update.status.checking`);case`available`:return t(`update.status.available`,{version:n});case`downloading`:return e.preparing?t(`update.status.preparing`,{version:n}):t(`update.status.downloading`,{version:n,pct:e.progress});case`downloaded`:return t(`update.status.downloaded`,{version:n});case`error`:return t(`update.status.error`,{reason:e.error??t(`update.status.unknownError`)});case`no-channel`:return e.error??t(`update.status.noChannel`);case`disabled`:return t(`update.status.disabled`);default:return t(`update.status.upToDate`)}}function VN(){let e=jN(),t=T(),n=kN(),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1);if(!n)return null;async function l(e,r){if(n){i(!0),o(null);try{await r(n)}catch(n){d.system.error(`${e} failed`,n),o(t(`update.settings.failed`,{action:g(e),reason:PN(n)}))}finally{i(!1)}}}let u=e.status===`disabled`,f=r||e.status===`checking`||e.status===`downloading`,p=`${t(`update.settings.running`,{version:e.currentVersion??t(`update.settings.unknownVersion`)})} ${BN(e,t)}`,m=[`available`,`downloaded`,`error`].includes(e.status)||!!e.pinnedVersion||!!e.installFailed||!!e.configError||!!a;return P(SN,{title:t(`update.settings.title`),titleId:`updates-label`,hint:p,forceOpen:m,children:V(`div`,{className:`settings-field`,role:`group`,"aria-labelledby":`updates-label`,children:[P(`p`,{className:`visually-hidden`,role:`status`,children:p}),V(`label`,{className:`setting-row`,children:[P(`span`,{children:t(`update.settings.auto`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,role:`switch`,checked:e.autoUpdate,"aria-describedby":`updates-auto-hint`,"aria-label":t(`update.settings.auto`),"aria-busy":r,disabled:u,onChange:()=>{r||l(`update.action.saveAuto`,t=>t.setAutoUpdate(!e.autoUpdate))}}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,id:`updates-auto-hint`,children:t(`update.settings.autoHint`)}),V(`label`,{className:`setting-row`,children:[P(`span`,{children:t(`update.settings.rc`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,role:`switch`,checked:!!e.includePrereleases,"aria-describedby":`updates-rc-hint`,"aria-label":t(`update.settings.rc`),"aria-busy":r,disabled:u,onChange:()=>{r||l(`update.action.saveRc`,t=>t.setIncludePrereleases(!e.includePrereleases))}}),P(`span`,{className:`toggle-track`})]})]}),V(`p`,{className:`settings-hint`,id:`updates-rc-hint`,children:[t(`update.settings.rcHint`),zN(e.currentVersion)&&` ${t(`update.settings.rcHintRunning`)}`]}),e.pinnedVersion&&V(`p`,{className:`settings-hint`,children:[t(`update.settings.pinned`,{version:e.pinnedVersion}),` `,P(`button`,{type:`button`,className:`btn-secondary`,disabled:r,onClick:()=>void l(`update.action.resume`,e=>e.resumeUpdates()),children:t(`update.settings.unpin`)})]}),V(`div`,{className:`setting-actions`,children:[e.status===`available`&&!e.pinnedVersion&&P(`button`,{type:`button`,className:`btn-primary`,disabled:r,onClick:()=>void l(`update.action.download`,e=>e.downloadUpdate()),children:t(`update.settings.updateTo`,{version:e.version??``})}),e.status===`downloaded`&&P(`button`,{type:`button`,className:`btn-primary`,disabled:r,onClick:()=>void l(`update.action.restart`,e=>e.restart()),children:t(`update.settings.restart`)}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:f||u,onClick:()=>void l(`update.action.check`,e=>e.check()),children:t(`update.settings.check`)}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:f||u,onClick:()=>c(!0),children:t(`update.settings.pick`)}),e.previousVersion&&P(`button`,{type:`button`,className:`btn-secondary`,"aria-describedby":`updates-back-hint`,disabled:f||u,onClick:()=>void l(`update.action.goBack`,e=>e.revertUpdate()),children:t(`update.settings.goBack`,{version:e.previousVersion})})]}),e.previousVersion&&P(`p`,{className:`settings-hint`,id:`updates-back-hint`,children:t(`update.settings.goBackHint`)}),e.installFailed&&P(`p`,{className:`settings-error`,role:`alert`,children:t(`update.settings.installFailed`,{...e.installFailed,url:RN})}),e.lastCheckError&&P(`p`,{className:`settings-hint`,children:t(`update.settings.lastCheckError`,{reason:e.lastCheckError})}),e.configError&&P(`p`,{className:`settings-error`,role:`alert`,children:e.configError}),a&&P(`p`,{className:`settings-error`,role:`alert`,children:a}),s&&P(LN,{onClose:()=>c(!1)})]})})}var HN=[{value:`light`,label:`settings.theme.light`},{value:`dark`,label:`settings.theme.dark`},{value:`system`,label:`settings.theme.system`}],UN={default:`palette.default`,stone:`palette.stone`,marble:`palette.marble`,glacier:`palette.glacier`,forest:`palette.forest`,sage:`palette.sage`,basalt:`palette.basalt`,gold:`palette.gold`,dusk:`palette.dusk`,custom:`settings.colors.custom`},WN=[[`Enter`,`settings.shortcut.send`],[`Shift+Enter`,`settings.shortcut.newLine`],[`Esc`,`settings.shortcut.stop`],[`Mod+Shift+O`,`settings.shortcut.newChat`],[`Mod+K`,`settings.shortcut.search`],[`Mod+B`,`settings.shortcut.sidebar`],[`Mod+,`,`settings.shortcut.settings`]];function GN(){let e=T(),t=k(e=>e.locale),n=k(e=>e.setLocale),r=k(e=>e.themePreference),i=k(e=>e.setThemePreference),a=k(e=>e.palette),o=k(e=>e.setPalette),s=k(e=>e.customColors),c=k(e=>e.setCustomColors),l=qO(e=>e.visible),u=qO(e=>e.setVisible),d=e=>t=>c({...s,[e]:t.target.value.toUpperCase()});return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.general`)}),V(`div`,{className:`settings-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`ui-language`,children:e(`settings.language`)}),P(`select`,{id:`ui-language`,className:`settings-input`,value:t,onChange:e=>n(e.target.value),children:b.map(({meta:e})=>P(`option`,{value:e.code,lang:e.code,dir:e.dir,children:M(e)},e.code))}),P(`span`,{className:`settings-hint`,children:e(`settings.languageHint`)})]}),V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,id:`appearance-label`,children:e(`settings.appearance`)}),P(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`appearance-label`,children:HN.map(t=>P(`button`,{type:`button`,role:`radio`,"aria-checked":r===t.value,className:r===t.value?`is-active`:``,onClick:()=>i(t.value),children:e(t.label)},t.value))})]}),V(`div`,{className:`settings-field`,children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`resources.settings`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),"aria-label":e(`resources.settings`),"aria-describedby":`resources-hint`}),P(`span`,{className:`toggle-track`})]})]}),P(`span`,{className:`settings-hint`,id:`resources-hint`,children:e(`resources.settingsHint`)})]}),V(SN,{title:e(`settings.colors`),titleId:`palette-label`,defaultOpen:a===`custom`,children:[V(`div`,{className:`palette-grid`,role:`radiogroup`,"aria-labelledby":`palette-label`,children:[oe.map(t=>V(`button`,{type:`button`,role:`radio`,"aria-checked":a===t.id,className:`palette-tile${a===t.id?` is-active`:``}`,onClick:()=>o(t.id),children:[P(`span`,{className:`palette-swatch`,"aria-hidden":`true`,children:t.swatch.map(e=>P(`i`,{style:{background:e}},e))}),e(UN[t.id])]},t.id)),V(`button`,{type:`button`,role:`radio`,"aria-checked":a===`custom`,className:`palette-tile${a===`custom`?` is-active`:``}`,onClick:()=>o(`custom`),children:[V(`span`,{className:`palette-swatch`,"aria-hidden":`true`,children:[P(`i`,{style:{background:s.base}}),P(`i`,{style:{background:s.accent}})]}),e(`settings.colors.custom`)]})]}),a===`custom`&&V(`div`,{className:`palette-custom`,children:[V(`label`,{className:`palette-color`,htmlFor:`custom-accent`,children:[P(`input`,{id:`custom-accent`,type:`color`,value:s.accent,onChange:d(`accent`)}),V(`span`,{children:[e(`settings.colors.accent`),P(`small`,{children:e(`settings.colors.accentHint`)})]})]}),V(`label`,{className:`palette-color`,htmlFor:`custom-base`,children:[P(`input`,{id:`custom-base`,type:`color`,value:s.base,onChange:d(`base`)}),V(`span`,{children:[e(`settings.colors.base`),P(`small`,{children:e(`settings.colors.baseHint`)})]})]}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>c(v),children:e(`settings.colors.reset`)}),P(`p`,{className:`settings-hint`,children:e(`settings.colors.hint`)})]})]}),P(ON,{}),P(VN,{}),P(SN,{title:e(`settings.shortcuts`),children:P(`dl`,{className:`shortcut-list`,children:WN.map(([t,n])=>V(`div`,{className:`shortcut-row`,children:[P(`dt`,{children:P(`kbd`,{children:kc(t)})}),P(`dd`,{children:e(n)})]},t))})})]})}function KN(e){return/not reachable|not answering|model server at|ConnectionPool|NewConnectionError|Connection refused|Max retries/i.test(e)}function qN(e){return/gaia init/i.test(e??``)}function JN(e){return!!e&&!e.lemonade_running&&(qN(e.start_command)||qN(e.start_instruction))}function YN({className:e=`btn-secondary`}){let t=T();return P(`button`,{type:`button`,className:e,onClick:()=>window.dispatchEvent(new CustomEvent(`gaia:set-up-local`)),children:t(`settings.errors.setUpLocal`)})}function XN({message:e,onRetry:t}){let n=T(),r=k(e=>JN(e.systemStatus));return KN(e)?V(`div`,{className:`settings-notice`,role:`alert`,children:[P(`strong`,{children:n(r?`settings.errors.notInstalledTitle`:`settings.errors.serverDownTitle`)}),P(`p`,{children:n(r?`settings.errors.notInstalled`:`settings.errors.serverDown`)}),r&&P(YN,{className:`btn-primary`}),t&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:t,children:n(`settings.key.checkAgain`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,n(`settings.errors.details`)]}),P(`bdi`,{dir:`ltr`,className:`settings-notice-raw`,children:e})]})]}):P(`p`,{className:`settings-error`,role:`alert`,children:e})}function ZN({onAdded:e}){let t=T(),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),f=(0,X.useRef)(``),p=(0,X.useCallback)(async e=>{let t=n.trim();f.current=t,l(`check`),d(null);try{let n=await cn(t,e);if(f.current!==t)return;s(n),a(n.file??e)}catch(e){if(f.current!==t)return;s(null),d(e instanceof Error?e.message:String(e))}finally{l(null)}},[n]),m=(0,X.useCallback)(async()=>{l(`add`),d(null);try{let{report:o}=await xt(n.trim(),i);r(``),a(``),s(null),e(o.display_name??o.model_id??t(`settings.custom.theModel`))}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(null)}},[e,i,n,t]);return V(`form`,{className:`settings-field custom-model-add`,onSubmit:e=>{e.preventDefault(),p(``)},children:[P(`label`,{className:`visually-hidden`,htmlFor:`custom-model-url`,children:t(`settings.custom.title`)}),P(`span`,{className:`settings-hint`,children:t(`settings.custom.hint`)}),V(`div`,{className:`settings-row`,children:[P(`input`,{id:`custom-model-url`,className:`settings-input`,type:`url`,inputMode:`url`,dir:`ltr`,spellCheck:!1,autoComplete:`off`,value:n,readOnly:c!==null,onChange:e=>{r(e.target.value),s(null),a(``),f.current=``},placeholder:`https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF`}),V(`button`,{type:`submit`,className:`btn-secondary`,disabled:c!==null||!n.trim(),children:[c===`check`?P(q,{size:13,className:`spin`}):null,` `,t(`settings.custom.check`)]})]}),o&&(()=>{let e=P(`ul`,{className:`custom-model-checks`,"aria-label":t(`settings.custom.checks`),children:o.checks.map(e=>V(`li`,{className:e.ok?`is-ok`:`is-failed`,children:[e.ok?P(mr,{size:13,"aria-label":t(`settings.custom.passed`)}):P(Y,{size:13,"aria-label":t(`settings.custom.failed`)}),V(`bdi`,{children:[P(`strong`,{children:e.label}),` — `,e.detail]})]},e.id))});return o.ok?V(`details`,{className:`custom-model-checks-summary`,children:[V(`summary`,{children:[P(mr,{size:13,"aria-hidden":`true`}),` `,t(`settings.custom.allPassed`,{n:o.checks.length})]}),e]}):e})(),o&&o.warnings.length>0&&P(`ul`,{className:`custom-model-checks`,"aria-label":t(`settings.custom.warnings`),children:o.warnings.map(e=>V(`li`,{className:`is-warning`,children:[P(J,{size:13,"aria-label":t(`settings.custom.warning`)}),` `,P(`bdi`,{children:e})]},e))}),o&&o.variants.length>1&&V(`div`,{className:`settings-row`,children:[P(`label`,{className:`settings-hint`,htmlFor:`custom-model-quant`,children:t(`settings.custom.quantization`)}),P(`select`,{id:`custom-model-quant`,className:`settings-input`,value:i,onChange:e=>void p(e.target.value),disabled:c!==null,children:o.variants.map(e=>V(`option`,{value:e.file,children:[e.quant,` · `,e.size_gb,` GB`,e.fits?``:` · ${t.bare(`settings.custom.tooLarge`)}`]},e.file))})]}),o?.ok&&V(`div`,{className:`settings-row`,children:[V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void m(),disabled:c!==null,children:[c===`add`?P(q,{size:13,className:`spin`}):null,` `,t(`settings.custom.add`,{name:o.display_name??``})]}),P(`span`,{className:`settings-hint`,children:t(`settings.model.sizeDownload`,{size:`${o.size_gb} GB`})})]}),u&&P(XN,{message:u})]})}function QN(e){return e instanceof Error?e.message:String(e)}function $N(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function eP({downloadsSlot:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),b=Ls(e=>e.status),x=Ls(e=>e.started),S=(0,X.useMemo)(()=>Ps(b,x),[b,x]),C=Ls(e=>e.error),w=Ls(e=>e.refresh),E=Ls(e=>e.enqueue),O=Ls(e=>e.cancel),k=(0,X.useCallback)(async(e=!1)=>{a(null);try{let t=await Ce();r(t),s(n=>e||!n?fj(t):n)}catch(e){a(QN(e))}},[]);(0,X.useEffect)(()=>{k(!0),w(),(async()=>{try{_(await Nn()??null)}catch(e){y(QN(e))}})()},[k,w]);let A=(S?.models??[]).filter(e=>e.state===`ready`).map(e=>e.id).join(`,`),j=(0,X.useRef)(A);(0,X.useEffect)(()=>{A!==j.current&&(j.current=A,k(!0))},[A,k]);let M=(0,X.useMemo)(()=>{let e={};for(let t of S?.models??[])e[t.id]=t;return e},[S]),N=(0,X.useMemo)(()=>{let e={};for(let t of n?.catalog??[])e[t.id]=t.name;return e},[n]),F=(0,X.useMemo)(()=>n?fj(n):null,[n]),I=ZA(n),L=n&&o?_j(I,o).filter(e=>M[e.id]?.state!==`downloading`):[],ee=L.reduce((e,t)=>e+(t.size_gb??0),0),R=!!n&&!!o&&!!F&&(!$N(o.ticked,F.ticked)||o.defaultChat!==F.defaultChat||L.length>0),z=(0,X.useCallback)(async(e,i)=>{if(!n||!o)return;if(p(null),!e){let e=bj(I,o).filter(e=>!e.downloaded||e.id===o.defaultChat);if(e.length>0&&e.every(e=>e.need_gb!=null)){l({kind:`no_fit`,models:e});return}}let a=yj(n,o);if(a&&!i)l({kind:`low_disk`,message:a.drop?t(`setup.summary.shortDrop`,{need:$(a.needGb),free:$(a.freeGb),drive:Pj(n.disk?.path??null)??t(`setup.summary.theDrive`),freeUp:$(a.freeUpGb),name:a.drop.name,saves:$(a.drop.size_gb??0)}):t(`setup.summary.short`,{need:$(a.needGb),free:$(a.freeGb),drive:Pj(n.disk?.path??null)??t(`setup.summary.theDrive`),freeUp:$(a.freeUpGb)})});else{d(!0);try{let i=n;if(o.defaultChat&&o.defaultChat!==i.chat_model.id)try{i=await Le(o.defaultChat,e||m)}catch(e){let t=ht(e);if(t){l({kind:`server`,detail:t});return}throw e}for(let e of xj(i,o))i=await ft(e.id,e.skipped);let a=_j(ZA(i),o).map(e=>e.id).filter(e=>M[e]?.state!==`downloading`);r(i),s({...o,defaultChat:i.chat_model.id}),cs.getState().refresh(),a.length&&await E(a,{acknowledgeLowDisk:!0}),p({ok:!0,text:t(`settings.models.applied`)})}catch(e){p({ok:!1,text:QN(e)})}finally{d(!1)}}},[n,o,I,m,M,E,t]),B=(0,X.useCallback)(async e=>{l(null),d(!0),p(null);try{let n=await dn(e.id);Uo(),r(n),s(fj(n)),p({ok:!0,text:t(`settings.models.removed`,{name:e.name,size:$(n.freed_gb)})})}catch(e){p({ok:!1,text:QN(e)})}finally{d(!1)}},[t]),te=(0,X.useCallback)((e,t)=>{(async()=>{try{t===`verify`&&await dn(e),await E([e])}catch(e){p({ok:!1,text:QN(e)})}})()},[E]),ne=!!S&&(S.models?.length??0)>0&&(CM(S)||S.models.some(e=>e.state!==`skipped`))&&S&&V(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-downloads-title`,children:[P(`span`,{className:`settings-label`,id:`settings-downloads-title`,children:t(`settings.models.downloads`)}),P(EM,{status:S,names:N,freeGb:n?.disk?.free_gb??null,onCancel:()=>void O(),onRetry:te,onResume:e=>void E([e]),onResumeAll:()=>void E((S.models??[]).filter(e=>e.state===`cancelled`).map(e=>e.id))}),C&&P(`p`,{className:`settings-error`,role:`alert`,children:C})]});return V(D.Fragment,{children:[P(SN,{title:t(`settings.models.manage`),hint:t(`settings.models.manageHint`),forceOpen:!!i||f?.ok===!1,children:V(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-models-title`,children:[P(`span`,{className:`visually-hidden`,id:`settings-models-title`,children:t(`settings.models.title`)}),P(`p`,{className:`settings-hint`,children:t(`settings.models.lede`)}),i&&P(XN,{message:i}),n&&!n.lemonade.reachable&&P(`p`,{className:`settings-hint`,children:t(`settings.models.unavailable`)}),!n&&!i&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,t(`setup.models.loading`)]}),n&&n.lemonade.reachable&&o&&V(D.Fragment,{children:[P(Ij,{plan:n,selection:o,onToggle:(e,t)=>s(mj(o,I,e,t)),onDefaultChat:e=>s(hj(o,I,e)),labelledBy:`settings-models-title`,place:`settings`,disabled:u,progress:M,rowActions:e=>e.downloaded&&e.id!==o.defaultChat?P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>l({kind:`remove`,entry:e}),disabled:u||M[e.id]?.state===`downloading`,"aria-label":t(`settings.models.removeAria`,{name:e.name}),children:t(`settings.models.remove`)}):null}),P(Nj,{plan:n,selection:o}),P(`div`,{className:`models-apply`,children:V(`button`,{type:`button`,className:`btn-primary`,disabled:!R||u,onClick:()=>void z(!1,!1),children:[u&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),u?t(`settings.models.applying`):L.length>0?t(`settings.models.applyDownload`,{size:$(Math.round(ee*10)/10)}):t(`settings.models.apply`)]})})]}),f?.ok&&P(`p`,{className:`settings-ok`,role:`status`,children:f.text}),f&&!f.ok&&P(XN,{message:f.text})]})}),(g?.applies||v&&!KN(v))&&P(SN,{title:t(`gpu.settingsTitle`),titleId:`settings-gpu-title`,defaultOpen:!!g?.pending||!!v,children:V(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-gpu-title`,children:[v&&P(`p`,{className:`settings-error`,role:`alert`,children:v}),g?.applies&&P(tM,{status:g,onStatus:_,mode:`settings`,names:N,headingId:`settings-gpu-title`})]})}),e?(0,eS.createPortal)(ne,e):e===void 0&&ne,c?.kind===`remove`&&P(Kj,{title:t(`settings.models.removeTitle`,{name:c.entry.name}),confirmLabel:t(`settings.models.removeConfirm`),cancelLabel:t(`settings.models.keep`),danger:!0,onConfirm:()=>void B(c.entry),onCancel:()=>l(null),children:P(`p`,{children:QA(c.entry)?t(`settings.models.removeVision`,{size:$(c.entry.full_size_gb??0)}):t(`settings.models.removeBody`,{size:$(c.entry.full_size_gb??0)})})}),c?.kind===`no_fit`&&P(Kj,{title:c.models.length===1?t(`setup.confirm.noFitOne`,{name:c.models[0].name}):t(`setup.confirm.noFitMany`),confirmLabel:t(`setup.confirm.downloadAnyway`),cancelLabel:t(`setup.confirm.pickSmaller`),onConfirm:()=>{l(null),h(!0),z(!0,!1)},onCancel:()=>l(null),children:c.models.map(e=>V(`p`,{children:[P(`bdi`,{children:e.name}),`: `,Aj(e,t)]},e.id))}),c?.kind===`low_disk`&&P(Kj,{title:t(`setup.confirm.lowDiskTitle`),confirmLabel:t(`setup.confirm.downloadAnyway`),cancelLabel:t(`setup.confirm.changeModels`),onConfirm:()=>{l(null),z(!0,!0)},onCancel:()=>l(null),children:P(`p`,{children:c.message})}),c?.kind===`server`&&P(Kj,{title:t(`setup.confirm.noFitServerTitle`),confirmLabel:t(`setup.confirm.useAnyway`),cancelLabel:t(`setup.confirm.changeModels`),onConfirm:()=>{l(null),h(!0),z(!0,!1)},onCancel:()=>l(null),children:P(`p`,{children:c.detail.message})})]})}var tP=`auto`;function nP({model:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null);(0,X.useEffect)(()=>{r(null),a(null),l(null),_e(e).then(r).catch(e=>a(e instanceof Error?e.message:String(e)))},[e]);let u=(0,X.useCallback)(async n=>{s(!0),a(null),l(null);try{let i=await Ke(e,n===tP?null:Number(n));r(i);let a={name:i.display_name,size:i.chosen?Cs(i.chosen):g(`settings.ctx.automaticSize`)},o=i.reload?.reason;i.reload?.started?l(t(`settings.ctx.reloading`,a)):l(o===`already_loaded`?t(`settings.ctx.alreadyLoaded`,a):o===`warm_up`?t(`settings.ctx.warmUp`,a):o===`busy`?t(`settings.ctx.busy`,a):o===`not_gaias_server`?t(`settings.ctx.ownServer`,a):t(o===`restarting`?`settings.ctx.restarting`:`settings.ctx.nextLoad`))}catch(e){a(e instanceof Error?e.message:String(e))}finally{s(!1)}},[e,t]);if(i&&!n)return KN(i)?P(`p`,{className:`settings-hint`,children:t(`settings.ctx.serverDown`)}):P(`p`,{className:`settings-error`,role:`alert`,children:i});if(!n)return V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.ctx.checking`)]});let d=n.chosen==null?tP:String(n.chosen),f=n.chosen!=null&&n.loaded_ctx!=null&&n.loaded_ctx!==n.chosen;return V(D.Fragment,{children:[V(`div`,{className:`model-in-use-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`ctx-size`,children:t(`settings.ctx.label`)}),V(`select`,{id:`ctx-size`,className:`settings-input`,value:d,onChange:e=>void u(e.target.value),disabled:o||n.options.length===0,children:[P(`option`,{value:tP,children:n.automatic?t.bare(`settings.ctx.automaticAt`,{size:Cs(n.automatic)}):t.bare(`settings.ctx.automatic`)}),n.options.map(e=>P(`option`,{value:String(e),children:t.bare(`settings.ctx.tokens`,{size:Cs(e)})},e))]})]}),n.note&&P(`span`,{className:`settings-hint`,children:P(`bdi`,{children:n.note})}),!n.note&&!!n.max_fit&&V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.ctx.about`)]}),P(`span`,{className:`settings-hint`,children:t(`settings.ctx.explain`,{size:Cs(n.max_fit),name:n.display_name,memory:n.memory_source})})]}),f&&P(`span`,{className:`settings-hint`,children:t(`settings.ctx.loadedAt`,{size:Cs(n.loaded_ctx)})}),o&&V(`span`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.ctx.applying`)]}),c&&P(`p`,{className:`settings-ok`,role:`status`,children:c}),i&&P(`p`,{className:`settings-error`,role:`alert`,children:i})]})}function rP({row:e,providerName:t,choices:n,labels:r,disabled:i,onSwitch:a}){let o=T(),s=cs(e=>e.active),c=s?.model??null,l=!!s?.remote,u=n.some(e=>us(c,e.id)),d=s?.downloaded??e?.downloaded,f=l?null:e?.state===`loaded`?o(`settings.model.loaded`):d===!0?o(`settings.model.downloaded`):d===!1?o(`settings.model.notDownloaded`):null,p=e?.placement?.device;return V(`section`,{className:`settings-card model-in-use`,"aria-label":o(`settings.model.inUseTitle`),children:[P(`span`,{className:`model-in-use-label`,children:o(`settings.model.inUseTitle`)}),c?P(`bdi`,{className:`model-in-use-name`,title:c,children:e?.display_name||s?.display_name||ds(c)}):P(`span`,{className:`settings-hint`,children:o(`settings.model.noneInUse`)}),s?.config_error&&P(`p`,{className:`settings-error`,role:`alert`,children:P(`bdi`,{children:s.config_error})}),c&&!l&&e?.available===!1&&P(`p`,{className:`settings-error`,role:`alert`,children:o(`settings.model.inUseCantRun`)}),c&&V(`span`,{className:`model-chips`,children:[l&&P(`span`,{className:`model-badge is-device`,children:o(`settings.model.cloud`)}),l&&t&&P(`bdi`,{className:`model-badge is-ready`,children:t}),p&&P(`span`,{className:`model-badge is-device`,children:p.toUpperCase()}),f&&P(`span`,{className:`model-badge ${e?.state===`loaded`?`is-loaded`:`is-ready`}`,children:f}),e?.fits===!0&&P(`span`,{className:`model-badge is-fit`,children:o(`settings.model.fits`)}),!!e?.size_gb&&V(`bdi`,{dir:`ltr`,className:`model-badge is-size`,children:[e.size_gb,` GB`]}),l&&!!e?.context_length&&P(`span`,{className:`model-badge is-ready`,children:o(`settings.model.contextChip`,{size:Cs(e.context_length)})})]}),(n.length>1||n.length===1&&!u)&&V(`div`,{className:`model-in-use-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`model-switch`,children:o(`settings.model.switch`)}),V(`select`,{id:`model-switch`,className:`settings-input`,value:u?n.find(e=>us(c,e.id))?.id:``,onChange:e=>a(e.target.value),disabled:i,children:[!u&&P(`option`,{value:``,disabled:!0,children:o.bare(`settings.model.switchPlaceholder`)}),n.map(e=>P(`option`,{value:e.id,children:r[e.id]},e.id))]})]}),c&&!l&&s?.downloaded!==!1&&P(nP,{model:c})]})}function iP({model:e,label:t,current:n,remote:r,busy:i,confirmingRemove:a,onUse:o,onDownload:s,onAskRemove:c,onKeep:l,onRemove:u,onNpuRecheck:d}){let f=T(),p=Ts(e)?e.download_progress:null,m=e.placement?.label,h=f.compose(t=>[m&&(e.placement?.source===`expected`?t(`settings.model.expected`,{label:m}):m),e.size_gb?t(e.downloaded?`settings.model.sizeOnDisk`:`settings.model.sizeDownload`,{size:`${e.size_gb} GB`}):null,e.tokens_per_second?t(`settings.model.speed`,{speed:`${Math.round(e.tokens_per_second)} tok/s`}):null,!e.placement&&e.context_length?t(`settings.model.contextTokens`,{size:e.context_length.toLocaleString()}):null].filter(Boolean).join(` · `)),g=!!(e.display_name||h||e.evidence||e.custom&&e.source_url);return V(`li`,{className:`model-row${n?` is-current`:``}`,children:[V(`div`,{className:`model-row-text`,children:[P(`bdi`,{className:`model-row-name`,title:e.id,children:t}),V(`div`,{className:`model-chips`,children:[e.placement?.device&&P(`span`,{className:`model-badge is-device`,children:e.placement.device.toUpperCase()}),e.rank&&V(`span`,{className:`model-badge is-rank`,children:[V(`bdi`,{dir:`ltr`,children:[`#`,e.rank]}),` `,e.note]}),e.state===`loaded`&&P(`span`,{className:`model-badge is-loaded`,children:f(`settings.model.loaded`)}),e.fits===!0&&e.available!==!1&&P(`span`,{className:`model-badge is-fit`,children:f(`settings.model.fits`)}),e.custom&&P(`span`,{className:`model-badge is-custom`,children:f(`settings.model.custom`)}),!!e.size_gb&&V(`bdi`,{dir:`ltr`,className:`model-badge is-size`,children:[e.size_gb,` GB`]}),g&&V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,f(`settings.model.details`)]}),e.display_name&&P(`span`,{className:`model-row-meta`,children:P(`bdi`,{children:e.id})}),h&&P(`span`,{className:`model-row-meta`,children:h}),e.evidence&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.measured`,{evidence:e.evidence})}),e.custom&&e.source_url&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.from`,{url:e.source_url})})]})]}),r&&P(`span`,{className:`model-row-meta${e.price?``:` is-unknown-price`}`,children:QT(e.price,f)}),e.placement?.warning&&P(`span`,{className:`model-row-meta is-warning`,role:`alert`,children:P(`bdi`,{children:e.placement.warning})}),e.npu_problems?.length?P(PM,{problems:e.npu_problems,disabled:i!==null,onRecheck:d,id:`npu-problems-${e.id}`}):e.unavailable_reason&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.cantRun`,{reason:e.unavailable_reason})}),p&&P(`progress`,{max:100,value:p.percent,"aria-label":f(`settings.model.downloadingAria`,{name:t})})]}),V(`div`,{className:`model-row-actions`,children:[e.custom&&!n&&!p&&(a?V(D.Fragment,{children:[V(`button`,{type:`button`,className:`btn-danger`,onClick:u,disabled:i!==null,children:[i===`rm:${e.id}`?P(q,{size:13,className:`spin`}):null,e.downloaded?f(`settings.model.removeDownload`):f(`settings.models.remove`)]}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:l,disabled:i!==null,children:f(`settings.models.keep`)})]}):P(`button`,{type:`button`,className:`btn-secondary`,onClick:c,disabled:i!==null,"aria-label":f(`settings.models.removeAria`,{name:t}),children:f(`settings.models.remove`)})),n&&e.available===!1?P(`span`,{className:`model-row-current is-blocked`,children:f(`settings.model.inUseBlocked`)}):n?V(`span`,{className:`model-row-current`,children:[P(mr,{size:13,"aria-hidden":`true`}),` `,f(`settings.model.inUse`)]}):e.available===!1?null:p?V(`span`,{className:`model-row-current`,children:[P(q,{size:13,className:`spin`}),` `,p.message?P(`bdi`,{children:p.message}):V(`bdi`,{dir:`ltr`,children:[Math.round(p.percent),`%`]})]}):e.downloaded?V(`button`,{type:`button`,className:`btn-secondary`,onClick:o,disabled:i!==null,"aria-label":f(`settings.model.useAria`,{name:t}),children:[i===e.id?P(q,{size:13,className:`spin`}):null,` `,f(`settings.model.use`)]}):V(`button`,{type:`button`,className:`btn-secondary`,onClick:s,disabled:i!==null,"aria-label":f(`settings.model.downloadAria`,{name:t}),children:[i===`dl:${e.id}`?P(q,{size:13,className:`spin`}):null,` `,f(`settings.model.download`)]})]})]})}function aP(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(!1),l=(0,X.useCallback)(async e=>{c(!0),i(null);try{let t=await e();n(t),o(t.limit_usd==null?``:String(t.limit_usd))}catch(e){i(e instanceof Error?e.message:String(e))}finally{c(!1)}},[]);if((0,X.useEffect)(()=>{l(H)},[l]),!t)return r?P(`p`,{className:`settings-error`,role:`alert`,children:r}):V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.spend.loading`)]});let u=t.limit_usd,d=a.trim()===``?null:Number(a),f=d===null||Number.isFinite(d)&&d>0,p=d!==u;return V(`section`,{className:`settings-field spending`,"aria-label":e(`settings.spend.aria`),children:[P(`span`,{className:`settings-label`,children:e(`settings.spend.title`)}),V(`p`,{className:`spending-total`,children:[P(`bdi`,{dir:`ltr`,children:P(`strong`,{children:$T(t.total_usd)})}),u!=null&&V(D.Fragment,{children:[` `,e(`settings.spend.ofLimit`,{limit:$T(u)})]}),V(`span`,{className:`settings-hint`,children:[` · `,e.plural(`settings.spend.turns`,t.turns)]})]}),t.unpriced_turns>0&&P(`p`,{className:`settings-hint`,children:e.plural(`settings.spend.unpriced`,t.unpriced_turns)}),t.unreported_turns>0&&P(`p`,{className:`settings-hint`,children:e.plural(`settings.spend.unreported`,t.unreported_turns)}),t.state===`near`&&V(`p`,{className:`spending-warning`,role:`status`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.near`)]}),t.state===`reached`&&V(`div`,{className:`spending-warning`,role:`alert`,children:[V(`p`,{children:[P(J,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.reached`)]}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void l(gn),children:e(`settings.spend.allow`)})]}),t.state===`allowed_over`&&P(`p`,{className:`settings-hint`,children:e(`settings.spend.allowed`)}),V(`form`,{className:`settings-row`,onSubmit:e=>{e.preventDefault(),f&&p&&l(()=>Qe(d))},children:[P(`label`,{className:`spending-limit-label`,htmlFor:`spend-limit`,children:e(`settings.spend.limit`)}),P(`input`,{id:`spend-limit`,className:`settings-input`,type:`number`,min:`0.01`,step:`0.01`,inputMode:`decimal`,placeholder:e.bare(`settings.spend.noLimit`),value:a,onChange:e=>o(e.target.value),"aria-invalid":!f}),V(`button`,{type:`submit`,className:`btn-secondary`,disabled:s||!f||!p,children:[s?P(q,{size:13,className:`spin`}):null,` `,e(`settings.advanced.save`)]}),u!=null&&P(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void l(()=>Qe(null)),children:e(`settings.spend.removeLimit`)})]}),P(`span`,{className:`settings-hint`,children:e(`settings.spend.how`)}),r&&P(`p`,{className:`settings-error`,role:`alert`,children:r})]})}var oP=2e3;function sP(e,t){return e.key_source===`environment`?t(`settings.key.setIn`,{name:e.env_var??``}):`••••••••••••••••••••${e.key_hint?` ${e.key_hint}`:``}`}function cP(){let e=T(),t=cs(e=>e.active),n=cs(e=>e.select),r=cs(e=>e.refresh),i=cs(e=>e.rememberNames),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),l=k(e=>e.settingsProvider),[u,d]=(0,X.useState)(l??t?.provider??`local`),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(!1),[w,E]=(0,X.useState)(!1),[O,A]=(0,X.useState)({base_url:``,auth_header_name:``,auth_header_prefix:``}),[j,M]=(0,X.useState)(null),[N,F]=(0,X.useState)(null),[I,L]=(0,X.useState)(null),[ee,R]=(0,X.useState)(null),[z,B]=(0,X.useState)(!1),[te,ne]=(0,X.useState)(null),[re,ie]=(0,X.useState)(null),ae=(0,X.useRef)(u);ae.current=u;let oe=(0,X.useRef)(!0);(0,X.useEffect)(()=>(oe.current=!0,()=>{oe.current=!1}),[]);let H=a?.find(e=>e.id===u)??null,U=e=>e?.network?.reachable===!1,se=e=>!!e?.blocked,W=!!H&&!se(H)&&(!H.remote||!!H.models_discovered),G=(0,X.useCallback)(async()=>{c(null);try{let e=await Tn();o(e.providers),e.lemonade_error&&c(e.lemonade_error)}catch(e){c(e instanceof Error?e.message:String(e))}},[]),ce=(0,X.useCallback)(async(t,n=!1)=>{n||(p(null),h(null));try{let n=await Zt(t);i(n.models),p(n.models),F(n.memory_gb?`${n.memory_gb} GB (${n.memory_source})`:n.capacity_error??null),n.blocked&&h(e(`settings.privacy.localOnlyBlocked`))}catch(e){h(e instanceof Error?e.message:String(e))}},[i,e]);(0,X.useEffect)(()=>{G()},[G]);let le=!!a?.some(e=>e.key_state===`waiting_for_os_permission`);(0,X.useEffect)(()=>{if(!le)return;let e=setInterval(()=>{G()},oP);return()=>clearInterval(e)},[le,G]);let ue=t?.provider;(0,X.useEffect)(()=>{ue&&!l&&d(ue)},[ue,l]),(0,X.useEffect)(()=>{x(``),C(!1),E(!1),L(null),_(``),y(!1),B(!1)},[u]),(0,X.useEffect)(()=>{W?ce(u):p(null)},[u,W,ce]);let de=(0,X.useCallback)(async()=>{if(H){M(`connect`),L(null);try{let t=u===`amd`?{api_key:b||void 0,...Object.fromEntries(Object.entries(O).filter(([,e])=>e!==``))}:{api_key:b||void 0},n=()=>!oe.current||ae.current!==u,r=await Rt(u,t,e=>{n()||L({ok:!0,text:e})},n);if(n())return;x(``),C(!1),L({ok:!0,text:r.remember_error?e(`settings.key.sessionOnly`,{reason:r.remember_error}):r.known_models?e(`settings.key.knownModels`,{name:H.name}):r.remembered?e(`settings.key.kept`):e(`settings.key.connectedDone`)}),await G()}catch(e){oe.current&&ae.current===u&&L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{oe.current&&M(null)}}},[O,u,b,G,H,e]),pe=(0,X.useCallback)(async()=>{M(`forget`),E(!1),L(null);try{await Kt(u),L({ok:!0,text:e(`settings.key.cleared`)}),await G(),await r()}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[u,G,r,e]),me=(0,X.useCallback)(async t=>{M(t),L(null);try{await n(t),L({ok:!0,text:e(`settings.model.switched`,{name:ds(t)})}),await ce(u,!0)}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[u,ce,n,e]),he=(0,X.useCallback)(async e=>{M(`dl:${e}`),L(null),B(!1);try{await fe(e),await ce(`local`,!0)}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[ce]),ge=(0,X.useCallback)(async t=>{M(`rm:${t}`),L(null);try{let n=await nt(t);R(null);let i=n.cleared.includes(`last_model`)?`settings.model.removedLast`:n.cleared.includes(`default_model`)?`settings.model.removedDefault`:`settings.model.removed`;L({ok:!0,text:e(i,{name:n.display_name})}),await ce(`local`,!0),await r()}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[ce,r,e]),_e=(0,X.useCallback)(async t=>{L({ok:!0,text:e(`settings.model.added`,{name:t})}),B(!0),await ce(`local`,!0)},[ce,e]),ve=!!f?.some(Ts);(0,X.useEffect)(()=>{if(ve)return()=>{r()}},[ve,r]),(0,X.useEffect)(()=>{if(u!==`local`||!ve)return;let e=setInterval(()=>{ce(`local`,!0)},oP);return()=>clearInterval(e)},[ve,u,ce]);let ye=t?.model,be=f?.find(e=>us(ye,e.id));(0,X.useEffect)(()=>{be&&ne(be)},[be]);let xe=(0,X.useMemo)(()=>{let e=g.trim().toLowerCase();return(f??[]).filter(t=>!e||t.id.toLowerCase().includes(e)||(t.display_name??``).toLowerCase().includes(e))},[f,g]),Se=xe.filter(e=>e.available!==!1),Ce=u===`fireworks`&&!v&&!g.trim()&&Se.some(e=>e.rank!==null),we=e=>e.rank!==null||e.id===t?.model,Te=Ce?Se.filter(we):Se,Ee=Ce?Se.filter(e=>!we(e)):[],De=xe.filter(e=>e.available===!1),Oe=ys(f??[]),ke=!!g.trim(),Ae=e=>us(t?.model,e.id),je=H?.id===`local`,Me=Te.filter(e=>e.downloaded).sort((e,t)=>Number(Ae(t))-Number(Ae(e))),Ne=Te.filter(e=>!e.downloaded),Pe=(f??[]).filter(e=>e.available!==!1&&e.downloaded),Fe=Pe.filter(we),Ie=u===`fireworks`&&Fe.some(e=>e.rank!==null)?Fe:Pe,Le=e=>P(iP,{model:e,label:Oe[e.id],current:Ae(e),remote:!!H?.remote,busy:j,confirmingRemove:ee===e.id,onUse:()=>void me(e.id),onDownload:()=>void he(e.id),onAskRemove:()=>R(e.id),onKeep:()=>R(null),onRemove:()=>void ge(e.id),onNpuRecheck:()=>void ce(u,!0)},e.id);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.model`)}),P(rP,{row:be??(us(te?.id,t?.model)?te:null),providerName:a?.find(e=>e.id===t?.provider)?.name??null,choices:W?Ie:[],labels:Oe,disabled:j!==null,onSwitch:e=>void me(e)}),P(`div`,{className:`provider-tabs`,role:`radiogroup`,"aria-label":e(`settings.model.whereRuns`),children:(a??[{id:`local`,name:`Local`,remote:!1}]).map(t=>V(`button`,{type:`button`,role:`radio`,"aria-checked":u===t.id,className:`provider-tab${u===t.id?` is-active`:``}${U(t)||se(t)?` is-disabled`:``}`,onClick:()=>d(t.id),disabled:(U(t)||se(t))&&u!==t.id,title:se(t)?e(`settings.privacy.localOnlyBlocked`):U(t)?t.network?.detail??void 0:void 0,children:[t.remote?P(Ir,{size:14,"aria-hidden":`true`}):P(Wr,{size:14,"aria-hidden":`true`}),P(`span`,{children:t.name}),t.remote&&t.models_discovered&&P(`span`,{className:`provider-tab-dot`,"aria-label":e(`settings.key.connectedDot`)})]},t.id))}),s&&P(XN,{message:s,onRetry:()=>{G(),ce(u)}}),H&&V(`section`,{className:`settings-card`,"aria-label":H.name,children:[H.remote&&P(`p`,{className:`settings-note`,children:P(`bdi`,{children:H.privacy_notice})}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,e(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:e(`settings.model.lede`)}),je&&P(`p`,{className:`settings-hint`,children:P(`bdi`,{children:H.privacy_notice})}),je&&P(`p`,{className:`settings-hint`,children:e(`settings.model.devices`)}),je&&N&&P(`p`,{className:`settings-hint`,children:e(`settings.model.memory`,{memory:N})})]}),H.remote&&!W&&V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,children:e(`settings.model.prices`)}),P(WA,{provider:H.id})]}),se(H)&&P(`div`,{className:`settings-field`,children:P(`p`,{className:`settings-error`,role:`alert`,children:e(`settings.privacy.localOnlyBlocked`)})}),U(H)&&V(`div`,{className:`settings-field`,children:[P(`p`,{className:`settings-error`,role:`alert`,children:H.network?.detail}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void G(),children:e(`settings.key.checkAgain`)})]}),H.remote&&!U(H)&&!se(H)&&V(`form`,{className:`settings-field`,onSubmit:e=>{e.preventDefault(),de()},children:[V(`div`,{className:`settings-row settings-row-between`,children:[P(`span`,{className:`settings-label`,children:e(`settings.key.title`)}),H.key_source&&P(`span`,{className:`settings-key-status ${W?`settings-ok`:`settings-error`}`,children:e(W?`settings.key.connected`:`settings.key.notConnected`)})]}),!H.key_source&&P(`span`,{className:`settings-hint`,children:H.key_state===`waiting_for_os_permission`?H.key_message??e(`settings.key.waitingOs`):e(`settings.key.none`)}),H.id===`amd`&&(!H.key_source||S)&&V(`div`,{className:`settings-grid`,children:[P(`input`,{className:`settings-input`,placeholder:e(`settings.key.gatewayPlaceholder`),value:O.base_url,onChange:e=>A({...O,base_url:e.target.value}),"aria-label":e(`settings.key.gatewayUrl`)}),P(`input`,{className:`settings-input`,placeholder:e(`settings.key.headerPlaceholder`),value:O.auth_header_name,onChange:e=>A({...O,auth_header_name:e.target.value}),"aria-label":e(`settings.key.headerName`)})]}),H.key_source&&!S?V(`div`,{className:`settings-row`,children:[P(`input`,{className:`settings-input settings-key-masked`,readOnly:!0,value:sP(H,e),"aria-label":e(`settings.key.savedAria`,{name:H.name})}),!W&&V(`button`,{type:`submit`,className:`btn-primary`,disabled:j!==null,children:[j===`connect`?P(q,{size:13,className:`spin`}):null,e(`settings.key.reconnect`)]}),(H.key_source!==`environment`||H.key_from_gaia_env)&&(w?V(D.Fragment,{children:[P(`span`,{className:`settings-hint`,children:e(`settings.key.removeAsk`)}),P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void pe(),disabled:j!==null,children:e(`settings.models.remove`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>E(!1),children:e(`settings.models.keep`)})]}):V(D.Fragment,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>C(!0),disabled:j!==null,children:e(`settings.key.replace`)}),H.key_source!==`environment`&&P(`button`,{type:`button`,className:`btn-secondary settings-key-remove`,onClick:()=>E(!0),disabled:j!==null,"aria-label":e(`settings.key.remove`),title:e(`settings.key.remove`),children:P(lo,{size:14,"aria-hidden":`true`})})]}))]}):V(`div`,{className:`settings-row`,children:[P(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,spellCheck:!1,autoFocus:S,value:b,onChange:e=>x(e.target.value),placeholder:e(S?`settings.key.pasteNew`:`settings.key.paste`),"aria-label":e(`settings.key.fieldAria`,{name:H.name})}),V(`button`,{type:`submit`,className:`btn-primary`,disabled:j!==null||!b,children:[j===`connect`?P(q,{size:13,className:`spin`}):null,e(S?`settings.key.save`:`settings.key.connect`)]}),S&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{x(``),C(!1)},disabled:j!==null,children:e(`settings.key.cancel`)})]}),H.key_source&&!W&&!H.error&&!S&&P(`p`,{className:`settings-hint`,children:e(`settings.key.notConnectedHint`,{name:H.name})}),H.error&&P(`p`,{className:`settings-error`,role:`alert`,children:H.error})]}),I?.ok&&P(`p`,{className:`settings-ok`,role:`status`,children:I.text}),I&&!I.ok&&P(XN,{message:I.text}),H.known_models&&P(`p`,{className:`settings-hint`,role:`status`,children:e(`settings.key.knownList`,{name:H.name})}),je&&P(`div`,{className:`models-downloads-slot`,ref:ie}),W&&V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,children:e(`settings.model.models`)}),(f?.length??0)>6&&P(`input`,{className:`settings-input`,type:`search`,value:g,onChange:e=>_(e.target.value),placeholder:e(`settings.model.search`),"aria-label":e(`settings.model.search`)}),m&&!(s&&KN(m))&&P(XN,{message:m}),!f&&!m&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.loading`)]}),f&&xe.length===0&&!m&&P(`p`,{className:`settings-hint`,children:e(ke||!je?`settings.model.noMatch`:`settings.model.noModels`)}),je?V(D.Fragment,{children:[Me.length>0&&P(SN,{title:e(`settings.model.groupDownloaded`),count:Me.length,defaultOpen:!0,forceOpen:ke,children:P(`ul`,{className:`model-list`,children:Me.map(Le)})}),Ne.length>0&&P(SN,{title:e(`settings.model.groupAvailable`),count:Ne.length,defaultOpen:Me.length===0,forceOpen:ke||z||Ne.some(Ts),children:P(`ul`,{className:`model-list`,children:Ne.map(Le)})})]}):P(`ul`,{className:`model-list`,children:Te.map(Le)}),Ce&&Ee.length>0&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>y(!0),children:e(`settings.model.showAll`)}),u===`fireworks`&&v&&!ke&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>y(!1),children:e(`settings.model.showRecommended`)}),De.length>0&&P(SN,{title:e(`settings.model.groupUnavailable`),count:De.length,forceOpen:ke,children:P(`ul`,{className:`model-list`,children:De.map(Le)})})]}),je&&W&&P(SN,{title:e(`settings.custom.title`),children:P(ZN,{onAdded:e=>void _e(e)})}),je&&W&&P(eP,{downloadsSlot:re}),H.remote&&P(aP,{})]})]})}function lP(){let e=T(),t=k(e=>e.sessions),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null),u=(0,X.useCallback)(async()=>{l(null);try{let e=await on();r(e.sessions),a(e.default_mode),k.getState().setDefaultPermissionMode(e.default_mode)}catch(e){l(e instanceof Error?e.message:String(e))}},[]);(0,X.useEffect)(()=>{u()},[u]);let d=(0,X.useCallback)(async e=>{l(null);try{await e(),await u()}catch(e){l(e instanceof Error?e.message:String(e))}},[u]),f=(0,X.useCallback)(async e=>{s(!1),await d(()=>kt(e))},[d]),p=()=>{i===`full_access`?f(`ask`):s(e=>!e)},m=e=>t.find(t=>t.id===e)?.title??e;return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.permissions`)}),P(`p`,{className:`settings-pane-lede`,children:e(`settings.permissions.lede`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,e(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:e(`settings.permissions.perChat`)})]}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.permissions.newChats`),children:[V(`label`,{className:`setting-row`,children:[P(`span`,{className:`settings-label`,children:e(`settings.permissions.fullAccess`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:i===`full_access`,onChange:p,disabled:i===null,"aria-label":e(`settings.permissions.fullAccess`)}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,children:e(i===`full_access`?`settings.permissions.on`:`settings.permissions.off`)}),o&&V(`div`,{className:`settings-warning`,role:`alert`,children:[P(`p`,{children:e(`settings.permissions.warning`)}),V(`div`,{className:`settings-row`,children:[P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void f(`full_access`),children:e(`settings.permissions.turnOn`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>s(!1),children:e(`settings.key.cancel`)})]})]})]}),c&&P(`p`,{className:`settings-error`,role:`alert`,children:c}),n&&n.length===0&&P(`p`,{className:`settings-hint`,children:e(`settings.permissions.none`)}),!!n?.length&&P(SN,{title:e(`settings.permissions.chats`),count:n.length,defaultOpen:!0,children:n.map(t=>V(`section`,{className:`settings-field permission-chat`,"aria-label":m(t.session_id),children:[V(`div`,{className:`settings-row settings-row-between`,children:[P(`bdi`,{className:`settings-label`,children:m(t.session_id)}),t.mode===`full_access`&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>d(async()=>{let e=(await Pt(t.session_id,`ask`)).mode;yE(t.session_id,e)}),children:e(`settings.permissions.turnOff`)})]}),t.grants.length>0&&P(`ul`,{className:`grant-list`,children:t.grants.map(n=>V(`li`,{className:`grant-row`,children:[P(`code`,{children:n.label}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>d(()=>Xt(t.session_id,n.key)),"aria-label":e(`settings.permissions.revokeAria`,{name:n.label}),children:e(`settings.permissions.revoke`)})]},n.key))}),t.grants.length>1&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>d(()=>Xt(t.session_id)),children:e(`settings.permissions.revokeAll`)})]},t.session_id))})]})}var uP={path:`~/.gaia/skills`},dP=[{source:`agent-bundled`,title:`settings.skills.bundled`,note:`settings.skills.bundledNote`},{source:`user`,title:`settings.skills.yours`,note:`settings.skills.yoursNote`,empty:`settings.skills.yoursEmpty`,params:uP},{source:`claude-project`,title:`settings.skills.project`,note:`settings.skills.projectNote`,params:{path:`.claude/skills`}},{source:`claude-import`,title:`settings.skills.import`,note:`settings.skills.importNote`}];function fP({onUseSkill:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)({}),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(``);(0,X.useEffect)(()=>{let e=!1;return ln().then(t=>{e||(r(t.skills),a(t.invalid))}).catch(t=>{e||s(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let u=c.trim().toLowerCase(),d=(n??[]).filter(e=>!u||e.name.toLowerCase().includes(u)||e.description.toLowerCase().includes(u)),f=n?.every(e=>dP.some(t=>t.source===e.source))??!1,p=n=>V(`li`,{className:`skill-row`,children:[V(`div`,{className:`skill-row-text`,children:[V(`span`,{className:`skill-row-name`,children:[n.name,n.version&&V(`span`,{className:`skill-row-meta`,children:[` v`,n.version]}),n.always_on&&V(`span`,{className:`skill-row-meta`,children:[` · `,t(`settings.skills.alwaysOn`)]})]}),P(`span`,{className:`skill-row-desc`,children:P(`bdi`,{children:n.description})})]}),!n.always_on&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>e(n.name),"aria-label":t(`settings.skills.useAria`,{name:n.name}),children:t(`settings.model.use`)})]},n.name);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:t(`settings.section.skills`)}),P(`p`,{className:`settings-pane-lede`,children:t(`settings.skills.lede`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:t(`settings.skills.how`,uP)})]}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o}),!n&&!o&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),n&&n.length>6&&P(`input`,{className:`settings-input`,type:`search`,value:c,onChange:e=>l(e.target.value),placeholder:t(`settings.skills.search`),"aria-label":t(`settings.skills.search`)}),n&&n.length===0&&P(`p`,{className:`settings-hint`,children:t(`settings.skills.none`)}),f?dP.map(e=>{let r=d.filter(t=>t.source===e.source),i=(n??[]).filter(t=>t.source===e.source).length;return r.length===0&&(u||!e.empty)?null:P(SN,{title:t(e.title),count:i,hint:t(e.note,e.params),defaultOpen:e.source===`user`,forceOpen:!!u,children:P(`section`,{"aria-label":t(e.title),children:r.length===0?P(`p`,{className:`settings-hint`,children:e.empty&&t(e.empty,e.params)}):P(`ul`,{className:`skill-list`,children:r.map(p)})})},e.source)}):P(`ul`,{className:`skill-list`,children:d.map(p)}),Object.keys(i).length>0&&V(`div`,{className:`settings-card`,role:`alert`,children:[P(`span`,{className:`settings-label`,children:t(`settings.skills.skipped`)}),P(`ul`,{className:`grant-list`,children:Object.entries(i).map(([e,t])=>V(`li`,{children:[P(`bdi`,{dir:`ltr`,children:P(`code`,{children:e})}),` — `,P(`bdi`,{children:t})]},e))})]})]})}function pP(){let e=T(),t=k(e=>e.setShowMemoryDashboard),n=k(e=>e.closeSettings),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1);(0,X.useEffect)(()=>{pA().then(i).catch(e=>o(e instanceof Error?e.message:String(e)))},[]);let l=(0,X.useCallback)(async()=>{if(r){c(!0),o(null);try{i(await mA({memory_enabled:!r.memory_enabled}))}catch(e){o(e instanceof Error?e.message:String(e))}finally{c(!1)}}},[r]);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.memory`)}),P(`p`,{className:`settings-pane-lede`,children:e(`settings.memory.lede`)}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.section.memory`),children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.memory.remember`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:!!r?.memory_enabled,onChange:()=>void l(),disabled:!r||s,"aria-label":e(`settings.memory.remember`)}),P(`span`,{className:`toggle-track`})]})]}),a&&P(`p`,{className:`settings-error`,role:`alert`,children:a}),V(`div`,{className:`settings-row settings-row-between`,children:[P(`span`,{className:`settings-hint`,children:e(`settings.memory.dashboardHint`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{n(),t(!0)},children:e(`settings.memory.dashboard`)})]})]})]})}function mP(e,t,n){if(!/^\d+$/.test(e.trim()))return!1;let r=Number(e);return r>=t&&r<=n}function hP(e){return e<1048576?`${Math.ceil(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}function gP(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1);(0,X.useEffect)(()=>{hn().then(e=>{n(e),i(String(e.retention_days)),o(String(e.max_mb))},t=>c({ok:!1,text:e(`settings.undo.readFailed`,{reason:t instanceof Error?t.message:String(t)})}))},[e]);let[d,f]=(0,X.useState)({days:!1,mb:!1}),p=!mP(r,1,365)||d.days,m=!mP(a,10,1e5)||d.mb,h=t!==null&&(r!==String(t.retention_days)||a!==String(t.max_mb)),g=async()=>{if(!(p||m)){u(!0),c(null);try{let t=await fn(Number(r),Number(a));n(t),c({ok:!0,text:e(`settings.undo.saved`)})}catch(t){let n=t instanceof yn&&t.httpStatus===422?t.fields:[],r=n.includes(`retention_days`),i=n.includes(`max_mb`);r||i?(f({days:r,mb:i}),c({ok:!1,text:e(`settings.undo.fix`)})):c({ok:!1,text:t instanceof Error?t.message:String(t)})}finally{u(!1)}}};return V(`div`,{className:`settings-field`,"aria-label":e(`settings.privacy.undo`),children:[P(`span`,{className:`settings-label`,children:e(`settings.privacy.undo`)}),P(`p`,{className:`settings-hint`,children:e(`settings.undo.hint`)}),t&&V(D.Fragment,{children:[V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`undo-days`,children:e(`settings.undo.days`)}),P(`input`,{id:`undo-days`,type:`number`,className:`model-input undo-history-input`,min:1,max:365,value:r,"aria-invalid":p,"aria-describedby":p?`undo-days-error`:void 0,onChange:e=>{i(e.target.value),f(e=>({...e,days:!1}))}})]}),p&&P(`p`,{id:`undo-days-error`,className:`settings-error`,children:e(`settings.undo.daysError`)}),V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`undo-mb`,children:e(`settings.undo.mb`)}),P(`input`,{id:`undo-mb`,type:`number`,className:`model-input undo-history-input`,min:10,max:1e5,value:a,"aria-invalid":m,"aria-describedby":m?`undo-mb-error`:void 0,onChange:e=>{o(e.target.value),f(e=>({...e,mb:!1}))}})]}),m&&P(`p`,{id:`undo-mb-error`,className:`settings-error`,children:e(`settings.undo.mbError`)}),V(`div`,{className:`setting-row setting-row-path`,children:[P(`span`,{children:e(`settings.undo.inUse`)}),V(`span`,{children:[e.plural(`settings.undo.used`,t.turns,{size:hP(t.used_bytes)}),` `,P(`bdi`,{dir:`ltr`,children:P(`code`,{className:`setting-path`,children:t.path})})]})]}),P(`button`,{type:`button`,className:`btn-model-save`,onClick:()=>void g(),disabled:!h||l||p||m,children:e(l?`settings.models.applying`:`settings.advanced.save`)})]}),s&&P(`p`,{className:s.ok?`settings-ok`:`settings-error`,role:s.ok?`status`:`alert`,children:s.text})]})}var _P={root:`settings-report`,button:`btn-secondary`,hint:`settings-hint`,error:`settings-error`};function vP(){let e=T(),t=k(e=>e.sessions),n=k(e=>e.removeSession),r=hs(),i=k(e=>e.systemStatus?.data_dir),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),p=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]),(0,X.useEffect)(()=>{let e=!0;return qe().then(t=>{e&&u(t.network_policy===`local_ai_only`)}).catch(t=>{e&&c({ok:!1,text:t instanceof Error?t.message:String(t)})}),()=>{e=!1}},[]);let m=(0,X.useCallback)(async()=>{if(l===null||d)return;let t=l,n=!t;u(n),f(!0),c(null);try{let t=await Me({network_policy:n?`local_ai_only`:`cloud_allowed`});u(t.network_policy===`local_ai_only`);let r=t.policy_notices??[],i=r.some(e=>e.severity===`warning`),a=r.length?r.map(t=>t.code===`users_server_keeps_keys`?e(`settings.privacy.usersServerKeepsKeys`,{url:t.url??``}):t.code===`runtime_keys_not_dropped`?e(`settings.privacy.runtimeKeysNotDropped`,{reason:t.reason??``}):t.code===`saved_models_not_checked`?e(`settings.privacy.savedModelsNotChecked`,{reason:t.reason??``}):e(`settings.privacy.policyNoticeUnknown`)).join(` `):e(n?`settings.privacy.localOnlyOn`:`settings.privacy.localOnlyOff`);c({ok:!i,text:a})}catch(e){u(t),c({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{f(!1)}},[l,d,e]),h=(0,X.useCallback)(async()=>{if(!a){o(!0),p.current=setTimeout(()=>o(!1),4e3);return}o(!1);let r=[];for(let e of t)try{await de(e.id),n(e.id)}catch(t){r.push(`${e.title}: ${t instanceof Error?t.message:t}`)}c(r.length?{ok:!1,text:e(`settings.privacy.deleteFailed`,{n:r.length,reason:r.join(`; `)})}:{ok:!0,text:e(`settings.privacy.deleted`)})},[a,n,t,e]);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.privacy`)}),P(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.localOnlyTitle`),children:V(`div`,{className:`settings-row settings-row-between`,children:[V(`div`,{children:[P(`strong`,{children:e(`settings.privacy.localOnlyTitle`)}),P(`p`,{className:`settings-hint`,children:e(`settings.privacy.localOnlyHint`)})]}),P(`button`,{type:`button`,role:`switch`,"aria-checked":l===!0,"aria-label":e(`settings.privacy.localOnlyTitle`),className:l?`is-active`:``,onClick:()=>void m(),disabled:l===null||d,children:e(l?`settings.privacy.localOnlyOnLabel`:`settings.privacy.localOnlyOffLabel`)})]})}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.whereTitle`),children:[P(`p`,{className:`settings-note`,children:e(`settings.privacy.stays`)}),P(`p`,{className:r?.remote?`settings-note`:`settings-hint`,children:r?.remote?e(`settings.privacy.remote`,{name:r.label}):e(r?`settings.privacy.local`:`settings.privacy.unknown`)}),i&&V(`div`,{className:`setting-row setting-row-path`,children:[P(`span`,{children:e(`settings.privacy.dataFolder`)}),P(`bdi`,{dir:`ltr`,className:`setting-path`,children:i})]})]}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.reportTitle`),children:[P(`p`,{className:`settings-note`,children:e(`settings.privacy.reportNote`)}),P(rC,{classes:_P})]}),P(SN,{title:e(`settings.privacy.undo`),children:P(gP,{})}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.deleteTitle`),children:[P(`p`,{className:`danger-warning`,children:t.length===0?e(`settings.privacy.nothingToDelete`):e(`settings.privacy.deleteWarning`)}),P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void h(),disabled:t.length===0,children:e(a?`settings.privacy.deleteConfirm`:`settings.privacy.delete`)})]}),s&&P(`p`,{className:s.ok?`settings-ok`:`settings-error`,role:s.ok?`status`:`alert`,children:s.text})]})}var yP=[{id:`needs_approval`,label:`settings.alerts.approval`},{id:`question`,label:`settings.alerts.question`},{id:`finished`,label:`settings.alerts.finished`}],bP=[{value:`banner`,label:`settings.alerts.banner`},{value:`badge`,label:`settings.alerts.badge`},{value:`off`,label:`settings.alerts.off`}],xP=[0,10,20,30,50];function SP(){return typeof Notification>`u`?`unsupported`:Notification.permission}function CP(){let e=T(),t=lc(),n=!!window.gaiaAPI,[r,i]=(0,X.useState)(SP),a=Object.values(t.modes).includes(`banner`);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.notifications`)}),P(`p`,{className:`settings-pane-lede`,children:e(`settings.alerts.lede`)}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.alerts.when`),children:[yP.map(n=>V(`div`,{className:`setting-row`,children:[P(`span`,{id:`alert-${n.id}`,children:e(n.label)}),P(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`alert-${n.id}`,children:bP.map(r=>P(`button`,{type:`button`,role:`radio`,"aria-checked":t.modes[n.id]===r.value,className:t.modes[n.id]===r.value?`is-active`:``,onClick:()=>t.setMode(n.id,r.value),children:e(r.label)},r.value))})]},n.id)),!n&&a&&r!==`granted`&&(r==="default"?P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{Notification.requestPermission().then(i).catch(e=>{console.error(`[alerts] Notification permission request failed`,e),i(SP())})},children:e(`settings.alerts.allow`)}):P(`p`,{className:`settings-error`,role:`alert`,children:e(r===`unsupported`?`settings.alerts.unsupported`:`settings.alerts.blocked`)})),V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.alerts.sound`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.sound,onChange:()=>t.update({sound:!t.sound}),"aria-label":e(`settings.alerts.sound`)}),P(`span`,{className:`toggle-track`})]})]}),n&&V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.alerts.flash`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.flash,onChange:()=>t.update({flash:!t.flash}),"aria-label":e(`settings.alerts.flash`)}),P(`span`,{className:`toggle-track`})]})]})]}),V(`section`,{className:`settings-card`,"aria-labelledby":`keep-awake-title`,children:[P(`h3`,{className:`settings-label`,id:`keep-awake-title`,children:e(`settings.alerts.keepAwakeTitle`)}),n?V(D.Fragment,{children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`settings.alerts.keepAwake`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.keepAwake,onChange:()=>t.update({keepAwake:!t.keepAwake}),"aria-label":e(`settings.alerts.keepAwake`)}),P(`span`,{className:`toggle-track`})]})]}),V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`battery-floor`,children:e(`settings.alerts.battery`)}),P(`select`,{id:`battery-floor`,className:`settings-input settings-select-compact`,value:t.batteryFloor,disabled:!t.keepAwake,onChange:e=>t.update({batteryFloor:Number(e.target.value)}),children:xP.map(t=>P(`option`,{value:t,children:t===0?e.bare(`settings.alerts.never`):`${t}%`},t))})]}),P(`p`,{className:`settings-hint`,children:e(`settings.alerts.screen`)})]}):P(`p`,{className:`settings-hint`,children:e(`settings.alerts.desktopOnly`)})]})]})}var wP=[50,75,100,125,150,175,200],TP=[{accent:`american`,gender:`female`},{accent:`american`,gender:`male`},{accent:`british`,gender:`female`},{accent:`british`,gender:`male`}],EP=`settings:preview`,DP=`Hello, I'm GAIA. This is how I'll read my replies to you.`;function OP(e){return e instanceof yn?e.detail||e.message:String(e)}function kP(){let e=T(),t=ES(e=>e.settings),n=ES(e=>e.setSettings),r=ES(e=>e.read),i=ES(e=>e.stop),a=ES(e=>e.messageId===EP),o=ES(e=>e.messageId===EP&&e.status===`loading`),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1);(0,X.useEffect)(()=>{pS().then(n).catch(e=>c(OP(e)))},[n]);let p=e=>{f(!0),u(null),ES.getState().messageId===EP&&i(),mS(e).then(n).catch(e=>u(OP(e))).finally(()=>f(!1))};return s?V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.voice`)}),P(`p`,{className:`settings-error`,role:`alert`,children:e(`readAloud.settings.loadFailed`,{reason:s})})]}):t?V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.voice`)}),P(`p`,{className:`settings-pane-lede`,children:e(`readAloud.settings.lede`)}),V(`div`,{className:`settings-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`read-aloud-voice`,children:e(`readAloud.settings.voice`)}),V(`div`,{className:`read-aloud-voice-row`,children:[P(`select`,{id:`read-aloud-voice`,className:`settings-input`,value:t.voice,disabled:d,onChange:e=>p({voice:e.target.value}),children:TP.map(n=>P(`optgroup`,{label:e(`readAloud.group.${n.accent}.${n.gender}`),children:t.voices.filter(e=>e.accent===n.accent&&e.gender===n.gender).map(e=>P(`option`,{value:e.id,lang:`en`,children:e.name},e.id))},`${n.accent}-${n.gender}`))}),V(`button`,{type:`button`,className:`btn-secondary`,"aria-pressed":a,disabled:d,onClick:()=>a?i():void r(EP,DP),children:[o?P(q,{size:13,className:`spin`}):P(a?ao:_o,{size:13}),e(a?`readAloud.stop`:`readAloud.settings.preview`)]})]}),P(`span`,{className:`settings-hint`,children:e(`readAloud.settings.englishOnly`)}),P(kS,{messageId:EP})]}),V(`div`,{className:`settings-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`read-aloud-speed`,children:e(`readAloud.settings.speed`)}),P(`select`,{id:`read-aloud-speed`,className:`settings-input`,value:t.speed,disabled:d,onChange:e=>p({speed:Number(e.target.value)}),children:(wP.includes(t.speed)?wP:[...wP,t.speed].sort((e,t)=>e-t)).map(t=>P(`option`,{value:t,children:t===100?e.bare(`readAloud.settings.normalSpeed`):`${(t/100).toLocaleString(e.locale)}×`},t))})]}),V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`readAloud.settings.auto`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.auto,disabled:d,onChange:()=>p({auto:!t.auto}),"aria-label":e(`readAloud.settings.auto`)}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,children:e(`readAloud.settings.shared`)}),l&&P(`p`,{className:`settings-error`,role:`alert`,children:e(`readAloud.settings.saveFailed`,{reason:l})})]}):V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.loading`)]})}function AP(){let e=T(),t=k(e=>e.openSettings),n=k(e=>e.closeSettings),r=k(e=>e.runSetupAgain),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1);(0,X.useEffect)(()=>{Ce().then(a).catch(e=>l(e instanceof Error?e.message:String(e))),ot().then(s).catch(e=>l(e instanceof Error?e.message:String(e)))},[]);let f=i?.catalog?.find(e=>e.id===i.chat_model.id),p=(i?.catalog??[]).filter(e=>e.downloaded),m=p.reduce((e,t)=>e+(t.full_size_gb??0),0),h=[o?.gpu_name,o?.npu_detected?e(`setup.checks.npu`):null].filter(Boolean).join(` · `),g=[{title:e(`settings.setup.where`),rows:[{label:e(`settings.setup.chatRuns`),value:f?.name??null,section:`model`},{label:e(`settings.setup.cloudKeys`),value:null,section:`model`}]},{title:e(`setup.pc.step`),rows:[{label:e(`settings.setup.detected`),value:[h,o?.ram_gb==null?null:`${o.ram_gb} GB`].filter(Boolean).join(` · `)||null,section:`advanced`},{label:e(`settings.setup.server`),value:i?.lemonade.mode===`external`?e(`settings.setup.serverYours`):e(`settings.setup.serverOwn`),section:`advanced`},{label:e(`setup.gpu.title`),value:null,section:`model`}]},{title:e(`setup.models.step`),rows:[{label:e(`settings.setup.models`),value:i?.catalog?e(`settings.setup.modelsValue`,{n:String(p.length),size:$(m)}):null,section:`model`},{label:e(`settings.setup.context`),value:null,section:`model`}]},{title:e(`settings.setup.after`),rows:[{label:e(`settings.section.connectors`),value:null,section:`connectors`},{label:e(`settings.section.memory`),value:null,section:`memory`},{label:e(`settings.language`),value:null,section:`general`},{label:e(`settings.setup.signIn`),value:null,section:`general`}]}];return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.setup`)}),P(`p`,{className:`settings-hint`,children:e(`settings.setup.lede`)}),V(`div`,{className:`settings-setup-status`,children:[V(`span`,{children:[P(`strong`,{children:e(`settings.setup.ready`)}),f&&V(`span`,{className:`settings-hint`,children:[` `,P(`bdi`,{children:e(`settings.setup.running`,{name:f.name})})]})]}),P(`button`,{type:`button`,className:`btn-secondary`,"data-testid":`setup-run-again`,onClick:()=>d(!0),children:e(`settings.setup.runAgain`)})]}),c&&P(`p`,{className:`setup-error`,role:`alert`,children:c}),g.map(e=>V(`section`,{className:`settings-setup-group`,"aria-label":e.title,children:[P(`h3`,{className:`settings-label`,children:e.title}),e.rows.map(e=>V(`button`,{type:`button`,className:`settings-setup-row`,onClick:()=>t(e.section),children:[V(`span`,{children:[P(`span`,{className:`settings-setup-row-label`,children:e.label}),e.value&&P(`bdi`,{className:`settings-hint settings-setup-row-value`,children:e.value})]}),P(br,{size:14,className:`settings-setup-chevron`,"aria-hidden":`true`})]},e.label))]},e.title)),u&&P(Kj,{title:e(`settings.setup.confirmTitle`),confirmLabel:e(`settings.setup.confirmYes`),cancelLabel:e(`setup.again.notNow`),onConfirm:()=>{d(!1),n(),r(!0)},onCancel:()=>d(!1),children:P(`p`,{children:e(`settings.setup.confirmBody`)})})]})}var jP=`modulepreload`,MP=function(e,t){return new URL(e,t).href},NP={},PP=function(e){return e.pathname.endsWith(`.css`)},FP=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},IP=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=MP(t,n);let r=s(t),i=PP(r);return FP(NP,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:jP,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},LP=(0,X.lazy)(()=>IP(()=>import(`./ConnectorsPane-BxnbIY7k.js`).then(e=>({default:e.ConnectorsPane})),__vite__mapDeps([0,1,2,3,4]),import.meta.url)),RP=(0,X.lazy)(()=>IP(()=>import(`./AdvancedSettings-w9D1AXlP.js`).then(e=>({default:e.AdvancedSettings})),__vite__mapDeps([5,1,2,3]),import.meta.url)),zP=[`general`,`setup`,`model`,`permissions`,`skills`,`connectors`,`memory`,`notifications`,`voice`,`privacy`,`advanced`];function BP({onUseSkill:e}){let t=T(),n=k(e=>e.settingsSection),r=k(e=>e.openSettings),i=k(e=>e.closeSettings),a=(0,X.useRef)(null),o=n!==null;if(Io(o,i),sS(a,o),xN(a,o,()=>a.current?.querySelector(`.settings-nav-item.is-active`)),!n)return null;let s=(()=>{switch(n){case`general`:return P(GN,{});case`setup`:return P(AP,{});case`model`:return P(cP,{});case`permissions`:return P(lP,{});case`skills`:return P(fP,{onUseSkill:t=>{i(),e(t)}});case`connectors`:return P(LP,{});case`memory`:return P(pP,{});case`notifications`:return P(CP,{});case`voice`:return P(kP,{});case`privacy`:return P(vP,{});case`advanced`:return P(RP,{})}})();return P(`div`,{className:`settings-overlay`,onMouseDown:e=>{e.target===e.currentTarget&&i()},children:V(`div`,{ref:a,className:`settings-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`settings.title`),children:[V(`nav`,{className:`settings-nav`,"aria-label":t(`settings.sections`),children:[P(`h1`,{className:`settings-nav-title`,children:t(`settings.title`)}),zP.map(e=>P(`button`,{type:`button`,"data-section":e,className:`settings-nav-item${n===e?` is-active`:``}`,"aria-current":n===e?`page`:void 0,onClick:t=>{t.currentTarget.focus(),r(e)},children:t(`settings.section.${e}`)},e))]}),V(`div`,{className:`settings-body`,children:[P(`button`,{type:`button`,className:`settings-close`,onClick:i,"aria-label":t(`settings.close`),children:P(Y,{size:18})}),P(`div`,{className:`settings-scroll`,children:P(X.Suspense,{fallback:V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),children:s})})]})]})})}var VP=p((e,t)=>({lifecycle:null,restartError:null,apply:n=>{n.apiBase&&B(n.apiBase),e({lifecycle:n,restartError:n.status===`running`?null:t().restartError})},restart:async()=>{let n=window.gaiaAPI?.backend;if(!n)throw Error(`Restart GAIA needs the desktop app.`);e({restartError:null});try{t().apply(await n.restart())}catch(t){d.system.error(`Restart GAIA failed`,t),e({restartError:t instanceof Error?t.message:String(t)})}}}));function HP(e){let t=window.gaiaAPI?.backend;if(!t)return()=>{};let n=t=>{let n=VP.getState().lifecycle?.status;VP.getState().apply(t),t.status===`running`&&n&&n!==`running`&&e()},r=t.onState(n);return t.getState().then(n).catch(e=>d.system.error(`Could not read the backend state from the desktop app`,e)),r}function UP(e,t){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(null),c=(0,X.useRef)(null),l=(0,X.useRef)(null),u=(0,X.useRef)(null),f=(0,X.useCallback)(()=>{c.current&&=(clearTimeout(c.current),null),l.current&&=(clearTimeout(l.current),null),u.current&&=(clearInterval(u.current),null)},[]);(0,X.useEffect)(()=>f,[f]);let p=(0,X.useCallback)((e,t)=>{u.current&&clearInterval(u.current),u.current=setInterval(async()=>{try{let n=await Nt();t===`load`?n.model_loaded?.toLowerCase()===e.toLowerCase()&&(r(!1),c.current&&=(clearTimeout(c.current),null),u.current&&=(clearInterval(u.current),null)):(n.model_downloaded===!0||n.model_loaded?.toLowerCase()===e.toLowerCase())&&(a(!1),l.current&&=(clearTimeout(l.current),null),u.current&&=(clearInterval(u.current),null))}catch{}},Lc)},[]),m=e??`Gemma-4-E4B-it-GGUF`;return(0,X.useEffect)(()=>s(null),[m]),{isLoadingModel:n,isDownloadingModel:i,downloadError:o,loadModel:(0,X.useCallback)(async(e,t)=>{let n=e??m,i=t??32768;r(!0);try{if(!await zt(n,i)){r(!1);return}d.system.info(`Load model triggered: ${n} (ctx=${i})`),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>r(!1),Fc),p(n,`load`)}catch(e){d.system.error(`Failed to trigger model load`,e),r(!1)}},[m,t,p]),downloadModel:(0,X.useCallback)(async(e=!1,t,n=!1)=>{let r=t??m;a(!0),s(null);try{await fe(r,e,n),d.system.info(`Download model triggered: ${r} (force=${e})`),l.current&&clearTimeout(l.current),l.current=setTimeout(()=>a(!1),Ic),p(r,`download`)}catch(e){d.system.error(`Failed to trigger model download`,e),s(e instanceof Error?e.message:String(e)),a(!1)}},[m,p])}}function WP({onRetry:e,label:t,busyLabel:n=`Checking…`}){let[r,i]=(0,X.useState)(!1);return P(`button`,{className:`connection-banner__retry`,onClick:()=>{i(!0),Promise.resolve(e()).finally(()=>i(!1))},disabled:r,children:r?n:t})}function GP(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function KP({lifecycle:e}){let t=T(),n=VP(e=>e.restart),r=VP(e=>e.restartError),i=e.status===`restarting`,[a,o]=(0,X.useState)(()=>Date.now());if((0,X.useEffect)(()=>{if(!i)return;o(Date.now());let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[i]),i){let n=e.since?Math.max(0,Math.floor((a-e.since)/1e3)):0;return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t(`banner.restarting`),` `,P(`bdi`,{dir:`ltr`,className:`connection-banner__timer`,children:GP(n)}),` `,P(`span`,{className:`connection-banner__hint`,children:t(`banner.restartingHint`)})]})]})}return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t(`banner.restartStopped`),` `,P(`span`,{className:`connection-banner__hint`,children:r?t(`banner.restartFailed`,{error:r}):t(`banner.restartStoppedHint`)})]}),P(WP,{onRetry:n,label:t(`banner.restartButton`),busyLabel:t(`banner.restartingShort`)})]})}function qP({onRetry:e,backendSlow:t=!1,backendError:n=null}){let r=T(),{backendConnected:i,systemStatus:a,currentSessionId:o,messages:s}=k(),c=VP(e=>e.lifecycle),[l,u]=(0,X.useState)(!1),d=!!o&&s.length>0,f=a?.default_model_name??`Gemma-4-E4B-it-GGUF`,{isDownloadingModel:p,downloadError:m,downloadModel:h}=UP(f),g=cs(e=>e.pickLoad),_=cs(e=>e.retryPickLoad),v=cs(e=>e.dismissPickLoad);ls();let y=(0,X.useRef)(a?.lemonade_running),b=(0,X.useRef)(a?.model_downloaded),x=(0,X.useRef)(a?.context_size_sufficient),S=(0,X.useRef)(a?.expected_model_loaded);if((0,X.useEffect)(()=>{if(d)return;let e=a?.lemonade_running,t=a?.model_downloaded,n=a?.context_size_sufficient,r=a?.expected_model_loaded,i=!1;y.current!==e&&(y.current=e,e===!1&&(i=!0)),b.current!==t&&(b.current=t,t===!1&&(i=!0)),x.current!==n&&(x.current=n,n===!1&&(i=!0)),S.current!==r&&(S.current=r,r===!1&&(i=!0)),i&&u(!1)},[a,d]),c&&c.status!==`running`)return P(KP,{lifecycle:c});let C=a?.download_progress??null,w=C?.model_name||f;if(p||C?.state===`downloading`||C?.state===`starting`||C?.state===`error`){let e=C?.total_bytes?`${(C.total_bytes/1e9).toFixed(1)} GB`:`large download`,t=C?.state===`error`;return V(`div`,{className:`connection-banner ${t?`connection-banner--error`:`connection-banner--warning`}`,role:t?`alert`:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(t?J:Jr,{size:16})}),P(`div`,{className:`connection-banner__text`,dir:`auto`,children:t?V(D.Fragment,{children:[`Download of `,P(`strong`,{children:w}),` failed.`,` `,(m??C?.message)&&P(`span`,{className:`connection-banner__hint`,children:m??C?.message})]}):V(D.Fragment,{children:[`Downloading `,P(`strong`,{children:w}),` (`,e,`).`,C?.state===`downloading`&&C.file&&V(D.Fragment,{children:[` `,V(`span`,{className:`connection-banner__hint`,children:[`File `,C.file_index,` / `,C.total_files,`: `,P(`code`,{children:C.file})]})]})]})}),t?P(`button`,{className:`connection-banner__retry`,onClick:()=>h(!1,w,!a?.model_loaded),children:`Retry`}):P(`span`,{className:`connection-banner__loading connection-banner__progress`,children:C&&C.state===`downloading`&&C.total_bytes>0?V(D.Fragment,{children:[P(`span`,{className:`connection-banner__progress-bar`,role:`progressbar`,"aria-valuenow":C.percent,"aria-valuemin":0,"aria-valuemax":100,"aria-label":`Download progress`,children:P(`span`,{className:`connection-banner__progress-fill`,style:{width:`${C.percent}%`}})}),V(`span`,{className:`connection-banner__progress-label`,children:[C.percent,`% ·`,` `,(C.downloaded_bytes/1e9).toFixed(2),` /`,` `,(C.total_bytes/1e9).toFixed(2),` GB`]})]}):V(D.Fragment,{children:[P(q,{size:13,className:`connection-banner__spinner`}),C?.state===`starting`?C.message??`Starting download…`:`Downloading…`]})}),t&&P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}if(g){let e=ds(g.model);return g.error?V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.pickLoad.failed`,{model:e}),` `,P(`span`,{className:`connection-banner__hint`,dir:`auto`,children:g.error.key?r(g.error.key,{reason:g.error.reason}):g.error.reason})]}),P(WP,{onRetry:_,label:r(`banner.pickLoad.retry`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:v,"aria-label":r(`banner.dismiss`),children:P(Y,{size:14})})]}):V(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.pickLoad.loading`,{model:e}),` `,P(`bdi`,{dir:`ltr`,children:r(`banner.pickLoad.seconds`,{s:g.seconds})}),` `,P(`span`,{className:`connection-banner__hint`,children:r(`banner.pickLoad.canType`)})]})]})}if(Hw(a)&&!t&&!n){let e=a?.init_tasks?.find(e=>e.status===`running`)?.name||`Preparing AI system`;return V(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[e,V(`span`,{className:`thinking-dots`,children:[P(`span`,{children:`.`}),P(`span`,{children:`.`}),P(`span`,{children:`.`})]})]})]})}if(l||d)return null;if(!i)return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(yo,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.unreachable`),` `,P(`span`,{className:`connection-banner__hint`,children:r(`banner.unreachableHint`)})]}),e&&P(WP,{onRetry:e,label:`Retry`})]});if(n)return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA's backend answered with an error (`,n,`).`,` `,P(`span`,{className:`connection-banner__hint`,children:`It may be overloaded. GAIA keeps checking; if it lasts, restart GAIA.`})]}),e&&P(WP,{onRetry:e,label:`Check again`})]});if(t)return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA is slow to answer.`,` `,P(`span`,{className:`connection-banner__hint`,children:`It may be busy with another chat or app. GAIA keeps checking.`})]}),e&&P(WP,{onRetry:e,label:`Check again`})]});if(a?.config_error)return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA settings could not be loaded.`,` `,P(`span`,{className:`connection-banner__hint`,children:a.config_error})]}),e&&P(WP,{onRetry:e,label:`Check again`})]});if(a&&!a.lemonade_running){let t=Uw(a)===`unresponsive`,n=JN(a);return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t?`The model server is not answering (${a.lemonade_error}). It may be busy with another app or loading a model.`:r(`banner.serverStopped`),` `,n?P(`span`,{className:`connection-banner__hint`,children:r(`banner.finishSetup`)}):a.start_command?V(`span`,{className:`connection-banner__hint`,children:[t?`If it stays this way, restart it: `:`To start it by hand, run `,P(`code`,{children:a.start_command})]}):a.start_instruction&&P(`span`,{className:`connection-banner__hint`,children:a.start_instruction})]}),n&&P(YN,{className:`connection-banner__retry`}),e&&P(WP,{onRetry:e,label:r(`settings.key.checkAgain`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}if(a&&a.lemonade_running&&a.model_loaded&&a.context_size_sufficient===!1){let t=a.model_context_size??0;return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(Ji,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`LLM context window is too small (`,t.toLocaleString(),` tokens;`,` `,Nc.toLocaleString(),` required).`,` `,P(`span`,{className:`connection-banner__hint`,children:`Reload it with a larger context in Settings → Advanced.`})]}),e&&P(WP,{onRetry:e,label:`Check again`}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}return null}function JP(){let e=jN(),t=T(),[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(null),o=(0,X.useCallback)(e=>{let n=kN();n&&(a(null),n[e]().catch(n=>{d.system.error(`Update ${e} failed`,n),a(FN(n,t))}))},[t]);if(n)return null;let s=e.installFailed?t(`update.chip.installFailedDetail`,e.installFailed):null,c=e.status===`downloading`||e.status===`downloaded`;if(e.startFailed&&e.previousVersion&&!c)return V(`div`,{className:`update-chip update-chip--error`,role:`status`,children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,title:i??void 0,children:t(i?`update.chip.updateFailed`:`update.chip.startFailed`)}),P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`revertUpdate`),children:t(`update.chip.goBack`,{version:e.previousVersion})}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]});let l=e.status===`available`||e.status===`downloaded`;if(s&&!l)return V(`div`,{className:`update-chip update-chip--error`,role:`status`,title:s??void 0,children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:t(`update.chip.installFailed`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]});if(e.status===`idle`||e.status===`checking`||e.status===`disabled`||e.status===`no-channel`)return null;if(e.status===`downloading`){let n=Math.max(0,Math.min(100,e.progress));return V(`div`,{className:`update-chip update-chip--downloading`,role:`status`,"aria-live":`polite`,title:t(`update.chip.downloadingTitle`,{version:e.version??``}),children:[P(Jr,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:e.preparing?t(`update.chip.preparing`):t(`update.chip.downloading`,{pct:n})})]})}return e.status===`available`?V(`div`,{className:`update-chip update-chip--available`,role:`status`,title:i||s||e.releaseNotes||t(`update.chip.availableTitle`),children:[P(Jr,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:i?t(`update.chip.updateFailed`):s?t(`update.chip.installFailed`):t(`update.chip.available`,{version:e.version??``})}),!e.pinnedVersion&&P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`downloadUpdate`),children:t(`update.chip.updateNow`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismiss`),children:P(Y,{size:11})})]}):e.status===`downloaded`?V(`div`,{className:`update-chip update-chip--ready`,role:`status`,"aria-live":`polite`,children:[P(Fa,{size:13,className:`update-chip__icon`}),P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`restart`),title:i||s||t(`update.chip.restartTitle`),children:t(i?`update.chip.restartFailed`:s?`update.chip.installFailedRetry`:`update.chip.ready`)})]}):e.status===`error`?V(`div`,{className:`update-chip update-chip--error`,role:`status`,title:e.error||t(`update.chip.checkFailed`),children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:t(`update.chip.checkFailed`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]}):null}var YP={permission_request:{icon:P(Ga,{size:16}),colorClass:`notif-type-permission`},policy_alert:{icon:P(Ga,{size:16}),colorClass:`notif-type-policy`},security_alert:{icon:P(J,{size:16}),colorClass:`notif-type-security`},status_change:{icon:P(Er,{size:16}),colorClass:`notif-type-status`},info:{icon:P(Hi,{size:16}),colorClass:`notif-type-info`},error:{icon:P(wr,{size:16}),colorClass:`notif-type-error`}};function XP(e,t){let n=Date.now()-e,r=Math.floor(n/1e3);if(r<60)return t(`time.justNow`);let i=Math.floor(r/60);if(i<60)return t(`time.minutesAgo`,{n:i});let a=Math.floor(i/60);if(a<24)return t(`time.hoursAgo`,{n:a});let o=Math.floor(a/24);return o<7?t(`time.daysAgo`,{n:o}):new Date(e).toLocaleDateString(te(t),{month:`short`,day:`numeric`})}function ZP({onClose:e}){let t=T(),n=Qs(ko(ec)),r=Qs($s),i=Qs(e=>e.markRead),a=Qs(e=>e.markAllRead),o=Qs(e=>e.clearAll),s=Qs(e=>e.dismiss),c=Qs(e=>e.respondToPermission),l=Qs(e=>e.typeFilter),u=Qs(e=>e.setTypeFilter),d=(0,X.useCallback)(e=>{i(e)},[i]),f=(0,X.useCallback)(e=>{c(e.id,`allow`).catch(e=>console.error(`[NotificationCenter] allow failed:`,e))},[c]),p=(0,X.useCallback)(e=>{c(e.id,`deny`).catch(e=>console.error(`[NotificationCenter] deny failed:`,e))},[c]);Io(!0,e);let m=[{key:null,label:t(`notifications.filter.all`)},{key:`permission_request`,label:t(`notifications.filter.permissions`)},{key:`policy_alert`,label:t(`notifications.filter.policy`)},{key:`error`,label:t(`notifications.filter.errors`)},{key:`security_alert`,label:t(`notifications.filter.security`)},{key:`status_change`,label:t(`notifications.filter.status`)},{key:`info`,label:t(`notifications.filter.info`)}];return V(`div`,{className:`notification-center`,role:`dialog`,"aria-label":t(`notifications.dialogAria`),children:[V(`div`,{className:`notification-center-header`,children:[V(`div`,{className:`notification-center-title-row`,children:[P(`h2`,{className:`notification-center-title`,children:t(`notifications.title`)}),r>0&&P(`span`,{className:`notification-center-badge`,children:r})]}),P(`button`,{className:`btn-icon notification-center-close`,onClick:e,"aria-label":t(`notifications.close`),children:P(Y,{size:18})})]}),P(`div`,{className:`notification-filter-bar`,role:`tablist`,"aria-label":t(`notifications.filterAria`),children:m.map(e=>P(`button`,{role:`tab`,"aria-selected":l===e.key,className:`notification-filter-tab ${l===e.key?`active`:``}`,onClick:()=>u(e.key),children:e.label},e.key??`all`))}),P(`div`,{className:`notification-list`,children:n.length===0?V(`div`,{className:`notification-empty`,children:[P(er,{size:40,strokeWidth:1.2}),P(`span`,{children:t(`notifications.empty`)})]}):n.map(e=>{let n=YP[e.type],r=e.type===`permission_request`&&e.tool?Ks(e,t,iy):null;return V(`div`,{className:`notification-item ${e.read?``:`unread`} ${n.colorClass}`,id:e.type===`policy_alert`&&e.receiptId?`policy-receipt-${encodeURIComponent(e.receiptId)}`:void 0,onClick:()=>d(e.id),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&d(e.id)},children:[!e.read&&P(`span`,{className:`notification-unread-dot`}),P(`span`,{className:`notification-icon`,children:n.icon}),V(`div`,{className:`notification-content`,children:[V(`div`,{className:`notification-content-header`,children:[P(`span`,{className:`notification-agent`,dir:`auto`,children:e.agentName}),P(`span`,{className:`notification-time`,children:XP(e.timestamp,t)})]}),r?V(D.Fragment,{children:[P(`span`,{className:`notification-title`,children:P(sy,{text:r.heading})}),P(`span`,{className:`notification-message`,children:P(sy,{text:r.question})})]}):V(D.Fragment,{children:[e.title&&P(`span`,{className:`notification-title`,children:e.title}),P(`span`,{className:`notification-message`,children:e.message})]}),e.type===`permission_request`&&e.tool&&e.tool!==`allow_path_access`&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.tool`),`: `,P(`code`,{dir:`ltr`,children:e.tool})]}),e.type===`policy_alert`&&V(`div`,{className:`notification-policy-details`,children:[e.tool&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.tool`),`: `,P(`code`,{dir:`ltr`,children:e.tool})]}),e.reason&&V(`span`,{className:`notification-policy-reason`,children:[t(`notifications.reason`),`: `,e.reason]}),e.ruleIds&&e.ruleIds.length>0&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.rules`),`: `,P(`code`,{dir:`ltr`,children:e.ruleIds.join(`, `)})]}),e.policyVersion&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.policy`),`: `,P(`code`,{dir:`ltr`,children:e.policyVersion})]}),V(`span`,{className:`notification-tool`,children:[t(`activity.policy.receipt`),`:`,` `,e.receiptId?P(`code`,{dir:`ltr`,children:e.receiptId}):P(`em`,{children:t(`activity.policy.receiptUnavailable`)})]})]}),e.type===`permission_request`&&!e.response&&V(`div`,{className:`notification-actions`,children:[V(`button`,{className:`notification-action-btn notification-action-allow`,onClick:t=>{t.stopPropagation(),f(e)},children:[P(mr,{size:14}),t(`notifications.approve`)]}),V(`button`,{className:`notification-action-btn notification-action-deny`,onClick:t=>{t.stopPropagation(),p(e)},children:[P(Y,{size:14}),t(`notifications.deny`)]})]}),e.type===`permission_request`&&e.response&&P(`span`,{className:`notification-response-badge ${e.response===`allow`?`response-allow`:`response-deny`}`,children:e.response===`allow`?t(`notifications.approved`):t(`notifications.denied`)})]}),P(`button`,{className:`notification-dismiss`,onClick:t=>{t.stopPropagation(),s(e.id)},"aria-label":t(`notifications.dismiss`),children:P(Y,{size:14})})]},e.id)})}),n.length>0&&V(`div`,{className:`notification-center-footer`,children:[V(`button`,{className:`notification-footer-btn`,onClick:a,disabled:r===0,children:[P(mr,{size:14}),t(`notifications.markAllRead`)]}),V(`button`,{className:`notification-footer-btn notification-footer-clear`,onClick:o,children:[P(lo,{size:14}),t(`notifications.clear`)]})]})]})}var QP=1500,$P=e=>new Promise(t=>setTimeout(t,e));async function eF({onProgress:e,isCancelled:t=()=>!1,pollMs:n=QP}={}){try{await sn(ck)}catch(e){if(e?.httpStatus!==409)throw e;let t=await Ut(ck).catch(()=>null);if(!t||t.status===`completed`||t.status===`failed`)throw e}for(;!t();){let t=await Ut(ck);if(e?.(t),t.status===`completed`)return;if(t.status===`failed`)throw Error(t.error||`The GAIA agent could not be installed.`);await $P(n)}}function tF({onInstalled:e,noBuild:t=!1}){let n=T(),[r,i]=(0,X.useState)({kind:`idle`}),a=(0,X.useRef)(!1);(0,X.useEffect)(()=>()=>{a.current=!0},[]);let o=(0,X.useCallback)(async()=>{i({kind:`installing`,percent:0});try{if(await eF({isCancelled:()=>a.current,onProgress:e=>{a.current||i({kind:`installing`,percent:e.percent??0})}}),a.current)return;await e(),a.current||i({kind:`idle`})}catch(e){a.current||i({kind:`failed`,error:e instanceof Error?e.message:String(e)})}},[e]);return t?P(`div`,{className:`app-notice is-warning`,role:`status`,children:P(`span`,{children:n(`agentNotice.noBuild`)})}):V(`div`,{className:`app-notice is-warning`,role:`status`,children:[r.kind===`installing`?P(`span`,{children:n(`agentNotice.installing`,{percent:Math.round(r.percent)})}):r.kind===`failed`?P(`span`,{children:n(`agentNotice.failed`,{error:r.error})}):P(`span`,{children:n(`agentNotice.missing`)}),r.kind!==`installing`&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>void o(),children:r.kind===`failed`?n(`agentNotice.retry`):n(`agentNotice.install`)})]})}function nF(e,t){if(!(e instanceof Error))return t;let n=e.message,r=n.match(/API \d+: (.+)/);if(r)try{let e=JSON.parse(r[1]);if(e.detail)return e.detail}catch{}return n}function rF(e,t){let{addNotification:n}=Qs.getState();for(let r of t)r.error_count<=(e[r.id]??0)||!r.last_error||n({id:`schedule-error-${r.id}-${r.error_count}`,type:`error`,agentId:`scheduler`,agentName:`GAIA`,title:`Scheduled task "${r.name}" failed`,message:r.last_error,timestamp:Date.now(),read:!1,dismissed:!1,priority:`high`,...r.session_id?{sessionId:r.session_id}:{}})}var iF=p((e,t)=>({schedules:[],loading:!1,error:null,actionError:null,selectedSchedule:null,results:[],resultsLoading:!1,errorCounts:null,loadSchedules:async()=>{t().schedules.length===0&&!t().error&&e({loading:!0}),e({error:null});try{let n=(await At()).schedules||[],r=t().errorCounts;r&&rF(r,n),e({schedules:n,loading:!1,errorCounts:Object.fromEntries(n.map(e=>[e.id,e.error_count]))})}catch(t){d.api.error(`Failed to load schedules`,t),e({error:`Failed to load schedules`,loading:!1})}},createSchedule:async(t,n,r)=>{try{let i=await yt(t,n,r);e(e=>({schedules:[...e.schedules,i],actionError:null}))}catch(e){throw d.api.error(`Failed to create schedule`,e),e}},updateScheduleStatus:async(t,n)=>{try{let r=await ut(t,n);e(e=>({schedules:e.schedules.map(e=>e.name===t?r:e),actionError:null}))}catch(n){d.api.error(`Failed to update schedule "${t}"`,n),e({actionError:nF(n,`Failed to update schedule`)})}},runScheduleNow:async t=>{try{let n=await Jt(t);e(e=>({schedules:e.schedules.map(e=>e.name===t?n:e),actionError:null}))}catch(n){d.api.error(`Failed to run schedule "${t}" now`,n),e({actionError:nF(n,`Could not run the schedule now`)})}},deleteSchedule:async t=>{try{await $e(t),e(e=>({schedules:e.schedules.filter(e=>e.name!==t),selectedSchedule:e.selectedSchedule===t?null:e.selectedSchedule,actionError:null}))}catch(n){d.api.error(`Failed to delete schedule "${t}"`,n),e({actionError:nF(n,`Failed to delete schedule`)})}},selectSchedule:n=>{e({selectedSchedule:n,results:[],resultsLoading:!1}),n&&t().loadResults(n)},loadResults:async n=>{e({resultsLoading:!0});try{let r=await De(n);if(t().selectedSchedule!==n)return;e({results:r.results||[],resultsLoading:!1})}catch(r){if(d.api.error(`Failed to load results for "${n}"`,r),t().selectedSchedule!==n)return;e({results:[],resultsLoading:!1})}},dismissActionError:()=>e({actionError:null})})),aF=new Set([`loading_model`,`downloading_model`,`model_retry`,`waiting`]),oF=5;function sF(e,t){return{id:e,title:t.get(e)?.title??`Untitled chat`}}function cF(e){let t=new Map(e.sessions.map(e=>[e.id,e])),n=e.isStreaming&&e.currentSessionId!==null,r=[...e.runningSessionIds];n&&!r.includes(e.currentSessionId)&&r.push(e.currentSessionId);let i=new Set(r),a=new Set(e.notifications.filter(e=>e.type===`permission_request`&&!e.response&&!e.dismissed&&e.sessionId&&i.has(e.sessionId)).map(e=>e.sessionId)),o=[...a].map(e=>({...sF(e,t),reason:`approval`}));n&&e.awaitingUser&&!a.has(e.currentSessionId)&&o.push({...sF(e.currentSessionId,t),reason:`answer`});for(let[n,r]of Object.entries(e.awaitingBySession))o.some(e=>e.id===n)||o.push({...sF(n,t),reason:r===`question`?`answer`:`approval`});let s=n&&!e.awaitingUser&&e.livePhase&&aF.has(e.livePhase)?e.liveStatus:null,c=e.systemStatus,l=null;if(c?.default_model_is_cloud&&c.default_model_name)l={name:c.default_model_name,where:`cloud`};else if(c?.model_loaded){let e=c.model_labels?.includes(`cloud`),t=c.model_device&&c.model_device!==`none`?c.model_device:null;l={name:c.model_loaded,where:e?`cloud`:t}}let u=[...e.sessions].sort((e,t)=>t.updated_at.localeCompare(e.updated_at)).slice(0,oF).map(e=>sF(e.id,t));return{backendConnected:e.backendConnected,modelServerRunning:c&&!c.default_model_is_cloud?c.lemonade_running:null,model:l,waitingOnModel:s||null,running:r.map(e=>sF(e,t)),needsYou:o,recent:u}}function lF(e){let t=(0,X.useRef)(e);t.current=e,(0,X.useEffect)(()=>{let e=window.gaiaAPI?.tray;if(!e)return;let n=``,r=null,i=()=>{let t=k.getState(),i={backendConnected:t.backendConnected,systemStatus:t.systemStatus,sessions:t.sessions,runningSessionIds:t.runningSessionIds,awaitingBySession:t.awaitingBySession,currentSessionId:t.currentSessionId,isStreaming:t.isStreaming,awaitingUser:t.awaitingUser,liveStatus:t.liveStatus,livePhase:t.livePhase,notifications:Qs.getState().notifications},a=r;if(r=i,a&&Object.keys(i).every(e=>i[e]===a[e]))return;let o=cF(i),s=JSON.stringify(o);s!==n&&(n=s,e.setActivity(o).catch(e=>{n=``,d.system.error(`The tray could not take the app state`,e)}))};i();let a=k.subscribe(i),o=Qs.subscribe(i),s=e.onCommand(e=>{switch(e.type){case`open-chat`:t.current.openChat(e.sessionId);break;case`new-chat`:t.current.newChat();break;case`open-settings`:k.getState().openSettings(e.section);break;case`refresh-status`:t.current.refreshStatus();break;default:d.system.error(`Unknown tray command`,e)}});return()=>{a(),o(),s()}},[])}function uF(){(0,X.useEffect)(()=>{let e=window.gaiaAPI;if(!e)return;let t=Qs.getState().addNotification,n=[e.notification.onNotification(t),e.notification.onPermissionRequest(t),e.tray.onNavigate(e=>{let t=typeof e==`string`&&e.startsWith(`session:`)?e.slice(8):null;if(!t)return;let n=k.getState();n.currentSessionId!==t&&n.setMessages([]),n.setCurrentSession(t)})];return()=>n.forEach(e=>e())},[])}function dF(e,t,n){let r=window.gaiaAPI;if(r){r.notification.show({title:t,body:n,sessionId:e}).then(e=>{e||d.system.warn(`This OS has no desktop notifications; the badge still counts it.`)}).catch(e=>d.system.error(`Could not show the desktop notification`,e));return}if(typeof Notification>`u`){d.system.warn(`This browser has no notifications; the alert was not shown.`);return}if(Notification.permission!==`granted`){d.system.warn(`Browser notifications are ${Notification.permission}; allow them in Settings → Notifications.`);return}let i=new Notification(t,{body:n,tag:`gaia-${e}`});i.onclick=()=>{window.focus(),k.getState().setCurrentSession(e)}}function fF(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=navigator;if(!e.getBattery)return;let n=null,r=()=>{n&&t({charging:n.charging,level:n.level})};return e.getBattery().then(e=>{n=e,r(),e.addEventListener(`levelchange`,r),e.addEventListener(`chargingchange`,r)}).catch(e=>d.system.warn(`Battery level unavailable; keep-awake ignores the battery policy.`,e)),()=>{n?.removeEventListener(`levelchange`,r),n?.removeEventListener(`chargingchange`,r)}},[]),e}function pF(){uF();let e=k(e=>e.runningSessionIds),t=k(e=>e.awaitingBySession),n=k(e=>e.sessions),r=k(e=>e.currentSessionId),i=Qs(ko(nc)),a=lc(),o=fF(),s=(0,X.useRef)(null),c=gc(e,t,i),l=JSON.stringify(c);(0,X.useEffect)(()=>{let e=JSON.parse(l),t=s.current;if(s.current=e,t===null)return;let{sessions:n,currentSessionId:r}=k.getState(),i=document.hasFocus(),o=!1;for(let{sessionId:s,event:c}of _c(t,e)){let e=n.find(e=>e.id===s);if(e?.kind===`eval`||e?.kind===`scheduled`)continue;let t=a.modes[c];if(!(t===`off`||bc(s,r,i))&&(o=!0,t===`banner`)){if(c!==`finished`){let{title:t,body:n}=yc(c,e);dF(s,t,n)}else mt(s).then(e=>{k.getState().updateSessionInList(s,e);let{title:t,body:n}=yc(c,e);dF(s,t,n)}).catch(t=>{d.system.error(`Could not read how chat ${s} ended`,t);let{title:n,body:r}=yc(c,{...e,last_run_status:null});dF(s,n,r)})}}if(o){if(a.sound)try{Cc()}catch(e){d.system.warn(`Alert sound not played`,e)}a.flash&&!i&&window.gaiaAPI&&window.gaiaAPI.notification.flash().catch(e=>d.system.error(`Could not flash the taskbar button`,e))}},[l,a.modes,a.sound,a.flash]);let u=xc(n,c,a.modes,r);(0,X.useEffect)(()=>{window.gaiaAPI?.notification.setAttentionCount(u).catch(e=>d.system.error(`Could not update the taskbar badge`,e))},[u]);let f=a.keepAwake&&e.length>0&&Sc(o,a.batteryFloor);(0,X.useEffect)(()=>{window.gaiaAPI?.power.setKeepAwake(f).catch(e=>d.system.error(`Could not change keep-awake`,e))},[f])}function mF(e){if(e<=0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.min(Math.floor(Math.log(e)/Math.log(t)),n.length-1);return parseFloat((e/t**r).toFixed(1))+` `+n[r]}function hF(e){return e.replace(/-/g,``).slice(0,7)}function gF(e,t){let n=t.replace(/^#/,``).toLowerCase();if(!n||n.length<4)return null;let r=e.find(e=>e.id.replace(/-/g,``).toLowerCase().startsWith(n));return r?r.id:null}function _F(e,t,n){return!e||t&&(e===t||e===hF(t))?null:n.some(t=>t.id===e)?e:gF(n,e)}function vF(e){return new URLSearchParams(e.search).get(`session`)||e.hash.replace(/^#/,``)||null}var yF=`gaia:last-session`;function bF(e){try{e?localStorage.setItem(yF,e):localStorage.removeItem(yF)}catch(e){d.ui.warn(`Could not save the open chat for the next launch`,e)}}function xF(){try{return localStorage.getItem(yF)}catch(e){return d.ui.warn(`Could not read the chat open at last launch`,e),null}}var SF=1e3,CF=3e4;function wF(e,{initialMs:t=SF,maxMs:n=CF,onError:r}={}){let i=t,a=0,o=null,s=!1,c=!1,l=!1,u=()=>{l||c||s||(o&&=(clearTimeout(o),null),s=!0,a+=1,e().then(()=>{c=!0}).catch(e=>{l||(r?.(e,a),o=setTimeout(()=>{o=null,u()},i),i=Math.min(i*2,n))}).finally(()=>{s=!1}))};return u(),{kick:()=>{o&&u()},stop:()=>{l=!0,o&&clearTimeout(o),o=null},done:()=>c}}function TF(e,t,n){return e&&!t&&!n}var EF=(0,X.lazy)(()=>IP(()=>import(`./MemoryDashboard-DDIIbL38.js`).then(e=>({default:e.MemoryDashboard})),__vite__mapDeps([6,1,2,7,8]),import.meta.url)),DF=(0,X.lazy)(()=>IP(()=>import(`./ScheduleManager-5ISmwd1h.js`).then(e=>({default:e.ScheduleManager})),__vite__mapDeps([9,1,2,7,3,10]),import.meta.url)),OF=(0,X.lazy)(()=>IP(()=>import(`./DocumentLibrary-BwCg6OBt.js`).then(e=>({default:e.DocumentLibrary})),__vite__mapDeps([11,1,2,3,12]),import.meta.url)),kF=(0,X.lazy)(()=>IP(()=>import(`./FileBrowser-ZQ8nEd3a.js`).then(e=>({default:e.FileBrowser})),__vite__mapDeps([13,1,2,3,14]),import.meta.url)),AF=(0,X.lazy)(()=>IP(()=>import(`./MobileAccessModal-DgmEaSve.js`).then(e=>({default:e.MobileAccessModal})),__vite__mapDeps([15,1,2,3,16]),import.meta.url)),jF=3,MF=3e5,NF=6e3,PF=6e4,FF=e=>e instanceof TypeError,IF=e=>new Promise(t=>setTimeout(t,e)),LF=3e5,RF=class extends Error{};async function zF(){let e=Date.now()+LF;for(;;){let t=await it();if(t.state===`ready`)return;if(t.state===`failed`||t.state===`cancelled`)throw new RF(t.error||I().bare(`setup.upgrading.stopped`));if(Date.now()>=e)throw Error(I().bare(`setup.upgrading.slow`));await IF(SF)}}function BF(){return P(`div`,{className:`loading-spinner`,role:`status`,"aria-label":`Loading`})}var VF=e=>e===1||e%10==0;function HF(){let e=T(),t=k(e=>e.currentSessionId),n=k(e=>e.setSessions),r=k(e=>e.setCurrentSession),i=k(e=>e.addSession),a=k(e=>e.setMessages),o=k(e=>e.showDocLibrary),s=k(e=>e.showFileBrowser),c=k(e=>e.showMemoryDashboard),l=k(e=>e.showSchedules),u=k(e=>e.sidebarOpen),f=k(e=>e.sidebarCollapsed),p=k(e=>e.setSidebarOpen),h=k(e=>e.setSystemStatus),g=k(e=>e.setBackendConnected),_=k(e=>e.setAgents),v=k(e=>e.agents),y=k(e=>e.setPendingPrompt),b=k(e=>e.setDefaultPermissionMode),x=k(e=>e.openSettings),S=k(e=>e.settingsSection),C=k(e=>e.syncSystemTheme),w=cs(e=>e.restoreNotice),E=cs(e=>e.dismissRestoreNotice),D=Qs(e=>e.showPanel),O=k(e=>e.systemStatus?.initialized===!0),A=(0,X.useRef)(!1),j=Qs(e=>e.setShowPanel);(0,X.useEffect)(()=>{if(!w?.ok)return;let e=setTimeout(E,NF);return()=>clearTimeout(e)},[w,E]);let[M,N]=(0,X.useState)({state:`checking`}),F=k(e=>e.setupAgain),I=k(e=>e.runSetupAgain),ee=(0,X.useRef)(M);ee.current=M;let[R,z]=(0,X.useState)(!1),B=(0,X.useRef)(R);B.current=R;let[te,ne]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(!1),ae=te||R&&!lk(v),oe=(0,X.useRef)(ae);oe.current=ae;let[H,se]=(0,X.useState)(null),[W,G]=(0,X.useState)(``),[ce,le]=(0,X.useState)(0),[de,fe]=(0,X.useState)(!1),[pe,me]=(0,X.useState)(!1),[he,ge]=(0,X.useState)(null),[_e,ve]=(0,X.useState)(null),ye=(0,X.useRef)(async()=>{}),be=(0,X.useRef)(async()=>{}),xe=(0,X.useCallback)(async(e=!1,t=!1)=>{e||N({state:`checking`});let n=0;try{for(;;){await cs.getState().refresh();let e=!!cs.getState().active?.remote,r;try{r=await Wt(e)}catch(e){if(!t||!FF(e)||n>=PF)throw e;await IF(SF),n+=SF;continue}if(!r.ready&&r.stage===`upgrade`){N({state:`upgrading`});let t=await it();(!t.upgrade_embedded||t.state!==`running`&&t.state!==`verifying`)&&await _t(e,!1,{upgradeEmbedded:!0}),await zF(),r=await Wt(e)}n>0&&await Promise.all([ye.current(),be.current()]),ie(!!r.no_agent_build),N(r.ready?{state:`ready`}:{state:`needed`,check:r});return}}catch(e){let t=e instanceof Error?e.message:String(e);if(e instanceof RF){d.system.warn(`Updating the local model server failed`,e),N({state:`unknown`,error:t,upgradeFailed:!0});return}d.system.warn(`Setup check could not be answered`,e),N({state:`unknown`,error:t})}},[]),Se=(0,X.useRef)(0),Ce=(0,X.useCallback)(async()=>{let e=++Se.current,t=(await vn()).agents||[];e===Se.current&&(_(t),z(!0),lk(t)&&ne(!1))},[_]),we=(0,X.useCallback)(()=>{let e=B.current;z(!1),Ce().catch(t=>{d.api.warn(`Agent list unavailable after setup`,t),e&&z(!0)})},[Ce]);(0,X.useEffect)(()=>{let e=()=>{oe.current&&Ce().catch(e=>d.api.warn(`Agent list unavailable`,e))};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[Ce]);let Te=(0,X.useCallback)(async()=>{b((await on()).default_mode)},[b]),Ee=(0,X.useRef)([]);(0,X.useEffect)(()=>{m(`0.26.0rc10`),xe(!1,!0);let e=[wF(Ce,{onError:(e,t)=>{VF(t)&&d.api.warn(`Agent list unavailable (attempt ${t}); retrying`,e)}}),wF(Te,{onError:(e,t)=>{VF(t)&&d.api.warn(`Default permission mode unavailable (attempt ${t}); retrying`,e)}})];return Ee.current=e,()=>e.forEach(e=>e.stop())},[xe,Ce,Te]);let De=(0,X.useCallback)(()=>{Ee.current.forEach(e=>e.kick()),cs.getState().retryNow(),be.current();let e=ee.current;e.state===`unknown`&&!e.upgradeFailed&&xe(!0)},[xe]),Oe=(0,X.useRef)(De);Oe.current=De;let ke=(0,X.useRef)(0),Ae=(0,X.useRef)(0),je=(0,X.useRef)(null),Me=(0,X.useRef)(!1),[Ne,Pe]=(0,X.useState)(!1),[Fe,Ie]=(0,X.useState)(null),Le=(0,X.useCallback)(e=>{if(e.kind===`unreachable`){d.system.warn(`System status check failed`,e.error),Me.current=!0,Ae.current=0,je.current=null,Pe(!1),Ie(null),g(!1),h(null);return}if(e.kind===`error`){d.system.warn(`System status answered HTTP ${e.httpStatus}`,e.message),Me.current&&Oe.current(),Me.current=!1,Ae.current=0,je.current=null,Pe(!1),Ie(`HTTP ${e.httpStatus}: ${e.message}`),g(!0);return}if(e.kind===`slow`){if(Ae.current+=1,je.current??=Date.now(),Ie(null),d.system.warn(`System status did not answer in time (${Ae.current} in a row)`),Date.now()-je.current>=MF){Pe(!1),g(!1),h(null);return}g(!0),(Me.current||Ae.current>=jF)&&Pe(!0);return}let{status:t}=e;Me.current&&Oe.current(),Me.current=!1,Ae.current=0,je.current=null,Pe(!1),Ie(null),g(!0),ke.current=t.lemonade_running?0:ke.current+1;let n=k.getState().systemStatus;t.lemonade_running||ke.current>=jF||!n?.lemonade_running?h(t):h({...n,download_progress:t.download_progress})},[g,h]),Re=(0,X.useRef)(Le);Re.current=Le;let[ze]=(0,X.useState)(()=>Kw(e=>Re.current(e))),Be=ze.check;ye.current=Be,(0,X.useEffect)(()=>_k(ze.start),[ze]),(0,X.useEffect)(()=>HP(()=>{Be()}),[Be]);let Ve=(0,X.useRef)(``);(0,X.useEffect)(()=>{let e=e=>Ft().then(t=>{let r=t.sessions||[];if(!e&&r.length===0&&k.getState().sessions.length>0)return;let i=r.map(e=>`${e.id}|${e.updated_at}|${e.title}|${e.inference_remote}|${e.inference_provider}|${e.inference_description}|${e.effective_model}|${e.unread}|${e.pinned}|${e.last_run_status}|${e.kind}`).join(`
|
|
82
|
-
`);if(i===Ve.current)return;Ve.current=i,n(r);let a=cs.getState().active?.model;a&&r.some(e=>e.effective_model&&e.effective_model!==a)&&cs.getState().refresh()}).catch(t=>{e&&d.system.error(`Could not load chats`,t)});be.current=()=>e(!1),e(!0);let t=setInterval(()=>void e(!1),5e3);return()=>clearInterval(t)},[n]),(0,X.useEffect)(()=>aT(),[]),(0,X.useEffect)(()=>{let e=()=>{iF.getState().loadSchedules()};e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[]),(0,X.useEffect)(()=>CT(),[]),pF();let He=(0,X.useRef)(!1),Ue=(0,X.useRef)(!1);(0,X.useEffect)(()=>{let e=()=>{let e=vF(window.location),{currentSessionId:t,sessions:n}=k.getState(),i=_F(e,t,n);return i&&(r(i),a([])),i},t=()=>{if(He.current||(He.current=!0,e()||k.getState().currentSessionId))return;if(window.location.hash){window.history.replaceState(null,``,window.location.pathname+window.location.search);return}if(Ue.current||xn(`new-chat`))return;let{sessions:t}=k.getState(),n=_F(xF(),null,t);n&&(r(n),a([]))},n=k.subscribe(e=>{e.sessions.length>0&&t()});return k.getState().sessions.length>0&&t(),window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{n(),window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[r,a]),(0,X.useEffect)(()=>{let e=null,t=2e3,n=!1,i=null,o=()=>{n||(e=new EventSource(`${L()}/sessions/events`),e.onopen=()=>{t=2e3},e.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch(e){d.api.warn(`Malformed session event`,e);return}t.type===`set_active_session`&&t.session_id&&t.session_id!==k.getState().currentSessionId&&(r(t.session_id),a([]))},e.onerror=()=>{e?.close(),e=null,!n&&(i=setTimeout(o,t),t=Math.min(t*2,3e4))})};return o(),()=>{n=!0,i&&clearTimeout(i),e?.close()}},[r,a]),(0,X.useEffect)(()=>{if(He.current&&bF(t),t){let e=hF(t);window.location.hash!==`#${e}`&&window.history.replaceState(null,``,`#${e}`)}else He.current&&window.location.hash&&window.history.replaceState(null,``,window.location.pathname+window.location.search)},[t]);let We=(0,X.useCallback)(async e=>{if(se(null),!await Go(`chat`))return G(e),!1;let t=k.getState(),n;try{n=await En({title:`New Task`,agent_type:ck,document_ids:t.draftDocumentIds,private:t.draftPrivate,folders:t.draftFolder?[t.draftFolder]:[]})}catch(e){throw uk(e)?(ne(!0),Error(`The GAIA agent isn't installed. Install it from the notice above, then send again.`)):e}oe.current&&(ne(!1),Ce().catch(e=>d.api.warn(`Agent list unavailable`,e))),t.defaultPermissionModeKnown||(await Te().catch(e=>d.api.warn(`Default permission mode unavailable; using the chip's mode`,e)),t=k.getState()),t.clearDraftDocuments(),t.setDraftPrivate(!1),t.setDraftFolder(null);let o=null;try{await Pt(n.id,t.draftPermissionMode)}catch(e){o=e}return Mt(Je),o&&!n.private&&nn(U(n.id),e),i(n),r(n.id),a([]),G(``),o?(se(`The chat was created, but its permission mode could not be set, so your message was not sent${n.private?``:` — it is in the chat's box`}: ${o instanceof Error?o.message:o}`),!1):(t.resetDraftPermissionMode(),y({sessionId:n.id,text:e}),!0)},[i,r,a,y,Ce,Te]),Ge=(0,X.useCallback)(()=>{let e=k.getState(),t=e.currentSessionId;t&&jc(t,e)&&Mc(t),e.setShowMemoryDashboard(!1),e.setShowSchedules(!1),Ue.current=!0,r(null),a([]),le(e=>e+1)},[r,a]);lF({openChat:(0,X.useCallback)(e=>{let t=k.getState();t.closeSettings(),e!==t.currentSessionId&&(Mc(t.currentSessionId),a([])),r(e)},[r,a]),newChat:(0,X.useCallback)(()=>{k.getState().closeSettings(),Ge()},[Ge]),refreshStatus:()=>void Be()});let Ke=(0,X.useCallback)(e=>{Ge(),We(`Load the \`${e}\` skill, then tell me briefly what it lets you do.`).catch(e=>se(e instanceof Error?e.message:String(e)))},[Ge,We]),qe=(0,X.useCallback)(e=>{N({state:`ready`}),we(),Be(),e&&(e.needs_input?G(e.prompt):We(e.prompt).catch(e=>se(e instanceof Error?e.message:String(e))))},[Be,We,we]),Ye=(0,X.useCallback)(()=>{N({state:`ready`}),Be()},[Be]);(0,X.useEffect)(()=>{let e=()=>{k.getState().closeSettings(),N({state:`addingLocal`})};return window.addEventListener(`gaia:set-up-local`,e),()=>window.removeEventListener(`gaia:set-up-local`,e)},[]),(0,X.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&(e.shiftKey&&e.key.toLowerCase()===`o`?(e.preventDefault(),Ge()):!e.shiftKey&&e.key.toLowerCase()===`k`?(e.preventDefault(),window.dispatchEvent(new CustomEvent(`gaia:focus-search`))):!e.shiftKey&&e.key.toLowerCase()===`b`?(e.preventDefault(),k.getState().toggleSidebarCollapsed()):!e.shiftKey&&e.key===`,`&&(e.preventDefault(),x()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Ge,x]),(0,X.useEffect)(()=>{let e=window.matchMedia?.(`(max-width: 768px)`);if(!e)return;let t=()=>p(!e.matches);return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[p]),(0,X.useEffect)(()=>{if(typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(prefers-color-scheme: light)`);return e.addEventListener(`change`,C),()=>e.removeEventListener(`change`,C)},[C]),(0,X.useEffect)(()=>{Sn().then(e=>me(e.active===!0)).catch(e=>d.system.debug(`Mobile access unavailable`,e))},[]);let Xe=(0,X.useCallback)(async()=>{if(fe(!0),ge(null),pe)ve(null);else try{let e=await Pn(),t=e.reason===`ngrok_not_installed`;if(ve(t?e.installCommands??[]:null),t)return;e.error?ge(e.error):me(!0)}catch(e){ve(null),ge(e instanceof Error?e.message:`Could not start mobile access`)}},[pe]),Ze=(0,X.useCallback)(async()=>{try{await ue(),me(!1),fe(!1)}catch(e){ge(e instanceof Error?e.message:`Could not stop mobile access`)}},[]);ND(e=>{e?Xe():Ze()}),(0,X.useEffect)(()=>{jD(pe)},[pe]);let Qe=zc(`(max-width: 768px)`),$e=TF(M.state===`checking`,O,A.current);if(!$e&&M.state!==`needed`&&(A.current=!0),$e)return P(`div`,{className:`app`,children:V(`main`,{className:`startup`,role:`status`,"aria-label":`Starting GAIA`,children:[P(`div`,{className:`loading-spinner`,"aria-hidden":`true`}),P(`p`,{className:`startup-text`,children:`Starting GAIA…`})]})});if(M.state===`upgrading`)return P(`div`,{className:`app`,children:V(`main`,{className:`startup`,role:`status`,"aria-live":`polite`,"aria-label":e(`setup.upgrading.notice`),children:[P(`div`,{className:`loading-spinner`,"aria-hidden":`true`}),P(`p`,{className:`startup-text`,children:e(`setup.upgrading.notice`)})]})});if(M.state===`needed`||M.state===`addingLocal`||F){let e=F?()=>I(!1):M.state===`addingLocal`?Ye:void 0;return V(`div`,{className:`app`,children:[P(bN,{onReady:e=>{I(!1),qe(e)},onClose:e}),P(HA,{}),P(JP,{})]})}let et=c?P(X.Suspense,{fallback:P(BF,{}),children:P(EF,{})}):t?P(kk,{sessionId:t},t):P(LA,{onSend:We,initialText:W,focusRequest:ce},W);return V(`div`,{className:`app`,children:[!u&&P(`button`,{className:`sidebar-toggle`,onClick:()=>p(!0),"aria-label":`Open sidebar`,children:P(sa,{size:18})}),P(`div`,{className:`sidebar-overlay ${u?`visible`:``}`,onClick:()=>p(!1),"aria-hidden":`true`}),P(ol,{onNewChat:Ge,onMobileAccess:Qe?void 0:()=>void Xe(),tunnelActive:pe}),V(`div`,{className:`main-content`,children:[M.state===`ready`&&P(qP,{onRetry:Be,backendSlow:Ne,backendError:Fe}),M.state===`unknown`&&(M.upgradeFailed?V(`div`,{className:`app-notice is-warning`,role:`status`,children:[P(`span`,{children:e(`setup.upgrading.failed`,{error:M.error})}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>void xe(),children:e(`setup.upgrading.retry`)})]}):V(`div`,{className:`app-notice is-warning`,role:`status`,children:[P(`span`,{children:e(`setup.unknown.failed`,{error:M.error})}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>void xe(),children:e(`setup.unknown.retry`)})]})),(!u||f)&&P(Rs,{placement:`main`}),ae&&P(tF,{onInstalled:Ce,noBuild:re}),w&&V(`div`,{className:`app-notice${w.ok?``:` is-warning`}`,role:`status`,children:[P(`span`,{children:w.message}),!w.ok&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>{E(),x(`model`)},children:`Pick a model`}),P(`button`,{type:`button`,className:`app-notice-close`,onClick:E,"aria-label":`Dismiss`,children:P(Y,{size:14})})]}),et]}),l&&P(X.Suspense,{fallback:null,children:P(DF,{})}),o&&P(X.Suspense,{fallback:null,children:P(OF,{})}),s&&P(X.Suspense,{fallback:null,children:P(kF,{onStartChat:We})}),D&&P(`div`,{className:`notification-center-popover`,children:P(ZP,{onClose:()=>j(!1)})}),de&&P(X.Suspense,{fallback:null,children:P(AF,{isOpen:de,onClose:()=>fe(!1),onStop:()=>void Ze(),error:he,setupCommands:_e,onRetry:()=>void Xe()})}),S&&P(BP,{onUseSkill:Ke}),P(HA,{}),P(JP,{}),H&&V(`div`,{className:`toast toast-dismissible`,role:`alert`,children:[P(`span`,{children:H}),P(`button`,{type:`button`,className:`toast-dismiss`,onClick:()=>se(null),"aria-label":e(`banner.dismiss`),children:P(Y,{size:14,"aria-hidden":`true`})})]})]})}var UF=`agent-refresh`,WF={"pre-checks":`engine.stage.preChecks`,"ensure-uv":`engine.stage.ensureUv`,"create-venv":`engine.stage.createVenv`,"install-package":`engine.stage.installPackage`,verify:`engine.stage.verify`,[UF]:`engine.stage.agentRefresh`,start:`engine.stage.start`},GF={disk:`engine.hint.disk`,network:`engine.hint.network`,tls:`engine.hint.tls`,locked:`engine.hint.locked`,daemon:`engine.hint.daemon`};function KF(e,t){if(!e)return t(`engine.stage.neutral`);let n=WF[e];return n?t(n):(console.warn(`[EngineInstallScreen] install stage "${e}" has no label`),t(`engine.stage.neutral`))}function qF(e,t){return e.reason?t(GF[e.reason]):t(e.stage===UF?`engine.hint.agent`:`engine.hint.other`)}function JF(e){return e.reason===`locked`&&e.lockedBy?.length?e.lockedBy:null}function YF(e,t){let n=e.name??String(e.pid),r=e.folder;return e.isGaia?r?t(`engine.locked.gaia`,{name:n,folder:r}):t(`engine.locked.gaiaNoFolder`,{name:n}):r?t(`engine.locked.other`,{name:n,folder:r}):t(`engine.locked.otherNoFolder`,{name:n})}function XF({status:e}){let t=T(),n=KF(e.stage,t);return V(`div`,{className:`engine-progress`,role:`status`,children:[V(`div`,{className:`engine-progress-head`,children:[P(`span`,{children:n}),e.percent!==null&&V(`bdi`,{dir:`ltr`,children:[e.percent,`%`]})]}),P(`progress`,{className:`engine-bar`,"aria-label":n,max:100,value:e.percent??void 0})]})}function ZF({error:e,busy:t,notice:n,onRetry:r,onCloseLockers:i,onContinue:a,onRevert:o,onOpenLog:s}){let c=T(),l=JF(e),u=l!==null&&l.every(e=>e.isGaia),d=(l?.length??0)>1;return V(`div`,{className:`engine-failure`,children:[V(`div`,{role:`alert`,children:[l?V(D.Fragment,{children:[l.map(e=>P(`p`,{className:`engine-hint`,children:YF(e,c)},e.pid)),!u&&P(`p`,{className:`engine-hint`,children:c(d?`engine.locked.closeThenMany`:`engine.locked.closeThen`)})]}):P(`p`,{className:`engine-hint`,children:qF(e,c)}),P(`p`,{className:`engine-error`,children:P(`bdi`,{dir:`ltr`,children:e.message})})]}),u&&P(`button`,{type:`button`,className:`btn-primary engine-retry`,disabled:t,onClick:i,autoFocus:!0,children:c(d?`engine.locked.closeMany`:`engine.locked.close`)}),P(`button`,{type:`button`,className:`${u?`btn-secondary`:`btn-primary`} engine-retry`,disabled:t,onClick:r,autoFocus:!u,children:c(`engine.tryAgain`)}),e.stage===UF&&P(`button`,{type:`button`,className:`btn-secondary engine-retry`,disabled:t,onClick:a,children:c(`engine.continueWithout`)}),e.previousVersion&&P(`button`,{type:`button`,className:`btn-secondary engine-retry`,disabled:t,onClick:o,children:c(`update.chip.goBack`,{version:e.previousVersion})}),n&&P(`p`,{className:`engine-error`,role:`alert`,children:P(`bdi`,{dir:`ltr`,children:n})}),V(`details`,{className:`engine-details`,children:[P(`summary`,{children:c(`engine.details`)}),P(`pre`,{className:`engine-log`,dir:`ltr`,children:e.logTail.join(`
|
|
83
|
-
`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:s,children:c(`engine.openLog`)})]})]})}function
|
|
77
|
+
`)),f(Ix(e))}finally{O.current=!1,m(!1)}}}},[S,e]),N=(0,X.useCallback)(()=>M(S.compose(c.trim()),c.trim()),[S,M,c]);(0,X.useEffect)(()=>{n&&y.current?.focus()},[n]);let F=c.length>0||p,I=(0,X.useRef)(null);(0,X.useLayoutEffect)(()=>{let e=b.current;if(!e)return;typeof e.getAnimations==`function`&&e.getAnimations().forEach(e=>e.cancel());let t=e.getBoundingClientRect().top,n=I.current;if(I.current={top:t,docked:F},!n||n.docked===F||jx()||typeof e.animate!=`function`)return;let r=getComputedStyle(document.documentElement).getPropertyValue(`--ease`).trim();if(!r)throw Error(`Motion token --ease is not set; check styles/index.css.`);e.animate([{transform:`translateY(${n.top-t}px)`},{transform:`none`}],{duration:Ax(`--duration-spring`),easing:r})});let L=a?.state===`starting`||a?.state===`downloading`,R=p?`sending`:L?`download`:i||C!==null?`loading`:`idle`,z=h?.working_folder;return V(`main`,{className:`new-chat${F?` is-docked`:``}`,"aria-label":r(`newChat.label`),children:[P(Uk,{activity:R,progress:(a?.percent??0)/100,pulse:c.length,docked:F,contentRef:b,composerRef:x}),V(`div`,{className:`new-chat-inner`,ref:b,children:[P(`h1`,{className:`new-chat-greeting`,"aria-hidden":F,children:jA(new Date,r)}),o&&!s&&P(LA,{error:o}),P(`div`,{ref:x,children:P(qT,{value:c,onChange:l,onSubmit:N,attachments:S,disabledReason:i?r(`composer.starting`):null,autoFocus:!0,inputRef:y,leftControls:V(D.Fragment,{children:[P(SE,{sessionId:null}),P(TA,{disabled:p})]}),rightControls:P(aE,{})})}),P(`div`,{className:`new-chat-meta`,children:z&&P(gE,{folder:z,disabled:i||p})}),P(IA,{}),C!==null&&!i&&P(`p`,{className:`new-chat-warmup`,role:`status`,children:NA(C,r)}),u&&P(`p`,{className:`new-chat-error`,role:`alert`,children:u}),_&&P(PA,{detail:_,onRetry:()=>E()})]})]})}var zA=1e3,BA=15,VA=5,HA=new Map;function UA(){let e=T(),t=Wo(e=>e.need),n=Wo(e=>e.settle),r=(0,X.useRef)(null),i=(0,X.useRef)(null),a=(0,X.useRef)(0),o=(0,X.useRef)(0),s=(0,X.useRef)(null);s.current=t;let[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(!1),g=(0,X.useCallback)(()=>{i.current&&clearInterval(i.current),i.current=null},[]);(0,X.useEffect)(()=>(l(null),d(!1),p(null),h(!1),g),[t,g]);let _=(0,X.useCallback)(()=>{g(),u&&t?.model&&G(t.model.id).catch(e=>console.warn(`[ModelNeededDialog] could not cancel the download`,e)),n(!1)},[u,t,n,g]);Io(!!t,_),sS(r,!!t);let v=(0,X.useCallback)(async r=>{if(!t?.model)return;let c=t,u=t.model.id,f=(HA.get(u)??0)+1;HA.set(u,f),p(null),d(!0),a.current=0,o.current=0;try{await Te(u,{acknowledgeLowDisk:r})}catch(e){if(s.current!==c)return;d(!1),p(e instanceof Error?e.message:String(e)),e instanceof yn&&e.body?.code===`low_disk`&&h(!0);return}s.current===c?(g(),i.current=setInterval(()=>{it().then(t=>{if(s.current!==c){g();return}o.current=0;let r=t.models?.find(e=>e.id===u);if(r)r.bytes_total>0&&l(Math.floor(r.bytes_done*100/r.bytes_total)),r.state===`ready`||r.state===`verifying`?(g(),n(!0)):(r.state===`failed`||r.state===`cancelled`)&&(g(),d(!1),p(r.error??e(`modelNeeded.failed`)));else{if(++a.current<BA)return;g(),d(!1),p(e(`modelNeeded.failed`))}}).catch(e=>{s.current===c?++o.current<VA||(g(),d(!1),p(e instanceof Error?e.message:String(e))):g()})},zA)):HA.get(u)===f&&G(u).catch(e=>console.warn(`[ModelNeededDialog] could not cancel the download`,e))},[t,n,g,e]);if(t?.off)return(0,eS.createPortal)(P(`div`,{className:`model-needed-overlay`,children:V(`div`,{ref:r,className:`model-needed`,role:`dialog`,"aria-modal":`true`,"aria-label":e(`modelNeeded.off.${t.off}.title`),children:[P(`h2`,{className:`model-needed-title`,children:e(`modelNeeded.off.${t.off}.title`)}),P(`p`,{className:`model-needed-from`,children:e(`modelNeeded.off.${t.off}.body`)}),V(`div`,{className:`model-needed-actions`,children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:_,children:e(`modelNeeded.notNow`)}),P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>n(!0),children:e(`modelNeeded.off.send`)})]})]})}),document.body);if(!t?.model)return null;let{model:y,job:b,disk_free_gb:x}=t,S=y.size_gb!=null&&x!=null&&y.size_gb>x,C=S||m;return(0,eS.createPortal)(P(`div`,{className:`model-needed-overlay`,children:V(`div`,{ref:r,className:`model-needed`,role:`dialog`,"aria-modal":`true`,"aria-label":e(`modelNeeded.dialog`),children:[P(`h2`,{className:`model-needed-title`,children:e(`modelNeeded.title.${b}`)}),V(`p`,{className:`model-needed-line`,children:[P(`bdi`,{children:y.name}),y.size_gb!=null&&V(D.Fragment,{children:[`, `,P(`bdi`,{dir:`ltr`,children:$(y.size_gb)})]}),x!=null&&V(D.Fragment,{children:[` · `,e(`modelNeeded.free`),` `,P(`bdi`,{dir:`ltr`,children:$(x)})]})]}),y.source&&V(`p`,{className:`model-needed-from`,children:[e(`setup.contents.from`),` `,P(`bdi`,{dir:`ltr`,children:y.source})]}),P(`p`,{className:`model-needed-from`,children:e(`modelNeeded.waits`)}),u&&(c==null?V(`p`,{role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,e(`modelNeeded.starting`)]}):P(`progress`,{className:`setup-progress`,max:100,value:c,"aria-label":e(`modelNeeded.dialog`)})),S&&!u&&P(`p`,{className:`setup-error`,role:`alert`,children:e(`modelNeeded.lowDisk`,{need:$(y.size_gb??0),free:$(x??0),freeUp:$((y.size_gb??0)-(x??0))})}),f&&P(`p`,{className:`setup-error`,role:`alert`,children:f}),V(`div`,{className:`model-needed-actions`,children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:_,children:e(`modelNeeded.notNow`)}),P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void v(C),disabled:u,children:e(C?`setup.confirm.downloadAnyway`:f?`setup.tryAgain`:`modelNeeded.download`)})]})]})}),document.body)}function WA(e){let t=e?.reason;return t===`needs_key`||t===`bad_key`}function GA({provider:e,limit:t}){let n=T(),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(null);if((0,X.useEffect)(()=>{i(null),o(null),We(e).then(i).catch(e=>o(e instanceof Error?e.message:String(e)))},[e]),a)return P(`p`,{className:`settings-error`,role:`alert`,children:n(`settings.price.loadFailed`,{reason:a})});if(!r)return V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,n(`settings.price.loading`)]});if(r.models.length===0)return V(`p`,{className:`settings-hint cloud-prices-note`,children:[n(`settings.price.unknownSentence`),` `,P(`bdi`,{children:r.note})]});let s=t?r.models.slice(0,t):r.models;return V(`div`,{className:`cloud-prices`,"aria-label":n(`settings.model.prices`),children:[P(`ul`,{className:`cloud-prices-list`,children:s.map(e=>V(`li`,{children:[V(`span`,{className:`cloud-prices-name`,children:[P(`bdi`,{children:e.name}),e.note&&V(`span`,{className:`cloud-prices-note`,children:[` · `,P(`bdi`,{children:e.note})]})]}),P(`span`,{className:`cloud-prices-price`,children:QT(e.price,n)})]},e.model))}),V(`span`,{className:`settings-hint`,children:[P(`bdi`,{children:r.source}),`. `,n(`settings.price.payProvider`)]})]})}function KA(){return zc(kx)}function qA(e,t=150){let n=KA(),[r,i]=(0,X.useState)(e),a=(0,X.useRef)(e);return(0,X.useEffect)(()=>{if(n||typeof requestAnimationFrame!=`function`){a.current=e,i(e);return}let r=a.current,o=performance.now(),s=0,c=n=>{let l=Math.min(1,(n-o)/t),u=1-(1-l)**3,d=r+(e-r)*u;a.current=d,i(d),l<1&&(s=requestAnimationFrame(c))};return s=requestAnimationFrame(c),()=>cancelAnimationFrame(s)},[e,t,n]),r}function JA(e,t){let[n,r]=(0,X.useState)(e);return(0,X.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function YA(){let[e,t]=(0,X.useState)(()=>typeof document>`u`||document.visibilityState!==`hidden`);return(0,X.useEffect)(()=>{let e=()=>t(document.visibilityState!==`hidden`);return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]),e}var XA=180;function ZA({open:e,children:t}){let[n,r]=(0,X.useState)(e),[i,a]=(0,X.useState)(e),o=(0,X.useRef)(t);return e&&(o.current=t),(0,X.useEffect)(()=>{if(e){r(!0);let e=requestAnimationFrame(()=>a(!0));return()=>cancelAnimationFrame(e)}a(!1);let t=setTimeout(()=>r(!1),XA);return()=>clearTimeout(t)},[e]),n?P(`div`,{className:`reveal${i?` is-open`:``}`,"aria-hidden":!e||void 0,children:P(`div`,{className:`reveal-inner`,children:e?t:o.current})}):null}var QA=e=>e?.catalog??[],$A=e=>e.roles.includes(`vision`),ej=e=>e.roles.includes(`embedding`),tj=e=>e.recipe===`flm`,nj=e=>e.fits===!1&&(e.fit_code===`npu`||e.fit_code===`backend`),rj=e=>e.support===null,ij=e=>e?.feature_tier!==`compact`;function aj(e,t){let n=e.find(e=>e.id===t.defaultChat);return n&&tj(n)||t.vision===`none`?null:t.vision?t.vision:n?.reads_images?n.id:e.find(e=>$A(e)&&e.gaia_model)?.id??null}function oj(e,t){let n=aj(t,e),r=new Set(e.ticked),i=new Set(e.unticked);for(let a of t)$A(a)&&a.id!==e.defaultChat&&(a.id===n?(r.add(a.id),i.delete(a.id)):a.downloaded||(r.delete(a.id),i.add(a.id)));return{...e,ticked:r,unticked:i}}function sj(e,t,n){let r=new Set(e.ticked),i=t.find(t=>t.id===e.defaultChat);i&&!i.downloaded&&r.delete(i.id);let a=t.find(e=>e.id===n);if(a?.downloaded||r.add(n),!ij(a))for(let e of t)e.roles.includes(`image_creation`)&&r.delete(e.id);return oj({...e,ticked:r,defaultChat:n,chatChosen:!0,vision:null},t)}function cj(e,t,n){return oj({...e,vision:n},t)}function lj(e,t){if(t.vision===`none`)return null;let n=aj(e,t),r=e.find(e=>e.id===t.defaultChat);return r&&tj(r)||n===(r?.reads_images?r.id:e.find(e=>$A(e)&&e.gaia_model)?.id)?null:n}function uj(e){return e.filter(e=>e.gaia_model&&(e.planned||e.recommended||e.downloaded||e.partial))}function dj(e){let t=new Set(uj(e).map(e=>e.id));return e.filter(e=>e.gaia_model&&!t.has(e.id))}function fj(e){return e.filter(e=>!e.gaia_model&&e.downloaded)}function pj(e){let t=QA(e),n=new Set(t.filter(e=>e.selected||e.gaia_model&&e.downloaded&&!e.skipped).map(e=>e.id)),r=!t.find(t=>t.id===e.chat_model.id)?.reads_images&&t.some(e=>$A(e)&&e.gaia_model&&e.skipped);return oj({ticked:n,defaultChat:e.chat_model.id,unticked:new Set,chatChosen:e.chat_model.user_set,vision:e.vision_model??(r?`none`:null)},t)}function mj(e,t){return e.filter(e=>e.chat_choice&&(t.has(e.id)||e.downloaded))}function hj(e,t,n,r){let i=new Set(e.ticked),a=new Set(e.unticked);r?(i.add(n),a.delete(n)):(i.delete(n),a.add(n));let o=mj(t,i),s=e.defaultChat;if(!s||!o.some(e=>e.id===s)){let e=t.find(e=>e.id===n);s=r&&e?.chat_choice?n:(o.find(e=>e.recommended)??o[0])?.id??null}return{...e,ticked:i,defaultChat:s,unticked:a}}function gj(e,t,n){let r=t.find(e=>e.id===n)?.downloaded;return{...e,defaultChat:n,chatChosen:!0,ticked:r?e.ticked:new Set([...e.ticked,n])}}function _j(e){let t=QA(e),n=new Set(t.filter(e=>e.recommended||e.gaia_model&&e.downloaded).map(e=>e.id)),r=mj(t,n);return oj({ticked:n,defaultChat:e.recommended_model&&r.some(t=>t.id===e.recommended_model)?e.recommended_model:(r.find(e=>e.recommended)??r[0])?.id??null,unticked:new Set,chatChosen:!1,vision:null},t)}function vj(e,t){return e.filter(e=>t.ticked.has(e.id)&&!e.downloaded).sort((e,t)=>(t.size_gb??0)-(e.size_gb??0))}function yj(e,t){let n=vj(QA(e),t).map(e=>e.size_gb),r=n.every(e=>e!=null)?Tj(n.reduce((e,t)=>e+t,0)):null,i=e.disk?.free_gb??null;return{downloadGb:r,freeGb:i,afterGb:r!=null&&i!=null?Tj(i-r):null}}function bj(e,t){let{downloadGb:n,freeGb:r}=yj(e,t);return n==null||r==null||n<=r?null:{needGb:n,freeGb:r,freeUpGb:Tj(n-r),drop:vj(QA(e),t).find(e=>e.size_gb!=null&&n-e.size_gb<=r)??null}}function xj(e,t){return e.filter(e=>e.fits===!1&&(t.ticked.has(e.id)||e.id===t.defaultChat))}function Sj(e,t){let n=[];for(let r of QA(e)){if(!r.planned){r.skipped&&t.ticked.has(r.id)&&n.push({id:r.id,skipped:!1});continue}if(r.id===e.chat_model.id){r.skipped&&n.push({id:r.id,skipped:!1});continue}let i=t.ticked.has(r.id);!i&&!r.skipped&&n.push({id:r.id,skipped:!0}),i&&r.skipped&&n.push({id:r.id,skipped:!1})}return n}function Cj(e,t){return QA(e).filter(e=>t.ticked.has(e.id)&&!e.planned&&!e.downloaded).map(e=>e.id)}function wj(e,t){let n=(e.models??[]).filter(e=>e.state!==`skipped`);if(!t?.catalog||n.length===0)return e.overall;let r=0,i=0;for(let e of n){let n=t.catalog.find(t=>t.id===e.id),a=n?.downloaded?0:n?.size_gb==null?e.bytes_total:Math.min(e.bytes_total||1/0,n.size_gb*1e9),o=Math.max(0,e.bytes_total-a);i+=a,r+=e.state===`ready`||e.state===`verifying`?a:Math.min(a,Math.max(0,e.bytes_done-o))}return{bytes_done:r,bytes_total:i,speed_bps:e.overall?.speed_bps??0,eta_s:null,percent:i>0?Math.floor(r*100/i):100,failed:n.filter(e=>e.state===`failed`).length}}function Tj(e){return Math.round(e*10)/10}var Ej=6;function Dj(e,t){let n=[];return e.chat_choice&&!ej(e)&&n.push(t(`setup.models.purpose.chat`)),$A(e)&&n.push(t(`setup.models.purpose.vision`)),ej(e)&&n.push(t(`setup.models.purpose.documents`)),n}function Oj(e,t){return ej(e)?t(`setup.models.line.documents`):$A(e)?t(`setup.models.line.vision`):t(`setup.models.line.chat`)}function kj(e,t){return e.downloaded?t(`setup.models.status.onPc`):e.size_gb==null?t(`setup.models.status.sizeUnknown`):e.partial?t(`setup.models.status.partial`,{size:$(e.size_gb)}):t(`setup.models.status.download`,{size:$(e.size_gb)})}function Aj(e,t){return e.fits!==!0||e.need_gb==null||e.capacity_gb==null?null:t(`setup.models.fit.ok`,{need:NS(e.need_gb),have:NS(e.capacity_gb)})}function jj(e,t){return e.fit_code===`npu`?t(`setup.models.warn.npu`):e.fit_code===`backend`?t(`setup.models.warn.backend`):e.need_gb!=null&&e.capacity_gb!=null?t(`setup.models.warn.tooBig`,{need:NS(e.need_gb),have:NS(e.capacity_gb)}):t(`setup.models.warn.tooBigNoNumbers`)}function Mj(e,t,n){return!$A(e)&&!ej(e)?null:n===`settings`?e.downloaded?t(`settings.models.warn.kept`,{name:e.name}):t($A(e)?`settings.models.warn.vision`:`settings.models.warn.documents`,{name:e.name}):t($A(e)?`setup.models.warn.vision`:`setup.models.warn.documents`,{name:e.name})}function Nj({entry:e,ticked:t,onToggle:n,disabled:r,progress:i,actions:a,place:o}){let s=T(),c=(0,X.useId)(),l=e.fits===!1,u=t?null:Mj(e,s,o),d=i?.state===`downloading`&&i.bytes_total>0,f=l?jj(e,s):u,p=[`${c}-status`,`${c}-note`,f?`${c}-warn`:null].filter(Boolean).join(` `);return V(`li`,{className:`mc-row${t?` is-ticked`:``}${f?` has-warning`:``}`,children:[V(`div`,{className:`mc-row-top`,children:[V(`label`,{className:`mc-row-main`,children:[P(`input`,{type:`checkbox`,className:`mc-input`,checked:t,disabled:r,onChange:e=>n(e.target.checked),"aria-describedby":p}),P(`span`,{className:`mc-box`,"aria-hidden":`true`,children:P(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,children:P(`path`,{className:`mc-tick`,d:`M3.5 8.5l3 3 6-7`})})}),V(`span`,{className:`mc-text`,children:[V(`span`,{className:`mc-name-line`,children:[P(`bdi`,{className:`mc-name`,title:e.id,children:e.name}),V(`span`,{className:`mc-chips`,children:[Dj(e,s).map(e=>P(`span`,{className:`mc-chip`,children:e},e)),tj(e)&&P(`span`,{className:`mc-chip is-npu`,children:s(`setup.models.npu`)})]})]}),V(`span`,{className:`mc-status`,id:`${c}-status`,children:[d?s(`setup.models.status.downloading`,{done:PS(i.bytes_done),total:PS(i.bytes_total)}):kj(e,s),e.recommended&&P(`span`,{className:`mc-pill`,children:s(`setup.models.recommended`)}),e.fits===null&&V(`span`,{className:`mc-chip is-unknown`,children:[P(Ar,{size:11,"aria-hidden":`true`}),` `,s(`setup.models.fitUnknown`)]})]}),P(`span`,{className:`mc-note`,id:`${c}-note`,children:s.compose(t=>[Oj(e,t),Aj(e,t),e.fits===null?t(`setup.models.fit.unknown`):null].filter(Boolean).join(` `))})]})]}),a&&P(`span`,{className:`mc-actions`,children:a})]}),d&&P(`progress`,{className:`mc-mini-progress`,max:i.bytes_total,value:i.bytes_done,"aria-label":s(`setup.progress.rowLabel`,{name:e.name,state:s(`setup.state.downloading`)})}),P(ZA,{open:!!f,children:V(`p`,{className:`mc-warn${l?` is-big`:``}`,role:`note`,id:`${c}-warn`,children:[P(J,{size:13,"aria-hidden":`true`}),P(`span`,{children:f})]})})]})}function Pj({plan:e,selection:t}){let n=T(),{downloadGb:r,freeGb:i,afterGb:a}=yj(e,t),o=bj(e,t),s=qA(r??0),c=qA(a??0),l=Fj(e.disk?.path??null),u=r!=null&&i?Math.min(1,r/i):0,d=JA(r==null?n(`setup.summary.spokenUnknown`):a==null?n(`setup.summary.spokenNoDisk`,{download:$(r)}):n(`setup.summary.spoken`,{download:$(r),after:$(Math.max(0,a))}),600);return V(`div`,{className:`mc-summary${o?` is-warn`:``}`,role:`group`,"aria-label":n(`setup.summary.label`),children:[V(`div`,{className:`mc-summary-stats`,children:[V(`span`,{className:`mc-stat`,children:[P(`span`,{className:`mc-stat-label`,children:n(`setup.summary.download`)}),P(`bdi`,{className:`mc-stat-value`,children:r==null?n(`setup.summary.sizeUnknown`):$(Ij(s))})]}),V(`span`,{className:`mc-stat`,children:[V(`span`,{className:`mc-stat-label`,children:[P(Ii,{size:12,"aria-hidden":`true`}),` `,l?n(`setup.summary.freeOn`,{drive:l}):n(`setup.summary.free`)]}),P(`bdi`,{className:`mc-stat-value`,children:i==null?n(`setup.summary.freeUnknown`):$(i)})]}),a!=null&&!o&&V(`span`,{className:`mc-stat`,children:[P(`span`,{className:`mc-stat-label`,children:n(`setup.summary.after`)}),P(`bdi`,{className:`mc-stat-value`,children:$(Math.max(0,Ij(c)))})]})]}),i!=null&&P(`div`,{className:`mc-disk`,"aria-hidden":`true`,children:P(`span`,{className:`mc-disk-fill`,style:{inlineSize:`${(u*100).toFixed(1)}%`}})}),P(ZA,{open:!!o,children:o&&V(`p`,{className:`mc-disk-warn`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),P(`span`,{children:o.drop?n(`setup.summary.shortDrop`,{need:$(o.needGb),free:$(o.freeGb),drive:l??n(`setup.summary.theDrive`),freeUp:$(o.freeUpGb),name:o.drop.name,saves:$(o.drop.size_gb??0)}):n(`setup.summary.short`,{need:$(o.needGb),free:$(o.freeGb),drive:l??n(`setup.summary.theDrive`),freeUp:$(o.freeUpGb)})})]})}),P(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:d})]})}function Fj(e){if(!e)return null;let t=/^([A-Za-z]:)[\\/]/.exec(e);return t?t[1]:e}function Ij(e){return Math.round(e*10)/10}function Lj({plan:e,selection:t,onToggle:n,onDefaultChat:r,labelledBy:i,cloud:a,disabled:o,progress:s,rowActions:c,place:l=`setup`}){let u=T(),d=QA(e),[f,p]=(0,X.useState)(``),m=(0,X.useId)(),h=a?d.filter(ej):uj(d),g=a?[]:dj(d),_=a?[]:fj(d),v=(0,X.useMemo)(()=>{let e=f.trim().toLowerCase();return e?_.filter(t=>t.id.toLowerCase().includes(e)||t.name.toLowerCase().includes(e)):_},[_,f]),y=mj(d,t.ticked),b=e=>P(Nj,{entry:e,ticked:t.ticked.has(e.id),onToggle:t=>n(e.id,t),disabled:o,progress:s?.[e.id],actions:c?.(e),place:l},e.id);return V(`div`,{className:`mc`,children:[P(`ul`,{className:`mc-list`,role:`group`,"aria-labelledby":i,children:h.map(b)}),a?P(`p`,{className:`setup-hint`,children:u(`setup.models.cloudNote`)}):P(`p`,{className:`mc-foot`,children:u(`setup.models.neverDeletes`)}),g.length>0&&V(`details`,{className:`mc-more`,children:[P(`summary`,{children:u(`setup.models.more`,{n:String(g.length)})}),P(`ul`,{className:`mc-list`,role:`group`,"aria-label":u(`setup.models.moreLabel`),children:g.map(b)})]}),_.length>0&&V(`details`,{className:`mc-more`,children:[P(`summary`,{children:u(`setup.models.installed`,{n:String(_.length)})}),_.length>Ej&&P(`input`,{className:`settings-input mc-search`,type:`search`,value:f,onChange:e=>p(e.target.value),placeholder:u(`setup.models.search`),"aria-label":u(`setup.models.search`)}),P(`ul`,{className:`mc-list`,role:`radiogroup`,"aria-label":u(`setup.models.installedLabel`),children:v.map(e=>P(`li`,{className:`mc-row is-installed${t.defaultChat===e.id?` is-ticked`:``}`,children:V(`label`,{className:`mc-row-main`,children:[P(`input`,{type:`radio`,name:`${m}-installed`,className:`mc-radio`,checked:t.defaultChat===e.id,disabled:o,onChange:()=>r(e.id)}),V(`span`,{className:`mc-text`,children:[V(`span`,{className:`mc-name-line`,children:[P(`bdi`,{className:`mc-name`,title:e.id,children:e.name}),V(`span`,{className:`mc-chips`,children:[P(`span`,{className:`mc-chip`,children:u(`setup.models.purpose.chat`)}),tj(e)&&P(`span`,{className:`mc-chip is-npu`,children:u(`setup.models.npu`)})]})]}),V(`span`,{className:`mc-status`,children:[u(`setup.models.status.onPc`),` · `,u(`setup.models.useAsDefault`)]})]})]})},e.id))})]}),!a&&V(`div`,{className:`mc-default`,children:[P(`label`,{htmlFor:m,className:`mc-default-label`,children:u(`setup.models.defaultChat`)}),V(`select`,{id:m,className:`settings-input mc-select`,value:t.defaultChat??``,disabled:o||y.length===0,onChange:e=>r(e.target.value),children:[y.length===0&&P(`option`,{value:``,children:u.bare(`setup.models.noChat`)}),y.map(e=>V(`option`,{value:e.id,children:[e.name,tj(e)?` (${u(`setup.models.npu`)})`:``]},e.id))]})]})]})}function Rj(){let e=T();return V(`div`,{className:`mc`,"aria-busy":`true`,children:[V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,e(`setup.models.loading`)]}),P(`ul`,{className:`mc-list`,"aria-hidden":`true`,children:[0,1,2].map(e=>P(`li`,{className:`mc-row is-skeleton`,children:P(`span`,{className:`mc-skeleton`})},e))})]})}function zj({entry:e}){let t=T();return e.support===`verified`?P(`span`,{className:`mc-chip is-verified`,children:t(`setup.label.verified`)}):e.support===`untested`?P(`span`,{className:`mc-chip is-untested`,children:t(`setup.label.untested`)}):null}function Bj({name:e,entry:t,checked:n,recommended:r,disabled:i,onPick:a,children:o}){let s=T();return P(`li`,{className:`mc-row${n?` is-ticked`:``}`,children:V(`label`,{className:`mc-row-main`,children:[P(`input`,{type:`radio`,className:`mc-radio`,name:e,checked:n,disabled:i||nj(t),onChange:a}),V(`span`,{className:`mc-text`,children:[V(`span`,{className:`mc-name-line`,children:[P(`span`,{className:`mc-name`,title:t.id,children:P(`bdi`,{children:t.name})}),V(`span`,{className:`mc-chips`,children:[r&&P(`span`,{className:`mc-pill`,children:s(`setup.models.recommended`)}),P(zj,{entry:t}),tj(t)&&P(`bdi`,{className:`mc-chip is-npu`,children:s(`setup.models.npu`)})]})]}),P(`span`,{className:`mc-status`,children:kj(t,s)}),t.fits===!1&&V(`span`,{className:`mc-warn is-big`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,jj(t,s)]}),o]})]})})}function Vj({label:e,note:t,size:n,checked:r,disabled:i,warning:a,chips:o,onChange:s}){return P(`li`,{className:`mc-row${r?` is-ticked`:``}${i?` is-off`:``}`,children:V(`label`,{className:`mc-row-main`,children:[P(`input`,{type:`checkbox`,className:`mc-input`,checked:r,disabled:i,onChange:e=>s(e.target.checked)}),P(`span`,{className:`mc-box`,"aria-hidden":`true`,children:P(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,children:P(`path`,{className:`mc-tick`,d:`M3.5 8.5l3 3 6-7`})})}),V(`span`,{className:`mc-text`,children:[V(`span`,{className:`mc-name-line`,children:[P(`span`,{className:`mc-name`,children:P(`bdi`,{children:e})}),P(`span`,{className:`mc-chips`,children:o})]}),P(`span`,{className:`mc-status`,children:P(`bdi`,{dir:`ltr`,children:n})}),P(`span`,{className:`mc-note`,children:t}),a&&V(`span`,{className:`mc-warn`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,a]})]})]})})}function Hj({plan:e,selection:t,onSelection:n,disabled:r}){let i=T(),a=(0,X.useId)(),o=QA(e),[s,c]=(0,X.useState)(!1),l=o.find(e=>e.id===t.defaultChat),u=!!l&&tj(l),d=o.filter(e=>e.chat_choice&&!ej(e)&&(e.gaia_model||e.downloaded)&&tj(e)===u),f=d.filter(e=>e.support===`verified`),p=d.filter(e=>e.support!==`verified`),m=aj(o,t),h=!!l?.reads_images,g=o.filter(e=>$A(e)&&e.id!==l?.id),_=o.find(ej),v=e=>o.find(t=>rj(t)&&t.roles.includes(e)),y=e=>e.downloaded?i(`setup.models.status.onPc`):e.size_gb==null?i(`setup.contents.sizeOnDownload`):$(e.size_gb),b=(e,r)=>n(hj(t,o,e,r)),x=e=>n(sj(t,o,e)),S=e=>n(cj(t,o,e)),C=v(`speech`),w=v(`voice`),E=v(`image_creation`),O=ij(l),k=l?.support===`untested`;return V(`div`,{className:`mc`,children:[V(`section`,{className:`mc-job`,"aria-labelledby":`${a}-chat`,children:[P(`h3`,{className:`mc-job-title`,id:`${a}-chat`,children:i(`setup.job.chat`)}),P(`p`,{className:`setup-hint`,children:i(`setup.job.verifiedNote`)}),P(`ul`,{className:`mc-list`,role:`radiogroup`,"aria-labelledby":`${a}-chat`,children:f.map(n=>P(Bj,{name:`${a}-chat-model`,entry:n,checked:n.id===t.defaultChat,recommended:n.id===e.recommended_model,disabled:r,onPick:()=>x(n.id)},n.id))}),p.length>0&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:i(`setup.job.untestedNote`)}),P(`ul`,{className:`mc-list`,role:`radiogroup`,"aria-labelledby":`${a}-chat`,children:p.map(e=>P(Bj,{name:`${a}-chat-model`,entry:e,checked:e.id===t.defaultChat,recommended:!1,disabled:r,onPick:()=>x(e.id)},e.id))})]}),k&&V(`p`,{className:`mc-warn`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,i(`setup.job.untestedPicked`)]})]}),V(`section`,{className:`mc-job`,"aria-labelledby":`${a}-vision`,children:[P(`h3`,{className:`mc-job-title`,id:`${a}-vision`,children:i(`setup.job.vision`)}),u?P(`p`,{className:`setup-hint`,role:`note`,children:i(`setup.job.visionOffNpu`,{name:l?.name??``})}):h?V(`div`,{className:`setup-card`,children:[V(`p`,{className:`mc-job-line`,children:[P(`bdi`,{children:i(`setup.job.visionBuiltIn`,{name:l?.name??``})}),P(`span`,{className:`setup-ok`,children:i(`setup.job.nothingMore`)})]}),P(`button`,{type:`button`,className:`link-btn`,"aria-expanded":s,onClick:()=>c(e=>!e),children:i(s?`setup.job.hideVision`:`setup.job.otherVision`)})]}):P(`p`,{className:`setup-hint`,children:i(`setup.job.visionNeeded`,{name:l?.name??``})}),!u&&(!h||s)&&V(`ul`,{className:`mc-list`,role:`radiogroup`,"aria-labelledby":`${a}-vision`,children:[g.map(e=>P(Bj,{name:`${a}-vision-model`,entry:e,checked:m===e.id,recommended:!h&&e.gaia_model&&e.support===`verified`,disabled:r,onPick:()=>S(e.id)},e.id)),P(`li`,{className:`mc-row${m===null?` is-ticked`:``}`,children:V(`label`,{className:`mc-row-main`,children:[P(`input`,{type:`radio`,className:`mc-radio`,name:`${a}-vision-model`,checked:h?m===l?.id:m===null,disabled:r,onChange:()=>S(h?null:`none`)}),V(`span`,{className:`mc-text`,children:[P(`span`,{className:`mc-name`,children:i(h?`setup.job.useChatForVision`:`setup.job.skipVision`)}),m===null&&!h&&V(`span`,{className:`mc-warn`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,i(`setup.job.skipVisionNote`)]})]})]})})]})]}),_&&V(`section`,{className:`mc-job`,"aria-labelledby":`${a}-docs`,children:[P(`h3`,{className:`mc-job-title`,id:`${a}-docs`,children:i(`setup.job.documents`)}),P(`ul`,{className:`mc-list`,children:P(Vj,{label:_.name,note:i(`setup.models.line.documents`),size:y(_),checked:t.ticked.has(_.id),disabled:r,warning:t.ticked.has(_.id)?null:i(`setup.job.documentsOff`),chips:V(D.Fragment,{children:[P(`span`,{className:`mc-pill`,children:i(`setup.models.recommended`)}),P(zj,{entry:_})]}),onChange:e=>b(_.id,e)})})]}),V(`section`,{className:`mc-job`,"aria-labelledby":`${a}-extras`,children:[P(`h3`,{className:`mc-job-title`,id:`${a}-extras`,children:i(`setup.job.extras`)}),P(`p`,{className:`setup-hint`,children:i(`setup.job.extrasNote`)}),V(`ul`,{className:`mc-list`,children:[C&&P(Vj,{label:i(`setup.job.speech`),note:i(`setup.job.speechNote`),size:y(C),checked:t.ticked.has(C.id),disabled:r,onChange:e=>b(C.id,e)}),w&&P(Vj,{label:i(`setup.job.voice`),note:i(`setup.job.voiceNote`),size:y(w),checked:t.ticked.has(w.id),disabled:r,onChange:e=>b(w.id,e)}),E&&P(Vj,{label:i(`setup.job.images`),note:i(`setup.job.imagesNote`),size:y(E),checked:t.ticked.has(E.id),disabled:r||!O,warning:O?null:i(`setup.job.imagesBlocked`,{name:l?.name??``}),onChange:e=>b(E.id,e)})]})]}),P(Uj,{plan:e,selection:t})]})}function Uj({plan:e,selection:t}){let n=T(),r=QA(e),i=e=>r.find(t=>t.id===e)?.name??e??n(`setup.get.off`),a=e=>r.find(n=>rj(n)&&n.roles.includes(e)&&t.ticked.has(n.id)),o=r.find(e=>ej(e)&&t.ticked.has(e.id)),s=r.find(e=>e.id===t.defaultChat),c=aj(r,t),l=[a(`speech`)&&n(`setup.job.speech`),a(`voice`)&&n(`setup.job.voice`)].filter(Boolean).join(`, `);return V(`section`,{className:`setup-card`,"aria-label":n(`setup.get.title`),children:[P(`h3`,{className:`mc-job-title`,children:n(`setup.get.title`)}),V(`dl`,{className:`setup-summary-list`,children:[V(`div`,{children:[P(`dt`,{children:n(`setup.job.chat`)}),P(`dd`,{children:P(`bdi`,{children:i(t.defaultChat)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.job.vision`)}),P(`dd`,{children:P(`bdi`,{children:s&&tj(s)?n(`setup.get.offNpu`):c?i(c):n(`setup.get.off`)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.job.documents`)}),P(`dd`,{children:P(`bdi`,{children:o?o.name:n(`setup.get.off`)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.get.voice`)}),P(`dd`,{children:l||n(`setup.get.off`)})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.job.images`)}),P(`dd`,{children:ij(s)?a(`image_creation`)?n(`setup.get.on`):n(`setup.get.off`):n(`setup.get.notAvailable`)})]})]})]})}var Wj=(0,X.createContext)(void 0),Gj=Wj.Provider;function Kj({children:e}){let t=(0,X.useContext)(Wj);return t===void 0?P(`div`,{className:`setup-row setup-nav`,children:e}):t===null?null:(0,eS.createPortal)(P(`div`,{className:`setup-footer-row`,children:e}),t)}function qj({title:e,children:t,confirmLabel:n,cancelLabel:r,onConfirm:i,onCancel:a,danger:o,busy:s}){let c=(0,X.useRef)(null),l=(0,X.useRef)(null),u=(0,X.useId)(),d=(0,X.useId)();return sS(c,!0),(0,X.useEffect)(()=>{let e=document.activeElement;return l.current?.focus(),()=>e?.focus?.()},[]),Io(!0,a,!s),(0,eS.createPortal)(P(`div`,{className:`confirm-overlay`,children:V(`div`,{ref:c,className:`confirm-sheet`,role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":u,"aria-describedby":t?d:void 0,children:[P(`h2`,{id:u,className:`confirm-title`,children:e}),t&&P(`div`,{id:d,className:`confirm-body`,children:t}),V(`div`,{className:`confirm-actions`,children:[P(`button`,{ref:l,type:`button`,className:`btn-secondary`,onClick:a,disabled:s,children:r}),P(`button`,{type:`button`,className:o?`btn-danger`:`btn-primary`,onClick:i,disabled:s,children:n})]})]})}),document.body)}function Jj(e){return e===`windows`?`Windows`:e===`linux`?`Linux`:e}function Yj(e){let t=/^Run:\s*(.+)$/.exec(e)??/^(sudo .+)$/.exec(e);return t?t[1].trim():null}function Xj(e,t){return e.setting&&Math.abs(e.setting.current_gb-t)<.05&&e.gpu_gb!=null?e.gpu_gb:e.presets?.find(e=>Math.abs(e.setting_gb-t)<.05)?.gpu_gb??null}function Zj(e,t,n=!1){return t==null?e(n?`gpu.appliedAny`:`gpu.pending.restartAny`):e(n?`gpu.applied`:`gpu.pending.restart`,{gb:$(t)})}function Qj(e){e.focus({preventScroll:!0});for(let t=e.parentElement;t;t=t.parentElement){let n=getComputedStyle(t).overflowY;if(n!==`auto`&&n!==`scroll`)continue;let r=e.getBoundingClientRect().top-t.getBoundingClientRect().top;(r<0||r>t.clientHeight-40)&&(t.scrollTop+=r-16);return}}function $j(e){return e instanceof Error?e.message:String(e)}function eM({status:e,targetGpuGb:t}){let n=T(),r=e=>Math.round(e*10),i=r(e.total_gb??0),a=r(e.gpu_gb??0),o=t!=null&&r(t)>a?r(t):null,s=o==null?0:o-a,c=Math.max(0,i-a-s),l=e=>$(e/10),u=e=>i>0?Math.min(100,e/i*100):0,d=e.pending?.state===`took_effect`;return V(`div`,{className:`gpu-split`,children:[V(`div`,{className:`gpu-bar${d?` is-new`:``}`,role:`img`,"aria-label":o==null?n(`gpu.split.aria`,{cpu:l(c),gpu:l(a)}):n(`gpu.split.ariaTarget`,{cpu:l(c),gpu:l(o),now:l(a)}),children:[P(`span`,{className:`gpu-seg is-gpu`,style:{inlineSize:`${u(a)}%`}}),P(`span`,{className:`gpu-seg is-target`,style:{inlineSize:`${u(s)}%`}}),P(`span`,{className:`gpu-seg is-cpu`}),o!=null&&P(`span`,{className:`gpu-marker`,style:{insetInlineStart:`${u(o)}%`}})]}),V(`div`,{className:`gpu-legend`,"aria-hidden":`true`,children:[P(`span`,{className:`gpu-key is-gpu`,children:P(`bdi`,{children:n(`gpu.split.gpu`,{gb:l(a)})})}),o!=null&&P(`span`,{className:`gpu-key is-target`,children:P(`bdi`,{children:n(`gpu.split.added`,{gb:l(s)})})}),P(`span`,{className:`gpu-key is-cpu`,children:P(`bdi`,{children:n(`gpu.split.cpu`,{gb:l(c)})})})]})]})}function tM({presets:e,value:t,onChange:n,recommended:r,max:i,disabled:a}){let o=T(),s=(0,X.useRef)([]),c=Math.max(0,e.findIndex(e=>e.setting_gb===t));return P(`div`,{className:`gpu-presets`,role:`radiogroup`,"aria-label":o(`gpu.presets.label`),onKeyDown:t=>{let r=t.key===`ArrowRight`||t.key===`ArrowDown`?1:t.key===`ArrowLeft`||t.key===`ArrowUp`?-1:0;if(!r)return;t.preventDefault();let i=getComputedStyle(t.currentTarget).direction===`rtl`,a=(t.key===`ArrowRight`||t.key===`ArrowLeft`)&&i?-r:r,o=(c+a+e.length)%e.length;n(e[o].setting_gb),s.current[o]?.focus()},children:e.map((e,l)=>V(`button`,{ref:e=>{s.current[l]=e},type:`button`,role:`radio`,"aria-checked":e.setting_gb===t,tabIndex:l===c?0:-1,className:`gpu-preset${e.setting_gb===t?` is-active`:``}`,disabled:a,onClick:()=>n(e.setting_gb),children:[P(`bdi`,{children:o(`gpu.presets.gpu`,{gb:$(e.gpu_gb)})}),e.setting_gb===r&&V(D.Fragment,{children:[` `,P(`span`,{className:`gpu-tag is-recommended`,children:o(`gpu.presets.recommended`)})]}),e.setting_gb===i&&V(D.Fragment,{children:[` `,P(`span`,{className:`gpu-tag is-max`,children:o(`gpu.presets.max`)})]})]},e.setting_gb))})}function nM({status:e,onStatus:t,mode:n,names:r,onSkip:i,onContinue:a,onBack:o,headingId:s}){let c=T(),l=(0,X.useCallback)(()=>{let e=s?document.getElementById(s):null;e&&Qj(e)},[s]);(0,X.useEffect)(()=>{n===`setup`&&l()},[n,l]);let u=(0,X.useId)(),d=e.presets??[],[f,p]=(0,X.useState)(e.recommended_setting_gb??d[0]?.setting_gb??null),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(void 0),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),[O,k]=(0,X.useState)(null),A=d.find(e=>e.setting_gb===f)??null,j=e.recommended_setting_gb??null,M=d.length>0&&d[d.length-1].setting_gb===e.setting?.max_gb?d[d.length-1].setting_gb:null,N=A&&e.total_gb!=null?Math.max(0,e.total_gb-A.gpu_gb):null,F=j==null?(e.models??[]).find(e=>e.default&&e.fits_now):void 0,I=(A?.unlocks??[]).slice(0,2).map(e=>r[e]??e),L=e.pending??null,ee=e.method===`apply`,R=e.guided_value!==null,z=(0,X.useCallback)(async()=>{h(!0),_(null),C(`steps`),E(null);try{let e=await Nn(f??void 0);y(e.guided_value),_(e.guided_value===null?[]:e.guided_steps??[])}catch(e){y(void 0),_([]),E({kind:`error`,message:$j(e)})}finally{C(null)}},[f]),B=async()=>{if(f!=null){x(null),C(`apply`),E(null);try{t(await qt(f)),E({kind:`applied`})}catch(e){let t=e instanceof yn&&e.httpStatus===403;E(t?{kind:`denied`}:{kind:`error`,message:$j(e)}),t&&l()}finally{C(null)}}},te=async()=>{x(null),C(`revert`),E(null);try{t(await Oe()),E({kind:`applied`})}catch(e){E(e instanceof yn&&e.httpStatus===403?{kind:`denied`}:{kind:`error`,message:$j(e)})}finally{C(null)}},ne=async()=>{if(f!=null){C(`done`),E(null);try{t(await je(f)),h(!1)}catch(e){E({kind:`error`,message:$j(e)})}finally{C(null)}}},re=async()=>{C(`keep`),E(null);try{t(await ve())}catch(e){E({kind:`error`,message:$j(e)})}finally{C(null)}},ie=async e=>{try{await navigator.clipboard.writeText(e),k(e)}catch(e){E({kind:`error`,message:c(`gpu.copyFailed`,{reason:$j(e)})})}},ae=L?.state===`restart_required`;return V(`div`,{className:`gpu`,children:[P(`p`,{className:`setup-hint`,children:c(`gpu.body`,{total:$(e.total_gb??0),gpu:$(e.gpu_gb??0)})}),P(eM,{status:e,targetGpuGb:!ae&&!m?A?.gpu_gb??null:null}),L?.state===`took_effect`&&V(`div`,{className:`gpu-notice is-ok`,role:`status`,children:[P(mr,{size:14,"aria-hidden":`true`}),P(`span`,{children:c(`gpu.pending.tookEffect`,{gb:$(e.gpu_gb??0)})}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void re(),disabled:S!==null,children:c(`gpu.ok`)})]}),ae&&V(`div`,{className:`gpu-notice`,role:`status`,children:[P(Hi,{size:14,"aria-hidden":`true`}),P(`span`,{children:c.compose(t=>[Zj(t,Xj(e,L.setting_gb),w?.kind===`applied`),t(`gpu.pending.restartHow`),n===`setup`?t(`gpu.pending.downloadsFirst`):null].filter(Boolean).join(` `))}),L.source===`guided`&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void re(),disabled:S!==null,children:c(`gpu.keep`,{gb:$(e.gpu_gb??0)})})]}),L?.state===`not_applied`&&V(`div`,{className:`gpu-notice is-warn`,role:`status`,children:[P(J,{size:14,"aria-hidden":`true`}),P(`span`,{children:c(`gpu.pending.notApplied`,{gb:$(e.gpu_gb??0)})}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void re(),disabled:S!==null,children:c(`gpu.keep`,{gb:$(e.gpu_gb??0)})})]}),!ae&&!m&&d.length>0&&V(D.Fragment,{children:[F&&V(`p`,{className:`gpu-unlock is-keep`,children:[P(mr,{size:13,"aria-hidden":`true`}),` `,c(`gpu.keepRecommended`,{model:r[F.id]??F.id})]}),P(tM,{presets:d,value:f,onChange:p,recommended:j,max:M,disabled:S!==null}),A&&P(`p`,{className:`gpu-unlock`,children:I.length>0?c(I.length>1?`gpu.unlock.two`:`gpu.unlock.one`,{gb:$(A.gpu_gb),a:I[0],b:I[1]??``}):c(`gpu.unlock.none`,{gb:$(A.gpu_gb)})}),A&&A.setting_gb===M&&N!=null&&V(`p`,{className:`gpu-unlock is-warn`,role:`note`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,c(`gpu.maxWarn`,{cpu:$(N),os:Jj(e.os)})]}),P(`p`,{className:`setup-hint`,children:c.compose(t=>`${t(`gpu.reserve`,{gb:$(e.reserve_gb??16),os:Jj(e.os)})} ${t(`gpu.needs`)}`)}),!ee&&e.method_reason&&P(`p`,{className:`setup-hint`,children:P(`bdi`,{dir:`ltr`,children:e.method_reason})})]}),!ae&&!m&&d.length===0&&P(`p`,{className:`setup-hint`,children:c(`gpu.noPresets`)}),m&&V(`div`,{className:`gpu-guided`,children:[A&&P(`p`,{className:`setup-hint`,id:u,children:c(`gpu.guided.lede`,{gb:$(A.gpu_gb)})}),g===null?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,c(`gpu.guided.loading`)]}):v===null?P(`p`,{className:`setup-hint`,children:c(`gpu.noPresets`)}):P(`ol`,{className:`gpu-steps`,"aria-labelledby":u,children:g.map(e=>{let t=Yj(e);return V(`li`,{children:[P(`span`,{children:e}),t&&V(`button`,{type:`button`,className:`btn-secondary gpu-copy`,onClick:()=>void ie(t),"aria-label":c(`gpu.copyAria`,{what:t}),children:[P(O===t?mr:Br,{size:12,"aria-hidden":`true`}),c(O===t?`gpu.copied`:`gpu.copy`)]})]},e)})}),V(Kj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>h(!1),disabled:S!==null,children:c(`gpu.guided.back`)}),!ee&&v!==null&&V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void ne(),disabled:S!==null||f==null,children:[S===`done`&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,c(`gpu.guided.done`)]})]})]}),S===`apply`||S===`revert`?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,c(`gpu.waiting`)]}):null,w?.kind===`denied`&&V(`div`,{className:`gpu-notice is-warn`,role:`alert`,children:[P(J,{size:14,"aria-hidden":`true`}),P(`span`,{children:c(`gpu.denied`)})]}),w?.kind===`error`&&P(`p`,{className:`setup-error`,role:`alert`,children:w.message}),!m&&(()=>{let t=!ae&&ee&&d.length>0&&P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>x(`apply`),disabled:S!==null||f==null,children:w?.kind===`denied`||L?.state===`not_applied`?c(`gpu.tryAgain`):c(`gpu.apply`)}),r=!ae&&d.length>0&&R&&P(`button`,{type:`button`,className:ee?`btn-secondary`:`btn-primary`,onClick:()=>void z(),disabled:S!==null,children:c(`gpu.showMe`)});return n===`setup`?V(Kj,{children:[o&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:o,children:c(`setup.back`)}),ae?a&&P(`button`,{type:`button`,className:`btn-primary`,onClick:a,autoFocus:!0,children:c(`setup.continue`)}):V(D.Fragment,{children:[i&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:i,disabled:S!==null,children:c(`gpu.skip`)}),ee?V(D.Fragment,{children:[r,t]}):r]})]}):V(`div`,{className:`setup-row gpu-actions`,children:[t,r,e.revert?.available&&V(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>x(`revert`),disabled:S!==null,children:[P(La,{size:13,"aria-hidden":`true`}),` `,c(`gpu.undo`)]})]})})(),b===`apply`&&f!=null&&V(qj,{title:A?c(`gpu.consent.title`,{gb:$(A.gpu_gb)}):c(`gpu.consent.titleAny`),confirmLabel:c(`setup.continue`),cancelLabel:c(`setup.cancel`),onConfirm:()=>void B(),onCancel:()=>x(null),children:[P(`p`,{children:A?c(`gpu.consent.body`,{name:e.setting?.name??``,gb:$(A.gpu_gb)}):c(`gpu.consent.bodyAny`,{name:e.setting?.name??``})}),P(`p`,{className:`confirm-note`,children:c(`gpu.consent.saved`,{gb:$(e.gpu_gb??0)})})]}),b===`revert`&&P(qj,{title:c(`gpu.revert.title`),confirmLabel:c(`setup.continue`),cancelLabel:c(`setup.cancel`),onConfirm:()=>void te(),onCancel:()=>x(null),children:P(`p`,{children:c(`gpu.revert.body`)})})]})}function rM({plan:e,planError:t,onRetryPlan:n,onUseRecommended:r,selection:i,onSelection:a,cloud:o,keepTrying:s,onKeepTrying:c,onBack:l,onContinue:u,busy:d,error:f}){let p=T(),m=(0,X.useRef)(null),[h,g]=(0,X.useState)(!1),_=!!e&&!!i&&!!e.catalog,v=(0,X.useRef)(null);if(_&&v.current===null&&(v.current=!o&&vj(QA(e),i).length===0&&!!i.defaultChat&&QA(e).some(e=>e.downloaded)),(0,X.useEffect)(()=>{_&&m.current?.querySelector(`input:not([disabled])`)?.focus()},[_,h]),t&&!_)return V(`div`,{className:`setup-models-error`,children:[P(`p`,{className:`setup-error`,role:`alert`,children:p(`setup.models.listFailed`,{reason:t})}),V(`div`,{className:`setup-row`,children:[P(`button`,{type:`button`,className:`btn-primary`,onClick:n,children:p(`setup.tryAgain`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:r,children:p(`setup.models.useRecommended`)})]}),P(`p`,{className:`setup-hint`,children:p(`setup.models.useRecommendedNote`)})]});if(!_)return P(Rj,{});let y=QA(e),b=vj(y,i),x=!o&&!i.defaultChat,S=bj(e,i),C=o?[]:y.filter(e=>e.fits===!1&&i.ticked.has(e.id)),w=!h&&!!v.current&&b.length===0,E=p(S?`setup.continueAnyway`:`setup.continue`);return w?V(`div`,{className:`setup-present`,role:`status`,children:[V(`p`,{children:[P(mr,{size:14,"aria-hidden":`true`}),` `,p(`setup.models.allPresent`)]}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>g(!0),children:p(`setup.models.change`)}),V(Kj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:l,disabled:d,children:p(`setup.back`)}),V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>u(!1),disabled:d,children:[d&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,p(`setup.finish`)]})]}),f&&P(`p`,{className:`setup-error`,role:`alert`,children:f})]}):V(`div`,{className:`setup-models`,ref:m,children:[P(`p`,{className:`setup-hint`,children:p(`setup.job.lede`)}),P(Hj,{plan:e,selection:i,onSelection:a,disabled:d}),!o&&P(`button`,{type:`button`,className:`link-btn setup-reset`,onClick:()=>a(_j(e)),disabled:d,children:p(`setup.models.resetRecommended`)}),V(`div`,{className:`setup-models-footer`,children:[P(Pj,{plan:e,selection:i}),V(`label`,{className:`setup-keep-trying`,children:[P(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),disabled:d}),P(`span`,{children:p(`setup.keepTrying`)})]}),P(ZA,{open:x,children:P(`p`,{className:`setup-error`,id:`setup-no-chat`,children:p(`setup.models.noChatReason`)})}),C.length>0&&P(`span`,{className:`visually-hidden`,children:C.map(e=>jj(e,p)).join(` `)}),f&&P(`p`,{className:`setup-error`,role:`alert`,children:f}),V(Kj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:l,disabled:d,children:p(`setup.back`)}),V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>u(!!S),disabled:d||x,"aria-describedby":x?`setup-no-chat`:void 0,children:[d&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,E]})]})]})]})}function iM({plan:e,chatModel:t,gpu:n}){let r=T();if(!e?.catalog)return null;let i=e.catalog,a=e=>e?i.find(t=>t.id===e)?.name??e:null,o=aj(i,{ticked:new Set,unticked:new Set,chatChosen:!1,defaultChat:t,vision:e.vision_model??null}),s=i.find(e=>e.id===o)??i.find(e=>$A(e)&&e.gaia_model),c=i.find(e=>ej(e)&&e.downloaded),l=i.filter(e=>e.gaia_model&&e.planned&&e.skipped),u=n?.pending,d=i.find(e=>e.id===t);return V(`dl`,{className:`setup-summary-list`,children:[t&&V(`div`,{children:[P(`dt`,{children:r(`setup.ready.chat`)}),V(`dd`,{children:[P(`bdi`,{children:a(t)}),d?.recipe===`flm`?` (${r(`setup.models.npu`)})`:``]})]}),V(`div`,{children:[P(`dt`,{children:r(`setup.ready.vision`)}),P(`dd`,{children:s?.downloaded?P(`bdi`,{children:s.name}):r(`setup.ready.visionOff`,{name:s?.name??`Gemma-4-E4B-it`})})]}),c&&V(`div`,{children:[P(`dt`,{children:r(`setup.ready.documents`)}),P(`dd`,{children:P(`bdi`,{children:c.name})})]}),l.length>0&&V(`div`,{children:[P(`dt`,{children:r(`setup.ready.notInstalled`)}),P(`dd`,{children:l.map(e=>e.name).join(`, `)})]}),u?.state===`restart_required`&&V(`div`,{className:`is-warn`,children:[P(`dt`,{children:r(`setup.ready.gpu`)}),V(`dd`,{children:[P(J,{size:13,"aria-hidden":`true`}),` `,Zj(r,n?Xj(n,u.setting_gb):null)]})]}),u?.state===`took_effect`&&V(`div`,{children:[P(`dt`,{children:r(`setup.ready.gpu`)}),P(`dd`,{children:n?.gpu_gb==null?r(`setup.ready.gpuChanged`):r(`setup.ready.gpuNow`,{gb:$(n.gpu_gb)})})]})]})}function aM(e){if(e.skill===`document-brief`){let t=/^(\d+) /.exec(e.note)?.[1];return t?{n:Number(t)}:void 0}if(e.skill===`coding`){let t=/^In (.+)$/.exec(e.note)?.[1];return t?{folder:t}:void 0}}function oM(e,t,n,r){let i=`${n}.one`,a=`${n}.other`,o=N(i)&&N(a)&&typeof r?.n==`number`?r.n===1?i:a:n;return!N(o)||c[o].includes(`{`)&&!r?t:z(o,r)===t?e(o,r):t}function sM(e,t){return{title:oM(t,e.title,`card.${e.skill}.title`),note:oM(t,e.note,`card.${e.skill}.note`,aM(e))}}function cM({text:e}){let t=o(e);return t.length===1?P(D.Fragment,{children:e}):P(D.Fragment,{children:t.map((e,t)=>P(`span`,{className:`start-card-part`,children:e},t))})}function lM({cards:e,onPick:t,disabled:n}){let r=T();return e.length===0?null:P(`ul`,{className:`start-cards`,"aria-label":r(`newChat.cardsLabel`),children:e.map(e=>{let{title:i,note:a}=sM(e,r);return P(`li`,{children:V(`button`,{type:`button`,className:`start-card`,onClick:()=>t(e),disabled:n,title:e.needs_input?`${e.prompt}…`:e.prompt,children:[V(`span`,{className:`start-card-title`,children:[i,P(Jn,{size:13,"aria-hidden":`true`})]}),P(`span`,{className:`start-card-note`,children:P(cM,{text:a})})]})},e.skill)})})}function uM(){let[e,t]=(0,X.useState)(null),[n,r]=(0,X.useState)([]),i=(0,X.useCallback)(()=>{Promise.resolve(Tn()).then(e=>{t(e?.providers?.find(e=>e.id===`amd`)?.network??null),r(e?.providers??[])}).catch(e=>{console.warn(`[useGatewayNetwork] could not check the AMD gateway`,e),t(null)})},[]);return(0,X.useEffect)(i,[i]),{network:e,providers:n,recheck:i}}function dM(e,t,n){return t===`active`?n(`setup.contents.working`):t===`done`?n(`setup.contents.ready`):t===`failed`?n(`setup.contents.failed`):e.installed?n(`setup.contents.alreadyHere`):n(`setup.contents.waiting`)}function fM(e,t){return e==null?t(`setup.contents.sizeOnDownload`):$(e)}function pM({state:e}){return e===`done`?P(mr,{size:13,"aria-hidden":`true`}):e===`active`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):P(e===`failed`?Y:Mr,{size:13,"aria-hidden":`true`})}function mM({id:e,error:t,transient:n,onRetry:r,disabled:i}){let a=T(),o=a(`setup.component.${e}`);return V(`div`,{className:`setup-content-failure`,role:`alert`,children:[P(`p`,{children:a(n?`setup.contents.failedNetwork`:`setup.contents.failedOther`,{name:o})}),t&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:a(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:t})]}),r&&P(`button`,{type:`button`,className:`btn-primary`,onClick:r,disabled:i,"aria-label":a(`setup.contents.retryNamed`,{name:o}),children:a(`setup.progress.retry`)})]})}function hM({plan:e,run:t,models:n=[],onRetry:r,retryDisabled:i}){let a=T();return V(`ul`,{className:`setup-contents`,children:[(e.components??[]).map(e=>{let n=t?.components?.[e.id],o=t!=null&&t.state!==`running`&&t.state!==`verifying`,s=n===`active`&&o?void 0:n;return V(`li`,{className:`setup-content is-${s??(e.installed?`done`:`waiting`)}`,children:[P(`span`,{className:`setup-content-icon`,children:P(pM,{state:s??(e.installed?`done`:void 0)})}),V(`span`,{className:`setup-content-main`,children:[P(`span`,{className:`setup-content-name`,children:a(`setup.component.${e.id}`)}),P(`span`,{className:`setup-content-note`,children:a(`setup.component.${e.id}Note`)}),V(`span`,{className:`setup-content-from`,children:[a(`setup.contents.from`),` `,P(`bdi`,{dir:`ltr`,children:e.source})]})]}),V(`span`,{className:`setup-content-side`,children:[P(`bdi`,{dir:`ltr`,children:fM(e.size_gb,a)}),P(`span`,{children:dM(e,s,a)})]}),s===`failed`&&o&&!t?.problem&&P(mM,{id:e.id,error:t?.error,transient:t?.component_kinds?.[e.id]===`transient`,onRetry:r,disabled:i})]},e.id)}),n.map(e=>V(`li`,{className:`setup-content is-waiting`,children:[P(`span`,{className:`setup-content-icon`,children:P(pM,{state:void 0})}),V(`span`,{className:`setup-content-main`,children:[P(`span`,{className:`setup-content-name`,children:P(`bdi`,{children:e.name})}),P(`span`,{className:`setup-content-note`,children:e.roles.map(e=>a(`setup.purpose.${e}`)).join(` · `)}),e.source&&V(`span`,{className:`setup-content-from`,children:[a(`setup.contents.from`),` `,P(`bdi`,{dir:`ltr`,children:e.source})]})]}),P(`span`,{className:`setup-content-side`,children:P(`bdi`,{dir:`ltr`,children:fM(e.size_gb,a)})})]},e.id))]})}function gM({lines:e,className:t,id:n}){let r=(0,X.useRef)(null),i=(0,X.useRef)(!0),a=e.join(`
|
|
78
|
+
`);return(0,X.useEffect)(()=>{let e=r.current;e&&i.current&&(e.scrollTop=e.scrollHeight)},[a]),P(`pre`,{ref:r,id:n,className:t,dir:`ltr`,tabIndex:0,onScroll:e=>{let t=e.currentTarget;i.current=t.scrollHeight-t.scrollTop-t.clientHeight<8},children:a})}var _M=1e9,vM={downloading:0,verifying:1,failed:2,ready:3,unchecked:3,cancelled:4,queued:5,skipped:6};function yM(e){return e.roles.includes(`embedding`)?0:e.roles.includes(`chat`)?1:2}function bM(e){return[...e].filter(e=>e.state!==`skipped`).sort((e,t)=>vM[e.state]-vM[t.state]||yM(e)-yM(t))}var xM=/^\s*(Downloading:|Downloaded\b|\[[=\-\s>#]*\])/;function SM(e){return e.some(e=>e.trim()&&!xM.test(e))}var CM={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 wM(e){return e?e.state===`running`||e.state===`verifying`||!!e.models?.some(e=>e.state===`downloading`||e.state===`queued`||e.state===`verifying`):!1}function TM(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 EM({model:e,name:t,estimate:n,now:r,freeGb:i,onRetry:a,onResume:o,onSkip:s,onRestart:c,busy:l,retryLater:u,checking:d,checkingFor:f}){let p=T(),m=(0,X.useId)(),h=(0,X.useId)(),[g,_]=(0,X.useState)(!1),v=e.log??[],y=e.bytes_total>0?Math.min(100,e.bytes_done/e.bytes_total*100):e.state===`ready`?100:0,b=p(CM[e.state]),x=e.retrying_until?Math.max(0,Math.round(e.retrying_until-r/1e3)):0,S=e.state===`downloading`&&!x?n?.stalledFor??0:0,C=e.state===`verifying`&&d||e.state===`downloading`&&!x&&S<15,w;if(e.state===`downloading`){let t=IS(p.locale,e.bytes_total>0?`${PS(e.bytes_done)} / ${PS(e.bytes_total)}`:PS(e.bytes_done));if(x>0)w=p(`setup.progress.retrying`,{n:String(x)});else if(S>=60)w=p(`setup.progress.stuck`);else if(S>=15)w=p(`setup.progress.stalled`,{n:`15`});else if(n?.speed&&n.eta!=null){let{speed:e,eta:r}=n;w=p.compose(n=>`${t} · ${IS(p.locale,FS(e))} · ${LS(r,n)}`)}else w=p.compose(e=>`${t} · ${e(`setup.progress.estimating`)}`)}else w=e.state===`verifying`?d?f>=10?p(`setup.progress.checkingFor`,{n:String(f)}):p(`setup.progress.checkingLoad`):p(`setup.progress.waitingCheck`):e.state===`ready`?e.bytes_total?PS(e.bytes_total):``:e.state===`unchecked`?p(`setup.progress.unchecked`):e.state===`cancelled`?e.bytes_done>0?p(`setup.progress.keptPartial`,{done:PS(e.bytes_done)}):``:e.state===`queued`&&e.bytes_total?PS(e.bytes_total):``;let E=e.state===`downloading`?p.compose(t=>[t(`setup.progress.percent`,{n:String(Math.floor(y))}),e.bytes_total?t(`setup.progress.of`,{done:PS(e.bytes_done),total:PS(e.bytes_total)}):null,n?.eta==null?null:RS(n.eta,t)].filter(Boolean).join(`, `)):b;return V(`li`,{className:`dl-row is-${e.state}${C?` is-live`:``}${S>=15?` is-stalled`:``}`,children:[V(`div`,{className:`dl-row-head`,children:[P(`span`,{className:`dl-icon`,"aria-hidden":`true`,children:e.state===`ready`||e.state===`unchecked`?P(mr,{size:14}):e.state===`failed`?P(wr,{size:14}):e.state===`cancelled`?P(Ca,{size:13}):P(`span`,{className:`dl-dot`})}),P(`span`,{className:`dl-name`,children:P(`bdi`,{title:e.id,children:t})}),P(`span`,{className:`dl-state`,children:b}),e.state===`downloading`&&V(`bdi`,{className:`dl-pct`,children:[Math.floor(y),`%`]}),e.state!==`failed`&&SM(v)&&P(`button`,{type:`button`,className:`dl-log-toggle`,onClick:()=>_(e=>!e),"aria-expanded":g,"aria-controls":h,"aria-label":p(`setup.progress.logFor`,{name:t}),title:p(`setup.progress.logFor`,{name:t}),children:P(br,{size:14,className:g?`is-open`:``,"aria-hidden":`true`})})]}),P(`div`,{className:`dl-track`,role:`progressbar`,"aria-label":p(`setup.progress.rowLabel`,{name:t,state:b}),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":C&&e.state===`verifying`?void 0:Math.floor(y),"aria-valuetext":E,children:P(`span`,{className:`dl-fill`,style:{inlineSize:`${e.state===`verifying`?100:y}%`}})}),w&&P(`p`,{className:`dl-detail`,children:P(`bdi`,{children:w})}),g&&e.state!==`failed`&&SM(v)&&P(gM,{lines:v,id:h,className:`dl-log`}),e.state===`failed`&&V(`div`,{className:`dl-fail`,children:[P(`p`,{className:`dl-error`,id:m,children:TM(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
|
+
`):e.error})]}),u?P(`p`,{className:`dl-detail`,children:p(`setup.progress.retryLater`)}):V(`div`,{className:`setup-row`,children:[a&&V(`button`,{type:`button`,className:`btn-primary`,disabled:l,onClick:()=>a(e.id,e.error_kind),"aria-describedby":m,children:[P(za,{size:13,"aria-hidden":`true`}),` `,p(`setup.progress.retry`)]}),s&&P(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:()=>s(e.id),children:p(`setup.progress.skipModel`)})]})]}),e.state===`cancelled`&&o&&P(`div`,{className:`setup-row`,children:P(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:()=>o(e.id),children:p(`setup.progress.resume`)})}),S>=60&&c&&P(`div`,{className:`setup-row`,children:V(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:c,children:[P(za,{size:13,"aria-hidden":`true`}),` `,p(`setup.progress.retry`)]})})]})}function DM({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=YA(),m=(0,X.useMemo)(()=>bM(e.models??[]),[e.models]),h=(0,X.useRef)(new Map),g=(0,X.useRef)(new Map),_=(0,X.useRef)(new BS),v=(0,X.useRef)(!1),[y,b]=(0,X.useState)(()=>Date.now()),[x,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(null),E=i&&((e,t)=>{let n=m.find(t=>t.id===e);t===`verify`&&n?w(n):i(e,t)}),[D,O]=(0,X.useState)(``),[k,A]=(0,X.useState)(``),j=(0,X.useRef)(null),M=e.state===`verifying`||e.state!==`running`&&m.some(e=>e.state===`verifying`),N=(0,X.useRef)(new Map);(0,X.useEffect)(()=>{if(!p||!(m.some(e=>e.retrying_until)||M))return;let e=setInterval(()=>b(Date.now()),1e3);return()=>clearInterval(e)},[m,p,M]);let F=e.overall,{estimates:I,overallEstimate:L}=(0,X.useMemo)(()=>{let e=Date.now(),t={};for(let n of m){if(n.state!==`downloading`){h.current.delete(n.id);continue}let r=h.current.get(n.id),i=n.downloaded_before_gb??null;(!r||g.current.get(n.id)!==i)&&(r=new BS,h.current.set(n.id,r),g.current.set(n.id,i)),t[n.id]=r.update(n.bytes_done,n.bytes_total,e)}let n=m.some(e=>e.state===`downloading`);n&&!v.current&&(_.current=new BS),v.current=n;let r=m.filter(e=>e.state===`downloading`||e.state===`queued`).reduce((e,t)=>e+Math.max(0,t.bytes_total-t.bytes_done),0);return{estimates:t,overallEstimate:n&&F?_.current.update(F.bytes_done,F.bytes_done+r,e):void 0}},[m,F]);(0,X.useEffect)(()=>{let e=new Map(m.map(e=>[e.id,e.state])),n=Math.floor((F?.percent??0)/25),r=j.current;if(j.current={states:e,quarter:n},!r)return;let i=[];for(let e of m){if(r.states.get(e.id)===e.state)continue;let n=t[e.id]??e.id;e.state===`failed`?A(f(`setup.progress.announceFailed`,{name:n})):i.push(f(`setup.progress.announceState`,{name:n,state:f(CM[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=wM(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)>_M?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(EM,{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(Kj,{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(qj,{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(qj,{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 OM=[`check`,`download`,`test`],kM={root:`setup-report`,button:`btn-secondary setup-report-button`,hint:`setup-hint`,error:`setup-error`};function AM({run:e,before:t={}}){let n=T(),[r,i]=(0,X.useState)(()=>new Set),a=e=>i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),o=n=>[...t[n]??[],...e?.logs?.[n]??[]],s=OM.filter(e=>o(e).length>0);return V(`section`,{className:`setup-logs`,"aria-label":n(`setup.logs.title`),children:[s.map(e=>{let t=o(e),i=r.has(e);return V(`div`,{className:`setup-log`,children:[V(`button`,{type:`button`,className:`setup-log-toggle`,onClick:()=>a(e),"aria-expanded":i,children:[P(br,{size:13,className:i?`is-open`:``,"aria-hidden":`true`}),` `,n(`setup.logs.${e}`)]}),i&&P(gM,{lines:t,className:`setup-log-pre`})]},e)}),P(rC,{classes:kM,note:n(`setup.logs.reportNote`)})]})}function jM(){let e=T(),t=k(e=>e.locale),n=k(e=>e.setLocale);return V(`label`,{className:`setup-language`,children:[P(Ki,{size:14,"aria-hidden":`true`}),P(`span`,{className:`visually-hidden`,children:e(`settings.language`)}),P(`select`,{value:t,onChange:e=>n(e.target.value),children:b.map(({meta:e})=>P(`option`,{value:e.code,lang:e.code,dir:e.dir,children:M(e)},e.code))})]})}var MM={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`]},NM={cancelled:`setup.npu.fixError.cancelled`,timeout:`setup.npu.fixError.timeout`,not_authorized:`setup.npu.fixError.notAuthorized`,no_pkexec:`setup.npu.fixError.noPkexec`};function PM({problem:e}){let t=T(),n=MM[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 FM({problems:e,disabled:t,onRecheck:n,id:r=`setup-npu-problems`}){let i=T(),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),l=e.some(e=>e.code===`memlock`&&e.params.fix===`apply`),u=async(e,t)=>{o(!0),c(null);try{await e(),n?.()}catch(e){let n=e instanceof yn?e.body?.code:void 0,r=n&&n in NM?NM[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(PM,{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 IM(){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 LM({plan:e,selection:t,onSelection:n,disabled:r=!1,onRecheck:i}){let a=T(),o=QA(e),s=e.npu?.present&&!e.npu.ready?e.npu.problems:[],c=s.length?void 0:o.find(e=>tj(e)&&e.gaia_model&&e.chat_choice&&e.fits!==!1)??o.find(e=>tj(e)&&e.chat_choice&&e.downloaded&&!nj(e)),l=!s.length&&!c&&o.some(e=>tj(e)&&e.fit_code===`npu`),u=!!o.find(e=>e.id===t.defaultChat&&tj(e)),d=_j(e).defaultChat,f=d&&!o.find(e=>e.id===d&&tj(e))?d:o.find(e=>e.chat_choice&&e.gaia_model&&e.support===`verified`&&!tj(e))?.id,p=e=>{e===`npu`&&c&&!u&&n(sj(t,o,c.id)),e===`gpu`&&u&&f&&n(sj(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(FM,{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 RM=({children:e})=>P(`bdi`,{dir:`ltr`,children:e});function zM({label:e,children:t}){return V(`div`,{className:`found-row`,children:[P(`dt`,{children:e}),P(`dd`,{children:t})]})}function BM(e){return e.family?`${e.name} (${e.family})`:e.name}var VM=[[`llamacpp`,`llama.cpp`],[`flm`,`FastFlowLM`],[`whispercpp`,`whisper.cpp`],[`kokoro`,`Kokoro`],[`sd-cpp`,`stable-diffusion.cpp`]],HM=new Set([`llamacpp`,`flm`]);function UM(e){let t=[];for(let[n,r]of VM){let i=(e.backends??[]).find(e=>e.recipe===n&&e.default);i&&i.state!==`unsupported`&&t.push({name:r,b:i})}return t}function WM(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 GM={release:`release`,release_candidate:`release candidate`,local:`local build`,source:`from source`};function KM(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=UM(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:WM(n?.gaia_build,n?.gaia_version),build:n?.gaia_build?.kind??null,software:[WM(n?.gaia_build,n?.gaia_version)?`GAIA ${WM(n?.gaia_build,n?.gaia_version)}`:null,n?.lemonade_version?`Lemonade ${n.lemonade_version}`:null,...o.filter(({b:e})=>HM.has(e.recipe)&&JM(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 qM={installed:`installed`,update_required:`installed, updates on first use`},JM=e=>e.state===`installed`||e.state===`update_required`,YM={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 XM(e,t){let n=KM(e,t),r=e.lemonade.mode===`external`?`the user's own`:`GAIA's own`;return[`GAIA: ${n.gaia??`unknown`}${n.build?`, ${GM[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}`:``} (${qM[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(BM).join(`; `)||t?.gpu_name||`none found`}`,`NPU: ${n.npus.map(BM).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
|
+
`)}function ZM({plan:e,hardware:t,onChangeMemory:n}){let r=T(),i=KM(e,t),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),d=async e=>{u(null);try{await Dn(e,!1)}catch(e){u(r(`setup.found.openFailed`,{error:e instanceof Error?e.message:String(e)}))}},f=P(`span`,{className:`found-muted`,children:r(`setup.found.unknown`)}),p=[...t?.blockers??[],...(t?.warnings??[]).filter(e=>t?.lemonade_running||!/\bNPU\b/.test(e))],m=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{m.current&&clearTimeout(m.current)},[]);let h=e=>{c(e),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>c(null),2e3)};return V(`section`,{className:`setup-card found`,"aria-label":r(`setup.found.title`),children:[V(`div`,{className:`found-head`,children:[P(`h3`,{className:`mc-job-title`,children:r(`setup.found.title`)}),P(`button`,{type:`button`,className:`found-copy`,onClick:()=>{navigator.clipboard.writeText(XM(e,t)).then(()=>h(`done`),e=>{console.warn(`[DetectedSummary] could not copy the details`,e),h(`failed`)})},"aria-label":r(`setup.found.copy`),title:r(`setup.found.copy`),children:P(s===`done`?mr:Br,{size:14,"aria-hidden":`true`})}),s&&P(`span`,{className:`found-copied`,role:`status`,children:r(s===`done`?`setup.found.copied`:`setup.found.copyFailed`)})]}),V(`dl`,{className:`found-glance`,children:[V(zM,{label:r(`setup.found.runsOn`),children:[i.runsOn?P(RM,{children:i.runsOn}):f,i.npu&&P(`span`,{className:`found-chip`,children:P(RM,{children:`NPU`})})]}),V(zM,{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(RM,{children:i.totalMemory}):f:P(RM,{children:$(e.capacity_gb)}),n&&P(`button`,{type:`button`,className:`link-btn found-link`,onClick:n,children:r(`setup.found.changeMemory`)})]}),P(zM,{label:r(`setup.found.space`),children:i.freeGb==null?f:P(RM,{children:$(i.freeGb)})}),V(zM,{label:r(`setup.found.software`),children:[i.software.length?P(RM,{children:i.software.join(` · `)}):f,i.build&&i.build!==`release`&&P(`span`,{className:`found-chip`,children:r(`setup.found.build.${i.build}`)})]})]}),V(`div`,{className:`found-paths`,children:[[[`setup.found.modelsFolder`,i.modelsPath],[`setup.found.gaiaFolder`,i.gaiaHome]].map(([e,t])=>t&&V(`button`,{type:`button`,className:`link-btn found-open`,onClick:()=>void d(t),title:t,children:[P(bi,{size:13,"aria-hidden":`true`}),` `,r(e)]},e)),l&&P(`p`,{className:`setup-error`,role:`alert`,children:l})]}),p.length>0&&V(`details`,{className:`dl-details found-warnings`,children:[V(`summary`,{children:[P(wr,{size:13,"aria-hidden":`true`}),` `,r(`setup.found.noticed`)]}),P(`ul`,{children:p.map(e=>P(`li`,{children:P(RM,{children:e})},e))})]}),V(`button`,{type:`button`,className:`setup-log-toggle found-more`,onClick:()=>o(e=>!e),"aria-expanded":a,children:[P(br,{size:13,className:a?`is-open`:``,"aria-hidden":`true`}),` `,r(`setup.found.details`)]}),a&&V(`div`,{className:`found-details`,children:[P(`h4`,{className:`found-group`,children:r(`setup.found.software`)}),V(`dl`,{className:`found-list`,children:[V(zM,{label:P(RM,{children:`GAIA`}),children:[i.gaia?P(RM,{children:i.gaia}):f,i.build&&i.build!==`release`&&P(`span`,{className:`found-chip`,children:r(`setup.found.build.${i.build}`)})]}),P(zM,{label:r(`setup.found.agent`),children:i.sys?.agent_version?P(RM,{children:i.sys.agent_version}):P(`span`,{className:`found-muted`,children:r(`setup.found.agentLater`)})}),V(zM,{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(RM,{children:i.sys.lemonade_version})]}),e.lemonade.url&&P(`span`,{className:`found-sub`,children:P(RM,{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(RM,{children:e})}),P(`td`,{children:P(RM,{children:t.backend})}),P(`td`,{children:P(RM,{children:t.version??``})}),P(`td`,{className:JM(t)?`is-installed`:void 0,children:r(JM(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(YM[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(RM,{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(zM,{label:r(`setup.found.os`),children:i.sys?.os??t?.os?P(RM,{children:i.sys?.os??t?.os}):f}),V(zM,{label:r(`setup.found.cpu`),children:[i.cpu||i.sys?.processor?P(RM,{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(zM,{label:r(`setup.found.gpu`),children:i.gpus.length?P(RM,{children:i.gpus.map(BM).join(`; `)}):P(`span`,{className:`found-muted`,children:r(`setup.found.none`)})}),P(zM,{label:r(`setup.found.npu`),children:i.npus.length?P(RM,{children:i.npus.map(BM).join(`; `)}):P(`span`,{className:`found-muted`,children:r(`setup.found.none`)})})]})]})]})}function QM({state:e}){return e===`done`?P(mr,{size:13,"aria-hidden":`true`}):e===`active`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):P(e===`failed`?Y:e===`question`?Ar:Mr,{size:13,"aria-hidden":`true`})}function $M({hardware:e,hardwareError:t,plan:n,serverRun:r,awaitingChoice:i=!1}){let a=T(),[o,s]=(0,X.useState)(!1),c=!!n?.lemonade.reachable,l=r?.state===`failed`||r?.state===`cancelled`,u=a(n?.lemonade.mode===`external`?`setup.found.serverYours`:`setup.found.serverOwn`),d=n?.system?.lemonade_version?a(`setup.checks.serverFound`,{version:n.system.lemonade_version,whose:u}):u,f=e?`done`:t?`failed`:`active`,p=[e?.gpu_name,e?.npu_detected?a(`setup.checks.npu`):null].filter(Boolean).join(` · `),m=t?null:n?.capacity_gb==null?c?MS(n?.system?.physical_memory,e?.ram_gb):null:$(n.capacity_gb),h=t?`failed`:m?`done`:l?`failed`:i?`waiting`:`active`,g=[{id:`device`,label:a(`setup.checks.device`),value:t?`${a(`setup.system.unread`)} ${t}`:p||null,state:f},{id:`memory`,label:a(`setup.found.memory`),value:m,state:h},{id:`disk`,label:a(`setup.checks.disk`),value:e?.disk_free_gb==null?null:a(`setup.checks.diskValue`,{size:IS(a.locale,`${Math.round(e.disk_free_gb)} GB`)}),state:f},{id:`server`,label:a(`setup.checks.server`),value:c?d:i?a(`setup.checks.serverChoose`):null,state:c?`done`:l?`failed`:i?`question`:e?`active`:`waiting`},{id:`models`,label:a(`setup.checks.backends`),value:c&&n?.catalog?a(`setup.checks.backendsValue`,{models:String(n.catalog.length),downloaded:String(n.catalog.filter(e=>e.downloaded).length)}):null,state:c&&n?.catalog?`done`:c?`active`:`waiting`}],_=g.filter(e=>e.state===`done`).length,v=Math.round(_/g.length*100),y=P(`ul`,{className:`setup-rows`,id:`setup-check-rows`,children:g.map(e=>V(`li`,{className:`setup-result is-${e.state}`,children:[P(QM,{state:e.state}),P(`span`,{className:`setup-result-label`,children:e.label}),e.value&&P(`bdi`,{className:`setup-result-value`,children:e.value})]},e.id))});return _===g.length?V(`section`,{className:`setup-card setup-checks-done`,"aria-label":a(`setup.check.title`),children:[P(`p`,{className:`setup-result is-done`,role:`status`,children:V(`button`,{type:`button`,className:`setup-checks-toggle`,"aria-expanded":o,"aria-controls":`setup-check-rows`,onClick:()=>s(e=>!e),children:[P(mr,{size:13,"aria-hidden":`true`}),P(`span`,{className:`setup-result-label`,children:a(`setup.checks.allPassed`,{n:String(g.length)})}),P(br,{size:13,className:o?`is-open`:``,"aria-hidden":`true`})]})}),o&&y]}):V(`section`,{className:`setup-card`,"aria-label":a(`setup.check.title`),children:[V(`div`,{className:`setup-bar-head`,children:[P(`span`,{children:a(`setup.checks.count`,{done:String(_),total:String(g.length)})}),V(`bdi`,{dir:`ltr`,children:[v,`%`]})]}),P(`progress`,{className:`setup-progress`,max:100,value:v,"aria-label":a(`setup.check.title`)}),y]})}function eN({steps:e}){let t=T();return V(`nav`,{className:`setup-rail`,"aria-label":t(`setup.rail.label`),children:[P(`p`,{className:`setup-rail-title`,children:t(`setup.title`)}),P(`ol`,{className:`setup-rail-list`,children:e.map((e,t)=>{let n=e.status===`done`?P(mr,{size:13,"aria-hidden":`true`}):e.status===`active`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):e.status===`failed`?P(wr,{size:13,"aria-hidden":`true`}):t+1,r=V(D.Fragment,{children:[P(`span`,{className:`setup-rail-num`,children:n}),P(`span`,{children:e.label})]}),i=`setup-rail-step is-${e.status}${e.shown?` is-shown`:``}`,a=e.shown?`step`:void 0;return P(`li`,{children:e.onOpen?P(`button`,{type:`button`,className:i,onClick:e.onOpen,children:r}):P(`span`,{className:i,"aria-current":a,children:r})},e.id)})})]})}var tN={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 nN(e,t){return t(`setup.test.job.${e}`)}function rN({state:e}){return e===`passed`?P(mr,{size:13,"aria-hidden":`true`}):e===`running`?P(q,{size:13,className:`spin`,"aria-hidden":`true`}):P(e===`failed`?Y:e===`skipped`?da:Mr,{size:13,"aria-hidden":`true`})}function iN(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 aN({run:e,expected:t,names:n,catalog:r,onRetry:i,onChooseAnother:a,onCancel:o,onDownloadAgain:s,busy:c}){let l=T(),u=e.tests??[],d=new Set(u.map(e=>e.job)),f=t.filter(e=>!d.has(e)),p=u.filter(e=>e.state!==`running`).length,m=Math.max(u.length+f.length,1),h=Math.round(p/m*100),g=u.filter(e=>e.state===`failed`).filter(e=>!r.find(t=>t.id===e.subject)?.roles.some(e=>[`speech`,`voice`,`image_creation`].includes(e))),_=e.state===`failed`||e.state===`cancelled`,v=s?[...new Set(g.filter(e=>e.kind===`broken`&&e.subject).map(e=>e.subject))]:[],[y,b]=(0,X.useState)(null),x=r.find(e=>e.id===y)?.full_size_gb,S=_&&e.components?.agent===`failed`,C=g.some(e=>e.subject&&e.kind!==`missing`);return V(D.Fragment,{children:[V(`section`,{className:`setup-card`,"aria-label":l(`setup.test.title`),children:[V(`div`,{className:`setup-bar-head`,children:[P(`span`,{children:l(`setup.test.count`,{done:String(p),total:String(m)})}),V(`bdi`,{dir:`ltr`,children:[h,`%`]})]}),P(`progress`,{className:`setup-progress`,max:100,value:h,"aria-label":l(`setup.test.title`)}),V(`ul`,{className:`setup-rows`,children:[u.map(e=>V(`li`,{className:`setup-result is-${e.state}`,children:[P(rN,{state:e.state}),V(`span`,{className:`setup-result-label`,children:[nN(e.job,l),e.subject&&V(`bdi`,{className:`setup-result-model`,children:[` `,n[e.subject]??e.subject]})]}),P(`span`,{className:`setup-result-value`,children:iN(e,l)}),e.error&&V(`div`,{className:`setup-result-error`,children:[P(`p`,{children:l(e.kind===`broken`&&!s?`setup.test.why.brokenYours`:tN[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(rN,{state:`failed`}),P(`span`,{className:`setup-result-label`,children:nN(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(rN,{state:`waiting`}),P(`span`,{className:`setup-result-label`,children:nN(e,l)}),P(`span`,{className:`setup-result-value`,children:l(`setup.test.waiting`)})]},e))]})]}),e.state===`verifying`&&o&&P(Kj,{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(Kj,{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(qj,{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 oN=`https://app.fireworks.ai/settings/users/api-keys`,sN=`https://amd-gaia.ai/docs/guides/llm-gateway`,cN=[{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 lN(e,t){return N(e.title)?t(e.title):e.title}var uN=1e3,dN=`gaia-setup-choice`;function fN(){try{let e=localStorage.getItem(dN);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 pN(e){try{localStorage.setItem(dN,e)}catch(e){console.warn(`[SetupScreen] could not save the provider choice; a reload will ask again`,e)}}var mN=[`ok`,`needs_key`,`too_old`];function hN({onChosen:e,onNothingToOffer:t,onFound:n,canInstallOwn:r=!0}){let i=T(),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)([]),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!1),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(null),E=(0,X.useRef)(!0),O=(0,X.useCallback)(async()=>{c(null);try{let e=await ce();if(!e.offer){t?.();return}f(!0);let{found:r,unchecked:i=[]}=await tt();if(!E.current)return;u(r?[]:i),r&&mN.includes(r.status)?(o({target:e,found:r}),n?.(r),g(r.status===`needs_key`),r.status===`too_old`&&t?.()):i.length===0&&t?.()}catch(e){E.current&&c(e instanceof Error?e.message:String(e))}finally{E.current&&f(!1)}},[t,n]);(0,X.useEffect)(()=>(E.current=!0,O(),()=>{E.current=!1}),[O]);let k=(0,X.useCallback)(async t=>{if(a){b(t),S(null);try{await Ee(t===`external`?{mode:t,base_url:a.found.url,api_key:p.trim()||void 0}:{mode:t}),m(``),w(t),e(t)}catch(e){WA(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(Kj,{children:[V(`button`,{type:`button`,className:`btn-secondary`,disabled:d,onClick:()=>void O(),children:[d&&P(q,{size:13,className:`spin`}),` `,i(`setup.offer.checkAgain`)]}),t&&r&&P(`button`,{type:`button`,className:`btn-primary`,disabled:d,onClick:t,children:i(`setup.offer.useOwn`)})]})]});if(!a)return d?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,i(`setup.offer.looking`)]}):null;let{target:A,found:j}=a;return C?P(`p`,{className:`setup-hint`,role:`status`,children:C===`external`?i(`setup.offer.usingYours`,{url:j.url}):i(`setup.offer.usingOwn`)}):j.status===`too_old`?V(`p`,{className:`setup-hint`,role:`status`,children:[i(`setup.offer.tooOld`),` `,V(`bdi`,{dir:`ltr`,className:`setup-choice-note`,children:[`Lemonade `,j.version??``,` · `,j.url]})]}):V(`form`,{id:`setup-lemonade-form`,className:`setup-lemonade`,"aria-label":i(`setup.offer.label`),onSubmit:e=>{e.preventDefault(),k(`external`)},children:[P(`span`,{className:`setup-choice-title`,children:i(`setup.offer.title`)}),P(`span`,{className:`setup-choice-note`,children:V(`bdi`,{dir:`ltr`,children:[`Lemonade`,j.version?` ${j.version}`:``,` · `,j.url]})}),V(`button`,{type:`button`,className:`setup-log-toggle setup-offer-more`,onClick:()=>v(e=>!e),"aria-expanded":_,"aria-controls":`setup-offer-detail`,children:[P(br,{size:13,className:_?`is-open`:``,"aria-hidden":`true`}),` `,i(`setup.offer.whatGaiaDoes`)]}),_&&P(`p`,{className:`setup-choice-note`,id:`setup-offer-detail`,children:i(`setup.offer.whatGaiaDoesText`)}),h&&P(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,value:p,onChange:e=>m(e.target.value),placeholder:i(`setup.offer.keyPlaceholder`),"aria-label":i(`setup.offer.keyLabel`)}),x&&(h?P(`p`,{className:`setup-error`,role:`alert`,children:i(`setup.offer.keyRejected`)}):P(_N,{text:x})),V(Kj,{children:[V(`button`,{type:`submit`,form:`setup-lemonade-form`,className:`btn-secondary`,disabled:!!y||h&&!p.trim(),children:[y===`external`&&P(q,{size:13,className:`spin`}),` `,i(`setup.offer.useMine`)]}),V(`button`,{type:`button`,className:`btn-primary`,disabled:!!y,onClick:()=>void k(`gaia`),children:[y===`gaia`&&P(q,{size:13,className:`spin`}),` `,i(`setup.offer.useOwn`)]})]})]})}function gN({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(Kj,{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 _N({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 vN({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 yN=[`check`,`plan`,`key`,`models`,`gpu`,`download`,`test`,`ready`];function bN(e){return e instanceof Error?e.message:String(e)}function xN({onReady:e,onClose:t}){let n=T(),r=cs(e=>e.refresh),i=cs(e=>e.select),[a,o]=(0,X.useState)(`local`),[s,c]=(0,X.useState)(`check`),[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(`models`),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(()=>new Set([`check`])),y=(0,X.useRef)(`check`),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),[O,k]=(0,X.useState)(null),[A,j]=(0,X.useState)(null),[M,N]=(0,X.useState)(``),[F,I]=(0,X.useState)({busy:!1,error:null,done:!1}),[L,ee]=(0,X.useState)(null),[R,z]=(0,X.useState)(null),[B,te]=(0,X.useState)(null),[ne,re]=(0,X.useState)(null),[ie,ae]=(0,X.useState)(null),[oe,H]=(0,X.useState)(null),[U,se]=(0,X.useState)(!1),[W,le]=(0,X.useState)(null),[ue,de]=(0,X.useState)(!1),[fe,pe]=(0,X.useState)(!1),[me,he]=(0,X.useState)(null),[ge,_e]=(0,X.useState)(!1),[ve,ye]=(0,X.useState)(null),[be,xe]=(0,X.useState)([]),[Se,we]=(0,X.useState)([]),[Ee,De]=(0,X.useState)([]),[Oe,ke]=(0,X.useState)(!1),[Ae,je]=(0,X.useState)(!1),Me=(0,X.useRef)({gaiaLemonade:!1,options:{}}),Ne=(0,X.useRef)(null),Pe=(0,X.useRef)(!1),Fe=(0,X.useRef)(!1),[Ie,Re]=(0,X.useState)(!1),[ze,Ve]=(0,X.useState)(!1),He=(0,X.useCallback)(()=>Ve(!0),[]),[Ue,We]=(0,X.useState)(null),[Ge,Ke]=(0,X.useState)(null),qe=(0,X.useRef)(!0);(0,X.useEffect)(()=>(qe.current=!0,()=>{qe.current=!1}),[]);let{network:Je,providers:Ye,recheck:Xe}=uM(),Ze=e=>Ye.find(t=>t.id===e),Qe=Ze(a),$e=Qe?.key_source===`environment`&&Qe.key_hint?Qe:void 0,et=e=>!!Ze(e)?.blocked,tt=e=>et(e)||e===`amd`&&Je?.reachable===!1,nt=e=>et(e)?n(`settings.privacy.localOnlyBlocked`):n(`setup.key.gatewayOff`),rt=a!==`local`,at=w?.server_only?w:null,K=w&&!w.server_only?w:null,st=w?.state===`running`||w?.state===`verifying`,ct=K?.state===`ready`,ut=wM(w),dt=!(K?.models??[]).some(e=>e.state===`downloading`||e.state===`queued`)&&((K?.tests?.length??0)>0||K?.state===`verifying`),pt=(0,X.useCallback)(()=>{C(null),ot().then(x).catch(e=>C(bN(e)))},[]),mt=(0,X.useRef)(0),gt=(0,X.useCallback)(async()=>{let e=++mt.current;z(null);try{let t=await Ce();return e===mt.current?(ee(t),t):null}catch(t){return e===mt.current&&z(bN(t)),null}},[]),vt=(0,X.useCallback)(async()=>{try{let e=await Nn();qe.current&&H(e??null)}catch(e){console.warn(`[SetupScreen] GPU memory could not be read; the step stays hidden`,e)}},[]),yt=t!=null;(0,X.useEffect)(()=>{ce().then(e=>ke(e.source===`config`)).catch(e=>console.warn(`[SetupScreen] could not read which Lemonade GAIA uses`,e)),pt(),gt(),it().then(e=>{(e.state!==`idle`||e.models?.length)&&(yt&&e.state!==`running`&&e.state!==`verifying`||(E(e),e.server_only||c(`download`),e.skip_chat_model&&o(fN()===`amd`?`amd`:`fireworks`)))}).catch(e=>j(bN(e))).finally(()=>Re(!0))},[pt,gt,yt]),(0,X.useEffect)(()=>{L?.catalog&&L.lemonade.reachable&&(te(e=>e??pj(L)),vt(),!w&&L.catalog.some(e=>e.partial&&e.selected)&&_e(!0))},[L,vt,w]);let bt=(0,X.useCallback)(()=>{Ne.current&&clearInterval(Ne.current),Ne.current=null},[]),xt=(w?.models??[]).filter(e=>e.state===`failed`&&e.error_kind===`disk_full`).length;(0,X.useEffect)(()=>{xt>0&>()},[xt,gt]);let St=(0,X.useCallback)(async()=>{try{let e=await it();if(k(null),e.state===`idle`&&!e.models?.length){E(null),c(`plan`),je(!0),gt();return}E(e)}catch(e){k(bN(e))}},[gt,n]);(0,X.useEffect)(()=>(!ut&&!O||(Ne.current=setInterval(()=>{St()},uN)),bt),[ut,O,St,bt]),(0,X.useEffect)(()=>{at&&at.state===`ready`&&(pt(),gt())},[at,at?.state,pt,gt]),(0,X.useEffect)(()=>{ct&&(pt(),gt().then(e=>{e&&ae(e)}),vt())},[ct,pt,gt,vt]);let Ct=(0,X.useRef)(!1),wt=(0,X.useCallback)(async(e=!1,t={})=>{if(Ct.current)return!1;Ct.current=!0,j(null),he(null),_e(!1),je(!1);try{pN(a),Me.current={gaiaLemonade:e,options:t};let n=await _t(rt,e,t);E(n),g(null);let r=t.extraModels??[];return r.length&&De(e=>e.filter(e=>!r.includes(e))),t.serverOnly||c(`download`),e&&ke(!1),!0}catch(e){let t=ht(e);if(t)return le({kind:`server`,detail:t,then:`run`}),!1;if(e instanceof yn&&e.httpStatus===409){let e=await it().catch(()=>null);if(e&&(e.state===`running`||e.state===`verifying`))return E(e),g(null),e.server_only||c(`download`),!0}return j(bN(e)),!1}finally{Ct.current=!1}},[a,rt]);(0,X.useEffect)(()=>{s===`check`&&Ie&&ze&&L&&!L.lemonade.reachable&&!w&&!Pe.current&&(Pe.current=!0,wt(!1,{serverOnly:!0}))},[s,Ie,ze,L,w,wt]);let Tt=!!(B&&L?.catalog&&L.lemonade.reachable&&(b||S)),Et=(0,X.useCallback)(()=>{let{gaiaLemonade:e,options:t}=Me.current;wt(e,t)},[wt]),Dt=(0,X.useCallback)((e,t=L)=>{re(t);let n=t&&B&&!rt?Cj(t,B):[];return wt(!1,{acknowledgeLowDisk:e,keepTrying:U,extraModels:n})},[L,B,rt,U,wt]),[Ot,kt]=(0,X.useState)(!1),At=(0,X.useRef)(!1),jt=(0,X.useCallback)(async(e,t=ue)=>{if(!L||!B||At.current)return;he(null),kt(e);let r=QA(L),i=rt?[]:xj(r,B).filter(e=>!e.downloaded||e.id===B.defaultChat),a=i.find(nj);if(a){let e=a.id===B.defaultChat?`setup.models.cantRun.chat`:`setup.models.cantRun.other`;he(n(e,{name:a.name,why:jj(a,n)}))}else if(!rt&&!t&&i.length>0&&i.every(e=>e.need_gb!=null))le({kind:`no_fit`,models:i});else{pe(!0),At.current=!0;try{let n=L;if(!rt&&B.defaultChat&&B.defaultChat!==n.chat_model.id)try{n=await Le(B.defaultChat,t)}catch(e){let t=ht(e);if(t){le({kind:`server`,detail:t,then:`chat`});return}throw e}if(!rt){await IM();let e=lj(r,B);e!==(n.vision_model??null)&&(n=await Be(e));for(let e of Sj(n,B))n=await ft(e.id,e.skipped)}ee(n),await Dt(e,n)}catch(e){he(bN(e))}finally{At.current=!1,pe(!1)}}},[L,B,rt,ue,Dt,n]),Mt=(0,X.useCallback)(e=>{he(null),s===`download`?g(e===y.current?null:e):(g(null),c(e===`test`||e===`ready`?`download`:e))},[s]),Nt=(0,X.useCallback)(()=>{h??o(`local`),Mt(`plan`)},[Mt,h]),Pt=(0,X.useCallback)(()=>{st&&h!=null||(o(`local`),u(!0),Mt(`models`))},[Mt,st,h]),Ft=(0,X.useCallback)(()=>{st&&h!=null||(u(!1),o(fN()===`amd`?`amd`:`fireworks`),Mt(`key`))},[Mt,st,h]),It=!!oe?.applies,Lt=(0,X.useCallback)(()=>{Mt((h??s)===`gpu`?d:`plan`)},[d,Mt,h,s]),zt=(0,X.useCallback)(e=>{f(e),Mt(`gpu`)},[Mt]),Bt=(0,X.useRef)({prev:null,next:null});(0,X.useEffect)(()=>{let e=e=>{if(!e.altKey||W||(e.target instanceof Element?e.target:null)?.closest(`input, textarea, select, [contenteditable="true"]`))return;let t=e.key===`ArrowLeft`?Bt.current.prev:e.key===`ArrowRight`?Bt.current.next:null;t&&(e.preventDefault(),Mt(t))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[Mt,W]);let Vt=(0,X.useCallback)(async()=>{try{await G(),await St()}catch(e){he(bN(e))}},[St]),Ht=(0,X.useCallback)(async(e,t)=>{he(null),pe(!0);try{t===`verify`&&await dn(e),t===`disk_full`&>();try{E(await Te(e,{keepTrying:U}))}catch(t){let n=ht(t);if(!n)throw t;le({kind:`server`,detail:n,then:`retry`,id:e})}}catch(e){he(bN(e))}finally{pe(!1)}},[U,gt]),Ut=(0,X.useCallback)(async e=>{he(null),pe(!0);try{L?.catalog?.find(t=>t.id===e)?.planned&&ee(await ft(e,!0)),E(t=>t&&{...t,models:t.models?.map(t=>t.id===e?{...t,state:`skipped`}:t)});let{options:t}=Me.current;Me.current.options={...t,extraModels:t.extraModels?.filter(t=>t!==e)},te(t=>t&&t.ticked.has(e)?hj(t,QA(L),e,!1):t)}catch(e){he(bN(e))}finally{pe(!1)}},[L]),Wt=(0,X.useCallback)(async()=>{await Vt(),Et()},[Vt,Et]),Gt=(0,X.useCallback)(async()=>{if(!st){I({busy:!0,error:null,done:!1});try{await Rt(a,{api_key:!Oe&&M||void 0},e=>I({busy:!0,error:null,done:!1,waiting:e}),()=>!qe.current);let{models:e}=await Zt(a),t=e.find(e=>e.rank===1)??e[0];if(!t)throw Error(n(`setup.key.noModels`));await i(t.id),ye(t.id),N(``),I({busy:!1,error:null,done:!0}),Dt(!1)}catch(e){I({busy:!1,error:bN(e),done:!1})}}},[a,M,i,Oe,Dt,n,st]),Kt=(0,X.useCallback)(e=>{pN(e),o(e),I({busy:!1,error:null,done:!1})},[]);(0,X.useEffect)(()=>{if(!ct||Se.length===0||Fe.current)return;let e=Se;Fe.current=!0,wt(!1,{keepTrying:U,extraModels:e}).then(t=>{Fe.current=!1,we(t=>t.filter(t=>!e.includes(t))),t||De(t=>[...t,...e.filter(e=>!t.includes(e))])})},[ct,Se,U,wt]);let qt=ct&&Se.length===0,Jt=rt?ve:K?.chat_model??(L&&!L.decided_after_server?L.chat_model.id:null),Yt=(0,X.useCallback)(async t=>{he(null);try{!rt&&Jt&&await i(Jt),await r()}catch(e){he(bN(e));return}e(t)},[Jt,rt,e,r,i]);(0,X.useEffect)(()=>{qt&<().then(e=>xe(e.cards)).catch(e=>console.warn(`[SetupScreen] no first tasks to offer`,e))},[qt]);let Xt=(0,X.useMemo)(()=>{let e={};for(let t of L?.catalog??[])e[t.id]=t.name;return e},[L]),Qt=w?.state===`failed`||w?.state===`cancelled`,$t=K&&(K.state===`failed`||K.state===`cancelled`)&&(K.models??[]).length>0&&(K.models??[]).every(e=>e.state===`ready`||e.state===`skipped`||e.state===`verifying`||e.state===`unchecked`)&&!ut,en=!!K&&Qt&&!K.problem&&Object.values(K.components??{}).includes(`failed`),tn=QA(L),nn=B?vj(tn,B):[],rn=L&&B?bj(L,B):null,an=tn.find(e=>e.id===B?.defaultChat),on=!!b&&!b.compatible&&b.blockers.length>0,sn=qt?`ready`:s===`download`&&dt?`test`:s;y.current=sn;let cn=h??sn;(0,X.useEffect)(()=>{v(e=>e.has(cn)?e:new Set(e).add(cn))},[cn]);let ln=(0,X.useRef)(!0);(0,X.useEffect)(()=>{if(ln.current){ln.current=!1;return}let e=document.querySelector(`.setup-inner`);e&&(e.scrollTop=0),document.getElementById(`setup-title`)?.focus({preventScroll:!0})},[cn]);let un=[{id:`check`,label:n(`setup.check.title`),key:`setup.check.title`},{id:`plan`,label:n(`setup.plan.step`),key:`setup.plan.step`},{id:`download`,label:n(`setup.download.step`),key:`setup.download.step`},{id:`test`,label:n(`setup.test.step`),key:`setup.test.step`},{id:`ready`,label:n(`setup.ready.step`),key:`setup.ready.step`}],fn=e=>e===`models`||e===`key`?`plan`:e===`gpu`?d===`check`?`check`:`plan`:e,pn=rt?`key`:l?`models`:`plan`,mn=un.findIndex(e=>e.id===fn(sn)),hn=e=>e===`download`||e===`test`||e===`ready`,gn=[];if(b){let e=[L?.system?.physical_memory?`${MS(L.system.physical_memory,null)} installed`:null,b.ram_gb==null?null:`${b.ram_gb} GB the OS can use`].filter(Boolean).join(`, `),t=b.disk_free_gb==null?null:`${Math.round(b.disk_free_gb)} GB free on disk`;gn.push(`This PC: ${[b.gpu_name,b.npu_detected?`NPU`:null].filter(Boolean).join(`, `)||`no GPU reported`}`+[e,t].filter(Boolean).map(e=>`; ${e}`).join(``))}else S&&gn.push(`Couldn't read this PC: ${S}`);Ue&&(gn.push(`Found your Lemonade${Ue.version?` ${Ue.version}`:``} at ${Ue.url}`),gn.push(Ge===`external`?`You chose your own Lemonade`:Ge===`gaia`?`You chose GAIA's own Lemonade`:`Waiting for you to choose which Lemonade GAIA uses`)),L&&(!Ue||Ge)?gn.push(L.lemonade.reachable?`Model server answering at ${L.lemonade.url??`its address`}`:`No model server answering yet`):R&&gn.push(`Couldn't read the model list: ${R}`);let _n=(e,t)=>t<=mn||_.has(e)&&!hn(e),vn=un.map((e,t)=>({id:e.id,label:e.label,status:t<mn?`done`:t>mn?`pending`:sn===`ready`?`done`:Qt&&(sn===`download`||sn===`test`||sn===`check`)?`failed`:st&&(sn===`download`||sn===`test`)?`active`:`current`,shown:e.id===fn(cn),onOpen:e.id!==fn(cn)&&_n(e.id,t)?()=>Mt(e.id===`plan`?pn:e.id):void 0})),bn=un.findIndex(e=>e.id===fn(cn)),xn=cn===`gpu`&&d===`check`?.5:yN.indexOf(cn),Sn=(0,X.useRef)(xn),Cn=(0,X.useRef)(`forward`);Sn.current!==xn&&(Cn.current=xn>Sn.current?`forward`:`back`,Sn.current=xn);let wn=cn===`gpu`?d:cn===`models`||cn===`key`?`plan`:bn>0?un[bn-1].id===`plan`?pn:un[bn-1].id:null,Tn=(cn!==`gpu`&&bn>=0&&bn<un.length-1&&_n(un[bn+1].id,bn+1)?un[bn+1].id:null)??(h==null?cn===`check`&&Tt?`plan`:cn===`gpu`?d:null:null);Bt.current={prev:wn,next:Tn};let En=cn===`gpu`||cn===`models`||cn===`key`,Dn=h!=null&&st,On=[`server`];rt||On.push(`chat`),!rt&&B&&aj(tn,B)&&On.push(`vision`),B&&tn.some(e=>ej(e)&&B.ticked.has(e.id))&&On.push(`embedding`);for(let e of tn)B&&rj(e)&&B.ticked.has(e.id)&&!e.downloaded&&On.push(e.roles[0]);On.push(`agent`);let kn=B&&!rt?tn.filter(e=>rj(e)&&!B.ticked.has(e.id)&&!e.downloaded&&(ij(an)||!e.roles.includes(`image_creation`))):[],An=tn.find(e=>e.fit_code===`memory`&&e.chat_choice&&e.support===`verified`);return V(`main`,{className:`setup`,"aria-labelledby":`setup-title`,children:[P(eN,{steps:vn}),P(Gj,{value:p,children:V(`div`,{className:`setup-pane`,children:[V(`div`,{className:`setup-inner`,children:[bn>=0&&V(`nav`,{className:`setup-topnav`,"aria-label":n(`setup.nav.label`),children:[P(`button`,{type:`button`,className:`setup-arrow`,onClick:()=>wn&&Mt(wn),disabled:!wn,"aria-label":n(`setup.nav.prev`),children:P(vr,{size:16,"aria-hidden":`true`})}),P(`button`,{type:`button`,className:`setup-arrow`,onClick:()=>Tn&&Mt(Tn),disabled:!Tn,"aria-label":n(`setup.nav.next`),children:P(br,{size:16,"aria-hidden":`true`})}),P(`span`,{children:P(`bdi`,{children:n(`setup.nav.stepOf`,{n:String(bn+1),total:String(un.length)})})}),h!=null&&h!==sn&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>g(null),children:n.compose(e=>e(`setup.nav.toLive`,{step:e(un.find(e=>e.id===sn)?.key??`setup.download.step`)}))}),P(jM,{})]}),ge&&s!==`download`&&V(`div`,{className:`setup-banner`,role:`status`,children:[P(Hi,{size:14,"aria-hidden":`true`}),P(`span`,{children:n(`setup.resume.banner`)})]}),Ae&&s!==`download`&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.interrupted`)}),V(`div`,{className:`setup-stage is-${Cn.current}`,children:[cn===`check`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(Tt?`setup.check.headingDone`:`setup.check.heading`)}),P(`p`,{className:`setup-lede`,children:n(Tt?`setup.check.ledeDone`:`setup.check.lede`)}),P($M,{hardware:b,hardwareError:S,plan:L,serverRun:at,awaitingChoice:!!Ue&&!ze}),Tt&&L&&P(ZM,{plan:L,hardware:b,onChangeMemory:It&&h==null?()=>zt(`check`):void 0}),Tt&&h==null&&!(Ue&&!ze)&&P(Kj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>Mt(`plan`),children:n(`setup.continue`)})}),at&&Qt&&V(D.Fragment,{children:[P(vN,{run:at}),at.problem?P(gN,{problem:at.problem,onRetry:()=>void wt(!1,{serverOnly:!0}),onUseGaia:()=>void wt(!0,{serverOnly:!0})}):P(Kj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void wt(!!at.gaia_lemonade,{serverOnly:!0}),children:n(`setup.tryAgain`)})})]}),R&&!L&&V(D.Fragment,{children:[P(_N,{text:R}),V(Kj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void wt(!1,{keepTrying:U}),children:n(`setup.models.useRecommended`)}),P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void gt(),children:n(`setup.tryAgain`)})]}),P(`p`,{className:`setup-hint`,children:n(`setup.models.useRecommendedNote`)})]}),A&&P(_N,{text:A}),A&&!at&&L&&!L.lemonade.reachable&&P(Kj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void wt(!1,{serverOnly:!0}),children:n(`setup.tryAgain`)})}),Ie&&L&&(!L.lemonade.reachable&&!at||Tt&&h==null&&L.lemonade.mode!==`external`)&&P(hN,{onNothingToOffer:He,canInstallOwn:!L.lemonade.reachable&&!at,onFound:We,onChosen:e=>{ke(e===`external`),Ke(e),Ve(!0),pt(),gt()}})]}),cn===`plan`&&L&&B&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.plan.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.plan.lede`)}),V(`section`,{className:`setup-hero`,"aria-label":n(`setup.plan.label`),children:[P(`p`,{className:`setup-eyebrow`,children:B.chatChosen?n(`setup.plan.yours`):n(`setup.plan.recommended`)}),P(`p`,{className:`setup-hero-title`,children:P(`bdi`,{children:n(`setup.plan.run`,{name:an?.name??``})})}),V(`dl`,{className:`setup-facts`,children:[V(`div`,{children:[P(`dt`,{children:n(`setup.summary.download`)}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:$(yj(L,B).downloadGb??0)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.plan.runsOn`)}),P(`dd`,{children:P(`bdi`,{children:an&&tj(an)?n(`setup.checks.npu`):b?.gpu_name??n(`setup.plan.cpu`)})})]}),V(`div`,{children:[P(`dt`,{children:n(`setup.plan.diskAfter`)}),P(`dd`,{children:P(`bdi`,{dir:`ltr`,children:yj(L,B).afterGb==null?`—`:$(Math.max(0,yj(L,B).afterGb))})})]})]}),V(`ul`,{className:`setup-reasons`,children:[!B.chatChosen&&P(`li`,{children:n(`setup.plan.why.evaluated`)}),an?.need_gb!=null&&an.capacity_gb!=null&&an.fits&&P(`li`,{children:n(`setup.plan.why.fits`,{need:NS(an.need_gb),have:NS(an.capacity_gb)})}),P(`li`,{children:n(`setup.plan.why.private`)}),an&&tj(an)&&P(`li`,{children:n(`setup.plan.why.noImagesNpu`)}),An&&An.id!==an?.id&&An.need_gb!=null&&An.capacity_gb!=null&&P(`li`,{children:n(`setup.plan.why.bigger`,{name:An.name,need:NS(An.need_gb),have:NS(An.capacity_gb)})})]}),P(Kj,{children:V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>rn?le({kind:`low_disk`}):void jt(!1),disabled:fe||on||Dn,children:[fe&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,nn.length?n(`setup.plan.start`):n(`setup.plan.startNoDownload`)]})}),V(`div`,{className:`setup-row`,children:[P(`button`,{type:`button`,className:`link-btn`,onClick:Pt,disabled:Dn,children:n(`setup.plan.customize`)}),P(`button`,{type:`button`,className:`link-btn`,onClick:Ft,disabled:Dn,children:n(`setup.plan.cloud`)}),t&&P(`button`,{type:`button`,className:`link-btn`,onClick:t,children:n(`setup.backToGaia`)})]}),on&&V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:n(`setup.blocked`)}),V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:b?.blockers.join(`
|
|
81
|
+
`)})]})]}),rn&&P(`p`,{className:`setup-error`,role:`alert`,children:n(`setup.summary.short`,{need:$(rn.needGb),free:$(rn.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(rn.freeUpGb)})}),(me??A)&&P(_N,{text:me??A})]}),V(`details`,{className:`setup-disclosure`,children:[P(`summary`,{children:n(`setup.plan.whatDownloads`)}),P(hM,{plan:L,models:nn})]})]}),cn===`gpu`&&oe&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.gpu.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.gpu.lede`)}),P(nM,{status:oe,onStatus:H,mode:`setup`,headingId:`setup-title`,names:Xt,onBack:Lt,onSkip:()=>Mt(d),onContinue:()=>Mt(d)})]}),cn===`models`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.models.title`)}),L&&B&&P(LM,{plan:L,selection:B,onSelection:te,disabled:fe||Dn,onRecheck:()=>void gt()}),It&&oe?.total_gb!=null&&oe.gpu_gb!=null&&V(`p`,{className:`setup-hint setup-gpu-option`,children:[n(`setup.models.gpu`,{gpu:$(oe.gpu_gb),total:$(oe.total_gb)}),` `,P(`button`,{type:`button`,className:`link-btn`,onClick:()=>zt(`models`),disabled:fe||Dn,children:n(`setup.found.changeMemory`)})]}),P(rM,{plan:L,planError:R,onRetryPlan:()=>void gt(),onUseRecommended:()=>void wt(!1,{keepTrying:U}),selection:B,onSelection:te,cloud:!1,keepTrying:U,onKeepTrying:se,onBack:Lt,onContinue:e=>void jt(e),busy:fe||Dn,error:me??A})]}),cn===`key`&&V(`form`,{id:`setup-key-form`,onSubmit:e=>{e.preventDefault(),Gt()},className:`setup-form`,children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.key.title`)}),P(`div`,{className:`setup-choices`,role:`radiogroup`,"aria-label":n(`setup.key.provider`),children:cN.filter(e=>e.id!==`local`).map(e=>V(`button`,{type:`button`,role:`radio`,"aria-checked":a===e.id,className:`setup-choice${a===e.id?` is-active`:``}${tt(e.id)?` is-disabled`:``}`,onClick:()=>Kt(e.id),disabled:F.busy||tt(e.id),title:et(e.id)?n(`settings.privacy.localOnlyBlocked`):void 0,children:[P(Ir,{size:16,"aria-hidden":`true`}),V(`span`,{children:[P(`span`,{className:`setup-choice-title`,children:P(`bdi`,{children:lN(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:oN,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:sN,target:`_blank`,rel:`noreferrer`,children:n(`setup.key.gatewayHelp`)})})}),!et(a)&&P(GA,{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(Kj,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:Nt,disabled:F.busy,children:n(`setup.back`)}),V(`button`,{type:`submit`,form:`setup-key-form`,className:`btn-primary`,disabled:F.busy||tt(a)||Dn,children:[F.busy&&P(q,{size:13,className:`spin`}),` `,n(`setup.key.connect`)]})]})]}),cn===`download`&&!K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.download.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.download.lede`)}),V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.starting`)]})]}),cn===`download`&&K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.download.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.download.lede`)}),L&&P(`section`,{className:`setup-card`,"aria-label":n(`setup.contents.title`),children:P(hM,{plan:L,run:K,onRetry:Et,retryDisabled:fe})}),(K.models?.length??0)>0?P(`div`,{className:O?`is-stale`:void 0,children:P(DM,{status:{...K,overall:wj(K,ne??L)},names:Xt,freeGb:L?.disk?.free_gb??null,onCancel:()=>void Vt(),onRetry:(e,t)=>void Ht(e,t),onResume:e=>void Ht(e,null),onResumeAll:Et,onSkip:e=>void Ut(e),onRestart:()=>void Wt(),busy:fe||!!O,retryLater:st,labelledBy:`setup-title`})}):st?V(`p`,{className:`setup-hint`,role:`status`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,n(`setup.download.working`)]}):null,kn.length>0&&V(`section`,{className:`setup-card`,"aria-label":n(`setup.optional.title`),children:[P(`h3`,{className:`mc-job-title`,children:n(`setup.optional.title`)}),P(`p`,{className:`setup-hint`,children:n(`setup.optional.lede`)}),P(`ul`,{className:`setup-rows`,children:kn.map(e=>{let t=Se.includes(e.id);return V(`li`,{className:`setup-result is-waiting`,children:[P(`span`,{className:`setup-result-label`,children:n(`setup.purpose.${e.roles[0]}`)}),V(`span`,{className:`setup-result-value`,children:[P(`bdi`,{dir:`ltr`,children:e.size_gb==null?n(`setup.contents.sizeOnDownload`):$(e.size_gb)}),P(`button`,{type:`button`,className:`btn-secondary`,"aria-pressed":t,onClick:()=>we(n=>t?n.filter(t=>t!==e.id):[...n,e.id]),children:n(t?`setup.optional.added`:`setup.optional.add`)})]})]},e.id)})})]}),O&&V(D.Fragment,{children:[P(`p`,{className:`setup-error`,role:`alert`,children:n(`setup.lostContact`,{error:O})}),P(Kj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void St(),children:n(`setup.reconnect`)})})]}),Qt&&$t&&!en&&K.state===`failed`&&!K.model_failed&&(K.problem?P(gN,{problem:K.problem,onRetry:Et,onUseGaia:()=>void wt(!0,Me.current.options)}):V(`div`,{className:`setup-error`,role:`alert`,children:[P(`p`,{children:n(`setup.download.stoppedBeforeCheck`)}),K.error&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:K.error})]})]})),Qt&&$t&&!en&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.download.finishNote`)}),P(Kj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:Et,disabled:fe,children:n(`setup.finish`)})})]}),Qt&&!$t&&!en&&!(K.models??[]).some(e=>e.state===`failed`||e.state===`cancelled`)&&V(D.Fragment,{children:[P(vN,{run:K}),K.problem?P(gN,{problem:K.problem,onRetry:Et,onUseGaia:()=>void wt(!0,Me.current.options)}):P(Kj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void wt(!!K.gaia_lemonade,Me.current.options),children:n(`setup.tryAgain`)})})]}),(me||A)&&P(_N,{text:me??A})]}),cn===`test`&&K&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.test.title`)}),P(`p`,{className:`setup-lede`,children:n(`setup.test.lede`)}),P(aN,{run:K,expected:On,names:Xt,catalog:tn,onRetry:Et,onChooseAnother:rt?void 0:Pt,onCancel:()=>void Vt(),onDownloadAgain:L?.lemonade.mode===`external`?void 0:e=>void Ht(e,`verify`),busy:fe}),Qt&&K.error&&!(K.tests??[]).some(e=>e.error===K.error)&&V(`details`,{className:`dl-details`,children:[P(`summary`,{children:n(`setup.progress.details`)}),P(`pre`,{dir:`ltr`,children:K.error})]}),(me||A)&&P(_N,{text:me??A})]}),cn===`ready`&&V(D.Fragment,{children:[P(`h1`,{id:`setup-title`,className:`setup-title`,tabIndex:-1,children:n(`setup.ready.heading`)}),V(`div`,{className:`setup-done`,role:`status`,children:[P(`div`,{className:`setup-done-head`,children:Jt&&P(`p`,{children:n(rt?`setup.ready.answersCloud`:`setup.ready.answersLocal`,{model:rt?vs(Jt):Xt[Jt]??ie?.catalog?.find(e=>e.id===Jt)?.name??vs(Jt)})})}),P(Kj,{children:P(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Yt(),autoFocus:!0,children:n(`setup.ready.start`)})}),!rt&&ie&&P(iM,{plan:ie,chatModel:Jt,gpu:oe}),A&&P(_N,{text:A}),(K?.tests??[]).filter(e=>e.state===`failed`).map(e=>P(`p`,{className:`setup-failed-extra`,role:`alert`,children:n(`setup.ready.extraFailed`,{job:n(`setup.test.job.${e.job}`)})},`${e.job}:${e.subject??``}`)),Ee.length>0&&!W&&P(`p`,{className:`setup-failed-extra`,role:`alert`,children:n(`setup.ready.extraNotFetched`,{names:Ee.map(e=>Xt[e]??e).join(`, `)})}),be.length>0&&V(D.Fragment,{children:[P(`p`,{className:`setup-hint`,children:n(`setup.ready.tasks`)}),P(lM,{cards:be,onPick:e=>void Yt(e)})]})]})]})]},cn),t&&!st&&cn!==`plan`&&cn!==`ready`&&P(`div`,{className:`setup-row`,children:P(`button`,{type:`button`,className:`link-btn setup-close`,onClick:t,children:n(`setup.backToGaia`)})}),Dn&&(En||cn===`plan`)&&P(`p`,{className:`setup-hint`,role:`status`,children:n(`setup.nav.runGoing`)}),P(AM,{run:w,before:{check:gn}})]}),P(`div`,{className:`setup-footer`,ref:m})]})}),W?.kind===`no_fit`&&P(qj,{title:W.models.length===1?n(`setup.confirm.noFitOne`,{name:W.models[0].name}):n(`setup.confirm.noFitMany`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.pickSmaller`),onConfirm:()=>{le(null),de(!0),jt(Ot,!0)},onCancel:()=>le(null),children:W.models.map(e=>V(`p`,{children:[P(`bdi`,{children:e.name}),`: `,jj(e,n)]},e.id))}),W?.kind===`low_disk`&&rn&&P(qj,{title:n(`setup.confirm.lowDiskTitle`),confirmLabel:n(`setup.confirm.downloadAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{le(null),jt(!0)},onCancel:()=>{le(null),Pt()},children:P(`p`,{children:n(`setup.summary.short`,{need:$(rn.needGb),free:$(rn.freeGb),drive:n(`setup.summary.theDrive`),freeUp:$(rn.freeUpGb)})})}),W?.kind===`server`&&P(qj,{title:W.detail.code===`low_disk`?n(`setup.confirm.lowDiskTitle`):n(`setup.confirm.noFitServerTitle`),confirmLabel:W.detail.code===`low_disk`?n(`setup.confirm.downloadAnyway`):n(`setup.confirm.useAnyway`),cancelLabel:n(`setup.confirm.changeModels`),onConfirm:()=>{let e=W;if(le(null),e.then===`chat`)de(!0),jt(Ot,!0);else if(e.then===`retry`)Te(e.id,{keepTrying:U,acknowledgeLowDisk:!0}).then(E).catch(e=>he(bN(e)));else{let{gaiaLemonade:e,options:t}=Me.current;wt(e,{...t,acknowledgeLowDisk:!0})}},onCancel:()=>{let e=W;le(null),e.then!==`retry`&&!ct&&Pt()},children:P(`p`,{children:W.detail.message})})]})}function SN(e,t,n){let r=(0,X.useRef)(n);(0,X.useEffect)(()=>{r.current=n});let i=(0,X.useRef)(!1),a=(0,X.useRef)(null);if(t&&!i.current){let e=document.activeElement;a.current=e instanceof HTMLElement?e:null}(0,X.useEffect)(()=>{if(!t)return;i.current=!0;let n=a.current,o=e.current;if(o&&!o.contains(document.activeElement)){let e=r.current?.()??oS(o)[0];e?e.focus():(o.hasAttribute(`tabindex`)||o.setAttribute(`tabindex`,`-1`),o.focus())}return()=>{i.current=!1;let e=document.activeElement;(!e||e===document.body||o?.contains(e))&&n?.isConnected&&n.focus()}},[e,t])}function CN({title:e,titleId:t,count:n,hint:r,defaultOpen:i=!1,forceOpen:a=!1,children:o}){let[s,c]=(0,X.useState)(i);return V(`details`,{className:`settings-disclosure`,open:s||a,onToggle:e=>{a||c(e.currentTarget.open)},children:[V(`summary`,{onClick:e=>{a&&e.preventDefault()},children:[P(gr,{size:15,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),V(`span`,{className:`settings-disclosure-text`,children:[P(`span`,{className:`settings-disclosure-title`,id:t,tabIndex:t?-1:void 0,children:e}),r&&P(`span`,{className:`settings-disclosure-hint`,children:r})]}),n!=null&&P(`bdi`,{dir:`ltr`,className:`settings-disclosure-count`,children:n})]}),P(`div`,{className:`settings-disclosure-body`,children:o})]})}var wN=g(Tc()?`settings.desktop.menuBar`:`settings.desktop.tray`),TN=[{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`}],EN=new Set([`startMinimized`]),DN={minimizeToTray:`settings.desktop.keepRunningNoTray`};function ON(e){return e?.reason===`no-host`?`settings.desktop.noTray`:e?.reason===`check-failed`?`settings.desktop.noTrayCheckFailed`:null}function kN(){let e=T(),t=window.gaiaAPI?.tray,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null);(0,X.useEffect)(()=>{t&&t.getConfig().then(e=>{r(e.tray),a(e.host)}).catch(t=>s(e(`settings.desktop.readFailed`,{reason:t instanceof Error?t.message:String(t)})))},[t,e]);let u=(0,X.useCallback)(async e=>{if(t&&n&&c===null){l(e),s(null);try{let i=await t.setConfig({tray:{[e]:!n[e]}});r(i.tray),a(i.host)}catch(e){s(e instanceof Error?e.message:String(e))}finally{l(null)}}},[t,n,c]);if(!t)return null;let d=ON(i);return P(CN,{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`)}),TN.map(({key:t,label:r,hint:i})=>{let a=EN.has(t)?d:null,o=d&&DN[t]||i;return V(`div`,{children:[V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(r,{tray:wN})}),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:wN})}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,id:`desktop-${t}-hint`,children:a?e(a):e(o,{tray:wN})})]},t)}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o})]})})}function AN(){return window.gaiaUpdater}var jN={status:`idle`,version:null,progress:0,releaseNotes:null,error:null,currentVersion:null,pinnedVersion:null,autoUpdate:!1,includePrereleases:!1};function MN(){let[e,t]=(0,X.useState)({...jN});return(0,X.useEffect)(()=>{let e=AN();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 NN=`gaia-update-error:`;function PN(e,t){let n=`update.err.${e}`;return N(n)?g(n,t??{}):null}function FN(e){let t=e instanceof Error?e.message:String(e),n=t.indexOf(NN);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=PN(r.code,r.params)??r.message??r.code,a=r.note&&PN(r.note.code,r.note.params);return a?g(`update.err.withNote`,{error:i,note:a}):i}function IN(e,t){let n=FN(e);return typeof n==`object`?t(n.ref,n.params):String(n)}function LN(){return window.gaiaUpdater}function RN({onClose:e}){let t=T(),[n,r]=(0,X.useState)({kind:`loading`}),i=(0,X.useRef)(null);(0,X.useEffect)(()=>{let e=LN();e?e.listReleases().then(e=>{r(Array.isArray(e)?{kind:`list`,releases:e}:{kind:`error`,message:e.error})}).catch(()=>{r({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})}):r({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})},[]),Io(!0,e),sS(i,!0),(0,X.useEffect)(()=>{let e=i.current;e&&e.querySelector(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`)?.focus()},[]),(0,X.useEffect)(()=>{let e=i.current;if(!e)return;function t(t){if(t.key!==`Tab`||!e)return;let n=e.querySelectorAll(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`);if(n.length===0)return;let r=n[0],i=n[n.length-1];t.shiftKey?document.activeElement===r&&(t.preventDefault(),i?.focus()):document.activeElement===i&&(t.preventDefault(),r?.focus())}return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[]);function a(e,t){e.isCurrent||r({kind:`confirm`,release:e,releases:t})}async function o(n){r({kind:`installing`});let i=LN();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:FN(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 zN=`https://github.com/amd/gaia/releases`;function BN(e){return/^\d+\.\d+\.\d+-/.test(e??``)}function VN(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 HN(){let e=MN(),t=T(),n=AN(),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1);if(!n)return null;async function l(e,r){if(n){i(!0),o(null);try{await r(n)}catch(n){d.system.error(`${e} failed`,n),o(t(`update.settings.failed`,{action:g(e),reason:FN(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`)})} ${VN(e,t)}`,m=[`available`,`downloaded`,`error`].includes(e.status)||!!e.pinnedVersion||!!e.installFailed||!!e.configError||!!a;return P(CN,{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`),BN(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:zN})}),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(RN,{onClose:()=>c(!1)})]})})}var UN=[{value:`light`,label:`settings.theme.light`},{value:`dark`,label:`settings.theme.dark`},{value:`system`,label:`settings.theme.system`}],WN={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`},GN=[[`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 KN(){let e=T(),t=k(e=>e.locale),n=k(e=>e.setLocale),r=k(e=>e.themePreference),i=k(e=>e.setThemePreference),a=k(e=>e.palette),o=k(e=>e.setPalette),s=k(e=>e.customColors),c=k(e=>e.setCustomColors),l=qO(e=>e.visible),u=qO(e=>e.setVisible),d=e=>t=>c({...s,[e]:t.target.value.toUpperCase()});return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.general`)}),V(`div`,{className:`settings-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`ui-language`,children:e(`settings.language`)}),P(`select`,{id:`ui-language`,className:`settings-input`,value:t,onChange:e=>n(e.target.value),children:b.map(({meta:e})=>P(`option`,{value:e.code,lang:e.code,dir:e.dir,children:M(e)},e.code))}),P(`span`,{className:`settings-hint`,children:e(`settings.languageHint`)})]}),V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,id:`appearance-label`,children:e(`settings.appearance`)}),P(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`appearance-label`,children:UN.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(CN,{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(WN[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(kN,{}),P(HN,{}),P(CN,{title:e(`settings.shortcuts`),children:P(`dl`,{className:`shortcut-list`,children:GN.map(([t,n])=>V(`div`,{className:`shortcut-row`,children:[P(`dt`,{children:P(`kbd`,{children:kc(t)})}),P(`dd`,{children:e(n)})]},t))})})]})}function qN(e){return/not reachable|not answering|model server at|ConnectionPool|NewConnectionError|Connection refused|Max retries/i.test(e)}function JN(e){return/gaia init/i.test(e??``)}function YN(e){return!!e&&!e.lemonade_running&&(JN(e.start_command)||JN(e.start_instruction))}function XN({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 ZN({message:e,onRetry:t}){let n=T(),r=k(e=>YN(e.systemStatus));return qN(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(XN,{className:`btn-primary`}),t&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:t,children:n(`settings.key.checkAgain`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,n(`settings.errors.details`)]}),P(`bdi`,{dir:`ltr`,className:`settings-notice-raw`,children:e})]})]}):P(`p`,{className:`settings-error`,role:`alert`,children:e})}function QN({onAdded:e}){let t=T(),[n,r]=(0,X.useState)(``),[i,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),f=(0,X.useRef)(``),p=(0,X.useCallback)(async e=>{let t=n.trim();f.current=t,l(`check`),d(null);try{let n=await cn(t,e);if(f.current!==t)return;s(n),a(n.file??e)}catch(e){if(f.current!==t)return;s(null),d(e instanceof Error?e.message:String(e))}finally{l(null)}},[n]),m=(0,X.useCallback)(async()=>{l(`add`),d(null);try{let{report:o}=await xt(n.trim(),i);r(``),a(``),s(null),e(o.display_name??o.model_id??t(`settings.custom.theModel`))}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(null)}},[e,i,n,t]);return V(`form`,{className:`settings-field custom-model-add`,onSubmit:e=>{e.preventDefault(),p(``)},children:[P(`label`,{className:`visually-hidden`,htmlFor:`custom-model-url`,children:t(`settings.custom.title`)}),P(`span`,{className:`settings-hint`,children:t(`settings.custom.hint`)}),V(`div`,{className:`settings-row`,children:[P(`input`,{id:`custom-model-url`,className:`settings-input`,type:`url`,inputMode:`url`,dir:`ltr`,spellCheck:!1,autoComplete:`off`,value:n,readOnly:c!==null,onChange:e=>{r(e.target.value),s(null),a(``),f.current=``},placeholder:`https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF`}),V(`button`,{type:`submit`,className:`btn-secondary`,disabled:c!==null||!n.trim(),children:[c===`check`?P(q,{size:13,className:`spin`}):null,` `,t(`settings.custom.check`)]})]}),o&&(()=>{let e=P(`ul`,{className:`custom-model-checks`,"aria-label":t(`settings.custom.checks`),children:o.checks.map(e=>V(`li`,{className:e.ok?`is-ok`:`is-failed`,children:[e.ok?P(mr,{size:13,"aria-label":t(`settings.custom.passed`)}):P(Y,{size:13,"aria-label":t(`settings.custom.failed`)}),V(`bdi`,{children:[P(`strong`,{children:e.label}),` — `,e.detail]})]},e.id))});return o.ok?V(`details`,{className:`custom-model-checks-summary`,children:[V(`summary`,{children:[P(mr,{size:13,"aria-hidden":`true`}),` `,t(`settings.custom.allPassed`,{n:o.checks.length})]}),e]}):e})(),o&&o.warnings.length>0&&P(`ul`,{className:`custom-model-checks`,"aria-label":t(`settings.custom.warnings`),children:o.warnings.map(e=>V(`li`,{className:`is-warning`,children:[P(J,{size:13,"aria-label":t(`settings.custom.warning`)}),` `,P(`bdi`,{children:e})]},e))}),o&&o.variants.length>1&&V(`div`,{className:`settings-row`,children:[P(`label`,{className:`settings-hint`,htmlFor:`custom-model-quant`,children:t(`settings.custom.quantization`)}),P(`select`,{id:`custom-model-quant`,className:`settings-input`,value:i,onChange:e=>void p(e.target.value),disabled:c!==null,children:o.variants.map(e=>V(`option`,{value:e.file,children:[e.quant,` · `,e.size_gb,` GB`,e.fits?``:` · ${t.bare(`settings.custom.tooLarge`)}`]},e.file))})]}),o?.ok&&V(`div`,{className:`settings-row`,children:[V(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void m(),disabled:c!==null,children:[c===`add`?P(q,{size:13,className:`spin`}):null,` `,t(`settings.custom.add`,{name:o.display_name??``})]}),P(`span`,{className:`settings-hint`,children:t(`settings.model.sizeDownload`,{size:`${o.size_gb} GB`})})]}),u&&P(ZN,{message:u})]})}function $N(e){return e instanceof Error?e.message:String(e)}function eP(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function tP({downloadsSlot:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(null),b=Ls(e=>e.status),x=Ls(e=>e.started),S=(0,X.useMemo)(()=>Ps(b,x),[b,x]),C=Ls(e=>e.error),w=Ls(e=>e.refresh),E=Ls(e=>e.enqueue),O=Ls(e=>e.cancel),k=(0,X.useCallback)(async(e=!1)=>{a(null);try{let t=await Ce();r(t),s(n=>e||!n?pj(t):n)}catch(e){a($N(e))}},[]);(0,X.useEffect)(()=>{k(!0),w(),(async()=>{try{_(await Nn()??null)}catch(e){y($N(e))}})()},[k,w]);let A=(S?.models??[]).filter(e=>e.state===`ready`).map(e=>e.id).join(`,`),j=(0,X.useRef)(A);(0,X.useEffect)(()=>{A!==j.current&&(j.current=A,k(!0))},[A,k]);let M=(0,X.useMemo)(()=>{let e={};for(let t of S?.models??[])e[t.id]=t;return e},[S]),N=(0,X.useMemo)(()=>{let e={};for(let t of n?.catalog??[])e[t.id]=t.name;return e},[n]),F=(0,X.useMemo)(()=>n?pj(n):null,[n]),I=QA(n),L=n&&o?vj(I,o).filter(e=>M[e.id]?.state!==`downloading`):[],ee=L.reduce((e,t)=>e+(t.size_gb??0),0),R=!!n&&!!o&&!!F&&(!eP(o.ticked,F.ticked)||o.defaultChat!==F.defaultChat||L.length>0),z=(0,X.useCallback)(async(e,i)=>{if(!n||!o)return;if(p(null),!e){let e=xj(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=bj(n,o);if(a&&!i)l({kind:`low_disk`,message:a.drop?t(`setup.summary.shortDrop`,{need:$(a.needGb),free:$(a.freeGb),drive:Fj(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:Fj(n.disk?.path??null)??t(`setup.summary.theDrive`),freeUp:$(a.freeUpGb)})});else{d(!0);try{let i=n;if(o.defaultChat&&o.defaultChat!==i.chat_model.id)try{i=await Le(o.defaultChat,e||m)}catch(e){let t=ht(e);if(t){l({kind:`server`,detail:t});return}throw e}for(let e of Sj(i,o))i=await ft(e.id,e.skipped);let a=vj(QA(i),o).map(e=>e.id).filter(e=>M[e]?.state!==`downloading`);r(i),s({...o,defaultChat:i.chat_model.id}),cs.getState().refresh(),a.length&&await E(a,{acknowledgeLowDisk:!0}),p({ok:!0,text:t(`settings.models.applied`)})}catch(e){p({ok:!1,text:$N(e)})}finally{d(!1)}}},[n,o,I,m,M,E,t]),B=(0,X.useCallback)(async e=>{l(null),d(!0),p(null);try{let n=await dn(e.id);Uo(),r(n),s(pj(n)),p({ok:!0,text:t(`settings.models.removed`,{name:e.name,size:$(n.freed_gb)})})}catch(e){p({ok:!1,text:$N(e)})}finally{d(!1)}},[t]),te=(0,X.useCallback)((e,t)=>{(async()=>{try{t===`verify`&&await dn(e),await E([e])}catch(e){p({ok:!1,text:$N(e)})}})()},[E]),ne=!!S&&(S.models?.length??0)>0&&(wM(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(DM,{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(CN,{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(ZN,{message:i}),n&&!n.lemonade.reachable&&P(`p`,{className:`settings-hint`,children:t(`settings.models.unavailable`)}),!n&&!i&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`,"aria-hidden":`true`}),` `,t(`setup.models.loading`)]}),n&&n.lemonade.reachable&&o&&V(D.Fragment,{children:[P(Lj,{plan:n,selection:o,onToggle:(e,t)=>s(hj(o,I,e,t)),onDefaultChat:e=>s(gj(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(Pj,{plan:n,selection:o}),P(`div`,{className:`models-apply`,children:V(`button`,{type:`button`,className:`btn-primary`,disabled:!R||u,onClick:()=>void z(!1,!1),children:[u&&P(q,{size:13,className:`spin`,"aria-hidden":`true`}),u?t(`settings.models.applying`):L.length>0?t(`settings.models.applyDownload`,{size:$(Math.round(ee*10)/10)}):t(`settings.models.apply`)]})})]}),f?.ok&&P(`p`,{className:`settings-ok`,role:`status`,children:f.text}),f&&!f.ok&&P(ZN,{message:f.text})]})}),(g?.applies||v&&!qN(v))&&P(CN,{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(nM,{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(qj,{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:$A(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(qj,{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}),`: `,jj(e,t)]},e.id))}),c?.kind===`low_disk`&&P(qj,{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(qj,{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 nP=`auto`;function rP({model:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null);(0,X.useEffect)(()=>{r(null),a(null),l(null),_e(e).then(r).catch(e=>a(e instanceof Error?e.message:String(e)))},[e]);let u=(0,X.useCallback)(async n=>{s(!0),a(null),l(null);try{let i=await Ke(e,n===nP?null:Number(n));r(i);let a={name:i.display_name,size:i.chosen?Cs(i.chosen):g(`settings.ctx.automaticSize`)},o=i.reload?.reason;i.reload?.started?l(t(`settings.ctx.reloading`,a)):l(o===`already_loaded`?t(`settings.ctx.alreadyLoaded`,a):o===`warm_up`?t(`settings.ctx.warmUp`,a):o===`busy`?t(`settings.ctx.busy`,a):o===`not_gaias_server`?t(`settings.ctx.ownServer`,a):t(o===`restarting`?`settings.ctx.restarting`:`settings.ctx.nextLoad`))}catch(e){a(e instanceof Error?e.message:String(e))}finally{s(!1)}},[e,t]);if(i&&!n)return qN(i)?P(`p`,{className:`settings-hint`,children:t(`settings.ctx.serverDown`)}):P(`p`,{className:`settings-error`,role:`alert`,children:i});if(!n)return V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.ctx.checking`)]});let d=n.chosen==null?nP: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:nP,children:n.automatic?t.bare(`settings.ctx.automaticAt`,{size:Cs(n.automatic)}):t.bare(`settings.ctx.automatic`)}),n.options.map(e=>P(`option`,{value:String(e),children:t.bare(`settings.ctx.tokens`,{size:Cs(e)})},e))]})]}),n.note&&P(`span`,{className:`settings-hint`,children:P(`bdi`,{children:n.note})}),!n.note&&!!n.max_fit&&V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.ctx.about`)]}),P(`span`,{className:`settings-hint`,children:t(`settings.ctx.explain`,{size:Cs(n.max_fit),name:n.display_name,memory:n.memory_source})})]}),f&&P(`span`,{className:`settings-hint`,children:t(`settings.ctx.loadedAt`,{size:Cs(n.loaded_ctx)})}),o&&V(`span`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.ctx.applying`)]}),c&&P(`p`,{className:`settings-ok`,role:`status`,children:c}),i&&P(`p`,{className:`settings-error`,role:`alert`,children:i})]})}function iP({row:e,providerName:t,choices:n,labels:r,disabled:i,onSwitch:a}){let o=T(),s=cs(e=>e.active),c=s?.model??null,l=!!s?.remote,u=n.some(e=>us(c,e.id)),d=s?.downloaded??e?.downloaded,f=l?null:e?.state===`loaded`?o(`settings.model.loaded`):d===!0?o(`settings.model.downloaded`):d===!1?o(`settings.model.notDownloaded`):null,p=e?.placement?.device;return V(`section`,{className:`settings-card model-in-use`,"aria-label":o(`settings.model.inUseTitle`),children:[P(`span`,{className:`model-in-use-label`,children:o(`settings.model.inUseTitle`)}),c?P(`bdi`,{className:`model-in-use-name`,title:c,children:e?.display_name||s?.display_name||ds(c)}):P(`span`,{className:`settings-hint`,children:o(`settings.model.noneInUse`)}),s?.config_error&&P(`p`,{className:`settings-error`,role:`alert`,children:P(`bdi`,{children:s.config_error})}),c&&!l&&e?.available===!1&&P(`p`,{className:`settings-error`,role:`alert`,children:o(`settings.model.inUseCantRun`)}),c&&V(`span`,{className:`model-chips`,children:[l&&P(`span`,{className:`model-badge is-device`,children:o(`settings.model.cloud`)}),l&&t&&P(`bdi`,{className:`model-badge is-ready`,children:t}),p&&P(`span`,{className:`model-badge is-device`,children:p.toUpperCase()}),f&&P(`span`,{className:`model-badge ${e?.state===`loaded`?`is-loaded`:`is-ready`}`,children:f}),e?.fits===!0&&P(`span`,{className:`model-badge is-fit`,children:o(`settings.model.fits`)}),!!e?.size_gb&&V(`bdi`,{dir:`ltr`,className:`model-badge is-size`,children:[e.size_gb,` GB`]}),l&&!!e?.context_length&&P(`span`,{className:`model-badge is-ready`,children:o(`settings.model.contextChip`,{size:Cs(e.context_length)})})]}),(n.length>1||n.length===1&&!u)&&V(`div`,{className:`model-in-use-field`,children:[P(`label`,{className:`settings-label`,htmlFor:`model-switch`,children:o(`settings.model.switch`)}),V(`select`,{id:`model-switch`,className:`settings-input`,value:u?n.find(e=>us(c,e.id))?.id:``,onChange:e=>a(e.target.value),disabled:i,children:[!u&&P(`option`,{value:``,disabled:!0,children:o.bare(`settings.model.switchPlaceholder`)}),n.map(e=>P(`option`,{value:e.id,children:r[e.id]},e.id))]})]}),c&&!l&&s?.downloaded!==!1&&P(rP,{model:c})]})}function aP({model:e,label:t,current:n,remote:r,busy:i,confirmingRemove:a,onUse:o,onDownload:s,onAskRemove:c,onKeep:l,onRemove:u,onNpuRecheck:d}){let f=T(),p=Ts(e)?e.download_progress:null,m=e.placement?.label,h=f.compose(t=>[m&&(e.placement?.source===`expected`?t(`settings.model.expected`,{label:m}):m),e.size_gb?t(e.downloaded?`settings.model.sizeOnDisk`:`settings.model.sizeDownload`,{size:`${e.size_gb} GB`}):null,e.tokens_per_second?t(`settings.model.speed`,{speed:`${Math.round(e.tokens_per_second)} tok/s`}):null,!e.placement&&e.context_length?t(`settings.model.contextTokens`,{size:e.context_length.toLocaleString()}):null].filter(Boolean).join(` · `)),g=!!(e.display_name||h||e.evidence||e.custom&&e.source_url);return V(`li`,{className:`model-row${n?` is-current`:``}`,children:[V(`div`,{className:`model-row-text`,children:[P(`bdi`,{className:`model-row-name`,title:e.id,children:t}),V(`div`,{className:`model-chips`,children:[e.placement?.device&&P(`span`,{className:`model-badge is-device`,children:e.placement.device.toUpperCase()}),e.rank&&V(`span`,{className:`model-badge is-rank`,children:[V(`bdi`,{dir:`ltr`,children:[`#`,e.rank]}),` `,e.note]}),e.state===`loaded`&&P(`span`,{className:`model-badge is-loaded`,children:f(`settings.model.loaded`)}),e.fits===!0&&e.available!==!1&&P(`span`,{className:`model-badge is-fit`,children:f(`settings.model.fits`)}),e.custom&&P(`span`,{className:`model-badge is-custom`,children:f(`settings.model.custom`)}),!!e.size_gb&&V(`bdi`,{dir:`ltr`,className:`model-badge is-size`,children:[e.size_gb,` GB`]}),g&&V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,f(`settings.model.details`)]}),e.display_name&&P(`span`,{className:`model-row-meta`,children:P(`bdi`,{children:e.id})}),h&&P(`span`,{className:`model-row-meta`,children:h}),e.evidence&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.measured`,{evidence:e.evidence})}),e.custom&&e.source_url&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.from`,{url:e.source_url})})]})]}),r&&P(`span`,{className:`model-row-meta${e.price?``:` is-unknown-price`}`,children:QT(e.price,f)}),e.placement?.warning&&P(`span`,{className:`model-row-meta is-warning`,role:`alert`,children:P(`bdi`,{children:e.placement.warning})}),e.npu_problems?.length?P(FM,{problems:e.npu_problems,disabled:i!==null,onRecheck:d,id:`npu-problems-${e.id}`}):e.unavailable_reason&&P(`span`,{className:`model-row-meta`,children:f(`settings.model.cantRun`,{reason:e.unavailable_reason})}),p&&P(`progress`,{max:100,value:p.percent,"aria-label":f(`settings.model.downloadingAria`,{name:t})})]}),V(`div`,{className:`model-row-actions`,children:[e.custom&&!n&&!p&&(a?V(D.Fragment,{children:[V(`button`,{type:`button`,className:`btn-danger`,onClick:u,disabled:i!==null,children:[i===`rm:${e.id}`?P(q,{size:13,className:`spin`}):null,e.downloaded?f(`settings.model.removeDownload`):f(`settings.models.remove`)]}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:l,disabled:i!==null,children:f(`settings.models.keep`)})]}):P(`button`,{type:`button`,className:`btn-secondary`,onClick:c,disabled:i!==null,"aria-label":f(`settings.models.removeAria`,{name:t}),children:f(`settings.models.remove`)})),n&&e.available===!1?P(`span`,{className:`model-row-current is-blocked`,children:f(`settings.model.inUseBlocked`)}):n?V(`span`,{className:`model-row-current`,children:[P(mr,{size:13,"aria-hidden":`true`}),` `,f(`settings.model.inUse`)]}):e.available===!1?null:p?V(`span`,{className:`model-row-current`,children:[P(q,{size:13,className:`spin`}),` `,p.message?P(`bdi`,{children:p.message}):V(`bdi`,{dir:`ltr`,children:[Math.round(p.percent),`%`]})]}):e.downloaded?V(`button`,{type:`button`,className:`btn-secondary`,onClick:o,disabled:i!==null,"aria-label":f(`settings.model.useAria`,{name:t}),children:[i===e.id?P(q,{size:13,className:`spin`}):null,` `,f(`settings.model.use`)]}):V(`button`,{type:`button`,className:`btn-secondary`,onClick:s,disabled:i!==null,"aria-label":f(`settings.model.downloadAria`,{name:t}),children:[i===`dl:${e.id}`?P(q,{size:13,className:`spin`}):null,` `,f(`settings.model.download`)]})]})]})}function oP(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(!1),l=(0,X.useCallback)(async e=>{c(!0),i(null);try{let t=await e();n(t),o(t.limit_usd==null?``:String(t.limit_usd))}catch(e){i(e instanceof Error?e.message:String(e))}finally{c(!1)}},[]);if((0,X.useEffect)(()=>{l(H)},[l]),!t)return r?P(`p`,{className:`settings-error`,role:`alert`,children:r}):V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.spend.loading`)]});let u=t.limit_usd,d=a.trim()===``?null:Number(a),f=d===null||Number.isFinite(d)&&d>0,p=d!==u;return V(`section`,{className:`settings-field spending`,"aria-label":e(`settings.spend.aria`),children:[P(`span`,{className:`settings-label`,children:e(`settings.spend.title`)}),V(`p`,{className:`spending-total`,children:[P(`bdi`,{dir:`ltr`,children:P(`strong`,{children:$T(t.total_usd)})}),u!=null&&V(D.Fragment,{children:[` `,e(`settings.spend.ofLimit`,{limit:$T(u)})]}),V(`span`,{className:`settings-hint`,children:[` · `,e.plural(`settings.spend.turns`,t.turns)]})]}),t.unpriced_turns>0&&P(`p`,{className:`settings-hint`,children:e.plural(`settings.spend.unpriced`,t.unpriced_turns)}),t.unreported_turns>0&&P(`p`,{className:`settings-hint`,children:e.plural(`settings.spend.unreported`,t.unreported_turns)}),t.state===`near`&&V(`p`,{className:`spending-warning`,role:`status`,children:[P(J,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.near`)]}),t.state===`reached`&&V(`div`,{className:`spending-warning`,role:`alert`,children:[V(`p`,{children:[P(J,{size:13,"aria-hidden":`true`}),` `,e(`settings.spend.reached`)]}),P(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void l(gn),children:e(`settings.spend.allow`)})]}),t.state===`allowed_over`&&P(`p`,{className:`settings-hint`,children:e(`settings.spend.allowed`)}),V(`form`,{className:`settings-row`,onSubmit:e=>{e.preventDefault(),f&&p&&l(()=>Qe(d))},children:[P(`label`,{className:`spending-limit-label`,htmlFor:`spend-limit`,children:e(`settings.spend.limit`)}),P(`input`,{id:`spend-limit`,className:`settings-input`,type:`number`,min:`0.01`,step:`0.01`,inputMode:`decimal`,placeholder:e.bare(`settings.spend.noLimit`),value:a,onChange:e=>o(e.target.value),"aria-invalid":!f}),V(`button`,{type:`submit`,className:`btn-secondary`,disabled:s||!f||!p,children:[s?P(q,{size:13,className:`spin`}):null,` `,e(`settings.advanced.save`)]}),u!=null&&P(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void l(()=>Qe(null)),children:e(`settings.spend.removeLimit`)})]}),P(`span`,{className:`settings-hint`,children:e(`settings.spend.how`)}),r&&P(`p`,{className:`settings-error`,role:`alert`,children:r})]})}var sP=2e3;function cP(e,t){return e.key_source===`environment`?t(`settings.key.setIn`,{name:e.env_var??``}):`••••••••••••••••••••${e.key_hint?` ${e.key_hint}`:``}`}function lP(){let e=T(),t=cs(e=>e.active),n=cs(e=>e.select),r=cs(e=>e.refresh),i=cs(e=>e.rememberNames),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),l=k(e=>e.settingsProvider),[u,d]=(0,X.useState)(l??t?.provider??`local`),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(!1),[w,E]=(0,X.useState)(!1),[O,A]=(0,X.useState)({base_url:``,auth_header_name:``,auth_header_prefix:``}),[j,M]=(0,X.useState)(null),[N,F]=(0,X.useState)(null),[I,L]=(0,X.useState)(null),[ee,R]=(0,X.useState)(null),[z,B]=(0,X.useState)(!1),[te,ne]=(0,X.useState)(null),[re,ie]=(0,X.useState)(null),ae=(0,X.useRef)(u);ae.current=u;let oe=(0,X.useRef)(!0);(0,X.useEffect)(()=>(oe.current=!0,()=>{oe.current=!1}),[]);let H=a?.find(e=>e.id===u)??null,U=e=>e?.network?.reachable===!1,se=e=>!!e?.blocked,W=!!H&&!se(H)&&(!H.remote||!!H.models_discovered),G=(0,X.useCallback)(async()=>{c(null);try{let e=await Tn();o(e.providers),e.lemonade_error&&c(e.lemonade_error)}catch(e){c(e instanceof Error?e.message:String(e))}},[]),ce=(0,X.useCallback)(async(t,n=!1)=>{n||(p(null),h(null));try{let n=await Zt(t);i(n.models),p(n.models),F(n.memory_gb?`${n.memory_gb} GB (${n.memory_source})`:n.capacity_error??null),n.blocked&&h(e(`settings.privacy.localOnlyBlocked`))}catch(e){h(e instanceof Error?e.message:String(e))}},[i,e]);(0,X.useEffect)(()=>{G()},[G]);let le=!!a?.some(e=>e.key_state===`waiting_for_os_permission`);(0,X.useEffect)(()=>{if(!le)return;let e=setInterval(()=>{G()},sP);return()=>clearInterval(e)},[le,G]);let ue=t?.provider;(0,X.useEffect)(()=>{ue&&!l&&d(ue)},[ue,l]),(0,X.useEffect)(()=>{x(``),C(!1),E(!1),L(null),_(``),y(!1),B(!1)},[u]),(0,X.useEffect)(()=>{W?ce(u):p(null)},[u,W,ce]);let de=(0,X.useCallback)(async()=>{if(H){M(`connect`),L(null);try{let t=u===`amd`?{api_key:b||void 0,...Object.fromEntries(Object.entries(O).filter(([,e])=>e!==``))}:{api_key:b||void 0},n=()=>!oe.current||ae.current!==u,r=await Rt(u,t,e=>{n()||L({ok:!0,text:e})},n);if(n())return;x(``),C(!1),L({ok:!0,text:r.remember_error?e(`settings.key.sessionOnly`,{reason:r.remember_error}):r.known_models?e(`settings.key.knownModels`,{name:H.name}):r.remembered?e(`settings.key.kept`):e(`settings.key.connectedDone`)}),await G()}catch(e){oe.current&&ae.current===u&&L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{oe.current&&M(null)}}},[O,u,b,G,H,e]),pe=(0,X.useCallback)(async()=>{M(`forget`),E(!1),L(null);try{await Kt(u),L({ok:!0,text:e(`settings.key.cleared`)}),await G(),await r()}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[u,G,r,e]),me=(0,X.useCallback)(async t=>{M(t),L(null);try{await n(t),L({ok:!0,text:e(`settings.model.switched`,{name:ds(t)})}),await ce(u,!0)}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[u,ce,n,e]),he=(0,X.useCallback)(async e=>{M(`dl:${e}`),L(null),B(!1);try{await fe(e),await ce(`local`,!0)}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[ce]),ge=(0,X.useCallback)(async t=>{M(`rm:${t}`),L(null);try{let n=await nt(t);R(null);let i=n.cleared.includes(`last_model`)?`settings.model.removedLast`:n.cleared.includes(`default_model`)?`settings.model.removedDefault`:`settings.model.removed`;L({ok:!0,text:e(i,{name:n.display_name})}),await ce(`local`,!0),await r()}catch(e){L({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{M(null)}},[ce,r,e]),_e=(0,X.useCallback)(async t=>{L({ok:!0,text:e(`settings.model.added`,{name:t})}),B(!0),await ce(`local`,!0)},[ce,e]),ve=!!f?.some(Ts);(0,X.useEffect)(()=>{if(ve)return()=>{r()}},[ve,r]),(0,X.useEffect)(()=>{if(u!==`local`||!ve)return;let e=setInterval(()=>{ce(`local`,!0)},sP);return()=>clearInterval(e)},[ve,u,ce]);let ye=t?.model,be=f?.find(e=>us(ye,e.id));(0,X.useEffect)(()=>{be&&ne(be)},[be]);let xe=(0,X.useMemo)(()=>{let e=g.trim().toLowerCase();return(f??[]).filter(t=>!e||t.id.toLowerCase().includes(e)||(t.display_name??``).toLowerCase().includes(e))},[f,g]),Se=xe.filter(e=>e.available!==!1),Ce=u===`fireworks`&&!v&&!g.trim()&&Se.some(e=>e.rank!==null),we=e=>e.rank!==null||e.id===t?.model,Te=Ce?Se.filter(we):Se,Ee=Ce?Se.filter(e=>!we(e)):[],De=xe.filter(e=>e.available===!1),Oe=ys(f??[]),ke=!!g.trim(),Ae=e=>us(t?.model,e.id),je=H?.id===`local`,Me=Te.filter(e=>e.downloaded).sort((e,t)=>Number(Ae(t))-Number(Ae(e))),Ne=Te.filter(e=>!e.downloaded),Pe=(f??[]).filter(e=>e.available!==!1&&e.downloaded),Fe=Pe.filter(we),Ie=u===`fireworks`&&Fe.some(e=>e.rank!==null)?Fe:Pe,Le=e=>P(aP,{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(iP,{row:be??(us(te?.id,t?.model)?te:null),providerName:a?.find(e=>e.id===t?.provider)?.name??null,choices:W?Ie:[],labels:Oe,disabled:j!==null,onSwitch:e=>void me(e)}),P(`div`,{className:`provider-tabs`,role:`radiogroup`,"aria-label":e(`settings.model.whereRuns`),children:(a??[{id:`local`,name:`Local`,remote:!1}]).map(t=>V(`button`,{type:`button`,role:`radio`,"aria-checked":u===t.id,className:`provider-tab${u===t.id?` is-active`:``}${U(t)||se(t)?` is-disabled`:``}`,onClick:()=>d(t.id),disabled:(U(t)||se(t))&&u!==t.id,title:se(t)?e(`settings.privacy.localOnlyBlocked`):U(t)?t.network?.detail??void 0:void 0,children:[t.remote?P(Ir,{size:14,"aria-hidden":`true`}):P(Wr,{size:14,"aria-hidden":`true`}),P(`span`,{children:t.name}),t.remote&&t.models_discovered&&P(`span`,{className:`provider-tab-dot`,"aria-label":e(`settings.key.connectedDot`)})]},t.id))}),s&&P(ZN,{message:s,onRetry:()=>{G(),ce(u)}}),H&&V(`section`,{className:`settings-card`,"aria-label":H.name,children:[H.remote&&P(`p`,{className:`settings-note`,children:P(`bdi`,{children:H.privacy_notice})}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,e(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:e(`settings.model.lede`)}),je&&P(`p`,{className:`settings-hint`,children:P(`bdi`,{children:H.privacy_notice})}),je&&P(`p`,{className:`settings-hint`,children:e(`settings.model.devices`)}),je&&N&&P(`p`,{className:`settings-hint`,children:e(`settings.model.memory`,{memory:N})})]}),H.remote&&!W&&V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,children:e(`settings.model.prices`)}),P(GA,{provider:H.id})]}),se(H)&&P(`div`,{className:`settings-field`,children:P(`p`,{className:`settings-error`,role:`alert`,children:e(`settings.privacy.localOnlyBlocked`)})}),U(H)&&V(`div`,{className:`settings-field`,children:[P(`p`,{className:`settings-error`,role:`alert`,children:H.network?.detail}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void G(),children:e(`settings.key.checkAgain`)})]}),H.remote&&!U(H)&&!se(H)&&V(`form`,{className:`settings-field`,onSubmit:e=>{e.preventDefault(),de()},children:[V(`div`,{className:`settings-row settings-row-between`,children:[P(`span`,{className:`settings-label`,children:e(`settings.key.title`)}),H.key_source&&P(`span`,{className:`settings-key-status ${W?`settings-ok`:`settings-error`}`,children:e(W?`settings.key.connected`:`settings.key.notConnected`)})]}),!H.key_source&&P(`span`,{className:`settings-hint`,children:H.key_state===`waiting_for_os_permission`?H.key_message??e(`settings.key.waitingOs`):e(`settings.key.none`)}),H.id===`amd`&&(!H.key_source||S)&&V(`div`,{className:`settings-grid`,children:[P(`input`,{className:`settings-input`,placeholder:e(`settings.key.gatewayPlaceholder`),value:O.base_url,onChange:e=>A({...O,base_url:e.target.value}),"aria-label":e(`settings.key.gatewayUrl`)}),P(`input`,{className:`settings-input`,placeholder:e(`settings.key.headerPlaceholder`),value:O.auth_header_name,onChange:e=>A({...O,auth_header_name:e.target.value}),"aria-label":e(`settings.key.headerName`)})]}),H.key_source&&!S?V(`div`,{className:`settings-row`,children:[P(`input`,{className:`settings-input settings-key-masked`,readOnly:!0,value:cP(H,e),"aria-label":e(`settings.key.savedAria`,{name:H.name})}),!W&&V(`button`,{type:`submit`,className:`btn-primary`,disabled:j!==null,children:[j===`connect`?P(q,{size:13,className:`spin`}):null,e(`settings.key.reconnect`)]}),(H.key_source!==`environment`||H.key_from_gaia_env)&&(w?V(D.Fragment,{children:[P(`span`,{className:`settings-hint`,children:e(`settings.key.removeAsk`)}),P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void pe(),disabled:j!==null,children:e(`settings.models.remove`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>E(!1),children:e(`settings.models.keep`)})]}):V(D.Fragment,{children:[P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>C(!0),disabled:j!==null,children:e(`settings.key.replace`)}),H.key_source!==`environment`&&P(`button`,{type:`button`,className:`btn-secondary settings-key-remove`,onClick:()=>E(!0),disabled:j!==null,"aria-label":e(`settings.key.remove`),title:e(`settings.key.remove`),children:P(lo,{size:14,"aria-hidden":`true`})})]}))]}):V(`div`,{className:`settings-row`,children:[P(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,spellCheck:!1,autoFocus:S,value:b,onChange:e=>x(e.target.value),placeholder:e(S?`settings.key.pasteNew`:`settings.key.paste`),"aria-label":e(`settings.key.fieldAria`,{name:H.name})}),V(`button`,{type:`submit`,className:`btn-primary`,disabled:j!==null||!b,children:[j===`connect`?P(q,{size:13,className:`spin`}):null,e(S?`settings.key.save`:`settings.key.connect`)]}),S&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{x(``),C(!1)},disabled:j!==null,children:e(`settings.key.cancel`)})]}),H.key_source&&!W&&!H.error&&!S&&P(`p`,{className:`settings-hint`,children:e(`settings.key.notConnectedHint`,{name:H.name})}),H.error&&P(`p`,{className:`settings-error`,role:`alert`,children:H.error})]}),I?.ok&&P(`p`,{className:`settings-ok`,role:`status`,children:I.text}),I&&!I.ok&&P(ZN,{message:I.text}),H.known_models&&P(`p`,{className:`settings-hint`,role:`status`,children:e(`settings.key.knownList`,{name:H.name})}),je&&P(`div`,{className:`models-downloads-slot`,ref:ie}),W&&V(`div`,{className:`settings-field`,children:[P(`span`,{className:`settings-label`,children:e(`settings.model.models`)}),(f?.length??0)>6&&P(`input`,{className:`settings-input`,type:`search`,value:g,onChange:e=>_(e.target.value),placeholder:e(`settings.model.search`),"aria-label":e(`settings.model.search`)}),m&&!(s&&qN(m))&&P(ZN,{message:m}),!f&&!m&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.loading`)]}),f&&xe.length===0&&!m&&P(`p`,{className:`settings-hint`,children:e(ke||!je?`settings.model.noMatch`:`settings.model.noModels`)}),je?V(D.Fragment,{children:[Me.length>0&&P(CN,{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(CN,{title:e(`settings.model.groupAvailable`),count:Ne.length,defaultOpen:Me.length===0,forceOpen:ke||z||Ne.some(Ts),children:P(`ul`,{className:`model-list`,children:Ne.map(Le)})})]}):P(`ul`,{className:`model-list`,children:Te.map(Le)}),Ce&&Ee.length>0&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>y(!0),children:e(`settings.model.showAll`)}),u===`fireworks`&&v&&!ke&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>y(!1),children:e(`settings.model.showRecommended`)}),De.length>0&&P(CN,{title:e(`settings.model.groupUnavailable`),count:De.length,forceOpen:ke,children:P(`ul`,{className:`model-list`,children:De.map(Le)})})]}),je&&W&&P(CN,{title:e(`settings.custom.title`),children:P(QN,{onAdded:e=>void _e(e)})}),je&&W&&P(tP,{downloadsSlot:re}),H.remote&&P(oP,{})]})]})}function uP(){let e=T(),t=k(e=>e.sessions),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(null),u=(0,X.useCallback)(async()=>{l(null);try{let e=await on();r(e.sessions),a(e.default_mode),k.getState().setDefaultPermissionMode(e.default_mode)}catch(e){l(e instanceof Error?e.message:String(e))}},[]);(0,X.useEffect)(()=>{u()},[u]);let d=(0,X.useCallback)(async e=>{l(null);try{await e(),await u()}catch(e){l(e instanceof Error?e.message:String(e))}},[u]),f=(0,X.useCallback)(async e=>{s(!1),await d(()=>kt(e))},[d]),p=()=>{i===`full_access`?f(`ask`):s(e=>!e)},m=e=>t.find(t=>t.id===e)?.title??e;return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.permissions`)}),P(`p`,{className:`settings-pane-lede`,children:e(`settings.permissions.lede`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,e(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:e(`settings.permissions.perChat`)})]}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.permissions.newChats`),children:[V(`label`,{className:`setting-row`,children:[P(`span`,{className:`settings-label`,children:e(`settings.permissions.fullAccess`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:i===`full_access`,onChange:p,disabled:i===null,"aria-label":e(`settings.permissions.fullAccess`)}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,children:e(i===`full_access`?`settings.permissions.on`:`settings.permissions.off`)}),o&&V(`div`,{className:`settings-warning`,role:`alert`,children:[P(`p`,{children:e(`settings.permissions.warning`)}),V(`div`,{className:`settings-row`,children:[P(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void f(`full_access`),children:e(`settings.permissions.turnOn`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>s(!1),children:e(`settings.key.cancel`)})]})]})]}),c&&P(`p`,{className:`settings-error`,role:`alert`,children:c}),n&&n.length===0&&P(`p`,{className:`settings-hint`,children:e(`settings.permissions.none`)}),!!n?.length&&P(CN,{title:e(`settings.permissions.chats`),count:n.length,defaultOpen:!0,children:n.map(t=>V(`section`,{className:`settings-field permission-chat`,"aria-label":m(t.session_id),children:[V(`div`,{className:`settings-row settings-row-between`,children:[P(`bdi`,{className:`settings-label`,children:m(t.session_id)}),t.mode===`full_access`&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>d(async()=>{let e=(await Pt(t.session_id,`ask`)).mode;yE(t.session_id,e)}),children:e(`settings.permissions.turnOff`)})]}),t.grants.length>0&&P(`ul`,{className:`grant-list`,children:t.grants.map(n=>V(`li`,{className:`grant-row`,children:[P(`code`,{children:n.label}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>d(()=>Xt(t.session_id,n.key)),"aria-label":e(`settings.permissions.revokeAria`,{name:n.label}),children:e(`settings.permissions.revoke`)})]},n.key))}),t.grants.length>1&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>d(()=>Xt(t.session_id)),children:e(`settings.permissions.revokeAll`)})]},t.session_id))})]})}var dP={path:`~/.gaia/skills`},fP=[{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:dP},{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 pP({onUseSkill:e}){let t=T(),[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)({}),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(``);(0,X.useEffect)(()=>{let e=!1;return ln().then(t=>{e||(r(t.skills),a(t.invalid))}).catch(t=>{e||s(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let u=c.trim().toLowerCase(),d=(n??[]).filter(e=>!u||e.name.toLowerCase().includes(u)||e.description.toLowerCase().includes(u)),f=n?.every(e=>fP.some(t=>t.source===e.source))??!1,p=n=>V(`li`,{className:`skill-row`,children:[V(`div`,{className:`skill-row-text`,children:[V(`span`,{className:`skill-row-name`,children:[n.name,n.version&&V(`span`,{className:`skill-row-meta`,children:[` v`,n.version]}),n.always_on&&V(`span`,{className:`skill-row-meta`,children:[` · `,t(`settings.skills.alwaysOn`)]})]}),P(`span`,{className:`skill-row-desc`,children:P(`bdi`,{children:n.description})})]}),!n.always_on&&P(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>e(n.name),"aria-label":t(`settings.skills.useAria`,{name:n.name}),children:t(`settings.model.use`)})]},n.name);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:t(`settings.section.skills`)}),P(`p`,{className:`settings-pane-lede`,children:t(`settings.skills.lede`)}),V(`details`,{className:`settings-more`,children:[V(`summary`,{children:[P(gr,{size:13,className:`settings-disclosure-chevron`,"aria-hidden":`true`}),` `,t(`settings.model.howItWorks`)]}),P(`p`,{className:`settings-hint`,children:t(`settings.skills.how`,dP)})]}),o&&P(`p`,{className:`settings-error`,role:`alert`,children:o}),!n&&!o&&V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),n&&n.length>6&&P(`input`,{className:`settings-input`,type:`search`,value:c,onChange:e=>l(e.target.value),placeholder:t(`settings.skills.search`),"aria-label":t(`settings.skills.search`)}),n&&n.length===0&&P(`p`,{className:`settings-hint`,children:t(`settings.skills.none`)}),f?fP.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(CN,{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 mP(){let e=T(),t=k(e=>e.setShowMemoryDashboard),n=k(e=>e.closeSettings),[r,i]=(0,X.useState)(null),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1);(0,X.useEffect)(()=>{mA().then(i).catch(e=>o(e instanceof Error?e.message:String(e)))},[]);let l=(0,X.useCallback)(async()=>{if(r){c(!0),o(null);try{i(await hA({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 hP(e,t,n){if(!/^\d+$/.test(e.trim()))return!1;let r=Number(e);return r>=t&&r<=n}function gP(e){return e<1048576?`${Math.ceil(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}function _P(){let e=T(),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1);(0,X.useEffect)(()=>{hn().then(e=>{n(e),i(String(e.retention_days)),o(String(e.max_mb))},t=>c({ok:!1,text:e(`settings.undo.readFailed`,{reason:t instanceof Error?t.message:String(t)})}))},[e]);let[d,f]=(0,X.useState)({days:!1,mb:!1}),p=!hP(r,1,365)||d.days,m=!hP(a,10,1e5)||d.mb,h=t!==null&&(r!==String(t.retention_days)||a!==String(t.max_mb)),g=async()=>{if(!(p||m)){u(!0),c(null);try{let t=await fn(Number(r),Number(a));n(t),c({ok:!0,text:e(`settings.undo.saved`)})}catch(t){let n=t instanceof yn&&t.httpStatus===422?t.fields:[],r=n.includes(`retention_days`),i=n.includes(`max_mb`);r||i?(f({days:r,mb:i}),c({ok:!1,text:e(`settings.undo.fix`)})):c({ok:!1,text:t instanceof Error?t.message:String(t)})}finally{u(!1)}}};return V(`div`,{className:`settings-field`,"aria-label":e(`settings.privacy.undo`),children:[P(`span`,{className:`settings-label`,children:e(`settings.privacy.undo`)}),P(`p`,{className:`settings-hint`,children:e(`settings.undo.hint`)}),t&&V(D.Fragment,{children:[V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`undo-days`,children:e(`settings.undo.days`)}),P(`input`,{id:`undo-days`,type:`number`,className:`model-input undo-history-input`,min:1,max:365,value:r,"aria-invalid":p,"aria-describedby":p?`undo-days-error`:void 0,onChange:e=>{i(e.target.value),f(e=>({...e,days:!1}))}})]}),p&&P(`p`,{id:`undo-days-error`,className:`settings-error`,children:e(`settings.undo.daysError`)}),V(`div`,{className:`setting-row`,children:[P(`label`,{htmlFor:`undo-mb`,children:e(`settings.undo.mb`)}),P(`input`,{id:`undo-mb`,type:`number`,className:`model-input undo-history-input`,min:10,max:1e5,value:a,"aria-invalid":m,"aria-describedby":m?`undo-mb-error`:void 0,onChange:e=>{o(e.target.value),f(e=>({...e,mb:!1}))}})]}),m&&P(`p`,{id:`undo-mb-error`,className:`settings-error`,children:e(`settings.undo.mbError`)}),V(`div`,{className:`setting-row setting-row-path`,children:[P(`span`,{children:e(`settings.undo.inUse`)}),V(`span`,{children:[e.plural(`settings.undo.used`,t.turns,{size:gP(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 vP={root:`settings-report`,button:`btn-secondary`,hint:`settings-hint`,error:`settings-error`};function yP(){let e=T(),t=k(e=>e.sessions),n=k(e=>e.removeSession),r=hs(),i=k(e=>e.systemStatus?.data_dir),[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),p=(0,X.useRef)(null);(0,X.useEffect)(()=>()=>{p.current&&clearTimeout(p.current)},[]),(0,X.useEffect)(()=>{let e=!0;return qe().then(t=>{e&&u(t.network_policy===`local_ai_only`)}).catch(t=>{e&&c({ok:!1,text:t instanceof Error?t.message:String(t)})}),()=>{e=!1}},[]);let m=(0,X.useCallback)(async()=>{if(l===null||d)return;let t=l,n=!t;u(n),f(!0),c(null);try{let t=await Me({network_policy:n?`local_ai_only`:`cloud_allowed`});u(t.network_policy===`local_ai_only`);let r=t.policy_notices??[],i=r.some(e=>e.severity===`warning`),a=r.length?r.map(t=>t.code===`users_server_keeps_keys`?e(`settings.privacy.usersServerKeepsKeys`,{url:t.url??``}):t.code===`runtime_keys_not_dropped`?e(`settings.privacy.runtimeKeysNotDropped`,{reason:t.reason??``}):t.code===`saved_models_not_checked`?e(`settings.privacy.savedModelsNotChecked`,{reason:t.reason??``}):e(`settings.privacy.policyNoticeUnknown`)).join(` `):e(n?`settings.privacy.localOnlyOn`:`settings.privacy.localOnlyOff`);c({ok:!i,text:a})}catch(e){u(t),c({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{f(!1)}},[l,d,e]),h=(0,X.useCallback)(async()=>{if(!a){o(!0),p.current=setTimeout(()=>o(!1),4e3);return}o(!1);let r=[];for(let e of t)try{await de(e.id),n(e.id)}catch(t){r.push(`${e.title}: ${t instanceof Error?t.message:t}`)}c(r.length?{ok:!1,text:e(`settings.privacy.deleteFailed`,{n:r.length,reason:r.join(`; `)})}:{ok:!0,text:e(`settings.privacy.deleted`)})},[a,n,t,e]);return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.privacy`)}),P(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.localOnlyTitle`),children:V(`div`,{className:`settings-row settings-row-between`,children:[V(`div`,{children:[P(`strong`,{children:e(`settings.privacy.localOnlyTitle`)}),P(`p`,{className:`settings-hint`,children:e(`settings.privacy.localOnlyHint`)})]}),P(`button`,{type:`button`,role:`switch`,"aria-checked":l===!0,"aria-label":e(`settings.privacy.localOnlyTitle`),className:l?`is-active`:``,onClick:()=>void m(),disabled:l===null||d,children:e(l?`settings.privacy.localOnlyOnLabel`:`settings.privacy.localOnlyOffLabel`)})]})}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.whereTitle`),children:[P(`p`,{className:`settings-note`,children:e(`settings.privacy.stays`)}),P(`p`,{className:r?.remote?`settings-note`:`settings-hint`,children:r?.remote?e(`settings.privacy.remote`,{name:r.label}):e(r?`settings.privacy.local`:`settings.privacy.unknown`)}),i&&V(`div`,{className:`setting-row setting-row-path`,children:[P(`span`,{children:e(`settings.privacy.dataFolder`)}),P(`bdi`,{dir:`ltr`,className:`setting-path`,children:i})]})]}),V(`section`,{className:`settings-card`,"aria-label":e(`settings.privacy.reportTitle`),children:[P(`p`,{className:`settings-note`,children:e(`settings.privacy.reportNote`)}),P(rC,{classes:vP})]}),P(CN,{title:e(`settings.privacy.undo`),children:P(_P,{})}),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 bP=[{id:`needs_approval`,label:`settings.alerts.approval`},{id:`question`,label:`settings.alerts.question`},{id:`finished`,label:`settings.alerts.finished`}],xP=[{value:`banner`,label:`settings.alerts.banner`},{value:`badge`,label:`settings.alerts.badge`},{value:`off`,label:`settings.alerts.off`}],SP=[0,10,20,30,50];function CP(){return typeof Notification>`u`?`unsupported`:Notification.permission}function wP(){let e=T(),t=lc(),n=!!window.gaiaAPI,[r,i]=(0,X.useState)(CP),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:[bP.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:xP.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(CP())})},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:SP.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 TP=[50,75,100,125,150,175,200],EP=[{accent:`american`,gender:`female`},{accent:`american`,gender:`male`},{accent:`british`,gender:`female`},{accent:`british`,gender:`male`}],DP=`settings:preview`,OP=`Hello, I'm GAIA. This is how I'll read my replies to you.`;function kP(e){return e instanceof yn?e.detail||e.message:String(e)}function AP(){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===DP),o=ES(e=>e.messageId===DP&&e.status===`loading`),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1);(0,X.useEffect)(()=>{pS().then(n).catch(e=>c(kP(e)))},[n]);let p=e=>{f(!0),u(null),ES.getState().messageId===DP&&i(),mS(e).then(n).catch(e=>u(kP(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:EP.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(DP,OP),children:[o?P(q,{size:13,className:`spin`}):P(a?ao:_o,{size:13}),e(a?`readAloud.stop`:`readAloud.settings.preview`)]})]}),P(`span`,{className:`settings-hint`,children:e(`readAloud.settings.englishOnly`)}),P(kS,{messageId:DP})]}),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:(TP.includes(t.speed)?TP:[...TP,t.speed].sort((e,t)=>e-t)).map(t=>P(`option`,{value:t,children:t===100?e.bare(`readAloud.settings.normalSpeed`):`${(t/100).toLocaleString(e.locale)}×`},t))})]}),V(`label`,{className:`setting-row`,children:[P(`span`,{children:e(`readAloud.settings.auto`)}),V(`span`,{className:`toggle-switch`,children:[P(`input`,{type:`checkbox`,checked:t.auto,disabled:d,onChange:()=>p({auto:!t.auto}),"aria-label":e(`readAloud.settings.auto`)}),P(`span`,{className:`toggle-track`})]})]}),P(`p`,{className:`settings-hint`,children:e(`readAloud.settings.shared`)}),l&&P(`p`,{className:`settings-error`,role:`alert`,children:e(`readAloud.settings.saveFailed`,{reason:l})})]}):V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,e(`settings.loading`)]})}function jP(){let e=T(),t=k(e=>e.openSettings),n=k(e=>e.closeSettings),r=k(e=>e.runSetupAgain),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1);(0,X.useEffect)(()=>{Ce().then(a).catch(e=>l(e instanceof Error?e.message:String(e))),ot().then(s).catch(e=>l(e instanceof Error?e.message:String(e)))},[]);let f=i?.catalog?.find(e=>e.id===i.chat_model.id),p=(i?.catalog??[]).filter(e=>e.downloaded),m=p.reduce((e,t)=>e+(t.full_size_gb??0),0),h=[o?.gpu_name,o?.npu_detected?e(`setup.checks.npu`):null].filter(Boolean).join(` · `),g=[{title:e(`settings.setup.where`),rows:[{label:e(`settings.setup.chatRuns`),value:f?.name??null,section:`model`},{label:e(`settings.setup.cloudKeys`),value:null,section:`model`}]},{title:e(`setup.pc.step`),rows:[{label:e(`settings.setup.detected`),value:[h,o?.ram_gb==null?null:`${o.ram_gb} GB`].filter(Boolean).join(` · `)||null,section:`advanced`},{label:e(`settings.setup.server`),value:i?.lemonade.mode===`external`?e(`settings.setup.serverYours`):e(`settings.setup.serverOwn`),section:`advanced`},{label:e(`setup.gpu.title`),value:null,section:`model`}]},{title:e(`setup.models.step`),rows:[{label:e(`settings.setup.models`),value:i?.catalog?e(`settings.setup.modelsValue`,{n:String(p.length),size:$(m)}):null,section:`model`},{label:e(`settings.setup.context`),value:null,section:`model`}]},{title:e(`settings.setup.after`),rows:[{label:e(`settings.section.connectors`),value:null,section:`connectors`},{label:e(`settings.section.memory`),value:null,section:`memory`},{label:e(`settings.language`),value:null,section:`general`},{label:e(`settings.setup.signIn`),value:null,section:`general`}]}];return V(`div`,{className:`settings-pane`,children:[P(`h2`,{className:`settings-pane-title`,children:e(`settings.section.setup`)}),P(`p`,{className:`settings-hint`,children:e(`settings.setup.lede`)}),V(`div`,{className:`settings-setup-status`,children:[V(`span`,{children:[P(`strong`,{children:e(`settings.setup.ready`)}),f&&V(`span`,{className:`settings-hint`,children:[` `,P(`bdi`,{children:e(`settings.setup.running`,{name:f.name})})]})]}),P(`button`,{type:`button`,className:`btn-secondary`,"data-testid":`setup-run-again`,onClick:()=>d(!0),children:e(`settings.setup.runAgain`)})]}),c&&P(`p`,{className:`setup-error`,role:`alert`,children:c}),g.map(e=>V(`section`,{className:`settings-setup-group`,"aria-label":e.title,children:[P(`h3`,{className:`settings-label`,children:e.title}),e.rows.map(e=>V(`button`,{type:`button`,className:`settings-setup-row`,onClick:()=>t(e.section),children:[V(`span`,{children:[P(`span`,{className:`settings-setup-row-label`,children:e.label}),e.value&&P(`bdi`,{className:`settings-hint settings-setup-row-value`,children:e.value})]}),P(br,{size:14,className:`settings-setup-chevron`,"aria-hidden":`true`})]},e.label))]},e.title)),u&&P(qj,{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 MP=class extends X.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(NP,{variant:this.props.variant??`fill`,onRetry:()=>this.setState({hasError:!1})}):this.props.children}};function NP({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 PP=`modulepreload`,FP=function(e,t){return new URL(e,t).href},IP={},LP=function(e){return e.pathname.endsWith(`.css`)},RP=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},zP=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=FP(t,n);let r=s(t),i=LP(r);return RP(IP,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`:PP,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)})},BP=(0,X.lazy)(()=>zP(()=>import(`./ConnectorsPane-BOj8VFq4.js`).then(e=>({default:e.ConnectorsPane})),__vite__mapDeps([0,1,2,3,4]),import.meta.url)),VP=(0,X.lazy)(()=>zP(()=>import(`./AdvancedSettings-BfZmpLHF.js`).then(e=>({default:e.AdvancedSettings})),__vite__mapDeps([5,1,2,3]),import.meta.url)),HP=[`general`,`setup`,`model`,`permissions`,`skills`,`connectors`,`memory`,`notifications`,`voice`,`privacy`,`advanced`];function UP({onUseSkill:e}){let t=T(),n=k(e=>e.settingsSection),r=k(e=>e.openSettings),i=k(e=>e.closeSettings),a=(0,X.useRef)(null),o=n!==null;if(Io(o,i),sS(a,o),SN(a,o,()=>a.current?.querySelector(`.settings-nav-item.is-active`)),!n)return null;let s=(()=>{switch(n){case`general`:return P(KN,{});case`setup`:return P(jP,{});case`model`:return P(lP,{});case`permissions`:return P(uP,{});case`skills`:return P(pP,{onUseSkill:t=>{i(),e(t)}});case`connectors`:return P(BP,{});case`memory`:return P(mP,{});case`notifications`:return P(wP,{});case`voice`:return P(AP,{});case`privacy`:return P(yP,{});case`advanced`:return P(VP,{})}})();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`)}),HP.map(e=>P(`button`,{type:`button`,"data-section":e,className:`settings-nav-item${n===e?` is-active`:``}`,"aria-current":n===e?`page`:void 0,onClick:t=>{t.currentTarget.focus(),r(e)},children:t(`settings.section.${e}`)},e))]}),V(`div`,{className:`settings-body`,children:[P(`button`,{type:`button`,className:`settings-close`,onClick:i,"aria-label":t(`settings.close`),children:P(Y,{size:18})}),P(`div`,{className:`settings-scroll`,children:P(MP,{area:`settings.${n}`,children:P(X.Suspense,{fallback:V(`p`,{className:`settings-hint`,children:[P(q,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),children:s})},n)})]})]})})}var WP=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 GP(e){let t=window.gaiaAPI?.backend;if(!t)return()=>{};let n=t=>{let n=WP.getState().lifecycle?.status;WP.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 KP(e,t){let[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(!1),[o,s]=(0,X.useState)(null),c=(0,X.useRef)(null),l=(0,X.useRef)(null),u=(0,X.useRef)(null),f=(0,X.useCallback)(()=>{c.current&&=(clearTimeout(c.current),null),l.current&&=(clearTimeout(l.current),null),u.current&&=(clearInterval(u.current),null)},[]);(0,X.useEffect)(()=>f,[f]);let p=(0,X.useCallback)((e,t)=>{u.current&&clearInterval(u.current),u.current=setInterval(async()=>{try{let n=await Nt();t===`load`?n.model_loaded?.toLowerCase()===e.toLowerCase()&&(r(!1),c.current&&=(clearTimeout(c.current),null),u.current&&=(clearInterval(u.current),null)):(n.model_downloaded===!0||n.model_loaded?.toLowerCase()===e.toLowerCase())&&(a(!1),l.current&&=(clearTimeout(l.current),null),u.current&&=(clearInterval(u.current),null))}catch{}},Lc)},[]),m=e??`Gemma-4-E4B-it-GGUF`;return(0,X.useEffect)(()=>s(null),[m]),{isLoadingModel:n,isDownloadingModel:i,downloadError:o,loadModel:(0,X.useCallback)(async(e,t)=>{let n=e??m,i=t??32768;r(!0);try{if(!await zt(n,i)){r(!1);return}d.system.info(`Load model triggered: ${n} (ctx=${i})`),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>r(!1),Fc),p(n,`load`)}catch(e){d.system.error(`Failed to trigger model load`,e),r(!1)}},[m,t,p]),downloadModel:(0,X.useCallback)(async(e=!1,t,n=!1)=>{let r=t??m;a(!0),s(null);try{await fe(r,e,n),d.system.info(`Download model triggered: ${r} (force=${e})`),l.current&&clearTimeout(l.current),l.current=setTimeout(()=>a(!1),Ic),p(r,`download`)}catch(e){d.system.error(`Failed to trigger model download`,e),s(e instanceof Error?e.message:String(e)),a(!1)}},[m,p])}}function qP({onRetry:e,label:t,busyLabel:n=`Checking…`}){let[r,i]=(0,X.useState)(!1);return P(`button`,{className:`connection-banner__retry`,onClick:()=>{i(!0),Promise.resolve(e()).finally(()=>i(!1))},disabled:r,children:r?n:t})}function JP(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function YP({lifecycle:e}){let t=T(),n=WP(e=>e.restart),r=WP(e=>e.restartError),i=e.status===`restarting`,[a,o]=(0,X.useState)(()=>Date.now());if((0,X.useEffect)(()=>{if(!i)return;o(Date.now());let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[i]),i){let n=e.since?Math.max(0,Math.floor((a-e.since)/1e3)):0;return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t(`banner.restarting`),` `,P(`bdi`,{dir:`ltr`,className:`connection-banner__timer`,children:JP(n)}),` `,P(`span`,{className:`connection-banner__hint`,children:t(`banner.restartingHint`)})]})]})}return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t(`banner.restartStopped`),` `,P(`span`,{className:`connection-banner__hint`,children:r?t(`banner.restartFailed`,{error:r}):t(`banner.restartStoppedHint`)})]}),P(qP,{onRetry:n,label:t(`banner.restartButton`),busyLabel:t(`banner.restartingShort`)})]})}function XP({onRetry:e,backendSlow:t=!1,backendError:n=null}){let r=T(),{backendConnected:i,systemStatus:a,currentSessionId:o,messages:s}=k(),c=WP(e=>e.lifecycle),[l,u]=(0,X.useState)(!1),d=!!o&&s.length>0,f=a?.default_model_name??`Gemma-4-E4B-it-GGUF`,{isDownloadingModel:p,downloadError:m,downloadModel:h}=KP(f),g=cs(e=>e.pickLoad),_=cs(e=>e.retryPickLoad),v=cs(e=>e.dismissPickLoad);ls();let y=(0,X.useRef)(a?.lemonade_running),b=(0,X.useRef)(a?.model_downloaded),x=(0,X.useRef)(a?.context_size_sufficient),S=(0,X.useRef)(a?.expected_model_loaded);if((0,X.useEffect)(()=>{if(d)return;let e=a?.lemonade_running,t=a?.model_downloaded,n=a?.context_size_sufficient,r=a?.expected_model_loaded,i=!1;y.current!==e&&(y.current=e,e===!1&&(i=!0)),b.current!==t&&(b.current=t,t===!1&&(i=!0)),x.current!==n&&(x.current=n,n===!1&&(i=!0)),S.current!==r&&(S.current=r,r===!1&&(i=!0)),i&&u(!1)},[a,d]),c&&c.status!==`running`)return P(YP,{lifecycle:c});let C=a?.download_progress??null,w=C?.model_name||f;if(p||C?.state===`downloading`||C?.state===`starting`||C?.state===`error`){let e=C?.total_bytes?`${(C.total_bytes/1e9).toFixed(1)} GB`:`large download`,t=C?.state===`error`;return V(`div`,{className:`connection-banner ${t?`connection-banner--error`:`connection-banner--warning`}`,role:t?`alert`:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(t?J:Jr,{size:16})}),P(`div`,{className:`connection-banner__text`,dir:`auto`,children:t?V(D.Fragment,{children:[`Download of `,P(`strong`,{children:w}),` failed.`,` `,(m??C?.message)&&P(`span`,{className:`connection-banner__hint`,children:m??C?.message})]}):V(D.Fragment,{children:[`Downloading `,P(`strong`,{children:w}),` (`,e,`).`,C?.state===`downloading`&&C.file&&V(D.Fragment,{children:[` `,V(`span`,{className:`connection-banner__hint`,children:[`File `,C.file_index,` / `,C.total_files,`: `,P(`code`,{children:C.file})]})]})]})}),t?P(`button`,{className:`connection-banner__retry`,onClick:()=>h(!1,w,!a?.model_loaded),children:`Retry`}):P(`span`,{className:`connection-banner__loading connection-banner__progress`,children:C&&C.state===`downloading`&&C.total_bytes>0?V(D.Fragment,{children:[P(`span`,{className:`connection-banner__progress-bar`,role:`progressbar`,"aria-valuenow":C.percent,"aria-valuemin":0,"aria-valuemax":100,"aria-label":`Download progress`,children:P(`span`,{className:`connection-banner__progress-fill`,style:{width:`${C.percent}%`}})}),V(`span`,{className:`connection-banner__progress-label`,children:[C.percent,`% ·`,` `,(C.downloaded_bytes/1e9).toFixed(2),` /`,` `,(C.total_bytes/1e9).toFixed(2),` GB`]})]}):V(D.Fragment,{children:[P(q,{size:13,className:`connection-banner__spinner`}),C?.state===`starting`?C.message??`Starting download…`:`Downloading…`]})}),t&&P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}if(g){let e=ds(g.model);return g.error?V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.pickLoad.failed`,{model:e}),` `,P(`span`,{className:`connection-banner__hint`,dir:`auto`,children:g.error.key?r(g.error.key,{reason:g.error.reason}):g.error.reason})]}),P(qP,{onRetry:_,label:r(`banner.pickLoad.retry`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:v,"aria-label":r(`banner.dismiss`),children:P(Y,{size:14})})]}):V(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.pickLoad.loading`,{model:e}),` `,P(`bdi`,{dir:`ltr`,children:r(`banner.pickLoad.seconds`,{s:g.seconds})}),` `,P(`span`,{className:`connection-banner__hint`,children:r(`banner.pickLoad.canType`)})]})]})}if(Hw(a)&&!t&&!n){let e=a?.init_tasks?.find(e=>e.status===`running`)?.name||`Preparing AI system`;return V(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(q,{size:16,className:`connection-banner__spinner`})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[e,V(`span`,{className:`thinking-dots`,children:[P(`span`,{children:`.`}),P(`span`,{children:`.`}),P(`span`,{children:`.`})]})]})]})}if(l||d)return null;if(!i)return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(yo,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[r(`banner.unreachable`),` `,P(`span`,{className:`connection-banner__hint`,children:r(`banner.unreachableHint`)})]}),e&&P(qP,{onRetry:e,label:`Retry`})]});if(n)return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA's backend answered with an error (`,n,`).`,` `,P(`span`,{className:`connection-banner__hint`,children:`It may be overloaded. GAIA keeps checking; if it lasts, restart GAIA.`})]}),e&&P(qP,{onRetry:e,label:`Check again`})]});if(t)return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA is slow to answer.`,` `,P(`span`,{className:`connection-banner__hint`,children:`It may be busy with another chat or app. GAIA keeps checking.`})]}),e&&P(qP,{onRetry:e,label:`Check again`})]});if(a?.config_error)return V(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA settings could not be loaded.`,` `,P(`span`,{className:`connection-banner__hint`,children:a.config_error})]}),e&&P(qP,{onRetry:e,label:`Check again`})]});if(a&&!a.lemonade_running){let t=Uw(a)===`unresponsive`,n=YN(a);return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(J,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t?`The model server is not answering (${a.lemonade_error}). It may be busy with another app or loading a model.`:r(`banner.serverStopped`),` `,n?P(`span`,{className:`connection-banner__hint`,children:r(`banner.finishSetup`)}):a.start_command?V(`span`,{className:`connection-banner__hint`,children:[t?`If it stays this way, restart it: `:`To start it by hand, run `,P(`code`,{children:a.start_command})]}):a.start_instruction&&P(`span`,{className:`connection-banner__hint`,children:a.start_instruction})]}),n&&P(XN,{className:`connection-banner__retry`}),e&&P(qP,{onRetry:e,label:r(`settings.key.checkAgain`)}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}if(a&&a.lemonade_running&&a.model_loaded&&a.context_size_sufficient===!1){let t=a.model_context_size??0;return V(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[P(`div`,{className:`connection-banner__icon`,children:P(Ji,{size:16})}),V(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`LLM context window is too small (`,t.toLocaleString(),` tokens;`,` `,Nc.toLocaleString(),` required).`,` `,P(`span`,{className:`connection-banner__hint`,children:`Reload it with a larger context in Settings → Advanced.`})]}),e&&P(qP,{onRetry:e,label:`Check again`}),P(`button`,{className:`connection-banner__dismiss`,onClick:()=>u(!0),"aria-label":`Dismiss`,children:P(Y,{size:14})})]})}return null}function ZP(){let e=MN(),t=T(),[n,r]=(0,X.useState)(!1),[i,a]=(0,X.useState)(null),o=(0,X.useCallback)(e=>{let n=AN();n&&(a(null),n[e]().catch(n=>{d.system.error(`Update ${e} failed`,n),a(IN(n,t))}))},[t]);if(n)return null;let s=e.installFailed?t(`update.chip.installFailedDetail`,e.installFailed):null,c=e.status===`downloading`||e.status===`downloaded`;if(e.startFailed&&e.previousVersion&&!c)return V(`div`,{className:`update-chip update-chip--error`,role:`status`,children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,title:i??void 0,children:t(i?`update.chip.updateFailed`:`update.chip.startFailed`)}),P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`revertUpdate`),children:t(`update.chip.goBack`,{version:e.previousVersion})}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]});let l=e.status===`available`||e.status===`downloaded`;if(s&&!l)return V(`div`,{className:`update-chip update-chip--error`,role:`status`,title:s??void 0,children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:t(`update.chip.installFailed`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]});if(e.status===`idle`||e.status===`checking`||e.status===`disabled`||e.status===`no-channel`)return null;if(e.status===`downloading`){let n=Math.max(0,Math.min(100,e.progress));return V(`div`,{className:`update-chip update-chip--downloading`,role:`status`,"aria-live":`polite`,title:t(`update.chip.downloadingTitle`,{version:e.version??``}),children:[P(Jr,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:e.preparing?t(`update.chip.preparing`):t(`update.chip.downloading`,{pct:n})})]})}return e.status===`available`?V(`div`,{className:`update-chip update-chip--available`,role:`status`,title:i||s||e.releaseNotes||t(`update.chip.availableTitle`),children:[P(Jr,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:i?t(`update.chip.updateFailed`):s?t(`update.chip.installFailed`):t(`update.chip.available`,{version:e.version??``})}),!e.pinnedVersion&&P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`downloadUpdate`),children:t(`update.chip.updateNow`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismiss`),children:P(Y,{size:11})})]}):e.status===`downloaded`?V(`div`,{className:`update-chip update-chip--ready`,role:`status`,"aria-live":`polite`,children:[P(Fa,{size:13,className:`update-chip__icon`}),P(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`restart`),title:i||s||t(`update.chip.restartTitle`),children:t(i?`update.chip.restartFailed`:s?`update.chip.installFailedRetry`:`update.chip.ready`)})]}):e.status===`error`?V(`div`,{className:`update-chip update-chip--error`,role:`status`,title:e.error||t(`update.chip.checkFailed`),children:[P(J,{size:13,className:`update-chip__icon`}),P(`span`,{className:`update-chip__label`,children:t(`update.chip.checkFailed`)}),P(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>r(!0),"aria-label":t(`update.chip.dismissError`),children:P(Y,{size:11})})]}):null}var QP={permission_request:{icon:P(Ga,{size:16}),colorClass:`notif-type-permission`},policy_alert:{icon:P(Ga,{size:16}),colorClass:`notif-type-policy`},security_alert:{icon:P(J,{size:16}),colorClass:`notif-type-security`},status_change:{icon:P(Er,{size:16}),colorClass:`notif-type-status`},info:{icon:P(Hi,{size:16}),colorClass:`notif-type-info`},error:{icon:P(wr,{size:16}),colorClass:`notif-type-error`}};function $P(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 eF({onClose:e}){let t=T(),n=Qs(ko(ec)),r=Qs($s),i=Qs(e=>e.markRead),a=Qs(e=>e.markAllRead),o=Qs(e=>e.clearAll),s=Qs(e=>e.dismiss),c=Qs(e=>e.respondToPermission),l=Qs(e=>e.typeFilter),u=Qs(e=>e.setTypeFilter),d=(0,X.useCallback)(e=>{i(e)},[i]),f=(0,X.useCallback)(e=>{c(e.id,`allow`).catch(e=>console.error(`[NotificationCenter] allow failed:`,e))},[c]),p=(0,X.useCallback)(e=>{c(e.id,`deny`).catch(e=>console.error(`[NotificationCenter] deny failed:`,e))},[c]);Io(!0,e);let m=[{key:null,label:t(`notifications.filter.all`)},{key:`permission_request`,label:t(`notifications.filter.permissions`)},{key:`policy_alert`,label:t(`notifications.filter.policy`)},{key:`error`,label:t(`notifications.filter.errors`)},{key:`security_alert`,label:t(`notifications.filter.security`)},{key:`status_change`,label:t(`notifications.filter.status`)},{key:`info`,label:t(`notifications.filter.info`)}];return V(`div`,{className:`notification-center`,role:`dialog`,"aria-label":t(`notifications.dialogAria`),children:[V(`div`,{className:`notification-center-header`,children:[V(`div`,{className:`notification-center-title-row`,children:[P(`h2`,{className:`notification-center-title`,children:t(`notifications.title`)}),r>0&&P(`span`,{className:`notification-center-badge`,children:r})]}),P(`button`,{className:`btn-icon notification-center-close`,onClick:e,"aria-label":t(`notifications.close`),children:P(Y,{size:18})})]}),P(`div`,{className:`notification-filter-bar`,role:`tablist`,"aria-label":t(`notifications.filterAria`),children:m.map(e=>P(`button`,{role:`tab`,"aria-selected":l===e.key,className:`notification-filter-tab ${l===e.key?`active`:``}`,onClick:()=>u(e.key),children:e.label},e.key??`all`))}),P(`div`,{className:`notification-list`,children:n.length===0?V(`div`,{className:`notification-empty`,children:[P(er,{size:40,strokeWidth:1.2}),P(`span`,{children:t(`notifications.empty`)})]}):n.map(e=>{let n=QP[e.type],r=e.type===`permission_request`&&e.tool?Ks(e,t,iy):null;return V(`div`,{className:`notification-item ${e.read?``:`unread`} ${n.colorClass}`,id:e.type===`policy_alert`&&e.receiptId?`policy-receipt-${encodeURIComponent(e.receiptId)}`:void 0,onClick:()=>d(e.id),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&d(e.id)},children:[!e.read&&P(`span`,{className:`notification-unread-dot`}),P(`span`,{className:`notification-icon`,children:n.icon}),V(`div`,{className:`notification-content`,children:[V(`div`,{className:`notification-content-header`,children:[P(`span`,{className:`notification-agent`,dir:`auto`,children:e.agentName}),P(`span`,{className:`notification-time`,children:$P(e.timestamp,t)})]}),r?V(D.Fragment,{children:[P(`span`,{className:`notification-title`,children:P(sy,{text:r.heading})}),P(`span`,{className:`notification-message`,children:P(sy,{text:r.question})})]}):V(D.Fragment,{children:[e.title&&P(`span`,{className:`notification-title`,children:e.title}),P(`span`,{className:`notification-message`,children:e.message})]}),e.type===`permission_request`&&e.tool&&e.tool!==`allow_path_access`&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.tool`),`: `,P(`code`,{dir:`ltr`,children:e.tool})]}),e.type===`policy_alert`&&V(`div`,{className:`notification-policy-details`,children:[e.tool&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.tool`),`: `,P(`code`,{dir:`ltr`,children:e.tool})]}),e.reason&&V(`span`,{className:`notification-policy-reason`,children:[t(`notifications.reason`),`: `,e.reason]}),e.ruleIds&&e.ruleIds.length>0&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.rules`),`: `,P(`code`,{dir:`ltr`,children:e.ruleIds.join(`, `)})]}),e.policyVersion&&V(`span`,{className:`notification-tool`,children:[t(`activity.policy.policy`),`: `,P(`code`,{dir:`ltr`,children:e.policyVersion})]}),V(`span`,{className:`notification-tool`,children:[t(`activity.policy.receipt`),`:`,` `,e.receiptId?P(`code`,{dir:`ltr`,children:e.receiptId}):P(`em`,{children:t(`activity.policy.receiptUnavailable`)})]})]}),e.type===`permission_request`&&!e.response&&V(`div`,{className:`notification-actions`,children:[V(`button`,{className:`notification-action-btn notification-action-allow`,onClick:t=>{t.stopPropagation(),f(e)},children:[P(mr,{size:14}),t(`notifications.approve`)]}),V(`button`,{className:`notification-action-btn notification-action-deny`,onClick:t=>{t.stopPropagation(),p(e)},children:[P(Y,{size:14}),t(`notifications.deny`)]})]}),e.type===`permission_request`&&e.response&&P(`span`,{className:`notification-response-badge ${e.response===`allow`?`response-allow`:`response-deny`}`,children:e.response===`allow`?t(`notifications.approved`):t(`notifications.denied`)})]}),P(`button`,{className:`notification-dismiss`,onClick:t=>{t.stopPropagation(),s(e.id)},"aria-label":t(`notifications.dismiss`),children:P(Y,{size:14})})]},e.id)})}),n.length>0&&V(`div`,{className:`notification-center-footer`,children:[V(`button`,{className:`notification-footer-btn`,onClick:a,disabled:r===0,children:[P(mr,{size:14}),t(`notifications.markAllRead`)]}),V(`button`,{className:`notification-footer-btn notification-footer-clear`,onClick:o,children:[P(lo,{size:14}),t(`notifications.clear`)]})]})]})}var tF=1500,nF=e=>new Promise(t=>setTimeout(t,e));async function rF({onProgress:e,isCancelled:t=()=>!1,pollMs:n=tF}={}){try{await sn(ck)}catch(e){if(e?.httpStatus!==409)throw e;let t=await Ut(ck).catch(()=>null);if(!t||t.status===`completed`||t.status===`failed`)throw e}for(;!t();){let t=await Ut(ck);if(e?.(t),t.status===`completed`)return;if(t.status===`failed`)throw Error(t.error||`The GAIA agent could not be installed.`);await nF(n)}}function iF({onInstalled:e,noBuild:t=!1}){let n=T(),[r,i]=(0,X.useState)({kind:`idle`}),a=(0,X.useRef)(!1);(0,X.useEffect)(()=>()=>{a.current=!0},[]);let o=(0,X.useCallback)(async()=>{i({kind:`installing`,percent:0});try{if(await rF({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 aF(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 oF(e,t){let{addNotification:n}=Qs.getState();for(let r of t)r.error_count<=(e[r.id]??0)||!r.last_error||n({id:`schedule-error-${r.id}-${r.error_count}`,type:`error`,agentId:`scheduler`,agentName:`GAIA`,title:`Scheduled task "${r.name}" failed`,message:r.last_error,timestamp:Date.now(),read:!1,dismissed:!1,priority:`high`,...r.session_id?{sessionId:r.session_id}:{}})}var sF=p((e,t)=>({schedules:[],loading:!1,error:null,actionError:null,selectedSchedule:null,results:[],resultsLoading:!1,errorCounts:null,loadSchedules:async()=>{t().schedules.length===0&&!t().error&&e({loading:!0}),e({error:null});try{let n=(await At()).schedules||[],r=t().errorCounts;r&&oF(r,n),e({schedules:n,loading:!1,errorCounts:Object.fromEntries(n.map(e=>[e.id,e.error_count]))})}catch(t){d.api.error(`Failed to load schedules`,t),e({error:`Failed to load schedules`,loading:!1})}},createSchedule:async(t,n,r)=>{try{let i=await yt(t,n,r);e(e=>({schedules:[...e.schedules,i],actionError:null}))}catch(e){throw d.api.error(`Failed to create schedule`,e),e}},updateScheduleStatus:async(t,n)=>{try{let r=await ut(t,n);e(e=>({schedules:e.schedules.map(e=>e.name===t?r:e),actionError:null}))}catch(n){d.api.error(`Failed to update schedule "${t}"`,n),e({actionError:aF(n,`Failed to update schedule`)})}},runScheduleNow:async t=>{try{let n=await Jt(t);e(e=>({schedules:e.schedules.map(e=>e.name===t?n:e),actionError:null}))}catch(n){d.api.error(`Failed to run schedule "${t}" now`,n),e({actionError:aF(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:aF(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})})),cF=new Set([`loading_model`,`downloading_model`,`model_retry`,`waiting`]),lF=5;function uF(e,t){return{id:e,title:t.get(e)?.title??`Untitled chat`}}function dF(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=>({...uF(e,t),reason:`approval`}));n&&e.awaitingUser&&!a.has(e.currentSessionId)&&o.push({...uF(e.currentSessionId,t),reason:`answer`});for(let[n,r]of Object.entries(e.awaitingBySession))o.some(e=>e.id===n)||o.push({...uF(n,t),reason:r===`question`?`answer`:`approval`});let s=n&&!e.awaitingUser&&e.livePhase&&cF.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,lF).map(e=>uF(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=>uF(e,t)),needsYou:o,recent:u}}function fF(e){let t=(0,X.useRef)(e);t.current=e,(0,X.useEffect)(()=>{let e=window.gaiaAPI?.tray;if(!e)return;let n=``,r=null,i=()=>{let t=k.getState(),i={backendConnected:t.backendConnected,systemStatus:t.systemStatus,sessions:t.sessions,runningSessionIds:t.runningSessionIds,awaitingBySession:t.awaitingBySession,currentSessionId:t.currentSessionId,isStreaming:t.isStreaming,awaitingUser:t.awaitingUser,liveStatus:t.liveStatus,livePhase:t.livePhase,notifications:Qs.getState().notifications},a=r;if(r=i,a&&Object.keys(i).every(e=>i[e]===a[e]))return;let o=dF(i),s=JSON.stringify(o);s!==n&&(n=s,e.setActivity(o).catch(e=>{n=``,d.system.error(`The tray could not take the app state`,e)}))};i();let a=k.subscribe(i),o=Qs.subscribe(i),s=e.onCommand(e=>{switch(e.type){case`open-chat`:t.current.openChat(e.sessionId);break;case`new-chat`:t.current.newChat();break;case`open-settings`:k.getState().openSettings(e.section);break;case`refresh-status`:t.current.refreshStatus();break;default:d.system.error(`Unknown tray command`,e)}});return()=>{a(),o(),s()}},[])}function pF(){(0,X.useEffect)(()=>{let e=window.gaiaAPI;if(!e)return;let t=Qs.getState().addNotification,n=[e.notification.onNotification(t),e.notification.onPermissionRequest(t),e.tray.onNavigate(e=>{let t=typeof e==`string`&&e.startsWith(`session:`)?e.slice(8):null;if(!t)return;let n=k.getState();n.currentSessionId!==t&&n.setMessages([]),n.setCurrentSession(t)})];return()=>n.forEach(e=>e())},[])}function mF(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 hF(){let[e,t]=(0,X.useState)(null);return(0,X.useEffect)(()=>{let e=navigator;if(!e.getBattery)return;let n=null,r=()=>{n&&t({charging:n.charging,level:n.level})};return e.getBattery().then(e=>{n=e,r(),e.addEventListener(`levelchange`,r),e.addEventListener(`chargingchange`,r)}).catch(e=>d.system.warn(`Battery level unavailable; keep-awake ignores the battery policy.`,e)),()=>{n?.removeEventListener(`levelchange`,r),n?.removeEventListener(`chargingchange`,r)}},[]),e}function gF(){pF();let e=k(e=>e.runningSessionIds),t=k(e=>e.awaitingBySession),n=k(e=>e.sessions),r=k(e=>e.currentSessionId),i=Qs(ko(nc)),a=lc(),o=hF(),s=(0,X.useRef)(null),c=gc(e,t,i),l=JSON.stringify(c);(0,X.useEffect)(()=>{let e=JSON.parse(l),t=s.current;if(s.current=e,t===null)return;let{sessions:n,currentSessionId:r}=k.getState(),i=document.hasFocus(),o=!1;for(let{sessionId:s,event:c}of _c(t,e)){let e=n.find(e=>e.id===s);if(e?.kind===`eval`||e?.kind===`scheduled`)continue;let t=a.modes[c];if(!(t===`off`||bc(s,r,i))&&(o=!0,t===`banner`)){if(c!==`finished`){let{title:t,body:n}=yc(c,e);mF(s,t,n)}else mt(s).then(e=>{k.getState().updateSessionInList(s,e);let{title:t,body:n}=yc(c,e);mF(s,t,n)}).catch(t=>{d.system.error(`Could not read how chat ${s} ended`,t);let{title:n,body:r}=yc(c,{...e,last_run_status:null});mF(s,n,r)})}}if(o){if(a.sound)try{Cc()}catch(e){d.system.warn(`Alert sound not played`,e)}a.flash&&!i&&window.gaiaAPI&&window.gaiaAPI.notification.flash().catch(e=>d.system.error(`Could not flash the taskbar button`,e))}},[l,a.modes,a.sound,a.flash]);let u=xc(n,c,a.modes,r);(0,X.useEffect)(()=>{window.gaiaAPI?.notification.setAttentionCount(u).catch(e=>d.system.error(`Could not update the taskbar badge`,e))},[u]);let f=a.keepAwake&&e.length>0&&Sc(o,a.batteryFloor);(0,X.useEffect)(()=>{window.gaiaAPI?.power.setKeepAwake(f).catch(e=>d.system.error(`Could not change keep-awake`,e))},[f])}function _F(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 vF(e){return e.replace(/-/g,``).slice(0,7)}function yF(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 bF(e,t,n){return!e||t&&(e===t||e===vF(t))?null:n.some(t=>t.id===e)?e:yF(n,e)}function xF(e){return new URLSearchParams(e.search).get(`session`)||e.hash.replace(/^#/,``)||null}var SF=`gaia:last-session`;function CF(e){try{e?localStorage.setItem(SF,e):localStorage.removeItem(SF)}catch(e){d.ui.warn(`Could not save the open chat for the next launch`,e)}}function wF(){try{return localStorage.getItem(SF)}catch(e){return d.ui.warn(`Could not read the chat open at last launch`,e),null}}var TF=1e3,EF=3e4;function DF(e,{initialMs:t=TF,maxMs:n=EF,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 OF(e,t,n){return e&&!t&&!n}var kF=(0,X.lazy)(()=>zP(()=>import(`./MemoryDashboard-J8lGJ5sQ.js`).then(e=>({default:e.MemoryDashboard})),__vite__mapDeps([6,1,2,7,8]),import.meta.url)),AF=(0,X.lazy)(()=>zP(()=>import(`./ScheduleManager-DDolvLap.js`).then(e=>({default:e.ScheduleManager})),__vite__mapDeps([9,1,2,7,3,10]),import.meta.url)),jF=(0,X.lazy)(()=>zP(()=>import(`./DocumentLibrary-Bx1pci4R.js`).then(e=>({default:e.DocumentLibrary})),__vite__mapDeps([11,1,2,3,12]),import.meta.url)),MF=(0,X.lazy)(()=>zP(()=>import(`./FileBrowser-CjvNU8QP.js`).then(e=>({default:e.FileBrowser})),__vite__mapDeps([13,1,2,3,14]),import.meta.url)),NF=(0,X.lazy)(()=>zP(()=>import(`./MobileAccessModal-B-TmXjst.js`).then(e=>({default:e.MobileAccessModal})),__vite__mapDeps([15,1,2,3,16]),import.meta.url)),PF=3,FF=3e5,IF=6e3,LF=6e4,RF=e=>e instanceof TypeError,zF=e=>new Promise(t=>setTimeout(t,e)),BF=3e5,VF=class extends Error{};async function HF(){let e=Date.now()+BF;for(;;){let t=await it();if(t.state===`ready`)return;if(t.state===`failed`||t.state===`cancelled`)throw new VF(t.error||I().bare(`setup.upgrading.stopped`));if(Date.now()>=e)throw Error(I().bare(`setup.upgrading.slow`));await zF(TF)}}function UF(){return P(`div`,{className:`loading-spinner`,role:`status`,"aria-label":`Loading`})}var WF=e=>e===1||e%10==0;function GF(){let e=T(),t=k(e=>e.currentSessionId),n=k(e=>e.setSessions),r=k(e=>e.setCurrentSession),i=k(e=>e.addSession),a=k(e=>e.setMessages),o=k(e=>e.showDocLibrary),s=k(e=>e.showFileBrowser),c=k(e=>e.showMemoryDashboard),l=k(e=>e.showSchedules),u=k(e=>e.sidebarOpen),f=k(e=>e.sidebarCollapsed),p=k(e=>e.setSidebarOpen),h=k(e=>e.setSystemStatus),g=k(e=>e.setBackendConnected),_=k(e=>e.setAgents),v=k(e=>e.agents),y=k(e=>e.setPendingPrompt),b=k(e=>e.setDefaultPermissionMode),x=k(e=>e.openSettings),S=k(e=>e.settingsSection),C=k(e=>e.syncSystemTheme),w=cs(e=>e.restoreNotice),E=cs(e=>e.dismissRestoreNotice),D=Qs(e=>e.showPanel),O=k(e=>e.systemStatus?.initialized===!0),A=(0,X.useRef)(!1),j=Qs(e=>e.setShowPanel);(0,X.useEffect)(()=>{if(!w?.ok)return;let e=setTimeout(E,IF);return()=>clearTimeout(e)},[w,E]);let[M,N]=(0,X.useState)({state:`checking`}),F=k(e=>e.setupAgain),I=k(e=>e.runSetupAgain),ee=(0,X.useRef)(M);ee.current=M;let[R,z]=(0,X.useState)(!1),B=(0,X.useRef)(R);B.current=R;let[te,ne]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(!1),ae=te||R&&!lk(v),oe=(0,X.useRef)(ae);oe.current=ae;let[H,se]=(0,X.useState)(null),[W,G]=(0,X.useState)(``),[ce,le]=(0,X.useState)(0),[de,fe]=(0,X.useState)(!1),[pe,me]=(0,X.useState)(!1),[he,ge]=(0,X.useState)(null),[_e,ve]=(0,X.useState)(null),ye=(0,X.useRef)(async()=>{}),be=(0,X.useRef)(async()=>{}),xe=(0,X.useCallback)(async(e=!1,t=!1)=>{e||N({state:`checking`});let n=0;try{for(;;){await cs.getState().refresh();let e=!!cs.getState().active?.remote,r;try{r=await Wt(e)}catch(e){if(!t||!RF(e)||n>=LF)throw e;await zF(TF),n+=TF;continue}if(!r.ready&&r.stage===`upgrade`){N({state:`upgrading`});let t=await it();(!t.upgrade_embedded||t.state!==`running`&&t.state!==`verifying`)&&await _t(e,!1,{upgradeEmbedded:!0}),await HF(),r=await Wt(e)}n>0&&await Promise.all([ye.current(),be.current()]),ie(!!r.no_agent_build),N(r.ready?{state:`ready`}:{state:`needed`,check:r});return}}catch(e){let t=e instanceof Error?e.message:String(e);if(e instanceof VF){d.system.warn(`Updating the local model server failed`,e),N({state:`unknown`,error:t,upgradeFailed:!0});return}d.system.warn(`Setup check could not be answered`,e),N({state:`unknown`,error:t})}},[]),Se=(0,X.useRef)(0),Ce=(0,X.useCallback)(async()=>{let e=++Se.current,t=(await vn()).agents||[];e===Se.current&&(_(t),z(!0),lk(t)&&ne(!1))},[_]),we=(0,X.useCallback)(()=>{let e=B.current;z(!1),Ce().catch(t=>{d.api.warn(`Agent list unavailable after setup`,t),e&&z(!0)})},[Ce]);(0,X.useEffect)(()=>{let e=()=>{oe.current&&Ce().catch(e=>d.api.warn(`Agent list unavailable`,e))};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[Ce]);let Te=(0,X.useCallback)(async()=>{b((await on()).default_mode)},[b]),Ee=(0,X.useRef)([]);(0,X.useEffect)(()=>{m(`0.26.0rc12`),xe(!1,!0);let e=[DF(Ce,{onError:(e,t)=>{WF(t)&&d.api.warn(`Agent list unavailable (attempt ${t}); retrying`,e)}}),DF(Te,{onError:(e,t)=>{WF(t)&&d.api.warn(`Default permission mode unavailable (attempt ${t}); retrying`,e)}})];return Ee.current=e,()=>e.forEach(e=>e.stop())},[xe,Ce,Te]);let De=(0,X.useCallback)(()=>{Ee.current.forEach(e=>e.kick()),cs.getState().retryNow(),be.current();let e=ee.current;e.state===`unknown`&&!e.upgradeFailed&&xe(!0)},[xe]),Oe=(0,X.useRef)(De);Oe.current=De;let ke=(0,X.useRef)(0),Ae=(0,X.useRef)(0),je=(0,X.useRef)(null),Me=(0,X.useRef)(!1),[Ne,Pe]=(0,X.useState)(!1),[Fe,Ie]=(0,X.useState)(null),Le=(0,X.useCallback)(e=>{if(e.kind===`unreachable`){d.system.warn(`System status check failed`,e.error),Me.current=!0,Ae.current=0,je.current=null,Pe(!1),Ie(null),g(!1),h(null);return}if(e.kind===`error`){d.system.warn(`System status answered HTTP ${e.httpStatus}`,e.message),Me.current&&Oe.current(),Me.current=!1,Ae.current=0,je.current=null,Pe(!1),Ie(`HTTP ${e.httpStatus}: ${e.message}`),g(!0);return}if(e.kind===`slow`){if(Ae.current+=1,je.current??=Date.now(),Ie(null),d.system.warn(`System status did not answer in time (${Ae.current} in a row)`),Date.now()-je.current>=FF){Pe(!1),g(!1),h(null);return}g(!0),(Me.current||Ae.current>=PF)&&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>=PF||!n?.lemonade_running?h(t):h({...n,download_progress:t.download_progress})},[g,h]),Re=(0,X.useRef)(Le);Re.current=Le;let[ze]=(0,X.useState)(()=>Kw(e=>Re.current(e))),Be=ze.check;ye.current=Be,(0,X.useEffect)(()=>_k(ze.start),[ze]),(0,X.useEffect)(()=>GP(()=>{Be()}),[Be]);let Ve=(0,X.useRef)(``);(0,X.useEffect)(()=>{let e=e=>Ft().then(t=>{let r=t.sessions||[];if(!e&&r.length===0&&k.getState().sessions.length>0)return;let i=r.map(e=>`${e.id}|${e.updated_at}|${e.title}|${e.inference_remote}|${e.inference_provider}|${e.inference_description}|${e.effective_model}|${e.unread}|${e.pinned}|${e.last_run_status}|${e.kind}`).join(`
|
|
82
|
+
`);if(i===Ve.current)return;Ve.current=i,n(r);let a=cs.getState().active?.model;a&&r.some(e=>e.effective_model&&e.effective_model!==a)&&cs.getState().refresh()}).catch(t=>{e&&d.system.error(`Could not load chats`,t)});be.current=()=>e(!1),e(!0);let t=setInterval(()=>void e(!1),5e3);return()=>clearInterval(t)},[n]),(0,X.useEffect)(()=>aT(),[]),(0,X.useEffect)(()=>{let e=()=>{sF.getState().loadSchedules()};e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[]),(0,X.useEffect)(()=>CT(),[]),gF();let He=(0,X.useRef)(!1),Ue=(0,X.useRef)(!1);(0,X.useEffect)(()=>{let e=()=>{let e=xF(window.location),{currentSessionId:t,sessions:n}=k.getState(),i=bF(e,t,n);return i&&(r(i),a([])),i},t=()=>{if(He.current||(He.current=!0,e()||k.getState().currentSessionId))return;if(window.location.hash){window.history.replaceState(null,``,window.location.pathname+window.location.search);return}if(Ue.current||xn(`new-chat`))return;let{sessions:t}=k.getState(),n=bF(wF(),null,t);n&&(r(n),a([]))},n=k.subscribe(e=>{e.sessions.length>0&&t()});return k.getState().sessions.length>0&&t(),window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{n(),window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[r,a]),(0,X.useEffect)(()=>{let e=null,t=2e3,n=!1,i=null,o=()=>{n||(e=new EventSource(`${L()}/sessions/events`),e.onopen=()=>{t=2e3},e.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch(e){d.api.warn(`Malformed session event`,e);return}t.type===`set_active_session`&&t.session_id&&t.session_id!==k.getState().currentSessionId&&(r(t.session_id),a([]))},e.onerror=()=>{e?.close(),e=null,!n&&(i=setTimeout(o,t),t=Math.min(t*2,3e4))})};return o(),()=>{n=!0,i&&clearTimeout(i),e?.close()}},[r,a]),(0,X.useEffect)(()=>{if(He.current&&CF(t),t){let e=vF(t);window.location.hash!==`#${e}`&&window.history.replaceState(null,``,`#${e}`)}else He.current&&window.location.hash&&window.history.replaceState(null,``,window.location.pathname+window.location.search)},[t]);let We=(0,X.useCallback)(async e=>{if(se(null),!await Go(`chat`))return G(e),!1;let t=k.getState(),n;try{n=await En({title:`New Task`,agent_type:ck,document_ids:t.draftDocumentIds,private:t.draftPrivate,folders:t.draftFolder?[t.draftFolder]:[]})}catch(e){throw uk(e)?(ne(!0),Error(`The GAIA agent isn't installed. Install it from the notice above, then send again.`)):e}oe.current&&(ne(!1),Ce().catch(e=>d.api.warn(`Agent list unavailable`,e))),t.defaultPermissionModeKnown||(await Te().catch(e=>d.api.warn(`Default permission mode unavailable; using the chip's mode`,e)),t=k.getState()),t.clearDraftDocuments(),t.setDraftPrivate(!1),t.setDraftFolder(null);let o=null;try{await Pt(n.id,t.draftPermissionMode)}catch(e){o=e}return Mt(Je),o&&!n.private&&nn(U(n.id),e),i(n),r(n.id),a([]),G(``),o?(se(`The chat was created, but its permission mode could not be set, so your message was not sent${n.private?``:` — it is in the chat's box`}: ${o instanceof Error?o.message:o}`),!1):(t.resetDraftPermissionMode(),y({sessionId:n.id,text:e}),!0)},[i,r,a,y,Ce,Te]),Ge=(0,X.useCallback)(()=>{let e=k.getState(),t=e.currentSessionId;t&&jc(t,e)&&Mc(t),e.setShowMemoryDashboard(!1),e.setShowSchedules(!1),Ue.current=!0,r(null),a([]),le(e=>e+1)},[r,a]);fF({openChat:(0,X.useCallback)(e=>{let t=k.getState();t.closeSettings(),e!==t.currentSessionId&&(Mc(t.currentSessionId),a([])),r(e)},[r,a]),newChat:(0,X.useCallback)(()=>{k.getState().closeSettings(),Ge()},[Ge]),refreshStatus:()=>void Be()});let Ke=(0,X.useCallback)(e=>{Ge(),We(`Load the \`${e}\` skill, then tell me briefly what it lets you do.`).catch(e=>se(e instanceof Error?e.message:String(e)))},[Ge,We]),qe=(0,X.useCallback)(e=>{N({state:`ready`}),we(),Be(),e&&(e.needs_input?G(e.prompt):We(e.prompt).catch(e=>se(e instanceof Error?e.message:String(e))))},[Be,We,we]),Ye=(0,X.useCallback)(()=>{N({state:`ready`}),Be()},[Be]);(0,X.useEffect)(()=>{let e=()=>{k.getState().closeSettings(),N({state:`addingLocal`})};return window.addEventListener(`gaia:set-up-local`,e),()=>window.removeEventListener(`gaia:set-up-local`,e)},[]),(0,X.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&(e.shiftKey&&e.key.toLowerCase()===`o`?(e.preventDefault(),Ge()):!e.shiftKey&&e.key.toLowerCase()===`k`?(e.preventDefault(),window.dispatchEvent(new CustomEvent(`gaia:focus-search`))):!e.shiftKey&&e.key.toLowerCase()===`b`?(e.preventDefault(),k.getState().toggleSidebarCollapsed()):!e.shiftKey&&e.key===`,`&&(e.preventDefault(),x()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Ge,x]),(0,X.useEffect)(()=>{let e=window.matchMedia?.(`(max-width: 768px)`);if(!e)return;let t=()=>p(!e.matches);return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[p]),(0,X.useEffect)(()=>{if(typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(prefers-color-scheme: light)`);return e.addEventListener(`change`,C),()=>e.removeEventListener(`change`,C)},[C]),(0,X.useEffect)(()=>{Sn().then(e=>me(e.active===!0)).catch(e=>d.system.debug(`Mobile access unavailable`,e))},[]);let Xe=(0,X.useCallback)(async()=>{if(fe(!0),ge(null),pe)ve(null);else try{let e=await Pn(),t=e.reason===`ngrok_not_installed`;if(ve(t?e.installCommands??[]:null),t)return;e.error?ge(e.error):me(!0)}catch(e){ve(null),ge(e instanceof Error?e.message:`Could not start mobile access`)}},[pe]),Ze=(0,X.useCallback)(async()=>{try{await ue(),me(!1),fe(!1)}catch(e){ge(e instanceof Error?e.message:`Could not stop mobile access`)}},[]);ND(e=>{e?Xe():Ze()}),(0,X.useEffect)(()=>{jD(pe)},[pe]);let Qe=zc(`(max-width: 768px)`),$e=OF(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(xN,{onReady:e=>{I(!1),qe(e)},onClose:e}),P(UA,{}),P(ZP,{})]})}let et=c?P(X.Suspense,{fallback:P(UF,{}),children:P(kF,{})}):t?P(Ak,{sessionId:t},t):P(RA,{onSend:We,initialText:W,focusRequest:ce},W);return V(`div`,{className:`app`,children:[!u&&P(`button`,{className:`sidebar-toggle`,onClick:()=>p(!0),"aria-label":`Open sidebar`,children:P(sa,{size:18})}),P(`div`,{className:`sidebar-overlay ${u?`visible`:``}`,onClick:()=>p(!1),"aria-hidden":`true`}),P(MP,{area:`sidebar`,variant:`compact`,children:P(ol,{onNewChat:Ge,onMobileAccess:Qe?void 0:()=>void Xe(),tunnelActive:pe})}),V(`div`,{className:`main-content`,children:[M.state===`ready`&&P(XP,{onRetry:Be,backendSlow:Ne,backendError:Fe}),M.state===`unknown`&&(M.upgradeFailed?V(`div`,{className:`app-notice is-warning`,role:`status`,children:[P(`span`,{children:e(`setup.upgrading.failed`,{error:M.error})}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>void xe(),children:e(`setup.upgrading.retry`)})]}):V(`div`,{className:`app-notice is-warning`,role:`status`,children:[P(`span`,{children:e(`setup.unknown.failed`,{error:M.error})}),P(`button`,{type:`button`,className:`link-btn`,onClick:()=>void xe(),children:e(`setup.unknown.retry`)})]})),(!u||f)&&P(Rs,{placement:`main`}),ae&&P(iF,{onInstalled:Ce,noBuild:re}),w&&V(`div`,{className:`app-notice${w.ok?``:` is-warning`}`,role:`status`,children:[P(`span`,{children:w.message}),!w.ok&&P(`button`,{type:`button`,className:`link-btn`,onClick:()=>{E(),x(`model`)},children:`Pick a model`}),P(`button`,{type:`button`,className:`app-notice-close`,onClick:E,"aria-label":`Dismiss`,children:P(Y,{size:14})})]}),P(MP,{resetKey:c?`memory`:t??`new-${ce}`,area:`main`,children:et})]}),l&&P(X.Suspense,{fallback:null,children:P(AF,{})}),o&&P(X.Suspense,{fallback:null,children:P(jF,{})}),s&&P(X.Suspense,{fallback:null,children:P(MF,{onStartChat:We})}),D&&P(`div`,{className:`notification-center-popover`,children:P(eF,{onClose:()=>j(!1)})}),de&&P(X.Suspense,{fallback:null,children:P(NF,{isOpen:de,onClose:()=>fe(!1),onStop:()=>void Ze(),error:he,setupCommands:_e,onRetry:()=>void Xe()})}),S&&P(UP,{onUseSkill:Ke}),P(UA,{}),P(ZP,{}),H&&V(`div`,{className:`toast toast-dismissible`,role:`alert`,children:[P(`span`,{children:H}),P(`button`,{type:`button`,className:`toast-dismiss`,onClick:()=>se(null),"aria-label":e(`banner.dismiss`),children:P(Y,{size:14,"aria-hidden":`true`})})]})]})}var KF=`agent-refresh`,qF={"pre-checks":`engine.stage.preChecks`,"ensure-uv":`engine.stage.ensureUv`,"create-venv":`engine.stage.createVenv`,"install-package":`engine.stage.installPackage`,verify:`engine.stage.verify`,[KF]:`engine.stage.agentRefresh`,start:`engine.stage.start`},JF={disk:`engine.hint.disk`,network:`engine.hint.network`,tls:`engine.hint.tls`,locked:`engine.hint.locked`,daemon:`engine.hint.daemon`};function YF(e,t){if(!e)return t(`engine.stage.neutral`);let n=qF[e];return n?t(n):(console.warn(`[EngineInstallScreen] install stage "${e}" has no label`),t(`engine.stage.neutral`))}function XF(e,t){return e.reason?t(JF[e.reason]):t(e.stage===KF?`engine.hint.agent`:`engine.hint.other`)}function ZF(e){return e.reason===`locked`&&e.lockedBy?.length?e.lockedBy:null}function QF(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 $F({status:e}){let t=T(),n=YF(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 eI({error:e,busy:t,notice:n,onRetry:r,onCloseLockers:i,onContinue:a,onRevert:o,onOpenLog:s}){let c=T(),l=ZF(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:QF(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:XF(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===KF&&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
|
+
`)}),P(`button`,{type:`button`,className:`btn-secondary`,onClick:s,children:c(`engine.openLog`)})]})]})}function tI(){let e=T(),[t,n]=(0,X.useState)({phase:`running`,stage:null,percent:null,message:``,error:null}),[r,i]=(0,X.useState)(!1),[a,o]=(0,X.useState)(null),s=(0,X.useCallback)(e=>{console.error(`[EngineInstallScreen] the desktop app did not answer`,e),o(e instanceof Error?e.message:String(e))},[]);(0,X.useEffect)(()=>{let e=window.gaiaInstall,t=e.onProgress(n);return e.status().then(n).catch(s),t},[s]);let c=(0,X.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.retry().catch(s).finally(()=>i(!1))},[s]),l=(0,X.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.closeLockingPrograms().catch(s).finally(()=>i(!1))},[s]),u=(0,X.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.continueWithoutAgentUpdate().catch(s).finally(()=>i(!1))},[s]),d=(0,X.useCallback)(()=>{i(!0),o(null),window.gaiaInstall.revert().then(e=>{e||i(!1)}).catch(e=>{s(e),i(!1)})},[s]),f=(0,X.useCallback)(()=>{o(null),window.gaiaInstall.openLogFile().then(e=>{e.ok||o(e.message)}).catch(s)},[s]),{error:p}=t,m=t.phase===`failed`&&p,h=e(m?p.stage===KF?`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(eI,{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($F,{status:t}),a&&P(`p`,{className:`engine-error`,role:`alert`,children:P(`bdi`,{dir:`ltr`,children:a})})]})]})})})}function nI(){return!!window.gaiaInstall&&new URLSearchParams(window.location.search).get(`engine`)===`install`}async function rI(e){if(!e.isProduction||e.protocol!==`https:`&&e.protocol!==`http:`||!e.serviceWorker)return!1;try{return await e.serviceWorker.register(`./sw.js`,{scope:`./`}),!0}catch(e){return console.error(`[pwa] Service worker registration failed, so the UI is not cached for an installed app:`,e),!1}}Vs(),u();var iI=localStorage.getItem(`gaia-chat-theme`);S(x(iI===`light`||iI===`dark`?iI:`system`));var aI=k.getState();i(aI.palette,aI.customColors,aI.theme),s(aI.locale),C(),l(),Co.createRoot(document.getElementById(`root`)).render(P(X.StrictMode,{children:P(MP,{area:`app`,variant:`window`,children:nI()?P(tI,{}):P(GF,{})})})),window.addEventListener(`load`,()=>{rI({isProduction:!0,protocol:window.location.protocol,serviceWorker:`serviceWorker`in navigator?navigator.serviceWorker:void 0})});export{Xh as $,eA as A,ni as At,sA as B,Er as Bt,Xk as C,na as Ct,vA as D,bi as Dt,Qk as E,Ei as Et,yA as F,Wr as Ft,hA as G,gr as Gt,_A as H,Sr as Ht,uA as I,Br as It,jT as J,Xn as Jt,LT as K,mr as Kt,dA as L,Pr as Lt,Kk as M,Xr as Mt,$k as N,Jr as Nt,Jk as O,vi as Ot,rA as P,Kr as Pt,Jh as Q,oA as R,Mr as Rt,Zk as S,q as St,iA as T,Ii as Tt,SA as U,br as Ut,lA as V,wr as Vt,tA as W,vr as Wt,IS as X,NT as Y,sS as Z,pA as _,Fa as _t,ZN as a,Go as at,Yk as b,Ca as bt,YN as c,xo as ct,WA as d,J as dt,Uh as et,kA as f,lo as ft,fA as g,za as gt,gA as h,Va as ht,zP as i,ds as it,mA as j,Qr as jt,qk as k,gi as kt,CN as l,ho as lt,CA as m,$a as mt,sF as n,Nc as nt,XN as o,Io as ot,xA as p,to as pt,zT as q,ir as qt,KP as r,Ec as rt,JN as s,Y as st,_F as t,Pc as tt,SN as u,po as ut,aA as v,Na as vt,nA as w,Qi as wt,wA as x,pa as xt,bA as y,Da as yt,cA as z,Or as zt};
|