tmex-cli 0.16.5 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -4
- package/dist/runtime/server.js +702 -337
- package/package.json +2 -1
- package/resources/fe-dist/assets/DevicePage-B-4Wp5gx.js +24 -0
- package/resources/fe-dist/assets/{DevicesPage-XMtf7VIy.js → DevicesPage-D3GQd_MI.js} +1 -1
- package/resources/fe-dist/assets/{FilePage-C1_JLsEc.js → FilePage-C45pl7_F.js} +2 -2
- package/resources/fe-dist/assets/SettingsPage-DEkQrJzi.js +39 -0
- package/resources/fe-dist/assets/{agent-tab-BgvIAv35.js → agent-tab-BnKrqJP2.js} +2 -2
- package/resources/fe-dist/assets/api-5IhJ49aS.js +5 -0
- package/resources/fe-dist/assets/{arc-BX-Po9p7.js → arc-DBxiTdY2.js} +1 -1
- package/resources/fe-dist/assets/{architectureDiagram-3BPJPVTR-BneOtjGd.js → architectureDiagram-3BPJPVTR-Dcd70ntw.js} +1 -1
- package/resources/fe-dist/assets/{blockDiagram-GPEHLZMM-Dcf0shYG.js → blockDiagram-GPEHLZMM-LsFpH20h.js} +1 -1
- package/resources/fe-dist/assets/{c4Diagram-AAUBKEIU-Cwhji_wO.js → c4Diagram-AAUBKEIU-BswGzO6B.js} +1 -1
- package/resources/fe-dist/assets/{card-IkOsEv2J.js → card-Bav-X9c4.js} +1 -1
- package/resources/fe-dist/assets/channel-hAJp4tg-.js +1 -0
- package/resources/fe-dist/assets/{chunk-2J33WTMH-IFwQoyns.js → chunk-2J33WTMH-C0yl1OR1.js} +1 -1
- package/resources/fe-dist/assets/{chunk-4BX2VUAB-BZhwH7K2.js → chunk-4BX2VUAB-Dwo9vDDk.js} +1 -1
- package/resources/fe-dist/assets/{chunk-55IACEB6-pYNojBsx.js → chunk-55IACEB6-Dz9e7vav.js} +1 -1
- package/resources/fe-dist/assets/{chunk-727SXJPM-BwBn-X-G.js → chunk-727SXJPM-ZkqwcZ6G.js} +1 -1
- package/resources/fe-dist/assets/{chunk-AQP2D5EJ-Cv5U78aO.js → chunk-AQP2D5EJ-79MMuY3h.js} +1 -1
- package/resources/fe-dist/assets/{chunk-FMBD7UC4-DnaDXP2z.js → chunk-FMBD7UC4-Vw8e6XCy.js} +1 -1
- package/resources/fe-dist/assets/{chunk-ND2GUHAM-BCRcaTWl.js → chunk-ND2GUHAM-um7O2-xi.js} +1 -1
- package/resources/fe-dist/assets/{chunk-QZHKN3VN-1sPBtZCH.js → chunk-QZHKN3VN-D8FuV91c.js} +1 -1
- package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-SSiS3KfC.js +1 -0
- package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-SSiS3KfC.js +1 -0
- package/resources/fe-dist/assets/{copy-CJIriuQt.js → copy-Cawnv2-o.js} +1 -1
- package/resources/fe-dist/assets/{cose-bilkent-S5V4N54A-CY6ERT7s.js → cose-bilkent-S5V4N54A-gidx-z0G.js} +1 -1
- package/resources/fe-dist/assets/{dagre-BM42HDAG-c_oJjVCK.js → dagre-BM42HDAG-C54CUHrk.js} +1 -1
- package/resources/fe-dist/assets/{diagram-2AECGRRQ-g-DJAnzv.js → diagram-2AECGRRQ-DFGI1MJu.js} +1 -1
- package/resources/fe-dist/assets/{diagram-5GNKFQAL-0DikWL30.js → diagram-5GNKFQAL-D7POJY8A.js} +1 -1
- package/resources/fe-dist/assets/{diagram-KO2AKTUF-wWVJH7kq.js → diagram-KO2AKTUF-CvV1GMLL.js} +1 -1
- package/resources/fe-dist/assets/{diagram-LMA3HP47-UwQ9OpsG.js → diagram-LMA3HP47-BbfJVUKI.js} +1 -1
- package/resources/fe-dist/assets/{diagram-OG6HWLK6-ZFNNtnbo.js → diagram-OG6HWLK6-CV6Q6IxH.js} +1 -1
- package/resources/fe-dist/assets/download-ZSRF6UU6.js +6 -0
- package/resources/fe-dist/assets/en_US-xzwBD2oK.js +1 -0
- package/resources/fe-dist/assets/{erDiagram-TEJ5UH35-D3na7WWE.js → erDiagram-TEJ5UH35-BPgvqV_L.js} +1 -1
- package/resources/fe-dist/assets/{files-tab-1FVCHULV.js → files-tab-BQhhr5Wi.js} +15 -15
- package/resources/fe-dist/assets/{flowDiagram-I6XJVG4X-Dsbf9z99.js → flowDiagram-I6XJVG4X-CKXjL0zg.js} +1 -1
- package/resources/fe-dist/assets/{ganttDiagram-6RSMTGT7-CF3CKflH.js → ganttDiagram-6RSMTGT7-D58QnW85.js} +1 -1
- package/resources/fe-dist/assets/{gitGraphDiagram-PVQCEYII-CRpX3WPf.js → gitGraphDiagram-PVQCEYII-BwB9zJYk.js} +1 -1
- package/resources/fe-dist/assets/{index-U4iZ6Kxr.js → index-CxD8veUJ.js} +16 -16
- package/resources/fe-dist/assets/{index-C-RSAqjj.js → index-DDvqV24J.js} +1 -1
- package/resources/fe-dist/assets/{infoDiagram-5YYISTIA-DMCNm7PZ.js → infoDiagram-5YYISTIA-DGZZJ51K.js} +1 -1
- package/resources/fe-dist/assets/{ishikawaDiagram-YF4QCWOH-CMe-J41c.js → ishikawaDiagram-YF4QCWOH-DKEV0i-O.js} +1 -1
- package/resources/fe-dist/assets/ja_JP-Dd1FrxOk.js +1 -0
- package/resources/fe-dist/assets/{journeyDiagram-JHISSGLW-CxFZDT81.js → journeyDiagram-JHISSGLW-Dvt5MIiS.js} +1 -1
- package/resources/fe-dist/assets/{kanban-definition-UN3LZRKU-DwBxD_Gg.js → kanban-definition-UN3LZRKU-BrLCK6I8.js} +1 -1
- package/resources/fe-dist/assets/{linear-CBM17AV1.js → linear-LNJ3BF_d.js} +1 -1
- package/resources/fe-dist/assets/{markdown-preview-CVeuDkuY.js → markdown-preview-Cqdqjc1H.js} +3 -3
- package/resources/fe-dist/assets/{mermaid.core-CvSv2dqw.js → mermaid.core-Cy4PFTl-.js} +5 -5
- package/resources/fe-dist/assets/{mindmap-definition-RKZ34NQL-DUu53RHy.js → mindmap-definition-RKZ34NQL-JOcL1ZTP.js} +1 -1
- package/resources/fe-dist/assets/{pieDiagram-4H26LBE5-CAbw9YBY.js → pieDiagram-4H26LBE5-_1o-TTd6.js} +1 -1
- package/resources/fe-dist/assets/{quadrantDiagram-W4KKPZXB-NmJUURAz.js → quadrantDiagram-W4KKPZXB-7Ggy2jhO.js} +1 -1
- package/resources/fe-dist/assets/{requirementDiagram-4Y6WPE33-B45iu7jV.js → requirementDiagram-4Y6WPE33-CH_udJzB.js} +1 -1
- package/resources/fe-dist/assets/{sankeyDiagram-5OEKKPKP-af9JvT_p.js → sankeyDiagram-5OEKKPKP-DO9ymHJb.js} +1 -1
- package/resources/fe-dist/assets/{send-e_FTy5nC.js → send-D0SbMcl5.js} +1 -1
- package/resources/fe-dist/assets/{sequenceDiagram-3UESZ5HK-CSpSOeHp.js → sequenceDiagram-3UESZ5HK-BfxbUo5S.js} +1 -1
- package/resources/fe-dist/assets/{stateDiagram-AJRCARHV-vM6MSoBd.js → stateDiagram-AJRCARHV-ChJ5OE86.js} +1 -1
- package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-yafZZKAc.js +1 -0
- package/resources/fe-dist/assets/terminal-settings-panel-CFkXHe7W.js +25 -0
- package/resources/fe-dist/assets/{timeline-definition-PNZ67QCA-A63tNc2d.js → timeline-definition-PNZ67QCA-CIlpfkBn.js} +1 -1
- package/resources/fe-dist/assets/{transfer-toast-CmSO0e95.js → transfer-toast-DvU8-v2e.js} +1 -1
- package/resources/fe-dist/assets/{triangle-alert-jNMwsJMj.js → triangle-alert-BI3hbdo6.js} +1 -1
- package/resources/fe-dist/assets/{vennDiagram-CIIHVFJN-BktPK2LC.js → vennDiagram-CIIHVFJN-NqSGMHBa.js} +1 -1
- package/resources/fe-dist/assets/{wardley-L42UT6IY-viU1xsE2.js → wardley-L42UT6IY-bOJt96SM.js} +1 -1
- package/resources/fe-dist/assets/{wardleyDiagram-YWT4CUSO-DICOr7Mv.js → wardleyDiagram-YWT4CUSO-DAgFPWOP.js} +1 -1
- package/resources/fe-dist/assets/{xychartDiagram-2RQKCTM6-bjue7pS9.js → xychartDiagram-2RQKCTM6-D5rVqEFB.js} +1 -1
- package/resources/fe-dist/assets/{zap-ClXbg92C.js → zap-D-Szn4JY.js} +1 -1
- package/resources/fe-dist/assets/zh_CN-DVIa9MQX.js +1 -0
- package/resources/fe-dist/index.html +1 -1
- package/resources/gateway-drizzle/0015_wise_mongu.sql +1 -0
- package/resources/gateway-drizzle/0016_cheerful_scarecrow.sql +17 -0
- package/resources/gateway-drizzle/meta/_journal.json +14 -0
- package/resources/fe-dist/assets/DevicePage-BIjGEtCP.js +0 -24
- package/resources/fe-dist/assets/SettingsPage-BAx39LyM.js +0 -39
- package/resources/fe-dist/assets/api-Dto6Spgl.js +0 -10
- package/resources/fe-dist/assets/channel-DD10rSnh.js +0 -1
- package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-CEWAB_yV.js +0 -1
- package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-CEWAB_yV.js +0 -1
- package/resources/fe-dist/assets/en_US-BihUhDmr.js +0 -1
- package/resources/fe-dist/assets/ja_JP-f5sXmz8W.js +0 -1
- package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-8FQLtPkV.js +0 -1
- package/resources/fe-dist/assets/terminal-settings-panel-DU9rOuZd.js +0 -25
- package/resources/fe-dist/assets/zh_CN-CPdvelFW.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tmex-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tmex": "./bin/tmex.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"clean": "rm -rf dist resources/fe-dist resources/gateway-drizzle",
|
|
21
21
|
"bundle:resources": "bash ./scripts/bundle-resources.sh",
|
|
22
22
|
"build:runtime": "bun scripts/build-runtime.ts",
|
|
23
|
+
"build:artifacts": "bun scripts/build-artifacts.ts",
|
|
23
24
|
"build:cli": "bun build src/cli-node.ts --outfile ./dist/cli-node.js --target node --format esm",
|
|
24
25
|
"build": "bun run clean && bun run bundle:resources && bun run build:runtime && bun run build:cli",
|
|
25
26
|
"release": "npm publish",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import{Y as Oe,u as Te,j as i,aD as Pt,aE as Mt,aF as kt,aG as It,aH as Tt,a6 as Lt,r as n,d as $,aa as ge,a9 as et,az as ht,ay as mt,ax as At,aA as _t,aI as Dt,aJ as zt,c as Xe,o as ke,aK as Bt,D as $t,p as Ft,q as Ht,s as Yt,ac as pt,aL as tt,aM as nt,b as wt,aN as rt,aO as Wt,ah as gt,aP as Me,aQ as Ot,a2 as Ke,y as Xt,ag as Ut,B as Ne,T as qt,aR as Vt,aS as Kt,aT as Gt,aU as Qt,aV as Zt,ai as Jt,aW as en,A as tn,f as nn,g as rn,i as sn,k as on,l as cn,m as an,n as ln}from"./index-CxD8veUJ.js";import{T as un,C as dn,c as fn,F as hn,a as xt,R as mn,A as pn,f as wn,t as gn,S as xn}from"./terminal-settings-panel-CFkXHe7W.js";import{f as vn,a as bn,b as Sn}from"./api-5IhJ49aS.js";import{e as yn}from"./selection-clipboard-D3gUQQ7L.js";import{C as En}from"./copy-Cawnv2-o.js";import{S as at,K as Rn}from"./send-D0SbMcl5.js";const jn=1,Cn=2,Nn=4,Pn=8,Mn=16;function kn(t){return{mouseStandard:(t&jn)!==0,mouseButton:(t&Cn)!==0,mouseAll:(t&Nn)!==0,mouseSgr:(t&Pn)!==0,mouseUtf8:(t&Mn)!==0}}const In=/^[0-9a-fA-F]{4}$/;function Tn(t){if(typeof t!="string"||t.length<6)return null;const e=t.slice(0,4);if(!In.test(e)||t[4]!==",")return null;const o={input:t,pos:5},a=vt(o);return!a||o.pos!==t.length?null:{checksum:e,root:a}}function $e(t){const e=t.pos;for(;t.pos<t.input.length;){const o=t.input.charCodeAt(t.pos);if(o<48||o>57)break;t.pos+=1}return t.pos===e?null:Number.parseInt(t.input.slice(e,t.pos),10)}function Fe(t,e){return t.input[t.pos]!==e?!1:(t.pos+=1,!0)}function vt(t){const e=$e(t);if(e===null||!Fe(t,"x"))return null;const o=$e(t);if(o===null||!Fe(t,","))return null;const a=$e(t);if(a===null||!Fe(t,","))return null;const p=$e(t);if(p===null)return null;const f=t.input[t.pos];if(f===","){t.pos+=1;const R=$e(t);return R===null?null:{type:"leaf",paneNumId:R,width:e,height:o,x:a,y:p}}if(f==="{"||f==="["){const R=f==="{"?"}":"]";t.pos+=1;const C=[];for(;;){const k=vt(t);if(!k)return null;if(C.push(k),!Fe(t,",")){if(Fe(t,R))break;return null}}return C.length<2?null:{type:f==="{"?"row":"column",width:e,height:o,x:a,y:p,children:C}}return null}function Ge(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 Ln=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],An=Oe("columns-2",Ln);/**
|
|
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 _n=[["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"}]],Dn=Oe("search-x",_n);/**
|
|
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 zn=[["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"}]],Bn=Oe("settings-2",zn);/**
|
|
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 $n=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],Fn=Oe("smartphone",$n);function Hn({open:t,onOpenChange:e}){const{t:o}=Te();return i.jsx(Pt,{open:t,onOpenChange:e,children:i.jsxs(Mt,{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(kt,{children:[i.jsx(It,{children:o("settings.terminal.title")}),i.jsx(Tt,{children:o("settings.terminal.savedInBrowser")})]}),i.jsx("div",{className:"px-4 pb-4",children:i.jsx(un,{})})]})})}function Yn({visible:t,canPaste:e,onCopy:o,onPaste:a,onDismiss:p}){const{t:f}=Te();if(!t)return null;const R=C=>{C.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:R,onClick:o,"data-testid":"terminal-selection-copy",children:[i.jsx(En,{className:"h-4 w-4"}),f("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:R,onClick:a,"data-testid":"terminal-selection-paste",children:[i.jsx(dn,{className:"h-4 w-4"}),f("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:R,onClick:p,"aria-label":f("terminal.clearSelection"),"data-testid":"terminal-selection-dismiss",children:i.jsx(Lt,{className:"h-4 w-4"})})]})}function bt(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 Wn="\x1B[?1049h\x1B[H\x1B[2J";function On(t){return Wn+bt(t)}function Xn(t,e){let o=e,a=0;for(const C of t)C===10&&!o&&(a+=1),o=C===13;const p=o;if(a===0)return{normalized:t,endedWithCR:p};const f=new Uint8Array(t.length+a);let R=0;o=e;for(const C of t)C===10&&!o&&(f[R]=13,R+=1),f[R]=C,R+=1,o=C===13;return{normalized:f,endedWithCR:p}}const lt=1.3,Un=36,qn=500,ut=12;function Vn(t,e){const o=n.useRef(!1);return n.useEffect(()=>{const a=t.current;if(!a||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;o.current=!0;let f="idle",R=0,C=null,k=0,X=0,Y=0,P=0,F=0,te=0,r=null;const ae=()=>{r!==null&&(clearTimeout(r),r=null)},K=c=>c?!!(c.closest(".scrollbar")||c.closest(".slider")||c.closest(".xterm-scroll-area")):!1,L=(c,g,j)=>{const b=j instanceof Element?j:null;return K(b)?!0:K(document.elementFromPoint(c,g))},de=(c,g,j)=>{if(L(c,g,j))return!0;const b=a.querySelector(".xterm");if(!(b instanceof HTMLElement))return!1;const S=b.getBoundingClientRect(),y=c>=S.left&&c<=S.right,z=g>=S.top&&g<=S.bottom;return!y||!z?!1:c>=S.right-Un},he=()=>[a.querySelector(".xterm-viewport"),a.querySelector(".xterm-scrollable-element")].filter(g=>g instanceof HTMLElement),le=c=>{if(C===null)return null;for(let g=0;g<c.length;g+=1){const j=c.item(g);if(j&&j.identifier===C)return j}return null},re=c=>{let g=0,j=0;for(let b=0;b<c.length;b+=1){const S=c.item(b);S&&(g+=S.clientY,j+=1)}return j>0?g/j:0},w=c=>{var j,b,S,y;const g=c==null?void 0:c._core;return((y=(S=(b=(j=g==null?void 0:g._renderService)==null?void 0:j.dimensions)==null?void 0:b.css)==null?void 0:S.cell)==null?void 0:y.height)??18},G=(c,g,j,b)=>{const S=w(c);k+=g*lt;const y=k>0?Math.floor(k/S):Math.ceil(k/S);if(y===0||typeof c.handleViewportGesture!="function")return!1;const z=c.handleViewportGesture({source:"touch",deltaY:y*S,clientX:j,clientY:b});return k-=y*S,z},M=()=>{ae(),f="idle",C=null,k=0},U=c=>{var g;if(c.touches.length===1){ae();const j=c.touches.item(0);if(!j)return;C=j.identifier,R=j.clientY,k=0,X=j.clientX,Y=j.clientY;const b=(e==null?void 0:e())??null,S=!!((g=b==null?void 0:b.isMouseReporting)!=null&&g.call(b));if(S?L(j.clientX,j.clientY,c.target):de(j.clientX,j.clientY,c.target)){f="bypass";return}f=S?"pending":"scroll",r=setTimeout(()=>{var Q;r=null;const z=(e==null?void 0:e())??null;(Q=z==null?void 0:z.startTouchSelection)!=null&&Q.call(z,X,Y,"word")&&(f="select")},qn);return}if(f==="pending"){ae(),f="wheel",k=0,te=re(c.touches);return}f==="wheel"&&(te=re(c.touches))},se=c=>{var Q,me,E,q,we,D,pe,l;if(f==="idle"||f==="bypass")return;if(f==="select"){const d=le(c.touches)??c.touches.item(0);if(!d)return;const u=(e==null?void 0:e())??null;(Q=u==null?void 0:u.updateTouchSelection)==null||Q.call(u,d.clientX,d.clientY),c.cancelable&&c.preventDefault();return}if(f==="wheel"){const d=(e==null?void 0:e())??null,u=re(c.touches),N=te-u;if(te=u,d&&N!==0){const H=c.touches.item(0);G(d,N,(H==null?void 0:H.clientX)??X,u)}c.cancelable&&c.preventDefault();return}const g=le(c.touches)??c.touches.item(0);if(!g)return;if(f==="pending"){if(Math.hypot(g.clientX-X,g.clientY-Y)<=ut)return;ae();const u=(e==null?void 0:e())??null;if(!((me=u==null?void 0:u.sendTouchMouseEvent)!=null&&me.call(u,{action:"press",clientX:X,clientY:Y}))){f="idle";return}f="drag",P=g.clientX,F=g.clientY,(E=u.sendTouchMouseEvent)==null||E.call(u,{action:"motion",clientX:g.clientX,clientY:g.clientY}),c.cancelable&&c.preventDefault();return}if(f==="drag"){const d=(e==null?void 0:e())??null;P=g.clientX,F=g.clientY,(q=d==null?void 0:d.sendTouchMouseEvent)==null||q.call(d,{action:"motion",clientX:g.clientX,clientY:g.clientY}),c.cancelable&&c.preventDefault();return}if(r!==null&&Math.hypot(g.clientX-X,g.clientY-Y)>ut&&ae(),de(g.clientX,g.clientY,c.target)){f="bypass",k=0;return}const j=g.clientY,b=R-j;if(R=j,b===0)return;let S=!1,y=!1;const z=(e==null?void 0:e())??null;if(z)if(typeof z.handleViewportGesture=="function")S=G(z,b,g.clientX,g.clientY);else{const d=w(z);k+=b*lt;const u=k>0?Math.floor(k/d):Math.ceil(k/d);if(u!==0){const N=((D=(we=z.buffer)==null?void 0:we.active)==null?void 0:D.viewportY)??0;z.scrollLines(u);const H=((l=(pe=z.buffer)==null?void 0:pe.active)==null?void 0:l.viewportY)??0;S=N!==H,y=u<0&&N<=0&&H<=0,k-=u*d}}else{const d=he();if(d.length===0)return;for(const u of d){const N=u.scrollTop;u.scrollTop+=b;const H=u.scrollTop;Math.abs(H-N)>0&&(S=!0),b<0&&H<=0&&(y=!0)}if(!S){const u=a.querySelector(".xterm");if(u instanceof HTMLElement){const N=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:b}),H=u.dispatchEvent(N);S=N.defaultPrevented||!H}}}c.cancelable&&(S||y)&&c.preventDefault()},V=c=>{var g,j,b,S,y,z,Q,me;if(f==="wheel"&&c.touches.length>0){te=re(c.touches);return}if(f==="drag"){if(c.touches.length>0&&!le(c.changedTouches))return;const E=(e==null?void 0:e())??null,q=le(c.changedTouches);(g=E==null?void 0:E.sendTouchMouseEvent)==null||g.call(E,{action:"release",clientX:(q==null?void 0:q.clientX)??P,clientY:(q==null?void 0:q.clientY)??F}),(j=E==null?void 0:E.noteTouchHandled)==null||j.call(E),c.cancelable&&c.preventDefault(),M();return}if(f==="pending"){const E=(e==null?void 0:e())??null;(b=E==null?void 0:E.sendTouchMouseEvent)!=null&&b.call(E,{action:"press",clientX:X,clientY:Y})&&((S=E.sendTouchMouseEvent)==null||S.call(E,{action:"release",clientX:X,clientY:Y})),(y=E==null?void 0:E.noteTouchHandled)==null||y.call(E),(z=E==null?void 0:E.focus)==null||z.call(E),c.cancelable&&c.preventDefault(),M();return}if(f==="select"){const E=(e==null?void 0:e())??null;(Q=E==null?void 0:E.endTouchSelection)==null||Q.call(E),(me=E==null?void 0:E.noteTouchHandled)==null||me.call(E),c.cancelable&&c.preventDefault(),M();return}if(f==="scroll"||f==="bypass"||f==="wheel"){c.touches.length===0&&M();return}M()},_=c=>{var g,j,b,S;if(f==="drag"){const y=(e==null?void 0:e())??null;(g=y==null?void 0:y.sendTouchMouseEvent)==null||g.call(y,{action:"release",clientX:P,clientY:F}),(j=y==null?void 0:y.noteTouchHandled)==null||j.call(y)}else if(f==="select"){const y=(e==null?void 0:e())??null;(b=y==null?void 0:y.endTouchSelection)==null||b.call(y),(S=y==null?void 0:y.noteTouchHandled)==null||S.call(y)}c.touches.length===0&&M()},ie=c=>{f==="select"&&c.preventDefault()};return a.addEventListener("touchstart",U,{passive:!0}),a.addEventListener("touchmove",se,{passive:!1}),a.addEventListener("touchend",V,{passive:!1}),a.addEventListener("touchcancel",_,{passive:!0}),a.addEventListener("contextmenu",ie),()=>{o.current=!1,ae(),a.removeEventListener("touchstart",U),a.removeEventListener("touchmove",se),a.removeEventListener("touchend",V),a.removeEventListener("touchcancel",_),a.removeEventListener("contextmenu",ie)}},[t,e]),o}function Kn({now:t,remoteSize:e,pendingLocalSize:o,ttlMs:a=2e3}){return!o||t-o.at>a?!0:o.cols===e.cols&&o.rows===e.rows}function Gn({currentSize:t,containerSize:e,force:o=!1}){return o?!0:t.cols!==e.cols||t.rows!==e.rows}function Qn({deviceId:t,paneId:e,deviceConnected:o,isSelectionInvalid:a,sizingMode:p="report",onResize:f,onSync:R,onResizeSettled:C,getContainerRect:k}){const X=n.useRef(null),Y=n.useRef(null),P=n.useRef(null),F=n.useRef(null),te=n.useRef(0),r=n.useRef([]),ae=n.useRef(null),K=n.useRef(null),L=n.useRef(k),de=n.useRef(!1),he=n.useRef(f),le=n.useRef(R),re=n.useRef(C);n.useEffect(()=>{he.current=f},[f]),n.useEffect(()=>{le.current=R},[R]),n.useEffect(()=>{re.current=C},[C]),n.useEffect(()=>{L.current=k},[k]);const w=n.useCallback(()=>{var Q,me,E,q,we,D,pe,l,d,u;const c=K.current,g=ae.current;if(!c||!g||!c.element)return null;let j;try{const N=g.proposeDimensions();if(!N)throw new Error("fitAddon.proposeDimensions() returned null");j=Math.max(2,N.cols)}catch{const N=c._core,H=((q=(E=(me=(Q=N==null?void 0:N._renderService)==null?void 0:Q.dimensions)==null?void 0:me.css)==null?void 0:E.cell)==null?void 0:q.width)??9,h=(we=L.current)==null?void 0:we.call(L);if(!h||h.width===0)return null;j=Math.max(2,Math.floor(h.width/H))}const b=(D=L.current)==null?void 0:D.call(L);if(!b||b.height===0)return null;const S=c._core,y=((u=(d=(l=(pe=S==null?void 0:S._renderService)==null?void 0:pe.dimensions)==null?void 0:l.css)==null?void 0:d.cell)==null?void 0:u.height)??17,z=Math.max(2,Math.floor(b.height/y));return{cols:j,rows:z}},[]),G=n.useCallback((c,g)=>{const j=K.current;j&&(j.cols===c&&j.rows===g||j.resize(c,g))},[]),M=n.useCallback((c,g=!1)=>{var Q;if(p==="follow"||!t||!e||!o||a&&c!=="sync"||!g&&Date.now()<te.current||!K.current)return!1;const b=w();if(!b)return!1;const{cols:S,rows:y}=b,z=P.current;return!g&&z&&z.cols===S&&z.rows===y?(G(S,y),!0):(G(S,y),c==="sync"?le.current(S,y):he.current(S,y),P.current={cols:S,rows:y},F.current={cols:S,rows:y,at:Date.now()},(Q=re.current)==null||Q.call(re,S,y),!0)},[G,o,t,a,w,e,p]),U=n.useCallback((c="resize",g={})=>{const{immediate:j=!1,force:b=!1}=g;Y.current!==null&&(window.clearTimeout(Y.current),Y.current=null),X.current!==null&&(cancelAnimationFrame(X.current),X.current=null);const S=()=>{X.current=requestAnimationFrame(()=>{X.current=null,M(c,b)})};if(j){S();return}Y.current=window.setTimeout(()=>{Y.current=null,S()},150)},[M]),se=n.useCallback(()=>{for(const c of r.current)window.clearTimeout(c);r.current=[]},[]),V=n.useCallback(()=>{var g;se(),U("sync",{immediate:!0,force:!0});const c=window.setTimeout(()=>{U("sync",{immediate:!0,force:!0})},60);r.current.push(c),typeof document<"u"&&"fonts"in document&&((g=document.fonts)!=null&&g.ready)&&document.fonts.ready.then(()=>{U("sync",{immediate:!0,force:!0})}).catch(()=>{})},[se,U]);n.useEffect(()=>{let c=null;const g=()=>{c!==null&&cancelAnimationFrame(c),c=requestAnimationFrame(()=>{c=null,U("resize")})};return window.addEventListener("resize",g),()=>{window.removeEventListener("resize",g),c!==null&&cancelAnimationFrame(c)}},[U]),n.useEffect(()=>{const c=()=>{var Q;const S=K.current,y=w();if(!S||!y)return;if(!Gn({currentSize:{cols:Math.max(2,S.cols),rows:Math.max(2,S.rows)},containerSize:y})){(Q=S.forceFullRepaint)==null||Q.call(S);return}U("sync",{force:!0})},g=()=>{if(document.visibilityState!=="visible"){de.current=!0;return}de.current&&(de.current=!1,c())},j=()=>{de.current=!0},b=()=>{de.current&&(de.current=!1,c())};return document.addEventListener("visibilitychange",g),window.addEventListener("blur",j),window.addEventListener("focus",b),()=>{document.removeEventListener("visibilitychange",g),window.removeEventListener("blur",j),window.removeEventListener("focus",b)}},[w,U]),n.useEffect(()=>()=>{se(),Y.current!==null&&window.clearTimeout(Y.current),X.current!==null&&cancelAnimationFrame(X.current)},[se]);const _=n.useCallback(c=>{ae.current=c},[]),ie=n.useCallback(c=>{K.current=c},[]);return{scheduleResize:U,runPostSelectResize:V,clearPostSelectResizeTimers:se,setFitAddon:_,setTerminal:ie,lastReportedSize:P,pendingLocalSize:F,suppressLocalResizeUntil:te}}const Zn=1e4;function Jn(t,e){const o=kn(t);return{mouseX10:!1,mouseNormal:o.mouseStandard,mouseButton:o.mouseButton,mouseAny:o.mouseAll,mouseUtf8:o.mouseUtf8,mouseSgr:o.mouseSgr,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:e,altScreen1047:!1,altScreen1049:!1}}function er(t){var o;const e=globalThis;e.__tmexE2eXterm=t,e.__tmexE2eTerminal=t,e.__tmexE2eTerminalEngine=xt,e.__tmexE2eTerminalRenderer=((o=t.getRendererKind)==null?void 0:o.call(t))??null}function tr(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 st=n.forwardRef(({deviceId:t,paneId:e,theme:o,inputMode:a,deviceConnected:p,isSelectionInvalid:f,sizingMode:R="report",autoFocus:C=!0,focused:k=!0,onResize:X,onSync:Y,onResizeSettled:P,children:F},te)=>{const[r,ae]=n.useState(null),[K,L]=n.useState(!1),de=$(h=>h.sendInput),he=ge(h=>h.terminalFontId),le=ge(h=>h.terminalFontSize),re=ge(h=>h.terminalLineHeight),{t:w}=Te(),G=et(),M=n.useMemo(()=>{switch(o){case"light":return mt;default:return ht}},[o]),U=n.useRef(null),se=n.useRef(null),V=n.useRef(null),_=n.useRef(t),ie=n.useRef(e),c=n.useRef(p&&!f),g=n.useRef(a),j=n.useRef(M),b=n.useRef(!1),S=n.useRef(null),y=n.useCallback(()=>r,[r]);Vn(U,y),n.useEffect(()=>{_.current=t,ie.current=e},[t,e]),n.useEffect(()=>{c.current=p&&!f},[p,f]),n.useEffect(()=>{g.current=a},[a]),n.useEffect(()=>{j.current=M},[M]);const z=n.useCallback(h=>{if(!h||a!=="direct"||!c.current)return;const m=_.current,I=ie.current;!m||!I||de(m,I,h,!1)},[a,de]),{pendingLocalSize:Q,scheduleResize:me,runPostSelectResize:E,setFitAddon:q,setTerminal:we}=Qn({deviceId:t,paneId:e,deviceConnected:p,isSelectionInvalid:f,sizingMode:R,onResize:X,onSync:Y,onResizeSettled:P,getContainerRect:()=>{const h=U.current;if(!h)return null;const m=h.getBoundingClientRect();return{width:m.width,height:m.height}}});n.useEffect(()=>{let h=!1,m=null;return(async()=>{if(await At(he,le),h)return;const I=await fn({fontFamily:_t(he),fontSize:le,lineHeight:re,scrollback:Zn,theme:j.current,disableStdin:g.current==="editor"});if(h){I.dispose();return}m=I,se.current&&I.open(se.current),ae(I)})(),()=>{h=!0,ae(null),tr(m),m==null||m.dispose()}},[he,le,re]),n.useEffect(()=>{!r||!C||er(r)},[r,C]),n.useEffect(()=>{var h;(h=r==null?void 0:r.setFocused)==null||h.call(r,k)},[r,k]),n.useEffect(()=>{!r||!("setTheme"in r)||r.setTheme(M)},[r,M]),n.useEffect(()=>{!r||!("setDisableStdin"in r)||r.setDisableStdin(a==="editor")},[r,a]),n.useEffect(()=>{if(!(r!=null&&r.getCursorViewportRect))return;const h=()=>{var m;return((m=r.getCursorViewportRect)==null?void 0:m.call(r))??null};return Bt(h),()=>Dt(h)},[r]),n.useEffect(()=>{!r||a!=="direct"||!C||window.innerWidth<768||"ontouchstart"in window||r.focus()},[r,a,C]);const D=n.useMemo(()=>r?{onReset:h=>{r.reset(),b.current=!1,h!=="history-refresh"&&E()},onApplyHistory:(h,m,I)=>{var T,Z;(T=r.restoreModeSnapshot)==null||T.call(r,Jn(I,m));const W=m?On(h):bt(h);r.write(W),(Z=r.forceFullRepaint)==null||Z.call(r)},onOutput:h=>{const m=Xn(h,b.current);b.current=m.endedWithCR,r.write(m.normalized)}}:null,[r,E]);n.useEffect(()=>{r?S.current!==r&&(b.current=!1,S.current=r):S.current=null},[r]),n.useEffect(()=>{if(!(!D||!t||!e))return zt(t,e,D)},[D,t,e]),n.useEffect(()=>{if(!r){V.current=null,q(null),we(null);return}const h=new hn;return r.loadAddon(h),V.current=h,q(h),we(r),E(),()=>{try{h.dispose()}finally{V.current=null,q(null),we(null)}}},[r,E,q,we]),n.useEffect(()=>{const h=U.current;if(!h)return;let m=null;const I=new ResizeObserver(()=>{m!==null&&cancelAnimationFrame(m),m=requestAnimationFrame(()=>{m=null,me("resize")})});return I.observe(h),()=>{I.disconnect(),m!==null&&cancelAnimationFrame(m)}},[me]),n.useEffect(()=>{if(!r||!t||!e)return;const h=r.onData(m=>{!p||f||z(m)});return r.attachCustomKeyEventHandler(m=>!p||f||m.type!=="keydown"||a!=="direct"?!0:m.shiftKey&&m.key==="Enter"?(m.preventDefault(),z("\x1B[13;2u"),!1):!0),()=>{h.dispose(),r.attachCustomKeyEventHandler(()=>!0)}},[r,p,f,a,z,t,e]),n.useEffect(()=>{if(!(r!=null&&r.onLinkActivated))return;const h=r.onLinkActivated(m=>{window.open(m,"_blank","noopener,noreferrer")});return()=>h.dispose()},[r]);const{data:pe}=Xe({queryKey:["files","roots"],queryFn:vn,staleTime:3e4}),l=n.useMemo(()=>((pe==null?void 0:pe.roots)??[]).filter(h=>h.enabled&&h.deviceId===t),[pe,t]),d=$(h=>{var I;const m=(I=h.snapshots[t])==null?void 0:I.session;if(m){for(const W of m.windows)for(const T of W.panes)if(T.id===e)return T.currentPath}});n.useEffect(()=>{var h;(h=r==null?void 0:r.setFileLinkContext)==null||h.call(r,{cwd:d??null,rootPaths:l.map(m=>m.path)})},[r,d,l]),n.useEffect(()=>{if(!(r!=null&&r.onFileLinkActivated))return;const h=r.onFileLinkActivated(m=>{const I=l.filter(W=>m===W.path||m.startsWith(W.path==="/"?"/":`${W.path}/`)).sort((W,T)=>T.path.length-W.path.length)[0];I&&bn(I.id,m).then(()=>{G(Sn(I.id,m))}).catch(()=>{ke.error(w("terminal.fileLinkNotFound"))})});return()=>h.dispose()},[r,l,G,w]),n.useEffect(()=>{if(!(r!=null&&r.onSelectionChange)){L(!1);return}const h=r.onSelectionChange(m=>{L(!!m)});return()=>{h.dispose(),L(!1)}},[r]);const u=n.useCallback(()=>{var m;if(!r)return;const h=((m=r.getSelection)==null?void 0:m.call(r))??"";h&&yn(h).then(()=>{ke.success(w("terminal.copied"))}).catch(()=>{ke.error(w("terminal.copyFailed"))}).finally(()=>{var I;(I=r.clearSelection)==null||I.call(r),r.focus()})},[r,w]),N=n.useCallback(()=>{var m;if(!r)return;((m=navigator.clipboard)!=null&&m.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(I=>{var W;I&&r.paste(I),(W=r.clearSelection)==null||W.call(r),r.focus()}).catch(()=>{ke.error(w("terminal.pasteFailed"))})},[r,w]),H=n.useCallback(()=>{var h;(h=r==null?void 0:r.clearSelection)==null||h.call(r),r==null||r.focus()},[r]);return n.useImperativeHandle(te,()=>({write:h=>r==null?void 0:r.write(h),reset:()=>{r==null||r.reset(),b.current=!1},scrollToBottom:()=>r==null?void 0:r.scrollToBottom(),resize:(h,m)=>r==null?void 0:r.resize(h,m),getTerminal:()=>r??null,getSize:()=>r?{cols:Math.max(2,r.cols),rows:Math.max(2,r.rows)}:null,runPostSelectResize:()=>E(),scheduleResize:(h,m)=>me(h,m),calculateSizeFromContainer:()=>{var Ee,Se,xe,O,ne,B,ee,ue,J,ye,Pe,Re,Ce,Le,Ae,_e;const h=U.current,m=r,I=V.current;if(!h||!m)return null;const W=h.getBoundingClientRect();if(W.width===0||W.height===0)return null;const T=m._core;let Z;if(I)try{const ce=I.proposeDimensions();if(ce)Z=Math.max(2,ce.cols);else{const De=((O=(xe=(Se=(Ee=T==null?void 0:T._renderService)==null?void 0:Ee.dimensions)==null?void 0:Se.css)==null?void 0:xe.cell)==null?void 0:O.width)??9;Z=Math.max(2,Math.floor(W.width/De))}}catch{const ce=((ue=(ee=(B=(ne=T==null?void 0:T._renderService)==null?void 0:ne.dimensions)==null?void 0:B.css)==null?void 0:ee.cell)==null?void 0:ue.width)??9;Z=Math.max(2,Math.floor(W.width/ce))}else{const ce=((Re=(Pe=(ye=(J=T==null?void 0:T._renderService)==null?void 0:J.dimensions)==null?void 0:ye.css)==null?void 0:Pe.cell)==null?void 0:Re.width)??9;Z=Math.max(2,Math.floor(W.width/ce))}const fe=((_e=(Ae=(Le=(Ce=T==null?void 0:T._renderService)==null?void 0:Ce.dimensions)==null?void 0:Le.css)==null?void 0:Ae.cell)==null?void 0:_e.height)??17,je=Math.max(2,Math.floor(W.height/fe));return{cols:Z,rows:je}},getPendingLocalSize:()=>Q.current,getCellSize:()=>{var I,W,T;const h=r==null?void 0:r._core,m=(T=(W=(I=h==null?void 0:h._renderService)==null?void 0:I.dimensions)==null?void 0:W.css)==null?void 0:T.cell;return!(m!=null&&m.width)||!(m!=null&&m.height)?null:{width:m.width,height:m.height}}}),[r,Q,E,me]),i.jsxs("div",{className:"flex h-full w-full flex-col",style:{backgroundColor:M.background},"data-terminal-engine":xt,children:[i.jsxs("div",{ref:U,className:"relative min-h-0 w-full flex-1",children:[i.jsx("div",{ref:se,className:"absolute inset-0"}),i.jsx(Yn,{visible:K,canPaste:a==="direct"&&p&&!f,onCopy:u,onPaste:N,onDismiss:H})]}),F]})});st.displayName="Terminal";function nr({window:t,currentPaneId:e,onSelectPane:o}){const{t:a}=Te();return i.jsxs($t,{children:[i.jsxs(Ft,{"data-testid":"pane-switcher-button","aria-label":a("window.switchPane"),title:a("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(An,{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(Ht,{align:"end",backdrop:!0,className:"min-w-56 max-w-[80vw]","data-testid":"pane-switcher-menu",children:t.panes.map(p=>{const f=p.id===e;return i.jsxs(Yt,{"data-testid":"pane-switcher-item","data-pane-id":p.id,className:`py-2 [@media(any-pointer:coarse)]:py-2.5 ${f?"bg-primary/10 text-primary":p.active?"bg-accent text-accent-foreground":""}`,onClick:()=>{f||o(p.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:p.customName||p.title||a("window.pane")}),p.currentCommand&&i.jsx("span",{className:"font-mono text-[10.5px] leading-tight text-muted-foreground line-clamp-1 break-all",children:p.currentPath?`${p.currentCommand}@${p.currentPath}`:p.currentCommand})]}),f&&i.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-primary"})]},p.id)})})]})}function rr(t,e){return pt(o=>{for(const a of Object.values(o.sessions))if(!(!a||a.deviceId!==t||a.paneId!==e)&&!(a.status==="stopped"||a.status==="error")){if(a.status==="running"){const p=o.inProgress[a.id];return p&&(p.texts.length>0||p.toolCalls.length>0||p.reasonings.length>0),"generating"}return"bound"}return"none"})}function Ze(t){return t.type==="leaf"?t:t.type==="row"?Ze(t.children[t.children.length-1]):Ze(t.children[0])}function Je(t){return t.type==="leaf"?t:t.type==="column"?Je(t.children[t.children.length-1]):Je(t.children[0])}function sr(t,e){const o=[],a=[],p=f=>{if(f.type==="leaf"){o.push({paneId:Ge(f),cols:f.width,rows:f.height,rect:{left:f.x*e.width,top:f.y*e.height,width:f.width*e.width,height:f.height*e.height}});return}for(let R=0;R<f.children.length;R+=1){const C=f.children[R];if(p(C),R!==f.children.length-1)if(f.type==="row"){const k=Ze(C);a.push({axis:"x",rect:{left:(C.x+C.width)*e.width,top:f.y*e.height,width:e.width,height:f.height*e.height},edgeLeafPaneId:Ge(k)})}else{const k=Je(C);a.push({axis:"y",rect:{left:f.x*e.width,top:(C.y+C.height)*e.height,width:f.width*e.width,height:e.height},edgeLeafPaneId:Ge(k)})}}};return p(t),{panes:o,gutters:a}}function Ye(t){if(t.type==="leaf")return 1;if(t.type==="column"){let o=0;for(const a of t.children)o+=Ye(a);return o}let e=1;for(const o of t.children)e=Math.max(e,Ye(o));return e}function We(t){if(t.type==="leaf")return 1;if(t.type==="row"){let o=0;for(const a of t.children)o+=We(a);return o}let e=1;for(const o of t.children)e=Math.max(e,We(o));return e}function or(t,e){const o=Ye(t),a=We(t),p=Math.max(0,e.viewport.width-a*e.paneChrome.width),f=Math.max(0,e.viewport.height-o*e.paneChrome.height),R=Math.max(2,Math.floor(p/e.cell.width)),C=Math.max(2,Math.floor(f/e.cell.height));return{cols:R,rows:C}}function ir(t){return t?t.panes.map(e=>`${e.paneId}:${e.cols}x${e.rows}`).join("|"):""}function cr(t,e){const o=Math.min(1,Math.max(0,t)),a=Math.min(1,Math.max(0,e)),p=[["left",o],["right",1-o],["top",a],["bottom",1-a]];return p.sort((f,R)=>f[1]-R[1]),p[0][0]}const dt=150,ar=200,lr=15,ur=46,dr=38,fr=12,hr=6;function ft(t){var e,o;return((e=t==null?void 0:t.customName)==null?void 0:e.trim())||((o=t==null?void 0:t.title)==null?void 0:o.trim())||"Pane"}function mr(t){var a,p;const e=(a=t==null?void 0:t.currentCommand)==null?void 0:a.trim();if(!e)return null;const o=(p=t==null?void 0:t.currentPath)==null?void 0:p.trim();return o?`${e}@${o}`:e}function pr({paneId:t}){return tt(o=>!!o.ringingPanes[t])?i.jsx("span",{className:"bell-blink shrink-0",children:"🔔 "}):null}function wr({deviceId:t,paneId:e}){const{t:o}=Te(),a=rr(t,e);return a==="none"?null:a==="generating"?i.jsxs("span",{className:"shrink-0 select-none text-xs",title:o("agent.paneBadge.generating"),"aria-label":o("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:o("agent.paneBadge.bound"),"aria-label":o("agent.paneBadge.bound"),children:"🤖"})}const gr={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 xr({deviceId:t,window:e,focusedPaneId:o,theme:a,inputMode:p,deviceConnected:f,focusedTerminalRef:R,onUserSelectPane:C,onWindowResize:k,onWindowResizeSettled:X}){var we,D,pe;const Y=n.useRef(null),P=n.useRef(new Map),[F,te]=n.useState(null),[r,ae]=n.useState(null),{t:K}=Te(),L=$(l=>l.subscribePanes),de=$(l=>l.fetchPaneHistory),he=$(l=>l.resizePaneInWindow),le=$(l=>l.movePane),re=$(l=>l.breakPane),w=$(l=>l.closePane),G=n.useMemo(()=>{const l=new Map;for(const d of e.panes)l.set(d.id,d);return l},[e.panes]),M=n.useMemo(()=>e.layout?Tn(e.layout):null,[e.layout]),U=n.useMemo(()=>M?sr(M.root,{width:1,height:1}):null,[M]),se=n.useRef(U);se.current=U;const V=(M==null?void 0:M.root.width)??1,_=(M==null?void 0:M.root.height)??1,ie=e.panes.map(l=>l.id).join(",");n.useEffect(()=>(L(t,ie?ie.split(","):[]),()=>{L(t,[])}),[t,ie,L]);const c=n.useRef({key:"",fetched:new Set});n.useEffect(()=>{const l=`${t}:${e.id}`;c.current.key!==l&&(c.current={key:l,fetched:new Set});for(const d of ie?ie.split(","):[])c.current.fetched.has(d)||d!==o&&(c.current.fetched.add(d),de(t,d))},[t,e.id,ie,o,de]),n.useEffect(()=>{var d,u;p!=="direct"||window.innerWidth<768||"ontouchstart"in window||(u=(d=P.current.get(o))==null?void 0:d.getTerminal())==null||u.focus()},[o,p]);const g=n.useCallback(()=>{var l;for(const d of[o,...P.current.keys()]){const u=(l=P.current.get(d))==null?void 0:l.getCellSize();if(u)return u}return null},[o]),j=ir(U);n.useEffect(()=>{var d;const l=se.current;if(l)for(const u of l.panes)(d=P.current.get(u.paneId))==null||d.resize(u.cols,u.rows)},[j]);const b=n.useMemo(()=>M?Ye(M.root):1,[M]),S=n.useMemo(()=>M?We(M.root):1,[M]),y=n.useCallback(()=>{const l=Y.current;if(!l||!M)return!1;const d=l.getBoundingClientRect();if(d.width<1||d.height<1)return!1;const u=g();if(!u)return!1;const{cols:N,rows:H}=or(M.root,{viewport:{width:d.width,height:d.height},cell:u,paneChrome:{width:fr,height:ur}});return k(N,H),X==null||X(N,H),!0},[g,M,k,X]),z=n.useRef(y);n.useEffect(()=>{z.current=y},[y]),n.useEffect(()=>{const l=Y.current;if(!l)return;let d=null,u=null,N=0;const H=()=>{if(z.current()){N=0;return}N<lr&&(N+=1,u=setTimeout(H,ar))},h=new ResizeObserver(()=>{d&&clearTimeout(d),d=setTimeout(H,dt)});return h.observe(l),()=>{h.disconnect(),d&&clearTimeout(d),u&&clearTimeout(u)}},[]),n.useEffect(()=>{const l=setTimeout(()=>{z.current()},dt);return()=>clearTimeout(l)},[b,S]);const Q=n.useCallback((l,d,u)=>{u.preventDefault();const N=Y.current;if(!N)return;const H=u.clientX,h=u.clientY,m=u.currentTarget;m.setPointerCapture(u.pointerId),te({gutterIndex:l,deltaPx:0});const I=fe=>{const je=d.axis==="x"?fe.clientX-H:fe.clientY-h;te({gutterIndex:l,deltaPx:je})},W=(fe,je)=>{if(m.removeEventListener("pointermove",I),m.removeEventListener("pointerup",T),m.removeEventListener("pointercancel",Z),window.removeEventListener("pointerup",T),window.removeEventListener("pointercancel",Z),te(null),!je)return;const Ee=g();if(!Ee)return;const Se=d.axis==="x"?fe.clientX-H:fe.clientY-h,xe=d.axis==="x"?Ee.width:Ee.height;if(xe<=0)return;const O=Math.round(Se/xe);if(O===0)return;const ne=N.querySelector(`[data-pane-id="${d.edgeLeafPaneId}"]`);if(!ne)return;const B=ne.getBoundingClientRect(),ue=(d.axis==="x"?Math.floor(B.width/xe):Math.floor(B.height/xe))+O;ue<2||(z.current(),he(t,d.edgeLeafPaneId,d.axis==="x"?{cols:ue}:{rows:ue}))},T=fe=>W(fe,!0),Z=fe=>W(fe,!1);m.addEventListener("pointermove",I),window.addEventListener("pointerup",T),window.addEventListener("pointercancel",Z)},[t,g,he]),me=n.useCallback((l,d)=>{const u=Y.current,N=U;if(!u||!N)return;d.preventDefault();const H=d.clientX,h=d.clientY,m=d.currentTarget;m.setPointerCapture(d.pointerId);let I=!1;const W=(O,ne)=>{const B=u.getBoundingClientRect();if(B.width<1||B.height<1)return null;const ee=(O-B.left)/B.width*Math.max(1,V),ue=(ne-B.top)/B.height*Math.max(1,_);for(const J of N.panes)if(ee>=J.rect.left&&ee<=J.rect.left+J.rect.width&&ue>=J.rect.top&&ue<=J.rect.top+J.rect.height){const ye=(ee-J.rect.left)/Math.max(1e-6,J.rect.width),Pe=(ue-J.rect.top)/Math.max(1e-6,J.rect.height);return{paneId:J.paneId,position:cr(ye,Pe)}}return null},T=(O,ne,B)=>O>=B.left&&O<=B.right&&ne>=B.top&&ne<=B.bottom,Z=(O,ne)=>{for(const B of Array.from(document.querySelectorAll('[data-testid^="window-item-"]'))){const ee=B.getBoundingClientRect();if(ee.width<1||!T(O,ne,ee))continue;const ue=(B.getAttribute("data-testid")??"").replace("window-item-","");return!ue||ue===e.id?null:{type:"window",windowId:ue,rect:{left:ee.left,top:ee.top,width:ee.width,height:ee.height}}}for(const B of Array.from(document.querySelectorAll('[data-slot="sidebar"]'))){const ee=B.getBoundingClientRect();if(!(ee.width<1||!T(O,ne,ee)))return{type:"break",rect:{left:ee.left,top:ee.top,width:ee.width,height:ee.height}}}return null},fe=(O,ne)=>{const B=W(O,ne);return B?B.paneId===l?null:{type:"pane",...B}:Z(O,ne)},je=O=>{const ne=Math.hypot(O.clientX-H,O.clientY-h);!I&&ne<hr||(I=!0,ae({srcPaneId:l,active:!0,pointerX:O.clientX,pointerY:O.clientY,target:fe(O.clientX,O.clientY)}))},Ee=(O,ne)=>{var ee,ue;if(m.removeEventListener("pointermove",je),m.removeEventListener("pointerup",Se),m.removeEventListener("pointercancel",xe),window.removeEventListener("pointerup",Se),window.removeEventListener("pointercancel",xe),ae(null),!ne||!I)return;const B=fe(O.clientX,O.clientY);if(B){if(B.type==="pane"){le(t,l,B.paneId,B.position);return}if(B.type==="window"){const J=(ue=(ee=$.getState().snapshots[t])==null?void 0:ee.session)==null?void 0:ue.windows,ye=J==null?void 0:J.find(Re=>Re.id===B.windowId),Pe=(ye==null?void 0:ye.panes.find(Re=>Re.active))??(ye==null?void 0:ye.panes[0]);Pe&&le(t,l,Pe.id,"right");return}re(t,l)}},Se=O=>Ee(O,!0),xe=O=>Ee(O,!1);m.addEventListener("pointermove",je),window.addEventListener("pointerup",Se),window.addEventListener("pointercancel",xe)},[t,U,le,re,V,_,e.id]),E=n.useCallback(l=>d=>{var u;if(d){P.current.set(l,d);const N=(u=se.current)==null?void 0:u.panes.find(H=>H.paneId===l);N&&d.resize(N.cols,N.rows)}else P.current.delete(l);l===o&&R(d)},[o,R]);if(n.useEffect(()=>{R(P.current.get(o)??null)},[o,R]),!U)return null;const q=(l,d)=>`${l/Math.max(1,d)*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:[U.panes.map(l=>{var m;const d=l.paneId===o,u=G.get(l.paneId),N=mr(u),H=(r==null?void 0:r.active)&&r.srcPaneId===l.paneId,h=r!=null&&r.active&&((m=r.target)==null?void 0:m.type)==="pane"&&r.target.paneId===l.paneId?r.target.position:null;return i.jsxs("div",{className:`absolute flex flex-col overflow-hidden ${H?"opacity-60":""}`,"data-testid":"split-pane","data-pane-id":l.paneId,"data-focused":d||void 0,style:{left:q(l.rect.left,V),top:q(l.rect.top,_),width:q(l.rect.width,V),height:q(l.rect.height,_)},onPointerDownCapture:()=>{d||C(e.id,l.paneId)},children:[i.jsx("div",{className:"shrink-0 px-1.5 pt-1.5 pb-2",style:{height:dr},children:i.jsxs("div",{"data-testid":"split-pane-titlebar","data-active":d||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 ${d?"bg-foreground/10":"bg-foreground/[0.04]"}`,onPointerDown:I=>me(l.paneId,I),children:[i.jsx(pr,{paneId:l.paneId}),i.jsx(wr,{deviceId:t,paneId:l.paneId}),i.jsx("span",{className:`shrink-0 truncate font-mono text-[10.5px] leading-none ${d?"text-foreground/90":"text-foreground/50"}`,children:ft(u)}),N&&i.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-[10px] leading-none ${d?"text-muted-foreground":"text-muted-foreground/60"}`,children:N}),i.jsx("button",{type:"button","data-testid":`split-pane-close-${l.paneId}`,"aria-label":K("window.closePane"),title:K("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:I=>I.stopPropagation(),onClick:I=>{I.stopPropagation(),w(t,l.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":l.paneId,children:i.jsx(st,{ref:E(l.paneId),deviceId:t,paneId:l.paneId,theme:a,inputMode:p,deviceConnected:f,isSelectionInvalid:!1,sizingMode:"follow",autoFocus:d,focused:d,onResize:()=>{},onSync:()=>{}},`${t}:${l.paneId}`)}),h&&i.jsx("div",{"data-testid":"split-pane-drop-preview","data-position":h,className:`pointer-events-none absolute z-30 rounded-sm bg-primary/20 ring-1 ring-inset ring-primary/60 ${gr[h]}`})]},l.paneId)}),(F!==null||(r==null?void 0:r.active))&&i.jsx("div",{"data-testid":"split-drag-shield",className:`absolute inset-0 z-30 ${F!==null?((we=U.gutters[F.gutterIndex])==null?void 0:we.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:ft(G.get(r.srcPaneId))}),((D=r.target)==null?void 0:D.type)==="window"&&i.jsx("div",{className:"text-[9.5px] text-muted-foreground",children:K("window.moveToWindow")}),((pe=r.target)==null?void 0:pe.type)==="break"&&i.jsx("div",{className:"text-[9.5px] text-muted-foreground",children:K("window.breakToWindow")})]}),U.gutters.map((l,d)=>{const u=l.axis==="x",N=(F==null?void 0:F.gutterIndex)===d;return i.jsxs("div",{className:"absolute z-20",style:{left:q(l.rect.left,V),top:q(l.rect.top,_),width:q(u?1:l.rect.width,V),height:q(u?l.rect.height:1,_)},children:[i.jsx("div",{"data-testid":"split-gutter","data-axis":l.axis,className:`absolute touch-none select-none ${u?"-inset-x-1 inset-y-0 cursor-col-resize":"inset-x-0 -inset-y-1 cursor-row-resize"}`,onPointerDown:H=>Q(d,l,H),children:i.jsx("div",{className:`absolute bg-foreground/[0.08] transition-colors hover:bg-primary/50 ${u?"inset-y-0 left-1/2 w-px -translate-x-1/2":"inset-x-0 top-1/2 h-px -translate-y-1/2"} ${N?"bg-primary":""}`})}),N&&F&&i.jsx("div",{className:"pointer-events-none absolute bg-primary/70",style:u?{top:0,bottom:0,width:2,left:`calc(50% + ${F.deltaPx}px)`}:{left:0,right:0,height:2,top:`calc(50% + ${F.deltaPx}px)`}})]},`${e.layout??""}:${d}`)})]})}const vr=1200,br=2e3;function Ie(t,e){return!t||!e?!1:t.windowId===e.windowId&&t.paneId===e.paneId}function St(t,e){const o=t.filter(a=>e-a.at<vr);return o.length===0?null:o.reduce((a,p)=>p.at>a.at?p:a)}function He(t,e=Date.now()){return!t||e-t.at>br?null:t}function Sr(t){const e=t.now??Date.now(),o=St(t.recentSelectRequests,e),a=f=>!!(f&&f.paneId===t.activePaneFromEvent.paneId&&f.windowId!==t.activePaneFromEvent.windowId);if(o&&!Ie(o,t.activePaneFromEvent)&&!a(o)||Ie(t.currentRoute,t.activePaneFromEvent)||Ie(t.lastHandledActive,t.activePaneFromEvent))return!0;const p=He(t.pendingUserSelection,e);return!!(p&&!Ie(p,t.activePaneFromEvent)&&!a(p))}function yr(t){const e=t.now??Date.now(),o=St(t.recentSelectRequests,e),a=He(t.pendingUserSelection,e);return!!(a&&!Ie(a,t.snapshotActive)||o&&!Ie(o,t.snapshotActive))}function Er(t){const e=t.now??Date.now(),o=He(t.pendingUserSelection,e);return!(o&&Ie(o,t.routeTarget)||t.snapshotActive&&Ie(t.snapshotActive,t.routeTarget))}const Qe=n.memo(function({onActivate:e,disabled:o}){const{data:a}=Xe({queryKey:gn,queryFn:wn,staleTime:6e4}),p=(a==null?void 0:a.items)??[];return p.length===0?null:i.jsx("div",{className:"terminal-shortcuts-strip","data-testid":"terminal-shortcuts-strip",children:i.jsx(xn,{items:p,useIcons:(a==null?void 0:a.useIcons)??!1,onActivate:e,disabled:o,preventFocusSteal:!0,rowTestId:"terminal-shortcuts-row",idPrefix:"terminal-shortcut"})})});function kr(){var ct;const{t}=Te(),{deviceId:e,windowId:o,paneId:a}=nt(),p=et(),f=n.useRef(null),R=n.useRef(null),C=n.useRef(null),k=n.useRef(null),X=n.useRef(!1),Y=n.useRef(!1),P=n.useRef(null),F=$(s=>s.selectPane),te=$(s=>s.focusPane),r=$(s=>s.fetchPaneHistory),ae=$(s=>e?s.snapshots[e]:void 0),K=$(s=>{var x;return e?(x=s.deviceErrors)==null?void 0:x[e]:void 0}),L=$(s=>{var x;return e?((x=s.deviceConnected)==null?void 0:x[e])??!1:!1}),he=!!$(s=>{var x;return e?(x=s.deviceReconnecting)==null?void 0:x[e]:void 0}),le=$(s=>e?s.connectedDevices.has(e):!1),re=wt(s=>{var x;return((x=s.settings)==null?void 0:x.siteName)??"tmex"}),w=n.useMemo(()=>rt(a),[a]),G=n.useMemo(()=>e&&w?`${e}:${w}`:null,[e,w]),[M,U]=n.useState(!1),se=n.useRef(!1);n.useEffect(()=>{se.current=M},[M]);const[V,_]=n.useState(""),ie=n.useRef(!1),c=!L||!w,[g,j]=n.useState(!1),b=ge(s=>s.inputMode),S=ge(s=>s.theme),y=ge(s=>s.editorSendWithEnter),z=ge(s=>s.setEditorSendWithEnter),Q=ge(s=>s.addEditorHistory),me=ge(s=>s.setEditorDraft),E=ge(s=>s.removeEditorDraft),q=ge(s=>G?s.editorDrafts[G]??"":""),we=n.useMemo(()=>Wt(),[]),D=(ct=ae==null?void 0:ae.session)==null?void 0:ct.windows,pe=S==="light"?mt:ht,{data:l}=Xe({queryKey:["devices"],queryFn:async()=>{const s=await fetch("/api/devices");if(!s.ok)throw new Error("Failed to fetch devices");return s.json()},throwOnError:!1}),d=n.useMemo(()=>{if(e)return l==null?void 0:l.devices.find(s=>s.id===e)},[e,l==null?void 0:l.devices]),u=n.useMemo(()=>{if(!(!o||!D))return D.find(s=>s.id===o)},[o,D]),N=n.useMemo(()=>{if(!(!w||!u))return u.panes.find(s=>s.id===w)},[w,u]),H=!!D,I=H&&!!o&&!u?t("terminal.windowClosed"):H&&!!o&&!!w&&!!u&&!N?t("terminal.paneClosed"):null,W=!!I,T=!!(L&&w&&!W),Z=!!(!M&&u&&u.panes.length>1&&u.layout&&!W),fe=n.useRef(Z);n.useEffect(()=>{fe.current=Z},[Z]);const je=tt(s=>s.ringingPanes),Ee=n.useMemo(()=>{if(!u||!N)return null;const s=(d==null?void 0:d.name)??e,x=gt({paneCustomName:N.customName,paneTitle:N.title,windowName:u.name,windowCustomName:u.customName,deviceName:s});return je[N.id]?`🔔 ${x}`:x},[d==null?void 0:d.name,e,N,u,je]),Se=n.useMemo(()=>{if(!D||D.length===0)return null;const s=D.find(v=>v.active),x=s==null?void 0:s.panes.find(v=>v.active);return!s||!x?null:{windowId:s.id,paneId:x.id}},[D]),xe=M&&u&&u.panes.length>1?u.id:null,O=n.useRef(xe);n.useEffect(()=>{O.current=xe},[xe]);const ne=n.useRef(!1);n.useEffect(()=>{ne.current=!!D&&!!o},[D,o]);const B=n.useCallback((s,x)=>{if(!e||!w)return;const v=O.current;if(v){$.getState().applyStackedLayout(e,v,s,x);return}se.current&&!ne.current||$.getState().resizePane(e,w,s,x)},[e,w]),ee=n.useCallback((s,x)=>{if(!e||!w)return;const v=O.current;if(v){$.getState().applyStackedLayout(e,v,s,x);return}se.current&&!ne.current||$.getState().syncPaneSize(e,w,s,x)},[e,w]),ue=n.useCallback(()=>{e&&$.getState().syncThemeAfterResize(e)},[e]),J=n.useCallback((s,x)=>{var Be;const v=k.current;if(fe.current){const be=(Be=f.current)==null?void 0:Be.getBoundingClientRect(),Ve=v==null?void 0:v.getCellSize();return be&&Ve&&be.width>0&&be.height>0?{cols:Math.max(2,Math.floor(be.width/Ve.width)),rows:Math.max(2,Math.floor(be.height/Ve.height))}:void 0}if(se.current)return;const A=(v==null?void 0:v.calculateSizeFromContainer())??(v==null?void 0:v.getSize())??void 0;if(A)return A;if(!s||!x||!D)return;const oe=D.find(be=>be.id===s),ve=oe==null?void 0:oe.panes.find(be=>be.id===x);if(!(!ve||ve.width<=1||ve.height<=1))return{cols:ve.width,rows:ve.height}},[D]),ye=n.useCallback((s,x)=>{e&&(P.current={windowId:s,paneId:x,at:Date.now()},p(`/devices/${e}/windows/${s}/panes/${Me(x)}`,{replace:!0}))},[e,p]),Pe=n.useCallback(s=>{k.current=s},[]);n.useEffect(()=>{const s=()=>{U(window.innerWidth<768||"ontouchstart"in window)};return s(),window.addEventListener("resize",s),()=>window.removeEventListener("resize",s)},[]),n.useEffect(()=>{if(!M||!we||Y.current)return;Y.current=!0;const s=()=>{window.scrollTo(0,1)},x=window.requestAnimationFrame(s),v=window.setTimeout(s,120),A=window.setTimeout(s,420);return()=>{window.cancelAnimationFrame(x),window.clearTimeout(v),window.clearTimeout(A)}},[we,M]),n.useEffect(()=>{e&&(X.current=!1,De.current=null,ze.current=null,P.current=null,Re.current=[])},[e]),n.useEffect(()=>{L||(X.current=!1)},[L]),n.useEffect(()=>{if(!e||!L||!o||!D)return;if(D.length===0){p("/devices",{replace:!0});return}const s=D.find(v=>v.id===o);if(!s)return;if(!w){const v=s.panes.find(A=>A.active)??s.panes[0];v&&p(`/devices/${e}/windows/${o}/panes/${Me(v.id)}`,{replace:!0});return}if(!s.panes.find(v=>v.id===w)){const v=D.find(oe=>oe.panes.some(ve=>ve.id===w));if(v){p(`/devices/${e}/windows/${v.id}/panes/${Me(w)}`,{replace:!0});return}const A=s.panes.find(oe=>oe.active)??s.panes[0];A&&p(`/devices/${e}/windows/${o}/panes/${Me(A.id)}`,{replace:!0});return}},[e,L,D,o,w,p]),n.useEffect(()=>{if(!e||!L||!D||D.length===0||o&&w||X.current)return;const s=D.find(v=>v.active)??D[0],x=s.panes.find(v=>v.active)??s.panes[0];x&&(X.current=!0,p(`/devices/${e}/windows/${s.id}/panes/${Me(x.id)}`,{replace:!0}))},[L,e,p,w,o,D]);const Re=n.useRef([]),Ce=n.useCallback((s,x)=>{const v=Date.now(),A=[...Re.current.filter(oe=>v-oe.at<2e3),{windowId:s,paneId:x,at:v}];Re.current=A.slice(-8)},[]),Le=n.useRef(null);n.useEffect(()=>{Le.current=null},[e,w]);const Ae=n.useRef(null),_e=n.useRef(Z);n.useEffect(()=>{_e.current!==Z&&(_e.current=Z,Le.current=null,Ae.current=null)},[Z]),n.useEffect(()=>{if(!e||!o||!w||c||!L)return;const s=`${e}:${o}:${w}`;if(Le.current===s)return;Le.current=s;const x=Z&&Ae.current===`${e}:${o}`&&!!(u!=null&&u.panes.some(A=>A.id===w));if(Ce(o,w),x){te(e,o,w);return}const v=J(o,w);F(e,o,w,v),Ae.current=`${e}:${o}`},[L,e,te,J,c,Z,Ce,w,F,u,o]),n.useEffect(()=>{if(!e||!L||!o||!w)return;const s={windowId:o,paneId:w};Er({routeTarget:s,snapshotActive:Se,pendingUserSelection:P.current})&&(P.current={windowId:s.windowId,paneId:s.paneId,at:Date.now()})},[L,e,w,Se,o]);const ce=$(s=>e?s.activePaneFromEvent[e]:void 0),De=n.useRef(null);n.useEffect(()=>{if(!e||!L||!o||!w||!ce)return;const s=Date.now(),x=He(P.current,s);if(P.current=x,Sr({now:s,pendingUserSelection:x,activePaneFromEvent:ce,currentRoute:{windowId:o,paneId:w},recentSelectRequests:Re.current,lastHandledActive:De.current}))return;if(De.current={...ce},x&&x.windowId===ce.windowId&&x.paneId===ce.paneId&&(P.current=null),!(fe.current&&ce.windowId===o)){const A=J(ce.windowId,ce.paneId);Ce(ce.windowId,ce.paneId),F(e,ce.windowId,ce.paneId,A)}p(`/devices/${e}/windows/${ce.windowId}/panes/${Me(ce.paneId)}`,{replace:!0})},[e,L,o,w,ce,Ce,J,F,p]);const ze=n.useRef(null);n.useEffect(()=>{if(!e||!L||!D||D.length===0)return;const s=Re.current,x=D.find(be=>be.active);if(!x)return;const v=x.panes.find(be=>be.active);if(!v)return;const A={windowId:x.id,paneId:v.id},oe=Date.now(),ve=He(P.current,oe);if(P.current=ve,yr({now:oe,pendingUserSelection:ve,snapshotActive:A,recentSelectRequests:s})||ze.current&&ze.current.windowId===A.windowId&&ze.current.paneId===A.paneId||(ze.current={...A},ve&&ve.windowId===A.windowId&&ve.paneId===A.paneId&&(P.current=null),o===A.windowId&&w===A.paneId))return;if(!(fe.current&&A.windowId===o)){const be=J(A.windowId,A.paneId);Ce(A.windowId,A.paneId),F(e,A.windowId,A.paneId,be)}p(`/devices/${e}/windows/${A.windowId}/panes/${Me(A.paneId)}`,{replace:!0})},[e,L,D,o,w,Ce,J,F,p]);const Ue=$(s=>e?s.pendingCreateWindowAt[e]:void 0);n.useEffect(()=>{if(!e||!L||!Ue)return;const s=5e3,x=Date.now()-Ue;if(x>s){$.getState().clearPendingCreateWindow(e);return}if(!Se){const oe=window.setTimeout(()=>{$.getState().clearPendingCreateWindow(e)},s-x);return()=>window.clearTimeout(oe)}const v=Se;if(o===v.windowId&&w===v.paneId){const oe=window.setTimeout(()=>{$.getState().clearPendingCreateWindow(e)},s-x);return()=>window.clearTimeout(oe)}P.current={windowId:v.windowId,paneId:v.paneId,at:Date.now()};const A=J(v.windowId,v.paneId);Ce(v.windowId,v.paneId),F(e,v.windowId,v.paneId,A),p(`/devices/${e}/windows/${v.windowId}/panes/${Me(v.paneId)}`,{replace:!0}),$.getState().clearPendingCreateWindow(e)},[e,L,Ue,Se,o,w,Ce,J,F,p]),n.useEffect(()=>{if(Z||!T||!N||c)return;const s=k.current,x=s==null?void 0:s.getTerminal();if(!x)return;const v=Math.max(2,Math.floor(N.width||0)),A=Math.max(2,Math.floor(N.height||0));if(!v||!A)return;const oe=Date.now(),ve={cols:v,rows:A},Be=(s==null?void 0:s.getPendingLocalSize())??null;Kn({now:oe,remoteSize:ve,pendingLocalSize:Be})&&(x.cols===v&&x.rows===A||(x.resize(v,A),e&&w&&r(e,w)))},[T,e,r,c,Z,w,N]),n.useEffect(()=>{const s=window.requestAnimationFrame(()=>{var v;(v=k.current)==null||v.scrollToBottom()}),x=window.setTimeout(()=>{var v;(v=k.current)==null||v.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(s),window.clearTimeout(x)}},[b]),n.useEffect(()=>{K!=null&&K.message&&ke.error(K.message)},[K==null?void 0:K.message]),n.useEffect(()=>(document.title=Ot(Ee),()=>{document.title=re}),[re,Ee]),n.useEffect(()=>{const s=()=>{var x;(x=k.current)==null||x.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",s),()=>{window.removeEventListener("tmex:jump-to-latest",s)}},[]),n.useEffect(()=>{const s=x=>{const{deviceId:v,windowId:A,paneId:oe}=x.detail;v===e&&(P.current={windowId:A,paneId:oe,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",s),()=>{window.removeEventListener("tmex:user-initiated-selection",s)}},[e]),n.useEffect(()=>{_(q)},[q]);const ot=n.useCallback(s=>{if(!e||!w||!T)return;$.getState().sendInput(e,w,s,!1)},[T,e,w]),qe=n.useCallback(s=>{var x,v;if(s.type==="action"){if(s.action==="toggleKeyboard"){ge.getState().setInputMode(b==="direct"?"editor":"direct");return}if(s.action==="scrollToBottom"){(x=k.current)==null||x.scrollToBottom();return}}if(s.type==="send"){s.payload&&ot(s.payload);return}if(!(!e||!w||!T))switch(s.action){case"paste":{((v=navigator.clipboard)!=null&&v.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(oe=>{oe&&$.getState().paste(e,w,oe)}).catch(()=>ke.error(t("terminal.pasteFailed")));break}case"newAgentSession":pt.getState().startDraft(e,w,null),ge.getState().setSidebarCollapsed(!1),ge.getState().setSidebarTab("agent");break}},[T,e,ot,b,w,t]),yt=n.useCallback(()=>{if(!T){ke.error(t("wsError.checkGateway"));return}if(!e||!w||!V.trim())return;j(!0),window.setTimeout(()=>j(!1),150);const s=y?`${V}\r`:V;$.getState().sendInput(e,w,s,!1),Q(V),G&&E(G),_("")},[Q,T,e,G,y,V,E,w,t]),Et=n.useCallback(()=>{if(!T){ke.error(t("wsError.checkGateway"));return}if(!e||!w||!V.trim())return;j(!0),window.setTimeout(()=>j(!1),150);const s=V.split(/\r?\n/),x=$.getState();for(const v of s)v.trim()&&x.sendInput(e,w,`${v}\r`,!1);Q(V),G&&E(G),_("")},[Q,T,e,G,V,E,w,t]),Rt=n.useCallback(()=>{var s;(s=C.current)==null||s.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 jt=!!w&&!W&&(L||he),Ct=L&&!!w&&!W&&!N,Nt=le&&!L&&!K&&!he,it=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(Ke,{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 ${M&&b==="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:pe.background},children:[W?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(Dn,{className:"h-6 w-6 text-muted-foreground"})}),i.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"terminal-selection-invalid",children:I})]})}):jt&&w?Z&&u?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:f,className:"relative min-h-0 flex-1",children:i.jsx(xr,{deviceId:e,window:u,focusedPaneId:w,theme:S,inputMode:b,deviceConnected:L,focusedTerminalRef:Pe,onUserSelectPane:ye,onWindowResize:B,onWindowResizeSettled:ue},`${e}:${u.id}`)}),b==="direct"&&i.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:pe.background},children:i.jsx(Qe,{onActivate:qe,disabled:!T})})]}):i.jsx("div",{ref:f,className:"flex-1 h-full min-h-0 w-full","data-virtual-keyboard-avoid":!0,children:i.jsx(st,{ref:k,deviceId:e,paneId:w,theme:S,inputMode:b,deviceConnected:L,isSelectionInvalid:W,onResize:B,onSync:ee,onResizeSettled:ue,children:b==="direct"&&i.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:pe.background},children:i.jsx(Qe,{onActivate:qe,disabled:!T})})},`${e}:${w}`)}):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:Nt?it:!L&&!he?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")})]}):o?it: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")})]})})}),he&&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(Xt,{deviceId:e,className:"shadow-sm"})}),Ct&&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")})]})})]})}),b==="editor"&&i.jsxs("div",{ref:R,"data-virtual-keyboard-avoid":!0,className:"editor-mode-input bg-card/85 backdrop-blur-sm",children:[M&&i.jsx(Qe,{onActivate:s=>{qe(s),s.type==="send"&&Rt()},disabled:!T}),i.jsx("textarea",{ref:C,"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:V,onChange:s=>{const x=s.target.value;if(_(x),!!G){if(x){me(G,x);return}E(G)}},placeholder:t("terminal.inputPlaceholder"),onCompositionStart:()=>{ie.current=!0},onCompositionEnd:()=>{ie.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(Ut,{size:"sm",checked:y,onCheckedChange:s=>z(!!s)}),i.jsx("span",{children:t("terminal.editorSendWithEnter")})]}),i.jsxs(Ne,{variant:"outline",size:"sm","data-testid":"editor-clear",onMouseDown:s=>s.preventDefault(),onClick:()=>{var s;_(""),G&&E(G),M&&b==="editor"&&((s=C.current)==null||s.focus({preventScroll:!0}))},title:t("terminal.clear"),children:[i.jsx(qt,{className:"h-4 w-4"}),t("terminal.clear")]}),i.jsxs(Ne,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onMouseDown:s=>s.preventDefault(),onClick:()=>{var s;Et(),M&&b==="editor"&&((s=C.current)==null||s.focus({preventScroll:!0}))},disabled:!T||g,children:[g?i.jsx(Ke,{className:"h-4 w-4 animate-spin"}):i.jsx(at,{className:"h-4 w-4"}),t("terminal.editorSendLineByLine")]}),i.jsxs(Ne,{variant:"default",size:"sm","data-testid":"editor-send",onMouseDown:s=>s.preventDefault(),onClick:()=>{var s;yt(),M&&b==="editor"&&((s=C.current)==null||s.focus({preventScroll:!0}))},disabled:!T||g,children:[g?i.jsx(Ke,{className:"h-4 w-4 animate-spin"}):i.jsx(at,{className:"h-4 w-4"}),t("common.send")]})]})})]})]})}function Ir(){const{deviceId:t,windowId:e,paneId:o}=nt(),a=o?rt(o):void 0,p=$(P=>P.snapshots),f=wt(P=>{var F;return((F=P.settings)==null?void 0:F.siteName)??"tmex"}),R=t?p[t]:void 0,C=n.useMemo(()=>{var P;if(!(!e||!((P=R==null?void 0:R.session)!=null&&P.windows)))return R.session.windows.find(F=>F.id===e)},[e,R]),k=n.useMemo(()=>{if(!(!a||!C))return C.panes.find(P=>P.id===a)},[a,C]),X=n.useMemo(()=>C&&k?gt({paneCustomName:k.customName,paneTitle:k.title,windowName:C.name,windowCustomName:C.customName,deviceName:f}):t??"",[C,k,f,t]),Y=tt(P=>a?!!P.ringingPanes[a]:!1);return i.jsxs(i.Fragment,{children:[Y&&i.jsx("span",{className:"bell-blink",children:"🔔 "}),X]})}function Tr(){const{t}=Te(),{deviceId:e,windowId:o,paneId:a}=nt(),p=et(),f=Vt(),R=a?rt(a):void 0,C=ge(_=>_.inputMode),k=ge(_=>_.setInputMode),X=$(_=>{var ie;return e?((ie=_.deviceConnected)==null?void 0:ie[e])??!1:!1}),Y=$(_=>e?_.snapshots[e]:void 0),P=n.useMemo(()=>{var _;if(!(!o||!((_=Y==null?void 0:Y.session)!=null&&_.windows)))return Y.session.windows.find(ie=>ie.id===o)},[o,Y]),F=n.useCallback(_=>{!e||!o||p(`/devices/${e}/windows/${o}/panes/${Me(_)}`,{replace:!0})},[e,o,p]),te=n.useMemo(()=>{if(!(!R||!P))return P.panes.find(_=>_.id===R)},[R,P]),r=n.useCallback(_=>{!e||!R||$.getState().splitPane(e,R,_,te==null?void 0:te.currentPath)},[e,R,te==null?void 0:te.currentPath]),[ae,K]=n.useState(!1),[L,de]=n.useState(!1),[he,le]=n.useState(!1),re=!!(R&&X),G=(Xe({queryKey:Gt(e??"",R??""),queryFn:()=>Kt(e??"",R??""),enabled:!!(e&&R),throwOnError:!1}).data??[]).some(_=>_.enabled),M=()=>{k(C==="direct"?"editor":"direct")},U=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},se=()=>{K(!0)},V=()=>{window.location.reload()};return i.jsxs(i.Fragment,{children:[f&&R&&P&&P.panes.length>1&&i.jsx(nr,{window:P,currentPaneId:R,onSelectPane:F}),!f&&i.jsxs(i.Fragment,{children:[i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:()=>r("right"),disabled:!re,"data-testid":"split-right-button","aria-label":t("window.splitRight"),title:t("window.splitRight"),children:i.jsx(Qt,{className:"h-4 w-4"})}),i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:()=>r("down"),disabled:!re,"data-testid":"split-down-button","aria-label":t("window.splitDown"),title:t("window.splitDown"),children:i.jsx(Zt,{className:"h-4 w-4"})})]}),i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:se,"aria-label":t("nav.refreshPage"),title:t("nav.refreshPage"),children:i.jsx(mn,{className:"h-4 w-4"})}),i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:M,disabled:!re,"data-testid":"terminal-input-mode-toggle","aria-label":t(C==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:t(C==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:C==="direct"?i.jsx(Rn,{className:"h-4 w-4"}):i.jsx(Fn,{className:"h-4 w-4"})}),i.jsx(Ne,{variant:"ghost",size:"icon-sm",onClick:U,disabled:!re,"aria-label":t("nav.jumpToLatest"),title:t("nav.jumpToLatest"),children:i.jsx(pn,{className:"h-4 w-4"})}),i.jsxs(Ne,{variant:"ghost",size:"icon-sm",className:"relative",onClick:()=>de(!0),disabled:!R,"data-testid":"watch-open-button","aria-label":t("watch.title"),title:t("watch.title"),children:[i.jsx(Jt,{className:"h-4 w-4"}),G&&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(Ne,{variant:"ghost",size:"icon-sm",onClick:()=>le(!0),"data-testid":"keyboard-behavior-open-button","aria-label":t("settings.terminal.title"),title:t("settings.terminal.title"),children:i.jsx(Bn,{className:"h-4 w-4"})}),i.jsx(Hn,{open:he,onOpenChange:le}),e&&R&&i.jsx(en,{open:L,onOpenChange:de,deviceId:e,paneId:R}),i.jsx(tn,{open:ae,onOpenChange:K,children:i.jsxs(nn,{children:[i.jsxs(rn,{children:[i.jsx(sn,{children:t("nav.refreshPage")}),i.jsx(on,{children:t("nav.refreshPageConfirm")})]}),i.jsxs(cn,{children:[i.jsx(an,{onClick:()=>K(!1),children:t("common.cancel")}),i.jsx(ln,{onClick:V,children:t("common.confirm")})]})]})})]})}export{Tr as PageActions,Ir as PageTitle,kr 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-U4iZ6Kxr.js";import{C as M,a as P,b as Ae,c as Te,d as Fe}from"./card-IkOsEv2J.js";import{Z as We}from"./zap-ClXbg92C.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-CxD8veUJ.js";import{C as M,a as P,b as Ae,c as Te,d as Fe}from"./card-Bav-X9c4.js";import{Z as We}from"./zap-D-Szn4JY.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};
|