tmex-cli 0.15.2 → 0.16.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +38 -8
  2. package/dist/runtime/server.js +869 -165
  3. package/package.json +1 -1
  4. package/resources/fe-dist/assets/DevicePage-CxCVolw8.js +24 -0
  5. package/resources/fe-dist/assets/{DevicesPage-DVAiqqAb.js → DevicesPage-_SYGKgwy.js} +1 -1
  6. package/resources/fe-dist/assets/{FilePage-DzKIB_pN.js → FilePage-Blf_MlAq.js} +1 -1
  7. package/resources/fe-dist/assets/{SettingsPage-BTLab-Z3.js → SettingsPage-BRt22APt.js} +1 -1
  8. package/resources/fe-dist/assets/{agent-tab-DRxXq67W.js → agent-tab-DRkW6D0y.js} +4 -4
  9. package/resources/fe-dist/assets/{api-B_pG5Lrn.js → api-C2-crTt8.js} +1 -1
  10. package/resources/fe-dist/assets/{arc-Bct5uFHQ.js → arc-Bzi-2Wgo.js} +1 -1
  11. package/resources/fe-dist/assets/{architectureDiagram-3BPJPVTR-BRDZ_iL7.js → architectureDiagram-3BPJPVTR-DZYFrhja.js} +1 -1
  12. package/resources/fe-dist/assets/{blockDiagram-GPEHLZMM-COe9KyYv.js → blockDiagram-GPEHLZMM-lpc1A1G1.js} +1 -1
  13. package/resources/fe-dist/assets/{c4Diagram-AAUBKEIU-DtQTgbwo.js → c4Diagram-AAUBKEIU-DOc1BzPY.js} +1 -1
  14. package/resources/fe-dist/assets/{card-DAJtOO99.js → card-BA66zlg1.js} +1 -1
  15. package/resources/fe-dist/assets/channel-DFyg9jlp.js +1 -0
  16. package/resources/fe-dist/assets/{chunk-2J33WTMH-D4_zLlF4.js → chunk-2J33WTMH-DqycjO3G.js} +1 -1
  17. package/resources/fe-dist/assets/{chunk-4BX2VUAB-C3M9MnUk.js → chunk-4BX2VUAB-t2B-Cl6x.js} +1 -1
  18. package/resources/fe-dist/assets/{chunk-55IACEB6-D5BgUYDW.js → chunk-55IACEB6-BmFdQL7n.js} +1 -1
  19. package/resources/fe-dist/assets/{chunk-727SXJPM-C03K3kUu.js → chunk-727SXJPM-DEa9FPer.js} +1 -1
  20. package/resources/fe-dist/assets/{chunk-AQP2D5EJ-DLv4_X-p.js → chunk-AQP2D5EJ-DiZ9AoB9.js} +1 -1
  21. package/resources/fe-dist/assets/{chunk-FMBD7UC4-CXm-3D35.js → chunk-FMBD7UC4-DLcIMhi1.js} +1 -1
  22. package/resources/fe-dist/assets/{chunk-ND2GUHAM-DH_J0yjP.js → chunk-ND2GUHAM-Cu1P2Ot8.js} +1 -1
  23. package/resources/fe-dist/assets/{chunk-QZHKN3VN-D5HtoYCj.js → chunk-QZHKN3VN-C8ki16q3.js} +1 -1
  24. package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-CAgGMVvn.js +1 -0
  25. package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-CAgGMVvn.js +1 -0
  26. package/resources/fe-dist/assets/{copy-BfLwocwm.js → copy-C8vDYUVz.js} +1 -1
  27. package/resources/fe-dist/assets/{cose-bilkent-S5V4N54A-be9ShD_r.js → cose-bilkent-S5V4N54A-baMBJteT.js} +1 -1
  28. package/resources/fe-dist/assets/{dagre-BM42HDAG-CC-KfeHH.js → dagre-BM42HDAG-CwWSiSwb.js} +1 -1
  29. package/resources/fe-dist/assets/{diagram-2AECGRRQ-BwKHXV4n.js → diagram-2AECGRRQ-CeSwouYZ.js} +1 -1
  30. package/resources/fe-dist/assets/{diagram-5GNKFQAL-Bqwpz1fr.js → diagram-5GNKFQAL-DgxdcMax.js} +1 -1
  31. package/resources/fe-dist/assets/{diagram-KO2AKTUF-CeMGb0yy.js → diagram-KO2AKTUF-DrglkRZC.js} +1 -1
  32. package/resources/fe-dist/assets/{diagram-LMA3HP47-Bsi1wTvw.js → diagram-LMA3HP47-BLHZ3p7v.js} +1 -1
  33. package/resources/fe-dist/assets/{diagram-OG6HWLK6-B4t3XGFO.js → diagram-OG6HWLK6-_I_mMaa6.js} +1 -1
  34. package/resources/fe-dist/assets/{en_US-Cf2EOKiI.js → en_US-CjVU4anP.js} +1 -1
  35. package/resources/fe-dist/assets/{erDiagram-TEJ5UH35-3Mvka2ky.js → erDiagram-TEJ5UH35-Zkbnn8Kh.js} +1 -1
  36. package/resources/fe-dist/assets/{files-tab-CozXv_f8.js → files-tab-CPud4eIT.js} +5 -5
  37. package/resources/fe-dist/assets/{flowDiagram-I6XJVG4X-DkGA4Ke1.js → flowDiagram-I6XJVG4X-BnV7dZI4.js} +1 -1
  38. package/resources/fe-dist/assets/{ganttDiagram-6RSMTGT7-3vhFpRP7.js → ganttDiagram-6RSMTGT7-Cn2f5kRI.js} +1 -1
  39. package/resources/fe-dist/assets/{gitGraphDiagram-PVQCEYII-CQV7XGpo.js → gitGraphDiagram-PVQCEYII-CEswG7nI.js} +1 -1
  40. package/resources/fe-dist/assets/index-BK6c5W5S.js +314 -0
  41. package/resources/fe-dist/assets/index-CuFTSN9i.css +1 -0
  42. package/resources/fe-dist/assets/{index-CxrkvaQh.js → index-DLyPliOu.js} +1 -1
  43. package/resources/fe-dist/assets/{infoDiagram-5YYISTIA-Do4YMzZB.js → infoDiagram-5YYISTIA-Dsx1fQI9.js} +1 -1
  44. package/resources/fe-dist/assets/{ishikawaDiagram-YF4QCWOH-D0s__l6a.js → ishikawaDiagram-YF4QCWOH-CgNMvXgO.js} +1 -1
  45. package/resources/fe-dist/assets/{ja_JP-s3e_OwvM.js → ja_JP-Bq-BwOH_.js} +1 -1
  46. package/resources/fe-dist/assets/{journeyDiagram-JHISSGLW-DZWnugOc.js → journeyDiagram-JHISSGLW-CVeui1xn.js} +1 -1
  47. package/resources/fe-dist/assets/{kanban-definition-UN3LZRKU-BgRtdsFS.js → kanban-definition-UN3LZRKU-WnLUDsz4.js} +1 -1
  48. package/resources/fe-dist/assets/{linear-yx1vNDZX.js → linear-B0SWPrkI.js} +1 -1
  49. package/resources/fe-dist/assets/{markdown-preview-BE4zuZfN.js → markdown-preview-CDjnYorp.js} +3 -3
  50. package/resources/fe-dist/assets/{mermaid.core-DE3GlZm2.js → mermaid.core-CXD-Pc2r.js} +5 -5
  51. package/resources/fe-dist/assets/{mindmap-definition-RKZ34NQL-25O7ch2Y.js → mindmap-definition-RKZ34NQL-DYEXXmag.js} +1 -1
  52. package/resources/fe-dist/assets/{pieDiagram-4H26LBE5-Nsg0nJjf.js → pieDiagram-4H26LBE5-DkZtnbYj.js} +1 -1
  53. package/resources/fe-dist/assets/{quadrantDiagram-W4KKPZXB-vf_qGk-r.js → quadrantDiagram-W4KKPZXB-DblvGass.js} +1 -1
  54. package/resources/fe-dist/assets/{requirementDiagram-4Y6WPE33-BFfrHVO7.js → requirementDiagram-4Y6WPE33-KAX1DxRY.js} +1 -1
  55. package/resources/fe-dist/assets/{sankeyDiagram-5OEKKPKP-Ce_HayCK.js → sankeyDiagram-5OEKKPKP-h9Z2LXNr.js} +1 -1
  56. package/resources/fe-dist/assets/{selection-clipboard-Dq6Zemfd.js → selection-clipboard-D3gUQQ7L.js} +1 -1
  57. package/resources/fe-dist/assets/{send-CKtMOmLP.js → send-BVxB0Ywb.js} +1 -1
  58. package/resources/fe-dist/assets/{sequenceDiagram-3UESZ5HK-C2vovJ8X.js → sequenceDiagram-3UESZ5HK-DUJcq5qX.js} +1 -1
  59. package/resources/fe-dist/assets/{stateDiagram-AJRCARHV-CLu4laAA.js → stateDiagram-AJRCARHV-BBT56nPD.js} +1 -1
  60. package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-wyzFZc_5.js +1 -0
  61. package/resources/fe-dist/assets/{terminal-settings-panel-DAWL48fe.js → terminal-settings-panel-DHrIp0wf.js} +1 -1
  62. package/resources/fe-dist/assets/{timeline-definition-PNZ67QCA-DkWMKmAT.js → timeline-definition-PNZ67QCA-DLkgXxGG.js} +1 -1
  63. package/resources/fe-dist/assets/{transfer-toast-CHZr1a7O.js → transfer-toast-BYw9LLNi.js} +1 -1
  64. package/resources/fe-dist/assets/{triangle-alert-03d4TB5d.js → triangle-alert-D4oQhgpz.js} +1 -1
  65. package/resources/fe-dist/assets/{vennDiagram-CIIHVFJN-BBlcBoH2.js → vennDiagram-CIIHVFJN-CyUw7cRl.js} +1 -1
  66. package/resources/fe-dist/assets/{wardley-L42UT6IY-BnzmzjjA.js → wardley-L42UT6IY-UVd2D_HQ.js} +1 -1
  67. package/resources/fe-dist/assets/{wardleyDiagram-YWT4CUSO-B3u1V3qc.js → wardleyDiagram-YWT4CUSO-B6As-5ml.js} +1 -1
  68. package/resources/fe-dist/assets/{xychartDiagram-2RQKCTM6-BTm5HZXX.js → xychartDiagram-2RQKCTM6-DFypVaEh.js} +1 -1
  69. package/resources/fe-dist/assets/{zap-CBeeCQFr.js → zap-DxVtkroR.js} +1 -1
  70. package/resources/fe-dist/assets/{zh_CN-6UyMkvZM.js → zh_CN-BuxyXhCT.js} +1 -1
  71. package/resources/fe-dist/index.html +2 -2
  72. package/resources/fe-dist/assets/DevicePage-BvwXdfhK.js +0 -19
  73. package/resources/fe-dist/assets/channel-CIG-CxyN.js +0 -1
  74. package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-CNRZMNkk.js +0 -1
  75. package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-CNRZMNkk.js +0 -1
  76. package/resources/fe-dist/assets/index-CEPc0i5O.js +0 -304
  77. package/resources/fe-dist/assets/index-CHeveVji.css +0 -1
  78. package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-CIfUS4rj.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmex-cli",
3
- "version": "0.15.2",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "tmex": "./bin/tmex.js",
@@ -0,0 +1,24 @@
1
+ import{Y as Xe,u as Pe,j as o,aD as Et,aE as Rt,aF as Tt,aG as Ct,aH as jt,at as Nt,r as n,d as O,af as ge,ai as at,ah as lt,ag as Mt,aj as Pt,aI as kt,aJ as It,o as Me,aK as Lt,D as At,p as Dt,q as _t,s as zt,aL as Ze,aw as ut,b as dt,aM as et,aN as $t,c as tt,aC as ft,aO as Ce,aP as Bt,ay as Ft,aq as qe,y as Ht,a2 as Wt,B as Re,T as Ot,aQ as Xt,aR as qt,aS as Yt,aT as Ut,aU as Vt,$ as Kt,aV as Gt,A as Qt,f as Jt,g as Zt,i as en,k as tn,l as nn,m as rn,n as sn}from"./index-BK6c5W5S.js";import{T as on,C as cn,c as an,F as ln,a as ht,R as un,A as dn,f as fn,t as hn,S as mn}from"./terminal-settings-panel-DHrIp0wf.js";import{e as wn}from"./selection-clipboard-D3gUQQ7L.js";import{C as pn}from"./copy-C8vDYUVz.js";import{S as ot,K as gn}from"./send-BVxB0Ywb.js";const xn=/^[0-9a-fA-F]{4}$/;function vn(e){if(typeof e!="string"||e.length<6)return null;const t=e.slice(0,4);if(!xn.test(t)||e[4]!==",")return null;const r={input:e,pos:5},c=mt(r);return!c||r.pos!==e.length?null:{checksum:t,root:c}}function $e(e){const t=e.pos;for(;e.pos<e.input.length;){const r=e.input.charCodeAt(e.pos);if(r<48||r>57)break;e.pos+=1}return e.pos===t?null:Number.parseInt(e.input.slice(t,e.pos),10)}function Be(e,t){return e.input[e.pos]!==t?!1:(e.pos+=1,!0)}function mt(e){const t=$e(e);if(t===null||!Be(e,"x"))return null;const r=$e(e);if(r===null||!Be(e,","))return null;const c=$e(e);if(c===null||!Be(e,","))return null;const l=$e(e);if(l===null)return null;const m=e.input[e.pos];if(m===","){e.pos+=1;const v=$e(e);return v===null?null:{type:"leaf",paneNumId:v,width:t,height:r,x:c,y:l}}if(m==="{"||m==="["){const v=m==="{"?"}":"]";e.pos+=1;const b=[];for(;;){const C=mt(e);if(!C)return null;if(b.push(C),!Be(e,",")){if(Be(e,v))break;return null}}return b.length<2?null:{type:m==="{"?"row":"column",width:t,height:r,x:c,y:l,children:b}}return null}function Ye(e){return`%${e.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 bn=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],Sn=Xe("columns-2",bn);/**
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 yn=[["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"}]],En=Xe("search-x",yn);/**
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 Rn=[["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"}]],Tn=Xe("settings-2",Rn);/**
17
+ * @license lucide-react v0.564.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const Cn=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],jn=Xe("smartphone",Cn);function Nn({open:e,onOpenChange:t}){const{t:r}=Pe();return o.jsx(Et,{open:e,onOpenChange:t,children:o.jsxs(Rt,{side:"bottom",className:"max-h-[88dvh] overflow-y-auto pb-[var(--tmex-safe-area-bottom)] sm:mx-auto sm:max-w-md sm:rounded-t-2xl sm:border sm:border-b-0","data-testid":"keyboard-behavior-sheet",children:[o.jsxs(Tt,{children:[o.jsx(Ct,{children:r("settings.terminal.title")}),o.jsx(jt,{children:r("settings.terminal.savedInBrowser")})]}),o.jsx("div",{className:"px-4 pb-4",children:o.jsx(on,{})})]})})}function Mn({visible:e,canPaste:t,onCopy:r,onPaste:c,onDismiss:l}){const{t:m}=Pe();if(!e)return null;const v=b=>{b.preventDefault()};return o.jsxs("div",{className:"absolute top-2 left-1/2 z-20 flex -translate-x-1/2 items-center gap-1 rounded-lg border bg-background/95 p-1 shadow-md backdrop-blur","data-testid":"terminal-selection-toolbar",children:[o.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:v,onClick:r,"data-testid":"terminal-selection-copy",children:[o.jsx(pn,{className:"h-4 w-4"}),m("terminal.copy")]}),t&&o.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:v,onClick:c,"data-testid":"terminal-selection-paste",children:[o.jsx(cn,{className:"h-4 w-4"}),m("terminal.paste")]}),o.jsx("button",{type:"button",className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground",onMouseDown:v,onClick:l,"aria-label":m("terminal.clearSelection"),"data-testid":"terminal-selection-dismiss",children:o.jsx(Nt,{className:"h-4 w-4"})})]})}function wt(e){if(!e)return e;const t=e.replace(/\r\n/g,`
22
+ `);return(t.endsWith(`
23
+ `)?t.slice(0,-1):t).replace(/\n/g,`\r
24
+ `)}const Pn="\x1B[?1049h\x1B[H\x1B[2J";function kn(e){return Pn+wt(e)}function In(e,t){let r=t,c=0;for(const b of e)b===10&&!r&&(c+=1),r=b===13;const l=r;if(c===0)return{normalized:e,endedWithCR:l};const m=new Uint8Array(e.length+c);let v=0;r=t;for(const b of e)b===10&&!r&&(m[v]=13,v+=1),m[v]=b,v+=1,r=b===13;return{normalized:m,endedWithCR:l}}const Ln=1.3,An=36,Dn=500,_n=12;function zn(e,t){const r=n.useRef(!1);return n.useEffect(()=>{const c=e.current;if(!c||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;r.current=!0;let m=0,v=null,b=!1,C=0,F=0,z=0,j=null,i=!1;const y=()=>{j!==null&&(clearTimeout(j),j=null)},ue=S=>S?!!(S.closest(".scrollbar")||S.closest(".slider")||S.closest(".xterm-scroll-area")):!1,U=(S,p,k)=>{const R=k instanceof Element?k:null;if(ue(R))return!0;const _=document.elementFromPoint(S,p);if(ue(_))return!0;const G=c.querySelector(".xterm");if(!(G instanceof HTMLElement))return!1;const u=G.getBoundingClientRect(),A=S>=u.left&&S<=u.right,Y=p>=u.top&&p<=u.bottom;return!A||!Y?!1:S>=u.right-An},M=()=>[c.querySelector(".xterm-viewport"),c.querySelector(".xterm-scrollable-element")].filter(p=>p instanceof HTMLElement),ce=S=>{if(v===null)return null;for(let p=0;p<S.length;p+=1){const k=S.item(p);if(k&&k.identifier===v)return k}return null},ne=S=>{if(y(),S.touches.length!==1)return;const p=S.touches.item(0);p&&(v=p.identifier,m=p.clientY,C=0,b=U(p.clientX,p.clientY,S.target),F=p.clientX,z=p.clientY,i=!1,b||(j=setTimeout(()=>{var R;j=null;const k=(t==null?void 0:t())??null;(R=k==null?void 0:k.startTouchSelection)!=null&&R.call(k,F,z,"word")&&(i=!0)},Dn)))},me=S=>{var A,Y,H,D,V,de,re,we,J;const p=ce(S.touches)??S.touches.item(0);if(!p)return;if(i){const Q=(t==null?void 0:t())??null;(A=Q==null?void 0:Q.updateTouchSelection)==null||A.call(Q,p.clientX,p.clientY),S.cancelable&&S.preventDefault();return}if(j!==null&&Math.hypot(p.clientX-F,p.clientY-z)>_n&&y(),b||(b=U(p.clientX,p.clientY,S.target),b&&(C=0)),b)return;const k=p.clientY,R=m-k;if(m=k,R===0)return;let _=!1,G=!1;const u=(t==null?void 0:t())??null;if(u){const Q=u==null?void 0:u._core,ee=((V=(D=(H=(Y=Q==null?void 0:Q._renderService)==null?void 0:Y.dimensions)==null?void 0:H.css)==null?void 0:D.cell)==null?void 0:V.height)??18;C+=R*Ln;const E=C>0?Math.floor(C/ee):Math.ceil(C/ee);if(typeof u.handleViewportGesture=="function")E!==0&&(_=u.handleViewportGesture({source:"touch",deltaY:E*ee,clientX:p.clientX,clientY:p.clientY}),C-=E*ee);else if(E!==0){const a=((re=(de=u.buffer)==null?void 0:de.active)==null?void 0:re.viewportY)??0;u.scrollLines(E);const h=((J=(we=u.buffer)==null?void 0:we.active)==null?void 0:J.viewportY)??0;_=a!==h,G=E<0&&a<=0&&h<=0,C-=E*ee}}else{const Q=M();if(Q.length===0)return;for(const ee of Q){const E=ee.scrollTop;ee.scrollTop+=R;const a=ee.scrollTop;Math.abs(a-E)>0&&(_=!0),R<0&&a<=0&&(G=!0)}if(!_){const ee=c.querySelector(".xterm");if(ee instanceof HTMLElement){const E=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:R}),a=ee.dispatchEvent(E);_=E.defaultPrevented||!a}}}S.cancelable&&(_||G)&&S.preventDefault()},Z=S=>{var k;if(y(),!(v===null||!ce(S.changedTouches))&&(v=null,C=0,b=!1,i)){i=!1;const R=(t==null?void 0:t())??null;(k=R==null?void 0:R.endTouchSelection)==null||k.call(R)}},d=S=>{i&&S.preventDefault()};return c.addEventListener("touchstart",ne,{passive:!0}),c.addEventListener("touchmove",me,{passive:!1}),c.addEventListener("touchend",Z,{passive:!0}),c.addEventListener("touchcancel",Z,{passive:!0}),c.addEventListener("contextmenu",d),()=>{r.current=!1,y(),c.removeEventListener("touchstart",ne),c.removeEventListener("touchmove",me),c.removeEventListener("touchend",Z),c.removeEventListener("touchcancel",Z),c.removeEventListener("contextmenu",d)}},[e,t]),r}function $n({now:e,remoteSize:t,pendingLocalSize:r,ttlMs:c=2e3}){return!r||e-r.at>c?!0:r.cols===t.cols&&r.rows===t.rows}function Bn({currentSize:e,containerSize:t,force:r=!1}){return r?!0:e.cols!==t.cols||e.rows!==t.rows}function Fn({deviceId:e,paneId:t,deviceConnected:r,isSelectionInvalid:c,sizingMode:l="report",onResize:m,onSync:v,getContainerRect:b}){const C=n.useRef(null),F=n.useRef(null),z=n.useRef(null),j=n.useRef(null),i=n.useRef(0),y=n.useRef([]),ue=n.useRef(null),U=n.useRef(null),M=n.useRef(b),ce=n.useRef(!1),ne=n.useRef(m),me=n.useRef(v);n.useEffect(()=>{ne.current=m},[m]),n.useEffect(()=>{me.current=v},[v]),n.useEffect(()=>{M.current=b},[b]);const Z=n.useCallback(()=>{var re,we,J,Q,ee,E,a,h,N,T;const u=U.current,A=ue.current;if(!u||!A||!u.element)return null;let Y;try{const W=A.proposeDimensions();if(!W)throw new Error("fitAddon.proposeDimensions() returned null");Y=Math.max(2,W.cols)}catch{const W=u._core,se=((Q=(J=(we=(re=W==null?void 0:W._renderService)==null?void 0:re.dimensions)==null?void 0:we.css)==null?void 0:J.cell)==null?void 0:Q.width)??9,K=(ee=M.current)==null?void 0:ee.call(M);if(!K||K.width===0)return null;Y=Math.max(2,Math.floor(K.width/se))}const H=(E=M.current)==null?void 0:E.call(M);if(!H||H.height===0)return null;const D=u._core,V=((T=(N=(h=(a=D==null?void 0:D._renderService)==null?void 0:a.dimensions)==null?void 0:h.css)==null?void 0:N.cell)==null?void 0:T.height)??17,de=Math.max(2,Math.floor(H.height/V));return{cols:Y,rows:de}},[]),d=n.useCallback((u,A)=>{const Y=U.current;Y&&(Y.cols===u&&Y.rows===A||Y.resize(u,A))},[]),S=n.useCallback((u,A=!1)=>{if(l==="follow"||!e||!t||!r||c&&u!=="sync"||!A&&Date.now()<i.current||!U.current)return!1;const H=Z();if(!H)return!1;const{cols:D,rows:V}=H,de=z.current;return!A&&de&&de.cols===D&&de.rows===V?(d(D,V),!0):(d(D,V),u==="sync"?me.current(D,V):ne.current(D,V),z.current={cols:D,rows:V},j.current={cols:D,rows:V,at:Date.now()},!0)},[d,r,e,c,Z,t,l]),p=n.useCallback((u="resize",A={})=>{const{immediate:Y=!1,force:H=!1}=A;F.current!==null&&(window.clearTimeout(F.current),F.current=null),C.current!==null&&(cancelAnimationFrame(C.current),C.current=null);const D=()=>{C.current=requestAnimationFrame(()=>{C.current=null,S(u,H)})};if(Y){D();return}F.current=window.setTimeout(()=>{F.current=null,D()},150)},[S]),k=n.useCallback(()=>{for(const u of y.current)window.clearTimeout(u);y.current=[]},[]),R=n.useCallback(()=>{var A;k(),p("sync",{immediate:!0,force:!0});const u=window.setTimeout(()=>{p("sync",{immediate:!0,force:!0})},60);y.current.push(u),typeof document<"u"&&"fonts"in document&&((A=document.fonts)!=null&&A.ready)&&document.fonts.ready.then(()=>{p("sync",{immediate:!0,force:!0})}).catch(()=>{})},[k,p]);n.useEffect(()=>{let u=null;const A=()=>{u!==null&&cancelAnimationFrame(u),u=requestAnimationFrame(()=>{u=null,p("resize")})};return window.addEventListener("resize",A),()=>{window.removeEventListener("resize",A),u!==null&&cancelAnimationFrame(u)}},[p]),n.useEffect(()=>{const u=()=>{var re;const D=U.current,V=Z();if(!D||!V)return;if(!Bn({currentSize:{cols:Math.max(2,D.cols),rows:Math.max(2,D.rows)},containerSize:V})){(re=D.refresh)==null||re.call(D);return}p("sync",{force:!0})},A=()=>{if(document.visibilityState!=="visible"){ce.current=!0;return}ce.current&&(ce.current=!1,u())},Y=()=>{ce.current=!0},H=()=>{ce.current&&(ce.current=!1,u())};return document.addEventListener("visibilitychange",A),window.addEventListener("blur",Y),window.addEventListener("focus",H),()=>{document.removeEventListener("visibilitychange",A),window.removeEventListener("blur",Y),window.removeEventListener("focus",H)}},[Z,p]),n.useEffect(()=>()=>{k(),F.current!==null&&window.clearTimeout(F.current),C.current!==null&&cancelAnimationFrame(C.current)},[k]);const _=n.useCallback(u=>{ue.current=u},[]),G=n.useCallback(u=>{U.current=u},[]);return{scheduleResize:p,runPostSelectResize:R,clearPostSelectResizeTimers:k,setFitAddon:_,setTerminal:G,lastReportedSize:z,pendingLocalSize:j,suppressLocalResizeUntil:i}}const Hn=1e4,Ve="tmex:terminal-mode-cache";function Wn(e,t){try{const r=sessionStorage.getItem(Ve);return r?JSON.parse(r)[`${e}:${t}`]??null:null}catch{return null}}function On(e,t,r){try{const c=sessionStorage.getItem(Ve),l=c?JSON.parse(c):{},m=`${e}:${t}`;r?l[m]=r:delete l[m],sessionStorage.setItem(Ve,JSON.stringify(l))}catch{}}function Xn(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1}}function qn(e,t){if(!t)return e?{...e,mouseX10:!1,mouseNormal:!1,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgrPixels:!1,mouseUrxvt:!1,altScreen1047:!1,altScreen1049:!1}:null;const r=Xn();if(!e)return r;const c=e.mouseNormal||e.mouseButton||e.mouseAny;return{...e,mouseX10:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1,mouseNormal:c?e.mouseNormal:r.mouseNormal}}function Yn(e){var r;const t=globalThis;t.__tmexE2eXterm=e,t.__tmexE2eTerminal=e,t.__tmexE2eTerminalEngine=ht,t.__tmexE2eTerminalRenderer=((r=e.getRendererKind)==null?void 0:r.call(e))??null}function Un(e){if(!e)return;const t=globalThis;t.__tmexE2eTerminal!==e&&t.__tmexE2eXterm!==e||(t.__tmexE2eXterm=null,t.__tmexE2eTerminal=null,t.__tmexE2eTerminalEngine=null,t.__tmexE2eTerminalRenderer=null,t.__tmexE2eTerminalSelectionText=null)}const nt=n.forwardRef(({deviceId:e,paneId:t,theme:r,inputMode:c,deviceConnected:l,isSelectionInvalid:m,sizingMode:v="report",autoFocus:b=!0,onResize:C,onSync:F,children:z},j)=>{const[i,y]=n.useState(null),[ue,U]=n.useState(!1),M=O(f=>f.sendInput),ce=ge(f=>f.terminalFontId),ne=ge(f=>f.terminalFontSize),me=ge(f=>f.terminalLineHeight),{t:Z}=Pe(),d=n.useMemo(()=>{switch(r){case"light":return lt;default:return at}},[r]),S=n.useRef(null),p=n.useRef(null),k=n.useRef(null),R=n.useRef(e),_=n.useRef(t),G=n.useRef(e),u=n.useRef(t),A=n.useRef(l&&!m),Y=n.useRef(c),H=n.useRef(d),D=n.useRef(!1),V=n.useRef(!1),de=n.useRef(null),re=n.useRef(!1),we=n.useCallback((f,x,L)=>{!(f!=null&&f.exportModeSnapshot)||!x||!L||On(x,L,f.exportModeSnapshot())},[]),J=n.useCallback(()=>i,[i]);zn(S,J),n.useEffect(()=>{R.current=e,_.current=t,V.current=!1},[e,t]),n.useEffect(()=>{A.current=l&&!m},[l,m]),n.useEffect(()=>{Y.current=c},[c]),n.useEffect(()=>{H.current=d},[d]);const Q=n.useCallback(f=>{if(!f||c!=="direct"||!A.current)return;const x=R.current,L=_.current;!x||!L||M(x,L,f,!1)},[c,M]),{pendingLocalSize:ee,scheduleResize:E,runPostSelectResize:a,setFitAddon:h,setTerminal:N}=Fn({deviceId:e,paneId:t,deviceConnected:l,isSelectionInvalid:m,sizingMode:v,onResize:C,onSync:F,getContainerRect:()=>{const f=S.current;if(!f)return null;const x=f.getBoundingClientRect();return{width:x.width,height:x.height}}});n.useEffect(()=>{let f=!1,x=null;return(async()=>{if(await Mt(ce,ne),f)return;const L=await an({fontFamily:Pt(ce),fontSize:ne,lineHeight:me,scrollback:Hn,theme:H.current,disableStdin:Y.current==="editor"});if(f){L.dispose();return}x=L,p.current&&L.open(p.current),y(L)})(),()=>{f=!0,y(null),Un(x),x==null||x.dispose()}},[ce,ne,me]),n.useEffect(()=>{!i||!b||Yn(i)},[i,b]),n.useEffect(()=>{!i||!("setTheme"in i)||i.setTheme(d)},[i,d]),n.useEffect(()=>{!i||!("setDisableStdin"in i)||i.setDisableStdin(c==="editor")},[i,c]),n.useEffect(()=>{if(!(i!=null&&i.getCursorViewportRect))return;const f=()=>{var x;return((x=i.getCursorViewportRect)==null?void 0:x.call(i))??null};return Lt(f),()=>kt(f)},[i]),n.useEffect(()=>{!i||c!=="direct"||!b||window.innerWidth<768||"ontouchstart"in window||i.focus()},[i,c,b]);const T=n.useMemo(()=>i?{onReset:()=>{we(i,G.current,u.current),re.current=!0,i.reset(),D.current=!1,a()},onApplyHistory:(f,x)=>{var P;const L=qn(Wn(R.current,_.current),x);L&&((P=i.restoreModeSnapshot)==null||P.call(i,L));const $=x?kn(f):wt(f);V.current=!0,i.write($),re.current=!1,G.current=R.current,u.current=_.current,we(i,R.current,_.current)},onOutput:f=>{const x=In(f,D.current);D.current=x.endedWithCR,i.write(x.normalized),V.current&&(i.buffer.active.baseY<=1&&i.scrollToTop(),V.current=!1),G.current=R.current,u.current=_.current,we(i,R.current,_.current)}}:null,[i,we,a]);n.useEffect(()=>{i?de.current!==i&&(D.current=!1,G.current=R.current,u.current=_.current,de.current=i):de.current=null},[i]),n.useEffect(()=>{if(!(!i||!e||!t))return()=>{if(re.current){re.current=!1;return}we(i,G.current,u.current)}},[e,i,t,we]),n.useEffect(()=>{if(!(!T||!e||!t))return It(e,t,T)},[T,e,t]),n.useEffect(()=>{if(!i){k.current=null,h(null),N(null);return}const f=new ln;return i.loadAddon(f),k.current=f,h(f),N(i),a(),()=>{try{f.dispose()}finally{k.current=null,h(null),N(null)}}},[i,a,h,N]),n.useEffect(()=>{const f=S.current;if(!f)return;let x=null;const L=new ResizeObserver(()=>{x!==null&&cancelAnimationFrame(x),x=requestAnimationFrame(()=>{x=null,E("resize")})});return L.observe(f),()=>{L.disconnect(),x!==null&&cancelAnimationFrame(x)}},[E]),n.useEffect(()=>{if(!i||!e||!t)return;const f=i.onData(x=>{!l||m||Q(x)});return i.attachCustomKeyEventHandler(x=>!l||m||x.type!=="keydown"||c!=="direct"?!0:x.shiftKey&&x.key==="Enter"?(x.preventDefault(),Q("\x1B[13;2u"),!1):!0),()=>{f.dispose(),i.attachCustomKeyEventHandler(()=>!0)}},[i,l,m,c,Q,e,t]),n.useEffect(()=>{if(!(i!=null&&i.onLinkActivated))return;const f=i.onLinkActivated(x=>{window.open(x,"_blank","noopener,noreferrer")});return()=>f.dispose()},[i]),n.useEffect(()=>{if(!(i!=null&&i.onSelectionChange)){U(!1);return}const f=i.onSelectionChange(x=>{U(!!x)});return()=>{f.dispose(),U(!1)}},[i]);const W=n.useCallback(()=>{var x;if(!i)return;const f=((x=i.getSelection)==null?void 0:x.call(i))??"";f&&wn(f).then(()=>{Me.success(Z("terminal.copied"))}).catch(()=>{Me.error(Z("terminal.copyFailed"))}).finally(()=>{var L;(L=i.clearSelection)==null||L.call(i),i.focus()})},[i,Z]),se=n.useCallback(()=>{var x;if(!i)return;((x=navigator.clipboard)!=null&&x.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(L=>{var $;L&&i.paste(L),($=i.clearSelection)==null||$.call(i),i.focus()}).catch(()=>{Me.error(Z("terminal.pasteFailed"))})},[i,Z]),K=n.useCallback(()=>{var f;(f=i==null?void 0:i.clearSelection)==null||f.call(i),i==null||i.focus()},[i]);return n.useImperativeHandle(j,()=>({write:f=>i==null?void 0:i.write(f),reset:()=>{i==null||i.reset(),D.current=!1},scrollToBottom:()=>i==null?void 0:i.scrollToBottom(),resize:(f,x)=>i==null?void 0:i.resize(f,x),getTerminal:()=>i??null,getSize:()=>i?{cols:Math.max(2,i.cols),rows:Math.max(2,i.rows)}:null,runPostSelectResize:()=>a(),scheduleResize:(f,x)=>E(f,x),calculateSizeFromContainer:()=>{var Se,B,oe,X,q,xe,ie,he,pe,ye,ke,Ae,ae,Ie,je,Le;const f=S.current,x=i,L=k.current;if(!f||!x)return null;const $=f.getBoundingClientRect();if($.width===0||$.height===0)return null;const P=x._core;let fe;if(L)try{const Te=L.proposeDimensions();if(Te)fe=Math.max(2,Te.cols);else{const De=((X=(oe=(B=(Se=P==null?void 0:P._renderService)==null?void 0:Se.dimensions)==null?void 0:B.css)==null?void 0:oe.cell)==null?void 0:X.width)??9;fe=Math.max(2,Math.floor($.width/De))}}catch{const Te=((he=(ie=(xe=(q=P==null?void 0:P._renderService)==null?void 0:q.dimensions)==null?void 0:xe.css)==null?void 0:ie.cell)==null?void 0:he.width)??9;fe=Math.max(2,Math.floor($.width/Te))}else{const Te=((Ae=(ke=(ye=(pe=P==null?void 0:P._renderService)==null?void 0:pe.dimensions)==null?void 0:ye.css)==null?void 0:ke.cell)==null?void 0:Ae.width)??9;fe=Math.max(2,Math.floor($.width/Te))}const Ee=((Le=(je=(Ie=(ae=P==null?void 0:P._renderService)==null?void 0:ae.dimensions)==null?void 0:Ie.css)==null?void 0:je.cell)==null?void 0:Le.height)??17,be=Math.max(2,Math.floor($.height/Ee));return{cols:fe,rows:be}},getPendingLocalSize:()=>ee.current,getCellSize:()=>{var L,$,P;const f=i==null?void 0:i._core,x=(P=($=(L=f==null?void 0:f._renderService)==null?void 0:L.dimensions)==null?void 0:$.css)==null?void 0:P.cell;return!(x!=null&&x.width)||!(x!=null&&x.height)?null:{width:x.width,height:x.height}}}),[i,ee,a,E]),o.jsxs("div",{className:"flex h-full w-full flex-col",style:{backgroundColor:d.background},"data-terminal-engine":ht,children:[o.jsxs("div",{ref:S,className:"relative min-h-0 w-full flex-1",children:[o.jsx("div",{ref:p,className:"absolute inset-0"}),o.jsx(Mn,{visible:ue,canPaste:c==="direct"&&l&&!m,onCopy:W,onPaste:se,onDismiss:K})]}),z]})});nt.displayName="Terminal";function Vn({window:e,currentPaneId:t,onSelectPane:r}){const{t:c}=Pe();return o.jsxs(At,{children:[o.jsxs(Dt,{"data-testid":"pane-switcher-button","aria-label":c("window.switchPane"),title:c("window.switchPane"),className:"relative inline-flex size-7 items-center justify-center rounded-[min(var(--radius-md),12px)] text-sm hover:bg-muted hover:text-foreground data-popup-open:bg-muted",children:[o.jsx(Sn,{className:"h-4 w-4"}),o.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:e.panes.length})]}),o.jsx(_t,{align:"end",backdrop:!0,className:"min-w-56 max-w-[80vw]","data-testid":"pane-switcher-menu",children:e.panes.map(l=>{const m=l.id===t;return o.jsxs(zt,{"data-testid":"pane-switcher-item","data-pane-id":l.id,className:`py-2 [@media(any-pointer:coarse)]:py-2.5 ${m?"bg-primary/10 text-primary":l.active?"bg-accent text-accent-foreground":""}`,onClick:()=>{m||r(l.id)},children:[o.jsxs("span",{className:"min-w-0 flex-1",children:[o.jsx("span",{className:"font-mono text-[11px] leading-tight font-medium line-clamp-2 [overflow-wrap:break-word]",children:l.customName||l.title||c("window.pane")}),l.currentCommand&&o.jsx("span",{className:"font-mono text-[10.5px] leading-tight text-muted-foreground line-clamp-1 break-all",children:l.currentPath?`${l.currentCommand}@${l.currentPath}`:l.currentCommand})]}),m&&o.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-primary"})]},l.id)})})]})}const He=2;function We(e){if(e.type==="leaf")return He;if(e.type==="row"){let r=e.children.length-1;for(const c of e.children)r+=We(c);return r}let t=He;for(const r of e.children)t=Math.max(t,We(r));return t}function Oe(e){if(e.type==="leaf")return He;if(e.type==="column"){let r=e.children.length-1;for(const c of e.children)r+=Oe(c);return r}let t=He;for(const r of e.children)t=Math.max(t,Oe(r));return t}function Ke(e){return e.type==="leaf"?e:e.type==="row"?Ke(e.children[e.children.length-1]):Ke(e.children[0])}function Ge(e){return e.type==="leaf"?e:e.type==="column"?Ge(e.children[e.children.length-1]):Ge(e.children[0])}function Kn(e,t){const r=[],c=[],l=m=>{if(m.type==="leaf"){r.push({paneId:Ye(m),cols:m.width,rows:m.height,rect:{left:m.x*t.width,top:m.y*t.height,width:m.width*t.width,height:m.height*t.height}});return}for(let v=0;v<m.children.length;v+=1){const b=m.children[v];if(l(b),v===m.children.length-1)continue;const C=m.children[v+1];if(m.type==="row"){const F=Ke(b);c.push({axis:"x",rect:{left:(b.x+b.width)*t.width,top:m.y*t.height,width:t.width,height:m.height*t.height},edgeLeafPaneId:Ye(F),edgeLeafSizeCells:F.width,minDeltaCells:-(b.width-We(b)),maxDeltaCells:C.width-We(C)})}else{const F=Ge(b);c.push({axis:"y",rect:{left:m.x*t.width,top:(b.y+b.height)*t.height,width:m.width*t.width,height:t.height},edgeLeafPaneId:Ye(F),edgeLeafSizeCells:F.height,minDeltaCells:-(b.height-Oe(b)),maxDeltaCells:C.height-Oe(C)})}}};return l(e),{panes:r,gutters:c}}function Qe(e){if(e.type==="leaf")return 1;if(e.type==="column"){let r=0;for(const c of e.children)r+=Qe(c);return r}let t=1;for(const r of e.children)t=Math.max(t,Qe(r));return t}function Je(e){if(e.type==="leaf")return 1;if(e.type==="row"){let r=0;for(const c of e.children)r+=Je(c);return r}let t=1;for(const r of e.children)t=Math.max(t,Je(r));return t}function Gn(e,t){const r=Math.min(1,Math.max(0,e)),c=Math.min(1,Math.max(0,t)),l=[["left",r],["right",1-r],["top",c],["bottom",1-c]];return l.sort((m,v)=>m[1]-v[1]),l[0][0]}function Qn(e,t,r){const c=e.axis==="x"?r.width:r.height;if(c<=0)return null;const l=Math.round(t/c),m=Math.min(e.maxDeltaCells,Math.max(e.minDeltaCells,l));return m===0?null:{deltaCells:m,targetSizeCells:e.edgeLeafSizeCells+m}}const it=150,Jn=200,Zn=15,er=46,tr=38,nr=12,rr=6;function ct(e){var t,r;return((t=e==null?void 0:e.customName)==null?void 0:t.trim())||((r=e==null?void 0:e.title)==null?void 0:r.trim())||"Pane"}function sr(e){var c,l;const t=(c=e==null?void 0:e.currentCommand)==null?void 0:c.trim();if(!t)return null;const r=(l=e==null?void 0:e.currentPath)==null?void 0:l.trim();return r?`${t}@${r}`:t}const or={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 ir({deviceId:e,window:t,focusedPaneId:r,theme:c,inputMode:l,deviceConnected:m,focusedTerminalRef:v,onUserSelectPane:b,onWindowResize:C}){var Q,ee,E;const F=n.useRef(null),z=n.useRef(new Map),[j,i]=n.useState(null),[y,ue]=n.useState(null),{t:U}=Pe(),M=O(a=>a.subscribePanes),ce=O(a=>a.fetchPaneHistory),ne=O(a=>a.resizePaneInWindow),me=O(a=>a.movePane),Z=O(a=>a.breakPane),d=O(a=>a.closePane),S=n.useMemo(()=>{const a=new Map;for(const h of t.panes)a.set(h.id,h);return a},[t.panes]),p=n.useMemo(()=>t.layout?vn(t.layout):null,[t.layout]),k=n.useMemo(()=>p?Kn(p.root,{width:1,height:1}):null,[p]),R=(p==null?void 0:p.root.width)??1,_=(p==null?void 0:p.root.height)??1,G=t.panes.map(a=>a.id).join(",");n.useEffect(()=>(M(e,G?G.split(","):[]),()=>{M(e,[])}),[e,G,M]);const u=n.useRef({key:"",fetched:new Set});n.useEffect(()=>{const a=`${e}:${t.id}`;u.current.key!==a&&(u.current={key:a,fetched:new Set});for(const h of G?G.split(","):[])u.current.fetched.has(h)||(u.current.fetched.add(h),h!==r&&ce(e,h))},[e,t.id,G,r,ce]),n.useEffect(()=>{var a;if(k)for(const h of k.panes)(a=z.current.get(h.paneId))==null||a.resize(h.cols,h.rows)},[k]),n.useEffect(()=>{var h,N;l!=="direct"||window.innerWidth<768||"ontouchstart"in window||(N=(h=z.current.get(r))==null?void 0:h.getTerminal())==null||N.focus()},[r,l]);const A=n.useCallback(()=>{var a;for(const h of[r,...z.current.keys()]){const N=(a=z.current.get(h))==null?void 0:a.getCellSize();if(N)return N}return null},[r]),Y=n.useMemo(()=>p?Qe(p.root):1,[p]),H=n.useMemo(()=>p?Je(p.root):1,[p]),D=n.useCallback(()=>{const a=F.current;if(!a)return!1;const h=a.getBoundingClientRect();if(h.width<1||h.height<1)return!1;const N=A();if(!N)return!1;const T=Math.max(0,h.height-Y*er),W=Math.max(0,h.width-H*nr),se=Math.max(2,Math.floor(W/N.width)),K=Math.max(2,Math.floor(T/N.height));return C(se,K),!0},[A,C,Y,H]),V=n.useRef(D);n.useEffect(()=>{V.current=D},[D]),n.useEffect(()=>{const a=F.current;if(!a)return;let h=null,N=null,T=0;const W=()=>{if(V.current()){T=0;return}T<Zn&&(T+=1,N=setTimeout(W,Jn))},se=new ResizeObserver(()=>{h&&clearTimeout(h),h=setTimeout(W,it)});return se.observe(a),()=>{se.disconnect(),h&&clearTimeout(h),N&&clearTimeout(N)}},[]),n.useEffect(()=>{const a=setTimeout(()=>{V.current()},it);return()=>clearTimeout(a)},[Y,H]);const de=n.useCallback((a,h,N)=>{N.preventDefault();const T=F.current;if(!T)return;const W=N.clientX,se=N.clientY,K=N.currentTarget;K.setPointerCapture(N.pointerId),i({gutterIndex:a,deltaPx:0});const f=P=>{const fe=h.axis==="x"?P.clientX-W:P.clientY-se;i({gutterIndex:a,deltaPx:fe})},x=(P,fe)=>{if(K.removeEventListener("pointermove",f),K.removeEventListener("pointerup",L),K.removeEventListener("pointercancel",$),i(null),!fe)return;const Ee=T.getBoundingClientRect(),be=h.axis==="x"?Ee.width/Math.max(1,R):Ee.height/Math.max(1,_),Se=h.axis==="x"?P.clientX-W:P.clientY-se,B=Qn(h,Se,{width:h.axis==="x"?be:1,height:h.axis==="y"?be:1});B&&ne(e,h.edgeLeafPaneId,h.axis==="x"?{cols:B.targetSizeCells}:{rows:B.targetSizeCells})},L=P=>x(P,!0),$=P=>x(P,!1);K.addEventListener("pointermove",f),K.addEventListener("pointerup",L),K.addEventListener("pointercancel",$)},[e,ne,R,_]),re=n.useCallback((a,h)=>{const N=F.current,T=k;if(!N||!T)return;h.preventDefault();const W=h.clientX,se=h.clientY,K=h.currentTarget;K.setPointerCapture(h.pointerId);let f=!1;const x=(B,oe)=>{const X=N.getBoundingClientRect();if(X.width<1||X.height<1)return null;const q=(B-X.left)/X.width*Math.max(1,R),xe=(oe-X.top)/X.height*Math.max(1,_);for(const ie of T.panes)if(q>=ie.rect.left&&q<=ie.rect.left+ie.rect.width&&xe>=ie.rect.top&&xe<=ie.rect.top+ie.rect.height){const he=(q-ie.rect.left)/Math.max(1e-6,ie.rect.width),pe=(xe-ie.rect.top)/Math.max(1e-6,ie.rect.height);return{paneId:ie.paneId,position:Gn(he,pe)}}return null},L=(B,oe,X)=>B>=X.left&&B<=X.right&&oe>=X.top&&oe<=X.bottom,$=(B,oe)=>{for(const X of Array.from(document.querySelectorAll('[data-testid^="window-item-"]'))){const q=X.getBoundingClientRect();if(q.width<1||!L(B,oe,q))continue;const xe=(X.getAttribute("data-testid")??"").replace("window-item-","");return!xe||xe===t.id?null:{type:"window",windowId:xe,rect:{left:q.left,top:q.top,width:q.width,height:q.height}}}for(const X of Array.from(document.querySelectorAll('[data-slot="sidebar"]'))){const q=X.getBoundingClientRect();if(!(q.width<1||!L(B,oe,q)))return{type:"break",rect:{left:q.left,top:q.top,width:q.width,height:q.height}}}return null},P=(B,oe)=>{const X=x(B,oe);return X?X.paneId===a?null:{type:"pane",...X}:$(B,oe)},fe=B=>{const oe=Math.hypot(B.clientX-W,B.clientY-se);!f&&oe<rr||(f=!0,ue({srcPaneId:a,active:!0,pointerX:B.clientX,pointerY:B.clientY,target:P(B.clientX,B.clientY)}))},Ee=(B,oe)=>{var q,xe;if(K.removeEventListener("pointermove",fe),K.removeEventListener("pointerup",be),K.removeEventListener("pointercancel",Se),ue(null),!oe||!f)return;const X=P(B.clientX,B.clientY);if(X){if(X.type==="pane"){me(e,a,X.paneId,X.position);return}if(X.type==="window"){const ie=(xe=(q=O.getState().snapshots[e])==null?void 0:q.session)==null?void 0:xe.windows,he=ie==null?void 0:ie.find(ye=>ye.id===X.windowId),pe=(he==null?void 0:he.panes.find(ye=>ye.active))??(he==null?void 0:he.panes[0]);pe&&me(e,a,pe.id,"right");return}Z(e,a)}},be=B=>Ee(B,!0),Se=B=>Ee(B,!1);K.addEventListener("pointermove",fe),K.addEventListener("pointerup",be),K.addEventListener("pointercancel",Se)},[e,k,me,Z,R,_,t.id]),we=n.useCallback(a=>h=>{h?z.current.set(a,h):z.current.delete(a),a===r&&v(h)},[r,v]);if(n.useEffect(()=>{v(z.current.get(r)??null)},[r,v]),!k)return null;const J=(a,h)=>`${a/Math.max(1,h)*100}%`;return o.jsxs("div",{ref:F,className:"relative h-full w-full min-h-0 min-w-0","data-testid":"split-terminal-area",children:[k.panes.map(a=>{var K;const h=a.paneId===r,N=S.get(a.paneId),T=sr(N),W=(y==null?void 0:y.active)&&y.srcPaneId===a.paneId,se=y!=null&&y.active&&((K=y.target)==null?void 0:K.type)==="pane"&&y.target.paneId===a.paneId?y.target.position:null;return o.jsxs("div",{className:`absolute flex flex-col ${W?"opacity-60":""}`,"data-testid":"split-pane","data-pane-id":a.paneId,"data-focused":h||void 0,style:{left:J(a.rect.left,R),top:J(a.rect.top,_),width:J(a.rect.width,R),height:J(a.rect.height,_)},onPointerDownCapture:()=>{h||b(t.id,a.paneId)},children:[o.jsx("div",{className:"shrink-0 px-1.5 pt-1.5 pb-2",style:{height:tr},children:o.jsxs("div",{"data-testid":"split-pane-titlebar","data-active":h||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 ${h?"bg-foreground/10":"bg-foreground/[0.04]"}`,onPointerDown:f=>re(a.paneId,f),children:[o.jsx("span",{className:`shrink-0 truncate font-mono text-[10.5px] leading-none ${h?"text-foreground/90":"text-foreground/50"}`,children:ct(N)}),T&&o.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-[10px] leading-none ${h?"text-muted-foreground":"text-muted-foreground/60"}`,children:T}),o.jsx("button",{type:"button","data-testid":`split-pane-close-${a.paneId}`,"aria-label":U("window.closePane"),title:U("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:f=>f.stopPropagation(),onClick:f=>{f.stopPropagation(),d(e,a.paneId)},children:o.jsx("span",{className:"text-xs leading-none",children:"×"})})]})}),o.jsx("div",{className:"relative min-h-0 flex-1 px-1.5 pb-2",children:o.jsx(nt,{ref:we(a.paneId),deviceId:e,paneId:a.paneId,theme:c,inputMode:l,deviceConnected:m,isSelectionInvalid:!1,sizingMode:"follow",autoFocus:h,onResize:()=>{},onSync:()=>{}},`${e}:${a.paneId}`)}),se&&o.jsx("div",{"data-testid":"split-pane-drop-preview","data-position":se,className:`pointer-events-none absolute z-30 rounded-sm bg-primary/20 ring-1 ring-inset ring-primary/60 ${or[se]}`})]},a.paneId)}),(j!==null||(y==null?void 0:y.active))&&o.jsx("div",{"data-testid":"split-drag-shield",className:`absolute inset-0 z-30 ${j!==null?((Q=k.gutters[j.gutterIndex])==null?void 0:Q.axis)==="x"?"cursor-col-resize":"cursor-row-resize":"cursor-grabbing"}`}),(y==null?void 0:y.active)&&y.target&&y.target.type!=="pane"&&o.jsx("div",{"data-testid":"split-pane-sidebar-drop","data-drop-type":y.target.type,className:"pointer-events-none fixed z-40 rounded-lg bg-primary/15 ring-1 ring-inset ring-primary/50",style:{left:y.target.rect.left,top:y.target.rect.top,width:y.target.rect.width,height:y.target.rect.height}}),(y==null?void 0:y.active)&&o.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:y.pointerX+12,top:y.pointerY+12},children:[o.jsx("div",{children:ct(S.get(y.srcPaneId))}),((ee=y.target)==null?void 0:ee.type)==="window"&&o.jsx("div",{className:"text-[9.5px] text-muted-foreground",children:U("window.moveToWindow")}),((E=y.target)==null?void 0:E.type)==="break"&&o.jsx("div",{className:"text-[9.5px] text-muted-foreground",children:U("window.breakToWindow")})]}),k.gutters.map((a,h)=>{const N=a.axis==="x",T=(j==null?void 0:j.gutterIndex)===h;return o.jsxs("div",{className:"absolute z-20",style:{left:J(a.rect.left,R),top:J(a.rect.top,_),width:J(N?1:a.rect.width,R),height:J(N?a.rect.height:1,_)},children:[o.jsx("div",{"data-testid":"split-gutter","data-axis":a.axis,className:`absolute touch-none select-none ${N?"-inset-x-1 inset-y-0 cursor-col-resize":"inset-x-0 -inset-y-1 cursor-row-resize"}`,onPointerDown:W=>de(h,a,W),children:o.jsx("div",{className:`absolute bg-foreground/[0.08] transition-colors hover:bg-primary/50 ${N?"inset-y-0 left-1/2 w-px -translate-x-1/2":"inset-x-0 top-1/2 h-px -translate-y-1/2"} ${T?"bg-primary":""}`})}),T&&j&&o.jsx("div",{className:"pointer-events-none absolute bg-primary/70",style:N?{top:0,bottom:0,width:2,left:`calc(50% + ${j.deltaPx}px)`}:{left:0,right:0,height:2,top:`calc(50% + ${j.deltaPx}px)`}})]},`${t.layout??""}:${h}`)})]})}const cr=1200,ar=2e3;function Ne(e,t){return!e||!t?!1:e.windowId===t.windowId&&e.paneId===t.paneId}function pt(e,t){const r=e.filter(c=>t-c.at<cr);return r.length===0?null:r.reduce((c,l)=>l.at>c.at?l:c)}function Fe(e,t=Date.now()){return!e||t-e.at>ar?null:e}function lr(e){const t=e.now??Date.now(),r=pt(e.recentSelectRequests,t),c=m=>!!(m&&m.paneId===e.activePaneFromEvent.paneId&&m.windowId!==e.activePaneFromEvent.windowId);if(r&&!Ne(r,e.activePaneFromEvent)&&!c(r)||Ne(e.currentRoute,e.activePaneFromEvent)||Ne(e.lastHandledActive,e.activePaneFromEvent))return!0;const l=Fe(e.pendingUserSelection,t);return!!(l&&!Ne(l,e.activePaneFromEvent)&&!c(l))}function ur(e){const t=e.now??Date.now(),r=pt(e.recentSelectRequests,t),c=Fe(e.pendingUserSelection,t);return!!(c&&!Ne(c,e.snapshotActive)||r&&!Ne(r,e.snapshotActive))}function dr(e){const t=e.now??Date.now(),r=Fe(e.pendingUserSelection,t);return!(r&&Ne(r,e.routeTarget)||e.snapshotActive&&Ne(e.snapshotActive,e.routeTarget))}const Ue=n.memo(function({onActivate:t,disabled:r}){const{data:c}=tt({queryKey:hn,queryFn:fn,staleTime:6e4}),l=(c==null?void 0:c.items)??[];return l.length===0?null:o.jsx("div",{className:"terminal-shortcuts-strip","data-testid":"terminal-shortcuts-strip",children:o.jsx(mn,{items:l,useIcons:(c==null?void 0:c.useIcons)??!1,onActivate:t,disabled:r,preventFocusSteal:!0,rowTestId:"terminal-shortcuts-row",idPrefix:"terminal-shortcut"})})});function gr(){var st;const{t:e}=Pe(),{deviceId:t,windowId:r,paneId:c}=Ze(),l=ut(),m=n.useRef(null),v=n.useRef(null),b=n.useRef(null),C=n.useRef(null),F=n.useRef(!1),z=n.useRef(!1),j=n.useRef(null),i=O(s=>s.selectPane),y=O(s=>s.focusPane),ue=O(s=>t?s.snapshots[t]:void 0),U=O(s=>{var g;return t?(g=s.deviceErrors)==null?void 0:g[t]:void 0}),M=O(s=>{var g;return t?((g=s.deviceConnected)==null?void 0:g[t])??!1:!1}),ne=!!O(s=>{var g;return t?(g=s.deviceReconnecting)==null?void 0:g[t]:void 0}),me=O(s=>t?s.connectedDevices.has(t):!1),Z=dt(s=>{var g;return((g=s.settings)==null?void 0:g.siteName)??"tmex"}),d=n.useMemo(()=>et(c),[c]),S=n.useMemo(()=>t&&d?`${t}:${d}`:null,[t,d]),[p,k]=n.useState(!1),[R,_]=n.useState(""),G=n.useRef(!1),u=!M||!d,[A,Y]=n.useState(!1),H=ge(s=>s.inputMode),D=ge(s=>s.theme),V=ge(s=>s.editorSendWithEnter),de=ge(s=>s.setEditorSendWithEnter),re=ge(s=>s.addEditorHistory),we=ge(s=>s.setEditorDraft),J=ge(s=>s.removeEditorDraft),Q=ge(s=>S?s.editorDrafts[S]??"":""),ee=n.useMemo(()=>$t(),[]),E=(st=ue==null?void 0:ue.session)==null?void 0:st.windows,a=D==="light"?lt:at,{data:h}=tt({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}),N=n.useMemo(()=>{if(t)return h==null?void 0:h.devices.find(s=>s.id===t)},[t,h==null?void 0:h.devices]),T=n.useMemo(()=>{if(!(!r||!E))return E.find(s=>s.id===r)},[r,E]),W=n.useMemo(()=>{if(!(!d||!T))return T.panes.find(s=>s.id===d)},[d,T]),se=!!E,x=se&&!!r&&!T?e("terminal.windowClosed"):se&&!!r&&!!d&&!!T&&!W?e("terminal.paneClosed"):null,L=!!x,$=!!(M&&d&&!L),P=!!(!p&&T&&T.panes.length>1&&T.layout&&!L),fe=n.useRef(P);n.useEffect(()=>{fe.current=P},[P]);const Ee=n.useMemo(()=>{if(!T||!W)return null;const s=(N==null?void 0:N.name)??t;return ft({paneCustomName:W.customName,paneTitle:W.title,windowName:T.name,windowCustomName:T.customName,deviceName:s})},[N==null?void 0:N.name,t,W,T]),be=n.useMemo(()=>{if(!E||E.length===0)return null;const s=E.find(w=>w.active),g=s==null?void 0:s.panes.find(w=>w.active);return!s||!g?null:{windowId:s.id,paneId:g.id}},[E]),Se=p&&T&&T.panes.length>1?T.id:null,B=n.useRef(Se);n.useEffect(()=>{B.current=Se},[Se]);const oe=n.useCallback((s,g)=>{if(!t||!d)return;const w=B.current;if(w){O.getState().applyStackedLayout(t,w,s,g);return}O.getState().resizePane(t,d,s,g)},[t,d]),X=n.useCallback((s,g)=>{if(!t||!d)return;const w=B.current;if(w){O.getState().applyStackedLayout(t,w,s,g);return}O.getState().syncPaneSize(t,d,s,g)},[t,d]),q=n.useCallback((s,g)=>{var _e;const w=C.current;if(fe.current){const le=(_e=m.current)==null?void 0:_e.getBoundingClientRect(),ze=w==null?void 0:w.getCellSize();return le&&ze&&le.width>0&&le.height>0?{cols:Math.max(2,Math.floor(le.width/ze.width)),rows:Math.max(2,Math.floor(le.height/ze.height))}:void 0}if(s&&E){const le=E.find(ze=>ze.id===s);if(p&&le&&le.panes.length>1)return}const I=(w==null?void 0:w.calculateSizeFromContainer())??(w==null?void 0:w.getSize())??void 0;if(I)return I;if(!s||!g||!E)return;const te=E.find(le=>le.id===s),ve=te==null?void 0:te.panes.find(le=>le.id===g);if(!(!ve||ve.width<=1||ve.height<=1))return{cols:ve.width,rows:ve.height}},[p,E]),xe=n.useCallback((s,g)=>{t&&(j.current={windowId:s,paneId:g,at:Date.now()},l(`/devices/${t}/windows/${s}/panes/${Ce(g)}`,{replace:!0}))},[t,l]),ie=n.useCallback(s=>{C.current=s},[]);n.useEffect(()=>{const s=()=>{k(window.innerWidth<768||"ontouchstart"in window)};return s(),window.addEventListener("resize",s),()=>window.removeEventListener("resize",s)},[]),n.useEffect(()=>{if(!p||!ee||z.current)return;z.current=!0;const s=()=>{window.scrollTo(0,1)},g=window.requestAnimationFrame(s),w=window.setTimeout(s,120),I=window.setTimeout(s,420);return()=>{window.cancelAnimationFrame(g),window.clearTimeout(w),window.clearTimeout(I)}},[ee,p]),n.useEffect(()=>{t&&(F.current=!1,Ie.current=null,je.current=null,j.current=null,he.current=[])},[t]),n.useEffect(()=>{M||(F.current=!1)},[M]),n.useEffect(()=>{if(!t||!M||!r||!E)return;if(E.length===0){l("/devices",{replace:!0});return}const s=E.find(w=>w.id===r);if(!s)return;if(!d){const w=s.panes.find(I=>I.active)??s.panes[0];w&&l(`/devices/${t}/windows/${r}/panes/${Ce(w.id)}`,{replace:!0});return}if(!s.panes.find(w=>w.id===d)){const w=E.find(te=>te.panes.some(ve=>ve.id===d));if(w){l(`/devices/${t}/windows/${w.id}/panes/${Ce(d)}`,{replace:!0});return}const I=s.panes.find(te=>te.active)??s.panes[0];I&&l(`/devices/${t}/windows/${r}/panes/${Ce(I.id)}`,{replace:!0});return}},[t,M,E,r,d,l]),n.useEffect(()=>{if(!t||!M||!E||E.length===0||r&&d||F.current)return;const s=E.find(w=>w.active)??E[0],g=s.panes.find(w=>w.active)??s.panes[0];g&&(F.current=!0,l(`/devices/${t}/windows/${s.id}/panes/${Ce(g.id)}`,{replace:!0}))},[M,t,l,d,r,E]);const he=n.useRef([]),pe=n.useCallback((s,g)=>{const w=Date.now(),I=[...he.current.filter(te=>w-te.at<2e3),{windowId:s,paneId:g,at:w}];he.current=I.slice(-8)},[]),ye=n.useRef(null);n.useEffect(()=>{ye.current=null},[t,d]);const ke=n.useRef(null),Ae=n.useRef(P);n.useEffect(()=>{Ae.current!==P&&(Ae.current=P,ye.current=null,ke.current=null)},[P]),n.useEffect(()=>{if(!t||!r||!d||u||!M)return;const s=`${t}:${r}:${d}`;if(ye.current===s)return;ye.current=s;const g=P&&ke.current===`${t}:${r}`&&!!(T!=null&&T.panes.some(I=>I.id===d));if(pe(r,d),g){y(t,r,d);return}const w=q(r,d);i(t,r,d,w),ke.current=`${t}:${r}`},[M,t,y,q,u,P,pe,d,i,T,r]),n.useEffect(()=>{if(!t||!M||!r||!d)return;const s={windowId:r,paneId:d};dr({routeTarget:s,snapshotActive:be,pendingUserSelection:j.current})&&(j.current={windowId:s.windowId,paneId:s.paneId,at:Date.now()})},[M,t,d,be,r]);const ae=O(s=>t?s.activePaneFromEvent[t]:void 0),Ie=n.useRef(null);n.useEffect(()=>{if(!t||!M||!r||!d||!ae)return;const s=Date.now(),g=Fe(j.current,s);if(j.current=g,lr({now:s,pendingUserSelection:g,activePaneFromEvent:ae,currentRoute:{windowId:r,paneId:d},recentSelectRequests:he.current,lastHandledActive:Ie.current}))return;if(Ie.current={...ae},g&&g.windowId===ae.windowId&&g.paneId===ae.paneId&&(j.current=null),!(fe.current&&ae.windowId===r)){const I=q(ae.windowId,ae.paneId);pe(ae.windowId,ae.paneId),i(t,ae.windowId,ae.paneId,I)}l(`/devices/${t}/windows/${ae.windowId}/panes/${Ce(ae.paneId)}`,{replace:!0})},[t,M,r,d,ae,pe,q,i,l]);const je=n.useRef(null);n.useEffect(()=>{if(!t||!M||!E||E.length===0)return;const s=he.current,g=E.find(le=>le.active);if(!g)return;const w=g.panes.find(le=>le.active);if(!w)return;const I={windowId:g.id,paneId:w.id},te=Date.now(),ve=Fe(j.current,te);if(j.current=ve,ur({now:te,pendingUserSelection:ve,snapshotActive:I,recentSelectRequests:s})||je.current&&je.current.windowId===I.windowId&&je.current.paneId===I.paneId||(je.current={...I},ve&&ve.windowId===I.windowId&&ve.paneId===I.paneId&&(j.current=null),r===I.windowId&&d===I.paneId))return;if(!(fe.current&&I.windowId===r)){const le=q(I.windowId,I.paneId);pe(I.windowId,I.paneId),i(t,I.windowId,I.paneId,le)}l(`/devices/${t}/windows/${I.windowId}/panes/${Ce(I.paneId)}`,{replace:!0})},[t,M,E,r,d,pe,q,i,l]);const Le=O(s=>t?s.pendingCreateWindowAt[t]:void 0);n.useEffect(()=>{if(!t||!M||!Le)return;const s=5e3,g=Date.now()-Le;if(g>s){O.getState().clearPendingCreateWindow(t);return}if(!be){const te=window.setTimeout(()=>{O.getState().clearPendingCreateWindow(t)},s-g);return()=>window.clearTimeout(te)}const w=be;if(r===w.windowId&&d===w.paneId){const te=window.setTimeout(()=>{O.getState().clearPendingCreateWindow(t)},s-g);return()=>window.clearTimeout(te)}j.current={windowId:w.windowId,paneId:w.paneId,at:Date.now()};const I=q(w.windowId,w.paneId);pe(w.windowId,w.paneId),i(t,w.windowId,w.paneId,I),l(`/devices/${t}/windows/${w.windowId}/panes/${Ce(w.paneId)}`,{replace:!0}),O.getState().clearPendingCreateWindow(t)},[t,M,Le,be,r,d,pe,q,i,l]),n.useEffect(()=>{if(P||!$||!W||u)return;const s=C.current,g=s==null?void 0:s.getTerminal();if(!g)return;const w=Math.max(2,Math.floor(W.width||0)),I=Math.max(2,Math.floor(W.height||0));if(!w||!I)return;const te=Date.now(),ve={cols:w,rows:I},_e=(s==null?void 0:s.getPendingLocalSize())??null;$n({now:te,remoteSize:ve,pendingLocalSize:_e})&&(g.cols===w&&g.rows===I||g.resize(w,I))},[$,u,P,W]),n.useEffect(()=>{const s=window.requestAnimationFrame(()=>{var w;(w=C.current)==null||w.scrollToBottom()}),g=window.setTimeout(()=>{var w;(w=C.current)==null||w.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(s),window.clearTimeout(g)}},[H]),n.useEffect(()=>{U!=null&&U.message&&Me.error(U.message)},[U==null?void 0:U.message]),n.useEffect(()=>(document.title=Bt(Ee),()=>{document.title=Z}),[Z,Ee]),n.useEffect(()=>{const s=()=>{var g;(g=C.current)==null||g.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",s),()=>{window.removeEventListener("tmex:jump-to-latest",s)}},[]),n.useEffect(()=>{const s=g=>{const{deviceId:w,windowId:I,paneId:te}=g.detail;w===t&&(j.current={windowId:I,paneId:te,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",s),()=>{window.removeEventListener("tmex:user-initiated-selection",s)}},[t]),n.useEffect(()=>{_(Q)},[Q]);const Te=n.useCallback(s=>{if(!t||!d||!$)return;O.getState().sendInput(t,d,s,!1)},[$,t,d]),De=n.useCallback(s=>{var g,w;if(s.type==="action"){if(s.action==="toggleKeyboard"){ge.getState().setInputMode(H==="direct"?"editor":"direct");return}if(s.action==="scrollToBottom"){(g=C.current)==null||g.scrollToBottom();return}}if(s.type==="send"){s.payload&&Te(s.payload);return}if(!(!t||!d||!$))switch(s.action){case"paste":{((w=navigator.clipboard)!=null&&w.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(te=>{te&&O.getState().paste(t,d,te)}).catch(()=>Me.error(e("terminal.pasteFailed")));break}case"newAgentSession":Ft.getState().startDraft(t,d,null),ge.getState().setSidebarCollapsed(!1),ge.getState().setSidebarTab("agent");break}},[$,t,Te,H,d,e]),gt=n.useCallback(()=>{if(!$){Me.error(e("wsError.checkGateway"));return}if(!t||!d||!R.trim())return;Y(!0),window.setTimeout(()=>Y(!1),150);const s=V?`${R}\r`:R;O.getState().sendInput(t,d,s,!1),re(R),S&&J(S),_("")},[re,$,t,S,V,R,J,d,e]),xt=n.useCallback(()=>{if(!$){Me.error(e("wsError.checkGateway"));return}if(!t||!d||!R.trim())return;Y(!0),window.setTimeout(()=>Y(!1),150);const s=R.split(/\r?\n/),g=O.getState();for(const w of s)w.trim()&&g.sendInput(t,d,`${w}\r`,!1);re(R),S&&J(S),_("")},[re,$,t,S,R,J,d,e]),vt=n.useCallback(()=>{var s;(s=b.current)==null||s.focus({preventScroll:!0})},[]);if(!t)return o.jsx("div",{className:"flex h-full items-center justify-center p-4",children:o.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:e("device.noDevices")})});const bt=!!d&&!L&&(M||ne),St=M&&!!d&&!L&&!W,yt=me&&!M&&!U&&!ne,rt=o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx(qe,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),o.jsx("h3",{className:"text-lg font-medium",children:e("terminal.connecting")})]});return o.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[o.jsx("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${p&&H==="editor"?"pb-1":""}`,children:o.jsxs("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:a.background},children:[L?o.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:o.jsxs("div",{className:"max-w-sm space-y-4",children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx(En,{className:"h-6 w-6 text-muted-foreground"})}),o.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"terminal-selection-invalid",children:x})]})}):bt&&d?P&&T?o.jsxs("div",{className:"flex h-full min-h-0 w-full flex-1 flex-col","data-virtual-keyboard-avoid":!0,children:[o.jsx("div",{ref:m,className:"relative min-h-0 flex-1",children:o.jsx(ir,{deviceId:t,window:T,focusedPaneId:d,theme:D,inputMode:H,deviceConnected:M,focusedTerminalRef:ie,onUserSelectPane:xe,onWindowResize:oe},`${t}:${T.id}`)}),H==="direct"&&o.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:a.background},children:o.jsx(Ue,{onActivate:De,disabled:!$})})]}):o.jsx("div",{ref:m,className:"flex-1 h-full min-h-0 w-full","data-virtual-keyboard-avoid":!0,children:o.jsx(nt,{ref:C,deviceId:t,paneId:d,theme:D,inputMode:H,deviceConnected:M,isSelectionInvalid:L,onResize:oe,onSync:X,children:H==="direct"&&o.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:a.background},children:o.jsx(Ue,{onActivate:De,disabled:!$})})},`${t}:${d}`)}):o.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:o.jsx("div",{className:"max-w-sm space-y-4",children:yt?rt:!M&&!ne?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),o.jsx("h3",{className:"text-lg font-medium",children:e("device.disconnected")}),o.jsx("p",{className:"text-sm text-muted-foreground",children:e("device.connectToStart")})]}):r?rt:o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),o.jsx("h3",{className:"text-lg font-medium",children:e("window.noWindowSelected")}),o.jsx("p",{className:"text-sm text-muted-foreground",children:e("window.selectWindowToStart")})]})})}),ne&&o.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-2 z-10 flex justify-center","data-testid":"terminal-reconnecting-indicator",children:o.jsx(Ht,{deviceId:t,className:"shadow-sm"})}),St&&o.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:o.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-card/90 px-4 py-3 shadow-sm",children:[o.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),o.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:e("terminal.connecting")})]})})]})}),H==="editor"&&o.jsxs("div",{ref:v,"data-virtual-keyboard-avoid":!0,className:"editor-mode-input bg-card/85 backdrop-blur-sm",children:[p&&o.jsx(Ue,{onActivate:s=>{De(s),s.type==="send"&&vt()},disabled:!$}),o.jsx("textarea",{ref:b,"data-testid":"editor-input",className:"min-h-[88px] max-h-[28vh] w-full resize-y rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground shadow-xs outline-none transition-colors focus:border-ring",value:R,onChange:s=>{const g=s.target.value;if(_(g),!!S){if(g){we(S,g);return}J(S)}},placeholder:e("terminal.inputPlaceholder"),onCompositionStart:()=>{G.current=!0},onCompositionEnd:()=>{G.current=!1}}),o.jsx("div",{className:"actions mt-2",children:o.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[o.jsxs("div",{className:"send-with-enter-toggle mr-auto flex items-center gap-2 text-xs text-muted-foreground","data-testid":"editor-send-with-enter-toggle",children:[o.jsx(Wt,{size:"sm",checked:V,onCheckedChange:s=>de(!!s)}),o.jsx("span",{children:e("terminal.editorSendWithEnter")})]}),o.jsxs(Re,{variant:"outline",size:"sm","data-testid":"editor-clear",onMouseDown:s=>s.preventDefault(),onClick:()=>{var s;_(""),S&&J(S),p&&H==="editor"&&((s=b.current)==null||s.focus({preventScroll:!0}))},title:e("terminal.clear"),children:[o.jsx(Ot,{className:"h-4 w-4"}),e("terminal.clear")]}),o.jsxs(Re,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onMouseDown:s=>s.preventDefault(),onClick:()=>{var s;xt(),p&&H==="editor"&&((s=b.current)==null||s.focus({preventScroll:!0}))},disabled:!$||A,children:[A?o.jsx(qe,{className:"h-4 w-4 animate-spin"}):o.jsx(ot,{className:"h-4 w-4"}),e("terminal.editorSendLineByLine")]}),o.jsxs(Re,{variant:"default",size:"sm","data-testid":"editor-send",onMouseDown:s=>s.preventDefault(),onClick:()=>{var s;gt(),p&&H==="editor"&&((s=b.current)==null||s.focus({preventScroll:!0}))},disabled:!$||A,children:[A?o.jsx(qe,{className:"h-4 w-4 animate-spin"}):o.jsx(ot,{className:"h-4 w-4"}),e("common.send")]})]})})]})]})}function xr(){const{deviceId:e,windowId:t,paneId:r}=Ze(),c=r?et(r):void 0,l=O(z=>z.snapshots),m=dt(z=>{var j;return((j=z.settings)==null?void 0:j.siteName)??"tmex"}),v=e?l[e]:void 0,b=n.useMemo(()=>{var z;if(!(!t||!((z=v==null?void 0:v.session)!=null&&z.windows)))return v.session.windows.find(j=>j.id===t)},[t,v]),C=n.useMemo(()=>{if(!(!c||!b))return b.panes.find(z=>z.id===c)},[c,b]),F=n.useMemo(()=>b&&C?ft({paneCustomName:C.customName,paneTitle:C.title,windowName:b.name,windowCustomName:b.customName,deviceName:m}):e??"",[b,C,m,e]);return o.jsx(o.Fragment,{children:F})}function vr(){const{t:e}=Pe(),{deviceId:t,windowId:r,paneId:c}=Ze(),l=ut(),m=Xt(),v=c?et(c):void 0,b=ge(u=>u.inputMode),C=ge(u=>u.setInputMode),F=O(u=>{var A;return t?((A=u.deviceConnected)==null?void 0:A[t])??!1:!1}),z=O(u=>t?u.snapshots[t]:void 0),j=n.useMemo(()=>{var u;if(!(!r||!((u=z==null?void 0:z.session)!=null&&u.windows)))return z.session.windows.find(A=>A.id===r)},[r,z]),i=n.useCallback(u=>{!t||!r||l(`/devices/${t}/windows/${r}/panes/${Ce(u)}`,{replace:!0})},[t,r,l]),y=n.useMemo(()=>{if(!(!v||!j))return j.panes.find(u=>u.id===v)},[v,j]),ue=n.useCallback(u=>{!t||!v||O.getState().splitPane(t,v,u,y==null?void 0:y.currentPath)},[t,v,y==null?void 0:y.currentPath]),[U,M]=n.useState(!1),[ce,ne]=n.useState(!1),[me,Z]=n.useState(!1),d=!!(v&&F),p=(tt({queryKey:Yt(t??"",v??""),queryFn:()=>qt(t??"",v??""),enabled:!!(t&&v),throwOnError:!1}).data??[]).some(u=>u.enabled),k=()=>{C(b==="direct"?"editor":"direct")},R=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},_=()=>{M(!0)},G=()=>{window.location.reload()};return o.jsxs(o.Fragment,{children:[m&&v&&j&&j.panes.length>1&&o.jsx(Vn,{window:j,currentPaneId:v,onSelectPane:i}),!m&&o.jsxs(o.Fragment,{children:[o.jsx(Re,{variant:"ghost",size:"icon-sm",onClick:()=>ue("right"),disabled:!d,"data-testid":"split-right-button","aria-label":e("window.splitRight"),title:e("window.splitRight"),children:o.jsx(Ut,{className:"h-4 w-4"})}),o.jsx(Re,{variant:"ghost",size:"icon-sm",onClick:()=>ue("down"),disabled:!d,"data-testid":"split-down-button","aria-label":e("window.splitDown"),title:e("window.splitDown"),children:o.jsx(Vt,{className:"h-4 w-4"})})]}),o.jsx(Re,{variant:"ghost",size:"icon-sm",onClick:_,"aria-label":e("nav.refreshPage"),title:e("nav.refreshPage"),children:o.jsx(un,{className:"h-4 w-4"})}),o.jsx(Re,{variant:"ghost",size:"icon-sm",onClick:k,disabled:!d,"data-testid":"terminal-input-mode-toggle","aria-label":e(b==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:e(b==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:b==="direct"?o.jsx(gn,{className:"h-4 w-4"}):o.jsx(jn,{className:"h-4 w-4"})}),o.jsx(Re,{variant:"ghost",size:"icon-sm",onClick:R,disabled:!d,"aria-label":e("nav.jumpToLatest"),title:e("nav.jumpToLatest"),children:o.jsx(dn,{className:"h-4 w-4"})}),o.jsxs(Re,{variant:"ghost",size:"icon-sm",className:"relative",onClick:()=>ne(!0),disabled:!v,"data-testid":"watch-open-button","aria-label":e("watch.title"),title:e("watch.title"),children:[o.jsx(Kt,{className:"h-4 w-4"}),p&&o.jsx("span",{className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-primary","data-testid":"watch-active-indicator"})]}),o.jsx(Re,{variant:"ghost",size:"icon-sm",onClick:()=>Z(!0),"data-testid":"keyboard-behavior-open-button","aria-label":e("settings.terminal.title"),title:e("settings.terminal.title"),children:o.jsx(Tn,{className:"h-4 w-4"})}),o.jsx(Nn,{open:me,onOpenChange:Z}),t&&v&&o.jsx(Gt,{open:ce,onOpenChange:ne,deviceId:t,paneId:v}),o.jsx(Qt,{open:U,onOpenChange:M,children:o.jsxs(Jt,{children:[o.jsxs(Zt,{children:[o.jsx(en,{children:e("nav.refreshPage")}),o.jsx(tn,{children:e("nav.refreshPageConfirm")})]}),o.jsxs(nn,{children:[o.jsx(rn,{onClick:()=>M(!1),children:e("common.cancel")}),o.jsx(sn,{onClick:G,children:e("common.confirm")})]})]})})]})}export{vr as PageActions,xr as PageTitle,gr 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-CEPc0i5O.js";import{C as M,a as P,b as Ae,c as Te,d as Fe}from"./card-DAJtOO99.js";import{Z as We}from"./zap-CBeeCQFr.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-BK6c5W5S.js";import{C as M,a as P,b as Ae,c as Te,d as Fe}from"./card-BA66zlg1.js";import{Z as We}from"./zap-DxVtkroR.js";function g(e){const o=e.trim();return o||void 0}function qe(e){return e?{name:e.name,type:e.type,host:e.host??"",port:e.port??22,username:e.username??"",sshConfigRef:e.sshConfigRef??"",session:e.session??"tmex",defaultWorkingDir:e.defaultWorkingDir??"",authMode:e.type==="local"?"auto":e.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"root",sshConfigRef:"",session:"tmex",defaultWorkingDir:"",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(e){if(e.type==="local")return{name:e.name.trim(),type:"local",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:"auto"};const o={name:e.name.trim(),type:"ssh",host:e.host.trim(),port:e.port,username:e.username.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir),authMode:e.authMode};return e.authMode==="configRef"&&(o.sshConfigRef=e.sshConfigRef.trim()),e.authMode==="password"&&(o.password=e.password),e.authMode==="key"&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function He(e){if(e.type==="local")return{name:e.name.trim(),session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:"auto"};const o={name:e.name.trim(),host:e.host.trim(),port:e.port,username:e.username.trim(),sshConfigRef:e.authMode==="configRef"?e.sshConfigRef.trim():"",session:g(e.session)??"tmex",defaultWorkingDir:g(e.defaultWorkingDir)??"",authMode:e.authMode};return e.authMode==="password"&&e.password&&(o.password=e.password),e.authMode==="key"&&e.privateKey&&(o.privateKey=e.privateKey,o.privateKeyPassphrase=e.privateKeyPassphrase||void 0),o}function se(e){return Number.isInteger(e)&&e>=1&&e<=65535}function Oe(e){return e.type!=="ssh"?null:e.host.trim()?se(e.port)?e.username.trim()?e.authMode==="configRef"&&!e.sshConfigRef.trim()?"validation.sshConfigRequired":null:"validation.usernameRequired":"validation.portRequired":"validation.hostRequired"}async function G(e,o){try{return(await e.json()).error??o}catch{return o}}function Ue(){const{t:e}=b(),[o,m]=v.useState(!1),[t,y]=v.useState(null),[r,d]=v.useState(null),l=_(),h=ie(n=>{var p;return((p=n.settings)==null?void 0:p.language)??"en_US"});v.useEffect(()=>{const n=()=>m(!0);return window.addEventListener("tmex:open-add-device",n),()=>window.removeEventListener("tmex:open-add-device",n)},[]);const{data:c,isLoading:K,isError:N}=re({queryKey:["devices"],queryFn:async()=>{const n=await fetch("/api/devices");if(!n.ok)throw new Error(e("device.loadFailed"));return n.json()},throwOnError:!1}),S=ne(n=>n.hydrateDeviceErrors);v.useEffect(()=>{c!=null&&c.devices&&S(c.devices.map(n=>({deviceId:n.id,lastError:n.lastError??null,lastErrorType:n.lastErrorType??null})))},[c,S]);const k=I({mutationFn:async n=>{if(!(await fetch(`/api/devices/${n}`,{method:"DELETE"})).ok)throw new Error(e("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),f.success(e("common.success"))},onError:n=>{f.error(n instanceof Error?n.message:e("common.error"))}}),E=v.useMemo(()=>[...(c==null?void 0:c.devices)??[]].sort((p,D)=>p.sortOrder-D.sortOrder||p.name.localeCompare(D.name,oe(h),{numeric:!0,sensitivity:"base"})),[c==null?void 0:c.devices,h]);return s.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-3 p-3 pb-[calc(1rem+env(safe-area-inset-bottom))] sm:gap-4 sm:p-5","data-testid":"devices-page",children:[K?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-muted-foreground",children:e("common.loading")})}):N?s.jsx(M,{children:s.jsx(P,{className:"py-16 text-center text-sm text-destructive",children:e("device.loadFailed")})}):E.length===0?s.jsx(M,{children:s.jsxs(P,{className:"space-y-4 py-14 text-center",children:[s.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:s.jsx(X,{className:"h-6 w-6 text-muted-foreground"})}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-medium",children:e("device.noDevices")}),s.jsx("p",{className:"text-sm text-muted-foreground",children:e("device.addDevice")})]}),s.jsxs(C,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[s.jsx(Y,{className:"h-4 w-4"}),e("device.addDevice")]})]})}):s.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:E.map(n=>s.jsx(Be,{device:n,onEdit:()=>y(n),onDelete:()=>d(n)},n.id))}),o&&s.jsx(Z,{mode:"create",onClose:()=>m(!1)}),t&&s.jsx(Z,{mode:"edit",device:t,onClose:()=>y(null)}),s.jsx(ce,{open:r!==null,onOpenChange:n=>!n&&d(null),children:s.jsxs(de,{children:[s.jsxs(le,{children:[s.jsx(ue,{className:"bg-destructive/10",children:s.jsx(ee,{className:"h-5 w-5 text-destructive"})}),s.jsx(me,{children:e("device.deleteConfirm")}),s.jsx(he,{children:e("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),s.jsxs(pe,{children:[s.jsx(xe,{children:e("common.cancel")}),s.jsx(ve,{variant:"destructive",disabled:!r||k.isPending,onClick:()=>{r&&(k.mutate(r.id),d(null))},children:e("common.delete")})]})]})})]})}function Be({device:e,onEdit:o,onDelete:m}){const{t}=b(),y=e.type==="local"?s.jsx(X,{className:"h-4 w-4"}):s.jsx(fe,{className:"h-4 w-4"}),r=e.type==="local"?t("device.typeLocal"):`${e.username??"-"}@${e.host??"-"}:${e.port??22}`,d=I({mutationFn:async()=>{const l=await fetch(`/api/devices/${e.id}/test-connection`,{method:"POST"});let h=null;try{h=await l.json()}catch{h=null}if(!l.ok){const c=h;throw new Error((c==null?void 0:c.error)??t("common.error"))}return h},onSuccess:l=>{f.success(l.message??t("common.success"))},onError:l=>{f.error(l instanceof Error?l.message:t("common.error"))}});return s.jsxs(M,{"data-testid":"device-card","data-device-id":e.id,"data-device-name":e.name,className:"overflow-hidden border-border/50",children:[s.jsxs(Ae,{className:"space-y-2 pb-2",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[s.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground",children:y}),s.jsxs("div",{className:"min-w-0 space-y-0.5",children:[s.jsx(Te,{className:"line-clamp-1 text-sm",title:e.name,children:e.name}),s.jsx(Fe,{className:"line-clamp-1 text-xs",children:r})]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:s.jsxs(ge,{children:[s.jsx(ye,{render:s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${e.id}`,"aria-label":t("common.edit"),title:t("common.edit")}),children:s.jsx(je,{className:"h-4 w-4"})}),s.jsxs(we,{align:"end",children:[s.jsxs($,{"data-testid":`device-card-edit-${e.id}`,onClick:o,children:[s.jsx(Ne,{className:"h-4 w-4"}),t("common.edit")]}),e.type==="ssh"&&s.jsxs($,{"data-testid":`device-card-test-${e.id}`,onClick:()=>d.mutate(),disabled:d.isPending,children:[s.jsx(We,{className:"h-4 w-4"}),t("common.test")]}),s.jsx(De,{}),s.jsxs($,{"data-testid":`device-card-delete-${e.id}`,variant:"destructive",onClick:m,children:[s.jsx(ee,{className:"h-4 w-4"}),t("common.delete")]})]})]})})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.type==="local"?t("device.typeLocal"):t("device.typeSSHBadge")}),e.session&&s.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:e.session}),s.jsx(Ce,{deviceId:e.id})]})]}),s.jsxs(P,{className:"pt-0",children:[s.jsx(be,{className:"mb-2"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(Se,{to:`/devices/${e.id}`,"data-testid":`device-card-connect-${e.id}`,className:ke({variant:"outline",size:"sm"}),children:t("device.connect")})})]})]})}function Z({mode:e,device:o,onClose:m}){const{t}=b(),y=_(),[r,d]=v.useState(qe(o)),[l,h]=v.useState(!1),[c,K]=v.useState(!1),N=e==="edit",S=r.type==="ssh",k=I({mutationFn:async a=>{const i=await fetch("/api/devices",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.createFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),E=I({mutationFn:async a=>{if(!o)throw new Error(t("apiError.deviceNotFound"));const i=await fetch(`/api/devices/${o.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.updateFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),f.success(t("common.success")),m()},onError:a=>{f.error(a instanceof Error?a.message:t("common.error"))}}),n=async a=>{a.preventDefault(),K(!0);const i=Oe(r);if(i){f.error(t(i));return}h(!0);try{e==="create"?await k.mutateAsync(Le(r)):await E.mutateAsync(He(r))}catch{}finally{h(!1)}},p=`${e}-device-name`,D=`${e}-device-type`,A=`${e}-device-host`,T=`${e}-device-port`,F=`${e}-device-username`,W=`${e}-device-session`,q=`${e}-device-default-working-dir`,L=`${e}-device-auth-mode`,H=`${e}-device-password`,O=`${e}-device-private-key`,B=`${e}-device-private-key-passphrase`,te={local:t("device.typeLocal"),ssh:t("device.typeSSH")},ae={password:t("device.authPassword"),key:t("device.authKey"),agent:t("device.authAgent"),configRef:t("device.authConfigRef")},R=a=>s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:a}),u=(a,i,j)=>s.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:a,children:[i,j&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return s.jsx(Ee,{open:!0,onOpenChange:a=>!a&&m(),children:s.jsxs(Me,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[s.jsxs(Pe,{children:[s.jsx(Ie,{children:t(N?"device.editDevice":"device.addDevice")}),s.jsx(Ke,{children:t(N?"device.editDeviceDescription":"device.addDeviceDescription")})]}),s.jsxs("form",{onSubmit:n,className:"space-y-4",children:[s.jsxs("div",{className:"-mr-2 max-h-[min(70dvh,720px)] space-y-5 overflow-y-auto pr-2",children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionBasic")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(p,t("device.name"),!0),s.jsx(x,{id:p,"data-testid":"device-name-input",type:"text",value:r.name,onChange:a=>d(i=>({...i,name:a.target.value})),placeholder:t("device.namePlaceholder"),required:!0})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(D,t("device.type")),s.jsxs(z,{value:r.type,onValueChange:a=>{if(!a)return;const i=a;d(j=>({...j,type:i,authMode:i==="local"?"auto":j.authMode==="auto"?"agent":j.authMode}))},disabled:N,children:[s.jsx(V,{id:D,"data-testid":"device-type-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.type"),children:a=>te[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"local",children:t("device.typeLocal")}),s.jsx(w,{value:"ssh",children:t("device.typeSSH")})]})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(W,t("device.session")),s.jsx(x,{id:W,"data-testid":"device-session-input",type:"text",value:r.session,onChange:a=>d(i=>({...i,session:a.target.value})),placeholder:t("device.sessionPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(q,t("device.defaultWorkingDir")),s.jsx(x,{id:q,"data-testid":"device-default-working-dir-input",type:"text",value:r.defaultWorkingDir,onChange:a=>d(i=>({...i,defaultWorkingDir:a.target.value})),placeholder:t("device.defaultWorkingDirPlaceholder")})]})]})]}),S&&s.jsxs(s.Fragment,{children:[s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionConnection")),s.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(A,t("device.host"),!0),s.jsx(x,{id:A,type:"text",value:r.host,onChange:a=>d(i=>({...i,host:a.target.value})),placeholder:t("device.hostPlaceholder"),"aria-invalid":c&&!r.host.trim()})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(T,t("device.port"),!0),s.jsx(x,{id:T,type:"number",value:Number.isNaN(r.port)?"":r.port,onChange:a=>{const i=a.target.value;d(j=>({...j,port:i===""?Number.NaN:Number.parseInt(i,10)}))},min:1,max:65535,"aria-invalid":c&&!se(r.port)})]}),s.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[u(F,t("device.username"),!0),s.jsx(x,{id:F,type:"text",value:r.username,onChange:a=>d(i=>({...i,username:a.target.value})),placeholder:t("device.usernamePlaceholder"),"aria-invalid":c&&!r.username.trim()})]})]})]}),s.jsxs("section",{className:"space-y-2.5",children:[R(t("device.sectionAuth")),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[u(L,t("device.authMode")),s.jsxs(z,{value:r.authMode,onValueChange:a=>{a&&d(i=>({...i,authMode:a}))},children:[s.jsx(V,{id:L,"data-testid":"device-auth-mode-select",className:"w-full",children:s.jsx(U,{placeholder:t("device.authMode"),children:a=>ae[a]??""})}),s.jsxs(J,{children:[s.jsx(w,{value:"password",children:t("device.authPassword")}),s.jsx(w,{value:"key",children:t("device.authKey")}),s.jsx(w,{value:"agent",children:t("device.authAgent")}),s.jsx(w,{value:"configRef",children:t("device.authConfigRef")})]})]})]}),r.authMode==="password"&&s.jsxs("div",{className:"space-y-1.5",children:[u(H,t("device.password")),s.jsx(x,{id:H,type:"password",value:r.password,onChange:a=>d(i=>({...i,password:a.target.value}))})]}),r.authMode==="key"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"space-y-1.5",children:[u(O,t("device.privateKey")),s.jsx(Re,{id:O,value:r.privateKey,onChange:a=>d(i=>({...i,privateKey:a.target.value})),className:"h-28 font-mono text-xs",placeholder:t("device.privateKeyPlaceholder")})]}),s.jsxs("div",{className:"space-y-1.5",children:[u(B,t("device.passphrase")),s.jsx(x,{id:B,type:"password",value:r.privateKeyPassphrase,onChange:a=>d(i=>({...i,privateKeyPassphrase:a.target.value}))})]})]}),r.authMode==="configRef"&&s.jsxs("div",{className:"space-y-1.5",children:[u(`${e}-device-ssh-config-ref`,t("device.authConfigRef"),!0),s.jsx(x,{id:`${e}-device-ssh-config-ref`,"data-testid":"device-ssh-config-ref-input",type:"text",value:r.sshConfigRef,onChange:a=>d(i=>({...i,sshConfigRef:a.target.value})),placeholder:t("device.sshConfigRefPlaceholder"),"aria-invalid":c&&!r.sshConfigRef.trim()}),s.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("device.sshConfigRefHint")})]})]})]})]})]}),s.jsxs($e,{children:[s.jsx(C,{type:"button",variant:"outline",onClick:m,children:t("common.cancel")}),s.jsx(C,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:t(l?"common.saving":"common.save")})]})]})]})})}function Je(){const{t:e}=b();return s.jsx(s.Fragment,{children:e("sidebar.manageDevices")})}function Ge(){const{t:e}=b(),o=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return s.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:o,"aria-label":e("sidebar.addDevice"),title:e("sidebar.addDevice"),children:s.jsx(Y,{className:"h-4 w-4"})})}export{Ge as PageActions,Je as PageTitle,Ue as default};
@@ -1,4 +1,4 @@
1
- import{Y as zn,_ as ut,r as oe,j as h,X as gt,ad as bt,u as ae,c as $n,al as qn,a as mt,B as se,Z as nn}from"./index-CEPc0i5O.js";import{r as pt,M as _t}from"./markdown-preview-BE4zuZfN.js";import{k as ft,d as Ve,l as te,D as Kn,m as Et,f as ht,c as Nt}from"./api-B_pG5Lrn.js";import{R as yt,s as vt}from"./transfer-toast-CHZr1a7O.js";import"./index-CxrkvaQh.js";/**
1
+ import{Y as zn,_ as ut,r as oe,j as h,X as gt,aL as bt,u as ae,c as $n,aq as qn,a as mt,B as se,Z as nn}from"./index-BK6c5W5S.js";import{r as pt,M as _t}from"./markdown-preview-CDjnYorp.js";import{k as ft,d as Ve,l as te,D as Kn,m as Et,f as ht,c as Nt}from"./api-C2-crTt8.js";import{R as yt,s as vt}from"./transfer-toast-BYw9LLNi.js";import"./index-DLyPliOu.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{Y as ce,u as F,j as e,L as It,M as Ze,z as Lt,r as w,c as Q,B as k,P as ge,a as O,e as M,o as b,am as D,v as De,T as te,A as xe,f as fe,g as pe,h as $t,i as we,k as ye,l as je,m as ve,n as be,C as ae,F as ne,H as ie,I as re,J as Ne,N as Ce,O as Ee,Q as ke,R as Se,U as le,K as B,W as de,al as U,G as Bt,x as xt,a4 as Dt,b as Oe,t as et,bp as $,X as ft,a5 as nt,bq as Ot,br as _t,aS as zt,bs as qt,bt as Kt,bu as Qt,bv as Ut,bw as it,Z as Ht}from"./index-CEPc0i5O.js";import{C as H,b as G,c as J,d as pt,a as V}from"./card-DAJtOO99.js";import{e as Vt,h as wt,F as We,i as Wt,j as Gt,D as Jt}from"./api-B_pG5Lrn.js";import{R as tt,T as Yt,b as Xt,d as Zt}from"./terminal-settings-panel-DAWL48fe.js";import{S as yt}from"./send-CKtMOmLP.js";import{M as es}from"./markdown-preview-BE4zuZfN.js";import{T as jt}from"./triangle-alert-03d4TB5d.js";import"./selection-clipboard-Dq6Zemfd.js";import"./index-CxrkvaQh.js";/**
1
+ import{Y as ce,u as F,j as e,L as It,M as Ze,z as Lt,r as w,c as Q,B as k,P as ge,a as O,e as M,o as b,a2 as D,v as De,T as te,A as xe,f as fe,g as pe,h as $t,i as we,k as ye,l as je,m as ve,n as be,C as ae,F as ne,H as ie,I as re,J as Ne,N as Ce,O as Ee,Q as ke,R as Se,U as le,K as B,W as de,aq as U,G as Bt,x as xt,at as Dt,b as Oe,t as et,bs as $,X as ft,af as nt,bt as Ot,bu as _t,aB as zt,bv as qt,bw as Kt,bx as Qt,by as Ut,bz as it,Z as Ht}from"./index-BK6c5W5S.js";import{C as H,b as G,c as J,d as pt,a as V}from"./card-BA66zlg1.js";import{e as Vt,h as wt,F as We,i as Wt,j as Gt,D as Jt}from"./api-C2-crTt8.js";import{R as tt,T as Yt,b as Xt,d as Zt}from"./terminal-settings-panel-DHrIp0wf.js";import{S as yt}from"./send-BVxB0Ywb.js";import{M as es}from"./markdown-preview-CDjnYorp.js";import{T as jt}from"./triangle-alert-D4oQhgpz.js";import"./selection-clipboard-D3gUQQ7L.js";import"./index-DLyPliOu.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{Y as _,r as N,j as e,X as C,u as k,aI as Y,aJ as ee,aK as te,al as se,aL as ne,aH as F,aM as B,a4 as H,B as y,G as be,M as ve,x as Ne,c as K,N as ye,O as ke,R as Ie,U as X,aN as Ce,aO as Se,V as re,v as Me,ae as _e,a5 as ze,aP as Te,ak as g,d as Ee,aQ as Be,aR as qe,P as $e,aS as Pe,am as Re,ah as Ae}from"./index-CEPc0i5O.js";import{M as Fe,r as He}from"./index-CxrkvaQh.js";import{K as Ke,S as Z}from"./send-CKtMOmLP.js";import{Z as ae}from"./zap-CBeeCQFr.js";/**
1
+ import{Y as _,r as N,j as e,X as C,u as k,an as Y,ao as ee,ap as te,aq as se,ar as ne,am as F,as as B,at as H,B as y,G as be,M as ve,x as Ne,c as K,N as ye,O as ke,R as Ie,U as X,au as Ce,av as Se,V as re,v as Me,aw as _e,af as ze,ax as Te,ay as g,d as Ee,az as Be,aA as qe,P as $e,aB as Pe,a2 as Ae,aC as Re}from"./index-BK6c5W5S.js";import{M as Fe,r as He}from"./index-DLyPliOu.js";import{K as Ke,S as Z}from"./send-BVxB0Ywb.js";import{Z as ae}from"./zap-DxVtkroR.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -13,12 +13,12 @@ import{Y as _,r as N,j as e,X as C,u as k,aI as Y,aJ as ee,aK as te,al as se,aL
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const Qe=[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]],Ue=_("list-tree",Qe);/**
16
+ */const Ue=[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]],Qe=_("list-tree",Ue);/**
17
17
  * @license lucide-react v0.564.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const Je=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],Ve=_("search",Je);/**
21
+ */const Ve=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],Je=_("search",Ve);/**
22
22
  * @license lucide-react v0.564.0 - ISC
23
23
  *
24
24
  * This source code is licensed under the ISC license.
@@ -35,4 +35,4 @@ import{Y as _,r as N,j as e,X as C,u as k,aI as Y,aJ as ee,aK as te,al as se,aL
35
35
  * See the LICENSE file in the root directory of this source tree.
36
36
  */const et=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],tt=_("wrench",et);function st(t){const s=t.split(`
37
37
  `),a=[];let d=[],o=!1;const i=()=>{const l=d.join(`
38
- `);l.trim()&&a.push(l),d=[]};for(const l of s){if(/^\s*(```|~~~)/.test(l)){o=!o,d.push(l);continue}if(!o&&l.trim()===""){i();continue}d.push(l)}return i(),a}const nt={a:({node:t,...s})=>e.jsx("a",{...s,target:"_blank",rel:"noopener noreferrer",className:"text-primary underline underline-offset-2 break-all"}),pre:({node:t,...s})=>e.jsx("pre",{...s,className:"bg-muted overflow-x-auto rounded-md p-2 font-mono text-xs leading-relaxed"}),code:({node:t,className:s,...a})=>e.jsx("code",{...a,className:C("bg-muted rounded px-1 font-mono text-xs",s)}),ul:({node:t,...s})=>e.jsx("ul",{...s,className:"list-disc pl-5"}),ol:({node:t,...s})=>e.jsx("ol",{...s,className:"list-decimal pl-5"}),blockquote:({node:t,...s})=>e.jsx("blockquote",{...s,className:"border-border text-muted-foreground border-l-2 pl-2"}),h1:({node:t,...s})=>e.jsx("h1",{...s,className:"text-base font-semibold"}),h2:({node:t,...s})=>e.jsx("h2",{...s,className:"text-sm font-semibold"}),h3:({node:t,...s})=>e.jsx("h3",{...s,className:"text-sm font-semibold"}),table:({node:t,...s})=>e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{...s,className:"border-border w-full border-collapse border text-xs"})}),th:({node:t,...s})=>e.jsx("th",{...s,className:"border-border bg-muted border px-2 py-1 text-left"}),td:({node:t,...s})=>e.jsx("td",{...s,className:"border-border border px-2 py-1"})},rt=N.memo(function({content:s}){return e.jsx(Fe,{remarkPlugins:[He],components:nt,children:s})});function at({text:t,streaming:s=!1,className:a}){const d=N.useMemo(()=>st(t),[t]);return e.jsxs("div",{className:C("flex min-w-0 flex-col gap-2 text-sm leading-relaxed",a),children:[d.map((o,i)=>e.jsx(rt,{content:o},i)),s&&e.jsx("span",{"data-testid":"agent-streaming-cursor",className:"bg-foreground inline-block h-4 w-2 animate-pulse self-start"})]})}function ot({text:t,streaming:s=!1,className:a}){return e.jsx("div",{"data-testid":"agent-assistant-message",className:C("min-w-0 max-w-full self-start",a),children:e.jsx(at,{text:t,streaming:s})})}function it({text:t,streaming:s=!1,className:a}){const{t:d}=k();return e.jsxs(Y,{"data-testid":"agent-reasoning-block",className:C("min-w-0 max-w-full self-start",a),children:[e.jsxs(ee,{className:"text-muted-foreground hover:text-foreground group flex items-center gap-1 text-xs",children:[e.jsx(te,{className:"size-3 transition-transform group-data-[panel-open]:rotate-90"}),e.jsx(Ge,{className:"size-3"}),e.jsx("span",{children:d("agent.reasoning.title")}),s&&e.jsx(se,{className:"size-3 animate-spin"})]}),e.jsx(ne,{children:e.jsx("div",{className:"text-muted-foreground border-border mt-1 border-l-2 pl-2 text-xs whitespace-pre-wrap break-words",children:t})})]})}function M(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function L(t){if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function dt(t){return M(t.output)&&typeof t.output.error=="string"?t.output.error:t.isError?L(t.output):null}function lt(t){switch(t){case"send_input":return e.jsx(Ke,{className:"size-3.5"});case"read_screen":return e.jsx(ve,{className:"size-3.5"});case"web_search":return e.jsx(Ve,{className:"size-3.5"});case"fetch_url":return e.jsx(be,{className:"size-3.5"});default:return e.jsx(tt,{className:"size-3.5"})}}function E({label:t,text:s}){return e.jsxs(Y,{children:[e.jsxs(ee,{className:"text-muted-foreground hover:text-foreground group flex items-center gap-1 text-xs",children:[e.jsx(te,{className:"size-3 transition-transform group-data-[panel-open]:rotate-90"}),e.jsx("span",{children:t})]}),e.jsx(ne,{children:e.jsx("pre",{className:"bg-muted mt-1 max-h-64 overflow-auto rounded-md p-2 font-mono text-xs whitespace-pre-wrap break-all",children:s})})]})}function ct(t){if(typeof t!="string")return null;try{const s=JSON.parse(t);return Array.isArray(s)?s.filter(M).map(a=>({title:typeof a.title=="string"?a.title:"",url:typeof a.url=="string"?a.url:"",snippet:typeof a.snippet=="string"?a.snippet:""})).filter(a=>a.url):null}catch{return null}}function ut({call:t}){const{t:s}=k(),a=M(t.input)?t.input:{},d=typeof a.text=="string"?a.text:"",o=Array.isArray(a.keys)?a.keys.filter(u=>typeof u=="string"):[],i=M(t.output)?t.output:{},l=typeof i.screenTail=="string"?i.screenTail:"";return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[d&&e.jsx("pre",{className:"bg-muted max-h-40 overflow-auto rounded-md p-2 font-mono text-xs whitespace-pre-wrap break-all",children:d}),o.length>0&&e.jsx("div",{className:"flex flex-wrap items-center gap-1",children:o.map((u,c)=>e.jsx(Ne,{variant:"outline",className:"font-mono",children:u},`${c}-${u}`))}),l&&e.jsx(E,{label:s("agent.tool.result"),text:l})]})}function xt({call:t}){const{t:s}=k(),a=M(t.output)?t.output:{},d=typeof a.screen=="string"?a.screen:"";return d?e.jsx(E,{label:s("agent.tool.screen"),text:d}):null}function mt({call:t}){const{t:s}=k(),a=M(t.input)?t.input:{},d=typeof a.query=="string"?a.query:"",o=t.resolved&&!t.isError&&!t.denied?ct(t.output):null;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[d&&e.jsxs("p",{className:"text-muted-foreground text-xs break-words",children:["“",d,"”"]}),o&&o.length>0&&e.jsx("ul",{className:"flex flex-col gap-1",children:o.map(i=>e.jsxs("li",{className:"min-w-0 text-xs",children:[e.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"text-primary block truncate underline underline-offset-2",title:i.title||i.url,children:i.title||i.url}),i.snippet&&e.jsx("p",{className:"text-muted-foreground line-clamp-2 break-words",children:i.snippet})]},i.url))}),t.resolved&&!t.isError&&!t.denied&&!o&&typeof t.output=="string"&&e.jsx(E,{label:s("agent.tool.result"),text:t.output})]})}function pt({call:t}){const{t:s}=k(),a=M(t.input)?t.input:{},d=typeof a.url=="string"?a.url:"",o=typeof t.output=="string"?t.output:"";return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[d&&e.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"text-primary block truncate text-xs underline underline-offset-2",title:d,children:d}),t.resolved&&!t.isError&&!t.denied&&o&&e.jsx(E,{label:s("agent.tool.result"),text:o})]})}const ft=/^[A-Za-z0-9+/]{256,}={0,2}$/,gt=/^https?:\/\/\S+\.(png|jpe?g|webp|gif)(\?\S*)?$/i;function ht(t){return typeof t!="string"||t.length===0?null:t.startsWith("data:image/")||gt.test(t)?t:ft.test(t.replace(/\s/g,""))?`data:image/png;base64,${t.replace(/\s/g,"")}`:null}function jt(t){if(!t.resolved||t.isError||t.denied)return[];const s=[],a=(d,o)=>{if(s.length>=8||o>3)return;const i=ht(d);if(i){s.push(i);return}if(Array.isArray(d)){for(const l of d)a(l,o+1);return}if(M(d))for(const l of["result","image","images","url","b64_json","data"])l in d&&a(d[l],o+1)};return a(t.output,0),[...new Set(s)]}function wt({images:t}){return t.length===0?null:e.jsx("div",{className:"flex flex-wrap gap-2",children:t.map((s,a)=>e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"block",children:e.jsx("img",{src:s,alt:"generated",className:"max-h-64 max-w-full rounded-md border border-border object-contain",loading:"lazy"})},a))})}function bt({call:t,hideOutput:s}){const{t:a}=k();return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.input!==void 0&&e.jsx(E,{label:a("agent.tool.input"),text:L(t.input)}),!s&&t.resolved&&!t.isError&&!t.denied&&t.output!==void 0&&e.jsx(E,{label:a("agent.tool.result"),text:L(t.output)})]})}function vt({call:t,confirmationId:s,onDecide:a,className:d}){const{t:o}=k(),i=!!s&&!t.resolved,l=t.resolved&&t.denied,u=t.resolved&&!l?dt(t):null,c=!t.resolved&&!i,j=l&&typeof t.output=="string"?t.output:"",h=`agent.tool.${t.toolName}`,p=["send_input","read_screen","web_search","fetch_url"].includes(t.toolName)?o(h):t.toolName,b=jt(t);return e.jsxs("div",{"data-testid":`agent-tool-card-${t.toolCallId}`,"data-tool-name":t.toolName,"data-tool-denied":l||void 0,className:C("border-border bg-card flex max-w-full min-w-0 flex-col gap-1.5 self-start rounded-lg border p-2",u!==null&&"border-destructive/50",l&&"opacity-80",d),children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium",children:[lt(t.toolName),e.jsx("span",{className:"min-w-0 truncate",children:p}),c&&e.jsx(se,{className:"text-muted-foreground size-3 animate-spin"}),t.resolved&&!l&&u===null&&e.jsx(F,{className:"size-3 text-emerald-500"}),u!==null&&e.jsx(B,{className:"text-destructive size-3"}),l&&e.jsxs("span",{className:"text-destructive flex items-center gap-0.5",children:[e.jsx(H,{className:"size-3"}),o("agent.tool.denied")]})]}),t.toolName==="send_input"&&e.jsx(ut,{call:t}),t.toolName==="read_screen"&&e.jsx(xt,{call:t}),t.toolName==="web_search"&&e.jsx(mt,{call:t}),t.toolName==="fetch_url"&&e.jsx(pt,{call:t}),!["send_input","read_screen","web_search","fetch_url"].includes(t.toolName)&&e.jsx(bt,{call:t,hideOutput:b.length>0}),e.jsx(wt,{images:b}),u!==null&&e.jsx("p",{className:"text-destructive text-xs break-words whitespace-pre-wrap",children:u}),j&&e.jsx("p",{className:"text-muted-foreground text-xs break-words whitespace-pre-wrap",children:j}),i&&s&&e.jsxs("div",{"data-testid":`agent-tool-approval-${t.toolCallId}`,className:"flex items-center gap-2 pt-1",children:[e.jsx("span",{className:"text-muted-foreground min-w-0 flex-1 text-xs",children:o("agent.confirm.title")}),e.jsxs(y,{"data-testid":"agent-confirm-approve",size:"xs",variant:"secondary",onClick:()=>a==null?void 0:a(s,!0),children:[e.jsx(F,{}),o("agent.confirm.approve")]}),e.jsxs(y,{"data-testid":"agent-confirm-deny",size:"xs",variant:"destructive",onClick:()=>a==null?void 0:a(s,!1),children:[e.jsx(H,{}),o("agent.confirm.deny")]})]})]})}function Nt({text:t,className:s}){return e.jsx("div",{"data-testid":"agent-user-message",className:C("bg-primary text-primary-foreground max-w-[85%] self-end rounded-2xl px-3 py-2 text-sm whitespace-pre-wrap break-words",s),children:t})}const yt=48;function kt(){return e.jsxs("div",{"data-testid":"agent-running-indicator",className:"flex items-center gap-1 self-start px-1",children:[e.jsx("span",{className:"bg-muted-foreground size-1.5 animate-pulse rounded-full"}),e.jsx("span",{className:"bg-muted-foreground size-1.5 animate-pulse rounded-full [animation-delay:150ms]"}),e.jsx("span",{className:"bg-muted-foreground size-1.5 animate-pulse rounded-full [animation-delay:300ms]"})]})}function It({blocks:t,running:s,emptyText:a,confirmationByToolCallId:d,onDecide:o,className:i}){const{t:l}=k(),u=N.useRef(null),c=N.useRef(!0),[j,h]=N.useState(!1),p=()=>{const x=u.current;x&&(x.scrollTop=x.scrollHeight,c.current=!0,h(!1))};N.useEffect(()=>{if(c.current){const x=u.current;x&&(x.scrollTop=x.scrollHeight)}else h(!0)},[t,s]);const b=()=>{const x=u.current;if(!x)return;const w=x.scrollHeight-x.scrollTop-x.clientHeight<yt;c.current=w,h(!w)};return t.length===0&&!s?e.jsx("div",{"data-testid":"agent-chat-thread",className:C("flex min-h-0 flex-1 items-center justify-center p-4",i),children:e.jsx("p",{className:"text-muted-foreground text-sm",children:a})}):e.jsxs("div",{className:C("relative min-h-0 flex-1",i),children:[e.jsx("div",{ref:u,"data-testid":"agent-chat-thread",className:"h-full overflow-y-auto p-3",onScroll:b,children:e.jsxs("div",{className:"flex flex-col gap-3",children:[t.map(x=>{switch(x.kind){case"user":return e.jsx(Nt,{text:x.text},x.key);case"assistant-text":return e.jsx(ot,{text:x.text,streaming:x.streaming},x.key);case"reasoning":return e.jsx(it,{text:x.text,streaming:x.streaming},x.key);case"tool-call":return e.jsx(vt,{call:x.call,confirmationId:d.get(x.call.toolCallId),onDecide:o},x.key);default:return null}}),s&&e.jsx(kt,{})]})}),j&&e.jsx(y,{"data-testid":"agent-scroll-to-bottom",size:"icon-sm",variant:"secondary",className:"absolute right-3 bottom-3 z-10 rounded-full shadow-md",onClick:p,"aria-label":l("agent.panel.scrollToBottom"),children:e.jsx(Oe,{})})]})}const O="::";function D(t,s){return`${t??""}${O}${s}`}function Ct(t){const s=t.indexOf(O);return s<0?{providerId:null,modelId:t}:{providerId:t.slice(0,s)||null,modelId:t.slice(s+O.length)}}function St({providerId:t,modelId:s,onChange:a,disabled:d,className:o}){var w;const{t:i}=k(),{data:l}=K({queryKey:["llm-providers"],queryFn:async()=>{const m=await fetch("/api/llm/providers");if(!m.ok)throw new Error("Failed to load providers");return await m.json()},throwOnError:!1}),{data:u}=K({queryKey:["llm-settings"],queryFn:async()=>{const m=await fetch("/api/llm/settings");if(!m.ok)throw new Error("Failed to load settings");return await m.json()},throwOnError:!1}),c=((l==null?void 0:l.providers)??[]).filter(m=>m.enabled&&m.models.length>0),j=t??(u==null?void 0:u.settings.defaultProviderId)??null,h=s??(u==null?void 0:u.settings.defaultModelId)??null,p=h?D(j,h):"",b=c.some(m=>m.id===j&&m.models.includes(h??"")),x=((w=c.find(m=>m.id===j))==null?void 0:w.name)??null,z=h?x?`${x}/${h}`:h:i("agent.model.placeholder");return e.jsxs(ye,{value:p,onValueChange:m=>{if(typeof m!="string"||!m)return;const n=Ct(m);a(n.providerId,n.modelId)},disabled:d||c.length===0,children:[e.jsx(ke,{size:"sm",className:C("h-7 w-full min-w-0 border-transparent bg-transparent text-muted-foreground text-xs hover:border-border/40 dark:bg-transparent dark:hover:bg-transparent",o),"data-testid":"agent-model-picker","aria-label":i("agent.model.select"),children:e.jsx("span",{className:"min-w-0 truncate",children:z})}),e.jsxs(Ie,{children:[!b&&h&&e.jsx(X,{value:p,className:"text-muted-foreground",children:h}),c.map(m=>e.jsxs(Ce,{children:[e.jsx(Se,{children:m.name}),m.models.map(n=>e.jsx(X,{value:D(m.id,n),children:n},`${m.id}:${n}`))]},m.id))]})]})}function Mt({queued:t,onEdit:s,onWithdraw:a,onSteer:d}){const{t:o}=k(),[i,l]=N.useState(null),[u,c]=N.useState("");if(t.length===0)return null;const j=p=>{l(p.id),c(p.text)},h=p=>{const b=u.trim();b&&s(p,b),l(null)};return e.jsxs("div",{"data-testid":"agent-queue",className:"bg-muted/50 mx-3 mb-2 flex shrink-0 flex-col gap-1.5 rounded-xl px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground text-xs font-medium",children:o("agent.queue.title",{count:t.length})}),e.jsxs(y,{"data-testid":"agent-queue-steer",size:"xs",variant:"outline",onClick:d,title:o("agent.queue.steerHint"),children:[e.jsx(ae,{}),o("agent.queue.steer")]})]}),e.jsx("ul",{className:"flex flex-col gap-1",children:t.map(p=>e.jsx("li",{"data-testid":`agent-queue-item-${p.id}`,className:"bg-background/60 flex items-start gap-1.5 rounded-lg px-2 py-1",children:i===p.id?e.jsxs(e.Fragment,{children:[e.jsx(re,{value:u,onChange:b=>c(b.target.value),onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),h(p.id)),b.key==="Escape"&&l(null)},rows:1,className:"max-h-32 min-h-7 flex-1 resize-none text-xs",autoFocus:!0}),e.jsx(y,{size:"icon-sm",variant:"ghost",onClick:()=>h(p.id),"aria-label":o("common.save"),children:e.jsx(F,{})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs",children:p.text}),e.jsx(y,{size:"icon-sm",variant:"ghost",onClick:()=>j(p),"aria-label":o("common.edit"),children:e.jsx(Me,{})}),e.jsx(y,{"data-testid":`agent-queue-withdraw-${p.id}`,size:"icon-sm",variant:"ghost",onClick:()=>a(p.id),"aria-label":o("agent.queue.withdraw"),children:e.jsx(H,{})})]})},p.id))})]})}function _t({onSend:t,onSteer:s,onStop:a,running:d,steerable:o,disabled:i,modelPicker:l,writeModeControl:u}){const{t:c}=k(),[j,h]=N.useState(""),p=g(w=>{var m;return((m=w.draft)==null?void 0:m.prompt)??null}),b=N.useRef(null);N.useEffect(()=>{p&&p!==b.current&&(b.current=p,h(p))},[p]);const x=()=>{const w=j.trim();!w||i||(t==null||t(w),h(""))},z=()=>{const w=j.trim();!w||i||(s==null||s(w),h(""))};return e.jsxs("div",{"data-testid":"agent-chat-input",className:"bg-chat-surface flex shrink-0 flex-col gap-2 mx-3 mb-2.5 rounded-xl mt-1.5 focus-within:ring-1 focus-within:ring-ring/30",children:[e.jsx(re,{"data-testid":"agent-chat-input-textarea",value:j,onChange:w=>h(w.target.value),onKeyDown:w=>{w.key==="Enter"&&!w.shiftKey&&!w.nativeEvent.isComposing&&(w.preventDefault(),x())},placeholder:c("agent.panel.inputPlaceholder"),disabled:i,className:"max-h-40 min-h-[4.5rem] w-full resize-none border-transparent bg-transparent p-3 text-[13px] shadow-none focus-visible:border-transparent focus-visible:ring-0 disabled:bg-transparent dark:bg-transparent dark:disabled:bg-transparent",rows:3}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 px-2.5 pb-2.5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[u,l&&e.jsx("div",{className:"min-w-0 flex-1",children:l})]}),d?e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[o&&e.jsx(y,{"data-testid":"agent-chat-steer",size:"icon",variant:"outline",disabled:i||j.trim().length===0,onClick:z,"aria-label":c("agent.queue.steer"),title:c("agent.queue.steerHint"),children:e.jsx(ae,{})}),e.jsx(y,{"data-testid":"agent-chat-send",size:"icon",variant:"secondary",disabled:i||j.trim().length===0,onClick:x,"aria-label":c("agent.panel.send"),children:e.jsx(Z,{})}),e.jsx(y,{"data-testid":"agent-chat-stop",size:"icon",variant:"destructive",onClick:()=>a==null?void 0:a(),"aria-label":c("agent.panel.stop"),children:e.jsx(Ze,{})})]}):e.jsx(y,{"data-testid":"agent-chat-send",size:"icon",className:"ml-auto shrink-0",disabled:i||j.trim().length===0,onClick:x,"aria-label":c("agent.panel.send"),children:e.jsx(Z,{})})]})]})}function zt(t,s,a){var i;if(!t.deviceId||!t.paneId)return null;const d=((i=a==null?void 0:a.find(l=>l.id===t.deviceId))==null?void 0:i.name)??null,o=s[t.deviceId];if(!(o!=null&&o.session))return{label:`${t.paneId}@${d??"?"}`,state:"unknown",windowId:null};for(const l of o.session.windows){const u=l.panes.find(c=>c.id===t.paneId);if(u)return{label:Ae({paneIdx:u.index,windowIdx:l.index,paneTitle:u.title,windowName:l.name,windowCustomName:l.customName,deviceName:d}),state:"valid",windowId:l.id}}return{label:`${t.paneId}@${d??"?"}`,state:"invalid",windowId:null}}function $t(){var J;const{t}=k(),s=_e(),a=ze(r=>r.setSidebarTab),d=Te("/devices/:deviceId/windows/:windowId/panes/:paneId"),o=(d==null?void 0:d.params.deviceId)??null,i=(d==null?void 0:d.params.paneId)??null,l=g(r=>r.sessions),u=g(r=>r.activeSessionId),c=g(r=>r.draft),j=g(r=>r.activeSessionId?r.messages[r.activeSessionId]:void 0),h=g(r=>r.activeSessionId?r.inProgress[r.activeSessionId]:void 0),p=g(r=>r.activeSessionId?r.pendingConfirmations[r.activeSessionId]:void 0),b=g(r=>r.activeSessionId?r.sending[r.activeSessionId]:void 0),x=g(r=>r.activeSessionId?r.queued[r.activeSessionId]:void 0),z=g(r=>r.defaultWriteMode),w=Ee(r=>r.snapshots),{data:m}=K({queryKey:["devices"],queryFn:async()=>{const r=await fetch("/api/devices");if(!r.ok)throw new Error("Failed to load devices");return r.json()},throwOnError:!1});N.useEffect(()=>{const r=g.getState();r.ensureInitialized(),r.loadSessions()},[]);const n=u?l[u]:void 0,q=N.useMemo(()=>{var f,S;if(!o||!i)return null;const r=(S=(f=w[o])==null?void 0:f.session)==null?void 0:S.windows;for(const I of r??[]){const V=I.panes.find(we=>we.id===i);if(V)return V.title??null}return null},[o,i,w]);N.useEffect(()=>{!n&&!c&&o&&i&&g.getState().startDraft(o,i,q)},[n,c,o,i,q]);const oe=N.useMemo(()=>{const r=new Map;for(const f of p??[])r.set(f.toolCallId,f.id);return r},[p]),ie=N.useMemo(()=>{const r=Be(j,h),f=new Set;for(const I of r)I.kind==="tool-call"&&f.add(I.call.toolCallId);const S=[];for(const I of p??[])f.has(I.toolCallId)||S.push({kind:"tool-call",key:`confirmation-${I.id}`,call:{toolCallId:I.toolCallId,toolName:I.toolName,input:I.input,isError:!1,denied:!1,resolved:!1}});return S.length>0?[...r,...S]:r},[j,h,p]),W=n??(c?{deviceId:c.deviceId,paneId:c.paneId}:null),v=W?zt(W,w,m==null?void 0:m.devices):null,de=!!(n&&i&&o&&(n.paneId!==i||n.deviceId!==o)),$=(n==null?void 0:n.status)==="running",G=qe(j),T=!!(n&&(!n.deviceId||!((J=m==null?void 0:m.devices)!=null&&J.some(r=>r.id===n.deviceId))||(v==null?void 0:v.state)==="invalid")),P=x??[],le=(r,f)=>{u&&g.getState().decideConfirmation(u,r,f)},Q=()=>{if(n!=null&&n.deviceId){if((v==null?void 0:v.state)==="valid"&&v.windowId&&n.paneId){s(`/devices/${n.deviceId}/windows/${v.windowId}/panes/${encodeURIComponent(n.paneId)}`);return}(v==null?void 0:v.state)==="unknown"&&s(`/devices/${n.deviceId}`)}},ce=()=>{!o||!i||g.getState().startDraft(o,i,q)},ue=(r,f)=>{n?g.getState().setSessionModel(n.id,r,f):c&&g.getState().updateDraft({providerId:r,modelId:f})},xe=r=>{const f=g.getState();if(n){n.status==="running"?f.enqueueMessage(n.id,r):f.sendMessage(n.id,r);return}c&&(async()=>{const S=await f.materializeDraft();S&&await f.sendMessage(S.id,r)})()},me=r=>{n&&g.getState().enqueueMessage(n.id,r,!0)},pe=()=>{if(!n)return;const r=P[0];if(!r)return;const f=g.getState();(async()=>(await f.withdrawQueuedMessage(n.id,r.id),await f.enqueueMessage(n.id,r.text,!0)))()},fe=n?n.providerId:(c==null?void 0:c.providerId)??null,ge=n?n.modelId:(c==null?void 0:c.modelId)??null,R=!!(n||c),A=!!(c&&!n),U=n?n.writeMode:z,he=!!(n&&((j==null?void 0:j.length)??0)>0),je=T||!R||(n==null?void 0:n.status)==="waiting_confirmation"||!!b;return e.jsxs("div",{"data-testid":"agent-tab",className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[v?e.jsxs("button",{type:"button","data-testid":"agent-binding-chip","data-binding-state":v.state,className:C("border-border flex min-w-0 items-center gap-1 rounded-full border px-2 py-0.5 text-xs",n&&v.state==="valid"?"hover:bg-muted cursor-pointer":"text-muted-foreground",v.state==="invalid"&&"opacity-60"),onClick:Q,disabled:!n||v.state==="invalid",children:[e.jsx(Ye,{className:"size-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:v.label}),v.state==="invalid"&&e.jsxs("span",{className:"shrink-0",children:["· ",t("agent.binding.invalid")]})]}):e.jsx("div",{className:"min-w-0 flex-1"}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-1",children:[e.jsx(y,{"data-testid":"agent-session-switch",size:"icon-sm",variant:"ghost",onClick:()=>a("panes"),"aria-label":t("agent.session.switch"),title:t("agent.session.switch"),children:e.jsx(Ue,{})}),he&&e.jsx(y,{"data-testid":"agent-session-new",size:"icon-sm",variant:"ghost",disabled:!o||!i,onClick:ce,"aria-label":t("agent.session.new"),title:t(!o||!i?"agent.session.selectPaneHint":"agent.session.new"),children:e.jsx($e,{})})]})]}),T&&e.jsxs("div",{"data-testid":"agent-orphan-banner",className:"bg-muted/50 text-muted-foreground mx-3 mb-1.5 flex shrink-0 items-start gap-2 rounded-lg px-2 py-1.5 text-xs",children:[e.jsx(B,{className:"mt-0.5 size-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:t("agent.orphan.readonly")})]}),n&&!T&&de&&e.jsxs("div",{"data-testid":"agent-pane-mismatch",className:"bg-muted/50 mx-3 mb-1.5 flex shrink-0 flex-wrap items-center gap-2 rounded-lg px-2 py-1.5 text-xs",children:[e.jsx(B,{className:"text-muted-foreground size-3.5 shrink-0"}),e.jsx("span",{className:"text-muted-foreground min-w-0 flex-1",children:t("agent.binding.mismatchTitle")}),(v==null?void 0:v.state)==="valid"&&e.jsx(y,{"data-testid":"agent-binding-goto",size:"xs",variant:"outline",onClick:Q,children:t("agent.binding.goTo")}),i&&e.jsx(y,{"data-testid":"agent-binding-rebind",size:"xs",variant:"outline",onClick:()=>{g.getState().rebindPane(n.id,i)},children:t("agent.binding.rebind")})]}),(n==null?void 0:n.status)==="error"&&n.lastError&&e.jsxs("div",{"data-testid":"agent-error-banner",className:"bg-destructive/10 text-destructive mx-3 mb-1.5 flex shrink-0 items-start gap-2 rounded-lg px-2 py-1.5 text-xs",children:[e.jsx(B,{className:"mt-0.5 size-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 break-words",children:n.lastError}),G&&!T&&e.jsx(y,{"data-testid":"agent-error-retry",size:"xs",variant:"outline",className:"shrink-0",disabled:!!b,onClick:()=>{g.getState().sendMessage(n.id,G)},children:t("agent.panel.retry")})]}),!A&&e.jsx(It,{blocks:n?ie:[],running:!!$,emptyText:t(R?"agent.panel.empty":"agent.session.selectPaneHint"),confirmationByToolCallId:oe,onDecide:le,className:"bg-chat-surface mx-3 mb-2 overflow-hidden rounded-xl"},(n==null?void 0:n.id)??(c?"draft":"none")),n&&!T&&P.length>0&&e.jsx(Mt,{queued:P,onEdit:(r,f)=>void g.getState().editQueuedMessage(n.id,r,f),onWithdraw:r=>void g.getState().withdrawQueuedMessage(n.id,r),onSteer:pe}),R&&e.jsxs("div",{className:A?"flex min-h-0 flex-1 flex-col justify-center":"contents",children:[A&&e.jsxs("div",{className:"flex flex-col items-center gap-2 px-6 pb-6 text-center",children:[e.jsx(Pe,{className:"text-muted-foreground size-9"}),e.jsx("h3",{className:"text-sm font-medium",children:t("agent.welcome.title")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("agent.welcome.subtitle")})]}),e.jsx(_t,{disabled:je,running:!!$,steerable:!!n,onSend:xe,onSteer:me,onStop:()=>{n&&g.getState().stopSession(n.id)},modelPicker:e.jsx(St,{providerId:fe,modelId:ge,onChange:ue,disabled:$}),writeModeControl:e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:t(U==="auto"?"agent.writeMode.auto":"agent.writeMode.confirm")}),e.jsx(Re,{"data-testid":"agent-write-mode-switch",checked:U==="auto",disabled:!!n&&T,onCheckedChange:r=>{const f=r?"auto":"confirm";g.getState().setDefaultWriteMode(f),n&&g.getState().setWriteMode(n.id,f)}})]})})]})]})}export{$t as AgentTab};
38
+ `);l.trim()&&a.push(l),d=[]};for(const l of s){if(/^\s*(```|~~~)/.test(l)){o=!o,d.push(l);continue}if(!o&&l.trim()===""){i();continue}d.push(l)}return i(),a}const nt={a:({node:t,...s})=>e.jsx("a",{...s,target:"_blank",rel:"noopener noreferrer",className:"text-primary underline underline-offset-2 break-all"}),pre:({node:t,...s})=>e.jsx("pre",{...s,className:"bg-muted overflow-x-auto rounded-md p-2 font-mono text-xs leading-relaxed"}),code:({node:t,className:s,...a})=>e.jsx("code",{...a,className:C("bg-muted rounded px-1 font-mono text-xs",s)}),ul:({node:t,...s})=>e.jsx("ul",{...s,className:"list-disc pl-5"}),ol:({node:t,...s})=>e.jsx("ol",{...s,className:"list-decimal pl-5"}),blockquote:({node:t,...s})=>e.jsx("blockquote",{...s,className:"border-border text-muted-foreground border-l-2 pl-2"}),h1:({node:t,...s})=>e.jsx("h1",{...s,className:"text-base font-semibold"}),h2:({node:t,...s})=>e.jsx("h2",{...s,className:"text-sm font-semibold"}),h3:({node:t,...s})=>e.jsx("h3",{...s,className:"text-sm font-semibold"}),table:({node:t,...s})=>e.jsx("div",{className:"overflow-x-auto",children:e.jsx("table",{...s,className:"border-border w-full border-collapse border text-xs"})}),th:({node:t,...s})=>e.jsx("th",{...s,className:"border-border bg-muted border px-2 py-1 text-left"}),td:({node:t,...s})=>e.jsx("td",{...s,className:"border-border border px-2 py-1"})},rt=N.memo(function({content:s}){return e.jsx(Fe,{remarkPlugins:[He],components:nt,children:s})});function at({text:t,streaming:s=!1,className:a}){const d=N.useMemo(()=>st(t),[t]);return e.jsxs("div",{className:C("flex min-w-0 flex-col gap-2 text-sm leading-relaxed",a),children:[d.map((o,i)=>e.jsx(rt,{content:o},i)),s&&e.jsx("span",{"data-testid":"agent-streaming-cursor",className:"bg-foreground inline-block h-4 w-2 animate-pulse self-start"})]})}function ot({text:t,streaming:s=!1,className:a}){return e.jsx("div",{"data-testid":"agent-assistant-message",className:C("min-w-0 max-w-full self-start",a),children:e.jsx(at,{text:t,streaming:s})})}function it({text:t,streaming:s=!1,className:a}){const{t:d}=k();return e.jsxs(Y,{"data-testid":"agent-reasoning-block",className:C("min-w-0 max-w-full self-start",a),children:[e.jsxs(ee,{className:"text-muted-foreground hover:text-foreground group flex items-center gap-1 text-xs",children:[e.jsx(te,{className:"size-3 transition-transform group-data-[panel-open]:rotate-90"}),e.jsx(Ge,{className:"size-3"}),e.jsx("span",{children:d("agent.reasoning.title")}),s&&e.jsx(se,{className:"size-3 animate-spin"})]}),e.jsx(ne,{children:e.jsx("div",{className:"text-muted-foreground border-border mt-1 border-l-2 pl-2 text-xs whitespace-pre-wrap break-words",children:t})})]})}function M(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function L(t){if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function dt(t){return M(t.output)&&typeof t.output.error=="string"?t.output.error:t.isError?L(t.output):null}function lt(t){switch(t){case"send_input":return e.jsx(Ke,{className:"size-3.5"});case"read_screen":return e.jsx(ve,{className:"size-3.5"});case"web_search":return e.jsx(Je,{className:"size-3.5"});case"fetch_url":return e.jsx(be,{className:"size-3.5"});default:return e.jsx(tt,{className:"size-3.5"})}}function E({label:t,text:s}){return e.jsxs(Y,{children:[e.jsxs(ee,{className:"text-muted-foreground hover:text-foreground group flex items-center gap-1 text-xs",children:[e.jsx(te,{className:"size-3 transition-transform group-data-[panel-open]:rotate-90"}),e.jsx("span",{children:t})]}),e.jsx(ne,{children:e.jsx("pre",{className:"bg-muted mt-1 max-h-64 overflow-auto rounded-md p-2 font-mono text-xs whitespace-pre-wrap break-all",children:s})})]})}function ct(t){if(typeof t!="string")return null;try{const s=JSON.parse(t);return Array.isArray(s)?s.filter(M).map(a=>({title:typeof a.title=="string"?a.title:"",url:typeof a.url=="string"?a.url:"",snippet:typeof a.snippet=="string"?a.snippet:""})).filter(a=>a.url):null}catch{return null}}function ut({call:t}){const{t:s}=k(),a=M(t.input)?t.input:{},d=typeof a.text=="string"?a.text:"",o=Array.isArray(a.keys)?a.keys.filter(u=>typeof u=="string"):[],i=M(t.output)?t.output:{},l=typeof i.screenTail=="string"?i.screenTail:"";return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[d&&e.jsx("pre",{className:"bg-muted max-h-40 overflow-auto rounded-md p-2 font-mono text-xs whitespace-pre-wrap break-all",children:d}),o.length>0&&e.jsx("div",{className:"flex flex-wrap items-center gap-1",children:o.map((u,c)=>e.jsx(Ne,{variant:"outline",className:"font-mono",children:u},`${c}-${u}`))}),l&&e.jsx(E,{label:s("agent.tool.result"),text:l})]})}function mt({call:t}){const{t:s}=k(),a=M(t.output)?t.output:{},d=typeof a.screen=="string"?a.screen:"";return d?e.jsx(E,{label:s("agent.tool.screen"),text:d}):null}function xt({call:t}){const{t:s}=k(),a=M(t.input)?t.input:{},d=typeof a.query=="string"?a.query:"",o=t.resolved&&!t.isError&&!t.denied?ct(t.output):null;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[d&&e.jsxs("p",{className:"text-muted-foreground text-xs break-words",children:["“",d,"”"]}),o&&o.length>0&&e.jsx("ul",{className:"flex flex-col gap-1",children:o.map(i=>e.jsxs("li",{className:"min-w-0 text-xs",children:[e.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"text-primary block truncate underline underline-offset-2",title:i.title||i.url,children:i.title||i.url}),i.snippet&&e.jsx("p",{className:"text-muted-foreground line-clamp-2 break-words",children:i.snippet})]},i.url))}),t.resolved&&!t.isError&&!t.denied&&!o&&typeof t.output=="string"&&e.jsx(E,{label:s("agent.tool.result"),text:t.output})]})}function pt({call:t}){const{t:s}=k(),a=M(t.input)?t.input:{},d=typeof a.url=="string"?a.url:"",o=typeof t.output=="string"?t.output:"";return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[d&&e.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"text-primary block truncate text-xs underline underline-offset-2",title:d,children:d}),t.resolved&&!t.isError&&!t.denied&&o&&e.jsx(E,{label:s("agent.tool.result"),text:o})]})}const ft=/^[A-Za-z0-9+/]{256,}={0,2}$/,gt=/^https?:\/\/\S+\.(png|jpe?g|webp|gif)(\?\S*)?$/i;function ht(t){return typeof t!="string"||t.length===0?null:t.startsWith("data:image/")||gt.test(t)?t:ft.test(t.replace(/\s/g,""))?`data:image/png;base64,${t.replace(/\s/g,"")}`:null}function jt(t){if(!t.resolved||t.isError||t.denied)return[];const s=[],a=(d,o)=>{if(s.length>=8||o>3)return;const i=ht(d);if(i){s.push(i);return}if(Array.isArray(d)){for(const l of d)a(l,o+1);return}if(M(d))for(const l of["result","image","images","url","b64_json","data"])l in d&&a(d[l],o+1)};return a(t.output,0),[...new Set(s)]}function wt({images:t}){return t.length===0?null:e.jsx("div",{className:"flex flex-wrap gap-2",children:t.map((s,a)=>e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"block",children:e.jsx("img",{src:s,alt:"generated",className:"max-h-64 max-w-full rounded-md border border-border object-contain",loading:"lazy"})},a))})}function bt({call:t,hideOutput:s}){const{t:a}=k();return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.input!==void 0&&e.jsx(E,{label:a("agent.tool.input"),text:L(t.input)}),!s&&t.resolved&&!t.isError&&!t.denied&&t.output!==void 0&&e.jsx(E,{label:a("agent.tool.result"),text:L(t.output)})]})}function vt({call:t,confirmationId:s,onDecide:a,className:d}){const{t:o}=k(),i=!!s&&!t.resolved,l=t.resolved&&t.denied,u=t.resolved&&!l?dt(t):null,c=!t.resolved&&!i,j=l&&typeof t.output=="string"?t.output:"",h=`agent.tool.${t.toolName}`,p=["send_input","read_screen","web_search","fetch_url"].includes(t.toolName)?o(h):t.toolName,b=jt(t);return e.jsxs("div",{"data-testid":`agent-tool-card-${t.toolCallId}`,"data-tool-name":t.toolName,"data-tool-denied":l||void 0,className:C("border-border bg-card flex max-w-full min-w-0 flex-col gap-1.5 self-start rounded-lg border p-2",u!==null&&"border-destructive/50",l&&"opacity-80",d),children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium",children:[lt(t.toolName),e.jsx("span",{className:"min-w-0 truncate",children:p}),c&&e.jsx(se,{className:"text-muted-foreground size-3 animate-spin"}),t.resolved&&!l&&u===null&&e.jsx(F,{className:"size-3 text-emerald-500"}),u!==null&&e.jsx(B,{className:"text-destructive size-3"}),l&&e.jsxs("span",{className:"text-destructive flex items-center gap-0.5",children:[e.jsx(H,{className:"size-3"}),o("agent.tool.denied")]})]}),t.toolName==="send_input"&&e.jsx(ut,{call:t}),t.toolName==="read_screen"&&e.jsx(mt,{call:t}),t.toolName==="web_search"&&e.jsx(xt,{call:t}),t.toolName==="fetch_url"&&e.jsx(pt,{call:t}),!["send_input","read_screen","web_search","fetch_url"].includes(t.toolName)&&e.jsx(bt,{call:t,hideOutput:b.length>0}),e.jsx(wt,{images:b}),u!==null&&e.jsx("p",{className:"text-destructive text-xs break-words whitespace-pre-wrap",children:u}),j&&e.jsx("p",{className:"text-muted-foreground text-xs break-words whitespace-pre-wrap",children:j}),i&&s&&e.jsxs("div",{"data-testid":`agent-tool-approval-${t.toolCallId}`,className:"flex items-center gap-2 pt-1",children:[e.jsx("span",{className:"text-muted-foreground min-w-0 flex-1 text-xs",children:o("agent.confirm.title")}),e.jsxs(y,{"data-testid":"agent-confirm-approve",size:"xs",variant:"secondary",onClick:()=>a==null?void 0:a(s,!0),children:[e.jsx(F,{}),o("agent.confirm.approve")]}),e.jsxs(y,{"data-testid":"agent-confirm-deny",size:"xs",variant:"destructive",onClick:()=>a==null?void 0:a(s,!1),children:[e.jsx(H,{}),o("agent.confirm.deny")]})]})]})}function Nt({text:t,className:s}){return e.jsx("div",{"data-testid":"agent-user-message",className:C("bg-primary text-primary-foreground max-w-[85%] self-end rounded-2xl px-3 py-2 text-sm whitespace-pre-wrap break-words",s),children:t})}const yt=48;function kt(){return e.jsxs("div",{"data-testid":"agent-running-indicator",className:"flex items-center gap-1 self-start px-1",children:[e.jsx("span",{className:"bg-muted-foreground size-1.5 animate-pulse rounded-full"}),e.jsx("span",{className:"bg-muted-foreground size-1.5 animate-pulse rounded-full [animation-delay:150ms]"}),e.jsx("span",{className:"bg-muted-foreground size-1.5 animate-pulse rounded-full [animation-delay:300ms]"})]})}function It({blocks:t,running:s,emptyText:a,confirmationByToolCallId:d,onDecide:o,className:i}){const{t:l}=k(),u=N.useRef(null),c=N.useRef(!0),[j,h]=N.useState(!1),p=()=>{const m=u.current;m&&(m.scrollTop=m.scrollHeight,c.current=!0,h(!1))};N.useEffect(()=>{if(c.current){const m=u.current;m&&(m.scrollTop=m.scrollHeight)}else h(!0)},[t,s]);const b=()=>{const m=u.current;if(!m)return;const w=m.scrollHeight-m.scrollTop-m.clientHeight<yt;c.current=w,h(!w)};return t.length===0&&!s?e.jsx("div",{"data-testid":"agent-chat-thread",className:C("flex min-h-0 flex-1 items-center justify-center p-4",i),children:e.jsx("p",{className:"text-muted-foreground text-sm",children:a})}):e.jsxs("div",{className:C("relative min-h-0 flex-1",i),children:[e.jsx("div",{ref:u,"data-testid":"agent-chat-thread",className:"h-full overflow-y-auto p-3",onScroll:b,children:e.jsxs("div",{className:"flex flex-col gap-3",children:[t.map(m=>{switch(m.kind){case"user":return e.jsx(Nt,{text:m.text},m.key);case"assistant-text":return e.jsx(ot,{text:m.text,streaming:m.streaming},m.key);case"reasoning":return e.jsx(it,{text:m.text,streaming:m.streaming},m.key);case"tool-call":return e.jsx(vt,{call:m.call,confirmationId:d.get(m.call.toolCallId),onDecide:o},m.key);default:return null}}),s&&e.jsx(kt,{})]})}),j&&e.jsx(y,{"data-testid":"agent-scroll-to-bottom",size:"icon-sm",variant:"secondary",className:"absolute right-3 bottom-3 z-10 rounded-full shadow-md",onClick:p,"aria-label":l("agent.panel.scrollToBottom"),children:e.jsx(Oe,{})})]})}const O="::";function D(t,s){return`${t??""}${O}${s}`}function Ct(t){const s=t.indexOf(O);return s<0?{providerId:null,modelId:t}:{providerId:t.slice(0,s)||null,modelId:t.slice(s+O.length)}}function St({providerId:t,modelId:s,onChange:a,disabled:d,className:o}){var w;const{t:i}=k(),{data:l}=K({queryKey:["llm-providers"],queryFn:async()=>{const x=await fetch("/api/llm/providers");if(!x.ok)throw new Error("Failed to load providers");return await x.json()},throwOnError:!1}),{data:u}=K({queryKey:["llm-settings"],queryFn:async()=>{const x=await fetch("/api/llm/settings");if(!x.ok)throw new Error("Failed to load settings");return await x.json()},throwOnError:!1}),c=((l==null?void 0:l.providers)??[]).filter(x=>x.enabled&&x.models.length>0),j=t??(u==null?void 0:u.settings.defaultProviderId)??null,h=s??(u==null?void 0:u.settings.defaultModelId)??null,p=h?D(j,h):"",b=c.some(x=>x.id===j&&x.models.includes(h??"")),m=((w=c.find(x=>x.id===j))==null?void 0:w.name)??null,z=h?m?`${m}/${h}`:h:i("agent.model.placeholder");return e.jsxs(ye,{value:p,onValueChange:x=>{if(typeof x!="string"||!x)return;const n=Ct(x);a(n.providerId,n.modelId)},disabled:d||c.length===0,children:[e.jsx(ke,{size:"sm",className:C("h-7 w-full min-w-0 border-transparent bg-transparent text-muted-foreground text-xs hover:border-border/40 dark:bg-transparent dark:hover:bg-transparent",o),"data-testid":"agent-model-picker","aria-label":i("agent.model.select"),children:e.jsx("span",{className:"min-w-0 truncate",children:z})}),e.jsxs(Ie,{children:[!b&&h&&e.jsx(X,{value:p,className:"text-muted-foreground",children:h}),c.map(x=>e.jsxs(Ce,{children:[e.jsx(Se,{children:x.name}),x.models.map(n=>e.jsx(X,{value:D(x.id,n),children:n},`${x.id}:${n}`))]},x.id))]})]})}function Mt({queued:t,onEdit:s,onWithdraw:a,onSteer:d}){const{t:o}=k(),[i,l]=N.useState(null),[u,c]=N.useState("");if(t.length===0)return null;const j=p=>{l(p.id),c(p.text)},h=p=>{const b=u.trim();b&&s(p,b),l(null)};return e.jsxs("div",{"data-testid":"agent-queue",className:"bg-muted/50 mx-3 mb-2 flex shrink-0 flex-col gap-1.5 rounded-xl px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground text-xs font-medium",children:o("agent.queue.title",{count:t.length})}),e.jsxs(y,{"data-testid":"agent-queue-steer",size:"xs",variant:"outline",onClick:d,title:o("agent.queue.steerHint"),children:[e.jsx(ae,{}),o("agent.queue.steer")]})]}),e.jsx("ul",{className:"flex flex-col gap-1",children:t.map(p=>e.jsx("li",{"data-testid":`agent-queue-item-${p.id}`,className:"bg-background/60 flex items-start gap-1.5 rounded-lg px-2 py-1",children:i===p.id?e.jsxs(e.Fragment,{children:[e.jsx(re,{value:u,onChange:b=>c(b.target.value),onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),h(p.id)),b.key==="Escape"&&l(null)},rows:1,className:"max-h-32 min-h-7 flex-1 resize-none text-xs",autoFocus:!0}),e.jsx(y,{size:"icon-sm",variant:"ghost",onClick:()=>h(p.id),"aria-label":o("common.save"),children:e.jsx(F,{})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs",children:p.text}),e.jsx(y,{size:"icon-sm",variant:"ghost",onClick:()=>j(p),"aria-label":o("common.edit"),children:e.jsx(Me,{})}),e.jsx(y,{"data-testid":`agent-queue-withdraw-${p.id}`,size:"icon-sm",variant:"ghost",onClick:()=>a(p.id),"aria-label":o("agent.queue.withdraw"),children:e.jsx(H,{})})]})},p.id))})]})}function _t({onSend:t,onSteer:s,onStop:a,running:d,steerable:o,disabled:i,modelPicker:l,writeModeControl:u}){const{t:c}=k(),[j,h]=N.useState(""),p=g(w=>{var x;return((x=w.draft)==null?void 0:x.prompt)??null}),b=N.useRef(null);N.useEffect(()=>{p&&p!==b.current&&(b.current=p,h(p))},[p]);const m=()=>{const w=j.trim();!w||i||(t==null||t(w),h(""))},z=()=>{const w=j.trim();!w||i||(s==null||s(w),h(""))};return e.jsxs("div",{"data-testid":"agent-chat-input",className:"bg-chat-surface flex shrink-0 flex-col gap-2 mx-3 mb-2.5 rounded-xl mt-1.5 focus-within:ring-1 focus-within:ring-ring/30",children:[e.jsx(re,{"data-testid":"agent-chat-input-textarea",value:j,onChange:w=>h(w.target.value),onKeyDown:w=>{w.key==="Enter"&&!w.shiftKey&&!w.nativeEvent.isComposing&&(w.preventDefault(),m())},placeholder:c("agent.panel.inputPlaceholder"),disabled:i,className:"max-h-40 min-h-[4.5rem] w-full resize-none border-transparent bg-transparent p-3 text-[13px] shadow-none focus-visible:border-transparent focus-visible:ring-0 disabled:bg-transparent dark:bg-transparent dark:disabled:bg-transparent",rows:3}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 px-2.5 pb-2.5",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[u,l&&e.jsx("div",{className:"min-w-0 flex-1",children:l})]}),d?e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[o&&e.jsx(y,{"data-testid":"agent-chat-steer",size:"icon",variant:"outline",disabled:i||j.trim().length===0,onClick:z,"aria-label":c("agent.queue.steer"),title:c("agent.queue.steerHint"),children:e.jsx(ae,{})}),e.jsx(y,{"data-testid":"agent-chat-send",size:"icon",variant:"secondary",disabled:i||j.trim().length===0,onClick:m,"aria-label":c("agent.panel.send"),children:e.jsx(Z,{})}),e.jsx(y,{"data-testid":"agent-chat-stop",size:"icon",variant:"destructive",onClick:()=>a==null?void 0:a(),"aria-label":c("agent.panel.stop"),children:e.jsx(Ze,{})})]}):e.jsx(y,{"data-testid":"agent-chat-send",size:"icon",className:"ml-auto shrink-0",disabled:i||j.trim().length===0,onClick:m,"aria-label":c("agent.panel.send"),children:e.jsx(Z,{})})]})]})}function zt(t,s,a){var i;if(!t.deviceId||!t.paneId)return null;const d=((i=a==null?void 0:a.find(l=>l.id===t.deviceId))==null?void 0:i.name)??null,o=s[t.deviceId];if(!(o!=null&&o.session))return{label:`${t.paneId}@${d??"?"}`,state:"unknown",windowId:null};for(const l of o.session.windows){const u=l.panes.find(c=>c.id===t.paneId);if(u)return{label:Re({paneCustomName:u.customName,paneTitle:u.title,windowName:l.name,windowCustomName:l.customName,deviceName:d}),state:"valid",windowId:l.id}}return{label:`${t.paneId}@${d??"?"}`,state:"invalid",windowId:null}}function $t(){var V;const{t}=k(),s=_e(),a=ze(r=>r.setSidebarTab),d=Te("/devices/:deviceId/windows/:windowId/panes/:paneId"),o=(d==null?void 0:d.params.deviceId)??null,i=(d==null?void 0:d.params.paneId)??null,l=g(r=>r.sessions),u=g(r=>r.activeSessionId),c=g(r=>r.draft),j=g(r=>r.activeSessionId?r.messages[r.activeSessionId]:void 0),h=g(r=>r.activeSessionId?r.inProgress[r.activeSessionId]:void 0),p=g(r=>r.activeSessionId?r.pendingConfirmations[r.activeSessionId]:void 0),b=g(r=>r.activeSessionId?r.sending[r.activeSessionId]:void 0),m=g(r=>r.activeSessionId?r.queued[r.activeSessionId]:void 0),z=g(r=>r.defaultWriteMode),w=Ee(r=>r.snapshots),{data:x}=K({queryKey:["devices"],queryFn:async()=>{const r=await fetch("/api/devices");if(!r.ok)throw new Error("Failed to load devices");return r.json()},throwOnError:!1});N.useEffect(()=>{const r=g.getState();r.ensureInitialized(),r.loadSessions()},[]);const n=u?l[u]:void 0,q=N.useMemo(()=>{var f,S;if(!o||!i)return null;const r=(S=(f=w[o])==null?void 0:f.session)==null?void 0:S.windows;for(const I of r??[]){const J=I.panes.find(we=>we.id===i);if(J)return J.title??null}return null},[o,i,w]);N.useEffect(()=>{!n&&!c&&o&&i&&g.getState().startDraft(o,i,q)},[n,c,o,i,q]);const oe=N.useMemo(()=>{const r=new Map;for(const f of p??[])r.set(f.toolCallId,f.id);return r},[p]),ie=N.useMemo(()=>{const r=Be(j,h),f=new Set;for(const I of r)I.kind==="tool-call"&&f.add(I.call.toolCallId);const S=[];for(const I of p??[])f.has(I.toolCallId)||S.push({kind:"tool-call",key:`confirmation-${I.id}`,call:{toolCallId:I.toolCallId,toolName:I.toolName,input:I.input,isError:!1,denied:!1,resolved:!1}});return S.length>0?[...r,...S]:r},[j,h,p]),W=n??(c?{deviceId:c.deviceId,paneId:c.paneId}:null),v=W?zt(W,w,x==null?void 0:x.devices):null,de=!!(n&&i&&o&&(n.paneId!==i||n.deviceId!==o)),$=(n==null?void 0:n.status)==="running",G=qe(j),T=!!(n&&(!n.deviceId||!((V=x==null?void 0:x.devices)!=null&&V.some(r=>r.id===n.deviceId))||(v==null?void 0:v.state)==="invalid")),P=m??[],le=(r,f)=>{u&&g.getState().decideConfirmation(u,r,f)},U=()=>{if(n!=null&&n.deviceId){if((v==null?void 0:v.state)==="valid"&&v.windowId&&n.paneId){s(`/devices/${n.deviceId}/windows/${v.windowId}/panes/${encodeURIComponent(n.paneId)}`);return}(v==null?void 0:v.state)==="unknown"&&s(`/devices/${n.deviceId}`)}},ce=()=>{!o||!i||g.getState().startDraft(o,i,q)},ue=(r,f)=>{n?g.getState().setSessionModel(n.id,r,f):c&&g.getState().updateDraft({providerId:r,modelId:f})},me=r=>{const f=g.getState();if(n){n.status==="running"?f.enqueueMessage(n.id,r):f.sendMessage(n.id,r);return}c&&(async()=>{const S=await f.materializeDraft();S&&await f.sendMessage(S.id,r)})()},xe=r=>{n&&g.getState().enqueueMessage(n.id,r,!0)},pe=()=>{if(!n)return;const r=P[0];if(!r)return;const f=g.getState();(async()=>(await f.withdrawQueuedMessage(n.id,r.id),await f.enqueueMessage(n.id,r.text,!0)))()},fe=n?n.providerId:(c==null?void 0:c.providerId)??null,ge=n?n.modelId:(c==null?void 0:c.modelId)??null,A=!!(n||c),R=!!(c&&!n),Q=n?n.writeMode:z,he=!!(n&&((j==null?void 0:j.length)??0)>0),je=T||!A||(n==null?void 0:n.status)==="waiting_confirmation"||!!b;return e.jsxs("div",{"data-testid":"agent-tab",className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 px-3 py-2",children:[v?e.jsxs("button",{type:"button","data-testid":"agent-binding-chip","data-binding-state":v.state,className:C("border-border flex min-w-0 items-center gap-1 rounded-full border px-2 py-0.5 text-xs",n&&v.state==="valid"?"hover:bg-muted cursor-pointer":"text-muted-foreground",v.state==="invalid"&&"opacity-60"),onClick:U,disabled:!n||v.state==="invalid",children:[e.jsx(Ye,{className:"size-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:v.label}),v.state==="invalid"&&e.jsxs("span",{className:"shrink-0",children:["· ",t("agent.binding.invalid")]})]}):e.jsx("div",{className:"min-w-0 flex-1"}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-1",children:[e.jsx(y,{"data-testid":"agent-session-switch",size:"icon-sm",variant:"ghost",onClick:()=>a("panes"),"aria-label":t("agent.session.switch"),title:t("agent.session.switch"),children:e.jsx(Qe,{})}),he&&e.jsx(y,{"data-testid":"agent-session-new",size:"icon-sm",variant:"ghost",disabled:!o||!i,onClick:ce,"aria-label":t("agent.session.new"),title:t(!o||!i?"agent.session.selectPaneHint":"agent.session.new"),children:e.jsx($e,{})})]})]}),T&&e.jsxs("div",{"data-testid":"agent-orphan-banner",className:"bg-muted/50 text-muted-foreground mx-3 mb-1.5 flex shrink-0 items-start gap-2 rounded-lg px-2 py-1.5 text-xs",children:[e.jsx(B,{className:"mt-0.5 size-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:t("agent.orphan.readonly")})]}),n&&!T&&de&&e.jsxs("div",{"data-testid":"agent-pane-mismatch",className:"bg-muted/50 mx-3 mb-1.5 flex shrink-0 flex-wrap items-center gap-2 rounded-lg px-2 py-1.5 text-xs",children:[e.jsx(B,{className:"text-muted-foreground size-3.5 shrink-0"}),e.jsx("span",{className:"text-muted-foreground min-w-0 flex-1",children:t("agent.binding.mismatchTitle")}),(v==null?void 0:v.state)==="valid"&&e.jsx(y,{"data-testid":"agent-binding-goto",size:"xs",variant:"outline",onClick:U,children:t("agent.binding.goTo")}),i&&e.jsx(y,{"data-testid":"agent-binding-rebind",size:"xs",variant:"outline",onClick:()=>{g.getState().rebindPane(n.id,i)},children:t("agent.binding.rebind")})]}),(n==null?void 0:n.status)==="error"&&n.lastError&&e.jsxs("div",{"data-testid":"agent-error-banner",className:"bg-destructive/10 text-destructive mx-3 mb-1.5 flex shrink-0 items-start gap-2 rounded-lg px-2 py-1.5 text-xs",children:[e.jsx(B,{className:"mt-0.5 size-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 break-words",children:n.lastError}),G&&!T&&e.jsx(y,{"data-testid":"agent-error-retry",size:"xs",variant:"outline",className:"shrink-0",disabled:!!b,onClick:()=>{g.getState().sendMessage(n.id,G)},children:t("agent.panel.retry")})]}),!R&&e.jsx(It,{blocks:n?ie:[],running:!!$,emptyText:t(A?"agent.panel.empty":"agent.session.selectPaneHint"),confirmationByToolCallId:oe,onDecide:le,className:"bg-chat-surface mx-3 mb-2 overflow-hidden rounded-xl"},(n==null?void 0:n.id)??(c?"draft":"none")),n&&!T&&P.length>0&&e.jsx(Mt,{queued:P,onEdit:(r,f)=>void g.getState().editQueuedMessage(n.id,r,f),onWithdraw:r=>void g.getState().withdrawQueuedMessage(n.id,r),onSteer:pe}),A&&e.jsxs("div",{className:R?"flex min-h-0 flex-1 flex-col justify-center":"contents",children:[R&&e.jsxs("div",{className:"flex flex-col items-center gap-2 px-6 pb-6 text-center",children:[e.jsx(Pe,{className:"text-muted-foreground size-9"}),e.jsx("h3",{className:"text-sm font-medium",children:t("agent.welcome.title")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("agent.welcome.subtitle")})]}),e.jsx(_t,{disabled:je,running:!!$,steerable:!!n,onSend:me,onSteer:xe,onStop:()=>{n&&g.getState().stopSession(n.id)},modelPicker:e.jsx(St,{providerId:fe,modelId:ge,onChange:ue,disabled:$}),writeModeControl:e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:t(Q==="auto"?"agent.writeMode.auto":"agent.writeMode.confirm")}),e.jsx(Ae,{"data-testid":"agent-write-mode-switch",checked:Q==="auto",disabled:!!n&&T,onCheckedChange:r=>{const f=r?"auto":"confirm";g.getState().setDefaultWriteMode(f),n&&g.getState().setWriteMode(n.id,f)}})]})})]})]})}export{$t as AgentTab};
@@ -1,4 +1,4 @@
1
- var N=Object.defineProperty;var P=(t,e,o)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var O=(t,e,o)=>P(t,typeof e!="symbol"?e+"":e,o);import{Y as x}from"./index-CEPc0i5O.js";/**
1
+ var N=Object.defineProperty;var P=(t,e,o)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var O=(t,e,o)=>P(t,typeof e!="symbol"?e+"":e,o);import{Y as x}from"./index-BK6c5W5S.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{a0 as ln,a1 as an,a2 as H,a3 as q,a4 as B,a5 as un,a6 as y,a7 as tn,a8 as L,a9 as _,aa as rn,ab as o,ac as on,ad as sn,ae as fn}from"./mermaid.core-DE3GlZm2.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,C,a){var O=I-l,i=D-h,n=C-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function W(l,h,I,D,v,A,C){var a=l-I,O=h-D,i=(C?A:-A)/L(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,F=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*L(on(0,T*T*R-P*P)),j=(P*g-m*S)/R,z=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=j-F,e=z-t,r=w-F,G=p-t;return x*x+e*e>r*r+G*G&&(j=w,z=p),{cx:j,cy:z,x01:-n,y01:-d,x11:j*(v/T-1),y11:z*(v/T-1)}}function hn(){var l=cn,h=yn,I=B(0),D=null,v=gn,A=dn,C=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,F=rn(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(F>tn-y)a.moveTo(s*H(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*H(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=F,S=F,j=C.apply(this,arguments)/2,z=j>y&&(D?+D.apply(this,arguments):L(u*u+s*s)),w=_(rn(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if(z>y){var G=sn(z/u*q(j)),M=sn(z/s*q(j));(P-=G*2)>y?(G*=t?1:-1,R+=G,T-=G):(P=0,R=T=(f+c)/2),(S-=M*2)>y?(M*=t?1:-1,m+=M,g-=M):(S=0,m=g=(f+c)/2)}var J=s*H(m),K=s*q(m),N=u*H(T),Q=u*q(T);if(w>y){var U=s*H(g),V=s*q(g),X=u*H(R),Y=u*q(R),E;if(F<an)if(E=pn(J,K,X,Y,U,V,N,Q)){var Z=J-E[0],$=K-E[1],b=U-E[0],k=V-E[1],nn=1/q(fn((Z*b+$*k)/(L(Z*Z+$*$)*L(b*b+k*k)))/2),en=L(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=W(X,Y,J,K,s,x,t),r=W(U,V,N,Q,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(J,K),a.arc(0,0,s,m,g,!t)):a.moveTo(J,K),!(u>y)||!(P>y)?a.lineTo(N,Q):p>y?(e=W(N,Q,U,V,u,-p,t),r=W(J,K,X,Y,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[H(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:B(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:B(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:B(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:B(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:B(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:B(+n),i):A},i.padAngle=function(n){return arguments.length?(C=typeof n=="function"?n:B(+n),i):C},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};
1
+ import{a0 as ln,a1 as an,a2 as H,a3 as q,a4 as B,a5 as un,a6 as y,a7 as tn,a8 as L,a9 as _,aa as rn,ab as o,ac as on,ad as sn,ae as fn}from"./mermaid.core-CXD-Pc2r.js";function cn(l){return l.innerRadius}function yn(l){return l.outerRadius}function gn(l){return l.startAngle}function dn(l){return l.endAngle}function mn(l){return l&&l.padAngle}function pn(l,h,I,D,v,A,C,a){var O=I-l,i=D-h,n=C-v,d=a-A,u=d*O-n*i;if(!(u*u<y))return u=(n*(h-A)-d*(l-v))/u,[l+u*O,h+u*i]}function W(l,h,I,D,v,A,C){var a=l-I,O=h-D,i=(C?A:-A)/L(a*a+O*O),n=i*O,d=-i*a,u=l+n,s=h+d,f=I+n,c=D+d,F=(u+f)/2,t=(s+c)/2,m=f-u,g=c-s,R=m*m+g*g,T=v-A,P=u*c-f*s,S=(g<0?-1:1)*L(on(0,T*T*R-P*P)),j=(P*g-m*S)/R,z=(-P*m-g*S)/R,w=(P*g+m*S)/R,p=(-P*m+g*S)/R,x=j-F,e=z-t,r=w-F,G=p-t;return x*x+e*e>r*r+G*G&&(j=w,z=p),{cx:j,cy:z,x01:-n,y01:-d,x11:j*(v/T-1),y11:z*(v/T-1)}}function hn(){var l=cn,h=yn,I=B(0),D=null,v=gn,A=dn,C=mn,a=null,O=ln(i);function i(){var n,d,u=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-un,c=A.apply(this,arguments)-un,F=rn(c-f),t=c>f;if(a||(a=n=O()),s<u&&(d=s,s=u,u=d),!(s>y))a.moveTo(0,0);else if(F>tn-y)a.moveTo(s*H(f),s*q(f)),a.arc(0,0,s,f,c,!t),u>y&&(a.moveTo(u*H(c),u*q(c)),a.arc(0,0,u,c,f,t));else{var m=f,g=c,R=f,T=c,P=F,S=F,j=C.apply(this,arguments)/2,z=j>y&&(D?+D.apply(this,arguments):L(u*u+s*s)),w=_(rn(s-u)/2,+I.apply(this,arguments)),p=w,x=w,e,r;if(z>y){var G=sn(z/u*q(j)),M=sn(z/s*q(j));(P-=G*2)>y?(G*=t?1:-1,R+=G,T-=G):(P=0,R=T=(f+c)/2),(S-=M*2)>y?(M*=t?1:-1,m+=M,g-=M):(S=0,m=g=(f+c)/2)}var J=s*H(m),K=s*q(m),N=u*H(T),Q=u*q(T);if(w>y){var U=s*H(g),V=s*q(g),X=u*H(R),Y=u*q(R),E;if(F<an)if(E=pn(J,K,X,Y,U,V,N,Q)){var Z=J-E[0],$=K-E[1],b=U-E[0],k=V-E[1],nn=1/q(fn((Z*b+$*k)/(L(Z*Z+$*$)*L(b*b+k*k)))/2),en=L(E[0]*E[0]+E[1]*E[1]);p=_(w,(u-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else p=x=0}S>y?x>y?(e=W(X,Y,J,K,s,x,t),r=W(U,V,N,Q,s,x,t),a.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),a.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(a.moveTo(J,K),a.arc(0,0,s,m,g,!t)):a.moveTo(J,K),!(u>y)||!(P>y)?a.lineTo(N,Q):p>y?(e=W(N,Q,U,V,u,-p,t),r=W(J,K,X,Y,u,-p,t),a.lineTo(e.cx+e.x01,e.cy+e.y01),p<w?a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(r.y01,r.x01),!t):(a.arc(e.cx,e.cy,p,o(e.y01,e.x01),o(e.y11,e.x11),!t),a.arc(0,0,u,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),a.arc(r.cx,r.cy,p,o(r.y11,r.x11),o(r.y01,r.x01),!t))):a.arc(0,0,u,T,R,t)}if(a.closePath(),n)return a=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,d=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-an/2;return[H(d)*n,q(d)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:B(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:B(+n),i):h},i.cornerRadius=function(n){return arguments.length?(I=typeof n=="function"?n:B(+n),i):I},i.padRadius=function(n){return arguments.length?(D=n==null?null:typeof n=="function"?n:B(+n),i):D},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:B(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:B(+n),i):A},i.padAngle=function(n){return arguments.length?(C=typeof n=="function"?n:B(+n),i):C},i.context=function(n){return arguments.length?(a=n??null,i):a},i}export{hn as d};