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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{I as t,J as n,N as r,a as i,c as a,f as o,l as s,q as c,r as l,t as u,u as d}from"./useT-BNShbVIz.js";import{n as ee,t as te}from"./zap-BP1leAhK.js";import{A as ne,B as re,C as ie,D as ae,E as oe,F as se,Ft as ce,G as f,H as le,Ht as ue,I as de,It as fe,Kt as p,L as pe,Lt as me,M as he,N as m,Nt as ge,O as _e,P as h,Pt as ve,R as ye,S as be,St as xe,T as Se,U as Ce,Ut as we,V as Te,W as Ee,Wt as De,X as Oe,_ as ke,_t as Ae,at as je,b as Me,dt as Ne,ft as Pe,g as Fe,gt as Ie,h as Le,j as Re,k as ze,kt as Be,lt as Ve,m as He,mt as Ue,ot as We,p as Ge,st as Ke,t as qe,ut as Je,v as Ye,vt as Xe,w as Ze,x as Qe,y as $e,z as et,zt as tt}from"./index-B3y-e0-u.js";var g={name:`arrow-left`,size:24,node:[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]};g.node;var nt=c(g),rt={name:`git-merge`,size:24,node:[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]};rt.node;var it=c(rt),_={name:`shield-off`,size:24,node:[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]};_.node;var at=c(_),ot={name:`shield`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]};ot.node;var st=c(ot),v={name:`target`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`6`,key:`1vlfrh`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]};v.node;var ct=c(v),lt={name:`trending-up`,size:24,node:[[`path`,{d:`M16 7h6v6`,key:`box55l`}],[`path`,{d:`m22 7-8.5 8.5-5-5L2 17`,key:`1t1m79`}]]};lt.node;var ut=c(lt),dt={name:`user`,size:24,node:[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]};dt.node;var ft=c(dt),y=e(n(),1),pt=[{title:`mem.about.group.preferences`,categories:[`preference`]},{title:`mem.about.group.about`,categories:[`fact`,`profile`,`skill`]},{title:`mem.about.group.reminders`,categories:[`reminder`]},{title:`mem.about.group.notes`,categories:[`note`]}],mt={user:`mem.source.user`,tool:`mem.source.tool`,llm_extract:`mem.source.llm_extract`,consolidation:`mem.source.consolidation`,inferred:`mem.source.inferred`,discovery:`mem.source.discovery`};function ht(e){return mt[e]??`mem.source.other`}function gt(e,t){let n=new Date(e);if(Number.isNaN(n.getTime()))return null;let i=Math.floor((Date.now()-n.getTime())/864e5);return i<=0?r(`mem.day.today`):i===1?r(`mem.day.yesterday`):i<30?r(`mem.day.daysAgo`,{n:i}):n.toLocaleDateString(u(t),{month:`short`,day:`numeric`,year:`numeric`})}function _t(e,t=new Date,n=l){let r=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e),i=r?new Date(+r[1],r[2]-1,+r[3]):new Date(e);if(Number.isNaN(i.getTime()))return null;let a=i.getHours()===0&&i.getMinutes()===0&&i.getSeconds()===0,o=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),s=a?i.getTime()<o:i.getTime()<t.getTime(),c=i.toLocaleString(u(n),{weekday:`short`,month:`short`,day:`numeric`,...i.getFullYear()===t.getFullYear()?{}:{year:`numeric`},...a?{}:{hour:`numeric`,minute:`2-digit`}});return{text:n(s?`mem.due.past`:`mem.due.upcoming`,{when:c}),past:s}}function vt({memoryEnabled:e,reloadKey:n,onChanged:o,onOpenAdvanced:c,showToast:l}){let u=i(),[ee,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(null),[ae,oe]=(0,y.useState)(null),[se,ce]=(0,y.useState)(``),[f,le]=(0,y.useState)([]),[ue,de]=(0,y.useState)(new Set),[fe,p]=(0,y.useState)(``),[pe,me]=(0,y.useState)(`fact`),[he,m]=(0,y.useState)(null),ge=(0,y.useRef)(0),h=(0,y.useCallback)(async()=>{let e=++ge.current;try{let t=await _e({about_user:!0,include_sensitive:!0,sort_by:`updated_at`,order:`desc`,limit:200});if(e!==ge.current)return;te(t.items),re(null)}catch(n){if(e!==ge.current)return;t.system.warn(`Failed to load what GAIA knows about the user`,n),re(n instanceof Error?n.message:String(n))}},[]);(0,y.useEffect)(()=>{h()},[h,n]);let ve=(0,y.useCallback)(async e=>{let n=se.trim();if(!n||n===e.content)oe(null);else{m(e.id);try{await ie(e.id,{content:n}),oe(null),l(u(`mem.about.updated`),`success`),await h(),o()}catch(e){t.system.error(`Failed to edit memory`,e),l(u(`mem.about.editFailed`,{error:b(e)}),`error`)}finally{m(null)}}},[se,h,o,l,u]),ye=(0,y.useCallback)(async e=>{m(e.id);try{await be(e.id),ge.current++,te(t=>(t??[]).filter(t=>t.id!==e.id)),le(t=>[e,...t]),o()}catch(e){t.system.error(`Failed to forget memory`,e),l(u(`mem.about.forgetFailed`,{error:b(e)}),`error`)}finally{m(null)}},[o,l,u]),xe=(0,y.useCallback)(async e=>{m(e.id);try{await Me({content:e.content,category:e.category,domain:e.domain??void 0,context:e.context,entity:e.entity??void 0,sensitive:e.sensitive,due_at:e.due_at??void 0}),le(t=>t.filter(t=>t.id!==e.id)),await h(),o()}catch(e){t.system.error(`Failed to restore memory`,e),l(u(`mem.about.restoreFailed`,{error:b(e)}),`error`)}finally{m(null)}},[h,o,l,u]),Se=(0,y.useCallback)(async()=>{let e=fe.trim();if(e){m(`new`);try{await Me({content:e,category:pe}),p(``),l(u(`mem.about.saved`),`success`),await h(),o()}catch(e){t.system.error(`Failed to add memory`,e),l(u(`mem.about.addFailed`,{error:b(e)}),`error`)}finally{m(null)}}},[fe,pe,h,o,l,u]);if(!e)return d(`div`,{className:`mem-about`,children:[s(`h2`,{className:`mem-about-title`,children:u(`mem.about.title`)}),d(`div`,{className:`mem-about-empty`,children:[s(`p`,{children:u(`mem.about.off`)}),s(`button`,{className:`btn-secondary`,onClick:c,children:u(`mem.about.turnOn`)})]})]});let Ce=pt.map(e=>({...e,rows:(ee??[]).filter(t=>e.categories.includes(t.category))})).filter(e=>e.rows.length>0);return d(`div`,{className:`mem-about`,children:[s(`h2`,{className:`mem-about-title`,children:u(`mem.about.title`)}),s(`p`,{className:`mem-about-intro`,children:u(`mem.about.intro`)}),d(`form`,{className:`mem-about-add`,onSubmit:e=>{e.preventDefault(),Se()},children:[s(`input`,{className:`mem-input`,placeholder:u(`mem.about.addPlaceholder`),"aria-label":u(`mem.about.addLabel`),value:fe,onChange:e=>p(e.target.value)}),d(`select`,{className:`mem-select`,"aria-label":u(`mem.about.kind`),value:pe,onChange:e=>me(e.target.value),children:[s(`option`,{value:`fact`,children:u.bare(`mem.about.group.about`)}),s(`option`,{value:`preference`,children:u.bare(`mem.about.kind.preference`)}),s(`option`,{value:`reminder`,children:u.bare(`mem.about.kind.reminder`)}),s(`option`,{value:`note`,children:u.bare(`mem.about.kind.note`)})]}),d(`button`,{className:`btn-primary`,type:`submit`,disabled:!fe.trim()||he===`new`,children:[s(Ae,{size:14}),` `,u(`mem.about.add`)]})]}),f.map(e=>d(`div`,{className:`mem-about-forgotten`,role:`status`,children:[s(`span`,{children:e.sensitive?u(`mem.about.forgottenSensitive`):u(`mem.about.forgotten`,{content:e.content})}),d(`button`,{className:`mem-about-link`,disabled:he===e.id,onClick:()=>xe(e),children:[s(Ve,{size:12}),` `,u(`mem.about.undo`)]})]},e.id)),ne?d(`div`,{className:`mem-about-empty`,children:[s(`p`,{children:u(`mem.about.loadFailed`,{error:ne})}),s(`button`,{className:`btn-secondary`,onClick:h,children:u(`mem.about.retry`)})]}):ee===null?d(`div`,{className:`mem-loading`,children:[s(`div`,{className:`mem-spinner`}),` `,u(`mem.loading`)]}):Ce.length===0?d(`div`,{className:`mem-about-empty`,children:[s(`p`,{children:u(`mem.about.empty`)}),s(`p`,{className:`mem-about-hint`,children:u(`mem.about.emptyHint`)})]}):Ce.map(e=>d(`section`,{className:`mem-about-group`,"aria-label":u(e.title),children:[s(`h3`,{className:`mem-about-group-title`,children:u(e.title)}),s(`ul`,{className:`mem-about-list`,children:e.rows.map(e=>{let t=e.sensitive&&!ue.has(e.id),n=e.due_at?_t(e.due_at,new Date,u):null,i=gt(e.updated_at,u),o=t?r(`mem.about.sensitiveMemory`):e.content;return s(`li`,{className:`mem-about-item`,children:ae===e.id?d(`form`,{className:`mem-about-edit`,onSubmit:t=>{t.preventDefault(),ve(e)},children:[s(`textarea`,{className:`mem-input`,"aria-label":u(`mem.about.editLabel`),rows:2,autoFocus:!0,value:se,onChange:e=>ce(e.target.value),onKeyDown:t=>{t.key===`Escape`&&(t.stopPropagation(),oe(null)),t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ve(e))}}),d(`div`,{className:`mem-about-edit-actions`,children:[s(`button`,{className:`btn-primary`,type:`submit`,disabled:he===e.id,children:u(`mem.about.save`)}),s(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>oe(null),children:u(`mem.about.cancel`)})]})]}):d(a.Fragment,{children:[d(`div`,{className:`mem-about-text`,children:[t?d(`button`,{className:`mem-about-link`,onClick:()=>de(t=>new Set(t).add(e.id)),children:[s(Be,{size:12}),` `,u(`mem.about.showSensitive`)]}):s(`bdi`,{children:e.content}),n&&s(`span`,{className:`mem-about-due${n.past?` is-overdue`:``}`,children:n.text}),s(`span`,{className:`mem-about-meta`,children:i===null?u(ht(e.source)):u(`mem.about.meta`,{source:r(ht(e.source)),when:i})})]}),d(`div`,{className:`mem-about-actions`,children:[s(`button`,{className:`mem-about-btn`,"aria-label":u(`mem.about.editAria`,{name:o}),title:u(`mem.about.edit`),onClick:()=>{oe(e.id),ce(e.content)},children:s(Xe,{size:14})}),d(`button`,{className:`mem-about-btn mem-about-btn-remove`,"aria-label":u(`mem.about.forgetAria`,{name:o}),title:u(`mem.about.forget`),disabled:he===e.id,onClick:()=>ye(e),children:[s(Ne,{size:14}),` `,u(`mem.about.forget`)]})]})]})},e.id)})})]},e.title))]})}function b(e){return e instanceof Error?e.message:String(e)}function yt(e,t){if(!e)return`—`;try{let n=new Date(e);if(isNaN(n.getTime()))return`—`;let r={month:`short`,day:`numeric`};return n.getFullYear()!==new Date().getFullYear()&&(r.year=`numeric`),n.toLocaleDateString(t,r)}catch{return`—`}}function x(e,t){if(!e)return``;try{let n=new Date(e);return isNaN(n.getTime())?``:n.toLocaleString(t,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return``}}function S(e,t){if(!e)return`—`;try{let n=new Date(e);if(isNaN(n.getTime()))return`—`;let r=Date.now(),i=n.getTime()-r,a=Math.abs(i),o=Math.floor(a/1e3),s=Math.floor(a/6e4),c=Math.floor(a/36e5),l=Math.floor(a/864e5);return i<0?o<5?t(`time.justNow`):o<60?t(`mem.rel.secondsAgo`,{n:o}):c===0?t(`time.minutesAgo`,{n:s}):l===0?t(`time.hoursAgo`,{n:c}):l===1?t(`time.yesterday`):l<30?t(`time.daysAgo`,{n:l}):x(e,u(t)):o<5?t(`mem.rel.now`):o<60?t(`mem.rel.inSeconds`,{n:o}):c===0?t(`mem.rel.inMinutes`,{n:s}):l===0?t(`mem.rel.inHours`,{n:c}):l===1?t(`mem.rel.tomorrow`):l<30?t(`mem.rel.inDays`,{n:l}):x(e,u(t))}catch{return`—`}}function bt(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function xt(e){try{return new Date(e).getTime()<Date.now()}catch{return!1}}function St(e){return e>=.7?`high`:e>=.4?`medium`:`low`}function Ct(e){return e>=.9?`high`:e>=.7?`medium`:`low`}function wt(e,t,n){let r=yt(e,n),i=yt(t,n);return r===`—`&&i===`—`?``:r===i?r:`${r} \u2013 ${i}`}function Tt(e){if(e.length===0)return 0;let t=new Date().toISOString().slice(0,10),n=e.find(e=>e.date===t);return n?n.knowledge_added:0}var Et=[`fact`,`preference`,`error`,`skill`,`note`,`reminder`],C={fact:`mem.cat.fact`,preference:`mem.cat.preference`,error:`mem.cat.error`,skill:`mem.cat.skill`,note:`mem.cat.note`,reminder:`mem.cat.reminder`},Dt={pending_approval:`mem.status.pending_approval`,queued:`mem.status.queued`,in_progress:`mem.status.in_progress`,completed:`mem.status.completed`,failed:`mem.status.failed`,rejected:`mem.status.rejected`,cancelled:`mem.status.cancelled`,blocked:`mem.status.blocked`},Ot={low:`mem.priority.low`,medium:`mem.priority.medium`,high:`mem.priority.high`},kt={agent_inferred:`mem.goals.source.agent_inferred`,agent_scheduled:`mem.goals.source.agent_scheduled`},At={user:`mem.role.user`,assistant:`mem.role.assistant`},jt={work:`mem.domain.work`,technical:`mem.domain.technical`,personal:`mem.domain.personal`,general:`mem.domain.general`};function w({value:e,keys:t}){let n=i(),r=t[e];return r?s(a.Fragment,{children:n(r)}):s(`bdi`,{children:e})}function T(e){return e instanceof Error?e.message:String(e)}var Mt={work:`blue`,technical:`purple`,personal:`green`,general:`gray`};function Nt(){let e=i(),{setShowMemoryDashboard:n,sessions:c,setCurrentSession:l}=o(),Be=(0,y.useMemo)(()=>new Map(c.map(e=>[e.id,e.title])),[c]),Ve=e=>Be.get(e)||`${e.slice(0,8)}...`,[g,rt]=(0,y.useState)(null),[_,ot]=(0,y.useState)([]),[v,lt]=(0,y.useState)(null),[dt,pt]=(0,y.useState)([]),[mt,ht]=(0,y.useState)([]),[gt,_t]=(0,y.useState)([]),[b,yt]=(0,y.useState)(null),[Nt,Pt]=(0,y.useState)([]),[Ft,It]=(0,y.useState)(!0),[Lt,Rt]=(0,y.useState)(!1),[zt,Bt]=(0,y.useState)(null),[Vt,E]=(0,y.useState)(!1),[Ht,Ut]=(0,y.useState)(null),[Wt,Gt]=(0,y.useState)([]),Kt=(0,y.useRef)(0),[D,qt]=(0,y.useState)([]),[Jt,Yt]=(0,y.useState)(``),[Xt,Zt]=(0,y.useState)(``),[Qt,$t]=(0,y.useState)(``),[O,en]=(0,y.useState)(`updated_at`),[tn,nn]=(0,y.useState)(`desc`),[k,A]=(0,y.useState)(0),[rn,an]=(0,y.useState)(!1),[on,sn]=(0,y.useState)(``),[cn,ln]=(0,y.useState)(null),un=(0,y.useRef)(null),[j,dn]=(0,y.useState)(null),[fn,pn]=(0,y.useState)(!1),[M,mn]=(0,y.useState)(null),[N,P]=(0,y.useState)({content:``,category:`fact`,domain:``,context:`global`,entity:``,sensitive:!1,due_at:``}),[hn,gn]=(0,y.useState)(new Set),[F,_n]=(0,y.useState)(!1),[vn,yn]=(0,y.useState)(!1),[bn,xn]=(0,y.useState)(!1),[I,L]=(0,y.useState)(!1),[Sn,Cn]=(0,y.useState)(!1),[R,wn]=(0,y.useState)(null),[Tn,En]=(0,y.useState)(!1),[Dn,z]=(0,y.useState)(null),[B,On]=(0,y.useState)(`about`),[kn,An]=(0,y.useState)(0),[jn,Mn]=(0,y.useState)([]),[Nn,Pn]=(0,y.useState)(null),[Fn,In]=(0,y.useState)(!1),[Ln,Rn]=(0,y.useState)(null),[zn,Bn]=(0,y.useState)(null),[Vn,Hn]=(0,y.useState)(!1),[Un,Wn]=(0,y.useState)({title:``,description:``,priority:`medium`}),[V,H]=(0,y.useState)(`idle`),[Gn,U]=(0,y.useState)([]),[W,G]=(0,y.useState)([]),[Kn,qn]=(0,y.useState)(null),Jn=(0,y.useRef)(null),Yn=(0,y.useRef)(null),[K,q]=(0,y.useState)(`idle`),[Xn,J]=(0,y.useState)([]),[Y,Zn]=(0,y.useState)([]),[Qn,$n]=(0,y.useState)(null),[er,tr]=(0,y.useState)(!1),nr=(0,y.useRef)(null),rr=(0,y.useRef)(null),[ir,ar]=(0,y.useState)(30),[or,sr]=(0,y.useState)(!1),[cr,lr]=(0,y.useState)(!1),[ur,dr]=(0,y.useState)(!1),[fr,pr]=(0,y.useState)(!1),[mr,hr]=(0,y.useState)(!1),[gr,_r]=(0,y.useState)(!1),vr=(0,y.useRef)(null),yr=(0,y.useRef)(null),br=(0,y.useRef)(null),X=(0,y.useCallback)((e,t=`info`)=>{let n=++Kt.current;Gt(r=>[...r,{id:n,text:e,type:t}]),setTimeout(()=>{Gt(e=>e.filter(e=>e.id!==n))},4e3)},[]);(0,y.useEffect)(()=>{if(!Vt)return;let e=e=>{yr.current&&!yr.current.contains(e.target)&&E(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[Vt]),je(!0,()=>{Dn?z(null):Sn?Cn(!1):Tn?En(!1):j?dn(null):Vt?E(!1):fn||M?(pn(!1),mn(null)):Ht?Ut(null):n(!1)}),Oe(br,!!Dn),(0,y.useEffect)(()=>{if(!Dn)return;let e=br.current;if(!e)return;let t=document.activeElement;return e.focus(),()=>{t?.focus()}},[Dn]);let xr=(0,y.useCallback)(async()=>{try{let e=await he();rt(e)}catch(e){t.system.warn(`Failed to load memory stats`,e)}},[]),Sr=(0,y.useCallback)(async()=>{try{let e=await ze(ir);ot(e)}catch(e){t.system.warn(`Failed to load memory activity`,e)}},[ir]),Z=(0,y.useCallback)(async()=>{try{let e=await _e({category:D.length>0?D:void 0,context:Jt||void 0,entity:Xt||void 0,search:Qt||void 0,sort_by:O,order:tn,offset:k,limit:15,include_sensitive:!0,include_superseded:rn});lt(e)}catch(e){t.system.warn(`Failed to load knowledge`,e)}},[D,Jt,Xt,Qt,O,tn,k,rn]),Cr=(0,y.useCallback)(async()=>{try{let e=await m();pt(e)}catch(e){t.system.warn(`Failed to load tool summary`,e)}},[]),wr=(0,y.useCallback)(async()=>{try{let e=await ne(20);ht(e)}catch(e){t.system.warn(`Failed to load conversations`,e)}},[]),Tr=(0,y.useCallback)(async()=>{try{let e=await h(7);_t(e)}catch(e){t.system.warn(`Failed to load upcoming items`,e)}},[]),Er=(0,y.useCallback)(async()=>{try{let e=await Se();yt(e)}catch(e){t.system.warn(`Failed to load embedding coverage`,e)}},[]),Dr=(0,y.useCallback)(async()=>{try{let e=await oe();Pt(e||[])}catch(e){t.system.warn(`Failed to load entities`,e)}},[]),Or=(0,y.useCallback)(async()=>{try{let e=await Re();yn(e.mcp_memory_enabled),_n(e.memory_enabled),xn(e.system_discovery_consent)}catch(e){t.system.warn(`Failed to load memory settings`,e)}},[]),kr=(0,y.useCallback)(async()=>{In(!0);try{let[e,t]=await Promise.all([se(),ae()]);Mn(e.goals),Pn(t)}catch(e){t.system.warn(`Failed to load goals`,e)}finally{In(!1)}},[]),Ar=(0,y.useCallback)(async(n,i)=>{try{await n()}catch(n){t.system.error(`Goal action failed (${i})`,n),X(e(`mem.goals.failed`,{what:r(i),error:T(n)}),`error`);return}kr()},[kr,X,e]);(0,y.useEffect)(()=>{if(!zn)return;let e=setTimeout(()=>Bn(null),3e3);return()=>clearTimeout(e)},[zn]);let Q=(0,y.useCallback)(async()=>{It(!0),Rt(!1);try{await Promise.all([xr(),Sr(),Z(),Cr(),wr(),Tr(),Er(),Dr(),Or(),kr()]),An(e=>e+1)}catch(e){Rt(!0),t.system.error(`Memory dashboard load failed`,e)}finally{It(!1)}},[xr,Sr,Z,Cr,wr,Tr,Er,Dr,Or,kr]);(0,y.useEffect)(()=>{Q()},[Q]),(0,y.useEffect)(()=>{Z()},[Z]);let jr=(0,y.useRef)(!0);(0,y.useEffect)(()=>{jr.current?jr.current=!1:Sr()},[Sr]);let Mr=(0,y.useCallback)(e=>{$t(e),_r(!0),vr.current&&clearTimeout(vr.current),vr.current=setTimeout(()=>{A(0),_r(!1)},300)},[]),Nr=(0,y.useCallback)(()=>{Z(),xr(),Er(),Tr(),Dr()},[Z,xr,Er,Tr,Dr]),$=(0,y.useCallback)(()=>{Nr(),An(e=>e+1)},[Nr]),Pr=(0,y.useCallback)(async()=>{if(N.content.trim())try{let n=await Me({content:N.content,category:N.category,domain:N.domain||void 0,context:N.context,entity:N.entity||void 0,sensitive:N.sensitive,due_at:N.due_at||void 0});pn(!1),P({content:``,category:`fact`,domain:``,context:`global`,entity:``,sensitive:!1,due_at:``}),$(),t.ui.info(`Created new knowledge entry`),n?.embedded===!1?X(n.embed_error?e(`mem.toast.server`,{message:n.embed_error}):e(`mem.toast.notEmbedded`),`error`):X(e(`mem.toast.created`),`success`)}catch(n){t.system.error(`Failed to create knowledge`,n),X(e(`mem.toast.createFailed`,{error:T(n)}),`error`)}},[N,$,X,e]),Fr=(0,y.useCallback)(async()=>{if(M&&N.content.trim())try{let n=await ie(M,{content:N.content,category:N.category,domain:N.domain||void 0,context:N.context,entity:N.entity||void 0,sensitive:N.sensitive,due_at:N.due_at||void 0});mn(null),P({content:``,category:`fact`,domain:``,context:`global`,entity:``,sensitive:!1,due_at:``}),$(),t.ui.info(`Updated knowledge ${M}`),n?.embedded===!1?X(n.embed_error?e(`mem.toast.server`,{message:n.embed_error}):e(`mem.toast.notEmbedded`),`error`):X(e(`mem.toast.updated`),`success`)}catch(n){t.system.error(`Failed to update knowledge`,n),X(e(`mem.toast.updateFailed`,{error:T(n)}),`error`)}},[M,N,$,X,e]),Ir=(0,y.useCallback)(async n=>{if(R!==n)wn(n);else{wn(null);try{await be(n),$(),t.ui.info(`Deleted knowledge ${n}`),X(e(`mem.toast.deleted`),`info`)}catch(n){t.system.error(`Failed to delete knowledge`,n),X(e(`mem.toast.deleteFailed`,{error:T(n)}),`error`)}}},[R,$,X,e]);(0,y.useEffect)(()=>{if(!R)return;let e=setTimeout(()=>wn(null),3e3);return()=>clearTimeout(e)},[R]);let Lr=(0,y.useCallback)(async n=>{try{await ie(n.id,{sensitive:!n.sensitive}),Z(),t.ui.info(`Toggled sensitive for ${n.id}: ${!n.sensitive}`),X(e(n.sensitive?`mem.toast.unmarkedSensitive`:`mem.toast.markedSensitive`),`info`)}catch(n){t.system.error(`Failed to toggle sensitive`,n),X(e(`mem.toast.sensitiveFailed`,{error:T(n)}),`error`)}},[Z,X,e]),Rr=(0,y.useCallback)(e=>{mn(e.id),pn(!1),P({content:e.content,category:e.category,domain:e.domain||``,context:e.context,entity:e.entity||``,sensitive:e.sensitive,due_at:e.due_at||``})},[]),zr=(0,y.useCallback)(n=>{navigator.clipboard.writeText(n).then(()=>X(e(`mem.toast.idCopied`),`info`),r=>{t.ui.warn(`Couldn't copy knowledge ID ${n}`,r),X(e(`mem.toast.copyFailed`,{error:T(r)}),`error`)})},[X,e]),Br=(0,y.useCallback)(e=>{sn(e),un.current&&clearTimeout(un.current),e.trim()?un.current=setTimeout(async()=>{try{let t=await Ee(e.trim(),20);ln(t)}catch(e){t.system.warn(`Conversation search failed`,e)}},300):ln(null)},[]),Vr=(0,y.useCallback)(async e=>{try{let t=await Ze(e);dn({sessionId:e,turns:t})}catch(e){t.system.error(`Failed to load conversation detail`,e)}},[]),Hr=(0,y.useCallback)(e=>{qt(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),A(0)},[]),Ur=(0,y.useCallback)(e=>{O===e?nn(e=>e===`desc`?`asc`:`desc`):(en(e),nn(`desc`)),A(0)},[O]),Wr=(0,y.useCallback)(async()=>{sr(!0),E(!1);try{let t=await Ye();await Q(),X(e(`mem.toast.consolidated`,{sessions:t.consolidated??0,items:t.extracted_items??0}),`success`)}catch(n){t.system.error(`Failed to consolidate sessions`,n),X(e(`mem.toast.consolidateFailed`,{error:T(n)}),`error`)}finally{sr(!1)}},[Q,X,e]),Gr=(0,y.useCallback)(async()=>{lr(!0),E(!1);try{let t=await ye();await Er(),X(t.total_without?e(`mem.toast.backfilledMissing`,{n:t.backfilled??0,missing:t.total_without}):e(`mem.toast.backfilled`,{n:t.backfilled??0}),`success`)}catch(n){t.system.error(`Failed to rebuild embeddings`,n),X(e(`mem.toast.rebuildFailed`,{error:T(n)}),`error`)}finally{lr(!1)}},[Er,X,e]),Kr=(0,y.useCallback)(async()=>{dr(!0),E(!1);try{let t=await re();await Q(),X(e(`mem.toast.reconciled`,{pairs:t.pairs_checked??0,reinforced:t.reinforced??0,contradicted:t.contradicted??0}),`success`)}catch(n){t.system.error(`Failed to reconcile memory`,n),X(e(`mem.toast.reconcileFailed`,{error:T(n)}),`error`)}finally{dr(!1)}},[Q,X,e]),qr=(0,y.useCallback)(async()=>{pr(!0),E(!1);try{await et(),await Q(),X(e(`mem.toast.ftsRebuilt`),`success`)}catch(n){t.system.error(`Failed to rebuild FTS index`,n),X(e(`mem.toast.ftsFailed`,{error:T(n)}),`error`)}finally{pr(!1)}},[Q,X,e]),Jr=(0,y.useCallback)(async()=>{hr(!0),E(!1);try{let t=await Te();await Q(),t.skipped?X(e(`mem.toast.systemDisabled`),`error`):X(e(`mem.toast.systemRefreshed`,{n:t.stored}),`success`)}catch(n){t.system.error(`Failed to refresh system context`,n),X(e(`mem.toast.systemFailed`,{error:T(n)}),`error`)}finally{hr(!1)}},[Q,X,e]),Yr=or||cr||ur||fr||mr,Xr=(0,y.useCallback)(()=>{H(`running`),U([]),G([]),qn(null);let n=de();Yn.current=n,n.onmessage=r=>{try{let t=JSON.parse(r.data);if(t.type===`log`)U(e=>[...e,{text:t.message,kind:`log`,server:!0}]);else if(t.type===`finding`){let n=t.item;U(t=>[...t,{text:e.bare(`mem.log.found`,{content:n.content}),kind:`finding`}]),G(e=>[...e,{...n,_checked:!0}])}else t.type===`error`?U(n=>[...n,{text:e.bare(`mem.log.error`,{message:t.message}),kind:`error`}]):t.type===`done`&&(n.close(),Yn.current=null,U(n=>[...n,{text:e(`mem.log.discoveryDone`,{n:t.total??0}),kind:`log`}]),H(`review`))}catch(n){t.system.warn(`Unreadable discovery event`,n),U(t=>[...t,{text:e(`mem.log.parseFailed`),kind:`error`}])}},n.onerror=()=>{n.close(),Yn.current=null,U(t=>[...t,{text:e(`mem.log.discoveryConnection`),kind:`error`}]),G(e=>(H(e.length>0?`review`:`idle`),e))}},[e]),Zr=(0,y.useCallback)(async()=>{let n=W.filter(e=>e._checked);if(n.length!==0){H(`saving`);try{let t=n.map(({_checked:e,...t})=>t),r=await Fe(t);qn(r.stored),H(`done`),$(),X(e(`mem.disc.saved`,{n:r.stored}),`success`)}catch(n){t.system.error(`Failed to commit discovery items`,n),X(e(`mem.disc.saveFailed`,{error:T(n)}),`error`),H(`review`)}}},[W,$,X,e]),Qr=(0,y.useCallback)(()=>{q(`running`),J([]),Zn([]),$n(null);let n=pe(er);rr.current=n,n.onmessage=r=>{try{let t=JSON.parse(r.data);if(t.type===`log`)J(e=>[...e,{text:t.message,kind:`log`,server:!0}]);else if(t.type===`insight`){let n=t.item;J(t=>[...t,{text:e.bare(`mem.log.insight`,{content:n.content}),kind:`finding`}]),Zn(e=>[...e,{...n,_checked:!0}])}else t.type===`error`?J(n=>[...n,{text:e.bare(`mem.log.error`,{message:t.message}),kind:`error`}]):t.type===`done`&&(n.close(),rr.current=null,J(n=>[...n,{text:e(`mem.log.inferenceDone`,{n:t.total??0}),kind:`log`}]),q(`review`))}catch(n){t.system.warn(`Unreadable inference event`,n),J(t=>[...t,{text:e(`mem.log.parseFailed`),kind:`error`}])}},n.onerror=()=>{n.close(),rr.current=null,J(t=>[...t,{text:e(`mem.log.inferenceConnection`),kind:`error`}]),Zn(e=>(q(e.length>0?`review`:`idle`),e))}},[er,e]),$r=(0,y.useCallback)(async()=>{let n=Y.filter(e=>e._checked);if(n.length!==0){q(`saving`);try{let t=n.map(({_checked:e,...t})=>t),r=await ke(t);$n(r.stored),q(`done`),$(),X(e(`mem.inf.saved`,{n:r.stored}),`success`)}catch(n){t.system.error(`Failed to commit inference insights`,n),X(e(`mem.inf.saveFailed`,{error:T(n)}),`error`),q(`review`)}}},[Y,$,X,e]);(0,y.useEffect)(()=>{Jn.current&&(Jn.current.scrollTop=Jn.current.scrollHeight)},[Gn]),(0,y.useEffect)(()=>{nr.current&&(nr.current.scrollTop=nr.current.scrollHeight)},[Xn]),(0,y.useEffect)(()=>()=>{Yn.current&&=(Yn.current.close(),null),rr.current&&=(rr.current.close(),null)},[]);let ei=e=>O===e?s(`span`,{className:`mem-sort-arrow`,children:tn===`desc`?`↓`:`↑`}):null,ti=Math.max(1,..._.map(e=>e.conversations+e.tool_calls+e.knowledge_added+e.errors)),ni=g?.knowledge?.by_context?Object.keys(g.knowledge.by_context):[];return d(`div`,{className:`memory-dashboard-page`,children:[d(`div`,{className:`memory-dashboard-header`,children:[d(`div`,{className:`memory-dashboard-header-left`,children:[s(`button`,{className:`btn-icon settings-back-btn`,onClick:()=>n(!1),"aria-label":e(`mem.back`),children:s(nt,{size:18})}),d(`h1`,{children:[e(`mem.title`),` `,s(`span`,{className:`mem-beta`,style:{fontSize:11,fontWeight:600,color:`var(--accent-yellow)`,background:`var(--accent-yellow-dim)`,padding:`2px 8px`,borderRadius:4,marginInlineStart:8,verticalAlign:`middle`,whiteSpace:`nowrap`},children:e(`mem.beta`)})]})]}),d(`div`,{className:`memory-dashboard-header-actions`,children:[B===`advanced`&&d(a.Fragment,{children:[b&&b.total_items>0&&d(`div`,{className:`mem-embedding-coverage`,title:e(`mem.coverage.title`,{n:b.with_embedding,total:b.total_items}),children:[s(`div`,{className:`mem-embedding-bar`,children:s(`div`,{className:`mem-embedding-fill`,style:{width:`${Math.round(b.coverage_pct)}%`}})}),s(`span`,{className:`mem-embedding-label`,children:e(`mem.coverage.label`,{pct:`${Math.round(b.coverage_pct)}%`})})]}),d(`div`,{className:`mem-maintenance-wrap`,ref:yr,children:[d(`button`,{className:`btn-icon ${Yr?`mem-spinning`:``}`,onClick:()=>E(e=>!e),title:e(`mem.maint.label`),"aria-label":e(`mem.maint.label`),"aria-expanded":Vt,children:[Yr?s(`div`,{className:`mem-spinner-sm`}):s(ge,{size:16}),s(De,{size:10,style:{marginInlineStart:2}})]}),Vt&&d(`div`,{className:`mem-maintenance-menu`,role:`menu`,children:[d(`button`,{className:`mem-maintenance-item`,onClick:Wr,disabled:or,role:`menuitem`,children:[s(it,{size:14}),e(or?`mem.maint.consolidating`:`mem.maint.consolidate`)]}),d(`button`,{className:`mem-maintenance-item`,onClick:Gr,disabled:cr,role:`menuitem`,children:[s(te,{size:14}),e(cr?`mem.maint.rebuilding`:`mem.maint.rebuildEmbeddings`)]}),d(`button`,{className:`mem-maintenance-item`,onClick:Kr,disabled:ur,role:`menuitem`,children:[s(tt,{size:14}),e(ur?`mem.maint.reconciling`:`mem.maint.reconcile`)]}),s(`div`,{className:`mem-maintenance-divider`}),d(`button`,{className:`mem-maintenance-item`,onClick:Jr,disabled:mr,role:`menuitem`,children:[s(Ie,{size:14}),e(mr?`mem.maint.refreshing`:`mem.maint.refreshSystem`)]}),s(`div`,{className:`mem-maintenance-divider`}),d(`button`,{className:`mem-maintenance-item`,onClick:qr,disabled:fr,role:`menuitem`,children:[s(Ue,{size:14}),e(fr?`mem.maint.rebuilding`:`mem.maint.rebuildFts`)]})]})]})]}),s(`button`,{className:`btn-icon`,onClick:Q,title:e(`mem.refresh`),"aria-label":e(`mem.refreshAria`),children:s(Ie,{size:16})})]})]}),d(`div`,{className:`mem-tab-bar`,role:`tablist`,children:[d(`button`,{className:`mem-tab-btn${B===`about`?` mem-tab-active`:``}`,onClick:()=>On(`about`),role:`tab`,"aria-selected":B===`about`,children:[s(ft,{size:14}),` `,e(`mem.tab.about`)]}),d(`button`,{className:`mem-tab-btn${B===`goals`?` mem-tab-active`:``}`,onClick:()=>{On(`goals`),kr()},role:`tab`,"aria-selected":B===`goals`,children:[s(ct,{size:14}),` `,e(`mem.tab.goals`),Nn&&(Nn.goals.pending_approval??0)>0&&s(`span`,{className:`mem-tab-badge`,children:Nn.goals.pending_approval})]}),d(`button`,{className:`mem-tab-btn${B===`profile`?` mem-tab-active`:``}`,onClick:()=>On(`profile`),role:`tab`,"aria-selected":B===`profile`,children:[s(Pe,{size:14}),` `,e(`mem.tab.profile`)]}),d(`button`,{className:`mem-tab-btn${B===`advanced`?` mem-tab-active`:``}`,onClick:()=>On(`advanced`),role:`tab`,"aria-selected":B===`advanced`,children:[s(p,{size:14}),` `,e(`mem.tab.advanced`)]})]}),d(`div`,{className:`memory-dashboard-body`,children:[B===`about`&&s(vt,{memoryEnabled:F,reloadKey:kn,onChanged:Nr,onOpenAdvanced:()=>On(`advanced`),showToast:X}),B===`advanced`&&s(a.Fragment,{children:Ft&&!g?d(`div`,{className:`mem-loading`,children:[s(`div`,{className:`mem-spinner`}),e(`mem.loadingData`)]}):Lt?d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(Je,{size:32})}),s(`p`,{children:e(`mem.loadFailed`)}),d(`button`,{className:`btn-secondary`,onClick:Q,style:{marginTop:12},children:[s(Ie,{size:14}),` `,e(`mem.retry`)]})]}):d(a.Fragment,{children:[!F&&d(`div`,{className:`mem-empty-state`,style:{margin:`40px 0`},children:[s(`div`,{className:`mem-empty-icon`,style:{opacity:.5},children:s(st,{size:32})}),s(`p`,{style:{color:`var(--text-secondary)`,fontSize:14},children:e(`mem.offAdvanced`)})]}),F&&d(a.Fragment,{children:[g?.embedding_error&&d(`div`,{className:`mem-advanced-error`,role:`alert`,children:[s(Je,{size:14}),` `,s(`bdi`,{children:g.embedding_error})]}),d(`div`,{className:`mem-stat-cards`,children:[d(`div`,{className:`mem-stat-card`,"data-accent":`purple`,children:[s(`div`,{className:`mem-stat-value`,children:g?.knowledge?.total??0}),s(`div`,{className:`mem-stat-label`,children:e(`mem.stat.stored`)}),s(`div`,{className:`mem-stat-sub`,children:(()=>{let t=Tt(_);return t>0?e(`mem.stat.addedToday`,{n:t}):g?.knowledge?.by_category?e.compose(e=>Object.entries(g.knowledge.by_category).slice(0,3).map(([t,n])=>e(`mem.stat.categoryCount`,{category:C[t]?r(C[t]):t,n})).join(e(`mem.listSeparator`))):e(`mem.stat.noEntries`)})()})]}),d(`div`,{className:`mem-stat-card`,"data-accent":`gold`,children:[s(`div`,{className:`mem-stat-value`,children:g?.knowledge?.total_retrievals??0}),s(`div`,{className:`mem-stat-label`,children:e(`mem.stat.retrieved`)}),s(`div`,{className:`mem-stat-sub`,children:g?.knowledge?.total&&g?.knowledge?.total_retrievals?e(`mem.stat.avgRecall`,{n:(g.knowledge.total_retrievals/g.knowledge.total).toFixed(1)}):e(`mem.stat.noRecalls`)})]}),d(`div`,{className:`mem-stat-card`,"data-accent":`blue`,children:[s(`div`,{className:`mem-stat-value`,children:g?.conversations?.total_sessions??0}),s(`div`,{className:`mem-stat-label`,children:e(`mem.stat.sessions`)}),s(`div`,{className:`mem-stat-sub`,children:wt(g?.conversations?.first_session??null,g?.conversations?.last_session??null,u(e))||e(`mem.stat.totalTurns`,{n:g?.conversations?.total_turns??0})})]}),d(`div`,{className:`mem-stat-card`,"data-accent":`green`,children:[s(`div`,{className:`mem-stat-value`,children:g?.tools?.total_calls??0}),s(`div`,{className:`mem-stat-label`,children:e(`mem.stat.toolCalls`)}),s(`div`,{className:`mem-stat-sub`,title:e(`mem.stat.toolsNotLogged`),children:e(`mem.stat.toolsExclMemory`,{n:g?.tools?.unique_tools??0})})]}),d(`div`,{className:`mem-stat-card`,"data-accent":`red`,children:[s(`div`,{className:`mem-stat-value`,children:g?.tools?.overall_success_rate!=null&&(g.tools.total_calls??0)>0?`${Math.round(g.tools.overall_success_rate*100)}%`:`—`}),s(`div`,{className:`mem-stat-label`,children:e(`mem.stat.successRate`)}),s(`div`,{className:`mem-stat-sub`,children:(g?.tools?.total_calls??0)>0?e(`mem.stat.errors`,{n:g?.tools?.total_errors??0}):e(`mem.stat.noToolCalls`)})]})]}),d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title mem-section-title-row`,children:[d(`span`,{className:`mem-section-title-left`,children:[s(ut,{size:14}),` `,e(`mem.activity.title`)]}),s(`div`,{className:`mem-range-tabs`,role:`group`,"aria-label":e(`mem.activity.range`),children:[1,7,30].map(t=>s(`button`,{className:`mem-range-tab${ir===t?` active`:``}`,onClick:()=>ar(t),children:e(t===1?`mem.activity.day1`:t===7?`mem.activity.days7`:`mem.activity.days30`)},t))})]}),_.length>0?d(a.Fragment,{children:[s(`div`,{className:`mem-activity-chart`,children:_.map((t,n)=>{let r=t.conversations+t.tool_calls+t.knowledge_added+t.errors,i=n===0||n===_.length-1||n%7==0,o=new Date(t.date+`T00:00:00`).toLocaleDateString(u(e),{month:`short`,day:`numeric`});return d(`div`,{className:`mem-activity-bar-group`,onMouseEnter:()=>Bt(n),onMouseLeave:()=>Bt(null),children:[t.errors>0&&s(`div`,{className:`mem-activity-bar errors`,style:{height:`${t.errors/ti*100}%`}}),t.knowledge_added>0&&s(`div`,{className:`mem-activity-bar knowledge`,style:{height:`${t.knowledge_added/ti*100}%`}}),t.tool_calls>0&&s(`div`,{className:`mem-activity-bar tool_calls`,style:{height:`${t.tool_calls/ti*100}%`}}),t.conversations>0&&s(`div`,{className:`mem-activity-bar conversations`,style:{height:`${t.conversations/ti*100}%`}}),i&&s(`span`,{className:`mem-activity-date-label`,children:o}),zt===n&&r>0&&d(`div`,{className:`mem-activity-tooltip`,children:[s(`strong`,{children:o}),s(`br`,{}),t.conversations>0&&d(a.Fragment,{children:[e(`mem.activity.conversations`,{n:t.conversations}),s(`br`,{})]}),t.tool_calls>0&&d(a.Fragment,{children:[e(`mem.activity.toolCalls`,{n:t.tool_calls}),s(`br`,{})]}),t.knowledge_added>0&&d(a.Fragment,{children:[e(`mem.activity.learned`,{n:t.knowledge_added}),s(`br`,{})]}),t.errors>0&&s(a.Fragment,{children:e(`mem.stat.errors`,{n:t.errors})})]})]},t.date)})}),d(`div`,{className:`mem-activity-legend`,children:[d(`span`,{className:`mem-activity-legend-item`,children:[s(`span`,{className:`mem-activity-legend-dot conversations`}),` `,e(`mem.legend.conversations`)]}),d(`span`,{className:`mem-activity-legend-item`,children:[s(`span`,{className:`mem-activity-legend-dot tool_calls`}),` `,e(`mem.stat.toolCalls`)]}),d(`span`,{className:`mem-activity-legend-item`,children:[s(`span`,{className:`mem-activity-legend-dot knowledge`}),` `,e(`mem.legend.knowledge`)]}),d(`span`,{className:`mem-activity-legend-item`,children:[s(`span`,{className:`mem-activity-legend-dot errors`}),` `,e(`mem.legend.errors`)]})]})]}):d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(ut,{size:28})}),s(`p`,{children:e(`mem.activity.empty`)})]})]}),d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title mem-section-title-row`,children:[d(`span`,{className:`mem-section-title-left`,children:[s(p,{size:14}),` `,e(`mem.knowledge.title`),v&&v.total>0&&s(`span`,{className:`mem-section-count`,children:v.total})]}),!fn&&!M&&d(`button`,{className:`mem-section-add-btn`,onClick:()=>pn(!0),title:e(`mem.knowledge.addTitle`),children:[s(Ae,{size:13}),` `,e(`mem.knowledge.add`)]})]}),d(`div`,{className:`mem-filters`,children:[d(`div`,{className:`mem-category-pills`,role:`group`,"aria-label":e(`mem.knowledge.filterCategory`),children:[Et.map(t=>s(`button`,{className:`mem-category-pill ${t}${D.includes(t)?` active`:``}`,onClick:()=>Hr(t),"aria-pressed":D.includes(t),children:e(C[t])},t)),D.length>0&&d(`button`,{className:`mem-category-pill clear`,onClick:()=>{qt([]),A(0)},"aria-label":e(`mem.knowledge.clearAria`),children:[`✕ `,e(`mem.knowledge.clear`)]})]}),d(`select`,{className:`mem-filter-select`,value:Jt,onChange:e=>{Yt(e.target.value),A(0)},"aria-label":e(`mem.knowledge.filterContext`),children:[s(`option`,{value:``,children:e.bare(`mem.knowledge.allContexts`)}),ni.map(e=>s(`option`,{value:e,children:e},e))]}),d(`select`,{className:`mem-filter-select`,value:Xt,onChange:e=>{Zt(e.target.value),A(0)},"aria-label":e(`mem.knowledge.filterEntity`),children:[s(`option`,{value:``,children:e.bare(`mem.knowledge.allEntities`)}),Nt.map(e=>d(`option`,{value:e.entity,children:[e.entity,` (`,e.count,`)`]},e.entity))]}),d(`div`,{className:`mem-filter-search-wrap`,children:[gr?s(`div`,{className:`mem-spinner-sm search-icon`,style:{width:12,height:12,borderWidth:1.5}}):s(Ue,{size:13,className:`search-icon`}),s(`input`,{className:`mem-filter-search`,type:`text`,placeholder:e(`mem.knowledge.searchPlaceholder`),value:Qt,onChange:e=>Mr(e.target.value),"aria-label":e(`mem.knowledge.search`)})]}),d(`label`,{className:`mem-filter-toggle`,title:e(`mem.knowledge.supersededTitle`),children:[s(`input`,{type:`checkbox`,checked:rn,onChange:e=>an(e.target.checked)}),s(`span`,{children:e(`mem.knowledge.superseded`)})]})]}),(fn||M)&&d(`div`,{className:`mem-inline-form`,children:[d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.col.content`)}),s(`textarea`,{value:N.content,onChange:e=>P(t=>({...t,content:e.target.value})),placeholder:e(`mem.form.contentPlaceholder`)})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.col.category`)}),s(`select`,{value:N.category,onChange:e=>P(t=>({...t,category:e.target.value})),children:Et.map(t=>s(`option`,{value:t,children:e.bare(C[t])},t))})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.col.context`)}),s(`input`,{type:`text`,value:N.context,onChange:e=>P(t=>({...t,context:e.target.value})),placeholder:`global`})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.detail.domain`)}),s(`input`,{type:`text`,value:N.domain,onChange:e=>P(t=>({...t,domain:e.target.value})),placeholder:e(`mem.form.domainPlaceholder`)})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.col.entity`)}),s(`input`,{type:`text`,value:N.entity,onChange:e=>P(t=>({...t,entity:e.target.value})),placeholder:e(`mem.form.entityPlaceholder`)})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.form.dueAt`)}),s(`input`,{type:`text`,value:N.due_at,onChange:e=>P(t=>({...t,due_at:e.target.value})),placeholder:e(`mem.form.dueAtPlaceholder`)})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.form.sensitive`)}),d(`label`,{style:{display:`flex`,alignItems:`center`,gap:6,cursor:`pointer`,fontSize:12},children:[s(`input`,{type:`checkbox`,checked:N.sensitive,onChange:e=>P(t=>({...t,sensitive:e.target.checked}))}),e(`mem.form.sensitiveHint`)]})]}),d(`div`,{className:`mem-inline-form-actions`,children:[s(`button`,{className:`btn-secondary`,onClick:()=>{pn(!1),mn(null)},children:e(`mem.cancel`)}),s(`button`,{className:`btn-primary`,onClick:M?Fr:Pr,style:{padding:`8px 20px`,fontSize:13},children:e(M?`mem.form.update`:`mem.form.save`)})]})]}),v&&v.items.length>0?d(a.Fragment,{children:[s(`div`,{style:{overflowX:`auto`},children:d(`table`,{className:`mem-knowledge-table`,children:[s(`thead`,{children:d(`tr`,{children:[d(`th`,{onClick:()=>Ur(`category`),className:O===`category`?`sorted`:``,children:[e(`mem.col.category`),ei(`category`)]}),s(`th`,{children:e(`mem.col.content`)}),d(`th`,{onClick:()=>Ur(`context`),className:O===`context`?`sorted`:``,children:[e(`mem.col.context`),ei(`context`)]}),s(`th`,{children:e(`mem.col.entity`)}),d(`th`,{onClick:()=>Ur(`confidence`),className:O===`confidence`?`sorted`:``,children:[e(`mem.col.confidence`),ei(`confidence`)]}),s(`th`,{children:e(`mem.col.source`)}),d(`th`,{onClick:()=>Ur(`updated_at`),className:O===`updated_at`?`sorted`:``,children:[e(`mem.col.updated`),ei(`updated_at`)]}),d(`th`,{onClick:()=>Ur(`created_at`),className:O===`created_at`?`sorted`:``,children:[e(`mem.col.created`),ei(`created_at`)]}),s(`th`,{children:e(`mem.col.due`)}),s(`th`,{className:`mem-actions-cell`})]})}),s(`tbody`,{children:v.items.map(t=>{let n=Ht===t.id,r=t.has_embedding;return d(y.Fragment,{children:[d(`tr`,{className:`${t.superseded_by?`mem-superseded-row`:``} ${n?`mem-expanded-row`:``}`,onClick:()=>Ut(n?null:t.id),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),Ut(n?null:t.id))},tabIndex:0,role:`row`,"aria-expanded":n,style:{cursor:`pointer`},children:[s(`td`,{children:s(`span`,{className:`mem-cat-badge ${t.category}`,children:t.category===`error`&&t.source===`error_auto`?e(`mem.cat.errorLearned`):s(w,{value:t.category,keys:C})})}),s(`td`,{children:d(`div`,{className:`mem-content-cell`,title:t.content,children:[r!==void 0&&s(`span`,{className:`mem-embed-dot ${r?`embedded`:`missing`}`,title:e(r?`mem.knowledge.embedded`:`mem.knowledge.embedMissing`),children:s(me,{size:6,fill:`currentColor`})}),t.sensitive&&s(`span`,{className:`mem-sensitive-badge`,title:e(`mem.form.sensitive`),children:s(st,{size:11})}),s(`span`,{className:t.sensitive&&!hn.has(t.id)?`mem-sensitive-blur`:t.superseded_by?`mem-superseded-text`:``,onClick:e=>{t.sensitive&&(e.stopPropagation(),gn(e=>{let n=new Set(e);return n.has(t.id)?n.delete(t.id):n.add(t.id),n}))},children:s(`bdi`,{children:t.content})})]})}),s(`td`,{children:s(`bdi`,{className:`mem-date-cell`,children:t.context})}),s(`td`,{children:t.entity?s(`span`,{className:`mem-entity-link`,onClick:e=>{e.stopPropagation(),Zt(t.entity),A(0)},title:e(`mem.knowledge.filterBy`,{entity:t.entity}),children:s(`bdi`,{children:t.entity})}):s(`span`,{className:`mem-date-cell`,children:`—`})}),s(`td`,{children:d(`div`,{className:`mem-confidence`,children:[s(`div`,{className:`mem-confidence-bar`,children:s(`div`,{className:`mem-confidence-fill ${St(t.confidence)}`,style:{width:`${t.confidence*100}%`}})}),t.confidence.toFixed(2)]})}),s(`td`,{children:s(`bdi`,{className:`mem-date-cell`,children:t.source||`—`})}),s(`td`,{children:s(`span`,{className:`mem-date-cell`,title:x(t.updated_at,u(e)),children:S(t.updated_at,e)})}),s(`td`,{children:s(`span`,{className:`mem-date-cell`,title:x(t.created_at,u(e)),children:S(t.created_at,e)})}),s(`td`,{children:t.due_at?s(`span`,{className:`mem-due-badge ${xt(t.due_at)?`overdue`:`upcoming`}`,title:x(t.due_at,u(e)),children:S(t.due_at,e)}):s(`span`,{className:`mem-due-badge none`,children:`—`})}),s(`td`,{className:`mem-actions-cell`,children:d(`div`,{className:`mem-row-actions`,onClick:e=>e.stopPropagation(),children:[s(`button`,{className:`mem-row-action-btn`,onClick:()=>Rr(t),title:e(`mem.row.edit`),children:s(Xe,{size:13})}),s(`button`,{className:`mem-row-action-btn`,onClick:()=>Lr(t),title:e(t.sensitive?`mem.row.unmarkSensitive`:`mem.row.markSensitive`),children:t.sensitive?s(at,{size:13}):s(st,{size:13})}),s(`button`,{className:`mem-row-action-btn`,onClick:()=>zr(t.id),title:e(`mem.row.copyId`),children:s(ce,{size:13})}),s(`button`,{className:`mem-row-action-btn delete${R===t.id?` is-confirm`:``}`,onClick:()=>Ir(t.id),title:e(R===t.id?`mem.row.clickAgain`:`mem.row.delete`),"aria-label":e(R===t.id?`mem.row.confirmDeleteAria`:`mem.row.deleteAria`),children:R===t.id?s(`span`,{className:`mem-row-delete-label`,children:e(`mem.row.deleteConfirm`)}):s(Ne,{size:13})})]})})]}),n&&s(`tr`,{className:`mem-detail-row`,children:s(`td`,{colSpan:10,children:d(`div`,{className:`mem-detail-panel`,children:[d(`div`,{className:`mem-detail-grid`,children:[d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.id`)}),s(`span`,{className:`mem-detail-value`,children:t.id})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.domain`)}),s(`bdi`,{className:`mem-detail-value`,children:t.domain||`—`})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.col.source`)}),s(`bdi`,{className:`mem-detail-value`,children:t.source||`—`})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.useCount`)}),s(`span`,{className:`mem-detail-value`,children:t.use_count??0})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.col.created`)}),s(`span`,{className:`mem-detail-value`,children:x(t.created_at,u(e))})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.col.updated`)}),s(`span`,{className:`mem-detail-value`,children:x(t.updated_at,u(e))})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.lastUsed`)}),s(`span`,{className:`mem-detail-value`,children:x(t.last_used,u(e))})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.remindedAt`)}),s(`span`,{className:`mem-detail-value`,children:x(t.reminded_at,u(e))})]}),t.superseded_by&&d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.supersededBy`)}),s(`span`,{className:`mem-detail-value mem-detail-chain`,children:t.superseded_by})]}),t.metadata&&d(`div`,{className:`mem-detail-field mem-detail-full`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.metadata`)}),s(`span`,{className:`mem-detail-value`,children:s(`bdi`,{dir:`ltr`,children:typeof t.metadata==`object`?JSON.stringify(t.metadata,null,2):t.metadata})})]})]}),d(`div`,{className:`mem-detail-content-full`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.fullContent`)}),s(`div`,{className:`mem-detail-content-text`,children:s(`bdi`,{children:t.content})})]})]})})})]},t.id)})})]})}),d(`div`,{className:`mem-pagination`,children:[s(`span`,{children:e(`mem.page.range`,{from:k+1,to:Math.min(k+15,v.total),total:v.total})}),d(`div`,{className:`mem-pagination-btns`,children:[s(`button`,{type:`button`,className:`mem-page-btn`,"aria-label":e(`mem.page.previous`),disabled:k===0,onClick:()=>A(Math.max(0,k-15)),children:s(we,{size:14})}),s(`button`,{type:`button`,className:`mem-page-btn`,"aria-label":e(`mem.page.next`),disabled:k+15>=v.total,onClick:()=>A(k+15),children:s(ue,{size:14})})]})]})]}):d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(p,{size:28})}),s(`p`,{children:e(Qt||D.length>0||Jt||Xt?`mem.knowledge.noMatch`:`mem.knowledge.empty`)})]})]}),d(`div`,{className:`mem-two-col`,children:[d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title`,children:[s(Ke,{size:14}),` `,e(`mem.tools.title`),s(`span`,{className:`mem-section-note`,title:e(`mem.tools.noteTitle`),children:e(`mem.tools.note`)})]}),dt.length>0?s(`div`,{style:{overflowX:`auto`},children:d(`table`,{className:`mem-tool-table`,children:[s(`thead`,{children:d(`tr`,{children:[s(`th`,{children:e(`mem.tools.tool`)}),s(`th`,{children:e(`mem.tools.calls`)}),s(`th`,{children:e(`mem.tools.success`)}),s(`th`,{children:e(`mem.tools.denied`)}),s(`th`,{children:e(`mem.tools.avgTime`)}),s(`th`,{children:e(`mem.detail.lastUsed`)}),s(`th`,{children:e(`mem.tools.lastError`)})]})}),s(`tbody`,{children:dt.map(t=>d(`tr`,{children:[s(`td`,{children:s(`bdi`,{className:`mem-tool-name`,children:t.tool_name})}),s(`td`,{children:t.total_calls}),s(`td`,{children:d(`div`,{className:`mem-confidence`,children:[s(`div`,{className:`mem-confidence-bar`,style:{width:40},children:s(`div`,{className:`mem-confidence-fill ${Ct(t.success_rate)}`,style:{width:`${t.success_rate*100}%`}})}),d(`span`,{className:`mem-success-rate ${Ct(t.success_rate)}`,children:[Math.round(t.success_rate*100),`%`]})]})}),s(`td`,{children:t.denied_count??0}),s(`td`,{children:s(`bdi`,{dir:`ltr`,children:bt(t.avg_duration_ms)})}),s(`td`,{children:s(`span`,{className:`mem-date-cell`,title:x(t.last_used,u(e)),children:S(t.last_used,e)})}),s(`td`,{children:s(`bdi`,{className:`mem-tool-error`,title:t.last_error||``,children:t.last_error||`—`})})]},t.tool_name))})]})}):d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(Ke,{size:28})}),s(`p`,{children:e(`mem.tools.empty`)})]})]}),d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title`,children:[s(fe,{size:14}),` `,e(`mem.upcoming.title`)]}),gt.length>0?s(`div`,{className:`mem-temporal-list`,children:gt.map(t=>{let n=xt(t.due_at);return d(`div`,{className:`mem-temporal-item ${n?`overdue`:`upcoming`}`,children:[s(`span`,{className:`mem-temporal-icon`,children:s(n?Je:fe,{size:16})}),d(`div`,{className:`mem-temporal-content`,children:[s(`div`,{className:`mem-temporal-text`,children:s(`bdi`,{children:t.content})}),d(`div`,{className:`mem-temporal-date`,children:[e(n?`mem.upcoming.overdue`:`mem.upcoming.due`,{when:S(t.due_at,e)}),t.context!==`global`&&d(a.Fragment,{children:[` `,`·`,` `,s(`bdi`,{children:t.context})]})]})]})]},t.id)})}):d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(tt,{size:28})}),s(`p`,{children:e(`mem.upcoming.empty`)})]})]})]}),d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title`,children:[s(ee,{size:14}),` `,e(`mem.conv.title`)]}),d(`div`,{className:`mem-conv-search`,children:[s(Ue,{size:13,className:`search-icon`}),s(`input`,{type:`text`,placeholder:e(`mem.conv.searchPlaceholder`),value:on,onChange:e=>Br(e.target.value),"aria-label":e(`mem.conv.search`)}),on&&s(`button`,{className:`mem-search-clear`,onClick:()=>{sn(``),ln(null)},"aria-label":e(`mem.conv.clearSearch`),children:s(We,{size:12})})]}),cn===null?mt.length>0?s(`div`,{className:`mem-conv-list`,children:mt.map(t=>d(`div`,{className:`mem-conv-item`,onClick:()=>Vr(t.session_id),children:[d(`div`,{className:`mem-conv-info`,children:[d(`div`,{className:`mem-conv-session-id`,children:[s(`bdi`,{children:Ve(t.session_id)}),t.consolidated&&s(`span`,{className:`mem-consolidated-badge`,title:e(`mem.conv.consolidated`),children:s(it,{size:11})})]}),t.first_message&&s(`div`,{className:`mem-conv-preview`,children:s(`bdi`,{children:t.first_message})})]}),d(`div`,{className:`mem-conv-meta`,children:[s(`span`,{children:e.plural(`mem.conv.turns`,t.turn_count)}),s(`span`,{children:S(t.last_activity,e)})]})]},t.session_id))}):d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(ee,{size:28})}),s(`p`,{children:e(`mem.conv.empty`)})]}):cn.length>0?s(`div`,{className:`mem-conv-list`,children:cn.map(t=>d(`div`,{className:`mem-conv-item`,onClick:()=>Vr(t.session_id),children:[d(`div`,{className:`mem-conv-info`,children:[d(`div`,{className:`mem-conv-session-id`,children:[s(`span`,{className:`mem-conv-turn-role ${t.role}`,children:s(w,{value:t.role,keys:At})}),` `,s(`bdi`,{children:Ve(t.session_id)})]}),s(`div`,{className:`mem-conv-preview`,children:s(`bdi`,{children:t.content})})]}),s(`div`,{className:`mem-conv-meta`,children:s(`span`,{children:S(t.timestamp,e)})})]},t.id))}):s(`div`,{className:`mem-empty`,children:s(`p`,{children:e(`mem.conv.noMatch`,{query:on})})})]}),j&&d(`div`,{className:`mem-conv-detail-overlay`,children:[d(`div`,{className:`mem-conv-detail-header`,children:[s(`h2`,{children:s(`bdi`,{children:Ve(j.sessionId)})}),d(`div`,{className:`mem-conv-detail-actions`,children:[Be.has(j.sessionId)&&s(`button`,{className:`btn-secondary`,onClick:()=>l(j.sessionId),children:e(`mem.conv.openChat`)}),s(`button`,{className:`btn-icon`,onClick:()=>dn(null),"aria-label":e(`mem.conv.close`),children:s(We,{size:16})})]})]}),d(`div`,{className:`mem-conv-detail-body`,children:[j.turns.map(t=>d(`div`,{className:`mem-conv-turn`,children:[d(`div`,{className:`mem-conv-turn-header`,children:[s(`div`,{className:`mem-conv-turn-role ${t.role}`,children:s(w,{value:t.role,keys:At})}),s(`span`,{className:`mem-conv-turn-time`,title:x(t.timestamp,u(e)),children:S(t.timestamp,e)})]}),s(`div`,{className:`mem-conv-turn-content`,children:s(`bdi`,{children:t.content})})]},t.id)),j.turns.length===0&&s(`div`,{className:`mem-empty`,children:e(`mem.conv.noTurns`)})]})]})]}),d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title`,children:[s(st,{size:14}),` `,e(`mem.settings.title`),` `,s(`span`,{className:`mem-beta`,style:{fontSize:10,fontWeight:600,color:`var(--accent-yellow)`,background:`var(--accent-yellow-dim)`,padding:`1px 6px`,borderRadius:4,marginInlineStart:6,verticalAlign:`middle`},children:e(`mem.beta`)})]}),d(`div`,{className:`mem-setting-row`,children:[d(`div`,{className:`mem-setting-info`,children:[s(`span`,{className:`mem-setting-label`,children:e(`mem.settings.memory`)}),s(`span`,{className:`mem-setting-desc`,children:e(`mem.settings.memoryDesc`)})]}),s(`button`,{className:`mem-toggle${F?` mem-toggle-on`:``}`,disabled:I,onClick:async()=>{if(!F)z(`memory`);else{L(!0);try{let e=await f({memory_enabled:!1});_n(e.memory_enabled)}catch(n){t.system.warn(`Failed to disable memory`,n),X(e(`mem.toast.settingFailed`,{error:T(n)}),`error`)}finally{L(!1)}}},"aria-pressed":F,"aria-label":e(F?`mem.settings.memoryOn`:`mem.settings.memoryOff`),children:e.bare(F?`mem.on`:`mem.off`)})]}),Dn&&(()=>{let n={memory:{title:`mem.beta.memory.title`,description:`mem.beta.memory.desc`,bullets:[`mem.beta.memory.local`,`mem.beta.memory.lost`,`mem.beta.memory.disable`],buttonLabel:`mem.beta.memory.confirm`,onConfirm:async()=>{let t=await f({memory_enabled:!0});_n(t.memory_enabled),X(e(`mem.toast.memoryEnabled`),`info`)}},mcp:{title:`mem.beta.mcp.title`,description:`mem.beta.mcp.desc`,bullets:[`mem.beta.mcp.read`,`mem.beta.mcp.restart`,`mem.beta.mcp.debug`],buttonLabel:`mem.beta.mcp.confirm`,onConfirm:async()=>{let t=await f({mcp_memory_enabled:!0});yn(t.mcp_memory_enabled),X(e(`mem.toast.mcpEnabled`),`info`)}},discovery:{title:`mem.beta.discovery.title`,description:`mem.beta.discovery.desc`,bullets:[`mem.beta.discovery.collects`,`mem.beta.discovery.scans`,`mem.beta.discovery.local`],buttonLabel:`mem.beta.discovery.confirm`,onConfirm:async()=>{let t=await f({system_discovery_consent:!0});if(xn(t.system_discovery_consent),t.system_context_error)X(e(`mem.toast.discoveryScanFailed`,{error:t.system_context_error}),`error`);else{let n=t.system_context_refresh?.stored??0;X(e(`mem.toast.discoveryEnabled`,{n}),`info`)}Q()}}}[Dn];return d(a.Fragment,{children:[s(`div`,{"aria-hidden":`true`,style:{position:`fixed`,inset:0,background:`var(--bg-modal-overlay)`,zIndex:9998,backdropFilter:`blur(4px)`},onClick:()=>z(null)}),d(`div`,{ref:br,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`mem-beta-confirm-title`,"aria-describedby":`mem-beta-confirm-desc`,tabIndex:-1,style:{position:`fixed`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,zIndex:9999,background:`var(--bg-card)`,border:`1px solid var(--border)`,borderRadius:12,padding:`28px 32px`,maxWidth:420,width:`90vw`,boxShadow:`var(--shadow-lg)`},children:[d(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,marginBottom:16},children:[s(`span`,{className:`mem-beta`,style:{fontSize:11,fontWeight:700,color:`var(--accent-yellow)`,background:`var(--accent-yellow-dim)`,padding:`3px 10px`,borderRadius:4},children:e(`mem.beta`)}),s(`h2`,{id:`mem-beta-confirm-title`,style:{fontSize:16,fontWeight:600,color:`var(--text-primary)`},children:e(n.title)})]}),s(`p`,{id:`mem-beta-confirm-desc`,style:{fontSize:13,lineHeight:1.6,color:`var(--text-secondary)`,margin:`0 0 8px`},children:e(n.description)}),s(`ul`,{style:{fontSize:13,lineHeight:1.7,color:`var(--text-secondary)`,margin:`0 0 24px`,paddingInlineStart:20},children:n.bullets.map(t=>s(`li`,{children:e(t)},t))}),d(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:10},children:[s(`button`,{className:`btn-secondary`,onClick:()=>z(null),style:{padding:`8px 20px`,fontSize:13,borderRadius:6},children:e(`mem.cancel`)}),s(`button`,{disabled:I,onClick:async()=>{L(!0);try{await n.onConfirm()}catch(n){t.system.warn(`Failed to update setting`,n),X(e(`mem.toast.settingFailed`,{error:T(n)}),`error`)}finally{L(!1),z(null)}},style:{padding:`8px 24px`,fontSize:13,fontWeight:600,borderRadius:6,border:`none`,cursor:`pointer`,background:`var(--accent-fill)`,color:`var(--accent-fill-text)`},children:e(n.buttonLabel)})]})]})]})})(),d(`div`,{className:`mem-setting-row`,children:[d(`div`,{className:`mem-setting-info`,children:[s(`span`,{className:`mem-setting-label`,children:e(`mem.settings.mcp`)}),s(`span`,{className:`mem-setting-desc`,children:e(`mem.settings.mcpDesc`)})]}),s(`button`,{className:`mem-toggle${vn?` mem-toggle-on`:``}`,disabled:I,onClick:async()=>{if(!vn)z(`mcp`);else{L(!0);try{let e=await f({mcp_memory_enabled:!1});yn(e.mcp_memory_enabled)}catch(n){t.system.warn(`Failed to update memory settings`,n),X(e(`mem.toast.settingFailed`,{error:T(n)}),`error`)}finally{L(!1)}}},"aria-label":e(`mem.settings.mcpToggle`),"aria-pressed":vn,children:e.bare(vn?`mem.on`:`mem.off`)})]}),d(`div`,{className:`mem-setting-row`,children:[d(`div`,{className:`mem-setting-info`,children:[s(`span`,{className:`mem-setting-label`,children:e(`mem.settings.discovery`)}),s(`span`,{className:`mem-setting-desc`,children:e(`mem.settings.discoveryDesc`)})]}),s(`button`,{className:`mem-toggle${bn?` mem-toggle-on`:``}`,disabled:I,onClick:async()=>{if(!bn)z(`discovery`);else{L(!0);try{let e=await f({system_discovery_consent:!1});xn(e.system_discovery_consent)}catch(n){t.system.warn(`Failed to update system discovery setting`,n),X(e(`mem.toast.settingFailed`,{error:T(n)}),`error`)}finally{L(!1)}}},"aria-label":e(`mem.settings.discoveryToggle`),"aria-pressed":bn,children:e.bare(bn?`mem.on`:`mem.off`)})]}),d(`div`,{className:`mem-setting-row mem-setting-row-danger`,children:[d(`div`,{className:`mem-setting-info`,children:[s(`span`,{className:`mem-setting-label`,children:e(`mem.settings.reinit`)}),s(`span`,{className:`mem-setting-desc`,children:e(`mem.settings.reinitDesc`)})]}),Tn?d(`div`,{className:`mem-delete-confirm`,children:[s(`span`,{className:`mem-delete-confirm-label`,children:e(`mem.settings.sure`)}),s(`button`,{className:`mem-btn-danger`,disabled:I,onClick:async()=>{L(!0);try{let t=await le();t.system_context.error?X(e(`mem.toast.server`,{message:t.system_context.error}),`error`):X(e(`mem.toast.reinitialized`,{cleared:t.cleared.knowledge,stored:t.system_context.stored}),`info`),Q()}catch(n){t.system.warn(`Failed to reinitialize memory`,n),X(e(`mem.toast.reinitFailed`,{error:T(n)}),`error`)}finally{L(!1),En(!1)}},children:e(`mem.settings.reinitConfirm`)}),s(`button`,{className:`btn-secondary`,onClick:()=>En(!1),style:{padding:`6px 14px`,fontSize:12},children:e(`mem.cancel`)})]}):s(`button`,{className:`mem-btn-danger`,disabled:I,onClick:()=>En(!0),children:e(`mem.settings.reinitButton`)})]}),d(`div`,{className:`mem-setting-row mem-setting-row-danger`,children:[d(`div`,{className:`mem-setting-info`,children:[s(`span`,{className:`mem-setting-label`,children:e(`mem.settings.deleteAll`)}),s(`span`,{className:`mem-setting-desc`,children:e(`mem.settings.deleteAllDesc`)})]}),Sn?d(`div`,{className:`mem-delete-confirm`,children:[s(`span`,{className:`mem-delete-confirm-label`,children:e(`mem.settings.sure`)}),s(`button`,{className:`mem-btn-danger`,disabled:I,onClick:async()=>{L(!0);try{let t=await Le();X(e(`mem.toast.cleared`,{knowledge:t.knowledge,conversations:t.conversations}),`info`),Q()}catch(n){t.system.warn(`Failed to clear memory`,n),X(e(`mem.toast.clearFailed`,{error:T(n)}),`error`)}finally{L(!1),Cn(!1)}},children:e(`mem.settings.deleteConfirm`)}),s(`button`,{className:`btn-secondary`,onClick:()=>Cn(!1),style:{padding:`6px 14px`,fontSize:12},children:e(`mem.cancel`)})]}):s(`button`,{className:`mem-btn-danger`,disabled:I,onClick:()=>Cn(!0),children:e(`mem.settings.deleteButton`)})]})]}),g&&d(`div`,{className:`mem-db-footer`,children:[d(`span`,{children:[e(`mem.footer.database`),`: `,s(`bdi`,{dir:`ltr`,children:qe(g.db_size_bytes)}),g.knowledge?.avg_confidence!=null&&d(a.Fragment,{children:[` · `,e(`mem.footer.avgConfidence`,{n:g.knowledge.avg_confidence.toFixed(2)})]})]}),d(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[g.knowledge?.entity_count!=null&&g.knowledge.entity_count>0&&s(`span`,{children:e(`mem.footer.entities`,{n:g.knowledge.entity_count})}),g.knowledge?.sensitive_count!=null&&g.knowledge.sensitive_count>0&&d(`span`,{children:[s(st,{size:10}),` `,e(`mem.footer.sensitive`,{n:g.knowledge.sensitive_count})]})]})]})]})}),B===`profile`&&d(`div`,{className:`mem-profile-grid`,children:[d(`div`,{className:`mem-profile-card`,children:[d(`div`,{className:`mem-profile-card-title`,children:[s(ve,{size:16}),` `,e(`mem.disc.title`)]}),s(`p`,{className:`mem-profile-desc`,children:e(`mem.disc.desc`)}),s(`button`,{className:`btn-primary mem-profile-run-btn`,disabled:V===`running`||V===`saving`,onClick:Xr,children:V===`running`?d(a.Fragment,{children:[s(`div`,{className:`mem-spinner-sm`}),` `,e(`mem.running`)]}):e(`mem.disc.run`)}),Gn.length>0&&s(`div`,{className:`mem-log`,ref:Jn,children:Gn.map((e,t)=>s(`div`,{className:`mem-log-line ${e.kind}`,children:e.server?s(`bdi`,{children:e.text}):e.text},t))}),(V===`review`||V===`saving`||V===`done`)&&W.length>0&&d(`div`,{className:`mem-review-section`,children:[s(`div`,{className:`mem-review-header`,children:e(`mem.review.title`)}),s(`div`,{className:`mem-review-list`,children:W.map((e,t)=>d(`label`,{className:`mem-review-item`,children:[s(`input`,{type:`checkbox`,checked:e._checked,disabled:V===`saving`||V===`done`,onChange:()=>{G(e=>e.map((e,n)=>n===t?{...e,_checked:!e._checked}:e))}}),s(`bdi`,{className:`mem-review-content`,children:e.content}),s(`span`,{className:`mem-source-badge`,children:e._source_name?s(`bdi`,{children:e._source_name}):s(w,{value:e.category,keys:C})}),d(`span`,{className:`mem-conf-badge`,children:[Math.round(e.confidence*100),`%`]})]},t))}),d(`div`,{className:`mem-review-actions`,children:[s(`button`,{className:`btn-primary`,disabled:V===`saving`||V===`done`||W.filter(e=>e._checked).length===0,onClick:Zr,children:V===`saving`?d(a.Fragment,{children:[s(`div`,{className:`mem-spinner-sm`}),` `,e(`mem.saving`)]}):e(`mem.review.saveSelected`,{n:W.filter(e=>e._checked).length})}),d(`span`,{className:`mem-review-select-links`,children:[s(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>G(e=>e.map(e=>({...e,_checked:!0}))),children:e(`mem.review.selectAll`)}),` / `,s(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>G(e=>e.map(e=>({...e,_checked:!1}))),children:e(`mem.review.none`)})]})]})]}),V===`done`&&Kn!==null&&d(`div`,{className:`mem-profile-success`,children:[s(tt,{size:14}),` `,e(`mem.disc.saved`,{n:Kn})]}),V===`review`&&W.length===0&&s(`div`,{className:`mem-profile-empty`,children:e(`mem.disc.empty`)})]}),d(`div`,{className:`mem-profile-card`,children:[d(`div`,{className:`mem-profile-card-title`,children:[s(Pe,{size:16}),` `,e(`mem.inf.title`)]}),s(`p`,{className:`mem-profile-desc`,children:e(`mem.inf.desc`)}),s(`p`,{className:`mem-profile-note`,children:e(`mem.inf.note`)}),d(`label`,{className:`mem-profile-checkbox`,children:[s(`input`,{type:`checkbox`,checked:er,onChange:e=>tr(e.target.checked),disabled:K===`running`||K===`saving`}),e(`mem.inf.browser`)]}),s(`button`,{className:`btn-primary mem-profile-run-btn`,disabled:K===`running`||K===`saving`,onClick:Qr,children:K===`running`?d(a.Fragment,{children:[s(`div`,{className:`mem-spinner-sm`}),` `,e(`mem.running`)]}):e(`mem.inf.run`)}),Xn.length>0&&s(`div`,{className:`mem-log`,ref:nr,children:Xn.map((e,t)=>s(`div`,{className:`mem-log-line ${e.kind}`,children:e.server?s(`bdi`,{children:e.text}):e.text},t))}),(K===`review`||K===`saving`||K===`done`)&&Y.length>0&&d(`div`,{className:`mem-review-section`,children:[s(`div`,{className:`mem-review-header`,children:e(`mem.review.title`)}),s(`div`,{className:`mem-review-list`,children:Y.map((e,t)=>d(`label`,{className:`mem-review-item`,children:[s(`input`,{type:`checkbox`,checked:e._checked,disabled:K===`saving`||K===`done`,onChange:()=>{Zn(e=>e.map((e,n)=>n===t?{...e,_checked:!e._checked}:e))}}),s(`bdi`,{className:`mem-review-content`,children:e.content}),s(`span`,{className:`mem-domain-badge ${Mt[e.domain]||`gray`}`,children:s(w,{value:e.domain,keys:jt})}),d(`span`,{className:`mem-conf-badge`,children:[Math.round(e.confidence*100),`%`]})]},t))}),d(`div`,{className:`mem-review-actions`,children:[s(`button`,{className:`btn-primary`,disabled:K===`saving`||K===`done`||Y.filter(e=>e._checked).length===0,onClick:$r,children:K===`saving`?d(a.Fragment,{children:[s(`div`,{className:`mem-spinner-sm`}),` `,e(`mem.saving`)]}):e(`mem.review.saveSelected`,{n:Y.filter(e=>e._checked).length})}),d(`span`,{className:`mem-review-select-links`,children:[s(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>Zn(e=>e.map(e=>({...e,_checked:!0}))),children:e(`mem.review.selectAll`)}),` / `,s(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>Zn(e=>e.map(e=>({...e,_checked:!1}))),children:e(`mem.review.none`)})]})]})]}),K===`done`&&Qn!==null&&d(`div`,{className:`mem-profile-success`,children:[s(tt,{size:14}),` `,e(`mem.inf.saved`,{n:Qn})]}),K===`review`&&Y.length===0&&s(`div`,{className:`mem-profile-empty`,children:e(`mem.inf.empty`)})]})]}),B===`goals`&&d(`div`,{className:`mem-goals-tab`,children:[s(`div`,{className:`mem-goals-stats-row`,children:[`queued`,`in_progress`,`completed`,`failed`].map(t=>d(`div`,{className:`mem-goals-stat-pill mem-goal-status-${t.replace(`_`,`-`)}`,children:[s(`span`,{className:`mem-goals-stat-n`,children:Nn?.goals[t]??0}),s(`span`,{className:`mem-goals-stat-label`,children:e(Dt[t])})]},t))}),jn.filter(e=>e.status===`pending_approval`).length>0&&d(`div`,{className:`mem-goals-approval-banner`,children:[d(`div`,{className:`mem-goals-approval-title`,children:[s(te,{size:14}),` `,e(`mem.goals.suggested`,{n:jn.filter(e=>e.status===`pending_approval`).length})]}),jn.filter(e=>e.status===`pending_approval`).map(t=>d(`div`,{className:`mem-goals-approval-item`,children:[d(`div`,{className:`mem-goals-approval-text`,children:[s(`strong`,{children:s(`bdi`,{children:t.title})}),s(`bdi`,{children:t.description})]}),d(`div`,{className:`mem-goals-approval-actions`,children:[s(`button`,{className:`btn-danger-sm`,onClick:()=>Ar(()=>Ce(t.id),`mem.goals.rejectFailed`),children:e(`mem.goals.reject`)}),s(`button`,{className:`btn-secondary`,onClick:()=>Ar(()=>Ge(t.id),`mem.goals.acceptFailed`),children:e(`mem.goals.accept`)})]})]},t.id))]}),s(`div`,{className:`mem-goals-toolbar`,children:d(`button`,{className:`btn-primary`,onClick:()=>Hn(e=>!e),children:[s(Ae,{size:14}),` `,e(`mem.goals.new`)]})}),Vn&&d(`div`,{className:`mem-goals-add-form`,children:[s(`input`,{className:`mem-input`,placeholder:e(`mem.goals.titlePlaceholder`),value:Un.title,onChange:e=>Wn(t=>({...t,title:e.target.value}))}),s(`textarea`,{className:`mem-input`,placeholder:e(`mem.goals.descPlaceholder`),rows:2,value:Un.description,onChange:e=>Wn(t=>({...t,description:e.target.value}))}),d(`div`,{className:`mem-goals-form-row`,children:[d(`select`,{className:`mem-select`,value:Un.priority,onChange:e=>Wn(t=>({...t,priority:e.target.value})),children:[s(`option`,{value:`low`,children:e.bare(`mem.goals.priorityLow`)}),s(`option`,{value:`medium`,children:e.bare(`mem.goals.priorityMedium`)}),s(`option`,{value:`high`,children:e.bare(`mem.goals.priorityHigh`)})]}),s(`button`,{className:`btn-primary`,onClick:()=>{Un.title.trim()&&Ar(async()=>{await $e(Un),Wn({title:``,description:``,priority:`medium`}),Hn(!1)},`mem.goals.createFailed`)},children:e(`mem.goals.create`)}),s(`button`,{className:`btn-secondary`,onClick:()=>Hn(!1),children:e(`mem.cancel`)})]})]}),Fn?d(`div`,{className:`mem-loading`,children:[s(`div`,{className:`mem-spinner`}),` `,e(`mem.goals.loading`)]}):jn.filter(e=>e.status!==`pending_approval`&&e.status!==`rejected`).length===0?d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(ct,{size:32})}),s(`p`,{children:e(`mem.goals.empty`)})]}):s(`div`,{className:`mem-goals-list`,children:jn.filter(e=>e.status!==`pending_approval`&&e.status!==`rejected`).map(t=>d(`div`,{className:`mem-goal-card mem-goal-status-${t.status.replace(`_`,`-`)}`,children:[d(`div`,{className:`mem-goal-header`,role:`button`,tabIndex:0,"aria-expanded":Ln===t.id,onClick:()=>Rn(e=>e===t.id?null:t.id),onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),Rn(e=>e===t.id?null:t.id))},children:[d(`div`,{className:`mem-goal-header-left`,children:[s(`span`,{className:`mem-goal-status-dot status-${t.status.replace(`_`,`-`)}`}),s(`bdi`,{className:`mem-goal-title`,children:t.title}),s(`span`,{className:`mem-goal-priority mem-priority-${t.priority}`,children:s(w,{value:t.priority,keys:Ot})}),t.source!==`user`&&d(`span`,{className:`mem-goal-source-badge`,children:[s(te,{size:10}),` `,s(w,{value:t.source,keys:kt})]})]}),d(`div`,{className:`mem-goal-header-right`,children:[d(`span`,{className:`mem-goal-task-count`,children:[s(xe,{size:12}),d(`bdi`,{dir:`ltr`,children:[t.tasks.filter(e=>e.status===`completed`).length,`/`,t.tasks.length]})]}),t.status===`queued`&&s(`button`,{className:`mem-goal-action-btn mem-goal-cancel-btn`,onClick:e=>{e.stopPropagation(),Ar(()=>He(t.id),`mem.goals.cancelFailed`)},children:e(`mem.cancel`)}),zn===t.id?s(`button`,{className:`mem-goal-action-btn mem-goal-delete-btn mem-goal-delete-confirm`,onClick:e=>{e.stopPropagation(),Bn(null),Ar(()=>Qe(t.id),`mem.goals.deleteFailed`)},children:e(`mem.row.deleteConfirm`)}):s(`button`,{className:`mem-goal-action-btn mem-goal-delete-btn`,"aria-label":e(`mem.goals.deleteAria`,{title:t.title}),onClick:e=>{e.stopPropagation(),Bn(t.id)},children:s(Ne,{size:12})}),s(De,{size:14,className:Ln===t.id?`mem-chevron-open`:``})]})]}),Ln===t.id&&d(`div`,{className:`mem-goal-body`,children:[t.description&&s(`p`,{className:`mem-goal-desc`,children:s(`bdi`,{children:t.description})}),t.progress_notes&&s(`p`,{className:`mem-goal-progress`,children:s(`bdi`,{children:t.progress_notes})}),t.tasks.length>0?s(`div`,{className:`mem-task-list`,children:t.tasks.map(e=>d(`div`,{className:`mem-task-row mem-task-status-${e.status}`,children:[s(`span`,{className:`mem-task-dot status-${e.status}`}),s(`bdi`,{className:`mem-task-desc`,children:e.description}),s(`span`,{className:`mem-task-status-label`,children:s(w,{value:e.status,keys:Dt})}),e.result&&s(`bdi`,{className:`mem-task-result`,children:e.result})]},e.id))}):s(`p`,{className:`mem-goal-no-tasks`,children:e(`mem.goals.noTasks`)})]})]},t.id))})]})]}),Wt.length>0&&s(`div`,{className:`mem-toast-container`,"aria-live":`polite`,children:Wt.map(e=>d(`div`,{className:`mem-toast mem-toast-${e.type}`,role:`status`,children:[e.type===`success`&&s(tt,{size:14}),e.type===`error`&&s(Je,{size:14}),e.type===`info`&&s(p,{size:14}),s(`span`,{children:e.text})]},e.id))})]})}export{Nt as MemoryDashboard};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{I as t,J as n,N as r,a as i,c as a,f as o,l as s,q as c,r as l,t as u,u as d}from"./useT-9bLwAbF7.js";import{n as ee,t as te}from"./zap-gjTc4oQN.js";import{A as ne,B as re,C as ie,D as ae,E as oe,F as se,Ft as ce,G as f,H as le,Ht as ue,I as de,It as fe,Kt as p,L as pe,Lt as me,M as he,N as m,Nt as ge,O as _e,P as h,Pt as ve,R as ye,S as be,St as xe,T as Se,U as Ce,Ut as we,V as Te,W as Ee,Wt as De,X as Oe,_ as ke,_t as Ae,at as je,b as Me,dt as Ne,ft as Pe,g as Fe,gt as Ie,h as Le,j as Re,k as ze,kt as Be,lt as Ve,m as He,mt as Ue,ot as We,p as Ge,st as Ke,t as qe,ut as Je,v as Ye,vt as Xe,w as Ze,x as Qe,y as $e,z as et,zt as tt}from"./index-BSZT2AHb.js";var g={name:`arrow-left`,size:24,node:[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]};g.node;var nt=c(g),rt={name:`git-merge`,size:24,node:[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]};rt.node;var it=c(rt),_={name:`shield-off`,size:24,node:[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]};_.node;var at=c(_),ot={name:`shield`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]};ot.node;var st=c(ot),v={name:`target`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`6`,key:`1vlfrh`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]};v.node;var ct=c(v),lt={name:`trending-up`,size:24,node:[[`path`,{d:`M16 7h6v6`,key:`box55l`}],[`path`,{d:`m22 7-8.5 8.5-5-5L2 17`,key:`1t1m79`}]]};lt.node;var ut=c(lt),dt={name:`user`,size:24,node:[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]};dt.node;var ft=c(dt),y=e(n(),1),pt=[{title:`mem.about.group.preferences`,categories:[`preference`]},{title:`mem.about.group.about`,categories:[`fact`,`profile`,`skill`]},{title:`mem.about.group.reminders`,categories:[`reminder`]},{title:`mem.about.group.notes`,categories:[`note`]}],mt={user:`mem.source.user`,tool:`mem.source.tool`,llm_extract:`mem.source.llm_extract`,consolidation:`mem.source.consolidation`,inferred:`mem.source.inferred`,discovery:`mem.source.discovery`};function ht(e){return mt[e]??`mem.source.other`}function gt(e,t){let n=new Date(e);if(Number.isNaN(n.getTime()))return null;let i=Math.floor((Date.now()-n.getTime())/864e5);return i<=0?r(`mem.day.today`):i===1?r(`mem.day.yesterday`):i<30?r(`mem.day.daysAgo`,{n:i}):n.toLocaleDateString(u(t),{month:`short`,day:`numeric`,year:`numeric`})}function _t(e,t=new Date,n=l){let r=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e),i=r?new Date(+r[1],r[2]-1,+r[3]):new Date(e);if(Number.isNaN(i.getTime()))return null;let a=i.getHours()===0&&i.getMinutes()===0&&i.getSeconds()===0,o=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),s=a?i.getTime()<o:i.getTime()<t.getTime(),c=i.toLocaleString(u(n),{weekday:`short`,month:`short`,day:`numeric`,...i.getFullYear()===t.getFullYear()?{}:{year:`numeric`},...a?{}:{hour:`numeric`,minute:`2-digit`}});return{text:n(s?`mem.due.past`:`mem.due.upcoming`,{when:c}),past:s}}function vt({memoryEnabled:e,reloadKey:n,onChanged:o,onOpenAdvanced:c,showToast:l}){let u=i(),[ee,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(null),[ae,oe]=(0,y.useState)(null),[se,ce]=(0,y.useState)(``),[f,le]=(0,y.useState)([]),[ue,de]=(0,y.useState)(new Set),[fe,p]=(0,y.useState)(``),[pe,me]=(0,y.useState)(`fact`),[he,m]=(0,y.useState)(null),ge=(0,y.useRef)(0),h=(0,y.useCallback)(async()=>{let e=++ge.current;try{let t=await _e({about_user:!0,include_sensitive:!0,sort_by:`updated_at`,order:`desc`,limit:200});if(e!==ge.current)return;te(t.items),re(null)}catch(n){if(e!==ge.current)return;t.system.warn(`Failed to load what GAIA knows about the user`,n),re(n instanceof Error?n.message:String(n))}},[]);(0,y.useEffect)(()=>{h()},[h,n]);let ve=(0,y.useCallback)(async e=>{let n=se.trim();if(!n||n===e.content)oe(null);else{m(e.id);try{await ie(e.id,{content:n}),oe(null),l(u(`mem.about.updated`),`success`),await h(),o()}catch(e){t.system.error(`Failed to edit memory`,e),l(u(`mem.about.editFailed`,{error:b(e)}),`error`)}finally{m(null)}}},[se,h,o,l,u]),ye=(0,y.useCallback)(async e=>{m(e.id);try{await be(e.id),ge.current++,te(t=>(t??[]).filter(t=>t.id!==e.id)),le(t=>[e,...t]),o()}catch(e){t.system.error(`Failed to forget memory`,e),l(u(`mem.about.forgetFailed`,{error:b(e)}),`error`)}finally{m(null)}},[o,l,u]),xe=(0,y.useCallback)(async e=>{m(e.id);try{await Me({content:e.content,category:e.category,domain:e.domain??void 0,context:e.context,entity:e.entity??void 0,sensitive:e.sensitive,due_at:e.due_at??void 0}),le(t=>t.filter(t=>t.id!==e.id)),await h(),o()}catch(e){t.system.error(`Failed to restore memory`,e),l(u(`mem.about.restoreFailed`,{error:b(e)}),`error`)}finally{m(null)}},[h,o,l,u]),Se=(0,y.useCallback)(async()=>{let e=fe.trim();if(e){m(`new`);try{await Me({content:e,category:pe}),p(``),l(u(`mem.about.saved`),`success`),await h(),o()}catch(e){t.system.error(`Failed to add memory`,e),l(u(`mem.about.addFailed`,{error:b(e)}),`error`)}finally{m(null)}}},[fe,pe,h,o,l,u]);if(!e)return d(`div`,{className:`mem-about`,children:[s(`h2`,{className:`mem-about-title`,children:u(`mem.about.title`)}),d(`div`,{className:`mem-about-empty`,children:[s(`p`,{children:u(`mem.about.off`)}),s(`button`,{className:`btn-secondary`,onClick:c,children:u(`mem.about.turnOn`)})]})]});let Ce=pt.map(e=>({...e,rows:(ee??[]).filter(t=>e.categories.includes(t.category))})).filter(e=>e.rows.length>0);return d(`div`,{className:`mem-about`,children:[s(`h2`,{className:`mem-about-title`,children:u(`mem.about.title`)}),s(`p`,{className:`mem-about-intro`,children:u(`mem.about.intro`)}),d(`form`,{className:`mem-about-add`,onSubmit:e=>{e.preventDefault(),Se()},children:[s(`input`,{className:`mem-input`,placeholder:u(`mem.about.addPlaceholder`),"aria-label":u(`mem.about.addLabel`),value:fe,onChange:e=>p(e.target.value)}),d(`select`,{className:`mem-select`,"aria-label":u(`mem.about.kind`),value:pe,onChange:e=>me(e.target.value),children:[s(`option`,{value:`fact`,children:u.bare(`mem.about.group.about`)}),s(`option`,{value:`preference`,children:u.bare(`mem.about.kind.preference`)}),s(`option`,{value:`reminder`,children:u.bare(`mem.about.kind.reminder`)}),s(`option`,{value:`note`,children:u.bare(`mem.about.kind.note`)})]}),d(`button`,{className:`btn-primary`,type:`submit`,disabled:!fe.trim()||he===`new`,children:[s(Ae,{size:14}),` `,u(`mem.about.add`)]})]}),f.map(e=>d(`div`,{className:`mem-about-forgotten`,role:`status`,children:[s(`span`,{children:e.sensitive?u(`mem.about.forgottenSensitive`):u(`mem.about.forgotten`,{content:e.content})}),d(`button`,{className:`mem-about-link`,disabled:he===e.id,onClick:()=>xe(e),children:[s(Ve,{size:12}),` `,u(`mem.about.undo`)]})]},e.id)),ne?d(`div`,{className:`mem-about-empty`,children:[s(`p`,{children:u(`mem.about.loadFailed`,{error:ne})}),s(`button`,{className:`btn-secondary`,onClick:h,children:u(`mem.about.retry`)})]}):ee===null?d(`div`,{className:`mem-loading`,children:[s(`div`,{className:`mem-spinner`}),` `,u(`mem.loading`)]}):Ce.length===0?d(`div`,{className:`mem-about-empty`,children:[s(`p`,{children:u(`mem.about.empty`)}),s(`p`,{className:`mem-about-hint`,children:u(`mem.about.emptyHint`)})]}):Ce.map(e=>d(`section`,{className:`mem-about-group`,"aria-label":u(e.title),children:[s(`h3`,{className:`mem-about-group-title`,children:u(e.title)}),s(`ul`,{className:`mem-about-list`,children:e.rows.map(e=>{let t=e.sensitive&&!ue.has(e.id),n=e.due_at?_t(e.due_at,new Date,u):null,i=gt(e.updated_at,u),o=t?r(`mem.about.sensitiveMemory`):e.content;return s(`li`,{className:`mem-about-item`,children:ae===e.id?d(`form`,{className:`mem-about-edit`,onSubmit:t=>{t.preventDefault(),ve(e)},children:[s(`textarea`,{className:`mem-input`,"aria-label":u(`mem.about.editLabel`),rows:2,autoFocus:!0,value:se,onChange:e=>ce(e.target.value),onKeyDown:t=>{t.key===`Escape`&&(t.stopPropagation(),oe(null)),t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ve(e))}}),d(`div`,{className:`mem-about-edit-actions`,children:[s(`button`,{className:`btn-primary`,type:`submit`,disabled:he===e.id,children:u(`mem.about.save`)}),s(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>oe(null),children:u(`mem.about.cancel`)})]})]}):d(a.Fragment,{children:[d(`div`,{className:`mem-about-text`,children:[t?d(`button`,{className:`mem-about-link`,onClick:()=>de(t=>new Set(t).add(e.id)),children:[s(Be,{size:12}),` `,u(`mem.about.showSensitive`)]}):s(`bdi`,{children:e.content}),n&&s(`span`,{className:`mem-about-due${n.past?` is-overdue`:``}`,children:n.text}),s(`span`,{className:`mem-about-meta`,children:i===null?u(ht(e.source)):u(`mem.about.meta`,{source:r(ht(e.source)),when:i})})]}),d(`div`,{className:`mem-about-actions`,children:[s(`button`,{className:`mem-about-btn`,"aria-label":u(`mem.about.editAria`,{name:o}),title:u(`mem.about.edit`),onClick:()=>{oe(e.id),ce(e.content)},children:s(Xe,{size:14})}),d(`button`,{className:`mem-about-btn mem-about-btn-remove`,"aria-label":u(`mem.about.forgetAria`,{name:o}),title:u(`mem.about.forget`),disabled:he===e.id,onClick:()=>ye(e),children:[s(Ne,{size:14}),` `,u(`mem.about.forget`)]})]})]})},e.id)})})]},e.title))]})}function b(e){return e instanceof Error?e.message:String(e)}function yt(e,t){if(!e)return`—`;try{let n=new Date(e);if(isNaN(n.getTime()))return`—`;let r={month:`short`,day:`numeric`};return n.getFullYear()!==new Date().getFullYear()&&(r.year=`numeric`),n.toLocaleDateString(t,r)}catch{return`—`}}function x(e,t){if(!e)return``;try{let n=new Date(e);return isNaN(n.getTime())?``:n.toLocaleString(t,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return``}}function S(e,t){if(!e)return`—`;try{let n=new Date(e);if(isNaN(n.getTime()))return`—`;let r=Date.now(),i=n.getTime()-r,a=Math.abs(i),o=Math.floor(a/1e3),s=Math.floor(a/6e4),c=Math.floor(a/36e5),l=Math.floor(a/864e5);return i<0?o<5?t(`time.justNow`):o<60?t(`mem.rel.secondsAgo`,{n:o}):c===0?t(`time.minutesAgo`,{n:s}):l===0?t(`time.hoursAgo`,{n:c}):l===1?t(`time.yesterday`):l<30?t(`time.daysAgo`,{n:l}):x(e,u(t)):o<5?t(`mem.rel.now`):o<60?t(`mem.rel.inSeconds`,{n:o}):c===0?t(`mem.rel.inMinutes`,{n:s}):l===0?t(`mem.rel.inHours`,{n:c}):l===1?t(`mem.rel.tomorrow`):l<30?t(`mem.rel.inDays`,{n:l}):x(e,u(t))}catch{return`—`}}function bt(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function xt(e){try{return new Date(e).getTime()<Date.now()}catch{return!1}}function St(e){return e>=.7?`high`:e>=.4?`medium`:`low`}function Ct(e){return e>=.9?`high`:e>=.7?`medium`:`low`}function wt(e,t,n){let r=yt(e,n),i=yt(t,n);return r===`—`&&i===`—`?``:r===i?r:`${r} \u2013 ${i}`}function Tt(e){if(e.length===0)return 0;let t=new Date().toISOString().slice(0,10),n=e.find(e=>e.date===t);return n?n.knowledge_added:0}var Et=[`fact`,`preference`,`error`,`skill`,`note`,`reminder`],C={fact:`mem.cat.fact`,preference:`mem.cat.preference`,error:`mem.cat.error`,skill:`mem.cat.skill`,note:`mem.cat.note`,reminder:`mem.cat.reminder`},Dt={pending_approval:`mem.status.pending_approval`,queued:`mem.status.queued`,in_progress:`mem.status.in_progress`,completed:`mem.status.completed`,failed:`mem.status.failed`,rejected:`mem.status.rejected`,cancelled:`mem.status.cancelled`,blocked:`mem.status.blocked`},Ot={low:`mem.priority.low`,medium:`mem.priority.medium`,high:`mem.priority.high`},kt={agent_inferred:`mem.goals.source.agent_inferred`,agent_scheduled:`mem.goals.source.agent_scheduled`},At={user:`mem.role.user`,assistant:`mem.role.assistant`},jt={work:`mem.domain.work`,technical:`mem.domain.technical`,personal:`mem.domain.personal`,general:`mem.domain.general`};function w({value:e,keys:t}){let n=i(),r=t[e];return r?s(a.Fragment,{children:n(r)}):s(`bdi`,{children:e})}function T(e){return e instanceof Error?e.message:String(e)}var Mt={work:`blue`,technical:`purple`,personal:`green`,general:`gray`};function Nt(){let e=i(),{setShowMemoryDashboard:n,sessions:c,setCurrentSession:l}=o(),Be=(0,y.useMemo)(()=>new Map(c.map(e=>[e.id,e.title])),[c]),Ve=e=>Be.get(e)||`${e.slice(0,8)}...`,[g,rt]=(0,y.useState)(null),[_,ot]=(0,y.useState)([]),[v,lt]=(0,y.useState)(null),[dt,pt]=(0,y.useState)([]),[mt,ht]=(0,y.useState)([]),[gt,_t]=(0,y.useState)([]),[b,yt]=(0,y.useState)(null),[Nt,Pt]=(0,y.useState)([]),[Ft,It]=(0,y.useState)(!0),[Lt,Rt]=(0,y.useState)(!1),[zt,Bt]=(0,y.useState)(null),[Vt,E]=(0,y.useState)(!1),[Ht,Ut]=(0,y.useState)(null),[Wt,Gt]=(0,y.useState)([]),Kt=(0,y.useRef)(0),[D,qt]=(0,y.useState)([]),[Jt,Yt]=(0,y.useState)(``),[Xt,Zt]=(0,y.useState)(``),[Qt,$t]=(0,y.useState)(``),[O,en]=(0,y.useState)(`updated_at`),[tn,nn]=(0,y.useState)(`desc`),[k,A]=(0,y.useState)(0),[rn,an]=(0,y.useState)(!1),[on,sn]=(0,y.useState)(``),[cn,ln]=(0,y.useState)(null),un=(0,y.useRef)(null),[j,dn]=(0,y.useState)(null),[fn,pn]=(0,y.useState)(!1),[M,mn]=(0,y.useState)(null),[N,P]=(0,y.useState)({content:``,category:`fact`,domain:``,context:`global`,entity:``,sensitive:!1,due_at:``}),[hn,gn]=(0,y.useState)(new Set),[F,_n]=(0,y.useState)(!1),[vn,yn]=(0,y.useState)(!1),[bn,xn]=(0,y.useState)(!1),[I,L]=(0,y.useState)(!1),[Sn,Cn]=(0,y.useState)(!1),[R,wn]=(0,y.useState)(null),[Tn,En]=(0,y.useState)(!1),[Dn,z]=(0,y.useState)(null),[B,On]=(0,y.useState)(`about`),[kn,An]=(0,y.useState)(0),[jn,Mn]=(0,y.useState)([]),[Nn,Pn]=(0,y.useState)(null),[Fn,In]=(0,y.useState)(!1),[Ln,Rn]=(0,y.useState)(null),[zn,Bn]=(0,y.useState)(null),[Vn,Hn]=(0,y.useState)(!1),[Un,Wn]=(0,y.useState)({title:``,description:``,priority:`medium`}),[V,H]=(0,y.useState)(`idle`),[Gn,U]=(0,y.useState)([]),[W,G]=(0,y.useState)([]),[Kn,qn]=(0,y.useState)(null),Jn=(0,y.useRef)(null),Yn=(0,y.useRef)(null),[K,q]=(0,y.useState)(`idle`),[Xn,J]=(0,y.useState)([]),[Y,Zn]=(0,y.useState)([]),[Qn,$n]=(0,y.useState)(null),[er,tr]=(0,y.useState)(!1),nr=(0,y.useRef)(null),rr=(0,y.useRef)(null),[ir,ar]=(0,y.useState)(30),[or,sr]=(0,y.useState)(!1),[cr,lr]=(0,y.useState)(!1),[ur,dr]=(0,y.useState)(!1),[fr,pr]=(0,y.useState)(!1),[mr,hr]=(0,y.useState)(!1),[gr,_r]=(0,y.useState)(!1),vr=(0,y.useRef)(null),yr=(0,y.useRef)(null),br=(0,y.useRef)(null),X=(0,y.useCallback)((e,t=`info`)=>{let n=++Kt.current;Gt(r=>[...r,{id:n,text:e,type:t}]),setTimeout(()=>{Gt(e=>e.filter(e=>e.id!==n))},4e3)},[]);(0,y.useEffect)(()=>{if(!Vt)return;let e=e=>{yr.current&&!yr.current.contains(e.target)&&E(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[Vt]),je(!0,()=>{Dn?z(null):Sn?Cn(!1):Tn?En(!1):j?dn(null):Vt?E(!1):fn||M?(pn(!1),mn(null)):Ht?Ut(null):n(!1)}),Oe(br,!!Dn),(0,y.useEffect)(()=>{if(!Dn)return;let e=br.current;if(!e)return;let t=document.activeElement;return e.focus(),()=>{t?.focus()}},[Dn]);let xr=(0,y.useCallback)(async()=>{try{let e=await he();rt(e)}catch(e){t.system.warn(`Failed to load memory stats`,e)}},[]),Sr=(0,y.useCallback)(async()=>{try{let e=await ze(ir);ot(e)}catch(e){t.system.warn(`Failed to load memory activity`,e)}},[ir]),Z=(0,y.useCallback)(async()=>{try{let e=await _e({category:D.length>0?D:void 0,context:Jt||void 0,entity:Xt||void 0,search:Qt||void 0,sort_by:O,order:tn,offset:k,limit:15,include_sensitive:!0,include_superseded:rn});lt(e)}catch(e){t.system.warn(`Failed to load knowledge`,e)}},[D,Jt,Xt,Qt,O,tn,k,rn]),Cr=(0,y.useCallback)(async()=>{try{let e=await m();pt(e)}catch(e){t.system.warn(`Failed to load tool summary`,e)}},[]),wr=(0,y.useCallback)(async()=>{try{let e=await ne(20);ht(e)}catch(e){t.system.warn(`Failed to load conversations`,e)}},[]),Tr=(0,y.useCallback)(async()=>{try{let e=await h(7);_t(e)}catch(e){t.system.warn(`Failed to load upcoming items`,e)}},[]),Er=(0,y.useCallback)(async()=>{try{let e=await Se();yt(e)}catch(e){t.system.warn(`Failed to load embedding coverage`,e)}},[]),Dr=(0,y.useCallback)(async()=>{try{let e=await oe();Pt(e||[])}catch(e){t.system.warn(`Failed to load entities`,e)}},[]),Or=(0,y.useCallback)(async()=>{try{let e=await Re();yn(e.mcp_memory_enabled),_n(e.memory_enabled),xn(e.system_discovery_consent)}catch(e){t.system.warn(`Failed to load memory settings`,e)}},[]),kr=(0,y.useCallback)(async()=>{In(!0);try{let[e,t]=await Promise.all([se(),ae()]);Mn(e.goals),Pn(t)}catch(e){t.system.warn(`Failed to load goals`,e)}finally{In(!1)}},[]),Ar=(0,y.useCallback)(async(n,i)=>{try{await n()}catch(n){t.system.error(`Goal action failed (${i})`,n),X(e(`mem.goals.failed`,{what:r(i),error:T(n)}),`error`);return}kr()},[kr,X,e]);(0,y.useEffect)(()=>{if(!zn)return;let e=setTimeout(()=>Bn(null),3e3);return()=>clearTimeout(e)},[zn]);let Q=(0,y.useCallback)(async()=>{It(!0),Rt(!1);try{await Promise.all([xr(),Sr(),Z(),Cr(),wr(),Tr(),Er(),Dr(),Or(),kr()]),An(e=>e+1)}catch(e){Rt(!0),t.system.error(`Memory dashboard load failed`,e)}finally{It(!1)}},[xr,Sr,Z,Cr,wr,Tr,Er,Dr,Or,kr]);(0,y.useEffect)(()=>{Q()},[Q]),(0,y.useEffect)(()=>{Z()},[Z]);let jr=(0,y.useRef)(!0);(0,y.useEffect)(()=>{jr.current?jr.current=!1:Sr()},[Sr]);let Mr=(0,y.useCallback)(e=>{$t(e),_r(!0),vr.current&&clearTimeout(vr.current),vr.current=setTimeout(()=>{A(0),_r(!1)},300)},[]),Nr=(0,y.useCallback)(()=>{Z(),xr(),Er(),Tr(),Dr()},[Z,xr,Er,Tr,Dr]),$=(0,y.useCallback)(()=>{Nr(),An(e=>e+1)},[Nr]),Pr=(0,y.useCallback)(async()=>{if(N.content.trim())try{let n=await Me({content:N.content,category:N.category,domain:N.domain||void 0,context:N.context,entity:N.entity||void 0,sensitive:N.sensitive,due_at:N.due_at||void 0});pn(!1),P({content:``,category:`fact`,domain:``,context:`global`,entity:``,sensitive:!1,due_at:``}),$(),t.ui.info(`Created new knowledge entry`),n?.embedded===!1?X(n.embed_error?e(`mem.toast.server`,{message:n.embed_error}):e(`mem.toast.notEmbedded`),`error`):X(e(`mem.toast.created`),`success`)}catch(n){t.system.error(`Failed to create knowledge`,n),X(e(`mem.toast.createFailed`,{error:T(n)}),`error`)}},[N,$,X,e]),Fr=(0,y.useCallback)(async()=>{if(M&&N.content.trim())try{let n=await ie(M,{content:N.content,category:N.category,domain:N.domain||void 0,context:N.context,entity:N.entity||void 0,sensitive:N.sensitive,due_at:N.due_at||void 0});mn(null),P({content:``,category:`fact`,domain:``,context:`global`,entity:``,sensitive:!1,due_at:``}),$(),t.ui.info(`Updated knowledge ${M}`),n?.embedded===!1?X(n.embed_error?e(`mem.toast.server`,{message:n.embed_error}):e(`mem.toast.notEmbedded`),`error`):X(e(`mem.toast.updated`),`success`)}catch(n){t.system.error(`Failed to update knowledge`,n),X(e(`mem.toast.updateFailed`,{error:T(n)}),`error`)}},[M,N,$,X,e]),Ir=(0,y.useCallback)(async n=>{if(R!==n)wn(n);else{wn(null);try{await be(n),$(),t.ui.info(`Deleted knowledge ${n}`),X(e(`mem.toast.deleted`),`info`)}catch(n){t.system.error(`Failed to delete knowledge`,n),X(e(`mem.toast.deleteFailed`,{error:T(n)}),`error`)}}},[R,$,X,e]);(0,y.useEffect)(()=>{if(!R)return;let e=setTimeout(()=>wn(null),3e3);return()=>clearTimeout(e)},[R]);let Lr=(0,y.useCallback)(async n=>{try{await ie(n.id,{sensitive:!n.sensitive}),Z(),t.ui.info(`Toggled sensitive for ${n.id}: ${!n.sensitive}`),X(e(n.sensitive?`mem.toast.unmarkedSensitive`:`mem.toast.markedSensitive`),`info`)}catch(n){t.system.error(`Failed to toggle sensitive`,n),X(e(`mem.toast.sensitiveFailed`,{error:T(n)}),`error`)}},[Z,X,e]),Rr=(0,y.useCallback)(e=>{mn(e.id),pn(!1),P({content:e.content,category:e.category,domain:e.domain||``,context:e.context,entity:e.entity||``,sensitive:e.sensitive,due_at:e.due_at||``})},[]),zr=(0,y.useCallback)(n=>{navigator.clipboard.writeText(n).then(()=>X(e(`mem.toast.idCopied`),`info`),r=>{t.ui.warn(`Couldn't copy knowledge ID ${n}`,r),X(e(`mem.toast.copyFailed`,{error:T(r)}),`error`)})},[X,e]),Br=(0,y.useCallback)(e=>{sn(e),un.current&&clearTimeout(un.current),e.trim()?un.current=setTimeout(async()=>{try{let t=await Ee(e.trim(),20);ln(t)}catch(e){t.system.warn(`Conversation search failed`,e)}},300):ln(null)},[]),Vr=(0,y.useCallback)(async e=>{try{let t=await Ze(e);dn({sessionId:e,turns:t})}catch(e){t.system.error(`Failed to load conversation detail`,e)}},[]),Hr=(0,y.useCallback)(e=>{qt(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),A(0)},[]),Ur=(0,y.useCallback)(e=>{O===e?nn(e=>e===`desc`?`asc`:`desc`):(en(e),nn(`desc`)),A(0)},[O]),Wr=(0,y.useCallback)(async()=>{sr(!0),E(!1);try{let t=await Ye();await Q(),X(e(`mem.toast.consolidated`,{sessions:t.consolidated??0,items:t.extracted_items??0}),`success`)}catch(n){t.system.error(`Failed to consolidate sessions`,n),X(e(`mem.toast.consolidateFailed`,{error:T(n)}),`error`)}finally{sr(!1)}},[Q,X,e]),Gr=(0,y.useCallback)(async()=>{lr(!0),E(!1);try{let t=await ye();await Er(),X(t.total_without?e(`mem.toast.backfilledMissing`,{n:t.backfilled??0,missing:t.total_without}):e(`mem.toast.backfilled`,{n:t.backfilled??0}),`success`)}catch(n){t.system.error(`Failed to rebuild embeddings`,n),X(e(`mem.toast.rebuildFailed`,{error:T(n)}),`error`)}finally{lr(!1)}},[Er,X,e]),Kr=(0,y.useCallback)(async()=>{dr(!0),E(!1);try{let t=await re();await Q(),X(e(`mem.toast.reconciled`,{pairs:t.pairs_checked??0,reinforced:t.reinforced??0,contradicted:t.contradicted??0}),`success`)}catch(n){t.system.error(`Failed to reconcile memory`,n),X(e(`mem.toast.reconcileFailed`,{error:T(n)}),`error`)}finally{dr(!1)}},[Q,X,e]),qr=(0,y.useCallback)(async()=>{pr(!0),E(!1);try{await et(),await Q(),X(e(`mem.toast.ftsRebuilt`),`success`)}catch(n){t.system.error(`Failed to rebuild FTS index`,n),X(e(`mem.toast.ftsFailed`,{error:T(n)}),`error`)}finally{pr(!1)}},[Q,X,e]),Jr=(0,y.useCallback)(async()=>{hr(!0),E(!1);try{let t=await Te();await Q(),t.skipped?X(e(`mem.toast.systemDisabled`),`error`):X(e(`mem.toast.systemRefreshed`,{n:t.stored}),`success`)}catch(n){t.system.error(`Failed to refresh system context`,n),X(e(`mem.toast.systemFailed`,{error:T(n)}),`error`)}finally{hr(!1)}},[Q,X,e]),Yr=or||cr||ur||fr||mr,Xr=(0,y.useCallback)(()=>{H(`running`),U([]),G([]),qn(null);let n=de();Yn.current=n,n.onmessage=r=>{try{let t=JSON.parse(r.data);if(t.type===`log`)U(e=>[...e,{text:t.message,kind:`log`,server:!0}]);else if(t.type===`finding`){let n=t.item;U(t=>[...t,{text:e.bare(`mem.log.found`,{content:n.content}),kind:`finding`}]),G(e=>[...e,{...n,_checked:!0}])}else t.type===`error`?U(n=>[...n,{text:e.bare(`mem.log.error`,{message:t.message}),kind:`error`}]):t.type===`done`&&(n.close(),Yn.current=null,U(n=>[...n,{text:e(`mem.log.discoveryDone`,{n:t.total??0}),kind:`log`}]),H(`review`))}catch(n){t.system.warn(`Unreadable discovery event`,n),U(t=>[...t,{text:e(`mem.log.parseFailed`),kind:`error`}])}},n.onerror=()=>{n.close(),Yn.current=null,U(t=>[...t,{text:e(`mem.log.discoveryConnection`),kind:`error`}]),G(e=>(H(e.length>0?`review`:`idle`),e))}},[e]),Zr=(0,y.useCallback)(async()=>{let n=W.filter(e=>e._checked);if(n.length!==0){H(`saving`);try{let t=n.map(({_checked:e,...t})=>t),r=await Fe(t);qn(r.stored),H(`done`),$(),X(e(`mem.disc.saved`,{n:r.stored}),`success`)}catch(n){t.system.error(`Failed to commit discovery items`,n),X(e(`mem.disc.saveFailed`,{error:T(n)}),`error`),H(`review`)}}},[W,$,X,e]),Qr=(0,y.useCallback)(()=>{q(`running`),J([]),Zn([]),$n(null);let n=pe(er);rr.current=n,n.onmessage=r=>{try{let t=JSON.parse(r.data);if(t.type===`log`)J(e=>[...e,{text:t.message,kind:`log`,server:!0}]);else if(t.type===`insight`){let n=t.item;J(t=>[...t,{text:e.bare(`mem.log.insight`,{content:n.content}),kind:`finding`}]),Zn(e=>[...e,{...n,_checked:!0}])}else t.type===`error`?J(n=>[...n,{text:e.bare(`mem.log.error`,{message:t.message}),kind:`error`}]):t.type===`done`&&(n.close(),rr.current=null,J(n=>[...n,{text:e(`mem.log.inferenceDone`,{n:t.total??0}),kind:`log`}]),q(`review`))}catch(n){t.system.warn(`Unreadable inference event`,n),J(t=>[...t,{text:e(`mem.log.parseFailed`),kind:`error`}])}},n.onerror=()=>{n.close(),rr.current=null,J(t=>[...t,{text:e(`mem.log.inferenceConnection`),kind:`error`}]),Zn(e=>(q(e.length>0?`review`:`idle`),e))}},[er,e]),$r=(0,y.useCallback)(async()=>{let n=Y.filter(e=>e._checked);if(n.length!==0){q(`saving`);try{let t=n.map(({_checked:e,...t})=>t),r=await ke(t);$n(r.stored),q(`done`),$(),X(e(`mem.inf.saved`,{n:r.stored}),`success`)}catch(n){t.system.error(`Failed to commit inference insights`,n),X(e(`mem.inf.saveFailed`,{error:T(n)}),`error`),q(`review`)}}},[Y,$,X,e]);(0,y.useEffect)(()=>{Jn.current&&(Jn.current.scrollTop=Jn.current.scrollHeight)},[Gn]),(0,y.useEffect)(()=>{nr.current&&(nr.current.scrollTop=nr.current.scrollHeight)},[Xn]),(0,y.useEffect)(()=>()=>{Yn.current&&=(Yn.current.close(),null),rr.current&&=(rr.current.close(),null)},[]);let ei=e=>O===e?s(`span`,{className:`mem-sort-arrow`,children:tn===`desc`?`↓`:`↑`}):null,ti=Math.max(1,..._.map(e=>e.conversations+e.tool_calls+e.knowledge_added+e.errors)),ni=g?.knowledge?.by_context?Object.keys(g.knowledge.by_context):[];return d(`div`,{className:`memory-dashboard-page`,children:[d(`div`,{className:`memory-dashboard-header`,children:[d(`div`,{className:`memory-dashboard-header-left`,children:[s(`button`,{className:`btn-icon settings-back-btn`,onClick:()=>n(!1),"aria-label":e(`mem.back`),children:s(nt,{size:18})}),d(`h1`,{children:[e(`mem.title`),` `,s(`span`,{className:`mem-beta`,style:{fontSize:11,fontWeight:600,color:`var(--accent-yellow)`,background:`var(--accent-yellow-dim)`,padding:`2px 8px`,borderRadius:4,marginInlineStart:8,verticalAlign:`middle`,whiteSpace:`nowrap`},children:e(`mem.beta`)})]})]}),d(`div`,{className:`memory-dashboard-header-actions`,children:[B===`advanced`&&d(a.Fragment,{children:[b&&b.total_items>0&&d(`div`,{className:`mem-embedding-coverage`,title:e(`mem.coverage.title`,{n:b.with_embedding,total:b.total_items}),children:[s(`div`,{className:`mem-embedding-bar`,children:s(`div`,{className:`mem-embedding-fill`,style:{width:`${Math.round(b.coverage_pct)}%`}})}),s(`span`,{className:`mem-embedding-label`,children:e(`mem.coverage.label`,{pct:`${Math.round(b.coverage_pct)}%`})})]}),d(`div`,{className:`mem-maintenance-wrap`,ref:yr,children:[d(`button`,{className:`btn-icon ${Yr?`mem-spinning`:``}`,onClick:()=>E(e=>!e),title:e(`mem.maint.label`),"aria-label":e(`mem.maint.label`),"aria-expanded":Vt,children:[Yr?s(`div`,{className:`mem-spinner-sm`}):s(ge,{size:16}),s(De,{size:10,style:{marginInlineStart:2}})]}),Vt&&d(`div`,{className:`mem-maintenance-menu`,role:`menu`,children:[d(`button`,{className:`mem-maintenance-item`,onClick:Wr,disabled:or,role:`menuitem`,children:[s(it,{size:14}),e(or?`mem.maint.consolidating`:`mem.maint.consolidate`)]}),d(`button`,{className:`mem-maintenance-item`,onClick:Gr,disabled:cr,role:`menuitem`,children:[s(te,{size:14}),e(cr?`mem.maint.rebuilding`:`mem.maint.rebuildEmbeddings`)]}),d(`button`,{className:`mem-maintenance-item`,onClick:Kr,disabled:ur,role:`menuitem`,children:[s(tt,{size:14}),e(ur?`mem.maint.reconciling`:`mem.maint.reconcile`)]}),s(`div`,{className:`mem-maintenance-divider`}),d(`button`,{className:`mem-maintenance-item`,onClick:Jr,disabled:mr,role:`menuitem`,children:[s(Ie,{size:14}),e(mr?`mem.maint.refreshing`:`mem.maint.refreshSystem`)]}),s(`div`,{className:`mem-maintenance-divider`}),d(`button`,{className:`mem-maintenance-item`,onClick:qr,disabled:fr,role:`menuitem`,children:[s(Ue,{size:14}),e(fr?`mem.maint.rebuilding`:`mem.maint.rebuildFts`)]})]})]})]}),s(`button`,{className:`btn-icon`,onClick:Q,title:e(`mem.refresh`),"aria-label":e(`mem.refreshAria`),children:s(Ie,{size:16})})]})]}),d(`div`,{className:`mem-tab-bar`,role:`tablist`,children:[d(`button`,{className:`mem-tab-btn${B===`about`?` mem-tab-active`:``}`,onClick:()=>On(`about`),role:`tab`,"aria-selected":B===`about`,children:[s(ft,{size:14}),` `,e(`mem.tab.about`)]}),d(`button`,{className:`mem-tab-btn${B===`goals`?` mem-tab-active`:``}`,onClick:()=>{On(`goals`),kr()},role:`tab`,"aria-selected":B===`goals`,children:[s(ct,{size:14}),` `,e(`mem.tab.goals`),Nn&&(Nn.goals.pending_approval??0)>0&&s(`span`,{className:`mem-tab-badge`,children:Nn.goals.pending_approval})]}),d(`button`,{className:`mem-tab-btn${B===`profile`?` mem-tab-active`:``}`,onClick:()=>On(`profile`),role:`tab`,"aria-selected":B===`profile`,children:[s(Pe,{size:14}),` `,e(`mem.tab.profile`)]}),d(`button`,{className:`mem-tab-btn${B===`advanced`?` mem-tab-active`:``}`,onClick:()=>On(`advanced`),role:`tab`,"aria-selected":B===`advanced`,children:[s(p,{size:14}),` `,e(`mem.tab.advanced`)]})]}),d(`div`,{className:`memory-dashboard-body`,children:[B===`about`&&s(vt,{memoryEnabled:F,reloadKey:kn,onChanged:Nr,onOpenAdvanced:()=>On(`advanced`),showToast:X}),B===`advanced`&&s(a.Fragment,{children:Ft&&!g?d(`div`,{className:`mem-loading`,children:[s(`div`,{className:`mem-spinner`}),e(`mem.loadingData`)]}):Lt?d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(Je,{size:32})}),s(`p`,{children:e(`mem.loadFailed`)}),d(`button`,{className:`btn-secondary`,onClick:Q,style:{marginTop:12},children:[s(Ie,{size:14}),` `,e(`mem.retry`)]})]}):d(a.Fragment,{children:[!F&&d(`div`,{className:`mem-empty-state`,style:{margin:`40px 0`},children:[s(`div`,{className:`mem-empty-icon`,style:{opacity:.5},children:s(st,{size:32})}),s(`p`,{style:{color:`var(--text-secondary)`,fontSize:14},children:e(`mem.offAdvanced`)})]}),F&&d(a.Fragment,{children:[g?.embedding_error&&d(`div`,{className:`mem-advanced-error`,role:`alert`,children:[s(Je,{size:14}),` `,s(`bdi`,{children:g.embedding_error})]}),d(`div`,{className:`mem-stat-cards`,children:[d(`div`,{className:`mem-stat-card`,"data-accent":`purple`,children:[s(`div`,{className:`mem-stat-value`,children:g?.knowledge?.total??0}),s(`div`,{className:`mem-stat-label`,children:e(`mem.stat.stored`)}),s(`div`,{className:`mem-stat-sub`,children:(()=>{let t=Tt(_);return t>0?e(`mem.stat.addedToday`,{n:t}):g?.knowledge?.by_category?e.compose(e=>Object.entries(g.knowledge.by_category).slice(0,3).map(([t,n])=>e(`mem.stat.categoryCount`,{category:C[t]?r(C[t]):t,n})).join(e(`mem.listSeparator`))):e(`mem.stat.noEntries`)})()})]}),d(`div`,{className:`mem-stat-card`,"data-accent":`gold`,children:[s(`div`,{className:`mem-stat-value`,children:g?.knowledge?.total_retrievals??0}),s(`div`,{className:`mem-stat-label`,children:e(`mem.stat.retrieved`)}),s(`div`,{className:`mem-stat-sub`,children:g?.knowledge?.total&&g?.knowledge?.total_retrievals?e(`mem.stat.avgRecall`,{n:(g.knowledge.total_retrievals/g.knowledge.total).toFixed(1)}):e(`mem.stat.noRecalls`)})]}),d(`div`,{className:`mem-stat-card`,"data-accent":`blue`,children:[s(`div`,{className:`mem-stat-value`,children:g?.conversations?.total_sessions??0}),s(`div`,{className:`mem-stat-label`,children:e(`mem.stat.sessions`)}),s(`div`,{className:`mem-stat-sub`,children:wt(g?.conversations?.first_session??null,g?.conversations?.last_session??null,u(e))||e(`mem.stat.totalTurns`,{n:g?.conversations?.total_turns??0})})]}),d(`div`,{className:`mem-stat-card`,"data-accent":`green`,children:[s(`div`,{className:`mem-stat-value`,children:g?.tools?.total_calls??0}),s(`div`,{className:`mem-stat-label`,children:e(`mem.stat.toolCalls`)}),s(`div`,{className:`mem-stat-sub`,title:e(`mem.stat.toolsNotLogged`),children:e(`mem.stat.toolsExclMemory`,{n:g?.tools?.unique_tools??0})})]}),d(`div`,{className:`mem-stat-card`,"data-accent":`red`,children:[s(`div`,{className:`mem-stat-value`,children:g?.tools?.overall_success_rate!=null&&(g.tools.total_calls??0)>0?`${Math.round(g.tools.overall_success_rate*100)}%`:`—`}),s(`div`,{className:`mem-stat-label`,children:e(`mem.stat.successRate`)}),s(`div`,{className:`mem-stat-sub`,children:(g?.tools?.total_calls??0)>0?e(`mem.stat.errors`,{n:g?.tools?.total_errors??0}):e(`mem.stat.noToolCalls`)})]})]}),d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title mem-section-title-row`,children:[d(`span`,{className:`mem-section-title-left`,children:[s(ut,{size:14}),` `,e(`mem.activity.title`)]}),s(`div`,{className:`mem-range-tabs`,role:`group`,"aria-label":e(`mem.activity.range`),children:[1,7,30].map(t=>s(`button`,{className:`mem-range-tab${ir===t?` active`:``}`,onClick:()=>ar(t),children:e(t===1?`mem.activity.day1`:t===7?`mem.activity.days7`:`mem.activity.days30`)},t))})]}),_.length>0?d(a.Fragment,{children:[s(`div`,{className:`mem-activity-chart`,children:_.map((t,n)=>{let r=t.conversations+t.tool_calls+t.knowledge_added+t.errors,i=n===0||n===_.length-1||n%7==0,o=new Date(t.date+`T00:00:00`).toLocaleDateString(u(e),{month:`short`,day:`numeric`});return d(`div`,{className:`mem-activity-bar-group`,onMouseEnter:()=>Bt(n),onMouseLeave:()=>Bt(null),children:[t.errors>0&&s(`div`,{className:`mem-activity-bar errors`,style:{height:`${t.errors/ti*100}%`}}),t.knowledge_added>0&&s(`div`,{className:`mem-activity-bar knowledge`,style:{height:`${t.knowledge_added/ti*100}%`}}),t.tool_calls>0&&s(`div`,{className:`mem-activity-bar tool_calls`,style:{height:`${t.tool_calls/ti*100}%`}}),t.conversations>0&&s(`div`,{className:`mem-activity-bar conversations`,style:{height:`${t.conversations/ti*100}%`}}),i&&s(`span`,{className:`mem-activity-date-label`,children:o}),zt===n&&r>0&&d(`div`,{className:`mem-activity-tooltip`,children:[s(`strong`,{children:o}),s(`br`,{}),t.conversations>0&&d(a.Fragment,{children:[e(`mem.activity.conversations`,{n:t.conversations}),s(`br`,{})]}),t.tool_calls>0&&d(a.Fragment,{children:[e(`mem.activity.toolCalls`,{n:t.tool_calls}),s(`br`,{})]}),t.knowledge_added>0&&d(a.Fragment,{children:[e(`mem.activity.learned`,{n:t.knowledge_added}),s(`br`,{})]}),t.errors>0&&s(a.Fragment,{children:e(`mem.stat.errors`,{n:t.errors})})]})]},t.date)})}),d(`div`,{className:`mem-activity-legend`,children:[d(`span`,{className:`mem-activity-legend-item`,children:[s(`span`,{className:`mem-activity-legend-dot conversations`}),` `,e(`mem.legend.conversations`)]}),d(`span`,{className:`mem-activity-legend-item`,children:[s(`span`,{className:`mem-activity-legend-dot tool_calls`}),` `,e(`mem.stat.toolCalls`)]}),d(`span`,{className:`mem-activity-legend-item`,children:[s(`span`,{className:`mem-activity-legend-dot knowledge`}),` `,e(`mem.legend.knowledge`)]}),d(`span`,{className:`mem-activity-legend-item`,children:[s(`span`,{className:`mem-activity-legend-dot errors`}),` `,e(`mem.legend.errors`)]})]})]}):d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(ut,{size:28})}),s(`p`,{children:e(`mem.activity.empty`)})]})]}),d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title mem-section-title-row`,children:[d(`span`,{className:`mem-section-title-left`,children:[s(p,{size:14}),` `,e(`mem.knowledge.title`),v&&v.total>0&&s(`span`,{className:`mem-section-count`,children:v.total})]}),!fn&&!M&&d(`button`,{className:`mem-section-add-btn`,onClick:()=>pn(!0),title:e(`mem.knowledge.addTitle`),children:[s(Ae,{size:13}),` `,e(`mem.knowledge.add`)]})]}),d(`div`,{className:`mem-filters`,children:[d(`div`,{className:`mem-category-pills`,role:`group`,"aria-label":e(`mem.knowledge.filterCategory`),children:[Et.map(t=>s(`button`,{className:`mem-category-pill ${t}${D.includes(t)?` active`:``}`,onClick:()=>Hr(t),"aria-pressed":D.includes(t),children:e(C[t])},t)),D.length>0&&d(`button`,{className:`mem-category-pill clear`,onClick:()=>{qt([]),A(0)},"aria-label":e(`mem.knowledge.clearAria`),children:[`✕ `,e(`mem.knowledge.clear`)]})]}),d(`select`,{className:`mem-filter-select`,value:Jt,onChange:e=>{Yt(e.target.value),A(0)},"aria-label":e(`mem.knowledge.filterContext`),children:[s(`option`,{value:``,children:e.bare(`mem.knowledge.allContexts`)}),ni.map(e=>s(`option`,{value:e,children:e},e))]}),d(`select`,{className:`mem-filter-select`,value:Xt,onChange:e=>{Zt(e.target.value),A(0)},"aria-label":e(`mem.knowledge.filterEntity`),children:[s(`option`,{value:``,children:e.bare(`mem.knowledge.allEntities`)}),Nt.map(e=>d(`option`,{value:e.entity,children:[e.entity,` (`,e.count,`)`]},e.entity))]}),d(`div`,{className:`mem-filter-search-wrap`,children:[gr?s(`div`,{className:`mem-spinner-sm search-icon`,style:{width:12,height:12,borderWidth:1.5}}):s(Ue,{size:13,className:`search-icon`}),s(`input`,{className:`mem-filter-search`,type:`text`,placeholder:e(`mem.knowledge.searchPlaceholder`),value:Qt,onChange:e=>Mr(e.target.value),"aria-label":e(`mem.knowledge.search`)})]}),d(`label`,{className:`mem-filter-toggle`,title:e(`mem.knowledge.supersededTitle`),children:[s(`input`,{type:`checkbox`,checked:rn,onChange:e=>an(e.target.checked)}),s(`span`,{children:e(`mem.knowledge.superseded`)})]})]}),(fn||M)&&d(`div`,{className:`mem-inline-form`,children:[d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.col.content`)}),s(`textarea`,{value:N.content,onChange:e=>P(t=>({...t,content:e.target.value})),placeholder:e(`mem.form.contentPlaceholder`)})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.col.category`)}),s(`select`,{value:N.category,onChange:e=>P(t=>({...t,category:e.target.value})),children:Et.map(t=>s(`option`,{value:t,children:e.bare(C[t])},t))})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.col.context`)}),s(`input`,{type:`text`,value:N.context,onChange:e=>P(t=>({...t,context:e.target.value})),placeholder:`global`})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.detail.domain`)}),s(`input`,{type:`text`,value:N.domain,onChange:e=>P(t=>({...t,domain:e.target.value})),placeholder:e(`mem.form.domainPlaceholder`)})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.col.entity`)}),s(`input`,{type:`text`,value:N.entity,onChange:e=>P(t=>({...t,entity:e.target.value})),placeholder:e(`mem.form.entityPlaceholder`)})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.form.dueAt`)}),s(`input`,{type:`text`,value:N.due_at,onChange:e=>P(t=>({...t,due_at:e.target.value})),placeholder:e(`mem.form.dueAtPlaceholder`)})]}),d(`div`,{className:`mem-inline-form-row`,children:[s(`label`,{children:e(`mem.form.sensitive`)}),d(`label`,{style:{display:`flex`,alignItems:`center`,gap:6,cursor:`pointer`,fontSize:12},children:[s(`input`,{type:`checkbox`,checked:N.sensitive,onChange:e=>P(t=>({...t,sensitive:e.target.checked}))}),e(`mem.form.sensitiveHint`)]})]}),d(`div`,{className:`mem-inline-form-actions`,children:[s(`button`,{className:`btn-secondary`,onClick:()=>{pn(!1),mn(null)},children:e(`mem.cancel`)}),s(`button`,{className:`btn-primary`,onClick:M?Fr:Pr,style:{padding:`8px 20px`,fontSize:13},children:e(M?`mem.form.update`:`mem.form.save`)})]})]}),v&&v.items.length>0?d(a.Fragment,{children:[s(`div`,{style:{overflowX:`auto`},children:d(`table`,{className:`mem-knowledge-table`,children:[s(`thead`,{children:d(`tr`,{children:[d(`th`,{onClick:()=>Ur(`category`),className:O===`category`?`sorted`:``,children:[e(`mem.col.category`),ei(`category`)]}),s(`th`,{children:e(`mem.col.content`)}),d(`th`,{onClick:()=>Ur(`context`),className:O===`context`?`sorted`:``,children:[e(`mem.col.context`),ei(`context`)]}),s(`th`,{children:e(`mem.col.entity`)}),d(`th`,{onClick:()=>Ur(`confidence`),className:O===`confidence`?`sorted`:``,children:[e(`mem.col.confidence`),ei(`confidence`)]}),s(`th`,{children:e(`mem.col.source`)}),d(`th`,{onClick:()=>Ur(`updated_at`),className:O===`updated_at`?`sorted`:``,children:[e(`mem.col.updated`),ei(`updated_at`)]}),d(`th`,{onClick:()=>Ur(`created_at`),className:O===`created_at`?`sorted`:``,children:[e(`mem.col.created`),ei(`created_at`)]}),s(`th`,{children:e(`mem.col.due`)}),s(`th`,{className:`mem-actions-cell`})]})}),s(`tbody`,{children:v.items.map(t=>{let n=Ht===t.id,r=t.has_embedding;return d(y.Fragment,{children:[d(`tr`,{className:`${t.superseded_by?`mem-superseded-row`:``} ${n?`mem-expanded-row`:``}`,onClick:()=>Ut(n?null:t.id),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),Ut(n?null:t.id))},tabIndex:0,role:`row`,"aria-expanded":n,style:{cursor:`pointer`},children:[s(`td`,{children:s(`span`,{className:`mem-cat-badge ${t.category}`,children:t.category===`error`&&t.source===`error_auto`?e(`mem.cat.errorLearned`):s(w,{value:t.category,keys:C})})}),s(`td`,{children:d(`div`,{className:`mem-content-cell`,title:t.content,children:[r!==void 0&&s(`span`,{className:`mem-embed-dot ${r?`embedded`:`missing`}`,title:e(r?`mem.knowledge.embedded`:`mem.knowledge.embedMissing`),children:s(me,{size:6,fill:`currentColor`})}),t.sensitive&&s(`span`,{className:`mem-sensitive-badge`,title:e(`mem.form.sensitive`),children:s(st,{size:11})}),s(`span`,{className:t.sensitive&&!hn.has(t.id)?`mem-sensitive-blur`:t.superseded_by?`mem-superseded-text`:``,onClick:e=>{t.sensitive&&(e.stopPropagation(),gn(e=>{let n=new Set(e);return n.has(t.id)?n.delete(t.id):n.add(t.id),n}))},children:s(`bdi`,{children:t.content})})]})}),s(`td`,{children:s(`bdi`,{className:`mem-date-cell`,children:t.context})}),s(`td`,{children:t.entity?s(`span`,{className:`mem-entity-link`,onClick:e=>{e.stopPropagation(),Zt(t.entity),A(0)},title:e(`mem.knowledge.filterBy`,{entity:t.entity}),children:s(`bdi`,{children:t.entity})}):s(`span`,{className:`mem-date-cell`,children:`—`})}),s(`td`,{children:d(`div`,{className:`mem-confidence`,children:[s(`div`,{className:`mem-confidence-bar`,children:s(`div`,{className:`mem-confidence-fill ${St(t.confidence)}`,style:{width:`${t.confidence*100}%`}})}),t.confidence.toFixed(2)]})}),s(`td`,{children:s(`bdi`,{className:`mem-date-cell`,children:t.source||`—`})}),s(`td`,{children:s(`span`,{className:`mem-date-cell`,title:x(t.updated_at,u(e)),children:S(t.updated_at,e)})}),s(`td`,{children:s(`span`,{className:`mem-date-cell`,title:x(t.created_at,u(e)),children:S(t.created_at,e)})}),s(`td`,{children:t.due_at?s(`span`,{className:`mem-due-badge ${xt(t.due_at)?`overdue`:`upcoming`}`,title:x(t.due_at,u(e)),children:S(t.due_at,e)}):s(`span`,{className:`mem-due-badge none`,children:`—`})}),s(`td`,{className:`mem-actions-cell`,children:d(`div`,{className:`mem-row-actions`,onClick:e=>e.stopPropagation(),children:[s(`button`,{className:`mem-row-action-btn`,onClick:()=>Rr(t),title:e(`mem.row.edit`),children:s(Xe,{size:13})}),s(`button`,{className:`mem-row-action-btn`,onClick:()=>Lr(t),title:e(t.sensitive?`mem.row.unmarkSensitive`:`mem.row.markSensitive`),children:t.sensitive?s(at,{size:13}):s(st,{size:13})}),s(`button`,{className:`mem-row-action-btn`,onClick:()=>zr(t.id),title:e(`mem.row.copyId`),children:s(ce,{size:13})}),s(`button`,{className:`mem-row-action-btn delete${R===t.id?` is-confirm`:``}`,onClick:()=>Ir(t.id),title:e(R===t.id?`mem.row.clickAgain`:`mem.row.delete`),"aria-label":e(R===t.id?`mem.row.confirmDeleteAria`:`mem.row.deleteAria`),children:R===t.id?s(`span`,{className:`mem-row-delete-label`,children:e(`mem.row.deleteConfirm`)}):s(Ne,{size:13})})]})})]}),n&&s(`tr`,{className:`mem-detail-row`,children:s(`td`,{colSpan:10,children:d(`div`,{className:`mem-detail-panel`,children:[d(`div`,{className:`mem-detail-grid`,children:[d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.id`)}),s(`span`,{className:`mem-detail-value`,children:t.id})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.domain`)}),s(`bdi`,{className:`mem-detail-value`,children:t.domain||`—`})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.col.source`)}),s(`bdi`,{className:`mem-detail-value`,children:t.source||`—`})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.useCount`)}),s(`span`,{className:`mem-detail-value`,children:t.use_count??0})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.col.created`)}),s(`span`,{className:`mem-detail-value`,children:x(t.created_at,u(e))})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.col.updated`)}),s(`span`,{className:`mem-detail-value`,children:x(t.updated_at,u(e))})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.lastUsed`)}),s(`span`,{className:`mem-detail-value`,children:x(t.last_used,u(e))})]}),d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.remindedAt`)}),s(`span`,{className:`mem-detail-value`,children:x(t.reminded_at,u(e))})]}),t.superseded_by&&d(`div`,{className:`mem-detail-field`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.supersededBy`)}),s(`span`,{className:`mem-detail-value mem-detail-chain`,children:t.superseded_by})]}),t.metadata&&d(`div`,{className:`mem-detail-field mem-detail-full`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.metadata`)}),s(`span`,{className:`mem-detail-value`,children:s(`bdi`,{dir:`ltr`,children:typeof t.metadata==`object`?JSON.stringify(t.metadata,null,2):t.metadata})})]})]}),d(`div`,{className:`mem-detail-content-full`,children:[s(`span`,{className:`mem-detail-label`,children:e(`mem.detail.fullContent`)}),s(`div`,{className:`mem-detail-content-text`,children:s(`bdi`,{children:t.content})})]})]})})})]},t.id)})})]})}),d(`div`,{className:`mem-pagination`,children:[s(`span`,{children:e(`mem.page.range`,{from:k+1,to:Math.min(k+15,v.total),total:v.total})}),d(`div`,{className:`mem-pagination-btns`,children:[s(`button`,{type:`button`,className:`mem-page-btn`,"aria-label":e(`mem.page.previous`),disabled:k===0,onClick:()=>A(Math.max(0,k-15)),children:s(we,{size:14})}),s(`button`,{type:`button`,className:`mem-page-btn`,"aria-label":e(`mem.page.next`),disabled:k+15>=v.total,onClick:()=>A(k+15),children:s(ue,{size:14})})]})]})]}):d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(p,{size:28})}),s(`p`,{children:e(Qt||D.length>0||Jt||Xt?`mem.knowledge.noMatch`:`mem.knowledge.empty`)})]})]}),d(`div`,{className:`mem-two-col`,children:[d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title`,children:[s(Ke,{size:14}),` `,e(`mem.tools.title`),s(`span`,{className:`mem-section-note`,title:e(`mem.tools.noteTitle`),children:e(`mem.tools.note`)})]}),dt.length>0?s(`div`,{style:{overflowX:`auto`},children:d(`table`,{className:`mem-tool-table`,children:[s(`thead`,{children:d(`tr`,{children:[s(`th`,{children:e(`mem.tools.tool`)}),s(`th`,{children:e(`mem.tools.calls`)}),s(`th`,{children:e(`mem.tools.success`)}),s(`th`,{children:e(`mem.tools.denied`)}),s(`th`,{children:e(`mem.tools.avgTime`)}),s(`th`,{children:e(`mem.detail.lastUsed`)}),s(`th`,{children:e(`mem.tools.lastError`)})]})}),s(`tbody`,{children:dt.map(t=>d(`tr`,{children:[s(`td`,{children:s(`bdi`,{className:`mem-tool-name`,children:t.tool_name})}),s(`td`,{children:t.total_calls}),s(`td`,{children:d(`div`,{className:`mem-confidence`,children:[s(`div`,{className:`mem-confidence-bar`,style:{width:40},children:s(`div`,{className:`mem-confidence-fill ${Ct(t.success_rate)}`,style:{width:`${t.success_rate*100}%`}})}),d(`span`,{className:`mem-success-rate ${Ct(t.success_rate)}`,children:[Math.round(t.success_rate*100),`%`]})]})}),s(`td`,{children:t.denied_count??0}),s(`td`,{children:s(`bdi`,{dir:`ltr`,children:bt(t.avg_duration_ms)})}),s(`td`,{children:s(`span`,{className:`mem-date-cell`,title:x(t.last_used,u(e)),children:S(t.last_used,e)})}),s(`td`,{children:s(`bdi`,{className:`mem-tool-error`,title:t.last_error||``,children:t.last_error||`—`})})]},t.tool_name))})]})}):d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(Ke,{size:28})}),s(`p`,{children:e(`mem.tools.empty`)})]})]}),d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title`,children:[s(fe,{size:14}),` `,e(`mem.upcoming.title`)]}),gt.length>0?s(`div`,{className:`mem-temporal-list`,children:gt.map(t=>{let n=xt(t.due_at);return d(`div`,{className:`mem-temporal-item ${n?`overdue`:`upcoming`}`,children:[s(`span`,{className:`mem-temporal-icon`,children:s(n?Je:fe,{size:16})}),d(`div`,{className:`mem-temporal-content`,children:[s(`div`,{className:`mem-temporal-text`,children:s(`bdi`,{children:t.content})}),d(`div`,{className:`mem-temporal-date`,children:[e(n?`mem.upcoming.overdue`:`mem.upcoming.due`,{when:S(t.due_at,e)}),t.context!==`global`&&d(a.Fragment,{children:[` `,`·`,` `,s(`bdi`,{children:t.context})]})]})]})]},t.id)})}):d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(tt,{size:28})}),s(`p`,{children:e(`mem.upcoming.empty`)})]})]})]}),d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title`,children:[s(ee,{size:14}),` `,e(`mem.conv.title`)]}),d(`div`,{className:`mem-conv-search`,children:[s(Ue,{size:13,className:`search-icon`}),s(`input`,{type:`text`,placeholder:e(`mem.conv.searchPlaceholder`),value:on,onChange:e=>Br(e.target.value),"aria-label":e(`mem.conv.search`)}),on&&s(`button`,{className:`mem-search-clear`,onClick:()=>{sn(``),ln(null)},"aria-label":e(`mem.conv.clearSearch`),children:s(We,{size:12})})]}),cn===null?mt.length>0?s(`div`,{className:`mem-conv-list`,children:mt.map(t=>d(`div`,{className:`mem-conv-item`,onClick:()=>Vr(t.session_id),children:[d(`div`,{className:`mem-conv-info`,children:[d(`div`,{className:`mem-conv-session-id`,children:[s(`bdi`,{children:Ve(t.session_id)}),t.consolidated&&s(`span`,{className:`mem-consolidated-badge`,title:e(`mem.conv.consolidated`),children:s(it,{size:11})})]}),t.first_message&&s(`div`,{className:`mem-conv-preview`,children:s(`bdi`,{children:t.first_message})})]}),d(`div`,{className:`mem-conv-meta`,children:[s(`span`,{children:e.plural(`mem.conv.turns`,t.turn_count)}),s(`span`,{children:S(t.last_activity,e)})]})]},t.session_id))}):d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(ee,{size:28})}),s(`p`,{children:e(`mem.conv.empty`)})]}):cn.length>0?s(`div`,{className:`mem-conv-list`,children:cn.map(t=>d(`div`,{className:`mem-conv-item`,onClick:()=>Vr(t.session_id),children:[d(`div`,{className:`mem-conv-info`,children:[d(`div`,{className:`mem-conv-session-id`,children:[s(`span`,{className:`mem-conv-turn-role ${t.role}`,children:s(w,{value:t.role,keys:At})}),` `,s(`bdi`,{children:Ve(t.session_id)})]}),s(`div`,{className:`mem-conv-preview`,children:s(`bdi`,{children:t.content})})]}),s(`div`,{className:`mem-conv-meta`,children:s(`span`,{children:S(t.timestamp,e)})})]},t.id))}):s(`div`,{className:`mem-empty`,children:s(`p`,{children:e(`mem.conv.noMatch`,{query:on})})})]}),j&&d(`div`,{className:`mem-conv-detail-overlay`,children:[d(`div`,{className:`mem-conv-detail-header`,children:[s(`h2`,{children:s(`bdi`,{children:Ve(j.sessionId)})}),d(`div`,{className:`mem-conv-detail-actions`,children:[Be.has(j.sessionId)&&s(`button`,{className:`btn-secondary`,onClick:()=>l(j.sessionId),children:e(`mem.conv.openChat`)}),s(`button`,{className:`btn-icon`,onClick:()=>dn(null),"aria-label":e(`mem.conv.close`),children:s(We,{size:16})})]})]}),d(`div`,{className:`mem-conv-detail-body`,children:[j.turns.map(t=>d(`div`,{className:`mem-conv-turn`,children:[d(`div`,{className:`mem-conv-turn-header`,children:[s(`div`,{className:`mem-conv-turn-role ${t.role}`,children:s(w,{value:t.role,keys:At})}),s(`span`,{className:`mem-conv-turn-time`,title:x(t.timestamp,u(e)),children:S(t.timestamp,e)})]}),s(`div`,{className:`mem-conv-turn-content`,children:s(`bdi`,{children:t.content})})]},t.id)),j.turns.length===0&&s(`div`,{className:`mem-empty`,children:e(`mem.conv.noTurns`)})]})]})]}),d(`div`,{className:`mem-section`,children:[d(`div`,{className:`mem-section-title`,children:[s(st,{size:14}),` `,e(`mem.settings.title`),` `,s(`span`,{className:`mem-beta`,style:{fontSize:10,fontWeight:600,color:`var(--accent-yellow)`,background:`var(--accent-yellow-dim)`,padding:`1px 6px`,borderRadius:4,marginInlineStart:6,verticalAlign:`middle`},children:e(`mem.beta`)})]}),d(`div`,{className:`mem-setting-row`,children:[d(`div`,{className:`mem-setting-info`,children:[s(`span`,{className:`mem-setting-label`,children:e(`mem.settings.memory`)}),s(`span`,{className:`mem-setting-desc`,children:e(`mem.settings.memoryDesc`)})]}),s(`button`,{className:`mem-toggle${F?` mem-toggle-on`:``}`,disabled:I,onClick:async()=>{if(!F)z(`memory`);else{L(!0);try{let e=await f({memory_enabled:!1});_n(e.memory_enabled)}catch(n){t.system.warn(`Failed to disable memory`,n),X(e(`mem.toast.settingFailed`,{error:T(n)}),`error`)}finally{L(!1)}}},"aria-pressed":F,"aria-label":e(F?`mem.settings.memoryOn`:`mem.settings.memoryOff`),children:e.bare(F?`mem.on`:`mem.off`)})]}),Dn&&(()=>{let n={memory:{title:`mem.beta.memory.title`,description:`mem.beta.memory.desc`,bullets:[`mem.beta.memory.local`,`mem.beta.memory.lost`,`mem.beta.memory.disable`],buttonLabel:`mem.beta.memory.confirm`,onConfirm:async()=>{let t=await f({memory_enabled:!0});_n(t.memory_enabled),X(e(`mem.toast.memoryEnabled`),`info`)}},mcp:{title:`mem.beta.mcp.title`,description:`mem.beta.mcp.desc`,bullets:[`mem.beta.mcp.read`,`mem.beta.mcp.restart`,`mem.beta.mcp.debug`],buttonLabel:`mem.beta.mcp.confirm`,onConfirm:async()=>{let t=await f({mcp_memory_enabled:!0});yn(t.mcp_memory_enabled),X(e(`mem.toast.mcpEnabled`),`info`)}},discovery:{title:`mem.beta.discovery.title`,description:`mem.beta.discovery.desc`,bullets:[`mem.beta.discovery.collects`,`mem.beta.discovery.scans`,`mem.beta.discovery.local`],buttonLabel:`mem.beta.discovery.confirm`,onConfirm:async()=>{let t=await f({system_discovery_consent:!0});if(xn(t.system_discovery_consent),t.system_context_error)X(e(`mem.toast.discoveryScanFailed`,{error:t.system_context_error}),`error`);else{let n=t.system_context_refresh?.stored??0;X(e(`mem.toast.discoveryEnabled`,{n}),`info`)}Q()}}}[Dn];return d(a.Fragment,{children:[s(`div`,{"aria-hidden":`true`,style:{position:`fixed`,inset:0,background:`var(--bg-modal-overlay)`,zIndex:9998,backdropFilter:`blur(4px)`},onClick:()=>z(null)}),d(`div`,{ref:br,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`mem-beta-confirm-title`,"aria-describedby":`mem-beta-confirm-desc`,tabIndex:-1,style:{position:`fixed`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,zIndex:9999,background:`var(--bg-card)`,border:`1px solid var(--border)`,borderRadius:12,padding:`28px 32px`,maxWidth:420,width:`90vw`,boxShadow:`var(--shadow-lg)`},children:[d(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,marginBottom:16},children:[s(`span`,{className:`mem-beta`,style:{fontSize:11,fontWeight:700,color:`var(--accent-yellow)`,background:`var(--accent-yellow-dim)`,padding:`3px 10px`,borderRadius:4},children:e(`mem.beta`)}),s(`h2`,{id:`mem-beta-confirm-title`,style:{fontSize:16,fontWeight:600,color:`var(--text-primary)`},children:e(n.title)})]}),s(`p`,{id:`mem-beta-confirm-desc`,style:{fontSize:13,lineHeight:1.6,color:`var(--text-secondary)`,margin:`0 0 8px`},children:e(n.description)}),s(`ul`,{style:{fontSize:13,lineHeight:1.7,color:`var(--text-secondary)`,margin:`0 0 24px`,paddingInlineStart:20},children:n.bullets.map(t=>s(`li`,{children:e(t)},t))}),d(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:10},children:[s(`button`,{className:`btn-secondary`,onClick:()=>z(null),style:{padding:`8px 20px`,fontSize:13,borderRadius:6},children:e(`mem.cancel`)}),s(`button`,{disabled:I,onClick:async()=>{L(!0);try{await n.onConfirm()}catch(n){t.system.warn(`Failed to update setting`,n),X(e(`mem.toast.settingFailed`,{error:T(n)}),`error`)}finally{L(!1),z(null)}},style:{padding:`8px 24px`,fontSize:13,fontWeight:600,borderRadius:6,border:`none`,cursor:`pointer`,background:`var(--accent-fill)`,color:`var(--accent-fill-text)`},children:e(n.buttonLabel)})]})]})]})})(),d(`div`,{className:`mem-setting-row`,children:[d(`div`,{className:`mem-setting-info`,children:[s(`span`,{className:`mem-setting-label`,children:e(`mem.settings.mcp`)}),s(`span`,{className:`mem-setting-desc`,children:e(`mem.settings.mcpDesc`)})]}),s(`button`,{className:`mem-toggle${vn?` mem-toggle-on`:``}`,disabled:I,onClick:async()=>{if(!vn)z(`mcp`);else{L(!0);try{let e=await f({mcp_memory_enabled:!1});yn(e.mcp_memory_enabled)}catch(n){t.system.warn(`Failed to update memory settings`,n),X(e(`mem.toast.settingFailed`,{error:T(n)}),`error`)}finally{L(!1)}}},"aria-label":e(`mem.settings.mcpToggle`),"aria-pressed":vn,children:e.bare(vn?`mem.on`:`mem.off`)})]}),d(`div`,{className:`mem-setting-row`,children:[d(`div`,{className:`mem-setting-info`,children:[s(`span`,{className:`mem-setting-label`,children:e(`mem.settings.discovery`)}),s(`span`,{className:`mem-setting-desc`,children:e(`mem.settings.discoveryDesc`)})]}),s(`button`,{className:`mem-toggle${bn?` mem-toggle-on`:``}`,disabled:I,onClick:async()=>{if(!bn)z(`discovery`);else{L(!0);try{let e=await f({system_discovery_consent:!1});xn(e.system_discovery_consent)}catch(n){t.system.warn(`Failed to update system discovery setting`,n),X(e(`mem.toast.settingFailed`,{error:T(n)}),`error`)}finally{L(!1)}}},"aria-label":e(`mem.settings.discoveryToggle`),"aria-pressed":bn,children:e.bare(bn?`mem.on`:`mem.off`)})]}),d(`div`,{className:`mem-setting-row mem-setting-row-danger`,children:[d(`div`,{className:`mem-setting-info`,children:[s(`span`,{className:`mem-setting-label`,children:e(`mem.settings.reinit`)}),s(`span`,{className:`mem-setting-desc`,children:e(`mem.settings.reinitDesc`)})]}),Tn?d(`div`,{className:`mem-delete-confirm`,children:[s(`span`,{className:`mem-delete-confirm-label`,children:e(`mem.settings.sure`)}),s(`button`,{className:`mem-btn-danger`,disabled:I,onClick:async()=>{L(!0);try{let t=await le();t.system_context.error?X(e(`mem.toast.server`,{message:t.system_context.error}),`error`):X(e(`mem.toast.reinitialized`,{cleared:t.cleared.knowledge,stored:t.system_context.stored}),`info`),Q()}catch(n){t.system.warn(`Failed to reinitialize memory`,n),X(e(`mem.toast.reinitFailed`,{error:T(n)}),`error`)}finally{L(!1),En(!1)}},children:e(`mem.settings.reinitConfirm`)}),s(`button`,{className:`btn-secondary`,onClick:()=>En(!1),style:{padding:`6px 14px`,fontSize:12},children:e(`mem.cancel`)})]}):s(`button`,{className:`mem-btn-danger`,disabled:I,onClick:()=>En(!0),children:e(`mem.settings.reinitButton`)})]}),d(`div`,{className:`mem-setting-row mem-setting-row-danger`,children:[d(`div`,{className:`mem-setting-info`,children:[s(`span`,{className:`mem-setting-label`,children:e(`mem.settings.deleteAll`)}),s(`span`,{className:`mem-setting-desc`,children:e(`mem.settings.deleteAllDesc`)})]}),Sn?d(`div`,{className:`mem-delete-confirm`,children:[s(`span`,{className:`mem-delete-confirm-label`,children:e(`mem.settings.sure`)}),s(`button`,{className:`mem-btn-danger`,disabled:I,onClick:async()=>{L(!0);try{let t=await Le();X(e(`mem.toast.cleared`,{knowledge:t.knowledge,conversations:t.conversations}),`info`),Q()}catch(n){t.system.warn(`Failed to clear memory`,n),X(e(`mem.toast.clearFailed`,{error:T(n)}),`error`)}finally{L(!1),Cn(!1)}},children:e(`mem.settings.deleteConfirm`)}),s(`button`,{className:`btn-secondary`,onClick:()=>Cn(!1),style:{padding:`6px 14px`,fontSize:12},children:e(`mem.cancel`)})]}):s(`button`,{className:`mem-btn-danger`,disabled:I,onClick:()=>Cn(!0),children:e(`mem.settings.deleteButton`)})]})]}),g&&d(`div`,{className:`mem-db-footer`,children:[d(`span`,{children:[e(`mem.footer.database`),`: `,s(`bdi`,{dir:`ltr`,children:qe(g.db_size_bytes)}),g.knowledge?.avg_confidence!=null&&d(a.Fragment,{children:[` · `,e(`mem.footer.avgConfidence`,{n:g.knowledge.avg_confidence.toFixed(2)})]})]}),d(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[g.knowledge?.entity_count!=null&&g.knowledge.entity_count>0&&s(`span`,{children:e(`mem.footer.entities`,{n:g.knowledge.entity_count})}),g.knowledge?.sensitive_count!=null&&g.knowledge.sensitive_count>0&&d(`span`,{children:[s(st,{size:10}),` `,e(`mem.footer.sensitive`,{n:g.knowledge.sensitive_count})]})]})]})]})}),B===`profile`&&d(`div`,{className:`mem-profile-grid`,children:[d(`div`,{className:`mem-profile-card`,children:[d(`div`,{className:`mem-profile-card-title`,children:[s(ve,{size:16}),` `,e(`mem.disc.title`)]}),s(`p`,{className:`mem-profile-desc`,children:e(`mem.disc.desc`)}),s(`button`,{className:`btn-primary mem-profile-run-btn`,disabled:V===`running`||V===`saving`,onClick:Xr,children:V===`running`?d(a.Fragment,{children:[s(`div`,{className:`mem-spinner-sm`}),` `,e(`mem.running`)]}):e(`mem.disc.run`)}),Gn.length>0&&s(`div`,{className:`mem-log`,ref:Jn,children:Gn.map((e,t)=>s(`div`,{className:`mem-log-line ${e.kind}`,children:e.server?s(`bdi`,{children:e.text}):e.text},t))}),(V===`review`||V===`saving`||V===`done`)&&W.length>0&&d(`div`,{className:`mem-review-section`,children:[s(`div`,{className:`mem-review-header`,children:e(`mem.review.title`)}),s(`div`,{className:`mem-review-list`,children:W.map((e,t)=>d(`label`,{className:`mem-review-item`,children:[s(`input`,{type:`checkbox`,checked:e._checked,disabled:V===`saving`||V===`done`,onChange:()=>{G(e=>e.map((e,n)=>n===t?{...e,_checked:!e._checked}:e))}}),s(`bdi`,{className:`mem-review-content`,children:e.content}),s(`span`,{className:`mem-source-badge`,children:e._source_name?s(`bdi`,{children:e._source_name}):s(w,{value:e.category,keys:C})}),d(`span`,{className:`mem-conf-badge`,children:[Math.round(e.confidence*100),`%`]})]},t))}),d(`div`,{className:`mem-review-actions`,children:[s(`button`,{className:`btn-primary`,disabled:V===`saving`||V===`done`||W.filter(e=>e._checked).length===0,onClick:Zr,children:V===`saving`?d(a.Fragment,{children:[s(`div`,{className:`mem-spinner-sm`}),` `,e(`mem.saving`)]}):e(`mem.review.saveSelected`,{n:W.filter(e=>e._checked).length})}),d(`span`,{className:`mem-review-select-links`,children:[s(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>G(e=>e.map(e=>({...e,_checked:!0}))),children:e(`mem.review.selectAll`)}),` / `,s(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>G(e=>e.map(e=>({...e,_checked:!1}))),children:e(`mem.review.none`)})]})]})]}),V===`done`&&Kn!==null&&d(`div`,{className:`mem-profile-success`,children:[s(tt,{size:14}),` `,e(`mem.disc.saved`,{n:Kn})]}),V===`review`&&W.length===0&&s(`div`,{className:`mem-profile-empty`,children:e(`mem.disc.empty`)})]}),d(`div`,{className:`mem-profile-card`,children:[d(`div`,{className:`mem-profile-card-title`,children:[s(Pe,{size:16}),` `,e(`mem.inf.title`)]}),s(`p`,{className:`mem-profile-desc`,children:e(`mem.inf.desc`)}),s(`p`,{className:`mem-profile-note`,children:e(`mem.inf.note`)}),d(`label`,{className:`mem-profile-checkbox`,children:[s(`input`,{type:`checkbox`,checked:er,onChange:e=>tr(e.target.checked),disabled:K===`running`||K===`saving`}),e(`mem.inf.browser`)]}),s(`button`,{className:`btn-primary mem-profile-run-btn`,disabled:K===`running`||K===`saving`,onClick:Qr,children:K===`running`?d(a.Fragment,{children:[s(`div`,{className:`mem-spinner-sm`}),` `,e(`mem.running`)]}):e(`mem.inf.run`)}),Xn.length>0&&s(`div`,{className:`mem-log`,ref:nr,children:Xn.map((e,t)=>s(`div`,{className:`mem-log-line ${e.kind}`,children:e.server?s(`bdi`,{children:e.text}):e.text},t))}),(K===`review`||K===`saving`||K===`done`)&&Y.length>0&&d(`div`,{className:`mem-review-section`,children:[s(`div`,{className:`mem-review-header`,children:e(`mem.review.title`)}),s(`div`,{className:`mem-review-list`,children:Y.map((e,t)=>d(`label`,{className:`mem-review-item`,children:[s(`input`,{type:`checkbox`,checked:e._checked,disabled:K===`saving`||K===`done`,onChange:()=>{Zn(e=>e.map((e,n)=>n===t?{...e,_checked:!e._checked}:e))}}),s(`bdi`,{className:`mem-review-content`,children:e.content}),s(`span`,{className:`mem-domain-badge ${Mt[e.domain]||`gray`}`,children:s(w,{value:e.domain,keys:jt})}),d(`span`,{className:`mem-conf-badge`,children:[Math.round(e.confidence*100),`%`]})]},t))}),d(`div`,{className:`mem-review-actions`,children:[s(`button`,{className:`btn-primary`,disabled:K===`saving`||K===`done`||Y.filter(e=>e._checked).length===0,onClick:$r,children:K===`saving`?d(a.Fragment,{children:[s(`div`,{className:`mem-spinner-sm`}),` `,e(`mem.saving`)]}):e(`mem.review.saveSelected`,{n:Y.filter(e=>e._checked).length})}),d(`span`,{className:`mem-review-select-links`,children:[s(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>Zn(e=>e.map(e=>({...e,_checked:!0}))),children:e(`mem.review.selectAll`)}),` / `,s(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>Zn(e=>e.map(e=>({...e,_checked:!1}))),children:e(`mem.review.none`)})]})]})]}),K===`done`&&Qn!==null&&d(`div`,{className:`mem-profile-success`,children:[s(tt,{size:14}),` `,e(`mem.inf.saved`,{n:Qn})]}),K===`review`&&Y.length===0&&s(`div`,{className:`mem-profile-empty`,children:e(`mem.inf.empty`)})]})]}),B===`goals`&&d(`div`,{className:`mem-goals-tab`,children:[s(`div`,{className:`mem-goals-stats-row`,children:[`queued`,`in_progress`,`completed`,`failed`].map(t=>d(`div`,{className:`mem-goals-stat-pill mem-goal-status-${t.replace(`_`,`-`)}`,children:[s(`span`,{className:`mem-goals-stat-n`,children:Nn?.goals[t]??0}),s(`span`,{className:`mem-goals-stat-label`,children:e(Dt[t])})]},t))}),jn.filter(e=>e.status===`pending_approval`).length>0&&d(`div`,{className:`mem-goals-approval-banner`,children:[d(`div`,{className:`mem-goals-approval-title`,children:[s(te,{size:14}),` `,e(`mem.goals.suggested`,{n:jn.filter(e=>e.status===`pending_approval`).length})]}),jn.filter(e=>e.status===`pending_approval`).map(t=>d(`div`,{className:`mem-goals-approval-item`,children:[d(`div`,{className:`mem-goals-approval-text`,children:[s(`strong`,{children:s(`bdi`,{children:t.title})}),s(`bdi`,{children:t.description})]}),d(`div`,{className:`mem-goals-approval-actions`,children:[s(`button`,{className:`btn-danger-sm`,onClick:()=>Ar(()=>Ce(t.id),`mem.goals.rejectFailed`),children:e(`mem.goals.reject`)}),s(`button`,{className:`btn-secondary`,onClick:()=>Ar(()=>Ge(t.id),`mem.goals.acceptFailed`),children:e(`mem.goals.accept`)})]})]},t.id))]}),s(`div`,{className:`mem-goals-toolbar`,children:d(`button`,{className:`btn-primary`,onClick:()=>Hn(e=>!e),children:[s(Ae,{size:14}),` `,e(`mem.goals.new`)]})}),Vn&&d(`div`,{className:`mem-goals-add-form`,children:[s(`input`,{className:`mem-input`,placeholder:e(`mem.goals.titlePlaceholder`),value:Un.title,onChange:e=>Wn(t=>({...t,title:e.target.value}))}),s(`textarea`,{className:`mem-input`,placeholder:e(`mem.goals.descPlaceholder`),rows:2,value:Un.description,onChange:e=>Wn(t=>({...t,description:e.target.value}))}),d(`div`,{className:`mem-goals-form-row`,children:[d(`select`,{className:`mem-select`,value:Un.priority,onChange:e=>Wn(t=>({...t,priority:e.target.value})),children:[s(`option`,{value:`low`,children:e.bare(`mem.goals.priorityLow`)}),s(`option`,{value:`medium`,children:e.bare(`mem.goals.priorityMedium`)}),s(`option`,{value:`high`,children:e.bare(`mem.goals.priorityHigh`)})]}),s(`button`,{className:`btn-primary`,onClick:()=>{Un.title.trim()&&Ar(async()=>{await $e(Un),Wn({title:``,description:``,priority:`medium`}),Hn(!1)},`mem.goals.createFailed`)},children:e(`mem.goals.create`)}),s(`button`,{className:`btn-secondary`,onClick:()=>Hn(!1),children:e(`mem.cancel`)})]})]}),Fn?d(`div`,{className:`mem-loading`,children:[s(`div`,{className:`mem-spinner`}),` `,e(`mem.goals.loading`)]}):jn.filter(e=>e.status!==`pending_approval`&&e.status!==`rejected`).length===0?d(`div`,{className:`mem-empty`,children:[s(`div`,{className:`mem-empty-icon`,children:s(ct,{size:32})}),s(`p`,{children:e(`mem.goals.empty`)})]}):s(`div`,{className:`mem-goals-list`,children:jn.filter(e=>e.status!==`pending_approval`&&e.status!==`rejected`).map(t=>d(`div`,{className:`mem-goal-card mem-goal-status-${t.status.replace(`_`,`-`)}`,children:[d(`div`,{className:`mem-goal-header`,role:`button`,tabIndex:0,"aria-expanded":Ln===t.id,onClick:()=>Rn(e=>e===t.id?null:t.id),onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),Rn(e=>e===t.id?null:t.id))},children:[d(`div`,{className:`mem-goal-header-left`,children:[s(`span`,{className:`mem-goal-status-dot status-${t.status.replace(`_`,`-`)}`}),s(`bdi`,{className:`mem-goal-title`,children:t.title}),s(`span`,{className:`mem-goal-priority mem-priority-${t.priority}`,children:s(w,{value:t.priority,keys:Ot})}),t.source!==`user`&&d(`span`,{className:`mem-goal-source-badge`,children:[s(te,{size:10}),` `,s(w,{value:t.source,keys:kt})]})]}),d(`div`,{className:`mem-goal-header-right`,children:[d(`span`,{className:`mem-goal-task-count`,children:[s(xe,{size:12}),d(`bdi`,{dir:`ltr`,children:[t.tasks.filter(e=>e.status===`completed`).length,`/`,t.tasks.length]})]}),t.status===`queued`&&s(`button`,{className:`mem-goal-action-btn mem-goal-cancel-btn`,onClick:e=>{e.stopPropagation(),Ar(()=>He(t.id),`mem.goals.cancelFailed`)},children:e(`mem.cancel`)}),zn===t.id?s(`button`,{className:`mem-goal-action-btn mem-goal-delete-btn mem-goal-delete-confirm`,onClick:e=>{e.stopPropagation(),Bn(null),Ar(()=>Qe(t.id),`mem.goals.deleteFailed`)},children:e(`mem.row.deleteConfirm`)}):s(`button`,{className:`mem-goal-action-btn mem-goal-delete-btn`,"aria-label":e(`mem.goals.deleteAria`,{title:t.title}),onClick:e=>{e.stopPropagation(),Bn(t.id)},children:s(Ne,{size:12})}),s(De,{size:14,className:Ln===t.id?`mem-chevron-open`:``})]})]}),Ln===t.id&&d(`div`,{className:`mem-goal-body`,children:[t.description&&s(`p`,{className:`mem-goal-desc`,children:s(`bdi`,{children:t.description})}),t.progress_notes&&s(`p`,{className:`mem-goal-progress`,children:s(`bdi`,{children:t.progress_notes})}),t.tasks.length>0?s(`div`,{className:`mem-task-list`,children:t.tasks.map(e=>d(`div`,{className:`mem-task-row mem-task-status-${e.status}`,children:[s(`span`,{className:`mem-task-dot status-${e.status}`}),s(`bdi`,{className:`mem-task-desc`,children:e.description}),s(`span`,{className:`mem-task-status-label`,children:s(w,{value:e.status,keys:Dt})}),e.result&&s(`bdi`,{className:`mem-task-result`,children:e.result})]},e.id))}):s(`p`,{className:`mem-goal-no-tasks`,children:e(`mem.goals.noTasks`)})]})]},t.id))})]})]}),Wt.length>0&&s(`div`,{className:`mem-toast-container`,"aria-live":`polite`,children:Wt.map(e=>d(`div`,{className:`mem-toast mem-toast-${e.type}`,role:`status`,children:[e.type===`success`&&s(tt,{size:14}),e.type===`error`&&s(Je,{size:14}),e.type===`info`&&s(p,{size:14}),s(`span`,{children:e.text})]},e.id))})]})}export{Nt as MemoryDashboard};
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browser-KnDALPx_.js","./rolldown-runtime-XKyaHtl9.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{I as t,J as n,a as r,c as i,l as a,u as o}from"./useT-BNShbVIz.js";import{tt as s}from"./api-13Cql4sZ.js";import{At as c,Ft as l,Gt as u,X as d,at as f,ht as p,i as m,ot as h,pt as g,u as _}from"./index-B3y-e0-u.js";var v=e(n(),1),y=null,b=`https://ngrok.com/download`;function x({isOpen:n,onClose:x,onStop:S,error:C,setupCommands:w,onRetry:T}){let[E,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(!1),[A,j]=(0,v.useState)(null),M=r(),N=Array.isArray(w),P=!!C||N,[F,I]=(0,v.useState)(null),L=(0,v.useRef)(null);f(n,x);let R=(0,v.useRef)(null);d(R,n),_(R,n);let z=(0,v.useCallback)(async()=>{try{let e=await s();return D(e),e}catch(e){return t.system.error(`Failed to fetch tunnel status`,e),null}},[]);(0,v.useEffect)(()=>{if(!n||P)return;z();let e=setInterval(async()=>{let t=await z();t?.active&&t?.url&&clearInterval(e)},2e3);return()=>clearInterval(e)},[n,P,z]),(0,v.useEffect)(()=>{if(!E?.active||!E.url||!E.token||!L.current)return;let n=`${E.url}/?token=${E.token}`;t.system.info(`Generating QR code for: ${n}`),(async()=>{if(I(null),!y)try{let t=await m(()=>import(`./browser-KnDALPx_.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1]),import.meta.url);y=t.default||t}catch{t.system.error(`QR code library not available - install with: npm install qrcode`),I(`QR code unavailable on this build. Use the link below instead.`);return}let r=getComputedStyle(document.documentElement),i=r.getPropertyValue(`--text-primary`).trim(),a=r.getPropertyValue(`--bg-primary`).trim();if(!i||!a)t.system.error(`QR code skipped: --text-primary/--bg-primary did not resolve. styles/index.css must be loaded before this modal renders.`),I(`QR code unavailable — the theme did not load. Use the link below instead.`);else try{await y.toCanvas(L.current,n,{width:200,margin:2,color:{dark:i,light:a}})}catch(e){t.system.error(`QR code generation failed`,e),I(`QR code could not be drawn. Use the link below instead.`)}})()},[E?.active,E?.url,E?.token]);let B=(0,v.useRef)(null),V=(0,v.useCallback)(()=>{if(!E?.url||!E?.token)return;let e=`${E.url}/?token=${E.token}`;navigator.clipboard.writeText(e).then(()=>{k(!0),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>k(!1),2e3)})},[E]),H=(0,v.useCallback)(e=>{navigator.clipboard.writeText(e).then(()=>{j(e),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>j(null),2e3)}).catch(e=>t.system.error(`Could not copy the ngrok install command`,e))},[]);if((0,v.useEffect)(()=>()=>{B.current&&clearTimeout(B.current)},[]),!n)return null;let U=E?.active&&E?.url&&E?.token?`${E.url}/?token=${E.token}`:``;return a(`div`,{ref:R,className:`modal-overlay`,onClick:x,role:`dialog`,"aria-modal":`true`,"aria-label":`Mobile access`,children:o(`div`,{className:`modal-panel mobile-modal`,onClick:e=>e.stopPropagation(),children:[o(`div`,{className:`modal-header`,children:[o(`h3`,{style:{display:`flex`,alignItems:`center`,gap:`8px`},children:[a(g,{size:18}),`Mobile access`]}),a(`button`,{className:`btn-icon`,onClick:x,"aria-label":`Close`,children:a(h,{size:18})})]}),o(`div`,{className:`modal-body mobile-modal-body`,children:[o(`div`,{className:`tunnel-status`,children:[a(`span`,{className:`status-dot ${E?.active?`active`:N?`setup`:C?`error`:`starting`}`}),a(`span`,{children:E?.active?`Tunnel active`:N?M(`mobile.ngrokRequired`):C?`Couldn't start mobile access`:`Starting tunnel...`}),!E?.active&&!P&&a(`span`,{className:`tunnel-spinner`})]}),N&&o(`div`,{className:`tunnel-setup`,children:[a(`div`,{className:`tunnel-setup-title`,children:M(`mobile.setupTitle`)}),o(`p`,{children:[M(`mobile.setupIntro`),` `,w.length>0?M(`mobile.setupInstall`):M(`mobile.setupDownload`)]}),w.map(e=>o(`div`,{className:`tunnel-url-row tunnel-setup-command`,children:[a(`input`,{type:`text`,readOnly:!0,dir:`ltr`,value:e,"aria-label":M(`mobile.installCommand`)}),o(`button`,{className:`copy-url-btn ${A===e?`copied`:``}`,onClick:()=>H(e),title:M(`mobile.copyCommand`),children:[a(A===e?u:l,{size:13}),M(A===e?`mobile.copied`:`mobile.copy`)]})]},e)),o(`a`,{href:b,target:`_blank`,rel:`noopener noreferrer`,className:`tunnel-setup-link`,children:[M(`mobile.downloadPage`),` `,a(c,{size:11})]})]}),C&&!N&&a(`div`,{className:`tunnel-error`,children:C}),!P&&a(`div`,{className:`qr-code-area`,children:E?.active?o(i.Fragment,{children:[a(`canvas`,{ref:L,hidden:!!F}),F&&a(`div`,{className:`qr-placeholder error`,children:F})]}):o(`div`,{className:`qr-placeholder`,children:[a(`div`,{className:`placeholder-spinner`}),a(`span`,{children:`Connecting...`})]})}),E?.active&&U&&o(`div`,{className:`tunnel-url-area`,children:[a(`label`,{children:`Mobile URL`}),o(`div`,{className:`tunnel-url-row`,children:[a(`input`,{type:`text`,readOnly:!0,value:U}),o(`button`,{className:`copy-url-btn ${O?`copied`:``}`,onClick:V,title:`Copy URL`,children:[a(O?u:l,{size:13}),O?`Copied`:`Copy`]})]})]}),E?.active&&E?.publicIp&&E?.url&&!E.url.includes(`ngrok-free.app`)&&o(`div`,{className:`tunnel-password-hint`,children:[a(`label`,{children:`Tunnel password`}),a(`div`,{className:`tunnel-password-value`,children:E.publicIp}),a(`span`,{className:`tunnel-password-note`,children:`Enter this when the tunnel page asks for a password`})]}),!P&&a(`div`,{className:`mobile-instructions`,children:o(`ol`,{children:[a(`li`,{children:F?`Open the mobile URL above on your phone`:`Scan the QR code with your phone's camera`}),E?.url&&!E.url.includes(`ngrok-free.app`)&&a(`li`,{children:`Enter the tunnel password shown above when prompted`}),a(`li`,{children:`Chat with GAIA from your mobile device`}),a(`li`,{children:`Your data stays secure via encrypted tunnel`})]})}),E?.active&&!C&&o(`div`,{className:`mobile-install-hint`,children:[a(`div`,{className:`mobile-install-hint-title`,children:M(`mobileAccess.installTitle`)}),a(`p`,{children:M(`mobileAccess.installSteps`)}),a(`p`,{children:M(`mobileAccess.linkLifetime`)})]}),o(`div`,{className:`mobile-access-actions`,children:[E?.active&&S&&a(`button`,{className:`btn-danger`,onClick:S,title:`Close the tunnel and revoke the mobile URL`,children:`Stop tunnel`}),N&&T&&o(`button`,{className:`btn-primary`,onClick:T,children:[a(p,{size:13}),` `,M(`mobile.retry`)]}),a(`button`,{className:`btn-secondary`,onClick:x,children:`Close`})]})]})]})})}export{x as MobileAccessModal};
2
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{I as t,J as n,a as r,c as i,l as a,u as o}from"./useT-9bLwAbF7.js";import{tt as s}from"./api-c2Hja8UA.js";import{At as c,Ft as l,Gt as u,X as d,at as f,ht as p,i as m,ot as h,pt as g,u as _}from"./index-BSZT2AHb.js";var v=e(n(),1),y=null,b=`https://ngrok.com/download`;function x({isOpen:n,onClose:x,onStop:S,error:C,setupCommands:w,onRetry:T}){let[E,D]=(0,v.useState)(null),[O,k]=(0,v.useState)(!1),[A,j]=(0,v.useState)(null),M=r(),N=Array.isArray(w),P=!!C||N,[F,I]=(0,v.useState)(null),L=(0,v.useRef)(null);f(n,x);let R=(0,v.useRef)(null);d(R,n),_(R,n);let z=(0,v.useCallback)(async()=>{try{let e=await s();return D(e),e}catch(e){return t.system.error(`Failed to fetch tunnel status`,e),null}},[]);(0,v.useEffect)(()=>{if(!n||P)return;z();let e=setInterval(async()=>{let t=await z();t?.active&&t?.url&&clearInterval(e)},2e3);return()=>clearInterval(e)},[n,P,z]),(0,v.useEffect)(()=>{if(!E?.active||!E.url||!E.token||!L.current)return;let n=`${E.url}/?token=${E.token}`;t.system.info(`Generating QR code for: ${n}`),(async()=>{if(I(null),!y)try{let t=await m(()=>import(`./browser-KnDALPx_.js`).then(t=>e(t.default,1)),__vite__mapDeps([0,1]),import.meta.url);y=t.default||t}catch{t.system.error(`QR code library not available - install with: npm install qrcode`),I(`QR code unavailable on this build. Use the link below instead.`);return}let r=getComputedStyle(document.documentElement),i=r.getPropertyValue(`--text-primary`).trim(),a=r.getPropertyValue(`--bg-primary`).trim();if(!i||!a)t.system.error(`QR code skipped: --text-primary/--bg-primary did not resolve. styles/index.css must be loaded before this modal renders.`),I(`QR code unavailable — the theme did not load. Use the link below instead.`);else try{await y.toCanvas(L.current,n,{width:200,margin:2,color:{dark:i,light:a}})}catch(e){t.system.error(`QR code generation failed`,e),I(`QR code could not be drawn. Use the link below instead.`)}})()},[E?.active,E?.url,E?.token]);let B=(0,v.useRef)(null),V=(0,v.useCallback)(()=>{if(!E?.url||!E?.token)return;let e=`${E.url}/?token=${E.token}`;navigator.clipboard.writeText(e).then(()=>{k(!0),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>k(!1),2e3)})},[E]),H=(0,v.useCallback)(e=>{navigator.clipboard.writeText(e).then(()=>{j(e),B.current&&clearTimeout(B.current),B.current=setTimeout(()=>j(null),2e3)}).catch(e=>t.system.error(`Could not copy the ngrok install command`,e))},[]);if((0,v.useEffect)(()=>()=>{B.current&&clearTimeout(B.current)},[]),!n)return null;let U=E?.active&&E?.url&&E?.token?`${E.url}/?token=${E.token}`:``;return a(`div`,{ref:R,className:`modal-overlay`,onClick:x,role:`dialog`,"aria-modal":`true`,"aria-label":`Mobile access`,children:o(`div`,{className:`modal-panel mobile-modal`,onClick:e=>e.stopPropagation(),children:[o(`div`,{className:`modal-header`,children:[o(`h3`,{style:{display:`flex`,alignItems:`center`,gap:`8px`},children:[a(g,{size:18}),`Mobile access`]}),a(`button`,{className:`btn-icon`,onClick:x,"aria-label":`Close`,children:a(h,{size:18})})]}),o(`div`,{className:`modal-body mobile-modal-body`,children:[o(`div`,{className:`tunnel-status`,children:[a(`span`,{className:`status-dot ${E?.active?`active`:N?`setup`:C?`error`:`starting`}`}),a(`span`,{children:E?.active?`Tunnel active`:N?M(`mobile.ngrokRequired`):C?`Couldn't start mobile access`:`Starting tunnel...`}),!E?.active&&!P&&a(`span`,{className:`tunnel-spinner`})]}),N&&o(`div`,{className:`tunnel-setup`,children:[a(`div`,{className:`tunnel-setup-title`,children:M(`mobile.setupTitle`)}),o(`p`,{children:[M(`mobile.setupIntro`),` `,w.length>0?M(`mobile.setupInstall`):M(`mobile.setupDownload`)]}),w.map(e=>o(`div`,{className:`tunnel-url-row tunnel-setup-command`,children:[a(`input`,{type:`text`,readOnly:!0,dir:`ltr`,value:e,"aria-label":M(`mobile.installCommand`)}),o(`button`,{className:`copy-url-btn ${A===e?`copied`:``}`,onClick:()=>H(e),title:M(`mobile.copyCommand`),children:[a(A===e?u:l,{size:13}),M(A===e?`mobile.copied`:`mobile.copy`)]})]},e)),o(`a`,{href:b,target:`_blank`,rel:`noopener noreferrer`,className:`tunnel-setup-link`,children:[M(`mobile.downloadPage`),` `,a(c,{size:11})]})]}),C&&!N&&a(`div`,{className:`tunnel-error`,children:C}),!P&&a(`div`,{className:`qr-code-area`,children:E?.active?o(i.Fragment,{children:[a(`canvas`,{ref:L,hidden:!!F}),F&&a(`div`,{className:`qr-placeholder error`,children:F})]}):o(`div`,{className:`qr-placeholder`,children:[a(`div`,{className:`placeholder-spinner`}),a(`span`,{children:`Connecting...`})]})}),E?.active&&U&&o(`div`,{className:`tunnel-url-area`,children:[a(`label`,{children:`Mobile URL`}),o(`div`,{className:`tunnel-url-row`,children:[a(`input`,{type:`text`,readOnly:!0,value:U}),o(`button`,{className:`copy-url-btn ${O?`copied`:``}`,onClick:V,title:`Copy URL`,children:[a(O?u:l,{size:13}),O?`Copied`:`Copy`]})]})]}),E?.active&&E?.publicIp&&E?.url&&!E.url.includes(`ngrok-free.app`)&&o(`div`,{className:`tunnel-password-hint`,children:[a(`label`,{children:`Tunnel password`}),a(`div`,{className:`tunnel-password-value`,children:E.publicIp}),a(`span`,{className:`tunnel-password-note`,children:`Enter this when the tunnel page asks for a password`})]}),!P&&a(`div`,{className:`mobile-instructions`,children:o(`ol`,{children:[a(`li`,{children:F?`Open the mobile URL above on your phone`:`Scan the QR code with your phone's camera`}),E?.url&&!E.url.includes(`ngrok-free.app`)&&a(`li`,{children:`Enter the tunnel password shown above when prompted`}),a(`li`,{children:`Chat with GAIA from your mobile device`}),a(`li`,{children:`Your data stays secure via encrypted tunnel`})]})}),E?.active&&!C&&o(`div`,{className:`mobile-install-hint`,children:[a(`div`,{className:`mobile-install-hint-title`,children:M(`mobileAccess.installTitle`)}),a(`p`,{children:M(`mobileAccess.installSteps`)}),a(`p`,{children:M(`mobileAccess.linkLifetime`)})]}),o(`div`,{className:`mobile-access-actions`,children:[E?.active&&S&&a(`button`,{className:`btn-danger`,onClick:S,title:`Close the tunnel and revoke the mobile URL`,children:`Stop tunnel`}),N&&T&&o(`button`,{className:`btn-primary`,onClick:T,children:[a(p,{size:13}),` `,M(`mobile.retry`)]}),a(`button`,{className:`btn-secondary`,onClick:x,children:`Close`})]})]})]})})}export{x as MobileAccessModal};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{I as t,J as n,P as r,a as i,c as a,f as o,i as s,k as c,l,q as u,r as d,t as f,u as p}from"./useT-BNShbVIz.js";import{n as m,t as h}from"./zap-BP1leAhK.js";import{xt as g}from"./api-13Cql4sZ.js";import{It as _,X as v,_t as y,at as b,dt as x,n as S,ot as C,u as w,yt as T}from"./index-B3y-e0-u.js";var E={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]};E.node;var D=u(E),O=e(n(),1),k=8e3,A={active:`schedules.status.active`,paused:`schedules.status.paused`,cancelled:`schedules.status.cancelled`};function j(e,t,n,r){if(!e)return t(`schedules.time.never`);let i=new Date(e),a=(n||new Date).getTime()-i.getTime(),o=Math.floor(a/1e3);if(o<0){let e=Math.abs(o);if(e<60)return t(`schedules.time.inSeconds`,{n:e});let n=Math.floor(e/60);if(n<60)return t(`schedules.time.inMinutes`,{n});let r=Math.floor(n/60);return r<24?t(`schedules.time.inHours`,{n:r}):t(`schedules.time.inDays`,{n:Math.floor(r/24)})}if(o<60)return t(`time.justNow`);let s=Math.floor(o/60);if(s<60)return t(`time.minutesAgo`,{n:s});let c=Math.floor(s/60);return c<24?t(`time.hoursAgo`,{n:c}):i.toLocaleDateString(r,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function M(e,t,n=d.bare,r){if(!e)return n(`schedules.time.never`);let i=j(e,n,t,r),a=new Date(e);return a.getTime()<=(t||new Date).getTime()?i:n(`schedules.time.clockIn`,{clock:a.toLocaleString(r,{weekday:`short`,hour:`numeric`,minute:`2-digit`}),relative:i})}function N(e){if(!e)return!1;let t=new Date(e).getTime()-Date.now();return t>0&&t<6e4}function P(e,t,n=0){let r=new Date(2e3,0,1,t,n);return new Intl.DateTimeFormat(f(e),{hour:`numeric`,minute:`2-digit`}).format(r)}function F(e,t){let[n,r]=e.split(`:`).map(Number);return P(t,n,r)}function I(e,t,n){let r=`${e}.${new Intl.PluralRules(n.locale).select(t)}`;return c(r)?r:null}var L=e=>e.length===5&&e.every(e=>e<5),R=e=>e.length===2&&e.includes(5)&&e.includes(6);function z(e,t,n){if(L(e))return n(`schedules.desc.days.weekdays`);if(R(e))return n(`schedules.desc.days.weekends`);if(e.length===7)return n(`schedules.desc.days.every`);let r=I(`schedules.desc.dayList`,e.length,t);return r?n(r,{days:e.map(e=>n(`schedules.dayName.${e}`)).join(n(`schedules.desc.dayJoin`))}):null}function B(e,t,n,r){let{kind:i,count:a,unit:o,days:s,time:c,start_hour:l,end_hour:u}=e,d=e=>c?n(`schedules.desc.at`,{when:e,time:F(c,r)}):e;if(i===`every`||i===`window`){let e=a&&o?I(`schedules.span.${o}`,a,t):null,c=s?z(s,t,n):void 0;if(!e||c===null)return null;let d=n(e,{n:a});if(i===`every`)return c?n(`schedules.desc.everyOn`,{span:d,days:c}):n(`schedules.desc.every`,{span:d});if(l==null||u==null)return null;let f=n(`schedules.hours`,{start:P(r,l),end:P(r,u)});return c?n(`schedules.desc.windowOn`,{span:d,hours:f,days:c}):n(`schedules.desc.window`,{span:d,hours:f})}if(i===`daily`)return c?d(n(`schedules.desc.daily`)):null;if(i!==`days`||!s?.length)return null;if(s.length===7)return d(n(`schedules.desc.daily`));if(L(s))return d(n(`schedules.desc.weekdays`));if(R(s))return d(n(`schedules.desc.weekends`));let f=z(s,t,n);return f&&d(n(`schedules.desc.onDays`,{days:f}))}function V(e,t){return!e||B(e,t,t.bare,t)===null?null:t.compose((n,r)=>B(e,t,n,s(r))??``)}function H(e,t){return e.length===5&&!e.includes(5)&&!e.includes(6)?t(`schedules.days.weekdays`):e.length===2&&e.includes(5)&&e.includes(6)?t(`schedules.days.weekends`):e.length===7?t(`schedules.days.every`):e.map(e=>t(`schedules.day.${e}`)).join(t(`schedules.days.join`))}function U({schedule:e}){let n=i(),{selectedSchedule:s,selectSchedule:c,updateScheduleStatus:u,runScheduleNow:d,deleteSchedule:g,results:v,resultsLoading:y,loadSchedules:b,loadResults:C}=S(),{setCurrentSession:w,setShowSchedules:E}=o(),P=s===e.name,F=V(e.description_parts,n),[I,L]=(0,O.useState)(!1),R=(0,O.useRef)(null),z=(0,O.useCallback)(()=>{R.current&&=(clearTimeout(R.current),null)},[]);(0,O.useEffect)(()=>z,[z]);let[B,H]=(0,O.useState)(()=>new Date),U=(0,O.useRef)(null);(0,O.useEffect)(()=>{let t=e.status===`active`&&N(e.next_run_at);return t&&!U.current?U.current=setInterval(()=>{H(new Date),e.next_run_at&&new Date(e.next_run_at).getTime()<=Date.now()&&b()},1e3):!t&&U.current&&(clearInterval(U.current),U.current=null),()=>{U.current&&=(clearInterval(U.current),null)}},[e.status,e.next_run_at,b]);let W=(0,O.useRef)(e.last_run_at);(0,O.useEffect)(()=>{P&&e.last_run_at!==W.current&&(W.current=e.last_run_at,C(e.name))},[P,e.last_run_at,e.name,C]);let G=e.last_run_at&&Date.now()-new Date(e.last_run_at).getTime()<5e3,K=(0,O.useCallback)(n=>{n.stopPropagation();let r=e.status===`active`?`paused`:`active`;t.ui.info(`Schedule "${e.name}": ${e.status} -> ${r}`),u(e.name,r)},[e.name,e.status,u]),q=(0,O.useCallback)(n=>{n.stopPropagation(),t.ui.info(`Schedule "${e.name}": run now`),d(e.name)},[e.name,d]),J=(0,O.useCallback)(n=>{n.stopPropagation(),z(),I?(t.ui.info(`Deleting schedule "${e.name}"`),g(e.name)):(L(!0),R.current=setTimeout(()=>{R.current=null,L(!1)},k))},[e.name,I,g,z]),Y=(0,O.useCallback)(n=>{n.stopPropagation(),e.session_id&&(t.ui.info(`Opening chat session for schedule "${e.name}"`),w(e.session_id),E(!1))},[e.session_id,e.name,w,E]);return p(`div`,{className:`schedule-card ${P?`selected`:``} ${G?`just-ran`:``}`,onClick:()=>c(P?null:e.name),children:[p(`div`,{className:`schedule-card-header`,children:[l(`span`,{className:`schedule-card-name`,dir:`auto`,children:e.name}),l(`span`,{className:`schedule-card-status ${e.status}`,children:n(A[e.status])})]}),l(`div`,{className:`schedule-card-prompt`,dir:`auto`,children:e.prompt}),p(`div`,{className:`schedule-card-meta`,children:[p(`span`,{title:r(F??e.description),children:[l(_,{size:11}),` `,F??l(`bdi`,{children:e.description})]}),l(`span`,{children:n(`schedules.card.runs`,{n:e.run_count})}),e.error_count>0&&l(`span`,{children:n(`schedules.card.errors`,{n:e.error_count})}),l(`span`,{children:n.compose(t=>t(`schedules.card.last`,{when:j(e.last_run_at,t,void 0,f(n))}))}),l(`span`,{children:n.compose(t=>t(`schedules.card.next`,{when:M(e.next_run_at,B,t,f(n))}))})]}),e.last_error&&l(`div`,{className:`schedule-card-error`,children:n(`schedules.card.lastFailed`,{error:e.last_error})}),p(`div`,{className:`schedule-card-actions`,children:[e.session_id&&p(`button`,{className:`btn-sm chat`,onClick:Y,title:n(`schedules.card.openChatTitle`),children:[l(m,{size:11}),` `,n(`schedules.card.openChat`)]}),p(`button`,{className:`btn-sm`,onClick:q,disabled:e.running,title:n(`schedules.card.runNowTitle`),children:[l(h,{size:11}),` `,n(e.running?`schedules.card.running`:`schedules.card.runNow`)]}),l(`button`,{className:`btn-sm`,onClick:K,title:n(e.status===`active`?`schedules.card.pause`:`schedules.card.resume`),children:e.status===`active`?p(a.Fragment,{children:[l(T,{size:11}),` `,n(`schedules.card.pause`)]}):p(a.Fragment,{children:[l(D,{size:11}),` `,n(`schedules.card.resume`)]})}),p(`button`,{className:`btn-sm danger`,onClick:J,title:n(`schedules.card.delete`),children:[l(x,{size:11}),` `,n(I?`schedules.card.confirmDelete`:`schedules.card.delete`)]})]}),P&&p(`div`,{className:`schedule-results`,children:[l(`h4`,{children:n(`schedules.history`)}),y?l(`p`,{className:`schedule-results-empty`,children:n(`schedules.historyLoading`)}):v.length===0?l(`p`,{className:`schedule-results-empty`,children:n(`schedules.historyEmpty`)}):l(`div`,{className:`schedule-results-list`,children:v.map(e=>p(`div`,{className:`schedule-result-item`,children:[l(`div`,{className:`schedule-result-time`,children:n.compose(t=>j(e.executed_at,t,void 0,f(n)))}),e.error?l(`div`,{className:`schedule-result-content schedule-result-error`,children:l(`bdi`,{children:e.error})}):l(`div`,{className:`schedule-result-content`,children:e.result?l(`bdi`,{children:e.result}):n(`schedules.noOutput`)})]},e.id))})]})]})}function W(){let e=i(),{setShowSchedules:n}=o(),{schedules:r,loading:c,error:u,actionError:d,loadSchedules:m,createSchedule:h,dismissActionError:x}=S(),T=(0,O.useCallback)(()=>n(!1),[n]);b(!0,T);let E=(0,O.useRef)(null);v(E,!0),w(E,!0);let[D,k]=(0,O.useState)(!1),[A,j]=(0,O.useState)(``),[M,N]=(0,O.useState)(``),[I,L]=(0,O.useState)(``),[R,z]=(0,O.useState)(null),[B,W]=(0,O.useState)(!1),[G,K]=(0,O.useState)(!1),[q,J]=(0,O.useState)(null),Y=(0,O.useId)(),X=`${Y}-when`,ee=`${Y}-when-error`,te=`${Y}-name`,ne=`${Y}-prompt`,re=!B&&R!==null&&!R.valid,Z=(0,O.useRef)(null);(0,O.useEffect)(()=>{if(!A.trim())z(null);else return Z.current&&clearTimeout(Z.current),Z.current=window.setTimeout(async()=>{W(!0);try{let e=await g(A);z(e)}catch{z(null)}finally{W(!1)}},400),()=>{Z.current&&clearTimeout(Z.current)}},[A]);let Q=(0,O.useRef)(null);(0,O.useEffect)(()=>(t.ui.info(`Schedule Manager opened`),m(),Q.current=window.setInterval(()=>m(),5e3),()=>{Q.current&&clearInterval(Q.current),x()}),[m,x]);let $=A.trim()&&M.trim()&&I.trim()&&(R===null||R.valid),ie=(0,O.useCallback)(async()=>{if($){K(!0),J(null);try{await h(M.trim(),A.trim(),I.trim()),j(``),N(``),L(``),z(null),k(!1),t.ui.info(`Schedule "${M}" created`)}catch(t){J(t instanceof Error?t.message:e(`schedules.createFailed`))}finally{K(!1)}}},[$,M,A,I,h,e]);return l(`div`,{ref:E,className:`modal-overlay`,onClick:()=>n(!1),role:`dialog`,"aria-modal":`true`,"aria-label":e(`schedules.title`),children:p(`div`,{className:`modal-panel schedule-modal`,onClick:e=>e.stopPropagation(),children:[p(`div`,{className:`modal-header`,children:[l(`h3`,{children:e(`schedules.title`)}),l(`button`,{className:`btn-icon`,onClick:()=>n(!1),"aria-label":e(`schedules.close`),children:l(C,{size:18})})]}),p(`div`,{className:`modal-body`,children:[l(`section`,{className:`schedule-section`,children:D?p(`div`,{className:`schedule-create-form`,children:[p(`div`,{className:`schedule-field`,children:[l(`label`,{className:`schedule-field-label`,htmlFor:X,children:e(`schedules.when`)}),l(`textarea`,{id:X,className:`schedule-nl-input`,placeholder:e.bare(`schedules.whenPlaceholder`),value:A,onChange:e=>j(e.target.value),"aria-invalid":re,"aria-describedby":re?ee:void 0,autoFocus:!0,rows:2})]}),(R||B)&&l(`div`,{className:`schedule-parsed-preview ${R?.valid?`valid`:`invalid`}`,"aria-live":`polite`,children:B?l(`span`,{className:`schedule-parsed-loading`,children:e(`schedules.parsing`)}):R?p(a.Fragment,{children:[R.valid?l(`div`,{className:`schedule-parsed-description`,children:V(R.description_parts,e)??l(`bdi`,{children:R.description})}):p(`div`,{id:ee,children:[l(`div`,{className:`schedule-parsed-description`,children:e(`schedules.notUnderstood`)}),l(`div`,{className:`schedule-parsed-hint`,children:l(`bdi`,{children:R.description})})]}),R.valid&&R.next_run_at&&l(`div`,{className:`schedule-parsed-next`,children:e(`schedules.nextRun`,{when:new Date(R.next_run_at).toLocaleString(f(e))})}),R.valid&&p(`div`,{className:`schedule-parsed-details`,children:[R.time_of_day&&p(`span`,{className:`schedule-parsed-tag`,children:[l(_,{size:10}),` `,F(R.time_of_day,e)]}),R.start_hour!=null&&R.end_hour!=null&&p(`span`,{className:`schedule-parsed-tag`,children:[l(_,{size:10}),` `,e.compose((e,t)=>e(`schedules.hours`,{start:P(s(t),R.start_hour),end:P(s(t),R.end_hour)}))]}),R.days_of_week&&l(`span`,{className:`schedule-parsed-tag`,children:e.compose(e=>H(R.days_of_week,e))})]})]}):null}),p(`div`,{className:`schedule-field`,children:[l(`label`,{className:`schedule-field-label`,htmlFor:te,children:e(`schedules.name`)}),l(`div`,{className:`schedule-form-row`,children:l(`input`,{id:te,type:`text`,placeholder:e(`schedules.namePlaceholder`),value:M,onChange:e=>N(e.target.value),className:!M.trim()&&A.trim()?`schedule-field-missing`:``})})]}),p(`div`,{className:`schedule-field`,children:[l(`label`,{className:`schedule-field-label`,htmlFor:ne,children:e(`schedules.prompt`)}),l(`textarea`,{id:ne,className:`schedule-prompt-input ${!I.trim()&&A.trim()?`schedule-field-missing`:``}`,placeholder:e(`schedules.promptPlaceholder`),value:I,onChange:e=>L(e.target.value)})]}),q&&l(`p`,{className:`schedule-form-error`,children:l(`bdi`,{children:q})}),p(`div`,{className:`schedule-create-actions`,children:[l(`button`,{className:`btn-secondary`,onClick:()=>{k(!1),J(null),z(null),j(``),N(``),L(``)},children:e(`schedules.cancel`)}),l(`button`,{className:`btn-primary`,onClick:ie,disabled:!$||G,children:e(G?`schedules.creating`:`schedules.create`)})]})]}):p(`button`,{className:`btn-primary`,onClick:()=>k(!0),children:[l(y,{size:14}),` `,e(`schedules.new`)]})}),p(`section`,{className:`schedule-section`,children:[l(`h4`,{children:e(`schedules.list`)}),d&&p(`div`,{className:`schedule-action-error`,role:`alert`,children:[l(`span`,{children:l(`bdi`,{children:d})}),l(`button`,{className:`btn-icon`,onClick:x,"aria-label":e(`schedules.dismissError`),children:l(C,{size:14})})]}),c?l(`p`,{className:`schedule-empty`,children:e(`schedules.loading`)}):u?l(`p`,{className:`schedule-empty`,children:e(`schedules.loadFailed`)}):r.length===0?l(`p`,{className:`schedule-empty`,children:e(`schedules.empty`)}):l(`div`,{className:`schedule-list`,children:r.map(e=>l(U,{schedule:e},e.id))})]})]})]})})}export{W as ScheduleManager};
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{I as t,J as n,P as r,a as i,c as a,f as o,i as s,k as c,l,q as u,r as d,t as f,u as p}from"./useT-9bLwAbF7.js";import{n as m,t as h}from"./zap-gjTc4oQN.js";import{xt as g}from"./api-c2Hja8UA.js";import{It as _,X as v,_t as y,at as b,dt as x,n as S,ot as C,u as w,yt as T}from"./index-BSZT2AHb.js";var E={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]};E.node;var D=u(E),O=e(n(),1),k=8e3,A={active:`schedules.status.active`,paused:`schedules.status.paused`,cancelled:`schedules.status.cancelled`};function j(e,t,n,r){if(!e)return t(`schedules.time.never`);let i=new Date(e),a=(n||new Date).getTime()-i.getTime(),o=Math.floor(a/1e3);if(o<0){let e=Math.abs(o);if(e<60)return t(`schedules.time.inSeconds`,{n:e});let n=Math.floor(e/60);if(n<60)return t(`schedules.time.inMinutes`,{n});let r=Math.floor(n/60);return r<24?t(`schedules.time.inHours`,{n:r}):t(`schedules.time.inDays`,{n:Math.floor(r/24)})}if(o<60)return t(`time.justNow`);let s=Math.floor(o/60);if(s<60)return t(`time.minutesAgo`,{n:s});let c=Math.floor(s/60);return c<24?t(`time.hoursAgo`,{n:c}):i.toLocaleDateString(r,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function M(e,t,n=d.bare,r){if(!e)return n(`schedules.time.never`);let i=j(e,n,t,r),a=new Date(e);return a.getTime()<=(t||new Date).getTime()?i:n(`schedules.time.clockIn`,{clock:a.toLocaleString(r,{weekday:`short`,hour:`numeric`,minute:`2-digit`}),relative:i})}function N(e){if(!e)return!1;let t=new Date(e).getTime()-Date.now();return t>0&&t<6e4}function P(e,t,n=0){let r=new Date(2e3,0,1,t,n);return new Intl.DateTimeFormat(f(e),{hour:`numeric`,minute:`2-digit`}).format(r)}function F(e,t){let[n,r]=e.split(`:`).map(Number);return P(t,n,r)}function I(e,t,n){let r=`${e}.${new Intl.PluralRules(n.locale).select(t)}`;return c(r)?r:null}var L=e=>e.length===5&&e.every(e=>e<5),R=e=>e.length===2&&e.includes(5)&&e.includes(6);function z(e,t,n){if(L(e))return n(`schedules.desc.days.weekdays`);if(R(e))return n(`schedules.desc.days.weekends`);if(e.length===7)return n(`schedules.desc.days.every`);let r=I(`schedules.desc.dayList`,e.length,t);return r?n(r,{days:e.map(e=>n(`schedules.dayName.${e}`)).join(n(`schedules.desc.dayJoin`))}):null}function B(e,t,n,r){let{kind:i,count:a,unit:o,days:s,time:c,start_hour:l,end_hour:u}=e,d=e=>c?n(`schedules.desc.at`,{when:e,time:F(c,r)}):e;if(i===`every`||i===`window`){let e=a&&o?I(`schedules.span.${o}`,a,t):null,c=s?z(s,t,n):void 0;if(!e||c===null)return null;let d=n(e,{n:a});if(i===`every`)return c?n(`schedules.desc.everyOn`,{span:d,days:c}):n(`schedules.desc.every`,{span:d});if(l==null||u==null)return null;let f=n(`schedules.hours`,{start:P(r,l),end:P(r,u)});return c?n(`schedules.desc.windowOn`,{span:d,hours:f,days:c}):n(`schedules.desc.window`,{span:d,hours:f})}if(i===`daily`)return c?d(n(`schedules.desc.daily`)):null;if(i!==`days`||!s?.length)return null;if(s.length===7)return d(n(`schedules.desc.daily`));if(L(s))return d(n(`schedules.desc.weekdays`));if(R(s))return d(n(`schedules.desc.weekends`));let f=z(s,t,n);return f&&d(n(`schedules.desc.onDays`,{days:f}))}function V(e,t){return!e||B(e,t,t.bare,t)===null?null:t.compose((n,r)=>B(e,t,n,s(r))??``)}function H(e,t){return e.length===5&&!e.includes(5)&&!e.includes(6)?t(`schedules.days.weekdays`):e.length===2&&e.includes(5)&&e.includes(6)?t(`schedules.days.weekends`):e.length===7?t(`schedules.days.every`):e.map(e=>t(`schedules.day.${e}`)).join(t(`schedules.days.join`))}function U({schedule:e}){let n=i(),{selectedSchedule:s,selectSchedule:c,updateScheduleStatus:u,runScheduleNow:d,deleteSchedule:g,results:v,resultsLoading:y,loadSchedules:b,loadResults:C}=S(),{setCurrentSession:w,setShowSchedules:E}=o(),P=s===e.name,F=V(e.description_parts,n),[I,L]=(0,O.useState)(!1),R=(0,O.useRef)(null),z=(0,O.useCallback)(()=>{R.current&&=(clearTimeout(R.current),null)},[]);(0,O.useEffect)(()=>z,[z]);let[B,H]=(0,O.useState)(()=>new Date),U=(0,O.useRef)(null);(0,O.useEffect)(()=>{let t=e.status===`active`&&N(e.next_run_at);return t&&!U.current?U.current=setInterval(()=>{H(new Date),e.next_run_at&&new Date(e.next_run_at).getTime()<=Date.now()&&b()},1e3):!t&&U.current&&(clearInterval(U.current),U.current=null),()=>{U.current&&=(clearInterval(U.current),null)}},[e.status,e.next_run_at,b]);let W=(0,O.useRef)(e.last_run_at);(0,O.useEffect)(()=>{P&&e.last_run_at!==W.current&&(W.current=e.last_run_at,C(e.name))},[P,e.last_run_at,e.name,C]);let G=e.last_run_at&&Date.now()-new Date(e.last_run_at).getTime()<5e3,K=(0,O.useCallback)(n=>{n.stopPropagation();let r=e.status===`active`?`paused`:`active`;t.ui.info(`Schedule "${e.name}": ${e.status} -> ${r}`),u(e.name,r)},[e.name,e.status,u]),q=(0,O.useCallback)(n=>{n.stopPropagation(),t.ui.info(`Schedule "${e.name}": run now`),d(e.name)},[e.name,d]),J=(0,O.useCallback)(n=>{n.stopPropagation(),z(),I?(t.ui.info(`Deleting schedule "${e.name}"`),g(e.name)):(L(!0),R.current=setTimeout(()=>{R.current=null,L(!1)},k))},[e.name,I,g,z]),Y=(0,O.useCallback)(n=>{n.stopPropagation(),e.session_id&&(t.ui.info(`Opening chat session for schedule "${e.name}"`),w(e.session_id),E(!1))},[e.session_id,e.name,w,E]);return p(`div`,{className:`schedule-card ${P?`selected`:``} ${G?`just-ran`:``}`,onClick:()=>c(P?null:e.name),children:[p(`div`,{className:`schedule-card-header`,children:[l(`span`,{className:`schedule-card-name`,dir:`auto`,children:e.name}),l(`span`,{className:`schedule-card-status ${e.status}`,children:n(A[e.status])})]}),l(`div`,{className:`schedule-card-prompt`,dir:`auto`,children:e.prompt}),p(`div`,{className:`schedule-card-meta`,children:[p(`span`,{title:r(F??e.description),children:[l(_,{size:11}),` `,F??l(`bdi`,{children:e.description})]}),l(`span`,{children:n(`schedules.card.runs`,{n:e.run_count})}),e.error_count>0&&l(`span`,{children:n(`schedules.card.errors`,{n:e.error_count})}),l(`span`,{children:n.compose(t=>t(`schedules.card.last`,{when:j(e.last_run_at,t,void 0,f(n))}))}),l(`span`,{children:n.compose(t=>t(`schedules.card.next`,{when:M(e.next_run_at,B,t,f(n))}))})]}),e.last_error&&l(`div`,{className:`schedule-card-error`,children:n(`schedules.card.lastFailed`,{error:e.last_error})}),p(`div`,{className:`schedule-card-actions`,children:[e.session_id&&p(`button`,{className:`btn-sm chat`,onClick:Y,title:n(`schedules.card.openChatTitle`),children:[l(m,{size:11}),` `,n(`schedules.card.openChat`)]}),p(`button`,{className:`btn-sm`,onClick:q,disabled:e.running,title:n(`schedules.card.runNowTitle`),children:[l(h,{size:11}),` `,n(e.running?`schedules.card.running`:`schedules.card.runNow`)]}),l(`button`,{className:`btn-sm`,onClick:K,title:n(e.status===`active`?`schedules.card.pause`:`schedules.card.resume`),children:e.status===`active`?p(a.Fragment,{children:[l(T,{size:11}),` `,n(`schedules.card.pause`)]}):p(a.Fragment,{children:[l(D,{size:11}),` `,n(`schedules.card.resume`)]})}),p(`button`,{className:`btn-sm danger`,onClick:J,title:n(`schedules.card.delete`),children:[l(x,{size:11}),` `,n(I?`schedules.card.confirmDelete`:`schedules.card.delete`)]})]}),P&&p(`div`,{className:`schedule-results`,children:[l(`h4`,{children:n(`schedules.history`)}),y?l(`p`,{className:`schedule-results-empty`,children:n(`schedules.historyLoading`)}):v.length===0?l(`p`,{className:`schedule-results-empty`,children:n(`schedules.historyEmpty`)}):l(`div`,{className:`schedule-results-list`,children:v.map(e=>p(`div`,{className:`schedule-result-item`,children:[l(`div`,{className:`schedule-result-time`,children:n.compose(t=>j(e.executed_at,t,void 0,f(n)))}),e.error?l(`div`,{className:`schedule-result-content schedule-result-error`,children:l(`bdi`,{children:e.error})}):l(`div`,{className:`schedule-result-content`,children:e.result?l(`bdi`,{children:e.result}):n(`schedules.noOutput`)})]},e.id))})]})]})}function W(){let e=i(),{setShowSchedules:n}=o(),{schedules:r,loading:c,error:u,actionError:d,loadSchedules:m,createSchedule:h,dismissActionError:x}=S(),T=(0,O.useCallback)(()=>n(!1),[n]);b(!0,T);let E=(0,O.useRef)(null);v(E,!0),w(E,!0);let[D,k]=(0,O.useState)(!1),[A,j]=(0,O.useState)(``),[M,N]=(0,O.useState)(``),[I,L]=(0,O.useState)(``),[R,z]=(0,O.useState)(null),[B,W]=(0,O.useState)(!1),[G,K]=(0,O.useState)(!1),[q,J]=(0,O.useState)(null),Y=(0,O.useId)(),X=`${Y}-when`,ee=`${Y}-when-error`,te=`${Y}-name`,ne=`${Y}-prompt`,re=!B&&R!==null&&!R.valid,Z=(0,O.useRef)(null);(0,O.useEffect)(()=>{if(!A.trim())z(null);else return Z.current&&clearTimeout(Z.current),Z.current=window.setTimeout(async()=>{W(!0);try{let e=await g(A);z(e)}catch{z(null)}finally{W(!1)}},400),()=>{Z.current&&clearTimeout(Z.current)}},[A]);let Q=(0,O.useRef)(null);(0,O.useEffect)(()=>(t.ui.info(`Schedule Manager opened`),m(),Q.current=window.setInterval(()=>m(),5e3),()=>{Q.current&&clearInterval(Q.current),x()}),[m,x]);let $=A.trim()&&M.trim()&&I.trim()&&(R===null||R.valid),ie=(0,O.useCallback)(async()=>{if($){K(!0),J(null);try{await h(M.trim(),A.trim(),I.trim()),j(``),N(``),L(``),z(null),k(!1),t.ui.info(`Schedule "${M}" created`)}catch(t){J(t instanceof Error?t.message:e(`schedules.createFailed`))}finally{K(!1)}}},[$,M,A,I,h,e]);return l(`div`,{ref:E,className:`modal-overlay`,onClick:()=>n(!1),role:`dialog`,"aria-modal":`true`,"aria-label":e(`schedules.title`),children:p(`div`,{className:`modal-panel schedule-modal`,onClick:e=>e.stopPropagation(),children:[p(`div`,{className:`modal-header`,children:[l(`h3`,{children:e(`schedules.title`)}),l(`button`,{className:`btn-icon`,onClick:()=>n(!1),"aria-label":e(`schedules.close`),children:l(C,{size:18})})]}),p(`div`,{className:`modal-body`,children:[l(`section`,{className:`schedule-section`,children:D?p(`div`,{className:`schedule-create-form`,children:[p(`div`,{className:`schedule-field`,children:[l(`label`,{className:`schedule-field-label`,htmlFor:X,children:e(`schedules.when`)}),l(`textarea`,{id:X,className:`schedule-nl-input`,placeholder:e.bare(`schedules.whenPlaceholder`),value:A,onChange:e=>j(e.target.value),"aria-invalid":re,"aria-describedby":re?ee:void 0,autoFocus:!0,rows:2})]}),(R||B)&&l(`div`,{className:`schedule-parsed-preview ${R?.valid?`valid`:`invalid`}`,"aria-live":`polite`,children:B?l(`span`,{className:`schedule-parsed-loading`,children:e(`schedules.parsing`)}):R?p(a.Fragment,{children:[R.valid?l(`div`,{className:`schedule-parsed-description`,children:V(R.description_parts,e)??l(`bdi`,{children:R.description})}):p(`div`,{id:ee,children:[l(`div`,{className:`schedule-parsed-description`,children:e(`schedules.notUnderstood`)}),l(`div`,{className:`schedule-parsed-hint`,children:l(`bdi`,{children:R.description})})]}),R.valid&&R.next_run_at&&l(`div`,{className:`schedule-parsed-next`,children:e(`schedules.nextRun`,{when:new Date(R.next_run_at).toLocaleString(f(e))})}),R.valid&&p(`div`,{className:`schedule-parsed-details`,children:[R.time_of_day&&p(`span`,{className:`schedule-parsed-tag`,children:[l(_,{size:10}),` `,F(R.time_of_day,e)]}),R.start_hour!=null&&R.end_hour!=null&&p(`span`,{className:`schedule-parsed-tag`,children:[l(_,{size:10}),` `,e.compose((e,t)=>e(`schedules.hours`,{start:P(s(t),R.start_hour),end:P(s(t),R.end_hour)}))]}),R.days_of_week&&l(`span`,{className:`schedule-parsed-tag`,children:e.compose(e=>H(R.days_of_week,e))})]})]}):null}),p(`div`,{className:`schedule-field`,children:[l(`label`,{className:`schedule-field-label`,htmlFor:te,children:e(`schedules.name`)}),l(`div`,{className:`schedule-form-row`,children:l(`input`,{id:te,type:`text`,placeholder:e(`schedules.namePlaceholder`),value:M,onChange:e=>N(e.target.value),className:!M.trim()&&A.trim()?`schedule-field-missing`:``})})]}),p(`div`,{className:`schedule-field`,children:[l(`label`,{className:`schedule-field-label`,htmlFor:ne,children:e(`schedules.prompt`)}),l(`textarea`,{id:ne,className:`schedule-prompt-input ${!I.trim()&&A.trim()?`schedule-field-missing`:``}`,placeholder:e(`schedules.promptPlaceholder`),value:I,onChange:e=>L(e.target.value)})]}),q&&l(`p`,{className:`schedule-form-error`,children:l(`bdi`,{children:q})}),p(`div`,{className:`schedule-create-actions`,children:[l(`button`,{className:`btn-secondary`,onClick:()=>{k(!1),J(null),z(null),j(``),N(``),L(``)},children:e(`schedules.cancel`)}),l(`button`,{className:`btn-primary`,onClick:ie,disabled:!$||G,children:e(G?`schedules.creating`:`schedules.create`)})]})]}):p(`button`,{className:`btn-primary`,onClick:()=>k(!0),children:[l(y,{size:14}),` `,e(`schedules.new`)]})}),p(`section`,{className:`schedule-section`,children:[l(`h4`,{children:e(`schedules.list`)}),d&&p(`div`,{className:`schedule-action-error`,role:`alert`,children:[l(`span`,{children:l(`bdi`,{children:d})}),l(`button`,{className:`btn-icon`,onClick:x,"aria-label":e(`schedules.dismissError`),children:l(C,{size:14})})]}),c?l(`p`,{className:`schedule-empty`,children:e(`schedules.loading`)}):u?l(`p`,{className:`schedule-empty`,children:e(`schedules.loadFailed`)}):r.length===0?l(`p`,{className:`schedule-empty`,children:e(`schedules.empty`)}):l(`div`,{className:`schedule-list`,children:r.map(e=>l(U,{schedule:e},e.id))})]})]})]})})}export{W as ScheduleManager};
@@ -1,4 +1,4 @@
1
- import{I as e,o as t}from"./useT-BNShbVIz.js";var n=`gaia:draft:`,r=e=>`chat:${e}`,i=`new-chat`;function a(t){try{return localStorage.getItem(n+t)??``}catch(n){return e.ui.warn(`Couldn't read the saved draft for ${t}`,n),``}}function o(t,r){try{r?localStorage.setItem(n+t,r):localStorage.removeItem(n+t)}catch(n){e.ui.warn(`Couldn't save the draft for ${t}`,n)}}function s(e){o(e,``)}function c(e){if(!(e instanceof L)||e.httpStatus!==409||!e.body)return null;let{code:t,acknowledge:n}=e.body;return(t===`no_fit`||t===`low_disk`)&&typeof n==`string`?e.body:null}async function l(){return V(`GET`,`/onboarding/preflight`)}async function u(e=!1){return V(`GET`,`/setup/check?skip_chat_model=${e}`)}async function d(e,t=!1,n={}){return V(`POST`,`/setup/run`,{skip_chat_model:e,gaia_lemonade:t,acknowledge_low_disk:!!n.acknowledgeLowDisk,keep_trying:!!n.keepTrying,extra_models:n.extraModels??[],server_only:!!n.serverOnly,upgrade_embedded:!!n.upgradeEmbedded})}async function f(e){return V(`POST`,`/setup/cancel`,e?{model_id:e}:void 0)}async function p(e,t){return V(`POST`,`/setup/models/skip`,{model_id:e,skipped:t})}async function m(e,t={}){return V(`POST`,`/setup/models/download`,{model_id:e,acknowledge_low_disk:!!t.acknowledgeLowDisk,keep_trying:!!t.keepTrying})}async function h(e){return V(`POST`,`/setup/models/remove`,{model_id:e})}async function g(){return V(`GET`,`/setup/status`)}async function ee(){return V(`GET`,`/setup/plan`)}async function te(e,t=!1){return V(`POST`,`/setup/chat-model`,{model_id:e,acknowledge_no_fit:t})}async function ne(){return V(`POST`,`/setup/npu/recheck`)}async function re(){return V(`POST`,`/setup/npu/memlock-fix`)}async function ie(e){return V(`POST`,`/setup/vision-model`,{model_id:e})}async function ae(e){return V(`GET`,`/setup/needs/${e}`)}async function oe(e){return V(`GET`,e==null?`/gpu-memory`:`/gpu-memory?setting_gb=${e}`)}async function se(e){return V(`POST`,`/gpu-memory/apply`,{setting_gb:e,confirm:!0})}async function ce(){return V(`POST`,`/gpu-memory/revert`,{confirm:!0})}async function le(e){return V(`POST`,`/gpu-memory/pending`,{setting_gb:e})}async function ue(){return V(`DELETE`,`/gpu-memory/pending`)}async function de(){return V(`GET`,`/onboarding/start`)}async function fe(){return V(`POST`,`/setup/report`)}async function pe(e){let n=await fetch(`${t()}/setup/report/${encodeURIComponent(e)}`,{headers:B});if(!n.ok)throw new L(`Couldn't read the report (HTTP ${n.status}).`,n.status,await n.text().catch(()=>``),null);return n.blob()}async function me(){return V(`GET`,`/connectors`)}async function he(e){return V(`GET`,`/connectors/${e}`)}async function ge(e,t,n=[]){return V(`POST`,`/connectors/${e}/authorize`,{scopes:t,grant_agents:n},B)}async function _e(e,t,n=[]){return V(`POST`,`/connectors/${e}/authorize-device`,{scopes:t,grant_agents:n},B)}async function ve(e,t){return V(`POST`,`/connectors/${e}/configure`,{config:t},B)}async function ye(e){return V(`POST`,`/connectors/${e}/test`,void 0,B)}async function _(e){await V(`DELETE`,`/connectors/${e}`,void 0,B)}async function v(e){return V(`POST`,`/connectors/${e}/enable`,{},B)}async function y(e){return V(`POST`,`/connectors/${e}/disable`,{},B)}async function b(){return V(`GET`,`/connectors/agent-mcps`)}async function x(e){return V(`GET`,`/connectors/${e}/grants`)}async function S(e,t,n){await V(`PUT`,`/connectors/${e}/grants/${encodeURIComponent(t)}`,{scopes:n},B)}async function C(e,t){await V(`DELETE`,`/connectors/${e}/grants/${encodeURIComponent(t)}`,void 0,B)}async function w(e){return V(`GET`,`/connectors/${e}/activations`)}async function T(e,t,n){return V(`PUT`,`/connectors/${e}/activations/${encodeURIComponent(t)}`,n?{scopes:n}:{},B)}async function E(e,t){await V(`DELETE`,`/connectors/${e}/activations/${encodeURIComponent(t)}`,void 0,B)}async function D(e){return V(`POST`,`/chat/cancel`,{session_id:e})}async function O(e,t){return V(`POST`,`/chat/followup`,{session_id:e,text:t})}async function k(e){return V(`GET`,`/chat/followup/${encodeURIComponent(e)}`)}async function A(e){return V(`GET`,`/chat/context/${encodeURIComponent(e)}`)}async function j(e){return V(`GET`,`/chat/performance/${encodeURIComponent(e)}`)}async function M(e,t,n){return V(`POST`,`/chat/retry-with`,{session_id:e,message_id:t,model:n})}async function N(e,t,n){return V(`POST`,`/chat/retry-with/choose`,{session_id:e,message_id:t,keep:n})}async function P(){return V(`GET`,`/chat/active`)}async function be(e,t,n={}){return V(`POST`,`/chat/confirm-tool`,{session_id:e,approved:t,always:n.always??!1,...n.confirmId?{confirm_id:n.confirmId}:{}})}async function xe(e,t,n){return V(`POST`,`/chat/user-input`,{session_id:e,request_id:t,value:n})}async function Se(e){return V(`GET`,`/chat/permissions/${encodeURIComponent(e)}`)}async function Ce(){return V(`GET`,`/chat/permissions`)}async function we(e){return V(`PUT`,`/chat/permissions`,{mode:e})}async function Te(e,t){return V(`PUT`,`/chat/permissions/${encodeURIComponent(e)}`,{mode:t})}async function Ee(e,t){let n=t?`?key=${encodeURIComponent(t)}`:``;return V(`DELETE`,`/chat/permissions/${encodeURIComponent(e)}/grants${n}`)}function F(e){try{let t=JSON.parse(e).detail;return Array.isArray(t)?t.map(e=>e?.msg??JSON.stringify(e)).join(`; `)||e:t&&typeof t==`object`&&typeof t.message==`string`?t.message:t&&typeof t!=`string`?JSON.stringify(t):t||e}catch{return e}}function I(e){try{let t=JSON.parse(e).detail?.status;return typeof t==`string`?t:null}catch{return null}}function De(e){try{let t=JSON.parse(e).detail;return Array.isArray(t)?t.map(e=>Array.isArray(e?.loc)?e.loc[e.loc.length-1]:void 0).filter(e=>typeof e==`string`):[]}catch{return[]}}function Oe(e){try{let t=JSON.parse(e).detail;return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}var L=class extends Error{httpStatus;detail;reason;fields;body;constructor(e,t,n,r,i=[],a=null){super(e),this.name=`ApiError`,this.httpStatus=t,this.detail=n,this.reason=r,this.fields=i,this.body=a}};function R(e){return e.trim().toLowerCase()===`internal server error`}function ke(e){let t=e.trim();return t!==``&&!R(t)&&!/^[<{[]/.test(t)}function z(e,t){switch(e){case 403:return t||`Access denied.`;case 404:return t||`The requested item was not found.`;case 413:return t||`File too large to process.`;case 500:return ke(t)?t:`Server error. Please try again.`;case 502:return`Service unavailable. Is the backend running?`;case 503:return t||`Service unavailable.`;default:return t||`Request failed (HTTP ${e})`}}var B={"x-gaia-ui":`1`,"x-gaia-client":`agent-ui`},Ae=/key|token|secret|password/i;function je(e){return!e||typeof e!=`object`||Array.isArray(e)?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Ae.test(e)&&typeof t==`string`&&t?`***`:t]))}async function V(n,r,i,a,o){let s=`${t()}${r}`,c=e.api.time();e.api.info(`${n} ${s}`,i===void 0?``:{body:je(i)});let l=i===void 0?{}:{"Content-Type":`application/json`},u={method:n,headers:{...B,...a,...l},body:i===void 0?void 0:JSON.stringify(i),signal:o},d;try{d=await fetch(s,u)}catch(t){throw e.api.error(`${n} ${s} - network error`,t),t}if(!d.ok){let t=await d.text().catch(()=>``);e.api.error(`${n} ${s} - HTTP ${d.status}`,{errorText:t});let r=F(t);throw new L(z(d.status,r),d.status,r,I(t),De(t),Oe(t))}let f=d.headers.get(`content-type`)||``;if(!f.includes(`application/json`)){let t=await d.text().catch(()=>``);if(d.status===204||t.trim()===``){e.api.timed(`${n} ${s} -> ${d.status} (no body)`,c);return}throw e.api.error(`${n} ${s} -> ${d.status} (non-JSON body)`,{contentType:f,preview:t.slice(0,200)}),Error(`${n} ${r}: expected JSON, got ${f||`no Content-Type`} (HTTP ${d.status}: ${t.slice(0,120)})`)}let p=await d.json();return e.api.timed(`${n} ${s} -> ${d.status}`,c,p),p}async function Me(e){return V(`GET`,`/system/status`,void 0,void 0,e)}async function Ne(e){return V(`GET`,`/system/resources`,void 0,void 0,e)}async function Pe(e=!1){return V(`POST`,e?`/system/warm-up?fresh=true`:`/system/warm-up`)}async function Fe(){return V(`GET`,`/system/warm-up`)}async function Ie(){return V(`GET`,`/system/model-server`)}async function Le(e){return V(`PUT`,`/system/model-server/backend`,{backend:e})}async function Re(){return V(`GET`,`/settings`)}async function ze(e){return V(`PUT`,`/settings`,e)}async function H(e,t,n=!1){return V(`POST`,`/system/load-model`,{model_name:e,ctx_size:t,force:n})}async function Be(e,t,n=e=>window.confirm(e)){try{return await H(e,t),!0}catch(r){if(!(r instanceof L)||r.httpStatus!==409)throw r;return n(`${r.detail}
1
+ import{I as e,o as t}from"./useT-9bLwAbF7.js";var n=`gaia:draft:`,r=e=>`chat:${e}`,i=`new-chat`;function a(t){try{return localStorage.getItem(n+t)??``}catch(n){return e.ui.warn(`Couldn't read the saved draft for ${t}`,n),``}}function o(t,r){try{r?localStorage.setItem(n+t,r):localStorage.removeItem(n+t)}catch(n){e.ui.warn(`Couldn't save the draft for ${t}`,n)}}function s(e){o(e,``)}function c(e){if(!(e instanceof L)||e.httpStatus!==409||!e.body)return null;let{code:t,acknowledge:n}=e.body;return(t===`no_fit`||t===`low_disk`)&&typeof n==`string`?e.body:null}async function l(){return V(`GET`,`/onboarding/preflight`)}async function u(e=!1){return V(`GET`,`/setup/check?skip_chat_model=${e}`)}async function d(e,t=!1,n={}){return V(`POST`,`/setup/run`,{skip_chat_model:e,gaia_lemonade:t,acknowledge_low_disk:!!n.acknowledgeLowDisk,keep_trying:!!n.keepTrying,extra_models:n.extraModels??[],server_only:!!n.serverOnly,upgrade_embedded:!!n.upgradeEmbedded})}async function f(e){return V(`POST`,`/setup/cancel`,e?{model_id:e}:void 0)}async function p(e,t){return V(`POST`,`/setup/models/skip`,{model_id:e,skipped:t})}async function m(e,t={}){return V(`POST`,`/setup/models/download`,{model_id:e,acknowledge_low_disk:!!t.acknowledgeLowDisk,keep_trying:!!t.keepTrying})}async function h(e){return V(`POST`,`/setup/models/remove`,{model_id:e})}async function g(){return V(`GET`,`/setup/status`)}async function ee(){return V(`GET`,`/setup/plan`)}async function te(e,t=!1){return V(`POST`,`/setup/chat-model`,{model_id:e,acknowledge_no_fit:t})}async function ne(){return V(`POST`,`/setup/npu/recheck`)}async function re(){return V(`POST`,`/setup/npu/memlock-fix`)}async function ie(e){return V(`POST`,`/setup/vision-model`,{model_id:e})}async function ae(e){return V(`GET`,`/setup/needs/${e}`)}async function oe(e){return V(`GET`,e==null?`/gpu-memory`:`/gpu-memory?setting_gb=${e}`)}async function se(e){return V(`POST`,`/gpu-memory/apply`,{setting_gb:e,confirm:!0})}async function ce(){return V(`POST`,`/gpu-memory/revert`,{confirm:!0})}async function le(e){return V(`POST`,`/gpu-memory/pending`,{setting_gb:e})}async function ue(){return V(`DELETE`,`/gpu-memory/pending`)}async function de(){return V(`GET`,`/onboarding/start`)}async function fe(){return V(`POST`,`/setup/report`)}async function pe(e){let n=await fetch(`${t()}/setup/report/${encodeURIComponent(e)}`,{headers:B});if(!n.ok)throw new L(`Couldn't read the report (HTTP ${n.status}).`,n.status,await n.text().catch(()=>``),null);return n.blob()}async function me(){return V(`GET`,`/connectors`)}async function he(e){return V(`GET`,`/connectors/${e}`)}async function ge(e,t,n=[]){return V(`POST`,`/connectors/${e}/authorize`,{scopes:t,grant_agents:n},B)}async function _e(e,t,n=[]){return V(`POST`,`/connectors/${e}/authorize-device`,{scopes:t,grant_agents:n},B)}async function ve(e,t){return V(`POST`,`/connectors/${e}/configure`,{config:t},B)}async function ye(e){return V(`POST`,`/connectors/${e}/test`,void 0,B)}async function _(e){await V(`DELETE`,`/connectors/${e}`,void 0,B)}async function v(e){return V(`POST`,`/connectors/${e}/enable`,{},B)}async function y(e){return V(`POST`,`/connectors/${e}/disable`,{},B)}async function b(){return V(`GET`,`/connectors/agent-mcps`)}async function x(e){return V(`GET`,`/connectors/${e}/grants`)}async function S(e,t,n){await V(`PUT`,`/connectors/${e}/grants/${encodeURIComponent(t)}`,{scopes:n},B)}async function C(e,t){await V(`DELETE`,`/connectors/${e}/grants/${encodeURIComponent(t)}`,void 0,B)}async function w(e){return V(`GET`,`/connectors/${e}/activations`)}async function T(e,t,n){return V(`PUT`,`/connectors/${e}/activations/${encodeURIComponent(t)}`,n?{scopes:n}:{},B)}async function E(e,t){await V(`DELETE`,`/connectors/${e}/activations/${encodeURIComponent(t)}`,void 0,B)}async function D(e){return V(`POST`,`/chat/cancel`,{session_id:e})}async function O(e,t){return V(`POST`,`/chat/followup`,{session_id:e,text:t})}async function k(e){return V(`GET`,`/chat/followup/${encodeURIComponent(e)}`)}async function A(e){return V(`GET`,`/chat/context/${encodeURIComponent(e)}`)}async function j(e){return V(`GET`,`/chat/performance/${encodeURIComponent(e)}`)}async function M(e,t,n){return V(`POST`,`/chat/retry-with`,{session_id:e,message_id:t,model:n})}async function N(e,t,n){return V(`POST`,`/chat/retry-with/choose`,{session_id:e,message_id:t,keep:n})}async function P(){return V(`GET`,`/chat/active`)}async function be(e,t,n={}){return V(`POST`,`/chat/confirm-tool`,{session_id:e,approved:t,always:n.always??!1,...n.confirmId?{confirm_id:n.confirmId}:{}})}async function xe(e,t,n){return V(`POST`,`/chat/user-input`,{session_id:e,request_id:t,value:n})}async function Se(e){return V(`GET`,`/chat/permissions/${encodeURIComponent(e)}`)}async function Ce(){return V(`GET`,`/chat/permissions`)}async function we(e){return V(`PUT`,`/chat/permissions`,{mode:e})}async function Te(e,t){return V(`PUT`,`/chat/permissions/${encodeURIComponent(e)}`,{mode:t})}async function Ee(e,t){let n=t?`?key=${encodeURIComponent(t)}`:``;return V(`DELETE`,`/chat/permissions/${encodeURIComponent(e)}/grants${n}`)}function F(e){try{let t=JSON.parse(e).detail;return Array.isArray(t)?t.map(e=>e?.msg??JSON.stringify(e)).join(`; `)||e:t&&typeof t==`object`&&typeof t.message==`string`?t.message:t&&typeof t!=`string`?JSON.stringify(t):t||e}catch{return e}}function I(e){try{let t=JSON.parse(e).detail?.status;return typeof t==`string`?t:null}catch{return null}}function De(e){try{let t=JSON.parse(e).detail;return Array.isArray(t)?t.map(e=>Array.isArray(e?.loc)?e.loc[e.loc.length-1]:void 0).filter(e=>typeof e==`string`):[]}catch{return[]}}function Oe(e){try{let t=JSON.parse(e).detail;return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}var L=class extends Error{httpStatus;detail;reason;fields;body;constructor(e,t,n,r,i=[],a=null){super(e),this.name=`ApiError`,this.httpStatus=t,this.detail=n,this.reason=r,this.fields=i,this.body=a}};function R(e){return e.trim().toLowerCase()===`internal server error`}function ke(e){let t=e.trim();return t!==``&&!R(t)&&!/^[<{[]/.test(t)}function z(e,t){switch(e){case 403:return t||`Access denied.`;case 404:return t||`The requested item was not found.`;case 413:return t||`File too large to process.`;case 500:return ke(t)?t:`Server error. Please try again.`;case 502:return`Service unavailable. Is the backend running?`;case 503:return t||`Service unavailable.`;default:return t||`Request failed (HTTP ${e})`}}var B={"x-gaia-ui":`1`,"x-gaia-client":`agent-ui`},Ae=/key|token|secret|password/i;function je(e){return!e||typeof e!=`object`||Array.isArray(e)?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Ae.test(e)&&typeof t==`string`&&t?`***`:t]))}async function V(n,r,i,a,o){let s=`${t()}${r}`,c=e.api.time();e.api.info(`${n} ${s}`,i===void 0?``:{body:je(i)});let l=i===void 0?{}:{"Content-Type":`application/json`},u={method:n,headers:{...B,...a,...l},body:i===void 0?void 0:JSON.stringify(i),signal:o},d;try{d=await fetch(s,u)}catch(t){throw e.api.error(`${n} ${s} - network error`,t),t}if(!d.ok){let t=await d.text().catch(()=>``);e.api.error(`${n} ${s} - HTTP ${d.status}`,{errorText:t});let r=F(t);throw new L(z(d.status,r),d.status,r,I(t),De(t),Oe(t))}let f=d.headers.get(`content-type`)||``;if(!f.includes(`application/json`)){let t=await d.text().catch(()=>``);if(d.status===204||t.trim()===``){e.api.timed(`${n} ${s} -> ${d.status} (no body)`,c);return}throw e.api.error(`${n} ${s} -> ${d.status} (non-JSON body)`,{contentType:f,preview:t.slice(0,200)}),Error(`${n} ${r}: expected JSON, got ${f||`no Content-Type`} (HTTP ${d.status}: ${t.slice(0,120)})`)}let p=await d.json();return e.api.timed(`${n} ${s} -> ${d.status}`,c,p),p}async function Me(e){return V(`GET`,`/system/status`,void 0,void 0,e)}async function Ne(e){return V(`GET`,`/system/resources`,void 0,void 0,e)}async function Pe(e=!1){return V(`POST`,e?`/system/warm-up?fresh=true`:`/system/warm-up`)}async function Fe(){return V(`GET`,`/system/warm-up`)}async function Ie(){return V(`GET`,`/system/model-server`)}async function Le(e){return V(`PUT`,`/system/model-server/backend`,{backend:e})}async function Re(){return V(`GET`,`/settings`)}async function ze(e){return V(`PUT`,`/settings`,e)}async function H(e,t,n=!1){return V(`POST`,`/system/load-model`,{model_name:e,ctx_size:t,force:n})}async function Be(e,t,n=e=>window.confirm(e)){try{return await H(e,t),!0}catch(r){if(!(r instanceof L)||r.httpStatus!==409)throw r;return n(`${r.detail}
2
2
 
3
3
  Load ${e} anyway?`)?(await H(e,t,!0),!0):!1}}async function Ve(e,t=!1,n=!1){return V(`POST`,`/system/download-model`,{model_name:e,force:t,load_after:n})}async function He(){return V(`GET`,`/agents`)}async function Ue(e){return V(`POST`,`/agents/install`,{id:e})}async function We(e){return V(`GET`,`/agents/${encodeURIComponent(e)}/install-status`)}async function Ge(){return V(`GET`,`/lemonade/target`)}async function Ke(){return V(`GET`,`/lemonade/detect`)}async function qe(e){try{return await V(`POST`,`/lemonade/target`,e)}catch(e){throw e instanceof L&&e.httpStatus===502&&e.detail?new L(e.detail,e.httpStatus,e.detail,e.reason,e.fields):e}}async function Je(){return V(`GET`,`/providers`)}async function Ye(){return V(`GET`,`/providers/active`)}async function Xe(e,t){return V(`POST`,`/providers/${encodeURIComponent(e)}/connect`,t)}var Ze=2e3;async function Qe(e,t,n,r=()=>!1){for(;;)try{return await Xe(e,t)}catch(e){if(!(e instanceof L)||e.httpStatus!==409||r())throw e;n(e.detail),await new Promise(e=>setTimeout(e,Ze))}}async function $e(e){return V(`DELETE`,`/providers/${encodeURIComponent(e)}/key`)}async function et(e){return V(`GET`,`/providers/${encodeURIComponent(e)}/models`)}async function tt(e){return V(`GET`,`/providers/local/context?model=${encodeURIComponent(e)}`)}async function nt(e,t){return V(`PUT`,`/providers/local/context`,{model:e,ctx_size:t})}async function rt(){return V(`GET`,`/providers/local/status`)}async function it(e=!1){return V(`POST`,`/providers/local/restart`,{confirm:e})}async function at(e){return V(`POST`,`/providers/select`,{model:e})}async function ot(e,t){return V(`POST`,`/providers/local/custom/check`,{url:e,quant:t||null})}async function st(e,t){return V(`POST`,`/providers/local/custom`,{url:e,quant:t||null})}async function ct(e){return V(`DELETE`,`/providers/local/custom/${encodeURIComponent(e)}`)}async function lt(e){return V(`GET`,`/spending/prices/${encodeURIComponent(e)}`)}async function ut(){return V(`GET`,`/spending`)}async function dt(e,t,n){let r=new URLSearchParams({since:t});return n&&r.set(`model`,n),V(`GET`,`/spending/chat/${encodeURIComponent(e)}?${r}`)}async function ft(e){return V(`PUT`,`/spending/limit`,{limit_usd:e})}async function pt(){return V(`POST`,`/spending/allow-month`)}async function mt(){return V(`GET`,`/skills`)}async function ht(){let e=new Map,t=0;for(let n=0;;n+=200){let r=await V(`GET`,`/sessions?limit=200&offset=${n}`);t=r.total;for(let t of r.sessions)e.has(t.id)||e.set(t.id,t);if(r.sessions.length<200||n+200>=t)break}return{sessions:[...e.values()],total:t}}async function gt(e={}){return V(`POST`,`/sessions`,e)}async function _t(e,t){return V(`PUT`,`/sessions/${e}`,t)}async function vt(e){await V(`DELETE`,`/sessions/${e}`),s(r(e))}async function yt(e){return V(`GET`,`/sessions/${e}`)}async function bt(e,t){return V(`PUT`,`/sessions/${e}/pin`,{pinned:t})}async function xt(e,t,n){return V(`GET`,`/sessions/search?${new URLSearchParams({q:e,include_automated:String(t)})}`,void 0,void 0,n)}async function St(e){return V(`POST`,`/sessions/${e}/read`)}async function Ct(e){return V(`PATCH`,`/sessions/${e}/private`)}async function wt(e){let{total:t}=await V(`GET`,`/sessions/${e}/messages?limit=1&offset=0`);return t}async function Tt(e){let t=`/sessions/${e}/messages`,n=await V(`GET`,`${t}?limit=100&offset=0`),r=[...n.messages],i=n.total;for(;r.length<i;){let e=await V(`GET`,`${t}?limit=${Math.min(100,i-r.length)}&offset=${r.length}`);if(e.messages.length===0)throw Error(`Incomplete transcript received. Please reload the conversation.`);r.push(...e.messages)}return{messages:r,total:i}}async function Et(e){return V(`GET`,`/sessions/${e}/export?format=markdown`)}async function Dt(e,t){return V(`DELETE`,`/sessions/${e}/messages/${t}`)}async function Ot(e,t){return V(`DELETE`,`/sessions/${e}/messages/${t}/and-below`)}var kt=new Set([`status`,`step`,`thinking`,`commentary`,`plan`,`tool_start`,`tool_end`,`tool_result`,`tool_args`,`tool_confirm`,`skill_use`,`agent_error`,`permission_request`,`needs_confirmation`,`needs_input`,`policy_alert`,`followup_taken`,`followup_returned`,`followup_unavailable`,`context_usage`]);function At(n,r,i,a,o,s,c){let l;l=typeof i==`function`?{onChunk:i,onAgentEvent:()=>{},onDone:a||(()=>{}),onError:o||(t=>{e.stream.error(`Unhandled stream error`,t)})}:i;let u=new AbortController,d=e.stream.time();e.stream.info(`Starting SSE stream for session=${n}`,{messageLength:r.length});let f=Y(u,l,U,Nt);return fetch(`${t()}/chat/send`,{method:`POST`,headers:{...B,"Content-Type":`application/json`},body:JSON.stringify({session_id:n,message:r,stream:!0,...s?{agent_type:s}:{},...c?{device:c}:{}}),signal:u.signal}).then(e=>(f.received(),f.connected(),X(e,l,d,{silentCloseIsError:!0}))).catch(t=>{f.received(),f.timedOut()?(e.stream.error(`No answer to /chat/send within ${U/1e3}s`),l.onError(new J(`send`,U))):t.name===`AbortError`?e.stream.warn(`Stream aborted by user`):(e.stream.error(`Stream fetch error`,t),l.onError(t))}),u}var jt=3e4,Mt=6e5,U=9e4,Nt=3e3,W=`Waiting for GAIA to start this answer…`,G=3e4,K=class extends Error{idleMs;constructor(e){super(`The connection to GAIA went silent for ${Math.round(e/1e3)} s.`),this.idleMs=e,this.name=`StreamStalledError`}},q=class extends Error{cause;unreachable;constructor(e,t=!1){super(`The connection to GAIA was cut: ${e instanceof Error?e.message:String(e)}`),this.cause=e,this.unreachable=t,this.name=`StreamDroppedError`}},J=class extends Error{endpoint;timeoutMs;constructor(e,t){super(`GAIA did not start answering within ${Math.round(t/1e3)} s.`),this.endpoint=e,this.timeoutMs=t,this.name=`StreamTimeoutError`}};function Y(e,t,n,r){let i=!1,a=r===void 0?void 0:setTimeout(()=>{t.onAgentEvent({type:`status`,status:`working`,phase:`waiting`,message:W})},r),o=setTimeout(()=>{i=!0,e.abort()},n),s=!1;return{received:()=>{clearTimeout(a),clearTimeout(o)},connected:()=>{s||(s=!0,t.onConnected?.())},timedOut:()=>i}}async function Pt(e,t){let n,r=new Promise((e,r)=>{n=setTimeout(()=>r(new K(t)),t)});try{return await Promise.race([e.read(),r])}finally{clearTimeout(n)}}async function X(t,n,r,{silentCloseIsError:i=!1}={}){if(e.stream.info(`SSE connection opened -> HTTP ${t.status}`),!t.ok){let r=await t.text().catch(()=>``);e.stream.error(`SSE connection failed: HTTP ${t.status}`,r);let i=F(r),a=i&&!R(i)?i:z(t.status,i);n.onError(new L(a,t.status,i,I(r)));return}let a=t.body?.getReader();if(!a){e.stream.error(`No response body reader available`),n.onError(Error(`No response body`));return}let o=new TextDecoder,s=``,c=!1,l=0,u=0,d=0,f=!1,p=!1,m=!1;try{for(;;){let t;try{t=await Pt(a,f?Mt:jt)}catch(t){if(t?.name===`AbortError`)throw t;if(!(t instanceof K)){if(e.stream.error(`SSE connection cut mid-stream`,t),c||p)return;if(m)break;throw new q(t)}if(e.stream.error(`SSE stream silent for ${t.idleMs/1e3}s; dropping the connection`),await a.cancel().catch(t=>e.stream.warn(`Could not cancel the stalled stream`,t)),c||p)return;if(m)break;throw t}let{done:i,value:h}=t;if(i){e.stream.debug(`SSE reader done (stream ended)`);break}s+=o.decode(h,{stream:!0});let g=s.split(`
4
4
  `);s=g.pop()||``;for(let t of g)if(t.startsWith(`data: `)){let i=t.slice(6).trim();if(!i)continue;try{let t=JSON.parse(i);if(f=t.type===`status`&&t.phase===`queued`,t.type===`chunk`)l++,u+=(t.content||``).length,(l<=3||l%50==0)&&e.stream.debug(`Chunk #${l} (+${(t.content||``).length} chars)`),n.onChunk(t);else if(t.type===`answer`)n.onChunk(t);else if(t.type===`done`)c=!0,e.stream.timed(`Stream complete: ${l} chunks, ${u} chars, ${d} agent events`,r),n.onDone(t);else if(t.type===`error`)e.stream.error(`Stream error event:`,t.content),p=!0,n.onError(Error(t.content||`Unknown error`));else if(t.type===`agent_created`)e.stream.info(`Agent created: ${t.agent_id}`),n.onAgentCreated?.(t);else if(t.type===`mcp_status`){let n=t.servers??[];e.stream.debug(`MCP status: ${n.length} server(s)`,n);for(let t of n)t.connected||e.stream.warn(`MCP server "${t.name}" is not connected: ${t.error??`no error reported`}`)}else kt.has(t.type)?(d++,t.type===`agent_error`&&!t.recoverable&&(m=!0),e.stream.debug(`Agent event: ${t.type}`,t),n.onAgentEvent(t)):e.stream.warn(`Unknown SSE event type: ${t.type}`,t)}catch{e.stream.warn(`Malformed SSE data, skipping`,{raw:i.slice(0,100)})}}}}finally{a.releaseLock()}if(!c){if(e.stream.timed(`SSE connection closed without done event: ${l} chunks, ${d} agent events`,r),i&&l===0&&d===0&&!p){n.onError(Error(`GAIA closed the connection before any answer arrived. Send the message again; if it keeps happening, check the GAIA server log.`));return}n.onDone({type:`done`})}}function Ft(n,r){let i=new AbortController,a=e.stream.time();e.stream.info(`Attaching to background run for session=${n}`);let o=Y(i,r,G);return fetch(`${t()}/chat/attach?session_id=${encodeURIComponent(n)}`,{method:`GET`,signal:i.signal}).then(t=>{if(o.received(),o.connected(),t.status===404)e.stream.info(`Run for session=${n} finished before the attach`),r.onDone({type:`done`,content:``});else return X(t,r,a)}).catch(t=>{o.received(),o.timedOut()?(e.stream.error(`No answer to /chat/attach within ${G/1e3}s`),r.onError(new J(`attach`,G))):t.name===`AbortError`?e.stream.warn(`Run attach detached by client`):t instanceof TypeError?(e.stream.error(`Run attach could not connect`,t),r.onError(new q(t,!0))):(e.stream.error(`Run attach fetch error`,t),r.onError(t))}),i}async function It(){return V(`GET`,`/documents`)}async function Lt(e){return V(`POST`,`/documents/upload-path`,{filepath:e})}async function Rt(n){let r=`${t()}/documents/upload`,i=e.api.time();e.api.info(`POST ${r}`,{fileName:n.name,size:n.size});let a=new FormData;a.append(`file`,n);let o;try{o=await fetch(r,{method:`POST`,headers:B,body:a})}catch(t){throw e.api.error(`POST ${r} - network error`,t),t}if(!o.ok){let t=await o.text().catch(()=>``);e.api.error(`POST ${r} - HTTP ${o.status}`,{errorText:t});let n=F(t);throw new L(z(o.status,n),o.status,n,I(t))}let s=await o.json();return e.api.timed(`POST ${r} -> ${o.status}`,i,s),s}async function zt(e){return V(`DELETE`,`/documents/${e}`)}async function Bt(e){return V(`GET`,`/documents/${e}/status`)}function Vt(e,n){let r=new URL(`${t()}/documents/${encodeURIComponent(e)}/file`,window.location.href);return n&&(r.hash=`page=${n}`),r.href}async function Ht(e){return V(`POST`,`/documents/${e}/cancel`)}async function Ut(e){return V(`POST`,`/documents/${e}/reindex`)}async function Wt(e,t){return V(`POST`,`/sessions/${e}/documents`,{document_id:t})}async function Gt(e,t){return V(`DELETE`,`/sessions/${e}/documents/${t}`)}async function Kt(e){return V(`GET`,`/files/browse${e?`?path=${encodeURIComponent(e)}`:``}`)}async function qt(e,t=!0){return V(`POST`,`/documents/index-folder`,{folder_path:e,recursive:t})}async function Jt(e,t=!0){return V(`POST`,`/files/open`,{path:e,reveal:t})}async function Yt(e){return V(`POST`,`/files/open`,{path:e,launch:!0})}async function Xt(e){return V(`POST`,`/files/status`,{paths:e})}async function Zt(n){let r=`${t()}/files/upload`,i=e.api.time();e.api.info(`POST ${r}`,{fileName:n.name,size:n.size});let a=new FormData;a.append(`file`,n);let o=await fetch(r,{method:`POST`,headers:B,body:a});if(!o.ok){let t=await o.text().catch(()=>``);e.api.error(`POST ${r} - HTTP ${o.status}`,{errorText:t});let n=F(t);throw new L(z(o.status,n),o.status,n,I(t))}let s=await o.json();return e.api.timed(`POST ${r} -> ${o.status}`,i,s),s}function Qt(n,r,i){let a=`${t()}/files/upload-media?name=${encodeURIComponent(n.name)}`;return e.api.info(`POST ${a}`,{fileName:n.name,size:n.size}),new Promise((t,o)=>{let s=new XMLHttpRequest;s.open(`POST`,a);for(let[e,t]of Object.entries(B))s.setRequestHeader(e,t);s.upload.onprogress=e=>{e.lengthComputable&&r(Math.floor(e.loaded/e.total*100))},s.onerror=()=>o(new L(z(0,`network error`),0,`network error`,null)),s.onabort=()=>o(new DOMException(`Upload cancelled`,`AbortError`)),i?.addEventListener(`abort`,()=>s.abort()),s.onload=()=>{if(s.status>=200&&s.status<300){t(JSON.parse(s.responseText));return}e.api.error(`POST ${a} - HTTP ${s.status}`,{errorText:s.responseText});let n=F(s.responseText);o(new L(z(s.status,n),s.status,n,I(s.responseText)))},s.send(n)})}async function $t(e,t,n){let r=new URLSearchParams({query:e});return t&&r.set(`file_types`,t),n&&r.set(`max_results`,String(n)),V(`GET`,`/files/search?${r}`)}async function en(e,t){let n=new URLSearchParams({path:e});return t&&n.set(`lines`,String(t)),V(`GET`,`/files/preview?${n}`)}async function tn(){return V(`POST`,`/tunnel/start`)}async function nn(){return V(`POST`,`/tunnel/stop`)}async function rn(){return V(`GET`,`/tunnel/status`)}async function an(){return V(`GET`,`/mcp/status`)}async function on(){return V(`GET`,`/schedules`)}function Z(){return Intl.DateTimeFormat().resolvedOptions().timeZone||void 0}async function sn(e,t,n){return V(`POST`,`/schedules`,{name:e,interval:t,prompt:n,timezone:Z()})}async function cn(e,t){return V(`PUT`,`/schedules/${encodeURIComponent(e)}`,{status:t})}async function ln(e){return V(`POST`,`/schedules/${encodeURIComponent(e)}/run`)}async function Q(e){return V(`DELETE`,`/schedules/${encodeURIComponent(e)}`)}async function un(e,t=20){return V(`GET`,`/schedules/${encodeURIComponent(e)}/results?limit=${t}`)}async function dn(e){return V(`POST`,`/schedules/parse`,{input:e,timezone:Z()})}async function fn(e){return V(`GET`,`/sessions/${encodeURIComponent(e)}/changes`)}async function pn(e,t){return V(`GET`,`/sessions/${encodeURIComponent(e)}/changes/${encodeURIComponent(t)}/diff`)}async function mn(e,t,n=!1){return V(`POST`,`/sessions/${encodeURIComponent(e)}/changes/${encodeURIComponent(t)}/undo`,{force:n})}async function hn(){return V(`GET`,`/settings/undo`)}async function gn(e,t){return V(`PUT`,`/settings/undo`,{retention_days:e,max_mb:t})}var $=e=>`/sessions/${encodeURIComponent(e)}`;async function _n(e){return V(`GET`,`${$(e)}/environment`)}async function vn(e,t){return V(`POST`,`${$(e)}/environment/folders`,{path:t})}async function yn(e,t){return V(`POST`,`${$(e)}/environment/folders/remove`,{path:t})}async function bn(e,t){return V(`PUT`,`${$(e)}/environment/internet`,{on:t})}async function xn(e){return V(`GET`,`${$(e)}/outputs`)}async function Sn(e){return V(`GET`,`${$(e)}/capabilities`)}async function Cn(e){return V(`GET`,`${$(e)}/changes/total`)}async function wn(e,t=!1){return V(`POST`,`${$(e)}/changes/undo`,{force:t})}async function Tn(e){return V(`GET`,`${$(e)}/changes/git`)}async function En(e,t,n){return V(`POST`,`${$(e)}/changes/git/commit`,{root:t,message:n,confirmed:!0})}async function Dn(e,t,n,r){return V(`POST`,`${$(e)}/changes/git/pr`,{root:t,title:n,body:r,confirmed:!0})}export{ut as $,r as $n,N as $t,Ye as A,f as An,$t as At,Ge as B,ae as Bn,nn as Bt,vt as C,b as Cn,en as Ct,Ve as D,C as Dn,Pe as Dt,Vt as E,me as En,yn as Et,tt as F,ue as Fn,bn as Ft,Ie as G,ne as Gn,_t as Gt,an as H,ee as Hn,wn as Ht,Bt as I,m as In,qe as It,un as J,ce as Jn,Rt as Jt,xn as K,le as Kn,ze as Kt,_n as L,pe as Ln,Le as Lt,Sn as M,te as Mn,at as Mt,dt as N,ie as Nn,At as Nt,Et as O,ye as On,it as Ot,lt as P,fe as Pn,nt as Pt,Re as Q,i as Qn,D as Qt,Xt as R,re as Rn,ft as Rt,Q as S,S as Sn,bt as St,Ke as T,x as Tn,ct as Tt,wt as U,g as Un,mn as Ut,rt as V,l as Vn,Ct as Vt,Tt as W,de as Wn,cn as Wt,Cn as X,p as Xn,Zt as Xt,yt as Y,c as Yn,Lt as Yt,Tn as Z,d as Zn,Qt as Zt,sn as _,E as _n,Yt as _t,st as a,Se as an,qt as at,Dt as b,v as bn,I as bt,V as c,M as cn,It as ct,Kt as d,we as dn,on as dt,be as en,s as er,Me as et,Ht as f,Te as fn,ht as ft,Dn as g,ve as gn,St as gt,Qe as h,_e as hn,Be as ht,B as i,k as in,Fe as it,We as j,u as jn,xt as jt,$e as k,se as kn,ln as kt,Wt as l,Ee as ln,et as lt,En as m,ge as mn,fn as mt,W as n,j as nn,o as nr,pn as nt,vn as o,Ce as on,Ue as ot,ot as p,T as pn,mt as pt,Ne as q,h as qn,gn as qt,J as r,A as rn,hn as rt,pt as s,xe as sn,He as st,L as t,P as tn,a as tr,rn as tt,Ft as u,O as un,Je as ut,gt as v,y as vn,Jt as vt,Gt as w,w as wn,Ut as wt,Ot as x,he as xn,dn as xt,zt as y,_ as yn,F as yt,z,oe as zn,tn as zt};