@tencent-ai/agent-sdk 0.3.272 → 0.3.273

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 (142) hide show
  1. package/cli/CHANGELOG.md +17 -0
  2. package/cli/dist/codebuddy-headless.js +23 -23
  3. package/cli/dist/codebuddy-lite-wb.mjs +25 -25
  4. package/cli/dist/web-ui/assets/{CanvasPaneStandaloneView-DIn545ua.js → CanvasPaneStandaloneView-dyWkk4PZ.js} +1 -1
  5. package/cli/dist/web-ui/assets/{CanvasView-hnvCmPSV.js → CanvasView-DkhyH_1F.js} +1 -1
  6. package/cli/dist/web-ui/assets/{ChangesView-CtIfLmOc.js → ChangesView-CaHOWv2Z.js} +1 -1
  7. package/cli/dist/web-ui/assets/{DocsView-HBxNI97Q.js → DocsView-DiGzijj1.js} +1 -1
  8. package/cli/dist/web-ui/assets/{EditorView-DvwpvafF.js → EditorView-CUu0ekRP.js} +1 -1
  9. package/cli/dist/web-ui/assets/HoverHint-LssI0qEE.js +1 -0
  10. package/cli/dist/web-ui/assets/{KeybindingsView-B88MXgWr.js → KeybindingsView-DWUI1JpY.js} +1 -1
  11. package/cli/dist/web-ui/assets/{LogsView-DjF_5-Jd.js → LogsView-CEHx06nm.js} +1 -1
  12. package/cli/dist/web-ui/assets/{MetricsView-DImkPyZM.js → MetricsView-BZuMTUvp.js} +1 -1
  13. package/cli/dist/web-ui/assets/{PluginsView-2uPy3XvK.js → PluginsView-DPWy3FBq.js} +1 -1
  14. package/cli/dist/web-ui/assets/{RemoteControlView-kPy9GUlN.js → RemoteControlView-C1NdBeJw.js} +1 -1
  15. package/cli/dist/web-ui/assets/{SettingsView-CWRqL0oA.js → SettingsView-BJCKKgWV.js} +1 -1
  16. package/cli/dist/web-ui/assets/{SplitContainer-Dm1TgCaG.js → SplitContainer-BpAMtGSs.js} +1 -1
  17. package/cli/dist/web-ui/assets/{StatsView-okhz7xRe.js → StatsView-C-HzWG8r.js} +1 -1
  18. package/cli/dist/web-ui/assets/{TasksView-CICNpZ9N.js → TasksView-BnFNp4fv.js} +1 -1
  19. package/cli/dist/web-ui/assets/{TerminalPaneView-BFSDyqOG.js → TerminalPaneView-ALwEzbwH.js} +1 -1
  20. package/cli/dist/web-ui/assets/{TracesView-Burz_yeC.js → TracesView-t3wi7Kes.js} +1 -1
  21. package/cli/dist/web-ui/assets/{WorkersView-BqddwtUV.js → WorkersView-d7IuRA1g.js} +1 -1
  22. package/cli/dist/web-ui/assets/{abnfDiagram-O67JEVCF-33nTnJ2S.js → abnfDiagram-O67JEVCF-DlRX5Clr.js} +1 -1
  23. package/cli/dist/web-ui/assets/architecture-7GRP2DOG-4118Qje4.js +1 -0
  24. package/cli/dist/web-ui/assets/{architectureDiagram-NJMV4G6O-FzGcEis5.js → architectureDiagram-NJMV4G6O-CvzoqRYj.js} +1 -1
  25. package/cli/dist/web-ui/assets/{blockDiagram-BEXU5L5S-DSx6FBt9.js → blockDiagram-BEXU5L5S-Dmo7FSbu.js} +1 -1
  26. package/cli/dist/web-ui/assets/{c4Diagram-YGBWAQC7-CF2SLLtS.js → c4Diagram-YGBWAQC7-D-rNXRo3.js} +1 -1
  27. package/cli/dist/web-ui/assets/{canvas-store-CTF2gk3l.js → canvas-store-C-T5LSPT.js} +1 -1
  28. package/cli/dist/web-ui/assets/channel-CzlEOE5Z.js +1 -0
  29. package/cli/dist/web-ui/assets/{chunk-3FUC2YCW-BSfDfOZA.js → chunk-3FUC2YCW-44Og191I.js} +1 -1
  30. package/cli/dist/web-ui/assets/{chunk-5DYCD2WN-Cw4uUnBv.js → chunk-5DYCD2WN-BMcJMkic.js} +1 -1
  31. package/cli/dist/web-ui/assets/{chunk-742MDFTN-Crj_2MBX.js → chunk-742MDFTN-C9Feux5F.js} +1 -1
  32. package/cli/dist/web-ui/assets/{chunk-7INBJB4K-CQzVOJr6.js → chunk-7INBJB4K-DFzU3uUY.js} +1 -1
  33. package/cli/dist/web-ui/assets/{chunk-7M6MHVWA-C0J56L0S.js → chunk-7M6MHVWA-BP_hs_Zh.js} +1 -1
  34. package/cli/dist/web-ui/assets/{chunk-7PRAP22T-CcX4ntNx.js → chunk-7PRAP22T-DhCB5ggZ.js} +1 -1
  35. package/cli/dist/web-ui/assets/{chunk-GTNCS2PH-UUmiv_WZ.js → chunk-GTNCS2PH-CgRQhFK-.js} +1 -1
  36. package/cli/dist/web-ui/assets/{chunk-GWA4HPMP-Cj2HSbZB.js → chunk-GWA4HPMP-DVQFlNrg.js} +1 -1
  37. package/cli/dist/web-ui/assets/{chunk-MBY4JIJT-BeWwQI_5.js → chunk-MBY4JIJT-ClsX9AV0.js} +1 -1
  38. package/cli/dist/web-ui/assets/{chunk-NETBCI7D-BXoE0wX2.js → chunk-NETBCI7D-Ok_AlsOs.js} +1 -1
  39. package/cli/dist/web-ui/assets/{chunk-O7XYJQB3-BkJCF4Hl.js → chunk-O7XYJQB3-BrUoQZlx.js} +1 -1
  40. package/cli/dist/web-ui/assets/{chunk-UA2S7LBM-BiEZLJdx.js → chunk-UA2S7LBM-CcImKd_4.js} +1 -1
  41. package/cli/dist/web-ui/assets/{chunk-WEXAMYUT-CVYmgL88.js → chunk-WEXAMYUT-DuMzoDxl.js} +1 -1
  42. package/cli/dist/web-ui/assets/{chunk-Z7XXMR3K-CNWwStqk.js → chunk-Z7XXMR3K-DNFavXEr.js} +1 -1
  43. package/cli/dist/web-ui/assets/{chunk-ZIGJFQKS-B2DOCzA_.js → chunk-ZIGJFQKS-C7Y7rwsz.js} +1 -1
  44. package/cli/dist/web-ui/assets/{classDiagram-v2-NBCMYWYE-Cg87JbAk.js → classDiagram-v2-NBCMYWYE-DtdQ5tsO.js} +1 -1
  45. package/cli/dist/web-ui/assets/{cssMode-CRv4tEjN.js → cssMode-DqpFSny4.js} +1 -1
  46. package/cli/dist/web-ui/assets/{cynefin-OW5HDTMX-CzRVph15.js → cynefin-OW5HDTMX-D-khVVHT.js} +1 -1
  47. package/cli/dist/web-ui/assets/{cynefinDiagram-VND7K2PF-CNBPnBJq.js → cynefinDiagram-VND7K2PF-D4SBf27A.js} +1 -1
  48. package/cli/dist/web-ui/assets/{dagre-6A5THRUB-Din1Iojv.js → dagre-6A5THRUB-DVdcjlZz.js} +1 -1
  49. package/cli/dist/web-ui/assets/{diagram-22UHCM2B-DYXr4hLX.js → diagram-22UHCM2B-N9qNPFGx.js} +1 -1
  50. package/cli/dist/web-ui/assets/{diagram-3UASUU5V-Q_QpApP2.js → diagram-3UASUU5V-BOrM2fJW.js} +1 -1
  51. package/cli/dist/web-ui/assets/{diagram-ATOU4E4O-B0cBUUAl.js → diagram-ATOU4E4O-BnlFCQjV.js} +1 -1
  52. package/cli/dist/web-ui/assets/{diagram-CDSNMT55-CqpNUvJt.js → diagram-CDSNMT55-Db7azPHL.js} +1 -1
  53. package/cli/dist/web-ui/assets/{diagram-MLGK6HIB-4ZDRCl9v.js → diagram-MLGK6HIB-Awr2vnnw.js} +1 -1
  54. package/cli/dist/web-ui/assets/{diagram-MPIPVDR6-t-N00d6f.js → diagram-MPIPVDR6-mMEzAWkb.js} +1 -1
  55. package/cli/dist/web-ui/assets/{ebnfDiagram-ZINNZB2B-DPflRvsG.js → ebnfDiagram-ZINNZB2B-DDcxPluf.js} +1 -1
  56. package/cli/dist/web-ui/assets/{editor-store-Bnu4yw4O.js → editor-store-BVy4DJoP.js} +1 -1
  57. package/cli/dist/web-ui/assets/{editor.main-BES2SJR1.js → editor.main-BPCdeUv0.js} +2 -2
  58. package/cli/dist/web-ui/assets/{elk-276RUBZZ-DMGj1qO4.js → elk-276RUBZZ-1ObyfSih.js} +1 -1
  59. package/cli/dist/web-ui/assets/{erDiagram-OPXOYQCR-DhPB_L2_.js → erDiagram-OPXOYQCR-85QZesG5.js} +1 -1
  60. package/cli/dist/web-ui/assets/eventmodeling-NTZA5JFV-DzcNhtMG.js +1 -0
  61. package/cli/dist/web-ui/assets/flowDiagram-KWPJA3E3-C7gZq6zs.js +1 -0
  62. package/cli/dist/web-ui/assets/{ganttDiagram-FUAMR5RP-BuNFnD8o.js → ganttDiagram-FUAMR5RP-CWKxEm2a.js} +1 -1
  63. package/cli/dist/web-ui/assets/{gitGraph-4MIJSDKK-DvwoNKUh.js → gitGraph-4MIJSDKK-Va9MqQP7.js} +1 -1
  64. package/cli/dist/web-ui/assets/{gitGraphDiagram-X574FWY7-CMVV2pN8.js → gitGraphDiagram-X574FWY7-CxDUZnv6.js} +1 -1
  65. package/cli/dist/web-ui/assets/{htmlMode-RPgBxfFT.js → htmlMode-CcmjLBK1.js} +1 -1
  66. package/cli/dist/web-ui/assets/index-BUL8iy6o.css +1 -0
  67. package/cli/dist/web-ui/assets/{index-BI5Z_cST.js → index-CcT-vg3O.js} +88 -88
  68. package/cli/dist/web-ui/assets/{info-A6RAGUB7-BkTwTvGc.js → info-A6RAGUB7-KlhzL_St.js} +1 -1
  69. package/cli/dist/web-ui/assets/{infoDiagram-VRGFBTTK-B9qpTfBj.js → infoDiagram-VRGFBTTK-COv85ylX.js} +1 -1
  70. package/cli/dist/web-ui/assets/{ishikawaDiagram-OU5B5YK6-CQYN-WJG.js → ishikawaDiagram-OU5B5YK6-B6LK0Dp0.js} +1 -1
  71. package/cli/dist/web-ui/assets/{journeyDiagram-ZHPQQLJL-Bhhb_1ix.js → journeyDiagram-ZHPQQLJL-7_gx-X1b.js} +1 -1
  72. package/cli/dist/web-ui/assets/{jsonMode-BmcV16dZ.js → jsonMode-DjeQHeec.js} +1 -1
  73. package/cli/dist/web-ui/assets/{kanban-definition-PNTS6WVX-2sWMVFOP.js → kanban-definition-PNTS6WVX-BuoY2Y9n.js} +1 -1
  74. package/cli/dist/web-ui/assets/{line-dyZ1bUO3.js → line-U1NpPN9F.js} +1 -1
  75. package/cli/dist/web-ui/assets/loader-circle-CbX-mRDA.js +1 -0
  76. package/cli/dist/web-ui/assets/{mermaid-parser.core-DCSwPqyy.js → mermaid-parser.core-CWo09gq-.js} +3 -3
  77. package/cli/dist/web-ui/assets/{mermaid.core-00vr9ukx.js → mermaid.core-ChqNs8I4.js} +4 -4
  78. package/cli/dist/web-ui/assets/{mindmap-definition-NLK3R4M7-CxnIh2aq.js → mindmap-definition-NLK3R4M7-CqCx8Oby.js} +1 -1
  79. package/cli/dist/web-ui/assets/{packet-AYTQ26CC-CMmSJjVl.js → packet-AYTQ26CC-7UVU8Lay.js} +1 -1
  80. package/cli/dist/web-ui/assets/{pegDiagram-GJSIUBJH-D4cdj7vr.js → pegDiagram-GJSIUBJH-BBJmKZzK.js} +1 -1
  81. package/cli/dist/web-ui/assets/{pie-WAS4IAKB-BesuGcpz.js → pie-WAS4IAKB-CWoQ0mW0.js} +1 -1
  82. package/cli/dist/web-ui/assets/{pieDiagram-5QR66LMP-BGskFaPj.js → pieDiagram-5QR66LMP-BbAkRCRb.js} +1 -1
  83. package/cli/dist/web-ui/assets/power-GWOABL7s.js +1 -0
  84. package/cli/dist/web-ui/assets/{quadrantDiagram-O4NWA36T-Bkvvkyx-.js → quadrantDiagram-O4NWA36T-Bcgl9szm.js} +1 -1
  85. package/cli/dist/web-ui/assets/{radar-RG4KPBEZ-Bj7UyIL-.js → radar-RG4KPBEZ-B0sDFvbJ.js} +1 -1
  86. package/cli/dist/web-ui/assets/{railroad-74A4TZTK-D2D2Em5k.js → railroad-74A4TZTK-C0abYTLu.js} +1 -1
  87. package/cli/dist/web-ui/assets/railroad-abnf-HS5TGJTU-BhEAzBPy.js +1 -0
  88. package/cli/dist/web-ui/assets/railroad-ebnf-LZEXJU2U-BQshAF1C.js +1 -0
  89. package/cli/dist/web-ui/assets/railroad-peg-WCYAUIDC-BhzEUl06.js +1 -0
  90. package/cli/dist/web-ui/assets/{railroadDiagram-XR7U4H2S-kdQApYhY.js → railroadDiagram-XR7U4H2S-Xdtrah7h.js} +1 -1
  91. package/cli/dist/web-ui/assets/{requirementDiagram-PLB6GJNP-BqBC3CXU.js → requirementDiagram-PLB6GJNP-Dmm_Xtdj.js} +1 -1
  92. package/cli/dist/web-ui/assets/{sankeyDiagram-IPEJSGJF-DVzCsx-G.js → sankeyDiagram-IPEJSGJF-BExPBGN1.js} +1 -1
  93. package/cli/dist/web-ui/assets/{sequenceDiagram-PO4LG4MO-yG_YwbRF.js → sequenceDiagram-PO4LG4MO-DjyWwluL.js} +1 -1
  94. package/cli/dist/web-ui/assets/{server-CnUlxMCB.js → server-BYrFK9uI.js} +1 -1
  95. package/cli/dist/web-ui/assets/{sidebar-store-BECS2ZHH.js → sidebar-store-bTJzulZp.js} +1 -1
  96. package/cli/dist/web-ui/assets/{stateDiagram-v2-GCMORJYK-CTmS4-3L.js → stateDiagram-v2-GCMORJYK-BKgBFDVg.js} +1 -1
  97. package/cli/dist/web-ui/assets/{swimlanes-2SLR337P-B8qdR1JY.js → swimlanes-2SLR337P-vVovFCNH.js} +1 -1
  98. package/cli/dist/web-ui/assets/swimlanesDiagram-TC7HE7FX-DRp2HW8M.js +8 -0
  99. package/cli/dist/web-ui/assets/{terminal-store-C9T3TvZG.js → terminal-store-CCHDZeLq.js} +1 -1
  100. package/cli/dist/web-ui/assets/{theme-store-e89BUV83.js → theme-store-Cvh0uW_P.js} +1 -1
  101. package/cli/dist/web-ui/assets/{timeline-definition-EJHVYXUP-DBuW2EtA.js → timeline-definition-EJHVYXUP-DkMh7Iif.js} +1 -1
  102. package/cli/dist/web-ui/assets/{timer-hXQHNuTF.js → timer-BJmcyIbv.js} +1 -1
  103. package/cli/dist/web-ui/assets/{treeView-Q6P3EWNA-DZwOY3Vo.js → treeView-Q6P3EWNA-DkhVSMV1.js} +1 -1
  104. package/cli/dist/web-ui/assets/{treemap-WGGIJYW6-KzsufT0z.js → treemap-WGGIJYW6-CWTt7auX.js} +1 -1
  105. package/cli/dist/web-ui/assets/{triangle-alert-Bgaqn5eg.js → triangle-alert-CGAm2zgw.js} +1 -1
  106. package/cli/dist/web-ui/assets/{tsMode-DmXjlKw6.js → tsMode-92q32nO9.js} +1 -1
  107. package/cli/dist/web-ui/assets/use-i18n-pIrmaYmw.js +10 -0
  108. package/cli/dist/web-ui/assets/{usecaseDiagram-POWQR4AR-CMUsnek4.js → usecaseDiagram-POWQR4AR-Cmkzn47X.js} +1 -1
  109. package/cli/dist/web-ui/assets/{vennDiagram-UO4OBE2U-DfvnmEI-.js → vennDiagram-UO4OBE2U-krvLAVN1.js} +1 -1
  110. package/cli/dist/web-ui/assets/{wardley-WFR3VGLG-gMMXWBBC.js → wardley-WFR3VGLG-D5c13zW9.js} +1 -1
  111. package/cli/dist/web-ui/assets/{wardleyDiagram-VNRHLVJA-Dg12ciAd.js → wardleyDiagram-VNRHLVJA-CrnhHeux.js} +1 -1
  112. package/cli/dist/web-ui/assets/{workspace-dock-store-uPe33-_O.js → workspace-dock-store-DnFjd3tC.js} +1 -1
  113. package/cli/dist/web-ui/assets/{xychartDiagram-PMCCYNJV-DF6GiPla.js → xychartDiagram-PMCCYNJV-CUWbjTrP.js} +1 -1
  114. package/cli/dist/web-ui/assets/{zap-nSKVK-41.js → zap-BbNNHf5_.js} +1 -1
  115. package/cli/dist/web-ui/index.html +11 -11
  116. package/cli/dist/web-ui/sw.js +1 -1
  117. package/cli/dist-server/3163.codebuddy.js +1 -1
  118. package/cli/dist-server/3209.codebuddy.js +2 -2
  119. package/cli/dist-server/codebuddy.js +7 -7
  120. package/cli/dist-server/types/node/agent-home/agent-home-agent-create.d.ts +5 -0
  121. package/cli/dist-server/types/vendor/cbc-core/node/session/session-admission-service.d.ts +6 -0
  122. package/cli/dist-server/types/vendor/cbc-shared/node/model/model-errors.d.ts +5 -2
  123. package/cli/package.json +1 -1
  124. package/cli/product.cloudhosted.json +2 -2
  125. package/cli/product.internal.json +2 -2
  126. package/cli/product.ioa.json +2 -2
  127. package/cli/product.json +2 -2
  128. package/cli/product.selfhosted.json +2 -2
  129. package/package.json +1 -1
  130. package/cli/dist/web-ui/assets/HoverHint-D2G73lbr.js +0 -1
  131. package/cli/dist/web-ui/assets/architecture-7GRP2DOG-DIJIAReN.js +0 -1
  132. package/cli/dist/web-ui/assets/channel-Oqc_5uJL.js +0 -1
  133. package/cli/dist/web-ui/assets/eventmodeling-NTZA5JFV-DhJKLgIL.js +0 -1
  134. package/cli/dist/web-ui/assets/flowDiagram-KWPJA3E3-C8j8-NKs.js +0 -1
  135. package/cli/dist/web-ui/assets/index-_kDd5loD.css +0 -1
  136. package/cli/dist/web-ui/assets/loader-circle-OavGeXCF.js +0 -1
  137. package/cli/dist/web-ui/assets/power-f1Ij2Msg.js +0 -1
  138. package/cli/dist/web-ui/assets/railroad-abnf-HS5TGJTU-qU-l3gTW.js +0 -1
  139. package/cli/dist/web-ui/assets/railroad-ebnf-LZEXJU2U-Co7bnXh9.js +0 -1
  140. package/cli/dist/web-ui/assets/railroad-peg-WCYAUIDC-BE_5lCh8.js +0 -1
  141. package/cli/dist/web-ui/assets/swimlanesDiagram-TC7HE7FX-B2Lj57-K.js +0 -8
  142. package/cli/dist/web-ui/assets/use-i18n-BvN1piiI.js +0 -10
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{l as t,u as n}from"./markdown-DCKhnxE9.js";import{n as r}from"./vendor-D7d5DZKE.js";var i=e(n(),1),a=r();function o(e){return e.find(e=>e.visibility!==`hidden`)??e[0]}function s(e,t){let n=[];for(let r of e){let e=t.get(r);e&&n.push(e)}return n}function c(e){return e.replace(/^房间:[^\n]*(?:\n+)?/u,``).trim()}function l(e,t,n){return s(e,n).filter(e=>!t||e.id!==t)[0]}function u(e){return e?e.mentioned||e.attention?`yellow`:e.working?`green`:e.failed||e.offline?`red`:null:null}function d(e,t){let n=!1,r=!1;for(let i of e){let e=t.get(i);if(e){if(e.mentioned||e.attention)return`yellow`;n||=e.working===!0,r||=e.failed===!0}}return n?`green`:r?`red`:null}function f(e){return[...e].sort((e,t)=>{let n=Number(t.pinned===!0)-Number(e.pinned===!0);return n===0?e.sortIndex===t.sortIndex?e.createdAt-t.createdAt:e.sortIndex-t.sortIndex:n})}var p=1e3;function m(e,t,n){let r=f(e).filter(e=>e.id!==t),i=n?r.findIndex(e=>e.id===n):-1,a=i>=0?i:r.length,o=r[a-1],s=r[a];return o&&s?(o.sortIndex+s.sortIndex)/2:s?s.sortIndex-p:o?o.sortIndex+p:Date.now()}function h(e,t){if(e){let n=t.find(t=>t.id===e);if(n)return n}return t.reduce((e,t)=>!e||t.startedAt<e.startedAt?t:e,void 0)}function g(e,t,n){return n?e.filter(e=>!t[e.id]):[]}function _(e){return e.localDraftId??e.draftAgentId??(e.selectedJobId?e.jobAssignments[e.selectedJobId]??e.agents.find(t=>t.primaryJobId===e.selectedJobId)?.id:void 0)??(e.mainChatActive?e.defaultAgentId??void 0:void 0)}function ee(e){let t=new Set;for(let n of e)if(n.visibility!==`hidden`)for(let e of n.memberAgentIds)t.add(e);return t}function v(e,t,n){let r=n.trim().toLowerCase();return!r||`${e} ${t.join(` `)}`.toLowerCase().includes(r)}function y(e){let t=t=>{if(t)return e.jobAssignments[t]??e.agents.find(e=>e.primaryJobId===t)?.id},n=e.embeddedJobId?t(e.embeddedJobId):!e.mainChatActive&&e.selectedJobId?t(e.selectedJobId):e.defaultAgentId??void 0;return{name:n?e.agents.find(e=>e.id===n)?.name:void 0,seed:n??(e.mainChatActive?void 0:e.embeddedJobId??e.selectedJobId)??e.defaultAgentId??`main`}}function b(e){let t=e??(typeof window>`u`?``:window.location.search),n=new URLSearchParams(t),r=n.get(`selfId`)?.trim()||void 0,i=n.get(`selfName`)?.trim();if(r||i)return{name:i||r||``,seed:n.get(`selfSeed`)?.trim()||r||i||``,...r?{id:r}:{}}}var x=`min-w-0 overflow-clip text-clip whitespace-nowrap`;function S(e,t,n=!1){return e?n||t?!0:e.includes(`/`)||e.includes(`\\`):!1}function C(e){let t=(e||``).replace(/\btruncate\b/g,``).replace(/\btext-ellipsis\b/g,``).replace(/\s+/g,` `).trim();return t?`${x} ${t}`:x}function w(e,t,n,r=6){let i=Math.max(8,t.width-n.width-8),a=Math.round(Math.min(Math.max(8,e.left),i)),o=e.bottom+r;return o+n.height<=t.height-8?{top:Math.round(o),left:a}:{top:Math.round(Math.max(8,e.top-r-n.height)),left:a}}var T=2e3,E=1024,D=20971520,O=`application/x-codebuddy-home-row`;function k(e){return{kind:`noop`,reason:e}}function A(e){return JSON.stringify(e)}function j(e){if(!e)return null;try{let t=JSON.parse(e);return!t||typeof t.id!=`string`||!t.id?null:t.kind===`agent`||t.kind===`room`||t.kind===`run`||t.kind===`channel`?{kind:t.kind,id:t.id}:t.kind===`member`&&typeof t.groupId==`string`&&t.groupId?{kind:`member`,id:t.id,groupId:t.groupId}:null}catch{return null}}function M(e,t){let n=A(t);e.effectAllowed=`copyMove`;try{e.setData(`text/plain`,n)}catch{}try{e.setData(O,n)}catch{}}function N(e,t){try{return e.getData(t)}catch{return``}}function P(e){if(e){let t=j(N(e,O));if(t)return t;let n=j(N(e,`text/plain`));if(n)return n}return I()}function te(e){return e?.kind===`agent`||e?.kind===`run`}var F=null;function ne(e){F=e,e||H(null)}function I(){return F}function L(e){return I()?!0:e?Array.from(e.types??[]).includes(O):!1}function R(e,t){if(t.isMobile===!0)return!1;if(e.kind===`agent`)return t.draggableAgentIds.has(e.id);if(e.kind===`run`)return t.draggableRunIds?.has(e.id)===!0;if(e.kind===`room`)return t.groups.some(t=>t.id===e.id);if(e.kind===`channel`)return t.channels?.some(t=>t.id===e.id)===!0;let n=t.groups.find(t=>t.id===e.groupId);return!!n&&!n?.activeTeamName}function z(e,t){if(e.kind===`agent`&&t.draggableAgentIds.has(e.id))return{kind:`agent`,id:e.id};if(e.kind===`run`&&t.draggableRunIds?.has(e.id))return{kind:`run`,id:e.id}}var B=null,V=new Set;function H(e){B=e;for(let e of V)e()}function U(){return B}function W(e){return V.add(e),()=>{V.delete(e)}}function G(e){return e.kind===`noop`&&(e.reason==="default"||e.reason===`minimal`)?e.reason:null}function K(e,t,n){return t.kind!==`noop`||G(t)?!1:e.kind!==`member`||n.kind!==`people-section`&&n.kind!==`agent`&&n.kind!==`run`&&n.kind!==`directory-section`}function q(e){return e.kind===`room`||e.kind===`channel`}function J(e,t){if(t.defaultAgentId&&e===t.defaultAgentId)return`default`;if(t.noRoomAgentIds?.has(e)===!0||t.noChannelAgentIds?.has(e)===!0)return`minimal`}function Y(e,t,n,r){if(!e)return k(`other`);if(t.kind===`agent`){let e=J(t.id,r);if(e)return k(e)}return t.kind===`agent`&&e.memberAgentIds.includes(t.id)?k(`duplicate`):e.activeTeamName?k(`teaming`):e.memberAgentIds.length>=n?k(`full`):{kind:`add-member`,groupId:e.id,member:t}}function X(e,t,n){if(!e)return k(`other`);if(t.kind===`agent`){let e=J(t.id,n);if(e)return k(e)}return t.kind===`agent`&&e.memberAgentIds.includes(t.id)?k(`duplicate`):e.memberAgentIds.length>=6?k(`full`):{kind:`add-channel-member`,channelId:e.id,member:t}}function re(e,t,n){return e===`channel`?n.channels?.find(e=>e.id===t)?.sectionId:n.agentSectionIds?.get(t)}function Z(e,t,n){let r=re(e.kind,e.id,n)??null,i=t?.trim()?t.trim():null;return r===i?k(`self`):{kind:`assign-section`,entry:e,sectionId:i}}function Q(e,t,n){return e.memberAgentIds.includes(t)?e.memberAgentIds.length-1<2?{kind:`dissolve-confirm`,groupId:e.id,agentId:t,...n?{toGroupId:n}:{}}:n?{kind:`move-member`,agentId:t,fromGroupId:e.id,toGroupId:n}:{kind:`remove-member`,groupId:e.id,agentId:t}:k(`other`)}function ie(e,t,n){if(n.isMobile===!0)return k(`mobile`);let r=n.maxMembers??6,i=e=>n.groups.find(t=>t.id===e);if(e.kind===`channel`)return n.channels?.some(t=>t.id===e.id)?t.kind===`directory-section`?Z({kind:`channel`,id:e.id},t.sectionId,n):t.kind===`people-section`?Z({kind:`channel`,id:e.id},null,n):k(`other`):k(`other`);if(e.kind===`agent`||e.kind===`run`){if(e.kind===`agent`&&n.hiddenAgentIds?.has(e.id))return k(`hidden`);let a=z(e,n);if(!a)return k(`draft`);if(a.kind===`agent`&&(t.kind===`directory-section`||t.kind===`people-section`))return Z({kind:`agent`,id:a.id},t.kind===`directory-section`?t.sectionId:null,n);if(t.kind===`agent`||t.kind===`run`){if(t.id===e.id)return k(`self`);let i=z(t,n);if(!i)return k(`other`);if(a.kind===`agent`&&i.kind===`agent`){let e=J(a.id,n)??J(i.id,n);if(e)return k(e);let t=o(n.groups);if(t){if(t.memberAgentIds.includes(a.id)&&t.memberAgentIds.includes(i.id))return{kind:`open-room`,groupId:t.id};let e=[a.id,i.id].filter(e=>!t.memberAgentIds.includes(e));if(t.memberAgentIds.length+e.length>r)return k(`full`);if(e.length===1)return{kind:`add-member`,groupId:t.id,member:e[0]===a.id?a:i}}}let s=(a.kind===`agent`?J(a.id,n):void 0)??(i.kind===`agent`?J(i.id,n):void 0);return s?k(s):{kind:`create-room`,members:[a,i]}}return t.kind===`room`?Y(i(t.id),a,r,n):t.kind===`channel`?X(n.channels?.find(e=>e.id===t.id),a,n):k(`other`)}if(e.kind===`room`){let a=i(e.id);if(!a)return k(`other`);if(t.kind===`agent`||t.kind===`run`){let e=z(t,n);return e?Y(a,e,r,n):k(`other`)}return t.kind===`hidden-section`?a.visibility===`hidden`?k(`duplicate`):{kind:`hide-room`,groupId:a.id}:t.kind===`room-section`||t.kind===`people-section`?a.visibility===`hidden`?{kind:`unhide-room`,groupId:a.id}:k(`other`):t.kind===`room-gap`?t.beforeId===e.id?k(`self`):{kind:`reorder-rooms`,groupId:a.id,beforeGroupId:t.beforeId}:k(`other`)}let a=i(e.groupId);if(!a)return k(`other`);if(a.activeTeamName)return k(`teaming`);if(t.kind===`people-section`||t.kind===`agent`||t.kind===`run`)return Q(a,e.id);if(t.kind===`room`){if(t.id===e.groupId)return k(`self`);let n=i(t.id);return n?n.memberAgentIds.includes(e.id)?k(`duplicate`):n.activeTeamName?k(`teaming`):n.memberAgentIds.length>=r?k(`full`):Q(a,e.id,n.id):k(`other`)}return t.kind===`channel`?X(n.channels?.find(e=>e.id===t.id),{kind:`agent`,id:e.id},n):k(`other`)}var $=t(),ae=80;function oe({defaultText:e,minimalText:t}){let[n,r]=(0,i.useState)(U),o=(0,i.useRef)(null),[s,c]=(0,i.useState)({top:0,left:0});if((0,i.useEffect)(()=>W(()=>r(U())),[]),(0,i.useLayoutEffect)(()=>{if(!n||!o.current)return;let e=w({top:n.y,left:n.x,bottom:n.y},{width:window.innerWidth,height:window.innerHeight},o.current.getBoundingClientRect(),16);c(t=>t.top===e.top&&t.left===e.left?t:e)},[n]),!n)return null;let l=n.reason==="default"?e:t;return(0,a.createPortal)((0,$.jsx)(`div`,{ref:o,role:`tooltip`,className:`pointer-events-none fixed z-[200] max-w-[min(90vw,20rem)] rounded-md border border-border-default bg-bg-secondary px-2.5 py-1.5 text-[12px] leading-relaxed text-text-primary shadow-lg`,style:{top:s.top||n.y+16,left:s.left||n.x+12},children:l}),document.body)}function se({text:e,className:t,children:n,onClick:r,always:o=!1,"aria-label":s}){let c=(0,i.useRef)(null),l=(0,i.useRef)(null),u=(0,i.useRef)(),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)({top:0,left:0}),h=()=>{window.clearTimeout(u.current),f(!1)},g=()=>{window.clearTimeout(u.current),u.current=setTimeout(()=>{let t=c.current;if(!t||!e||!S(e,t.scrollWidth>t.clientWidth+1,o))return;let n=t.getBoundingClientRect();m({top:n.bottom+6,left:n.left}),f(!0)},ae)};return(0,i.useEffect)(()=>()=>window.clearTimeout(u.current),[]),(0,i.useEffect)(()=>{if(!d)return;let e=()=>h();return window.addEventListener(`scroll`,e,!0),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,!0),window.removeEventListener(`resize`,e)}},[d]),(0,i.useLayoutEffect)(()=>{if(!d||!l.current||!c.current)return;let e=w(c.current.getBoundingClientRect(),{width:window.innerWidth,height:window.innerHeight},l.current.getBoundingClientRect());m(t=>t.top===e.top&&t.left===e.left?t:e)},[d,e]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{ref:c,className:o?t:C(t),title:``,"aria-label":s,onMouseEnter:g,onMouseLeave:h,onFocus:g,onBlur:h,onClick:r,children:n}),d&&e&&(0,a.createPortal)((0,$.jsx)(`div`,{ref:l,role:`tooltip`,className:`pointer-events-none fixed z-[180] max-w-[min(90vw,32rem)] rounded-md border border-border-default bg-bg-secondary px-2.5 py-1.5 text-[12px] leading-relaxed text-text-primary shadow-lg ${o?`break-words`:`font-mono break-all`}`,style:{top:p.top,left:p.left},children:e}),document.body)]})}export{s as A,m as C,_ as D,y as E,o as M,f as N,d as O,c as P,u as S,l as T,E as _,I as a,ee as b,P as c,H as d,q as f,D as g,T as h,L as i,g as j,v as k,ie as l,M as m,se as n,G as o,K as p,R as r,te as s,oe as t,ne as u,x as v,h as w,b as x,C as y};
@@ -1,4 +1,4 @@
1
- import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./use-i18n-BvN1piiI.js";import{l as n,u as r}from"./markdown-DCKhnxE9.js";import{Dt as i,Ft as a,S as o,_t as s,b as c,kt as l,v as u,x as d,y as f}from"./index-BI5Z_cST.js";var p=e(r(),1),m=n(),h=({isOpen:e,actionId:n,actionName:r,context:i,existingBindings:a,onSave:o,onCancel:s})=>{let{t:l}=t(),[u,h]=(0,p.useState)([]),[g,_]=(0,p.useState)([]);(0,p.useEffect)(()=>{e&&(h([]),_([]))},[e]),(0,p.useEffect)(()=>{if(!e)return;let t=e=>{if(e.preventDefault(),e.stopPropagation(),[`Control`,`Shift`,`Alt`,`Meta`].includes(e.key))return;let t=f(e);if(!t)return;let r=[...u,t];h(r);let o=c(r).toLowerCase(),s=a.filter(e=>e.action===n&&e.context===i?!1:c(e.chord).toLowerCase()===o&&e.action!==null).map(e=>`${e.action} (${e.context})`);_(s)};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e,u,a,n,i]);let v=(0,p.useCallback)(()=>{u.length!==0&&o(u.map(e=>{let t=[];return e.ctrl&&t.push(`ctrl`),e.alt&&t.push(`alt`),e.shift&&t.push(`shift`),e.super&&t.push(`cmd`),t.push(e.key===` `?`space`:e.key),t.join(`+`)}).join(` `))},[u,o]),y=(0,p.useCallback)(()=>{h([]),_([])},[]);return e?(0,m.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center bg-black/50`,style:{zIndex:`var(--z-modal, 100)`},onClick:s,children:(0,m.jsxs)(`div`,{className:`bg-[var(--color-bg-primary)] border border-[var(--color-border-default)] rounded-lg p-6 w-[440px] shadow-xl`,onClick:e=>e.stopPropagation(),children:[(0,m.jsx)(`h3`,{className:`text-base font-medium text-[var(--color-text-primary)] mb-1`,children:l(`keybindings.record.title`)}),(0,m.jsxs)(`p`,{className:`text-sm text-[var(--color-text-secondary)] mb-4`,children:[r,` `,(0,m.jsxs)(`span`,{className:`text-[var(--color-text-muted)]`,children:[`(`,i,`)`]})]}),(0,m.jsx)(`div`,{className:`border border-[var(--color-border-default)] rounded-md p-4 mb-4 text-center min-h-[60px] flex items-center justify-center bg-[var(--color-bg-secondary)]`,children:u.length>0?(0,m.jsx)(`span`,{className:`text-lg font-mono text-[var(--color-text-primary)]`,children:u.map((e,t)=>(0,m.jsxs)(`span`,{children:[t>0&&(0,m.jsx)(`span`,{className:`text-[var(--color-text-muted)] mx-1`,children:` `}),d(e)]},t))}):(0,m.jsx)(`span`,{className:`text-sm text-[var(--color-text-muted)]`,children:l(`keybindings.record.hint`)})}),g.length>0&&(0,m.jsxs)(`div`,{className:`text-sm text-[var(--color-warning)] mb-4`,children:[l(`keybindings.record.conflict`),`: `,g.join(`, `)]}),(0,m.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[u.length>0&&(0,m.jsx)(`button`,{className:`px-3 py-1.5 text-sm text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] transition-colors`,onClick:y,children:l(`keybindings.action.reset`)}),(0,m.jsx)(`button`,{className:`px-3 py-1.5 text-sm text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] transition-colors`,onClick:s,children:l(`app.cancel`)}),(0,m.jsx)(`button`,{className:`px-4 py-1.5 text-sm rounded-md transition-colors ${u.length===0?`bg-[var(--color-bg-secondary)] text-[var(--color-text-muted)] cursor-not-allowed`:`bg-[var(--color-accent-brand)] text-[var(--color-bg-primary)] hover:opacity-90`}`,disabled:u.length===0,onClick:v,children:l(`app.confirm`)})]})]})}):null},g=()=>{let{t:e,tryT:n}=t(),{defaults:r,userBlocks:d,bindings:f,warnings:g,loaded:v,loadBindings:y,saveUserBindings:b,resetBindings:x}=u(),[S,C]=(0,p.useState)(``),[w,T]=(0,p.useState)(null),E=(0,p.useCallback)(e=>n(`keybindings.ctx.${e}`)??e,[n]),D=(0,p.useCallback)(e=>n(`keybindings.ctxDesc.${e}`)??``,[n]),O=(0,p.useCallback)(e=>n(`keybindings.act.${e}`)??_(e),[n]);(0,p.useEffect)(()=>{v||y()},[v,y]);let k=(0,p.useMemo)(()=>{if(!v)return[];let e=new Set;if(d)for(let t of d)for(let[n,r]of Object.entries(t.bindings))e.add(`${t.context}:${r??`null`}:${n}`);let t=new Map;for(let n of f){let r=`${n.context}:${n.action}`,i=c(n.chord),a=n.chord.map(e=>{let t=[];return e.ctrl&&t.push(`ctrl`),e.alt&&t.push(`alt`),e.shift&&t.push(`shift`),e.super&&t.push(`cmd`),t.push(e.key===` `?`space`:e.key),t.join(`+`)}).join(` `),o=e.has(`${n.context}:${n.action}:${a}`);t.set(r,{action:n.action??``,displayName:n.action?O(n.action):``,keyDisplay:i,keyRaw:a,context:n.context,source:o?`user`:`default`,isUnbound:n.action===null})}return Array.from(t.values()).filter(e=>!e.isUnbound)},[v,f,d,O]),A=(0,p.useMemo)(()=>S.trim()?k.filter(e=>[e.displayName,e.action,e.keyDisplay,E(e.context)].some(e=>o(S,e).match)):k,[k,S,E]),j=(0,p.useMemo)(()=>{let e=new Map;for(let t of A){let n=e.get(t.context)||[];n.push(t),e.set(t.context,n)}return e},[A]),M=(0,p.useCallback)(async e=>{if(!w)return;let t=d?JSON.parse(JSON.stringify(d)):[],n=t.find(e=>e.context===w.context);n||(n={context:w.context,bindings:{}},t.push(n));for(let[e,t]of Object.entries(n.bindings))t===w.action&&delete n.bindings[e];n.bindings[e]=w.action,await b({bindings:t}),T(null)},[w,d,b]),N=(0,p.useCallback)(async e=>{let t=d?JSON.parse(JSON.stringify(d)):[],n=t.find(t=>t.context===e.context);n||(n={context:e.context,bindings:{}},t.push(n)),n.bindings[e.keyRaw]=null,await b({bindings:t})},[d,b]),P=(0,p.useCallback)(async e=>{if(!d)return;let t=JSON.parse(JSON.stringify(d)),n=t.find(t=>t.context===e.context);if(!n)return;delete n.bindings[e.keyRaw];for(let[t,i]of Object.entries(n.bindings))if(i===e.action||i===null){let i=r.find(t=>t.context===e.context);i&&i.bindings[t]===e.action&&delete n.bindings[t]}let i=t.filter(e=>Object.keys(e.bindings).length>0);await b({bindings:i})},[d,r,b]);return v?(0,m.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,m.jsxs)(`div`,{className:`px-4 py-2 border-b border-[var(--color-border-default)] flex items-center gap-2`,children:[(0,m.jsxs)(`div`,{className:`relative flex-1`,children:[(0,m.jsx)(i,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-muted)]`}),(0,m.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:e(`keybindings.search.placeholder`),className:`w-full pl-8 pr-8 py-1.5 text-sm bg-[var(--color-bg-secondary)] text-[var(--color-text-primary)] border border-[var(--color-border-default)] rounded-md outline-none focus:border-[var(--color-accent-blue)]`}),S&&(0,m.jsx)(`button`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]`,onClick:()=>C(``),children:(0,m.jsx)(s,{size:14})})]}),(0,m.jsx)(`button`,{className:`p-1.5 text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] transition-colors`,onClick:()=>x(),title:e(`keybindings.reset.all`),children:(0,m.jsx)(l,{size:14})})]}),g.length>0&&(0,m.jsx)(`div`,{className:`px-4 py-2 bg-[var(--color-warning-bg,rgba(255,170,0,0.1))] border-b border-[var(--color-border-default)]`,children:g.slice(0,3).map((e,t)=>(0,m.jsxs)(`p`,{className:`text-xs text-[var(--color-warning)]`,children:[e.severity===`error`?`x`:`!`,` `,e.message]},t))}),(0,m.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[Array.from(j.entries()).map(([t,n])=>(0,m.jsxs)(`div`,{className:`mb-2`,children:[(0,m.jsxs)(`div`,{className:`sticky top-0 px-4 py-2 bg-[var(--color-bg-secondary)] border-b border-[var(--color-border-default)]`,children:[(0,m.jsx)(`span`,{className:`text-xs font-semibold text-[var(--color-text-secondary)] uppercase tracking-wider`,children:E(t)}),(0,m.jsx)(`span`,{className:`text-xs text-[var(--color-text-muted)] ml-2 font-normal normal-case tracking-normal`,children:D(t)})]}),n.map(t=>(0,m.jsxs)(`div`,{className:`
1
+ import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./use-i18n-pIrmaYmw.js";import{l as n,u as r}from"./markdown-DCKhnxE9.js";import{Dt as i,Ft as a,S as o,_t as s,b as c,kt as l,v as u,x as d,y as f}from"./index-CcT-vg3O.js";var p=e(r(),1),m=n(),h=({isOpen:e,actionId:n,actionName:r,context:i,existingBindings:a,onSave:o,onCancel:s})=>{let{t:l}=t(),[u,h]=(0,p.useState)([]),[g,_]=(0,p.useState)([]);(0,p.useEffect)(()=>{e&&(h([]),_([]))},[e]),(0,p.useEffect)(()=>{if(!e)return;let t=e=>{if(e.preventDefault(),e.stopPropagation(),[`Control`,`Shift`,`Alt`,`Meta`].includes(e.key))return;let t=f(e);if(!t)return;let r=[...u,t];h(r);let o=c(r).toLowerCase(),s=a.filter(e=>e.action===n&&e.context===i?!1:c(e.chord).toLowerCase()===o&&e.action!==null).map(e=>`${e.action} (${e.context})`);_(s)};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e,u,a,n,i]);let v=(0,p.useCallback)(()=>{u.length!==0&&o(u.map(e=>{let t=[];return e.ctrl&&t.push(`ctrl`),e.alt&&t.push(`alt`),e.shift&&t.push(`shift`),e.super&&t.push(`cmd`),t.push(e.key===` `?`space`:e.key),t.join(`+`)}).join(` `))},[u,o]),y=(0,p.useCallback)(()=>{h([]),_([])},[]);return e?(0,m.jsx)(`div`,{className:`fixed inset-0 flex items-center justify-center bg-black/50`,style:{zIndex:`var(--z-modal, 100)`},onClick:s,children:(0,m.jsxs)(`div`,{className:`bg-[var(--color-bg-primary)] border border-[var(--color-border-default)] rounded-lg p-6 w-[440px] shadow-xl`,onClick:e=>e.stopPropagation(),children:[(0,m.jsx)(`h3`,{className:`text-base font-medium text-[var(--color-text-primary)] mb-1`,children:l(`keybindings.record.title`)}),(0,m.jsxs)(`p`,{className:`text-sm text-[var(--color-text-secondary)] mb-4`,children:[r,` `,(0,m.jsxs)(`span`,{className:`text-[var(--color-text-muted)]`,children:[`(`,i,`)`]})]}),(0,m.jsx)(`div`,{className:`border border-[var(--color-border-default)] rounded-md p-4 mb-4 text-center min-h-[60px] flex items-center justify-center bg-[var(--color-bg-secondary)]`,children:u.length>0?(0,m.jsx)(`span`,{className:`text-lg font-mono text-[var(--color-text-primary)]`,children:u.map((e,t)=>(0,m.jsxs)(`span`,{children:[t>0&&(0,m.jsx)(`span`,{className:`text-[var(--color-text-muted)] mx-1`,children:` `}),d(e)]},t))}):(0,m.jsx)(`span`,{className:`text-sm text-[var(--color-text-muted)]`,children:l(`keybindings.record.hint`)})}),g.length>0&&(0,m.jsxs)(`div`,{className:`text-sm text-[var(--color-warning)] mb-4`,children:[l(`keybindings.record.conflict`),`: `,g.join(`, `)]}),(0,m.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[u.length>0&&(0,m.jsx)(`button`,{className:`px-3 py-1.5 text-sm text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] transition-colors`,onClick:y,children:l(`keybindings.action.reset`)}),(0,m.jsx)(`button`,{className:`px-3 py-1.5 text-sm text-[var(--color-text-secondary)] hover:text-[var(--color-text-primary)] transition-colors`,onClick:s,children:l(`app.cancel`)}),(0,m.jsx)(`button`,{className:`px-4 py-1.5 text-sm rounded-md transition-colors ${u.length===0?`bg-[var(--color-bg-secondary)] text-[var(--color-text-muted)] cursor-not-allowed`:`bg-[var(--color-accent-brand)] text-[var(--color-bg-primary)] hover:opacity-90`}`,disabled:u.length===0,onClick:v,children:l(`app.confirm`)})]})]})}):null},g=()=>{let{t:e,tryT:n}=t(),{defaults:r,userBlocks:d,bindings:f,warnings:g,loaded:v,loadBindings:y,saveUserBindings:b,resetBindings:x}=u(),[S,C]=(0,p.useState)(``),[w,T]=(0,p.useState)(null),E=(0,p.useCallback)(e=>n(`keybindings.ctx.${e}`)??e,[n]),D=(0,p.useCallback)(e=>n(`keybindings.ctxDesc.${e}`)??``,[n]),O=(0,p.useCallback)(e=>n(`keybindings.act.${e}`)??_(e),[n]);(0,p.useEffect)(()=>{v||y()},[v,y]);let k=(0,p.useMemo)(()=>{if(!v)return[];let e=new Set;if(d)for(let t of d)for(let[n,r]of Object.entries(t.bindings))e.add(`${t.context}:${r??`null`}:${n}`);let t=new Map;for(let n of f){let r=`${n.context}:${n.action}`,i=c(n.chord),a=n.chord.map(e=>{let t=[];return e.ctrl&&t.push(`ctrl`),e.alt&&t.push(`alt`),e.shift&&t.push(`shift`),e.super&&t.push(`cmd`),t.push(e.key===` `?`space`:e.key),t.join(`+`)}).join(` `),o=e.has(`${n.context}:${n.action}:${a}`);t.set(r,{action:n.action??``,displayName:n.action?O(n.action):``,keyDisplay:i,keyRaw:a,context:n.context,source:o?`user`:`default`,isUnbound:n.action===null})}return Array.from(t.values()).filter(e=>!e.isUnbound)},[v,f,d,O]),A=(0,p.useMemo)(()=>S.trim()?k.filter(e=>[e.displayName,e.action,e.keyDisplay,E(e.context)].some(e=>o(S,e).match)):k,[k,S,E]),j=(0,p.useMemo)(()=>{let e=new Map;for(let t of A){let n=e.get(t.context)||[];n.push(t),e.set(t.context,n)}return e},[A]),M=(0,p.useCallback)(async e=>{if(!w)return;let t=d?JSON.parse(JSON.stringify(d)):[],n=t.find(e=>e.context===w.context);n||(n={context:w.context,bindings:{}},t.push(n));for(let[e,t]of Object.entries(n.bindings))t===w.action&&delete n.bindings[e];n.bindings[e]=w.action,await b({bindings:t}),T(null)},[w,d,b]),N=(0,p.useCallback)(async e=>{let t=d?JSON.parse(JSON.stringify(d)):[],n=t.find(t=>t.context===e.context);n||(n={context:e.context,bindings:{}},t.push(n)),n.bindings[e.keyRaw]=null,await b({bindings:t})},[d,b]),P=(0,p.useCallback)(async e=>{if(!d)return;let t=JSON.parse(JSON.stringify(d)),n=t.find(t=>t.context===e.context);if(!n)return;delete n.bindings[e.keyRaw];for(let[t,i]of Object.entries(n.bindings))if(i===e.action||i===null){let i=r.find(t=>t.context===e.context);i&&i.bindings[t]===e.action&&delete n.bindings[t]}let i=t.filter(e=>Object.keys(e.bindings).length>0);await b({bindings:i})},[d,r,b]);return v?(0,m.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,m.jsxs)(`div`,{className:`px-4 py-2 border-b border-[var(--color-border-default)] flex items-center gap-2`,children:[(0,m.jsxs)(`div`,{className:`relative flex-1`,children:[(0,m.jsx)(i,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-muted)]`}),(0,m.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:e(`keybindings.search.placeholder`),className:`w-full pl-8 pr-8 py-1.5 text-sm bg-[var(--color-bg-secondary)] text-[var(--color-text-primary)] border border-[var(--color-border-default)] rounded-md outline-none focus:border-[var(--color-accent-blue)]`}),S&&(0,m.jsx)(`button`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)]`,onClick:()=>C(``),children:(0,m.jsx)(s,{size:14})})]}),(0,m.jsx)(`button`,{className:`p-1.5 text-[var(--color-text-muted)] hover:text-[var(--color-text-secondary)] transition-colors`,onClick:()=>x(),title:e(`keybindings.reset.all`),children:(0,m.jsx)(l,{size:14})})]}),g.length>0&&(0,m.jsx)(`div`,{className:`px-4 py-2 bg-[var(--color-warning-bg,rgba(255,170,0,0.1))] border-b border-[var(--color-border-default)]`,children:g.slice(0,3).map((e,t)=>(0,m.jsxs)(`p`,{className:`text-xs text-[var(--color-warning)]`,children:[e.severity===`error`?`x`:`!`,` `,e.message]},t))}),(0,m.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[Array.from(j.entries()).map(([t,n])=>(0,m.jsxs)(`div`,{className:`mb-2`,children:[(0,m.jsxs)(`div`,{className:`sticky top-0 px-4 py-2 bg-[var(--color-bg-secondary)] border-b border-[var(--color-border-default)]`,children:[(0,m.jsx)(`span`,{className:`text-xs font-semibold text-[var(--color-text-secondary)] uppercase tracking-wider`,children:E(t)}),(0,m.jsx)(`span`,{className:`text-xs text-[var(--color-text-muted)] ml-2 font-normal normal-case tracking-normal`,children:D(t)})]}),n.map(t=>(0,m.jsxs)(`div`,{className:`
2
2
  group flex items-center gap-2 px-4 py-2.5 border-b border-[var(--color-border-muted)]
3
3
  hover:bg-[var(--color-bg-secondary)] transition-colors
4
4
  ${t.source===`user`?`border-l-2 border-l-[var(--color-accent-blue)]`:`border-l-2 border-l-transparent`}
@@ -1,4 +1,4 @@
1
- import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./use-i18n-BvN1piiI.js";import{l as n,u as r}from"./markdown-DCKhnxE9.js";import{t as i}from"./theme-store-e89BUV83.js";import{n as a,t as o}from"./one-light-B9flS40H.js";import{At as s,B as c,Dt as l,J as u,V as d,_t as f,un as p}from"./index-BI5Z_cST.js";var m=e(r(),1),h=n(),g=c,_=5e3,v={telemetry:{zh:`遥测日志`,en:`Telemetry`},process:{zh:`进程输出`,en:`Process`},debug:{zh:`调试日志`,en:`Debug`},transcript:{zh:`对话记录`,en:`Transcript`}};function y(){let{t:e,resolved:n}=t(),r=i(e=>e.resolved),{workers:c,fetchWorkers:y,logsContent:b,logsType:x,logsAvailableTypes:S,logsPath:w,fetchLogs:T}=u(),[E,D]=(0,m.useState)(``),[O,k]=(0,m.useState)(``),[A,j]=(0,m.useState)(!1),M=(0,m.useRef)(null);(0,m.useEffect)(()=>{y();let e=window.location.hash.match(/[?&]worker=(\d+)/);e&&D(e[1])},[y]),(0,m.useEffect)(()=>{E&&T(E)},[E,T]),(0,m.useEffect)(()=>{if(!E&&c.length>0){let e=window.location.hash.match(/[?&]worker=(\d+)/);if(e)D(e[1]);else{let e=c.find(e=>e.isCurrent);e&&D(String(e.pid))}}},[c,E]),(0,m.useEffect)(()=>{if(!A||!E)return;let e=setInterval(()=>{T(E,x||void 0)},_);return()=>clearInterval(e)},[A,E,x,T]),(0,m.useEffect)(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},[b]);let N=(0,m.useCallback)(()=>{E&&T(E,x||void 0)},[E,x,T]),P=(0,m.useCallback)(e=>{E&&T(E,e)},[E,T]),F=(0,m.useMemo)(()=>{if(!O.trim()||!b)return b;let e=O.toLowerCase();return b.split(`
1
+ import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./use-i18n-pIrmaYmw.js";import{l as n,u as r}from"./markdown-DCKhnxE9.js";import{t as i}from"./theme-store-Cvh0uW_P.js";import{n as a,t as o}from"./one-light-B9flS40H.js";import{At as s,B as c,Dt as l,J as u,V as d,_t as f,un as p}from"./index-CcT-vg3O.js";var m=e(r(),1),h=n(),g=c,_=5e3,v={telemetry:{zh:`遥测日志`,en:`Telemetry`},process:{zh:`进程输出`,en:`Process`},debug:{zh:`调试日志`,en:`Debug`},transcript:{zh:`对话记录`,en:`Transcript`}};function y(){let{t:e,resolved:n}=t(),r=i(e=>e.resolved),{workers:c,fetchWorkers:y,logsContent:b,logsType:x,logsAvailableTypes:S,logsPath:w,fetchLogs:T}=u(),[E,D]=(0,m.useState)(``),[O,k]=(0,m.useState)(``),[A,j]=(0,m.useState)(!1),M=(0,m.useRef)(null);(0,m.useEffect)(()=>{y();let e=window.location.hash.match(/[?&]worker=(\d+)/);e&&D(e[1])},[y]),(0,m.useEffect)(()=>{E&&T(E)},[E,T]),(0,m.useEffect)(()=>{if(!E&&c.length>0){let e=window.location.hash.match(/[?&]worker=(\d+)/);if(e)D(e[1]);else{let e=c.find(e=>e.isCurrent);e&&D(String(e.pid))}}},[c,E]),(0,m.useEffect)(()=>{if(!A||!E)return;let e=setInterval(()=>{T(E,x||void 0)},_);return()=>clearInterval(e)},[A,E,x,T]),(0,m.useEffect)(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},[b]);let N=(0,m.useCallback)(()=>{E&&T(E,x||void 0)},[E,x,T]),P=(0,m.useCallback)(e=>{E&&T(E,e)},[E,T]),F=(0,m.useMemo)(()=>{if(!O.trim()||!b)return b;let e=O.toLowerCase();return b.split(`
2
2
  `).filter(t=>t.toLowerCase().includes(e)).join(`
3
3
  `)},[b,O]),I=(0,m.useMemo)(()=>{if(!O.trim()||!b)return 0;let e=O.toLowerCase();return b.split(`
4
4
  `).filter(t=>t.toLowerCase().includes(e)).length},[b,O]),L=c.find(e=>String(e.pid)===E);return(0,h.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,h.jsxs)(`div`,{className:`flex-none px-4 py-3 border-b border-border-primary bg-bg-primary`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,h.jsx)(p,{size:18,className:`text-accent-brand`}),(0,h.jsx)(`h1`,{className:`text-base font-semibold text-text-primary`,children:e(`logs.title`)})]}),(0,h.jsxs)(`select`,{value:E,onChange:e=>D(e.target.value),className:`px-2.5 py-1.5 text-xs rounded-lg border border-border-primary bg-bg-secondary
@@ -1,2 +1,2 @@
1
- import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{i as t,ot as n,st as r,t as i,tt as a}from"./use-i18n-BvN1piiI.js";import{l as o,u as s}from"./markdown-DCKhnxE9.js";import{t as c}from"./server-CnUlxMCB.js";import{At as l,En as u,J as d,O as f,V as p,an as m,cn as h,rn as g}from"./index-BI5Z_cST.js";var _=t(`hard-drive`,[[`path`,{d:`M10 16h.01`,key:`1bzywj`}],[`path`,{d:`M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`18tbho`}],[`path`,{d:`M21.946 12.013H2.054`,key:`zqlbp7`}],[`path`,{d:`M6 16h.01`,key:`1pmjb7`}]]),v=t(`memory-stick`,[[`path`,{d:`M12 12v-2`,key:`fwoke6`}],[`path`,{d:`M12 18v-2`,key:`qj6yno`}],[`path`,{d:`M16 12v-2`,key:`heuere`}],[`path`,{d:`M16 18v-2`,key:`s1ct0w`}],[`path`,{d:`M2 11h1.5`,key:`15p63e`}],[`path`,{d:`M20 18v-2`,key:`12ehxp`}],[`path`,{d:`M20.5 11H22`,key:`khsy7a`}],[`path`,{d:`M4 18v-2`,key:`1c3oqr`}],[`path`,{d:`M8 12v-2`,key:`1mwtfd`}],[`path`,{d:`M8 18v-2`,key:`qcmpov`}],[`rect`,{x:`2`,y:`6`,width:`20`,height:`10`,rx:`2`,key:`1qcswk`}]]),y=e(s(),1),b=8e3,x=r((e,t)=>({metrics:null,loading:!1,error:null,_pollTimer:null,fetchMetrics:async()=>{e({loading:!t().metrics,error:null});try{let t=await n(`/api/v1/metrics`,{headers:a()});if(!t.ok)throw Error(`Failed to fetch metrics: ${t.status}`);e({metrics:(await t.json()).data,loading:!1})}catch(t){e({error:t.message,loading:!1})}},startPolling:(n=b)=>{let{stopPolling:r,fetchMetrics:i}=t();r(),i(),e({_pollTimer:setInterval(i,n)})},stopPolling:()=>{let{_pollTimer:n}=t();n&&(clearInterval(n),e({_pollTimer:null}))}})),S=o(),C={interactive:`bg-blue-50 text-blue-700 border border-blue-200 dark:bg-blue-500/10 dark:text-blue-400 dark:border-blue-500/20`,bg:`bg-purple-50 text-purple-700 border border-purple-200 dark:bg-purple-500/10 dark:text-purple-400 dark:border-purple-500/20`,daemon:`bg-green-50 text-green-700 border border-green-200 dark:bg-green-500/10 dark:text-green-400 dark:border-green-500/20`,"daemon-worker":`bg-orange-50 text-orange-700 border border-orange-200 dark:bg-orange-500/10 dark:text-orange-400 dark:border-orange-500/20`};function w(){let{t:e}=i(),{metrics:t,loading:n,error:r,fetchMetrics:a,startPolling:o,stopPolling:s}=x(),{workers:c,fetchWorkers:p}=d();if((0,y.useEffect)(()=>(o(8e3),p(),()=>s()),[o,s,p]),n&&!t)return(0,S.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,S.jsx)(f,{size:`large`,text:e(`metrics.loading`)})});if(r&&!t)return(0,S.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,S.jsxs)(`div`,{className:`text-center`,children:[(0,S.jsx)(`div`,{className:`text-text-secondary mb-4`,children:r}),(0,S.jsx)(`button`,{onClick:a,className:`px-4 py-2 bg-accent-brand text-accent-brand-foreground rounded-lg text-sm`,children:e(`metrics.refresh`)})]})});let m=T(t?.instances||[],c);return(0,S.jsxs)(`div`,{className:`flex-1 overflow-auto p-4 md:p-6`,children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between mb-6`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(u,{size:20,className:`text-accent-brand`}),(0,S.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:e(`metrics.title`)})]}),(0,S.jsxs)(`button`,{onClick:()=>{a(),p()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-text-secondary
1
+ import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{i as t,ot as n,st as r,t as i,tt as a}from"./use-i18n-pIrmaYmw.js";import{l as o,u as s}from"./markdown-DCKhnxE9.js";import{t as c}from"./server-BYrFK9uI.js";import{At as l,En as u,J as d,O as f,V as p,an as m,cn as h,rn as g}from"./index-CcT-vg3O.js";var _=t(`hard-drive`,[[`path`,{d:`M10 16h.01`,key:`1bzywj`}],[`path`,{d:`M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`18tbho`}],[`path`,{d:`M21.946 12.013H2.054`,key:`zqlbp7`}],[`path`,{d:`M6 16h.01`,key:`1pmjb7`}]]),v=t(`memory-stick`,[[`path`,{d:`M12 12v-2`,key:`fwoke6`}],[`path`,{d:`M12 18v-2`,key:`qj6yno`}],[`path`,{d:`M16 12v-2`,key:`heuere`}],[`path`,{d:`M16 18v-2`,key:`s1ct0w`}],[`path`,{d:`M2 11h1.5`,key:`15p63e`}],[`path`,{d:`M20 18v-2`,key:`12ehxp`}],[`path`,{d:`M20.5 11H22`,key:`khsy7a`}],[`path`,{d:`M4 18v-2`,key:`1c3oqr`}],[`path`,{d:`M8 12v-2`,key:`1mwtfd`}],[`path`,{d:`M8 18v-2`,key:`qcmpov`}],[`rect`,{x:`2`,y:`6`,width:`20`,height:`10`,rx:`2`,key:`1qcswk`}]]),y=e(s(),1),b=8e3,x=r((e,t)=>({metrics:null,loading:!1,error:null,_pollTimer:null,fetchMetrics:async()=>{e({loading:!t().metrics,error:null});try{let t=await n(`/api/v1/metrics`,{headers:a()});if(!t.ok)throw Error(`Failed to fetch metrics: ${t.status}`);e({metrics:(await t.json()).data,loading:!1})}catch(t){e({error:t.message,loading:!1})}},startPolling:(n=b)=>{let{stopPolling:r,fetchMetrics:i}=t();r(),i(),e({_pollTimer:setInterval(i,n)})},stopPolling:()=>{let{_pollTimer:n}=t();n&&(clearInterval(n),e({_pollTimer:null}))}})),S=o(),C={interactive:`bg-blue-50 text-blue-700 border border-blue-200 dark:bg-blue-500/10 dark:text-blue-400 dark:border-blue-500/20`,bg:`bg-purple-50 text-purple-700 border border-purple-200 dark:bg-purple-500/10 dark:text-purple-400 dark:border-purple-500/20`,daemon:`bg-green-50 text-green-700 border border-green-200 dark:bg-green-500/10 dark:text-green-400 dark:border-green-500/20`,"daemon-worker":`bg-orange-50 text-orange-700 border border-orange-200 dark:bg-orange-500/10 dark:text-orange-400 dark:border-orange-500/20`};function w(){let{t:e}=i(),{metrics:t,loading:n,error:r,fetchMetrics:a,startPolling:o,stopPolling:s}=x(),{workers:c,fetchWorkers:p}=d();if((0,y.useEffect)(()=>(o(8e3),p(),()=>s()),[o,s,p]),n&&!t)return(0,S.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,S.jsx)(f,{size:`large`,text:e(`metrics.loading`)})});if(r&&!t)return(0,S.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,S.jsxs)(`div`,{className:`text-center`,children:[(0,S.jsx)(`div`,{className:`text-text-secondary mb-4`,children:r}),(0,S.jsx)(`button`,{onClick:a,className:`px-4 py-2 bg-accent-brand text-accent-brand-foreground rounded-lg text-sm`,children:e(`metrics.refresh`)})]})});let m=T(t?.instances||[],c);return(0,S.jsxs)(`div`,{className:`flex-1 overflow-auto p-4 md:p-6`,children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between mb-6`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(u,{size:20,className:`text-accent-brand`}),(0,S.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:e(`metrics.title`)})]}),(0,S.jsxs)(`button`,{onClick:()=>{a(),p()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-text-secondary
2
2
  hover:text-text-primary hover:bg-bg-hover rounded-lg transition-colors`,title:e(`metrics.refresh`),children:[(0,S.jsx)(l,{size:14}),(0,S.jsx)(`span`,{children:e(`metrics.refresh`)})]})]}),t&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(E,{metrics:t}),(0,S.jsx)(O,{workers:m})]})]})}function T(e,t){return e.map(e=>{let n=t.find(t=>t.pid===e.pid);return{...e,kind:n?.kind,name:n?.name,url:n?.url||n?.endpoint,status:n?.status}})}function E({metrics:e}){let{t}=i(),n=e.memTotalMib>0?e.memUsedMib/e.memTotalMib*100:0,r=e.diskTotal>0?e.diskUsed/e.diskTotal*100:0;return(0,S.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4 mb-6`,children:[(0,S.jsx)(D,{icon:(0,S.jsx)(m,{size:18}),label:t(`metrics.cpu`),value:`${e.cpuUsedPct.toFixed(1)}%`,subtext:`${e.cpuCount} ${t(`metrics.cores`)}`,percent:e.cpuUsedPct,colorClasses:j(e.cpuUsedPct)}),(0,S.jsx)(D,{icon:(0,S.jsx)(v,{size:18}),label:t(`metrics.memory`),value:`${M(e.memUsedMib)} / ${M(e.memTotalMib)}`,subtext:`${n.toFixed(1)}%`,percent:n,colorClasses:j(n)}),(0,S.jsx)(D,{icon:(0,S.jsx)(_,{size:18}),label:t(`metrics.disk`),value:`${N(e.diskUsed)} / ${N(e.diskTotal)}`,subtext:`${r.toFixed(1)}%`,percent:r,colorClasses:j(r)})]})}function D({icon:e,label:t,value:n,subtext:r,percent:i,colorClasses:a}){let[o,s]=a;return(0,S.jsxs)(`div`,{className:`bg-bg-secondary rounded-xl p-4 border border-border-primary`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,S.jsx)(`span`,{className:o,children:e}),(0,S.jsx)(`span`,{className:`text-sm font-medium text-text-secondary`,children:t})]}),(0,S.jsx)(`div`,{className:`text-xl font-semibold text-text-primary mb-1`,children:n}),(0,S.jsx)(`div`,{className:`text-xs text-text-tertiary mb-3`,children:r}),(0,S.jsx)(`div`,{className:`h-2 bg-bg-tertiary rounded-full overflow-hidden`,children:(0,S.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${s}`,style:{width:`${Math.min(i,100)}%`}})})]})}function O({workers:e}){let{t}=i();return e.length===0?(0,S.jsx)(`div`,{className:`text-center py-12 text-text-tertiary`,children:t(`metrics.noWorkers`)}):(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,S.jsx)(m,{size:18,className:`text-text-secondary`}),(0,S.jsxs)(`h2`,{className:`text-base font-medium text-text-primary`,children:[`Workers (`,e.length,`)`]})]}),(0,S.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>(0,S.jsx)(k,{worker:e},e.id))})]})}function k({worker:e}){let{t}=i();return(0,S.jsx)(`div`,{className:`bg-bg-secondary rounded-xl p-4 md:p-5 border transition-colors hover:border-gray-300 dark:hover:border-gray-600 border-border-primary ${e.error?`opacity-60`:``}`,children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,S.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,S.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full ${e.error?`bg-red-400`:`bg-green-400`}`}),e.kind&&(0,S.jsx)(`span`,{className:`inline-block px-2.5 py-0.5 text-xs font-medium rounded-md ${C[e.kind]||`bg-gray-100 text-gray-600`}`,children:e.kind}),(0,S.jsx)(`span`,{className:`text-sm font-medium text-text-primary`,children:e.name||e.hostname}),e.isCurrent&&(0,S.jsx)(`span`,{className:`text-[10px] uppercase font-bold tracking-wider px-1.5 py-0.5 bg-accent-brand/10 text-accent-brand rounded`,children:t(`metrics.current`)}),e.error&&(0,S.jsx)(`span`,{className:`text-xs text-red-400`,children:e.error})]}),(0,S.jsxs)(`span`,{className:`text-xs text-text-tertiary font-mono bg-bg-tertiary px-2 py-0.5 rounded-md border border-border-primary/50`,children:[`PID `,e.pid]})]}),(0,S.jsxs)(`div`,{className:`flex flex-col md:flex-row md:items-start justify-between gap-4 md:gap-6`,children:[(0,S.jsxs)(`div`,{className:`flex flex-col gap-2.5 flex-1 min-w-0`,children:[(0,S.jsx)(p,{path:e.cwd,displayMode:`basename`,className:`text-[13px] text-text-secondary font-mono truncate max-w-full`}),e.url&&(0,S.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,S.jsx)(g,{size:14,className:`text-text-tertiary flex-none`}),(0,S.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`text-sm text-accent-brand hover:underline truncate`,children:e.url})]})]}),e.rssMib>0||e.heapUsedMib>0?(0,S.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 flex-none`,style:{minWidth:`460px`},children:[(0,S.jsxs)(`div`,{className:`min-w-[100px]`,children:[(0,S.jsx)(A,{icon:(0,S.jsx)(v,{size:14}),label:`RSS`,value:`${e.rssMib.toFixed(0)} MiB`}),(0,S.jsx)(`div`,{className:`mt-1.5 h-1.5 bg-bg-tertiary rounded-full overflow-hidden`,children:(0,S.jsx)(`div`,{className:`h-full rounded-full bg-blue-500 transition-all duration-500`,style:{width:`${Math.min(e.rssMib/2048*100,100)}%`}})})]}),(0,S.jsxs)(`div`,{className:`min-w-[140px]`,children:[(0,S.jsx)(A,{icon:(0,S.jsx)(v,{size:14}),label:`Heap`,value:`${e.heapUsedMib.toFixed(0)} / ${e.heapTotalMib.toFixed(0)} MiB`}),e.heapTotalMib>0&&(0,S.jsx)(`div`,{className:`mt-1.5 h-1.5 bg-bg-tertiary rounded-full overflow-hidden`,children:(0,S.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${j(e.heapUsedMib/e.heapTotalMib*100)[1]}`,style:{width:`${Math.min(e.heapUsedMib/e.heapTotalMib*100,100)}%`}})})]}),(0,S.jsx)(`div`,{className:`min-w-[80px]`,children:(0,S.jsx)(A,{icon:(0,S.jsx)(h,{size:14}),label:t(`metrics.uptime`),value:P(e.uptimeSeconds)})}),(0,S.jsx)(`div`,{className:`min-w-[60px]`,children:(0,S.jsx)(A,{icon:(0,S.jsx)(c,{size:14}),label:t(`metrics.version`),value:e.version||`-`})})]}):(0,S.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 flex-none`,style:{minWidth:`200px`},children:[(0,S.jsx)(`div`,{className:`min-w-[80px]`,children:(0,S.jsx)(A,{icon:(0,S.jsx)(h,{size:14}),label:t(`metrics.uptime`),value:P(e.uptimeSeconds)})}),(0,S.jsx)(`div`,{className:`min-w-[60px]`,children:(0,S.jsx)(A,{icon:(0,S.jsx)(c,{size:14}),label:t(`metrics.version`),value:e.version||`-`})})]})]})]})})}function A({icon:e,label:t,value:n}){return(0,S.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-1.5 text-text-tertiary`,children:[e,(0,S.jsx)(`span`,{className:`text-[11px] font-medium uppercase tracking-wider`,children:t})]}),(0,S.jsx)(`div`,{className:`text-sm font-semibold text-text-primary`,style:{fontVariantNumeric:`tabular-nums`},children:n})]})}function j(e){return e>=90?[`text-red-500`,`bg-red-500`]:e>=70?[`text-amber-500`,`bg-amber-500`]:[`text-green-500`,`bg-green-500`]}function M(e){return e>=1024?`${(e/1024).toFixed(1)} GiB`:`${e} MiB`}function N(e){if(e===0)return`0 B`;let t=e/1073741824;return t>=1?`${t.toFixed(1)} GB`:`${(e/1048576).toFixed(0)} MB`}function P(e){if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m ${e%60}s`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return t>=24?`${Math.floor(t/24)}d ${t%24}h`:`${t}h ${n}m`}export{w as MetricsView};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{i as t,st as n,t as r}from"./use-i18n-BvN1piiI.js";import{l as i,u as a}from"./markdown-DCKhnxE9.js";import{t as o}from"./loader-circle-OavGeXCF.js";import{t as s}from"./power-f1Ij2Msg.js";import{t as c}from"./triangle-alert-Bgaqn5eg.js";import{At as ee,Cn as te,Dt as l,Mt as u,O as ne,Sn as d,_t as f,ct as p,dt as m,in as h,lt as g,rn as _,yt as re}from"./index-BI5Z_cST.js";var v=t(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),y=t(`store`,[[`path`,{d:`M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5`,key:`slp6dd`}],[`path`,{d:`M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244`,key:`o0xfot`}],[`path`,{d:`M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05`,key:`wn3emo`}]]),b=e(a(),1);function x(e,t){return`${e}@${t}`}var S=m,C=p,w=g,ie=n((e,t)=>({plugins:[],loading:!1,error:null,marketplaces:[],marketplaceLoading:!1,availablePlugins:[],browsingMarketplace:null,browsingLoading:!1,browsingError:null,operatingPlugins:new Set,fetchPlugins:async()=>{e({loading:!0,error:null});try{let t=await w(`/api/v1/plugins`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=(await t.json()).data;e({plugins:Array.isArray(n)?n.map(e=>({...e,canRemove:e.canRemove,canSwitchoff:e.canSwitchoff,canEdit:e.canEdit})):[],loading:!1})}catch(t){console.warn(`[plugin-store] fetchPlugins failed:`,t),e({error:t.message,loading:!1})}},fetchMarketplaces:async()=>{e({marketplaceLoading:!0});try{let t=await w(`/api/v1/plugins/marketplaces`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=(await t.json()).data;e({marketplaces:Array.isArray(n)?n:[],marketplaceLoading:!1})}catch(t){console.warn(`[plugin-store] fetchMarketplaces failed:`,t),e({marketplaceLoading:!1})}},browseMarketplace:async t=>{e({browsingMarketplace:t,browsingLoading:!0,browsingError:null});try{let n=await S(`/api/v1/plugins/marketplaces/browse`,{marketplace:t});if(!n.ok){let e=await n.json().catch(()=>null);throw Error(e?.error?.message||`HTTP ${n.status}`)}let r=await n.json();e({availablePlugins:(Array.isArray(r.data)?r.data:[]).map(e=>({name:e.name,version:e.version,description:e.description,marketplace:e.marketplaceName||t,installed:!!e.status,author:e.author,license:e.license,homepage:e.homepage,repository:e.repository,keywords:e.keywords,category:e.category,features:e.features,source:e.source,dependencies:e.dependencies})),browsingLoading:!1})}catch(t){console.warn(`[plugin-store] browseMarketplace failed:`,t),e({browsingError:t.message,browsingLoading:!1})}},browseAllMarketplaces:async()=>{let{marketplaces:n}=t();if(n.length!==0){e({browsingMarketplace:`__all__`,browsingLoading:!0,browsingError:null});try{let t=await Promise.allSettled(n.map(async e=>{let t=await S(`/api/v1/plugins/marketplaces/browse`,{marketplace:e.name});if(!t.ok){let e=await t.json().catch(()=>null);throw Error(e?.error?.message||`HTTP ${t.status}`)}let n=await t.json();return(Array.isArray(n.data)?n.data:[]).map(t=>({name:t.name,version:t.version,description:t.description,marketplace:t.marketplaceName||e.name,installed:!!t.status,author:t.author,license:t.license,homepage:t.homepage,repository:t.repository,keywords:t.keywords,category:t.category,features:t.features,source:t.source,dependencies:t.dependencies}))})),r=[],i=!1;for(let e of t)e.status===`fulfilled`?r.push(...e.value):i=!0;let a=new Set,o=r.filter(e=>{let t=`${e.name}@${e.marketplace}`;return!a.has(t)&&(a.add(t),!0)});e({availablePlugins:o,browsingLoading:!1,browsingError:i&&o.length===0?`Some marketplaces failed to load`:null})}catch(t){console.warn(`[plugin-store] browseAllMarketplaces failed:`,t),e({browsingError:t.message,browsingLoading:!1})}}},enablePlugin:async(n,r)=>{let i=x(n,r);e(e=>({operatingPlugins:new Set(e.operatingPlugins).add(i)}));try{let e=await S(`/api/v1/plugins/enable`,{plugin:i});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message||`HTTP ${e.status}`)}await t().fetchPlugins()}finally{e(e=>{let t=new Set(e.operatingPlugins);return t.delete(i),{operatingPlugins:t}})}},disablePlugin:async(n,r)=>{let i=x(n,r);e(e=>({operatingPlugins:new Set(e.operatingPlugins).add(i)}));try{let e=await S(`/api/v1/plugins/disable`,{plugin:i});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message||`HTTP ${e.status}`)}await t().fetchPlugins()}finally{e(e=>{let t=new Set(e.operatingPlugins);return t.delete(i),{operatingPlugins:t}})}},uninstallPlugin:async(n,r)=>{let i=x(n,r);e(e=>({operatingPlugins:new Set(e.operatingPlugins).add(i)}));try{let e=await S(`/api/v1/plugins/uninstall`,{plugin:i});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message||`HTTP ${e.status}`)}await t().fetchPlugins()}finally{e(e=>{let t=new Set(e.operatingPlugins);return t.delete(i),{operatingPlugins:t}})}},installPlugin:async(n,r,i)=>{let a=x(n,r);e(e=>({operatingPlugins:new Set(e.operatingPlugins).add(a)}));try{let e=await S(`/api/v1/plugins`,{plugin:a,options:i?{scope:i}:void 0});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message||`HTTP ${e.status}`)}await t().fetchPlugins();let n=t();n.browsingMarketplace&&(n.browsingMarketplace===`__all__`?await t().browseAllMarketplaces():await t().browseMarketplace(n.browsingMarketplace))}finally{e(e=>{let t=new Set(e.operatingPlugins);return t.delete(a),{operatingPlugins:t}})}},addMarketplace:async(e,n)=>{let r=await S(`/api/v1/plugins/marketplaces`,{source:e,name:n});if(!r.ok){let e=await r.json().catch(()=>null);throw Error(e?.error?.message||`HTTP ${r.status}`)}await t().fetchMarketplaces()},removeMarketplace:async e=>{let n=await C(`/api/v1/plugins/marketplaces/${encodeURIComponent(e)}`);if(!n.ok){let e=await n.json().catch(()=>null);throw Error(e?.error?.message||`HTTP ${n.status}`)}await t().fetchMarketplaces()}})),T=i(),E=12;function D(e){let t=[e.category,...e.features||[],...e.keywords||[],e.name,e.description||``].join(` `).toLowerCase();return/\b(skill|skills)\b/.test(t)?`skills`:/\b(mcp|model[- ]?context)\b/.test(t)?`mcp`:/\b(hook|hooks)\b/.test(t)?`hooks`:/\b(tool|tools)\b/.test(t)?`tools`:`unknown`}function O(){let{t:e}=r(),{plugins:t,marketplaces:n,loading:i,marketplaceLoading:a,error:s,operatingPlugins:p,availablePlugins:m,browsingLoading:h,browsingError:g,fetchPlugins:_,fetchMarketplaces:v,browseMarketplace:x,browseAllMarketplaces:S,enablePlugin:C,disablePlugin:w,uninstallPlugin:O,installPlugin:k,addMarketplace:A,removeMarketplace:j}=ie(),[M,N]=(0,b.useState)(`installed`),[P,ce]=(0,b.useState)(``),[F,le]=(0,b.useState)(`all`),[I,ue]=(0,b.useState)(`all`),[L,de]=(0,b.useState)(`all`),[fe,pe]=(0,b.useState)(E),[me,he]=(0,b.useState)(E),[R,ge]=(0,b.useState)(null),[_e,ve]=(0,b.useState)(!1),[ye,z]=(0,b.useState)(null),[B,V]=(0,b.useState)(!1),[H,be]=(0,b.useState)(``),[U,xe]=(0,b.useState)(``),[Se,Ce]=(0,b.useState)(!1),[we,W]=(0,b.useState)(null),[Te,G]=(0,b.useState)(null),[Ee,K]=(0,b.useState)(null),[q,J]=(0,b.useState)(``),[Y,X]=(0,b.useState)(``),[De,Oe]=(0,b.useState)(null),ke=(0,b.useCallback)(e=>{Oe(t=>t===e?null:e)},[]);(0,b.useEffect)(()=>{_(),v()},[_,v]),(0,b.useEffect)(()=>{M===`browse`&&!q&&n.length>0&&(J(`__all__`),S())},[M,n,q,S]);let Ae=(0,b.useCallback)(async e=>{z(null);try{e.status===`enabled`?await w(e.name,e.marketplace):await C(e.name,e.marketplace)}catch(e){z(e.message)}},[C,w]),je=(0,b.useCallback)(async e=>{z(null),G(null);try{await O(e.name,e.marketplace)}catch(e){z(e.message)}},[O]),Me=(0,b.useCallback)(async(e,t)=>{z(null);try{await k(e.name,e.marketplace,t)}catch(e){z(e.message)}},[k]),Ne=(0,b.useCallback)(async()=>{let e=H.trim();if(e){Ce(!0),W(null);try{await A(e,U.trim()||void 0),be(``),xe(``),V(!1)}catch(e){W(e.message)}finally{Ce(!1)}}},[H,U,A]),Pe=(0,b.useCallback)(async e=>{z(null),K(null);try{if(await j(e),q===e&&n.length>1){let t=n.find(t=>t.name!==e);t&&(J(t.name),x(t.name))}}catch(e){z(e.message)}},[j,q,n,x]),Fe=(0,b.useCallback)(()=>{_(),v(),M===`browse`&&q&&(q===`__all__`?S():x(q))},[_,v,M,q,x,S]),Ie=(0,b.useCallback)(e=>{J(e),X(``),e===`__all__`?S():x(e)},[x,S]),Le=e=>`${e.name}@${e.marketplace}`,Re=(0,b.useMemo)(()=>{let e=new Set(t.map(e=>e.marketplace));return Array.from(e).sort()},[t]),Z=(0,b.useMemo)(()=>{let e=t;F!==`all`&&(e=e.filter(e=>e.marketplace===F)),L!==`all`&&(e=e.filter(e=>L===`enabled`?e.status===`enabled`:e.status!==`enabled`)),I!==`all`&&(e=e.filter(e=>D(e)===I));let n=P.trim().toLowerCase();return n&&(e=e.filter(e=>e.name.toLowerCase().includes(n)||e.description&&e.description.toLowerCase().includes(n)||e.marketplace.toLowerCase().includes(n)||D(e).includes(n))),e},[t,F,I,L,P]),Q=(0,b.useMemo)(()=>{let e=m;I!==`all`&&(e=e.filter(e=>D(e)===I));let t=Y.trim().toLowerCase();return t&&(e=e.filter(e=>e.name.toLowerCase().includes(t)||e.description&&e.description.toLowerCase().includes(t)||D(e).includes(t))),e},[m,Y,I]);(0,b.useEffect)(()=>{pe(E)},[P,F,I,L,t.length]),(0,b.useEffect)(()=>{he(E)},[Y,I,m.length,q]);let ze=(0,b.useMemo)(()=>Z.slice(0,fe),[Z,fe]),Be=(0,b.useMemo)(()=>Q.slice(0,me),[Q,me]),Ve=(0,b.useCallback)(()=>{pe(e=>Math.min(e+E,Z.length))},[Z.length]),He=(0,b.useCallback)(()=>{he(e=>Math.min(e+E,Q.length))},[Q.length]);(0,b.useEffect)(()=>{if(!R){ve(!1);return}let e=()=>{ve(R.scrollTop>480)};return e(),R.addEventListener(`scroll`,e,{passive:!0}),()=>R.removeEventListener(`scroll`,e)},[R,M]);let Ue=(0,b.useCallback)(()=>{R?.scrollTo({top:0,behavior:`smooth`})},[R]),$=(0,b.useMemo)(()=>{let e={skills:0,mcp:0,hooks:0,tools:0,unknown:0},n=M===`browse`?m:t;for(let t of n)e[D(t)]+=1;return e},[t,m,M]),We=t.filter(e=>e.status===`enabled`).length;return(0,T.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden bg-bg-primary`,children:[(0,T.jsx)(`div`,{className:`flex-none border-b border-border-muted px-6 py-4`,children:(0,T.jsxs)(`div`,{className:`max-w-3xl mx-auto`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:e(`plugins.title`)}),M===`installed`&&t.length>0&&(0,T.jsxs)(`p`,{className:`text-sm text-text-tertiary mt-0.5`,children:[t.length,` `,e(`plugins.totalCount`),` · `,We,` `,e(`plugins.enabled`)]}),M===`browse`&&q&&!h&&m.length>0&&(0,T.jsxs)(`p`,{className:`text-sm text-text-tertiary mt-0.5`,children:[m.length,` `,e(`plugins.totalCount`)]}),M===`marketplaces`&&n.length>0&&(0,T.jsxs)(`p`,{className:`text-sm text-text-tertiary mt-0.5`,children:[n.length,` `,e(`plugins.totalCount`)]})]}),(0,T.jsx)(`button`,{onClick:Fe,disabled:i||h,className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-all ${i||h?`opacity-50 cursor-not-allowed border-border-muted text-text-secondary`:`border-border-muted text-text-secondary hover:text-text-primary hover:border-text-primary/20 hover:bg-bg-secondary`}`,title:e(`plugins.refresh`),children:(0,T.jsx)(ee,{size:14,className:i||h?`animate-spin`:``})})]}),(0,T.jsxs)(`div`,{className:`flex gap-1 border-b border-border-muted`,children:[(0,T.jsx)(`button`,{onClick:()=>{N(`installed`),z(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${M===`installed`?`text-text-primary border-text-primary`:`text-text-secondary border-transparent hover:text-text-primary`}`,children:e(`plugins.installedPlugins`)}),(0,T.jsx)(`button`,{onClick:()=>{N(`browse`),z(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${M===`browse`?`text-text-primary border-text-primary`:`text-text-secondary border-transparent hover:text-text-primary`}`,children:e(`plugins.browseMarketplace`)}),(0,T.jsx)(`button`,{onClick:()=>{N(`marketplaces`),z(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${M===`marketplaces`?`text-text-primary border-text-primary`:`text-text-secondary border-transparent hover:text-text-primary`}`,children:e(`plugins.marketplaces`)})]}),M===`installed`&&t.length>0&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2 mt-4`,children:[(0,T.jsxs)(`div`,{className:`flex-1 relative`,children:[(0,T.jsx)(l,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary pointer-events-none`}),(0,T.jsx)(`input`,{type:`text`,value:P,onChange:e=>ce(e.target.value),placeholder:e(`plugins.searchPlaceholder`),className:`w-full bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg pl-9 pr-8 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary`}),P&&(0,T.jsx)(`button`,{onClick:()=>ce(``),className:`absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center rounded-full text-text-tertiary hover:text-text-secondary transition-colors`,children:(0,T.jsx)(f,{size:12})})]}),Re.length>1&&(0,T.jsxs)(`select`,{value:F,onChange:e=>le(e.target.value),className:`bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0 max-w-[120px] sm:max-w-[160px]`,children:[(0,T.jsx)(`option`,{value:`all`,children:e(`plugins.allMarketplaces`)}),Re.map(e=>(0,T.jsx)(`option`,{value:e,children:e},e))]}),(0,T.jsxs)(`select`,{value:L,onChange:e=>de(e.target.value),className:`bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0`,children:[(0,T.jsx)(`option`,{value:`all`,children:e(`plugins.filterStatusAll`)}),(0,T.jsx)(`option`,{value:`enabled`,children:e(`plugins.filterStatusEnabled`)}),(0,T.jsx)(`option`,{value:`disabled`,children:e(`plugins.filterStatusDisabled`)})]})]}),(M===`installed`||M===`browse`)&&(0,T.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-3`,children:[[`all`,e(`plugins.kindAll`),M===`installed`?t.length:m.length],[`skills`,e(`plugins.kindSkills`),$.skills],[`mcp`,e(`plugins.kindMcp`),$.mcp],[`hooks`,e(`plugins.kindHooks`),$.hooks],[`tools`,e(`plugins.kindTools`),$.tools],[`unknown`,e(`plugins.kindUnknown`),$.unknown]].map(([e,t,n])=>(0,T.jsxs)(`button`,{type:`button`,onClick:()=>ue(e),className:`px-2.5 py-1 rounded-full text-[12px] border transition-colors ${I===e?`bg-bg-secondary text-text-primary border-text-primary/30 font-medium`:`bg-transparent text-text-tertiary border-border-muted hover:text-text-secondary`}`,children:[t,(0,T.jsx)(`span`,{className:`ml-1 opacity-70`,children:n})]},e))}),M===`browse`&&n.length>0&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2 mt-4`,children:[(0,T.jsxs)(`div`,{className:`flex-1 relative`,children:[(0,T.jsx)(l,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary pointer-events-none`}),(0,T.jsx)(`input`,{type:`text`,value:Y,onChange:e=>X(e.target.value),placeholder:e(`plugins.searchPlaceholder`),className:`w-full bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg pl-9 pr-8 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary`}),Y&&(0,T.jsx)(`button`,{onClick:()=>X(``),className:`absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center rounded-full text-text-tertiary hover:text-text-secondary transition-colors`,children:(0,T.jsx)(f,{size:12})})]}),(0,T.jsxs)(`select`,{value:q,onChange:e=>Ie(e.target.value),className:`bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0 max-w-[120px] sm:max-w-[160px]`,children:[(0,T.jsx)(`option`,{value:`__all__`,children:e(`plugins.allMarketplaces`)}),n.map(e=>(0,T.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]})]})}),(0,T.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,T.jsx)(`div`,{ref:ge,className:`h-full overflow-y-auto px-6 py-6`,children:(0,T.jsxs)(`div`,{className:`max-w-3xl mx-auto space-y-6`,children:[ye&&(0,T.jsxs)(`div`,{className:`bg-accent-red/10 border border-accent-red/30 rounded-xl p-3.5 text-accent-red text-[13px] flex items-center justify-between`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,T.jsx)(c,{size:14,className:`shrink-0`}),(0,T.jsxs)(`span`,{className:`truncate`,children:[e(`plugins.operationFailed`),`: `,ye]})]}),(0,T.jsx)(`button`,{onClick:()=>z(null),className:`w-5 h-5 flex items-center justify-center rounded-full hover:bg-accent-red/20 transition-colors shrink-0 ml-3`,children:(0,T.jsx)(f,{size:12})})]}),M===`installed`&&(0,T.jsxs)(T.Fragment,{children:[i&&t.length===0&&(0,T.jsx)(`div`,{className:`flex flex-col items-center justify-center py-20`,children:(0,T.jsx)(ne,{size:`small`,text:e(`plugins.loading`)})}),s&&!i&&t.length===0&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20`,children:[(0,T.jsx)(c,{size:40,className:`text-text-tertiary opacity-40 mb-4`}),(0,T.jsx)(`div`,{className:`text-[14px] text-text-secondary font-medium mb-3`,children:e(`plugins.error`)}),(0,T.jsx)(`button`,{onClick:_,className:`px-4 py-2 rounded-lg text-[13px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors`,children:e(`plugins.retry`)})]}),!i&&!s&&t.length===0&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-text-tertiary`,children:[(0,T.jsx)(d,{size:48,className:`mb-4 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[15px] font-medium mb-1.5 text-text-secondary`,children:e(`plugins.noPlugins`)}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noPluginsHint`)})]}),t.length>0&&Z.length===0&&!i&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-text-tertiary`,children:[(0,T.jsx)(l,{size:36,className:`mb-3 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noSearchResults`)})]}),Z.length>0&&(0,T.jsxs)(`div`,{className:`space-y-3`,children:[ze.map(t=>{let n=Le(t);return(0,T.jsx)(oe,{plugin:t,isEnabled:t.status===`enabled`,isOperating:p.has(n),isExpanded:De===n,confirmUninstall:Te===n,onToggle:()=>Ae(t),onUninstall:()=>je(t),onConfirmUninstall:()=>G(n),onCancelUninstall:()=>G(null),onExpand:()=>ke(n),t:e},n)}),(0,T.jsx)(ae,{visible:ze.length,total:Z.length,onLoadMore:Ve,scrollRoot:R,t:e})]})]}),M===`browse`&&(0,T.jsxs)(T.Fragment,{children:[!a&&n.length===0&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-text-tertiary`,children:[(0,T.jsx)(y,{size:48,className:`mb-4 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[15px] font-medium mb-1.5 text-text-secondary`,children:e(`plugins.noMarketplaces`)}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noMarketplacesHint`)})]}),h&&m.length===0&&q&&(0,T.jsx)(`div`,{className:`flex flex-col items-center justify-center py-20`,children:(0,T.jsx)(ne,{size:`small`,text:e(`plugins.browsingMarketplace`)})}),g&&m.length===0&&q&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20`,children:[(0,T.jsx)(c,{size:40,className:`text-text-tertiary opacity-40 mb-4`}),(0,T.jsx)(`div`,{className:`text-[14px] text-text-secondary font-medium mb-3`,children:e(`plugins.error`)}),(0,T.jsx)(`button`,{onClick:()=>q&&x(q),className:`px-4 py-2 rounded-lg text-[13px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors`,children:e(`plugins.retry`)})]}),q&&m.length===0&&!h&&!g&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-text-tertiary`,children:[(0,T.jsx)(d,{size:48,className:`mb-4 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[15px] font-medium mb-1.5 text-text-secondary`,children:e(`plugins.noAvailablePlugins`)}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noAvailablePluginsHint`)})]}),m.length>0&&Q.length===0&&!h&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-text-tertiary`,children:[(0,T.jsx)(l,{size:36,className:`mb-3 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noSearchResults`)})]}),Q.length>0&&(0,T.jsxs)(`div`,{className:`space-y-3`,children:[Be.map(t=>{let n=`${t.name}@${t.marketplace}`;return(0,T.jsx)(se,{plugin:t,isInstalled:t.installed,isOperating:p.has(n),isExpanded:De===n,onInstall:e=>Me(t,e),onExpand:()=>ke(n),t:e},n)}),(0,T.jsx)(ae,{visible:Be.length,total:Q.length,onLoadMore:He,scrollRoot:R,t:e})]})]}),M===`marketplaces`&&(0,T.jsxs)(`div`,{className:`space-y-3`,children:[!B&&(0,T.jsxs)(`button`,{onClick:()=>V(!0),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium text-text-primary border border-border-muted hover:bg-bg-tertiary hover:border-text-primary/30 transition-colors`,children:[(0,T.jsx)(u,{size:12}),e(`plugins.addMarketplace`)]}),B&&(0,T.jsxs)(`div`,{className:`bg-bg-secondary rounded-xl border border-border-muted p-4 space-y-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,T.jsx)(`span`,{className:`text-[13px] font-medium`,children:e(`plugins.addMarketplace`)}),(0,T.jsx)(`button`,{onClick:()=>{V(!1),W(null)},className:`w-6 h-6 flex items-center justify-center rounded-full hover:bg-bg-tertiary transition-colors text-text-secondary`,children:(0,T.jsx)(f,{size:12})})]}),(0,T.jsx)(`input`,{type:`text`,value:H,onChange:e=>be(e.target.value),placeholder:e(`plugins.sourcePlaceholder`),className:`w-full bg-bg-primary text-text-primary text-[13px] border border-border-muted rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary`}),(0,T.jsx)(`input`,{type:`text`,value:U,onChange:e=>xe(e.target.value),placeholder:e(`plugins.namePlaceholder`),className:`w-full bg-bg-primary text-text-primary text-[13px] border border-border-muted rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary`}),we&&(0,T.jsx)(`div`,{className:`text-accent-red text-[12px]`,children:we}),(0,T.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,T.jsx)(`button`,{onClick:()=>{V(!1),W(null)},className:`px-3 py-1.5 rounded-lg text-[12px] text-text-secondary hover:bg-bg-tertiary transition-colors`,children:e(`plugins.cancel`)}),(0,T.jsxs)(`button`,{onClick:Ne,disabled:!H.trim()||Se,className:`px-3 py-1.5 rounded-lg text-[12px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1.5`,children:[Se&&(0,T.jsx)(o,{size:12,className:`animate-spin`}),e(`plugins.add`)]})]})]}),a&&n.length===0&&(0,T.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,T.jsx)(o,{size:18,className:`animate-spin text-text-tertiary`})}),!a&&n.length===0&&!B&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-text-tertiary`,children:[(0,T.jsx)(y,{size:48,className:`mb-4 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[15px] font-medium mb-1.5 text-text-secondary`,children:e(`plugins.noMarketplaces`)}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noMarketplacesHint`)})]}),n.length>0&&(0,T.jsx)(`div`,{className:`bg-bg-secondary rounded-xl border border-border-muted overflow-hidden`,children:n.map((t,n)=>(0,T.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 ${n>0?`border-t border-border-muted`:``}`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,T.jsx)(y,{size:14,className:`text-text-tertiary shrink-0`}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`div`,{className:`text-[13px] font-medium truncate`,children:t.name}),t.type&&(0,T.jsx)(`div`,{className:`text-[11px] text-text-tertiary`,children:t.type})]})]}),(0,T.jsx)(`div`,{className:`flex items-center gap-2 shrink-0`,children:Ee===t.name?(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`button`,{onClick:()=>Pe(t.name),className:`px-2.5 py-1 rounded-md text-[11px] font-medium text-white bg-accent-red hover:bg-accent-red/90 transition-colors`,children:e(`plugins.removeMarketplace`)}),(0,T.jsx)(`button`,{onClick:()=>K(null),className:`px-2.5 py-1 rounded-md text-[11px] text-text-secondary hover:bg-bg-tertiary transition-colors`,children:e(`plugins.cancel`)})]}):(0,T.jsx)(`button`,{onClick:()=>K(t.name),className:`w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-accent-red hover:bg-accent-red/10 transition-colors`,title:e(`plugins.removeMarketplace`),children:(0,T.jsx)(re,{size:13})})})]},t.name))})]})]})}),_e&&(0,T.jsxs)(`button`,{type:`button`,onClick:Ue,className:`absolute bottom-5 right-5 z-10 flex items-center gap-1.5 rounded-full border border-border-muted bg-bg-secondary/95 px-3 py-2 text-[12px] font-medium text-text-primary shadow-sm backdrop-blur-sm transition-colors hover:bg-bg-tertiary`,"aria-label":e(`plugins.backToTop`),children:[(0,T.jsx)(te,{size:14}),e(`plugins.backToTop`)]})]})]})}function ae({visible:e,total:t,onLoadMore:n,scrollRoot:r,t:i}){let a=(0,b.useRef)(null),s=e<t;return(0,b.useEffect)(()=>{let e=a.current;if(!e||!s)return;let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&n()},{root:r,rootMargin:`120px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[s,n,r,e,t]),t===0?null:(0,T.jsxs)(`div`,{ref:a,className:`flex flex-col items-center justify-center gap-1.5 pt-2 pb-1`,children:[(0,T.jsx)(`span`,{className:`text-[12px] text-text-tertiary`,children:i(`plugins.infiniteRange`).replace(`{visible}`,String(e)).replace(`{total}`,String(t))}),s?(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[11px] text-text-tertiary`,children:[(0,T.jsx)(o,{size:12,className:`animate-spin`}),i(`plugins.infiniteLoading`)]}):(0,T.jsx)(`span`,{className:`text-[11px] text-text-tertiary`,children:i(`plugins.infiniteEnd`)})]})}function oe({plugin:e,isEnabled:t,isOperating:n,isExpanded:r,confirmUninstall:i,onToggle:a,onUninstall:c,onConfirmUninstall:ee,onCancelUninstall:te,onExpand:l,t:u}){return(0,T.jsxs)(`div`,{className:`group rounded-xl border transition-all ${t?`bg-bg-secondary border-border-muted`:`bg-bg-secondary border-border-muted hover:border-border-muted`}`,children:[(0,T.jsxs)(`div`,{className:`flex items-start gap-4 px-5 py-4 cursor-pointer`,onClick:l,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 w-9 h-9 rounded-lg flex items-center justify-center mt-0.5 ${t?`bg-text-primary/8`:`bg-bg-tertiary`}`,children:(0,T.jsx)(d,{size:18,className:t?`text-text-primary`:`text-text-tertiary`})}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,T.jsx)(`span`,{className:`text-[14px] font-semibold text-text-primary truncate`,children:e.name}),e.version&&(0,T.jsxs)(`span`,{className:`text-[11px] text-text-tertiary shrink-0 font-mono`,children:[`v`,e.version]}),(0,T.jsx)(`span`,{className:`text-[10px] px-1.5 py-px rounded font-medium shrink-0 ${t?`bg-accent-green/15 text-accent-green`:`bg-bg-tertiary text-text-tertiary`}`,children:u(t?`plugins.enabled`:`plugins.disabled`)})]}),e.description&&(0,T.jsx)(`div`,{className:`text-[12px] text-text-secondary leading-relaxed mb-1.5 ${r?``:`line-clamp-2`}`,children:e.description}),(0,T.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-text-tertiary`,children:[(0,T.jsx)(y,{size:10,className:`shrink-0`}),(0,T.jsx)(`span`,{children:e.marketplace}),e.installScope&&(0,T.jsx)(`span`,{className:`px-1.5 py-px rounded bg-bg-tertiary text-[10px] font-medium`,children:u(`plugins.scope.${e.installScope}`)})]})]}),(0,T.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 pt-0.5`,onClick:e=>e.stopPropagation(),children:n?(0,T.jsx)(`div`,{className:`w-[72px] flex justify-center`,children:(0,T.jsx)(o,{size:16,className:`animate-spin text-text-tertiary`})}):i?(0,T.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,T.jsx)(`button`,{onClick:c,className:`px-2.5 py-1 rounded-md text-[11px] font-medium text-white bg-accent-red hover:bg-accent-red/90 transition-colors`,children:u(`plugins.uninstall`)}),(0,T.jsx)(`button`,{onClick:te,className:`px-2.5 py-1 rounded-md text-[11px] text-text-secondary hover:bg-bg-tertiary transition-colors`,children:u(`plugins.cancel`)})]}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`button`,{onClick:e.canSwitchoff===!1?void 0:a,disabled:e.canSwitchoff===!1,className:`px-2.5 py-1.5 rounded-md text-[11px] font-medium transition-colors flex items-center gap-1 ${e.canSwitchoff===!1?`text-text-tertiary border border-border-muted cursor-not-allowed opacity-50`:t?`text-text-secondary border border-border-muted hover:bg-bg-tertiary`:`text-text-primary border border-border-muted hover:bg-bg-tertiary`}`,title:e.canSwitchoff===!1?u(`plugins.policyCannotSwitchoff`):u(t?`plugins.disable`:`plugins.enable`),children:[t?(0,T.jsx)(v,{size:11}):(0,T.jsx)(s,{size:11}),u(t?`plugins.disable`:`plugins.enable`)]}),(0,T.jsx)(`button`,{onClick:e.canRemove===!1?void 0:ee,disabled:e.canRemove===!1,className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors ${e.canRemove===!1?`text-text-tertiary cursor-not-allowed opacity-30`:`text-text-tertiary hover:text-accent-red hover:bg-accent-red/10 opacity-0 group-hover:opacity-100 touch-actions-visible`}`,title:e.canRemove===!1?u(`plugins.policyCannotRemove`):u(`plugins.uninstall`),children:(0,T.jsx)(re,{size:13})})]})})]}),r&&(0,T.jsx)(k,{plugin:e,t:u})]})}function se({plugin:e,isInstalled:t,isOperating:n,isExpanded:r,onInstall:i,onExpand:a,t:s}){return(0,T.jsxs)(`div`,{className:`group rounded-xl border transition-all ${t?`bg-bg-secondary border-border-muted`:`bg-bg-secondary border-border-muted hover:border-border-muted`}`,children:[(0,T.jsxs)(`div`,{className:`flex items-start gap-4 px-5 py-4 cursor-pointer`,onClick:a,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 w-9 h-9 rounded-lg flex items-center justify-center mt-0.5 ${t?`bg-text-primary/8`:`bg-bg-tertiary`}`,children:(0,T.jsx)(d,{size:18,className:t?`text-text-primary`:`text-text-tertiary`})}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,T.jsx)(`span`,{className:`text-[14px] font-semibold text-text-primary truncate`,children:e.name}),e.version&&(0,T.jsxs)(`span`,{className:`text-[11px] text-text-tertiary shrink-0 font-mono`,children:[`v`,e.version]}),t&&(0,T.jsx)(`span`,{className:`text-[10px] px-1.5 py-px rounded font-medium shrink-0 bg-accent-green/15 text-accent-green`,children:s(`plugins.installedLabel`)})]}),e.description&&(0,T.jsx)(`div`,{className:`text-[12px] text-text-secondary leading-relaxed mb-1.5 ${r?``:`line-clamp-2`}`,children:e.description}),(0,T.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px] text-text-tertiary`,children:[(0,T.jsx)(y,{size:10,className:`shrink-0`}),(0,T.jsx)(`span`,{children:e.marketplace})]})]}),(0,T.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 pt-0.5`,onClick:e=>e.stopPropagation(),children:t?(0,T.jsx)(`div`,{className:`px-2.5 py-1.5 rounded-md text-[11px] font-medium text-text-tertiary bg-bg-tertiary`,children:s(`plugins.installed`)}):n?(0,T.jsx)(`div`,{className:`w-[72px] flex justify-center`,children:(0,T.jsx)(o,{size:16,className:`animate-spin text-text-tertiary`})}):(0,T.jsx)(j,{onInstall:i,t:s})})]}),r&&(0,T.jsx)(k,{plugin:e,t:s})]})}function k({plugin:e,t}){let n=e.source,r=typeof n==`object`&&n?n.url:void 0,i=typeof n==`object`&&n?n.source:typeof n==`string`?n:void 0,a=`installScope`in e?e.installScope:void 0;return(0,T.jsxs)(`div`,{className:`border-t border-border-muted mx-5 px-0 py-3.5 space-y-2.5`,children:[a&&(0,T.jsx)(A,{label:t(`plugins.scope`),children:(0,T.jsx)(`span`,{className:`text-[12px] text-text-secondary`,children:t(`plugins.scope.${a}`)})}),e.category&&(0,T.jsx)(A,{label:t(`plugins.category`),children:(0,T.jsx)(`span`,{className:`text-[11px] px-2 py-0.5 rounded bg-[#f5a623]/8 text-[#b8860b] font-medium`,children:e.category})}),e.author&&(0,T.jsxs)(A,{label:t(`plugins.author`),children:[(0,T.jsx)(`span`,{className:`text-[12px] text-text-primary font-medium`,children:e.author.name}),e.author.email&&(0,T.jsx)(`a`,{href:`mailto:${e.author.email}`,className:`text-[11px] text-text-tertiary hover:text-text-primary hover:underline ml-1`,onClick:e=>e.stopPropagation(),children:e.author.email}),e.author.url&&(0,T.jsxs)(`a`,{href:e.author.url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-[11px] text-text-tertiary hover:text-text-primary hover:underline ml-1`,onClick:e=>e.stopPropagation(),children:[e.author.url,(0,T.jsx)(_,{size:9})]})]}),e.license&&(0,T.jsx)(A,{label:t(`plugins.license`),children:(0,T.jsx)(`span`,{className:`text-[12px] text-text-secondary`,children:e.license})}),e.homepage&&(0,T.jsx)(A,{label:t(`plugins.homepage`),children:(0,T.jsxs)(`a`,{href:e.homepage,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all`,onClick:e=>e.stopPropagation(),children:[e.homepage,(0,T.jsx)(_,{size:10,className:`shrink-0 text-text-tertiary`})]})}),e.repository&&(0,T.jsx)(A,{label:t(`plugins.repository`),children:(0,T.jsxs)(`a`,{href:e.repository,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all`,onClick:e=>e.stopPropagation(),children:[e.repository,(0,T.jsx)(_,{size:10,className:`shrink-0 text-text-tertiary`})]})}),i&&(0,T.jsx)(A,{label:t(`plugins.source`),children:r?(0,T.jsxs)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all`,onClick:e=>e.stopPropagation(),children:[i,(0,T.jsx)(_,{size:10,className:`shrink-0 text-text-tertiary`})]}):(0,T.jsx)(`span`,{className:`text-[12px] text-text-secondary font-mono`,children:i})}),e.keywords&&e.keywords.length>0&&(0,T.jsx)(A,{label:t(`plugins.keywords`),children:(0,T.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.keywords.map(e=>(0,T.jsx)(`span`,{className:`text-[10px] px-1.5 py-px rounded bg-bg-tertiary text-text-tertiary`,children:e},e))})}),e.features&&e.features.length>0&&(0,T.jsx)(A,{label:t(`plugins.features`),children:(0,T.jsx)(`ul`,{className:`space-y-0.5`,children:e.features.map((e,t)=>(0,T.jsxs)(`li`,{className:`text-[12px] text-text-secondary flex items-start gap-1.5`,children:[(0,T.jsx)(`span`,{className:`text-text-tertiary shrink-0`,children:`·`}),e]},t))})})]})}function A({label:e,children:t}){return(0,T.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,T.jsx)(`span`,{className:`text-[11px] text-text-tertiary w-12 shrink-0 text-right`,children:e}),(0,T.jsx)(`div`,{className:`flex-1 min-w-0 flex items-baseline flex-wrap gap-1`,children:t})]})}function j({onInstall:e,t}){let[n,r]=(0,b.useState)(!1);return(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsxs)(`button`,{onClick:()=>r(!n),className:`px-2.5 py-1.5 rounded-md text-[11px] font-medium text-text-primary border border-border-muted hover:bg-bg-tertiary transition-colors flex items-center gap-1`,title:t(`plugins.install`),children:[(0,T.jsx)(h,{size:11}),t(`plugins.install`)]}),n&&(0,T.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-50 bg-bg-primary border border-border-muted rounded-lg shadow-lg py-1 min-w-[220px]`,children:[(0,T.jsx)(`button`,{onClick:()=>{e(`user`),r(!1)},className:`w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors`,children:t(`plugins.installScope.user`)}),(0,T.jsx)(`button`,{onClick:()=>{e(`project`),r(!1)},className:`w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors`,children:t(`plugins.installScope.project`)}),(0,T.jsx)(`button`,{onClick:()=>{e(`project-local`),r(!1)},className:`w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors`,children:t(`plugins.installScope.local`)})]})]})}export{O as PluginsView};
1
+ import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{i as t,st as n,t as r}from"./use-i18n-pIrmaYmw.js";import{l as i,u as a}from"./markdown-DCKhnxE9.js";import{t as o}from"./loader-circle-CbX-mRDA.js";import{t as s}from"./power-GWOABL7s.js";import{t as c}from"./triangle-alert-CGAm2zgw.js";import{At as ee,Cn as te,Dt as l,Mt as u,O as ne,Sn as d,_t as f,ct as p,dt as m,in as h,lt as g,rn as _,yt as re}from"./index-CcT-vg3O.js";var v=t(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),y=t(`store`,[[`path`,{d:`M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5`,key:`slp6dd`}],[`path`,{d:`M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244`,key:`o0xfot`}],[`path`,{d:`M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05`,key:`wn3emo`}]]),b=e(a(),1);function x(e,t){return`${e}@${t}`}var S=m,C=p,w=g,ie=n((e,t)=>({plugins:[],loading:!1,error:null,marketplaces:[],marketplaceLoading:!1,availablePlugins:[],browsingMarketplace:null,browsingLoading:!1,browsingError:null,operatingPlugins:new Set,fetchPlugins:async()=>{e({loading:!0,error:null});try{let t=await w(`/api/v1/plugins`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=(await t.json()).data;e({plugins:Array.isArray(n)?n.map(e=>({...e,canRemove:e.canRemove,canSwitchoff:e.canSwitchoff,canEdit:e.canEdit})):[],loading:!1})}catch(t){console.warn(`[plugin-store] fetchPlugins failed:`,t),e({error:t.message,loading:!1})}},fetchMarketplaces:async()=>{e({marketplaceLoading:!0});try{let t=await w(`/api/v1/plugins/marketplaces`);if(!t.ok)throw Error(`HTTP ${t.status}`);let n=(await t.json()).data;e({marketplaces:Array.isArray(n)?n:[],marketplaceLoading:!1})}catch(t){console.warn(`[plugin-store] fetchMarketplaces failed:`,t),e({marketplaceLoading:!1})}},browseMarketplace:async t=>{e({browsingMarketplace:t,browsingLoading:!0,browsingError:null});try{let n=await S(`/api/v1/plugins/marketplaces/browse`,{marketplace:t});if(!n.ok){let e=await n.json().catch(()=>null);throw Error(e?.error?.message||`HTTP ${n.status}`)}let r=await n.json();e({availablePlugins:(Array.isArray(r.data)?r.data:[]).map(e=>({name:e.name,version:e.version,description:e.description,marketplace:e.marketplaceName||t,installed:!!e.status,author:e.author,license:e.license,homepage:e.homepage,repository:e.repository,keywords:e.keywords,category:e.category,features:e.features,source:e.source,dependencies:e.dependencies})),browsingLoading:!1})}catch(t){console.warn(`[plugin-store] browseMarketplace failed:`,t),e({browsingError:t.message,browsingLoading:!1})}},browseAllMarketplaces:async()=>{let{marketplaces:n}=t();if(n.length!==0){e({browsingMarketplace:`__all__`,browsingLoading:!0,browsingError:null});try{let t=await Promise.allSettled(n.map(async e=>{let t=await S(`/api/v1/plugins/marketplaces/browse`,{marketplace:e.name});if(!t.ok){let e=await t.json().catch(()=>null);throw Error(e?.error?.message||`HTTP ${t.status}`)}let n=await t.json();return(Array.isArray(n.data)?n.data:[]).map(t=>({name:t.name,version:t.version,description:t.description,marketplace:t.marketplaceName||e.name,installed:!!t.status,author:t.author,license:t.license,homepage:t.homepage,repository:t.repository,keywords:t.keywords,category:t.category,features:t.features,source:t.source,dependencies:t.dependencies}))})),r=[],i=!1;for(let e of t)e.status===`fulfilled`?r.push(...e.value):i=!0;let a=new Set,o=r.filter(e=>{let t=`${e.name}@${e.marketplace}`;return!a.has(t)&&(a.add(t),!0)});e({availablePlugins:o,browsingLoading:!1,browsingError:i&&o.length===0?`Some marketplaces failed to load`:null})}catch(t){console.warn(`[plugin-store] browseAllMarketplaces failed:`,t),e({browsingError:t.message,browsingLoading:!1})}}},enablePlugin:async(n,r)=>{let i=x(n,r);e(e=>({operatingPlugins:new Set(e.operatingPlugins).add(i)}));try{let e=await S(`/api/v1/plugins/enable`,{plugin:i});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message||`HTTP ${e.status}`)}await t().fetchPlugins()}finally{e(e=>{let t=new Set(e.operatingPlugins);return t.delete(i),{operatingPlugins:t}})}},disablePlugin:async(n,r)=>{let i=x(n,r);e(e=>({operatingPlugins:new Set(e.operatingPlugins).add(i)}));try{let e=await S(`/api/v1/plugins/disable`,{plugin:i});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message||`HTTP ${e.status}`)}await t().fetchPlugins()}finally{e(e=>{let t=new Set(e.operatingPlugins);return t.delete(i),{operatingPlugins:t}})}},uninstallPlugin:async(n,r)=>{let i=x(n,r);e(e=>({operatingPlugins:new Set(e.operatingPlugins).add(i)}));try{let e=await S(`/api/v1/plugins/uninstall`,{plugin:i});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message||`HTTP ${e.status}`)}await t().fetchPlugins()}finally{e(e=>{let t=new Set(e.operatingPlugins);return t.delete(i),{operatingPlugins:t}})}},installPlugin:async(n,r,i)=>{let a=x(n,r);e(e=>({operatingPlugins:new Set(e.operatingPlugins).add(a)}));try{let e=await S(`/api/v1/plugins`,{plugin:a,options:i?{scope:i}:void 0});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message||`HTTP ${e.status}`)}await t().fetchPlugins();let n=t();n.browsingMarketplace&&(n.browsingMarketplace===`__all__`?await t().browseAllMarketplaces():await t().browseMarketplace(n.browsingMarketplace))}finally{e(e=>{let t=new Set(e.operatingPlugins);return t.delete(a),{operatingPlugins:t}})}},addMarketplace:async(e,n)=>{let r=await S(`/api/v1/plugins/marketplaces`,{source:e,name:n});if(!r.ok){let e=await r.json().catch(()=>null);throw Error(e?.error?.message||`HTTP ${r.status}`)}await t().fetchMarketplaces()},removeMarketplace:async e=>{let n=await C(`/api/v1/plugins/marketplaces/${encodeURIComponent(e)}`);if(!n.ok){let e=await n.json().catch(()=>null);throw Error(e?.error?.message||`HTTP ${n.status}`)}await t().fetchMarketplaces()}})),T=i(),E=12;function D(e){let t=[e.category,...e.features||[],...e.keywords||[],e.name,e.description||``].join(` `).toLowerCase();return/\b(skill|skills)\b/.test(t)?`skills`:/\b(mcp|model[- ]?context)\b/.test(t)?`mcp`:/\b(hook|hooks)\b/.test(t)?`hooks`:/\b(tool|tools)\b/.test(t)?`tools`:`unknown`}function O(){let{t:e}=r(),{plugins:t,marketplaces:n,loading:i,marketplaceLoading:a,error:s,operatingPlugins:p,availablePlugins:m,browsingLoading:h,browsingError:g,fetchPlugins:_,fetchMarketplaces:v,browseMarketplace:x,browseAllMarketplaces:S,enablePlugin:C,disablePlugin:w,uninstallPlugin:O,installPlugin:k,addMarketplace:A,removeMarketplace:j}=ie(),[M,N]=(0,b.useState)(`installed`),[P,ce]=(0,b.useState)(``),[F,le]=(0,b.useState)(`all`),[I,ue]=(0,b.useState)(`all`),[L,de]=(0,b.useState)(`all`),[fe,pe]=(0,b.useState)(E),[me,he]=(0,b.useState)(E),[R,ge]=(0,b.useState)(null),[_e,ve]=(0,b.useState)(!1),[ye,z]=(0,b.useState)(null),[B,V]=(0,b.useState)(!1),[H,be]=(0,b.useState)(``),[U,xe]=(0,b.useState)(``),[Se,Ce]=(0,b.useState)(!1),[we,W]=(0,b.useState)(null),[Te,G]=(0,b.useState)(null),[Ee,K]=(0,b.useState)(null),[q,J]=(0,b.useState)(``),[Y,X]=(0,b.useState)(``),[De,Oe]=(0,b.useState)(null),ke=(0,b.useCallback)(e=>{Oe(t=>t===e?null:e)},[]);(0,b.useEffect)(()=>{_(),v()},[_,v]),(0,b.useEffect)(()=>{M===`browse`&&!q&&n.length>0&&(J(`__all__`),S())},[M,n,q,S]);let Ae=(0,b.useCallback)(async e=>{z(null);try{e.status===`enabled`?await w(e.name,e.marketplace):await C(e.name,e.marketplace)}catch(e){z(e.message)}},[C,w]),je=(0,b.useCallback)(async e=>{z(null),G(null);try{await O(e.name,e.marketplace)}catch(e){z(e.message)}},[O]),Me=(0,b.useCallback)(async(e,t)=>{z(null);try{await k(e.name,e.marketplace,t)}catch(e){z(e.message)}},[k]),Ne=(0,b.useCallback)(async()=>{let e=H.trim();if(e){Ce(!0),W(null);try{await A(e,U.trim()||void 0),be(``),xe(``),V(!1)}catch(e){W(e.message)}finally{Ce(!1)}}},[H,U,A]),Pe=(0,b.useCallback)(async e=>{z(null),K(null);try{if(await j(e),q===e&&n.length>1){let t=n.find(t=>t.name!==e);t&&(J(t.name),x(t.name))}}catch(e){z(e.message)}},[j,q,n,x]),Fe=(0,b.useCallback)(()=>{_(),v(),M===`browse`&&q&&(q===`__all__`?S():x(q))},[_,v,M,q,x,S]),Ie=(0,b.useCallback)(e=>{J(e),X(``),e===`__all__`?S():x(e)},[x,S]),Le=e=>`${e.name}@${e.marketplace}`,Re=(0,b.useMemo)(()=>{let e=new Set(t.map(e=>e.marketplace));return Array.from(e).sort()},[t]),Z=(0,b.useMemo)(()=>{let e=t;F!==`all`&&(e=e.filter(e=>e.marketplace===F)),L!==`all`&&(e=e.filter(e=>L===`enabled`?e.status===`enabled`:e.status!==`enabled`)),I!==`all`&&(e=e.filter(e=>D(e)===I));let n=P.trim().toLowerCase();return n&&(e=e.filter(e=>e.name.toLowerCase().includes(n)||e.description&&e.description.toLowerCase().includes(n)||e.marketplace.toLowerCase().includes(n)||D(e).includes(n))),e},[t,F,I,L,P]),Q=(0,b.useMemo)(()=>{let e=m;I!==`all`&&(e=e.filter(e=>D(e)===I));let t=Y.trim().toLowerCase();return t&&(e=e.filter(e=>e.name.toLowerCase().includes(t)||e.description&&e.description.toLowerCase().includes(t)||D(e).includes(t))),e},[m,Y,I]);(0,b.useEffect)(()=>{pe(E)},[P,F,I,L,t.length]),(0,b.useEffect)(()=>{he(E)},[Y,I,m.length,q]);let ze=(0,b.useMemo)(()=>Z.slice(0,fe),[Z,fe]),Be=(0,b.useMemo)(()=>Q.slice(0,me),[Q,me]),Ve=(0,b.useCallback)(()=>{pe(e=>Math.min(e+E,Z.length))},[Z.length]),He=(0,b.useCallback)(()=>{he(e=>Math.min(e+E,Q.length))},[Q.length]);(0,b.useEffect)(()=>{if(!R){ve(!1);return}let e=()=>{ve(R.scrollTop>480)};return e(),R.addEventListener(`scroll`,e,{passive:!0}),()=>R.removeEventListener(`scroll`,e)},[R,M]);let Ue=(0,b.useCallback)(()=>{R?.scrollTo({top:0,behavior:`smooth`})},[R]),$=(0,b.useMemo)(()=>{let e={skills:0,mcp:0,hooks:0,tools:0,unknown:0},n=M===`browse`?m:t;for(let t of n)e[D(t)]+=1;return e},[t,m,M]),We=t.filter(e=>e.status===`enabled`).length;return(0,T.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden bg-bg-primary`,children:[(0,T.jsx)(`div`,{className:`flex-none border-b border-border-muted px-6 py-4`,children:(0,T.jsxs)(`div`,{className:`max-w-3xl mx-auto`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:e(`plugins.title`)}),M===`installed`&&t.length>0&&(0,T.jsxs)(`p`,{className:`text-sm text-text-tertiary mt-0.5`,children:[t.length,` `,e(`plugins.totalCount`),` · `,We,` `,e(`plugins.enabled`)]}),M===`browse`&&q&&!h&&m.length>0&&(0,T.jsxs)(`p`,{className:`text-sm text-text-tertiary mt-0.5`,children:[m.length,` `,e(`plugins.totalCount`)]}),M===`marketplaces`&&n.length>0&&(0,T.jsxs)(`p`,{className:`text-sm text-text-tertiary mt-0.5`,children:[n.length,` `,e(`plugins.totalCount`)]})]}),(0,T.jsx)(`button`,{onClick:Fe,disabled:i||h,className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-all ${i||h?`opacity-50 cursor-not-allowed border-border-muted text-text-secondary`:`border-border-muted text-text-secondary hover:text-text-primary hover:border-text-primary/20 hover:bg-bg-secondary`}`,title:e(`plugins.refresh`),children:(0,T.jsx)(ee,{size:14,className:i||h?`animate-spin`:``})})]}),(0,T.jsxs)(`div`,{className:`flex gap-1 border-b border-border-muted`,children:[(0,T.jsx)(`button`,{onClick:()=>{N(`installed`),z(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${M===`installed`?`text-text-primary border-text-primary`:`text-text-secondary border-transparent hover:text-text-primary`}`,children:e(`plugins.installedPlugins`)}),(0,T.jsx)(`button`,{onClick:()=>{N(`browse`),z(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${M===`browse`?`text-text-primary border-text-primary`:`text-text-secondary border-transparent hover:text-text-primary`}`,children:e(`plugins.browseMarketplace`)}),(0,T.jsx)(`button`,{onClick:()=>{N(`marketplaces`),z(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${M===`marketplaces`?`text-text-primary border-text-primary`:`text-text-secondary border-transparent hover:text-text-primary`}`,children:e(`plugins.marketplaces`)})]}),M===`installed`&&t.length>0&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2 mt-4`,children:[(0,T.jsxs)(`div`,{className:`flex-1 relative`,children:[(0,T.jsx)(l,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary pointer-events-none`}),(0,T.jsx)(`input`,{type:`text`,value:P,onChange:e=>ce(e.target.value),placeholder:e(`plugins.searchPlaceholder`),className:`w-full bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg pl-9 pr-8 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary`}),P&&(0,T.jsx)(`button`,{onClick:()=>ce(``),className:`absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center rounded-full text-text-tertiary hover:text-text-secondary transition-colors`,children:(0,T.jsx)(f,{size:12})})]}),Re.length>1&&(0,T.jsxs)(`select`,{value:F,onChange:e=>le(e.target.value),className:`bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0 max-w-[120px] sm:max-w-[160px]`,children:[(0,T.jsx)(`option`,{value:`all`,children:e(`plugins.allMarketplaces`)}),Re.map(e=>(0,T.jsx)(`option`,{value:e,children:e},e))]}),(0,T.jsxs)(`select`,{value:L,onChange:e=>de(e.target.value),className:`bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0`,children:[(0,T.jsx)(`option`,{value:`all`,children:e(`plugins.filterStatusAll`)}),(0,T.jsx)(`option`,{value:`enabled`,children:e(`plugins.filterStatusEnabled`)}),(0,T.jsx)(`option`,{value:`disabled`,children:e(`plugins.filterStatusDisabled`)})]})]}),(M===`installed`||M===`browse`)&&(0,T.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-3`,children:[[`all`,e(`plugins.kindAll`),M===`installed`?t.length:m.length],[`skills`,e(`plugins.kindSkills`),$.skills],[`mcp`,e(`plugins.kindMcp`),$.mcp],[`hooks`,e(`plugins.kindHooks`),$.hooks],[`tools`,e(`plugins.kindTools`),$.tools],[`unknown`,e(`plugins.kindUnknown`),$.unknown]].map(([e,t,n])=>(0,T.jsxs)(`button`,{type:`button`,onClick:()=>ue(e),className:`px-2.5 py-1 rounded-full text-[12px] border transition-colors ${I===e?`bg-bg-secondary text-text-primary border-text-primary/30 font-medium`:`bg-transparent text-text-tertiary border-border-muted hover:text-text-secondary`}`,children:[t,(0,T.jsx)(`span`,{className:`ml-1 opacity-70`,children:n})]},e))}),M===`browse`&&n.length>0&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2 mt-4`,children:[(0,T.jsxs)(`div`,{className:`flex-1 relative`,children:[(0,T.jsx)(l,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary pointer-events-none`}),(0,T.jsx)(`input`,{type:`text`,value:Y,onChange:e=>X(e.target.value),placeholder:e(`plugins.searchPlaceholder`),className:`w-full bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg pl-9 pr-8 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary`}),Y&&(0,T.jsx)(`button`,{onClick:()=>X(``),className:`absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center rounded-full text-text-tertiary hover:text-text-secondary transition-colors`,children:(0,T.jsx)(f,{size:12})})]}),(0,T.jsxs)(`select`,{value:q,onChange:e=>Ie(e.target.value),className:`bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0 max-w-[120px] sm:max-w-[160px]`,children:[(0,T.jsx)(`option`,{value:`__all__`,children:e(`plugins.allMarketplaces`)}),n.map(e=>(0,T.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]})]})}),(0,T.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,T.jsx)(`div`,{ref:ge,className:`h-full overflow-y-auto px-6 py-6`,children:(0,T.jsxs)(`div`,{className:`max-w-3xl mx-auto space-y-6`,children:[ye&&(0,T.jsxs)(`div`,{className:`bg-accent-red/10 border border-accent-red/30 rounded-xl p-3.5 text-accent-red text-[13px] flex items-center justify-between`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,T.jsx)(c,{size:14,className:`shrink-0`}),(0,T.jsxs)(`span`,{className:`truncate`,children:[e(`plugins.operationFailed`),`: `,ye]})]}),(0,T.jsx)(`button`,{onClick:()=>z(null),className:`w-5 h-5 flex items-center justify-center rounded-full hover:bg-accent-red/20 transition-colors shrink-0 ml-3`,children:(0,T.jsx)(f,{size:12})})]}),M===`installed`&&(0,T.jsxs)(T.Fragment,{children:[i&&t.length===0&&(0,T.jsx)(`div`,{className:`flex flex-col items-center justify-center py-20`,children:(0,T.jsx)(ne,{size:`small`,text:e(`plugins.loading`)})}),s&&!i&&t.length===0&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20`,children:[(0,T.jsx)(c,{size:40,className:`text-text-tertiary opacity-40 mb-4`}),(0,T.jsx)(`div`,{className:`text-[14px] text-text-secondary font-medium mb-3`,children:e(`plugins.error`)}),(0,T.jsx)(`button`,{onClick:_,className:`px-4 py-2 rounded-lg text-[13px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors`,children:e(`plugins.retry`)})]}),!i&&!s&&t.length===0&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-text-tertiary`,children:[(0,T.jsx)(d,{size:48,className:`mb-4 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[15px] font-medium mb-1.5 text-text-secondary`,children:e(`plugins.noPlugins`)}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noPluginsHint`)})]}),t.length>0&&Z.length===0&&!i&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-text-tertiary`,children:[(0,T.jsx)(l,{size:36,className:`mb-3 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noSearchResults`)})]}),Z.length>0&&(0,T.jsxs)(`div`,{className:`space-y-3`,children:[ze.map(t=>{let n=Le(t);return(0,T.jsx)(oe,{plugin:t,isEnabled:t.status===`enabled`,isOperating:p.has(n),isExpanded:De===n,confirmUninstall:Te===n,onToggle:()=>Ae(t),onUninstall:()=>je(t),onConfirmUninstall:()=>G(n),onCancelUninstall:()=>G(null),onExpand:()=>ke(n),t:e},n)}),(0,T.jsx)(ae,{visible:ze.length,total:Z.length,onLoadMore:Ve,scrollRoot:R,t:e})]})]}),M===`browse`&&(0,T.jsxs)(T.Fragment,{children:[!a&&n.length===0&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-text-tertiary`,children:[(0,T.jsx)(y,{size:48,className:`mb-4 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[15px] font-medium mb-1.5 text-text-secondary`,children:e(`plugins.noMarketplaces`)}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noMarketplacesHint`)})]}),h&&m.length===0&&q&&(0,T.jsx)(`div`,{className:`flex flex-col items-center justify-center py-20`,children:(0,T.jsx)(ne,{size:`small`,text:e(`plugins.browsingMarketplace`)})}),g&&m.length===0&&q&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20`,children:[(0,T.jsx)(c,{size:40,className:`text-text-tertiary opacity-40 mb-4`}),(0,T.jsx)(`div`,{className:`text-[14px] text-text-secondary font-medium mb-3`,children:e(`plugins.error`)}),(0,T.jsx)(`button`,{onClick:()=>q&&x(q),className:`px-4 py-2 rounded-lg text-[13px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors`,children:e(`plugins.retry`)})]}),q&&m.length===0&&!h&&!g&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-text-tertiary`,children:[(0,T.jsx)(d,{size:48,className:`mb-4 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[15px] font-medium mb-1.5 text-text-secondary`,children:e(`plugins.noAvailablePlugins`)}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noAvailablePluginsHint`)})]}),m.length>0&&Q.length===0&&!h&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-text-tertiary`,children:[(0,T.jsx)(l,{size:36,className:`mb-3 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noSearchResults`)})]}),Q.length>0&&(0,T.jsxs)(`div`,{className:`space-y-3`,children:[Be.map(t=>{let n=`${t.name}@${t.marketplace}`;return(0,T.jsx)(se,{plugin:t,isInstalled:t.installed,isOperating:p.has(n),isExpanded:De===n,onInstall:e=>Me(t,e),onExpand:()=>ke(n),t:e},n)}),(0,T.jsx)(ae,{visible:Be.length,total:Q.length,onLoadMore:He,scrollRoot:R,t:e})]})]}),M===`marketplaces`&&(0,T.jsxs)(`div`,{className:`space-y-3`,children:[!B&&(0,T.jsxs)(`button`,{onClick:()=>V(!0),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium text-text-primary border border-border-muted hover:bg-bg-tertiary hover:border-text-primary/30 transition-colors`,children:[(0,T.jsx)(u,{size:12}),e(`plugins.addMarketplace`)]}),B&&(0,T.jsxs)(`div`,{className:`bg-bg-secondary rounded-xl border border-border-muted p-4 space-y-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,T.jsx)(`span`,{className:`text-[13px] font-medium`,children:e(`plugins.addMarketplace`)}),(0,T.jsx)(`button`,{onClick:()=>{V(!1),W(null)},className:`w-6 h-6 flex items-center justify-center rounded-full hover:bg-bg-tertiary transition-colors text-text-secondary`,children:(0,T.jsx)(f,{size:12})})]}),(0,T.jsx)(`input`,{type:`text`,value:H,onChange:e=>be(e.target.value),placeholder:e(`plugins.sourcePlaceholder`),className:`w-full bg-bg-primary text-text-primary text-[13px] border border-border-muted rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary`}),(0,T.jsx)(`input`,{type:`text`,value:U,onChange:e=>xe(e.target.value),placeholder:e(`plugins.namePlaceholder`),className:`w-full bg-bg-primary text-text-primary text-[13px] border border-border-muted rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary`}),we&&(0,T.jsx)(`div`,{className:`text-accent-red text-[12px]`,children:we}),(0,T.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,T.jsx)(`button`,{onClick:()=>{V(!1),W(null)},className:`px-3 py-1.5 rounded-lg text-[12px] text-text-secondary hover:bg-bg-tertiary transition-colors`,children:e(`plugins.cancel`)}),(0,T.jsxs)(`button`,{onClick:Ne,disabled:!H.trim()||Se,className:`px-3 py-1.5 rounded-lg text-[12px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1.5`,children:[Se&&(0,T.jsx)(o,{size:12,className:`animate-spin`}),e(`plugins.add`)]})]})]}),a&&n.length===0&&(0,T.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,T.jsx)(o,{size:18,className:`animate-spin text-text-tertiary`})}),!a&&n.length===0&&!B&&(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-text-tertiary`,children:[(0,T.jsx)(y,{size:48,className:`mb-4 opacity-30`}),(0,T.jsx)(`div`,{className:`text-[15px] font-medium mb-1.5 text-text-secondary`,children:e(`plugins.noMarketplaces`)}),(0,T.jsx)(`div`,{className:`text-[13px]`,children:e(`plugins.noMarketplacesHint`)})]}),n.length>0&&(0,T.jsx)(`div`,{className:`bg-bg-secondary rounded-xl border border-border-muted overflow-hidden`,children:n.map((t,n)=>(0,T.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 ${n>0?`border-t border-border-muted`:``}`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,T.jsx)(y,{size:14,className:`text-text-tertiary shrink-0`}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`div`,{className:`text-[13px] font-medium truncate`,children:t.name}),t.type&&(0,T.jsx)(`div`,{className:`text-[11px] text-text-tertiary`,children:t.type})]})]}),(0,T.jsx)(`div`,{className:`flex items-center gap-2 shrink-0`,children:Ee===t.name?(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`button`,{onClick:()=>Pe(t.name),className:`px-2.5 py-1 rounded-md text-[11px] font-medium text-white bg-accent-red hover:bg-accent-red/90 transition-colors`,children:e(`plugins.removeMarketplace`)}),(0,T.jsx)(`button`,{onClick:()=>K(null),className:`px-2.5 py-1 rounded-md text-[11px] text-text-secondary hover:bg-bg-tertiary transition-colors`,children:e(`plugins.cancel`)})]}):(0,T.jsx)(`button`,{onClick:()=>K(t.name),className:`w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-accent-red hover:bg-accent-red/10 transition-colors`,title:e(`plugins.removeMarketplace`),children:(0,T.jsx)(re,{size:13})})})]},t.name))})]})]})}),_e&&(0,T.jsxs)(`button`,{type:`button`,onClick:Ue,className:`absolute bottom-5 right-5 z-10 flex items-center gap-1.5 rounded-full border border-border-muted bg-bg-secondary/95 px-3 py-2 text-[12px] font-medium text-text-primary shadow-sm backdrop-blur-sm transition-colors hover:bg-bg-tertiary`,"aria-label":e(`plugins.backToTop`),children:[(0,T.jsx)(te,{size:14}),e(`plugins.backToTop`)]})]})]})}function ae({visible:e,total:t,onLoadMore:n,scrollRoot:r,t:i}){let a=(0,b.useRef)(null),s=e<t;return(0,b.useEffect)(()=>{let e=a.current;if(!e||!s)return;let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&n()},{root:r,rootMargin:`120px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[s,n,r,e,t]),t===0?null:(0,T.jsxs)(`div`,{ref:a,className:`flex flex-col items-center justify-center gap-1.5 pt-2 pb-1`,children:[(0,T.jsx)(`span`,{className:`text-[12px] text-text-tertiary`,children:i(`plugins.infiniteRange`).replace(`{visible}`,String(e)).replace(`{total}`,String(t))}),s?(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[11px] text-text-tertiary`,children:[(0,T.jsx)(o,{size:12,className:`animate-spin`}),i(`plugins.infiniteLoading`)]}):(0,T.jsx)(`span`,{className:`text-[11px] text-text-tertiary`,children:i(`plugins.infiniteEnd`)})]})}function oe({plugin:e,isEnabled:t,isOperating:n,isExpanded:r,confirmUninstall:i,onToggle:a,onUninstall:c,onConfirmUninstall:ee,onCancelUninstall:te,onExpand:l,t:u}){return(0,T.jsxs)(`div`,{className:`group rounded-xl border transition-all ${t?`bg-bg-secondary border-border-muted`:`bg-bg-secondary border-border-muted hover:border-border-muted`}`,children:[(0,T.jsxs)(`div`,{className:`flex items-start gap-4 px-5 py-4 cursor-pointer`,onClick:l,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 w-9 h-9 rounded-lg flex items-center justify-center mt-0.5 ${t?`bg-text-primary/8`:`bg-bg-tertiary`}`,children:(0,T.jsx)(d,{size:18,className:t?`text-text-primary`:`text-text-tertiary`})}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,T.jsx)(`span`,{className:`text-[14px] font-semibold text-text-primary truncate`,children:e.name}),e.version&&(0,T.jsxs)(`span`,{className:`text-[11px] text-text-tertiary shrink-0 font-mono`,children:[`v`,e.version]}),(0,T.jsx)(`span`,{className:`text-[10px] px-1.5 py-px rounded font-medium shrink-0 ${t?`bg-accent-green/15 text-accent-green`:`bg-bg-tertiary text-text-tertiary`}`,children:u(t?`plugins.enabled`:`plugins.disabled`)})]}),e.description&&(0,T.jsx)(`div`,{className:`text-[12px] text-text-secondary leading-relaxed mb-1.5 ${r?``:`line-clamp-2`}`,children:e.description}),(0,T.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-text-tertiary`,children:[(0,T.jsx)(y,{size:10,className:`shrink-0`}),(0,T.jsx)(`span`,{children:e.marketplace}),e.installScope&&(0,T.jsx)(`span`,{className:`px-1.5 py-px rounded bg-bg-tertiary text-[10px] font-medium`,children:u(`plugins.scope.${e.installScope}`)})]})]}),(0,T.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 pt-0.5`,onClick:e=>e.stopPropagation(),children:n?(0,T.jsx)(`div`,{className:`w-[72px] flex justify-center`,children:(0,T.jsx)(o,{size:16,className:`animate-spin text-text-tertiary`})}):i?(0,T.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,T.jsx)(`button`,{onClick:c,className:`px-2.5 py-1 rounded-md text-[11px] font-medium text-white bg-accent-red hover:bg-accent-red/90 transition-colors`,children:u(`plugins.uninstall`)}),(0,T.jsx)(`button`,{onClick:te,className:`px-2.5 py-1 rounded-md text-[11px] text-text-secondary hover:bg-bg-tertiary transition-colors`,children:u(`plugins.cancel`)})]}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`button`,{onClick:e.canSwitchoff===!1?void 0:a,disabled:e.canSwitchoff===!1,className:`px-2.5 py-1.5 rounded-md text-[11px] font-medium transition-colors flex items-center gap-1 ${e.canSwitchoff===!1?`text-text-tertiary border border-border-muted cursor-not-allowed opacity-50`:t?`text-text-secondary border border-border-muted hover:bg-bg-tertiary`:`text-text-primary border border-border-muted hover:bg-bg-tertiary`}`,title:e.canSwitchoff===!1?u(`plugins.policyCannotSwitchoff`):u(t?`plugins.disable`:`plugins.enable`),children:[t?(0,T.jsx)(v,{size:11}):(0,T.jsx)(s,{size:11}),u(t?`plugins.disable`:`plugins.enable`)]}),(0,T.jsx)(`button`,{onClick:e.canRemove===!1?void 0:ee,disabled:e.canRemove===!1,className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors ${e.canRemove===!1?`text-text-tertiary cursor-not-allowed opacity-30`:`text-text-tertiary hover:text-accent-red hover:bg-accent-red/10 opacity-0 group-hover:opacity-100 touch-actions-visible`}`,title:e.canRemove===!1?u(`plugins.policyCannotRemove`):u(`plugins.uninstall`),children:(0,T.jsx)(re,{size:13})})]})})]}),r&&(0,T.jsx)(k,{plugin:e,t:u})]})}function se({plugin:e,isInstalled:t,isOperating:n,isExpanded:r,onInstall:i,onExpand:a,t:s}){return(0,T.jsxs)(`div`,{className:`group rounded-xl border transition-all ${t?`bg-bg-secondary border-border-muted`:`bg-bg-secondary border-border-muted hover:border-border-muted`}`,children:[(0,T.jsxs)(`div`,{className:`flex items-start gap-4 px-5 py-4 cursor-pointer`,onClick:a,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 w-9 h-9 rounded-lg flex items-center justify-center mt-0.5 ${t?`bg-text-primary/8`:`bg-bg-tertiary`}`,children:(0,T.jsx)(d,{size:18,className:t?`text-text-primary`:`text-text-tertiary`})}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2 mb-0.5`,children:[(0,T.jsx)(`span`,{className:`text-[14px] font-semibold text-text-primary truncate`,children:e.name}),e.version&&(0,T.jsxs)(`span`,{className:`text-[11px] text-text-tertiary shrink-0 font-mono`,children:[`v`,e.version]}),t&&(0,T.jsx)(`span`,{className:`text-[10px] px-1.5 py-px rounded font-medium shrink-0 bg-accent-green/15 text-accent-green`,children:s(`plugins.installedLabel`)})]}),e.description&&(0,T.jsx)(`div`,{className:`text-[12px] text-text-secondary leading-relaxed mb-1.5 ${r?``:`line-clamp-2`}`,children:e.description}),(0,T.jsxs)(`div`,{className:`flex items-center gap-1 text-[11px] text-text-tertiary`,children:[(0,T.jsx)(y,{size:10,className:`shrink-0`}),(0,T.jsx)(`span`,{children:e.marketplace})]})]}),(0,T.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 pt-0.5`,onClick:e=>e.stopPropagation(),children:t?(0,T.jsx)(`div`,{className:`px-2.5 py-1.5 rounded-md text-[11px] font-medium text-text-tertiary bg-bg-tertiary`,children:s(`plugins.installed`)}):n?(0,T.jsx)(`div`,{className:`w-[72px] flex justify-center`,children:(0,T.jsx)(o,{size:16,className:`animate-spin text-text-tertiary`})}):(0,T.jsx)(j,{onInstall:i,t:s})})]}),r&&(0,T.jsx)(k,{plugin:e,t:s})]})}function k({plugin:e,t}){let n=e.source,r=typeof n==`object`&&n?n.url:void 0,i=typeof n==`object`&&n?n.source:typeof n==`string`?n:void 0,a=`installScope`in e?e.installScope:void 0;return(0,T.jsxs)(`div`,{className:`border-t border-border-muted mx-5 px-0 py-3.5 space-y-2.5`,children:[a&&(0,T.jsx)(A,{label:t(`plugins.scope`),children:(0,T.jsx)(`span`,{className:`text-[12px] text-text-secondary`,children:t(`plugins.scope.${a}`)})}),e.category&&(0,T.jsx)(A,{label:t(`plugins.category`),children:(0,T.jsx)(`span`,{className:`text-[11px] px-2 py-0.5 rounded bg-[#f5a623]/8 text-[#b8860b] font-medium`,children:e.category})}),e.author&&(0,T.jsxs)(A,{label:t(`plugins.author`),children:[(0,T.jsx)(`span`,{className:`text-[12px] text-text-primary font-medium`,children:e.author.name}),e.author.email&&(0,T.jsx)(`a`,{href:`mailto:${e.author.email}`,className:`text-[11px] text-text-tertiary hover:text-text-primary hover:underline ml-1`,onClick:e=>e.stopPropagation(),children:e.author.email}),e.author.url&&(0,T.jsxs)(`a`,{href:e.author.url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-[11px] text-text-tertiary hover:text-text-primary hover:underline ml-1`,onClick:e=>e.stopPropagation(),children:[e.author.url,(0,T.jsx)(_,{size:9})]})]}),e.license&&(0,T.jsx)(A,{label:t(`plugins.license`),children:(0,T.jsx)(`span`,{className:`text-[12px] text-text-secondary`,children:e.license})}),e.homepage&&(0,T.jsx)(A,{label:t(`plugins.homepage`),children:(0,T.jsxs)(`a`,{href:e.homepage,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all`,onClick:e=>e.stopPropagation(),children:[e.homepage,(0,T.jsx)(_,{size:10,className:`shrink-0 text-text-tertiary`})]})}),e.repository&&(0,T.jsx)(A,{label:t(`plugins.repository`),children:(0,T.jsxs)(`a`,{href:e.repository,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all`,onClick:e=>e.stopPropagation(),children:[e.repository,(0,T.jsx)(_,{size:10,className:`shrink-0 text-text-tertiary`})]})}),i&&(0,T.jsx)(A,{label:t(`plugins.source`),children:r?(0,T.jsxs)(`a`,{href:r,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all`,onClick:e=>e.stopPropagation(),children:[i,(0,T.jsx)(_,{size:10,className:`shrink-0 text-text-tertiary`})]}):(0,T.jsx)(`span`,{className:`text-[12px] text-text-secondary font-mono`,children:i})}),e.keywords&&e.keywords.length>0&&(0,T.jsx)(A,{label:t(`plugins.keywords`),children:(0,T.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.keywords.map(e=>(0,T.jsx)(`span`,{className:`text-[10px] px-1.5 py-px rounded bg-bg-tertiary text-text-tertiary`,children:e},e))})}),e.features&&e.features.length>0&&(0,T.jsx)(A,{label:t(`plugins.features`),children:(0,T.jsx)(`ul`,{className:`space-y-0.5`,children:e.features.map((e,t)=>(0,T.jsxs)(`li`,{className:`text-[12px] text-text-secondary flex items-start gap-1.5`,children:[(0,T.jsx)(`span`,{className:`text-text-tertiary shrink-0`,children:`·`}),e]},t))})})]})}function A({label:e,children:t}){return(0,T.jsxs)(`div`,{className:`flex items-baseline gap-3`,children:[(0,T.jsx)(`span`,{className:`text-[11px] text-text-tertiary w-12 shrink-0 text-right`,children:e}),(0,T.jsx)(`div`,{className:`flex-1 min-w-0 flex items-baseline flex-wrap gap-1`,children:t})]})}function j({onInstall:e,t}){let[n,r]=(0,b.useState)(!1);return(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsxs)(`button`,{onClick:()=>r(!n),className:`px-2.5 py-1.5 rounded-md text-[11px] font-medium text-text-primary border border-border-muted hover:bg-bg-tertiary transition-colors flex items-center gap-1`,title:t(`plugins.install`),children:[(0,T.jsx)(h,{size:11}),t(`plugins.install`)]}),n&&(0,T.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-50 bg-bg-primary border border-border-muted rounded-lg shadow-lg py-1 min-w-[220px]`,children:[(0,T.jsx)(`button`,{onClick:()=>{e(`user`),r(!1)},className:`w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors`,children:t(`plugins.installScope.user`)}),(0,T.jsx)(`button`,{onClick:()=>{e(`project`),r(!1)},className:`w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors`,children:t(`plugins.installScope.project`)}),(0,T.jsx)(`button`,{onClick:()=>{e(`project-local`),r(!1)},className:`w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors`,children:t(`plugins.installScope.local`)})]})]})}export{O as PluginsView};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{G as t,X as n,et as r,i,ot as a,t as o,tt as s}from"./use-i18n-BvN1piiI.js";import{l as c,u as l}from"./markdown-DCKhnxE9.js";import{At as u,Mt as d,Vt as f,jt as p,wn as m,yt as h}from"./index-BI5Z_cST.js";var g=i(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),_=i(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),v=i(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),y=e(l(),1),b=c();function x({onNavigate:e}){let{t:n}=o(),[i,a]=(0,y.useState)(t);if((0,y.useEffect)(()=>{let e=()=>a(t());return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[]),i===`add-wechat`||i?.startsWith(`rebind-wechat/`)){let e=i?.startsWith(`rebind-wechat/`)?i.split(`/`)[1]:void 0;return(0,b.jsx)(C,{onBack:()=>r(`remote-control`),t:n,existingInstanceId:e})}return i===`add-wecom`?(0,b.jsx)(T,{onBack:()=>r(`remote-control`),t:n}):(0,b.jsx)(S,{onNavigate:e,t:n})}function S({onNavigate:e,t}){let[r,i]=(0,y.useState)([]),[o,c]=(0,y.useState)(!0),[l,m]=(0,y.useState)(null),[x,S]=(0,y.useState)(null),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)({}),j=(0,y.useCallback)(async()=>{try{let e=await a(`/api/v1/channels`);if(e.ok){let t=await e.json(),n=t.capabilities?.remoteControlEnabled??!1;w(n),i((t.clients||[]).filter(e=>!e.hidden&&!e.instanceId.startsWith(`_pending`))),E(n&&t.capabilities?.canAddWechatBot!==!1),O(n&&t.capabilities?.canAddWecomBot!==!1),A(t.wecomGlobalDefaults??{})}}catch{}finally{c(!1)}},[]);(0,y.useEffect)(()=>{j();let e=setInterval(j,5e3);return()=>clearInterval(e)},[j]);let M=(0,y.useCallback)(async(e,t,r)=>{let i=`${t}:${r}:${e}`;S(i),m(null);try{let i=e===`delete`?`DELETE`:`POST`,o=e===`delete`?`/api/v1/channels/${t}/${r}`:`/api/v1/channels/${t}/${r}/${e}`,s=await a(o,{method:i});if(!s.ok){let e=await s.json().catch(()=>({}));throw Error(e.error||`Failed: ${s.status}`)}let c=await s.json().catch(()=>({}));if(e===`unbind`&&t===`wechat`&&c.needsQrScan){n(`remote-control`,`rebind-wechat/${r}`);return}await j()}catch(e){m(e?.message||`Action failed`)}finally{S(null)}},[j]),N=(0,y.useCallback)(async(e,t,n)=>{let r=`${e}:${t}:${n.streaming===void 0?`cards`:`streaming`}`;S(r),m(null);try{let r=await a(`/api/v1/channels/${e}/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`,...s()},body:JSON.stringify(n)});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error||`Failed: ${r.status}`)}await j()}catch(e){m(e?.message||`Action failed`)}finally{S(null)}},[j]),P=(0,y.useCallback)(async e=>{S(`wecom-global`),m(null);try{let t=await a(`/api/v1/channels/wecom-global`,{method:`PATCH`,headers:{"Content-Type":`application/json`,...s()},body:JSON.stringify(e)});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed: ${t.status}`)}let n=await t.json();A(n.wecomGlobalDefaults??{}),await j()}catch(e){m(e?.message||`Action failed`)}finally{S(null)}},[j]),F=e=>e===`connected`?`text-green-500`:e===`connecting`?`text-yellow-500`:e===`error`?`text-red-500`:`text-text-tertiary`,I=e=>t(e===`connected`?`remoteControl.connected`:e===`connecting`?`remoteControl.connecting`:`remoteControl.disconnected`),L=e=>e===`wechat`?(0,b.jsx)(f,{size:18,className:`text-green-500`}):e===`wecom`?(0,b.jsx)(p,{size:18,className:`text-accent-brand`}):(0,b.jsx)(_,{size:18,className:`text-text-tertiary`}),R=e=>e===`wechat`?t(`channel.wechat`)+t(`remoteControl.bot`):e===`wecom`?t(`channel.wecom`)+t(`remoteControl.bot`):e,z=e=>`${R(e.clientType)} #${e.instanceId.slice(0,4)}`,B=r.filter(e=>e.clientType===`wechat`&&!e.hidden),V=r.filter(e=>e.clientType===`wecom`&&!e.hidden),H=r.filter(e=>e.clientType!==`wechat`&&e.clientType!==`wecom`&&!e.hidden),U=T||D,W=e=>{let n=`${e.clientType}:${e.instanceId}`,r=e.status===`connected`,i=x?.startsWith(n);return(0,b.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-bg-secondary hover:bg-bg-hover transition-colors cursor-pointer`,onClick:()=>{i||M(r?`stop`:`start`,e.clientType,e.instanceId)},children:[L(e.clientType),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`div`,{className:`text-sm font-medium text-text-primary truncate`,children:z(e)}),(0,b.jsx)(`span`,{className:`text-xs ${F(e.status)}`,children:I(e.status)}),e.clientType===`wecom`&&(0,b.jsxs)(`div`,{className:`text-xs text-text-tertiary mt-0.5`,children:[e.streaming===!1?t(`remoteControl.replyMode`):t(`remoteControl.streamMode`),` · `,e.cards===!1?t(`remoteControl.textMode`):t(`remoteControl.cardMode`)]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[e.clientType===`wecom`&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`button`,{className:`px-2 py-1 rounded-md text-xs text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors border border-border-primary`,title:e.streaming===!1?t(`remoteControl.enableStreaming`):t(`remoteControl.disableStreaming`),disabled:!!i,onClick:()=>N(e.clientType,e.instanceId,{streaming:e.streaming===!1}),children:e.streaming===!1?t(`remoteControl.enableStreaming`):t(`remoteControl.disableStreaming`)}),(0,b.jsx)(`button`,{className:`px-2 py-1 rounded-md text-xs text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors border border-border-primary`,title:e.cards===!1?t(`remoteControl.enableCards`):t(`remoteControl.disableCards`),disabled:!!i,onClick:()=>N(e.clientType,e.instanceId,{cards:e.cards===!1}),children:e.cards===!1?t(`remoteControl.enableCards`):t(`remoteControl.disableCards`)})]}),(0,b.jsx)(`button`,{className:`p-1.5 rounded-md text-text-tertiary transition-colors ${r?`hover:text-orange-500`:`hover:text-green-500`} hover:bg-bg-hover`,title:t(r?`remoteControl.disconnect`:`remoteControl.connect`),disabled:!!i,onClick:()=>M(r?`stop`:`start`,e.clientType,e.instanceId),children:r?(0,b.jsx)(_,{size:14}):(0,b.jsx)(v,{size:14})}),r&&(0,b.jsx)(`button`,{className:`p-1.5 rounded-md text-text-tertiary hover:text-orange-500 hover:bg-bg-hover transition-colors`,title:t(`remoteControl.unbind`),disabled:!!i,onClick:()=>M(`unbind`,e.clientType,e.instanceId),children:(0,b.jsx)(u,{size:14})}),(0,b.jsx)(`button`,{className:`p-1.5 rounded-md text-text-tertiary hover:text-red-500 hover:bg-bg-hover transition-colors`,title:t(`remoteControl.delete`),disabled:!!i,onClick:()=>M(`delete`,e.clientType,e.instanceId),children:(0,b.jsx)(h,{size:14})})]})]},n)},G=(e,n,r,i)=>(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h2`,{className:`text-sm font-medium text-text-secondary mb-2`,children:e}),n.length===0?(0,b.jsx)(`div`,{className:`py-4 text-center text-xs text-text-tertiary`,children:t(`remoteControl.noChannels`)}):(0,b.jsx)(`div`,{className:`space-y-2`,children:n.map(W)}),r&&(0,b.jsxs)(`button`,{className:`flex items-center gap-1.5 mt-2 px-3 py-1.5 text-xs text-text-tertiary hover:text-text-primary hover:bg-bg-hover rounded-md transition-colors`,onClick:r,children:[(0,b.jsx)(d,{size:12}),i||t(`remoteControl.add`)]})]}),K=()=>(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-3 py-2.5 rounded-lg bg-bg-secondary border border-border-primary flex-wrap`,children:[(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`div`,{className:`text-xs font-medium text-text-secondary`,children:t(`remoteControl.wecomGlobalTitle`)}),(0,b.jsx)(`p`,{className:`text-xs text-text-tertiary mt-0.5`,children:t(`remoteControl.wecomGlobalHint`)})]}),(0,b.jsxs)(`div`,{className:`flex flex-wrap gap-2 shrink-0`,children:[(0,b.jsx)(`button`,{type:`button`,disabled:x===`wecom-global`,onClick:()=>P({streaming:!(k.streaming??!0)}),className:`px-3 py-1.5 rounded-full text-xs border border-border-primary text-text-primary hover:bg-bg-hover disabled:opacity-60 transition-colors`,children:k.streaming===!1?t(`remoteControl.wecomGlobalStreamOff`):t(`remoteControl.wecomGlobalStreamOn`)}),(0,b.jsx)(`button`,{type:`button`,disabled:x===`wecom-global`,onClick:()=>P({cards:!(k.cards??!0)}),className:`px-3 py-1.5 rounded-full text-xs border border-border-primary text-text-primary hover:bg-bg-hover disabled:opacity-60 transition-colors`,children:k.cards===!1?t(`remoteControl.wecomGlobalCardsOff`):t(`remoteControl.wecomGlobalCardsOn`)})]})]});return!o&&!C?(0,b.jsx)(b.Fragment,{}):(0,b.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:[(0,b.jsxs)(`div`,{className:`px-6 py-5 border-b border-border-primary`,children:[(0,b.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:t(`remoteControl.title`)}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary mt-1`,children:t(`remoteControl.subtitle`)})]}),(0,b.jsxs)(`div`,{className:`px-6 py-4 flex-1 space-y-6`,children:[l&&(0,b.jsx)(`div`,{className:`p-3 rounded-lg bg-red-500/10 text-red-500 text-sm`,children:l}),o?(0,b.jsx)(`div`,{className:`text-sm text-text-tertiary py-4`,children:t(`remoteControl.connecting`)}):(0,b.jsx)(`div`,{className:`space-y-6`,children:r.length===0?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`py-8 text-center`,children:[(0,b.jsx)(p,{size:32,className:`mx-auto mb-3 text-text-tertiary opacity-50`}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:t(`remoteControl.noChannels`)}),(0,b.jsx)(`p`,{className:`text-xs text-text-tertiary mt-1`,children:t(`remoteControl.noChannelsHint`)})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[D&&K(),U&&(0,b.jsxs)(`div`,{className:`flex gap-3`,children:[T&&(0,b.jsxs)(`button`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary`,onClick:()=>n(`remote-control`,`add-wechat`),children:[(0,b.jsx)(d,{size:14}),t(`remoteControl.addWeChat`)]}),D&&(0,b.jsxs)(`button`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary`,onClick:()=>n(`remote-control`,`add-wecom`),children:[(0,b.jsx)(d,{size:14}),t(`remoteControl.addWeCom`)]})]})]})]}):(0,b.jsxs)(b.Fragment,{children:[G(t(`channel.wechat`)+t(`remoteControl.bot`),B,T?()=>n(`remote-control`,`add-wechat`):void 0,t(`remoteControl.addWeChat`)),(0,b.jsxs)(`div`,{className:`space-y-2`,children:[D&&K(),G(t(`channel.wecom`)+t(`remoteControl.bot`),V,D?()=>n(`remote-control`,`add-wecom`):void 0,t(`remoteControl.addWeCom`))]}),H.length>0&&G(t(`remoteControl.plugin`),H)]})}),(0,b.jsx)(`hr`,{className:`border-border-primary`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 p-4 rounded-lg bg-bg-secondary hover:bg-bg-hover cursor-pointer transition-colors border border-border-primary`,onClick:()=>{e?e(`plugins`):window.location.hash=`#/plugins`},children:[(0,b.jsxs)(`div`,{className:`flex-1`,children:[(0,b.jsx)(`h3`,{className:`text-sm font-medium text-text-primary`,children:t(`remoteControl.installMore`)}),(0,b.jsx)(`p`,{className:`text-xs text-text-tertiary mt-1`,children:t(`remoteControl.installMoreHint`)})]}),(0,b.jsx)(g,{size:16,className:`text-text-tertiary`})]})]})]})}function C({onBack:e,t,existingInstanceId:n}){let[r,i]=(0,y.useState)(null),[o,c]=(0,y.useState)(t(`remoteControl.fetchingQr`)),[l,u]=(0,y.useState)(n??null),[d,f]=(0,y.useState)(null),[p,h]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let r=!1;return(async()=>{try{let o=n;if(!o){let e=await a(`/api/v1/channels/wechat`,{method:`POST`});if(!e.ok)throw Error((await e.json().catch(()=>({}))).error||`Failed`);let t=await e.json();if(r)return;o=t.instanceId,u(o)}for(let n=0;n<180&&!r;n++){await new Promise(e=>setTimeout(e,1e3));try{let n=await fetch(`/api/v1/channels/wechat/${o}/qr`,{headers:s()});if(!n.ok)continue;let a=await n.json();if(r)return;if(a.qrUrl&&i(a.qrUrl),a.message&&c(a.message),a.type===`confirmed`){h(!0),c(t(`remoteControl.connected`)),setTimeout(()=>{r||e()},1500);return}if(a.type===`error`){f(a.message);return}}catch{}}!r&&!p&&f(`Timeout`)}catch(e){r||f(e?.message||`Failed`)}})(),()=>{r=!0}},[n]),(0,b.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:[(0,b.jsxs)(`div`,{className:`px-6 py-5 border-b border-border-primary flex items-center gap-3`,children:[(0,b.jsx)(`button`,{onClick:e,className:`p-1 rounded-md hover:bg-bg-hover transition-colors`,children:(0,b.jsx)(m,{size:18})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:t(`remoteControl.addWeChat`)}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:t(`remoteControl.scanQr`)})]})]}),(0,b.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center px-6 py-8`,children:d?(0,b.jsxs)(`div`,{className:`text-center space-y-4`,children:[(0,b.jsx)(`p`,{className:`text-red-500`,children:d}),(0,b.jsx)(`button`,{onClick:e,className:`px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm border border-border-primary`,children:t(`remoteControl.cancel`)})]}):r?(0,b.jsxs)(`div`,{className:`text-center space-y-4`,children:[(0,b.jsx)(`div`,{className:`inline-block p-4 bg-white rounded-xl`,children:(0,b.jsx)(`img`,{src:`https://api.qrserver.com/v1/create-qr-code/?size=240x240&data=${encodeURIComponent(r)}`,alt:`QR Code`,className:`w-60 h-60`})}),(0,b.jsx)(`p`,{className:`text-sm text-text-secondary`,children:o})]}):(0,b.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,b.jsx)(`div`,{className:`w-8 h-8 mx-auto border-2 border-accent-brand border-t-transparent rounded-full animate-spin`}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:o})]})})]})}function w({onBack:e,onManual:t,t:n}){let[r,i]=(0,y.useState)(null),[o,c]=(0,y.useState)(n(`remoteControl.fetchingQr`)),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),p=(0,y.useRef)(e),h=(0,y.useRef)(n),g=(0,y.useRef)(d);return p.current=e,h.current=n,g.current=d,(0,y.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await a(`/api/v1/channels/wecom`,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`});if(!t.ok)throw Error((await t.json().catch(()=>({}))).error||`Failed`);let n=(await t.json()).instanceId;if(e)return;let r=Date.now()+3e5;for(;Date.now()<r&&!e;){try{let t=await fetch(`/api/v1/channels/wecom/${n}/qr`,{headers:s()});if(t.ok){let n=await t.json();if(e)return;if(n.qrUrl&&i(n.qrUrl),n.message&&c(n.message),n.type===`confirmed`){f(!0),c(h.current(`remoteControl.connected`)),setTimeout(()=>{e||p.current()},1500);return}if(n.type===`error`||n.type===`expired`){u(n.message);return}}}catch{}await new Promise(e=>setTimeout(e,1e3))}!e&&!g.current&&u(`Timeout`)}catch(t){e||u(t?.message||`Failed`)}})(),()=>{e=!0}},[]),(0,b.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:[(0,b.jsxs)(`div`,{className:`px-6 py-5 border-b border-border-primary flex items-center gap-3`,children:[(0,b.jsx)(`button`,{onClick:e,className:`p-1 rounded-md hover:bg-bg-hover transition-colors`,children:(0,b.jsx)(m,{size:18})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:n(`remoteControl.addWeCom`)}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:n(`remoteControl.scanWecomQr`)})]})]}),(0,b.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center px-6 py-8`,children:[t&&(0,b.jsx)(`button`,{className:`mb-6 text-sm text-text-tertiary hover:text-text-secondary underline`,onClick:t,children:n(`remoteControl.addWeComManual`)}),l?(0,b.jsxs)(`div`,{className:`text-center space-y-4`,children:[(0,b.jsx)(`p`,{className:`text-red-500`,children:l}),(0,b.jsx)(`button`,{onClick:e,className:`px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm border border-border-primary`,children:n(`remoteControl.cancel`)})]}):r?(0,b.jsxs)(`div`,{className:`text-center space-y-4`,children:[(0,b.jsx)(`div`,{className:`inline-block p-4 bg-white rounded-xl`,children:(0,b.jsx)(`img`,{src:`https://api.qrserver.com/v1/create-qr-code/?size=240x240&data=${encodeURIComponent(r)}`,alt:`QR Code`,className:`w-60 h-60`})}),(0,b.jsx)(`p`,{className:`text-sm text-text-secondary`,children:o})]}):(0,b.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,b.jsx)(`div`,{className:`w-8 h-8 mx-auto border-2 border-accent-brand border-t-transparent rounded-full animate-spin`}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:o})]})]})]})}function T({onBack:e,t}){let[n,r]=(0,y.useState)(`scan`);return n===`scan`?(0,b.jsx)(w,{onBack:e,onManual:()=>r(`manual`),t}):(0,b.jsx)(E,{onBack:e,onScan:()=>r(`scan`),t})}function E({onBack:e,onScan:t,t:n}){let[r,i]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(`botId`),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),h=(0,y.useCallback)(async()=>{if(r.trim()&&o.trim()){d(!0),p(null);try{let t=await a(`/api/v1/channels/wecom`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({botId:r.trim(),secret:o.trim()})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed`)}e()}catch(e){p(e?.message||`Failed`)}finally{d(!1)}}},[r,o,e]);return(0,b.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:[(0,b.jsxs)(`div`,{className:`px-6 py-5 border-b border-border-primary flex items-center gap-3`,children:[(0,b.jsx)(`button`,{onClick:e,className:`p-1 rounded-md hover:bg-bg-hover transition-colors`,children:(0,b.jsx)(m,{size:18})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:n(`remoteControl.addWeCom`)}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:n(`remoteControl.wecomBotIdHint`)})]})]}),(0,b.jsxs)(`div`,{className:`px-6 py-8 max-w-md mx-auto w-full space-y-6`,children:[t&&(0,b.jsx)(`button`,{className:`w-full px-4 py-2 rounded-lg bg-accent-brand text-accent-brand-foreground text-sm hover:bg-accent-brand/90 transition-colors`,onClick:t,children:n(`remoteControl.addWeComScan`)}),f&&(0,b.jsx)(`div`,{className:`p-3 rounded-lg bg-red-500/10 text-red-500 text-sm`,children:f}),(0,b.jsxs)(`div`,{className:`space-y-2`,children:[(0,b.jsx)(`label`,{className:`text-sm font-medium text-text-primary`,children:`Bot ID`}),(0,b.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors`,placeholder:n(`channel.botIdPlaceholder`),value:r,onChange:e=>i(e.target.value),autoFocus:!0,disabled:c===`secret`,onKeyDown:e=>{e.key===`Enter`&&r.trim()&&l(`secret`)}})]}),c===`secret`&&(0,b.jsxs)(`div`,{className:`space-y-2`,children:[(0,b.jsx)(`label`,{className:`text-sm font-medium text-text-primary`,children:`Secret`}),(0,b.jsx)(`input`,{type:`password`,className:`w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors`,placeholder:n(`channel.secretPlaceholder`),value:o,onChange:e=>s(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&o.trim()&&h()}}),(0,b.jsx)(`p`,{className:`text-xs text-text-tertiary`,children:n(`remoteControl.wecomSecretHint`)})]}),(0,b.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[c===`botId`?(0,b.jsx)(`button`,{className:`px-4 py-2 rounded-lg bg-accent-brand text-accent-brand-foreground text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50`,disabled:!r.trim(),onClick:()=>l(`secret`),children:n(`remoteControl.next`)}):(0,b.jsx)(`button`,{className:`px-4 py-2 rounded-lg bg-accent-brand text-accent-brand-foreground text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50`,disabled:!o.trim()||u,onClick:h,children:n(u?`remoteControl.connecting`:`remoteControl.connect`)}),(0,b.jsx)(`button`,{className:`px-4 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-secondary hover:bg-bg-hover transition-colors`,onClick:e,children:n(`remoteControl.cancel`)})]})]})]})}export{x as RemoteControlView};
1
+ import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{G as t,X as n,et as r,i,ot as a,t as o,tt as s}from"./use-i18n-pIrmaYmw.js";import{l as c,u as l}from"./markdown-DCKhnxE9.js";import{At as u,Mt as d,Vt as f,jt as p,wn as m,yt as h}from"./index-CcT-vg3O.js";var g=i(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),_=i(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),v=i(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),y=e(l(),1),b=c();function x({onNavigate:e}){let{t:n}=o(),[i,a]=(0,y.useState)(t);if((0,y.useEffect)(()=>{let e=()=>a(t());return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[]),i===`add-wechat`||i?.startsWith(`rebind-wechat/`)){let e=i?.startsWith(`rebind-wechat/`)?i.split(`/`)[1]:void 0;return(0,b.jsx)(C,{onBack:()=>r(`remote-control`),t:n,existingInstanceId:e})}return i===`add-wecom`?(0,b.jsx)(T,{onBack:()=>r(`remote-control`),t:n}):(0,b.jsx)(S,{onNavigate:e,t:n})}function S({onNavigate:e,t}){let[r,i]=(0,y.useState)([]),[o,c]=(0,y.useState)(!0),[l,m]=(0,y.useState)(null),[x,S]=(0,y.useState)(null),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)({}),j=(0,y.useCallback)(async()=>{try{let e=await a(`/api/v1/channels`);if(e.ok){let t=await e.json(),n=t.capabilities?.remoteControlEnabled??!1;w(n),i((t.clients||[]).filter(e=>!e.hidden&&!e.instanceId.startsWith(`_pending`))),E(n&&t.capabilities?.canAddWechatBot!==!1),O(n&&t.capabilities?.canAddWecomBot!==!1),A(t.wecomGlobalDefaults??{})}}catch{}finally{c(!1)}},[]);(0,y.useEffect)(()=>{j();let e=setInterval(j,5e3);return()=>clearInterval(e)},[j]);let M=(0,y.useCallback)(async(e,t,r)=>{let i=`${t}:${r}:${e}`;S(i),m(null);try{let i=e===`delete`?`DELETE`:`POST`,o=e===`delete`?`/api/v1/channels/${t}/${r}`:`/api/v1/channels/${t}/${r}/${e}`,s=await a(o,{method:i});if(!s.ok){let e=await s.json().catch(()=>({}));throw Error(e.error||`Failed: ${s.status}`)}let c=await s.json().catch(()=>({}));if(e===`unbind`&&t===`wechat`&&c.needsQrScan){n(`remote-control`,`rebind-wechat/${r}`);return}await j()}catch(e){m(e?.message||`Action failed`)}finally{S(null)}},[j]),N=(0,y.useCallback)(async(e,t,n)=>{let r=`${e}:${t}:${n.streaming===void 0?`cards`:`streaming`}`;S(r),m(null);try{let r=await a(`/api/v1/channels/${e}/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`,...s()},body:JSON.stringify(n)});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error||`Failed: ${r.status}`)}await j()}catch(e){m(e?.message||`Action failed`)}finally{S(null)}},[j]),P=(0,y.useCallback)(async e=>{S(`wecom-global`),m(null);try{let t=await a(`/api/v1/channels/wecom-global`,{method:`PATCH`,headers:{"Content-Type":`application/json`,...s()},body:JSON.stringify(e)});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed: ${t.status}`)}let n=await t.json();A(n.wecomGlobalDefaults??{}),await j()}catch(e){m(e?.message||`Action failed`)}finally{S(null)}},[j]),F=e=>e===`connected`?`text-green-500`:e===`connecting`?`text-yellow-500`:e===`error`?`text-red-500`:`text-text-tertiary`,I=e=>t(e===`connected`?`remoteControl.connected`:e===`connecting`?`remoteControl.connecting`:`remoteControl.disconnected`),L=e=>e===`wechat`?(0,b.jsx)(f,{size:18,className:`text-green-500`}):e===`wecom`?(0,b.jsx)(p,{size:18,className:`text-accent-brand`}):(0,b.jsx)(_,{size:18,className:`text-text-tertiary`}),R=e=>e===`wechat`?t(`channel.wechat`)+t(`remoteControl.bot`):e===`wecom`?t(`channel.wecom`)+t(`remoteControl.bot`):e,z=e=>`${R(e.clientType)} #${e.instanceId.slice(0,4)}`,B=r.filter(e=>e.clientType===`wechat`&&!e.hidden),V=r.filter(e=>e.clientType===`wecom`&&!e.hidden),H=r.filter(e=>e.clientType!==`wechat`&&e.clientType!==`wecom`&&!e.hidden),U=T||D,W=e=>{let n=`${e.clientType}:${e.instanceId}`,r=e.status===`connected`,i=x?.startsWith(n);return(0,b.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-bg-secondary hover:bg-bg-hover transition-colors cursor-pointer`,onClick:()=>{i||M(r?`stop`:`start`,e.clientType,e.instanceId)},children:[L(e.clientType),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`div`,{className:`text-sm font-medium text-text-primary truncate`,children:z(e)}),(0,b.jsx)(`span`,{className:`text-xs ${F(e.status)}`,children:I(e.status)}),e.clientType===`wecom`&&(0,b.jsxs)(`div`,{className:`text-xs text-text-tertiary mt-0.5`,children:[e.streaming===!1?t(`remoteControl.replyMode`):t(`remoteControl.streamMode`),` · `,e.cards===!1?t(`remoteControl.textMode`):t(`remoteControl.cardMode`)]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[e.clientType===`wecom`&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`button`,{className:`px-2 py-1 rounded-md text-xs text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors border border-border-primary`,title:e.streaming===!1?t(`remoteControl.enableStreaming`):t(`remoteControl.disableStreaming`),disabled:!!i,onClick:()=>N(e.clientType,e.instanceId,{streaming:e.streaming===!1}),children:e.streaming===!1?t(`remoteControl.enableStreaming`):t(`remoteControl.disableStreaming`)}),(0,b.jsx)(`button`,{className:`px-2 py-1 rounded-md text-xs text-text-tertiary hover:text-text-primary hover:bg-bg-hover transition-colors border border-border-primary`,title:e.cards===!1?t(`remoteControl.enableCards`):t(`remoteControl.disableCards`),disabled:!!i,onClick:()=>N(e.clientType,e.instanceId,{cards:e.cards===!1}),children:e.cards===!1?t(`remoteControl.enableCards`):t(`remoteControl.disableCards`)})]}),(0,b.jsx)(`button`,{className:`p-1.5 rounded-md text-text-tertiary transition-colors ${r?`hover:text-orange-500`:`hover:text-green-500`} hover:bg-bg-hover`,title:t(r?`remoteControl.disconnect`:`remoteControl.connect`),disabled:!!i,onClick:()=>M(r?`stop`:`start`,e.clientType,e.instanceId),children:r?(0,b.jsx)(_,{size:14}):(0,b.jsx)(v,{size:14})}),r&&(0,b.jsx)(`button`,{className:`p-1.5 rounded-md text-text-tertiary hover:text-orange-500 hover:bg-bg-hover transition-colors`,title:t(`remoteControl.unbind`),disabled:!!i,onClick:()=>M(`unbind`,e.clientType,e.instanceId),children:(0,b.jsx)(u,{size:14})}),(0,b.jsx)(`button`,{className:`p-1.5 rounded-md text-text-tertiary hover:text-red-500 hover:bg-bg-hover transition-colors`,title:t(`remoteControl.delete`),disabled:!!i,onClick:()=>M(`delete`,e.clientType,e.instanceId),children:(0,b.jsx)(h,{size:14})})]})]},n)},G=(e,n,r,i)=>(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h2`,{className:`text-sm font-medium text-text-secondary mb-2`,children:e}),n.length===0?(0,b.jsx)(`div`,{className:`py-4 text-center text-xs text-text-tertiary`,children:t(`remoteControl.noChannels`)}):(0,b.jsx)(`div`,{className:`space-y-2`,children:n.map(W)}),r&&(0,b.jsxs)(`button`,{className:`flex items-center gap-1.5 mt-2 px-3 py-1.5 text-xs text-text-tertiary hover:text-text-primary hover:bg-bg-hover rounded-md transition-colors`,onClick:r,children:[(0,b.jsx)(d,{size:12}),i||t(`remoteControl.add`)]})]}),K=()=>(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-3 py-2.5 rounded-lg bg-bg-secondary border border-border-primary flex-wrap`,children:[(0,b.jsxs)(`div`,{className:`min-w-0`,children:[(0,b.jsx)(`div`,{className:`text-xs font-medium text-text-secondary`,children:t(`remoteControl.wecomGlobalTitle`)}),(0,b.jsx)(`p`,{className:`text-xs text-text-tertiary mt-0.5`,children:t(`remoteControl.wecomGlobalHint`)})]}),(0,b.jsxs)(`div`,{className:`flex flex-wrap gap-2 shrink-0`,children:[(0,b.jsx)(`button`,{type:`button`,disabled:x===`wecom-global`,onClick:()=>P({streaming:!(k.streaming??!0)}),className:`px-3 py-1.5 rounded-full text-xs border border-border-primary text-text-primary hover:bg-bg-hover disabled:opacity-60 transition-colors`,children:k.streaming===!1?t(`remoteControl.wecomGlobalStreamOff`):t(`remoteControl.wecomGlobalStreamOn`)}),(0,b.jsx)(`button`,{type:`button`,disabled:x===`wecom-global`,onClick:()=>P({cards:!(k.cards??!0)}),className:`px-3 py-1.5 rounded-full text-xs border border-border-primary text-text-primary hover:bg-bg-hover disabled:opacity-60 transition-colors`,children:k.cards===!1?t(`remoteControl.wecomGlobalCardsOff`):t(`remoteControl.wecomGlobalCardsOn`)})]})]});return!o&&!C?(0,b.jsx)(b.Fragment,{}):(0,b.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:[(0,b.jsxs)(`div`,{className:`px-6 py-5 border-b border-border-primary`,children:[(0,b.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:t(`remoteControl.title`)}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary mt-1`,children:t(`remoteControl.subtitle`)})]}),(0,b.jsxs)(`div`,{className:`px-6 py-4 flex-1 space-y-6`,children:[l&&(0,b.jsx)(`div`,{className:`p-3 rounded-lg bg-red-500/10 text-red-500 text-sm`,children:l}),o?(0,b.jsx)(`div`,{className:`text-sm text-text-tertiary py-4`,children:t(`remoteControl.connecting`)}):(0,b.jsx)(`div`,{className:`space-y-6`,children:r.length===0?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`py-8 text-center`,children:[(0,b.jsx)(p,{size:32,className:`mx-auto mb-3 text-text-tertiary opacity-50`}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:t(`remoteControl.noChannels`)}),(0,b.jsx)(`p`,{className:`text-xs text-text-tertiary mt-1`,children:t(`remoteControl.noChannelsHint`)})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[D&&K(),U&&(0,b.jsxs)(`div`,{className:`flex gap-3`,children:[T&&(0,b.jsxs)(`button`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary`,onClick:()=>n(`remote-control`,`add-wechat`),children:[(0,b.jsx)(d,{size:14}),t(`remoteControl.addWeChat`)]}),D&&(0,b.jsxs)(`button`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm text-text-primary transition-colors border border-border-primary`,onClick:()=>n(`remote-control`,`add-wecom`),children:[(0,b.jsx)(d,{size:14}),t(`remoteControl.addWeCom`)]})]})]})]}):(0,b.jsxs)(b.Fragment,{children:[G(t(`channel.wechat`)+t(`remoteControl.bot`),B,T?()=>n(`remote-control`,`add-wechat`):void 0,t(`remoteControl.addWeChat`)),(0,b.jsxs)(`div`,{className:`space-y-2`,children:[D&&K(),G(t(`channel.wecom`)+t(`remoteControl.bot`),V,D?()=>n(`remote-control`,`add-wecom`):void 0,t(`remoteControl.addWeCom`))]}),H.length>0&&G(t(`remoteControl.plugin`),H)]})}),(0,b.jsx)(`hr`,{className:`border-border-primary`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-4 p-4 rounded-lg bg-bg-secondary hover:bg-bg-hover cursor-pointer transition-colors border border-border-primary`,onClick:()=>{e?e(`plugins`):window.location.hash=`#/plugins`},children:[(0,b.jsxs)(`div`,{className:`flex-1`,children:[(0,b.jsx)(`h3`,{className:`text-sm font-medium text-text-primary`,children:t(`remoteControl.installMore`)}),(0,b.jsx)(`p`,{className:`text-xs text-text-tertiary mt-1`,children:t(`remoteControl.installMoreHint`)})]}),(0,b.jsx)(g,{size:16,className:`text-text-tertiary`})]})]})]})}function C({onBack:e,t,existingInstanceId:n}){let[r,i]=(0,y.useState)(null),[o,c]=(0,y.useState)(t(`remoteControl.fetchingQr`)),[l,u]=(0,y.useState)(n??null),[d,f]=(0,y.useState)(null),[p,h]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let r=!1;return(async()=>{try{let o=n;if(!o){let e=await a(`/api/v1/channels/wechat`,{method:`POST`});if(!e.ok)throw Error((await e.json().catch(()=>({}))).error||`Failed`);let t=await e.json();if(r)return;o=t.instanceId,u(o)}for(let n=0;n<180&&!r;n++){await new Promise(e=>setTimeout(e,1e3));try{let n=await fetch(`/api/v1/channels/wechat/${o}/qr`,{headers:s()});if(!n.ok)continue;let a=await n.json();if(r)return;if(a.qrUrl&&i(a.qrUrl),a.message&&c(a.message),a.type===`confirmed`){h(!0),c(t(`remoteControl.connected`)),setTimeout(()=>{r||e()},1500);return}if(a.type===`error`){f(a.message);return}}catch{}}!r&&!p&&f(`Timeout`)}catch(e){r||f(e?.message||`Failed`)}})(),()=>{r=!0}},[n]),(0,b.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:[(0,b.jsxs)(`div`,{className:`px-6 py-5 border-b border-border-primary flex items-center gap-3`,children:[(0,b.jsx)(`button`,{onClick:e,className:`p-1 rounded-md hover:bg-bg-hover transition-colors`,children:(0,b.jsx)(m,{size:18})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:t(`remoteControl.addWeChat`)}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:t(`remoteControl.scanQr`)})]})]}),(0,b.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center px-6 py-8`,children:d?(0,b.jsxs)(`div`,{className:`text-center space-y-4`,children:[(0,b.jsx)(`p`,{className:`text-red-500`,children:d}),(0,b.jsx)(`button`,{onClick:e,className:`px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm border border-border-primary`,children:t(`remoteControl.cancel`)})]}):r?(0,b.jsxs)(`div`,{className:`text-center space-y-4`,children:[(0,b.jsx)(`div`,{className:`inline-block p-4 bg-white rounded-xl`,children:(0,b.jsx)(`img`,{src:`https://api.qrserver.com/v1/create-qr-code/?size=240x240&data=${encodeURIComponent(r)}`,alt:`QR Code`,className:`w-60 h-60`})}),(0,b.jsx)(`p`,{className:`text-sm text-text-secondary`,children:o})]}):(0,b.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,b.jsx)(`div`,{className:`w-8 h-8 mx-auto border-2 border-accent-brand border-t-transparent rounded-full animate-spin`}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:o})]})})]})}function w({onBack:e,onManual:t,t:n}){let[r,i]=(0,y.useState)(null),[o,c]=(0,y.useState)(n(`remoteControl.fetchingQr`)),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),p=(0,y.useRef)(e),h=(0,y.useRef)(n),g=(0,y.useRef)(d);return p.current=e,h.current=n,g.current=d,(0,y.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await a(`/api/v1/channels/wecom`,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`});if(!t.ok)throw Error((await t.json().catch(()=>({}))).error||`Failed`);let n=(await t.json()).instanceId;if(e)return;let r=Date.now()+3e5;for(;Date.now()<r&&!e;){try{let t=await fetch(`/api/v1/channels/wecom/${n}/qr`,{headers:s()});if(t.ok){let n=await t.json();if(e)return;if(n.qrUrl&&i(n.qrUrl),n.message&&c(n.message),n.type===`confirmed`){f(!0),c(h.current(`remoteControl.connected`)),setTimeout(()=>{e||p.current()},1500);return}if(n.type===`error`||n.type===`expired`){u(n.message);return}}}catch{}await new Promise(e=>setTimeout(e,1e3))}!e&&!g.current&&u(`Timeout`)}catch(t){e||u(t?.message||`Failed`)}})(),()=>{e=!0}},[]),(0,b.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:[(0,b.jsxs)(`div`,{className:`px-6 py-5 border-b border-border-primary flex items-center gap-3`,children:[(0,b.jsx)(`button`,{onClick:e,className:`p-1 rounded-md hover:bg-bg-hover transition-colors`,children:(0,b.jsx)(m,{size:18})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:n(`remoteControl.addWeCom`)}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:n(`remoteControl.scanWecomQr`)})]})]}),(0,b.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center px-6 py-8`,children:[t&&(0,b.jsx)(`button`,{className:`mb-6 text-sm text-text-tertiary hover:text-text-secondary underline`,onClick:t,children:n(`remoteControl.addWeComManual`)}),l?(0,b.jsxs)(`div`,{className:`text-center space-y-4`,children:[(0,b.jsx)(`p`,{className:`text-red-500`,children:l}),(0,b.jsx)(`button`,{onClick:e,className:`px-4 py-2 rounded-lg bg-bg-secondary hover:bg-bg-hover text-sm border border-border-primary`,children:n(`remoteControl.cancel`)})]}):r?(0,b.jsxs)(`div`,{className:`text-center space-y-4`,children:[(0,b.jsx)(`div`,{className:`inline-block p-4 bg-white rounded-xl`,children:(0,b.jsx)(`img`,{src:`https://api.qrserver.com/v1/create-qr-code/?size=240x240&data=${encodeURIComponent(r)}`,alt:`QR Code`,className:`w-60 h-60`})}),(0,b.jsx)(`p`,{className:`text-sm text-text-secondary`,children:o})]}):(0,b.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,b.jsx)(`div`,{className:`w-8 h-8 mx-auto border-2 border-accent-brand border-t-transparent rounded-full animate-spin`}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:o})]})]})]})}function T({onBack:e,t}){let[n,r]=(0,y.useState)(`scan`);return n===`scan`?(0,b.jsx)(w,{onBack:e,onManual:()=>r(`manual`),t}):(0,b.jsx)(E,{onBack:e,onScan:()=>r(`scan`),t})}function E({onBack:e,onScan:t,t:n}){let[r,i]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(`botId`),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),h=(0,y.useCallback)(async()=>{if(r.trim()&&o.trim()){d(!0),p(null);try{let t=await a(`/api/v1/channels/wecom`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({botId:r.trim(),secret:o.trim()})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed`)}e()}catch(e){p(e?.message||`Failed`)}finally{d(!1)}}},[r,o,e]);return(0,b.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:[(0,b.jsxs)(`div`,{className:`px-6 py-5 border-b border-border-primary flex items-center gap-3`,children:[(0,b.jsx)(`button`,{onClick:e,className:`p-1 rounded-md hover:bg-bg-hover transition-colors`,children:(0,b.jsx)(m,{size:18})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h1`,{className:`text-lg font-semibold text-text-primary`,children:n(`remoteControl.addWeCom`)}),(0,b.jsx)(`p`,{className:`text-sm text-text-tertiary`,children:n(`remoteControl.wecomBotIdHint`)})]})]}),(0,b.jsxs)(`div`,{className:`px-6 py-8 max-w-md mx-auto w-full space-y-6`,children:[t&&(0,b.jsx)(`button`,{className:`w-full px-4 py-2 rounded-lg bg-accent-brand text-accent-brand-foreground text-sm hover:bg-accent-brand/90 transition-colors`,onClick:t,children:n(`remoteControl.addWeComScan`)}),f&&(0,b.jsx)(`div`,{className:`p-3 rounded-lg bg-red-500/10 text-red-500 text-sm`,children:f}),(0,b.jsxs)(`div`,{className:`space-y-2`,children:[(0,b.jsx)(`label`,{className:`text-sm font-medium text-text-primary`,children:`Bot ID`}),(0,b.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors`,placeholder:n(`channel.botIdPlaceholder`),value:r,onChange:e=>i(e.target.value),autoFocus:!0,disabled:c===`secret`,onKeyDown:e=>{e.key===`Enter`&&r.trim()&&l(`secret`)}})]}),c===`secret`&&(0,b.jsxs)(`div`,{className:`space-y-2`,children:[(0,b.jsx)(`label`,{className:`text-sm font-medium text-text-primary`,children:`Secret`}),(0,b.jsx)(`input`,{type:`password`,className:`w-full px-3 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-primary placeholder-text-tertiary focus:outline-none focus:border-accent-brand transition-colors`,placeholder:n(`channel.secretPlaceholder`),value:o,onChange:e=>s(e.target.value),autoFocus:!0,onKeyDown:e=>{e.key===`Enter`&&o.trim()&&h()}}),(0,b.jsx)(`p`,{className:`text-xs text-text-tertiary`,children:n(`remoteControl.wecomSecretHint`)})]}),(0,b.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[c===`botId`?(0,b.jsx)(`button`,{className:`px-4 py-2 rounded-lg bg-accent-brand text-accent-brand-foreground text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50`,disabled:!r.trim(),onClick:()=>l(`secret`),children:n(`remoteControl.next`)}):(0,b.jsx)(`button`,{className:`px-4 py-2 rounded-lg bg-accent-brand text-accent-brand-foreground text-sm hover:bg-accent-brand/90 transition-colors disabled:opacity-50`,disabled:!o.trim()||u,onClick:h,children:n(u?`remoteControl.connecting`:`remoteControl.connect`)}),(0,b.jsx)(`button`,{className:`px-4 py-2 rounded-lg bg-bg-secondary border border-border-primary text-sm text-text-secondary hover:bg-bg-hover transition-colors`,onClick:e,children:n(`remoteControl.cancel`)})]})]})]})}export{x as RemoteControlView};