@amd-gaia/agent-ui 0.25.4-rc.2 → 0.25.4-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ConnectorsPane-B71QL-Kl.js","./rolldown-runtime-XKyaHtl9.js","./apiBase-DRtaTd8u.js","./ConnectorsPane-Dzu2DRTc.css","./AdvancedSettings-B4MY5XPH.js","./MemoryDashboard-BQhg3t2B.js","./zap-BdhDcjhB.js","./MemoryDashboard-Dt6zI60b.css","./ScheduleManager-tcyjbGY9.js","./ScheduleManager-D5c4gVIt.css","./DocumentLibrary-c78Y6arz.js","./DocumentLibrary-CM6o8j2T.css","./FileBrowser-DwEPODjV.js","./FileBrowser-Cna3BsT7.css","./MobileAccessModal-RI4HtcYe.js","./MobileAccessModal-DuVy9F1u.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ConnectorsPane-CLQK0rsX.js","./rolldown-runtime-XKyaHtl9.js","./apiBase-DRtaTd8u.js","./ConnectorsPane-Dzu2DRTc.css","./AdvancedSettings-CHxpG8nH.js","./MemoryDashboard-D5NugQoq.js","./zap-BdhDcjhB.js","./MemoryDashboard-Dt6zI60b.css","./ScheduleManager-CkYWygZG.js","./ScheduleManager-D5c4gVIt.css","./DocumentLibrary-hSat3aHA.js","./DocumentLibrary-CM6o8j2T.css","./FileBrowser-BneKS6fe.js","./FileBrowser-Cna3BsT7.css","./MobileAccessModal-Cl7eErMB.js","./MobileAccessModal-DuVy9F1u.css"])))=>i.map(i=>d[i]);
2
2
  import{n as e,r as t,t as n}from"./rolldown-runtime-XKyaHtl9.js";import{C as r,S as i,T as a,_ as o,a as s,b as c,c as l,d as u,f as d,g as f,h as p,i as m,l as h,m as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C,v as w,w as T,x as E,y as D}from"./apiBase-DRtaTd8u.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 O=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&&A(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&&A(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 ee=new MessageChannel,k=ee.port2;ee.port1.onmessage=D,O=function(){k.postMessage(null)}}else O=function(){_(D,0)};function A(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,A(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}}}})),ee=n(((e,t)=>{t.exports=O()})),k=n((e=>{var t=a();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},o=Symbol.for(`react.portal`),s=Symbol.for(`react.recoverable`),c=Symbol.for(`react.optimistic_key`);function l(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:o,key:r==null?null:r===c?c:``+r,children:e,containerInfo:t,implementation:n}}var u=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function d(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:s,_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 l(e,t,null,r)},e.flushSync=function(e){var t=u.T,n=i.p;try{if(u.T=null,i.p=2,e)return e()}finally{u.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=d(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=d(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=d(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=d(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 u.H.useFormState(e,t,n)},e.useFormStatus=function(){return u.H.useHostTransitionStatus()},e.version=`19.3.1`})),A=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=k()})),j=n((e=>{var t=ee(),n=a(),r=A();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 o(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function s(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 c(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 l(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 u(e){if(s(e)!==e)throw Error(i(188))}function d(e){var t=e.alternate;if(!t){if(t=s(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 o=a.alternate;if(o===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===o.child){for(o=a.child;o;){if(o===n)return u(a),e;if(o===r)return u(a),t;o=o.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=o;else{for(var c=!1,l=a.child;l;){if(l===n){c=!0,n=a,r=o;break}if(l===r){c=!0,r=a,n=o;break}l=l.sibling}if(!c){for(l=o.child;l;){if(l===n){c=!0,n=o,r=a;break}if(l===r){c=!0,r=o,n=a;break}l=l.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 f(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=f(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`),j=Symbol.for(`react.strict_mode`),M=Symbol.for(`react.profiler`),te=Symbol.for(`react.consumer`),N=Symbol.for(`react.context`),ne=Symbol.for(`react.forward_ref`),re=Symbol.for(`react.suspense`),ie=Symbol.for(`react.suspense_list`),P=Symbol.for(`react.memo`),F=Symbol.for(`react.lazy`),I=Symbol.for(`react.activity`),ae=Symbol.for(`react.legacy_hidden`),oe=Symbol.for(`react.memo_cache_sentinel`),L=Symbol.for(`react.view_transition`),se=Symbol.for(`react.recoverable`),ce=Symbol.iterator;function le(e){return typeof e!=`object`||!e?null:(e=ce&&e[ce]||e[`@@iterator`],typeof e==`function`?e:null)}var ue=Symbol.for(`react.client.reference`);function de(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===ue?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case k:return`Fragment`;case M:return`Profiler`;case j:return`StrictMode`;case re:return`Suspense`;case ie:return`SuspenseList`;case I:return`Activity`;case L:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case O:return`Portal`;case N:return e.displayName||`Context`;case te:return(e._context.displayName||`Context`)+`.Consumer`;case ne:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case P:return t=e.displayName||null,t===null?de(e.type)||`Memo`:t;case F:t=e._payload,e=e._init;try{return de(e(t))}catch{}}return null}var fe=Array.isArray,R=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,z=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,pe={pending:!1,data:null,method:null,action:null},me=[],he=-1;function ge(e){return{current:e}}function B(e){0>he||(e.current=me[he],me[he]=null,he--)}function V(e,t){he++,me[he]=e.current,e.current=t}var _e=ge(null),ve=ge(null),ye=ge(null),be=ge(null);function xe(e,t){switch(V(ye,t),V(ve,e),V(_e,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}}B(_e),V(_e,e)}function Se(){B(_e),B(ve),B(ye)}function Ce(e){var t=e.memoizedState;t!==null&&(ch._currentValue=t.memoizedState,V(be,e)),t=_e.current;var n=fp(t,e.type);t!==n&&(V(ve,e),V(_e,n))}function we(e){ve.current===e&&(B(_e),B(ve)),be.current===e&&(B(be),ch._currentValue=pe)}var Te,Ee;function H(e){if(Te===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);Te=t&&t[1]||``,Ee=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+Te+e+Ee}var De=!1;function Oe(e,t){if(!e||De)return``;De=!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(`
@@ -55,7 +55,7 @@ Load ${e} anyway?`)?(await Xa(e,t,!0),!0):!1}}async function Qa(e,t=!1){return K
55
55
  `),n=n.replace(/\\"/g,`"`)),n=mC(n).trim(),vC(n)}function vC(e){let t=!1;return e.split(`
56
56
  `).map(e=>(/^\s*(```|~~~)/.test(e)&&(t=!t),t?e:e.replace(/^(\s*\d+)\.(\s*)$/,`$1\\.$2`))).join(`
57
57
  `)}function yC(e){return e?new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,year:`numeric`,hour:`numeric`,minute:`2-digit`,second:`2-digit`,hour12:!0}):``}var bC=`Cancelled.`,xC=[`This answer was interrupted when GAIA closed. Send again to retry.`,`This answer was interrupted before it finished. Send again to retry.`,`This answer ended before GAIA could save a reply. Send again to retry.`];function SC(e,t){if(t)return`stopped`;let n=e.trim();return xC.some(e=>n.endsWith(e))?`interrupted`:void 0}function CC({message:e,isStreaming:t,agentSteps:n,agentStepsActive:r,cards:i,onDelete:a,onResend:o,extraActions:s,latencyMs:c,liveStatus:l,awaitingUser:u}){let d=J();rc();let f=(0,W.useMemo)(()=>e.role===`assistant`&&!t&&n?aC(n,e.content):{steps:n,echoed:!1},[n,e.content,e.role,t]),p=e.role===`assistant`&&(f.echoed||rC(e.content)),h=e.role===`assistant`?e.stopState??(e.content.trim()===bC?`stopped`:void 0):void 0,g=(0,W.useMemo)(()=>e.role===`user`?e.content:_C(e.content,!!t),[e.content,e.role,t]),[v,y]=(0,W.useState)(!1),[x,S]=(0,W.useState)(!1),C=e.role===`user`&&ab(e.content),[w,T]=(0,W.useState)(!1),E=(0,W.useId)(),D=(0,W.useRef)(null),O=(0,W.useRef)(!1),ee=(0,W.useCallback)(()=>{w&&(O.current=!0),T(!w)},[w]);(0,W.useEffect)(()=>{!w&&O.current&&(O.current=!1,D.current?.scrollIntoView?.({block:`nearest`}))},[w]);let k=(0,W.useRef)(null),A=(0,W.useRef)(null);(0,W.useEffect)(()=>()=>{k.current&&clearTimeout(k.current),A.current&&clearTimeout(A.current)},[]);let j=(0,W.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)}y(!0),k.current&&clearTimeout(k.current),k.current=setTimeout(()=>y(!1),2e3)},[e.content]),M=(0,W.useCallback)(()=>{x?(S(!1),A.current&&clearTimeout(A.current),a?.(e.id)):(S(!0),A.current&&clearTimeout(A.current),A.current=setTimeout(()=>S(!1),3e3))},[x,e.id,a]),te=(0,W.useCallback)(()=>{o?.(e)},[e,o]),N=e.created_at?d(e.role===`user`?`msg.sent`:`msg.replied`,{time:yC(e.created_at)}):void 0;return b(`div`,{className:`msg msg-${e.role} ${p?`msg-error`:``}`,title:N,children:m(`div`,{className:`msg-inner`,children:[m(`div`,{className:`msg-header`,children:[b(`div`,{className:`msg-header-left`}),!t&&m(`div`,{className:`msg-actions`,children:[e.role===`user`&&o&&b(`button`,{className:`msg-action-btn`,onClick:te,title:d(`msg.resend`),"aria-label":d(`msg.resend`),children:b(Sn,{size:12})}),s,b(`button`,{className:`msg-copy ${v?`copied`:``}`,onClick:j,title:d(v?`msg.copied`:`msg.copy`),"aria-label":d(v?`msg.copiedAria`:`msg.copy`),children:b(v?he:Ie,{size:12})}),a&&b(`button`,{className:`msg-action-btn msg-delete ${x?`confirm`:``}`,onClick:M,title:d(x?`msg.confirmDelete`:`msg.delete`),"aria-label":d(x?`msg.confirmDeleteAria`:`msg.delete`),children:b(Xn,{size:12})})]})]}),m(`div`,{className:`msg-body`,children:[e.role===`assistant`&&(f.steps&&f.steps.length>0||t)&&b(Ub,{steps:f.steps??[],isActive:r??!1,running:!!t,awaitingUser:u,answer:t?void 0:g,liveLine:t&&b(eC,{active:!!r||!g,label:l,awaitingUser:u})}),p&&m(`div`,{className:`error-banner`,children:[b(Qn,{size:14}),b(`span`,{children:d(`msg.error`)})]}),(e.cards??i)?.map((e,t)=>b(eS,{render:e.render,data:e.data},t)),C?m(_.Fragment,{children:[b(`div`,{ref:D,id:E,className:`msg-collapsible${w?``:` is-collapsed`}`,children:b(VC,{content:g})}),b(sb,{expanded:w,onToggle:ee,controls:E,collapsedLabel:d.hint(d(`msg.showAll`),ob(e.content)),expandedLabel:d(`msg.showLess`),className:`msg-expand-toggle`})]}):!(h&&g.trim()===bC)&&b(VC,{content:g,showCursor:t&&!!g&&!r,isStreaming:t}),h&&m(`div`,{className:`msg-stopped${h===`unconfirmed`||e.stopError?` is-unconfirmed`:``}`,role:`note`,children:[b(Kn,{size:9,fill:`currentColor`,"aria-hidden":`true`}),b(`span`,{children:h===`unconfirmed`?d(`msg.stoppedUnconfirmed`):e.stopError?d(`msg.stoppedError`,{error:e.stopError}):d(`msg.stopped`)})]}),e.role===`assistant`&&!t&&dx(g)&&b(hx,{content:g}),e.role===`assistant`&&!t&&(e.stats||c!=null||e.created_at)&&m(`div`,{className:`msg-stats`,"aria-label":d(`msg.about`),children:[e.created_at&&b(`span`,{className:`msg-stats-ts`,title:d(`msg.timestamp`),children:yC(e.created_at)}),e.stats?.retried&&e.stats.model&&b(`span`,{title:`This answer was kept from Retry with… (${e.stats.model})`,children:ac(e.stats.model)}),b(aS,{latencyMs:c,stats:e.stats,ended:SC(e.content,h)})]}),e.role===`assistant`&&!t&&e.id>0&&e.session_id&&b(BS,{sessionId:e.session_id,messageId:e.id})]})]})})}var wC=(0,W.createContext)(!1);function TC({lang:e,code:t}){let n=J(),[r,i]=(0,W.useState)(!1),[a,o]=(0,W.useState)(!1),s=(0,W.useContext)(wC),c=(0,W.useId)(),l=ib(t),u=l>(s?20:25),d=u&&!a,f=(0,W.useRef)(null);(0,W.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]);let p=(0,W.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 m(`div`,{className:`code-block${d?` is-collapsed`:``}`,dir:`ltr`,children:[m(`div`,{className:`code-header`,children:[b(`span`,{className:`code-lang`,children:e||`code`}),m(`button`,{className:`code-copy ${r?`copied`:``}`,onClick:p,title:n(r?`msg.copied`:`code.copy`),"aria-label":n(r?`msg.copiedAria`:`code.copyAria`),children:[b(r?he:Ie,{size:13}),b(`span`,{children:n(r?`code.copied`:`code.copy`)})]})]}),b(`pre`,{id:c,children:b(`code`,{children:t})}),u&&b(sb,{expanded:a,onToggle:()=>o(e=>!e),controls:c,collapsedLabel:`Expand (${l.toLocaleString(`en-US`)} lines)`,expandedLabel:`Collapse`,className:`code-expand-toggle`})]})}var EC=/\b[A-Z]:[\\/][^\s*?"<>|,;)}\]\\/]+(?:[\\/][^\s*?"<>|,;)}\]\\/]+)*[\\/]?/gi,DC=/[.:!']+$/,OC=RegExp(`^(?:${EC.source})$`,`i`);function kC(e){if(typeof e!=`string`)return null;let t=e.trim();return OC.test(t)?t:null}function AC({path:e}){let t=t=>{t.preventDefault(),fs(e).catch(e=>{i.ui.error(`Failed to open path`,e)})};return m(`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:[b(ut,{size:12,className:`file-path-icon`}),e]})}function jC(e){let t=new RegExp(EC.source,`gi`),n=[],r=0,i;for(;(i=t.exec(e))!==null;){i.index>r&&n.push(e.slice(r,i.index));let t=i[0].replace(DC,``);n.push(b(AC,{path:t},i.index)),r=i.index+t.length}return n.length===0?e:(r<e.length&&n.push(e.slice(r)),b(_.Fragment,{children:n}))}var MC=(0,W.createContext)(GS([]));function NC({doc:e,page:t,t:n}){return m(`a`,{className:`citation-link`,href:as(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:[b(ot,{size:12,className:`citation-icon`,"aria-hidden":`true`}),e.filename]})}function PC({doc:e,page:t,label:n,t:r}){return b(`a`,{className:`citation-page`,href:as(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 FC(e,t){let n=qS(e,t)[0];return $S(n?t.slice(0,n.start):t)}function IC(e,t,n,r){let i=qS(t,e),a=[],o=(t,r,i)=>{for(let o of r){let r=i+o.start,s=i+o.end;a.push({start:r,end:s,node:b(PC,{doc:t,page:o.page,label:e.slice(r,s),t:n},`p${r}`)})}};if(r&&o(r,$S(e.slice(0,i[0]?.start??e.length)),0),i.forEach((t,r)=>{let s=$S(e.slice(t.end,i[r+1]?.start??e.length));a.push({start:t.start,end:t.end,node:b(NC,{doc:t.doc,page:s[0]?.page,t:n},`c${t.start}`)}),o(t.doc,s,t.end)}),a.length===0)return jC(e);a.sort((e,t)=>e.start-t.start);let s=[],c=0;for(let t of a)t.start>c&&s.push(b(W.Fragment,{children:jC(e.slice(c,t.start))},`t${c}`)),s.push(t.node),c=t.end;return c<e.length&&s.push(b(W.Fragment,{children:jC(e.slice(c))},`t${c}`)),b(_.Fragment,{children:s})}function LC(e,t){return typeof t==`string`?KS(e,t):null}function RC({children:e}){let t=(0,W.useContext)(MC),n=J(),r=W.Children.toArray(e),i=null,a=r.map((e,a)=>{if(typeof e==`string`){let r=IC(e,t,n,i);return i=null,b(W.Fragment,{children:r},`s${a}`)}if(i=null,W.isValidElement(e)&&e.type===zC){let o=LC(t,e.props.children);if(o){let e=r[a+1],s=typeof e==`string`?FC(t,e):[];return i=o,b(NC,{doc:o,page:s[0]?.page,t:n},`k${a}`)}}return e});return b(_.Fragment,{children:a})}function zC({className:e,children:t,node:n,...r}){let i=(0,W.useContext)(MC),a=J(),o=LC(i,t);if(o)return b(NC,{doc:o,t:a});let s=kC(t);return s?b(AC,{path:s}):b(`code`,{className:`inline-code`,dir:`ltr`,...r,children:t})}var BC={code:zC,pre({children:e}){let t=W.Children.toArray(e)[0];if(W.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 b(TC,{lang:a,code:i})}return b(`pre`,{dir:`ltr`,children:e})},table({children:e}){return b(`div`,{className:`md-table-wrap`,children:b(`table`,{className:`md-table`,dir:`auto`,children:e})})},a({href:e,children:t}){return b(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`md-link`,children:t})},p({children:e}){return b(`p`,{className:`md-p`,dir:`auto`,children:b(RC,{children:e})})},h1({children:e}){return b(`h2`,{className:`md-h2`,dir:`auto`,children:b(RC,{children:e})})},h2({children:e}){return b(`h3`,{className:`md-h3`,dir:`auto`,children:b(RC,{children:e})})},h3({children:e}){return b(`h4`,{className:`md-h4`,dir:`auto`,children:b(RC,{children:e})})},h4({children:e}){return b(`h5`,{className:`md-h4`,dir:`auto`,children:b(RC,{children:e})})},ul({children:e}){return b(`ul`,{className:`md-ul`,dir:`auto`,children:e})},ol({children:e,start:t}){return b(`ol`,{className:`md-ol`,start:t,dir:`auto`,children:e})},li({children:e}){return b(`li`,{className:`md-li`,dir:`auto`,children:b(RC,{children:e})})},blockquote({children:e}){return b(`blockquote`,{className:`md-blockquote`,dir:`auto`,children:b(RC,{children:e})})},hr(){return b(`hr`,{className:`md-hr`})},td({children:e}){return b(`td`,{dir:`auto`,children:b(RC,{children:e})})},th({children:e}){return b(`th`,{dir:`auto`,children:b(RC,{children:e})})}};function VC({content:e,showCursor:t,isStreaming:n=!1}){let r=G(e=>e.documents),i=(0,W.useMemo)(()=>GS(r),[r]);return!e&&!t?null:!e&&t?b(`span`,{className:`cursor`}):b(wC.Provider,{value:n,children:b(MC.Provider,{value:i,children:m(`div`,{className:`md-content`,children:[b(Ig,{remarkPlugins:[Uy,Jy,Xy],disallowedElements:[...Vg],urlTransform:Ug,components:BC,children:e}),t&&b(`span`,{className:`cursor`})]})})})}function HC(e){return e.type===`status`&&e.status===`working`&&!e.phase&&(e.message??``).startsWith(`Model is processing`)}function UC(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`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 WC=/\s*\{\s*"?(?:tool|thought|goal)"?\s*:\s*"[^"]*"[^}]*(?:"?tool_args"?\s*:\s*\{[^}]*\})?\s*\}/g;function GC(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,`
58
- `).replace(/\\\\/g,`\\`)}function KC(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 qC(e){return(e||[]).map(e=>({...e,agentSteps:e.agentSteps||e.agent_steps||void 0,stats:e.stats||e.inference_stats||void 0,turnSummary:e.turnSummary||e.turn_summary||void 0}))}function JC(e){return`policy-receipt-${encodeURIComponent(e)}`}var YC=1e3,XC=15e3,ZC=null,QC=null,$C=YC,ew=0,tw=null;function nw(){if(ZC)return ZC;let e=Date.now();return ZC=Ca().then(t=>G.getState().setActiveRuns(t,e)).catch(e=>i.api.warn(`Could not read which chats are running`,e)).finally(()=>{ZC=null}),ZC}function rw(){let e=G.getState();return e.isStreaming||e.runningSessionIds.length>0}function iw(){return rw()?($C=YC,YC):($C=Math.min($C*2,XC),$C)}function aw(e){nw().then(()=>{e===ew&&(QC=setTimeout(()=>aw(e),iw()))})}function ow(){tw&&(QC&&clearTimeout(QC),QC=null,$C=YC,aw(++ew))}function sw(){tw?.();let e=G.subscribe((e,t)=>{e.isStreaming&&!t.isStreaming&&ow()}),t=()=>ow();window.addEventListener(`focus`,t);let n=()=>{ew++,QC&&clearTimeout(QC),QC=null,e(),window.removeEventListener(`focus`,t),tw===n&&(tw=null)};return tw=n,$C=YC,aw(++ew),n}var cw=[0,3e3,1e4],lw=`The answer to your last message was lost: its run stopped before it finished, most often because GAIA restarted. Send the message again.`;function uw(e){return e.name===`StreamStalledError`||e.name===`StreamDroppedError`}function dw(e){if(uw(e))return`Lost the live view of this answer: the connection to GAIA dropped 4 times. The answer may still finish. Reopen this chat in a minute to see it.`;if(e instanceof Yo)return e.endpoint===`send`?`GAIA did not start this answer within ${Math.round(e.timeoutMs/1e3)} seconds; it may be busy or stuck. If the chat list shows this chat running, reopen it later to see the answer. Otherwise, send the message again.`:`GAIA did not respond when this chat reconnected to its running answer. The answer may still finish: check that GAIA is still running, then reopen this chat.`;if(e instanceof Ia){let t=e.detail?Ma(e.detail):``;return e.httpStatus===429?`GAIA is busy with another chat, so this message was not sent. Send it again when that chat finishes.`:e.httpStatus===409?t||`This chat is already answering a message. Wait for it to finish, or press Stop.`:`GAIA could not take this message (HTTP ${e.httpStatus})${t?`: ${t}`:`.`}`}return null}var fw=3e3,pw=new Set,mw=new Map,hw=new Set,gw=null;function _w(e,t=Date.now()){mw.set(e,t)}function vw(e){let t=G.getState();return t.activeRunsAt>0&&t.activeRunsAt>=(mw.get(e)??0)&&!t.runningSessionIds.includes(e)&&!t.queuedSessionIds.includes(e)}function yw(e){return hw.add(e),()=>{hw.delete(e),gw?.()}}function bw(e){return e instanceof Error?dw(e)??(e.message||`Unknown error`):String(e)}function xw(e){let t=e?.httpStatus;return typeof t==`number`?t:void 0}function Sw(e){let t=xw(e);return t===409||t===429}function Cw(e){G.getState().setQueueHold(e,!0),setTimeout(()=>G.getState().setQueueHold(e,!1),fw)}function ww(e,t,n){return xw(n)===409&&(i.chat.info(`Chat ${e} was busy; queueing the message to try again`),G.getState().updateQueue(e,e=>Xr(e,t,`queued`)),Cw(e),!0)}async function Tw(e,t,n){let r=G.getState;if(pw.has(e)||r().queueHolds[e])return;let a=r().messageQueues[e]??[];if(a.some(e=>e.state===`sending`))return;let o=ai(a);if(o||li(a)){pw.add(e);try{if(o){let t;try{t=await va(e)}catch(t){if(xw(t)===409){i.chat.info(`Chat ${e} is answering again; its queue waits for that turn to end`);return}i.chat.error(`Could not learn what chat ${e}'s last reply did with the messages added to it`,t),r().updateQueue(e,e=>ci(e,`GAIA could not say whether it read this message: ${bw(t)}`));return}r().updateQueue(e,e=>si(e,t))}let a=li(r().messageQueues[e]??[]);if(!a||!n())return;r().updateQueue(e,e=>Zr(e,a.id,`queued`,`starting`));let s;try{s=await t(e,a.text)}catch(e){s={kind:`failed`,error:bw(e)}}if(s.kind===`accepted`){_w(e),r().updateQueue(e,e=>ei(e,a.id)),ow();return}if(s.kind===`busy`){i.chat.info(`Queued message found chat ${e} busy; holding it`),r().updateQueue(e,e=>ti(e,a.id)),Cw(e);return}i.chat.error(`Queued message for chat ${e} was not sent: ${s.error}`),r().updateQueue(e,e=>ti(e,a.id,s.error))}finally{pw.delete(e)}}}function Ew(e){return e.type!==`status`||e.phase!==`waiting`}var Dw=(e,t)=>new Promise(n=>{let r=!1,a=null,o=!1,s=e=>{r||(r=!0,e.kind===`accepted`&&(a?a.abort():o=!0),n(e))},c=()=>s({kind:`accepted`});i.chat.info(`Sending queued message for chat ${e} in the background`),a=Bo(e,t,{onChunk:c,onAgentEvent:e=>{Ew(e)&&c()},onDone:c,onError:e=>{uw(e)?c():Sw(e)?s({kind:`busy`}):s({kind:`failed`,error:bw(e)})}}),o&&a.abort()});function Ow(e=Dw){let t=()=>{let t=G.getState();if(t.systemStatus?.init_state!==`initializing`)for(let n of Object.keys(t.messageQueues))!hw.has(n)&&vw(n)&&Tw(n,e,()=>!hw.has(n))},n=G.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 gw=t,t(),()=>{n(),gw===t&&(gw=null)}}var kw=`https://github.com/amd/gaia/issues/new`,Aw=[{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:new Set([`.mp4`,`.avi`,`.mkv`,`.mov`,`.wmv`,`.flv`,`.webm`,`.m4v`]),message:`Video files are not supported for indexing.`,alternatives:[`Extract subtitles or transcripts from videos and index those`,`Use GAIA's voice/talk mode for audio: gaia talk`],featureTitle:`Support video file indexing`},{label:`Audio`,extensions:new Set([`.mp3`,`.wav`,`.flac`,`.aac`,`.ogg`,`.wma`,`.m4a`,`.opus`]),message:`Audio files are not supported for indexing.`,alternatives:[`Use GAIA's voice mode for speech interaction: gaia talk`,`Transcribe audio to text first, then index the transcript`],featureTitle:`Support audio file transcription and indexing`},{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 jw(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;for(let e of Aw)if(e.extensions.has(t))return e;return null}var Mw=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 Nw(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;return Mw.has(t)}function Pw(){let e=navigator.userAgent;return`**Environment:**\n- GAIA Version: 0.25.4rc2\n- Platform: ${navigator.platform||`unknown`}\n- User Agent: ${e}\n- Interface: Agent UI (Web)`}function Fw(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?_`,``,`---`,Pw(),``,`_Submitted from GAIA Agent UI_`].join(`
58
+ `).replace(/\\\\/g,`\\`)}function KC(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 qC(e){return(e||[]).map(e=>({...e,agentSteps:e.agentSteps||e.agent_steps||void 0,stats:e.stats||e.inference_stats||void 0,turnSummary:e.turnSummary||e.turn_summary||void 0}))}function JC(e){return`policy-receipt-${encodeURIComponent(e)}`}var YC=1e3,XC=15e3,ZC=null,QC=null,$C=YC,ew=0,tw=null;function nw(){if(ZC)return ZC;let e=Date.now();return ZC=Ca().then(t=>G.getState().setActiveRuns(t,e)).catch(e=>i.api.warn(`Could not read which chats are running`,e)).finally(()=>{ZC=null}),ZC}function rw(){let e=G.getState();return e.isStreaming||e.runningSessionIds.length>0}function iw(){return rw()?($C=YC,YC):($C=Math.min($C*2,XC),$C)}function aw(e){nw().then(()=>{e===ew&&(QC=setTimeout(()=>aw(e),iw()))})}function ow(){tw&&(QC&&clearTimeout(QC),QC=null,$C=YC,aw(++ew))}function sw(){tw?.();let e=G.subscribe((e,t)=>{e.isStreaming&&!t.isStreaming&&ow()}),t=()=>ow();window.addEventListener(`focus`,t);let n=()=>{ew++,QC&&clearTimeout(QC),QC=null,e(),window.removeEventListener(`focus`,t),tw===n&&(tw=null)};return tw=n,$C=YC,aw(++ew),n}var cw=[0,3e3,1e4],lw=`The answer to your last message was lost: its run stopped before it finished, most often because GAIA restarted. Send the message again.`;function uw(e){return e.name===`StreamStalledError`||e.name===`StreamDroppedError`}function dw(e){if(uw(e))return`Lost the live view of this answer: the connection to GAIA dropped 4 times. The answer may still finish. Reopen this chat in a minute to see it.`;if(e instanceof Yo)return e.endpoint===`send`?`GAIA did not start this answer within ${Math.round(e.timeoutMs/1e3)} seconds; it may be busy or stuck. If the chat list shows this chat running, reopen it later to see the answer. Otherwise, send the message again.`:`GAIA did not respond when this chat reconnected to its running answer. The answer may still finish: check that GAIA is still running, then reopen this chat.`;if(e instanceof Ia){let t=e.detail?Ma(e.detail):``;return e.httpStatus===429?`GAIA is busy with another chat, so this message was not sent. Send it again when that chat finishes.`:e.httpStatus===409?t||`This chat is already answering a message. Wait for it to finish, or press Stop.`:`GAIA could not take this message (HTTP ${e.httpStatus})${t?`: ${t}`:`.`}`}return null}var fw=3e3,pw=new Set,mw=new Map,hw=new Set,gw=null;function _w(e,t=Date.now()){mw.set(e,t)}function vw(e){let t=G.getState();return t.activeRunsAt>0&&t.activeRunsAt>=(mw.get(e)??0)&&!t.runningSessionIds.includes(e)&&!t.queuedSessionIds.includes(e)}function yw(e){return hw.add(e),()=>{hw.delete(e),gw?.()}}function bw(e){return e instanceof Error?dw(e)??(e.message||`Unknown error`):String(e)}function xw(e){let t=e?.httpStatus;return typeof t==`number`?t:void 0}function Sw(e){let t=xw(e);return t===409||t===429}function Cw(e){G.getState().setQueueHold(e,!0),setTimeout(()=>G.getState().setQueueHold(e,!1),fw)}function ww(e,t,n){return xw(n)===409&&(i.chat.info(`Chat ${e} was busy; queueing the message to try again`),G.getState().updateQueue(e,e=>Xr(e,t,`queued`)),Cw(e),!0)}async function Tw(e,t,n){let r=G.getState;if(pw.has(e)||r().queueHolds[e])return;let a=r().messageQueues[e]??[];if(a.some(e=>e.state===`sending`))return;let o=ai(a);if(o||li(a)){pw.add(e);try{if(o){let t;try{t=await va(e)}catch(t){if(xw(t)===409){i.chat.info(`Chat ${e} is answering again; its queue waits for that turn to end`);return}i.chat.error(`Could not learn what chat ${e}'s last reply did with the messages added to it`,t),r().updateQueue(e,e=>ci(e,`GAIA could not say whether it read this message: ${bw(t)}`));return}r().updateQueue(e,e=>si(e,t))}let a=li(r().messageQueues[e]??[]);if(!a||!n())return;r().updateQueue(e,e=>Zr(e,a.id,`queued`,`starting`));let s;try{s=await t(e,a.text)}catch(e){s={kind:`failed`,error:bw(e)}}if(s.kind===`accepted`){_w(e),r().updateQueue(e,e=>ei(e,a.id)),ow();return}if(s.kind===`busy`){i.chat.info(`Queued message found chat ${e} busy; holding it`),r().updateQueue(e,e=>ti(e,a.id)),Cw(e);return}i.chat.error(`Queued message for chat ${e} was not sent: ${s.error}`),r().updateQueue(e,e=>ti(e,a.id,s.error))}finally{pw.delete(e)}}}function Ew(e){return e.type!==`status`||e.phase!==`waiting`}var Dw=(e,t)=>new Promise(n=>{let r=!1,a=null,o=!1,s=e=>{r||(r=!0,e.kind===`accepted`&&(a?a.abort():o=!0),n(e))},c=()=>s({kind:`accepted`});i.chat.info(`Sending queued message for chat ${e} in the background`),a=Bo(e,t,{onChunk:c,onAgentEvent:e=>{Ew(e)&&c()},onDone:c,onError:e=>{uw(e)?c():Sw(e)?s({kind:`busy`}):s({kind:`failed`,error:bw(e)})}}),o&&a.abort()});function Ow(e=Dw){let t=()=>{let t=G.getState();if(t.systemStatus?.init_state!==`initializing`)for(let n of Object.keys(t.messageQueues))!hw.has(n)&&vw(n)&&Tw(n,e,()=>!hw.has(n))},n=G.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 gw=t,t(),()=>{n(),gw===t&&(gw=null)}}var kw=`https://github.com/amd/gaia/issues/new`,Aw=[{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:new Set([`.mp4`,`.avi`,`.mkv`,`.mov`,`.wmv`,`.flv`,`.webm`,`.m4v`]),message:`Video files are not supported for indexing.`,alternatives:[`Extract subtitles or transcripts from videos and index those`,`Use GAIA's voice/talk mode for audio: gaia talk`],featureTitle:`Support video file indexing`},{label:`Audio`,extensions:new Set([`.mp3`,`.wav`,`.flac`,`.aac`,`.ogg`,`.wma`,`.m4a`,`.opus`]),message:`Audio files are not supported for indexing.`,alternatives:[`Use GAIA's voice mode for speech interaction: gaia talk`,`Transcribe audio to text first, then index the transcript`],featureTitle:`Support audio file transcription and indexing`},{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 jw(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;for(let e of Aw)if(e.extensions.has(t))return e;return null}var Mw=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 Nw(e){let t=e.toLowerCase().startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`;return Mw.has(t)}function Pw(){let e=navigator.userAgent;return`**Environment:**\n- GAIA Version: 0.25.4rc3\n- Platform: ${navigator.platform||`unknown`}\n- User Agent: ${e}\n- Interface: Agent UI (Web)`}function Fw(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?_`,``,`---`,Pw(),``,`_Submitted from GAIA Agent UI_`].join(`
59
59
  `);return`${kw}?${new URLSearchParams({title:`[Feature] ${e}`,body:n,labels:`enhancement,agent-ui`}).toString()}`}function Iw(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?_`,``,`---`,Pw(),``,`_Submitted from GAIA Agent UI_`].join(`
60
60
  `);return`${kw}?${new URLSearchParams({title:`[Bug] ${e}`,body:n,labels:`bug,agent-ui`}).toString()}`}var Lw={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 Rw(e,t){return e.startsWith(t)?e.slice(t.length).trim():e}function zw({filename:e,error:t,status:n,kind:r,onDismiss:i,timeout:a=15e3}){let o=(0,W.useRef)(null);(0,W.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?jw(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,h=xe,g=r?Lw[r]:void 0;return g?(d=`"${e}" can't be read`,f=g,p=null,h=Qn):n===404?(d=`"${e}" doesn't exist`,f=Rw(t,`File not found:`),p=null,h=Qn):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,h=Qn):l&&c?(d=`${c.label} files not supported`,f=c.message,p=Fw(c.featureTitle),h=Qn):l&&!s?(d=`"${e}" has no file extension`,f=Rw(t,`File type not allowed:`),p=null,h=Qn):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=Fw(`Support ${s} file indexing`),h=Qn):u?(d=`Connection error`,f=`Could not reach the GAIA server. Make sure the backend is running.`,p=Iw(`Upload connection error for ${e}`),h=xe):(d=`Failed to index "${e}"`,f=t||`An unexpected error occurred during indexing.`,p=Iw(`Indexing error: ${t.slice(0,80)}`),h=de),m(`div`,{className:`upload-error-toast`,role:`alert`,children:[b(h,{size:16}),m(`div`,{className:`upload-error-content`,children:[b(`div`,{className:`upload-error-title`,children:d}),m(`div`,{className:`upload-error-detail`,children:[f,p&&` `,p===null?null:l?b(`a`,{href:p,target:`_blank`,rel:`noopener noreferrer`,children:`Request this feature →`}):b(`a`,{href:p,target:`_blank`,rel:`noopener noreferrer`,children:`Report this issue →`})]})]}),b(`button`,{className:`upload-error-dismiss`,onClick:i,"aria-label":`Dismiss`,children:b(cr,{size:14})})]})}function Bw(e,t){let n=e=>t.some(t=>t.id===e&&t.configured),r=fx(e);return r===`google`?n(`google`):r===`microsoft`?n(`microsoft`):r===`microsoft_work`?n(`microsoft_work`):n(`google`)||n(`microsoft`)||n(`microsoft_work`)}function Vw(e,t){let n=e=>t.some(t=>t.id===e&&t.configured),r=fx(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 Hw=4e3;function Uw({content:e,onRetry:t}){let[n,r]=(0,W.useState)([]),[a,o]=(0,W.useState)(!1),s=(0,W.useCallback)(()=>{ta().then(e=>r(e.connectors||[])).catch(e=>i.ui.warn(`ConnectorRetryBanner: connector fetch failed`,e))},[]),c=Bw(e,n);if((0,W.useEffect)(()=>{s();let e=()=>s();return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[s]),(0,W.useEffect)(()=>{if(c)return;let e=setInterval(s,Hw);return()=>clearInterval(e)},[c,s]),!c||a)return null;let l=Vw(e,n);return m(`div`,{className:`connector-retry-banner`,role:`status`,children:[b(Te,{size:14,className:`connector-retry-banner__icon`}),m(`span`,{className:`connector-retry-banner__text`,children:[l,` connected since this reply — ask again to run it now.`]}),m(`button`,{type:`button`,className:`connector-retry-banner__btn`,onClick:()=>{o(!0),t()},children:[b(Sn,{size:12}),b(`span`,{children:`Ask again`})]}),b(`button`,{type:`button`,className:`connector-retry-banner__dismiss`,onClick:()=>o(!0),"aria-label":`Dismiss`,children:`×`})]})}var Ww=240,Gw=1e5;function Kw({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 h=J(),g=(0,W.useRef)(null),_=d??g,v=(0,W.useRef)(null),y=!!s,x=e.trim().length>0||c.hasUploaded,S=c.compose(e.trim()).length,C=S>Gw,w=!y&&(!i||o)&&!c.uploading&&x&&!C,T=s||l||h(`composer.placeholder`);(0,W.useLayoutEffect)(()=>{let e=_.current;if(!e)return;let t=()=>{e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,Ww)}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,T,_]);let E=(0,W.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),w&&n())},[w,n]),D=(0,W.useCallback)(e=>{e.dataTransfer?.files?.length&&(e.preventDefault(),e.stopPropagation(),c.addFiles(Array.from(e.dataTransfer.files)))},[c]);return m(`div`,{className:`composer${y?` composer-disabled`:``}`,onDrop:D,onDragOver:e=>{e.dataTransfer?.types?.includes(`Files`)&&e.preventDefault()},children:[c.attachments.length>0&&b(`ul`,{className:`composer-attachments`,"aria-label":h(`composer.attached`),children:c.attachments.map(e=>m(`li`,{className:`composer-attachment${e.error?` has-error`:``}`,children:[e.isImage&&e.url?b(`img`,{src:e.url,alt:``,className:`composer-attachment-thumb`}):b(ot,{size:14,"aria-hidden":`true`}),b(`span`,{className:`composer-attachment-name`,title:e.name,dir:`auto`,children:e.name}),e.uploading&&b(`span`,{className:`composer-attachment-state`,children:h(`composer.uploading`)}),e.error&&b(`span`,{className:`composer-attachment-state`,role:`alert`,title:e.error,children:e.error}),b(`button`,{type:`button`,className:`composer-icon-btn`,onClick:()=>c.remove(e.id),"aria-label":h(`composer.remove`,{name:e.name}),children:b(cr,{size:12})})]},e.id))}),b(`textarea`,{ref:_,className:`composer-input`,value:e,onChange:e=>t(e.target.value),onKeyDown:E,onPaste:e=>{c.handlePaste(e)},placeholder:T,rows:1,disabled:y,autoFocus:u,"aria-label":h(`composer.message`),dir:`auto`}),C&&m(`p`,{className:`composer-limit-error`,role:`alert`,children:[h(`composer.tooLong`,{sent:S.toLocaleString(),max:1e5.toLocaleString()}),` `,h(`composer.tooLongHint`)]}),m(`div`,{className:`composer-row`,children:[m(`div`,{className:`composer-row-left`,children:[b(`button`,{type:`button`,className:`composer-icon-btn`,onClick:()=>v.current?.click(),disabled:y,"aria-label":h(`composer.attach`),title:h(`composer.attach`),children:b(bn,{size:16})}),b(`input`,{ref:v,type:`file`,multiple:!0,hidden:!0,onChange:e=>{e.target.files&&c.addFiles(Array.from(e.target.files)),e.target.value=``}}),f]}),m(`div`,{className:`composer-row-right`,children:[p,i&&o&&x&&b(`button`,{type:`button`,className:`composer-send`,onClick:n,disabled:!w,"aria-label":h(`composer.queue`),title:h(`composer.queueTitle`),children:b(I,{size:16})}),i?b(`button`,{type:`button`,className:`composer-send is-stop`,onClick:r,disabled:a,"aria-label":h(`composer.stop`),title:a?h(`composer.stopping`):h.hint(h(`composer.stop`),`Esc`),children:b(Kn,{size:12,fill:`currentColor`})}):b(`button`,{type:`button`,className:`composer-send`,onClick:n,disabled:!w,"aria-label":h(`composer.send`),title:h.hint(h(`composer.send`),`Enter`),children:b(I,{size:16})})]})]})]})}var qw=8,Jw=8;function Yw({label:e,warning:t,children:n,id:r,pinned:i=!1,onUnpin:a,tabIndex:o}){let s=(0,W.useId)(),c=r??s,l=(0,W.useRef)(null),u=(0,W.useRef)(null),[d,f]=(0,W.useState)(!1),p=d||i,[h,g]=(0,W.useState)(null);return(0,W.useLayoutEffect)(()=>{if(!p){g(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+qw+t.width<=r-Jw?(a=n.right+qw,o=e.top+e.height/2-t.height/2):n.left-qw-t.width>=Jw?(a=n.left-qw-t.width,o=e.top+e.height/2-t.height/2):(a=Math.min(Math.max(Jw,e.right-t.width),r-Jw-t.width),o=e.top-qw-t.height>=Jw?e.top-qw-t.height:e.bottom+qw),o=Math.min(Math.max(Jw,o),i-Jw-t.height),g({left:a,top:o})},[p]),(0,W.useEffect)(()=>{if(!p)return;let e=()=>{f(!1),a?.()};return window.addEventListener(`scroll`,e,!0),()=>window.removeEventListener(`scroll`,e,!0)},[p,a]),m(_.Fragment,{children:[b(`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:b(Mt,{size:13,"aria-hidden":`true`})}),p&&(0,OS.createPortal)(b(`div`,{ref:u,id:c,role:`tooltip`,className:`info-bubble`,style:h?{left:h.left,top:h.top}:{left:0,top:0,visibility:`hidden`},children:n}),document.body)]})}function Xw(e){return e<.1?`$${e.toFixed(3)}`:`$${e.toFixed(2)}`}function Zw(e){return e?`${Xw(e.input_per_million)} in · ${Xw(e.output_per_million)} out per 1M tokens`:`price unknown`}function Qw(e){return`$${e.toFixed(2)}`}var $w=2e3,eT=`waiting_for_os_permission`,tT=5;function nT(e,t){let n=e.rank?`#${e.rank} ${e.note??``}`.trim():null;return t?[n,Zw(e.price)].filter(e=>!!e):[gc(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 rT({m:e,onDownload:t,busy:n}){if(yc(e)){let t=Math.round(e.download_progress?.percent??0);return m(`span`,{className:`model-state is-downloading`,title:`Downloading, ${t}%`,children:[b(U,{size:12,className:`spin`,"aria-hidden":`true`}),` `,t,`%`]})}let r=vc(e);return r===`not_downloaded`?b(`button`,{type:`button`,className:`model-state-btn`,onClick:e=>{e.stopPropagation(),t()},disabled:n,"aria-label":`Download ${e.display_name??e.id}`,title:hc.not_downloaded,tabIndex:-1,children:b(We,{size:13,"aria-hidden":`true`})}):r===`loaded`?b(`span`,{className:`model-state is-loaded`,role:`img`,"aria-label":hc.loaded,title:hc.loaded}):b(`span`,{className:`model-state is-ready`,title:hc.downloaded,children:`Ready`})}function iT(){let e=nc(e=>e.active),t=nc(e=>e.select),n=nc(e=>e.queued),r=nc(e=>e.queue),i=nc(e=>e.queueError),a=nc(e=>e.rememberNames);nc(e=>e.names);let o=lc(),s=G(t=>uc(e,t.sessions,t.currentSessionId)),c=G(e=>e.isStreaming),l=G(e=>e.openSettings),u=(0,W.useRef)(null),[d,f]=(0,W.useState)(!1),[p,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(0),[v,y]=(0,W.useState)(null),[x,S]=(0,W.useState)(null),[C,w]=(0,W.useState)(null),[T,E]=(0,W.useState)(null),[D,O]=(0,W.useState)(null),[ee,k]=(0,W.useState)(0),[A,j]=(0,W.useState)(null),M=(0,W.useRef)(0),te=(0,W.useRef)(null),N=(0,W.useId)(),ne=(0,W.useRef)(null),[re,ie]=(0,W.useState)(null),[P,F]=(0,W.useState)(null),I=(0,W.useCallback)(()=>F(null),[]),ae=(0,W.useCallback)(()=>f(!1),[]),oe=(0,W.useRef)(!1),L=(0,W.useCallback)(async(e=!1)=>{e||(oe.current=!1,y(null),h(null));try{let{providers:t,lemonade_error:n}=await ao();if(n)throw Error(n);let r=t.filter(e=>!e.remote||e.models_discovered||e.id===`fireworks`||e.registered),i=await Promise.all(r.map(async e=>{if(e.remote&&!e.models_discovered)return{provider:e,models:[]};try{return{provider:e,models:(await fo(e.id)).models}}catch(t){return{provider:e,models:[],error:t instanceof Error?t.message:String(t)}}}));a(i.flatMap(e=>e.models)),_(i.flatMap(e=>e.models).filter(e=>e.available===!1).length),e||(oe.current=!0),h(i.map(e=>({...e,models:e.models.filter(e=>e.available!==!1)})))}catch(e){y(e instanceof Error?e.message:String(e))}},[a]);(0,W.useEffect)(()=>{d&&(S(null),ie(null),F(null),L())},[d,L]),(0,W.useEffect)(()=>{if(!d||!p||!oe.current)return;let e=ne.current?.querySelector(`[role="option"][tabindex="0"]`);e&&(oe.current=!1,e.focus(),e.scrollIntoView?.({block:`nearest`}))},[d,p]);let se=e=>{if(e.altKey||e.ctrlKey||e.metaKey)return;let t=Array.from(ne.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(),F(t=>e.key===`i`&&t===r?null:r);return}case`ArrowLeft`:e.preventDefault(),F(null);return;default:return}e.preventDefault(),t[r].focus(),t[r].scrollIntoView?.({block:`nearest`})},ce=!!p?.some(e=>e.models.some(yc)),le=!!p?.some(e=>e.provider.key_state===eT);(0,W.useEffect)(()=>{if(!(d||D)||!(ce||D||le))return;let e=setInterval(()=>{L(!0)},$w);return()=>clearInterval(e)},[d,ce,D,le,L]);let ue=(0,W.useCallback)(async e=>{E(e),k(e=>e+1),y(null);try{await Qa(e),await L(!0)}catch(t){O(t=>t?.model===e?null:t),y(t instanceof Error?t.message:String(t))}finally{E(null),k(e=>e-1)}},[L]),de=(0,W.useCallback)(async(n,i)=>{if(i.remote&&!e?.remote&&x?.model!==n)return S({model:n,provider:i}),null;if(S(null),c)return r(n===e?.model?null:n),f(!1),null;w(n),y(null);try{return await t(n),j(null),f(!1),null}catch(e){let t=e instanceof Error?e.message:String(e);return y(t),t}finally{w(null)}},[e?.model,e?.remote,x,r,t,c]);(0,W.useEffect)(()=>{if(!D||!p||ee>0)return;let{model:e,provider:t}=D,n=()=>(te.current!==p&&(te.current=p,M.current+=1),M.current>=tT),r=p.flatMap(e=>e.models).find(t=>t.id===e);if(!r){if(!n())return;O(null),j(`${ac(e)} is no longer in the model list, so it wasn't switched to.`);return}if(yc(r)){M.current=0;return}let i=r.download_progress;if(i?.state===`error`)O(null),j(`Downloading ${ac(e)} failed: ${i.message??`no reason given`}`);else if(i?.state!==`complete`&&vc(r)===`not_downloaded`){if(!n())return;O(null),j(`The download of ${ac(e)} never started. Try the download button again.`)}else O(null),de(e,t).then(t=>{t&&j(`${ac(e)} downloaded, but switching to it failed: ${t}`)})},[p,D,ee,de]);let fe=p?.flatMap(({provider:e,models:t})=>[...e.remote&&!e.models_discovered?[`key:${e.id}`]:[],...t.filter(e=>C===null&&!yc(e)).map(e=>e.id)])??[],R=n??e?.model,z=re&&fe.includes(re)?re:R&&fe.includes(R)?R:fe[0],pe=e=>({role:`option`,tabIndex:e===z?0:-1,"data-row":e,onFocus:()=>ie(e),onBlur:()=>F(null)}),me=o?.remote?Me:o?Be:H,ge=s?ac(s):`Model`,V=`${ge}${o?` · ${o.label}`:``}`,_e=Object.fromEntries((p??[]).map(e=>[e.provider.id,pc(e.models)])),ve=e?.downloaded===!1&&s===e.model,ye=A||i||(n?`${ac(n)} is used from your next message.`:e?.config_error?e.config_error:ve?`${ge} isn't downloaded yet. Open the list to download it.`:o?o.description?.replace(/`/g,``)??(o.remote?`Runs on ${o.label} — chat history leaves this PC`:`Runs on this PC`):cc);return m(`div`,{className:`composer-chip-wrap`,children:[m(`button`,{ref:u,type:`button`,className:`composer-chip${ve||i||A?` is-warning`:``}`,onClick:()=>f(e=>!e),"aria-haspopup":`dialog`,"aria-expanded":d,title:ye,children:[b(me,{size:13,"aria-hidden":`true`}),b(`span`,{className:`composer-chip-label`,dir:`auto`,children:V}),n&&m(`span`,{className:`composer-chip-next`,children:[`→ `,ac(n),` next`]}),ve&&b(We,{size:12,"aria-label":`Not downloaded`}),A&&b(xe,{size:12,"aria-label":`Model switch failed`}),b(B,{size:12,"aria-hidden":`true`})]}),m(ji,{open:d,onClose:ae,anchor:u,label:`Choose a model`,align:`end`,children:[c&&m(`div`,{className:`popover-message`,role:`status`,children:[`This reply keeps `,s?ac(s):`its model`,`. A model you pick here is used from your next message.`]}),A&&b(`div`,{className:`popover-message is-error`,role:`alert`,children:A}),i&&b(`div`,{className:`popover-message is-error`,role:`alert`,children:i}),v&&b(`div`,{className:`popover-message is-error`,role:`alert`,children:v}),!p&&!v&&m(`div`,{className:`popover-message`,children:[b(U,{size:13,className:`spin`}),` Loading models…`]}),p&&b(`div`,{ref:ne,role:`listbox`,"aria-label":`Models`,onKeyDown:se,children:p.map(({provider:t,models:r,error:i})=>m(`div`,{role:`group`,"aria-labelledby":`${N}-${t.id}`,children:[b(`div`,{className:`popover-heading`,id:`${N}-${t.id}`,children:t.name}),i&&b(`div`,{className:`popover-message is-error`,children:i}),t.key_state===eT?m(`div`,{className:`popover-message`,role:`status`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,t.key_message]}):t.remote&&!t.models_discovered&&m(`button`,{type:`button`,className:`popover-item`,...pe(`key:${t.id}`),"aria-selected":!1,onClick:()=>{f(!1),l(`model`,t.id)},children:[b(`span`,{className:`popover-item-check`,children:b(Pt,{size:13,"aria-hidden":`true`})}),m(`span`,{className:`popover-item-body`,children:[b(`span`,{className:`popover-item-title`,children:`Add your key`}),m(`span`,{className:`popover-item-note`,children:[`Connect `,t.name,` in Settings`]})]})]}),!i&&r.length===0&&t.models_discovered!==!1&&b(`div`,{className:`popover-message`,children:`No models yet.`}),r.map(r=>{let i=ic(n??e?.model,r.id),a=!t.remote&&vc(r)===`not_downloaded`,o=_e[t.id][r.id],s=nT(r,t.remote),c=`${N}-info-${t.id}-${r.id}`;return m(`div`,{className:`popover-row`,children:[m(`button`,{type:`button`,className:`popover-item`,onClick:()=>{a?(M.current=0,j(null),O({model:r.id,provider:t}),ue(r.id)):(O(null),de(r.id,t))},disabled:C!==null||yc(r),...pe(r.id),"aria-selected":i,"aria-describedby":P===r.id?c:void 0,children:[b(`span`,{className:`popover-item-check`,"aria-hidden":`true`,children:C===r.id?b(U,{size:13,className:`spin`}):i?b(he,{size:13}):null}),b(`span`,{className:`popover-item-body`,children:b(`span`,{className:`popover-item-title`,children:o})})]}),m(Yw,{label:`About ${o}`,warning:!!r.placement?.warning,id:c,pinned:P===r.id,onUnpin:I,tabIndex:-1,children:[b(`div`,{className:`info-bubble-title`,children:o}),s.length>0&&b(`ul`,{className:`info-bubble-lines`,children:s.map(e=>b(`li`,{children:e},e))}),r.placement?.warning&&b(`ul`,{className:`info-bubble-lines`,children:b(`li`,{className:`is-warning`,children:r.placement.warning})}),b(`div`,{className:`info-bubble-id`,children:r.id})]}),b(`span`,{className:`popover-row-state`,children:!t.remote&&b(rT,{m:r,busy:T!==null,onDownload:()=>void ue(r.id)})})]},r.id)})]},t.id))}),x&&m(`div`,{className:`popover-message`,role:`alert`,children:[x.provider.privacy_notice,` `,m(`button`,{type:`button`,className:`link-btn`,onClick:()=>de(x.model,x.provider),children:[`Use `,ac(x.model)]})]}),g>0&&m(`button`,{type:`button`,className:`popover-item`,onClick:()=>{f(!1),l(`model`)},children:[b(`span`,{className:`popover-item-check`}),b(`span`,{className:`popover-item-body`,children:m(`span`,{className:`popover-item-note`,children:[g,` `,g===1?`model isn’t`:`models aren’t`,` available on this PC — see why in Settings`]})})]}),b(`div`,{className:`popover-divider`}),m(`button`,{type:`button`,className:`popover-item`,onClick:()=>{f(!1),l(`model`)},children:[b(`span`,{className:`popover-item-check`,children:b(Bt,{size:13,"aria-hidden":`true`})}),m(`span`,{className:`popover-item-body`,children:[b(`span`,{className:`popover-item-title`,children:`Add a model from a link…`}),b(`span`,{className:`popover-item-note`,children:`Any GGUF chat model on Hugging Face`})]})]}),m(`button`,{type:`button`,className:`popover-item`,onClick:()=>{f(!1),l(`model`)},children:[b(`span`,{className:`popover-item-check`}),b(`span`,{className:`popover-item-body`,children:b(`span`,{className:`popover-item-title`,children:`Providers and keys…`})})]})]})]})}function aT(e,t,n){if(e==null||!t(e))throw Error(`the server sent no ${n}`);return e}var oT=e=>e.startsWith(`.`);function sT({onPick:e,onClose:t}){let n=J(),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(``),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(!1);ki(!0,t);let p=(0,W.useRef)(null);FS(p,!0);let h=(0,W.useCallback)(e=>{u(!0),c(null),Promise.resolve().then(()=>us(e)).then(e=>{let t=aT(e,e=>Array.isArray(e.entries),`folder listing`);i(t),o(t.current_path)}).catch(e=>c(e instanceof Ia?e.detail||e.message:String(e))).finally(()=>u(!1))},[]);(0,W.useEffect)(()=>h(),[h]);let g=r?.entries.filter(e=>e.type===`folder`)??[],_=d?g:g.filter(e=>!oT(e.name));return b(`div`,{className:`modal-overlay`,onClick:t,children:m(`div`,{ref:p,className:`modal-panel sp-picker`,role:`dialog`,"aria-modal":`true`,"aria-label":n(`pick.label`),onClick:e=>e.stopPropagation(),children:[m(`div`,{className:`modal-header`,children:[b(`h3`,{children:n(`pick.title`)}),b(`button`,{type:`button`,className:`btn-icon`,onClick:t,"aria-label":n(`sp.closeShort`),children:b(cr,{size:18})})]}),m(`div`,{className:`modal-body sp-picker-body`,children:[b(`p`,{className:`sp-meta`,children:n(`pick.note`)}),m(`form`,{className:`sp-picker-path`,onSubmit:e=>{e.preventDefault(),a.trim()&&h(a.trim())},children:[b(`input`,{value:a,onChange:e=>o(e.target.value),"aria-label":n(`pick.path`),spellCheck:!1,dir:`ltr`}),b(`button`,{type:`submit`,className:`sp-action`,children:n(`pick.go`)})]}),r&&m(`div`,{className:`sp-picker-quick`,children:[r.quick_links.map(e=>b(`button`,{type:`button`,className:`sp-action`,onClick:()=>h(e.path),children:e.name},e.path)),m(`label`,{className:`sp-picker-hidden`,children:[b(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked)}),n(`pick.showHidden`)]})]}),m(`ul`,{className:`sp-picker-list`,"aria-busy":l,children:[r?.parent_path&&b(`li`,{children:m(`button`,{type:`button`,onClick:()=>h(r.parent_path??void 0),children:[b(I,{size:13,"aria-hidden":`true`}),` `,n(`pick.up`)]})}),_.map(e=>b(`li`,{children:m(`button`,{type:`button`,onClick:()=>h(e.path),children:[b(gt,{size:13,"aria-hidden":`true`}),` `,e.name]})},e.path)),r&&_.length===0&&b(`li`,{className:`sp-meta`,children:n(g.length>0?`pick.onlyHidden`:`pick.none`)}),l&&m(`li`,{className:`sp-meta`,children:[b(U,{size:12,className:`spin`,"aria-hidden":`true`}),` `,n(`pick.loading`)]})]}),s&&b(`p`,{className:`sp-error`,role:`alert`,children:s})]}),m(`div`,{className:`sp-picker-actions`,children:[b(`button`,{type:`button`,className:`btn-secondary`,onClick:t,children:n(`sp.cancel`)}),b(`button`,{type:`button`,className:`btn-primary`,disabled:!r,onClick:()=>r&&e(r.current_path),children:n(`pick.use`)})]})]})})}function cT(e){let[t,n]=(0,W.useState)(!1),[r,i]=(0,W.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?b(sT,{onPick:t=>{n(!1),e(t)},onClose:()=>n(!1)}):null,error:r}}var lT=new Map;function uT(e){let t=lT.get(e);return t||(t={env:null,error:null,inFlight:null,version:0,listeners:new Set},lT.set(e,t)),t}function dT(e,t,n){let r=uT(e);r.env=t??r.env,r.error=n,r.listeners.forEach(e=>e())}function fT(e){let t=uT(e);if(t.inFlight)return t.inFlight;let n=t.version;return t.inFlight=Promise.resolve().then(()=>Is(e)).then(r=>{let i=aT(r,e=>Array.isArray(e.folders),`chat's environment`);t.version===n&&dT(e,i,null)}).catch(t=>dT(e,null,t instanceof Error?t.message:String(t))).finally(()=>{t.inFlight=null}),t.inFlight}function pT(e){let[,t]=(0,W.useState)(0);(0,W.useEffect)(()=>{let n=uT(e),r=()=>t(e=>e+1);return n.listeners.add(r),!n.env&&!n.inFlight&&fT(e),()=>{n.listeners.delete(r)}},[e]);let n=(0,W.useCallback)(()=>fT(e),[e]),r=(0,W.useCallback)(async t=>{let n=await t();return uT(e).version+=1,dT(e,n,null),n},[e]),i=uT(e);return{env:i.env,error:i.error,refresh:n,change:r}}var mT=e=>e.split(/[\\/]/).filter(Boolean).pop()??e;function hT({folder:e,disabled:t}){let n=G(e=>e.draftFolder),r=G(e=>e.setDraftFolder),{open:i,picker:a,error:o}=cT(r),s=e.gaia_folder?`GAIA works in its own folder, ${e.path}.`:`GAIA works in ${e.path}.`;return e.choosable?m(_.Fragment,{children:[m(`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 ${mT(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:[b(gt,{size:13,"aria-hidden":`true`}),b(`span`,{className:`new-chat-folder-name`,dir:`auto`,children:n?`${e.name} + ${mT(n)}`:e.name}),b(B,{size:12,"aria-hidden":`true`})]}),n&&b(`button`,{type:`button`,className:`btn-icon-sm new-chat-folder-clear`,onClick:()=>r(null),disabled:t,"aria-label":`Don't give this chat ${mT(n)}`,title:`Don't add this folder`,children:b(cr,{size:12})}),o&&b(`span`,{className:`new-chat-folder-error`,role:`alert`,children:o}),a]}):m(`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:[b(gt,{size:13,"aria-hidden":`true`}),b(`span`,{className:`new-chat-folder-name`,dir:`auto`,children:e.name})]})}function gT({sessionId:e,onOpen:t}){let{env:n}=pT(e),r=n?.folders.find(e=>e.source===`working_folder`);if(!r)return null;let i=mT(r.path);return m(`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:[b(gt,{size:13,"aria-hidden":`true`}),b(`span`,{className:`composer-chip-label`,dir:`auto`,children:i})]})}var _T=`gaia:permission-mode`;function vT(e,t){window.dispatchEvent(new CustomEvent(_T,{detail:{sessionId:e,mode:t}}))}function yT(e,t){let n=(0,W.useRef)(t);n.current=t,(0,W.useEffect)(()=>{if(!e)return;let t=t=>{let r=t.detail;r?.sessionId===e&&n.current(r.mode)};return window.addEventListener(_T,t),()=>window.removeEventListener(_T,t)},[e])}var bT=[{mode:`ask`,label:`perm.ask`,note:`perm.askNote`},{mode:`full_access`,label:`perm.full`,note:`perm.fullNote`}];function xT({sessionId:e,disabled:t}){let n=J(),r=G(e=>e.draftPermissionMode),i=G(e=>e.setDraftPermissionMode),[a,s]=(0,W.useState)(e?`ask`:r),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(null),h=(0,W.useRef)(null);(0,W.useEffect)(()=>{if(!e){s(r);return}let t=!1;return Ea(e).then(e=>{t||s(e.mode)}).catch(e=>{t||p(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e,r]),yT(e,s);let g=(0,W.useCallback)(async t=>{if(t===`full_access`&&!u)d(!0);else{p(null);try{if(e){let n=(await ka(e,t)).mode;s(n),vT(e,n)}else i(t),s(t);l(!1)}catch(t){p(t instanceof Error?t.message:String(t)),e&&Ea(e).then(e=>s(e.mode)).catch(e=>p(t=>`${t??``} Couldn't re-read the saved mode: ${e instanceof Error?e.message:String(e)}`.trim()))}finally{d(!1)}}},[u,e,i]),_=a===`full_access`,v=_?Mn:Pn;return m(`div`,{className:`composer-chip-wrap`,children:[m(`button`,{ref:h,type:`button`,className:`composer-chip${_?` is-warning`:``}`,onClick:()=>{d(!1),l(e=>!e)},disabled:t,"aria-haspopup":`dialog`,"aria-expanded":c,"aria-label":n(`perm.chipAria`,{mode:o(_?`perm.fullLower`:`perm.askLower`)}),children:[b(v,{size:13,"aria-hidden":`true`}),b(`span`,{className:`composer-chip-label`,dir:`auto`,children:n(_?`perm.full`:`env.ask`)}),b(B,{size:12,"aria-hidden":`true`})]}),m(ji,{open:c,onClose:()=>l(!1),anchor:h,label:n(`env.permission`),children:[bT.map(e=>m(`button`,{type:`button`,className:`popover-item`,onClick:()=>g(e.mode),"aria-pressed":a===e.mode,children:[b(`span`,{className:`popover-item-check`,"aria-hidden":`true`,children:a===e.mode&&b(he,{size:13})}),m(`span`,{className:`popover-item-body`,children:[b(`span`,{className:`popover-item-title`,children:n(e.label)}),b(`span`,{className:`popover-item-note`,children:n(e.note)})]})]},e.mode)),u&&m(`div`,{className:`popover-message`,role:`alert`,children:[n(`env.fullAccessWarn`),` `,b(`button`,{type:`button`,className:`link-btn`,onClick:()=>g(`full_access`),children:n(`env.turnOn`)})]}),f&&b(`div`,{className:`popover-message is-error`,role:`alert`,children:f})]})]})}var ST={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 CT(e,t){return e?ST.queued:t?`GAIA is still busy in this chat. Trying again in a few seconds.`:`Sending next.`}function wT({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:b(`ul`,{className:`queued-messages`,"aria-label":`Messages waiting to send`,"aria-live":`polite`,children:o.map(e=>m(`li`,{className:`queued-message is-${e.state}`,children:[e.state===`failed`?b(xe,{size:12,"aria-hidden":`true`}):e.state===`queued`?b(Ae,{size:12,"aria-hidden":`true`}):b(Re,{size:12,"aria-hidden":`true`}),b(`span`,{className:`queued-message-text`,title:e.text,children:e.text}),b(`span`,{className:`queued-message-state`,title:e.error,children:e.state===`failed`?`Not sent. ${e.error??``}`.trim():e.state===`queued`?i&&e.note||CT(i,a):ST[e.state]}),e.state===`failed`&&m(`button`,{type:`button`,className:`queued-message-steer`,onClick:()=>r(e.id),"aria-label":`Send again: ${e.text}`,children:[b(En,{size:11,"aria-hidden":`true`}),` Send again`]}),e.state===`queued`&&n&&b(`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`)&&b(`button`,{type:`button`,className:`queued-message-remove`,onClick:()=>t(e.id),"aria-label":`Remove queued message: ${e.text}`,title:`Remove`,children:b(cr,{size:12})})]},e.id))})}var TT=e=>e.toLocaleString(`en-US`);function ET({n:e}){let t=J();if(e==null)return b(`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 b(`span`,{title:t(`ctx.tokens`,{n:TT(e)}),dir:`ltr`,children:n})}function DT({s:e}){let t=J();if(e==null)return b(`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 b(`span`,{title:`${(e*1e3).toFixed(0)} ms`,dir:`ltr`,children:n})}function OT({r:e}){let t=J();return e==null?b(`span`,{className:`cp-unknown`,children:t(`ctx.unknown`)}):b(`span`,{title:t(`ctx.rateTitle`,{n:e}),children:t(`ctx.rate`,{n:Math.round(e).toLocaleString(`en-US`)})})}var kT=(e,t)=>t>0?Math.round(e/t*100):0,AT=(e,t)=>{let n=kT(e,t);return n===0&&e>0?`<1`:String(n)},jT=(e,t)=>t&&e!=null?Math.floor(e/t*100):null,MT=256;function NT(e,t=Dc){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:mc(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 PT({label:e,children:t,hint:n}){return m(`div`,{className:`cp-row`,title:n,children:[b(`dt`,{children:e}),b(`dd`,{children:t})]})}function FT({t:e}){let t=J();if(e.model_seconds==null||e.gaia_seconds==null)return m(PT,{label:t(`ctx.took`),children:[b(DT,{s:e.wall_seconds}),` · `,t.bare(`ctx.split`),` `,b(`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 m(_.Fragment,{children:[b(PT,{label:t(`ctx.took`),hint:t(`ctx.tookHint`),children:b(DT,{s:e.wall_seconds})}),b(`div`,{className:`cp-stack`,"aria-hidden":`true`,children:n.map(t=>b(`span`,{className:`cp-time-${t.key}`,style:{width:`${kT(t.s,e.wall_seconds)}%`}},t.key))}),m(`dl`,{className:`cp-rows cp-indent`,children:[b(PT,{label:t(`ctx.inModel`),children:b(DT,{s:e.model_seconds})}),b(PT,{label:t(`ctx.inGaia`),hint:t(`ctx.inGaiaHint`),children:b(DT,{s:e.gaia_seconds})}),n.slice(1).filter(e=>e.s>0).map(e=>m(PT,{label:`· ${e.label}`,children:[b(`span`,{className:`swatch cp-time-${e.key}`,"aria-hidden":`true`}),` `,b(DT,{s:e.s})]},e.key))]})]})}function IT({why:e}){let t=J();return b(`span`,{className:`cp-unknown`,title:e,children:t(`ctx.unknown`)})}var LT={server:`ctx.src.server`,client:`ctx.src.client`};function RT(e,t){return e?t(LT[e]):void 0}function zT({turn:e}){let t=J(),n=jT(e.tokens_cached,e.tokens_in),r=e.unknown??{},i=e.tools.map(e=>`${e.name??t(`ctx.toolOutside`)}: ${e.seconds??`?`} s`).join(`
61
61
  `);return m(_.Fragment,{children:[b(FT,{t:e.time}),m(`dl`,{className:`cp-rows`,children:[b(PT,{label:t(`ctx.firstWord`),hint:RT(e.first_token_source,t),children:e.first_token_seconds==null?b(IT,{why:r.first_token_seconds}):m(_.Fragment,{children:[t.bare(`ctx.in`),` `,b(DT,{s:e.first_token_seconds})]})}),b(PT,{label:t(`ctx.readingPrompt`),hint:t(`ctx.readingHint`),children:e.tokens_new!=null&&e.tokens_new<MT?b(`span`,{title:t(`ctx.tooFewTitle`),children:t(`ctx.onlyNew`,{n:e.tokens_new})}):e.prefill_tokens_per_second==null?b(IT,{why:r.prefill_tokens_per_second}):m(_.Fragment,{children:[b(OT,{r:e.prefill_tokens_per_second}),e.prefill_source===`client`&&b(`span`,{className:`cp-chip`,title:t(`ctx.approxTitle`),children:t(`ctx.approx`)})]})}),b(PT,{label:t(`ctx.writing`),hint:RT(e.generation_source,t)??t(`ctx.writingHint`),children:e.generation_tokens_per_second==null?b(IT,{why:r.generation_tokens_per_second}):b(OT,{r:e.generation_tokens_per_second})}),b(PT,{label:t(`ctx.tokensInOut`),hint:r.tokens,children:m(`span`,{dir:`ltr`,children:[b(ET,{n:e.tokens_in}),` → `,b(ET,{n:e.tokens_out})]})}),b(PT,{label:t(`ctx.cache`),hint:t(`ctx.cacheHint`),children:e.tokens_cached==null?b(IT,{why:r.tokens_cached}):m(_.Fragment,{children:[b(ET,{n:e.tokens_cached}),n!=null&&` (${n}%)`]})}),b(PT,{label:t(`ctx.modelCalls`),children:e.model_calls}),b(PT,{label:t(`ctx.toolCalls`),hint:i||void 0,children:e.tool_calls===0&&!e.tool_seconds_total?t(`ctx.none`):m(_.Fragment,{children:[e.tool_calls,` · `,b(DT,{s:e.tool_seconds_total??0})]})}),b(PT,{label:t(`ctx.loads`),children:e.loads.length===0?t(`ctx.none`):m(`span`,{title:e.loads.map(e=>`${e.model}${e.replaced?.length?` replaced ${e.replaced.join(`, `)}`:``}: ${e.seconds} s`).join(`
@@ -74,5 +74,5 @@ Details: ${u}`+d:t instanceof TypeError||u.includes(`fetch`)||u.includes(`Failed
74
74
  `)))}else et.length===0||lt||A||P||xt.current||Oe||M?.init_state===`initializing`||gt()||!at.current&&!Wt||Tw(e,Gt,()=>bt.current&&!gt()&&!G.getState().isStreaming&&!Ot.current)}},[U,et,lt,Wt,A,P,Oe,M?.init_state,e,Gt,gt]);let Kt=(0,W.useRef)(!1);(0,W.useEffect)(()=>{Kt.current&&!U&&wt(),Kt.current=U},[U,wt]);let qt=(0,W.useCallback)(t=>{let n=et.find(e=>e.id===t&&e.state===`queued`);n&&u&&(tt(e=>Zr(e,t,`queued`,`sending`)),_a(e,n.text).then(()=>tt(e=>Zr(e,t,`sending`,`delivered`))).catch(e=>{i.chat.info(`Follow-up not taken by the running reply; it stays queued: ${e instanceof Error?e.message:e}`),tt(e=>$r(e,t))}))},[et,u,e,tt]),Jt=(0,W.useCallback)(()=>{for(let e=r.length-1;e>=0;e--)if(r[e].role===`user`){Ut(r[e]);return}},[r,Ut]),Yt=()=>{z(L?.title||``),fe(!0)},Xt=async()=>{let t=R.trim().slice(0,200).trim();t&&R!==L?.title&&t!==L?.title&&(await Oo(e,{title:t,title_is_custom:!0}),l(e,{title:t})),fe(!1)},Zt=(0,W.useCallback)(async()=>{if(e)try{let t=await Po(e);l(e,{private:t.private})}catch(e){i.ui.warn(`Failed to toggle private mode`,e)}},[e,l]),Qt=(0,W.useCallback)(async(t,n)=>{t.stopPropagation();let r=D.find(e=>e.id===n);i.doc.info(`Detaching document from session: ${r?.filename||n}`);try{await ls(e,n);let t=(G.getState().sessions.find(t=>t.id===e)?.document_ids??[]).filter(e=>e!==n);l(e,{document_ids:t}),t.length<=3&&_e(!1),i.doc.info(`Detached document from session: ${r?.filename||n}`)}catch(e){i.doc.error(`Failed to detach document: ${r?.filename||n}`,e)}},[D,e,l]),$t=(0,W.useCallback)(async t=>{if(t.preventDefault(),t.stopPropagation(),me(!1),t.dataTransfer.files.length!==0){for(let n of Array.from(t.dataTransfer.files)){i.doc.info(`Dropped on chat view: ${n.name}`);try{let t=await ns(n);if(e&&t?.id)try{await cs(e,t.id);let r=G.getState().sessions.find(t=>t.id===e)?.document_ids??[];r.includes(t.id)||l(e,{document_ids:[...r,t.id]}),i.doc.info(`Auto-attached "${n.name}" to session ${e}`)}catch(e){i.doc.warn(`Could not attach dropped document to session: ${e}`)}}catch(e){i.doc.error(`Upload failed: ${n.name}`,e)}}try{let e=await es();O(e.documents||[])}catch(e){i.doc.error(`Could not refresh the document list after a drop`,e)}}},[e,l,O]),en=e=>{e.preventDefault(),e.stopPropagation(),me(!0)},tn=e=>{e.preventDefault(),e.stopPropagation(),me(!1)},nn=r.length>0?r[r.length-1]:void 0,rn=!u&&!A&&nn?.role===`assistant`&&dx(nn.content),an=(0,W.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]),on=Oe?`This chat used the retired "${Oe}" agent and is read-only. Start a new chat.`:M?.init_state===`initializing`?Nl:null;return m(`main`,{className:`task-view ${pe?`drag-active`:``}`,style:{"--session-panel-w":`${Pt}px`},onDrop:$t,onDragOver:en,onDragLeave:tn,"aria-label":L?.title||`Chat`,children:[m(`header`,{className:`task-header`,children:[b(`div`,{className:`task-header-left`,children:de?b(`input`,{className:`title-edit`,value:R,maxLength:200,onChange:e=>z(e.target.value),onBlur:Xt,onKeyDown:e=>{e.key===`Enter`&&Xt(),e.key===`Escape`&&(e.preventDefault(),fe(!1))},...Ci,autoFocus:!0,"aria-label":`Chat title`,dir:`auto`}):m(`button`,{type:`button`,className:`task-title`,onClick:Yt,title:t(`row.rename`),children:[b(`span`,{children:L?.title||t(`sidebar.newChat`)}),b(fn,{size:12,"aria-hidden":`true`,className:`task-title-edit`})]})}),m(`div`,{className:`task-header-right`,children:[b(mD,{isPrivate:!!L?.private,onToggle:Zt}),b(`button`,{className:`btn-icon-sm`,onClick:()=>k(!0),title:`Browse files on this PC`,"aria-label":`Browse files on this PC`,children:b(mt,{size:15})}),b(`button`,{className:`btn-icon-sm`,onClick:Ee,title:`Export as Markdown`,"aria-label":`Export chat`,children:b(We,{size:15})}),b(pD,{messages:r,busy:u})]})]}),ce.length>0&&(()=>{let e=[...ce].sort((e,t)=>{let n=e.last_accessed_at||e.indexed_at||``;return(t.last_accessed_at||t.indexed_at||``).localeCompare(n)}),t=V?e:e.slice(0,3),n=e.length-3;return m(`div`,{className:`doc-context-bar${V?` doc-context-expanded`:``}`,"aria-label":`${ce.length} indexed document${ce.length===1?``:`s`}`,children:[b(Te,{size:12,className:`doc-context-icon`,"aria-hidden":`true`}),m(`button`,{type:`button`,className:`doc-context-label`,onClick:()=>ee(!0),title:`Manage documents`,children:[ce.length,` indexed`]}),m(`div`,{className:`doc-context-pills${V?` doc-context-pills-expanded`:``}`,children:[t.map(e=>m(`span`,{className:`doc-pill`,title:e.filepath||e.filename,children:[b(ot,{size:9,className:`doc-pill-icon`,"aria-hidden":`true`}),b(`span`,{className:`doc-pill-name`,children:e.filename}),b(`button`,{className:`doc-pill-remove`,onClick:t=>Qt(t,e.id),"aria-label":`Remove ${e.filename} from this chat`,children:b(cr,{size:10})})]},e.id)),!V&&n>0&&m(`button`,{className:`doc-pill-more`,onClick:e=>{e.stopPropagation(),_e(!0)},children:[`+`,n,` more`]}),V&&n>0&&b(`button`,{className:`doc-pill-collapse`,onClick:e=>{e.stopPropagation(),_e(!1)},children:`show less`})]})]})})(),b(`div`,{className:`messages-scroll`,ref:Re,onScroll:Nt,children:m(`div`,{className:`messages-column`,children:[A&&b(`div`,{className:`skeleton-messages`,"aria-label":`Loading messages`,children:[0,1,2].map(e=>b(`div`,{className:`skeleton-msg`,children:m(`div`,{className:`skeleton-lines`,children:[b(`div`,{className:`skeleton-line`}),b(`div`,{className:`skeleton-line`}),e!==2&&b(`div`,{className:`skeleton-line`})]})},e))}),r.map((e,t)=>{if(ke&&e.role===`assistant`&&t===r.length-1)return null;let n=e.role===`assistant`?e.historyNotice??RD.get(e.id):void 0,i=!U&&!Et&&!Oe&&!ke&&e.role===`assistant`&&t===r.length-1&&!e.stopState&&!rC(e.content),a=e.stats?.seconds==null?an.get(e.id):e.stats.seconds*1e3;return m(`div`,{className:ve===e.id?`msg-deleting`:void 0,"data-message-id":e.id,"data-role":e.role,children:[n&&b(zD,{text:n}),b(CC,{message:e,agentSteps:e.role===`assistant`?e.agentSteps:void 0,onDelete:U?void 0:Ht,onResend:!U&&e.role===`user`&&!Oe?Ut:void 0,extraActions:i?b(XT,{answeredBy:e.stats?.model??L?.effective_model,onPick:t=>kt(e,t)}):void 0,latencyMs:a}),Et?.messageId===e.id&&b($T,{original:e,originalModel:e.stats?.model??L?.effective_model,originalLatencyMs:a,state:Et.state,keeping:Et.keeping,onKeep:e=>{At(e)},onClose:jt})]},e.id)}),(u||ke)&&je&&b(zD,{text:je}),(u||ke)&&b(`div`,{className:`streaming-bubble ${ke?`stream-ending`:`stream-active`}`,children:b(CC,{message:{id:-1,session_id:e,role:`assistant`,content:(u?d:Ne.current)||``,created_at:``,rag_sources:null},isStreaming:u,agentSteps:u?g:Pe.current,agentStepsActive:u&&g.some(e=>e.active),cards:u?w:Fe.current,liveStatus:u?F:null,awaitingUser:u&&(I||ae||oe)})}),b(`div`,{ref:Le})]})}),b(fD,{sessionId:e,messages:r,busy:U,onUsage:Tt,onJumpToMessage:It}),he&&b(`button`,{className:`scroll-bottom-btn`,onClick:Lt,title:`Scroll to bottom`,"aria-label":`Scroll to bottom`,children:b(re,{size:16})}),pe&&m(`div`,{className:`drag-overlay`,children:[b(nr,{size:32,strokeWidth:1.5,"aria-hidden":`true`}),b(`span`,{children:`Drop files to index them for this chat`})]}),be&&m(`div`,{className:`toast policy-alert-toast`,role:`alert`,children:[m(`span`,{children:[`Blocked: `,be.tool,` is restricted by policy.`]}),be.receiptId?b(`button`,{type:`button`,className:`policy-alert-toast-link`,onClick:()=>{let e=be.receiptId;e&&(ie(`policy_alert`),ne(!0),we(e))},children:`View receipt`}):b(`span`,{className:`policy-alert-toast-missing`,children:`Receipt unavailable`})]}),b(`div`,{className:`input-area`,children:m(`div`,{className:`input-column`,children:[b(gD,{message:H,onDismiss:De}),rn&&nn&&b(Uw,{content:nn.content,onRetry:Jt}),b(tb,{sessionId:e}),b(JT,{usage:St}),b(hD,{sessionId:e}),b(wT,{items:et,onRemove:e=>tt(t=>ei(t,e)),onRetry:e=>tt(t=>Zr(t,e,`failed`,`queued`)),onSteer:u&&!Ke&&!rt?qt:void 0,replying:u,busyRetry:!!lt}),b(Kw,{value:le,onChange:ue,onSubmit:()=>zt(),onStop:Rt,streaming:u,stopping:Ke,queueWhileStreaming:!0,disabledReason:on,attachments:B,inputRef:ze,placeholder:u?t(`composer.queueNext`):r.length===0?t(`composer.placeholder`):t(`composer.reply`),leftControls:b(xT,{sessionId:e,disabled:!!Oe}),rightControls:m(_.Fragment,{children:[b(qT,{usage:St,unavailable:Ct,sessionId:e,busy:U,onUsage:Tt,onDetails:()=>Ft(`context`)}),b(gT,{sessionId:e,onOpen:()=>Ft(`environment`)}),b(iT,{})]})})]})})]})}var VD=1.1,HD=60,UD=110,WD=24,GD=2.4,KD=Math.PI*2,qD=(e,t,n)=>{let r=Math.min(1,Math.max(0,(n-e)/(t-e)));return r*r*(3-2*r)};function JD(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 YD=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=JD(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()*KD),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*qD(.75,1.5,a))*qD(0,50,i)*qD(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()*KD})}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()*KD},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*GD),a=Math.min(1,e*14),o=Math.min(1,e*9),s=r?HD+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)>WD+.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)/WD;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<UD){let i=(1-n/UD)**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/VD),i=(1-(1-r)**3)*n.reach,a=new Path2D;for(let e=0;e<=180;e++){let t=e/180*KD,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)}},XD=90;function ZD(){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 QD(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 $D({activity:e,progress:t=0,pulse:n,docked:r,contentRef:a,composerRef:o}){let s=(0,W.useRef)(null),c=(0,W.useRef)(null),l=(0,W.useRef)(null),u=(0,W.useRef)(()=>{}),d=(0,W.useRef)(()=>{}),f=(0,W.useRef)(r),p=(0,W.useRef)({value:n,at:0});f.current=r,(0,W.useEffect)(()=>{let e=s.current,t=e?.parentElement;if(!e||!t)return;let n=e.getContext(`2d`);if(!n){i.ui.warn(`New-chat background is off: the browser gave no 2D canvas context (often low graphics memory).`);return}l.current=t;let r=new YD;c.current=r;let p=typeof window.matchMedia==`function`?window.matchMedia(sS):null,m=ZD(),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?o.current:a.current,r=(n&&QD(n,e,f.current?24:40))??{cx:e.width/2,cy:e.height/2,rx:1,ry:1},i=`${Math.round(r.cx)},${Math.round(r.cy)},${Math.round(r.rx)},${Math.round(r.ry)}`;return t||i!==v?(v=i,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)};u.current=w,d.current=()=>{let e=x(t.getBoundingClientRect());e&&r.setHole(e),_||b()};let E=()=>document.hidden?T():w(),D=()=>{T(),b(),w()},O=()=>{m=ZD(),b()},ee=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)},k=()=>{y.at=0,y.speed=0,r.clearPointer()},A=typeof ResizeObserver>`u`?null:new ResizeObserver(S);A?.observe(t,{box:`border-box`});let j=new MutationObserver(O);return j.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`,`data-palette`,`style`]}),document.addEventListener(`visibilitychange`,E),p?.addEventListener(`change`,D),t.addEventListener(`pointermove`,ee),t.addEventListener(`pointerleave`,k),S(),w(),()=>{T(),A?.disconnect(),j.disconnect(),document.removeEventListener(`visibilitychange`,E),p?.removeEventListener(`change`,D),t.removeEventListener(`pointermove`,ee),t.removeEventListener(`pointerleave`,k),c.current=null,u.current=()=>{},d.current=()=>{}}},[a,o]);let m=(0,W.useCallback)(()=>{let e=l.current,t=o.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]},[o]);return(0,W.useEffect)(()=>{let t=c.current;if(t){if(t.setActivity(e),e===`sending`){let e=m();e&&t.dissolve(...e)}else t.dissolving&&(t.restore(),u.current())}},[e,m]),(0,W.useEffect)(()=>{c.current?.setProgress(t)},[t]),(0,W.useEffect)(()=>{d.current()},[r]),(0,W.useEffect)(()=>{let e=p.current;if(n===e.value)return;let t=performance.now();if(e.value=n,t-e.at<XD)return;e.at=t;let r=m();r&&c.current?.ripple(...r,.45)},[n,m]),b(`canvas`,{ref:s,className:`npu-backdrop`,"aria-hidden":`true`})}var eO=S();async function tO(e,t,n){let r=`${eO}${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 nO(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 rO(){return tO(`GET`,`/memory/stats`)}function iO(e=30){return tO(`GET`,`/memory/activity?days=${e}`)}function aO(e={}){return tO(`GET`,`/memory/knowledge${nO(e)}`)}function oO(e){return tO(`POST`,`/memory/knowledge`,e)}function sO(e,t){return tO(`PUT`,`/memory/knowledge/${encodeURIComponent(e)}`,t)}function cO(e){return tO(`DELETE`,`/memory/knowledge/${encodeURIComponent(e)}`)}function lO(){return tO(`GET`,`/memory/entities`)}function uO(){return tO(`GET`,`/memory/tools`)}function dO(e=20){return tO(`GET`,`/memory/conversations?limit=${e}`)}function fO(e,t=20){return tO(`GET`,`/memory/conversations/search?query=${encodeURIComponent(e)}&limit=${t}`)}function pO(e){return tO(`GET`,`/memory/conversations/${encodeURIComponent(e)}`)}function mO(e=7){return tO(`GET`,`/memory/upcoming?days=${e}`)}function hO(){return tO(`GET`,`/memory/embedding-coverage`)}function gO(){return tO(`POST`,`/memory/consolidate`)}function _O(){return tO(`POST`,`/memory/rebuild-embeddings`)}function vO(){return tO(`POST`,`/memory/reconcile`)}function yO(){return tO(`POST`,`/memory/rebuild-fts`)}function bO(){return tO(`POST`,`/memory/refresh-system-context`)}function xO(){return new EventSource(`${eO}/memory/stream-discovery`)}function SO(e){return new EventSource(`${eO}/memory/stream-inference?include_browser=${e}`)}function CO(e){return tO(`POST`,`/memory/commit-discovery`,{items:e})}function wO(e){return tO(`POST`,`/memory/commit-inference`,{insights:e})}function TO(){return tO(`GET`,`/memory/settings`)}function EO(e){return tO(`PUT`,`/memory/settings`,e)}function DO(){return tO(`DELETE`,`/memory/all`)}function OO(){return tO(`POST`,`/memory/reinitialize`)}function kO(){return tO(`GET`,`/goals/stats`)}function AO(e={}){return tO(`GET`,`/goals${nO(e)}`)}function jO(e){return tO(`POST`,`/goals`,e)}function MO(e){return tO(`PUT`,`/goals/${encodeURIComponent(e)}/approve`)}function NO(e){return tO(`PUT`,`/goals/${encodeURIComponent(e)}/reject`)}function PO(e){return tO(`PUT`,`/goals/${encodeURIComponent(e)}/cancel`)}function FO(e){return tO(`DELETE`,`/goals/${encodeURIComponent(e)}`)}function IO({disabled:e}){let t=J(),n=G(e=>e.draftPrivate),r=G(e=>e.setDraftPrivate),a=G(e=>e.settingsSection!==null),[o,s]=(0,W.useState)(null),[c,l]=(0,W.useState)(!1);return(0,W.useEffect)(()=>{if(a)return;let e=!1;return TO().then(t=>{e||(s(t.memory_enabled),l(!1))}).catch(t=>{e||(i.ui.error(`Could not read the memory setting for the Private chip`,t),s(null),l(!0))}),()=>{e=!0}},[a]),(0,W.useEffect)(()=>{o===!1&&n&&r(!1)},[o,n,r]),o===!1?m(`button`,{type:`button`,className:`composer-chip composer-chip-memory is-unavailable`,disabled:!0,"aria-label":t(`composer.memoryOff`),title:t(`composer.memoryOffTitle`),children:[b(Xe,{size:13,"aria-hidden":`true`}),b(`span`,{className:`composer-chip-label`,dir:`auto`,children:t(`composer.memoryOff`)})]}):m(`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`:c?`composer.memoryUnknownTitle`:`composer.privateOnTitle`),children:[b(n?Xe:Qe,{size:13,"aria-hidden":`true`}),b(`span`,{className:`composer-chip-label`,dir:`auto`,children:t(n?`composer.private`:c?`composer.memoryUnknown`:`composer.memoryOn`)})]})}var LO=1e3;function RO(){let[e,t]=(0,W.useState)(null);return(0,W.useEffect)(()=>{let e=!1,n,r=i=>{e||(i.state===`warming`?(t({seconds:Math.floor(i.elapsed_seconds??0),model:i.model??null,device:i.device??null}),n=setTimeout(()=>{Ga().then(r,a)},LO)):t(null))},a=n=>{e||(i.system.warn(`Warm-up status unavailable`,n),t(null))};return Wa().then(r,a),()=>{e=!0,n&&clearTimeout(n)}},[]),e}function zO(e){return e===`gpu`?`your GPU`:e===`npu`?`your NPU`:e===`cpu`?`the CPU`:null}function BO(e){return e<1?`under 1 GB`:`${e.toFixed(1)} GB`}var VO=15e3;function HO(e=new Date,t=Dc){let n=e.getHours();return t(`newChat.greeting.${n<5?`evening`:n<12?`morning`:n<18?`afternoon`:`evening`}`)}var UO={gpu:`device.gpu`,npu:`device.npu`,cpu:`device.cpu`};function WO({seconds:e,model:t,device:n},r=Dc){if(!t)return r(`newChat.warmup.ready`,{s:e});let i=ac(t),a=n?UO[n]:void 0;if(a)return r(`newChat.warmup.loadingOn`,{model:i,where:o(a),s:e});let s=zO(n);return s?r(`newChat.warmup.loadingOn`,{model:i,where:s,s:e}):r(`newChat.warmup.loading`,{model:i,s:e})}function GO({detail:e,onRetry:t}){let n=J(),[r,i]=(0,W.useState)(!1);return m(`div`,{className:`new-chat-note`,children:[m(`p`,{children:[n(`newChat.assistantUnavailable`),` `,b(`button`,{type:`button`,className:`link-btn`,onClick:t,children:n(`newChat.tryAgain`)})]}),m(`button`,{type:`button`,className:`new-chat-details`,"aria-expanded":r,onClick:()=>i(e=>!e),children:[b(_e,{size:12,className:r?`is-open`:``,"aria-hidden":`true`}),` `,n(`newChat.details`)]}),r&&b(`pre`,{className:`new-chat-details-text`,children:e})]})}function KO(){let{documents:e,draftDocumentIds:t,addDraftDocuments:n}=G.getState();n(e.filter(e=>e.indexing_status===`complete`&&!t.includes(e.id)).map(e=>e.id))}function qO(){let e=J(),t=G(e=>e.documents),n=G(e=>e.draftDocumentIds),r=G(e=>e.removeDraftDocument),i=G(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 m(`div`,{className:`new-chat-docs`,children:[a.length>0&&b(`ul`,{className:`new-chat-doc-list`,"aria-label":e(`newChat.docs.forChat`),children:a.map(t=>m(`li`,{className:`new-chat-doc`,children:[b(ot,{size:12,"aria-hidden":`true`}),b(`span`,{dir:`auto`,children:t.filename}),b(`button`,{type:`button`,className:`new-chat-doc-remove`,onClick:()=>r(t.id),"aria-label":e(`newChat.docs.dontAttach`,{name:t.filename}),children:b(cr,{size:12,"aria-hidden":`true`})})]},t.id))}),s>0&&m(`p`,{className:`new-chat-note`,children:[a.length?e.plural(`newChat.docs.more`,s):e.plural(`newChat.docs.library`,s),` `,b(`button`,{type:`button`,className:`link-btn`,onClick:KO,children:s===1?e(`newChat.docs.attachIt`):e(`newChat.docs.attachAll`,{n:s})}),s>1&&m(_.Fragment,{children:[` · `,b(`button`,{type:`button`,className:`link-btn`,onClick:()=>i(!0),children:e(`newChat.docs.choose`)})]})]})]})}function JO({error:e}){let t=J(),n=G(e=>e.openSettings);return m(`div`,{className:`new-chat-setup-failed`,role:`alert`,children:[b(`p`,{className:`new-chat-setup-failed-title`,children:t(`newChat.setupFailed.title`)}),b(`p`,{className:`new-chat-setup-failed-error`,children:e}),m(`p`,{children:[t(`newChat.setupFailed.hint`),` `,b(`button`,{type:`button`,className:`link-btn`,onClick:()=>n(`model`),children:t(`newChat.setupFailed.choose`)})]})]})}function YO({onSend:e,initialText:t=``,focusRequest:n=0}){let r=J(),a=G(e=>e.systemStatus?.init_state===`initializing`),o=G(e=>e.systemStatus?.download_progress??null),s=G(e=>e.systemStatus?.model_loaded?null:e.systemStatus?.setup_error??null),c=nc(e=>!!e.active?.remote),[l,u]=MD(Pi,t),[d,f]=(0,W.useState)(null),[p,h]=(0,W.useState)(!1),[g,v]=(0,W.useState)(null),[y,x]=(0,W.useState)(null),S=(0,W.useRef)(null),C=(0,W.useRef)(null),w=(0,W.useRef)(null),T=vD(),E=RO();rc();let D=(0,W.useRef)(!0),O=(0,W.useCallback)((e=!1)=>{e||x(null),ea().then(e=>{D.current&&(v(e),x(e.skills_error??null))}).catch(e=>{i.api.warn(`New-chat start screen unavailable`,e),D.current&&x(e instanceof Error?e.message:String(e))})},[]);(0,W.useEffect)(()=>(D.current=!0,O(),()=>{D.current=!1}),[O]),(0,W.useEffect)(()=>{es().then(e=>G.getState().setDocuments(e.documents||[])).catch(e=>i.api.warn(`Document library unavailable; not offering its documents`,e))},[]),(0,W.useEffect)(()=>{if(y)return AD(()=>O(!0),VO)},[y,O]);let ee=(0,W.useRef)(!1),k=(0,W.useRef)([]),A=(0,W.useCallback)(async(t,n=``)=>{if(t){if(ee.current)k.current.push(n||t),u(``);else{ee.current=!0,h(!0),f(null),u(``);try{let n=await e(t);T.clear();let r=k.current.splice(0),i=G.getState().currentSessionId;if(r.length>0&&i){let e=(e,t)=>n===!1?[...e,{...Yr(t,`failed`),error:`The first message was not sent.`}]:Xr(e,t,`queued`);G.getState().updateQueue(i,t=>r.reduce(e,t))}}catch(e){let r=k.current.splice(0);u([n||t,...r].join(`
75
75
 
76
76
  `)),f(e instanceof Error?e.message:String(e))}finally{ee.current=!1,h(!1)}}}},[T,e]),j=(0,W.useCallback)(()=>A(T.compose(l.trim()),l.trim()),[T,A,l]);(0,W.useEffect)(()=>{n&&S.current?.focus()},[n]);let M=l.length>0||p,te=(0,W.useRef)(null);(0,W.useLayoutEffect)(()=>{let e=C.current;if(!e)return;typeof e.getAnimations==`function`&&e.getAnimations().forEach(e=>e.cancel());let t=e.getBoundingClientRect().top,n=te.current;if(te.current={top:t,docked:M},!n||n.docked===M||lS()||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:cS(`--duration-spring`),easing:r})});let N=o?.state===`starting`||o?.state===`downloading`,ne=p?`sending`:N?`download`:a||E!==null?`loading`:`idle`,re=g?.working_folder;return m(`main`,{className:`new-chat${M?` is-docked`:``}`,"aria-label":r(`newChat.label`),children:[b($D,{activity:ne,progress:(o?.percent??0)/100,pulse:l.length,docked:M,contentRef:C,composerRef:w}),m(`div`,{className:`new-chat-inner`,ref:C,children:[b(`h1`,{className:`new-chat-greeting`,"aria-hidden":M,children:HO(new Date,r)}),s&&!c&&b(JO,{error:s}),b(`div`,{ref:w,children:b(Kw,{value:l,onChange:u,onSubmit:j,attachments:T,disabledReason:a?r(`composer.starting`):null,autoFocus:!0,inputRef:S,leftControls:m(_.Fragment,{children:[b(xT,{sessionId:null}),b(IO,{disabled:p})]}),rightControls:b(iT,{})})}),b(`div`,{className:`new-chat-meta`,children:re&&b(hT,{folder:re,disabled:a||p})}),b(qO,{}),E!==null&&!a&&b(`p`,{className:`new-chat-warmup`,role:`status`,children:WO(E,r)}),d&&b(`p`,{className:`new-chat-error`,role:`alert`,children:d}),y&&b(GO,{detail:y,onRetry:()=>O()})]})]})}function XO(e){let t=e?.reason;return t===`needs_key`||t===`bad_key`}function ZO({provider:e,limit:t}){let[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(null);if((0,W.useEffect)(()=>{r(null),a(null),xo(e).then(r).catch(e=>a(e instanceof Error?e.message:String(e)))},[e]),i)return m(`p`,{className:`settings-error`,role:`alert`,children:[`Prices could not be loaded: `,i]});if(!n)return m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Loading prices…`]});if(n.models.length===0)return m(`p`,{className:`settings-hint cloud-prices-note`,children:[`Price unknown. `,n.note]});let o=t?n.models.slice(0,t):n.models;return m(`div`,{className:`cloud-prices`,"aria-label":`Prices`,children:[b(`ul`,{className:`cloud-prices-list`,children:o.map(e=>m(`li`,{children:[m(`span`,{className:`cloud-prices-name`,children:[e.name,e.note&&m(`span`,{className:`cloud-prices-note`,children:[` · `,e.note]})]}),b(`span`,{className:`cloud-prices-price`,children:Zw(e.price)})]},e.model))}),m(`span`,{className:`settings-hint`,children:[n.source,`. You pay the provider for what you use.`]})]})}var QO=1e9;function $(e){return e>0&&e<1?`${Math.max(1,Math.round(e*1e3))} MB`:`${e.toFixed(1)} GB`}function $O(e){return`${e.toFixed(1)} GB`}function ek(e){return $(e/QO)}function tk(e){let t=e/1e6;return`${t>=10?Math.round(t):t.toFixed(1)} MB/s`}function nk(e,t){return u(e).meta.dir===`rtl`?g(t,`ltr`):t}function rk(e,t){return e<90?t(`setup.eta.sec`,{n:String(Math.max(1,Math.round(e)))}):e<=7200?t(`setup.eta.min`,{n:String(Math.round(e/60))}):t(`setup.eta.long`)}function ik(e,t){return e<90?t(`setup.eta.secSpoken`,{n:String(Math.max(1,Math.round(e)))}):e<=7200?t(`setup.eta.minSpoken`,{n:String(Math.round(e/60))}):t(`setup.eta.long`)}var ak=5,ok=class{start=null;lastAt=0;lastBytes=0;movedAt=0;speed=0;shownEta=null;shownAt=0;update(e,t,n){if(this.start===null||e<this.lastBytes)return this.start=n,this.lastAt=n,this.lastBytes=e,this.movedAt=n,this.speed=0,this.shownEta=null,{speed:null,eta:null,stalledFor:0};if(this.lastBytes===0&&e>0)return this.lastAt=n,this.lastBytes=e,this.movedAt=n,{speed:null,eta:null,stalledFor:0};let r=(n-this.lastAt)/1e3;if(r>0){let t=(e-this.lastBytes)/r,i=1-Math.exp(-r/ak);this.speed=this.speed===0?t:this.speed+i*(t-this.speed),e>this.lastBytes&&(this.movedAt=n),this.lastAt=n,this.lastBytes=e}let i=(n-this.movedAt)/1e3;if((n-this.start)/1e3<10)return{speed:null,eta:null,stalledFor:i};if(this.speed<=0)return this.shownEta=null,{speed:0,eta:null,stalledFor:i};let a=Math.max(0,t-e)/this.speed;if(this.shownEta===null)this.shownEta=a;else{let e=(n-this.shownAt)/1e3,t=this.shownEta-e;this.shownEta=a<t?this.shownEta-Math.max(e,(this.shownEta-a)/2):a>this.shownEta?this.shownEta+(a-this.shownEta)*.25:a}return this.shownAt=n,{speed:this.speed,eta:Math.max(0,this.shownEta),stalledFor:i}}};function sk(){return Pl(sS)}function ck(e,t=150){let n=sk(),[r,i]=(0,W.useState)(e),a=(0,W.useRef)(e);return(0,W.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 lk(e,t){let[n,r]=(0,W.useState)(e);return(0,W.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function uk(){let[e,t]=(0,W.useState)(()=>typeof document>`u`||document.visibilityState!==`hidden`);return(0,W.useEffect)(()=>{let e=()=>t(document.visibilityState!==`hidden`);return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]),e}var dk=180;function fk({open:e,children:t}){let[n,r]=(0,W.useState)(e),[i,a]=(0,W.useState)(e),o=(0,W.useRef)(t);return e&&(o.current=t),(0,W.useEffect)(()=>{if(e){r(!0);let e=requestAnimationFrame(()=>a(!0));return()=>cancelAnimationFrame(e)}a(!1);let t=setTimeout(()=>r(!1),dk);return()=>clearTimeout(t)},[e]),n?b(`div`,{className:`reveal${i?` is-open`:``}`,"aria-hidden":!e||void 0,children:b(`div`,{className:`reveal-inner`,children:e?t:o.current})}):null}var pk=e=>e?.catalog??[],mk=e=>e.roles.includes(`vision`),hk=e=>e.roles.includes(`embedding`),gk=e=>e.recipe===`flm`;function _k(e){return e.filter(e=>e.gaia_model&&(e.planned||e.recommended||e.downloaded||e.partial))}function vk(e){let t=new Set(_k(e).map(e=>e.id));return e.filter(e=>e.gaia_model&&!t.has(e.id))}function yk(e){return e.filter(e=>!e.gaia_model&&e.downloaded)}function bk(e){let t=pk(e);return{ticked:new Set(t.filter(e=>e.selected||e.gaia_model&&e.downloaded&&!e.skipped).map(e=>e.id)),defaultChat:e.chat_model.id,unticked:new Set,chatChosen:e.chat_model.user_set}}function xk(e,t){return e.filter(e=>e.chat_choice&&(t.has(e.id)||e.downloaded))}function Sk(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=xk(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{ticked:i,defaultChat:s,unticked:a,chatChosen:e.chatChosen}}function Ck(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 wk(e){let t=pk(e),n=new Set(t.filter(e=>e.recommended||e.gaia_model&&e.downloaded).map(e=>e.id)),r=xk(t,n);return{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}}function Tk(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 Ek(e,t){let n=Tk(pk(e),t).map(e=>e.size_gb),r=n.every(e=>e!=null)?Nk(n.reduce((e,t)=>e+t,0)):null,i=e.disk?.free_gb??null;return{downloadGb:r,freeGb:i,afterGb:r!=null&&i!=null?Nk(i-r):null}}function Dk(e,t){let{downloadGb:n,freeGb:r}=Ek(e,t);return n==null||r==null||n<=r?null:{needGb:n,freeGb:r,freeUpGb:Nk(n-r),drop:Tk(pk(e),t).find(e=>e.size_gb!=null&&n-e.size_gb<=r)??null}}function Ok(e,t){return e.filter(e=>e.fits===!1&&(t.ticked.has(e.id)||e.id===t.defaultChat))}function kk(e,t){let n=[];for(let r of pk(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 Ak(e,t){return pk(e).filter(e=>t.ticked.has(e.id)&&!e.planned&&!e.downloaded).map(e=>e.id)}function jk(e,t){return!e?.applies||!e.show_in_setup?!1:(e.models??[]).some(e=>!e.fits_now&&e.fits_at_setting_gb!=null&&(t.ticked.has(e.id)||e.id===t.defaultChat||e.default&&!t.unticked.has(e.id)&&!t.chatChosen))}function Mk(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 Nk(e){return Math.round(e*10)/10}var Pk=6;function Fk(e,t){let n=[];return e.chat_choice&&!hk(e)&&n.push(t(`setup.models.purpose.chat`)),mk(e)&&n.push(t(`setup.models.purpose.vision`)),hk(e)&&n.push(t(`setup.models.purpose.documents`)),n}function Ik(e,t){return hk(e)?t(`setup.models.line.documents`):mk(e)?t(`setup.models.line.vision`):t(`setup.models.line.chat`)}function Lk(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 Rk(e,t){return e.fits!==!0||e.need_gb==null||e.capacity_gb==null?null:t(`setup.models.fit.ok`,{need:$O(e.need_gb),have:$O(e.capacity_gb)})}function zk(e,t){return e.need_gb!=null&&e.capacity_gb!=null?t(`setup.models.warn.tooBig`,{need:$O(e.need_gb),have:$O(e.capacity_gb)}):t(`setup.models.warn.tooBigNoNumbers`,{reason:e.fit_reason??``})}function Bk(e,t,n){return!mk(e)&&!hk(e)?null:n===`settings`?e.downloaded?t(`settings.models.warn.kept`,{name:e.name}):t(mk(e)?`settings.models.warn.vision`:`settings.models.warn.documents`,{name:e.name}):t(mk(e)?`setup.models.warn.vision`:`setup.models.warn.documents`,{name:e.name})}function Vk({entry:e,ticked:t,onToggle:n,disabled:r,progress:i,actions:a,place:o}){let s=J(),c=(0,W.useId)(),l=e.fits===!1,u=t?null:Bk(e,s,o),d=i?.state===`downloading`&&i.bytes_total>0,f=l?zk(e,s):u,p=[`${c}-status`,`${c}-note`,f?`${c}-warn`:null].filter(Boolean).join(` `);return m(`li`,{className:`mc-row${t?` is-ticked`:``}${f?` has-warning`:``}`,children:[m(`div`,{className:`mc-row-top`,children:[m(`label`,{className:`mc-row-main`,children:[b(`input`,{type:`checkbox`,className:`mc-input`,checked:t,disabled:r,onChange:e=>n(e.target.checked),"aria-describedby":p}),b(`span`,{className:`mc-box`,"aria-hidden":`true`,children:b(`svg`,{viewBox:`0 0 16 16`,width:`14`,height:`14`,children:b(`path`,{className:`mc-tick`,d:`M3.5 8.5l3 3 6-7`})})}),m(`span`,{className:`mc-text`,children:[m(`span`,{className:`mc-name-line`,children:[b(`bdi`,{className:`mc-name`,title:e.id,children:e.name}),m(`span`,{className:`mc-chips`,children:[Fk(e,s).map(e=>b(`span`,{className:`mc-chip`,children:e},e)),gk(e)&&b(`span`,{className:`mc-chip is-npu`,children:s(`setup.models.npu`)})]})]}),m(`span`,{className:`mc-status`,id:`${c}-status`,children:[d?s(`setup.models.status.downloading`,{done:ek(i.bytes_done),total:ek(i.bytes_total)}):Lk(e,s),e.recommended&&b(`span`,{className:`mc-pill`,children:s(`setup.models.recommended`)}),e.fits===null&&m(`span`,{className:`mc-chip is-unknown`,children:[b(H,{size:11,"aria-hidden":`true`}),` `,s(`setup.models.fitUnknown`)]})]}),b(`span`,{className:`mc-note`,id:`${c}-note`,children:s.compose(t=>[Ik(e,t),Rk(e,t),e.fits===null?t(`setup.models.fit.unknown`):null].filter(Boolean).join(` `))})]})]}),a&&b(`span`,{className:`mc-actions`,children:a})]}),d&&b(`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`)})}),b(fk,{open:!!f,children:m(`p`,{className:`mc-warn${l?` is-big`:``}`,role:`note`,id:`${c}-warn`,children:[b(Qn,{size:13,"aria-hidden":`true`}),b(`span`,{children:f})]})})]})}function Hk({plan:e,selection:t}){let n=J(),{downloadGb:r,freeGb:i,afterGb:a}=Ek(e,t),o=Dk(e,t),s=ck(r??0),c=ck(a??0),l=Uk(e.disk?.path??null),u=r!=null&&i?Math.min(1,r/i):0,d=lk(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 m(`div`,{className:`mc-summary${o?` is-warn`:``}`,role:`group`,"aria-label":n(`setup.summary.label`),children:[m(`div`,{className:`mc-summary-stats`,children:[m(`span`,{className:`mc-stat`,children:[b(`span`,{className:`mc-stat-label`,children:n(`setup.summary.download`)}),b(`bdi`,{className:`mc-stat-value`,children:r==null?n(`setup.summary.sizeUnknown`):$(Wk(s))})]}),m(`span`,{className:`mc-stat`,children:[m(`span`,{className:`mc-stat-label`,children:[b(Et,{size:12,"aria-hidden":`true`}),` `,l?n(`setup.summary.freeOn`,{drive:l}):n(`setup.summary.free`)]}),b(`bdi`,{className:`mc-stat-value`,children:i==null?n(`setup.summary.freeUnknown`):$(i)})]}),a!=null&&!o&&m(`span`,{className:`mc-stat`,children:[b(`span`,{className:`mc-stat-label`,children:n(`setup.summary.after`)}),b(`bdi`,{className:`mc-stat-value`,children:$(Math.max(0,Wk(c)))})]})]}),i!=null&&b(`div`,{className:`mc-disk`,"aria-hidden":`true`,children:b(`span`,{className:`mc-disk-fill`,style:{inlineSize:`${(u*100).toFixed(1)}%`}})}),b(fk,{open:!!o,children:o&&m(`p`,{className:`mc-disk-warn`,role:`note`,children:[b(Qn,{size:13,"aria-hidden":`true`}),b(`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)})})]})}),b(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:d})]})}function Uk(e){if(!e)return null;let t=/^([A-Za-z]:)[\\/]/.exec(e);return t?t[1]:e}function Wk(e){return Math.round(e*10)/10}function Gk({plan:e,selection:t,onToggle:n,onDefaultChat:r,labelledBy:i,cloud:a,disabled:o,progress:s,rowActions:c,place:l=`setup`}){let u=J(),d=pk(e),[f,p]=(0,W.useState)(``),h=(0,W.useId)(),g=a?d.filter(hk):_k(d),_=a?[]:vk(d),v=a?[]:yk(d),y=(0,W.useMemo)(()=>{let e=f.trim().toLowerCase();return e?v.filter(t=>t.id.toLowerCase().includes(e)||t.name.toLowerCase().includes(e)):v},[v,f]),x=xk(d,t.ticked),S=e=>b(Vk,{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 m(`div`,{className:`mc`,children:[b(`ul`,{className:`mc-list`,role:`group`,"aria-labelledby":i,children:g.map(S)}),a?b(`p`,{className:`setup-hint`,children:u(`setup.models.cloudNote`)}):b(`p`,{className:`mc-foot`,children:u(`setup.models.neverDeletes`)}),_.length>0&&m(`details`,{className:`mc-more`,children:[b(`summary`,{children:u(`setup.models.more`,{n:String(_.length)})}),b(`ul`,{className:`mc-list`,role:`group`,"aria-label":u(`setup.models.moreLabel`),children:_.map(S)})]}),v.length>0&&m(`details`,{className:`mc-more`,children:[b(`summary`,{children:u(`setup.models.installed`,{n:String(v.length)})}),v.length>Pk&&b(`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`)}),b(`ul`,{className:`mc-list`,role:`radiogroup`,"aria-label":u(`setup.models.installedLabel`),children:y.map(e=>b(`li`,{className:`mc-row is-installed${t.defaultChat===e.id?` is-ticked`:``}`,children:m(`label`,{className:`mc-row-main`,children:[b(`input`,{type:`radio`,name:`${h}-installed`,className:`mc-radio`,checked:t.defaultChat===e.id,disabled:o,onChange:()=>r(e.id)}),m(`span`,{className:`mc-text`,children:[m(`span`,{className:`mc-name-line`,children:[b(`bdi`,{className:`mc-name`,title:e.id,children:e.name}),m(`span`,{className:`mc-chips`,children:[b(`span`,{className:`mc-chip`,children:u(`setup.models.purpose.chat`)}),gk(e)&&b(`span`,{className:`mc-chip is-npu`,children:u(`setup.models.npu`)})]})]}),m(`span`,{className:`mc-status`,children:[u(`setup.models.status.onPc`),` · `,u(`setup.models.useAsDefault`)]})]})]})},e.id))})]}),!a&&m(`div`,{className:`mc-default`,children:[b(`label`,{htmlFor:h,className:`mc-default-label`,children:u(`setup.models.defaultChat`)}),m(`select`,{id:h,className:`settings-input mc-select`,value:t.defaultChat??``,disabled:o||x.length===0,onChange:e=>r(e.target.value),children:[x.length===0&&b(`option`,{value:``,children:u(`setup.models.noChat`)}),x.map(e=>m(`option`,{value:e.id,children:[e.name,gk(e)?` (${u(`setup.models.npu`)})`:``]},e.id))]})]})]})}function Kk(){let e=J();return m(`div`,{className:`mc`,"aria-busy":`true`,children:[m(`p`,{className:`setup-hint`,role:`status`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,e(`setup.models.loading`)]}),b(`ul`,{className:`mc-list`,"aria-hidden":`true`,children:[0,1,2].map(e=>b(`li`,{className:`mc-row is-skeleton`,children:b(`span`,{className:`mc-skeleton`})},e))})]})}function qk({title:e,children:t,confirmLabel:n,cancelLabel:r,onConfirm:i,onCancel:a,danger:o,busy:s}){let c=(0,W.useRef)(null),l=(0,W.useRef)(null),u=(0,W.useId)(),d=(0,W.useId)();return FS(c,!0),(0,W.useEffect)(()=>{let e=document.activeElement;return l.current?.focus(),()=>e?.focus?.()},[]),ki(!0,a,!s),(0,OS.createPortal)(b(`div`,{className:`confirm-overlay`,children:m(`div`,{ref:c,className:`confirm-sheet`,role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":u,"aria-describedby":t?d:void 0,children:[b(`h2`,{id:u,className:`confirm-title`,children:e}),t&&b(`div`,{id:d,className:`confirm-body`,children:t}),m(`div`,{className:`confirm-actions`,children:[b(`button`,{ref:l,type:`button`,className:`btn-secondary`,onClick:a,disabled:s,children:r}),b(`button`,{type:`button`,className:o?`btn-danger`:`btn-primary`,onClick:i,disabled:s,children:n})]})]})}),document.body)}function Jk(e){return e===`windows`?`Windows`:e===`linux`?`Linux`:e}function Yk(e){let t=/^Run:\s*(.+)$/.exec(e)??/^(sudo .+)$/.exec(e);return t?t[1].trim():null}function Xk(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 Zk(e,t,n=!1){return t==null?e(n?`gpu.appliedAny`:`gpu.pending.restartAny`):e(n?`gpu.applied`:`gpu.pending.restart`,{gb:$(t)})}function Qk(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 $k(e){return e instanceof Error?e.message:String(e)}function eA({status:e,targetGpuGb:t}){let n=J(),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 m(`div`,{className:`gpu-split`,children:[m(`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:[b(`span`,{className:`gpu-seg is-gpu`,style:{inlineSize:`${u(a)}%`}}),b(`span`,{className:`gpu-seg is-target`,style:{inlineSize:`${u(s)}%`}}),b(`span`,{className:`gpu-seg is-cpu`}),o!=null&&b(`span`,{className:`gpu-marker`,style:{insetInlineStart:`${u(o)}%`}})]}),m(`div`,{className:`gpu-legend`,"aria-hidden":`true`,children:[b(`span`,{className:`gpu-key is-gpu`,children:b(`bdi`,{children:n(`gpu.split.gpu`,{gb:l(a)})})}),o!=null&&b(`span`,{className:`gpu-key is-target`,children:b(`bdi`,{children:n(`gpu.split.added`,{gb:l(s)})})}),b(`span`,{className:`gpu-key is-cpu`,children:b(`bdi`,{children:n(`gpu.split.cpu`,{gb:l(c)})})})]})]})}function tA({presets:e,value:t,onChange:n,disabled:r}){let i=J(),a=(0,W.useRef)([]),o=Math.max(0,e.findIndex(e=>e.setting_gb===t));return b(`div`,{className:`gpu-presets`,role:`radiogroup`,"aria-label":i(`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`,s=(t.key===`ArrowRight`||t.key===`ArrowLeft`)&&i?-r:r,c=(o+s+e.length)%e.length;n(e[c].setting_gb),a.current[c]?.focus()},children:e.map((e,s)=>b(`button`,{ref:e=>{a.current[s]=e},type:`button`,role:`radio`,"aria-checked":e.setting_gb===t,tabIndex:s===o?0:-1,className:`gpu-preset${e.setting_gb===t?` is-active`:``}`,disabled:r,onClick:()=>n(e.setting_gb),children:b(`bdi`,{children:i(`gpu.presets.gpu`,{gb:$(e.gpu_gb)})})},e.setting_gb))})}function nA({status:e,onStatus:t,mode:n,names:r,onSkip:i,onContinue:a,onBack:o,headingId:s}){let c=J(),l=(0,W.useCallback)(()=>{let e=s?document.getElementById(s):null;e&&Qk(e)},[s]);(0,W.useEffect)(()=>{n===`setup`&&l()},[n,l]);let u=(0,W.useId)(),d=e.presets??[],[f,p]=(0,W.useState)(e.recommended_setting_gb??d[0]?.setting_gb??null),[h,g]=(0,W.useState)(!1),[v,y]=(0,W.useState)(null),[x,S]=(0,W.useState)(void 0),[C,w]=(0,W.useState)(null),[T,E]=(0,W.useState)(null),[D,O]=(0,W.useState)(null),[ee,k]=(0,W.useState)(null),A=d.find(e=>e.setting_gb===f)??null,j=(A?.unlocks??[]).slice(0,2).map(e=>r[e]??e),M=e.pending??null,te=e.method===`apply`,N=e.guided_value!==null,ne=(0,W.useCallback)(async()=>{g(!0),y(null),E(`steps`),O(null);try{let e=await Yi(f??void 0);S(e.guided_value),y(e.guided_value===null?[]:e.guided_steps??[])}catch(e){S(void 0),y([]),O({kind:`error`,message:$k(e)})}finally{E(null)}},[f]),re=async()=>{if(f!=null){w(null),E(`apply`),O(null);try{t(await Xi(f)),O({kind:`applied`})}catch(e){let t=e instanceof Ia&&e.httpStatus===403;O(t?{kind:`denied`}:{kind:`error`,message:$k(e)}),t&&l()}finally{E(null)}}},ie=async()=>{w(null),E(`revert`),O(null);try{t(await Zi()),O({kind:`applied`})}catch(e){O(e instanceof Ia&&e.httpStatus===403?{kind:`denied`}:{kind:`error`,message:$k(e)})}finally{E(null)}},P=async()=>{if(f!=null){E(`done`),O(null);try{t(await Qi(f)),g(!1)}catch(e){O({kind:`error`,message:$k(e)})}finally{E(null)}}},F=async()=>{E(`keep`),O(null);try{t(await $i())}catch(e){O({kind:`error`,message:$k(e)})}finally{E(null)}},I=async e=>{try{await navigator.clipboard.writeText(e),k(e)}catch(e){O({kind:`error`,message:c(`gpu.copyFailed`,{reason:$k(e)})})}},ae=M?.state===`restart_required`;return m(`div`,{className:`gpu`,children:[b(`p`,{className:`setup-hint`,children:c(`gpu.body`,{total:$(e.total_gb??0),gpu:$(e.gpu_gb??0)})}),b(eA,{status:e,targetGpuGb:!ae&&!h?A?.gpu_gb??null:null}),M?.state===`took_effect`&&m(`div`,{className:`gpu-notice is-ok`,role:`status`,children:[b(he,{size:14,"aria-hidden":`true`}),b(`span`,{children:c(`gpu.pending.tookEffect`,{gb:$(e.gpu_gb??0)})}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void F(),disabled:T!==null,children:c(`gpu.ok`)})]}),ae&&m(`div`,{className:`gpu-notice`,role:`status`,children:[b(Mt,{size:14,"aria-hidden":`true`}),b(`span`,{children:c.compose(t=>[Zk(t,Xk(e,M.setting_gb),D?.kind===`applied`),t(`gpu.pending.restartHow`),n===`setup`?t(`gpu.pending.downloadsFirst`):null].filter(Boolean).join(` `))}),M.source===`guided`&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void F(),disabled:T!==null,children:c(`gpu.keep`,{gb:$(e.gpu_gb??0)})})]}),M?.state===`not_applied`&&m(`div`,{className:`gpu-notice is-warn`,role:`status`,children:[b(Qn,{size:14,"aria-hidden":`true`}),b(`span`,{children:c(`gpu.pending.notApplied`,{gb:$(e.gpu_gb??0)})}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void F(),disabled:T!==null,children:c(`gpu.keep`,{gb:$(e.gpu_gb??0)})})]}),!ae&&!h&&d.length>0&&m(_.Fragment,{children:[b(tA,{presets:d,value:f,onChange:p,disabled:T!==null}),A&&b(`p`,{className:`gpu-unlock`,children:j.length>0?c(j.length>1?`gpu.unlock.two`:`gpu.unlock.one`,{gb:$(A.gpu_gb),a:j[0],b:j[1]??``}):c(`gpu.unlock.none`,{gb:$(A.gpu_gb)})}),b(`p`,{className:`setup-hint`,children:c.compose(t=>`${t(`gpu.reserve`,{gb:$(e.reserve_gb??16),os:Jk(e.os)})} ${t(`gpu.needs`)}`)}),!te&&e.method_reason&&b(`p`,{className:`setup-hint`,children:e.method_reason})]}),!ae&&!h&&d.length===0&&b(`p`,{className:`setup-hint`,children:c(`gpu.noPresets`)}),h&&m(`div`,{className:`gpu-guided`,children:[A&&b(`p`,{className:`setup-hint`,id:u,children:c(`gpu.guided.lede`,{gb:$(A.gpu_gb)})}),v===null?m(`p`,{className:`setup-hint`,role:`status`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,c(`gpu.guided.loading`)]}):x===null?b(`p`,{className:`setup-hint`,children:c(`gpu.noPresets`)}):b(`ol`,{className:`gpu-steps`,"aria-labelledby":u,children:v.map(e=>{let t=Yk(e);return m(`li`,{children:[b(`span`,{children:e}),t&&m(`button`,{type:`button`,className:`btn-secondary gpu-copy`,onClick:()=>void I(t),"aria-label":c(`gpu.copyAria`,{what:t}),children:[b(ee===t?he:Ie,{size:12,"aria-hidden":`true`}),c(ee===t?`gpu.copied`:`gpu.copy`)]})]},e)})}),m(`div`,{className:`setup-row`,children:[!te&&x!==null&&m(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void P(),disabled:T!==null||f==null,children:[T===`done`&&b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,c(`gpu.guided.done`)]}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>g(!1),disabled:T!==null,children:c(`gpu.guided.back`)})]})]}),T===`apply`||T===`revert`?m(`p`,{className:`setup-hint`,role:`status`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,c(`gpu.waiting`)]}):null,D?.kind===`denied`&&m(`div`,{className:`gpu-notice is-warn`,role:`alert`,children:[b(Qn,{size:14,"aria-hidden":`true`}),b(`span`,{children:c(`gpu.denied`)})]}),D?.kind===`error`&&b(`p`,{className:`setup-error`,role:`alert`,children:D.message}),!h&&m(`div`,{className:`setup-row gpu-actions`,children:[n===`setup`&&o&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:o,children:c(`setup.back`)}),!ae&&te&&d.length>0&&b(`button`,{type:`button`,className:`btn-primary`,onClick:()=>w(`apply`),disabled:T!==null||f==null,children:D?.kind===`denied`||M?.state===`not_applied`?c(`gpu.tryAgain`):c(`gpu.apply`)}),!ae&&d.length>0&&N&&b(`button`,{type:`button`,className:te?`btn-secondary`:`btn-primary`,onClick:()=>void ne(),disabled:T!==null,children:c(`gpu.showMe`)}),n===`settings`&&e.revert?.available&&m(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>w(`revert`),disabled:T!==null,children:[b(wn,{size:13,"aria-hidden":`true`}),` `,c(`gpu.undo`)]}),n===`setup`&&(ae?a&&b(`button`,{type:`button`,className:`btn-primary`,onClick:a,autoFocus:!0,children:c(`setup.continue`)}):i&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:i,disabled:T!==null,children:c(`gpu.skip`)}))]}),C===`apply`&&f!=null&&m(qk,{title:A?c(`gpu.consent.title`,{gb:$(A.gpu_gb)}):c(`gpu.consent.titleAny`),confirmLabel:c(`setup.continue`),cancelLabel:c(`setup.cancel`),onConfirm:()=>void re(),onCancel:()=>w(null),children:[b(`p`,{children:A?c(`gpu.consent.body`,{name:e.setting?.name??``,gb:$(A.gpu_gb)}):c(`gpu.consent.bodyAny`,{name:e.setting?.name??``})}),b(`p`,{className:`confirm-note`,children:c(`gpu.consent.saved`,{gb:$(e.gpu_gb??0)})})]}),C===`revert`&&b(qk,{title:c(`gpu.revert.title`),confirmLabel:c(`setup.continue`),cancelLabel:c(`setup.cancel`),onConfirm:()=>void ie(),onCancel:()=>w(null),children:b(`p`,{children:c(`gpu.revert.body`)})})]})}function rA({label:e,value:t,ok:n}){return m(`li`,{className:`setup-check-row${n?` is-ok`:``}`,children:[b(n?he:Mt,{size:13,"aria-hidden":`true`}),b(`span`,{className:`setup-check-label`,children:e}),b(`span`,{className:`setup-check-value`,children:t})]})}function iA(e){return!!e.gpu_name||!!e.npu_detected||e.lemonade_running}function aA(e){let t=[e.gpu_name,e.npu_detected?`Ryzen AI NPU`:null].filter(Boolean);return t.length?{value:t.join(` · `),ok:!0}:iA(e)?{value:`No GPU or NPU reported; models run on the CPU`,ok:!1}:{value:`Checked once the model server is running`,ok:!1}}function oA({hardware:e,error:t}){if(t)return m(`p`,{className:`setup-hint`,children:[`This PC’s hardware couldn’t be read (`,t,`). Setup still checks it as it goes.`]});if(!e)return m(`p`,{className:`setup-hint`,role:`status`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` Checking this PC…`]});let n=aA(e),r=e.lemonade_running?e.warnings:e.warnings.filter(e=>!/\bNPU\b/.test(e));return m(_.Fragment,{children:[m(`ul`,{className:`setup-check`,"aria-label":`This PC`,children:[b(rA,{label:`Device`,value:n.value,ok:n.ok}),b(rA,{label:`Memory`,value:e.ram_gb==null?`Not reported`:`${e.ram_gb} GB`,ok:e.ram_gb!=null}),b(rA,{label:`Disk`,value:e.disk_free_gb==null?`Not reported`:`${Math.round(e.disk_free_gb)} GB free`,ok:e.disk_free_gb!=null&&e.compatible})]}),!e.compatible&&e.blockers.length>0&&b(`p`,{className:`setup-error`,role:`alert`,children:e.blockers.join(` `)}),r.length>0&&b(`p`,{className:`setup-hint`,children:r.join(` `)})]})}function sA({plan:e,planError:t,onRetryPlan:n,onUseRecommended:r,selection:i,onSelection:a,cloud:o,keepTrying:s,onKeepTrying:c,labelledBy:l,onBack:u,onContinue:d,busy:f,error:p}){let h=J(),g=(0,W.useRef)(null),[_,v]=(0,W.useState)(!1),y=!!e&&!!i&&!!e.catalog,x=(0,W.useRef)(null);if(y&&x.current===null&&(x.current=!o&&Tk(pk(e),i).length===0&&!!i.defaultChat&&pk(e).some(e=>e.downloaded)),(0,W.useEffect)(()=>{y&&g.current?.querySelector(`input:not([disabled])`)?.focus()},[y,_]),t&&!y)return m(`div`,{className:`setup-models-error`,children:[b(`p`,{className:`setup-error`,role:`alert`,children:h(`setup.models.listFailed`,{reason:t})}),m(`div`,{className:`setup-row`,children:[b(`button`,{type:`button`,className:`btn-primary`,onClick:n,children:h(`setup.tryAgain`)}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:r,children:h(`setup.models.useRecommended`)})]}),b(`p`,{className:`setup-hint`,children:h(`setup.models.useRecommendedNote`)})]});if(!y)return b(Kk,{});let S=pk(e),C=Tk(S,i),w=!o&&!i.defaultChat,T=Dk(e,i),E=o?[]:S.filter(e=>e.fits===!1&&i.ticked.has(e.id)),D=!_&&!!x.current&&C.length===0,O=h(T?`setup.continueAnyway`:`setup.continue`);return D?m(`div`,{className:`setup-present`,role:`status`,children:[m(`p`,{children:[b(he,{size:14,"aria-hidden":`true`}),` `,h(`setup.models.allPresent`)]}),m(`div`,{className:`setup-row`,children:[b(`button`,{type:`button`,className:`btn-secondary`,onClick:u,disabled:f,children:h(`setup.back`)}),m(`button`,{type:`button`,className:`btn-primary`,onClick:()=>d(!1),disabled:f,children:[f&&b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,h(`setup.finish`)]}),b(`button`,{type:`button`,className:`link-btn`,onClick:()=>v(!0),children:h(`setup.models.change`)})]}),p&&b(`p`,{className:`setup-error`,role:`alert`,children:p})]}):m(`div`,{className:`setup-models`,ref:g,children:[b(`p`,{className:`setup-hint`,children:h(o?`setup.models.cloudLede`:`setup.models.lede`)}),b(Gk,{plan:e,selection:i,onToggle:(e,t)=>a(Sk(i,S,e,t)),onDefaultChat:e=>a(Ck(i,S,e)),labelledBy:l,cloud:o,disabled:f}),!o&&b(`button`,{type:`button`,className:`link-btn setup-reset`,onClick:()=>a(wk(e)),disabled:f,children:h(`setup.models.resetRecommended`)}),m(`div`,{className:`setup-models-footer`,children:[b(Hk,{plan:e,selection:i}),m(`label`,{className:`setup-keep-trying`,children:[b(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),disabled:f}),b(`span`,{children:h(`setup.keepTrying`)})]}),b(fk,{open:w,children:b(`p`,{className:`setup-error`,id:`setup-no-chat`,children:h(`setup.models.noChatReason`)})}),E.length>0&&b(`span`,{className:`visually-hidden`,children:E.map(e=>zk(e,h)).join(` `)}),p&&b(`p`,{className:`setup-error`,role:`alert`,children:p}),m(`div`,{className:`setup-row setup-nav`,children:[b(`button`,{type:`button`,className:`btn-secondary`,onClick:u,disabled:f,children:h(`setup.back`)}),m(`button`,{type:`button`,className:`btn-primary`,onClick:()=>d(!!T),disabled:f||w,"aria-describedby":w?`setup-no-chat`:void 0,children:[f&&b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,O]})]})]})]})}function cA({plan:e,chatModel:t,gpu:n}){let r=J();if(!e?.catalog)return null;let i=e.catalog,a=e=>e?i.find(t=>t.id===e)?.name??e:null,o=i.find(e=>mk(e)&&e.gaia_model),s=i.find(e=>hk(e)&&e.downloaded),c=i.filter(e=>e.gaia_model&&e.planned&&e.skipped),l=n?.pending,u=i.find(e=>e.id===t);return m(`dl`,{className:`setup-summary-list`,children:[t&&m(`div`,{children:[b(`dt`,{children:r(`setup.ready.chat`)}),m(`dd`,{children:[b(`bdi`,{children:a(t)}),u?.recipe===`flm`?` (${r(`setup.models.npu`)})`:``]})]}),m(`div`,{children:[b(`dt`,{children:r(`setup.ready.vision`)}),b(`dd`,{children:o?.downloaded?b(`bdi`,{children:o.name}):r(`setup.ready.visionOff`,{name:o?.name??`Gemma-4-E4B-it`})})]}),s&&m(`div`,{children:[b(`dt`,{children:r(`setup.ready.documents`)}),b(`dd`,{children:b(`bdi`,{children:s.name})})]}),c.length>0&&m(`div`,{children:[b(`dt`,{children:r(`setup.ready.notInstalled`)}),b(`dd`,{children:c.map(e=>e.name).join(`, `)})]}),l?.state===`restart_required`&&m(`div`,{className:`is-warn`,children:[b(`dt`,{children:r(`setup.ready.gpu`)}),m(`dd`,{children:[b(Qn,{size:13,"aria-hidden":`true`}),` `,Zk(r,n?Xk(n,l.setting_gb):null)]})]}),l?.state===`took_effect`&&m(`div`,{children:[b(`dt`,{children:r(`setup.ready.gpu`)}),b(`dd`,{children:n?.gpu_gb==null?r(`setup.ready.gpuChanged`):r(`setup.ready.gpuNow`,{gb:$(n.gpu_gb)})})]})]})}function lA(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 uA(e,t,n,r){let i=`${n}.one`,a=`${n}.other`,o=y(i)&&y(a)&&typeof r?.n==`number`?r.n===1?i:a:n;return!y(o)||E[o].includes(`{`)&&!r?t:Dc(o,r)===t?e(o,r):t}function dA(e,t){return{title:uA(t,e.title,`card.${e.skill}.title`),note:uA(t,e.note,`card.${e.skill}.note`,lA(e))}}function fA({text:e}){let t=h(e);return t.length===1?b(_.Fragment,{children:e}):b(_.Fragment,{children:t.map((e,t)=>b(`span`,{className:`start-card-part`,children:e},t))})}function pA({cards:e,onPick:t,disabled:n}){let r=J();return e.length===0?null:b(`ul`,{className:`start-cards`,"aria-label":r(`newChat.cardsLabel`),children:e.map(e=>{let{title:i,note:a}=dA(e,r);return b(`li`,{children:m(`button`,{type:`button`,className:`start-card`,onClick:()=>t(e),disabled:n,title:e.needs_input?`${e.prompt}…`:e.prompt,children:[m(`span`,{className:`start-card-title`,children:[i,b(P,{size:13,"aria-hidden":`true`})]}),b(`span`,{className:`start-card-note`,children:b(fA,{text:a})})]})},e.skill)})})}function mA(){let[e,t]=(0,W.useState)(null),n=(0,W.useCallback)(()=>{Promise.resolve(ao()).then(e=>t(e?.providers?.find(e=>e.id===`amd`)?.network??null)).catch(e=>{console.warn(`[useGatewayNetwork] could not check the AMD gateway`,e),t(null)})},[]);return(0,W.useEffect)(n,[n]),{network:e,recheck:n}}var hA=1e9;function gA(e){return e.roles.includes(`embedding`)?0:e.roles.includes(`chat`)?1:2}function _A(e){return[...e].filter(e=>e.state!==`skipped`).sort((e,t)=>gA(e)-gA(t))}var vA={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 yA(e){return e?e.state===`running`||e.state===`verifying`||!!e.models?.some(e=>e.state===`downloading`||e.state===`queued`):!1}function bA(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:ek(e.bytes_done),need:$(a)})}case`verify`:return r(`setup.fail.verify`,{name:t});default:return r(`setup.fail.lemonade`,{name:t})}}function xA({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=J(),h=(0,W.useId)(),g=e.bytes_total>0?Math.min(100,e.bytes_done/e.bytes_total*100):e.state===`ready`?100:0,_=p(vA[e.state]),v=e.retrying_until?Math.max(0,Math.round(e.retrying_until-r/1e3)):0,y=e.state===`downloading`&&!v?n?.stalledFor??0:0,x=e.state===`verifying`&&d||e.state===`downloading`&&!v&&y<15,S;if(e.state===`downloading`){let t=nk(p.locale,e.bytes_total>0?`${ek(e.bytes_done)} / ${ek(e.bytes_total)}`:ek(e.bytes_done));if(v>0)S=p(`setup.progress.retrying`,{n:String(v)});else if(y>=60)S=p(`setup.progress.stuck`);else if(y>=15)S=p(`setup.progress.stalled`,{n:`15`});else if(n?.speed&&n.eta!=null){let{speed:e,eta:r}=n;S=p.compose(n=>`${t} · ${nk(p.locale,tk(e))} · ${rk(r,n)}`)}else S=p.compose(e=>`${t} · ${e(`setup.progress.estimating`)}`)}else S=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?ek(e.bytes_total):``:e.state===`unchecked`?p(`setup.progress.unchecked`):e.state===`cancelled`?e.bytes_done>0?p(`setup.progress.keptPartial`,{done:ek(e.bytes_done)}):``:e.state===`queued`&&e.bytes_total?ek(e.bytes_total):``;let C=e.state===`downloading`?p.compose(t=>[t(`setup.progress.percent`,{n:String(Math.floor(g))}),e.bytes_total?t(`setup.progress.of`,{done:ek(e.bytes_done),total:ek(e.bytes_total)}):null,n?.eta==null?null:ik(n.eta,t)].filter(Boolean).join(`, `)):_;return m(`li`,{className:`dl-row is-${e.state}${x?` is-live`:``}${y>=15?` is-stalled`:``}`,children:[m(`div`,{className:`dl-row-head`,children:[b(`span`,{className:`dl-icon`,"aria-hidden":`true`,children:e.state===`ready`||e.state===`unchecked`?b(he,{size:14}):e.state===`failed`?b(xe,{size:14}):e.state===`cancelled`?b(un,{size:13}):b(`span`,{className:`dl-dot`})}),b(`span`,{className:`dl-name`,children:b(`bdi`,{title:e.id,children:t})}),b(`span`,{className:`dl-state`,children:_}),e.state===`downloading`&&m(`bdi`,{className:`dl-pct`,children:[Math.floor(g),`%`]})]}),b(`div`,{className:`dl-track`,role:`progressbar`,"aria-label":p(`setup.progress.rowLabel`,{name:t,state:_}),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":x&&e.state===`verifying`?void 0:Math.floor(g),"aria-valuetext":C,children:b(`span`,{className:`dl-fill`,style:{inlineSize:`${e.state===`verifying`?100:g}%`}})}),S&&b(`p`,{className:`dl-detail`,children:b(`bdi`,{children:S})}),e.state===`failed`&&m(`div`,{className:`dl-fail`,children:[b(`p`,{className:`dl-error`,id:h,children:bA(e,t,i,p)}),e.error&&m(`details`,{className:`dl-details`,children:[b(`summary`,{children:p(`setup.progress.details`)}),b(`pre`,{children:e.error})]}),u?b(`p`,{className:`dl-detail`,children:p(`setup.progress.retryLater`)}):m(`div`,{className:`setup-row`,children:[a&&m(`button`,{type:`button`,className:`btn-primary`,disabled:l,onClick:()=>a(e.id,e.error_kind),"aria-describedby":h,children:[b(En,{size:13,"aria-hidden":`true`}),` `,p(`setup.progress.retry`)]}),s&&b(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:()=>s(e.id),children:p(`setup.progress.skipModel`)})]})]}),e.state===`cancelled`&&o&&b(`div`,{className:`setup-row`,children:b(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:()=>o(e.id),children:p(`setup.progress.resume`)})}),y>=60&&c&&b(`div`,{className:`setup-row`,children:m(`button`,{type:`button`,className:`btn-secondary`,disabled:l,onClick:c,children:[b(En,{size:13,"aria-hidden":`true`}),` `,p(`setup.progress.retry`)]})})]})}function SA({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=J(),p=uk(),h=(0,W.useMemo)(()=>_A(e.models??[]),[e.models]),g=(0,W.useRef)(new Map),_=(0,W.useRef)(new Map),v=(0,W.useRef)(new ok),y=(0,W.useRef)(!1),[x,S]=(0,W.useState)(()=>Date.now()),[C,w]=(0,W.useState)(!1),[T,E]=(0,W.useState)(null),D=i&&((e,t)=>{let n=h.find(t=>t.id===e);t===`verify`&&n?E(n):i(e,t)}),[O,ee]=(0,W.useState)(``),[k,A]=(0,W.useState)(``),j=(0,W.useRef)(null),M=e.state===`verifying`,te=(0,W.useRef)(new Map);(0,W.useEffect)(()=>{if(!p||!(h.some(e=>e.retrying_until)||M))return;let e=setInterval(()=>S(Date.now()),1e3);return()=>clearInterval(e)},[h,p,M]);let N=e.overall,{estimates:ne,overallEstimate:re}=(0,W.useMemo)(()=>{let e=Date.now(),t={};for(let n of h){if(n.state!==`downloading`){g.current.delete(n.id);continue}let r=g.current.get(n.id),i=n.downloaded_before_gb??null;(!r||_.current.get(n.id)!==i)&&(r=new ok,g.current.set(n.id,r),_.current.set(n.id,i)),t[n.id]=r.update(n.bytes_done,n.bytes_total,e)}let n=h.some(e=>e.state===`downloading`);n&&!y.current&&(v.current=new ok),y.current=n;let r=h.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&&N?v.current.update(N.bytes_done,N.bytes_done+r,e):void 0}},[h,N]);(0,W.useEffect)(()=>{let e=new Map(h.map(e=>[e.id,e.state])),n=Math.floor((N?.percent??0)/25),r=j.current;if(j.current={states:e,quarter:n},!r)return;let i=[];for(let e of h){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(vA[e.state])}))}n>r.quarter&&n>0&&n<4&&i.push(f(`setup.progress.announceOverall`,{n:String(n*25)})),i.length&&ee(i.join(`. `))},[h,N?.percent,t,f]);let ie=e=>{if(!M)return te.current.delete(e),0;let t=Date.now(),n=te.current.get(e)??t;return te.current.set(e,n),Math.floor((t-n)/1e3)},P=yA(e),F=h.filter(e=>e.state===`cancelled`),I=N?.failed??h.filter(e=>e.state===`failed`).length,ae=N?.percent??0,oe=()=>{(N?.bytes_done??0)>hA?w(!0):r?.()},L=f.compose(e=>[e(`setup.progress.overallPct`,{n:String(ae)}),N&&N.bytes_total>0?e(`setup.progress.of`,{done:ek(N.bytes_done),total:ek(N.bytes_total)}):null,P&&re?.speed?nk(f.locale,tk(re.speed)):null,P?re?.eta==null?e(`setup.progress.estimating`):e(`setup.progress.left`,{eta:rk(re.eta,e)}):null,I>0?e(`setup.progress.failedCount`,{n:String(I)}):null].filter(Boolean).join(` · `));return m(`section`,{className:`dl${p?``:` is-paused`}`,"aria-labelledby":d,children:[m(`div`,{className:`dl-overall`,children:[b(`p`,{className:`dl-overall-line`,children:b(`bdi`,{children:L})}),b(`div`,{className:`dl-track is-overall${h.some(e=>e.state===`downloading`)?` is-live`:``}`,role:`progressbar`,"aria-label":f(`setup.progress.overallLabel`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":ae,"aria-valuetext":f(`setup.progress.percent`,{n:String(ae)}),children:b(`span`,{className:`dl-fill`,style:{inlineSize:`${ae}%`}})})]}),b(`ul`,{className:`dl-list`,children:h.map(e=>b(xA,{model:e,name:t[e.id]??e.id,estimate:ne[e.id],now:x,freeGb:n,onRetry:D,onResume:P?void 0:a,onSkip:s,onRestart:c,busy:l,retryLater:u,checking:M,checkingFor:ie(e.id)},e.id))}),m(`div`,{className:`setup-row dl-controls`,children:[P&&r&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:oe,disabled:l,children:f(`setup.progress.cancel`)}),!P&&F.length>1&&o&&b(`button`,{type:`button`,className:`btn-primary`,onClick:o,disabled:l,children:f(`setup.progress.resumeAll`)}),P&&b(`span`,{className:`setup-hint`,children:f(`setup.progress.keepsGoing`)})]}),b(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:O}),b(`span`,{className:`visually-hidden`,role:`alert`,children:k}),C&&b(qk,{title:f(`setup.progress.cancelTitle`),confirmLabel:f(`setup.progress.cancelConfirm`),cancelLabel:f(`setup.progress.cancelKeep`),onConfirm:()=>{w(!1),r?.()},onCancel:()=>w(!1),children:b(`p`,{children:f(`setup.progress.cancelBody`)})}),T&&b(qk,{title:f(`setup.redownload.title`,{name:t[T.id]??T.id}),confirmLabel:f(`setup.redownload.confirm`),cancelLabel:f(`setup.redownload.keep`),onConfirm:()=>{let e=T;E(null),i?.(e.id,`verify`)},onCancel:()=>E(null),children:b(`p`,{children:f(`setup.redownload.body`,{name:t[T.id]??T.id,size:ek(T.bytes_total)})})})]})}var CA=[{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 wA(e,t){return y(e.title)?t(e.title):e.title}var TA=1e3,EA=`gaia-setup-choice`;function DA(){try{let e=localStorage.getItem(EA);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 OA(e){try{localStorage.setItem(EA,e)}catch(e){console.warn(`[SetupScreen] could not save the provider choice; a reload will ask again`,e)}}var kA=[`ok`,`needs_key`,`too_old`];function AA({onChosen:e}){let[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)([]),[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(``),[d,f]=(0,W.useState)(!1),[p,h]=(0,W.useState)(!1),[g,_]=(0,W.useState)(null),[v,y]=(0,W.useState)(null),x=(0,W.useRef)(!0),S=(0,W.useCallback)(async()=>{i(null);try{let e=await no();if(!e.offer)return;c(!0);let{found:t,unchecked:r=[]}=await ro();if(!x.current)return;o(t?[]:r),t&&kA.includes(t.status)&&(n({target:e,found:t}),f(t.status===`needs_key`))}catch(e){x.current&&i(e instanceof Error?e.message:String(e))}finally{x.current&&c(!1)}},[]);(0,W.useEffect)(()=>(x.current=!0,S(),()=>{x.current=!1}),[S]);let C=(0,W.useCallback)(async n=>{if(t){h(!0),_(null);try{await io(n===`external`?{mode:n,base_url:t.found.url,api_key:l.trim()||void 0}:{mode:n}),u(``),y(n),e(n)}catch(e){XO(e)&&f(!0),_(e instanceof Error?e.message:String(e))}finally{h(!1)}}},[t,l,e]);if(r||a.length>0)return m(`div`,{className:`setup-row`,children:[b(`span`,{className:`setup-hint`,children:r?`Couldn't check for a Lemonade Server you already run: ${r}`:`Couldn't check whether your Lemonade Server at ${a.join(` or `)} is running: it didn't answer in time.`}),m(`button`,{type:`button`,className:`btn-secondary`,disabled:s,onClick:()=>void S(),children:[s&&b(U,{size:13,className:`spin`}),` Check again`]})]});if(!t)return s?m(`p`,{className:`setup-hint`,role:`status`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` Looking for a Lemonade Server you already run…`]}):null;let{target:w,found:T}=t;return v?b(`p`,{className:`setup-hint`,role:`status`,children:v===`external`?`GAIA will use your Lemonade Server at ${T.url} and won't install its own.`:`GAIA will set up its own Lemonade Server.`}):T.status===`too_old`?b(`p`,{className:`setup-hint`,children:T.message}):m(`form`,{className:`setup-lemonade`,"aria-label":`Use your Lemonade Server`,onSubmit:e=>{e.preventDefault(),C(`external`)},children:[m(`span`,{className:`setup-choice-title`,children:[`Use the Lemonade you already run at `,T.url,T.version?` (v${T.version})`:``]}),b(`span`,{className:`setup-choice-note`,children:w.what_gaia_does}),d&&b(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,value:l,onChange:e=>u(e.target.value),placeholder:`The API key your Lemonade Server was started with`,"aria-label":`Lemonade API key`}),m(`div`,{className:`setup-row`,children:[m(`button`,{type:`submit`,className:`btn-primary`,disabled:p||d&&!l.trim(),children:[p&&b(U,{size:13,className:`spin`}),` Use mine`]}),b(`button`,{type:`button`,className:`btn-secondary`,disabled:p,onClick:()=>void C(`gaia`),children:`Use GAIA’s own`})]}),g&&b(`p`,{className:`setup-error`,role:`alert`,children:g})]})}function jA({problem:e,onRetry:t,onUseGaia:n}){return m(_.Fragment,{children:[e.start&&b(`p`,{className:`setup-hint`,children:e.start}),m(`div`,{className:`setup-row`,children:[b(`button`,{type:`button`,className:`btn-primary`,onClick:t,children:`Try again`}),e.use_gaia&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:n,children:`Use GAIA’s own instead`})]}),e.use_gaia&&b(`p`,{className:`setup-hint`,children:`GAIA’s own Lemonade Server downloads its own copy of the models.`}),e.switch_hint&&b(`p`,{className:`setup-hint`,children:e.switch_hint})]})}function MA(e){return e instanceof Error?e.message:String(e)}function NA({n:e,status:t,label:n,labelId:r,children:i}){let a=t===`done`?b(he,{size:14,"aria-hidden":`true`}):t===`active`?b(U,{size:14,className:`spin`,"aria-hidden":`true`}):t===`failed`?b(xe,{size:14,"aria-hidden":`true`}):e;return m(`li`,{className:`setup-step is-${t}`,"aria-current":t===`current`||t===`active`?`step`:void 0,children:[m(`div`,{className:`setup-step-head`,children:[b(`span`,{className:`setup-step-num`,children:a}),b(`span`,{className:`setup-step-label`,id:r,tabIndex:r?-1:void 0,children:n})]}),i&&b(`div`,{className:`setup-step-body`,children:i})]})}function PA({onReady:e}){let t=J(),n=nc(e=>e.refresh),r=nc(e=>e.select),[i,a]=(0,W.useState)(()=>DA()??`local`),[o,s]=(0,W.useState)(`where`),[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(null),[h,g]=(0,W.useState)(null),[v,y]=(0,W.useState)(null),[x,S]=(0,W.useState)(``),[C,w]=(0,W.useState)({busy:!1,error:null,done:!1}),[T,E]=(0,W.useState)(!1),[D,O]=(0,W.useState)(null),[ee,k]=(0,W.useState)(null),[A,j]=(0,W.useState)(null),[M,te]=(0,W.useState)(null),[N,ne]=(0,W.useState)(null),[re,ie]=(0,W.useState)(null),[P,F]=(0,W.useState)(!1),[I,ae]=(0,W.useState)(null),[oe,L]=(0,W.useState)(!1),[se,ce]=(0,W.useState)(!1),[le,ue]=(0,W.useState)(null),[de,fe]=(0,W.useState)(!1),[R,z]=(0,W.useState)(!1),[pe,me]=(0,W.useState)(null),[ge,B]=(0,W.useState)([]),[V,ve]=(0,W.useState)(!1),ye=(0,W.useRef)({gaiaLemonade:!1,options:{}}),be=(0,W.useRef)(null),xe=(0,W.useRef)(!0);(0,W.useEffect)(()=>(xe.current=!0,()=>{xe.current=!1}),[]);let{network:Se,recheck:Ce}=mA(),we=e=>e===`amd`&&Se?.reachable===!1,Te=i!==`local`,Ee=!!f?.server_only,H=f&&!f.server_only?f:null,De=f?.state===`running`||f?.state===`verifying`,Oe=H?.state===`ready`,ke=yA(f),Ae=(0,W.useCallback)(()=>{d(null),zi().then(l).catch(e=>d(MA(e)))},[]),je=(0,W.useRef)(0),Ne=(0,W.useCallback)(async()=>{let e=++je.current;k(null);try{let t=await qi();return e===je.current?(O(t),t):null}catch(t){return e===je.current&&k(MA(t)),null}},[]),Pe=(0,W.useCallback)(async()=>{try{let e=await Yi();xe.current&&ie(e??null)}catch(e){console.warn(`[SetupScreen] GPU memory could not be read; the step stays hidden`,e)}},[]);(0,W.useEffect)(()=>{no().then(e=>ve(e.source===`config`)).catch(e=>console.warn(`[SetupScreen] could not read which Lemonade GAIA uses`,e)),Ae(),Ne(),Ki().then(e=>{(e.state!==`idle`||e.models?.length)&&(p(e),e.server_only?(z(!0),e.state!==`ready`&&s(`server`)):s(`download`),e.skip_chat_model&&!DA()&&a(`fireworks`))}).catch(e=>y(`Could not read setup progress: ${MA(e)}`))},[Ae,Ne]),(0,W.useEffect)(()=>{D?.catalog&&D.lemonade.reachable&&(j(e=>e??bk(D)),Pe(),!f&&D.catalog.some(e=>e.partial&&e.selected)&&fe(!0))},[D,Pe,f]);let Fe=(0,W.useCallback)(()=>{be.current&&clearInterval(be.current),be.current=null},[]),Ie=(f?.models??[]).filter(e=>e.state===`failed`&&e.error_kind===`disk_full`).length;(0,W.useEffect)(()=>{Ie>0&&Ne()},[Ie,Ne]);let Le=(0,W.useCallback)(async()=>{try{let e=await Ki();g(null),p(e)}catch(e){g(MA(e))}},[]);(0,W.useEffect)(()=>(!ke&&!h||(be.current=setInterval(()=>{Le()},TA)),Fe),[ke,h,Le,Fe]),(0,W.useEffect)(()=>{Ee&&f?.state===`ready`&&(Ae(),Ne().then(e=>{e?.lemonade.reachable&&s(e=>e===`server`?`models`:e)}))},[Ee,f?.state,Ae,Ne]),(0,W.useEffect)(()=>{Oe&&(Ae(),Ne().then(e=>{e&&ne(e)}),Pe())},[Oe,Ae,Ne,Pe]);let Re=(0,W.useCallback)(async(e=!1,t={})=>{y(null),ue(null),fe(!1);try{OA(i),ye.current={gaiaLemonade:e,options:t};let n=await Vi(Te,e,t);p(n),t.serverOnly?(z(!0),s(`server`)):s(`download`),e&&ve(!1)}catch(e){let t=Ri(e);if(t){ae({kind:`server`,detail:t,then:`run`});return}y(MA(e))}},[i,Te]),ze=(0,W.useCallback)(()=>{let{gaiaLemonade:e,options:t}=ye.current;Re(e,t)},[Re]),Ve=(0,W.useCallback)((e,t=D)=>{te(t);let n=t&&A&&!Te?Ak(t,A):[];Re(!1,{acknowledgeLowDisk:e,keepTrying:P,extraModels:n})},[D,A,Te,P,Re]),[He,Ue]=(0,W.useState)(!1),We=(0,W.useCallback)(async(e,t=oe)=>{if(!D||!A)return;ue(null),Ue(e);let n=pk(D);if(!Te&&!t){let e=Ok(n,A).filter(e=>!e.downloaded||e.id===A.defaultChat);if(e.length>0&&e.every(e=>e.need_gb!=null)){ae({kind:`no_fit`,models:e});return}}ce(!0);try{let n=D;if(!Te&&A.defaultChat&&A.defaultChat!==n.chat_model.id)try{n=await Ji(A.defaultChat,t)}catch(e){let t=Ri(e);if(t){ae({kind:`server`,detail:t,then:`chat`});return}throw e}if(!Te)for(let e of kk(n,A))n=await Ui(e.id,e.skipped);if(O(n),!Te&&jk(re,A)){s(`gpu`);return}Ve(e,n)}catch(e){ue(MA(e))}finally{ce(!1)}},[D,A,Te,oe,re,Ve]),Ge=(0,W.useCallback)(()=>{OA(i),ue(null),!Te&&D&&!D.lemonade.reachable?Re(!1,{serverOnly:!0}):s(`models`)},[i,Te,D,Re]),Ke=(0,W.useCallback)(()=>{ue(null),s(e=>e===`gpu`?`models`:e===`models`?`where`:e)},[]);(0,W.useEffect)(()=>{let e=e=>{e.altKey&&e.key===`ArrowLeft`&&!I&&(o===`models`||o===`gpu`)&&(e.preventDefault(),Ke())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[o,Ke,I]);let qe=(0,W.useCallback)(async()=>{try{await Hi(),await Le()}catch(e){ue(MA(e))}},[Le]),Je=(0,W.useCallback)(async(e,t)=>{ue(null),ce(!0);try{t===`verify`&&await Gi(e),t===`disk_full`&&Ne();try{p(await Wi(e,{keepTrying:P}))}catch(t){let n=Ri(t);if(!n)throw t;ae({kind:`server`,detail:n,then:`retry`,id:e})}}catch(e){ue(MA(e))}finally{ce(!1)}},[P,Ne]),Ye=(0,W.useCallback)(async e=>{ue(null),ce(!0);try{D?.catalog?.find(t=>t.id===e)?.planned&&O(await Ui(e,!0)),p(t=>t&&{...t,models:t.models?.map(t=>t.id===e?{...t,state:`skipped`}:t)})}catch(e){ue(MA(e))}finally{ce(!1)}},[D]),Xe=(0,W.useCallback)(async()=>{await qe(),ze()},[qe,ze]),Ze=(0,W.useCallback)(async()=>{w({busy:!0,error:null,done:!1});try{await lo(i,{api_key:!V&&x||void 0},e=>w({busy:!0,error:null,done:!1,waiting:e}),()=>!xe.current);let{models:e}=await fo(i),t=e.find(e=>e.rank===1)??e[0];if(!t)throw Error(`Connected, but the provider listed no chat models.`);await r(t.id),me(t.id),S(``),w({busy:!1,error:null,done:!0})}catch(e){w({busy:!1,error:MA(e),done:!1})}},[i,x,r,V]),Qe=(0,W.useCallback)(e=>{OA(e),a(e),w({busy:!1,error:null,done:!1})},[]),$e=(0,W.useCallback)(async t=>{await n(),e(t)},[e,n]),et=Oe&&(!Te||C.done),tt=Te?pe:H?.chat_model??(D&&!D.decided_after_server?D.chat_model.id:null);(0,W.useEffect)(()=>{et&&ea().then(e=>B(e.cards)).catch(e=>console.warn(`[SetupScreen] no first tasks to offer`,e))},[et]);let nt=(0,W.useMemo)(()=>{let e={};for(let t of D?.catalog??[])e[t.id]=t.name;return e},[D]),rt=!Te&&(o===`gpu`||!!A&&jk(re,A)),it=!Te&&(R||o===`server`||!!D&&!D.lemonade.reachable&&!H),at=[`check`,`where`,...it?[`server`]:[],`models`,...rt?[`gpu`]:[],`download`,...Te?[`connect`]:[]],ot=e=>at.indexOf(e)+1,st=[`where`,`server`,`models`,`gpu`,`download`,`connect`],ct=st.indexOf(o===`download`&&Oe&&Te?`connect`:o),lt=e=>{let t=st.indexOf(e);return Oe&&e!==`connect`||t<ct?`done`:t===ct?`current`:`pending`},ut=!!u||!!c&&!iA(c),dt=f?.state===`failed`||f?.state===`cancelled`,ft=H&&(H.state===`failed`||H.state===`cancelled`)&&(H.models??[]).length>0&&(H.models??[]).every(e=>e.state===`ready`||e.state===`skipped`||e.state===`verifying`||e.state===`unchecked`)&&!ke,pt=t(et?`setup.lede.done`:f&&De?`setup.lede.running`:`setup.lede.start`);return m(`main`,{className:`setup`,"aria-labelledby":`setup-title`,children:[m(`div`,{className:`setup-inner`,children:[b(`h1`,{id:`setup-title`,className:`setup-title`,children:t(`setup.title`)}),b(`p`,{className:`setup-lede`,children:pt}),de&&o!==`download`&&m(`div`,{className:`setup-banner`,role:`status`,children:[b(Mt,{size:14,"aria-hidden":`true`}),b(`span`,{children:t(`setup.resume.banner`)}),m(`span`,{className:`setup-row`,children:[b(`button`,{type:`button`,className:`btn-primary`,onClick:()=>Ve(!1),children:t(`setup.resume.resume`)}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{fe(!1),s(`models`)},children:t(`setup.models.change`)})]})]}),m(`ol`,{className:`setup-steps`,children:[m(`li`,{className:`setup-step${ut?``:c?` is-done`:` is-current`}`,children:[m(`div`,{className:`setup-step-head`,children:[b(`span`,{className:`setup-step-num`,children:ut?b(Mt,{size:14,"aria-hidden":`true`}):c?b(he,{size:14,"aria-hidden":`true`}):ot(`check`)}),b(`span`,{className:`setup-step-label`,children:t(`setup.check.title`)})]}),o===`where`&&b(`div`,{className:`setup-step-body`,children:b(oA,{hardware:c,error:u})})]}),b(NA,{n:ot(`where`),status:lt(`where`),label:t(`setup.where.title`),children:o===`where`&&m(_.Fragment,{children:[b(AA,{onChosen:e=>{ve(e===`external`),Ae(),Ne()}}),b(`div`,{className:`setup-choices`,role:`radiogroup`,"aria-label":`Where GAIA runs`,children:CA.map(e=>m(`button`,{type:`button`,role:`radio`,"aria-checked":i===e.id,className:`setup-choice${i===e.id?` is-active`:``}${we(e.id)?` is-disabled`:``}`,onClick:()=>a(e.id),disabled:we(e.id),children:[e.id===`local`?b(Be,{size:16,"aria-hidden":`true`}):b(Me,{size:16,"aria-hidden":`true`}),m(`span`,{children:[b(`span`,{className:`setup-choice-title`,children:wA(e,t)}),b(`span`,{className:`setup-choice-note`,children:we(e.id)?Se?.detail:t(e.note)})]})]},e.id))}),Se?.reachable===!1&&b(`button`,{type:`button`,className:`btn-secondary setup-start`,onClick:Ce,children:`Check the AMD gateway again`}),b(`div`,{className:`setup-row setup-nav`,children:b(`button`,{type:`button`,className:`btn-primary setup-start`,onClick:Ge,disabled:we(i),children:t(`setup.continue`)})}),we(i)&&m(`p`,{className:`setup-error`,role:`alert`,children:[Se?.detail,`. Choose another option, or connect and check again.`]}),v&&b(`p`,{className:`setup-error`,role:`alert`,children:v})]})}),it&&m(NA,{n:ot(`server`),status:Ee&&f?.state===`ready`||D?.lemonade.reachable&&o!==`server`?`done`:Ee&&dt?`failed`:o===`server`?`active`:`pending`,label:V?m(_.Fragment,{children:[t(`setup.server.yours`),D?.lemonade.url&&m(`span`,{className:`setup-step-detail`,children:[` — `,b(`bdi`,{children:D.lemonade.url})]})]}):m(_.Fragment,{children:[t(`setup.server.install`),m(`span`,{className:`setup-step-detail`,children:[` — `,t(`setup.server.aboutMinute`)]})]}),children:[o===`server`&&Ee&&De&&b(`p`,{className:`setup-hint`,role:`status`,children:f?.text}),o===`server`&&Ee&&dt&&f&&m(_.Fragment,{children:[b(`p`,{className:`setup-error`,role:`alert`,children:f.error??`Setup stopped.`}),f.problem?b(jA,{problem:f.problem,onRetry:()=>void Re(!1,{serverOnly:!0}),onUseGaia:()=>void Re(!0,{serverOnly:!0})}):m(`div`,{className:`setup-row`,children:[b(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Re(!!f.gaia_lemonade,{serverOnly:!0}),children:`Try again`}),m(`span`,{className:`setup-hint`,children:[`or run `,b(`code`,{children:f.command}),` in a terminal.`]})]})]}),o===`server`&&Ee&&f?.state===`ready`&&m(`p`,{className:`setup-hint`,role:`status`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,t(`setup.models.loading`)]})]}),b(NA,{n:ot(`models`),status:lt(`models`),label:t(`setup.models.title`),labelId:`setup-models-title`,children:o===`models`&&b(sA,{plan:D,planError:ee,onRetryPlan:()=>void Ne(),onUseRecommended:()=>void Re(!1,{keepTrying:P}),selection:A,onSelection:j,cloud:Te,keepTrying:P,onKeepTrying:F,labelledBy:`setup-models-title`,onBack:Ke,onContinue:e=>void We(e),busy:se,error:le??v})}),rt&&b(NA,{n:ot(`gpu`),status:lt(`gpu`),label:t(`gpu.title`),labelId:`setup-gpu-title`,children:o===`gpu`&&re&&m(_.Fragment,{children:[b(nA,{status:re,onStatus:ie,mode:`setup`,headingId:`setup-gpu-title`,names:nt,onBack:Ke,onSkip:()=>Ve(He),onContinue:()=>Ve(He)}),v&&b(`p`,{className:`setup-error`,role:`alert`,children:v})]})}),b(NA,{n:ot(`download`),status:Oe?`done`:o===`download`?dt&&!ft?`failed`:De?`active`:`current`:`pending`,label:t(`setup.download.title`),labelId:`setup-download-title`,children:o===`download`&&H&&m(_.Fragment,{children:[(H.models?.length??0)>0?b(`div`,{className:h?`is-stale`:void 0,children:b(SA,{status:{...H,overall:Mk(H,M??D)},names:nt,freeGb:D?.disk?.free_gb??null,onCancel:()=>void qe(),onRetry:(e,t)=>void Je(e,t),onResume:e=>void Je(e,null),onResumeAll:ze,onSkip:e=>void Ye(e),onRestart:()=>void Xe(),busy:se||!!h,retryLater:De,labelledBy:`setup-download-title`})}):De?m(`p`,{className:`setup-hint`,role:`status`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,H.text]}):null,H.state===`verifying`&&m(`p`,{className:`setup-hint`,role:`status`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,t(`setup.download.verifying`)]}),h&&m(`div`,{className:`setup-row`,role:`alert`,children:[m(`span`,{className:`setup-error`,children:[`Lost contact with GAIA: `,h]}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void Le(),children:t(`setup.reconnect`)})]}),dt&&ft&&H.state===`failed`&&!H.model_failed&&(H.problem?b(jA,{problem:H.problem,onRetry:ze,onUseGaia:()=>void Re(!0,ye.current.options)}):m(`div`,{className:`setup-error`,role:`alert`,children:[b(`p`,{children:t(`setup.download.stoppedBeforeCheck`)}),H.error&&m(`details`,{className:`dl-details`,children:[b(`summary`,{children:t(`setup.progress.details`)}),b(`pre`,{dir:`ltr`,children:H.error})]})]})),dt&&ft&&m(`div`,{className:`setup-row`,children:[b(`button`,{type:`button`,className:`btn-primary`,onClick:ze,disabled:se,children:t(`setup.finish`)}),b(`span`,{className:`setup-hint`,children:t(`setup.download.finishNote`)})]}),dt&&!ft&&!(H.models??[]).some(e=>e.state===`failed`||e.state===`cancelled`)&&m(_.Fragment,{children:[b(`p`,{className:`setup-error`,role:`alert`,children:H.error??`Setup stopped.`}),H.problem?b(jA,{problem:H.problem,onRetry:ze,onUseGaia:()=>void Re(!0,ye.current.options)}):m(`div`,{className:`setup-row`,children:[b(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void Re(!!H.gaia_lemonade,ye.current.options),children:`Try again`}),m(`span`,{className:`setup-hint`,children:[`or run `,b(`code`,{children:H.command}),` in a terminal.`]})]})]}),(le||v)&&b(`p`,{className:`setup-error`,role:`alert`,children:le??v})]})}),Te&&m(`li`,{className:`setup-step${C.done?` is-done`:Oe?` is-current`:` is-pending`}`,children:[m(`div`,{className:`setup-step-head`,children:[b(`span`,{className:`setup-step-num`,children:C.done?b(he,{size:14,"aria-hidden":`true`}):ot(`connect`)}),m(`span`,{className:`setup-step-label`,children:[`Connect `,wA(CA.find(e=>e.id===i)??CA[1],t)]})]}),Oe&&!C.done&&m(`form`,{className:`setup-step-body`,onSubmit:e=>{e.preventDefault(),Ze()},children:[b(`div`,{className:`setup-row`,role:`radiogroup`,"aria-label":`Cloud provider`,children:CA.filter(e=>e.id!==`local`).map(e=>b(`button`,{type:`button`,role:`radio`,"aria-checked":i===e.id,className:i===e.id?`btn-primary`:`btn-secondary`,onClick:()=>Qe(e.id),disabled:C.busy||we(e.id),title:we(e.id)?Se?.detail??void 0:void 0,children:wA(e,t)},e.id))}),b(ZO,{provider:i,limit:3}),V?b(`p`,{className:`setup-hint`,children:`GAIA uses this provider as your Lemonade Server already has it set up. It doesn’t send your server a key or change its setup.`}):b(`p`,{className:`setup-hint`,children:`The key goes to GAIA’s local model server and your OS credential store, nowhere else.`}),m(`div`,{className:`setup-row`,children:[!V&&b(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,value:x,onChange:e=>S(e.target.value),placeholder:`Paste API key (blank uses a key already configured)`,"aria-label":`API key`}),m(`button`,{type:`submit`,className:`btn-primary`,disabled:C.busy,children:[C.busy&&b(U,{size:13,className:`spin`}),` Connect`]})]}),C.busy&&C.waiting&&b(`p`,{className:`setup-hint`,role:`status`,children:C.waiting}),C.error&&b(`p`,{className:`setup-error`,role:`alert`,children:C.error})]})]})]}),f&&f.log_tail&&f.log_tail.length>0&&m(`div`,{className:`setup-log`,children:[m(`button`,{type:`button`,className:`setup-log-toggle`,onClick:()=>E(e=>!e),"aria-expanded":T,children:[b(_e,{size:13,className:T?`is-open`:``,"aria-hidden":`true`}),` Details`]}),T&&b(`pre`,{className:`setup-log-pre`,children:f.log_tail.join(`
77
- `)})]}),et&&m(`div`,{className:`setup-done`,role:`status`,children:[m(`div`,{className:`setup-done-head`,children:[b(`p`,{children:t.compose(e=>[e(`setup.ready.title`),tt?e(Te?`setup.ready.answersCloud`:`setup.ready.answersLocal`,{model:Te?fc(tt):nt[tt]??N?.catalog?.find(e=>e.id===tt)?.name??fc(tt)}):null].filter(Boolean).join(` `))}),b(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void $e(),autoFocus:!0,children:t(`setup.ready.start`)})]}),!Te&&N&&b(cA,{plan:N,chatModel:tt,gpu:re}),ge.length>0&&m(_.Fragment,{children:[b(`p`,{className:`setup-hint`,children:`Or start with one of these:`}),b(pA,{cards:ge,onPick:e=>void $e(e)})]})]})]}),I?.kind===`no_fit`&&b(qk,{title:I.models.length===1?t(`setup.confirm.noFitOne`,{name:I.models[0].name}):t(`setup.confirm.noFitMany`),confirmLabel:t(`setup.confirm.downloadAnyway`),cancelLabel:t(`setup.confirm.pickSmaller`),onConfirm:()=>{ae(null),L(!0),We(He,!0)},onCancel:()=>ae(null),children:I.models.map(e=>m(`p`,{children:[b(`bdi`,{children:e.name}),`: `,zk(e,t)]},e.id))}),I?.kind===`server`&&b(qk,{title:I.detail.code===`low_disk`?t(`setup.confirm.lowDiskTitle`):t(`setup.confirm.noFitServerTitle`),confirmLabel:I.detail.code===`low_disk`?t(`setup.confirm.downloadAnyway`):t(`setup.confirm.useAnyway`),cancelLabel:t(`setup.confirm.changeModels`),onConfirm:()=>{let e=I;if(ae(null),e.then===`chat`)L(!0),We(He,!0);else if(e.then===`retry`)Wi(e.id,{keepTrying:P,acknowledgeLowDisk:!0}).then(p).catch(e=>ue(MA(e)));else{let{gaiaLemonade:e,options:t}=ye.current;Re(e,{...t,acknowledgeLowDisk:!0})}},onCancel:()=>{let e=I;ae(null),e.then!==`retry`&&s(`models`)},children:b(`p`,{children:I.detail.message})})]})}var FA=bl()?`menu bar`:`tray`,IA=[{key:`minimizeToTray`,label:`Keep running when the window closes`,hint:`GAIA stays in the ${FA} with your model loaded. Quit from the ${FA} menu.`},{key:`startOnLogin`,label:`Start GAIA when you sign in`,hint:`Your first chat of the day starts without waiting for GAIA to open.`},{key:`startMinimized`,label:`Start in the ${FA}`,hint:`GAIA opens without its window. Use the ${FA} icon to show it.`}];function LA(){let e=window.gaiaAPI?.tray,[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(null);(0,W.useEffect)(()=>{e&&e.getConfig().then(e=>n(e.tray)).catch(e=>i(`Couldn't read the desktop settings: ${e instanceof Error?e.message:String(e)}`))},[e]);let s=(0,W.useCallback)(async r=>{if(e&&t&&a===null){o(r),i(null);try{let i=await e.setConfig({tray:{[r]:!t[r]}});n(i.tray)}catch(e){i(e instanceof Error?e.message:String(e))}finally{o(null)}}},[e,t,a]);return e?m(`div`,{className:`settings-field`,role:`group`,"aria-labelledby":`desktop-app-label`,children:[b(`span`,{className:`settings-label`,id:`desktop-app-label`,children:`Desktop app`}),IA.map(({key:e,label:n,hint:r})=>m(`div`,{children:[m(`label`,{className:`setting-row`,children:[b(`span`,{children:n}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,role:`switch`,checked:!!t?.[e],"aria-describedby":`desktop-${e}-hint`,onChange:()=>void s(e),disabled:!t||a!==null&&a!==e,"aria-busy":a===e,"aria-label":n}),b(`span`,{className:`toggle-track`})]})]}),b(`p`,{className:`settings-hint`,id:`desktop-${e}-hint`,children:r})]},e)),r&&b(`p`,{className:`settings-error`,role:`alert`,children:r})]}):null}function RA(){return window.gaiaUpdater}var zA={status:`idle`,version:null,progress:0,releaseNotes:null,error:null,currentVersion:null,pinnedVersion:null,autoUpdate:!1,includePrereleases:!1};function BA(){let[e,t]=(0,W.useState)({...zA});return(0,W.useEffect)(()=>{let e=RA();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}function VA(){return window.gaiaUpdater}function HA({onClose:e}){let[t,n]=(0,W.useState)({kind:`loading`}),r=(0,W.useRef)(null);(0,W.useEffect)(()=>{let e=VA();e?e.listReleases().then(e=>{n(Array.isArray(e)?{kind:`list`,releases:e}:{kind:`error`,message:e.error})}).catch(()=>{n({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})}):n({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})},[]),ki(!0,e),FS(r,!0),(0,W.useEffect)(()=>{let e=r.current;e&&e.querySelector(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`)?.focus()},[]),(0,W.useEffect)(()=>{let e=r.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 i(e,t){e.isCurrent||n({kind:`confirm`,release:e,releases:t})}async function a(t){n({kind:`installing`});let r=VA();if(!r)n({kind:`error`,message:`Bridge unavailable — please restart the app.`});else try{await r.installVersion(t.tag),e()}catch(e){let t=e instanceof Error?e.message:String(e);n({kind:`error`,message:`Failed to install that version: ${t}`})}}function o(e){if(!e)return``;try{return new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}catch{return e}}return b(`div`,{className:`version-picker-overlay`,onClick:t=>{t.target===t.currentTarget&&e()},children:m(`div`,{className:`version-picker-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":`Install a specific version`,ref:r,children:[m(`div`,{className:`version-picker-header`,children:[b(`h3`,{children:`Install a specific version`}),b(`button`,{className:`version-picker-close`,onClick:e,"aria-label":`Close`,type:`button`,children:`×`})]}),m(`div`,{className:`version-picker-body`,children:[t.kind===`loading`&&m(`div`,{className:`version-picker-loading`,"aria-busy":`true`,children:[b(`span`,{className:`version-picker-spinner`}),`Loading releases…`]}),t.kind===`error`&&m(`div`,{className:`version-picker-error`,children:[b(`p`,{children:t.message}),b(`p`,{children:b(`a`,{href:`https://github.com/amd/gaia/releases`,target:`_blank`,rel:`noreferrer`,children:`Browse releases on GitHub`})})]}),t.kind===`list`&&b(`ul`,{className:`version-picker-list`,role:`listbox`,"aria-label":`Available releases`,children:t.releases.map(e=>b(`li`,{children:m(`button`,{type:`button`,className:`version-picker-row`,"data-version":e.version,"aria-label":`${e.version}${e.isCurrent?` — installed`:``}${e.isPinned?` — pinned`:``}`,"aria-disabled":e.isCurrent?`true`:`false`,onClick:()=>i(e,t.releases),disabled:e.isCurrent,children:[b(`span`,{className:`vp-version`,children:e.version}),b(`span`,{className:`vp-date`,children:o(e.date)}),e.isCurrent&&b(`span`,{className:`vp-badge vp-badge-current`,children:`Installed`}),e.isPinned&&!e.isCurrent&&b(`span`,{className:`vp-badge vp-badge-pinned`,children:`Pinned`}),!e.isCurrent&&b(`span`,{className:`vp-arrow`,"aria-hidden":`true`,children:`›`})]})},e.tag))}),t.kind===`list`&&m(`p`,{className:`version-picker-more`,children:[`Showing the `,t.releases.length,` most recent.`,` `,b(`a`,{href:`https://github.com/amd/gaia/releases`,target:`_blank`,rel:`noreferrer`,children:`Browse all releases on GitHub`})]}),t.kind===`confirm`&&m(`div`,{className:`version-picker-confirm`,children:[m(`p`,{children:[`This will `,m(`strong`,{children:[`install v`,t.release.version]}),` and restart the app.`]}),m(`p`,{className:`vp-confirm-note`,children:[`GAIA will stay on v`,t.release.version,`: updates are paused until you unpin it in Settings → Updates.`]}),m(`div`,{className:`vp-confirm-actions`,children:[b(`button`,{type:`button`,className:`vp-btn-cancel`,onClick:()=>n({kind:`list`,releases:t.releases}),children:`Back`}),b(`button`,{type:`button`,className:`vp-btn-confirm`,onClick:()=>a(t.release),children:`Install & restart`})]})]}),t.kind===`installing`&&m(`div`,{className:`version-picker-loading`,"aria-busy":`true`,children:[b(`span`,{className:`version-picker-spinner`}),`Starting download…`]})]})]})})}var UA=`Install updates automatically`,WA=`Include release candidates`;function GA(e){return/^\d+\.\d+\.\d+-/.test(e??``)}function KA(e){switch(e.status){case`checking`:return`Checking for updates…`;case`available`:return`GAIA ${e.version??``} is available.`;case`downloading`:return`Downloading GAIA ${e.version??``}… ${e.progress}%`;case`downloaded`:return`GAIA ${e.version??``} is ready — restart to finish installing.`;case`error`:return`Update check failed: ${e.error??`unknown error`}`;case`no-channel`:return e.error??`No GAIA release publishes a desktop update for this platform yet.`;case`disabled`:return`Updates are turned off for this install (GAIA_DISABLE_UPDATE=1).`;default:return`GAIA is up to date.`}}function qA(){let e=BA(),t=RA(),[n,r]=(0,W.useState)(!1),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(!1);if(!t)return null;async function l(e,n){if(t){r(!0),o(null);try{await n(t)}catch(t){i.system.error(`${e} failed`,t),o(`${e} failed: ${t instanceof Error?t.message:String(t)}`)}finally{r(!1)}}}let u=e.status===`disabled`,d=n||e.status===`checking`||e.status===`downloading`;return m(`div`,{className:`settings-field`,role:`group`,"aria-labelledby":`updates-label`,children:[b(`span`,{className:`settings-label`,id:`updates-label`,children:`Updates`}),m(`p`,{className:`settings-hint`,role:`status`,children:[`Running GAIA `,e.currentVersion??`unknown`,`. `,KA(e)]}),m(`label`,{className:`setting-row`,children:[b(`span`,{children:UA}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,role:`switch`,checked:e.autoUpdate,"aria-describedby":`updates-auto-hint`,"aria-label":UA,"aria-busy":n,disabled:u,onChange:()=>{n||l(`Saving the auto-update setting`,t=>t.setAutoUpdate(!e.autoUpdate))}}),b(`span`,{className:`toggle-track`})]})]}),b(`p`,{className:`settings-hint`,id:`updates-auto-hint`,children:`Off by default while GAIA is changing quickly — you choose when to update. The Terminal UI follows the same setting.`}),m(`label`,{className:`setting-row`,children:[b(`span`,{children:WA}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,role:`switch`,checked:!!e.includePrereleases,"aria-describedby":`updates-rc-hint`,"aria-label":WA,"aria-busy":n,disabled:u,onChange:()=>{n||l(`Saving the release-candidate setting`,t=>t.setIncludePrereleases(!e.includePrereleases))}}),b(`span`,{className:`toggle-track`})]})]}),m(`p`,{className:`settings-hint`,id:`updates-rc-hint`,children:[`Also offer test builds (vX.Y.Z-rcN) before they become a final release. Off by default.`,GA(e.currentVersion)&&` This is a release candidate, so newer ones are offered either way.`]}),e.pinnedVersion&&m(`p`,{className:`settings-hint`,children:[`Pinned to `,e.pinnedVersion,`, so updates are paused.`,` `,b(`button`,{type:`button`,className:`btn-secondary`,disabled:n,onClick:()=>void l(`Resuming updates`,e=>e.resumeUpdates()),children:`Unpin`})]}),m(`div`,{className:`setting-actions`,children:[e.status===`available`&&!e.pinnedVersion&&m(`button`,{type:`button`,className:`btn-primary`,disabled:n,onClick:()=>void l(`Downloading the update`,e=>e.downloadUpdate()),children:[`Update to `,e.version]}),e.status===`downloaded`&&b(`button`,{type:`button`,className:`btn-primary`,disabled:n,onClick:()=>void l(`Restarting to install`,e=>e.restart()),children:`Restart to install`}),b(`button`,{type:`button`,className:`btn-secondary`,disabled:d||u,onClick:()=>void l(`Checking for updates`,e=>e.check()),children:`Check for updates`}),b(`button`,{type:`button`,className:`btn-secondary`,disabled:d||u,onClick:()=>c(!0),children:`Install a specific version…`})]}),e.configError&&b(`p`,{className:`settings-error`,role:`alert`,children:e.configError}),a&&b(`p`,{className:`settings-error`,role:`alert`,children:a}),s&&b(HA,{onClose:()=>c(!1)})]})}var JA=[{value:`light`,label:`settings.theme.light`},{value:`dark`,label:`settings.theme.dark`},{value:`system`,label:`settings.theme.system`}],YA={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`},XA=[[`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 ZA(){let e=J(),t=G(e=>e.locale),n=G(e=>e.setLocale),r=G(e=>e.themePreference),i=G(e=>e.setThemePreference),a=G(e=>e.palette),o=G(e=>e.setPalette),s=G(e=>e.customColors),c=G(e=>e.setCustomColors),l=e=>t=>c({...s,[e]:t.target.value.toUpperCase()});return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:e(`settings.section.general`)}),m(`div`,{className:`settings-field`,children:[b(`label`,{className:`settings-label`,htmlFor:`ui-language`,children:e(`settings.language`)}),b(`select`,{id:`ui-language`,className:`settings-input`,value:t,onChange:e=>n(e.target.value),children:x.map(({meta:e})=>b(`option`,{value:e.code,lang:e.code,dir:e.dir,children:p(e)},e.code))}),b(`span`,{className:`settings-hint`,children:e(`settings.languageHint`)})]}),m(`div`,{className:`settings-field`,children:[b(`span`,{className:`settings-label`,id:`appearance-label`,children:e(`settings.appearance`)}),b(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`appearance-label`,children:JA.map(t=>b(`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))})]}),b(LA,{}),b(qA,{}),m(`div`,{className:`settings-field`,children:[b(`span`,{className:`settings-label`,id:`palette-label`,children:e(`settings.colors`)}),m(`div`,{className:`palette-grid`,role:`radiogroup`,"aria-labelledby":`palette-label`,children:[jr.map(t=>m(`button`,{type:`button`,role:`radio`,"aria-checked":a===t.id,className:`palette-tile${a===t.id?` is-active`:``}`,onClick:()=>o(t.id),children:[b(`span`,{className:`palette-swatch`,"aria-hidden":`true`,children:t.swatch.map(e=>b(`i`,{style:{background:e}},e))}),e(YA[t.id])]},t.id)),m(`button`,{type:`button`,role:`radio`,"aria-checked":a===`custom`,className:`palette-tile${a===`custom`?` is-active`:``}`,onClick:()=>o(`custom`),children:[m(`span`,{className:`palette-swatch`,"aria-hidden":`true`,children:[b(`i`,{style:{background:s.base}}),b(`i`,{style:{background:s.accent}})]}),e(`settings.colors.custom`)]})]}),a===`custom`&&m(`div`,{className:`palette-custom`,children:[m(`label`,{className:`palette-color`,htmlFor:`custom-accent`,children:[b(`input`,{id:`custom-accent`,type:`color`,value:s.accent,onChange:l(`accent`)}),m(`span`,{children:[e(`settings.colors.accent`),b(`small`,{children:e(`settings.colors.accentHint`)})]})]}),m(`label`,{className:`palette-color`,htmlFor:`custom-base`,children:[b(`input`,{id:`custom-base`,type:`color`,value:s.base,onChange:l(`base`)}),m(`span`,{children:[e(`settings.colors.base`),b(`small`,{children:e(`settings.colors.baseHint`)})]})]}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>c(Nr),children:e(`settings.colors.reset`)}),b(`p`,{className:`settings-hint`,children:e(`settings.colors.hint`)})]})]}),m(`div`,{className:`settings-field`,children:[b(`span`,{className:`settings-label`,children:e(`settings.shortcuts`)}),b(`dl`,{className:`shortcut-list`,children:XA.map(([t,n])=>m(`div`,{className:`shortcut-row`,children:[b(`dt`,{children:b(`kbd`,{children:wl(t)})}),b(`dd`,{children:e(n)})]},t))})]})]})}var QA=`auto`;function $A({model:e}){let[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(null);(0,W.useEffect)(()=>{n(null),i(null),c(null),po(e).then(n).catch(e=>i(e instanceof Error?e.message:String(e)))},[e]);let l=(0,W.useCallback)(async t=>{o(!0),i(null),c(null);try{let r=await mo(e,t===QA?null:Number(t));n(r);let i=r.chosen?_c(r.chosen):`the automatic size`;r.reload?.started?c(`Reloading ${r.display_name} at ${i}. Chat pauses until it's back.`):r.reload?.reason===`already_loaded`?c(`Saved. ${r.display_name} is already loaded at ${i}, so nothing reloads.`):r.reload?.reason===`warm_up`?c(`Saved. GAIA is getting the model ready for a new chat, so ${r.display_name} switches to ${i} the next time it loads.`):r.reload?.reason===`busy`?c(`Saved. GAIA is answering right now, so ${r.display_name} switches to ${i} the next time it loads.`):r.reload?.reason===`not_gaias_server`?c(`Saved. GAIA doesn't reload models on your own server; ${r.display_name} uses ${i} the next time it loads.`):r.reload?.reason===`restarting`?c(`Saved. A reload is already running; this size applies the next time the model loads.`):c(`Saved. It applies the next time this model loads.`)}catch(e){i(e instanceof Error?e.message:String(e))}finally{o(!1)}},[e]);if(r&&!t)return b(`p`,{className:`settings-error`,role:`alert`,children:r});if(!t)return m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Checking context sizes…`]});let u=t.chosen==null?QA:String(t.chosen),d=t.chosen!=null&&t.loaded_ctx!=null&&t.loaded_ctx!==t.chosen;return m(`div`,{className:`settings-field`,children:[b(`label`,{className:`settings-label`,htmlFor:`ctx-size`,children:`Context size`}),m(`select`,{id:`ctx-size`,className:`settings-input`,value:u,onChange:e=>void l(e.target.value),disabled:a||t.options.length===0,children:[m(`option`,{value:QA,children:[`Automatic`,t.automatic?` (${_c(t.automatic)})`:``]}),t.options.map(e=>m(`option`,{value:String(e),children:[_c(e),` tokens`]},e))]}),m(`span`,{className:`settings-hint`,children:[t.note??(t.max_fit?`Up to ${_c(t.max_fit)}, the most ${t.display_name} can hold on this PC (${t.memory_source}). A larger window uses more memory. GAIA reloads the model to apply it, except on a Lemonade you run yourself.`:null),d&&` Loaded now at ${_c(t.loaded_ctx)}.`]}),a&&m(`span`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Applying…`]}),s&&b(`p`,{className:`settings-ok`,role:`status`,children:s}),r&&b(`p`,{className:`settings-error`,role:`alert`,children:r})]})}function ej({onAdded:e}){let[t,n]=(0,W.useState)(``),[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(null),d=(0,W.useRef)(``),f=(0,W.useCallback)(async e=>{let n=t.trim();d.current=n,c(`check`),u(null);try{let t=await vo(n,e);if(d.current!==n)return;o(t),i(t.file??e)}catch(e){if(d.current!==n)return;o(null),u(e instanceof Error?e.message:String(e))}finally{c(null)}},[t]),p=(0,W.useCallback)(async()=>{c(`add`),u(null);try{let{report:a}=await yo(t.trim(),r);n(``),i(``),o(null),e(a.display_name??a.model_id??`The model`)}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(null)}},[e,r,t]);return m(`form`,{className:`settings-field custom-model-add`,onSubmit:e=>{e.preventDefault(),f(``)},children:[b(`label`,{className:`settings-label`,htmlFor:`custom-model-url`,children:`Add a model from Hugging Face`}),b(`span`,{className:`settings-hint`,children:`Paste the link to a GGUF model. GAIA checks that it is a chat model your model server can run and that it fits this PC before adding it. It downloads when you choose Download.`}),m(`div`,{className:`settings-row`,children:[b(`input`,{id:`custom-model-url`,className:`settings-input`,type:`url`,inputMode:`url`,spellCheck:!1,autoComplete:`off`,value:t,readOnly:s!==null,onChange:e=>{n(e.target.value),o(null),i(``),d.current=``},placeholder:`https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF`}),m(`button`,{type:`submit`,className:`btn-secondary`,disabled:s!==null||!t.trim(),children:[s===`check`?b(U,{size:13,className:`spin`}):null,` Check`]})]}),a&&(()=>{let e=b(`ul`,{className:`custom-model-checks`,"aria-label":`Checks`,children:a.checks.map(e=>m(`li`,{className:e.ok?`is-ok`:`is-failed`,children:[e.ok?b(he,{size:13,"aria-label":`Passed`}):b(cr,{size:13,"aria-label":`Failed`}),m(`span`,{children:[b(`strong`,{children:e.label}),` — `,e.detail]})]},e.id))});return a.ok?m(`details`,{className:`custom-model-checks-summary`,children:[m(`summary`,{children:[b(he,{size:13,"aria-hidden":`true`}),` All `,a.checks.length,` checks passed`]}),e]}):e})(),a&&a.warnings.length>0&&b(`ul`,{className:`custom-model-checks`,"aria-label":`Warnings`,children:a.warnings.map(e=>m(`li`,{className:`is-warning`,children:[b(Qn,{size:13,"aria-label":`Warning`}),` `,b(`span`,{children:e})]},e))}),a&&a.variants.length>1&&m(`div`,{className:`settings-row`,children:[b(`label`,{className:`settings-hint`,htmlFor:`custom-model-quant`,children:`Quantization`}),b(`select`,{id:`custom-model-quant`,className:`settings-input`,value:r,onChange:e=>void f(e.target.value),disabled:s!==null,children:a.variants.map(e=>m(`option`,{value:e.file,children:[e.quant,` · `,e.size_gb,` GB`,e.fits?``:` · too large for this PC`]},e.file))})]}),a?.ok&&m(`div`,{className:`settings-row`,children:[m(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void p(),disabled:s!==null,children:[s===`add`?b(U,{size:13,className:`spin`}):null,` Add `,a.display_name]}),m(`span`,{className:`settings-hint`,children:[a.size_gb,` GB download`]})]}),l&&b(`p`,{className:`settings-error`,role:`alert`,children:l})]})}function tj(e){return e instanceof Error?e.message:String(e)}function nj(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function rj(){let e=J(),[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(null),[p,h]=(0,W.useState)(!1),[g,v]=(0,W.useState)(null),[y,x]=(0,W.useState)(null),S=Nc(e=>e.status),C=Nc(e=>e.started),w=(0,W.useMemo)(()=>Ac(S,C),[S,C]),T=Nc(e=>e.error),E=Nc(e=>e.refresh),D=Nc(e=>e.enqueue),O=Nc(e=>e.cancel),ee=(0,W.useCallback)(async(e=!1)=>{i(null);try{let t=await qi();n(t),o(n=>e||!n?bk(t):n)}catch(e){i(tj(e))}},[]);(0,W.useEffect)(()=>{ee(!0),E(),(async()=>{try{v(await Yi()??null)}catch(e){x(tj(e))}})()},[ee,E]);let k=(w?.models??[]).filter(e=>e.state===`ready`).map(e=>e.id).join(`,`),A=(0,W.useRef)(k);(0,W.useEffect)(()=>{k!==A.current&&(A.current=k,ee(!0))},[k,ee]);let j=(0,W.useMemo)(()=>{let e={};for(let t of w?.models??[])e[t.id]=t;return e},[w]),M=(0,W.useMemo)(()=>{let e={};for(let n of t?.catalog??[])e[n.id]=n.name;return e},[t]),te=(0,W.useMemo)(()=>t?bk(t):null,[t]),N=pk(t),ne=t&&a?Tk(N,a).filter(e=>j[e.id]?.state!==`downloading`):[],re=ne.reduce((e,t)=>e+(t.size_gb??0),0),ie=!!t&&!!a&&!!te&&(!nj(a.ticked,te.ticked)||a.defaultChat!==te.defaultChat||ne.length>0),P=(0,W.useCallback)(async(r,i)=>{if(!t||!a)return;if(f(null),!r){let e=Ok(N,a).filter(e=>!e.downloaded||e.id===a.defaultChat);if(e.length>0&&e.every(e=>e.need_gb!=null)){c({kind:`no_fit`,models:e});return}}let s=Dk(t,a);if(s&&!i)c({kind:`low_disk`,message:s.drop?e(`setup.summary.shortDrop`,{need:$(s.needGb),free:$(s.freeGb),drive:Uk(t.disk?.path??null)??e(`setup.summary.theDrive`),freeUp:$(s.freeUpGb),name:s.drop.name,saves:$(s.drop.size_gb??0)}):e(`setup.summary.short`,{need:$(s.needGb),free:$(s.freeGb),drive:Uk(t.disk?.path??null)??e(`setup.summary.theDrive`),freeUp:$(s.freeUpGb)})});else{u(!0);try{let i=t;if(a.defaultChat&&a.defaultChat!==i.chat_model.id)try{i=await Ji(a.defaultChat,r||p)}catch(e){let t=Ri(e);if(t){c({kind:`server`,detail:t});return}throw e}for(let e of kk(i,a))i=await Ui(e.id,e.skipped);let s=Tk(pk(i),a).map(e=>e.id).filter(e=>j[e]?.state!==`downloading`);n(i),o({...a,defaultChat:i.chat_model.id}),nc.getState().refresh(),s.length&&await D(s,{acknowledgeLowDisk:!0}),f({ok:!0,text:e(`settings.models.applied`)})}catch(e){f({ok:!1,text:tj(e)})}finally{u(!1)}}},[t,a,N,p,j,D,e]),F=(0,W.useCallback)(async t=>{c(null),u(!0),f(null);try{let r=await Gi(t.id);n(r),o(bk(r)),f({ok:!0,text:e(`settings.models.removed`,{name:t.name,size:$(r.freed_gb)})})}catch(e){f({ok:!1,text:tj(e)})}finally{u(!1)}},[e]),I=(0,W.useCallback)((e,t)=>{(async()=>{try{t===`verify`&&await Gi(e),await D([e])}catch(e){f({ok:!1,text:tj(e)})}})()},[D]),ae=!!w&&(w.models?.length??0)>0&&(yA(w)||w.models.some(e=>e.state!==`skipped`));return m(_.Fragment,{children:[m(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-models-title`,children:[b(`span`,{className:`settings-label`,id:`settings-models-title`,children:e(`settings.models.title`)}),b(`p`,{className:`settings-hint`,children:e(`settings.models.lede`)}),r&&b(`p`,{className:`settings-error`,role:`alert`,children:r}),t&&!t.lemonade.reachable&&b(`p`,{className:`settings-hint`,children:e(`settings.models.unavailable`)}),!t&&!r&&m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,e(`setup.models.loading`)]}),t&&t.lemonade.reachable&&a&&m(_.Fragment,{children:[b(Gk,{plan:t,selection:a,onToggle:(e,t)=>o(Sk(a,N,e,t)),onDefaultChat:e=>o(Ck(a,N,e)),labelledBy:`settings-models-title`,place:`settings`,disabled:l,progress:j,rowActions:t=>t.downloaded&&t.id!==a.defaultChat?b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>c({kind:`remove`,entry:t}),disabled:l||j[t.id]?.state===`downloading`,"aria-label":e(`settings.models.removeAria`,{name:t.name}),children:e(`settings.models.remove`)}):null}),b(Hk,{plan:t,selection:a}),b(`div`,{className:`models-apply`,children:m(`button`,{type:`button`,className:`btn-primary`,disabled:!ie||l,onClick:()=>void P(!1,!1),children:[l&&b(U,{size:13,className:`spin`,"aria-hidden":`true`}),l?e(`settings.models.applying`):ne.length>0?e(`settings.models.applyDownload`,{size:$(Math.round(re*10)/10)}):e(`settings.models.apply`)]})})]}),d&&b(`p`,{className:d.ok?`settings-ok`:`settings-error`,role:d.ok?`status`:`alert`,children:d.text})]}),(g?.applies||y)&&m(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-gpu-title`,children:[b(`span`,{className:`settings-label`,id:`settings-gpu-title`,tabIndex:-1,children:e(`gpu.settingsTitle`)}),y&&b(`p`,{className:`settings-error`,role:`alert`,children:y}),g?.applies&&b(nA,{status:g,onStatus:v,mode:`settings`,names:M,headingId:`settings-gpu-title`})]}),ae&&w&&m(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-downloads-title`,children:[b(`span`,{className:`settings-label`,id:`settings-downloads-title`,children:e(`settings.models.downloads`)}),b(SA,{status:w,names:M,freeGb:t?.disk?.free_gb??null,onCancel:()=>void O(),onRetry:I,onResume:e=>void D([e]),onResumeAll:()=>void D((w.models??[]).filter(e=>e.state===`cancelled`).map(e=>e.id))}),T&&b(`p`,{className:`settings-error`,role:`alert`,children:T})]}),s?.kind===`remove`&&b(qk,{title:e(`settings.models.removeTitle`,{name:s.entry.name}),confirmLabel:e(`settings.models.removeConfirm`),cancelLabel:e(`settings.models.keep`),danger:!0,onConfirm:()=>void F(s.entry),onCancel:()=>c(null),children:b(`p`,{children:mk(s.entry)?e(`settings.models.removeVision`,{size:$(s.entry.full_size_gb??0)}):e(`settings.models.removeBody`,{size:$(s.entry.full_size_gb??0)})})}),s?.kind===`no_fit`&&b(qk,{title:s.models.length===1?e(`setup.confirm.noFitOne`,{name:s.models[0].name}):e(`setup.confirm.noFitMany`),confirmLabel:e(`setup.confirm.downloadAnyway`),cancelLabel:e(`setup.confirm.pickSmaller`),onConfirm:()=>{c(null),h(!0),P(!0,!1)},onCancel:()=>c(null),children:s.models.map(t=>m(`p`,{children:[b(`bdi`,{children:t.name}),`: `,zk(t,e)]},t.id))}),s?.kind===`low_disk`&&b(qk,{title:e(`setup.confirm.lowDiskTitle`),confirmLabel:e(`setup.confirm.downloadAnyway`),cancelLabel:e(`setup.confirm.changeModels`),onConfirm:()=>{c(null),P(!0,!0)},onCancel:()=>c(null),children:b(`p`,{children:s.message})}),s?.kind===`server`&&b(qk,{title:e(`setup.confirm.noFitServerTitle`),confirmLabel:e(`setup.confirm.useAnyway`),cancelLabel:e(`setup.confirm.changeModels`),onConfirm:()=>{c(null),h(!0),P(!0,!1)},onCancel:()=>c(null),children:b(`p`,{children:s.detail.message})})]})}function ij(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(!1),c=(0,W.useCallback)(async e=>{s(!0),r(null);try{let n=await e();t(n),a(n.limit_usd==null?``:String(n.limit_usd))}catch(e){r(e instanceof Error?e.message:String(e))}finally{s(!1)}},[]);if((0,W.useEffect)(()=>{c(So)},[c]),!e)return n?b(`p`,{className:`settings-error`,role:`alert`,children:n}):m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Loading this month’s spending…`]});let l=e.limit_usd,u=i.trim()===``?null:Number(i),d=u===null||Number.isFinite(u)&&u>0,f=u!==l;return m(`section`,{className:`settings-field spending`,"aria-label":`Cloud spending`,children:[b(`span`,{className:`settings-label`,children:`Cloud spending this month`}),m(`p`,{className:`spending-total`,children:[b(`strong`,{children:Qw(e.total_usd)}),l!=null&&m(_.Fragment,{children:[` of your `,Qw(l),` limit`]}),m(`span`,{className:`settings-hint`,children:[` · `,e.turns,` cloud `,e.turns===1?`chat turn`:`chat turns`,`, at list price`]})]}),e.unpriced_turns>0&&m(`p`,{className:`settings-hint`,children:[`Plus `,e.unpriced_turns,` `,e.unpriced_turns===1?`turn`:`turns`,` on models with an unknown price, not included above.`]}),e.state===`near`&&m(`p`,{className:`spending-warning`,role:`status`,children:[b(Qn,{size:13,"aria-hidden":`true`}),` Close to your limit. GAIA stops before a cloud chat once it’s reached.`]}),e.state===`reached`&&m(`div`,{className:`spending-warning`,role:`alert`,children:[m(`p`,{children:[b(Qn,{size:13,"aria-hidden":`true`}),` You’ve reached your limit, so cloud chats are stopped until next month. Models on this PC still work.`]}),b(`button`,{type:`button`,className:`btn-secondary`,disabled:o,onClick:()=>void c(wo),children:`Allow more this month`})]}),e.state===`allowed_over`&&b(`p`,{className:`settings-hint`,children:`Over your limit; you allowed more for this month.`}),m(`form`,{className:`settings-row`,onSubmit:e=>{e.preventDefault(),d&&f&&c(()=>Co(u))},children:[b(`label`,{className:`spending-limit-label`,htmlFor:`spend-limit`,children:`Monthly limit ($)`}),b(`input`,{id:`spend-limit`,className:`settings-input`,type:`number`,min:`0.01`,step:`0.01`,inputMode:`decimal`,placeholder:`No limit`,value:i,onChange:e=>a(e.target.value),"aria-invalid":!d}),m(`button`,{type:`submit`,className:`btn-secondary`,disabled:o||!d||!f,children:[o?b(U,{size:13,className:`spin`}):null,` Save`]}),l!=null&&b(`button`,{type:`button`,className:`btn-secondary`,disabled:o,onClick:()=>void c(()=>Co(null)),children:`Remove limit`})]}),b(`span`,{className:`settings-hint`,children:`Counts cloud chats in GAIA’s Agent UI at list price, without cache discounts. Your provider’s bill is the final word. Turns that fail or are stopped before a reply aren’t counted. Models with an unknown price, like the AMD LLM Gateway’s, add nothing to the total, but are stopped too once the limit is reached.`}),n&&b(`p`,{className:`settings-error`,role:`alert`,children:n})]})}var aj=2e3;function oj(e){return e.key_source===`environment`?`Set in ${e.env_var}`:`••••••••••••••••••••${e.key_hint?` ${e.key_hint}`:``}`}function sj(){let e=nc(e=>e.active),t=nc(e=>e.select),n=nc(e=>e.refresh),r=nc(e=>e.rememberNames),[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(null),c=G(e=>e.settingsProvider),[l,u]=(0,W.useState)(c??e?.provider??`local`),[d,f]=(0,W.useState)(null),[p,h]=(0,W.useState)(null),[g,v]=(0,W.useState)(``),[y,x]=(0,W.useState)(!1),[S,C]=(0,W.useState)(``),[w,T]=(0,W.useState)(!1),[E,D]=(0,W.useState)(!1),[O,ee]=(0,W.useState)({base_url:``,auth_header_name:``,auth_header_prefix:``}),[k,A]=(0,W.useState)(null),[j,M]=(0,W.useState)(null),[te,N]=(0,W.useState)(null),[ne,re]=(0,W.useState)(null),ie=(0,W.useRef)(l);ie.current=l;let P=(0,W.useRef)(!0);(0,W.useEffect)(()=>(P.current=!0,()=>{P.current=!1}),[]);let F=i?.find(e=>e.id===l)??null,I=e=>e?.network?.reachable===!1,ae=!!F&&(!F.remote||!!F.models_discovered),oe=(0,W.useCallback)(async()=>{s(null);try{let e=await ao();a(e.providers),e.lemonade_error&&s(e.lemonade_error)}catch(e){s(e instanceof Error?e.message:String(e))}},[]),L=(0,W.useCallback)(async(e,t=!1)=>{t||(f(null),h(null));try{let t=await fo(e);r(t.models),f(t.models),M(t.memory_gb?`${t.memory_gb} GB (${t.memory_source})`:t.capacity_error??null)}catch(e){h(e instanceof Error?e.message:String(e))}},[r]);(0,W.useEffect)(()=>{oe()},[oe]);let se=!!i?.some(e=>e.key_state===`waiting_for_os_permission`);(0,W.useEffect)(()=>{if(!se)return;let e=setInterval(()=>{oe()},aj);return()=>clearInterval(e)},[se,oe]);let ce=e?.provider;(0,W.useEffect)(()=>{ce&&!c&&u(ce)},[ce,c]),(0,W.useEffect)(()=>{C(``),T(!1),D(!1),N(null),v(``),x(!1)},[l]),(0,W.useEffect)(()=>{ae?L(l):f(null)},[l,ae,L]);let le=(0,W.useCallback)(async()=>{if(F){A(`connect`),N(null);try{let e=l===`amd`?{api_key:S||void 0,...Object.fromEntries(Object.entries(O).filter(([,e])=>e!==``))}:{api_key:S||void 0},t=()=>!P.current||ie.current!==l,n=await lo(l,e,e=>{t()||N({ok:!0,text:e})},t);if(t())return;C(``),T(!1),N({ok:!0,text:n.remember_error?`Connected for this session only — the key could not be kept: ${n.remember_error}`:n.known_models?`${F.name} can't list its models right now. Your key still works, so GAIA connected using models it already knows.`:n.remembered?`Connected. The key is kept for next time.`:`Connected.`}),await oe()}catch(e){P.current&&ie.current===l&&N({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{P.current&&A(null)}}},[O,l,S,oe,F]),ue=(0,W.useCallback)(async()=>{A(`forget`),D(!1),N(null);try{await uo(l),N({ok:!0,text:`Key cleared, here and for future sessions. An environment key, if set, stays active.`}),await oe(),await n()}catch(e){N({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{A(null)}},[l,oe,n]),de=(0,W.useCallback)(async e=>{A(e),N(null);try{await t(e),N({ok:!0,text:`New messages use ${ac(e)}. It is remembered across restarts.`})}catch(e){N({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{A(null)}},[t]),fe=(0,W.useCallback)(async e=>{A(`dl:${e}`),N(null);try{await Qa(e),await L(`local`,!0)}catch(e){N({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{A(null)}},[L]),R=(0,W.useCallback)(async e=>{A(`rm:${e}`),N(null);try{let t=await bo(e);re(null);let r=t.cleared.includes(`last_model`)?` New messages use your default model.`:t.cleared.includes(`default_model`)?` It was your default model, so GAIA's own default takes its place.`:``;N({ok:!0,text:`Removed ${t.display_name} and its download.${r}`}),await L(`local`,!0),await n()}catch(e){N({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{A(null)}},[L,n]),z=(0,W.useCallback)(async e=>{N({ok:!0,text:`Added ${e}. Choose Download to fetch it, then Use.`}),await L(`local`,!0)},[L]),pe=!!d?.some(yc);(0,W.useEffect)(()=>{if(l!==`local`||!pe)return;let e=setInterval(()=>{L(`local`,!0)},aj);return()=>clearInterval(e)},[pe,l,L]);let me=(0,W.useMemo)(()=>{let e=g.trim().toLowerCase();return(d??[]).filter(t=>!e||t.id.toLowerCase().includes(e)||(t.display_name??``).toLowerCase().includes(e))},[d,g]),ge=me.filter(e=>e.available!==!1),B=l===`fireworks`&&!y&&!g.trim()&&ge.some(e=>e.rank!==null),V=t=>t.rank!==null||t.id===e?.model,_e=B?ge.filter(V):ge,ve=B?ge.filter(e=>!V(e)):[],ye=me.filter(e=>e.available===!1),be=pc(d??[]),xe=e&&!e.remote&&e.model?e.model:null,Se=t=>{let n=ic(e?.model,t.id),r=yc(t)?t.download_progress:null,i=[gc(t.placement),t.size_gb?`${t.size_gb} GB ${t.downloaded?`on disk`:`download`}`:null,t.tokens_per_second?`${Math.round(t.tokens_per_second)} tok/s measured here`:null,!t.placement&&t.context_length?`Context ${t.context_length.toLocaleString()} tokens`:null].filter(Boolean).join(` · `);return m(`li`,{className:`model-row${n?` is-current`:``}`,children:[m(`div`,{className:`model-row-text`,children:[m(`span`,{className:`model-row-name`,title:t.id,children:[be[t.id],t.rank&&m(`span`,{className:`model-row-rank`,children:[`#`,t.rank,` `,t.note]}),t.state===`loaded`&&b(`span`,{className:`model-badge is-loaded`,children:hc.loaded}),t.fits===!0&&t.available!==!1&&b(`span`,{className:`model-badge is-fit`,children:`Fits this PC`}),t.custom&&b(`span`,{className:`model-badge is-custom`,children:`Added by you`})]}),F?.remote&&b(`span`,{className:`model-row-meta${t.price?``:` is-unknown-price`}`,children:Zw(t.price)}),t.display_name&&b(`span`,{className:`model-row-meta`,children:t.id}),i&&b(`span`,{className:`model-row-meta`,children:i}),t.placement?.warning&&b(`span`,{className:`model-row-meta is-warning`,role:`alert`,children:t.placement.warning}),t.unavailable_reason&&m(`span`,{className:`model-row-meta`,children:[`Can't run here: `,t.unavailable_reason]}),t.evidence&&m(`span`,{className:`model-row-meta`,children:[`Measured: `,t.evidence]}),r&&b(`progress`,{max:100,value:r.percent,"aria-label":`Downloading ${be[t.id]}`}),t.custom&&t.source_url&&m(`span`,{className:`model-row-meta`,children:[`From `,t.source_url]})]}),t.custom&&!n&&!r&&(ne===t.id?m(`span`,{className:`model-row-confirm`,children:[m(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void R(t.id),disabled:k!==null,children:[k===`rm:${t.id}`?b(U,{size:13,className:`spin`}):null,t.downloaded?`Remove and delete download`:`Remove`]}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>re(null),disabled:k!==null,children:`Keep`})]}):b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>re(t.id),disabled:k!==null,"aria-label":`Remove ${be[t.id]}`,children:`Remove`})),n?m(`span`,{className:`model-row-current`,children:[b(he,{size:13,"aria-hidden":`true`}),` In use`]}):t.available===!1?null:r?m(`span`,{className:`model-row-current`,children:[b(U,{size:13,className:`spin`}),` `,Math.round(r.percent),`%`]}):t.downloaded?m(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void de(t.id),disabled:k!==null,"aria-label":`Use ${be[t.id]}`,children:[k===t.id?b(U,{size:13,className:`spin`}):null,` Use`]}):m(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void fe(t.id),disabled:k!==null,"aria-label":`Download ${be[t.id]}`,children:[k===`dl:${t.id}`?b(U,{size:13,className:`spin`}):null,` Download`]})]},t.id)};return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Model`}),b(`p`,{className:`settings-pane-lede`,children:`GAIA runs on this PC by default. Cloud providers are used only when you pick one of their models.`}),b(`div`,{className:`provider-tabs`,role:`radiogroup`,"aria-label":`Where GAIA runs`,children:(i??[{id:`local`,name:`Local`,remote:!1}]).map(e=>m(`button`,{type:`button`,role:`radio`,"aria-checked":l===e.id,className:`provider-tab${l===e.id?` is-active`:``}${I(e)?` is-disabled`:``}`,onClick:()=>u(e.id),disabled:I(e)&&l!==e.id,title:I(e)?e.network?.detail??void 0:void 0,children:[e.remote?b(Me,{size:14,"aria-hidden":`true`}):b(Be,{size:14,"aria-hidden":`true`}),b(`span`,{children:e.name}),e.remote&&e.models_discovered&&b(`span`,{className:`provider-tab-dot`,"aria-label":`connected`})]},e.id))}),o&&b(`p`,{className:`settings-error`,role:`alert`,children:o}),F&&m(`section`,{className:`settings-card`,"aria-label":F.name,children:[b(`p`,{className:`settings-note`,children:F.privacy_notice}),F.id===`local`&&m(`p`,{className:`settings-hint`,children:[`Each model runs where it was built to: GGUF models on the GPU, FLM models on the NPU.`,j&&` Memory for models: ${j}.`]}),F.remote&&!ae&&m(`div`,{className:`settings-field`,children:[b(`span`,{className:`settings-label`,children:`Prices`}),b(ZO,{provider:F.id})]}),I(F)&&m(`div`,{className:`settings-field`,children:[b(`p`,{className:`settings-error`,role:`alert`,children:F.network?.detail}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void oe(),children:`Check again`})]}),F.remote&&!I(F)&&m(`form`,{className:`settings-field`,onSubmit:e=>{e.preventDefault(),le()},children:[m(`div`,{className:`settings-row settings-row-between`,children:[b(`span`,{className:`settings-label`,children:`API key`}),F.key_source&&b(`span`,{className:`settings-key-status ${ae?`settings-ok`:`settings-error`}`,children:ae?`Connected`:`Not connected`})]}),!F.key_source&&b(`span`,{className:`settings-hint`,children:F.key_state===`waiting_for_os_permission`?F.key_message??`Waiting for the OS to allow reading the saved key.`:`No key yet.`}),F.id===`amd`&&(!F.key_source||w)&&m(`div`,{className:`settings-grid`,children:[b(`input`,{className:`settings-input`,placeholder:`Gateway URL (default https://llm-api.amd.com/Unified/v1)`,value:O.base_url,onChange:e=>ee({...O,base_url:e.target.value}),"aria-label":`Gateway URL`}),b(`input`,{className:`settings-input`,placeholder:`Auth header (default Ocp-Apim-Subscription-Key)`,value:O.auth_header_name,onChange:e=>ee({...O,auth_header_name:e.target.value}),"aria-label":`Auth header name`})]}),F.key_source&&!w?m(`div`,{className:`settings-row`,children:[b(`input`,{className:`settings-input settings-key-masked`,readOnly:!0,value:oj(F),"aria-label":`Saved ${F.name} API key`}),!ae&&m(`button`,{type:`submit`,className:`btn-primary`,disabled:k!==null,children:[k===`connect`?b(U,{size:13,className:`spin`}):null,`Reconnect`]}),F.key_source!==`environment`&&(E?m(_.Fragment,{children:[b(`span`,{className:`settings-hint`,children:`Remove this key?`}),b(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void ue(),disabled:k!==null,children:`Remove`}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>D(!1),children:`Keep`})]}):m(_.Fragment,{children:[b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>T(!0),disabled:k!==null,children:`Replace`}),b(`button`,{type:`button`,className:`btn-secondary settings-key-remove`,onClick:()=>D(!0),disabled:k!==null,"aria-label":`Remove key`,title:`Remove key`,children:b(Xn,{size:14,"aria-hidden":`true`})})]}))]}):m(`div`,{className:`settings-row`,children:[b(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,spellCheck:!1,autoFocus:w,value:S,onChange:e=>C(e.target.value),placeholder:w?`Paste your new key`:`Paste API key`,"aria-label":`${F.name} API key`}),m(`button`,{type:`submit`,className:`btn-primary`,disabled:k!==null||!S,children:[k===`connect`?b(U,{size:13,className:`spin`}):null,w?`Save key`:`Connect`]}),w&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{C(``),T(!1)},disabled:k!==null,children:`Cancel`})]}),F.error&&b(`p`,{className:`settings-error`,role:`alert`,children:F.error})]}),te&&b(`p`,{className:te.ok?`settings-ok`:`settings-error`,role:te.ok?`status`:`alert`,children:te.text}),F.known_models&&m(`p`,{className:`settings-hint`,role:`status`,children:[F.name,` can't list its models right now, so GAIA is showing models it already knows. Your key still works, but this list may be out of date.`]}),F.id===`local`&&xe&&e?.downloaded!==!1&&b($A,{model:xe}),ae&&m(`div`,{className:`settings-field`,children:[b(`span`,{className:`settings-label`,children:`Models`}),(d?.length??0)>6&&b(`input`,{className:`settings-input`,type:`search`,value:g,onChange:e=>v(e.target.value),placeholder:`Search models`,"aria-label":`Search models`}),p&&b(`p`,{className:`settings-error`,role:`alert`,children:p}),!d&&!p&&m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Loading…`]}),d&&me.length===0&&b(`p`,{className:`settings-hint`,children:`No models match.`}),b(`ul`,{className:`model-list`,children:_e.map(Se)}),B&&ve.length>0&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>x(!0),children:`Show all models`}),l===`fireworks`&&y&&!g.trim()&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>x(!1),children:`Show recommended models`}),ye.length>0&&m(`details`,{className:`model-unavailable`,children:[m(`summary`,{children:[`Not available on this PC (`,ye.length,`)`]}),b(`ul`,{className:`model-list`,children:ye.map(Se)})]})]}),F.id===`local`&&ae&&b(ej,{onAdded:e=>void z(e)}),F.id===`local`&&ae&&b(rj,{}),F.remote&&b(ij,{})]})]})}function cj(){let e=G(e=>e.sessions),[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(null),l=(0,W.useCallback)(async()=>{c(null);try{let e=await Da();n(e.sessions),i(e.default_mode),G.getState().setDefaultPermissionMode(e.default_mode)}catch(e){c(e instanceof Error?e.message:String(e))}},[]);(0,W.useEffect)(()=>{l()},[l]);let u=(0,W.useCallback)(async e=>{c(null);try{await e(),await l()}catch(e){c(e instanceof Error?e.message:String(e))}},[l]),d=(0,W.useCallback)(async e=>{o(!1),await u(()=>Oa(e))},[u]),f=()=>{r===`full_access`?d(`ask`):o(e=>!e)},p=t=>e.find(e=>e.id===t)?.title??t;return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Permissions`}),b(`p`,{className:`settings-pane-lede`,children:`GAIA asks before it changes files, runs commands, or uses tools that act on your behalf. Pick a mode per chat from the shield next to the message box. “Always allow” covers one exact action in one chat and ends when GAIA restarts.`}),m(`section`,{className:`settings-card`,"aria-label":`New chats`,children:[m(`label`,{className:`setting-row`,children:[b(`span`,{className:`settings-label`,children:`Start new chats in full access`}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,checked:r===`full_access`,onChange:f,disabled:r===null,"aria-label":`Start new chats in full access`}),b(`span`,{className:`toggle-track`})]})]}),b(`p`,{className:`settings-hint`,children:r===`full_access`?`On. Every new chat runs commands and changes files without asking. Chats already open keep their mode.`:`Off. New chats ask before they change files or run commands. Chats already open keep their mode.`}),a&&m(`div`,{className:`settings-warning`,role:`alert`,children:[m(`p`,{children:[`Full access lets GAIA change or delete files and run commands on this PC without asking you first, in every new chat, until you turn this off. A mistake or a bad instruction in a document it reads can do real damage. This is the same setting as the TUI’s`,b(`code`,{children:` /full-access always`}),`.`]}),m(`div`,{className:`settings-row`,children:[b(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void d(`full_access`),children:`Turn on full access for new chats`}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>o(!1),children:`Cancel`})]})]})]}),s&&b(`p`,{className:`settings-error`,role:`alert`,children:s}),t&&t.length===0&&b(`p`,{className:`settings-hint`,children:`No chat has full access or anything allowed without asking.`}),t?.map(e=>m(`section`,{className:`settings-card`,"aria-label":p(e.session_id),children:[m(`div`,{className:`settings-row settings-row-between`,children:[b(`span`,{className:`settings-label`,children:p(e.session_id)}),e.mode===`full_access`&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>u(async()=>{let t=(await ka(e.session_id,`ask`)).mode;vT(e.session_id,t)}),children:`Turn off full access`})]}),e.grants.length>0&&b(`ul`,{className:`grant-list`,children:e.grants.map(t=>m(`li`,{className:`grant-row`,children:[b(`code`,{children:t.label}),b(`button`,{type:`button`,className:`link-btn`,onClick:()=>u(()=>Aa(e.session_id,t.key)),"aria-label":`Revoke ${t.label}`,children:`Revoke`})]},t.key))}),e.grants.length>1&&b(`button`,{type:`button`,className:`link-btn`,onClick:()=>u(()=>Aa(e.session_id)),children:`Revoke all in this chat`})]},e.session_id))]})}var lj=[{source:`agent-bundled`,title:`Built into GAIA`,note:`Ship with GAIA.`},{source:`user`,title:`Yours`,note:`From your ~/.gaia/skills folder.`,empty:`None yet. Add a folder with a SKILL.md file to ~/.gaia/skills and reopen this page.`},{source:`claude-project`,title:`From this project`,note:`In the .claude/skills folder of the project GAIA is working in. Their instructions load; any tools or commands they ask for stay off until you import them.`},{source:`claude-import`,title:`From Claude Code`,note:`Found in your Claude Code skill folders. GAIA reads them in place and does not change them.`}];function uj({onUseSkill:e}){let[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)({}),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(``);(0,W.useEffect)(()=>{let e=!1;return To().then(t=>{e||(n(t.skills),i(t.invalid))}).catch(t=>{e||o(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let l=s.trim().toLowerCase(),u=(t??[]).filter(e=>!l||e.name.toLowerCase().includes(l)||e.description.toLowerCase().includes(l)),d=t?.every(e=>lj.some(t=>t.source===e.source))??!1,f=t=>m(`li`,{className:`skill-row`,children:[m(`div`,{className:`skill-row-text`,children:[m(`span`,{className:`skill-row-name`,children:[t.name,t.version&&m(`span`,{className:`skill-row-meta`,children:[` v`,t.version]}),t.always_on&&b(`span`,{className:`skill-row-meta`,children:` · Always on`})]}),b(`span`,{className:`skill-row-desc`,children:t.description})]}),!t.always_on&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>e(t.name),"aria-label":`Use ${t.name} in a new chat`,children:`Use`})]},t.name);return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Skills`}),m(`p`,{className:`settings-pane-lede`,children:[`Skills teach GAIA a job — a workflow, a CLI, a document type. GAIA loads one when a request needs it, and keeps the lessons it learns while using it. Your own skills go in `,b(`code`,{children:`~/.gaia/skills`}),`, one folder each with a `,b(`code`,{children:`SKILL.md`}),` file.`]}),a&&b(`p`,{className:`settings-error`,role:`alert`,children:a}),!t&&!a&&m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Loading…`]}),t&&t.length>6&&b(`input`,{className:`settings-input`,type:`search`,value:s,onChange:e=>c(e.target.value),placeholder:`Search skills`,"aria-label":`Search skills`}),t&&t.length===0&&b(`p`,{className:`settings-hint`,children:`No skills are installed.`}),d?lj.map(e=>{let n=u.filter(t=>t.source===e.source),r=(t??[]).filter(t=>t.source===e.source).length;return n.length===0&&(l||!e.empty)?null:m(`section`,{className:`skill-group`,"aria-label":e.title,children:[m(`h3`,{className:`skill-group-title`,children:[e.title,` `,b(`span`,{className:`skill-row-meta`,children:r})]}),b(`p`,{className:`settings-hint`,children:e.note}),n.length===0?b(`p`,{className:`settings-hint`,children:e.empty}):b(`ul`,{className:`skill-list`,children:n.map(f)})]},e.source)}):b(`ul`,{className:`skill-list`,children:u.map(f)}),Object.keys(r).length>0&&m(`div`,{className:`settings-card`,role:`alert`,children:[b(`span`,{className:`settings-label`,children:`Skipped, could not be read`}),b(`ul`,{className:`grant-list`,children:Object.entries(r).map(([e,t])=>m(`li`,{children:[b(`code`,{children:e}),` — `,t]},e))})]})]})}function dj(){let e=G(e=>e.setShowMemoryDashboard),t=G(e=>e.closeSettings),[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(!1);(0,W.useEffect)(()=>{TO().then(r).catch(e=>a(e instanceof Error?e.message:String(e)))},[]);let c=(0,W.useCallback)(async()=>{if(n){s(!0),a(null);try{r(await EO({memory_enabled:!n.memory_enabled}))}catch(e){a(e instanceof Error?e.message:String(e))}finally{s(!1)}}},[n]);return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Memory`}),b(`p`,{className:`settings-pane-lede`,children:`GAIA remembers facts, preferences and past conversations across chats, on this PC only. Private chats (the eye icon in a chat) are never remembered.`}),m(`label`,{className:`setting-row`,children:[b(`span`,{children:`Remember across chats`}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,checked:!!n?.memory_enabled,onChange:()=>void c(),disabled:!n||o,"aria-label":`Remember across chats`}),b(`span`,{className:`toggle-track`})]})]}),i&&b(`p`,{className:`settings-error`,role:`alert`,children:i}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{t(),e(!0)},children:`Open the memory dashboard`}),b(`p`,{className:`settings-hint`,children:`Search, edit and forget what GAIA remembers.`})]})}var fj=`Keep for: enter a whole number of days from 1 to 365.`,pj=`Use at most: enter a whole number of MB from 10 to 100,000.`;function mj(e,t,n){if(!/^\d+$/.test(e.trim()))return!1;let r=Number(e);return r>=t&&r<=n}function hj(e){return e<1048576?`${Math.ceil(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}function gj(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(``),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(null),[c,l]=(0,W.useState)(!1);(0,W.useEffect)(()=>{Ns().then(e=>{t(e),r(String(e.retention_days)),a(String(e.max_mb))},e=>s({ok:!1,text:`Could not read undo history settings: ${e instanceof Error?e.message:e}`}))},[]);let[u,d]=(0,W.useState)({days:!1,mb:!1}),f=!mj(n,1,365)||u.days,p=!mj(i,10,1e5)||u.mb,h=e!==null&&(n!==String(e.retention_days)||i!==String(e.max_mb)),g=async()=>{if(!(f||p)){l(!0),s(null);try{let e=await Ps(Number(n),Number(i));t(e),s({ok:!0,text:`Saved. Older undo history beyond these limits was removed.`})}catch(e){let t=e instanceof Ia&&e.httpStatus===422?e.fields:[],n=t.includes(`retention_days`),r=t.includes(`max_mb`);n||r?(d({days:n,mb:r}),s({ok:!1,text:`Not saved. Fix the limit marked above.`})):s({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{l(!1)}}};return m(`div`,{className:`settings-field`,"aria-label":`Undo history`,children:[b(`span`,{className:`settings-label`,children:`Undo history`}),b(`p`,{className:`settings-hint`,children:`Before GAIA changes a file it keeps a copy, so you can undo a turn. Copies older than the time limit, or past the space limit (oldest first), are deleted. The space limit never deletes the latest turn.`}),e&&m(_.Fragment,{children:[m(`div`,{className:`setting-row`,children:[b(`label`,{htmlFor:`undo-days`,children:`Keep for (days)`}),b(`input`,{id:`undo-days`,type:`number`,className:`model-input undo-history-input`,min:1,max:365,value:n,"aria-invalid":f,"aria-describedby":f?`undo-days-error`:void 0,onChange:e=>{r(e.target.value),d(e=>({...e,days:!1}))}})]}),f&&b(`p`,{id:`undo-days-error`,className:`settings-error`,children:fj}),m(`div`,{className:`setting-row`,children:[b(`label`,{htmlFor:`undo-mb`,children:`Use at most (MB)`}),b(`input`,{id:`undo-mb`,type:`number`,className:`model-input undo-history-input`,min:10,max:1e5,value:i,"aria-invalid":p,"aria-describedby":p?`undo-mb-error`:void 0,onChange:e=>{a(e.target.value),d(e=>({...e,mb:!1}))}})]}),p&&b(`p`,{id:`undo-mb-error`,className:`settings-error`,children:pj}),m(`div`,{className:`setting-row setting-row-path`,children:[b(`span`,{children:`In use`}),m(`span`,{children:[hj(e.used_bytes),` for `,e.turns,` turn`,e.turns===1?``:`s`,` `,`in `,b(`code`,{className:`setting-path`,children:e.path})]})]}),b(`button`,{type:`button`,className:`btn-model-save`,onClick:()=>void g(),disabled:!h||c||f||p,children:c?`Saving…`:`Save`})]}),o&&b(`p`,{className:o.ok?`settings-ok`:`settings-error`,role:o.ok?`status`:`alert`,children:o.text})]})}function _j(){let e=G(e=>e.sessions),t=G(e=>e.removeSession),n=lc(),r=G(e=>e.systemStatus?.data_dir),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(null),c=(0,W.useRef)(null);(0,W.useEffect)(()=>()=>{c.current&&clearTimeout(c.current)},[]);let l=(0,W.useCallback)(async()=>{if(!i){a(!0),c.current=setTimeout(()=>a(!1),4e3);return}a(!1);let n=[];for(let r of e)try{await ko(r.id),t(r.id)}catch(e){n.push(`${r.title}: ${e instanceof Error?e.message:e}`)}s(n.length?{ok:!1,text:`Could not delete ${n.length} chat(s): ${n.join(`; `)}`}:{ok:!0,text:`All chats deleted.`})},[i,t,e]);return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Privacy`}),m(`p`,{className:`settings-pane-lede`,children:[`Chats, documents and memory stay on this PC. `,n?.remote?`Right now answers come from ${n.label}, so each message and the chat history are sent there.`:n?`Right now answers are generated on this PC too.`:`GAIA can't tell right now whether answers are generated on this PC or by a cloud provider.`]}),r&&m(`div`,{className:`setting-row`,children:[b(`span`,{children:`Data folder`}),b(`code`,{className:`setting-path`,children:r})]}),b(gj,{}),b(`div`,{className:`danger-divider`}),b(`p`,{className:`danger-warning`,children:`Deletes every chat and its messages. Documents and memory are kept.`}),b(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void l(),disabled:e.length===0,children:i?`Click again to delete all chats`:`Delete all chats`}),o&&b(`p`,{className:o.ok?`settings-ok`:`settings-error`,role:o.ok?`status`:`alert`,children:o.text})]})}var vj=[{id:`needs_approval`,label:`Needs your approval`},{id:`question`,label:`Has a question`},{id:`finished`,label:`Finished`}],yj=[{value:`banner`,label:`Banner`},{value:`badge`,label:`Badge`},{value:`off`,label:`Off`}],bj=[0,10,20,30,50];function xj(){return typeof Notification>`u`?`unsupported`:Notification.permission}function Sj(){let e=il(),t=!!window.gaiaAPI,[n,r]=(0,W.useState)(xj),i=Object.values(e.modes).includes(`banner`);return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Notifications`}),b(`p`,{className:`settings-pane-lede`,children:`When a chat you aren't looking at needs you or finishes. A banner also counts on the badge.`}),vj.map(t=>m(`div`,{className:`setting-row`,children:[b(`span`,{id:`alert-${t.id}`,children:t.label}),b(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`alert-${t.id}`,children:yj.map(n=>b(`button`,{type:`button`,role:`radio`,"aria-checked":e.modes[t.id]===n.value,className:e.modes[t.id]===n.value?`is-active`:``,onClick:()=>e.setMode(t.id,n.value),children:n.label},n.value))})]},t.id)),!t&&i&&n!==`granted`&&(n==="default"?b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{Notification.requestPermission().then(r).catch(e=>{console.error(`[alerts] Notification permission request failed`,e),r(xj())})},children:`Allow banners in this browser`}):b(`p`,{className:`settings-error`,role:`alert`,children:n===`unsupported`?`This browser can't show banners; alerts appear in the chat list only.`:`This browser blocks banners from GAIA. Allow notifications for this site in the browser’s site settings.`})),m(`label`,{className:`setting-row`,children:[b(`span`,{children:`Play a sound`}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,checked:e.sound,onChange:()=>e.update({sound:!e.sound}),"aria-label":`Play a sound`}),b(`span`,{className:`toggle-track`})]})]}),t&&m(`label`,{className:`setting-row`,children:[b(`span`,{children:`Flash the taskbar when GAIA isn't focused`}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,checked:e.flash,onChange:()=>e.update({flash:!e.flash}),"aria-label":`Flash the taskbar when GAIA isn't focused`}),b(`span`,{className:`toggle-track`})]})]}),b(`h3`,{className:`settings-label`,children:`Keep awake`}),t?m(_.Fragment,{children:[m(`label`,{className:`setting-row`,children:[b(`span`,{children:`Keep the PC awake while GAIA works`}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,checked:e.keepAwake,onChange:()=>e.update({keepAwake:!e.keepAwake}),"aria-label":`Keep the PC awake while GAIA works`}),b(`span`,{className:`toggle-track`})]})]}),m(`div`,{className:`setting-row`,children:[b(`label`,{htmlFor:`battery-floor`,children:`On battery, let it sleep below`}),b(`select`,{id:`battery-floor`,value:e.batteryFloor,disabled:!e.keepAwake,onChange:t=>e.update({batteryFloor:Number(t.target.value)}),children:bj.map(e=>b(`option`,{value:e,children:e===0?`Never`:`${e}%`},e))})]}),b(`p`,{className:`settings-hint`,children:`The screen can still turn off; only sleep is held off.`})]}):b(`p`,{className:`settings-hint`,children:`Keep-awake needs the GAIA desktop app.`})]})}var Cj=`modulepreload`,wj=function(e,t){return new URL(e,t).href},Tj={},Ej=function(e){return e.pathname.endsWith(`.css`)},Dj=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},Oj=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=wj(t,n);let r=s(t),i=Ej(r);return Dj(Tj,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`:Cj,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)})},kj=(0,W.lazy)(()=>Oj(()=>import(`./ConnectorsPane-B71QL-Kl.js`).then(e=>({default:e.ConnectorsPane})),__vite__mapDeps([0,1,2,3]),import.meta.url)),Aj=(0,W.lazy)(()=>Oj(()=>import(`./AdvancedSettings-B4MY5XPH.js`).then(e=>({default:e.AdvancedSettings})),__vite__mapDeps([4,1,2]),import.meta.url)),jj=[`general`,`model`,`permissions`,`skills`,`connectors`,`memory`,`notifications`,`privacy`,`advanced`];function Mj({onUseSkill:e}){let t=J(),n=G(e=>e.settingsSection),r=G(e=>e.openSettings),i=G(e=>e.closeSettings),a=(0,W.useRef)(null),o=(0,W.useRef)(null),s=n!==null;if(ki(s,i),FS(a,s),(0,W.useEffect)(()=>{if(s)return o.current=document.activeElement,()=>{o.current?.focus?.()}},[s,i]),(0,W.useEffect)(()=>{s&&a.current?.querySelector(`.settings-nav-item.is-active`)?.focus()},[s]),!n)return null;let c=(()=>{switch(n){case`general`:return b(ZA,{});case`model`:return b(sj,{});case`permissions`:return b(cj,{});case`skills`:return b(uj,{onUseSkill:t=>{i(),e(t)}});case`connectors`:return b(kj,{});case`memory`:return b(dj,{});case`notifications`:return b(Sj,{});case`privacy`:return b(_j,{});case`advanced`:return b(Aj,{})}})();return b(`div`,{className:`settings-overlay`,onMouseDown:e=>{e.target===e.currentTarget&&i()},children:m(`div`,{ref:a,className:`settings-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`settings.title`),children:[m(`nav`,{className:`settings-nav`,"aria-label":t(`settings.sections`),children:[b(`h1`,{className:`settings-nav-title`,children:t(`settings.title`)}),jj.map(e=>b(`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))]}),m(`div`,{className:`settings-body`,children:[b(`button`,{type:`button`,className:`settings-close`,onClick:i,"aria-label":t(`settings.close`),children:b(cr,{size:18})}),b(`div`,{className:`settings-scroll`,children:b(W.Suspense,{fallback:m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),children:c})})]})]})})}function Nj(e,t){let[n,r]=(0,W.useState)(!1),[a,o]=(0,W.useState)(!1),s=(0,W.useRef)(null),c=(0,W.useRef)(null),l=(0,W.useRef)(null),u=(0,W.useCallback)(()=>{s.current&&=(clearTimeout(s.current),null),c.current&&=(clearTimeout(c.current),null),l.current&&=(clearInterval(l.current),null)},[]);(0,W.useEffect)(()=>u,[u]);let d=(0,W.useCallback)((e,t)=>{l.current&&clearInterval(l.current),l.current=setInterval(async()=>{try{let n=await Ua();t===`load`?n.model_loaded?.toLowerCase()===e.toLowerCase()&&(r(!1),s.current&&=(clearTimeout(s.current),null),l.current&&=(clearInterval(l.current),null)):(n.model_downloaded===!0||n.model_loaded?.toLowerCase()===e.toLowerCase())&&(o(!1),c.current&&=(clearTimeout(c.current),null),l.current&&=(clearInterval(l.current),null))}catch{}},Ml)},[]),f=e??`Gemma-4-E4B-it-GGUF`;return{isLoadingModel:n,isDownloadingModel:a,loadModel:(0,W.useCallback)(async(e,t)=>{let n=e??f,a=t??32768;r(!0);try{if(!await Za(n,a)){r(!1);return}i.system.info(`Load model triggered: ${n} (ctx=${a})`),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>r(!1),Al),d(n,`load`)}catch(e){i.system.error(`Failed to trigger model load`,e),r(!1)}},[f,t,d]),downloadModel:(0,W.useCallback)(async(e=!1,t)=>{let n=t??f;o(!0);try{await Qa(n,e),i.system.info(`Download model triggered: ${n} (force=${e})`),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>o(!1),jl),d(n,`download`)}catch(e){i.system.error(`Failed to trigger model download`,e),o(!1)}},[f,d])}}var Pj=5e3,Fj=2e3,Ij=3e4,Lj=6e4;function Rj(e){return e.lemonade_running?`up`:e.lemonade_error?`unresponsive`:`down`}function zj(e){return e.kind===`slow`||e.kind===`error`||e.kind===`ok`&&Rj(e.status)===`unresponsive`}function Bj(e){let t=e.kind===`ok`?e.status.download_progress?.state:void 0;return t===`downloading`||t===`starting`}function Vj(e){let t=null,n=0,r=!1,a=null,o=0,s=null,c=async()=>{let e={controller:new AbortController,cancelled:!1};s=e;let{controller:t}=e,n=setTimeout(()=>t.abort(),Lj);try{return{kind:`ok`,status:await Ua(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),s===e&&(s=null)}},l=()=>{if(t)return t;let a=c().then(t=>{if(t!==null){n=zj(t)?n+1:0,r=Bj(t);try{e(t)}catch(e){i.system.error(`Could not apply the system status; the next poll will try again`,e)}}}).finally(()=>{t===a&&(t=null)});return t=a,a},u=()=>Math.min((r?Fj:Pj)*2**n,Ij),d=e=>{l().finally(()=>{e===o&&(a=setTimeout(()=>d(e),u()))})};return{check:l,start:()=>{let e=++o;return d(e),()=>{e===o&&(o++,a&&clearTimeout(a),a=null,s&&(s.cancelled=!0,s.controller.abort(),s=null,t=null))}}}}function Hj({onRetry:e,label:t}){let[n,r]=(0,W.useState)(!1);return b(`button`,{className:`connection-banner__retry`,onClick:()=>{r(!0),Promise.resolve(e()).finally(()=>r(!1))},disabled:n,children:n?`Checking…`:t})}function Uj({onRetry:e,backendSlow:t=!1,backendError:n=null}){let{backendConnected:r,systemStatus:i,currentSessionId:a,messages:o}=G(),[s,c]=(0,W.useState)(!1),l=!!a&&o.length>0,u=i?.default_model_name??`Gemma-4-E4B-it-GGUF`,{isDownloadingModel:d,downloadModel:f}=Nj(u),p=(0,W.useRef)(i?.lemonade_running),h=(0,W.useRef)(i?.model_downloaded),g=(0,W.useRef)(i?.context_size_sufficient),v=(0,W.useRef)(i?.expected_model_loaded);(0,W.useEffect)(()=>{if(l)return;let e=i?.lemonade_running,t=i?.model_downloaded,n=i?.context_size_sufficient,r=i?.expected_model_loaded,a=!1;p.current!==e&&(p.current=e,e===!1&&(a=!0)),h.current!==t&&(h.current=t,t===!1&&(a=!0)),g.current!==n&&(g.current=n,n===!1&&(a=!0)),v.current!==r&&(v.current=r,r===!1&&(a=!0)),a&&c(!1)},[i,l]);let y=i?.download_progress??null,x=y?.model_name||u;if(d||y?.state===`downloading`||y?.state===`starting`||y?.state===`error`){let e=y?.total_bytes?`${(y.total_bytes/1e9).toFixed(1)} GB`:`large download`,t=y?.state===`error`;return m(`div`,{className:`connection-banner ${t?`connection-banner--error`:`connection-banner--warning`}`,role:t?`alert`:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(t?Qn:We,{size:16})}),b(`div`,{className:`connection-banner__text`,dir:`auto`,children:t?m(_.Fragment,{children:[`Download of `,b(`strong`,{children:x}),` failed.`,` `,y?.message&&b(`span`,{className:`connection-banner__hint`,children:y.message})]}):m(_.Fragment,{children:[`Downloading `,b(`strong`,{children:x}),` (`,e,`).`,y?.state===`downloading`&&y.file&&m(_.Fragment,{children:[` `,m(`span`,{className:`connection-banner__hint`,children:[`File `,y.file_index,` / `,y.total_files,`: `,b(`code`,{children:y.file})]})]})]})}),t?b(`button`,{className:`connection-banner__retry`,onClick:()=>f(!1,x),children:`Retry`}):b(`span`,{className:`connection-banner__loading connection-banner__progress`,children:y&&y.state===`downloading`&&y.total_bytes>0?m(_.Fragment,{children:[b(`span`,{className:`connection-banner__progress-bar`,role:`progressbar`,"aria-valuenow":y.percent,"aria-valuemin":0,"aria-valuemax":100,"aria-label":`Download progress`,children:b(`span`,{className:`connection-banner__progress-fill`,style:{width:`${y.percent}%`}})}),m(`span`,{className:`connection-banner__progress-label`,children:[y.percent,`% ·`,` `,(y.downloaded_bytes/1e9).toFixed(2),` /`,` `,(y.total_bytes/1e9).toFixed(2),` GB`]})]}):m(_.Fragment,{children:[b(U,{size:13,className:`connection-banner__spinner`}),y?.state===`starting`?`Starting download…`:`Downloading…`]})}),t&&b(`button`,{className:`connection-banner__dismiss`,onClick:()=>c(!0),"aria-label":`Dismiss`,children:b(cr,{size:14})})]})}if(i?.init_state===`initializing`){let e=i.init_tasks?.find(e=>e.status===`running`)?.name||`Preparing AI system`;return m(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(U,{size:16,className:`connection-banner__spinner`})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[e,m(`span`,{className:`thinking-dots`,children:[b(`span`,{children:`.`}),b(`span`,{children:`.`}),b(`span`,{children:`.`})]})]})]})}if(s||l)return null;if(!r)return m(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[b(`div`,{className:`connection-banner__icon`,children:b(ir,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`Lost the connection to GAIA.`,` `,b(`span`,{className:`connection-banner__hint`,children:`Check that GAIA is still running, then retry.`})]}),e&&b(Hj,{onRetry:e,label:`Retry`})]});if(n)return m(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(Qn,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA's backend answered with an error (`,n,`).`,` `,b(`span`,{className:`connection-banner__hint`,children:`It may be overloaded. GAIA keeps checking; if it lasts, restart GAIA.`})]}),e&&b(Hj,{onRetry:e,label:`Check again`})]});if(t)return m(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(Qn,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA is slow to answer.`,` `,b(`span`,{className:`connection-banner__hint`,children:`It may be busy with another chat or app. GAIA keeps checking.`})]}),e&&b(Hj,{onRetry:e,label:`Check again`})]});if(i?.config_error)return m(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[b(`div`,{className:`connection-banner__icon`,children:b(Qn,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA settings could not be loaded.`,` `,b(`span`,{className:`connection-banner__hint`,children:i.config_error})]}),e&&b(Hj,{onRetry:e,label:`Check again`})]});if(i&&!i.lemonade_running){let t=Rj(i)===`unresponsive`;return m(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(Qn,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t?`The model server is not answering (${i.lemonade_error}). It may be busy with another app or loading a model.`:`The model server isn't running.`,` `,i.start_command?m(`span`,{className:`connection-banner__hint`,children:[t?`If it stays this way, restart it: `:`To start it by hand, run `,b(`code`,{children:i.start_command})]}):i.start_instruction&&b(`span`,{className:`connection-banner__hint`,children:i.start_instruction})]}),e&&b(Hj,{onRetry:e,label:`Check again`}),b(`button`,{className:`connection-banner__dismiss`,onClick:()=>c(!0),"aria-label":`Dismiss`,children:b(cr,{size:14})})]})}if(i&&i.lemonade_running&&i.model_loaded&&i.context_size_sufficient===!1){let t=i.model_context_size??0;return m(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(It,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`LLM context window is too small (`,t.toLocaleString(),` tokens;`,` `,Ol.toLocaleString(),` required).`,` `,b(`span`,{className:`connection-banner__hint`,children:`Reload it with a larger context in Settings → Advanced.`})]}),e&&b(Hj,{onRetry:e,label:`Check again`}),b(`button`,{className:`connection-banner__dismiss`,onClick:()=>c(!0),"aria-label":`Dismiss`,children:b(cr,{size:14})})]})}return null}function Wj(){let e=BA(),[t,n]=(0,W.useState)(!1),[r,a]=(0,W.useState)(null),o=(0,W.useCallback)(e=>{let t=RA();t&&(a(null),t[e]().catch(t=>{let n=t instanceof Error?t.message:String(t);i.system.error(`Update ${e} failed`,t),a(n)}))},[]);if(t||e.status===`idle`||e.status===`checking`||e.status===`disabled`||e.status===`no-channel`)return null;if(e.status===`downloading`){let t=Math.max(0,Math.min(100,e.progress));return m(`div`,{className:`update-chip update-chip--downloading`,role:`status`,"aria-live":`polite`,title:`Downloading update${e.version?` ${e.version}`:``}…`,children:[b(We,{size:13,className:`update-chip__icon`}),m(`span`,{className:`update-chip__label`,children:[`Downloading update… `,t,`%`]})]})}return e.status===`available`?m(`div`,{className:`update-chip update-chip--available`,role:`status`,title:r||e.releaseNotes||`A new version is available.`,children:[b(We,{size:13,className:`update-chip__icon`}),b(`span`,{className:`update-chip__label`,children:r?`Update failed — try again`:`GAIA ${e.version??``} is available`}),!e.pinnedVersion&&b(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`downloadUpdate`),children:`Update now`}),b(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>n(!0),"aria-label":`Dismiss update notification`,children:b(cr,{size:11})})]}):e.status===`downloaded`?m(`div`,{className:`update-chip update-chip--ready`,role:`status`,"aria-live":`polite`,children:[b(Sn,{size:13,className:`update-chip__icon`}),b(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`restart`),title:r||`Click to restart and apply the update`,children:r?`Restart failed — try again`:`Update ready — restart to apply`})]}):e.status===`error`?m(`div`,{className:`update-chip update-chip--error`,role:`status`,title:e.error||`Update check failed.`,children:[b(Qn,{size:13,className:`update-chip__icon`}),b(`span`,{className:`update-chip__label`,children:`Update check failed`}),b(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>n(!0),"aria-label":`Dismiss update error`,children:b(cr,{size:11})})]}):null}var Gj={permission_request:{icon:b(Mn,{size:16}),colorClass:`notif-type-permission`,label:`Permission`},policy_alert:{icon:b(Mn,{size:16}),colorClass:`notif-type-policy`,label:`Policy`},security_alert:{icon:b(Qn,{size:16}),colorClass:`notif-type-security`,label:`Security`},status_change:{icon:b(Ce,{size:16}),colorClass:`notif-type-status`,label:`Status`},info:{icon:b(Mt,{size:16}),colorClass:`notif-type-info`,label:`Info`},error:{icon:b(xe,{size:16}),colorClass:`notif-type-error`,label:`Error`}};function Kj(e){let t=Date.now()-e,n=Math.floor(t/1e3);if(n<60)return`just now`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function qj({onClose:e}){let t=qc(hr(Yc)),n=qc(Jc),r=qc(e=>e.markRead),i=qc(e=>e.markAllRead),a=qc(e=>e.clearAll),o=qc(e=>e.dismiss),s=qc(e=>e.respondToPermission),c=qc(e=>e.typeFilter),l=qc(e=>e.setTypeFilter),u=(0,W.useCallback)(e=>{r(e)},[r]),d=(0,W.useCallback)(e=>{s(e.id,`allow`).catch(e=>console.error(`[NotificationCenter] allow failed:`,e))},[s]),f=(0,W.useCallback)(e=>{s(e.id,`deny`).catch(e=>console.error(`[NotificationCenter] deny failed:`,e))},[s]);return ki(!0,e),m(`div`,{className:`notification-center`,role:`dialog`,"aria-label":`Notification Center`,children:[m(`div`,{className:`notification-center-header`,children:[m(`div`,{className:`notification-center-title-row`,children:[b(`h2`,{className:`notification-center-title`,children:`Notifications`}),n>0&&b(`span`,{className:`notification-center-badge`,children:n})]}),b(`button`,{className:`btn-icon notification-center-close`,onClick:e,"aria-label":`Close notification center`,children:b(cr,{size:18})})]}),b(`div`,{className:`notification-filter-bar`,role:`tablist`,"aria-label":`Filter notifications`,children:[{key:null,label:`All`},{key:`permission_request`,label:`Permissions`},{key:`policy_alert`,label:`Policy`},{key:`error`,label:`Errors`},{key:`security_alert`,label:`Security`},{key:`status_change`,label:`Status`},{key:`info`,label:`Info`}].map(e=>b(`button`,{role:`tab`,"aria-selected":c===e.key,className:`notification-filter-tab ${c===e.key?`active`:``}`,onClick:()=>l(e.key),children:e.label},e.key??`all`))}),b(`div`,{className:`notification-list`,children:t.length===0?m(`div`,{className:`notification-empty`,children:[b(oe,{size:40,strokeWidth:1.2}),b(`span`,{children:`No notifications`})]}):t.map(e=>{let t=Gj[e.type];return m(`div`,{className:`notification-item ${e.read?``:`unread`} ${t.colorClass}`,id:e.type===`policy_alert`&&e.receiptId?`policy-receipt-${encodeURIComponent(e.receiptId)}`:void 0,onClick:()=>u(e.id),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&u(e.id)},children:[!e.read&&b(`span`,{className:`notification-unread-dot`}),b(`span`,{className:`notification-icon`,children:t.icon}),m(`div`,{className:`notification-content`,children:[m(`div`,{className:`notification-content-header`,children:[b(`span`,{className:`notification-agent`,children:e.agentName}),b(`span`,{className:`notification-time`,children:Kj(e.timestamp)})]}),e.title&&b(`span`,{className:`notification-title`,children:e.title}),b(`span`,{className:`notification-message`,children:e.message}),e.type===`permission_request`&&e.tool&&e.tool!==`allow_path_access`&&m(`span`,{className:`notification-tool`,children:[`Tool: `,b(`code`,{children:e.tool})]}),e.type===`policy_alert`&&m(`div`,{className:`notification-policy-details`,children:[e.tool&&m(`span`,{className:`notification-tool`,children:[`Tool: `,b(`code`,{children:e.tool})]}),e.reason&&m(`span`,{className:`notification-policy-reason`,children:[`Reason: `,e.reason]}),e.ruleIds&&e.ruleIds.length>0&&m(`span`,{className:`notification-tool`,children:[`Rules: `,b(`code`,{children:e.ruleIds.join(`, `)})]}),e.policyVersion&&m(`span`,{className:`notification-tool`,children:[`Policy: `,b(`code`,{children:e.policyVersion})]}),m(`span`,{className:`notification-tool`,children:[`Receipt:`,` `,e.receiptId?b(`code`,{children:e.receiptId}):b(`em`,{children:`Receipt unavailable`})]})]}),e.type===`permission_request`&&!e.response&&m(`div`,{className:`notification-actions`,children:[m(`button`,{className:`notification-action-btn notification-action-allow`,onClick:t=>{t.stopPropagation(),d(e)},children:[b(he,{size:14}),`Approve`]}),m(`button`,{className:`notification-action-btn notification-action-deny`,onClick:t=>{t.stopPropagation(),f(e)},children:[b(cr,{size:14}),`Deny`]})]}),e.type===`permission_request`&&e.response&&b(`span`,{className:`notification-response-badge ${e.response===`allow`?`response-allow`:`response-deny`}`,children:e.response===`allow`?`Approved`:`Denied`})]}),b(`button`,{className:`notification-dismiss`,onClick:t=>{t.stopPropagation(),o(e.id)},"aria-label":`Dismiss notification`,children:b(cr,{size:14})})]},e.id)})}),t.length>0&&m(`div`,{className:`notification-center-footer`,children:[m(`button`,{className:`notification-footer-btn`,onClick:i,disabled:n===0,children:[b(he,{size:14}),`Mark All Read`]}),m(`button`,{className:`notification-footer-btn notification-footer-clear`,onClick:a,children:[b(Xn,{size:14}),`Clear`]})]})]})}var Jj=1500,Yj=e=>new Promise(t=>setTimeout(t,e));async function Xj({onProgress:e,isCancelled:t=()=>!1,pollMs:n=Jj}={}){try{await eo(TD)}catch(e){if(e?.httpStatus!==409)throw e;let t=await to(TD).catch(()=>null);if(!t||t.status===`completed`||t.status===`failed`)throw e}for(;!t();){let t=await to(TD);if(e?.(t),t.status===`completed`)return;if(t.status===`failed`)throw Error(t.error||`The GAIA agent could not be installed.`);await Yj(n)}}function Zj({onInstalled:e}){let t=J(),[n,r]=(0,W.useState)({kind:`idle`}),i=(0,W.useRef)(!1);(0,W.useEffect)(()=>()=>{i.current=!0},[]);let a=(0,W.useCallback)(async()=>{r({kind:`installing`,percent:0});try{if(await Xj({isCancelled:()=>i.current,onProgress:e=>{i.current||r({kind:`installing`,percent:e.percent??0})}}),i.current)return;await e(),i.current||r({kind:`idle`})}catch(e){i.current||r({kind:`failed`,error:e instanceof Error?e.message:String(e)})}},[e]);return m(`div`,{className:`app-notice is-warning`,role:`status`,children:[n.kind===`installing`?b(`span`,{children:t(`agentNotice.installing`,{percent:Math.round(n.percent)})}):n.kind===`failed`?b(`span`,{children:t(`agentNotice.failed`,{error:n.error})}):b(`span`,{children:t(`agentNotice.missing`)}),n.kind!==`installing`&&b(`button`,{type:`button`,className:`link-btn`,onClick:()=>void a(),children:n.kind===`failed`?t(`agentNotice.retry`):t(`agentNotice.install`)})]})}function Qj(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 $j(e,t){let{addNotification:n}=qc.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 eM=xr((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 Ss()).schedules||[],r=t().errorCounts;r&&$j(r,n),e({schedules:n,loading:!1,errorCounts:Object.fromEntries(n.map(e=>[e.id,e.error_count]))})}catch(t){i.api.error(`Failed to load schedules`,t),e({error:`Failed to load schedules`,loading:!1})}},createSchedule:async(t,n,r)=>{try{let i=await ws(t,n,r);e(e=>({schedules:[...e.schedules,i],actionError:null}))}catch(e){throw i.api.error(`Failed to create schedule`,e),e}},updateScheduleStatus:async(t,n)=>{try{let r=await Ts(t,n);e(e=>({schedules:e.schedules.map(e=>e.name===t?r:e),actionError:null}))}catch(n){i.api.error(`Failed to update schedule "${t}"`,n),e({actionError:Qj(n,`Failed to update schedule`)})}},runScheduleNow:async t=>{try{let n=await Es(t);e(e=>({schedules:e.schedules.map(e=>e.name===t?n:e),actionError:null}))}catch(n){i.api.error(`Failed to run schedule "${t}" now`,n),e({actionError:Qj(n,`Could not run the schedule now`)})}},deleteSchedule:async t=>{try{await Ds(t),e(e=>({schedules:e.schedules.filter(e=>e.name!==t),selectedSchedule:e.selectedSchedule===t?null:e.selectedSchedule,actionError:null}))}catch(n){i.api.error(`Failed to delete schedule "${t}"`,n),e({actionError:Qj(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 Os(n);if(t().selectedSchedule!==n)return;e({results:r.results||[],resultsLoading:!1})}catch(r){if(i.api.error(`Failed to load results for "${n}"`,r),t().selectedSchedule!==n)return;e({results:[],resultsLoading:!1})}},dismissActionError:()=>e({actionError:null})})),tM=new Set([`loading_model`,`downloading_model`,`model_retry`,`waiting`]),nM=5;function rM(e,t){return{id:e,title:t.get(e)?.title??`Untitled chat`}}function iM(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=>({...rM(e,t),reason:`approval`}));n&&e.awaitingUser&&!a.has(e.currentSessionId)&&o.push({...rM(e.currentSessionId,t),reason:`answer`});for(let[n,r]of Object.entries(e.awaitingBySession))o.some(e=>e.id===n)||o.push({...rM(n,t),reason:r===`question`?`answer`:`approval`});let s=n&&!e.awaitingUser&&e.livePhase&&tM.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,nM).map(e=>rM(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=>rM(e,t)),needsYou:o,recent:u}}function aM(e){let t=(0,W.useRef)(e);t.current=e,(0,W.useEffect)(()=>{let e=window.gaiaAPI?.tray;if(!e)return;let n=``,r=null,a=()=>{let t=G.getState(),a={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:qc.getState().notifications},o=r;if(r=a,o&&Object.keys(a).every(e=>a[e]===o[e]))return;let s=iM(a),c=JSON.stringify(s);c!==n&&(n=c,e.setActivity(s).catch(e=>{n=``,i.system.error(`The tray could not take the app state`,e)}))};a();let o=G.subscribe(a),s=qc.subscribe(a),c=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`:G.getState().openSettings(e.section);break;case`refresh-status`:t.current.refreshStatus();break;default:i.system.error(`Unknown tray command`,e)}});return()=>{o(),s(),c()}},[])}function oM(){(0,W.useEffect)(()=>{let e=window.gaiaAPI;if(!e)return;let t=qc.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=G.getState();n.currentSessionId!==t&&n.setMessages([]),n.setCurrentSession(t)})];return()=>n.forEach(e=>e())},[])}function sM(e,t,n){let r=window.gaiaAPI;if(r){r.notification.show({title:t,body:n,sessionId:e}).then(e=>{e||i.system.warn(`This OS has no desktop notifications; the badge still counts it.`)}).catch(e=>i.system.error(`Could not show the desktop notification`,e));return}if(typeof Notification>`u`){i.system.warn(`This browser has no notifications; the alert was not shown.`);return}if(Notification.permission!==`granted`){i.system.warn(`Browser notifications are ${Notification.permission}; allow them in Settings → Notifications.`);return}let a=new Notification(t,{body:n,tag:`gaia-${e}`});a.onclick=()=>{window.focus(),G.getState().setCurrentSession(e)}}function cM(){let[e,t]=(0,W.useState)(null);return(0,W.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=>i.system.warn(`Battery level unavailable; keep-awake ignores the battery policy.`,e)),()=>{n?.removeEventListener(`levelchange`,r),n?.removeEventListener(`chargingchange`,r)}},[]),e}function lM(){oM();let e=G(e=>e.runningSessionIds),t=G(e=>e.awaitingBySession),n=G(e=>e.sessions),r=G(e=>e.currentSessionId),a=qc(hr(Zc)),o=il(),s=cM(),c=(0,W.useRef)(null),l=dl(e,t,a),u=JSON.stringify(l);(0,W.useEffect)(()=>{let e=JSON.parse(u),t=c.current;if(c.current=e,t===null)return;let{sessions:n,currentSessionId:r}=G.getState(),a=document.hasFocus(),s=!1;for(let{sessionId:c,event:l}of fl(t,e)){let e=n.find(e=>e.id===c);if(e?.kind===`eval`||e?.kind===`scheduled`)continue;let t=o.modes[l];if(!(t===`off`||hl(c,r,a))&&(s=!0,t===`banner`)){if(l!==`finished`){let{title:t,body:n}=ml(l,e);sM(c,t,n)}else Ao(c).then(e=>{G.getState().updateSessionInList(c,e);let{title:t,body:n}=ml(l,e);sM(c,t,n)}).catch(t=>{i.system.error(`Could not read how chat ${c} ended`,t);let{title:n,body:r}=ml(l,{...e,last_run_status:null});sM(c,n,r)})}}if(s){if(o.sound)try{vl()}catch(e){i.system.warn(`Alert sound not played`,e)}o.flash&&!a&&window.gaiaAPI&&window.gaiaAPI.notification.flash().catch(e=>i.system.error(`Could not flash the taskbar button`,e))}},[u,o.modes,o.sound,o.flash]);let d=gl(n,l,o.modes,r);(0,W.useEffect)(()=>{window.gaiaAPI?.notification.setAttentionCount(d).catch(e=>i.system.error(`Could not update the taskbar badge`,e))},[d]);let f=o.keepAwake&&e.length>0&&_l(s,o.batteryFloor);(0,W.useEffect)(()=>{window.gaiaAPI?.power.setKeepAwake(f).catch(e=>i.system.error(`Could not change keep-awake`,e))},[f])}function uM(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 dM(e){return e.replace(/-/g,``).slice(0,7)}function fM(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 pM(e,t,n){return!e||t&&(e===t||e===dM(t))?null:n.some(t=>t.id===e)?e:fM(n,e)}function mM(e){return new URLSearchParams(e.search).get(`session`)||e.hash.replace(/^#/,``)||null}var hM=`gaia:last-session`;function gM(e){try{e?localStorage.setItem(hM,e):localStorage.removeItem(hM)}catch(e){i.ui.warn(`Could not save the open chat for the next launch`,e)}}function _M(){try{return localStorage.getItem(hM)}catch(e){return i.ui.warn(`Could not read the chat open at last launch`,e),null}}var vM=1e3,yM=3e4;function bM(e,{initialMs:t=vM,maxMs:n=yM,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 xM(e,t,n){return e&&!t&&!n}var SM=(0,W.lazy)(()=>Oj(()=>import(`./MemoryDashboard-BQhg3t2B.js`).then(e=>({default:e.MemoryDashboard})),__vite__mapDeps([5,1,2,6,7]),import.meta.url)),CM=(0,W.lazy)(()=>Oj(()=>import(`./ScheduleManager-tcyjbGY9.js`).then(e=>({default:e.ScheduleManager})),__vite__mapDeps([8,1,2,6,9]),import.meta.url)),wM=(0,W.lazy)(()=>Oj(()=>import(`./DocumentLibrary-c78Y6arz.js`).then(e=>({default:e.DocumentLibrary})),__vite__mapDeps([10,1,2,11]),import.meta.url)),TM=(0,W.lazy)(()=>Oj(()=>import(`./FileBrowser-DwEPODjV.js`).then(e=>({default:e.FileBrowser})),__vite__mapDeps([12,1,2,13]),import.meta.url)),EM=(0,W.lazy)(()=>Oj(()=>import(`./MobileAccessModal-RI4HtcYe.js`).then(e=>({default:e.MobileAccessModal})),__vite__mapDeps([14,1,2,15]),import.meta.url)),DM=3,OM=3e5,kM=6e3,AM=6e4,jM=e=>e instanceof TypeError,MM=e=>new Promise(t=>setTimeout(t,e));function NM(){return b(`div`,{className:`loading-spinner`,role:`status`,"aria-label":`Loading`})}var PM=e=>e===1||e%10==0;function FM(){let e=G(e=>e.currentSessionId),t=G(e=>e.setSessions),n=G(e=>e.setCurrentSession),a=G(e=>e.addSession),o=G(e=>e.setMessages),s=G(e=>e.showDocLibrary),c=G(e=>e.showFileBrowser),l=G(e=>e.showMemoryDashboard),u=G(e=>e.showSchedules),d=G(e=>e.sidebarOpen),f=G(e=>e.sidebarCollapsed),p=G(e=>e.setSidebarOpen),h=G(e=>e.setSystemStatus),g=G(e=>e.setBackendConnected),_=G(e=>e.setAgents),v=G(e=>e.agents),y=G(e=>e.setPendingPrompt),x=G(e=>e.setDefaultPermissionMode),C=G(e=>e.openSettings),w=G(e=>e.settingsSection),T=G(e=>e.syncSystemTheme),E=nc(e=>e.restoreNotice),D=nc(e=>e.dismissRestoreNotice),O=qc(e=>e.showPanel),ee=G(e=>e.systemStatus?.initialized===!0),k=(0,W.useRef)(!1),A=qc(e=>e.setShowPanel);(0,W.useEffect)(()=>{if(!E?.ok)return;let e=setTimeout(D,kM);return()=>clearTimeout(e)},[E,D]);let[j,M]=(0,W.useState)({state:`checking`}),te=(0,W.useRef)(j);te.current=j;let[N,ne]=(0,W.useState)(!1),re=(0,W.useRef)(N);re.current=N;let[ie,P]=(0,W.useState)(!1),F=ie||N&&!ED(v),I=(0,W.useRef)(F);I.current=F;let[ae,oe]=(0,W.useState)(null),[L,se]=(0,W.useState)(``),[ce,le]=(0,W.useState)(0),[ue,de]=(0,W.useState)(!1),[fe,R]=(0,W.useState)(!1),[z,pe]=(0,W.useState)(null),me=(0,W.useRef)(async()=>{}),he=(0,W.useRef)(async()=>{}),ge=(0,W.useCallback)(async(e=!1,t=!1)=>{e||M({state:`checking`});let n=0;try{for(;;){await nc.getState().refresh();let e=nc.getState().active,r;try{r=await Bi(!!e?.remote)}catch(e){if(!t||!jM(e)||n>=AM)throw e;await MM(vM),n+=vM;continue}n>0&&await Promise.all([me.current(),he.current()]),M(r.ready?{state:`ready`}:{state:`needed`,check:r});return}}catch(e){let t=e instanceof Error?e.message:String(e);i.system.warn(`Setup check could not be answered`,e),M({state:`unknown`,error:t})}},[]),B=(0,W.useRef)(0),V=(0,W.useCallback)(async()=>{let e=++B.current,t=(await $a()).agents||[];e===B.current&&(_(t),ne(!0),ED(t)&&P(!1))},[_]),_e=(0,W.useCallback)(()=>{let e=re.current;ne(!1),V().catch(t=>{i.api.warn(`Agent list unavailable after setup`,t),e&&ne(!0)})},[V]);(0,W.useEffect)(()=>{let e=()=>{I.current&&V().catch(e=>i.api.warn(`Agent list unavailable`,e))};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[V]);let ve=(0,W.useCallback)(async()=>{x((await Da()).default_mode)},[x]),ye=(0,W.useRef)([]);(0,W.useEffect)(()=>{r(`0.25.4rc2`),ge(!1,!0);let e=[bM(V,{onError:(e,t)=>{PM(t)&&i.api.warn(`Agent list unavailable (attempt ${t}); retrying`,e)}}),bM(ve,{onError:(e,t)=>{PM(t)&&i.api.warn(`Default permission mode unavailable (attempt ${t}); retrying`,e)}})];return ye.current=e,()=>e.forEach(e=>e.stop())},[ge,V,ve]);let be=(0,W.useCallback)(()=>{ye.current.forEach(e=>e.kick()),nc.getState().retryNow(),he.current(),te.current.state===`unknown`&&ge(!0)},[ge]),xe=(0,W.useRef)(be);xe.current=be;let Se=(0,W.useRef)(0),Ce=(0,W.useRef)(0),we=(0,W.useRef)(null),Te=(0,W.useRef)(!1),[Ee,H]=(0,W.useState)(!1),[De,Oe]=(0,W.useState)(null),ke=(0,W.useCallback)(e=>{if(e.kind===`unreachable`){i.system.warn(`System status check failed`,e.error),Te.current=!0,Ce.current=0,we.current=null,H(!1),Oe(null),g(!1),h(null);return}if(e.kind===`error`){i.system.warn(`System status answered HTTP ${e.httpStatus}`,e.message),Te.current&&xe.current(),Te.current=!1,Ce.current=0,we.current=null,H(!1),Oe(`HTTP ${e.httpStatus}: ${e.message}`),g(!0);return}if(e.kind===`slow`){if(Ce.current+=1,we.current??=Date.now(),Oe(null),i.system.warn(`System status did not answer in time (${Ce.current} in a row)`),Date.now()-we.current>=OM){H(!1),g(!1),h(null);return}g(!0),(Te.current||Ce.current>=DM)&&H(!0);return}let{status:t}=e;Te.current&&xe.current(),Te.current=!1,Ce.current=0,we.current=null,H(!1),Oe(null),g(!0),Se.current=t.lemonade_running?0:Se.current+1;let n=G.getState().systemStatus;t.lemonade_running||Se.current>=DM||!n?.lemonade_running?h(t):h({...n,download_progress:t.download_progress})},[g,h]),Ae=(0,W.useRef)(ke);Ae.current=ke;let[je]=(0,W.useState)(()=>Vj(e=>Ae.current(e))),Me=je.check;me.current=Me,(0,W.useEffect)(()=>jD(je.start),[je]);let Ne=(0,W.useRef)(``);(0,W.useEffect)(()=>{let e=e=>Eo().then(n=>{let r=n.sessions||[];if(!e&&r.length===0&&G.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(`
77
+ `)})]}),et&&m(`div`,{className:`setup-done`,role:`status`,children:[m(`div`,{className:`setup-done-head`,children:[b(`p`,{children:t.compose(e=>[e(`setup.ready.title`),tt?e(Te?`setup.ready.answersCloud`:`setup.ready.answersLocal`,{model:Te?fc(tt):nt[tt]??N?.catalog?.find(e=>e.id===tt)?.name??fc(tt)}):null].filter(Boolean).join(` `))}),b(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void $e(),autoFocus:!0,children:t(`setup.ready.start`)})]}),!Te&&N&&b(cA,{plan:N,chatModel:tt,gpu:re}),ge.length>0&&m(_.Fragment,{children:[b(`p`,{className:`setup-hint`,children:`Or start with one of these:`}),b(pA,{cards:ge,onPick:e=>void $e(e)})]})]})]}),I?.kind===`no_fit`&&b(qk,{title:I.models.length===1?t(`setup.confirm.noFitOne`,{name:I.models[0].name}):t(`setup.confirm.noFitMany`),confirmLabel:t(`setup.confirm.downloadAnyway`),cancelLabel:t(`setup.confirm.pickSmaller`),onConfirm:()=>{ae(null),L(!0),We(He,!0)},onCancel:()=>ae(null),children:I.models.map(e=>m(`p`,{children:[b(`bdi`,{children:e.name}),`: `,zk(e,t)]},e.id))}),I?.kind===`server`&&b(qk,{title:I.detail.code===`low_disk`?t(`setup.confirm.lowDiskTitle`):t(`setup.confirm.noFitServerTitle`),confirmLabel:I.detail.code===`low_disk`?t(`setup.confirm.downloadAnyway`):t(`setup.confirm.useAnyway`),cancelLabel:t(`setup.confirm.changeModels`),onConfirm:()=>{let e=I;if(ae(null),e.then===`chat`)L(!0),We(He,!0);else if(e.then===`retry`)Wi(e.id,{keepTrying:P,acknowledgeLowDisk:!0}).then(p).catch(e=>ue(MA(e)));else{let{gaiaLemonade:e,options:t}=ye.current;Re(e,{...t,acknowledgeLowDisk:!0})}},onCancel:()=>{let e=I;ae(null),e.then!==`retry`&&s(`models`)},children:b(`p`,{children:I.detail.message})})]})}var FA=bl()?`menu bar`:`tray`,IA=[{key:`minimizeToTray`,label:`Keep running when the window closes`,hint:`GAIA stays in the ${FA} with your model loaded. Quit from the ${FA} menu.`},{key:`startOnLogin`,label:`Start GAIA when you sign in`,hint:`Your first chat of the day starts without waiting for GAIA to open.`},{key:`startMinimized`,label:`Start in the ${FA}`,hint:`GAIA opens without its window. Use the ${FA} icon to show it.`}];function LA(){let e=window.gaiaAPI?.tray,[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(null);(0,W.useEffect)(()=>{e&&e.getConfig().then(e=>n(e.tray)).catch(e=>i(`Couldn't read the desktop settings: ${e instanceof Error?e.message:String(e)}`))},[e]);let s=(0,W.useCallback)(async r=>{if(e&&t&&a===null){o(r),i(null);try{let i=await e.setConfig({tray:{[r]:!t[r]}});n(i.tray)}catch(e){i(e instanceof Error?e.message:String(e))}finally{o(null)}}},[e,t,a]);return e?m(`div`,{className:`settings-field`,role:`group`,"aria-labelledby":`desktop-app-label`,children:[b(`span`,{className:`settings-label`,id:`desktop-app-label`,children:`Desktop app`}),IA.map(({key:e,label:n,hint:r})=>m(`div`,{children:[m(`label`,{className:`setting-row`,children:[b(`span`,{children:n}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,role:`switch`,checked:!!t?.[e],"aria-describedby":`desktop-${e}-hint`,onChange:()=>void s(e),disabled:!t||a!==null&&a!==e,"aria-busy":a===e,"aria-label":n}),b(`span`,{className:`toggle-track`})]})]}),b(`p`,{className:`settings-hint`,id:`desktop-${e}-hint`,children:r})]},e)),r&&b(`p`,{className:`settings-error`,role:`alert`,children:r})]}):null}function RA(){return window.gaiaUpdater}var zA={status:`idle`,version:null,progress:0,releaseNotes:null,error:null,currentVersion:null,pinnedVersion:null,autoUpdate:!1,includePrereleases:!1};function BA(){let[e,t]=(0,W.useState)({...zA});return(0,W.useEffect)(()=>{let e=RA();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}function VA(){return window.gaiaUpdater}function HA({onClose:e}){let[t,n]=(0,W.useState)({kind:`loading`}),r=(0,W.useRef)(null);(0,W.useEffect)(()=>{let e=VA();e?e.listReleases().then(e=>{n(Array.isArray(e)?{kind:`list`,releases:e}:{kind:`error`,message:e.error})}).catch(()=>{n({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})}):n({kind:`error`,message:`Couldn't reach GitHub to list releases — check your connection; you can still download installers from the Releases page.`})},[]),ki(!0,e),FS(r,!0),(0,W.useEffect)(()=>{let e=r.current;e&&e.querySelector(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`)?.focus()},[]),(0,W.useEffect)(()=>{let e=r.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 i(e,t){e.isCurrent||n({kind:`confirm`,release:e,releases:t})}async function a(t){n({kind:`installing`});let r=VA();if(!r)n({kind:`error`,message:`Bridge unavailable — please restart the app.`});else try{await r.installVersion(t.tag),e()}catch(e){let t=e instanceof Error?e.message:String(e);n({kind:`error`,message:`Failed to install that version: ${t}`})}}function o(e){if(!e)return``;try{return new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`})}catch{return e}}return b(`div`,{className:`version-picker-overlay`,onClick:t=>{t.target===t.currentTarget&&e()},children:m(`div`,{className:`version-picker-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":`Install a specific version`,ref:r,children:[m(`div`,{className:`version-picker-header`,children:[b(`h3`,{children:`Install a specific version`}),b(`button`,{className:`version-picker-close`,onClick:e,"aria-label":`Close`,type:`button`,children:`×`})]}),m(`div`,{className:`version-picker-body`,children:[t.kind===`loading`&&m(`div`,{className:`version-picker-loading`,"aria-busy":`true`,children:[b(`span`,{className:`version-picker-spinner`}),`Loading releases…`]}),t.kind===`error`&&m(`div`,{className:`version-picker-error`,children:[b(`p`,{children:t.message}),b(`p`,{children:b(`a`,{href:`https://github.com/amd/gaia/releases`,target:`_blank`,rel:`noreferrer`,children:`Browse releases on GitHub`})})]}),t.kind===`list`&&b(`ul`,{className:`version-picker-list`,role:`listbox`,"aria-label":`Available releases`,children:t.releases.map(e=>b(`li`,{children:m(`button`,{type:`button`,className:`version-picker-row`,"data-version":e.version,"aria-label":`${e.version}${e.isCurrent?` — installed`:``}${e.isPinned?` — pinned`:``}`,"aria-disabled":e.isCurrent?`true`:`false`,onClick:()=>i(e,t.releases),disabled:e.isCurrent,children:[b(`span`,{className:`vp-version`,children:e.version}),b(`span`,{className:`vp-date`,children:o(e.date)}),e.isCurrent&&b(`span`,{className:`vp-badge vp-badge-current`,children:`Installed`}),e.isPinned&&!e.isCurrent&&b(`span`,{className:`vp-badge vp-badge-pinned`,children:`Pinned`}),!e.isCurrent&&b(`span`,{className:`vp-arrow`,"aria-hidden":`true`,children:`›`})]})},e.tag))}),t.kind===`list`&&m(`p`,{className:`version-picker-more`,children:[`Showing the `,t.releases.length,` most recent.`,` `,b(`a`,{href:`https://github.com/amd/gaia/releases`,target:`_blank`,rel:`noreferrer`,children:`Browse all releases on GitHub`})]}),t.kind===`confirm`&&m(`div`,{className:`version-picker-confirm`,children:[m(`p`,{children:[`This will `,m(`strong`,{children:[`install v`,t.release.version]}),` and restart the app.`]}),m(`p`,{className:`vp-confirm-note`,children:[`GAIA will stay on v`,t.release.version,`: updates are paused until you unpin it in Settings → Updates.`]}),m(`div`,{className:`vp-confirm-actions`,children:[b(`button`,{type:`button`,className:`vp-btn-cancel`,onClick:()=>n({kind:`list`,releases:t.releases}),children:`Back`}),b(`button`,{type:`button`,className:`vp-btn-confirm`,onClick:()=>a(t.release),children:`Install & restart`})]})]}),t.kind===`installing`&&m(`div`,{className:`version-picker-loading`,"aria-busy":`true`,children:[b(`span`,{className:`version-picker-spinner`}),`Starting download…`]})]})]})})}var UA=`Install updates automatically`,WA=`Include release candidates`;function GA(e){return/^\d+\.\d+\.\d+-/.test(e??``)}function KA(e){switch(e.status){case`checking`:return`Checking for updates…`;case`available`:return`GAIA ${e.version??``} is available.`;case`downloading`:return`Downloading GAIA ${e.version??``}… ${e.progress}%`;case`downloaded`:return`GAIA ${e.version??``} is ready — restart to finish installing.`;case`error`:return`Update check failed: ${e.error??`unknown error`}`;case`no-channel`:return e.error??`No GAIA release publishes a desktop update for this platform yet.`;case`disabled`:return`Updates are turned off for this install (GAIA_DISABLE_UPDATE=1).`;default:return`GAIA is up to date.`}}function qA(){let e=BA(),t=RA(),[n,r]=(0,W.useState)(!1),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(!1);if(!t)return null;async function l(e,n){if(t){r(!0),o(null);try{await n(t)}catch(t){i.system.error(`${e} failed`,t),o(`${e} failed: ${t instanceof Error?t.message:String(t)}`)}finally{r(!1)}}}let u=e.status===`disabled`,d=n||e.status===`checking`||e.status===`downloading`;return m(`div`,{className:`settings-field`,role:`group`,"aria-labelledby":`updates-label`,children:[b(`span`,{className:`settings-label`,id:`updates-label`,children:`Updates`}),m(`p`,{className:`settings-hint`,role:`status`,children:[`Running GAIA `,e.currentVersion??`unknown`,`. `,KA(e)]}),m(`label`,{className:`setting-row`,children:[b(`span`,{children:UA}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,role:`switch`,checked:e.autoUpdate,"aria-describedby":`updates-auto-hint`,"aria-label":UA,"aria-busy":n,disabled:u,onChange:()=>{n||l(`Saving the auto-update setting`,t=>t.setAutoUpdate(!e.autoUpdate))}}),b(`span`,{className:`toggle-track`})]})]}),b(`p`,{className:`settings-hint`,id:`updates-auto-hint`,children:`Off by default while GAIA is changing quickly — you choose when to update. The Terminal UI follows the same setting.`}),m(`label`,{className:`setting-row`,children:[b(`span`,{children:WA}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,role:`switch`,checked:!!e.includePrereleases,"aria-describedby":`updates-rc-hint`,"aria-label":WA,"aria-busy":n,disabled:u,onChange:()=>{n||l(`Saving the release-candidate setting`,t=>t.setIncludePrereleases(!e.includePrereleases))}}),b(`span`,{className:`toggle-track`})]})]}),m(`p`,{className:`settings-hint`,id:`updates-rc-hint`,children:[`Also offer test builds (vX.Y.Z-rcN) before they become a final release. Off by default.`,GA(e.currentVersion)&&` This is a release candidate, so newer ones are offered either way.`]}),e.pinnedVersion&&m(`p`,{className:`settings-hint`,children:[`Pinned to `,e.pinnedVersion,`, so updates are paused.`,` `,b(`button`,{type:`button`,className:`btn-secondary`,disabled:n,onClick:()=>void l(`Resuming updates`,e=>e.resumeUpdates()),children:`Unpin`})]}),m(`div`,{className:`setting-actions`,children:[e.status===`available`&&!e.pinnedVersion&&m(`button`,{type:`button`,className:`btn-primary`,disabled:n,onClick:()=>void l(`Downloading the update`,e=>e.downloadUpdate()),children:[`Update to `,e.version]}),e.status===`downloaded`&&b(`button`,{type:`button`,className:`btn-primary`,disabled:n,onClick:()=>void l(`Restarting to install`,e=>e.restart()),children:`Restart to install`}),b(`button`,{type:`button`,className:`btn-secondary`,disabled:d||u,onClick:()=>void l(`Checking for updates`,e=>e.check()),children:`Check for updates`}),b(`button`,{type:`button`,className:`btn-secondary`,disabled:d||u,onClick:()=>c(!0),children:`Install a specific version…`})]}),e.configError&&b(`p`,{className:`settings-error`,role:`alert`,children:e.configError}),a&&b(`p`,{className:`settings-error`,role:`alert`,children:a}),s&&b(HA,{onClose:()=>c(!1)})]})}var JA=[{value:`light`,label:`settings.theme.light`},{value:`dark`,label:`settings.theme.dark`},{value:`system`,label:`settings.theme.system`}],YA={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`},XA=[[`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 ZA(){let e=J(),t=G(e=>e.locale),n=G(e=>e.setLocale),r=G(e=>e.themePreference),i=G(e=>e.setThemePreference),a=G(e=>e.palette),o=G(e=>e.setPalette),s=G(e=>e.customColors),c=G(e=>e.setCustomColors),l=e=>t=>c({...s,[e]:t.target.value.toUpperCase()});return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:e(`settings.section.general`)}),m(`div`,{className:`settings-field`,children:[b(`label`,{className:`settings-label`,htmlFor:`ui-language`,children:e(`settings.language`)}),b(`select`,{id:`ui-language`,className:`settings-input`,value:t,onChange:e=>n(e.target.value),children:x.map(({meta:e})=>b(`option`,{value:e.code,lang:e.code,dir:e.dir,children:p(e)},e.code))}),b(`span`,{className:`settings-hint`,children:e(`settings.languageHint`)})]}),m(`div`,{className:`settings-field`,children:[b(`span`,{className:`settings-label`,id:`appearance-label`,children:e(`settings.appearance`)}),b(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`appearance-label`,children:JA.map(t=>b(`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))})]}),b(LA,{}),b(qA,{}),m(`div`,{className:`settings-field`,children:[b(`span`,{className:`settings-label`,id:`palette-label`,children:e(`settings.colors`)}),m(`div`,{className:`palette-grid`,role:`radiogroup`,"aria-labelledby":`palette-label`,children:[jr.map(t=>m(`button`,{type:`button`,role:`radio`,"aria-checked":a===t.id,className:`palette-tile${a===t.id?` is-active`:``}`,onClick:()=>o(t.id),children:[b(`span`,{className:`palette-swatch`,"aria-hidden":`true`,children:t.swatch.map(e=>b(`i`,{style:{background:e}},e))}),e(YA[t.id])]},t.id)),m(`button`,{type:`button`,role:`radio`,"aria-checked":a===`custom`,className:`palette-tile${a===`custom`?` is-active`:``}`,onClick:()=>o(`custom`),children:[m(`span`,{className:`palette-swatch`,"aria-hidden":`true`,children:[b(`i`,{style:{background:s.base}}),b(`i`,{style:{background:s.accent}})]}),e(`settings.colors.custom`)]})]}),a===`custom`&&m(`div`,{className:`palette-custom`,children:[m(`label`,{className:`palette-color`,htmlFor:`custom-accent`,children:[b(`input`,{id:`custom-accent`,type:`color`,value:s.accent,onChange:l(`accent`)}),m(`span`,{children:[e(`settings.colors.accent`),b(`small`,{children:e(`settings.colors.accentHint`)})]})]}),m(`label`,{className:`palette-color`,htmlFor:`custom-base`,children:[b(`input`,{id:`custom-base`,type:`color`,value:s.base,onChange:l(`base`)}),m(`span`,{children:[e(`settings.colors.base`),b(`small`,{children:e(`settings.colors.baseHint`)})]})]}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>c(Nr),children:e(`settings.colors.reset`)}),b(`p`,{className:`settings-hint`,children:e(`settings.colors.hint`)})]})]}),m(`div`,{className:`settings-field`,children:[b(`span`,{className:`settings-label`,children:e(`settings.shortcuts`)}),b(`dl`,{className:`shortcut-list`,children:XA.map(([t,n])=>m(`div`,{className:`shortcut-row`,children:[b(`dt`,{children:b(`kbd`,{children:wl(t)})}),b(`dd`,{children:e(n)})]},t))})]})]})}var QA=`auto`;function $A({model:e}){let[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(null);(0,W.useEffect)(()=>{n(null),i(null),c(null),po(e).then(n).catch(e=>i(e instanceof Error?e.message:String(e)))},[e]);let l=(0,W.useCallback)(async t=>{o(!0),i(null),c(null);try{let r=await mo(e,t===QA?null:Number(t));n(r);let i=r.chosen?_c(r.chosen):`the automatic size`;r.reload?.started?c(`Reloading ${r.display_name} at ${i}. Chat pauses until it's back.`):r.reload?.reason===`already_loaded`?c(`Saved. ${r.display_name} is already loaded at ${i}, so nothing reloads.`):r.reload?.reason===`warm_up`?c(`Saved. GAIA is getting the model ready for a new chat, so ${r.display_name} switches to ${i} the next time it loads.`):r.reload?.reason===`busy`?c(`Saved. GAIA is answering right now, so ${r.display_name} switches to ${i} the next time it loads.`):r.reload?.reason===`not_gaias_server`?c(`Saved. GAIA doesn't reload models on your own server; ${r.display_name} uses ${i} the next time it loads.`):r.reload?.reason===`restarting`?c(`Saved. A reload is already running; this size applies the next time the model loads.`):c(`Saved. It applies the next time this model loads.`)}catch(e){i(e instanceof Error?e.message:String(e))}finally{o(!1)}},[e]);if(r&&!t)return b(`p`,{className:`settings-error`,role:`alert`,children:r});if(!t)return m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Checking context sizes…`]});let u=t.chosen==null?QA:String(t.chosen),d=t.chosen!=null&&t.loaded_ctx!=null&&t.loaded_ctx!==t.chosen;return m(`div`,{className:`settings-field`,children:[b(`label`,{className:`settings-label`,htmlFor:`ctx-size`,children:`Context size`}),m(`select`,{id:`ctx-size`,className:`settings-input`,value:u,onChange:e=>void l(e.target.value),disabled:a||t.options.length===0,children:[m(`option`,{value:QA,children:[`Automatic`,t.automatic?` (${_c(t.automatic)})`:``]}),t.options.map(e=>m(`option`,{value:String(e),children:[_c(e),` tokens`]},e))]}),m(`span`,{className:`settings-hint`,children:[t.note??(t.max_fit?`Up to ${_c(t.max_fit)}, the most ${t.display_name} can hold on this PC (${t.memory_source}). A larger window uses more memory. GAIA reloads the model to apply it, except on a Lemonade you run yourself.`:null),d&&` Loaded now at ${_c(t.loaded_ctx)}.`]}),a&&m(`span`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Applying…`]}),s&&b(`p`,{className:`settings-ok`,role:`status`,children:s}),r&&b(`p`,{className:`settings-error`,role:`alert`,children:r})]})}function ej({onAdded:e}){let[t,n]=(0,W.useState)(``),[r,i]=(0,W.useState)(``),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(null),d=(0,W.useRef)(``),f=(0,W.useCallback)(async e=>{let n=t.trim();d.current=n,c(`check`),u(null);try{let t=await vo(n,e);if(d.current!==n)return;o(t),i(t.file??e)}catch(e){if(d.current!==n)return;o(null),u(e instanceof Error?e.message:String(e))}finally{c(null)}},[t]),p=(0,W.useCallback)(async()=>{c(`add`),u(null);try{let{report:a}=await yo(t.trim(),r);n(``),i(``),o(null),e(a.display_name??a.model_id??`The model`)}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(null)}},[e,r,t]);return m(`form`,{className:`settings-field custom-model-add`,onSubmit:e=>{e.preventDefault(),f(``)},children:[b(`label`,{className:`settings-label`,htmlFor:`custom-model-url`,children:`Add a model from Hugging Face`}),b(`span`,{className:`settings-hint`,children:`Paste the link to a GGUF model. GAIA checks that it is a chat model your model server can run and that it fits this PC before adding it. It downloads when you choose Download.`}),m(`div`,{className:`settings-row`,children:[b(`input`,{id:`custom-model-url`,className:`settings-input`,type:`url`,inputMode:`url`,spellCheck:!1,autoComplete:`off`,value:t,readOnly:s!==null,onChange:e=>{n(e.target.value),o(null),i(``),d.current=``},placeholder:`https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF`}),m(`button`,{type:`submit`,className:`btn-secondary`,disabled:s!==null||!t.trim(),children:[s===`check`?b(U,{size:13,className:`spin`}):null,` Check`]})]}),a&&(()=>{let e=b(`ul`,{className:`custom-model-checks`,"aria-label":`Checks`,children:a.checks.map(e=>m(`li`,{className:e.ok?`is-ok`:`is-failed`,children:[e.ok?b(he,{size:13,"aria-label":`Passed`}):b(cr,{size:13,"aria-label":`Failed`}),m(`span`,{children:[b(`strong`,{children:e.label}),` — `,e.detail]})]},e.id))});return a.ok?m(`details`,{className:`custom-model-checks-summary`,children:[m(`summary`,{children:[b(he,{size:13,"aria-hidden":`true`}),` All `,a.checks.length,` checks passed`]}),e]}):e})(),a&&a.warnings.length>0&&b(`ul`,{className:`custom-model-checks`,"aria-label":`Warnings`,children:a.warnings.map(e=>m(`li`,{className:`is-warning`,children:[b(Qn,{size:13,"aria-label":`Warning`}),` `,b(`span`,{children:e})]},e))}),a&&a.variants.length>1&&m(`div`,{className:`settings-row`,children:[b(`label`,{className:`settings-hint`,htmlFor:`custom-model-quant`,children:`Quantization`}),b(`select`,{id:`custom-model-quant`,className:`settings-input`,value:r,onChange:e=>void f(e.target.value),disabled:s!==null,children:a.variants.map(e=>m(`option`,{value:e.file,children:[e.quant,` · `,e.size_gb,` GB`,e.fits?``:` · too large for this PC`]},e.file))})]}),a?.ok&&m(`div`,{className:`settings-row`,children:[m(`button`,{type:`button`,className:`btn-primary`,onClick:()=>void p(),disabled:s!==null,children:[s===`add`?b(U,{size:13,className:`spin`}):null,` Add `,a.display_name]}),m(`span`,{className:`settings-hint`,children:[a.size_gb,` GB download`]})]}),l&&b(`p`,{className:`settings-error`,role:`alert`,children:l})]})}function tj(e){return e instanceof Error?e.message:String(e)}function nj(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function rj(){let e=J(),[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(null),[p,h]=(0,W.useState)(!1),[g,v]=(0,W.useState)(null),[y,x]=(0,W.useState)(null),S=Nc(e=>e.status),C=Nc(e=>e.started),w=(0,W.useMemo)(()=>Ac(S,C),[S,C]),T=Nc(e=>e.error),E=Nc(e=>e.refresh),D=Nc(e=>e.enqueue),O=Nc(e=>e.cancel),ee=(0,W.useCallback)(async(e=!1)=>{i(null);try{let t=await qi();n(t),o(n=>e||!n?bk(t):n)}catch(e){i(tj(e))}},[]);(0,W.useEffect)(()=>{ee(!0),E(),(async()=>{try{v(await Yi()??null)}catch(e){x(tj(e))}})()},[ee,E]);let k=(w?.models??[]).filter(e=>e.state===`ready`).map(e=>e.id).join(`,`),A=(0,W.useRef)(k);(0,W.useEffect)(()=>{k!==A.current&&(A.current=k,ee(!0))},[k,ee]);let j=(0,W.useMemo)(()=>{let e={};for(let t of w?.models??[])e[t.id]=t;return e},[w]),M=(0,W.useMemo)(()=>{let e={};for(let n of t?.catalog??[])e[n.id]=n.name;return e},[t]),te=(0,W.useMemo)(()=>t?bk(t):null,[t]),N=pk(t),ne=t&&a?Tk(N,a).filter(e=>j[e.id]?.state!==`downloading`):[],re=ne.reduce((e,t)=>e+(t.size_gb??0),0),ie=!!t&&!!a&&!!te&&(!nj(a.ticked,te.ticked)||a.defaultChat!==te.defaultChat||ne.length>0),P=(0,W.useCallback)(async(r,i)=>{if(!t||!a)return;if(f(null),!r){let e=Ok(N,a).filter(e=>!e.downloaded||e.id===a.defaultChat);if(e.length>0&&e.every(e=>e.need_gb!=null)){c({kind:`no_fit`,models:e});return}}let s=Dk(t,a);if(s&&!i)c({kind:`low_disk`,message:s.drop?e(`setup.summary.shortDrop`,{need:$(s.needGb),free:$(s.freeGb),drive:Uk(t.disk?.path??null)??e(`setup.summary.theDrive`),freeUp:$(s.freeUpGb),name:s.drop.name,saves:$(s.drop.size_gb??0)}):e(`setup.summary.short`,{need:$(s.needGb),free:$(s.freeGb),drive:Uk(t.disk?.path??null)??e(`setup.summary.theDrive`),freeUp:$(s.freeUpGb)})});else{u(!0);try{let i=t;if(a.defaultChat&&a.defaultChat!==i.chat_model.id)try{i=await Ji(a.defaultChat,r||p)}catch(e){let t=Ri(e);if(t){c({kind:`server`,detail:t});return}throw e}for(let e of kk(i,a))i=await Ui(e.id,e.skipped);let s=Tk(pk(i),a).map(e=>e.id).filter(e=>j[e]?.state!==`downloading`);n(i),o({...a,defaultChat:i.chat_model.id}),nc.getState().refresh(),s.length&&await D(s,{acknowledgeLowDisk:!0}),f({ok:!0,text:e(`settings.models.applied`)})}catch(e){f({ok:!1,text:tj(e)})}finally{u(!1)}}},[t,a,N,p,j,D,e]),F=(0,W.useCallback)(async t=>{c(null),u(!0),f(null);try{let r=await Gi(t.id);n(r),o(bk(r)),f({ok:!0,text:e(`settings.models.removed`,{name:t.name,size:$(r.freed_gb)})})}catch(e){f({ok:!1,text:tj(e)})}finally{u(!1)}},[e]),I=(0,W.useCallback)((e,t)=>{(async()=>{try{t===`verify`&&await Gi(e),await D([e])}catch(e){f({ok:!1,text:tj(e)})}})()},[D]),ae=!!w&&(w.models?.length??0)>0&&(yA(w)||w.models.some(e=>e.state!==`skipped`));return m(_.Fragment,{children:[m(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-models-title`,children:[b(`span`,{className:`settings-label`,id:`settings-models-title`,children:e(`settings.models.title`)}),b(`p`,{className:`settings-hint`,children:e(`settings.models.lede`)}),r&&b(`p`,{className:`settings-error`,role:`alert`,children:r}),t&&!t.lemonade.reachable&&b(`p`,{className:`settings-hint`,children:e(`settings.models.unavailable`)}),!t&&!r&&m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`,"aria-hidden":`true`}),` `,e(`setup.models.loading`)]}),t&&t.lemonade.reachable&&a&&m(_.Fragment,{children:[b(Gk,{plan:t,selection:a,onToggle:(e,t)=>o(Sk(a,N,e,t)),onDefaultChat:e=>o(Ck(a,N,e)),labelledBy:`settings-models-title`,place:`settings`,disabled:l,progress:j,rowActions:t=>t.downloaded&&t.id!==a.defaultChat?b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>c({kind:`remove`,entry:t}),disabled:l||j[t.id]?.state===`downloading`,"aria-label":e(`settings.models.removeAria`,{name:t.name}),children:e(`settings.models.remove`)}):null}),b(Hk,{plan:t,selection:a}),b(`div`,{className:`models-apply`,children:m(`button`,{type:`button`,className:`btn-primary`,disabled:!ie||l,onClick:()=>void P(!1,!1),children:[l&&b(U,{size:13,className:`spin`,"aria-hidden":`true`}),l?e(`settings.models.applying`):ne.length>0?e(`settings.models.applyDownload`,{size:$(Math.round(re*10)/10)}):e(`settings.models.apply`)]})})]}),d&&b(`p`,{className:d.ok?`settings-ok`:`settings-error`,role:d.ok?`status`:`alert`,children:d.text})]}),(g?.applies||y)&&m(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-gpu-title`,children:[b(`span`,{className:`settings-label`,id:`settings-gpu-title`,tabIndex:-1,children:e(`gpu.settingsTitle`)}),y&&b(`p`,{className:`settings-error`,role:`alert`,children:y}),g?.applies&&b(nA,{status:g,onStatus:v,mode:`settings`,names:M,headingId:`settings-gpu-title`})]}),ae&&w&&m(`section`,{className:`settings-field models-pane-section`,"aria-labelledby":`settings-downloads-title`,children:[b(`span`,{className:`settings-label`,id:`settings-downloads-title`,children:e(`settings.models.downloads`)}),b(SA,{status:w,names:M,freeGb:t?.disk?.free_gb??null,onCancel:()=>void O(),onRetry:I,onResume:e=>void D([e]),onResumeAll:()=>void D((w.models??[]).filter(e=>e.state===`cancelled`).map(e=>e.id))}),T&&b(`p`,{className:`settings-error`,role:`alert`,children:T})]}),s?.kind===`remove`&&b(qk,{title:e(`settings.models.removeTitle`,{name:s.entry.name}),confirmLabel:e(`settings.models.removeConfirm`),cancelLabel:e(`settings.models.keep`),danger:!0,onConfirm:()=>void F(s.entry),onCancel:()=>c(null),children:b(`p`,{children:mk(s.entry)?e(`settings.models.removeVision`,{size:$(s.entry.full_size_gb??0)}):e(`settings.models.removeBody`,{size:$(s.entry.full_size_gb??0)})})}),s?.kind===`no_fit`&&b(qk,{title:s.models.length===1?e(`setup.confirm.noFitOne`,{name:s.models[0].name}):e(`setup.confirm.noFitMany`),confirmLabel:e(`setup.confirm.downloadAnyway`),cancelLabel:e(`setup.confirm.pickSmaller`),onConfirm:()=>{c(null),h(!0),P(!0,!1)},onCancel:()=>c(null),children:s.models.map(t=>m(`p`,{children:[b(`bdi`,{children:t.name}),`: `,zk(t,e)]},t.id))}),s?.kind===`low_disk`&&b(qk,{title:e(`setup.confirm.lowDiskTitle`),confirmLabel:e(`setup.confirm.downloadAnyway`),cancelLabel:e(`setup.confirm.changeModels`),onConfirm:()=>{c(null),P(!0,!0)},onCancel:()=>c(null),children:b(`p`,{children:s.message})}),s?.kind===`server`&&b(qk,{title:e(`setup.confirm.noFitServerTitle`),confirmLabel:e(`setup.confirm.useAnyway`),cancelLabel:e(`setup.confirm.changeModels`),onConfirm:()=>{c(null),h(!0),P(!0,!1)},onCancel:()=>c(null),children:b(`p`,{children:s.detail.message})})]})}function ij(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(!1),c=(0,W.useCallback)(async e=>{s(!0),r(null);try{let n=await e();t(n),a(n.limit_usd==null?``:String(n.limit_usd))}catch(e){r(e instanceof Error?e.message:String(e))}finally{s(!1)}},[]);if((0,W.useEffect)(()=>{c(So)},[c]),!e)return n?b(`p`,{className:`settings-error`,role:`alert`,children:n}):m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Loading this month’s spending…`]});let l=e.limit_usd,u=i.trim()===``?null:Number(i),d=u===null||Number.isFinite(u)&&u>0,f=u!==l;return m(`section`,{className:`settings-field spending`,"aria-label":`Cloud spending`,children:[b(`span`,{className:`settings-label`,children:`Cloud spending this month`}),m(`p`,{className:`spending-total`,children:[b(`strong`,{children:Qw(e.total_usd)}),l!=null&&m(_.Fragment,{children:[` of your `,Qw(l),` limit`]}),m(`span`,{className:`settings-hint`,children:[` · `,e.turns,` cloud `,e.turns===1?`chat turn`:`chat turns`,`, at list price`]})]}),e.unpriced_turns>0&&m(`p`,{className:`settings-hint`,children:[`Plus `,e.unpriced_turns,` `,e.unpriced_turns===1?`turn`:`turns`,` on models with an unknown price, not included above.`]}),e.state===`near`&&m(`p`,{className:`spending-warning`,role:`status`,children:[b(Qn,{size:13,"aria-hidden":`true`}),` Close to your limit. GAIA stops before a cloud chat once it’s reached.`]}),e.state===`reached`&&m(`div`,{className:`spending-warning`,role:`alert`,children:[m(`p`,{children:[b(Qn,{size:13,"aria-hidden":`true`}),` You’ve reached your limit, so cloud chats are stopped until next month. Models on this PC still work.`]}),b(`button`,{type:`button`,className:`btn-secondary`,disabled:o,onClick:()=>void c(wo),children:`Allow more this month`})]}),e.state===`allowed_over`&&b(`p`,{className:`settings-hint`,children:`Over your limit; you allowed more for this month.`}),m(`form`,{className:`settings-row`,onSubmit:e=>{e.preventDefault(),d&&f&&c(()=>Co(u))},children:[b(`label`,{className:`spending-limit-label`,htmlFor:`spend-limit`,children:`Monthly limit ($)`}),b(`input`,{id:`spend-limit`,className:`settings-input`,type:`number`,min:`0.01`,step:`0.01`,inputMode:`decimal`,placeholder:`No limit`,value:i,onChange:e=>a(e.target.value),"aria-invalid":!d}),m(`button`,{type:`submit`,className:`btn-secondary`,disabled:o||!d||!f,children:[o?b(U,{size:13,className:`spin`}):null,` Save`]}),l!=null&&b(`button`,{type:`button`,className:`btn-secondary`,disabled:o,onClick:()=>void c(()=>Co(null)),children:`Remove limit`})]}),b(`span`,{className:`settings-hint`,children:`Counts cloud chats in GAIA’s Agent UI at list price, without cache discounts. Your provider’s bill is the final word. Turns that fail or are stopped before a reply aren’t counted. Models with an unknown price, like the AMD LLM Gateway’s, add nothing to the total, but are stopped too once the limit is reached.`}),n&&b(`p`,{className:`settings-error`,role:`alert`,children:n})]})}var aj=2e3;function oj(e){return e.key_source===`environment`?`Set in ${e.env_var}`:`••••••••••••••••••••${e.key_hint?` ${e.key_hint}`:``}`}function sj(){let e=nc(e=>e.active),t=nc(e=>e.select),n=nc(e=>e.refresh),r=nc(e=>e.rememberNames),[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(null),c=G(e=>e.settingsProvider),[l,u]=(0,W.useState)(c??e?.provider??`local`),[d,f]=(0,W.useState)(null),[p,h]=(0,W.useState)(null),[g,v]=(0,W.useState)(``),[y,x]=(0,W.useState)(!1),[S,C]=(0,W.useState)(``),[w,T]=(0,W.useState)(!1),[E,D]=(0,W.useState)(!1),[O,ee]=(0,W.useState)({base_url:``,auth_header_name:``,auth_header_prefix:``}),[k,A]=(0,W.useState)(null),[j,M]=(0,W.useState)(null),[te,N]=(0,W.useState)(null),[ne,re]=(0,W.useState)(null),ie=(0,W.useRef)(l);ie.current=l;let P=(0,W.useRef)(!0);(0,W.useEffect)(()=>(P.current=!0,()=>{P.current=!1}),[]);let F=i?.find(e=>e.id===l)??null,I=e=>e?.network?.reachable===!1,ae=!!F&&(!F.remote||!!F.models_discovered),oe=(0,W.useCallback)(async()=>{s(null);try{let e=await ao();a(e.providers),e.lemonade_error&&s(e.lemonade_error)}catch(e){s(e instanceof Error?e.message:String(e))}},[]),L=(0,W.useCallback)(async(e,t=!1)=>{t||(f(null),h(null));try{let t=await fo(e);r(t.models),f(t.models),M(t.memory_gb?`${t.memory_gb} GB (${t.memory_source})`:t.capacity_error??null)}catch(e){h(e instanceof Error?e.message:String(e))}},[r]);(0,W.useEffect)(()=>{oe()},[oe]);let se=!!i?.some(e=>e.key_state===`waiting_for_os_permission`);(0,W.useEffect)(()=>{if(!se)return;let e=setInterval(()=>{oe()},aj);return()=>clearInterval(e)},[se,oe]);let ce=e?.provider;(0,W.useEffect)(()=>{ce&&!c&&u(ce)},[ce,c]),(0,W.useEffect)(()=>{C(``),T(!1),D(!1),N(null),v(``),x(!1)},[l]),(0,W.useEffect)(()=>{ae?L(l):f(null)},[l,ae,L]);let le=(0,W.useCallback)(async()=>{if(F){A(`connect`),N(null);try{let e=l===`amd`?{api_key:S||void 0,...Object.fromEntries(Object.entries(O).filter(([,e])=>e!==``))}:{api_key:S||void 0},t=()=>!P.current||ie.current!==l,n=await lo(l,e,e=>{t()||N({ok:!0,text:e})},t);if(t())return;C(``),T(!1),N({ok:!0,text:n.remember_error?`Connected for this session only — the key could not be kept: ${n.remember_error}`:n.known_models?`${F.name} can't list its models right now. Your key still works, so GAIA connected using models it already knows.`:n.remembered?`Connected. The key is kept for next time.`:`Connected.`}),await oe()}catch(e){P.current&&ie.current===l&&N({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{P.current&&A(null)}}},[O,l,S,oe,F]),ue=(0,W.useCallback)(async()=>{A(`forget`),D(!1),N(null);try{await uo(l),N({ok:!0,text:`Key cleared, here and for future sessions. An environment key, if set, stays active.`}),await oe(),await n()}catch(e){N({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{A(null)}},[l,oe,n]),de=(0,W.useCallback)(async e=>{A(e),N(null);try{await t(e),N({ok:!0,text:`New messages use ${ac(e)}. It is remembered across restarts.`})}catch(e){N({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{A(null)}},[t]),fe=(0,W.useCallback)(async e=>{A(`dl:${e}`),N(null);try{await Qa(e),await L(`local`,!0)}catch(e){N({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{A(null)}},[L]),R=(0,W.useCallback)(async e=>{A(`rm:${e}`),N(null);try{let t=await bo(e);re(null);let r=t.cleared.includes(`last_model`)?` New messages use your default model.`:t.cleared.includes(`default_model`)?` It was your default model, so GAIA's own default takes its place.`:``;N({ok:!0,text:`Removed ${t.display_name} and its download.${r}`}),await L(`local`,!0),await n()}catch(e){N({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{A(null)}},[L,n]),z=(0,W.useCallback)(async e=>{N({ok:!0,text:`Added ${e}. Choose Download to fetch it, then Use.`}),await L(`local`,!0)},[L]),pe=!!d?.some(yc);(0,W.useEffect)(()=>{if(l!==`local`||!pe)return;let e=setInterval(()=>{L(`local`,!0)},aj);return()=>clearInterval(e)},[pe,l,L]);let me=(0,W.useMemo)(()=>{let e=g.trim().toLowerCase();return(d??[]).filter(t=>!e||t.id.toLowerCase().includes(e)||(t.display_name??``).toLowerCase().includes(e))},[d,g]),ge=me.filter(e=>e.available!==!1),B=l===`fireworks`&&!y&&!g.trim()&&ge.some(e=>e.rank!==null),V=t=>t.rank!==null||t.id===e?.model,_e=B?ge.filter(V):ge,ve=B?ge.filter(e=>!V(e)):[],ye=me.filter(e=>e.available===!1),be=pc(d??[]),xe=e&&!e.remote&&e.model?e.model:null,Se=t=>{let n=ic(e?.model,t.id),r=yc(t)?t.download_progress:null,i=[gc(t.placement),t.size_gb?`${t.size_gb} GB ${t.downloaded?`on disk`:`download`}`:null,t.tokens_per_second?`${Math.round(t.tokens_per_second)} tok/s measured here`:null,!t.placement&&t.context_length?`Context ${t.context_length.toLocaleString()} tokens`:null].filter(Boolean).join(` · `);return m(`li`,{className:`model-row${n?` is-current`:``}`,children:[m(`div`,{className:`model-row-text`,children:[m(`span`,{className:`model-row-name`,title:t.id,children:[be[t.id],t.rank&&m(`span`,{className:`model-row-rank`,children:[`#`,t.rank,` `,t.note]}),t.state===`loaded`&&b(`span`,{className:`model-badge is-loaded`,children:hc.loaded}),t.fits===!0&&t.available!==!1&&b(`span`,{className:`model-badge is-fit`,children:`Fits this PC`}),t.custom&&b(`span`,{className:`model-badge is-custom`,children:`Added by you`})]}),F?.remote&&b(`span`,{className:`model-row-meta${t.price?``:` is-unknown-price`}`,children:Zw(t.price)}),t.display_name&&b(`span`,{className:`model-row-meta`,children:t.id}),i&&b(`span`,{className:`model-row-meta`,children:i}),t.placement?.warning&&b(`span`,{className:`model-row-meta is-warning`,role:`alert`,children:t.placement.warning}),t.unavailable_reason&&m(`span`,{className:`model-row-meta`,children:[`Can't run here: `,t.unavailable_reason]}),t.evidence&&m(`span`,{className:`model-row-meta`,children:[`Measured: `,t.evidence]}),r&&b(`progress`,{max:100,value:r.percent,"aria-label":`Downloading ${be[t.id]}`}),t.custom&&t.source_url&&m(`span`,{className:`model-row-meta`,children:[`From `,t.source_url]})]}),t.custom&&!n&&!r&&(ne===t.id?m(`span`,{className:`model-row-confirm`,children:[m(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void R(t.id),disabled:k!==null,children:[k===`rm:${t.id}`?b(U,{size:13,className:`spin`}):null,t.downloaded?`Remove and delete download`:`Remove`]}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>re(null),disabled:k!==null,children:`Keep`})]}):b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>re(t.id),disabled:k!==null,"aria-label":`Remove ${be[t.id]}`,children:`Remove`})),n?m(`span`,{className:`model-row-current`,children:[b(he,{size:13,"aria-hidden":`true`}),` In use`]}):t.available===!1?null:r?m(`span`,{className:`model-row-current`,children:[b(U,{size:13,className:`spin`}),` `,Math.round(r.percent),`%`]}):t.downloaded?m(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void de(t.id),disabled:k!==null,"aria-label":`Use ${be[t.id]}`,children:[k===t.id?b(U,{size:13,className:`spin`}):null,` Use`]}):m(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void fe(t.id),disabled:k!==null,"aria-label":`Download ${be[t.id]}`,children:[k===`dl:${t.id}`?b(U,{size:13,className:`spin`}):null,` Download`]})]},t.id)};return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Model`}),b(`p`,{className:`settings-pane-lede`,children:`GAIA runs on this PC by default. Cloud providers are used only when you pick one of their models.`}),b(`div`,{className:`provider-tabs`,role:`radiogroup`,"aria-label":`Where GAIA runs`,children:(i??[{id:`local`,name:`Local`,remote:!1}]).map(e=>m(`button`,{type:`button`,role:`radio`,"aria-checked":l===e.id,className:`provider-tab${l===e.id?` is-active`:``}${I(e)?` is-disabled`:``}`,onClick:()=>u(e.id),disabled:I(e)&&l!==e.id,title:I(e)?e.network?.detail??void 0:void 0,children:[e.remote?b(Me,{size:14,"aria-hidden":`true`}):b(Be,{size:14,"aria-hidden":`true`}),b(`span`,{children:e.name}),e.remote&&e.models_discovered&&b(`span`,{className:`provider-tab-dot`,"aria-label":`connected`})]},e.id))}),o&&b(`p`,{className:`settings-error`,role:`alert`,children:o}),F&&m(`section`,{className:`settings-card`,"aria-label":F.name,children:[b(`p`,{className:`settings-note`,children:F.privacy_notice}),F.id===`local`&&m(`p`,{className:`settings-hint`,children:[`Each model runs where it was built to: GGUF models on the GPU, FLM models on the NPU.`,j&&` Memory for models: ${j}.`]}),F.remote&&!ae&&m(`div`,{className:`settings-field`,children:[b(`span`,{className:`settings-label`,children:`Prices`}),b(ZO,{provider:F.id})]}),I(F)&&m(`div`,{className:`settings-field`,children:[b(`p`,{className:`settings-error`,role:`alert`,children:F.network?.detail}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>void oe(),children:`Check again`})]}),F.remote&&!I(F)&&m(`form`,{className:`settings-field`,onSubmit:e=>{e.preventDefault(),le()},children:[m(`div`,{className:`settings-row settings-row-between`,children:[b(`span`,{className:`settings-label`,children:`API key`}),F.key_source&&b(`span`,{className:`settings-key-status ${ae?`settings-ok`:`settings-error`}`,children:ae?`Connected`:`Not connected`})]}),!F.key_source&&b(`span`,{className:`settings-hint`,children:F.key_state===`waiting_for_os_permission`?F.key_message??`Waiting for the OS to allow reading the saved key.`:`No key yet.`}),F.id===`amd`&&(!F.key_source||w)&&m(`div`,{className:`settings-grid`,children:[b(`input`,{className:`settings-input`,placeholder:`Gateway URL (default https://llm-api.amd.com/Unified/v1)`,value:O.base_url,onChange:e=>ee({...O,base_url:e.target.value}),"aria-label":`Gateway URL`}),b(`input`,{className:`settings-input`,placeholder:`Auth header (default Ocp-Apim-Subscription-Key)`,value:O.auth_header_name,onChange:e=>ee({...O,auth_header_name:e.target.value}),"aria-label":`Auth header name`})]}),F.key_source&&!w?m(`div`,{className:`settings-row`,children:[b(`input`,{className:`settings-input settings-key-masked`,readOnly:!0,value:oj(F),"aria-label":`Saved ${F.name} API key`}),!ae&&m(`button`,{type:`submit`,className:`btn-primary`,disabled:k!==null,children:[k===`connect`?b(U,{size:13,className:`spin`}):null,`Reconnect`]}),F.key_source!==`environment`&&(E?m(_.Fragment,{children:[b(`span`,{className:`settings-hint`,children:`Remove this key?`}),b(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void ue(),disabled:k!==null,children:`Remove`}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>D(!1),children:`Keep`})]}):m(_.Fragment,{children:[b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>T(!0),disabled:k!==null,children:`Replace`}),b(`button`,{type:`button`,className:`btn-secondary settings-key-remove`,onClick:()=>D(!0),disabled:k!==null,"aria-label":`Remove key`,title:`Remove key`,children:b(Xn,{size:14,"aria-hidden":`true`})})]}))]}):m(`div`,{className:`settings-row`,children:[b(`input`,{className:`settings-input`,type:`password`,autoComplete:`off`,spellCheck:!1,autoFocus:w,value:S,onChange:e=>C(e.target.value),placeholder:w?`Paste your new key`:`Paste API key`,"aria-label":`${F.name} API key`}),m(`button`,{type:`submit`,className:`btn-primary`,disabled:k!==null||!S,children:[k===`connect`?b(U,{size:13,className:`spin`}):null,w?`Save key`:`Connect`]}),w&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{C(``),T(!1)},disabled:k!==null,children:`Cancel`})]}),F.error&&b(`p`,{className:`settings-error`,role:`alert`,children:F.error})]}),te&&b(`p`,{className:te.ok?`settings-ok`:`settings-error`,role:te.ok?`status`:`alert`,children:te.text}),F.known_models&&m(`p`,{className:`settings-hint`,role:`status`,children:[F.name,` can't list its models right now, so GAIA is showing models it already knows. Your key still works, but this list may be out of date.`]}),F.id===`local`&&xe&&e?.downloaded!==!1&&b($A,{model:xe}),ae&&m(`div`,{className:`settings-field`,children:[b(`span`,{className:`settings-label`,children:`Models`}),(d?.length??0)>6&&b(`input`,{className:`settings-input`,type:`search`,value:g,onChange:e=>v(e.target.value),placeholder:`Search models`,"aria-label":`Search models`}),p&&b(`p`,{className:`settings-error`,role:`alert`,children:p}),!d&&!p&&m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Loading…`]}),d&&me.length===0&&b(`p`,{className:`settings-hint`,children:`No models match.`}),b(`ul`,{className:`model-list`,children:_e.map(Se)}),B&&ve.length>0&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>x(!0),children:`Show all models`}),l===`fireworks`&&y&&!g.trim()&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>x(!1),children:`Show recommended models`}),ye.length>0&&m(`details`,{className:`model-unavailable`,children:[m(`summary`,{children:[`Not available on this PC (`,ye.length,`)`]}),b(`ul`,{className:`model-list`,children:ye.map(Se)})]})]}),F.id===`local`&&ae&&b(ej,{onAdded:e=>void z(e)}),F.id===`local`&&ae&&b(rj,{}),F.remote&&b(ij,{})]})]})}function cj(){let e=G(e=>e.sessions),[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)(null),[a,o]=(0,W.useState)(!1),[s,c]=(0,W.useState)(null),l=(0,W.useCallback)(async()=>{c(null);try{let e=await Da();n(e.sessions),i(e.default_mode),G.getState().setDefaultPermissionMode(e.default_mode)}catch(e){c(e instanceof Error?e.message:String(e))}},[]);(0,W.useEffect)(()=>{l()},[l]);let u=(0,W.useCallback)(async e=>{c(null);try{await e(),await l()}catch(e){c(e instanceof Error?e.message:String(e))}},[l]),d=(0,W.useCallback)(async e=>{o(!1),await u(()=>Oa(e))},[u]),f=()=>{r===`full_access`?d(`ask`):o(e=>!e)},p=t=>e.find(e=>e.id===t)?.title??t;return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Permissions`}),b(`p`,{className:`settings-pane-lede`,children:`GAIA asks before it changes files, runs commands, or uses tools that act on your behalf. Pick a mode per chat from the shield next to the message box. “Always allow” covers one exact action in one chat and ends when GAIA restarts.`}),m(`section`,{className:`settings-card`,"aria-label":`New chats`,children:[m(`label`,{className:`setting-row`,children:[b(`span`,{className:`settings-label`,children:`Start new chats in full access`}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,checked:r===`full_access`,onChange:f,disabled:r===null,"aria-label":`Start new chats in full access`}),b(`span`,{className:`toggle-track`})]})]}),b(`p`,{className:`settings-hint`,children:r===`full_access`?`On. Every new chat runs commands and changes files without asking. Chats already open keep their mode.`:`Off. New chats ask before they change files or run commands. Chats already open keep their mode.`}),a&&m(`div`,{className:`settings-warning`,role:`alert`,children:[m(`p`,{children:[`Full access lets GAIA change or delete files and run commands on this PC without asking you first, in every new chat, until you turn this off. A mistake or a bad instruction in a document it reads can do real damage. This is the same setting as the TUI’s`,b(`code`,{children:` /full-access always`}),`.`]}),m(`div`,{className:`settings-row`,children:[b(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void d(`full_access`),children:`Turn on full access for new chats`}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>o(!1),children:`Cancel`})]})]})]}),s&&b(`p`,{className:`settings-error`,role:`alert`,children:s}),t&&t.length===0&&b(`p`,{className:`settings-hint`,children:`No chat has full access or anything allowed without asking.`}),t?.map(e=>m(`section`,{className:`settings-card`,"aria-label":p(e.session_id),children:[m(`div`,{className:`settings-row settings-row-between`,children:[b(`span`,{className:`settings-label`,children:p(e.session_id)}),e.mode===`full_access`&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>u(async()=>{let t=(await ka(e.session_id,`ask`)).mode;vT(e.session_id,t)}),children:`Turn off full access`})]}),e.grants.length>0&&b(`ul`,{className:`grant-list`,children:e.grants.map(t=>m(`li`,{className:`grant-row`,children:[b(`code`,{children:t.label}),b(`button`,{type:`button`,className:`link-btn`,onClick:()=>u(()=>Aa(e.session_id,t.key)),"aria-label":`Revoke ${t.label}`,children:`Revoke`})]},t.key))}),e.grants.length>1&&b(`button`,{type:`button`,className:`link-btn`,onClick:()=>u(()=>Aa(e.session_id)),children:`Revoke all in this chat`})]},e.session_id))]})}var lj=[{source:`agent-bundled`,title:`Built into GAIA`,note:`Ship with GAIA.`},{source:`user`,title:`Yours`,note:`From your ~/.gaia/skills folder.`,empty:`None yet. Add a folder with a SKILL.md file to ~/.gaia/skills and reopen this page.`},{source:`claude-project`,title:`From this project`,note:`In the .claude/skills folder of the project GAIA is working in. Their instructions load; any tools or commands they ask for stay off until you import them.`},{source:`claude-import`,title:`From Claude Code`,note:`Found in your Claude Code skill folders. GAIA reads them in place and does not change them.`}];function uj({onUseSkill:e}){let[t,n]=(0,W.useState)(null),[r,i]=(0,W.useState)({}),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(``);(0,W.useEffect)(()=>{let e=!1;return To().then(t=>{e||(n(t.skills),i(t.invalid))}).catch(t=>{e||o(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let l=s.trim().toLowerCase(),u=(t??[]).filter(e=>!l||e.name.toLowerCase().includes(l)||e.description.toLowerCase().includes(l)),d=t?.every(e=>lj.some(t=>t.source===e.source))??!1,f=t=>m(`li`,{className:`skill-row`,children:[m(`div`,{className:`skill-row-text`,children:[m(`span`,{className:`skill-row-name`,children:[t.name,t.version&&m(`span`,{className:`skill-row-meta`,children:[` v`,t.version]}),t.always_on&&b(`span`,{className:`skill-row-meta`,children:` · Always on`})]}),b(`span`,{className:`skill-row-desc`,children:t.description})]}),!t.always_on&&b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>e(t.name),"aria-label":`Use ${t.name} in a new chat`,children:`Use`})]},t.name);return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Skills`}),m(`p`,{className:`settings-pane-lede`,children:[`Skills teach GAIA a job — a workflow, a CLI, a document type. GAIA loads one when a request needs it, and keeps the lessons it learns while using it. Your own skills go in `,b(`code`,{children:`~/.gaia/skills`}),`, one folder each with a `,b(`code`,{children:`SKILL.md`}),` file.`]}),a&&b(`p`,{className:`settings-error`,role:`alert`,children:a}),!t&&!a&&m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` Loading…`]}),t&&t.length>6&&b(`input`,{className:`settings-input`,type:`search`,value:s,onChange:e=>c(e.target.value),placeholder:`Search skills`,"aria-label":`Search skills`}),t&&t.length===0&&b(`p`,{className:`settings-hint`,children:`No skills are installed.`}),d?lj.map(e=>{let n=u.filter(t=>t.source===e.source),r=(t??[]).filter(t=>t.source===e.source).length;return n.length===0&&(l||!e.empty)?null:m(`section`,{className:`skill-group`,"aria-label":e.title,children:[m(`h3`,{className:`skill-group-title`,children:[e.title,` `,b(`span`,{className:`skill-row-meta`,children:r})]}),b(`p`,{className:`settings-hint`,children:e.note}),n.length===0?b(`p`,{className:`settings-hint`,children:e.empty}):b(`ul`,{className:`skill-list`,children:n.map(f)})]},e.source)}):b(`ul`,{className:`skill-list`,children:u.map(f)}),Object.keys(r).length>0&&m(`div`,{className:`settings-card`,role:`alert`,children:[b(`span`,{className:`settings-label`,children:`Skipped, could not be read`}),b(`ul`,{className:`grant-list`,children:Object.entries(r).map(([e,t])=>m(`li`,{children:[b(`code`,{children:e}),` — `,t]},e))})]})]})}function dj(){let e=G(e=>e.setShowMemoryDashboard),t=G(e=>e.closeSettings),[n,r]=(0,W.useState)(null),[i,a]=(0,W.useState)(null),[o,s]=(0,W.useState)(!1);(0,W.useEffect)(()=>{TO().then(r).catch(e=>a(e instanceof Error?e.message:String(e)))},[]);let c=(0,W.useCallback)(async()=>{if(n){s(!0),a(null);try{r(await EO({memory_enabled:!n.memory_enabled}))}catch(e){a(e instanceof Error?e.message:String(e))}finally{s(!1)}}},[n]);return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Memory`}),b(`p`,{className:`settings-pane-lede`,children:`GAIA remembers facts, preferences and past conversations across chats, on this PC only. Private chats (the eye icon in a chat) are never remembered.`}),m(`label`,{className:`setting-row`,children:[b(`span`,{children:`Remember across chats`}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,checked:!!n?.memory_enabled,onChange:()=>void c(),disabled:!n||o,"aria-label":`Remember across chats`}),b(`span`,{className:`toggle-track`})]})]}),i&&b(`p`,{className:`settings-error`,role:`alert`,children:i}),b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{t(),e(!0)},children:`Open the memory dashboard`}),b(`p`,{className:`settings-hint`,children:`Search, edit and forget what GAIA remembers.`})]})}var fj=`Keep for: enter a whole number of days from 1 to 365.`,pj=`Use at most: enter a whole number of MB from 10 to 100,000.`;function mj(e,t,n){if(!/^\d+$/.test(e.trim()))return!1;let r=Number(e);return r>=t&&r<=n}function hj(e){return e<1048576?`${Math.ceil(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}function gj(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(``),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(null),[c,l]=(0,W.useState)(!1);(0,W.useEffect)(()=>{Ns().then(e=>{t(e),r(String(e.retention_days)),a(String(e.max_mb))},e=>s({ok:!1,text:`Could not read undo history settings: ${e instanceof Error?e.message:e}`}))},[]);let[u,d]=(0,W.useState)({days:!1,mb:!1}),f=!mj(n,1,365)||u.days,p=!mj(i,10,1e5)||u.mb,h=e!==null&&(n!==String(e.retention_days)||i!==String(e.max_mb)),g=async()=>{if(!(f||p)){l(!0),s(null);try{let e=await Ps(Number(n),Number(i));t(e),s({ok:!0,text:`Saved. Older undo history beyond these limits was removed.`})}catch(e){let t=e instanceof Ia&&e.httpStatus===422?e.fields:[],n=t.includes(`retention_days`),r=t.includes(`max_mb`);n||r?(d({days:n,mb:r}),s({ok:!1,text:`Not saved. Fix the limit marked above.`})):s({ok:!1,text:e instanceof Error?e.message:String(e)})}finally{l(!1)}}};return m(`div`,{className:`settings-field`,"aria-label":`Undo history`,children:[b(`span`,{className:`settings-label`,children:`Undo history`}),b(`p`,{className:`settings-hint`,children:`Before GAIA changes a file it keeps a copy, so you can undo a turn. Copies older than the time limit, or past the space limit (oldest first), are deleted. The space limit never deletes the latest turn.`}),e&&m(_.Fragment,{children:[m(`div`,{className:`setting-row`,children:[b(`label`,{htmlFor:`undo-days`,children:`Keep for (days)`}),b(`input`,{id:`undo-days`,type:`number`,className:`model-input undo-history-input`,min:1,max:365,value:n,"aria-invalid":f,"aria-describedby":f?`undo-days-error`:void 0,onChange:e=>{r(e.target.value),d(e=>({...e,days:!1}))}})]}),f&&b(`p`,{id:`undo-days-error`,className:`settings-error`,children:fj}),m(`div`,{className:`setting-row`,children:[b(`label`,{htmlFor:`undo-mb`,children:`Use at most (MB)`}),b(`input`,{id:`undo-mb`,type:`number`,className:`model-input undo-history-input`,min:10,max:1e5,value:i,"aria-invalid":p,"aria-describedby":p?`undo-mb-error`:void 0,onChange:e=>{a(e.target.value),d(e=>({...e,mb:!1}))}})]}),p&&b(`p`,{id:`undo-mb-error`,className:`settings-error`,children:pj}),m(`div`,{className:`setting-row setting-row-path`,children:[b(`span`,{children:`In use`}),m(`span`,{children:[hj(e.used_bytes),` for `,e.turns,` turn`,e.turns===1?``:`s`,` `,`in `,b(`code`,{className:`setting-path`,children:e.path})]})]}),b(`button`,{type:`button`,className:`btn-model-save`,onClick:()=>void g(),disabled:!h||c||f||p,children:c?`Saving…`:`Save`})]}),o&&b(`p`,{className:o.ok?`settings-ok`:`settings-error`,role:o.ok?`status`:`alert`,children:o.text})]})}function _j(){let e=G(e=>e.sessions),t=G(e=>e.removeSession),n=lc(),r=G(e=>e.systemStatus?.data_dir),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(null),c=(0,W.useRef)(null);(0,W.useEffect)(()=>()=>{c.current&&clearTimeout(c.current)},[]);let l=(0,W.useCallback)(async()=>{if(!i){a(!0),c.current=setTimeout(()=>a(!1),4e3);return}a(!1);let n=[];for(let r of e)try{await ko(r.id),t(r.id)}catch(e){n.push(`${r.title}: ${e instanceof Error?e.message:e}`)}s(n.length?{ok:!1,text:`Could not delete ${n.length} chat(s): ${n.join(`; `)}`}:{ok:!0,text:`All chats deleted.`})},[i,t,e]);return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Privacy`}),m(`p`,{className:`settings-pane-lede`,children:[`Chats, documents and memory stay on this PC. `,n?.remote?`Right now answers come from ${n.label}, so each message and the chat history are sent there.`:n?`Right now answers are generated on this PC too.`:`GAIA can't tell right now whether answers are generated on this PC or by a cloud provider.`]}),r&&m(`div`,{className:`setting-row`,children:[b(`span`,{children:`Data folder`}),b(`code`,{className:`setting-path`,children:r})]}),b(gj,{}),b(`div`,{className:`danger-divider`}),b(`p`,{className:`danger-warning`,children:`Deletes every chat and its messages. Documents and memory are kept.`}),b(`button`,{type:`button`,className:`btn-danger`,onClick:()=>void l(),disabled:e.length===0,children:i?`Click again to delete all chats`:`Delete all chats`}),o&&b(`p`,{className:o.ok?`settings-ok`:`settings-error`,role:o.ok?`status`:`alert`,children:o.text})]})}var vj=[{id:`needs_approval`,label:`Needs your approval`},{id:`question`,label:`Has a question`},{id:`finished`,label:`Finished`}],yj=[{value:`banner`,label:`Banner`},{value:`badge`,label:`Badge`},{value:`off`,label:`Off`}],bj=[0,10,20,30,50];function xj(){return typeof Notification>`u`?`unsupported`:Notification.permission}function Sj(){let e=il(),t=!!window.gaiaAPI,[n,r]=(0,W.useState)(xj),i=Object.values(e.modes).includes(`banner`);return m(`div`,{className:`settings-pane`,children:[b(`h2`,{className:`settings-pane-title`,children:`Notifications`}),b(`p`,{className:`settings-pane-lede`,children:`When a chat you aren't looking at needs you or finishes. A banner also counts on the badge.`}),vj.map(t=>m(`div`,{className:`setting-row`,children:[b(`span`,{id:`alert-${t.id}`,children:t.label}),b(`div`,{className:`segmented`,role:`radiogroup`,"aria-labelledby":`alert-${t.id}`,children:yj.map(n=>b(`button`,{type:`button`,role:`radio`,"aria-checked":e.modes[t.id]===n.value,className:e.modes[t.id]===n.value?`is-active`:``,onClick:()=>e.setMode(t.id,n.value),children:n.label},n.value))})]},t.id)),!t&&i&&n!==`granted`&&(n==="default"?b(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{Notification.requestPermission().then(r).catch(e=>{console.error(`[alerts] Notification permission request failed`,e),r(xj())})},children:`Allow banners in this browser`}):b(`p`,{className:`settings-error`,role:`alert`,children:n===`unsupported`?`This browser can't show banners; alerts appear in the chat list only.`:`This browser blocks banners from GAIA. Allow notifications for this site in the browser’s site settings.`})),m(`label`,{className:`setting-row`,children:[b(`span`,{children:`Play a sound`}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,checked:e.sound,onChange:()=>e.update({sound:!e.sound}),"aria-label":`Play a sound`}),b(`span`,{className:`toggle-track`})]})]}),t&&m(`label`,{className:`setting-row`,children:[b(`span`,{children:`Flash the taskbar when GAIA isn't focused`}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,checked:e.flash,onChange:()=>e.update({flash:!e.flash}),"aria-label":`Flash the taskbar when GAIA isn't focused`}),b(`span`,{className:`toggle-track`})]})]}),b(`h3`,{className:`settings-label`,children:`Keep awake`}),t?m(_.Fragment,{children:[m(`label`,{className:`setting-row`,children:[b(`span`,{children:`Keep the PC awake while GAIA works`}),m(`span`,{className:`toggle-switch`,children:[b(`input`,{type:`checkbox`,checked:e.keepAwake,onChange:()=>e.update({keepAwake:!e.keepAwake}),"aria-label":`Keep the PC awake while GAIA works`}),b(`span`,{className:`toggle-track`})]})]}),m(`div`,{className:`setting-row`,children:[b(`label`,{htmlFor:`battery-floor`,children:`On battery, let it sleep below`}),b(`select`,{id:`battery-floor`,value:e.batteryFloor,disabled:!e.keepAwake,onChange:t=>e.update({batteryFloor:Number(t.target.value)}),children:bj.map(e=>b(`option`,{value:e,children:e===0?`Never`:`${e}%`},e))})]}),b(`p`,{className:`settings-hint`,children:`The screen can still turn off; only sleep is held off.`})]}):b(`p`,{className:`settings-hint`,children:`Keep-awake needs the GAIA desktop app.`})]})}var Cj=`modulepreload`,wj=function(e,t){return new URL(e,t).href},Tj={},Ej=function(e){return e.pathname.endsWith(`.css`)},Dj=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},Oj=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=wj(t,n);let r=s(t),i=Ej(r);return Dj(Tj,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`:Cj,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)})},kj=(0,W.lazy)(()=>Oj(()=>import(`./ConnectorsPane-CLQK0rsX.js`).then(e=>({default:e.ConnectorsPane})),__vite__mapDeps([0,1,2,3]),import.meta.url)),Aj=(0,W.lazy)(()=>Oj(()=>import(`./AdvancedSettings-CHxpG8nH.js`).then(e=>({default:e.AdvancedSettings})),__vite__mapDeps([4,1,2]),import.meta.url)),jj=[`general`,`model`,`permissions`,`skills`,`connectors`,`memory`,`notifications`,`privacy`,`advanced`];function Mj({onUseSkill:e}){let t=J(),n=G(e=>e.settingsSection),r=G(e=>e.openSettings),i=G(e=>e.closeSettings),a=(0,W.useRef)(null),o=(0,W.useRef)(null),s=n!==null;if(ki(s,i),FS(a,s),(0,W.useEffect)(()=>{if(s)return o.current=document.activeElement,()=>{o.current?.focus?.()}},[s,i]),(0,W.useEffect)(()=>{s&&a.current?.querySelector(`.settings-nav-item.is-active`)?.focus()},[s]),!n)return null;let c=(()=>{switch(n){case`general`:return b(ZA,{});case`model`:return b(sj,{});case`permissions`:return b(cj,{});case`skills`:return b(uj,{onUseSkill:t=>{i(),e(t)}});case`connectors`:return b(kj,{});case`memory`:return b(dj,{});case`notifications`:return b(Sj,{});case`privacy`:return b(_j,{});case`advanced`:return b(Aj,{})}})();return b(`div`,{className:`settings-overlay`,onMouseDown:e=>{e.target===e.currentTarget&&i()},children:m(`div`,{ref:a,className:`settings-dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`settings.title`),children:[m(`nav`,{className:`settings-nav`,"aria-label":t(`settings.sections`),children:[b(`h1`,{className:`settings-nav-title`,children:t(`settings.title`)}),jj.map(e=>b(`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))]}),m(`div`,{className:`settings-body`,children:[b(`button`,{type:`button`,className:`settings-close`,onClick:i,"aria-label":t(`settings.close`),children:b(cr,{size:18})}),b(`div`,{className:`settings-scroll`,children:b(W.Suspense,{fallback:m(`p`,{className:`settings-hint`,children:[b(U,{size:13,className:`spin`}),` `,t(`settings.loading`)]}),children:c})})]})]})})}function Nj(e,t){let[n,r]=(0,W.useState)(!1),[a,o]=(0,W.useState)(!1),s=(0,W.useRef)(null),c=(0,W.useRef)(null),l=(0,W.useRef)(null),u=(0,W.useCallback)(()=>{s.current&&=(clearTimeout(s.current),null),c.current&&=(clearTimeout(c.current),null),l.current&&=(clearInterval(l.current),null)},[]);(0,W.useEffect)(()=>u,[u]);let d=(0,W.useCallback)((e,t)=>{l.current&&clearInterval(l.current),l.current=setInterval(async()=>{try{let n=await Ua();t===`load`?n.model_loaded?.toLowerCase()===e.toLowerCase()&&(r(!1),s.current&&=(clearTimeout(s.current),null),l.current&&=(clearInterval(l.current),null)):(n.model_downloaded===!0||n.model_loaded?.toLowerCase()===e.toLowerCase())&&(o(!1),c.current&&=(clearTimeout(c.current),null),l.current&&=(clearInterval(l.current),null))}catch{}},Ml)},[]),f=e??`Gemma-4-E4B-it-GGUF`;return{isLoadingModel:n,isDownloadingModel:a,loadModel:(0,W.useCallback)(async(e,t)=>{let n=e??f,a=t??32768;r(!0);try{if(!await Za(n,a)){r(!1);return}i.system.info(`Load model triggered: ${n} (ctx=${a})`),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>r(!1),Al),d(n,`load`)}catch(e){i.system.error(`Failed to trigger model load`,e),r(!1)}},[f,t,d]),downloadModel:(0,W.useCallback)(async(e=!1,t)=>{let n=t??f;o(!0);try{await Qa(n,e),i.system.info(`Download model triggered: ${n} (force=${e})`),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>o(!1),jl),d(n,`download`)}catch(e){i.system.error(`Failed to trigger model download`,e),o(!1)}},[f,d])}}var Pj=5e3,Fj=2e3,Ij=3e4,Lj=6e4;function Rj(e){return e.lemonade_running?`up`:e.lemonade_error?`unresponsive`:`down`}function zj(e){return e.kind===`slow`||e.kind===`error`||e.kind===`ok`&&Rj(e.status)===`unresponsive`}function Bj(e){let t=e.kind===`ok`?e.status.download_progress?.state:void 0;return t===`downloading`||t===`starting`}function Vj(e){let t=null,n=0,r=!1,a=null,o=0,s=null,c=async()=>{let e={controller:new AbortController,cancelled:!1};s=e;let{controller:t}=e,n=setTimeout(()=>t.abort(),Lj);try{return{kind:`ok`,status:await Ua(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),s===e&&(s=null)}},l=()=>{if(t)return t;let a=c().then(t=>{if(t!==null){n=zj(t)?n+1:0,r=Bj(t);try{e(t)}catch(e){i.system.error(`Could not apply the system status; the next poll will try again`,e)}}}).finally(()=>{t===a&&(t=null)});return t=a,a},u=()=>Math.min((r?Fj:Pj)*2**n,Ij),d=e=>{l().finally(()=>{e===o&&(a=setTimeout(()=>d(e),u()))})};return{check:l,start:()=>{let e=++o;return d(e),()=>{e===o&&(o++,a&&clearTimeout(a),a=null,s&&(s.cancelled=!0,s.controller.abort(),s=null,t=null))}}}}function Hj({onRetry:e,label:t}){let[n,r]=(0,W.useState)(!1);return b(`button`,{className:`connection-banner__retry`,onClick:()=>{r(!0),Promise.resolve(e()).finally(()=>r(!1))},disabled:n,children:n?`Checking…`:t})}function Uj({onRetry:e,backendSlow:t=!1,backendError:n=null}){let{backendConnected:r,systemStatus:i,currentSessionId:a,messages:o}=G(),[s,c]=(0,W.useState)(!1),l=!!a&&o.length>0,u=i?.default_model_name??`Gemma-4-E4B-it-GGUF`,{isDownloadingModel:d,downloadModel:f}=Nj(u),p=(0,W.useRef)(i?.lemonade_running),h=(0,W.useRef)(i?.model_downloaded),g=(0,W.useRef)(i?.context_size_sufficient),v=(0,W.useRef)(i?.expected_model_loaded);(0,W.useEffect)(()=>{if(l)return;let e=i?.lemonade_running,t=i?.model_downloaded,n=i?.context_size_sufficient,r=i?.expected_model_loaded,a=!1;p.current!==e&&(p.current=e,e===!1&&(a=!0)),h.current!==t&&(h.current=t,t===!1&&(a=!0)),g.current!==n&&(g.current=n,n===!1&&(a=!0)),v.current!==r&&(v.current=r,r===!1&&(a=!0)),a&&c(!1)},[i,l]);let y=i?.download_progress??null,x=y?.model_name||u;if(d||y?.state===`downloading`||y?.state===`starting`||y?.state===`error`){let e=y?.total_bytes?`${(y.total_bytes/1e9).toFixed(1)} GB`:`large download`,t=y?.state===`error`;return m(`div`,{className:`connection-banner ${t?`connection-banner--error`:`connection-banner--warning`}`,role:t?`alert`:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(t?Qn:We,{size:16})}),b(`div`,{className:`connection-banner__text`,dir:`auto`,children:t?m(_.Fragment,{children:[`Download of `,b(`strong`,{children:x}),` failed.`,` `,y?.message&&b(`span`,{className:`connection-banner__hint`,children:y.message})]}):m(_.Fragment,{children:[`Downloading `,b(`strong`,{children:x}),` (`,e,`).`,y?.state===`downloading`&&y.file&&m(_.Fragment,{children:[` `,m(`span`,{className:`connection-banner__hint`,children:[`File `,y.file_index,` / `,y.total_files,`: `,b(`code`,{children:y.file})]})]})]})}),t?b(`button`,{className:`connection-banner__retry`,onClick:()=>f(!1,x),children:`Retry`}):b(`span`,{className:`connection-banner__loading connection-banner__progress`,children:y&&y.state===`downloading`&&y.total_bytes>0?m(_.Fragment,{children:[b(`span`,{className:`connection-banner__progress-bar`,role:`progressbar`,"aria-valuenow":y.percent,"aria-valuemin":0,"aria-valuemax":100,"aria-label":`Download progress`,children:b(`span`,{className:`connection-banner__progress-fill`,style:{width:`${y.percent}%`}})}),m(`span`,{className:`connection-banner__progress-label`,children:[y.percent,`% ·`,` `,(y.downloaded_bytes/1e9).toFixed(2),` /`,` `,(y.total_bytes/1e9).toFixed(2),` GB`]})]}):m(_.Fragment,{children:[b(U,{size:13,className:`connection-banner__spinner`}),y?.state===`starting`?`Starting download…`:`Downloading…`]})}),t&&b(`button`,{className:`connection-banner__dismiss`,onClick:()=>c(!0),"aria-label":`Dismiss`,children:b(cr,{size:14})})]})}if(i?.init_state===`initializing`){let e=i.init_tasks?.find(e=>e.status===`running`)?.name||`Preparing AI system`;return m(`div`,{className:`connection-banner connection-banner--init`,role:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(U,{size:16,className:`connection-banner__spinner`})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[e,m(`span`,{className:`thinking-dots`,children:[b(`span`,{children:`.`}),b(`span`,{children:`.`}),b(`span`,{children:`.`})]})]})]})}if(s||l)return null;if(!r)return m(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[b(`div`,{className:`connection-banner__icon`,children:b(ir,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`Lost the connection to GAIA.`,` `,b(`span`,{className:`connection-banner__hint`,children:`Check that GAIA is still running, then retry.`})]}),e&&b(Hj,{onRetry:e,label:`Retry`})]});if(n)return m(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(Qn,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA's backend answered with an error (`,n,`).`,` `,b(`span`,{className:`connection-banner__hint`,children:`It may be overloaded. GAIA keeps checking; if it lasts, restart GAIA.`})]}),e&&b(Hj,{onRetry:e,label:`Check again`})]});if(t)return m(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(Qn,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA is slow to answer.`,` `,b(`span`,{className:`connection-banner__hint`,children:`It may be busy with another chat or app. GAIA keeps checking.`})]}),e&&b(Hj,{onRetry:e,label:`Check again`})]});if(i?.config_error)return m(`div`,{className:`connection-banner connection-banner--error`,role:`alert`,children:[b(`div`,{className:`connection-banner__icon`,children:b(Qn,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`GAIA settings could not be loaded.`,` `,b(`span`,{className:`connection-banner__hint`,children:i.config_error})]}),e&&b(Hj,{onRetry:e,label:`Check again`})]});if(i&&!i.lemonade_running){let t=Rj(i)===`unresponsive`;return m(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(Qn,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[t?`The model server is not answering (${i.lemonade_error}). It may be busy with another app or loading a model.`:`The model server isn't running.`,` `,i.start_command?m(`span`,{className:`connection-banner__hint`,children:[t?`If it stays this way, restart it: `:`To start it by hand, run `,b(`code`,{children:i.start_command})]}):i.start_instruction&&b(`span`,{className:`connection-banner__hint`,children:i.start_instruction})]}),e&&b(Hj,{onRetry:e,label:`Check again`}),b(`button`,{className:`connection-banner__dismiss`,onClick:()=>c(!0),"aria-label":`Dismiss`,children:b(cr,{size:14})})]})}if(i&&i.lemonade_running&&i.model_loaded&&i.context_size_sufficient===!1){let t=i.model_context_size??0;return m(`div`,{className:`connection-banner connection-banner--warning`,role:`status`,children:[b(`div`,{className:`connection-banner__icon`,children:b(It,{size:16})}),m(`div`,{className:`connection-banner__text`,dir:`auto`,children:[`LLM context window is too small (`,t.toLocaleString(),` tokens;`,` `,Ol.toLocaleString(),` required).`,` `,b(`span`,{className:`connection-banner__hint`,children:`Reload it with a larger context in Settings → Advanced.`})]}),e&&b(Hj,{onRetry:e,label:`Check again`}),b(`button`,{className:`connection-banner__dismiss`,onClick:()=>c(!0),"aria-label":`Dismiss`,children:b(cr,{size:14})})]})}return null}function Wj(){let e=BA(),[t,n]=(0,W.useState)(!1),[r,a]=(0,W.useState)(null),o=(0,W.useCallback)(e=>{let t=RA();t&&(a(null),t[e]().catch(t=>{let n=t instanceof Error?t.message:String(t);i.system.error(`Update ${e} failed`,t),a(n)}))},[]);if(t||e.status===`idle`||e.status===`checking`||e.status===`disabled`||e.status===`no-channel`)return null;if(e.status===`downloading`){let t=Math.max(0,Math.min(100,e.progress));return m(`div`,{className:`update-chip update-chip--downloading`,role:`status`,"aria-live":`polite`,title:`Downloading update${e.version?` ${e.version}`:``}…`,children:[b(We,{size:13,className:`update-chip__icon`}),m(`span`,{className:`update-chip__label`,children:[`Downloading update… `,t,`%`]})]})}return e.status===`available`?m(`div`,{className:`update-chip update-chip--available`,role:`status`,title:r||e.releaseNotes||`A new version is available.`,children:[b(We,{size:13,className:`update-chip__icon`}),b(`span`,{className:`update-chip__label`,children:r?`Update failed — try again`:`GAIA ${e.version??``} is available`}),!e.pinnedVersion&&b(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`downloadUpdate`),children:`Update now`}),b(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>n(!0),"aria-label":`Dismiss update notification`,children:b(cr,{size:11})})]}):e.status===`downloaded`?m(`div`,{className:`update-chip update-chip--ready`,role:`status`,"aria-live":`polite`,children:[b(Sn,{size:13,className:`update-chip__icon`}),b(`button`,{type:`button`,className:`update-chip__action`,onClick:()=>o(`restart`),title:r||`Click to restart and apply the update`,children:r?`Restart failed — try again`:`Update ready — restart to apply`})]}):e.status===`error`?m(`div`,{className:`update-chip update-chip--error`,role:`status`,title:e.error||`Update check failed.`,children:[b(Qn,{size:13,className:`update-chip__icon`}),b(`span`,{className:`update-chip__label`,children:`Update check failed`}),b(`button`,{type:`button`,className:`update-chip__dismiss`,onClick:()=>n(!0),"aria-label":`Dismiss update error`,children:b(cr,{size:11})})]}):null}var Gj={permission_request:{icon:b(Mn,{size:16}),colorClass:`notif-type-permission`,label:`Permission`},policy_alert:{icon:b(Mn,{size:16}),colorClass:`notif-type-policy`,label:`Policy`},security_alert:{icon:b(Qn,{size:16}),colorClass:`notif-type-security`,label:`Security`},status_change:{icon:b(Ce,{size:16}),colorClass:`notif-type-status`,label:`Status`},info:{icon:b(Mt,{size:16}),colorClass:`notif-type-info`,label:`Info`},error:{icon:b(xe,{size:16}),colorClass:`notif-type-error`,label:`Error`}};function Kj(e){let t=Date.now()-e,n=Math.floor(t/1e3);if(n<60)return`just now`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function qj({onClose:e}){let t=qc(hr(Yc)),n=qc(Jc),r=qc(e=>e.markRead),i=qc(e=>e.markAllRead),a=qc(e=>e.clearAll),o=qc(e=>e.dismiss),s=qc(e=>e.respondToPermission),c=qc(e=>e.typeFilter),l=qc(e=>e.setTypeFilter),u=(0,W.useCallback)(e=>{r(e)},[r]),d=(0,W.useCallback)(e=>{s(e.id,`allow`).catch(e=>console.error(`[NotificationCenter] allow failed:`,e))},[s]),f=(0,W.useCallback)(e=>{s(e.id,`deny`).catch(e=>console.error(`[NotificationCenter] deny failed:`,e))},[s]);return ki(!0,e),m(`div`,{className:`notification-center`,role:`dialog`,"aria-label":`Notification Center`,children:[m(`div`,{className:`notification-center-header`,children:[m(`div`,{className:`notification-center-title-row`,children:[b(`h2`,{className:`notification-center-title`,children:`Notifications`}),n>0&&b(`span`,{className:`notification-center-badge`,children:n})]}),b(`button`,{className:`btn-icon notification-center-close`,onClick:e,"aria-label":`Close notification center`,children:b(cr,{size:18})})]}),b(`div`,{className:`notification-filter-bar`,role:`tablist`,"aria-label":`Filter notifications`,children:[{key:null,label:`All`},{key:`permission_request`,label:`Permissions`},{key:`policy_alert`,label:`Policy`},{key:`error`,label:`Errors`},{key:`security_alert`,label:`Security`},{key:`status_change`,label:`Status`},{key:`info`,label:`Info`}].map(e=>b(`button`,{role:`tab`,"aria-selected":c===e.key,className:`notification-filter-tab ${c===e.key?`active`:``}`,onClick:()=>l(e.key),children:e.label},e.key??`all`))}),b(`div`,{className:`notification-list`,children:t.length===0?m(`div`,{className:`notification-empty`,children:[b(oe,{size:40,strokeWidth:1.2}),b(`span`,{children:`No notifications`})]}):t.map(e=>{let t=Gj[e.type];return m(`div`,{className:`notification-item ${e.read?``:`unread`} ${t.colorClass}`,id:e.type===`policy_alert`&&e.receiptId?`policy-receipt-${encodeURIComponent(e.receiptId)}`:void 0,onClick:()=>u(e.id),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&u(e.id)},children:[!e.read&&b(`span`,{className:`notification-unread-dot`}),b(`span`,{className:`notification-icon`,children:t.icon}),m(`div`,{className:`notification-content`,children:[m(`div`,{className:`notification-content-header`,children:[b(`span`,{className:`notification-agent`,children:e.agentName}),b(`span`,{className:`notification-time`,children:Kj(e.timestamp)})]}),e.title&&b(`span`,{className:`notification-title`,children:e.title}),b(`span`,{className:`notification-message`,children:e.message}),e.type===`permission_request`&&e.tool&&e.tool!==`allow_path_access`&&m(`span`,{className:`notification-tool`,children:[`Tool: `,b(`code`,{children:e.tool})]}),e.type===`policy_alert`&&m(`div`,{className:`notification-policy-details`,children:[e.tool&&m(`span`,{className:`notification-tool`,children:[`Tool: `,b(`code`,{children:e.tool})]}),e.reason&&m(`span`,{className:`notification-policy-reason`,children:[`Reason: `,e.reason]}),e.ruleIds&&e.ruleIds.length>0&&m(`span`,{className:`notification-tool`,children:[`Rules: `,b(`code`,{children:e.ruleIds.join(`, `)})]}),e.policyVersion&&m(`span`,{className:`notification-tool`,children:[`Policy: `,b(`code`,{children:e.policyVersion})]}),m(`span`,{className:`notification-tool`,children:[`Receipt:`,` `,e.receiptId?b(`code`,{children:e.receiptId}):b(`em`,{children:`Receipt unavailable`})]})]}),e.type===`permission_request`&&!e.response&&m(`div`,{className:`notification-actions`,children:[m(`button`,{className:`notification-action-btn notification-action-allow`,onClick:t=>{t.stopPropagation(),d(e)},children:[b(he,{size:14}),`Approve`]}),m(`button`,{className:`notification-action-btn notification-action-deny`,onClick:t=>{t.stopPropagation(),f(e)},children:[b(cr,{size:14}),`Deny`]})]}),e.type===`permission_request`&&e.response&&b(`span`,{className:`notification-response-badge ${e.response===`allow`?`response-allow`:`response-deny`}`,children:e.response===`allow`?`Approved`:`Denied`})]}),b(`button`,{className:`notification-dismiss`,onClick:t=>{t.stopPropagation(),o(e.id)},"aria-label":`Dismiss notification`,children:b(cr,{size:14})})]},e.id)})}),t.length>0&&m(`div`,{className:`notification-center-footer`,children:[m(`button`,{className:`notification-footer-btn`,onClick:i,disabled:n===0,children:[b(he,{size:14}),`Mark All Read`]}),m(`button`,{className:`notification-footer-btn notification-footer-clear`,onClick:a,children:[b(Xn,{size:14}),`Clear`]})]})]})}var Jj=1500,Yj=e=>new Promise(t=>setTimeout(t,e));async function Xj({onProgress:e,isCancelled:t=()=>!1,pollMs:n=Jj}={}){try{await eo(TD)}catch(e){if(e?.httpStatus!==409)throw e;let t=await to(TD).catch(()=>null);if(!t||t.status===`completed`||t.status===`failed`)throw e}for(;!t();){let t=await to(TD);if(e?.(t),t.status===`completed`)return;if(t.status===`failed`)throw Error(t.error||`The GAIA agent could not be installed.`);await Yj(n)}}function Zj({onInstalled:e}){let t=J(),[n,r]=(0,W.useState)({kind:`idle`}),i=(0,W.useRef)(!1);(0,W.useEffect)(()=>()=>{i.current=!0},[]);let a=(0,W.useCallback)(async()=>{r({kind:`installing`,percent:0});try{if(await Xj({isCancelled:()=>i.current,onProgress:e=>{i.current||r({kind:`installing`,percent:e.percent??0})}}),i.current)return;await e(),i.current||r({kind:`idle`})}catch(e){i.current||r({kind:`failed`,error:e instanceof Error?e.message:String(e)})}},[e]);return m(`div`,{className:`app-notice is-warning`,role:`status`,children:[n.kind===`installing`?b(`span`,{children:t(`agentNotice.installing`,{percent:Math.round(n.percent)})}):n.kind===`failed`?b(`span`,{children:t(`agentNotice.failed`,{error:n.error})}):b(`span`,{children:t(`agentNotice.missing`)}),n.kind!==`installing`&&b(`button`,{type:`button`,className:`link-btn`,onClick:()=>void a(),children:n.kind===`failed`?t(`agentNotice.retry`):t(`agentNotice.install`)})]})}function Qj(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 $j(e,t){let{addNotification:n}=qc.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 eM=xr((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 Ss()).schedules||[],r=t().errorCounts;r&&$j(r,n),e({schedules:n,loading:!1,errorCounts:Object.fromEntries(n.map(e=>[e.id,e.error_count]))})}catch(t){i.api.error(`Failed to load schedules`,t),e({error:`Failed to load schedules`,loading:!1})}},createSchedule:async(t,n,r)=>{try{let i=await ws(t,n,r);e(e=>({schedules:[...e.schedules,i],actionError:null}))}catch(e){throw i.api.error(`Failed to create schedule`,e),e}},updateScheduleStatus:async(t,n)=>{try{let r=await Ts(t,n);e(e=>({schedules:e.schedules.map(e=>e.name===t?r:e),actionError:null}))}catch(n){i.api.error(`Failed to update schedule "${t}"`,n),e({actionError:Qj(n,`Failed to update schedule`)})}},runScheduleNow:async t=>{try{let n=await Es(t);e(e=>({schedules:e.schedules.map(e=>e.name===t?n:e),actionError:null}))}catch(n){i.api.error(`Failed to run schedule "${t}" now`,n),e({actionError:Qj(n,`Could not run the schedule now`)})}},deleteSchedule:async t=>{try{await Ds(t),e(e=>({schedules:e.schedules.filter(e=>e.name!==t),selectedSchedule:e.selectedSchedule===t?null:e.selectedSchedule,actionError:null}))}catch(n){i.api.error(`Failed to delete schedule "${t}"`,n),e({actionError:Qj(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 Os(n);if(t().selectedSchedule!==n)return;e({results:r.results||[],resultsLoading:!1})}catch(r){if(i.api.error(`Failed to load results for "${n}"`,r),t().selectedSchedule!==n)return;e({results:[],resultsLoading:!1})}},dismissActionError:()=>e({actionError:null})})),tM=new Set([`loading_model`,`downloading_model`,`model_retry`,`waiting`]),nM=5;function rM(e,t){return{id:e,title:t.get(e)?.title??`Untitled chat`}}function iM(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=>({...rM(e,t),reason:`approval`}));n&&e.awaitingUser&&!a.has(e.currentSessionId)&&o.push({...rM(e.currentSessionId,t),reason:`answer`});for(let[n,r]of Object.entries(e.awaitingBySession))o.some(e=>e.id===n)||o.push({...rM(n,t),reason:r===`question`?`answer`:`approval`});let s=n&&!e.awaitingUser&&e.livePhase&&tM.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,nM).map(e=>rM(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=>rM(e,t)),needsYou:o,recent:u}}function aM(e){let t=(0,W.useRef)(e);t.current=e,(0,W.useEffect)(()=>{let e=window.gaiaAPI?.tray;if(!e)return;let n=``,r=null,a=()=>{let t=G.getState(),a={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:qc.getState().notifications},o=r;if(r=a,o&&Object.keys(a).every(e=>a[e]===o[e]))return;let s=iM(a),c=JSON.stringify(s);c!==n&&(n=c,e.setActivity(s).catch(e=>{n=``,i.system.error(`The tray could not take the app state`,e)}))};a();let o=G.subscribe(a),s=qc.subscribe(a),c=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`:G.getState().openSettings(e.section);break;case`refresh-status`:t.current.refreshStatus();break;default:i.system.error(`Unknown tray command`,e)}});return()=>{o(),s(),c()}},[])}function oM(){(0,W.useEffect)(()=>{let e=window.gaiaAPI;if(!e)return;let t=qc.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=G.getState();n.currentSessionId!==t&&n.setMessages([]),n.setCurrentSession(t)})];return()=>n.forEach(e=>e())},[])}function sM(e,t,n){let r=window.gaiaAPI;if(r){r.notification.show({title:t,body:n,sessionId:e}).then(e=>{e||i.system.warn(`This OS has no desktop notifications; the badge still counts it.`)}).catch(e=>i.system.error(`Could not show the desktop notification`,e));return}if(typeof Notification>`u`){i.system.warn(`This browser has no notifications; the alert was not shown.`);return}if(Notification.permission!==`granted`){i.system.warn(`Browser notifications are ${Notification.permission}; allow them in Settings → Notifications.`);return}let a=new Notification(t,{body:n,tag:`gaia-${e}`});a.onclick=()=>{window.focus(),G.getState().setCurrentSession(e)}}function cM(){let[e,t]=(0,W.useState)(null);return(0,W.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=>i.system.warn(`Battery level unavailable; keep-awake ignores the battery policy.`,e)),()=>{n?.removeEventListener(`levelchange`,r),n?.removeEventListener(`chargingchange`,r)}},[]),e}function lM(){oM();let e=G(e=>e.runningSessionIds),t=G(e=>e.awaitingBySession),n=G(e=>e.sessions),r=G(e=>e.currentSessionId),a=qc(hr(Zc)),o=il(),s=cM(),c=(0,W.useRef)(null),l=dl(e,t,a),u=JSON.stringify(l);(0,W.useEffect)(()=>{let e=JSON.parse(u),t=c.current;if(c.current=e,t===null)return;let{sessions:n,currentSessionId:r}=G.getState(),a=document.hasFocus(),s=!1;for(let{sessionId:c,event:l}of fl(t,e)){let e=n.find(e=>e.id===c);if(e?.kind===`eval`||e?.kind===`scheduled`)continue;let t=o.modes[l];if(!(t===`off`||hl(c,r,a))&&(s=!0,t===`banner`)){if(l!==`finished`){let{title:t,body:n}=ml(l,e);sM(c,t,n)}else Ao(c).then(e=>{G.getState().updateSessionInList(c,e);let{title:t,body:n}=ml(l,e);sM(c,t,n)}).catch(t=>{i.system.error(`Could not read how chat ${c} ended`,t);let{title:n,body:r}=ml(l,{...e,last_run_status:null});sM(c,n,r)})}}if(s){if(o.sound)try{vl()}catch(e){i.system.warn(`Alert sound not played`,e)}o.flash&&!a&&window.gaiaAPI&&window.gaiaAPI.notification.flash().catch(e=>i.system.error(`Could not flash the taskbar button`,e))}},[u,o.modes,o.sound,o.flash]);let d=gl(n,l,o.modes,r);(0,W.useEffect)(()=>{window.gaiaAPI?.notification.setAttentionCount(d).catch(e=>i.system.error(`Could not update the taskbar badge`,e))},[d]);let f=o.keepAwake&&e.length>0&&_l(s,o.batteryFloor);(0,W.useEffect)(()=>{window.gaiaAPI?.power.setKeepAwake(f).catch(e=>i.system.error(`Could not change keep-awake`,e))},[f])}function uM(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 dM(e){return e.replace(/-/g,``).slice(0,7)}function fM(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 pM(e,t,n){return!e||t&&(e===t||e===dM(t))?null:n.some(t=>t.id===e)?e:fM(n,e)}function mM(e){return new URLSearchParams(e.search).get(`session`)||e.hash.replace(/^#/,``)||null}var hM=`gaia:last-session`;function gM(e){try{e?localStorage.setItem(hM,e):localStorage.removeItem(hM)}catch(e){i.ui.warn(`Could not save the open chat for the next launch`,e)}}function _M(){try{return localStorage.getItem(hM)}catch(e){return i.ui.warn(`Could not read the chat open at last launch`,e),null}}var vM=1e3,yM=3e4;function bM(e,{initialMs:t=vM,maxMs:n=yM,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 xM(e,t,n){return e&&!t&&!n}var SM=(0,W.lazy)(()=>Oj(()=>import(`./MemoryDashboard-D5NugQoq.js`).then(e=>({default:e.MemoryDashboard})),__vite__mapDeps([5,1,2,6,7]),import.meta.url)),CM=(0,W.lazy)(()=>Oj(()=>import(`./ScheduleManager-CkYWygZG.js`).then(e=>({default:e.ScheduleManager})),__vite__mapDeps([8,1,2,6,9]),import.meta.url)),wM=(0,W.lazy)(()=>Oj(()=>import(`./DocumentLibrary-hSat3aHA.js`).then(e=>({default:e.DocumentLibrary})),__vite__mapDeps([10,1,2,11]),import.meta.url)),TM=(0,W.lazy)(()=>Oj(()=>import(`./FileBrowser-BneKS6fe.js`).then(e=>({default:e.FileBrowser})),__vite__mapDeps([12,1,2,13]),import.meta.url)),EM=(0,W.lazy)(()=>Oj(()=>import(`./MobileAccessModal-Cl7eErMB.js`).then(e=>({default:e.MobileAccessModal})),__vite__mapDeps([14,1,2,15]),import.meta.url)),DM=3,OM=3e5,kM=6e3,AM=6e4,jM=e=>e instanceof TypeError,MM=e=>new Promise(t=>setTimeout(t,e));function NM(){return b(`div`,{className:`loading-spinner`,role:`status`,"aria-label":`Loading`})}var PM=e=>e===1||e%10==0;function FM(){let e=G(e=>e.currentSessionId),t=G(e=>e.setSessions),n=G(e=>e.setCurrentSession),a=G(e=>e.addSession),o=G(e=>e.setMessages),s=G(e=>e.showDocLibrary),c=G(e=>e.showFileBrowser),l=G(e=>e.showMemoryDashboard),u=G(e=>e.showSchedules),d=G(e=>e.sidebarOpen),f=G(e=>e.sidebarCollapsed),p=G(e=>e.setSidebarOpen),h=G(e=>e.setSystemStatus),g=G(e=>e.setBackendConnected),_=G(e=>e.setAgents),v=G(e=>e.agents),y=G(e=>e.setPendingPrompt),x=G(e=>e.setDefaultPermissionMode),C=G(e=>e.openSettings),w=G(e=>e.settingsSection),T=G(e=>e.syncSystemTheme),E=nc(e=>e.restoreNotice),D=nc(e=>e.dismissRestoreNotice),O=qc(e=>e.showPanel),ee=G(e=>e.systemStatus?.initialized===!0),k=(0,W.useRef)(!1),A=qc(e=>e.setShowPanel);(0,W.useEffect)(()=>{if(!E?.ok)return;let e=setTimeout(D,kM);return()=>clearTimeout(e)},[E,D]);let[j,M]=(0,W.useState)({state:`checking`}),te=(0,W.useRef)(j);te.current=j;let[N,ne]=(0,W.useState)(!1),re=(0,W.useRef)(N);re.current=N;let[ie,P]=(0,W.useState)(!1),F=ie||N&&!ED(v),I=(0,W.useRef)(F);I.current=F;let[ae,oe]=(0,W.useState)(null),[L,se]=(0,W.useState)(``),[ce,le]=(0,W.useState)(0),[ue,de]=(0,W.useState)(!1),[fe,R]=(0,W.useState)(!1),[z,pe]=(0,W.useState)(null),me=(0,W.useRef)(async()=>{}),he=(0,W.useRef)(async()=>{}),ge=(0,W.useCallback)(async(e=!1,t=!1)=>{e||M({state:`checking`});let n=0;try{for(;;){await nc.getState().refresh();let e=nc.getState().active,r;try{r=await Bi(!!e?.remote)}catch(e){if(!t||!jM(e)||n>=AM)throw e;await MM(vM),n+=vM;continue}n>0&&await Promise.all([me.current(),he.current()]),M(r.ready?{state:`ready`}:{state:`needed`,check:r});return}}catch(e){let t=e instanceof Error?e.message:String(e);i.system.warn(`Setup check could not be answered`,e),M({state:`unknown`,error:t})}},[]),B=(0,W.useRef)(0),V=(0,W.useCallback)(async()=>{let e=++B.current,t=(await $a()).agents||[];e===B.current&&(_(t),ne(!0),ED(t)&&P(!1))},[_]),_e=(0,W.useCallback)(()=>{let e=re.current;ne(!1),V().catch(t=>{i.api.warn(`Agent list unavailable after setup`,t),e&&ne(!0)})},[V]);(0,W.useEffect)(()=>{let e=()=>{I.current&&V().catch(e=>i.api.warn(`Agent list unavailable`,e))};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[V]);let ve=(0,W.useCallback)(async()=>{x((await Da()).default_mode)},[x]),ye=(0,W.useRef)([]);(0,W.useEffect)(()=>{r(`0.25.4rc3`),ge(!1,!0);let e=[bM(V,{onError:(e,t)=>{PM(t)&&i.api.warn(`Agent list unavailable (attempt ${t}); retrying`,e)}}),bM(ve,{onError:(e,t)=>{PM(t)&&i.api.warn(`Default permission mode unavailable (attempt ${t}); retrying`,e)}})];return ye.current=e,()=>e.forEach(e=>e.stop())},[ge,V,ve]);let be=(0,W.useCallback)(()=>{ye.current.forEach(e=>e.kick()),nc.getState().retryNow(),he.current(),te.current.state===`unknown`&&ge(!0)},[ge]),xe=(0,W.useRef)(be);xe.current=be;let Se=(0,W.useRef)(0),Ce=(0,W.useRef)(0),we=(0,W.useRef)(null),Te=(0,W.useRef)(!1),[Ee,H]=(0,W.useState)(!1),[De,Oe]=(0,W.useState)(null),ke=(0,W.useCallback)(e=>{if(e.kind===`unreachable`){i.system.warn(`System status check failed`,e.error),Te.current=!0,Ce.current=0,we.current=null,H(!1),Oe(null),g(!1),h(null);return}if(e.kind===`error`){i.system.warn(`System status answered HTTP ${e.httpStatus}`,e.message),Te.current&&xe.current(),Te.current=!1,Ce.current=0,we.current=null,H(!1),Oe(`HTTP ${e.httpStatus}: ${e.message}`),g(!0);return}if(e.kind===`slow`){if(Ce.current+=1,we.current??=Date.now(),Oe(null),i.system.warn(`System status did not answer in time (${Ce.current} in a row)`),Date.now()-we.current>=OM){H(!1),g(!1),h(null);return}g(!0),(Te.current||Ce.current>=DM)&&H(!0);return}let{status:t}=e;Te.current&&xe.current(),Te.current=!1,Ce.current=0,we.current=null,H(!1),Oe(null),g(!0),Se.current=t.lemonade_running?0:Se.current+1;let n=G.getState().systemStatus;t.lemonade_running||Se.current>=DM||!n?.lemonade_running?h(t):h({...n,download_progress:t.download_progress})},[g,h]),Ae=(0,W.useRef)(ke);Ae.current=ke;let[je]=(0,W.useState)(()=>Vj(e=>Ae.current(e))),Me=je.check;me.current=Me,(0,W.useEffect)(()=>jD(je.start),[je]);let Ne=(0,W.useRef)(``);(0,W.useEffect)(()=>{let e=e=>Eo().then(n=>{let r=n.sessions||[];if(!e&&r.length===0&&G.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(`
78
78
  `);if(i===Ne.current)return;Ne.current=i,t(r);let a=nc.getState().active?.model;a&&r.some(e=>e.effective_model&&e.effective_model!==a)&&nc.getState().refresh()}).catch(t=>{e&&i.system.error(`Could not load chats`,t)});he.current=()=>e(!1),e(!0);let n=setInterval(()=>void e(!1),5e3);return()=>clearInterval(n)},[t]),(0,W.useEffect)(()=>sw(),[]),(0,W.useEffect)(()=>{let e=()=>{eM.getState().loadSchedules()};e();let t=setInterval(e,3e4);return()=>clearInterval(t)},[]),(0,W.useEffect)(()=>Ow(),[]),lM();let Pe=(0,W.useRef)(!1),Fe=(0,W.useRef)(!1);(0,W.useEffect)(()=>{let e=()=>{let e=mM(window.location),{currentSessionId:t,sessions:r}=G.getState(),i=pM(e,t,r);return i&&(n(i),o([])),i},t=()=>{if(Pe.current||(Pe.current=!0,e()||G.getState().currentSessionId))return;if(window.location.hash){window.history.replaceState(null,``,window.location.pathname+window.location.search);return}if(Fe.current||Fi(`new-chat`))return;let{sessions:t}=G.getState(),r=pM(_M(),null,t);r&&(n(r),o([]))},r=G.subscribe(e=>{e.sessions.length>0&&t()});return G.getState().sessions.length>0&&t(),window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{r(),window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[n,o]),(0,W.useEffect)(()=>{let e=null,t=2e3,r=!1,a=null,s=()=>{r||(e=new EventSource(`${S()}/sessions/events`),e.onopen=()=>{t=2e3},e.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch(e){i.api.warn(`Malformed session event`,e);return}t.type===`set_active_session`&&t.session_id&&t.session_id!==G.getState().currentSessionId&&(n(t.session_id),o([]))},e.onerror=()=>{e?.close(),e=null,!r&&(a=setTimeout(s,t),t=Math.min(t*2,3e4))})};return s(),()=>{r=!0,a&&clearTimeout(a),e?.close()}},[n,o]),(0,W.useEffect)(()=>{if(Pe.current&&gM(e),e){let t=dM(e);window.location.hash!==`#${t}`&&window.history.replaceState(null,``,`#${t}`)}else Pe.current&&window.location.hash&&window.history.replaceState(null,``,window.location.pathname+window.location.search)},[e]);let Ie=(0,W.useCallback)(async e=>{oe(null);let t=G.getState(),r;try{r=await Do({title:`New Task`,agent_type:TD,document_ids:t.draftDocumentIds,private:t.draftPrivate,folders:t.draftFolder?[t.draftFolder]:[]})}catch(e){throw DD(e)?(P(!0),Error(`The GAIA agent isn't installed. Install it from the notice above, then send again.`)):e}I.current&&(P(!1),V().catch(e=>i.api.warn(`Agent list unavailable`,e))),t.defaultPermissionModeKnown||(await ve().catch(e=>i.api.warn(`Default permission mode unavailable; using the chip's mode`,e)),t=G.getState()),t.clearDraftDocuments(),t.setDraftPrivate(!1),t.setDraftFolder(null);let s=null;try{await ka(r.id,t.draftPermissionMode)}catch(e){s=e}return Li(Pi),s&&!r.private&&Ii(Ni(r.id),e),a(r),n(r.id),o([]),se(``),s?(oe(`The chat was created, but its permission mode could not be set, so your message was not sent${r.private?``:` — it is in the chat's box`}: ${s instanceof Error?s.message:s}`),!1):(t.resetDraftPermissionMode(),y({sessionId:r.id,text:e}),!0)},[a,n,o,y,V,ve]),Le=(0,W.useCallback)(()=>{let e=G.getState(),t=e.currentSessionId;t&&El(t,e)&&Dl(t),e.setShowMemoryDashboard(!1),e.setShowSchedules(!1),Fe.current=!0,n(null),o([]),le(e=>e+1)},[n,o]);aM({openChat:(0,W.useCallback)(e=>{let t=G.getState();t.closeSettings(),e!==t.currentSessionId&&(Dl(t.currentSessionId),o([])),n(e)},[n,o]),newChat:(0,W.useCallback)(()=>{G.getState().closeSettings(),Le()},[Le]),refreshStatus:()=>void Me()});let Re=(0,W.useCallback)(e=>{Le(),Ie(`Load the \`${e}\` skill, then tell me briefly what it lets you do.`).catch(e=>oe(e instanceof Error?e.message:String(e)))},[Le,Ie]),ze=(0,W.useCallback)(e=>{M({state:`ready`}),_e(),Me(),e&&(e.needs_input?se(e.prompt):Ie(e.prompt).catch(e=>oe(e instanceof Error?e.message:String(e))))},[Me,Ie,_e]);(0,W.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&(e.shiftKey&&e.key.toLowerCase()===`o`?(e.preventDefault(),Le()):!e.shiftKey&&e.key.toLowerCase()===`k`?(e.preventDefault(),window.dispatchEvent(new CustomEvent(`gaia:focus-search`))):!e.shiftKey&&e.key.toLowerCase()===`b`?(e.preventDefault(),G.getState().toggleSidebarCollapsed()):!e.shiftKey&&e.key===`,`&&(e.preventDefault(),C()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Le,C]),(0,W.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,W.useEffect)(()=>{if(typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(prefers-color-scheme: light)`);return e.addEventListener(`change`,T),()=>e.removeEventListener(`change`,T)},[T]),(0,W.useEffect)(()=>{bs().then(e=>R(e.active===!0)).catch(e=>i.system.debug(`Mobile access unavailable`,e))},[]);let Be=(0,W.useCallback)(async()=>{if(de(!0),pe(null),!fe)try{let e=await vs();e.error?pe(e.error):R(!0)}catch(e){pe(e instanceof Error?e.message:`Could not start mobile access`)}},[fe]),Ve=(0,W.useCallback)(async()=>{try{await ys(),R(!1),de(!1)}catch(e){pe(e instanceof Error?e.message:`Could not stop mobile access`)}},[]);kE(e=>{e?Be():Ve()}),(0,W.useEffect)(()=>{DE(fe)},[fe]);let He=typeof window<`u`&&window.innerWidth<=768,Ue=xM(j.state===`checking`,ee,k.current);if(!Ue&&j.state!==`needed`&&(k.current=!0),Ue)return b(`div`,{className:`app`,children:m(`main`,{className:`startup`,role:`status`,"aria-label":`Starting GAIA`,children:[b(`div`,{className:`loading-spinner`,"aria-hidden":`true`}),b(`p`,{className:`startup-text`,children:`Starting GAIA…`})]})});if(j.state===`needed`)return b(`div`,{className:`app`,children:b(PA,{onReady:ze})});let We=l?b(W.Suspense,{fallback:b(NM,{}),children:b(SM,{})}):e?b(BD,{sessionId:e},e):b(YO,{onSend:Ie,initialText:L,focusRequest:ce},L);return m(`div`,{className:`app`,children:[!d&&b(`button`,{className:`sidebar-toggle`,onClick:()=>p(!0),"aria-label":`Open sidebar`,children:b(Yt,{size:18})}),b(`div`,{className:`sidebar-overlay ${d?`visible`:``}`,onClick:()=>p(!1),"aria-hidden":`true`}),b(tu,{onNewChat:Le,onMobileAccess:He?void 0:()=>void Be(),tunnelActive:fe}),m(`div`,{className:`main-content`,children:[j.state===`ready`&&b(Uj,{onRetry:Me,backendSlow:Ee,backendError:De}),j.state===`unknown`&&m(`div`,{className:`app-notice is-warning`,role:`status`,children:[m(`span`,{children:[`Could not check whether GAIA is set up: `,j.error]}),b(`button`,{type:`button`,className:`link-btn`,onClick:()=>void ge(),children:`Check again`})]}),(!d||f)&&b(Pc,{placement:`main`}),F&&b(Zj,{onInstalled:V}),E&&m(`div`,{className:`app-notice${E.ok?``:` is-warning`}`,role:`status`,children:[b(`span`,{children:E.message}),!E.ok&&b(`button`,{type:`button`,className:`link-btn`,onClick:()=>{D(),C(`model`)},children:`Pick a model`}),b(`button`,{type:`button`,className:`app-notice-close`,onClick:D,"aria-label":`Dismiss`,children:b(cr,{size:14})})]}),We]}),u&&b(W.Suspense,{fallback:null,children:b(CM,{})}),s&&b(W.Suspense,{fallback:null,children:b(wM,{})}),c&&b(W.Suspense,{fallback:null,children:b(TM,{onStartChat:Ie})}),O&&b(`div`,{className:`notification-center-popover`,children:b(qj,{onClose:()=>A(!1)})}),ue&&b(W.Suspense,{fallback:null,children:b(EM,{isOpen:ue,onClose:()=>de(!1),onStop:()=>void Ve(),error:z})}),w&&b(Mj,{onUseSkill:Re}),b(Wj,{}),ae&&b(`div`,{className:`toast`,role:`alert`,children:ae})]})}Lc(),Er();var IM=localStorage.getItem(`gaia-chat-theme`);Tr(Cr(IM===`light`||IM===`dark`?IM:`system`));var LM=G.getState();Kr(LM.palette,LM.customColors,LM.theme),l(LM.locale),Ar(),kr(),lr.createRoot(document.getElementById(`root`)).render(b(W.StrictMode,{children:b(FM,{})}));export{rs as $,Bt as $t,xO as A,la as At,Lw as B,er as Bt,iO as C,aa as Ct,uO as D,sa as Dt,rO as E,oa as Et,bO as F,ki as Ft,kl as G,On as Gt,jw as H,Xn as Ht,OO as I,G as It,J,mn as Jt,Ol as K,Sn as Kt,NO as L,cr as Lt,_O as M,ua as Mt,yO as N,ta as Nt,mO as O,na as Ot,vO as P,fa as Pt,os as Q,Wt as Qt,fO as R,or as Rt,aO as S,I as Sn,ia as St,TO as T,ca as Tt,Nw as U,Hn as Ut,zw as V,Qn as Vt,FS as W,Bn as Wt,cs as X,$t as Xt,ac as Y,un as Yt,us as Z,U as Zt,sO as _,ye as _n,Ya as _t,XO as a,Qe as an,Ua as at,lO as b,he as bn,ma as bt,PO as c,We as cn,es as ct,wO as d,Ie as dn,ks as dt,Et as en,is as et,gO as f,Ae as fn,_s as ft,cO as g,xe as gn,qa as gt,FO as h,Ce as hn,io as ht,Oj as i,ot as in,Ja as it,SO as j,pa as jt,AO as k,da as kt,DO as l,He as ln,Za as lt,oO as m,Te as mn,gs as mt,eM as n,ut as nn,xs as nt,BO as o,Je as on,bs as ot,jO as p,Oe as pn,ss as pt,xl as q,bn as qt,Nj as r,ct as rn,Ka as rt,MO as s,Ke as sn,ds as st,uM as t,gt as tn,no as tt,CO as u,Be as un,fs as ut,pO as v,_e as vn,ns as vt,dO as w,ha as wt,kO as x,le as xn,ra as xt,hO as y,B as yn,ts as yt,EO as z,nr as zt};