@tencent-ai/agent-sdk 0.3.245-dev.cd0b453.202608251505 → 0.3.246

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 (62) hide show
  1. package/cli/CHANGELOG.md +33 -0
  2. package/cli/dist/codebuddy-headless.js +228 -293
  3. package/cli/dist/web-ui/assets/{CanvasPaneStandaloneView-Cmwt9Y8a.js → CanvasPaneStandaloneView-BD_qZwpK.js} +1 -1
  4. package/cli/dist/web-ui/assets/{CanvasView-kh-VwNZt.js → CanvasView-BAUxFLH1.js} +1 -1
  5. package/cli/dist/web-ui/assets/{ChangesView-LyTT64_e.js → ChangesView-Bvr-6a62.js} +1 -1
  6. package/cli/dist/web-ui/assets/{DocsView-DzT0XXMI.js → DocsView-BVidmMmQ.js} +1 -1
  7. package/cli/dist/web-ui/assets/EditorView-BWnNeB5q.js +75 -0
  8. package/cli/dist/web-ui/assets/{FileIcon-CiviXX19.js → FileIcon-BsViq6H0.js} +1 -1
  9. package/cli/dist/web-ui/assets/{KeybindingsView-CYLH1DTg.js → KeybindingsView-QuWWE_H3.js} +1 -1
  10. package/cli/dist/web-ui/assets/{LogsView-RDobPjF6.js → LogsView-DUMNTy8H.js} +3 -3
  11. package/cli/dist/web-ui/assets/{MetricsView-0TBamh3L.js → MetricsView-BY2YOvXi.js} +3 -3
  12. package/cli/dist/web-ui/assets/{PluginsView-CzAIf5_-.js → PluginsView-BzgBeIFp.js} +2 -2
  13. package/cli/dist/web-ui/assets/{RemoteControlView-CNsCKFhh.js → RemoteControlView-BuKYLVCs.js} +1 -1
  14. package/cli/dist/web-ui/assets/{SettingsView-B2RLsYo0.js → SettingsView-Bu_9EZ8x.js} +2 -2
  15. package/cli/dist/web-ui/assets/{SplitContainer-CJB8eH3c.js → SplitContainer-C2WbFxdL.js} +1 -1
  16. package/cli/dist/web-ui/assets/{StatsView-wHMAAyEJ.js → StatsView-h44ujqat.js} +2 -2
  17. package/cli/dist/web-ui/assets/{TasksView-DOFeNXmC.js → TasksView-D2q4JOBP.js} +2 -2
  18. package/cli/dist/web-ui/assets/{TerminalPaneView-BXNcwxsi.js → TerminalPaneView-lhajvnaH.js} +3 -3
  19. package/cli/dist/web-ui/assets/{TracesView-BtPCpydR.js → TracesView-B5i4emxN.js} +3 -3
  20. package/cli/dist/web-ui/assets/{WorkersView-sQMhvJ2l.js → WorkersView-Bw2bTNo6.js} +2 -2
  21. package/cli/dist/web-ui/assets/{canvas-store-0BnkCTHk.js → canvas-store-Smrtng_e.js} +1 -1
  22. package/cli/dist/web-ui/assets/{cssMode-jwjmt121.js → cssMode-EsOJVYiu.js} +1 -1
  23. package/cli/dist/web-ui/assets/{download-iNxRYv3J.js → download-BsdRqzY7.js} +1 -1
  24. package/cli/dist/web-ui/assets/{editor.main-CGYuAeQx.js → editor.main-q4R8cbC1.js} +3 -3
  25. package/cli/dist/web-ui/assets/{external-link-D5RWsA9l.js → external-link-Ea1Nar0e.js} +1 -1
  26. package/cli/dist/web-ui/assets/{freemarker2-CX3QfLDV.js → freemarker2-DVmHExbB.js} +1 -1
  27. package/cli/dist/web-ui/assets/{handlebars-C5TLi2Pr.js → handlebars-Cguwj4ew.js} +1 -1
  28. package/cli/dist/web-ui/assets/{html-VGWLEWVQ.js → html-DRfZqNG-.js} +1 -1
  29. package/cli/dist/web-ui/assets/{htmlMode-B7yDtJr6.js → htmlMode-mn7qxh39.js} +1 -1
  30. package/cli/dist/web-ui/assets/index-BOvl5ICo.css +1 -0
  31. package/cli/dist/web-ui/assets/{index-CHcoPr8x.js → index-CBmymKHy.js} +180 -175
  32. package/cli/dist/web-ui/assets/{javascript-rebq-3hM.js → javascript-Dv0-Ka9H.js} +1 -1
  33. package/cli/dist/web-ui/assets/{jsonMode-CisSEnRa.js → jsonMode-MVrw6wSj.js} +1 -1
  34. package/cli/dist/web-ui/assets/{liquid-C0GU_tuJ.js → liquid-2HR35IQO.js} +1 -1
  35. package/cli/dist/web-ui/assets/{lspLanguageFeatures-DdEy47qR.js → lspLanguageFeatures-BA4h_1Zp.js} +1 -1
  36. package/cli/dist/web-ui/assets/{markdown-DIY6o85n.js → markdown-CP9awqWt.js} +1 -1
  37. package/cli/dist/web-ui/assets/{mdx-DjEmR07p.js → mdx-CFi7brpM.js} +1 -1
  38. package/cli/dist/web-ui/assets/{minus-BHON617T.js → minus-Dw9-WG76.js} +1 -1
  39. package/cli/dist/web-ui/assets/{power-BoeeA3TI.js → power-BJk8Xq9U.js} +1 -1
  40. package/cli/dist/web-ui/assets/{python-YOuEQ1oe.js → python-BqoHrqNK.js} +1 -1
  41. package/cli/dist/web-ui/assets/{razor-DTO4iPoC.js → razor-CPnz313K.js} +1 -1
  42. package/cli/dist/web-ui/assets/{server-Gy9um44Z.js → server-D4446JKI.js} +1 -1
  43. package/cli/dist/web-ui/assets/{timer-CVn2LoSe.js → timer-D8MX3pYj.js} +1 -1
  44. package/cli/dist/web-ui/assets/{tsMode-J-jxLo7h.js → tsMode-DMOs1uPQ.js} +1 -1
  45. package/cli/dist/web-ui/assets/{typescript-BTZe1y3z.js → typescript-CP_zrnR8.js} +1 -1
  46. package/cli/dist/web-ui/assets/{vendor-D35k0Cos.js → vendor-iLJwFVtf.js} +1 -1
  47. package/cli/dist/web-ui/assets/{worker-store-CsMfXxjm.js → worker-store-qfd_N8Zm.js} +1 -1
  48. package/cli/dist/web-ui/assets/{xml-DaZe33xf.js → xml-BNASinsS.js} +1 -1
  49. package/cli/dist/web-ui/assets/{yaml-yofIoqGl.js → yaml-D_cB1VDT.js} +1 -1
  50. package/cli/dist/web-ui/assets/{zap-BeZalqcf.js → zap-yafQUspl.js} +1 -1
  51. package/cli/dist/web-ui/index.html +4 -4
  52. package/cli/dist/web-ui/sw.js +1 -1
  53. package/cli/package.json +2 -3
  54. package/cli/product.cloudhosted.json +4 -2
  55. package/cli/product.internal.json +4 -2
  56. package/cli/product.ioa.json +4 -2
  57. package/cli/product.json +383 -17
  58. package/cli/product.selfhosted.json +4 -2
  59. package/cli/vendor/shim/sitecustomize.py +43 -1
  60. package/package.json +2 -3
  61. package/cli/dist/web-ui/assets/EditorView-ZUnDw1V1.js +0 -75
  62. package/cli/dist/web-ui/assets/index-Ddq_addW.css +0 -1
@@ -1,4 +1,4 @@
1
- import{a as N,j as r}from"./markdown-DIY6o85n.js";import{c as v,e as M,U as $,h as C,u as c,y as T,aF as z,ab as U,aG as k,aE as F,aH as h}from"./index-CHcoPr8x.js";import{u as P}from"./worker-store-CsMfXxjm.js";import{E as S}from"./external-link-D5RWsA9l.js";import{S as b}from"./server-Gy9um44Z.js";import"./vendor-D35k0Cos.js";/**
1
+ import{a as N,j as r}from"./markdown-CP9awqWt.js";import{c as v,e as M,U as $,h as C,u as c,y as T,aG as z,ab as U,aH as k,aF as F,aI as h}from"./index-CBmymKHy.js";import{u as P}from"./worker-store-qfd_N8Zm.js";import{E as S}from"./external-link-Ea1Nar0e.js";import{S as b}from"./server-D4446JKI.js";import"./vendor-iLJwFVtf.js";/**
2
2
  * @license lucide-react v1.18.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -8,5 +8,5 @@ import{a as N,j as r}from"./markdown-DIY6o85n.js";import{c as v,e as M,U as $,h
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const w=[["path",{d:"M12 12v-2",key:"fwoke6"}],["path",{d:"M12 18v-2",key:"qj6yno"}],["path",{d:"M16 12v-2",key:"heuere"}],["path",{d:"M16 18v-2",key:"s1ct0w"}],["path",{d:"M2 11h1.5",key:"15p63e"}],["path",{d:"M20 18v-2",key:"12ehxp"}],["path",{d:"M20.5 11H22",key:"khsy7a"}],["path",{d:"M4 18v-2",key:"1c3oqr"}],["path",{d:"M8 12v-2",key:"1mwtfd"}],["path",{d:"M8 18v-2",key:"qcmpov"}],["rect",{x:"2",y:"6",width:"20",height:"10",rx:"2",key:"1qcswk"}]],u=v("memory-stick",w),E=8e3,L=M((e,t)=>({metrics:null,loading:!1,error:null,_pollTimer:null,fetchMetrics:async()=>{e({loading:!t().metrics,error:null});try{const s=await $("/api/v1/metrics",{headers:C()});if(!s.ok)throw new Error(`Failed to fetch metrics: ${s.status}`);const a=await s.json();e({metrics:a.data,loading:!1})}catch(s){e({error:s.message,loading:!1})}},startPolling:(s=E)=>{const{stopPolling:a,fetchMetrics:i}=t();a(),i();const n=setInterval(i,s);e({_pollTimer:n})},stopPolling:()=>{const{_pollTimer:s}=t();s&&(clearInterval(s),e({_pollTimer:null}))}})),B={interactive:"bg-blue-50 text-blue-700 border border-blue-200 dark:bg-blue-500/10 dark:text-blue-400 dark:border-blue-500/20",bg:"bg-purple-50 text-purple-700 border border-purple-200 dark:bg-purple-500/10 dark:text-purple-400 dark:border-purple-500/20",daemon:"bg-green-50 text-green-700 border border-green-200 dark:bg-green-500/10 dark:text-green-400 dark:border-green-500/20","daemon-worker":"bg-orange-50 text-orange-700 border border-orange-200 dark:bg-orange-500/10 dark:text-orange-400 dark:border-orange-500/20"};function Y(){const{t:e}=c(),{metrics:t,loading:s,error:a,fetchMetrics:i,startPolling:n,stopPolling:d}=L(),{workers:x,fetchWorkers:m}=P();if(N.useEffect(()=>(n(8e3),m(),()=>d()),[n,d,m]),s&&!t)return r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(T,{size:"large",text:e("metrics.loading")})});if(a&&!t)return r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:"text-text-secondary mb-4",children:a}),r.jsx("button",{onClick:i,className:"px-4 py-2 bg-accent-brand text-accent-brand-foreground rounded-lg text-sm",children:e("metrics.refresh")})]})});const y=H((t==null?void 0:t.instances)||[],x);return r.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[r.jsxs("div",{className:"flex items-center justify-between mb-6",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(z,{size:20,className:"text-accent-brand"}),r.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:e("metrics.title")})]}),r.jsxs("button",{onClick:()=>{i(),m()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-text-secondary
12
- hover:text-text-primary hover:bg-bg-hover rounded-lg transition-colors`,title:e("metrics.refresh"),children:[r.jsx(U,{size:14}),r.jsx("span",{children:e("metrics.refresh")})]})]}),t&&r.jsxs(r.Fragment,{children:[r.jsx(I,{metrics:t}),r.jsx(q,{workers:y})]})]})}function H(e,t){return e.map(s=>{const a=t.find(i=>i.pid===s.pid);return{...s,kind:a==null?void 0:a.kind,name:a==null?void 0:a.name,url:(a==null?void 0:a.url)||(a==null?void 0:a.endpoint),status:a==null?void 0:a.status}})}function I({metrics:e}){const{t}=c(),s=e.memTotalMib>0?e.memUsedMib/e.memTotalMib*100:0,a=e.diskTotal>0?e.diskUsed/e.diskTotal*100:0;return r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6",children:[r.jsx(p,{icon:r.jsx(k,{size:18}),label:t("metrics.cpu"),value:`${e.cpuUsedPct.toFixed(1)}%`,subtext:`${e.cpuCount} ${t("metrics.cores")}`,percent:e.cpuUsedPct,colorClasses:o(e.cpuUsedPct)}),r.jsx(p,{icon:r.jsx(u,{size:18}),label:t("metrics.memory"),value:`${f(e.memUsedMib)} / ${f(e.memTotalMib)}`,subtext:`${s.toFixed(1)}%`,percent:s,colorClasses:o(s)}),r.jsx(p,{icon:r.jsx(W,{size:18}),label:t("metrics.disk"),value:`${g(e.diskUsed)} / ${g(e.diskTotal)}`,subtext:`${a.toFixed(1)}%`,percent:a,colorClasses:o(a)})]})}function p({icon:e,label:t,value:s,subtext:a,percent:i,colorClasses:n}){const[d,x]=n;return r.jsxs("div",{className:"bg-bg-secondary rounded-xl p-4 border border-border-primary",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx("span",{className:d,children:e}),r.jsx("span",{className:"text-sm font-medium text-text-secondary",children:t})]}),r.jsx("div",{className:"text-xl font-semibold text-text-primary mb-1",children:s}),r.jsx("div",{className:"text-xs text-text-tertiary mb-3",children:a}),r.jsx("div",{className:"h-2 bg-bg-tertiary rounded-full overflow-hidden",children:r.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${x}`,style:{width:`${Math.min(i,100)}%`}})})]})}function q({workers:e}){const{t}=c();return e.length===0?r.jsx("div",{className:"text-center py-12 text-text-tertiary",children:t("metrics.noWorkers")}):r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[r.jsx(k,{size:18,className:"text-text-secondary"}),r.jsxs("h2",{className:"text-base font-medium text-text-primary",children:["Workers (",e.length,")"]})]}),r.jsx("div",{className:"space-y-3",children:e.map(s=>r.jsx(R,{worker:s},s.id))})]})}function R({worker:e}){const{t}=c();return r.jsx("div",{className:`bg-bg-secondary rounded-xl p-4 md:p-5 border transition-colors hover:border-gray-300 dark:hover:border-gray-600 border-border-primary ${e.error?"opacity-60":""}`,children:r.jsxs("div",{className:"flex flex-col gap-4",children:[r.jsxs("div",{className:"flex items-start justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${e.error?"bg-red-400":"bg-green-400"}`}),e.kind&&r.jsx("span",{className:`inline-block px-2.5 py-0.5 text-xs font-medium rounded-md ${B[e.kind]||"bg-gray-100 text-gray-600"}`,children:e.kind}),r.jsx("span",{className:"text-sm font-medium text-text-primary",children:e.name||e.hostname}),e.isCurrent&&r.jsx("span",{className:"text-[10px] uppercase font-bold tracking-wider px-1.5 py-0.5 bg-accent-brand/10 text-accent-brand rounded",children:t("metrics.current")}),e.error&&r.jsx("span",{className:"text-xs text-red-400",children:e.error})]}),r.jsxs("span",{className:"text-xs text-text-tertiary font-mono bg-bg-tertiary px-2 py-0.5 rounded-md border border-border-primary/50",children:["PID ",e.pid]})]}),r.jsxs("div",{className:"flex flex-col md:flex-row md:items-start justify-between gap-4 md:gap-6",children:[r.jsxs("div",{className:"flex flex-col gap-2.5 flex-1 min-w-0",children:[r.jsx(F,{path:e.cwd,displayMode:"basename",className:"text-[13px] text-text-secondary font-mono truncate max-w-full"}),e.url&&r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx(S,{size:14,className:"text-text-tertiary flex-none"}),r.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-accent-brand hover:underline truncate",children:e.url})]})]}),e.rssMib>0||e.heapUsedMib>0?r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 flex-none",style:{minWidth:"460px"},children:[r.jsxs("div",{className:"min-w-[100px]",children:[r.jsx(l,{icon:r.jsx(u,{size:14}),label:"RSS",value:`${e.rssMib.toFixed(0)} MiB`}),r.jsx("div",{className:"mt-1.5 h-1.5 bg-bg-tertiary rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full rounded-full bg-blue-500 transition-all duration-500",style:{width:`${Math.min(e.rssMib/2048*100,100)}%`}})})]}),r.jsxs("div",{className:"min-w-[140px]",children:[r.jsx(l,{icon:r.jsx(u,{size:14}),label:"Heap",value:`${e.heapUsedMib.toFixed(0)} / ${e.heapTotalMib.toFixed(0)} MiB`}),e.heapTotalMib>0&&r.jsx("div",{className:"mt-1.5 h-1.5 bg-bg-tertiary rounded-full overflow-hidden",children:r.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${o(e.heapUsedMib/e.heapTotalMib*100)[1]}`,style:{width:`${Math.min(e.heapUsedMib/e.heapTotalMib*100,100)}%`}})})]}),r.jsx("div",{className:"min-w-[80px]",children:r.jsx(l,{icon:r.jsx(h,{size:14}),label:t("metrics.uptime"),value:j(e.uptimeSeconds)})}),r.jsx("div",{className:"min-w-[60px]",children:r.jsx(l,{icon:r.jsx(b,{size:14}),label:t("metrics.version"),value:e.version||"-"})})]}):r.jsxs("div",{className:"grid grid-cols-2 gap-4 flex-none",style:{minWidth:"200px"},children:[r.jsx("div",{className:"min-w-[80px]",children:r.jsx(l,{icon:r.jsx(h,{size:14}),label:t("metrics.uptime"),value:j(e.uptimeSeconds)})}),r.jsx("div",{className:"min-w-[60px]",children:r.jsx(l,{icon:r.jsx(b,{size:14}),label:t("metrics.version"),value:e.version||"-"})})]})]})]})})}function l({icon:e,label:t,value:s}){return r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-text-tertiary",children:[e,r.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider",children:t})]}),r.jsx("div",{className:"text-sm font-semibold text-text-primary",style:{fontVariantNumeric:"tabular-nums"},children:s})]})}function o(e){return e>=90?["text-red-500","bg-red-500"]:e>=70?["text-amber-500","bg-amber-500"]:["text-green-500","bg-green-500"]}function f(e){return e>=1024?`${(e/1024).toFixed(1)} GiB`:`${e} MiB`}function g(e){if(e===0)return"0 B";const t=e/(1024*1024*1024);return t>=1?`${t.toFixed(1)} GB`:`${(e/(1024*1024)).toFixed(0)} MB`}function j(e){if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m ${e%60}s`;const t=Math.floor(e/3600),s=Math.floor(e%3600/60);return t>=24?`${Math.floor(t/24)}d ${t%24}h`:`${t}h ${s}m`}export{Y as MetricsView};
11
+ */const w=[["path",{d:"M12 12v-2",key:"fwoke6"}],["path",{d:"M12 18v-2",key:"qj6yno"}],["path",{d:"M16 12v-2",key:"heuere"}],["path",{d:"M16 18v-2",key:"s1ct0w"}],["path",{d:"M2 11h1.5",key:"15p63e"}],["path",{d:"M20 18v-2",key:"12ehxp"}],["path",{d:"M20.5 11H22",key:"khsy7a"}],["path",{d:"M4 18v-2",key:"1c3oqr"}],["path",{d:"M8 12v-2",key:"1mwtfd"}],["path",{d:"M8 18v-2",key:"qcmpov"}],["rect",{x:"2",y:"6",width:"20",height:"10",rx:"2",key:"1qcswk"}]],u=v("memory-stick",w),E=8e3,L=M((e,t)=>({metrics:null,loading:!1,error:null,_pollTimer:null,fetchMetrics:async()=>{e({loading:!t().metrics,error:null});try{const s=await $("/api/v1/metrics",{headers:C()});if(!s.ok)throw new Error(`Failed to fetch metrics: ${s.status}`);const a=await s.json();e({metrics:a.data,loading:!1})}catch(s){e({error:s.message,loading:!1})}},startPolling:(s=E)=>{const{stopPolling:a,fetchMetrics:i}=t();a(),i();const n=setInterval(i,s);e({_pollTimer:n})},stopPolling:()=>{const{_pollTimer:s}=t();s&&(clearInterval(s),e({_pollTimer:null}))}})),B={interactive:"bg-blue-50 text-blue-700 border border-blue-200 dark:bg-blue-500/10 dark:text-blue-400 dark:border-blue-500/20",bg:"bg-purple-50 text-purple-700 border border-purple-200 dark:bg-purple-500/10 dark:text-purple-400 dark:border-purple-500/20",daemon:"bg-green-50 text-green-700 border border-green-200 dark:bg-green-500/10 dark:text-green-400 dark:border-green-500/20","daemon-worker":"bg-orange-50 text-orange-700 border border-orange-200 dark:bg-orange-500/10 dark:text-orange-400 dark:border-orange-500/20"};function Y(){const{t:e}=c(),{metrics:t,loading:s,error:a,fetchMetrics:i,startPolling:n,stopPolling:d}=L(),{workers:x,fetchWorkers:m}=P();if(N.useEffect(()=>(n(8e3),m(),()=>d()),[n,d,m]),s&&!t)return r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(T,{size:"large",text:e("metrics.loading")})});if(a&&!t)return r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:"text-text-secondary mb-4",children:a}),r.jsx("button",{onClick:i,className:"px-4 py-2 bg-accent-brand text-accent-brand-foreground rounded-lg text-sm",children:e("metrics.refresh")})]})});const y=I((t==null?void 0:t.instances)||[],x);return r.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[r.jsxs("div",{className:"flex items-center justify-between mb-6",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(z,{size:20,className:"text-accent-brand"}),r.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:e("metrics.title")})]}),r.jsxs("button",{onClick:()=>{i(),m()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-text-secondary
12
+ hover:text-text-primary hover:bg-bg-hover rounded-lg transition-colors`,title:e("metrics.refresh"),children:[r.jsx(U,{size:14}),r.jsx("span",{children:e("metrics.refresh")})]})]}),t&&r.jsxs(r.Fragment,{children:[r.jsx(H,{metrics:t}),r.jsx(q,{workers:y})]})]})}function I(e,t){return e.map(s=>{const a=t.find(i=>i.pid===s.pid);return{...s,kind:a==null?void 0:a.kind,name:a==null?void 0:a.name,url:(a==null?void 0:a.url)||(a==null?void 0:a.endpoint),status:a==null?void 0:a.status}})}function H({metrics:e}){const{t}=c(),s=e.memTotalMib>0?e.memUsedMib/e.memTotalMib*100:0,a=e.diskTotal>0?e.diskUsed/e.diskTotal*100:0;return r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6",children:[r.jsx(p,{icon:r.jsx(k,{size:18}),label:t("metrics.cpu"),value:`${e.cpuUsedPct.toFixed(1)}%`,subtext:`${e.cpuCount} ${t("metrics.cores")}`,percent:e.cpuUsedPct,colorClasses:o(e.cpuUsedPct)}),r.jsx(p,{icon:r.jsx(u,{size:18}),label:t("metrics.memory"),value:`${f(e.memUsedMib)} / ${f(e.memTotalMib)}`,subtext:`${s.toFixed(1)}%`,percent:s,colorClasses:o(s)}),r.jsx(p,{icon:r.jsx(W,{size:18}),label:t("metrics.disk"),value:`${g(e.diskUsed)} / ${g(e.diskTotal)}`,subtext:`${a.toFixed(1)}%`,percent:a,colorClasses:o(a)})]})}function p({icon:e,label:t,value:s,subtext:a,percent:i,colorClasses:n}){const[d,x]=n;return r.jsxs("div",{className:"bg-bg-secondary rounded-xl p-4 border border-border-primary",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[r.jsx("span",{className:d,children:e}),r.jsx("span",{className:"text-sm font-medium text-text-secondary",children:t})]}),r.jsx("div",{className:"text-xl font-semibold text-text-primary mb-1",children:s}),r.jsx("div",{className:"text-xs text-text-tertiary mb-3",children:a}),r.jsx("div",{className:"h-2 bg-bg-tertiary rounded-full overflow-hidden",children:r.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${x}`,style:{width:`${Math.min(i,100)}%`}})})]})}function q({workers:e}){const{t}=c();return e.length===0?r.jsx("div",{className:"text-center py-12 text-text-tertiary",children:t("metrics.noWorkers")}):r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[r.jsx(k,{size:18,className:"text-text-secondary"}),r.jsxs("h2",{className:"text-base font-medium text-text-primary",children:["Workers (",e.length,")"]})]}),r.jsx("div",{className:"space-y-3",children:e.map(s=>r.jsx(R,{worker:s},s.id))})]})}function R({worker:e}){const{t}=c();return r.jsx("div",{className:`bg-bg-secondary rounded-xl p-4 md:p-5 border transition-colors hover:border-gray-300 dark:hover:border-gray-600 border-border-primary ${e.error?"opacity-60":""}`,children:r.jsxs("div",{className:"flex flex-col gap-4",children:[r.jsxs("div",{className:"flex items-start justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[r.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${e.error?"bg-red-400":"bg-green-400"}`}),e.kind&&r.jsx("span",{className:`inline-block px-2.5 py-0.5 text-xs font-medium rounded-md ${B[e.kind]||"bg-gray-100 text-gray-600"}`,children:e.kind}),r.jsx("span",{className:"text-sm font-medium text-text-primary",children:e.name||e.hostname}),e.isCurrent&&r.jsx("span",{className:"text-[10px] uppercase font-bold tracking-wider px-1.5 py-0.5 bg-accent-brand/10 text-accent-brand rounded",children:t("metrics.current")}),e.error&&r.jsx("span",{className:"text-xs text-red-400",children:e.error})]}),r.jsxs("span",{className:"text-xs text-text-tertiary font-mono bg-bg-tertiary px-2 py-0.5 rounded-md border border-border-primary/50",children:["PID ",e.pid]})]}),r.jsxs("div",{className:"flex flex-col md:flex-row md:items-start justify-between gap-4 md:gap-6",children:[r.jsxs("div",{className:"flex flex-col gap-2.5 flex-1 min-w-0",children:[r.jsx(F,{path:e.cwd,displayMode:"basename",className:"text-[13px] text-text-secondary font-mono truncate max-w-full"}),e.url&&r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx(S,{size:14,className:"text-text-tertiary flex-none"}),r.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-accent-brand hover:underline truncate",children:e.url})]})]}),e.rssMib>0||e.heapUsedMib>0?r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 flex-none",style:{minWidth:"460px"},children:[r.jsxs("div",{className:"min-w-[100px]",children:[r.jsx(l,{icon:r.jsx(u,{size:14}),label:"RSS",value:`${e.rssMib.toFixed(0)} MiB`}),r.jsx("div",{className:"mt-1.5 h-1.5 bg-bg-tertiary rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full rounded-full bg-blue-500 transition-all duration-500",style:{width:`${Math.min(e.rssMib/2048*100,100)}%`}})})]}),r.jsxs("div",{className:"min-w-[140px]",children:[r.jsx(l,{icon:r.jsx(u,{size:14}),label:"Heap",value:`${e.heapUsedMib.toFixed(0)} / ${e.heapTotalMib.toFixed(0)} MiB`}),e.heapTotalMib>0&&r.jsx("div",{className:"mt-1.5 h-1.5 bg-bg-tertiary rounded-full overflow-hidden",children:r.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${o(e.heapUsedMib/e.heapTotalMib*100)[1]}`,style:{width:`${Math.min(e.heapUsedMib/e.heapTotalMib*100,100)}%`}})})]}),r.jsx("div",{className:"min-w-[80px]",children:r.jsx(l,{icon:r.jsx(h,{size:14}),label:t("metrics.uptime"),value:j(e.uptimeSeconds)})}),r.jsx("div",{className:"min-w-[60px]",children:r.jsx(l,{icon:r.jsx(b,{size:14}),label:t("metrics.version"),value:e.version||"-"})})]}):r.jsxs("div",{className:"grid grid-cols-2 gap-4 flex-none",style:{minWidth:"200px"},children:[r.jsx("div",{className:"min-w-[80px]",children:r.jsx(l,{icon:r.jsx(h,{size:14}),label:t("metrics.uptime"),value:j(e.uptimeSeconds)})}),r.jsx("div",{className:"min-w-[60px]",children:r.jsx(l,{icon:r.jsx(b,{size:14}),label:t("metrics.version"),value:e.version||"-"})})]})]})]})})}function l({icon:e,label:t,value:s}){return r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsxs("div",{className:"flex items-center gap-1.5 text-text-tertiary",children:[e,r.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider",children:t})]}),r.jsx("div",{className:"text-sm font-semibold text-text-primary",style:{fontVariantNumeric:"tabular-nums"},children:s})]})}function o(e){return e>=90?["text-red-500","bg-red-500"]:e>=70?["text-amber-500","bg-amber-500"]:["text-green-500","bg-green-500"]}function f(e){return e>=1024?`${(e/1024).toFixed(1)} GiB`:`${e} MiB`}function g(e){if(e===0)return"0 B";const t=e/(1024*1024*1024);return t>=1?`${t.toFixed(1)} GB`:`${(e/(1024*1024)).toFixed(0)} MB`}function j(e){if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m ${e%60}s`;const t=Math.floor(e/3600),s=Math.floor(e%3600/60);return t>=24?`${Math.floor(t/24)}d ${t%24}h`:`${t}h ${s}m`}export{Y as MetricsView};
@@ -1,4 +1,4 @@
1
- import{a as x,j as e}from"./markdown-DIY6o85n.js";import{c as Pe,e as Qe,aI as Ge,aJ as Xe,aK as Ze,u as We,ab as Ye,t as B,X as F,aL as W,y as ve,aM as V,P as et,L as R,aN as Ce,aq as tt}from"./index-CHcoPr8x.js";import{P as st}from"./power-BoeeA3TI.js";import{E as D}from"./external-link-D5RWsA9l.js";import{D as rt}from"./download-iNxRYv3J.js";import"./vendor-D35k0Cos.js";/**
1
+ import{a as x,j as e}from"./markdown-CP9awqWt.js";import{c as Pe,e as Qe,aJ as Ge,aK as Xe,aL as Ze,u as We,ab as Ye,t as B,X as F,aM as W,y as ve,aN as O,P as et,L as R,aO as Ce,aq as tt}from"./index-CBmymKHy.js";import{P as st}from"./power-BJk8Xq9U.js";import{E as D}from"./external-link-Ea1Nar0e.js";import{D as rt}from"./download-BsdRqzY7.js";import"./vendor-iLJwFVtf.js";/**
2
2
  * @license lucide-react v1.18.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -8,4 +8,4 @@ import{a as x,j as e}from"./markdown-DIY6o85n.js";import{c as Pe,e as Qe,aI as G
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const lt=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5",key:"slp6dd"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244",key:"o0xfot"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05",key:"wn3emo"}]],A=Pe("store",lt);function K(t,r){return`${t}@${r}`}const M=Ge,it=Ze,we=Xe,ot=Qe((t,r)=>({plugins:[],loading:!1,error:null,marketplaces:[],marketplaceLoading:!1,availablePlugins:[],browsingMarketplace:null,browsingLoading:!1,browsingError:null,operatingPlugins:new Set,fetchPlugins:async()=>{t({loading:!0,error:null});try{const n=await we("/api/v1/plugins");if(!n.ok)throw new Error(`HTTP ${n.status}`);const i=(await n.json()).data,p=Array.isArray(i)?i.map(a=>({...a,canRemove:a.canRemove,canSwitchoff:a.canSwitchoff,canEdit:a.canEdit})):[];t({plugins:p,loading:!1})}catch(n){console.warn("[plugin-store] fetchPlugins failed:",n),t({error:n.message,loading:!1})}},fetchMarketplaces:async()=>{t({marketplaceLoading:!0});try{const n=await we("/api/v1/plugins/marketplaces");if(!n.ok)throw new Error(`HTTP ${n.status}`);const i=(await n.json()).data;t({marketplaces:Array.isArray(i)?i:[],marketplaceLoading:!1})}catch(n){console.warn("[plugin-store] fetchMarketplaces failed:",n),t({marketplaceLoading:!1})}},browseMarketplace:async n=>{var o;t({browsingMarketplace:n,browsingLoading:!0,browsingError:null});try{const i=await M("/api/v1/plugins/marketplaces/browse",{marketplace:n});if(!i.ok){const c=await i.json().catch(()=>null);throw new Error(((o=c==null?void 0:c.error)==null?void 0:o.message)||`HTTP ${i.status}`)}const p=await i.json(),l=(Array.isArray(p.data)?p.data:[]).map(c=>({name:c.name,version:c.version,description:c.description,marketplace:c.marketplaceName||n,installed:!!c.status,author:c.author,license:c.license,homepage:c.homepage,repository:c.repository,keywords:c.keywords,category:c.category,features:c.features,source:c.source,dependencies:c.dependencies}));t({availablePlugins:l,browsingLoading:!1})}catch(i){console.warn("[plugin-store] browseMarketplace failed:",i),t({browsingError:i.message,browsingLoading:!1})}},browseAllMarketplaces:async()=>{const{marketplaces:n}=r();if(n.length!==0){t({browsingMarketplace:"__all__",browsingLoading:!0,browsingError:null});try{const o=await Promise.allSettled(n.map(async c=>{var k;const b=await M("/api/v1/plugins/marketplaces/browse",{marketplace:c.name});if(!b.ok){const u=await b.json().catch(()=>null);throw new Error(((k=u==null?void 0:u.error)==null?void 0:k.message)||`HTTP ${b.status}`)}const g=await b.json();return(Array.isArray(g.data)?g.data:[]).map(u=>({name:u.name,version:u.version,description:u.description,marketplace:u.marketplaceName||c.name,installed:!!u.status,author:u.author,license:u.license,homepage:u.homepage,repository:u.repository,keywords:u.keywords,category:u.category,features:u.features,source:u.source,dependencies:u.dependencies}))})),i=[];let p=!1;for(const c of o)c.status==="fulfilled"?i.push(...c.value):p=!0;const a=new Set,l=i.filter(c=>{const b=`${c.name}@${c.marketplace}`;return a.has(b)?!1:(a.add(b),!0)});t({availablePlugins:l,browsingLoading:!1,browsingError:p&&l.length===0?"Some marketplaces failed to load":null})}catch(o){console.warn("[plugin-store] browseAllMarketplaces failed:",o),t({browsingError:o.message,browsingLoading:!1})}}},enablePlugin:async(n,o)=>{var p;const i=K(n,o);t(a=>({operatingPlugins:new Set(a.operatingPlugins).add(i)}));try{const a=await M("/api/v1/plugins/enable",{plugin:i});if(!a.ok){const l=await a.json().catch(()=>null);throw new Error(((p=l==null?void 0:l.error)==null?void 0:p.message)||`HTTP ${a.status}`)}await r().fetchPlugins()}finally{t(a=>{const l=new Set(a.operatingPlugins);return l.delete(i),{operatingPlugins:l}})}},disablePlugin:async(n,o)=>{var p;const i=K(n,o);t(a=>({operatingPlugins:new Set(a.operatingPlugins).add(i)}));try{const a=await M("/api/v1/plugins/disable",{plugin:i});if(!a.ok){const l=await a.json().catch(()=>null);throw new Error(((p=l==null?void 0:l.error)==null?void 0:p.message)||`HTTP ${a.status}`)}await r().fetchPlugins()}finally{t(a=>{const l=new Set(a.operatingPlugins);return l.delete(i),{operatingPlugins:l}})}},uninstallPlugin:async(n,o)=>{var p;const i=K(n,o);t(a=>({operatingPlugins:new Set(a.operatingPlugins).add(i)}));try{const a=await M("/api/v1/plugins/uninstall",{plugin:i});if(!a.ok){const l=await a.json().catch(()=>null);throw new Error(((p=l==null?void 0:l.error)==null?void 0:p.message)||`HTTP ${a.status}`)}await r().fetchPlugins()}finally{t(a=>{const l=new Set(a.operatingPlugins);return l.delete(i),{operatingPlugins:l}})}},installPlugin:async(n,o,i)=>{var a;const p=K(n,o);t(l=>({operatingPlugins:new Set(l.operatingPlugins).add(p)}));try{const l=await M("/api/v1/plugins",{plugin:p,options:i?{scope:i}:void 0});if(!l.ok){const b=await l.json().catch(()=>null);throw new Error(((a=b==null?void 0:b.error)==null?void 0:a.message)||`HTTP ${l.status}`)}await r().fetchPlugins();const c=r();c.browsingMarketplace&&(c.browsingMarketplace==="__all__"?await r().browseAllMarketplaces():await r().browseMarketplace(c.browsingMarketplace))}finally{t(l=>{const c=new Set(l.operatingPlugins);return c.delete(p),{operatingPlugins:c}})}},addMarketplace:async(n,o)=>{var p;const i=await M("/api/v1/plugins/marketplaces",{source:n,name:o});if(!i.ok){const a=await i.json().catch(()=>null);throw new Error(((p=a==null?void 0:a.error)==null?void 0:p.message)||`HTTP ${i.status}`)}await r().fetchMarketplaces()},removeMarketplace:async n=>{var i;const o=await it(`/api/v1/plugins/marketplaces/${encodeURIComponent(n)}`);if(!o.ok){const p=await o.json().catch(()=>null);throw new Error(((i=p==null?void 0:p.error)==null?void 0:i.message)||`HTTP ${o.status}`)}await r().fetchMarketplaces()}})),S=12;function _(t){const r=[t.category,...t.features||[],...t.keywords||[],t.name,t.description||""].join(" ").toLowerCase();return/\b(skill|skills)\b/.test(r)?"skills":/\b(mcp|model[- ]?context)\b/.test(r)?"mcp":/\b(hook|hooks)\b/.test(r)?"hooks":/\b(tool|tools)\b/.test(r)?"tools":"unknown"}function ft(){const{t}=We(),{plugins:r,marketplaces:n,loading:o,marketplaceLoading:i,error:p,operatingPlugins:a,availablePlugins:l,browsingLoading:c,browsingError:b,fetchPlugins:g,fetchMarketplaces:N,browseMarketplace:k,browseAllMarketplaces:u,enablePlugin:Y,disablePlugin:ee,uninstallPlugin:te,installPlugin:se,addMarketplace:re,removeMarketplace:ae}=ot(),[h,O]=x.useState("installed"),[z,ne]=x.useState(""),[T,Se]=x.useState("all"),[v,ze]=x.useState("all"),[$,Te]=x.useState("all"),[le,ie]=x.useState(S),[oe,ce]=x.useState(S),[j,$e]=x.useState(null),[Ee,de]=x.useState(!1),[xe,y]=x.useState(null),[q,H]=x.useState(!1),[I,pe]=x.useState(""),[J,me]=x.useState(""),[ue,ge]=x.useState(!1),[he,U]=x.useState(null),[Le,Q]=x.useState(null),[_e,G]=x.useState(null),[f,X]=x.useState(""),[E,Z]=x.useState(""),[be,Ae]=x.useState(null),fe=x.useCallback(s=>{Ae(d=>d===s?null:s)},[]);x.useEffect(()=>{g(),N()},[g,N]),x.useEffect(()=>{h==="browse"&&!f&&n.length>0&&(X("__all__"),u())},[h,n,f,u]);const Re=x.useCallback(async s=>{y(null);try{s.status==="enabled"?await ee(s.name,s.marketplace):await Y(s.name,s.marketplace)}catch(d){y(d.message)}},[Y,ee]),He=x.useCallback(async s=>{y(null),Q(null);try{await te(s.name,s.marketplace)}catch(d){y(d.message)}},[te]),Ie=x.useCallback(async(s,d)=>{y(null);try{await se(s.name,s.marketplace,d)}catch(m){y(m.message)}},[se]),Ue=x.useCallback(async()=>{const s=I.trim();if(s){ge(!0),U(null);try{await re(s,J.trim()||void 0),pe(""),me(""),H(!1)}catch(d){U(d.message)}finally{ge(!1)}}},[I,J,re]),Be=x.useCallback(async s=>{y(null),G(null);try{if(await ae(s),f===s&&n.length>1){const d=n.find(m=>m.name!==s);d&&(X(d.name),k(d.name))}}catch(d){y(d.message)}},[ae,f,n,k]),Fe=x.useCallback(()=>{g(),N(),h==="browse"&&f&&(f==="__all__"?u():k(f))},[g,N,h,f,k,u]),De=x.useCallback(s=>{X(s),Z(""),s==="__all__"?u():k(s)},[k,u]),Ke=s=>`${s.name}@${s.marketplace}`,ye=x.useMemo(()=>{const s=new Set(r.map(d=>d.marketplace));return Array.from(s).sort()},[r]),P=x.useMemo(()=>{let s=r;T!=="all"&&(s=s.filter(m=>m.marketplace===T)),$!=="all"&&(s=s.filter(m=>$==="enabled"?m.status==="enabled":m.status!=="enabled")),v!=="all"&&(s=s.filter(m=>_(m)===v));const d=z.trim().toLowerCase();return d&&(s=s.filter(m=>m.name.toLowerCase().includes(d)||m.description&&m.description.toLowerCase().includes(d)||m.marketplace.toLowerCase().includes(d)||_(m).includes(d))),s},[r,T,v,$,z]),C=x.useMemo(()=>{let s=l;v!=="all"&&(s=s.filter(m=>_(m)===v));const d=E.trim().toLowerCase();return d&&(s=s.filter(m=>m.name.toLowerCase().includes(d)||m.description&&m.description.toLowerCase().includes(d)||_(m).includes(d))),s},[l,E,v]);x.useEffect(()=>{ie(S)},[z,T,v,$,r.length]),x.useEffect(()=>{ce(S)},[E,v,l.length,f]);const je=x.useMemo(()=>P.slice(0,le),[P,le]),ke=x.useMemo(()=>C.slice(0,oe),[C,oe]),Ve=x.useCallback(()=>{ie(s=>Math.min(s+S,P.length))},[P.length]),Oe=x.useCallback(()=>{ce(s=>Math.min(s+S,C.length))},[C.length]);x.useEffect(()=>{if(!j){de(!1);return}const s=()=>{de(j.scrollTop>480)};return s(),j.addEventListener("scroll",s,{passive:!0}),()=>j.removeEventListener("scroll",s)},[j,h]);const qe=x.useCallback(()=>{j==null||j.scrollTo({top:0,behavior:"smooth"})},[j]),L=x.useMemo(()=>{const s={skills:0,mcp:0,hooks:0,tools:0,unknown:0},d=h==="browse"?l:r;for(const m of d)s[_(m)]+=1;return s},[r,l,h]),Je=r.filter(s=>s.status==="enabled").length;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden bg-bg-primary",children:[e.jsx("div",{className:"flex-none border-b border-border-muted px-6 py-4",children:e.jsxs("div",{className:"max-w-3xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("plugins.title")}),h==="installed"&&r.length>0&&e.jsxs("p",{className:"text-sm text-text-tertiary mt-0.5",children:[r.length," ",t("plugins.totalCount")," · ",Je," ",t("plugins.enabled")]}),h==="browse"&&f&&!c&&l.length>0&&e.jsxs("p",{className:"text-sm text-text-tertiary mt-0.5",children:[l.length," ",t("plugins.totalCount")]}),h==="marketplaces"&&n.length>0&&e.jsxs("p",{className:"text-sm text-text-tertiary mt-0.5",children:[n.length," ",t("plugins.totalCount")]})]}),e.jsx("button",{onClick:Fe,disabled:o||c,className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-all ${o||c?"opacity-50 cursor-not-allowed border-border-muted text-text-secondary":"border-border-muted text-text-secondary hover:text-text-primary hover:border-text-primary/20 hover:bg-bg-secondary"}`,title:t("plugins.refresh"),children:e.jsx(Ye,{size:14,className:o||c?"animate-spin":""})})]}),e.jsxs("div",{className:"flex gap-1 border-b border-border-muted",children:[e.jsx("button",{onClick:()=>{O("installed"),y(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${h==="installed"?"text-text-primary border-text-primary":"text-text-secondary border-transparent hover:text-text-primary"}`,children:t("plugins.installedPlugins")}),e.jsx("button",{onClick:()=>{O("browse"),y(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${h==="browse"?"text-text-primary border-text-primary":"text-text-secondary border-transparent hover:text-text-primary"}`,children:t("plugins.browseMarketplace")}),e.jsx("button",{onClick:()=>{O("marketplaces"),y(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${h==="marketplaces"?"text-text-primary border-text-primary":"text-text-secondary border-transparent hover:text-text-primary"}`,children:t("plugins.marketplaces")})]}),h==="installed"&&r.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mt-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(B,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary pointer-events-none"}),e.jsx("input",{type:"text",value:z,onChange:s=>ne(s.target.value),placeholder:t("plugins.searchPlaceholder"),className:"w-full bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg pl-9 pr-8 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary"}),z&&e.jsx("button",{onClick:()=>ne(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center rounded-full text-text-tertiary hover:text-text-secondary transition-colors",children:e.jsx(F,{size:12})})]}),ye.length>1&&e.jsxs("select",{value:T,onChange:s=>Se(s.target.value),className:"bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0 max-w-[120px] sm:max-w-[160px]",children:[e.jsx("option",{value:"all",children:t("plugins.allMarketplaces")}),ye.map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsxs("select",{value:$,onChange:s=>Te(s.target.value),className:"bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0",children:[e.jsx("option",{value:"all",children:t("plugins.filterStatusAll")}),e.jsx("option",{value:"enabled",children:t("plugins.filterStatusEnabled")}),e.jsx("option",{value:"disabled",children:t("plugins.filterStatusDisabled")})]})]}),(h==="installed"||h==="browse")&&e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 mt-3",children:[["all",t("plugins.kindAll"),h==="installed"?r.length:l.length],["skills",t("plugins.kindSkills"),L.skills],["mcp",t("plugins.kindMcp"),L.mcp],["hooks",t("plugins.kindHooks"),L.hooks],["tools",t("plugins.kindTools"),L.tools],["unknown",t("plugins.kindUnknown"),L.unknown]].map(([s,d,m])=>e.jsxs("button",{type:"button",onClick:()=>ze(s),className:`px-2.5 py-1 rounded-full text-[12px] border transition-colors ${v===s?"bg-bg-secondary text-text-primary border-text-primary/30 font-medium":"bg-transparent text-text-tertiary border-border-muted hover:text-text-secondary"}`,children:[d,e.jsx("span",{className:"ml-1 opacity-70",children:m})]},s))}),h==="browse"&&n.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mt-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(B,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary pointer-events-none"}),e.jsx("input",{type:"text",value:E,onChange:s=>Z(s.target.value),placeholder:t("plugins.searchPlaceholder"),className:"w-full bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg pl-9 pr-8 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary"}),E&&e.jsx("button",{onClick:()=>Z(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center rounded-full text-text-tertiary hover:text-text-secondary transition-colors",children:e.jsx(F,{size:12})})]}),e.jsxs("select",{value:f,onChange:s=>De(s.target.value),className:"bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0 max-w-[120px] sm:max-w-[160px]",children:[e.jsx("option",{value:"__all__",children:t("plugins.allMarketplaces")}),n.map(s=>e.jsx("option",{value:s.name,children:s.name},s.name))]})]})]})}),e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsx("div",{ref:$e,className:"h-full overflow-y-auto px-6 py-6",children:e.jsxs("div",{className:"max-w-3xl mx-auto space-y-6",children:[xe&&e.jsxs("div",{className:"bg-accent-red/10 border border-accent-red/30 rounded-xl p-3.5 text-accent-red text-[13px] flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(W,{size:14,className:"shrink-0"}),e.jsxs("span",{className:"truncate",children:[t("plugins.operationFailed"),": ",xe]})]}),e.jsx("button",{onClick:()=>y(null),className:"w-5 h-5 flex items-center justify-center rounded-full hover:bg-accent-red/20 transition-colors shrink-0 ml-3",children:e.jsx(F,{size:12})})]}),h==="installed"&&e.jsxs(e.Fragment,{children:[o&&r.length===0&&e.jsx("div",{className:"flex flex-col items-center justify-center py-20",children:e.jsx(ve,{size:"small",text:t("plugins.loading")})}),p&&!o&&r.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20",children:[e.jsx(W,{size:40,className:"text-text-tertiary opacity-40 mb-4"}),e.jsx("div",{className:"text-[14px] text-text-secondary font-medium mb-3",children:t("plugins.error")}),e.jsx("button",{onClick:g,className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors",children:t("plugins.retry")})]}),!o&&!p&&r.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-text-tertiary",children:[e.jsx(V,{size:48,className:"mb-4 opacity-30"}),e.jsx("div",{className:"text-[15px] font-medium mb-1.5 text-text-secondary",children:t("plugins.noPlugins")}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noPluginsHint")})]}),r.length>0&&P.length===0&&!o&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-text-tertiary",children:[e.jsx(B,{size:36,className:"mb-3 opacity-30"}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noSearchResults")})]}),P.length>0&&e.jsxs("div",{className:"space-y-3",children:[je.map(s=>{const d=Ke(s);return e.jsx(ct,{plugin:s,isEnabled:s.status==="enabled",isOperating:a.has(d),isExpanded:be===d,confirmUninstall:Le===d,onToggle:()=>Re(s),onUninstall:()=>He(s),onConfirmUninstall:()=>Q(d),onCancelUninstall:()=>Q(null),onExpand:()=>fe(d),t},d)}),e.jsx(Ne,{visible:je.length,total:P.length,onLoadMore:Ve,scrollRoot:j,t})]})]}),h==="browse"&&e.jsxs(e.Fragment,{children:[!i&&n.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-text-tertiary",children:[e.jsx(A,{size:48,className:"mb-4 opacity-30"}),e.jsx("div",{className:"text-[15px] font-medium mb-1.5 text-text-secondary",children:t("plugins.noMarketplaces")}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noMarketplacesHint")})]}),c&&l.length===0&&f&&e.jsx("div",{className:"flex flex-col items-center justify-center py-20",children:e.jsx(ve,{size:"small",text:t("plugins.browsingMarketplace")})}),b&&l.length===0&&f&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20",children:[e.jsx(W,{size:40,className:"text-text-tertiary opacity-40 mb-4"}),e.jsx("div",{className:"text-[14px] text-text-secondary font-medium mb-3",children:t("plugins.error")}),e.jsx("button",{onClick:()=>f&&k(f),className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors",children:t("plugins.retry")})]}),f&&l.length===0&&!c&&!b&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-text-tertiary",children:[e.jsx(V,{size:48,className:"mb-4 opacity-30"}),e.jsx("div",{className:"text-[15px] font-medium mb-1.5 text-text-secondary",children:t("plugins.noAvailablePlugins")}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noAvailablePluginsHint")})]}),l.length>0&&C.length===0&&!c&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-text-tertiary",children:[e.jsx(B,{size:36,className:"mb-3 opacity-30"}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noSearchResults")})]}),C.length>0&&e.jsxs("div",{className:"space-y-3",children:[ke.map(s=>{const d=`${s.name}@${s.marketplace}`;return e.jsx(dt,{plugin:s,isInstalled:s.installed,isOperating:a.has(d),isExpanded:be===d,onInstall:m=>Ie(s,m),onExpand:()=>fe(d),t},d)}),e.jsx(Ne,{visible:ke.length,total:C.length,onLoadMore:Oe,scrollRoot:j,t})]})]}),h==="marketplaces"&&e.jsxs("div",{className:"space-y-3",children:[!q&&e.jsxs("button",{onClick:()=>H(!0),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium text-text-primary border border-border-muted hover:bg-bg-tertiary hover:border-text-primary/30 transition-colors",children:[e.jsx(et,{size:12}),t("plugins.addMarketplace")]}),q&&e.jsxs("div",{className:"bg-bg-secondary rounded-xl border border-border-muted p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[13px] font-medium",children:t("plugins.addMarketplace")}),e.jsx("button",{onClick:()=>{H(!1),U(null)},className:"w-6 h-6 flex items-center justify-center rounded-full hover:bg-bg-tertiary transition-colors text-text-secondary",children:e.jsx(F,{size:12})})]}),e.jsx("input",{type:"text",value:I,onChange:s=>pe(s.target.value),placeholder:t("plugins.sourcePlaceholder"),className:"w-full bg-bg-primary text-text-primary text-[13px] border border-border-muted rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary"}),e.jsx("input",{type:"text",value:J,onChange:s=>me(s.target.value),placeholder:t("plugins.namePlaceholder"),className:"w-full bg-bg-primary text-text-primary text-[13px] border border-border-muted rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary"}),he&&e.jsx("div",{className:"text-accent-red text-[12px]",children:he}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>{H(!1),U(null)},className:"px-3 py-1.5 rounded-lg text-[12px] text-text-secondary hover:bg-bg-tertiary transition-colors",children:t("plugins.cancel")}),e.jsxs("button",{onClick:Ue,disabled:!I.trim()||ue,className:"px-3 py-1.5 rounded-lg text-[12px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1.5",children:[ue&&e.jsx(R,{size:12,className:"animate-spin"}),t("plugins.add")]})]})]}),i&&n.length===0&&e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(R,{size:18,className:"animate-spin text-text-tertiary"})}),!i&&n.length===0&&!q&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-text-tertiary",children:[e.jsx(A,{size:48,className:"mb-4 opacity-30"}),e.jsx("div",{className:"text-[15px] font-medium mb-1.5 text-text-secondary",children:t("plugins.noMarketplaces")}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noMarketplacesHint")})]}),n.length>0&&e.jsx("div",{className:"bg-bg-secondary rounded-xl border border-border-muted overflow-hidden",children:n.map((s,d)=>e.jsxs("div",{className:`flex items-center justify-between px-4 py-3 ${d>0?"border-t border-border-muted":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(A,{size:14,className:"text-text-tertiary shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium truncate",children:s.name}),s.type&&e.jsx("div",{className:"text-[11px] text-text-tertiary",children:s.type})]})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:_e===s.name?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>Be(s.name),className:"px-2.5 py-1 rounded-md text-[11px] font-medium text-white bg-accent-red hover:bg-accent-red/90 transition-colors",children:t("plugins.removeMarketplace")}),e.jsx("button",{onClick:()=>G(null),className:"px-2.5 py-1 rounded-md text-[11px] text-text-secondary hover:bg-bg-tertiary transition-colors",children:t("plugins.cancel")})]}):e.jsx("button",{onClick:()=>G(s.name),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-accent-red hover:bg-accent-red/10 transition-colors",title:t("plugins.removeMarketplace"),children:e.jsx(Ce,{size:13})})})]},s.name))})]})]})}),Ee&&e.jsxs("button",{type:"button",onClick:qe,className:"absolute bottom-5 right-5 z-10 flex items-center gap-1.5 rounded-full border border-border-muted bg-bg-secondary/95 px-3 py-2 text-[12px] font-medium text-text-primary shadow-sm backdrop-blur-sm transition-colors hover:bg-bg-tertiary","aria-label":t("plugins.backToTop"),children:[e.jsx(tt,{size:14}),t("plugins.backToTop")]})]})]})}function Ne({visible:t,total:r,onLoadMore:n,scrollRoot:o,t:i}){const p=x.useRef(null),a=t<r;return x.useEffect(()=>{const l=p.current;if(!l||!a)return;const c=new IntersectionObserver(b=>{b.some(g=>g.isIntersecting)&&n()},{root:o,rootMargin:"120px 0px",threshold:0});return c.observe(l),()=>c.disconnect()},[a,n,o,t,r]),r===0?null:e.jsxs("div",{ref:p,className:"flex flex-col items-center justify-center gap-1.5 pt-2 pb-1",children:[e.jsx("span",{className:"text-[12px] text-text-tertiary",children:i("plugins.infiniteRange").replace("{visible}",String(t)).replace("{total}",String(r))}),a?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] text-text-tertiary",children:[e.jsx(R,{size:12,className:"animate-spin"}),i("plugins.infiniteLoading")]}):e.jsx("span",{className:"text-[11px] text-text-tertiary",children:i("plugins.infiniteEnd")})]})}function ct({plugin:t,isEnabled:r,isOperating:n,isExpanded:o,confirmUninstall:i,onToggle:p,onUninstall:a,onConfirmUninstall:l,onCancelUninstall:c,onExpand:b,t:g}){return e.jsxs("div",{className:`group rounded-xl border transition-all ${r?"bg-bg-secondary border-border-muted":"bg-bg-secondary border-border-muted hover:border-border-muted"}`,children:[e.jsxs("div",{className:"flex items-start gap-4 px-5 py-4 cursor-pointer",onClick:b,children:[e.jsx("div",{className:`flex-shrink-0 w-9 h-9 rounded-lg flex items-center justify-center mt-0.5 ${r?"bg-text-primary/8":"bg-bg-tertiary"}`,children:e.jsx(V,{size:18,className:r?"text-text-primary":"text-text-tertiary"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:"text-[14px] font-semibold text-text-primary truncate",children:t.name}),t.version&&e.jsxs("span",{className:"text-[11px] text-text-tertiary shrink-0 font-mono",children:["v",t.version]}),e.jsx("span",{className:`text-[10px] px-1.5 py-px rounded font-medium shrink-0 ${r?"bg-accent-green/15 text-accent-green":"bg-bg-tertiary text-text-tertiary"}`,children:g(r?"plugins.enabled":"plugins.disabled")})]}),t.description&&e.jsx("div",{className:`text-[12px] text-text-secondary leading-relaxed mb-1.5 ${o?"":"line-clamp-2"}`,children:t.description}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-text-tertiary",children:[e.jsx(A,{size:10,className:"shrink-0"}),e.jsx("span",{children:t.marketplace}),t.installScope&&e.jsx("span",{className:"px-1.5 py-px rounded bg-bg-tertiary text-[10px] font-medium",children:g(`plugins.scope.${t.installScope}`)})]})]}),e.jsx("div",{className:"flex items-center gap-1.5 shrink-0 pt-0.5",onClick:N=>N.stopPropagation(),children:n?e.jsx("div",{className:"w-[72px] flex justify-center",children:e.jsx(R,{size:16,className:"animate-spin text-text-tertiary"})}):i?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:a,className:"px-2.5 py-1 rounded-md text-[11px] font-medium text-white bg-accent-red hover:bg-accent-red/90 transition-colors",children:g("plugins.uninstall")}),e.jsx("button",{onClick:c,className:"px-2.5 py-1 rounded-md text-[11px] text-text-secondary hover:bg-bg-tertiary transition-colors",children:g("plugins.cancel")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:t.canSwitchoff===!1?void 0:p,disabled:t.canSwitchoff===!1,className:`px-2.5 py-1.5 rounded-md text-[11px] font-medium transition-colors flex items-center gap-1 ${t.canSwitchoff===!1?"text-text-tertiary border border-border-muted cursor-not-allowed opacity-50":r?"text-text-secondary border border-border-muted hover:bg-bg-tertiary":"text-text-primary border border-border-muted hover:bg-bg-tertiary"}`,title:t.canSwitchoff===!1?g("plugins.policyCannotSwitchoff"):g(r?"plugins.disable":"plugins.enable"),children:[r?e.jsx(nt,{size:11}):e.jsx(st,{size:11}),g(r?"plugins.disable":"plugins.enable")]}),e.jsx("button",{onClick:t.canRemove===!1?void 0:l,disabled:t.canRemove===!1,className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors ${t.canRemove===!1?"text-text-tertiary cursor-not-allowed opacity-30":"text-text-tertiary hover:text-accent-red hover:bg-accent-red/10 opacity-0 group-hover:opacity-100"}`,title:t.canRemove===!1?g("plugins.policyCannotRemove"):g("plugins.uninstall"),children:e.jsx(Ce,{size:13})})]})})]}),o&&e.jsx(Me,{plugin:t,t:g})]})}function dt({plugin:t,isInstalled:r,isOperating:n,isExpanded:o,onInstall:i,onExpand:p,t:a}){return e.jsxs("div",{className:`group rounded-xl border transition-all ${r?"bg-bg-secondary border-border-muted":"bg-bg-secondary border-border-muted hover:border-border-muted"}`,children:[e.jsxs("div",{className:"flex items-start gap-4 px-5 py-4 cursor-pointer",onClick:p,children:[e.jsx("div",{className:`flex-shrink-0 w-9 h-9 rounded-lg flex items-center justify-center mt-0.5 ${r?"bg-text-primary/8":"bg-bg-tertiary"}`,children:e.jsx(V,{size:18,className:r?"text-text-primary":"text-text-tertiary"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:"text-[14px] font-semibold text-text-primary truncate",children:t.name}),t.version&&e.jsxs("span",{className:"text-[11px] text-text-tertiary shrink-0 font-mono",children:["v",t.version]}),r&&e.jsx("span",{className:"text-[10px] px-1.5 py-px rounded font-medium shrink-0 bg-accent-green/15 text-accent-green",children:a("plugins.installedLabel")})]}),t.description&&e.jsx("div",{className:`text-[12px] text-text-secondary leading-relaxed mb-1.5 ${o?"":"line-clamp-2"}`,children:t.description}),e.jsxs("div",{className:"flex items-center gap-1 text-[11px] text-text-tertiary",children:[e.jsx(A,{size:10,className:"shrink-0"}),e.jsx("span",{children:t.marketplace})]})]}),e.jsx("div",{className:"flex items-center gap-1.5 shrink-0 pt-0.5",onClick:l=>l.stopPropagation(),children:r?e.jsx("div",{className:"px-2.5 py-1.5 rounded-md text-[11px] font-medium text-text-tertiary bg-bg-tertiary",children:a("plugins.installed")}):n?e.jsx("div",{className:"w-[72px] flex justify-center",children:e.jsx(R,{size:16,className:"animate-spin text-text-tertiary"})}):e.jsx(xt,{onInstall:i,t:a})})]}),o&&e.jsx(Me,{plugin:t,t:a})]})}function Me({plugin:t,t:r}){const n=t.source,o=typeof n=="object"&&n!==null?n.url:void 0,i=typeof n=="object"&&n!==null?n.source:typeof n=="string"?n:void 0,p="installScope"in t?t.installScope:void 0;return e.jsxs("div",{className:"border-t border-border-muted mx-5 px-0 py-3.5 space-y-2.5",children:[p&&e.jsx(w,{label:r("plugins.scope"),children:e.jsx("span",{className:"text-[12px] text-text-secondary",children:r(`plugins.scope.${p}`)})}),t.category&&e.jsx(w,{label:r("plugins.category"),children:e.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded bg-[#f5a623]/8 text-[#b8860b] font-medium",children:t.category})}),t.author&&e.jsxs(w,{label:r("plugins.author"),children:[e.jsx("span",{className:"text-[12px] text-text-primary font-medium",children:t.author.name}),t.author.email&&e.jsx("a",{href:`mailto:${t.author.email}`,className:"text-[11px] text-text-tertiary hover:text-text-primary hover:underline ml-1",onClick:a=>a.stopPropagation(),children:t.author.email}),t.author.url&&e.jsxs("a",{href:t.author.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-0.5 text-[11px] text-text-tertiary hover:text-text-primary hover:underline ml-1",onClick:a=>a.stopPropagation(),children:[t.author.url,e.jsx(D,{size:9})]})]}),t.license&&e.jsx(w,{label:r("plugins.license"),children:e.jsx("span",{className:"text-[12px] text-text-secondary",children:t.license})}),t.homepage&&e.jsx(w,{label:r("plugins.homepage"),children:e.jsxs("a",{href:t.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all",onClick:a=>a.stopPropagation(),children:[t.homepage,e.jsx(D,{size:10,className:"shrink-0 text-text-tertiary"})]})}),t.repository&&e.jsx(w,{label:r("plugins.repository"),children:e.jsxs("a",{href:t.repository,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all",onClick:a=>a.stopPropagation(),children:[t.repository,e.jsx(D,{size:10,className:"shrink-0 text-text-tertiary"})]})}),i&&e.jsx(w,{label:r("plugins.source"),children:o?e.jsxs("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all",onClick:a=>a.stopPropagation(),children:[i,e.jsx(D,{size:10,className:"shrink-0 text-text-tertiary"})]}):e.jsx("span",{className:"text-[12px] text-text-secondary font-mono",children:i})}),t.keywords&&t.keywords.length>0&&e.jsx(w,{label:r("plugins.keywords"),children:e.jsx("div",{className:"flex flex-wrap gap-1",children:t.keywords.map(a=>e.jsx("span",{className:"text-[10px] px-1.5 py-px rounded bg-bg-tertiary text-text-tertiary",children:a},a))})}),t.features&&t.features.length>0&&e.jsx(w,{label:r("plugins.features"),children:e.jsx("ul",{className:"space-y-0.5",children:t.features.map((a,l)=>e.jsxs("li",{className:"text-[12px] text-text-secondary flex items-start gap-1.5",children:[e.jsx("span",{className:"text-text-tertiary shrink-0",children:"·"}),a]},l))})})]})}function w({label:t,children:r}){return e.jsxs("div",{className:"flex items-baseline gap-3",children:[e.jsx("span",{className:"text-[11px] text-text-tertiary w-12 shrink-0 text-right",children:t}),e.jsx("div",{className:"flex-1 min-w-0 flex items-baseline flex-wrap gap-1",children:r})]})}function xt({onInstall:t,t:r}){const[n,o]=x.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>o(!n),className:"px-2.5 py-1.5 rounded-md text-[11px] font-medium text-text-primary border border-border-muted hover:bg-bg-tertiary transition-colors flex items-center gap-1",title:r("plugins.install"),children:[e.jsx(rt,{size:11}),r("plugins.install")]}),n&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-50 bg-bg-primary border border-border-muted rounded-lg shadow-lg py-1 min-w-[220px]",children:[e.jsx("button",{onClick:()=>{t("user"),o(!1)},className:"w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors",children:r("plugins.installScope.user")}),e.jsx("button",{onClick:()=>{t("project"),o(!1)},className:"w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors",children:r("plugins.installScope.project")}),e.jsx("button",{onClick:()=>{t("project-local"),o(!1)},className:"w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors",children:r("plugins.installScope.local")})]})]})}export{ft as PluginsView};
11
+ */const lt=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5",key:"slp6dd"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244",key:"o0xfot"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05",key:"wn3emo"}]],A=Pe("store",lt);function K(t,r){return`${t}@${r}`}const M=Ge,it=Ze,we=Xe,ot=Qe((t,r)=>({plugins:[],loading:!1,error:null,marketplaces:[],marketplaceLoading:!1,availablePlugins:[],browsingMarketplace:null,browsingLoading:!1,browsingError:null,operatingPlugins:new Set,fetchPlugins:async()=>{t({loading:!0,error:null});try{const n=await we("/api/v1/plugins");if(!n.ok)throw new Error(`HTTP ${n.status}`);const i=(await n.json()).data,p=Array.isArray(i)?i.map(a=>({...a,canRemove:a.canRemove,canSwitchoff:a.canSwitchoff,canEdit:a.canEdit})):[];t({plugins:p,loading:!1})}catch(n){console.warn("[plugin-store] fetchPlugins failed:",n),t({error:n.message,loading:!1})}},fetchMarketplaces:async()=>{t({marketplaceLoading:!0});try{const n=await we("/api/v1/plugins/marketplaces");if(!n.ok)throw new Error(`HTTP ${n.status}`);const i=(await n.json()).data;t({marketplaces:Array.isArray(i)?i:[],marketplaceLoading:!1})}catch(n){console.warn("[plugin-store] fetchMarketplaces failed:",n),t({marketplaceLoading:!1})}},browseMarketplace:async n=>{var o;t({browsingMarketplace:n,browsingLoading:!0,browsingError:null});try{const i=await M("/api/v1/plugins/marketplaces/browse",{marketplace:n});if(!i.ok){const c=await i.json().catch(()=>null);throw new Error(((o=c==null?void 0:c.error)==null?void 0:o.message)||`HTTP ${i.status}`)}const p=await i.json(),l=(Array.isArray(p.data)?p.data:[]).map(c=>({name:c.name,version:c.version,description:c.description,marketplace:c.marketplaceName||n,installed:!!c.status,author:c.author,license:c.license,homepage:c.homepage,repository:c.repository,keywords:c.keywords,category:c.category,features:c.features,source:c.source,dependencies:c.dependencies}));t({availablePlugins:l,browsingLoading:!1})}catch(i){console.warn("[plugin-store] browseMarketplace failed:",i),t({browsingError:i.message,browsingLoading:!1})}},browseAllMarketplaces:async()=>{const{marketplaces:n}=r();if(n.length!==0){t({browsingMarketplace:"__all__",browsingLoading:!0,browsingError:null});try{const o=await Promise.allSettled(n.map(async c=>{var k;const b=await M("/api/v1/plugins/marketplaces/browse",{marketplace:c.name});if(!b.ok){const u=await b.json().catch(()=>null);throw new Error(((k=u==null?void 0:u.error)==null?void 0:k.message)||`HTTP ${b.status}`)}const g=await b.json();return(Array.isArray(g.data)?g.data:[]).map(u=>({name:u.name,version:u.version,description:u.description,marketplace:u.marketplaceName||c.name,installed:!!u.status,author:u.author,license:u.license,homepage:u.homepage,repository:u.repository,keywords:u.keywords,category:u.category,features:u.features,source:u.source,dependencies:u.dependencies}))})),i=[];let p=!1;for(const c of o)c.status==="fulfilled"?i.push(...c.value):p=!0;const a=new Set,l=i.filter(c=>{const b=`${c.name}@${c.marketplace}`;return a.has(b)?!1:(a.add(b),!0)});t({availablePlugins:l,browsingLoading:!1,browsingError:p&&l.length===0?"Some marketplaces failed to load":null})}catch(o){console.warn("[plugin-store] browseAllMarketplaces failed:",o),t({browsingError:o.message,browsingLoading:!1})}}},enablePlugin:async(n,o)=>{var p;const i=K(n,o);t(a=>({operatingPlugins:new Set(a.operatingPlugins).add(i)}));try{const a=await M("/api/v1/plugins/enable",{plugin:i});if(!a.ok){const l=await a.json().catch(()=>null);throw new Error(((p=l==null?void 0:l.error)==null?void 0:p.message)||`HTTP ${a.status}`)}await r().fetchPlugins()}finally{t(a=>{const l=new Set(a.operatingPlugins);return l.delete(i),{operatingPlugins:l}})}},disablePlugin:async(n,o)=>{var p;const i=K(n,o);t(a=>({operatingPlugins:new Set(a.operatingPlugins).add(i)}));try{const a=await M("/api/v1/plugins/disable",{plugin:i});if(!a.ok){const l=await a.json().catch(()=>null);throw new Error(((p=l==null?void 0:l.error)==null?void 0:p.message)||`HTTP ${a.status}`)}await r().fetchPlugins()}finally{t(a=>{const l=new Set(a.operatingPlugins);return l.delete(i),{operatingPlugins:l}})}},uninstallPlugin:async(n,o)=>{var p;const i=K(n,o);t(a=>({operatingPlugins:new Set(a.operatingPlugins).add(i)}));try{const a=await M("/api/v1/plugins/uninstall",{plugin:i});if(!a.ok){const l=await a.json().catch(()=>null);throw new Error(((p=l==null?void 0:l.error)==null?void 0:p.message)||`HTTP ${a.status}`)}await r().fetchPlugins()}finally{t(a=>{const l=new Set(a.operatingPlugins);return l.delete(i),{operatingPlugins:l}})}},installPlugin:async(n,o,i)=>{var a;const p=K(n,o);t(l=>({operatingPlugins:new Set(l.operatingPlugins).add(p)}));try{const l=await M("/api/v1/plugins",{plugin:p,options:i?{scope:i}:void 0});if(!l.ok){const b=await l.json().catch(()=>null);throw new Error(((a=b==null?void 0:b.error)==null?void 0:a.message)||`HTTP ${l.status}`)}await r().fetchPlugins();const c=r();c.browsingMarketplace&&(c.browsingMarketplace==="__all__"?await r().browseAllMarketplaces():await r().browseMarketplace(c.browsingMarketplace))}finally{t(l=>{const c=new Set(l.operatingPlugins);return c.delete(p),{operatingPlugins:c}})}},addMarketplace:async(n,o)=>{var p;const i=await M("/api/v1/plugins/marketplaces",{source:n,name:o});if(!i.ok){const a=await i.json().catch(()=>null);throw new Error(((p=a==null?void 0:a.error)==null?void 0:p.message)||`HTTP ${i.status}`)}await r().fetchMarketplaces()},removeMarketplace:async n=>{var i;const o=await it(`/api/v1/plugins/marketplaces/${encodeURIComponent(n)}`);if(!o.ok){const p=await o.json().catch(()=>null);throw new Error(((i=p==null?void 0:p.error)==null?void 0:i.message)||`HTTP ${o.status}`)}await r().fetchMarketplaces()}})),S=12;function _(t){const r=[t.category,...t.features||[],...t.keywords||[],t.name,t.description||""].join(" ").toLowerCase();return/\b(skill|skills)\b/.test(r)?"skills":/\b(mcp|model[- ]?context)\b/.test(r)?"mcp":/\b(hook|hooks)\b/.test(r)?"hooks":/\b(tool|tools)\b/.test(r)?"tools":"unknown"}function ft(){const{t}=We(),{plugins:r,marketplaces:n,loading:o,marketplaceLoading:i,error:p,operatingPlugins:a,availablePlugins:l,browsingLoading:c,browsingError:b,fetchPlugins:g,fetchMarketplaces:N,browseMarketplace:k,browseAllMarketplaces:u,enablePlugin:Y,disablePlugin:ee,uninstallPlugin:te,installPlugin:se,addMarketplace:re,removeMarketplace:ae}=ot(),[h,V]=x.useState("installed"),[z,ne]=x.useState(""),[T,Se]=x.useState("all"),[v,ze]=x.useState("all"),[$,Te]=x.useState("all"),[le,ie]=x.useState(S),[oe,ce]=x.useState(S),[j,$e]=x.useState(null),[Ee,de]=x.useState(!1),[xe,y]=x.useState(null),[q,H]=x.useState(!1),[U,pe]=x.useState(""),[J,me]=x.useState(""),[ue,ge]=x.useState(!1),[he,I]=x.useState(null),[Le,Q]=x.useState(null),[_e,G]=x.useState(null),[f,X]=x.useState(""),[E,Z]=x.useState(""),[be,Ae]=x.useState(null),fe=x.useCallback(s=>{Ae(d=>d===s?null:s)},[]);x.useEffect(()=>{g(),N()},[g,N]),x.useEffect(()=>{h==="browse"&&!f&&n.length>0&&(X("__all__"),u())},[h,n,f,u]);const Re=x.useCallback(async s=>{y(null);try{s.status==="enabled"?await ee(s.name,s.marketplace):await Y(s.name,s.marketplace)}catch(d){y(d.message)}},[Y,ee]),He=x.useCallback(async s=>{y(null),Q(null);try{await te(s.name,s.marketplace)}catch(d){y(d.message)}},[te]),Ue=x.useCallback(async(s,d)=>{y(null);try{await se(s.name,s.marketplace,d)}catch(m){y(m.message)}},[se]),Ie=x.useCallback(async()=>{const s=U.trim();if(s){ge(!0),I(null);try{await re(s,J.trim()||void 0),pe(""),me(""),H(!1)}catch(d){I(d.message)}finally{ge(!1)}}},[U,J,re]),Be=x.useCallback(async s=>{y(null),G(null);try{if(await ae(s),f===s&&n.length>1){const d=n.find(m=>m.name!==s);d&&(X(d.name),k(d.name))}}catch(d){y(d.message)}},[ae,f,n,k]),Fe=x.useCallback(()=>{g(),N(),h==="browse"&&f&&(f==="__all__"?u():k(f))},[g,N,h,f,k,u]),De=x.useCallback(s=>{X(s),Z(""),s==="__all__"?u():k(s)},[k,u]),Ke=s=>`${s.name}@${s.marketplace}`,ye=x.useMemo(()=>{const s=new Set(r.map(d=>d.marketplace));return Array.from(s).sort()},[r]),P=x.useMemo(()=>{let s=r;T!=="all"&&(s=s.filter(m=>m.marketplace===T)),$!=="all"&&(s=s.filter(m=>$==="enabled"?m.status==="enabled":m.status!=="enabled")),v!=="all"&&(s=s.filter(m=>_(m)===v));const d=z.trim().toLowerCase();return d&&(s=s.filter(m=>m.name.toLowerCase().includes(d)||m.description&&m.description.toLowerCase().includes(d)||m.marketplace.toLowerCase().includes(d)||_(m).includes(d))),s},[r,T,v,$,z]),C=x.useMemo(()=>{let s=l;v!=="all"&&(s=s.filter(m=>_(m)===v));const d=E.trim().toLowerCase();return d&&(s=s.filter(m=>m.name.toLowerCase().includes(d)||m.description&&m.description.toLowerCase().includes(d)||_(m).includes(d))),s},[l,E,v]);x.useEffect(()=>{ie(S)},[z,T,v,$,r.length]),x.useEffect(()=>{ce(S)},[E,v,l.length,f]);const je=x.useMemo(()=>P.slice(0,le),[P,le]),ke=x.useMemo(()=>C.slice(0,oe),[C,oe]),Oe=x.useCallback(()=>{ie(s=>Math.min(s+S,P.length))},[P.length]),Ve=x.useCallback(()=>{ce(s=>Math.min(s+S,C.length))},[C.length]);x.useEffect(()=>{if(!j){de(!1);return}const s=()=>{de(j.scrollTop>480)};return s(),j.addEventListener("scroll",s,{passive:!0}),()=>j.removeEventListener("scroll",s)},[j,h]);const qe=x.useCallback(()=>{j==null||j.scrollTo({top:0,behavior:"smooth"})},[j]),L=x.useMemo(()=>{const s={skills:0,mcp:0,hooks:0,tools:0,unknown:0},d=h==="browse"?l:r;for(const m of d)s[_(m)]+=1;return s},[r,l,h]),Je=r.filter(s=>s.status==="enabled").length;return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden bg-bg-primary",children:[e.jsx("div",{className:"flex-none border-b border-border-muted px-6 py-4",children:e.jsxs("div",{className:"max-w-3xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold text-text-primary",children:t("plugins.title")}),h==="installed"&&r.length>0&&e.jsxs("p",{className:"text-sm text-text-tertiary mt-0.5",children:[r.length," ",t("plugins.totalCount")," · ",Je," ",t("plugins.enabled")]}),h==="browse"&&f&&!c&&l.length>0&&e.jsxs("p",{className:"text-sm text-text-tertiary mt-0.5",children:[l.length," ",t("plugins.totalCount")]}),h==="marketplaces"&&n.length>0&&e.jsxs("p",{className:"text-sm text-text-tertiary mt-0.5",children:[n.length," ",t("plugins.totalCount")]})]}),e.jsx("button",{onClick:Fe,disabled:o||c,className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-all ${o||c?"opacity-50 cursor-not-allowed border-border-muted text-text-secondary":"border-border-muted text-text-secondary hover:text-text-primary hover:border-text-primary/20 hover:bg-bg-secondary"}`,title:t("plugins.refresh"),children:e.jsx(Ye,{size:14,className:o||c?"animate-spin":""})})]}),e.jsxs("div",{className:"flex gap-1 border-b border-border-muted",children:[e.jsx("button",{onClick:()=>{V("installed"),y(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${h==="installed"?"text-text-primary border-text-primary":"text-text-secondary border-transparent hover:text-text-primary"}`,children:t("plugins.installedPlugins")}),e.jsx("button",{onClick:()=>{V("browse"),y(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${h==="browse"?"text-text-primary border-text-primary":"text-text-secondary border-transparent hover:text-text-primary"}`,children:t("plugins.browseMarketplace")}),e.jsx("button",{onClick:()=>{V("marketplaces"),y(null)},className:`px-4 py-2.5 text-[13px] font-medium border-b-2 transition-colors ${h==="marketplaces"?"text-text-primary border-text-primary":"text-text-secondary border-transparent hover:text-text-primary"}`,children:t("plugins.marketplaces")})]}),h==="installed"&&r.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mt-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(B,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary pointer-events-none"}),e.jsx("input",{type:"text",value:z,onChange:s=>ne(s.target.value),placeholder:t("plugins.searchPlaceholder"),className:"w-full bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg pl-9 pr-8 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary"}),z&&e.jsx("button",{onClick:()=>ne(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center rounded-full text-text-tertiary hover:text-text-secondary transition-colors",children:e.jsx(F,{size:12})})]}),ye.length>1&&e.jsxs("select",{value:T,onChange:s=>Se(s.target.value),className:"bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0 max-w-[120px] sm:max-w-[160px]",children:[e.jsx("option",{value:"all",children:t("plugins.allMarketplaces")}),ye.map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsxs("select",{value:$,onChange:s=>Te(s.target.value),className:"bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0",children:[e.jsx("option",{value:"all",children:t("plugins.filterStatusAll")}),e.jsx("option",{value:"enabled",children:t("plugins.filterStatusEnabled")}),e.jsx("option",{value:"disabled",children:t("plugins.filterStatusDisabled")})]})]}),(h==="installed"||h==="browse")&&e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 mt-3",children:[["all",t("plugins.kindAll"),h==="installed"?r.length:l.length],["skills",t("plugins.kindSkills"),L.skills],["mcp",t("plugins.kindMcp"),L.mcp],["hooks",t("plugins.kindHooks"),L.hooks],["tools",t("plugins.kindTools"),L.tools],["unknown",t("plugins.kindUnknown"),L.unknown]].map(([s,d,m])=>e.jsxs("button",{type:"button",onClick:()=>ze(s),className:`px-2.5 py-1 rounded-full text-[12px] border transition-colors ${v===s?"bg-bg-secondary text-text-primary border-text-primary/30 font-medium":"bg-transparent text-text-tertiary border-border-muted hover:text-text-secondary"}`,children:[d,e.jsx("span",{className:"ml-1 opacity-70",children:m})]},s))}),h==="browse"&&n.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mt-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(B,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-tertiary pointer-events-none"}),e.jsx("input",{type:"text",value:E,onChange:s=>Z(s.target.value),placeholder:t("plugins.searchPlaceholder"),className:"w-full bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg pl-9 pr-8 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary"}),E&&e.jsx("button",{onClick:()=>Z(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center rounded-full text-text-tertiary hover:text-text-secondary transition-colors",children:e.jsx(F,{size:12})})]}),e.jsxs("select",{value:f,onChange:s=>De(s.target.value),className:"bg-bg-secondary text-text-primary text-[13px] border border-border-muted rounded-lg px-2 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all cursor-pointer shrink-0 max-w-[120px] sm:max-w-[160px]",children:[e.jsx("option",{value:"__all__",children:t("plugins.allMarketplaces")}),n.map(s=>e.jsx("option",{value:s.name,children:s.name},s.name))]})]})]})}),e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsx("div",{ref:$e,className:"h-full overflow-y-auto px-6 py-6",children:e.jsxs("div",{className:"max-w-3xl mx-auto space-y-6",children:[xe&&e.jsxs("div",{className:"bg-accent-red/10 border border-accent-red/30 rounded-xl p-3.5 text-accent-red text-[13px] flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(W,{size:14,className:"shrink-0"}),e.jsxs("span",{className:"truncate",children:[t("plugins.operationFailed"),": ",xe]})]}),e.jsx("button",{onClick:()=>y(null),className:"w-5 h-5 flex items-center justify-center rounded-full hover:bg-accent-red/20 transition-colors shrink-0 ml-3",children:e.jsx(F,{size:12})})]}),h==="installed"&&e.jsxs(e.Fragment,{children:[o&&r.length===0&&e.jsx("div",{className:"flex flex-col items-center justify-center py-20",children:e.jsx(ve,{size:"small",text:t("plugins.loading")})}),p&&!o&&r.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20",children:[e.jsx(W,{size:40,className:"text-text-tertiary opacity-40 mb-4"}),e.jsx("div",{className:"text-[14px] text-text-secondary font-medium mb-3",children:t("plugins.error")}),e.jsx("button",{onClick:g,className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors",children:t("plugins.retry")})]}),!o&&!p&&r.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-text-tertiary",children:[e.jsx(O,{size:48,className:"mb-4 opacity-30"}),e.jsx("div",{className:"text-[15px] font-medium mb-1.5 text-text-secondary",children:t("plugins.noPlugins")}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noPluginsHint")})]}),r.length>0&&P.length===0&&!o&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-text-tertiary",children:[e.jsx(B,{size:36,className:"mb-3 opacity-30"}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noSearchResults")})]}),P.length>0&&e.jsxs("div",{className:"space-y-3",children:[je.map(s=>{const d=Ke(s);return e.jsx(ct,{plugin:s,isEnabled:s.status==="enabled",isOperating:a.has(d),isExpanded:be===d,confirmUninstall:Le===d,onToggle:()=>Re(s),onUninstall:()=>He(s),onConfirmUninstall:()=>Q(d),onCancelUninstall:()=>Q(null),onExpand:()=>fe(d),t},d)}),e.jsx(Ne,{visible:je.length,total:P.length,onLoadMore:Oe,scrollRoot:j,t})]})]}),h==="browse"&&e.jsxs(e.Fragment,{children:[!i&&n.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-text-tertiary",children:[e.jsx(A,{size:48,className:"mb-4 opacity-30"}),e.jsx("div",{className:"text-[15px] font-medium mb-1.5 text-text-secondary",children:t("plugins.noMarketplaces")}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noMarketplacesHint")})]}),c&&l.length===0&&f&&e.jsx("div",{className:"flex flex-col items-center justify-center py-20",children:e.jsx(ve,{size:"small",text:t("plugins.browsingMarketplace")})}),b&&l.length===0&&f&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20",children:[e.jsx(W,{size:40,className:"text-text-tertiary opacity-40 mb-4"}),e.jsx("div",{className:"text-[14px] text-text-secondary font-medium mb-3",children:t("plugins.error")}),e.jsx("button",{onClick:()=>f&&k(f),className:"px-4 py-2 rounded-lg text-[13px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors",children:t("plugins.retry")})]}),f&&l.length===0&&!c&&!b&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-text-tertiary",children:[e.jsx(O,{size:48,className:"mb-4 opacity-30"}),e.jsx("div",{className:"text-[15px] font-medium mb-1.5 text-text-secondary",children:t("plugins.noAvailablePlugins")}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noAvailablePluginsHint")})]}),l.length>0&&C.length===0&&!c&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-text-tertiary",children:[e.jsx(B,{size:36,className:"mb-3 opacity-30"}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noSearchResults")})]}),C.length>0&&e.jsxs("div",{className:"space-y-3",children:[ke.map(s=>{const d=`${s.name}@${s.marketplace}`;return e.jsx(dt,{plugin:s,isInstalled:s.installed,isOperating:a.has(d),isExpanded:be===d,onInstall:m=>Ue(s,m),onExpand:()=>fe(d),t},d)}),e.jsx(Ne,{visible:ke.length,total:C.length,onLoadMore:Ve,scrollRoot:j,t})]})]}),h==="marketplaces"&&e.jsxs("div",{className:"space-y-3",children:[!q&&e.jsxs("button",{onClick:()=>H(!0),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[12px] font-medium text-text-primary border border-border-muted hover:bg-bg-tertiary hover:border-text-primary/30 transition-colors",children:[e.jsx(et,{size:12}),t("plugins.addMarketplace")]}),q&&e.jsxs("div",{className:"bg-bg-secondary rounded-xl border border-border-muted p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[13px] font-medium",children:t("plugins.addMarketplace")}),e.jsx("button",{onClick:()=>{H(!1),I(null)},className:"w-6 h-6 flex items-center justify-center rounded-full hover:bg-bg-tertiary transition-colors text-text-secondary",children:e.jsx(F,{size:12})})]}),e.jsx("input",{type:"text",value:U,onChange:s=>pe(s.target.value),placeholder:t("plugins.sourcePlaceholder"),className:"w-full bg-bg-primary text-text-primary text-[13px] border border-border-muted rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary"}),e.jsx("input",{type:"text",value:J,onChange:s=>me(s.target.value),placeholder:t("plugins.namePlaceholder"),className:"w-full bg-bg-primary text-text-primary text-[13px] border border-border-muted rounded-lg px-3 py-2 outline-none focus:ring-2 focus:ring-text-primary/10 focus:border-text-primary/30 transition-all placeholder:text-text-tertiary"}),he&&e.jsx("div",{className:"text-accent-red text-[12px]",children:he}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>{H(!1),I(null)},className:"px-3 py-1.5 rounded-lg text-[12px] text-text-secondary hover:bg-bg-tertiary transition-colors",children:t("plugins.cancel")}),e.jsxs("button",{onClick:Ie,disabled:!U.trim()||ue,className:"px-3 py-1.5 rounded-lg text-[12px] font-medium bg-text-primary text-white hover:opacity-80 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1.5",children:[ue&&e.jsx(R,{size:12,className:"animate-spin"}),t("plugins.add")]})]})]}),i&&n.length===0&&e.jsx("div",{className:"flex items-center justify-center py-6",children:e.jsx(R,{size:18,className:"animate-spin text-text-tertiary"})}),!i&&n.length===0&&!q&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-text-tertiary",children:[e.jsx(A,{size:48,className:"mb-4 opacity-30"}),e.jsx("div",{className:"text-[15px] font-medium mb-1.5 text-text-secondary",children:t("plugins.noMarketplaces")}),e.jsx("div",{className:"text-[13px]",children:t("plugins.noMarketplacesHint")})]}),n.length>0&&e.jsx("div",{className:"bg-bg-secondary rounded-xl border border-border-muted overflow-hidden",children:n.map((s,d)=>e.jsxs("div",{className:`flex items-center justify-between px-4 py-3 ${d>0?"border-t border-border-muted":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(A,{size:14,className:"text-text-tertiary shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium truncate",children:s.name}),s.type&&e.jsx("div",{className:"text-[11px] text-text-tertiary",children:s.type})]})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:_e===s.name?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>Be(s.name),className:"px-2.5 py-1 rounded-md text-[11px] font-medium text-white bg-accent-red hover:bg-accent-red/90 transition-colors",children:t("plugins.removeMarketplace")}),e.jsx("button",{onClick:()=>G(null),className:"px-2.5 py-1 rounded-md text-[11px] text-text-secondary hover:bg-bg-tertiary transition-colors",children:t("plugins.cancel")})]}):e.jsx("button",{onClick:()=>G(s.name),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-accent-red hover:bg-accent-red/10 transition-colors",title:t("plugins.removeMarketplace"),children:e.jsx(Ce,{size:13})})})]},s.name))})]})]})}),Ee&&e.jsxs("button",{type:"button",onClick:qe,className:"absolute bottom-5 right-5 z-10 flex items-center gap-1.5 rounded-full border border-border-muted bg-bg-secondary/95 px-3 py-2 text-[12px] font-medium text-text-primary shadow-sm backdrop-blur-sm transition-colors hover:bg-bg-tertiary","aria-label":t("plugins.backToTop"),children:[e.jsx(tt,{size:14}),t("plugins.backToTop")]})]})]})}function Ne({visible:t,total:r,onLoadMore:n,scrollRoot:o,t:i}){const p=x.useRef(null),a=t<r;return x.useEffect(()=>{const l=p.current;if(!l||!a)return;const c=new IntersectionObserver(b=>{b.some(g=>g.isIntersecting)&&n()},{root:o,rootMargin:"120px 0px",threshold:0});return c.observe(l),()=>c.disconnect()},[a,n,o,t,r]),r===0?null:e.jsxs("div",{ref:p,className:"flex flex-col items-center justify-center gap-1.5 pt-2 pb-1",children:[e.jsx("span",{className:"text-[12px] text-text-tertiary",children:i("plugins.infiniteRange").replace("{visible}",String(t)).replace("{total}",String(r))}),a?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] text-text-tertiary",children:[e.jsx(R,{size:12,className:"animate-spin"}),i("plugins.infiniteLoading")]}):e.jsx("span",{className:"text-[11px] text-text-tertiary",children:i("plugins.infiniteEnd")})]})}function ct({plugin:t,isEnabled:r,isOperating:n,isExpanded:o,confirmUninstall:i,onToggle:p,onUninstall:a,onConfirmUninstall:l,onCancelUninstall:c,onExpand:b,t:g}){return e.jsxs("div",{className:`group rounded-xl border transition-all ${r?"bg-bg-secondary border-border-muted":"bg-bg-secondary border-border-muted hover:border-border-muted"}`,children:[e.jsxs("div",{className:"flex items-start gap-4 px-5 py-4 cursor-pointer",onClick:b,children:[e.jsx("div",{className:`flex-shrink-0 w-9 h-9 rounded-lg flex items-center justify-center mt-0.5 ${r?"bg-text-primary/8":"bg-bg-tertiary"}`,children:e.jsx(O,{size:18,className:r?"text-text-primary":"text-text-tertiary"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:"text-[14px] font-semibold text-text-primary truncate",children:t.name}),t.version&&e.jsxs("span",{className:"text-[11px] text-text-tertiary shrink-0 font-mono",children:["v",t.version]}),e.jsx("span",{className:`text-[10px] px-1.5 py-px rounded font-medium shrink-0 ${r?"bg-accent-green/15 text-accent-green":"bg-bg-tertiary text-text-tertiary"}`,children:g(r?"plugins.enabled":"plugins.disabled")})]}),t.description&&e.jsx("div",{className:`text-[12px] text-text-secondary leading-relaxed mb-1.5 ${o?"":"line-clamp-2"}`,children:t.description}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-text-tertiary",children:[e.jsx(A,{size:10,className:"shrink-0"}),e.jsx("span",{children:t.marketplace}),t.installScope&&e.jsx("span",{className:"px-1.5 py-px rounded bg-bg-tertiary text-[10px] font-medium",children:g(`plugins.scope.${t.installScope}`)})]})]}),e.jsx("div",{className:"flex items-center gap-1.5 shrink-0 pt-0.5",onClick:N=>N.stopPropagation(),children:n?e.jsx("div",{className:"w-[72px] flex justify-center",children:e.jsx(R,{size:16,className:"animate-spin text-text-tertiary"})}):i?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:a,className:"px-2.5 py-1 rounded-md text-[11px] font-medium text-white bg-accent-red hover:bg-accent-red/90 transition-colors",children:g("plugins.uninstall")}),e.jsx("button",{onClick:c,className:"px-2.5 py-1 rounded-md text-[11px] text-text-secondary hover:bg-bg-tertiary transition-colors",children:g("plugins.cancel")})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:t.canSwitchoff===!1?void 0:p,disabled:t.canSwitchoff===!1,className:`px-2.5 py-1.5 rounded-md text-[11px] font-medium transition-colors flex items-center gap-1 ${t.canSwitchoff===!1?"text-text-tertiary border border-border-muted cursor-not-allowed opacity-50":r?"text-text-secondary border border-border-muted hover:bg-bg-tertiary":"text-text-primary border border-border-muted hover:bg-bg-tertiary"}`,title:t.canSwitchoff===!1?g("plugins.policyCannotSwitchoff"):g(r?"plugins.disable":"plugins.enable"),children:[r?e.jsx(nt,{size:11}):e.jsx(st,{size:11}),g(r?"plugins.disable":"plugins.enable")]}),e.jsx("button",{onClick:t.canRemove===!1?void 0:l,disabled:t.canRemove===!1,className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors ${t.canRemove===!1?"text-text-tertiary cursor-not-allowed opacity-30":"text-text-tertiary hover:text-accent-red hover:bg-accent-red/10 opacity-0 group-hover:opacity-100"}`,title:t.canRemove===!1?g("plugins.policyCannotRemove"):g("plugins.uninstall"),children:e.jsx(Ce,{size:13})})]})})]}),o&&e.jsx(Me,{plugin:t,t:g})]})}function dt({plugin:t,isInstalled:r,isOperating:n,isExpanded:o,onInstall:i,onExpand:p,t:a}){return e.jsxs("div",{className:`group rounded-xl border transition-all ${r?"bg-bg-secondary border-border-muted":"bg-bg-secondary border-border-muted hover:border-border-muted"}`,children:[e.jsxs("div",{className:"flex items-start gap-4 px-5 py-4 cursor-pointer",onClick:p,children:[e.jsx("div",{className:`flex-shrink-0 w-9 h-9 rounded-lg flex items-center justify-center mt-0.5 ${r?"bg-text-primary/8":"bg-bg-tertiary"}`,children:e.jsx(O,{size:18,className:r?"text-text-primary":"text-text-tertiary"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:"text-[14px] font-semibold text-text-primary truncate",children:t.name}),t.version&&e.jsxs("span",{className:"text-[11px] text-text-tertiary shrink-0 font-mono",children:["v",t.version]}),r&&e.jsx("span",{className:"text-[10px] px-1.5 py-px rounded font-medium shrink-0 bg-accent-green/15 text-accent-green",children:a("plugins.installedLabel")})]}),t.description&&e.jsx("div",{className:`text-[12px] text-text-secondary leading-relaxed mb-1.5 ${o?"":"line-clamp-2"}`,children:t.description}),e.jsxs("div",{className:"flex items-center gap-1 text-[11px] text-text-tertiary",children:[e.jsx(A,{size:10,className:"shrink-0"}),e.jsx("span",{children:t.marketplace})]})]}),e.jsx("div",{className:"flex items-center gap-1.5 shrink-0 pt-0.5",onClick:l=>l.stopPropagation(),children:r?e.jsx("div",{className:"px-2.5 py-1.5 rounded-md text-[11px] font-medium text-text-tertiary bg-bg-tertiary",children:a("plugins.installed")}):n?e.jsx("div",{className:"w-[72px] flex justify-center",children:e.jsx(R,{size:16,className:"animate-spin text-text-tertiary"})}):e.jsx(xt,{onInstall:i,t:a})})]}),o&&e.jsx(Me,{plugin:t,t:a})]})}function Me({plugin:t,t:r}){const n=t.source,o=typeof n=="object"&&n!==null?n.url:void 0,i=typeof n=="object"&&n!==null?n.source:typeof n=="string"?n:void 0,p="installScope"in t?t.installScope:void 0;return e.jsxs("div",{className:"border-t border-border-muted mx-5 px-0 py-3.5 space-y-2.5",children:[p&&e.jsx(w,{label:r("plugins.scope"),children:e.jsx("span",{className:"text-[12px] text-text-secondary",children:r(`plugins.scope.${p}`)})}),t.category&&e.jsx(w,{label:r("plugins.category"),children:e.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded bg-[#f5a623]/8 text-[#b8860b] font-medium",children:t.category})}),t.author&&e.jsxs(w,{label:r("plugins.author"),children:[e.jsx("span",{className:"text-[12px] text-text-primary font-medium",children:t.author.name}),t.author.email&&e.jsx("a",{href:`mailto:${t.author.email}`,className:"text-[11px] text-text-tertiary hover:text-text-primary hover:underline ml-1",onClick:a=>a.stopPropagation(),children:t.author.email}),t.author.url&&e.jsxs("a",{href:t.author.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-0.5 text-[11px] text-text-tertiary hover:text-text-primary hover:underline ml-1",onClick:a=>a.stopPropagation(),children:[t.author.url,e.jsx(D,{size:9})]})]}),t.license&&e.jsx(w,{label:r("plugins.license"),children:e.jsx("span",{className:"text-[12px] text-text-secondary",children:t.license})}),t.homepage&&e.jsx(w,{label:r("plugins.homepage"),children:e.jsxs("a",{href:t.homepage,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all",onClick:a=>a.stopPropagation(),children:[t.homepage,e.jsx(D,{size:10,className:"shrink-0 text-text-tertiary"})]})}),t.repository&&e.jsx(w,{label:r("plugins.repository"),children:e.jsxs("a",{href:t.repository,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all",onClick:a=>a.stopPropagation(),children:[t.repository,e.jsx(D,{size:10,className:"shrink-0 text-text-tertiary"})]})}),i&&e.jsx(w,{label:r("plugins.source"),children:o?e.jsxs("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[12px] text-text-secondary hover:text-text-primary hover:underline break-all",onClick:a=>a.stopPropagation(),children:[i,e.jsx(D,{size:10,className:"shrink-0 text-text-tertiary"})]}):e.jsx("span",{className:"text-[12px] text-text-secondary font-mono",children:i})}),t.keywords&&t.keywords.length>0&&e.jsx(w,{label:r("plugins.keywords"),children:e.jsx("div",{className:"flex flex-wrap gap-1",children:t.keywords.map(a=>e.jsx("span",{className:"text-[10px] px-1.5 py-px rounded bg-bg-tertiary text-text-tertiary",children:a},a))})}),t.features&&t.features.length>0&&e.jsx(w,{label:r("plugins.features"),children:e.jsx("ul",{className:"space-y-0.5",children:t.features.map((a,l)=>e.jsxs("li",{className:"text-[12px] text-text-secondary flex items-start gap-1.5",children:[e.jsx("span",{className:"text-text-tertiary shrink-0",children:"·"}),a]},l))})})]})}function w({label:t,children:r}){return e.jsxs("div",{className:"flex items-baseline gap-3",children:[e.jsx("span",{className:"text-[11px] text-text-tertiary w-12 shrink-0 text-right",children:t}),e.jsx("div",{className:"flex-1 min-w-0 flex items-baseline flex-wrap gap-1",children:r})]})}function xt({onInstall:t,t:r}){const[n,o]=x.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>o(!n),className:"px-2.5 py-1.5 rounded-md text-[11px] font-medium text-text-primary border border-border-muted hover:bg-bg-tertiary transition-colors flex items-center gap-1",title:r("plugins.install"),children:[e.jsx(rt,{size:11}),r("plugins.install")]}),n&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 z-50 bg-bg-primary border border-border-muted rounded-lg shadow-lg py-1 min-w-[220px]",children:[e.jsx("button",{onClick:()=>{t("user"),o(!1)},className:"w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors",children:r("plugins.installScope.user")}),e.jsx("button",{onClick:()=>{t("project"),o(!1)},className:"w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors",children:r("plugins.installScope.project")}),e.jsx("button",{onClick:()=>{t("project-local"),o(!1)},className:"w-full text-left px-3 py-2 text-[12px] text-text-primary hover:bg-bg-secondary transition-colors",children:r("plugins.installScope.local")})]})]})}export{ft as PluginsView};
@@ -1,4 +1,4 @@
1
- import{a as n,j as e}from"./markdown-DIY6o85n.js";import{c as W,u as J,x as z,aO as P,U as E,h as V,A as q,aP as I,aQ as R,P as T,ab as X,aN as Y,aR as Z}from"./index-CHcoPr8x.js";import"./vendor-D35k0Cos.js";/**
1
+ import{a as n,j as e}from"./markdown-CP9awqWt.js";import{c as W,u as J,x as z,aP as P,U as E,h as V,A as q,aQ as I,aR as R,P as T,ab as X,aO as Y,aS as Z}from"./index-CBmymKHy.js";import"./vendor-iLJwFVtf.js";/**
2
2
  * @license lucide-react v1.18.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{a as c,j as e}from"./markdown-DIY6o85n.js";import{c as Ce,u as ne,aS as Ke,X as Ie,P as Se,aC as Ee,aN as we,af as Pe,aT as Oe,aU as Fe,aV as q,aW as Me,aX as G,aY as Re,aZ as ce,a_ as $e,a$ as me,b0 as ge,F as _e,b1 as Le,b2 as ze,U as te,b3 as De,b4 as pe,b5 as Te,b6 as Be,w as Ue,q as Ve,b7 as He,h as de,b8 as he,a0 as qe,b9 as Ge,ba as Je,bb as We,bc as Qe,Z as xe,C as be,bd as Ze,be as Xe}from"./index-CHcoPr8x.js";import"./vendor-D35k0Cos.js";/**
1
+ import{a as c,j as e}from"./markdown-CP9awqWt.js";import{c as Ce,u as ne,aT as Ke,X as Ie,P as we,aD as Ee,aO as Se,af as Pe,aU as Oe,aV as Fe,aW as q,aX as Me,aY as G,aZ as Re,a_ as ce,a$ as $e,b0 as me,b1 as ge,F as _e,b2 as Le,b3 as De,U as te,b4 as ze,b5 as pe,b6 as Te,b7 as Be,w as Ue,q as Ve,b8 as He,h as de,b9 as he,a1 as qe,ba as Ge,bb as Je,bc as We,bd as Qe,Z as xe,C as be,be as Ze,bf as Xe}from"./index-CBmymKHy.js";import"./vendor-iLJwFVtf.js";/**
2
2
  * @license lucide-react v1.18.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -8,4 +8,4 @@ import{a as c,j as e}from"./markdown-DIY6o85n.js";import{c as Ce,u as ne,aS as K
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const tt=[["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M14.837 16.385a6 6 0 1 1-7.223-7.222c.624-.147.97.66.715 1.248a4 4 0 0 0 5.26 5.259c.589-.255 1.396.09 1.248.715",key:"xlf6rm"}],["path",{d:"M16 12a4 4 0 0 0-4-4",key:"6vsxu"}],["path",{d:"m19 5-1.256 1.256",key:"1yg6a6"}],["path",{d:"M20 12h2",key:"1q8mjw"}]],st=Ce("sun-moon",tt),nt=["128000","256000","1000000"],at=["16384","32768","65536","128000"],ye={id:"",name:"",vendor:"Custom",url:"",apiKey:"",maxInputTokens:"128000",maxOutputTokens:"16384",temperature:"",supportsToolCall:!0,supportsImages:!1,supportsReasoning:!1,useCustomProtocol:!1};function fe(t){const s=Number(t);return Number.isFinite(s)?s>=1e6&&s%1e6===0?`${s/1e6}M`:s>=1e3&&s%1e3===0?`${s/1e3}k`:s>=1024&&s%1024===0?`${s/1024}k`:String(s):t}function je(t){const{label:s,value:m,presets:u,disabled:x,step:k,formatLabel:h,onChange:f}=t,b=u.includes(m),M=b?m:"__custom__",d=h||(g=>g);return e.jsxs("label",{className:"custom-models-field",children:[e.jsx("span",{children:s}),e.jsxs("select",{className:"custom-models-select",value:M,disabled:x,onChange:g=>{const l=g.target.value;if(l==="__custom__"){f(m&&!Number.isNaN(Number(m))?m:u[0]);return}f(l)},children:[u.map(g=>e.jsx("option",{value:g,children:d(g)},g)),e.jsx("option",{value:"__custom__",children:"Custom…"})]}),!b&&e.jsx("input",{className:"settings-input",type:"number",step:k,value:m,disabled:x,onChange:g=>f(g.target.value),placeholder:u[0]})]})}function lt(t){return{id:t.id||"",name:t.name||"",vendor:t.vendor||"Custom",url:t.url||"",apiKey:t.apiKey||"",maxInputTokens:t.maxInputTokens!=null?String(t.maxInputTokens):"",maxOutputTokens:t.maxOutputTokens!=null?String(t.maxOutputTokens):"",temperature:t.temperature!=null?String(t.temperature):"",supportsToolCall:t.supportsToolCall!==!1,supportsImages:!!t.supportsImages,supportsReasoning:!!t.supportsReasoning,useCustomProtocol:!!t.useCustomProtocol}}function ue(t){const s=t.trim();return s!==""&&!Number.isNaN(Number(s))?Number(s):void 0}function it(t){const s={id:t.id.trim(),name:t.name.trim()||t.id.trim(),vendor:t.vendor.trim()||"Custom",url:t.url.trim(),supportsToolCall:t.supportsToolCall,supportsImages:t.supportsImages,supportsReasoning:t.supportsReasoning,useCustomProtocol:t.useCustomProtocol};t.apiKey.trim()&&(s.apiKey=t.apiKey.trim());const m=ue(t.maxInputTokens);m!==void 0&&(s.maxInputTokens=m);const u=ue(t.maxOutputTokens);u!==void 0&&(s.maxOutputTokens=u);const x=ue(t.temperature);return x!==void 0&&(s.temperature=x),s}const ot=/^[a-zA-Z0-9._:-]+$/;function rt({onClose:t}){const{t:s}=ne(),[m,u]=c.useState("list"),[x,k]=c.useState([]),[h,f]=c.useState(!0),[b,M]=c.useState(!1),[d,g]=c.useState(null),[l,C]=c.useState(ye),[S,O]=c.useState(),[A,I]=c.useState(null),D=c.useCallback(async()=>{f(!0),g(null);try{const i=await Ke(!0),N=Array.isArray(i==null?void 0:i.models)?i.models:[];k(N)}catch(i){g((i==null?void 0:i.message)||s("settings.customModels.loadFailed")),k([])}finally{f(!1)}},[]);c.useEffect(()=>{D().catch(()=>{})},[D]),c.useEffect(()=>{const i=N=>{if(N.key==="Escape"){if(A){I(null);return}if(m==="form"){u("list"),g(null);return}t()}};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[A,m,t]);const B=()=>{C(ye),O(void 0),g(null),u("form")},T=i=>{C(lt(i)),O(i.id),g(null),u("form")},F=()=>{u("list"),g(null),O(void 0)},j=(i,N)=>{C(w=>({...w,[i]:N}))},U=async()=>{const i=l.id.trim(),N=l.url.trim();if(!i){g(s("settings.customModels.err.idRequired"));return}if(!ot.test(i)){g(s("settings.customModels.err.idInvalid"));return}if(!N){g(s("settings.customModels.err.urlRequired"));return}if(!/^https?:\/\//i.test(N)){g(s("settings.customModels.err.urlInvalid"));return}if((!S||S!==i)&&x.some(w=>w.id===i)){g(s("settings.customModels.err.idDuplicate"));return}M(!0),g(null);try{const w=it(l);if(S&&!l.apiKey.trim()){const K=x.find(V=>V.id===S);K!=null&&K.apiKey&&(w.apiKey=K.apiKey)}const _=await Oe({model:w,previousId:S&&S!==i?S:void 0,visible:!1,global:!0});k(Array.isArray(_.models)?_.models:[]),u("list"),O(void 0)}catch(w){g((w==null?void 0:w.message)||s("settings.customModels.saveFailed"))}finally{M(!1)}},$=async()=>{if(A){M(!0),g(null);try{const i=await Fe(A.id,!0);k(Array.isArray(i.models)?i.models:[]),I(null)}catch(i){g((i==null?void 0:i.message)||s("settings.customModels.deleteFailed")),I(null)}finally{M(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"custom-models-overlay",onClick:t,children:e.jsxs("div",{className:"custom-models-modal",role:"dialog","aria-modal":"true","aria-labelledby":"custom-models-title",onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"custom-models-header",children:[e.jsx("h2",{id:"custom-models-title",className:"custom-models-title",children:s(m==="list"?"settings.customModels.title":S?"settings.customModels.editTitle":"settings.customModels.addTitle")}),e.jsx("button",{type:"button",className:"custom-models-icon-btn",onClick:t,"aria-label":s("settings.customModels.close"),children:e.jsx(Ie,{size:16})})]}),d&&e.jsx("div",{className:"custom-models-error",children:d}),m==="list"?e.jsxs("div",{className:"custom-models-body",children:[e.jsxs("div",{className:"custom-models-toolbar",children:[e.jsx("span",{className:"custom-models-hint",children:s("settings.customModels.hint")}),e.jsxs("button",{type:"button",className:"settings-toggle-btn",onClick:B,children:[e.jsx(Se,{size:14}),e.jsx("span",{children:s("settings.customModels.add")})]})]}),h?e.jsx("div",{className:"custom-models-empty",children:s("settings.loading")}):x.length===0?e.jsx("div",{className:"custom-models-empty",children:s("settings.customModels.empty")}):e.jsx("ul",{className:"custom-models-list",children:x.map(i=>e.jsxs("li",{className:"custom-models-row",children:[e.jsxs("div",{className:"custom-models-row-main",children:[e.jsx("div",{className:"custom-models-row-name",children:i.name||i.id}),e.jsxs("div",{className:"custom-models-row-meta",children:[e.jsx("span",{className:"font-mono",children:i.id}),i.vendor?e.jsxs("span",{children:["· ",i.vendor]}):null]}),i.url?e.jsx("div",{className:"custom-models-row-url",title:i.url,children:i.url}):null]}),e.jsxs("div",{className:"custom-models-row-actions",children:[e.jsx("button",{type:"button",className:"custom-models-icon-btn",onClick:()=>T(i),title:s("settings.customModels.edit"),children:e.jsx(Ee,{size:14})}),e.jsx("button",{type:"button",className:"custom-models-icon-btn danger",onClick:()=>I(i),title:s("settings.customModels.delete"),children:e.jsx(we,{size:14})})]})]},i.id))})]}):e.jsxs("div",{className:"custom-models-body custom-models-form",children:[e.jsxs("label",{className:"custom-models-field",children:[e.jsxs("span",{children:[s("settings.customModels.field.id")," *"]}),e.jsx("input",{className:"settings-input",value:l.id,onChange:i=>j("id",i.target.value),placeholder:"my-openai-model",disabled:b})]}),e.jsxs("label",{className:"custom-models-field",children:[e.jsx("span",{children:s("settings.customModels.field.name")}),e.jsx("input",{className:"settings-input",value:l.name,onChange:i=>j("name",i.target.value),disabled:b})]}),e.jsxs("label",{className:"custom-models-field",children:[e.jsx("span",{children:s("settings.customModels.field.vendor")}),e.jsx("input",{className:"settings-input",value:l.vendor,onChange:i=>j("vendor",i.target.value),placeholder:"OpenAI / Anthropic / Custom",disabled:b})]}),e.jsxs("label",{className:"custom-models-field",children:[e.jsxs("span",{children:[s("settings.customModels.field.url")," *"]}),e.jsx("input",{className:"settings-input",value:l.url,onChange:i=>j("url",i.target.value),placeholder:"https://api.example.com/v1/chat/completions",disabled:b})]}),e.jsxs("label",{className:"custom-models-field",children:[e.jsx("span",{children:s("settings.customModels.field.apiKey")}),e.jsx("input",{className:"settings-input",type:"password",autoComplete:"off",value:l.apiKey,onChange:i=>j("apiKey",i.target.value),placeholder:S?s("settings.customModels.apiKeyKeep"):"",disabled:b})]}),e.jsxs("div",{className:"custom-models-field-row",children:[e.jsx(je,{label:s("settings.customModels.field.maxInputTokens"),value:l.maxInputTokens,presets:nt,formatLabel:fe,disabled:b,onChange:i=>j("maxInputTokens",i)}),e.jsx(je,{label:s("settings.customModels.field.maxOutputTokens"),value:l.maxOutputTokens,presets:at,formatLabel:fe,disabled:b,onChange:i=>j("maxOutputTokens",i)}),e.jsxs("label",{className:"custom-models-field",children:[e.jsx("span",{children:s("settings.customModels.field.temperature")}),e.jsx("input",{className:"settings-input",type:"number",step:"0.1",min:"0",max:"2",value:l.temperature,disabled:b,onChange:i=>j("temperature",i.target.value),placeholder:s("settings.customModels.field.temperatureDefault")})]})]}),e.jsxs("div",{className:"custom-models-toggles",children:[e.jsxs("label",{className:"custom-models-toggle",children:[e.jsx("span",{children:s("settings.customModels.field.supportsToolCall")}),e.jsx("button",{type:"button",className:`settings-toggle-switch ${l.supportsToolCall?"on":""}`,onClick:()=>j("supportsToolCall",!l.supportsToolCall)})]}),e.jsxs("label",{className:"custom-models-toggle",children:[e.jsx("span",{children:s("settings.customModels.field.supportsImages")}),e.jsx("button",{type:"button",className:`settings-toggle-switch ${l.supportsImages?"on":""}`,onClick:()=>j("supportsImages",!l.supportsImages)})]}),e.jsxs("label",{className:"custom-models-toggle",children:[e.jsx("span",{children:s("settings.customModels.field.supportsReasoning")}),e.jsx("button",{type:"button",className:`settings-toggle-switch ${l.supportsReasoning?"on":""}`,onClick:()=>j("supportsReasoning",!l.supportsReasoning)})]}),e.jsxs("label",{className:"custom-models-toggle",children:[e.jsx("span",{children:s("settings.customModels.field.useCustomProtocol")}),e.jsx("button",{type:"button",className:`settings-toggle-switch ${l.useCustomProtocol?"on":""}`,onClick:()=>j("useCustomProtocol",!l.useCustomProtocol)})]})]}),e.jsxs("div",{className:"custom-models-form-actions",children:[e.jsx("button",{type:"button",className:"settings-toggle-btn",onClick:F,disabled:b,children:s("settings.customModels.cancel")}),e.jsx("button",{type:"button",className:"custom-models-primary-btn",onClick:()=>{U().catch(()=>{})},disabled:b,children:s(b?"settings.loading":"settings.customModels.save")})]})]})]})}),A&&e.jsx(Pe,{title:s("settings.customModels.deleteTitle"),message:s("settings.customModels.deleteMessage").replace("{id}",A.id),danger:!0,confirmLabel:s("settings.customModels.delete"),cancelLabel:s("settings.customModels.cancel"),onConfirm:()=>{$().catch(()=>{})},onCancel:()=>I(null)})]})}function R(t,s){return Ae(t)||s}function Ae(t,s=0){if(typeof t=="string")return t.trim();if(t instanceof Error)return t.message.trim();if(!t||typeof t!="object"||s>2)return"";const m=t;if("error"in m){const u=Ae(m.error,s+1);if(u)return u}return typeof m.message=="string"?m.message.trim():""}function se(t){const s={...t??{}},m=Be();return m&&(s.Authorization=`Bearer ${m}`),s}function ct(){const{t,tryT:s}=ne(),{agents:m,defaultAgentName:u,sessionBlank:x}=q(),k=q(o=>o.backendSupport),h=Me(o=>o.sessionId),[f,b]=c.useState(""),[M,d]=c.useState(!1),[g,l]=c.useState(null),[C,S]=c.useState(null),[O,A]=c.useState(!1),[I,D]=c.useState(""),[B,T]=c.useState(!1),F=o=>{const r=o==null?void 0:o.agents;r&&(q.getState().applyAgentFromResponse({agents:r,defaultAgentName:o.defaultAgentName}),b(n=>{var p,v;const a=o.defaultAgentName||n;return a&&r.some(y=>y.name===a)?a:((p=r.find(y=>Le(y.name)))==null?void 0:p.name)??((v=r[0])==null?void 0:v.name)??""}))};c.useEffect(()=>{if(k!==!0)return;let o=!1;return G().callExtMethod("_codebuddy.ai/getAgents",{}).then(r=>{o||F(r)}).catch(r=>{o||l(R(r,t("mainAgent.loadFailed")))}),()=>{o=!0}},[k]);const[j,U]=c.useState(!1),[$,i]=c.useState(""),[N,w]=c.useState(!1),[_,K]=c.useState(null),V=async()=>{var r;const o=$.trim();if(!(!o||N)){w(!0),K(null);try{const n=await te("/api/v1/agents/create-by-ai",{method:"POST",headers:se({"Content-Type":"application/json"}),body:JSON.stringify({description:o})}),a=await n.json().catch(()=>({}));if(!n.ok||((r=a==null?void 0:a.data)==null?void 0:r.success)!==!0){K(R(a,`HTTP ${n.status}`));return}U(!1),i(""),l(t("mainAgent.createSuccess"));const p=await G().callExtMethod("_codebuddy.ai/getAgents",{});F(p)}catch(n){K(R(n,t("mainAgent.createFailed")))}finally{w(!1)}}},ae=async o=>{if(!O){if(C!==o){S(o);return}A(!0),l(null);try{const r=await te("/api/v1/agents/delete",{method:"POST",headers:se({"Content-Type":"application/json"}),body:JSON.stringify({name:o})});if(!r.ok){const a=await r.json().catch(()=>({}));l(R(a,`${t("mainAgent.deleteFailed")} (HTTP ${r.status})`));return}l(t("mainAgent.deleted",{name:o}));const n=await G().callExtMethod("_codebuddy.ai/getAgents",{});F(n)}catch(r){l(R(r,t("mainAgent.deleteFailed")))}finally{A(!1),S(null)}}},Q=async o=>{var r;l(null);try{const n=await te("/api/v1/agents/open",{method:"POST",headers:se({"Content-Type":"application/json"}),body:JSON.stringify({name:o})}),a=await n.json().catch(()=>({}));if(!n.ok){l(R(a,t("mainAgent.openFailed")));return}const p=(r=a==null?void 0:a.data)==null?void 0:r.path;if(typeof p=="string"&&p.trim()){T(!1),Te(p.trim());return}l(t("mainAgent.openFailed"))}catch(n){l(R(n,t("mainAgent.openFailed")))}},le=async o=>{d(!0),l(null);try{const r=await te("/api/v1/settings/codebuddy?scope=user",{method:"PUT",headers:se({"Content-Type":"application/json"}),body:JSON.stringify({value:{mainAgent:{default:o}}})});r.ok||r.status===204?(b(o),q.getState().applyAgentFromResponse({defaultAgentName:o}),l(t("mainAgent.defaultSaved"))):l(`HTTP ${r.status}`)}catch(r){l(R(r,t("settings.saveFailed")))}finally{d(!1)}},ie=async()=>{if(l(null),!h){l(t("mainAgent.openInCreateFailed"));return}if(!x){l(t("mainAgent.openInCreateFailed"));return}d(!0),De();try{const o=await G().callExtMethod("session/set_agent",{sessionId:h,agentName:"create"});o!=null&&o.agentName?(q.getState().applySetAgentResult({agentName:o.agentName,models:o.models??[],currentModelId:o.currentModelId??"",sessionBlank:o.sessionBlank??!1}),l(t("mainAgent.openInCreateSuccess"))):pe()}catch(o){pe(),l(R(o,t("mainAgent.openInCreateFailed")))}finally{d(!1)}},H=I.trim().toLowerCase(),J=o=>H?[o.name,o.displayName,ce(o,s),me(o,s)].filter(Boolean).join(" ").toLowerCase().includes(H):!0,Z=Re(m),X=[{label:t("mainAgent.groupBuiltin"),items:Z.builtin},{label:t("mainAgent.groupCustom"),items:Z.custom}].map(o=>({...o,items:o.items.filter(J)})).filter(o=>o.items.length>0),Y=ze(f,u),ee=m.find(o=>o.name===Y),oe=ee?ce(ee,s):f||u||"-",re=e.jsxs(e.Fragment,{children:[m.length>4&&e.jsx("div",{className:"px-3 pb-1",children:e.jsx("input",{type:"search",value:I,onChange:o=>D(o.target.value),placeholder:t("mainAgent.searchPlaceholder"),className:"w-full rounded-md border border-border-default bg-bg-secondary px-2 py-1.5 text-[12px] text-text-primary outline-none focus:border-accent-brand"})}),g&&e.jsx("div",{className:"settings-value text-[12px] text-text-tertiary",children:g}),X.length===0&&e.jsx("div",{className:"settings-value",children:m.length===0?t("mainAgent.empty"):t("mainAgent.filterEmpty")}),X.map(o=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 pt-2 pb-1 text-[11px] uppercase tracking-wide text-text-tertiary",children:o.label}),o.items.map(r=>{const n=$e(r.name,Y),a=r.custom?r.source==="user"?t("mainAgent.scope.user"):t("mainAgent.scope.project"):null,p=r.custom&&(r.source==="user"||r.source==="project"),v=me(r,s);return e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("span",{className:"text-[13px] text-text-primary truncate block",children:[ce(r,s),a&&e.jsx("span",{className:"ml-1.5 rounded border border-border-default px-1 py-px text-[10px] text-text-tertiary align-middle",children:a})]}),v&&e.jsx("span",{className:"text-[11px] text-text-tertiary truncate block",children:v}),r.broken&&e.jsx("span",{className:"text-[11px] text-red-500 truncate block",children:r.broken})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[n?e.jsx("span",{className:"text-[11px] text-text-tertiary",children:t("mainAgent.isDefault")}):e.jsx("button",{type:"button",disabled:M||!!r.broken,onClick:()=>le(r.name),className:"text-[12px] text-accent-brand hover:underline disabled:opacity-40",children:t("mainAgent.setDefault")}),r.name==="create"&&!r.broken&&e.jsxs("button",{type:"button",disabled:M||!x,onClick:()=>{ie().catch(()=>{})},className:"flex items-center gap-1 text-[12px] text-accent-brand hover:underline disabled:opacity-40",title:t("mainAgent.openInCreate"),children:[e.jsx(ge,{size:12}),t("mainAgent.openInCreate")]}),p&&e.jsxs("button",{type:"button",onClick:()=>{Q(r.name).catch(()=>{})},className:"flex items-center gap-1 text-[12px] text-text-tertiary hover:text-text-primary",title:t("mainAgent.openFile"),children:[e.jsx(_e,{size:12}),t("mainAgent.openFile")]}),p&&e.jsxs("button",{type:"button",disabled:O,onClick:()=>{ae(r.name).catch(()=>{})},onBlur:()=>{C===r.name&&S(null)},className:`flex items-center gap-1 text-[12px] disabled:opacity-40 ${C===r.name?"text-red-500 font-medium hover:underline":"text-text-tertiary hover:text-red-500"}`,title:t("mainAgent.delete"),children:[e.jsx(we,{size:12}),C===r.name?t("mainAgent.deleteConfirm"):t("mainAgent.delete")]})]})]},r.name)})]},o.label)),e.jsxs("button",{type:"button",onClick:()=>{U(!0),K(null)},className:"mx-2 my-2 flex w-[calc(100%-16px)] items-center justify-center gap-1.5 rounded-lg border border-dashed border-border-default py-2 text-[12px] text-text-tertiary transition-colors hover:border-accent-brand hover:text-text-primary",children:[e.jsx(ge,{size:13}),t("mainAgent.createByAI")]}),j&&e.jsxs("div",{className:"mx-2 mb-2 rounded-lg border border-border-default bg-bg-primary p-3",children:[e.jsx("div",{className:"text-[12px] text-text-primary mb-1.5",children:t("mainAgent.createByAIHint")}),e.jsx("textarea",{value:$,onChange:o=>i(o.target.value),rows:3,placeholder:t("mainAgent.createByAIPlaceholder"),className:"w-full resize-none rounded-md border border-border-default bg-bg-secondary px-2 py-1.5 text-[12px] text-text-primary outline-none focus:border-accent-brand",disabled:N}),_&&e.jsx("div",{className:"mt-1.5 text-[11px] text-red-500",children:_}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{U(!1),i(""),K(null)},disabled:N,className:"text-[12px] text-text-tertiary hover:text-text-primary disabled:opacity-40",children:t("app.cancel")}),e.jsx("button",{type:"button",onClick:V,disabled:N||!$.trim(),className:"flex items-center gap-1 rounded-md bg-accent-brand px-2.5 py-1 text-[12px] text-white hover:opacity-90 disabled:opacity-40",children:N?e.jsxs(e.Fragment,{children:[t("mainAgent.creating"),"…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Se,{size:12}),t("mainAgent.createByAI")]})})]})]})]});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"settings-row",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[e.jsx("span",{className:"settings-label",children:t("mainAgent.currentDefault")}),e.jsx("span",{className:"settings-desc",children:t("mainAgent.currentDefaultHint")})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 ml-3",children:[e.jsx("span",{className:"settings-value",children:e.jsx("strong",{children:oe})}),e.jsx("button",{type:"button",onClick:()=>{T(!0),l(null)},className:"rounded-md border border-border-default px-2.5 py-1 text-[12px] text-text-primary transition-colors hover:border-accent-brand hover:text-accent-brand",children:t("mainAgent.manage")})]})]}),B&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:()=>T(!1),children:e.jsxs("div",{className:"flex max-h-[80vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-border-default bg-bg-primary shadow-xl",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border-default px-4 py-3",children:[e.jsx("h3",{className:"text-[14px] font-medium text-text-primary",children:t("mainAgent.sectionTitle")}),e.jsx("button",{type:"button",onClick:()=>T(!1),className:"text-text-tertiary hover:text-text-primary","aria-label":t("app.cancel"),children:"✕"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-3",children:re})]})})]})}const dt=[{value:"minimal",labelKey:"settings.effort.minimal"},{value:"low",labelKey:"settings.effort.low"},{value:"medium",labelKey:"settings.effort.medium"},{value:"high",labelKey:"settings.effort.high"},{value:"xhigh",labelKey:"settings.effort.xhigh"},{value:"max",labelKey:"settings.effort.max"}],Ne=[{titleKey:"settings.group.modelAndReasoning",items:[{key:"model",labelKey:"settings.item.model",descKey:"settings.item.model.desc",type:"text"},{key:"reasoningEffort",labelKey:"settings.item.reasoningEffort",descKey:"settings.item.reasoningEffort.desc",type:"select",options:dt},{key:"alwaysThinkingEnabled",labelKey:"settings.item.alwaysThinkingEnabled",type:"toggle"}]},{titleKey:"settings.group.behavior",items:[{key:"autoCompactEnabled",labelKey:"settings.item.autoCompactEnabled",type:"toggle"},{key:"autoCompactWindow",labelKey:"settings.item.autoCompactWindow",descKey:"settings.item.autoCompactWindow.desc",type:"number"},{key:"includeCoAuthoredBy",labelKey:"settings.item.includeCoAuthoredBy",type:"toggle"},{key:"fileCheckpointingEnabled",labelKey:"settings.item.fileCheckpointingEnabled",descKey:"settings.item.fileCheckpointingEnabled.desc",type:"toggle"},{key:"promptSuggestionEnabled",labelKey:"settings.item.promptSuggestionEnabled",type:"toggle"},{key:"codebuddy.composer.busySendMode",labelKey:"settings.item.busySendMode",descKey:"settings.item.busySendMode.desc",type:"select",defaultValue:"queue",hideEmptyOption:!0,options:[{value:"queue",labelKey:"settings.item.busySendMode.queue"},{value:"immediate",labelKey:"settings.item.busySendMode.immediate"}]},{key:"ignoreGitIgnore",labelKey:"settings.item.ignoreGitIgnore",descKey:"settings.item.ignoreGitIgnore.desc",type:"toggle"},{key:"deferToolLoading",labelKey:"settings.item.deferToolLoading",type:"toggle"},{key:"hookOutputCollapsed",labelKey:"settings.item.hookOutputCollapsed",type:"toggle"}]},{titleKey:"settings.group.memory",items:[{key:"memory.enabled",labelKey:"settings.item.memory.enabled",type:"toggle"},{key:"memory.autoMemoryEnabled",labelKey:"settings.item.memory.autoMemoryEnabled",descKey:"settings.item.memory.autoMemoryEnabled.desc",type:"toggle"}]},{titleKey:"settings.group.language",items:[{key:"language",labelKey:"settings.item.language",descKey:"settings.item.language.desc",type:"text"}]},{titleKey:"settings.group.mainAgent",items:[{key:"codebuddy.mainAgent.enabled",labelKey:"settings.item.mainAgent.enabled",descKey:"settings.item.mainAgent.enabled.desc",type:"toggle",defaultValue:!0},{key:"codebuddy.mainAgent.allowUnopted",labelKey:"settings.item.mainAgent.allowUnopted",descKey:"settings.item.mainAgent.allowUnopted.desc",type:"toggle",defaultValue:!1}]},{titleKey:"settings.group.advanced",items:[{key:"cleanupPeriodDays",labelKey:"settings.item.cleanupPeriodDays",type:"number"},{key:"imageHistoryRetainRounds",labelKey:"settings.item.imageHistoryRetainRounds",descKey:"settings.item.imageHistoryRetainRounds.desc",type:"number"},{key:"env",labelKey:"settings.item.env",descKey:"settings.item.env.desc",type:"json"}]},{titleKey:"settings.group.sandbox",items:[{key:"sandbox.enabled",labelKey:"settings.item.sandbox.enabled",descKey:"settings.item.sandbox.enabled.desc",type:"toggle"},{key:"sandbox.autoAllowBashIfSandboxed",labelKey:"settings.item.sandbox.autoAllowBashIfSandboxed",descKey:"settings.item.sandbox.autoAllowBashIfSandboxed.desc",type:"toggle"}]}];function ve(t,s){const m=s.split(".");let u=t;for(const x of m){if(u==null||typeof u!="object")return;u=u[x]}return u}const E={connection:"settings-section-connection",appearance:"settings-section-appearance",model:"settings-section-model",mode:"settings-section-mode",system:"settings-section-system"};function ke(t){return`settings-section-${t.replace(/\./g,"-")}`}function ht(){const{status:t,sessionId:s,currentModel:m,models:u,modes:x,currentMode:k}=Me(),{info:h,fetch:f}=Ue(),{mode:b,toggle:M}=Ve(),{t:d,tryT:g,locale:l,toggleLocale:C}=ne(),S=q(n=>n.backendSupport),O=He(S),[A,I]=c.useState(null),[D,B]=c.useState({}),T=c.useRef({}),[F,j]=c.useState(!1),[U,$]=c.useState({}),i=c.useRef({}),N=c.useRef(null),[w,_]=c.useState(E.connection),[K,V]=c.useState(!1),ae=ve(D,"codebuddy.mainAgent.enabled")!==!1;c.useEffect(()=>{let n=!1;return j(!0),Promise.all([fetch("/api/v1/settings",{headers:de()}).then(a=>{if(!a.ok)throw new Error(`Settings API: ${a.status}`);return a.json()}).then(a=>(a==null?void 0:a.data)??a??{}),fetch("/api/v1/settings?scope=user",{headers:de()}).then(a=>{if(!a.ok)throw new Error(`User settings API: ${a.status}`);return a.json()}).then(a=>(a==null?void 0:a.data)??a??{})]).then(([a,p])=>{n||(B(a),T.current=p,he.getState().hydrateFromSettings(a),j(!1))}).catch(a=>{console.error("Failed to load settings:",a),n||j(!1)}),()=>{n=!0}},[]),c.useEffect(()=>()=>{Object.values(i.current).forEach(clearTimeout)},[]),c.useEffect(()=>{h||f()},[h,f]);const Q=c.useCallback(async(n,a)=>{await qe(n)&&(I(a),setTimeout(()=>I(null),1500))},[]),le=async n=>{if(H("model",n),Ze(n),s)try{await G().setModel(s,n)}catch(a){console.error("Model change failed:",a)}},ie=async n=>{if(H("permissions.defaultMode",n),Xe(n),s)try{await G().setMode(s,n)}catch(a){console.error("Mode change failed:",a)}},H=c.useCallback(async(n,a)=>{const p=n.split(".")[0];let v=a;if(n.includes(".")){const y=n.split("."),W={...T.current[p]??{}};let P=W;for(let z=1;z<y.length-1;z++)P[y[z]]=P[y[z]]?{...P[y[z]]}:{},P=P[y[z]];P[y[y.length-1]]=a,v=W}try{const y=await fetch(`/api/v1/settings/${p}?scope=user`,{method:"PUT",headers:de({"Content-Type":"application/json"}),body:JSON.stringify({value:v})});y.ok||y.status===204?(n.includes(".")?(T.current={...T.current,[p]:v},B(L=>({...L,[p]:{...L[p]??{},...v}}))):(T.current={...T.current,[n]:a},B(L=>({...L,[n]:a}))),n==="codebuddy.composer.busySendMode"&&(a==="queue"||a==="immediate")&&he.getState().setMode(a,!1),J(n,"success")):(console.error(`Failed to save setting "${n}": HTTP ${y.status}`),J(n,"error"))}catch(y){console.error(`Failed to save setting "${n}":`,y),J(n,"error")}},[]),J=c.useCallback((n,a)=>{$(p=>({...p,[n]:a})),i.current[n]&&clearTimeout(i.current[n]),i.current[n]=setTimeout(()=>{$(p=>{const v={...p};return delete v[n],v})},1500)},[]),Z={disconnected:"bg-gray-400",connecting:"bg-accent-yellow animate-pulse",connected:"bg-accent-green",error:"bg-accent-red"}[t],X={connected:"connection.connected",connecting:"connection.connecting",disconnected:"connection.disconnected",error:"connection.error"},Y=b==="light"?Ge:b==="dark"?Je:st,ee=d(b==="light"?"theme.light":b==="dark"?"theme.dark":"theme.system"),oe=l==="system"?et:We,re=d(l==="zh"?"locale.zh":l==="en"?"locale.en":"locale.system"),o=c.useMemo(()=>{const n=[{id:E.connection,label:d("sidebar.connectionStatus")},{id:E.appearance,label:d("settings.appearance")}];if(n.push({id:E.model,label:d("settings.model")}),x.length>0&&n.push({id:E.mode,label:d("settings.mode")}),!F)for(const a of Ne)n.push({id:ke(a.titleKey),label:d(a.titleKey)});return h&&n.push({id:E.system,label:d("settings.systemInfo")}),n},[d,u.length,x.length,F,h]),r=c.useCallback(n=>{const a=N.current,p=(a==null?void 0:a.querySelector(`#${CSS.escape(n)}`))??document.getElementById(n);p&&(_(n),p.scrollIntoView({behavior:"smooth",block:"start"}))},[]);return c.useEffect(()=>{const n=N.current;if(!n||o.length===0)return;const a=new IntersectionObserver(p=>{var L,W;const y=(W=(L=p.filter(P=>P.isIntersecting).sort((P,z)=>P.boundingClientRect.top-z.boundingClientRect.top)[0])==null?void 0:L.target)==null?void 0:W.id;y&&_(y)},{root:n,rootMargin:"-12% 0px -70% 0px",threshold:[0,.1,.25,.5,1]});for(const p of o){const v=n.querySelector(`#${CSS.escape(p.id)}`);v&&a.observe(v)}return()=>a.disconnect()},[o]),e.jsxs("div",{className:"settings-view",children:[e.jsxs("div",{className:"settings-content",ref:N,children:[e.jsx("nav",{className:"settings-toc","aria-label":"Settings sections",children:e.jsx("div",{className:"settings-toc-inner",children:o.map(n=>e.jsx("button",{type:"button",className:`settings-toc-item${w===n.id?" active":""}`,onClick:()=>r(n.id),children:n.label},n.id))})}),e.jsxs("div",{className:"settings-sections",children:[e.jsxs("div",{id:E.connection,className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d("sidebar.connectionStatus")}),e.jsxs("div",{className:"settings-card",children:[e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.status")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${Z}`}),e.jsx("span",{className:"settings-value",children:d(X[t]||"connection.disconnected")})]})]}),e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.sessionId")}),e.jsx("span",{className:"settings-value font-mono text-[12px]",children:s?s.substring(0,12):d("sidebar.notConnected")})]})]})]}),e.jsxs("div",{id:E.appearance,className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d("settings.appearance")}),e.jsxs("div",{className:"settings-card",children:[e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.theme")}),e.jsxs("button",{onClick:M,className:"settings-toggle-btn",children:[e.jsx(Y,{size:14,className:"text-accent-brand"}),e.jsx("span",{children:ee})]})]}),e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.language")}),e.jsxs("button",{onClick:C,className:"settings-toggle-btn",children:[e.jsx(oe,{size:14,className:"text-accent-brand"}),e.jsx("span",{children:re})]})]})]})]}),e.jsxs("div",{id:E.model,className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d("settings.model")}),e.jsxs("div",{className:"settings-card",children:[u.length>0?e.jsx("div",{className:"settings-row settings-row-stack",children:e.jsx("select",{value:m,onChange:n=>le(n.target.value),className:"settings-select",children:u.map(n=>e.jsx("option",{value:n.id,children:n.name||n.id},n.id))})}):e.jsx("div",{className:"settings-row",children:e.jsx("span",{className:"settings-value",children:d("sidebar.noModels")})}),e.jsxs("div",{className:"settings-row",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[e.jsx("span",{className:"settings-label",children:d("settings.customModels.entryLabel")}),e.jsx("span",{className:"settings-desc",children:d("settings.customModels.entryDesc")})]}),e.jsxs("button",{type:"button",className:"settings-toggle-btn",onClick:()=>V(!0),children:[e.jsx(Qe,{size:14,className:"text-accent-brand"}),e.jsx("span",{children:d("settings.customModels.manage")})]})]})]})]}),x.length>0&&e.jsxs("div",{id:E.mode,className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d("settings.mode")}),e.jsx("div",{className:"settings-card",children:e.jsx("select",{value:k,onChange:n=>ie(n.target.value),className:"settings-select",children:x.map(n=>e.jsx("option",{value:n.id,title:g(`mode.${n.id}.desc`)||n.description,children:g(`mode.${n.id}`)||n.name},n.id))})})]}),F?e.jsx("div",{className:"settings-group",children:e.jsx("span",{className:"settings-value",children:d("settings.loading")})}):Ne.map(n=>e.jsxs("div",{id:ke(n.titleKey),className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d(n.titleKey)}),e.jsxs("div",{className:"settings-card",children:[n.items.map(a=>e.jsx(ut,{item:a,value:ve(D,a.key),feedback:U[a.key],onSave:H},a.key)),n.titleKey==="settings.group.mainAgent"&&ae&&O.enabled&&!0&&e.jsx(ct,{})]})]},n.titleKey)),h&&e.jsxs("div",{id:E.system,className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d("settings.systemInfo")}),e.jsxs("div",{className:"settings-card",children:[e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.cwd")}),e.jsxs("button",{onClick:()=>Q(h.cwd,"cwd"),className:"settings-copy-btn",title:h.cwd,children:[e.jsx("span",{className:"truncate cursor-pointer hover:underline hover:text-accent-brand",onClick:n=>{n.stopPropagation(),Te(h.cwd)},children:h.cwd}),A==="cwd"?e.jsx(xe,{size:12,className:"shrink-0 text-accent-green"}):e.jsx(be,{size:12,className:"shrink-0 text-text-tertiary"})]})]}),e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.os")}),e.jsxs("span",{className:"settings-value",children:[h.os," ",h.arch]})]}),e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.nodeVersion")}),e.jsx("span",{className:"settings-value",children:h.nodeVersion})]}),e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.gatewayMode")}),e.jsx("span",{className:"settings-value capitalize",children:h.gatewayMode})]}),h.tunnelUrl&&e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.tunnelUrl")}),e.jsxs("button",{onClick:()=>Q(h.tunnelUrl,"tunnel"),className:"settings-copy-btn",title:h.tunnelUrl,children:[e.jsx("span",{className:"truncate",children:h.tunnelUrl.replace(/^https?:\/\//,"")}),A==="tunnel"?e.jsx(xe,{size:12,className:"shrink-0 text-accent-green"}):e.jsx(be,{size:12,className:"shrink-0 text-text-tertiary"})]})]})]})]})]})]}),K&&e.jsx(rt,{onClose:()=>V(!1)})]})}function ut({item:t,value:s,feedback:m,onSave:u}){const{t:x}=ne(),[k,h]=c.useState(""),f=c.useRef(null);c.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]),c.useEffect(()=>{t.type==="text"||t.type==="number"?h(s!=null?String(s):""):t.type==="json"&&h(s!=null?JSON.stringify(s,null,2):"")},[s,t.type]);const b=t.type==="toggle"&&s===void 0&&t.defaultValue!==void 0?t.defaultValue:s,M=c.useCallback(()=>{u(t.key,!b)},[t.key,b,u]),d=c.useCallback(l=>{u(t.key,l||void 0)},[t.key,u]),g=c.useCallback(l=>{h(l),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{if(t.type==="number"){const C=Number(l);!isNaN(C)&&l.trim()!==""&&u(t.key,C)}else if(t.type==="json")try{const C=JSON.parse(l);u(t.key,C)}catch{}else u(t.key,l)},600)},[t.key,t.type,u]);return e.jsxs("div",{className:"settings-row",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"settings-label",children:x(t.labelKey)}),m&&e.jsx("span",{className:`settings-save-feedback ${m==="success"?"success":"error"}`,children:x(m==="success"?"settings.saved":"settings.saveFailed")})]}),t.descKey&&e.jsx("span",{className:"settings-desc",children:x(t.descKey)})]}),e.jsxs("div",{className:"flex items-center shrink-0 ml-3",children:[t.type==="toggle"&&e.jsx("button",{className:`settings-toggle-switch ${b?"on":""}`,onClick:M}),t.type==="select"&&t.options&&e.jsxs("select",{value:s??(typeof t.defaultValue=="string"?t.defaultValue:""),onChange:l=>d(l.target.value),className:"settings-inline-select",children:[!t.hideEmptyOption&&e.jsx("option",{value:"",children:"-"}),t.options.map(l=>e.jsx("option",{value:l.value,children:x(l.labelKey)},l.value))]}),t.type==="text"&&e.jsx("input",{type:"text",value:k,onChange:l=>g(l.target.value),placeholder:x("settings.notSet"),className:"settings-input"}),t.type==="number"&&e.jsx("input",{type:"number",value:k,onChange:l=>g(l.target.value),className:"settings-input",style:{width:80}}),t.type==="json"&&e.jsx("textarea",{value:k,onChange:l=>g(l.target.value),placeholder:"{}",className:"settings-input wide",rows:3,style:{width:"100%",resize:"vertical"}})]})]})}export{ht as SettingsView};
11
+ */const tt=[["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M14.837 16.385a6 6 0 1 1-7.223-7.222c.624-.147.97.66.715 1.248a4 4 0 0 0 5.26 5.259c.589-.255 1.396.09 1.248.715",key:"xlf6rm"}],["path",{d:"M16 12a4 4 0 0 0-4-4",key:"6vsxu"}],["path",{d:"m19 5-1.256 1.256",key:"1yg6a6"}],["path",{d:"M20 12h2",key:"1q8mjw"}]],st=Ce("sun-moon",tt),nt=["128000","256000","1000000"],at=["16384","32768","65536","128000"],ye={id:"",name:"",vendor:"Custom",url:"",apiKey:"",maxInputTokens:"128000",maxOutputTokens:"16384",temperature:"",supportsToolCall:!0,supportsImages:!1,supportsReasoning:!1,useCustomProtocol:!1};function fe(t){const s=Number(t);return Number.isFinite(s)?s>=1e6&&s%1e6===0?`${s/1e6}M`:s>=1e3&&s%1e3===0?`${s/1e3}k`:s>=1024&&s%1024===0?`${s/1024}k`:String(s):t}function je(t){const{label:s,value:m,presets:u,disabled:x,step:k,formatLabel:h,onChange:f}=t,b=u.includes(m),M=b?m:"__custom__",d=h||(g=>g);return e.jsxs("label",{className:"custom-models-field",children:[e.jsx("span",{children:s}),e.jsxs("select",{className:"custom-models-select",value:M,disabled:x,onChange:g=>{const l=g.target.value;if(l==="__custom__"){f(m&&!Number.isNaN(Number(m))?m:u[0]);return}f(l)},children:[u.map(g=>e.jsx("option",{value:g,children:d(g)},g)),e.jsx("option",{value:"__custom__",children:"Custom…"})]}),!b&&e.jsx("input",{className:"settings-input",type:"number",step:k,value:m,disabled:x,onChange:g=>f(g.target.value),placeholder:u[0]})]})}function lt(t){return{id:t.id||"",name:t.name||"",vendor:t.vendor||"Custom",url:t.url||"",apiKey:t.apiKey||"",maxInputTokens:t.maxInputTokens!=null?String(t.maxInputTokens):"",maxOutputTokens:t.maxOutputTokens!=null?String(t.maxOutputTokens):"",temperature:t.temperature!=null?String(t.temperature):"",supportsToolCall:t.supportsToolCall!==!1,supportsImages:!!t.supportsImages,supportsReasoning:!!t.supportsReasoning,useCustomProtocol:!!t.useCustomProtocol}}function ue(t){const s=t.trim();return s!==""&&!Number.isNaN(Number(s))?Number(s):void 0}function it(t){const s={id:t.id.trim(),name:t.name.trim()||t.id.trim(),vendor:t.vendor.trim()||"Custom",url:t.url.trim(),supportsToolCall:t.supportsToolCall,supportsImages:t.supportsImages,supportsReasoning:t.supportsReasoning,useCustomProtocol:t.useCustomProtocol};t.apiKey.trim()&&(s.apiKey=t.apiKey.trim());const m=ue(t.maxInputTokens);m!==void 0&&(s.maxInputTokens=m);const u=ue(t.maxOutputTokens);u!==void 0&&(s.maxOutputTokens=u);const x=ue(t.temperature);return x!==void 0&&(s.temperature=x),s}const ot=/^[a-zA-Z0-9._:-]+$/;function rt({onClose:t}){const{t:s}=ne(),[m,u]=c.useState("list"),[x,k]=c.useState([]),[h,f]=c.useState(!0),[b,M]=c.useState(!1),[d,g]=c.useState(null),[l,C]=c.useState(ye),[w,O]=c.useState(),[A,I]=c.useState(null),z=c.useCallback(async()=>{f(!0),g(null);try{const i=await Ke(!0),N=Array.isArray(i==null?void 0:i.models)?i.models:[];k(N)}catch(i){g((i==null?void 0:i.message)||s("settings.customModels.loadFailed")),k([])}finally{f(!1)}},[]);c.useEffect(()=>{z().catch(()=>{})},[z]),c.useEffect(()=>{const i=N=>{if(N.key==="Escape"){if(A){I(null);return}if(m==="form"){u("list"),g(null);return}t()}};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[A,m,t]);const B=()=>{C(ye),O(void 0),g(null),u("form")},T=i=>{C(lt(i)),O(i.id),g(null),u("form")},F=()=>{u("list"),g(null),O(void 0)},j=(i,N)=>{C(S=>({...S,[i]:N}))},U=async()=>{const i=l.id.trim(),N=l.url.trim();if(!i){g(s("settings.customModels.err.idRequired"));return}if(!ot.test(i)){g(s("settings.customModels.err.idInvalid"));return}if(!N){g(s("settings.customModels.err.urlRequired"));return}if(!/^https?:\/\//i.test(N)){g(s("settings.customModels.err.urlInvalid"));return}if((!w||w!==i)&&x.some(S=>S.id===i)){g(s("settings.customModels.err.idDuplicate"));return}M(!0),g(null);try{const S=it(l);if(w&&!l.apiKey.trim()){const K=x.find(V=>V.id===w);K!=null&&K.apiKey&&(S.apiKey=K.apiKey)}const _=await Oe({model:S,previousId:w&&w!==i?w:void 0,visible:!1,global:!0});k(Array.isArray(_.models)?_.models:[]),u("list"),O(void 0)}catch(S){g((S==null?void 0:S.message)||s("settings.customModels.saveFailed"))}finally{M(!1)}},$=async()=>{if(A){M(!0),g(null);try{const i=await Fe(A.id,!0);k(Array.isArray(i.models)?i.models:[]),I(null)}catch(i){g((i==null?void 0:i.message)||s("settings.customModels.deleteFailed")),I(null)}finally{M(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"custom-models-overlay",onClick:t,children:e.jsxs("div",{className:"custom-models-modal",role:"dialog","aria-modal":"true","aria-labelledby":"custom-models-title",onClick:i=>i.stopPropagation(),children:[e.jsxs("div",{className:"custom-models-header",children:[e.jsx("h2",{id:"custom-models-title",className:"custom-models-title",children:s(m==="list"?"settings.customModels.title":w?"settings.customModels.editTitle":"settings.customModels.addTitle")}),e.jsx("button",{type:"button",className:"custom-models-icon-btn",onClick:t,"aria-label":s("settings.customModels.close"),children:e.jsx(Ie,{size:16})})]}),d&&e.jsx("div",{className:"custom-models-error",children:d}),m==="list"?e.jsxs("div",{className:"custom-models-body",children:[e.jsxs("div",{className:"custom-models-toolbar",children:[e.jsx("span",{className:"custom-models-hint",children:s("settings.customModels.hint")}),e.jsxs("button",{type:"button",className:"settings-toggle-btn",onClick:B,children:[e.jsx(we,{size:14}),e.jsx("span",{children:s("settings.customModels.add")})]})]}),h?e.jsx("div",{className:"custom-models-empty",children:s("settings.loading")}):x.length===0?e.jsx("div",{className:"custom-models-empty",children:s("settings.customModels.empty")}):e.jsx("ul",{className:"custom-models-list",children:x.map(i=>e.jsxs("li",{className:"custom-models-row",children:[e.jsxs("div",{className:"custom-models-row-main",children:[e.jsx("div",{className:"custom-models-row-name",children:i.name||i.id}),e.jsxs("div",{className:"custom-models-row-meta",children:[e.jsx("span",{className:"font-mono",children:i.id}),i.vendor?e.jsxs("span",{children:["· ",i.vendor]}):null]}),i.url?e.jsx("div",{className:"custom-models-row-url",title:i.url,children:i.url}):null]}),e.jsxs("div",{className:"custom-models-row-actions",children:[e.jsx("button",{type:"button",className:"custom-models-icon-btn",onClick:()=>T(i),title:s("settings.customModels.edit"),children:e.jsx(Ee,{size:14})}),e.jsx("button",{type:"button",className:"custom-models-icon-btn danger",onClick:()=>I(i),title:s("settings.customModels.delete"),children:e.jsx(Se,{size:14})})]})]},i.id))})]}):e.jsxs("div",{className:"custom-models-body custom-models-form",children:[e.jsxs("label",{className:"custom-models-field",children:[e.jsxs("span",{children:[s("settings.customModels.field.id")," *"]}),e.jsx("input",{className:"settings-input",value:l.id,onChange:i=>j("id",i.target.value),placeholder:"my-openai-model",disabled:b})]}),e.jsxs("label",{className:"custom-models-field",children:[e.jsx("span",{children:s("settings.customModels.field.name")}),e.jsx("input",{className:"settings-input",value:l.name,onChange:i=>j("name",i.target.value),disabled:b})]}),e.jsxs("label",{className:"custom-models-field",children:[e.jsx("span",{children:s("settings.customModels.field.vendor")}),e.jsx("input",{className:"settings-input",value:l.vendor,onChange:i=>j("vendor",i.target.value),placeholder:"OpenAI / Anthropic / Custom",disabled:b})]}),e.jsxs("label",{className:"custom-models-field",children:[e.jsxs("span",{children:[s("settings.customModels.field.url")," *"]}),e.jsx("input",{className:"settings-input",value:l.url,onChange:i=>j("url",i.target.value),placeholder:"https://api.example.com/v1/chat/completions",disabled:b})]}),e.jsxs("label",{className:"custom-models-field",children:[e.jsx("span",{children:s("settings.customModels.field.apiKey")}),e.jsx("input",{className:"settings-input",type:"password",autoComplete:"off",value:l.apiKey,onChange:i=>j("apiKey",i.target.value),placeholder:w?s("settings.customModels.apiKeyKeep"):"",disabled:b})]}),e.jsxs("div",{className:"custom-models-field-row",children:[e.jsx(je,{label:s("settings.customModels.field.maxInputTokens"),value:l.maxInputTokens,presets:nt,formatLabel:fe,disabled:b,onChange:i=>j("maxInputTokens",i)}),e.jsx(je,{label:s("settings.customModels.field.maxOutputTokens"),value:l.maxOutputTokens,presets:at,formatLabel:fe,disabled:b,onChange:i=>j("maxOutputTokens",i)}),e.jsxs("label",{className:"custom-models-field",children:[e.jsx("span",{children:s("settings.customModels.field.temperature")}),e.jsx("input",{className:"settings-input",type:"number",step:"0.1",min:"0",max:"2",value:l.temperature,disabled:b,onChange:i=>j("temperature",i.target.value),placeholder:s("settings.customModels.field.temperatureDefault")})]})]}),e.jsxs("div",{className:"custom-models-toggles",children:[e.jsxs("label",{className:"custom-models-toggle",children:[e.jsx("span",{children:s("settings.customModels.field.supportsToolCall")}),e.jsx("button",{type:"button",className:`settings-toggle-switch ${l.supportsToolCall?"on":""}`,onClick:()=>j("supportsToolCall",!l.supportsToolCall)})]}),e.jsxs("label",{className:"custom-models-toggle",children:[e.jsx("span",{children:s("settings.customModels.field.supportsImages")}),e.jsx("button",{type:"button",className:`settings-toggle-switch ${l.supportsImages?"on":""}`,onClick:()=>j("supportsImages",!l.supportsImages)})]}),e.jsxs("label",{className:"custom-models-toggle",children:[e.jsx("span",{children:s("settings.customModels.field.supportsReasoning")}),e.jsx("button",{type:"button",className:`settings-toggle-switch ${l.supportsReasoning?"on":""}`,onClick:()=>j("supportsReasoning",!l.supportsReasoning)})]}),e.jsxs("label",{className:"custom-models-toggle",children:[e.jsx("span",{children:s("settings.customModels.field.useCustomProtocol")}),e.jsx("button",{type:"button",className:`settings-toggle-switch ${l.useCustomProtocol?"on":""}`,onClick:()=>j("useCustomProtocol",!l.useCustomProtocol)})]})]}),e.jsxs("div",{className:"custom-models-form-actions",children:[e.jsx("button",{type:"button",className:"settings-toggle-btn",onClick:F,disabled:b,children:s("settings.customModels.cancel")}),e.jsx("button",{type:"button",className:"custom-models-primary-btn",onClick:()=>{U().catch(()=>{})},disabled:b,children:s(b?"settings.loading":"settings.customModels.save")})]})]})]})}),A&&e.jsx(Pe,{title:s("settings.customModels.deleteTitle"),message:s("settings.customModels.deleteMessage").replace("{id}",A.id),danger:!0,confirmLabel:s("settings.customModels.delete"),cancelLabel:s("settings.customModels.cancel"),onConfirm:()=>{$().catch(()=>{})},onCancel:()=>I(null)})]})}function R(t,s){return Ae(t)||s}function Ae(t,s=0){if(typeof t=="string")return t.trim();if(t instanceof Error)return t.message.trim();if(!t||typeof t!="object"||s>2)return"";const m=t;if("error"in m){const u=Ae(m.error,s+1);if(u)return u}return typeof m.message=="string"?m.message.trim():""}function se(t){const s={...t??{}},m=Be();return m&&(s.Authorization=`Bearer ${m}`),s}function ct(){const{t,tryT:s}=ne(),{agents:m,defaultAgentName:u,sessionBlank:x}=q(),k=q(o=>o.backendSupport),h=Me(o=>o.sessionId),[f,b]=c.useState(""),[M,d]=c.useState(!1),[g,l]=c.useState(null),[C,w]=c.useState(null),[O,A]=c.useState(!1),[I,z]=c.useState(""),[B,T]=c.useState(!1),F=o=>{const r=o==null?void 0:o.agents;r&&(q.getState().applyAgentFromResponse({agents:r,defaultAgentName:o.defaultAgentName}),b(n=>{var p,v;const a=o.defaultAgentName||n;return a&&r.some(y=>y.name===a)?a:((p=r.find(y=>Le(y.name)))==null?void 0:p.name)??((v=r[0])==null?void 0:v.name)??""}))};c.useEffect(()=>{if(k!==!0)return;let o=!1;return G().callExtMethod("_codebuddy.ai/getAgents",{}).then(r=>{o||F(r)}).catch(r=>{o||l(R(r,t("mainAgent.loadFailed")))}),()=>{o=!0}},[k]);const[j,U]=c.useState(!1),[$,i]=c.useState(""),[N,S]=c.useState(!1),[_,K]=c.useState(null),V=async()=>{var r;const o=$.trim();if(!(!o||N)){S(!0),K(null);try{const n=await te("/api/v1/agents/create-by-ai",{method:"POST",headers:se({"Content-Type":"application/json"}),body:JSON.stringify({description:o})}),a=await n.json().catch(()=>({}));if(!n.ok||((r=a==null?void 0:a.data)==null?void 0:r.success)!==!0){K(R(a,`HTTP ${n.status}`));return}U(!1),i(""),l(t("mainAgent.createSuccess"));const p=await G().callExtMethod("_codebuddy.ai/getAgents",{});F(p)}catch(n){K(R(n,t("mainAgent.createFailed")))}finally{S(!1)}}},ae=async o=>{if(!O){if(C!==o){w(o);return}A(!0),l(null);try{const r=await te("/api/v1/agents/delete",{method:"POST",headers:se({"Content-Type":"application/json"}),body:JSON.stringify({name:o})});if(!r.ok){const a=await r.json().catch(()=>({}));l(R(a,`${t("mainAgent.deleteFailed")} (HTTP ${r.status})`));return}l(t("mainAgent.deleted",{name:o}));const n=await G().callExtMethod("_codebuddy.ai/getAgents",{});F(n)}catch(r){l(R(r,t("mainAgent.deleteFailed")))}finally{A(!1),w(null)}}},Q=async o=>{var r;l(null);try{const n=await te("/api/v1/agents/open",{method:"POST",headers:se({"Content-Type":"application/json"}),body:JSON.stringify({name:o})}),a=await n.json().catch(()=>({}));if(!n.ok){l(R(a,t("mainAgent.openFailed")));return}const p=(r=a==null?void 0:a.data)==null?void 0:r.path;if(typeof p=="string"&&p.trim()){T(!1),Te(p.trim());return}l(t("mainAgent.openFailed"))}catch(n){l(R(n,t("mainAgent.openFailed")))}},le=async o=>{d(!0),l(null);try{const r=await te("/api/v1/settings/codebuddy?scope=user",{method:"PUT",headers:se({"Content-Type":"application/json"}),body:JSON.stringify({value:{mainAgent:{default:o}}})});r.ok||r.status===204?(b(o),q.getState().applyAgentFromResponse({defaultAgentName:o}),l(t("mainAgent.defaultSaved"))):l(`HTTP ${r.status}`)}catch(r){l(R(r,t("settings.saveFailed")))}finally{d(!1)}},ie=async()=>{if(l(null),!h){l(t("mainAgent.openInCreateFailed"));return}if(!x){l(t("mainAgent.openInCreateFailed"));return}d(!0),ze();try{const o=await G().callExtMethod("session/set_agent",{sessionId:h,agentName:"create"});o!=null&&o.agentName?(q.getState().applySetAgentResult({agentName:o.agentName,models:o.models??[],currentModelId:o.currentModelId??"",sessionBlank:o.sessionBlank??!1}),l(t("mainAgent.openInCreateSuccess"))):pe()}catch(o){pe(),l(R(o,t("mainAgent.openInCreateFailed")))}finally{d(!1)}},H=I.trim().toLowerCase(),J=o=>H?[o.name,o.displayName,ce(o,s),me(o,s)].filter(Boolean).join(" ").toLowerCase().includes(H):!0,Z=Re(m),X=[{label:t("mainAgent.groupBuiltin"),items:Z.builtin},{label:t("mainAgent.groupCustom"),items:Z.custom}].map(o=>({...o,items:o.items.filter(J)})).filter(o=>o.items.length>0),Y=De(f,u),ee=m.find(o=>o.name===Y),oe=ee?ce(ee,s):f||u||"-",re=e.jsxs(e.Fragment,{children:[m.length>4&&e.jsx("div",{className:"px-3 pb-1",children:e.jsx("input",{type:"search",value:I,onChange:o=>z(o.target.value),placeholder:t("mainAgent.searchPlaceholder"),className:"w-full rounded-md border border-border-default bg-bg-secondary px-2 py-1.5 text-[12px] text-text-primary outline-none focus:border-accent-brand"})}),g&&e.jsx("div",{className:"settings-value text-[12px] text-text-tertiary",children:g}),X.length===0&&e.jsx("div",{className:"settings-value",children:m.length===0?t("mainAgent.empty"):t("mainAgent.filterEmpty")}),X.map(o=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 pt-2 pb-1 text-[11px] uppercase tracking-wide text-text-tertiary",children:o.label}),o.items.map(r=>{const n=$e(r.name,Y),a=r.custom?r.source==="user"?t("mainAgent.scope.user"):t("mainAgent.scope.project"):null,p=r.custom&&(r.source==="user"||r.source==="project"),v=me(r,s);return e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("span",{className:"text-[13px] text-text-primary truncate block",children:[ce(r,s),a&&e.jsx("span",{className:"ml-1.5 rounded border border-border-default px-1 py-px text-[10px] text-text-tertiary align-middle",children:a})]}),v&&e.jsx("span",{className:"text-[11px] text-text-tertiary truncate block",children:v}),r.broken&&e.jsx("span",{className:"text-[11px] text-red-500 truncate block",children:r.broken})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[n?e.jsx("span",{className:"text-[11px] text-text-tertiary",children:t("mainAgent.isDefault")}):e.jsx("button",{type:"button",disabled:M||!!r.broken,onClick:()=>le(r.name),className:"text-[12px] text-accent-brand hover:underline disabled:opacity-40",children:t("mainAgent.setDefault")}),r.name==="create"&&!r.broken&&e.jsxs("button",{type:"button",disabled:M||!x,onClick:()=>{ie().catch(()=>{})},className:"flex items-center gap-1 text-[12px] text-accent-brand hover:underline disabled:opacity-40",title:t("mainAgent.openInCreate"),children:[e.jsx(ge,{size:12}),t("mainAgent.openInCreate")]}),p&&e.jsxs("button",{type:"button",onClick:()=>{Q(r.name).catch(()=>{})},className:"flex items-center gap-1 text-[12px] text-text-tertiary hover:text-text-primary",title:t("mainAgent.openFile"),children:[e.jsx(_e,{size:12}),t("mainAgent.openFile")]}),p&&e.jsxs("button",{type:"button",disabled:O,onClick:()=>{ae(r.name).catch(()=>{})},onBlur:()=>{C===r.name&&w(null)},className:`flex items-center gap-1 text-[12px] disabled:opacity-40 ${C===r.name?"text-red-500 font-medium hover:underline":"text-text-tertiary hover:text-red-500"}`,title:t("mainAgent.delete"),children:[e.jsx(Se,{size:12}),C===r.name?t("mainAgent.deleteConfirm"):t("mainAgent.delete")]})]})]},r.name)})]},o.label)),e.jsxs("button",{type:"button",onClick:()=>{U(!0),K(null)},className:"mx-2 my-2 flex w-[calc(100%-16px)] items-center justify-center gap-1.5 rounded-lg border border-dashed border-border-default py-2 text-[12px] text-text-tertiary transition-colors hover:border-accent-brand hover:text-text-primary",children:[e.jsx(ge,{size:13}),t("mainAgent.createByAI")]}),j&&e.jsxs("div",{className:"mx-2 mb-2 rounded-lg border border-border-default bg-bg-primary p-3",children:[e.jsx("div",{className:"text-[12px] text-text-primary mb-1.5",children:t("mainAgent.createByAIHint")}),e.jsx("textarea",{value:$,onChange:o=>i(o.target.value),rows:3,placeholder:t("mainAgent.createByAIPlaceholder"),className:"w-full resize-none rounded-md border border-border-default bg-bg-secondary px-2 py-1.5 text-[12px] text-text-primary outline-none focus:border-accent-brand",disabled:N}),_&&e.jsx("div",{className:"mt-1.5 text-[11px] text-red-500",children:_}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{U(!1),i(""),K(null)},disabled:N,className:"text-[12px] text-text-tertiary hover:text-text-primary disabled:opacity-40",children:t("app.cancel")}),e.jsx("button",{type:"button",onClick:V,disabled:N||!$.trim(),className:"flex items-center gap-1 rounded-md bg-accent-brand px-2.5 py-1 text-[12px] text-white hover:opacity-90 disabled:opacity-40",children:N?e.jsxs(e.Fragment,{children:[t("mainAgent.creating"),"…"]}):e.jsxs(e.Fragment,{children:[e.jsx(we,{size:12}),t("mainAgent.createByAI")]})})]})]})]});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"settings-row",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[e.jsx("span",{className:"settings-label",children:t("mainAgent.currentDefault")}),e.jsx("span",{className:"settings-desc",children:t("mainAgent.currentDefaultHint")})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 ml-3",children:[e.jsx("span",{className:"settings-value",children:e.jsx("strong",{children:oe})}),e.jsx("button",{type:"button",onClick:()=>{T(!0),l(null)},className:"rounded-md border border-border-default px-2.5 py-1 text-[12px] text-text-primary transition-colors hover:border-accent-brand hover:text-accent-brand",children:t("mainAgent.manage")})]})]}),B&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:()=>T(!1),children:e.jsxs("div",{className:"flex max-h-[80vh] w-full max-w-2xl flex-col overflow-hidden rounded-xl border border-border-default bg-bg-primary shadow-xl",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border-default px-4 py-3",children:[e.jsx("h3",{className:"text-[14px] font-medium text-text-primary",children:t("mainAgent.sectionTitle")}),e.jsx("button",{type:"button",onClick:()=>T(!1),className:"text-text-tertiary hover:text-text-primary","aria-label":t("app.cancel"),children:"✕"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-3",children:re})]})})]})}const dt=[{value:"minimal",labelKey:"settings.effort.minimal"},{value:"low",labelKey:"settings.effort.low"},{value:"medium",labelKey:"settings.effort.medium"},{value:"high",labelKey:"settings.effort.high"},{value:"xhigh",labelKey:"settings.effort.xhigh"},{value:"max",labelKey:"settings.effort.max"}],Ne=[{titleKey:"settings.group.modelAndReasoning",items:[{key:"model",labelKey:"settings.item.model",descKey:"settings.item.model.desc",type:"text"},{key:"reasoningEffort",labelKey:"settings.item.reasoningEffort",descKey:"settings.item.reasoningEffort.desc",type:"select",options:dt},{key:"alwaysThinkingEnabled",labelKey:"settings.item.alwaysThinkingEnabled",type:"toggle"}]},{titleKey:"settings.group.behavior",items:[{key:"autoCompactEnabled",labelKey:"settings.item.autoCompactEnabled",type:"toggle"},{key:"autoCompactWindow",labelKey:"settings.item.autoCompactWindow",descKey:"settings.item.autoCompactWindow.desc",type:"number"},{key:"includeCoAuthoredBy",labelKey:"settings.item.includeCoAuthoredBy",type:"toggle"},{key:"fileCheckpointingEnabled",labelKey:"settings.item.fileCheckpointingEnabled",descKey:"settings.item.fileCheckpointingEnabled.desc",type:"toggle"},{key:"promptSuggestionEnabled",labelKey:"settings.item.promptSuggestionEnabled",type:"toggle"},{key:"codebuddy.composer.busySendMode",labelKey:"settings.item.busySendMode",descKey:"settings.item.busySendMode.desc",type:"select",defaultValue:"queue",hideEmptyOption:!0,options:[{value:"queue",labelKey:"settings.item.busySendMode.queue"},{value:"immediate",labelKey:"settings.item.busySendMode.immediate"}]},{key:"ignoreGitIgnore",labelKey:"settings.item.ignoreGitIgnore",descKey:"settings.item.ignoreGitIgnore.desc",type:"toggle"},{key:"deferToolLoading",labelKey:"settings.item.deferToolLoading",type:"toggle"},{key:"hookOutputCollapsed",labelKey:"settings.item.hookOutputCollapsed",type:"toggle"}]},{titleKey:"settings.group.memory",items:[{key:"memory.enabled",labelKey:"settings.item.memory.enabled",type:"toggle"},{key:"memory.autoMemoryEnabled",labelKey:"settings.item.memory.autoMemoryEnabled",descKey:"settings.item.memory.autoMemoryEnabled.desc",type:"toggle"}]},{titleKey:"settings.group.language",items:[{key:"language",labelKey:"settings.item.language",descKey:"settings.item.language.desc",type:"text"}]},{titleKey:"settings.group.mainAgent",items:[{key:"codebuddy.mainAgent.enabled",labelKey:"settings.item.mainAgent.enabled",descKey:"settings.item.mainAgent.enabled.desc",type:"toggle",defaultValue:!0},{key:"codebuddy.mainAgent.allowUnopted",labelKey:"settings.item.mainAgent.allowUnopted",descKey:"settings.item.mainAgent.allowUnopted.desc",type:"toggle",defaultValue:!1}]},{titleKey:"settings.group.advanced",items:[{key:"cleanupPeriodDays",labelKey:"settings.item.cleanupPeriodDays",type:"number"},{key:"imageHistoryRetainRounds",labelKey:"settings.item.imageHistoryRetainRounds",descKey:"settings.item.imageHistoryRetainRounds.desc",type:"number"},{key:"env",labelKey:"settings.item.env",descKey:"settings.item.env.desc",type:"json"}]},{titleKey:"settings.group.sandbox",items:[{key:"sandbox.enabled",labelKey:"settings.item.sandbox.enabled",descKey:"settings.item.sandbox.enabled.desc",type:"toggle"},{key:"sandbox.autoAllowBashIfSandboxed",labelKey:"settings.item.sandbox.autoAllowBashIfSandboxed",descKey:"settings.item.sandbox.autoAllowBashIfSandboxed.desc",type:"toggle"}]}];function ve(t,s){const m=s.split(".");let u=t;for(const x of m){if(u==null||typeof u!="object")return;u=u[x]}return u}const E={connection:"settings-section-connection",appearance:"settings-section-appearance",model:"settings-section-model",mode:"settings-section-mode",system:"settings-section-system"};function ke(t){return`settings-section-${t.replace(/\./g,"-")}`}function ht(){const{status:t,sessionId:s,currentModel:m,models:u,modes:x,currentMode:k}=Me(),{info:h,fetch:f}=Ue(),{mode:b,toggle:M}=Ve(),{t:d,tryT:g,locale:l,toggleLocale:C}=ne(),w=q(n=>n.backendSupport),O=He(w),[A,I]=c.useState(null),[z,B]=c.useState({}),T=c.useRef({}),[F,j]=c.useState(!1),[U,$]=c.useState({}),i=c.useRef({}),N=c.useRef(null),[S,_]=c.useState(E.connection),[K,V]=c.useState(!1),ae=ve(z,"codebuddy.mainAgent.enabled")!==!1;c.useEffect(()=>{let n=!1;return j(!0),Promise.all([fetch("/api/v1/settings",{headers:de()}).then(a=>{if(!a.ok)throw new Error(`Settings API: ${a.status}`);return a.json()}).then(a=>(a==null?void 0:a.data)??a??{}),fetch("/api/v1/settings?scope=user",{headers:de()}).then(a=>{if(!a.ok)throw new Error(`User settings API: ${a.status}`);return a.json()}).then(a=>(a==null?void 0:a.data)??a??{})]).then(([a,p])=>{n||(B(a),T.current=p,he.getState().hydrateFromSettings(a),j(!1))}).catch(a=>{console.error("Failed to load settings:",a),n||j(!1)}),()=>{n=!0}},[]),c.useEffect(()=>()=>{Object.values(i.current).forEach(clearTimeout)},[]),c.useEffect(()=>{h||f()},[h,f]);const Q=c.useCallback(async(n,a)=>{await qe(n)&&(I(a),setTimeout(()=>I(null),1500))},[]),le=async n=>{if(H("model",n),Ze(n),s)try{await G().setModel(s,n)}catch(a){console.error("Model change failed:",a)}},ie=async n=>{if(H("permissions.defaultMode",n),Xe(n),s)try{await G().setMode(s,n)}catch(a){console.error("Mode change failed:",a)}},H=c.useCallback(async(n,a)=>{const p=n.split(".")[0];let v=a;if(n.includes(".")){const y=n.split("."),W={...T.current[p]??{}};let P=W;for(let D=1;D<y.length-1;D++)P[y[D]]=P[y[D]]?{...P[y[D]]}:{},P=P[y[D]];P[y[y.length-1]]=a,v=W}try{const y=await fetch(`/api/v1/settings/${p}?scope=user`,{method:"PUT",headers:de({"Content-Type":"application/json"}),body:JSON.stringify({value:v})});y.ok||y.status===204?(n.includes(".")?(T.current={...T.current,[p]:v},B(L=>({...L,[p]:{...L[p]??{},...v}}))):(T.current={...T.current,[n]:a},B(L=>({...L,[n]:a}))),n==="codebuddy.composer.busySendMode"&&(a==="queue"||a==="immediate")&&he.getState().setMode(a,!1),J(n,"success")):(console.error(`Failed to save setting "${n}": HTTP ${y.status}`),J(n,"error"))}catch(y){console.error(`Failed to save setting "${n}":`,y),J(n,"error")}},[]),J=c.useCallback((n,a)=>{$(p=>({...p,[n]:a})),i.current[n]&&clearTimeout(i.current[n]),i.current[n]=setTimeout(()=>{$(p=>{const v={...p};return delete v[n],v})},1500)},[]),Z={disconnected:"bg-gray-400",connecting:"bg-accent-yellow animate-pulse",connected:"bg-accent-green",error:"bg-accent-red"}[t],X={connected:"connection.connected",connecting:"connection.connecting",disconnected:"connection.disconnected",error:"connection.error"},Y=b==="light"?Ge:b==="dark"?Je:st,ee=d(b==="light"?"theme.light":b==="dark"?"theme.dark":"theme.system"),oe=l==="system"?et:We,re=d(l==="zh"?"locale.zh":l==="en"?"locale.en":"locale.system"),o=c.useMemo(()=>{const n=[{id:E.connection,label:d("sidebar.connectionStatus")},{id:E.appearance,label:d("settings.appearance")}];if(n.push({id:E.model,label:d("settings.model")}),x.length>0&&n.push({id:E.mode,label:d("settings.mode")}),!F)for(const a of Ne)n.push({id:ke(a.titleKey),label:d(a.titleKey)});return h&&n.push({id:E.system,label:d("settings.systemInfo")}),n},[d,u.length,x.length,F,h]),r=c.useCallback(n=>{const a=N.current,p=(a==null?void 0:a.querySelector(`#${CSS.escape(n)}`))??document.getElementById(n);p&&(_(n),p.scrollIntoView({behavior:"smooth",block:"start"}))},[]);return c.useEffect(()=>{const n=N.current;if(!n||o.length===0)return;const a=new IntersectionObserver(p=>{var L,W;const y=(W=(L=p.filter(P=>P.isIntersecting).sort((P,D)=>P.boundingClientRect.top-D.boundingClientRect.top)[0])==null?void 0:L.target)==null?void 0:W.id;y&&_(y)},{root:n,rootMargin:"-12% 0px -70% 0px",threshold:[0,.1,.25,.5,1]});for(const p of o){const v=n.querySelector(`#${CSS.escape(p.id)}`);v&&a.observe(v)}return()=>a.disconnect()},[o]),e.jsxs("div",{className:"settings-view",children:[e.jsxs("div",{className:"settings-content",ref:N,children:[e.jsx("nav",{className:"settings-toc","aria-label":"Settings sections",children:e.jsx("div",{className:"settings-toc-inner",children:o.map(n=>e.jsx("button",{type:"button",className:`settings-toc-item${S===n.id?" active":""}`,onClick:()=>r(n.id),children:n.label},n.id))})}),e.jsxs("div",{className:"settings-sections",children:[e.jsxs("div",{id:E.connection,className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d("sidebar.connectionStatus")}),e.jsxs("div",{className:"settings-card",children:[e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.status")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${Z}`}),e.jsx("span",{className:"settings-value",children:d(X[t]||"connection.disconnected")})]})]}),e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.sessionId")}),e.jsx("span",{className:"settings-value font-mono text-[12px]",children:s?s.substring(0,12):d("sidebar.notConnected")})]})]})]}),e.jsxs("div",{id:E.appearance,className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d("settings.appearance")}),e.jsxs("div",{className:"settings-card",children:[e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.theme")}),e.jsxs("button",{onClick:M,className:"settings-toggle-btn",children:[e.jsx(Y,{size:14,className:"text-accent-brand"}),e.jsx("span",{children:ee})]})]}),e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.language")}),e.jsxs("button",{onClick:C,className:"settings-toggle-btn",children:[e.jsx(oe,{size:14,className:"text-accent-brand"}),e.jsx("span",{children:re})]})]})]})]}),e.jsxs("div",{id:E.model,className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d("settings.model")}),e.jsxs("div",{className:"settings-card",children:[u.length>0?e.jsx("div",{className:"settings-row settings-row-stack",children:e.jsx("select",{value:m,onChange:n=>le(n.target.value),className:"settings-select",children:u.map(n=>e.jsx("option",{value:n.id,children:n.name||n.id},n.id))})}):e.jsx("div",{className:"settings-row",children:e.jsx("span",{className:"settings-value",children:d("sidebar.noModels")})}),e.jsxs("div",{className:"settings-row",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[e.jsx("span",{className:"settings-label",children:d("settings.customModels.entryLabel")}),e.jsx("span",{className:"settings-desc",children:d("settings.customModels.entryDesc")})]}),e.jsxs("button",{type:"button",className:"settings-toggle-btn",onClick:()=>V(!0),children:[e.jsx(Qe,{size:14,className:"text-accent-brand"}),e.jsx("span",{children:d("settings.customModels.manage")})]})]})]})]}),x.length>0&&e.jsxs("div",{id:E.mode,className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d("settings.mode")}),e.jsx("div",{className:"settings-card",children:e.jsx("select",{value:k,onChange:n=>ie(n.target.value),className:"settings-select",children:x.map(n=>e.jsx("option",{value:n.id,title:g(`mode.${n.id}.desc`)||n.description,children:g(`mode.${n.id}`)||n.name},n.id))})})]}),F?e.jsx("div",{className:"settings-group",children:e.jsx("span",{className:"settings-value",children:d("settings.loading")})}):Ne.map(n=>e.jsxs("div",{id:ke(n.titleKey),className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d(n.titleKey)}),e.jsxs("div",{className:"settings-card",children:[n.items.map(a=>e.jsx(ut,{item:a,value:ve(z,a.key),feedback:U[a.key],onSave:H},a.key)),n.titleKey==="settings.group.mainAgent"&&ae&&O.enabled&&!0&&e.jsx(ct,{})]})]},n.titleKey)),h&&e.jsxs("div",{id:E.system,className:"settings-group",children:[e.jsx("h2",{className:"settings-group-title",children:d("settings.systemInfo")}),e.jsxs("div",{className:"settings-card",children:[e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.cwd")}),e.jsxs("button",{onClick:()=>Q(h.cwd,"cwd"),className:"settings-copy-btn",title:h.cwd,children:[e.jsx("span",{className:"truncate cursor-pointer hover:underline hover:text-accent-brand",onClick:n=>{n.stopPropagation(),Te(h.cwd)},children:h.cwd}),A==="cwd"?e.jsx(xe,{size:12,className:"shrink-0 text-accent-green"}):e.jsx(be,{size:12,className:"shrink-0 text-text-tertiary"})]})]}),e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.os")}),e.jsxs("span",{className:"settings-value",children:[h.os," ",h.arch]})]}),e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.nodeVersion")}),e.jsx("span",{className:"settings-value",children:h.nodeVersion})]}),e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.gatewayMode")}),e.jsx("span",{className:"settings-value capitalize",children:h.gatewayMode})]}),h.tunnelUrl&&e.jsxs("div",{className:"settings-row",children:[e.jsx("span",{className:"settings-label",children:d("sidebar.tunnelUrl")}),e.jsxs("button",{onClick:()=>Q(h.tunnelUrl,"tunnel"),className:"settings-copy-btn",title:h.tunnelUrl,children:[e.jsx("span",{className:"truncate",children:h.tunnelUrl.replace(/^https?:\/\//,"")}),A==="tunnel"?e.jsx(xe,{size:12,className:"shrink-0 text-accent-green"}):e.jsx(be,{size:12,className:"shrink-0 text-text-tertiary"})]})]})]})]})]})]}),K&&e.jsx(rt,{onClose:()=>V(!1)})]})}function ut({item:t,value:s,feedback:m,onSave:u}){const{t:x}=ne(),[k,h]=c.useState(""),f=c.useRef(null);c.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]),c.useEffect(()=>{t.type==="text"||t.type==="number"?h(s!=null?String(s):""):t.type==="json"&&h(s!=null?JSON.stringify(s,null,2):"")},[s,t.type]);const b=t.type==="toggle"&&s===void 0&&t.defaultValue!==void 0?t.defaultValue:s,M=c.useCallback(()=>{u(t.key,!b)},[t.key,b,u]),d=c.useCallback(l=>{u(t.key,l||void 0)},[t.key,u]),g=c.useCallback(l=>{h(l),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{if(t.type==="number"){const C=Number(l);!isNaN(C)&&l.trim()!==""&&u(t.key,C)}else if(t.type==="json")try{const C=JSON.parse(l);u(t.key,C)}catch{}else u(t.key,l)},600)},[t.key,t.type,u]);return e.jsxs("div",{className:"settings-row",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"settings-label",children:x(t.labelKey)}),m&&e.jsx("span",{className:`settings-save-feedback ${m==="success"?"success":"error"}`,children:x(m==="success"?"settings.saved":"settings.saveFailed")})]}),t.descKey&&e.jsx("span",{className:"settings-desc",children:x(t.descKey)})]}),e.jsxs("div",{className:"flex items-center shrink-0 ml-3",children:[t.type==="toggle"&&e.jsx("button",{className:`settings-toggle-switch ${b?"on":""}`,onClick:M}),t.type==="select"&&t.options&&e.jsxs("select",{value:s??(typeof t.defaultValue=="string"?t.defaultValue:""),onChange:l=>d(l.target.value),className:"settings-inline-select",children:[!t.hideEmptyOption&&e.jsx("option",{value:"",children:"-"}),t.options.map(l=>e.jsx("option",{value:l.value,children:x(l.labelKey)},l.value))]}),t.type==="text"&&e.jsx("input",{type:"text",value:k,onChange:l=>g(l.target.value),placeholder:x("settings.notSet"),className:"settings-input"}),t.type==="number"&&e.jsx("input",{type:"number",value:k,onChange:l=>g(l.target.value),className:"settings-input",style:{width:80}}),t.type==="json"&&e.jsx("textarea",{value:k,onChange:l=>g(l.target.value),placeholder:"{}",className:"settings-input wide",rows:3,style:{width:"100%",resize:"vertical"}})]})]})}export{ht as SettingsView};
@@ -1 +1 @@
1
- import{a as o,j as s}from"./markdown-DIY6o85n.js";import{u as z,ai as D}from"./index-CHcoPr8x.js";function b({direction:r,ratio:n,onRatioChange:a,children:u}){const{t:d}=z(),h=o.useRef(null),[p,c]=o.useState(!1),w=o.useCallback(e=>{if(e.button!==0&&e.pointerType==="mouse")return;e.preventDefault(),e.stopPropagation();const t=h.current;if(!t)return;const l=t.getBoundingClientRect();c(!0),D({pointerId:e.pointerId,target:e.currentTarget,cursor:r==="horizontal"?"col-resize":"row-resize",onMove:(v,y)=>{let f;r==="horizontal"?f=(v-l.left)/l.width:f=(y-l.top)/l.height,a(Math.max(.1,Math.min(.9,f)))},onEnd:()=>c(!1)})},[r,a]),g=o.useCallback(e=>{let t=null;e.key==="Home"&&(t=.1),e.key==="End"&&(t=.9),r==="horizontal"?(e.key==="ArrowLeft"&&(t=n-.05),e.key==="ArrowRight"&&(t=n+.05)):(e.key==="ArrowUp"&&(t=n-.05),e.key==="ArrowDown"&&(t=n+.05)),t!==null&&(e.preventDefault(),a(Math.max(.1,Math.min(.9,t))))},[r,a,n]),i=r==="horizontal",m=`${n*100}%`,x=`${(1-n)*100}%`;return s.jsxs("div",{ref:h,className:"flex h-full w-full min-h-0",style:{flexDirection:i?"row":"column"},children:[s.jsx("div",{style:{[i?"width":"height"]:m,overflow:"hidden",display:"flex"},children:u[0]}),s.jsx("div",{className:`split-sash ${i?"split-sash-horizontal":"split-sash-vertical"} ${p?"dragging":""}`,role:"separator",tabIndex:0,"aria-label":d("ide.resizeSplit"),"aria-orientation":i?"vertical":"horizontal","aria-valuemin":10,"aria-valuemax":90,"aria-valuenow":Math.round(n*100),onPointerDown:w,onKeyDown:g}),s.jsx("div",{style:{[i?"width":"height"]:x,overflow:"hidden",display:"flex"},children:u[1]})]})}export{b as S};
1
+ import{a as o,j as s}from"./markdown-CP9awqWt.js";import{u as z,ai as D}from"./index-CBmymKHy.js";function b({direction:r,ratio:n,onRatioChange:a,children:u}){const{t:d}=z(),h=o.useRef(null),[p,c]=o.useState(!1),w=o.useCallback(e=>{if(e.button!==0&&e.pointerType==="mouse")return;e.preventDefault(),e.stopPropagation();const t=h.current;if(!t)return;const l=t.getBoundingClientRect();c(!0),D({pointerId:e.pointerId,target:e.currentTarget,cursor:r==="horizontal"?"col-resize":"row-resize",onMove:(v,y)=>{let f;r==="horizontal"?f=(v-l.left)/l.width:f=(y-l.top)/l.height,a(Math.max(.1,Math.min(.9,f)))},onEnd:()=>c(!1)})},[r,a]),g=o.useCallback(e=>{let t=null;e.key==="Home"&&(t=.1),e.key==="End"&&(t=.9),r==="horizontal"?(e.key==="ArrowLeft"&&(t=n-.05),e.key==="ArrowRight"&&(t=n+.05)):(e.key==="ArrowUp"&&(t=n-.05),e.key==="ArrowDown"&&(t=n+.05)),t!==null&&(e.preventDefault(),a(Math.max(.1,Math.min(.9,t))))},[r,a,n]),i=r==="horizontal",m=`${n*100}%`,x=`${(1-n)*100}%`;return s.jsxs("div",{ref:h,className:"flex h-full w-full min-h-0",style:{flexDirection:i?"row":"column"},children:[s.jsx("div",{style:{[i?"width":"height"]:m,overflow:"hidden",display:"flex"},children:u[0]}),s.jsx("div",{className:`split-sash ${i?"split-sash-horizontal":"split-sash-vertical"} ${p?"dragging":""}`,role:"separator",tabIndex:0,"aria-label":d("ide.resizeSplit"),"aria-orientation":i?"vertical":"horizontal","aria-valuemin":10,"aria-valuemax":90,"aria-valuenow":Math.round(n*100),onPointerDown:w,onKeyDown:g}),s.jsx("div",{style:{[i?"width":"height"]:x,overflow:"hidden",display:"flex"},children:u[1]})]})}export{b as S};