@opencodex/cli 1.0.37 → 1.0.40

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 (129) hide show
  1. package/LICENSE.md +12 -0
  2. package/README.md +429 -24
  3. package/bin/stt/requirements.txt +32 -0
  4. package/bin/stt/stt_server.py +619 -0
  5. package/bin/tts/requirements.txt +21 -0
  6. package/bin/tts/tts_server.py +404 -0
  7. package/cli-wrapper.cjs +4 -0
  8. package/llms.txt +88 -0
  9. package/package.json +30 -11
  10. package/web/dist/assets/AssistantsView-BiUiWjhF.js +1 -0
  11. package/web/dist/assets/AutomationView-Dcf_yNaI.js +1 -0
  12. package/web/dist/assets/ChannelConfigView-BLnxsMGm.js +8 -0
  13. package/web/dist/assets/ConnectorsView-CX3E6X6c.js +1 -0
  14. package/web/dist/assets/DesignSystemView--x-P-lpD.js +1 -0
  15. package/web/dist/assets/Drawer-CjAgqH3B.js +1 -0
  16. package/web/dist/assets/FileTreeView-Chb_fzTK.js +11 -0
  17. package/web/dist/assets/HookConfigView-EafYlWdN.js +1 -0
  18. package/web/dist/assets/InputArea-BbHslX7b.js +50 -0
  19. package/web/dist/assets/ModelsView-CGN5Nljr.js +1 -0
  20. package/web/dist/assets/PluginsView-CDiJgvI8.js +2 -0
  21. package/web/dist/assets/ProjectsView-C5Usmwqy.js +1 -0
  22. package/web/dist/assets/SessionGrid-Drxg0r_u.js +4 -0
  23. package/web/dist/assets/SettingsModal-Cmts6aBG.js +10 -0
  24. package/web/dist/assets/Skeleton-Dsk6B0U3.js +1 -0
  25. package/web/dist/assets/SkillsView-TEDR_3XX.js +1 -0
  26. package/web/dist/assets/TemplatesTab-DtN5Kdgh.js +1 -0
  27. package/web/dist/assets/ToolsView-VukZnIt1.js +1 -0
  28. package/web/dist/assets/VizCardsSkeleton-C_GaEfXd.js +1 -0
  29. package/web/dist/assets/abnfDiagram-YUKMZFIV-BIFw6B_N.js +1 -0
  30. package/web/dist/assets/arc-BZQ951h9.js +1 -0
  31. package/web/dist/assets/architectureDiagram-47P4ROYG-BP5qiXzf.js +36 -0
  32. package/web/dist/assets/blockDiagram-E7TT5TSB-DtRpcE7F.js +140 -0
  33. package/web/dist/assets/c4Diagram-CRA5TL53-Gdzn8UBh.js +38 -0
  34. package/web/dist/assets/channel-BND6_KSH.js +1 -0
  35. package/web/dist/assets/chunk-2Q5K7J3B-3U6HMlsm.js +1 -0
  36. package/web/dist/assets/chunk-5VM5RSS4-CYl9mwa-.js +15 -0
  37. package/web/dist/assets/chunk-7TKQ45FW-Dn6ktcY5.js +1 -0
  38. package/web/dist/assets/chunk-AW2ZBBNX-De0QX6p1.js +88 -0
  39. package/web/dist/assets/chunk-FVRAUYC3-CpXDfvz4.js +2 -0
  40. package/web/dist/assets/chunk-HTAEGDNF-D1KDvcDd.js +1 -0
  41. package/web/dist/assets/chunk-JWPE2WC7-umm4A-fq.js +1 -0
  42. package/web/dist/assets/chunk-KQW6MTUR-JYH94hpE.js +1 -0
  43. package/web/dist/assets/chunk-XXDRQBXY-CSlCFByc.js +1 -0
  44. package/web/dist/assets/classDiagram-v2-K4WV4PDN-DnFwS0qN.js +217 -0
  45. package/web/dist/assets/cose-bilkent-JH36ORCC-BxUTUyep.js +1 -0
  46. package/web/dist/assets/cynefin-EF2NZ3EQ-CiMvulJr.js +141 -0
  47. package/web/dist/assets/cynefinDiagram-3GCD6N5R-DuXFORdW.js +62 -0
  48. package/web/dist/assets/cytoscape.esm-Ix0LnXOy.js +331 -0
  49. package/web/dist/assets/dagre-W4DXFKR2-DzMZHXci.js +4 -0
  50. package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
  51. package/web/dist/assets/diagram-2UJZ2QOL-B6tO5G1v.js +200 -0
  52. package/web/dist/assets/diagram-OVF4WLC6-DRZt8tGc.js +24 -0
  53. package/web/dist/assets/diagram-PFPMY2P6-DGh6IecR.js +30 -0
  54. package/web/dist/assets/diagram-UMYRVEAY-BLbnt0yT.js +24 -0
  55. package/web/dist/assets/diagram-YEKJPTXX-C-S5DVhj.js +41 -0
  56. package/web/dist/assets/diagram-ZIFT7M5P-JrGHTWbo.js +3 -0
  57. package/web/dist/assets/ebnfDiagram-VR2GEFS7-DPXA-YOi.js +1 -0
  58. package/web/dist/assets/elk-IJKZMXRS-CINeWt2W.js +27 -0
  59. package/web/dist/assets/erDiagram-O2IAPWRE-PPaHmqA1.js +99 -0
  60. package/web/dist/assets/flowDiagram-OXPTDLAJ-t-u0QXEA.js +213 -0
  61. package/web/dist/assets/ganttDiagram-R7TSEDQI-Bw49ZD_b.js +292 -0
  62. package/web/dist/assets/gitGraphDiagram-XJZIOB7I-BAfOqeeg.js +106 -0
  63. package/web/dist/assets/graph-Bn3Yngep.js +1 -0
  64. package/web/dist/assets/{icons-f1hlMKvD.js → icons-Bm_ZzSAy.js} +384 -144
  65. package/web/dist/assets/index-CeeLdENM.js +677 -0
  66. package/web/dist/assets/index-Ceez9lYk.css +1 -0
  67. package/web/dist/assets/infoDiagram-5W2HQ5XZ-Bv4RBxYW.js +2 -0
  68. package/web/dist/assets/init-Gi6I4Gst.js +1 -0
  69. package/web/dist/assets/ishikawaDiagram-K3B6WC7H-DEpj0bRp.js +70 -0
  70. package/web/dist/assets/journeyDiagram-COXZFDF6-MJu84Iiz.js +139 -0
  71. package/web/dist/assets/kanban-definition-P3RFRI5V-mlYSRALK.js +89 -0
  72. package/web/dist/assets/linear-5j9gt8MV.js +1 -0
  73. package/web/dist/assets/{markdown-DEtuzEyz.js → markdown-BWXjRrSw.js} +8 -8
  74. package/web/dist/assets/mermaid.core-DLb6eAON.js +314 -0
  75. package/web/dist/assets/mindmap-definition-LZFPQGKD-C9v_57Ex.js +96 -0
  76. package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
  77. package/web/dist/assets/{panels-Bn-2wCur.js → panels-BQOvnbWH.js} +1 -1
  78. package/web/dist/assets/pegDiagram-BGZESJAR-KQP26s3-.js +1 -0
  79. package/web/dist/assets/pieDiagram-CAPJLFHJ-DN3RQ_ih.js +39 -0
  80. package/web/dist/assets/profileChange-B7TaQ18u.js +1 -0
  81. package/web/dist/assets/quadrantDiagram-GDMTTRAM-BpL_ZL76.js +7 -0
  82. package/web/dist/assets/railroadDiagram-SM67HX2B-DZ-fPU85.js +1 -0
  83. package/web/dist/assets/{react-vendor-ClBKp0t-.js → react-vendor-C0HIWSpf.js} +1 -1
  84. package/web/dist/assets/requirementDiagram-X7JNWC4A-mKPGj64L.js +84 -0
  85. package/web/dist/assets/sankeyDiagram-UM26HJRW-Bs4xfjQP.js +40 -0
  86. package/web/dist/assets/sequenceDiagram-ZO4K6R2Y-BjUmzZaO.js +169 -0
  87. package/web/dist/assets/sizeCapture-INFHLROL-BXBM3j_Q.js +1 -0
  88. package/web/dist/assets/{state-xD58vmym.js → state-Kfon1nTr.js} +1 -1
  89. package/web/dist/assets/stateDiagram-v2-TBUQTH76-FGgFDGUU.js +291 -0
  90. package/web/dist/assets/sttLanguages-C7kVulzY.js +1 -0
  91. package/web/dist/assets/swimlanes-N4OXWK64-wkd_n4HU.js +1 -0
  92. package/web/dist/assets/swimlanesDiagram-K3J5GTZL-CKnwEuq_.js +8 -0
  93. package/web/dist/assets/timeline-definition-YOQAKGHF-DyBln1jw.js +120 -0
  94. package/web/dist/assets/usecaseDiagram-VIAY4XPW-Cqis3XHX.js +370 -0
  95. package/web/dist/assets/vennDiagram-BLWOH2XV-BaiFLOVS.js +34 -0
  96. package/web/dist/assets/wardleyDiagram-YMQ3BMBF-C4CzpJto.js +78 -0
  97. package/web/dist/assets/xychartDiagram-TAQBALBS-Dp1hfe3-.js +7 -0
  98. package/web/dist/figma-demo/product-1.jpg +0 -0
  99. package/web/dist/figma-demo/product-2.jpg +0 -0
  100. package/web/dist/figma-demo/trail-1.jpg +0 -0
  101. package/web/dist/figma-demo/trail-2.jpg +0 -0
  102. package/web/dist/figma-demo/trail-3.jpg +0 -0
  103. package/web/dist/fonts/OFL-Inter.txt +93 -0
  104. package/web/dist/fonts/inter-latin-400-normal.woff2 +0 -0
  105. package/web/dist/fonts/inter-latin-600-normal.woff2 +0 -0
  106. package/web/dist/icons/icon-180.png +0 -0
  107. package/web/dist/icons/icon-192.png +0 -0
  108. package/web/dist/icons/icon-512.png +0 -0
  109. package/web/dist/icons/icon-maskable-512.png +0 -0
  110. package/web/dist/index.html +39 -9
  111. package/web/dist/manifest.webmanifest +16 -0
  112. package/web/dist/assets/AssistantsView-OMdgsTIj.js +0 -1
  113. package/web/dist/assets/AutomationView-BPwjLbkL.js +0 -1
  114. package/web/dist/assets/ChannelConfigView-JDljUn42.js +0 -8
  115. package/web/dist/assets/ConnectorsView-AemNT1Ae.js +0 -1
  116. package/web/dist/assets/FileTreeView-DYx-0jFV.js +0 -11
  117. package/web/dist/assets/HookConfigView-CS1QqgPx.js +0 -1
  118. package/web/dist/assets/ModelsView-B3nHezvJ.js +0 -1
  119. package/web/dist/assets/PluginsView-C4Xc70ec.js +0 -1
  120. package/web/dist/assets/SessionGrid-C9-LeJH0.js +0 -47
  121. package/web/dist/assets/SettingsModal-CjWT1C66.js +0 -4
  122. package/web/dist/assets/SkillsView-DTZyXald.js +0 -1
  123. package/web/dist/assets/TemplatesTab-CE-CfCf2.js +0 -1
  124. package/web/dist/assets/ThreeScene-CMqkpyKO.js +0 -2863
  125. package/web/dist/assets/ThreeScene-DvOrMIoG.css +0 -1
  126. package/web/dist/assets/ToolsView-CrEHDTEO.js +0 -1
  127. package/web/dist/assets/index-BCHbHIbw.css +0 -1
  128. package/web/dist/assets/index-u1vYyqna.js +0 -592
  129. package/web/dist/assets/sttLanguages-BNRptAQA.js +0 -1
@@ -1 +0,0 @@
1
- import{j as e}from"./markdown-DEtuzEyz.js";import{a as r,au as j,h as N,L as v,be as w,b7 as S,b3 as k,aU as C,a9 as I,l as z}from"./icons-f1hlMKvD.js";import{u as g,a as y,a9 as A,aa as E}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";const R={idle:"bg-green-500",running:"bg-yellow-500 animate-pulse",paused:"bg-gray-500",error:"bg-red-500"};function q(d){return R[d]??"bg-gray-500"}const O=r.memo(function({onOpenSession:s,onNavigate:m}){const{t:a}=g(),[l,u]=r.useState([]),[n,c]=r.useState(!0),[p,h]=r.useState(null),[x,f]=r.useState(null),o=r.useCallback(async()=>{try{const t=await y.assistants.list();t.success&&Array.isArray(t.data)?(u(t.data),h(null)):h(t.error||a("assistants.loadFailed"))}catch(t){h(t instanceof Error?t.message:String(t))}finally{c(!1)}},[a]);r.useEffect(()=>{o();const t=window.setInterval(()=>{o()},8e3);return()=>window.clearInterval(t)},[o]);const b=r.useCallback(async(t,i)=>{(await y.assistants.update(t,i)).success&&o()},[o]);return e.jsxs("div",{className:"flex h-full flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-dark-border px-4 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{size:16,className:"text-accent-blue","aria-hidden":"true"}),e.jsx("h2",{className:"text-sm font-semibold text-dark-text",children:a("assistants.title")}),!n&&e.jsx("span",{className:"rounded-full bg-dark-hover px-1.5 py-0.5 text-[10px] text-dark-muted",children:l.length})]}),e.jsxs("button",{type:"button",onClick:()=>void o(),className:"flex items-center gap-1 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-hover hover:text-dark-text",title:a("common.refresh"),children:[e.jsx(N,{size:12,className:n?"animate-spin":"","aria-hidden":"true"}),a("common.refresh")]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-3",children:n&&l.length===0?e.jsxs("div",{className:"flex items-center justify-center py-12 text-xs text-dark-muted",children:[e.jsx(v,{size:14,className:"mr-1.5 animate-spin","aria-hidden":"true"}),a("assistants.loading")]}):p&&l.length===0?e.jsx("div",{className:"py-8 text-center text-xs text-red-400",children:p}):l.length===0?e.jsxs("div",{className:"py-10 text-center text-xs text-dark-muted",children:[e.jsx(j,{size:24,className:"mx-auto mb-2 text-dark-muted","aria-hidden":"true"}),e.jsx("p",{children:a("assistants.empty")}),e.jsx("p",{className:"mt-1 text-[11px]",children:a("assistants.emptyHint")}),e.jsx("button",{type:"button",onClick:()=>m("channels"),className:"mt-3 rounded border border-dark-border px-2.5 py-1 text-[11px] text-dark-text hover:bg-dark-hover",children:a("assistants.goChannels")})]}):e.jsx("div",{className:"flex flex-col gap-2",children:l.map(t=>e.jsx(T,{assistant:t,expanded:x===t.sessionId,onToggleExpand:()=>f(x===t.sessionId?null:t.sessionId),onOpen:()=>s(t.sessionId,t.title),onUpdate:i=>void b(t.sessionId,i)},t.sessionId))})})]})}),T=r.memo(function({assistant:s,expanded:m,onToggleExpand:a,onOpen:l,onUpdate:u}){const{t:n}=g(),c=s.channel.peerKind==="group";return e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx("span",{className:"text-base leading-none","aria-hidden":"true",children:A(s.channel.type)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs font-medium text-dark-text",title:s.title,children:s.title}),e.jsx("span",{className:`h-1.5 w-1.5 shrink-0 rounded-full ${q(s.status)}`,title:n(`assistants.status.${s.status}`,{defaultValue:s.status})}),c?e.jsx(w,{size:11,className:"shrink-0 text-dark-muted","aria-label":n("assistants.group")}):e.jsx(S,{size:11,className:"shrink-0 text-dark-muted","aria-label":n("assistants.dm")})]}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-1.5 text-[10px] text-dark-muted",children:[e.jsx("span",{className:"shrink-0",children:E(s.channel.type)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:s.channel.peerId,children:s.channel.peerId}),s.stats.unread>0&&e.jsx("span",{className:"shrink-0 rounded-full bg-red-500/80 px-1.5 text-[9px] font-medium text-white",children:s.stats.unread})]}),s.preview&&e.jsx("p",{className:"mt-1 line-clamp-2 text-[11px] leading-snug text-dark-muted",title:s.preview,children:s.preview})]}),e.jsx(U,{mode:s.mode}),s.trust.level==="owner"?e.jsx(k,{size:12,className:"shrink-0 text-green-500","aria-label":n("assistants.trust.owner")}):s.trust.level==="public"?e.jsx(C,{size:12,className:"shrink-0 text-yellow-600","aria-label":n("assistants.trust.public")}):e.jsx(k,{size:12,className:"shrink-0 text-accent-blue","aria-label":n("assistants.trust.team")})]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t border-dark-border px-3 py-1.5",children:[e.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 rounded px-2 py-0.5 text-[11px] text-accent-blue hover:bg-dark-hover",children:[e.jsx(I,{size:11,"aria-hidden":"true"}),n("assistants.openSession")]}),e.jsx("button",{type:"button",onClick:a,className:"flex items-center gap-1 rounded px-2 py-0.5 text-[11px] text-dark-muted hover:bg-dark-hover hover:text-dark-text",children:n("assistants.policy")}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[10px] text-dark-muted",children:n("assistants.groupPolicy",{mention:String(c?s.policy.mentionRequired:!1)})})]}),m&&e.jsx(M,{assistant:s,isGroup:c,onUpdate:u})]})});function U({mode:d}){const{t:s}=g();return e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[9px] font-medium ${d==="delegate"?"bg-accent-blue/15 text-accent-blue":"bg-dark-hover text-dark-muted"}`,children:s(`assistants.mode.${d}`)})}function M({assistant:d,isGroup:s,onUpdate:m}){const{t:a}=g(),[l,u]=r.useState(d.mode),[n,c]=r.useState(d.policy.mentionRequired),[p,h]=r.useState(String(d.policy.cooldownSeconds)),[x,f]=r.useState((d.policy.keywords??[]).join(", ")),[o,b]=r.useState(!1),t=()=>{b(!0),m({mode:l,policy:{mentionRequired:s?n:!1,cooldownSeconds:Math.max(0,Number(p)||0),...x.trim()?{keywords:x.split(/[,,]/).map(i=>i.trim()).filter(Boolean)}:{}}}),window.setTimeout(()=>b(!1),600)};return e.jsxs("div",{className:"border-t border-dark-border px-3 py-2.5 text-[11px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-dark-muted",children:[a("assistants.mode.label"),e.jsxs("select",{value:l,onChange:i=>u(i.target.value),className:"rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-dark-text",children:[e.jsx("option",{value:"delegate",children:a("assistants.mode.delegate")}),e.jsx("option",{value:"direct",children:a("assistants.mode.direct")})]})]}),s&&e.jsxs("label",{className:"flex items-center gap-1.5 text-dark-muted",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:i=>c(i.target.checked)}),a("assistants.mentionRequired")]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-dark-muted",children:[a("assistants.cooldown"),e.jsx("input",{type:"number",min:0,value:p,onChange:i=>h(i.target.value),className:"w-14 rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-dark-text"}),"s"]})]}),e.jsxs("label",{className:"mt-2 flex items-center gap-1.5 text-dark-muted",children:[a("assistants.keywords"),e.jsx("input",{type:"text",value:x,placeholder:a("assistants.keywordsPlaceholder")??"",onChange:i=>f(i.target.value),className:"min-w-0 flex-1 rounded border border-dark-border bg-dark-surface px-1.5 py-0.5 text-dark-text"})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs("button",{type:"button",onClick:t,disabled:o,className:"flex items-center gap-1 rounded bg-accent-blue px-2.5 py-1 text-[11px] font-medium text-white disabled:opacity-60",children:[o?e.jsx(v,{size:11,className:"animate-spin","aria-hidden":"true"}):e.jsx(z,{size:11,"aria-hidden":"true"}),a("common.save")]})})]})}export{O as AssistantsView};
@@ -1 +0,0 @@
1
- import{j as e}from"./markdown-DEtuzEyz.js";import{a as n,ay as v,h as $,aa as D,A as I,bp as L,f as O,aE as J,b2 as U,X as B}from"./icons-f1hlMKvD.js";import{u as M,ab as V}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";function Q(){const{t:a}=M(),{automations:r,runsByAutomation:d,fetchAutomations:o,createAutomation:N,deleteAutomation:y,toggleAutomation:w,runAutomation:C,fetchRuns:A,error:l}=V(),[S,x]=n.useState(!1),[m,P]=n.useState(null),[u,p]=n.useState(""),[h,b]=n.useState(""),[i,g]=n.useState("0 9 * * *"),[f,j]=n.useState("");n.useEffect(()=>{o()},[o]);const z=async t=>{const s=f.trim();if(!s)return;const[c,...T]=s.split(/\s+/),k=T.join(" ");c&&k&&(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tool:c,target:k})})).ok&&(j(""),await o())},E=async(t,s)=>{(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"DELETE",headers:{"content-type":"application/json"},body:JSON.stringify({entry:s})})).ok&&await o()},R=async t=>{const s=m===t?null:t;P(s),s&&await A(t)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(v,{size:20,className:"text-accent-blue"}),a("automation.title"),e.jsxs("span",{className:"text-xs text-dark-muted font-normal",children:["(",r.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>void o(),className:"p-2 rounded-lg hover:bg-dark-hover text-dark-muted",title:a("automation.refresh"),children:e.jsx($,{size:16})}),e.jsxs("button",{onClick:()=>x(t=>!t),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-blue/20 text-accent-blue hover:bg-accent-blue/30 text-sm font-medium",children:[e.jsx(D,{size:16})," ",a("automation.new")]})]})]}),l&&e.jsxs("div",{className:"mb-3 p-3 rounded-lg bg-accent-red/10 text-accent-red text-sm flex items-center gap-2",children:[e.jsx(I,{size:16})," ",l]}),S&&e.jsxs("div",{className:"mb-4 rounded-lg border border-dark-border bg-dark-surface p-4 space-y-3",children:[e.jsx("input",{value:u,onChange:t=>p(t.target.value),placeholder:a("automation.namePlaceholder"),className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),e.jsx("textarea",{value:h,onChange:t=>b(t.target.value),placeholder:a("automation.instructionsPlaceholder"),rows:3,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue resize-none"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i,onChange:t=>g(t.target.value),placeholder:a("automation.cronPlaceholder"),className:"flex-1 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:async()=>{await N({name:u,instructions:h,schedule:{kind:"cron",cron:i}})&&(p(""),b(""),x(!1))},className:"px-4 py-2 rounded-lg bg-accent-blue text-white text-sm font-medium hover:bg-accent-blue/80",children:a("automation.create")})]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:[["0 9 * * *",a("automation.cronDaily9")],["0 9 * * 1-5",a("automation.cronWeekday9")],["*/30 * * * *",a("automation.cronEvery30Min")]].map(([t,s])=>e.jsxs("button",{onClick:()=>g(t),className:`px-2 py-1 rounded text-xs ${i===t?"bg-accent-blue/20 text-accent-blue":"bg-dark-hover text-dark-muted hover:text-dark-text"}`,children:[s," (",t,")"]},t))})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2",children:[r.length===0&&e.jsx("p",{className:"text-dark-muted text-center py-8",children:a("automation.empty")}),r.map(t=>e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface",children:[e.jsxs("div",{className:"flex items-center justify-between p-3",children:[e.jsxs("button",{onClick:()=>void R(t.id),className:"flex items-center gap-2 min-w-0 text-left",children:[e.jsx(v,{size:16,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"font-medium text-sm truncate",children:t.name}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded shrink-0 ${t.status==="enabled"?"bg-accent-green/20 text-accent-green":"bg-dark-hover text-dark-muted"}`,children:t.status})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("span",{className:"text-xs text-dark-muted hidden lg:inline mr-1",children:[t.schedule.kind==="cron"?t.schedule.cron:t.schedule.fireAt,t.nextRunAt?` · ${new Date(t.nextRunAt).toLocaleString()}`:""]}),e.jsx("button",{onClick:()=>void w(t.id,t.status!=="enabled"),className:"p-1.5 rounded-lg hover:bg-dark-hover text-dark-muted",title:t.status==="enabled"?a("automation.disable"):a("automation.enable"),children:e.jsx(L,{size:15})}),e.jsx("button",{onClick:()=>void C(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-green",title:a("automation.runNow"),children:e.jsx(O,{size:15})}),e.jsx("button",{onClick:()=>void y(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-red",title:a("automation.delete"),children:e.jsx(J,{size:15})})]})]}),m===t.id&&e.jsxs("div",{className:"px-3 pb-3 space-y-3 border-t border-dark-border pt-3",children:[e.jsx("p",{className:"text-xs text-dark-muted whitespace-pre-wrap",children:t.instructions}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold text-dark-muted mb-1 flex items-center gap-1",children:[e.jsx(U,{size:12})," ",a("automation.historyTitle")]}),(d[t.id]||[]).length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:a("automation.noRuns")}),(d[t.id]||[]).slice(0,10).map(s=>e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded ${s.status==="ok"?"bg-accent-green/20 text-accent-green":s.status==="error"?"bg-accent-red/20 text-accent-red":"bg-accent-yellow/20 text-accent-yellow"}`,children:s.status}),e.jsx("span",{className:"text-dark-muted",children:new Date(s.startedAt).toLocaleString()}),e.jsxs("span",{className:"text-dark-muted truncate flex-1",children:["#",s.id.slice(0,8)," · ",s.trigger]})]},s.id))]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-dark-muted mb-1",children:a("automation.permissionsTitle")}),t.permissions.length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:a("automation.permissionsEmpty")}),e.jsx("div",{className:"flex flex-wrap gap-1 mb-1",children:t.permissions.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded bg-accent-blue/10 text-accent-blue text-xs",children:[s,e.jsx("button",{onClick:()=>void E(t.id,s),className:"hover:text-accent-red",children:e.jsx(B,{size:12})})]},s))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:f,onChange:s=>j(s.target.value),placeholder:a("automation.permissionPlaceholder"),className:"flex-1 px-2 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-xs focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:()=>void z(t.id),className:"px-3 py-1.5 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-xs",children:a("automation.add")})]})]})]})]},t.id))]})]})}export{Q as AutomationView};
@@ -1,8 +0,0 @@
1
- import{j as a}from"./markdown-DEtuzEyz.js";import{a as I,bq as ft,aJ as gt,aI as mt,ax as kt,aa as ne,A as vt,br as Be,aE as xt,l as Et,g as Bt,h as Tt}from"./icons-f1hlMKvD.js";import{u as D,a7 as Te,a8 as G,a9 as W,aa as Q,M as St,a as Me,t as re}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";const Pe=[{labelKey:"im",types:["wechat","feishu","dingtalk"]},{labelKey:"international",types:["telegram","discord","slack","signal","whatsapp"]},{labelKey:"eastAsia",types:["line","qqbot"]},{labelKey:"collaboration",types:["matrix","mattermost","msteams","googlechat"]},{labelKey:"classic",types:["irc","imessage","sms"]},{labelKey:"other",types:["nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser"]},{labelKey:"builtin",types:["clickclack","raft","qa-channel"]}];function Rt(){const{t:n}=D(),{channels:i,availableTypes:s,typesLoaded:t,selectedType:e,selectType:r,loadTypes:o}=Te();I.useEffect(()=>{o()},[o]);const c=I.useMemo(()=>{if(s.length===0)return[];const x=new Set(s),h=Pe.map(y=>({...y,types:y.types.filter(A=>x.has(A))})).filter(y=>y.types.length>0),d=new Set(Pe.flatMap(y=>y.types)),p=s.filter(y=>!d.has(y));return p.length>0?[...h,{labelKey:"plugins",types:p}]:h},[s]),l=I.useMemo(()=>{const x=new Map;for(const h of i){const d=x.get(h.type)??{count:0,connected:0};x.set(h.type,{count:d.count+1,connected:d.connected+(h.connected?1:0)})}return x},[i]),u=s.length>0,g=I.useMemo(()=>u?i.filter(x=>s.includes(x.type)):[],[u,i,s]);return a.jsxs("div",{className:"flex flex-col h-full min-h-0 border-r border-dark-border bg-dark-surface",children:[a.jsxs("div",{className:"shrink-0 px-4 py-3 border-b border-dark-border",children:[a.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-dark-muted",children:n("channels.sidebar.title")}),a.jsx("p",{className:"text-[11px] text-dark-muted mt-0.5",children:g.length>0?n("channels.sidebar.configuredCount",{n:g.length}):n(u?"channels.sidebar.clickToConfigure":"channels.sidebar.emptyHint")})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar",children:[t&&!u&&a.jsxs("div",{className:"px-4 py-10 text-center",children:[a.jsx("p",{className:"text-xs text-dark-muted",children:n("channels.sidebar.empty")}),a.jsx("p",{className:"text-[11px] text-dark-muted/70 mt-1.5 leading-relaxed",children:n("channels.sidebar.emptyHint")})]}),c.map(x=>{const h=x.types.filter(d=>l.has(d));return h.length===0?null:a.jsxs("div",{children:[a.jsx("div",{className:"sticky top-0 bg-dark-surface/95 backdrop-blur px-4 py-1.5 text-[10px] font-semibold uppercase tracking-wider text-dark-muted/60",children:n(`channels.categories.${x.labelKey}`)}),h.map(d=>{const p=l.get(d);return a.jsx(Le,{label:Q(d),icon:W(d),isSelected:e===d,experimental:G(d),info:p,onClick:()=>r(d)},d)})]},x.labelKey)}),(()=>{const x=c.flatMap(h=>h.types).filter(h=>!l.has(h));return x.length===0?null:a.jsxs("div",{children:[a.jsx("div",{className:"sticky top-0 bg-dark-surface/95 backdrop-blur px-4 py-1.5 text-[10px] font-semibold uppercase tracking-wider text-dark-muted/60",children:n("channels.sidebar.unconfigured")}),x.map(h=>a.jsx(Le,{label:Q(h),icon:W(h),isSelected:e===h,experimental:G(h),onClick:()=>r(h)},h))]})})()]})]})}function Le({label:n,icon:i,isSelected:s,experimental:t,info:e,onClick:r}){const{t:o}=D();return a.jsxs("button",{onClick:r,className:`w-full flex items-center gap-2.5 px-4 py-2.5 text-left transition-colors hover:bg-dark-hover ${s?"bg-accent-blue/10 border-l-2 border-accent-blue":"border-l-2 border-transparent"}`,children:[a.jsx("span",{className:"text-lg shrink-0 w-7 h-7 flex items-center justify-center rounded-md bg-dark-bg",children:i}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:"text-sm font-medium text-dark-text truncate",children:n}),t&&a.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[9px] text-yellow-500 bg-yellow-500/10 px-1 py-0.5 rounded shrink-0",title:o("channels.experimentalTip"),children:[a.jsx(ft,{className:"w-2.5 h-2.5"})," ",o("channels.experimentalShort")]}),e&&a.jsx("span",{className:"text-[10px] text-dark-muted bg-dark-hover px-1.5 py-0.5 rounded shrink-0",children:e.count})]}),a.jsx("div",{className:"flex items-center gap-1 mt-0.5",children:e?e.connected>0?a.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-green-400",children:[a.jsx(gt,{className:"w-3 h-3"}),e.connected===e.count?o("channels.status.connected"):o("channels.sidebar.partialConnected",{connected:e.connected,count:e.count})]}):a.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-dark-muted",children:[a.jsx(mt,{className:"w-3 h-3"}),o("channels.status.disconnected")]}):a.jsx("span",{className:"text-[11px] text-dark-muted",children:o("channels.sidebar.unconfigured")})})]})]})}const z={name:"",type:"wechat",appId:"",appSecret:"",token:"",encodingAESKey:"",enabled:!0};function At(){const{t:n}=D(),{channels:i,selectedType:s,availableTypes:t,create:e,update:r,remove:o,toggle:c,error:l,clearError:u,openQr:g,load:x}=Te(),h=I.useMemo(()=>t.length>0&&!!s&&!t.includes(s),[t,s]),d=I.useMemo(()=>s?i.filter(f=>f.type===s):[],[i,s]),[p,y]=I.useState(""),[A,N]=I.useState(z),[R,B]=I.useState(!1),j=p==="__new__",k=I.useMemo(()=>j?null:d.find(f=>f.id===p)??null,[d,p,j]);I.useEffect(()=>{y(""),N(z),B(!1),u()},[s]),I.useEffect(()=>{s==="wechat"&&d.length===0&&!h&&g(null)},[s,d.length,h,g]),I.useEffect(()=>{k?N({name:k.name,type:k.type,appId:k.appId||"",appSecret:"",token:"",encodingAESKey:k.encodingAESKey||"",enabled:k.enabled}):j&&N(f=>({...f,type:s}))},[p]);const m=(f,T)=>{u(),N(M=>({...M,[f]:T}))},b=f=>{y(f),u()},C=()=>{y("__new__"),N({...z,type:s}),u()},w=()=>{y(""),N(z),u()},S=async()=>{if(!A.name.trim())return;B(!0);const f=k?await r(k.id,A):await e(A);B(!1),f&&(y(""),N(z))},v=async f=>{if(!confirm(n("channels.actions.deleteConfirmShort")))return;await o(f)&&p===f&&(y(""),N(z))},E=(f,T)=>{c(f,T)};return s?a.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[a.jsx("div",{className:"shrink-0 px-6 py-4 border-b border-dark-border",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("span",{className:"text-2xl",children:W(s)}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("h2",{className:"font-semibold text-base text-dark-text",children:Q(s)}),G(s)&&a.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] text-yellow-500 bg-yellow-500/10 px-1.5 py-0.5 rounded",title:n("channels.experimentalTip"),children:[a.jsx(ft,{className:"w-3 h-3"})," ",n("channels.experimentalLabel")]})]}),a.jsx("p",{className:"text-xs text-dark-muted mt-0.5",children:d.length>0?n("channels.instancesCount",{n:d.length}):n("channels.notConfiguredYet")}),G(s)&&a.jsx("p",{className:"text-[10px] text-yellow-600/70 mt-1",children:n("channels.experimentalDesc")})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{onClick:()=>x(),className:"text-xs px-3 py-1.5 rounded-lg border border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:n("channels.actions.refresh")}),a.jsxs("button",{onClick:C,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-lg bg-accent-blue hover:bg-accent-blue/90 text-white transition-colors",children:[a.jsx(ne,{className:"w-3.5 h-3.5"})," ",n("channels.createInstance")]})]})]})}),l&&a.jsxs("div",{className:"shrink-0 mx-6 mt-3 bg-red-500/10 border border-red-500/40 text-red-400 px-3 py-2 rounded-lg text-sm flex justify-between items-center",children:[a.jsx("span",{children:l}),a.jsx("button",{onClick:u,className:"text-red-400 hover:text-red-300",children:a.jsx("span",{className:"w-4 h-4 inline-flex items-center justify-center",children:"×"})})]}),h&&a.jsxs("div",{className:"shrink-0 mx-6 mt-3 flex items-start gap-2 bg-amber-500/10 border border-amber-500/40 text-amber-400 px-3 py-2 rounded-lg text-xs",children:[a.jsx(vt,{className:"w-3.5 h-3.5 mt-0.5 shrink-0"}),a.jsx("span",{children:n("channels.pluginMissingWarning",{name:s==="wechat"?" WeChat Channel":` ${Q(s)}`})})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar p-6",children:[d.length>1&&!j&&a.jsxs("div",{className:"mb-4",children:[a.jsx("label",{className:"block text-xs text-dark-muted mb-1.5",children:n("channels.selectInstance")}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[d.map(f=>a.jsxs("button",{onClick:()=>b(f.id),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs border transition-colors ${p===f.id?"bg-accent-blue/10 border-accent-blue/40 text-accent-blue":"border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,children:[a.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${f.connected?"bg-green-500":"bg-gray-500"}`}),f.name]},f.id)),a.jsxs("button",{onClick:C,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs border border-dashed border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:[a.jsx(ne,{className:"w-3 h-3"})," ",n("channels.createShort")]})]})]}),d.length===0&&p===""&&a.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[a.jsx("div",{className:"text-4xl mb-3",children:W(s)}),a.jsx("p",{className:"text-dark-text font-medium",children:n("channels.emptyWithType",{type:Q(s)})}),a.jsx("p",{className:"text-sm text-dark-muted mt-1 mb-4",children:n(s==="wechat"?"channels.wechatBindHint":"channels.startWithCreate")}),s==="wechat"&&a.jsxs("button",{onClick:()=>g(null),className:"flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 transition-colors mb-3",children:[a.jsx(Be,{className:"w-4 h-4"})," ",n("channels.scanToBind")]}),a.jsxs("button",{onClick:C,className:"flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-accent-blue hover:bg-accent-blue/90 text-white transition-colors",children:[a.jsx(ne,{className:"w-4 h-4"})," ",n("channels.createInstance")]})]}),d.length===1&&p===""&&d[0]&&a.jsx(qe,{channel:d[0],onEdit:()=>b(d[0].id),onDelete:()=>v(d[0].id),onToggle:f=>E(d[0].id,f),onQr:()=>g(d[0])}),d.length>1&&p===""&&a.jsx("div",{className:"space-y-3",children:d.map(f=>a.jsx(qe,{channel:f,onEdit:()=>b(f.id),onDelete:()=>v(f.id),onToggle:T=>E(f.id,T),onQr:()=>g(f)},f.id))}),p!==""&&(j||k)&&a.jsx(It,{form:A,upd:m,saving:R,editing:!!k,channel:k??void 0,onSave:S,onCancel:w,onDelete:k?()=>v(k.id):void 0,onQr:k?()=>g(k):void 0})]})]}):a.jsx("div",{className:"flex-1 flex items-center justify-center",children:a.jsxs("div",{className:"text-center",children:[a.jsx(kt,{className:"w-12 h-12 mx-auto mb-3 text-dark-muted/40"}),a.jsx("p",{className:"text-dark-muted text-sm",children:n("channels.selectTypeHint")})]})})}function qe({channel:n,onEdit:i,onDelete:s,onToggle:t,onQr:e}){const{t:r}=D();return a.jsxs("div",{className:"border border-dark-border rounded-lg bg-dark-surface overflow-hidden",children:[a.jsx("div",{className:"p-5",children:a.jsxs("div",{className:"flex items-start justify-between",children:[a.jsxs("div",{children:[a.jsx("h3",{className:"font-medium text-dark-text",children:n.name}),a.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[a.jsx("span",{className:`flex items-center gap-1 text-xs ${n.connected?"text-green-400":"text-dark-muted"}`,children:n.connected?a.jsxs(a.Fragment,{children:[a.jsx(gt,{className:"w-3 h-3"})," ",r("channels.status.connected")]}):a.jsxs(a.Fragment,{children:[a.jsx(mt,{className:"w-3 h-3"})," ",r("channels.status.disconnected")]})}),a.jsxs("span",{className:"text-xs text-dark-muted",children:["AppID: ",n.appId||"—"]})]})]}),a.jsx("button",{onClick:()=>t(!n.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${n.enabled?"bg-green-600":"bg-gray-600"}`,children:a.jsx("span",{className:`absolute top-0.5 w-4 h-4 bg-white rounded-full transition-all ${n.enabled?"left-[18px]":"left-0.5"}`})})]})}),a.jsxs("div",{className:"flex items-center gap-1 px-5 py-2.5 bg-dark-bg/50 border-t border-dark-border",children:[n.type==="wechat"&&a.jsxs("button",{onClick:e,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-green-400 hover:bg-green-500/10 transition-colors",children:[a.jsx(Be,{className:"w-3.5 h-3.5"})," ",r("channels.actions.qrLogin")]}),a.jsxs("button",{onClick:i,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-accent-blue hover:bg-accent-blue/10 transition-colors",children:[a.jsx("span",{className:"w-3.5 h-3.5 inline-flex items-center justify-center",children:"✎"})," ",r("channels.actions.edit")]}),a.jsxs("button",{onClick:s,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-red-400 hover:bg-red-500/10 transition-colors ml-auto",children:[a.jsx(xt,{className:"w-3.5 h-3.5"})," ",r("channels.actions.delete")]})]})]})}function It({form:n,upd:i,saving:s,editing:t,channel:e,onSave:r,onCancel:o,onDelete:c,onQr:l}){const{t:u}=D();return a.jsxs("div",{className:"border border-dark-border rounded-lg bg-dark-surface overflow-hidden",children:[a.jsx("div",{className:"px-5 py-4 border-b border-dark-border",children:a.jsx("h3",{className:"font-medium text-dark-text",children:u(t?"channels.editConfig":"channels.createConfig")})}),a.jsxs("div",{className:"p-5 space-y-4",children:[a.jsx(_e,{label:u("channels.form.name"),required:!0,children:a.jsx("input",{value:n.name,onChange:g=>i("name",g.target.value),placeholder:u("channels.form.namePlaceholderDev"),className:O})}),a.jsxs(_e,{label:u("channels.form.credentials"),children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:u("channels.form.appId")}),a.jsx("input",{value:n.appId,onChange:g=>i("appId",g.target.value),placeholder:"AppID",className:O})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"AppSecret"}),a.jsx("input",{type:"password",value:n.appSecret,onChange:g=>i("appSecret",g.target.value),placeholder:u(t?"channels.form.leaveBlankUnchanged":"channels.form.appSecretValue"),className:O})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"Token"}),a.jsx("input",{value:n.token,onChange:g=>i("token",g.target.value),placeholder:u(t?"channels.form.leaveBlankUnchanged":"channels.form.tokenCallback"),className:O})]}),n.type==="wechat"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"EncodingAESKey"}),a.jsx("input",{value:n.encodingAESKey,onChange:g=>i("encodingAESKey",g.target.value),placeholder:u("channels.form.optionalShort"),className:O})]})]}),n.type==="wechat"&&a.jsx("p",{className:"text-xs text-dark-muted mt-2",children:u("channels.form.wechatIlinkHint")})]}),a.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-dark-border px-3 py-2.5",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-dark-text",children:u("channels.form.enabled")}),a.jsx("p",{className:"text-xs text-dark-muted",children:u("channels.form.enabledOffHint")})]}),a.jsx("button",{onClick:()=>i("enabled",!n.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${n.enabled?"bg-green-600":"bg-gray-600"}`,children:a.jsx("span",{className:`absolute top-0.5 w-4 h-4 bg-white rounded-full transition-all ${n.enabled?"left-[18px]":"left-0.5"}`})})]}),t&&(e==null?void 0:e.type)==="wechat"&&l&&a.jsxs("button",{onClick:l,className:"w-full flex items-center justify-center gap-2 text-sm bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 px-3 py-2.5 rounded-lg transition-colors",children:[a.jsx(Be,{className:"w-4 h-4"})," ",u("channels.qrLoginReauth")]})]}),a.jsxs("div",{className:"flex items-center justify-between px-5 py-3 bg-dark-bg/50 border-t border-dark-border",children:[a.jsx("div",{children:t&&c&&a.jsxs("button",{onClick:c,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-red-400 hover:bg-red-500/10 transition-colors",children:[a.jsx(xt,{className:"w-3.5 h-3.5"})," ",u("channels.actions.delete")]})}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{onClick:o,className:"px-4 py-2 text-sm text-dark-muted hover:text-dark-text transition-colors",children:u("channels.actions.cancel")}),a.jsxs("button",{onClick:r,disabled:s||!n.name.trim(),className:"flex items-center gap-1.5 px-4 py-2 text-sm bg-accent-blue hover:bg-accent-blue/90 text-white rounded-lg disabled:opacity-50 transition-colors",children:[a.jsx(Et,{className:"w-3.5 h-3.5"}),u(s?"channels.saving":"channels.save")]})]})]})]})}function _e({label:n,required:i,children:s}){return a.jsxs("div",{children:[a.jsxs("label",{className:"block text-xs text-dark-muted mb-1.5",children:[n,i&&a.jsx("span",{className:"text-red-400 ml-0.5",children:"*"})]}),s]})}const O="w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm text-dark-text placeholder-dark-muted/60 focus:outline-none focus:border-accent-blue transition-colors";var V={},se,De;function Mt(){return De||(De=1,se=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),se}var ie={},_={},Ue;function U(){if(Ue)return _;Ue=1;let n;const i=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return _.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return t*4+17},_.getSymbolTotalCodewords=function(t){return i[t]},_.getBCHDigit=function(s){let t=0;for(;s!==0;)t++,s>>>=1;return t},_.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');n=t},_.isKanjiModeEnabled=function(){return typeof n<"u"},_.toSJIS=function(t){return n(t)},_}var ae={},Fe;function Se(){return Fe||(Fe=1,(function(n){n.L={bit:1},n.M={bit:0},n.Q={bit:3},n.H={bit:2};function i(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"l":case"low":return n.L;case"m":case"medium":return n.M;case"q":case"quartile":return n.Q;case"h":case"high":return n.H;default:throw new Error("Unknown EC Level: "+s)}}n.isValid=function(t){return t&&typeof t.bit<"u"&&t.bit>=0&&t.bit<4},n.from=function(t,e){if(n.isValid(t))return t;try{return i(t)}catch{return e}}})(ae)),ae}var oe,Ke;function Pt(){if(Ke)return oe;Ke=1;function n(){this.buffer=[],this.length=0}return n.prototype={get:function(i){const s=Math.floor(i/8);return(this.buffer[s]>>>7-i%8&1)===1},put:function(i,s){for(let t=0;t<s;t++)this.putBit((i>>>s-t-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(i){const s=Math.floor(this.length/8);this.buffer.length<=s&&this.buffer.push(0),i&&(this.buffer[s]|=128>>>this.length%8),this.length++}},oe=n,oe}var le,ze;function Lt(){if(ze)return le;ze=1;function n(i){if(!i||i<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=i,this.data=new Uint8Array(i*i),this.reservedBit=new Uint8Array(i*i)}return n.prototype.set=function(i,s,t,e){const r=i*this.size+s;this.data[r]=t,e&&(this.reservedBit[r]=!0)},n.prototype.get=function(i,s){return this.data[i*this.size+s]},n.prototype.xor=function(i,s,t){this.data[i*this.size+s]^=t},n.prototype.isReserved=function(i,s){return this.reservedBit[i*this.size+s]},le=n,le}var ce={},Ve;function qt(){return Ve||(Ve=1,(function(n){const i=U().getSymbolSize;n.getRowColCoords=function(t){if(t===1)return[];const e=Math.floor(t/7)+2,r=i(t),o=r===145?26:Math.ceil((r-13)/(2*e-2))*2,c=[r-7];for(let l=1;l<e-1;l++)c[l]=c[l-1]-o;return c.push(6),c.reverse()},n.getPositions=function(t){const e=[],r=n.getRowColCoords(t),o=r.length;for(let c=0;c<o;c++)for(let l=0;l<o;l++)c===0&&l===0||c===0&&l===o-1||c===o-1&&l===0||e.push([r[c],r[l]]);return e}})(ce)),ce}var de={},He;function _t(){if(He)return de;He=1;const n=U().getSymbolSize,i=7;return de.getPositions=function(t){const e=n(t);return[[0,0],[e-i,0],[0,e-i]]},de}var ue={},Oe;function Dt(){return Oe||(Oe=1,(function(n){n.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const i={N1:3,N2:3,N3:40,N4:10};n.isValid=function(e){return e!=null&&e!==""&&!isNaN(e)&&e>=0&&e<=7},n.from=function(e){return n.isValid(e)?parseInt(e,10):void 0},n.getPenaltyN1=function(e){const r=e.size;let o=0,c=0,l=0,u=null,g=null;for(let x=0;x<r;x++){c=l=0,u=g=null;for(let h=0;h<r;h++){let d=e.get(x,h);d===u?c++:(c>=5&&(o+=i.N1+(c-5)),u=d,c=1),d=e.get(h,x),d===g?l++:(l>=5&&(o+=i.N1+(l-5)),g=d,l=1)}c>=5&&(o+=i.N1+(c-5)),l>=5&&(o+=i.N1+(l-5))}return o},n.getPenaltyN2=function(e){const r=e.size;let o=0;for(let c=0;c<r-1;c++)for(let l=0;l<r-1;l++){const u=e.get(c,l)+e.get(c,l+1)+e.get(c+1,l)+e.get(c+1,l+1);(u===4||u===0)&&o++}return o*i.N2},n.getPenaltyN3=function(e){const r=e.size;let o=0,c=0,l=0;for(let u=0;u<r;u++){c=l=0;for(let g=0;g<r;g++)c=c<<1&2047|e.get(u,g),g>=10&&(c===1488||c===93)&&o++,l=l<<1&2047|e.get(g,u),g>=10&&(l===1488||l===93)&&o++}return o*i.N3},n.getPenaltyN4=function(e){let r=0;const o=e.data.length;for(let l=0;l<o;l++)r+=e.data[l];return Math.abs(Math.ceil(r*100/o/5)-10)*i.N4};function s(t,e,r){switch(t){case n.Patterns.PATTERN000:return(e+r)%2===0;case n.Patterns.PATTERN001:return e%2===0;case n.Patterns.PATTERN010:return r%3===0;case n.Patterns.PATTERN011:return(e+r)%3===0;case n.Patterns.PATTERN100:return(Math.floor(e/2)+Math.floor(r/3))%2===0;case n.Patterns.PATTERN101:return e*r%2+e*r%3===0;case n.Patterns.PATTERN110:return(e*r%2+e*r%3)%2===0;case n.Patterns.PATTERN111:return(e*r%3+(e+r)%2)%2===0;default:throw new Error("bad maskPattern:"+t)}}n.applyMask=function(e,r){const o=r.size;for(let c=0;c<o;c++)for(let l=0;l<o;l++)r.isReserved(l,c)||r.xor(l,c,s(e,l,c))},n.getBestMask=function(e,r){const o=Object.keys(n.Patterns).length;let c=0,l=1/0;for(let u=0;u<o;u++){r(u),n.applyMask(u,e);const g=n.getPenaltyN1(e)+n.getPenaltyN2(e)+n.getPenaltyN3(e)+n.getPenaltyN4(e);n.applyMask(u,e),g<l&&(l=g,c=u)}return c}})(ue)),ue}var $={},Je;function pt(){if(Je)return $;Je=1;const n=Se(),i=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],s=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return $.getBlocksCount=function(e,r){switch(r){case n.L:return i[(e-1)*4+0];case n.M:return i[(e-1)*4+1];case n.Q:return i[(e-1)*4+2];case n.H:return i[(e-1)*4+3];default:return}},$.getTotalCodewordsCount=function(e,r){switch(r){case n.L:return s[(e-1)*4+0];case n.M:return s[(e-1)*4+1];case n.Q:return s[(e-1)*4+2];case n.H:return s[(e-1)*4+3];default:return}},$}var he={},J={},Qe;function Ut(){if(Qe)return J;Qe=1;const n=new Uint8Array(512),i=new Uint8Array(256);return(function(){let t=1;for(let e=0;e<255;e++)n[e]=t,i[t]=e,t<<=1,t&256&&(t^=285);for(let e=255;e<512;e++)n[e]=n[e-255]})(),J.log=function(t){if(t<1)throw new Error("log("+t+")");return i[t]},J.exp=function(t){return n[t]},J.mul=function(t,e){return t===0||e===0?0:n[i[t]+i[e]]},J}var Ye;function Ft(){return Ye||(Ye=1,(function(n){const i=Ut();n.mul=function(t,e){const r=new Uint8Array(t.length+e.length-1);for(let o=0;o<t.length;o++)for(let c=0;c<e.length;c++)r[o+c]^=i.mul(t[o],e[c]);return r},n.mod=function(t,e){let r=new Uint8Array(t);for(;r.length-e.length>=0;){const o=r[0];for(let l=0;l<e.length;l++)r[l]^=i.mul(e[l],o);let c=0;for(;c<r.length&&r[c]===0;)c++;r=r.slice(c)}return r},n.generateECPolynomial=function(t){let e=new Uint8Array([1]);for(let r=0;r<t;r++)e=n.mul(e,new Uint8Array([1,i.exp(r)]));return e}})(he)),he}var fe,$e;function Kt(){if($e)return fe;$e=1;const n=Ft();function i(s){this.genPoly=void 0,this.degree=s,this.degree&&this.initialize(this.degree)}return i.prototype.initialize=function(t){this.degree=t,this.genPoly=n.generateECPolynomial(this.degree)},i.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");const e=new Uint8Array(t.length+this.degree);e.set(t);const r=n.mod(e,this.genPoly),o=this.degree-r.length;if(o>0){const c=new Uint8Array(this.degree);return c.set(r,o),c}return r},fe=i,fe}var ge={},me={},xe={},Ge;function bt(){return Ge||(Ge=1,xe.isValid=function(i){return!isNaN(i)&&i>=1&&i<=40}),xe}var P={},We;function wt(){if(We)return P;We=1;const n="[0-9]+",i="[A-Z $%*+\\-./:]+";let s="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";s=s.replace(/u/g,"\\u");const t="(?:(?![A-Z0-9 $%*+\\-./:]|"+s+`)(?:.|[\r
2
- ]))+`;P.KANJI=new RegExp(s,"g"),P.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),P.BYTE=new RegExp(t,"g"),P.NUMERIC=new RegExp(n,"g"),P.ALPHANUMERIC=new RegExp(i,"g");const e=new RegExp("^"+s+"$"),r=new RegExp("^"+n+"$"),o=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return P.testKanji=function(l){return e.test(l)},P.testNumeric=function(l){return r.test(l)},P.testAlphanumeric=function(l){return o.test(l)},P}var Xe;function F(){return Xe||(Xe=1,(function(n){const i=bt(),s=wt();n.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},n.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},n.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},n.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},n.MIXED={bit:-1},n.getCharCountIndicator=function(r,o){if(!r.ccBits)throw new Error("Invalid mode: "+r);if(!i.isValid(o))throw new Error("Invalid version: "+o);return o>=1&&o<10?r.ccBits[0]:o<27?r.ccBits[1]:r.ccBits[2]},n.getBestModeForData=function(r){return s.testNumeric(r)?n.NUMERIC:s.testAlphanumeric(r)?n.ALPHANUMERIC:s.testKanji(r)?n.KANJI:n.BYTE},n.toString=function(r){if(r&&r.id)return r.id;throw new Error("Invalid mode")},n.isValid=function(r){return r&&r.bit&&r.ccBits};function t(e){if(typeof e!="string")throw new Error("Param is not a string");switch(e.toLowerCase()){case"numeric":return n.NUMERIC;case"alphanumeric":return n.ALPHANUMERIC;case"kanji":return n.KANJI;case"byte":return n.BYTE;default:throw new Error("Unknown mode: "+e)}}n.from=function(r,o){if(n.isValid(r))return r;try{return t(r)}catch{return o}}})(me)),me}var Ze;function zt(){return Ze||(Ze=1,(function(n){const i=U(),s=pt(),t=Se(),e=F(),r=bt(),o=7973,c=i.getBCHDigit(o);function l(h,d,p){for(let y=1;y<=40;y++)if(d<=n.getCapacity(y,p,h))return y}function u(h,d){return e.getCharCountIndicator(h,d)+4}function g(h,d){let p=0;return h.forEach(function(y){const A=u(y.mode,d);p+=A+y.getBitsLength()}),p}function x(h,d){for(let p=1;p<=40;p++)if(g(h,p)<=n.getCapacity(p,d,e.MIXED))return p}n.from=function(d,p){return r.isValid(d)?parseInt(d,10):p},n.getCapacity=function(d,p,y){if(!r.isValid(d))throw new Error("Invalid QR Code version");typeof y>"u"&&(y=e.BYTE);const A=i.getSymbolTotalCodewords(d),N=s.getTotalCodewordsCount(d,p),R=(A-N)*8;if(y===e.MIXED)return R;const B=R-u(y,d);switch(y){case e.NUMERIC:return Math.floor(B/10*3);case e.ALPHANUMERIC:return Math.floor(B/11*2);case e.KANJI:return Math.floor(B/13);case e.BYTE:default:return Math.floor(B/8)}},n.getBestVersionForData=function(d,p){let y;const A=t.from(p,t.M);if(Array.isArray(d)){if(d.length>1)return x(d,A);if(d.length===0)return 1;y=d[0]}else y=d;return l(y.mode,y.getLength(),A)},n.getEncodedBits=function(d){if(!r.isValid(d)||d<7)throw new Error("Invalid QR Code version");let p=d<<12;for(;i.getBCHDigit(p)-c>=0;)p^=o<<i.getBCHDigit(p)-c;return d<<12|p}})(ge)),ge}var pe={},et;function Vt(){if(et)return pe;et=1;const n=U(),i=1335,s=21522,t=n.getBCHDigit(i);return pe.getEncodedBits=function(r,o){const c=r.bit<<3|o;let l=c<<10;for(;n.getBCHDigit(l)-t>=0;)l^=i<<n.getBCHDigit(l)-t;return(c<<10|l)^s},pe}var be={},we,tt;function Ht(){if(tt)return we;tt=1;const n=F();function i(s){this.mode=n.NUMERIC,this.data=s.toString()}return i.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(t){let e,r,o;for(e=0;e+3<=this.data.length;e+=3)r=this.data.substr(e,3),o=parseInt(r,10),t.put(o,10);const c=this.data.length-e;c>0&&(r=this.data.substr(e),o=parseInt(r,10),t.put(o,c*3+1))},we=i,we}var ye,nt;function Ot(){if(nt)return ye;nt=1;const n=F(),i=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function s(t){this.mode=n.ALPHANUMERIC,this.data=t}return s.getBitsLength=function(e){return 11*Math.floor(e/2)+6*(e%2)},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(e){let r;for(r=0;r+2<=this.data.length;r+=2){let o=i.indexOf(this.data[r])*45;o+=i.indexOf(this.data[r+1]),e.put(o,11)}this.data.length%2&&e.put(i.indexOf(this.data[r]),6)},ye=s,ye}var Ne,rt;function Jt(){if(rt)return Ne;rt=1;const n=F();function i(s){this.mode=n.BYTE,typeof s=="string"?this.data=new TextEncoder().encode(s):this.data=new Uint8Array(s)}return i.getBitsLength=function(t){return t*8},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(s){for(let t=0,e=this.data.length;t<e;t++)s.put(this.data[t],8)},Ne=i,Ne}var Ce,st;function Qt(){if(st)return Ce;st=1;const n=F(),i=U();function s(t){this.mode=n.KANJI,this.data=t}return s.getBitsLength=function(e){return e*13},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(t){let e;for(e=0;e<this.data.length;e++){let r=i.toSJIS(this.data[e]);if(r>=33088&&r<=40956)r-=33088;else if(r>=57408&&r<=60351)r-=49472;else throw new Error("Invalid SJIS character: "+this.data[e]+`
3
- Make sure your charset is UTF-8`);r=(r>>>8&255)*192+(r&255),t.put(r,13)}},Ce=s,Ce}var je={exports:{}},it;function Yt(){return it||(it=1,(function(n){var i={single_source_shortest_paths:function(s,t,e){var r={},o={};o[t]=0;var c=i.PriorityQueue.make();c.push(t,0);for(var l,u,g,x,h,d,p,y,A;!c.empty();){l=c.pop(),u=l.value,x=l.cost,h=s[u]||{};for(g in h)h.hasOwnProperty(g)&&(d=h[g],p=x+d,y=o[g],A=typeof o[g]>"u",(A||y>p)&&(o[g]=p,c.push(g,p),r[g]=u))}if(typeof e<"u"&&typeof o[e]>"u"){var N=["Could not find a path from ",t," to ",e,"."].join("");throw new Error(N)}return r},extract_shortest_path_from_predecessor_list:function(s,t){for(var e=[],r=t;r;)e.push(r),s[r],r=s[r];return e.reverse(),e},find_path:function(s,t,e){var r=i.single_source_shortest_paths(s,t,e);return i.extract_shortest_path_from_predecessor_list(r,e)},PriorityQueue:{make:function(s){var t=i.PriorityQueue,e={},r;s=s||{};for(r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e.queue=[],e.sorter=s.sorter||t.default_sorter,e},default_sorter:function(s,t){return s.cost-t.cost},push:function(s,t){var e={value:s,cost:t};this.queue.push(e),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};n.exports=i})(je)),je.exports}var at;function $t(){return at||(at=1,(function(n){const i=F(),s=Ht(),t=Ot(),e=Jt(),r=Qt(),o=wt(),c=U(),l=Yt();function u(N){return unescape(encodeURIComponent(N)).length}function g(N,R,B){const j=[];let k;for(;(k=N.exec(B))!==null;)j.push({data:k[0],index:k.index,mode:R,length:k[0].length});return j}function x(N){const R=g(o.NUMERIC,i.NUMERIC,N),B=g(o.ALPHANUMERIC,i.ALPHANUMERIC,N);let j,k;return c.isKanjiModeEnabled()?(j=g(o.BYTE,i.BYTE,N),k=g(o.KANJI,i.KANJI,N)):(j=g(o.BYTE_KANJI,i.BYTE,N),k=[]),R.concat(B,j,k).sort(function(b,C){return b.index-C.index}).map(function(b){return{data:b.data,mode:b.mode,length:b.length}})}function h(N,R){switch(R){case i.NUMERIC:return s.getBitsLength(N);case i.ALPHANUMERIC:return t.getBitsLength(N);case i.KANJI:return r.getBitsLength(N);case i.BYTE:return e.getBitsLength(N)}}function d(N){return N.reduce(function(R,B){const j=R.length-1>=0?R[R.length-1]:null;return j&&j.mode===B.mode?(R[R.length-1].data+=B.data,R):(R.push(B),R)},[])}function p(N){const R=[];for(let B=0;B<N.length;B++){const j=N[B];switch(j.mode){case i.NUMERIC:R.push([j,{data:j.data,mode:i.ALPHANUMERIC,length:j.length},{data:j.data,mode:i.BYTE,length:j.length}]);break;case i.ALPHANUMERIC:R.push([j,{data:j.data,mode:i.BYTE,length:j.length}]);break;case i.KANJI:R.push([j,{data:j.data,mode:i.BYTE,length:u(j.data)}]);break;case i.BYTE:R.push([{data:j.data,mode:i.BYTE,length:u(j.data)}])}}return R}function y(N,R){const B={},j={start:{}};let k=["start"];for(let m=0;m<N.length;m++){const b=N[m],C=[];for(let w=0;w<b.length;w++){const S=b[w],v=""+m+w;C.push(v),B[v]={node:S,lastCount:0},j[v]={};for(let E=0;E<k.length;E++){const f=k[E];B[f]&&B[f].node.mode===S.mode?(j[f][v]=h(B[f].lastCount+S.length,S.mode)-h(B[f].lastCount,S.mode),B[f].lastCount+=S.length):(B[f]&&(B[f].lastCount=S.length),j[f][v]=h(S.length,S.mode)+4+i.getCharCountIndicator(S.mode,R))}}k=C}for(let m=0;m<k.length;m++)j[k[m]].end=0;return{map:j,table:B}}function A(N,R){let B;const j=i.getBestModeForData(N);if(B=i.from(R,j),B!==i.BYTE&&B.bit<j.bit)throw new Error('"'+N+'" cannot be encoded with mode '+i.toString(B)+`.
4
- Suggested mode is: `+i.toString(j));switch(B===i.KANJI&&!c.isKanjiModeEnabled()&&(B=i.BYTE),B){case i.NUMERIC:return new s(N);case i.ALPHANUMERIC:return new t(N);case i.KANJI:return new r(N);case i.BYTE:return new e(N)}}n.fromArray=function(R){return R.reduce(function(B,j){return typeof j=="string"?B.push(A(j,null)):j.data&&B.push(A(j.data,j.mode)),B},[])},n.fromString=function(R,B){const j=x(R,c.isKanjiModeEnabled()),k=p(j),m=y(k,B),b=l.find_path(m.map,"start","end"),C=[];for(let w=1;w<b.length-1;w++)C.push(m.table[b[w]].node);return n.fromArray(d(C))},n.rawSplit=function(R){return n.fromArray(x(R,c.isKanjiModeEnabled()))}})(be)),be}var ot;function Gt(){if(ot)return ie;ot=1;const n=U(),i=Se(),s=Pt(),t=Lt(),e=qt(),r=_t(),o=Dt(),c=pt(),l=Kt(),u=zt(),g=Vt(),x=F(),h=$t();function d(m,b){const C=m.size,w=r.getPositions(b);for(let S=0;S<w.length;S++){const v=w[S][0],E=w[S][1];for(let f=-1;f<=7;f++)if(!(v+f<=-1||C<=v+f))for(let T=-1;T<=7;T++)E+T<=-1||C<=E+T||(f>=0&&f<=6&&(T===0||T===6)||T>=0&&T<=6&&(f===0||f===6)||f>=2&&f<=4&&T>=2&&T<=4?m.set(v+f,E+T,!0,!0):m.set(v+f,E+T,!1,!0))}}function p(m){const b=m.size;for(let C=8;C<b-8;C++){const w=C%2===0;m.set(C,6,w,!0),m.set(6,C,w,!0)}}function y(m,b){const C=e.getPositions(b);for(let w=0;w<C.length;w++){const S=C[w][0],v=C[w][1];for(let E=-2;E<=2;E++)for(let f=-2;f<=2;f++)E===-2||E===2||f===-2||f===2||E===0&&f===0?m.set(S+E,v+f,!0,!0):m.set(S+E,v+f,!1,!0)}}function A(m,b){const C=m.size,w=u.getEncodedBits(b);let S,v,E;for(let f=0;f<18;f++)S=Math.floor(f/3),v=f%3+C-8-3,E=(w>>f&1)===1,m.set(S,v,E,!0),m.set(v,S,E,!0)}function N(m,b,C){const w=m.size,S=g.getEncodedBits(b,C);let v,E;for(v=0;v<15;v++)E=(S>>v&1)===1,v<6?m.set(v,8,E,!0):v<8?m.set(v+1,8,E,!0):m.set(w-15+v,8,E,!0),v<8?m.set(8,w-v-1,E,!0):v<9?m.set(8,15-v-1+1,E,!0):m.set(8,15-v-1,E,!0);m.set(w-8,8,1,!0)}function R(m,b){const C=m.size;let w=-1,S=C-1,v=7,E=0;for(let f=C-1;f>0;f-=2)for(f===6&&f--;;){for(let T=0;T<2;T++)if(!m.isReserved(S,f-T)){let M=!1;E<b.length&&(M=(b[E]>>>v&1)===1),m.set(S,f-T,M),v--,v===-1&&(E++,v=7)}if(S+=w,S<0||C<=S){S-=w,w=-w;break}}}function B(m,b,C){const w=new s;C.forEach(function(T){w.put(T.mode.bit,4),w.put(T.getLength(),x.getCharCountIndicator(T.mode,m)),T.write(w)});const S=n.getSymbolTotalCodewords(m),v=c.getTotalCodewordsCount(m,b),E=(S-v)*8;for(w.getLengthInBits()+4<=E&&w.put(0,4);w.getLengthInBits()%8!==0;)w.putBit(0);const f=(E-w.getLengthInBits())/8;for(let T=0;T<f;T++)w.put(T%2?17:236,8);return j(w,m,b)}function j(m,b,C){const w=n.getSymbolTotalCodewords(b),S=c.getTotalCodewordsCount(b,C),v=w-S,E=c.getBlocksCount(b,C),f=w%E,T=E-f,M=Math.floor(w/E),H=Math.floor(v/E),Nt=H+1,Re=M-H,Ct=new l(Re);let X=0;const Y=new Array(E),Ae=new Array(E);let Z=0;const jt=new Uint8Array(m.buffer);for(let K=0;K<E;K++){const te=K<T?H:Nt;Y[K]=jt.slice(X,X+te),Ae[K]=Ct.encode(Y[K]),X+=te,Z=Math.max(Z,te)}const ee=new Uint8Array(w);let Ie=0,L,q;for(L=0;L<Z;L++)for(q=0;q<E;q++)L<Y[q].length&&(ee[Ie++]=Y[q][L]);for(L=0;L<Re;L++)for(q=0;q<E;q++)ee[Ie++]=Ae[q][L];return ee}function k(m,b,C,w){let S;if(Array.isArray(m))S=h.fromArray(m);else if(typeof m=="string"){let M=b;if(!M){const H=h.rawSplit(m);M=u.getBestVersionForData(H,C)}S=h.fromString(m,M||40)}else throw new Error("Invalid data");const v=u.getBestVersionForData(S,C);if(!v)throw new Error("The amount of data is too big to be stored in a QR Code");if(!b)b=v;else if(b<v)throw new Error(`
5
- The chosen QR Code version cannot contain this amount of data.
6
- Minimum version required to store current data is: `+v+`.
7
- `);const E=B(b,C,S),f=n.getSymbolSize(b),T=new t(f);return d(T,b),p(T),y(T,b),N(T,C,0),b>=7&&A(T,b),R(T,E),isNaN(w)&&(w=o.getBestMask(T,N.bind(null,T,C))),o.applyMask(w,T),N(T,C,w),{modules:T,version:b,errorCorrectionLevel:C,maskPattern:w,segments:S}}return ie.create=function(b,C){if(typeof b>"u"||b==="")throw new Error("No input text");let w=i.M,S,v;return typeof C<"u"&&(w=i.from(C.errorCorrectionLevel,i.M),S=u.from(C.version),v=o.from(C.maskPattern),C.toSJISFunc&&n.setToSJISFunction(C.toSJISFunc)),k(b,S,w,v)},ie}var ke={},ve={},lt;function yt(){return lt||(lt=1,(function(n){function i(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let t=s.slice().replace("#","").split("");if(t.length<3||t.length===5||t.length>8)throw new Error("Invalid hex color: "+s);(t.length===3||t.length===4)&&(t=Array.prototype.concat.apply([],t.map(function(r){return[r,r]}))),t.length===6&&t.push("F","F");const e=parseInt(t.join(""),16);return{r:e>>24&255,g:e>>16&255,b:e>>8&255,a:e&255,hex:"#"+t.slice(0,6).join("")}}n.getOptions=function(t){t||(t={}),t.color||(t.color={});const e=typeof t.margin>"u"||t.margin===null||t.margin<0?4:t.margin,r=t.width&&t.width>=21?t.width:void 0,o=t.scale||4;return{width:r,scale:r?4:o,margin:e,color:{dark:i(t.color.dark||"#000000ff"),light:i(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}},n.getScale=function(t,e){return e.width&&e.width>=t+e.margin*2?e.width/(t+e.margin*2):e.scale},n.getImageWidth=function(t,e){const r=n.getScale(t,e);return Math.floor((t+e.margin*2)*r)},n.qrToImageData=function(t,e,r){const o=e.modules.size,c=e.modules.data,l=n.getScale(o,r),u=Math.floor((o+r.margin*2)*l),g=r.margin*l,x=[r.color.light,r.color.dark];for(let h=0;h<u;h++)for(let d=0;d<u;d++){let p=(h*u+d)*4,y=r.color.light;if(h>=g&&d>=g&&h<u-g&&d<u-g){const A=Math.floor((h-g)/l),N=Math.floor((d-g)/l);y=x[c[A*o+N]?1:0]}t[p++]=y.r,t[p++]=y.g,t[p++]=y.b,t[p]=y.a}}})(ve)),ve}var ct;function Wt(){return ct||(ct=1,(function(n){const i=yt();function s(e,r,o){e.clearRect(0,0,r.width,r.height),r.style||(r.style={}),r.height=o,r.width=o,r.style.height=o+"px",r.style.width=o+"px"}function t(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}n.render=function(r,o,c){let l=c,u=o;typeof l>"u"&&(!o||!o.getContext)&&(l=o,o=void 0),o||(u=t()),l=i.getOptions(l);const g=i.getImageWidth(r.modules.size,l),x=u.getContext("2d"),h=x.createImageData(g,g);return i.qrToImageData(h.data,r,l),s(x,u,g),x.putImageData(h,0,0),u},n.renderToDataURL=function(r,o,c){let l=c;typeof l>"u"&&(!o||!o.getContext)&&(l=o,o=void 0),l||(l={});const u=n.render(r,o,l),g=l.type||"image/png",x=l.rendererOpts||{};return u.toDataURL(g,x.quality)}})(ke)),ke}var Ee={},dt;function Xt(){if(dt)return Ee;dt=1;const n=yt();function i(e,r){const o=e.a/255,c=r+'="'+e.hex+'"';return o<1?c+" "+r+'-opacity="'+o.toFixed(2).slice(1)+'"':c}function s(e,r,o){let c=e+r;return typeof o<"u"&&(c+=" "+o),c}function t(e,r,o){let c="",l=0,u=!1,g=0;for(let x=0;x<e.length;x++){const h=Math.floor(x%r),d=Math.floor(x/r);!h&&!u&&(u=!0),e[x]?(g++,x>0&&h>0&&e[x-1]||(c+=u?s("M",h+o,.5+d+o):s("m",l,0),l=0,u=!1),h+1<r&&e[x+1]||(c+=s("h",g),g=0)):l++}return c}return Ee.render=function(r,o,c){const l=n.getOptions(o),u=r.modules.size,g=r.modules.data,x=u+l.margin*2,h=l.color.light.a?"<path "+i(l.color.light,"fill")+' d="M0 0h'+x+"v"+x+'H0z"/>':"",d="<path "+i(l.color.dark,"stroke")+' d="'+t(g,u,l.margin)+'"/>',p='viewBox="0 0 '+x+" "+x+'"',A='<svg xmlns="http://www.w3.org/2000/svg" '+(l.width?'width="'+l.width+'" height="'+l.width+'" ':"")+p+' shape-rendering="crispEdges">'+h+d+`</svg>
8
- `;return typeof c=="function"&&c(null,A),A},Ee}var ut;function Zt(){if(ut)return V;ut=1;const n=Mt(),i=Gt(),s=Wt(),t=Xt();function e(r,o,c,l,u){const g=[].slice.call(arguments,1),x=g.length,h=typeof g[x-1]=="function";if(!h&&!n())throw new Error("Callback required as last argument");if(h){if(x<2)throw new Error("Too few arguments provided");x===2?(u=c,c=o,o=l=void 0):x===3&&(o.getContext&&typeof u>"u"?(u=l,l=void 0):(u=l,l=c,c=o,o=void 0))}else{if(x<1)throw new Error("Too few arguments provided");return x===1?(c=o,o=l=void 0):x===2&&!o.getContext&&(l=c,c=o,o=void 0),new Promise(function(d,p){try{const y=i.create(c,l);d(r(y,o,l))}catch(y){p(y)}})}try{const d=i.create(c,l);u(null,r(d,o,l))}catch(d){u(d)}}return V.create=i.create,V.toCanvas=e.bind(null,s.render),V.toDataURL=e.bind(null,s.renderToDataURL),V.toString=e.bind(null,function(r,o,c){return t.render(r,c)}),V}var en=Zt();const tn=Bt(en),nn=2e3,ht=5;function rn({channel:n,onClose:i}){const{t:s}=D(),[t,e]=I.useState("loading"),[r,o]=I.useState(null),[c,l]=I.useState(null),[u,g]=I.useState(""),x=I.useRef(null),h=I.useRef(0),d=I.useRef(null),p=I.useRef(!1),y=()=>{d.current&&(clearTimeout(d.current),d.current=null),p.current=!0},A=async k=>{if(x.current)try{await tn.toCanvas(x.current,k,{width:240,margin:2,color:{dark:"#000000ff",light:"#ffffffff"}})}catch(m){console.warn("[WechatQr] Canvas QR generation failed, falling back to URL:",m)}},N=async()=>{if(!(p.current||!c))try{const k=await Me.channels.weixin.bindStatus(c),m=(k==null?void 0:k.data)??k,b=(m==null?void 0:m.status)??"";if(h.current=0,b==="confirmed"){e("confirmed"),re.success(n?s("channels.toastReauthSuccess",{name:n.name}):s("channels.toastBindSuccess")),setTimeout(i,2400);return}if(b==="scaned")e("scanned");else if(b==="expired"){e("expired");return}p.current||(d.current=setTimeout(N,nn))}catch(k){if(h.current++,console.warn("[WechatQr] poll error ("+h.current+"/"+ht+")",k),h.current>=ht)e("error"),g(s("channels.pollFailedRefresh")),re.error(s("channels.pollFailedToast"));else if(!p.current){const m=Math.min(1e3*Math.pow(2,h.current),1e4);d.current=setTimeout(N,m)}}},R=()=>{y(),p.current=!1,h.current=0,d.current=setTimeout(N,1e3)},B=async()=>{e("loading"),o(null),l(null),g(""),h.current=0;try{const k=await Me.channels.weixin.bind(),m=(k==null?void 0:k.data)??k,b=(m==null?void 0:m.qrcode_img_content)??"",C=(m==null?void 0:m.qrcode)??"";if(!b||!C){e("error"),g(s("channels.qrDataMissing",{data:JSON.stringify(m)}));return}o(b),l(C),await A(b),e("waiting")}catch(k){e("error");const m=String((k==null?void 0:k.message)??k);g(m),re.error(s("channels.fetchWechatQrFailed",{error:m}))}},j=()=>{B()};return I.useEffect(()=>(B(),y),[]),I.useEffect(()=>(c&&R(),y),[c]),a.jsx(St,{isOpen:!0,onClose:i,title:s("channels.bindTitle",{name:(n==null?void 0:n.name)??s("channels.typeLabels.wechat")}),size:"sm",children:a.jsxs("div",{className:"flex flex-col items-center gap-4 py-2",children:[a.jsxs("div",{className:"relative w-60 h-60 rounded-lg bg-white flex items-center justify-center overflow-hidden",children:[t==="loading"&&a.jsx("span",{className:"text-gray-400 text-sm",children:s("channels.qr.generating")}),t!=="error"&&t!=="expired"&&a.jsx("canvas",{ref:x,width:240,height:240,className:`w-full h-full object-contain ${t==="waiting"?"":"opacity-30"}`}),t==="scanned"&&a.jsxs("div",{className:"absolute inset-0 bg-black/70 flex flex-col items-center justify-center text-white gap-1",children:[a.jsx("span",{className:"text-2xl",children:"✓"}),a.jsx("span",{className:"text-sm",children:s("channels.qr.scanned")})]}),t==="confirmed"&&a.jsxs("div",{className:"absolute inset-0 bg-green-600/90 flex flex-col items-center justify-center text-white gap-2 px-4 text-center",children:[a.jsx("span",{className:"text-2xl",children:"🎉"}),a.jsx("span",{className:"text-sm font-medium",children:s("channels.bindSuccess")}),a.jsx("span",{className:"text-xs opacity-90",children:n?s("channels.connectedReady",{name:n.name}):s("channels.createdConnectedReady")}),a.jsx("button",{onClick:i,className:"mt-1 text-xs bg-white/20 hover:bg-white/30 px-3 py-1.5 rounded-md transition-colors",children:s("channels.startUsing")})]}),t==="expired"&&a.jsxs("div",{className:"absolute inset-0 bg-black/80 flex flex-col items-center justify-center text-white gap-2",children:[a.jsx("span",{className:"text-sm",children:s("channels.qr.expired")}),a.jsx("button",{onClick:j,className:"text-xs bg-green-600 hover:bg-green-500 px-3 py-1 rounded",children:s("channels.clickToRefresh")})]}),t==="error"&&a.jsxs("div",{className:"absolute inset-0 bg-black/80 flex flex-col items-center justify-center text-red-300 gap-2 px-4 text-center",children:[a.jsx("span",{className:"text-xs",children:u||s("channels.unknownError")}),a.jsx("button",{onClick:j,className:"text-xs bg-blue-600 hover:bg-blue-500 px-3 py-1 rounded text-white",children:s("channels.retry")})]})]}),a.jsxs("p",{className:"text-sm text-dark-muted text-center",children:[t==="waiting"&&s("channels.waitingAuthorize"),t==="scanned"&&s("channels.scannedConfirming"),t==="confirmed"&&s("channels.confirmedClosing"),t==="loading"&&s("channels.connectingIlink"),(t==="expired"||t==="error")&&(t==="expired"?s("channels.qr.expired"):"")]}),r&&t==="waiting"&&a.jsxs("button",{onClick:()=>window.open(r,"_blank","width=480,height=600,noopener"),className:"w-full flex items-center justify-center gap-2 text-sm bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 px-3 py-2.5 rounded-lg transition-colors",children:[a.jsx("span",{children:"🔔"})," ",s("channels.openInNewTabFallback")]})]})})}function un(){const{t:n}=D(),{load:i,loading:s,qrOpen:t,qrChannel:e,closeQr:r}=Te();return I.useEffect(()=>{i()},[]),a.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-dark-bg text-dark-text",children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-dark-border shrink-0",children:[a.jsxs("div",{children:[a.jsx("h2",{className:"font-semibold text-base",children:n("channels.title")}),a.jsx("p",{className:"text-xs text-dark-muted mt-0.5",children:n("channels.viewSubtitle")})]}),a.jsx("div",{className:"flex items-center gap-2",children:a.jsx("button",{onClick:()=>i(),title:n("channels.actions.refresh"),className:"p-2 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:a.jsx(Tt,{className:`w-4 h-4 ${s?"animate-spin":""}`})})})]}),a.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[a.jsx("div",{className:"w-[260px] shrink-0",children:a.jsx(Rt,{})}),a.jsx("div",{className:"flex-1 min-w-0",children:a.jsx(At,{})})]}),t&&a.jsx(rn,{channel:e,onClose:r})]})}export{un as ChannelConfigView};
@@ -1 +0,0 @@
1
- import{j as s}from"./markdown-DEtuzEyz.js";import{a as c,L as w,A as q,ax as G,aa as pe,h as be,b1 as ge,bb as he,$ as I,at as fe,af as V,Q as H,S as M,am as je,b5 as D,aE as ve,a2 as Q,s as ke}from"./icons-f1hlMKvD.js";import{u as Ne,w as ye,a as p}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";const we={"code-intelligence":"🧠 代码智能",filesystem:"📂 文件系统",databases:"🗄️ 数据库","browser-automation":"🌐 浏览器自动化","knowledge-memory":"🧠 知识/记忆","search-web":"🔎 搜索/网页","cloud-platforms":"☁️ 云平台",communication:"💬 通讯","developer-tools":"🛠️ 开发者工具",security:"🔒 安全","test-demo":"🧪 测试/Demo",other:"📦 其他"};function Le({onNavigate:C}){const{t:n}=Ne(),[b,i]=c.useState([]),[Y,T]=c.useState(!0),[L,A]=c.useState(null),[S,m]=c.useState({}),[B,u]=c.useState(null),[E,W]=c.useState(""),[g,_]=c.useState(null),[z,J]=c.useState("all"),[X,j]=c.useState(null),[Z,P]=c.useState({}),[ee,$]=c.useState(!1),[o,x]=c.useState({name:"",command:"",args:"",env:"",transport:"stdio",url:"",headers:""}),[h,F]=c.useState(null),[R,v]=c.useState(!1),[U,f]=c.useState(null),se=async()=>{v(!0),f(null);try{const e=await p.tools.get("computer_use");F(e.success&&e.data?!!e.data.enabled:!1)}catch(e){f(e instanceof Error?e.message:String(e))}v(!1)},te=async()=>{if(h===null)return;const e=!h;v(!0),f(null);try{const t=await p.tools.toggle("computer_use",e);t.success?F(e):f(t.error||"切换 Computer Use 失败")}catch(t){f(t instanceof Error?t.message:String(t))}v(!1)},re=()=>x({name:"",command:"",args:"",env:"",transport:"stdio",url:"",headers:""}),K=e=>Object.fromEntries(e.split(",").map(t=>t.trim()).filter(Boolean).map(t=>{const a=t.indexOf("=");return a>0?[t.slice(0,a).trim(),t.slice(a+1).trim()]:[t,""]})),ae=async()=>{const e=o.transport!=="stdio";if(!o.name.trim()||!e&&!o.command.trim()||e&&!o.url.trim()){u(n("connectors.customFormRequired"));return}m(t=>({...t,__add:!0})),u(null);try{const t=await p.connectors.addCustom({name:o.name.trim(),command:e?void 0:o.command.trim(),args:e?void 0:o.args.split(/\s+/).filter(Boolean),env:K(o.env),url:e?o.url.trim():void 0,transport:e?o.transport:void 0,headers:e?K(o.headers):void 0});t.success&&t.data?(i(a=>[...a,t.data]),$(!1),re()):u(t.error||"添加失败")}catch(t){u(t instanceof Error?t.message:String(t))}finally{m(t=>({...t,__add:!1}))}},ne=async e=>{m(t=>({...t,[e.id]:!0}));try{const t=await p.connectors.removeCustom(e.id);t.success?i(a=>a.filter(r=>r.id!==e.id)):u(t.error||"删除失败")}finally{m(t=>({...t,[e.id]:!1}))}},k=async()=>{var t;T(!0),A(null);const e=await p.connectors.list();e.success&&Array.isArray((t=e.data)==null?void 0:t.connectors)?i(e.data.connectors):A(e.error||"加载连接器失败"),T(!1)};c.useEffect(()=>{k(),se()},[]),c.useEffect(()=>{let e=null;const t=r=>{if(!r||r.type!=="mcp_update")return;let l;try{l=typeof r.data=="string"?JSON.parse(r.data):r.data||{}}catch{return}const d=String(l.server||l.name||"");/^(managed|custom)-connector-/.test(d)&&(e&&clearTimeout(e),e=setTimeout(()=>{e=null,k()},150))},a=ye.onMessage(t);return()=>{e&&clearTimeout(e),a()}},[]);const N=(e,t,a,r)=>{u(a||null),i(l=>l.map(d=>d.id===e?{...d,enabled:!!r,status:"error"}:d))},le=async(e,t,a)=>{u(null),m(r=>({...r,[e.id]:!0})),i(r=>r.map(l=>l.id===e.id?{...l,enabled:t,status:t?"connecting":"installed"}:l));try{const r=await p.connectors.toggle(e.id,t,a);r.success&&r.data?i(l=>l.map(d=>d.id===e.id?r.data:d)):N(e.id,void 0,r.error||`切换 ${e.name} 失败`,!t)}catch(r){N(e.id,void 0,r instanceof Error?r.message:String(r),!t)}finally{m(r=>({...r,[e.id]:!1}))}},oe=e=>{var t,a;if(!e.enabled&&((t=e.requiresEnv)!=null&&t.length)&&((a=e.missingEnv)!=null&&a.length)){j(e.id);return}j(null),le(e,!e.enabled)},ce=async(e,t)=>{j(null),u(null),m(a=>({...a,[e.id]:!0})),i(a=>a.map(r=>r.id===e.id?{...r,enabled:!0,status:"connecting"}:r));try{const a=await p.connectors.connect(e.id,t);a.success&&a.data?(i(r=>r.map(l=>l.id===e.id?a.data:l)),P(r=>({...r,[e.id]:{}}))):N(e.id,void 0,a.error||`连接 ${e.name} 失败`,!1)}catch(a){N(e.id,void 0,a instanceof Error?a.message:String(a),!1)}finally{m(a=>({...a,[e.id]:!1}))}},de=e=>{const t="inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium";if(!e.installed)return s.jsxs("span",{className:`${t} bg-dark-hover text-dark-muted`,children:[s.jsx(Q,{size:12}),n("connectors.notInstalled")]});switch(e.status){case"ready":return s.jsxs("span",{className:`${t} bg-accent-green/15 text-accent-green`,children:[s.jsx(ke,{size:12}),n("connectors.ready")]});case"connecting":return s.jsxs("span",{className:`${t} bg-accent-blue/15 text-accent-blue`,children:[s.jsx(w,{size:12,className:"animate-spin"}),n("connectors.connecting")]});case"error":return s.jsxs("span",{className:`${t} bg-accent-red/15 text-accent-red`,children:[s.jsx(q,{size:12}),n("connectors.error")]});case"disabled":return s.jsx("span",{className:`${t} bg-dark-hover text-dark-muted`,children:n("connectors.disabled")});default:return s.jsx("span",{className:`${t} bg-dark-hover text-dark-muted`,children:n("connectors.installed")})}},y=b.filter(e=>z==="all"||e.kind===z),O=y.filter(e=>{if(E){const t=E.toLowerCase();if(![e.name,e.id,e.description,e.category??"",e.kind,...e.languages??[]].join(" ").toLowerCase().includes(t))return!1}return!(g&&e.category!==g)}).sort((e,t)=>e.enabled!==t.enabled?e.enabled?-1:1:e.name.localeCompare(t.name)),ie=[...new Set(y.map(e=>e.category).filter(Boolean))];if(Y)return s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(w,{size:32,className:"animate-spin mx-auto mb-2 text-accent-blue"}),s.jsx("p",{className:"text-dark-muted",children:n("common.loading")})]})});if(L)return s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(q,{size:32,className:"mx-auto mb-2 text-accent-red"}),s.jsx("p",{className:"text-accent-red mb-4",children:L}),s.jsx("button",{onClick:()=>void k(),className:"px-4 py-2 bg-accent-blue text-white rounded-lg",children:n("common.retry")})]})});const me=e=>{const t=Z[e.id]??{},a=(r,l)=>P(d=>({...d,[e.id]:{...d[e.id]??{},[r]:l}}));return s.jsxs("div",{className:"mt-3 pt-3 border-t border-dark-border",children:[s.jsxs("div",{className:"text-xs text-dark-muted mb-2 flex items-center gap-1",children:[s.jsx(D,{size:12}),n("connectors.needCredentials")]}),s.jsx("div",{className:"space-y-2",children:(e.requiresEnv??[]).map(r=>s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r.label}),s.jsx("input",{type:r.secret?"password":"text",value:t[r.key]??"",onChange:l=>a(r.key,l.target.value),placeholder:r.key,className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]},r.key))}),s.jsxs("div",{className:"flex gap-2 mt-2",children:[s.jsx("button",{onClick:()=>void ce(e,t),className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm",children:n("connectors.connect")}),s.jsx("button",{onClick:()=>j(null),className:"px-3 py-1.5 bg-dark-surface border border-dark-border rounded-lg text-sm",children:n("common.cancel")})]})]})},ue=e=>{var r,l,d;const t=!!S[e.id],a=X===e.id;return s.jsxs("div",{className:`bg-dark-surface border border-dark-border rounded-lg p-4 transition-opacity ${e.enabled?"":"opacity-80"}`,children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[s.jsx("span",{className:`mt-0.5 shrink-0 px-2 py-1 rounded-md text-[11px] font-semibold uppercase ${e.kind==="lsp"?"bg-accent-purple/15 text-accent-purple":"bg-accent-green/15 text-accent-green"}`,children:e.kind==="lsp"?"LSP":"MCP"}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("span",{className:"font-medium text-sm truncate",children:e.name}),e.custom?s.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-purple/15 text-accent-purple",children:n("connectors.custom")}):null,e.official?s.jsxs("span",{title:"Official",className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-yellow/15 text-accent-yellow",children:["🎖️ ",n("connectors.official")]}):null,e.scope==="cloud"?s.jsxs("span",{title:"Cloud",className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/15 text-accent-blue",children:[s.jsx(H,{size:9}),n("connectors.cloud")]}):s.jsxs("span",{title:"Local",className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted",children:[s.jsx(M,{size:9}),n("connectors.local")]}),e.language?s.jsx("span",{className:"text-[10px]",children:e.language}):null,de(e)]}),s.jsx("p",{className:"text-xs text-dark-muted mt-1 line-clamp-2",children:e.description}),s.jsxs("div",{className:"flex items-center gap-3 mt-2 text-[11px] text-dark-muted flex-wrap",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(M,{size:11}),s.jsx("code",{className:"text-[10px]",children:e.installHint})]}),e.transport&&e.transport!=="stdio"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-accent-blue",children:[s.jsx(H,{size:11}),e.transport==="sse"?"SSE":"Streamable HTTP"]}):null,(r=e.languages)!=null&&r.length?s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(je,{size:11}),e.languages.join(", ")]}):null,e.kind==="mcp"&&e.toolCount!==void 0?s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(G,{size:11}),n("connectors.toolCount",{count:e.toolCount})]}):null,(l=e.requiresEnv)!=null&&l.length?s.jsxs("span",{className:"inline-flex items-center gap-1 text-accent-yellow",children:[s.jsx(D,{size:11}),(d=e.missingEnv)!=null&&d.length?`${e.missingEnv.join(", ")} ${n("connectors.missing")}`:n("connectors.envConfigured")]}):null,e.docsUrl?s.jsxs("a",{href:e.docsUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 hover:text-accent-blue",onClick:xe=>xe.stopPropagation(),children:[s.jsx(I,{size:11}),n("connectors.docs")]}):null]}),e.error?s.jsx("p",{className:"text-[11px] text-accent-red mt-1",children:e.error}):null]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.custom?s.jsx("button",{onClick:()=>void ne(e),disabled:t,title:n("connectors.removeCustom"),className:"p-1.5 rounded-lg text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors disabled:opacity-40",children:s.jsx(ve,{size:14})}):null,!e.installed&&e.enabled?s.jsxs("span",{className:"text-[11px] text-accent-blue flex items-center gap-1",children:[s.jsx(Q,{size:11,className:"animate-pulse"}),n("connectors.installing")]}):null,s.jsx("button",{role:"switch","aria-checked":e.enabled,disabled:t,onClick:()=>oe(e),className:`relative w-12 h-6 rounded-full transition-colors disabled:opacity-50 ${e.enabled?"bg-accent-green":"bg-dark-border"}`,children:s.jsx("span",{className:`absolute top-1 w-4 h-4 bg-white rounded-full transition-transform ${e.enabled?"left-7":"left-1"}`})})]})]}),a?me(e):null]},e.id)};return s.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[s.jsx(G,{size:20}),n("nav.connectors"),s.jsxs("span",{className:"text-sm font-normal text-dark-muted",children:["· ",b.filter(e=>e.enabled).length,"/",b.length]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("button",{onClick:()=>$(e=>!e),className:"flex items-center gap-2 px-3 py-1.5 bg-accent-blue text-white rounded hover:bg-accent-blue/90 transition-colors",children:[s.jsx(pe,{size:14}),n("connectors.addCustom")]}),s.jsxs("button",{onClick:()=>void k(),className:"flex items-center gap-2 px-3 py-1.5 bg-dark-surface border border-dark-border rounded hover:bg-dark-hover transition-colors",children:[s.jsx(be,{size:14}),n("common.refresh")]})]})]}),s.jsxs("div",{className:"mb-4 p-4 bg-dark-surface border border-dark-border rounded-lg space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-start gap-2",children:[s.jsx(ge,{size:16,className:"text-accent-blue mt-0.5 shrink-0"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-sm text-dark-text",children:"Computer Use"}),s.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:"GUI 截屏 + 鼠标键盘操控(Windows)。每次调用需审批;需要视觉模型读屏。"})]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":!!h,disabled:R,onClick:()=>void te(),className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:opacity-50 ${h?"bg-accent-blue":"bg-dark-border"}`,children:R?s.jsx(w,{size:12,className:"absolute left-[7px] top-[3px] animate-spin text-white"}):s.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${h?"translate-x-[18px]":"translate-x-0.5"}`})})]}),s.jsxs("div",{className:"pt-3 border-t border-dark-border flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-start gap-2",children:[s.jsx(he,{size:16,className:"text-accent-yellow mt-0.5 shrink-0"}),s.jsxs("div",{children:[s.jsx("div",{className:"text-sm text-dark-text",children:"xAI (Grok) API"}),s.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:"官方 OpenAI 兼容端点,支持 X 实时数据的 Grok 系列模型。"})]})]}),s.jsxs("button",{onClick:()=>C==null?void 0:C("models"),className:"flex items-center gap-1.5 px-3 py-1.5 bg-accent-blue/10 text-accent-blue border border-accent-blue/30 rounded-lg hover:bg-accent-blue/20 transition-colors text-xs shrink-0",children:["配置",s.jsx(I,{size:11})]})]}),U?s.jsx("div",{className:"text-xs text-accent-red bg-accent-red/10 border border-accent-red/30 rounded-lg px-3 py-2",children:U}):null]}),ee?s.jsxs("div",{className:"mb-4 p-4 bg-dark-surface border border-dark-border rounded-lg",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[s.jsx(fe,{size:15,className:"text-accent-purple"}),n("connectors.customTitle")]}),s.jsx("div",{className:"flex gap-1",children:[["stdio","🖥️ "+n("connectors.customLocal")],["http","🌐 HTTP"],["sse","📡 SSE"]].map(([e,t])=>s.jsx("button",{onClick:()=>x(a=>({...a,transport:e})),className:`px-3 py-1.5 rounded-lg text-xs transition-colors ${o.transport===e?"bg-accent-blue text-white":"bg-dark-bg border border-dark-border hover:bg-dark-hover"}`,children:t},e))})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customName")}),s.jsx("input",{value:o.name,onChange:e=>x(t=>({...t,name:e.target.value})),placeholder:"my-server",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),o.transport==="stdio"?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customCommand")}),s.jsx("input",{value:o.command,onChange:e=>x(t=>({...t,command:e.target.value})),placeholder:"npx -y @some/mcp-server",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customArgs")}),s.jsx("input",{value:o.args,onChange:e=>x(t=>({...t,args:e.target.value})),placeholder:"--arg value",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customUrl")}),s.jsx("input",{value:o.url,onChange:e=>x(t=>({...t,url:e.target.value})),placeholder:"https://mcp.example.com/mcp",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),o.transport==="stdio"?s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customEnv")}),s.jsx("input",{value:o.env,onChange:e=>x(t=>({...t,env:e.target.value})),placeholder:"KEY=value, KEY2=value2",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:n("connectors.customHeaders")}),s.jsx("input",{value:o.headers,onChange:e=>x(t=>({...t,headers:e.target.value})),placeholder:"Authorization=Bearer xxx",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})]}),s.jsxs("div",{className:"flex gap-2 mt-3",children:[s.jsx("button",{onClick:()=>void ae(),disabled:!!S.__add,className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm disabled:opacity-50",children:S.__add?s.jsx(w,{size:14,className:"animate-spin"}):n("connectors.add")}),s.jsx("button",{onClick:()=>$(!1),className:"px-3 py-1.5 bg-dark-surface border border-dark-border rounded-lg text-sm",children:n("common.cancel")})]})]}):null,s.jsx("div",{className:"flex gap-1 mb-3",children:[["all",`${n("connectors.all")} (${b.length})`],["lsp",`LSP (${b.filter(e=>e.kind==="lsp").length})`],["mcp",`MCP (${b.filter(e=>e.kind==="mcp").length})`]].map(([e,t])=>s.jsx("button",{onClick:()=>J(e),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${z===e?"bg-accent-blue text-white":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:t},e))}),s.jsx("div",{className:"flex gap-3 mb-3",children:s.jsxs("div",{className:"flex-1 relative",children:[s.jsx(V,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),s.jsx("input",{type:"text",value:E,onChange:e=>W(e.target.value),placeholder:n("connectors.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-dark-surface border border-dark-border rounded-lg text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})}),s.jsxs("div",{className:"flex gap-1 mb-4 flex-wrap",children:[s.jsxs("button",{onClick:()=>_(null),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${g?"bg-dark-surface border border-dark-border hover:bg-dark-hover":"bg-accent-blue text-white"}`,children:[n("connectors.all")," ",s.jsxs("span",{className:"opacity-70 text-xs",children:["(",y.length,")"]})]}),ie.map(e=>{const t=y.filter(a=>a.category===e).length;return s.jsxs("button",{onClick:()=>_(g===e?null:e),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${g===e?"bg-accent-blue text-white":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:[we[e]??e," ",s.jsxs("span",{className:"opacity-70 text-xs",children:["(",t,")"]})]},e)})]}),B?s.jsx("div",{className:"mb-4 px-3 py-2 bg-accent-red/10 border border-accent-red/30 rounded-lg text-accent-red text-sm",children:B}):null,s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:O.length===0?s.jsxs("div",{className:"text-center text-dark-muted text-sm py-10",children:[s.jsx(V,{size:24,className:"mx-auto mb-2 opacity-50"}),n("connectors.noResults")]}):s.jsx("div",{className:"space-y-2",children:O.map(ue)})})]})}export{Le as ConnectorsView};
@@ -1,11 +0,0 @@
1
- import{j as l}from"./markdown-DEtuzEyz.js";import{a as s,W as K,ar as Ce,aQ as Me,h as Ne,a_ as Te,af as ke,Z as le,l as Pe,a2 as ue,X as Ee,d as Re,ad as Fe,a$ as Le}from"./icons-f1hlMKvD.js";import{u as ze,a as B,t as F}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";function de(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Ae(e){if(Array.isArray(e))return e}function $e(e,t,r){return(t=We(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function De(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n,o,u,p,v=[],g=!0,j=!1;try{if(u=(r=r.call(e)).next,t!==0)for(;!(g=(n=u.call(r)).done)&&(v.push(n.value),v.length!==t);g=!0);}catch(N){j=!0,o=N}finally{try{if(!g&&r.return!=null&&(p=r.return(),Object(p)!==p))return}finally{if(j)throw o}}return v}}function Ie(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
2
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function fe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),r.push.apply(r,n)}return r}function pe(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?fe(Object(r),!0).forEach(function(n){$e(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):fe(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Ve(e,t){if(e==null)return{};var r,n,o=Ue(e,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)===-1&&{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function Ue(e,t){if(e==null)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.indexOf(n)!==-1)continue;r[n]=e[n]}return r}function He(e,t){return Ae(e)||De(e,t)||Be(e,t)||Ie()}function qe(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function We(e){var t=qe(e,"string");return typeof t=="symbol"?t:t+""}function Be(e,t){if(e){if(typeof e=="string")return de(e,t);var r={}.toString.call(e).slice(8,-1);return r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set"?Array.from(e):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?de(e,t):void 0}}function Qe(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function he(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),r.push.apply(r,n)}return r}function me(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?he(Object(r),!0).forEach(function(n){Qe(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):he(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Ke(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(n){return t.reduceRight(function(o,u){return u(o)},n)}}function G(e){return function t(){for(var r=this,n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];return o.length>=e.length?e.apply(this,o):function(){for(var p=arguments.length,v=new Array(p),g=0;g<p;g++)v[g]=arguments[g];return t.apply(r,[].concat(o,v))}}}function ne(e){return{}.toString.call(e).includes("Object")}function _e(e){return!Object.keys(e).length}function X(e){return typeof e=="function"}function Ge(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Je(e,t){return ne(t)||A("changeType"),Object.keys(t).some(function(r){return!Ge(e,r)})&&A("changeField"),t}function Xe(e){X(e)||A("selectorType")}function Ye(e){X(e)||ne(e)||A("handlerType"),ne(e)&&Object.values(e).some(function(t){return!X(t)})&&A("handlersType")}function Ze(e){e||A("initialIsRequired"),ne(e)||A("initialType"),_e(e)&&A("initialContent")}function et(e,t){throw new Error(e[t]||e.default)}var tt={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},A=G(et)(tt),te={changes:Je,selector:Xe,handler:Ye,initial:Ze};function rt(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};te.initial(e),te.handler(t);var r={current:e},n=G(it)(r,t),o=G(at)(r),u=G(te.changes)(e),p=G(nt)(r);function v(){var j=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(N){return N};return te.selector(j),j(r.current)}function g(j){Ke(n,o,u,p)(j)}return[v,g]}function nt(e,t){return X(t)?t(e.current):t}function at(e,t){return e.current=me(me({},e.current),t),t}function it(e,t,r){return X(t)?t(e.current):Object.keys(r).forEach(function(n){var o;return(o=t[n])===null||o===void 0?void 0:o.call(t,e.current[n])}),r}var ot={create:rt},st={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function ct(e){return function t(){for(var r=this,n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];return o.length>=e.length?e.apply(this,o):function(){for(var p=arguments.length,v=new Array(p),g=0;g<p;g++)v[g]=arguments[g];return t.apply(r,[].concat(o,v))}}}function lt(e){return{}.toString.call(e).includes("Object")}function ut(e){return e||ge("configIsRequired"),lt(e)||ge("configType"),e.urls?(dt(),{paths:{vs:e.urls.monacoBase}}):e}function dt(){console.warn(ve.deprecation)}function ft(e,t){throw new Error(e[t]||e.default)}var ve={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
3
- You are using deprecated way of configuration.
4
-
5
- Instead of using
6
- monaco.config({ urls: { monacoBase: '...' } })
7
- use
8
- monaco.config({ paths: { vs: '...' } })
9
-
10
- For more please check the link https://github.com/suren-atoyan/monaco-loader#config
11
- `},ge=ct(ft)(ve),pt={config:ut},ht=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(o){return r.reduceRight(function(u,p){return p(u)},o)}};function be(e,t){return Object.keys(t).forEach(function(r){t[r]instanceof Object&&e[r]&&Object.assign(t[r],be(e[r],t[r]))}),pe(pe({},e),t)}var mt={type:"cancelation",msg:"operation is manually canceled"};function oe(e){var t=!1,r=new Promise(function(n,o){e.then(function(u){return t?o(mt):n(u)}),e.catch(o)});return r.cancel=function(){return t=!0},r}var gt=["monaco"],vt=ot.create({config:st,isInitialized:!1,resolve:null,reject:null,monaco:null}),ye=He(vt,2),Y=ye[0],ae=ye[1];function bt(e){var t=pt.config(e),r=t.monaco,n=Ve(t,gt);ae(function(o){return{config:be(o.config,n),monaco:r}})}function yt(){var e=Y(function(t){var r=t.monaco,n=t.isInitialized,o=t.resolve;return{monaco:r,isInitialized:n,resolve:o}});if(!e.isInitialized){if(ae({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),oe(se);if(window.monaco&&window.monaco.editor)return xe(window.monaco),e.resolve(window.monaco),oe(se);ht(xt,wt)(Ot)}return oe(se)}function xt(e){return document.body.appendChild(e)}function jt(e){var t=document.createElement("script");return e&&(t.src=e),t}function wt(e){var t=Y(function(n){var o=n.config,u=n.reject;return{config:o,reject:u}}),r=jt("".concat(t.config.paths.vs,"/loader.js"));return r.onload=function(){return e()},r.onerror=t.reject,r}function Ot(){var e=Y(function(r){var n=r.config,o=r.resolve,u=r.reject;return{config:n,resolve:o,reject:u}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(r){var n=r.m||r;xe(n),e.resolve(n)},function(r){e.reject(r)})}function xe(e){Y().monaco||ae({monaco:e})}function St(){return Y(function(e){var t=e.monaco;return t})}var se=new Promise(function(e,t){return ae({resolve:e,reject:t})}),je={config:bt,init:yt,__getMonacoInstance:St},Ct={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},ce=Ct,Mt={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},Nt=Mt;function Tt({children:e}){return K.createElement("div",{style:Nt.container},e)}var kt=Tt,Pt=kt;function Et({width:e,height:t,isEditorReady:r,loading:n,_ref:o,className:u,wrapperProps:p}){return K.createElement("section",{style:{...ce.wrapper,width:e,height:t},...p},!r&&K.createElement(Pt,null,n),K.createElement("div",{ref:o,style:{...ce.fullWidth,...!r&&ce.hide},className:u}))}var Rt=Et,we=s.memo(Rt);function Ft(e){s.useEffect(e,[])}var Oe=Ft;function Lt(e,t,r=!0){let n=s.useRef(!0);s.useEffect(n.current||!r?()=>{n.current=!1}:e,t)}var M=Lt;function J(){}function Q(e,t,r,n){return zt(e,n)||At(e,t,r,n)}function zt(e,t){return e.editor.getModel(Se(e,t))}function At(e,t,r,n){return e.editor.createModel(t,r,n?Se(e,n):void 0)}function Se(e,t){return e.Uri.parse(t)}function $t({original:e,modified:t,language:r,originalLanguage:n,modifiedLanguage:o,originalModelPath:u,modifiedModelPath:p,keepCurrentOriginalModel:v=!1,keepCurrentModifiedModel:g=!1,theme:j="light",loading:N="Loading...",options:C={},height:_="100%",width:I="100%",className:V,wrapperProps:U={},beforeMount:H=J,onMount:q=J}){let[w,T]=s.useState(!1),[E,y]=s.useState(!0),x=s.useRef(null),b=s.useRef(null),L=s.useRef(null),O=s.useRef(q),h=s.useRef(H),R=s.useRef(!1);Oe(()=>{let d=je.init();return d.then(m=>(b.current=m)&&y(!1)).catch(m=>(m==null?void 0:m.type)!=="cancelation"&&console.error("Monaco initialization: error:",m)),()=>x.current?D():d.cancel()}),M(()=>{if(x.current&&b.current){let d=x.current.getOriginalEditor(),m=Q(b.current,e||"",n||r||"text",u||"");m!==d.getModel()&&d.setModel(m)}},[u],w),M(()=>{if(x.current&&b.current){let d=x.current.getModifiedEditor(),m=Q(b.current,t||"",o||r||"text",p||"");m!==d.getModel()&&d.setModel(m)}},[p],w),M(()=>{let d=x.current.getModifiedEditor();d.getOption(b.current.editor.EditorOption.readOnly)?d.setValue(t||""):t!==d.getValue()&&(d.executeEdits("",[{range:d.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),d.pushUndoStop())},[t],w),M(()=>{var d,m;(m=(d=x.current)==null?void 0:d.getModel())==null||m.original.setValue(e||"")},[e],w),M(()=>{let{original:d,modified:m}=x.current.getModel();b.current.editor.setModelLanguage(d,n||r||"text"),b.current.editor.setModelLanguage(m,o||r||"text")},[r,n,o],w),M(()=>{var d;(d=b.current)==null||d.editor.setTheme(j)},[j],w),M(()=>{var d;(d=x.current)==null||d.updateOptions(C)},[C],w);let $=s.useCallback(()=>{var k;if(!b.current)return;h.current(b.current);let d=Q(b.current,e||"",n||r||"text",u||""),m=Q(b.current,t||"",o||r||"text",p||"");(k=x.current)==null||k.setModel({original:d,modified:m})},[r,t,o,e,n,u,p]),W=s.useCallback(()=>{var d;!R.current&&L.current&&(x.current=b.current.editor.createDiffEditor(L.current,{automaticLayout:!0,...C}),$(),(d=b.current)==null||d.editor.setTheme(j),T(!0),R.current=!0)},[C,j,$]);s.useEffect(()=>{w&&O.current(x.current,b.current)},[w]),s.useEffect(()=>{!E&&!w&&W()},[E,w,W]);function D(){var m,k,P,z;let d=(m=x.current)==null?void 0:m.getModel();v||((k=d==null?void 0:d.original)==null||k.dispose()),g||((P=d==null?void 0:d.modified)==null||P.dispose()),(z=x.current)==null||z.dispose()}return K.createElement(we,{width:I,height:_,isEditorReady:w,loading:N,_ref:L,className:V,wrapperProps:U})}var Dt=$t;s.memo(Dt);function It(e){let t=s.useRef();return s.useEffect(()=>{t.current=e},[e]),t.current}var Vt=It,re=new Map;function Ut({defaultValue:e,defaultLanguage:t,defaultPath:r,value:n,language:o,path:u,theme:p="light",line:v,loading:g="Loading...",options:j={},overrideServices:N={},saveViewState:C=!0,keepCurrentModel:_=!1,width:I="100%",height:V="100%",className:U,wrapperProps:H={},beforeMount:q=J,onMount:w=J,onChange:T,onValidate:E=J}){let[y,x]=s.useState(!1),[b,L]=s.useState(!0),O=s.useRef(null),h=s.useRef(null),R=s.useRef(null),$=s.useRef(w),W=s.useRef(q),D=s.useRef(),d=s.useRef(n),m=Vt(u),k=s.useRef(!1),P=s.useRef(!1);Oe(()=>{let a=je.init();return a.then(i=>(O.current=i)&&L(!1)).catch(i=>(i==null?void 0:i.type)!=="cancelation"&&console.error("Monaco initialization: error:",i)),()=>h.current?ie():a.cancel()}),M(()=>{var i,c,f,S;let a=Q(O.current,e||n||"",t||o||"",u||r||"");a!==((i=h.current)==null?void 0:i.getModel())&&(C&&re.set(m,(c=h.current)==null?void 0:c.saveViewState()),(f=h.current)==null||f.setModel(a),C&&((S=h.current)==null||S.restoreViewState(re.get(u))))},[u],y),M(()=>{var a;(a=h.current)==null||a.updateOptions(j)},[j],y),M(()=>{!h.current||n===void 0||(h.current.getOption(O.current.editor.EditorOption.readOnly)?h.current.setValue(n):n!==h.current.getValue()&&(P.current=!0,h.current.executeEdits("",[{range:h.current.getModel().getFullModelRange(),text:n,forceMoveMarkers:!0}]),h.current.pushUndoStop(),P.current=!1))},[n],y),M(()=>{var i,c;let a=(i=h.current)==null?void 0:i.getModel();a&&o&&((c=O.current)==null||c.editor.setModelLanguage(a,o))},[o],y),M(()=>{var a;v!==void 0&&((a=h.current)==null||a.revealLine(v))},[v],y),M(()=>{var a;(a=O.current)==null||a.editor.setTheme(p)},[p],y);let z=s.useCallback(()=>{var a;if(!(!R.current||!O.current)&&!k.current){W.current(O.current);let i=u||r,c=Q(O.current,n||e||"",t||o||"",i||"");h.current=(a=O.current)==null?void 0:a.editor.create(R.current,{model:c,automaticLayout:!0,...j},N),C&&h.current.restoreViewState(re.get(i)),O.current.editor.setTheme(p),v!==void 0&&h.current.revealLine(v),x(!0),k.current=!0}},[e,t,r,n,o,u,j,N,C,p,v]);s.useEffect(()=>{y&&$.current(h.current,O.current)},[y]),s.useEffect(()=>{!b&&!y&&z()},[b,y,z]),d.current=n,s.useEffect(()=>{var a,i;y&&T&&((a=D.current)==null||a.dispose(),D.current=(i=h.current)==null?void 0:i.onDidChangeModelContent(c=>{P.current||T(h.current.getValue(),c)}))},[y,T]),s.useEffect(()=>{if(y){let a=O.current.editor.onDidChangeMarkers(i=>{var f;let c=(f=h.current.getModel())==null?void 0:f.uri;if(c&&i.find(S=>S.path===c.path)){let S=O.current.editor.getModelMarkers({resource:c});E==null||E(S)}});return()=>{a==null||a.dispose()}}return()=>{}},[y,E]);function ie(){var a,i;(a=D.current)==null||a.dispose(),_?C&&re.set(u,h.current.saveViewState()):(i=h.current.getModel())==null||i.dispose(),h.current.dispose()}return K.createElement(we,{width:I,height:V,isEditorReady:y,loading:g,_ref:R,className:U,wrapperProps:H})}var Ht=Ut,qt=s.memo(Ht),Wt=qt;function Bt(e){var n;const t=(n=e.split(".").pop())==null?void 0:n.toLowerCase();return{ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",json:"json",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",yaml:"yaml",yml:"yaml",toml:"toml",sql:"sql",sh:"shell",bat:"bat",ps1:"powershell",dockerfile:"dockerfile",properties:"properties",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",vue:"html",svelte:"html",svg:"xml"}[t||""]||"plaintext"}function Yt(){const{t:e}=ze(),[t,r]=s.useState([]),[n,o]=s.useState(null),[u,p]=s.useState(""),[v,g]=s.useState(""),[j,N]=s.useState(!1),[C,_]=s.useState(""),[I,V]=s.useState(!1),[U,H]=s.useState(!1),[q,w]=s.useState(!1),[T,E]=s.useState(""),y=s.useRef(null);s.useEffect(()=>{if(!n){p(""),g("");return}N(!0),B.files.read(n).then(a=>{if(a.success&&a.data){const i=typeof a.data=="string"?a.data:JSON.stringify(a.data);p(i),g(i)}else F.error(a.error||e("fileTree.readFail"))}).catch(()=>F.error(e("fileTree.readFail"))).finally(()=>N(!1))},[n]);const x=async a=>{V(!0);try{const i=await B.files.list(a);i.success&&Array.isArray(i.data)&&r(i.data.map(c=>({...c,expanded:!1})))}finally{V(!1)}},b=async a=>{if(a.type==="directory")try{const i=await B.files.list(a.path);if(i.success&&Array.isArray(i.data)){const c=i.data.map(f=>({...f,expanded:!1}));r(f=>L(f,a.id,c))}}catch{}},L=(a,i,c)=>a.map(f=>f.id===i?{...f,children:c,expanded:!0}:f.children?{...f,children:L(f.children,i,c)}:f);s.useEffect(()=>{x()},[]);const O=a=>{const i=R(t,a);if(i&&i.type==="directory"&&!i.children){b(i);return}r(c=>h(c,a))},h=(a,i)=>a.map(c=>c.id===i&&c.type==="directory"?{...c,expanded:!c.expanded}:c.children?{...c,children:h(c.children,i)}:c),R=(a,i)=>{for(const c of a){if(c.id===i)return c;if(c.children){const f=R(c.children,i);if(f)return f}}return null},$=(a,i)=>i?a.reduce((c,f)=>{if(f.name.toLowerCase().includes(i.toLowerCase()))c.push(f);else if(f.children){const S=$(f.children,i);S.length>0&&c.push({...f,children:S,expanded:!0})}return c},[]):a,W=s.useCallback(async()=>{if(n){H(!0);try{const a=await B.files.update(n,u);a.success?(g(u),F.success(e("fileTree.saved"))):F.error(a.error||e("fileTree.saveFail"))}catch{F.error(e("fileTree.saveFail"))}finally{H(!1)}}},[n,u,e]),D=()=>{o(null),p(""),g("")},d=s.useCallback(async a=>{const i=await B.files.download(a);i.success?F.success(e("fileTree.downloadStarted")):F.error(i.error||e("fileTree.downloadFail"))},[e]),m=()=>{var a;return(a=y.current)==null?void 0:a.click()},k=s.useCallback(async a=>{if(!a||a.length===0)return;const i=T||(n?n.replace(/[\\/][^\\/]+$/,""):"");w(!0);let c=0,f=0;for(const S of Array.from(a)){const Z=i?`${i}/${S.name}`:S.name;(await B.files.upload(S,Z)).success?c++:f++}w(!1),c>0&&F.success(e("fileTree.uploadedCount",{count:c})),f>0&&F.error(e("fileTree.uploadFailedCount",{count:f})),await x()},[T,n,e]),P=u!==v,z=(a,i=0)=>{var Z;const c=a.type==="directory",f=n===a.path,S=T===a.path;return l.jsxs("div",{children:[l.jsxs("div",{className:`group flex items-center gap-1 px-2 py-0.5 cursor-pointer rounded text-xs transition-colors ${f?"bg-accent-blue/20 text-accent-blue":S?"bg-accent-blue/10":"hover:bg-dark-hover"}`,style:{paddingLeft:`${i*14+6}px`},onClick:()=>c?(E(a.path),O(a.id)):o(a.path),title:c?e("fileTree.setUploadDirHint"):a.path,children:[c&&l.jsx("span",{className:"text-dark-muted shrink-0",children:a.expanded?l.jsx(Re,{size:12}):l.jsx(Fe,{size:12})}),c?l.jsx(Le,{size:12,className:"text-accent-yellow shrink-0"}):l.jsx("span",{className:"w-3"}),l.jsx("span",{className:"truncate flex-1",children:a.name}),!c&&l.jsx("button",{onClick:ee=>{ee.stopPropagation(),d(a.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-dark-border text-dark-muted hover:text-dark-text shrink-0",title:e("fileTree.download"),children:l.jsx(ue,{size:11})})]}),c&&a.expanded&&((Z=a.children)==null?void 0:Z.map(ee=>z(ee,i+1)))]},a.id)},ie=C?$(t,C):t;return l.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[l.jsxs("div",{className:"w-64 shrink-0 flex flex-col overflow-hidden border-r border-dark-border",children:[l.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-dark-border",children:[l.jsxs("h2",{className:"text-xs font-semibold flex items-center gap-1.5",children:[l.jsx(Ce,{size:14}),e("fileTree.title")]}),l.jsxs("div",{className:"flex items-center gap-0.5",children:[l.jsx("button",{onClick:m,disabled:q,className:"p-1 rounded hover:bg-dark-hover disabled:opacity-50",title:T?e("fileTree.uploadTo",{dir:T}):e("fileTree.uploadToRoot"),children:l.jsx(Me,{size:12,className:q?"animate-pulse":""})}),l.jsx("button",{onClick:()=>x(),disabled:I,className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.refresh"),children:l.jsx(Ne,{size:12,className:I?"animate-spin":""})}),l.jsx("button",{onClick:()=>{r(t.map(a=>({...a,expanded:!1}))),o(null)},className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.collapse"),children:l.jsx(Te,{size:12})})]})]}),l.jsx("div",{className:"p-1.5 border-b border-dark-border",children:l.jsxs("div",{className:"relative",children:[l.jsx(ke,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),l.jsx("input",{type:"text",value:C,onChange:a=>_(a.target.value),placeholder:e("fileTree.searchPlaceholder"),className:"w-full pl-6 pr-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:border-accent-blue focus:outline-none"})]})}),l.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar py-1",children:ie.map(a=>z(a))}),l.jsx("input",{ref:y,type:"file",multiple:!0,className:"hidden",onChange:a=>{k(a.target.files),a.currentTarget.value=""}})]}),l.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-dark-bg",children:n?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-dark-border bg-dark-surface",children:[l.jsxs("div",{className:"flex items-center gap-2 text-xs min-w-0",children:[l.jsx(le,{size:12,className:"text-dark-muted shrink-0"}),l.jsx("span",{className:"truncate",children:n}),P&&l.jsxs("span",{className:"text-accent-yellow text-[10px] shrink-0",children:["● ",e("fileTree.modified")]})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs("button",{onClick:W,disabled:!P||U,className:`px-2 py-0.5 text-[10px] rounded flex items-center gap-1 transition-colors ${P?"bg-accent-green text-white hover:opacity-90":"bg-dark-border text-dark-muted cursor-not-allowed"}`,children:[l.jsx(Pe,{size:10}),e(U?"fileTree.saving":"fileTree.save")]}),l.jsx("button",{onClick:()=>void d(n),className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.download"),children:l.jsx(ue,{size:12})}),l.jsx("button",{onClick:D,className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.close"),children:l.jsx(Ee,{size:12})})]})]}),l.jsx("div",{className:"flex-1 min-h-0",children:j?l.jsx("div",{className:"flex items-center justify-center h-full",children:l.jsx("div",{className:"w-4 h-4 border-2 border-accent-blue border-t-transparent rounded-full animate-spin"})}):l.jsx(Wt,{language:Bt(n),value:u,onChange:a=>p(a||""),theme:"vs-dark",options:{fontSize:13,fontFamily:'"Cascadia Code", "Fira Code", Consolas, monospace',minimap:{enabled:!0,renderCharacters:!1,maxColumn:80,showSlider:"mouseover"},lineNumbers:"on",scrollBeyondLastLine:!1,wordWrap:"on",automaticLayout:!0,tabSize:2}})})]}):l.jsx("div",{className:"flex-1 flex items-center justify-center",children:l.jsxs("div",{className:"text-center",children:[l.jsx(le,{size:32,className:"text-dark-muted mx-auto mb-2"}),l.jsx("p",{className:"text-sm text-dark-muted",children:e("fileTree.selectFileHint")})]})})})]})}export{Yt as FileTreeView,Yt as default};
@@ -1 +0,0 @@
1
- import{j as e}from"./markdown-DEtuzEyz.js";import{a as y,aX as L,p as D,aY as Y,aE as B,X as z,f as G,a4 as J,ad as W,aZ as _,aL as q,aM as X,h as Q,aQ as V,a2 as Z,aa as K}from"./icons-f1hlMKvD.js";import{c as ee}from"./state-xD58vmym.js";import{a as j,u as E}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./panels-Bn-2wCur.js";const P=ee((l,d)=>({rules:[],stats:null,events:[],agents:[],loading:!1,error:null,fieldErrors:null,formOpen:!1,editingRule:null,dryRunResult:null,loadRules:async()=>{const t=await j.hooks.list();t.success&&Array.isArray(t.data)?l({rules:t.data}):t.success&&t.data&&!Array.isArray(t.data)?l({error:"服务端返回的规则数据格式异常"}):l({error:t.error||"Failed to load rules"})},loadStats:async()=>{const t=await j.hooks.stats();t.success&&t.data&&l({stats:t.data})},loadEvents:async()=>{const t=await j.hooks.events();t.success&&Array.isArray(t.data)?l({events:t.data}):t.success&&t.data&&!Array.isArray(t.data)&&l({error:"服务端返回的事件数据格式异常"})},loadAgents:async()=>{const t=await j.hooks.agents();t.success&&Array.isArray(t.data)?l({agents:t.data}):t.success&&t.data&&!Array.isArray(t.data)&&l({error:"服务端返回的Agent数据格式异常"})},loadAll:async()=>{l({loading:!0,error:null});try{await Promise.all([d().loadRules(),d().loadStats(),d().loadEvents(),d().loadAgents()])}catch(t){l({error:String(t)})}finally{l({loading:!1})}},createRule:async t=>{l({fieldErrors:null});const r=await j.hooks.create(t);if(r.success)return await d().loadRules(),await d().loadStats(),l({formOpen:!1,editingRule:null}),!0;if(r.error){l({error:r.error});try{const c=JSON.parse(r.error);c.fieldErrors&&l({fieldErrors:c.fieldErrors})}catch{}}return!1},updateRule:async(t,r)=>{l({fieldErrors:null});const c=await j.hooks.update(t,r);return c.success?(await d().loadRules(),l({formOpen:!1,editingRule:null}),!0):(l({error:c.error||"Update failed"}),!1)},deleteRule:async t=>{const r=await j.hooks.delete(t);return r.success?(await d().loadRules(),await d().loadStats(),!0):(l({error:r.error||"Delete failed"}),!1)},batchDelete:async t=>{const r=await j.hooks.batchDelete(t);return r.success?(await d().loadRules(),await d().loadStats(),!0):(l({error:r.error||"Batch delete failed"}),!1)},toggleRule:async(t,r)=>(await j.hooks.toggle(t,r)).success?(l(x=>({rules:x.rules.map(p=>p.name===t?{...p,enabled:r}:p)})),!0):(await d().loadRules(),!1),batchToggle:async(t,r)=>(await j.hooks.batchToggle(t,r)).success?(l(x=>({rules:x.rules.map(p=>t.includes(p.name)?{...p,enabled:r}:p)})),!0):(await d().loadRules(),!1),dryRun:async t=>{const r=await j.hooks.dryRun(t);return r.success&&r.data?(l({dryRunResult:r.data}),r.data):(l({error:r.error||"Dry-run failed"}),null)},openForm:t=>l({formOpen:!0,editingRule:t||null,dryRunResult:null,fieldErrors:null}),closeForm:()=>l({formOpen:!1,editingRule:null,dryRunResult:null,fieldErrors:null}),setDryRunResult:t=>l({dryRunResult:t}),clearError:()=>l({error:null}),clearFieldErrors:()=>l({fieldErrors:null})})),te={SYSTEM:"bg-accent-red/15 text-accent-red",SECURITY:"bg-accent-orange/15 text-accent-orange",PROJECT:"bg-accent-blue/15 text-accent-blue",USER:"bg-accent-green/15 text-accent-green",PLUGIN:"bg-accent-purple/15 text-accent-purple"},ae={SHELL:"bg-accent-yellow/15 text-accent-yellow",HTTP:"bg-accent-cyan/15 text-accent-cyan",PROMPT:"bg-accent-purple/15 text-accent-purple",AGENT:"bg-accent-blue/15 text-accent-blue"};function se({rules:l,onEdit:d}){const{t}=E(),{toggleRule:r,deleteRule:c,batchDelete:x,batchToggle:p}=P(),[k,b]=y.useState(new Set),[R,v]=y.useState(!1),T=Array.isArray(l)?l:[];if(T.length===0)return e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 py-16 text-dark-muted",children:[e.jsx("div",{className:"text-4xl opacity-60",children:"🪝"}),e.jsx("p",{className:"text-sm",children:t("hook.noRules")}),e.jsx("p",{className:"text-xs text-dark-muted/70",children:t("hook.noRulesHint")})]});const C=n=>{const s=new Set(k);s.has(n)?s.delete(n):s.add(n),b(s),v(s.size===T.length)},h=()=>{R?(b(new Set),v(!1)):(b(new Set(T.map(n=>n.name))),v(!0))},w=()=>{k.size!==0&&confirm(t("hook.batchDeleteConfirm",{n:k.size}))&&(x(Array.from(k)),b(new Set),v(!1))},m=n=>{k.size!==0&&(p(Array.from(k),n),b(new Set),v(!1))};return e.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[k.size>0&&e.jsxs("div",{className:"mb-2 flex items-center gap-2 rounded-lg border border-accent-blue/30 bg-accent-blue/5 px-3 py-1.5 text-sm",children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.selectedItems",{n:k.size})}),e.jsx("button",{onClick:()=>m(!0),className:"rounded bg-accent-green/15 px-2 py-0.5 text-accent-green transition-colors hover:bg-accent-green/25",children:t("hook.enableAll")}),e.jsx("button",{onClick:()=>m(!1),className:"rounded bg-dark-hover px-2 py-0.5 text-dark-text transition-colors hover:bg-dark-border",children:t("hook.disableAll")}),e.jsx("button",{onClick:w,className:"rounded bg-accent-red/15 px-2 py-0.5 text-accent-red transition-colors hover:bg-accent-red/25",children:t("common.delete")})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar rounded-xl border border-dark-border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-dark-hover text-dark-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"w-8 p-2.5",children:e.jsx("button",{onClick:h,children:R?e.jsx(L,{size:14}):e.jsx(D,{size:14})})}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colName")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colEvents")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colType")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.fieldPriority")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colStatus")}),e.jsx("th",{className:"p-2.5 text-right font-medium",children:t("hook.colActions")})]})}),e.jsx("tbody",{className:"divide-y divide-dark-border",children:T.map(n=>e.jsxs("tr",{className:"transition-colors hover:bg-dark-hover/50",children:[e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>C(n.name),children:k.has(n.name)?e.jsx(L,{size:14,className:"text-accent-blue"}):e.jsx(D,{size:14,className:"text-dark-muted"})})}),e.jsxs("td",{className:"p-2.5",children:[e.jsx("div",{className:"font-medium text-dark-text",children:n.name}),n.description&&e.jsx("div",{className:"mt-0.5 max-w-[220px] truncate text-xs text-dark-muted",children:n.description})]}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[Array.isArray(n.events)&&n.events.slice(0,3).map(s=>e.jsx("span",{className:"rounded bg-dark-hover px-1.5 py-0.5 text-xs text-dark-text",children:s},s)),Array.isArray(n.events)&&n.events.length>3&&e.jsxs("span",{className:"px-1 py-0.5 text-xs text-dark-muted",children:["+",n.events.length-3]})]})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${ae[n.implementationType]||"bg-dark-hover text-dark-muted"}`,children:n.implementationType})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${te[n.priority]||"bg-dark-hover text-dark-muted"}`,children:n.priority})}),e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>r(n.name,!n.enabled),className:`relative h-5 w-9 rounded-full transition-colors ${n.enabled?"bg-accent-green":"bg-dark-border"}`,title:n.enabled?t("hook.clickToDisable"):t("hook.clickToEnable"),children:e.jsx("span",{className:`absolute top-0.5 block h-3.5 w-3.5 rounded-full bg-white transition-all ${n.enabled?"left-[18px]":"left-[2px]"}`})})}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{onClick:()=>d(n),className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue",title:t("hook.actionEdit"),children:e.jsx(Y,{size:14})}),e.jsx("button",{onClick:()=>{confirm(t("hook.deleteRuleConfirm",{name:n.name}))&&c(n.name)},className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red",title:t("common.delete"),children:e.jsx(B,{size:14})})]})})]},n.name))})]})})]})}const re={name:"",description:"",events:[],implementationType:"SHELL",command:"",url:"",promptTemplate:"",agentName:"",priority:"USER",tools:[],matcherToolNamePattern:"",matcherFromState:"",matcherToState:"",timeoutMs:3e4,enabled:!0,failOpen:!0,scope:"project"},le=[{value:"SYSTEM",label:"SYSTEM (100)"},{value:"SECURITY",label:"SECURITY (80)"},{value:"PROJECT",label:"PROJECT (60)"},{value:"USER",label:"USER (40)"},{value:"PLUGIN",label:"PLUGIN (20)"}],g=l=>`w-full rounded-lg border bg-dark-bg px-3 py-2 text-sm text-dark-text placeholder-dark-muted/60 transition-colors focus:outline-none focus:ring-2 ${l?"border-accent-red focus:border-accent-red focus:ring-accent-red/20":"border-dark-border focus:border-accent-blue focus:ring-accent-blue/20"}`,f="mb-1 block text-xs font-medium text-dark-muted";function ne({events:l,agents:d}){const{t}=E(),{editingRule:r,fieldErrors:c,dryRunResult:x,createRule:p,updateRule:k,closeForm:b,dryRun:R,setDryRunResult:v,clearFieldErrors:T}=P(),C=[{value:"SHELL",label:t("hook.implShell"),desc:t("hook.implShellDesc")},{value:"HTTP",label:t("hook.implHttp"),desc:t("hook.implHttpDesc")},{value:"PROMPT",label:"LLM Prompt",desc:t("hook.implPromptDesc")},{value:"AGENT",label:"AI Agent",desc:t("hook.implAgentDesc")}],h=Array.isArray(l)?l:[],w=Array.isArray(d)?d:[],[m,n]=y.useState(0),[s,N]=y.useState(re),[S,O]=y.useState("");y.useEffect(()=>{var a,o,i;r&&N({name:r.name,description:r.description||"",events:r.events,implementationType:r.implementationType,command:r.command||"",url:r.url||"",promptTemplate:r.promptTemplate||"",agentName:r.agentName||"",priority:r.priority,tools:r.tools||[],matcherToolNamePattern:((a=r.matchers)==null?void 0:a.toolNamePattern)||"",matcherFromState:((o=r.matchers)==null?void 0:o.fromState)||"",matcherToState:((i=r.matchers)==null?void 0:i.toState)||"",timeoutMs:r.timeoutMs,enabled:r.enabled,failOpen:r.failOpen,scope:r.scope||"project"})},[r]);const u=(a,o)=>{N(i=>({...i,[a]:o})),T()},I=a=>{N(o=>({...o,events:o.events.includes(a)?o.events.filter(i=>i!==a):[...o.events,a]}))},F=a=>{const o=a.every(i=>s.events.includes(i));N(o?i=>({...i,events:i.events.filter(A=>!a.includes(A))}):i=>({...i,events:[...new Set([...i.events,...a])]}))},M=async()=>{const a={};s.matcherToolNamePattern&&(a.toolNamePattern=s.matcherToolNamePattern),s.matcherFromState&&(a.fromState=s.matcherFromState),s.matcherToState&&(a.toState=s.matcherToState);const i={...{...s,tools:s.tools.length>0?s.tools:[]}};i.matchers=a,delete i.matcherToolNamePattern,delete i.matcherFromState,delete i.matcherToState,r?await k(r.name,i):await p(i)},U=async()=>{v(null);const a={};s.matcherToolNamePattern&&(a.toolNamePattern=s.matcherToolNamePattern),await R({hook:{name:s.name||"dry-run",description:s.description,events:s.events,implementationType:s.implementationType,command:s.command,url:s.url,promptTemplate:s.promptTemplate,agentName:s.agentName,priority:s.priority,tools:s.tools,matchers:a,timeoutMs:s.timeoutMs,enabled:!0,failOpen:s.failOpen,scope:s.scope},eventType:s.events[0]||"PRE_TOOL_USE",toolName:"",toolInput:""})},H=S?h.map(a=>({...a,events:Array.isArray(a.events)?a.events.filter(o=>o.name.toLowerCase().includes(S.toLowerCase())||o.summary.includes(S)):[]})).filter(a=>a.events.length>0):h,$=[{title:t("hook.stepBasicTitle"),desc:t("hook.stepBasicDesc")},{title:t("hook.stepImplTitle"),desc:t("hook.stepImplDesc")},{title:t("hook.stepAdvancedTitle"),desc:t("hook.stepAdvancedDesc")}];return e.jsxs("div",{className:"fixed inset-0 z-50 flex justify-end",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:b}),e.jsxs("div",{className:"relative flex h-full w-[560px] flex-col border-l border-dark-border bg-dark-bg shadow-2xl animate-slide-in-right",children:[e.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-b border-dark-border px-4 py-3.5",children:[e.jsx("h3",{className:"text-base font-semibold text-dark-text",children:r?t("hook.editRule",{name:r.name}):t("hook.addRule")}),e.jsx("button",{onClick:b,className:"rounded-lg p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(z,{size:18})})]}),e.jsx("div",{className:"flex flex-shrink-0 border-b border-dark-border",children:$.map((a,o)=>{const i=o===m,A=o<m;return e.jsxs("button",{onClick:()=>n(o),className:`relative flex-1 border-b-2 px-2 py-2.5 text-center text-xs transition-colors ${i?"border-accent-blue bg-accent-blue/5 text-accent-blue":A?"border-transparent text-dark-text":"border-transparent text-dark-muted hover:text-dark-text"}`,children:[e.jsx("span",{className:`mr-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-[10px] ${i?"bg-accent-blue text-white":A?"bg-accent-green text-white":"bg-dark-hover text-dark-muted"}`,children:A?"✓":o+1}),e.jsx("span",{className:"font-medium",children:a.title})]},a.title)})}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-4 overflow-auto custom-scrollbar p-4",children:[c&&Object.keys(c).length>0&&e.jsx("div",{className:"rounded-lg border border-accent-red/40 bg-accent-red/10 p-2.5 text-xs text-accent-red",children:Object.entries(c).map(([a,o])=>e.jsxs("div",{children:[e.jsxs("strong",{children:[a,":"]})," ",o]},a))}),m===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldName")}),e.jsx("input",{value:s.name,onChange:a=>u("name",a.target.value),placeholder:"my-custom-hook",className:g(c==null?void 0:c.name)})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldDescription")}),e.jsx("textarea",{value:s.description,onChange:a=>u("description",a.target.value),placeholder:t("hook.descriptionPlaceholder"),rows:2,className:g()})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:"Scope"}),e.jsxs("select",{value:s.scope,onChange:a=>u("scope",a.target.value),className:g(),children:[e.jsx("option",{value:"project",children:"project (.agent/hooks.json)"}),e.jsx("option",{value:"user",children:"user (~/.agent/hooks.json)"}),e.jsx("option",{value:"local",children:"local (.agent/hooks.local.json)"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-medium text-dark-muted",children:t("hook.fieldEvents")}),e.jsx("span",{className:"text-xs text-accent-blue",children:t("hook.eventsSelected",{n:s.events.length})})]}),e.jsx("input",{value:S,onChange:a=>O(a.target.value),placeholder:t("hook.searchEventsPlaceholder"),className:g()+" mb-2"}),e.jsx("div",{className:"max-h-[280px] space-y-2 overflow-auto custom-scrollbar rounded-lg border border-dark-border bg-dark-surface p-2",children:H.map(a=>e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>F(a.events.map(o=>o.name)),className:"mb-1 text-xs font-medium text-dark-muted transition-colors hover:text-dark-text",children:[a.category," — ",t("hook.toggleAllEvents")]}),a.events.map(o=>{const i=s.events.includes(o.name);return e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded px-1 py-1 transition-colors hover:bg-dark-hover",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:()=>I(o.name),className:"h-3.5 w-3.5 accent-accent-blue"}),e.jsx("span",{className:"text-xs text-dark-text",children:o.name}),e.jsxs("span",{className:"truncate text-xs text-dark-muted",children:["— ",o.summary]})]},o.name)})]},a.category))})]})]}),m===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldImplType")}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:C.map(a=>{const o=s.implementationType===a.value;return e.jsxs("button",{onClick:()=>u("implementationType",a.value),className:`rounded-lg border p-3 text-left transition-colors ${o?"border-accent-blue bg-accent-blue/10 ring-1 ring-accent-blue/30":"border-dark-border bg-dark-surface hover:bg-dark-hover"}`,children:[e.jsx("div",{className:`text-sm font-medium ${o?"text-accent-blue":"text-dark-text"}`,children:a.label}),e.jsx("div",{className:"mt-1 text-xs text-dark-muted",children:a.desc})]},a.value)})})]}),s.implementationType==="SHELL"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldCommand")}),e.jsx("input",{value:s.command,onChange:a=>u("command",a.target.value),placeholder:"python3 .agent/hooks/audit.py",className:`font-mono ${g(c==null?void 0:c.command)}`})]}),s.implementationType==="HTTP"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:"URL *"}),e.jsx("input",{value:s.url,onChange:a=>u("url",a.target.value),placeholder:"https://example.com/hooks/audit",className:g(c==null?void 0:c.url)})]}),s.implementationType==="PROMPT"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldPromptTemplate")}),e.jsx("textarea",{value:s.promptTemplate,onChange:a=>u("promptTemplate",a.target.value),placeholder:t("hook.promptTemplatePlaceholder"),rows:5,className:`font-mono ${g(c==null?void 0:c.promptTemplate)}`})]}),s.implementationType==="AGENT"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:"Agent *"}),e.jsxs("select",{value:s.agentName,onChange:a=>u("agentName",a.target.value),className:g(c==null?void 0:c.agentName),children:[e.jsx("option",{value:"",children:t("hook.selectAgentPlaceholder")}),w.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.description,")"]},a.id))]}),e.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:t("hook.agentReadOnlyHint")})]})]}),m===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldPriority")}),e.jsx("select",{value:s.priority,onChange:a=>u("priority",a.target.value),className:g(),children:le.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldTimeout")}),e.jsx("input",{type:"number",value:s.timeoutMs,onChange:a=>u("timeoutMs",parseInt(a.target.value)||3e4),min:100,max:3e5,step:1e3,className:g()})]}),e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:a=>u("enabled",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),t("hook.labelEnabled")]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:s.failOpen,onChange:a=>u("failOpen",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),t("hook.failOpenLabel")]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldToolFilter")}),e.jsx("input",{value:s.matcherToolNamePattern,onChange:a=>u("matcherToolNamePattern",a.target.value),placeholder:"Bash.*|FileWrite.*",className:`font-mono ${g()}`})]}),s.events.some(a=>a.includes("STATE"))&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:"From State"}),e.jsx("input",{value:s.matcherFromState,onChange:a=>u("matcherFromState",a.target.value),className:g()})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:"To State"}),e.jsx("input",{value:s.matcherToState,onChange:a=>u("matcherToState",a.target.value),className:g()})]})]}),x&&e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-dark-text",children:t("hook.dryRunResultTitle")}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.dryRunDecision")}),e.jsx("span",{className:x.decision==="ALLOW"?"text-accent-green":x.decision==="DENY"?"text-accent-red":"text-accent-yellow",children:x.decision})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.dryRunReason")}),e.jsx("span",{className:"text-dark-text",children:x.reason})]}),x.contextOutput&&e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.dryRunOutput")}),e.jsx("span",{className:"text-dark-text",children:x.contextOutput})]})]})]}),e.jsxs("button",{onClick:U,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-1.5 text-xs text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(G,{size:12})," ",t("hook.dryRunButton")]})]})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-t border-dark-border px-4 py-3",children:[e.jsx("div",{className:"flex gap-2",children:m>0&&e.jsxs("button",{onClick:()=>n(m-1),className:"inline-flex items-center gap-1 rounded-lg border border-dark-border bg-dark-surface px-3 py-1.5 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(J,{size:14})," ",t("hook.prevStep")]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:b,className:"rounded-lg border border-dark-border bg-dark-surface px-4 py-1.5 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:t("common.cancel")}),m<2?e.jsxs("button",{onClick:()=>n(m+1),className:"inline-flex items-center gap-1 rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:[t("hook.nextStep")," ",e.jsx(W,{size:14})]}):e.jsx("button",{onClick:M,className:"rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:t(r?"hook.saveChanges":"hook.createRule")})]})]})]})]})}function oe({stats:l}){const{t:d}=E();if(!l)return null;const t=[{id:"total",label:d("hook.statTotal"),value:l.totalHooks,icon:_,iconWrap:"bg-accent-blue/15 text-accent-blue"},{id:"enabled",label:d("common.enabled"),value:l.enabledCount,icon:q,iconWrap:"bg-accent-green/15 text-accent-green"},{id:"disabled",label:d("common.disabled"),value:l.disabledCount,icon:X,iconWrap:"bg-dark-hover text-dark-muted"}];return e.jsx("div",{className:"grid grid-cols-3 gap-3",children:t.map(r=>{const c=r.icon;return e.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-dark-border bg-dark-surface px-4 py-3",children:[e.jsx("span",{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg ${r.iconWrap}`,children:e.jsx(c,{size:18})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xl font-bold text-dark-text",children:r.value}),e.jsx("div",{className:"text-xs text-dark-muted",children:r.label})]})]},r.id)})})}function ue(){const{t:l}=E(),{rules:d,stats:t,events:r,agents:c,loading:x,error:p,formOpen:k,loadAll:b,openForm:R,clearError:v}=P();y.useEffect(()=>{b()},[]);const T=y.useCallback(async()=>{const h=await j.hooks.export();if(h.success&&h.data){const w=new Blob([JSON.stringify(h.data,null,2)],{type:"application/json"}),m=URL.createObjectURL(w),n=document.createElement("a");n.href=m,n.download="hooks-export.json",n.click(),URL.revokeObjectURL(m)}},[]),C=y.useCallback(()=>{const h=document.createElement("input");h.type="file",h.accept=".json",h.onchange=async w=>{var s;const m=(s=w.target.files)==null?void 0:s[0];if(!m)return;const n=await m.text();try{const N=JSON.parse(n),S=confirm(l("hook.importMergeConfirm"))?"merge":"replace";(await j.hooks.import({...N,mergeMode:S})).success&&b()}catch(N){console.error("Import failed:",N)}},h.click()},[b,l]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-dark-bg text-dark-text",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-dark-border px-6 py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-dark-text",children:l("hook.configTitle")}),e.jsx("p",{className:"mt-0.5 text-xs text-dark-muted",children:l("hook.configDesc")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:b,title:l("common.refresh"),className:"rounded-lg p-2 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(Q,{size:16,className:x?"animate-spin":""})}),e.jsxs("button",{onClick:C,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(V,{size:14}),l("hook.import")]}),e.jsxs("button",{onClick:T,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(Z,{size:14}),l("hook.export")]}),e.jsxs("button",{onClick:()=>R(),className:"inline-flex items-center gap-1.5 rounded-lg bg-accent-blue px-3 py-2 text-sm text-white transition-colors hover:bg-accent-blue/90",children:[e.jsx(K,{size:14}),l("hook.newRule")]})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar px-6 py-4",children:[p&&e.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-lg border border-accent-red/40 bg-accent-red/10 px-4 py-2 text-sm text-accent-red",children:[e.jsx("span",{children:p}),e.jsx("button",{onClick:v,className:"text-accent-red/70 transition-colors hover:text-accent-red",children:e.jsx(z,{size:16})})]}),e.jsx(oe,{stats:t}),e.jsxs("section",{className:"mt-4 min-w-0 rounded-xl border border-dark-border bg-dark-surface p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-dark-text",children:l("hook.ruleList")}),e.jsx("span",{className:"text-xs text-dark-muted",children:l("hook.ruleCount",{n:d.length})})]}),x&&d.length===0?e.jsx("div",{className:"flex h-[520px] items-center justify-center text-dark-muted",children:l("common.loading")}):e.jsx("div",{className:"min-h-[520px]",children:e.jsx(se,{rules:d,onEdit:h=>R(h)})})]})]}),k&&e.jsx(ne,{events:r,agents:c})]})}export{ue as HookConfigView};
@@ -1 +0,0 @@
1
- import{j as e}from"./markdown-DEtuzEyz.js";import{a as o,h as re,an as Os,aa as ke,af as oe,X as Fe,aD as Bs,C as X,aE as $e,aF as us,as as Hs,j as Gs,aG as qs,aH as _s,a2 as Vs,ax as Ws,aI as ms,A as Ys,aJ as Qs}from"./icons-f1hlMKvD.js";import{a as j,u as Js,t as T,f as ne,M as xs,P as Xs}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";function Zs(){const[k,g]=o.useState([]),[C,t]=o.useState("1.0"),[P,Pe]=o.useState(!0),[b,de]=o.useState(!0),[Te,W]=o.useState(null),Y=o.useCallback(async()=>{de(!0),W(null);try{const w=await j.providers.presets();w.success&&w.data?(g(Array.isArray(w.data.providers)?w.data.providers:[]),t(w.data.version||"1.0"),Pe(w.data.customSupported!==!1)):W(w.error||"获取 Provider 列表失败")}catch(w){W(w instanceof Error?w.message:"未知错误")}finally{de(!1)}},[]);return o.useEffect(()=>{Y()},[Y]),{presets:k,loading:b,error:Te,version:C,customSupported:P,reload:Y}}const et=[{key:"global",labelKey:"chat.globalDefault",color:"text-accent-red",bg:"bg-accent-red/20"},{key:"plan",labelKey:"chat.planDefault",color:"text-accent-blue",bg:"bg-accent-blue/20"},{key:"goal",labelKey:"chat.goalDefault",color:"text-accent-purple",bg:"bg-accent-purple/20"}],st={providerKey:"",apiKeys:[],modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!1,modelOverrides:{}},ps=Xs,Ne={"openai-chat-completions":"OpenAI Chat","openai-completions":"OpenAI Compatible","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages","codex-responses":"Codex (本机登录)","claude-code":"Claude Code (本机登录)"};function Z(k){return k.trim().split("|")[0].trim()}function tt(k){const g=k.toLowerCase();return g.startsWith("claude-code://")||g.includes("/backend-api/codex")?g.startsWith("claude-code://")?"claude-code":"codex-responses":g.includes("/anthropic")||g.includes("/coding")||g.includes("/claude")||g.includes("/messages")?"anthropic-messages":g.includes("/responses")?"openai-responses":"openai-completions"}function ze(k){if(!k)return{};const g={};for(const C of k.models){const t={};C.apiType&&C.apiType!==k.apiType&&(t.apiType=C.apiType),C.baseUrl&&(t.baseUrl=C.baseUrl),Object.keys(t).length>0&&(g[C.id]=t)}return g}const we={"opencode-free":5,deepseek:10,moonshotai:20,"moonshotai-cn":21,"kimi-for-coding":22,zhipuai:30,zai:31,"alibaba-cn":40,alibaba:41,minimax:50,"minimax-cn":51,moark:60,siliconflow:70,"siliconflow-cn":71,"stepfun-ai":80,stepfun:81,modelscope:90,openai:100,anthropic:110,google:120,"google-vertex":121,meta:130,mistral:140,groq:150,xai:160,cohere:170,openrouter:180,huggingface:190};function ct(){var ls,rs,os,ns,ds,cs,is;const{presets:k,loading:g,reload:C}=Zs(),{t}=Js(),[P,Pe]=o.useState([]),[b,de]=o.useState(null),[Te,W]=o.useState(!0),[Y,w]=o.useState(null),[Ee,Le]=o.useState(null),[n,hs]=o.useState(null),[I,bs]=o.useState([]),[fs,H]=o.useState(!1),[Re,G]=o.useState("select"),[D,L]=o.useState(null),[u,f]=o.useState(st),[gs,F]=o.useState(""),[Oe,Be]=o.useState(!1),[He,$]=o.useState(null),[Me,ee]=o.useState(!1),[ce,Ge]=o.useState(!1),[se,ie]=o.useState(""),[Se,qe]=o.useState(!1),[M,q]=o.useState([]),[ue,U]=o.useState(new Set),[_e,R]=o.useState(null),[me,te]=o.useState(""),[De,Ve]=o.useState(!1),[xe,O]=o.useState(null),We=o.useMemo(()=>{const s=me.trim().toLowerCase();return s?M.filter(a=>a.id.toLowerCase().includes(s)||a.name.toLowerCase().includes(s)):M},[M,me]),_=o.useCallback(async()=>{try{const s=await j.config.provider.get();s.success&&s.data&&(hs(s.data),bs(Array.isArray(s.data.entries)?s.data.entries:[]))}catch{}},[]),S=o.useCallback(async()=>{W(!0),w(null);try{const[s,a]=await Promise.all([j.models.list(),j.system.status()]);if(await _(),s.success&&s.data&&Array.isArray(s.data.models)&&Pe(s.data.models),a.success&&a.data){const l=a.data.models||{total:0,online:0,offline:0};de({overallStatus:l.offline===0?"healthy":l.online>0?"degraded":"unhealthy",healthRate:l.total>0?l.online/l.total:0,healthyInstances:l.online,totalInstances:l.total,totalRequests:0})}}catch{w(t("models.loadFailed"))}finally{W(!1)}},[_,t]);o.useEffect(()=>{S()},[S]),o.useEffect(()=>{const s=()=>{S(),_()};return window.addEventListener("models-updated",s),()=>window.removeEventListener("models-updated",s)},[S,_]);const pe=o.useCallback(s=>`${s.provider}:${s.id}`,[]),z=o.useMemo(()=>{const s=[...k];return s.find(a=>a.key==="custom")||s.push({key:"custom",name:"Custom",baseUrl:"",apiType:"openai-completions",defaultModel:"",isCustom:!0}),s},[k]),he=o.useMemo(()=>[...z].sort((s,a)=>{if(s.isCustom)return-1;if(a.isCustom)return 1;const l=we[s.key],c=we[a.key];return l!==void 0&&c!==void 0?l-c:l!==void 0?-1:c!==void 0?1:s.name.localeCompare(a.name)}),[z]),Ye=o.useMemo(()=>{const s=se.trim().toLowerCase();return s?he.filter(a=>a.name.toLowerCase().includes(s)||a.key.toLowerCase().includes(s)||(a.defaultModel||"").toLowerCase().includes(s)||(a.baseUrl||"").toLowerCase().includes(s)||(a.models||[]).some(l=>String(l).toLowerCase().includes(s))):he},[he,se]),E=o.useMemo(()=>{var c,r,d,i;const s=(n==null?void 0:n.providers)||{},a=new Set(z.map(m=>m.key)),l=Object.entries(s).filter(([m])=>!a.has(m));if(l.length!==0)return{keys:l.map(([m])=>m),modelCount:l.reduce((m,[,h])=>m+(h.modelCount||0),0),hasApiKey:l.some(([,m])=>m.hasApiKey),baseUrl:((r=(c=l.find(([,m])=>m.baseUrl))==null?void 0:c[1])==null?void 0:r.baseUrl)||"",apiType:((i=(d=l.find(([,m])=>m.apiType))==null?void 0:d[1])==null?void 0:i.apiType)||"openai-completions"}},[n,z]),V=D==="custom"?u.providerKey.trim():D||"",Ke=o.useMemo(()=>V?P.filter(s=>s.provider===V):[],[P,V]),vs=o.useMemo(()=>{const s=new Map;for(const l of P)s.has(l.provider)||s.set(l.provider,[]),s.get(l.provider).push(l);for(const l of I)s.has(l.key)||s.set(l.key,[]);const a=[...s.keys()];return a.sort((l,c)=>{const r=we[l],d=we[c];return r!==void 0&&d!==void 0?r-d:r!==void 0?-1:d!==void 0?1:l.localeCompare(c)}),a.map(l=>({provider:l,models:s.get(l)||[]}))},[P,I]),Qe=o.useCallback(s=>{var i,m;const a=(i=n==null?void 0:n.providers)==null?void 0:i[s.key],l=I.find(h=>h.key===s.key),c=P.filter(h=>h.provider===s.key).map(h=>h.id),r=((m=s.models)==null?void 0:m.slice(0,3).join(", "))||s.defaultModel,d=c.length>0?c.join(", "):r;L(s.key),F(""),f({providerKey:s.key,apiKeys:[""],modelIds:d,baseUrl:(a==null?void 0:a.baseUrl)||s.baseUrl,apiType:(a==null?void 0:a.apiType)||s.apiType,fullPath:(a==null?void 0:a.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s.key,modelOverrides:ze(l)}),G("form"),H(!0),$(null),ee(!1),q([]),U(new Set),R(null),te("")},[P,n,I]),ys=o.useCallback(s=>{var r;const a=(r=n==null?void 0:n.providers)==null?void 0:r[s],l=I.find(d=>d.key===s),c=P.filter(d=>d.provider===s).map(d=>d.id).join(", ");L("custom"),F(s),f({providerKey:s,apiKeys:[""],modelIds:c,baseUrl:(a==null?void 0:a.baseUrl)||"",apiType:(a==null?void 0:a.apiType)||"",fullPath:(a==null?void 0:a.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s,modelOverrides:ze(l)}),$(null),ee(!1),q([]),U(new Set),R(null),te("")},[n,P,I]),Ie=o.useCallback(()=>{L("custom"),F(""),f({providerKey:"",apiKeys:[""],modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!(n!=null&&n.configured),modelOverrides:{}}),G("form"),H(!0),$(null),ee(!1),q([]),U(new Set),R(null),te("")},[n]),js=o.useCallback(async()=>{var a;const s=u.baseUrl;if(!s){R(t("models.baseUrlRequired"));return}qe(!0),R(null),q([]),U(new Set);try{const l=(u.apiKeys||[]).map(d=>d.trim()).filter(Boolean)[0]||"",c=l.replace(/[^\x00-\xFF]/g,"");c!==l&&T.warning(t("models.apiKeySanitized"));const r=await j.models.fetch(s,c,u.fullPath===!0);if(r.success&&((a=r.data)!=null&&a.models)){const d=r.data.models;q(d);const i=new Set(d.map(v=>v.id)),m=u.modelIds.split(",").map(v=>v.trim()).filter(Boolean),h=m.filter(v=>i.has(v.split("|")[0].trim())),K=m.filter(v=>!i.has(v.split("|")[0].trim()));if(U(new Set(h.map(v=>v.split("|")[0].trim()))),K.length>0){const v=K.map(x=>x.split("|")[0].trim());f(x=>({...x,modelIds:h.join(", ")})),T.warning(t("models.autoRemovedMissingModels",{models:v.join(", ")}))}T.success(t("models.fetchedCount",{n:d.length}))}else R(r.error||t("models.fetchFailed"))}catch(l){R(l instanceof Error?l.message:t("models.requestFailed"))}finally{qe(!1)}},[u.baseUrl,u.apiKeys,u.modelIds,t]),ks=o.useCallback(async()=>{var a,l;const s=u.baseUrl;if(!s){O({ok:!1,message:t("models.baseUrlRequired")});return}Ve(!0),O(null);try{const c=(u.apiKeys||[]).map(i=>i.trim()).filter(Boolean)[0]||"",r=c.replace(/[^\x00-\xFF]/g,"");r!==c&&T.warning(t("models.apiKeySanitized"));const d=await j.providers.testConnection(s,r);if(d.success&&((a=d.data)!=null&&a.reachable)){const i=d.data,m={};i.resolvedBaseUrl&&i.resolvedBaseUrl!==u.baseUrl&&(m.baseUrl=i.resolvedBaseUrl),i.detectedApiType&&u.apiType===""&&(m.apiType=i.detectedApiType),Object.keys(m).length>0&&f(v=>({...v,...m}));const h=[];m.baseUrl&&h.push(t("models.baseUrlAutoCompleted",{url:m.baseUrl})),m.apiType&&h.push(t("models.apiTypeAutoSelected",{type:Ne[m.apiType]}));const K=i.message||t("models.connectionSuccess");O({ok:!0,message:h.length>0?t("models.connectionSuccessWithHints",{message:K,hints:h.join(t("models.hintJoiner"))}):K})}else O({ok:!1,message:((l=d.data)==null?void 0:l.message)||d.error||t("models.connectionFailed")})}catch(c){O({ok:!1,message:c instanceof Error?c.message:t("models.requestFailed")})}finally{Ve(!1)}},[u.baseUrl,u.apiKeys,u.apiType,t]),Ns=o.useCallback(s=>{const a=new Set(ue);a.has(s)?a.delete(s):a.add(s),U(a),f(l=>({...l,modelIds:Array.from(a).join(", ")}))},[ue]),ws=o.useCallback(s=>{const a=u.modelIds.split(",").map(d=>d.trim()).filter(Boolean),c=a.some(d=>Z(d)===s.id)?a.filter(d=>Z(d)!==s.id):[...a,s.name&&s.name!==s.id?`${s.id}|${s.name}`:s.id];f(d=>({...d,modelIds:c.join(", ")}));const r=new Set(M.map(d=>d.id));U(new Set(c.map(Z).filter(d=>r.has(d))))},[u.modelIds,M]),[Cs,Je]=o.useState(!1),[Ue,Xe]=o.useState(""),[Ze,be]=o.useState([]),[Ps,es]=o.useState(!1),[ss,fe]=o.useState(null),[ge,Ts]=o.useState(!1),[ve,Ms]=o.useState(!0),Ss=o.useCallback(()=>{Xe(""),be([]),fe(null),Je(!0),ae("",{reason:!1,tool:!0})},[]),ae=o.useCallback(async(s,a)=>{es(!0),fe(null);try{const l=await j.models.catalogSearch({q:s,reasoning:(a==null?void 0:a.reason)??!1,toolCall:(a==null?void 0:a.tool)??!0,limit:30});l.success&&l.data?be(l.data.hits||[]):(fe(l.error||t("models.catalogSearchFailed")),be([]))}catch(l){fe(l instanceof Error?l.message:t("models.requestFailed")),be([])}finally{es(!1)}},[t]),Ds=o.useCallback(s=>{f(a=>{const l=a.modelIds.split(",").map(c=>c.trim()).filter(Boolean);return l.includes(s.model.id)?a:{...a,modelIds:[...l,s.model.id].join(", ")}}),T.success(t("models.addedModel",{id:s.model.id}))},[t]),[Ae,Ks]=o.useState(null),Is=o.useCallback(s=>{Xe(s),Ae&&clearTimeout(Ae),Ks(setTimeout(()=>{ae(s,{reason:ge,tool:ve})},300))},[Ae,ge,ve,ae]),Us=async s=>{const a=s.provider,l=s.id,c=s.enabled!==!1,r=s.name||l,d=i=>c&&/default model/i.test(i);try{const i=await j.models.toggle(a,l);if(i.success){await S();return}const m=i.error||"";d(m)?T.error(t("models.defaultModelDisableBlocked",{name:r})):T.error(m||t("models.operationFailed"))}catch(i){const m=i instanceof Error?i.message:"";d(m)?T.error(t("models.defaultModelDisableBlocked",{name:r})):T.error(m||t("models.operationFailed"))}},As=async s=>{const a=pe(s);Le(a);try{await j.models.test(s.id),await S()}finally{Le(null)}},Fs=async(s,a)=>{if(confirm(t("models.deleteModelConfirm",{id:a})))try{(await j.models.delete(s,a)).success&&await S()}catch{}},ts=o.useCallback(s=>{var d;const a=I.find(i=>i.key===s),l=z.find(i=>i.key===s),c=!l||l.isCustom,r=(d=n==null?void 0:n.providers)==null?void 0:d[s];L(c?"custom":s),F(c?s:""),f({providerKey:s,apiKeys:[""],modelIds:(a==null?void 0:a.models.map(i=>i.name&&i.name!==i.id?`${i.id}|${i.name}`:i.id).join(", "))||"",baseUrl:(a==null?void 0:a.baseUrl)||(r==null?void 0:r.baseUrl)||(l==null?void 0:l.baseUrl)||"",apiType:(a==null?void 0:a.apiType)||(r==null?void 0:r.apiType)||(l==null?void 0:l.apiType)||"",fullPath:(a==null?void 0:a.fullPath)===!0||(r==null?void 0:r.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s,modelOverrides:ze(a)}),G("form"),H(!0),$(null),ee(!1),q([]),U(new Set),R(null),te("")},[I,z,n]),$s=s=>{ts(s.provider)},zs=async()=>{var ye,je;const s=z.find(p=>p.key===D)||null,a=D==="custom"?u.providerKey.trim():(s==null?void 0:s.key)||"";if(!a){$(t("models.providerNameRequired"));return}const l=(u.apiKeys||[]).map(p=>p.trim()).filter(Boolean),c=!!((je=(ye=n==null?void 0:n.providers)==null?void 0:ye[a])!=null&&je.hasApiKey);if(l.length===0&&!c){$(t("models.apiKeyRequired"));return}const r=s||{baseUrl:"",apiType:"openai-completions",defaultModel:""},d=l.map(p=>p.replace(/[^\x00-\xFF]/g,"")).filter(Boolean),i=M.length>0?new Set(M.map(p=>p.id)):null,m=(u.modelIds||r.defaultModel||"").split(",").map(p=>p.trim()).filter(Boolean),h=i?m.filter(p=>i.has(p.split("|")[0].trim())):m,K=i?m.filter(p=>!i.has(p.split("|")[0].trim())):[];K.length>0&&T.warning(t("models.autoSkippedMissingModels",{models:K.map(p=>p.split("|")[0].trim()).join(", ")}));const v=h.map(Z).filter(Boolean),x=new Set;for(const p of P)p.provider!==a||v.includes(p.id)||(p.isGlobalDefault&&x.add("global"),p.isPlanDefault&&x.add("plan"),p.isGoalDefault&&x.add("goal"));const le={provider:a,name:a,baseUrl:u.baseUrl||r.baseUrl,fullPath:u.fullPath===!0,apiType:u.apiType||tt(u.baseUrl||r.baseUrl)||r.apiType,models:h.map((p,J)=>{const N=p.trim().split("|").map(Rs=>Rs.trim()).filter(Boolean),A=N[0]||"",y=u.modelOverrides[A];return{id:A,name:N[1]||A,aliases:N.length>2?N.slice(2):void 0,enabled:!0,priority:10+J,...y!=null&&y.apiType?{apiType:y.apiType}:{},...y!=null&&y.baseUrl?{baseUrl:y.baseUrl}:{}}}).filter(p=>p.id.length>0)};d.length>0&&(le.apiKeys=d),(!(n!=null&&n.configured)||u.setDefault)&&(le.setDefault=!0),Be(!0),$(null);try{const p=await j.config.provider.save(le);if(p.success){if(x.size>0){const J=v[0]||"",N={};if(J){const A=`${a}:${J}`;for(const y of x)N[y]=A}else{const A=P.find(y=>y.provider!==a);for(const y of x)y==="plan"||y==="goal"?N[y]=null:A&&(N[y]=`${A.provider}:${A.id}`)}Object.keys(N).length>0&&(await j.models.setDefaults(N)).success&&T.success(t("models.defaultsAutoUpdated"))}H(!1),G("select"),L(null),F(""),await _(),await S()}else $(p.error||t("models.saveFailed"))}catch(p){$(p instanceof Error?p.message:t("models.unknownError"))}finally{Be(!1)}},as=async s=>{if(confirm(t("models.removeConfirm",{providerKey:s})))try{await j.config.provider.delete(s),await _(),await S()}catch{}},Es=s=>{switch(s){case"online":return"text-accent-green";case"offline":return"text-dark-muted";case"error":return"text-accent-red";default:return"text-dark-muted"}},Ls=s=>{switch(s){case"online":return e.jsx(Qs,{size:14});case"offline":return e.jsx(ms,{size:14});case"error":return e.jsx(Ys,{size:14});default:return e.jsx(ms,{size:14})}},Q=o.useMemo(()=>z.find(s=>s.key===D)||null,[D,z]);return Te?e.jsx("div",{className:"flex h-64 items-center justify-center text-dark-muted",children:t("models.loading")}):Y?e.jsx("div",{className:"flex h-64 items-center justify-center text-accent-red",children:Y}):e.jsx("div",{className:"ui-page flex-1 min-h-0",children:e.jsxs("div",{className:"ui-page-inner space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-base font-semibold",children:t("models.providerConfig")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:async()=>{try{await j.providers.refresh(),T.success(t("models.providerListRefreshed")),Ge(!0),await C(),setTimeout(()=>{C()},3e3)}catch{T.error(t("models.refreshFailed"))}},className:"btn btn-secondary px-3 py-2 text-xs",title:t("models.refreshListTitle"),children:[e.jsx(re,{size:12}),t("models.refreshList")]}),e.jsxs("button",{onClick:()=>{ce&&ie(""),Ge(s=>!s)},className:"btn btn-accent px-3 py-2 text-xs",children:[ce?e.jsx(Os,{size:12}):e.jsx(ke,{size:12}),t(ce?"models.collapse":"models.addProvider")]})]})]}),ce&&e.jsxs("div",{children:[e.jsxs("div",{className:"relative mb-3 max-w-md",children:[e.jsx(oe,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:se,onChange:s=>ie(s.target.value),className:"w-full pl-8 pr-8 py-1.5 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",placeholder:t("models.providerSearchPlaceholder")}),se&&e.jsx("button",{onClick:()=>ie(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-white",title:t("models.clear"),"aria-label":t("models.clearSearch"),children:e.jsx(Fe,{size:13})})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3 max-h-[420px] overflow-y-auto custom-scrollbar pr-1",children:g?e.jsxs("div",{className:"col-span-full flex items-center justify-center py-4 text-dark-muted text-sm",children:[e.jsx(Bs,{size:14,className:"mr-2 animate-spin"}),t("models.loadingProviders")]}):Ye.length===0?e.jsxs("div",{className:"col-span-full border border-accent-red/30 bg-accent-red/10 rounded-lg p-4 text-center",children:[e.jsx("div",{className:"text-sm text-accent-red font-medium mb-1",children:t("models.noMatchingProviders")}),e.jsx("div",{className:"text-xs text-dark-muted mb-3",children:t("models.noMatchingProvidersHint",{query:se})}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsxs("button",{onClick:()=>ie(""),className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-dark-border rounded hover:bg-dark-hover",children:[e.jsx(Fe,{size:12}),t("models.clearSearch")]}),e.jsxs("button",{onClick:Ie,className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs bg-accent-blue text-white rounded hover:opacity-90",children:[e.jsx(ke,{size:12}),t("models.addCustomProvider")]})]})]}):Ye.map(s=>{var d,i;const a=s.key==="custom",l=a?E:(d=n==null?void 0:n.providers)==null?void 0:d[s.key],c=l==null?void 0:l.hasApiKey,r=a?!!(n!=null&&n.defaultProvider)&&((E==null?void 0:E.keys)||[]).includes(n.defaultProvider):(n==null?void 0:n.defaultProvider)===s.key;return e.jsxs("div",{className:`ui-card-interactive text-left p-4 relative ${c?"border-accent-green/30 bg-dark-surface hover:border-accent-green/50":"border-dark-border bg-dark-surface hover:border-dark-hover"}`,children:[e.jsxs("div",{onClick:()=>s.key==="custom"?Ie():Qe(s),className:"cursor-pointer",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),c&&e.jsx(X,{size:14,className:"text-accent-green"})]}),e.jsxs("div",{className:"text-[10px] text-dark-muted space-y-0.5",children:[e.jsx("div",{className:"truncate",children:a?(l==null?void 0:l.baseUrl)||t("models.customBaseUrl"):s.baseUrl||t("models.customBaseUrl")}),e.jsx("div",{className:"truncate",children:a&&E?`${E.keys.join(", ")}`:s.defaultModel||t("models.noDefaultModel")}),e.jsxs("div",{children:[l?t("models.configuredCount",{n:l.modelCount}):t("models.availableCount",{n:((i=s.models)==null?void 0:i.length)||0}),s.models&&s.models.length>0&&!l&&e.jsx("span",{className:"text-accent-blue",children:" ✓"})]})]}),r&&e.jsx("div",{className:"mt-1 text-[10px] text-accent-red",children:t("models.defaultProviderBadge")})]}),c&&s.key!=="custom"&&e.jsx("button",{onClick:m=>{m.stopPropagation(),as(s.key)},className:"absolute top-1.5 right-1.5 p-1 rounded text-dark-muted hover:bg-accent-red/10 hover:text-accent-red transition-colors",title:t("models.deleteProvider"),"aria-label":t("models.deleteProviderNamed",{name:s.name}),children:e.jsx($e,{size:13})})]},s.key)})})]})]}),b&&e.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[e.jsx(Ce,{title:t("models.overallStatus"),value:b.totalInstances===0?t("models.notConfigured"):b.overallStatus==="healthy"?t("models.healthy"):b.overallStatus==="degraded"?t("models.degraded"):t("models.abnormal"),color:b.totalInstances===0?"blue":b.overallStatus==="healthy"?"green":b.overallStatus==="degraded"?"yellow":"red"}),e.jsx(Ce,{title:t("models.healthRate"),value:b.totalInstances===0?"N/A":`${(b.healthRate*100).toFixed(0)}%`,color:b.totalInstances===0?"blue":b.healthRate>.8?"green":b.healthRate>.5?"yellow":"red"}),e.jsx(Ce,{title:t("models.onlineInstances"),value:b.totalInstances===0?t("models.none"):`${b.healthyInstances}/${b.totalInstances}`,color:b.healthyInstances>0?"green":"red"}),e.jsx(Ce,{title:t("models.totalRequests"),value:b.totalRequests>0?b.totalRequests.toLocaleString():"0",color:"blue"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("models.configuredModels")}),e.jsx("span",{className:"text-[10px] text-dark-muted",title:t("models.actIsGlobalHint"),children:t("models.actIsGlobalHint")})]}),e.jsxs("div",{className:"space-y-4 max-h-[640px] overflow-y-auto custom-scrollbar pr-1",children:[vs.map(s=>{var c;const a=I.find(r=>r.key===s.provider),l=(c=n==null?void 0:n.providers)==null?void 0:c[s.provider];return e.jsxs("div",{className:"rounded-lg border border-dark-border overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 bg-dark-bg border-b border-dark-border",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[e.jsx("span",{className:"text-xs font-semibold whitespace-nowrap text-accent-purple",children:s.provider}),(n==null?void 0:n.defaultProvider)===s.provider&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red whitespace-nowrap",children:t("models.defaultShort")}),e.jsx("span",{className:"text-[10px] text-dark-muted truncate",children:(l==null?void 0:l.baseUrl)||(a==null?void 0:a.baseUrl)||""}),e.jsx("span",{className:"text-[10px] text-dark-muted whitespace-nowrap",children:(a==null?void 0:a.apiType)||(l==null?void 0:l.apiType)||""}),l!=null&&l.hasApiKey||a!=null&&a.hasApiKey?e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-green/20 text-accent-green whitespace-nowrap",children:t("models.hasKey")}):e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red whitespace-nowrap",children:t("models.noKey")})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>ts(s.provider),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:t("models.editProviderNamed",{name:s.provider}),children:e.jsx(us,{size:13})}),e.jsx("button",{onClick:()=>as(s.provider),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:t("models.deleteProviderNamed",{name:s.provider}),children:e.jsx($e,{size:13})})]})]}),e.jsxs("div",{className:"space-y-2 p-2 bg-dark-surface/40",children:[s.models.map(r=>{var m,h,K,v;const d=a==null?void 0:a.models.find(x=>x.id===r.id),i=!!(d!=null&&d.apiType&&d.apiType!==(a==null?void 0:a.apiType));return e.jsx("div",{className:`bg-dark-surface border rounded-lg p-3 ${r.status==="online"?"border-accent-green":"border-dark-border"} ${r.enabled===!1?"opacity-60":""}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:Es(r.status),children:Ls(r.status)}),e.jsx("span",{className:"font-medium text-sm text-accent-blue",children:r.name}),e.jsx("span",{className:"text-[10px] text-accent-purple px-1.5 py-0.5 bg-accent-purple/10 rounded",children:r.provider}),r.apiType&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${r.apiType==="anthropic-messages"||r.apiType==="openai-responses"?"bg-accent-purple/20 text-accent-purple":"bg-accent-blue/20 text-accent-blue"}`,children:Ne[r.apiType]||r.apiType}),i&&e.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",title:t("models.overrideTitle"),children:t("models.overrideBadge")}),r.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red font-medium",title:t("models.globalDefaultUnsettable"),children:t("chat.globalDefault")}),r.isPlanDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue font-medium",children:t("chat.planDefault")}),r.isActDefault&&!r.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",children:t("chat.actDefault")}),r.isGoalDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-purple/20 text-accent-purple font-medium",children:t("chat.goalDefault")})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[e.jsx(B,{label:t("models.loadLabel"),value:`${r.load}/${r.maxLoad}`}),e.jsx(B,{label:t("models.tokenUsageLabel"),value:`${ne(r.tokens)}/${ne(r.maxTokens)}`}),e.jsx(B,{label:t("models.inputPrice"),value:`$${r.price.input}/M`}),e.jsx(B,{label:t("models.outputPrice"),value:`$${r.price.output}/M`})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[e.jsx(B,{label:t("models.inputTokensLabel"),value:ne(((m=r.usage)==null?void 0:m.input)??0)}),e.jsx(B,{label:t("models.outputTokensLabel"),value:ne(((h=r.usage)==null?void 0:h.output)??0)}),e.jsx(B,{label:t("models.totalTokensLabel"),value:ne(((K=r.usage)==null?void 0:K.total)??0)}),e.jsx(B,{label:t("models.usageRequestsLabel"),value:String(((v=r.usage)==null?void 0:v.requests)??0)})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[et.map(x=>{const le=x.key==="global"?r.isGlobalDefault:x.key==="plan"?r.isPlanDefault:r.isGoalDefault,ye=x.key==="global"?t("models.setGlobalDefaultTitle"):x.key==="plan"?t("models.setPlanDefaultTitle"):t("models.setGoalDefaultTitle"),je=x.key==="plan"?t("models.unsetPlanDefaultTitle"):t("models.unsetGoalDefaultTitle"),p=x.key==="plan"?t("models.unsetPlanDefaultFailed"):t("models.unsetGoalDefaultFailed"),J=x.key==="plan"?t("models.setPlanDefaultFailed"):t("models.setGoalDefaultFailed");return le?x.key==="global"?e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded text-[10px] border ${x.bg} ${x.color} font-medium`,title:t("chat.globalDefault"),children:[e.jsx(X,{size:11}),t(x.labelKey)]},x.key):e.jsxs("button",{onClick:async()=>{try{await j.models.setDefaults({[x.key]:null}),await S()}catch(N){w(N instanceof Error?N.message:p)}},className:`inline-flex items-center gap-1 px-2 py-1 rounded text-[10px] border ${x.bg} ${x.color} font-medium cursor-pointer hover:opacity-80`,title:je,children:[e.jsx(X,{size:11}),t(x.labelKey)]},x.key):r.enabled===!1?null:e.jsx("button",{onClick:async()=>{try{await j.models.setDefaults({[x.key]:`${r.provider}:${r.id}`}),await S()}catch(N){w(N instanceof Error?N.message:J)}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:text-dark-text hover:border-dark-hover",title:ye,children:t(x.labelKey)},x.key)}),e.jsx("button",{onClick:()=>$s(r),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:t("models.editModel"),children:e.jsx(us,{size:13})}),e.jsx("button",{onClick:()=>Fs(r.provider,r.id),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:t("models.deleteModel"),children:e.jsx($e,{size:13})}),e.jsx("button",{onClick:()=>As(r),disabled:Ee===pe(r),className:"p-1.5 rounded hover:bg-dark-hover disabled:opacity-50",title:t("models.refresh"),children:e.jsx(re,{size:13,className:Ee===pe(r)?"animate-spin":""})}),e.jsx("button",{onClick:()=>Us(r),className:`px-2 py-0.5 rounded text-xs transition-colors ${r.enabled===!1?"bg-accent-green/20 text-accent-green hover:bg-accent-green/30":"bg-accent-red/20 text-accent-red hover:bg-accent-red/30"}`,children:r.enabled===!1?t("models.enable"):t("models.disable")})]})]})},pe(r))}),s.models.length===0&&e.jsx("div",{className:"text-center text-[11px] text-dark-muted py-3",children:t("models.noModelsInProvider")})]})]},s.provider)}),P.length===0&&I.length===0&&e.jsxs("div",{className:"text-center text-dark-muted py-6",children:[e.jsx(Hs,{size:36,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:t("models.emptyHint")})]})]})]}),e.jsx(xs,{isOpen:fs,onClose:()=>{H(!1),G("select"),L(null),F("")},title:Re==="select"?t("chat.selectProvider"):(Q==null?void 0:Q.name)||t("models.providerConfig"),size:"xl",children:Re==="select"?e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[he.filter(s=>s.key!=="custom").map(s=>e.jsxs("button",{onClick:()=>Qe(s),className:"text-left p-3 rounded-lg border border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(X,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium",children:s.name})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:s.defaultModel})]},s.key)),e.jsxs("button",{onClick:Ie,className:"text-left p-3 rounded-lg border border-dashed border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Gs,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium",children:t("models.customProvider")})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("models.customProviderDesc")})]})]})}):e.jsxs("div",{className:"space-y-3",children:[D==="custom"&&e.jsxs("div",{className:"space-y-3",children:[E&&E.keys.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.editExistingConfig")}),e.jsxs("select",{value:gs,onChange:s=>{const a=s.target.value;a?ys(a):(F(""),f(l=>({...l,providerKey:"",modelIds:"",baseUrl:"",apiType:"",apiKeys:[""]})))},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:t("models.newCustomProviderOption")}),E.keys.map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.editExistingConfigHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.providerNameLabel")}),e.jsx("input",{value:u.providerKey,onChange:s=>f(a=>({...a,providerKey:s.target.value})),className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:t("models.providerNamePlaceholder")})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:["API Keys",(rs=(ls=n==null?void 0:n.providers)==null?void 0:ls[D==="custom"?u.providerKey.trim():D||""])!=null&&rs.hasApiKey?"":" *",e.jsx("span",{className:"text-dark-muted/60 text-xs",children:(ns=(os=n==null?void 0:n.providers)==null?void 0:os[D==="custom"?u.providerKey.trim():D||""])!=null&&ns.hasApiKey?t("models.apiKeysHintConfigured"):t("models.apiKeysHintNew")})]}),e.jsx("div",{className:"space-y-1.5",children:((ds=u.apiKeys)!=null&&ds.length?u.apiKeys:[""]).map((s,a)=>e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:Me?"text":"password",value:s,autoComplete:"off",spellCheck:!1,onChange:l=>f(c=>({...c,apiKeys:c.apiKeys.map((r,d)=>d===a?l.target.value:r)})),className:"w-full px-3 py-2 pr-9 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:t("models.apiKeyDefaultPlaceholder")}),e.jsx("button",{type:"button",onClick:()=>ee(l=>!l),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-white",title:t(Me?"models.hideKeyTitle":"models.showKeyTitle"),children:Me?e.jsx(qs,{size:14}):e.jsx(_s,{size:14})})]}),a===0?e.jsxs("button",{type:"button",onClick:()=>f(l=>({...l,apiKeys:[...l.apiKeys,""]})),className:"shrink-0 inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-dashed border-dark-border text-dark-muted hover:text-accent-blue hover:border-accent-blue/50 transition-colors",title:t("models.addApiKeyTitle"),children:[e.jsx(ke,{size:14}),e.jsx("span",{className:"hidden sm:inline",children:t("models.addApiKey")})]}):e.jsx("button",{type:"button",onClick:()=>f(l=>({...l,apiKeys:l.apiKeys.filter((c,r)=>r!==a)})),className:"shrink-0 inline-flex items-center px-3 py-2 rounded text-sm text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors",title:t("models.removeApiKeyTitle"),children:e.jsx(Fe,{size:14})})]},a))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.modelIdLabel")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:u.modelIds,onChange:s=>{const a=s.target.value;f(l=>({...l,modelIds:a})),U(()=>{const l=new Set;for(const c of a.split(",")){const r=c.trim().split("|")[0].trim();r&&M.some(d=>d.id===r)&&l.add(r)}return l})},className:"flex-1 px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:(Q==null?void 0:Q.defaultModel)||t("models.modelIdPlaceholder")}),e.jsxs("button",{onClick:js,disabled:Se||!u.baseUrl,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-blue/30 text-accent-blue hover:bg-accent-blue/10 disabled:opacity-50 whitespace-nowrap",title:t("models.fetchModelsTitle"),children:[Se?e.jsx(re,{size:13,className:"animate-spin"}):e.jsx(Vs,{size:13}),t(Se?"models.fetchingModels":"models.fetchModels")]}),e.jsxs("button",{onClick:ks,disabled:De||!u.baseUrl,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-yellow/30 text-accent-yellow hover:bg-accent-yellow/10 disabled:opacity-50 whitespace-nowrap",title:t("models.testConnectionTitle"),children:[De?e.jsx(re,{size:13,className:"animate-spin"}):e.jsx(Ws,{size:13}),t(De?"models.testingConnection":"models.testConnection")]}),e.jsxs("button",{onClick:Ss,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-green/30 text-accent-green hover:bg-accent-green/10 whitespace-nowrap",title:t("models.catalogSearchTitle"),children:[e.jsx(oe,{size:13}),t("models.catalogSearch")]})]}),xe&&e.jsxs("div",{className:`mt-1 text-xs ${xe.ok?"text-accent-green":"text-accent-red"}`,children:[xe.ok?"✓ ":"✗ ",xe.message]}),_e&&e.jsx("div",{className:"mt-1 text-xs text-accent-red",children:_e}),M.length===0&&Ke.length>0&&e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("models.configuredPanelPrefix"),e.jsx("strong",{className:"text-dark-text",children:Ke.length}),t("models.configuredPanelSuffix"),e.jsx("span",{className:"text-accent-green/70",children:t("models.configuredPanelHint")})]})}),e.jsx("div",{className:"max-h-48 overflow-y-auto custom-scrollbar grid grid-cols-2 sm:grid-cols-3 gap-1",children:Ke.map(s=>{const a=u.modelIds.split(",").map(Z).filter(Boolean).includes(s.id);return e.jsxs("div",{role:"checkbox","aria-checked":a,title:s.name&&s.name!==s.id?`${s.id} — ${s.name}`:s.name||s.id,tabIndex:-1,onMouseDown:l=>l.preventDefault(),onClick:()=>ws(s),className:`flex items-start gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${a?"bg-accent-green/20 text-accent-green border border-accent-green/30":"hover:bg-dark-hover border border-transparent"}`,children:[e.jsx("span",{className:"shrink-0 mt-[3px]",children:a?e.jsx(X,{size:10}):e.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"})}),e.jsx("span",{className:"min-w-0 flex-1 break-words leading-snug",children:s.name||s.id}),s.isGlobalDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-red/20 text-accent-red shrink-0",children:t("models.globalShort")}),s.isPlanDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-blue/20 shrink-0",children:"Plan"}),s.isActDefault&&!s.isGlobalDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-yellow/20 shrink-0",children:"Act"}),s.isGoalDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-purple/20 shrink-0",children:"Goal"})]},s.id)})})]}),M.length>0&&e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("models.fetchedPanelPrefix"),e.jsx("strong",{className:"text-dark-text",children:M.length}),t("models.fetchedPanelMiddle"),e.jsx("strong",{className:"text-accent-blue",children:ue.size}),t("models.fetchedPanelSuffix"),e.jsx("span",{className:"text-accent-blue/70",children:t("models.fetchedPanelHint")})]}),e.jsx("button",{onClick:()=>{q([]),U(new Set)},className:"px-2 py-0.5 text-[10px] border border-dark-border rounded hover:bg-dark-hover",children:t("models.close")})]}),e.jsxs("div",{className:"relative mb-2",children:[e.jsx(oe,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:me,onChange:s=>te(s.target.value),className:"w-full pl-7 pr-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",placeholder:t("models.modelSearchPlaceholder")})]}),me.trim()!==""&&e.jsxs("div",{className:"mb-1 text-[10px] text-dark-muted",children:[t("models.searchMatchPrefix"),e.jsx("strong",{className:"text-accent-blue",children:We.length}),t("models.searchMatchSuffix",{total:M.length})]}),e.jsx("div",{className:"max-h-72 overflow-y-auto custom-scrollbar grid grid-cols-1 sm:grid-cols-2 gap-1",children:We.map(s=>{const a=ue.has(s.id);return e.jsxs("div",{role:"checkbox","aria-checked":a,title:s.name&&s.name!==s.id?`${s.id} — ${s.name}`:s.id,tabIndex:-1,onMouseDown:l=>l.preventDefault(),onClick:()=>Ns(s.id),className:`flex items-start gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${a?"bg-accent-blue/20 text-accent-blue border border-accent-blue/30":"hover:bg-dark-hover border border-transparent"}`,children:[e.jsx("span",{className:"shrink-0 mt-[3px]",children:a?e.jsx(X,{size:10}):e.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"})}),e.jsx("span",{className:"min-w-0 flex-1 break-all leading-snug",children:s.id})]},s.id)})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"Base URL"}),e.jsx("input",{value:u.baseUrl,onChange:s=>{f(a=>({...a,baseUrl:s.target.value})),O(null)},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:"https://api.example.com/v1"}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none mt-2",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":u.fullPath,onClick:()=>{f(s=>({...s,fullPath:!s.fullPath})),O(null)},className:`relative w-9 h-5 rounded-full transition-colors shrink-0 ${u.fullPath?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${u.fullPath?"translate-x-[18px]":"translate-x-0.5"}`})}),e.jsx("span",{className:"text-sm text-dark-muted",children:t("models.fullPathLabel")})]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.fullPathHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.apiTypeLabel")}),e.jsxs("select",{value:u.apiType,onChange:s=>{f(a=>({...a,apiType:s.target.value})),O(null)},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:t("models.apiTypeAutoDetect")}),ps.map(s=>e.jsx("option",{value:s,children:Ne[s]},s))]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.apiTypeHint")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:[t("models.modelApiTypeLabel"),e.jsx("span",{className:"text-dark-muted/60 text-xs",children:t("models.modelApiTypeHint")})]}),e.jsx("div",{className:"border border-dark-border rounded-lg divide-y divide-dark-border max-h-40 overflow-y-auto custom-scrollbar",children:(()=>{const s=u.modelIds.split(",").map(Z).filter(Boolean);return s.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t("models.modelApiTypeEmpty")}):s.map(a=>{var l;return e.jsxs("div",{className:"flex items-start justify-between gap-2 px-3 py-1.5",children:[e.jsx("span",{className:"text-xs min-w-0 flex-1 break-all leading-snug",title:a,children:a}),e.jsxs("select",{value:((l=u.modelOverrides[a])==null?void 0:l.apiType)||"",onChange:c=>f(r=>({...r,modelOverrides:{...r.modelOverrides,[a]:{...r.modelOverrides[a]||{},apiType:c.target.value}}})),className:"w-52 px-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:"继承 Provider(默认)"}),ps.map(c=>e.jsx("option",{value:c,children:Ne[c]},c))]})]},a)})})()})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:u.setDefault,onChange:s=>f(a=>({...a,setDefault:s.target.checked})),className:"accent-accent-blue"}),e.jsx("span",{className:"text-sm text-dark-muted",children:t("models.setDefaultProvider")})]}),He&&e.jsx("div",{className:"text-sm text-accent-red",children:He}),e.jsxs("div",{className:"flex justify-between gap-2 pt-2",children:[e.jsx("div",{children:V&&((is=(cs=n==null?void 0:n.providers)==null?void 0:cs[V])==null?void 0:is.hasApiKey)&&e.jsx("button",{onClick:async()=>{if(confirm(t("models.deleteProviderConfirm",{key:V})))try{await j.config.provider.delete(V),H(!1),G("select"),L(null),F(""),await _(),await S()}catch{}},className:"px-4 py-2 rounded border border-accent-red/30 text-accent-red hover:bg-accent-red/10 transition-colors text-sm",children:t("models.deleteProvider")})}),e.jsx("button",{onClick:()=>{G("select"),L(null),F(""),H(!1)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:t("common.cancel")}),e.jsx("button",{onClick:zs,disabled:Oe,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:t(Oe?"common.saving":"common.save")})]})]})}),e.jsx(xs,{isOpen:Cs,onClose:()=>Je(!1),title:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(oe,{size:15,className:"text-accent-green"}),t("models.catalogTitle")]}),size:"2xl",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(oe,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:Ue,onChange:s=>Is(s.target.value),className:"w-full pl-9 pr-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-green",placeholder:t("models.catalogSearchPlaceholder"),autoFocus:!0})]}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:ve,onChange:s=>{const a=s.target.checked;Ms(a),ae(Ue,{reason:ge,tool:a})},className:"accent-accent-green"}),t("models.catalogOnlyToolCall")]}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:ge,onChange:s=>{const a=s.target.checked;Ts(a),ae(Ue,{reason:a,tool:ve})},className:"accent-accent-green"}),t("models.catalogOnlyReasoning")]})]}),ss&&e.jsx("div",{className:"text-xs text-accent-red bg-accent-red/10 p-2 rounded",children:ss}),Ps?e.jsxs("div",{className:"flex items-center justify-center py-10 text-dark-muted",children:[e.jsx(re,{size:18,className:"animate-spin mr-2"})," ",t("models.searching")]}):e.jsx("div",{className:"max-h-96 overflow-y-auto custom-scrollbar border border-dark-border rounded-lg divide-y divide-dark-border",children:Ze.length===0?e.jsx("div",{className:"py-10 text-center text-dark-muted text-sm",children:t("models.catalogNoResults")}):Ze.map(s=>{var a,l,c;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 hover:bg-dark-hover",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-dark-text truncate",children:s.model.name||s.model.id}),e.jsx("code",{className:"text-[10px] px-1.5 py-0.5 bg-dark-bg border border-dark-border rounded text-dark-muted truncate",children:s.model.id}),s.model.reasoning&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-yellow/10 text-accent-yellow rounded",children:t("models.badgeReasoning")}),s.model.tool_call&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-blue/10 text-accent-blue rounded",children:t("models.badgeToolCall")}),s.model.attachment&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-green/10 text-accent-green rounded",children:t("models.badgeMultimodal")})]}),e.jsxs("div",{className:"text-[11px] text-dark-muted mt-0.5",children:[s.providerName,(a=s.model.limit)!=null&&a.context?` · ${t("models.ctxLimit",{k:(s.model.limit.context/1e3).toFixed(0)})}`:"",(l=s.model.limit)!=null&&l.output?` · ${t("models.outLimit",{k:(s.model.limit.output/1e3).toFixed(0)})}`:"",((c=s.model.cost)==null?void 0:c.input)!==void 0?` · $${s.model.cost.input}/M in / $${s.model.cost.output}/M out`:""]})]}),e.jsxs("button",{onClick:()=>Ds(s),className:"shrink-0 inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-accent-green/30 text-accent-green rounded hover:bg-accent-green/10 whitespace-nowrap",title:t("models.catalogAddTitle"),children:[e.jsx(ke,{size:12})," ",t("models.add")]})]},`${s.providerId}:${s.model.id}`)})}),e.jsx("div",{className:"text-[11px] text-dark-muted/60",children:t("models.catalogSourceHint")})]})})]})})}function Ce({title:k,value:g,color:C}){const t={green:"bg-accent-green/10 text-accent-green",yellow:"bg-accent-yellow/10 text-accent-yellow",red:"bg-accent-red/10 text-accent-red",blue:"bg-accent-blue/10 text-accent-blue"};return e.jsxs("div",{className:`${t[C]} rounded-lg p-3`,children:[e.jsx("div",{className:"text-xs opacity-70",children:k}),e.jsx("div",{className:"text-xl font-semibold",children:g})]})}function B({label:k,value:g}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-dark-muted",children:k}),e.jsx("div",{children:g})]})}export{ct as ModelsView,ct as default};
@@ -1 +0,0 @@
1
- import{j as t}from"./markdown-DEtuzEyz.js";import{a as s,ax as be,h as me,af as ge,X as J,A as he,k as W,bs as ke,bp as ve,aE as fe,a2 as ee,a4 as je,ad as ye}from"./icons-f1hlMKvD.js";import{u as Ne,ac as p,C as Ce}from"./index-u1vYyqna.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";const I=12,we="other",Se=[{value:"all"},{value:"builtin"},{value:"openclaw"},{value:"deepseek-harness"}];function $e(a){return a==="wired"?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":a==="pending"||a==="pending_wiring"?"bg-amber-500/15 text-amber-400 border-amber-500/30":"bg-dark-hover text-dark-muted border-dark-border"}function te(a){var n;return((n=a.category)==null?void 0:n.trim())||we}function Me(a,n){const f=n.trim().toLowerCase();return f?[a.id,a.name,a.description,a.category,...a.tags??[]].filter(S=>typeof S=="string").join(" ").toLowerCase().includes(f):!0}function Re(){const{t:a}=Ne(),[n,f]=s.useState("installed"),[b,S]=s.useState([]),[R,re]=s.useState([]),[F,ae]=s.useState(null),[j,L]=s.useState(!0),[$,O]=s.useState(null),[i,B]=s.useState(null),[M,U]=s.useState(null),[y,V]=s.useState(null),[N,P]=s.useState(null),[_,q]=s.useState(null),[m,D]=s.useState(""),[o,se]=s.useState(null),[c,le]=s.useState(null),[u,z]=s.useState(1),x=s.useCallback((e,r)=>{V({kind:e,text:r}),window.setTimeout(()=>V(null),4e3)},[]),g=s.useCallback(async()=>{L(!0),O(null);const[e,r]=await Promise.all([p.get("/api/plugins"),p.get("/api/plugins/market")]);e.success&&e.data?(S(e.data.plugins),ae(e.data.schemaVersion??null)):O(e.error??"Failed to load plugins"),r.success&&r.data&&re(r.data.plugins),L(!1)},[]);s.useEffect(()=>{g()},[g]);const T=s.useMemo(()=>b.filter(e=>e.installable!==!0),[b]),h=s.useMemo(()=>[...b.filter(e=>e.installable===!0),...R.filter(e=>!b.some(r=>r.id===e.id||r.marketId===e.id))],[b,R]),C=s.useCallback(e=>e.filter(r=>o&&te(r)!==o||c&&(r.market??null)!==c?!1:Me(r,m)),[o,m,c]),k=s.useMemo(()=>C(T),[C,T]),v=s.useMemo(()=>C(h),[C,h]),G=s.useMemo(()=>{const e=new Set;for(const r of h)e.add(te(r));return["all",...Array.from(e).sort()]},[h]),H=e=>Math.max(1,Math.ceil(e/I)),K=(e,r)=>e.slice((r-1)*I,r*I),A=H(k.length),E=H(v.length),ne=s.useMemo(()=>K(k,Math.min(u,A)),[k,u,A]),de=s.useMemo(()=>K(v,Math.min(u,E)),[v,u,E]);s.useEffect(()=>{z(1)},[n,m,o,c]);const ie=m.trim().length>0||o!==null||c!==null,w=s.useCallback(async(e,r,d)=>{B(e),U(r);try{const l=await d();l&&l.success===!1?x("err",String(l.error??"Request failed")):(x("ok",`${r} ${e} ✓`),await g())}catch(l){x("err",l instanceof Error?l.message:String(l))}finally{B(null),U(null)}},[g,x]),Q=(e,r)=>w(e,r?"installed+activated":"installed",()=>p.post("/api/plugins/install",{id:e,activate:r})),oe=e=>w(e,"activated",()=>p.post(`/api/plugins/${encodeURIComponent(e)}/activate`)),ce=e=>w(e,"deactivated",()=>p.post(`/api/plugins/${encodeURIComponent(e)}/deactivate`)),ue=e=>w(e,"uninstalled",()=>p.delete(`/api/plugins/${encodeURIComponent(e)}`)),xe=async e=>{q(e);try{const r=await p.post(`/api/plugins/l2/provider/${encodeURIComponent(e)}`);r.success&&r.data?(x("ok",`Provider ${r.data.applied} applied to config ✓`),await g()):x("err",r.error??"Apply failed")}catch(r){x("err",r instanceof Error?r.message:String(r))}finally{q(null)}},X=e=>{const r=e==="bundled"?"bg-blue-500/15 text-blue-400 border-blue-500/30":e==="npm"?"bg-purple-500/15 text-purple-400 border-purple-500/30":e==="local"?"bg-cyan-500/15 text-cyan-400 border-cyan-500/30":"bg-dark-hover text-dark-muted border-dark-border";return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border ${r}`,children:e})},pe=e=>{if(!e)return null;const r=e==="builtin"?"bg-dark-hover text-dark-muted border-dark-border":e==="openclaw"?"bg-amber-500/15 text-amber-400 border-amber-500/30":e==="deepseek-harness"?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":"bg-dark-hover text-dark-muted border-dark-border";return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border ${r}`,children:e})},Y=(e,r)=>r>1?t.jsxs("div",{className:"flex items-center justify-center gap-3 pt-3 pb-1 select-none",children:[t.jsxs("button",{onClick:()=>z(d=>Math.max(1,d-1)),disabled:u<=1,className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border bg-dark-hover text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[t.jsx(je,{size:12})," ",a("plugins.prevPage")]}),t.jsx("span",{className:"text-[11px] text-dark-muted",children:a("plugins.pageInfo",{page:Math.min(u,r),pages:r,count:e})}),t.jsxs("button",{onClick:()=>z(d=>Math.min(r,d+1)),disabled:u>=r,className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border bg-dark-hover text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[a("plugins.nextPage")," ",t.jsx(ye,{size:12})]})]}):null,Z=e=>t.jsx("div",{className:"mt-8 text-center text-[12px] text-dark-muted",children:ie?a("plugins.noMatch"):e});return t.jsxs("div",{className:"h-full flex flex-col min-h-0 bg-dark-bg",children:[t.jsxs("div",{className:"h-11 flex items-center gap-2 px-3 border-b border-dark-border bg-dark-bg shrink-0 select-none",children:[t.jsx(be,{size:15,className:"text-accent-blue"}),t.jsx("span",{className:"truncate text-[13px] font-medium text-dark-text",children:a("nav.plugins")}),F!==null&&t.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-dark-hover text-dark-muted border border-dark-border",children:["schema v",F]}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:()=>void g(),className:"p-1.5 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text transition-colors",title:"Refresh",children:t.jsx(me,{size:14,className:j?"animate-spin":""})})]}),t.jsx("div",{className:"flex items-center gap-1 px-3 pt-2 shrink-0",children:["installed","available"].map(e=>t.jsx("button",{onClick:()=>f(e),className:`px-3 py-1.5 rounded-t text-[12px] transition-colors ${n===e?"bg-dark-surface text-accent-blue border border-b-0 border-dark-border":"text-dark-muted hover:text-dark-text"}`,children:e==="installed"?a("plugins.installedTab",{count:T.length}):a("plugins.availableTab",{count:h.length})},e))}),t.jsxs("div",{className:"shrink-0 px-3 pt-2 pb-1 space-y-2 bg-dark-bg",children:[t.jsxs("div",{className:"relative",children:[t.jsx(ge,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted pointer-events-none"}),t.jsx("input",{value:m,onChange:e=>D(e.target.value),placeholder:a("plugins.searchPlaceholder"),className:"w-full pl-8 pr-8 py-1.5 rounded bg-dark-hover border border-dark-border text-[12px] text-dark-text placeholder-dark-muted outline-none focus:border-accent-blue/50 transition-colors"}),m&&t.jsx("button",{onClick:()=>D(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-dark-muted hover:text-dark-text transition-colors",title:a("plugins.clear"),children:t.jsx(J,{size:12})})]}),n==="available"&&G.length>2&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:G.map(e=>t.jsx("button",{onClick:()=>se(e==="all"?null:e),className:`px-2 py-0.5 rounded-full text-[11px] border transition-colors ${e==="all"&&o===null||o===e?"bg-accent-blue/20 text-accent-blue border-accent-blue/40":"bg-dark-hover text-dark-muted border-dark-border hover:text-dark-text"}`,children:e==="all"?a("plugins.allCategories"):e},e))}),n==="available"&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:Se.map(e=>{const r=e.value==="all"?a("plugins.marketFilterAll"):e.value==="builtin"?a("plugins.marketFilterBuiltin"):e.value;return t.jsx("button",{onClick:()=>le(e.value==="all"?null:e.value),className:`px-2 py-0.5 rounded-full text-[11px] border transition-colors ${e.value==="all"&&c===null||c===e.value?"bg-accent-blue/20 text-accent-blue border-accent-blue/40":"bg-dark-hover text-dark-muted border-dark-border hover:text-dark-text"}`,children:r},e.value)})})]}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-3 pb-4",children:[$&&t.jsxs("div",{className:"mt-3 flex items-center gap-2 px-3 py-2 rounded bg-red-500/10 border border-red-500/30 text-red-400 text-[12px]",children:[t.jsx(he,{size:14})," ",$]}),j&&!$&&t.jsx("div",{className:"mt-10 flex justify-center",children:t.jsx("div",{className:"w-5 h-5 border-2 border-accent-blue border-t-transparent rounded-full animate-spin"})}),!j&&n==="installed"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[k.length===0&&Z(a("plugins.emptyInstalled")),ne.map(e=>{const r=e.l2??[],d=e.status==="active";return t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-medium text-dark-text truncate",children:e.name||e.id}),e.version&&t.jsx("span",{className:"text-[11px] text-dark-muted shrink-0",children:e.version}),X(e.source),t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border shrink-0 ${d?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":"bg-dark-hover text-dark-muted border-dark-border"}`,children:d?"active":"installed"}),e.httpMounted&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[11px] bg-emerald-500/15 text-emerald-400 border border-emerald-500/30 shrink-0",children:"http mounted"}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-[11px] text-dark-muted font-mono shrink-0",children:e.id})]}),e.description&&t.jsx("p",{className:"mt-1 text-[12px] text-dark-muted",children:e.description}),r.length>0&&t.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[r.map(l=>t.jsxs("span",{title:l.note||l.id,className:`px-1.5 py-0.5 rounded text-[11px] border cursor-help ${$e(l.status)}`,children:[l.kind," · ",l.status,l.status==="wired"&&t.jsx(W,{size:10,className:"inline ml-0.5"})]},`${l.kind}-${l.id}`)),r.filter(l=>l.kind==="provider"&&l.status==="wired").map(l=>t.jsx("button",{disabled:_===l.id,onClick:()=>void xe(l.id),className:"px-1.5 py-0.5 rounded text-[11px] border border-accent-blue/40 text-accent-blue hover:bg-accent-blue/10 disabled:opacity-50 transition-colors",title:a("plugins.applyProviderTitle"),children:_===l.id?"applying…":"apply provider"},`apply-${l.id}`))]}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[d?t.jsxs("button",{onClick:()=>void ce(e.id),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-amber-500/15 border border-amber-500/30 text-amber-400 text-[11px] hover:bg-amber-500/25 disabled:opacity-50 transition-colors",children:[t.jsx(ke,{size:11})," ",i===e.id?`${M}…`:a("plugins.deactivate")]}):t.jsxs("button",{onClick:()=>void oe(e.id),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 text-[11px] hover:bg-emerald-500/25 disabled:opacity-50 transition-colors",children:[t.jsx(ve,{size:11})," ",i===e.id?`${M}…`:a("plugins.activate")]}),t.jsxs("button",{onClick:()=>P(e.id),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-hover border border-dark-border text-dark-muted text-[11px] hover:text-red-400 hover:border-red-500/40 disabled:opacity-50 transition-colors",children:[t.jsx(fe,{size:11})," ",a("plugins.uninstall")]})]})]},e.id)}),Y(k.length,A)]}),!j&&n==="available"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[v.length===0&&Z(a("plugins.emptyMarket")),de.map(e=>t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-medium text-dark-text truncate",children:e.name||e.id}),e.version&&t.jsx("span",{className:"text-[11px] text-dark-muted shrink-0",children:e.version}),X(e.source),pe(e.market),e.category&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[11px] bg-dark-hover text-dark-muted border border-dark-border shrink-0",children:e.category}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-[11px] text-dark-muted font-mono shrink-0",children:e.id})]}),e.description&&t.jsx("p",{className:"mt-1 text-[12px] text-dark-muted",children:e.description}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[t.jsxs("button",{onClick:()=>void Q(e.id,!0),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-blue/20 border border-accent-blue/40 text-accent-blue text-[11px] hover:bg-accent-blue/30 disabled:opacity-50 transition-colors",children:[t.jsx(ee,{size:11})," ",i===e.id?`${M}…`:a("plugins.installActivate")]}),t.jsxs("button",{onClick:()=>void Q(e.id,!1),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-hover border border-dark-border text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-50 transition-colors",children:[t.jsx(ee,{size:11})," ",a("plugins.installOnly")]})]})]},e.id)),Y(v.length,E)]})]}),y&&t.jsxs("div",{className:`fixed bottom-4 right-4 z-50 flex items-center gap-2 px-3 py-2 rounded-lg border text-[12px] shadow-lg ${y.kind==="ok"?"bg-emerald-500/15 border-emerald-500/30 text-emerald-400":"bg-red-500/15 border-red-500/30 text-red-400"}`,children:[y.kind==="ok"?t.jsx(W,{size:13}):t.jsx(J,{size:13})," ",y.text]}),t.jsx(Ce,{isOpen:N!==null,title:a("plugins.uninstallTitle"),message:a("plugins.uninstallConfirm",{id:N??""}),onConfirm:()=>{N&&ue(N),P(null)},onClose:()=>P(null)})]})}export{Re as PluginsView};