tmex-cli 0.12.4 → 0.14.0
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/CHANGELOG.md +22 -6
- package/dist/cli-node.js +492 -87
- package/dist/runtime/server.js +1912 -132
- package/package.json +1 -1
- package/resources/fe-dist/assets/DevicePage-Ctq31eWb.js +19 -0
- package/resources/fe-dist/assets/DevicesPage-DGo44NW0.js +1 -0
- package/resources/fe-dist/assets/{FilePage-D1t8_zlX.js → FilePage-BpubOqjN.js} +3 -4
- package/resources/fe-dist/assets/SettingsPage-QT6fy6XA.js +39 -0
- package/resources/fe-dist/assets/agent-tab-A2FeMPwL.js +38 -0
- package/resources/fe-dist/assets/api-CGfOwFKm.js +10 -0
- package/resources/fe-dist/assets/{arc-Cv0H1Phu.js → arc-B2dphCVi.js} +1 -2
- package/resources/fe-dist/assets/{architectureDiagram-3BPJPVTR-DG7npZeK.js → architectureDiagram-3BPJPVTR-BpvEhd8M.js} +1 -2
- package/resources/fe-dist/assets/{blockDiagram-GPEHLZMM-weB7PKUK.js → blockDiagram-GPEHLZMM-CI_NnIJz.js} +1 -2
- package/resources/fe-dist/assets/{c4Diagram-AAUBKEIU-C0sEabtp.js → c4Diagram-AAUBKEIU-Y6RrOc7Y.js} +1 -2
- package/resources/fe-dist/assets/{card-Spfb5xRZ.js → card-CydUB3N3.js} +1 -2
- package/resources/fe-dist/assets/channel-Ce3VMo9B.js +1 -0
- package/resources/fe-dist/assets/{chunk-2J33WTMH-BxOp2sIC.js → chunk-2J33WTMH-BQN_fYaa.js} +1 -2
- package/resources/fe-dist/assets/{chunk-4BX2VUAB-bhg4hxVT.js → chunk-4BX2VUAB-BExarxjk.js} +1 -2
- package/resources/fe-dist/assets/{chunk-55IACEB6-v6jayOak.js → chunk-55IACEB6-DeOEgcn_.js} +1 -2
- package/resources/fe-dist/assets/{chunk-727SXJPM-IY0KVws8.js → chunk-727SXJPM-CwkxCtPA.js} +1 -2
- package/resources/fe-dist/assets/{chunk-AQP2D5EJ-CgwymoWa.js → chunk-AQP2D5EJ-_IoTtvOb.js} +1 -2
- package/resources/fe-dist/assets/{chunk-FMBD7UC4-DN35690f.js → chunk-FMBD7UC4-6pvmQ3Lj.js} +1 -2
- package/resources/fe-dist/assets/{chunk-ND2GUHAM-lJmtxdhS.js → chunk-ND2GUHAM-CxpGf5zM.js} +1 -2
- package/resources/fe-dist/assets/{chunk-QZHKN3VN-DFeaB8rn.js → chunk-QZHKN3VN-DOMH0v_e.js} +1 -2
- package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-BjK-bnh-.js +1 -0
- package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-BjK-bnh-.js +1 -0
- package/resources/fe-dist/assets/copy-DnlW35bA.js +6 -0
- package/resources/fe-dist/assets/{cose-bilkent-S5V4N54A-Dw2yYQz4.js → cose-bilkent-S5V4N54A-D03NElzH.js} +1 -2
- package/resources/fe-dist/assets/cytoscape.esm-DTSO7Bv0.js +0 -1
- package/resources/fe-dist/assets/{dagre-BM42HDAG-BeMjJ7ln.js → dagre-BM42HDAG-CVOxLhKQ.js} +1 -2
- package/resources/fe-dist/assets/defaultLocale-DX6XiGOO.js +0 -1
- package/resources/fe-dist/assets/{diagram-2AECGRRQ-Dur8_CuN.js → diagram-2AECGRRQ-p564GAo-.js} +1 -2
- package/resources/fe-dist/assets/{diagram-5GNKFQAL-GJc7gVa_.js → diagram-5GNKFQAL-C_pgnQLt.js} +1 -2
- package/resources/fe-dist/assets/{diagram-KO2AKTUF-pxckXfjw.js → diagram-KO2AKTUF-B36jioML.js} +1 -2
- package/resources/fe-dist/assets/{diagram-LMA3HP47-B9E8-X7C.js → diagram-LMA3HP47-B8P4WWeq.js} +1 -2
- package/resources/fe-dist/assets/{diagram-OG6HWLK6-DrhHw5wy.js → diagram-OG6HWLK6-CTL4zJlz.js} +1 -2
- package/resources/fe-dist/assets/en_US-DRPd4vPi.js +1 -0
- package/resources/fe-dist/assets/{erDiagram-TEJ5UH35-DY9Wg1A1.js → erDiagram-TEJ5UH35-DbKPL3Fa.js} +1 -2
- package/resources/fe-dist/assets/files-tab-CeUM00x8.js +70 -0
- package/resources/fe-dist/assets/{flowDiagram-I6XJVG4X-eq3WE9d6.js → flowDiagram-I6XJVG4X-DvOU6wtN.js} +1 -2
- package/resources/fe-dist/assets/{ganttDiagram-6RSMTGT7-BlXISXe1.js → ganttDiagram-6RSMTGT7-CwgNky8L.js} +1 -2
- package/resources/fe-dist/assets/{gitGraphDiagram-PVQCEYII-Bg-xHeIY.js → gitGraphDiagram-PVQCEYII-B3U-hNGe.js} +1 -2
- package/resources/fe-dist/assets/graph-CAnANduQ.js +0 -1
- package/resources/fe-dist/assets/index-D-q7dOhH.css +1 -0
- package/resources/fe-dist/assets/index-DAElYydw.js +299 -0
- package/resources/fe-dist/assets/index-DBHh6Xu1.js +29 -0
- package/resources/fe-dist/assets/{infoDiagram-5YYISTIA-CW2drAHG.js → infoDiagram-5YYISTIA-BmcWF7v1.js} +1 -2
- package/resources/fe-dist/assets/init-Gi6I4Gst.js +0 -1
- package/resources/fe-dist/assets/{ishikawaDiagram-YF4QCWOH-Qchz0nqR.js → ishikawaDiagram-YF4QCWOH-Dr8C0MtS.js} +1 -2
- package/resources/fe-dist/assets/ja_JP-DHREHMZZ.js +1 -0
- package/resources/fe-dist/assets/{journeyDiagram-JHISSGLW-Dk-UsexE.js → journeyDiagram-JHISSGLW-DzlvXb4K.js} +1 -2
- package/resources/fe-dist/assets/{kanban-definition-UN3LZRKU-DKeGp7b5.js → kanban-definition-UN3LZRKU-4aBWZlcm.js} +1 -2
- package/resources/fe-dist/assets/layout-DGIYPm2g.js +0 -1
- package/resources/fe-dist/assets/{linear-Bt4f_qDW.js → linear-_wXLepjd.js} +1 -2
- package/resources/fe-dist/assets/{markdown-preview-DXv9GzaA.js → markdown-preview-BX0o83rG.js} +6 -7
- package/resources/fe-dist/assets/{mermaid.core-B-wSkmMd.js → mermaid.core-DoE3dx_X.js} +5 -6
- package/resources/fe-dist/assets/{mindmap-definition-RKZ34NQL-DXBwCMXu.js → mindmap-definition-RKZ34NQL-CKpq2s43.js} +1 -2
- package/resources/fe-dist/assets/ordinal-BENe2yWM.js +0 -1
- package/resources/fe-dist/assets/{pieDiagram-4H26LBE5--KxRgbWG.js → pieDiagram-4H26LBE5-DlW1TLza.js} +1 -2
- package/resources/fe-dist/assets/{quadrantDiagram-W4KKPZXB-DqXsCI9E.js → quadrantDiagram-W4KKPZXB-NEwxpMVe.js} +1 -2
- package/resources/fe-dist/assets/{requirementDiagram-4Y6WPE33-C2KeTWqB.js → requirementDiagram-4Y6WPE33-CGysr6uH.js} +1 -2
- package/resources/fe-dist/assets/{sankeyDiagram-5OEKKPKP-CC5tcr7d.js → sankeyDiagram-5OEKKPKP-j8yXOgys.js} +1 -2
- package/resources/fe-dist/assets/selection-clipboard-Dq6Zemfd.js +1 -0
- package/resources/fe-dist/assets/send-BtOPYsPT.js +11 -0
- package/resources/fe-dist/assets/{sequenceDiagram-3UESZ5HK-CqlMDtOG.js → sequenceDiagram-3UESZ5HK-BRPWK9ZU.js} +1 -2
- package/resources/fe-dist/assets/{stateDiagram-AJRCARHV-CVcrlBiw.js → stateDiagram-AJRCARHV-C8ckQlA7.js} +1 -2
- package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-Cm0vyyJy.js +1 -0
- package/resources/fe-dist/assets/{terminal-settings-panel-CYV9svzz.js → terminal-settings-panel-ZnL_cBER.js} +6 -7
- package/resources/fe-dist/assets/{timeline-definition-PNZ67QCA-CEBskfkL.js → timeline-definition-PNZ67QCA-BXMFPa99.js} +1 -2
- package/resources/fe-dist/assets/transfer-toast-CUkPc73G.js +6 -0
- package/resources/fe-dist/assets/triangle-alert-DyM9tU7d.js +6 -0
- package/resources/fe-dist/assets/{vennDiagram-CIIHVFJN-CrxyVTtu.js → vennDiagram-CIIHVFJN-Bk8oPY9E.js} +1 -2
- package/resources/fe-dist/assets/{wardley-L42UT6IY-CSmsRb8z.js → wardley-L42UT6IY-Bi_GTP2_.js} +1 -2
- package/resources/fe-dist/assets/{wardleyDiagram-YWT4CUSO-DoDzNeOA.js → wardleyDiagram-YWT4CUSO-CaPDmxFM.js} +1 -2
- package/resources/fe-dist/assets/{xychartDiagram-2RQKCTM6-Dbq_OKsv.js → xychartDiagram-2RQKCTM6-EHogasXy.js} +1 -2
- package/resources/fe-dist/assets/zap-CBgYyGBV.js +6 -0
- package/resources/fe-dist/assets/zh_CN-DMEKXuFd.js +1 -0
- package/resources/fe-dist/index.html +2 -2
- package/resources/gateway-drizzle/0010_lucky_kabuki.sql +32 -0
- package/resources/gateway-drizzle/0011_stormy_sauron.sql +1 -0
- package/resources/gateway-drizzle/meta/_journal.json +14 -0
- package/resources/fe-dist/assets/DevicePage-C4JS6baR.js +0 -15
- package/resources/fe-dist/assets/DevicesPage-p0CfWP1T.js +0 -2
- package/resources/fe-dist/assets/SettingsPage-Cq6n8Xjc.js +0 -27
- package/resources/fe-dist/assets/channel-DDiDKfY0.js +0 -2
- package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-CXFjdzka.js +0 -2
- package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-CXFjdzka.js +0 -2
- package/resources/fe-dist/assets/index-CXIj7HZi.css +0 -1
- package/resources/fe-dist/assets/index-CYmVLCAD.js +0 -488
- package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-B0BDuZBM.js +0 -2
|
@@ -71,6 +71,20 @@
|
|
|
71
71
|
"when": 1781546649471,
|
|
72
72
|
"tag": "0009_lying_lethal_legion",
|
|
73
73
|
"breakpoints": true
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"idx": 10,
|
|
77
|
+
"version": "6",
|
|
78
|
+
"when": 1781940934364,
|
|
79
|
+
"tag": "0010_lucky_kabuki",
|
|
80
|
+
"breakpoints": true
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"idx": 11,
|
|
84
|
+
"version": "6",
|
|
85
|
+
"when": 1782709181895,
|
|
86
|
+
"tag": "0011_stormy_sauron",
|
|
87
|
+
"breakpoints": true
|
|
74
88
|
}
|
|
75
89
|
]
|
|
76
90
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import{_ as We,u as Re,j as o,$ as Ge,a0 as Ve,a1 as Qe,a2 as Je,a3 as Ze,a4 as et,a5 as tt,r,d as K,a6 as ee,a7 as He,a8 as $e,a9 as nt,aa as rt,ab as st,ac as ze,ad as ot,o as he,ae as it,af as Pe,ag as ct,b as Oe,ah as Le,ai as at,c as _e,aj as qe,ak as xe,al as lt,am as ut,an as ke,ao as dt,B as de,T as ft,ap as De,aq as mt,ar as ht,as as wt,A as pt,f as xt,g as vt,i as gt,k as St,l as bt,m as Et,n as Tt,at as Rt,au as yt}from"./index-CYmVLCAD.js";import{T as It,C as Ct,c as jt,F as Nt,a as Ue,R as Mt,A as kt,S as At,f as Pt,t as Lt}from"./terminal-settings-panel-CYV9svzz.js";/**
|
|
2
|
-
* @license lucide-react v0.564.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const _t=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],zt=We("settings-2",_t);/**
|
|
7
|
-
* @license lucide-react v0.564.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const Dt=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],Ft=We("smartphone",Dt);function Bt({open:n,onOpenChange:e}){const{t:i}=Re();return o.jsx(Ge,{open:n,onOpenChange:e,children:o.jsxs(Ve,{side:"bottom",className:"max-h-[88dvh] overflow-y-auto pb-[var(--tmex-safe-area-bottom)] sm:mx-auto sm:max-w-md sm:rounded-t-2xl sm:border sm:border-b-0","data-testid":"keyboard-behavior-sheet",children:[o.jsxs(Qe,{children:[o.jsx(Je,{children:i("settings.terminal.title")}),o.jsx(Ze,{children:i("settings.terminal.savedInBrowser")})]}),o.jsx("div",{className:"px-4 pb-4",children:o.jsx(It,{})})]})})}function Wt({visible:n,canPaste:e,onCopy:i,onPaste:c,onDismiss:p}){const{t:R}=Re();if(!n)return null;const N=v=>{v.preventDefault()};return o.jsxs("div",{className:"absolute top-2 left-1/2 z-20 flex -translate-x-1/2 items-center gap-1 rounded-lg border bg-background/95 p-1 shadow-md backdrop-blur","data-testid":"terminal-selection-toolbar",children:[o.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:N,onClick:i,"data-testid":"terminal-selection-copy",children:[o.jsx(et,{className:"h-4 w-4"}),R("terminal.copy")]}),e&&o.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:N,onClick:c,"data-testid":"terminal-selection-paste",children:[o.jsx(Ct,{className:"h-4 w-4"}),R("terminal.paste")]}),o.jsx("button",{type:"button",className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground",onMouseDown:N,onClick:p,"aria-label":R("terminal.clearSelection"),"data-testid":"terminal-selection-dismiss",children:o.jsx(tt,{className:"h-4 w-4"})})]})}function Ye(n){if(!n)return n;const e=n.replace(/\r\n/g,`
|
|
12
|
-
`);return(e.endsWith(`
|
|
13
|
-
`)?e.slice(0,-1):e).replace(/\n/g,`\r
|
|
14
|
-
`)}const Ht="\x1B[?1049h\x1B[H\x1B[2J";function $t(n){return Ht+Ye(n)}function Fe(n,e){let i=e,c=0;for(const v of n)v===10&&!i&&(c+=1),i=v===13;const p=i;if(c===0)return{normalized:n,endedWithCR:p};const R=new Uint8Array(n.length+c);let N=0;i=e;for(const v of n)v===10&&!i&&(R[N]=13,N+=1),R[N]=v,N+=1,i=v===13;return{normalized:R,endedWithCR:p}}const Ot=1.3,qt=36,Ut=500,Yt=12;function Xt(n,e){const i=r.useRef(!1);return r.useEffect(()=>{const c=n.current;if(!c||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;i.current=!0;let R=0,N=null,v=!1,E=0,G=0,s=0,C=null,F=!1;const V=()=>{C!==null&&(clearTimeout(C),C=null)},O=w=>w?!!(w.closest(".scrollbar")||w.closest(".slider")||w.closest(".xterm-scroll-area")):!1,S=(w,m,b)=>{const M=b instanceof Element?b:null;if(O(M))return!0;const $=document.elementFromPoint(w,m);if(O($))return!0;const h=c.querySelector(".xterm");if(!(h instanceof HTMLElement))return!1;const g=h.getBoundingClientRect(),L=w>=g.left&&w<=g.right,_=m>=g.top&&m<=g.bottom;return!L||!_?!1:w>=g.right-qt},Q=()=>[c.querySelector(".xterm-viewport"),c.querySelector(".xterm-scrollable-element")].filter(m=>m instanceof HTMLElement),f=w=>{if(N===null)return null;for(let m=0;m<w.length;m+=1){const b=w.item(m);if(b&&b.identifier===N)return b}return null},P=w=>{if(V(),w.touches.length!==1)return;const m=w.touches.item(0);m&&(N=m.identifier,R=m.clientY,E=0,v=S(m.clientX,m.clientY,w.target),G=m.clientX,s=m.clientY,F=!1,v||(C=setTimeout(()=>{var M;C=null;const b=(e==null?void 0:e())??null;(M=b==null?void 0:b.startTouchSelection)!=null&&M.call(b,G,s,"word")&&(F=!0)},Ut)))},B=w=>{var L,_,T,q,U,X,se,y,ne;const m=f(w.touches)??w.touches.item(0);if(!m)return;if(F){const A=(e==null?void 0:e())??null;(L=A==null?void 0:A.updateTouchSelection)==null||L.call(A,m.clientX,m.clientY),w.cancelable&&w.preventDefault();return}if(C!==null&&Math.hypot(m.clientX-G,m.clientY-s)>Yt&&V(),v||(v=S(m.clientX,m.clientY,w.target),v&&(E=0)),v)return;const b=m.clientY,M=R-b;if(R=b,M===0)return;let $=!1,h=!1;const g=(e==null?void 0:e())??null;if(g){const A=g==null?void 0:g._core,k=((U=(q=(T=(_=A==null?void 0:A._renderService)==null?void 0:_.dimensions)==null?void 0:T.css)==null?void 0:q.cell)==null?void 0:U.height)??18;E+=M*Ot;const j=E>0?Math.floor(E/k):Math.ceil(E/k);if(typeof g.handleViewportGesture=="function")j!==0&&($=g.handleViewportGesture({source:"touch",deltaY:j*k,clientX:m.clientX,clientY:m.clientY}),E-=j*k);else if(j!==0){const D=((se=(X=g.buffer)==null?void 0:X.active)==null?void 0:se.viewportY)??0;g.scrollLines(j);const re=((ne=(y=g.buffer)==null?void 0:y.active)==null?void 0:ne.viewportY)??0;$=D!==re,h=j<0&&D<=0&&re<=0,E-=j*k}}else{const A=Q();if(A.length===0)return;for(const k of A){const j=k.scrollTop;k.scrollTop+=M;const D=k.scrollTop;Math.abs(D-j)>0&&($=!0),M<0&&D<=0&&(h=!0)}if(!$){const k=c.querySelector(".xterm");if(k instanceof HTMLElement){const j=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:M}),D=k.dispatchEvent(j);$=j.defaultPrevented||!D}}}w.cancelable&&($||h)&&w.preventDefault()},z=w=>{var b;if(V(),!(N===null||!f(w.changedTouches))&&(N=null,E=0,v=!1,F)){F=!1;const M=(e==null?void 0:e())??null;(b=M==null?void 0:M.endTouchSelection)==null||b.call(M)}},H=w=>{F&&w.preventDefault()};return c.addEventListener("touchstart",P,{passive:!0}),c.addEventListener("touchmove",B,{passive:!1}),c.addEventListener("touchend",z,{passive:!0}),c.addEventListener("touchcancel",z,{passive:!0}),c.addEventListener("contextmenu",H),()=>{i.current=!1,V(),c.removeEventListener("touchstart",P),c.removeEventListener("touchmove",B),c.removeEventListener("touchend",z),c.removeEventListener("touchcancel",z),c.removeEventListener("contextmenu",H)}},[n,e]),i}function Kt({now:n,remoteSize:e,pendingLocalSize:i,ttlMs:c=2e3}){return!i||n-i.at>c?!0:i.cols===e.cols&&i.rows===e.rows}function Gt({currentSize:n,containerSize:e,force:i=!1}){return i?!0:n.cols!==e.cols||n.rows!==e.rows}function Vt({deviceId:n,paneId:e,deviceConnected:i,isSelectionInvalid:c,onResize:p,onSync:R,getContainerRect:N}){const v=r.useRef(null),E=r.useRef(null),G=r.useRef(null),s=r.useRef(null),C=r.useRef(0),F=r.useRef([]),V=r.useRef(null),O=r.useRef(null),S=r.useRef(N),Q=r.useRef(!1),f=r.useRef(p),P=r.useRef(R);r.useEffect(()=>{f.current=p},[p]),r.useEffect(()=>{P.current=R},[R]),r.useEffect(()=>{S.current=N},[N]);const B=r.useCallback(()=>{var X,se,y,ne,A,k,j,D,re,ve;const h=O.current,g=V.current;if(!h||!g||!h.element)return null;let L;try{const ae=g.proposeDimensions();if(!ae)throw new Error("fitAddon.proposeDimensions() returned null");L=Math.max(2,ae.cols)}catch{const ae=h._core,ye=((ne=(y=(se=(X=ae==null?void 0:ae._renderService)==null?void 0:X.dimensions)==null?void 0:se.css)==null?void 0:y.cell)==null?void 0:ne.width)??9,a=(A=S.current)==null?void 0:A.call(S);if(!a||a.width===0)return null;L=Math.max(2,Math.floor(a.width/ye))}const _=(k=S.current)==null?void 0:k.call(S);if(!_||_.height===0)return null;const T=h._core,q=((ve=(re=(D=(j=T==null?void 0:T._renderService)==null?void 0:j.dimensions)==null?void 0:D.css)==null?void 0:re.cell)==null?void 0:ve.height)??17,U=Math.max(2,Math.floor(_.height/q));return{cols:L,rows:U}},[]),z=r.useCallback((h,g)=>{const L=O.current;L&&(L.cols===h&&L.rows===g||L.resize(h,g))},[]),H=r.useCallback((h,g=!1)=>{if(!n||!e||!i||c&&h!=="sync"||!g&&Date.now()<C.current||!O.current)return!1;const _=B();if(!_)return!1;const{cols:T,rows:q}=_,U=G.current;return!g&&U&&U.cols===T&&U.rows===q?(z(T,q),!0):(z(T,q),h==="sync"?P.current(T,q):f.current(T,q),G.current={cols:T,rows:q},s.current={cols:T,rows:q,at:Date.now()},!0)},[z,i,n,c,B,e]),w=r.useCallback((h="resize",g={})=>{const{immediate:L=!1,force:_=!1}=g;E.current!==null&&(window.clearTimeout(E.current),E.current=null),v.current!==null&&(cancelAnimationFrame(v.current),v.current=null);const T=()=>{v.current=requestAnimationFrame(()=>{v.current=null,H(h,_)})};if(L){T();return}E.current=window.setTimeout(()=>{E.current=null,T()},150)},[H]),m=r.useCallback(()=>{for(const h of F.current)window.clearTimeout(h);F.current=[]},[]),b=r.useCallback(()=>{var g;m(),w("sync",{immediate:!0,force:!0});const h=window.setTimeout(()=>{w("sync",{immediate:!0,force:!0})},60);F.current.push(h),typeof document<"u"&&"fonts"in document&&((g=document.fonts)!=null&&g.ready)&&document.fonts.ready.then(()=>{w("sync",{immediate:!0,force:!0})}).catch(()=>{})},[m,w]);r.useEffect(()=>{let h=null;const g=()=>{h!==null&&cancelAnimationFrame(h),h=requestAnimationFrame(()=>{h=null,w("resize")})};return window.addEventListener("resize",g),()=>{window.removeEventListener("resize",g),h!==null&&cancelAnimationFrame(h)}},[w]),r.useEffect(()=>{const h=()=>{var X;const T=O.current,q=B();if(!T||!q)return;if(!Gt({currentSize:{cols:Math.max(2,T.cols),rows:Math.max(2,T.rows)},containerSize:q})){(X=T.refresh)==null||X.call(T);return}w("sync",{force:!0})},g=()=>{if(document.visibilityState!=="visible"){Q.current=!0;return}Q.current&&(Q.current=!1,h())},L=()=>{Q.current=!0},_=()=>{Q.current&&(Q.current=!1,h())};return document.addEventListener("visibilitychange",g),window.addEventListener("blur",L),window.addEventListener("focus",_),()=>{document.removeEventListener("visibilitychange",g),window.removeEventListener("blur",L),window.removeEventListener("focus",_)}},[B,w]),r.useEffect(()=>()=>{m(),E.current!==null&&window.clearTimeout(E.current),v.current!==null&&cancelAnimationFrame(v.current)},[m]);const M=r.useCallback(h=>{V.current=h},[]),$=r.useCallback(h=>{O.current=h},[]);return{scheduleResize:w,runPostSelectResize:b,clearPostSelectResizeTimers:m,setFitAddon:M,setTerminal:$,lastReportedSize:G,pendingLocalSize:s,suppressLocalResizeUntil:C}}const Qt=1e4,Ae="tmex:terminal-mode-cache";function Jt(n,e){try{const i=sessionStorage.getItem(Ae);return i?JSON.parse(i)[`${n}:${e}`]??null:null}catch{return null}}function Zt(n,e,i){try{const c=sessionStorage.getItem(Ae),p=c?JSON.parse(c):{},R=`${n}:${e}`;i?p[R]=i:delete p[R],sessionStorage.setItem(Ae,JSON.stringify(p))}catch{}}function en(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1}}function tn(n,e){if(!e)return n?{...n,mouseX10:!1,mouseNormal:!1,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgrPixels:!1,mouseUrxvt:!1,altScreen1047:!1,altScreen1049:!1}:null;const i=en();if(!n)return i;const c=n.mouseNormal||n.mouseButton||n.mouseAny;return{...n,mouseX10:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1,mouseNormal:c?n.mouseNormal:i.mouseNormal}}function nn(n){var i;const e=globalThis;e.__tmexE2eXterm=n,e.__tmexE2eTerminal=n,e.__tmexE2eTerminalEngine=Ue,e.__tmexE2eTerminalRenderer=((i=n.getRendererKind)==null?void 0:i.call(n))??null}function rn(n){if(!n)return;const e=globalThis;e.__tmexE2eTerminal!==n&&e.__tmexE2eXterm!==n||(e.__tmexE2eXterm=null,e.__tmexE2eTerminal=null,e.__tmexE2eTerminalEngine=null,e.__tmexE2eTerminalRenderer=null,e.__tmexE2eTerminalSelectionText=null)}const Xe=r.forwardRef(({deviceId:n,paneId:e,theme:i,inputMode:c,deviceConnected:p,isSelectionInvalid:R,onResize:N,onSync:v,children:E},G)=>{const[s,C]=r.useState(null),[F,V]=r.useState(!1),O=K(a=>a.sendInput),S=ee(a=>a.terminalFontId),Q=ee(a=>a.terminalFontSize),f=ee(a=>a.terminalLineHeight),{t:P}=Re(),B=r.useMemo(()=>{switch(i){case"light":return $e;default:return He}},[i]),z=r.useRef(null),H=r.useRef(null),w=r.useRef(null),m=r.useRef(n),b=r.useRef(e),M=r.useRef(n),$=r.useRef(e),h=r.useRef(p&&!R),g=r.useRef(c),L=r.useRef(B),_=r.useRef(!1),T=r.useRef(!1),q=r.useRef(null),U=r.useRef(!1),X=r.useCallback((a,l,I)=>{!(a!=null&&a.exportModeSnapshot)||!l||!I||Zt(l,I,a.exportModeSnapshot())},[]),se=r.useCallback(()=>s,[s]);Xt(z,se),r.useEffect(()=>{m.current=n,b.current=e,T.current=!1},[n,e]),r.useEffect(()=>{h.current=p&&!R},[p,R]),r.useEffect(()=>{g.current=c},[c]),r.useEffect(()=>{L.current=B},[B]);const y=r.useCallback(a=>{if(!a||c!=="direct"||!h.current)return;const l=m.current,I=b.current;!l||!I||O(l,I,a,!1)},[c,O]),{pendingLocalSize:ne,scheduleResize:A,runPostSelectResize:k,setFitAddon:j,setTerminal:D}=Vt({deviceId:n,paneId:e,deviceConnected:p,isSelectionInvalid:R,onResize:N,onSync:v,getContainerRect:()=>{const a=z.current;if(!a)return null;const l=a.getBoundingClientRect();return{width:l.width,height:l.height}}});r.useEffect(()=>{let a=!1,l=null;return(async()=>{if(await nt(S,Q),a)return;const I=await jt({fontFamily:rt(S),fontSize:Q,lineHeight:f,scrollback:Qt,theme:L.current,disableStdin:g.current==="editor"});if(a){I.dispose();return}l=I,H.current&&I.open(H.current),nn(I),C(I)})(),()=>{a=!0,C(null),rn(l),l==null||l.dispose()}},[S,Q,f]),r.useEffect(()=>{!s||!("setTheme"in s)||s.setTheme(B)},[s,B]),r.useEffect(()=>{!s||!("setDisableStdin"in s)||s.setDisableStdin(c==="editor")},[s,c]),r.useEffect(()=>{if(!(s!=null&&s.getCursorViewportRect))return;const a=()=>{var l;return((l=s.getCursorViewportRect)==null?void 0:l.call(s))??null};return it(a),()=>st(a)},[s]),r.useEffect(()=>{!s||c!=="direct"||window.innerWidth<768||"ontouchstart"in window||s.focus()},[s,c]);const re=r.useMemo(()=>s?{onResetTerminal:a=>{m.current===a&&(X(s,M.current,$.current),U.current=!0,s.reset(),_.current=!1,k())},onApplyHistory:(a,l,I)=>{var oe;if(m.current!==a)return;const W=tn(Jt(m.current,b.current),I);W&&((oe=s.restoreModeSnapshot)==null||oe.call(s,W));const Z=I?$t(l):Ye(l);T.current=!0,s.write(Z),U.current=!1,M.current=m.current,$.current=b.current,X(s,m.current,b.current)},onFlushBuffer:(a,l)=>{if(m.current===a){for(const I of l){const W=Fe(I,_.current);_.current=W.endedWithCR,s.write(W.normalized)}T.current&&(s.buffer.active.baseY<=1&&s.scrollToTop(),T.current=!1),M.current=m.current,$.current=b.current,X(s,m.current,b.current)}},onOutput:(a,l,I)=>{if(m.current!==a||b.current!==l)return;const W=Fe(I,_.current);_.current=W.endedWithCR,s.write(W.normalized),T.current&&(s.buffer.active.baseY<=1&&s.scrollToTop(),T.current=!1),M.current=m.current,$.current=b.current,X(s,m.current,b.current)}}:{},[s,X,k]);r.useEffect(()=>{s?q.current!==s&&(_.current=!1,M.current=m.current,$.current=b.current,q.current=s):q.current=null},[s]),r.useEffect(()=>{if(!(!s||!n||!e))return()=>{if(U.current){U.current=!1;return}X(s,M.current,$.current)}},[n,s,e,X]),r.useEffect(()=>{ze(re)},[re]),r.useEffect(()=>()=>{ze({})},[]),r.useEffect(()=>{if(!s){w.current=null,j(null),D(null);return}const a=new Nt;return s.loadAddon(a),w.current=a,j(a),D(s),k(),()=>{try{a.dispose()}finally{w.current=null,j(null),D(null)}}},[s,k,j,D]),r.useEffect(()=>{const a=z.current;if(!a)return;let l=null;const I=new ResizeObserver(()=>{l!==null&&cancelAnimationFrame(l),l=requestAnimationFrame(()=>{l=null,A("resize")})});return I.observe(a),()=>{I.disconnect(),l!==null&&cancelAnimationFrame(l)}},[A]),r.useEffect(()=>{if(!s||!n||!e)return;const a=s.onData(l=>{!p||R||y(l)});return s.attachCustomKeyEventHandler(l=>!p||R||l.type!=="keydown"||c!=="direct"?!0:l.shiftKey&&l.key==="Enter"?(l.preventDefault(),y("\x1B[13;2u"),!1):!0),()=>{a.dispose(),s.attachCustomKeyEventHandler(()=>!0)}},[s,p,R,c,y,n,e]),r.useEffect(()=>{if(!(s!=null&&s.onLinkActivated))return;const a=s.onLinkActivated(l=>{window.open(l,"_blank","noopener,noreferrer")});return()=>a.dispose()},[s]),r.useEffect(()=>{if(!(s!=null&&s.onSelectionChange)){V(!1);return}const a=s.onSelectionChange(l=>{V(!!l)});return()=>{a.dispose(),V(!1)}},[s]);const ve=r.useCallback(()=>{var l;if(!s)return;const a=((l=s.getSelection)==null?void 0:l.call(s))??"";a&&ot(a).then(()=>{he.success(P("terminal.copied"))}).catch(()=>{he.error(P("terminal.copyFailed"))}).finally(()=>{var I;(I=s.clearSelection)==null||I.call(s),s.focus()})},[s,P]),ae=r.useCallback(()=>{var l;if(!s)return;((l=navigator.clipboard)!=null&&l.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(I=>{var W;I&&s.paste(I),(W=s.clearSelection)==null||W.call(s),s.focus()}).catch(()=>{he.error(P("terminal.pasteFailed"))})},[s,P]),ye=r.useCallback(()=>{var a;(a=s==null?void 0:s.clearSelection)==null||a.call(s),s==null||s.focus()},[s]);return r.useImperativeHandle(G,()=>({write:a=>s==null?void 0:s.write(a),reset:()=>{s==null||s.reset(),_.current=!1},scrollToBottom:()=>s==null?void 0:s.scrollToBottom(),resize:(a,l)=>s==null?void 0:s.resize(a,l),getTerminal:()=>s??null,getSize:()=>s?{cols:Math.max(2,s.cols),rows:Math.max(2,s.rows)}:null,runPostSelectResize:()=>k(),scheduleResize:(a,l)=>A(a,l),calculateSizeFromContainer:()=>{var le,ce,J,we,ue,pe,Se,be,Ie,Ce,je,Ne,Ee,t,d,u;const a=z.current,l=s,I=w.current;if(!a||!l)return null;const W=a.getBoundingClientRect();if(W.width===0||W.height===0)return null;const Z=l._core;let oe;if(I)try{const x=I.proposeDimensions();if(x)oe=Math.max(2,x.cols);else{const Y=((we=(J=(ce=(le=Z==null?void 0:Z._renderService)==null?void 0:le.dimensions)==null?void 0:ce.css)==null?void 0:J.cell)==null?void 0:we.width)??9;oe=Math.max(2,Math.floor(W.width/Y))}}catch{const x=((be=(Se=(pe=(ue=Z==null?void 0:Z._renderService)==null?void 0:ue.dimensions)==null?void 0:pe.css)==null?void 0:Se.cell)==null?void 0:be.width)??9;oe=Math.max(2,Math.floor(W.width/x))}else{const x=((Ne=(je=(Ce=(Ie=Z==null?void 0:Z._renderService)==null?void 0:Ie.dimensions)==null?void 0:Ce.css)==null?void 0:je.cell)==null?void 0:Ne.width)??9;oe=Math.max(2,Math.floor(W.width/x))}const ie=((u=(d=(t=(Ee=Z==null?void 0:Z._renderService)==null?void 0:Ee.dimensions)==null?void 0:t.css)==null?void 0:d.cell)==null?void 0:u.height)??17,ge=Math.max(2,Math.floor(W.height/ie));return{cols:oe,rows:ge}},getPendingLocalSize:()=>ne.current}),[s,ne,k,A]),o.jsxs("div",{className:"flex h-full w-full flex-col",style:{backgroundColor:B.background},"data-terminal-engine":Ue,children:[o.jsxs("div",{ref:z,className:"relative min-h-0 w-full flex-1",children:[o.jsx("div",{ref:H,className:"absolute inset-0"}),o.jsx(Wt,{visible:F,canPaste:c==="direct"&&p&&!R,onCopy:ve,onPaste:ae,onDismiss:ye})]}),E]})});Xe.displayName="Terminal";const sn=1200,on=2e3;function fe(n,e){return!n||!e?!1:n.windowId===e.windowId&&n.paneId===e.paneId}function Ke(n,e){const i=n.filter(c=>e-c.at<sn);return i.length===0?null:i.reduce((c,p)=>p.at>c.at?p:c)}function Te(n,e=Date.now()){return!n||e-n.at>on?null:n}function cn(n){const e=n.now??Date.now(),i=Ke(n.recentSelectRequests,e);if(i&&!fe(i,n.activePaneFromEvent)||fe(n.currentRoute,n.activePaneFromEvent)||fe(n.lastHandledActive,n.activePaneFromEvent))return!0;const c=Te(n.pendingUserSelection,e);return!!(c&&!fe(c,n.activePaneFromEvent))}function an(n){const e=n.now??Date.now(),i=Ke(n.recentSelectRequests,e),c=Te(n.pendingUserSelection,e);return!!(c&&!fe(c,n.snapshotActive)||i&&!fe(i,n.snapshotActive))}function ln(n){const e=n.now??Date.now(),i=Te(n.pendingUserSelection,e);return!(i&&fe(i,n.routeTarget)||n.snapshotActive&&fe(n.snapshotActive,n.routeTarget))}const Be=r.memo(function({onActivate:e,disabled:i}){const{data:c}=_e({queryKey:Lt,queryFn:Pt,staleTime:6e4}),p=(c==null?void 0:c.items)??[];return p.length===0?null:o.jsx("div",{className:"terminal-shortcuts-strip","data-testid":"terminal-shortcuts-strip",children:o.jsx(At,{items:p,useIcons:(c==null?void 0:c.useIcons)??!1,onActivate:e,disabled:i,preventFocusSteal:!0,rowTestId:"terminal-shortcuts-row",idPrefix:"terminal-shortcut"})})});function fn(){var Ee;const{t:n}=Re(),{deviceId:e,windowId:i,paneId:c}=Pe(),p=ct(),R=r.useRef(null),N=r.useRef(null),v=r.useRef(null),E=r.useRef(null),G=r.useRef(!1),s=r.useRef(!1),C=r.useRef(null),F=K(t=>t.selectPane),V=K(t=>e?t.snapshots[e]:void 0),O=K(t=>{var d;return e?(d=t.deviceErrors)==null?void 0:d[e]:void 0}),S=K(t=>{var d;return e?((d=t.deviceConnected)==null?void 0:d[e])??!1:!1}),Q=Oe(t=>{var d;return((d=t.settings)==null?void 0:d.siteName)??"tmex"}),f=r.useMemo(()=>Le(c),[c]),P=r.useMemo(()=>e&&f?`${e}:${f}`:null,[e,f]),[B,z]=r.useState(!1),[H,w]=r.useState(""),m=r.useRef(!1),b=!S||!f,[M,$]=r.useState(!1),h=ee(t=>t.inputMode),g=ee(t=>t.theme),L=ee(t=>t.editorSendWithEnter),_=ee(t=>t.setEditorSendWithEnter),T=ee(t=>t.addEditorHistory),q=ee(t=>t.setEditorDraft),U=ee(t=>t.removeEditorDraft),X=ee(t=>P?t.editorDrafts[P]??"":""),se=r.useMemo(()=>at(),[]),y=(Ee=V==null?void 0:V.session)==null?void 0:Ee.windows,ne=g==="light"?$e:He,{data:A}=_e({queryKey:["devices"],queryFn:async()=>{const t=await fetch("/api/devices");if(!t.ok)throw new Error("Failed to fetch devices");return t.json()},throwOnError:!1}),k=r.useMemo(()=>{if(e)return A==null?void 0:A.devices.find(t=>t.id===e)},[e,A==null?void 0:A.devices]),j=r.useMemo(()=>{if(!(!i||!y))return y.find(t=>t.id===i)},[i,y]),D=r.useMemo(()=>{if(!(!f||!j))return j.panes.find(t=>t.id===f)},[f,j]),re=!!y,a=!!(re&&!!i&&!j||re&&!!i&&!!f&&!!j&&!D?n("wsError.checkGateway"):null),l=!!(S&&f&&!a),I=r.useMemo(()=>{if(!j||!D)return null;const t=(k==null?void 0:k.name)??e;return qe({paneIdx:D.index,windowIdx:j.index,paneTitle:D.title,windowName:j.name,windowCustomName:j.customName,deviceName:t})},[k==null?void 0:k.name,e,D,j]),W=r.useMemo(()=>{if(!y||y.length===0)return null;const t=y.find(u=>u.active),d=t==null?void 0:t.panes.find(u=>u.active);return!t||!d?null:{windowId:t.id,paneId:d.id}},[y]),Z=r.useCallback((t,d)=>{!e||!f||K.getState().resizePane(e,f,t,d)},[e,f]),oe=r.useCallback((t,d)=>{!e||!f||K.getState().syncPaneSize(e,f,t,d)},[e,f]),ie=r.useCallback((t,d)=>{const u=E.current,x=(u==null?void 0:u.calculateSizeFromContainer())??(u==null?void 0:u.getSize())??void 0;if(x)return x;if(!t||!d||!y)return;const Y=y.find(me=>me.id===t),te=Y==null?void 0:Y.panes.find(me=>me.id===d);if(!(!te||te.width<=1||te.height<=1))return{cols:te.width,rows:te.height}},[y]);r.useEffect(()=>{const t=()=>{z(window.innerWidth<768||"ontouchstart"in window)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),r.useEffect(()=>{if(!B||!se||s.current)return;s.current=!0;const t=()=>{window.scrollTo(0,1)},d=window.requestAnimationFrame(t),u=window.setTimeout(t,120),x=window.setTimeout(t,420);return()=>{window.cancelAnimationFrame(d),window.clearTimeout(u),window.clearTimeout(x)}},[se,B]),r.useEffect(()=>{e&&(G.current=!1,we.current=null,ue.current=null,C.current=null,le.current=[])},[e]),r.useEffect(()=>{S||(G.current=!1)},[S]),r.useEffect(()=>{if(!e||!S||!i||!y)return;if(y.length===0){p("/devices",{replace:!0});return}const t=y.find(u=>u.id===i);if(!t)return;if(!f){const u=t.panes.find(x=>x.active)??t.panes[0];u&&p(`/devices/${e}/windows/${i}/panes/${xe(u.id)}`,{replace:!0});return}if(!t.panes.find(u=>u.id===f)){const u=t.panes.find(x=>x.active)??t.panes[0];u&&p(`/devices/${e}/windows/${i}/panes/${xe(u.id)}`,{replace:!0});return}},[e,S,y,i,f,p]),r.useEffect(()=>{if(!e||!S||!y||y.length===0||i&&f||G.current)return;const t=y.find(u=>u.active)??y[0],d=t.panes.find(u=>u.active)??t.panes[0];d&&(G.current=!0,p(`/devices/${e}/windows/${t.id}/panes/${xe(d.id)}`,{replace:!0}))},[S,e,p,f,i,y]);const ge=r.useRef(null);r.useEffect(()=>{ge.current=null},[e,f]),r.useEffect(()=>{if(!e||!i||!f||b||!S)return;const t=`${e}:${i}:${f}`;if(ge.current===t)return;ge.current=t;const d=ie(i,f);ce(i,f),F(e,i,f,d)},[S,e,ie,b,f,F,i]),r.useEffect(()=>{if(!e||!S||!i||!f)return;const t={windowId:i,paneId:f};ln({routeTarget:t,snapshotActive:W,pendingUserSelection:C.current})&&(C.current={windowId:t.windowId,paneId:t.paneId,at:Date.now()})},[S,e,f,W,i]);const le=r.useRef([]),ce=r.useCallback((t,d)=>{const u=Date.now(),x=[...le.current.filter(Y=>u-Y.at<2e3),{windowId:t,paneId:d,at:u}];le.current=x.slice(-8)},[]),J=K(t=>e?t.activePaneFromEvent[e]:void 0),we=r.useRef(null);r.useEffect(()=>{if(!e||!S||!i||!f||!J)return;const t=Date.now(),d=Te(C.current,t);if(C.current=d,cn({now:t,pendingUserSelection:d,activePaneFromEvent:J,currentRoute:{windowId:i,paneId:f},recentSelectRequests:le.current,lastHandledActive:we.current}))return;we.current={...J},d&&d.windowId===J.windowId&&d.paneId===J.paneId&&(C.current=null);const u=ie(J.windowId,J.paneId);ce(J.windowId,J.paneId),F(e,J.windowId,J.paneId,u),p(`/devices/${e}/windows/${J.windowId}/panes/${xe(J.paneId)}`,{replace:!0})},[e,S,i,f,J,ce,ie,F,p]);const ue=r.useRef(null);r.useEffect(()=>{if(!e||!S||!y||y.length===0)return;const t=le.current,d=y.find(Me=>Me.active);if(!d)return;const u=d.panes.find(Me=>Me.active);if(!u)return;const x={windowId:d.id,paneId:u.id},Y=Date.now(),te=Te(C.current,Y);if(C.current=te,an({now:Y,pendingUserSelection:te,snapshotActive:x,recentSelectRequests:t})||ue.current&&ue.current.windowId===x.windowId&&ue.current.paneId===x.paneId||(ue.current={...x},te&&te.windowId===x.windowId&&te.paneId===x.paneId&&(C.current=null),i===x.windowId&&f===x.paneId))return;const me=ie(x.windowId,x.paneId);ce(x.windowId,x.paneId),F(e,x.windowId,x.paneId,me),p(`/devices/${e}/windows/${x.windowId}/panes/${xe(x.paneId)}`,{replace:!0})},[e,S,y,i,f,ce,ie,F,p]);const pe=K(t=>e?t.pendingCreateWindowAt[e]:void 0);r.useEffect(()=>{if(!e||!S||!pe)return;const t=5e3,d=Date.now()-pe;if(d>t){K.getState().clearPendingCreateWindow(e);return}if(!W){const Y=window.setTimeout(()=>{K.getState().clearPendingCreateWindow(e)},t-d);return()=>window.clearTimeout(Y)}const u=W;if(i===u.windowId&&f===u.paneId){const Y=window.setTimeout(()=>{K.getState().clearPendingCreateWindow(e)},t-d);return()=>window.clearTimeout(Y)}C.current={windowId:u.windowId,paneId:u.paneId,at:Date.now()};const x=ie(u.windowId,u.paneId);ce(u.windowId,u.paneId),F(e,u.windowId,u.paneId,x),p(`/devices/${e}/windows/${u.windowId}/panes/${xe(u.paneId)}`,{replace:!0}),K.getState().clearPendingCreateWindow(e)},[e,S,pe,W,i,f,ce,ie,F,p]),r.useEffect(()=>{if(!l||!D||b)return;const t=E.current,d=t==null?void 0:t.getTerminal();if(!d)return;const u=Math.max(2,Math.floor(D.width||0)),x=Math.max(2,Math.floor(D.height||0));if(!u||!x)return;const Y=Date.now(),te={cols:u,rows:x},me=(t==null?void 0:t.getPendingLocalSize())??null;Kt({now:Y,remoteSize:te,pendingLocalSize:me})&&(d.cols===u&&d.rows===x||d.resize(u,x))},[l,b,D]),r.useEffect(()=>{const t=window.requestAnimationFrame(()=>{var u;(u=E.current)==null||u.scrollToBottom()}),d=window.setTimeout(()=>{var u;(u=E.current)==null||u.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(t),window.clearTimeout(d)}},[h]),r.useEffect(()=>{O!=null&&O.message&&he.error(O.message)},[O==null?void 0:O.message]),r.useEffect(()=>(document.title=lt(I),()=>{document.title=Q}),[Q,I]),r.useEffect(()=>{const t=()=>{var d;(d=E.current)==null||d.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",t),()=>{window.removeEventListener("tmex:jump-to-latest",t)}},[]),r.useEffect(()=>{const t=d=>{const{deviceId:u,windowId:x,paneId:Y}=d.detail;u===e&&(C.current={windowId:x,paneId:Y,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",t),()=>{window.removeEventListener("tmex:user-initiated-selection",t)}},[e]),r.useEffect(()=>{w(X)},[X]);const Se=r.useCallback(t=>{if(!e||!f||!l)return;K.getState().sendInput(e,f,t,!1)},[l,e,f]),be=r.useCallback(t=>{var d,u;if(t.type==="action"){if(t.action==="toggleKeyboard"){ee.getState().setInputMode(h==="direct"?"editor":"direct");return}if(t.action==="scrollToBottom"){(d=E.current)==null||d.scrollToBottom();return}}if(t.type==="send"){t.payload&&Se(t.payload);return}if(!(!e||!f||!l))switch(t.action){case"paste":{((u=navigator.clipboard)!=null&&u.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(Y=>{Y&&K.getState().paste(e,f,Y)}).catch(()=>he.error(n("terminal.pasteFailed")));break}case"newAgentSession":ut.getState().startDraft(e,f,null),ee.getState().setSidebarCollapsed(!1),ee.getState().setSidebarTab("agent");break}},[l,e,Se,h,f,n]),Ie=r.useCallback(()=>{if(!l){he.error(n("wsError.checkGateway"));return}if(!e||!f||!H.trim())return;$(!0),window.setTimeout(()=>$(!1),150);const t=L?`${H}\r`:H;K.getState().sendInput(e,f,t,!1),T(H),P&&U(P),w("")},[T,l,e,P,L,H,U,f,n]),Ce=r.useCallback(()=>{if(!l){he.error(n("wsError.checkGateway"));return}if(!e||!f||!H.trim())return;$(!0),window.setTimeout(()=>$(!1),150);const t=H.split(/\r?\n/),d=K.getState();for(const u of t)u.trim()&&d.sendInput(e,f,`${u}\r`,!1);T(H),P&&U(P),w("")},[T,l,e,P,H,U,f,n]),je=r.useCallback(()=>{var t;(t=v.current)==null||t.focus({preventScroll:!0})},[]);if(!e)return o.jsx("div",{className:"flex h-full items-center justify-center p-4",children:o.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:n("device.noDevices")})});const Ne=!S&&!O;return o.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[o.jsxs("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${B&&h==="editor"?"pb-1":""}`,children:[o.jsx("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:ne.background},children:S&&f?o.jsx("div",{ref:R,className:"flex-1 h-full min-h-0 w-full","data-virtual-keyboard-avoid":!0,children:o.jsx(Xe,{ref:E,deviceId:e,paneId:f,theme:g,inputMode:h,deviceConnected:S,isSelectionInvalid:a,onResize:Z,onSync:oe,children:h==="direct"&&o.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:ne.background},children:o.jsx(Be,{onActivate:be,disabled:!l})})},`${e}:${f}`)}):o.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:o.jsx("div",{className:"max-w-sm space-y-4",children:S?i?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx(ke,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),o.jsx("h3",{className:"text-lg font-medium",children:n("terminal.connecting")})]}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),o.jsx("h3",{className:"text-lg font-medium",children:n("window.noWindowSelected")}),o.jsx("p",{className:"text-sm text-muted-foreground",children:n("window.selectWindowToStart")})]}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),o.jsx("h3",{className:"text-lg font-medium",children:n("device.disconnected")}),o.jsx("p",{className:"text-sm text-muted-foreground",children:n("device.connectToStart")})]})})})}),Ne&&o.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:o.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-card/90 px-4 py-3 shadow-sm",children:[o.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),o.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:n("terminal.connecting")})]})})]}),h==="editor"&&o.jsxs("div",{ref:N,"data-virtual-keyboard-avoid":!0,className:"editor-mode-input bg-card/85 backdrop-blur-sm",children:[B&&o.jsx(Be,{onActivate:t=>{be(t),t.type==="send"&&je()},disabled:!l}),o.jsx("textarea",{ref:v,"data-testid":"editor-input",className:"min-h-[88px] max-h-[28vh] w-full resize-y rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground shadow-xs outline-none transition-colors focus:border-ring",value:H,onChange:t=>{const d=t.target.value;if(w(d),!!P){if(d){q(P,d);return}U(P)}},placeholder:n("terminal.inputPlaceholder"),onCompositionStart:()=>{m.current=!0},onCompositionEnd:()=>{m.current=!1}}),o.jsx("div",{className:"actions mt-2",children:o.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[o.jsxs("div",{className:"send-with-enter-toggle mr-auto flex items-center gap-2 text-xs text-muted-foreground","data-testid":"editor-send-with-enter-toggle",children:[o.jsx(dt,{size:"sm",checked:L,onCheckedChange:t=>_(!!t)}),o.jsx("span",{children:n("terminal.editorSendWithEnter")})]}),o.jsxs(de,{variant:"outline",size:"sm","data-testid":"editor-clear",onMouseDown:t=>t.preventDefault(),onClick:()=>{var t;w(""),P&&U(P),B&&h==="editor"&&((t=v.current)==null||t.focus({preventScroll:!0}))},title:n("terminal.clear"),children:[o.jsx(ft,{className:"h-4 w-4"}),n("terminal.clear")]}),o.jsxs(de,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onMouseDown:t=>t.preventDefault(),onClick:()=>{var t;Ce(),B&&h==="editor"&&((t=v.current)==null||t.focus({preventScroll:!0}))},disabled:!l||M,children:[M?o.jsx(ke,{className:"h-4 w-4 animate-spin"}):o.jsx(De,{className:"h-4 w-4"}),n("terminal.editorSendLineByLine")]}),o.jsxs(de,{variant:"default",size:"sm","data-testid":"editor-send",onMouseDown:t=>t.preventDefault(),onClick:()=>{var t;Ie(),B&&h==="editor"&&((t=v.current)==null||t.focus({preventScroll:!0}))},disabled:!l||M,children:[M?o.jsx(ke,{className:"h-4 w-4 animate-spin"}):o.jsx(De,{className:"h-4 w-4"}),n("common.send")]})]})})]})]})}function mn(){const{deviceId:n,windowId:e,paneId:i}=Pe(),c=i?Le(i):void 0,p=K(s=>s.snapshots),R=Oe(s=>{var C;return((C=s.settings)==null?void 0:C.siteName)??"tmex"}),N=n?p[n]:void 0,v=r.useMemo(()=>{var s;if(!(!e||!((s=N==null?void 0:N.session)!=null&&s.windows)))return N.session.windows.find(C=>C.id===e)},[e,N]),E=r.useMemo(()=>{if(!(!c||!v))return v.panes.find(s=>s.id===c)},[c,v]),G=r.useMemo(()=>v&&E?qe({paneIdx:E.index,windowIdx:v.index,paneTitle:E.title,windowName:v.name,windowCustomName:v.customName,deviceName:R}):n??"",[v,E,R,n]);return o.jsx(o.Fragment,{children:G})}function hn(){const{t:n}=Re(),{deviceId:e,paneId:i}=Pe(),c=i?Le(i):void 0,p=ee(z=>z.inputMode),R=ee(z=>z.setInputMode),N=K(z=>{var H;return e?((H=z.deviceConnected)==null?void 0:H[e])??!1:!1}),[v,E]=r.useState(!1),[G,s]=r.useState(!1),[C,F]=r.useState(!1),V=!!(c&&N),S=(_e({queryKey:yt(e??"",c??""),queryFn:()=>Rt(e??"",c??""),enabled:!!(e&&c),throwOnError:!1}).data??[]).some(z=>z.enabled),Q=()=>{R(p==="direct"?"editor":"direct")},f=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},P=()=>{E(!0)},B=()=>{window.location.reload()};return o.jsxs(o.Fragment,{children:[o.jsx(de,{variant:"ghost",size:"icon-sm",onClick:P,"aria-label":n("nav.refreshPage"),title:n("nav.refreshPage"),children:o.jsx(Mt,{className:"h-4 w-4"})}),o.jsx(de,{variant:"ghost",size:"icon-sm",onClick:Q,disabled:!V,"data-testid":"terminal-input-mode-toggle","aria-label":n(p==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:n(p==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:p==="direct"?o.jsx(mt,{className:"h-4 w-4"}):o.jsx(Ft,{className:"h-4 w-4"})}),o.jsx(de,{variant:"ghost",size:"icon-sm",onClick:f,disabled:!V,"aria-label":n("nav.jumpToLatest"),title:n("nav.jumpToLatest"),children:o.jsx(kt,{className:"h-4 w-4"})}),o.jsxs(de,{variant:"ghost",size:"icon-sm",className:"relative",onClick:()=>s(!0),disabled:!c,"data-testid":"watch-open-button","aria-label":n("watch.title"),title:n("watch.title"),children:[o.jsx(ht,{className:"h-4 w-4"}),S&&o.jsx("span",{className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-primary","data-testid":"watch-active-indicator"})]}),o.jsx(de,{variant:"ghost",size:"icon-sm",onClick:()=>F(!0),"data-testid":"keyboard-behavior-open-button","aria-label":n("settings.terminal.title"),title:n("settings.terminal.title"),children:o.jsx(zt,{className:"h-4 w-4"})}),o.jsx(Bt,{open:C,onOpenChange:F}),e&&c&&o.jsx(wt,{open:G,onOpenChange:s,deviceId:e,paneId:c}),o.jsx(pt,{open:v,onOpenChange:E,children:o.jsxs(xt,{children:[o.jsxs(vt,{children:[o.jsx(gt,{children:n("nav.refreshPage")}),o.jsx(St,{children:n("nav.refreshPageConfirm")})]}),o.jsxs(bt,{children:[o.jsx(Et,{onClick:()=>E(!1),children:n("common.cancel")}),o.jsx(Tt,{onClick:B,children:n("common.confirm")})]})]})})]})}export{hn as PageActions,mn as PageTitle,fn as default};
|
|
15
|
-
//# sourceMappingURL=DevicePage-C4JS6baR.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{u as D,r as x,a as W,b as ae,c as ie,d as re,e as K,t as ne,j as e,M as _,B as C,P as X,A as oe,f as ce,g as de,h as le,T as Y,i as me,k as he,l as ue,m as pe,n as xe,G as ve,o as v,D as fe,p as ye,E as ge,q as je,s as A,v as we,Z as Ne,w as Ce,x as Q,y as De,S as be,L as Se,z as Ee,C as Me,F as Pe,H as Ke,I as Re,J as Ie,K as f,N as z,O as V,Q as U,R as J,U as j,V as ke,W as Ae}from"./index-CYmVLCAD.js";import{C as M,a as P,b as $e,c as Te,d as Fe}from"./card-Spfb5xRZ.js";function R(s){const o=s.trim();return o||void 0}function qe(s){return s?{name:s.name,type:s.type,host:s.host??"",port:s.port??22,username:s.username??"",sshConfigRef:s.sshConfigRef??"",session:s.session??"tmex",authMode:s.type==="local"?"auto":s.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"root",sshConfigRef:"",session:"tmex",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(s){if(s.type==="local")return{name:s.name.trim(),type:"local",session:R(s.session)??"tmex",authMode:"auto"};const o={name:s.name.trim(),type:"ssh",host:s.host.trim(),port:s.port,username:s.username.trim(),session:R(s.session)??"tmex",authMode:s.authMode};return s.authMode==="configRef"&&(o.sshConfigRef=s.sshConfigRef.trim()),s.authMode==="password"&&(o.password=s.password),s.authMode==="key"&&(o.privateKey=s.privateKey,o.privateKeyPassphrase=s.privateKeyPassphrase||void 0),o}function He(s){if(s.type==="local")return{name:s.name.trim(),session:R(s.session)??"tmex",authMode:"auto"};const o={name:s.name.trim(),host:s.host.trim(),port:s.port,username:s.username.trim(),sshConfigRef:s.authMode==="configRef"?s.sshConfigRef.trim():"",session:R(s.session)??"tmex",authMode:s.authMode};return s.authMode==="password"&&s.password&&(o.password=s.password),s.authMode==="key"&&s.privateKey&&(o.privateKey=s.privateKey,o.privateKeyPassphrase=s.privateKeyPassphrase||void 0),o}function ee(s){return Number.isInteger(s)&&s>=1&&s<=65535}function Oe(s){return s.type!=="ssh"?null:s.host.trim()?ee(s.port)?s.username.trim()?s.authMode==="configRef"&&!s.sshConfigRef.trim()?"validation.sshConfigRequired":null:"validation.usernameRequired":"validation.portRequired":"validation.hostRequired"}async function G(s,o){try{return(await s.json()).error??o}catch{return o}}function Ve(){const{t:s}=D(),[o,m]=x.useState(!1),[t,y]=x.useState(null),[r,d]=x.useState(null),l=W(),u=ae(n=>{var p;return((p=n.settings)==null?void 0:p.language)??"en_US"});x.useEffect(()=>{const n=()=>m(!0);return window.addEventListener("tmex:open-add-device",n),()=>window.removeEventListener("tmex:open-add-device",n)},[]);const{data:c,isLoading:I,isError:w}=ie({queryKey:["devices"],queryFn:async()=>{const n=await fetch("/api/devices");if(!n.ok)throw new Error(s("device.loadFailed"));return n.json()},throwOnError:!1}),b=re(n=>n.hydrateDeviceErrors);x.useEffect(()=>{c!=null&&c.devices&&b(c.devices.map(n=>({deviceId:n.id,lastError:n.lastError??null,lastErrorType:n.lastErrorType??null})))},[c,b]);const S=K({mutationFn:async n=>{if(!(await fetch(`/api/devices/${n}`,{method:"DELETE"})).ok)throw new Error(s("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),v.success(s("common.success"))},onError:n=>{v.error(n instanceof Error?n.message:s("common.error"))}}),E=x.useMemo(()=>[...(c==null?void 0:c.devices)??[]].sort((p,N)=>p.sortOrder-N.sortOrder||p.name.localeCompare(N.name,ne(u),{numeric:!0,sensitivity:"base"})),[c==null?void 0:c.devices,u]);return e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-3 p-3 pb-[calc(1rem+env(safe-area-inset-bottom))] sm:gap-4 sm:p-5","data-testid":"devices-page",children:[I?e.jsx(M,{children:e.jsx(P,{className:"py-16 text-center text-sm text-muted-foreground",children:s("common.loading")})}):w?e.jsx(M,{children:e.jsx(P,{className:"py-16 text-center text-sm text-destructive",children:s("device.loadFailed")})}):E.length===0?e.jsx(M,{children:e.jsxs(P,{className:"space-y-4 py-14 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:e.jsx(_,{className:"h-6 w-6 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-medium",children:s("device.noDevices")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("device.addDevice")})]}),e.jsxs(C,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[e.jsx(X,{className:"h-4 w-4"}),s("device.addDevice")]})]})}):e.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:E.map(n=>e.jsx(Be,{device:n,onEdit:()=>y(n),onDelete:()=>d(n)},n.id))}),o&&e.jsx(Z,{mode:"create",onClose:()=>m(!1)}),t&&e.jsx(Z,{mode:"edit",device:t,onClose:()=>y(null)}),e.jsx(oe,{open:r!==null,onOpenChange:n=>!n&&d(null),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsx(le,{className:"bg-destructive/10",children:e.jsx(Y,{className:"h-5 w-5 text-destructive"})}),e.jsx(me,{children:s("device.deleteConfirm")}),e.jsx(he,{children:s("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),e.jsxs(ue,{children:[e.jsx(pe,{children:s("common.cancel")}),e.jsx(xe,{variant:"destructive",disabled:!r||S.isPending,onClick:()=>{r&&(S.mutate(r.id),d(null))},children:s("common.delete")})]})]})})]})}function Be({device:s,onEdit:o,onDelete:m}){const{t}=D(),y=s.type==="local"?e.jsx(_,{className:"h-4 w-4"}):e.jsx(ve,{className:"h-4 w-4"}),r=s.type==="local"?t("device.typeLocal"):`${s.username??"-"}@${s.host??"-"}:${s.port??22}`,d=K({mutationFn:async()=>{const l=await fetch(`/api/devices/${s.id}/test-connection`,{method:"POST"});let u=null;try{u=await l.json()}catch{u=null}if(!l.ok){const c=u;throw new Error((c==null?void 0:c.error)??t("common.error"))}return u},onSuccess:l=>{v.success(l.message??t("common.success"))},onError:l=>{v.error(l instanceof Error?l.message:t("common.error"))}});return e.jsxs(M,{"data-testid":"device-card","data-device-id":s.id,"data-device-name":s.name,className:"overflow-hidden border-border/50",children:[e.jsxs($e,{className:"space-y-2 pb-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground",children:y}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx(Te,{className:"line-clamp-1 text-sm",title:s.name,children:s.name}),e.jsx(Fe,{className:"line-clamp-1 text-xs",children:r})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1",children:e.jsxs(fe,{children:[e.jsx(ye,{render:e.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${s.id}`,"aria-label":t("common.edit"),title:t("common.edit")}),children:e.jsx(ge,{className:"h-4 w-4"})}),e.jsxs(je,{align:"end",children:[e.jsxs(A,{"data-testid":`device-card-edit-${s.id}`,onClick:o,children:[e.jsx(we,{className:"h-4 w-4"}),t("common.edit")]}),s.type==="ssh"&&e.jsxs(A,{"data-testid":`device-card-test-${s.id}`,onClick:()=>d.mutate(),disabled:d.isPending,children:[e.jsx(Ne,{className:"h-4 w-4"}),t("common.test")]}),e.jsx(Ce,{}),e.jsxs(A,{"data-testid":`device-card-delete-${s.id}`,variant:"destructive",onClick:m,children:[e.jsx(Y,{className:"h-4 w-4"}),t("common.delete")]})]})]})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:s.type==="local"?t("device.typeLocal"):t("device.typeSSHBadge")}),s.session&&e.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:s.session}),e.jsx(De,{deviceId:s.id})]})]}),e.jsxs(P,{className:"pt-0",children:[e.jsx(be,{className:"mb-2"}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(Se,{to:`/devices/${s.id}`,"data-testid":`device-card-connect-${s.id}`,className:Ee({variant:"outline",size:"sm"}),children:t("device.connect")})})]})]})}function Z({mode:s,device:o,onClose:m}){const{t}=D(),y=W(),[r,d]=x.useState(qe(o)),[l,u]=x.useState(!1),[c,I]=x.useState(!1),w=s==="edit",b=r.type==="ssh",S=K({mutationFn:async a=>{const i=await fetch("/api/devices",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.createFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),v.success(t("common.success")),m()},onError:a=>{v.error(a instanceof Error?a.message:t("common.error"))}}),E=K({mutationFn:async a=>{if(!o)throw new Error(t("apiError.deviceNotFound"));const i=await fetch(`/api/devices/${o.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.updateFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),v.success(t("common.success")),m()},onError:a=>{v.error(a instanceof Error?a.message:t("common.error"))}}),n=async a=>{a.preventDefault(),I(!0);const i=Oe(r);if(i){v.error(t(i));return}u(!0);try{s==="create"?await S.mutateAsync(Le(r)):await E.mutateAsync(He(r))}catch{}finally{u(!1)}},p=`${s}-device-name`,N=`${s}-device-type`,$=`${s}-device-host`,T=`${s}-device-port`,F=`${s}-device-username`,q=`${s}-device-session`,L=`${s}-device-auth-mode`,H=`${s}-device-password`,O=`${s}-device-private-key`,B=`${s}-device-private-key-passphrase`,se={local:t("device.typeLocal"),ssh:t("device.typeSSH")},te={password:t("device.authPassword"),key:t("device.authKey"),agent:t("device.authAgent"),configRef:t("device.authConfigRef")},k=a=>e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:a}),h=(a,i,g)=>e.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:a,children:[i,g&&e.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return e.jsx(Me,{open:!0,onOpenChange:a=>!a&&m(),children:e.jsxs(Pe,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[e.jsxs(Ke,{children:[e.jsx(Re,{children:t(w?"device.editDevice":"device.addDevice")}),e.jsx(Ie,{children:t(w?"device.editDeviceDescription":"device.addDeviceDescription")})]}),e.jsxs("form",{onSubmit:n,className:"space-y-4",children:[e.jsxs("div",{className:"-mr-2 max-h-[min(70dvh,720px)] space-y-5 overflow-y-auto pr-2",children:[e.jsxs("section",{className:"space-y-2.5",children:[k(t("device.sectionBasic")),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[h(p,t("device.name"),!0),e.jsx(f,{id:p,"data-testid":"device-name-input",type:"text",value:r.name,onChange:a=>d(i=>({...i,name:a.target.value})),placeholder:t("device.namePlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(N,t("device.type")),e.jsxs(z,{value:r.type,onValueChange:a=>{if(!a)return;const i=a;d(g=>({...g,type:i,authMode:i==="local"?"auto":g.authMode==="auto"?"agent":g.authMode}))},disabled:w,children:[e.jsx(V,{id:N,"data-testid":"device-type-select",className:"w-full",children:e.jsx(U,{placeholder:t("device.type"),children:a=>se[a]??""})}),e.jsxs(J,{children:[e.jsx(j,{value:"local",children:t("device.typeLocal")}),e.jsx(j,{value:"ssh",children:t("device.typeSSH")})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(q,t("device.session")),e.jsx(f,{id:q,"data-testid":"device-session-input",type:"text",value:r.session,onChange:a=>d(i=>({...i,session:a.target.value})),placeholder:t("device.sessionPlaceholder")})]})]})]}),b&&e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2.5",children:[k(t("device.sectionConnection")),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[h($,t("device.host"),!0),e.jsx(f,{id:$,type:"text",value:r.host,onChange:a=>d(i=>({...i,host:a.target.value})),placeholder:t("device.hostPlaceholder"),"aria-invalid":c&&!r.host.trim()})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(T,t("device.port"),!0),e.jsx(f,{id:T,type:"number",value:Number.isNaN(r.port)?"":r.port,onChange:a=>{const i=a.target.value;d(g=>({...g,port:i===""?Number.NaN:Number.parseInt(i,10)}))},min:1,max:65535,"aria-invalid":c&&!ee(r.port)})]}),e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[h(F,t("device.username"),!0),e.jsx(f,{id:F,type:"text",value:r.username,onChange:a=>d(i=>({...i,username:a.target.value})),placeholder:t("device.usernamePlaceholder"),"aria-invalid":c&&!r.username.trim()})]})]})]}),e.jsxs("section",{className:"space-y-2.5",children:[k(t("device.sectionAuth")),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[h(L,t("device.authMode")),e.jsxs(z,{value:r.authMode,onValueChange:a=>{a&&d(i=>({...i,authMode:a}))},children:[e.jsx(V,{id:L,"data-testid":"device-auth-mode-select",className:"w-full",children:e.jsx(U,{placeholder:t("device.authMode"),children:a=>te[a]??""})}),e.jsxs(J,{children:[e.jsx(j,{value:"password",children:t("device.authPassword")}),e.jsx(j,{value:"key",children:t("device.authKey")}),e.jsx(j,{value:"agent",children:t("device.authAgent")}),e.jsx(j,{value:"configRef",children:t("device.authConfigRef")})]})]})]}),r.authMode==="password"&&e.jsxs("div",{className:"space-y-1.5",children:[h(H,t("device.password")),e.jsx(f,{id:H,type:"password",value:r.password,onChange:a=>d(i=>({...i,password:a.target.value}))})]}),r.authMode==="key"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[h(O,t("device.privateKey")),e.jsx(ke,{id:O,value:r.privateKey,onChange:a=>d(i=>({...i,privateKey:a.target.value})),className:"h-28 font-mono text-xs",placeholder:t("device.privateKeyPlaceholder")})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(B,t("device.passphrase")),e.jsx(f,{id:B,type:"password",value:r.privateKeyPassphrase,onChange:a=>d(i=>({...i,privateKeyPassphrase:a.target.value}))})]})]}),r.authMode==="configRef"&&e.jsxs("div",{className:"space-y-1.5",children:[h(`${s}-device-ssh-config-ref`,t("device.authConfigRef"),!0),e.jsx(f,{id:`${s}-device-ssh-config-ref`,"data-testid":"device-ssh-config-ref-input",type:"text",value:r.sshConfigRef,onChange:a=>d(i=>({...i,sshConfigRef:a.target.value})),placeholder:t("device.sshConfigRefPlaceholder"),"aria-invalid":c&&!r.sshConfigRef.trim()}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("device.sshConfigRefHint")})]})]})]})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{type:"button",variant:"outline",onClick:m,children:t("common.cancel")}),e.jsx(C,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:t(l?"common.saving":"common.save")})]})]})]})})}function Ue(){const{t:s}=D();return e.jsx(e.Fragment,{children:s("sidebar.manageDevices")})}function Je(){const{t:s}=D(),o=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return e.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:o,"aria-label":s("sidebar.addDevice"),title:s("sidebar.addDevice"),children:e.jsx(X,{className:"h-4 w-4"})})}export{Je as PageActions,Ue as PageTitle,Ve as default};
|
|
2
|
-
//# sourceMappingURL=DevicesPage-p0CfWP1T.js.map
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import{_ as U,u as F,j as e,L as es,M as Ne,z as ss,r as j,c as K,B as w,P as de,a as M,e as k,o as y,aV as Ve,aW as we,aX as ts,ao as A,v as ke,T as O,A as z,f as V,g as H,h as as,i as W,k as J,l as G,m as Z,n as X,aY as ns,C as Y,F as ee,H as se,I as te,J as me,N as ae,O as ne,Q as ie,R as re,U as Q,K as P,W as he,an as D,G as is,aZ as rs,x as He,a5 as ls,b as ue,t as Ce,ap as os,a_ as cs,a$ as ds,a6 as Be,b0 as ms,b1 as hs,b2 as us,b3 as gs,b4 as xs,b5 as ps,X as fs,b6 as js,b7 as _e,b8 as ys}from"./index-CYmVLCAD.js";import{C as $,b as B,c as _,d as We,a as q}from"./card-Spfb5xRZ.js";import{R as Je,T as vs,b as ws,d as bs}from"./terminal-settings-panel-CYV9svzz.js";import{M as Ns}from"./markdown-preview-DXv9GzaA.js";/**
|
|
2
|
-
* @license lucide-react v0.564.0 - ISC
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the ISC license.
|
|
5
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const ks=[["path",{d:"M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z",key:"lc1i9w"}],["path",{d:"m7 16.5-4.74-2.85",key:"1o9zyk"}],["path",{d:"m7 16.5 5-3",key:"va8pkn"}],["path",{d:"M7 16.5v5.17",key:"jnp8gn"}],["path",{d:"M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z",key:"8zsnat"}],["path",{d:"m17 16.5-5-3",key:"8arw3v"}],["path",{d:"m17 16.5 4.74-2.85",key:"8rfmw"}],["path",{d:"M17 16.5v5.17",key:"k6z78m"}],["path",{d:"M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z",key:"1xygjf"}],["path",{d:"M12 8 7.26 5.15",key:"1vbdud"}],["path",{d:"m12 8 4.74-2.85",key:"3rx089"}],["path",{d:"M12 13.5V8",key:"1io7kd"}]],Cs=U("boxes",ks);/**
|
|
7
|
-
* @license lucide-react v0.564.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const Ss=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],I=U("save",Ss);/**
|
|
12
|
-
* @license lucide-react v0.564.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const Es=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],Fs=U("server",Es);/**
|
|
17
|
-
* @license lucide-react v0.564.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const Ps=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],Re=U("shield",Ps);/**
|
|
22
|
-
* @license lucide-react v0.564.0 - ISC
|
|
23
|
-
*
|
|
24
|
-
* This source code is licensed under the ISC license.
|
|
25
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const Ts=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],Ms=U("users",Ts);function As(){const{t:s}=F();return e.jsxs($,{className:"border-0 ring-0",children:[e.jsxs(B,{children:[e.jsx(_,{children:s("settings.deviceManagement.title")}),e.jsx(We,{children:s("settings.deviceManagement.description")})]}),e.jsx(q,{children:e.jsxs(es,{to:"/devices","data-testid":"settings-device-management-link",className:ss({variant:"secondary"}),children:[e.jsx(Ne,{className:"h-4 w-4"}),s("settings.deviceManagement.openButton")]})})]})}function ce({type:s,className:a}){return s==="ssh"?e.jsx(is,{className:a}):e.jsx(Ne,{className:a})}function Ks(){var d,v;const{t:s}=F(),[a,t]=j.useState(!1),[n,r]=j.useState(void 0),m=K({queryKey:["files","roots"],queryFn:rs}),p=K({queryKey:["devices"],queryFn:async()=>{const l=await fetch("/api/devices");if(!l.ok)throw new Error(`HTTP ${l.status}`);return await l.json()},throwOnError:!1}),x=((d=m.data)==null?void 0:d.roots)??[],i=((v=p.data)==null?void 0:v.devices)??[],c=()=>{r(void 0),t(!0)},f=l=>{r(l),t(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs($,{className:"border-0 ring-0","data-testid":"settings-files-section",children:[e.jsxs(B,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(_,{children:s("settings.files.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("settings.files.description")})]}),e.jsxs(w,{variant:"secondary","data-testid":"settings-files-root-add",onClick:c,children:[e.jsx(de,{className:"h-4 w-4"}),s("settings.files.addRoot")]})]}),e.jsxs(q,{className:"space-y-3",children:[m.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.loading")}),!m.isLoading&&x.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground","data-testid":"settings-files-empty",children:s("settings.files.empty")}),x.map(l=>e.jsx($s,{root:l,onEdit:f},l.id))]})]}),e.jsx(qs,{open:a,onOpenChange:t,root:n,devices:i})]})}function $s({root:s,onEdit:a}){const{t}=F(),n=M(),[r,m]=j.useState(!1),p=k({mutationFn:({id:i,enabled:c})=>Ve(i,{enabled:c}),onSuccess:async()=>{await n.invalidateQueries({queryKey:["files"]})},onError:()=>{y.error(t("settings.files.toggleFailed"))}}),x=k({mutationFn:i=>ts(i),onSuccess:async()=>{await n.invalidateQueries({queryKey:["files"]}),y.success(t("common.success"))},onError:i=>{const c=i instanceof we?i.message:t("settings.files.deleteFailed");y.error(c)}});return e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border p-3","data-testid":`settings-files-root-${s.id}`,children:[e.jsx(A,{checked:s.enabled,disabled:p.isPending,onCheckedChange:i=>p.mutate({id:s.id,enabled:!!i}),"data-testid":`settings-files-root-enabled-${s.id}`}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(ce,{type:s.deviceType,className:"h-3.5 w-3.5 shrink-0"}),s.deviceName===null?e.jsx("span",{className:"text-destructive",children:t("settings.files.missing")}):e.jsx("span",{className:"truncate",children:s.deviceName})]}),e.jsx("div",{className:"truncate font-mono text-xs",children:s.path}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:s.name})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(w,{variant:"ghost",size:"icon-sm",title:t("common.edit"),"data-testid":`settings-files-root-edit-${s.id}`,onClick:()=>a(s),children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx(w,{variant:"ghost",size:"icon-sm",title:t("common.delete"),"data-testid":`settings-files-root-delete-${s.id}`,onClick:()=>m(!0),disabled:x.isPending,children:e.jsx(O,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(z,{open:r,onOpenChange:m,children:e.jsxs(V,{children:[e.jsxs(H,{children:[e.jsx(as,{className:"bg-destructive/10",children:e.jsx(O,{className:"h-5 w-5 text-destructive"})}),e.jsx(W,{children:t("settings.files.deleteTitle")}),e.jsx(J,{children:t("settings.files.deleteDesc",{path:s.path})})]}),e.jsxs(G,{children:[e.jsx(Z,{children:t("common.cancel")}),e.jsx(X,{variant:"destructive","data-testid":`settings-files-root-delete-confirm-${s.id}`,onClick:()=>{x.mutate(s.id),m(!1)},children:t("common.delete")})]})]})})]})}const Ie="h-9 w-full";function qs({open:s,onOpenChange:a,root:t,devices:n}){const{t:r}=F(),m=M(),p=!!t,[x,i]=j.useState(""),[c,f]=j.useState(""),[d,v]=j.useState(!0);j.useEffect(()=>{s&&(i((t==null?void 0:t.deviceId)??""),f((t==null?void 0:t.path)??""),v((t==null?void 0:t.enabled)??!0))},[s,t]);const l=k({mutationFn:()=>{const N={deviceId:x,path:c.trim(),enabled:d};return ns(N)},onSuccess:async()=>{await m.invalidateQueries({queryKey:["files"]}),y.success(r("common.success")),a(!1)},onError:N=>{const L=N instanceof we?N.message:r("settings.files.addFailed");y.error(L)}}),h=k({mutationFn:()=>{if(!t)throw new Error(r("settings.files.updateFailed"));const N={path:c.trim(),enabled:d};return Ve(t.id,N)},onSuccess:async()=>{await m.invalidateQueries({queryKey:["files"]}),y.success(r("common.success")),a(!1)},onError:N=>{const L=N instanceof we?N.message:r("settings.files.updateFailed");y.error(L)}}),b=l.isPending||h.isPending,E=c.trim().startsWith("/")&&(p||x.length>0),g=()=>{!E||b||(p?h.mutate():l.mutate())},C=n.find(N=>N.id===x);return e.jsx(Y,{open:s,onOpenChange:a,children:e.jsxs(ee,{className:"sm:max-w-lg","data-testid":p?`settings-files-edit-modal-${t==null?void 0:t.id}`:"settings-files-add-modal",children:[e.jsxs(se,{children:[e.jsx(te,{children:r(p?"settings.files.modalEditTitle":"settings.files.modalAddTitle")}),e.jsx(me,{children:r("settings.files.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"files-form-device",children:r("settings.files.device")}),p?e.jsxs("div",{className:"flex h-9 items-center gap-1.5 rounded-lg border border-input bg-muted/30 px-2.5 text-sm",children:[e.jsx(ce,{type:(t==null?void 0:t.deviceType)??null,className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:(t==null?void 0:t.deviceName)??r("settings.files.missing")})]}):e.jsxs(ae,{value:x,onValueChange:N=>{N&&i(N)},children:[e.jsx(ne,{id:"files-form-device","data-testid":"settings-files-device-select",className:Ie,disabled:n.length===0,children:e.jsx(ie,{children:C?e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ce,{type:C.type,className:"h-4 w-4 shrink-0"}),C.name]}):e.jsx("span",{className:"text-muted-foreground",children:r("settings.files.devicePlaceholder")})})}),e.jsx(re,{children:n.map(N=>e.jsxs(Q,{value:N.id,children:[e.jsx(ce,{type:N.type,className:"h-4 w-4 shrink-0"}),N.name]},N.id))})]}),!p&&n.length===0&&e.jsx("p",{className:"text-xs text-destructive",children:r("settings.files.noDevices")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"files-form-path",children:r("settings.files.path")}),e.jsx(P,{id:"files-form-path","data-testid":"settings-files-path-input",value:c,onChange:N=>f(N.target.value),placeholder:r("settings.files.pathPlaceholder"),className:`${Ie} font-mono`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("settings.files.pathHint")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{checked:d,onCheckedChange:N=>v(!!N),"data-testid":"settings-files-enabled-switch"}),e.jsx("label",{className:"text-sm font-medium",htmlFor:"settings-files-enabled-switch",children:r("settings.files.enabled")})]})]}),e.jsxs(he,{children:[e.jsx(w,{variant:"outline",onClick:()=>a(!1),disabled:b,children:r("common.cancel")}),e.jsxs(w,{variant:"secondary","data-testid":"settings-files-form-submit",onClick:g,disabled:!E||b,children:[b?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(I,{className:"h-4 w-4"}),r("common.save")]})]})]})})}async function R(s,a){try{return(await s.json()).error??a}catch{return a}}const Ds=["openai-chat","openai-responses"],le="h-9 w-full";function Bs({open:s,onOpenChange:a,provider:t}){const{t:n}=F(),r=M(),m=!!t,[p,x]=j.useState(""),[i,c]=j.useState(""),[f,d]=j.useState("openai-chat"),[v,l]=j.useState("");j.useEffect(()=>{s&&(x((t==null?void 0:t.name)??""),c((t==null?void 0:t.baseUrl)??""),d((t==null?void 0:t.protocol)??"openai-chat"),l(""))},[s,t]);const h=k({mutationFn:async()=>{const g={name:p.trim(),protocol:f,baseUrl:i.trim(),apiKey:v.trim(),enabled:!0},C=await fetch("/api/llm/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!C.ok)throw new Error(await R(C,n("settings.llm.createFailed")));return await C.json()},onSuccess:async g=>{await r.invalidateQueries({queryKey:["llm-providers"]}),g.modelsError?y.warning(n("settings.llm.modelsFetchFailed",{error:g.modelsError})):y.success(n("common.success")),a(!1)},onError:g=>{y.error(g instanceof Error?g.message:n("common.error"))}}),b=k({mutationFn:async()=>{if(!t)throw new Error(n("settings.llm.updateFailed"));const g={name:p.trim(),baseUrl:i.trim(),protocol:f};v.trim()&&(g.apiKey=v.trim());const C=await fetch(`/api/llm/providers/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!C.ok)throw new Error(await R(C,n("settings.llm.updateFailed")));return await C.json()},onSuccess:async g=>{await r.invalidateQueries({queryKey:["llm-providers"]}),g.modelsError?y.warning(n("settings.llm.modelsFetchFailed",{error:g.modelsError})):y.success(n("common.success")),a(!1)},onError:g=>{y.error(g instanceof Error?g.message:n("common.error"))}}),S=h.isPending||b.isPending,o=p.trim().length>0&&i.trim().length>0&&(m||v.trim().length>0),E=()=>{!o||S||(m?b.mutate():h.mutate())};return e.jsx(Y,{open:s,onOpenChange:a,children:e.jsxs(ee,{className:"sm:max-w-lg","data-testid":m?`llm-provider-edit-modal-${t==null?void 0:t.id}`:"llm-provider-add-modal",children:[e.jsxs(se,{children:[e.jsx(te,{children:n(m?"settings.llm.editProvider":"settings.llm.addProvider")}),e.jsx(me,{children:n("settings.llm.formHint")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-name",children:n("settings.llm.name")}),e.jsx(P,{id:"llm-form-name","data-testid":"llm-provider-name-input",value:p,onChange:g=>x(g.target.value),placeholder:n("settings.llm.namePlaceholder"),className:le})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-baseurl",children:n("settings.llm.baseUrl")}),e.jsx(P,{id:"llm-form-baseurl","data-testid":"llm-provider-baseurl-input",value:i,onChange:g=>c(g.target.value),placeholder:n("settings.llm.baseUrlPlaceholder"),className:le}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.llm.baseUrlHint")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-protocol",children:n("settings.llm.protocol")}),e.jsxs(ae,{value:f,onValueChange:g=>{g&&d(g)},children:[e.jsx(ne,{id:"llm-form-protocol","data-testid":"llm-provider-protocol-select",className:le,children:e.jsx(ie,{})}),e.jsx(re,{children:Ds.map(g=>e.jsx(Q,{value:g,children:g},g))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-apikey",children:n("settings.llm.apiKey")}),e.jsx(P,{id:"llm-form-apikey","data-testid":"llm-provider-apikey-input","data-key-set":t!=null&&t.hasApiKey?"true":"false",type:"password",value:v,onChange:g=>l(g.target.value),placeholder:t!=null&&t.hasApiKey?n("settings.llm.apiKeySetPlaceholder"):n("settings.llm.apiKeyPlaceholder"),className:le})]})]}),e.jsxs(he,{children:[e.jsx(w,{variant:"outline",onClick:()=>a(!1),disabled:S,children:n("common.cancel")}),e.jsxs(w,{variant:"secondary","data-testid":"llm-provider-form-submit",onClick:E,disabled:!o||S,children:[S?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(I,{className:"h-4 w-4"}),n("common.save")]})]})]})})}function _s({models:s,onChange:a}){const{t}=F(),[n,r]=j.useState(""),m=(i,c)=>{a(s.map(f=>f.id===i?{...f,enabled:c}:f))},p=i=>{a(s.filter(c=>c.id!==i))},x=()=>{const i=n.trim();if(i){if(s.some(c=>c.id===i)){r("");return}a([...s,{id:i,source:"manual",enabled:!0}]),r("")}};return e.jsxs("div",{className:"space-y-3","data-testid":"llm-provider-models",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{value:n,onChange:i=>r(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),x())},placeholder:t("settings.llm.addModelPlaceholder"),className:"h-9","data-testid":"llm-provider-add-model-input"}),e.jsxs(w,{type:"button",variant:"outline",size:"lg",onClick:x,disabled:!n.trim(),"data-testid":"llm-provider-add-model",children:[e.jsx(de,{className:"h-4 w-4"}),t("common.add")]})]}),s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.llm.modelsNotFetched")}):e.jsx("ul",{className:"max-h-56 space-y-1 overflow-y-auto rounded-lg border border-border bg-background p-2",children:s.map(i=>e.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-md px-2 py-1.5","data-testid":`llm-provider-model-${i.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(A,{checked:i.enabled,onCheckedChange:c=>m(i.id,!!c),"data-testid":`llm-provider-model-toggle-${i.id}`}),e.jsx("span",{className:"truncate font-mono text-xs",children:i.id}),i.source==="manual"&&e.jsx(He,{variant:"secondary",children:t("settings.llm.modelManual")})]}),i.source==="manual"&&e.jsx(w,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>p(i.id),"data-testid":`llm-provider-model-remove-${i.id}`,children:e.jsx(ls,{className:"h-4 w-4"})})]},i.id))})]})}function Rs(s){return s.modelDetails.map(a=>({id:a.id,source:a.source,enabled:a.enabled}))}function Is({open:s,onOpenChange:a,provider:t}){const{t:n}=F(),r=M(),[m,p]=j.useState([]);j.useEffect(()=>{s&&p(Rs(t))},[s,t]);const x=k({mutationFn:async()=>{const i=m.filter(v=>v.source==="manual").map(v=>v.id),c=m.filter(v=>!v.enabled).map(v=>v.id),f={manualModels:i,disabledModels:c},d=await fetch(`/api/llm/providers/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)});if(!d.ok)throw new Error(await R(d,n("settings.llm.updateFailed")));return await d.json()},onSuccess:async i=>{await r.invalidateQueries({queryKey:["llm-providers"]}),i.modelsError?y.warning(n("settings.llm.modelsFetchFailed",{error:i.modelsError})):y.success(n("common.success")),a(!1)},onError:i=>{y.error(i instanceof Error?i.message:n("common.error"))}});return e.jsx(Y,{open:s,onOpenChange:a,children:e.jsxs(ee,{className:"sm:max-w-lg","data-testid":`llm-provider-models-modal-${t.id}`,children:[e.jsxs(se,{children:[e.jsx(te,{children:n("settings.llm.modelsTitle",{name:t.name})}),e.jsx(me,{children:n("settings.llm.modelsHint")})]}),e.jsx(_s,{models:m,onChange:p}),e.jsxs(he,{children:[e.jsx(w,{variant:"outline",onClick:()=>a(!1),disabled:x.isPending,children:n("common.cancel")}),e.jsxs(w,{variant:"secondary","data-testid":`llm-provider-models-save-${t.id}`,onClick:()=>x.mutate(),disabled:x.isPending,children:[x.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(I,{className:"h-4 w-4"}),n("common.save")]})]})]})})}function Ls(s){try{const a=new URL(s);return`${a.protocol}//${a.host}${a.pathname==="/"?"":a.pathname}`}catch{return s}}function Os({provider:s,onEdit:a}){const{t}=F(),n=M(),[r,m]=j.useState(!1),[p,x]=j.useState(!1),i=k({mutationFn:async d=>{const v=await fetch(`/api/llm/providers/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:d})});if(!v.ok)throw new Error(await R(v,t("settings.llm.updateFailed")))},onSuccess:async()=>{await n.invalidateQueries({queryKey:["llm-providers"]})},onError:d=>{y.error(d instanceof Error?d.message:t("common.error"))}}),c=k({mutationFn:async()=>{const d=await fetch(`/api/llm/providers/${s.id}/refresh-models`,{method:"POST"});if(!d.ok)throw new Error(await R(d,t("settings.llm.refreshModelsFailed")))},onSuccess:async()=>{await n.invalidateQueries({queryKey:["llm-providers"]}),y.success(t("common.success"))},onError:d=>{y.error(d instanceof Error?d.message:t("common.error"))}}),f=k({mutationFn:async()=>{const d=await fetch(`/api/llm/providers/${s.id}`,{method:"DELETE"});if(!d.ok)throw new Error(await R(d,t("settings.llm.deleteFailed")))},onSuccess:async()=>{await n.invalidateQueries({queryKey:["llm-providers"]}),await n.invalidateQueries({queryKey:["llm-settings"]}),y.success(t("common.success"))},onError:d=>{y.error(d instanceof Error?d.message:t("common.error"))}});return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-3 sm:flex-row sm:items-center sm:justify-between","data-testid":`llm-provider-row-${s.id}`,"data-provider-name":s.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(A,{checked:s.enabled,disabled:i.isPending,onCheckedChange:d=>i.mutate(!!d),"data-testid":`llm-provider-enabled-${s.id}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium",children:s.name}),e.jsx(He,{variant:"outline",children:s.protocol})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"truncate font-mono",children:Ls(s.baseUrl)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"whitespace-nowrap",children:t("settings.llm.modelsCount",{total:s.models.length})})]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(w,{variant:"ghost",size:"icon-sm",title:t("settings.llm.refreshModels"),"data-testid":`llm-provider-refresh-models-${s.id}`,onClick:()=>c.mutate(),disabled:c.isPending,children:c.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(Je,{className:"h-4 w-4"})}),e.jsx(w,{variant:"ghost",size:"icon-sm",title:t("settings.llm.models"),"data-testid":`llm-provider-models-${s.id}`,onClick:()=>x(!0),children:e.jsx(Cs,{className:"h-4 w-4"})}),e.jsx(w,{variant:"ghost",size:"icon-sm",title:t("common.edit"),"data-testid":`llm-provider-edit-${s.id}`,onClick:()=>a(s),children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx(w,{variant:"ghost",size:"icon-sm",title:t("common.delete"),"data-testid":`llm-provider-delete-${s.id}`,onClick:()=>m(!0),disabled:f.isPending,children:e.jsx(O,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(Is,{open:p,onOpenChange:x,provider:s}),e.jsx(z,{open:r,onOpenChange:m,children:e.jsxs(V,{children:[e.jsxs(H,{children:[e.jsx(W,{children:t("settings.llm.deleteProvider")}),e.jsx(J,{children:t("settings.llm.deleteConfirm",{name:s.name})})]}),e.jsxs(G,{children:[e.jsx(Z,{onClick:()=>m(!1),children:t("common.cancel")}),e.jsx(X,{variant:"destructive","data-testid":`llm-provider-delete-confirm-${s.id}`,onClick:()=>{f.mutate(),m(!1)},children:t("common.confirm")})]})]})})]})}function Qs(){var c;const{t:s}=F(),[a,t]=j.useState(!1),[n,r]=j.useState(void 0),m=K({queryKey:["llm-providers"],queryFn:async()=>{const f=await fetch("/api/llm/providers");if(!f.ok)throw new Error(await R(f,s("settings.llm.loadFailed")));return await f.json()}}),p=((c=m.data)==null?void 0:c.providers)??[],x=()=>{r(void 0),t(!0)},i=f=>{r(f),t(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs($,{className:"border-0 ring-0","data-testid":"llm-providers-section",children:[e.jsxs(B,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsx(_,{children:s("settings.llm.title")}),e.jsxs(w,{variant:"secondary","data-testid":"llm-provider-add",onClick:x,children:[e.jsx(de,{className:"h-4 w-4"}),s("settings.llm.addProvider")]})]}),e.jsxs(q,{className:"space-y-3",children:[m.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.loading")}),!m.isLoading&&p.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground","data-testid":"llm-providers-empty",children:s("settings.llm.empty")}),p.map(f=>e.jsx(Os,{provider:f,onEdit:i},f.id))]})]}),e.jsx(Bs,{open:a,onOpenChange:t,provider:n}),e.jsx(Us,{providers:p})]})}const xe="__none__";function Us({providers:s}){var b,S;const{t:a}=F(),t=M(),[n,r]=j.useState(null),[m,p]=j.useState(""),x=K({queryKey:["llm-settings"],queryFn:async()=>{const o=await fetch("/api/llm/settings");if(!o.ok)throw new Error(await R(o,a("settings.llm.settingsLoadFailed")));return await o.json()}}),i=((b=x.data)==null?void 0:b.settings.defaultProviderId)??null,c=((S=x.data)==null?void 0:S.settings.defaultModelId)??"",f=!!x.data;j.useEffect(()=>{f&&(r(i),p(c))},[f,i,c]);const d=k({mutationFn:async()=>{const o={defaultProviderId:n,defaultModelId:m.trim()||null},E=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!E.ok)throw new Error(await R(E,a("settings.llm.settingsSaveFailed")))},onSuccess:async()=>{await t.invalidateQueries({queryKey:["llm-settings"]}),y.success(a("common.success"))},onError:o=>{y.error(o instanceof Error?o.message:a("common.error"))}}),v=s.filter(o=>o.enabled),l=s.find(o=>o.id===n),h=(l==null?void 0:l.models)??[];return e.jsxs($,{className:"border-0 ring-0","data-testid":"llm-defaults-section",children:[e.jsx(B,{children:e.jsx(_,{children:a("settings.llm.defaults")})}),e.jsxs(q,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-default-provider-select",children:a("settings.llm.defaultProvider")}),e.jsxs(ae,{value:n??xe,onValueChange:o=>{o&&r(o===xe?null:o)},children:[e.jsx(ne,{id:"llm-default-provider-select","data-testid":"llm-default-provider-select",className:"h-9 w-full",children:e.jsx(ie,{children:(l==null?void 0:l.name)??a("settings.llm.defaultProviderNone")})}),e.jsxs(re,{children:[e.jsx(Q,{value:xe,children:a("settings.llm.defaultProviderNone")}),v.map(o=>e.jsx(Q,{value:o.id,children:o.name},o.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-default-model-input",children:a("settings.llm.defaultModel")}),e.jsx(P,{id:"llm-default-model-input","data-testid":"llm-default-model-input",list:"llm-default-model-options",value:m,onChange:o=>p(o.target.value),placeholder:a("settings.llm.defaultModelPlaceholder"),className:"h-9"}),e.jsx("datalist",{id:"llm-default-model-options",children:h.map(o=>e.jsx("option",{value:o},o))})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{variant:"secondary","data-testid":"llm-defaults-save",onClick:()=>d.mutate(),disabled:d.isPending||x.isLoading,className:"w-full sm:w-auto",children:[d.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(I,{className:"h-4 w-4"}),a("settings.llm.saveDefaults")]})})]})]})}const zs=["none","tavily","brave"];async function pe(s,a){try{return(await s.json()).error??a}catch{return a}}function Vs(){var S;const{t:s}=F(),a=M(),[t,n]=j.useState("none"),[r,m]=j.useState(""),[p,x]=j.useState(""),[i,c]=j.useState(null),f=K({queryKey:["llm-settings"],queryFn:async()=>{const o=await fetch("/api/llm/settings");if(!o.ok)throw new Error(await pe(o,s("settings.search.loadFailed")));return await o.json()}}),d=(S=f.data)==null?void 0:S.settings,v=d==null?void 0:d.searchProvider;j.useEffect(()=>{v&&n(v)},[v]);const l=k({mutationFn:async()=>{const o={searchProvider:t};r.trim()&&(o.tavilyApiKey=r.trim()),p.trim()&&(o.braveApiKey=p.trim());const E=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!E.ok)throw new Error(await pe(E,s("settings.search.saveFailed")))},onSuccess:async()=>{m(""),x(""),await a.invalidateQueries({queryKey:["llm-settings"]}),y.success(s("common.success"))},onError:o=>{y.error(o instanceof Error?o.message:s("common.error"))}}),h=k({mutationFn:async o=>{const E={[o]:""},g=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(E)});if(!g.ok)throw new Error(await pe(g,s("settings.search.saveFailed")))},onSuccess:async()=>{await a.invalidateQueries({queryKey:["llm-settings"]}),y.success(s("common.success"))},onError:o=>{y.error(o instanceof Error?o.message:s("common.error"))}}),b=o=>o==="none"?s("settings.search.providerNone"):o==="tavily"?"Tavily":"Brave";return e.jsxs($,{className:"border-0 ring-0","data-testid":"settings-search-section",children:[e.jsx(B,{children:e.jsx(_,{children:s("settings.search.title")})}),e.jsxs(q,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"search-provider-select",children:s("settings.search.provider")}),e.jsxs(ae,{value:t,onValueChange:o=>{o&&n(o)},children:[e.jsx(ne,{id:"search-provider-select","data-testid":"settings-search-provider-select",className:"w-full min-h-10",children:e.jsx(ie,{children:b(t)})}),e.jsx(re,{children:zs.map(o=>e.jsx(Q,{value:o,children:b(o)},o))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settings.search.responsesApiHint")})]}),e.jsx(Le,{id:"search-tavily-key-input",testId:"settings-search-tavily",label:s("settings.search.tavilyApiKey"),value:r,hasKey:(d==null?void 0:d.hasTavilyApiKey)??!1,onChange:m,onClear:()=>c("tavilyApiKey"),clearing:h.isPending&&h.variables==="tavilyApiKey"}),e.jsx(Le,{id:"search-brave-key-input",testId:"settings-search-brave",label:s("settings.search.braveApiKey"),value:p,hasKey:(d==null?void 0:d.hasBraveApiKey)??!1,onChange:x,onClear:()=>c("braveApiKey"),clearing:h.isPending&&h.variables==="braveApiKey"}),e.jsx(z,{open:i!==null,onOpenChange:o=>{o||c(null)},children:e.jsxs(V,{children:[e.jsxs(H,{children:[e.jsx(W,{children:s("settings.search.clearKey")}),e.jsx(J,{children:s("settings.search.clearKeyConfirm")})]}),e.jsxs(G,{children:[e.jsx(Z,{children:s("common.cancel")}),e.jsx(X,{"data-testid":"settings-search-clear-confirm",onClick:()=>{i&&h.mutate(i),c(null)},children:s("settings.search.clearKey")})]})]})}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{variant:"secondary","data-testid":"settings-search-save",onClick:()=>l.mutate(),disabled:l.isPending||f.isLoading,className:"w-full sm:w-auto",children:[l.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(I,{className:"h-4 w-4"}),s("common.save")]})})]})]})}function Le({id:s,testId:a,label:t,value:n,hasKey:r,onChange:m,onClear:p,clearing:x}){const{t:i}=F();return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:s,children:t}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{id:s,"data-testid":`${a}-input`,"data-key-set":r?"true":"false",type:"password",value:n,onChange:c=>m(c.target.value),placeholder:i(r?"settings.search.keySetPlaceholder":"settings.search.keyPlaceholder"),className:"min-h-10"}),r&&e.jsxs(w,{variant:"outline",size:"sm","data-testid":`${a}-clear`,onClick:p,disabled:x,className:"shrink-0",children:[e.jsx(O,{className:"h-4 w-4"}),i("settings.search.clearKey")]})]})]})}const Oe="min-h-10";async function Qe(s,a){try{return(await s.json()).error??a}catch{return a}}function Hs({open:s,onOpenChange:a,bot:t}){const{t:n}=F(),r=M(),m=!!t,[p,x]=j.useState(""),[i,c]=j.useState(""),[f,d]=j.useState(!0);j.useEffect(()=>{s&&(x((t==null?void 0:t.name)??""),c(""),d((t==null?void 0:t.allowAuthRequests)??!0))},[s,t]);const v=k({mutationFn:async()=>{const o=await fetch("/api/settings/telegram/bots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:p.trim(),token:i.trim(),enabled:!0,allowAuthRequests:f})});if(!o.ok)throw new Error(await Qe(o,n("telegram.createFailed")))},onSuccess:async()=>{await r.invalidateQueries({queryKey:["telegram-bots"]}),y.success(n("common.success")),a(!1)},onError:o=>{y.error(o instanceof Error?o.message:n("common.error"))}}),l=k({mutationFn:async()=>{if(!t)throw new Error(n("telegram.updateFailed"));const o={name:p.trim(),allowAuthRequests:f};i.trim()&&(o.token=i.trim());const E=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!E.ok)throw new Error(await Qe(E,n("telegram.updateFailed")))},onSuccess:async()=>{await r.invalidateQueries({queryKey:["telegram-bots"]}),y.success(n("common.success")),a(!1)},onError:o=>{y.error(o instanceof Error?o.message:n("common.error"))}}),h=v.isPending||l.isPending,b=p.trim().length>0&&(m||i.trim().length>0),S=()=>{!b||h||(m?l.mutate():v.mutate())};return e.jsx(Y,{open:s,onOpenChange:a,children:e.jsxs(ee,{className:"sm:max-w-lg","data-testid":m?`telegram-bot-edit-modal-${t==null?void 0:t.id}`:"telegram-bot-add-modal",children:[e.jsx(se,{children:e.jsx(te,{children:n(m?"telegram.editBot":"telegram.addBot")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"telegram-bot-name",children:n("telegram.botName")}),e.jsx(P,{id:"telegram-bot-name","data-testid":"telegram-bot-name-input",value:p,onChange:o=>x(o.target.value),placeholder:n("telegram.botNamePlaceholder"),className:Oe})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"telegram-bot-token",children:n("telegram.botToken")}),e.jsx(P,{id:"telegram-bot-token","data-testid":"telegram-bot-token-input",type:"password",value:i,onChange:o=>c(o.target.value),placeholder:n(m?"telegram.tokenPlaceholder":"telegram.botTokenPlaceholder"),className:Oe})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:n("telegram.allowAuthRequests")}),e.jsx(A,{checked:f,"data-testid":"telegram-bot-allow-auth",onCheckedChange:o=>d(!!o)})]})]}),e.jsxs(he,{children:[e.jsx(w,{variant:"outline",onClick:()=>a(!1),disabled:h,children:n("common.cancel")}),e.jsxs(w,{variant:"secondary","data-testid":"telegram-bot-form-submit",onClick:S,disabled:!b||h,children:[h?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(I,{className:"h-4 w-4"}),n("common.save")]})]})]})})}async function oe(s,a){try{return(await s.json()).error??a}catch{return a}}function Ws({open:s,onOpenChange:a,botId:t,botName:n}){var v;const{t:r}=F(),m=M(),p=K({queryKey:["telegram-bot-chats",t],enabled:s,queryFn:async()=>{const l=await fetch(`/api/settings/telegram/bots/${t}/chats`);if(!l.ok)throw new Error(await oe(l,r("telegram.loadChatsFailed")));return await l.json()}}),x=j.useMemo(()=>{var h;const l=((h=p.data)==null?void 0:h.chats)??[];return{pending:l.filter(b=>b.status==="pending"),authorized:l.filter(b=>b.status==="authorized")}},[(v=p.data)==null?void 0:v.chats]),i=async()=>{await Promise.all([m.invalidateQueries({queryKey:["telegram-bots"]}),m.invalidateQueries({queryKey:["telegram-bot-chats",t]})])},c=k({mutationFn:async l=>{const h=await fetch(`/api/settings/telegram/bots/${t}/chats/${encodeURIComponent(l)}/approve`,{method:"POST"});if(!h.ok)throw new Error(await oe(h,r("telegram.approveFailed")))},onSuccess:async()=>{await i(),y.success(r("common.success"))},onError:l=>{y.error(l instanceof Error?l.message:r("common.error"))}}),f=k({mutationFn:async l=>{const h=await fetch(`/api/settings/telegram/bots/${t}/chats/${encodeURIComponent(l)}`,{method:"DELETE"});if(!h.ok)throw new Error(await oe(h,r("telegram.removeFailed")))},onSuccess:async()=>{await i(),y.success(r("common.success"))},onError:l=>{y.error(l instanceof Error?l.message:r("common.error"))}}),d=k({mutationFn:async l=>{const h=await fetch(`/api/settings/telegram/bots/${t}/chats/${encodeURIComponent(l)}/test`,{method:"POST"});if(!h.ok)throw new Error(await oe(h,r("telegram.testMessageFailed")))},onSuccess:()=>{y.success(r("common.success"))},onError:l=>{y.error(l instanceof Error?l.message:r("common.error"))}});return e.jsx(Y,{open:s,onOpenChange:a,children:e.jsxs(ee,{className:"sm:max-w-2xl","data-testid":`telegram-bot-chats-modal-${t}`,children:[e.jsxs(se,{children:[e.jsx(te,{children:r("telegram.chats")}),e.jsx(me,{children:n})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"flex items-center gap-1 text-sm font-semibold",children:[e.jsx(Re,{className:"h-4 w-4"}),r("telegram.pendingChats")]}),x.pending.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:r("telegram.noPendingChats")}),x.pending.map(l=>e.jsx(Ue,{chat:l,pending:!0,onApprove:()=>c.mutate(l.chatId),onDelete:()=>f.mutate(l.chatId)},`${l.botId}-${l.chatId}`))]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"flex items-center gap-1 text-sm font-semibold",children:[e.jsx(Re,{className:"h-4 w-4"}),r("telegram.chats")]}),x.authorized.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:r("telegram.noAuthorizedChats")}),x.authorized.map(l=>e.jsx(Ue,{chat:l,pending:!1,onTest:()=>d.mutate(l.chatId),onDelete:()=>f.mutate(l.chatId)},`${l.botId}-${l.chatId}`))]}),p.isLoading&&e.jsx("div",{className:"text-xs text-muted-foreground lg:col-span-2",children:r("common.loading")})]})]})})}function Ue({chat:s,pending:a,onApprove:t,onDelete:n,onTest:r}){const{t:m}=F(),p=ue(x=>{var i;return((i=x.settings)==null?void 0:i.language)??"en_US"});return e.jsxs("div",{className:"space-y-2 rounded border-0 bg-background p-3",children:[e.jsx("div",{className:"truncate text-sm font-medium",title:s.displayName,children:s.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[m("telegram.chatId"),":",s.chatId]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(s.appliedAt).toLocaleString(Ce(p))}),e.jsx("div",{className:"flex items-center justify-end gap-2 pt-1",children:a?e.jsxs(e.Fragment,{children:[e.jsx(w,{variant:"outline",size:"sm",onClick:n,children:m("telegram.reject")}),e.jsx(w,{variant:"secondary",size:"sm",onClick:t,children:m("telegram.authorize")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(w,{variant:"secondary",size:"sm",onClick:r,children:[e.jsx(os,{className:"h-3.5 w-3.5"}),m("telegram.sendTestMessage")]}),e.jsx(w,{variant:"destructive",size:"sm",onClick:n,children:m("common.delete")})]})})]})}async function ze(s,a){try{return(await s.json()).error??a}catch{return a}}function Js({bot:s,onEdit:a}){const{t}=F(),n=M(),[r,m]=j.useState(!1),p=k({mutationFn:async i=>{const c=await fetch(`/api/settings/telegram/bots/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:i})});if(!c.ok)throw new Error(await ze(c,t("telegram.updateFailed")))},onSuccess:async()=>{await n.invalidateQueries({queryKey:["telegram-bots"]})},onError:i=>{y.error(i instanceof Error?i.message:t("common.error"))}}),x=k({mutationFn:async()=>{const i=await fetch(`/api/settings/telegram/bots/${s.id}`,{method:"DELETE"});if(!i.ok)throw new Error(await ze(i,t("telegram.deleteFailed")))},onSuccess:async()=>{await n.invalidateQueries({queryKey:["telegram-bots"]}),y.success(t("common.success"))},onError:i=>{y.error(i instanceof Error?i.message:t("common.error"))}});return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-3 sm:flex-row sm:items-center sm:justify-between","data-testid":`telegram-bot-card-${s.id}`,"data-bot-name":s.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(A,{checked:s.enabled,disabled:p.isPending,onCheckedChange:i=>p.mutate(!!i),"data-testid":`telegram-bot-enabled-${s.id}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:s.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t("telegram.authCount",{authorized:s.authorizedCount,pending:s.pendingCount})})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(w,{variant:"ghost",size:"icon-sm",title:t("telegram.chats"),"data-testid":`telegram-bot-chats-${s.id}`,onClick:()=>m(!0),children:e.jsx(Ms,{className:"h-4 w-4"})}),e.jsx(w,{variant:"ghost",size:"icon-sm",title:t("common.edit"),"data-testid":`telegram-bot-edit-${s.id}`,onClick:()=>a(s),children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx(w,{variant:"ghost",size:"icon-sm",title:t("telegram.deleteBot"),"data-testid":`telegram-bot-delete-${s.id}`,onClick:()=>x.mutate(),disabled:x.isPending,children:e.jsx(O,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(Ws,{open:r,onOpenChange:m,botId:s.id,botName:s.name})]})}async function Gs(s,a){try{return(await s.json()).error??a}catch{return a}}function Zs(){var c;const{t:s}=F(),[a,t]=j.useState(!1),[n,r]=j.useState(void 0),m=K({queryKey:["telegram-bots"],queryFn:async()=>{const f=await fetch("/api/settings/telegram/bots");if(!f.ok)throw new Error(await Gs(f,s("telegram.loadBotsFailed")));return await f.json()}}),p=((c=m.data)==null?void 0:c.bots)??[],x=()=>{r(void 0),t(!0)},i=f=>{r(f),t(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs($,{className:"border-0 ring-0",children:[e.jsxs(B,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsx(_,{children:s("telegram.title")}),e.jsxs(w,{variant:"secondary","data-testid":"telegram-add-bot",onClick:x,children:[e.jsx(de,{className:"h-4 w-4"}),s("telegram.addBot")]})]}),e.jsxs(q,{className:"space-y-3",children:[m.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.loading")}),!m.isLoading&&p.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("telegram.noBots")}),p.map(f=>e.jsx(Js,{bot:f,onEdit:i},f.id))]})]}),e.jsx(Hs,{open:a,onOpenChange:t,bot:n})]})}function Xs(){const{t:s}=F();return e.jsxs("div",{className:"space-y-4",children:[e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(B,{children:e.jsx(_,{children:s("settings.terminal.title")})}),e.jsx(q,{children:e.jsx(vs,{showShortcuts:!1})})]}),e.jsxs($,{className:"border-0 ring-0",children:[e.jsxs(B,{children:[e.jsx(_,{children:s("settings.terminal.shortcuts.title")}),e.jsx(We,{children:s("settings.terminal.shortcuts.savedOnServer")})]}),e.jsx(q,{children:e.jsx(ws,{})})]})]})}async function fe(s,a){try{return(await s.json()).error??a}catch{return a}}function je({label:s,value:a}){return e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2 text-sm font-medium",children:s}),e.jsx("div",{className:"min-w-0 truncate text-right text-sm text-muted-foreground",children:a})]})}function Ys(){const{t:s}=F(),a=M(),t=ue(g=>{var C;return((C=g.settings)==null?void 0:C.language)??"en_US"}),[n,r]=j.useState(!1),[m,p]=j.useState(!1),x=j.useRef(!1),c=K({queryKey:["system-info"],queryFn:async()=>{const g=await fetch("/api/system/info");if(!g.ok)throw new Error(await fe(g,s("settings.loadFailed")));return await g.json()}}).data,f=K({queryKey:["system-update-check"],enabled:!1,gcTime:0,queryFn:async()=>{const g=await fetch("/api/system/update-check");if(!g.ok)throw new Error(await fe(g,s("settings.version.checkFailed")));return await g.json()}}),d=f.data,l=K({queryKey:["system-upgrade-status"],enabled:m,refetchInterval:g=>{var N;const C=(N=g.state.data)==null?void 0:N.state;return m||C&&C!=="idle"?2e3:!1},retry:!0,queryFn:async()=>{const g=await fetch("/api/system/upgrade");if(!g.ok)throw new Error("status");return await g.json()}}).data;j.useEffect(()=>{if(!m)return;const g=l==null?void 0:l.state;g&&g!=="idle"?x.current=!0:g==="idle"&&(l!=null&&l.error)?(x.current=!1,p(!1),y.error(l.error)):g==="idle"&&x.current&&(x.current=!1,p(!1),a.invalidateQueries({queryKey:["system-info"]}),a.removeQueries({queryKey:["system-update-check"]}),y.success(s("common.success")))},[m,l,a,s]);const h=k({mutationFn:async g=>{const C=await fetch("/api/system/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({version:g})});if(!C.ok)throw new Error(await fe(C,s("common.error")));return await C.json()},onSuccess:g=>{x.current=!1,p(!0),a.setQueryData(["system-upgrade-status"],g),y.success(s("settings.version.upgradeStarted"))},onError:g=>{y.error(g instanceof Error?g.message:s("common.error"))}}),b=g=>s(g==="launchd"?"settings.version.deploymentLaunchd":g==="systemd"?"settings.version.deploymentSystemd":"settings.version.deploymentNone"),S=m&&(l==null?void 0:l.state)!==void 0,o=(l==null?void 0:l.state)==="downloading"?s("settings.version.stateDownloading"):(l==null?void 0:l.state)==="executing"?s("settings.version.stateExecuting"):null,E=c!=null&&c.canSelfUpdate?null:c!=null&&c.isProd?c!=null&&c.installedViaCli?null:s("settings.version.upgradeDisabledNonCli"):s("settings.version.upgradeDisabledDev");return e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(B,{children:e.jsx(_,{children:s("settings.version.title")})}),e.jsxs(q,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(je,{label:s("settings.version.currentVersion"),value:e.jsx("span",{"data-testid":"settings-version-current",className:"font-mono",children:c?c.version:s("common.loading")})}),e.jsx(je,{label:s("settings.version.installMethod"),value:c?c.installedViaCli?s("settings.version.installMethodCli"):s("settings.version.installMethodNonCli"):"-"}),e.jsx(je,{label:s("settings.version.deployment"),value:c?b(c.deployment):"-"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(w,{variant:"outline","data-testid":"settings-version-check",onClick:()=>f.refetch(),disabled:f.isFetching||S,children:[f.isFetching?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(Je,{className:"h-4 w-4"}),f.isFetching?s("settings.version.checking"):s("settings.version.checkUpdate")]}),d&&e.jsxs("span",{className:"text-sm text-muted-foreground","data-testid":"settings-version-latest",children:[d.hasUpdate&&d.latestVersion?s("settings.version.updateAvailable",{version:d.latestVersion}):s("settings.version.upToDate"),d.publishedAt?` · ${s("settings.version.publishedAt",{date:new Date(d.publishedAt).toLocaleDateString(Ce(t))})}`:""]})]}),f.isError&&e.jsx("div",{className:"text-sm text-destructive",children:s("settings.version.checkFailed")}),(d==null?void 0:d.hasUpdate)&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-semibold",children:s("settings.version.changelog")}),e.jsx("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:d.changelog?e.jsx(Ns,{source:d.changelog,basePath:"/"}):e.jsx("div",{className:"text-sm text-muted-foreground",children:s("settings.version.changelogUnavailable")})}),c!=null&&c.canSelfUpdate?e.jsxs(w,{variant:"secondary","data-testid":"settings-version-upgrade",disabled:S||h.isPending,onClick:()=>r(!0),children:[S?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(cs,{className:"h-4 w-4"}),s("settings.version.upgrade")]}):e.jsxs("div",{className:"space-y-1",children:[E&&e.jsx("div",{className:"text-sm text-muted-foreground",children:E}),e.jsx("div",{className:"text-xs text-muted-foreground font-mono",children:s("settings.version.terminalHint")})]})]}),S&&o&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-border bg-card px-4 py-3","data-testid":"settings-version-upgrade-status",children:[e.jsx(D,{className:"mt-0.5 h-4 w-4 shrink-0 animate-spin text-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm font-medium",children:o}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("settings.version.interruptNotice")})]})]})]}),e.jsx(z,{open:n,onOpenChange:r,children:e.jsxs(V,{children:[e.jsxs(H,{children:[e.jsxs(W,{className:"flex items-center gap-2",children:[e.jsx(ds,{className:"h-5 w-5 text-destructive"}),s("settings.version.upgradeWarningTitle")]}),e.jsx(J,{children:s("settings.version.upgradeWarningBody")})]}),e.jsxs(G,{children:[e.jsx(Z,{onClick:()=>r(!1),children:s("common.cancel")}),e.jsx(X,{variant:"destructive","data-testid":"settings-version-upgrade-confirm",onClick:()=>{r(!1),d!=null&&d.latestVersion&&h.mutate(d.latestVersion)},children:s("settings.version.upgrade")})]})]})})]})}const ye=["terminal_bell","terminal_notification","tmux_window_close","tmux_pane_close","device_tmux_missing","device_disconnect","session_created","session_closed","agent_confirmation_pending","agent_turn_finished","agent_error","watch_triggered","watch_model_unavailable","watch_rule_error"];async function ve(s,a){try{return(await s.json()).error??a}catch{return a}}function et(){var l;const{t:s}=F(),a=M(),t=ue(h=>{var b;return((b=h.settings)==null?void 0:b.language)??"en_US"}),[n,r]=j.useState(""),[m,p]=j.useState(""),[x,i]=j.useState(ye),c=K({queryKey:["webhooks"],queryFn:async()=>{const h=await fetch("/api/webhooks");if(!h.ok)throw new Error(await ve(h,s("webhook.loadFailed")));return await h.json()}}),f=k({mutationFn:async()=>{const h=await fetch("/api/webhooks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:n,secret:m,eventMask:x})});if(!h.ok)throw new Error(await ve(h,s("webhook.createFailed")))},onSuccess:async()=>{r(""),p(""),i(ye),await a.invalidateQueries({queryKey:["webhooks"]}),y.success(s("common.success"))},onError:h=>{y.error(h instanceof Error?h.message:s("common.error"))}}),d=k({mutationFn:async h=>{const b=await fetch(`/api/webhooks/${h}`,{method:"DELETE"});if(!b.ok)throw new Error(await ve(b,s("webhook.deleteFailed")))},onSuccess:async()=>{await a.invalidateQueries({queryKey:["webhooks"]}),y.success(s("common.success"))},onError:h=>{y.error(h instanceof Error?h.message:s("common.error"))}}),v=((l=c.data)==null?void 0:l.webhooks)??[];return e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(B,{children:e.jsx(_,{children:s("webhook.title")})}),e.jsxs(q,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-6 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-url-input",children:s("webhook.url")}),e.jsx(P,{id:"webhook-url-input","data-testid":"webhook-url-input",value:n,onChange:h=>r(h.target.value),placeholder:"https://example.com/webhook",className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-secret-input",children:s("webhook.secret")}),e.jsx(P,{id:"webhook-secret-input","data-testid":"webhook-secret-input",value:m,onChange:h=>p(h.target.value),placeholder:s("webhook.secretPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs(w,{variant:"secondary",className:"w-full md:w-auto","data-testid":"webhook-add",onClick:()=>f.mutate(),disabled:f.isPending||!n.trim()||!m.trim()||x.length===0,children:[f.isPending?e.jsx(D,{className:"h-4 w-4 animate-spin"}):e.jsx(I,{className:"h-4 w-4"}),s("webhook.add")]})})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("div",{className:"text-sm font-medium",children:s("webhook.eventMask")}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:ye.map(h=>{const b=x.includes(h);return e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-background px-3 py-2",children:[e.jsx("div",{className:"min-w-0 pr-2 text-sm font-medium",children:s(`notification.eventType.${h}`)}),e.jsx(A,{checked:b,"data-testid":`webhook-event-${h}`,onCheckedChange:S=>{i(o=>S?o.includes(h)?o:[...o,h]:o.filter(E=>E!==h))}})]},h)})})]}),e.jsxs("div",{className:"space-y-2",children:[c.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.loading")}),!c.isLoading&&v.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s("webhook.empty")}),v.map(h=>e.jsxs("div",{"data-testid":"webhook-item","data-webhook-url":h.url,className:"flex items-center justify-between gap-3 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:h.url}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(h.createdAt).toLocaleString(Ce(t))})]}),e.jsx(w,{variant:"ghost",size:"icon-sm","data-testid":"webhook-delete",onClick:()=>d.mutate(h.id),disabled:d.isPending,"aria-label":s("common.delete"),title:s("common.delete"),children:e.jsx(O,{className:"h-4 w-4"})})]},h.id))]})]})]})}async function be(s,a){try{return(await s.json()).error??a}catch{return a}}function it(){var qe,De;const{t:s}=F(),a=M(),{refreshSettings:t}=ue(),[n,r]=j.useState("general"),m=Be(u=>u.theme),p=Be(u=>u.setTheme),x=m==="dark",[i,c]=j.useState("tmex"),[f,d]=j.useState(window.location.origin),[v,l]=j.useState("en_US"),[h,b]=j.useState(6),[S,o]=j.useState(3),[E,g]=j.useState(!0),[C,N]=j.useState(!0),[L,Se]=j.useState(!0),[Ee,Fe]=j.useState(!0),[Pe,Te]=j.useState(2),[Me,Ae]=j.useState(10),[Ge,Ze]=j.useState(!1),Xe=u=>{const T=u?"dark":"light";p(T),document.documentElement.classList.toggle("dark",T==="dark")},ge=K({queryKey:["site-settings"],queryFn:async()=>{const u=await fetch("/api/settings/site");if(!u.ok)throw new Error(await be(u,s("settings.loadFailed")));return await u.json()}});j.useEffect(()=>{var T;const u=(T=ge.data)==null?void 0:T.settings;u&&(c(u.siteName),d(u.siteUrl),l(u.language??"en_US"),b(u.bellThrottleSeconds),o(u.notificationThrottleSeconds??3),g(u.enableBrowserBellToast??!0),N(u.enableBrowserNotificationToast??!0),Se(u.enableTelegramBellPush??!0),Fe(u.enableTelegramNotificationPush??!0),Te(u.sshReconnectMaxRetries),Ae(u.sshReconnectDelaySeconds))},[(qe=ge.data)==null?void 0:qe.settings]);const Ke=k({mutationFn:async()=>{const T=await fetch("/api/settings/site",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({siteName:i,siteUrl:f,language:v,bellThrottleSeconds:h,notificationThrottleSeconds:S,enableBrowserBellToast:E,enableBrowserNotificationToast:C,enableTelegramBellPush:L,enableTelegramNotificationPush:Ee,sshReconnectMaxRetries:Pe,sshReconnectDelaySeconds:Me})});if(!T.ok)throw new Error(await be(T,s("settings.saveFailed")))},onSuccess:async()=>{var u,T;await Promise.all([a.invalidateQueries({queryKey:["site-settings"]}),t()]),y.success(s("settings.settingsSaved")),((T=(u=ge.data)==null?void 0:u.settings)==null?void 0:T.language)!==v&&(ys.changeLanguage(v),Ze(!0))},onError:u=>{y.error(u instanceof Error?u.message:s("common.error"))}}),Ye=[{value:"general",label:s("settings.tabGroup.general"),icon:ms,testId:"settings-tab-general"},{value:"terminal",label:s("settings.tabGroup.terminal"),icon:Ne,testId:"settings-tab-terminal"},{value:"devicesAndFiles",label:s("settings.tabGroup.devicesAndFiles"),icon:Fs,testId:"settings-tab-devicesAndFiles"},{value:"notifications",label:s("settings.tabGroup.notifications"),icon:hs,testId:"settings-tab-notifications"},{value:"ai",label:s("settings.tabGroup.ai"),icon:us,testId:"settings-tab-ai"}],$e=e.jsx("div",{className:"flex justify-end pt-2",children:e.jsxs(w,{variant:"secondary","data-testid":"settings-save",onClick:()=>Ke.mutate(),disabled:Ke.isPending,className:"w-full sm:w-auto",children:[e.jsx(I,{className:"h-4 w-4"}),s("common.save")]})});return e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-4 p-3 pb-[calc(2rem+env(safe-area-inset-bottom))] sm:gap-6 sm:p-5","data-testid":"settings-page",children:[e.jsx(gs,{value:n,onValueChange:u=>r(u),children:e.jsx(xs,{className:"w-full gap-1 !justify-start overflow-x-auto rounded-xl border border-border/60 p-1.5 group-data-horizontal/tabs:h-12 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:Ye.map(u=>{const T=u.icon;return e.jsxs(ps,{value:u.value,"data-testid":u.testId,className:fs(js,"min-w-max gap-2 px-3.5"),children:[e.jsx(T,{}),u.label]},u.value)})})}),n==="general"&&e.jsxs(e.Fragment,{children:[e.jsxs($,{className:"border-0 ring-0",children:[e.jsx(B,{children:e.jsx(_,{children:s("settings.siteSettings")})}),e.jsxs(q,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-name-input",children:s("settings.siteName")}),e.jsx(P,{id:"site-name-input",value:i,onChange:u=>c(u.target.value),placeholder:s("settings.siteNamePlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-url-input",children:s("settings.siteUrl")}),e.jsx(P,{id:"site-url-input",value:f,onChange:u=>d(u.target.value),placeholder:s("settings.siteUrlPlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"language-select",children:s("settings.language")}),e.jsxs(ae,{value:v,onValueChange:u=>{u&&l(u)},children:[e.jsx(ne,{id:"language-select","data-testid":"settings-language-select",className:"w-full min-h-10",children:e.jsx(ie,{placeholder:s("settings.language"),children:((De=_e.locales.find(u=>u.code===v))==null?void 0:De.nativeName)??v})}),e.jsx(re,{className:"max-h-[var(--tmex-viewport-height)]",children:_e.locales.map(u=>e.jsx(Q,{value:u.code,children:u.nativeName},u.code))})]}),Ge&&e.jsx("p",{className:"mt-1 text-xs text-primary","data-testid":"settings-refresh-notice",children:s("settings.refreshToApply")})]}),e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:s("settings.theme")})}),e.jsx(A,{checked:x,onCheckedChange:u=>Xe(!!u),"data-testid":"settings-theme-toggle"})]})}),$e]})]}),e.jsx(Ys,{})]}),n==="devicesAndFiles"&&e.jsxs(e.Fragment,{children:[e.jsx(As,{}),e.jsx(Ks,{})]}),n==="notifications"&&e.jsxs(e.Fragment,{children:[e.jsx($,{className:"border-0 ring-0",children:e.jsxs(q,{className:"space-y-6 pt-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:s("settings.enableBrowserBellToast")})}),e.jsx(A,{checked:E,onCheckedChange:u=>g(!!u),"data-testid":"settings-enable-browser-bell-toast"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:s("settings.enableTelegramBellPush")})}),e.jsx(A,{checked:L,onCheckedChange:u=>Se(!!u),"data-testid":"settings-enable-telegram-bell-push"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:s("settings.enableBrowserNotificationToast")})}),e.jsx(A,{checked:C,onCheckedChange:u=>N(!!u),"data-testid":"settings-enable-browser-notification-toast"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:s("settings.enableTelegramNotificationPush")})}),e.jsx(A,{checked:Ee,onCheckedChange:u=>Fe(!!u),"data-testid":"settings-enable-telegram-notification-push"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"bell-throttle-input",children:s("settings.bellThrottle")}),e.jsx(P,{id:"bell-throttle-input",type:"number",value:h,min:0,max:300,onChange:u=>b(Number(u.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"notification-throttle-input",children:s("settings.notificationThrottle")}),e.jsx(P,{id:"notification-throttle-input",type:"number",value:S,min:0,max:300,onChange:u=>o(Number(u.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-retries-input",children:s("settings.sshReconnectMaxRetries")}),e.jsx(P,{id:"ssh-reconnect-retries-input",type:"number",value:Pe,min:0,max:20,onChange:u=>Te(Number(u.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-delay-input",children:s("settings.sshReconnectDelay")}),e.jsx(P,{id:"ssh-reconnect-delay-input",type:"number",value:Me,min:1,max:300,onChange:u=>Ae(Number(u.target.value)),className:"min-h-10"})]})]}),$e]})}),e.jsx(Zs,{}),e.jsx(et,{})]}),n==="ai"&&e.jsxs(e.Fragment,{children:[e.jsx(Qs,{}),e.jsx(Vs,{})]}),n==="terminal"&&e.jsx(Xs,{})]})}function rt(){const{t:s}=F();return e.jsx(e.Fragment,{children:s("sidebar.settings")})}function lt(){const{t:s}=F(),[a,t]=j.useState(!1),n=k({mutationFn:async()=>{const r=await fetch("/api/settings/restart",{method:"POST"});if(!r.ok)throw new Error(await be(r,s("settings.restartFailed")))},onSuccess:()=>{y.success(s("settings.restartScheduled"))},onError:r=>{y.error(r instanceof Error?r.message:s("common.error"))}});return e.jsxs(e.Fragment,{children:[e.jsx(w,{variant:"ghost",size:"icon-sm",onClick:()=>t(!0),disabled:n.isPending,"aria-label":s("settings.restartGateway"),title:s("settings.restartGateway"),className:"text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(bs,{className:"h-4 w-4"})}),e.jsx(z,{open:a,onOpenChange:t,children:e.jsxs(V,{children:[e.jsxs(H,{children:[e.jsx(W,{children:s("settings.restartGateway")}),e.jsx(J,{children:s("settings.restartConfirm")})]}),e.jsxs(G,{children:[e.jsx(Z,{onClick:()=>t(!1),children:s("common.cancel")}),e.jsx(X,{variant:"destructive",onClick:()=>{n.mutate(),t(!1)},children:s("common.confirm")})]})]})})]})}export{lt as PageActions,rt as PageTitle,it as default};
|
|
27
|
-
//# sourceMappingURL=SettingsPage-Cq6n8Xjc.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{s as a,c as s,a as e,C as t}from"./chunk-727SXJPM-IY0KVws8.js";import{_ as i}from"./mermaid.core-B-wSkmMd.js";import"./chunk-FMBD7UC4-DN35690f.js";import"./chunk-ND2GUHAM-lJmtxdhS.js";import"./chunk-55IACEB6-v6jayOak.js";import"./chunk-2J33WTMH-BxOp2sIC.js";import"./index-CYmVLCAD.js";var n={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{n as diagram};
|
|
2
|
-
//# sourceMappingURL=classDiagram-4FO5ZUOK-CXFjdzka.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{s as a,c as s,a as e,C as t}from"./chunk-727SXJPM-IY0KVws8.js";import{_ as i}from"./mermaid.core-B-wSkmMd.js";import"./chunk-FMBD7UC4-DN35690f.js";import"./chunk-ND2GUHAM-lJmtxdhS.js";import"./chunk-55IACEB6-v6jayOak.js";import"./chunk-2J33WTMH-BxOp2sIC.js";import"./index-CYmVLCAD.js";var n={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{n as diagram};
|
|
2
|
-
//# sourceMappingURL=classDiagram-v2-Q7XG4LA2-CXFjdzka.js.map
|