limixbot 0.3.123 → 0.3.125
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{ActivityPanel-DKkRPc5u.js → ActivityPanel-B1MiMy01.js} +1 -1
- package/dist/assets/{App-B_6v005D.js → App-BDek3TXw.js} +70 -70
- package/dist/assets/{AppEventEditor-CgCAU3xb.js → AppEventEditor-CkV750Dg.js} +1 -1
- package/dist/assets/{BotSettingsDialog-BKYvhszb.js → BotSettingsDialog-BHeBFafC.js} +1 -1
- package/dist/assets/{BrowserPanel-5gB4tS9U.js → BrowserPanel-DHS4wRrK.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-DZ7c1q5q.js → BrowserProfilesManager-hX2FZVA6.js} +1 -1
- package/dist/assets/{CloudAddDialog-Bvd7FZ4d.js → CloudAddDialog-BFNCuBON.js} +1 -1
- package/dist/assets/{ComputerFilesPane-CjtNKKbe.js → ComputerFilesPane-DtlwTLBS.js} +1 -1
- package/dist/assets/{ComputerPanel-CBapTQFD.js → ComputerPanel-C24OAo45.js} +2 -2
- package/dist/assets/{DataPanel-C4f550Lj.js → DataPanel-teqnaUYe.js} +1 -1
- package/dist/assets/{DesktopViewer-CYtP0Zj2.js → DesktopViewer-Ds7umweq.js} +1 -1
- package/dist/assets/{GrokMoveDialog-BtXCnEYN.js → GrokMoveDialog-YEvZOK3B.js} +1 -1
- package/dist/assets/{InspectorPanel--xnRumvj.js → InspectorPanel-CX1qhEyS.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-CEx_V0bQ.js → KeyboardShortcutsModal-DZLTMLnr.js} +1 -1
- package/dist/assets/{LimixResizeHandles-CjRRCwcN.js → LimixResizeHandles-DwJ0Ihrt.js} +1 -1
- package/dist/assets/{LiveDesktop-Dn_PuQ9F.js → LiveDesktop-CLklPOhB.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-B5fxw6lw.js → LocalVmWorkspace-D-fpJ9Gj.js} +1 -1
- package/dist/assets/{MacLocalControl-DODUL7HN.js → MacLocalControl-B_r8KnC1.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-BruQLC_l.js → MarkdownFilePreview--8KJ8eQs.js} +1 -1
- package/dist/assets/{MenuMotion-d099kOVA.js → MenuMotion-p_3OSw7G.js} +1 -1
- package/dist/assets/{NewBotDialog-DyMTAHj0.js → NewBotDialog-CjhREbKo.js} +1 -1
- package/dist/assets/{PhoneAppDialog-Bq_Mdffc.js → PhoneAppDialog-DbiY0X_c.js} +1 -1
- package/dist/assets/{PlacesRail-Dn-Dc7z1.js → PlacesRail-RbEQCQDz.js} +1 -1
- package/dist/assets/{PluginsPanel-BfNxvMCp.js → PluginsPanel-BT5pSJ2n.js} +1 -1
- package/dist/assets/{ProIntroduction-DPl3c2lY.js → ProIntroduction-CNDF-TfS.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-CtPuKNKB.js → RemoteAgentSettingsPanel-TKCPYqQ-.js} +1 -1
- package/dist/assets/{RoomPanel-DumARUQU.js → RoomPanel-DMWVlkFR.js} +1 -1
- package/dist/assets/{RoutinesPage-C9LoeKE6.js → RoutinesPage-BkY2zvS9.js} +1 -1
- package/dist/assets/{SettingsModal-DAGwAG7c.js → SettingsModal-C5HAuVLr.js} +2 -2
- package/dist/assets/{ShareTeamDialog-C-mL1bDp.js → ShareTeamDialog-DJaYhyPl.js} +1 -1
- package/dist/assets/{SignedInSites-Dkhkaakq.js → SignedInSites-h30xrxTC.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-DJFUR0Vg.js → TeamLibraryPanel-CtBoQnfe.js} +1 -1
- package/dist/assets/{TeamMapPage-DktNaqor.js → TeamMapPage-BDXDKV9M.js} +1 -1
- package/dist/assets/{TriggersPage-CvdNOyPE.js → TriggersPage-53lVBpL4.js} +1 -1
- package/dist/assets/{VisibilitySection-WomPXyvQ.js → VisibilitySection-CFAscYka.js} +1 -1
- package/dist/assets/{WebhookTrigger-BMc0D2XF.js → WebhookTrigger-xRXNGj85.js} +1 -1
- package/dist/assets/{WorksOnGrid-DTRgzn-y.js → WorksOnGrid-Btzc4Woq.js} +1 -1
- package/dist/assets/{abnfDiagram-YUKMZFIV-LvbndEKG.js → abnfDiagram-YUKMZFIV--WCL2tMc.js} +1 -1
- package/dist/assets/{activity-C9SY9LzF.js → activity-sibNyUyL.js} +1 -1
- package/dist/assets/{architectureDiagram-47P4ROYG-L2knYgF3.js → architectureDiagram-47P4ROYG-B1hTlWSu.js} +1 -1
- package/dist/assets/{blockDiagram-E7TT5TSB-BKtl-N-f.js → blockDiagram-E7TT5TSB-CR8Ikgnw.js} +1 -1
- package/dist/assets/{c4Diagram-CRA5TL53-OlkwIe4P.js → c4Diagram-CRA5TL53-BCn3JBuz.js} +1 -1
- package/dist/assets/{calendar-days-iWF1m0sv.js → calendar-days-B4jDUJhh.js} +1 -1
- package/dist/assets/channel-BhOgq7GX.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-DB7ZLT5q.js → chunk-2Q5K7J3B-Du-j8Umu.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-BEkhWSog.js → chunk-5VM5RSS4-CPiVWlX1.js} +1 -1
- package/dist/assets/{chunk-7TKQ45FW-B_Zzai_0.js → chunk-7TKQ45FW-BeWSj3er.js} +1 -1
- package/dist/assets/{chunk-AW2ZBBNX-C46zNr3c.js → chunk-AW2ZBBNX-BpnBu77E.js} +1 -1
- package/dist/assets/{chunk-FVRAUYC3-Bhcd1hRY.js → chunk-FVRAUYC3-bysqJhIZ.js} +2 -2
- package/dist/assets/{chunk-HTAEGDNF-B2zP3ALR.js → chunk-HTAEGDNF-lirRQO83.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-B0v66Iag.js → chunk-JWPE2WC7-D6tCBX7U.js} +1 -1
- package/dist/assets/{chunk-KQW6MTUR-Bw6s89MJ.js → chunk-KQW6MTUR-Bl29yJPi.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-CZCXbUVJ.js → chunk-XXDRQBXY-J7gpzVSr.js} +1 -1
- package/dist/assets/{classDiagram-v2-K4WV4PDN-CIJSY4qL.js → classDiagram-v2-K4WV4PDN-CMuhYLe2.js} +1 -1
- package/dist/assets/{coins-DFjPGla0.js → coins-ClQfPsPX.js} +1 -1
- package/dist/assets/{core-Dh1v1aux.js → core-pbJ0Y4DO.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-DGZ7PM7O.js → cose-bilkent-JH36ORCC-BPk6ajRx.js} +1 -1
- package/dist/assets/{cynefin-EF2NZ3EQ-CI20N1Uv.js → cynefin-EF2NZ3EQ-CdSZNyDb.js} +1 -1
- package/dist/assets/{cynefinDiagram-3GCD6N5R-B9Rp28HY.js → cynefinDiagram-3GCD6N5R-BWiP56VZ.js} +1 -1
- package/dist/assets/{dagre-W4DXFKR2-Dox8O9ve.js → dagre-W4DXFKR2-DlWQa6YL.js} +1 -1
- package/dist/assets/{diagram-2UJZ2QOL-BRFprBVL.js → diagram-2UJZ2QOL-DzLU_CvL.js} +1 -1
- package/dist/assets/{diagram-OVF4WLC6-Cby4vlqr.js → diagram-OVF4WLC6-D5q75Tpg.js} +1 -1
- package/dist/assets/{diagram-PFPMY2P6-CXtyV5t3.js → diagram-PFPMY2P6-B-0a4IjT.js} +1 -1
- package/dist/assets/{diagram-UMYRVEAY-PxZ-8p6w.js → diagram-UMYRVEAY-BcWzkqz1.js} +1 -1
- package/dist/assets/{diagram-YEKJPTXX-DyCOpyxT.js → diagram-YEKJPTXX-JHnKjNA5.js} +1 -1
- package/dist/assets/{diagram-ZIFT7M5P-BCud51MV.js → diagram-ZIFT7M5P-VFRbybQZ.js} +1 -1
- package/dist/assets/{ebnfDiagram-VR2GEFS7-t9-FZzuU.js → ebnfDiagram-VR2GEFS7-Cgoe3hKK.js} +1 -1
- package/dist/assets/{elk-IJKZMXRS-BIi3YkGX.js → elk-IJKZMXRS-D7bwq_yP.js} +1 -1
- package/dist/assets/{erDiagram-O2IAPWRE-BrwuBEyt.js → erDiagram-O2IAPWRE-CpPh8Fah.js} +1 -1
- package/dist/assets/{file-up-BVTwLH93.js → file-up-BQt7Df7g.js} +1 -1
- package/dist/assets/{flowDiagram-OXPTDLAJ-Dk8qo54K.js → flowDiagram-OXPTDLAJ-BaJnQZkq.js} +1 -1
- package/dist/assets/{ganttDiagram-R7TSEDQI-Dtlz3NJp.js → ganttDiagram-R7TSEDQI-Di9Ny9eQ.js} +1 -1
- package/dist/assets/{gitGraphDiagram-XJZIOB7I-BjqjJyy7.js → gitGraphDiagram-XJZIOB7I-DMpC98bf.js} +1 -1
- package/dist/assets/{import-name-BxVszYzp.js → import-name--JRNCkRq.js} +1 -1
- package/dist/assets/{index-b0EYe0fw.js → index-B4VKEuQ6.js} +3 -3
- package/dist/assets/{index-Bm141aLh.js → index-dHi7tvH8.js} +1 -1
- package/dist/assets/{infoDiagram-5W2HQ5XZ-DrQwurt5.js → infoDiagram-5W2HQ5XZ-BwOcT6_N.js} +1 -1
- package/dist/assets/{ishikawaDiagram-K3B6WC7H-DbnPKoAH.js → ishikawaDiagram-K3B6WC7H-zxqGDW3L.js} +1 -1
- package/dist/assets/{journeyDiagram-COXZFDF6-DlLxO3bq.js → journeyDiagram-COXZFDF6-AN1_ttld.js} +1 -1
- package/dist/assets/{kanban-definition-P3RFRI5V-DC0c2bug.js → kanban-definition-P3RFRI5V-DOYL5g17.js} +1 -1
- package/dist/assets/{mcp-servers-DgHu1Oo5.js → mcp-servers-_PFzCXco.js} +1 -1
- package/dist/assets/{mermaid.core-BJC-zKhr.js → mermaid.core-DHkkkuN6.js} +4 -4
- package/dist/assets/{mindmap-definition-LZFPQGKD-BbY-pql1.js → mindmap-definition-LZFPQGKD-DoCFyCMx.js} +1 -1
- package/dist/assets/{minimize-c4TxXV2u.js → minimize-ByFqP2FI.js} +1 -1
- package/dist/assets/{monitor-Gi_HIBoq.js → monitor-DInAobl-.js} +1 -1
- package/dist/assets/{new-bot-Bo6rB5z3.js → new-bot-Div0m6qw.js} +1 -1
- package/dist/assets/{org-library-Bl1Hxxhy.js → org-library-ClYoJFnL.js} +1 -1
- package/dist/assets/{package-format-BWkx2lL0.js → package-format--z2ustts.js} +1 -1
- package/dist/assets/{pegDiagram-BGZESJAR-qLl1QDAo.js → pegDiagram-BGZESJAR-CKpEIG3z.js} +1 -1
- package/dist/assets/{pieDiagram-CAPJLFHJ-BkrwNpmm.js → pieDiagram-CAPJLFHJ-DoffR53C.js} +1 -1
- package/dist/assets/{quadrantDiagram-GDMTTRAM-Cw-T3c_W.js → quadrantDiagram-GDMTTRAM-kaoXoO-E.js} +1 -1
- package/dist/assets/{rail-nOTcofnu.js → rail-BZIFozED.js} +1 -1
- package/dist/assets/{railroadDiagram-SM67HX2B-BweBmdBU.js → railroadDiagram-SM67HX2B-DeKMhm5p.js} +1 -1
- package/dist/assets/{remote-desktop-panel-DAuUht5N.js → remote-desktop-panel-BYM8frxM.js} +1 -1
- package/dist/assets/{requirementDiagram-X7JNWC4A-CARqzijV.js → requirementDiagram-X7JNWC4A-CdflPcl0.js} +1 -1
- package/dist/assets/{sankeyDiagram-UM26HJRW-C4n0n0FA.js → sankeyDiagram-UM26HJRW-B0-2F0b9.js} +1 -1
- package/dist/assets/{sequenceDiagram-ZO4K6R2Y-DsTqgd-h.js → sequenceDiagram-ZO4K6R2Y-BrFZfWoC.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-ZvCk5fAt.js → sizeCapture-INFHLROL-CZMn3-3_.js} +1 -1
- package/dist/assets/{stateDiagram-v2-TBUQTH76-pWJExt54.js → stateDiagram-v2-TBUQTH76-BeOXXJ0J.js} +1 -1
- package/dist/assets/styles-B8xkIKpA.css +1 -0
- package/dist/assets/{swimlanes-N4OXWK64-jWj3wFzw.js → swimlanes-N4OXWK64-C3ZH7QZn.js} +1 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-87e__yCN.js +8 -0
- package/dist/assets/{team-share-CsPQlRh2.js → team-share-DdYOqcXI.js} +1 -1
- package/dist/assets/{timeline-definition-YOQAKGHF-CWCUk5cJ.js → timeline-definition-YOQAKGHF-r0yv8R_y.js} +1 -1
- package/dist/assets/{usecaseDiagram-VIAY4XPW-BxEq_OjR.js → usecaseDiagram-VIAY4XPW-Dn-rjHRV.js} +1 -1
- package/dist/assets/{vennDiagram-BLWOH2XV-wqR53XUL.js → vennDiagram-BLWOH2XV-B6g8THhH.js} +1 -1
- package/dist/assets/{wardleyDiagram-YMQ3BMBF-CwgJZ9ph.js → wardleyDiagram-YMQ3BMBF-B-zEt-P1.js} +1 -1
- package/dist/assets/{xychartDiagram-TAQBALBS-xkfdYBWM.js → xychartDiagram-TAQBALBS-BJsqiM_K.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/rail.html +5 -5
- package/dist-server/package.json +1 -1
- package/package.json +1 -1
- package/dist/assets/channel-BFJ19G-H.js +0 -1
- package/dist/assets/styles-D55d5vt1.css +0 -1
- package/dist/assets/swimlanesDiagram-K3J5GTZL-DM7KvPAR.js +0 -8
- /package/dist/assets/{styles-B_kHEXu4.js → styles-CbbuPFF7.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as ut,j as e,t,r as l,a as z,S as mt,d as ge,p as ws,k as Rt,X as $e,i as Ss,C as zr,ae as Ca,L as St,aO as Ur,aZ as Fr,a8 as Dr,R as _r,l as Me,a_ as $r,a$ as Kr,ab as Hr,b0 as Wr,b1 as Lt,ax as en,y as Gr,au as Vr,z as tn,ay as Ea,b as qr,b2 as Jr,B as Xr,b3 as Yr,A as Qr,aD as Zr,b4 as sn,aC as el,b5 as tl,b6 as nn,b7 as an,b8 as rn,b9 as sl,ba as nl,ah as al,bb as il}from"./styles-B_kHEXu4.js";import{L as rl}from"./LimixResizeHandles-CjRRCwcN.js";import{L as X,P as Ce,v as pt,E as ll,ah as ol,ai as cl,$ as dl,W as ul,l as Cs,C as Aa,B as Bt,aj as ml,ak as pl,al as xl,d as Ia,r as hl,h as ln,g as on,i as gl,am as fl,an as bl,ao as yl,ap as Wt,A as vl,p as jl,aq as kl,ar as Pa,as as Nl,R as Ta,c as wl,at as Sl,au as Cl,M as El,ab as Al,av as Il,aw as os,b as Pl,t as Tl,U as Rl,N as Gt,f as Ll}from"./PlacesRail-Dn-Dc7z1.js";import{bY as Ot,u as W,S as me,j as M,h6 as Be,T as Ee,dA as Qe,w as xe,cT as Bl,cP as Ra,eV as Ze,h7 as Ol,Y as Oe,eT as Ml,eU as zl,h8 as cs,h9 as lt,ha as La,hb as Es,hc as As,hd as Ul,e8 as cn,he as Ba,hf as Oa,hg as Fl,hh as Dl,hi as _l,a2 as ue,c7 as Y,eg as ds,eS as $l,hj as Ma,hk as Nt,hl as Mt,hm as za,hn as Ua,ho as Le,hp as _e,hq as Kl,hr as Hl,hs as Wl,ht as Gl,hu as Vl,hv as Fa,hw as ql,hx as Jl,hy as Da,hz as _a,hA as be,hB as ye,dw as dn,hC as zt,hD as Xl,hE as Yl,hF as Ql,hG as Zl,hH as eo,g$ as $a,bu as to,x as L,hI as rt,R as so,dP as no,hJ as ao,hK as un,aQ as Ct,fA as ot,fB as ct,hL as io,K as Ye,r as ro,cs as lo,gQ as oo,hM as Ut,hN as Ka,hO as co,hP as uo,hQ as mn,hR as Ha,hS as Ft,hT as Wa,hU as mo,hV as po,hW as xo,hX as ho,G as go,hY as fo,hZ as dt,en as Dt,h_ as bo,h$ as yo,i0 as vo,i1 as jo,fI as ko,i2 as pn,i3 as No,i4 as wo,E as So,i5 as xn,i6 as Co,el as Ga,i7 as Eo,i8 as Ao,i9 as Io,ia as Po,ib as To,ic as Ro,id as Va,ie as Lo,ig as Bo,ih as Oo,ii as Mo,ij as zo,ik as Uo,il as qa,im as Fo,io as Do,dV as _o,ip as $o,eh as Ko,iq as Ho,ir as Wo,is as Go,it as Vo,iu as hn,iv as qo,iw as Jo,ix as gn,l as Xo,iy as Yo,iz as Qo,iA as Zo,bR as ec,iB as tc,iC as sc,iD as nc,iE as ac,iF as Ja,fy as nt,iG as ic,fx as rc,iH as Xa,iI as lc,iJ as Ya,iK as oc,iL as fn,i as cc,iM as us,iN as bn,iO as yn,iP as dc,iQ as uc,iR as mc,iS as pc,iT as xc,iU as hc,iV as gc,iW as fc,iX as bc,iY as Is,iZ as yc,fo as Qa,h as vc,i_ as jc,i$ as kc,j0 as vn,j1 as Nc,j2 as wc,j3 as jn,j4 as Sc,b9 as Cc,j5 as Ec,j6 as Ac,j7 as Ic,bJ as Pc,j8 as Tc,j9 as kn,ja as Rc,bE as Ps,jb as Lc,bF as Bc,jc as Oc,jd as Mc,je as zc,jf as Uc,jg as Fc,jh as Dc,ji as _c,jj as $c,jk as Nn,gC as Kc,jl as Hc,jm as Wc,jn as Za,jo as Gc,jp as Vc,jq as qc,jr as ei,js as ti,jt as si,ju as Jc,jv as Xc,jw as Yc,dc as Qc,I as Zc,jx as ni,eN as ed,c5 as wn,jy as td,jz as Sn,fa as Cn,e7 as sd,_ as nd,az as ad,jA as id,jB as rd,jC as ld}from"./App-B_6v005D.js";import{C as Ts,a as od,R as Se}from"./MenuMotion-d099kOVA.js";import{l as ai,M as cd,w as En}from"./MacLocalControl-DODUL7HN.js";import{Q as ii}from"./VisibilitySection-WomPXyvQ.js";import{a as dd,r as ud,C as md,s as ri,b as pd,c as xd,w as hd,t as gd,T as fd,l as Rs,d as An,e as bd,f as yd}from"./index-b0EYe0fw.js";import{c as vd,A as jd,w as kd,d as Nd,e as In}from"./activity-C9SY9LzF.js";import{U as li,R as oi,B as ci,S as di,a as ui,D as mi,T as pi,C as xi,L as ms,b as hi,F as gi,A as ps,E as wd,c as Sd,P as Cd,d as Ed,e as Ad,N as Id}from"./NewBotDialog-DyMTAHj0.js";import{a as Pd,u as Td,C as fi,b as Rd,P as Ld}from"./ProIntroduction-DPl3c2lY.js";import{M as bi}from"./monitor-Gi_HIBoq.js";import{C as Bd}from"./coins-DFjPGla0.js";import"./org-library-Bl1Hxxhy.js";import"./package-format-BWkx2lL0.js";import"./mcp-servers-DgHu1Oo5.js";import"./WorksOnGrid-DTRgzn-y.js";import"./new-bot-Bo6rB5z3.js";import"./RoutinesPage-C9LoeKE6.js";import"./remote-desktop-DDRRx8uY.js";import"./team-share-CsPQlRh2.js";import"./BrowserProfilesManager-DZ7c1q5q.js";import"./SignedInSites-Dkhkaakq.js";const Od=[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]],Md=ut("cloud-download",Od);const zd=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Ud=ut("palette",zd);const Fd=[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]],Dd=ut("scroll-text",Fd);const _d=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],$d=ut("terminal",_d);const Kd=[["path",{d:"m19 5 3-3",key:"yk6iyv"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z",key:"1snsnr"}]],Hd=ut("unplug",Kd);function Ls(s){return s.filter(n=>n.driverKind==="openai-compat"&&n.instanceId.startsWith("openai-compat-"))}function je({children:s,note:n="settings.adminOnly.change"}){return Ot()===!1?e.jsx("p",{"data-admin-only":!0,className:"text-[13px] text-ink-secondary",children:t(n)}):s}function Bs(s,n,a="start",i=0){const r=n.getBoundingClientRect().top-s.getBoundingClientRect().top+s.scrollTop;s.scrollTop=Math.max(0,a==="center"?r-(s.clientHeight-(n.offsetHeight??0))/2:r-i)}function Wd(s){for(let n=s.parentElement;n;n=n.parentElement){const a=getComputedStyle(n).overflowY;if((a==="auto"||a==="scroll")&&n.scrollHeight>n.clientHeight)return n}return null}function Gd(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(!1),[r,c]=l.useState(null),o=s.config?.tts?.everyReply===!0,d=()=>{i(!0),c(null),M("/api/config",{method:"PUT",body:JSON.stringify({tts:{everyReply:!o}})}).then(m=>n({type:"configStatus",config:m})).catch(m=>c(m.message)).finally(()=>i(!1))};return e.jsxs("div",{"data-voice-every-reply":!0,className:"flex items-center justify-between gap-4 px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-medium leading-5 text-ink",children:t("voice.everyReply")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-4 text-ink-secondary",children:t("voice.everyReply.allHelp")}),r&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:r})]}),e.jsx(me,{checked:o,disabled:a,"aria-label":t("voice.everyReply"),onClick:d})]})}const Vd="https://api.xingchiapi.com/v1",qd={claude:{url:"https://api.anthropic.com",model:"deepseek-chat"},codex:{url:"https://api.openai.com/v1",model:""}},ft=z(Be,"font-sans"),Pn={name:"",url:"",token:"",model:""},Jd=s=>({name:s.displayName,url:(s.claudeEndpoint??s.codexEndpoint)?.baseUrl??"",token:"",model:(s.claudeEndpoint??s.codexEndpoint)?.model??""});function Os({instance:s,engine:n,onDone:a,xingchi:i=!1}){const{dispatch:r}=W(),c=qd[n],[o,d]=l.useState(s?Jd(s):i?{...Pn,name:"Xingchi (Codex Responses)",url:Vd}:Pn),[m,u]=l.useState(!1),[x,p]=l.useState(null),h=b=>({value:o[b],onChange:g=>d(k=>({...k,[b]:g.target.value})),spellCheck:!1,disabled:m}),f=!!(o.name.trim()&&(o.url.trim()||n==="codex")&&(s||o.token.trim())),y=async()=>{if(m||!f)return;u(!0),p(null);const b={displayName:o.name.trim(),...i&&!s?{profile:"xingchi"}:{},baseUrl:o.url.trim()||c.url,...o.token.trim()?{token:o.token.trim()}:{},...o.model.trim()?{model:o.model.trim()}:{}};try{const g=s?await M(`/api/instances/${encodeURIComponent(s.instanceId)}/${n}-endpoint`,{method:"PATCH",body:JSON.stringify(b)}):await M(`/api/instances/${n}-endpoint`,{method:"POST",body:JSON.stringify(b)});Array.isArray(g.instances)&&r({type:"instances",instances:g.instances}),a()}catch(g){const k=g instanceof Error?g.message:"";p(k.includes("HTTP 403, client_not_allowed")?t("agentEndpoints.modelListClientDenied"):k||t("claudeEndpoints.failed"))}finally{u(!1)}};return e.jsxs("form",{"data-claude-endpoint-form":n==="claude"?s?.instanceId??"new":void 0,"data-codex-endpoint-form":n==="codex"?s?.instanceId??"new":void 0,className:"flex flex-col gap-2 rounded-xl border border-hairline/50 bg-inset p-3",onSubmit:b=>{b.preventDefault(),y()},children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t(n==="codex"?"agentEndpoints.responses":"agentEndpoints.messages")}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.name"),e.jsx("input",{...h("name"),maxLength:80,autoFocus:!0,"aria-label":t("claudeEndpoints.name"),className:ft})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.baseUrl"),e.jsx("input",{...h("url"),readOnly:i||s?.codexEndpoint?.profile==="xingchi",type:"url",maxLength:2048,placeholder:c.url,"aria-label":t("claudeEndpoints.baseUrl"),className:z(ft,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.token"),e.jsx("input",{...h("token"),type:"password",maxLength:4096,autoComplete:"off","aria-label":t("claudeEndpoints.token"),className:z(ft,"font-mono"),placeholder:s?t("claudeEndpoints.tokenKeep"):""})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.model"),e.jsx("input",{...h("model"),maxLength:160,placeholder:c.model,"aria-label":t("claudeEndpoints.model"),className:z(ft,"font-mono")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeEndpoints.modelHint")}),x&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:x}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:a,disabled:m,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:m||!f,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[m&&e.jsx(X,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function yi({instance:s,showName:n=!1}){const{state:a,dispatch:i}=W(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[m,u]=l.useState(!1),[x,p]=l.useState(null),h=a.bots.filter(b=>b.modelSelection.instanceId===s.instanceId||b.fallback?.some(g=>g.instanceId===s.instanceId)||b.tasks?.some(g=>g.modelSelection?.instanceId===s.instanceId)).length,f=s.claudeEndpoint??s.codexEndpoint;if(!f||s.readOnly)return null;const y=async()=>{d(!1),u(!0),p(null);try{const b=await M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(b.instances)&&i({type:"instances",instances:b.instances})}catch(b){p(b instanceof Error?b.message:String(b))}finally{u(!1)}};return r?e.jsx(Os,{instance:s,engine:s.codexEndpoint?"codex":"claude",onDone:()=>c(!1)}):e.jsxs("div",{"data-claude-endpoint":s.claudeEndpoint?s.instanceId:void 0,"data-codex-endpoint":s.codexEndpoint?s.instanceId:void 0,children:[e.jsxs("div",{className:"flex min-h-9 flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[n&&e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:s.displayName,children:s.displayName}),e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",title:f.baseUrl,children:f.baseUrl}),f.model&&e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",title:f.model,children:f.model})]}),e.jsx("button",{type:"button",onClick:()=>c(!0),disabled:m,className:"ui-button shrink-0",children:t("claudeEndpoints.edit")}),e.jsxs("button",{type:"button",disabled:m||h>0,onClick:()=>d(!0),title:h>0?t("accounts.inUse",{count:String(h)}):t("accounts.remove"),"aria-label":t("claudeEndpoints.remove",{name:s.displayName}),className:"flex min-h-8 shrink-0 items-center justify-center gap-1.5 rounded-lg px-2.5 text-[12px] font-medium text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:[m?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(Ee,{size:14}),t("common.delete")]})]}),h>0&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("accounts.inUse",{count:String(h)})}),x&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:x}),e.jsx(Qe,{open:o,title:t("accounts.removeTitle",{name:s.displayName}),body:t("claudeEndpoints.removeBody"),confirmLabel:t("common.delete"),pending:m,onCancel:()=>d(!1),onConfirm:()=>{y()}})]})}function vi({engine:s}){const{state:n}=W(),a=n.instances.filter(c=>!c.readOnly&&(s==="claude"?c.claudeEndpoint:c.codexEndpoint)),[i,r]=l.useState(!1);return e.jsxs("div",{"data-claude-endpoints":s==="claude"?"":void 0,"data-codex-endpoints":s==="codex"?"":void 0,className:"mt-3 space-y-2",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t(s==="claude"?"claudeEndpoints.title":"agentEndpoints.codexTitle")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t(s==="claude"?"claudeEndpoints.hint":"agentEndpoints.codexHint")}),a.length===0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeEndpoints.empty")}):e.jsx("ul",{className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:a.map(c=>e.jsx("li",{className:"px-3 py-2.5",children:e.jsx(yi,{instance:c,showName:!0})},c.instanceId))}),i?e.jsx(Os,{engine:s,onDone:()=>r(!1)}):e.jsxs("button",{type:"button",onClick:()=>r(!0),className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),t("claudeEndpoints.add")]})]})}function Vt(){return e.jsx(vi,{engine:"claude"})}function wt(){return e.jsx(vi,{engine:"codex"})}function qt(s){return[...new Set(s.split(/[,,、\s]+/).map(n=>n.trim()).filter(Boolean))]}const De=z(Be,"font-sans"),Xd=[5,10,20,30,60],Jt="ui-icon-button shrink-0 hover:text-ink",Xt={name:"Google Gemini",url:"https://generativelanguage.googleapis.com/v1beta/openai"},xs={count:64,length:200},Yd=s=>s.length<=xs.count&&s.every(n=>n.length<=xs.length),hs=(s,n)=>M(`/api/instances/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(n)});function ji({server:s,disabled:n,onPick:a}){return e.jsxs(xe,{size:"sm",className:"shrink-0",value:s.replyWaitMinutes??"",onChange:i=>a(i.target.value?Number(i.target.value):null),disabled:n,"aria-label":t("apiInstances.replyWaitFor",{name:s.displayName}),title:t("apiInstances.replyWaitHint"),children:[e.jsx("option",{value:"",children:t("apiInstances.replyWaitDefault")}),[...new Set([...Xd,...s.replyWaitMinutes?[s.replyWaitMinutes]:[]])].sort((i,r)=>i-r).map(i=>e.jsx("option",{value:i,children:t("apiInstances.replyWaitMinutes",{minutes:String(i)})},i))]})}function Qd(){const{state:s,dispatch:n,refreshInstances:a}=W(),[i,r]=l.useState(!1),[c,o]=l.useState(null),d=s.instances.find(u=>u.instanceId==="openaiCompat"&&u.driverKind==="openai-compat");if(!d||!s.config?.openaiCompat?.url)return null;const m=u=>{i||(r(!0),o(null),hs(d.instanceId,{replyWaitMinutes:u}).then(async({instances:x})=>{Array.isArray(x)?n({type:"instances",instances:x}):await a({reportErrors:!0})}).catch(x=>o(x.message||t("apiInstances.failed"))).finally(()=>r(!1)))};return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(ji,{server:d,disabled:i,onPick:m}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.replyWaitHint")}),c&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:c})]})}function Zd(){const{state:s}=W();return e.jsxs(e.Fragment,{children:[e.jsx(eu,{servers:Ls(s.instances)}),e.jsxs("details",{className:"mt-3 rounded-lg border border-hairline/60 bg-inset px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[13px] text-ink",children:t("agentEndpoints.codexConnect")}),e.jsx(wt,{})]})]})}function eu({servers:s}){const{dispatch:n,refreshInstances:a}=W(),[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(""),[u,x]=l.useState(""),[p,h]=l.useState(null),[f,y]=l.useState(null),[b,g]=l.useState(null),[k,S]=l.useState(""),C=!!(i.trim()&&c.trim()&&d.trim()),w=(v,B,j,A)=>{p||(h(v),y(null),B().then(async({instances:I})=>{Array.isArray(I)?n({type:"instances",instances:I}):await a({reportErrors:!0}),j?.()}).catch(I=>y({text:I.message||t("apiInstances.failed"),at:A})).finally(()=>h(null)))},P=()=>C&&w("add",()=>M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:i.trim(),url:c.trim(),key:d.trim(),...qt(u).length?{models:qt(u)}:{}})}).then(v=>(Ze("custom_endpoint","settings","unverified"),v),v=>{throw Ze("custom_endpoint","settings","error"),v}),()=>{r(""),o(""),m(""),x("")});return e.jsxs("div",{"data-api-keys-other":!0,children:[e.jsx("div",{className:"mb-0.5 text-[13px] leading-[18px] text-ink",children:t("apiInstances.title")}),e.jsx("p",{className:"mb-2 text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.subtitle")}),s.length===0&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.empty")}),s.map(v=>e.jsxs("div",{className:"mb-1.5 rounded-lg border border-hairline/60 bg-inset px-3 py-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12px] text-ink",children:v.displayName}),v.url&&e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",children:v.url})]}),e.jsx(ji,{server:v,disabled:p!==null,onPick:B=>w("other",()=>hs(v.instanceId,{replyWaitMinutes:B}))}),e.jsx("button",{type:"button",onClick:()=>{S((v.managedModels??[]).join(", ")),g(b===v.instanceId?null:v.instanceId),y(null)},disabled:p!==null,"aria-label":t("apiInstances.editModels",{name:v.displayName}),"aria-expanded":b===v.instanceId,title:t("apiInstances.editModels",{name:v.displayName}),className:Jt,children:e.jsx(Bl,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>w("other",()=>M(`/api/instances/${encodeURIComponent(v.instanceId)}/refresh-models`,{method:"POST"})),disabled:p!==null,"aria-label":t("apiInstances.refreshModels",{name:v.displayName}),title:t("apiInstances.refreshModels",{name:v.displayName}),className:Jt,children:e.jsx(Ra,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>w("other",()=>M(`/api/instances/${encodeURIComponent(v.instanceId)}`,{method:"DELETE"})),disabled:p!==null,"aria-label":t("apiInstances.remove",{name:v.displayName}),title:t("apiInstances.remove",{name:v.displayName}),className:`${Jt} hover:bg-danger/10 hover:text-danger`,children:e.jsx(Ee,{size:13,"aria-hidden":"true"})})]}),b===v.instanceId&&e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5",children:[e.jsx("input",{value:k,onChange:B=>S(B.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.modelsFor",{name:v.displayName}),spellCheck:!1,disabled:p!==null,className:z(De,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.editModelsHint")}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{const B=qt(k);if(!Yd(B)){y({text:t("apiInstances.modelsLimit",xs),at:v.instanceId});return}w("other",()=>hs(v.instanceId,{models:B}),()=>g(null),v.instanceId)},disabled:p!==null,className:"ui-button",children:t("common.save")}),e.jsx("button",{type:"button",onClick:()=>g(null),disabled:p!==null,className:"ui-button",children:t("common.cancel")})]}),f?.at===v.instanceId&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:f.text})]})]},v.instanceId)),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{r(Xt.name),o(Xt.url)},disabled:p!==null,className:"ui-button self-start",children:t("apiInstances.geminiPreset")}),c.trim()===Xt.url&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.geminiKeyHint")}),e.jsx("input",{value:i,onChange:v=>r(v.target.value),placeholder:t("apiInstances.name"),"aria-label":t("apiInstances.name"),spellCheck:!1,disabled:p!==null,className:De}),e.jsx("input",{type:"url",value:c,onChange:v=>o(v.target.value),placeholder:"https://api.example.com/v1","aria-label":t("apiInstances.url"),spellCheck:!1,disabled:p!==null,className:z(De,"font-mono")}),e.jsx("input",{type:"password",value:d,onChange:v=>m(v.target.value),placeholder:t("apiInstances.key"),"aria-label":t("apiInstances.key"),autoComplete:"off",disabled:p!==null,className:z(De,"font-mono")}),e.jsx("input",{value:u,onChange:v=>x(v.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.models"),spellCheck:!1,disabled:p!==null,className:z(De,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.modelsHint")}),e.jsxs("button",{type:"button",onClick:P,disabled:p!==null||!C,className:"ui-button self-start",children:[p==="add"?e.jsx(X,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),p==="add"?t("apiInstances.adding"):t("apiInstances.add")]})]}),f&&!f.at&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:f.text})]})}const tu="lm-studio";function su(s){const n=s.trim();if(!/^[1-9]\d{0,4}$/.test(n))return null;const a=Number(n);return a>65535?null:`http://127.0.0.1:${a}/v1`}function nu({heading:s=!0}={}){const{state:n,dispatch:a,refreshInstances:i}=W(),r=Ls(n.instances),[c,o]=l.useState("1234"),[d,m]=l.useState(""),[u,x]=l.useState(!1),[p,h]=l.useState(null),f=su(c),y=!!(f&&r.some(g=>g.url===f)),b=()=>{u||!f||y||(x(!0),h(null),M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"LM Studio",url:f,key:d.trim()||tu,catalog:"lmstudio"})}).then(async g=>{Ze("custom_endpoint","settings","unverified"),Array.isArray(g.instances)?a({type:"instances",instances:g.instances}):await i({reportErrors:!0}),m("")},g=>{Ze("custom_endpoint","settings","error"),h(g instanceof Error&&g.message?g.message:t("apiInstances.failed"))}).finally(()=>x(!1)))};return e.jsxs("div",{className:z(s&&"rounded-lg border border-hairline/40 bg-inset px-3 py-2"),children:[s&&e.jsx("div",{className:"text-[13px] text-ink",children:t("lmStudio.title")}),e.jsx("p",{className:z("text-[12px] leading-4 text-ink-secondary",s&&"mt-1"),children:t("lmStudio.desc")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] leading-4 text-ink-secondary",children:[t("lmStudio.port"),e.jsx("input",{inputMode:"numeric",value:c,onChange:g=>o(g.target.value),"aria-label":t("lmStudio.port"),spellCheck:!1,disabled:u,className:z(De,"font-mono")})]}),e.jsx("input",{type:"password",value:d,onChange:g=>m(g.target.value),placeholder:t("lmStudio.token"),"aria-label":t("lmStudio.token"),autoComplete:"off",disabled:u,className:z(De,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("lmStudio.tokenHint")}),f&&e.jsx("p",{className:"truncate font-mono text-[12px] leading-4 text-ink-secondary",children:f}),e.jsxs("button",{type:"button",onClick:b,disabled:u||!f||y,className:"ui-button self-start",children:[u?e.jsx(X,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),u?t("lmStudio.adding"):t("lmStudio.add")]}),y&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lmStudio.added")})]}),p&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:p})]})}const au="ollama",iu="https://ollama.com/download",ru=s=>`${s.replace(/\/+$/,"")}/v1`,lu=(s,n)=>s?.trim().replace(/\/+$/,"")===n;function ou({visible:s}){const{state:n,dispatch:a,refreshInstances:i}=W(),[r,c]=l.useState(""),[o,d]=l.useState(null),[m,u]=l.useState(!1),[x,p]=l.useState(!1),[h,f]=l.useState(null),y=l.useRef(0),b=l.useRef(!1),g=l.useCallback(P=>{const v=++y.current;u(!0),f(null),M(`/api/instances/ollama${P?`?url=${encodeURIComponent(P)}`:""}`).then(B=>{v===y.current&&d(B.status)}).catch(B=>{v===y.current&&(d(null),f(B.message||t("apiInstances.failed")))}).finally(()=>{v===y.current&&u(!1)})},[]);l.useEffect(()=>{!s||b.current||(b.current=!0,g(""))},[s,g]);const k=o?ru(o.url):null,S=!!(k&&(Ls(n.instances).some(P=>P.url===k)||lu(n.config?.openaiCompat?.url,k))),C=!!(k&&!S&&!x&&!m&&(o?.state==="ready"||o?.state==="no-models")),w=()=>{!C||!k||(p(!0),f(null),M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"Ollama",url:k,key:au,catalog:"ollama"})}).then(async P=>{Ze("custom_endpoint","settings","unverified"),Array.isArray(P.instances)?a({type:"instances",instances:P.instances}):await i({reportErrors:!0})},P=>{Ze("custom_endpoint","settings","error"),f(P instanceof Error&&P.message?P.message:t("apiInstances.failed"))}).finally(()=>p(!1)))};return e.jsxs("div",{"data-ollama-server":!0,children:[e.jsx("div",{role:"status","aria-live":"polite",children:m?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] leading-4 text-ink-secondary",children:[e.jsx(X,{size:12,className:"animate-spin","aria-hidden":"true"}),t("ollama.checking")]}):o&&e.jsx(Ol,{status:o})}),!m&&o?.state==="not-running"&&e.jsx("a",{href:iu,target:"_blank",rel:"noopener noreferrer",className:"mt-1 inline-block text-[12px] font-medium text-accent-text hover:underline",children:t("ollama.download")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("input",{type:"url",value:r,onChange:P=>c(P.target.value),onKeyDown:P=>{P.key==="Enter"&&g(r.trim())},placeholder:"http://127.0.0.1:11434","aria-label":t("ollama.address"),spellCheck:!1,disabled:x,className:z(Be,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("ollama.addressHint")}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsxs("button",{type:"button",onClick:w,disabled:!C,className:"ui-button",children:[x?e.jsx(X,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),x?t("ollama.adding"):t("ollama.add")]}),e.jsxs("button",{type:"button",onClick:()=>g(r.trim()),disabled:m||x,className:"ui-button",children:[e.jsx(Ra,{size:12,"aria-hidden":"true"}),t("common.checkAgain")]})]}),S&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("ollama.added")})]}),h&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:h})]})}function cu(){const{state:s,dispatch:n}=W(),a=s.config?.opencodeGo?.providerKeys??[],[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(!1),[u,x]=l.useState(null),[p,h]=l.useState(null),f=d||u!==null,y=(k,S)=>M("/api/config",{method:"PUT",body:JSON.stringify({opencodeGo:{providerKeys:{[k]:S}}})}).then(C=>n({type:"configStatus",config:C})),b=()=>{const k=i.trim().toUpperCase(),S=Ml(c);if(!(f||!k||!S)){if(!zl(S)){h(t("keys.notAKey"));return}m(!0),h(null),y(k,S).then(()=>{r(""),o("")}).catch(C=>h(C.message)).finally(()=>m(!1))}},g=k=>{f||(x(k),h(null),y(k,"").catch(S=>h(S.message)).finally(()=>x(null)))};return e.jsxs("div",{"data-opencode-provider-keys":!0,className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.opencode.otherProviders.hint")}),s.config?.cloudHome!==!0&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.opencode.providersHint").split("{command}").flatMap((k,S)=>S===0?[k]:[e.jsx("code",{className:"font-mono",children:"opencode auth login"},S),k])}),a.map(k=>e.jsxs("div",{"data-opencode-provider-key":k,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:z(Be,"block flex-1 truncate text-ink"),children:k}),e.jsx("button",{type:"button",onClick:()=>g(k),disabled:f,"aria-label":t("keys.opencode.otherProviders.removeAria",{name:k}),className:"ui-button shrink-0",children:u===k?e.jsx(X,{size:13,className:"animate-spin","aria-hidden":"true"}):t("keys.row.remove")})]},k)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text",value:i,onChange:k=>{h(null),r(k.target.value)},onKeyDown:k=>k.key==="Enter"&&b(),disabled:f,placeholder:"VENICE_API_KEY","aria-label":t("keys.opencode.otherProviders.name"),autoComplete:"off",spellCheck:!1,className:z(Be,"w-auto min-w-[min(100%,10rem)] flex-1 uppercase placeholder:normal-case")}),e.jsx("input",{type:"password",value:c,onChange:k=>{h(null),o(k.target.value)},onKeyDown:k=>k.key==="Enter"&&b(),disabled:f,placeholder:t("keys.opencode.otherProviders.keyPlaceholder"),"aria-label":t("keys.opencode.otherProviders.key"),autoComplete:"off",className:z(Be,"w-auto min-w-[min(100%,10rem)] flex-1")}),e.jsx("button",{type:"button",onClick:b,disabled:f||!i.trim()||!c.trim(),className:"ui-button ui-button-primary shrink-0",children:d?e.jsx(X,{size:13,className:"animate-spin","aria-hidden":"true"}):t("common.save")})]}),p&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:p})]})}function du(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(!1),[r,c]=l.useState(null);if(!s.config?.anthropic?.configured)return null;const o=s.config.anthropic.everyClaudeBot===!0,d=()=>{a||(i(!0),c(null),M("/api/config",{method:"PUT",body:JSON.stringify({anthropic:{everyClaudeBot:!o}})}).then(m=>n({type:"configStatus",config:m})).catch(m=>c(m.message)).finally(()=>i(!1)))};return e.jsxs("div",{"data-anthropic-every-claude-bot":!0,className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("keys.anthropic.everyBot")}),e.jsx("div",{className:"text-[12px] leading-4 text-ink-secondary",children:o?t("keys.anthropic.everyBotOn"):t("keys.anthropic.everyBotOff")})]}),e.jsx(me,{checked:o,disabled:a,onClick:d,"aria-label":t("keys.anthropic.everyBot")})]}),o&&e.jsxs("p",{className:"flex gap-1.5 text-[12px] leading-4 text-warning",children:[e.jsx(Oe,{size:13,className:"mt-px shrink-0","aria-hidden":"true"}),e.jsx("span",{children:t("keys.anthropic.warning")})]}),r&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:r})]})}function uu(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),m=!!s.config?.vps?.configured,u=!a.trim()&&m;l.useEffect(()=>{i(s.config?.vps?.sshAlias??"")},[s.config?.vps?.sshAlias]);const x=()=>{r||!a.trim()&&!m||(c(!0),d(null),M("/api/config",{method:"PUT",body:JSON.stringify({vps:{sshAlias:a.trim()}})}).then(p=>{n({type:"configStatus",config:p}),i(p.vps?.sshAlias??"")}).catch(p=>d(p.message)).finally(()=>c(!1)))};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("p",{className:"text-[12px] leading-4 text-ink-secondary",children:[t("keys.vps.descBefore"),e.jsx("a",{href:"https://github.com/leomieo/limix-bot/blob/main/docs/byo-vps.md",target:"_blank",rel:"noopener noreferrer",className:"text-accent-text hover:underline",children:t("keys.vps.descLink")}),t("keys.vps.descAfter")]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text","data-key-input":!0,value:a,onChange:p=>i(p.target.value),onKeyDown:p=>p.key==="Enter"&&x(),placeholder:"my-vps","aria-label":t("keys.vps.aria"),autoComplete:"off",spellCheck:!1,className:z(Be,"w-auto min-w-[min(100%,12rem)] flex-1")}),e.jsx("button",{type:"button",onClick:x,disabled:r||!a.trim()&&!m||a.trim()===(s.config?.vps?.sshAlias??""),className:z("ui-button shrink-0",!u&&"ui-button-primary"),title:u?t("keys.vps.removeAlias"):void 0,children:r?e.jsx(X,{size:13,className:"animate-spin","aria-hidden":"true"}):u?t("keys.row.remove"):t("common.save")})]}),o&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:o})]})}function mu(){const{state:s,dispatch:n}=W(),a=s.config?.openaiCompat?.url??"",[i,r]=l.useState(a),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=l.useRef(!1);l.useEffect(()=>{r(a)},[a]);const x=i.trim()!==a,p=()=>{u.current||!x||(u.current=!0,o(!0),m(null),M("/api/config",{method:"PUT",body:JSON.stringify({openaiCompat:{url:i.trim()}})}).then(h=>n({type:"configStatus",config:h})).catch(h=>m(h.message)).finally(()=>{u.current=!1,o(!1)}))};return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("keys.openaiCompat.url")}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"url",value:i,onChange:h=>r(h.target.value),onBlur:p,onKeyDown:h=>h.key==="Enter"&&p(),placeholder:"https://api.groq.com/openai/v1","aria-label":t("keys.openaiCompat.url"),spellCheck:!1,className:z(Be,"pr-8")}),c&&e.jsx(X,{size:13,"aria-hidden":"true",className:"absolute right-2.5 top-1/2 -translate-y-1/2 animate-spin text-ink-secondary"})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.openaiCompat.urlHint")}),d&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:d})]})}const pu="rounded-xl bg-card in-data-[settings-look=simple]:rounded-[12px] in-data-[settings-look=simple]:border-[0.5px] in-data-[settings-look=simple]:border-(--settings-edge) in-data-[settings-look=simple]:bg-menu",xu=1600,hu={opencodeProviders:()=>e.jsx(cu,{}),ollama:s=>e.jsx(ou,{visible:s}),lmStudio:()=>e.jsx(nu,{heading:!1}),vps:()=>e.jsx(uu,{})},gu={anthropic:()=>e.jsx(du,{}),openaiCompat:()=>e.jsxs(e.Fragment,{children:[e.jsx(mu,{}),e.jsx(Qd,{}),e.jsx(Zd,{})]}),box:()=>e.jsx(_l,{}),liveKey:()=>e.jsx(Dl,{})};function ki(s,n){if(s.kind==="uses")return!1;const a=As(s,n);return a.configured||a.included===!0}function fu({entry:s,visible:n}){const{state:a}=W(),i=l.useId(),c=As(s,a.config).configured?{tone:"ok",text:t("keys.connected")}:null;return e.jsxs("div",{"data-key-row":s.id,role:"group","aria-labelledby":i,className:Ba,children:[e.jsx(Oa,{entry:s,status:c,titleId:i}),e.jsx("div",{className:"flex flex-col gap-2 pl-8",children:hu[s.id]?.(n)})]})}function bu({entry:s}){const{state:n,dispatch:a}=W(),i=l.useId(),r=s.opens,c=As(s,n.config),o=c.configured?{tone:"ok",text:t("keys.connected")}:null;return e.jsxs("div",{"data-key-row":s.id,role:"group","aria-labelledby":i,className:Ba,children:[e.jsx(Oa,{entry:s,status:o,titleId:i}),e.jsxs("div",{className:"flex flex-col gap-2 pl-8",children:[c.configured&&e.jsx("div",{className:"flex",children:e.jsx(Fl,{saved:c,label:t(s.labelKey)})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[s.whereKey&&e.jsx("span",{className:"min-w-0 flex-1 text-[12px] leading-4 text-ink-secondary",children:t(s.whereKey)}),r&&e.jsx("button",{type:"button","data-key-open":!0,className:"ui-button shrink-0",onClick:()=>a({type:"toggleAppSettings",open:!0,section:r}),children:t("keys.row.open")})]})]})]})}function yu({entry:s,visible:n}){return s.kind==="uses"&&s.uses?e.jsx(cn,{id:s.uses,row:s.id}):s.kind==="panel"?e.jsx(fu,{entry:s,visible:n}):s.kind==="elsewhere"?e.jsx(bu,{entry:s}):e.jsx(cn,{id:s.id,children:gu[s.id]?.()})}function vu({id:s,rows:n,open:a,onToggle:i}){const{state:r}=W(),c=cs.find(u=>u.id===s),o=l.useId(),d=l.useId(),m=n.filter(u=>ki(u,r.config)).length;return e.jsxs("section",{"data-keys-section":s,"aria-labelledby":o,className:pu,children:[e.jsxs("button",{type:"button","aria-expanded":a,"aria-controls":d,onClick:i,className:"flex w-full cursor-pointer items-center gap-3 rounded-[inherit] px-4 py-2.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus/60",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{id:o,className:"text-[14px] font-medium leading-5 text-ink",children:t(c.titleKey)}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t(c.purposeKey)})]}),m>0&&e.jsx("span",{className:"shrink-0 text-[12px] leading-4 text-ink-secondary",children:t("keys.section.connected",{count:m})}),e.jsx(Ts,{size:14,"aria-hidden":"true",className:z("shrink-0 text-ink-secondary transition-transform motion-reduce:transition-none",a&&"rotate-90")})]}),e.jsxs("div",{id:d,hidden:!a,className:"flex flex-col gap-0.5 border-t border-hairline/40 px-1 py-1.5 in-data-[settings-look=simple]:border-t-[0.5px] in-data-[settings-look=simple]:border-(--settings-edge)",children:[n.map(u=>e.jsx(yu,{entry:u,visible:a},u.id)),s==="voice"&&e.jsx(Gd,{})]})]})}function ju(s,n,a){const i=n.row?s?.querySelector(`[data-key-row="${n.row}"]`):s?.querySelector(`[data-keys-section="${a}"]`);if(!i||i.closest("[hidden]"))return!1;const r=Wd(i);return r&&Bs(r,i,n.row?"center":"start",16),n.row&&(i.querySelector("[data-key-input], [data-key-replace], [data-key-own], [data-key-open], input, button")?.focus({preventScroll:!0}),i.setAttribute("data-key-highlight",""),window.setTimeout(()=>i.removeAttribute("data-key-highlight"),xu)),!0}function ku(){const{state:s}=W(),[n,a]=l.useState(""),[i,r]=l.useState(()=>new Set(cs.filter(p=>p.id==="ai"||lt.some(h=>h.section===p.id&&ki(h,s.config))).map(p=>p.id))),c=l.useRef(null),o=La(),d=n.trim().toLowerCase();l.useEffect(()=>{if(!o)return;const p=lt.find(b=>b.id===o.row)?.section??"ai";a(""),r(b=>b.has(p)?b:new Set([...b,p]));let h=0,f=0;const y=()=>{ju(c.current,o,p)||++f>60?Ul(o):h=window.requestAnimationFrame(y)};return h=window.requestAnimationFrame(y),()=>window.cancelAnimationFrame(h)},[o]);const m=s.config?.live?.provider==="azure",u=lt.filter(p=>Es(p,d)&&!(m&&p.id==="liveCalls")),x=cs.flatMap(p=>{const h=u.filter(f=>f.section===p.id);return h.length>0?[{id:p.id,rows:h}]:[]});return e.jsxs("div",{ref:c,"data-keys-page":!0,className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.connections.subtitle")}),e.jsxs("div",{className:"flex h-8 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] focus-within:ring-2 focus-within:ring-focus/60",children:[e.jsx(mt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-keys-search":!0,type:"text",value:n,onChange:p=>a(p.target.value),onKeyDown:p=>{p.key!=="Escape"||!n||(p.preventDefault(),p.stopPropagation(),a(""))},placeholder:t("keys.search.placeholder"),"aria-label":t("keys.search.aria"),autoComplete:"off",spellCheck:!1,className:"w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),x.length===0?e.jsx("p",{"data-keys-empty":!0,className:"px-1 text-[13px] leading-[18px] text-ink-secondary",children:t("keys.search.none",{query:n.trim()})}):x.map(({id:p,rows:h})=>e.jsx(vu,{id:p,rows:h,open:d!==""||i.has(p),onToggle:()=>r(f=>{const y=new Set(f);return y.has(p)?y.delete(p):y.add(p),y})},p))]})}function Ni({simple:s=!1}){return null}function wi({simple:s=!1}){const n=window.ogb?.openAtLogin,[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(!1);if(l.useEffect(()=>{let u=!0;return n?.state().then(x=>{u&&i(x)}).catch(()=>{}),()=>{u=!1}},[n]),!n||!a?.available)return null;const m=u=>{c(!0),d(!1),n.set(u).then(x=>{i(x),d(x.on!==u)},()=>d(!0)).finally(()=>c(!1))};return e.jsx(ue,{title:t("settings.openAtLogin.title"),subtitle:t(s?"settings.simple.openAtLogin":"settings.openAtLogin.subtitle"),message:o?e.jsx("span",{role:"alert",className:"text-danger",children:t("settings.openAtLogin.failed")}):void 0,children:e.jsx(me,{checked:a.on,disabled:r,"aria-label":t("settings.openAtLogin.title"),onClick:()=>m(!a.on)})})}function Nu(s=typeof window>"u"?void 0:window.ogb){return s?.platform==="darwin"&&s.talkShortcut?["talk","voice","shortcut","hotkey","hold to talk","push to talk","quick asks"]:[]}function Si(){const s=window.ogb?.talkShortcut,[n,a]=l.useState(null),[i,r]=l.useState(!1),[c,o]=l.useState(!1);if(l.useEffect(()=>{let p=!0;return s?.state().then(h=>{p&&a(h)}).catch(()=>{}),()=>{p=!1}},[s]),!s||!n?.available)return null;const d=n.keys.find(p=>p.id===n.key)?.label??"",m=p=>{r(!0),o(!1),s.set(p).then(a,()=>o(!0)).finally(()=>r(!1))},u=c?t("settings.talk.failed"):n.enabled&&n.taken?t("settings.talk.taken",{key:d}):null,x=e.jsxs(e.Fragment,{children:[n.enabled&&e.jsx(xe,{size:"sm",className:"w-full max-w-[240px]",value:n.key,disabled:i,"aria-label":t("settings.talk.keyAria"),onChange:p=>m({key:p.target.value}),children:n.keys.map(p=>e.jsx("option",{value:p.id,children:p.label},p.id))}),u&&e.jsx("div",{role:"alert",className:n.enabled?"mt-2 text-danger":"text-danger",children:u})]});return e.jsx(ue,{title:t("settings.talk.title"),subtitle:t("settings.talk.subtitle",{key:d}),message:n.enabled||u?x:null,children:e.jsx(me,{checked:n.enabled,disabled:i,"aria-label":t("settings.talk.aria"),onClick:()=>m({enabled:!n.enabled})})})}const Yt=s=>s===0||s>=1024*1024?`${Math.round(s/(1024*1024))} MB`:`${Math.ceil(s/1024)} KB`;function Ci(){const[s,n]=l.useState(null),[a,i]=l.useState(!1),[r,c]=l.useState(!1),[o,d]=l.useState(null);if(l.useEffect(()=>{let u=!0;return M("/api/attachment-storage").then(x=>{u&&n(x)}).catch(()=>{}),()=>{u=!1}},[]),!s)return null;const m=async()=>{c(!0),d(null);try{const u=await M("/api/attachment-storage",{method:"POST"});n(u);const x=t("settings.attachments.cleared",{count:u.removed,freed:Yt(u.freedBytes)});d(u.failed>0?{kind:"error",message:`${x} ${t("settings.attachments.failed",{count:u.failed})}`}:{kind:"success",message:x})}catch(u){d({kind:"error",message:u instanceof Error?u.message:String(u)})}finally{c(!1),i(!1)}};return e.jsx(ue,{title:t("settings.attachments.title"),subtitle:e.jsxs(e.Fragment,{children:[e.jsx("span",{"data-attachments-used":!0,className:"block",children:t("settings.attachments.used",{used:Yt(s.usedBytes),max:Yt(s.maxBytes)})}),e.jsx("span",{className:"block",children:t(a?"settings.attachments.confirmText":"settings.attachments.help")})]}),message:o&&e.jsx("p",{role:o.kind==="error"?"alert":"status",className:z(o.kind==="error"?"text-danger":"text-success"),children:o.message}),children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>i(!1),disabled:r,className:"ui-button",children:t("settings.attachments.cancel")}),e.jsx("button",{type:"button",onClick:()=>{m()},disabled:r,className:"ui-button text-danger",children:r?t("settings.attachments.clearing"):t("settings.attachments.confirm")})]}):e.jsx("button",{type:"button",onClick:()=>{d(null),i(!0)},className:"ui-button",children:t("settings.attachments.clear")})})})}function Ei({simple:s=!1}){const[n,a]=l.useState(!1),[i,r]=l.useState(null),[c,o]=l.useState(null),d=async()=>{if(!(!window.ogb?.exportDiagnostics||n)){a(!0),r(null);try{const x=await window.ogb.exportDiagnostics();x&&r({kind:"success",message:t("settings.diagnostics.saved",{path:x})})}catch(x){r({kind:"error",message:x instanceof Error?x.message:String(x)})}finally{a(!1)}}},m=async()=>{if(window.ogb?.openLogsFolder){r(null);try{const x=await window.ogb.openLogsFolder();o(x.folder),x.opened||r({kind:"error",message:t("settings.diagnostics.openFailed",{folder:x.folder})})}catch(x){r({kind:"error",message:x instanceof Error?x.message:String(x)})}}},u=!!window.ogb?.exportDiagnostics;return e.jsx(ue,{title:t("settings.diagnostics.title"),subtitle:t(s?"settings.simple.diagnostics":"settings.diagnostics.subtitle"),message:e.jsxs(e.Fragment,{children:[c&&i?.kind!=="error"&&e.jsx("p",{role:"status","data-logs-folder":!0,className:"break-all text-ink-secondary",children:t("settings.diagnostics.logsAt",{folder:c})}),i&&e.jsx("p",{role:i.kind==="error"?"alert":"status",className:z("break-all",i.kind==="error"?"text-danger":"text-success"),children:i.message}),e.jsx("p",{"data-logs-help":!0,className:"text-ink-tertiary",children:t(u?"settings.diagnostics.logsHelp":"settings.diagnostics.elsewhere")})]}),children:u&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[window.ogb?.openLogsFolder&&e.jsx("button",{type:"button",onClick:()=>{m()},className:"ui-button",children:t("settings.diagnostics.openLogs")}),e.jsx("button",{onClick:()=>{d()},disabled:n,"aria-label":t("settings.diagnostics.aria"),className:"ui-button",children:n?t("settings.diagnostics.exporting"):t("settings.diagnostics.export")})]})})}const wu="https://dash.cloudflare.com/profile/api-tokens",Su=/^[0-9a-f]{32}$/i,Tn="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none";function Cu({failureText:s}){const{state:n,dispatch:a}=W(),i=n.config?.helpers,r=i?.own.workersAi===!0,c=i?.workersAiAccountId??"",[o,d]=l.useState(null),[m,u]=l.useState(""),[x,p]=l.useState(!1),[h,f]=l.useState(!1),[y,b]=l.useState(null),[g,k]=l.useState(null),S=(o??c).trim(),C=m.trim(),w=!C&&r&&o===null,P=o!==null&&S!==c,v=A=>a({type:"configStatus",config:A}),B=async()=>{if(!(x||!C&&!r&&!P)){if(C&&!Su.test(S))return b(t("decider.workersAi.needsAccount"));p(!0),b(null),k(null);try{(P||C&&!c)&&v(await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiAccountId:S}})})),(C||w)&&v(window.ogb?.setCredential?await window.ogb.setCredential("workersAiToken",C):await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiToken:C}})})),u(""),d(null)}catch(A){b(A instanceof Error?A.message:String(A))}finally{p(!1)}}},j=async()=>{if(!(h||x||!C&&!r)){f(!0),k(null),b(null);try{const A=await M("/api/decider/test",{method:"POST",body:JSON.stringify({provider:"workersai",...C?{key:C,accountId:S}:{}})}),I=A.extraction?[t(A.extraction.ok?"decider.test.extractionOk":"decider.test.extractionFailed")]:[];k(A.ok?{ok:A.extraction?.ok!==!1,text:[t("decider.workersAi.test.ok",{ms:String(A.latencyMs)}),...I].join(" ")}:{ok:!1,text:s(A)})}catch(A){k({ok:!1,text:A instanceof Error?A.message:String(A)})}finally{f(!1)}}};return e.jsxs(Y,{title:t("decider.workersAi.title"),children:[e.jsx("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.workersAi.detail")}),r&&e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-success"}),e.jsx("span",{children:t("decider.status.connected")})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("input",{type:"text","data-testid":"workers-ai-account",value:o??c,onChange:A=>{k(null),b(null),d(A.target.value)},disabled:x,placeholder:t("decider.workersAi.accountIdPlaceholder"),"aria-label":t("decider.workersAi.accountId"),autoComplete:"off",spellCheck:!1,className:Tn}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password","data-testid":"workers-ai-token",value:m,onChange:A=>{k(null),b(null),u(A.target.value)},onKeyDown:A=>A.key==="Enter"&&void B(),disabled:x,placeholder:r?t("keys.replace"):t("decider.workersAi.tokenPlaceholder"),"aria-label":t("decider.workersAi.token"),autoComplete:"off",spellCheck:!1,className:Tn}),e.jsx("button",{type:"button","data-testid":"workers-ai-save",onClick:()=>{B()},disabled:x||!C&&!r&&!P,title:w?t("keys.removeKey"):t("common.save"),className:z("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",w?"text-danger":"text-ink"),children:x?e.jsx(X,{size:13,className:"animate-spin"}):w?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"workers-ai-test",onClick:()=>{j()},disabled:h||x||!C&&!r,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:h?t("keys.testing"):t("keys.test")})]})]}),y&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:y}),g&&e.jsx("p",{role:"status",className:z("mt-1 text-[12px]",g.ok?"text-success":"text-danger"),children:g.text}),e.jsxs("a",{href:wu,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t("decider.workersAi.getKey"),e.jsx(pt,{size:11,"aria-hidden":"true"})]})]})}const Eu={jev:"https://typesafe.ai",openrouter:"https://openrouter.ai/keys"},Au=1500,Ms={rejected:"decider.error.rejected",unreachable:"decider.error.unreachable",timeout:"decider.error.timeout",rate_limited:"decider.error.rateLimited",overloaded:"decider.error.overloaded",malformed:"decider.error.malformed",no_key:"decider.error.noKey",misconfigured:"decider.error.misconfigured"},Rn={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"},Iu={...Ms,rejected:"decider.openrouter.error.rejected",unreachable:"decider.openrouter.error.unreachable",timeout:"decider.openrouter.error.timeout",rate_limited:"decider.openrouter.error.rateLimited",overloaded:"decider.openrouter.error.overloaded",malformed:"decider.openrouter.error.malformed"},Pu={...Ms,rejected:"decider.workersAi.error.rejected",unreachable:"decider.workersAi.error.unreachable",timeout:"decider.workersAi.error.timeout",rate_limited:"decider.workersAi.error.rateLimited",overloaded:"decider.workersAi.error.overloaded",malformed:"decider.workersAi.error.malformed"},Qt={jev:"decider.status.byJev",workersai:"decider.status.byWorkersAi",openrouter:"decider.status.byOpenRouter"};function Tu(s){const n=s?.decider,a=s?.helpers?.extraction,i=n?.configured?n.included?t("decider.status.byCloud"):t(Qt[n.provider]??Qt.jev):t("decider.status.notSetUp"),r=a?.provider?a.included?t("decider.status.byCloud"):t(Qt[a.provider]):t("decider.status.notSetUp");return t("decider.status.line",{decisions:i,extraction:r})}function Ln(s,n=!1,a="jev"){if(a==="workersai"){if(s.reason==="http_error")return t("decider.workersAi.error.http",{status:String(s.status??"?")});const r=Pu[s.reason];return r?t(r):t("decider.error.other")}if(a==="openrouter"){if(s.reason==="http_error"&&s.status===402)return t("decider.openrouter.error.credits");if(s.reason==="http_error")return t("decider.openrouter.error.http",{status:String(s.status??"?")});const r=Iu[s.reason];return r?t(r):t("decider.error.other")}if(n&&s.reason==="http_error"&&s.status===402)return t("decider.included.error.subscription");if(n&&Rn[s.reason])return t(Rn[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const i=Ms[s.reason];return i?t(i):t("decider.error.other")}const Ru=["decider.jobs.browserClicks","decider.jobs.toolSelection","decider.jobs.placement"];function Lu(){const{state:s,dispatch:n}=W(),a=s.config?.decider,i=a?.selectedProvider??(a?.provider==="openrouter"?"openrouter":"jev"),r=i==="workersai",c=i==="openrouter",o=a?.configured??!1,d=o&&a?.included===!0,m=c&&o&&a?.keySource==="shared",u=c&&a?.sharedKey===!0,x=o&&!d&&!m,p=a?.enabled??!1,h=a?.jobs.roomRouting??!0,[f,y]=l.useState(""),[b,g]=l.useState(!1),[k,S]=l.useState(!1),[C,w]=l.useState(!1),[P,v]=l.useState(null),[B,j]=l.useState(null),[A,I]=l.useState(null),_=f.trim(),U=!_&&x,J=!c||d?null:m?"decider.openrouter.status.sharedHint":o?u?"decider.openrouter.status.ownFallbackHint":null:"decider.openrouter.status.notConnectedHint",K=T=>n({type:"configStatus",config:T}),te=async T=>{if(!k){S(!0),v(null);try{K(await M("/api/config",{method:"PUT",body:JSON.stringify({decider:T})}))}catch(Z){v(Z instanceof Error?Z.message:String(Z))}finally{S(!1)}}};l.useEffect(()=>{if(!c||A)return;let T=!1;return M("/api/decider/models").then(Z=>{T||I(Z)},()=>{}),()=>{T=!0}},[c,A]);const ae=T=>{y(""),j(null),te(T)},de=async()=>{if(!(b||!_&&!x)){g(!0),v(null),j(null);try{const T=window.ogb?.setCredential?await window.ogb.setCredential(c?"openrouterDeciderKey":"jevApiKey",_):await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{[c?"openrouterKey":"key"]:_}})});K(T),y("")}catch(T){v(T instanceof Error?T.message:String(T))}finally{g(!1)}}},D=async()=>{if(C||b||!_&&!o)return;w(!0),j(null),v(null);const T=!_&&d,Z=!_&&m;try{const ee=await M("/api/decider/test",{method:"POST",body:JSON.stringify(_?{key:_}:{})});j(ee.ok?{ok:!0,text:c?[t(Z?"decider.openrouter.test.okShared":"decider.openrouter.test.ok",{ms:String(ee.latencyMs)}),...ee.latencyMs>Au?[t("decider.test.slow")]:[]].join(" "):t("decider.test.ok",{ms:String(ee.latencyMs)})}:{ok:!1,text:Ln(ee,T,i)})}catch(ee){j({ok:!1,text:ee instanceof Error?ee.message:String(ee)})}finally{w(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2 px-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("decider.intro")}),e.jsx("p",{role:"status","data-testid":"helpers-status",className:"text-[13px] font-medium text-ink",children:Tu(s.config)})]}),e.jsx(Cu,{failureText:T=>Ln(T,!1,"workersai")}),e.jsx(ue,{title:t("decider.provider.label"),children:e.jsxs(xe,{className:"w-48","data-testid":"decider-provider",value:i,onChange:T=>ae({provider:T.target.value}),disabled:k||!s.config,"aria-label":t("decider.provider.label"),children:[e.jsx("option",{value:"jev",children:t("decider.provider.jev")}),e.jsx("option",{value:"workersai",children:"Cloudflare Workers AI"}),e.jsx("option",{value:"openrouter",children:t("decider.provider.openrouter")})]})}),c&&e.jsx(ue,{title:t("decider.model.label"),subtitle:A?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs(xe,{className:"w-64 max-w-full","data-testid":"decider-model",value:a?.model??"",onChange:T=>ae({openrouterModel:T.target.value,openrouterApi:A?.models.find(Z=>Z.id===T.target.value)?.api??"chat"}),disabled:k,"aria-label":t("decider.model.label"),children:[a?.model&&!A?.models.some(T=>T.id===a.model)&&e.jsx("option",{value:a.model,children:a.model}),["recommended","more"].map(T=>{const Z=A?.models.filter(ee=>ee.group===T)??[];return Z.length>0&&e.jsx("optgroup",{label:t(T==="recommended"?"decider.model.recommended":"decider.model.more"),children:Z.map(ee=>e.jsx("option",{value:ee.id,children:ee.name},ee.id))},T)})]})}),e.jsx(ue,{title:t(c?"decider.openrouter.master":"decider.master"),subtitle:o?void 0:t(r?"decider.workersAi.needsAccount":c?"decider.masterNeedsKey.openrouter":"decider.masterNeedsKey"),children:e.jsx(me,{"data-testid":"decider-master","aria-label":t(c?"decider.openrouter.master":"decider.master"),checked:p,disabled:!o||k||!s.config,onClick:()=>{te({enabled:!p})},className:"cursor-pointer"})}),!r&&e.jsxs(Y,{title:t(c?"decider.openrouter.key.label":"decider.key.label"),children:[e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:z("size-1.5 rounded-full",o?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:o?"text-success":void 0,children:d?t("keys.includedWithCloudPro"):m?t("decider.openrouter.status.shared"):o?t(u?"decider.openrouter.status.own":"decider.status.connected"):t("decider.status.notConnected")})]}),J&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(J),!x&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button","data-testid":"decider-manage-keys",onClick:()=>n(ds("openrouter")),className:"cursor-pointer text-accent hover:underline",children:t("decider.openrouter.key.manageLink")})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:f,onChange:T=>{j(null),v(null),y(T.target.value)},onKeyDown:T=>T.key==="Enter"&&void de(),disabled:b,placeholder:x?t("keys.replace"):t(m?"decider.openrouter.key.overridePlaceholder":c?"decider.openrouter.key.placeholder":"decider.key.placeholder"),"aria-label":t(c?"decider.openrouter.key.label":"decider.key.label"),autoComplete:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("button",{type:"button","data-testid":"decider-save",onClick:()=>{de()},disabled:b||!_&&!x,title:U?t("keys.removeKey"):t("common.save"),className:z("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",U?"text-danger":"text-ink"),children:b?e.jsx(X,{size:13,className:"animate-spin"}):U?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{D()},disabled:C||b||!_&&!o,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:C?t("keys.testing"):t("keys.test")})]}),P&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:P}),B&&e.jsx("p",{role:"status",className:z("mt-1 text-[12px]",B.ok?"text-success":"text-danger"),children:B.text}),!m&&e.jsxs("a",{href:Eu[i],target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t(c?"decider.openrouter.key.getKey":"decider.key.getKey"),e.jsx(pt,{size:11,"aria-hidden":"true"})]})]}),r&&P&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] text-danger",children:P}),e.jsx(Y,{title:t("decider.jobs.title"),children:e.jsxs("ul",{className:"flex flex-col",children:[e.jsxs("li",{className:"flex items-start justify-between gap-4 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("decider.jobs.roomRouting")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.jobs.roomRoutingDetail")})]}),e.jsx(me,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:p&&h,disabled:!p||k,onClick:()=>{te({jobs:{roomRouting:!h}})},className:"cursor-pointer"})]}),Ru.map(T=>e.jsxs("li",{"data-testid":"decider-coming-soon","aria-disabled":"true",className:"flex items-center justify-between gap-4 border-t border-hairline/40 py-2 opacity-50",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t(T)}),e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink-secondary",children:t("decider.jobs.comingSoon")})]},T))]})})]})}const Bu=["openai","xai","gemini","openrouter","custom"],Ou=4,Ai={openai:"gpt-image-2",xai:"grok-imagine-image-2.0",gemini:"gemini-2.5-flash-image",openrouter:"google/gemini-2.5-flash-image",custom:""},Mu={openai:[{id:"gpt-image-2",name:"GPT Image 2"},{id:"gpt-image-1",name:"GPT Image 1"},{id:"gpt-image-1-mini",name:"GPT Image 1 Mini"}],xai:[{id:"grok-imagine-image-2.0",name:"Grok Imagine Image 2.0"}],gemini:[{id:"gemini-2.5-flash-image",name:"Nano Banana (Gemini 2.5 Flash Image)"}],openrouter:[{id:"google/gemini-2.5-flash-image",name:"Google: Nano Banana (Gemini 2.5 Flash Image)"},{id:"google/gemini-3.1-flash-image",name:"Google: Nano Banana 2 (Gemini 3.1 Flash Image)"},{id:"google/gemini-3-pro-image",name:"Google: Nano Banana Pro (Gemini 3 Pro Image)"},{id:"openai/gpt-image-2",name:"OpenAI: GPT Image 2"},{id:"black-forest-labs/flux-3-image",name:"Black Forest Labs: FLUX 3 Image"},{id:"bytedance-seed/seedream-5-0-pro",name:"ByteDance Seed: Seedream 5.0 Pro"},{id:"x-ai/grok-imagine-image-2.0",name:"xAI: Grok Imagine Image 2.0"},{id:"qwen/qwen-image-3",name:"Qwen: Qwen Image 3"}],custom:[]};function zu(s){const n="Use an HTTPS API base URL, or HTTP for a local router, without passwords, query parameters or fragments";let a;try{a=new URL(s.trim())}catch{throw new Error(n)}if(s.length>2048||a.username||a.password||a.search||a.hash)throw new Error(n);const i=a.hostname.toLowerCase(),r=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(i),c=i==="localhost"||i.endsWith(".localhost")||i.endsWith(".local")||i==="host.docker.internal"||i==="host.containers.internal"||i==="[::1]"||/^\[f[cd][0-9a-f]{2}:/.test(i)||r&&(Number(r[1])===127||Number(r[1])===10||Number(r[1])===192&&Number(r[2])===168||Number(r[1])===172&&Number(r[2])>=16&&Number(r[2])<=31);if(a.protocol!=="https:"&&!(a.protocol==="http:"&&c))throw new Error(n);if(r&&(Number(r[1])===0||Number(r[1])===169&&Number(r[2])===254))throw new Error(n);return a.pathname=a.pathname.replace(/\/+$/,"").replace(/\/(images\/generations|responses)$/,""),a.toString().replace(/\/+$/,"")}const Et={openai:"OpenAI",xai:"Grok (xAI)",gemini:"Gemini",openrouter:"OpenRouter",custom:"Custom"},Uu={openai:{credential:"openaiImageApiKey",patch:s=>({imageGen:{key:s}}),label:"imageGen.key.openai"},gemini:{credential:"geminiImageApiKey",patch:s=>({imageGen:{geminiKey:s}}),label:"imageGen.key.gemini"},custom:{credential:"customImageApiKey",patch:s=>({imageGen:{customApiKey:s}}),label:"imageGen.key.custom"}},Fu={xai:{label:"imageGen.key.xai",note:"imageGen.key.sharedXai"},openrouter:{label:"imageGen.key.openrouter",note:"imageGen.key.sharedOpenrouter"}},Bn={openai:"https://platform.openai.com/api-keys",gemini:"https://aistudio.google.com/apikey",xai:"https://console.x.ai",openrouter:"https://openrouter.ai/keys"},gs="w-full min-w-0 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50",At="flex shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",Zt="\0other";function Du(s,n){return n.ok?n.freeTier?{ok:!1,text:t("imageGen.test.noCredit")}:{ok:!0,text:t(s==="openrouter"?"imageGen.test.okOpenrouter":"imageGen.test.ok")}:n.reason==="model_missing"?{ok:!1,text:t("imageGen.test.modelMissing",{model:n.model})}:n.reason==="rejected"?{ok:!1,text:t("imageGen.test.rejected")}:n.reason==="unreachable"?{ok:!1,text:t("imageGen.test.unreachable")}:n.reason==="no_key"?{ok:!1,text:t("imageGen.key.missing")}:n.reason==="no_url"?{ok:!1,text:t("imageGen.test.noUrl")}:{ok:!1,text:t("imageGen.test.unexpected")}}function _u(s,n){return n==="openai"?s?.openaiConfigured===!0:n==="xai"?s?.xaiConfigured===!0:n==="gemini"?s?.geminiConfigured===!0:n==="openrouter"?s?.openrouterConfigured===!0:s?.customKeyConfigured===!0}function $u(){const{state:s,dispatch:n}=W(),a=s.config?.imageGen,i=a?.primary??{provider:a?.provider??"openai",model:a?.model??Ai.openai,configured:a?.configured===!0},r=a?.fallback??null,[c,o]=l.useState(!1),[d,m]=l.useState(null),[u,x]=l.useState(null),p=i.provider==="openrouter"||r?.provider==="openrouter";l.useEffect(()=>{if(!p||u)return;let b=!1;return M("/api/images/openrouter-models").then(g=>{b||x(Array.isArray(g?.models)?g:{source:"builtin",models:[]})},()=>{b||x({source:"builtin",models:[]})}),()=>{b=!0}},[p,u]);const h=async b=>{o(!0),m(null);try{const g=await M("/api/config",{method:"PUT",body:JSON.stringify(b)});n({type:"configStatus",config:g})}catch(g){m(g instanceof Error?g.message:String(g))}finally{o(!1)}},f=(b,g)=>{if(b==="fallback"&&g==="")return void h({imageGen:{fallback:null}});const k=g,S=b==="primary"&&r?.provider===k;h({imageGen:{[b]:{provider:k},...S?{fallback:null}:{}}})},y=[i.provider,...r?[r.provider]:[]].filter((b,g,k)=>k.indexOf(b)===g);return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2 px-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("imageGen.intro")}),e.jsxs("p",{role:"status","data-testid":"image-gen-status",className:"flex items-center gap-2 text-[13px] font-medium text-ink",children:[e.jsx("span",{className:z("size-1.5 shrink-0 rounded-full",a?.ready?i.configured?"bg-success":"bg-warning":"bg-raised-hover")}),a?.ready?i.configured?t("imageGen.status.ready",{provider:Et[i.provider]}):t("imageGen.status.backupOnly",{provider:Et[r.provider]}):t("imageGen.status.notReady")]})]}),e.jsx(Ku,{disabled:c}),e.jsx(On,{slot:"primary",provider:i.provider,model:i.model,configured:i.configured,openrouterModels:u,disabled:c||!s.config,onProvider:f,onModel:b=>{h({imageGen:{primary:{provider:i.provider,model:b}}})}}),e.jsx(On,{slot:"fallback",provider:r?.provider??null,model:r?.model??"",configured:r?.configured===!0,exclude:i.provider,openrouterModels:u,disabled:c||!s.config,onProvider:f,onModel:b=>r&&void h({imageGen:{fallback:{provider:r.provider,model:b}}})}),e.jsx(ue,{title:t("imageGen.maxPerTurn.label"),subtitle:t("imageGen.maxPerTurn.help"),children:e.jsx(xe,{className:"w-20","data-testid":"image-gen-max",value:String(a?.maxPerTurn??Ou),onChange:b=>{h({imageGen:{maxPerTurn:Number(b.target.value)}})},disabled:c||!s.config,"aria-label":t("imageGen.maxPerTurn.label"),children:Array.from({length:10},(b,g)=>g+1).map(b=>e.jsx("option",{value:b,children:b},b))})}),d&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] text-danger",children:d}),y.map(b=>e.jsx(Wu,{provider:b,status:a},b))]})}function Ku({disabled:s}){const{dispatch:n}=W(),[a,i]=l.useState(null),[r,c]=l.useState(""),[o,d]=l.useState(!1),[m,u]=l.useState(""),x=async p=>{d(!0),u("");try{if(p){const h=await M("/api/images/connections",{method:"POST",body:JSON.stringify({id:r})});n({type:"configStatus",config:h}),i(null),c("")}else{const h=await M("/api/images/connections");i(h.connections),c(h.connections[0]?.id??"")}}catch(h){u(h instanceof Error?h.message:String(h))}finally{d(!1)}};return e.jsxs(Y,{title:t("imageGen.saved.title"),children:[e.jsx("p",{className:"mb-2 text-[12px] text-ink-secondary",children:t("imageGen.saved.help")}),a===null?e.jsx("button",{type:"button",className:At,disabled:o||s,onClick:()=>{x(!1)},children:t("imageGen.saved.title")}):a.length?e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(xe,{"aria-label":t("imageGen.saved.title"),value:r,disabled:o,onChange:p=>c(p.target.value),children:a.map(p=>e.jsxs("option",{value:p.id,children:[p.name," · ",p.url]},p.id))}),e.jsx("button",{type:"button",className:At,disabled:o||s||!r,onClick:()=>{x(!0)},children:t("imageGen.saved.apply")})]}):e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("imageGen.saved.empty")}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m})]})}function On({slot:s,provider:n,model:a,configured:i,exclude:r,openrouterModels:c,disabled:o,onProvider:d,onModel:m}){const u=t(s==="primary"?"imageGen.primary.label":"imageGen.fallback.label");return e.jsxs(e.Fragment,{children:[e.jsx(ue,{title:u,subtitle:n&&!i?t(n==="custom"?"imageGen.slot.needsConnection":"imageGen.slot.needsKey"):t(s==="primary"?"imageGen.primary.help":"imageGen.fallback.help"),children:e.jsxs(xe,{className:"w-48","data-testid":`image-gen-${s}`,value:n??"",onChange:x=>d(s,x.target.value),disabled:o,"aria-label":u,children:[s==="fallback"&&e.jsx("option",{value:"",children:t("imageGen.fallback.none")}),Bu.filter(x=>x!==r).map(x=>e.jsx("option",{value:x,children:Et[x]},x))]})}),n&&e.jsx(Hu,{slot:s,slotLabel:u,provider:n,model:a,openrouterModels:c,disabled:o,onModel:m})]})}function Hu({slot:s,slotLabel:n,provider:a,model:i,openrouterModels:r,disabled:c,onModel:o}){const[d,m]=l.useState(null),{state:u}=W(),x=a==="custom"&&u.config?.imageGen?.customApi==="responses",h=(a==="openrouter"&&r?.source==="openrouter"?r.models:null)??(x?[{id:"gpt-6.1-sol",name:"GPT-6.1 Sol"},{id:"gpt-6-astra",name:"GPT-6 Astra"}]:Mu[a]).map(g=>({...g,group:"recommended"})),f=d!==null||h.length===0,y=()=>{d!==null&&(m(null),d.trim()&&d.trim()!==i&&o(d.trim()))},b=g=>{if(g===Zt)return m(i);m(null),o(g)};return e.jsx(ue,{title:t("decider.model.label"),subtitle:a==="openrouter"&&r?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[h.length>0&&e.jsxs(xe,{className:"w-64 max-w-full","data-testid":`image-gen-${s}-model`,value:f?Zt:i,onChange:g=>b(g.target.value),disabled:c,"aria-label":t("imageGen.model.label",{slot:n}),children:[!i&&e.jsx("option",{value:"",disabled:!0,children:t("imageGen.model.placeholder")}),i&&!h.some(g=>g.id===i)&&e.jsx("option",{value:i,children:i}),["recommended","more"].map(g=>{const k=h.filter(S=>S.group===g);return k.length>0&&e.jsx("optgroup",{label:t(g==="recommended"?"decider.model.recommended":"decider.model.more"),children:k.map(S=>e.jsx("option",{value:S.id,children:S.name},S.id))},g)}),e.jsx("option",{value:Zt,children:t("imageGen.model.other")})]}),f&&e.jsx("input",{value:d??i,onChange:g=>m(g.target.value),onBlur:y,onKeyDown:g=>g.key==="Enter"&&y(),disabled:c,placeholder:Ai[a]||t("imageGen.model.placeholder"),"aria-label":t("imageGen.model.idLabel",{slot:n}),autoComplete:"off",spellCheck:!1,className:z(gs,"w-64 max-w-full")})]})})}function Wu({provider:s,status:n}){const{dispatch:a}=W(),[i,r]=l.useState(""),[c,o]=l.useState(null),[d,m]=l.useState(!1),[u,x]=l.useState(null),[p,h]=l.useState(!1),[f,y]=l.useState(null),b=s==="openrouter"?[n?.primary,n?.fallback].filter(I=>I?.provider===s).map(I=>I?.model).join(" "):"",g=f?.models===b?f:null,k=I=>y(I&&{...I,models:b}),S=_u(n,s),C=s==="openai"||s==="gemini"||s==="custom"?Uu[s]:null,w=s==="xai"||s==="openrouter"?Fu[s]:null,P=c??n?.customUrl??"",v=async I=>{m(!0),x(null),k(null);try{a({type:"configStatus",config:await I()}),r(""),o(null)}catch(_){x(_ instanceof Error?_.message:String(_))}finally{m(!1)}},B=I=>v(async()=>s==="xai"||s==="openrouter"?$l(s,I,!1):window.ogb?.setCredential&&C?window.ogb.setCredential(C.credential,I):M("/api/config",{method:"PUT",body:JSON.stringify(C.patch(I))})),j=()=>v(async()=>{const I=P.trim()?zu(P.trim()):"";return M("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customUrl:I}})})}),A=async()=>{h(!0),k(null);try{k(Du(s,await M("/api/images/test",{method:"POST",body:JSON.stringify({provider:s})})))}catch(I){k({ok:!1,text:I instanceof Error?I.message:String(I)})}finally{h(!1)}};return e.jsxs(Y,{title:Et[s],children:[e.jsx(Gu,{configured:S,optional:s==="custom"}),w&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(w.note)," ",e.jsx("button",{type:"button",onClick:()=>a({type:"toggleAppSettings",open:!0,section:"connections"}),className:"cursor-pointer text-accent hover:underline",children:t("imageGen.key.manage")})]}),s==="custom"&&e.jsxs("div",{className:"mb-3 space-y-2",children:[e.jsx("label",{className:"block text-[13px] text-ink-secondary",children:t("imageGen.custom.api")}),e.jsxs(xe,{"aria-label":t("imageGen.custom.api"),value:n?.customApi??"images",disabled:d,onChange:I=>{v(()=>M("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customApi:I.target.value}})}))},children:[e.jsx("option",{value:"images",children:"Images API"}),e.jsx("option",{value:"responses",children:"Responses API · image_generation"})]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("imageGen.custom.apiHelp")}),n?.customApi==="responses"&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:n.customLocalImageExtension===!0,disabled:d,onChange:I=>{v(()=>M("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customLocalImageExtension:I.target.checked}})}))}}),t("imageGen.custom.extension")]})]}),s==="custom"&&e.jsxs("div",{className:"mb-2 flex gap-2",children:[e.jsx("input",{type:"url",value:P,onChange:I=>o(I.target.value),onKeyDown:I=>I.key==="Enter"&&void j(),disabled:d,placeholder:"http://127.0.0.1:4000/v1","aria-label":t("imageGen.custom.url"),autoComplete:"off",className:gs}),e.jsxs("button",{type:"button",onClick:()=>{j()},disabled:d||c===null,className:At,children:[d?e.jsx(X,{size:13,className:"animate-spin"}):e.jsx(ge,{size:13}),t("common.save")]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:i,onChange:I=>r(I.target.value),onKeyDown:I=>I.key==="Enter"&&i.trim()&&void B(i.trim()),disabled:d,placeholder:S?t("keys.replace"):t("imageGen.key.paste"),"aria-label":t((C??w).label),autoComplete:"off",spellCheck:!1,className:gs}),e.jsxs("button",{type:"button",onClick:()=>{B(i.trim())},disabled:d||!i.trim(),className:At,children:[d?e.jsx(X,{size:13,className:"animate-spin"}):e.jsx(ge,{size:13}),t("common.save")]}),S&&e.jsx("button",{type:"button",onClick:()=>{A()},disabled:p||d,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:p?t("keys.testing"):t("keys.test")})]}),g&&e.jsx("p",{role:"status",className:z("mt-1 text-[12px]",g.ok?"text-success":"text-danger"),children:g.text}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2 text-[12px] text-ink-secondary",children:[Bn[s]?e.jsx("a",{href:Bn[s],target:"_blank",rel:"noreferrer",className:"text-accent hover:underline",children:t("imageGen.key.get")}):e.jsx("span",{children:t("imageGen.custom.help",{app:ws()})}),S&&e.jsx("button",{type:"button",onClick:()=>{B("")},disabled:d,className:"cursor-pointer hover:text-danger disabled:opacity-50",children:t("keys.removeKey")})]}),u&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:u})]})}function Gu({configured:s,optional:n=!1}){return e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:z("size-1.5 rounded-full",s?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:s?"text-success":void 0,children:t(s?"imageGen.key.saved":n?"imageGen.key.optional":"imageGen.key.missing")})]})}function es(s){if(s.readOnly||s.trialCredit||s.access==="custom"||s.access==="api")return null;if(s.driverKind==="claudeAgent")return"claude";const n=s.authentication?.method;return s.snapshot.chatgptPlan===!0||(n==="device-code"||n==="browser-pkce")&&Ma(s.driverKind)==="codex"?"chatgpt":null}function zs(s){return s.snapshot.state!=="available"?"unavailable":s.snapshot.authenticated===!0?"signedIn":s.snapshot.authenticated===!1?"signedOut":"unknown"}const Us={claude:{title:"accounts.claude",add:"accounts.addClaude",removeBody:"accounts.removeBodyClaude"},chatgpt:{title:"accounts.chatgpt",add:"accounts.addChatgpt",removeBody:"accounts.removeBodyChatgpt"}};function Vu(s,n){return{signOut:zs(n)==="signedIn"&&n.authentication?.signOut===!0&&n.snapshot.account?.method!=="api-key",remove:s==="claude"?n.instanceId!=="claude"&&n.claudeAccount?.isDefault!==!0:n.instanceId.startsWith("chatgpt-")}}function Ii(s){return s.some(Le)}function qu(s,n){const a=n.filter(o=>zs(o)==="signedIn"),i=Ii(n),r=n.some(o=>o.snapshot.state==="available"),c=n.length>1?t("accounts.count",{count:String(n.length),signedIn:String(a.length)}):a[0]?.snapshot.account?.email??Vl(n[0]);return{title:t(Us[s].title),subtitle:c,ready:i,status:i?t("onboarding.engines.ready"):r?t("model.signInRequired"):t("onboarding.engines.needsSetup"),action:i?t("engines.library.manage"):r?t("accounts.signIn"):t("engines.library.setup")}}function Ju({group:s,instance:n,onRename:a}){const{state:i,dispatch:r,refreshInstances:c}=W(),[o,d]=l.useState(!1),[m,u]=l.useState(null),[x,p]=l.useState(!1),[h,f]=l.useState(null),y=l.useRef(null),{signOut:b,remove:g}=Vu(s,n),k=i.bots.filter(w=>w.modelSelection.instanceId===n.instanceId).length;l.useEffect(()=>{if(!o)return;const w=v=>{v.key==="Escape"&&(v.stopPropagation(),d(!1))},P=v=>{v.target instanceof Node&&!y.current?.contains(v.target)&&d(!1)};return window.addEventListener("keydown",w,!0),window.addEventListener("pointerdown",P),()=>{window.removeEventListener("keydown",w,!0),window.removeEventListener("pointerdown",P)}},[o]);const S=async w=>{u(null),p(!0),f(null);try{const P=`/api/instances/${encodeURIComponent(n.instanceId)}${w==="signOut"?"/auth/sign-out":""}`,{instances:v}=await M(P,w==="signOut"?{method:"POST"}:{method:"DELETE"});Array.isArray(v)?r({type:"instances",instances:v}):await c().catch(()=>{})}catch(P){f(P instanceof Error?P.message:String(P))}finally{p(!1)}},C="ui-menu-row w-full text-left disabled:cursor-not-allowed disabled:opacity-50";return e.jsxs("div",{ref:y,className:"relative flex items-center gap-1",children:[g&&e.jsx("button",{type:"button",disabled:x||k>0,onClick:()=>u("remove"),title:k>0?t("accounts.inUse",{count:String(k)}):void 0,className:"rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:t("accounts.remove")}),e.jsx("button",{type:"button",onClick:()=>d(w=>!w),disabled:x,"aria-haspopup":"menu","aria-expanded":o,"aria-label":t("accounts.menu",{name:_e(n)}),className:"flex size-8 items-center justify-center rounded-lg text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50",children:x?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(ll,{size:16})}),o&&e.jsxs("div",{role:"menu",className:z("absolute right-0 top-full z-40 mt-1 w-[220px] overflow-hidden text-[13px]",ol),children:[e.jsx("button",{type:"button",role:"menuitem",className:z(C,"text-ink"),onClick:()=>{d(!1),a()},children:t("accounts.rename")}),b&&e.jsx("button",{type:"button",role:"menuitem",className:z(C,"text-ink"),onClick:()=>{d(!1),u("signOut")},children:t("accounts.signOut")}),g&&k>0&&e.jsx("p",{className:"px-3 pb-1 pt-0.5 text-[11px] leading-snug text-ink-secondary",children:t("accounts.inUse",{count:String(k)})})]}),h&&e.jsx("p",{role:"alert",className:"absolute right-0 top-full z-30 mt-1 w-[260px] rounded-lg bg-card p-2 text-[12px] text-danger shadow-lg",children:h}),e.jsx(Qe,{open:m==="signOut",title:t("accounts.signOutTitle",{name:_e(n)}),body:t("accounts.signOutBody"),confirmLabel:t("accounts.signOut"),onCancel:()=>u(null),onConfirm:()=>{S("signOut")}}),e.jsx(Qe,{open:m==="remove",title:t("accounts.removeTitle",{name:_e(n)}),body:t(Us[s].removeBody),confirmLabel:t("accounts.remove"),tone:"neutral",onCancel:()=>u(null),onConfirm:()=>{S("remove")}})]})}function Xu({instance:s,onDone:n}){const{dispatch:a}=W(),[i,r]=l.useState(_e(s)),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=async()=>{const x=i.trim();if(!x||x===_e(s))return n();o(!0),m(null);try{const{instances:p}=await M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({displayName:x})});Array.isArray(p)&&a({type:"instances",instances:p}),n()}catch(p){m(p instanceof Error?p.message:String(p))}finally{o(!1)}};return e.jsxs("form",{className:"flex min-w-0 flex-1 flex-col gap-1",onSubmit:x=>{x.preventDefault(),u()},children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i,onChange:x=>r(x.target.value),maxLength:80,autoFocus:!0,disabled:c,"aria-label":t("accounts.nameLabel"),onKeyDown:x=>{x.key==="Escape"&&(x.stopPropagation(),n())},className:"min-w-0 flex-1 rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink outline-none focus:border-accent-border disabled:opacity-50"}),e.jsx("button",{type:"submit",disabled:c||!i.trim(),className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-50",children:c?e.jsx(X,{size:13,className:"animate-spin"}):t("common.save")}),e.jsx("button",{type:"button",onClick:n,disabled:c,className:"rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control",children:t("common.cancel")})]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:d})]})}function Yu({group:s,instance:n,signingIn:a,onSignIn:i,onSignInDone:r}){const[c,o]=l.useState(!1),d=zs(n),m=n.snapshot.account,u=n.snapshot.authenticationUnavailableReason,x=u&&d!=="signedIn"?u:d==="signedIn"?m?.method==="api-key"?t("accounts.apiKey"):[m?.email,m?.organization].filter(Boolean).join(" · ")||t("accounts.signedIn"):d==="signedOut"?t("accounts.notSignedIn"):d==="unknown"?t("accounts.unknown"):n.snapshot.reason??t("onboarding.engines.needsSetup");return e.jsxs("li",{"data-account":n.instanceId,"data-account-state":d,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsx("span",{"aria-hidden":"true",className:z("flex size-6 shrink-0 items-center justify-center rounded-full",d==="signedIn"?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:d==="signedIn"?e.jsx(ge,{size:13}):e.jsx("span",{className:z("size-1.5 rounded-full",d==="signedOut"?"bg-warning":"bg-ink-tertiary")})}),c?e.jsx(Xu,{instance:n,onDone:()=>o(!1)}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:_e(n),children:_e(n)}),e.jsx("div",{className:"truncate text-[12px] text-ink-secondary",title:x,children:x})]}),d!=="signedIn"&&d!=="unavailable"&&!u&&!a&&e.jsx("button",{type:"button",onClick:i,className:z("shrink-0 rounded-lg px-3 py-1.5 text-[12px] font-semibold",d==="signedOut"?"bg-accent text-white hover:brightness-110":"bg-control text-ink hover:bg-raised-hover"),children:t("accounts.signIn")}),e.jsx(Ju,{group:s,instance:n,onRename:()=>o(!0)})]})]}),a&&e.jsx("div",{className:"pl-9",children:s==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(Kl,{instanceId:n.instanceId,autoStart:!0,onDone:r}),n.claudeAccount?.signInCommand&&e.jsxs("details",{className:"mt-2 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer select-none hover:text-ink",children:t("engineSetup.preferTerminal")}),e.jsx(Hl,{command:n.claudeAccount.signInCommand,actionLabel:t("engineSetup.openSignIn"),compact:!0})]})]}):e.jsx(Wl,{instanceId:n.instanceId,provider:"codex",browserPkce:n.authentication?.method==="browser-pkce",autoStart:!0,onDone:r})}),s==="chatgpt"&&d==="signedIn"&&n.snapshot.chatgptPlan&&e.jsx("div",{className:"pl-9",children:e.jsx(Gl,{instanceId:n.instanceId,welcome:!1})})]})}function Pi({label:s,endpoint:n,extra:a,folder:i=!1,describedBy:r,onAdded:c}){const{dispatch:o}=W(),[d,m]=l.useState(!1),[u,x]=l.useState(""),[p,h]=l.useState(""),[f,y]=l.useState(!1),[b,g]=l.useState(null),k=async()=>{if(!(f||!u.trim())){y(!0),g(null);try{const S={displayName:u.trim(),...a,...i&&p.trim()?{configDir:p.trim()}:{}},C=await M(n,{method:"POST",body:JSON.stringify(S)});Array.isArray(C.instances)&&o({type:"instances",instances:C.instances}),m(!1),x(""),h(""),typeof C.instanceId=="string"&&c(C.instanceId)}catch(S){g(S instanceof Error?S.message:String(S))}finally{y(!1)}}};return d?e.jsxs("form",{"data-add-account":n,className:"space-y-2.5 rounded-xl border border-hairline/50 bg-app p-3",onSubmit:S=>{S.preventDefault(),k()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("accounts.nameLabel"),e.jsx("input",{value:u,onChange:S=>x(S.target.value),placeholder:t("accounts.namePlaceholder"),maxLength:80,autoFocus:!0,required:!0,disabled:f,"aria-describedby":r,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] font-normal text-ink outline-none focus:border-accent-border disabled:opacity-50"})]}),i&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer select-none hover:text-ink",children:t("accounts.folderToggle")}),e.jsx("input",{value:p,onChange:S=>h(S.target.value),placeholder:"~/.claude-work",maxLength:4096,spellCheck:!1,disabled:f,"aria-label":t("accounts.folderToggle"),className:"mt-2 w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink outline-none focus:border-accent-border disabled:opacity-50"}),e.jsx("p",{className:"mt-1 leading-relaxed",children:t("accounts.folderHint")})]}),b&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:b}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{m(!1),g(null)},disabled:f,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:f||!u.trim(),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[f&&e.jsx(X,{size:13,className:"animate-spin"}),t("accounts.addSubmit")]})]})]}):e.jsxs("button",{type:"button",onClick:()=>m(!0),"aria-describedby":r,className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),s]})}function Qu({group:s,accounts:n,advanced:a,bare:i=!1}){const[r,c]=l.useState(null),o=n[0],d=n.some(x=>x.snapshot.state==="available"),m=n.find(x=>x.policy)?.policy,u=l.useId();return e.jsxs(Nt,{instance:o,summary:qu(s,n),bare:i,children:[m&&e.jsxs("p",{className:"mb-3 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:m.organizationName})})," · ",m.reason]}),d?e.jsxs("div",{className:"space-y-2",children:[e.jsx("ul",{"data-accounts":s,className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:n.map(x=>e.jsx(Yu,{group:s,instance:x,signingIn:r===x.instanceId,onSignIn:()=>c(x.instanceId),onSignInDone:()=>c(p=>p===x.instanceId?null:p)},x.instanceId))}),!o.snapshot.authenticationUnavailableReason&&e.jsxs(e.Fragment,{children:[e.jsx(Pi,{label:t(Us[s].add),endpoint:`/api/instances/${s}-accounts`,folder:s==="claude",describedBy:s==="chatgpt"?u:void 0,onAdded:c}),s==="chatgpt"&&e.jsx("p",{id:u,className:"px-2 text-[12px] leading-relaxed text-ink-secondary",children:t("accounts.addChatgptWorkspaceNote")})]})]}):e.jsx(Mt,{instance:o,unframed:!0}),o.snapshot.update&&e.jsx(za,{update:o.snapshot.update,instance:o,className:"mt-3",quiet:!0}),o.snapshot.warning&&e.jsx(Ua,{warning:o.snapshot.warning,className:"mt-3"}),a]})}const at=z(Be,"font-sans"),Zu={opusModel:"global.anthropic.claude-opus-5-5",sonnetModel:"global.anthropic.claude-sonnet-5-5",haikuModel:"global.anthropic.claude-haiku-5-5",smallFastModel:"global.anthropic.claude-haiku-5-5"},Mn=["opusModel","sonnetModel","haikuModel","smallFastModel"],em={name:"Claude on Bedrock",awsProfile:"default",awsRegion:"",model:"",opusModel:"",sonnetModel:"",haikuModel:"",smallFastModel:""},tm=s=>{const n=s.claudeBedrock;return{name:s.displayName,awsProfile:n?.awsProfile||"default",awsRegion:n?.awsRegion??"",model:n?.model??"",opusModel:n?.opusModel??"",sonnetModel:n?.sonnetModel??"",haikuModel:n?.haikuModel??"",smallFastModel:n?.smallFastModel??""}},zn={opusModel:"claudeBedrock.opus",sonnetModel:"claudeBedrock.sonnet",haikuModel:"claudeBedrock.haiku",smallFastModel:"claudeBedrock.smallFast"};function Un({instance:s,onDone:n}){const{dispatch:a}=W(),[i,r]=l.useState(s?tm(s):em),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=h=>({value:i[h],onChange:f=>r(y=>({...y,[h]:f.target.value})),spellCheck:!1,disabled:c}),x=!!(i.name.trim()&&i.awsProfile.trim()&&i.awsRegion.trim()&&i.model.trim()),p=async()=>{if(c||!x)return;o(!0),m(null);const h={displayName:i.name.trim(),awsProfile:i.awsProfile.trim(),awsRegion:i.awsRegion.trim(),model:i.model.trim(),...Object.fromEntries(Mn.map(f=>[f,i[f].trim()]))};try{const f=s?await M(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-bedrock`,{method:"PATCH",body:JSON.stringify(h)}):await M("/api/instances/claude-bedrock",{method:"POST",body:JSON.stringify(h)});Array.isArray(f.instances)&&a({type:"instances",instances:f.instances}),n()}catch(f){m(f instanceof Error&&f.message?f.message:t("claudeBedrock.failed"))}finally{o(!1)}};return e.jsxs("form",{"data-claude-bedrock-form":s?.instanceId??"new",className:"flex flex-col gap-2 rounded-xl border border-hairline/50 bg-inset p-3",onSubmit:h=>{h.preventDefault(),p()},children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.awsHint")}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.name"),e.jsx("input",{...u("name"),maxLength:80,autoFocus:!0,"aria-label":t("claudeBedrock.name"),className:at})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.profile"),e.jsx("input",{...u("awsProfile"),maxLength:128,placeholder:"default","aria-label":t("claudeBedrock.profile"),className:z(at,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.region"),e.jsx("input",{...u("awsRegion"),maxLength:32,placeholder:"us-east-1","aria-label":t("claudeBedrock.region"),className:z(at,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.model"),e.jsx("input",{...u("model"),maxLength:160,placeholder:"global.anthropic.claude-sonnet-5-5","aria-label":t("claudeBedrock.model"),className:z(at,"font-mono")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.modelHint")}),e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-2.5 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary outline-none hover:text-ink",children:t("claudeBedrock.tiers")}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:Mn.map(h=>e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t(zn[h]),e.jsx("input",{...u(h),maxLength:160,placeholder:Zu[h],"aria-label":t(zn[h]),className:z(at,"font-mono")})]},h))})]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:d}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:n,disabled:c,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:c||!x,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[c&&e.jsx(X,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function sm({instance:s,onEdit:n}){const{state:a,dispatch:i}=W(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[m,u]=l.useState(null),x=a.bots.filter(f=>f.modelSelection.instanceId===s.instanceId||f.fallback?.some(y=>y.instanceId===s.instanceId)||f.tasks?.some(y=>y.modelSelection?.instanceId===s.instanceId)).length,p=s.claudeBedrock,h=async()=>{c(!1),d(!0),u(null);try{const f=await M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(f.instances)&&i({type:"instances",instances:f.instances})}catch(f){u(f instanceof Error?f.message:String(f))}finally{d(!1)}};return e.jsxs("li",{"data-claude-bedrock":s.instanceId,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsx(Fa,{preset:"aws",size:16,className:"shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:s.displayName,children:s.displayName}),e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",children:t("claudeBedrock.rowSubtitle",{profile:p?.awsProfile??"",region:p?.awsRegion??""})})]}),e.jsx("button",{type:"button",onClick:n,disabled:o,className:"shrink-0 rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("claudeBedrock.edit")}),e.jsx("button",{type:"button",disabled:o||x>0,onClick:()=>c(!0),title:x>0?t("accounts.inUse",{count:String(x)}):t("accounts.remove"),"aria-label":t("claudeBedrock.remove",{name:s.displayName}),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(Ee,{size:14})})]}),m&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:m}),e.jsx(Qe,{open:r,title:t("accounts.removeTitle",{name:s.displayName}),body:t("claudeBedrock.removeBody"),confirmLabel:t("accounts.remove"),tone:"neutral",pending:o,onCancel:()=>c(!1),onConfirm:()=>{h()}})]})}function ts(){const{state:s}=W(),n=s.instances.filter(r=>r.claudeBedrock),[a,i]=l.useState(null);return e.jsxs("div",{"data-claude-bedrock-endpoints":"",className:"mt-3 space-y-2",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("claudeBedrock.title")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.hint")}),n.length===0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.empty")}):e.jsx("ul",{className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:n.map(r=>a===r.instanceId?e.jsx("li",{className:"p-3",children:e.jsx(Un,{instance:r,onDone:()=>i(null)})},r.instanceId):e.jsx(sm,{instance:r,onEdit:()=>i(r.instanceId)},r.instanceId))}),a==="new"?e.jsx(Un,{onDone:()=>i(null)}):e.jsxs("button",{type:"button",onClick:()=>i("new"),className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),t("claudeBedrock.add")]})]})}function Fn(s){const n=s/1048576;return n<1?t("engines.freeSpace.underOneMb"):n<1024?`${Math.round(n)} MB`:`${(n/1024).toFixed(1)} GB`}function nm({instance:s,initial:n={kind:"idle"}}){const[a,i]=l.useState(n),[r,c]=l.useState(null),o=`/api/instances/${encodeURIComponent(s.instanceId)}/leftover-files`,d=async()=>{c(null),i({kind:"scanning"});try{const x=await M(o);i(x.folders>0?{kind:"found",bytes:x.bytes,complete:x.complete}:{kind:"none"})}catch(x){c(x instanceof Error?x.message:String(x)),i({kind:"idle"})}},m=async()=>{c(null),i({kind:"deleting"});try{const x=await M(`${o}/remove`,{method:"POST",body:JSON.stringify({})});i({kind:"done",freedBytes:x.freedBytes,remaining:x.remaining})}catch(x){c(x instanceof Error?x.message:String(x)),i({kind:"idle"})}},u=a.kind==="scanning"||a.kind==="deleting";return e.jsxs("section",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5","aria-label":t("engines.freeSpace.title"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(cl,{size:13,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"text-[12px] font-medium text-ink",children:t("engines.freeSpace.title")}),e.jsx("span",{className:"flex-1"}),(a.kind==="idle"||a.kind==="none"||a.kind==="done"||u)&&e.jsxs("button",{type:"button",onClick:()=>{d()},disabled:u,className:"flex shrink-0 items-center gap-1 rounded-lg border border-hairline/40 px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[u&&e.jsx(X,{size:12,className:"animate-spin"}),t("engines.freeSpace.action")]})]}),e.jsx("p",{className:"mt-1.5 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.freeSpace.intro")}),a.kind==="scanning"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.scanning")}),a.kind==="deleting"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.deleting")}),a.kind==="none"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.none")}),a.kind==="found"&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("p",{role:"status",className:"flex-1 text-[12px] text-ink",children:t(a.complete?"engines.freeSpace.found":"engines.freeSpace.foundAtLeast",{size:Fn(a.bytes)})}),e.jsx("button",{type:"button",onClick:()=>i({kind:"idle"}),className:"rounded-lg px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:t("common.cancel")}),e.jsx("button",{type:"button",onClick:()=>{m()},className:"rounded-lg bg-raised px-3 py-1 text-[12px] text-ink hover:bg-raised-hover",children:t("engines.freeSpace.delete")})]}),a.kind==="done"&&e.jsxs("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:[(a.freedBytes>0||a.remaining===0)&&e.jsxs("span",{className:"text-success",children:[t("engines.freeSpace.freed",{size:Fn(a.freedBytes)})," "]}),a.remaining>0&&t("engines.freeSpace.someLeft")]}),r&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}const ss=[60,120,180,360,720];function Ti(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(!1),[r,c]=l.useState(""),o=l.useRef(!1),d=s.config?.cacheKeepWarm;if(!d)return null;const m=async x=>{if(!o.current){o.current=!0,i(!0),c("");try{const p=await M("/api/config",{method:"PUT",body:JSON.stringify({cacheKeepWarm:{enabled:x.enabled,windowMinutes:x.windowMinutes}})});n({type:"configStatus",config:p})}catch(p){c(p instanceof Error?p.message:t("settings.keepWarm.error"))}finally{o.current=!1,i(!1)}}},u=ss.includes(d.windowMinutes)?[...ss]:[...ss,d.windowMinutes].sort((x,p)=>x-p);return e.jsxs(Y,{title:t("settings.keepWarm.title"),subtitle:t("settings.keepWarm.subtitle"),children:[e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"cache-keepwarm-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.keepWarm.enable")}),e.jsx(me,{id:"cache-keepwarm-enabled",checked:d.enabled,disabled:a,"aria-describedby":"cache-keepwarm-help cache-keepwarm-cost",onClick:()=>{m({...d,enabled:!d.enabled})}})]}),e.jsx("p",{id:"cache-keepwarm-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.keepWarm.help")}),e.jsx("p",{id:"cache-keepwarm-cost",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.keepWarm.cost")}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"cache-keepwarm-window",className:"text-[13px] font-medium text-ink",children:t("settings.keepWarm.window")}),e.jsx(xe,{id:"cache-keepwarm-window",value:d.windowMinutes,disabled:a||!d.enabled,onChange:x=>{m({...d,windowMinutes:Number(x.target.value)})},children:u.map(x=>e.jsx("option",{value:x,children:t("settings.keepWarm.hours",{hours:Number((x/60).toFixed(2))})},x))})]}),a&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),r&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}function am({instance:s,cliDefault:n,onClose:a,onSaved:i}){const[r,c]=l.useState(s.cliCandidates??null),[o,d]=l.useState(""),[m,u]=l.useState(s.cli&&!(s.cliCandidates??[]).includes(s.cli)?s.cli:""),[x,p]=l.useState(!1),[h,f]=l.useState(null),[y,b]=l.useState(!1),[g,k]=l.useState(null),S=l.useRef(!1);l.useEffect(()=>{S.current||(S.current=!0,M(`/api/cli-candidates?name=${encodeURIComponent(n??"")}`).then(({candidates:j})=>{c(j),s.cli&&(j.includes(s.cli)?d(s.cli):u(s.cli))}).catch(()=>c(j=>j??[])))},[n,s.cli]);const C=m.trim()||o,w=C!==(s.cli??""),P=x||y;l.useEffect(()=>{f(null)},[C]);const v=()=>{if(P||!C||!w)return;b(!0),k(null);const j=C;M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:j})}).then(()=>Promise.resolve(i()).catch(()=>{})).then(a).catch(A=>k(A.message)).finally(()=>b(!1))},B=()=>{P||!C||!w||(p(!0),k(null),M("/api/cli-test",{method:"POST",body:JSON.stringify({cli:C,driver:s.driverKind})}).then(j=>{f(j),j.ok&&v()}).catch(j=>k(j.message)).finally(()=>p(!1)))};return e.jsxs("div",{className:"mt-2.5 flex flex-col gap-2",children:[r!==null&&r.length>0&&e.jsxs(xe,{className:"w-full font-mono",value:m.trim()?"":o,onChange:j=>{d(j.target.value),u("")},"aria-label":t("engines.detectedAria",{name:s.displayName}),disabled:P,children:[e.jsx("option",{value:"",children:t("engines.selectBinary")}),r.map(j=>e.jsx("option",{value:j,children:j},j))]}),e.jsx("input",{type:"text",value:m,onChange:j=>u(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),!(!C||!w)&&B())},placeholder:r?.length?t("engines.manualPath"):"/absolute/path/to/cli","aria-label":t("engines.customAria",{name:s.displayName}),spellCheck:!1,disabled:P,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink placeholder:font-sans placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),h&&!h.ok&&h.message&&e.jsxs("div",{role:"alert",className:"flex gap-1.5 rounded-lg border border-warning/25 bg-warning/10 px-2.5 py-2 text-[12px] leading-relaxed text-warning",children:[e.jsx(Oe,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t("engines.testFailed",{message:h.message})})]}),h?.ok&&h.version&&e.jsx("div",{className:"text-[12px] text-success",children:t("engines.testPassed",{version:h.version})}),g&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:g}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:a,disabled:P,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("common.cancel")}),h&&!h.ok?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>f(null),disabled:P,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("engines.editPath")}),e.jsx("button",{onClick:()=>v(),disabled:P,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[13px] text-danger hover:bg-raised-hover disabled:opacity-50",children:y?e.jsx(X,{size:13,className:"animate-spin"}):t("engines.saveAnyway")})]}):e.jsx("button",{onClick:B,disabled:P||!C||!w,className:z("flex w-[72px] items-center justify-center gap-1.5 rounded-lg py-1.5 text-[13px]","bg-raised text-ink hover:bg-raised-hover","disabled:cursor-not-allowed disabled:opacity-50"),children:P?e.jsx(X,{size:13,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})})]})]})}function Ri({instance:s}){const{refreshInstances:n}=W(),[a,i]=l.useState(!1),r=od(a),[c,o]=l.useState(!1),[d,m]=l.useState(!1),[u,x]=l.useState(null),[p,h]=l.useState(null),f=l.useRef(null);l.useEffect(()=>{f.current!==null&&f.current!==s.cli&&i(!1),f.current=s.cli??null},[s.cli]);const y=()=>{c||d||(o(!0),h(null),M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:""})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(k=>h(k.message)).finally(()=>o(!1)))},b=()=>{c||d||(o(!0),h(null),M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({hidden:!0})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(k=>h(k.message)).finally(()=>o(!1)))},g=()=>{c||d||(m(!0),x(null),h(null),M(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-update`,{method:"POST",body:JSON.stringify({})}).then(async({version:k})=>{x(k),await Promise.resolve(n()).catch(()=>{})}).catch(k=>h(k.message)).finally(()=>m(!1)))};return e.jsxs("details",{className:"mt-4 border-t border-hairline/40 pt-3",children:[e.jsx("summary",{className:"cursor-pointer rounded-md py-1 text-[12px] font-medium text-ink-secondary outline-none hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:t("engines.library.advanced")}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.footer")}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[13px]",children:[s.cli?e.jsx("span",{className:"w-full break-all font-mono text-[12px] text-ink-secondary",title:s.cli,children:s.cli}):s.cliDefault&&e.jsx("span",{className:"break-all font-mono text-[11px] text-ink-secondary",children:s.cliDefault}),s.snapshot.version&&e.jsx("span",{className:"break-all text-[11px] text-ink-secondary",title:s.snapshot.version,children:s.snapshot.version}),e.jsx("span",{className:"flex-1"}),s.driverKind==="claudeAgent"&&e.jsxs("button",{onClick:g,disabled:c||d,className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[d?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),d?t("engines.updating"):t("engines.updateClaude")]}),s.cli&&e.jsx("button",{onClick:y,disabled:c||d,className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:c?t("engines.resetting"):t("engines.reset")}),e.jsx("button",{type:"button","data-hide-engine":s.instanceId,onClick:b,disabled:c||d,title:t("engines.hideHint"),className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:t("engines.hide")}),e.jsx("button",{onClick:()=>i(k=>!k),disabled:d,"aria-expanded":a,className:z("shrink-0 rounded-lg border border-hairline/40 px-3 py-1 text-[12px]",a?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised/50 hover:text-ink","disabled:opacity-50"),children:t("engines.setCli")})]}),u&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-success",children:t("engines.claudeUpdated",{version:u})}),p&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:p}),r.shown&&e.jsx("div",{className:r.className,...r.exitProps,children:e.jsx(am,{instance:s,cliDefault:s.cliDefault,onClose:()=>i(!1),onSaved:n})})]})}function Dn({instance:s,action:n}){const{state:a,dispatch:i,refreshInstances:r}=W(),[c,o]=l.useState(!1),[d,m]=l.useState(!1),[u,x]=l.useState(null),p=n==="remove",h=p?a.bots.filter(b=>b.modelSelection.instanceId===s.instanceId).length:0,f=t(p?"accounts.remove":"accounts.signOut"),y=async()=>{o(!1),m(!0),x(null);try{const b=`/api/instances/${encodeURIComponent(s.instanceId)}${p?"":"/auth/sign-out"}`,{instances:g}=await M(b,{method:p?"DELETE":"POST"});Array.isArray(g)?i({type:"instances",instances:g}):await r()}catch(b){x(b instanceof Error?b.message:String(b))}finally{m(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",disabled:d||h>0,onClick:()=>o(!0),className:z("rounded-lg px-2.5 py-1.5 text-[12px] font-medium disabled:cursor-not-allowed disabled:opacity-50",p?"text-danger hover:bg-danger/10":"text-ink-secondary hover:bg-raised hover:text-ink"),children:d?e.jsx(X,{size:13,className:"animate-spin"}):f}),h>0&&e.jsx("p",{className:"text-[11px] text-ink-secondary",children:t("accounts.inUse",{count:String(h)})})]}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u}),e.jsx(Qe,{open:c,title:t(p?"accounts.removeTitle":"accounts.signOutTitle",{name:s.displayName}),body:t(p?"accounts.removeBodyAntigravity":"accounts.signOutBody"),confirmLabel:f,tone:"neutral",pending:d,onCancel:()=>{d||o(!1)},onConfirm:()=>{y()}})]})}function im({source:s}){const{state:n}=W(),[a,i]=l.useState(null),r=a?n.instances.find(c=>c.instanceId===a&&c.snapshot.authenticated!==!0):void 0;return e.jsxs(e.Fragment,{children:[e.jsx(Pi,{label:t("engineSetup.antigravity.addAccount"),endpoint:"/api/instances/antigravity-accounts",extra:{sourceInstanceId:s.instanceId},onAdded:i}),r&&e.jsx("div",{"data-antigravity-added":r.instanceId,children:e.jsx(Mt,{instance:r,unframed:!0})})]})}function rm({instance:s,bare:n=!1}){const a=s.policy&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:s.policy.organizationName})})," · ",s.policy.reason]});return s.trialCredit?e.jsx(Nt,{instance:s,bare:n,children:e.jsx("p",{"data-trial-credit":s.trialCredit,className:"text-[13px] leading-relaxed text-ink-secondary",children:t(s.trialCredit==="used_up"?"engines.trialCreditUsedUp":s.trialCredit==="ended"?"engines.trialCreditEnded":Le(s)?"engines.trialCredit":"engines.trialCreditOwn")})}):s.readOnly?e.jsxs(Nt,{instance:s,bare:n,children:[a,e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.managedEngine")}),!Le(s)&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("organization.engineUnavailable")})]}):e.jsxs(Nt,{instance:s,bare:n,children:[a,(s.codexEndpoint||s.claudeEndpoint)&&e.jsx(yi,{instance:s},s.instanceId),!Le(s)&&e.jsx(Mt,{instance:s,intent:s.access==="custom"?"inject":"cloud",description:s.codexEndpoint?t("agentEndpoints.codexHint"):void 0,unframed:!0}),Le(s)&&e.jsx(Yl,{instance:s,className:"mt-3"}),Le(s)&&s.serverKind==="ollama"&&e.jsx(Ql,{instance:s,className:"mt-3"}),Le(s)&&e.jsx(Zl,{instance:s,className:"mt-3"}),s.snapshot.update&&e.jsx(za,{update:s.snapshot.update,instance:s,className:"mt-3",quiet:!0}),s.snapshot.warning&&e.jsx(Ua,{warning:s.snapshot.warning,className:"mt-3"}),Le(s)&&s.snapshot.authenticated===!0&&(s.authentication?.method==="device-code"?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(ge,{size:13}),t(eo[Ma(s.driverKind)].connectedAccount)]}):s.authentication?.method==="paste-code"&&e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(ge,{size:13}),t("engineSetup.claude.connectedAccount")]})),s.freeUpSpace&&e.jsx(nm,{instance:s}),s.driverKind==="antigravityAgent"&&e.jsxs("div",{className:"mt-3 space-y-3",children:[s.snapshot.authenticated&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:s.snapshot.account?.email??t("engineSetup.antigravity.emailUnavailable")}),e.jsx(im,{source:s}),s.snapshot.authenticated===!0&&s.authentication?.signOut===!0&&e.jsx(Dn,{instance:s,action:"signOut"}),s.instanceId.startsWith("antigravity-")&&e.jsx(Dn,{instance:s,action:"remove"})]}),e.jsx(Ri,{instance:s})]})}function lm(s,n){return n?s.snapshot.authenticated===!0&&s.snapshot.account?.email?s.snapshot.account.email:t("onboarding.engines.ready"):s.snapshot.ollama?Xl(s.snapshot.ollama):s.snapshot.state==="available"&&s.snapshot.authenticated===!1?t("model.signInRequired"):t("onboarding.engines.needsSetup")}function om({rows:s,isReady:n,renderEngine:a,more:i}){const[r,c]=l.useState(null),o=s.filter(p=>n(p)||p.authentication!==void 0||p.codexEndpoint||p.claudeEndpoint),[d,m]=l.useState(!1),u=!s.length||s.some(p=>!p.readOnly),x=s.filter(p=>!o.includes(p));return e.jsxs(e.Fragment,{children:[e.jsx(be,{label:t("settings.simple.ai.yours"),actions:e.jsx(Da,{}),children:e.jsx(ye,{children:o.map(p=>{const h=n(p),f=r===p.instanceId;return e.jsxs("div",{"data-simple-engine":p.instanceId,className:"group",children:[e.jsxs("div",{className:"flex min-h-11 flex-wrap items-center gap-x-5 gap-y-2 px-4 py-2.5",children:[e.jsxs("span",{className:"flex min-w-[min(100%,15rem)] flex-1 items-center gap-3",children:[e.jsx(dn,{instance:p,size:14,subtle:!0}),e.jsxs("span",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"truncate text-[14px] leading-5 text-ink",children:p.displayName}),e.jsx("span",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:lm(p,h)})]})]}),e.jsx("button",{type:"button","aria-expanded":f,className:"ui-button ml-auto shrink-0",onClick:()=>c(f?null:p.instanceId),children:t(f?"common.done":h||p.codexEndpoint||p.claudeEndpoint?"settings.simple.ai.manage":"settings.simple.ai.setUp")})]}),f&&e.jsx("div",{className:"px-4 pb-3",children:a(p,!0)})]},p.instanceId)})})}),(x.length>0||u)&&e.jsxs(zt,{title:t("settings.simple.ai.more",{count:String(x.length+Number(u))}),trailing:e.jsx("span",{"aria-hidden":"true",className:"flex items-center -space-x-1",children:x.slice(0,4).map(p=>e.jsx("span",{className:"flex size-[18px] items-center justify-center rounded-full bg-menu",children:e.jsx(dn,{instance:p,size:14,subtle:!0})},p.instanceId))}),...i,children:[u&&e.jsxs("div",{className:"rounded-xl border border-hairline/50 bg-inset p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("strong",{className:"text-sm",children:"Xingchi (Codex Responses)"}),!d&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>m(!0),children:t("settings.simple.ai.setUp")})]}),d&&e.jsx(Os,{engine:"codex",xingchi:!0,onDone:()=>m(!1)})]}),e.jsx(_a,{instances:x,isReady:n,renderEngine:p=>a(p)})]})]})}function cm(){const{state:s,refreshInstances:n}=W(),[a,i]=l.useState([]),[r,c]=l.useState(null),[o,d]=l.useState(null);if(l.useEffect(()=>{let u=!0;return M("/api/instances/hidden").then(x=>{u&&i(Array.isArray(x?.instances)?x.instances:[])}).catch(()=>{}),()=>{u=!1}},[s.instances]),a.length===0)return null;const m=u=>{c(u),d(null),M(`/api/instances/${encodeURIComponent(u)}`,{method:"PATCH",body:JSON.stringify({hidden:!1})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(x=>d(x.message)).finally(()=>c(null))};return e.jsxs("details",{"data-hidden-engines":!0,className:"px-4",children:[e.jsx("summary",{className:"cursor-pointer text-[13px] font-medium text-ink-secondary hover:text-ink",children:t("engines.hiddenTitle",{count:String(a.length)})}),e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.hiddenHint")}),e.jsx("div",{className:"mt-2 flex flex-col gap-1.5",children:a.map(u=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[13px] text-ink",children:u.displayName}),e.jsx("button",{type:"button","data-unhide-engine":u.instanceId,disabled:r!==null,onClick:()=>m(u.instanceId),className:"shrink-0 text-[12px] font-medium text-accent hover:underline disabled:opacity-50",children:r===u.instanceId?t("engines.unhiding"):t("engines.unhide")})]},u.instanceId))}),o&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:o})]})}function Li({simple:s=!1,more:n}){const{state:a}=W();l.useEffect(()=>ql,[]);const i=a.instances.filter(h=>h.readOnly||h.cli!==void 0||h.cliDefault!==void 0||h.snapshot.state==="unavailable"||Jl(h)||h.claudeEndpoint!==void 0||h.claudeBedrock!==void 0||h.codexEndpoint!==void 0),r=new Map;for(const h of i){const f=es(h);f&&r.set(f,[...r.get(f)??[],h])}const c=h=>{const f=es(h);return f&&r.get(f)?.[0]===h?f:null},o=i.filter(h=>!es(h)||c(h)),d=o.length>0&&o.every(h=>h.readOnly),m=!r.has("chatgpt")&&!d,u=!r.has("claude")&&!d,x=h=>{const f=c(h);return f?Ii(r.get(f)):Le(h)},p=(h,f=!1)=>{const y=c(h);return y?e.jsx(Qu,{group:y,accounts:r.get(y),bare:f,advanced:e.jsxs(e.Fragment,{children:[y==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(Vt,{}),e.jsx(ts,{})]}):e.jsx(wt,{}),e.jsx(Ri,{instance:h})]})}):e.jsx(rm,{instance:h,bare:f})};return s&&n?e.jsxs(e.Fragment,{children:[e.jsx(om,{rows:o,isReady:x,renderEngine:p,more:n}),u&&e.jsxs("div",{className:"px-4",children:[e.jsx(Vt,{}),e.jsx(ts,{})]}),m&&e.jsx("div",{className:"px-4",children:e.jsx(wt,{})})]}):e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-60 space-y-2 px-4",children:[e.jsx("h1",{className:"text-[22px] font-semibold tracking-tight text-ink",children:t("settings.engines.title")}),e.jsx("p",{className:"mt-2 max-w-lg text-[13px] leading-relaxed text-ink-secondary",children:t("engines.library.intro")})]}),e.jsx(Da,{})]}),e.jsx(_a,{instances:o,isReady:x,renderEngine:p}),u&&e.jsxs("div",{className:"px-4",children:[e.jsx(Vt,{}),e.jsx(ts,{})]}),m&&e.jsx("div",{className:"px-4",children:e.jsx(wt,{})}),e.jsx(cm,{}),e.jsx(Ti,{})]})}const dm={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function bt(s,n){return[dm[s],{signal:n}]}function Fs(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function um({instances:s,configured:n,aliases:a,loading:i,removingName:r,error:c,unavailableReason:o,onRefresh:d,onRemove:m}){return e.jsxs(Y,{title:t("vm.vps.title"),subtitle:t("vm.vps.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n===!0?t("vm.vps.sshHost",{alias:a.join(", ")||t("vm.vps.configuredFallback")}):n===!1?e.jsxs(e.Fragment,{children:[t("vm.vps.needsAlias")," ",e.jsx($a,{id:"vps"})]}):t("vm.vps.refreshHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:i||r!==null,"aria-label":t("vm.vps.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(Se,{size:12,className:z(i&&"animate-spin")})," ",t("vm.refresh")]})]}),c&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:c}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:i?t("vm.vps.checking"):o?t("vm.vps.unavailable",{reason:o}):n===!1?t("vm.vps.notConfigured"):s.length===1?t("vm.vps.foundOne"):t("vm.vps.foundMany",{count:s.length})}),!(n===!1&&!i&&!o)&&e.jsxs("div",{"aria-busy":i||r!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:[o&&s.length>0&&e.jsxs("div",{className:"flex items-center gap-2 border-b border-hairline/35 px-3 py-2.5 text-[12px] text-ink-secondary",children:[e.jsx(Oe,{size:14,className:"shrink-0 text-warning"})," ",o]}),i&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:13,className:"animate-spin"})," ",t("vm.vps.checkingList")]}):o&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Oe,{size:14,className:"shrink-0 text-warning"})," ",o]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(dl,{size:14,className:"shrink-0"})," ",t("vm.vps.notConfigured")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.vps.noneFound")}):s.map((u,x)=>{const p=jm(u),h=Ds(p),f=r===u.name,y=_s(u.name);return e.jsxs("div",{className:z("flex items-start justify-between gap-3 px-3 py-3",x>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:u.orphaned?t("vm.vps.orphan",{id:y}):u.ownerName}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px]",u.inUse||p==="running"?"bg-success/15 text-success":p==="stopped"||p==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:h}),a.length>1&&e.jsx("span",{className:"rounded-full bg-control px-2 py-0.5 font-mono text-[11px] text-ink-secondary",children:u.vpsAlias})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:u.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>m(u),disabled:i||u.inUse||r!==null,"aria-busy":f||void 0,title:t("vm.vps.removeTitle"),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[f?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Ee,{size:12}),t("vm.vps.remove")]})]},`${u.vpsAlias??""}:${u.name}`)})]})]})}const mm=[1e3,2e3,4e3];function pm(s){return new Promise(n=>window.setTimeout(n,s))}const xm={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},hm={unmanaged:"vm.state.notManaged","in-use":"vm.state.inUse",stopped:"vm.state.stopped",running:"vm.state.running",attention:"vm.state.attention",sleeping:"vm.state.sleeping","going-to-sleep":"vm.state.goingToSleep",starting:"vm.state.starting",restarting:"vm.state.restarting",removing:"vm.state.removing",paused:"vm.state.paused"};function Ds(s){return t(hm[s])}function gm(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function fm(s){return Ds(gm(s))}function bm(s){return s.inUse?"in-use":s.state==="removing"?"removing":s.state==="archived"?"sleeping":s.state==="archiving"?"going-to-sleep":["idle","ready","running"].includes(s.state)?"running":["init","provisioning","provisioned","cloning"].includes(s.state)?"starting":"attention"}function Bi(s,n,a){const i={...a},r=new Set(s.map(o=>o.boxId)),c=s.flatMap(o=>{const d=a[o.boxId];return d==="deleted"?[]:d==="deleting"?[{...o,state:"removing"}]:d!=="sleeping"?[o]:o.state==="archived"?(delete i[o.boxId],[o]):[{...o,state:"archived"}]});for(const o of n)a[o.boxId]!=="sleeping"||r.has(o.boxId)||c.push({...o,state:"archived"});for(const[o,d]of Object.entries(a))(d==="deleted"||d==="deleting")&&!r.has(o)&&delete i[o];return{instances:c,overrides:i}}function ym(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:Bi(Array.isArray(s.instances)?s.instances:[],n,a)}function vm(s){return["idle","ready","running"].includes(s.state)}function jm(s){return s.inUse?"in-use":s.state==="running"?"running":s.state==="restarting"?"restarting":s.state==="removing"?"removing":["created","exited"].includes(s.state)?"stopped":s.state==="paused"?"paused":"attention"}function _s(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}function km(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:Fs(`/api/bots/${s.botId}/local-computer/remove`,{})}}function Nm(s,n){return{confirmation:s==="delete"?t("vm.confirm.deleteCloud",{subject:n.orphaned?t("vm.confirm.orphanCloud"):t("vm.confirm.ownedCloud",{name:n.ownerName??""})}):null,request:Fs(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function wm(s){const n=_s(s.name);return{confirmation:t("vm.confirm.removeVps",{subject:s.orphaned?t("vm.confirm.orphanVps",{id:n}):t("vm.confirm.ownedVps",{name:s.ownerName??""})}),request:Fs(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name,alias:s.vpsAlias})}}function ns(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function Sm({instances:s,configured:n,loading:a,pending:i,error:r,unavailableReason:c,onRefresh:o,onSleep:d,onDelete:m}){return e.jsxs(Y,{title:t("vm.cloud.title"),subtitle:t("vm.cloud.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n===!0?t("vm.cloud.includesOrphans"):n===!1?e.jsxs(e.Fragment,{children:[t("vm.cloud.needsKey")," ",e.jsx($a,{id:"box"})]}):t("vm.cloud.refreshHint")}),e.jsxs("button",{type:"button",onClick:o,disabled:a||i!==null,"aria-label":t("vm.cloud.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(Se,{size:12,className:z(a&&"animate-spin")})," ",t("vm.refresh")]})]}),r&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:r}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.cloud.checking"):c?t("vm.cloud.unavailable",{reason:c}):n===!1?t("vm.cloud.notConnected"):s.length===1?t("vm.cloud.foundOne"):t("vm.cloud.foundMany",{count:s.length})}),!(n===!1&&!a&&!c)&&e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:13,className:"animate-spin"})," ",t("vm.cloud.checkingList")]}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Oe,{size:14,className:"shrink-0 text-warning"})," ",c]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Rt,{size:14,className:"shrink-0"})," ",t("vm.cloud.notConnected")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.cloud.noneFound")}):s.map((u,x)=>{const p=bm(u),h=Ds(p),f=i?.boxId===u.boxId,y=vm(u),b=p==="removing";return e.jsxs("div",{className:z("flex items-start justify-between gap-3 px-3 py-3",x>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:u.orphaned?t("vm.cloud.orphan"):t("vm.cloud.ofBot",{name:u.ownerName??""})}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px]",u.inUse||p==="running"?"bg-success/15 text-success":p==="sleeping"||p==="going-to-sleep"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:h})]}),e.jsx("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:u.orphaned?t("vm.owner.gone"):t("vm.cloud.machineId",{id:u.name})}),u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.cloud.stopFirst")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>d(u),disabled:a||u.inUse||i!==null||!y,"aria-busy":f&&i?.action==="sleep"?!0:void 0,title:y?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:h.toLowerCase()}),className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:cursor-not-allowed disabled:opacity-40",children:[f&&i?.action==="sleep"?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(ul,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>m(u),disabled:a||u.inUse||i!==null||b,"aria-busy":f&&i?.action==="delete"?!0:void 0,title:t("vm.cloud.deleteTitle"),className:"flex items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[f&&i?.action==="delete"?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Ee,{size:12}),t("common.delete")]})]})]},u.boxId)})})]})}function Cm({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:r,unavailableReason:c,onRefresh:o,onDelete:d,runningInstances:m,powerPending:u,onPower:x}){return e.jsxs(Y,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:c?t("vm.perBot.inventoryUnavailable"):m===void 0?t("vm.perBot.created",{count:s.length,max:n}):L(`Đã tạo ${s.length} máy · Đang chạy ${m}/${n}`,`${s.length} desktops created · ${m}/${n} running`)}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:m===void 0?t("vm.perBot.deleteHint"):L("Ứng dụng không giới hạn số máy đã tạo; số lượng thực tế phụ thuộc dung lượng ổ đĩa. Dừng một máy để giải phóng tài nguyên cho máy khác.","The app does not cap created desktops; their number depends on disk space. Stop a desktop to free resources for another.")}),e.jsxs("button",{type:"button",onClick:o,disabled:a||i!==null||!!u,"aria-label":t("vm.perBot.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(Se,{size:12,className:z(a&&"animate-spin")})," ",t("vm.refresh")]})]}),r&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:r}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.perBot.checking"):c?t("vm.perBot.unavailable",{reason:c}):s.length===1?t("vm.perBot.foundOne"):t("vm.perBot.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null||!!u,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:13,className:"animate-spin"})," ",t("vm.perBot.checkingList")]}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Oe,{size:14,className:"shrink-0 text-warning"})," ",c]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.perBot.none")}):s.map((p,h)=>{const f=fm(p),y=i===p.botId,b=p.managed===!0;return e.jsxs("div",{className:z("flex items-start justify-between gap-3 px-3 py-3",h>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:p.name}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px]",b?p.inUse||p.ready?"bg-success/15 text-success":p.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:f})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(xm[p.destination])})}),!b&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:t("vm.perBot.unmanaged")}),b&&p.problem&&!p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:ai(p.problem)}),b&&p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),b&&e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[x&&e.jsxs("button",{type:"button",onClick:()=>x(p,p.container==="running"?"stop":"start"),disabled:a||p.inUse||i!==null||!!u||p.container==="stopped"&&m!==void 0&&m>=n,"aria-busy":u?.botId===p.botId||void 0,className:"flex items-center gap-1.5 rounded-lg bg-control px-2.5 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-40",children:[u?.botId===p.botId&&e.jsx(X,{size:12,className:"animate-spin"}),p.container==="running"?L("Dừng","Stop"):L("Bật","Start")]}),e.jsxs("button",{type:"button",onClick:()=>d(p),disabled:a||p.inUse||i!==null||!!u,"aria-busy":y||void 0,title:p.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:p.name}),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[y?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Ee,{size:12}),t("common.delete")]})]})]},p.botId)})})]})}function yt({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:z("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-[11px]",a?"bg-success/20 text-success":"border border-hairline/50 text-ink-secondary"),children:a?e.jsx(ge,{size:12}):s}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:z("text-[14px]",a?"text-ink-secondary line-through":"text-ink"),children:n}),!a&&i&&e.jsx("div",{className:"mt-2 flex flex-col items-start gap-2 [&>*]:max-w-full",children:i})]})]})}function qe({action:s,pending:n,children:a,onClick:i,danger:r=!1}){return e.jsxs("button",{onClick:i,"aria-busy":n===s,disabled:n!==null,className:z("flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[13px] font-medium disabled:opacity-50",r?"bg-danger/15 text-danger hover:bg-danger/20":"bg-accent text-white hover:brightness-110"),children:[n===s&&e.jsx(X,{size:13,className:"animate-spin"}),a]})}const Oi=5,Mi=1440,Em=480;function Am(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=Oi&&a<=Mi?a:null}function Im({minutes:s,disabled:n,onSave:a}){const[i,r]=l.useState(String(s)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,x]=l.useState(!1);l.useEffect(()=>{c||r(String(s))},[s,c]);const p=async()=>{if(!c||u)return;const h=Am(i);if(h===null){m(t("vm.idle.range"));return}x(!0);try{await a(h),r(String(h)),o(!1),m("")}catch(f){m(f instanceof Error?f.message:t("vm.idle.error"))}finally{x(!1)}};return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[13px] text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[12px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("div",{className:z("flex w-[150px] shrink-0 items-center rounded-lg border bg-control",d?"border-danger/60":"border-hairline/40 focus-within:border-focus"),children:[e.jsx("input",{id:"local-vm-idle-timeout",type:"number",min:Oi,max:Mi,step:1,inputMode:"numeric",value:i,disabled:n||u,"aria-invalid":!!d,"aria-describedby":d?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:h=>{r(h.target.value),o(!0),m("")},onBlur:()=>{p()},onKeyDown:h=>{h.key==="Enter"&&h.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-2.5 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"}),e.jsx("span",{className:"pr-2.5 text-[13px] text-ink-secondary",children:t("vm.idle.minutes")})]})]}),d?e.jsx("p",{id:"local-vm-idle-timeout-error",role:"alert",className:"mt-1.5 text-[12px] text-danger",children:d}):null]})}function zi(){const s=W().state.config?.cloudHome===!0,[n,a]=l.useState(null),[i,r]=l.useState(!0),[c,o]=l.useState(null),d=l.useRef(null);l.useEffect(()=>()=>d.current?.abort(),[]);const[m,u]=l.useState(null),[x,p]=l.useState(!1),[h,f]=l.useState(0),[y,b]=l.useState([]),[g,k]=l.useState(2),[S,C]=l.useState(!1),[w,P]=l.useState(null),[v,B]=l.useState(null),[j,A]=l.useState(null),[I,_]=l.useState(null),[U,J]=l.useState(0),[K,te]=l.useState([]),[ae,de]=l.useState(null),[D,T]=l.useState(!0),[Z,ee]=l.useState(null),[fe,N]=l.useState(null),[re,se]=l.useState(null),[ne,G]=l.useState(0),ie=l.useRef([]),le=l.useRef({}),[ce,ve]=l.useState([]),[$,oe]=l.useState(null),[R,E]=l.useState([]),[H,pe]=l.useState(!0),[q,ke]=l.useState(null),[Pe,et]=l.useState(null),[tt,ze]=l.useState(null),[Ir,Pr]=l.useState(0),[Tr,Fe]=l.useState(""),Ke=l.useCallback(async O=>{const F=await fetch(...bt("status",O)),Q=await F.json().catch(()=>({}));if(!O?.aborted){if(!F.ok)throw new Error(Q.error??t("vm.err.status",{code:F.status}));return a(Q),u(null),Q}},[]),xt=l.useCallback(async O=>{const F=await fetch(...bt("local-vms",O)),Q=await F.json().catch(()=>({}));if(!F.ok)throw new Error(Q.error??t("vm.err.inventory",{code:F.status}));const V=Q;b(V.instances),k(V.maxInstances),B(V.available?null:ai(V.problem)??t("vm.err.runtimeUnavailable")),P(null)},[]),st=l.useCallback(async O=>{const F=await fetch(...bt("cloud",O)),Q=await F.json().catch(()=>({}));if(!F.ok)throw new Error(Q.error??t("vm.err.cloudInventory",{code:F.status}));const V=Q,he=ym(V,ie.current,le.current);le.current=he.overrides,ie.current=he.instances,te(he.instances),de(V.configured===!0),N(V.available||!V.configured?null:V.problem??t("vm.err.cloudUnavailable")),ee(null)},[]),_t=l.useCallback(async O=>{const F=await fetch(...bt("vps",O)),Q=await F.json().catch(()=>({}));if(!F.ok)throw new Error(Q.error??t("vm.err.vpsInventory",{code:F.status}));const V=Q;ve(Array.isArray(V.instances)?V.instances:[]),oe(V.configured===!0),E(Array.isArray(V.vpsAliases)?V.vpsAliases:[]),et(V.available||!V.configured?null:V.problem??t("vm.err.vpsUnavailable")),ke(null)},[]);l.useEffect(()=>{if(s)return;let O=!0,F,Q;const V=async()=>{Q=new AbortController;try{await Ke(Q.signal)}catch(he){O&&!(he instanceof DOMException&&he.name==="AbortError")&&(a(null),u(he instanceof Error?he.message:String(he)))}finally{O&&(r(!1),F=window.setTimeout(()=>{V()},5e3))}};return V(),()=>{O=!1,Q?.abort(),F!==void 0&&window.clearTimeout(F)}},[s,Ke,h]),l.useEffect(()=>{if(n?.mode!=="per-bot"){b([]),C(!1),P(null),B(null);return}const O=new AbortController;return C(!0),xt(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||P(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||C(!1)}),()=>O.abort()},[U,xt,n?.mode]),l.useEffect(()=>{const O=new AbortController;return T(!0),st(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||N(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||T(!1)}),()=>O.abort()},[ne,st]),l.useEffect(()=>{const O=new AbortController;return pe(!0),_t(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||et(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||pe(!1)}),()=>O.abort()},[_t,Ir]);const $t=async(O,F)=>{const Q=await fetch(`/api/local-computer/${O}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:F}),V=await Q.json().catch(()=>({})),he={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!Q.ok)throw new Error(V.error??t(he[O]));return F.throwIfAborted(),a(V),V},Vs=O=>window.ogb?.confirm?window.ogb.confirm(O):window.confirm(O),He=async O=>{if(c!==null||d.current)return;const F=new AbortController;d.current=F,o(O),u(null);try{if(O==="remove"&&!await Vs(t("vm.confirm.deleteShared"))||O==="recreate"&&!await Vs(t("vm.confirm.recreate")))return;let Q;if(O==="recreate"?(await $t("remove",F.signal),Q=await $t("run",F.signal)):Q=await $t(O,F.signal),(O==="run"||O==="start"||O==="recreate")&&(Q=await En(Q,async()=>await Ke(F.signal)??Q,F.signal),!Q.ready&&!Q.capacity_limited))throw new Error(Q.problem??t("vm.err.start"));await Ke(),Fe(O==="remove"?t("vm.announce.deleted"):O==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(Q){if(F.signal.aborted)return;u(Q instanceof Error?Q.message:String(Q))}finally{d.current=null,F.signal.aborted||o(null)}},Rr=async(O,F)=>{if(I||j)return;_({botId:O.botId,action:F}),P(null);const Q=new AbortController;try{const V=`/api/bots/${encodeURIComponent(O.botId)}/local-computer`,he=await fetch(`${V}/${F}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}"});let Re=await he.json();if(!he.ok)throw new Error(Re.error??t("vm.err.start"));if(F==="start"&&(Re=await En(Re,async()=>{const We=await fetch(V);if(!We.ok)throw new Error(t("vm.err.start"));return We.json()},Q.signal)),F==="start"&&!Re.ready)throw new Error(Re.problem??t("vm.err.start"));await Promise.all([xt(),Ke()])}catch(V){P(V instanceof Error?V.message:String(V))}finally{_(null)}},qs=async O=>{p(!0),u(null);try{const F=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:O,automaticCapacity:!0}})}),Q=await F.json().catch(()=>({}));if(!F.ok)throw new Error(Q.error??t("vm.policyError"));a(V=>V&&{...V,mode:O}),await Ke()}catch(F){u(F instanceof Error?F.message:String(F))}finally{p(!1)}},Lr=async O=>{const F=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:O}})}),Q=await F.json().catch(()=>({}));if(!F.ok)throw new Error(Q.error??t("vm.idle.error"));a(V=>V&&{...V,idle_timeout_ms:O*6e4})},Br=async O=>{if(!O.managed){P(t("vm.unmanagedError"));return}const F=ns(km(O),Q=>window.confirm(Q));if(F){A(O.botId),P(null);try{const Q=await fetch(...F),V=await Q.json().catch(()=>({}));if(!Q.ok)throw new Error(V.error??t("vm.deleteError"));await xt(),Fe(t("vm.announce.deletedBot",{name:O.name}))}catch(Q){P(Q instanceof Error?Q.message:String(Q))}finally{A(null)}}},Js=async(O,F)=>{const Q=ns(Nm(O,F),V=>window.confirm(V));if(Q){se({boxId:F.boxId,action:O}),ee(null),Fe("");try{const V=await fetch(...Q),he=await V.json().catch(()=>({}));if(!V.ok)throw new Error(he.error??t(O==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const Re=O==="delete"&&he?.pending===!0;le.current={...le.current,[F.boxId]:O==="delete"?Re?"deleting":"deleted":"sleeping"};const We=Bi(ie.current,ie.current,le.current);le.current=We.overrides,ie.current=We.instances,te(We.instances);const Ge=F.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:F.ownerName??""});if(Fe(Re?`${Ge}: ${t("vm.state.removing")}.`:t(O==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:Ge})),Re){for(const Ae of mm){await pm(Ae);try{await st()}catch{}if(le.current[F.boxId]!=="deleting"){Fe(t("vm.announce.cloudDeleted",{subject:Ge}));return}}const Ve={...le.current};delete Ve[F.boxId],le.current=Ve;const gt=ie.current.map(Ae=>Ae.boxId===F.boxId?{...Ae,state:F.state}:Ae);ie.current=gt,te(gt);try{await st(),ie.current.some(Ae=>Ae.boxId===F.boxId)||Fe(t("vm.announce.cloudDeleted",{subject:Ge}))}catch(Ae){const Mr=Ae instanceof Error?Ae.message:String(Ae);ee(`${Ge}: ${t("vm.state.removing")}. ${Mr}`)}return}try{await st()}catch(Ve){const gt=Ve instanceof Error?Ve.message:String(Ve);ee(t(O==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:Ge,detail:gt}))}}catch(V){ee(V instanceof Error?V.message:String(V))}finally{se(null)}}},Or=async O=>{const F=_s(O.name),Q=ns(wm(O),V=>window.confirm(V));if(Q){ze(O.name),ke(null);try{const V=await fetch(...Q),he=await V.json().catch(()=>({}));if(!V.ok)throw new Error(he.error??t("vm.vpsRemoveError"));await _t(),Fe(t("vm.announce.vpsRemoved",{subject:O.orphaned?t("vm.announce.orphanVps",{id:F}):t("vm.confirm.ownedVps",{name:O.ownerName??""})}))}catch(V){ke(V instanceof Error?V.message:String(V))}finally{ze(null)}}},Te=n?.commands,ht=n?.ready===!0,Xs=n?.container!=="missing",Ys=!!(Xs&&(!n?.imageMatches||!n?.managed||n?.network==="unsafe"||n?.security==="unsafe"||n?.persistence==="unsafe")),Qs=!i&&!n,Zs=n?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),Ne=n?.mode==="per-bot",Kt=Ne&&n?.runtime==="container",Ht=Ne?!!(n?.daemonUp&&n?.image&&!Kt):ht;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:Tr}),e.jsx(Sm,{instances:K,configured:ae,loading:D,pending:re,error:Z,unavailableReason:fe,onRefresh:()=>G(O=>O+1),onSleep:O=>{Js("sleep",O)},onDelete:O=>{Js("delete",O)}}),e.jsx(um,{instances:ce,configured:$,aliases:R,loading:H,removingName:tt,error:q,unavailableReason:Pe,onRefresh:()=>Pr(O=>O+1),onRemove:O=>{Or(O)}}),e.jsx(cd,{}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs(Y,{title:t("vm.main.title"),subtitle:Ne?t("vm.main.perBotSubtitle",{host:Zs}):t("vm.main.sharedSubtitle",{host:Zs}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:z("flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[13px]",Ht?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:[i?e.jsx(X,{size:12,className:"animate-spin"}):Ht?e.jsx(ge,{size:12}):e.jsx(to,{size:9}),i?t("common.checking"):Qs?t("vm.main.statusUnavailable"):Ne&&Ht?t("vm.main.readyPerBot"):Kt?t("vm.main.perBotUnsupported"):ht?t("vm.main.ready"):n?.problem??t("vm.main.notReady")]}),e.jsxs("button",{onClick:()=>{r(!0),f(O=>O+1),J(O=>O+1)},disabled:i||c!==null,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(Se,{size:12})," ",t("vm.main.recheck")]}),ht&&!Ne&&e.jsxs("a",{href:n?.viewer_url??Te?.view,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[13px] text-ink hover:bg-control",children:[e.jsx(pt,{size:12})," ",t("vm.main.watch")]})]}),m&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:m})]}),e.jsxs(Y,{title:t("vm.isolation.title"),subtitle:t("vm.isolation.subtitle"),children:[e.jsx("div",{className:"flex overflow-hidden rounded-lg border border-hairline/40",children:["shared","per-bot"].map((O,F)=>e.jsx("button",{type:"button",disabled:!n||x,onClick:()=>{qs(O)},className:z("flex-1 px-3 py-2 text-[13px] disabled:opacity-50",F>0&&"border-l border-hairline/40",n?.mode===O?"bg-control text-ink":"text-ink-secondary hover:text-ink"),children:O==="shared"?t("vm.isolation.shared"):t("vm.isolation.perBot")},O))}),Ne&&e.jsxs("div",{className:"mt-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:L("Số máy ảo chạy cùng lúc tối đa","Maximum desktops running at once")}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:L("Không giới hạn số máy đã tạo trong ứng dụng. Giới hạn chạy cùng lúc tự tính theo RAM/CPU cấp cho Docker hoặc Podman, có dự phòng cho hệ thống. Khi đủ chỗ đang chạy, máy mới vẫn được tạo ở trạng thái dừng.","The app does not cap created desktops. The running limit is calculated from Docker or Podman memory/CPU with a system reserve. When running slots are full, new desktops are still created in a stopped state.")}),n?.capacity&&e.jsxs("div",{className:"mt-1 text-[12px] text-ink-secondary",children:[n.capacity.source==="host"?L("Ước tính từ máy chủ; chưa đọc được tài nguyên Docker/Podman","Host estimate; Docker/Podman resources have not been read"):n.capacity.source==="docker"?"Docker":"Podman",` · ${n.capacity.memoryGb.toFixed(1)} GB RAM · ${n.capacity.cpus} CPU`,` · ${L("Mỗi máy","Each desktop")}: ${n.capacity.perVmMemoryGb} GB / ${n.capacity.perVmCpus} CPU`,` · ${L("Dành cho hệ thống","System reserve")}: ${n.capacity.reservedMemoryGb.toFixed(1)} GB / ${n.capacity.reservedCpus} CPU`]}),n?.automatic_capacity===!1&&e.jsx("button",{type:"button",disabled:x,onClick:()=>{qs(n.mode)},className:"mt-1 text-[12px] text-accent hover:underline",children:L("Chuyển sang tự động","Switch to automatic")}),n&&(n.running_instances??0)>n.max_instances&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:L("Số máy đang chạy vượt mức ước tính mới. Ứng dụng giữ nguyên chúng; dừng bớt máy trước khi bật máy khác.","The running desktops exceed the new estimate. They are kept; stop some before starting another.")})]}),e.jsxs("div",{className:"shrink-0 rounded-lg bg-control px-3 py-2 text-center text-[13px] text-ink",children:[e.jsx("div",{className:"text-[11px] text-ink-secondary",children:n?.automatic_capacity===!1?L("Thủ công","Manual"):L("Tự động","Automatic")}),e.jsx("div",{className:"font-semibold tabular-nums",children:n?.max_instances??"…"})]})]}),e.jsx(Im,{minutes:n?Math.round(n.idle_timeout_ms/6e4):Em,disabled:!n||x,onSave:Lr}),x&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(X,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(Y,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(yt,{n:1,title:t("vm.setup.step1"),done:!!n?.runtime,children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.step1Detail")}),Te?.install?e.jsx(rt,{command:Te.install}):e.jsx("a",{href:"https://podman.io/docs/installation",target:"_blank",rel:"noreferrer",className:"text-[13px] text-accent hover:underline",children:t("vm.setup.podmanGuide")})]}),e.jsx(yt,{n:2,title:n?.runtime&&!n.daemonUp?t("vm.setup.step2Open",{runtime:n.runtime}):t("vm.setup.step2"),done:!!n?.daemonUp,children:n?.runtime?Te?.runtimeStart?e.jsx(rt,{command:Te.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(yt,{n:3,title:t("vm.setup.step3"),done:!!n?.image,children:[n?.daemonUp&&e.jsx(qe,{action:"pull",pending:c,onClick:()=>{He("pull")},children:t("vm.setup.prepare")}),Te?.pull&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showPull")}),e.jsx("div",{className:"mt-2",children:e.jsx(rt,{command:Te.pull})})]})]}),e.jsxs(yt,{n:4,title:Ne?t("vm.setup.step4PerBot"):Ys?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:Ne?y.some(O=>O.managed):ht,children:[Ne?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:Kt?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):Ys?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(Oe,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n?.problem})]}),n?.image?e.jsxs(qe,{action:"recreate",pending:c,onClick:()=>{He("recreate")},danger:!0,children:[e.jsx(so,{size:13})," ",t("vm.setup.recreate")]}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.prepareFirst")})]}):n?.container==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(n.stop_reason==="idle"?"vm.stopped.idle":"vm.stopped.detail")}),e.jsx(qe,{action:"start",pending:c,onClick:()=>{He("start")},children:t("vm.setup.start")})]}):n?.container==="running"?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):n?.image?e.jsxs(e.Fragment,{children:[e.jsx(qe,{action:"run",pending:c,onClick:()=>{He("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,Te?.run&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showCommand")}),e.jsx("div",{className:"mt-2",children:e.jsx(rt,{command:Te.run})})]})]})]})}),Ne&&e.jsx(Cm,{instances:y,maxInstances:n?.max_instances??g,runningInstances:n?.running_instances,powerPending:I,onPower:(O,F)=>{Rr(O,F)},loading:S,deletingBotId:j,error:w,unavailableReason:v,onRefresh:()=>J(O=>O+1),onDelete:O=>{Br(O)}}),Qs&&e.jsx(Y,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(Oe,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(Y,{title:t("vm.safety.title"),subtitle:Ne?t("vm.safety.perBot",{path:n?.workspace_guest_path??"/home/cua/workspace"}):t("vm.safety.shared",{path:n?.workspace_guest_path??"/home/cua/workspace"}),children:[Xs&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?.container==="running"&&e.jsxs(qe,{action:"stop",pending:c,onClick:()=>{He("stop")},children:[e.jsx(no,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(qe,{action:"remove",pending:c,onClick:()=>{He("remove")},danger:!0,children:[e.jsx(Ee,{size:12})," ",Ne?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsxs("div",{className:"mt-3 break-all text-[11px] text-ink-secondary",children:[t("vm.safety.workspace",{path:n?.workspace_path??t("vm.safety.notCreated"),driver:n?.driver_version??"0.37.0",image:n?.image_ref??t("vm.safety.notPrepared")}),n?.base_image_ref?e.jsxs(e.Fragment,{children:[" · ",t("vm.safety.baseImage",{image:n.base_image_ref})]}):null]})]})]})]})}function Pm({profileEmail:s="",focusRequest:n=0,simple:a=!1}){return e.jsx(ao,{})}function Tm(s){const n=s.trim().toLowerCase();return!n||/\s/.test(n)?null:n.startsWith("@")?/^@[^@\s]+\.[^@\s]+$/.test(n)?n:null:/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(n)?n:null}function _n(s,n,a){const i=s.admins.filter(c=>c!==n),r=s.members.filter(c=>c!==n);return a==="admin"?{admins:[...i,n],members:r}:{admins:i,members:[...r,n]}}function Rm(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function $n(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function Lm(s,n,a){const i=[],r=new Set,c=(o,d)=>{const m=o.trim().toLowerCase();if(!m||r.has(m))return;r.add(m);const u=n.filter(p=>p.email?.toLowerCase()===m),x=a.find(p=>p.key===`user:${m}`);i.push({entry:m,role:d,isDomain:m.startsWith("@"),lastSeenAt:u.length?Math.max(...u.map(p=>p.lastSeenAt)):null,devices:u.length,turns:x?.turns??0,costUsd:x?.costUsd??null,...ot(x?.estimatedUsd)&&x.estimatedUsd>0?{estimated:!0}:{}})};for(const o of s.admins)c(o,"admin");for(const o of s.members)c(o,"member");return i}function Bm(s,n){const a=new Map;for(const i of s){const r=i.email?.trim().toLowerCase();r&&a.set(r,[...a.get(r)??[],i])}return[...a.entries()].map(([i,r])=>{const c=n.find(o=>o.key===`user:${i}`);return{entry:i,role:r.some(o=>o.scopes?.includes("admin"))?"admin":"member",isDomain:!1,lastSeenAt:Math.max(...r.map(o=>o.lastSeenAt)),devices:r.length,turns:c?.turns??0,costUsd:c?.costUsd??null}}).sort((i,r)=>i.role===r.role?i.entry.localeCompare(r.entry):i.role==="admin"?-1:1)}function Om(s,n=Date.now()){return s===null?t("people.never"):n-s<1440*6e4?t("people.today"):new Date(s).toISOString().slice(0,10)}function Ui({people:s,busy:n,onRole:a,onRemove:i,onLink:r,readOnly:c=!1}){if(s.length===0)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(c?"people.portal.empty":"people.empty")});const o="grid grid-cols-[1fr_auto_auto_auto_auto] items-center gap-x-4";return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:z(o,"border-b border-hairline/40 pb-2 text-[12px] font-medium uppercase tracking-wide text-ink-secondary"),children:[e.jsx("span",{children:t("people.colPerson")}),e.jsx("span",{children:t("people.colRole")}),e.jsx("span",{className:"text-right",children:t("people.colLastSeen")}),e.jsx("span",{className:"text-right",children:t("people.colMonth")}),e.jsx("span",{})]}),s.map(d=>e.jsxs("div",{className:z(o,"border-b border-hairline/20 py-2 text-[13px]"),children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-ink",children:d.isDomain?t("people.everyoneAt",{domain:d.entry.slice(1)}):d.entry}),d.devices>0&&e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:t("people.devices",{count:String(d.devices)})})]}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px] font-medium",d.role==="admin"?"bg-accent/15 text-accent":"bg-control text-ink-secondary"),children:d.role==="admin"?t("people.roleAdmin"):t("people.roleMember")}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:d.isDomain?"—":Om(d.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(d.turns)}),children:ot(d.costUsd)?`${d.estimated?"~":""}${ct(d.costUsd)}`:"—"}),c?e.jsx("span",{}):e.jsxs("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:[e.jsx("button",{type:"button",disabled:n,onClick:()=>r(d),"aria-label":t("people.link"),title:t("people.link"),className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(io,{size:13})}),e.jsx("button",{type:"button",disabled:n,onClick:()=>a(d,d.role==="admin"?"member":"admin"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:d.role==="admin"?t("people.makeMember"):t("people.makeAdmin")}),e.jsx("button",{type:"button",disabled:n,onClick:()=>i(d),className:"text-danger hover:underline disabled:opacity-50",children:t("people.remove")})]})]},d.entry))]})}function Fi({link:s}){const{state:n,copy:a}=Cs(s);return e.jsxs("div",{className:"mt-3 rounded-lg border border-hairline/40 bg-inset p-3 text-[13px]",children:[e.jsx("div",{className:"mb-1 text-ink-secondary",children:t("people.link")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 select-all break-all text-ink",children:s}),e.jsxs("button",{type:"button",onClick:a,className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control hover:text-ink",children:[n==="copied"?e.jsx(ge,{size:13,className:"text-success"}):n==="failed"?e.jsx($e,{size:13,className:"text-danger"}):e.jsx(Aa,{size:13}),t(n==="copied"?"people.copied":n==="failed"?"common.copyFailed":"people.copy")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.linkHint")})]})}function Mm({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(Y,{title:t("people.title"),subtitle:t("people.portal.subtitle"),children:[e.jsxs("div",{"data-people-portal":!0,className:"flex flex-col gap-3 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:t("people.portal.managed")}),s&&e.jsxs("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"flex w-fit items-center gap-2 rounded-lg bg-control px-3 py-2 font-medium text-ink hover:bg-control/70",children:[t("people.portal.open")," ",e.jsx(pt,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Ui,{people:n,busy:!1,readOnly:!0,onRole:a,onRemove:a,onLink:a})}),e.jsx("p",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("people.portal.note")})]})}function Di({simple:s=!1,startOpen:n=!1}){const[a,i]=l.useState(n),[r,c]=l.useState(!1),[o,d]=l.useState(null),[m,u]=l.useState(null),[x,p]=l.useState(null),[h,f]=l.useState([]),[y,b]=l.useState(typeof window<"u"?window.location.origin:""),[g,k]=l.useState(null),[S,C]=l.useState(""),[w,P]=l.useState("member"),[v,B]=l.useState(null),[j,A]=l.useState(!1),[I,_]=l.useState(!1),[U,J]=l.useState(null),K=l.useCallback(async()=>{_(!0),J(null);try{const[T,Z,ee,fe,N]=await Promise.all([M("/api/config"),M("/api/auth/sessions").catch(()=>({sessions:[]})),M("/api/usage?groupBy=user").catch(()=>({groups:[]})),M("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(ie=>ie.ok?ie.json():null).catch(()=>null)]),re={admins:Array.isArray(T?.signIn?.admins)?T.signIn.admins:[],members:Array.isArray(T?.signIn?.members)?T.signIn.members:[]},se=dd(T);u(se),p(re);const ne=Array.isArray(Z?.sessions)?Z.sessions:[],G=Array.isArray(ee?.groups)?ee.groups:[];f(se.authority==="portal"?Bm(ne,G):Lm(re,ne,G)),typeof fe?.publicUrl=="string"&&fe.publicUrl&&b(fe.publicUrl),k(N?.capabilities?.emailSignIn===!0?!0:N?!1:null)}catch(T){J(T instanceof Error?T.message:String(T))}finally{_(!1)}},[]);l.useEffect(()=>{ud().then(T=>{d(T),un(T)&&K()})},[K]);const te=async T=>{A(!0),J(null);try{await M("/api/config",{method:"PUT",body:JSON.stringify({signIn:T})}),await K()}catch(Z){J(Z instanceof Error?Z.message:String(Z))}finally{A(!1)}},ae=async()=>{if(c(!0),!x||j)return;const T=Tm(S);if(!T){J(t("remote.signInAccess.invalid"));return}await te(_n(x,T,w)),C(""),B($n(y,T))};if(!un(o))return null;const de=m?.authority==="portal"?e.jsx(Mm,{peopleUrl:m.peopleUrl,people:h}):null,D=e.jsxs(e.Fragment,{children:[g===!1&&(!s||r)&&e.jsx("p",{className:"mb-3 rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-[13px] text-ink-secondary",children:t(m?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:T=>{T.preventDefault(),ae()},children:[e.jsx("input",{value:S,onChange:T=>C(T.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:j,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs(xe,{value:w,onChange:T=>P(T.target.value),"aria-label":t("people.colRole"),disabled:j,children:[e.jsx("option",{value:"member",children:t("people.roleMember")}),e.jsx("option",{value:"admin",children:t("people.roleAdmin")})]}),e.jsxs("button",{type:"submit",disabled:j||!S.trim(),className:"ui-button ui-button-primary",children:[j?e.jsx(X,{size:13,className:"animate-spin"}):e.jsx(Ce,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{K()},disabled:I||j,"aria-label":t("people.refresh"),title:t("people.refresh"),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(Se,{size:13,className:z(I&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),v&&e.jsx(Fi,{link:v}),U&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:U}),e.jsx("div",{className:"mt-4",children:e.jsx(Ui,{people:h,busy:j,onRole:(T,Z)=>{x&&te(_n(x,T.entry,Z))},onRemove:T=>{x&&te(Rm(x,T.entry))},onLink:T=>B($n(y,T.entry))})}),!s&&e.jsx("p",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("people.note")})]});return s?e.jsxs("div",{"data-people-summary":"",children:[e.jsxs("div",{role:"group","aria-label":t("people.title"),className:"flex min-w-0 items-center gap-3 px-4 py-[13px]",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-11 shrink-0 items-center justify-center rounded-full bg-ink/[0.06] text-ink-secondary",children:e.jsx(Ct,{size:20})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:t("people.title")}),e.jsx("div",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.simple.people")})]}),e.jsx("button",{type:"button","aria-expanded":a,className:"ui-button shrink-0",onClick:()=>i(!a),children:a?t("common.done"):t("settings.simple.people.invite")})]}),a&&e.jsx("div",{className:"px-3.5 pb-3.5 pt-1",children:de??D})]}):de??e.jsx(Y,{title:t("people.title"),subtitle:t("people.subtitle"),children:D})}const as="rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none [color-scheme:dark]";function zm({entry:s}){const[n,a]=l.useState(!1),i=s.type==="admin"&&(s.changed?.length||s.before||s.after);return e.jsx("li",{className:"border-b border-hairline/20 py-2 text-[13px]","data-activity-entry":s.type,children:e.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-start gap-x-3",children:[e.jsx("time",{className:"whitespace-nowrap tabular-nums text-ink-secondary",dateTime:s.at,children:new Date(s.at).toLocaleString(Ss())}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"font-medium text-ink",children:kd(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:Nd(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:ro(s.summaryCode,s.summary,s.summaryParams)}),i&&e.jsxs("button",{type:"button",onClick:()=>a(!n),"aria-expanded":n,className:"cursor-pointer mt-0.5 flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink",children:[e.jsx(Ts,{size:12,className:z("transition-transform",n&&"rotate-90")}),t("activity.changed",{paths:(s.changed??[]).join(", ")||"—"})]}),i&&n&&s.type==="admin"&&e.jsxs("dl",{className:"mt-1 grid grid-cols-[auto_1fr_1fr] gap-x-3 gap-y-0.5 rounded-lg bg-inset p-2 text-[12px]",children:[e.jsx("dt",{}),e.jsx("dd",{className:"text-ink-secondary",children:t("activity.before")}),e.jsx("dd",{className:"text-ink-secondary",children:t("activity.after")}),(s.changed??Object.keys({...s.before,...s.after})).map(r=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"font-mono text-ink-secondary",children:r}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:In(s.before?.[r])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:In(s.after?.[r])})]},r))]})]})]})})}function _i(){const[s,n]=l.useState({who:"",what:"all",from:"",to:""}),[a,i]=l.useState([]),[r,c]=l.useState(0),[o,d]=l.useState(null),[m,u]=l.useState(!1),[x,p]=l.useState(null),h=vd(s),f=l.useCallback(async()=>{u(!0),p(null);try{const b=await M(`/api/admin-activity${h}`);i(b.entries),c(b.total),d(b.retentionDays)}catch(b){p(b instanceof Error?b.message:String(b))}finally{u(!1)}},[h]);l.useEffect(()=>{const b=window.setTimeout(()=>{f()},250);return()=>window.clearTimeout(b)},[f]);const y=b=>n(g=>({...g,...b}));return e.jsxs(Y,{title:t("activity.title"),subtitle:t("activity.subtitle",{days:String(o??180)}),children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.who"),e.jsx("input",{value:s.who,onChange:b=>y({who:b.target.value}),placeholder:t("activity.whoPlaceholder"),className:z(as,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx(xe,{value:s.what,onChange:b=>y({what:b.target.value}),children:jd.map(b=>e.jsx("option",{value:b,children:t(`activity.what.${b}`)},b))})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.from"),e.jsx("input",{type:"date",value:s.from,max:s.to||void 0,onChange:b=>y({from:b.target.value}),className:as})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.to"),e.jsx("input",{type:"date",value:s.to,min:s.from||void 0,onChange:b=>y({to:b.target.value}),className:as})]}),e.jsx("button",{type:"button",onClick:()=>{f()},disabled:m,"aria-label":t("activity.refresh"),title:t("activity.refresh"),className:"cursor-pointer rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:m?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(Se,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${h}`,download:!0,className:"ui-button hover:bg-raised-hover",children:[e.jsx(Ye,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),x&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("activity.error",{message:x})}),!x&&a.length===0&&!m&&e.jsx("p",{className:"mt-4 text-[13px] text-ink-secondary",children:t("activity.empty")}),a.length>0&&e.jsx("ul",{className:"mt-3 flex flex-col",children:a.map((b,g)=>e.jsx(zm,{entry:b},`${b.at}-${g}`))}),r>a.length&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("activity.more",{shown:String(a.length),total:String(r)})})]})}const Kn=4,$s="flex w-full min-w-0 items-center gap-3 px-3 py-2 text-start",Ks="flex flex-col divide-y divide-hairline/30 overflow-hidden rounded-xl border border-hairline/40 bg-card",Um=s=>s.filter(n=>!n.hidden&&!n.defaultBot?.person).sort((n,a)=>n.name.localeCompare(a.name)),$i=(s,n)=>Ut(s)===n||Wa(Ft(s),n)!=="none",Ki=(s,n)=>{const a=Ka(s,n);return a?t("lookedAfter.line",{name:a.name}):t("lookedAfter.nobody")},Hn=(s,...n)=>n.some(a=>a?.toLowerCase().includes(s));function Fm(){const{state:s}=W(),n=lo(),a=oo(),i=l.useRef(null),[r,c]=l.useState("bot"),[o,d]=l.useState(""),[m,u]=l.useState(null),[x,p]=l.useState(null),h=l.useRef(null),[f,y]=l.useState(null),[b,g]=l.useState(""),k=l.useCallback(()=>y(null),[]);if(l.useEffect(()=>{x||!h.current||([...i.current?.querySelectorAll("[data-access-person]")??[]].find(j=>j.dataset.accessPerson===h.current)?.focus(),h.current=null)},[x]),!n||!a)return null;const S=n.people.filter(j=>j.role==="member").sort((j,A)=>j.name.localeCompare(A.name)),C=Um(s.bots),w=m?C.find(j=>j.id===m):void 0,P=x?S.find(j=>j.email===x):void 0,v=o.trim().toLowerCase(),B=async(j,A,I)=>{g("");const _=Ft(j);try{await mn(j.id,A),y({botId:j.id,before:_,after:A,text:I})}catch(U){g(U instanceof Error?U.message:String(U))}};return e.jsxs("div",{ref:i,className:"flex min-w-0 flex-col gap-3","data-access-overview":!0,children:[P?e.jsx(Km,{person:P,bots:C.filter(j=>$i(j,P.email)),team:n,teamName:a,apply:B,onBack:()=>{h.current=P.email,p(null)}}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"ps-4 text-[13px] leading-relaxed text-ink-secondary",children:t("botAccess.overview.introUse",{team:a})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-[180px] flex-1",children:[e.jsx(mt,{size:14,"aria-hidden":"true",className:"pointer-events-none absolute start-2.5 top-1/2 -translate-y-1/2 text-ink-secondary"}),e.jsx("input",{type:"search",value:o,"data-access-search":!0,"aria-label":t(r==="bot"?"botAccess.overview.searchBots":"botAccess.overview.searchPeople"),placeholder:t(r==="bot"?"botAccess.overview.searchBots":"botAccess.overview.searchPeople"),onChange:j=>d(j.target.value),onKeyDown:j=>{j.key==="Escape"&&o&&(j.preventDefault(),d(""))},className:"w-full rounded-lg border border-hairline/50 bg-transparent py-1.5 pe-2.5 ps-8 text-[13px] text-ink placeholder:text-ink-secondary focus:border-focus focus:outline-none"})]}),e.jsx("div",{role:"group","aria-label":t("botAccess.overview.listBy"),className:"flex shrink-0 rounded-full bg-raised/70 p-0.5",children:["bot","person"].map(j=>e.jsx("button",{type:"button","aria-pressed":r===j,"data-access-listing":j,onClick:()=>{c(j),d("")},className:z("rounded-full px-3 py-1 text-[13px] leading-[18px]",r===j?"bg-menu font-medium text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(j==="bot"?"botAccess.overview.byBot":"botAccess.overview.byPerson")},j))})]}),r==="bot"?e.jsx(Dm,{bots:C.filter(j=>!v||Hn(v,j.name,Ka(j,n)?.name,Ut(j)??void 0)),anyBots:C.length>0,team:n,onOpen:u}):e.jsx($m,{people:S.filter(j=>!v||Hn(v,j.name,j.email)),anyPeople:S.length>0,bots:C,onOpen:p}),e.jsx("p",{className:"ps-4 text-[12px] text-ink-secondary",children:t("botAccess.admins")})]}),b&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:b}),w&&e.jsx(co,{bot:w,teamName:a,onClose:()=>u(null),onChanged:j=>y({botId:w.id,...j})}),f&&e.jsx(uo,{text:f.text,onUndo:()=>mn(f.botId,f.before),onDone:k},`${f.botId}:${f.text}:${JSON.stringify(f.after)}`)]})}function Dm({bots:s,anyBots:n,team:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:Ks,children:s.map(r=>{const c=Ft(r),o=Ut(r);return e.jsx("li",{className:"min-w-0",children:e.jsxs("button",{type:"button","aria-haspopup":"dialog","data-access-row":r.id,onClick:()=>i(r.id),className:z($s,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Bt,{bot:r,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] leading-[18px] text-ink",children:r.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:Ki(r,a)})]}),e.jsx("span",{className:"min-w-0 max-w-[40%] truncate text-[13px] text-ink-secondary","data-access-summary":!0,children:c.everyone==="none"?t("botAccess.onlyAdded"):t("botAccess.overview.everyoneUses")}),e.jsx(_m,{entries:Object.keys(c.people).filter(d=>d!==o),team:a})]})},r.id)})}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noBotMatch")}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noBots")})}function _m({entries:s,team:n}){if(!s.length)return null;const a=s.map(r=>po(r,n)).join(", "),i=s.length-Kn;return e.jsxs("span",{role:"img","aria-label":a,title:a,"data-access-stack":s.length,className:"flex shrink-0 -space-x-0.5 rtl:space-x-reverse",children:[s.slice(0,Kn).map(r=>e.jsx("span",{className:"flex rounded-full ring-2 ring-card",children:e.jsx(xo,{person:ho(r,n),size:22})},r)),i>0&&e.jsxs("span",{className:"flex h-[22px] min-w-[22px] items-center justify-center rounded-full bg-card px-1 text-[11px] font-medium text-ink-secondary ring-2 ring-card",children:["+",i]})]})}function $m({people:s,anyPeople:n,bots:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:Ks,children:s.map(r=>{const c=a.filter(o=>$i(o,r.email)).length;return e.jsx("li",{className:"min-w-0",children:e.jsxs("button",{type:"button","data-access-person":r.email,onClick:()=>i(r.email),className:z($s,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Ha,{person:r,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] leading-[18px] text-ink",children:r.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:r.email})]}),e.jsx("span",{className:"shrink-0 text-[13px] text-ink-secondary",children:c===1?t("botAccess.overview.botCount.one"):t("botAccess.overview.botCount.other",{count:c})})]})},r.email)})}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.noMatch")}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noPeople")})}function Km({person:s,bots:n,team:a,teamName:i,apply:r,onBack:c}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsxs("button",{type:"button",autoFocus:!0,"data-access-back":!0,onClick:c,className:"-ms-2 flex items-center gap-1 rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-ink/[0.06] hover:text-ink",children:[e.jsx(zr,{size:14,"aria-hidden":"true",className:"rtl:-scale-x-100"}),t("botAccess.overview.allPeople")]})}),e.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-3",children:[e.jsx(Ha,{person:s,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] font-medium leading-[18px] text-ink",children:s.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:s.email})]})]}),n.length===0?e.jsx("p",{className:"px-3 text-[13px] text-ink-secondary",children:t("botAccess.overview.noBotsForPerson",{name:s.name})}):e.jsx("ul",{className:Ks,children:n.map(o=>e.jsx(Hm,{bot:o,person:s,team:a,teamName:i,apply:r},o.id))})]})}function Hm({bot:s,person:n,team:a,teamName:i,apply:r}){const c=Ft(s),o=Ut(s)===n.email,d=c.people[n.email],m=Wa(c,n.email);return e.jsxs("li",{className:$s,"data-access-person-bot":s.id,children:[e.jsx(Bt,{bot:s,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] leading-[18px] text-ink",children:s.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:!d&&!o&&m===c.everyone?t("botAccess.everyoneUse",{team:i}):Ki(s,a)})]}),e.jsx("span",{className:"min-w-0 shrink-0 text-[13px] text-ink-secondary",children:o?e.jsx("span",{className:"px-2",children:t("lookedAfter.badge")}):d?e.jsx("button",{type:"button","data-access-remove":s.id,"aria-label":t("botAccess.overview.removeFrom",{name:n.name,bot:s.name}),onClick:()=>{r(s,mo(c,n.email,null),t("botAccess.overview.toastRemoved",{name:n.name,bot:s.name}))},className:"rounded-md px-2 py-1 hover:bg-ink/[0.06] hover:text-ink",children:t("botAccess.remove")}):null})]})}function Wm(s){const n=s.trim();if(!n||/[\s\\?#@%]/.test(n))return null;try{const a=new URL(n.includes("://")?n:`https://${n}`),i=a.hostname.replace(/\.$/,"");return a.protocol!=="https:"||a.port||a.pathname!=="/"||!i.includes(".")||i.length>253||/^[\d.]+$/.test(i)||!i.split(".").every(r=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(r))||/(?:^|\.)(?:localhost|local|internal|invalid|test)$/.test(i)?null:i}catch{return null}}function Gm({domain:s,serverIpv4:n}){const a=Wm(s);if(!a)return e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.domain.enterDomain")});const i=[[t("settings.domain.recordType"),"A"],[t("settings.domain.recordName"),a],[t("settings.domain.recordValue"),n]];return e.jsxs("section",{"aria-label":t("settings.domain.dnsRecord"),className:"space-y-2 rounded-lg border border-hairline/50 p-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("settings.domain.dnsRecord")}),e.jsx("dl",{className:"space-y-2",children:i.map(([r,c])=>e.jsxs("div",{className:"grid grid-cols-[80px_minmax(0,1fr)] items-center gap-2",children:[e.jsx("dt",{className:"text-[12px] text-ink-secondary",children:r}),e.jsx("dd",{className:"min-w-0",children:c?e.jsx(rt,{command:c,copyLabel:t("settings.domain.copyField",{field:r})},c):e.jsx("p",{className:"text-[12px] text-warning",children:t("settings.domain.missingIp")})})]},r))}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.domain.recordHint")})]})}function Vm(s){return`bots.example.com {
|
|
1
|
+
import{c as ut,j as e,t,r as l,a as z,S as mt,d as ge,p as ws,k as Rt,X as $e,i as Ss,C as zr,ae as Ca,L as St,aO as Ur,aZ as Fr,a8 as Dr,R as _r,l as Me,a_ as $r,a$ as Kr,ab as Hr,b0 as Wr,b1 as Lt,ax as en,y as Gr,au as Vr,z as tn,ay as Ea,b as qr,b2 as Jr,B as Xr,b3 as Yr,A as Qr,aD as Zr,b4 as sn,aC as el,b5 as tl,b6 as nn,b7 as an,b8 as rn,b9 as sl,ba as nl,ah as al,bb as il}from"./styles-CbbuPFF7.js";import{L as rl}from"./LimixResizeHandles-DwJ0Ihrt.js";import{L as X,P as Ce,v as pt,E as ll,ah as ol,ai as cl,$ as dl,W as ul,l as Cs,C as Aa,B as Bt,aj as ml,ak as pl,al as xl,d as Ia,r as hl,h as ln,g as on,i as gl,am as fl,an as bl,ao as yl,ap as Wt,A as vl,p as jl,aq as kl,ar as Pa,as as Nl,R as Ta,c as wl,at as Sl,au as Cl,M as El,ab as Al,av as Il,aw as os,b as Pl,t as Tl,U as Rl,N as Gt,f as Ll}from"./PlacesRail-RbEQCQDz.js";import{bY as Ot,u as W,S as me,j as M,h6 as Be,T as Ee,dA as Qe,w as xe,cT as Bl,cP as Ra,eV as Ze,h7 as Ol,Y as Oe,eT as Ml,eU as zl,h8 as cs,h9 as lt,ha as La,hb as Es,hc as As,hd as Ul,e8 as cn,he as Ba,hf as Oa,hg as Fl,hh as Dl,hi as _l,a2 as ue,c7 as Y,eg as ds,eS as $l,hj as Ma,hk as Nt,hl as Mt,hm as za,hn as Ua,ho as Le,hp as _e,hq as Kl,hr as Hl,hs as Wl,ht as Gl,hu as Vl,hv as Fa,hw as ql,hx as Jl,hy as Da,hz as _a,hA as be,hB as ye,dw as dn,hC as zt,hD as Xl,hE as Yl,hF as Ql,hG as Zl,hH as eo,g$ as $a,bu as to,x as L,hI as rt,R as so,dP as no,hJ as ao,hK as un,aQ as Ct,fA as ot,fB as ct,hL as io,K as Ye,r as ro,cs as lo,gQ as oo,hM as Ut,hN as Ka,hO as co,hP as uo,hQ as mn,hR as Ha,hS as Ft,hT as Wa,hU as mo,hV as po,hW as xo,hX as ho,G as go,hY as fo,hZ as dt,en as Dt,h_ as bo,h$ as yo,i0 as vo,i1 as jo,fI as ko,i2 as pn,i3 as No,i4 as wo,E as So,i5 as xn,i6 as Co,el as Ga,i7 as Eo,i8 as Ao,i9 as Io,ia as Po,ib as To,ic as Ro,id as Va,ie as Lo,ig as Bo,ih as Oo,ii as Mo,ij as zo,ik as Uo,il as qa,im as Fo,io as Do,dV as _o,ip as $o,eh as Ko,iq as Ho,ir as Wo,is as Go,it as Vo,iu as hn,iv as qo,iw as Jo,ix as gn,l as Xo,iy as Yo,iz as Qo,iA as Zo,bR as ec,iB as tc,iC as sc,iD as nc,iE as ac,iF as Ja,fy as nt,iG as ic,fx as rc,iH as Xa,iI as lc,iJ as Ya,iK as oc,iL as fn,i as cc,iM as us,iN as bn,iO as yn,iP as dc,iQ as uc,iR as mc,iS as pc,iT as xc,iU as hc,iV as gc,iW as fc,iX as bc,iY as Is,iZ as yc,fo as Qa,h as vc,i_ as jc,i$ as kc,j0 as vn,j1 as Nc,j2 as wc,j3 as jn,j4 as Sc,b9 as Cc,j5 as Ec,j6 as Ac,j7 as Ic,bJ as Pc,j8 as Tc,j9 as kn,ja as Rc,bE as Ps,jb as Lc,bF as Bc,jc as Oc,jd as Mc,je as zc,jf as Uc,jg as Fc,jh as Dc,ji as _c,jj as $c,jk as Nn,gC as Kc,jl as Hc,jm as Wc,jn as Za,jo as Gc,jp as Vc,jq as qc,jr as ei,js as ti,jt as si,ju as Jc,jv as Xc,jw as Yc,dc as Qc,I as Zc,jx as ni,eN as ed,c5 as wn,jy as td,jz as Sn,fa as Cn,e7 as sd,_ as nd,az as ad,jA as id,jB as rd,jC as ld}from"./App-BDek3TXw.js";import{C as Ts,a as od,R as Se}from"./MenuMotion-p_3OSw7G.js";import{l as ai,M as cd,w as En}from"./MacLocalControl-B_r8KnC1.js";import{Q as ii}from"./VisibilitySection-CFAscYka.js";import{a as dd,r as ud,C as md,s as ri,b as pd,c as xd,w as hd,t as gd,T as fd,l as Rs,d as An,e as bd,f as yd}from"./index-B4VKEuQ6.js";import{c as vd,A as jd,w as kd,d as Nd,e as In}from"./activity-sibNyUyL.js";import{U as li,R as oi,B as ci,S as di,a as ui,D as mi,T as pi,C as xi,L as ms,b as hi,F as gi,A as ps,E as wd,c as Sd,P as Cd,d as Ed,e as Ad,N as Id}from"./NewBotDialog-CjhREbKo.js";import{a as Pd,u as Td,C as fi,b as Rd,P as Ld}from"./ProIntroduction-CNDF-TfS.js";import{M as bi}from"./monitor-DInAobl-.js";import{C as Bd}from"./coins-ClQfPsPX.js";import"./org-library-ClYoJFnL.js";import"./package-format--z2ustts.js";import"./mcp-servers-_PFzCXco.js";import"./WorksOnGrid-Btzc4Woq.js";import"./new-bot-Div0m6qw.js";import"./RoutinesPage-BkY2zvS9.js";import"./remote-desktop-DDRRx8uY.js";import"./team-share-DdYOqcXI.js";import"./BrowserProfilesManager-hX2FZVA6.js";import"./SignedInSites-h30xrxTC.js";const Od=[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]],Md=ut("cloud-download",Od);const zd=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Ud=ut("palette",zd);const Fd=[["path",{d:"M15 12h-5",key:"r7krc0"}],["path",{d:"M15 8h-5",key:"1khuty"}],["path",{d:"M19 17V5a2 2 0 0 0-2-2H4",key:"zz82l3"}],["path",{d:"M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3",key:"1ph1d7"}]],Dd=ut("scroll-text",Fd);const _d=[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]],$d=ut("terminal",_d);const Kd=[["path",{d:"m19 5 3-3",key:"yk6iyv"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z",key:"1snsnr"}]],Hd=ut("unplug",Kd);function Ls(s){return s.filter(n=>n.driverKind==="openai-compat"&&n.instanceId.startsWith("openai-compat-"))}function je({children:s,note:n="settings.adminOnly.change"}){return Ot()===!1?e.jsx("p",{"data-admin-only":!0,className:"text-[13px] text-ink-secondary",children:t(n)}):s}function Bs(s,n,a="start",i=0){const r=n.getBoundingClientRect().top-s.getBoundingClientRect().top+s.scrollTop;s.scrollTop=Math.max(0,a==="center"?r-(s.clientHeight-(n.offsetHeight??0))/2:r-i)}function Wd(s){for(let n=s.parentElement;n;n=n.parentElement){const a=getComputedStyle(n).overflowY;if((a==="auto"||a==="scroll")&&n.scrollHeight>n.clientHeight)return n}return null}function Gd(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(!1),[r,c]=l.useState(null),o=s.config?.tts?.everyReply===!0,d=()=>{i(!0),c(null),M("/api/config",{method:"PUT",body:JSON.stringify({tts:{everyReply:!o}})}).then(m=>n({type:"configStatus",config:m})).catch(m=>c(m.message)).finally(()=>i(!1))};return e.jsxs("div",{"data-voice-every-reply":!0,className:"flex items-center justify-between gap-4 px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-medium leading-5 text-ink",children:t("voice.everyReply")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-4 text-ink-secondary",children:t("voice.everyReply.allHelp")}),r&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:r})]}),e.jsx(me,{checked:o,disabled:a,"aria-label":t("voice.everyReply"),onClick:d})]})}const Vd="https://api.xingchiapi.com/v1",qd={claude:{url:"https://api.anthropic.com",model:"deepseek-chat"},codex:{url:"https://api.openai.com/v1",model:""}},ft=z(Be,"font-sans"),Pn={name:"",url:"",token:"",model:""},Jd=s=>({name:s.displayName,url:(s.claudeEndpoint??s.codexEndpoint)?.baseUrl??"",token:"",model:(s.claudeEndpoint??s.codexEndpoint)?.model??""});function Os({instance:s,engine:n,onDone:a,xingchi:i=!1}){const{dispatch:r}=W(),c=qd[n],[o,d]=l.useState(s?Jd(s):i?{...Pn,name:"Xingchi (Codex Responses)",url:Vd}:Pn),[m,u]=l.useState(!1),[x,p]=l.useState(null),h=b=>({value:o[b],onChange:g=>d(k=>({...k,[b]:g.target.value})),spellCheck:!1,disabled:m}),f=!!(o.name.trim()&&(o.url.trim()||n==="codex")&&(s||o.token.trim())),y=async()=>{if(m||!f)return;u(!0),p(null);const b={displayName:o.name.trim(),...i&&!s?{profile:"xingchi"}:{},baseUrl:o.url.trim()||c.url,...o.token.trim()?{token:o.token.trim()}:{},...o.model.trim()?{model:o.model.trim()}:{}};try{const g=s?await M(`/api/instances/${encodeURIComponent(s.instanceId)}/${n}-endpoint`,{method:"PATCH",body:JSON.stringify(b)}):await M(`/api/instances/${n}-endpoint`,{method:"POST",body:JSON.stringify(b)});Array.isArray(g.instances)&&r({type:"instances",instances:g.instances}),a()}catch(g){const k=g instanceof Error?g.message:"";p(k.includes("HTTP 403, client_not_allowed")?t("agentEndpoints.modelListClientDenied"):k||t("claudeEndpoints.failed"))}finally{u(!1)}};return e.jsxs("form",{"data-claude-endpoint-form":n==="claude"?s?.instanceId??"new":void 0,"data-codex-endpoint-form":n==="codex"?s?.instanceId??"new":void 0,className:"flex flex-col gap-2 rounded-xl border border-hairline/50 bg-inset p-3",onSubmit:b=>{b.preventDefault(),y()},children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t(n==="codex"?"agentEndpoints.responses":"agentEndpoints.messages")}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.name"),e.jsx("input",{...h("name"),maxLength:80,autoFocus:!0,"aria-label":t("claudeEndpoints.name"),className:ft})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.baseUrl"),e.jsx("input",{...h("url"),readOnly:i||s?.codexEndpoint?.profile==="xingchi",type:"url",maxLength:2048,placeholder:c.url,"aria-label":t("claudeEndpoints.baseUrl"),className:z(ft,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.token"),e.jsx("input",{...h("token"),type:"password",maxLength:4096,autoComplete:"off","aria-label":t("claudeEndpoints.token"),className:z(ft,"font-mono"),placeholder:s?t("claudeEndpoints.tokenKeep"):""})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeEndpoints.model"),e.jsx("input",{...h("model"),maxLength:160,placeholder:c.model,"aria-label":t("claudeEndpoints.model"),className:z(ft,"font-mono")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeEndpoints.modelHint")}),x&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:x}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:a,disabled:m,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:m||!f,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[m&&e.jsx(X,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function yi({instance:s,showName:n=!1}){const{state:a,dispatch:i}=W(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[m,u]=l.useState(!1),[x,p]=l.useState(null),h=a.bots.filter(b=>b.modelSelection.instanceId===s.instanceId||b.fallback?.some(g=>g.instanceId===s.instanceId)||b.tasks?.some(g=>g.modelSelection?.instanceId===s.instanceId)).length,f=s.claudeEndpoint??s.codexEndpoint;if(!f||s.readOnly)return null;const y=async()=>{d(!1),u(!0),p(null);try{const b=await M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(b.instances)&&i({type:"instances",instances:b.instances})}catch(b){p(b instanceof Error?b.message:String(b))}finally{u(!1)}};return r?e.jsx(Os,{instance:s,engine:s.codexEndpoint?"codex":"claude",onDone:()=>c(!1)}):e.jsxs("div",{"data-claude-endpoint":s.claudeEndpoint?s.instanceId:void 0,"data-codex-endpoint":s.codexEndpoint?s.instanceId:void 0,children:[e.jsxs("div",{className:"flex min-h-9 flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[n&&e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:s.displayName,children:s.displayName}),e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",title:f.baseUrl,children:f.baseUrl}),f.model&&e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",title:f.model,children:f.model})]}),e.jsx("button",{type:"button",onClick:()=>c(!0),disabled:m,className:"ui-button shrink-0",children:t("claudeEndpoints.edit")}),e.jsxs("button",{type:"button",disabled:m||h>0,onClick:()=>d(!0),title:h>0?t("accounts.inUse",{count:String(h)}):t("accounts.remove"),"aria-label":t("claudeEndpoints.remove",{name:s.displayName}),className:"flex min-h-8 shrink-0 items-center justify-center gap-1.5 rounded-lg px-2.5 text-[12px] font-medium text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:[m?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(Ee,{size:14}),t("common.delete")]})]}),h>0&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("accounts.inUse",{count:String(h)})}),x&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:x}),e.jsx(Qe,{open:o,title:t("accounts.removeTitle",{name:s.displayName}),body:t("claudeEndpoints.removeBody"),confirmLabel:t("common.delete"),pending:m,onCancel:()=>d(!1),onConfirm:()=>{y()}})]})}function vi({engine:s}){const{state:n}=W(),a=n.instances.filter(c=>!c.readOnly&&(s==="claude"?c.claudeEndpoint:c.codexEndpoint)),[i,r]=l.useState(!1);return e.jsxs("div",{"data-claude-endpoints":s==="claude"?"":void 0,"data-codex-endpoints":s==="codex"?"":void 0,className:"mt-3 space-y-2",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t(s==="claude"?"claudeEndpoints.title":"agentEndpoints.codexTitle")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t(s==="claude"?"claudeEndpoints.hint":"agentEndpoints.codexHint")}),a.length===0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeEndpoints.empty")}):e.jsx("ul",{className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:a.map(c=>e.jsx("li",{className:"px-3 py-2.5",children:e.jsx(yi,{instance:c,showName:!0})},c.instanceId))}),i?e.jsx(Os,{engine:s,onDone:()=>r(!1)}):e.jsxs("button",{type:"button",onClick:()=>r(!0),className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),t("claudeEndpoints.add")]})]})}function Vt(){return e.jsx(vi,{engine:"claude"})}function wt(){return e.jsx(vi,{engine:"codex"})}function qt(s){return[...new Set(s.split(/[,,、\s]+/).map(n=>n.trim()).filter(Boolean))]}const De=z(Be,"font-sans"),Xd=[5,10,20,30,60],Jt="ui-icon-button shrink-0 hover:text-ink",Xt={name:"Google Gemini",url:"https://generativelanguage.googleapis.com/v1beta/openai"},xs={count:64,length:200},Yd=s=>s.length<=xs.count&&s.every(n=>n.length<=xs.length),hs=(s,n)=>M(`/api/instances/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(n)});function ji({server:s,disabled:n,onPick:a}){return e.jsxs(xe,{size:"sm",className:"shrink-0",value:s.replyWaitMinutes??"",onChange:i=>a(i.target.value?Number(i.target.value):null),disabled:n,"aria-label":t("apiInstances.replyWaitFor",{name:s.displayName}),title:t("apiInstances.replyWaitHint"),children:[e.jsx("option",{value:"",children:t("apiInstances.replyWaitDefault")}),[...new Set([...Xd,...s.replyWaitMinutes?[s.replyWaitMinutes]:[]])].sort((i,r)=>i-r).map(i=>e.jsx("option",{value:i,children:t("apiInstances.replyWaitMinutes",{minutes:String(i)})},i))]})}function Qd(){const{state:s,dispatch:n,refreshInstances:a}=W(),[i,r]=l.useState(!1),[c,o]=l.useState(null),d=s.instances.find(u=>u.instanceId==="openaiCompat"&&u.driverKind==="openai-compat");if(!d||!s.config?.openaiCompat?.url)return null;const m=u=>{i||(r(!0),o(null),hs(d.instanceId,{replyWaitMinutes:u}).then(async({instances:x})=>{Array.isArray(x)?n({type:"instances",instances:x}):await a({reportErrors:!0})}).catch(x=>o(x.message||t("apiInstances.failed"))).finally(()=>r(!1)))};return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(ji,{server:d,disabled:i,onPick:m}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.replyWaitHint")}),c&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:c})]})}function Zd(){const{state:s}=W();return e.jsxs(e.Fragment,{children:[e.jsx(eu,{servers:Ls(s.instances)}),e.jsxs("details",{className:"mt-3 rounded-lg border border-hairline/60 bg-inset px-3 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[13px] text-ink",children:t("agentEndpoints.codexConnect")}),e.jsx(wt,{})]})]})}function eu({servers:s}){const{dispatch:n,refreshInstances:a}=W(),[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(""),[u,x]=l.useState(""),[p,h]=l.useState(null),[f,y]=l.useState(null),[b,g]=l.useState(null),[k,S]=l.useState(""),C=!!(i.trim()&&c.trim()&&d.trim()),w=(v,B,j,A)=>{p||(h(v),y(null),B().then(async({instances:I})=>{Array.isArray(I)?n({type:"instances",instances:I}):await a({reportErrors:!0}),j?.()}).catch(I=>y({text:I.message||t("apiInstances.failed"),at:A})).finally(()=>h(null)))},P=()=>C&&w("add",()=>M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:i.trim(),url:c.trim(),key:d.trim(),...qt(u).length?{models:qt(u)}:{}})}).then(v=>(Ze("custom_endpoint","settings","unverified"),v),v=>{throw Ze("custom_endpoint","settings","error"),v}),()=>{r(""),o(""),m(""),x("")});return e.jsxs("div",{"data-api-keys-other":!0,children:[e.jsx("div",{className:"mb-0.5 text-[13px] leading-[18px] text-ink",children:t("apiInstances.title")}),e.jsx("p",{className:"mb-2 text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.subtitle")}),s.length===0&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.empty")}),s.map(v=>e.jsxs("div",{className:"mb-1.5 rounded-lg border border-hairline/60 bg-inset px-3 py-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12px] text-ink",children:v.displayName}),v.url&&e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",children:v.url})]}),e.jsx(ji,{server:v,disabled:p!==null,onPick:B=>w("other",()=>hs(v.instanceId,{replyWaitMinutes:B}))}),e.jsx("button",{type:"button",onClick:()=>{S((v.managedModels??[]).join(", ")),g(b===v.instanceId?null:v.instanceId),y(null)},disabled:p!==null,"aria-label":t("apiInstances.editModels",{name:v.displayName}),"aria-expanded":b===v.instanceId,title:t("apiInstances.editModels",{name:v.displayName}),className:Jt,children:e.jsx(Bl,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>w("other",()=>M(`/api/instances/${encodeURIComponent(v.instanceId)}/refresh-models`,{method:"POST"})),disabled:p!==null,"aria-label":t("apiInstances.refreshModels",{name:v.displayName}),title:t("apiInstances.refreshModels",{name:v.displayName}),className:Jt,children:e.jsx(Ra,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:()=>w("other",()=>M(`/api/instances/${encodeURIComponent(v.instanceId)}`,{method:"DELETE"})),disabled:p!==null,"aria-label":t("apiInstances.remove",{name:v.displayName}),title:t("apiInstances.remove",{name:v.displayName}),className:`${Jt} hover:bg-danger/10 hover:text-danger`,children:e.jsx(Ee,{size:13,"aria-hidden":"true"})})]}),b===v.instanceId&&e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1.5",children:[e.jsx("input",{value:k,onChange:B=>S(B.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.modelsFor",{name:v.displayName}),spellCheck:!1,disabled:p!==null,className:z(De,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.editModelsHint")}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{const B=qt(k);if(!Yd(B)){y({text:t("apiInstances.modelsLimit",xs),at:v.instanceId});return}w("other",()=>hs(v.instanceId,{models:B}),()=>g(null),v.instanceId)},disabled:p!==null,className:"ui-button",children:t("common.save")}),e.jsx("button",{type:"button",onClick:()=>g(null),disabled:p!==null,className:"ui-button",children:t("common.cancel")})]}),f?.at===v.instanceId&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:f.text})]})]},v.instanceId)),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{r(Xt.name),o(Xt.url)},disabled:p!==null,className:"ui-button self-start",children:t("apiInstances.geminiPreset")}),c.trim()===Xt.url&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.geminiKeyHint")}),e.jsx("input",{value:i,onChange:v=>r(v.target.value),placeholder:t("apiInstances.name"),"aria-label":t("apiInstances.name"),spellCheck:!1,disabled:p!==null,className:De}),e.jsx("input",{type:"url",value:c,onChange:v=>o(v.target.value),placeholder:"https://api.example.com/v1","aria-label":t("apiInstances.url"),spellCheck:!1,disabled:p!==null,className:z(De,"font-mono")}),e.jsx("input",{type:"password",value:d,onChange:v=>m(v.target.value),placeholder:t("apiInstances.key"),"aria-label":t("apiInstances.key"),autoComplete:"off",disabled:p!==null,className:z(De,"font-mono")}),e.jsx("input",{value:u,onChange:v=>x(v.target.value),placeholder:t("apiInstances.models"),"aria-label":t("apiInstances.models"),spellCheck:!1,disabled:p!==null,className:z(De,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("apiInstances.modelsHint")}),e.jsxs("button",{type:"button",onClick:P,disabled:p!==null||!C,className:"ui-button self-start",children:[p==="add"?e.jsx(X,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),p==="add"?t("apiInstances.adding"):t("apiInstances.add")]})]}),f&&!f.at&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:f.text})]})}const tu="lm-studio";function su(s){const n=s.trim();if(!/^[1-9]\d{0,4}$/.test(n))return null;const a=Number(n);return a>65535?null:`http://127.0.0.1:${a}/v1`}function nu({heading:s=!0}={}){const{state:n,dispatch:a,refreshInstances:i}=W(),r=Ls(n.instances),[c,o]=l.useState("1234"),[d,m]=l.useState(""),[u,x]=l.useState(!1),[p,h]=l.useState(null),f=su(c),y=!!(f&&r.some(g=>g.url===f)),b=()=>{u||!f||y||(x(!0),h(null),M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"LM Studio",url:f,key:d.trim()||tu,catalog:"lmstudio"})}).then(async g=>{Ze("custom_endpoint","settings","unverified"),Array.isArray(g.instances)?a({type:"instances",instances:g.instances}):await i({reportErrors:!0}),m("")},g=>{Ze("custom_endpoint","settings","error"),h(g instanceof Error&&g.message?g.message:t("apiInstances.failed"))}).finally(()=>x(!1)))};return e.jsxs("div",{className:z(s&&"rounded-lg border border-hairline/40 bg-inset px-3 py-2"),children:[s&&e.jsx("div",{className:"text-[13px] text-ink",children:t("lmStudio.title")}),e.jsx("p",{className:z("text-[12px] leading-4 text-ink-secondary",s&&"mt-1"),children:t("lmStudio.desc")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] leading-4 text-ink-secondary",children:[t("lmStudio.port"),e.jsx("input",{inputMode:"numeric",value:c,onChange:g=>o(g.target.value),"aria-label":t("lmStudio.port"),spellCheck:!1,disabled:u,className:z(De,"font-mono")})]}),e.jsx("input",{type:"password",value:d,onChange:g=>m(g.target.value),placeholder:t("lmStudio.token"),"aria-label":t("lmStudio.token"),autoComplete:"off",disabled:u,className:z(De,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("lmStudio.tokenHint")}),f&&e.jsx("p",{className:"truncate font-mono text-[12px] leading-4 text-ink-secondary",children:f}),e.jsxs("button",{type:"button",onClick:b,disabled:u||!f||y,className:"ui-button self-start",children:[u?e.jsx(X,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),u?t("lmStudio.adding"):t("lmStudio.add")]}),y&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("lmStudio.added")})]}),p&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:p})]})}const au="ollama",iu="https://ollama.com/download",ru=s=>`${s.replace(/\/+$/,"")}/v1`,lu=(s,n)=>s?.trim().replace(/\/+$/,"")===n;function ou({visible:s}){const{state:n,dispatch:a,refreshInstances:i}=W(),[r,c]=l.useState(""),[o,d]=l.useState(null),[m,u]=l.useState(!1),[x,p]=l.useState(!1),[h,f]=l.useState(null),y=l.useRef(0),b=l.useRef(!1),g=l.useCallback(P=>{const v=++y.current;u(!0),f(null),M(`/api/instances/ollama${P?`?url=${encodeURIComponent(P)}`:""}`).then(B=>{v===y.current&&d(B.status)}).catch(B=>{v===y.current&&(d(null),f(B.message||t("apiInstances.failed")))}).finally(()=>{v===y.current&&u(!1)})},[]);l.useEffect(()=>{!s||b.current||(b.current=!0,g(""))},[s,g]);const k=o?ru(o.url):null,S=!!(k&&(Ls(n.instances).some(P=>P.url===k)||lu(n.config?.openaiCompat?.url,k))),C=!!(k&&!S&&!x&&!m&&(o?.state==="ready"||o?.state==="no-models")),w=()=>{!C||!k||(p(!0),f(null),M("/api/instances/openai-compat",{method:"POST",body:JSON.stringify({displayName:"Ollama",url:k,key:au,catalog:"ollama"})}).then(async P=>{Ze("custom_endpoint","settings","unverified"),Array.isArray(P.instances)?a({type:"instances",instances:P.instances}):await i({reportErrors:!0})},P=>{Ze("custom_endpoint","settings","error"),f(P instanceof Error&&P.message?P.message:t("apiInstances.failed"))}).finally(()=>p(!1)))};return e.jsxs("div",{"data-ollama-server":!0,children:[e.jsx("div",{role:"status","aria-live":"polite",children:m?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] leading-4 text-ink-secondary",children:[e.jsx(X,{size:12,className:"animate-spin","aria-hidden":"true"}),t("ollama.checking")]}):o&&e.jsx(Ol,{status:o})}),!m&&o?.state==="not-running"&&e.jsx("a",{href:iu,target:"_blank",rel:"noopener noreferrer",className:"mt-1 inline-block text-[12px] font-medium text-accent-text hover:underline",children:t("ollama.download")}),e.jsxs("div",{className:"mt-2 flex flex-col gap-1.5",children:[e.jsx("input",{type:"url",value:r,onChange:P=>c(P.target.value),onKeyDown:P=>{P.key==="Enter"&&g(r.trim())},placeholder:"http://127.0.0.1:11434","aria-label":t("ollama.address"),spellCheck:!1,disabled:x,className:z(Be,"font-mono")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("ollama.addressHint")}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsxs("button",{type:"button",onClick:w,disabled:!C,className:"ui-button",children:[x?e.jsx(X,{size:12,"aria-hidden":"true",className:"animate-spin"}):e.jsx(Ce,{size:12,"aria-hidden":"true"}),x?t("ollama.adding"):t("ollama.add")]}),e.jsxs("button",{type:"button",onClick:()=>g(r.trim()),disabled:m||x,className:"ui-button",children:[e.jsx(Ra,{size:12,"aria-hidden":"true"}),t("common.checkAgain")]})]}),S&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("ollama.added")})]}),h&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:h})]})}function cu(){const{state:s,dispatch:n}=W(),a=s.config?.opencodeGo?.providerKeys??[],[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(!1),[u,x]=l.useState(null),[p,h]=l.useState(null),f=d||u!==null,y=(k,S)=>M("/api/config",{method:"PUT",body:JSON.stringify({opencodeGo:{providerKeys:{[k]:S}}})}).then(C=>n({type:"configStatus",config:C})),b=()=>{const k=i.trim().toUpperCase(),S=Ml(c);if(!(f||!k||!S)){if(!zl(S)){h(t("keys.notAKey"));return}m(!0),h(null),y(k,S).then(()=>{r(""),o("")}).catch(C=>h(C.message)).finally(()=>m(!1))}},g=k=>{f||(x(k),h(null),y(k,"").catch(S=>h(S.message)).finally(()=>x(null)))};return e.jsxs("div",{"data-opencode-provider-keys":!0,className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.opencode.otherProviders.hint")}),s.config?.cloudHome!==!0&&e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.opencode.providersHint").split("{command}").flatMap((k,S)=>S===0?[k]:[e.jsx("code",{className:"font-mono",children:"opencode auth login"},S),k])}),a.map(k=>e.jsxs("div",{"data-opencode-provider-key":k,className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:z(Be,"block flex-1 truncate text-ink"),children:k}),e.jsx("button",{type:"button",onClick:()=>g(k),disabled:f,"aria-label":t("keys.opencode.otherProviders.removeAria",{name:k}),className:"ui-button shrink-0",children:u===k?e.jsx(X,{size:13,className:"animate-spin","aria-hidden":"true"}):t("keys.row.remove")})]},k)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text",value:i,onChange:k=>{h(null),r(k.target.value)},onKeyDown:k=>k.key==="Enter"&&b(),disabled:f,placeholder:"VENICE_API_KEY","aria-label":t("keys.opencode.otherProviders.name"),autoComplete:"off",spellCheck:!1,className:z(Be,"w-auto min-w-[min(100%,10rem)] flex-1 uppercase placeholder:normal-case")}),e.jsx("input",{type:"password",value:c,onChange:k=>{h(null),o(k.target.value)},onKeyDown:k=>k.key==="Enter"&&b(),disabled:f,placeholder:t("keys.opencode.otherProviders.keyPlaceholder"),"aria-label":t("keys.opencode.otherProviders.key"),autoComplete:"off",className:z(Be,"w-auto min-w-[min(100%,10rem)] flex-1")}),e.jsx("button",{type:"button",onClick:b,disabled:f||!i.trim()||!c.trim(),className:"ui-button ui-button-primary shrink-0",children:d?e.jsx(X,{size:13,className:"animate-spin","aria-hidden":"true"}):t("common.save")})]}),p&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:p})]})}function du(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(!1),[r,c]=l.useState(null);if(!s.config?.anthropic?.configured)return null;const o=s.config.anthropic.everyClaudeBot===!0,d=()=>{a||(i(!0),c(null),M("/api/config",{method:"PUT",body:JSON.stringify({anthropic:{everyClaudeBot:!o}})}).then(m=>n({type:"configStatus",config:m})).catch(m=>c(m.message)).finally(()=>i(!1)))};return e.jsxs("div",{"data-anthropic-every-claude-bot":!0,className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("keys.anthropic.everyBot")}),e.jsx("div",{className:"text-[12px] leading-4 text-ink-secondary",children:o?t("keys.anthropic.everyBotOn"):t("keys.anthropic.everyBotOff")})]}),e.jsx(me,{checked:o,disabled:a,onClick:d,"aria-label":t("keys.anthropic.everyBot")})]}),o&&e.jsxs("p",{className:"flex gap-1.5 text-[12px] leading-4 text-warning",children:[e.jsx(Oe,{size:13,className:"mt-px shrink-0","aria-hidden":"true"}),e.jsx("span",{children:t("keys.anthropic.warning")})]}),r&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:r})]})}function uu(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),m=!!s.config?.vps?.configured,u=!a.trim()&&m;l.useEffect(()=>{i(s.config?.vps?.sshAlias??"")},[s.config?.vps?.sshAlias]);const x=()=>{r||!a.trim()&&!m||(c(!0),d(null),M("/api/config",{method:"PUT",body:JSON.stringify({vps:{sshAlias:a.trim()}})}).then(p=>{n({type:"configStatus",config:p}),i(p.vps?.sshAlias??"")}).catch(p=>d(p.message)).finally(()=>c(!1)))};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("p",{className:"text-[12px] leading-4 text-ink-secondary",children:[t("keys.vps.descBefore"),e.jsx("a",{href:"https://github.com/leomieo/limix-bot/blob/main/docs/byo-vps.md",target:"_blank",rel:"noopener noreferrer",className:"text-accent-text hover:underline",children:t("keys.vps.descLink")}),t("keys.vps.descAfter")]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"text","data-key-input":!0,value:a,onChange:p=>i(p.target.value),onKeyDown:p=>p.key==="Enter"&&x(),placeholder:"my-vps","aria-label":t("keys.vps.aria"),autoComplete:"off",spellCheck:!1,className:z(Be,"w-auto min-w-[min(100%,12rem)] flex-1")}),e.jsx("button",{type:"button",onClick:x,disabled:r||!a.trim()&&!m||a.trim()===(s.config?.vps?.sshAlias??""),className:z("ui-button shrink-0",!u&&"ui-button-primary"),title:u?t("keys.vps.removeAlias"):void 0,children:r?e.jsx(X,{size:13,className:"animate-spin","aria-hidden":"true"}):u?t("keys.row.remove"):t("common.save")})]}),o&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:o})]})}function mu(){const{state:s,dispatch:n}=W(),a=s.config?.openaiCompat?.url??"",[i,r]=l.useState(a),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=l.useRef(!1);l.useEffect(()=>{r(a)},[a]);const x=i.trim()!==a,p=()=>{u.current||!x||(u.current=!0,o(!0),m(null),M("/api/config",{method:"PUT",body:JSON.stringify({openaiCompat:{url:i.trim()}})}).then(h=>n({type:"configStatus",config:h})).catch(h=>m(h.message)).finally(()=>{u.current=!1,o(!1)}))};return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("keys.openaiCompat.url")}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"url",value:i,onChange:h=>r(h.target.value),onBlur:p,onKeyDown:h=>h.key==="Enter"&&p(),placeholder:"https://api.groq.com/openai/v1","aria-label":t("keys.openaiCompat.url"),spellCheck:!1,className:z(Be,"pr-8")}),c&&e.jsx(X,{size:13,"aria-hidden":"true",className:"absolute right-2.5 top-1/2 -translate-y-1/2 animate-spin text-ink-secondary"})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("keys.openaiCompat.urlHint")}),d&&e.jsx("div",{role:"alert",className:"text-[12px] leading-4 text-danger",children:d})]})}const pu="rounded-xl bg-card in-data-[settings-look=simple]:rounded-[12px] in-data-[settings-look=simple]:border-[0.5px] in-data-[settings-look=simple]:border-(--settings-edge) in-data-[settings-look=simple]:bg-menu",xu=1600,hu={opencodeProviders:()=>e.jsx(cu,{}),ollama:s=>e.jsx(ou,{visible:s}),lmStudio:()=>e.jsx(nu,{heading:!1}),vps:()=>e.jsx(uu,{})},gu={anthropic:()=>e.jsx(du,{}),openaiCompat:()=>e.jsxs(e.Fragment,{children:[e.jsx(mu,{}),e.jsx(Qd,{}),e.jsx(Zd,{})]}),box:()=>e.jsx(_l,{}),liveKey:()=>e.jsx(Dl,{})};function ki(s,n){if(s.kind==="uses")return!1;const a=As(s,n);return a.configured||a.included===!0}function fu({entry:s,visible:n}){const{state:a}=W(),i=l.useId(),c=As(s,a.config).configured?{tone:"ok",text:t("keys.connected")}:null;return e.jsxs("div",{"data-key-row":s.id,role:"group","aria-labelledby":i,className:Ba,children:[e.jsx(Oa,{entry:s,status:c,titleId:i}),e.jsx("div",{className:"flex flex-col gap-2 pl-8",children:hu[s.id]?.(n)})]})}function bu({entry:s}){const{state:n,dispatch:a}=W(),i=l.useId(),r=s.opens,c=As(s,n.config),o=c.configured?{tone:"ok",text:t("keys.connected")}:null;return e.jsxs("div",{"data-key-row":s.id,role:"group","aria-labelledby":i,className:Ba,children:[e.jsx(Oa,{entry:s,status:o,titleId:i}),e.jsxs("div",{className:"flex flex-col gap-2 pl-8",children:[c.configured&&e.jsx("div",{className:"flex",children:e.jsx(Fl,{saved:c,label:t(s.labelKey)})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[s.whereKey&&e.jsx("span",{className:"min-w-0 flex-1 text-[12px] leading-4 text-ink-secondary",children:t(s.whereKey)}),r&&e.jsx("button",{type:"button","data-key-open":!0,className:"ui-button shrink-0",onClick:()=>a({type:"toggleAppSettings",open:!0,section:r}),children:t("keys.row.open")})]})]})]})}function yu({entry:s,visible:n}){return s.kind==="uses"&&s.uses?e.jsx(cn,{id:s.uses,row:s.id}):s.kind==="panel"?e.jsx(fu,{entry:s,visible:n}):s.kind==="elsewhere"?e.jsx(bu,{entry:s}):e.jsx(cn,{id:s.id,children:gu[s.id]?.()})}function vu({id:s,rows:n,open:a,onToggle:i}){const{state:r}=W(),c=cs.find(u=>u.id===s),o=l.useId(),d=l.useId(),m=n.filter(u=>ki(u,r.config)).length;return e.jsxs("section",{"data-keys-section":s,"aria-labelledby":o,className:pu,children:[e.jsxs("button",{type:"button","aria-expanded":a,"aria-controls":d,onClick:i,className:"flex w-full cursor-pointer items-center gap-3 rounded-[inherit] px-4 py-2.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus/60",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{id:o,className:"text-[14px] font-medium leading-5 text-ink",children:t(c.titleKey)}),e.jsx("span",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t(c.purposeKey)})]}),m>0&&e.jsx("span",{className:"shrink-0 text-[12px] leading-4 text-ink-secondary",children:t("keys.section.connected",{count:m})}),e.jsx(Ts,{size:14,"aria-hidden":"true",className:z("shrink-0 text-ink-secondary transition-transform motion-reduce:transition-none",a&&"rotate-90")})]}),e.jsxs("div",{id:d,hidden:!a,className:"flex flex-col gap-0.5 border-t border-hairline/40 px-1 py-1.5 in-data-[settings-look=simple]:border-t-[0.5px] in-data-[settings-look=simple]:border-(--settings-edge)",children:[n.map(u=>e.jsx(yu,{entry:u,visible:a},u.id)),s==="voice"&&e.jsx(Gd,{})]})]})}function ju(s,n,a){const i=n.row?s?.querySelector(`[data-key-row="${n.row}"]`):s?.querySelector(`[data-keys-section="${a}"]`);if(!i||i.closest("[hidden]"))return!1;const r=Wd(i);return r&&Bs(r,i,n.row?"center":"start",16),n.row&&(i.querySelector("[data-key-input], [data-key-replace], [data-key-own], [data-key-open], input, button")?.focus({preventScroll:!0}),i.setAttribute("data-key-highlight",""),window.setTimeout(()=>i.removeAttribute("data-key-highlight"),xu)),!0}function ku(){const{state:s}=W(),[n,a]=l.useState(""),[i,r]=l.useState(()=>new Set(cs.filter(p=>p.id==="ai"||lt.some(h=>h.section===p.id&&ki(h,s.config))).map(p=>p.id))),c=l.useRef(null),o=La(),d=n.trim().toLowerCase();l.useEffect(()=>{if(!o)return;const p=lt.find(b=>b.id===o.row)?.section??"ai";a(""),r(b=>b.has(p)?b:new Set([...b,p]));let h=0,f=0;const y=()=>{ju(c.current,o,p)||++f>60?Ul(o):h=window.requestAnimationFrame(y)};return h=window.requestAnimationFrame(y),()=>window.cancelAnimationFrame(h)},[o]);const m=s.config?.live?.provider==="azure",u=lt.filter(p=>Es(p,d)&&!(m&&p.id==="liveCalls")),x=cs.flatMap(p=>{const h=u.filter(f=>f.section===p.id);return h.length>0?[{id:p.id,rows:h}]:[]});return e.jsxs("div",{ref:c,"data-keys-page":!0,className:"flex flex-col gap-4",children:[e.jsx("p",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.connections.subtitle")}),e.jsxs("div",{className:"flex h-8 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] focus-within:ring-2 focus-within:ring-focus/60",children:[e.jsx(mt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-keys-search":!0,type:"text",value:n,onChange:p=>a(p.target.value),onKeyDown:p=>{p.key!=="Escape"||!n||(p.preventDefault(),p.stopPropagation(),a(""))},placeholder:t("keys.search.placeholder"),"aria-label":t("keys.search.aria"),autoComplete:"off",spellCheck:!1,className:"w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),x.length===0?e.jsx("p",{"data-keys-empty":!0,className:"px-1 text-[13px] leading-[18px] text-ink-secondary",children:t("keys.search.none",{query:n.trim()})}):x.map(({id:p,rows:h})=>e.jsx(vu,{id:p,rows:h,open:d!==""||i.has(p),onToggle:()=>r(f=>{const y=new Set(f);return y.has(p)?y.delete(p):y.add(p),y})},p))]})}function Ni({simple:s=!1}){return null}function wi({simple:s=!1}){const n=window.ogb?.openAtLogin,[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(!1);if(l.useEffect(()=>{let u=!0;return n?.state().then(x=>{u&&i(x)}).catch(()=>{}),()=>{u=!1}},[n]),!n||!a?.available)return null;const m=u=>{c(!0),d(!1),n.set(u).then(x=>{i(x),d(x.on!==u)},()=>d(!0)).finally(()=>c(!1))};return e.jsx(ue,{title:t("settings.openAtLogin.title"),subtitle:t(s?"settings.simple.openAtLogin":"settings.openAtLogin.subtitle"),message:o?e.jsx("span",{role:"alert",className:"text-danger",children:t("settings.openAtLogin.failed")}):void 0,children:e.jsx(me,{checked:a.on,disabled:r,"aria-label":t("settings.openAtLogin.title"),onClick:()=>m(!a.on)})})}function Nu(s=typeof window>"u"?void 0:window.ogb){return s?.platform==="darwin"&&s.talkShortcut?["talk","voice","shortcut","hotkey","hold to talk","push to talk","quick asks"]:[]}function Si(){const s=window.ogb?.talkShortcut,[n,a]=l.useState(null),[i,r]=l.useState(!1),[c,o]=l.useState(!1);if(l.useEffect(()=>{let p=!0;return s?.state().then(h=>{p&&a(h)}).catch(()=>{}),()=>{p=!1}},[s]),!s||!n?.available)return null;const d=n.keys.find(p=>p.id===n.key)?.label??"",m=p=>{r(!0),o(!1),s.set(p).then(a,()=>o(!0)).finally(()=>r(!1))},u=c?t("settings.talk.failed"):n.enabled&&n.taken?t("settings.talk.taken",{key:d}):null,x=e.jsxs(e.Fragment,{children:[n.enabled&&e.jsx(xe,{size:"sm",className:"w-full max-w-[240px]",value:n.key,disabled:i,"aria-label":t("settings.talk.keyAria"),onChange:p=>m({key:p.target.value}),children:n.keys.map(p=>e.jsx("option",{value:p.id,children:p.label},p.id))}),u&&e.jsx("div",{role:"alert",className:n.enabled?"mt-2 text-danger":"text-danger",children:u})]});return e.jsx(ue,{title:t("settings.talk.title"),subtitle:t("settings.talk.subtitle",{key:d}),message:n.enabled||u?x:null,children:e.jsx(me,{checked:n.enabled,disabled:i,"aria-label":t("settings.talk.aria"),onClick:()=>m({enabled:!n.enabled})})})}const Yt=s=>s===0||s>=1024*1024?`${Math.round(s/(1024*1024))} MB`:`${Math.ceil(s/1024)} KB`;function Ci(){const[s,n]=l.useState(null),[a,i]=l.useState(!1),[r,c]=l.useState(!1),[o,d]=l.useState(null);if(l.useEffect(()=>{let u=!0;return M("/api/attachment-storage").then(x=>{u&&n(x)}).catch(()=>{}),()=>{u=!1}},[]),!s)return null;const m=async()=>{c(!0),d(null);try{const u=await M("/api/attachment-storage",{method:"POST"});n(u);const x=t("settings.attachments.cleared",{count:u.removed,freed:Yt(u.freedBytes)});d(u.failed>0?{kind:"error",message:`${x} ${t("settings.attachments.failed",{count:u.failed})}`}:{kind:"success",message:x})}catch(u){d({kind:"error",message:u instanceof Error?u.message:String(u)})}finally{c(!1),i(!1)}};return e.jsx(ue,{title:t("settings.attachments.title"),subtitle:e.jsxs(e.Fragment,{children:[e.jsx("span",{"data-attachments-used":!0,className:"block",children:t("settings.attachments.used",{used:Yt(s.usedBytes),max:Yt(s.maxBytes)})}),e.jsx("span",{className:"block",children:t(a?"settings.attachments.confirmText":"settings.attachments.help")})]}),message:o&&e.jsx("p",{role:o.kind==="error"?"alert":"status",className:z(o.kind==="error"?"text-danger":"text-success"),children:o.message}),children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>i(!1),disabled:r,className:"ui-button",children:t("settings.attachments.cancel")}),e.jsx("button",{type:"button",onClick:()=>{m()},disabled:r,className:"ui-button text-danger",children:r?t("settings.attachments.clearing"):t("settings.attachments.confirm")})]}):e.jsx("button",{type:"button",onClick:()=>{d(null),i(!0)},className:"ui-button",children:t("settings.attachments.clear")})})})}function Ei({simple:s=!1}){const[n,a]=l.useState(!1),[i,r]=l.useState(null),[c,o]=l.useState(null),d=async()=>{if(!(!window.ogb?.exportDiagnostics||n)){a(!0),r(null);try{const x=await window.ogb.exportDiagnostics();x&&r({kind:"success",message:t("settings.diagnostics.saved",{path:x})})}catch(x){r({kind:"error",message:x instanceof Error?x.message:String(x)})}finally{a(!1)}}},m=async()=>{if(window.ogb?.openLogsFolder){r(null);try{const x=await window.ogb.openLogsFolder();o(x.folder),x.opened||r({kind:"error",message:t("settings.diagnostics.openFailed",{folder:x.folder})})}catch(x){r({kind:"error",message:x instanceof Error?x.message:String(x)})}}},u=!!window.ogb?.exportDiagnostics;return e.jsx(ue,{title:t("settings.diagnostics.title"),subtitle:t(s?"settings.simple.diagnostics":"settings.diagnostics.subtitle"),message:e.jsxs(e.Fragment,{children:[c&&i?.kind!=="error"&&e.jsx("p",{role:"status","data-logs-folder":!0,className:"break-all text-ink-secondary",children:t("settings.diagnostics.logsAt",{folder:c})}),i&&e.jsx("p",{role:i.kind==="error"?"alert":"status",className:z("break-all",i.kind==="error"?"text-danger":"text-success"),children:i.message}),e.jsx("p",{"data-logs-help":!0,className:"text-ink-tertiary",children:t(u?"settings.diagnostics.logsHelp":"settings.diagnostics.elsewhere")})]}),children:u&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[window.ogb?.openLogsFolder&&e.jsx("button",{type:"button",onClick:()=>{m()},className:"ui-button",children:t("settings.diagnostics.openLogs")}),e.jsx("button",{onClick:()=>{d()},disabled:n,"aria-label":t("settings.diagnostics.aria"),className:"ui-button",children:n?t("settings.diagnostics.exporting"):t("settings.diagnostics.export")})]})})}const wu="https://dash.cloudflare.com/profile/api-tokens",Su=/^[0-9a-f]{32}$/i,Tn="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none";function Cu({failureText:s}){const{state:n,dispatch:a}=W(),i=n.config?.helpers,r=i?.own.workersAi===!0,c=i?.workersAiAccountId??"",[o,d]=l.useState(null),[m,u]=l.useState(""),[x,p]=l.useState(!1),[h,f]=l.useState(!1),[y,b]=l.useState(null),[g,k]=l.useState(null),S=(o??c).trim(),C=m.trim(),w=!C&&r&&o===null,P=o!==null&&S!==c,v=A=>a({type:"configStatus",config:A}),B=async()=>{if(!(x||!C&&!r&&!P)){if(C&&!Su.test(S))return b(t("decider.workersAi.needsAccount"));p(!0),b(null),k(null);try{(P||C&&!c)&&v(await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiAccountId:S}})})),(C||w)&&v(window.ogb?.setCredential?await window.ogb.setCredential("workersAiToken",C):await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{workersAiToken:C}})})),u(""),d(null)}catch(A){b(A instanceof Error?A.message:String(A))}finally{p(!1)}}},j=async()=>{if(!(h||x||!C&&!r)){f(!0),k(null),b(null);try{const A=await M("/api/decider/test",{method:"POST",body:JSON.stringify({provider:"workersai",...C?{key:C,accountId:S}:{}})}),I=A.extraction?[t(A.extraction.ok?"decider.test.extractionOk":"decider.test.extractionFailed")]:[];k(A.ok?{ok:A.extraction?.ok!==!1,text:[t("decider.workersAi.test.ok",{ms:String(A.latencyMs)}),...I].join(" ")}:{ok:!1,text:s(A)})}catch(A){k({ok:!1,text:A instanceof Error?A.message:String(A)})}finally{f(!1)}}};return e.jsxs(Y,{title:t("decider.workersAi.title"),children:[e.jsx("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.workersAi.detail")}),r&&e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-success",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-success"}),e.jsx("span",{children:t("decider.status.connected")})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("input",{type:"text","data-testid":"workers-ai-account",value:o??c,onChange:A=>{k(null),b(null),d(A.target.value)},disabled:x,placeholder:t("decider.workersAi.accountIdPlaceholder"),"aria-label":t("decider.workersAi.accountId"),autoComplete:"off",spellCheck:!1,className:Tn}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password","data-testid":"workers-ai-token",value:m,onChange:A=>{k(null),b(null),u(A.target.value)},onKeyDown:A=>A.key==="Enter"&&void B(),disabled:x,placeholder:r?t("keys.replace"):t("decider.workersAi.tokenPlaceholder"),"aria-label":t("decider.workersAi.token"),autoComplete:"off",spellCheck:!1,className:Tn}),e.jsx("button",{type:"button","data-testid":"workers-ai-save",onClick:()=>{B()},disabled:x||!C&&!r&&!P,title:w?t("keys.removeKey"):t("common.save"),className:z("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",w?"text-danger":"text-ink"),children:x?e.jsx(X,{size:13,className:"animate-spin"}):w?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"workers-ai-test",onClick:()=>{j()},disabled:h||x||!C&&!r,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:h?t("keys.testing"):t("keys.test")})]})]}),y&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:y}),g&&e.jsx("p",{role:"status",className:z("mt-1 text-[12px]",g.ok?"text-success":"text-danger"),children:g.text}),e.jsxs("a",{href:wu,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t("decider.workersAi.getKey"),e.jsx(pt,{size:11,"aria-hidden":"true"})]})]})}const Eu={jev:"https://typesafe.ai",openrouter:"https://openrouter.ai/keys"},Au=1500,Ms={rejected:"decider.error.rejected",unreachable:"decider.error.unreachable",timeout:"decider.error.timeout",rate_limited:"decider.error.rateLimited",overloaded:"decider.error.overloaded",malformed:"decider.error.malformed",no_key:"decider.error.noKey",misconfigured:"decider.error.misconfigured"},Rn={rejected:"decider.included.error.rejected",rate_limited:"decider.included.error.limited"},Iu={...Ms,rejected:"decider.openrouter.error.rejected",unreachable:"decider.openrouter.error.unreachable",timeout:"decider.openrouter.error.timeout",rate_limited:"decider.openrouter.error.rateLimited",overloaded:"decider.openrouter.error.overloaded",malformed:"decider.openrouter.error.malformed"},Pu={...Ms,rejected:"decider.workersAi.error.rejected",unreachable:"decider.workersAi.error.unreachable",timeout:"decider.workersAi.error.timeout",rate_limited:"decider.workersAi.error.rateLimited",overloaded:"decider.workersAi.error.overloaded",malformed:"decider.workersAi.error.malformed"},Qt={jev:"decider.status.byJev",workersai:"decider.status.byWorkersAi",openrouter:"decider.status.byOpenRouter"};function Tu(s){const n=s?.decider,a=s?.helpers?.extraction,i=n?.configured?n.included?t("decider.status.byCloud"):t(Qt[n.provider]??Qt.jev):t("decider.status.notSetUp"),r=a?.provider?a.included?t("decider.status.byCloud"):t(Qt[a.provider]):t("decider.status.notSetUp");return t("decider.status.line",{decisions:i,extraction:r})}function Ln(s,n=!1,a="jev"){if(a==="workersai"){if(s.reason==="http_error")return t("decider.workersAi.error.http",{status:String(s.status??"?")});const r=Pu[s.reason];return r?t(r):t("decider.error.other")}if(a==="openrouter"){if(s.reason==="http_error"&&s.status===402)return t("decider.openrouter.error.credits");if(s.reason==="http_error")return t("decider.openrouter.error.http",{status:String(s.status??"?")});const r=Iu[s.reason];return r?t(r):t("decider.error.other")}if(n&&s.reason==="http_error"&&s.status===402)return t("decider.included.error.subscription");if(n&&Rn[s.reason])return t(Rn[s.reason]);if(s.reason==="http_error")return t("decider.error.http",{status:String(s.status??"?")});const i=Ms[s.reason];return i?t(i):t("decider.error.other")}const Ru=["decider.jobs.browserClicks","decider.jobs.toolSelection","decider.jobs.placement"];function Lu(){const{state:s,dispatch:n}=W(),a=s.config?.decider,i=a?.selectedProvider??(a?.provider==="openrouter"?"openrouter":"jev"),r=i==="workersai",c=i==="openrouter",o=a?.configured??!1,d=o&&a?.included===!0,m=c&&o&&a?.keySource==="shared",u=c&&a?.sharedKey===!0,x=o&&!d&&!m,p=a?.enabled??!1,h=a?.jobs.roomRouting??!0,[f,y]=l.useState(""),[b,g]=l.useState(!1),[k,S]=l.useState(!1),[C,w]=l.useState(!1),[P,v]=l.useState(null),[B,j]=l.useState(null),[A,I]=l.useState(null),_=f.trim(),U=!_&&x,J=!c||d?null:m?"decider.openrouter.status.sharedHint":o?u?"decider.openrouter.status.ownFallbackHint":null:"decider.openrouter.status.notConnectedHint",K=T=>n({type:"configStatus",config:T}),te=async T=>{if(!k){S(!0),v(null);try{K(await M("/api/config",{method:"PUT",body:JSON.stringify({decider:T})}))}catch(Z){v(Z instanceof Error?Z.message:String(Z))}finally{S(!1)}}};l.useEffect(()=>{if(!c||A)return;let T=!1;return M("/api/decider/models").then(Z=>{T||I(Z)},()=>{}),()=>{T=!0}},[c,A]);const ae=T=>{y(""),j(null),te(T)},de=async()=>{if(!(b||!_&&!x)){g(!0),v(null),j(null);try{const T=window.ogb?.setCredential?await window.ogb.setCredential(c?"openrouterDeciderKey":"jevApiKey",_):await M("/api/config",{method:"PUT",body:JSON.stringify({decider:{[c?"openrouterKey":"key"]:_}})});K(T),y("")}catch(T){v(T instanceof Error?T.message:String(T))}finally{g(!1)}}},D=async()=>{if(C||b||!_&&!o)return;w(!0),j(null),v(null);const T=!_&&d,Z=!_&&m;try{const ee=await M("/api/decider/test",{method:"POST",body:JSON.stringify(_?{key:_}:{})});j(ee.ok?{ok:!0,text:c?[t(Z?"decider.openrouter.test.okShared":"decider.openrouter.test.ok",{ms:String(ee.latencyMs)}),...ee.latencyMs>Au?[t("decider.test.slow")]:[]].join(" "):t("decider.test.ok",{ms:String(ee.latencyMs)})}:{ok:!1,text:Ln(ee,T,i)})}catch(ee){j({ok:!1,text:ee instanceof Error?ee.message:String(ee)})}finally{w(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2 px-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("decider.intro")}),e.jsx("p",{role:"status","data-testid":"helpers-status",className:"text-[13px] font-medium text-ink",children:Tu(s.config)})]}),e.jsx(Cu,{failureText:T=>Ln(T,!1,"workersai")}),e.jsx(ue,{title:t("decider.provider.label"),children:e.jsxs(xe,{className:"w-48","data-testid":"decider-provider",value:i,onChange:T=>ae({provider:T.target.value}),disabled:k||!s.config,"aria-label":t("decider.provider.label"),children:[e.jsx("option",{value:"jev",children:t("decider.provider.jev")}),e.jsx("option",{value:"workersai",children:"Cloudflare Workers AI"}),e.jsx("option",{value:"openrouter",children:t("decider.provider.openrouter")})]})}),c&&e.jsx(ue,{title:t("decider.model.label"),subtitle:A?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs(xe,{className:"w-64 max-w-full","data-testid":"decider-model",value:a?.model??"",onChange:T=>ae({openrouterModel:T.target.value,openrouterApi:A?.models.find(Z=>Z.id===T.target.value)?.api??"chat"}),disabled:k,"aria-label":t("decider.model.label"),children:[a?.model&&!A?.models.some(T=>T.id===a.model)&&e.jsx("option",{value:a.model,children:a.model}),["recommended","more"].map(T=>{const Z=A?.models.filter(ee=>ee.group===T)??[];return Z.length>0&&e.jsx("optgroup",{label:t(T==="recommended"?"decider.model.recommended":"decider.model.more"),children:Z.map(ee=>e.jsx("option",{value:ee.id,children:ee.name},ee.id))},T)})]})}),e.jsx(ue,{title:t(c?"decider.openrouter.master":"decider.master"),subtitle:o?void 0:t(r?"decider.workersAi.needsAccount":c?"decider.masterNeedsKey.openrouter":"decider.masterNeedsKey"),children:e.jsx(me,{"data-testid":"decider-master","aria-label":t(c?"decider.openrouter.master":"decider.master"),checked:p,disabled:!o||k||!s.config,onClick:()=>{te({enabled:!p})},className:"cursor-pointer"})}),!r&&e.jsxs(Y,{title:t(c?"decider.openrouter.key.label":"decider.key.label"),children:[e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:z("size-1.5 rounded-full",o?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:o?"text-success":void 0,children:d?t("keys.includedWithCloudPro"):m?t("decider.openrouter.status.shared"):o?t(u?"decider.openrouter.status.own":"decider.status.connected"):t("decider.status.notConnected")})]}),J&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(J),!x&&e.jsxs(e.Fragment,{children:[" ",e.jsx("button",{type:"button","data-testid":"decider-manage-keys",onClick:()=>n(ds("openrouter")),className:"cursor-pointer text-accent hover:underline",children:t("decider.openrouter.key.manageLink")})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:f,onChange:T=>{j(null),v(null),y(T.target.value)},onKeyDown:T=>T.key==="Enter"&&void de(),disabled:b,placeholder:x?t("keys.replace"):t(m?"decider.openrouter.key.overridePlaceholder":c?"decider.openrouter.key.placeholder":"decider.key.placeholder"),"aria-label":t(c?"decider.openrouter.key.label":"decider.key.label"),autoComplete:"off",spellCheck:!1,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsx("button",{type:"button","data-testid":"decider-save",onClick:()=>{de()},disabled:b||!_&&!x,title:U?t("keys.removeKey"):t("common.save"),className:z("flex w-[72px] shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control py-2 text-[13px] hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",U?"text-danger":"text-ink"),children:b?e.jsx(X,{size:13,className:"animate-spin"}):U?t("keys.clear"):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})}),e.jsx("button",{type:"button","data-testid":"decider-test",onClick:()=>{D()},disabled:C||b||!_&&!o,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:C?t("keys.testing"):t("keys.test")})]}),P&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:P}),B&&e.jsx("p",{role:"status",className:z("mt-1 text-[12px]",B.ok?"text-success":"text-danger"),children:B.text}),!m&&e.jsxs("a",{href:Eu[i],target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex cursor-pointer items-center gap-1 text-[12px] text-accent hover:underline",children:[t(c?"decider.openrouter.key.getKey":"decider.key.getKey"),e.jsx(pt,{size:11,"aria-hidden":"true"})]})]}),r&&P&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] text-danger",children:P}),e.jsx(Y,{title:t("decider.jobs.title"),children:e.jsxs("ul",{className:"flex flex-col",children:[e.jsxs("li",{className:"flex items-start justify-between gap-4 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("decider.jobs.roomRouting")}),e.jsx("div",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:t("decider.jobs.roomRoutingDetail")})]}),e.jsx(me,{"data-testid":"decider-job-roomRouting","aria-label":t("decider.jobs.roomRouting"),checked:p&&h,disabled:!p||k,onClick:()=>{te({jobs:{roomRouting:!h}})},className:"cursor-pointer"})]}),Ru.map(T=>e.jsxs("li",{"data-testid":"decider-coming-soon","aria-disabled":"true",className:"flex items-center justify-between gap-4 border-t border-hairline/40 py-2 opacity-50",children:[e.jsx("span",{className:"text-[13px] text-ink-secondary",children:t(T)}),e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-ink-secondary",children:t("decider.jobs.comingSoon")})]},T))]})})]})}const Bu=["openai","xai","gemini","openrouter","custom"],Ou=4,Ai={openai:"gpt-image-2",xai:"grok-imagine-image-2.0",gemini:"gemini-2.5-flash-image",openrouter:"google/gemini-2.5-flash-image",custom:""},Mu={openai:[{id:"gpt-image-2",name:"GPT Image 2"},{id:"gpt-image-1",name:"GPT Image 1"},{id:"gpt-image-1-mini",name:"GPT Image 1 Mini"}],xai:[{id:"grok-imagine-image-2.0",name:"Grok Imagine Image 2.0"}],gemini:[{id:"gemini-2.5-flash-image",name:"Nano Banana (Gemini 2.5 Flash Image)"}],openrouter:[{id:"google/gemini-2.5-flash-image",name:"Google: Nano Banana (Gemini 2.5 Flash Image)"},{id:"google/gemini-3.1-flash-image",name:"Google: Nano Banana 2 (Gemini 3.1 Flash Image)"},{id:"google/gemini-3-pro-image",name:"Google: Nano Banana Pro (Gemini 3 Pro Image)"},{id:"openai/gpt-image-2",name:"OpenAI: GPT Image 2"},{id:"black-forest-labs/flux-3-image",name:"Black Forest Labs: FLUX 3 Image"},{id:"bytedance-seed/seedream-5-0-pro",name:"ByteDance Seed: Seedream 5.0 Pro"},{id:"x-ai/grok-imagine-image-2.0",name:"xAI: Grok Imagine Image 2.0"},{id:"qwen/qwen-image-3",name:"Qwen: Qwen Image 3"}],custom:[]};function zu(s){const n="Use an HTTPS API base URL, or HTTP for a local router, without passwords, query parameters or fragments";let a;try{a=new URL(s.trim())}catch{throw new Error(n)}if(s.length>2048||a.username||a.password||a.search||a.hash)throw new Error(n);const i=a.hostname.toLowerCase(),r=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(i),c=i==="localhost"||i.endsWith(".localhost")||i.endsWith(".local")||i==="host.docker.internal"||i==="host.containers.internal"||i==="[::1]"||/^\[f[cd][0-9a-f]{2}:/.test(i)||r&&(Number(r[1])===127||Number(r[1])===10||Number(r[1])===192&&Number(r[2])===168||Number(r[1])===172&&Number(r[2])>=16&&Number(r[2])<=31);if(a.protocol!=="https:"&&!(a.protocol==="http:"&&c))throw new Error(n);if(r&&(Number(r[1])===0||Number(r[1])===169&&Number(r[2])===254))throw new Error(n);return a.pathname=a.pathname.replace(/\/+$/,"").replace(/\/(images\/generations|responses)$/,""),a.toString().replace(/\/+$/,"")}const Et={openai:"OpenAI",xai:"Grok (xAI)",gemini:"Gemini",openrouter:"OpenRouter",custom:"Custom"},Uu={openai:{credential:"openaiImageApiKey",patch:s=>({imageGen:{key:s}}),label:"imageGen.key.openai"},gemini:{credential:"geminiImageApiKey",patch:s=>({imageGen:{geminiKey:s}}),label:"imageGen.key.gemini"},custom:{credential:"customImageApiKey",patch:s=>({imageGen:{customApiKey:s}}),label:"imageGen.key.custom"}},Fu={xai:{label:"imageGen.key.xai",note:"imageGen.key.sharedXai"},openrouter:{label:"imageGen.key.openrouter",note:"imageGen.key.sharedOpenrouter"}},Bn={openai:"https://platform.openai.com/api-keys",gemini:"https://aistudio.google.com/apikey",xai:"https://console.x.ai",openrouter:"https://openrouter.ai/keys"},gs="w-full min-w-0 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50",At="flex shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:cursor-not-allowed disabled:opacity-50",Zt="\0other";function Du(s,n){return n.ok?n.freeTier?{ok:!1,text:t("imageGen.test.noCredit")}:{ok:!0,text:t(s==="openrouter"?"imageGen.test.okOpenrouter":"imageGen.test.ok")}:n.reason==="model_missing"?{ok:!1,text:t("imageGen.test.modelMissing",{model:n.model})}:n.reason==="rejected"?{ok:!1,text:t("imageGen.test.rejected")}:n.reason==="unreachable"?{ok:!1,text:t("imageGen.test.unreachable")}:n.reason==="no_key"?{ok:!1,text:t("imageGen.key.missing")}:n.reason==="no_url"?{ok:!1,text:t("imageGen.test.noUrl")}:{ok:!1,text:t("imageGen.test.unexpected")}}function _u(s,n){return n==="openai"?s?.openaiConfigured===!0:n==="xai"?s?.xaiConfigured===!0:n==="gemini"?s?.geminiConfigured===!0:n==="openrouter"?s?.openrouterConfigured===!0:s?.customKeyConfigured===!0}function $u(){const{state:s,dispatch:n}=W(),a=s.config?.imageGen,i=a?.primary??{provider:a?.provider??"openai",model:a?.model??Ai.openai,configured:a?.configured===!0},r=a?.fallback??null,[c,o]=l.useState(!1),[d,m]=l.useState(null),[u,x]=l.useState(null),p=i.provider==="openrouter"||r?.provider==="openrouter";l.useEffect(()=>{if(!p||u)return;let b=!1;return M("/api/images/openrouter-models").then(g=>{b||x(Array.isArray(g?.models)?g:{source:"builtin",models:[]})},()=>{b||x({source:"builtin",models:[]})}),()=>{b=!0}},[p,u]);const h=async b=>{o(!0),m(null);try{const g=await M("/api/config",{method:"PUT",body:JSON.stringify(b)});n({type:"configStatus",config:g})}catch(g){m(g instanceof Error?g.message:String(g))}finally{o(!1)}},f=(b,g)=>{if(b==="fallback"&&g==="")return void h({imageGen:{fallback:null}});const k=g,S=b==="primary"&&r?.provider===k;h({imageGen:{[b]:{provider:k},...S?{fallback:null}:{}}})},y=[i.provider,...r?[r.provider]:[]].filter((b,g,k)=>k.indexOf(b)===g);return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2 px-4",children:[e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("imageGen.intro")}),e.jsxs("p",{role:"status","data-testid":"image-gen-status",className:"flex items-center gap-2 text-[13px] font-medium text-ink",children:[e.jsx("span",{className:z("size-1.5 shrink-0 rounded-full",a?.ready?i.configured?"bg-success":"bg-warning":"bg-raised-hover")}),a?.ready?i.configured?t("imageGen.status.ready",{provider:Et[i.provider]}):t("imageGen.status.backupOnly",{provider:Et[r.provider]}):t("imageGen.status.notReady")]})]}),e.jsx(Ku,{disabled:c}),e.jsx(On,{slot:"primary",provider:i.provider,model:i.model,configured:i.configured,openrouterModels:u,disabled:c||!s.config,onProvider:f,onModel:b=>{h({imageGen:{primary:{provider:i.provider,model:b}}})}}),e.jsx(On,{slot:"fallback",provider:r?.provider??null,model:r?.model??"",configured:r?.configured===!0,exclude:i.provider,openrouterModels:u,disabled:c||!s.config,onProvider:f,onModel:b=>r&&void h({imageGen:{fallback:{provider:r.provider,model:b}}})}),e.jsx(ue,{title:t("imageGen.maxPerTurn.label"),subtitle:t("imageGen.maxPerTurn.help"),children:e.jsx(xe,{className:"w-20","data-testid":"image-gen-max",value:String(a?.maxPerTurn??Ou),onChange:b=>{h({imageGen:{maxPerTurn:Number(b.target.value)}})},disabled:c||!s.config,"aria-label":t("imageGen.maxPerTurn.label"),children:Array.from({length:10},(b,g)=>g+1).map(b=>e.jsx("option",{value:b,children:b},b))})}),d&&e.jsx("p",{role:"alert",className:"px-4 text-[12px] text-danger",children:d}),y.map(b=>e.jsx(Wu,{provider:b,status:a},b))]})}function Ku({disabled:s}){const{dispatch:n}=W(),[a,i]=l.useState(null),[r,c]=l.useState(""),[o,d]=l.useState(!1),[m,u]=l.useState(""),x=async p=>{d(!0),u("");try{if(p){const h=await M("/api/images/connections",{method:"POST",body:JSON.stringify({id:r})});n({type:"configStatus",config:h}),i(null),c("")}else{const h=await M("/api/images/connections");i(h.connections),c(h.connections[0]?.id??"")}}catch(h){u(h instanceof Error?h.message:String(h))}finally{d(!1)}};return e.jsxs(Y,{title:t("imageGen.saved.title"),children:[e.jsx("p",{className:"mb-2 text-[12px] text-ink-secondary",children:t("imageGen.saved.help")}),a===null?e.jsx("button",{type:"button",className:At,disabled:o||s,onClick:()=>{x(!1)},children:t("imageGen.saved.title")}):a.length?e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(xe,{"aria-label":t("imageGen.saved.title"),value:r,disabled:o,onChange:p=>c(p.target.value),children:a.map(p=>e.jsxs("option",{value:p.id,children:[p.name," · ",p.url]},p.id))}),e.jsx("button",{type:"button",className:At,disabled:o||s||!r,onClick:()=>{x(!0)},children:t("imageGen.saved.apply")})]}):e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("imageGen.saved.empty")}),m&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:m})]})}function On({slot:s,provider:n,model:a,configured:i,exclude:r,openrouterModels:c,disabled:o,onProvider:d,onModel:m}){const u=t(s==="primary"?"imageGen.primary.label":"imageGen.fallback.label");return e.jsxs(e.Fragment,{children:[e.jsx(ue,{title:u,subtitle:n&&!i?t(n==="custom"?"imageGen.slot.needsConnection":"imageGen.slot.needsKey"):t(s==="primary"?"imageGen.primary.help":"imageGen.fallback.help"),children:e.jsxs(xe,{className:"w-48","data-testid":`image-gen-${s}`,value:n??"",onChange:x=>d(s,x.target.value),disabled:o,"aria-label":u,children:[s==="fallback"&&e.jsx("option",{value:"",children:t("imageGen.fallback.none")}),Bu.filter(x=>x!==r).map(x=>e.jsx("option",{value:x,children:Et[x]},x))]})}),n&&e.jsx(Hu,{slot:s,slotLabel:u,provider:n,model:a,openrouterModels:c,disabled:o,onModel:m})]})}function Hu({slot:s,slotLabel:n,provider:a,model:i,openrouterModels:r,disabled:c,onModel:o}){const[d,m]=l.useState(null),{state:u}=W(),x=a==="custom"&&u.config?.imageGen?.customApi==="responses",h=(a==="openrouter"&&r?.source==="openrouter"?r.models:null)??(x?[{id:"gpt-6.1-sol",name:"GPT-6.1 Sol"},{id:"gpt-6-astra",name:"GPT-6 Astra"}]:Mu[a]).map(g=>({...g,group:"recommended"})),f=d!==null||h.length===0,y=()=>{d!==null&&(m(null),d.trim()&&d.trim()!==i&&o(d.trim()))},b=g=>{if(g===Zt)return m(i);m(null),o(g)};return e.jsx(ue,{title:t("decider.model.label"),subtitle:a==="openrouter"&&r?.source==="builtin"?t("decider.model.builtinNote"):void 0,children:e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[h.length>0&&e.jsxs(xe,{className:"w-64 max-w-full","data-testid":`image-gen-${s}-model`,value:f?Zt:i,onChange:g=>b(g.target.value),disabled:c,"aria-label":t("imageGen.model.label",{slot:n}),children:[!i&&e.jsx("option",{value:"",disabled:!0,children:t("imageGen.model.placeholder")}),i&&!h.some(g=>g.id===i)&&e.jsx("option",{value:i,children:i}),["recommended","more"].map(g=>{const k=h.filter(S=>S.group===g);return k.length>0&&e.jsx("optgroup",{label:t(g==="recommended"?"decider.model.recommended":"decider.model.more"),children:k.map(S=>e.jsx("option",{value:S.id,children:S.name},S.id))},g)}),e.jsx("option",{value:Zt,children:t("imageGen.model.other")})]}),f&&e.jsx("input",{value:d??i,onChange:g=>m(g.target.value),onBlur:y,onKeyDown:g=>g.key==="Enter"&&y(),disabled:c,placeholder:Ai[a]||t("imageGen.model.placeholder"),"aria-label":t("imageGen.model.idLabel",{slot:n}),autoComplete:"off",spellCheck:!1,className:z(gs,"w-64 max-w-full")})]})})}function Wu({provider:s,status:n}){const{dispatch:a}=W(),[i,r]=l.useState(""),[c,o]=l.useState(null),[d,m]=l.useState(!1),[u,x]=l.useState(null),[p,h]=l.useState(!1),[f,y]=l.useState(null),b=s==="openrouter"?[n?.primary,n?.fallback].filter(I=>I?.provider===s).map(I=>I?.model).join(" "):"",g=f?.models===b?f:null,k=I=>y(I&&{...I,models:b}),S=_u(n,s),C=s==="openai"||s==="gemini"||s==="custom"?Uu[s]:null,w=s==="xai"||s==="openrouter"?Fu[s]:null,P=c??n?.customUrl??"",v=async I=>{m(!0),x(null),k(null);try{a({type:"configStatus",config:await I()}),r(""),o(null)}catch(_){x(_ instanceof Error?_.message:String(_))}finally{m(!1)}},B=I=>v(async()=>s==="xai"||s==="openrouter"?$l(s,I,!1):window.ogb?.setCredential&&C?window.ogb.setCredential(C.credential,I):M("/api/config",{method:"PUT",body:JSON.stringify(C.patch(I))})),j=()=>v(async()=>{const I=P.trim()?zu(P.trim()):"";return M("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customUrl:I}})})}),A=async()=>{h(!0),k(null);try{k(Du(s,await M("/api/images/test",{method:"POST",body:JSON.stringify({provider:s})})))}catch(I){k({ok:!1,text:I instanceof Error?I.message:String(I)})}finally{h(!1)}};return e.jsxs(Y,{title:Et[s],children:[e.jsx(Gu,{configured:S,optional:s==="custom"}),w&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[t(w.note)," ",e.jsx("button",{type:"button",onClick:()=>a({type:"toggleAppSettings",open:!0,section:"connections"}),className:"cursor-pointer text-accent hover:underline",children:t("imageGen.key.manage")})]}),s==="custom"&&e.jsxs("div",{className:"mb-3 space-y-2",children:[e.jsx("label",{className:"block text-[13px] text-ink-secondary",children:t("imageGen.custom.api")}),e.jsxs(xe,{"aria-label":t("imageGen.custom.api"),value:n?.customApi??"images",disabled:d,onChange:I=>{v(()=>M("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customApi:I.target.value}})}))},children:[e.jsx("option",{value:"images",children:"Images API"}),e.jsx("option",{value:"responses",children:"Responses API · image_generation"})]}),e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("imageGen.custom.apiHelp")}),n?.customApi==="responses"&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:n.customLocalImageExtension===!0,disabled:d,onChange:I=>{v(()=>M("/api/config",{method:"PUT",body:JSON.stringify({imageGen:{customLocalImageExtension:I.target.checked}})}))}}),t("imageGen.custom.extension")]})]}),s==="custom"&&e.jsxs("div",{className:"mb-2 flex gap-2",children:[e.jsx("input",{type:"url",value:P,onChange:I=>o(I.target.value),onKeyDown:I=>I.key==="Enter"&&void j(),disabled:d,placeholder:"http://127.0.0.1:4000/v1","aria-label":t("imageGen.custom.url"),autoComplete:"off",className:gs}),e.jsxs("button",{type:"button",onClick:()=>{j()},disabled:d||c===null,className:At,children:[d?e.jsx(X,{size:13,className:"animate-spin"}):e.jsx(ge,{size:13}),t("common.save")]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"password",value:i,onChange:I=>r(I.target.value),onKeyDown:I=>I.key==="Enter"&&i.trim()&&void B(i.trim()),disabled:d,placeholder:S?t("keys.replace"):t("imageGen.key.paste"),"aria-label":t((C??w).label),autoComplete:"off",spellCheck:!1,className:gs}),e.jsxs("button",{type:"button",onClick:()=>{B(i.trim())},disabled:d||!i.trim(),className:At,children:[d?e.jsx(X,{size:13,className:"animate-spin"}):e.jsx(ge,{size:13}),t("common.save")]}),S&&e.jsx("button",{type:"button",onClick:()=>{A()},disabled:p||d,className:"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border border-hairline/40 px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:p?t("keys.testing"):t("keys.test")})]}),g&&e.jsx("p",{role:"status",className:z("mt-1 text-[12px]",g.ok?"text-success":"text-danger"),children:g.text}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2 text-[12px] text-ink-secondary",children:[Bn[s]?e.jsx("a",{href:Bn[s],target:"_blank",rel:"noreferrer",className:"text-accent hover:underline",children:t("imageGen.key.get")}):e.jsx("span",{children:t("imageGen.custom.help",{app:ws()})}),S&&e.jsx("button",{type:"button",onClick:()=>{B("")},disabled:d,className:"cursor-pointer hover:text-danger disabled:opacity-50",children:t("keys.removeKey")})]}),u&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:u})]})}function Gu({configured:s,optional:n=!1}){return e.jsxs("div",{role:"status",className:"mb-2 flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{className:z("size-1.5 rounded-full",s?"bg-success":"bg-raised-hover")}),e.jsx("span",{className:s?"text-success":void 0,children:t(s?"imageGen.key.saved":n?"imageGen.key.optional":"imageGen.key.missing")})]})}function es(s){if(s.readOnly||s.trialCredit||s.access==="custom"||s.access==="api")return null;if(s.driverKind==="claudeAgent")return"claude";const n=s.authentication?.method;return s.snapshot.chatgptPlan===!0||(n==="device-code"||n==="browser-pkce")&&Ma(s.driverKind)==="codex"?"chatgpt":null}function zs(s){return s.snapshot.state!=="available"?"unavailable":s.snapshot.authenticated===!0?"signedIn":s.snapshot.authenticated===!1?"signedOut":"unknown"}const Us={claude:{title:"accounts.claude",add:"accounts.addClaude",removeBody:"accounts.removeBodyClaude"},chatgpt:{title:"accounts.chatgpt",add:"accounts.addChatgpt",removeBody:"accounts.removeBodyChatgpt"}};function Vu(s,n){return{signOut:zs(n)==="signedIn"&&n.authentication?.signOut===!0&&n.snapshot.account?.method!=="api-key",remove:s==="claude"?n.instanceId!=="claude"&&n.claudeAccount?.isDefault!==!0:n.instanceId.startsWith("chatgpt-")}}function Ii(s){return s.some(Le)}function qu(s,n){const a=n.filter(o=>zs(o)==="signedIn"),i=Ii(n),r=n.some(o=>o.snapshot.state==="available"),c=n.length>1?t("accounts.count",{count:String(n.length),signedIn:String(a.length)}):a[0]?.snapshot.account?.email??Vl(n[0]);return{title:t(Us[s].title),subtitle:c,ready:i,status:i?t("onboarding.engines.ready"):r?t("model.signInRequired"):t("onboarding.engines.needsSetup"),action:i?t("engines.library.manage"):r?t("accounts.signIn"):t("engines.library.setup")}}function Ju({group:s,instance:n,onRename:a}){const{state:i,dispatch:r,refreshInstances:c}=W(),[o,d]=l.useState(!1),[m,u]=l.useState(null),[x,p]=l.useState(!1),[h,f]=l.useState(null),y=l.useRef(null),{signOut:b,remove:g}=Vu(s,n),k=i.bots.filter(w=>w.modelSelection.instanceId===n.instanceId).length;l.useEffect(()=>{if(!o)return;const w=v=>{v.key==="Escape"&&(v.stopPropagation(),d(!1))},P=v=>{v.target instanceof Node&&!y.current?.contains(v.target)&&d(!1)};return window.addEventListener("keydown",w,!0),window.addEventListener("pointerdown",P),()=>{window.removeEventListener("keydown",w,!0),window.removeEventListener("pointerdown",P)}},[o]);const S=async w=>{u(null),p(!0),f(null);try{const P=`/api/instances/${encodeURIComponent(n.instanceId)}${w==="signOut"?"/auth/sign-out":""}`,{instances:v}=await M(P,w==="signOut"?{method:"POST"}:{method:"DELETE"});Array.isArray(v)?r({type:"instances",instances:v}):await c().catch(()=>{})}catch(P){f(P instanceof Error?P.message:String(P))}finally{p(!1)}},C="ui-menu-row w-full text-left disabled:cursor-not-allowed disabled:opacity-50";return e.jsxs("div",{ref:y,className:"relative flex items-center gap-1",children:[g&&e.jsx("button",{type:"button",disabled:x||k>0,onClick:()=>u("remove"),title:k>0?t("accounts.inUse",{count:String(k)}):void 0,className:"rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:t("accounts.remove")}),e.jsx("button",{type:"button",onClick:()=>d(w=>!w),disabled:x,"aria-haspopup":"menu","aria-expanded":o,"aria-label":t("accounts.menu",{name:_e(n)}),className:"flex size-8 items-center justify-center rounded-lg text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50",children:x?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(ll,{size:16})}),o&&e.jsxs("div",{role:"menu",className:z("absolute right-0 top-full z-40 mt-1 w-[220px] overflow-hidden text-[13px]",ol),children:[e.jsx("button",{type:"button",role:"menuitem",className:z(C,"text-ink"),onClick:()=>{d(!1),a()},children:t("accounts.rename")}),b&&e.jsx("button",{type:"button",role:"menuitem",className:z(C,"text-ink"),onClick:()=>{d(!1),u("signOut")},children:t("accounts.signOut")}),g&&k>0&&e.jsx("p",{className:"px-3 pb-1 pt-0.5 text-[11px] leading-snug text-ink-secondary",children:t("accounts.inUse",{count:String(k)})})]}),h&&e.jsx("p",{role:"alert",className:"absolute right-0 top-full z-30 mt-1 w-[260px] rounded-lg bg-card p-2 text-[12px] text-danger shadow-lg",children:h}),e.jsx(Qe,{open:m==="signOut",title:t("accounts.signOutTitle",{name:_e(n)}),body:t("accounts.signOutBody"),confirmLabel:t("accounts.signOut"),onCancel:()=>u(null),onConfirm:()=>{S("signOut")}}),e.jsx(Qe,{open:m==="remove",title:t("accounts.removeTitle",{name:_e(n)}),body:t(Us[s].removeBody),confirmLabel:t("accounts.remove"),tone:"neutral",onCancel:()=>u(null),onConfirm:()=>{S("remove")}})]})}function Xu({instance:s,onDone:n}){const{dispatch:a}=W(),[i,r]=l.useState(_e(s)),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=async()=>{const x=i.trim();if(!x||x===_e(s))return n();o(!0),m(null);try{const{instances:p}=await M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({displayName:x})});Array.isArray(p)&&a({type:"instances",instances:p}),n()}catch(p){m(p instanceof Error?p.message:String(p))}finally{o(!1)}};return e.jsxs("form",{className:"flex min-w-0 flex-1 flex-col gap-1",onSubmit:x=>{x.preventDefault(),u()},children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i,onChange:x=>r(x.target.value),maxLength:80,autoFocus:!0,disabled:c,"aria-label":t("accounts.nameLabel"),onKeyDown:x=>{x.key==="Escape"&&(x.stopPropagation(),n())},className:"min-w-0 flex-1 rounded-lg border border-hairline/40 bg-inset px-2.5 py-1.5 text-[13px] text-ink outline-none focus:border-accent-border disabled:opacity-50"}),e.jsx("button",{type:"submit",disabled:c||!i.trim(),className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] font-medium text-ink hover:bg-raised-hover disabled:opacity-50",children:c?e.jsx(X,{size:13,className:"animate-spin"}):t("common.save")}),e.jsx("button",{type:"button",onClick:n,disabled:c,className:"rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control",children:t("common.cancel")})]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:d})]})}function Yu({group:s,instance:n,signingIn:a,onSignIn:i,onSignInDone:r}){const[c,o]=l.useState(!1),d=zs(n),m=n.snapshot.account,u=n.snapshot.authenticationUnavailableReason,x=u&&d!=="signedIn"?u:d==="signedIn"?m?.method==="api-key"?t("accounts.apiKey"):[m?.email,m?.organization].filter(Boolean).join(" · ")||t("accounts.signedIn"):d==="signedOut"?t("accounts.notSignedIn"):d==="unknown"?t("accounts.unknown"):n.snapshot.reason??t("onboarding.engines.needsSetup");return e.jsxs("li",{"data-account":n.instanceId,"data-account-state":d,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsx("span",{"aria-hidden":"true",className:z("flex size-6 shrink-0 items-center justify-center rounded-full",d==="signedIn"?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:d==="signedIn"?e.jsx(ge,{size:13}):e.jsx("span",{className:z("size-1.5 rounded-full",d==="signedOut"?"bg-warning":"bg-ink-tertiary")})}),c?e.jsx(Xu,{instance:n,onDone:()=>o(!1)}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:_e(n),children:_e(n)}),e.jsx("div",{className:"truncate text-[12px] text-ink-secondary",title:x,children:x})]}),d!=="signedIn"&&d!=="unavailable"&&!u&&!a&&e.jsx("button",{type:"button",onClick:i,className:z("shrink-0 rounded-lg px-3 py-1.5 text-[12px] font-semibold",d==="signedOut"?"bg-accent text-white hover:brightness-110":"bg-control text-ink hover:bg-raised-hover"),children:t("accounts.signIn")}),e.jsx(Ju,{group:s,instance:n,onRename:()=>o(!0)})]})]}),a&&e.jsx("div",{className:"pl-9",children:s==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(Kl,{instanceId:n.instanceId,autoStart:!0,onDone:r}),n.claudeAccount?.signInCommand&&e.jsxs("details",{className:"mt-2 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer select-none hover:text-ink",children:t("engineSetup.preferTerminal")}),e.jsx(Hl,{command:n.claudeAccount.signInCommand,actionLabel:t("engineSetup.openSignIn"),compact:!0})]})]}):e.jsx(Wl,{instanceId:n.instanceId,provider:"codex",browserPkce:n.authentication?.method==="browser-pkce",autoStart:!0,onDone:r})}),s==="chatgpt"&&d==="signedIn"&&n.snapshot.chatgptPlan&&e.jsx("div",{className:"pl-9",children:e.jsx(Gl,{instanceId:n.instanceId,welcome:!1})})]})}function Pi({label:s,endpoint:n,extra:a,folder:i=!1,describedBy:r,onAdded:c}){const{dispatch:o}=W(),[d,m]=l.useState(!1),[u,x]=l.useState(""),[p,h]=l.useState(""),[f,y]=l.useState(!1),[b,g]=l.useState(null),k=async()=>{if(!(f||!u.trim())){y(!0),g(null);try{const S={displayName:u.trim(),...a,...i&&p.trim()?{configDir:p.trim()}:{}},C=await M(n,{method:"POST",body:JSON.stringify(S)});Array.isArray(C.instances)&&o({type:"instances",instances:C.instances}),m(!1),x(""),h(""),typeof C.instanceId=="string"&&c(C.instanceId)}catch(S){g(S instanceof Error?S.message:String(S))}finally{y(!1)}}};return d?e.jsxs("form",{"data-add-account":n,className:"space-y-2.5 rounded-xl border border-hairline/50 bg-app p-3",onSubmit:S=>{S.preventDefault(),k()},children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("accounts.nameLabel"),e.jsx("input",{value:u,onChange:S=>x(S.target.value),placeholder:t("accounts.namePlaceholder"),maxLength:80,autoFocus:!0,required:!0,disabled:f,"aria-describedby":r,className:"rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] font-normal text-ink outline-none focus:border-accent-border disabled:opacity-50"})]}),i&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer select-none hover:text-ink",children:t("accounts.folderToggle")}),e.jsx("input",{value:p,onChange:S=>h(S.target.value),placeholder:"~/.claude-work",maxLength:4096,spellCheck:!1,disabled:f,"aria-label":t("accounts.folderToggle"),className:"mt-2 w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink outline-none focus:border-accent-border disabled:opacity-50"}),e.jsx("p",{className:"mt-1 leading-relaxed",children:t("accounts.folderHint")})]}),b&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:b}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{m(!1),g(null)},disabled:f,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:f||!u.trim(),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[f&&e.jsx(X,{size:13,className:"animate-spin"}),t("accounts.addSubmit")]})]})]}):e.jsxs("button",{type:"button",onClick:()=>m(!0),"aria-describedby":r,className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),s]})}function Qu({group:s,accounts:n,advanced:a,bare:i=!1}){const[r,c]=l.useState(null),o=n[0],d=n.some(x=>x.snapshot.state==="available"),m=n.find(x=>x.policy)?.policy,u=l.useId();return e.jsxs(Nt,{instance:o,summary:qu(s,n),bare:i,children:[m&&e.jsxs("p",{className:"mb-3 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:m.organizationName})})," · ",m.reason]}),d?e.jsxs("div",{className:"space-y-2",children:[e.jsx("ul",{"data-accounts":s,className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:n.map(x=>e.jsx(Yu,{group:s,instance:x,signingIn:r===x.instanceId,onSignIn:()=>c(x.instanceId),onSignInDone:()=>c(p=>p===x.instanceId?null:p)},x.instanceId))}),!o.snapshot.authenticationUnavailableReason&&e.jsxs(e.Fragment,{children:[e.jsx(Pi,{label:t(Us[s].add),endpoint:`/api/instances/${s}-accounts`,folder:s==="claude",describedBy:s==="chatgpt"?u:void 0,onAdded:c}),s==="chatgpt"&&e.jsx("p",{id:u,className:"px-2 text-[12px] leading-relaxed text-ink-secondary",children:t("accounts.addChatgptWorkspaceNote")})]})]}):e.jsx(Mt,{instance:o,unframed:!0}),o.snapshot.update&&e.jsx(za,{update:o.snapshot.update,instance:o,className:"mt-3",quiet:!0}),o.snapshot.warning&&e.jsx(Ua,{warning:o.snapshot.warning,className:"mt-3"}),a]})}const at=z(Be,"font-sans"),Zu={opusModel:"global.anthropic.claude-opus-5-5",sonnetModel:"global.anthropic.claude-sonnet-5-5",haikuModel:"global.anthropic.claude-haiku-5-5",smallFastModel:"global.anthropic.claude-haiku-5-5"},Mn=["opusModel","sonnetModel","haikuModel","smallFastModel"],em={name:"Claude on Bedrock",awsProfile:"default",awsRegion:"",model:"",opusModel:"",sonnetModel:"",haikuModel:"",smallFastModel:""},tm=s=>{const n=s.claudeBedrock;return{name:s.displayName,awsProfile:n?.awsProfile||"default",awsRegion:n?.awsRegion??"",model:n?.model??"",opusModel:n?.opusModel??"",sonnetModel:n?.sonnetModel??"",haikuModel:n?.haikuModel??"",smallFastModel:n?.smallFastModel??""}},zn={opusModel:"claudeBedrock.opus",sonnetModel:"claudeBedrock.sonnet",haikuModel:"claudeBedrock.haiku",smallFastModel:"claudeBedrock.smallFast"};function Un({instance:s,onDone:n}){const{dispatch:a}=W(),[i,r]=l.useState(s?tm(s):em),[c,o]=l.useState(!1),[d,m]=l.useState(null),u=h=>({value:i[h],onChange:f=>r(y=>({...y,[h]:f.target.value})),spellCheck:!1,disabled:c}),x=!!(i.name.trim()&&i.awsProfile.trim()&&i.awsRegion.trim()&&i.model.trim()),p=async()=>{if(c||!x)return;o(!0),m(null);const h={displayName:i.name.trim(),awsProfile:i.awsProfile.trim(),awsRegion:i.awsRegion.trim(),model:i.model.trim(),...Object.fromEntries(Mn.map(f=>[f,i[f].trim()]))};try{const f=s?await M(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-bedrock`,{method:"PATCH",body:JSON.stringify(h)}):await M("/api/instances/claude-bedrock",{method:"POST",body:JSON.stringify(h)});Array.isArray(f.instances)&&a({type:"instances",instances:f.instances}),n()}catch(f){m(f instanceof Error&&f.message?f.message:t("claudeBedrock.failed"))}finally{o(!1)}};return e.jsxs("form",{"data-claude-bedrock-form":s?.instanceId??"new",className:"flex flex-col gap-2 rounded-xl border border-hairline/50 bg-inset p-3",onSubmit:h=>{h.preventDefault(),p()},children:[e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.awsHint")}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.name"),e.jsx("input",{...u("name"),maxLength:80,autoFocus:!0,"aria-label":t("claudeBedrock.name"),className:at})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.profile"),e.jsx("input",{...u("awsProfile"),maxLength:128,placeholder:"default","aria-label":t("claudeBedrock.profile"),className:z(at,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.region"),e.jsx("input",{...u("awsRegion"),maxLength:32,placeholder:"us-east-1","aria-label":t("claudeBedrock.region"),className:z(at,"font-mono")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t("claudeBedrock.model"),e.jsx("input",{...u("model"),maxLength:160,placeholder:"global.anthropic.claude-sonnet-5-5","aria-label":t("claudeBedrock.model"),className:z(at,"font-mono")})]}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.modelHint")}),e.jsxs("details",{className:"rounded-lg border border-hairline/40 px-2.5 py-2",children:[e.jsx("summary",{className:"cursor-pointer text-[12px] font-medium text-ink-secondary outline-none hover:text-ink",children:t("claudeBedrock.tiers")}),e.jsx("div",{className:"mt-2 flex flex-col gap-2",children:Mn.map(h=>e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] font-medium text-ink",children:[t(zn[h]),e.jsx("input",{...u(h),maxLength:160,placeholder:Zu[h],"aria-label":t(zn[h]),className:z(at,"font-mono")})]},h))})]}),d&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:d}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:n,disabled:c,className:"rounded-lg px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-control disabled:opacity-50",children:t("common.cancel")}),e.jsxs("button",{type:"submit",disabled:c||!x,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-1.5 text-[12px] font-semibold text-white hover:brightness-110 disabled:opacity-50",children:[c&&e.jsx(X,{size:13,className:"animate-spin"}),t("common.save")]})]})]})}function sm({instance:s,onEdit:n}){const{state:a,dispatch:i}=W(),[r,c]=l.useState(!1),[o,d]=l.useState(!1),[m,u]=l.useState(null),x=a.bots.filter(f=>f.modelSelection.instanceId===s.instanceId||f.fallback?.some(y=>y.instanceId===s.instanceId)||f.tasks?.some(y=>y.modelSelection?.instanceId===s.instanceId)).length,p=s.claudeBedrock,h=async()=>{c(!1),d(!0),u(null);try{const f=await M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"DELETE"});Array.isArray(f.instances)&&i({type:"instances",instances:f.instances})}catch(f){u(f instanceof Error?f.message:String(f))}finally{d(!1)}};return e.jsxs("li",{"data-claude-bedrock":s.instanceId,className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[e.jsx(Fa,{preset:"aws",size:16,className:"shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-ink",title:s.displayName,children:s.displayName}),e.jsx("div",{className:"truncate font-mono text-[11px] text-ink-secondary",children:t("claudeBedrock.rowSubtitle",{profile:p?.awsProfile??"",region:p?.awsRegion??""})})]}),e.jsx("button",{type:"button",onClick:n,disabled:o,className:"shrink-0 rounded-lg px-2.5 py-1.5 text-[12px] font-medium text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("claudeBedrock.edit")}),e.jsx("button",{type:"button",disabled:o||x>0,onClick:()=>c(!0),title:x>0?t("accounts.inUse",{count:String(x)}):t("accounts.remove"),"aria-label":t("claudeBedrock.remove",{name:s.displayName}),className:"flex size-8 shrink-0 items-center justify-center rounded-lg text-danger hover:bg-danger/10 disabled:cursor-not-allowed disabled:opacity-50",children:o?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(Ee,{size:14})})]}),m&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:m}),e.jsx(Qe,{open:r,title:t("accounts.removeTitle",{name:s.displayName}),body:t("claudeBedrock.removeBody"),confirmLabel:t("accounts.remove"),tone:"neutral",pending:o,onCancel:()=>c(!1),onConfirm:()=>{h()}})]})}function ts(){const{state:s}=W(),n=s.instances.filter(r=>r.claudeBedrock),[a,i]=l.useState(null);return e.jsxs("div",{"data-claude-bedrock-endpoints":"",className:"mt-3 space-y-2",children:[e.jsx("div",{className:"text-[13px] leading-[18px] text-ink",children:t("claudeBedrock.title")}),e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.hint")}),n.length===0?e.jsx("p",{className:"text-[12px] leading-4 text-ink-secondary",children:t("claudeBedrock.empty")}):e.jsx("ul",{className:"divide-y divide-hairline/40 rounded-xl border border-hairline/50 bg-panel/40",children:n.map(r=>a===r.instanceId?e.jsx("li",{className:"p-3",children:e.jsx(Un,{instance:r,onDone:()=>i(null)})},r.instanceId):e.jsx(sm,{instance:r,onEdit:()=>i(r.instanceId)},r.instanceId))}),a==="new"?e.jsx(Un,{onDone:()=>i(null)}):e.jsxs("button",{type:"button",onClick:()=>i("new"),className:"flex min-h-8 w-fit items-center gap-1.5 rounded-lg px-2 py-1.5 text-[13px] font-medium text-ink-secondary outline-none hover:bg-control hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx(Ce,{size:14}),t("claudeBedrock.add")]})]})}function Fn(s){const n=s/1048576;return n<1?t("engines.freeSpace.underOneMb"):n<1024?`${Math.round(n)} MB`:`${(n/1024).toFixed(1)} GB`}function nm({instance:s,initial:n={kind:"idle"}}){const[a,i]=l.useState(n),[r,c]=l.useState(null),o=`/api/instances/${encodeURIComponent(s.instanceId)}/leftover-files`,d=async()=>{c(null),i({kind:"scanning"});try{const x=await M(o);i(x.folders>0?{kind:"found",bytes:x.bytes,complete:x.complete}:{kind:"none"})}catch(x){c(x instanceof Error?x.message:String(x)),i({kind:"idle"})}},m=async()=>{c(null),i({kind:"deleting"});try{const x=await M(`${o}/remove`,{method:"POST",body:JSON.stringify({})});i({kind:"done",freedBytes:x.freedBytes,remaining:x.remaining})}catch(x){c(x instanceof Error?x.message:String(x)),i({kind:"idle"})}},u=a.kind==="scanning"||a.kind==="deleting";return e.jsxs("section",{className:"mt-3 rounded-xl border border-hairline/40 px-3 py-2.5","aria-label":t("engines.freeSpace.title"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(cl,{size:13,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("span",{className:"text-[12px] font-medium text-ink",children:t("engines.freeSpace.title")}),e.jsx("span",{className:"flex-1"}),(a.kind==="idle"||a.kind==="none"||a.kind==="done"||u)&&e.jsxs("button",{type:"button",onClick:()=>{d()},disabled:u,className:"flex shrink-0 items-center gap-1 rounded-lg border border-hairline/40 px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[u&&e.jsx(X,{size:12,className:"animate-spin"}),t("engines.freeSpace.action")]})]}),e.jsx("p",{className:"mt-1.5 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.freeSpace.intro")}),a.kind==="scanning"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.scanning")}),a.kind==="deleting"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.deleting")}),a.kind==="none"&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.freeSpace.none")}),a.kind==="found"&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("p",{role:"status",className:"flex-1 text-[12px] text-ink",children:t(a.complete?"engines.freeSpace.found":"engines.freeSpace.foundAtLeast",{size:Fn(a.bytes)})}),e.jsx("button",{type:"button",onClick:()=>i({kind:"idle"}),className:"rounded-lg px-3 py-1 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink",children:t("common.cancel")}),e.jsx("button",{type:"button",onClick:()=>{m()},className:"rounded-lg bg-raised px-3 py-1 text-[12px] text-ink hover:bg-raised-hover",children:t("engines.freeSpace.delete")})]}),a.kind==="done"&&e.jsxs("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:[(a.freedBytes>0||a.remaining===0)&&e.jsxs("span",{className:"text-success",children:[t("engines.freeSpace.freed",{size:Fn(a.freedBytes)})," "]}),a.remaining>0&&t("engines.freeSpace.someLeft")]}),r&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}const ss=[60,120,180,360,720];function Ti(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(!1),[r,c]=l.useState(""),o=l.useRef(!1),d=s.config?.cacheKeepWarm;if(!d)return null;const m=async x=>{if(!o.current){o.current=!0,i(!0),c("");try{const p=await M("/api/config",{method:"PUT",body:JSON.stringify({cacheKeepWarm:{enabled:x.enabled,windowMinutes:x.windowMinutes}})});n({type:"configStatus",config:p})}catch(p){c(p instanceof Error?p.message:t("settings.keepWarm.error"))}finally{o.current=!1,i(!1)}}},u=ss.includes(d.windowMinutes)?[...ss]:[...ss,d.windowMinutes].sort((x,p)=>x-p);return e.jsxs(Y,{title:t("settings.keepWarm.title"),subtitle:t("settings.keepWarm.subtitle"),children:[e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"cache-keepwarm-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.keepWarm.enable")}),e.jsx(me,{id:"cache-keepwarm-enabled",checked:d.enabled,disabled:a,"aria-describedby":"cache-keepwarm-help cache-keepwarm-cost",onClick:()=>{m({...d,enabled:!d.enabled})}})]}),e.jsx("p",{id:"cache-keepwarm-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.keepWarm.help")}),e.jsx("p",{id:"cache-keepwarm-cost",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.keepWarm.cost")}),e.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"cache-keepwarm-window",className:"text-[13px] font-medium text-ink",children:t("settings.keepWarm.window")}),e.jsx(xe,{id:"cache-keepwarm-window",value:d.windowMinutes,disabled:a||!d.enabled,onChange:x=>{m({...d,windowMinutes:Number(x.target.value)})},children:u.map(x=>e.jsx("option",{value:x,children:t("settings.keepWarm.hours",{hours:Number((x/60).toFixed(2))})},x))})]}),a&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),r&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}function am({instance:s,cliDefault:n,onClose:a,onSaved:i}){const[r,c]=l.useState(s.cliCandidates??null),[o,d]=l.useState(""),[m,u]=l.useState(s.cli&&!(s.cliCandidates??[]).includes(s.cli)?s.cli:""),[x,p]=l.useState(!1),[h,f]=l.useState(null),[y,b]=l.useState(!1),[g,k]=l.useState(null),S=l.useRef(!1);l.useEffect(()=>{S.current||(S.current=!0,M(`/api/cli-candidates?name=${encodeURIComponent(n??"")}`).then(({candidates:j})=>{c(j),s.cli&&(j.includes(s.cli)?d(s.cli):u(s.cli))}).catch(()=>c(j=>j??[])))},[n,s.cli]);const C=m.trim()||o,w=C!==(s.cli??""),P=x||y;l.useEffect(()=>{f(null)},[C]);const v=()=>{if(P||!C||!w)return;b(!0),k(null);const j=C;M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:j})}).then(()=>Promise.resolve(i()).catch(()=>{})).then(a).catch(A=>k(A.message)).finally(()=>b(!1))},B=()=>{P||!C||!w||(p(!0),k(null),M("/api/cli-test",{method:"POST",body:JSON.stringify({cli:C,driver:s.driverKind})}).then(j=>{f(j),j.ok&&v()}).catch(j=>k(j.message)).finally(()=>p(!1)))};return e.jsxs("div",{className:"mt-2.5 flex flex-col gap-2",children:[r!==null&&r.length>0&&e.jsxs(xe,{className:"w-full font-mono",value:m.trim()?"":o,onChange:j=>{d(j.target.value),u("")},"aria-label":t("engines.detectedAria",{name:s.displayName}),disabled:P,children:[e.jsx("option",{value:"",children:t("engines.selectBinary")}),r.map(j=>e.jsx("option",{value:j,children:j},j))]}),e.jsx("input",{type:"text",value:m,onChange:j=>u(j.target.value),onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),!(!C||!w)&&B())},placeholder:r?.length?t("engines.manualPath"):"/absolute/path/to/cli","aria-label":t("engines.customAria",{name:s.displayName}),spellCheck:!1,disabled:P,className:"w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 font-mono text-[12px] text-ink placeholder:font-sans placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),h&&!h.ok&&h.message&&e.jsxs("div",{role:"alert",className:"flex gap-1.5 rounded-lg border border-warning/25 bg-warning/10 px-2.5 py-2 text-[12px] leading-relaxed text-warning",children:[e.jsx(Oe,{size:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t("engines.testFailed",{message:h.message})})]}),h?.ok&&h.version&&e.jsx("div",{className:"text-[12px] text-success",children:t("engines.testPassed",{version:h.version})}),g&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:g}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:a,disabled:P,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("common.cancel")}),h&&!h.ok?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>f(null),disabled:P,className:"rounded-lg px-3 py-1.5 text-[13px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:t("engines.editPath")}),e.jsx("button",{onClick:()=>v(),disabled:P,className:"flex items-center gap-1.5 rounded-lg bg-raised px-3 py-1.5 text-[13px] text-danger hover:bg-raised-hover disabled:opacity-50",children:y?e.jsx(X,{size:13,className:"animate-spin"}):t("engines.saveAnyway")})]}):e.jsx("button",{onClick:B,disabled:P||!C||!w,className:z("flex w-[72px] items-center justify-center gap-1.5 rounded-lg py-1.5 text-[13px]","bg-raised text-ink hover:bg-raised-hover","disabled:cursor-not-allowed disabled:opacity-50"),children:P?e.jsx(X,{size:13,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{size:13}),t("common.save")]})})]})]})}function Ri({instance:s}){const{refreshInstances:n}=W(),[a,i]=l.useState(!1),r=od(a),[c,o]=l.useState(!1),[d,m]=l.useState(!1),[u,x]=l.useState(null),[p,h]=l.useState(null),f=l.useRef(null);l.useEffect(()=>{f.current!==null&&f.current!==s.cli&&i(!1),f.current=s.cli??null},[s.cli]);const y=()=>{c||d||(o(!0),h(null),M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({cli:""})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(k=>h(k.message)).finally(()=>o(!1)))},b=()=>{c||d||(o(!0),h(null),M(`/api/instances/${encodeURIComponent(s.instanceId)}`,{method:"PATCH",body:JSON.stringify({hidden:!0})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(k=>h(k.message)).finally(()=>o(!1)))},g=()=>{c||d||(m(!0),x(null),h(null),M(`/api/instances/${encodeURIComponent(s.instanceId)}/claude-update`,{method:"POST",body:JSON.stringify({})}).then(async({version:k})=>{x(k),await Promise.resolve(n()).catch(()=>{})}).catch(k=>h(k.message)).finally(()=>m(!1)))};return e.jsxs("details",{className:"mt-4 border-t border-hairline/40 pt-3",children:[e.jsx("summary",{className:"cursor-pointer rounded-md py-1 text-[12px] font-medium text-ink-secondary outline-none hover:text-ink focus-visible:ring-2 focus-visible:ring-accent",children:t("engines.library.advanced")}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("engines.footer")}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2 text-[13px]",children:[s.cli?e.jsx("span",{className:"w-full break-all font-mono text-[12px] text-ink-secondary",title:s.cli,children:s.cli}):s.cliDefault&&e.jsx("span",{className:"break-all font-mono text-[11px] text-ink-secondary",children:s.cliDefault}),s.snapshot.version&&e.jsx("span",{className:"break-all text-[11px] text-ink-secondary",title:s.snapshot.version,children:s.snapshot.version}),e.jsx("span",{className:"flex-1"}),s.driverKind==="claudeAgent"&&e.jsxs("button",{onClick:g,disabled:c||d,className:"flex shrink-0 items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[d?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Se,{size:12}),d?t("engines.updating"):t("engines.updateClaude")]}),s.cli&&e.jsx("button",{onClick:y,disabled:c||d,className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:c?t("engines.resetting"):t("engines.reset")}),e.jsx("button",{type:"button","data-hide-engine":s.instanceId,onClick:b,disabled:c||d,title:t("engines.hideHint"),className:"shrink-0 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:t("engines.hide")}),e.jsx("button",{onClick:()=>i(k=>!k),disabled:d,"aria-expanded":a,className:z("shrink-0 rounded-lg border border-hairline/40 px-3 py-1 text-[12px]",a?"bg-accent/15 text-accent":"text-ink-secondary hover:bg-raised/50 hover:text-ink","disabled:opacity-50"),children:t("engines.setCli")})]}),u&&e.jsx("div",{role:"status",className:"mt-1 text-[12px] text-success",children:t("engines.claudeUpdated",{version:u})}),p&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:p}),r.shown&&e.jsx("div",{className:r.className,...r.exitProps,children:e.jsx(am,{instance:s,cliDefault:s.cliDefault,onClose:()=>i(!1),onSaved:n})})]})}function Dn({instance:s,action:n}){const{state:a,dispatch:i,refreshInstances:r}=W(),[c,o]=l.useState(!1),[d,m]=l.useState(!1),[u,x]=l.useState(null),p=n==="remove",h=p?a.bots.filter(b=>b.modelSelection.instanceId===s.instanceId).length:0,f=t(p?"accounts.remove":"accounts.signOut"),y=async()=>{o(!1),m(!0),x(null);try{const b=`/api/instances/${encodeURIComponent(s.instanceId)}${p?"":"/auth/sign-out"}`,{instances:g}=await M(b,{method:p?"DELETE":"POST"});Array.isArray(g)?i({type:"instances",instances:g}):await r()}catch(b){x(b instanceof Error?b.message:String(b))}finally{m(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",disabled:d||h>0,onClick:()=>o(!0),className:z("rounded-lg px-2.5 py-1.5 text-[12px] font-medium disabled:cursor-not-allowed disabled:opacity-50",p?"text-danger hover:bg-danger/10":"text-ink-secondary hover:bg-raised hover:text-ink"),children:d?e.jsx(X,{size:13,className:"animate-spin"}):f}),h>0&&e.jsx("p",{className:"text-[11px] text-ink-secondary",children:t("accounts.inUse",{count:String(h)})})]}),u&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:u}),e.jsx(Qe,{open:c,title:t(p?"accounts.removeTitle":"accounts.signOutTitle",{name:s.displayName}),body:t(p?"accounts.removeBodyAntigravity":"accounts.signOutBody"),confirmLabel:f,tone:"neutral",pending:d,onCancel:()=>{d||o(!1)},onConfirm:()=>{y()}})]})}function im({source:s}){const{state:n}=W(),[a,i]=l.useState(null),r=a?n.instances.find(c=>c.instanceId===a&&c.snapshot.authenticated!==!0):void 0;return e.jsxs(e.Fragment,{children:[e.jsx(Pi,{label:t("engineSetup.antigravity.addAccount"),endpoint:"/api/instances/antigravity-accounts",extra:{sourceInstanceId:s.instanceId},onAdded:i}),r&&e.jsx("div",{"data-antigravity-added":r.instanceId,children:e.jsx(Mt,{instance:r,unframed:!0})})]})}function rm({instance:s,bare:n=!1}){const a=s.policy&&e.jsxs("p",{className:"mb-2 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{className:"font-medium text-ink",children:t("policy.managedBy",{organization:s.policy.organizationName})})," · ",s.policy.reason]});return s.trialCredit?e.jsx(Nt,{instance:s,bare:n,children:e.jsx("p",{"data-trial-credit":s.trialCredit,className:"text-[13px] leading-relaxed text-ink-secondary",children:t(s.trialCredit==="used_up"?"engines.trialCreditUsedUp":s.trialCredit==="ended"?"engines.trialCreditEnded":Le(s)?"engines.trialCredit":"engines.trialCreditOwn")})}):s.readOnly?e.jsxs(Nt,{instance:s,bare:n,children:[a,e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("organization.managedEngine")}),!Le(s)&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("organization.engineUnavailable")})]}):e.jsxs(Nt,{instance:s,bare:n,children:[a,(s.codexEndpoint||s.claudeEndpoint)&&e.jsx(yi,{instance:s},s.instanceId),!Le(s)&&e.jsx(Mt,{instance:s,intent:s.access==="custom"?"inject":"cloud",description:s.codexEndpoint?t("agentEndpoints.codexHint"):void 0,unframed:!0}),Le(s)&&e.jsx(Yl,{instance:s,className:"mt-3"}),Le(s)&&s.serverKind==="ollama"&&e.jsx(Ql,{instance:s,className:"mt-3"}),Le(s)&&e.jsx(Zl,{instance:s,className:"mt-3"}),s.snapshot.update&&e.jsx(za,{update:s.snapshot.update,instance:s,className:"mt-3",quiet:!0}),s.snapshot.warning&&e.jsx(Ua,{warning:s.snapshot.warning,className:"mt-3"}),Le(s)&&s.snapshot.authenticated===!0&&(s.authentication?.method==="device-code"?e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(ge,{size:13}),t(eo[Ma(s.driverKind)].connectedAccount)]}):s.authentication?.method==="paste-code"&&e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-success",children:[e.jsx(ge,{size:13}),t("engineSetup.claude.connectedAccount")]})),s.freeUpSpace&&e.jsx(nm,{instance:s}),s.driverKind==="antigravityAgent"&&e.jsxs("div",{className:"mt-3 space-y-3",children:[s.snapshot.authenticated&&e.jsx("p",{className:"break-words text-[12px] text-ink-secondary",children:s.snapshot.account?.email??t("engineSetup.antigravity.emailUnavailable")}),e.jsx(im,{source:s}),s.snapshot.authenticated===!0&&s.authentication?.signOut===!0&&e.jsx(Dn,{instance:s,action:"signOut"}),s.instanceId.startsWith("antigravity-")&&e.jsx(Dn,{instance:s,action:"remove"})]}),e.jsx(Ri,{instance:s})]})}function lm(s,n){return n?s.snapshot.authenticated===!0&&s.snapshot.account?.email?s.snapshot.account.email:t("onboarding.engines.ready"):s.snapshot.ollama?Xl(s.snapshot.ollama):s.snapshot.state==="available"&&s.snapshot.authenticated===!1?t("model.signInRequired"):t("onboarding.engines.needsSetup")}function om({rows:s,isReady:n,renderEngine:a,more:i}){const[r,c]=l.useState(null),o=s.filter(p=>n(p)||p.authentication!==void 0||p.codexEndpoint||p.claudeEndpoint),[d,m]=l.useState(!1),u=!s.length||s.some(p=>!p.readOnly),x=s.filter(p=>!o.includes(p));return e.jsxs(e.Fragment,{children:[e.jsx(be,{label:t("settings.simple.ai.yours"),actions:e.jsx(Da,{}),children:e.jsx(ye,{children:o.map(p=>{const h=n(p),f=r===p.instanceId;return e.jsxs("div",{"data-simple-engine":p.instanceId,className:"group",children:[e.jsxs("div",{className:"flex min-h-11 flex-wrap items-center gap-x-5 gap-y-2 px-4 py-2.5",children:[e.jsxs("span",{className:"flex min-w-[min(100%,15rem)] flex-1 items-center gap-3",children:[e.jsx(dn,{instance:p,size:14,subtle:!0}),e.jsxs("span",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"truncate text-[14px] leading-5 text-ink",children:p.displayName}),e.jsx("span",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:lm(p,h)})]})]}),e.jsx("button",{type:"button","aria-expanded":f,className:"ui-button ml-auto shrink-0",onClick:()=>c(f?null:p.instanceId),children:t(f?"common.done":h||p.codexEndpoint||p.claudeEndpoint?"settings.simple.ai.manage":"settings.simple.ai.setUp")})]}),f&&e.jsx("div",{className:"px-4 pb-3",children:a(p,!0)})]},p.instanceId)})})}),(x.length>0||u)&&e.jsxs(zt,{title:t("settings.simple.ai.more",{count:String(x.length+Number(u))}),trailing:e.jsx("span",{"aria-hidden":"true",className:"flex items-center -space-x-1",children:x.slice(0,4).map(p=>e.jsx("span",{className:"flex size-[18px] items-center justify-center rounded-full bg-menu",children:e.jsx(dn,{instance:p,size:14,subtle:!0})},p.instanceId))}),...i,children:[u&&e.jsxs("div",{className:"rounded-xl border border-hairline/50 bg-inset p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("strong",{className:"text-sm",children:"Xingchi (Codex Responses)"}),!d&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>m(!0),children:t("settings.simple.ai.setUp")})]}),d&&e.jsx(Os,{engine:"codex",xingchi:!0,onDone:()=>m(!1)})]}),e.jsx(_a,{instances:x,isReady:n,renderEngine:p=>a(p)})]})]})}function cm(){const{state:s,refreshInstances:n}=W(),[a,i]=l.useState([]),[r,c]=l.useState(null),[o,d]=l.useState(null);if(l.useEffect(()=>{let u=!0;return M("/api/instances/hidden").then(x=>{u&&i(Array.isArray(x?.instances)?x.instances:[])}).catch(()=>{}),()=>{u=!1}},[s.instances]),a.length===0)return null;const m=u=>{c(u),d(null),M(`/api/instances/${encodeURIComponent(u)}`,{method:"PATCH",body:JSON.stringify({hidden:!1})}).then(()=>Promise.resolve(n()).catch(()=>{})).catch(x=>d(x.message)).finally(()=>c(null))};return e.jsxs("details",{"data-hidden-engines":!0,className:"px-4",children:[e.jsx("summary",{className:"cursor-pointer text-[13px] font-medium text-ink-secondary hover:text-ink",children:t("engines.hiddenTitle",{count:String(a.length)})}),e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("engines.hiddenHint")}),e.jsx("div",{className:"mt-2 flex flex-col gap-1.5",children:a.map(u=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-hairline/40 bg-inset px-3 py-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[13px] text-ink",children:u.displayName}),e.jsx("button",{type:"button","data-unhide-engine":u.instanceId,disabled:r!==null,onClick:()=>m(u.instanceId),className:"shrink-0 text-[12px] font-medium text-accent hover:underline disabled:opacity-50",children:r===u.instanceId?t("engines.unhiding"):t("engines.unhide")})]},u.instanceId))}),o&&e.jsx("div",{role:"alert",className:"mt-1 text-[12px] text-danger",children:o})]})}function Li({simple:s=!1,more:n}){const{state:a}=W();l.useEffect(()=>ql,[]);const i=a.instances.filter(h=>h.readOnly||h.cli!==void 0||h.cliDefault!==void 0||h.snapshot.state==="unavailable"||Jl(h)||h.claudeEndpoint!==void 0||h.claudeBedrock!==void 0||h.codexEndpoint!==void 0),r=new Map;for(const h of i){const f=es(h);f&&r.set(f,[...r.get(f)??[],h])}const c=h=>{const f=es(h);return f&&r.get(f)?.[0]===h?f:null},o=i.filter(h=>!es(h)||c(h)),d=o.length>0&&o.every(h=>h.readOnly),m=!r.has("chatgpt")&&!d,u=!r.has("claude")&&!d,x=h=>{const f=c(h);return f?Ii(r.get(f)):Le(h)},p=(h,f=!1)=>{const y=c(h);return y?e.jsx(Qu,{group:y,accounts:r.get(y),bare:f,advanced:e.jsxs(e.Fragment,{children:[y==="claude"?e.jsxs(e.Fragment,{children:[e.jsx(Vt,{}),e.jsx(ts,{})]}):e.jsx(wt,{}),e.jsx(Ri,{instance:h})]})}):e.jsx(rm,{instance:h,bare:f})};return s&&n?e.jsxs(e.Fragment,{children:[e.jsx(om,{rows:o,isReady:x,renderEngine:p,more:n}),u&&e.jsxs("div",{className:"px-4",children:[e.jsx(Vt,{}),e.jsx(ts,{})]}),m&&e.jsx("div",{className:"px-4",children:e.jsx(wt,{})})]}):e.jsxs("div",{className:"flex min-w-0 flex-col gap-6 pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-60 space-y-2 px-4",children:[e.jsx("h1",{className:"text-[22px] font-semibold tracking-tight text-ink",children:t("settings.engines.title")}),e.jsx("p",{className:"mt-2 max-w-lg text-[13px] leading-relaxed text-ink-secondary",children:t("engines.library.intro")})]}),e.jsx(Da,{})]}),e.jsx(_a,{instances:o,isReady:x,renderEngine:p}),u&&e.jsxs("div",{className:"px-4",children:[e.jsx(Vt,{}),e.jsx(ts,{})]}),m&&e.jsx("div",{className:"px-4",children:e.jsx(wt,{})}),e.jsx(cm,{}),e.jsx(Ti,{})]})}const dm={status:"/api/local-computer","local-vms":"/api/local-computer/instances",cloud:"/api/computers/boxes",vps:"/api/computers/vps"};function bt(s,n){return[dm[s],{signal:n}]}function Fs(s,n){return[s,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)}]}function um({instances:s,configured:n,aliases:a,loading:i,removingName:r,error:c,unavailableReason:o,onRefresh:d,onRemove:m}){return e.jsxs(Y,{title:t("vm.vps.title"),subtitle:t("vm.vps.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n===!0?t("vm.vps.sshHost",{alias:a.join(", ")||t("vm.vps.configuredFallback")}):n===!1?e.jsxs(e.Fragment,{children:[t("vm.vps.needsAlias")," ",e.jsx($a,{id:"vps"})]}):t("vm.vps.refreshHint")}),e.jsxs("button",{type:"button",onClick:d,disabled:i||r!==null,"aria-label":t("vm.vps.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(Se,{size:12,className:z(i&&"animate-spin")})," ",t("vm.refresh")]})]}),c&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:c}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:i?t("vm.vps.checking"):o?t("vm.vps.unavailable",{reason:o}):n===!1?t("vm.vps.notConfigured"):s.length===1?t("vm.vps.foundOne"):t("vm.vps.foundMany",{count:s.length})}),!(n===!1&&!i&&!o)&&e.jsxs("div",{"aria-busy":i||r!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:[o&&s.length>0&&e.jsxs("div",{className:"flex items-center gap-2 border-b border-hairline/35 px-3 py-2.5 text-[12px] text-ink-secondary",children:[e.jsx(Oe,{size:14,className:"shrink-0 text-warning"})," ",o]}),i&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:13,className:"animate-spin"})," ",t("vm.vps.checkingList")]}):o&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Oe,{size:14,className:"shrink-0 text-warning"})," ",o]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(dl,{size:14,className:"shrink-0"})," ",t("vm.vps.notConfigured")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.vps.noneFound")}):s.map((u,x)=>{const p=jm(u),h=Ds(p),f=r===u.name,y=_s(u.name);return e.jsxs("div",{className:z("flex items-start justify-between gap-3 px-3 py-3",x>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:u.orphaned?t("vm.vps.orphan",{id:y}):u.ownerName}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px]",u.inUse||p==="running"?"bg-success/15 text-success":p==="stopped"||p==="paused"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:h}),a.length>1&&e.jsx("span",{className:"rounded-full bg-control px-2 py-0.5 font-mono text-[11px] text-ink-secondary",children:u.vpsAlias})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:u.orphaned?t("vm.owner.gone"):t("vm.owner.owned")}),u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.vps.stopFirst")})]}),e.jsxs("button",{type:"button",onClick:()=>m(u),disabled:i||u.inUse||r!==null,"aria-busy":f||void 0,title:t("vm.vps.removeTitle"),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[f?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Ee,{size:12}),t("vm.vps.remove")]})]},`${u.vpsAlias??""}:${u.name}`)})]})]})}const mm=[1e3,2e3,4e3];function pm(s){return new Promise(n=>window.setTimeout(n,s))}const xm={auto:"vm.dest.auto",cloud:"place.cloud",vm:"vm.dest.vm",local:"vm.dest.local",browser:"vm.dest.browser",off:"vm.dest.off"},hm={unmanaged:"vm.state.notManaged","in-use":"vm.state.inUse",stopped:"vm.state.stopped",running:"vm.state.running",attention:"vm.state.attention",sleeping:"vm.state.sleeping","going-to-sleep":"vm.state.goingToSleep",starting:"vm.state.starting",restarting:"vm.state.restarting",removing:"vm.state.removing",paused:"vm.state.paused"};function Ds(s){return t(hm[s])}function gm(s){return s.managed?s.inUse?"in-use":s.container==="stopped"?"stopped":s.ready?"running":"attention":"unmanaged"}function fm(s){return Ds(gm(s))}function bm(s){return s.inUse?"in-use":s.state==="removing"?"removing":s.state==="archived"?"sleeping":s.state==="archiving"?"going-to-sleep":["idle","ready","running"].includes(s.state)?"running":["init","provisioning","provisioned","cloning"].includes(s.state)?"starting":"attention"}function Bi(s,n,a){const i={...a},r=new Set(s.map(o=>o.boxId)),c=s.flatMap(o=>{const d=a[o.boxId];return d==="deleted"?[]:d==="deleting"?[{...o,state:"removing"}]:d!=="sleeping"?[o]:o.state==="archived"?(delete i[o.boxId],[o]):[{...o,state:"archived"}]});for(const o of n)a[o.boxId]!=="sleeping"||r.has(o.boxId)||c.push({...o,state:"archived"});for(const[o,d]of Object.entries(a))(d==="deleted"||d==="deleting")&&!r.has(o)&&delete i[o];return{instances:c,overrides:i}}function ym(s,n,a){return s.configured!==!0||s.available!==!0?{instances:n,overrides:{...a}}:Bi(Array.isArray(s.instances)?s.instances:[],n,a)}function vm(s){return["idle","ready","running"].includes(s.state)}function jm(s){return s.inUse?"in-use":s.state==="running"?"running":s.state==="restarting"?"restarting":s.state==="removing"?"removing":["created","exited"].includes(s.state)?"stopped":s.state==="paused"?"paused":"attention"}function _s(s){const n=/-([a-f0-9]{12})$/i.exec(s)?.[1];return n?n.slice(-8).toLowerCase():"unknown"}function km(s){return{confirmation:t("vm.confirm.deleteBotVm",{name:s.name}),request:Fs(`/api/bots/${s.botId}/local-computer/remove`,{})}}function Nm(s,n){return{confirmation:s==="delete"?t("vm.confirm.deleteCloud",{subject:n.orphaned?t("vm.confirm.orphanCloud"):t("vm.confirm.ownedCloud",{name:n.ownerName??""})}):null,request:Fs(`/api/computers/boxes/${encodeURIComponent(n.boxId)}/${s}`,s==="delete"?{confirmName:n.name}:{})}}function wm(s){const n=_s(s.name);return{confirmation:t("vm.confirm.removeVps",{subject:s.orphaned?t("vm.confirm.orphanVps",{id:n}):t("vm.confirm.ownedVps",{name:s.ownerName??""})}),request:Fs(`/api/computers/vps/${encodeURIComponent(s.name)}/remove`,{confirmName:s.name,alias:s.vpsAlias})}}function ns(s,n){return s.confirmation!==null&&!n(s.confirmation)?null:s.request}function Sm({instances:s,configured:n,loading:a,pending:i,error:r,unavailableReason:c,onRefresh:o,onSleep:d,onDelete:m}){return e.jsxs(Y,{title:t("vm.cloud.title"),subtitle:t("vm.cloud.subtitle"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:n===!0?t("vm.cloud.includesOrphans"):n===!1?e.jsxs(e.Fragment,{children:[t("vm.cloud.needsKey")," ",e.jsx($a,{id:"box"})]}):t("vm.cloud.refreshHint")}),e.jsxs("button",{type:"button",onClick:o,disabled:a||i!==null,"aria-label":t("vm.cloud.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(Se,{size:12,className:z(a&&"animate-spin")})," ",t("vm.refresh")]})]}),r&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:r}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.cloud.checking"):c?t("vm.cloud.unavailable",{reason:c}):n===!1?t("vm.cloud.notConnected"):s.length===1?t("vm.cloud.foundOne"):t("vm.cloud.foundMany",{count:s.length})}),!(n===!1&&!a&&!c)&&e.jsx("div",{"aria-busy":a||i!==null,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:13,className:"animate-spin"})," ",t("vm.cloud.checkingList")]}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Oe,{size:14,className:"shrink-0 text-warning"})," ",c]}):n===!1?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Rt,{size:14,className:"shrink-0"})," ",t("vm.cloud.notConnected")]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.cloud.noneFound")}):s.map((u,x)=>{const p=bm(u),h=Ds(p),f=i?.boxId===u.boxId,y=vm(u),b=p==="removing";return e.jsxs("div",{className:z("flex items-start justify-between gap-3 px-3 py-3",x>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:u.orphaned?t("vm.cloud.orphan"):t("vm.cloud.ofBot",{name:u.ownerName??""})}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px]",u.inUse||p==="running"?"bg-success/15 text-success":p==="sleeping"||p==="going-to-sleep"?"bg-control text-ink-secondary":"bg-warning/15 text-warning"),children:h})]}),e.jsx("div",{className:"mt-1 break-all text-[12px] text-ink-secondary",children:u.orphaned?t("vm.owner.gone"):t("vm.cloud.machineId",{id:u.name})}),u.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.cloud.stopFirst")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>d(u),disabled:a||u.inUse||i!==null||!y,"aria-busy":f&&i?.action==="sleep"?!0:void 0,title:y?t("vm.cloud.sleepTitle"):t("vm.cloud.sleepBlocked",{state:h.toLowerCase()}),className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:cursor-not-allowed disabled:opacity-40",children:[f&&i?.action==="sleep"?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(ul,{size:12}),t("vm.cloud.sleep")]}),e.jsxs("button",{type:"button",onClick:()=>m(u),disabled:a||u.inUse||i!==null||b,"aria-busy":f&&i?.action==="delete"?!0:void 0,title:t("vm.cloud.deleteTitle"),className:"flex items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[f&&i?.action==="delete"?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Ee,{size:12}),t("common.delete")]})]})]},u.boxId)})})]})}function Cm({instances:s,maxInstances:n,loading:a,deletingBotId:i,error:r,unavailableReason:c,onRefresh:o,onDelete:d,runningInstances:m,powerPending:u,onPower:x}){return e.jsxs(Y,{title:t("vm.perBot.title"),subtitle:t("vm.perBot.subtitle",{count:c?t("vm.perBot.inventoryUnavailable"):m===void 0?t("vm.perBot.created",{count:s.length,max:n}):L(`Đã tạo ${s.length} máy · Đang chạy ${m}/${n}`,`${s.length} desktops created · ${m}/${n} running`)}),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[12px] text-ink-secondary",children:m===void 0?t("vm.perBot.deleteHint"):L("Ứng dụng không giới hạn số máy đã tạo; số lượng thực tế phụ thuộc dung lượng ổ đĩa. Dừng một máy để giải phóng tài nguyên cho máy khác.","The app does not cap created desktops; their number depends on disk space. Stop a desktop to free resources for another.")}),e.jsxs("button",{type:"button",onClick:o,disabled:a||i!==null||!!u,"aria-label":t("vm.perBot.refreshAria"),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(Se,{size:12,className:z(a&&"animate-spin")})," ",t("vm.refresh")]})]}),r&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:r}),e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:a?t("vm.perBot.checking"):c?t("vm.perBot.unavailable",{reason:c}):s.length===1?t("vm.perBot.foundOne"):t("vm.perBot.foundMany",{count:s.length})}),e.jsx("div",{"aria-busy":a||i!==null||!!u,className:"mt-3 overflow-hidden rounded-xl border border-hairline/40",children:a&&s.length===0?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:13,className:"animate-spin"})," ",t("vm.perBot.checkingList")]}):c?e.jsxs("div",{className:"flex items-center gap-2 px-3 py-4 text-[13px] text-ink-secondary",children:[e.jsx(Oe,{size:14,className:"shrink-0 text-warning"})," ",c]}):s.length===0?e.jsx("div",{className:"px-3 py-4 text-[13px] text-ink-secondary",children:t("vm.perBot.none")}):s.map((p,h)=>{const f=fm(p),y=i===p.botId,b=p.managed===!0;return e.jsxs("div",{className:z("flex items-start justify-between gap-3 px-3 py-3",h>0&&"border-t border-hairline/35"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-[14px] font-medium text-ink",children:p.name}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px]",b?p.inUse||p.ready?"bg-success/15 text-success":p.container==="stopped"?"bg-control text-ink-secondary":"bg-warning/15 text-warning":"bg-warning/15 text-warning"),children:f})]}),e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.destination",{destination:t(xm[p.destination])})}),!b&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:t("vm.perBot.unmanaged")}),b&&p.problem&&!p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:ai(p.problem)}),b&&p.inUse&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:t("vm.perBot.stopFirst")})]}),b&&e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-2",children:[x&&e.jsxs("button",{type:"button",onClick:()=>x(p,p.container==="running"?"stop":"start"),disabled:a||p.inUse||i!==null||!!u||p.container==="stopped"&&m!==void 0&&m>=n,"aria-busy":u?.botId===p.botId||void 0,className:"flex items-center gap-1.5 rounded-lg bg-control px-2.5 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-40",children:[u?.botId===p.botId&&e.jsx(X,{size:12,className:"animate-spin"}),p.container==="running"?L("Dừng","Stop"):L("Bật","Start")]}),e.jsxs("button",{type:"button",onClick:()=>d(p),disabled:a||p.inUse||i!==null||!!u,"aria-busy":y||void 0,title:p.inUse?t("vm.perBot.deleteBlocked"):t("vm.perBot.deleteTitle",{name:p.name}),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-danger/10 px-2.5 py-1.5 text-[12px] font-medium text-danger hover:bg-danger/15 disabled:cursor-not-allowed disabled:opacity-40",children:[y?e.jsx(X,{size:12,className:"animate-spin"}):e.jsx(Ee,{size:12}),t("common.delete")]})]})]},p.botId)})})]})}function yt({n:s,title:n,done:a,children:i}){return e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:z("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-[11px]",a?"bg-success/20 text-success":"border border-hairline/50 text-ink-secondary"),children:a?e.jsx(ge,{size:12}):s}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:z("text-[14px]",a?"text-ink-secondary line-through":"text-ink"),children:n}),!a&&i&&e.jsx("div",{className:"mt-2 flex flex-col items-start gap-2 [&>*]:max-w-full",children:i})]})]})}function qe({action:s,pending:n,children:a,onClick:i,danger:r=!1}){return e.jsxs("button",{onClick:i,"aria-busy":n===s,disabled:n!==null,className:z("flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-[13px] font-medium disabled:opacity-50",r?"bg-danger/15 text-danger hover:bg-danger/20":"bg-accent text-white hover:brightness-110"),children:[n===s&&e.jsx(X,{size:13,className:"animate-spin"}),a]})}const Oi=5,Mi=1440,Em=480;function Am(s){const n=s.trim();if(!/^\d+$/.test(n))return null;const a=Number(n);return a>=Oi&&a<=Mi?a:null}function Im({minutes:s,disabled:n,onSave:a}){const[i,r]=l.useState(String(s)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,x]=l.useState(!1);l.useEffect(()=>{c||r(String(s))},[s,c]);const p=async()=>{if(!c||u)return;const h=Am(i);if(h===null){m(t("vm.idle.range"));return}x(!0);try{await a(h),r(String(h)),o(!1),m("")}catch(f){m(f instanceof Error?f.message:t("vm.idle.error"))}finally{x(!1)}};return e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"local-vm-idle-timeout",className:"text-[13px] text-ink",children:t("vm.idle.label")}),e.jsx("div",{id:"local-vm-idle-timeout-help",className:"text-[12px] text-ink-secondary",children:t("vm.idle.detail")})]}),e.jsxs("div",{className:z("flex w-[150px] shrink-0 items-center rounded-lg border bg-control",d?"border-danger/60":"border-hairline/40 focus-within:border-focus"),children:[e.jsx("input",{id:"local-vm-idle-timeout",type:"number",min:Oi,max:Mi,step:1,inputMode:"numeric",value:i,disabled:n||u,"aria-invalid":!!d,"aria-describedby":d?"local-vm-idle-timeout-error local-vm-idle-timeout-help":"local-vm-idle-timeout-help",onChange:h=>{r(h.target.value),o(!0),m("")},onBlur:()=>{p()},onKeyDown:h=>{h.key==="Enter"&&h.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-2.5 py-1.5 text-[13px] tabular-nums text-ink focus:outline-none disabled:opacity-50"}),e.jsx("span",{className:"pr-2.5 text-[13px] text-ink-secondary",children:t("vm.idle.minutes")})]})]}),d?e.jsx("p",{id:"local-vm-idle-timeout-error",role:"alert",className:"mt-1.5 text-[12px] text-danger",children:d}):null]})}function zi(){const s=W().state.config?.cloudHome===!0,[n,a]=l.useState(null),[i,r]=l.useState(!0),[c,o]=l.useState(null),d=l.useRef(null);l.useEffect(()=>()=>d.current?.abort(),[]);const[m,u]=l.useState(null),[x,p]=l.useState(!1),[h,f]=l.useState(0),[y,b]=l.useState([]),[g,k]=l.useState(2),[S,C]=l.useState(!1),[w,P]=l.useState(null),[v,B]=l.useState(null),[j,A]=l.useState(null),[I,_]=l.useState(null),[U,J]=l.useState(0),[K,te]=l.useState([]),[ae,de]=l.useState(null),[D,T]=l.useState(!0),[Z,ee]=l.useState(null),[fe,N]=l.useState(null),[re,se]=l.useState(null),[ne,G]=l.useState(0),ie=l.useRef([]),le=l.useRef({}),[ce,ve]=l.useState([]),[$,oe]=l.useState(null),[R,E]=l.useState([]),[H,pe]=l.useState(!0),[q,ke]=l.useState(null),[Pe,et]=l.useState(null),[tt,ze]=l.useState(null),[Ir,Pr]=l.useState(0),[Tr,Fe]=l.useState(""),Ke=l.useCallback(async O=>{const F=await fetch(...bt("status",O)),Q=await F.json().catch(()=>({}));if(!O?.aborted){if(!F.ok)throw new Error(Q.error??t("vm.err.status",{code:F.status}));return a(Q),u(null),Q}},[]),xt=l.useCallback(async O=>{const F=await fetch(...bt("local-vms",O)),Q=await F.json().catch(()=>({}));if(!F.ok)throw new Error(Q.error??t("vm.err.inventory",{code:F.status}));const V=Q;b(V.instances),k(V.maxInstances),B(V.available?null:ai(V.problem)??t("vm.err.runtimeUnavailable")),P(null)},[]),st=l.useCallback(async O=>{const F=await fetch(...bt("cloud",O)),Q=await F.json().catch(()=>({}));if(!F.ok)throw new Error(Q.error??t("vm.err.cloudInventory",{code:F.status}));const V=Q,he=ym(V,ie.current,le.current);le.current=he.overrides,ie.current=he.instances,te(he.instances),de(V.configured===!0),N(V.available||!V.configured?null:V.problem??t("vm.err.cloudUnavailable")),ee(null)},[]),_t=l.useCallback(async O=>{const F=await fetch(...bt("vps",O)),Q=await F.json().catch(()=>({}));if(!F.ok)throw new Error(Q.error??t("vm.err.vpsInventory",{code:F.status}));const V=Q;ve(Array.isArray(V.instances)?V.instances:[]),oe(V.configured===!0),E(Array.isArray(V.vpsAliases)?V.vpsAliases:[]),et(V.available||!V.configured?null:V.problem??t("vm.err.vpsUnavailable")),ke(null)},[]);l.useEffect(()=>{if(s)return;let O=!0,F,Q;const V=async()=>{Q=new AbortController;try{await Ke(Q.signal)}catch(he){O&&!(he instanceof DOMException&&he.name==="AbortError")&&(a(null),u(he instanceof Error?he.message:String(he)))}finally{O&&(r(!1),F=window.setTimeout(()=>{V()},5e3))}};return V(),()=>{O=!1,Q?.abort(),F!==void 0&&window.clearTimeout(F)}},[s,Ke,h]),l.useEffect(()=>{if(n?.mode!=="per-bot"){b([]),C(!1),P(null),B(null);return}const O=new AbortController;return C(!0),xt(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||P(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||C(!1)}),()=>O.abort()},[U,xt,n?.mode]),l.useEffect(()=>{const O=new AbortController;return T(!0),st(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||N(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||T(!1)}),()=>O.abort()},[ne,st]),l.useEffect(()=>{const O=new AbortController;return pe(!0),_t(O.signal).catch(F=>{F instanceof DOMException&&F.name==="AbortError"||et(F instanceof Error?F.message:String(F))}).finally(()=>{O.signal.aborted||pe(!1)}),()=>O.abort()},[_t,Ir]);const $t=async(O,F)=>{const Q=await fetch(`/api/local-computer/${O}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:F}),V=await Q.json().catch(()=>({})),he={pull:"vm.err.prepare",run:"vm.err.create",start:"vm.err.start",stop:"vm.err.stop",remove:"vm.deleteError"};if(!Q.ok)throw new Error(V.error??t(he[O]));return F.throwIfAborted(),a(V),V},Vs=O=>window.ogb?.confirm?window.ogb.confirm(O):window.confirm(O),He=async O=>{if(c!==null||d.current)return;const F=new AbortController;d.current=F,o(O),u(null);try{if(O==="remove"&&!await Vs(t("vm.confirm.deleteShared"))||O==="recreate"&&!await Vs(t("vm.confirm.recreate")))return;let Q;if(O==="recreate"?(await $t("remove",F.signal),Q=await $t("run",F.signal)):Q=await $t(O,F.signal),(O==="run"||O==="start"||O==="recreate")&&(Q=await En(Q,async()=>await Ke(F.signal)??Q,F.signal),!Q.ready&&!Q.capacity_limited))throw new Error(Q.problem??t("vm.err.start"));await Ke(),Fe(O==="remove"?t("vm.announce.deleted"):O==="stop"?t("vm.announce.stopped"):t("vm.announce.updated"))}catch(Q){if(F.signal.aborted)return;u(Q instanceof Error?Q.message:String(Q))}finally{d.current=null,F.signal.aborted||o(null)}},Rr=async(O,F)=>{if(I||j)return;_({botId:O.botId,action:F}),P(null);const Q=new AbortController;try{const V=`/api/bots/${encodeURIComponent(O.botId)}/local-computer`,he=await fetch(`${V}/${F}`,{method:"POST",headers:{"content-type":"application/json"},body:"{}"});let Re=await he.json();if(!he.ok)throw new Error(Re.error??t("vm.err.start"));if(F==="start"&&(Re=await En(Re,async()=>{const We=await fetch(V);if(!We.ok)throw new Error(t("vm.err.start"));return We.json()},Q.signal)),F==="start"&&!Re.ready)throw new Error(Re.problem??t("vm.err.start"));await Promise.all([xt(),Ke()])}catch(V){P(V instanceof Error?V.message:String(V))}finally{_(null)}},qs=async O=>{p(!0),u(null);try{const F=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{mode:O,automaticCapacity:!0}})}),Q=await F.json().catch(()=>({}));if(!F.ok)throw new Error(Q.error??t("vm.policyError"));a(V=>V&&{...V,mode:O}),await Ke()}catch(F){u(F instanceof Error?F.message:String(F))}finally{p(!1)}},Lr=async O=>{const F=await fetch("/api/config",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({localVm:{idleTimeoutMinutes:O}})}),Q=await F.json().catch(()=>({}));if(!F.ok)throw new Error(Q.error??t("vm.idle.error"));a(V=>V&&{...V,idle_timeout_ms:O*6e4})},Br=async O=>{if(!O.managed){P(t("vm.unmanagedError"));return}const F=ns(km(O),Q=>window.confirm(Q));if(F){A(O.botId),P(null);try{const Q=await fetch(...F),V=await Q.json().catch(()=>({}));if(!Q.ok)throw new Error(V.error??t("vm.deleteError"));await xt(),Fe(t("vm.announce.deletedBot",{name:O.name}))}catch(Q){P(Q instanceof Error?Q.message:String(Q))}finally{A(null)}}},Js=async(O,F)=>{const Q=ns(Nm(O,F),V=>window.confirm(V));if(Q){se({boxId:F.boxId,action:O}),ee(null),Fe("");try{const V=await fetch(...Q),he=await V.json().catch(()=>({}));if(!V.ok)throw new Error(he.error??t(O==="delete"?"vm.cloud.deleteError":"vm.cloud.sleepError"));const Re=O==="delete"&&he?.pending===!0;le.current={...le.current,[F.boxId]:O==="delete"?Re?"deleting":"deleted":"sleeping"};const We=Bi(ie.current,ie.current,le.current);le.current=We.overrides,ie.current=We.instances,te(We.instances);const Ge=F.orphaned?t("vm.announce.orphanCloud"):t("vm.confirm.ownedCloud",{name:F.ownerName??""});if(Fe(Re?`${Ge}: ${t("vm.state.removing")}.`:t(O==="delete"?"vm.announce.cloudDeleted":"vm.announce.cloudSleeping",{subject:Ge})),Re){for(const Ae of mm){await pm(Ae);try{await st()}catch{}if(le.current[F.boxId]!=="deleting"){Fe(t("vm.announce.cloudDeleted",{subject:Ge}));return}}const Ve={...le.current};delete Ve[F.boxId],le.current=Ve;const gt=ie.current.map(Ae=>Ae.boxId===F.boxId?{...Ae,state:F.state}:Ae);ie.current=gt,te(gt);try{await st(),ie.current.some(Ae=>Ae.boxId===F.boxId)||Fe(t("vm.announce.cloudDeleted",{subject:Ge}))}catch(Ae){const Mr=Ae instanceof Error?Ae.message:String(Ae);ee(`${Ge}: ${t("vm.state.removing")}. ${Mr}`)}return}try{await st()}catch(Ve){const gt=Ve instanceof Error?Ve.message:String(Ve);ee(t(O==="delete"?"vm.cloud.deletedRefreshError":"vm.cloud.sleepRefreshError",{subject:Ge,detail:gt}))}}catch(V){ee(V instanceof Error?V.message:String(V))}finally{se(null)}}},Or=async O=>{const F=_s(O.name),Q=ns(wm(O),V=>window.confirm(V));if(Q){ze(O.name),ke(null);try{const V=await fetch(...Q),he=await V.json().catch(()=>({}));if(!V.ok)throw new Error(he.error??t("vm.vpsRemoveError"));await _t(),Fe(t("vm.announce.vpsRemoved",{subject:O.orphaned?t("vm.announce.orphanVps",{id:F}):t("vm.confirm.ownedVps",{name:O.ownerName??""})}))}catch(V){ke(V instanceof Error?V.message:String(V))}finally{ze(null)}}},Te=n?.commands,ht=n?.ready===!0,Xs=n?.container!=="missing",Ys=!!(Xs&&(!n?.imageMatches||!n?.managed||n?.network==="unsafe"||n?.security==="unsafe"||n?.persistence==="unsafe")),Qs=!i&&!n,Zs=n?.platform==="darwin"?t("vm.host.mac"):t("vm.host.computer"),Ne=n?.mode==="per-bot",Kt=Ne&&n?.runtime==="container",Ht=Ne?!!(n?.daemonUp&&n?.image&&!Kt):ht;return e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status","aria-live":"polite","aria-atomic":"true",className:"sr-only",children:Tr}),e.jsx(Sm,{instances:K,configured:ae,loading:D,pending:re,error:Z,unavailableReason:fe,onRefresh:()=>G(O=>O+1),onSleep:O=>{Js("sleep",O)},onDelete:O=>{Js("delete",O)}}),e.jsx(um,{instances:ce,configured:$,aliases:R,loading:H,removingName:tt,error:q,unavailableReason:Pe,onRefresh:()=>Pr(O=>O+1),onRemove:O=>{Or(O)}}),e.jsx(cd,{}),!s&&e.jsxs(e.Fragment,{children:[e.jsxs(Y,{title:t("vm.main.title"),subtitle:Ne?t("vm.main.perBotSubtitle",{host:Zs}):t("vm.main.sharedSubtitle",{host:Zs}),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("span",{"aria-live":"polite",className:z("flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[13px]",Ht?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:[i?e.jsx(X,{size:12,className:"animate-spin"}):Ht?e.jsx(ge,{size:12}):e.jsx(to,{size:9}),i?t("common.checking"):Qs?t("vm.main.statusUnavailable"):Ne&&Ht?t("vm.main.readyPerBot"):Kt?t("vm.main.perBotUnsupported"):ht?t("vm.main.ready"):n?.problem??t("vm.main.notReady")]}),e.jsxs("button",{onClick:()=>{r(!0),f(O=>O+1),J(O=>O+1)},disabled:i||c!==null,className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-40",children:[e.jsx(Se,{size:12})," ",t("vm.main.recheck")]}),ht&&!Ne&&e.jsxs("a",{href:n?.viewer_url??Te?.view,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 rounded-lg border border-hairline/40 px-2.5 py-1 text-[13px] text-ink hover:bg-control",children:[e.jsx(pt,{size:12})," ",t("vm.main.watch")]})]}),m&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:m})]}),e.jsxs(Y,{title:t("vm.isolation.title"),subtitle:t("vm.isolation.subtitle"),children:[e.jsx("div",{className:"flex overflow-hidden rounded-lg border border-hairline/40",children:["shared","per-bot"].map((O,F)=>e.jsx("button",{type:"button",disabled:!n||x,onClick:()=>{qs(O)},className:z("flex-1 px-3 py-2 text-[13px] disabled:opacity-50",F>0&&"border-l border-hairline/40",n?.mode===O?"bg-control text-ink":"text-ink-secondary hover:text-ink"),children:O==="shared"?t("vm.isolation.shared"):t("vm.isolation.perBot")},O))}),Ne&&e.jsxs("div",{className:"mt-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] text-ink",children:L("Số máy ảo chạy cùng lúc tối đa","Maximum desktops running at once")}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:L("Không giới hạn số máy đã tạo trong ứng dụng. Giới hạn chạy cùng lúc tự tính theo RAM/CPU cấp cho Docker hoặc Podman, có dự phòng cho hệ thống. Khi đủ chỗ đang chạy, máy mới vẫn được tạo ở trạng thái dừng.","The app does not cap created desktops. The running limit is calculated from Docker or Podman memory/CPU with a system reserve. When running slots are full, new desktops are still created in a stopped state.")}),n?.capacity&&e.jsxs("div",{className:"mt-1 text-[12px] text-ink-secondary",children:[n.capacity.source==="host"?L("Ước tính từ máy chủ; chưa đọc được tài nguyên Docker/Podman","Host estimate; Docker/Podman resources have not been read"):n.capacity.source==="docker"?"Docker":"Podman",` · ${n.capacity.memoryGb.toFixed(1)} GB RAM · ${n.capacity.cpus} CPU`,` · ${L("Mỗi máy","Each desktop")}: ${n.capacity.perVmMemoryGb} GB / ${n.capacity.perVmCpus} CPU`,` · ${L("Dành cho hệ thống","System reserve")}: ${n.capacity.reservedMemoryGb.toFixed(1)} GB / ${n.capacity.reservedCpus} CPU`]}),n?.automatic_capacity===!1&&e.jsx("button",{type:"button",disabled:x,onClick:()=>{qs(n.mode)},className:"mt-1 text-[12px] text-accent hover:underline",children:L("Chuyển sang tự động","Switch to automatic")}),n&&(n.running_instances??0)>n.max_instances&&e.jsx("div",{className:"mt-1 text-[12px] text-warning",children:L("Số máy đang chạy vượt mức ước tính mới. Ứng dụng giữ nguyên chúng; dừng bớt máy trước khi bật máy khác.","The running desktops exceed the new estimate. They are kept; stop some before starting another.")})]}),e.jsxs("div",{className:"shrink-0 rounded-lg bg-control px-3 py-2 text-center text-[13px] text-ink",children:[e.jsx("div",{className:"text-[11px] text-ink-secondary",children:n?.automatic_capacity===!1?L("Thủ công","Manual"):L("Tự động","Automatic")}),e.jsx("div",{className:"font-semibold tabular-nums",children:n?.max_instances??"…"})]})]}),e.jsx(Im,{minutes:n?Math.round(n.idle_timeout_ms/6e4):Em,disabled:!n||x,onSave:Lr}),x&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx(X,{size:12,className:"animate-spin"})," ",t("vm.saving")]})]}),e.jsx(Y,{title:t("vm.setup.title"),subtitle:t("vm.setup.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(yt,{n:1,title:t("vm.setup.step1"),done:!!n?.runtime,children:[e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.step1Detail")}),Te?.install?e.jsx(rt,{command:Te.install}):e.jsx("a",{href:"https://podman.io/docs/installation",target:"_blank",rel:"noreferrer",className:"text-[13px] text-accent hover:underline",children:t("vm.setup.podmanGuide")})]}),e.jsx(yt,{n:2,title:n?.runtime&&!n.daemonUp?t("vm.setup.step2Open",{runtime:n.runtime}):t("vm.setup.step2"),done:!!n?.daemonUp,children:n?.runtime?Te?.runtimeStart?e.jsx(rt,{command:Te.runtimeStart}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.step2Detail")}):null}),e.jsxs(yt,{n:3,title:t("vm.setup.step3"),done:!!n?.image,children:[n?.daemonUp&&e.jsx(qe,{action:"pull",pending:c,onClick:()=>{He("pull")},children:t("vm.setup.prepare")}),Te?.pull&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showPull")}),e.jsx("div",{className:"mt-2",children:e.jsx(rt,{command:Te.pull})})]})]}),e.jsxs(yt,{n:4,title:Ne?t("vm.setup.step4PerBot"):Ys?t("vm.setup.step4Recreate"):t("vm.setup.step4"),done:Ne?y.some(O=>O.managed):ht,children:[Ne?e.jsx("div",{className:"text-[13px] leading-relaxed text-ink-secondary",children:Kt?t("vm.setup.applePort"):t("vm.setup.perBotHint")}):Ys?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2 text-[13px] text-warning",children:[e.jsx(Oe,{size:15,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n?.problem})]}),n?.image?e.jsxs(qe,{action:"recreate",pending:c,onClick:()=>{He("recreate")},danger:!0,children:[e.jsx(so,{size:13})," ",t("vm.setup.recreate")]}):e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("vm.setup.prepareFirst")})]}):n?.container==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(n.stop_reason==="idle"?"vm.stopped.idle":"vm.stopped.detail")}),e.jsx(qe,{action:"start",pending:c,onClick:()=>{He("start")},children:t("vm.setup.start")})]}):n?.container==="running"?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:13,className:"animate-spin"})," ",t("vm.setup.waiting")]}):n?.image?e.jsxs(e.Fragment,{children:[e.jsx(qe,{action:"run",pending:c,onClick:()=>{He("run")},children:t("vm.setup.start")}),e.jsx("p",{className:"text-[13px] leading-relaxed text-ink-secondary",children:t("vm.setup.idleHint")})]}):null,Te?.run&&e.jsxs("details",{className:"text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:t("vm.setup.showCommand")}),e.jsx("div",{className:"mt-2",children:e.jsx(rt,{command:Te.run})})]})]})]})}),Ne&&e.jsx(Cm,{instances:y,maxInstances:n?.max_instances??g,runningInstances:n?.running_instances,powerPending:I,onPower:(O,F)=>{Rr(O,F)},loading:S,deletingBotId:j,error:w,unavailableReason:v,onRefresh:()=>J(O=>O+1),onDelete:O=>{Br(O)}}),Qs&&e.jsx(Y,{children:e.jsxs("div",{className:"flex gap-2 text-[13px] text-ink-secondary",children:[e.jsx(Oe,{size:15,className:"mt-0.5 shrink-0 text-warning"}),e.jsx("span",{children:t("vm.inspectFailed")})]})}),e.jsxs(Y,{title:t("vm.safety.title"),subtitle:Ne?t("vm.safety.perBot",{path:n?.workspace_guest_path??"/home/cua/workspace"}):t("vm.safety.shared",{path:n?.workspace_guest_path??"/home/cua/workspace"}),children:[Xs&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?.container==="running"&&e.jsxs(qe,{action:"stop",pending:c,onClick:()=>{He("stop")},children:[e.jsx(no,{size:12})," ",t("vm.safety.stop")]}),e.jsxs(qe,{action:"remove",pending:c,onClick:()=>{He("remove")},danger:!0,children:[e.jsx(Ee,{size:12})," ",Ne?t("vm.safety.deleteLegacy"):t("vm.safety.deleteVm")]})]}),e.jsxs("div",{className:"mt-3 break-all text-[11px] text-ink-secondary",children:[t("vm.safety.workspace",{path:n?.workspace_path??t("vm.safety.notCreated"),driver:n?.driver_version??"0.37.0",image:n?.image_ref??t("vm.safety.notPrepared")}),n?.base_image_ref?e.jsxs(e.Fragment,{children:[" · ",t("vm.safety.baseImage",{image:n.base_image_ref})]}):null]})]})]})]})}function Pm({profileEmail:s="",focusRequest:n=0,simple:a=!1}){return e.jsx(ao,{})}function Tm(s){const n=s.trim().toLowerCase();return!n||/\s/.test(n)?null:n.startsWith("@")?/^@[^@\s]+\.[^@\s]+$/.test(n)?n:null:/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(n)?n:null}function _n(s,n,a){const i=s.admins.filter(c=>c!==n),r=s.members.filter(c=>c!==n);return a==="admin"?{admins:[...i,n],members:r}:{admins:i,members:[...r,n]}}function Rm(s,n){return{admins:s.admins.filter(a=>a!==n),members:s.members.filter(a=>a!==n)}}function $n(s,n){const a=s.replace(/\/+$/,"");return n.startsWith("@")?`${a}/pair`:`${a}/pair?email=${encodeURIComponent(n)}`}function Lm(s,n,a){const i=[],r=new Set,c=(o,d)=>{const m=o.trim().toLowerCase();if(!m||r.has(m))return;r.add(m);const u=n.filter(p=>p.email?.toLowerCase()===m),x=a.find(p=>p.key===`user:${m}`);i.push({entry:m,role:d,isDomain:m.startsWith("@"),lastSeenAt:u.length?Math.max(...u.map(p=>p.lastSeenAt)):null,devices:u.length,turns:x?.turns??0,costUsd:x?.costUsd??null,...ot(x?.estimatedUsd)&&x.estimatedUsd>0?{estimated:!0}:{}})};for(const o of s.admins)c(o,"admin");for(const o of s.members)c(o,"member");return i}function Bm(s,n){const a=new Map;for(const i of s){const r=i.email?.trim().toLowerCase();r&&a.set(r,[...a.get(r)??[],i])}return[...a.entries()].map(([i,r])=>{const c=n.find(o=>o.key===`user:${i}`);return{entry:i,role:r.some(o=>o.scopes?.includes("admin"))?"admin":"member",isDomain:!1,lastSeenAt:Math.max(...r.map(o=>o.lastSeenAt)),devices:r.length,turns:c?.turns??0,costUsd:c?.costUsd??null}}).sort((i,r)=>i.role===r.role?i.entry.localeCompare(r.entry):i.role==="admin"?-1:1)}function Om(s,n=Date.now()){return s===null?t("people.never"):n-s<1440*6e4?t("people.today"):new Date(s).toISOString().slice(0,10)}function Ui({people:s,busy:n,onRole:a,onRemove:i,onLink:r,readOnly:c=!1}){if(s.length===0)return e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t(c?"people.portal.empty":"people.empty")});const o="grid grid-cols-[1fr_auto_auto_auto_auto] items-center gap-x-4";return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:z(o,"border-b border-hairline/40 pb-2 text-[12px] font-medium uppercase tracking-wide text-ink-secondary"),children:[e.jsx("span",{children:t("people.colPerson")}),e.jsx("span",{children:t("people.colRole")}),e.jsx("span",{className:"text-right",children:t("people.colLastSeen")}),e.jsx("span",{className:"text-right",children:t("people.colMonth")}),e.jsx("span",{})]}),s.map(d=>e.jsxs("div",{className:z(o,"border-b border-hairline/20 py-2 text-[13px]"),children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-ink",children:d.isDomain?t("people.everyoneAt",{domain:d.entry.slice(1)}):d.entry}),d.devices>0&&e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:t("people.devices",{count:String(d.devices)})})]}),e.jsx("span",{className:z("rounded-full px-2 py-0.5 text-[11px] font-medium",d.role==="admin"?"bg-accent/15 text-accent":"bg-control text-ink-secondary"),children:d.role==="admin"?t("people.roleAdmin"):t("people.roleMember")}),e.jsx("span",{className:"text-right tabular-nums text-ink-secondary",children:d.isDomain?"—":Om(d.lastSeenAt)}),e.jsx("span",{className:"text-right tabular-nums text-ink",title:t("people.turns",{turns:String(d.turns)}),children:ot(d.costUsd)?`${d.estimated?"~":""}${ct(d.costUsd)}`:"—"}),c?e.jsx("span",{}):e.jsxs("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:[e.jsx("button",{type:"button",disabled:n,onClick:()=>r(d),"aria-label":t("people.link"),title:t("people.link"),className:"rounded-md p-1 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(io,{size:13})}),e.jsx("button",{type:"button",disabled:n,onClick:()=>a(d,d.role==="admin"?"member":"admin"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:d.role==="admin"?t("people.makeMember"):t("people.makeAdmin")}),e.jsx("button",{type:"button",disabled:n,onClick:()=>i(d),className:"text-danger hover:underline disabled:opacity-50",children:t("people.remove")})]})]},d.entry))]})}function Fi({link:s}){const{state:n,copy:a}=Cs(s);return e.jsxs("div",{className:"mt-3 rounded-lg border border-hairline/40 bg-inset p-3 text-[13px]",children:[e.jsx("div",{className:"mb-1 text-ink-secondary",children:t("people.link")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 select-all break-all text-ink",children:s}),e.jsxs("button",{type:"button",onClick:a,className:"flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control hover:text-ink",children:[n==="copied"?e.jsx(ge,{size:13,className:"text-success"}):n==="failed"?e.jsx($e,{size:13,className:"text-danger"}):e.jsx(Aa,{size:13}),t(n==="copied"?"people.copied":n==="failed"?"common.copyFailed":"people.copy")]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.linkHint")})]})}function Mm({peopleUrl:s,people:n}){const a=()=>{};return e.jsxs(Y,{title:t("people.title"),subtitle:t("people.portal.subtitle"),children:[e.jsxs("div",{"data-people-portal":!0,className:"flex flex-col gap-3 text-[13px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:t("people.portal.managed")}),s&&e.jsxs("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"flex w-fit items-center gap-2 rounded-lg bg-control px-3 py-2 font-medium text-ink hover:bg-control/70",children:[t("people.portal.open")," ",e.jsx(pt,{size:14,"aria-hidden":"true"})]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(Ui,{people:n,busy:!1,readOnly:!0,onRole:a,onRemove:a,onLink:a})}),e.jsx("p",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("people.portal.note")})]})}function Di({simple:s=!1,startOpen:n=!1}){const[a,i]=l.useState(n),[r,c]=l.useState(!1),[o,d]=l.useState(null),[m,u]=l.useState(null),[x,p]=l.useState(null),[h,f]=l.useState([]),[y,b]=l.useState(typeof window<"u"?window.location.origin:""),[g,k]=l.useState(null),[S,C]=l.useState(""),[w,P]=l.useState("member"),[v,B]=l.useState(null),[j,A]=l.useState(!1),[I,_]=l.useState(!1),[U,J]=l.useState(null),K=l.useCallback(async()=>{_(!0),J(null);try{const[T,Z,ee,fe,N]=await Promise.all([M("/api/config"),M("/api/auth/sessions").catch(()=>({sessions:[]})),M("/api/usage?groupBy=user").catch(()=>({groups:[]})),M("/api/settings/custom-domain").catch(()=>null),fetch("/.well-known/openmausbot/environment").then(ie=>ie.ok?ie.json():null).catch(()=>null)]),re={admins:Array.isArray(T?.signIn?.admins)?T.signIn.admins:[],members:Array.isArray(T?.signIn?.members)?T.signIn.members:[]},se=dd(T);u(se),p(re);const ne=Array.isArray(Z?.sessions)?Z.sessions:[],G=Array.isArray(ee?.groups)?ee.groups:[];f(se.authority==="portal"?Bm(ne,G):Lm(re,ne,G)),typeof fe?.publicUrl=="string"&&fe.publicUrl&&b(fe.publicUrl),k(N?.capabilities?.emailSignIn===!0?!0:N?!1:null)}catch(T){J(T instanceof Error?T.message:String(T))}finally{_(!1)}},[]);l.useEffect(()=>{ud().then(T=>{d(T),un(T)&&K()})},[K]);const te=async T=>{A(!0),J(null);try{await M("/api/config",{method:"PUT",body:JSON.stringify({signIn:T})}),await K()}catch(Z){J(Z instanceof Error?Z.message:String(Z))}finally{A(!1)}},ae=async()=>{if(c(!0),!x||j)return;const T=Tm(S);if(!T){J(t("remote.signInAccess.invalid"));return}await te(_n(x,T,w)),C(""),B($n(y,T))};if(!un(o))return null;const de=m?.authority==="portal"?e.jsx(Mm,{peopleUrl:m.peopleUrl,people:h}):null,D=e.jsxs(e.Fragment,{children:[g===!1&&(!s||r)&&e.jsx("p",{className:"mb-3 rounded-lg border border-warning/25 bg-warning/5 px-3 py-2 text-[13px] text-ink-secondary",children:t(m?.pairingCodes===!1?"people.portalSignIn":"people.notHosted")}),e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:T=>{T.preventDefault(),ae()},children:[e.jsx("input",{value:S,onChange:T=>C(T.target.value),placeholder:t("remote.signInAccess.placeholder"),"aria-label":t("people.inviteEmail"),disabled:j,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs(xe,{value:w,onChange:T=>P(T.target.value),"aria-label":t("people.colRole"),disabled:j,children:[e.jsx("option",{value:"member",children:t("people.roleMember")}),e.jsx("option",{value:"admin",children:t("people.roleAdmin")})]}),e.jsxs("button",{type:"submit",disabled:j||!S.trim(),className:"ui-button ui-button-primary",children:[j?e.jsx(X,{size:13,className:"animate-spin"}):e.jsx(Ce,{size:13}),t("people.invite")]}),e.jsx("button",{type:"button",onClick:()=>{K()},disabled:I||j,"aria-label":t("people.refresh"),title:t("people.refresh"),className:"rounded-md p-1.5 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:e.jsx(Se,{size:13,className:z(I&&"animate-spin")})})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("people.inviteHint")}),v&&e.jsx(Fi,{link:v}),U&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:U}),e.jsx("div",{className:"mt-4",children:e.jsx(Ui,{people:h,busy:j,onRole:(T,Z)=>{x&&te(_n(x,T.entry,Z))},onRemove:T=>{x&&te(Rm(x,T.entry))},onLink:T=>B($n(y,T.entry))})}),!s&&e.jsx("p",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:t("people.note")})]});return s?e.jsxs("div",{"data-people-summary":"",children:[e.jsxs("div",{role:"group","aria-label":t("people.title"),className:"flex min-w-0 items-center gap-3 px-4 py-[13px]",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-11 shrink-0 items-center justify-center rounded-full bg-ink/[0.06] text-ink-secondary",children:e.jsx(Ct,{size:20})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:t("people.title")}),e.jsx("div",{className:"text-[13px] leading-[18px] text-ink-secondary",children:t("settings.simple.people")})]}),e.jsx("button",{type:"button","aria-expanded":a,className:"ui-button shrink-0",onClick:()=>i(!a),children:a?t("common.done"):t("settings.simple.people.invite")})]}),a&&e.jsx("div",{className:"px-3.5 pb-3.5 pt-1",children:de??D})]}):de??e.jsx(Y,{title:t("people.title"),subtitle:t("people.subtitle"),children:D})}const as="rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none [color-scheme:dark]";function zm({entry:s}){const[n,a]=l.useState(!1),i=s.type==="admin"&&(s.changed?.length||s.before||s.after);return e.jsx("li",{className:"border-b border-hairline/20 py-2 text-[13px]","data-activity-entry":s.type,children:e.jsxs("div",{className:"grid grid-cols-[auto_1fr] items-start gap-x-3",children:[e.jsx("time",{className:"whitespace-nowrap tabular-nums text-ink-secondary",dateTime:s.at,children:new Date(s.at).toLocaleString(Ss())}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2",children:[e.jsx("span",{className:"font-medium text-ink",children:kd(s.who)}),e.jsx("span",{className:"min-w-0 break-words text-ink",children:Nd(s)})]}),s.type==="approval"&&s.summary&&e.jsx("div",{className:"mt-0.5 truncate text-[12px] text-ink-secondary",children:ro(s.summaryCode,s.summary,s.summaryParams)}),i&&e.jsxs("button",{type:"button",onClick:()=>a(!n),"aria-expanded":n,className:"cursor-pointer mt-0.5 flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink",children:[e.jsx(Ts,{size:12,className:z("transition-transform",n&&"rotate-90")}),t("activity.changed",{paths:(s.changed??[]).join(", ")||"—"})]}),i&&n&&s.type==="admin"&&e.jsxs("dl",{className:"mt-1 grid grid-cols-[auto_1fr_1fr] gap-x-3 gap-y-0.5 rounded-lg bg-inset p-2 text-[12px]",children:[e.jsx("dt",{}),e.jsx("dd",{className:"text-ink-secondary",children:t("activity.before")}),e.jsx("dd",{className:"text-ink-secondary",children:t("activity.after")}),(s.changed??Object.keys({...s.before,...s.after})).map(r=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"font-mono text-ink-secondary",children:r}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:In(s.before?.[r])}),e.jsx("dd",{className:"min-w-0 break-all font-mono text-ink",children:In(s.after?.[r])})]},r))]})]})]})})}function _i(){const[s,n]=l.useState({who:"",what:"all",from:"",to:""}),[a,i]=l.useState([]),[r,c]=l.useState(0),[o,d]=l.useState(null),[m,u]=l.useState(!1),[x,p]=l.useState(null),h=vd(s),f=l.useCallback(async()=>{u(!0),p(null);try{const b=await M(`/api/admin-activity${h}`);i(b.entries),c(b.total),d(b.retentionDays)}catch(b){p(b instanceof Error?b.message:String(b))}finally{u(!1)}},[h]);l.useEffect(()=>{const b=window.setTimeout(()=>{f()},250);return()=>window.clearTimeout(b)},[f]);const y=b=>n(g=>({...g,...b}));return e.jsxs(Y,{title:t("activity.title"),subtitle:t("activity.subtitle",{days:String(o??180)}),children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.who"),e.jsx("input",{value:s.who,onChange:b=>y({who:b.target.value}),placeholder:t("activity.whoPlaceholder"),className:z(as,"w-44")})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.what"),e.jsx(xe,{value:s.what,onChange:b=>y({what:b.target.value}),children:jd.map(b=>e.jsx("option",{value:b,children:t(`activity.what.${b}`)},b))})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.from"),e.jsx("input",{type:"date",value:s.from,max:s.to||void 0,onChange:b=>y({from:b.target.value}),className:as})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("activity.to"),e.jsx("input",{type:"date",value:s.to,min:s.from||void 0,onChange:b=>y({to:b.target.value}),className:as})]}),e.jsx("button",{type:"button",onClick:()=>{f()},disabled:m,"aria-label":t("activity.refresh"),title:t("activity.refresh"),className:"cursor-pointer rounded-md p-2 text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:m?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(Se,{size:14})}),e.jsxs("a",{href:`/api/admin-activity.csv${h}`,download:!0,className:"ui-button hover:bg-raised-hover",children:[e.jsx(Ye,{size:13,"aria-hidden":"true"}),t("activity.export")]})]}),x&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("activity.error",{message:x})}),!x&&a.length===0&&!m&&e.jsx("p",{className:"mt-4 text-[13px] text-ink-secondary",children:t("activity.empty")}),a.length>0&&e.jsx("ul",{className:"mt-3 flex flex-col",children:a.map((b,g)=>e.jsx(zm,{entry:b},`${b.at}-${g}`))}),r>a.length&&e.jsx("p",{className:"mt-3 text-[12px] text-ink-secondary",children:t("activity.more",{shown:String(a.length),total:String(r)})})]})}const Kn=4,$s="flex w-full min-w-0 items-center gap-3 px-3 py-2 text-start",Ks="flex flex-col divide-y divide-hairline/30 overflow-hidden rounded-xl border border-hairline/40 bg-card",Um=s=>s.filter(n=>!n.hidden&&!n.defaultBot?.person).sort((n,a)=>n.name.localeCompare(a.name)),$i=(s,n)=>Ut(s)===n||Wa(Ft(s),n)!=="none",Ki=(s,n)=>{const a=Ka(s,n);return a?t("lookedAfter.line",{name:a.name}):t("lookedAfter.nobody")},Hn=(s,...n)=>n.some(a=>a?.toLowerCase().includes(s));function Fm(){const{state:s}=W(),n=lo(),a=oo(),i=l.useRef(null),[r,c]=l.useState("bot"),[o,d]=l.useState(""),[m,u]=l.useState(null),[x,p]=l.useState(null),h=l.useRef(null),[f,y]=l.useState(null),[b,g]=l.useState(""),k=l.useCallback(()=>y(null),[]);if(l.useEffect(()=>{x||!h.current||([...i.current?.querySelectorAll("[data-access-person]")??[]].find(j=>j.dataset.accessPerson===h.current)?.focus(),h.current=null)},[x]),!n||!a)return null;const S=n.people.filter(j=>j.role==="member").sort((j,A)=>j.name.localeCompare(A.name)),C=Um(s.bots),w=m?C.find(j=>j.id===m):void 0,P=x?S.find(j=>j.email===x):void 0,v=o.trim().toLowerCase(),B=async(j,A,I)=>{g("");const _=Ft(j);try{await mn(j.id,A),y({botId:j.id,before:_,after:A,text:I})}catch(U){g(U instanceof Error?U.message:String(U))}};return e.jsxs("div",{ref:i,className:"flex min-w-0 flex-col gap-3","data-access-overview":!0,children:[P?e.jsx(Km,{person:P,bots:C.filter(j=>$i(j,P.email)),team:n,teamName:a,apply:B,onBack:()=>{h.current=P.email,p(null)}}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"ps-4 text-[13px] leading-relaxed text-ink-secondary",children:t("botAccess.overview.introUse",{team:a})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative min-w-[180px] flex-1",children:[e.jsx(mt,{size:14,"aria-hidden":"true",className:"pointer-events-none absolute start-2.5 top-1/2 -translate-y-1/2 text-ink-secondary"}),e.jsx("input",{type:"search",value:o,"data-access-search":!0,"aria-label":t(r==="bot"?"botAccess.overview.searchBots":"botAccess.overview.searchPeople"),placeholder:t(r==="bot"?"botAccess.overview.searchBots":"botAccess.overview.searchPeople"),onChange:j=>d(j.target.value),onKeyDown:j=>{j.key==="Escape"&&o&&(j.preventDefault(),d(""))},className:"w-full rounded-lg border border-hairline/50 bg-transparent py-1.5 pe-2.5 ps-8 text-[13px] text-ink placeholder:text-ink-secondary focus:border-focus focus:outline-none"})]}),e.jsx("div",{role:"group","aria-label":t("botAccess.overview.listBy"),className:"flex shrink-0 rounded-full bg-raised/70 p-0.5",children:["bot","person"].map(j=>e.jsx("button",{type:"button","aria-pressed":r===j,"data-access-listing":j,onClick:()=>{c(j),d("")},className:z("rounded-full px-3 py-1 text-[13px] leading-[18px]",r===j?"bg-menu font-medium text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(j==="bot"?"botAccess.overview.byBot":"botAccess.overview.byPerson")},j))})]}),r==="bot"?e.jsx(Dm,{bots:C.filter(j=>!v||Hn(v,j.name,Ka(j,n)?.name,Ut(j)??void 0)),anyBots:C.length>0,team:n,onOpen:u}):e.jsx($m,{people:S.filter(j=>!v||Hn(v,j.name,j.email)),anyPeople:S.length>0,bots:C,onOpen:p}),e.jsx("p",{className:"ps-4 text-[12px] text-ink-secondary",children:t("botAccess.admins")})]}),b&&e.jsx("p",{role:"alert",className:"text-[13px] text-danger",children:b}),w&&e.jsx(co,{bot:w,teamName:a,onClose:()=>u(null),onChanged:j=>y({botId:w.id,...j})}),f&&e.jsx(uo,{text:f.text,onUndo:()=>mn(f.botId,f.before),onDone:k},`${f.botId}:${f.text}:${JSON.stringify(f.after)}`)]})}function Dm({bots:s,anyBots:n,team:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:Ks,children:s.map(r=>{const c=Ft(r),o=Ut(r);return e.jsx("li",{className:"min-w-0",children:e.jsxs("button",{type:"button","aria-haspopup":"dialog","data-access-row":r.id,onClick:()=>i(r.id),className:z($s,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Bt,{bot:r,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] leading-[18px] text-ink",children:r.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:Ki(r,a)})]}),e.jsx("span",{className:"min-w-0 max-w-[40%] truncate text-[13px] text-ink-secondary","data-access-summary":!0,children:c.everyone==="none"?t("botAccess.onlyAdded"):t("botAccess.overview.everyoneUses")}),e.jsx(_m,{entries:Object.keys(c.people).filter(d=>d!==o),team:a})]})},r.id)})}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noBotMatch")}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noBots")})}function _m({entries:s,team:n}){if(!s.length)return null;const a=s.map(r=>po(r,n)).join(", "),i=s.length-Kn;return e.jsxs("span",{role:"img","aria-label":a,title:a,"data-access-stack":s.length,className:"flex shrink-0 -space-x-0.5 rtl:space-x-reverse",children:[s.slice(0,Kn).map(r=>e.jsx("span",{className:"flex rounded-full ring-2 ring-card",children:e.jsx(xo,{person:ho(r,n),size:22})},r)),i>0&&e.jsxs("span",{className:"flex h-[22px] min-w-[22px] items-center justify-center rounded-full bg-card px-1 text-[11px] font-medium text-ink-secondary ring-2 ring-card",children:["+",i]})]})}function $m({people:s,anyPeople:n,bots:a,onOpen:i}){return n?s.length?e.jsx("ul",{className:Ks,children:s.map(r=>{const c=a.filter(o=>$i(o,r.email)).length;return e.jsx("li",{className:"min-w-0",children:e.jsxs("button",{type:"button","data-access-person":r.email,onClick:()=>i(r.email),className:z($s,"hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06] focus-visible:outline-none"),children:[e.jsx(Ha,{person:r,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] leading-[18px] text-ink",children:r.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:r.email})]}),e.jsx("span",{className:"shrink-0 text-[13px] text-ink-secondary",children:c===1?t("botAccess.overview.botCount.one"):t("botAccess.overview.botCount.other",{count:c})})]})},r.email)})}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.noMatch")}):e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("botAccess.overview.noPeople")})}function Km({person:s,bots:n,team:a,teamName:i,apply:r,onBack:c}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsxs("button",{type:"button",autoFocus:!0,"data-access-back":!0,onClick:c,className:"-ms-2 flex items-center gap-1 rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-ink/[0.06] hover:text-ink",children:[e.jsx(zr,{size:14,"aria-hidden":"true",className:"rtl:-scale-x-100"}),t("botAccess.overview.allPeople")]})}),e.jsxs("div",{className:"flex min-w-0 items-center gap-3 px-3",children:[e.jsx(Ha,{person:s,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] font-medium leading-[18px] text-ink",children:s.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:s.email})]})]}),n.length===0?e.jsx("p",{className:"px-3 text-[13px] text-ink-secondary",children:t("botAccess.overview.noBotsForPerson",{name:s.name})}):e.jsx("ul",{className:Ks,children:n.map(o=>e.jsx(Hm,{bot:o,person:s,team:a,teamName:i,apply:r},o.id))})]})}function Hm({bot:s,person:n,team:a,teamName:i,apply:r}){const c=Ft(s),o=Ut(s)===n.email,d=c.people[n.email],m=Wa(c,n.email);return e.jsxs("li",{className:$s,"data-access-person-bot":s.id,children:[e.jsx(Bt,{bot:s,size:32}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[14px] leading-[18px] text-ink",children:s.name}),e.jsx("span",{className:"block truncate text-[12px] leading-4 text-ink-secondary",children:!d&&!o&&m===c.everyone?t("botAccess.everyoneUse",{team:i}):Ki(s,a)})]}),e.jsx("span",{className:"min-w-0 shrink-0 text-[13px] text-ink-secondary",children:o?e.jsx("span",{className:"px-2",children:t("lookedAfter.badge")}):d?e.jsx("button",{type:"button","data-access-remove":s.id,"aria-label":t("botAccess.overview.removeFrom",{name:n.name,bot:s.name}),onClick:()=>{r(s,mo(c,n.email,null),t("botAccess.overview.toastRemoved",{name:n.name,bot:s.name}))},className:"rounded-md px-2 py-1 hover:bg-ink/[0.06] hover:text-ink",children:t("botAccess.remove")}):null})]})}function Wm(s){const n=s.trim();if(!n||/[\s\\?#@%]/.test(n))return null;try{const a=new URL(n.includes("://")?n:`https://${n}`),i=a.hostname.replace(/\.$/,"");return a.protocol!=="https:"||a.port||a.pathname!=="/"||!i.includes(".")||i.length>253||/^[\d.]+$/.test(i)||!i.split(".").every(r=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(r))||/(?:^|\.)(?:localhost|local|internal|invalid|test)$/.test(i)?null:i}catch{return null}}function Gm({domain:s,serverIpv4:n}){const a=Wm(s);if(!a)return e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("settings.domain.enterDomain")});const i=[[t("settings.domain.recordType"),"A"],[t("settings.domain.recordName"),a],[t("settings.domain.recordValue"),n]];return e.jsxs("section",{"aria-label":t("settings.domain.dnsRecord"),className:"space-y-2 rounded-lg border border-hairline/50 p-3",children:[e.jsx("p",{className:"text-[12px] font-medium text-ink",children:t("settings.domain.dnsRecord")}),e.jsx("dl",{className:"space-y-2",children:i.map(([r,c])=>e.jsxs("div",{className:"grid grid-cols-[80px_minmax(0,1fr)] items-center gap-2",children:[e.jsx("dt",{className:"text-[12px] text-ink-secondary",children:r}),e.jsx("dd",{className:"min-w-0",children:c?e.jsx(rt,{command:c,copyLabel:t("settings.domain.copyField",{field:r})},c):e.jsx("p",{className:"text-[12px] text-warning",children:t("settings.domain.missingIp")})})]},r))}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.domain.recordHint")})]})}function Vm(s){return`bots.example.com {
|
|
2
2
|
handle /hooks/* {
|
|
3
3
|
reverse_proxy 127.0.0.1:${s.webhookPort}
|
|
4
4
|
}
|
|
@@ -16,4 +16,4 @@ Vẫn cài đặt (kỹ năng sẽ ở trạng thái tắt)?`,`WARNING: "${N.nam
|
|
|
16
16
|
Installing is not recommended. This skill may contain malware or dangerous commands. Only install it if you understand the risk and trust ${N.source.repository??"the source"}.
|
|
17
17
|
|
|
18
18
|
Install anyway (the skill will stay switched off)?`))&&J(N.id,()=>Ie("/api/limix/hub/install",{id:N.id,allowRisky:!0}))},ee=N=>{!N.enabled&&N.risky&&!window.confirm(L(`"${N.name}" bị cách ly (${N.risky}). Vẫn bật cho bot dùng?`,`"${N.name}" is quarantined (${N.risky}). Switch it on for bots anyway?`))||J(N.id,()=>Ie("/api/limix/hub/enable",{id:N.id,enabled:!N.enabled}))},fe=N=>{const re=N.description_vi||N.description,se=j===N.id,ne=(N.permissions.runs_code||N.permissions.mcp)&&!N.blocked;return e.jsx("li",{className:"px-4 py-4",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{className:"font-mono text-[14px] font-semibold text-ink",children:N.name}),e.jsxs("span",{className:`rounded-md px-1.5 py-0.5 text-[11px] font-medium ${D[N.grade]??"bg-ink/10 text-ink-secondary"}`,children:[N.quality_score,"/100 · ",px(N.grade)??N.grade]}),typeof N.stars=="number"&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[12px] text-ink-secondary",children:[e.jsx(oc,{size:12}),N.stars.toLocaleString(L("vi-VN","en-US"))]})]}),e.jsx("p",{className:`mt-1 text-[12.5px] leading-relaxed text-ink-secondary ${se?"":"line-clamp-3"}`,children:re}),re.length>220&&e.jsx("button",{type:"button",className:"mt-0.5 text-[12px] text-ink underline-offset-2 hover:underline",onClick:()=>A(se?null:N.id),children:se?L("Thu gọn","Show less"):L("Xem thêm","Show more")}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:T,children:xx(N.kind)??N.kind}),e.jsxs("span",{className:`${T} ${N.security_status==="clean"?"":N.security_status==="quarantined"?"!bg-danger/15 !text-danger":"!bg-amber-500/15 !text-amber-500"}`,children:[L("Bảo mật","Security"),": ",rs(N.security_status)??N.security_status]}),e.jsx("span",{className:T,children:N.license??L("Chưa có giấy phép","No license")}),N.dependencies.length>0&&e.jsxs("span",{className:T,children:[L("Cần","Needs"),": ",N.dependencies.join(", ")]})]}),e.jsxs("p",{className:"mt-1.5 text-[11px] leading-relaxed text-ink-tertiary",children:[N.source.repository??L("Không rõ nguồn","Unknown source"),N.added_at&&L(` · Thêm vào kho ${Ue(N.added_at)}`,` · Added to catalog ${Ue(N.added_at)}`),N.created_at&&L(` · Tạo ${Ue(N.created_at)}`,` · Created ${Ue(N.created_at)}`),N.pushed_at&&L(` · Cập nhật ${Ue(N.pushed_at)}`,` · Updated ${Ue(N.pushed_at)}`),N.stats_checked&&L(` · số sao đo ngày ${Ue(N.stats_checked)}`,` · stars measured ${Ue(N.stats_checked)}`)]}),N.risky&&e.jsxs("p",{className:"mt-2 flex items-start gap-1.5 rounded-lg bg-danger/10 p-2 text-[12px] leading-relaxed text-danger",children:[e.jsx(fn,{size:14,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:[N.risky," ",L("Không khuyến khích cài.","Installing is not recommended.")]})]}),N.blocked&&e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-[12px] text-danger",children:[e.jsx(fn,{size:13}),N.blocked]}),ne&&e.jsxs("div",{className:"mt-2 rounded-lg border border-hairline/40 bg-raised/50 p-2.5 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("button",{type:"button",className:"text-ink underline-offset-2 hover:underline",onClick:()=>B(v===N.id?null:N.id),children:v===N.id?L("Ẩn hướng dẫn cài đặt","Hide install guide"):L("Kỹ năng này có tool: xem hướng dẫn cài đặt","This skill has tools: see the install guide")}),v===N.id&&e.jsxs("ol",{className:"mt-2 list-decimal space-y-1.5 pl-4",children:[e.jsx("li",{children:L(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Cài kỹ năng:"}),' bấm "Cài đặt". Mặc định chỉ lấy phần hướng dẫn (SKILL.md). Kỹ năng được tải từ GitHub và kiểm tra SHA-256 từng file.']}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Install the skill:"}),' press "Install". By default only the instructions (SKILL.md) are taken. The skill is downloaded from GitHub and every file is checked with SHA-256.']}))}),N.compatibility.runtimes.length>0&&e.jsxs("li",{children:[e.jsxs("b",{className:"text-ink",children:[L("Chuẩn bị máy","Prepare this computer"),":"]})," ",L("kỹ năng cần","the skill needs")," ",N.compatibility.runtimes.map(G=>G.name).join(", "),".",N.compatibility.runtimes.filter(G=>G.installerId).length>0&&e.jsxs(e.Fragment,{children:[" ",L("Limix Bot cài được","Limix Bot can install"),": ",N.compatibility.runtimes.filter(G=>G.installerId).map(G=>G.name).join(", "),". "]}),N.compatibility.runtimes.some(G=>!G.installerId)&&e.jsxs(e.Fragment,{children:[" ",L("Phải cài tay","Install by hand"),": ",N.compatibility.runtimes.filter(G=>!G.installerId).map(G=>G.name).join(", ")," (",L('Python: tải từ python.org, tick "Add python.exe to PATH"','Python: download from python.org, tick "Add python.exe to PATH"'),"). "]}),Xa()&&e.jsx("button",{type:"button",className:"ml-1 text-ink underline",onClick:()=>P(!0),children:L('Mở "Công cụ cho kỹ năng"','Open "Tools for skills"')})]}),N.permissions.runs_code&&e.jsx("li",{children:L(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Cài phần script:"}),' bấm "Cài đặt kèm tool". Các file script nằm trong thư mục kỹ năng và bot có thể chạy chúng. Chỉ làm khi bạn tin nguồn ',N.source.repository??"này"," (đã quét: ",rs(N.security_status)??N.security_status,")."]}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Install the scripts:"}),' press "Install with tools". The script files go in the skill folder and the bot can run them. Only do this if you trust ',N.source.repository??"the source"," (scanned: ",rs(N.security_status)??N.security_status,")."]}))}),N.permissions.mcp&&e.jsx("li",{children:L(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"MCP:"})," file cấu hình MCP chỉ được chép vào thư mục kỹ năng, không tự bật. Muốn dùng, thêm máy chủ MCP ở Cài đặt rồi bật."]}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"MCP:"})," the MCP config file is only copied into the skill folder and is not switched on. To use it, add the MCP server in Settings and turn it on."]}))}),e.jsx("li",{children:L(e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Bật:"}),' sau khi cài, gạt công tắc "Đang tắt" sang bật, rồi mở cài đặt của bot → Kỹ năng để thêm.']}),e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-ink",children:"Switch on:"}),' after installing, flip the "Off" switch to on, then add it in the bot’s Settings → Skills.']}))})]})]}),a==="security"&&N.security_findings?.slice(0,5).map((G,ie)=>e.jsxs("p",{className:"text-[11px] text-ink-tertiary",children:[G.severity," · ",G.rule," · ",G.file,G.line?`:${G.line}`:""]},ie)),N.notes.map(G=>e.jsx("p",{className:"mt-0.5 text-[11px] text-ink-tertiary",children:G},G))]}),e.jsx("div",{className:"flex shrink-0 flex-row flex-wrap items-center gap-2 sm:w-[168px] sm:flex-col sm:items-stretch",children:r===N.id?e.jsx(X,{size:15,className:"animate-spin text-ink-secondary sm:self-end"}):N.installed?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center justify-between gap-2 text-[12px] text-ink-secondary",children:[N.enabled?L("Đang bật","On"):L("Đang tắt","Off"),e.jsx(me,{checked:N.enabled,disabled:r!==null,onClick:()=>ee(N)})]}),N.updateAvailable&&e.jsxs("button",{type:"button",className:`${we} justify-center`,disabled:r!==null,onClick:()=>{J(N.id,()=>Ie("/api/limix/hub/update",{id:N.id,allowRisky:!!N.risky}))},children:[e.jsx(Se,{size:14}),L("Cập nhật","Update")]}),e.jsxs("button",{type:"button",className:`${we} justify-center`,disabled:r!==null,onClick:()=>{J(N.id,()=>Ie("/api/limix/hub/remove",{id:N.id}))},children:[e.jsx(Ee,{size:14}),L("Gỡ","Remove")]})]}):e.jsxs(e.Fragment,{children:[N.risky?e.jsxs("button",{type:"button",className:`${we} justify-center !border-danger/40 !text-danger`,disabled:!!N.blocked||r!==null,onClick:()=>Z(N),children:[e.jsx(Ye,{size:14}),L("Cài đặt (không khuyến khích)","Install (not recommended)")]}):e.jsxs("button",{type:"button",className:`${we} justify-center`,disabled:!!N.blocked||r!==null,onClick:()=>{J(N.id,()=>Ie("/api/limix/hub/install",{id:N.id}))},children:[e.jsx(Ye,{size:14}),L("Cài đặt","Install")]}),N.permissions.runs_code&&!N.blocked&&!N.risky&&e.jsxs("button",{type:"button",className:`${we} justify-center`,disabled:r!==null,onClick:()=>{window.confirm(L(`Cài cả script của "${N.name}"? Bot có thể chạy các script này. Chỉ làm khi bạn tin nguồn.`,`Install the scripts of "${N.name}" too? Bots can run these scripts. Only do this if you trust the source.`))&&J(N.id,()=>Ie("/api/limix/hub/install",{id:N.id,allowTools:!0}))},children:[e.jsx(Ye,{size:14}),L("Cài đặt kèm tool","Install with tools")]})]})})]})},N.id)};return e.jsxs(Y,{title:L("Kho kỹ năng Limix","Limix Skill Catalog"),subtitle:L("Các kỹ năng trong kho đã được quét bảo mật và chấm điểm. Sau khi cài, mở cài đặt của bot → Kỹ năng → Kho kỹ năng để thêm kỹ năng cho bot đó.","Skills that are security-scanned and scored. Once installed, a skill waits in the store and no bot uses it yet: open a bot → Skills → Skills Store to add it to one bot."),children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:mx.map(([N,re])=>{const se=N==="installed"?K.filter(ne=>ne.installed).length:N==="updates"?K.filter(ne=>ne.updateAvailable).length:N==="discover"?K.length:null;return e.jsxs("button",{type:"button",onClick:()=>i(N),className:`rounded-lg px-2.5 py-1 text-[13px] ${a===N?"bg-raised text-ink":"text-ink-secondary hover:bg-raised-hover"}`,children:[re(),se?e.jsx("span",{className:"ml-1 text-[11px] text-ink-tertiary",children:se}):null]},N)})}),o&&e.jsx("p",{className:"text-[12px] text-danger",children:o}),s?a==="settings"?e.jsxs("div",{className:"flex flex-col gap-3 text-[13px] text-ink",children:[e.jsxs("label",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{children:[L("Tự đồng bộ danh mục","Sync the catalog automatically"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:L("Chỉ cập nhật danh sách, không cài gì.","Only refreshes the list, installs nothing.")})]}),e.jsx(me,{checked:s.settings.autoSync,onClick:()=>{J("settings",()=>Ie("/api/limix/hub/settings",{autoSync:!s.settings.autoSync}))}})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{children:[L("Tự cài kỹ năng mới","Install new skills automatically"),e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:L("Mặc định tắt. Nếu bật: chỉ cài loại chỉ có hướng dẫn, đã duyệt, điểm từ 80; vẫn ở trạng thái tắt.","Off by default. When on: only instruction-only skills that are approved and score 80 or more are installed, and they stay switched off.")})]}),e.jsx(me,{checked:s.settings.autoInstall,onClick:()=>{J("settings",()=>Ie("/api/limix/hub/settings",{autoInstall:!s.settings.autoInstall}))}})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("input",{value:m,onChange:N=>u(N.target.value),placeholder:L("Tìm kỹ năng…","Search skills…"),className:"min-w-[160px] flex-1 rounded-lg border border-hairline/60 bg-card px-3 py-1.5 text-[13px] text-ink"}),e.jsxs("select",{"aria-label":L("Chủ đề","Topic"),value:x,onChange:N=>p(N.target.value),className:"rounded-lg border border-hairline/60 bg-card px-2 py-1.5 text-[13px] text-ink",children:[e.jsx("option",{value:"",children:L("Mọi chủ đề","All topics")}),te.map(N=>e.jsx("option",{value:N,children:N},N))]}),e.jsxs("select",{"aria-label":L("Sắp xếp","Sort by"),value:h,onChange:N=>f(N.target.value),className:we,children:[e.jsx("option",{value:"catalog",children:L("Thứ tự trong kho","Catalog order")}),e.jsx("option",{value:"stars",children:L("Nhiều sao nhất","Most stars")}),e.jsx("option",{value:"newest",children:L("Mới thêm nhất","Recently added")})]}),a==="discover"&&e.jsxs("button",{type:"button",className:`${we} shrink-0`,disabled:r!==null,onClick:()=>{de()},children:[r==="sync"?e.jsx(X,{size:14,className:"animate-spin"}):e.jsx(Se,{size:14}),L("Đồng bộ ngay","Sync now")]})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3 text-[12px] text-ink-secondary",children:[e.jsxs("label",{className:"grid gap-1",children:[L("Số sao tối thiểu","Minimum stars"),e.jsx("input",{type:"number",min:"0",step:"1",placeholder:"0",value:y,onChange:N=>b(N.target.validity.valid?N.target.value:""),className:`${we} w-28`})]}),e.jsxs("label",{className:"grid gap-1",children:[L("Thêm vào kho từ ngày","Added from"),e.jsx("input",{type:"date",value:g,max:S||void 0,onChange:N=>k(N.target.value),className:we})]}),e.jsxs("label",{className:"grid gap-1",children:[L("Đến ngày","Added through"),e.jsx("input",{type:"date",value:S,min:g||void 0,onChange:N=>C(N.target.value),className:we})]}),(m||x||y||g||S)&&e.jsx("button",{type:"button",className:we,onClick:()=>{u(""),p(""),b(""),k(""),C("")},children:L("Xóa bộ lọc","Clear filters")})]}),a==="discover"&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-[12px] text-ink-tertiary",role:"status",children:[L("Đồng bộ gần nhất","Last sync"),": ",s.settings.lastSync?new Date(s.settings.lastSync).toLocaleString(L("vi-VN","en-US")):L("chưa lần nào","never")]}),s.settings.lastError&&e.jsxs("p",{className:"text-[12px] text-danger",children:[L("Lỗi đồng bộ gần nhất","Last sync error"),": ",s.settings.lastError]})]}),ae.length===0?e.jsx("p",{className:"text-[13px] text-ink-secondary",children:K.length===0?L("Chưa có danh mục. Mở Khám phá và bấm Đồng bộ ngay.","No catalog yet. Open Discover and press Sync now."):L("Không có kỹ năng nào ở mục này.","No skills in this tab.")}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-[12px] text-ink-tertiary",children:[ae.length," ",L("kỹ năng","skills")]}),e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-xl border border-hairline/40 bg-card",children:ae.slice(0,I).map(fe)}),ae.length>I&&e.jsx("button",{type:"button",className:`${we} w-fit self-center`,onClick:()=>_(N=>N+it),children:L(`Xem thêm ${Math.min(it,ae.length-I)} kỹ năng`,`Show ${Math.min(it,ae.length-I)} more`)})]}),a==="installed"&&ae.length>0&&e.jsxs("p",{className:"flex items-center gap-1 text-[12px] text-ink-tertiary",children:[e.jsx(ge,{size:13}),L("Kỹ năng đã bật nằm trong thư viện bên dưới. Mở cài đặt của từng bot → Kỹ năng để thêm.","Enabled skills are in the library below. Add them from each bot’s Settings → Skills.")]})]}):e.jsx(X,{size:15,className:"animate-spin text-ink-secondary"})]}),w&&e.jsx(Ya,{onClose:()=>P(!1)})]})}function gx(s,n,a){const i=n.trim().toLowerCase();return s.filter(r=>a&&!r.tags.includes(a)?!1:i?[r.name,r.description,r.source].some(c=>c.toLowerCase().includes(i)):!0)}function ar({skill:s}){return e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-ink-secondary",children:[e.jsx("span",{className:"truncate",title:s.source,children:t("skills.source",{source:s.source})}),e.jsx("span",{children:s.version?t("skills.library.version",{version:s.version}):t("skills.library.noVersion")}),e.jsx("span",{children:t("skills.library.importedAt",{date:new Date(s.importedAt).toLocaleDateString(Ss())})}),s.tags.map(n=>e.jsx("span",{className:"rounded bg-control px-1.5 py-0.5 font-mono",children:n},n))]})}function fx(){const[s,n]=l.useState([]),[a,i]=l.useState(!0),[r,c]=l.useState(""),[o,d]=l.useState(""),[m,u]=l.useState(null),[x,p]=l.useState(null),[h,f]=l.useState(""),[y,b]=l.useState(""),[g,k]=l.useState(!1),[S,C]=l.useState(""),w=l.useRef(!1),P=l.useMemo(()=>[...new Set(s.flatMap(U=>U.tags))].sort((U,J)=>U.localeCompare(J)),[s]),v=gx(s,o,m),B=async U=>{try{const J=await fetch("/api/skills-library"),K=await J.json();if(!J.ok)throw new Error(K.error??t("skills.library.loadError"));if(U?.())return;n(K.skills??[]),c("")}catch(J){U?.()||c(J instanceof Error?J.message:t("skills.library.loadError"))}finally{U?.()||i(!1)}};l.useEffect(()=>{let U=!1;return i(!0),B(()=>U),()=>{U=!0}},[]);const j=async(U,J=!1)=>{if(!w.current){if(!U.enabled&&!J)return A(U,!0);w.current=!0,f(U.name),c("");try{const K=await fetch(`/api/skills-library/${encodeURIComponent(U.name)}`,{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({enabled:!U.enabled})}),te=await K.json();if(!K.ok)throw new Error(te.error??t("skills.error.update"));J&&p(null),await B()}catch(K){c(K instanceof Error?K.message:t("skills.error.update"))}finally{w.current=!1,f("")}}},A=async(U,J=!1)=>{c("");try{const K=await fetch(`/api/skills-library/${encodeURIComponent(U.name)}`),te=await K.json();if(!K.ok)throw new Error(te.error??t("skills.error.load"));if(!te.text)throw new Error(t("skills.error.contentsImport"));p({skill:U,text:te.text,review:J})}catch(K){c(K instanceof Error?K.message:t("skills.error.load"))}},I=async()=>{const U=y.trim();if(U){k(!0),c(""),C("");try{const J=await fetch("/api/skills-library",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:U})}),K=await J.json();if(!J.ok)throw new Error(K.error??t("skills.error.import"));C(t("skills.library.imported",{name:K.skill?.name??""})),b(""),await B()}catch(J){c(J instanceof Error?J.message:t("skills.error.import"))}finally{k(!1)}}},_="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none";return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs(cx,{catalog:e.jsx(hx,{}),bundled:e.jsx(dx,{}),tools:e.jsx(ux,{}),children:[e.jsx(Y,{title:t("skills.library.title"),subtitle:t("skills.library.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(mt,{size:15,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{className:_,placeholder:t("skills.library.searchPlaceholder"),"aria-label":t("skills.library.searchPlaceholder"),value:o,onChange:U=>d(U.target.value)})]}),P.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>u(null),className:m===null?"rounded-full bg-control px-2.5 py-1 text-[12px] font-medium text-ink":"rounded-full px-2.5 py-1 text-[12px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:t("skills.library.allTags")}),P.map(U=>e.jsx("button",{type:"button",onClick:()=>u(m===U?null:U),className:m===U?"rounded-full bg-control px-2.5 py-1 font-mono text-[12px] font-medium text-ink":"rounded-full px-2.5 py-1 font-mono text-[12px] text-ink-secondary hover:bg-control/50 hover:text-ink",children:U},U))]}),a?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("skills.library.loading")}):v.length===0?e.jsx("div",{className:"rounded-lg bg-inset px-3 py-2 text-[12px] text-ink-secondary",children:s.length===0?t("skills.library.empty"):t("skills.library.noMatches")}):e.jsx("div",{className:"divide-y divide-hairline/40 overflow-hidden rounded-lg border border-hairline/40",children:v.map(U=>e.jsxs("div",{className:"px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{A(U)},className:"min-w-0 flex-1 text-left","aria-label":t("skills.library.view",{skill:U.name}),children:[e.jsx("div",{className:"truncate font-mono text-[13px] text-ink",children:U.name}),e.jsx("div",{className:"mt-0.5 line-clamp-2 text-[12px] text-ink-secondary",children:U.description})]}),e.jsx(me,{checked:U.enabled,"aria-label":U.enabled?t("skills.library.disable",{skill:U.name}):t("skills.library.enable",{skill:U.name}),disabled:!!(h||g),onClick:()=>{j(U)}})]}),e.jsx(ar,{skill:U}),U.warnings.length>0&&e.jsx("div",{className:"mt-1 text-[11px] text-warning",children:U.warnings.join(" · ")})]},U.name))}),r&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:r})]})}),e.jsx(Y,{title:t("skills.library.importTitle"),subtitle:t("skills.library.importHint"),children:e.jsxs("form",{className:"flex flex-col gap-2",onSubmit:U=>{U.preventDefault(),I()},children:[e.jsx("textarea",{className:`${_} min-h-32 font-mono text-[12px]`,placeholder:t("skills.library.importPlaceholder"),"aria-label":t("skills.library.importTitle"),value:y,onChange:U=>b(U.target.value)}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S?e.jsx("div",{className:"text-[12px] text-ink-secondary",children:S}):e.jsx("span",{}),e.jsx("button",{type:"submit",disabled:g||!!h||!y.trim(),className:"shrink-0 rounded-lg bg-control px-3 py-2 text-[13px] text-ink hover:bg-raised-hover disabled:opacity-50",children:g?t("skills.library.importing"):t("skills.library.importButton")})]})]})})]}),x&&e.jsx(Ta,{modal:!0,children:e.jsx(bx,{viewing:x,error:r,working:!!h,onClose:()=>{h||p(null)},onEnable:()=>{j(x.skill,!0)}})})]})}function bx({viewing:s,error:n,working:a,onClose:i,onEnable:r}){const c=l.useRef(null);return wl(c,i),e.jsx("div",{ref:c,tabIndex:-1,role:"dialog","aria-modal":"true","aria-labelledby":"skills-library-view-title",className:"fixed inset-0 z-[90] flex items-center justify-center bg-black/45 p-6",children:e.jsxs("div",{className:"flex max-h-[min(760px,90vh)] w-full max-w-2xl flex-col rounded-2xl bg-card p-5 shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{id:"skills-library-view-title",className:"text-[16px] font-semibold text-ink",children:s.review?t("skills.reviewTitle",{name:s.skill.name}):s.skill.name}),e.jsx("button",{type:"button",disabled:a,onClick:i,className:"rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink",children:t("skills.library.close")})]}),s.review&&e.jsx(ar,{skill:s.skill}),s.skill.warnings.length>0&&e.jsx("div",{className:"mt-2 text-[12px] text-warning",children:s.skill.warnings.join(" · ")}),e.jsx("pre",{tabIndex:0,"aria-label":`${t("skills.library.view",{skill:s.skill.name})}`,className:"mt-3 min-h-0 flex-1 overflow-auto whitespace-pre-wrap break-words rounded-xl bg-inset p-3 font-mono text-[12px] leading-relaxed text-ink",children:s.text}),n&&e.jsx("div",{role:"alert",className:"mt-2 text-[12px] text-danger",children:n}),s.review&&e.jsx("button",{type:"button",disabled:a,onClick:r,className:"mt-4 self-end rounded-lg bg-accent px-4 py-2 text-[13px] font-semibold text-white disabled:opacity-40",children:t("skills.enableReviewed")})]})})}function yx(s){const n=s?.edition?.license;return!n||typeof n.expiresAt!="string"||!Number.isFinite(n.expiresInDays)?null:n.graceEndsAt?{tone:"danger",text:t("settings.license.grace",{date:n.expiresAt,graceEnd:n.graceEndsAt})}:{tone:"warning",text:t("settings.license.expiring",{date:n.expiresAt,days:String(Math.max(0,n.expiresInDays))})}}function da({config:s}){const n=yx(s);return n?e.jsxs("div",{role:"status",className:z("flex items-start gap-2 rounded-xl border px-3 py-2.5 text-[13px] leading-relaxed",n.tone==="danger"?"border-danger/40 bg-danger/10 text-danger":"border-warning/40 bg-warning/10 text-warning"),children:[e.jsx(Oe,{size:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:n.text})]}):null}function ir(s){return s?.edition?.features?.includes("admin")===!0&&s?.fleet?.available===!0}const vx=()=>M("/api/fleet");function jx({fleet:s,onAct:n,busy:a}){return s.workspaces.length===0?e.jsx("div",{className:"text-[13px] text-ink-secondary",children:t("workspaces.empty",{domain:s.domain})}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto_auto] gap-x-5 border-b border-hairline/40 pb-2 text-[12px] font-medium uppercase tracking-wide text-ink-secondary",children:[e.jsx("span",{children:t("workspaces.colWorkspace")}),e.jsx("span",{className:"text-right",children:t("workspaces.colState")}),e.jsx("span",{className:"text-right",children:t("workspaces.colMonth")}),e.jsx("span",{})]}),s.workspaces.map(i=>{const r=i.status==="suspended",c=i.status==="running"||r,o=i.status==="provisioning"?t("workspaces.provisioning"):i.status==="error"?t("workspaces.error"):i.status==="retained"?t("workspaces.retained"):r?t("workspaces.suspended"):i.live==="active"?t("workspaces.running"):i.live;return e.jsxs("div",{className:"grid grid-cols-[1fr_auto_auto_auto] items-center gap-x-5 border-b border-hairline/20 py-2 text-[13px]",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-ink",children:i.slug}),e.jsx("a",{href:`https://${i.host}`,target:"_blank",rel:"noreferrer",className:"block truncate text-[12px] text-accent hover:underline",children:i.host}),!c&&e.jsx("span",{className:"block text-[12px] text-ink-secondary",children:t("workspaces.recoveryHint")})]}),e.jsx("span",{className:z("text-right",r||i.status==="provisioning"?"text-warning":i.status==="running"&&i.live==="active"?"text-success":"text-danger"),children:o}),e.jsxs("span",{className:"text-right tabular-nums text-ink",title:i.usage.turns===null?void 0:t("workspaces.turns",{turns:String(i.usage.turns)}),children:[ot(i.usage.costUsd)?ct(i.usage.costUsd):"—",ot(i.usage.billableUsd)&&e.jsxs("span",{className:"text-ink-secondary",children:[" · ",ct(i.usage.billableUsd)]})]}),e.jsx("span",{className:"flex items-center justify-end gap-2 text-[12px]",children:c&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:a!==null,onClick:()=>n(i.slug,"users"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:t("workspaces.users")}),e.jsx("button",{type:"button",disabled:a!==null,onClick:()=>n(i.slug,r?"resume":"suspend"),className:"text-ink-secondary hover:text-ink disabled:opacity-50",children:r?t("workspaces.resume"):t("workspaces.suspend")}),e.jsx("button",{type:"button",disabled:a!==null,onClick:()=>n(i.slug,"delete"),className:"text-danger hover:underline disabled:opacity-50",children:t("workspaces.delete")})]})})]},i.slug)})]})}function kx({domain:s,onCreated:n,disabled:a}){const[i,r]=l.useState(""),[c,o]=l.useState(""),[d,m]=l.useState(""),[u,x]=l.useState(""),[p,h]=l.useState(""),[f,y]=l.useState(!1),[b,g]=l.useState(null),k=async()=>{if(!f){y(!0),g(null);try{const C={slug:i.trim().toLowerCase(),admins:[c.trim()],members:d.split(/[,\s]+/).map(P=>P.trim()).filter(Boolean),...u.trim()?{cap:Number(u)}:{},...p.trim()?{anthropicKey:p.trim()}:{}},w=await M("/api/fleet/workspaces",{method:"POST",body:JSON.stringify(C)});r(""),o(""),m(""),x(""),h(""),n(w.log??[],{slug:C.slug,admin:C.admins[0]})}catch(C){g(C instanceof Error?C.message:String(C))}finally{y(!1)}}},S="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50";return e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:C=>{C.preventDefault(),k()},children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.name"),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{value:i,onChange:C=>r(C.target.value),placeholder:"acme",pattern:"[a-z][a-z0-9-]{1,30}",required:!0,disabled:a||f,"aria-label":t("workspaces.name"),className:S}),e.jsxs("span",{className:"whitespace-nowrap text-[12px] text-ink-secondary",children:[".",s]})]})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.adminEmail"),e.jsx("input",{value:c,onChange:C=>o(C.target.value),type:"email",required:!0,disabled:a||f,"aria-label":t("workspaces.adminEmail"),className:S})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.members"),e.jsx("input",{value:d,onChange:C=>m(C.target.value),placeholder:"bob@acme.test, @acme.test",disabled:a||f,"aria-label":t("workspaces.members"),className:S})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary",children:[t("workspaces.cap"),e.jsx("input",{value:u,onChange:C=>x(C.target.value),inputMode:"decimal",placeholder:"50",disabled:a||f,"aria-label":t("workspaces.cap"),className:S})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-[12px] text-ink-secondary sm:col-span-2",children:[t("workspaces.anthropicKey"),e.jsx("input",{value:p,onChange:C=>h(C.target.value),type:"password",autoComplete:"off",placeholder:"sk-ant-…",disabled:a||f,"aria-label":t("workspaces.anthropicKey"),className:S})]})]}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:t("workspaces.createHint")}),b&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:b}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"submit",disabled:a||f,className:"ui-button ui-button-primary",children:[f?e.jsx(X,{size:13,className:"animate-spin"}):e.jsx(Ce,{size:13}),f?t("workspaces.creating"):t("workspaces.create")]})})]})}function Nx({slug:s,onDone:n}){const[a,i]=l.useState(""),[r,c]=l.useState(!1),[o,d]=l.useState(null),[m,u]=l.useState(null),x=async p=>{if(!o){d(p),u(null);try{const h=await M(`/api/fleet/workspaces/${encodeURIComponent(s)}/users`,{method:"POST",body:JSON.stringify({action:p,email:a.trim(),chatOnly:r})});i(""),n(h.log??[])}catch(h){u(h instanceof Error?h.message:String(h))}finally{d(null)}}};return e.jsxs("div",{className:"mt-2 rounded-lg border border-hairline/40 p-3",children:[e.jsx("div",{className:"mb-2 text-[13px] font-medium text-ink",children:t("workspaces.usersTitle",{slug:s})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:a,onChange:p=>i(p.target.value),type:"text",placeholder:"person@example.com or @example.com","aria-label":t("workspaces.email"),disabled:o!==null,className:"min-w-[16rem] flex-1 rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none disabled:opacity-50"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:p=>c(p.target.checked),disabled:o!==null}),t("workspaces.chatOnly")]}),e.jsx("button",{type:"button",disabled:o!==null||!a.trim(),onClick:()=>{x("add")},className:"rounded-lg bg-raised px-3 py-1.5 text-[12px] text-ink hover:bg-raised-hover disabled:opacity-50",children:o==="add"?t("workspaces.working"):t("workspaces.addUser")}),e.jsx("button",{type:"button",disabled:o!==null||!a.trim(),onClick:()=>{x("remove")},className:"rounded-lg px-3 py-1.5 text-[12px] text-danger hover:underline disabled:opacity-50",children:o==="remove"?t("workspaces.working"):t("workspaces.removeUser")})]}),m&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:m})]})}function wx({load:s=vx}){const{state:n}=W(),[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[m,u]=l.useState(null),[x,p]=l.useState([]),[h,f]=l.useState(null),[y,b]=l.useState(null),[g,k]=l.useState(!1),[S,C]=l.useState(null),w=l.useCallback(async()=>{d(!0),c(null);try{i(await s())}catch(j){c(j instanceof Error?j.message:String(j))}finally{d(!1)}},[s]);l.useEffect(()=>{w()},[w]);const P=async(j,A)=>{if(A==="users"){f(I=>I===j?null:j);return}if(A==="delete"){b({slug:j,keepData:!1});return}u(j),c(null);try{const I=await M(`/api/fleet/workspaces/${encodeURIComponent(j)}/${A}`,{method:"POST"});p(I.log??[]),await w()}catch(I){c(I instanceof Error?I.message:String(I))}finally{u(null)}},v=async()=>{if(!y)return;const{slug:j,keepData:A}=y;b(null),u(j),c(null);try{const I=await M(`/api/fleet/workspaces/${encodeURIComponent(j)}`,{method:"DELETE",body:JSON.stringify({keepData:A})});p(I.log??[]),await w()}catch(I){c(I instanceof Error?I.message:String(I))}finally{u(null)}},B=async()=>{u("*"),c(null);try{const j=await M("/api/fleet/upgrade",{method:"POST"});p(j.log??[t("workspaces.upgraded")]),await w()}catch(j){c(j instanceof Error?j.message:String(j))}finally{u(null)}};return ir(n.config)?e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs(Y,{title:t("workspaces.title"),subtitle:t("workspaces.subtitle"),children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{w()},disabled:o||m!==null,className:"flex items-center gap-1 text-[12px] text-ink-secondary hover:text-ink disabled:opacity-50",children:[e.jsx(Se,{size:12,className:z(o&&"animate-spin")}),t("workspaces.refresh")]}),e.jsxs("button",{type:"button",onClick:()=>k(j=>!j),disabled:m!==null,className:"ml-auto flex items-center gap-1.5 rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:[e.jsx(Ce,{size:13}),t("workspaces.new")]}),e.jsx("button",{type:"button",onClick:()=>{B()},disabled:m!==null||!a?.workspaces.length,className:"rounded-lg border border-hairline/40 px-3 py-1.5 text-[12px] text-ink-secondary hover:bg-raised/50 hover:text-ink disabled:opacity-50",children:m==="*"?t("workspaces.working"):t("workspaces.upgradeAll")})]}),g&&a&&e.jsx("div",{className:"mb-4 rounded-xl border border-hairline/40 p-3",children:e.jsx(kx,{domain:a.domain,disabled:m!==null,onCreated:(j,A)=>{k(!1),p(j),C(`https://${A.slug}.${a.domain}/pair?email=${encodeURIComponent(A.admin)}`),w()}})}),S&&e.jsx("div",{className:"mb-4",children:e.jsx(Fi,{link:S})}),r&&e.jsx("p",{role:"alert",className:"mb-2 text-[12px] text-danger",children:r}),a?e.jsx(jx,{fleet:a,onAct:(j,A)=>{P(j,A)},busy:m}):o?e.jsxs("div",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:14,className:"animate-spin"}),t("common.checking")]}):null,h&&e.jsx(Nx,{slug:h,onDone:j=>{p(j),w()}}),x.length>0&&e.jsx("pre",{className:"mt-3 max-h-40 overflow-auto rounded-lg bg-inset p-2 text-[12px] text-ink-secondary",children:x.join(`
|
|
19
|
-
`)})]}),e.jsx(Qe,{open:y!==null,title:t("workspaces.deleteTitle",{slug:y?.slug??""}),body:t(y?.keepData?"workspaces.deleteKeepHint":"workspaces.deleteHint"),confirmLabel:t("workspaces.delete"),onCancel:()=>b(null),onConfirm:()=>{v()}}),y&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:y.keepData,onChange:j=>b({...y,keepData:j.target.checked})}),t("workspaces.keepData")]})]}):null}const rr=s=>({method:"PUT",body:JSON.stringify(s)}),Pt=s=>s instanceof Error?s.message:String(s);function Sx(){return l.useSyncExternalStore(ri,()=>hd()?.id??null,()=>null)}function Cx(s,n){const a=URL.createObjectURL(new Blob([JSON.stringify(n,null,2)],{type:"application/json"}));Object.assign(document.createElement("a"),{href:a,download:s}).click(),setTimeout(()=>URL.revokeObjectURL(a),1e3)}function Ex({id:s,act:n,onClose:a,onDelete:i}){const[r,c]=l.useState(null),[o,d]=l.useState(null),[m,u]=l.useState(!1);if(l.useEffect(()=>{M(`/api/themes/${s}`).then(h=>c(h.theme),h=>d(Pt(h)))},[s]),!r)return e.jsx(us,{children:o??t("settings.customThemes.loading")});const x=r.css?gd(r.css):null,p=async()=>{u(!0);try{await M(`/api/themes/${s}`,rr({theme:{...r,name:r.name.trim(),css:r.css||void 0}})),d(t("settings.customThemes.saved")),await Rs()}catch(h){d(Pt(h))}finally{u(!1)}};return e.jsxs("div",{"data-settings-block":"theme-editor",className:"flex flex-col gap-3 px-4 py-3",children:[e.jsx(bn,{label:t("settings.customThemes.name"),children:e.jsx("input",{className:yn,value:r.name,maxLength:60,onChange:h=>c({...r,name:h.target.value})})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:["canvas","accent"].map(h=>e.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"color",className:"size-7 cursor-pointer rounded-md bg-transparent",value:r[h]??(h==="canvas"?"#121212":"#1084fe"),onChange:f=>c({...r,[h]:f.target.value})}),t(h==="canvas"?"settings.customThemes.canvas":"settings.customThemes.accent"),r[h]&&e.jsx("button",{type:"button",className:"text-[12px] text-accent-text hover:underline",onClick:()=>c({...r,[h]:void 0}),children:t("settings.customThemes.clear")})]},h))}),e.jsx(bn,{label:t("settings.customThemes.css"),hint:x??t("settings.customThemes.cssHint"),children:e.jsx("textarea",{className:`${yn} h-64 resize-y py-2 font-mono text-[12px]`,spellCheck:!1,maxLength:fd.cssChars,"aria-label":t("settings.customThemes.css"),value:r.css??"",onChange:h=>c({...r,css:h.target.value})})}),e.jsxs(dc,{status:o,children:[e.jsxs("div",{className:"mr-auto flex flex-wrap gap-1.5",children:[e.jsx("button",{type:"button",className:"ui-button ui-button-sm",onClick:()=>{n(()=>M(`/api/themes/${s}/duplicate`,{method:"POST",body:JSON.stringify({name:t("settings.customThemes.copyName",{name:r.name}).slice(0,60)})}))},children:t("settings.customThemes.duplicate")}),e.jsx("button",{type:"button",className:"ui-button ui-button-sm",onClick:()=>{n(async()=>Cx(`${s}.mausbot-theme.json`,await M(`/api/themes/${s}/export`)))},children:t("settings.customThemes.export")}),e.jsx("button",{type:"button",className:"ui-button ui-button-sm","data-danger":"",onClick:i,children:t("common.delete")})]}),e.jsx("button",{type:"button",className:"ui-button",onClick:a,children:t("common.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",disabled:m||!!x||!r.name.trim(),onClick:()=>{p()},children:t("common.save")})]})]})}const Ax=6;function Ix(s){const n=s.name??"";switch(s.kind){case"made":return t("settings.customThemes.historyMade",{name:n});case"edited":return t("settings.customThemes.historyEdited",{name:n});case"deleted":return t("settings.customThemes.historyDeleted",{name:n});case"wore":return t("settings.customThemes.historyWore",{name:n});case"skin":return t("settings.customThemes.historySkin",{name:Lt.find(a=>a.id===n)?.name??n});case"default":return t("settings.customThemes.historyDefault");case"undid":return t("settings.customThemes.historyUndid")}}function Px({items:s,act:n}){return s.length<2?null:e.jsx(be,{label:t("settings.customThemes.history"),block:"theme-history",description:t("settings.customThemes.historyHint"),children:e.jsx(ye,{children:s.slice(0,Ax).map(a=>e.jsx(ue,{title:Ix(a),subtitle:ii(Date.parse(a.at)),children:a.index===1?e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:t("settings.customThemes.historyNow")}):e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{n(async()=>{await M("/api/themes/history",{method:"POST",body:JSON.stringify({index:a.index})}),await Rs()})},children:t("settings.customThemes.restore")})},a.index))})})}function lr(){const[s,n]=l.useState(null),[a,i]=l.useState(null),[r,c]=l.useState(null),o=l.useRef(null),d=Sx(),[m,u]=l.useState([]),x=l.useCallback(()=>Promise.all([M("/api/themes").then(n,g=>c(Pt(g))),M("/api/themes/history").then(g=>u(g.items),()=>u([]))]),[]);l.useEffect(()=>(x(),ri(()=>{x()})),[x]);const p=async g=>{c(null);try{await g()}catch(k){c(Pt(k))}await x()},h=()=>p(async()=>{const g=`theme-${Date.now().toString(36)}`;await M(`/api/themes/${g}`,rr({theme:{name:t("settings.customThemes.newName")}})),i(g)}),f=g=>g&&p(async()=>{let k;try{k=JSON.parse(await g.text())}catch{throw new Error(t("settings.customThemes.importFailed"))}await M("/api/themes/import",{method:"POST",body:JSON.stringify(k)})}),y=(g,k)=>p(async()=>{const S=await M(`/api/themes/${g}/export`);await M(`/api/themes/${g}`,{method:"DELETE"}),i(null),await Rs(),c(e.jsxs(e.Fragment,{children:[t("settings.customThemes.deleted",{name:k})," ",e.jsx("button",{type:"button",className:"text-accent-text hover:underline",onClick:()=>{p(()=>M("/api/themes/import",{method:"POST",body:JSON.stringify(S)}))},children:t("common.undo")})]}))}),b=cc()?"⌘⌥⇧R":"Ctrl+Alt+Shift+R";return e.jsxs(e.Fragment,{children:[e.jsx(be,{label:t("settings.customThemes.title"),block:"custom-themes",description:t("settings.customThemes.description"),actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>o.current?.click(),children:t("settings.customThemes.import")}),e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{h()},children:t("settings.customThemes.new")}),e.jsx("input",{ref:o,type:"file",accept:"application/json,.json",hidden:!0,onChange:g=>{f(g.target.files?.[0]),g.target.value=""}})]}),footnote:r,children:e.jsxs(ye,{children:[pd()&&e.jsx(us,{children:t("settings.customThemes.safe")}),s&&!s.themes.length&&e.jsx(us,{children:t("settings.customThemes.empty")}),s?.themes.map(g=>a===g.id?e.jsx(Ex,{id:g.id,act:p,onClose:()=>{i(null),x()},onDelete:()=>{y(g.id,g.name)}},g.id):e.jsx(ue,{title:g.name,subtitle:d===g.id?t("settings.customThemes.inUse"):g.assets.length?t("settings.customThemes.files",{count:g.assets.length}):void 0,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>i(g.id),children:t("settings.customThemes.edit")}),d===g.id?e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{p(()=>An(null))},children:t("settings.customThemes.takeOff")}):e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>{p(()=>An(g.id))},children:t("settings.customThemes.use")})]})},g.id)),e.jsx(ue,{title:t("settings.customThemes.reset"),subtitle:t("settings.customThemes.resetHint",{keys:b}),children:e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{xd(),x()},children:t("settings.customThemes.reset")})})]})}),e.jsx(Px,{items:m,act:p})]})}const ua=[{choice:"system",label:"settings.theme.system"},{choice:en.light,label:"settings.theme.light"},{choice:en.dark,label:"settings.theme.dark"}];function Ws(){return l.useSyncExternalStore(Vr,tn,tn)}function or({simple:s=!1}){const n=Ws(),a=ua.some(i=>i.choice===n)?void 0:Lt.find(i=>i.id===n)?.name;return e.jsx(ue,{title:t(s?"settings.theme.lightOrDark":"settings.theme.title"),subtitle:a?t("settings.theme.look",{name:a}):s?void 0:t("settings.theme.subtitle"),children:e.jsx("div",{role:"radiogroup","aria-label":t(s?"settings.theme.lightOrDark":"settings.theme.title"),className:s?"inline-flex h-7 rounded-full bg-ink/[0.06] p-0.5":"inline-flex rounded-full bg-inset p-0.5",children:ua.map(i=>e.jsx("button",{type:"button",role:"radio","aria-checked":n===i.choice,onClick:()=>Gr(i.choice),className:s?z("h-6 rounded-full px-2.5 text-[13px] transition-colors",n===i.choice?"bg-ink/[0.12] text-ink":"text-ink-secondary hover:text-ink"):z("rounded-full px-3 py-1 text-[13px] font-medium transition-colors",n===i.choice?"bg-raised text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(s&&i.choice==="system"?"settings.simple.theme.system":i.label)},i.choice))})})}function Tx({skin:s}){return e.jsxs("div",{"data-skin":s,"data-skin-preview":"","aria-hidden":"true",className:"flex h-[78px] w-full overflow-hidden rounded-lg bg-app ring-1 ring-hairline/60",children:[e.jsxs("div",{className:"flex w-[11px] shrink-0 flex-col items-center gap-[3px] bg-panel pt-[5px]",children:[e.jsx("span",{className:"size-[5px] rounded-full bg-accent"}),e.jsx("span",{className:"size-[5px] rounded-full bg-ink-secondary/40"}),e.jsx("span",{className:"size-[5px] rounded-full bg-ink-secondary/40"})]}),e.jsxs("div",{className:"flex w-[30px] shrink-0 flex-col gap-[3px] border-r border-hairline bg-panel p-[4px]",children:[e.jsxs("span",{className:"flex h-[9px] w-full items-center gap-[2px] rounded-sm bg-raised px-[2px]",children:[e.jsx("span",{className:"size-[4px] shrink-0 rounded-full bg-accent"}),e.jsx("span",{className:"h-[2px] flex-1 rounded-full bg-ink/50"})]}),e.jsx("span",{className:"h-[3px] w-[80%] rounded-full bg-ink-secondary/30"}),e.jsx("span",{className:"h-[3px] w-[62%] rounded-full bg-ink-secondary/30"}),e.jsx("span",{className:"h-[3px] w-[74%] rounded-full bg-ink-secondary/30"})]}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-[4px] p-[6px]",children:[e.jsx("span",{className:"h-[13px] w-[62%] self-end rounded-md bg-bubble-user"}),e.jsxs("div",{className:"flex w-[88%] flex-col gap-[3px] rounded-md bg-card p-[4px]",children:[e.jsx("span",{className:"h-[2px] w-full rounded-full bg-ink/45"}),e.jsx("span",{className:"h-[2px] w-[85%] rounded-full bg-ink/45"}),e.jsx("span",{className:"h-[2px] w-[60%] rounded-full bg-ink-secondary/40"})]}),e.jsxs("div",{className:"mt-auto flex items-center gap-[4px]",children:[e.jsx("span",{className:"h-[11px] flex-1 rounded-full bg-inset ring-1 ring-hairline"}),e.jsx("span",{className:"flex size-[11px] items-center justify-center rounded-full bg-accent",children:e.jsx("span",{className:"h-[1.5px] w-[5px] rounded-full",style:{background:"var(--color-accent-ink)"}})})]})]})]})}const Rx={halloween:["orange","purple","teal","red"],diwali:["red","orange","pink","coral"]};function Lx({festival:s}){const n=Cl(),a=t("settings.skin.dressUp.title");return e.jsxs("div",{"data-dress-up":!0,className:"mt-4 flex items-center gap-4 rounded-xl border border-accent-border/40 bg-accent/[0.06] p-3",children:[e.jsx("div",{className:"flex shrink-0 -space-x-1.5","aria-hidden":"true",children:Rx[s].map(i=>e.jsx(El,{color:i,bodyId:Al[s].costumes[i],size:30,animated:!1,trackPointer:!1},i))}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:a}),e.jsx("div",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.skin.dressUp.subtitle")})]}),e.jsx(me,{checked:n,"aria-label":a,onClick:()=>Il(!n)})]})}function cr(){const s=Ea(Ws());return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:Lt.map(n=>{const a=n.id===s;return e.jsxs("button",{type:"button",onClick:()=>{Jr(n.id),bd()},"aria-pressed":a,className:z("cursor-pointer flex flex-col gap-2 rounded-xl border p-2 text-left transition-colors",a?"border-accent-border bg-control":"border-hairline/60 hover:border-hairline hover:bg-control/50"),children:[e.jsx(Tx,{skin:n.id}),e.jsxs("div",{className:"flex items-start gap-1.5 px-0.5 pb-0.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n.name}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-ink-secondary",children:qr(`skins.tagline.${n.id}`,n.tagline)})]}),a&&e.jsx(ge,{size:13,className:"mt-0.5 shrink-0 text-accent-text"})]})]},n.id)})}),Sl(s)&&e.jsx(Lx,{festival:s})]})}function Bx(){const[s,n]=l.useState(Xr);return e.jsx(ue,{title:t("settings.font.title"),subtitle:t("settings.font.subtitle"),children:e.jsx(xe,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.font.aria"),onChange:a=>{const i=a.target.value;Qr(i),n(i)},children:Yr.map(a=>e.jsx("option",{value:a,children:t(`settings.font.${a}`)},a))})})}function Ox(){const[s,n]=l.useState(Zr);return e.jsx(ue,{title:t("settings.chatWidth.title"),subtitle:t("settings.chatWidth.subtitle"),children:e.jsx(xe,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.chatWidth.aria"),onChange:a=>{const i=sn.find(r=>r===a.target.value);i&&(el(i),n(i))},children:sn.map(a=>e.jsx("option",{value:a,children:t(`settings.chatWidth.${a}`)},a))})})}function Mx(){const s=uc();return e.jsx(ue,{title:t("sidebar.toolsLayout.title"),subtitle:t("sidebar.toolsLayout.subtitle"),children:e.jsx(xe,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("sidebar.toolsLayout.chooseAria"),onChange:n=>pc(xc(n.target.value)),children:mc.map(n=>e.jsx("option",{value:n,children:t(`sidebar.toolsLayout.${n}`)},n))})})}function dr(){const{state:s,dispatch:n}=W(),a=s.config?.rooms.turnTimeoutMinutes??5,[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,x]=l.useState(!1),p=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const h=async()=>{if(!c||p.current)return;const f=fc(i);if(!f.ok){m(t("settings.roomTurns.range"));return}p.current=!0,x(!0);try{const y=await M("/api/config",{method:"PUT",body:JSON.stringify({rooms:{turnTimeoutMinutes:f.minutes}})});n({type:"configStatus",config:y}),r(String(y.rooms.turnTimeoutMinutes)),o(!1),m("")}catch(y){m(y instanceof Error?y.message:t("settings.roomTurns.error"))}finally{p.current=!1,x(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"room-turn-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.roomTurns.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${d?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"room-turn-timeout",type:"number",min:gc,max:hc,step:1,inputMode:"numeric",value:i,disabled:u,"aria-invalid":!!d,"aria-describedby":d?"room-turn-timeout-error room-turn-timeout-help":"room-turn-timeout-help",onChange:f=>{r(f.target.value),o(!0),m("")},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.roomTurns.minutes")})]}),e.jsx("p",{id:"room-turn-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.roomTurns.help")}),d?e.jsx("p",{id:"room-turn-timeout-error",role:"alert",className:"text-[12px] text-danger",children:d}):null]})}const zx=10,ur=1,mr=60,ma="Enter a whole number from 1 to 60.";function Ux(s){const n=s.trim();if(!/^\d+$/.test(n))return{ok:!1,error:ma};const a=Number(n);return a<ur||a>mr?{ok:!1,error:ma}:{ok:!0,minutes:a}}function pa(s){return s?.mcp?.callTimeoutMinutes??zx}function pr(){const{state:s,dispatch:n}=W(),a=pa(s.config),[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,x]=l.useState(!1),p=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const h=async()=>{if(!c||p.current)return;const f=Ux(i);if(!f.ok){m(t("settings.mcpCalls.range"));return}p.current=!0,x(!0);try{const y=await M("/api/config",{method:"PUT",body:JSON.stringify({mcp:{callTimeoutMinutes:f.minutes}})});n({type:"configStatus",config:y}),r(String(pa(y))),o(!1),m("")}catch(y){m(y instanceof Error?y.message:t("settings.mcpCalls.error"))}finally{p.current=!1,x(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"mcp-call-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.mcpCalls.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${d?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"mcp-call-timeout",type:"number",min:ur,max:mr,step:1,inputMode:"numeric",value:i,disabled:u,"aria-invalid":!!d,"aria-describedby":d?"mcp-call-timeout-error mcp-call-timeout-help":"mcp-call-timeout-help",onChange:f=>{r(f.target.value),o(!0),m("")},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.mcpCalls.minutes")})]}),e.jsx("p",{id:"mcp-call-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.mcpCalls.help")}),d?e.jsx("p",{id:"mcp-call-timeout-error",role:"alert",className:"text-[12px] text-danger",children:d}):null]})}function xr(s,n){let a={value:s,status:"idle"},i=!1,r,c;const o=new Set,d=(u,x)=>{a={value:u,status:x};for(const p of o)p()},m=()=>(clearTimeout(c),r||(i?(d(a.value,"saving"),r=(async()=>{try{for(;i;){const u=a.value;await n(u),i=a.value!==u}d(a.value,"saved")}catch{d(a.value,"error")}})().finally(()=>{r=void 0}),r):Promise.resolve()));return{getSnapshot:()=>a,subscribe(u){return o.add(u),()=>{o.delete(u)}},confirm(u){!i&&!r&&u!==a.value&&d(u,"idle")},edit(u){i=!0,d(u,"idle"),clearTimeout(c),c=setTimeout(()=>{m()},600)},flush:m}}const xa=new WeakMap;function Fx(){const{state:s,dispatch:n}=W(),a=s.config?.profile?.aboutMe??"",i=!!s.config?.team;let r=xa.get(n);if(!r){const u={current:i};r={team:u,controller:xr(a,async x=>{const p=u.current?await Is({aboutMe:x}):(await M("/api/config",{method:"PUT",body:JSON.stringify({profile:{aboutMe:x}}),timeoutMs:1e4})).profile;n({type:"profileSaved",profile:{aboutMe:p?.aboutMe??x}})})},xa.set(n,r)}r.team.current=i;const c=r.controller,{value:o,status:d}=l.useSyncExternalStore(c.subscribe,c.getSnapshot,c.getSnapshot),{flush:m}=c;return l.useEffect(()=>{c.confirm(a)},[c,a]),l.useEffect(()=>()=>{m()},[m]),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{htmlFor:"profile-about-me",className:"text-[14px] text-ink",children:t("settings.profile.aboutMe")}),e.jsxs("details",{className:"group relative",children:[e.jsx("summary",{title:t("settings.profile.aboutMeHelp"),"aria-label":t("settings.profile.aboutMeHelp"),className:"flex size-6 cursor-pointer list-none items-center justify-center rounded-md text-ink-secondary hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70 [&::-webkit-details-marker]:hidden",children:e.jsx(bc,{size:14,"aria-hidden":"true"})}),e.jsx("p",{className:"absolute left-0 z-30 mt-1 w-56 rounded-xl border border-hairline bg-panel p-3 text-[12px] text-ink-secondary shadow-xl",children:t("settings.profile.aboutMeHelp")})]})]}),e.jsx("textarea",{id:"profile-about-me",value:o,rows:5,maxLength:i?4e3:24e3,onChange:u=>c.edit(u.target.value),onBlur:()=>{m()},className:"min-h-[120px] w-full resize-y rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none"}),e.jsx(Dx,{onChanged:u=>{c.confirm(u),n({type:"profileSaved",profile:{aboutMe:u}})}}),e.jsxs("div",{className:"min-h-4 text-[12px]",role:"status",children:[d==="saving"&&e.jsx("span",{className:"text-ink-secondary",children:t("settings.profile.saving")}),d==="saved"&&e.jsx("span",{className:"text-success",children:t("settings.profile.saved")}),d==="error"&&e.jsxs("span",{className:"text-danger",children:[t("settings.profile.saveError")," "," ",e.jsx("button",{type:"button",onClick:()=>{m()},className:"underline",children:t("settings.profile.retry")})]})]})]})}function Dx({onChanged:s}){const[n,a]=l.useState([]),[i,r]=l.useState(null),[c,o]=l.useState(!1);l.useEffect(()=>{let m=!1;return M("/api/profile/learned").then(u=>{m||a(u.learned)}).catch(()=>{}),()=>{m=!0}},[]);const d=async m=>{r(m),o(!1);try{const u=await M(`/api/profile/learned/${encodeURIComponent(m)}/remove`,{method:"POST"});a(u.learned),s(u.aboutMe)}catch{o(!0)}finally{r(null)}};return n.length?e.jsxs("div",{className:"mt-1 rounded-lg border border-hairline/40 bg-inset p-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("settings.profile.learned.title")}),e.jsx("p",{className:"mt-0.5 text-[12px] text-ink-secondary",children:t("settings.profile.learned.hint")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-2",children:n.map(m=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 text-[13px] text-ink",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[m.text," ",e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.learned.from",{name:m.botName})})]}),e.jsx("button",{type:"button",disabled:i===m.id,onClick:()=>{d(m.id)},className:"rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("settings.profile.learned.remove")})]},m.id))}),c&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:t("settings.profile.learned.error")})]}):null}const ha=new WeakMap;function _x(){const{state:s,dispatch:n}=W(),a=s.config?.everyBotRules;let i=ha.get(n);i||(i=xr(a??"",async u=>{const x=await M("/api/config",{method:"PUT",body:JSON.stringify({everyBotRules:u}),timeoutMs:1e4});n({type:"configStatus",config:x})}),ha.set(n,i));const{value:r,status:c}=l.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot),{confirm:o,edit:d,flush:m}=i;return l.useEffect(()=>{o(a??"")},[o,a]),l.useEffect(()=>()=>{m()},[m]),a===void 0?null:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"profile-every-bot-rules",className:"text-[14px] text-ink",children:t("settings.profile.everyBotRules")}),e.jsx("textarea",{id:"profile-every-bot-rules",value:r,rows:4,maxLength:24e3,placeholder:t("settings.profile.everyBotRulesPlaceholder"),onChange:u=>d(u.target.value),onBlur:()=>{m()},className:"min-h-[96px] w-full resize-y rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsxs("div",{className:"min-h-4 text-[12px]",role:"status",children:[c==="saving"&&e.jsx("span",{className:"text-ink-secondary",children:t("settings.profile.saving")}),c==="saved"&&e.jsx("span",{className:"text-success",children:t("settings.profile.saved")}),c==="error"&&e.jsxs("span",{className:"text-danger",children:[t("settings.profile.saveError")," "," ",e.jsx("button",{type:"button",onClick:()=>{m()},className:"underline",children:t("settings.profile.retry")})]})]})]})}const ga=64,fa=8192,kt=512;function $x(s){return jc(s)?s.size>kc?"settings.profile.avatar.tooLarge":null:"settings.profile.avatar.invalidType"}function Kx(s,n){return s<ga||n<ga?"settings.profile.avatar.tooSmall":s>fa||n>fa?"settings.profile.avatar.tooLargeDimensions":null}async function hr(s,n){const a=URL.createObjectURL(s);try{const i=await new Promise((r,c)=>{const o=new Image;o.onload=()=>r(o),o.onerror=()=>c(new Error("invalid-image")),o.src=a});if(i.naturalWidth<=0||i.naturalHeight<=0)throw new Error("invalid-image");return await n(i)}finally{URL.revokeObjectURL(a)}}function Hx(s,n){return hr(s,async a=>{const i=Math.min(a.naturalWidth,a.naturalHeight)/Math.max(1,n),r=document.createElement("canvas");r.width=kt,r.height=kt;const c=r.getContext("2d");if(!c)throw new Error("canvas-unavailable");c.drawImage(a,(a.naturalWidth-i)/2,(a.naturalHeight-i)/2,i,i,0,0,kt,kt);const o=await new Promise((d,m)=>r.toBlob(u=>u?d(u):m(new Error("image-encode-failed")),"image/webp",.9));return new File([o],"profile-photo.webp",{type:"image/webp"})})}function Wx(){const{state:s,dispatch:n}=W(),a=s.config?.profile?.avatarUrl??"",[i,r]=l.useState(!1),[c,o]=l.useState(null),[d,m]=l.useState(null),u=l.useRef(null),x=g=>{const k=u.current;k&&k.previewUrl!==g?.previewUrl&&URL.revokeObjectURL(k.previewUrl),u.current=g,m(g)};l.useEffect(()=>()=>{u.current&&URL.revokeObjectURL(u.current.previewUrl)},[]);const p=!!s.config?.team,h=async g=>{const k=p?await Is({avatarUrl:g}):(await M("/api/config",{method:"PUT",body:JSON.stringify({profile:{avatarUrl:g}})})).profile;n({type:"profileSaved",profile:{avatarUrl:k?.avatarUrl}})},f=g=>{if(!g)return;o(null);const k=$x(g);if(k)return o(t(k));hr(g,S=>({width:S.naturalWidth,height:S.naturalHeight})).then(({width:S,height:C})=>{const w=Kx(S,C);if(w)return o(t(w));x({file:g,previewUrl:URL.createObjectURL(g),width:S,height:C,zoom:1})},()=>o(t("settings.profile.avatar.invalidType")))},y=g=>{r(!0),o(null),Hx(g.file,g.zoom).then(k=>vc(k)).then(k=>{const S=k?Pl(k.path):null;if(!S)throw new Error("avatar");return h(S)}).then(()=>x(null),()=>o(t("settings.profile.avatar.saveError"))).finally(()=>r(!1))},b=()=>{o(null),h("").catch(()=>o(t("settings.profile.avatar.saveError")))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[d?e.jsx("div",{className:"flex w-full flex-col gap-2 rounded-lg border border-hairline/40 bg-inset p-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-16 shrink-0 overflow-hidden rounded-full bg-raised",children:e.jsx("img",{src:d.previewUrl,alt:"",className:"size-full object-cover",style:{transform:`scale(${d.zoom})`}})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink",children:t("settings.profile.avatar.cropTitle")}),e.jsxs("div",{className:"text-[11px] text-ink-secondary",children:[d.width," × ",d.height,"px"]}),e.jsxs("label",{className:"mt-1 block text-[11px] text-ink-secondary",children:[t("settings.profile.avatar.zoom"),e.jsx("input",{"aria-label":t("settings.profile.avatar.zoom"),type:"range",min:"1",max:"2.5",step:"0.05",value:d.zoom,onChange:g=>x({...d,zoom:Number(g.target.value)}),className:"ml-2 w-28 align-middle accent-accent"})]})]}),e.jsx("button",{type:"button",className:"rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control",onClick:()=>x(null),children:t("settings.profile.avatar.cancel")}),e.jsx("button",{type:"button",className:"rounded-md bg-control px-2 py-1 text-[12px] text-ink hover:bg-raised-hover",disabled:i,onClick:()=>y(d),children:t("settings.profile.avatar.save")})]})}):a?e.jsx("img",{...os("person","picture"),src:a,alt:"",className:"size-12 rounded-full object-cover"}):e.jsx("div",{...os("person","initials"),className:"size-12 rounded-full bg-raised"}),e.jsxs("label",{className:"cursor-pointer rounded-lg bg-control px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[i?t("settings.profile.avatar.uploading"):t("settings.profile.avatar.choose"),e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",disabled:i,onChange:g=>{const k=g.target.files?.[0];g.currentTarget.value="",f(k)}})]}),a&&!d&&e.jsx("button",{type:"button",className:"text-[12px] text-ink-secondary underline",onClick:b,children:t("settings.profile.avatar.remove")})]}),c&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:c})]})}function gr(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(s.config?.profile?.name??""),[r,c]=l.useState(s.config?.profile?.email??"");l.useEffect(()=>{i(s.config?.profile?.name??""),c(s.config?.profile?.email??"")},[s.config?.profile?.name,s.config?.profile?.email]);const o=!!s.config?.team,d=()=>{if(o){Is({name:a.trim()}).then(u=>n({type:"profileSaved",profile:{name:u.name,email:u.email}})).catch(()=>{});return}fetch("/api/config",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({profile:{name:a.trim(),email:r.trim().toLowerCase()}})}).then(u=>{if(!u.ok)throw new Error("Profile save failed");return u.json()}).then(u=>{u.profile&&n({type:"profileSaved",profile:{name:u.profile.name,email:u.profile.email}})}).catch(()=>{})},m="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none";return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Wx,{}),e.jsx("input",{"aria-label":t("settings.profile.name"),value:a,onChange:u=>i(u.target.value),onBlur:d,placeholder:t("settings.profile.name"),className:m}),e.jsx("input",{type:"email","aria-label":t("phone.signIn.email"),value:r,onChange:u=>c(u.target.value),onBlur:o?void 0:d,readOnly:o,placeholder:t("common.emailPlaceholder"),className:m}),e.jsx(Fx,{}),e.jsx(_x,{})]})}function Gx({profile:s}){const[n,a]=l.useState(null),i=yc(s),r=s?.avatarUrl&&n!==s.avatarUrl?s.avatarUrl:null;return e.jsx("span",{...os("person",r?"picture":"initials"),className:"flex size-11 shrink-0 items-center justify-center overflow-hidden rounded-full bg-ink/[0.06] text-[15px] font-medium text-ink-secondary",children:r?e.jsx("img",{src:r,alt:"",onError:()=>a(r),className:"size-full object-cover"}):i!=="?"?i:e.jsx(Qa,{size:20,"aria-hidden":"true"})})}function Vx(){const{state:s}=W(),[n,a]=l.useState(!1),i=s.config?.profile,r=i?.name?.trim()??"",c=i?.email?.trim()??"",o=l.useId(),d=l.useRef(null);return l.useEffect(()=>{n&&d.current?.querySelector("input:not([type=file])")?.focus()},[n]),e.jsxs("div",{"data-profile-summary":"",className:"px-4 py-[13px]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Gx,{profile:i}),e.jsx("div",{className:"min-w-0 flex-1",children:r||c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:r||c}),r&&c&&e.jsx("div",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:t("settings.simple.account.yourName")}),e.jsx("div",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:t("settings.simple.account.noNameHint")})]})}),e.jsx("button",{type:"button","aria-expanded":n,"aria-controls":o,className:"ui-button shrink-0",onClick:()=>a(!n),children:n?t("common.done"):t(r||c?"settings.simple.account.edit":"settings.simple.account.add")})]}),e.jsx("div",{id:o,ref:d,hidden:!n,className:"mt-4",children:n&&e.jsx(gr,{})})]})}function fr({row:s=!1}){const n=!!W().state.config?.team,[a,i]=l.useState(null),[r,c]=l.useState(!1),o=l.useId();l.useEffect(()=>{if(!n)return;let m=!0;return M("/api/me/away-emails",{timeoutMs:1e4}).then(u=>{m&&i(u.on)},()=>{}),()=>{m=!1}},[n]);const d=m=>{const u=a;i(m),c(!1),M("/api/me/away-emails",{method:"PUT",body:JSON.stringify({on:m}),timeoutMs:1e4}).then(x=>i(x.on),()=>{i(u),c(!0)})};return!n||a===null?null:e.jsxs("div",{className:s?"flex flex-col gap-1 px-4 py-[13px]":"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{id:o,className:"text-[14px] text-ink",children:t("settings.profile.awayEmails")}),e.jsx(me,{"aria-labelledby":o,checked:a,onClick:()=>d(!a)})]}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.awayEmailsHelp")}),r&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:t("settings.profile.awayEmailsError")})]})}function br(){const{state:s,dispatch:n}=W(),a=s.config?.threads?.maxConcurrentPerBot??3,i=s.config?.cloudStarter===!0,[r,c]=l.useState(null),[o,d]=l.useState(""),m=l.useRef(!1),u=async x=>{if(!(m.current||x===a)){m.current=!0,c(x),d("");try{const p=await M("/api/config",{method:"PATCH",body:JSON.stringify({threads:{maxConcurrentPerBot:x}})});n({type:"configStatus",config:p})}catch(p){d(p instanceof Error?p.message:t("settings.threads.error"))}finally{m.current=!1,c(null)}}};return e.jsxs(Y,{title:t("settings.threads.title"),subtitle:t("settings.threads.subtitle"),children:[e.jsx("label",{htmlFor:"thread-concurrency",className:"block text-[13px] font-medium text-ink",children:t("settings.threads.label")}),e.jsx(xe,{className:"mt-2",id:"thread-concurrency",value:r??a,disabled:r!==null||i,"aria-describedby":"thread-concurrency-help",onChange:x=>{u(Number(x.target.value))},children:Array.from({length:16},(x,p)=>p+1).map(x=>e.jsx("option",{value:x,children:x},x))}),e.jsx("p",{id:"thread-concurrency-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:i?t("settings.threads.starter"):t("settings.threads.helpHanded")}),r!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threads.saving")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function yr(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(""),m=l.useRef(!1),u=a??s.config?.automaticRecovery??{enabled:!1},x=s.instances.filter(g=>g.snapshot.state==="available"&&!g.policy),p=x.find(g=>g.instanceId===u.backup?.instanceId),h=p?.models.options.filter(g=>!g.orgBlocked&&!g.needsCliUpdate&&(p.snapshot.authenticated!==!1||g.custom))??[],f=h.some(g=>g.id===u.backup?.model),y=g=>{i(g),d("")},b=async()=>{if(!(!a||m.current||u.enabled&&!f)){m.current=!0,c(!0),d("");try{const g=await M("/api/config",{method:"PUT",body:JSON.stringify({automaticRecovery:{enabled:a.enabled,...a.backup?.model?{backup:a.backup}:{}}})});n({type:"configStatus",config:g}),i(null)}catch(g){d(g instanceof Error?g.message:t("settings.recovery.error"))}finally{m.current=!1,c(!1)}}};return e.jsxs(Y,{title:t("settings.recovery.title"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"automatic-recovery-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.recovery.enable")}),e.jsx(me,{id:"automatic-recovery-enabled",checked:u.enabled,disabled:r||!s.config,"aria-describedby":"automatic-recovery-help automatic-recovery-scope automatic-recovery-own",onClick:()=>y({...u,enabled:!u.enabled})})]}),e.jsx("p",{id:"automatic-recovery-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.help")}),e.jsx("p",{id:"automatic-recovery-scope",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.scopeHanded")}),e.jsx("p",{id:"automatic-recovery-own",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.ownBackups")}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-engine",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.engine")}),e.jsxs(xe,{className:"mt-2 w-full",id:"automatic-recovery-engine",value:u.backup?.instanceId??"",disabled:r||!u.enabled,onChange:g=>y({enabled:u.enabled,...g.target.value?{backup:{instanceId:g.target.value,model:""}}:{}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseEngine")}),u.backup&&!p&&e.jsx("option",{value:u.backup.instanceId,disabled:!0,children:t("settings.recovery.unavailable",{name:u.backup.instanceId})}),x.map(g=>e.jsx("option",{value:g.instanceId,disabled:!g.models.options.some(k=>g.snapshot.authenticated!==!1||k.custom),children:g.displayName},g.instanceId))]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-model",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.model")}),e.jsxs(xe,{className:"mt-2 w-full",id:"automatic-recovery-model",value:u.backup?.model??"",disabled:r||!u.enabled||!p,onChange:g=>y({enabled:u.enabled,backup:{instanceId:p.instanceId,model:g.target.value}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseModel")}),u.backup?.model&&!f&&e.jsx("option",{value:u.backup.model,disabled:!0,children:t("settings.recovery.unavailable",{name:u.backup.model})}),h.map(g=>e.jsx("option",{value:g.id,children:g.label},g.id))]})]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.charges")}),u.enabled&&!f&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.recovery.required")}),e.jsx("button",{type:"button",disabled:!a||r||u.enabled&&!f,onClick:()=>{b()},className:"mt-3 cursor-pointer rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white disabled:opacity-50",children:r?t("settings.threads.saving"):t("common.save")}),r&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}const vr=1,jr=3650,qx=30,Tt=1024*1024,js=256*1024,kr=4*1024*1024*1024,Jx=50;function ba(s){const n=Number(s);return Number.isInteger(n)&&n>=vr&&n<=jr?n:null}function ya(s){const n=Number(s);if(!Number.isFinite(n))return null;const a=Math.round(n*Tt);return a>=js&&a<=kr&&a%js===0?a:null}function va(s){const n=s/Tt;return String(Number.isInteger(n)?n:Number(n.toFixed(2)))}function Nr(){const{state:s,dispatch:n}=W(),a=s.config?.threads?.eventLogRetentionDays??null,i=s.config?.threads?.eventLogMaxBytes??null,[r,c]=l.useState(null),[o,d]=l.useState(null),[m,u]=l.useState(null),[x,p]=l.useState(""),[h,f]=l.useState(null),y=l.useRef(!1),b=r??String(a===null?qx:a),g=o??(i===null?String(Jx):va(i));l.useEffect(()=>{r!==null&&a!==null&&String(a)===r&&c(null)},[a,r]),l.useEffect(()=>{o!==null&&i!==null&&va(i)===o&&d(null)},[i,o]);const k=async(v,B)=>{if(!y.current){y.current=!0,u(B),p(""),f(null);try{const j=await M("/api/config",{method:"PATCH",body:JSON.stringify({threads:v})});n({type:"configStatus",config:j})}catch(j){p(j instanceof Error?j.message:t("settings.threadCleanup.error"))}finally{y.current=!1,u(null)}}},S=v=>{if(!v){c(null),p(""),f(null),k({eventLogRetentionDays:null},"retention");return}const B=ba(b);if(B===null){p(t("settings.threadCleanup.invalidRetention")),f("retention");return}k({eventLogRetentionDays:B},"retention")},C=v=>{if(!v){d(null),p(""),f(null),k({eventLogMaxBytes:null},"cap");return}const B=ya(g);if(B===null){p(t("settings.threadCleanup.invalidCap")),f("cap");return}k({eventLogMaxBytes:B},"cap")},w=()=>{if(a===null)return;const v=ba(b);if(v===null){p(t("settings.threadCleanup.invalidRetention")),f("retention");return}if(v===a){c(null),p("");return}k({eventLogRetentionDays:v},"retention")},P=()=>{if(i===null)return;const v=ya(g);if(v===null){p(t("settings.threadCleanup.invalidCap")),f("cap");return}if(v===i){d(null),p("");return}k({eventLogMaxBytes:v},"cap")};return e.jsxs(Y,{title:t("settings.threadCleanup.title"),subtitle:t("settings.threadCleanup.subtitle"),children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-retention-enabled",type:"checkbox",checked:a!==null,disabled:m!==null,onChange:v=>S(v.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-retention-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.retention.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${h==="retention"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-retention-days",type:"number",min:vr,max:jr,step:1,inputMode:"numeric",value:b,disabled:a===null||m!==null,"aria-invalid":h==="retention","aria-describedby":"thread-log-retention-help",onChange:v=>{c(v.target.value),p(""),f(null)},onBlur:w,onKeyDown:v=>{v.key==="Enter"&&v.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.retention.unit")})]})]}),e.jsx("p",{id:"thread-log-retention-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.retention.help")})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-cap-enabled",type:"checkbox",checked:i!==null,disabled:m!==null,onChange:v=>C(v.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-cap-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.cap.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${h==="cap"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-cap-mib",type:"number",min:js/Tt,max:kr/Tt,step:.25,inputMode:"decimal",value:g,disabled:i===null||m!==null,"aria-invalid":h==="cap","aria-describedby":"thread-log-cap-help",onChange:v=>{d(v.target.value),p(""),f(null)},onBlur:P,onKeyDown:v=>{v.key==="Enter"&&v.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.cap.unit")})]})]}),e.jsx("p",{id:"thread-log-cap-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.cap.help")})]}),m!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threadCleanup.saving")}),x&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:x})]})}const ja="min-w-0 rounded-lg border bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none";function Xx(){const s=tl(),[n,a]=l.useState(""),[i,r]=l.useState(""),[c,o]=l.useState(""),d=s.length>=nn,m=()=>{const u=sl({name:n,url:i},window.location.origin);if(!u.ok){o(u.error);return}an([...s,{id:nl(s),name:u.name,url:u.url}]),a(""),r(""),o("")};return e.jsx(Y,{title:t("webPanels.settings.title"),subtitle:t("webPanels.settings.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[s.length>0&&e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-lg border border-hairline/40",children:s.map(u=>e.jsxs("li",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[14px] font-medium text-ink",children:u.name}),e.jsx("p",{className:"truncate text-[12px] text-ink-secondary",title:u.url,children:u.url??t("webPanels.settings.chatPage")})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",onClick:()=>an(s.filter(x=>x.id!==u.id)),children:t("webPanels.settings.remove")})]},u.id))}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{"aria-label":t("webPanels.settings.name"),placeholder:t("webPanels.settings.name"),value:n,maxLength:rn,disabled:d,"aria-invalid":c==="name",onChange:u=>{a(u.target.value),o("")},className:`${ja} sm:w-40 ${c==="name"?"border-danger/60":"border-hairline/40 focus:border-focus"}`}),e.jsx("input",{"aria-label":t("webPanels.settings.url"),placeholder:"https://",type:"url",inputMode:"url",value:i,disabled:d,"aria-invalid":c==="url"||c==="self",onChange:u=>{r(u.target.value),o("")},onKeyDown:u=>{u.key==="Enter"&&m()},className:`${ja} flex-1 ${c==="url"||c==="self"?"border-danger/60":"border-hairline/40 focus:border-focus"}`}),e.jsx("button",{type:"button",className:"ui-button",disabled:d,onClick:m,children:t("webPanels.settings.add")})]}),c&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:t(c==="name"?"webPanels.settings.nameInvalid":c==="self"?"webPanels.settings.urlSelf":"webPanels.settings.urlInvalid",{max:rn})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:d?t("webPanels.settings.full",{max:nn}):t("webPanels.settings.help")})]})})}const ls="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-50",Xe=s=>{const n=s>=1073741824?3:s>=1048576?2:1;return`${new Intl.NumberFormat(Me(),{maximumFractionDigits:2}).format(s/1024**n)} ${["","KiB","MiB","GiB"][n]}`},ka=s=>{const n=new Date(s.completedAt??s.createdAt??NaN);return Number.isFinite(n.getTime())?new Intl.DateTimeFormat(Me(),{dateStyle:"medium",timeStyle:"short"}).format(n):t("companyBackup.unknownDate")};function Yx(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,n=s?window.ogb?.companyBackups:void 0,[a,i]=l.useState(null),r=l.useRef(0),c=l.useRef(0);return l.useEffect(()=>{const o=++r.current,d=c.current;i(null);const m=x=>{r.current===o&&(c.current++,i(x))},u=s?.onState(m);return s?.state().then(x=>{c.current===d&&m(x)}).catch(()=>{}),()=>{r.current++,u?.()}},[s]),!n||!a?null:a.status!=="connected"||a.cloudBackups!==!0||!a.organization?.id||!a.organization.name?.trim()||!a.email?e.jsx(Qx,{bridge:n}):e.jsx(Zx,{connection:a,bridge:n},`${a.organization.id}:${a.email}:${a.deviceId??""}`)}function Qx({bridge:s}){const[n,a]=l.useState(null),[i,r]=l.useState(!1),[c,o]=l.useState(""),d=l.useRef(0);if(l.useEffect(()=>{const u=++d.current,x=s.onState(p=>{u===d.current&&a(p.schedule??null)});return s.state().then(p=>{u===d.current&&a(p.schedule??null)}).catch(()=>{}),()=>{d.current++,x()}},[s]),!s.configureSchedule||!n?.enabled)return null;const m=async()=>{if(i||!s.configureSchedule)return;const u=d.current;r(!0),o("");try{const x=await s.configureSchedule({enabled:!1});u===d.current&&a(x.schedule??null)}catch{u===d.current&&o(t("companyBackup.scheduleFailed"))}finally{u===d.current&&r(!1)}};return e.jsx(Y,{title:t("companyBackup.title"),subtitle:t("companyBackup.savedSchedule"),children:e.jsxs("div",{className:"rounded-lg border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[14px] font-medium",children:t("companyBackup.daily")}),e.jsx(me,{"aria-label":t("companyBackup.daily"),checked:!0,disabled:i,onClick:()=>{m()}})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${n.status}`)}),c&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:c})]})})}function Zx({connection:s,bridge:n}){const[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[m,u]=l.useState(null),[x,p]=l.useState(""),[h,f]=l.useState(null),[y,b]=l.useState(""),[g,k]=l.useState(""),[S,C]=l.useState(null),[w,P]=l.useState(!1),v=l.useRef(0),B=l.useRef(0),j=l.useRef(0),A=l.useRef(void 0),I=l.useRef(!1),_=l.useRef(null),U=async()=>{const $=v.current,oe=++j.current,R=B.current;d(!0);try{await Promise.all([n.state().then(E=>{$===v.current&&oe===j.current&&B.current===R&&i(E)}),n.list().then(E=>{$===v.current&&oe===j.current&&c(E)})]),$===v.current&&oe===j.current&&p("")}catch{$===v.current&&oe===j.current&&p(t("companyBackup.loadFailed"))}finally{$===v.current&&oe===j.current&&d(!1)}};l.useEffect(()=>{const $=++v.current,oe=E=>{if($!==v.current)return;B.current++,i(E);const H=E.lastBackupAt??E.schedule?.lastBackupAt;!E.busy&&!E.pendingRestore&&H&&H!==A.current&&(A.current=H,U())},R=n.onState(oe);return U(),()=>{v.current++,j.current++,R()}},[n]),l.useEffect(()=>{const $=_.current;if(!(!h||!$))return $.showModal(),()=>{$.close()}},[h]);const J=w||a?.pendingRestore===!0,K=m!==null||!a||a.busy||J,te=()=>{f(null),b(""),k(""),C(null)},ae=$=>{K||I.current||(p(""),b(""),k(""),C(null),f($))},de=async($,oe)=>{if(K||I.current)return;I.current=!0,u($),p("");const R=v.current;try{await oe(()=>R===v.current)}catch{R===v.current&&p(t($==="restore"?"companyBackup.restoreFailed":"companyBackup.actionFailed"))}finally{I.current=!1,R===v.current&&u(null)}},D=()=>{h?.kind==="create"&&de("create",async $=>{await n.create({clientState:wc()}),$()&&(te(),await U())})},T=async $=>{if(!n.configureSchedule||I.current||!a||$&&(K||h?.kind!=="schedule"||g!=="BACK UP THIS WORKSPACE DAILY"))return;I.current=!0,u("schedule"),p("");const oe=v.current,R=B.current;k("");try{const E=await n.configureSchedule($?{enabled:!0,confirmation:"BACK UP THIS WORKSPACE DAILY"}:{enabled:!1});oe===v.current&&(B.current===R&&i(E),te())}catch{oe===v.current&&p(t("companyBackup.scheduleFailed"))}finally{I.current=!1,oe===v.current&&u(null)}},Z=()=>{h?.kind!=="restore"||h.entry.passwordRequired!==!1&&(y.length<12||y.length>1024)||de("prepare",async $=>{const oe=y;b(""),C(null),k("");const R=await n.prepareRestore({id:h.entry.id,...h.entry.passwordRequired!==!1?{password:oe}:{}});$()&&C(R)})},ee=()=>{h?.kind!=="restore"||!S||g!=="REPLACE"||de("restore",async $=>{const oe=localStorage.getItem(jn);if(oe&&oe!==S.id)throw new Error(t("companyBackup.restorePending"));localStorage.setItem(jn,S.id),await n.restore({id:S.id,confirmation:"REPLACE"}),$()&&(P(!0),te())})},fe=()=>{h?.kind!=="delete"||g!=="DELETE"||de("delete",async $=>{await n.delete({id:h.entry.id,confirmation:"DELETE"}),$()&&(te(),await U())})},N=async()=>{const $=v.current;try{await n.cancel()}catch{$===v.current&&p(t("companyBackup.actionFailed"))}},re=r?.backups.filter($=>$.status==="ready")??[],se=r?r.backups.length-re.length:0,ne=a?.progress,G=x||a?.message,ie=(a?.busy||m)&&e.jsxs("div",{role:"status",className:"flex flex-col items-start gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{children:m==="restore"?t("backup.restoring"):ne?t(`companyBackup.phase.${ne.phase}`):t("companyBackup.working")}),ne&&ne.totalBytes>0&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{className:"w-full accent-accent",max:ne.totalBytes,value:Math.min(ne.bytesTransferred,ne.totalBytes),"aria-label":t("companyBackup.progress")}),e.jsx("span",{children:t("companyBackup.transferred",{done:Xe(ne.bytesTransferred),total:Xe(ne.totalBytes)})})]}),a?.busy&&m!=="restore"&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{N()},children:t("companyBackup.cancelTransfer")})]}),le=h?.kind==="restore"?t("companyBackup.restore"):h?.kind==="delete"?t("companyBackup.delete"):h?.kind==="schedule"?t("companyBackup.enableSchedule"):t("companyBackup.create"),ce=a?.schedule,ve=$=>new Intl.DateTimeFormat(Me(),{dateStyle:"medium",timeStyle:"short"}).format(new Date($));return e.jsxs(Y,{title:t("companyBackup.title"),subtitle:t("companyBackup.account",{organization:s.organization?.name??"",email:s.email??""}),children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedScope")}),n.configureSchedule&&ce&&e.jsxs("div",{className:"rounded-lg border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[14px] font-medium",children:t("companyBackup.daily")}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.scheduleHelp")})]}),e.jsx(me,{"aria-label":t("companyBackup.daily"),checked:ce.enabled,disabled:m!==null||!a||!ce.enabled&&K,onClick:()=>ce.enabled?void T(!1):ae({kind:"schedule"})})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${ce.status}`)}),ce.enabled&&ce.nextBackupAt&&Number.isFinite(ce.nextBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.nextBackup",{date:ve(ce.nextBackupAt)})}),ce.lastBackupAt&&Number.isFinite(ce.lastBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.lastScheduledBackup",{date:ve(ce.lastBackupAt)})}),ce.message&&e.jsx("p",{role:"status",className:"mt-1 break-words text-[12px] text-ink-secondary",children:ce.message})]}),J?e.jsx("div",{className:"rounded-lg border border-warning/40 bg-warning/10 p-3 text-ink",children:e.jsx(vn,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:K,onClick:()=>ae({kind:"create"}),children:t("companyBackup.create")}),e.jsx("button",{type:"button",className:"ui-button",disabled:m!==null||a?.busy||J||o,onClick:()=>{U()},children:t("companyBackup.refresh")})]}),o&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("companyBackup.loading")}),r&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("companyBackup.quota",{used:Xe(r.usedBytes),total:Xe(r.limits.ownerQuotaBytes),count:r.limits.retainedSnapshots})}),se>0&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("companyBackup.pending",{count:se})}),r&&re.length===0&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.empty")}),e.jsx("ul",{className:"divide-y divide-hairline/40",children:re.map($=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-3 py-3",children:[e.jsxs("div",{className:"min-w-0 text-[13px]",children:[e.jsx("div",{className:"text-ink",children:ka($)}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[Xe($.sizeBytes),$.appVersion?` · ${$.appVersion}`:""]}),e.jsx("code",{className:"break-all text-[11px] text-ink-secondary",children:$.id})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:K,onClick:()=>ae({kind:"restore",entry:$}),children:t("companyBackup.restore")}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:K,onClick:()=>ae({kind:"delete",entry:$}),children:t("companyBackup.delete")})]})]},$.id))})]}),!h&&ie,!h&&G&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:G})]}),h&&e.jsx("dialog",{ref:_,"aria-labelledby":"company-backup-dialog-title",onKeyDown:$=>{($.key==="Escape"||$.key==="Tab")&&$.stopPropagation()},onCancel:$=>{$.preventDefault(),m||te()},className:"fixed inset-0 m-auto max-h-[85dvh] w-[min(34rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border border-hairline/50 bg-app p-5 text-ink shadow-xl backdrop:bg-black/45",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h3",{id:"company-backup-dialog-title",className:"text-[16px] font-semibold",children:le}),J&&e.jsx(vn,{}),(h.kind==="restore"||h.kind==="delete")&&e.jsxs("div",{className:"text-[13px] text-ink-secondary",children:[e.jsxs("p",{children:[ka(h.entry)," · ",Xe(h.entry.sizeBytes)]}),e.jsx("code",{className:"break-all text-[11px]",children:h.entry.id})]}),(h.kind==="create"||h.kind==="schedule")&&e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:$=>{$.preventDefault(),h.kind==="schedule"?T(!0):D()},children:[e.jsx("p",{className:"text-[13px] text-ink",children:t(h.kind==="schedule"?"companyBackup.scheduleWarning":"companyBackup.managedUploadWarning",{organization:s.organization?.name??"",email:s.email??""})}),h.kind==="schedule"?e.jsxs("details",{className:"text-[13px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer text-ink",children:t("companyBackup.included")}),e.jsx("p",{className:"mt-2",children:t("backup.excluded")}),e.jsx("p",{className:"mt-2",children:t("companyBackup.managedPrivacy")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("backup.excluded")}),e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedPrivacy")})]}),e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedEncryption")}),h.kind==="schedule"&&e.jsxs("label",{className:"flex items-start gap-2 text-[13px]",children:[e.jsx("input",{className:"mt-1 accent-accent",type:"checkbox",required:!0,disabled:K,checked:g==="BACK UP THIS WORKSPACE DAILY",onChange:$=>k($.target.checked?"BACK UP THIS WORKSPACE DAILY":"")}),e.jsx("span",{children:t("companyBackup.scheduleConsent")})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:K||h.kind==="schedule"&&g!=="BACK UP THIS WORKSPACE DAILY",children:t(h.kind==="schedule"?"companyBackup.enableSchedule":"companyBackup.create")})]}),h.kind==="restore"&&(S?e.jsxs(e.Fragment,{children:[e.jsx(Nc,{summary:S.summary}),e.jsx("p",{className:"text-[13px] text-danger",children:t("backup.replaceWarning")}),e.jsx("p",{className:"text-[13px] text-danger",children:t("backup.trustWarning")}),e.jsxs("label",{className:"text-[13px]",children:[t("backup.confirmReplace"),e.jsx("input",{autoComplete:"off",spellCheck:!1,maxLength:7,disabled:K,value:g,onChange:$=>k($.target.value),className:ls})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:K||g!=="REPLACE",onClick:ee,children:t("backup.replace")})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:$=>{$.preventDefault(),Z()},children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.previewHelp")}),h.entry.passwordRequired!==!1&&e.jsxs("label",{className:"text-[13px]",children:[t("backup.importPassword"),e.jsx("input",{type:"password",autoComplete:"off",required:!0,minLength:12,maxLength:1024,disabled:K,value:y,onChange:$=>b($.target.value),className:ls})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:K||h.entry.passwordRequired!==!1&&(y.length<12||y.length>1024),children:t("backup.validate")})]})),h.kind==="delete"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-danger",children:t("companyBackup.deleteWarning")}),e.jsxs("label",{className:"text-[13px]",children:[t("companyBackup.confirmDelete"),e.jsx("input",{autoComplete:"off",spellCheck:!1,maxLength:6,disabled:K,value:g,onChange:$=>k($.target.value),className:ls})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:K||g!=="DELETE",onClick:fe,children:t("companyBackup.delete")})]}),ie,G&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:G}),e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button w-fit",disabled:m!==null,onClick:te,children:t("companyBackup.cancel")})]})})]})}function eh({sources:s}){const n=[...new Set(s.map(a=>a==="claudeDesktop"?"claudeCode":a))];return e.jsx("span",{className:"mr-1.5 inline-flex items-center gap-1 align-[-1px]","aria-hidden":"true",children:n.map(a=>{switch(a){case"codex":return e.jsx(zc,{size:12},a);case"cursor":return e.jsx(Mc,{size:12},a);case"gemini":return e.jsx(Fa,{preset:"google",size:12},a);default:return e.jsx(Oc,{size:12},a)}})})}function Na({icon:s,label:n,summary:a,hint:i,sources:r,checked:c,disabled:o,onChange:d}){return e.jsxs("label",{className:z("flex items-start gap-3 px-3.5 py-3 transition-colors",o?"cursor-default":"cursor-pointer hover:bg-raised/40"),children:[e.jsx("input",{type:"checkbox",checked:c,disabled:o,onChange:m=>d(m.target.checked),className:"mt-0.5 size-4 shrink-0 cursor-[inherit] accent-[var(--color-accent)]"}),e.jsx("span",{className:"mt-0.5 flex size-4 shrink-0 items-center justify-center text-ink-secondary",children:s}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("span",{className:"text-[13px] leading-5 text-ink-secondary",children:[e.jsx("span",{className:"mr-2 text-[14px] font-medium text-ink",children:n}),e.jsx(eh,{sources:r}),a]}),e.jsx("span",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:i})]})]})}const wr="inline-flex items-center justify-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink disabled:opacity-40";function th({local:s,detection:n,chosen:a,status:i,result:r,onChoose:c,onBring:o}){const d=i==="working";let m;if(!s)m=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("settings.import.appsLocalOnly")});else if(n===void 0)m=e.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:14,className:"animate-spin"}),t("settings.import.appsLooking")]});else if(r){const{line:u,notes:x,done:p}=Ic(r);m=e.jsxs("div",{role:"status",className:"flex items-start gap-3",children:[e.jsx("span",{className:z("mt-px flex size-5 shrink-0 items-center justify-center rounded-full",p?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:p?e.jsx(ge,{size:12,strokeWidth:3}):e.jsx(Pc,{size:12,strokeWidth:2.5})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[14px] font-medium text-ink",children:u}),x.map(h=>e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:h},h))]})]})}else!n||Tc(n)===0?m=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:n===null?t("onboarding.import.error"):t("settings.import.appsNothing")}):m=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"divide-y divide-hairline/40 overflow-hidden rounded-xl border border-hairline/40",children:[n.skills.length>0&&e.jsx(Na,{icon:e.jsx(Ps,{size:15}),label:t("onboarding.import.skills"),summary:Rc(n),hint:t("onboarding.import.skillsHint"),sources:kn(n.skills),checked:a.skills,disabled:d,onChange:u=>c({...a,skills:u})}),n.tools.length>0&&e.jsx(Na,{icon:e.jsx(Bc,{size:15}),label:t("onboarding.import.tools"),summary:Lc(n),hint:t("onboarding.import.toolsHint"),sources:kn(n.tools),checked:a.tools,disabled:d,onChange:u=>c({...a,tools:u})})]}),i==="failed"&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("onboarding.import.error")}),e.jsxs("button",{onClick:o,disabled:d||!(a.skills||a.tools),className:z(wr,"mt-3"),children:[d&&e.jsx(X,{size:14,className:"animate-spin"}),d?t("onboarding.import.bringing"):t("onboarding.import.bring")]})]});return e.jsxs("section",{"data-import-section":"apps",className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:t("settings.import.appsTitle")}),e.jsx("div",{className:"mt-0.5 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.import.appsSubtitle")}),e.jsx("div",{className:"mt-4",children:m})]})}function sh({client:s,local:n}){const[a,i]=l.useState(void 0),[r,c]=l.useState({skills:!0,tools:!0}),[o,d]=l.useState("idle"),[m,u]=l.useState(null);l.useEffect(()=>{if(!n)return;const p=new AbortController;return s.detect(p.signal).then(i,()=>i(null)),()=>p.abort()},[s,n]);const x=async()=>{if(!a||o==="working")return;const p={...r.skills&&a.skills.length?{skills:!0}:{},...r.tools&&a.tools.length?{tools:!0}:{}};if(!(!p.skills&&!p.tools)){d("working");try{const h=await s.apply(p);Tl("setup_import_applied",{skills:h.skills?.added.length??0,tools:h.tools?.added.length??0}),u(h),d("idle")}catch{d("failed")}}};return e.jsx(th,{local:n,detection:a,chosen:r,status:o,result:m,onChoose:c,onBring:()=>{x()}})}function nh(){const[s,n]=l.useState(!1),[a,i]=l.useState(!1);return e.jsxs("section",{"data-import-section":"grok",className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[15px] font-medium text-ink",children:[e.jsx(Ec,{size:16}),t("settings.import.grokTitle")]}),e.jsx("div",{className:"mt-0.5 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.import.grokSubtitle")}),e.jsxs("button",{type:"button","data-grok-move-open":!0,"aria-expanded":a,onClick:()=>{n(!0),i(!a)},className:z(wr,"mt-3"),children:[t("settings.import.grokTitle"),e.jsx(Ca,{size:14,"aria-hidden":"true",className:z("transition-transform",a&&"rotate-180")})]}),s&&e.jsx("div",{className:a?void 0:"hidden",children:e.jsx(Ac,{inline:!0,onClose:()=>{n(!1),i(!1)}})})]})}function Sr({client:s=Sc}){const{state:n}=W();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(sh,{client:s,local:Cc(n.config?.cloudHome===!0)}),e.jsx(nh,{})]})}function Cr({simple:s=!1}){return e.jsxs(e.Fragment,{children:[e.jsx(ah,{simple:s}),e.jsx(ih,{simple:s}),e.jsx(rh,{simple:s})]})}const wa=()=>typeof Notification<"u"?Notification.permission:"default";function ah({simple:s=!1}){const[n,a]=l.useState(wa),i=Uc();if(l.useEffect(()=>{const o=()=>{document.visibilityState==="visible"&&a(wa())};return window.addEventListener("focus",o),document.addEventListener("visibilitychange",o),()=>{window.removeEventListener("focus",o),document.removeEventListener("visibilitychange",o)}},[]),typeof Notification>"u")return null;const r=n==="denied",c=async()=>{if(n==="granted")return Nn(!i);const o=await Kc();o&&(a(o),o==="granted"&&Nn(!0))};return e.jsx(ue,{title:t("settings.deviceNotifications.title"),subtitle:t(r?"settings.deviceNotifications.blocked":s?"settings.simple.deviceNotifications":"settings.deviceNotifications.subtitle"),children:e.jsx(me,{checked:n==="granted"&&i,disabled:r,"aria-label":t("settings.deviceNotifications.show"),onClick:()=>{c()}})})}function ih({simple:s=!1}){const n=Fc();return e.jsx(ue,{title:t("settings.notificationSounds.title"),subtitle:t(s?"settings.simple.notificationSounds":"settings.notificationSounds.subtitle"),children:e.jsx(me,{checked:n,"aria-label":t("settings.notificationSounds.play"),onClick:()=>Dc(!n)})})}function rh({simple:s=!1}){const n=_c();return e.jsx(ue,{title:t("settings.notificationFeed.title"),subtitle:t(s?"settings.simple.notificationFeed":"settings.notificationFeed.subtitle"),children:e.jsx(me,{checked:n,"aria-label":t("settings.notificationFeed.show"),onClick:()=>$c(!n)})})}function Er(){const{state:s,dispatch:n}=W(),a=Hc(s.config),[i,r]=l.useState(!1),[c,o]=l.useState("");if(!Wc(s.config))return null;const d=async()=>{if(!i){r(!0),o("");try{const m=await M("/api/config",{method:"PATCH",body:JSON.stringify({features:{savedSteps:!a}})});n({type:"configStatus",config:m})}catch(m){o(m instanceof Error?m.message:t("settings.savedSteps.error"))}finally{r(!1)}}};return e.jsx(ue,{title:t("settings.savedSteps.title"),subtitle:t("settings.savedSteps.subtitle"),children:e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx(me,{checked:a,disabled:i,"aria-label":t("settings.savedSteps.aria"),onClick:d}),c&&e.jsx("span",{role:"alert",className:"text-[12px] text-danger",children:c})]})})}const lh=["settings.font.title","settings.chatWidth.title","settings.pinnedCircles.title","settings.universalPins.title","settings.runCard.title"],oh=["settings.roomTurns.title","settings.mcpCalls.title","settings.threads.title","settings.recovery.title","settings.threadCleanup.title","settings.keepWarm.title","settings.savedSteps.title"];function ch({has:s,peopleOpen:n,onLooks:a,onMore:i}){return e.jsxs(e.Fragment,{children:[(s("general")||s("people"))&&e.jsx(be,{label:t("settings.group.account"),block:"general",children:e.jsxs(ye,{children:[s("general")&&e.jsx(Vx,{}),s("general")&&e.jsx(fr,{row:!0}),s("general")&&e.jsx(fi,{place:"account"}),s("people")&&e.jsx("div",{"data-settings-block":"people",className:"scroll-mt-4",children:e.jsx(Di,{simple:!0,startOpen:n})})]})}),s("appearance")&&e.jsx(be,{label:t("settings.section.appearance"),block:"appearance",children:e.jsxs(ye,{children:[e.jsx(or,{simple:!0}),e.jsx(dh,{onLooks:a}),e.jsx(Gi,{}),e.jsx(ti,{}),e.jsx(Vi,{}),e.jsx(xi,{simple:!0})]})}),s("appearance")&&e.jsx(be,{label:t("settings.simple.group.typing"),children:e.jsxs(ye,{children:[e.jsx(ms,{simple:!0}),e.jsx(hi,{simple:!0}),e.jsx(gi,{simple:!0})]})}),s("appearance")&&e.jsx(be,{label:t("notifications.title"),children:e.jsx(ye,{children:e.jsx(Cr,{simple:!0})})}),s("general")&&e.jsx(be,{label:t("settings.simple.group.system"),children:e.jsxs(ye,{children:[e.jsx(wi,{simple:!0}),e.jsx(si,{simple:!0}),e.jsx(Si,{}),e.jsx(Ci,{}),e.jsx(Ni,{simple:!0})]})}),s("import")&&e.jsx(be,{label:t("settings.section.import"),block:"import",children:e.jsx(je,{children:e.jsx(Sr,{})})}),s("organization")&&e.jsx(be,{label:t("settings.section.organization"),block:"organization",children:e.jsx(Ji,{})}),s("activity")&&e.jsx(be,{label:t("settings.section.activity"),block:"activity",children:e.jsx(_i,{})}),i&&e.jsx("div",{"data-settings-block":"more",className:"scroll-mt-4",children:e.jsx(ye,{children:e.jsx(ue,{title:t("settings.simple.more.title"),subtitle:t("settings.simple.more.subtitle"),children:e.jsx("button",{type:"button",className:"ui-button","data-settings-more":"",onClick:i,children:t("settings.simple.more.open")})})})}),e.jsx("div",{"data-settings-block":"advanced-mode",className:"scroll-mt-4",children:e.jsx(ye,{children:e.jsx(ps,{simple:!0})})})]})}function dh({onLooks:s}){const n=Ws(),a=Lt.find(r=>r.id===Ea(n))?.name,i=n==="system"?t("settings.simple.themes.followHint"):a;return e.jsx(ue,{title:t("settings.theme.title"),subtitle:i,children:e.jsx("button",{type:"button",className:"ui-button",onClick:s,children:t("settings.simple.themes.browse")})})}function uh({onBack:s,toolCalls:n=!0}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:s,children:t("settings.simple.looks.back")})}),e.jsx("div",{"data-settings-block":"looks",children:e.jsx(cr,{})}),e.jsx(lr,{}),n&&e.jsx(ye,{children:e.jsx(pi,{})})]})}function mh({sections:s,onOpen:n,onBack:a}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:a,children:t("settings.simple.looks.back")})}),s.length>0&&e.jsx(be,{block:"more-sections",children:e.jsx(ye,{children:s.map(({id:i,labelKey:r})=>e.jsx(ue,{title:t(r),children:e.jsx("button",{type:"button",className:"ui-button","data-settings-more-section":i,onClick:()=>n(i),children:t("settings.simple.more.open")})},i))})}),e.jsx(be,{label:t("settings.simple.more.limits"),block:"limits",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Y,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(dr,{})}),e.jsx(Y,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(pr,{})}),e.jsx(br,{}),e.jsx(yr,{}),e.jsx(Nr,{}),e.jsx(Ti,{}),e.jsx(ye,{children:e.jsx(Er,{})})]})})]})}function ph({has:s,disclose:n,connections:a}){return e.jsxs(e.Fragment,{children:[s("engines")&&e.jsx("div",{"data-settings-block":"engines",className:"flex scroll-mt-4 flex-col gap-7",children:e.jsxs(je,{children:[e.jsx(Li,{simple:!0,more:n("ai-more")}),e.jsx(ye,{children:e.jsx(mi,{simple:!0})})]})}),s("connections")&&e.jsx(je,{children:e.jsx(zt,{title:t("settings.section.connections"),block:"connections",...n("ai-keys"),children:a})})]})}function xh({has:s,remoteAccess:n,servers:a,disclose:i}){return e.jsxs(e.Fragment,{children:[s("computer")&&e.jsx(be,{label:t("settings.simple.computer.bots"),block:"computer",children:e.jsx(je,{children:e.jsx(zi,{})})}),s("companion")&&e.jsxs(be,{label:t(ei()?"settings.section.phoneDevices":"settings.section.thisServer"),block:"companion",children:[n.companion,n.pairing,n.domain]}),s("computer")&&e.jsxs(be,{label:t("settings.experimental.browser"),block:"browser",children:[e.jsxs(ye,{children:[e.jsx(ci,{}),e.jsx(di,{})]}),e.jsx(ui,{})]}),s("logins")&&e.jsx("div",{"data-settings-block":"logins",className:"scroll-mt-4",children:e.jsx(Wi,{})}),(s("companion")||s("desktopWorkspaces"))&&e.jsxs(zt,{title:t("settings.simple.computer.elsewhere"),block:"elsewhere",...i("computer-elsewhere"),children:[s("desktopWorkspaces")&&e.jsx("div",{"data-settings-block":"desktopWorkspaces",className:"flex scroll-mt-4 flex-col gap-4",children:a}),s("companion")&&e.jsx("div",{"data-settings-block":"remote",className:"flex scroll-mt-4 flex-col gap-4 empty:hidden",children:n.client})]})]})}function hh({has:s,disclose:n,cloudAccount:a}){const{usage:i,upgrade:r,dialog:c}=Gc(),o=Td(),d=o?.view.kind==="signed-out"||o?.view.kind==="removed";return e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-settings-block":"usage",className:"scroll-mt-4",children:i?e.jsx(Vc,{usage:i,upgrade:r,children:c}):e.jsx(je,{note:"settings.adminOnly.usage",children:e.jsx(Xp,{})})}),(i||s("usage"))&&e.jsxs(zt,{title:t("settings.simple.billing.limits"),...n("billing-limits"),children:[i&&e.jsx(qc,{usage:i,upgrade:r}),s("usage")&&e.jsx(je,{note:"settings.adminOnly.usage",children:e.jsx(nr,{})})]}),s("cloudAccount")&&e.jsxs(be,{label:t("settings.simple.billing.plan"),block:"cloudAccount",footnote:e.jsx(Rd,{}),children:[e.jsx(ye,{children:e.jsx(fi,{place:"plan",usage:i,upgrade:r})}),d?null:e.jsx("div",{className:"flex flex-col gap-4",children:a})]})]})}const Ar=()=>`${ws()} ${Jc()}`;function gh(){const s=Xc(!0);if(!s)return null;const n=s.phase==="idle"?void 0:[s.label,s.item.subtitle].filter(Boolean).join(" "),a=s.phase==="available"?t("settings.simple.updates.seeRelease"):s.phase==="reload"?t("settings.simple.updates.reload"):s.phase==="checking"?t("common.checking"):t("settings.updates.check");return e.jsx(ue,{title:Ar(),subtitle:n,children:e.jsx("button",{type:"button",className:"ui-button",disabled:s.item.disabled,onClick:s.item.onSelect,children:a})})}function fh({remoteActive:s}){return e.jsx(be,{block:"updates",children:e.jsxs(ye,{children:[window.ogb?.updater?e.jsx(li,{title:Ar()}):e.jsx(gh,{}),e.jsx(Za,{}),!s&&e.jsx(oi,{}),e.jsx(Ei,{simple:!0})]})})}const Sa=[{id:"you",labelKey:"settings.group.you"},{id:"ai",labelKey:"settings.group.ai"},{id:"computers",labelKey:"settings.group.computers"},{id:"account",labelKey:"settings.group.account"}],Gs=[{id:"general",group:"you",labelKey:"settings.section.general",icon:Qa,keywords:["profile","pinned panels","web panel","dashboard","pin a page","name","email","about me","about","suggestions","suggested","memory","analytics","updates","product updates","newsletter","email updates","effort","new bots","reasoning","threads","parallel","concurrency","cleanup","retention","attachments","clear attachments","event log","event-log","log size","automatic recovery","backup model","fallback","routines","conversation","schedule","usage","limit","plan","upgrade","cloud desktop hours","storage","saved steps","repeat","replay","computer tasks","without ai","forget",...Nu()]},{id:"appearance",group:"you",labelKey:"settings.section.appearance",icon:Ud,keywords:["skin","theme","appearance","font","typeface","chat width","width","wide","full width","bubble","bubbles","tools","tool calls","threads","show threads","hide threads","sidebar","display","run","this run","run card","commands","notifications","sound","sounds","mute","silent","chime","pinned","circles","universal","groups","top","send","enter","return","shift+enter","ctrl+enter","cmd+enter","⌘+enter","new line","keyboard","ime","japanese","message color","my messages","toolbar","tools layout","footer","routines","triggers","team map","color","colour","cloud color","server color","tint","sidebar color","sidebar picture","picture","image","banner","background","computers","your computers","rail","strip","frame","window frame","title bar"]},{id:"companion",group:"you",labelKey:"settings.section.companion",icon:Yc,keywords:["companion","device","phone","desktop","client","host","pair","pairing","mobile","https","secure","tailscale","wifi","remote","advanced","domain","dns","self-hosted","server","caddy"]},{id:"engines",group:"ai",labelKey:"settings.section.engines",icon:$d,keywords:["models","model providers","engines","claude","codex","grok","providers","cli","sign in","subscription"]},{id:"connections",group:"ai",labelKey:"settings.section.connections",icon:Ga,keywords:["keys","api","api key","api keys","connections","composio","box","xai","mistral","cerebras","meta","muse","vps","router","openrouter","base url","openai","anthropic","groq","greenference","modelgo","opencode","deepseek","provider","ollama","lm studio","lmstudio","llm studio","llmstudio","bionic"]},{id:"decisionModel",group:"ai",labelKey:"settings.section.decisionModel",icon:Qc,keywords:["decision","extraction","jev","typesafe","cloudflare","workers ai","clef","clairic","email","routing","auto","rooms","who answers"]},{id:"imageGeneration",group:"ai",labelKey:"settings.section.imageGeneration",icon:Zc,keywords:["image","images","picture","generate","avatar","gpt image","grok imagine","gemini","nano banana","openrouter","flux","backup"]},{id:"skills",group:"ai",labelKey:"settings.section.skills",icon:Ps,keywords:["skills","library","assign","agent skills","skill md"]},{id:"desktopWorkspaces",group:"computers",labelKey:"settings.section.desktopWorkspaces",icon:Gt,keywords:["workspace","cloud","hosted","vps","server","servers","connect","pair","switch","local"]},{id:"computer",group:"computers",labelKey:"settings.section.computer",icon:bi,keywords:["vm","virtual","desktop","browser","built-in browser","profiles","browser profiles"]},{id:"logins",group:"computers",labelKey:"settings.section.vault",icon:Dt,keywords:["vault","logins","login","passwords","password","sign in","2fa","one-time code","totp","fill_login","1password","password manager","secrets","secret","token",".env","env"]},{id:"cloudAccount",group:"account",labelKey:"settings.section.cloudAccount",icon:Rt,keywords:["cloud","my cloud","account","personal","sign in","pro","subscription","billing","sync","send","this computer","bots","logins","1password"]},{id:"organization",group:"account",labelKey:"settings.section.organization",icon:Gt,keywords:["company","organization","organisation","sign in","enroll","managed","models","disconnect"]},{id:"usage",group:"account",labelKey:"settings.section.usage",icon:Bd,keywords:["tokens","cost","billing","plan","quota","remaining","weekly","5-hour","model","used"]},{id:"backups",group:"account",labelKey:"settings.section.backups",icon:ni,keywords:["export","import","restore","full backup","password","recovery"]},{id:"import",group:"account",labelKey:"settings.section.import",icon:Ye,keywords:["import","grok","grok bot","move","cursor","claude code","codex","gemini","skills","mcp","tools","bring"]},{id:"people",group:"account",labelKey:"settings.section.people",icon:Ct,keywords:["people","users","invite","sign in","members","admins","access"]},{id:"botAccess",group:"account",labelKey:"settings.section.botAccess",icon:Ct,keywords:["access","share","sharing","who can","view","chat","edit","permissions","team","members","bots"]},{id:"activity",group:"account",labelKey:"settings.section.activity",icon:Dd,keywords:["activity","audit","log","history","who changed","approvals","decisions","admin"]},{id:"workspaces",group:"account",labelKey:"settings.section.workspaces",icon:Gt,keywords:["clients","tenants","fleet","workspaces","installation","installations"]},{id:"experimental",group:"account",labelKey:"settings.section.experimental",icon:ed,keywords:["early","preview","learn","skill","authoring"]}],bh=[{id:"general",labelKey:"settings.section.general",icon:sd,sections:["general","appearance","people","import","organization","activity"],keywords:["account","theme","looks","open at login","startup","analytics","advanced mode","more settings","limits","timeout"]},{id:"botAccess",labelKey:"settings.section.botAccess",icon:Ct,sections:["botAccess"]},{id:"ai",labelKey:"settings.group.ai",icon:nd,sections:["engines","connections","imageGeneration"],keywords:["new bots","defaults","effort"]},{id:"skills",labelKey:"settings.section.skills",icon:Ps,sections:["skills"],keywords:["skills","skill hub","library","kỹ năng","thư viện"]},{id:"computer",labelKey:"settings.simple.page.computer",icon:bi,sections:["companion","desktopWorkspaces","computer","logins"]},{id:"billing",labelKey:"settings.simple.page.billing",icon:ad,sections:["usage"],keywords:["billing","included","allowance","cloud hours","voice"]},{id:"backups",labelKey:"settings.section.backups",icon:ni,sections:["backups"],keywords:["chuyển máy offline","transfer","export","import","restore","sao lưu"]},{id:"cloudAccount",labelKey:"settings.section.cloudAccount",icon:Rt,sections:["cloudAccount"],keywords:["cloud","limix cloud","đám mây","máy chủ","server"]},{id:"updates",labelKey:"settings.simple.page.updates",icon:Md,sections:["updates"],keywords:["update","version","release","product updates","newsletter","email updates","welcome","tour","diagnostics","logs","support"]}],ks=["experimental","workspaces","decisionModel"],yh={connections:"ai-keys",remote:"computer-elsewhere",desktopWorkspaces:"computer-elsewhere"};function vh(s,n){const a=bh.map(r=>({...r,sections:r.sections.filter(c=>s.has(c))})).filter(r=>r.sections.length>0),i=ks.includes(n)&&s.has(n)?Gs.find(r=>r.id===n):void 0;return i&&a.push({id:i.id,labelKey:i.labelKey,icon:i.icon,sections:[i.id]}),a}function jh(s,n,a){if(a<=0){s.scrollTop=0;return}const i=s.querySelector(`[data-settings-block="${n}"]`);i&&Bs(s,i)}function kh(s,n){return!n||[t(s.labelKey),...s.keywords??[]].some(a=>a.toLowerCase().includes(n))?!0:s.sections.some(a=>{const i=Gs.find(r=>r.id===a);return i?Ns(i,n):!1})}function Ns(s,n){return!n||s.id==="connections"&<.some(a=>Es(a,n))?!0:[t(s.labelKey),...s.keywords].some(a=>a.toLowerCase().includes(n))}function Nh(s){return s?lt.filter(n=>Es(n,s)).slice(0,8):[]}const wh=s=>s.uses?ds(s.uses,s.id):ds(s.id);function Jh(){return e.jsx(Ta,{modal:!0,children:e.jsx(Sh,{})})}function Sh(){const s=Rl(),{state:n,dispatch:a}=W(),i=al(),r=window.ogb?.remoteClient?.active===!0,c=n.appSettingsSection,o=i&&c==="remote"&&window.ogb?.environments?"desktopWorkspaces":r&&!["appearance","desktopWorkspaces"].includes(c)||c==="remote"?"companion":i&&c==="updates"?"general":c,d=l.useRef(null),m=l.useRef(null),u=l.useRef(i),[x,p]=l.useState("");l.useEffect(()=>window.ogb?.environments?.onOpenSettings?.(()=>p("")),[]),l.useEffect(()=>window.ogb?.onOpenAppSettings?.(()=>p("")),[]);const h=x.trim().toLowerCase(),f=Ot(),y=ei(),b=Gs.map(R=>R.id==="companion"?{...R,labelKey:y?"settings.section.phoneDevices":"settings.section.thisServer"}:R),k=b.filter(R=>!r||R.id==="companion"||R.id==="appearance"||R.id==="desktopWorkspaces").filter(R=>R.id!=="desktopWorkspaces"||!!window.ogb?.environments).filter(R=>R.id!=="organization"||!!window.ogb?.organization).filter(R=>R.id!=="cloudAccount"||!!(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)).filter(R=>R.id!=="workspaces"||ir(n.config)).filter(R=>R.id!=="people"||!window.ogb&&n.config?.cloudHome!==!0).filter(R=>R.id!=="activity"||!window.ogb&&f===!0).filter(R=>R.id!=="botAccess"||!!n.config?.team&&f===!0).filter(R=>(R.id!=="skills"||wn(n.config))&&(R.id!=="cloudAccount"||Ll)),S=k.filter(R=>Ns(R,h)),C=new Set([...k.map(R=>R.id),...r?[]:["updates"]]),w=i?[]:vh(C,o),P=w.filter(R=>kh(R,h)),v=w.find(R=>R.sections.includes(o)),B=i?b.find(R=>R.id===o)?.labelKey:v?.labelKey,j=i?S.some(R=>R.id===o)?void 0:S[0]?.id:v&&P.includes(v)?void 0:P[0]&&(P[0].sections.find(R=>S.some(E=>E.id===R))??P[0].sections[0]);l.useEffect(()=>{j&&a({type:"toggleAppSettings",open:!0,section:j})},[a,j]);const[A,I]=l.useState({}),_=La();l.useEffect(()=>{_&&I(R=>R["ai-keys"]?R:{...R,"ai-keys":!0})},[_]);const U=R=>{const E=h!==""||(A[R]??yh[c]===R);return{id:R,open:E,onToggle:()=>I(H=>({...H,[R]:!E}))}},[J,K]=l.useState(null),te=J?.for===c?J.view:null,ae=(R,E=c)=>K(R&&{view:R,for:E});l.useEffect(()=>{K(R=>R?.for===c?R:null)},[c]);const[de,D]=l.useState(null),T=i||il||!h?[]:lh.filter(R=>t(R).toLowerCase().includes(h)),Z=k.filter(R=>ks.includes(R.id)),ee=r||!k.some(R=>R.id==="connections")?[]:Nh(h),fe=R=>ee.map(E=>e.jsx("button",{type:"button","data-settings-key-result":E.id,className:R,onClick:()=>{p(""),ae(null),a(wh(E))},children:e.jsxs("span",{children:[t(E.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t(id(E).titleKey)]})]})},E.id)),N=v?.sections.indexOf(o)??0,re=!i&&c==="remote"?"remote":o;l.useEffect(()=>{m.current&&jh(m.current,re,i?0:re===o?N:1)},[i,re,o,N]),l.useEffect(()=>{if(!de)return;const R=m.current?.querySelector(`[data-settings-block="${de}"]`);m.current&&R&&Bs(m.current,R),D(null)},[de]),l.useEffect(()=>{const R=document.activeElement instanceof HTMLElement?document.activeElement:null,E=d.current,H=E?.querySelector("[data-settings-search]");u.current&&H?.checkVisibility()?H.focus():E?.focus();const pe=q=>{if(!s())return;if(!u.current&&E&&document.activeElement===E&&q.key.length===1&&!q.metaKey&&!q.ctrlKey&&!q.altKey&&H?.checkVisibility()){q.preventDefault(),H.focus(),p(ze=>ze+q.key);return}if(q.defaultPrevented||E&&[...E.querySelectorAll('[role="dialog"], [role="alertdialog"]')].some(ze=>ze.getClientRects().length))return;if(q.key==="Escape"){q.preventDefault(),a({type:"toggleAppSettings",open:!1});return}if(q.key!=="Tab"||!E)return;const ke=Array.from(E.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])')).filter(ze=>ze.checkVisibility());if(ke.length===0){q.preventDefault(),E.focus();return}const Pe=ke[0],et=ke[ke.length-1],tt=document.activeElement;q.shiftKey&&(tt===Pe||!E.contains(tt))?(q.preventDefault(),et.focus()):!q.shiftKey&&tt===et&&(q.preventDefault(),Pe.focus())};return window.addEventListener("keydown",pe),()=>{window.removeEventListener("keydown",pe),R?.focus()}},[a,s]);const se=R=>a({type:"toggleAppSettings",open:!0,section:R}),ne=n.appSettingsPhonePairing,G=yd(n.config?.cloudHome===!0)==="computer",ie={client:e.jsx(np,{hideWhenUnavailable:!0,legacyOnly:!0}),domain:r||y?null:e.jsx(Jm,{}),pairing:y?null:e.jsx(td,{cloudHome:n.config?.cloudHome===!0,focusRequest:G?0:ne,team:n.config?.team?.name,teamPhoneBlocked:n.config?.managedPolicy?.remoteAccess===!1?t("policy.teamRemoteBlocked",{organization:n.config.managedPolicy.organizationName}):null,simple:!i}),companion:y?e.jsx(Pm,{profileEmail:n.config?.profile?.email,focusRequest:ne,simple:!i}):null},le=R=>{switch(R){case"desktopWorkspaces":return e.jsxs(e.Fragment,{children:[e.jsx(Xn,{}),ie.client]});case"organization":return window.ogb?.organization&&!r?e.jsx(Ji,{}):null;case"cloudAccount":return(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)&&!r?e.jsx(Hp,{linkRequest:n.appSettingsCloudLink,cloudHome:n.config?.cloudHome===!0,teamHome:n.config?.team,onConnectPhone:()=>{a({type:"toggleAppSettings",open:!1}),window.dispatchEvent(new Event("limix:phone"))},onAddCloud:i?()=>a({type:"openCloudAdd",source:"app_settings"}):void 0,onSignIn:()=>a({type:"openCloudAdd",source:"app_settings",signIn:!0})}):null;case"general":return e.jsxs(e.Fragment,{children:[e.jsx(ps,{}),e.jsx(si,{}),e.jsx(Si,{}),e.jsx(Ld,{}),e.jsx(ld,{}),e.jsxs(Y,{title:t("settings.profile.title"),subtitle:t("settings.profile.sharedSubtitle"),children:[e.jsx(gr,{}),e.jsx(fr,{})]}),e.jsx(ms,{}),e.jsx(wi,{}),e.jsx(Id,{}),e.jsx(Er,{}),e.jsx(Ni,{}),e.jsx(Za,{}),e.jsx(mi,{}),e.jsx(Y,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(dr,{})}),e.jsx(Y,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(pr,{})}),e.jsx(br,{}),e.jsx(yr,{}),e.jsx(Nr,{}),e.jsx(Ci,{}),e.jsx(Xx,{}),!r&&e.jsx(oi,{}),e.jsx(li,{}),e.jsx(Ei,{})]});case"appearance":return e.jsxs(e.Fragment,{children:[e.jsx(or,{}),e.jsx(Y,{title:t("settings.skin.title"),subtitle:t("settings.skin.subtitle"),children:e.jsx(cr,{})}),e.jsx(lr,{}),e.jsx(fp,{}),r&&e.jsx(ps,{}),r&&e.jsx(ms,{}),e.jsx(Bx,{}),e.jsx(Ox,{}),e.jsx(xi,{}),e.jsx(hi,{}),e.jsx(gi,{}),e.jsx(Mx,{}),e.jsx(ti,{}),e.jsx(Vi,{}),e.jsx(Sd,{}),e.jsx(Cd,{}),e.jsx(Ed,{}),e.jsx(Cr,{}),!r&&e.jsx(pi,{}),e.jsx(Ad,{})]});case"experimental":return e.jsx(wd,{});case"connections":return e.jsx(je,{children:e.jsx(ku,{})});case"decisionModel":return e.jsx(je,{children:e.jsx(Lu,{})});case"imageGeneration":return e.jsx(je,{children:e.jsx($u,{})});case"engines":return e.jsx(je,{children:e.jsx(Li,{})});case"backups":return e.jsxs(je,{children:[e.jsx(rd,{}),e.jsx(Yx,{})]});case"import":return e.jsx(je,{children:e.jsx(Sr,{})});case"companion":return e.jsxs(e.Fragment,{children:[ie.companion,ie.pairing,ie.domain,window.ogb?.environments?null:ie.client]});case"computer":return e.jsxs(e.Fragment,{children:[e.jsx(ci,{}),e.jsx(di,{}),e.jsx(ui,{}),e.jsx(je,{children:e.jsx(zi,{})})]});case"logins":return e.jsx(Wi,{});case"usage":return e.jsx(je,{note:"settings.adminOnly.usage",children:e.jsx(nr,{})});case"skills":return wn(n.config)?e.jsx(fx,{}):null;case"people":return e.jsx(Di,{});case"activity":return e.jsx(_i,{});case"botAccess":return e.jsx(Fm,{});case"workspaces":return e.jsx(wx,{});default:return null}},ce=()=>{se("general"),ae("more","general")},ve=R=>{const E=H=>R.sections.includes(H);switch(R.id){case"general":return te==="looks"?e.jsx(uh,{toolCalls:!r,onBack:()=>{ae(null),D("appearance")}}):te==="more"?e.jsx(mh,{sections:Z,onOpen:H=>{ae(null),se(H)},onBack:()=>{ae(null),D("more")}}):e.jsx(ch,{has:E,peopleOpen:o==="people",onLooks:()=>ae("looks"),onMore:E("general")?()=>ae("more"):void 0});case"ai":return e.jsx(ph,{has:E,disclose:U,connections:le("connections")});case"computer":return e.jsx(xh,{has:E,remoteAccess:ie,servers:e.jsx(Xn,{}),disclose:U});case"billing":return e.jsx(hh,{has:E,disclose:U,cloudAccount:le("cloudAccount")});case"updates":return e.jsx(fh,{remoteActive:r});default:return e.jsxs(e.Fragment,{children:[ks.includes(R.sections[0])&&C.has("general")&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:ce,children:t("settings.simple.looks.back")})}),R.sections.map(H=>e.jsx("section",{"data-settings-block":H,className:"flex scroll-mt-4 flex-col gap-4",children:le(H)},H))]})}},$=()=>a({type:"toggleAppSettings",open:!1}),oe=(R,E)=>e.jsxs("div",{className:R,children:[e.jsx(mt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-settings-search":!0,value:x,onChange:H=>p(H.target.value),onKeyDown:H=>{H.key==="Escape"&&(H.stopPropagation(),x?p(""):$())},placeholder:t("settings.search"),"aria-label":t("settings.searchAria"),className:E})]});if(!i){const R=v?.id==="general"?te:null,E="flex min-h-8 shrink-0 cursor-pointer items-center rounded-lg px-[9px] py-1.5 text-left text-[13px] leading-[18px] text-ink transition-colors hover:bg-ink/[0.06] motion-reduce:transition-none",H=q=>{ae(null),se(q)},pe=h?[...Z.filter(q=>Ns(q,h)).map(q=>({key:q.id,labelKey:q.labelKey,open:()=>H(q.id)})),...(C.has("general")?oh:[]).filter(q=>t(q).toLowerCase().includes(h)).map(q=>({key:q,labelKey:q,open:()=>{ce(),D("limits")}}))]:[];return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"simple",style:Cn(),onMouseDown:q=>q.stopPropagation(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:d,role:"dialog","data-look":"settings","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,style:{outline:"none"},className:"glass-surface glass-popup animate-pop-in relative flex overflow-hidden rounded-2xl text-ink",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),e.jsx(rl,{}),e.jsxs("nav",{"aria-label":t("settings.title"),className:"glass-rail hidden min-h-0 w-[198px] shrink-0 flex-col gap-0.5 overflow-y-auto px-3 py-4 sm:flex",children:[oe("mb-2 flex h-8 shrink-0 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] text-[13px] focus-within:ring-2 focus-within:ring-focus/60","w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"),P.length===0&&T.length===0&&pe.length===0&&ee.length===0&&e.jsx("div",{className:"px-[9px] py-3 text-[13px] leading-[18px] text-ink-secondary",children:t("settings.noMatch",{query:x.trim()})}),P.map(q=>{const ke=q.icon,Pe=q===v;return e.jsxs("button",{type:"button","data-settings-page":q.id,onClick:()=>H(q.sections[0]),"aria-current":Pe?"page":void 0,className:z("flex h-8 shrink-0 cursor-pointer items-center gap-[9px] rounded-lg px-[9px] text-left text-[13px] text-ink transition-colors motion-reduce:transition-none",Pe?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(ke,{size:15,"aria-hidden":"true",className:"shrink-0"}),e.jsx("span",{className:"truncate",children:t(q.labelKey)})]},q.id)}),T.map(q=>e.jsx("button",{type:"button","data-settings-advanced-only":q,onClick:()=>{p(""),H("general"),D("advanced-mode")},className:E,children:e.jsxs("span",{children:[t(q)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.advanced")]})]})},q)),pe.map(q=>e.jsx("button",{type:"button","data-settings-more-result":q.key,onClick:()=>{p(""),q.open()},className:E,children:e.jsxs("span",{children:[t(q.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.more.title")]})]})},q.key)),fe(E)]}),e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("header",{className:"flex shrink-0 items-center gap-3 py-3 pl-4 pr-14 sm:pb-1.5 sm:pl-12 sm:pt-8",children:[e.jsx(xe,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:v?.id??"",onChange:q=>{p("");const ke=w.find(Pe=>Pe.id===q.target.value);ke&&H(ke.sections[0])},children:w.map(q=>e.jsx("option",{value:q.id,children:t(q.labelKey)},q.id))}),e.jsx("h2",{className:"hidden truncate text-[17px] font-medium leading-6 tracking-[-0.008em] text-ink sm:block",children:R==="looks"?t("settings.simple.page.looks"):R==="more"?t("settings.simple.more.title"):v?t(v.labelKey):null})]}),e.jsx("button",{type:"button",onClick:$,"aria-label":t("settings.close"),title:`${t("settings.close")} (${Sn("close-panel")})`,className:"absolute right-5 top-[18px] flex size-8 cursor-pointer items-center justify-center rounded-full text-ink-secondary transition-colors hover:bg-ink/[0.06] hover:text-ink motion-reduce:transition-none",children:e.jsx($e,{size:16,"aria-hidden":"true"})}),e.jsxs("div",{ref:m,"data-settings-scroll":!0,className:z("settings-scroll flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto px-4 pb-10 pt-4 sm:px-8 sm:pb-12 sm:pt-[22px]",qa,"[&_.uppercase]:normal-case [&_.uppercase]:tracking-normal"),children:[e.jsx(da,{config:n.config}),v?ve(v):null]})]})]})]})}return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"advanced",style:Cn(),onMouseDown:R=>R.stopPropagation(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,className:"glass-surface glass-popup animate-pop-in relative flex overflow-hidden rounded-2xl outline-none",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),e.jsxs("nav",{className:"glass-rail hidden min-h-0 w-[200px] shrink-0 flex-col gap-1 overflow-y-auto border-r border-hairline/30 p-3 sm:flex",children:[e.jsx("div",{className:"shrink-0 px-2 py-3 text-[15px] font-semibold text-ink",children:t("settings.title")}),oe("mb-2 mt-1 flex h-8 shrink-0 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] text-[13px] focus-within:ring-2 focus-within:ring-focus/60","w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-tertiary focus:outline-none"),S.length===0&&e.jsx("div",{className:"px-2.5 py-4 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.noMatch",{query:x.trim()})}),Sa.map(R=>{const E=S.filter(H=>H.group===R.id);return E.length===0?null:e.jsxs("div",{role:"group","aria-labelledby":`settings-group-${R.id}`,"data-settings-group":R.id,className:"flex flex-col gap-0.5 pb-2",children:[e.jsx("div",{id:`settings-group-${R.id}`,className:"px-[9px] pb-1 pt-2 text-[12px] font-medium leading-4 text-ink-tertiary",children:t(R.labelKey)}),E.map(({id:H,labelKey:pe,icon:q})=>e.jsxs("button",{"data-settings-section":H,onClick:()=>se(H),"aria-current":o===H?"page":void 0,className:z("flex h-8 shrink-0 cursor-pointer items-center gap-[9px] rounded-lg px-[9px] text-left text-[13px] text-ink transition-colors motion-reduce:transition-none",o===H?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(q,{size:15,className:"shrink-0"}),t(pe)]},H))]},R.id)}),fe("cursor-pointer flex min-h-9 items-center rounded-lg px-2.5 py-2 text-left text-[13px] text-ink transition-colors hover:bg-control/50 motion-reduce:transition-none")]}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-hairline/30 px-3 py-3 sm:pl-9",children:[e.jsx(xe,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:o,onChange:R=>{p(""),se(R.target.value)},children:Sa.map(R=>{const E=k.filter(H=>H.group===R.id);return E.length===0?null:e.jsx("optgroup",{label:t(R.labelKey),children:E.map(({id:H,labelKey:pe})=>e.jsx("option",{value:H,children:t(pe)},H))},R.id)})}),e.jsx("span",{className:"hidden text-[15px] font-semibold text-ink sm:block",children:B?t(B):null}),e.jsx("button",{onClick:$,"aria-label":t("settings.close"),title:`${t("settings.close")} (${Sn("close-panel")})`,className:"ui-icon-button cursor-pointer shrink-0 max-md:size-9 max-md:rounded-full max-md:border max-md:border-hairline max-md:bg-card",children:e.jsx($e,{size:18})})]}),e.jsxs("div",{ref:m,className:"flex flex-1 flex-col gap-4 overflow-y-auto px-3 py-4 sm:px-5 sm:pb-5",children:[e.jsx(da,{config:n.config}),le(o)]})]})]})]})}export{Gs as SECTIONS,Sa as SETTINGS_GROUPS,yh as SIMPLE_FOLDED,ks as SIMPLE_HIDDEN_SECTIONS,bh as SIMPLE_PAGES,Jh as SettingsModal,Nh as keySearchResults,wh as openKeyResult,jh as revealSettingsBlock,Ns as sectionMatches,vh as simpleSettingsPages};
|
|
19
|
+
`)})]}),e.jsx(Qe,{open:y!==null,title:t("workspaces.deleteTitle",{slug:y?.slug??""}),body:t(y?.keepData?"workspaces.deleteKeepHint":"workspaces.deleteHint"),confirmLabel:t("workspaces.delete"),onCancel:()=>b(null),onConfirm:()=>{v()}}),y&&e.jsxs("label",{className:"flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:y.keepData,onChange:j=>b({...y,keepData:j.target.checked})}),t("workspaces.keepData")]})]}):null}const rr=s=>({method:"PUT",body:JSON.stringify(s)}),Pt=s=>s instanceof Error?s.message:String(s);function Sx(){return l.useSyncExternalStore(ri,()=>hd()?.id??null,()=>null)}function Cx(s,n){const a=URL.createObjectURL(new Blob([JSON.stringify(n,null,2)],{type:"application/json"}));Object.assign(document.createElement("a"),{href:a,download:s}).click(),setTimeout(()=>URL.revokeObjectURL(a),1e3)}function Ex({id:s,act:n,onClose:a,onDelete:i}){const[r,c]=l.useState(null),[o,d]=l.useState(null),[m,u]=l.useState(!1);if(l.useEffect(()=>{M(`/api/themes/${s}`).then(h=>c(h.theme),h=>d(Pt(h)))},[s]),!r)return e.jsx(us,{children:o??t("settings.customThemes.loading")});const x=r.css?gd(r.css):null,p=async()=>{u(!0);try{await M(`/api/themes/${s}`,rr({theme:{...r,name:r.name.trim(),css:r.css||void 0}})),d(t("settings.customThemes.saved")),await Rs()}catch(h){d(Pt(h))}finally{u(!1)}};return e.jsxs("div",{"data-settings-block":"theme-editor",className:"flex flex-col gap-3 px-4 py-3",children:[e.jsx(bn,{label:t("settings.customThemes.name"),children:e.jsx("input",{className:yn,value:r.name,maxLength:60,onChange:h=>c({...r,name:h.target.value})})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:["canvas","accent"].map(h=>e.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-ink",children:[e.jsx("input",{type:"color",className:"size-7 cursor-pointer rounded-md bg-transparent",value:r[h]??(h==="canvas"?"#121212":"#1084fe"),onChange:f=>c({...r,[h]:f.target.value})}),t(h==="canvas"?"settings.customThemes.canvas":"settings.customThemes.accent"),r[h]&&e.jsx("button",{type:"button",className:"text-[12px] text-accent-text hover:underline",onClick:()=>c({...r,[h]:void 0}),children:t("settings.customThemes.clear")})]},h))}),e.jsx(bn,{label:t("settings.customThemes.css"),hint:x??t("settings.customThemes.cssHint"),children:e.jsx("textarea",{className:`${yn} h-64 resize-y py-2 font-mono text-[12px]`,spellCheck:!1,maxLength:fd.cssChars,"aria-label":t("settings.customThemes.css"),value:r.css??"",onChange:h=>c({...r,css:h.target.value})})}),e.jsxs(dc,{status:o,children:[e.jsxs("div",{className:"mr-auto flex flex-wrap gap-1.5",children:[e.jsx("button",{type:"button",className:"ui-button ui-button-sm",onClick:()=>{n(()=>M(`/api/themes/${s}/duplicate`,{method:"POST",body:JSON.stringify({name:t("settings.customThemes.copyName",{name:r.name}).slice(0,60)})}))},children:t("settings.customThemes.duplicate")}),e.jsx("button",{type:"button",className:"ui-button ui-button-sm",onClick:()=>{n(async()=>Cx(`${s}.mausbot-theme.json`,await M(`/api/themes/${s}/export`)))},children:t("settings.customThemes.export")}),e.jsx("button",{type:"button",className:"ui-button ui-button-sm","data-danger":"",onClick:i,children:t("common.delete")})]}),e.jsx("button",{type:"button",className:"ui-button",onClick:a,children:t("common.cancel")}),e.jsx("button",{type:"button",className:"ui-button ui-button-primary",disabled:m||!!x||!r.name.trim(),onClick:()=>{p()},children:t("common.save")})]})]})}const Ax=6;function Ix(s){const n=s.name??"";switch(s.kind){case"made":return t("settings.customThemes.historyMade",{name:n});case"edited":return t("settings.customThemes.historyEdited",{name:n});case"deleted":return t("settings.customThemes.historyDeleted",{name:n});case"wore":return t("settings.customThemes.historyWore",{name:n});case"skin":return t("settings.customThemes.historySkin",{name:Lt.find(a=>a.id===n)?.name??n});case"default":return t("settings.customThemes.historyDefault");case"undid":return t("settings.customThemes.historyUndid")}}function Px({items:s,act:n}){return s.length<2?null:e.jsx(be,{label:t("settings.customThemes.history"),block:"theme-history",description:t("settings.customThemes.historyHint"),children:e.jsx(ye,{children:s.slice(0,Ax).map(a=>e.jsx(ue,{title:Ix(a),subtitle:ii(Date.parse(a.at)),children:a.index===1?e.jsx("span",{className:"text-[12px] text-ink-tertiary",children:t("settings.customThemes.historyNow")}):e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{n(async()=>{await M("/api/themes/history",{method:"POST",body:JSON.stringify({index:a.index})}),await Rs()})},children:t("settings.customThemes.restore")})},a.index))})})}function lr(){const[s,n]=l.useState(null),[a,i]=l.useState(null),[r,c]=l.useState(null),o=l.useRef(null),d=Sx(),[m,u]=l.useState([]),x=l.useCallback(()=>Promise.all([M("/api/themes").then(n,g=>c(Pt(g))),M("/api/themes/history").then(g=>u(g.items),()=>u([]))]),[]);l.useEffect(()=>(x(),ri(()=>{x()})),[x]);const p=async g=>{c(null);try{await g()}catch(k){c(Pt(k))}await x()},h=()=>p(async()=>{const g=`theme-${Date.now().toString(36)}`;await M(`/api/themes/${g}`,rr({theme:{name:t("settings.customThemes.newName")}})),i(g)}),f=g=>g&&p(async()=>{let k;try{k=JSON.parse(await g.text())}catch{throw new Error(t("settings.customThemes.importFailed"))}await M("/api/themes/import",{method:"POST",body:JSON.stringify(k)})}),y=(g,k)=>p(async()=>{const S=await M(`/api/themes/${g}/export`);await M(`/api/themes/${g}`,{method:"DELETE"}),i(null),await Rs(),c(e.jsxs(e.Fragment,{children:[t("settings.customThemes.deleted",{name:k})," ",e.jsx("button",{type:"button",className:"text-accent-text hover:underline",onClick:()=>{p(()=>M("/api/themes/import",{method:"POST",body:JSON.stringify(S)}))},children:t("common.undo")})]}))}),b=cc()?"⌘⌥⇧R":"Ctrl+Alt+Shift+R";return e.jsxs(e.Fragment,{children:[e.jsx(be,{label:t("settings.customThemes.title"),block:"custom-themes",description:t("settings.customThemes.description"),actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>o.current?.click(),children:t("settings.customThemes.import")}),e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{h()},children:t("settings.customThemes.new")}),e.jsx("input",{ref:o,type:"file",accept:"application/json,.json",hidden:!0,onChange:g=>{f(g.target.files?.[0]),g.target.value=""}})]}),footnote:r,children:e.jsxs(ye,{children:[pd()&&e.jsx(us,{children:t("settings.customThemes.safe")}),s&&!s.themes.length&&e.jsx(us,{children:t("settings.customThemes.empty")}),s?.themes.map(g=>a===g.id?e.jsx(Ex,{id:g.id,act:p,onClose:()=>{i(null),x()},onDelete:()=>{y(g.id,g.name)}},g.id):e.jsx(ue,{title:g.name,subtitle:d===g.id?t("settings.customThemes.inUse"):g.assets.length?t("settings.customThemes.files",{count:g.assets.length}):void 0,children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",className:"ui-button",onClick:()=>i(g.id),children:t("settings.customThemes.edit")}),d===g.id?e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{p(()=>An(null))},children:t("settings.customThemes.takeOff")}):e.jsx("button",{type:"button",className:"ui-button ui-button-primary",onClick:()=>{p(()=>An(g.id))},children:t("settings.customThemes.use")})]})},g.id)),e.jsx(ue,{title:t("settings.customThemes.reset"),subtitle:t("settings.customThemes.resetHint",{keys:b}),children:e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{xd(),x()},children:t("settings.customThemes.reset")})})]})}),e.jsx(Px,{items:m,act:p})]})}const ua=[{choice:"system",label:"settings.theme.system"},{choice:en.light,label:"settings.theme.light"},{choice:en.dark,label:"settings.theme.dark"}];function Ws(){return l.useSyncExternalStore(Vr,tn,tn)}function or({simple:s=!1}){const n=Ws(),a=ua.some(i=>i.choice===n)?void 0:Lt.find(i=>i.id===n)?.name;return e.jsx(ue,{title:t(s?"settings.theme.lightOrDark":"settings.theme.title"),subtitle:a?t("settings.theme.look",{name:a}):s?void 0:t("settings.theme.subtitle"),children:e.jsx("div",{role:"radiogroup","aria-label":t(s?"settings.theme.lightOrDark":"settings.theme.title"),className:s?"inline-flex h-7 rounded-full bg-ink/[0.06] p-0.5":"inline-flex rounded-full bg-inset p-0.5",children:ua.map(i=>e.jsx("button",{type:"button",role:"radio","aria-checked":n===i.choice,onClick:()=>Gr(i.choice),className:s?z("h-6 rounded-full px-2.5 text-[13px] transition-colors",n===i.choice?"bg-ink/[0.12] text-ink":"text-ink-secondary hover:text-ink"):z("rounded-full px-3 py-1 text-[13px] font-medium transition-colors",n===i.choice?"bg-raised text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:t(s&&i.choice==="system"?"settings.simple.theme.system":i.label)},i.choice))})})}function Tx({skin:s}){return e.jsxs("div",{"data-skin":s,"data-skin-preview":"","aria-hidden":"true",className:"flex h-[78px] w-full overflow-hidden rounded-lg bg-app ring-1 ring-hairline/60",children:[e.jsxs("div",{className:"flex w-[11px] shrink-0 flex-col items-center gap-[3px] bg-panel pt-[5px]",children:[e.jsx("span",{className:"size-[5px] rounded-full bg-accent"}),e.jsx("span",{className:"size-[5px] rounded-full bg-ink-secondary/40"}),e.jsx("span",{className:"size-[5px] rounded-full bg-ink-secondary/40"})]}),e.jsxs("div",{className:"flex w-[30px] shrink-0 flex-col gap-[3px] border-r border-hairline bg-panel p-[4px]",children:[e.jsxs("span",{className:"flex h-[9px] w-full items-center gap-[2px] rounded-sm bg-raised px-[2px]",children:[e.jsx("span",{className:"size-[4px] shrink-0 rounded-full bg-accent"}),e.jsx("span",{className:"h-[2px] flex-1 rounded-full bg-ink/50"})]}),e.jsx("span",{className:"h-[3px] w-[80%] rounded-full bg-ink-secondary/30"}),e.jsx("span",{className:"h-[3px] w-[62%] rounded-full bg-ink-secondary/30"}),e.jsx("span",{className:"h-[3px] w-[74%] rounded-full bg-ink-secondary/30"})]}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-[4px] p-[6px]",children:[e.jsx("span",{className:"h-[13px] w-[62%] self-end rounded-md bg-bubble-user"}),e.jsxs("div",{className:"flex w-[88%] flex-col gap-[3px] rounded-md bg-card p-[4px]",children:[e.jsx("span",{className:"h-[2px] w-full rounded-full bg-ink/45"}),e.jsx("span",{className:"h-[2px] w-[85%] rounded-full bg-ink/45"}),e.jsx("span",{className:"h-[2px] w-[60%] rounded-full bg-ink-secondary/40"})]}),e.jsxs("div",{className:"mt-auto flex items-center gap-[4px]",children:[e.jsx("span",{className:"h-[11px] flex-1 rounded-full bg-inset ring-1 ring-hairline"}),e.jsx("span",{className:"flex size-[11px] items-center justify-center rounded-full bg-accent",children:e.jsx("span",{className:"h-[1.5px] w-[5px] rounded-full",style:{background:"var(--color-accent-ink)"}})})]})]})]})}const Rx={halloween:["orange","purple","teal","red"],diwali:["red","orange","pink","coral"]};function Lx({festival:s}){const n=Cl(),a=t("settings.skin.dressUp.title");return e.jsxs("div",{"data-dress-up":!0,className:"mt-4 flex items-center gap-4 rounded-xl border border-accent-border/40 bg-accent/[0.06] p-3",children:[e.jsx("div",{className:"flex shrink-0 -space-x-1.5","aria-hidden":"true",children:Rx[s].map(i=>e.jsx(El,{color:i,bodyId:Al[s].costumes[i],size:30,animated:!1,trackPointer:!1},i))}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:a}),e.jsx("div",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.skin.dressUp.subtitle")})]}),e.jsx(me,{checked:n,"aria-label":a,onClick:()=>Il(!n)})]})}function cr(){const s=Ea(Ws());return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:Lt.map(n=>{const a=n.id===s;return e.jsxs("button",{type:"button",onClick:()=>{Jr(n.id),bd()},"aria-pressed":a,className:z("cursor-pointer flex flex-col gap-2 rounded-xl border p-2 text-left transition-colors",a?"border-accent-border bg-control":"border-hairline/60 hover:border-hairline hover:bg-control/50"),children:[e.jsx(Tx,{skin:n.id}),e.jsxs("div",{className:"flex items-start gap-1.5 px-0.5 pb-0.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n.name}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-ink-secondary",children:qr(`skins.tagline.${n.id}`,n.tagline)})]}),a&&e.jsx(ge,{size:13,className:"mt-0.5 shrink-0 text-accent-text"})]})]},n.id)})}),Sl(s)&&e.jsx(Lx,{festival:s})]})}function Bx(){const[s,n]=l.useState(Xr);return e.jsx(ue,{title:t("settings.font.title"),subtitle:t("settings.font.subtitle"),children:e.jsx(xe,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.font.aria"),onChange:a=>{const i=a.target.value;Qr(i),n(i)},children:Yr.map(a=>e.jsx("option",{value:a,children:t(`settings.font.${a}`)},a))})})}function Ox(){const[s,n]=l.useState(Zr);return e.jsx(ue,{title:t("settings.chatWidth.title"),subtitle:t("settings.chatWidth.subtitle"),children:e.jsx(xe,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("settings.chatWidth.aria"),onChange:a=>{const i=sn.find(r=>r===a.target.value);i&&(el(i),n(i))},children:sn.map(a=>e.jsx("option",{value:a,children:t(`settings.chatWidth.${a}`)},a))})})}function Mx(){const s=uc();return e.jsx(ue,{title:t("sidebar.toolsLayout.title"),subtitle:t("sidebar.toolsLayout.subtitle"),children:e.jsx(xe,{size:"sm",className:"w-full max-w-[240px]",value:s,"aria-label":t("sidebar.toolsLayout.chooseAria"),onChange:n=>pc(xc(n.target.value)),children:mc.map(n=>e.jsx("option",{value:n,children:t(`sidebar.toolsLayout.${n}`)},n))})})}function dr(){const{state:s,dispatch:n}=W(),a=s.config?.rooms.turnTimeoutMinutes??5,[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,x]=l.useState(!1),p=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const h=async()=>{if(!c||p.current)return;const f=fc(i);if(!f.ok){m(t("settings.roomTurns.range"));return}p.current=!0,x(!0);try{const y=await M("/api/config",{method:"PUT",body:JSON.stringify({rooms:{turnTimeoutMinutes:f.minutes}})});n({type:"configStatus",config:y}),r(String(y.rooms.turnTimeoutMinutes)),o(!1),m("")}catch(y){m(y instanceof Error?y.message:t("settings.roomTurns.error"))}finally{p.current=!1,x(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"room-turn-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.roomTurns.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${d?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"room-turn-timeout",type:"number",min:gc,max:hc,step:1,inputMode:"numeric",value:i,disabled:u,"aria-invalid":!!d,"aria-describedby":d?"room-turn-timeout-error room-turn-timeout-help":"room-turn-timeout-help",onChange:f=>{r(f.target.value),o(!0),m("")},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.roomTurns.minutes")})]}),e.jsx("p",{id:"room-turn-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.roomTurns.help")}),d?e.jsx("p",{id:"room-turn-timeout-error",role:"alert",className:"text-[12px] text-danger",children:d}):null]})}const zx=10,ur=1,mr=60,ma="Enter a whole number from 1 to 60.";function Ux(s){const n=s.trim();if(!/^\d+$/.test(n))return{ok:!1,error:ma};const a=Number(n);return a<ur||a>mr?{ok:!1,error:ma}:{ok:!0,minutes:a}}function pa(s){return s?.mcp?.callTimeoutMinutes??zx}function pr(){const{state:s,dispatch:n}=W(),a=pa(s.config),[i,r]=l.useState(String(a)),[c,o]=l.useState(!1),[d,m]=l.useState(""),[u,x]=l.useState(!1),p=l.useRef(!1);l.useEffect(()=>{c||r(String(a))},[a,c]);const h=async()=>{if(!c||p.current)return;const f=Ux(i);if(!f.ok){m(t("settings.mcpCalls.range"));return}p.current=!0,x(!0);try{const y=await M("/api/config",{method:"PUT",body:JSON.stringify({mcp:{callTimeoutMinutes:f.minutes}})});n({type:"configStatus",config:y}),r(String(pa(y))),o(!1),m("")}catch(y){m(y instanceof Error?y.message:t("settings.mcpCalls.error"))}finally{p.current=!1,x(!1)}};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"mcp-call-timeout",className:"text-[13px] font-medium text-ink",children:t("settings.mcpCalls.label")}),e.jsxs("div",{className:`flex max-w-[220px] items-center rounded-lg border bg-inset ${d?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"mcp-call-timeout",type:"number",min:ur,max:mr,step:1,inputMode:"numeric",value:i,disabled:u,"aria-invalid":!!d,"aria-describedby":d?"mcp-call-timeout-error mcp-call-timeout-help":"mcp-call-timeout-help",onChange:f=>{r(f.target.value),o(!0),m("")},onBlur:()=>{h()},onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.mcpCalls.minutes")})]}),e.jsx("p",{id:"mcp-call-timeout-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.mcpCalls.help")}),d?e.jsx("p",{id:"mcp-call-timeout-error",role:"alert",className:"text-[12px] text-danger",children:d}):null]})}function xr(s,n){let a={value:s,status:"idle"},i=!1,r,c;const o=new Set,d=(u,x)=>{a={value:u,status:x};for(const p of o)p()},m=()=>(clearTimeout(c),r||(i?(d(a.value,"saving"),r=(async()=>{try{for(;i;){const u=a.value;await n(u),i=a.value!==u}d(a.value,"saved")}catch{d(a.value,"error")}})().finally(()=>{r=void 0}),r):Promise.resolve()));return{getSnapshot:()=>a,subscribe(u){return o.add(u),()=>{o.delete(u)}},confirm(u){!i&&!r&&u!==a.value&&d(u,"idle")},edit(u){i=!0,d(u,"idle"),clearTimeout(c),c=setTimeout(()=>{m()},600)},flush:m}}const xa=new WeakMap;function Fx(){const{state:s,dispatch:n}=W(),a=s.config?.profile?.aboutMe??"",i=!!s.config?.team;let r=xa.get(n);if(!r){const u={current:i};r={team:u,controller:xr(a,async x=>{const p=u.current?await Is({aboutMe:x}):(await M("/api/config",{method:"PUT",body:JSON.stringify({profile:{aboutMe:x}}),timeoutMs:1e4})).profile;n({type:"profileSaved",profile:{aboutMe:p?.aboutMe??x}})})},xa.set(n,r)}r.team.current=i;const c=r.controller,{value:o,status:d}=l.useSyncExternalStore(c.subscribe,c.getSnapshot,c.getSnapshot),{flush:m}=c;return l.useEffect(()=>{c.confirm(a)},[c,a]),l.useEffect(()=>()=>{m()},[m]),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{htmlFor:"profile-about-me",className:"text-[14px] text-ink",children:t("settings.profile.aboutMe")}),e.jsxs("details",{className:"group relative",children:[e.jsx("summary",{title:t("settings.profile.aboutMeHelp"),"aria-label":t("settings.profile.aboutMeHelp"),className:"flex size-6 cursor-pointer list-none items-center justify-center rounded-md text-ink-secondary hover:text-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70 [&::-webkit-details-marker]:hidden",children:e.jsx(bc,{size:14,"aria-hidden":"true"})}),e.jsx("p",{className:"absolute left-0 z-30 mt-1 w-56 rounded-xl border border-hairline bg-panel p-3 text-[12px] text-ink-secondary shadow-xl",children:t("settings.profile.aboutMeHelp")})]})]}),e.jsx("textarea",{id:"profile-about-me",value:o,rows:5,maxLength:i?4e3:24e3,onChange:u=>c.edit(u.target.value),onBlur:()=>{m()},className:"min-h-[120px] w-full resize-y rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none"}),e.jsx(Dx,{onChanged:u=>{c.confirm(u),n({type:"profileSaved",profile:{aboutMe:u}})}}),e.jsxs("div",{className:"min-h-4 text-[12px]",role:"status",children:[d==="saving"&&e.jsx("span",{className:"text-ink-secondary",children:t("settings.profile.saving")}),d==="saved"&&e.jsx("span",{className:"text-success",children:t("settings.profile.saved")}),d==="error"&&e.jsxs("span",{className:"text-danger",children:[t("settings.profile.saveError")," "," ",e.jsx("button",{type:"button",onClick:()=>{m()},className:"underline",children:t("settings.profile.retry")})]})]})]})}function Dx({onChanged:s}){const[n,a]=l.useState([]),[i,r]=l.useState(null),[c,o]=l.useState(!1);l.useEffect(()=>{let m=!1;return M("/api/profile/learned").then(u=>{m||a(u.learned)}).catch(()=>{}),()=>{m=!0}},[]);const d=async m=>{r(m),o(!1);try{const u=await M(`/api/profile/learned/${encodeURIComponent(m)}/remove`,{method:"POST"});a(u.learned),s(u.aboutMe)}catch{o(!0)}finally{r(null)}};return n.length?e.jsxs("div",{className:"mt-1 rounded-lg border border-hairline/40 bg-inset p-3",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:t("settings.profile.learned.title")}),e.jsx("p",{className:"mt-0.5 text-[12px] text-ink-secondary",children:t("settings.profile.learned.hint")}),e.jsx("ul",{className:"mt-2 flex flex-col gap-2",children:n.map(m=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 text-[13px] text-ink",children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[m.text," ",e.jsx("span",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.learned.from",{name:m.botName})})]}),e.jsx("button",{type:"button",disabled:i===m.id,onClick:()=>{d(m.id)},className:"rounded-md px-2 py-1 text-[13px] text-ink-secondary hover:bg-control hover:text-ink disabled:opacity-50",children:t("settings.profile.learned.remove")})]},m.id))}),c&&e.jsx("div",{className:"mt-2 text-[12px] text-danger",children:t("settings.profile.learned.error")})]}):null}const ha=new WeakMap;function _x(){const{state:s,dispatch:n}=W(),a=s.config?.everyBotRules;let i=ha.get(n);i||(i=xr(a??"",async u=>{const x=await M("/api/config",{method:"PUT",body:JSON.stringify({everyBotRules:u}),timeoutMs:1e4});n({type:"configStatus",config:x})}),ha.set(n,i));const{value:r,status:c}=l.useSyncExternalStore(i.subscribe,i.getSnapshot,i.getSnapshot),{confirm:o,edit:d,flush:m}=i;return l.useEffect(()=>{o(a??"")},[o,a]),l.useEffect(()=>()=>{m()},[m]),a===void 0?null:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:"profile-every-bot-rules",className:"text-[14px] text-ink",children:t("settings.profile.everyBotRules")}),e.jsx("textarea",{id:"profile-every-bot-rules",value:r,rows:4,maxLength:24e3,placeholder:t("settings.profile.everyBotRulesPlaceholder"),onChange:u=>d(u.target.value),onBlur:()=>{m()},className:"min-h-[96px] w-full resize-y rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none"}),e.jsxs("div",{className:"min-h-4 text-[12px]",role:"status",children:[c==="saving"&&e.jsx("span",{className:"text-ink-secondary",children:t("settings.profile.saving")}),c==="saved"&&e.jsx("span",{className:"text-success",children:t("settings.profile.saved")}),c==="error"&&e.jsxs("span",{className:"text-danger",children:[t("settings.profile.saveError")," "," ",e.jsx("button",{type:"button",onClick:()=>{m()},className:"underline",children:t("settings.profile.retry")})]})]})]})}const ga=64,fa=8192,kt=512;function $x(s){return jc(s)?s.size>kc?"settings.profile.avatar.tooLarge":null:"settings.profile.avatar.invalidType"}function Kx(s,n){return s<ga||n<ga?"settings.profile.avatar.tooSmall":s>fa||n>fa?"settings.profile.avatar.tooLargeDimensions":null}async function hr(s,n){const a=URL.createObjectURL(s);try{const i=await new Promise((r,c)=>{const o=new Image;o.onload=()=>r(o),o.onerror=()=>c(new Error("invalid-image")),o.src=a});if(i.naturalWidth<=0||i.naturalHeight<=0)throw new Error("invalid-image");return await n(i)}finally{URL.revokeObjectURL(a)}}function Hx(s,n){return hr(s,async a=>{const i=Math.min(a.naturalWidth,a.naturalHeight)/Math.max(1,n),r=document.createElement("canvas");r.width=kt,r.height=kt;const c=r.getContext("2d");if(!c)throw new Error("canvas-unavailable");c.drawImage(a,(a.naturalWidth-i)/2,(a.naturalHeight-i)/2,i,i,0,0,kt,kt);const o=await new Promise((d,m)=>r.toBlob(u=>u?d(u):m(new Error("image-encode-failed")),"image/webp",.9));return new File([o],"profile-photo.webp",{type:"image/webp"})})}function Wx(){const{state:s,dispatch:n}=W(),a=s.config?.profile?.avatarUrl??"",[i,r]=l.useState(!1),[c,o]=l.useState(null),[d,m]=l.useState(null),u=l.useRef(null),x=g=>{const k=u.current;k&&k.previewUrl!==g?.previewUrl&&URL.revokeObjectURL(k.previewUrl),u.current=g,m(g)};l.useEffect(()=>()=>{u.current&&URL.revokeObjectURL(u.current.previewUrl)},[]);const p=!!s.config?.team,h=async g=>{const k=p?await Is({avatarUrl:g}):(await M("/api/config",{method:"PUT",body:JSON.stringify({profile:{avatarUrl:g}})})).profile;n({type:"profileSaved",profile:{avatarUrl:k?.avatarUrl}})},f=g=>{if(!g)return;o(null);const k=$x(g);if(k)return o(t(k));hr(g,S=>({width:S.naturalWidth,height:S.naturalHeight})).then(({width:S,height:C})=>{const w=Kx(S,C);if(w)return o(t(w));x({file:g,previewUrl:URL.createObjectURL(g),width:S,height:C,zoom:1})},()=>o(t("settings.profile.avatar.invalidType")))},y=g=>{r(!0),o(null),Hx(g.file,g.zoom).then(k=>vc(k)).then(k=>{const S=k?Pl(k.path):null;if(!S)throw new Error("avatar");return h(S)}).then(()=>x(null),()=>o(t("settings.profile.avatar.saveError"))).finally(()=>r(!1))},b=()=>{o(null),h("").catch(()=>o(t("settings.profile.avatar.saveError")))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[d?e.jsx("div",{className:"flex w-full flex-col gap-2 rounded-lg border border-hairline/40 bg-inset p-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-16 shrink-0 overflow-hidden rounded-full bg-raised",children:e.jsx("img",{src:d.previewUrl,alt:"",className:"size-full object-cover",style:{transform:`scale(${d.zoom})`}})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink",children:t("settings.profile.avatar.cropTitle")}),e.jsxs("div",{className:"text-[11px] text-ink-secondary",children:[d.width," × ",d.height,"px"]}),e.jsxs("label",{className:"mt-1 block text-[11px] text-ink-secondary",children:[t("settings.profile.avatar.zoom"),e.jsx("input",{"aria-label":t("settings.profile.avatar.zoom"),type:"range",min:"1",max:"2.5",step:"0.05",value:d.zoom,onChange:g=>x({...d,zoom:Number(g.target.value)}),className:"ml-2 w-28 align-middle accent-accent"})]})]}),e.jsx("button",{type:"button",className:"rounded-md px-2 py-1 text-[12px] text-ink-secondary hover:bg-control",onClick:()=>x(null),children:t("settings.profile.avatar.cancel")}),e.jsx("button",{type:"button",className:"rounded-md bg-control px-2 py-1 text-[12px] text-ink hover:bg-raised-hover",disabled:i,onClick:()=>y(d),children:t("settings.profile.avatar.save")})]})}):a?e.jsx("img",{...os("person","picture"),src:a,alt:"",className:"size-12 rounded-full object-cover"}):e.jsx("div",{...os("person","initials"),className:"size-12 rounded-full bg-raised"}),e.jsxs("label",{className:"cursor-pointer rounded-lg bg-control px-3 py-2 text-[12px] text-ink hover:bg-raised-hover",children:[i?t("settings.profile.avatar.uploading"):t("settings.profile.avatar.choose"),e.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"sr-only",disabled:i,onChange:g=>{const k=g.target.files?.[0];g.currentTarget.value="",f(k)}})]}),a&&!d&&e.jsx("button",{type:"button",className:"text-[12px] text-ink-secondary underline",onClick:b,children:t("settings.profile.avatar.remove")})]}),c&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:c})]})}function gr(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(s.config?.profile?.name??""),[r,c]=l.useState(s.config?.profile?.email??"");l.useEffect(()=>{i(s.config?.profile?.name??""),c(s.config?.profile?.email??"")},[s.config?.profile?.name,s.config?.profile?.email]);const o=!!s.config?.team,d=()=>{if(o){Is({name:a.trim()}).then(u=>n({type:"profileSaved",profile:{name:u.name,email:u.email}})).catch(()=>{});return}fetch("/api/config",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({profile:{name:a.trim(),email:r.trim().toLowerCase()}})}).then(u=>{if(!u.ok)throw new Error("Profile save failed");return u.json()}).then(u=>{u.profile&&n({type:"profileSaved",profile:{name:u.profile.name,email:u.profile.email}})}).catch(()=>{})},m="w-full rounded-lg border border-hairline/40 bg-inset px-3 py-2 text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none";return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Wx,{}),e.jsx("input",{"aria-label":t("settings.profile.name"),value:a,onChange:u=>i(u.target.value),onBlur:d,placeholder:t("settings.profile.name"),className:m}),e.jsx("input",{type:"email","aria-label":t("phone.signIn.email"),value:r,onChange:u=>c(u.target.value),onBlur:o?void 0:d,readOnly:o,placeholder:t("common.emailPlaceholder"),className:m}),e.jsx(Fx,{}),e.jsx(_x,{})]})}function Gx({profile:s}){const[n,a]=l.useState(null),i=yc(s),r=s?.avatarUrl&&n!==s.avatarUrl?s.avatarUrl:null;return e.jsx("span",{...os("person",r?"picture":"initials"),className:"flex size-11 shrink-0 items-center justify-center overflow-hidden rounded-full bg-ink/[0.06] text-[15px] font-medium text-ink-secondary",children:r?e.jsx("img",{src:r,alt:"",onError:()=>a(r),className:"size-full object-cover"}):i!=="?"?i:e.jsx(Qa,{size:20,"aria-hidden":"true"})})}function Vx(){const{state:s}=W(),[n,a]=l.useState(!1),i=s.config?.profile,r=i?.name?.trim()??"",c=i?.email?.trim()??"",o=l.useId(),d=l.useRef(null);return l.useEffect(()=>{n&&d.current?.querySelector("input:not([type=file])")?.focus()},[n]),e.jsxs("div",{"data-profile-summary":"",className:"px-4 py-[13px]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(Gx,{profile:i}),e.jsx("div",{className:"min-w-0 flex-1",children:r||c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:r||c}),r&&c&&e.jsx("div",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:c})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"truncate text-[14px] leading-5 text-ink",children:t("settings.simple.account.yourName")}),e.jsx("div",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",children:t("settings.simple.account.noNameHint")})]})}),e.jsx("button",{type:"button","aria-expanded":n,"aria-controls":o,className:"ui-button shrink-0",onClick:()=>a(!n),children:n?t("common.done"):t(r||c?"settings.simple.account.edit":"settings.simple.account.add")})]}),e.jsx("div",{id:o,ref:d,hidden:!n,className:"mt-4",children:n&&e.jsx(gr,{})})]})}function fr({row:s=!1}){const n=!!W().state.config?.team,[a,i]=l.useState(null),[r,c]=l.useState(!1),o=l.useId();l.useEffect(()=>{if(!n)return;let m=!0;return M("/api/me/away-emails",{timeoutMs:1e4}).then(u=>{m&&i(u.on)},()=>{}),()=>{m=!1}},[n]);const d=m=>{const u=a;i(m),c(!1),M("/api/me/away-emails",{method:"PUT",body:JSON.stringify({on:m}),timeoutMs:1e4}).then(x=>i(x.on),()=>{i(u),c(!0)})};return!n||a===null?null:e.jsxs("div",{className:s?"flex flex-col gap-1 px-4 py-[13px]":"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{id:o,className:"text-[14px] text-ink",children:t("settings.profile.awayEmails")}),e.jsx(me,{"aria-labelledby":o,checked:a,onClick:()=>d(!a)})]}),e.jsx("div",{className:"text-[12px] text-ink-secondary",children:t("settings.profile.awayEmailsHelp")}),r&&e.jsx("div",{role:"alert",className:"text-[12px] text-danger",children:t("settings.profile.awayEmailsError")})]})}function br(){const{state:s,dispatch:n}=W(),a=s.config?.threads?.maxConcurrentPerBot??3,i=s.config?.cloudStarter===!0,[r,c]=l.useState(null),[o,d]=l.useState(""),m=l.useRef(!1),u=async x=>{if(!(m.current||x===a)){m.current=!0,c(x),d("");try{const p=await M("/api/config",{method:"PATCH",body:JSON.stringify({threads:{maxConcurrentPerBot:x}})});n({type:"configStatus",config:p})}catch(p){d(p instanceof Error?p.message:t("settings.threads.error"))}finally{m.current=!1,c(null)}}};return e.jsxs(Y,{title:t("settings.threads.title"),subtitle:t("settings.threads.subtitle"),children:[e.jsx("label",{htmlFor:"thread-concurrency",className:"block text-[13px] font-medium text-ink",children:t("settings.threads.label")}),e.jsx(xe,{className:"mt-2",id:"thread-concurrency",value:r??a,disabled:r!==null||i,"aria-describedby":"thread-concurrency-help",onChange:x=>{u(Number(x.target.value))},children:Array.from({length:16},(x,p)=>p+1).map(x=>e.jsx("option",{value:x,children:x},x))}),e.jsx("p",{id:"thread-concurrency-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:i?t("settings.threads.starter"):t("settings.threads.helpHanded")}),r!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threads.saving")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}function yr(){const{state:s,dispatch:n}=W(),[a,i]=l.useState(null),[r,c]=l.useState(!1),[o,d]=l.useState(""),m=l.useRef(!1),u=a??s.config?.automaticRecovery??{enabled:!1},x=s.instances.filter(g=>g.snapshot.state==="available"&&!g.policy),p=x.find(g=>g.instanceId===u.backup?.instanceId),h=p?.models.options.filter(g=>!g.orgBlocked&&!g.needsCliUpdate&&(p.snapshot.authenticated!==!1||g.custom))??[],f=h.some(g=>g.id===u.backup?.model),y=g=>{i(g),d("")},b=async()=>{if(!(!a||m.current||u.enabled&&!f)){m.current=!0,c(!0),d("");try{const g=await M("/api/config",{method:"PUT",body:JSON.stringify({automaticRecovery:{enabled:a.enabled,...a.backup?.model?{backup:a.backup}:{}}})});n({type:"configStatus",config:g}),i(null)}catch(g){d(g instanceof Error?g.message:t("settings.recovery.error"))}finally{m.current=!1,c(!1)}}};return e.jsxs(Y,{title:t("settings.recovery.title"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("label",{htmlFor:"automatic-recovery-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.recovery.enable")}),e.jsx(me,{id:"automatic-recovery-enabled",checked:u.enabled,disabled:r||!s.config,"aria-describedby":"automatic-recovery-help automatic-recovery-scope automatic-recovery-own",onClick:()=>y({...u,enabled:!u.enabled})})]}),e.jsx("p",{id:"automatic-recovery-help",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.help")}),e.jsx("p",{id:"automatic-recovery-scope",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.scopeHanded")}),e.jsx("p",{id:"automatic-recovery-own",className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.ownBackups")}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-engine",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.engine")}),e.jsxs(xe,{className:"mt-2 w-full",id:"automatic-recovery-engine",value:u.backup?.instanceId??"",disabled:r||!u.enabled,onChange:g=>y({enabled:u.enabled,...g.target.value?{backup:{instanceId:g.target.value,model:""}}:{}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseEngine")}),u.backup&&!p&&e.jsx("option",{value:u.backup.instanceId,disabled:!0,children:t("settings.recovery.unavailable",{name:u.backup.instanceId})}),x.map(g=>e.jsx("option",{value:g.instanceId,disabled:!g.models.options.some(k=>g.snapshot.authenticated!==!1||k.custom),children:g.displayName},g.instanceId))]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("label",{htmlFor:"automatic-recovery-model",className:"block text-[13px] font-medium text-ink",children:t("settings.recovery.model")}),e.jsxs(xe,{className:"mt-2 w-full",id:"automatic-recovery-model",value:u.backup?.model??"",disabled:r||!u.enabled||!p,onChange:g=>y({enabled:u.enabled,backup:{instanceId:p.instanceId,model:g.target.value}}),children:[e.jsx("option",{value:"",children:t("settings.recovery.chooseModel")}),u.backup?.model&&!f&&e.jsx("option",{value:u.backup.model,disabled:!0,children:t("settings.recovery.unavailable",{name:u.backup.model})}),h.map(g=>e.jsx("option",{value:g.id,children:g.label},g.id))]})]})]}),e.jsx("p",{className:"mt-2 text-[12px] leading-relaxed text-ink-secondary",children:t("settings.recovery.charges")}),u.enabled&&!f&&e.jsx("p",{className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.recovery.required")}),e.jsx("button",{type:"button",disabled:!a||r||u.enabled&&!f,onClick:()=>{b()},className:"mt-3 cursor-pointer rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white disabled:opacity-50",children:r?t("settings.threads.saving"):t("common.save")}),r&&e.jsx("span",{role:"status",className:"sr-only",children:t("settings.threads.saving")}),o&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:o})]})}const vr=1,jr=3650,qx=30,Tt=1024*1024,js=256*1024,kr=4*1024*1024*1024,Jx=50;function ba(s){const n=Number(s);return Number.isInteger(n)&&n>=vr&&n<=jr?n:null}function ya(s){const n=Number(s);if(!Number.isFinite(n))return null;const a=Math.round(n*Tt);return a>=js&&a<=kr&&a%js===0?a:null}function va(s){const n=s/Tt;return String(Number.isInteger(n)?n:Number(n.toFixed(2)))}function Nr(){const{state:s,dispatch:n}=W(),a=s.config?.threads?.eventLogRetentionDays??null,i=s.config?.threads?.eventLogMaxBytes??null,[r,c]=l.useState(null),[o,d]=l.useState(null),[m,u]=l.useState(null),[x,p]=l.useState(""),[h,f]=l.useState(null),y=l.useRef(!1),b=r??String(a===null?qx:a),g=o??(i===null?String(Jx):va(i));l.useEffect(()=>{r!==null&&a!==null&&String(a)===r&&c(null)},[a,r]),l.useEffect(()=>{o!==null&&i!==null&&va(i)===o&&d(null)},[i,o]);const k=async(v,B)=>{if(!y.current){y.current=!0,u(B),p(""),f(null);try{const j=await M("/api/config",{method:"PATCH",body:JSON.stringify({threads:v})});n({type:"configStatus",config:j})}catch(j){p(j instanceof Error?j.message:t("settings.threadCleanup.error"))}finally{y.current=!1,u(null)}}},S=v=>{if(!v){c(null),p(""),f(null),k({eventLogRetentionDays:null},"retention");return}const B=ba(b);if(B===null){p(t("settings.threadCleanup.invalidRetention")),f("retention");return}k({eventLogRetentionDays:B},"retention")},C=v=>{if(!v){d(null),p(""),f(null),k({eventLogMaxBytes:null},"cap");return}const B=ya(g);if(B===null){p(t("settings.threadCleanup.invalidCap")),f("cap");return}k({eventLogMaxBytes:B},"cap")},w=()=>{if(a===null)return;const v=ba(b);if(v===null){p(t("settings.threadCleanup.invalidRetention")),f("retention");return}if(v===a){c(null),p("");return}k({eventLogRetentionDays:v},"retention")},P=()=>{if(i===null)return;const v=ya(g);if(v===null){p(t("settings.threadCleanup.invalidCap")),f("cap");return}if(v===i){d(null),p("");return}k({eventLogMaxBytes:v},"cap")};return e.jsxs(Y,{title:t("settings.threadCleanup.title"),subtitle:t("settings.threadCleanup.subtitle"),children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-retention-enabled",type:"checkbox",checked:a!==null,disabled:m!==null,onChange:v=>S(v.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-retention-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.retention.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${h==="retention"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-retention-days",type:"number",min:vr,max:jr,step:1,inputMode:"numeric",value:b,disabled:a===null||m!==null,"aria-invalid":h==="retention","aria-describedby":"thread-log-retention-help",onChange:v=>{c(v.target.value),p(""),f(null)},onBlur:w,onKeyDown:v=>{v.key==="Enter"&&v.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.retention.unit")})]})]}),e.jsx("p",{id:"thread-log-retention-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.retention.help")})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{id:"thread-log-cap-enabled",type:"checkbox",checked:i!==null,disabled:m!==null,onChange:v=>C(v.target.checked),className:"size-4 accent-accent"}),e.jsx("label",{htmlFor:"thread-log-cap-enabled",className:"text-[13px] font-medium text-ink",children:t("settings.threadCleanup.cap.enable")}),e.jsxs("div",{className:`flex max-w-[160px] items-center rounded-lg border bg-inset ${h==="cap"?"border-danger/60":"border-hairline/40 focus-within:border-focus"}`,children:[e.jsx("input",{id:"thread-log-cap-mib",type:"number",min:js/Tt,max:kr/Tt,step:.25,inputMode:"decimal",value:g,disabled:i===null||m!==null,"aria-invalid":h==="cap","aria-describedby":"thread-log-cap-help",onChange:v=>{d(v.target.value),p(""),f(null)},onBlur:P,onKeyDown:v=>{v.key==="Enter"&&v.currentTarget.blur()},className:"min-w-0 flex-1 bg-transparent px-3 py-2 text-[14px] tabular-nums text-ink focus:outline-none"}),e.jsx("span",{className:"pr-3 text-[13px] text-ink-secondary",children:t("settings.threadCleanup.cap.unit")})]})]}),e.jsx("p",{id:"thread-log-cap-help",className:"text-[12px] leading-relaxed text-ink-secondary",children:t("settings.threadCleanup.cap.help")})]}),m!==null&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t("settings.threadCleanup.saving")}),x&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:x})]})}const ja="min-w-0 rounded-lg border bg-inset px-3 py-2 text-[14px] text-ink focus:outline-none";function Xx(){const s=tl(),[n,a]=l.useState(""),[i,r]=l.useState(""),[c,o]=l.useState(""),d=s.length>=nn,m=()=>{const u=sl({name:n,url:i},window.location.origin);if(!u.ok){o(u.error);return}an([...s,{id:nl(s),name:u.name,url:u.url}]),a(""),r(""),o("")};return e.jsx(Y,{title:t("webPanels.settings.title"),subtitle:t("webPanels.settings.subtitle"),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[s.length>0&&e.jsx("ul",{className:"flex flex-col divide-y divide-hairline/40 rounded-lg border border-hairline/40",children:s.map(u=>e.jsxs("li",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[14px] font-medium text-ink",children:u.name}),e.jsx("p",{className:"truncate text-[12px] text-ink-secondary",title:u.url,children:u.url??t("webPanels.settings.chatPage")})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",onClick:()=>an(s.filter(x=>x.id!==u.id)),children:t("webPanels.settings.remove")})]},u.id))}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx("input",{"aria-label":t("webPanels.settings.name"),placeholder:t("webPanels.settings.name"),value:n,maxLength:rn,disabled:d,"aria-invalid":c==="name",onChange:u=>{a(u.target.value),o("")},className:`${ja} sm:w-40 ${c==="name"?"border-danger/60":"border-hairline/40 focus:border-focus"}`}),e.jsx("input",{"aria-label":t("webPanels.settings.url"),placeholder:"https://",type:"url",inputMode:"url",value:i,disabled:d,"aria-invalid":c==="url"||c==="self",onChange:u=>{r(u.target.value),o("")},onKeyDown:u=>{u.key==="Enter"&&m()},className:`${ja} flex-1 ${c==="url"||c==="self"?"border-danger/60":"border-hairline/40 focus:border-focus"}`}),e.jsx("button",{type:"button",className:"ui-button",disabled:d,onClick:m,children:t("webPanels.settings.add")})]}),c&&e.jsx("p",{role:"alert",className:"text-[12px] text-danger",children:t(c==="name"?"webPanels.settings.nameInvalid":c==="self"?"webPanels.settings.urlSelf":"webPanels.settings.urlInvalid",{max:rn})}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:d?t("webPanels.settings.full",{max:nn}):t("webPanels.settings.help")})]})})}const ls="mt-1 w-full rounded-lg border border-hairline/50 bg-inset px-3 py-2 text-[14px] text-ink disabled:opacity-50",Xe=s=>{const n=s>=1073741824?3:s>=1048576?2:1;return`${new Intl.NumberFormat(Me(),{maximumFractionDigits:2}).format(s/1024**n)} ${["","KiB","MiB","GiB"][n]}`},ka=s=>{const n=new Date(s.completedAt??s.createdAt??NaN);return Number.isFinite(n.getTime())?new Intl.DateTimeFormat(Me(),{dateStyle:"medium",timeStyle:"short"}).format(n):t("companyBackup.unknownDate")};function Yx(){const s=window.ogb?.remoteClient?.active?void 0:window.ogb?.organization,n=s?window.ogb?.companyBackups:void 0,[a,i]=l.useState(null),r=l.useRef(0),c=l.useRef(0);return l.useEffect(()=>{const o=++r.current,d=c.current;i(null);const m=x=>{r.current===o&&(c.current++,i(x))},u=s?.onState(m);return s?.state().then(x=>{c.current===d&&m(x)}).catch(()=>{}),()=>{r.current++,u?.()}},[s]),!n||!a?null:a.status!=="connected"||a.cloudBackups!==!0||!a.organization?.id||!a.organization.name?.trim()||!a.email?e.jsx(Qx,{bridge:n}):e.jsx(Zx,{connection:a,bridge:n},`${a.organization.id}:${a.email}:${a.deviceId??""}`)}function Qx({bridge:s}){const[n,a]=l.useState(null),[i,r]=l.useState(!1),[c,o]=l.useState(""),d=l.useRef(0);if(l.useEffect(()=>{const u=++d.current,x=s.onState(p=>{u===d.current&&a(p.schedule??null)});return s.state().then(p=>{u===d.current&&a(p.schedule??null)}).catch(()=>{}),()=>{d.current++,x()}},[s]),!s.configureSchedule||!n?.enabled)return null;const m=async()=>{if(i||!s.configureSchedule)return;const u=d.current;r(!0),o("");try{const x=await s.configureSchedule({enabled:!1});u===d.current&&a(x.schedule??null)}catch{u===d.current&&o(t("companyBackup.scheduleFailed"))}finally{u===d.current&&r(!1)}};return e.jsx(Y,{title:t("companyBackup.title"),subtitle:t("companyBackup.savedSchedule"),children:e.jsxs("div",{className:"rounded-lg border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-[14px] font-medium",children:t("companyBackup.daily")}),e.jsx(me,{"aria-label":t("companyBackup.daily"),checked:!0,disabled:i,onClick:()=>{m()}})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${n.status}`)}),c&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:c})]})})}function Zx({connection:s,bridge:n}){const[a,i]=l.useState(null),[r,c]=l.useState(null),[o,d]=l.useState(!1),[m,u]=l.useState(null),[x,p]=l.useState(""),[h,f]=l.useState(null),[y,b]=l.useState(""),[g,k]=l.useState(""),[S,C]=l.useState(null),[w,P]=l.useState(!1),v=l.useRef(0),B=l.useRef(0),j=l.useRef(0),A=l.useRef(void 0),I=l.useRef(!1),_=l.useRef(null),U=async()=>{const $=v.current,oe=++j.current,R=B.current;d(!0);try{await Promise.all([n.state().then(E=>{$===v.current&&oe===j.current&&B.current===R&&i(E)}),n.list().then(E=>{$===v.current&&oe===j.current&&c(E)})]),$===v.current&&oe===j.current&&p("")}catch{$===v.current&&oe===j.current&&p(t("companyBackup.loadFailed"))}finally{$===v.current&&oe===j.current&&d(!1)}};l.useEffect(()=>{const $=++v.current,oe=E=>{if($!==v.current)return;B.current++,i(E);const H=E.lastBackupAt??E.schedule?.lastBackupAt;!E.busy&&!E.pendingRestore&&H&&H!==A.current&&(A.current=H,U())},R=n.onState(oe);return U(),()=>{v.current++,j.current++,R()}},[n]),l.useEffect(()=>{const $=_.current;if(!(!h||!$))return $.showModal(),()=>{$.close()}},[h]);const J=w||a?.pendingRestore===!0,K=m!==null||!a||a.busy||J,te=()=>{f(null),b(""),k(""),C(null)},ae=$=>{K||I.current||(p(""),b(""),k(""),C(null),f($))},de=async($,oe)=>{if(K||I.current)return;I.current=!0,u($),p("");const R=v.current;try{await oe(()=>R===v.current)}catch{R===v.current&&p(t($==="restore"?"companyBackup.restoreFailed":"companyBackup.actionFailed"))}finally{I.current=!1,R===v.current&&u(null)}},D=()=>{h?.kind==="create"&&de("create",async $=>{await n.create({clientState:wc()}),$()&&(te(),await U())})},T=async $=>{if(!n.configureSchedule||I.current||!a||$&&(K||h?.kind!=="schedule"||g!=="BACK UP THIS WORKSPACE DAILY"))return;I.current=!0,u("schedule"),p("");const oe=v.current,R=B.current;k("");try{const E=await n.configureSchedule($?{enabled:!0,confirmation:"BACK UP THIS WORKSPACE DAILY"}:{enabled:!1});oe===v.current&&(B.current===R&&i(E),te())}catch{oe===v.current&&p(t("companyBackup.scheduleFailed"))}finally{I.current=!1,oe===v.current&&u(null)}},Z=()=>{h?.kind!=="restore"||h.entry.passwordRequired!==!1&&(y.length<12||y.length>1024)||de("prepare",async $=>{const oe=y;b(""),C(null),k("");const R=await n.prepareRestore({id:h.entry.id,...h.entry.passwordRequired!==!1?{password:oe}:{}});$()&&C(R)})},ee=()=>{h?.kind!=="restore"||!S||g!=="REPLACE"||de("restore",async $=>{const oe=localStorage.getItem(jn);if(oe&&oe!==S.id)throw new Error(t("companyBackup.restorePending"));localStorage.setItem(jn,S.id),await n.restore({id:S.id,confirmation:"REPLACE"}),$()&&(P(!0),te())})},fe=()=>{h?.kind!=="delete"||g!=="DELETE"||de("delete",async $=>{await n.delete({id:h.entry.id,confirmation:"DELETE"}),$()&&(te(),await U())})},N=async()=>{const $=v.current;try{await n.cancel()}catch{$===v.current&&p(t("companyBackup.actionFailed"))}},re=r?.backups.filter($=>$.status==="ready")??[],se=r?r.backups.length-re.length:0,ne=a?.progress,G=x||a?.message,ie=(a?.busy||m)&&e.jsxs("div",{role:"status",className:"flex flex-col items-start gap-2 text-[13px] text-ink-secondary",children:[e.jsx("span",{children:m==="restore"?t("backup.restoring"):ne?t(`companyBackup.phase.${ne.phase}`):t("companyBackup.working")}),ne&&ne.totalBytes>0&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{className:"w-full accent-accent",max:ne.totalBytes,value:Math.min(ne.bytesTransferred,ne.totalBytes),"aria-label":t("companyBackup.progress")}),e.jsx("span",{children:t("companyBackup.transferred",{done:Xe(ne.bytesTransferred),total:Xe(ne.totalBytes)})})]}),a?.busy&&m!=="restore"&&e.jsx("button",{type:"button",className:"ui-button",onClick:()=>{N()},children:t("companyBackup.cancelTransfer")})]}),le=h?.kind==="restore"?t("companyBackup.restore"):h?.kind==="delete"?t("companyBackup.delete"):h?.kind==="schedule"?t("companyBackup.enableSchedule"):t("companyBackup.create"),ce=a?.schedule,ve=$=>new Intl.DateTimeFormat(Me(),{dateStyle:"medium",timeStyle:"short"}).format(new Date($));return e.jsxs(Y,{title:t("companyBackup.title"),subtitle:t("companyBackup.account",{organization:s.organization?.name??"",email:s.email??""}),children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedScope")}),n.configureSchedule&&ce&&e.jsxs("div",{className:"rounded-lg border border-hairline/40 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[14px] font-medium",children:t("companyBackup.daily")}),e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.scheduleHelp")})]}),e.jsx(me,{"aria-label":t("companyBackup.daily"),checked:ce.enabled,disabled:m!==null||!a||!ce.enabled&&K,onClick:()=>ce.enabled?void T(!1):ae({kind:"schedule"})})]}),e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:t(`companyBackup.scheduleStatus.${ce.status}`)}),ce.enabled&&ce.nextBackupAt&&Number.isFinite(ce.nextBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.nextBackup",{date:ve(ce.nextBackupAt)})}),ce.lastBackupAt&&Number.isFinite(ce.lastBackupAt)&&e.jsx("p",{className:"mt-1 text-[12px] text-ink-secondary",children:t("companyBackup.lastScheduledBackup",{date:ve(ce.lastBackupAt)})}),ce.message&&e.jsx("p",{role:"status",className:"mt-1 break-words text-[12px] text-ink-secondary",children:ce.message})]}),J?e.jsx("div",{className:"rounded-lg border border-warning/40 bg-warning/10 p-3 text-ink",children:e.jsx(vn,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:K,onClick:()=>ae({kind:"create"}),children:t("companyBackup.create")}),e.jsx("button",{type:"button",className:"ui-button",disabled:m!==null||a?.busy||J||o,onClick:()=>{U()},children:t("companyBackup.refresh")})]}),o&&e.jsx("p",{role:"status",className:"text-[13px] text-ink-secondary",children:t("companyBackup.loading")}),r&&e.jsx("p",{className:"text-[12px] text-ink-secondary",children:t("companyBackup.quota",{used:Xe(r.usedBytes),total:Xe(r.limits.ownerQuotaBytes),count:r.limits.retainedSnapshots})}),se>0&&e.jsx("p",{role:"status",className:"text-[12px] text-ink-secondary",children:t("companyBackup.pending",{count:se})}),r&&re.length===0&&e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.empty")}),e.jsx("ul",{className:"divide-y divide-hairline/40",children:re.map($=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-3 py-3",children:[e.jsxs("div",{className:"min-w-0 text-[13px]",children:[e.jsx("div",{className:"text-ink",children:ka($)}),e.jsxs("div",{className:"text-[12px] text-ink-secondary",children:[Xe($.sizeBytes),$.appVersion?` · ${$.appVersion}`:""]}),e.jsx("code",{className:"break-all text-[11px] text-ink-secondary",children:$.id})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"ui-button",disabled:K,onClick:()=>ae({kind:"restore",entry:$}),children:t("companyBackup.restore")}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:K,onClick:()=>ae({kind:"delete",entry:$}),children:t("companyBackup.delete")})]})]},$.id))})]}),!h&&ie,!h&&G&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:G})]}),h&&e.jsx("dialog",{ref:_,"aria-labelledby":"company-backup-dialog-title",onKeyDown:$=>{($.key==="Escape"||$.key==="Tab")&&$.stopPropagation()},onCancel:$=>{$.preventDefault(),m||te()},className:"fixed inset-0 m-auto max-h-[85dvh] w-[min(34rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border border-hairline/50 bg-app p-5 text-ink shadow-xl backdrop:bg-black/45",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h3",{id:"company-backup-dialog-title",className:"text-[16px] font-semibold",children:le}),J&&e.jsx(vn,{}),(h.kind==="restore"||h.kind==="delete")&&e.jsxs("div",{className:"text-[13px] text-ink-secondary",children:[e.jsxs("p",{children:[ka(h.entry)," · ",Xe(h.entry.sizeBytes)]}),e.jsx("code",{className:"break-all text-[11px]",children:h.entry.id})]}),(h.kind==="create"||h.kind==="schedule")&&e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:$=>{$.preventDefault(),h.kind==="schedule"?T(!0):D()},children:[e.jsx("p",{className:"text-[13px] text-ink",children:t(h.kind==="schedule"?"companyBackup.scheduleWarning":"companyBackup.managedUploadWarning",{organization:s.organization?.name??"",email:s.email??""})}),h.kind==="schedule"?e.jsxs("details",{className:"text-[13px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer text-ink",children:t("companyBackup.included")}),e.jsx("p",{className:"mt-2",children:t("backup.excluded")}),e.jsx("p",{className:"mt-2",children:t("companyBackup.managedPrivacy")})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("backup.excluded")}),e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedPrivacy")})]}),e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.managedEncryption")}),h.kind==="schedule"&&e.jsxs("label",{className:"flex items-start gap-2 text-[13px]",children:[e.jsx("input",{className:"mt-1 accent-accent",type:"checkbox",required:!0,disabled:K,checked:g==="BACK UP THIS WORKSPACE DAILY",onChange:$=>k($.target.checked?"BACK UP THIS WORKSPACE DAILY":"")}),e.jsx("span",{children:t("companyBackup.scheduleConsent")})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:K||h.kind==="schedule"&&g!=="BACK UP THIS WORKSPACE DAILY",children:t(h.kind==="schedule"?"companyBackup.enableSchedule":"companyBackup.create")})]}),h.kind==="restore"&&(S?e.jsxs(e.Fragment,{children:[e.jsx(Nc,{summary:S.summary}),e.jsx("p",{className:"text-[13px] text-danger",children:t("backup.replaceWarning")}),e.jsx("p",{className:"text-[13px] text-danger",children:t("backup.trustWarning")}),e.jsxs("label",{className:"text-[13px]",children:[t("backup.confirmReplace"),e.jsx("input",{autoComplete:"off",spellCheck:!1,maxLength:7,disabled:K,value:g,onChange:$=>k($.target.value),className:ls})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:K||g!=="REPLACE",onClick:ee,children:t("backup.replace")})]}):e.jsxs("form",{className:"flex flex-col gap-3",onSubmit:$=>{$.preventDefault(),Z()},children:[e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("companyBackup.previewHelp")}),h.entry.passwordRequired!==!1&&e.jsxs("label",{className:"text-[13px]",children:[t("backup.importPassword"),e.jsx("input",{type:"password",autoComplete:"off",required:!0,minLength:12,maxLength:1024,disabled:K,value:y,onChange:$=>b($.target.value),className:ls})]}),e.jsx("button",{type:"submit",className:"ui-button",disabled:K||h.entry.passwordRequired!==!1&&(y.length<12||y.length>1024),children:t("backup.validate")})]})),h.kind==="delete"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-danger",children:t("companyBackup.deleteWarning")}),e.jsxs("label",{className:"text-[13px]",children:[t("companyBackup.confirmDelete"),e.jsx("input",{autoComplete:"off",spellCheck:!1,maxLength:6,disabled:K,value:g,onChange:$=>k($.target.value),className:ls})]}),e.jsx("button",{type:"button",className:"ui-button text-danger",disabled:K||g!=="DELETE",onClick:fe,children:t("companyBackup.delete")})]}),ie,G&&e.jsx("p",{role:"alert",className:"break-words text-[13px] text-danger",children:G}),e.jsx("button",{type:"button",autoFocus:!0,className:"ui-button w-fit",disabled:m!==null,onClick:te,children:t("companyBackup.cancel")})]})})]})}function eh({sources:s}){const n=[...new Set(s.map(a=>a==="claudeDesktop"?"claudeCode":a))];return e.jsx("span",{className:"mr-1.5 inline-flex items-center gap-1 align-[-1px]","aria-hidden":"true",children:n.map(a=>{switch(a){case"codex":return e.jsx(zc,{size:12},a);case"cursor":return e.jsx(Mc,{size:12},a);case"gemini":return e.jsx(Fa,{preset:"google",size:12},a);default:return e.jsx(Oc,{size:12},a)}})})}function Na({icon:s,label:n,summary:a,hint:i,sources:r,checked:c,disabled:o,onChange:d}){return e.jsxs("label",{className:z("flex items-start gap-3 px-3.5 py-3 transition-colors",o?"cursor-default":"cursor-pointer hover:bg-raised/40"),children:[e.jsx("input",{type:"checkbox",checked:c,disabled:o,onChange:m=>d(m.target.checked),className:"mt-0.5 size-4 shrink-0 cursor-[inherit] accent-[var(--color-accent)]"}),e.jsx("span",{className:"mt-0.5 flex size-4 shrink-0 items-center justify-center text-ink-secondary",children:s}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("span",{className:"text-[13px] leading-5 text-ink-secondary",children:[e.jsx("span",{className:"mr-2 text-[14px] font-medium text-ink",children:n}),e.jsx(eh,{sources:r}),a]}),e.jsx("span",{className:"mt-0.5 text-[12px] leading-relaxed text-ink-secondary",children:i})]})]})}const wr="inline-flex items-center justify-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-accent-ink disabled:opacity-40";function th({local:s,detection:n,chosen:a,status:i,result:r,onChoose:c,onBring:o}){const d=i==="working";let m;if(!s)m=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:t("settings.import.appsLocalOnly")});else if(n===void 0)m=e.jsxs("p",{className:"flex items-center gap-2 text-[13px] text-ink-secondary",children:[e.jsx(X,{size:14,className:"animate-spin"}),t("settings.import.appsLooking")]});else if(r){const{line:u,notes:x,done:p}=Ic(r);m=e.jsxs("div",{role:"status",className:"flex items-start gap-3",children:[e.jsx("span",{className:z("mt-px flex size-5 shrink-0 items-center justify-center rounded-full",p?"bg-success/15 text-success":"bg-control text-ink-secondary"),children:p?e.jsx(ge,{size:12,strokeWidth:3}):e.jsx(Pc,{size:12,strokeWidth:2.5})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[14px] font-medium text-ink",children:u}),x.map(h=>e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:h},h))]})]})}else!n||Tc(n)===0?m=e.jsx("p",{className:"text-[13px] text-ink-secondary",children:n===null?t("onboarding.import.error"):t("settings.import.appsNothing")}):m=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"divide-y divide-hairline/40 overflow-hidden rounded-xl border border-hairline/40",children:[n.skills.length>0&&e.jsx(Na,{icon:e.jsx(Ps,{size:15}),label:t("onboarding.import.skills"),summary:Rc(n),hint:t("onboarding.import.skillsHint"),sources:kn(n.skills),checked:a.skills,disabled:d,onChange:u=>c({...a,skills:u})}),n.tools.length>0&&e.jsx(Na,{icon:e.jsx(Bc,{size:15}),label:t("onboarding.import.tools"),summary:Lc(n),hint:t("onboarding.import.toolsHint"),sources:kn(n.tools),checked:a.tools,disabled:d,onChange:u=>c({...a,tools:u})})]}),i==="failed"&&e.jsx("p",{role:"alert",className:"mt-3 text-[13px] text-danger",children:t("onboarding.import.error")}),e.jsxs("button",{onClick:o,disabled:d||!(a.skills||a.tools),className:z(wr,"mt-3"),children:[d&&e.jsx(X,{size:14,className:"animate-spin"}),d?t("onboarding.import.bringing"):t("onboarding.import.bring")]})]});return e.jsxs("section",{"data-import-section":"apps",className:"rounded-xl bg-card p-4",children:[e.jsx("div",{className:"text-[15px] font-medium text-ink",children:t("settings.import.appsTitle")}),e.jsx("div",{className:"mt-0.5 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.import.appsSubtitle")}),e.jsx("div",{className:"mt-4",children:m})]})}function sh({client:s,local:n}){const[a,i]=l.useState(void 0),[r,c]=l.useState({skills:!0,tools:!0}),[o,d]=l.useState("idle"),[m,u]=l.useState(null);l.useEffect(()=>{if(!n)return;const p=new AbortController;return s.detect(p.signal).then(i,()=>i(null)),()=>p.abort()},[s,n]);const x=async()=>{if(!a||o==="working")return;const p={...r.skills&&a.skills.length?{skills:!0}:{},...r.tools&&a.tools.length?{tools:!0}:{}};if(!(!p.skills&&!p.tools)){d("working");try{const h=await s.apply(p);Tl("setup_import_applied",{skills:h.skills?.added.length??0,tools:h.tools?.added.length??0}),u(h),d("idle")}catch{d("failed")}}};return e.jsx(th,{local:n,detection:a,chosen:r,status:o,result:m,onChoose:c,onBring:()=>{x()}})}function nh(){const[s,n]=l.useState(!1),[a,i]=l.useState(!1);return e.jsxs("section",{"data-import-section":"grok",className:"rounded-xl bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[15px] font-medium text-ink",children:[e.jsx(Ec,{size:16}),t("settings.import.grokTitle")]}),e.jsx("div",{className:"mt-0.5 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.import.grokSubtitle")}),e.jsxs("button",{type:"button","data-grok-move-open":!0,"aria-expanded":a,onClick:()=>{n(!0),i(!a)},className:z(wr,"mt-3"),children:[t("settings.import.grokTitle"),e.jsx(Ca,{size:14,"aria-hidden":"true",className:z("transition-transform",a&&"rotate-180")})]}),s&&e.jsx("div",{className:a?void 0:"hidden",children:e.jsx(Ac,{inline:!0,onClose:()=>{n(!1),i(!1)}})})]})}function Sr({client:s=Sc}){const{state:n}=W();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(sh,{client:s,local:Cc(n.config?.cloudHome===!0)}),e.jsx(nh,{})]})}function Cr({simple:s=!1}){return e.jsxs(e.Fragment,{children:[e.jsx(ah,{simple:s}),e.jsx(ih,{simple:s}),e.jsx(rh,{simple:s})]})}const wa=()=>typeof Notification<"u"?Notification.permission:"default";function ah({simple:s=!1}){const[n,a]=l.useState(wa),i=Uc();if(l.useEffect(()=>{const o=()=>{document.visibilityState==="visible"&&a(wa())};return window.addEventListener("focus",o),document.addEventListener("visibilitychange",o),()=>{window.removeEventListener("focus",o),document.removeEventListener("visibilitychange",o)}},[]),typeof Notification>"u")return null;const r=n==="denied",c=async()=>{if(n==="granted")return Nn(!i);const o=await Kc();o&&(a(o),o==="granted"&&Nn(!0))};return e.jsx(ue,{title:t("settings.deviceNotifications.title"),subtitle:t(r?"settings.deviceNotifications.blocked":s?"settings.simple.deviceNotifications":"settings.deviceNotifications.subtitle"),children:e.jsx(me,{checked:n==="granted"&&i,disabled:r,"aria-label":t("settings.deviceNotifications.show"),onClick:()=>{c()}})})}function ih({simple:s=!1}){const n=Fc();return e.jsx(ue,{title:t("settings.notificationSounds.title"),subtitle:t(s?"settings.simple.notificationSounds":"settings.notificationSounds.subtitle"),children:e.jsx(me,{checked:n,"aria-label":t("settings.notificationSounds.play"),onClick:()=>Dc(!n)})})}function rh({simple:s=!1}){const n=_c();return e.jsx(ue,{title:t("settings.notificationFeed.title"),subtitle:t(s?"settings.simple.notificationFeed":"settings.notificationFeed.subtitle"),children:e.jsx(me,{checked:n,"aria-label":t("settings.notificationFeed.show"),onClick:()=>$c(!n)})})}function Er(){const{state:s,dispatch:n}=W(),a=Hc(s.config),[i,r]=l.useState(!1),[c,o]=l.useState("");if(!Wc(s.config))return null;const d=async()=>{if(!i){r(!0),o("");try{const m=await M("/api/config",{method:"PATCH",body:JSON.stringify({features:{savedSteps:!a}})});n({type:"configStatus",config:m})}catch(m){o(m instanceof Error?m.message:t("settings.savedSteps.error"))}finally{r(!1)}}};return e.jsx(ue,{title:t("settings.savedSteps.title"),subtitle:t("settings.savedSteps.subtitle"),children:e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx(me,{checked:a,disabled:i,"aria-label":t("settings.savedSteps.aria"),onClick:d}),c&&e.jsx("span",{role:"alert",className:"text-[12px] text-danger",children:c})]})})}const lh=["settings.font.title","settings.chatWidth.title","settings.pinnedCircles.title","settings.universalPins.title","settings.runCard.title"],oh=["settings.roomTurns.title","settings.mcpCalls.title","settings.threads.title","settings.recovery.title","settings.threadCleanup.title","settings.keepWarm.title","settings.savedSteps.title"];function ch({has:s,peopleOpen:n,onLooks:a,onMore:i}){return e.jsxs(e.Fragment,{children:[(s("general")||s("people"))&&e.jsx(be,{label:t("settings.group.account"),block:"general",children:e.jsxs(ye,{children:[s("general")&&e.jsx(Vx,{}),s("general")&&e.jsx(fr,{row:!0}),s("general")&&e.jsx(fi,{place:"account"}),s("people")&&e.jsx("div",{"data-settings-block":"people",className:"scroll-mt-4",children:e.jsx(Di,{simple:!0,startOpen:n})})]})}),s("appearance")&&e.jsx(be,{label:t("settings.section.appearance"),block:"appearance",children:e.jsxs(ye,{children:[e.jsx(or,{simple:!0}),e.jsx(dh,{onLooks:a}),e.jsx(Gi,{}),e.jsx(ti,{}),e.jsx(Vi,{}),e.jsx(xi,{simple:!0})]})}),s("appearance")&&e.jsx(be,{label:t("settings.simple.group.typing"),children:e.jsxs(ye,{children:[e.jsx(ms,{simple:!0}),e.jsx(hi,{simple:!0}),e.jsx(gi,{simple:!0})]})}),s("appearance")&&e.jsx(be,{label:t("notifications.title"),children:e.jsx(ye,{children:e.jsx(Cr,{simple:!0})})}),s("general")&&e.jsx(be,{label:t("settings.simple.group.system"),children:e.jsxs(ye,{children:[e.jsx(wi,{simple:!0}),e.jsx(si,{simple:!0}),e.jsx(Si,{}),e.jsx(Ci,{}),e.jsx(Ni,{simple:!0})]})}),s("import")&&e.jsx(be,{label:t("settings.section.import"),block:"import",children:e.jsx(je,{children:e.jsx(Sr,{})})}),s("organization")&&e.jsx(be,{label:t("settings.section.organization"),block:"organization",children:e.jsx(Ji,{})}),s("activity")&&e.jsx(be,{label:t("settings.section.activity"),block:"activity",children:e.jsx(_i,{})}),i&&e.jsx("div",{"data-settings-block":"more",className:"scroll-mt-4",children:e.jsx(ye,{children:e.jsx(ue,{title:t("settings.simple.more.title"),subtitle:t("settings.simple.more.subtitle"),children:e.jsx("button",{type:"button",className:"ui-button","data-settings-more":"",onClick:i,children:t("settings.simple.more.open")})})})}),e.jsx("div",{"data-settings-block":"advanced-mode",className:"scroll-mt-4",children:e.jsx(ye,{children:e.jsx(ps,{simple:!0})})})]})}function dh({onLooks:s}){const n=Ws(),a=Lt.find(r=>r.id===Ea(n))?.name,i=n==="system"?t("settings.simple.themes.followHint"):a;return e.jsx(ue,{title:t("settings.theme.title"),subtitle:i,children:e.jsx("button",{type:"button",className:"ui-button",onClick:s,children:t("settings.simple.themes.browse")})})}function uh({onBack:s,toolCalls:n=!0}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:s,children:t("settings.simple.looks.back")})}),e.jsx("div",{"data-settings-block":"looks",children:e.jsx(cr,{})}),e.jsx(lr,{}),n&&e.jsx(ye,{children:e.jsx(pi,{})})]})}function mh({sections:s,onOpen:n,onBack:a}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:a,children:t("settings.simple.looks.back")})}),s.length>0&&e.jsx(be,{block:"more-sections",children:e.jsx(ye,{children:s.map(({id:i,labelKey:r})=>e.jsx(ue,{title:t(r),children:e.jsx("button",{type:"button",className:"ui-button","data-settings-more-section":i,onClick:()=>n(i),children:t("settings.simple.more.open")})},i))})}),e.jsx(be,{label:t("settings.simple.more.limits"),block:"limits",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Y,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(dr,{})}),e.jsx(Y,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(pr,{})}),e.jsx(br,{}),e.jsx(yr,{}),e.jsx(Nr,{}),e.jsx(Ti,{}),e.jsx(ye,{children:e.jsx(Er,{})})]})})]})}function ph({has:s,disclose:n,connections:a}){return e.jsxs(e.Fragment,{children:[s("engines")&&e.jsx("div",{"data-settings-block":"engines",className:"flex scroll-mt-4 flex-col gap-7",children:e.jsxs(je,{children:[e.jsx(Li,{simple:!0,more:n("ai-more")}),e.jsx(ye,{children:e.jsx(mi,{simple:!0})})]})}),s("connections")&&e.jsx(je,{children:e.jsx(zt,{title:t("settings.section.connections"),block:"connections",...n("ai-keys"),children:a})})]})}function xh({has:s,remoteAccess:n,servers:a,disclose:i}){return e.jsxs(e.Fragment,{children:[s("computer")&&e.jsx(be,{label:t("settings.simple.computer.bots"),block:"computer",children:e.jsx(je,{children:e.jsx(zi,{})})}),s("companion")&&e.jsxs(be,{label:t(ei()?"settings.section.phoneDevices":"settings.section.thisServer"),block:"companion",children:[n.companion,n.pairing,n.domain]}),s("computer")&&e.jsxs(be,{label:t("settings.experimental.browser"),block:"browser",children:[e.jsxs(ye,{children:[e.jsx(ci,{}),e.jsx(di,{})]}),e.jsx(ui,{})]}),s("logins")&&e.jsx("div",{"data-settings-block":"logins",className:"scroll-mt-4",children:e.jsx(Wi,{})}),(s("companion")||s("desktopWorkspaces"))&&e.jsxs(zt,{title:t("settings.simple.computer.elsewhere"),block:"elsewhere",...i("computer-elsewhere"),children:[s("desktopWorkspaces")&&e.jsx("div",{"data-settings-block":"desktopWorkspaces",className:"flex scroll-mt-4 flex-col gap-4",children:a}),s("companion")&&e.jsx("div",{"data-settings-block":"remote",className:"flex scroll-mt-4 flex-col gap-4 empty:hidden",children:n.client})]})]})}function hh({has:s,disclose:n,cloudAccount:a}){const{usage:i,upgrade:r,dialog:c}=Gc(),o=Td(),d=o?.view.kind==="signed-out"||o?.view.kind==="removed";return e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-settings-block":"usage",className:"scroll-mt-4",children:i?e.jsx(Vc,{usage:i,upgrade:r,children:c}):e.jsx(je,{note:"settings.adminOnly.usage",children:e.jsx(Xp,{})})}),(i||s("usage"))&&e.jsxs(zt,{title:t("settings.simple.billing.limits"),...n("billing-limits"),children:[i&&e.jsx(qc,{usage:i,upgrade:r}),s("usage")&&e.jsx(je,{note:"settings.adminOnly.usage",children:e.jsx(nr,{})})]}),s("cloudAccount")&&e.jsxs(be,{label:t("settings.simple.billing.plan"),block:"cloudAccount",footnote:e.jsx(Rd,{}),children:[e.jsx(ye,{children:e.jsx(fi,{place:"plan",usage:i,upgrade:r})}),d?null:e.jsx("div",{className:"flex flex-col gap-4",children:a})]})]})}const Ar=()=>`${ws()} ${Jc()}`;function gh(){const s=Xc(!0);if(!s)return null;const n=s.phase==="idle"?void 0:[s.label,s.item.subtitle].filter(Boolean).join(" "),a=s.phase==="available"?t("settings.simple.updates.seeRelease"):s.phase==="reload"?t("settings.simple.updates.reload"):s.phase==="checking"?t("common.checking"):t("settings.updates.check");return e.jsx(ue,{title:Ar(),subtitle:n,children:e.jsx("button",{type:"button",className:"ui-button",disabled:s.item.disabled,onClick:s.item.onSelect,children:a})})}function fh({remoteActive:s}){return e.jsx(be,{block:"updates",children:e.jsxs(ye,{children:[window.ogb?.updater?e.jsx(li,{title:Ar()}):e.jsx(gh,{}),e.jsx(Za,{}),!s&&e.jsx(oi,{}),e.jsx(Ei,{simple:!0})]})})}const Sa=[{id:"you",labelKey:"settings.group.you"},{id:"ai",labelKey:"settings.group.ai"},{id:"computers",labelKey:"settings.group.computers"},{id:"account",labelKey:"settings.group.account"}],Gs=[{id:"general",group:"you",labelKey:"settings.section.general",icon:Qa,keywords:["profile","pinned panels","web panel","dashboard","pin a page","name","email","about me","about","suggestions","suggested","memory","analytics","updates","product updates","newsletter","email updates","effort","new bots","reasoning","threads","parallel","concurrency","cleanup","retention","attachments","clear attachments","event log","event-log","log size","automatic recovery","backup model","fallback","routines","conversation","schedule","usage","limit","plan","upgrade","cloud desktop hours","storage","saved steps","repeat","replay","computer tasks","without ai","forget",...Nu()]},{id:"appearance",group:"you",labelKey:"settings.section.appearance",icon:Ud,keywords:["skin","theme","appearance","font","typeface","chat width","width","wide","full width","bubble","bubbles","tools","tool calls","threads","show threads","hide threads","sidebar","display","run","this run","run card","commands","notifications","sound","sounds","mute","silent","chime","pinned","circles","universal","groups","top","send","enter","return","shift+enter","ctrl+enter","cmd+enter","⌘+enter","new line","keyboard","ime","japanese","message color","my messages","toolbar","tools layout","footer","routines","triggers","team map","color","colour","cloud color","server color","tint","sidebar color","sidebar picture","picture","image","banner","background","computers","your computers","rail","strip","frame","window frame","title bar"]},{id:"companion",group:"you",labelKey:"settings.section.companion",icon:Yc,keywords:["companion","device","phone","desktop","client","host","pair","pairing","mobile","https","secure","tailscale","wifi","remote","advanced","domain","dns","self-hosted","server","caddy"]},{id:"engines",group:"ai",labelKey:"settings.section.engines",icon:$d,keywords:["models","model providers","engines","claude","codex","grok","providers","cli","sign in","subscription"]},{id:"connections",group:"ai",labelKey:"settings.section.connections",icon:Ga,keywords:["keys","api","api key","api keys","connections","composio","box","xai","mistral","cerebras","meta","muse","vps","router","openrouter","base url","openai","anthropic","groq","greenference","modelgo","opencode","deepseek","provider","ollama","lm studio","lmstudio","llm studio","llmstudio","bionic"]},{id:"decisionModel",group:"ai",labelKey:"settings.section.decisionModel",icon:Qc,keywords:["decision","extraction","jev","typesafe","cloudflare","workers ai","clef","clairic","email","routing","auto","rooms","who answers"]},{id:"imageGeneration",group:"ai",labelKey:"settings.section.imageGeneration",icon:Zc,keywords:["image","images","picture","generate","avatar","gpt image","grok imagine","gemini","nano banana","openrouter","flux","backup"]},{id:"skills",group:"ai",labelKey:"settings.section.skills",icon:Ps,keywords:["skills","library","assign","agent skills","skill md"]},{id:"desktopWorkspaces",group:"computers",labelKey:"settings.section.desktopWorkspaces",icon:Gt,keywords:["workspace","cloud","hosted","vps","server","servers","connect","pair","switch","local"]},{id:"computer",group:"computers",labelKey:"settings.section.computer",icon:bi,keywords:["vm","virtual","desktop","browser","built-in browser","profiles","browser profiles"]},{id:"logins",group:"computers",labelKey:"settings.section.vault",icon:Dt,keywords:["vault","logins","login","passwords","password","sign in","2fa","one-time code","totp","fill_login","1password","password manager","secrets","secret","token",".env","env"]},{id:"cloudAccount",group:"account",labelKey:"settings.section.cloudAccount",icon:Rt,keywords:["cloud","my cloud","account","personal","sign in","pro","subscription","billing","sync","send","this computer","bots","logins","1password"]},{id:"organization",group:"account",labelKey:"settings.section.organization",icon:Gt,keywords:["company","organization","organisation","sign in","enroll","managed","models","disconnect"]},{id:"usage",group:"account",labelKey:"settings.section.usage",icon:Bd,keywords:["tokens","cost","billing","plan","quota","remaining","weekly","5-hour","model","used"]},{id:"backups",group:"account",labelKey:"settings.section.backups",icon:ni,keywords:["export","import","restore","full backup","password","recovery"]},{id:"import",group:"account",labelKey:"settings.section.import",icon:Ye,keywords:["import","grok","grok bot","move","cursor","claude code","codex","gemini","skills","mcp","tools","bring"]},{id:"people",group:"account",labelKey:"settings.section.people",icon:Ct,keywords:["people","users","invite","sign in","members","admins","access"]},{id:"botAccess",group:"account",labelKey:"settings.section.botAccess",icon:Ct,keywords:["access","share","sharing","who can","view","chat","edit","permissions","team","members","bots"]},{id:"activity",group:"account",labelKey:"settings.section.activity",icon:Dd,keywords:["activity","audit","log","history","who changed","approvals","decisions","admin"]},{id:"workspaces",group:"account",labelKey:"settings.section.workspaces",icon:Gt,keywords:["clients","tenants","fleet","workspaces","installation","installations"]},{id:"experimental",group:"account",labelKey:"settings.section.experimental",icon:ed,keywords:["early","preview","learn","skill","authoring"]}],bh=[{id:"general",labelKey:"settings.section.general",icon:sd,sections:["general","appearance","people","import","organization","activity"],keywords:["account","theme","looks","open at login","startup","analytics","advanced mode","more settings","limits","timeout"]},{id:"botAccess",labelKey:"settings.section.botAccess",icon:Ct,sections:["botAccess"]},{id:"ai",labelKey:"settings.group.ai",icon:nd,sections:["engines","connections","imageGeneration"],keywords:["new bots","defaults","effort"]},{id:"skills",labelKey:"settings.section.skills",icon:Ps,sections:["skills"],keywords:["skills","skill hub","library","kỹ năng","thư viện"]},{id:"computer",labelKey:"settings.simple.page.computer",icon:bi,sections:["companion","desktopWorkspaces","computer","logins"]},{id:"billing",labelKey:"settings.simple.page.billing",icon:ad,sections:["usage"],keywords:["billing","included","allowance","cloud hours","voice"]},{id:"backups",labelKey:"settings.section.backups",icon:ni,sections:["backups"],keywords:["chuyển máy offline","transfer","export","import","restore","sao lưu"]},{id:"cloudAccount",labelKey:"settings.section.cloudAccount",icon:Rt,sections:["cloudAccount"],keywords:["cloud","limix cloud","đám mây","máy chủ","server"]},{id:"updates",labelKey:"settings.simple.page.updates",icon:Md,sections:["updates"],keywords:["update","version","release","product updates","newsletter","email updates","welcome","tour","diagnostics","logs","support"]}],ks=["experimental","workspaces","decisionModel"],yh={connections:"ai-keys",remote:"computer-elsewhere",desktopWorkspaces:"computer-elsewhere"};function vh(s,n){const a=bh.map(r=>({...r,sections:r.sections.filter(c=>s.has(c))})).filter(r=>r.sections.length>0),i=ks.includes(n)&&s.has(n)?Gs.find(r=>r.id===n):void 0;return i&&a.push({id:i.id,labelKey:i.labelKey,icon:i.icon,sections:[i.id]}),a}function jh(s,n,a){if(a<=0){s.scrollTop=0;return}const i=s.querySelector(`[data-settings-block="${n}"]`);i&&Bs(s,i)}function kh(s,n){return!n||[t(s.labelKey),...s.keywords??[]].some(a=>a.toLowerCase().includes(n))?!0:s.sections.some(a=>{const i=Gs.find(r=>r.id===a);return i?Ns(i,n):!1})}function Ns(s,n){return!n||s.id==="connections"&<.some(a=>Es(a,n))?!0:[t(s.labelKey),...s.keywords].some(a=>a.toLowerCase().includes(n))}function Nh(s){return s?lt.filter(n=>Es(n,s)).slice(0,8):[]}const wh=s=>s.uses?ds(s.uses,s.id):ds(s.id);function Jh(){return e.jsx(Ta,{modal:!0,children:e.jsx(Sh,{})})}function Sh(){const s=Rl(),{state:n,dispatch:a}=W(),i=al(),r=window.ogb?.remoteClient?.active===!0,c=n.appSettingsSection,o=i&&c==="remote"&&window.ogb?.environments?"desktopWorkspaces":r&&!["appearance","desktopWorkspaces"].includes(c)||c==="remote"?"companion":i&&c==="updates"?"general":c,d=l.useRef(null),m=l.useRef(null),u=l.useRef(i),[x,p]=l.useState("");l.useEffect(()=>window.ogb?.environments?.onOpenSettings?.(()=>p("")),[]),l.useEffect(()=>window.ogb?.onOpenAppSettings?.(()=>p("")),[]);const h=x.trim().toLowerCase(),f=Ot(),y=ei(),b=Gs.map(R=>R.id==="companion"?{...R,labelKey:y?"settings.section.phoneDevices":"settings.section.thisServer"}:R),k=b.filter(R=>!r||R.id==="companion"||R.id==="appearance"||R.id==="desktopWorkspaces").filter(R=>R.id!=="desktopWorkspaces"||!!window.ogb?.environments).filter(R=>R.id!=="organization"||!!window.ogb?.organization).filter(R=>R.id!=="cloudAccount"||!!(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)).filter(R=>R.id!=="workspaces"||ir(n.config)).filter(R=>R.id!=="people"||!window.ogb&&n.config?.cloudHome!==!0).filter(R=>R.id!=="activity"||!window.ogb&&f===!0).filter(R=>R.id!=="botAccess"||!!n.config?.team&&f===!0).filter(R=>(R.id!=="skills"||wn(n.config))&&(R.id!=="cloudAccount"||Ll)),S=k.filter(R=>Ns(R,h)),C=new Set([...k.map(R=>R.id),...r?[]:["updates"]]),w=i?[]:vh(C,o),P=w.filter(R=>kh(R,h)),v=w.find(R=>R.sections.includes(o)),B=i?b.find(R=>R.id===o)?.labelKey:v?.labelKey,j=i?S.some(R=>R.id===o)?void 0:S[0]?.id:v&&P.includes(v)?void 0:P[0]&&(P[0].sections.find(R=>S.some(E=>E.id===R))??P[0].sections[0]);l.useEffect(()=>{j&&a({type:"toggleAppSettings",open:!0,section:j})},[a,j]);const[A,I]=l.useState({}),_=La();l.useEffect(()=>{_&&I(R=>R["ai-keys"]?R:{...R,"ai-keys":!0})},[_]);const U=R=>{const E=h!==""||(A[R]??yh[c]===R);return{id:R,open:E,onToggle:()=>I(H=>({...H,[R]:!E}))}},[J,K]=l.useState(null),te=J?.for===c?J.view:null,ae=(R,E=c)=>K(R&&{view:R,for:E});l.useEffect(()=>{K(R=>R?.for===c?R:null)},[c]);const[de,D]=l.useState(null),T=i||il||!h?[]:lh.filter(R=>t(R).toLowerCase().includes(h)),Z=k.filter(R=>ks.includes(R.id)),ee=r||!k.some(R=>R.id==="connections")?[]:Nh(h),fe=R=>ee.map(E=>e.jsx("button",{type:"button","data-settings-key-result":E.id,className:R,onClick:()=>{p(""),ae(null),a(wh(E))},children:e.jsxs("span",{children:[t(E.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t(id(E).titleKey)]})]})},E.id)),N=v?.sections.indexOf(o)??0,re=!i&&c==="remote"?"remote":o;l.useEffect(()=>{m.current&&jh(m.current,re,i?0:re===o?N:1)},[i,re,o,N]),l.useEffect(()=>{if(!de)return;const R=m.current?.querySelector(`[data-settings-block="${de}"]`);m.current&&R&&Bs(m.current,R),D(null)},[de]),l.useEffect(()=>{const R=document.activeElement instanceof HTMLElement?document.activeElement:null,E=d.current,H=E?.querySelector("[data-settings-search]");u.current&&H?.checkVisibility()?H.focus():E?.focus();const pe=q=>{if(!s())return;if(!u.current&&E&&document.activeElement===E&&q.key.length===1&&!q.metaKey&&!q.ctrlKey&&!q.altKey&&H?.checkVisibility()){q.preventDefault(),H.focus(),p(ze=>ze+q.key);return}if(q.defaultPrevented||E&&[...E.querySelectorAll('[role="dialog"], [role="alertdialog"]')].some(ze=>ze.getClientRects().length))return;if(q.key==="Escape"){q.preventDefault(),a({type:"toggleAppSettings",open:!1});return}if(q.key!=="Tab"||!E)return;const ke=Array.from(E.querySelectorAll('button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), summary, [tabindex]:not([tabindex="-1"])')).filter(ze=>ze.checkVisibility());if(ke.length===0){q.preventDefault(),E.focus();return}const Pe=ke[0],et=ke[ke.length-1],tt=document.activeElement;q.shiftKey&&(tt===Pe||!E.contains(tt))?(q.preventDefault(),et.focus()):!q.shiftKey&&tt===et&&(q.preventDefault(),Pe.focus())};return window.addEventListener("keydown",pe),()=>{window.removeEventListener("keydown",pe),R?.focus()}},[a,s]);const se=R=>a({type:"toggleAppSettings",open:!0,section:R}),ne=n.appSettingsPhonePairing,G=yd(n.config?.cloudHome===!0)==="computer",ie={client:e.jsx(np,{hideWhenUnavailable:!0,legacyOnly:!0}),domain:r||y?null:e.jsx(Jm,{}),pairing:y?null:e.jsx(td,{cloudHome:n.config?.cloudHome===!0,focusRequest:G?0:ne,team:n.config?.team?.name,teamPhoneBlocked:n.config?.managedPolicy?.remoteAccess===!1?t("policy.teamRemoteBlocked",{organization:n.config.managedPolicy.organizationName}):null,simple:!i}),companion:y?e.jsx(Pm,{profileEmail:n.config?.profile?.email,focusRequest:ne,simple:!i}):null},le=R=>{switch(R){case"desktopWorkspaces":return e.jsxs(e.Fragment,{children:[e.jsx(Xn,{}),ie.client]});case"organization":return window.ogb?.organization&&!r?e.jsx(Ji,{}):null;case"cloudAccount":return(window.ogb?.cloudAccount||window.ogb?.cloudPlan&&n.config?.cloudHome===!0)&&!r?e.jsx(Hp,{linkRequest:n.appSettingsCloudLink,cloudHome:n.config?.cloudHome===!0,teamHome:n.config?.team,onConnectPhone:()=>{a({type:"toggleAppSettings",open:!1}),window.dispatchEvent(new Event("limix:phone"))},onAddCloud:i?()=>a({type:"openCloudAdd",source:"app_settings"}):void 0,onSignIn:()=>a({type:"openCloudAdd",source:"app_settings",signIn:!0})}):null;case"general":return e.jsxs(e.Fragment,{children:[e.jsx(ps,{}),e.jsx(si,{}),e.jsx(Si,{}),e.jsx(Ld,{}),e.jsx(ld,{}),e.jsxs(Y,{title:t("settings.profile.title"),subtitle:t("settings.profile.sharedSubtitle"),children:[e.jsx(gr,{}),e.jsx(fr,{})]}),e.jsx(ms,{}),e.jsx(wi,{}),e.jsx(Id,{}),e.jsx(Er,{}),e.jsx(Ni,{}),e.jsx(Za,{}),e.jsx(mi,{}),e.jsx(Y,{title:t("settings.roomTurns.title"),subtitle:t("settings.roomTurns.subtitle"),children:e.jsx(dr,{})}),e.jsx(Y,{title:t("settings.mcpCalls.title"),subtitle:t("settings.mcpCalls.subtitle"),children:e.jsx(pr,{})}),e.jsx(br,{}),e.jsx(yr,{}),e.jsx(Nr,{}),e.jsx(Ci,{}),e.jsx(Xx,{}),!r&&e.jsx(oi,{}),e.jsx(li,{}),e.jsx(Ei,{})]});case"appearance":return e.jsxs(e.Fragment,{children:[e.jsx(or,{}),e.jsx(Y,{title:t("settings.skin.title"),subtitle:t("settings.skin.subtitle"),children:e.jsx(cr,{})}),e.jsx(lr,{}),e.jsx(fp,{}),r&&e.jsx(ps,{}),r&&e.jsx(ms,{}),e.jsx(Bx,{}),e.jsx(Ox,{}),e.jsx(xi,{}),e.jsx(hi,{}),e.jsx(gi,{}),e.jsx(Mx,{}),e.jsx(ti,{}),e.jsx(Vi,{}),e.jsx(Sd,{}),e.jsx(Cd,{}),e.jsx(Ed,{}),e.jsx(Cr,{}),!r&&e.jsx(pi,{}),e.jsx(Ad,{})]});case"experimental":return e.jsx(wd,{});case"connections":return e.jsx(je,{children:e.jsx(ku,{})});case"decisionModel":return e.jsx(je,{children:e.jsx(Lu,{})});case"imageGeneration":return e.jsx(je,{children:e.jsx($u,{})});case"engines":return e.jsx(je,{children:e.jsx(Li,{})});case"backups":return e.jsxs(je,{children:[e.jsx(rd,{}),e.jsx(Yx,{})]});case"import":return e.jsx(je,{children:e.jsx(Sr,{})});case"companion":return e.jsxs(e.Fragment,{children:[ie.companion,ie.pairing,ie.domain,window.ogb?.environments?null:ie.client]});case"computer":return e.jsxs(e.Fragment,{children:[e.jsx(ci,{}),e.jsx(di,{}),e.jsx(ui,{}),e.jsx(je,{children:e.jsx(zi,{})})]});case"logins":return e.jsx(Wi,{});case"usage":return e.jsx(je,{note:"settings.adminOnly.usage",children:e.jsx(nr,{})});case"skills":return wn(n.config)?e.jsx(fx,{}):null;case"people":return e.jsx(Di,{});case"activity":return e.jsx(_i,{});case"botAccess":return e.jsx(Fm,{});case"workspaces":return e.jsx(wx,{});default:return null}},ce=()=>{se("general"),ae("more","general")},ve=R=>{const E=H=>R.sections.includes(H);switch(R.id){case"general":return te==="looks"?e.jsx(uh,{toolCalls:!r,onBack:()=>{ae(null),D("appearance")}}):te==="more"?e.jsx(mh,{sections:Z,onOpen:H=>{ae(null),se(H)},onBack:()=>{ae(null),D("more")}}):e.jsx(ch,{has:E,peopleOpen:o==="people",onLooks:()=>ae("looks"),onMore:E("general")?()=>ae("more"):void 0});case"ai":return e.jsx(ph,{has:E,disclose:U,connections:le("connections")});case"computer":return e.jsx(xh,{has:E,remoteAccess:ie,servers:e.jsx(Xn,{}),disclose:U});case"billing":return e.jsx(hh,{has:E,disclose:U,cloudAccount:le("cloudAccount")});case"updates":return e.jsx(fh,{remoteActive:r});default:return e.jsxs(e.Fragment,{children:[ks.includes(R.sections[0])&&C.has("general")&&e.jsx("div",{children:e.jsx("button",{type:"button",className:"ui-button",onClick:ce,children:t("settings.simple.looks.back")})}),R.sections.map(H=>e.jsx("section",{"data-settings-block":H,className:"flex scroll-mt-4 flex-col gap-4",children:le(H)},H))]})}},$=()=>a({type:"toggleAppSettings",open:!1}),oe=(R,E)=>e.jsxs("div",{className:R,children:[e.jsx(mt,{size:15,"aria-hidden":"true",className:"shrink-0 text-ink-secondary"}),e.jsx("input",{"data-settings-search":!0,value:x,onChange:H=>p(H.target.value),onKeyDown:H=>{H.key==="Escape"&&(H.stopPropagation(),x?p(""):$())},placeholder:t("settings.search"),"aria-label":t("settings.searchAria"),className:E})]});if(!i){const R=v?.id==="general"?te:null,E="flex min-h-8 shrink-0 cursor-pointer items-center rounded-lg px-[9px] py-1.5 text-left text-[13px] leading-[18px] text-ink transition-colors hover:bg-ink/[0.06] motion-reduce:transition-none",H=q=>{ae(null),se(q)},pe=h?[...Z.filter(q=>Ns(q,h)).map(q=>({key:q.id,labelKey:q.labelKey,open:()=>H(q.id)})),...(C.has("general")?oh:[]).filter(q=>t(q).toLowerCase().includes(h)).map(q=>({key:q,labelKey:q,open:()=>{ce(),D("limits")}}))]:[];return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"simple",style:Cn(),onMouseDown:q=>q.stopPropagation(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:d,role:"dialog","data-look":"settings","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,style:{outline:"none"},className:"glass-surface glass-popup animate-pop-in relative flex overflow-hidden rounded-2xl text-ink",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),e.jsx(rl,{}),e.jsxs("nav",{"aria-label":t("settings.title"),className:"glass-rail hidden min-h-0 w-[198px] md:w-[220px] shrink-0 flex-col gap-0.5 overflow-y-auto px-3 py-4 sm:flex",children:[oe("mb-2 flex h-8 shrink-0 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] text-[13px] focus-within:ring-2 focus-within:ring-focus/60","w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none"),P.length===0&&T.length===0&&pe.length===0&&ee.length===0&&e.jsx("div",{className:"px-[9px] py-3 text-[13px] leading-[18px] text-ink-secondary",children:t("settings.noMatch",{query:x.trim()})}),P.map(q=>{const ke=q.icon,Pe=q===v;return e.jsxs("button",{type:"button","data-settings-page":q.id,onClick:()=>H(q.sections[0]),"aria-current":Pe?"page":void 0,className:z("flex min-h-8 shrink-0 cursor-pointer items-center gap-[9px] rounded-lg px-[9px] py-1 leading-[18px] text-left text-[13px] text-ink transition-colors motion-reduce:transition-none",Pe?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(ke,{size:15,"aria-hidden":"true",className:"shrink-0"}),e.jsx("span",{className:"min-w-0 whitespace-normal [overflow-wrap:anywhere]",children:t(q.labelKey)})]},q.id)}),T.map(q=>e.jsx("button",{type:"button","data-settings-advanced-only":q,onClick:()=>{p(""),H("general"),D("advanced-mode")},className:E,children:e.jsxs("span",{children:[t(q)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.advanced")]})]})},q)),pe.map(q=>e.jsx("button",{type:"button","data-settings-more-result":q.key,onClick:()=>{p(""),q.open()},className:E,children:e.jsxs("span",{children:[t(q.labelKey)," ",e.jsxs("span",{className:"text-ink-secondary",children:["· ",t("settings.simple.more.title")]})]})},q.key)),fe(E)]}),e.jsxs("div",{className:"relative flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("header",{className:"flex shrink-0 items-center gap-3 py-3 pl-4 pr-14 sm:pb-1.5 sm:pl-12 sm:pt-8",children:[e.jsx(xe,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:v?.id??"",onChange:q=>{p("");const ke=w.find(Pe=>Pe.id===q.target.value);ke&&H(ke.sections[0])},children:w.map(q=>e.jsx("option",{value:q.id,children:t(q.labelKey)},q.id))}),e.jsx("h2",{className:"hidden truncate text-[17px] font-medium leading-6 tracking-[-0.008em] text-ink sm:block",children:R==="looks"?t("settings.simple.page.looks"):R==="more"?t("settings.simple.more.title"):v?t(v.labelKey):null})]}),e.jsx("button",{type:"button",onClick:$,"aria-label":t("settings.close"),title:`${t("settings.close")} (${Sn("close-panel")})`,className:"absolute right-5 top-[18px] flex size-8 cursor-pointer items-center justify-center rounded-full text-ink-secondary transition-colors hover:bg-ink/[0.06] hover:text-ink motion-reduce:transition-none",children:e.jsx($e,{size:16,"aria-hidden":"true"})}),e.jsxs("div",{ref:m,"data-settings-scroll":!0,className:z("settings-scroll flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto px-4 pb-10 pt-4 sm:px-8 sm:pb-12 sm:pt-[22px]",qa,"[&_.uppercase]:normal-case [&_.uppercase]:tracking-normal"),children:[e.jsx(da,{config:n.config}),v?ve(v):null]})]})]})]})}return e.jsxs("div",{className:"glass-popup-frame","data-settings-sheet":!0,"data-settings-look":"advanced",style:Cn(),onMouseDown:R=>R.stopPropagation(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:d,role:"dialog","aria-modal":"true","aria-labelledby":"app-settings-title",tabIndex:-1,className:"glass-surface glass-popup animate-pop-in relative flex overflow-hidden rounded-2xl outline-none",children:[e.jsx("span",{id:"app-settings-title",className:"sr-only",children:t("settings.title")}),e.jsxs("nav",{className:"glass-rail hidden min-h-0 w-[200px] md:w-[220px] shrink-0 flex-col gap-1 overflow-y-auto border-r border-hairline/30 p-3 sm:flex",children:[e.jsx("div",{className:"shrink-0 px-2 py-3 text-[15px] font-semibold text-ink",children:t("settings.title")}),oe("mb-2 mt-1 flex h-8 shrink-0 items-center gap-2 rounded-lg bg-ink/[0.05] px-[9px] text-[13px] focus-within:ring-2 focus-within:ring-focus/60","w-full min-w-0 bg-transparent text-[13px] text-ink placeholder:text-ink-tertiary focus:outline-none"),S.length===0&&e.jsx("div",{className:"px-2.5 py-4 text-[13px] leading-relaxed text-ink-secondary",children:t("settings.noMatch",{query:x.trim()})}),Sa.map(R=>{const E=S.filter(H=>H.group===R.id);return E.length===0?null:e.jsxs("div",{role:"group","aria-labelledby":`settings-group-${R.id}`,"data-settings-group":R.id,className:"flex flex-col gap-0.5 pb-2",children:[e.jsx("div",{id:`settings-group-${R.id}`,className:"px-[9px] pb-1 pt-2 text-[12px] font-medium leading-4 text-ink-tertiary",children:t(R.labelKey)}),E.map(({id:H,labelKey:pe,icon:q})=>e.jsxs("button",{"data-settings-section":H,onClick:()=>se(H),"aria-current":o===H?"page":void 0,className:z("flex min-h-8 shrink-0 cursor-pointer items-center gap-[9px] rounded-lg px-[9px] py-1 leading-[18px] text-left text-[13px] text-ink transition-colors motion-reduce:transition-none",o===H?"bg-ink/[0.08]":"hover:bg-ink/[0.06]"),children:[e.jsx(q,{size:15,className:"shrink-0"}),e.jsx("span",{className:"min-w-0 whitespace-normal [overflow-wrap:anywhere]",children:t(pe)})]},H))]},R.id)}),fe("cursor-pointer flex min-h-9 items-center rounded-lg px-2.5 py-2 text-left text-[13px] text-ink transition-colors hover:bg-control/50 motion-reduce:transition-none")]}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-hairline/30 px-3 py-3 sm:pl-9",children:[e.jsx(xe,{className:"min-w-0 sm:hidden","aria-label":t("settings.title"),value:o,onChange:R=>{p(""),se(R.target.value)},children:Sa.map(R=>{const E=k.filter(H=>H.group===R.id);return E.length===0?null:e.jsx("optgroup",{label:t(R.labelKey),children:E.map(({id:H,labelKey:pe})=>e.jsx("option",{value:H,children:t(pe)},H))},R.id)})}),e.jsx("span",{className:"hidden text-[15px] font-semibold text-ink sm:block",children:B?t(B):null}),e.jsx("button",{onClick:$,"aria-label":t("settings.close"),title:`${t("settings.close")} (${Sn("close-panel")})`,className:"ui-icon-button cursor-pointer shrink-0 max-md:size-9 max-md:rounded-full max-md:border max-md:border-hairline max-md:bg-card",children:e.jsx($e,{size:18})})]}),e.jsxs("div",{ref:m,className:"flex flex-1 flex-col gap-4 overflow-y-auto px-3 py-4 sm:px-5 sm:pb-5",children:[e.jsx(da,{config:n.config}),le(o)]})]})]})]})}export{Gs as SECTIONS,Sa as SETTINGS_GROUPS,yh as SIMPLE_FOLDED,ks as SIMPLE_HIDDEN_SECTIONS,bh as SIMPLE_PAGES,Jh as SettingsModal,Nh as keySearchResults,wh as openKeyResult,jh as revealSettingsBlock,Ns as sectionMatches,vh as simpleSettingsPages};
|