tmex-cli 0.16.5 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.md +40 -4
  2. package/dist/runtime/server.js +702 -337
  3. package/package.json +2 -1
  4. package/resources/fe-dist/assets/DevicePage-B-4Wp5gx.js +24 -0
  5. package/resources/fe-dist/assets/{DevicesPage-XMtf7VIy.js → DevicesPage-D3GQd_MI.js} +1 -1
  6. package/resources/fe-dist/assets/{FilePage-C1_JLsEc.js → FilePage-C45pl7_F.js} +2 -2
  7. package/resources/fe-dist/assets/SettingsPage-DEkQrJzi.js +39 -0
  8. package/resources/fe-dist/assets/{agent-tab-BgvIAv35.js → agent-tab-BnKrqJP2.js} +2 -2
  9. package/resources/fe-dist/assets/api-5IhJ49aS.js +5 -0
  10. package/resources/fe-dist/assets/{arc-BX-Po9p7.js → arc-DBxiTdY2.js} +1 -1
  11. package/resources/fe-dist/assets/{architectureDiagram-3BPJPVTR-BneOtjGd.js → architectureDiagram-3BPJPVTR-Dcd70ntw.js} +1 -1
  12. package/resources/fe-dist/assets/{blockDiagram-GPEHLZMM-Dcf0shYG.js → blockDiagram-GPEHLZMM-LsFpH20h.js} +1 -1
  13. package/resources/fe-dist/assets/{c4Diagram-AAUBKEIU-Cwhji_wO.js → c4Diagram-AAUBKEIU-BswGzO6B.js} +1 -1
  14. package/resources/fe-dist/assets/{card-IkOsEv2J.js → card-Bav-X9c4.js} +1 -1
  15. package/resources/fe-dist/assets/channel-hAJp4tg-.js +1 -0
  16. package/resources/fe-dist/assets/{chunk-2J33WTMH-IFwQoyns.js → chunk-2J33WTMH-C0yl1OR1.js} +1 -1
  17. package/resources/fe-dist/assets/{chunk-4BX2VUAB-BZhwH7K2.js → chunk-4BX2VUAB-Dwo9vDDk.js} +1 -1
  18. package/resources/fe-dist/assets/{chunk-55IACEB6-pYNojBsx.js → chunk-55IACEB6-Dz9e7vav.js} +1 -1
  19. package/resources/fe-dist/assets/{chunk-727SXJPM-BwBn-X-G.js → chunk-727SXJPM-ZkqwcZ6G.js} +1 -1
  20. package/resources/fe-dist/assets/{chunk-AQP2D5EJ-Cv5U78aO.js → chunk-AQP2D5EJ-79MMuY3h.js} +1 -1
  21. package/resources/fe-dist/assets/{chunk-FMBD7UC4-DnaDXP2z.js → chunk-FMBD7UC4-Vw8e6XCy.js} +1 -1
  22. package/resources/fe-dist/assets/{chunk-ND2GUHAM-BCRcaTWl.js → chunk-ND2GUHAM-um7O2-xi.js} +1 -1
  23. package/resources/fe-dist/assets/{chunk-QZHKN3VN-1sPBtZCH.js → chunk-QZHKN3VN-D8FuV91c.js} +1 -1
  24. package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-SSiS3KfC.js +1 -0
  25. package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-SSiS3KfC.js +1 -0
  26. package/resources/fe-dist/assets/{copy-CJIriuQt.js → copy-Cawnv2-o.js} +1 -1
  27. package/resources/fe-dist/assets/{cose-bilkent-S5V4N54A-CY6ERT7s.js → cose-bilkent-S5V4N54A-gidx-z0G.js} +1 -1
  28. package/resources/fe-dist/assets/{dagre-BM42HDAG-c_oJjVCK.js → dagre-BM42HDAG-C54CUHrk.js} +1 -1
  29. package/resources/fe-dist/assets/{diagram-2AECGRRQ-g-DJAnzv.js → diagram-2AECGRRQ-DFGI1MJu.js} +1 -1
  30. package/resources/fe-dist/assets/{diagram-5GNKFQAL-0DikWL30.js → diagram-5GNKFQAL-D7POJY8A.js} +1 -1
  31. package/resources/fe-dist/assets/{diagram-KO2AKTUF-wWVJH7kq.js → diagram-KO2AKTUF-CvV1GMLL.js} +1 -1
  32. package/resources/fe-dist/assets/{diagram-LMA3HP47-UwQ9OpsG.js → diagram-LMA3HP47-BbfJVUKI.js} +1 -1
  33. package/resources/fe-dist/assets/{diagram-OG6HWLK6-ZFNNtnbo.js → diagram-OG6HWLK6-CV6Q6IxH.js} +1 -1
  34. package/resources/fe-dist/assets/download-ZSRF6UU6.js +6 -0
  35. package/resources/fe-dist/assets/en_US-xzwBD2oK.js +1 -0
  36. package/resources/fe-dist/assets/{erDiagram-TEJ5UH35-D3na7WWE.js → erDiagram-TEJ5UH35-BPgvqV_L.js} +1 -1
  37. package/resources/fe-dist/assets/{files-tab-1FVCHULV.js → files-tab-BQhhr5Wi.js} +15 -15
  38. package/resources/fe-dist/assets/{flowDiagram-I6XJVG4X-Dsbf9z99.js → flowDiagram-I6XJVG4X-CKXjL0zg.js} +1 -1
  39. package/resources/fe-dist/assets/{ganttDiagram-6RSMTGT7-CF3CKflH.js → ganttDiagram-6RSMTGT7-D58QnW85.js} +1 -1
  40. package/resources/fe-dist/assets/{gitGraphDiagram-PVQCEYII-CRpX3WPf.js → gitGraphDiagram-PVQCEYII-BwB9zJYk.js} +1 -1
  41. package/resources/fe-dist/assets/{index-U4iZ6Kxr.js → index-CxD8veUJ.js} +16 -16
  42. package/resources/fe-dist/assets/{index-C-RSAqjj.js → index-DDvqV24J.js} +1 -1
  43. package/resources/fe-dist/assets/{infoDiagram-5YYISTIA-DMCNm7PZ.js → infoDiagram-5YYISTIA-DGZZJ51K.js} +1 -1
  44. package/resources/fe-dist/assets/{ishikawaDiagram-YF4QCWOH-CMe-J41c.js → ishikawaDiagram-YF4QCWOH-DKEV0i-O.js} +1 -1
  45. package/resources/fe-dist/assets/ja_JP-Dd1FrxOk.js +1 -0
  46. package/resources/fe-dist/assets/{journeyDiagram-JHISSGLW-CxFZDT81.js → journeyDiagram-JHISSGLW-Dvt5MIiS.js} +1 -1
  47. package/resources/fe-dist/assets/{kanban-definition-UN3LZRKU-DwBxD_Gg.js → kanban-definition-UN3LZRKU-BrLCK6I8.js} +1 -1
  48. package/resources/fe-dist/assets/{linear-CBM17AV1.js → linear-LNJ3BF_d.js} +1 -1
  49. package/resources/fe-dist/assets/{markdown-preview-CVeuDkuY.js → markdown-preview-Cqdqjc1H.js} +3 -3
  50. package/resources/fe-dist/assets/{mermaid.core-CvSv2dqw.js → mermaid.core-Cy4PFTl-.js} +5 -5
  51. package/resources/fe-dist/assets/{mindmap-definition-RKZ34NQL-DUu53RHy.js → mindmap-definition-RKZ34NQL-JOcL1ZTP.js} +1 -1
  52. package/resources/fe-dist/assets/{pieDiagram-4H26LBE5-CAbw9YBY.js → pieDiagram-4H26LBE5-_1o-TTd6.js} +1 -1
  53. package/resources/fe-dist/assets/{quadrantDiagram-W4KKPZXB-NmJUURAz.js → quadrantDiagram-W4KKPZXB-7Ggy2jhO.js} +1 -1
  54. package/resources/fe-dist/assets/{requirementDiagram-4Y6WPE33-B45iu7jV.js → requirementDiagram-4Y6WPE33-CH_udJzB.js} +1 -1
  55. package/resources/fe-dist/assets/{sankeyDiagram-5OEKKPKP-af9JvT_p.js → sankeyDiagram-5OEKKPKP-DO9ymHJb.js} +1 -1
  56. package/resources/fe-dist/assets/{send-e_FTy5nC.js → send-D0SbMcl5.js} +1 -1
  57. package/resources/fe-dist/assets/{sequenceDiagram-3UESZ5HK-CSpSOeHp.js → sequenceDiagram-3UESZ5HK-BfxbUo5S.js} +1 -1
  58. package/resources/fe-dist/assets/{stateDiagram-AJRCARHV-vM6MSoBd.js → stateDiagram-AJRCARHV-ChJ5OE86.js} +1 -1
  59. package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-yafZZKAc.js +1 -0
  60. package/resources/fe-dist/assets/terminal-settings-panel-CFkXHe7W.js +25 -0
  61. package/resources/fe-dist/assets/{timeline-definition-PNZ67QCA-A63tNc2d.js → timeline-definition-PNZ67QCA-CIlpfkBn.js} +1 -1
  62. package/resources/fe-dist/assets/{transfer-toast-CmSO0e95.js → transfer-toast-DvU8-v2e.js} +1 -1
  63. package/resources/fe-dist/assets/{triangle-alert-jNMwsJMj.js → triangle-alert-BI3hbdo6.js} +1 -1
  64. package/resources/fe-dist/assets/{vennDiagram-CIIHVFJN-BktPK2LC.js → vennDiagram-CIIHVFJN-NqSGMHBa.js} +1 -1
  65. package/resources/fe-dist/assets/{wardley-L42UT6IY-viU1xsE2.js → wardley-L42UT6IY-bOJt96SM.js} +1 -1
  66. package/resources/fe-dist/assets/{wardleyDiagram-YWT4CUSO-DICOr7Mv.js → wardleyDiagram-YWT4CUSO-DAgFPWOP.js} +1 -1
  67. package/resources/fe-dist/assets/{xychartDiagram-2RQKCTM6-bjue7pS9.js → xychartDiagram-2RQKCTM6-D5rVqEFB.js} +1 -1
  68. package/resources/fe-dist/assets/{zap-ClXbg92C.js → zap-D-Szn4JY.js} +1 -1
  69. package/resources/fe-dist/assets/zh_CN-DVIa9MQX.js +1 -0
  70. package/resources/fe-dist/index.html +1 -1
  71. package/resources/gateway-drizzle/0015_wise_mongu.sql +1 -0
  72. package/resources/gateway-drizzle/0016_cheerful_scarecrow.sql +17 -0
  73. package/resources/gateway-drizzle/meta/_journal.json +14 -0
  74. package/resources/fe-dist/assets/DevicePage-BIjGEtCP.js +0 -24
  75. package/resources/fe-dist/assets/SettingsPage-BAx39LyM.js +0 -39
  76. package/resources/fe-dist/assets/api-Dto6Spgl.js +0 -10
  77. package/resources/fe-dist/assets/channel-DD10rSnh.js +0 -1
  78. package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-CEWAB_yV.js +0 -1
  79. package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-CEWAB_yV.js +0 -1
  80. package/resources/fe-dist/assets/en_US-BihUhDmr.js +0 -1
  81. package/resources/fe-dist/assets/ja_JP-f5sXmz8W.js +0 -1
  82. package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-8FQLtPkV.js +0 -1
  83. package/resources/fe-dist/assets/terminal-settings-panel-DU9rOuZd.js +0 -25
  84. package/resources/fe-dist/assets/zh_CN-CPdvelFW.js +0 -1
@@ -0,0 +1,39 @@
1
+ import{Y as ce,u as F,j as e,L as Pt,M as Ye,z as Ft,r as v,c as Q,B as E,P as xe,a as B,e as M,o as N,ag as _,v as Oe,T as te,A as fe,f as pe,g as we,h as At,i as ye,k as je,l as ve,m as be,n as Ne,C as ae,F as ne,H as ie,I as re,J as Ce,N as Ee,O as ke,Q as Se,R as Me,U as le,K as O,W as de,a2 as q,G as Tt,x as dt,a6 as Rt,b as ge,t as Xe,bt as $,X as mt,aa as It,bu as Lt,bv as $t,af as Dt,bw as Ot,bx as Bt,by as zt,bz as _t,bA as et,Z as Kt}from"./index-CxD8veUJ.js";import{C as U,b as G,c as W,d as ut,a as H}from"./card-Bav-X9c4.js";import{f as Qt,i as ht,F as He,j as qt,k as Ut}from"./api-5IhJ49aS.js";import{R as Ze,T as Ht,b as Vt,d as Gt}from"./terminal-settings-panel-CFkXHe7W.js";import{S as gt}from"./send-D0SbMcl5.js";import{M as Wt}from"./markdown-preview-Cqdqjc1H.js";import{D as Jt}from"./download-ZSRF6UU6.js";import{T as xt}from"./triangle-alert-BI3hbdo6.js";import"./selection-clipboard-D3gUQQ7L.js";import"./index-DDvqV24J.js";/**
2
+ * @license lucide-react v0.564.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const Yt=[["path",{d:"M2.97 12.92A2 2 0 0 0 2 14.63v3.24a2 2 0 0 0 .97 1.71l3 1.8a2 2 0 0 0 2.06 0L12 19v-5.5l-5-3-4.03 2.42Z",key:"lc1i9w"}],["path",{d:"m7 16.5-4.74-2.85",key:"1o9zyk"}],["path",{d:"m7 16.5 5-3",key:"va8pkn"}],["path",{d:"M7 16.5v5.17",key:"jnp8gn"}],["path",{d:"M12 13.5V19l3.97 2.38a2 2 0 0 0 2.06 0l3-1.8a2 2 0 0 0 .97-1.71v-3.24a2 2 0 0 0-.97-1.71L17 10.5l-5 3Z",key:"8zsnat"}],["path",{d:"m17 16.5-5-3",key:"8arw3v"}],["path",{d:"m17 16.5 4.74-2.85",key:"8rfmw"}],["path",{d:"M17 16.5v5.17",key:"k6z78m"}],["path",{d:"M7.97 4.42A2 2 0 0 0 7 6.13v4.37l5 3 5-3V6.13a2 2 0 0 0-.97-1.71l-3-1.8a2 2 0 0 0-2.06 0l-3 1.8Z",key:"1xygjf"}],["path",{d:"M12 8 7.26 5.15",key:"1vbdud"}],["path",{d:"m12 8 4.74-2.85",key:"3rx089"}],["path",{d:"M12 13.5V8",key:"1io7kd"}]],Xt=ce("boxes",Yt);/**
7
+ * @license lucide-react v0.564.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const Zt=[["rect",{width:"5",height:"5",x:"3",y:"3",rx:"1",key:"1tu5fj"}],["rect",{width:"5",height:"5",x:"16",y:"3",rx:"1",key:"1v8r4q"}],["rect",{width:"5",height:"5",x:"3",y:"16",rx:"1",key:"1x03jg"}],["path",{d:"M21 16h-3a2 2 0 0 0-2 2v3",key:"177gqh"}],["path",{d:"M21 21v.01",key:"ents32"}],["path",{d:"M12 7v3a2 2 0 0 1-2 2H7",key:"8crl2c"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M12 16v.01",key:"133mhm"}],["path",{d:"M16 12h1",key:"1slzba"}],["path",{d:"M21 12v.01",key:"1lwtk9"}],["path",{d:"M12 21v-1",key:"1880an"}]],Ve=ce("qr-code",Zt);/**
12
+ * @license lucide-react v0.564.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const es=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],ee=ce("save",es);/**
17
+ * @license lucide-react v0.564.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const ts=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],ss=ce("server",ts);/**
22
+ * @license lucide-react v0.564.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const as=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],tt=ce("shield",as);/**
27
+ * @license lucide-react v0.564.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const ns=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],is=ce("users",ns);function rs(){const{t}=F();return e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{children:[e.jsx(W,{children:t("settings.deviceManagement.title")}),e.jsx(ut,{children:t("settings.deviceManagement.description")})]}),e.jsx(H,{children:e.jsxs(Pt,{to:"/devices","data-testid":"settings-device-management-link",className:Ft({variant:"secondary"}),children:[e.jsx(Ye,{className:"h-4 w-4"}),t("settings.deviceManagement.openButton")]})})]})}function $e({type:t,className:o}){return t==="ssh"?e.jsx(Tt,{className:o}):e.jsx(Ye,{className:o})}function os(){var r,m;const{t}=F(),[o,s]=v.useState(!1),[l,c]=v.useState(void 0),h=Q({queryKey:["files","roots"],queryFn:Qt}),f=Q({queryKey:["devices"],queryFn:async()=>{const d=await fetch("/api/devices");if(!d.ok)throw new Error(`HTTP ${d.status}`);return await d.json()},throwOnError:!1}),x=((r=h.data)==null?void 0:r.roots)??[],a=((m=f.data)==null?void 0:m.devices)??[],n=()=>{c(void 0),s(!0)},i=d=>{c(d),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0","data-testid":"settings-files-section",children:[e.jsxs(G,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(W,{children:t("settings.files.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settings.files.description")})]}),e.jsxs(E,{variant:"secondary","data-testid":"settings-files-root-add",onClick:n,children:[e.jsx(xe,{className:"h-4 w-4"}),t("settings.files.addRoot")]})]}),e.jsxs(H,{className:"space-y-3",children:[h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&x.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground","data-testid":"settings-files-empty",children:t("settings.files.empty")}),x.map(d=>e.jsx(ls,{root:d,onEdit:i},d.id))]})]}),e.jsx(cs,{open:o,onOpenChange:s,root:l,devices:a})]})}function ls({root:t,onEdit:o}){const{t:s}=F(),l=B(),[c,h]=v.useState(!1),f=M({mutationFn:({id:a,enabled:n})=>ht(a,{enabled:n}),onSuccess:async()=>{await l.invalidateQueries({queryKey:["files"]})},onError:()=>{N.error(s("settings.files.toggleFailed"))}}),x=M({mutationFn:a=>qt(a),onSuccess:async()=>{await l.invalidateQueries({queryKey:["files"]}),N.success(s("common.success"))},onError:a=>{const n=a instanceof He?a.message:s("settings.files.deleteFailed");N.error(n)}});return e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border p-3","data-testid":`settings-files-root-${t.id}`,children:[e.jsx(_,{checked:t.enabled,disabled:f.isPending,onCheckedChange:a=>f.mutate({id:t.id,enabled:!!a}),"data-testid":`settings-files-root-enabled-${t.id}`}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx($e,{type:t.deviceType,className:"h-3.5 w-3.5 shrink-0"}),t.deviceName===null?e.jsx("span",{className:"text-destructive",children:s("settings.files.missing")}):e.jsx("span",{className:"truncate",children:t.deviceName})]}),e.jsx("div",{className:"truncate font-mono text-xs",children:t.path}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:t.name})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`settings-files-root-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(Oe,{className:"h-4 w-4"})}),e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("common.delete"),"data-testid":`settings-files-root-delete-${t.id}`,onClick:()=>h(!0),disabled:x.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(fe,{open:c,onOpenChange:h,children:e.jsxs(pe,{children:[e.jsxs(we,{children:[e.jsx(At,{className:"bg-destructive/10",children:e.jsx(te,{className:"h-5 w-5 text-destructive"})}),e.jsx(ye,{children:s("settings.files.deleteTitle")}),e.jsx(je,{children:s("settings.files.deleteDesc",{path:t.path})})]}),e.jsxs(ve,{children:[e.jsx(be,{children:s("common.cancel")}),e.jsx(Ne,{variant:"destructive","data-testid":`settings-files-root-delete-confirm-${t.id}`,onClick:()=>{x.mutate(t.id),h(!1)},children:s("common.delete")})]})]})})]})}const st="h-9 w-full";function cs({open:t,onOpenChange:o,root:s,devices:l}){const{t:c}=F(),h=B(),f=!!s,[x,a]=v.useState(""),[n,i]=v.useState(""),[r,m]=v.useState(!0);v.useEffect(()=>{t&&(a((s==null?void 0:s.deviceId)??""),i((s==null?void 0:s.path)??""),m((s==null?void 0:s.enabled)??!0))},[t,s]);const d=M({mutationFn:()=>{const C={deviceId:x,path:n.trim(),enabled:r};return Ut(C)},onSuccess:async()=>{await h.invalidateQueries({queryKey:["files"]}),N.success(c("common.success")),o(!1)},onError:C=>{const D=C instanceof He?C.message:c("settings.files.addFailed");N.error(D)}}),u=M({mutationFn:()=>{if(!s)throw new Error(c("settings.files.updateFailed"));const C={path:n.trim(),enabled:r};return ht(s.id,C)},onSuccess:async()=>{await h.invalidateQueries({queryKey:["files"]}),N.success(c("common.success")),o(!1)},onError:C=>{const D=C instanceof He?C.message:c("settings.files.updateFailed");N.error(D)}}),y=d.isPending||u.isPending,k=n.trim().startsWith("/")&&(f||x.length>0),g=()=>{!k||y||(f?u.mutate():d.mutate())},w=l.find(C=>C.id===x);return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":f?`settings-files-edit-modal-${s==null?void 0:s.id}`:"settings-files-add-modal",children:[e.jsxs(ie,{children:[e.jsx(re,{children:c(f?"settings.files.modalEditTitle":"settings.files.modalAddTitle")}),e.jsx(Ce,{children:c("settings.files.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"files-form-device",children:c("settings.files.device")}),f?e.jsxs("div",{className:"flex h-9 items-center gap-1.5 rounded-lg border border-input bg-muted/30 px-2.5 text-sm",children:[e.jsx($e,{type:(s==null?void 0:s.deviceType)??null,className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:(s==null?void 0:s.deviceName)??c("settings.files.missing")})]}):e.jsxs(Ee,{value:x,onValueChange:C=>{C&&a(C)},children:[e.jsx(ke,{id:"files-form-device","data-testid":"settings-files-device-select",className:st,disabled:l.length===0,children:e.jsx(Se,{children:w?e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($e,{type:w.type,className:"h-4 w-4 shrink-0"}),w.name]}):e.jsx("span",{className:"text-muted-foreground",children:c("settings.files.devicePlaceholder")})})}),e.jsx(Me,{children:l.map(C=>e.jsxs(le,{value:C.id,children:[e.jsx($e,{type:C.type,className:"h-4 w-4 shrink-0"}),C.name]},C.id))})]}),!f&&l.length===0&&e.jsx("p",{className:"text-xs text-destructive",children:c("settings.files.noDevices")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"files-form-path",children:c("settings.files.path")}),e.jsx(O,{id:"files-form-path","data-testid":"settings-files-path-input",value:n,onChange:C=>i(C.target.value),placeholder:c("settings.files.pathPlaceholder"),className:`${st} font-mono`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c("settings.files.pathHint")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{checked:r,onCheckedChange:C=>m(!!C),"data-testid":"settings-files-enabled-switch"}),e.jsx("label",{className:"text-sm font-medium",htmlFor:"settings-files-enabled-switch",children:c("settings.files.enabled")})]})]}),e.jsxs(de,{children:[e.jsx(E,{variant:"outline",onClick:()=>o(!1),disabled:y,children:c("common.cancel")}),e.jsxs(E,{variant:"secondary","data-testid":"settings-files-form-submit",onClick:g,disabled:!k||y,children:[y?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),c("common.save")]})]})]})})}async function Z(t,o){try{return(await t.json()).error??o}catch{return o}}const ds=["openai-chat","openai-responses"],Re="h-9 w-full";function ms({open:t,onOpenChange:o,provider:s}){const{t:l}=F(),c=B(),h=!!s,[f,x]=v.useState(""),[a,n]=v.useState(""),[i,r]=v.useState("openai-chat"),[m,d]=v.useState("");v.useEffect(()=>{t&&(x((s==null?void 0:s.name)??""),n((s==null?void 0:s.baseUrl)??""),r((s==null?void 0:s.protocol)??"openai-chat"),d(""))},[t,s]);const u=M({mutationFn:async()=>{const g={name:f.trim(),protocol:i,baseUrl:a.trim(),apiKey:m.trim(),enabled:!0},w=await fetch("/api/llm/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!w.ok)throw new Error(await Z(w,l("settings.llm.createFailed")));return await w.json()},onSuccess:async g=>{await c.invalidateQueries({queryKey:["llm-providers"]}),g.modelsError?N.warning(l("settings.llm.modelsFetchFailed",{error:g.modelsError})):N.success(l("common.success")),o(!1)},onError:g=>{N.error(g instanceof Error?g.message:l("common.error"))}}),y=M({mutationFn:async()=>{if(!s)throw new Error(l("settings.llm.updateFailed"));const g={name:f.trim(),baseUrl:a.trim(),protocol:i};m.trim()&&(g.apiKey=m.trim());const w=await fetch(`/api/llm/providers/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!w.ok)throw new Error(await Z(w,l("settings.llm.updateFailed")));return await w.json()},onSuccess:async g=>{await c.invalidateQueries({queryKey:["llm-providers"]}),g.modelsError?N.warning(l("settings.llm.modelsFetchFailed",{error:g.modelsError})):N.success(l("common.success")),o(!1)},onError:g=>{N.error(g instanceof Error?g.message:l("common.error"))}}),j=u.isPending||y.isPending,p=f.trim().length>0&&a.trim().length>0&&(h||m.trim().length>0),k=()=>{!p||j||(h?y.mutate():u.mutate())};return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":h?`llm-provider-edit-modal-${s==null?void 0:s.id}`:"llm-provider-add-modal",children:[e.jsxs(ie,{children:[e.jsx(re,{children:l(h?"settings.llm.editProvider":"settings.llm.addProvider")}),e.jsx(Ce,{children:l("settings.llm.formHint")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-name",children:l("settings.llm.name")}),e.jsx(O,{id:"llm-form-name","data-testid":"llm-provider-name-input",value:f,onChange:g=>x(g.target.value),placeholder:l("settings.llm.namePlaceholder"),className:Re})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-baseurl",children:l("settings.llm.baseUrl")}),e.jsx(O,{id:"llm-form-baseurl","data-testid":"llm-provider-baseurl-input",value:a,onChange:g=>n(g.target.value),placeholder:l("settings.llm.baseUrlPlaceholder"),className:Re}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("settings.llm.baseUrlHint")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-protocol",children:l("settings.llm.protocol")}),e.jsxs(Ee,{value:i,onValueChange:g=>{g&&r(g)},children:[e.jsx(ke,{id:"llm-form-protocol","data-testid":"llm-provider-protocol-select",className:Re,children:e.jsx(Se,{})}),e.jsx(Me,{children:ds.map(g=>e.jsx(le,{value:g,children:g},g))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-form-apikey",children:l("settings.llm.apiKey")}),e.jsx(O,{id:"llm-form-apikey","data-testid":"llm-provider-apikey-input","data-key-set":s!=null&&s.hasApiKey?"true":"false",type:"password",value:m,onChange:g=>d(g.target.value),placeholder:s!=null&&s.hasApiKey?l("settings.llm.apiKeySetPlaceholder"):l("settings.llm.apiKeyPlaceholder"),className:Re})]})]}),e.jsxs(de,{children:[e.jsx(E,{variant:"outline",onClick:()=>o(!1),disabled:j,children:l("common.cancel")}),e.jsxs(E,{variant:"secondary","data-testid":"llm-provider-form-submit",onClick:k,disabled:!p||j,children:[j?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})})}function us({models:t,onChange:o}){const{t:s}=F(),[l,c]=v.useState(""),h=(a,n)=>{o(t.map(i=>i.id===a?{...i,enabled:n}:i))},f=a=>{o(t.filter(n=>n.id!==a))},x=()=>{const a=l.trim();if(a){if(t.some(n=>n.id===a)){c("");return}o([...t,{id:a,source:"manual",enabled:!0}]),c("")}};return e.jsxs("div",{className:"space-y-3","data-testid":"llm-provider-models",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{value:l,onChange:a=>c(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),x())},placeholder:s("settings.llm.addModelPlaceholder"),className:"h-9","data-testid":"llm-provider-add-model-input"}),e.jsxs(E,{type:"button",variant:"outline",size:"lg",onClick:x,disabled:!l.trim(),"data-testid":"llm-provider-add-model",children:[e.jsx(xe,{className:"h-4 w-4"}),s("common.add")]})]}),t.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:s("settings.llm.modelsNotFetched")}):e.jsx("ul",{className:"max-h-56 space-y-1 overflow-y-auto rounded-lg border border-border bg-background p-2",children:t.map(a=>e.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-md px-2 py-1.5","data-testid":`llm-provider-model-${a.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(_,{checked:a.enabled,onCheckedChange:n=>h(a.id,!!n),"data-testid":`llm-provider-model-toggle-${a.id}`}),e.jsx("span",{className:"truncate font-mono text-xs",children:a.id}),a.source==="manual"&&e.jsx(dt,{variant:"secondary",children:s("settings.llm.modelManual")})]}),a.source==="manual"&&e.jsx(E,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>f(a.id),"data-testid":`llm-provider-model-remove-${a.id}`,children:e.jsx(Rt,{className:"h-4 w-4"})})]},a.id))})]})}function hs(t){return t.modelDetails.map(o=>({id:o.id,source:o.source,enabled:o.enabled}))}function gs({open:t,onOpenChange:o,provider:s}){const{t:l}=F(),c=B(),[h,f]=v.useState([]);v.useEffect(()=>{t&&f(hs(s))},[t,s]);const x=M({mutationFn:async()=>{const a=h.filter(m=>m.source==="manual").map(m=>m.id),n=h.filter(m=>!m.enabled).map(m=>m.id),i={manualModels:a,disabledModels:n},r=await fetch(`/api/llm/providers/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(await Z(r,l("settings.llm.updateFailed")));return await r.json()},onSuccess:async a=>{await c.invalidateQueries({queryKey:["llm-providers"]}),a.modelsError?N.warning(l("settings.llm.modelsFetchFailed",{error:a.modelsError})):N.success(l("common.success")),o(!1)},onError:a=>{N.error(a instanceof Error?a.message:l("common.error"))}});return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":`llm-provider-models-modal-${s.id}`,children:[e.jsxs(ie,{children:[e.jsx(re,{children:l("settings.llm.modelsTitle",{name:s.name})}),e.jsx(Ce,{children:l("settings.llm.modelsHint")})]}),e.jsx(us,{models:h,onChange:f}),e.jsxs(de,{children:[e.jsx(E,{variant:"outline",onClick:()=>o(!1),disabled:x.isPending,children:l("common.cancel")}),e.jsxs(E,{variant:"secondary","data-testid":`llm-provider-models-save-${s.id}`,onClick:()=>x.mutate(),disabled:x.isPending,children:[x.isPending?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})})}function xs(t){try{const o=new URL(t);return`${o.protocol}//${o.host}${o.pathname==="/"?"":o.pathname}`}catch{return t}}function fs({provider:t,onEdit:o}){const{t:s}=F(),l=B(),[c,h]=v.useState(!1),[f,x]=v.useState(!1),a=M({mutationFn:async r=>{const m=await fetch(`/api/llm/providers/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:r})});if(!m.ok)throw new Error(await Z(m,s("settings.llm.updateFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["llm-providers"]})},onError:r=>{N.error(r instanceof Error?r.message:s("common.error"))}}),n=M({mutationFn:async()=>{const r=await fetch(`/api/llm/providers/${t.id}/refresh-models`,{method:"POST"});if(!r.ok)throw new Error(await Z(r,s("settings.llm.refreshModelsFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["llm-providers"]}),N.success(s("common.success"))},onError:r=>{N.error(r instanceof Error?r.message:s("common.error"))}}),i=M({mutationFn:async()=>{const r=await fetch(`/api/llm/providers/${t.id}`,{method:"DELETE"});if(!r.ok)throw new Error(await Z(r,s("settings.llm.deleteFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["llm-providers"]}),await l.invalidateQueries({queryKey:["llm-settings"]}),N.success(s("common.success"))},onError:r=>{N.error(r instanceof Error?r.message:s("common.error"))}});return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-3 sm:flex-row sm:items-center sm:justify-between","data-testid":`llm-provider-row-${t.id}`,"data-provider-name":t.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(_,{checked:t.enabled,disabled:a.isPending,onCheckedChange:r=>a.mutate(!!r),"data-testid":`llm-provider-enabled-${t.id}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium",children:t.name}),e.jsx(dt,{variant:"outline",children:t.protocol})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"truncate font-mono",children:xs(t.baseUrl)}),e.jsx("span",{"aria-hidden":!0,children:"·"}),e.jsx("span",{className:"whitespace-nowrap",children:s("settings.llm.modelsCount",{total:t.models.length})})]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("settings.llm.refreshModels"),"data-testid":`llm-provider-refresh-models-${t.id}`,onClick:()=>n.mutate(),disabled:n.isPending,children:n.isPending?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(Ze,{className:"h-4 w-4"})}),e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("settings.llm.models"),"data-testid":`llm-provider-models-${t.id}`,onClick:()=>x(!0),children:e.jsx(Xt,{className:"h-4 w-4"})}),e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`llm-provider-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(Oe,{className:"h-4 w-4"})}),e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("common.delete"),"data-testid":`llm-provider-delete-${t.id}`,onClick:()=>h(!0),disabled:i.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(gs,{open:f,onOpenChange:x,provider:t}),e.jsx(fe,{open:c,onOpenChange:h,children:e.jsxs(pe,{children:[e.jsxs(we,{children:[e.jsx(ye,{children:s("settings.llm.deleteProvider")}),e.jsx(je,{children:s("settings.llm.deleteConfirm",{name:t.name})})]}),e.jsxs(ve,{children:[e.jsx(be,{onClick:()=>h(!1),children:s("common.cancel")}),e.jsx(Ne,{variant:"destructive","data-testid":`llm-provider-delete-confirm-${t.id}`,onClick:()=>{i.mutate(),h(!1)},children:s("common.confirm")})]})]})})]})}function ps(){var n;const{t}=F(),[o,s]=v.useState(!1),[l,c]=v.useState(void 0),h=Q({queryKey:["llm-providers"],queryFn:async()=>{const i=await fetch("/api/llm/providers");if(!i.ok)throw new Error(await Z(i,t("settings.llm.loadFailed")));return await i.json()}}),f=((n=h.data)==null?void 0:n.providers)??[],x=()=>{c(void 0),s(!0)},a=i=>{c(i),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0","data-testid":"llm-providers-section",children:[e.jsxs(G,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsx(W,{children:t("settings.llm.title")}),e.jsxs(E,{variant:"secondary","data-testid":"llm-provider-add",onClick:x,children:[e.jsx(xe,{className:"h-4 w-4"}),t("settings.llm.addProvider")]})]}),e.jsxs(H,{className:"space-y-3",children:[h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&f.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground","data-testid":"llm-providers-empty",children:t("settings.llm.empty")}),f.map(i=>e.jsx(fs,{provider:i,onEdit:a},i.id))]})]}),e.jsx(ms,{open:o,onOpenChange:s,provider:l}),e.jsx(ws,{providers:f})]})}const Be="__none__";function ws({providers:t}){var y,j;const{t:o}=F(),s=B(),[l,c]=v.useState(null),[h,f]=v.useState(""),x=Q({queryKey:["llm-settings"],queryFn:async()=>{const p=await fetch("/api/llm/settings");if(!p.ok)throw new Error(await Z(p,o("settings.llm.settingsLoadFailed")));return await p.json()}}),a=((y=x.data)==null?void 0:y.settings.defaultProviderId)??null,n=((j=x.data)==null?void 0:j.settings.defaultModelId)??"",i=!!x.data;v.useEffect(()=>{i&&(c(a),f(n))},[i,a,n]);const r=M({mutationFn:async()=>{const p={defaultProviderId:l,defaultModelId:h.trim()||null},k=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)});if(!k.ok)throw new Error(await Z(k,o("settings.llm.settingsSaveFailed")))},onSuccess:async()=>{await s.invalidateQueries({queryKey:["llm-settings"]}),N.success(o("common.success"))},onError:p=>{N.error(p instanceof Error?p.message:o("common.error"))}}),m=t.filter(p=>p.enabled),d=t.find(p=>p.id===l),u=(d==null?void 0:d.models)??[];return e.jsxs(U,{className:"border-0 ring-0","data-testid":"llm-defaults-section",children:[e.jsx(G,{children:e.jsx(W,{children:o("settings.llm.defaults")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-default-provider-select",children:o("settings.llm.defaultProvider")}),e.jsxs(Ee,{value:l??Be,onValueChange:p=>{p&&c(p===Be?null:p)},children:[e.jsx(ke,{id:"llm-default-provider-select","data-testid":"llm-default-provider-select",className:"h-9 w-full",children:e.jsx(Se,{children:(d==null?void 0:d.name)??o("settings.llm.defaultProviderNone")})}),e.jsxs(Me,{children:[e.jsx(le,{value:Be,children:o("settings.llm.defaultProviderNone")}),m.map(p=>e.jsx(le,{value:p.id,children:p.name},p.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"llm-default-model-input",children:o("settings.llm.defaultModel")}),e.jsx(O,{id:"llm-default-model-input","data-testid":"llm-default-model-input",list:"llm-default-model-options",value:h,onChange:p=>f(p.target.value),placeholder:o("settings.llm.defaultModelPlaceholder"),className:"h-9"}),e.jsx("datalist",{id:"llm-default-model-options",children:u.map(p=>e.jsx("option",{value:p},p))})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(E,{variant:"secondary","data-testid":"llm-defaults-save",onClick:()=>r.mutate(),disabled:r.isPending||x.isLoading,className:"w-full sm:w-auto",children:[r.isPending?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),o("settings.llm.saveDefaults")]})})]})]})}async function ze(t,o){try{return(await t.json()).error??o}catch{return o}}function ys(){var k,g;const{t}=F(),o=B(),[s,l]=v.useState("none"),[c,h]=v.useState(""),[f,x]=v.useState(""),[a,n]=v.useState(null),i=Q({queryKey:["llm-settings"],queryFn:async()=>{const w=await fetch("/api/llm/settings");if(!w.ok)throw new Error(await ze(w,t("settings.search.loadFailed")));return await w.json()}}),r=(k=i.data)==null?void 0:k.settings,m=r==null?void 0:r.searchProvider;v.useEffect(()=>{m&&l(m)},[m]);const d=M({mutationFn:async()=>{const w={searchProvider:s};c.trim()&&(w.tavilyApiKey=c.trim()),f.trim()&&(w.braveApiKey=f.trim());const C=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)});if(!C.ok)throw new Error(await ze(C,t("settings.search.saveFailed")))},onSuccess:async()=>{h(""),x(""),await o.invalidateQueries({queryKey:["llm-settings"]}),N.success(t("common.success"))},onError:w=>{N.error(w instanceof Error?w.message:t("common.error"))}}),u=M({mutationFn:async w=>{const C={[w]:""},D=await fetch("/api/llm/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(C)});if(!D.ok)throw new Error(await ze(D,t("settings.search.saveFailed")))},onSuccess:async()=>{await o.invalidateQueries({queryKey:["llm-settings"]}),N.success(t("common.success"))},onError:w=>{N.error(w instanceof Error?w.message:t("common.error"))}}),y=((g=i.data)==null?void 0:g.searchProviders)??[],j=["none",...y.map(w=>w.id)];j.includes(s)||j.push(s);const p=w=>{var C;return w==="none"?t("settings.search.providerNone"):((C=y.find(D=>D.id===w))==null?void 0:C.label)??w};return e.jsxs(U,{className:"border-0 ring-0","data-testid":"settings-search-section",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.search.title")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"search-provider-select",children:t("settings.search.provider")}),e.jsxs(Ee,{value:s,onValueChange:w=>{w&&l(w)},children:[e.jsx(ke,{id:"search-provider-select","data-testid":"settings-search-provider-select",className:"w-full min-h-10",children:e.jsx(Se,{children:p(s)})}),e.jsx(Me,{children:j.map(w=>e.jsx(le,{value:w,children:p(w)},w))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.search.responsesApiHint")})]}),e.jsx(at,{id:"search-tavily-key-input",testId:"settings-search-tavily",label:t("settings.search.tavilyApiKey"),value:c,hasKey:(r==null?void 0:r.hasTavilyApiKey)??!1,onChange:h,onClear:()=>n("tavilyApiKey"),clearing:u.isPending&&u.variables==="tavilyApiKey"}),e.jsx(at,{id:"search-brave-key-input",testId:"settings-search-brave",label:t("settings.search.braveApiKey"),value:f,hasKey:(r==null?void 0:r.hasBraveApiKey)??!1,onChange:x,onClear:()=>n("braveApiKey"),clearing:u.isPending&&u.variables==="braveApiKey"}),e.jsx(fe,{open:a!==null,onOpenChange:w=>{w||n(null)},children:e.jsxs(pe,{children:[e.jsxs(we,{children:[e.jsx(ye,{children:t("settings.search.clearKey")}),e.jsx(je,{children:t("settings.search.clearKeyConfirm")})]}),e.jsxs(ve,{children:[e.jsx(be,{children:t("common.cancel")}),e.jsx(Ne,{"data-testid":"settings-search-clear-confirm",onClick:()=>{a&&u.mutate(a),n(null)},children:t("settings.search.clearKey")})]})]})}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(E,{variant:"secondary","data-testid":"settings-search-save",onClick:()=>d.mutate(),disabled:d.isPending||i.isLoading,className:"w-full sm:w-auto",children:[d.isPending?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),t("common.save")]})})]})]})}function at({id:t,testId:o,label:s,value:l,hasKey:c,onChange:h,onClear:f,clearing:x}){const{t:a}=F();return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:t,children:s}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{id:t,"data-testid":`${o}-input`,"data-key-set":c?"true":"false",type:"password",value:l,onChange:n=>h(n.target.value),placeholder:a(c?"settings.search.keySetPlaceholder":"settings.search.keyPlaceholder"),className:"min-h-10"}),c&&e.jsxs(E,{variant:"outline",size:"sm","data-testid":`${o}-clear`,onClick:f,disabled:x,className:"shrink-0",children:[e.jsx(te,{className:"h-4 w-4"}),a("settings.search.clearKey")]})]})]})}const nt="min-h-10";async function it(t,o){try{return(await t.json()).error??o}catch{return o}}function js({open:t,onOpenChange:o,bot:s}){const{t:l}=F(),c=B(),h=!!s,[f,x]=v.useState(""),[a,n]=v.useState(""),[i,r]=v.useState(!0);v.useEffect(()=>{t&&(x((s==null?void 0:s.name)??""),n(""),r((s==null?void 0:s.allowAuthRequests)??!0))},[t,s]);const m=M({mutationFn:async()=>{const p=await fetch("/api/settings/telegram/bots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:f.trim(),token:a.trim(),enabled:!0,allowAuthRequests:i})});if(!p.ok)throw new Error(await it(p,l("telegram.createFailed")))},onSuccess:async()=>{await c.invalidateQueries({queryKey:["telegram-bots"]}),N.success(l("common.success")),o(!1)},onError:p=>{N.error(p instanceof Error?p.message:l("common.error"))}}),d=M({mutationFn:async()=>{if(!s)throw new Error(l("telegram.updateFailed"));const p={name:f.trim(),allowAuthRequests:i};a.trim()&&(p.token=a.trim());const k=await fetch(`/api/settings/telegram/bots/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)});if(!k.ok)throw new Error(await it(k,l("telegram.updateFailed")))},onSuccess:async()=>{await c.invalidateQueries({queryKey:["telegram-bots"]}),N.success(l("common.success")),o(!1)},onError:p=>{N.error(p instanceof Error?p.message:l("common.error"))}}),u=m.isPending||d.isPending,y=f.trim().length>0&&(h||a.trim().length>0),j=()=>{!y||u||(h?d.mutate():m.mutate())};return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":h?`telegram-bot-edit-modal-${s==null?void 0:s.id}`:"telegram-bot-add-modal",children:[e.jsx(ie,{children:e.jsx(re,{children:l(h?"telegram.editBot":"telegram.addBot")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"telegram-bot-name",children:l("telegram.botName")}),e.jsx(O,{id:"telegram-bot-name","data-testid":"telegram-bot-name-input",value:f,onChange:p=>x(p.target.value),placeholder:l("telegram.botNamePlaceholder"),className:nt})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"telegram-bot-token",children:l("telegram.botToken")}),e.jsx(O,{id:"telegram-bot-token","data-testid":"telegram-bot-token-input",type:"password",value:a,onChange:p=>n(p.target.value),placeholder:l(h?"telegram.tokenPlaceholder":"telegram.botTokenPlaceholder"),className:nt})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:l("telegram.allowAuthRequests")}),e.jsx(_,{checked:i,"data-testid":"telegram-bot-allow-auth",onCheckedChange:p=>r(!!p)})]})]}),e.jsxs(de,{children:[e.jsx(E,{variant:"outline",onClick:()=>o(!1),disabled:u,children:l("common.cancel")}),e.jsxs(E,{variant:"secondary","data-testid":"telegram-bot-form-submit",onClick:j,disabled:!y||u,children:[u?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})})}async function Ie(t,o){try{return(await t.json()).error??o}catch{return o}}function vs({open:t,onOpenChange:o,botId:s,botName:l}){var m;const{t:c}=F(),h=B(),f=Q({queryKey:["telegram-bot-chats",s],enabled:t,queryFn:async()=>{const d=await fetch(`/api/settings/telegram/bots/${s}/chats`);if(!d.ok)throw new Error(await Ie(d,c("telegram.loadChatsFailed")));return await d.json()}}),x=v.useMemo(()=>{var u;const d=((u=f.data)==null?void 0:u.chats)??[];return{pending:d.filter(y=>y.status==="pending"),authorized:d.filter(y=>y.status==="authorized")}},[(m=f.data)==null?void 0:m.chats]),a=async()=>{await Promise.all([h.invalidateQueries({queryKey:["telegram-bots"]}),h.invalidateQueries({queryKey:["telegram-bot-chats",s]})])},n=M({mutationFn:async d=>{const u=await fetch(`/api/settings/telegram/bots/${s}/chats/${encodeURIComponent(d)}/approve`,{method:"POST"});if(!u.ok)throw new Error(await Ie(u,c("telegram.approveFailed")))},onSuccess:async()=>{await a(),N.success(c("common.success"))},onError:d=>{N.error(d instanceof Error?d.message:c("common.error"))}}),i=M({mutationFn:async d=>{const u=await fetch(`/api/settings/telegram/bots/${s}/chats/${encodeURIComponent(d)}`,{method:"DELETE"});if(!u.ok)throw new Error(await Ie(u,c("telegram.removeFailed")))},onSuccess:async()=>{await a(),N.success(c("common.success"))},onError:d=>{N.error(d instanceof Error?d.message:c("common.error"))}}),r=M({mutationFn:async d=>{const u=await fetch(`/api/settings/telegram/bots/${s}/chats/${encodeURIComponent(d)}/test`,{method:"POST"});if(!u.ok)throw new Error(await Ie(u,c("telegram.testMessageFailed")))},onSuccess:()=>{N.success(c("common.success"))},onError:d=>{N.error(d instanceof Error?d.message:c("common.error"))}});return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-2xl","data-testid":`telegram-bot-chats-modal-${s}`,children:[e.jsxs(ie,{children:[e.jsx(re,{children:c("telegram.chats")}),e.jsx(Ce,{children:l})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"flex items-center gap-1 text-sm font-semibold",children:[e.jsx(tt,{className:"h-4 w-4"}),c("telegram.pendingChats")]}),x.pending.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:c("telegram.noPendingChats")}),x.pending.map(d=>e.jsx(rt,{chat:d,pending:!0,onApprove:()=>n.mutate(d.chatId),onDelete:()=>i.mutate(d.chatId)},`${d.botId}-${d.chatId}`))]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"flex items-center gap-1 text-sm font-semibold",children:[e.jsx(tt,{className:"h-4 w-4"}),c("telegram.chats")]}),x.authorized.length===0&&e.jsx("div",{className:"text-xs text-muted-foreground",children:c("telegram.noAuthorizedChats")}),x.authorized.map(d=>e.jsx(rt,{chat:d,pending:!1,onTest:()=>r.mutate(d.chatId),onDelete:()=>i.mutate(d.chatId)},`${d.botId}-${d.chatId}`))]}),f.isLoading&&e.jsx("div",{className:"text-xs text-muted-foreground lg:col-span-2",children:c("common.loading")})]})]})})}function rt({chat:t,pending:o,onApprove:s,onDelete:l,onTest:c}){const{t:h}=F(),f=ge(x=>{var a;return((a=x.settings)==null?void 0:a.language)??"en_US"});return e.jsxs("div",{className:"space-y-2 rounded border-0 bg-background p-3",children:[e.jsx("div",{className:"truncate text-sm font-medium",title:t.displayName,children:t.displayName}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[h("telegram.chatId"),":",t.chatId]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(t.appliedAt).toLocaleString(Xe(f))}),e.jsx("div",{className:"flex items-center justify-end gap-2 pt-1",children:o?e.jsxs(e.Fragment,{children:[e.jsx(E,{variant:"outline",size:"sm",onClick:l,children:h("telegram.reject")}),e.jsx(E,{variant:"secondary",size:"sm",onClick:s,children:h("telegram.authorize")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(E,{variant:"secondary",size:"sm",onClick:c,children:[e.jsx(gt,{className:"h-3.5 w-3.5"}),h("telegram.sendTestMessage")]}),e.jsx(E,{variant:"destructive",size:"sm",onClick:l,children:h("common.delete")})]})})]})}async function ot(t,o){try{return(await t.json()).error??o}catch{return o}}function bs({bot:t,onEdit:o}){const{t:s}=F(),l=B(),[c,h]=v.useState(!1),f=M({mutationFn:async a=>{const n=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:a})});if(!n.ok)throw new Error(await ot(n,s("telegram.updateFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["telegram-bots"]})},onError:a=>{N.error(a instanceof Error?a.message:s("common.error"))}}),x=M({mutationFn:async()=>{const a=await fetch(`/api/settings/telegram/bots/${t.id}`,{method:"DELETE"});if(!a.ok)throw new Error(await ot(a,s("telegram.deleteFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["telegram-bots"]}),N.success(s("common.success"))},onError:a=>{N.error(a instanceof Error?a.message:s("common.error"))}});return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-3 sm:flex-row sm:items-center sm:justify-between","data-testid":`telegram-bot-card-${t.id}`,"data-bot-name":t.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(_,{checked:t.enabled,disabled:f.isPending,onCheckedChange:a=>f.mutate(!!a),"data-testid":`telegram-bot-enabled-${t.id}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:t.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s("telegram.authCount",{authorized:t.authorizedCount,pending:t.pendingCount})})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("telegram.chats"),"data-testid":`telegram-bot-chats-${t.id}`,onClick:()=>h(!0),children:e.jsx(is,{className:"h-4 w-4"})}),e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`telegram-bot-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(Oe,{className:"h-4 w-4"})}),e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("telegram.deleteBot"),"data-testid":`telegram-bot-delete-${t.id}`,onClick:()=>x.mutate(),disabled:x.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(vs,{open:c,onOpenChange:h,botId:t.id,botName:t.name})]})}async function Ns(t,o){try{return(await t.json()).error??o}catch{return o}}function Cs(){var n;const{t}=F(),[o,s]=v.useState(!1),[l,c]=v.useState(void 0),h=Q({queryKey:["telegram-bots"],queryFn:async()=>{const i=await fetch("/api/settings/telegram/bots");if(!i.ok)throw new Error(await Ns(i,t("telegram.loadBotsFailed")));return await i.json()}}),f=((n=h.data)==null?void 0:n.bots)??[],x=()=>{c(void 0),s(!0)},a=i=>{c(i),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{className:"flex flex-row items-center justify-between gap-2",children:[e.jsx(W,{children:t("telegram.title")}),e.jsxs(E,{variant:"secondary","data-testid":"telegram-add-bot",onClick:x,children:[e.jsx(xe,{className:"h-4 w-4"}),t("telegram.addBot")]})]}),e.jsxs(H,{className:"space-y-3",children:[h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&f.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("telegram.noBots")}),f.map(i=>e.jsx(bs,{bot:i,onEdit:a},i.id))]})]}),e.jsx(js,{open:o,onOpenChange:s,bot:l})]})}function Es(){const{t}=F();return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.terminal.title")})}),e.jsx(H,{children:e.jsx(Ht,{showShortcuts:!1})})]}),e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{children:[e.jsx(W,{children:t("settings.terminal.shortcuts.title")}),e.jsx(ut,{children:t("settings.terminal.shortcuts.savedOnServer")})]}),e.jsx(H,{children:e.jsx(Vt,{})})]})]})}async function _e(t,o){try{return(await t.json()).error??o}catch{return o}}function Ke({label:t,value:o}){return e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2 text-sm font-medium",children:t}),e.jsx("div",{className:"min-w-0 truncate text-right text-sm text-muted-foreground",children:o})]})}function ks(){const{t}=F(),o=B(),s=ge(g=>{var w;return((w=g.settings)==null?void 0:w.language)??"en_US"}),[l,c]=v.useState(!1),[h,f]=v.useState(!1),x=v.useRef(!1),n=Q({queryKey:["system-info"],queryFn:async()=>{const g=await fetch("/api/system/info");if(!g.ok)throw new Error(await _e(g,t("settings.loadFailed")));return await g.json()}}).data,i=Q({queryKey:["system-update-check"],enabled:!1,gcTime:0,queryFn:async()=>{const g=await fetch("/api/system/update-check");if(!g.ok)throw new Error(await _e(g,t("settings.version.checkFailed")));return await g.json()}}),r=i.data,d=Q({queryKey:["system-upgrade-status"],enabled:h,refetchInterval:g=>{var C;const w=(C=g.state.data)==null?void 0:C.state;return h||w&&w!=="idle"?2e3:!1},retry:!0,queryFn:async()=>{const g=await fetch("/api/system/upgrade");if(!g.ok)throw new Error("status");return await g.json()}}).data;v.useEffect(()=>{if(!h)return;const g=d==null?void 0:d.state;g&&g!=="idle"?x.current=!0:g==="idle"&&(d!=null&&d.error)?(x.current=!1,f(!1),N.error(d.error)):g==="idle"&&x.current&&(x.current=!1,f(!1),o.invalidateQueries({queryKey:["system-info"]}),o.removeQueries({queryKey:["system-update-check"]}),N.success(t("common.success")))},[h,d,o,t]);const u=M({mutationFn:async g=>{const w=await fetch("/api/system/upgrade",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({version:g})});if(!w.ok)throw new Error(await _e(w,t("common.error")));return await w.json()},onSuccess:g=>{x.current=!1,f(!0),o.setQueryData(["system-upgrade-status"],g),N.success(t("settings.version.upgradeStarted"))},onError:g=>{N.error(g instanceof Error?g.message:t("common.error"))}}),y=g=>t(g==="launchd"?"settings.version.deploymentLaunchd":g==="systemd"?"settings.version.deploymentSystemd":"settings.version.deploymentNone"),j=h&&(d==null?void 0:d.state)!==void 0,p=(d==null?void 0:d.state)==="downloading"?t("settings.version.stateDownloading"):(d==null?void 0:d.state)==="executing"?t("settings.version.stateExecuting"):null,k=n!=null&&n.canSelfUpdate?null:n!=null&&n.isProd?n!=null&&n.installedViaCli?null:t("settings.version.upgradeDisabledNonCli"):t("settings.version.upgradeDisabledDev");return e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.version.title")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ke,{label:t("settings.version.currentVersion"),value:e.jsx("span",{"data-testid":"settings-version-current",className:"font-mono",children:n?n.version:t("common.loading")})}),e.jsx(Ke,{label:t("settings.version.installMethod"),value:n?n.installedViaCli?t("settings.version.installMethodCli"):t("settings.version.installMethodNonCli"):"-"}),e.jsx(Ke,{label:t("settings.version.deployment"),value:n?y(n.deployment):"-"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(E,{variant:"outline","data-testid":"settings-version-check",onClick:()=>i.refetch(),disabled:i.isFetching||j,children:[i.isFetching?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(Ze,{className:"h-4 w-4"}),i.isFetching?t("settings.version.checking"):t("settings.version.checkUpdate")]}),r&&e.jsxs("span",{className:"text-sm text-muted-foreground","data-testid":"settings-version-latest",children:[r.hasUpdate&&r.latestVersion?t("settings.version.updateAvailable",{version:r.latestVersion}):t("settings.version.upToDate"),r.publishedAt?` · ${t("settings.version.publishedAt",{date:new Date(r.publishedAt).toLocaleDateString(Xe(s))})}`:""]})]}),i.isError&&e.jsx("div",{className:"text-sm text-destructive",children:t("settings.version.checkFailed")}),(r==null?void 0:r.hasUpdate)&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-semibold",children:t("settings.version.changelog")}),e.jsx("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:r.changelog?e.jsx(Wt,{source:r.changelog,basePath:"/"}):e.jsx("div",{className:"text-sm text-muted-foreground",children:t("settings.version.changelogUnavailable")})}),n!=null&&n.canSelfUpdate?e.jsxs(E,{variant:"secondary","data-testid":"settings-version-upgrade",disabled:j||u.isPending,onClick:()=>c(!0),children:[j?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(Jt,{className:"h-4 w-4"}),t("settings.version.upgrade")]}):e.jsxs("div",{className:"space-y-1",children:[k&&e.jsx("div",{className:"text-sm text-muted-foreground",children:k}),e.jsx("div",{className:"text-xs text-muted-foreground font-mono",children:t("settings.version.terminalHint")})]})]}),j&&p&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-border bg-card px-4 py-3","data-testid":"settings-version-upgrade-status",children:[e.jsx(q,{className:"mt-0.5 h-4 w-4 shrink-0 animate-spin text-primary"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-sm font-medium",children:p}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t("settings.version.interruptNotice")})]})]})]}),e.jsx(fe,{open:l,onOpenChange:c,children:e.jsxs(pe,{children:[e.jsxs(we,{children:[e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(xt,{className:"h-5 w-5 text-destructive"}),t("settings.version.upgradeWarningTitle")]}),e.jsx(je,{children:t("settings.version.upgradeWarningBody")})]}),e.jsxs(ve,{children:[e.jsx(be,{onClick:()=>c(!1),children:t("common.cancel")}),e.jsx(Ne,{variant:"destructive","data-testid":"settings-version-upgrade-confirm",onClick:()=>{c(!1),r!=null&&r.latestVersion&&u.mutate(r.latestVersion)},children:t("settings.version.upgrade")})]})]})})]})}const Qe=["terminal_bell","terminal_notification","tmux_window_close","tmux_pane_close","device_tmux_missing","device_disconnect","session_created","session_closed","agent_confirmation_pending","agent_turn_finished","agent_error","watch_triggered","watch_model_unavailable","watch_rule_error"];async function qe(t,o){try{return(await t.json()).error??o}catch{return o}}function Ss(){var d;const{t}=F(),o=B(),s=ge(u=>{var y;return((y=u.settings)==null?void 0:y.language)??"en_US"}),[l,c]=v.useState(""),[h,f]=v.useState(""),[x,a]=v.useState(Qe),n=Q({queryKey:["webhooks"],queryFn:async()=>{const u=await fetch("/api/webhooks");if(!u.ok)throw new Error(await qe(u,t("webhook.loadFailed")));return await u.json()}}),i=M({mutationFn:async()=>{const u=await fetch("/api/webhooks",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:l,secret:h,eventMask:x})});if(!u.ok)throw new Error(await qe(u,t("webhook.createFailed")))},onSuccess:async()=>{c(""),f(""),a(Qe),await o.invalidateQueries({queryKey:["webhooks"]}),N.success(t("common.success"))},onError:u=>{N.error(u instanceof Error?u.message:t("common.error"))}}),r=M({mutationFn:async u=>{const y=await fetch(`/api/webhooks/${u}`,{method:"DELETE"});if(!y.ok)throw new Error(await qe(y,t("webhook.deleteFailed")))},onSuccess:async()=>{await o.invalidateQueries({queryKey:["webhooks"]}),N.success(t("common.success"))},onError:u=>{N.error(u instanceof Error?u.message:t("common.error"))}}),m=((d=n.data)==null?void 0:d.webhooks)??[];return e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("webhook.title")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-12 md:items-end",children:[e.jsxs("div",{className:"md:col-span-6 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-url-input",children:t("webhook.url")}),e.jsx(O,{id:"webhook-url-input","data-testid":"webhook-url-input",value:l,onChange:u=>c(u.target.value),placeholder:"https://example.com/webhook",className:"min-h-10"})]}),e.jsxs("div",{className:"md:col-span-4 space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"webhook-secret-input",children:t("webhook.secret")}),e.jsx(O,{id:"webhook-secret-input","data-testid":"webhook-secret-input",value:h,onChange:u=>f(u.target.value),placeholder:t("webhook.secretPlaceholder"),className:"min-h-10"})]}),e.jsx("div",{className:"md:col-span-2",children:e.jsxs(E,{variant:"secondary",className:"w-full md:w-auto","data-testid":"webhook-add",onClick:()=>i.mutate(),disabled:i.isPending||!l.trim()||!h.trim()||x.length===0,children:[i.isPending?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),t("webhook.add")]})})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("div",{className:"text-sm font-medium",children:t("webhook.eventMask")}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:Qe.map(u=>{const y=x.includes(u);return e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-background px-3 py-2",children:[e.jsx("div",{className:"min-w-0 pr-2 text-sm font-medium",children:t(`notification.eventType.${u}`)}),e.jsx(_,{checked:y,"data-testid":`webhook-event-${u}`,onCheckedChange:j=>{a(p=>j?p.includes(u)?p:[...p,u]:p.filter(k=>k!==u))}})]},u)})})]}),e.jsxs("div",{className:"space-y-2",children:[n.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!n.isLoading&&m.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("webhook.empty")}),m.map(u=>e.jsxs("div",{"data-testid":"webhook-item","data-webhook-url":u.url,className:"flex items-center justify-between gap-3 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:u.url}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(u.createdAt).toLocaleString(Xe(s))})]}),e.jsx(E,{variant:"ghost",size:"icon-sm","data-testid":"webhook-delete",onClick:()=>r.mutate(u.id),disabled:r.isPending,"aria-label":t("common.delete"),title:t("common.delete"),children:e.jsx(te,{className:"h-4 w-4"})})]},u.id))]})]})]})}var Ms=Object.defineProperty,De=Object.getOwnPropertySymbols,ft=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable,lt=(t,o,s)=>o in t?Ms(t,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[o]=s,Ge=(t,o)=>{for(var s in o||(o={}))ft.call(o,s)&&lt(t,s,o[s]);if(De)for(var s of De(o))pt.call(o,s)&&lt(t,s,o[s]);return t},We=(t,o)=>{var s={};for(var l in t)ft.call(t,l)&&o.indexOf(l)<0&&(s[l]=t[l]);if(t!=null&&De)for(var l of De(t))o.indexOf(l)<0&&pt.call(t,l)&&(s[l]=t[l]);return s};/**
32
+ * @license QR Code generator library (TypeScript)
33
+ * Copyright (c) Project Nayuki.
34
+ * SPDX-License-Identifier: MIT
35
+ */var se;(t=>{const o=class S{constructor(a,n,i,r){if(this.version=a,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],a<S.MIN_VERSION||a>S.MAX_VERSION)throw new RangeError("Version value out of range");if(r<-1||r>7)throw new RangeError("Mask value out of range");this.size=a*4+17;let m=[];for(let u=0;u<this.size;u++)m.push(!1);for(let u=0;u<this.size;u++)this.modules.push(m.slice()),this.isFunction.push(m.slice());this.drawFunctionPatterns();const d=this.addEccAndInterleave(i);if(this.drawCodewords(d),r==-1){let u=1e9;for(let y=0;y<8;y++){this.applyMask(y),this.drawFormatBits(y);const j=this.getPenaltyScore();j<u&&(r=y,u=j),this.applyMask(y)}}c(0<=r&&r<=7),this.mask=r,this.applyMask(r),this.drawFormatBits(r),this.isFunction=[]}static encodeText(a,n){const i=t.QrSegment.makeSegments(a);return S.encodeSegments(i,n)}static encodeBinary(a,n){const i=t.QrSegment.makeBytes(a);return S.encodeSegments([i],n)}static encodeSegments(a,n,i=1,r=40,m=-1,d=!0){if(!(S.MIN_VERSION<=i&&i<=r&&r<=S.MAX_VERSION)||m<-1||m>7)throw new RangeError("Invalid value");let u,y;for(u=i;;u++){const g=S.getNumDataCodewords(u,n)*8,w=f.getTotalBits(a,u);if(w<=g){y=w;break}if(u>=r)throw new RangeError("Data too long")}for(const g of[S.Ecc.MEDIUM,S.Ecc.QUARTILE,S.Ecc.HIGH])d&&y<=S.getNumDataCodewords(u,g)*8&&(n=g);let j=[];for(const g of a){s(g.mode.modeBits,4,j),s(g.numChars,g.mode.numCharCountBits(u),j);for(const w of g.getData())j.push(w)}c(j.length==y);const p=S.getNumDataCodewords(u,n)*8;c(j.length<=p),s(0,Math.min(4,p-j.length),j),s(0,(8-j.length%8)%8,j),c(j.length%8==0);for(let g=236;j.length<p;g^=253)s(g,8,j);let k=[];for(;k.length*8<j.length;)k.push(0);return j.forEach((g,w)=>k[w>>>3]|=g<<7-(w&7)),new S(u,n,k,m)}getModule(a,n){return 0<=a&&a<this.size&&0<=n&&n<this.size&&this.modules[n][a]}getModules(){return this.modules}drawFunctionPatterns(){for(let i=0;i<this.size;i++)this.setFunctionModule(6,i,i%2==0),this.setFunctionModule(i,6,i%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const a=this.getAlignmentPatternPositions(),n=a.length;for(let i=0;i<n;i++)for(let r=0;r<n;r++)i==0&&r==0||i==0&&r==n-1||i==n-1&&r==0||this.drawAlignmentPattern(a[i],a[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(a){const n=this.errorCorrectionLevel.formatBits<<3|a;let i=n;for(let m=0;m<10;m++)i=i<<1^(i>>>9)*1335;const r=(n<<10|i)^21522;c(r>>>15==0);for(let m=0;m<=5;m++)this.setFunctionModule(8,m,l(r,m));this.setFunctionModule(8,7,l(r,6)),this.setFunctionModule(8,8,l(r,7)),this.setFunctionModule(7,8,l(r,8));for(let m=9;m<15;m++)this.setFunctionModule(14-m,8,l(r,m));for(let m=0;m<8;m++)this.setFunctionModule(this.size-1-m,8,l(r,m));for(let m=8;m<15;m++)this.setFunctionModule(8,this.size-15+m,l(r,m));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let a=this.version;for(let i=0;i<12;i++)a=a<<1^(a>>>11)*7973;const n=this.version<<12|a;c(n>>>18==0);for(let i=0;i<18;i++){const r=l(n,i),m=this.size-11+i%3,d=Math.floor(i/3);this.setFunctionModule(m,d,r),this.setFunctionModule(d,m,r)}}drawFinderPattern(a,n){for(let i=-4;i<=4;i++)for(let r=-4;r<=4;r++){const m=Math.max(Math.abs(r),Math.abs(i)),d=a+r,u=n+i;0<=d&&d<this.size&&0<=u&&u<this.size&&this.setFunctionModule(d,u,m!=2&&m!=4)}}drawAlignmentPattern(a,n){for(let i=-2;i<=2;i++)for(let r=-2;r<=2;r++)this.setFunctionModule(a+r,n+i,Math.max(Math.abs(r),Math.abs(i))!=1)}setFunctionModule(a,n,i){this.modules[n][a]=i,this.isFunction[n][a]=!0}addEccAndInterleave(a){const n=this.version,i=this.errorCorrectionLevel;if(a.length!=S.getNumDataCodewords(n,i))throw new RangeError("Invalid argument");const r=S.NUM_ERROR_CORRECTION_BLOCKS[i.ordinal][n],m=S.ECC_CODEWORDS_PER_BLOCK[i.ordinal][n],d=Math.floor(S.getNumRawDataModules(n)/8),u=r-d%r,y=Math.floor(d/r);let j=[];const p=S.reedSolomonComputeDivisor(m);for(let g=0,w=0;g<r;g++){let C=a.slice(w,w+y-m+(g<u?0:1));w+=C.length;const D=S.reedSolomonComputeRemainder(C,p);g<u&&C.push(0),j.push(C.concat(D))}let k=[];for(let g=0;g<j[0].length;g++)j.forEach((w,C)=>{(g!=y-m||C>=u)&&k.push(w[g])});return c(k.length==d),k}drawCodewords(a){if(a.length!=Math.floor(S.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let n=0;for(let i=this.size-1;i>=1;i-=2){i==6&&(i=5);for(let r=0;r<this.size;r++)for(let m=0;m<2;m++){const d=i-m,y=(i+1&2)==0?this.size-1-r:r;!this.isFunction[y][d]&&n<a.length*8&&(this.modules[y][d]=l(a[n>>>3],7-(n&7)),n++)}}c(n==a.length*8)}applyMask(a){if(a<0||a>7)throw new RangeError("Mask value out of range");for(let n=0;n<this.size;n++)for(let i=0;i<this.size;i++){let r;switch(a){case 0:r=(i+n)%2==0;break;case 1:r=n%2==0;break;case 2:r=i%3==0;break;case 3:r=(i+n)%3==0;break;case 4:r=(Math.floor(i/3)+Math.floor(n/2))%2==0;break;case 5:r=i*n%2+i*n%3==0;break;case 6:r=(i*n%2+i*n%3)%2==0;break;case 7:r=((i+n)%2+i*n%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[n][i]&&r&&(this.modules[n][i]=!this.modules[n][i])}}getPenaltyScore(){let a=0;for(let m=0;m<this.size;m++){let d=!1,u=0,y=[0,0,0,0,0,0,0];for(let j=0;j<this.size;j++)this.modules[m][j]==d?(u++,u==5?a+=S.PENALTY_N1:u>5&&a++):(this.finderPenaltyAddHistory(u,y),d||(a+=this.finderPenaltyCountPatterns(y)*S.PENALTY_N3),d=this.modules[m][j],u=1);a+=this.finderPenaltyTerminateAndCount(d,u,y)*S.PENALTY_N3}for(let m=0;m<this.size;m++){let d=!1,u=0,y=[0,0,0,0,0,0,0];for(let j=0;j<this.size;j++)this.modules[j][m]==d?(u++,u==5?a+=S.PENALTY_N1:u>5&&a++):(this.finderPenaltyAddHistory(u,y),d||(a+=this.finderPenaltyCountPatterns(y)*S.PENALTY_N3),d=this.modules[j][m],u=1);a+=this.finderPenaltyTerminateAndCount(d,u,y)*S.PENALTY_N3}for(let m=0;m<this.size-1;m++)for(let d=0;d<this.size-1;d++){const u=this.modules[m][d];u==this.modules[m][d+1]&&u==this.modules[m+1][d]&&u==this.modules[m+1][d+1]&&(a+=S.PENALTY_N2)}let n=0;for(const m of this.modules)n=m.reduce((d,u)=>d+(u?1:0),n);const i=this.size*this.size,r=Math.ceil(Math.abs(n*20-i*10)/i)-1;return c(0<=r&&r<=9),a+=r*S.PENALTY_N4,c(0<=a&&a<=2568888),a}getAlignmentPatternPositions(){if(this.version==1)return[];{const a=Math.floor(this.version/7)+2,n=this.version==32?26:Math.ceil((this.version*4+4)/(a*2-2))*2;let i=[6];for(let r=this.size-7;i.length<a;r-=n)i.splice(1,0,r);return i}}static getNumRawDataModules(a){if(a<S.MIN_VERSION||a>S.MAX_VERSION)throw new RangeError("Version number out of range");let n=(16*a+128)*a+64;if(a>=2){const i=Math.floor(a/7)+2;n-=(25*i-10)*i-55,a>=7&&(n-=36)}return c(208<=n&&n<=29648),n}static getNumDataCodewords(a,n){return Math.floor(S.getNumRawDataModules(a)/8)-S.ECC_CODEWORDS_PER_BLOCK[n.ordinal][a]*S.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][a]}static reedSolomonComputeDivisor(a){if(a<1||a>255)throw new RangeError("Degree out of range");let n=[];for(let r=0;r<a-1;r++)n.push(0);n.push(1);let i=1;for(let r=0;r<a;r++){for(let m=0;m<n.length;m++)n[m]=S.reedSolomonMultiply(n[m],i),m+1<n.length&&(n[m]^=n[m+1]);i=S.reedSolomonMultiply(i,2)}return n}static reedSolomonComputeRemainder(a,n){let i=n.map(r=>0);for(const r of a){const m=r^i.shift();i.push(0),n.forEach((d,u)=>i[u]^=S.reedSolomonMultiply(d,m))}return i}static reedSolomonMultiply(a,n){if(a>>>8||n>>>8)throw new RangeError("Byte out of range");let i=0;for(let r=7;r>=0;r--)i=i<<1^(i>>>7)*285,i^=(n>>>r&1)*a;return c(i>>>8==0),i}finderPenaltyCountPatterns(a){const n=a[1];c(n<=this.size*3);const i=n>0&&a[2]==n&&a[3]==n*3&&a[4]==n&&a[5]==n;return(i&&a[0]>=n*4&&a[6]>=n?1:0)+(i&&a[6]>=n*4&&a[0]>=n?1:0)}finderPenaltyTerminateAndCount(a,n,i){return a&&(this.finderPenaltyAddHistory(n,i),n=0),n+=this.size,this.finderPenaltyAddHistory(n,i),this.finderPenaltyCountPatterns(i)}finderPenaltyAddHistory(a,n){n[0]==0&&(a+=this.size),n.pop(),n.unshift(a)}};o.MIN_VERSION=1,o.MAX_VERSION=40,o.PENALTY_N1=3,o.PENALTY_N2=3,o.PENALTY_N3=40,o.PENALTY_N4=10,o.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],o.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],t.QrCode=o;function s(x,a,n){if(a<0||a>31||x>>>a)throw new RangeError("Value out of range");for(let i=a-1;i>=0;i--)n.push(x>>>i&1)}function l(x,a){return(x>>>a&1)!=0}function c(x){if(!x)throw new Error("Assertion error")}const h=class R{constructor(a,n,i){if(this.mode=a,this.numChars=n,this.bitData=i,n<0)throw new RangeError("Invalid argument");this.bitData=i.slice()}static makeBytes(a){let n=[];for(const i of a)s(i,8,n);return new R(R.Mode.BYTE,a.length,n)}static makeNumeric(a){if(!R.isNumeric(a))throw new RangeError("String contains non-numeric characters");let n=[];for(let i=0;i<a.length;){const r=Math.min(a.length-i,3);s(parseInt(a.substring(i,i+r),10),r*3+1,n),i+=r}return new R(R.Mode.NUMERIC,a.length,n)}static makeAlphanumeric(a){if(!R.isAlphanumeric(a))throw new RangeError("String contains unencodable characters in alphanumeric mode");let n=[],i;for(i=0;i+2<=a.length;i+=2){let r=R.ALPHANUMERIC_CHARSET.indexOf(a.charAt(i))*45;r+=R.ALPHANUMERIC_CHARSET.indexOf(a.charAt(i+1)),s(r,11,n)}return i<a.length&&s(R.ALPHANUMERIC_CHARSET.indexOf(a.charAt(i)),6,n),new R(R.Mode.ALPHANUMERIC,a.length,n)}static makeSegments(a){return a==""?[]:R.isNumeric(a)?[R.makeNumeric(a)]:R.isAlphanumeric(a)?[R.makeAlphanumeric(a)]:[R.makeBytes(R.toUtf8ByteArray(a))]}static makeEci(a){let n=[];if(a<0)throw new RangeError("ECI assignment value out of range");if(a<128)s(a,8,n);else if(a<16384)s(2,2,n),s(a,14,n);else if(a<1e6)s(6,3,n),s(a,21,n);else throw new RangeError("ECI assignment value out of range");return new R(R.Mode.ECI,0,n)}static isNumeric(a){return R.NUMERIC_REGEX.test(a)}static isAlphanumeric(a){return R.ALPHANUMERIC_REGEX.test(a)}getData(){return this.bitData.slice()}static getTotalBits(a,n){let i=0;for(const r of a){const m=r.mode.numCharCountBits(n);if(r.numChars>=1<<m)return 1/0;i+=4+m+r.bitData.length}return i}static toUtf8ByteArray(a){a=encodeURI(a);let n=[];for(let i=0;i<a.length;i++)a.charAt(i)!="%"?n.push(a.charCodeAt(i)):(n.push(parseInt(a.substring(i+1,i+3),16)),i+=2);return n}};h.NUMERIC_REGEX=/^[0-9]*$/,h.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,h.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let f=h;t.QrSegment=h})(se||(se={}));(t=>{(o=>{const s=class{constructor(c,h){this.ordinal=c,this.formatBits=h}};s.LOW=new s(0,1),s.MEDIUM=new s(1,0),s.QUARTILE=new s(2,3),s.HIGH=new s(3,2),o.Ecc=s})(t.QrCode||(t.QrCode={}))})(se||(se={}));(t=>{(o=>{const s=class{constructor(c,h){this.modeBits=c,this.numBitsCharCount=h}numCharCountBits(c){return this.numBitsCharCount[Math.floor((c+7)/17)]}};s.NUMERIC=new s(1,[10,12,14]),s.ALPHANUMERIC=new s(2,[9,11,13]),s.BYTE=new s(4,[8,16,16]),s.KANJI=new s(8,[8,10,12]),s.ECI=new s(7,[0,0,0]),o.Mode=s})(t.QrSegment||(t.QrSegment={}))})(se||(se={}));var oe=se;/**
36
+ * @license qrcode.react
37
+ * Copyright (c) Paul O'Shannessy
38
+ * SPDX-License-Identifier: ISC
39
+ */var Ps={L:oe.QrCode.Ecc.LOW,M:oe.QrCode.Ecc.MEDIUM,Q:oe.QrCode.Ecc.QUARTILE,H:oe.QrCode.Ecc.HIGH},wt=128,yt="L",jt="#FFFFFF",vt="#000000",bt=!1,Nt=1,Fs=4,As=0,Ts=.1;function Ct(t,o=0){const s=[];return t.forEach(function(l,c){let h=null;l.forEach(function(f,x){if(!f&&h!==null){s.push(`M${h+o} ${c+o}h${x-h}v1H${h+o}z`),h=null;return}if(x===l.length-1){if(!f)return;h===null?s.push(`M${x+o},${c+o} h1v1H${x+o}z`):s.push(`M${h+o},${c+o} h${x+1-h}v1H${h+o}z`);return}f&&h===null&&(h=x)})}),s.join("")}function Et(t,o){return t.slice().map((s,l)=>l<o.y||l>=o.y+o.h?s:s.map((c,h)=>h<o.x||h>=o.x+o.w?c:!1))}function Rs(t,o,s,l){if(l==null)return null;const c=t.length+s*2,h=Math.floor(o*Ts),f=c/o,x=(l.width||h)*f,a=(l.height||h)*f,n=l.x==null?t.length/2-x/2:l.x*f,i=l.y==null?t.length/2-a/2:l.y*f,r=l.opacity==null?1:l.opacity;let m=null;if(l.excavate){let u=Math.floor(n),y=Math.floor(i),j=Math.ceil(x+n-u),p=Math.ceil(a+i-y);m={x:u,y,w:j,h:p}}const d=l.crossOrigin;return{x:n,y:i,h:a,w:x,excavation:m,opacity:r,crossOrigin:d}}function Is(t,o){return o!=null?Math.max(Math.floor(o),0):t?Fs:As}function kt({value:t,level:o,minVersion:s,includeMargin:l,marginSize:c,imageSettings:h,size:f,boostLevel:x}){let a=$.useMemo(()=>{const u=(Array.isArray(t)?t:[t]).reduce((y,j)=>(y.push(...oe.QrSegment.makeSegments(j)),y),[]);return oe.QrCode.encodeSegments(u,Ps[o],s,void 0,void 0,x)},[t,o,s,x]);const{cells:n,margin:i,numCells:r,calculatedImageSettings:m}=$.useMemo(()=>{let d=a.getModules();const u=Is(l,c),y=d.length+u*2,j=Rs(d,f,u,h);return{cells:d,margin:u,numCells:y,calculatedImageSettings:j}},[a,f,h,l,c]);return{qrcode:a,margin:i,cells:n,numCells:r,calculatedImageSettings:m}}var Ls=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),$s=$.forwardRef(function(o,s){const l=o,{value:c,size:h=wt,level:f=yt,bgColor:x=jt,fgColor:a=vt,includeMargin:n=bt,minVersion:i=Nt,boostLevel:r,marginSize:m,imageSettings:d}=l,y=We(l,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:j}=y,p=We(y,["style"]),k=d==null?void 0:d.src,g=$.useRef(null),w=$.useRef(null),C=$.useCallback(V=>{g.current=V,typeof s=="function"?s(V):s&&(s.current=V)},[s]),[D,P]=$.useState(!1),{margin:A,cells:T,numCells:I,calculatedImageSettings:L}=kt({value:c,level:f,minVersion:i,boostLevel:r,includeMargin:n,marginSize:m,imageSettings:d,size:h});$.useEffect(()=>{if(g.current!=null){const V=g.current,J=V.getContext("2d");if(!J)return;let Pe=T;const X=w.current,me=L!=null&&X!==null&&X.complete&&X.naturalHeight!==0&&X.naturalWidth!==0;me&&L.excavation!=null&&(Pe=Et(T,L.excavation));const Fe=window.devicePixelRatio||1;V.height=V.width=h*Fe;const ue=h/I*Fe;J.scale(ue,ue),J.fillStyle=x,J.fillRect(0,0,I,I),J.fillStyle=a,Ls?J.fill(new Path2D(Ct(Pe,A))):T.forEach(function(Ae,Te){Ae.forEach(function(b,z){b&&J.fillRect(z+A,Te+A,1,1)})}),L&&(J.globalAlpha=L.opacity),me&&J.drawImage(X,L.x+A,L.y+A,L.w,L.h)}}),$.useEffect(()=>{P(!1)},[k]);const Y=Ge({height:h,width:h},j);let K=null;return k!=null&&(K=$.createElement("img",{src:k,key:k,style:{display:"none"},onLoad:()=>{P(!0)},ref:w,crossOrigin:L==null?void 0:L.crossOrigin})),$.createElement($.Fragment,null,$.createElement("canvas",Ge({style:Y,height:h,width:h,ref:C,role:"img"},p)),K)});$s.displayName="QRCodeCanvas";var St=$.forwardRef(function(o,s){const l=o,{value:c,size:h=wt,level:f=yt,bgColor:x=jt,fgColor:a=vt,includeMargin:n=bt,minVersion:i=Nt,boostLevel:r,title:m,marginSize:d,imageSettings:u}=l,y=We(l,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:j,cells:p,numCells:k,calculatedImageSettings:g}=kt({value:c,level:f,minVersion:i,boostLevel:r,includeMargin:n,marginSize:d,imageSettings:u,size:h});let w=p,C=null;u!=null&&g!=null&&(g.excavation!=null&&(w=Et(p,g.excavation)),C=$.createElement("image",{href:u.src,height:g.h,width:g.w,x:g.x+j,y:g.y+j,preserveAspectRatio:"none",opacity:g.opacity,crossOrigin:g.crossOrigin}));const D=Ct(w,j);return $.createElement("svg",Ge({height:h,width:h,viewBox:`0 0 ${k} ${k}`,ref:s,role:"img"},y),!!m&&$.createElement("title",null,m),$.createElement("path",{fill:x,d:`M0,0 h${k}v${k}H0z`,shapeRendering:"crispEdges"}),$.createElement("path",{fill:a,d:D,shapeRendering:"crispEdges"}),C)});St.displayName="QRCodeSVG";const Le=1500;async function he(t,o){try{return(await t.json()).error??o}catch{return o}}function Mt({open:t,onOpenChange:o,accountId:s,accountName:l}){const{t:c}=F(),h=B(),[f,x]=v.useState(null),[a,n]=v.useState("starting"),[i,r]=v.useState(null),m=v.useRef(null),d=v.useRef(0),u=v.useRef(null),y=v.useCallback(()=>{m.current!==null&&(clearTimeout(m.current),m.current=null)},[]),j=v.useCallback(()=>{var P;y(),(P=u.current)==null||P.abort(),u.current=null,d.current+=1},[y]),p=v.useCallback(async()=>{j(),await h.invalidateQueries({queryKey:["weixin-accounts"]}),N.success(c("weixin.bindSuccess")),o(!1)},[j,o,h,c]),k=v.useCallback(async(P,A,T)=>{try{const I=await fetch(`/api/settings/weixin/accounts/${s}/users`,{signal:A});if(d.current!==P)return;if(!I.ok)throw new Error(await he(I,c("weixin.loginFailed")));const L=await I.json();if(d.current!==P)return;const Y=L.users.find(K=>!T.has(K.userId)||K.lastInboundAt!==T.get(K.userId));if(Y){if(n("binding"),r(c("weixin.bindingInProgress")),Y.status==="pending"){const K=await fetch(`/api/settings/weixin/accounts/${s}/users/${encodeURIComponent(Y.userId)}/approve`,{method:"POST",signal:A});if(d.current!==P)return;if(!K.ok)throw new Error(await he(K,c("weixin.approveFailed")))}await p();return}m.current=setTimeout(()=>void k(P,A,T),Le)}catch(I){if(A.aborted||d.current!==P)return;n("error"),r(I instanceof Error?I.message:c("weixin.loginFailed"))}},[s,p,c]),g=v.useCallback(async(P,A)=>{try{const T=await fetch(`/api/settings/weixin/accounts/${s}/login/status`,{signal:A});if(d.current!==P)return;if(!T.ok)throw new Error(await he(T,c("weixin.loginFailed")));const I=await T.json();if(d.current!==P)return;if(I.status==="expired"){n("expired"),r(c("weixin.loginExpired"));return}if(I.status==="error"){n("error"),r(c("weixin.loginError",{message:I.message??""}));return}if(I.loggedIn||I.status==="confirmed"){const L=await fetch(`/api/settings/weixin/accounts/${s}/users`,{signal:A});if(d.current!==P)return;if(!L.ok)throw new Error(await he(L,c("weixin.loginFailed")));const Y=await L.json();if(d.current!==P)return;const K=new Map(Y.users.map(V=>[V.userId,V.lastInboundAt]));n("awaitMessage"),r(c("weixin.scanConfirmedSendHint")),m.current=setTimeout(()=>void k(P,A,K),Le);return}n("scanning"),r(c("weixin.scanQrcodeHint")),m.current=setTimeout(()=>void g(P,A),Le)}catch(T){if(A.aborted||d.current!==P)return;n("error"),r(T instanceof Error?T.message:c("weixin.loginFailed"))}},[s,k,c]),w=v.useCallback(async()=>{j();const P=d.current,A=new AbortController;u.current=A,n("starting"),r(null),x(null);try{const T=await fetch(`/api/settings/weixin/accounts/${s}/login/start`,{method:"POST",signal:A.signal});if(d.current!==P)return;if(!T.ok)throw new Error(await he(T,c("weixin.loginFailed")));const I=await T.json();if(d.current!==P)return;x(I.qrcodeUrl),n("scanning"),r(c("weixin.scanQrcodeHint")),m.current=setTimeout(()=>void g(P,A.signal),Le)}catch(T){if(A.signal.aborted||d.current!==P)return;n("error"),r(T instanceof Error?T.message:c("weixin.loginFailed"))}},[s,j,g,c]);v.useEffect(()=>{if(!t){j();return}return w(),j},[t,s]);const C=a==="starting",D=a==="expired"||a==="error";return e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-sm","data-testid":`weixin-account-login-modal-${s}`,children:[e.jsxs(ie,{children:[e.jsx(re,{children:c("weixin.scanToLogin")}),e.jsx(Ce,{children:l})]}),e.jsxs("div",{className:"flex flex-col items-center gap-3 py-2",children:[e.jsxs("div",{className:"flex h-56 w-56 items-center justify-center rounded-lg border border-border bg-white",children:[C&&e.jsx(q,{className:"h-8 w-8 animate-spin text-muted-foreground"}),!C&&f&&e.jsx(St,{value:f,size:208,marginSize:3,"data-testid":`weixin-account-login-qrcode-${s}`}),!C&&!f&&e.jsx(Ve,{className:"h-10 w-10 text-muted-foreground"})]}),i&&e.jsx("p",{className:"text-center text-sm font-medium","data-testid":`weixin-account-login-status-${s}`,children:i})]}),e.jsxs(de,{children:[D&&e.jsxs(E,{variant:"secondary","data-testid":"weixin-account-login-refresh",onClick:()=>void w(),children:[e.jsx(Ze,{className:"h-4 w-4"}),c("weixin.refreshQrcode")]}),e.jsx(E,{variant:"outline",onClick:()=>o(!1),children:c("weixin.closeLogin")})]})]})})}const Ds="min-h-10";async function ct(t,o){try{return(await t.json()).error??o}catch{return o}}function Os({open:t,onOpenChange:o,account:s}){const{t:l}=F(),c=B(),h=!!s,[f,x]=v.useState(""),[a,n]=v.useState(!0),[i,r]=v.useState(null);v.useEffect(()=>{t&&(x((s==null?void 0:s.name)??""),n((s==null?void 0:s.enabled)??!0))},[t,s]);const m=M({mutationFn:async()=>{const p=await fetch("/api/settings/weixin/accounts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:f.trim(),enabled:a,allowAuthRequests:!0})});if(!p.ok)throw new Error(await ct(p,l("weixin.createFailed")));return await p.json()},onSuccess:async p=>{await c.invalidateQueries({queryKey:["weixin-accounts"]}),N.success(l("weixin.accountCreated")),o(!1),r({id:p.accountId,name:f.trim()})},onError:p=>{N.error(p instanceof Error?p.message:l("common.error"))}}),d=M({mutationFn:async()=>{if(!s)throw new Error(l("weixin.updateFailed"));const p=await fetch(`/api/settings/weixin/accounts/${s.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:f.trim(),enabled:a})});if(!p.ok)throw new Error(await ct(p,l("weixin.updateFailed")))},onSuccess:async()=>{await c.invalidateQueries({queryKey:["weixin-accounts"]}),N.success(l("weixin.accountUpdated")),o(!1)},onError:p=>{N.error(p instanceof Error?p.message:l("common.error"))}}),u=m.isPending||d.isPending,y=f.trim().length>0,j=()=>{!y||u||(h?d.mutate():m.mutate())};return e.jsxs(e.Fragment,{children:[e.jsx(ae,{open:t,onOpenChange:o,children:e.jsxs(ne,{className:"sm:max-w-lg","data-testid":h?`weixin-account-edit-modal-${s==null?void 0:s.id}`:"weixin-account-add-modal",children:[e.jsx(ie,{children:e.jsx(re,{children:l(h?"weixin.editAccount":"weixin.addAccount")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"weixin-account-name",children:l("weixin.accountName")}),e.jsx(O,{id:"weixin-account-name","data-testid":"weixin-account-name-input",value:f,onChange:p=>x(p.target.value),placeholder:l("weixin.accountNamePlaceholder"),className:Ds})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-3 rounded-lg border border-border bg-background px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium",children:l("weixin.enableAccount")}),e.jsx(_,{checked:a,"data-testid":"weixin-account-enabled",onCheckedChange:p=>n(!!p)})]})]}),e.jsxs(de,{children:[e.jsx(E,{variant:"outline",onClick:()=>o(!1),disabled:u,children:l("common.cancel")}),e.jsxs(E,{variant:"secondary","data-testid":"weixin-account-form-submit",onClick:j,disabled:!y||u,children:[u?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),l("common.save")]})]})]})}),i&&e.jsx(Mt,{open:!!i,onOpenChange:p=>{p||r(null)},accountId:i.id,accountName:i.name})]})}async function Ue(t,o){try{return(await t.json()).error??o}catch{return o}}function Bs({account:t,onEdit:o}){const{t:s}=F(),l=B(),[c,h]=v.useState(!1),f=t.loggedIn&&t.authorizedCount>0,x=M({mutationFn:async r=>{const m=await fetch(`/api/settings/weixin/accounts/${t.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:r})});if(!m.ok)throw new Error(await Ue(m,s("weixin.updateFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["weixin-accounts"]})},onError:r=>{N.error(r instanceof Error?r.message:s("common.error"))}}),a=M({mutationFn:async()=>{const r=await fetch(`/api/settings/weixin/accounts/${t.id}/test`,{method:"POST"});if(!r.ok)throw new Error(await Ue(r,s("weixin.testMessageFailed")))},onSuccess:()=>{N.success(s("weixin.testMessageSent"))},onError:r=>{N.error(r instanceof Error?r.message:s("weixin.testMessageFailed"))}}),n=M({mutationFn:async()=>{const r=await fetch(`/api/settings/weixin/accounts/${t.id}`,{method:"DELETE"});if(!r.ok)throw new Error(await Ue(r,s("weixin.deleteFailed")))},onSuccess:async()=>{await l.invalidateQueries({queryKey:["weixin-accounts"]}),N.success(s("weixin.accountDeleted"))},onError:r=>{N.error(r instanceof Error?r.message:s("common.error"))}}),i=t.loggedIn?f?{label:s("weixin.bound"),tone:"success"}:{label:s("weixin.unbound"),tone:"muted"}:{label:s("weixin.notLoggedIn"),tone:"muted"};return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-3 sm:flex-row sm:items-center sm:justify-between","data-testid":`weixin-account-card-${t.id}`,"data-account-name":t.name,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx(_,{checked:t.enabled,disabled:x.isPending,onCheckedChange:r=>x.mutate(!!r),"data-testid":`weixin-account-enabled-${t.id}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate font-medium",children:t.name}),e.jsx("span",{className:mt("shrink-0 rounded px-1.5 py-0.5 text-xs font-medium",i.tone==="success"?"bg-emerald-500/15 text-emerald-600 dark:text-emerald-400":"bg-muted text-muted-foreground"),"data-testid":`weixin-account-login-state-${t.id}`,children:i.label}),f&&t.needsReactivationCount>0&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 rounded bg-destructive/15 px-1.5 py-0.5 text-xs font-medium text-destructive",title:s("weixin.reactivationHint"),"data-testid":`weixin-account-needs-reactivation-${t.id}`,children:[e.jsx(xt,{className:"h-3.5 w-3.5"}),s("weixin.needsReactivation")]})]}),f&&t.needsReactivationCount>0&&e.jsx("div",{className:"mt-0.5 text-xs text-muted-foreground",children:s("weixin.reactivationHint")})]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-1",children:[f?e.jsxs(e.Fragment,{children:[e.jsxs(E,{variant:"ghost",size:"sm","data-testid":`weixin-account-relogin-${t.id}`,onClick:()=>h(!0),children:[e.jsx(Ve,{className:"h-4 w-4"}),s("weixin.relogin")]}),e.jsxs(E,{variant:"ghost",size:"sm","data-testid":`weixin-account-test-${t.id}`,onClick:()=>a.mutate(),disabled:a.isPending,children:[e.jsx(gt,{className:"h-4 w-4"}),s("weixin.testMessage")]})]}):e.jsxs(E,{variant:"secondary",size:"sm","data-testid":`weixin-account-login-${t.id}`,onClick:()=>h(!0),children:[e.jsx(Ve,{className:"h-4 w-4"}),s("weixin.bindAction")]}),e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("common.edit"),"data-testid":`weixin-account-edit-${t.id}`,onClick:()=>o(t),children:e.jsx(Oe,{className:"h-4 w-4"})}),e.jsx(E,{variant:"ghost",size:"icon-sm",title:s("weixin.deleteAccount"),"data-testid":`weixin-account-delete-${t.id}`,onClick:()=>n.mutate(),disabled:n.isPending,children:e.jsx(te,{className:"h-4 w-4 text-destructive"})})]}),e.jsx(Mt,{open:c,onOpenChange:h,accountId:t.id,accountName:t.name})]})}async function zs(t,o){try{return(await t.json()).error??o}catch{return o}}function _s(){var n;const{t}=F(),[o,s]=v.useState(!1),[l,c]=v.useState(void 0),h=Q({queryKey:["weixin-accounts"],queryFn:async()=>{const i=await fetch("/api/settings/weixin/accounts");if(!i.ok)throw new Error(await zs(i,t("weixin.loadAccountsFailed")));return await i.json()}}),f=((n=h.data)==null?void 0:n.accounts)??[],x=()=>{c(void 0),s(!0)},a=i=>{c(i),s(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsxs(G,{className:"flex flex-row items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(W,{children:t("weixin.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("weixin.subtitle")})]}),e.jsxs(E,{variant:"secondary","data-testid":"weixin-add-account",onClick:x,children:[e.jsx(xe,{className:"h-4 w-4"}),t("weixin.addAccount")]})]}),e.jsxs(H,{className:"space-y-3",children:[e.jsx("p",{className:"rounded-lg border border-border bg-muted/40 p-3 text-xs text-muted-foreground",children:t("weixin.replyOnlyNotice")}),h.isLoading&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("common.loading")}),!h.isLoading&&f.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t("weixin.noAccounts")}),f.map(i=>e.jsx(Bs,{account:i,onEdit:a},i.id))]})]}),e.jsx(Os,{open:o,onOpenChange:s,account:l})]})}async function Je(t,o){try{return(await t.json()).error??o}catch{return o}}function ea(){var Ae,Te;const{t}=F(),o=B(),{refreshSettings:s}=ge(),[l,c]=v.useState("general"),h=It(b=>b.theme),f=ge(b=>b.updateTheme),x=h==="dark",[a,n]=v.useState("tmex"),[i,r]=v.useState(window.location.origin),[m,d]=v.useState("en_US"),[u,y]=v.useState(6),[j,p]=v.useState(3),[k,g]=v.useState(!0),[w,C]=v.useState(!0),[D,P]=v.useState(!0),[A,T]=v.useState(!0),[I,L]=v.useState(2),[Y,K]=v.useState(10),[V,J]=v.useState(!1),Pe=b=>{const z=b?"dark":"light";f(z),document.documentElement.classList.toggle("dark",z==="dark")},X=Q({queryKey:["site-settings"],queryFn:async()=>{const b=await fetch("/api/settings/site");if(!b.ok)throw new Error(await Je(b,t("settings.loadFailed")));return await b.json()}});v.useEffect(()=>{var z;const b=(z=X.data)==null?void 0:z.settings;b&&(n(b.siteName),r(b.siteUrl),d(b.language??"en_US"),y(b.bellThrottleSeconds),p(b.notificationThrottleSeconds??3),g(b.enableBrowserNotificationToast??!0),C(b.enableNotificationPush??!0),P(b.enableBellPush??!0),T(b.enableBellSound??!0))},[(Ae=X.data)==null?void 0:Ae.settings]);const me=M({mutationFn:async()=>{const z=await fetch("/api/settings/site",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({siteName:a,siteUrl:i,language:m,bellThrottleSeconds:u,notificationThrottleSeconds:j,enableBrowserNotificationToast:k,enableNotificationPush:w,enableBellPush:D,enableBellSound:A,sshReconnectMaxRetries:I,sshReconnectDelaySeconds:Y})});if(!z.ok)throw new Error(await Je(z,t("settings.saveFailed")))},onSuccess:async()=>{var b,z;await Promise.all([o.invalidateQueries({queryKey:["site-settings"]}),s()]),N.success(t("settings.settingsSaved")),((z=(b=X.data)==null?void 0:b.settings)==null?void 0:z.language)!==m&&(Kt.changeLanguage(m),J(!0))},onError:b=>{N.error(b instanceof Error?b.message:t("common.error"))}}),Fe=[{value:"general",label:t("settings.tabGroup.general"),icon:Lt,testId:"settings-tab-general"},{value:"terminal",label:t("settings.tabGroup.terminal"),icon:Ye,testId:"settings-tab-terminal"},{value:"devicesAndFiles",label:t("settings.tabGroup.devicesAndFiles"),icon:ss,testId:"settings-tab-devicesAndFiles"},{value:"notifications",label:t("settings.tabGroup.notifications"),icon:$t,testId:"settings-tab-notifications"},{value:"ai",label:t("settings.tabGroup.ai"),icon:Dt,testId:"settings-tab-ai"}],ue=e.jsx("div",{className:"flex justify-end pt-2",children:e.jsxs(E,{variant:"secondary","data-testid":"settings-save",onClick:()=>me.mutate(),disabled:me.isPending,className:"w-full sm:w-auto",children:[e.jsx(ee,{className:"h-4 w-4"}),t("common.save")]})});return e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-4 p-3 pb-[calc(2rem+env(safe-area-inset-bottom))] sm:gap-6 sm:p-5","data-testid":"settings-page",children:[e.jsx(Ot,{value:l,onValueChange:b=>c(b),children:e.jsx(Bt,{className:"w-full gap-1 !justify-start overflow-x-auto rounded-xl border border-border/60 p-1.5 group-data-horizontal/tabs:h-12 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:Fe.map(b=>{const z=b.icon;return e.jsxs(zt,{value:b.value,"data-testid":b.testId,className:mt(_t,"min-w-max gap-2 px-3.5"),children:[e.jsx(z,{}),b.label]},b.value)})})}),l==="general"&&e.jsxs(e.Fragment,{children:[e.jsxs(U,{className:"border-0 ring-0",children:[e.jsx(G,{children:e.jsx(W,{children:t("settings.siteSettings")})}),e.jsxs(H,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-name-input",children:t("settings.siteName")}),e.jsx(O,{id:"site-name-input",value:a,onChange:b=>n(b.target.value),placeholder:t("settings.siteNamePlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"site-url-input",children:t("settings.siteUrl")}),e.jsx(O,{id:"site-url-input",value:i,onChange:b=>r(b.target.value),placeholder:t("settings.siteUrlPlaceholder"),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"language-select",children:t("settings.language")}),e.jsxs(Ee,{value:m,onValueChange:b=>{b&&d(b)},children:[e.jsx(ke,{id:"language-select","data-testid":"settings-language-select",className:"w-full min-h-10",children:e.jsx(Se,{placeholder:t("settings.language"),children:((Te=et.locales.find(b=>b.code===m))==null?void 0:Te.nativeName)??m})}),e.jsx(Me,{className:"max-h-[var(--tmex-viewport-height)]",children:et.locales.map(b=>e.jsx(le,{value:b.code,children:b.nativeName},b.code))})]}),V&&e.jsx("p",{className:"mt-1 text-xs text-primary","data-testid":"settings-refresh-notice",children:t("settings.refreshToApply")})]}),e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.theme")})}),e.jsx(_,{checked:x,onCheckedChange:b=>Pe(!!b),"data-testid":"settings-theme-toggle"})]})}),ue]})]}),e.jsx(ks,{})]}),l==="devicesAndFiles"&&e.jsxs(e.Fragment,{children:[e.jsx(rs,{}),e.jsx(os,{})]}),l==="notifications"&&e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"border-0 ring-0",children:e.jsxs(H,{className:"space-y-6 pt-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableNotificationPush")})}),e.jsx(_,{checked:w,onCheckedChange:b=>C(!!b),"data-testid":"settings-enable-notification-push"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBellPush")})}),e.jsx(_,{checked:D,onCheckedChange:b=>P(!!b),"data-testid":"settings-enable-bell-push"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBellSound")})}),e.jsx(_,{checked:A,onCheckedChange:b=>T(!!b),"data-testid":"settings-enable-bell-sound"})]}),e.jsxs("div",{className:"flex min-h-10 items-center justify-between gap-4 rounded-lg border border-border bg-card px-4 py-2.5",children:[e.jsx("div",{className:"min-w-0 pr-2",children:e.jsx("div",{className:"text-sm font-medium",children:t("settings.enableBrowserNotificationToast")})}),e.jsx(_,{checked:k,onCheckedChange:b=>g(!!b),"data-testid":"settings-enable-browser-notification-toast"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"bell-throttle-input",children:t("settings.bellThrottle")}),e.jsx(O,{id:"bell-throttle-input",type:"number",value:u,min:0,max:300,onChange:b=>y(Number(b.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"notification-throttle-input",children:t("settings.notificationThrottle")}),e.jsx(O,{id:"notification-throttle-input",type:"number",value:j,min:0,max:300,onChange:b=>p(Number(b.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-retries-input",children:t("settings.sshReconnectMaxRetries")}),e.jsx(O,{id:"ssh-reconnect-retries-input",type:"number",value:I,min:0,max:20,onChange:b=>L(Number(b.target.value)),className:"min-h-10"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-medium",htmlFor:"ssh-reconnect-delay-input",children:t("settings.sshReconnectDelay")}),e.jsx(O,{id:"ssh-reconnect-delay-input",type:"number",value:Y,min:1,max:300,onChange:b=>K(Number(b.target.value)),className:"min-h-10"})]})]}),ue]})}),e.jsx(Cs,{}),e.jsx(_s,{}),e.jsx(Ss,{})]}),l==="ai"&&e.jsxs(e.Fragment,{children:[e.jsx(ps,{}),e.jsx(ys,{})]}),l==="terminal"&&e.jsx(Es,{})]})}function ta(){const{t}=F();return e.jsx(e.Fragment,{children:t("sidebar.settings")})}function sa(){const{t}=F(),[o,s]=v.useState(!1),l=M({mutationFn:async()=>{const c=await fetch("/api/settings/restart",{method:"POST"});if(!c.ok)throw new Error(await Je(c,t("settings.restartFailed")))},onSuccess:()=>{N.success(t("settings.restartScheduled"))},onError:c=>{N.error(c instanceof Error?c.message:t("common.error"))}});return e.jsxs(e.Fragment,{children:[e.jsx(E,{variant:"ghost",size:"icon-sm",onClick:()=>s(!0),disabled:l.isPending,"aria-label":t("settings.restartGateway"),title:t("settings.restartGateway"),className:"text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(Gt,{className:"h-4 w-4"})}),e.jsx(fe,{open:o,onOpenChange:s,children:e.jsxs(pe,{children:[e.jsxs(we,{children:[e.jsx(ye,{children:t("settings.restartGateway")}),e.jsx(je,{children:t("settings.restartConfirm")})]}),e.jsxs(ve,{children:[e.jsx(be,{onClick:()=>s(!1),children:t("common.cancel")}),e.jsx(Ne,{variant:"destructive",onClick:()=>{l.mutate(),s(!1)},children:t("common.confirm")})]})]})})]})}export{sa as PageActions,ta as PageTitle,ea as default};
@@ -1,4 +1,4 @@
1
- import{Y as T,r as v,j as e,X as S,u as I,an as se,ao as ne,ap as re,aq as ae,ar as oe,am as F,as as B,at as H,B as N,C as Ie,F as Ce,H as _e,I as Se,G as Me,M as ze,x as J,c as K,N as Te,O as Ee,R as Be,U as X,au as $e,av as qe,V as ie,v as Ae,aw as Pe,af as Oe,ax as Re,ay as h,d as Fe,az as He,aA as Ke,P as Le,aB as We,a2 as Z,aC as De}from"./index-U4iZ6Kxr.js";import{M as Ue,r as Ge}from"./index-C-RSAqjj.js";import{K as Qe,S as Y}from"./send-e_FTy5nC.js";import{Z as de}from"./zap-ClXbg92C.js";/**
1
+ import{Y as T,r as v,j as e,X as S,u as I,$ as se,a0 as ne,a1 as re,a2 as ae,a3 as oe,a4 as F,a5 as $,a6 as H,B as N,C as Ie,F as Ce,H as _e,I as Se,G as Me,M as ze,x as J,c as K,N as Te,O as Ee,R as $e,U as X,a7 as Be,a8 as qe,V as ie,v as Ae,a9 as Pe,aa as Oe,ab as Re,ac as h,d as Fe,ad as He,ae as Ke,P as Le,af as We,ag as Z,ah as De}from"./index-CxD8veUJ.js";import{M as Ue,r as Ge}from"./index-DDvqV24J.js";import{K as Qe,S as Y}from"./send-D0SbMcl5.js";import{Z as de}from"./zap-D-Szn4JY.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -35,4 +35,4 @@ import{Y as T,r as v,j as e,X as S,u as I,an as se,ao as ne,ap as re,aq as ae,ar
35
35
  * See the LICENSE file in the root directory of this source tree.
36
36
  */const it=[["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"}]],dt=T("wrench",it);function lt(t){const s=t.split(`
37
37
  `),n=[];let i=[],o=!1;const d=()=>{const c=i.join(`
38
- `);c.trim()&&n.push(c),i=[]};for(const c of s){if(/^\s*(```|~~~)/.test(c)){o=!o,i.push(c);continue}if(!o&&c.trim()===""){d();continue}i.push(c)}return d(),n}const ct={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,...n})=>e.jsx("code",{...n,className:S("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"})},ut=v.memo(function({content:s}){return e.jsx(Ue,{remarkPlugins:[Ge],components:ct,children:s})});function mt({text:t,streaming:s=!1,className:n}){const i=v.useMemo(()=>lt(t),[t]);return e.jsxs("div",{className:S("flex min-w-0 flex-col gap-2 text-sm leading-relaxed",n),children:[i.map((o,d)=>e.jsx(ut,{content:o},d)),s&&e.jsx("span",{"data-testid":"agent-streaming-cursor",className:"bg-foreground inline-block h-4 w-2 animate-pulse self-start"})]})}function xt({text:t,streaming:s=!1,className:n}){return e.jsx("div",{"data-testid":"agent-assistant-message",className:S("min-w-0 max-w-full self-start",n),children:e.jsx(mt,{text:t,streaming:s})})}function pt({text:t,streaming:s=!1,className:n}){const{t:i}=I();return e.jsxs(se,{"data-testid":"agent-reasoning-block",className:S("min-w-0 max-w-full self-start",n),children:[e.jsxs(ne,{className:"text-muted-foreground hover:text-foreground group flex items-center gap-1 text-xs",children:[e.jsx(re,{className:"size-3 transition-transform group-data-[panel-open]:rotate-90"}),e.jsx(Ze,{className:"size-3"}),e.jsx("span",{children:i("agent.reasoning.title")}),s&&e.jsx(ae,{className:"size-3 animate-spin"})]}),e.jsx(oe,{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})})]})}const ft=["send_input","read_screen","web_search","fetch_url","run_command","get_pane_info"],gt=["send_input","read_screen","web_search","fetch_url"];function C(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function $(t){if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function ht(t){return C(t.output)&&typeof t.output.error=="string"?t.output.error:t.isError?$(t.output):null}function ee(t){switch(t){case"send_input":return e.jsx(Qe,{className:"size-3.5"});case"read_screen":return e.jsx(ze,{className:"size-3.5"});case"web_search":return e.jsx(st,{className:"size-3.5"});case"fetch_url":return e.jsx(Me,{className:"size-3.5"});default:return e.jsx(dt,{className:"size-3.5"})}}const le=v.createContext(!1);function E({label:t,text:s}){const n=v.useContext(le);return e.jsxs(se,{defaultOpen:n,children:[e.jsxs(ne,{className:"text-muted-foreground hover:text-foreground group flex items-center gap-1 text-xs",children:[e.jsx(re,{className:"size-3 transition-transform group-data-[panel-open]:rotate-90"}),e.jsx("span",{children:t})]}),e.jsx(oe,{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 jt(t){if(typeof t!="string")return null;try{const s=JSON.parse(t);return Array.isArray(s)?s.filter(C).map(n=>({title:typeof n.title=="string"?n.title:"",url:typeof n.url=="string"?n.url:"",snippet:typeof n.snippet=="string"?n.snippet:""})).filter(n=>n.url):null}catch{return null}}function wt({call:t}){const{t:s}=I(),n=C(t.input)?t.input:{},i=typeof n.text=="string"?n.text:"",o=Array.isArray(n.keys)?n.keys.filter(m=>typeof m=="string"):[],d=Array.isArray(n.combos)?n.combos.filter(C):[],c=C(t.output)?t.output:{},f=typeof c.screenTail=="string"?c.screenTail:"",l=o.length>0||d.length>0;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[i&&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:i}),l&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[o.map((m,g)=>e.jsx(J,{variant:"outline",className:"font-mono",children:m},`k-${g}-${m}`)),d.map((m,g)=>{const x=Array.isArray(m.modifiers)?m.modifiers.filter(k=>typeof k=="string"):[],w=typeof m.key=="string"?m.key:"";if(!w&&x.length===0)return null;const u=[...x.map(k=>`${k.charAt(0).toUpperCase()}${k.slice(1)}`),w].filter(Boolean).join("+");return e.jsx(J,{variant:"outline",className:"font-mono",children:u},`c-${g}-${u}`)})]}),f&&e.jsx(E,{label:s("agent.tool.result"),text:f})]})}function bt({call:t}){const{t:s}=I(),n=C(t.output)?t.output:{},i=typeof n.screen=="string"?n.screen:"";return i?e.jsx(E,{label:s("agent.tool.screen"),text:i}):null}function yt({call:t}){const{t:s}=I(),n=C(t.input)?t.input:{},i=typeof n.query=="string"?n.query:"",o=t.resolved&&!t.isError&&!t.denied?jt(t.output):null;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[i&&e.jsxs("p",{className:"text-muted-foreground text-xs break-words",children:["“",i,"”"]}),o&&o.length>0&&e.jsx("ul",{className:"flex flex-col gap-1",children:o.map(d=>e.jsxs("li",{className:"min-w-0 text-xs",children:[e.jsx("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",className:"text-primary block truncate underline underline-offset-2",title:d.title||d.url,children:d.title||d.url}),d.snippet&&e.jsx("p",{className:"text-muted-foreground line-clamp-2 break-words",children:d.snippet})]},d.url))}),t.resolved&&!t.isError&&!t.denied&&!o&&typeof t.output=="string"&&e.jsx(E,{label:s("agent.tool.result"),text:t.output})]})}function vt({call:t}){const{t:s}=I(),n=C(t.input)?t.input:{},i=typeof n.url=="string"?n.url:"",o=typeof t.output=="string"?t.output:"";return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[i&&e.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:"text-primary block truncate text-xs underline underline-offset-2",title:i,children:i}),t.resolved&&!t.isError&&!t.denied&&o&&e.jsx(E,{label:s("agent.tool.result"),text:o})]})}const Nt=/^[A-Za-z0-9+/]{256,}={0,2}$/,kt=/^https?:\/\/\S+\.(png|jpe?g|webp|gif)(\?\S*)?$/i;function It(t){return typeof t!="string"||t.length===0?null:t.startsWith("data:image/")||kt.test(t)?t:Nt.test(t.replace(/\s/g,""))?`data:image/png;base64,${t.replace(/\s/g,"")}`:null}function Ct(t){if(!t.resolved||t.isError||t.denied)return[];const s=[],n=(i,o)=>{if(s.length>=8||o>3)return;const d=It(i);if(d){s.push(d);return}if(Array.isArray(i)){for(const c of i)n(c,o+1);return}if(C(i))for(const c of["result","image","images","url","b64_json","data"])c in i&&n(i[c],o+1)};return n(t.output,0),[...new Set(s)]}function _t({images:t}){return t.length===0?null:e.jsx("div",{className:"flex flex-wrap gap-2",children:t.map((s,n)=>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"})},n))})}function St({call:t,hideOutput:s}){const{t:n}=I();return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.input!==void 0&&e.jsx(E,{label:n("agent.tool.input"),text:$(t.input)}),!s&&t.resolved&&!t.isError&&!t.denied&&t.output!==void 0&&e.jsx(E,{label:n("agent.tool.result"),text:$(t.output)})]})}function Mt(t){const s=C(t.input)?t.input:{};switch(t.toolName){case"send_input":{const n=[],i=typeof s.text=="string"?s.text:"";i&&n.push(i.slice(0,40));const o=Array.isArray(s.combos)?s.combos:[],d=Array.isArray(s.keys)?s.keys:[],c=o.length+d.length;return c>0&&n.push(`+${c} key${c>1?"s":""}`),n.join(" · ")||"(empty)"}case"read_screen":{const n=C(t.output)?t.output:{},i=typeof n.rows=="number"?n.rows:null;return i!==null?`(${i} rows)`:"(screen)"}case"run_command":return(typeof s.command=="string"?s.command:"").slice(0,60)||"(command)";case"web_search":return(typeof s.query=="string"?s.query:"").slice(0,60)||"(query)";case"fetch_url":return(typeof s.url=="string"?s.url:"").slice(0,60)||"(url)";case"get_pane_info":return"(pane info)";default:return $(t.input).slice(0,60)||""}}function zt({call:t,confirmationId:s,onDecide:n,className:i}){const{t:o}=I(),[d,c]=v.useState(!1),f=!!s&&!t.resolved,l=t.resolved&&t.denied,m=t.resolved&&!l?ht(t):null,g=!t.resolved&&!f,x=l&&typeof t.output=="string"?t.output:"",w=ft.includes(t.toolName)?o(`agent.tool.${t.toolName}`):t.toolName,u=Ct(t),k=gt.includes(t.toolName);return e.jsxs("div",{"data-tool-name":t.toolName,"data-tool-denied":l||void 0,className:S("border-border bg-card flex max-w-full min-w-0 flex-col gap-1.5 self-start rounded-lg border p-2",m!==null&&"border-destructive/50",l&&"opacity-80",i),children:[e.jsxs("button",{type:"button",onClick:()=>c(!0),"data-testid":`agent-tool-card-${t.toolCallId}`,className:"border-border bg-card/50 hover:bg-accent/50 flex max-w-full min-w-0 items-center gap-1.5 rounded-md border px-1.5 py-1 text-xs transition-colors",children:[ee(t.toolName),e.jsx("span",{className:"min-w-0 shrink-0 font-medium truncate",children:w}),e.jsx("span",{className:"text-muted-foreground min-w-0 flex-1 truncate",children:Mt(t)}),g&&e.jsx(ae,{className:"text-muted-foreground size-3 shrink-0 animate-spin"}),t.resolved&&!l&&m===null&&e.jsx(F,{className:"size-3 shrink-0 text-emerald-500"}),m!==null&&e.jsx(B,{className:"text-destructive size-3 shrink-0"}),l&&e.jsx(H,{className:"text-destructive size-3 shrink-0"})]}),m!==null&&e.jsx("p",{className:"text-destructive text-xs break-words whitespace-pre-wrap",children:m}),x&&e.jsx("p",{className:"text-muted-foreground text-xs break-words whitespace-pre-wrap",children:x}),f&&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(N,{"data-testid":"agent-confirm-approve",size:"xs",variant:"secondary",onClick:()=>n==null?void 0:n(s,!0),children:[e.jsx(F,{}),o("agent.confirm.approve")]}),e.jsxs(N,{"data-testid":"agent-confirm-deny",size:"xs",variant:"destructive",onClick:()=>n==null?void 0:n(s,!1),children:[e.jsx(H,{}),o("agent.confirm.deny")]})]}),e.jsx(Ie,{open:d,onOpenChange:c,children:e.jsxs(Ce,{className:"flex max-h-[80vh] max-w-2xl flex-col gap-3 overflow-hidden sm:max-w-2xl",children:[e.jsx(_e,{children:e.jsxs(Se,{className:"flex items-center gap-1.5 text-sm",children:[ee(t.toolName),e.jsx("span",{children:w})]})}),e.jsx("div",{className:"text-muted-foreground flex flex-col gap-3 overflow-auto text-xs",children:e.jsxs(le.Provider,{value:!0,children:[t.toolName==="send_input"&&e.jsx(wt,{call:t}),t.toolName==="read_screen"&&e.jsx(bt,{call:t}),t.toolName==="web_search"&&e.jsx(yt,{call:t}),t.toolName==="fetch_url"&&e.jsx(vt,{call:t}),!k&&e.jsx(St,{call:t,hideOutput:u.length>0}),e.jsx(_t,{images:u})]})})]})})]})}function Tt({text:t,className:s}){return e.jsx("div",{"data-testid":"agent-user-message",className:S("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 Et=48;function Bt(){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 $t({blocks:t,running:s,emptyText:n,confirmationByToolCallId:i,onDecide:o,className:d}){const{t:c}=I(),f=v.useRef(null),l=v.useRef(!0),[m,g]=v.useState(!1),x=()=>{const u=f.current;u&&(u.scrollTop=u.scrollHeight,l.current=!0,g(!1))};v.useEffect(()=>{if(l.current){const u=f.current;u&&(u.scrollTop=u.scrollHeight)}else g(!0)},[t,s]);const w=()=>{const u=f.current;if(!u)return;const b=u.scrollHeight-u.scrollTop-u.clientHeight<Et;l.current=b,g(!b)};return t.length===0&&!s?e.jsx("div",{"data-testid":"agent-chat-thread",className:S("flex min-h-0 flex-1 items-center justify-center p-4",d),children:e.jsx("p",{className:"text-muted-foreground text-sm",children:n})}):e.jsxs("div",{className:S("relative min-h-0 flex-1",d),children:[e.jsx("div",{ref:f,"data-testid":"agent-chat-thread",className:"h-full overflow-y-auto p-3",onScroll:w,children:e.jsxs("div",{className:"flex flex-col gap-3",children:[t.map(u=>{switch(u.kind){case"user":return e.jsx(Tt,{text:u.text},u.key);case"assistant-text":return e.jsx(xt,{text:u.text,streaming:u.streaming},u.key);case"reasoning":return e.jsx(pt,{text:u.text,streaming:u.streaming},u.key);case"tool-call":return e.jsx(zt,{call:u.call,confirmationId:i.get(u.call.toolCallId),onDecide:o},u.key);default:return null}}),s&&e.jsx(Bt,{})]})}),m&&e.jsx(N,{"data-testid":"agent-scroll-to-bottom",size:"icon-sm",variant:"secondary",className:"absolute right-3 bottom-3 z-10 rounded-full shadow-md",onClick:x,"aria-label":c("agent.panel.scrollToBottom"),children:e.jsx(Je,{})})]})}const L="::";function te(t,s){return`${t??""}${L}${s}`}function qt(t){const s=t.indexOf(L);return s<0?{providerId:null,modelId:t}:{providerId:t.slice(0,s)||null,modelId:t.slice(s+L.length)}}function At({providerId:t,modelId:s,onChange:n,disabled:i,className:o}){var b;const{t:d}=I(),{data:c}=K({queryKey:["llm-providers"],queryFn:async()=>{const p=await fetch("/api/llm/providers");if(!p.ok)throw new Error("Failed to load providers");return await p.json()},throwOnError:!1}),{data:f}=K({queryKey:["llm-settings"],queryFn:async()=>{const p=await fetch("/api/llm/settings");if(!p.ok)throw new Error("Failed to load settings");return await p.json()},throwOnError:!1}),l=((c==null?void 0:c.providers)??[]).filter(p=>p.enabled&&p.models.length>0),m=t??(f==null?void 0:f.settings.defaultProviderId)??null,g=s??(f==null?void 0:f.settings.defaultModelId)??null,x=g?te(m,g):"",w=l.some(p=>p.id===m&&p.models.includes(g??"")),u=((b=l.find(p=>p.id===m))==null?void 0:b.name)??null,k=g?u?`${u}/${g}`:g:d("agent.model.placeholder");return e.jsxs(Te,{value:x,onValueChange:p=>{if(typeof p!="string"||!p)return;const r=qt(p);n(r.providerId,r.modelId)},disabled:i||l.length===0,children:[e.jsx(Ee,{size:"sm",className:S("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":d("agent.model.select"),children:e.jsx("span",{className:"min-w-0 truncate",children:k})}),e.jsxs(Be,{children:[!w&&g&&e.jsx(X,{value:x,className:"text-muted-foreground",children:g}),l.map(p=>e.jsxs($e,{children:[e.jsx(qe,{children:p.name}),p.models.map(r=>e.jsx(X,{value:te(p.id,r),children:r},`${p.id}:${r}`))]},p.id))]})]})}function Pt({queued:t,onEdit:s,onWithdraw:n,onSteer:i}){const{t:o}=I(),[d,c]=v.useState(null),[f,l]=v.useState("");if(t.length===0)return null;const m=x=>{c(x.id),l(x.text)},g=x=>{const w=f.trim();w&&s(x,w),c(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(N,{"data-testid":"agent-queue-steer",size:"xs",variant:"outline",onClick:i,title:o("agent.queue.steerHint"),children:[e.jsx(de,{}),o("agent.queue.steer")]})]}),e.jsx("ul",{className:"flex flex-col gap-1",children:t.map(x=>e.jsx("li",{"data-testid":`agent-queue-item-${x.id}`,className:"bg-background/60 flex items-start gap-1.5 rounded-lg px-2 py-1",children:d===x.id?e.jsxs(e.Fragment,{children:[e.jsx(ie,{value:f,onChange:w=>l(w.target.value),onKeyDown:w=>{w.key==="Enter"&&!w.shiftKey&&(w.preventDefault(),g(x.id)),w.key==="Escape"&&c(null)},rows:1,className:"max-h-32 min-h-7 flex-1 resize-none text-xs",autoFocus:!0}),e.jsx(N,{size:"icon-sm",variant:"ghost",onClick:()=>g(x.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:x.text}),e.jsx(N,{size:"icon-sm",variant:"ghost",onClick:()=>m(x),"aria-label":o("common.edit"),children:e.jsx(Ae,{})}),e.jsx(N,{"data-testid":`agent-queue-withdraw-${x.id}`,size:"icon-sm",variant:"ghost",onClick:()=>n(x.id),"aria-label":o("agent.queue.withdraw"),children:e.jsx(H,{})})]})},x.id))})]})}function Ot({onSend:t,onSteer:s,onStop:n,running:i,steerable:o,disabled:d,modelPicker:c,writeModeControl:f}){const{t:l}=I(),[m,g]=v.useState(""),x=h(b=>{var p;return((p=b.draft)==null?void 0:p.prompt)??null}),w=v.useRef(null);v.useEffect(()=>{x&&x!==w.current&&(w.current=x,g(x))},[x]);const u=()=>{const b=m.trim();!b||d||(t==null||t(b),g(""))},k=()=>{const b=m.trim();!b||d||(s==null||s(b),g(""))};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(ie,{"data-testid":"agent-chat-input-textarea",value:m,onChange:b=>g(b.target.value),onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&!b.nativeEvent.isComposing&&(b.preventDefault(),u())},placeholder:l("agent.panel.inputPlaceholder"),disabled:d,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:[f,c&&e.jsx("div",{className:"min-w-0 flex-1",children:c})]}),i?e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[o&&e.jsx(N,{"data-testid":"agent-chat-steer",size:"icon",variant:"outline",disabled:d||m.trim().length===0,onClick:k,"aria-label":l("agent.queue.steer"),title:l("agent.queue.steerHint"),children:e.jsx(de,{})}),e.jsx(N,{"data-testid":"agent-chat-send",size:"icon",variant:"secondary",disabled:d||m.trim().length===0,onClick:u,"aria-label":l("agent.panel.send"),children:e.jsx(Y,{})}),e.jsx(N,{"data-testid":"agent-chat-stop",size:"icon",variant:"destructive",onClick:()=>n==null?void 0:n(),"aria-label":l("agent.panel.stop"),children:e.jsx(rt,{})})]}):e.jsx(N,{"data-testid":"agent-chat-send",size:"icon",className:"ml-auto shrink-0",disabled:d||m.trim().length===0,onClick:u,"aria-label":l("agent.panel.send"),children:e.jsx(Y,{})})]})]})}function Rt(t,s,n){var d;if(!t.deviceId||!t.paneId)return null;const i=((d=n==null?void 0:n.find(c=>c.id===t.deviceId))==null?void 0:d.name)??null,o=s[t.deviceId];if(!(o!=null&&o.session))return{label:`${t.paneId}@${i??"?"}`,state:"unknown",windowId:null};for(const c of o.session.windows){const f=c.panes.find(l=>l.id===t.paneId);if(f)return{label:De({paneCustomName:f.customName,paneTitle:f.title,windowName:c.name,windowCustomName:c.customName,deviceName:i}),state:"valid",windowId:c.id}}return{label:`${t.paneId}@${i??"?"}`,state:"invalid",windowId:null}}function Wt(){var Q;const{t}=I(),s=Pe(),n=Oe(a=>a.setSidebarTab),i=Re("/devices/:deviceId/windows/:windowId/panes/:paneId"),o=(i==null?void 0:i.params.deviceId)??null,d=(i==null?void 0:i.params.paneId)??null,c=h(a=>a.sessions),f=h(a=>a.activeSessionId),l=h(a=>a.draft),m=h(a=>a.activeSessionId?a.messages[a.activeSessionId]:void 0),g=h(a=>a.activeSessionId?a.inProgress[a.activeSessionId]:void 0),x=h(a=>a.activeSessionId?a.pendingConfirmations[a.activeSessionId]:void 0),w=h(a=>a.activeSessionId?a.sending[a.activeSessionId]:void 0),u=h(a=>a.activeSessionId?a.queued[a.activeSessionId]:void 0),k=h(a=>a.defaultWriteMode),b=Fe(a=>a.snapshots),{data:p}=K({queryKey:["devices"],queryFn:async()=>{const a=await fetch("/api/devices");if(!a.ok)throw new Error("Failed to load devices");return a.json()},throwOnError:!1});v.useEffect(()=>{const a=h.getState();a.ensureInitialized(),a.loadSessions()},[]);const r=f?c[f]:void 0,q=v.useMemo(()=>{var j,M;if(!o||!d)return null;const a=(M=(j=b[o])==null?void 0:j.session)==null?void 0:M.windows;for(const _ of a??[]){const V=_.panes.find(ke=>ke.id===d);if(V)return V.title??null}return null},[o,d,b]);v.useEffect(()=>{!r&&!l&&o&&d&&h.getState().startDraft(o,d,q)},[r,l,o,d,q]);const ce=v.useMemo(()=>{const a=new Map;for(const j of x??[])a.set(j.toolCallId,j.id);return a},[x]),ue=v.useMemo(()=>{const a=He(m,g),j=new Set;for(const _ of a)_.kind==="tool-call"&&j.add(_.call.toolCallId);const M=[];for(const _ of x??[])j.has(_.toolCallId)||M.push({kind:"tool-call",key:`confirmation-${_.id}`,call:{toolCallId:_.toolCallId,toolName:_.toolName,input:_.input,isError:!1,denied:!1,resolved:!1}});return M.length>0?[...a,...M]:a},[m,g,x]),W=r??(l?{deviceId:l.deviceId,paneId:l.paneId}:null),y=W?Rt(W,b,p==null?void 0:p.devices):null,me=!!(r&&d&&o&&(r.paneId!==d||r.deviceId!==o)),A=(r==null?void 0:r.status)==="running",D=Ke(m),z=!!(r&&(!r.deviceId||!((Q=p==null?void 0:p.devices)!=null&&Q.some(a=>a.id===r.deviceId))||(y==null?void 0:y.state)==="invalid")),P=u??[],xe=(a,j)=>{f&&h.getState().decideConfirmation(f,a,j)},U=()=>{if(r!=null&&r.deviceId){if((y==null?void 0:y.state)==="valid"&&y.windowId&&r.paneId){s(`/devices/${r.deviceId}/windows/${y.windowId}/panes/${encodeURIComponent(r.paneId)}`);return}(y==null?void 0:y.state)==="unknown"&&s(`/devices/${r.deviceId}`)}},pe=()=>{!o||!d||h.getState().startDraft(o,d,q)},fe=(a,j)=>{r?h.getState().setSessionModel(r.id,a,j):l&&h.getState().updateDraft({providerId:a,modelId:j})},ge=a=>{const j=h.getState();if(r){r.status==="running"?j.enqueueMessage(r.id,a):j.sendMessage(r.id,a);return}l&&(async()=>{const M=await j.materializeDraft();M&&await j.sendMessage(M.id,a)})()},he=a=>{r&&h.getState().enqueueMessage(r.id,a,!0)},je=()=>{if(!r)return;const a=P[0];if(!a)return;const j=h.getState();(async()=>(await j.withdrawQueuedMessage(r.id,a.id),await j.enqueueMessage(r.id,a.text,!0)))()},we=r?r.providerId:(l==null?void 0:l.providerId)??null,be=r?r.modelId:(l==null?void 0:l.modelId)??null,O=!!(r||l),R=!!(l&&!r),G=r?r.writeMode:k,ye=(r==null?void 0:r.allowControlChars)??!1,ve=!!(r&&((m==null?void 0:m.length)??0)>0),Ne=z||!O||(r==null?void 0:r.status)==="waiting_confirmation"||!!w;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:[y?e.jsxs("button",{type:"button","data-testid":"agent-binding-chip","data-binding-state":y.state,className:S("border-border flex min-w-0 items-center gap-1 rounded-full border px-2 py-0.5 text-xs",r&&y.state==="valid"?"hover:bg-muted cursor-pointer":"text-muted-foreground",y.state==="invalid"&&"opacity-60"),onClick:U,disabled:!r||y.state==="invalid",children:[e.jsx(ot,{className:"size-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:y.label}),y.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(N,{"data-testid":"agent-session-switch",size:"icon-sm",variant:"ghost",onClick:()=>n("panes"),"aria-label":t("agent.session.switch"),title:t("agent.session.switch"),children:e.jsx(et,{})}),ve&&e.jsx(N,{"data-testid":"agent-session-new",size:"icon-sm",variant:"ghost",disabled:!o||!d,onClick:pe,"aria-label":t("agent.session.new"),title:t(!o||!d?"agent.session.selectPaneHint":"agent.session.new"),children:e.jsx(Le,{})})]})]}),z&&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")})]}),r&&!z&&me&&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")}),(y==null?void 0:y.state)==="valid"&&e.jsx(N,{"data-testid":"agent-binding-goto",size:"xs",variant:"outline",onClick:U,children:t("agent.binding.goTo")}),d&&e.jsx(N,{"data-testid":"agent-binding-rebind",size:"xs",variant:"outline",onClick:()=>{h.getState().rebindPane(r.id,d)},children:t("agent.binding.rebind")})]}),(r==null?void 0:r.status)==="error"&&r.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:r.lastError}),D&&!z&&e.jsx(N,{"data-testid":"agent-error-retry",size:"xs",variant:"outline",className:"shrink-0",disabled:!!w,onClick:()=>{h.getState().sendMessage(r.id,D)},children:t("agent.panel.retry")})]}),!R&&e.jsx($t,{blocks:r?ue:[],running:!!A,emptyText:t(O?"agent.panel.empty":"agent.session.selectPaneHint"),confirmationByToolCallId:ce,onDecide:xe,className:"bg-chat-surface mx-3 mb-2 overflow-hidden rounded-xl"},(r==null?void 0:r.id)??(l?"draft":"none")),r&&!z&&P.length>0&&e.jsx(Pt,{queued:P,onEdit:(a,j)=>void h.getState().editQueuedMessage(r.id,a,j),onWithdraw:a=>void h.getState().withdrawQueuedMessage(r.id,a),onSteer:je}),O&&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(We,{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(Ot,{disabled:Ne,running:!!A,steerable:!!r,onSend:ge,onSteer:he,onStop:()=>{r&&h.getState().stopSession(r.id)},modelPicker:e.jsx(At,{providerId:we,modelId:be,onChange:fe,disabled:A}),writeModeControl:e.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:t(G==="auto"?"agent.writeMode.auto":"agent.writeMode.confirm")}),e.jsx(Z,{"data-testid":"agent-write-mode-switch",checked:G==="auto",disabled:!!r&&z,onCheckedChange:a=>{const j=a?"auto":"confirm";h.getState().setDefaultWriteMode(j),r&&h.getState().setWriteMode(r.id,j)}})]}),r&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-muted-foreground text-xs",title:t("agent.controlChars.hint"),children:t("agent.controlChars.label")}),e.jsx(Z,{"data-testid":"agent-control-chars-switch",checked:ye,disabled:z,title:t("agent.controlChars.hint"),onCheckedChange:a=>{h.getState().setAllowControlChars(r.id,a)}})]})]})})]})]})}export{Wt as AgentTab};
38
+ `);c.trim()&&n.push(c),i=[]};for(const c of s){if(/^\s*(```|~~~)/.test(c)){o=!o,i.push(c);continue}if(!o&&c.trim()===""){d();continue}i.push(c)}return d(),n}const ct={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,...n})=>e.jsx("code",{...n,className:S("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"})},ut=v.memo(function({content:s}){return e.jsx(Ue,{remarkPlugins:[Ge],components:ct,children:s})});function mt({text:t,streaming:s=!1,className:n}){const i=v.useMemo(()=>lt(t),[t]);return e.jsxs("div",{className:S("flex min-w-0 flex-col gap-2 text-sm leading-relaxed",n),children:[i.map((o,d)=>e.jsx(ut,{content:o},d)),s&&e.jsx("span",{"data-testid":"agent-streaming-cursor",className:"bg-foreground inline-block h-4 w-2 animate-pulse self-start"})]})}function xt({text:t,streaming:s=!1,className:n}){return e.jsx("div",{"data-testid":"agent-assistant-message",className:S("min-w-0 max-w-full self-start",n),children:e.jsx(mt,{text:t,streaming:s})})}function pt({text:t,streaming:s=!1,className:n}){const{t:i}=I();return e.jsxs(se,{"data-testid":"agent-reasoning-block",className:S("min-w-0 max-w-full self-start",n),children:[e.jsxs(ne,{className:"text-muted-foreground hover:text-foreground group flex items-center gap-1 text-xs",children:[e.jsx(re,{className:"size-3 transition-transform group-data-[panel-open]:rotate-90"}),e.jsx(Ze,{className:"size-3"}),e.jsx("span",{children:i("agent.reasoning.title")}),s&&e.jsx(ae,{className:"size-3 animate-spin"})]}),e.jsx(oe,{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})})]})}const ft=["send_input","read_screen","web_search","fetch_url","run_command","get_pane_info"],gt=["send_input","read_screen","web_search","fetch_url"];function C(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function B(t){if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function ht(t){return C(t.output)&&typeof t.output.error=="string"?t.output.error:t.isError?B(t.output):null}function ee(t){switch(t){case"send_input":return e.jsx(Qe,{className:"size-3.5"});case"read_screen":return e.jsx(ze,{className:"size-3.5"});case"web_search":return e.jsx(st,{className:"size-3.5"});case"fetch_url":return e.jsx(Me,{className:"size-3.5"});default:return e.jsx(dt,{className:"size-3.5"})}}const le=v.createContext(!1);function E({label:t,text:s}){const n=v.useContext(le);return e.jsxs(se,{defaultOpen:n,children:[e.jsxs(ne,{className:"text-muted-foreground hover:text-foreground group flex items-center gap-1 text-xs",children:[e.jsx(re,{className:"size-3 transition-transform group-data-[panel-open]:rotate-90"}),e.jsx("span",{children:t})]}),e.jsx(oe,{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 jt(t){if(typeof t!="string")return null;try{const s=JSON.parse(t);return Array.isArray(s)?s.filter(C).map(n=>({title:typeof n.title=="string"?n.title:"",url:typeof n.url=="string"?n.url:"",snippet:typeof n.snippet=="string"?n.snippet:""})).filter(n=>n.url):null}catch{return null}}function wt({call:t}){const{t:s}=I(),n=C(t.input)?t.input:{},i=typeof n.text=="string"?n.text:"",o=Array.isArray(n.keys)?n.keys.filter(m=>typeof m=="string"):[],d=Array.isArray(n.combos)?n.combos.filter(C):[],c=C(t.output)?t.output:{},f=typeof c.screenTail=="string"?c.screenTail:"",l=o.length>0||d.length>0;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[i&&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:i}),l&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[o.map((m,g)=>e.jsx(J,{variant:"outline",className:"font-mono",children:m},`k-${g}-${m}`)),d.map((m,g)=>{const x=Array.isArray(m.modifiers)?m.modifiers.filter(k=>typeof k=="string"):[],w=typeof m.key=="string"?m.key:"";if(!w&&x.length===0)return null;const u=[...x.map(k=>`${k.charAt(0).toUpperCase()}${k.slice(1)}`),w].filter(Boolean).join("+");return e.jsx(J,{variant:"outline",className:"font-mono",children:u},`c-${g}-${u}`)})]}),f&&e.jsx(E,{label:s("agent.tool.result"),text:f})]})}function bt({call:t}){const{t:s}=I(),n=C(t.output)?t.output:{},i=typeof n.screen=="string"?n.screen:"";return i?e.jsx(E,{label:s("agent.tool.screen"),text:i}):null}function yt({call:t}){const{t:s}=I(),n=C(t.input)?t.input:{},i=typeof n.query=="string"?n.query:"",o=t.resolved&&!t.isError&&!t.denied?jt(t.output):null;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[i&&e.jsxs("p",{className:"text-muted-foreground text-xs break-words",children:["“",i,"”"]}),o&&o.length>0&&e.jsx("ul",{className:"flex flex-col gap-1",children:o.map(d=>e.jsxs("li",{className:"min-w-0 text-xs",children:[e.jsx("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",className:"text-primary block truncate underline underline-offset-2",title:d.title||d.url,children:d.title||d.url}),d.snippet&&e.jsx("p",{className:"text-muted-foreground line-clamp-2 break-words",children:d.snippet})]},d.url))}),t.resolved&&!t.isError&&!t.denied&&!o&&typeof t.output=="string"&&e.jsx(E,{label:s("agent.tool.result"),text:t.output})]})}function vt({call:t}){const{t:s}=I(),n=C(t.input)?t.input:{},i=typeof n.url=="string"?n.url:"",o=typeof t.output=="string"?t.output:"";return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[i&&e.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:"text-primary block truncate text-xs underline underline-offset-2",title:i,children:i}),t.resolved&&!t.isError&&!t.denied&&o&&e.jsx(E,{label:s("agent.tool.result"),text:o})]})}const Nt=/^[A-Za-z0-9+/]{256,}={0,2}$/,kt=/^https?:\/\/\S+\.(png|jpe?g|webp|gif)(\?\S*)?$/i;function It(t){return typeof t!="string"||t.length===0?null:t.startsWith("data:image/")||kt.test(t)?t:Nt.test(t.replace(/\s/g,""))?`data:image/png;base64,${t.replace(/\s/g,"")}`:null}function Ct(t){if(!t.resolved||t.isError||t.denied)return[];const s=[],n=(i,o)=>{if(s.length>=8||o>3)return;const d=It(i);if(d){s.push(d);return}if(Array.isArray(i)){for(const c of i)n(c,o+1);return}if(C(i))for(const c of["result","image","images","url","b64_json","data"])c in i&&n(i[c],o+1)};return n(t.output,0),[...new Set(s)]}function _t({images:t}){return t.length===0?null:e.jsx("div",{className:"flex flex-wrap gap-2",children:t.map((s,n)=>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"})},n))})}function St({call:t,hideOutput:s}){const{t:n}=I();return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.input!==void 0&&e.jsx(E,{label:n("agent.tool.input"),text:B(t.input)}),!s&&t.resolved&&!t.isError&&!t.denied&&t.output!==void 0&&e.jsx(E,{label:n("agent.tool.result"),text:B(t.output)})]})}function Mt(t){const s=C(t.input)?t.input:{};switch(t.toolName){case"send_input":{const n=[],i=typeof s.text=="string"?s.text:"";i&&n.push(i.slice(0,40));const o=Array.isArray(s.combos)?s.combos:[],d=Array.isArray(s.keys)?s.keys:[],c=o.length+d.length;return c>0&&n.push(`+${c} key${c>1?"s":""}`),n.join(" · ")||"(empty)"}case"read_screen":{const n=C(t.output)?t.output:{},i=typeof n.rows=="number"?n.rows:null;return i!==null?`(${i} rows)`:"(screen)"}case"run_command":return(typeof s.command=="string"?s.command:"").slice(0,60)||"(command)";case"web_search":return(typeof s.query=="string"?s.query:"").slice(0,60)||"(query)";case"fetch_url":return(typeof s.url=="string"?s.url:"").slice(0,60)||"(url)";case"get_pane_info":return"(pane info)";default:return B(t.input).slice(0,60)||""}}function zt({call:t,confirmationId:s,onDecide:n,className:i}){const{t:o}=I(),[d,c]=v.useState(!1),f=!!s&&!t.resolved,l=t.resolved&&t.denied,m=t.resolved&&!l?ht(t):null,g=!t.resolved&&!f,x=l&&typeof t.output=="string"?t.output:"",w=ft.includes(t.toolName)?o(`agent.tool.${t.toolName}`):t.toolName,u=Ct(t),k=gt.includes(t.toolName);return e.jsxs("div",{"data-tool-name":t.toolName,"data-tool-denied":l||void 0,className:S("border-border bg-card flex max-w-full min-w-0 flex-col gap-1.5 self-start rounded-lg border p-2",m!==null&&"border-destructive/50",l&&"opacity-80",i),children:[e.jsxs("button",{type:"button",onClick:()=>c(!0),"data-testid":`agent-tool-card-${t.toolCallId}`,className:"border-border bg-card/50 hover:bg-accent/50 flex max-w-full min-w-0 items-center gap-1.5 rounded-md border px-1.5 py-1 text-xs transition-colors",children:[ee(t.toolName),e.jsx("span",{className:"min-w-0 shrink-0 font-medium truncate",children:w}),e.jsx("span",{className:"text-muted-foreground min-w-0 flex-1 truncate",children:Mt(t)}),g&&e.jsx(ae,{className:"text-muted-foreground size-3 shrink-0 animate-spin"}),t.resolved&&!l&&m===null&&e.jsx(F,{className:"size-3 shrink-0 text-emerald-500"}),m!==null&&e.jsx($,{className:"text-destructive size-3 shrink-0"}),l&&e.jsx(H,{className:"text-destructive size-3 shrink-0"})]}),m!==null&&e.jsx("p",{className:"text-destructive text-xs break-words whitespace-pre-wrap",children:m}),x&&e.jsx("p",{className:"text-muted-foreground text-xs break-words whitespace-pre-wrap",children:x}),f&&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(N,{"data-testid":"agent-confirm-approve",size:"xs",variant:"secondary",onClick:()=>n==null?void 0:n(s,!0),children:[e.jsx(F,{}),o("agent.confirm.approve")]}),e.jsxs(N,{"data-testid":"agent-confirm-deny",size:"xs",variant:"destructive",onClick:()=>n==null?void 0:n(s,!1),children:[e.jsx(H,{}),o("agent.confirm.deny")]})]}),e.jsx(Ie,{open:d,onOpenChange:c,children:e.jsxs(Ce,{className:"flex max-h-[80vh] max-w-2xl flex-col gap-3 overflow-hidden sm:max-w-2xl",children:[e.jsx(_e,{children:e.jsxs(Se,{className:"flex items-center gap-1.5 text-sm",children:[ee(t.toolName),e.jsx("span",{children:w})]})}),e.jsx("div",{className:"text-muted-foreground flex flex-col gap-3 overflow-auto text-xs",children:e.jsxs(le.Provider,{value:!0,children:[t.toolName==="send_input"&&e.jsx(wt,{call:t}),t.toolName==="read_screen"&&e.jsx(bt,{call:t}),t.toolName==="web_search"&&e.jsx(yt,{call:t}),t.toolName==="fetch_url"&&e.jsx(vt,{call:t}),!k&&e.jsx(St,{call:t,hideOutput:u.length>0}),e.jsx(_t,{images:u})]})})]})})]})}function Tt({text:t,className:s}){return e.jsx("div",{"data-testid":"agent-user-message",className:S("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 Et=48;function $t(){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 Bt({blocks:t,running:s,emptyText:n,confirmationByToolCallId:i,onDecide:o,className:d}){const{t:c}=I(),f=v.useRef(null),l=v.useRef(!0),[m,g]=v.useState(!1),x=()=>{const u=f.current;u&&(u.scrollTop=u.scrollHeight,l.current=!0,g(!1))};v.useEffect(()=>{if(l.current){const u=f.current;u&&(u.scrollTop=u.scrollHeight)}else g(!0)},[t,s]);const w=()=>{const u=f.current;if(!u)return;const b=u.scrollHeight-u.scrollTop-u.clientHeight<Et;l.current=b,g(!b)};return t.length===0&&!s?e.jsx("div",{"data-testid":"agent-chat-thread",className:S("flex min-h-0 flex-1 items-center justify-center p-4",d),children:e.jsx("p",{className:"text-muted-foreground text-sm",children:n})}):e.jsxs("div",{className:S("relative min-h-0 flex-1",d),children:[e.jsx("div",{ref:f,"data-testid":"agent-chat-thread",className:"h-full overflow-y-auto p-3",onScroll:w,children:e.jsxs("div",{className:"flex flex-col gap-3",children:[t.map(u=>{switch(u.kind){case"user":return e.jsx(Tt,{text:u.text},u.key);case"assistant-text":return e.jsx(xt,{text:u.text,streaming:u.streaming},u.key);case"reasoning":return e.jsx(pt,{text:u.text,streaming:u.streaming},u.key);case"tool-call":return e.jsx(zt,{call:u.call,confirmationId:i.get(u.call.toolCallId),onDecide:o},u.key);default:return null}}),s&&e.jsx($t,{})]})}),m&&e.jsx(N,{"data-testid":"agent-scroll-to-bottom",size:"icon-sm",variant:"secondary",className:"absolute right-3 bottom-3 z-10 rounded-full shadow-md",onClick:x,"aria-label":c("agent.panel.scrollToBottom"),children:e.jsx(Je,{})})]})}const L="::";function te(t,s){return`${t??""}${L}${s}`}function qt(t){const s=t.indexOf(L);return s<0?{providerId:null,modelId:t}:{providerId:t.slice(0,s)||null,modelId:t.slice(s+L.length)}}function At({providerId:t,modelId:s,onChange:n,disabled:i,className:o}){var b;const{t:d}=I(),{data:c}=K({queryKey:["llm-providers"],queryFn:async()=>{const p=await fetch("/api/llm/providers");if(!p.ok)throw new Error("Failed to load providers");return await p.json()},throwOnError:!1}),{data:f}=K({queryKey:["llm-settings"],queryFn:async()=>{const p=await fetch("/api/llm/settings");if(!p.ok)throw new Error("Failed to load settings");return await p.json()},throwOnError:!1}),l=((c==null?void 0:c.providers)??[]).filter(p=>p.enabled&&p.models.length>0),m=t??(f==null?void 0:f.settings.defaultProviderId)??null,g=s??(f==null?void 0:f.settings.defaultModelId)??null,x=g?te(m,g):"",w=l.some(p=>p.id===m&&p.models.includes(g??"")),u=((b=l.find(p=>p.id===m))==null?void 0:b.name)??null,k=g?u?`${u}/${g}`:g:d("agent.model.placeholder");return e.jsxs(Te,{value:x,onValueChange:p=>{if(typeof p!="string"||!p)return;const r=qt(p);n(r.providerId,r.modelId)},disabled:i||l.length===0,children:[e.jsx(Ee,{size:"sm",className:S("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":d("agent.model.select"),children:e.jsx("span",{className:"min-w-0 truncate",children:k})}),e.jsxs($e,{children:[!w&&g&&e.jsx(X,{value:x,className:"text-muted-foreground",children:g}),l.map(p=>e.jsxs(Be,{children:[e.jsx(qe,{children:p.name}),p.models.map(r=>e.jsx(X,{value:te(p.id,r),children:r},`${p.id}:${r}`))]},p.id))]})]})}function Pt({queued:t,onEdit:s,onWithdraw:n,onSteer:i}){const{t:o}=I(),[d,c]=v.useState(null),[f,l]=v.useState("");if(t.length===0)return null;const m=x=>{c(x.id),l(x.text)},g=x=>{const w=f.trim();w&&s(x,w),c(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(N,{"data-testid":"agent-queue-steer",size:"xs",variant:"outline",onClick:i,title:o("agent.queue.steerHint"),children:[e.jsx(de,{}),o("agent.queue.steer")]})]}),e.jsx("ul",{className:"flex flex-col gap-1",children:t.map(x=>e.jsx("li",{"data-testid":`agent-queue-item-${x.id}`,className:"bg-background/60 flex items-start gap-1.5 rounded-lg px-2 py-1",children:d===x.id?e.jsxs(e.Fragment,{children:[e.jsx(ie,{value:f,onChange:w=>l(w.target.value),onKeyDown:w=>{w.key==="Enter"&&!w.shiftKey&&(w.preventDefault(),g(x.id)),w.key==="Escape"&&c(null)},rows:1,className:"max-h-32 min-h-7 flex-1 resize-none text-xs",autoFocus:!0}),e.jsx(N,{size:"icon-sm",variant:"ghost",onClick:()=>g(x.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:x.text}),e.jsx(N,{size:"icon-sm",variant:"ghost",onClick:()=>m(x),"aria-label":o("common.edit"),children:e.jsx(Ae,{})}),e.jsx(N,{"data-testid":`agent-queue-withdraw-${x.id}`,size:"icon-sm",variant:"ghost",onClick:()=>n(x.id),"aria-label":o("agent.queue.withdraw"),children:e.jsx(H,{})})]})},x.id))})]})}function Ot({onSend:t,onSteer:s,onStop:n,running:i,steerable:o,disabled:d,modelPicker:c,writeModeControl:f}){const{t:l}=I(),[m,g]=v.useState(""),x=h(b=>{var p;return((p=b.draft)==null?void 0:p.prompt)??null}),w=v.useRef(null);v.useEffect(()=>{x&&x!==w.current&&(w.current=x,g(x))},[x]);const u=()=>{const b=m.trim();!b||d||(t==null||t(b),g(""))},k=()=>{const b=m.trim();!b||d||(s==null||s(b),g(""))};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(ie,{"data-testid":"agent-chat-input-textarea",value:m,onChange:b=>g(b.target.value),onKeyDown:b=>{b.key==="Enter"&&!b.shiftKey&&!b.nativeEvent.isComposing&&(b.preventDefault(),u())},placeholder:l("agent.panel.inputPlaceholder"),disabled:d,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:[f,c&&e.jsx("div",{className:"min-w-0 flex-1",children:c})]}),i?e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[o&&e.jsx(N,{"data-testid":"agent-chat-steer",size:"icon",variant:"outline",disabled:d||m.trim().length===0,onClick:k,"aria-label":l("agent.queue.steer"),title:l("agent.queue.steerHint"),children:e.jsx(de,{})}),e.jsx(N,{"data-testid":"agent-chat-send",size:"icon",variant:"secondary",disabled:d||m.trim().length===0,onClick:u,"aria-label":l("agent.panel.send"),children:e.jsx(Y,{})}),e.jsx(N,{"data-testid":"agent-chat-stop",size:"icon",variant:"destructive",onClick:()=>n==null?void 0:n(),"aria-label":l("agent.panel.stop"),children:e.jsx(rt,{})})]}):e.jsx(N,{"data-testid":"agent-chat-send",size:"icon",className:"ml-auto shrink-0",disabled:d||m.trim().length===0,onClick:u,"aria-label":l("agent.panel.send"),children:e.jsx(Y,{})})]})]})}function Rt(t,s,n){var d;if(!t.deviceId||!t.paneId)return null;const i=((d=n==null?void 0:n.find(c=>c.id===t.deviceId))==null?void 0:d.name)??null,o=s[t.deviceId];if(!(o!=null&&o.session))return{label:`${t.paneId}@${i??"?"}`,state:"unknown",windowId:null};for(const c of o.session.windows){const f=c.panes.find(l=>l.id===t.paneId);if(f)return{label:De({paneCustomName:f.customName,paneTitle:f.title,windowName:c.name,windowCustomName:c.customName,deviceName:i}),state:"valid",windowId:c.id}}return{label:`${t.paneId}@${i??"?"}`,state:"invalid",windowId:null}}function Wt(){var Q;const{t}=I(),s=Pe(),n=Oe(a=>a.setSidebarTab),i=Re("/devices/:deviceId/windows/:windowId/panes/:paneId"),o=(i==null?void 0:i.params.deviceId)??null,d=(i==null?void 0:i.params.paneId)??null,c=h(a=>a.sessions),f=h(a=>a.activeSessionId),l=h(a=>a.draft),m=h(a=>a.activeSessionId?a.messages[a.activeSessionId]:void 0),g=h(a=>a.activeSessionId?a.inProgress[a.activeSessionId]:void 0),x=h(a=>a.activeSessionId?a.pendingConfirmations[a.activeSessionId]:void 0),w=h(a=>a.activeSessionId?a.sending[a.activeSessionId]:void 0),u=h(a=>a.activeSessionId?a.queued[a.activeSessionId]:void 0),k=h(a=>a.defaultWriteMode),b=Fe(a=>a.snapshots),{data:p}=K({queryKey:["devices"],queryFn:async()=>{const a=await fetch("/api/devices");if(!a.ok)throw new Error("Failed to load devices");return a.json()},throwOnError:!1});v.useEffect(()=>{const a=h.getState();a.ensureInitialized(),a.loadSessions()},[]);const r=f?c[f]:void 0,q=v.useMemo(()=>{var j,M;if(!o||!d)return null;const a=(M=(j=b[o])==null?void 0:j.session)==null?void 0:M.windows;for(const _ of a??[]){const V=_.panes.find(ke=>ke.id===d);if(V)return V.title??null}return null},[o,d,b]);v.useEffect(()=>{!r&&!l&&o&&d&&h.getState().startDraft(o,d,q)},[r,l,o,d,q]);const ce=v.useMemo(()=>{const a=new Map;for(const j of x??[])a.set(j.toolCallId,j.id);return a},[x]),ue=v.useMemo(()=>{const a=He(m,g),j=new Set;for(const _ of a)_.kind==="tool-call"&&j.add(_.call.toolCallId);const M=[];for(const _ of x??[])j.has(_.toolCallId)||M.push({kind:"tool-call",key:`confirmation-${_.id}`,call:{toolCallId:_.toolCallId,toolName:_.toolName,input:_.input,isError:!1,denied:!1,resolved:!1}});return M.length>0?[...a,...M]:a},[m,g,x]),W=r??(l?{deviceId:l.deviceId,paneId:l.paneId}:null),y=W?Rt(W,b,p==null?void 0:p.devices):null,me=!!(r&&d&&o&&(r.paneId!==d||r.deviceId!==o)),A=(r==null?void 0:r.status)==="running",D=Ke(m),z=!!(r&&(!r.deviceId||!((Q=p==null?void 0:p.devices)!=null&&Q.some(a=>a.id===r.deviceId))||(y==null?void 0:y.state)==="invalid")),P=u??[],xe=(a,j)=>{f&&h.getState().decideConfirmation(f,a,j)},U=()=>{if(r!=null&&r.deviceId){if((y==null?void 0:y.state)==="valid"&&y.windowId&&r.paneId){s(`/devices/${r.deviceId}/windows/${y.windowId}/panes/${encodeURIComponent(r.paneId)}`);return}(y==null?void 0:y.state)==="unknown"&&s(`/devices/${r.deviceId}`)}},pe=()=>{!o||!d||h.getState().startDraft(o,d,q)},fe=(a,j)=>{r?h.getState().setSessionModel(r.id,a,j):l&&h.getState().updateDraft({providerId:a,modelId:j})},ge=a=>{const j=h.getState();if(r){r.status==="running"?j.enqueueMessage(r.id,a):j.sendMessage(r.id,a);return}l&&(async()=>{const M=await j.materializeDraft();M&&await j.sendMessage(M.id,a)})()},he=a=>{r&&h.getState().enqueueMessage(r.id,a,!0)},je=()=>{if(!r)return;const a=P[0];if(!a)return;const j=h.getState();(async()=>(await j.withdrawQueuedMessage(r.id,a.id),await j.enqueueMessage(r.id,a.text,!0)))()},we=r?r.providerId:(l==null?void 0:l.providerId)??null,be=r?r.modelId:(l==null?void 0:l.modelId)??null,O=!!(r||l),R=!!(l&&!r),G=r?r.writeMode:k,ye=(r==null?void 0:r.allowControlChars)??!1,ve=!!(r&&((m==null?void 0:m.length)??0)>0),Ne=z||!O||(r==null?void 0:r.status)==="waiting_confirmation"||!!w;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:[y?e.jsxs("button",{type:"button","data-testid":"agent-binding-chip","data-binding-state":y.state,className:S("border-border flex min-w-0 items-center gap-1 rounded-full border px-2 py-0.5 text-xs",r&&y.state==="valid"?"hover:bg-muted cursor-pointer":"text-muted-foreground",y.state==="invalid"&&"opacity-60"),onClick:U,disabled:!r||y.state==="invalid",children:[e.jsx(ot,{className:"size-3 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:y.label}),y.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(N,{"data-testid":"agent-session-switch",size:"icon-sm",variant:"ghost",onClick:()=>n("panes"),"aria-label":t("agent.session.switch"),title:t("agent.session.switch"),children:e.jsx(et,{})}),ve&&e.jsx(N,{"data-testid":"agent-session-new",size:"icon-sm",variant:"ghost",disabled:!o||!d,onClick:pe,"aria-label":t("agent.session.new"),title:t(!o||!d?"agent.session.selectPaneHint":"agent.session.new"),children:e.jsx(Le,{})})]})]}),z&&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($,{className:"mt-0.5 size-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1",children:t("agent.orphan.readonly")})]}),r&&!z&&me&&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($,{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")}),(y==null?void 0:y.state)==="valid"&&e.jsx(N,{"data-testid":"agent-binding-goto",size:"xs",variant:"outline",onClick:U,children:t("agent.binding.goTo")}),d&&e.jsx(N,{"data-testid":"agent-binding-rebind",size:"xs",variant:"outline",onClick:()=>{h.getState().rebindPane(r.id,d)},children:t("agent.binding.rebind")})]}),(r==null?void 0:r.status)==="error"&&r.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($,{className:"mt-0.5 size-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 flex-1 break-words",children:r.lastError}),D&&!z&&e.jsx(N,{"data-testid":"agent-error-retry",size:"xs",variant:"outline",className:"shrink-0",disabled:!!w,onClick:()=>{h.getState().sendMessage(r.id,D)},children:t("agent.panel.retry")})]}),!R&&e.jsx(Bt,{blocks:r?ue:[],running:!!A,emptyText:t(O?"agent.panel.empty":"agent.session.selectPaneHint"),confirmationByToolCallId:ce,onDecide:xe,className:"bg-chat-surface mx-3 mb-2 overflow-hidden rounded-xl"},(r==null?void 0:r.id)??(l?"draft":"none")),r&&!z&&P.length>0&&e.jsx(Pt,{queued:P,onEdit:(a,j)=>void h.getState().editQueuedMessage(r.id,a,j),onWithdraw:a=>void h.getState().withdrawQueuedMessage(r.id,a),onSteer:je}),O&&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(We,{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(Ot,{disabled:Ne,running:!!A,steerable:!!r,onSend:ge,onSteer:he,onStop:()=>{r&&h.getState().stopSession(r.id)},modelPicker:e.jsx(At,{providerId:we,modelId:be,onChange:fe,disabled:A}),writeModeControl:e.jsxs("div",{className:"flex shrink-0 items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:t(G==="auto"?"agent.writeMode.auto":"agent.writeMode.confirm")}),e.jsx(Z,{"data-testid":"agent-write-mode-switch",checked:G==="auto",disabled:!!r&&z,onCheckedChange:a=>{const j=a?"auto":"confirm";h.getState().setDefaultWriteMode(j),r&&h.getState().setWriteMode(r.id,j)}})]}),r&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-muted-foreground text-xs",title:t("agent.controlChars.hint"),children:t("agent.controlChars.label")}),e.jsx(Z,{"data-testid":"agent-control-chars-switch",checked:ye,disabled:z,title:t("agent.controlChars.hint"),onCheckedChange:a=>{h.getState().setAllowControlChars(r.id,a)}})]})]})})]})]})}export{Wt as AgentTab};
@@ -0,0 +1,5 @@
1
+ var N=Object.defineProperty;var B=(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)=>B(t,typeof e!="symbol"?e+"":e,o);function D(t){const e=new TextEncoder().encode(t);let o="";for(const n of e)o+=String.fromCharCode(n);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function x(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),o=e.length%4===0?"":"=".repeat(4-e.length%4),n=atob(e+o),a=new Uint8Array(n.length);for(let s=0;s<n.length;s++)a[s]=n.charCodeAt(s);return new TextDecoder().decode(a)}function g(t,e){return D(`${t}
2
+ ${e}`)}function z(t){try{const e=x(t),o=e.indexOf(`
3
+ `);return o<0?null:{rootId:e.slice(0,o),path:e.slice(o+1)}}catch{return null}}function M(t,e){return`/file/${g(t,e)}`}function A(t,e,o){const n=new URLSearchParams({rootId:e});return o!=null&&n.set("path",o),`/api/files/${t}?${n.toString()}`}function _(t,e,o=!1){const n=new URLSearchParams({rootId:t,path:e});return o&&n.set("download","1"),`/api/files/raw?${n.toString()}`}function H(t,e){return`/api/files/download?${new URLSearchParams({rootId:t,path:e}).toString()}`}function h(t){if(!Number.isFinite(t)||t<0)return"0 B";if(t<1024)return`${t} B`;const e=["KB","MB","GB","TB"];let o=t/1024,n=0;for(;o>=1024&&n<e.length-1;)o/=1024,n+=1;const a=o>=100?0:o>=10?1:2;return`${o.toFixed(a)} ${e[n]}`}function P(t){return`${h(t)}/s`}class j extends Error{constructor(o,n,a){super(n);O(this,"status");O(this,"code");this.name="FileApiError",this.status=o,this.code=a}}async function l(t){let e=`HTTP ${t.status}`,o;try{const n=await t.json();n.error&&(e=n.error),o=n.code}catch{}return new j(t.status,e,o)}async function K(){const t=await fetch("/api/files/roots");if(!t.ok)throw await l(t);return await t.json()}async function G(t){const e=await fetch("/api/files/roots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw await l(e);return await e.json()}async function W(t,e){const o=await fetch(`/api/files/roots/${encodeURIComponent(t)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!o.ok)throw await l(o);return await o.json()}async function q(t){const e=await fetch(`/api/files/roots/${encodeURIComponent(t)}`,{method:"DELETE"});if(!e.ok)throw await l(e)}async function Q(t,e){const o=await fetch(A("list",t,e));if(!o.ok)throw await l(o);return await o.json()}async function V(t,e){const o=await fetch(A("stat",t,e));if(!o.ok)throw await l(o);return await o.json()}async function X(t,e){const o=await fetch(A("content",t,e));if(!o.ok)throw await l(o);return await o.json()}const I=8*1024*1024;async function Y(t,e,o,n={}){const{onLeg:a,signal:s}=n,$=()=>{if(s!=null&&s.aborted)throw new DOMException("Aborted","AbortError")},w=o.size,y=c=>`${h(c)} / ${h(w)}`,E={rootId:t,path:e,name:o.name,size:w},m=await fetch("/api/files/upload/init",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(E),signal:s});if(!m.ok)throw await l(m);const{uploadId:u,chunkSize:F}=await m.json(),U=F>0?F:I;try{a==null||a(1,{pct:w===0?100:0,detail:y(0)});const c=performance.now();let i=0;for(;i<w;){$();const S=Math.min(i+U,w),k=await fetch(`/api/files/upload/${u}?offset=${i}`,{method:"PUT",body:o.slice(i,S),signal:s});if(!k.ok)throw await l(k);i=S;const p=(performance.now()-c)/1e3;a==null||a(1,{pct:Math.round(i/w*100),rate:p>0?P(i/p):void 0,detail:y(i)})}a==null||a(1,{pct:100,detail:y(w)}),$(),a==null||a(2,{pct:0,detail:y(0)});const f=await fetch(`/api/files/upload/${u}/commit`,{method:"POST",signal:s});if(!f.ok||!f.body)throw await l(f);const R=f.body.getReader(),r=new TextDecoder;let b="",C=!1;for(;;){const{done:S,value:k}=await R.read();if(S)break;b+=r.decode(k,{stream:!0});const p=b.split(`
4
+ `);b=p.pop()??"";for(const T of p){if(!T.trim())continue;const d=JSON.parse(T);if(d.type==="progress")a==null||a(2,{pct:d.pct,rate:d.rate,detail:y(d.transferred)});else if(d.type==="done")C=!0;else if(d.type==="error")throw new j(500,d.detail??d.code,d.code)}}if(!C)throw new j(500,"unknown","unknown");a==null||a(2,{pct:100,detail:y(w)})}catch(c){try{await fetch(`/api/files/upload/${u}`,{method:"DELETE"})}catch{}throw c}}async function Z(t,e,o,n={}){const{onLeg:a,signal:s}=n;a==null||a(1,{pct:0});const $=await fetch("/api/files/download/prepare",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({rootId:t,path:e}),signal:s});if(!$.ok||!$.body)throw await l($);const w=$.body.getReader(),y=new TextDecoder;let E="",m="",u=0,F=o,U=null;for(;;){const{done:c,value:i}=await w.read();if(c)break;E+=y.decode(i,{stream:!0});const f=E.split(`
5
+ `);E=f.pop()??"";for(const R of f){if(!R.trim())continue;const r=JSON.parse(R);r.type==="progress"?a==null||a(1,{pct:r.pct??0,rate:r.rate,detail:r.transferred!=null?h(r.transferred):void 0}):r.type==="done"?(m=r.downloadId??"",u=r.size??0,F=r.name??o):r.type==="error"&&(U=new j(500,r.detail??r.code??"unknown",r.code))}}if(U)throw U;if(!m)throw new j(500,"unknown","unknown");a==null||a(1,{pct:100,detail:h(u)});try{const c=T=>`${h(T)} / ${h(u)}`;a==null||a(2,{pct:0,detail:c(0)});const i=await fetch(`/api/files/download/${m}/content`,{signal:s});if(!i.ok||!i.body)throw await l(i);const f=Number(i.headers.get("Content-Length")??String(u)),R=i.body.getReader(),r=[];let b=0;const C=performance.now();for(;;){const{done:T,value:d}=await R.read();if(T)break;r.push(d),b+=d.byteLength;const v=(performance.now()-C)/1e3;a==null||a(2,{pct:f>0?Math.round(b/f*100):0,rate:v>0?P(b/v):void 0,detail:`${h(b)} / ${h(f)}`})}const S=new Blob(r),k=URL.createObjectURL(S),p=document.createElement("a");p.href=k,p.download=F,document.body.appendChild(p),p.click(),p.remove(),URL.revokeObjectURL(k),a==null||a(2,{pct:100,detail:c(u)})}catch(c){try{await fetch(`/api/files/download/${m}`,{method:"DELETE"})}catch{}throw c}}export{j as F,V as a,M as b,h as c,H as d,z as e,K as f,Z as g,Q as h,W as i,q as j,G as k,_ as l,X as m,Y as u};
@@ -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-CvSv2dqw.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-Cy4PFTl-.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};