tmex-cli 0.16.0 → 0.16.2
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 +12 -24
- package/dist/runtime/server.js +414 -106
- package/package.json +1 -1
- package/resources/fe-dist/assets/DevicePage-CgDkuNLp.js +24 -0
- package/resources/fe-dist/assets/{DevicesPage-_SYGKgwy.js → DevicesPage-B_jvUZtl.js} +1 -1
- package/resources/fe-dist/assets/{FilePage-Blf_MlAq.js → FilePage-DTSmWM1D.js} +1 -1
- package/resources/fe-dist/assets/SettingsPage-LTHV37Rj.js +39 -0
- package/resources/fe-dist/assets/agent-tab-vPjPGa5f.js +38 -0
- package/resources/fe-dist/assets/{api-C2-crTt8.js → api-D_FToAy0.js} +1 -1
- package/resources/fe-dist/assets/{arc-Bzi-2Wgo.js → arc-BSCyoyGW.js} +1 -1
- package/resources/fe-dist/assets/{architectureDiagram-3BPJPVTR-DZYFrhja.js → architectureDiagram-3BPJPVTR-CBO0dAe2.js} +1 -1
- package/resources/fe-dist/assets/{blockDiagram-GPEHLZMM-lpc1A1G1.js → blockDiagram-GPEHLZMM-0ONANm30.js} +1 -1
- package/resources/fe-dist/assets/{c4Diagram-AAUBKEIU-DOc1BzPY.js → c4Diagram-AAUBKEIU-DpvhCnF8.js} +1 -1
- package/resources/fe-dist/assets/{card-BA66zlg1.js → card-CD9i-fLq.js} +1 -1
- package/resources/fe-dist/assets/channel-DBhb6_En.js +1 -0
- package/resources/fe-dist/assets/{chunk-2J33WTMH-DqycjO3G.js → chunk-2J33WTMH-MmS9_ur_.js} +1 -1
- package/resources/fe-dist/assets/{chunk-4BX2VUAB-t2B-Cl6x.js → chunk-4BX2VUAB-CLd4Yxwh.js} +1 -1
- package/resources/fe-dist/assets/{chunk-55IACEB6-BmFdQL7n.js → chunk-55IACEB6-DgCH4WwT.js} +1 -1
- package/resources/fe-dist/assets/{chunk-727SXJPM-DEa9FPer.js → chunk-727SXJPM-B9DM5PB4.js} +1 -1
- package/resources/fe-dist/assets/{chunk-AQP2D5EJ-DiZ9AoB9.js → chunk-AQP2D5EJ-DQwC9D9W.js} +1 -1
- package/resources/fe-dist/assets/{chunk-FMBD7UC4-DLcIMhi1.js → chunk-FMBD7UC4-BnvyNYGh.js} +1 -1
- package/resources/fe-dist/assets/{chunk-ND2GUHAM-Cu1P2Ot8.js → chunk-ND2GUHAM-BzcZgEWG.js} +1 -1
- package/resources/fe-dist/assets/{chunk-QZHKN3VN-C8ki16q3.js → chunk-QZHKN3VN-C9BaHIUI.js} +1 -1
- package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-9V2iXOG7.js +1 -0
- package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-9V2iXOG7.js +1 -0
- package/resources/fe-dist/assets/{copy-C8vDYUVz.js → copy-DzIk8AxV.js} +1 -1
- package/resources/fe-dist/assets/{cose-bilkent-S5V4N54A-baMBJteT.js → cose-bilkent-S5V4N54A-NkTc0ObP.js} +1 -1
- package/resources/fe-dist/assets/{dagre-BM42HDAG-CwWSiSwb.js → dagre-BM42HDAG-BdFDBfE_.js} +1 -1
- package/resources/fe-dist/assets/{diagram-2AECGRRQ-CeSwouYZ.js → diagram-2AECGRRQ-Ba4Y0igR.js} +1 -1
- package/resources/fe-dist/assets/{diagram-5GNKFQAL-DgxdcMax.js → diagram-5GNKFQAL-B4_Or8Vp.js} +1 -1
- package/resources/fe-dist/assets/{diagram-KO2AKTUF-DrglkRZC.js → diagram-KO2AKTUF-DbmmHTYj.js} +1 -1
- package/resources/fe-dist/assets/{diagram-LMA3HP47-BLHZ3p7v.js → diagram-LMA3HP47-CRrd6lc4.js} +1 -1
- package/resources/fe-dist/assets/{diagram-OG6HWLK6-_I_mMaa6.js → diagram-OG6HWLK6-BOEazFIu.js} +1 -1
- package/resources/fe-dist/assets/en_US-BihUhDmr.js +1 -0
- package/resources/fe-dist/assets/{erDiagram-TEJ5UH35-Zkbnn8Kh.js → erDiagram-TEJ5UH35-Dk-UowK8.js} +1 -1
- package/resources/fe-dist/assets/{files-tab-CPud4eIT.js → files-tab-D2vddvsj.js} +1 -1
- package/resources/fe-dist/assets/{flowDiagram-I6XJVG4X-BnV7dZI4.js → flowDiagram-I6XJVG4X-BhbGYx-g.js} +1 -1
- package/resources/fe-dist/assets/{ganttDiagram-6RSMTGT7-Cn2f5kRI.js → ganttDiagram-6RSMTGT7-iezClDTv.js} +1 -1
- package/resources/fe-dist/assets/{gitGraphDiagram-PVQCEYII-CEswG7nI.js → gitGraphDiagram-PVQCEYII-Ncqf3CQw.js} +1 -1
- package/resources/fe-dist/assets/{index-DLyPliOu.js → index-DOfY8kwB.js} +1 -1
- package/resources/fe-dist/assets/{index-BK6c5W5S.js → index-UoApkLSY.js} +67 -67
- package/resources/fe-dist/assets/index-j9kTGUS5.css +1 -0
- package/resources/fe-dist/assets/{infoDiagram-5YYISTIA-Dsx1fQI9.js → infoDiagram-5YYISTIA-CUg3PkAb.js} +1 -1
- package/resources/fe-dist/assets/{ishikawaDiagram-YF4QCWOH-CgNMvXgO.js → ishikawaDiagram-YF4QCWOH-DU0ekJw5.js} +1 -1
- package/resources/fe-dist/assets/ja_JP-f5sXmz8W.js +1 -0
- package/resources/fe-dist/assets/{journeyDiagram-JHISSGLW-CVeui1xn.js → journeyDiagram-JHISSGLW-Ji7WtMH7.js} +1 -1
- package/resources/fe-dist/assets/{kanban-definition-UN3LZRKU-WnLUDsz4.js → kanban-definition-UN3LZRKU-B8zVyM8Q.js} +1 -1
- package/resources/fe-dist/assets/{linear-B0SWPrkI.js → linear-tNPPicfI.js} +1 -1
- package/resources/fe-dist/assets/{markdown-preview-CDjnYorp.js → markdown-preview-CzbcKxcJ.js} +3 -3
- package/resources/fe-dist/assets/{mermaid.core-CXD-Pc2r.js → mermaid.core-BoNU6G1d.js} +5 -5
- package/resources/fe-dist/assets/{mindmap-definition-RKZ34NQL-DYEXXmag.js → mindmap-definition-RKZ34NQL-D_v1LaNP.js} +1 -1
- package/resources/fe-dist/assets/{pieDiagram-4H26LBE5-DkZtnbYj.js → pieDiagram-4H26LBE5-B1CHCpFf.js} +1 -1
- package/resources/fe-dist/assets/{quadrantDiagram-W4KKPZXB-DblvGass.js → quadrantDiagram-W4KKPZXB-DvA3zgR7.js} +1 -1
- package/resources/fe-dist/assets/{requirementDiagram-4Y6WPE33-KAX1DxRY.js → requirementDiagram-4Y6WPE33-BCna6ZG5.js} +1 -1
- package/resources/fe-dist/assets/{sankeyDiagram-5OEKKPKP-h9Z2LXNr.js → sankeyDiagram-5OEKKPKP-KEllFLAf.js} +1 -1
- package/resources/fe-dist/assets/{send-BVxB0Ywb.js → send-BgCF67Uc.js} +1 -1
- package/resources/fe-dist/assets/{sequenceDiagram-3UESZ5HK-DUJcq5qX.js → sequenceDiagram-3UESZ5HK-DRsq_jg_.js} +1 -1
- package/resources/fe-dist/assets/{stateDiagram-AJRCARHV-BBT56nPD.js → stateDiagram-AJRCARHV-DhATBo8D.js} +1 -1
- package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-Dn_gMFVD.js +1 -0
- package/resources/fe-dist/assets/terminal-settings-panel-DsMMZFBi.js +25 -0
- package/resources/fe-dist/assets/{timeline-definition-PNZ67QCA-DLkgXxGG.js → timeline-definition-PNZ67QCA-Det7AzPd.js} +1 -1
- package/resources/fe-dist/assets/{transfer-toast-BYw9LLNi.js → transfer-toast-CHcCj3qf.js} +1 -1
- package/resources/fe-dist/assets/{triangle-alert-D4oQhgpz.js → triangle-alert-BjHP6Ipw.js} +1 -1
- package/resources/fe-dist/assets/{vennDiagram-CIIHVFJN-CyUw7cRl.js → vennDiagram-CIIHVFJN-BF4R466L.js} +1 -1
- package/resources/fe-dist/assets/{wardley-L42UT6IY-UVd2D_HQ.js → wardley-L42UT6IY-DLHZ_6-V.js} +1 -1
- package/resources/fe-dist/assets/{wardleyDiagram-YWT4CUSO-B6As-5ml.js → wardleyDiagram-YWT4CUSO-CekN3Ye6.js} +1 -1
- package/resources/fe-dist/assets/{xychartDiagram-2RQKCTM6-DFypVaEh.js → xychartDiagram-2RQKCTM6-CJD3yg0M.js} +1 -1
- package/resources/fe-dist/assets/{zap-DxVtkroR.js → zap-Dx7JTXJN.js} +1 -1
- package/resources/fe-dist/assets/zh_CN-CPdvelFW.js +1 -0
- package/resources/fe-dist/index.html +2 -2
- package/resources/gateway-drizzle/0012_naive_lizard.sql +8 -0
- package/resources/gateway-drizzle/0013_bored_blindfold.sql +1 -0
- package/resources/gateway-drizzle/meta/_journal.json +14 -0
- package/resources/fe-dist/assets/DevicePage-CxCVolw8.js +0 -24
- package/resources/fe-dist/assets/SettingsPage-BRt22APt.js +0 -39
- package/resources/fe-dist/assets/agent-tab-DRkW6D0y.js +0 -38
- package/resources/fe-dist/assets/channel-DFyg9jlp.js +0 -1
- package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-CAgGMVvn.js +0 -1
- package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-CAgGMVvn.js +0 -1
- package/resources/fe-dist/assets/en_US-CjVU4anP.js +0 -1
- package/resources/fe-dist/assets/index-CuFTSN9i.css +0 -1
- package/resources/fe-dist/assets/ja_JP-Bq-BwOH_.js +0 -1
- package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-wyzFZc_5.js +0 -1
- package/resources/fe-dist/assets/terminal-settings-panel-DHrIp0wf.js +0 -25
- package/resources/fe-dist/assets/zh_CN-BuxyXhCT.js +0 -1
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import{Y as Oe,u as ke,j as i,aD as Tt,aE as jt,aF as Ct,aG as Nt,aH as Pt,at as kt,r as n,d as W,af as ge,ai as lt,ah as ut,ag as It,aj as Mt,aI as Lt,aJ as At,o as Me,aK as _t,D as zt,p as Dt,q as $t,s as Bt,ay as dt,aL as Je,aM as Ze,aw as ft,b as ht,aN as et,aO as Ft,c as tt,aC as mt,aP as Ne,aQ as Wt,aq as Ye,y as Ht,a2 as Ot,B as je,T as Xt,aR as qt,aS as Yt,aT as Ut,aU as Vt,aV as Kt,$ as Gt,aW as Qt,A as Jt,f as Zt,g as en,i as tn,k as nn,l as rn,m as sn,n as on}from"./index-UoApkLSY.js";import{T as cn,C as an,c as ln,F as un,a as wt,R as dn,A as fn,f as hn,t as mn,S as wn}from"./terminal-settings-panel-DsMMZFBi.js";import{e as pn}from"./selection-clipboard-D3gUQQ7L.js";import{C as gn}from"./copy-DzIk8AxV.js";import{S as it,K as xn}from"./send-BgCF67Uc.js";const vn=/^[0-9a-fA-F]{4}$/;function bn(t){if(typeof t!="string"||t.length<6)return null;const e=t.slice(0,4);if(!vn.test(e)||t[4]!==",")return null;const s={input:t,pos:5},c=pt(s);return!c||s.pos!==t.length?null:{checksum:e,root:c}}function $e(t){const e=t.pos;for(;t.pos<t.input.length;){const s=t.input.charCodeAt(t.pos);if(s<48||s>57)break;t.pos+=1}return t.pos===e?null:Number.parseInt(t.input.slice(e,t.pos),10)}function Be(t,e){return t.input[t.pos]!==e?!1:(t.pos+=1,!0)}function pt(t){const e=$e(t);if(e===null||!Be(t,"x"))return null;const s=$e(t);if(s===null||!Be(t,","))return null;const c=$e(t);if(c===null||!Be(t,","))return null;const l=$e(t);if(l===null)return null;const g=t.input[t.pos];if(g===","){t.pos+=1;const v=$e(t);return v===null?null:{type:"leaf",paneNumId:v,width:e,height:s,x:c,y:l}}if(g==="{"||g==="["){const v=g==="{"?"}":"]";t.pos+=1;const b=[];for(;;){const T=pt(t);if(!T)return null;if(b.push(T),!Be(t,",")){if(Be(t,v))break;return null}}return b.length<2?null:{type:g==="{"?"row":"column",width:e,height:s,x:c,y:l,children:b}}return null}function Ue(t){return`%${t.paneNumId}`}/**
|
|
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 Sn=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],yn=Oe("columns-2",Sn);/**
|
|
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 En=[["path",{d:"m13.5 8.5-5 5",key:"1cs55j"}],["path",{d:"m8.5 8.5 5 5",key:"a8mexj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]],Rn=Oe("search-x",En);/**
|
|
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 Tn=[["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"}]],jn=Oe("settings-2",Tn);/**
|
|
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 Cn=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],Nn=Oe("smartphone",Cn);function Pn({open:t,onOpenChange:e}){const{t:s}=ke();return i.jsx(Tt,{open:t,onOpenChange:e,children:i.jsxs(jt,{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:[i.jsxs(Ct,{children:[i.jsx(Nt,{children:s("settings.terminal.title")}),i.jsx(Pt,{children:s("settings.terminal.savedInBrowser")})]}),i.jsx("div",{className:"px-4 pb-4",children:i.jsx(cn,{})})]})})}function kn({visible:t,canPaste:e,onCopy:s,onPaste:c,onDismiss:l}){const{t:g}=ke();if(!t)return null;const v=b=>{b.preventDefault()};return i.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:[i.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:v,onClick:s,"data-testid":"terminal-selection-copy",children:[i.jsx(gn,{className:"h-4 w-4"}),g("terminal.copy")]}),e&&i.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:v,onClick:c,"data-testid":"terminal-selection-paste",children:[i.jsx(an,{className:"h-4 w-4"}),g("terminal.paste")]}),i.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:v,onClick:l,"aria-label":g("terminal.clearSelection"),"data-testid":"terminal-selection-dismiss",children:i.jsx(kt,{className:"h-4 w-4"})})]})}function gt(t){if(!t)return t;const e=t.replace(/\r\n/g,`
|
|
22
|
+
`);return(e.endsWith(`
|
|
23
|
+
`)?e.slice(0,-1):e).replace(/\n/g,`\r
|
|
24
|
+
`)}const In="\x1B[?1049h\x1B[H\x1B[2J";function Mn(t){return In+gt(t)}function Ln(t,e){let s=e,c=0;for(const b of t)b===10&&!s&&(c+=1),s=b===13;const l=s;if(c===0)return{normalized:t,endedWithCR:l};const g=new Uint8Array(t.length+c);let v=0;s=e;for(const b of t)b===10&&!s&&(g[v]=13,v+=1),g[v]=b,v+=1,s=b===13;return{normalized:g,endedWithCR:l}}const An=1.3,_n=36,zn=500,Dn=12;function $n(t,e){const s=n.useRef(!1);return n.useEffect(()=>{const c=t.current;if(!c||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;s.current=!0;let g=0,v=null,b=!1,T=0,Y=0,U=0,E=null,O=!1;const r=()=>{E!==null&&(clearTimeout(E),E=null)},ae=S=>S?!!(S.closest(".scrollbar")||S.closest(".slider")||S.closest(".xterm-scroll-area")):!1,G=(S,h,P)=>{const B=P instanceof Element?P:null;if(ae(B))return!0;const A=document.elementFromPoint(S,h);if(ae(A))return!0;const F=c.querySelector(".xterm");if(!(F instanceof HTMLElement))return!1;const u=F.getBoundingClientRect(),N=S>=u.left&&S<=u.right,H=h>=u.top&&h<=u.bottom;return!N||!H?!1:S>=u.right-_n},j=()=>[c.querySelector(".xterm-viewport"),c.querySelector(".xterm-scrollable-element")].filter(h=>h instanceof HTMLElement),le=S=>{if(v===null)return null;for(let h=0;h<S.length;h+=1){const P=S.item(h);if(P&&P.identifier===v)return P}return null},se=S=>{if(r(),S.touches.length!==1)return;const h=S.touches.item(0);h&&(v=h.identifier,g=h.clientY,T=0,b=G(h.clientX,h.clientY,S.target),Y=h.clientX,U=h.clientY,O=!1,b||(E=setTimeout(()=>{var B;E=null;const P=(e==null?void 0:e())??null;(B=P==null?void 0:P.startTouchSelection)!=null&&B.call(P,Y,U,"word")&&(O=!0)},zn)))},de=S=>{var N,H,J,M,q,te,we,fe,pe;const h=le(S.touches)??S.touches.item(0);if(!h)return;if(O){const z=(e==null?void 0:e())??null;(N=z==null?void 0:z.updateTouchSelection)==null||N.call(z,h.clientX,h.clientY),S.cancelable&&S.preventDefault();return}if(E!==null&&Math.hypot(h.clientX-Y,h.clientY-U)>Dn&&r(),b||(b=G(h.clientX,h.clientY,S.target),b&&(T=0)),b)return;const P=h.clientY,B=g-P;if(g=P,B===0)return;let A=!1,F=!1;const u=(e==null?void 0:e())??null;if(u){const z=u==null?void 0:u._core,Q=((q=(M=(J=(H=z==null?void 0:z._renderService)==null?void 0:H.dimensions)==null?void 0:J.css)==null?void 0:M.cell)==null?void 0:q.height)??18;T+=B*An;const Z=T>0?Math.floor(T/Q):Math.ceil(T/Q);if(typeof u.handleViewportGesture=="function")Z!==0&&(A=u.handleViewportGesture({source:"touch",deltaY:Z*Q,clientX:h.clientX,clientY:h.clientY}),T-=Z*Q);else if(Z!==0){const C=((we=(te=u.buffer)==null?void 0:te.active)==null?void 0:we.viewportY)??0;u.scrollLines(Z);const a=((pe=(fe=u.buffer)==null?void 0:fe.active)==null?void 0:pe.viewportY)??0;A=C!==a,F=Z<0&&C<=0&&a<=0,T-=Z*Q}}else{const z=j();if(z.length===0)return;for(const Q of z){const Z=Q.scrollTop;Q.scrollTop+=B;const C=Q.scrollTop;Math.abs(C-Z)>0&&(A=!0),B<0&&C<=0&&(F=!0)}if(!A){const Q=c.querySelector(".xterm");if(Q instanceof HTMLElement){const Z=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:B}),C=Q.dispatchEvent(Z);A=Z.defaultPrevented||!C}}}S.cancelable&&(A||F)&&S.preventDefault()},re=S=>{var P;if(r(),!(v===null||!le(S.changedTouches))&&(v=null,T=0,b=!1,O)){O=!1;const B=(e==null?void 0:e())??null;(P=B==null?void 0:B.endTouchSelection)==null||P.call(B)}},f=S=>{O&&S.preventDefault()};return c.addEventListener("touchstart",se,{passive:!0}),c.addEventListener("touchmove",de,{passive:!1}),c.addEventListener("touchend",re,{passive:!0}),c.addEventListener("touchcancel",re,{passive:!0}),c.addEventListener("contextmenu",f),()=>{s.current=!1,r(),c.removeEventListener("touchstart",se),c.removeEventListener("touchmove",de),c.removeEventListener("touchend",re),c.removeEventListener("touchcancel",re),c.removeEventListener("contextmenu",f)}},[t,e]),s}function Bn({now:t,remoteSize:e,pendingLocalSize:s,ttlMs:c=2e3}){return!s||t-s.at>c?!0:s.cols===e.cols&&s.rows===e.rows}function Fn({currentSize:t,containerSize:e,force:s=!1}){return s?!0:t.cols!==e.cols||t.rows!==e.rows}function Wn({deviceId:t,paneId:e,deviceConnected:s,isSelectionInvalid:c,sizingMode:l="report",onResize:g,onSync:v,getContainerRect:b}){const T=n.useRef(null),Y=n.useRef(null),U=n.useRef(null),E=n.useRef(null),O=n.useRef(0),r=n.useRef([]),ae=n.useRef(null),G=n.useRef(null),j=n.useRef(b),le=n.useRef(!1),se=n.useRef(g),de=n.useRef(v);n.useEffect(()=>{se.current=g},[g]),n.useEffect(()=>{de.current=v},[v]),n.useEffect(()=>{j.current=b},[b]);const re=n.useCallback(()=>{var we,fe,pe,z,Q,Z,C,a,m,R;const u=G.current,N=ae.current;if(!u||!N||!u.element)return null;let H;try{const y=N.proposeDimensions();if(!y)throw new Error("fitAddon.proposeDimensions() returned null");H=Math.max(2,y.cols)}catch{const y=u._core,X=((z=(pe=(fe=(we=y==null?void 0:y._renderService)==null?void 0:we.dimensions)==null?void 0:fe.css)==null?void 0:pe.cell)==null?void 0:z.width)??9,oe=(Q=j.current)==null?void 0:Q.call(j);if(!oe||oe.width===0)return null;H=Math.max(2,Math.floor(oe.width/X))}const J=(Z=j.current)==null?void 0:Z.call(j);if(!J||J.height===0)return null;const M=u._core,q=((R=(m=(a=(C=M==null?void 0:M._renderService)==null?void 0:C.dimensions)==null?void 0:a.css)==null?void 0:m.cell)==null?void 0:R.height)??17,te=Math.max(2,Math.floor(J.height/q));return{cols:H,rows:te}},[]),f=n.useCallback((u,N)=>{const H=G.current;H&&(H.cols===u&&H.rows===N||H.resize(u,N))},[]),S=n.useCallback((u,N=!1)=>{if(l==="follow"||!t||!e||!s||c&&u!=="sync"||!N&&Date.now()<O.current||!G.current)return!1;const J=re();if(!J)return!1;const{cols:M,rows:q}=J,te=U.current;return!N&&te&&te.cols===M&&te.rows===q?(f(M,q),!0):(f(M,q),u==="sync"?de.current(M,q):se.current(M,q),U.current={cols:M,rows:q},E.current={cols:M,rows:q,at:Date.now()},!0)},[f,s,t,c,re,e,l]),h=n.useCallback((u="resize",N={})=>{const{immediate:H=!1,force:J=!1}=N;Y.current!==null&&(window.clearTimeout(Y.current),Y.current=null),T.current!==null&&(cancelAnimationFrame(T.current),T.current=null);const M=()=>{T.current=requestAnimationFrame(()=>{T.current=null,S(u,J)})};if(H){M();return}Y.current=window.setTimeout(()=>{Y.current=null,M()},150)},[S]),P=n.useCallback(()=>{for(const u of r.current)window.clearTimeout(u);r.current=[]},[]),B=n.useCallback(()=>{var N;P(),h("sync",{immediate:!0,force:!0});const u=window.setTimeout(()=>{h("sync",{immediate:!0,force:!0})},60);r.current.push(u),typeof document<"u"&&"fonts"in document&&((N=document.fonts)!=null&&N.ready)&&document.fonts.ready.then(()=>{h("sync",{immediate:!0,force:!0})}).catch(()=>{})},[P,h]);n.useEffect(()=>{let u=null;const N=()=>{u!==null&&cancelAnimationFrame(u),u=requestAnimationFrame(()=>{u=null,h("resize")})};return window.addEventListener("resize",N),()=>{window.removeEventListener("resize",N),u!==null&&cancelAnimationFrame(u)}},[h]),n.useEffect(()=>{const u=()=>{var we;const M=G.current,q=re();if(!M||!q)return;if(!Fn({currentSize:{cols:Math.max(2,M.cols),rows:Math.max(2,M.rows)},containerSize:q})){(we=M.forceFullRepaint)==null||we.call(M);return}h("sync",{force:!0})},N=()=>{if(document.visibilityState!=="visible"){le.current=!0;return}le.current&&(le.current=!1,u())},H=()=>{le.current=!0},J=()=>{le.current&&(le.current=!1,u())};return document.addEventListener("visibilitychange",N),window.addEventListener("blur",H),window.addEventListener("focus",J),()=>{document.removeEventListener("visibilitychange",N),window.removeEventListener("blur",H),window.removeEventListener("focus",J)}},[re,h]),n.useEffect(()=>()=>{P(),Y.current!==null&&window.clearTimeout(Y.current),T.current!==null&&cancelAnimationFrame(T.current)},[P]);const A=n.useCallback(u=>{ae.current=u},[]),F=n.useCallback(u=>{G.current=u},[]);return{scheduleResize:h,runPostSelectResize:B,clearPostSelectResizeTimers:P,setFitAddon:A,setTerminal:F,lastReportedSize:U,pendingLocalSize:E,suppressLocalResizeUntil:O}}const Hn=1e4,Ke="tmex:terminal-mode-cache";function On(t,e){try{const s=sessionStorage.getItem(Ke);return s?JSON.parse(s)[`${t}:${e}`]??null:null}catch{return null}}function Xn(t,e,s){try{const c=sessionStorage.getItem(Ke),l=c?JSON.parse(c):{},g=`${t}:${e}`;s?l[g]=s:delete l[g],sessionStorage.setItem(Ke,JSON.stringify(l))}catch{}}function qn(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1}}function Yn(t,e){if(!e)return t?{...t,mouseX10:!1,mouseNormal:!1,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgrPixels:!1,mouseUrxvt:!1,altScreen1047:!1,altScreen1049:!1}:null;const s=qn();if(!t)return s;const c=t.mouseNormal||t.mouseButton||t.mouseAny;return{...t,mouseX10:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1,mouseNormal:c?t.mouseNormal:s.mouseNormal}}function Un(t){var s;const e=globalThis;e.__tmexE2eXterm=t,e.__tmexE2eTerminal=t,e.__tmexE2eTerminalEngine=wt,e.__tmexE2eTerminalRenderer=((s=t.getRendererKind)==null?void 0:s.call(t))??null}function Vn(t){if(!t)return;const e=globalThis;e.__tmexE2eTerminal!==t&&e.__tmexE2eXterm!==t||(e.__tmexE2eXterm=null,e.__tmexE2eTerminal=null,e.__tmexE2eTerminalEngine=null,e.__tmexE2eTerminalRenderer=null,e.__tmexE2eTerminalSelectionText=null)}const nt=n.forwardRef(({deviceId:t,paneId:e,theme:s,inputMode:c,deviceConnected:l,isSelectionInvalid:g,sizingMode:v="report",autoFocus:b=!0,focused:T=!0,onResize:Y,onSync:U,children:E},O)=>{const[r,ae]=n.useState(null),[G,j]=n.useState(!1),le=W(d=>d.sendInput),se=ge(d=>d.terminalFontId),de=ge(d=>d.terminalFontSize),re=ge(d=>d.terminalLineHeight),{t:f}=ke(),S=n.useMemo(()=>{switch(s){case"light":return ut;default:return lt}},[s]),h=n.useRef(null),P=n.useRef(null),B=n.useRef(null),A=n.useRef(t),F=n.useRef(e),u=n.useRef(t),N=n.useRef(e),H=n.useRef(l&&!g),J=n.useRef(c),M=n.useRef(S),q=n.useRef(!1),te=n.useRef(!1),we=n.useRef(null),fe=n.useRef(!1),pe=n.useCallback((d,x,L)=>{!(d!=null&&d.exportModeSnapshot)||!x||!L||Xn(x,L,d.exportModeSnapshot())},[]),z=n.useCallback(()=>r,[r]);$n(h,z),n.useEffect(()=>{A.current=t,F.current=e,te.current=!1},[t,e]),n.useEffect(()=>{H.current=l&&!g},[l,g]),n.useEffect(()=>{J.current=c},[c]),n.useEffect(()=>{M.current=S},[S]);const Q=n.useCallback(d=>{if(!d||c!=="direct"||!H.current)return;const x=A.current,L=F.current;!x||!L||le(x,L,d,!1)},[c,le]),{pendingLocalSize:Z,scheduleResize:C,runPostSelectResize:a,setFitAddon:m,setTerminal:R}=Wn({deviceId:t,paneId:e,deviceConnected:l,isSelectionInvalid:g,sizingMode:v,onResize:Y,onSync:U,getContainerRect:()=>{const d=h.current;if(!d)return null;const x=d.getBoundingClientRect();return{width:x.width,height:x.height}}});n.useEffect(()=>{let d=!1,x=null;return(async()=>{if(await It(se,de),d)return;const L=await ln({fontFamily:Mt(se),fontSize:de,lineHeight:re,scrollback:Hn,theme:M.current,disableStdin:J.current==="editor"});if(d){L.dispose();return}x=L,P.current&&L.open(P.current),ae(L)})(),()=>{d=!0,ae(null),Vn(x),x==null||x.dispose()}},[se,de,re]),n.useEffect(()=>{!r||!b||Un(r)},[r,b]),n.useEffect(()=>{var d;(d=r==null?void 0:r.setFocused)==null||d.call(r,T)},[r,T]),n.useEffect(()=>{!r||!("setTheme"in r)||r.setTheme(S)},[r,S]),n.useEffect(()=>{!r||!("setDisableStdin"in r)||r.setDisableStdin(c==="editor")},[r,c]),n.useEffect(()=>{if(!(r!=null&&r.getCursorViewportRect))return;const d=()=>{var x;return((x=r.getCursorViewportRect)==null?void 0:x.call(r))??null};return _t(d),()=>Lt(d)},[r]),n.useEffect(()=>{!r||c!=="direct"||!b||window.innerWidth<768||"ontouchstart"in window||r.focus()},[r,c,b]);const y=n.useMemo(()=>r?{onReset:()=>{pe(r,u.current,N.current),fe.current=!0,r.reset(),q.current=!1,a()},onApplyHistory:(d,x)=>{var k,ie;const L=Yn(On(A.current,F.current),x);L&&((k=r.restoreModeSnapshot)==null||k.call(r,L));const D=x?Mn(d):gt(d);te.current=!0,r.write(D),(ie=r.forceFullRepaint)==null||ie.call(r),fe.current=!1,u.current=A.current,N.current=F.current,pe(r,A.current,F.current)},onOutput:d=>{const x=Ln(d,q.current);q.current=x.endedWithCR,r.write(x.normalized),te.current&&(r.buffer.active.baseY<=1&&r.scrollToTop(),te.current=!1),u.current=A.current,N.current=F.current,pe(r,A.current,F.current)}}:null,[r,pe,a]);n.useEffect(()=>{r?we.current!==r&&(q.current=!1,u.current=A.current,N.current=F.current,we.current=r):we.current=null},[r]),n.useEffect(()=>{if(!(!r||!t||!e))return()=>{if(fe.current){fe.current=!1;return}pe(r,u.current,N.current)}},[t,r,e,pe]),n.useEffect(()=>{if(!(!y||!t||!e))return At(t,e,y)},[y,t,e]),n.useEffect(()=>{if(!r){B.current=null,m(null),R(null);return}const d=new un;return r.loadAddon(d),B.current=d,m(d),R(r),a(),()=>{try{d.dispose()}finally{B.current=null,m(null),R(null)}}},[r,a,m,R]),n.useEffect(()=>{const d=h.current;if(!d)return;let x=null;const L=new ResizeObserver(()=>{x!==null&&cancelAnimationFrame(x),x=requestAnimationFrame(()=>{x=null,C("resize")})});return L.observe(d),()=>{L.disconnect(),x!==null&&cancelAnimationFrame(x)}},[C]),n.useEffect(()=>{if(!r||!t||!e)return;const d=r.onData(x=>{!l||g||Q(x)});return r.attachCustomKeyEventHandler(x=>!l||g||x.type!=="keydown"||c!=="direct"?!0:x.shiftKey&&x.key==="Enter"?(x.preventDefault(),Q("\x1B[13;2u"),!1):!0),()=>{d.dispose(),r.attachCustomKeyEventHandler(()=>!0)}},[r,l,g,c,Q,t,e]),n.useEffect(()=>{if(!(r!=null&&r.onLinkActivated))return;const d=r.onLinkActivated(x=>{window.open(x,"_blank","noopener,noreferrer")});return()=>d.dispose()},[r]),n.useEffect(()=>{if(!(r!=null&&r.onSelectionChange)){j(!1);return}const d=r.onSelectionChange(x=>{j(!!x)});return()=>{d.dispose(),j(!1)}},[r]);const X=n.useCallback(()=>{var x;if(!r)return;const d=((x=r.getSelection)==null?void 0:x.call(r))??"";d&&pn(d).then(()=>{Me.success(f("terminal.copied"))}).catch(()=>{Me.error(f("terminal.copyFailed"))}).finally(()=>{var L;(L=r.clearSelection)==null||L.call(r),r.focus()})},[r,f]),oe=n.useCallback(()=>{var x;if(!r)return;((x=navigator.clipboard)!=null&&x.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(L=>{var D;L&&r.paste(L),(D=r.clearSelection)==null||D.call(r),r.focus()}).catch(()=>{Me.error(f("terminal.pasteFailed"))})},[r,f]),he=n.useCallback(()=>{var d;(d=r==null?void 0:r.clearSelection)==null||d.call(r),r==null||r.focus()},[r]);return n.useImperativeHandle(O,()=>({write:d=>r==null?void 0:r.write(d),reset:()=>{r==null||r.reset(),q.current=!1},scrollToBottom:()=>r==null?void 0:r.scrollToBottom(),resize:(d,x)=>r==null?void 0:r.resize(d,x),getTerminal:()=>r??null,getSize:()=>r?{cols:Math.max(2,r.cols),rows:Math.max(2,r.rows)}:null,runPostSelectResize:()=>a(),scheduleResize:(d,x)=>C(d,x),calculateSizeFromContainer:()=>{var me,$,ee,_,V,ce,K,be,Ce,Se,Re,Ie,Le,_e,ue,Ae;const d=h.current,x=r,L=B.current;if(!d||!x)return null;const D=d.getBoundingClientRect();if(D.width===0||D.height===0)return null;const k=x._core;let ie;if(L)try{const ye=L.proposeDimensions();if(ye)ie=Math.max(2,ye.cols);else{const ze=((_=(ee=($=(me=k==null?void 0:k._renderService)==null?void 0:me.dimensions)==null?void 0:$.css)==null?void 0:ee.cell)==null?void 0:_.width)??9;ie=Math.max(2,Math.floor(D.width/ze))}}catch{const ye=((be=(K=(ce=(V=k==null?void 0:k._renderService)==null?void 0:V.dimensions)==null?void 0:ce.css)==null?void 0:K.cell)==null?void 0:be.width)??9;ie=Math.max(2,Math.floor(D.width/ye))}else{const ye=((Ie=(Re=(Se=(Ce=k==null?void 0:k._renderService)==null?void 0:Ce.dimensions)==null?void 0:Se.css)==null?void 0:Re.cell)==null?void 0:Ie.width)??9;ie=Math.max(2,Math.floor(D.width/ye))}const Ee=((Ae=(ue=(_e=(Le=k==null?void 0:k._renderService)==null?void 0:Le.dimensions)==null?void 0:_e.css)==null?void 0:ue.cell)==null?void 0:Ae.height)??17,Te=Math.max(2,Math.floor(D.height/Ee));return{cols:ie,rows:Te}},getPendingLocalSize:()=>Z.current,getCellSize:()=>{var L,D,k;const d=r==null?void 0:r._core,x=(k=(D=(L=d==null?void 0:d._renderService)==null?void 0:L.dimensions)==null?void 0:D.css)==null?void 0:k.cell;return!(x!=null&&x.width)||!(x!=null&&x.height)?null:{width:x.width,height:x.height}}}),[r,Z,a,C]),i.jsxs("div",{className:"flex h-full w-full flex-col",style:{backgroundColor:S.background},"data-terminal-engine":wt,children:[i.jsxs("div",{ref:h,className:"relative min-h-0 w-full flex-1",children:[i.jsx("div",{ref:P,className:"absolute inset-0"}),i.jsx(kn,{visible:G,canPaste:c==="direct"&&l&&!g,onCopy:X,onPaste:oe,onDismiss:he})]}),E]})});nt.displayName="Terminal";function Kn({window:t,currentPaneId:e,onSelectPane:s}){const{t:c}=ke();return i.jsxs(zt,{children:[i.jsxs(Dt,{"data-testid":"pane-switcher-button","aria-label":c("window.switchPane"),title:c("window.switchPane"),className:"relative inline-flex size-7 items-center justify-center rounded-[min(var(--radius-md),12px)] text-sm hover:bg-muted hover:text-foreground data-popup-open:bg-muted",children:[i.jsx(yn,{className:"h-4 w-4"}),i.jsx("span",{className:"absolute -right-0.5 -top-0.5 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-primary px-0.5 text-[9px] font-medium leading-none text-primary-foreground",children:t.panes.length})]}),i.jsx($t,{align:"end",backdrop:!0,className:"min-w-56 max-w-[80vw]","data-testid":"pane-switcher-menu",children:t.panes.map(l=>{const g=l.id===e;return i.jsxs(Bt,{"data-testid":"pane-switcher-item","data-pane-id":l.id,className:`py-2 [@media(any-pointer:coarse)]:py-2.5 ${g?"bg-primary/10 text-primary":l.active?"bg-accent text-accent-foreground":""}`,onClick:()=>{g||s(l.id)},children:[i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"font-mono text-[11px] leading-tight font-medium line-clamp-2 [overflow-wrap:break-word]",children:l.customName||l.title||c("window.pane")}),l.currentCommand&&i.jsx("span",{className:"font-mono text-[10.5px] leading-tight text-muted-foreground line-clamp-1 break-all",children:l.currentPath?`${l.currentCommand}@${l.currentPath}`:l.currentCommand})]}),g&&i.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-primary"})]},l.id)})})]})}function Gn(t,e){return dt(s=>{for(const c of Object.values(s.sessions))if(!(!c||c.deviceId!==t||c.paneId!==e)&&!(c.status==="stopped"||c.status==="error")){if(c.status==="running"){const l=s.inProgress[c.id];return l&&(l.texts.length>0||l.toolCalls.length>0||l.reasonings.length>0),"generating"}return"bound"}return"none"})}function Ge(t){return t.type==="leaf"?t:t.type==="row"?Ge(t.children[t.children.length-1]):Ge(t.children[0])}function Qe(t){return t.type==="leaf"?t:t.type==="column"?Qe(t.children[t.children.length-1]):Qe(t.children[0])}function Qn(t,e){const s=[],c=[],l=g=>{if(g.type==="leaf"){s.push({paneId:Ue(g),cols:g.width,rows:g.height,rect:{left:g.x*e.width,top:g.y*e.height,width:g.width*e.width,height:g.height*e.height}});return}for(let v=0;v<g.children.length;v+=1){const b=g.children[v];if(l(b),v!==g.children.length-1)if(g.type==="row"){const T=Ge(b);c.push({axis:"x",rect:{left:(b.x+b.width)*e.width,top:g.y*e.height,width:e.width,height:g.height*e.height},edgeLeafPaneId:Ue(T)})}else{const T=Qe(b);c.push({axis:"y",rect:{left:g.x*e.width,top:(b.y+b.height)*e.height,width:g.width*e.width,height:e.height},edgeLeafPaneId:Ue(T)})}}};return l(t),{panes:s,gutters:c}}function We(t){if(t.type==="leaf")return 1;if(t.type==="column"){let s=0;for(const c of t.children)s+=We(c);return s}let e=1;for(const s of t.children)e=Math.max(e,We(s));return e}function He(t){if(t.type==="leaf")return 1;if(t.type==="row"){let s=0;for(const c of t.children)s+=He(c);return s}let e=1;for(const s of t.children)e=Math.max(e,He(s));return e}function Jn(t,e){const s=We(t),c=He(t),l=Math.max(0,e.viewport.width-c*e.paneChrome.width),g=Math.max(0,e.viewport.height-s*e.paneChrome.height),v=Math.max(2,Math.floor(l/e.cell.width)),b=Math.max(2,Math.floor(g/e.cell.height));return{cols:v,rows:b}}function Zn(t,e){const s=Math.min(1,Math.max(0,t)),c=Math.min(1,Math.max(0,e)),l=[["left",s],["right",1-s],["top",c],["bottom",1-c]];return l.sort((g,v)=>g[1]-v[1]),l[0][0]}const ct=150,er=200,tr=15,nr=46,rr=38,sr=12,or=6;function at(t){var e,s;return((e=t==null?void 0:t.customName)==null?void 0:e.trim())||((s=t==null?void 0:t.title)==null?void 0:s.trim())||"Pane"}function ir(t){var c,l;const e=(c=t==null?void 0:t.currentCommand)==null?void 0:c.trim();if(!e)return null;const s=(l=t==null?void 0:t.currentPath)==null?void 0:l.trim();return s?`${e}@${s}`:e}function cr({paneId:t}){return Je(s=>!!s.ringingPanes[t])?i.jsx("span",{className:"bell-blink shrink-0",children:"🔔 "}):null}function ar({deviceId:t,paneId:e}){const{t:s}=ke(),c=Gn(t,e);return c==="none"?null:c==="generating"?i.jsxs("span",{className:"shrink-0 select-none text-xs",title:s("agent.paneBadge.generating"),"aria-label":s("agent.paneBadge.generating"),children:["🤖",i.jsx("span",{className:"ml-0.5 text-[10px] animate-pulse",children:"✨"})]}):i.jsx("span",{className:"text-muted-foreground/60 shrink-0 select-none text-xs grayscale",title:s("agent.paneBadge.bound"),"aria-label":s("agent.paneBadge.bound"),children:"🤖"})}const lr={left:"left-0 top-0 bottom-0 w-1/2",right:"right-0 top-0 bottom-0 w-1/2",top:"left-0 right-0 top-0 h-1/2",bottom:"left-0 right-0 bottom-0 h-1/2"};function ur({deviceId:t,window:e,focusedPaneId:s,theme:c,inputMode:l,deviceConnected:g,focusedTerminalRef:v,onUserSelectPane:b,onWindowResize:T}){var Q,Z,C;const Y=n.useRef(null),U=n.useRef(new Map),[E,O]=n.useState(null),[r,ae]=n.useState(null),{t:G}=ke(),j=W(a=>a.subscribePanes),le=W(a=>a.fetchPaneHistory),se=W(a=>a.resizePaneInWindow),de=W(a=>a.movePane),re=W(a=>a.breakPane),f=W(a=>a.closePane),S=n.useMemo(()=>{const a=new Map;for(const m of e.panes)a.set(m.id,m);return a},[e.panes]),h=n.useMemo(()=>e.layout?bn(e.layout):null,[e.layout]),P=n.useMemo(()=>h?Qn(h.root,{width:1,height:1}):null,[h]),B=n.useRef(P);B.current=P;const A=(h==null?void 0:h.root.width)??1,F=(h==null?void 0:h.root.height)??1,u=e.panes.map(a=>a.id).join(",");n.useEffect(()=>(j(t,u?u.split(","):[]),()=>{j(t,[])}),[t,u,j]);const N=n.useRef({key:"",fetched:new Set});n.useEffect(()=>{const a=`${t}:${e.id}`;N.current.key!==a&&(N.current={key:a,fetched:new Set});for(const m of u?u.split(","):[])N.current.fetched.has(m)||m!==s&&(N.current.fetched.add(m),le(t,m))},[t,e.id,u,s,le]),n.useEffect(()=>{var m,R;l!=="direct"||window.innerWidth<768||"ontouchstart"in window||(R=(m=U.current.get(s))==null?void 0:m.getTerminal())==null||R.focus()},[s,l]);const H=n.useCallback(()=>{var a;for(const m of[s,...U.current.keys()]){const R=(a=U.current.get(m))==null?void 0:a.getCellSize();if(R)return R}return null},[s]);n.useEffect(()=>{var a;if(P)for(const m of P.panes)(a=U.current.get(m.paneId))==null||a.resize(m.cols,m.rows)},[P]);const J=n.useMemo(()=>h?We(h.root):1,[h]),M=n.useMemo(()=>h?He(h.root):1,[h]),q=n.useCallback(()=>{const a=Y.current;if(!a||!h)return!1;const m=a.getBoundingClientRect();if(m.width<1||m.height<1)return!1;const R=H();if(!R)return!1;const{cols:y,rows:X}=Jn(h.root,{viewport:{width:m.width,height:m.height},cell:R,paneChrome:{width:sr,height:nr}});return T(y,X),!0},[H,h,T]),te=n.useRef(q);n.useEffect(()=>{te.current=q},[q]),n.useEffect(()=>{const a=Y.current;if(!a)return;let m=null,R=null,y=0;const X=()=>{if(te.current()){y=0;return}y<tr&&(y+=1,R=setTimeout(X,er))},oe=new ResizeObserver(()=>{m&&clearTimeout(m),m=setTimeout(X,ct)});return oe.observe(a),()=>{oe.disconnect(),m&&clearTimeout(m),R&&clearTimeout(R)}},[]),n.useEffect(()=>{const a=setTimeout(()=>{te.current()},ct);return()=>clearTimeout(a)},[J,M]);const we=n.useCallback((a,m,R)=>{R.preventDefault();const y=Y.current;if(!y)return;const X=R.clientX,oe=R.clientY,he=R.currentTarget;he.setPointerCapture(R.pointerId),O({gutterIndex:a,deltaPx:0});const d=k=>{const ie=m.axis==="x"?k.clientX-X:k.clientY-oe;O({gutterIndex:a,deltaPx:ie})},x=(k,ie)=>{if(he.removeEventListener("pointermove",d),he.removeEventListener("pointerup",L),he.removeEventListener("pointercancel",D),window.removeEventListener("pointerup",L),window.removeEventListener("pointercancel",D),O(null),!ie)return;const Ee=H();if(!Ee)return;const Te=m.axis==="x"?k.clientX-X:k.clientY-oe,me=m.axis==="x"?Ee.width:Ee.height;if(me<=0)return;const $=Math.round(Te/me);if($===0)return;const ee=y.querySelector(`[data-pane-id="${m.edgeLeafPaneId}"]`);if(!ee)return;const _=ee.getBoundingClientRect(),ce=(m.axis==="x"?Math.floor(_.width/me):Math.floor(_.height/me))+$;ce<2||(te.current(),se(t,m.edgeLeafPaneId,m.axis==="x"?{cols:ce}:{rows:ce}))},L=k=>x(k,!0),D=k=>x(k,!1);he.addEventListener("pointermove",d),window.addEventListener("pointerup",L),window.addEventListener("pointercancel",D)},[t,H,se]),fe=n.useCallback((a,m)=>{const R=Y.current,y=P;if(!R||!y)return;m.preventDefault();const X=m.clientX,oe=m.clientY,he=m.currentTarget;he.setPointerCapture(m.pointerId);let d=!1;const x=($,ee)=>{const _=R.getBoundingClientRect();if(_.width<1||_.height<1)return null;const V=($-_.left)/_.width*Math.max(1,A),ce=(ee-_.top)/_.height*Math.max(1,F);for(const K of y.panes)if(V>=K.rect.left&&V<=K.rect.left+K.rect.width&&ce>=K.rect.top&&ce<=K.rect.top+K.rect.height){const be=(V-K.rect.left)/Math.max(1e-6,K.rect.width),Ce=(ce-K.rect.top)/Math.max(1e-6,K.rect.height);return{paneId:K.paneId,position:Zn(be,Ce)}}return null},L=($,ee,_)=>$>=_.left&&$<=_.right&&ee>=_.top&&ee<=_.bottom,D=($,ee)=>{for(const _ of Array.from(document.querySelectorAll('[data-testid^="window-item-"]'))){const V=_.getBoundingClientRect();if(V.width<1||!L($,ee,V))continue;const ce=(_.getAttribute("data-testid")??"").replace("window-item-","");return!ce||ce===e.id?null:{type:"window",windowId:ce,rect:{left:V.left,top:V.top,width:V.width,height:V.height}}}for(const _ of Array.from(document.querySelectorAll('[data-slot="sidebar"]'))){const V=_.getBoundingClientRect();if(!(V.width<1||!L($,ee,V)))return{type:"break",rect:{left:V.left,top:V.top,width:V.width,height:V.height}}}return null},k=($,ee)=>{const _=x($,ee);return _?_.paneId===a?null:{type:"pane",..._}:D($,ee)},ie=$=>{const ee=Math.hypot($.clientX-X,$.clientY-oe);!d&&ee<or||(d=!0,ae({srcPaneId:a,active:!0,pointerX:$.clientX,pointerY:$.clientY,target:k($.clientX,$.clientY)}))},Ee=($,ee)=>{var V,ce;if(he.removeEventListener("pointermove",ie),he.removeEventListener("pointerup",Te),he.removeEventListener("pointercancel",me),window.removeEventListener("pointerup",Te),window.removeEventListener("pointercancel",me),ae(null),!ee||!d)return;const _=k($.clientX,$.clientY);if(_){if(_.type==="pane"){de(t,a,_.paneId,_.position);return}if(_.type==="window"){const K=(ce=(V=W.getState().snapshots[t])==null?void 0:V.session)==null?void 0:ce.windows,be=K==null?void 0:K.find(Se=>Se.id===_.windowId),Ce=(be==null?void 0:be.panes.find(Se=>Se.active))??(be==null?void 0:be.panes[0]);Ce&&de(t,a,Ce.id,"right");return}re(t,a)}},Te=$=>Ee($,!0),me=$=>Ee($,!1);he.addEventListener("pointermove",ie),window.addEventListener("pointerup",Te),window.addEventListener("pointercancel",me)},[t,P,de,re,A,F,e.id]),pe=n.useCallback(a=>m=>{var R;if(m){U.current.set(a,m);const y=(R=B.current)==null?void 0:R.panes.find(X=>X.paneId===a);y&&m.resize(y.cols,y.rows)}else U.current.delete(a);a===s&&v(m)},[s,v]);if(n.useEffect(()=>{v(U.current.get(s)??null)},[s,v]),!P)return null;const z=(a,m)=>`${a/Math.max(1,m)*100}%`;return i.jsxs("div",{ref:Y,className:"relative h-full w-full min-h-0 min-w-0","data-testid":"split-terminal-area",children:[P.panes.map(a=>{var he;const m=a.paneId===s,R=S.get(a.paneId),y=ir(R),X=(r==null?void 0:r.active)&&r.srcPaneId===a.paneId,oe=r!=null&&r.active&&((he=r.target)==null?void 0:he.type)==="pane"&&r.target.paneId===a.paneId?r.target.position:null;return i.jsxs("div",{className:`absolute flex flex-col overflow-hidden ${X?"opacity-60":""}`,"data-testid":"split-pane","data-pane-id":a.paneId,"data-focused":m||void 0,style:{left:z(a.rect.left,A),top:z(a.rect.top,F),width:z(a.rect.width,A),height:z(a.rect.height,F)},onPointerDownCapture:()=>{m||b(e.id,a.paneId)},children:[i.jsx("div",{className:"shrink-0 px-1.5 pt-1.5 pb-2",style:{height:rr},children:i.jsxs("div",{"data-testid":"split-pane-titlebar","data-active":m||void 0,className:`flex h-6 cursor-grab touch-none select-none items-center gap-1.5 rounded-md px-2.5 transition-colors active:cursor-grabbing ${m?"bg-foreground/10":"bg-foreground/[0.04]"}`,onPointerDown:d=>fe(a.paneId,d),children:[i.jsx(cr,{paneId:a.paneId}),i.jsx(ar,{deviceId:t,paneId:a.paneId}),i.jsx("span",{className:`shrink-0 truncate font-mono text-[10.5px] leading-none ${m?"text-foreground/90":"text-foreground/50"}`,children:at(R)}),y&&i.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-[10px] leading-none ${m?"text-muted-foreground":"text-muted-foreground/60"}`,children:y}),i.jsx("button",{type:"button","data-testid":`split-pane-close-${a.paneId}`,"aria-label":G("window.closePane"),title:G("window.closePane"),className:"ml-auto flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground/50 hover:bg-foreground/10 hover:text-foreground",onPointerDown:d=>d.stopPropagation(),onClick:d=>{d.stopPropagation(),f(t,a.paneId)},children:i.jsx("span",{className:"text-xs leading-none",children:"×"})})]})}),i.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden px-1.5 pb-2","data-pane-content-id":a.paneId,children:i.jsx(nt,{ref:pe(a.paneId),deviceId:t,paneId:a.paneId,theme:c,inputMode:l,deviceConnected:g,isSelectionInvalid:!1,sizingMode:"follow",autoFocus:m,focused:m,onResize:()=>{},onSync:()=>{}},`${t}:${a.paneId}`)}),oe&&i.jsx("div",{"data-testid":"split-pane-drop-preview","data-position":oe,className:`pointer-events-none absolute z-30 rounded-sm bg-primary/20 ring-1 ring-inset ring-primary/60 ${lr[oe]}`})]},a.paneId)}),(E!==null||(r==null?void 0:r.active))&&i.jsx("div",{"data-testid":"split-drag-shield",className:`absolute inset-0 z-30 ${E!==null?((Q=P.gutters[E.gutterIndex])==null?void 0:Q.axis)==="x"?"cursor-col-resize":"cursor-row-resize":"cursor-grabbing"}`}),(r==null?void 0:r.active)&&r.target&&r.target.type!=="pane"&&i.jsx("div",{"data-testid":"split-pane-sidebar-drop","data-drop-type":r.target.type,className:"pointer-events-none fixed z-40 rounded-lg bg-primary/15 ring-1 ring-inset ring-primary/50",style:{left:r.target.rect.left,top:r.target.rect.top,width:r.target.rect.width,height:r.target.rect.height}}),(r==null?void 0:r.active)&&i.jsxs("div",{className:"pointer-events-none fixed z-50 rounded border border-primary/40 bg-popover/95 px-2 py-1 font-mono text-[10.5px] text-popover-foreground shadow-md",style:{left:r.pointerX+12,top:r.pointerY+12},children:[i.jsx("div",{children:at(S.get(r.srcPaneId))}),((Z=r.target)==null?void 0:Z.type)==="window"&&i.jsx("div",{className:"text-[9.5px] text-muted-foreground",children:G("window.moveToWindow")}),((C=r.target)==null?void 0:C.type)==="break"&&i.jsx("div",{className:"text-[9.5px] text-muted-foreground",children:G("window.breakToWindow")})]}),P.gutters.map((a,m)=>{const R=a.axis==="x",y=(E==null?void 0:E.gutterIndex)===m;return i.jsxs("div",{className:"absolute z-20",style:{left:z(a.rect.left,A),top:z(a.rect.top,F),width:z(R?1:a.rect.width,A),height:z(R?a.rect.height:1,F)},children:[i.jsx("div",{"data-testid":"split-gutter","data-axis":a.axis,className:`absolute touch-none select-none ${R?"-inset-x-1 inset-y-0 cursor-col-resize":"inset-x-0 -inset-y-1 cursor-row-resize"}`,onPointerDown:X=>we(m,a,X),children:i.jsx("div",{className:`absolute bg-foreground/[0.08] transition-colors hover:bg-primary/50 ${R?"inset-y-0 left-1/2 w-px -translate-x-1/2":"inset-x-0 top-1/2 h-px -translate-y-1/2"} ${y?"bg-primary":""}`})}),y&&E&&i.jsx("div",{className:"pointer-events-none absolute bg-primary/70",style:R?{top:0,bottom:0,width:2,left:`calc(50% + ${E.deltaPx}px)`}:{left:0,right:0,height:2,top:`calc(50% + ${E.deltaPx}px)`}})]},`${e.layout??""}:${m}`)})]})}const dr=1200,fr=2e3;function Pe(t,e){return!t||!e?!1:t.windowId===e.windowId&&t.paneId===e.paneId}function xt(t,e){const s=t.filter(c=>e-c.at<dr);return s.length===0?null:s.reduce((c,l)=>l.at>c.at?l:c)}function Fe(t,e=Date.now()){return!t||e-t.at>fr?null:t}function hr(t){const e=t.now??Date.now(),s=xt(t.recentSelectRequests,e),c=g=>!!(g&&g.paneId===t.activePaneFromEvent.paneId&&g.windowId!==t.activePaneFromEvent.windowId);if(s&&!Pe(s,t.activePaneFromEvent)&&!c(s)||Pe(t.currentRoute,t.activePaneFromEvent)||Pe(t.lastHandledActive,t.activePaneFromEvent))return!0;const l=Fe(t.pendingUserSelection,e);return!!(l&&!Pe(l,t.activePaneFromEvent)&&!c(l))}function mr(t){const e=t.now??Date.now(),s=xt(t.recentSelectRequests,e),c=Fe(t.pendingUserSelection,e);return!!(c&&!Pe(c,t.snapshotActive)||s&&!Pe(s,t.snapshotActive))}function wr(t){const e=t.now??Date.now(),s=Fe(t.pendingUserSelection,e);return!(s&&Pe(s,t.routeTarget)||t.snapshotActive&&Pe(t.snapshotActive,t.routeTarget))}const Ve=n.memo(function({onActivate:e,disabled:s}){const{data:c}=tt({queryKey:mn,queryFn:hn,staleTime:6e4}),l=(c==null?void 0:c.items)??[];return l.length===0?null:i.jsx("div",{className:"terminal-shortcuts-strip","data-testid":"terminal-shortcuts-strip",children:i.jsx(wn,{items:l,useIcons:(c==null?void 0:c.useIcons)??!1,onActivate:e,disabled:s,preventFocusSteal:!0,rowTestId:"terminal-shortcuts-row",idPrefix:"terminal-shortcut"})})});function Sr(){var ot;const{t}=ke(),{deviceId:e,windowId:s,paneId:c}=Ze(),l=ft(),g=n.useRef(null),v=n.useRef(null),b=n.useRef(null),T=n.useRef(null),Y=n.useRef(!1),U=n.useRef(!1),E=n.useRef(null),O=W(o=>o.selectPane),r=W(o=>o.focusPane),ae=W(o=>e?o.snapshots[e]:void 0),G=W(o=>{var w;return e?(w=o.deviceErrors)==null?void 0:w[e]:void 0}),j=W(o=>{var w;return e?((w=o.deviceConnected)==null?void 0:w[e])??!1:!1}),se=!!W(o=>{var w;return e?(w=o.deviceReconnecting)==null?void 0:w[e]:void 0}),de=W(o=>e?o.connectedDevices.has(e):!1),re=ht(o=>{var w;return((w=o.settings)==null?void 0:w.siteName)??"tmex"}),f=n.useMemo(()=>et(c),[c]),S=n.useMemo(()=>e&&f?`${e}:${f}`:null,[e,f]),[h,P]=n.useState(!1),B=n.useRef(!1);n.useEffect(()=>{B.current=h},[h]);const[A,F]=n.useState(""),u=n.useRef(!1),N=!j||!f,[H,J]=n.useState(!1),M=ge(o=>o.inputMode),q=ge(o=>o.theme),te=ge(o=>o.editorSendWithEnter),we=ge(o=>o.setEditorSendWithEnter),fe=ge(o=>o.addEditorHistory),pe=ge(o=>o.setEditorDraft),z=ge(o=>o.removeEditorDraft),Q=ge(o=>S?o.editorDrafts[S]??"":""),Z=n.useMemo(()=>Ft(),[]),C=(ot=ae==null?void 0:ae.session)==null?void 0:ot.windows,a=q==="light"?ut:lt,{data:m}=tt({queryKey:["devices"],queryFn:async()=>{const o=await fetch("/api/devices");if(!o.ok)throw new Error("Failed to fetch devices");return o.json()},throwOnError:!1}),R=n.useMemo(()=>{if(e)return m==null?void 0:m.devices.find(o=>o.id===e)},[e,m==null?void 0:m.devices]),y=n.useMemo(()=>{if(!(!s||!C))return C.find(o=>o.id===s)},[s,C]),X=n.useMemo(()=>{if(!(!f||!y))return y.panes.find(o=>o.id===f)},[f,y]),oe=!!C,x=oe&&!!s&&!y?t("terminal.windowClosed"):oe&&!!s&&!!f&&!!y&&!X?t("terminal.paneClosed"):null,L=!!x,D=!!(j&&f&&!L),k=!!(!h&&y&&y.panes.length>1&&y.layout&&!L),ie=n.useRef(k);n.useEffect(()=>{ie.current=k},[k]);const Ee=Je(o=>o.ringingPanes),Te=n.useMemo(()=>{if(!y||!X)return null;const o=(R==null?void 0:R.name)??e,w=mt({paneCustomName:X.customName,paneTitle:X.title,windowName:y.name,windowCustomName:y.customName,deviceName:o});return Ee[X.id]?`🔔 ${w}`:w},[R==null?void 0:R.name,e,X,y,Ee]),me=n.useMemo(()=>{if(!C||C.length===0)return null;const o=C.find(p=>p.active),w=o==null?void 0:o.panes.find(p=>p.active);return!o||!w?null:{windowId:o.id,paneId:w.id}},[C]),$=h&&y&&y.panes.length>1?y.id:null,ee=n.useRef($);n.useEffect(()=>{ee.current=$},[$]);const _=n.useRef(!1);n.useEffect(()=>{_.current=!!C&&!!s},[C,s]);const V=n.useCallback((o,w)=>{if(!e||!f)return;const p=ee.current;if(p){W.getState().applyStackedLayout(e,p,o,w);return}B.current&&!_.current||W.getState().resizePane(e,f,o,w)},[e,f]),ce=n.useCallback((o,w)=>{if(!e||!f)return;const p=ee.current;if(p){W.getState().applyStackedLayout(e,p,o,w);return}B.current&&!_.current||W.getState().syncPaneSize(e,f,o,w)},[e,f]),K=n.useCallback((o,w)=>{var De;const p=T.current;if(ie.current){const ve=(De=g.current)==null?void 0:De.getBoundingClientRect(),qe=p==null?void 0:p.getCellSize();return ve&&qe&&ve.width>0&&ve.height>0?{cols:Math.max(2,Math.floor(ve.width/qe.width)),rows:Math.max(2,Math.floor(ve.height/qe.height))}:void 0}if(B.current)return;const I=(p==null?void 0:p.calculateSizeFromContainer())??(p==null?void 0:p.getSize())??void 0;if(I)return I;if(!o||!w||!C)return;const ne=C.find(ve=>ve.id===o),xe=ne==null?void 0:ne.panes.find(ve=>ve.id===w);if(!(!xe||xe.width<=1||xe.height<=1))return{cols:xe.width,rows:xe.height}},[C]),be=n.useCallback((o,w)=>{e&&(E.current={windowId:o,paneId:w,at:Date.now()},l(`/devices/${e}/windows/${o}/panes/${Ne(w)}`,{replace:!0}))},[e,l]),Ce=n.useCallback(o=>{T.current=o},[]);n.useEffect(()=>{const o=()=>{P(window.innerWidth<768||"ontouchstart"in window)};return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),n.useEffect(()=>{if(!h||!Z||U.current)return;U.current=!0;const o=()=>{window.scrollTo(0,1)},w=window.requestAnimationFrame(o),p=window.setTimeout(o,120),I=window.setTimeout(o,420);return()=>{window.cancelAnimationFrame(w),window.clearTimeout(p),window.clearTimeout(I)}},[Z,h]),n.useEffect(()=>{e&&(Y.current=!1,Ae.current=null,ye.current=null,E.current=null,Se.current=[])},[e]),n.useEffect(()=>{j||(Y.current=!1)},[j]),n.useEffect(()=>{if(!e||!j||!s||!C)return;if(C.length===0){l("/devices",{replace:!0});return}const o=C.find(p=>p.id===s);if(!o)return;if(!f){const p=o.panes.find(I=>I.active)??o.panes[0];p&&l(`/devices/${e}/windows/${s}/panes/${Ne(p.id)}`,{replace:!0});return}if(!o.panes.find(p=>p.id===f)){const p=C.find(ne=>ne.panes.some(xe=>xe.id===f));if(p){l(`/devices/${e}/windows/${p.id}/panes/${Ne(f)}`,{replace:!0});return}const I=o.panes.find(ne=>ne.active)??o.panes[0];I&&l(`/devices/${e}/windows/${s}/panes/${Ne(I.id)}`,{replace:!0});return}},[e,j,C,s,f,l]),n.useEffect(()=>{if(!e||!j||!C||C.length===0||s&&f||Y.current)return;const o=C.find(p=>p.active)??C[0],w=o.panes.find(p=>p.active)??o.panes[0];w&&(Y.current=!0,l(`/devices/${e}/windows/${o.id}/panes/${Ne(w.id)}`,{replace:!0}))},[j,e,l,f,s,C]);const Se=n.useRef([]),Re=n.useCallback((o,w)=>{const p=Date.now(),I=[...Se.current.filter(ne=>p-ne.at<2e3),{windowId:o,paneId:w,at:p}];Se.current=I.slice(-8)},[]),Ie=n.useRef(null);n.useEffect(()=>{Ie.current=null},[e,f]);const Le=n.useRef(null),_e=n.useRef(k);n.useEffect(()=>{_e.current!==k&&(_e.current=k,Ie.current=null,Le.current=null)},[k]),n.useEffect(()=>{if(!e||!s||!f||N||!j)return;const o=`${e}:${s}:${f}`;if(Ie.current===o)return;Ie.current=o;const w=k&&Le.current===`${e}:${s}`&&!!(y!=null&&y.panes.some(I=>I.id===f));if(Re(s,f),w){r(e,s,f);return}const p=K(s,f);O(e,s,f,p),Le.current=`${e}:${s}`},[j,e,r,K,N,k,Re,f,O,y,s]),n.useEffect(()=>{if(!e||!j||!s||!f)return;const o={windowId:s,paneId:f};wr({routeTarget:o,snapshotActive:me,pendingUserSelection:E.current})&&(E.current={windowId:o.windowId,paneId:o.paneId,at:Date.now()})},[j,e,f,me,s]);const ue=W(o=>e?o.activePaneFromEvent[e]:void 0),Ae=n.useRef(null);n.useEffect(()=>{if(!e||!j||!s||!f||!ue)return;const o=Date.now(),w=Fe(E.current,o);if(E.current=w,hr({now:o,pendingUserSelection:w,activePaneFromEvent:ue,currentRoute:{windowId:s,paneId:f},recentSelectRequests:Se.current,lastHandledActive:Ae.current}))return;if(Ae.current={...ue},w&&w.windowId===ue.windowId&&w.paneId===ue.paneId&&(E.current=null),!(ie.current&&ue.windowId===s)){const I=K(ue.windowId,ue.paneId);Re(ue.windowId,ue.paneId),O(e,ue.windowId,ue.paneId,I)}l(`/devices/${e}/windows/${ue.windowId}/panes/${Ne(ue.paneId)}`,{replace:!0})},[e,j,s,f,ue,Re,K,O,l]);const ye=n.useRef(null);n.useEffect(()=>{if(!e||!j||!C||C.length===0)return;const o=Se.current,w=C.find(ve=>ve.active);if(!w)return;const p=w.panes.find(ve=>ve.active);if(!p)return;const I={windowId:w.id,paneId:p.id},ne=Date.now(),xe=Fe(E.current,ne);if(E.current=xe,mr({now:ne,pendingUserSelection:xe,snapshotActive:I,recentSelectRequests:o})||ye.current&&ye.current.windowId===I.windowId&&ye.current.paneId===I.paneId||(ye.current={...I},xe&&xe.windowId===I.windowId&&xe.paneId===I.paneId&&(E.current=null),s===I.windowId&&f===I.paneId))return;if(!(ie.current&&I.windowId===s)){const ve=K(I.windowId,I.paneId);Re(I.windowId,I.paneId),O(e,I.windowId,I.paneId,ve)}l(`/devices/${e}/windows/${I.windowId}/panes/${Ne(I.paneId)}`,{replace:!0})},[e,j,C,s,f,Re,K,O,l]);const ze=W(o=>e?o.pendingCreateWindowAt[e]:void 0);n.useEffect(()=>{if(!e||!j||!ze)return;const o=5e3,w=Date.now()-ze;if(w>o){W.getState().clearPendingCreateWindow(e);return}if(!me){const ne=window.setTimeout(()=>{W.getState().clearPendingCreateWindow(e)},o-w);return()=>window.clearTimeout(ne)}const p=me;if(s===p.windowId&&f===p.paneId){const ne=window.setTimeout(()=>{W.getState().clearPendingCreateWindow(e)},o-w);return()=>window.clearTimeout(ne)}E.current={windowId:p.windowId,paneId:p.paneId,at:Date.now()};const I=K(p.windowId,p.paneId);Re(p.windowId,p.paneId),O(e,p.windowId,p.paneId,I),l(`/devices/${e}/windows/${p.windowId}/panes/${Ne(p.paneId)}`,{replace:!0}),W.getState().clearPendingCreateWindow(e)},[e,j,ze,me,s,f,Re,K,O,l]),n.useEffect(()=>{if(k||!D||!X||N)return;const o=T.current,w=o==null?void 0:o.getTerminal();if(!w)return;const p=Math.max(2,Math.floor(X.width||0)),I=Math.max(2,Math.floor(X.height||0));if(!p||!I)return;const ne=Date.now(),xe={cols:p,rows:I},De=(o==null?void 0:o.getPendingLocalSize())??null;Bn({now:ne,remoteSize:xe,pendingLocalSize:De})&&(w.cols===p&&w.rows===I||w.resize(p,I))},[D,N,k,X]),n.useEffect(()=>{const o=window.requestAnimationFrame(()=>{var p;(p=T.current)==null||p.scrollToBottom()}),w=window.setTimeout(()=>{var p;(p=T.current)==null||p.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(o),window.clearTimeout(w)}},[M]),n.useEffect(()=>{G!=null&&G.message&&Me.error(G.message)},[G==null?void 0:G.message]),n.useEffect(()=>(document.title=Wt(Te),()=>{document.title=re}),[re,Te]),n.useEffect(()=>{const o=()=>{var w;(w=T.current)==null||w.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",o),()=>{window.removeEventListener("tmex:jump-to-latest",o)}},[]),n.useEffect(()=>{const o=w=>{const{deviceId:p,windowId:I,paneId:ne}=w.detail;p===e&&(E.current={windowId:I,paneId:ne,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",o),()=>{window.removeEventListener("tmex:user-initiated-selection",o)}},[e]),n.useEffect(()=>{F(Q)},[Q]);const rt=n.useCallback(o=>{if(!e||!f||!D)return;W.getState().sendInput(e,f,o,!1)},[D,e,f]),Xe=n.useCallback(o=>{var w,p;if(o.type==="action"){if(o.action==="toggleKeyboard"){ge.getState().setInputMode(M==="direct"?"editor":"direct");return}if(o.action==="scrollToBottom"){(w=T.current)==null||w.scrollToBottom();return}}if(o.type==="send"){o.payload&&rt(o.payload);return}if(!(!e||!f||!D))switch(o.action){case"paste":{((p=navigator.clipboard)!=null&&p.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(ne=>{ne&&W.getState().paste(e,f,ne)}).catch(()=>Me.error(t("terminal.pasteFailed")));break}case"newAgentSession":dt.getState().startDraft(e,f,null),ge.getState().setSidebarCollapsed(!1),ge.getState().setSidebarTab("agent");break}},[D,e,rt,M,f,t]),vt=n.useCallback(()=>{if(!D){Me.error(t("wsError.checkGateway"));return}if(!e||!f||!A.trim())return;J(!0),window.setTimeout(()=>J(!1),150);const o=te?`${A}\r`:A;W.getState().sendInput(e,f,o,!1),fe(A),S&&z(S),F("")},[fe,D,e,S,te,A,z,f,t]),bt=n.useCallback(()=>{if(!D){Me.error(t("wsError.checkGateway"));return}if(!e||!f||!A.trim())return;J(!0),window.setTimeout(()=>J(!1),150);const o=A.split(/\r?\n/),w=W.getState();for(const p of o)p.trim()&&w.sendInput(e,f,`${p}\r`,!1);fe(A),S&&z(S),F("")},[fe,D,e,S,A,z,f,t]),St=n.useCallback(()=>{var o;(o=b.current)==null||o.focus({preventScroll:!0})},[]);if(!e)return i.jsx("div",{className:"flex h-full items-center justify-center p-4",children:i.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:t("device.noDevices")})});const yt=!!f&&!L&&(j||se),Et=j&&!!f&&!L&&!X,Rt=de&&!j&&!G&&!se,st=i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx(Ye,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),i.jsx("h3",{className:"text-lg font-medium",children:t("terminal.connecting")})]});return i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[i.jsx("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${h&&M==="editor"?"pb-1":""}`,children:i.jsxs("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:a.background},children:[L?i.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:i.jsxs("div",{className:"max-w-sm space-y-4",children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx(Rn,{className:"h-6 w-6 text-muted-foreground"})}),i.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"terminal-selection-invalid",children:x})]})}):yt&&f?k&&y?i.jsxs("div",{className:"flex h-full min-h-0 w-full flex-1 flex-col","data-virtual-keyboard-avoid":!0,children:[i.jsx("div",{ref:g,className:"relative min-h-0 flex-1",children:i.jsx(ur,{deviceId:e,window:y,focusedPaneId:f,theme:q,inputMode:M,deviceConnected:j,focusedTerminalRef:Ce,onUserSelectPane:be,onWindowResize:V},`${e}:${y.id}`)}),M==="direct"&&i.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:a.background},children:i.jsx(Ve,{onActivate:Xe,disabled:!D})})]}):i.jsx("div",{ref:g,className:"flex-1 h-full min-h-0 w-full","data-virtual-keyboard-avoid":!0,children:i.jsx(nt,{ref:T,deviceId:e,paneId:f,theme:q,inputMode:M,deviceConnected:j,isSelectionInvalid:L,onResize:V,onSync:ce,children:M==="direct"&&i.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:a.background},children:i.jsx(Ve,{onActivate:Xe,disabled:!D})})},`${e}:${f}`)}):i.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:i.jsx("div",{className:"max-w-sm space-y-4",children:Rt?st:!j&&!se?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),i.jsx("h3",{className:"text-lg font-medium",children:t("device.disconnected")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:t("device.connectToStart")})]}):s?st:i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:i.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),i.jsx("h3",{className:"text-lg font-medium",children:t("window.noWindowSelected")}),i.jsx("p",{className:"text-sm text-muted-foreground",children:t("window.selectWindowToStart")})]})})}),se&&i.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-2 z-10 flex justify-center","data-testid":"terminal-reconnecting-indicator",children:i.jsx(Ht,{deviceId:e,className:"shadow-sm"})}),Et&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:i.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:[i.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),i.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:t("terminal.connecting")})]})})]})}),M==="editor"&&i.jsxs("div",{ref:v,"data-virtual-keyboard-avoid":!0,className:"editor-mode-input bg-card/85 backdrop-blur-sm",children:[h&&i.jsx(Ve,{onActivate:o=>{Xe(o),o.type==="send"&&St()},disabled:!D}),i.jsx("textarea",{ref:b,"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:A,onChange:o=>{const w=o.target.value;if(F(w),!!S){if(w){pe(S,w);return}z(S)}},placeholder:t("terminal.inputPlaceholder"),onCompositionStart:()=>{u.current=!0},onCompositionEnd:()=>{u.current=!1}}),i.jsx("div",{className:"actions mt-2",children:i.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[i.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:[i.jsx(Ot,{size:"sm",checked:te,onCheckedChange:o=>we(!!o)}),i.jsx("span",{children:t("terminal.editorSendWithEnter")})]}),i.jsxs(je,{variant:"outline",size:"sm","data-testid":"editor-clear",onMouseDown:o=>o.preventDefault(),onClick:()=>{var o;F(""),S&&z(S),h&&M==="editor"&&((o=b.current)==null||o.focus({preventScroll:!0}))},title:t("terminal.clear"),children:[i.jsx(Xt,{className:"h-4 w-4"}),t("terminal.clear")]}),i.jsxs(je,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onMouseDown:o=>o.preventDefault(),onClick:()=>{var o;bt(),h&&M==="editor"&&((o=b.current)==null||o.focus({preventScroll:!0}))},disabled:!D||H,children:[H?i.jsx(Ye,{className:"h-4 w-4 animate-spin"}):i.jsx(it,{className:"h-4 w-4"}),t("terminal.editorSendLineByLine")]}),i.jsxs(je,{variant:"default",size:"sm","data-testid":"editor-send",onMouseDown:o=>o.preventDefault(),onClick:()=>{var o;vt(),h&&M==="editor"&&((o=b.current)==null||o.focus({preventScroll:!0}))},disabled:!D||H,children:[H?i.jsx(Ye,{className:"h-4 w-4 animate-spin"}):i.jsx(it,{className:"h-4 w-4"}),t("common.send")]})]})})]})]})}function yr(){const{deviceId:t,windowId:e,paneId:s}=Ze(),c=s?et(s):void 0,l=W(E=>E.snapshots),g=ht(E=>{var O;return((O=E.settings)==null?void 0:O.siteName)??"tmex"}),v=t?l[t]:void 0,b=n.useMemo(()=>{var E;if(!(!e||!((E=v==null?void 0:v.session)!=null&&E.windows)))return v.session.windows.find(O=>O.id===e)},[e,v]),T=n.useMemo(()=>{if(!(!c||!b))return b.panes.find(E=>E.id===c)},[c,b]),Y=n.useMemo(()=>b&&T?mt({paneCustomName:T.customName,paneTitle:T.title,windowName:b.name,windowCustomName:b.customName,deviceName:g}):t??"",[b,T,g,t]),U=Je(E=>c?!!E.ringingPanes[c]:!1);return i.jsxs(i.Fragment,{children:[U&&i.jsx("span",{className:"bell-blink",children:"🔔 "}),Y]})}function Er(){const{t}=ke(),{deviceId:e,windowId:s,paneId:c}=Ze(),l=ft(),g=qt(),v=c?et(c):void 0,b=ge(u=>u.inputMode),T=ge(u=>u.setInputMode),Y=W(u=>{var N;return e?((N=u.deviceConnected)==null?void 0:N[e])??!1:!1}),U=W(u=>e?u.snapshots[e]:void 0),E=n.useMemo(()=>{var u;if(!(!s||!((u=U==null?void 0:U.session)!=null&&u.windows)))return U.session.windows.find(N=>N.id===s)},[s,U]),O=n.useCallback(u=>{!e||!s||l(`/devices/${e}/windows/${s}/panes/${Ne(u)}`,{replace:!0})},[e,s,l]),r=n.useMemo(()=>{if(!(!v||!E))return E.panes.find(u=>u.id===v)},[v,E]),ae=n.useCallback(u=>{!e||!v||W.getState().splitPane(e,v,u,r==null?void 0:r.currentPath)},[e,v,r==null?void 0:r.currentPath]),[G,j]=n.useState(!1),[le,se]=n.useState(!1),[de,re]=n.useState(!1),f=!!(v&&Y),h=(tt({queryKey:Ut(e??"",v??""),queryFn:()=>Yt(e??"",v??""),enabled:!!(e&&v),throwOnError:!1}).data??[]).some(u=>u.enabled),P=()=>{T(b==="direct"?"editor":"direct")},B=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},A=()=>{j(!0)},F=()=>{window.location.reload()};return i.jsxs(i.Fragment,{children:[g&&v&&E&&E.panes.length>1&&i.jsx(Kn,{window:E,currentPaneId:v,onSelectPane:O}),!g&&i.jsxs(i.Fragment,{children:[i.jsx(je,{variant:"ghost",size:"icon-sm",onClick:()=>ae("right"),disabled:!f,"data-testid":"split-right-button","aria-label":t("window.splitRight"),title:t("window.splitRight"),children:i.jsx(Vt,{className:"h-4 w-4"})}),i.jsx(je,{variant:"ghost",size:"icon-sm",onClick:()=>ae("down"),disabled:!f,"data-testid":"split-down-button","aria-label":t("window.splitDown"),title:t("window.splitDown"),children:i.jsx(Kt,{className:"h-4 w-4"})})]}),i.jsx(je,{variant:"ghost",size:"icon-sm",onClick:A,"aria-label":t("nav.refreshPage"),title:t("nav.refreshPage"),children:i.jsx(dn,{className:"h-4 w-4"})}),i.jsx(je,{variant:"ghost",size:"icon-sm",onClick:P,disabled:!f,"data-testid":"terminal-input-mode-toggle","aria-label":t(b==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:t(b==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:b==="direct"?i.jsx(xn,{className:"h-4 w-4"}):i.jsx(Nn,{className:"h-4 w-4"})}),i.jsx(je,{variant:"ghost",size:"icon-sm",onClick:B,disabled:!f,"aria-label":t("nav.jumpToLatest"),title:t("nav.jumpToLatest"),children:i.jsx(fn,{className:"h-4 w-4"})}),i.jsxs(je,{variant:"ghost",size:"icon-sm",className:"relative",onClick:()=>se(!0),disabled:!v,"data-testid":"watch-open-button","aria-label":t("watch.title"),title:t("watch.title"),children:[i.jsx(Gt,{className:"h-4 w-4"}),h&&i.jsx("span",{className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-primary","data-testid":"watch-active-indicator"})]}),i.jsx(je,{variant:"ghost",size:"icon-sm",onClick:()=>re(!0),"data-testid":"keyboard-behavior-open-button","aria-label":t("settings.terminal.title"),title:t("settings.terminal.title"),children:i.jsx(jn,{className:"h-4 w-4"})}),i.jsx(Pn,{open:de,onOpenChange:re}),e&&v&&i.jsx(Qt,{open:le,onOpenChange:se,deviceId:e,paneId:v}),i.jsx(Jt,{open:G,onOpenChange:j,children:i.jsxs(Zt,{children:[i.jsxs(en,{children:[i.jsx(tn,{children:t("nav.refreshPage")}),i.jsx(nn,{children:t("nav.refreshPageConfirm")})]}),i.jsxs(rn,{children:[i.jsx(sn,{onClick:()=>j(!1),children:t("common.cancel")}),i.jsx(on,{onClick:F,children:t("common.confirm")})]})]})})]})}export{Er as PageActions,yr as PageTitle,Sr as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as b,r as v,a as _,b as ie,c as re,d as ne,e as I,t as oe,j as s,M as X,B as C,P as Y,A as ce,f as de,g as le,h as ue,T as ee,i as me,k as he,l as pe,m as xe,n as ve,G as fe,o as f,D as ge,p as ye,E as je,q as we,s as $,v as Ne,w as De,x as Q,y as Ce,S as be,L as Se,z as ke,C as Ee,F as Me,H as Pe,I as Ie,J as Ke,K as x,N as z,O as V,Q as U,R as J,U as w,V as Re,W as $e}from"./index-BK6c5W5S.js";import{C as M,a as P,b as Ae,c as Te,d as Fe}from"./card-BA66zlg1.js";import{Z as We}from"./zap-DxVtkroR.js";function g(e){const o=e.trim();return o||void 0}function qe(e){return e?{name:e.name,type:e.type,host:e.host??"",port:e.port??22,username:e.username??"",sshConfigRef:e.sshConfigRef??"",session:e.session??"tmex",defaultWorkingDir:e.defaultWorkingDir??"",authMode:e.type==="local"?"auto":e.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"root",sshConfigRef:"",session:"tmex",defaultWorkingDir:"",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(e){if(e.type==="local")return{name:e.name.trim(),type:"local",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:"auto"};const o={name:e.name.trim(),type:"ssh",host:e.host.trim(),port:e.port,username:e.username.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:e.authMode};return e.authMode==="configRef"&&(o.sshConfigRef=e.sshConfigRef.trim()),e.authMode==="password"&&(o.password=e.password),e.authMode==="key"&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function He(e){if(e.type==="local")return{name:e.name.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:"auto"};const o={name:e.name.trim(),host:e.host.trim(),port:e.port,username:e.username.trim(),sshConfigRef:e.authMode==="configRef"?e.sshConfigRef.trim():"",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:e.authMode};return e.authMode==="password"&&e.password&&(o.password=e.password),e.authMode==="key"&&e.privateKey&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function se(e){return Number.isInteger(e)&&e>=1&&e<=65535}function Oe(e){return e.type!=="ssh"?null:e.host.trim()?se(e.port)?e.username.trim()?e.authMode==="configRef"&&!e.sshConfigRef.trim()?"validation.sshConfigRequired":null:"validation.usernameRequired":"validation.portRequired":"validation.hostRequired"}async function G(e,o){try{return(await e.json()).error??o}catch{return o}}function Ue(){const{t:e}=b(),[o,m]=v.useState(!1),[t,y]=v.useState(null),[r,d]=v.useState(null),l=_(),h=ie(n=>{var p;return((p=n.settings)==null?void 0:p.language)??"en_US"});v.useEffect(()=>{const n=()=>m(!0);return window.addEventListener("tmex:open-add-device",n),()=>window.removeEventListener("tmex:open-add-device",n)},[]);const{data:c,isLoading:K,isError:N}=re({queryKey:["devices"],queryFn:async()=>{const n=await fetch("/api/devices");if(!n.ok)throw new Error(e("device.loadFailed"));return n.json()},throwOnError:!1}),S=ne(n=>n.hydrateDeviceErrors);v.useEffect(()=>{c!=null&&c.devices&&S(c.devices.map(n=>({deviceId:n.id,lastError:n.lastError??null,lastErrorType:n.lastErrorType??null})))},[c,S]);const k=I({mutationFn:async n=>{if(!(await fetch(`/api/devices/${n}`,{method:"DELETE"})).ok)throw new Error(e("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),f.success(e("common.success"))},onError:n=>{f.error(n instanceof Error?n.message:e("common.error"))}}),E=v.useMemo(()=>[...(c==null?void 0:c.devices)??[]].sort((p,D)=>p.sortOrder-D.sortOrder||p.name.localeCompare(D.name,oe(h),{numeric:!0,sensitivity:"base"})),[c==null?void 0:c.devices,h]);return s.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:[K?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-muted-foreground",children:e("common.loading")})}):N?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-destructive",children:e("device.loadFailed")})}):E.length===0?s.jsx(M,{children:s.jsxs(P,{className:"space-y-4 py-14 text-center",children:[s.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:s.jsx(X,{className:"h-6 w-6 text-muted-foreground"})}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-medium",children:e("device.noDevices")}),s.jsx("p",{className:"text-sm text-muted-foreground",children:e("device.addDevice")})]}),s.jsxs(C,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[s.jsx(Y,{className:"h-4 w-4"}),e("device.addDevice")]})]})}):s.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:E.map(n=>s.jsx(Be,{device:n,onEdit:()=>y(n),onDelete:()=>d(n)},n.id))}),o&&s.jsx(Z,{mode:"create",onClose:()=>m(!1)}),t&&s.jsx(Z,{mode:"edit",device:t,onClose:()=>y(null)}),s.jsx(ce,{open:r!==null,onOpenChange:n=>!n&&d(null),children:s.jsxs(de,{children:[s.jsxs(le,{children:[s.jsx(ue,{className:"bg-destructive/10",children:s.jsx(ee,{className:"h-5 w-5 text-destructive"})}),s.jsx(me,{children:e("device.deleteConfirm")}),s.jsx(he,{children:e("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),s.jsxs(pe,{children:[s.jsx(xe,{children:e("common.cancel")}),s.jsx(ve,{variant:"destructive",disabled:!r||k.isPending,onClick:()=>{r&&(k.mutate(r.id),d(null))},children:e("common.delete")})]})]})})]})}function Be({device:e,onEdit:o,onDelete:m}){const{t}=b(),y=e.type==="local"?s.jsx(X,{className:"h-4 w-4"}):s.jsx(fe,{className:"h-4 w-4"}),r=e.type==="local"?t("device.typeLocal"):`${e.username??"-"}@${e.host??"-"}:${e.port??22}`,d=I({mutationFn:async()=>{const l=await fetch(`/api/devices/${e.id}/test-connection`,{method:"POST"});let h=null;try{h=await l.json()}catch{h=null}if(!l.ok){const c=h;throw new Error((c==null?void 0:c.error)??t("common.error"))}return h},onSuccess:l=>{f.success(l.message??t("common.success"))},onError:l=>{f.error(l instanceof Error?l.message:t("common.error"))}});return s.jsxs(M,{"data-testid":"device-card","data-device-id":e.id,"data-device-name":e.name,className:"overflow-hidden border-border/50",children:[s.jsxs(Ae,{className:"space-y-2 pb-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[s.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}),s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsx(Te,{className:"line-clamp-1 text-sm",title:e.name,children:e.name}),s.jsx(Fe,{className:"line-clamp-1 text-xs",children:r})]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:s.jsxs(ge,{children:[s.jsx(ye,{render:s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${e.id}`,"aria-label":t("common.edit"),title:t("common.edit")}),children:s.jsx(je,{className:"h-4 w-4"})}),s.jsxs(we,{align:"end",children:[s.jsxs($,{"data-testid":`device-card-edit-${e.id}`,onClick:o,children:[s.jsx(Ne,{className:"h-4 w-4"}),t("common.edit")]}),e.type==="ssh"&&s.jsxs($,{"data-testid":`device-card-test-${e.id}`,onClick:()=>d.mutate(),disabled:d.isPending,children:[s.jsx(We,{className:"h-4 w-4"}),t("common.test")]}),s.jsx(De,{}),s.jsxs($,{"data-testid":`device-card-delete-${e.id}`,variant:"destructive",onClick:m,children:[s.jsx(ee,{className:"h-4 w-4"}),t("common.delete")]})]})]})})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.type==="local"?t("device.typeLocal"):t("device.typeSSHBadge")}),e.session&&s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.session}),s.jsx(Ce,{deviceId:e.id})]})]}),s.jsxs(P,{className:"pt-0",children:[s.jsx(be,{className:"mb-2"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(Se,{to:`/devices/${e.id}`,"data-testid":`device-card-connect-${e.id}`,className:ke({variant:"outline",size:"sm"}),children:t("device.connect")})})]})]})}function Z({mode:e,device:o,onClose:m}){const{t}=b(),y=_(),[r,d]=v.useState(qe(o)),[l,h]=v.useState(!1),[c,K]=v.useState(!1),N=e==="edit",S=r.type==="ssh",k=I({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"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),E=I({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"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),n=async a=>{a.preventDefault(),K(!0);const i=Oe(r);if(i){f.error(t(i));return}h(!0);try{e==="create"?await k.mutateAsync(Le(r)):await E.mutateAsync(He(r))}catch{}finally{h(!1)}},p=`${e}-device-name`,D=`${e}-device-type`,A=`${e}-device-host`,T=`${e}-device-port`,F=`${e}-device-username`,W=`${e}-device-session`,q=`${e}-device-default-working-dir`,L=`${e}-device-auth-mode`,H=`${e}-device-password`,O=`${e}-device-private-key`,B=`${e}-device-private-key-passphrase`,te={local:t("device.typeLocal"),ssh:t("device.typeSSH")},ae={password:t("device.authPassword"),key:t("device.authKey"),agent:t("device.authAgent"),configRef:t("device.authConfigRef")},R=a=>s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:a}),u=(a,i,j)=>s.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:a,children:[i,j&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return s.jsx(Ee,{open:!0,onOpenChange:a=>!a&&m(),children:s.jsxs(Me,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[s.jsxs(Pe,{children:[s.jsx(Ie,{children:t(N?"device.editDevice":"device.addDevice")}),s.jsx(Ke,{children:t(N?"device.editDeviceDescription":"device.addDeviceDescription")})]}),s.jsxs("form",{onSubmit:n,className:"space-y-4",children:[s.jsxs("div",{className:"-mr-2 max-h-[min(70dvh,720px)] space-y-5 overflow-y-auto pr-2",children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionBasic")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(p,t("device.name"),!0),s.jsx(x,{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})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(D,t("device.type")),s.jsxs(z,{value:r.type,onValueChange:a=>{if(!a)return;const i=a;d(j=>({...j,type:i,authMode:i==="local"?"auto":j.authMode==="auto"?"agent":j.authMode}))},disabled:N,children:[s.jsx(V,{id:D,"data-testid":"device-type-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.type"),children:a=>te[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"local",children:t("device.typeLocal")}),s.jsx(w,{value:"ssh",children:t("device.typeSSH")})]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(W,t("device.session")),s.jsx(x,{id:W,"data-testid":"device-session-input",type:"text",value:r.session,onChange:a=>d(i=>({...i,session:a.target.value})),placeholder:t("device.sessionPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(q,t("device.defaultWorkingDir")),s.jsx(x,{id:q,"data-testid":"device-default-working-dir-input",type:"text",value:r.defaultWorkingDir,onChange:a=>d(i=>({...i,defaultWorkingDir:a.target.value})),placeholder:t("device.defaultWorkingDirPlaceholder")})]})]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionConnection")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(A,t("device.host"),!0),s.jsx(x,{id:A,type:"text",value:r.host,onChange:a=>d(i=>({...i,host:a.target.value})),placeholder:t("device.hostPlaceholder"),"aria-invalid":c&&!r.host.trim()})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(T,t("device.port"),!0),s.jsx(x,{id:T,type:"number",value:Number.isNaN(r.port)?"":r.port,onChange:a=>{const i=a.target.value;d(j=>({...j,port:i===""?Number.NaN:Number.parseInt(i,10)}))},min:1,max:65535,"aria-invalid":c&&!se(r.port)})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(F,t("device.username"),!0),s.jsx(x,{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()})]})]})]}),s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionAuth")),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[u(L,t("device.authMode")),s.jsxs(z,{value:r.authMode,onValueChange:a=>{a&&d(i=>({...i,authMode:a}))},children:[s.jsx(V,{id:L,"data-testid":"device-auth-mode-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.authMode"),children:a=>ae[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"password",children:t("device.authPassword")}),s.jsx(w,{value:"key",children:t("device.authKey")}),s.jsx(w,{value:"agent",children:t("device.authAgent")}),s.jsx(w,{value:"configRef",children:t("device.authConfigRef")})]})]})]}),r.authMode==="password"&&s.jsxs("div",{className:"space-y-1.5",children:[u(H,t("device.password")),s.jsx(x,{id:H,type:"password",value:r.password,onChange:a=>d(i=>({...i,password:a.target.value}))})]}),r.authMode==="key"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"space-y-1.5",children:[u(O,t("device.privateKey")),s.jsx(Re,{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")})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(B,t("device.passphrase")),s.jsx(x,{id:B,type:"password",value:r.privateKeyPassphrase,onChange:a=>d(i=>({...i,privateKeyPassphrase:a.target.value}))})]})]}),r.authMode==="configRef"&&s.jsxs("div",{className:"space-y-1.5",children:[u(`${e}-device-ssh-config-ref`,t("device.authConfigRef"),!0),s.jsx(x,{id:`${e}-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()}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("device.sshConfigRefHint")})]})]})]})]})]}),s.jsxs($e,{children:[s.jsx(C,{type:"button",variant:"outline",onClick:m,children:t("common.cancel")}),s.jsx(C,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:t(l?"common.saving":"common.save")})]})]})]})})}function Je(){const{t:e}=b();return s.jsx(s.Fragment,{children:e("sidebar.manageDevices")})}function Ge(){const{t:e}=b(),o=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:o,"aria-label":e("sidebar.addDevice"),title:e("sidebar.addDevice"),children:s.jsx(Y,{className:"h-4 w-4"})})}export{Ge as PageActions,Je as PageTitle,Ue as default};
|
|
1
|
+
import{u as b,r as v,a as _,b as ie,c as re,d as ne,e as I,t as oe,j as s,M as X,B as C,P as Y,A as ce,f as de,g as le,h as ue,T as ee,i as me,k as he,l as pe,m as xe,n as ve,G as fe,o as f,D as ge,p as ye,E as je,q as we,s as $,v as Ne,w as De,x as Q,y as Ce,S as be,L as Se,z as ke,C as Ee,F as Me,H as Pe,I as Ie,J as Ke,K as x,N as z,O as V,Q as U,R as J,U as w,V as Re,W as $e}from"./index-UoApkLSY.js";import{C as M,a as P,b as Ae,c as Te,d as Fe}from"./card-CD9i-fLq.js";import{Z as We}from"./zap-Dx7JTXJN.js";function g(e){const o=e.trim();return o||void 0}function qe(e){return e?{name:e.name,type:e.type,host:e.host??"",port:e.port??22,username:e.username??"",sshConfigRef:e.sshConfigRef??"",session:e.session??"tmex",defaultWorkingDir:e.defaultWorkingDir??"",authMode:e.type==="local"?"auto":e.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"root",sshConfigRef:"",session:"tmex",defaultWorkingDir:"",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(e){if(e.type==="local")return{name:e.name.trim(),type:"local",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:"auto"};const o={name:e.name.trim(),type:"ssh",host:e.host.trim(),port:e.port,username:e.username.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:e.authMode};return e.authMode==="configRef"&&(o.sshConfigRef=e.sshConfigRef.trim()),e.authMode==="password"&&(o.password=e.password),e.authMode==="key"&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function He(e){if(e.type==="local")return{name:e.name.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:"auto"};const o={name:e.name.trim(),host:e.host.trim(),port:e.port,username:e.username.trim(),sshConfigRef:e.authMode==="configRef"?e.sshConfigRef.trim():"",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:e.authMode};return e.authMode==="password"&&e.password&&(o.password=e.password),e.authMode==="key"&&e.privateKey&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function se(e){return Number.isInteger(e)&&e>=1&&e<=65535}function Oe(e){return e.type!=="ssh"?null:e.host.trim()?se(e.port)?e.username.trim()?e.authMode==="configRef"&&!e.sshConfigRef.trim()?"validation.sshConfigRequired":null:"validation.usernameRequired":"validation.portRequired":"validation.hostRequired"}async function G(e,o){try{return(await e.json()).error??o}catch{return o}}function Ue(){const{t:e}=b(),[o,m]=v.useState(!1),[t,y]=v.useState(null),[r,d]=v.useState(null),l=_(),h=ie(n=>{var p;return((p=n.settings)==null?void 0:p.language)??"en_US"});v.useEffect(()=>{const n=()=>m(!0);return window.addEventListener("tmex:open-add-device",n),()=>window.removeEventListener("tmex:open-add-device",n)},[]);const{data:c,isLoading:K,isError:N}=re({queryKey:["devices"],queryFn:async()=>{const n=await fetch("/api/devices");if(!n.ok)throw new Error(e("device.loadFailed"));return n.json()},throwOnError:!1}),S=ne(n=>n.hydrateDeviceErrors);v.useEffect(()=>{c!=null&&c.devices&&S(c.devices.map(n=>({deviceId:n.id,lastError:n.lastError??null,lastErrorType:n.lastErrorType??null})))},[c,S]);const k=I({mutationFn:async n=>{if(!(await fetch(`/api/devices/${n}`,{method:"DELETE"})).ok)throw new Error(e("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),f.success(e("common.success"))},onError:n=>{f.error(n instanceof Error?n.message:e("common.error"))}}),E=v.useMemo(()=>[...(c==null?void 0:c.devices)??[]].sort((p,D)=>p.sortOrder-D.sortOrder||p.name.localeCompare(D.name,oe(h),{numeric:!0,sensitivity:"base"})),[c==null?void 0:c.devices,h]);return s.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:[K?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-muted-foreground",children:e("common.loading")})}):N?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-destructive",children:e("device.loadFailed")})}):E.length===0?s.jsx(M,{children:s.jsxs(P,{className:"space-y-4 py-14 text-center",children:[s.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:s.jsx(X,{className:"h-6 w-6 text-muted-foreground"})}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-medium",children:e("device.noDevices")}),s.jsx("p",{className:"text-sm text-muted-foreground",children:e("device.addDevice")})]}),s.jsxs(C,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[s.jsx(Y,{className:"h-4 w-4"}),e("device.addDevice")]})]})}):s.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:E.map(n=>s.jsx(Be,{device:n,onEdit:()=>y(n),onDelete:()=>d(n)},n.id))}),o&&s.jsx(Z,{mode:"create",onClose:()=>m(!1)}),t&&s.jsx(Z,{mode:"edit",device:t,onClose:()=>y(null)}),s.jsx(ce,{open:r!==null,onOpenChange:n=>!n&&d(null),children:s.jsxs(de,{children:[s.jsxs(le,{children:[s.jsx(ue,{className:"bg-destructive/10",children:s.jsx(ee,{className:"h-5 w-5 text-destructive"})}),s.jsx(me,{children:e("device.deleteConfirm")}),s.jsx(he,{children:e("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),s.jsxs(pe,{children:[s.jsx(xe,{children:e("common.cancel")}),s.jsx(ve,{variant:"destructive",disabled:!r||k.isPending,onClick:()=>{r&&(k.mutate(r.id),d(null))},children:e("common.delete")})]})]})})]})}function Be({device:e,onEdit:o,onDelete:m}){const{t}=b(),y=e.type==="local"?s.jsx(X,{className:"h-4 w-4"}):s.jsx(fe,{className:"h-4 w-4"}),r=e.type==="local"?t("device.typeLocal"):`${e.username??"-"}@${e.host??"-"}:${e.port??22}`,d=I({mutationFn:async()=>{const l=await fetch(`/api/devices/${e.id}/test-connection`,{method:"POST"});let h=null;try{h=await l.json()}catch{h=null}if(!l.ok){const c=h;throw new Error((c==null?void 0:c.error)??t("common.error"))}return h},onSuccess:l=>{f.success(l.message??t("common.success"))},onError:l=>{f.error(l instanceof Error?l.message:t("common.error"))}});return s.jsxs(M,{"data-testid":"device-card","data-device-id":e.id,"data-device-name":e.name,className:"overflow-hidden border-border/50",children:[s.jsxs(Ae,{className:"space-y-2 pb-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[s.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}),s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsx(Te,{className:"line-clamp-1 text-sm",title:e.name,children:e.name}),s.jsx(Fe,{className:"line-clamp-1 text-xs",children:r})]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:s.jsxs(ge,{children:[s.jsx(ye,{render:s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${e.id}`,"aria-label":t("common.edit"),title:t("common.edit")}),children:s.jsx(je,{className:"h-4 w-4"})}),s.jsxs(we,{align:"end",children:[s.jsxs($,{"data-testid":`device-card-edit-${e.id}`,onClick:o,children:[s.jsx(Ne,{className:"h-4 w-4"}),t("common.edit")]}),e.type==="ssh"&&s.jsxs($,{"data-testid":`device-card-test-${e.id}`,onClick:()=>d.mutate(),disabled:d.isPending,children:[s.jsx(We,{className:"h-4 w-4"}),t("common.test")]}),s.jsx(De,{}),s.jsxs($,{"data-testid":`device-card-delete-${e.id}`,variant:"destructive",onClick:m,children:[s.jsx(ee,{className:"h-4 w-4"}),t("common.delete")]})]})]})})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.type==="local"?t("device.typeLocal"):t("device.typeSSHBadge")}),e.session&&s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.session}),s.jsx(Ce,{deviceId:e.id})]})]}),s.jsxs(P,{className:"pt-0",children:[s.jsx(be,{className:"mb-2"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(Se,{to:`/devices/${e.id}`,"data-testid":`device-card-connect-${e.id}`,className:ke({variant:"outline",size:"sm"}),children:t("device.connect")})})]})]})}function Z({mode:e,device:o,onClose:m}){const{t}=b(),y=_(),[r,d]=v.useState(qe(o)),[l,h]=v.useState(!1),[c,K]=v.useState(!1),N=e==="edit",S=r.type==="ssh",k=I({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"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),E=I({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"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),n=async a=>{a.preventDefault(),K(!0);const i=Oe(r);if(i){f.error(t(i));return}h(!0);try{e==="create"?await k.mutateAsync(Le(r)):await E.mutateAsync(He(r))}catch{}finally{h(!1)}},p=`${e}-device-name`,D=`${e}-device-type`,A=`${e}-device-host`,T=`${e}-device-port`,F=`${e}-device-username`,W=`${e}-device-session`,q=`${e}-device-default-working-dir`,L=`${e}-device-auth-mode`,H=`${e}-device-password`,O=`${e}-device-private-key`,B=`${e}-device-private-key-passphrase`,te={local:t("device.typeLocal"),ssh:t("device.typeSSH")},ae={password:t("device.authPassword"),key:t("device.authKey"),agent:t("device.authAgent"),configRef:t("device.authConfigRef")},R=a=>s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:a}),u=(a,i,j)=>s.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:a,children:[i,j&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return s.jsx(Ee,{open:!0,onOpenChange:a=>!a&&m(),children:s.jsxs(Me,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[s.jsxs(Pe,{children:[s.jsx(Ie,{children:t(N?"device.editDevice":"device.addDevice")}),s.jsx(Ke,{children:t(N?"device.editDeviceDescription":"device.addDeviceDescription")})]}),s.jsxs("form",{onSubmit:n,className:"space-y-4",children:[s.jsxs("div",{className:"-mr-2 max-h-[min(70dvh,720px)] space-y-5 overflow-y-auto pr-2",children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionBasic")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(p,t("device.name"),!0),s.jsx(x,{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})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(D,t("device.type")),s.jsxs(z,{value:r.type,onValueChange:a=>{if(!a)return;const i=a;d(j=>({...j,type:i,authMode:i==="local"?"auto":j.authMode==="auto"?"agent":j.authMode}))},disabled:N,children:[s.jsx(V,{id:D,"data-testid":"device-type-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.type"),children:a=>te[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"local",children:t("device.typeLocal")}),s.jsx(w,{value:"ssh",children:t("device.typeSSH")})]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(W,t("device.session")),s.jsx(x,{id:W,"data-testid":"device-session-input",type:"text",value:r.session,onChange:a=>d(i=>({...i,session:a.target.value})),placeholder:t("device.sessionPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(q,t("device.defaultWorkingDir")),s.jsx(x,{id:q,"data-testid":"device-default-working-dir-input",type:"text",value:r.defaultWorkingDir,onChange:a=>d(i=>({...i,defaultWorkingDir:a.target.value})),placeholder:t("device.defaultWorkingDirPlaceholder")})]})]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionConnection")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(A,t("device.host"),!0),s.jsx(x,{id:A,type:"text",value:r.host,onChange:a=>d(i=>({...i,host:a.target.value})),placeholder:t("device.hostPlaceholder"),"aria-invalid":c&&!r.host.trim()})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(T,t("device.port"),!0),s.jsx(x,{id:T,type:"number",value:Number.isNaN(r.port)?"":r.port,onChange:a=>{const i=a.target.value;d(j=>({...j,port:i===""?Number.NaN:Number.parseInt(i,10)}))},min:1,max:65535,"aria-invalid":c&&!se(r.port)})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(F,t("device.username"),!0),s.jsx(x,{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()})]})]})]}),s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionAuth")),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[u(L,t("device.authMode")),s.jsxs(z,{value:r.authMode,onValueChange:a=>{a&&d(i=>({...i,authMode:a}))},children:[s.jsx(V,{id:L,"data-testid":"device-auth-mode-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.authMode"),children:a=>ae[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"password",children:t("device.authPassword")}),s.jsx(w,{value:"key",children:t("device.authKey")}),s.jsx(w,{value:"agent",children:t("device.authAgent")}),s.jsx(w,{value:"configRef",children:t("device.authConfigRef")})]})]})]}),r.authMode==="password"&&s.jsxs("div",{className:"space-y-1.5",children:[u(H,t("device.password")),s.jsx(x,{id:H,type:"password",value:r.password,onChange:a=>d(i=>({...i,password:a.target.value}))})]}),r.authMode==="key"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"space-y-1.5",children:[u(O,t("device.privateKey")),s.jsx(Re,{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")})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(B,t("device.passphrase")),s.jsx(x,{id:B,type:"password",value:r.privateKeyPassphrase,onChange:a=>d(i=>({...i,privateKeyPassphrase:a.target.value}))})]})]}),r.authMode==="configRef"&&s.jsxs("div",{className:"space-y-1.5",children:[u(`${e}-device-ssh-config-ref`,t("device.authConfigRef"),!0),s.jsx(x,{id:`${e}-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()}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("device.sshConfigRefHint")})]})]})]})]})]}),s.jsxs($e,{children:[s.jsx(C,{type:"button",variant:"outline",onClick:m,children:t("common.cancel")}),s.jsx(C,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:t(l?"common.saving":"common.save")})]})]})]})})}function Je(){const{t:e}=b();return s.jsx(s.Fragment,{children:e("sidebar.manageDevices")})}function Ge(){const{t:e}=b(),o=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:o,"aria-label":e("sidebar.addDevice"),title:e("sidebar.addDevice"),children:s.jsx(Y,{className:"h-4 w-4"})})}export{Ge as PageActions,Je as PageTitle,Ue as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Y as zn,_ as ut,r as oe,j as h,X as gt,
|
|
1
|
+
import{Y as zn,_ as ut,r as oe,j as h,X as gt,aM as bt,u as ae,c as $n,aq as qn,a as mt,B as se,Z as nn}from"./index-UoApkLSY.js";import{r as pt,M as _t}from"./markdown-preview-CzbcKxcJ.js";import{k as ft,d as Ve,l as te,D as Kn,m as Et,f as ht,c as Nt}from"./api-D_FToAy0.js";import{R as yt,s as vt}from"./transfer-toast-CHcCj3qf.js";import"./index-DOfY8kwB.js";/**
|
|
2
2
|
* @license lucide-react v0.564.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import{Y as ce,u as F,j as e,L as Ft,M as Ye,z as At,r as y,c as K,B as k,P as ge,a as O,e as M,o as b,a2 as _,v as De,T as te,A as xe,f as fe,g as pe,h as Tt,i as we,k as ye,l as je,m as ve,n as be,C as ae,F as ne,H as ie,I as re,J as Ne,N as Ce,O as Ee,Q as ke,R as Se,U as le,K as D,W as de,aq as Q,G as Rt,x as mt,at as It,b as Oe,t as Xe,bt as $,X as ut,af as et,bu as Lt,bv as $t,aB as Dt,bw as Ot,bx as Bt,by as _t,bz as zt,bA as tt,Z as qt}from"./index-UoApkLSY.js";import{C as U,b as G,c as W,d as ht,a as H}from"./card-CD9i-fLq.js";import{e as Kt,h as gt,F as He,i as Qt,j as Ut,D as Ht}from"./api-D_FToAy0.js";import{R as Ze,T as Vt,b as Gt,d as Wt}from"./terminal-settings-panel-DsMMZFBi.js";import{S as xt}from"./send-BgCF67Uc.js";import{M as Jt}from"./markdown-preview-CzbcKxcJ.js";import{T as ft}from"./triangle-alert-BjHP6Ipw.js";import"./selection-clipboard-D3gUQQ7L.js";import"./index-DOfY8kwB.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 Yt=[["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"}]],Xt=ce("boxes",Yt);/**
|
|
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 Zt=[["rect",{width:"5",height:"5",x:"3",y:"3",rx:"1",key:"1tu5fj"}],["rect",{width:"5",height:"5",x:"16",y:"3",rx:"1",key:"1v8r4q"}],["rect",{width:"5",height:"5",x:"3",y:"16",rx:"1",key:"1x03jg"}],["path",{d:"M21 16h-3a2 2 0 0 0-2 2v3",key:"177gqh"}],["path",{d:"M21 21v.01",key:"ents32"}],["path",{d:"M12 7v3a2 2 0 0 1-2 2H7",key:"8crl2c"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M12 16v.01",key:"133mhm"}],["path",{d:"M16 12h1",key:"1slzba"}],["path",{d:"M21 12v.01",key:"1lwtk9"}],["path",{d:"M12 21v-1",key:"1880an"}]],Ve=ce("qr-code",Zt);/**
|
|
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=[["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"}]],ee=ce("save",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 ts=[["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"}]],ss=ce("server",ts);/**
|
|
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 as=[["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"}]],st=ce("shield",as);/**
|
|
27
|
+
* @license lucide-react v0.564.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const ns=[["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"}]],is=ce("users",ns);function rs(){const{t}=F();return e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{children:[e.jsx(W,{children:t("settings.deviceManagement.title")}),e.jsx(ht,{children:t("settings.deviceManagement.description")})]}),e.jsx(H,{children:e.jsxs(Ft,{to:"/devices","data-testid":"settings-device-management-link",className:At({variant:"secondary"}),children:[e.jsx(Ye,{className:"h-4 w-4"}),t("settings.deviceManagement.openButton")]})})]})}function Le({type:t,className:o}){return t==="ssh"?e.jsx(Rt,{className:o}):e.jsx(Ye,{className:o})}function os(){var r,m;const{t}=F(),[o,s]=y.useState(!1),[l,c]=y.useState(void 0),h=K({queryKey:["files","roots"],queryFn:Kt}),p=K({queryKey:["devices"],queryFn:async()=>{const d=await fetch("/api/devices");if(!d.ok)throw new Error(`HTTP ${d.status}`);return await d.json()},throwOnError:!1}),f=((r=h.data)==null?void 0:r.roots)??[],a=((m=p.data)==null?void 0:m.devices)??[],n=()=>{c(void 0),s(!0)},i=d=>{c(d),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0","data-testid":"settings-files-section",children:[e.jsxs(G,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(W,{children:t("settings.files.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settings.files.description")})]}),e.jsxs(k,{variant:"secondary","data-testid":"settings-files-root-add",onClick:n,children:[e.jsx(ge,{className:"h-4 w-4"}),t("settings.files.addRoot")]})]}),e.jsxs(H,{className:"space-y-3",children:[h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&f.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground","data-testid":"settings-files-empty",children:t("settings.files.empty")}),f.map(d=>e.jsx(ls,{root:d,onEdit:i},d.id))]})]}),e.jsx(cs,{open:o,onOpenChange:s,root:l,devices:a})]})}function ls({root:t,onEdit:o}){const{t:s}=F(),l=O(),[c,h]=y.useState(!1),p=M({mutationFn:({id:a,enabled:n})=>gt(a,{enabled:n}),onSuccess:async()=>{await l.invalidateQueries({queryKey:["files"]})},onError:()=>{b.error(s("settings.files.toggleFailed"))}}),f=M({mutationFn:a=>Qt(a),onSuccess:async()=>{await l.invalidateQueries({queryKey:["files"]}),b.success(s("common.success"))},onError:a=>{const n=a instanceof He?a.message:s("settings.files.deleteFailed");b.error(n)}});return e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border p-3","data-testid":`settings-files-root-${t.id}`,children:[e.jsx(_,{checked:t.enabled,disabled:p.isPending,onCheckedChange:a=>p.mutate({id:t.id,enabled:!!a}),"data-testid":`settings-files-root-enabled-${t.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(Le,{type:t.deviceType,className:"h-3.5 w-3.5 shrink-0"}),t.deviceName===null?e.jsx("span",{className:"text-destructive",children:s("settings.files.missing")}):e.jsx("span",{className:"truncate",children:t.deviceName})]}),e.jsx("div",{className:"truncate font-mono text-xs",children:t.path}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:t.name})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`settings-files-root-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(De,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.delete"),"data-testid":`settings-files-root-delete-${t.id}`,onClick:()=>h(!0),disabled:f.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(xe,{open:c,onOpenChange:h,children:e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsx(Tt,{className:"bg-destructive/10",children:e.jsx(te,{className:"h-5 w-5 text-destructive"})}),e.jsx(we,{children:s("settings.files.deleteTitle")}),e.jsx(ye,{children:s("settings.files.deleteDesc",{path:t.path})})]}),e.jsxs(je,{children:[e.jsx(ve,{children:s("common.cancel")}),e.jsx(be,{variant:"destructive","data-testid":`settings-files-root-delete-confirm-${t.id}`,onClick:()=>{f.mutate(t.id),h(!1)},children:s("common.delete")})]})]})})]})}const at="h-9 w-full";function cs({open:t,onOpenChange:o,root:s,devices:l}){const{t:c}=F(),h=O(),p=!!s,[f,a]=y.useState(""),[n,i]=y.useState(""),[r,m]=y.useState(!0);y.useEffect(()=>{t&&(a((s==null?void 0:s.deviceId)??""),i((s==null?void 0:s.path)??""),m((s==null?void 0:s.enabled)??!0))},[t,s]);const d=M({mutationFn:()=>{const E={deviceId:f,path:n.trim(),enabled:r};return Ut(E)},onSuccess:async()=>{await h.invalidateQueries({queryKey:["files"]}),b.success(c("common.success")),o(!1)},onError:E=>{const z=E instanceof He?E.message:c("settings.files.addFailed");b.error(z)}}),u=M({mutationFn:()=>{if(!s)throw new Error(c("settings.files.updateFailed"));const E={path:n.trim(),enabled:r};return gt(s.id,E)},onSuccess:async()=>{await h.invalidateQueries({queryKey:["files"]}),b.success(c("common.success")),o(!1)},onError:E=>{const z=E instanceof He?E.message:c("settings.files.updateFailed");b.error(z)}}),w=d.isPending||u.isPending,C=n.trim().startsWith("/")&&(p||f.length>0),x=()=>{!C||w||(p?u.mutate():d.mutate())},N=l.find(E=>E.id===f);return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":p?`settings-files-edit-modal-${s==null?void 0:s.id}`:"settings-files-add-modal",children:[e.jsxs(ie,{children:[e.jsx(re,{children:c(p?"settings.files.modalEditTitle":"settings.files.modalAddTitle")}),e.jsx(Ne,{children:c("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:c("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(Le,{type:(s==null?void 0:s.deviceType)??null,className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:(s==null?void 0:s.deviceName)??c("settings.files.missing")})]}):e.jsxs(Ce,{value:f,onValueChange:E=>{E&&a(E)},children:[e.jsx(Ee,{id:"files-form-device","data-testid":"settings-files-device-select",className:at,disabled:l.length===0,children:e.jsx(ke,{children:N?e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{type:N.type,className:"h-4 w-4 shrink-0"}),N.name]}):e.jsx("span",{className:"text-muted-foreground",children:c("settings.files.devicePlaceholder")})})}),e.jsx(Se,{children:l.map(E=>e.jsxs(le,{value:E.id,children:[e.jsx(Le,{type:E.type,className:"h-4 w-4 shrink-0"}),E.name]},E.id))})]}),!p&&l.length===0&&e.jsx("p",{className:"text-xs text-destructive",children:c("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:c("settings.files.path")}),e.jsx(D,{id:"files-form-path","data-testid":"settings-files-path-input",value:n,onChange:E=>i(E.target.value),placeholder:c("settings.files.pathPlaceholder"),className:`${at} font-mono`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("settings.files.pathHint")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{checked:r,onCheckedChange:E=>m(!!E),"data-testid":"settings-files-enabled-switch"}),e.jsx("label",{className:"text-sm font-medium",htmlFor:"settings-files-enabled-switch",children:c("settings.files.enabled")})]})]}),e.jsxs(de,{children:[e.jsx(k,{variant:"outline",onClick:()=>o(!1),disabled:w,children:c("common.cancel")}),e.jsxs(k,{variant:"secondary","data-testid":"settings-files-form-submit",onClick:x,disabled:!C||w,children:[w?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),c("common.save")]})]})]})})}async function Z(t,o){try{return(await t.json()).error??o}catch{return o}}const ds=["openai-chat","openai-responses"],Te="h-9 w-full";function ms({open:t,onOpenChange:o,provider:s}){const{t:l}=F(),c=O(),h=!!s,[p,f]=y.useState(""),[a,n]=y.useState(""),[i,r]=y.useState("openai-chat"),[m,d]=y.useState("");y.useEffect(()=>{t&&(f((s==null?void 0:s.name)??""),n((s==null?void 0:s.baseUrl)??""),r((s==null?void 0:s.protocol)??"openai-chat"),d(""))},[t,s]);const u=M({mutationFn:async()=>{const x={name:p.trim(),protocol:i,baseUrl:a.trim(),apiKey:m.trim(),enabled:!0},N=await fetch("/api/llm/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!N.ok)throw new Error(await Z(N,l("settings.llm.createFailed")));return await N.json()},onSuccess:async x=>{await c.invalidateQueries({queryKey:["llm-providers"]}),x.modelsError?b.warning(l("settings.llm.modelsFetchFailed",{error:x.modelsError})):b.success(l("common.success")),o(!1)},onError:x=>{b.error(x instanceof Error?x.message:l("common.error"))}}),w=M({mutationFn:async()=>{if(!s)throw new Error(l("settings.llm.updateFailed"));const x={name:p.trim(),baseUrl:a.trim(),protocol:i};m.trim()&&(x.apiKey=m.trim());const N=await fetch(`/api/llm/providers/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(x)});if(!N.ok)throw new Error(await Z(N,l("settings.llm.updateFailed")));return await N.json()},onSuccess:async x=>{await c.invalidateQueries({queryKey:["llm-providers"]}),x.modelsError?b.warning(l("settings.llm.modelsFetchFailed",{error:x.modelsError})):b.success(l("common.success")),o(!1)},onError:x=>{b.error(x instanceof Error?x.message:l("common.error"))}}),j=u.isPending||w.isPending,g=p.trim().length>0&&a.trim().length>0&&(h||m.trim().length>0),C=()=>{!g||j||(h?w.mutate():u.mutate())};return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":h?`llm-provider-edit-modal-${s==null?void 0:s.id}`:"llm-provider-add-modal",children:[e.jsxs(ie,{children:[e.jsx(re,{children:l(h?"settings.llm.editProvider":"settings.llm.addProvider")}),e.jsx(Ne,{children:l("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:l("settings.llm.name")}),e.jsx(D,{id:"llm-form-name","data-testid":"llm-provider-name-input",value:p,onChange:x=>f(x.target.value),placeholder:l("settings.llm.namePlaceholder"),className:Te})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-baseurl",children:l("settings.llm.baseUrl")}),e.jsx(D,{id:"llm-form-baseurl","data-testid":"llm-provider-baseurl-input",value:a,onChange:x=>n(x.target.value),placeholder:l("settings.llm.baseUrlPlaceholder"),className:Te}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("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:l("settings.llm.protocol")}),e.jsxs(Ce,{value:i,onValueChange:x=>{x&&r(x)},children:[e.jsx(Ee,{id:"llm-form-protocol","data-testid":"llm-provider-protocol-select",className:Te,children:e.jsx(ke,{})}),e.jsx(Se,{children:ds.map(x=>e.jsx(le,{value:x,children:x},x))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-apikey",children:l("settings.llm.apiKey")}),e.jsx(D,{id:"llm-form-apikey","data-testid":"llm-provider-apikey-input","data-key-set":s!=null&&s.hasApiKey?"true":"false",type:"password",value:m,onChange:x=>d(x.target.value),placeholder:s!=null&&s.hasApiKey?l("settings.llm.apiKeySetPlaceholder"):l("settings.llm.apiKeyPlaceholder"),className:Te})]})]}),e.jsxs(de,{children:[e.jsx(k,{variant:"outline",onClick:()=>o(!1),disabled:j,children:l("common.cancel")}),e.jsxs(k,{variant:"secondary","data-testid":"llm-provider-form-submit",onClick:C,disabled:!g||j,children:[j?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})})}function us({models:t,onChange:o}){const{t:s}=F(),[l,c]=y.useState(""),h=(a,n)=>{o(t.map(i=>i.id===a?{...i,enabled:n}:i))},p=a=>{o(t.filter(n=>n.id!==a))},f=()=>{const a=l.trim();if(a){if(t.some(n=>n.id===a)){c("");return}o([...t,{id:a,source:"manual",enabled:!0}]),c("")}};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(D,{value:l,onChange:a=>c(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),f())},placeholder:s("settings.llm.addModelPlaceholder"),className:"h-9","data-testid":"llm-provider-add-model-input"}),e.jsxs(k,{type:"button",variant:"outline",size:"lg",onClick:f,disabled:!l.trim(),"data-testid":"llm-provider-add-model",children:[e.jsx(ge,{className:"h-4 w-4"}),s("common.add")]})]}),t.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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:t.map(a=>e.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-md px-2 py-1.5","data-testid":`llm-provider-model-${a.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(_,{checked:a.enabled,onCheckedChange:n=>h(a.id,!!n),"data-testid":`llm-provider-model-toggle-${a.id}`}),e.jsx("span",{className:"truncate font-mono text-xs",children:a.id}),a.source==="manual"&&e.jsx(mt,{variant:"secondary",children:s("settings.llm.modelManual")})]}),a.source==="manual"&&e.jsx(k,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>p(a.id),"data-testid":`llm-provider-model-remove-${a.id}`,children:e.jsx(It,{className:"h-4 w-4"})})]},a.id))})]})}function hs(t){return t.modelDetails.map(o=>({id:o.id,source:o.source,enabled:o.enabled}))}function gs({open:t,onOpenChange:o,provider:s}){const{t:l}=F(),c=O(),[h,p]=y.useState([]);y.useEffect(()=>{t&&p(hs(s))},[t,s]);const f=M({mutationFn:async()=>{const a=h.filter(m=>m.source==="manual").map(m=>m.id),n=h.filter(m=>!m.enabled).map(m=>m.id),i={manualModels:a,disabledModels:n},r=await fetch(`/api/llm/providers/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await Z(r,l("settings.llm.updateFailed")));return await r.json()},onSuccess:async a=>{await c.invalidateQueries({queryKey:["llm-providers"]}),a.modelsError?b.warning(l("settings.llm.modelsFetchFailed",{error:a.modelsError})):b.success(l("common.success")),o(!1)},onError:a=>{b.error(a instanceof Error?a.message:l("common.error"))}});return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":`llm-provider-models-modal-${s.id}`,children:[e.jsxs(ie,{children:[e.jsx(re,{children:l("settings.llm.modelsTitle",{name:s.name})}),e.jsx(Ne,{children:l("settings.llm.modelsHint")})]}),e.jsx(us,{models:h,onChange:p}),e.jsxs(de,{children:[e.jsx(k,{variant:"outline",onClick:()=>o(!1),disabled:f.isPending,children:l("common.cancel")}),e.jsxs(k,{variant:"secondary","data-testid":`llm-provider-models-save-${s.id}`,onClick:()=>f.mutate(),disabled:f.isPending,children:[f.isPending?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})})}function xs(t){try{const o=new URL(t);return`${o.protocol}//${o.host}${o.pathname==="/"?"":o.pathname}`}catch{return t}}function fs({provider:t,onEdit:o}){const{t:s}=F(),l=O(),[c,h]=y.useState(!1),[p,f]=y.useState(!1),a=M({mutationFn:async r=>{const m=await fetch(`/api/llm/providers/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:r})});if(!m.ok)throw new Error(await Z(m,s("settings.llm.updateFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["llm-providers"]})},onError:r=>{b.error(r instanceof Error?r.message:s("common.error"))}}),n=M({mutationFn:async()=>{const r=await fetch(`/api/llm/providers/${t.id}/refresh-models`,{method:"POST"});if(!r.ok)throw new Error(await Z(r,s("settings.llm.refreshModelsFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["llm-providers"]}),b.success(s("common.success"))},onError:r=>{b.error(r instanceof Error?r.message:s("common.error"))}}),i=M({mutationFn:async()=>{const r=await fetch(`/api/llm/providers/${t.id}`,{method:"DELETE"});if(!r.ok)throw new Error(await Z(r,s("settings.llm.deleteFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["llm-providers"]}),await l.invalidateQueries({queryKey:["llm-settings"]}),b.success(s("common.success"))},onError:r=>{b.error(r instanceof Error?r.message:s("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-${t.id}`,"data-provider-name":t.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(_,{checked:t.enabled,disabled:a.isPending,onCheckedChange:r=>a.mutate(!!r),"data-testid":`llm-provider-enabled-${t.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:t.name}),e.jsx(mt,{variant:"outline",children:t.protocol})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"truncate font-mono",children:xs(t.baseUrl)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"whitespace-nowrap",children:s("settings.llm.modelsCount",{total:t.models.length})})]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("settings.llm.refreshModels"),"data-testid":`llm-provider-refresh-models-${t.id}`,onClick:()=>n.mutate(),disabled:n.isPending,children:n.isPending?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(Ze,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("settings.llm.models"),"data-testid":`llm-provider-models-${t.id}`,onClick:()=>f(!0),children:e.jsx(Xt,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`llm-provider-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(De,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.delete"),"data-testid":`llm-provider-delete-${t.id}`,onClick:()=>h(!0),disabled:i.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(gs,{open:p,onOpenChange:f,provider:t}),e.jsx(xe,{open:c,onOpenChange:h,children:e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsx(we,{children:s("settings.llm.deleteProvider")}),e.jsx(ye,{children:s("settings.llm.deleteConfirm",{name:t.name})})]}),e.jsxs(je,{children:[e.jsx(ve,{onClick:()=>h(!1),children:s("common.cancel")}),e.jsx(be,{variant:"destructive","data-testid":`llm-provider-delete-confirm-${t.id}`,onClick:()=>{i.mutate(),h(!1)},children:s("common.confirm")})]})]})})]})}function ps(){var n;const{t}=F(),[o,s]=y.useState(!1),[l,c]=y.useState(void 0),h=K({queryKey:["llm-providers"],queryFn:async()=>{const i=await fetch("/api/llm/providers");if(!i.ok)throw new Error(await Z(i,t("settings.llm.loadFailed")));return await i.json()}}),p=((n=h.data)==null?void 0:n.providers)??[],f=()=>{c(void 0),s(!0)},a=i=>{c(i),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0","data-testid":"llm-providers-section",children:[e.jsxs(G,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsx(W,{children:t("settings.llm.title")}),e.jsxs(k,{variant:"secondary","data-testid":"llm-provider-add",onClick:f,children:[e.jsx(ge,{className:"h-4 w-4"}),t("settings.llm.addProvider")]})]}),e.jsxs(H,{className:"space-y-3",children:[h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&p.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground","data-testid":"llm-providers-empty",children:t("settings.llm.empty")}),p.map(i=>e.jsx(fs,{provider:i,onEdit:a},i.id))]})]}),e.jsx(ms,{open:o,onOpenChange:s,provider:l}),e.jsx(ws,{providers:p})]})}const Be="__none__";function ws({providers:t}){var w,j;const{t:o}=F(),s=O(),[l,c]=y.useState(null),[h,p]=y.useState(""),f=K({queryKey:["llm-settings"],queryFn:async()=>{const g=await fetch("/api/llm/settings");if(!g.ok)throw new Error(await Z(g,o("settings.llm.settingsLoadFailed")));return await g.json()}}),a=((w=f.data)==null?void 0:w.settings.defaultProviderId)??null,n=((j=f.data)==null?void 0:j.settings.defaultModelId)??"",i=!!f.data;y.useEffect(()=>{i&&(c(a),p(n))},[i,a,n]);const r=M({mutationFn:async()=>{const g={defaultProviderId:l,defaultModelId:h.trim()||null},C=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!C.ok)throw new Error(await Z(C,o("settings.llm.settingsSaveFailed")))},onSuccess:async()=>{await s.invalidateQueries({queryKey:["llm-settings"]}),b.success(o("common.success"))},onError:g=>{b.error(g instanceof Error?g.message:o("common.error"))}}),m=t.filter(g=>g.enabled),d=t.find(g=>g.id===l),u=(d==null?void 0:d.models)??[];return e.jsxs(U,{className:"border-0 ring-0","data-testid":"llm-defaults-section",children:[e.jsx(G,{children:e.jsx(W,{children:o("settings.llm.defaults")})}),e.jsxs(H,{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:o("settings.llm.defaultProvider")}),e.jsxs(Ce,{value:l??Be,onValueChange:g=>{g&&c(g===Be?null:g)},children:[e.jsx(Ee,{id:"llm-default-provider-select","data-testid":"llm-default-provider-select",className:"h-9 w-full",children:e.jsx(ke,{children:(d==null?void 0:d.name)??o("settings.llm.defaultProviderNone")})}),e.jsxs(Se,{children:[e.jsx(le,{value:Be,children:o("settings.llm.defaultProviderNone")}),m.map(g=>e.jsx(le,{value:g.id,children:g.name},g.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-default-model-input",children:o("settings.llm.defaultModel")}),e.jsx(D,{id:"llm-default-model-input","data-testid":"llm-default-model-input",list:"llm-default-model-options",value:h,onChange:g=>p(g.target.value),placeholder:o("settings.llm.defaultModelPlaceholder"),className:"h-9"}),e.jsx("datalist",{id:"llm-default-model-options",children:u.map(g=>e.jsx("option",{value:g},g))})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(k,{variant:"secondary","data-testid":"llm-defaults-save",onClick:()=>r.mutate(),disabled:r.isPending||f.isLoading,className:"w-full sm:w-auto",children:[r.isPending?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),o("settings.llm.saveDefaults")]})})]})]})}const ys=["none","tavily","brave"];async function _e(t,o){try{return(await t.json()).error??o}catch{return o}}function js(){var j;const{t}=F(),o=O(),[s,l]=y.useState("none"),[c,h]=y.useState(""),[p,f]=y.useState(""),[a,n]=y.useState(null),i=K({queryKey:["llm-settings"],queryFn:async()=>{const g=await fetch("/api/llm/settings");if(!g.ok)throw new Error(await _e(g,t("settings.search.loadFailed")));return await g.json()}}),r=(j=i.data)==null?void 0:j.settings,m=r==null?void 0:r.searchProvider;y.useEffect(()=>{m&&l(m)},[m]);const d=M({mutationFn:async()=>{const g={searchProvider:s};c.trim()&&(g.tavilyApiKey=c.trim()),p.trim()&&(g.braveApiKey=p.trim());const C=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!C.ok)throw new Error(await _e(C,t("settings.search.saveFailed")))},onSuccess:async()=>{h(""),f(""),await o.invalidateQueries({queryKey:["llm-settings"]}),b.success(t("common.success"))},onError:g=>{b.error(g instanceof Error?g.message:t("common.error"))}}),u=M({mutationFn:async g=>{const C={[g]:""},x=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(C)});if(!x.ok)throw new Error(await _e(x,t("settings.search.saveFailed")))},onSuccess:async()=>{await o.invalidateQueries({queryKey:["llm-settings"]}),b.success(t("common.success"))},onError:g=>{b.error(g instanceof Error?g.message:t("common.error"))}}),w=g=>g==="none"?t("settings.search.providerNone"):g==="tavily"?"Tavily":"Brave";return e.jsxs(U,{className:"border-0 ring-0","data-testid":"settings-search-section",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.search.title")})}),e.jsxs(H,{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:t("settings.search.provider")}),e.jsxs(Ce,{value:s,onValueChange:g=>{g&&l(g)},children:[e.jsx(Ee,{id:"search-provider-select","data-testid":"settings-search-provider-select",className:"w-full min-h-10",children:e.jsx(ke,{children:w(s)})}),e.jsx(Se,{children:ys.map(g=>e.jsx(le,{value:g,children:w(g)},g))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.search.responsesApiHint")})]}),e.jsx(nt,{id:"search-tavily-key-input",testId:"settings-search-tavily",label:t("settings.search.tavilyApiKey"),value:c,hasKey:(r==null?void 0:r.hasTavilyApiKey)??!1,onChange:h,onClear:()=>n("tavilyApiKey"),clearing:u.isPending&&u.variables==="tavilyApiKey"}),e.jsx(nt,{id:"search-brave-key-input",testId:"settings-search-brave",label:t("settings.search.braveApiKey"),value:p,hasKey:(r==null?void 0:r.hasBraveApiKey)??!1,onChange:f,onClear:()=>n("braveApiKey"),clearing:u.isPending&&u.variables==="braveApiKey"}),e.jsx(xe,{open:a!==null,onOpenChange:g=>{g||n(null)},children:e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsx(we,{children:t("settings.search.clearKey")}),e.jsx(ye,{children:t("settings.search.clearKeyConfirm")})]}),e.jsxs(je,{children:[e.jsx(ve,{children:t("common.cancel")}),e.jsx(be,{"data-testid":"settings-search-clear-confirm",onClick:()=>{a&&u.mutate(a),n(null)},children:t("settings.search.clearKey")})]})]})}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(k,{variant:"secondary","data-testid":"settings-search-save",onClick:()=>d.mutate(),disabled:d.isPending||i.isLoading,className:"w-full sm:w-auto",children:[d.isPending?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),t("common.save")]})})]})]})}function nt({id:t,testId:o,label:s,value:l,hasKey:c,onChange:h,onClear:p,clearing:f}){const{t:a}=F();return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:t,children:s}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{id:t,"data-testid":`${o}-input`,"data-key-set":c?"true":"false",type:"password",value:l,onChange:n=>h(n.target.value),placeholder:a(c?"settings.search.keySetPlaceholder":"settings.search.keyPlaceholder"),className:"min-h-10"}),c&&e.jsxs(k,{variant:"outline",size:"sm","data-testid":`${o}-clear`,onClick:p,disabled:f,className:"shrink-0",children:[e.jsx(te,{className:"h-4 w-4"}),a("settings.search.clearKey")]})]})]})}const it="min-h-10";async function rt(t,o){try{return(await t.json()).error??o}catch{return o}}function vs({open:t,onOpenChange:o,bot:s}){const{t:l}=F(),c=O(),h=!!s,[p,f]=y.useState(""),[a,n]=y.useState(""),[i,r]=y.useState(!0);y.useEffect(()=>{t&&(f((s==null?void 0:s.name)??""),n(""),r((s==null?void 0:s.allowAuthRequests)??!0))},[t,s]);const m=M({mutationFn:async()=>{const g=await fetch("/api/settings/telegram/bots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:p.trim(),token:a.trim(),enabled:!0,allowAuthRequests:i})});if(!g.ok)throw new Error(await rt(g,l("telegram.createFailed")))},onSuccess:async()=>{await c.invalidateQueries({queryKey:["telegram-bots"]}),b.success(l("common.success")),o(!1)},onError:g=>{b.error(g instanceof Error?g.message:l("common.error"))}}),d=M({mutationFn:async()=>{if(!s)throw new Error(l("telegram.updateFailed"));const g={name:p.trim(),allowAuthRequests:i};a.trim()&&(g.token=a.trim());const C=await fetch(`/api/settings/telegram/bots/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!C.ok)throw new Error(await rt(C,l("telegram.updateFailed")))},onSuccess:async()=>{await c.invalidateQueries({queryKey:["telegram-bots"]}),b.success(l("common.success")),o(!1)},onError:g=>{b.error(g instanceof Error?g.message:l("common.error"))}}),u=m.isPending||d.isPending,w=p.trim().length>0&&(h||a.trim().length>0),j=()=>{!w||u||(h?d.mutate():m.mutate())};return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":h?`telegram-bot-edit-modal-${s==null?void 0:s.id}`:"telegram-bot-add-modal",children:[e.jsx(ie,{children:e.jsx(re,{children:l(h?"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:l("telegram.botName")}),e.jsx(D,{id:"telegram-bot-name","data-testid":"telegram-bot-name-input",value:p,onChange:g=>f(g.target.value),placeholder:l("telegram.botNamePlaceholder"),className:it})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"telegram-bot-token",children:l("telegram.botToken")}),e.jsx(D,{id:"telegram-bot-token","data-testid":"telegram-bot-token-input",type:"password",value:a,onChange:g=>n(g.target.value),placeholder:l(h?"telegram.tokenPlaceholder":"telegram.botTokenPlaceholder"),className:it})]}),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:l("telegram.allowAuthRequests")}),e.jsx(_,{checked:i,"data-testid":"telegram-bot-allow-auth",onCheckedChange:g=>r(!!g)})]})]}),e.jsxs(de,{children:[e.jsx(k,{variant:"outline",onClick:()=>o(!1),disabled:u,children:l("common.cancel")}),e.jsxs(k,{variant:"secondary","data-testid":"telegram-bot-form-submit",onClick:j,disabled:!w||u,children:[u?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})})}async function Re(t,o){try{return(await t.json()).error??o}catch{return o}}function bs({open:t,onOpenChange:o,botId:s,botName:l}){var m;const{t:c}=F(),h=O(),p=K({queryKey:["telegram-bot-chats",s],enabled:t,queryFn:async()=>{const d=await fetch(`/api/settings/telegram/bots/${s}/chats`);if(!d.ok)throw new Error(await Re(d,c("telegram.loadChatsFailed")));return await d.json()}}),f=y.useMemo(()=>{var u;const d=((u=p.data)==null?void 0:u.chats)??[];return{pending:d.filter(w=>w.status==="pending"),authorized:d.filter(w=>w.status==="authorized")}},[(m=p.data)==null?void 0:m.chats]),a=async()=>{await Promise.all([h.invalidateQueries({queryKey:["telegram-bots"]}),h.invalidateQueries({queryKey:["telegram-bot-chats",s]})])},n=M({mutationFn:async d=>{const u=await fetch(`/api/settings/telegram/bots/${s}/chats/${encodeURIComponent(d)}/approve`,{method:"POST"});if(!u.ok)throw new Error(await Re(u,c("telegram.approveFailed")))},onSuccess:async()=>{await a(),b.success(c("common.success"))},onError:d=>{b.error(d instanceof Error?d.message:c("common.error"))}}),i=M({mutationFn:async d=>{const u=await fetch(`/api/settings/telegram/bots/${s}/chats/${encodeURIComponent(d)}`,{method:"DELETE"});if(!u.ok)throw new Error(await Re(u,c("telegram.removeFailed")))},onSuccess:async()=>{await a(),b.success(c("common.success"))},onError:d=>{b.error(d instanceof Error?d.message:c("common.error"))}}),r=M({mutationFn:async d=>{const u=await fetch(`/api/settings/telegram/bots/${s}/chats/${encodeURIComponent(d)}/test`,{method:"POST"});if(!u.ok)throw new Error(await Re(u,c("telegram.testMessageFailed")))},onSuccess:()=>{b.success(c("common.success"))},onError:d=>{b.error(d instanceof Error?d.message:c("common.error"))}});return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-2xl","data-testid":`telegram-bot-chats-modal-${s}`,children:[e.jsxs(ie,{children:[e.jsx(re,{children:c("telegram.chats")}),e.jsx(Ne,{children:l})]}),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(st,{className:"h-4 w-4"}),c("telegram.pendingChats")]}),f.pending.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:c("telegram.noPendingChats")}),f.pending.map(d=>e.jsx(ot,{chat:d,pending:!0,onApprove:()=>n.mutate(d.chatId),onDelete:()=>i.mutate(d.chatId)},`${d.botId}-${d.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(st,{className:"h-4 w-4"}),c("telegram.chats")]}),f.authorized.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:c("telegram.noAuthorizedChats")}),f.authorized.map(d=>e.jsx(ot,{chat:d,pending:!1,onTest:()=>r.mutate(d.chatId),onDelete:()=>i.mutate(d.chatId)},`${d.botId}-${d.chatId}`))]}),p.isLoading&&e.jsx("div",{className:"text-xs text-muted-foreground lg:col-span-2",children:c("common.loading")})]})]})})}function ot({chat:t,pending:o,onApprove:s,onDelete:l,onTest:c}){const{t:h}=F(),p=Oe(f=>{var a;return((a=f.settings)==null?void 0:a.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:t.displayName,children:t.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[h("telegram.chatId"),":",t.chatId]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(t.appliedAt).toLocaleString(Xe(p))}),e.jsx("div",{className:"flex items-center justify-end gap-2 pt-1",children:o?e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"outline",size:"sm",onClick:l,children:h("telegram.reject")}),e.jsx(k,{variant:"secondary",size:"sm",onClick:s,children:h("telegram.authorize")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(k,{variant:"secondary",size:"sm",onClick:c,children:[e.jsx(xt,{className:"h-3.5 w-3.5"}),h("telegram.sendTestMessage")]}),e.jsx(k,{variant:"destructive",size:"sm",onClick:l,children:h("common.delete")})]})})]})}async function lt(t,o){try{return(await t.json()).error??o}catch{return o}}function Ns({bot:t,onEdit:o}){const{t:s}=F(),l=O(),[c,h]=y.useState(!1),p=M({mutationFn:async a=>{const n=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:a})});if(!n.ok)throw new Error(await lt(n,s("telegram.updateFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["telegram-bots"]})},onError:a=>{b.error(a instanceof Error?a.message:s("common.error"))}}),f=M({mutationFn:async()=>{const a=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"DELETE"});if(!a.ok)throw new Error(await lt(a,s("telegram.deleteFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["telegram-bots"]}),b.success(s("common.success"))},onError:a=>{b.error(a instanceof Error?a.message:s("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-${t.id}`,"data-bot-name":t.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(_,{checked:t.enabled,disabled:p.isPending,onCheckedChange:a=>p.mutate(!!a),"data-testid":`telegram-bot-enabled-${t.id}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:t.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("telegram.authCount",{authorized:t.authorizedCount,pending:t.pendingCount})})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("telegram.chats"),"data-testid":`telegram-bot-chats-${t.id}`,onClick:()=>h(!0),children:e.jsx(is,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`telegram-bot-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(De,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("telegram.deleteBot"),"data-testid":`telegram-bot-delete-${t.id}`,onClick:()=>f.mutate(),disabled:f.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(bs,{open:c,onOpenChange:h,botId:t.id,botName:t.name})]})}async function Cs(t,o){try{return(await t.json()).error??o}catch{return o}}function Es(){var n;const{t}=F(),[o,s]=y.useState(!1),[l,c]=y.useState(void 0),h=K({queryKey:["telegram-bots"],queryFn:async()=>{const i=await fetch("/api/settings/telegram/bots");if(!i.ok)throw new Error(await Cs(i,t("telegram.loadBotsFailed")));return await i.json()}}),p=((n=h.data)==null?void 0:n.bots)??[],f=()=>{c(void 0),s(!0)},a=i=>{c(i),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsx(W,{children:t("telegram.title")}),e.jsxs(k,{variant:"secondary","data-testid":"telegram-add-bot",onClick:f,children:[e.jsx(ge,{className:"h-4 w-4"}),t("telegram.addBot")]})]}),e.jsxs(H,{className:"space-y-3",children:[h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&p.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("telegram.noBots")}),p.map(i=>e.jsx(Ns,{bot:i,onEdit:a},i.id))]})]}),e.jsx(vs,{open:o,onOpenChange:s,bot:l})]})}function ks(){const{t}=F();return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.terminal.title")})}),e.jsx(H,{children:e.jsx(Vt,{showShortcuts:!1})})]}),e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{children:[e.jsx(W,{children:t("settings.terminal.shortcuts.title")}),e.jsx(ht,{children:t("settings.terminal.shortcuts.savedOnServer")})]}),e.jsx(H,{children:e.jsx(Gt,{})})]})]})}async function ze(t,o){try{return(await t.json()).error??o}catch{return o}}function qe({label:t,value:o}){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:t}),e.jsx("div",{className:"min-w-0 truncate text-right text-sm text-muted-foreground",children:o})]})}function Ss(){const{t}=F(),o=O(),s=Oe(x=>{var N;return((N=x.settings)==null?void 0:N.language)??"en_US"}),[l,c]=y.useState(!1),[h,p]=y.useState(!1),f=y.useRef(!1),n=K({queryKey:["system-info"],queryFn:async()=>{const x=await fetch("/api/system/info");if(!x.ok)throw new Error(await ze(x,t("settings.loadFailed")));return await x.json()}}).data,i=K({queryKey:["system-update-check"],enabled:!1,gcTime:0,queryFn:async()=>{const x=await fetch("/api/system/update-check");if(!x.ok)throw new Error(await ze(x,t("settings.version.checkFailed")));return await x.json()}}),r=i.data,d=K({queryKey:["system-upgrade-status"],enabled:h,refetchInterval:x=>{var E;const N=(E=x.state.data)==null?void 0:E.state;return h||N&&N!=="idle"?2e3:!1},retry:!0,queryFn:async()=>{const x=await fetch("/api/system/upgrade");if(!x.ok)throw new Error("status");return await x.json()}}).data;y.useEffect(()=>{if(!h)return;const x=d==null?void 0:d.state;x&&x!=="idle"?f.current=!0:x==="idle"&&(d!=null&&d.error)?(f.current=!1,p(!1),b.error(d.error)):x==="idle"&&f.current&&(f.current=!1,p(!1),o.invalidateQueries({queryKey:["system-info"]}),o.removeQueries({queryKey:["system-update-check"]}),b.success(t("common.success")))},[h,d,o,t]);const u=M({mutationFn:async x=>{const N=await fetch("/api/system/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({version:x})});if(!N.ok)throw new Error(await ze(N,t("common.error")));return await N.json()},onSuccess:x=>{f.current=!1,p(!0),o.setQueryData(["system-upgrade-status"],x),b.success(t("settings.version.upgradeStarted"))},onError:x=>{b.error(x instanceof Error?x.message:t("common.error"))}}),w=x=>t(x==="launchd"?"settings.version.deploymentLaunchd":x==="systemd"?"settings.version.deploymentSystemd":"settings.version.deploymentNone"),j=h&&(d==null?void 0:d.state)!==void 0,g=(d==null?void 0:d.state)==="downloading"?t("settings.version.stateDownloading"):(d==null?void 0:d.state)==="executing"?t("settings.version.stateExecuting"):null,C=n!=null&&n.canSelfUpdate?null:n!=null&&n.isProd?n!=null&&n.installedViaCli?null:t("settings.version.upgradeDisabledNonCli"):t("settings.version.upgradeDisabledDev");return e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.version.title")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(qe,{label:t("settings.version.currentVersion"),value:e.jsx("span",{"data-testid":"settings-version-current",className:"font-mono",children:n?n.version:t("common.loading")})}),e.jsx(qe,{label:t("settings.version.installMethod"),value:n?n.installedViaCli?t("settings.version.installMethodCli"):t("settings.version.installMethodNonCli"):"-"}),e.jsx(qe,{label:t("settings.version.deployment"),value:n?w(n.deployment):"-"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(k,{variant:"outline","data-testid":"settings-version-check",onClick:()=>i.refetch(),disabled:i.isFetching||j,children:[i.isFetching?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(Ze,{className:"h-4 w-4"}),i.isFetching?t("settings.version.checking"):t("settings.version.checkUpdate")]}),r&&e.jsxs("span",{className:"text-sm text-muted-foreground","data-testid":"settings-version-latest",children:[r.hasUpdate&&r.latestVersion?t("settings.version.updateAvailable",{version:r.latestVersion}):t("settings.version.upToDate"),r.publishedAt?` · ${t("settings.version.publishedAt",{date:new Date(r.publishedAt).toLocaleDateString(Xe(s))})}`:""]})]}),i.isError&&e.jsx("div",{className:"text-sm text-destructive",children:t("settings.version.checkFailed")}),(r==null?void 0:r.hasUpdate)&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-semibold",children:t("settings.version.changelog")}),e.jsx("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:r.changelog?e.jsx(Jt,{source:r.changelog,basePath:"/"}):e.jsx("div",{className:"text-sm text-muted-foreground",children:t("settings.version.changelogUnavailable")})}),n!=null&&n.canSelfUpdate?e.jsxs(k,{variant:"secondary","data-testid":"settings-version-upgrade",disabled:j||u.isPending,onClick:()=>c(!0),children:[j?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(Ht,{className:"h-4 w-4"}),t("settings.version.upgrade")]}):e.jsxs("div",{className:"space-y-1",children:[C&&e.jsx("div",{className:"text-sm text-muted-foreground",children:C}),e.jsx("div",{className:"text-xs text-muted-foreground font-mono",children:t("settings.version.terminalHint")})]})]}),j&&g&&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(Q,{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:g}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t("settings.version.interruptNotice")})]})]})]}),e.jsx(xe,{open:l,onOpenChange:c,children:e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsxs(we,{className:"flex items-center gap-2",children:[e.jsx(ft,{className:"h-5 w-5 text-destructive"}),t("settings.version.upgradeWarningTitle")]}),e.jsx(ye,{children:t("settings.version.upgradeWarningBody")})]}),e.jsxs(je,{children:[e.jsx(ve,{onClick:()=>c(!1),children:t("common.cancel")}),e.jsx(be,{variant:"destructive","data-testid":"settings-version-upgrade-confirm",onClick:()=>{c(!1),r!=null&&r.latestVersion&&u.mutate(r.latestVersion)},children:t("settings.version.upgrade")})]})]})})]})}const Ke=["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 Qe(t,o){try{return(await t.json()).error??o}catch{return o}}function Ms(){var d;const{t}=F(),o=O(),s=Oe(u=>{var w;return((w=u.settings)==null?void 0:w.language)??"en_US"}),[l,c]=y.useState(""),[h,p]=y.useState(""),[f,a]=y.useState(Ke),n=K({queryKey:["webhooks"],queryFn:async()=>{const u=await fetch("/api/webhooks");if(!u.ok)throw new Error(await Qe(u,t("webhook.loadFailed")));return await u.json()}}),i=M({mutationFn:async()=>{const u=await fetch("/api/webhooks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:l,secret:h,eventMask:f})});if(!u.ok)throw new Error(await Qe(u,t("webhook.createFailed")))},onSuccess:async()=>{c(""),p(""),a(Ke),await o.invalidateQueries({queryKey:["webhooks"]}),b.success(t("common.success"))},onError:u=>{b.error(u instanceof Error?u.message:t("common.error"))}}),r=M({mutationFn:async u=>{const w=await fetch(`/api/webhooks/${u}`,{method:"DELETE"});if(!w.ok)throw new Error(await Qe(w,t("webhook.deleteFailed")))},onSuccess:async()=>{await o.invalidateQueries({queryKey:["webhooks"]}),b.success(t("common.success"))},onError:u=>{b.error(u instanceof Error?u.message:t("common.error"))}}),m=((d=n.data)==null?void 0:d.webhooks)??[];return e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("webhook.title")})}),e.jsxs(H,{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:t("webhook.url")}),e.jsx(D,{id:"webhook-url-input","data-testid":"webhook-url-input",value:l,onChange:u=>c(u.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:t("webhook.secret")}),e.jsx(D,{id:"webhook-secret-input","data-testid":"webhook-secret-input",value:h,onChange:u=>p(u.target.value),placeholder:t("webhook.secretPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs(k,{variant:"secondary",className:"w-full md:w-auto","data-testid":"webhook-add",onClick:()=>i.mutate(),disabled:i.isPending||!l.trim()||!h.trim()||f.length===0,children:[i.isPending?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),t("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:t("webhook.eventMask")}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:Ke.map(u=>{const w=f.includes(u);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:t(`notification.eventType.${u}`)}),e.jsx(_,{checked:w,"data-testid":`webhook-event-${u}`,onCheckedChange:j=>{a(g=>j?g.includes(u)?g:[...g,u]:g.filter(C=>C!==u))}})]},u)})})]}),e.jsxs("div",{className:"space-y-2",children:[n.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!n.isLoading&&m.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("webhook.empty")}),m.map(u=>e.jsxs("div",{"data-testid":"webhook-item","data-webhook-url":u.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:u.url}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(u.createdAt).toLocaleString(Xe(s))})]}),e.jsx(k,{variant:"ghost",size:"icon-sm","data-testid":"webhook-delete",onClick:()=>r.mutate(u.id),disabled:r.isPending,"aria-label":t("common.delete"),title:t("common.delete"),children:e.jsx(te,{className:"h-4 w-4"})})]},u.id))]})]})]})}var Ps=Object.defineProperty,$e=Object.getOwnPropertySymbols,pt=Object.prototype.hasOwnProperty,wt=Object.prototype.propertyIsEnumerable,ct=(t,o,s)=>o in t?Ps(t,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[o]=s,Ge=(t,o)=>{for(var s in o||(o={}))pt.call(o,s)&&ct(t,s,o[s]);if($e)for(var s of $e(o))wt.call(o,s)&&ct(t,s,o[s]);return t},We=(t,o)=>{var s={};for(var l in t)pt.call(t,l)&&o.indexOf(l)<0&&(s[l]=t[l]);if(t!=null&&$e)for(var l of $e(t))o.indexOf(l)<0&&wt.call(t,l)&&(s[l]=t[l]);return s};/**
|
|
32
|
+
* @license QR Code generator library (TypeScript)
|
|
33
|
+
* Copyright (c) Project Nayuki.
|
|
34
|
+
* SPDX-License-Identifier: MIT
|
|
35
|
+
*/var se;(t=>{const o=class S{constructor(a,n,i,r){if(this.version=a,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],a<S.MIN_VERSION||a>S.MAX_VERSION)throw new RangeError("Version value out of range");if(r<-1||r>7)throw new RangeError("Mask value out of range");this.size=a*4+17;let m=[];for(let u=0;u<this.size;u++)m.push(!1);for(let u=0;u<this.size;u++)this.modules.push(m.slice()),this.isFunction.push(m.slice());this.drawFunctionPatterns();const d=this.addEccAndInterleave(i);if(this.drawCodewords(d),r==-1){let u=1e9;for(let w=0;w<8;w++){this.applyMask(w),this.drawFormatBits(w);const j=this.getPenaltyScore();j<u&&(r=w,u=j),this.applyMask(w)}}c(0<=r&&r<=7),this.mask=r,this.applyMask(r),this.drawFormatBits(r),this.isFunction=[]}static encodeText(a,n){const i=t.QrSegment.makeSegments(a);return S.encodeSegments(i,n)}static encodeBinary(a,n){const i=t.QrSegment.makeBytes(a);return S.encodeSegments([i],n)}static encodeSegments(a,n,i=1,r=40,m=-1,d=!0){if(!(S.MIN_VERSION<=i&&i<=r&&r<=S.MAX_VERSION)||m<-1||m>7)throw new RangeError("Invalid value");let u,w;for(u=i;;u++){const x=S.getNumDataCodewords(u,n)*8,N=p.getTotalBits(a,u);if(N<=x){w=N;break}if(u>=r)throw new RangeError("Data too long")}for(const x of[S.Ecc.MEDIUM,S.Ecc.QUARTILE,S.Ecc.HIGH])d&&w<=S.getNumDataCodewords(u,x)*8&&(n=x);let j=[];for(const x of a){s(x.mode.modeBits,4,j),s(x.numChars,x.mode.numCharCountBits(u),j);for(const N of x.getData())j.push(N)}c(j.length==w);const g=S.getNumDataCodewords(u,n)*8;c(j.length<=g),s(0,Math.min(4,g-j.length),j),s(0,(8-j.length%8)%8,j),c(j.length%8==0);for(let x=236;j.length<g;x^=253)s(x,8,j);let C=[];for(;C.length*8<j.length;)C.push(0);return j.forEach((x,N)=>C[N>>>3]|=x<<7-(N&7)),new S(u,n,C,m)}getModule(a,n){return 0<=a&&a<this.size&&0<=n&&n<this.size&&this.modules[n][a]}getModules(){return this.modules}drawFunctionPatterns(){for(let i=0;i<this.size;i++)this.setFunctionModule(6,i,i%2==0),this.setFunctionModule(i,6,i%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const a=this.getAlignmentPatternPositions(),n=a.length;for(let i=0;i<n;i++)for(let r=0;r<n;r++)i==0&&r==0||i==0&&r==n-1||i==n-1&&r==0||this.drawAlignmentPattern(a[i],a[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(a){const n=this.errorCorrectionLevel.formatBits<<3|a;let i=n;for(let m=0;m<10;m++)i=i<<1^(i>>>9)*1335;const r=(n<<10|i)^21522;c(r>>>15==0);for(let m=0;m<=5;m++)this.setFunctionModule(8,m,l(r,m));this.setFunctionModule(8,7,l(r,6)),this.setFunctionModule(8,8,l(r,7)),this.setFunctionModule(7,8,l(r,8));for(let m=9;m<15;m++)this.setFunctionModule(14-m,8,l(r,m));for(let m=0;m<8;m++)this.setFunctionModule(this.size-1-m,8,l(r,m));for(let m=8;m<15;m++)this.setFunctionModule(8,this.size-15+m,l(r,m));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let a=this.version;for(let i=0;i<12;i++)a=a<<1^(a>>>11)*7973;const n=this.version<<12|a;c(n>>>18==0);for(let i=0;i<18;i++){const r=l(n,i),m=this.size-11+i%3,d=Math.floor(i/3);this.setFunctionModule(m,d,r),this.setFunctionModule(d,m,r)}}drawFinderPattern(a,n){for(let i=-4;i<=4;i++)for(let r=-4;r<=4;r++){const m=Math.max(Math.abs(r),Math.abs(i)),d=a+r,u=n+i;0<=d&&d<this.size&&0<=u&&u<this.size&&this.setFunctionModule(d,u,m!=2&&m!=4)}}drawAlignmentPattern(a,n){for(let i=-2;i<=2;i++)for(let r=-2;r<=2;r++)this.setFunctionModule(a+r,n+i,Math.max(Math.abs(r),Math.abs(i))!=1)}setFunctionModule(a,n,i){this.modules[n][a]=i,this.isFunction[n][a]=!0}addEccAndInterleave(a){const n=this.version,i=this.errorCorrectionLevel;if(a.length!=S.getNumDataCodewords(n,i))throw new RangeError("Invalid argument");const r=S.NUM_ERROR_CORRECTION_BLOCKS[i.ordinal][n],m=S.ECC_CODEWORDS_PER_BLOCK[i.ordinal][n],d=Math.floor(S.getNumRawDataModules(n)/8),u=r-d%r,w=Math.floor(d/r);let j=[];const g=S.reedSolomonComputeDivisor(m);for(let x=0,N=0;x<r;x++){let E=a.slice(N,N+w-m+(x<u?0:1));N+=E.length;const z=S.reedSolomonComputeRemainder(E,g);x<u&&E.push(0),j.push(E.concat(z))}let C=[];for(let x=0;x<j[0].length;x++)j.forEach((N,E)=>{(x!=w-m||E>=u)&&C.push(N[x])});return c(C.length==d),C}drawCodewords(a){if(a.length!=Math.floor(S.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let n=0;for(let i=this.size-1;i>=1;i-=2){i==6&&(i=5);for(let r=0;r<this.size;r++)for(let m=0;m<2;m++){const d=i-m,w=(i+1&2)==0?this.size-1-r:r;!this.isFunction[w][d]&&n<a.length*8&&(this.modules[w][d]=l(a[n>>>3],7-(n&7)),n++)}}c(n==a.length*8)}applyMask(a){if(a<0||a>7)throw new RangeError("Mask value out of range");for(let n=0;n<this.size;n++)for(let i=0;i<this.size;i++){let r;switch(a){case 0:r=(i+n)%2==0;break;case 1:r=n%2==0;break;case 2:r=i%3==0;break;case 3:r=(i+n)%3==0;break;case 4:r=(Math.floor(i/3)+Math.floor(n/2))%2==0;break;case 5:r=i*n%2+i*n%3==0;break;case 6:r=(i*n%2+i*n%3)%2==0;break;case 7:r=((i+n)%2+i*n%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[n][i]&&r&&(this.modules[n][i]=!this.modules[n][i])}}getPenaltyScore(){let a=0;for(let m=0;m<this.size;m++){let d=!1,u=0,w=[0,0,0,0,0,0,0];for(let j=0;j<this.size;j++)this.modules[m][j]==d?(u++,u==5?a+=S.PENALTY_N1:u>5&&a++):(this.finderPenaltyAddHistory(u,w),d||(a+=this.finderPenaltyCountPatterns(w)*S.PENALTY_N3),d=this.modules[m][j],u=1);a+=this.finderPenaltyTerminateAndCount(d,u,w)*S.PENALTY_N3}for(let m=0;m<this.size;m++){let d=!1,u=0,w=[0,0,0,0,0,0,0];for(let j=0;j<this.size;j++)this.modules[j][m]==d?(u++,u==5?a+=S.PENALTY_N1:u>5&&a++):(this.finderPenaltyAddHistory(u,w),d||(a+=this.finderPenaltyCountPatterns(w)*S.PENALTY_N3),d=this.modules[j][m],u=1);a+=this.finderPenaltyTerminateAndCount(d,u,w)*S.PENALTY_N3}for(let m=0;m<this.size-1;m++)for(let d=0;d<this.size-1;d++){const u=this.modules[m][d];u==this.modules[m][d+1]&&u==this.modules[m+1][d]&&u==this.modules[m+1][d+1]&&(a+=S.PENALTY_N2)}let n=0;for(const m of this.modules)n=m.reduce((d,u)=>d+(u?1:0),n);const i=this.size*this.size,r=Math.ceil(Math.abs(n*20-i*10)/i)-1;return c(0<=r&&r<=9),a+=r*S.PENALTY_N4,c(0<=a&&a<=2568888),a}getAlignmentPatternPositions(){if(this.version==1)return[];{const a=Math.floor(this.version/7)+2,n=this.version==32?26:Math.ceil((this.version*4+4)/(a*2-2))*2;let i=[6];for(let r=this.size-7;i.length<a;r-=n)i.splice(1,0,r);return i}}static getNumRawDataModules(a){if(a<S.MIN_VERSION||a>S.MAX_VERSION)throw new RangeError("Version number out of range");let n=(16*a+128)*a+64;if(a>=2){const i=Math.floor(a/7)+2;n-=(25*i-10)*i-55,a>=7&&(n-=36)}return c(208<=n&&n<=29648),n}static getNumDataCodewords(a,n){return Math.floor(S.getNumRawDataModules(a)/8)-S.ECC_CODEWORDS_PER_BLOCK[n.ordinal][a]*S.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][a]}static reedSolomonComputeDivisor(a){if(a<1||a>255)throw new RangeError("Degree out of range");let n=[];for(let r=0;r<a-1;r++)n.push(0);n.push(1);let i=1;for(let r=0;r<a;r++){for(let m=0;m<n.length;m++)n[m]=S.reedSolomonMultiply(n[m],i),m+1<n.length&&(n[m]^=n[m+1]);i=S.reedSolomonMultiply(i,2)}return n}static reedSolomonComputeRemainder(a,n){let i=n.map(r=>0);for(const r of a){const m=r^i.shift();i.push(0),n.forEach((d,u)=>i[u]^=S.reedSolomonMultiply(d,m))}return i}static reedSolomonMultiply(a,n){if(a>>>8||n>>>8)throw new RangeError("Byte out of range");let i=0;for(let r=7;r>=0;r--)i=i<<1^(i>>>7)*285,i^=(n>>>r&1)*a;return c(i>>>8==0),i}finderPenaltyCountPatterns(a){const n=a[1];c(n<=this.size*3);const i=n>0&&a[2]==n&&a[3]==n*3&&a[4]==n&&a[5]==n;return(i&&a[0]>=n*4&&a[6]>=n?1:0)+(i&&a[6]>=n*4&&a[0]>=n?1:0)}finderPenaltyTerminateAndCount(a,n,i){return a&&(this.finderPenaltyAddHistory(n,i),n=0),n+=this.size,this.finderPenaltyAddHistory(n,i),this.finderPenaltyCountPatterns(i)}finderPenaltyAddHistory(a,n){n[0]==0&&(a+=this.size),n.pop(),n.unshift(a)}};o.MIN_VERSION=1,o.MAX_VERSION=40,o.PENALTY_N1=3,o.PENALTY_N2=3,o.PENALTY_N3=40,o.PENALTY_N4=10,o.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],o.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],t.QrCode=o;function s(f,a,n){if(a<0||a>31||f>>>a)throw new RangeError("Value out of range");for(let i=a-1;i>=0;i--)n.push(f>>>i&1)}function l(f,a){return(f>>>a&1)!=0}function c(f){if(!f)throw new Error("Assertion error")}const h=class R{constructor(a,n,i){if(this.mode=a,this.numChars=n,this.bitData=i,n<0)throw new RangeError("Invalid argument");this.bitData=i.slice()}static makeBytes(a){let n=[];for(const i of a)s(i,8,n);return new R(R.Mode.BYTE,a.length,n)}static makeNumeric(a){if(!R.isNumeric(a))throw new RangeError("String contains non-numeric characters");let n=[];for(let i=0;i<a.length;){const r=Math.min(a.length-i,3);s(parseInt(a.substring(i,i+r),10),r*3+1,n),i+=r}return new R(R.Mode.NUMERIC,a.length,n)}static makeAlphanumeric(a){if(!R.isAlphanumeric(a))throw new RangeError("String contains unencodable characters in alphanumeric mode");let n=[],i;for(i=0;i+2<=a.length;i+=2){let r=R.ALPHANUMERIC_CHARSET.indexOf(a.charAt(i))*45;r+=R.ALPHANUMERIC_CHARSET.indexOf(a.charAt(i+1)),s(r,11,n)}return i<a.length&&s(R.ALPHANUMERIC_CHARSET.indexOf(a.charAt(i)),6,n),new R(R.Mode.ALPHANUMERIC,a.length,n)}static makeSegments(a){return a==""?[]:R.isNumeric(a)?[R.makeNumeric(a)]:R.isAlphanumeric(a)?[R.makeAlphanumeric(a)]:[R.makeBytes(R.toUtf8ByteArray(a))]}static makeEci(a){let n=[];if(a<0)throw new RangeError("ECI assignment value out of range");if(a<128)s(a,8,n);else if(a<16384)s(2,2,n),s(a,14,n);else if(a<1e6)s(6,3,n),s(a,21,n);else throw new RangeError("ECI assignment value out of range");return new R(R.Mode.ECI,0,n)}static isNumeric(a){return R.NUMERIC_REGEX.test(a)}static isAlphanumeric(a){return R.ALPHANUMERIC_REGEX.test(a)}getData(){return this.bitData.slice()}static getTotalBits(a,n){let i=0;for(const r of a){const m=r.mode.numCharCountBits(n);if(r.numChars>=1<<m)return 1/0;i+=4+m+r.bitData.length}return i}static toUtf8ByteArray(a){a=encodeURI(a);let n=[];for(let i=0;i<a.length;i++)a.charAt(i)!="%"?n.push(a.charCodeAt(i)):(n.push(parseInt(a.substring(i+1,i+3),16)),i+=2);return n}};h.NUMERIC_REGEX=/^[0-9]*$/,h.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,h.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let p=h;t.QrSegment=h})(se||(se={}));(t=>{(o=>{const s=class{constructor(c,h){this.ordinal=c,this.formatBits=h}};s.LOW=new s(0,1),s.MEDIUM=new s(1,0),s.QUARTILE=new s(2,3),s.HIGH=new s(3,2),o.Ecc=s})(t.QrCode||(t.QrCode={}))})(se||(se={}));(t=>{(o=>{const s=class{constructor(c,h){this.modeBits=c,this.numBitsCharCount=h}numCharCountBits(c){return this.numBitsCharCount[Math.floor((c+7)/17)]}};s.NUMERIC=new s(1,[10,12,14]),s.ALPHANUMERIC=new s(2,[9,11,13]),s.BYTE=new s(4,[8,16,16]),s.KANJI=new s(8,[8,10,12]),s.ECI=new s(7,[0,0,0]),o.Mode=s})(t.QrSegment||(t.QrSegment={}))})(se||(se={}));var oe=se;/**
|
|
36
|
+
* @license qrcode.react
|
|
37
|
+
* Copyright (c) Paul O'Shannessy
|
|
38
|
+
* SPDX-License-Identifier: ISC
|
|
39
|
+
*/var Fs={L:oe.QrCode.Ecc.LOW,M:oe.QrCode.Ecc.MEDIUM,Q:oe.QrCode.Ecc.QUARTILE,H:oe.QrCode.Ecc.HIGH},yt=128,jt="L",vt="#FFFFFF",bt="#000000",Nt=!1,Ct=1,As=4,Ts=0,Rs=.1;function Et(t,o=0){const s=[];return t.forEach(function(l,c){let h=null;l.forEach(function(p,f){if(!p&&h!==null){s.push(`M${h+o} ${c+o}h${f-h}v1H${h+o}z`),h=null;return}if(f===l.length-1){if(!p)return;h===null?s.push(`M${f+o},${c+o} h1v1H${f+o}z`):s.push(`M${h+o},${c+o} h${f+1-h}v1H${h+o}z`);return}p&&h===null&&(h=f)})}),s.join("")}function kt(t,o){return t.slice().map((s,l)=>l<o.y||l>=o.y+o.h?s:s.map((c,h)=>h<o.x||h>=o.x+o.w?c:!1))}function Is(t,o,s,l){if(l==null)return null;const c=t.length+s*2,h=Math.floor(o*Rs),p=c/o,f=(l.width||h)*p,a=(l.height||h)*p,n=l.x==null?t.length/2-f/2:l.x*p,i=l.y==null?t.length/2-a/2:l.y*p,r=l.opacity==null?1:l.opacity;let m=null;if(l.excavate){let u=Math.floor(n),w=Math.floor(i),j=Math.ceil(f+n-u),g=Math.ceil(a+i-w);m={x:u,y:w,w:j,h:g}}const d=l.crossOrigin;return{x:n,y:i,h:a,w:f,excavation:m,opacity:r,crossOrigin:d}}function Ls(t,o){return o!=null?Math.max(Math.floor(o),0):t?As:Ts}function St({value:t,level:o,minVersion:s,includeMargin:l,marginSize:c,imageSettings:h,size:p,boostLevel:f}){let a=$.useMemo(()=>{const u=(Array.isArray(t)?t:[t]).reduce((w,j)=>(w.push(...oe.QrSegment.makeSegments(j)),w),[]);return oe.QrCode.encodeSegments(u,Fs[o],s,void 0,void 0,f)},[t,o,s,f]);const{cells:n,margin:i,numCells:r,calculatedImageSettings:m}=$.useMemo(()=>{let d=a.getModules();const u=Ls(l,c),w=d.length+u*2,j=Is(d,p,u,h);return{cells:d,margin:u,numCells:w,calculatedImageSettings:j}},[a,p,h,l,c]);return{qrcode:a,margin:i,cells:n,numCells:r,calculatedImageSettings:m}}var $s=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),Ds=$.forwardRef(function(o,s){const l=o,{value:c,size:h=yt,level:p=jt,bgColor:f=vt,fgColor:a=bt,includeMargin:n=Nt,minVersion:i=Ct,boostLevel:r,marginSize:m,imageSettings:d}=l,w=We(l,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:j}=w,g=We(w,["style"]),C=d==null?void 0:d.src,x=$.useRef(null),N=$.useRef(null),E=$.useCallback(V=>{x.current=V,typeof s=="function"?s(V):s&&(s.current=V)},[s]),[z,P]=$.useState(!1),{margin:A,cells:T,numCells:I,calculatedImageSettings:L}=St({value:c,level:p,minVersion:i,boostLevel:r,includeMargin:n,marginSize:m,imageSettings:d,size:h});$.useEffect(()=>{if(x.current!=null){const V=x.current,J=V.getContext("2d");if(!J)return;let Me=T;const X=N.current,me=L!=null&&X!==null&&X.complete&&X.naturalHeight!==0&&X.naturalWidth!==0;me&&L.excavation!=null&&(Me=kt(T,L.excavation));const Pe=window.devicePixelRatio||1;V.height=V.width=h*Pe;const ue=h/I*Pe;J.scale(ue,ue),J.fillStyle=f,J.fillRect(0,0,I,I),J.fillStyle=a,$s?J.fill(new Path2D(Et(Me,A))):T.forEach(function(Fe,Ae){Fe.forEach(function(v,B){v&&J.fillRect(B+A,Ae+A,1,1)})}),L&&(J.globalAlpha=L.opacity),me&&J.drawImage(X,L.x+A,L.y+A,L.w,L.h)}}),$.useEffect(()=>{P(!1)},[C]);const Y=Ge({height:h,width:h},j);let q=null;return C!=null&&(q=$.createElement("img",{src:C,key:C,style:{display:"none"},onLoad:()=>{P(!0)},ref:N,crossOrigin:L==null?void 0:L.crossOrigin})),$.createElement($.Fragment,null,$.createElement("canvas",Ge({style:Y,height:h,width:h,ref:E,role:"img"},g)),q)});Ds.displayName="QRCodeCanvas";var Mt=$.forwardRef(function(o,s){const l=o,{value:c,size:h=yt,level:p=jt,bgColor:f=vt,fgColor:a=bt,includeMargin:n=Nt,minVersion:i=Ct,boostLevel:r,title:m,marginSize:d,imageSettings:u}=l,w=We(l,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:j,cells:g,numCells:C,calculatedImageSettings:x}=St({value:c,level:p,minVersion:i,boostLevel:r,includeMargin:n,marginSize:d,imageSettings:u,size:h});let N=g,E=null;u!=null&&x!=null&&(x.excavation!=null&&(N=kt(g,x.excavation)),E=$.createElement("image",{href:u.src,height:x.h,width:x.w,x:x.x+j,y:x.y+j,preserveAspectRatio:"none",opacity:x.opacity,crossOrigin:x.crossOrigin}));const z=Et(N,j);return $.createElement("svg",Ge({height:h,width:h,viewBox:`0 0 ${C} ${C}`,ref:s,role:"img"},w),!!m&&$.createElement("title",null,m),$.createElement("path",{fill:f,d:`M0,0 h${C}v${C}H0z`,shapeRendering:"crispEdges"}),$.createElement("path",{fill:a,d:z,shapeRendering:"crispEdges"}),E)});Mt.displayName="QRCodeSVG";const Ie=1500;async function he(t,o){try{return(await t.json()).error??o}catch{return o}}function Pt({open:t,onOpenChange:o,accountId:s,accountName:l}){const{t:c}=F(),h=O(),[p,f]=y.useState(null),[a,n]=y.useState("starting"),[i,r]=y.useState(null),m=y.useRef(null),d=y.useRef(0),u=y.useRef(null),w=y.useCallback(()=>{m.current!==null&&(clearTimeout(m.current),m.current=null)},[]),j=y.useCallback(()=>{var P;w(),(P=u.current)==null||P.abort(),u.current=null,d.current+=1},[w]),g=y.useCallback(async()=>{j(),await h.invalidateQueries({queryKey:["weixin-accounts"]}),b.success(c("weixin.bindSuccess")),o(!1)},[j,o,h,c]),C=y.useCallback(async(P,A,T)=>{try{const I=await fetch(`/api/settings/weixin/accounts/${s}/users`,{signal:A});if(d.current!==P)return;if(!I.ok)throw new Error(await he(I,c("weixin.loginFailed")));const L=await I.json();if(d.current!==P)return;const Y=L.users.find(q=>!T.has(q.userId)||q.lastInboundAt!==T.get(q.userId));if(Y){if(n("binding"),r(c("weixin.bindingInProgress")),Y.status==="pending"){const q=await fetch(`/api/settings/weixin/accounts/${s}/users/${encodeURIComponent(Y.userId)}/approve`,{method:"POST",signal:A});if(d.current!==P)return;if(!q.ok)throw new Error(await he(q,c("weixin.approveFailed")))}await g();return}m.current=setTimeout(()=>void C(P,A,T),Ie)}catch(I){if(A.aborted||d.current!==P)return;n("error"),r(I instanceof Error?I.message:c("weixin.loginFailed"))}},[s,g,c]),x=y.useCallback(async(P,A)=>{try{const T=await fetch(`/api/settings/weixin/accounts/${s}/login/status`,{signal:A});if(d.current!==P)return;if(!T.ok)throw new Error(await he(T,c("weixin.loginFailed")));const I=await T.json();if(d.current!==P)return;if(I.status==="expired"){n("expired"),r(c("weixin.loginExpired"));return}if(I.status==="error"){n("error"),r(c("weixin.loginError",{message:I.message??""}));return}if(I.loggedIn||I.status==="confirmed"){const L=await fetch(`/api/settings/weixin/accounts/${s}/users`,{signal:A});if(d.current!==P)return;if(!L.ok)throw new Error(await he(L,c("weixin.loginFailed")));const Y=await L.json();if(d.current!==P)return;const q=new Map(Y.users.map(V=>[V.userId,V.lastInboundAt]));n("awaitMessage"),r(c("weixin.scanConfirmedSendHint")),m.current=setTimeout(()=>void C(P,A,q),Ie);return}n("scanning"),r(c("weixin.scanQrcodeHint")),m.current=setTimeout(()=>void x(P,A),Ie)}catch(T){if(A.aborted||d.current!==P)return;n("error"),r(T instanceof Error?T.message:c("weixin.loginFailed"))}},[s,C,c]),N=y.useCallback(async()=>{j();const P=d.current,A=new AbortController;u.current=A,n("starting"),r(null),f(null);try{const T=await fetch(`/api/settings/weixin/accounts/${s}/login/start`,{method:"POST",signal:A.signal});if(d.current!==P)return;if(!T.ok)throw new Error(await he(T,c("weixin.loginFailed")));const I=await T.json();if(d.current!==P)return;f(I.qrcodeUrl),n("scanning"),r(c("weixin.scanQrcodeHint")),m.current=setTimeout(()=>void x(P,A.signal),Ie)}catch(T){if(A.signal.aborted||d.current!==P)return;n("error"),r(T instanceof Error?T.message:c("weixin.loginFailed"))}},[s,j,x,c]);y.useEffect(()=>{if(!t){j();return}return N(),j},[t,s]);const E=a==="starting",z=a==="expired"||a==="error";return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-sm","data-testid":`weixin-account-login-modal-${s}`,children:[e.jsxs(ie,{children:[e.jsx(re,{children:c("weixin.scanToLogin")}),e.jsx(Ne,{children:l})]}),e.jsxs("div",{className:"flex flex-col items-center gap-3 py-2",children:[e.jsxs("div",{className:"flex h-56 w-56 items-center justify-center rounded-lg border border-border bg-white",children:[E&&e.jsx(Q,{className:"h-8 w-8 animate-spin text-muted-foreground"}),!E&&p&&e.jsx(Mt,{value:p,size:208,marginSize:3,"data-testid":`weixin-account-login-qrcode-${s}`}),!E&&!p&&e.jsx(Ve,{className:"h-10 w-10 text-muted-foreground"})]}),i&&e.jsx("p",{className:"text-center text-sm font-medium","data-testid":`weixin-account-login-status-${s}`,children:i})]}),e.jsxs(de,{children:[z&&e.jsxs(k,{variant:"secondary","data-testid":"weixin-account-login-refresh",onClick:()=>void N(),children:[e.jsx(Ze,{className:"h-4 w-4"}),c("weixin.refreshQrcode")]}),e.jsx(k,{variant:"outline",onClick:()=>o(!1),children:c("weixin.closeLogin")})]})]})})}const Os="min-h-10";async function dt(t,o){try{return(await t.json()).error??o}catch{return o}}function Bs({open:t,onOpenChange:o,account:s}){const{t:l}=F(),c=O(),h=!!s,[p,f]=y.useState(""),[a,n]=y.useState(!0),[i,r]=y.useState(null);y.useEffect(()=>{t&&(f((s==null?void 0:s.name)??""),n((s==null?void 0:s.enabled)??!0))},[t,s]);const m=M({mutationFn:async()=>{const g=await fetch("/api/settings/weixin/accounts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:p.trim(),enabled:a,allowAuthRequests:!0})});if(!g.ok)throw new Error(await dt(g,l("weixin.createFailed")));return await g.json()},onSuccess:async g=>{await c.invalidateQueries({queryKey:["weixin-accounts"]}),b.success(l("weixin.accountCreated")),o(!1),r({id:g.accountId,name:p.trim()})},onError:g=>{b.error(g instanceof Error?g.message:l("common.error"))}}),d=M({mutationFn:async()=>{if(!s)throw new Error(l("weixin.updateFailed"));const g=await fetch(`/api/settings/weixin/accounts/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:p.trim(),enabled:a})});if(!g.ok)throw new Error(await dt(g,l("weixin.updateFailed")))},onSuccess:async()=>{await c.invalidateQueries({queryKey:["weixin-accounts"]}),b.success(l("weixin.accountUpdated")),o(!1)},onError:g=>{b.error(g instanceof Error?g.message:l("common.error"))}}),u=m.isPending||d.isPending,w=p.trim().length>0,j=()=>{!w||u||(h?d.mutate():m.mutate())};return e.jsxs(e.Fragment,{children:[e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":h?`weixin-account-edit-modal-${s==null?void 0:s.id}`:"weixin-account-add-modal",children:[e.jsx(ie,{children:e.jsx(re,{children:l(h?"weixin.editAccount":"weixin.addAccount")})}),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:"weixin-account-name",children:l("weixin.accountName")}),e.jsx(D,{id:"weixin-account-name","data-testid":"weixin-account-name-input",value:p,onChange:g=>f(g.target.value),placeholder:l("weixin.accountNamePlaceholder"),className:Os})]}),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:l("weixin.enableAccount")}),e.jsx(_,{checked:a,"data-testid":"weixin-account-enabled",onCheckedChange:g=>n(!!g)})]})]}),e.jsxs(de,{children:[e.jsx(k,{variant:"outline",onClick:()=>o(!1),disabled:u,children:l("common.cancel")}),e.jsxs(k,{variant:"secondary","data-testid":"weixin-account-form-submit",onClick:j,disabled:!w||u,children:[u?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})}),i&&e.jsx(Pt,{open:!!i,onOpenChange:g=>{g||r(null)},accountId:i.id,accountName:i.name})]})}async function Ue(t,o){try{return(await t.json()).error??o}catch{return o}}function _s({account:t,onEdit:o}){const{t:s}=F(),l=O(),[c,h]=y.useState(!1),p=t.loggedIn&&t.authorizedCount>0,f=M({mutationFn:async r=>{const m=await fetch(`/api/settings/weixin/accounts/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:r})});if(!m.ok)throw new Error(await Ue(m,s("weixin.updateFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["weixin-accounts"]})},onError:r=>{b.error(r instanceof Error?r.message:s("common.error"))}}),a=M({mutationFn:async()=>{const r=await fetch(`/api/settings/weixin/accounts/${t.id}/test`,{method:"POST"});if(!r.ok)throw new Error(await Ue(r,s("weixin.testMessageFailed")))},onSuccess:()=>{b.success(s("weixin.testMessageSent"))},onError:r=>{b.error(r instanceof Error?r.message:s("weixin.testMessageFailed"))}}),n=M({mutationFn:async()=>{const r=await fetch(`/api/settings/weixin/accounts/${t.id}`,{method:"DELETE"});if(!r.ok)throw new Error(await Ue(r,s("weixin.deleteFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["weixin-accounts"]}),b.success(s("weixin.accountDeleted"))},onError:r=>{b.error(r instanceof Error?r.message:s("common.error"))}}),i=t.loggedIn?p?{label:s("weixin.bound"),tone:"success"}:{label:s("weixin.unbound"),tone:"muted"}:{label:s("weixin.notLoggedIn"),tone:"muted"};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":`weixin-account-card-${t.id}`,"data-account-name":t.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(_,{checked:t.enabled,disabled:f.isPending,onCheckedChange:r=>f.mutate(!!r),"data-testid":`weixin-account-enabled-${t.id}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium",children:t.name}),e.jsx("span",{className:ut("shrink-0 rounded px-1.5 py-0.5 text-xs font-medium",i.tone==="success"?"bg-emerald-500/15 text-emerald-600 dark:text-emerald-400":"bg-muted text-muted-foreground"),"data-testid":`weixin-account-login-state-${t.id}`,children:i.label}),p&&t.needsReactivationCount>0&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 rounded bg-destructive/15 px-1.5 py-0.5 text-xs font-medium text-destructive",title:s("weixin.reactivationHint"),"data-testid":`weixin-account-needs-reactivation-${t.id}`,children:[e.jsx(ft,{className:"h-3.5 w-3.5"}),s("weixin.needsReactivation")]})]}),p&&t.needsReactivationCount>0&&e.jsx("div",{className:"mt-0.5 text-xs text-muted-foreground",children:s("weixin.reactivationHint")})]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-1",children:[p?e.jsxs(e.Fragment,{children:[e.jsxs(k,{variant:"ghost",size:"sm","data-testid":`weixin-account-relogin-${t.id}`,onClick:()=>h(!0),children:[e.jsx(Ve,{className:"h-4 w-4"}),s("weixin.relogin")]}),e.jsxs(k,{variant:"ghost",size:"sm","data-testid":`weixin-account-test-${t.id}`,onClick:()=>a.mutate(),disabled:a.isPending,children:[e.jsx(xt,{className:"h-4 w-4"}),s("weixin.testMessage")]})]}):e.jsxs(k,{variant:"secondary",size:"sm","data-testid":`weixin-account-login-${t.id}`,onClick:()=>h(!0),children:[e.jsx(Ve,{className:"h-4 w-4"}),s("weixin.bindAction")]}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`weixin-account-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(De,{className:"h-4 w-4"})}),e.jsx(k,{variant:"ghost",size:"icon-sm",title:s("weixin.deleteAccount"),"data-testid":`weixin-account-delete-${t.id}`,onClick:()=>n.mutate(),disabled:n.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(Pt,{open:c,onOpenChange:h,accountId:t.id,accountName:t.name})]})}async function zs(t,o){try{return(await t.json()).error??o}catch{return o}}function qs(){var n;const{t}=F(),[o,s]=y.useState(!1),[l,c]=y.useState(void 0),h=K({queryKey:["weixin-accounts"],queryFn:async()=>{const i=await fetch("/api/settings/weixin/accounts");if(!i.ok)throw new Error(await zs(i,t("weixin.loadAccountsFailed")));return await i.json()}}),p=((n=h.data)==null?void 0:n.accounts)??[],f=()=>{c(void 0),s(!0)},a=i=>{c(i),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{className:"flex flex-row items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(W,{children:t("weixin.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("weixin.subtitle")})]}),e.jsxs(k,{variant:"secondary","data-testid":"weixin-add-account",onClick:f,children:[e.jsx(ge,{className:"h-4 w-4"}),t("weixin.addAccount")]})]}),e.jsxs(H,{className:"space-y-3",children:[e.jsx("p",{className:"rounded-lg border border-border bg-muted/40 p-3 text-xs text-muted-foreground",children:t("weixin.replyOnlyNotice")}),h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&p.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("weixin.noAccounts")}),p.map(i=>e.jsx(_s,{account:i,onEdit:a},i.id))]})]}),e.jsx(Bs,{open:o,onOpenChange:s,account:l})]})}async function Je(t,o){try{return(await t.json()).error??o}catch{return o}}function ea(){var Fe,Ae;const{t}=F(),o=O(),{refreshSettings:s}=Oe(),[l,c]=y.useState("general"),h=et(v=>v.theme),p=et(v=>v.setTheme),f=h==="dark",[a,n]=y.useState("tmex"),[i,r]=y.useState(window.location.origin),[m,d]=y.useState("en_US"),[u,w]=y.useState(6),[j,g]=y.useState(3),[C,x]=y.useState(!0),[N,E]=y.useState(!0),[z,P]=y.useState(!0),[A,T]=y.useState(!0),[I,L]=y.useState(2),[Y,q]=y.useState(10),[V,J]=y.useState(!1),Me=v=>{const B=v?"dark":"light";p(B),document.documentElement.classList.toggle("dark",B==="dark")},X=K({queryKey:["site-settings"],queryFn:async()=>{const v=await fetch("/api/settings/site");if(!v.ok)throw new Error(await Je(v,t("settings.loadFailed")));return await v.json()}});y.useEffect(()=>{var B;const v=(B=X.data)==null?void 0:B.settings;v&&(n(v.siteName),r(v.siteUrl),d(v.language??"en_US"),w(v.bellThrottleSeconds),g(v.notificationThrottleSeconds??3),x(v.enableBrowserNotificationToast??!0),E(v.enableNotificationPush??!0),P(v.enableBellPush??!0),T(v.enableBellSound??!0))},[(Fe=X.data)==null?void 0:Fe.settings]);const me=M({mutationFn:async()=>{const B=await fetch("/api/settings/site",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({siteName:a,siteUrl:i,language:m,bellThrottleSeconds:u,notificationThrottleSeconds:j,enableBrowserNotificationToast:C,enableNotificationPush:N,enableBellPush:z,enableBellSound:A,sshReconnectMaxRetries:I,sshReconnectDelaySeconds:Y})});if(!B.ok)throw new Error(await Je(B,t("settings.saveFailed")))},onSuccess:async()=>{var v,B;await Promise.all([o.invalidateQueries({queryKey:["site-settings"]}),s()]),b.success(t("settings.settingsSaved")),((B=(v=X.data)==null?void 0:v.settings)==null?void 0:B.language)!==m&&(qt.changeLanguage(m),J(!0))},onError:v=>{b.error(v instanceof Error?v.message:t("common.error"))}}),Pe=[{value:"general",label:t("settings.tabGroup.general"),icon:Lt,testId:"settings-tab-general"},{value:"terminal",label:t("settings.tabGroup.terminal"),icon:Ye,testId:"settings-tab-terminal"},{value:"devicesAndFiles",label:t("settings.tabGroup.devicesAndFiles"),icon:ss,testId:"settings-tab-devicesAndFiles"},{value:"notifications",label:t("settings.tabGroup.notifications"),icon:$t,testId:"settings-tab-notifications"},{value:"ai",label:t("settings.tabGroup.ai"),icon:Dt,testId:"settings-tab-ai"}],ue=e.jsx("div",{className:"flex justify-end pt-2",children:e.jsxs(k,{variant:"secondary","data-testid":"settings-save",onClick:()=>me.mutate(),disabled:me.isPending,className:"w-full sm:w-auto",children:[e.jsx(ee,{className:"h-4 w-4"}),t("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(Ot,{value:l,onValueChange:v=>c(v),children:e.jsx(Bt,{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:Pe.map(v=>{const B=v.icon;return e.jsxs(_t,{value:v.value,"data-testid":v.testId,className:ut(zt,"min-w-max gap-2 px-3.5"),children:[e.jsx(B,{}),v.label]},v.value)})})}),l==="general"&&e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.siteSettings")})}),e.jsxs(H,{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:t("settings.siteName")}),e.jsx(D,{id:"site-name-input",value:a,onChange:v=>n(v.target.value),placeholder:t("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:t("settings.siteUrl")}),e.jsx(D,{id:"site-url-input",value:i,onChange:v=>r(v.target.value),placeholder:t("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:t("settings.language")}),e.jsxs(Ce,{value:m,onValueChange:v=>{v&&d(v)},children:[e.jsx(Ee,{id:"language-select","data-testid":"settings-language-select",className:"w-full min-h-10",children:e.jsx(ke,{placeholder:t("settings.language"),children:((Ae=tt.locales.find(v=>v.code===m))==null?void 0:Ae.nativeName)??m})}),e.jsx(Se,{className:"max-h-[var(--tmex-viewport-height)]",children:tt.locales.map(v=>e.jsx(le,{value:v.code,children:v.nativeName},v.code))})]}),V&&e.jsx("p",{className:"mt-1 text-xs text-primary","data-testid":"settings-refresh-notice",children:t("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:t("settings.theme")})}),e.jsx(_,{checked:f,onCheckedChange:v=>Me(!!v),"data-testid":"settings-theme-toggle"})]})}),ue]})]}),e.jsx(Ss,{})]}),l==="devicesAndFiles"&&e.jsxs(e.Fragment,{children:[e.jsx(rs,{}),e.jsx(os,{})]}),l==="notifications"&&e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"border-0 ring-0",children:e.jsxs(H,{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:t("settings.enableNotificationPush")})}),e.jsx(_,{checked:N,onCheckedChange:v=>E(!!v),"data-testid":"settings-enable-notification-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:t("settings.enableBellPush")})}),e.jsx(_,{checked:z,onCheckedChange:v=>P(!!v),"data-testid":"settings-enable-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:t("settings.enableBellSound")})}),e.jsx(_,{checked:A,onCheckedChange:v=>T(!!v),"data-testid":"settings-enable-bell-sound"})]}),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:t("settings.enableBrowserNotificationToast")})}),e.jsx(_,{checked:C,onCheckedChange:v=>x(!!v),"data-testid":"settings-enable-browser-notification-toast"})]})]}),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:t("settings.bellThrottle")}),e.jsx(D,{id:"bell-throttle-input",type:"number",value:u,min:0,max:300,onChange:v=>w(Number(v.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:t("settings.notificationThrottle")}),e.jsx(D,{id:"notification-throttle-input",type:"number",value:j,min:0,max:300,onChange:v=>g(Number(v.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:t("settings.sshReconnectMaxRetries")}),e.jsx(D,{id:"ssh-reconnect-retries-input",type:"number",value:I,min:0,max:20,onChange:v=>L(Number(v.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:t("settings.sshReconnectDelay")}),e.jsx(D,{id:"ssh-reconnect-delay-input",type:"number",value:Y,min:1,max:300,onChange:v=>q(Number(v.target.value)),className:"min-h-10"})]})]}),ue]})}),e.jsx(Es,{}),e.jsx(qs,{}),e.jsx(Ms,{})]}),l==="ai"&&e.jsxs(e.Fragment,{children:[e.jsx(ps,{}),e.jsx(js,{})]}),l==="terminal"&&e.jsx(ks,{})]})}function ta(){const{t}=F();return e.jsx(e.Fragment,{children:t("sidebar.settings")})}function sa(){const{t}=F(),[o,s]=y.useState(!1),l=M({mutationFn:async()=>{const c=await fetch("/api/settings/restart",{method:"POST"});if(!c.ok)throw new Error(await Je(c,t("settings.restartFailed")))},onSuccess:()=>{b.success(t("settings.restartScheduled"))},onError:c=>{b.error(c instanceof Error?c.message:t("common.error"))}});return e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"ghost",size:"icon-sm",onClick:()=>s(!0),disabled:l.isPending,"aria-label":t("settings.restartGateway"),title:t("settings.restartGateway"),className:"text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(Wt,{className:"h-4 w-4"})}),e.jsx(xe,{open:o,onOpenChange:s,children:e.jsxs(fe,{children:[e.jsxs(pe,{children:[e.jsx(we,{children:t("settings.restartGateway")}),e.jsx(ye,{children:t("settings.restartConfirm")})]}),e.jsxs(je,{children:[e.jsx(ve,{onClick:()=>s(!1),children:t("common.cancel")}),e.jsx(be,{variant:"destructive",onClick:()=>{l.mutate(),s(!1)},children:t("common.confirm")})]})]})})]})}export{sa as PageActions,ta as PageTitle,ea as default};
|