@deepseekcode/cli 1.0.24 → 1.0.26

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 (39) hide show
  1. package/dist/cli.js +1170 -1124
  2. package/package.json +4 -1
  3. package/web/dist/assets/AutomationView-CPCd-Qhd.js +1 -0
  4. package/web/dist/assets/ChannelConfigView-D6JtjZyf.js +8 -0
  5. package/web/dist/assets/ConnectorsView-BPPr7T9p.js +1 -0
  6. package/web/dist/assets/FileTreeView-CO8knuwu.js +11 -0
  7. package/web/dist/assets/HookConfigView-CYuzwf8u.js +1 -0
  8. package/web/dist/assets/ModelsView-Cji4mbXE.js +1 -0
  9. package/web/dist/assets/PluginsView-CKKnYKMP.js +1 -0
  10. package/web/dist/assets/SessionGrid-BOpVWUEK.js +37 -0
  11. package/web/dist/assets/SettingsPanel-R1fOoB25.js +4 -0
  12. package/web/dist/assets/{SkillsView-BrQY_vgT.js → SkillsView-DmQGY9v0.js} +1 -1
  13. package/web/dist/assets/TemplatesTab-_vSIuTZP.js +1 -0
  14. package/web/dist/assets/TerminalView-CTU0aA8o.js +3 -0
  15. package/web/dist/assets/ToolsView-DUEqePPo.js +1 -0
  16. package/web/dist/assets/{icons-B9mi2ie6.js → icons-qcawb7PZ.js} +1 -1
  17. package/web/dist/assets/index-DL2ULWxM.css +1 -0
  18. package/web/dist/assets/index-DUpwXfa-.js +70 -0
  19. package/web/dist/assets/{markdown-BrFQfawv.js → markdown-yjmXQjrx.js} +1 -1
  20. package/web/dist/assets/{panels-BX-TtLOU.js → panels-CX_dYEv0.js} +1 -1
  21. package/web/dist/assets/{react-vendor-CiRFOYk_.js → react-vendor-CSlQceOk.js} +1 -1
  22. package/web/dist/assets/{state-BcoCffxz.js → state-DOzZasIm.js} +1 -1
  23. package/web/dist/favicon.svg +32 -12
  24. package/web/dist/index.html +7 -7
  25. package/web/dist/logo.svg +32 -12
  26. package/web/dist/assets/AutomationView-MOGwMs0s.js +0 -1
  27. package/web/dist/assets/ChannelConfigView-CHWC4ETy.js +0 -8
  28. package/web/dist/assets/ConnectorsView-DaP_wB0W.js +0 -1
  29. package/web/dist/assets/FileTreeView-N64-Dser.js +0 -11
  30. package/web/dist/assets/HookConfigView-DsZDeVFi.js +0 -2
  31. package/web/dist/assets/ModelsView-C1cE2wMN.js +0 -2
  32. package/web/dist/assets/PluginsView-CsSjjfrn.js +0 -1
  33. package/web/dist/assets/SessionGrid-Bg-UTI2P.js +0 -37
  34. package/web/dist/assets/SettingsPanel-pZbjabYJ.js +0 -4
  35. package/web/dist/assets/TemplatesTab-DSfCryw2.js +0 -1
  36. package/web/dist/assets/TerminalView-Drr72DaP.js +0 -3
  37. package/web/dist/assets/ToolsView-ByqbKwqW.js +0 -1
  38. package/web/dist/assets/index-DCj9TkXV.css +0 -1
  39. package/web/dist/assets/index-PcXINYWS.js +0 -68
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepseekcode/cli",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "DeepSeekCode TypeScript CLI",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -56,6 +56,9 @@
56
56
  },
57
57
  "devDependencies": {
58
58
  "@babel/core": "^7.26.0",
59
+ "@deepseekcode/core": "workspace:*",
60
+ "@deepseekcode/server": "workspace:*",
61
+ "@deepseekcode/shared": "workspace:*",
59
62
  "@types/react": "^19.0.0",
60
63
  "@types/ws": "^8.5.13",
61
64
  "babel-plugin-react-compiler": "^1.0.0",
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-yjmXQjrx.js";import{a as n,ak as v,h as $,z as D,$ as O,ba as I,f as L,aq as J,aO as U,X as q}from"./icons-qcawb7PZ.js";import{u as B,Y as M}from"./index-DUpwXfa-.js";import"./react-vendor-CSlQceOk.js";import"./state-DOzZasIm.js";import"./panels-CX_dYEv0.js";function K(){const{t:a}=B(),{automations:r,runsByAutomation:d,fetchAutomations:o,createAutomation:N,deleteAutomation:y,toggleAutomation:w,runAutomation:C,fetchRuns:A,error:l}=M(),[S,x]=n.useState(!1),[m,z]=n.useState(null),[u,p]=n.useState(""),[h,b]=n.useState(""),[i,g]=n.useState("0 9 * * *"),[f,j]=n.useState("");n.useEffect(()=>{o()},[o]);const P=async t=>{const s=f.trim();if(!s)return;const[c,...T]=s.split(/\s+/),k=T.join(" ");c&&k&&(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tool:c,target:k})})).ok&&(j(""),await o())},E=async(t,s)=>{(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"DELETE",headers:{"content-type":"application/json"},body:JSON.stringify({entry:s})})).ok&&await o()},R=async t=>{const s=m===t?null:t;z(s),s&&await A(t)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(v,{size:20,className:"text-accent-blue"}),a("automation.title"),e.jsxs("span",{className:"text-xs text-dark-muted font-normal",children:["(",r.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>void o(),className:"p-2 rounded-lg hover:bg-dark-hover text-dark-muted",title:a("automation.refresh"),children:e.jsx($,{size:16})}),e.jsxs("button",{onClick:()=>x(t=>!t),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-blue/20 text-accent-blue hover:bg-accent-blue/30 text-sm font-medium",children:[e.jsx(D,{size:16})," ",a("automation.new")]})]})]}),l&&e.jsxs("div",{className:"mb-3 p-3 rounded-lg bg-accent-red/10 text-accent-red text-sm flex items-center gap-2",children:[e.jsx(O,{size:16})," ",l]}),S&&e.jsxs("div",{className:"mb-4 rounded-lg border border-dark-border bg-dark-surface p-4 space-y-3",children:[e.jsx("input",{value:u,onChange:t=>p(t.target.value),placeholder:a("automation.namePlaceholder"),className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),e.jsx("textarea",{value:h,onChange:t=>b(t.target.value),placeholder:a("automation.instructionsPlaceholder"),rows:3,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue resize-none"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:i,onChange:t=>g(t.target.value),placeholder:a("automation.cronPlaceholder"),className:"flex-1 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:async()=>{await N({name:u,instructions:h,schedule:{kind:"cron",cron:i}})&&(p(""),b(""),x(!1))},className:"px-4 py-2 rounded-lg bg-accent-blue text-white text-sm font-medium hover:bg-accent-blue/80",children:a("automation.create")})]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:[["0 9 * * *",a("automation.cronDaily9")],["0 9 * * 1-5",a("automation.cronWeekday9")],["*/30 * * * *",a("automation.cronEvery30Min")]].map(([t,s])=>e.jsxs("button",{onClick:()=>g(t),className:`px-2 py-1 rounded text-xs ${i===t?"bg-accent-blue/20 text-accent-blue":"bg-dark-hover text-dark-muted hover:text-dark-text"}`,children:[s," (",t,")"]},t))})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2",children:[r.length===0&&e.jsx("p",{className:"text-dark-muted text-center py-8",children:a("automation.empty")}),r.map(t=>e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface",children:[e.jsxs("div",{className:"flex items-center justify-between p-3",children:[e.jsxs("button",{onClick:()=>void R(t.id),className:"flex items-center gap-2 min-w-0 text-left",children:[e.jsx(v,{size:16,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"font-medium text-sm truncate",children:t.name}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded shrink-0 ${t.status==="enabled"?"bg-accent-green/20 text-accent-green":"bg-dark-hover text-dark-muted"}`,children:t.status})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("span",{className:"text-xs text-dark-muted hidden lg:inline mr-1",children:[t.schedule.kind==="cron"?t.schedule.cron:t.schedule.fireAt,t.nextRunAt?` · ${new Date(t.nextRunAt).toLocaleString()}`:""]}),e.jsx("button",{onClick:()=>void w(t.id,t.status!=="enabled"),className:"p-1.5 rounded-lg hover:bg-dark-hover text-dark-muted",title:t.status==="enabled"?a("automation.disable"):a("automation.enable"),children:e.jsx(I,{size:15})}),e.jsx("button",{onClick:()=>void C(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-green",title:a("automation.runNow"),children:e.jsx(L,{size:15})}),e.jsx("button",{onClick:()=>void y(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-red",title:a("automation.delete"),children:e.jsx(J,{size:15})})]})]}),m===t.id&&e.jsxs("div",{className:"px-3 pb-3 space-y-3 border-t border-dark-border pt-3",children:[e.jsx("p",{className:"text-xs text-dark-muted whitespace-pre-wrap",children:t.instructions}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold text-dark-muted mb-1 flex items-center gap-1",children:[e.jsx(U,{size:12})," ",a("automation.historyTitle")]}),(d[t.id]||[]).length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:a("automation.noRuns")}),(d[t.id]||[]).slice(0,10).map(s=>e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded ${s.status==="ok"?"bg-accent-green/20 text-accent-green":s.status==="error"?"bg-accent-red/20 text-accent-red":"bg-accent-yellow/20 text-accent-yellow"}`,children:s.status}),e.jsx("span",{className:"text-dark-muted",children:new Date(s.startedAt).toLocaleString()}),e.jsxs("span",{className:"text-dark-muted truncate flex-1",children:["#",s.id.slice(0,8)," · ",s.trigger]})]},s.id))]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-dark-muted mb-1",children:a("automation.permissionsTitle")}),t.permissions.length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:a("automation.permissionsEmpty")}),e.jsx("div",{className:"flex flex-wrap gap-1 mb-1",children:t.permissions.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded bg-accent-blue/10 text-accent-blue text-xs",children:[s,e.jsx("button",{onClick:()=>void E(t.id,s),className:"hover:text-accent-red",children:e.jsx(q,{size:12})})]},s))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:f,onChange:s=>j(s.target.value),placeholder:a("automation.permissionPlaceholder"),className:"flex-1 px-2 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-xs focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:()=>void P(t.id),className:"px-3 py-1.5 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-xs",children:a("automation.add")})]})]})]})]},t.id))]})]})}export{K as AutomationView};
@@ -0,0 +1,8 @@
1
+ import{j as a}from"./markdown-yjmXQjrx.js";import{a as A,bb as ft,$ as gt,aw as mt,av as xt,aj as vt,z as re,bc as Be,aq as pt,a8 as Et,g as St,h as Tt}from"./icons-qcawb7PZ.js";import{u as D,X as Re,M as Bt,a as Le,t as se}from"./index-DUpwXfa-.js";import"./react-vendor-CSlQceOk.js";import"./state-DOzZasIm.js";import"./panels-CX_dYEv0.js";const Rt={wechat:"微信",feishu:"飞书",dingtalk:"钉钉",telegram:"Telegram",discord:"Discord",slack:"Slack",signal:"Signal",whatsapp:"WhatsApp",line:"LINE",qqbot:"QQ Bot",matrix:"Matrix",mattermost:"Mattermost",msteams:"Teams",googlechat:"Google Chat",irc:"IRC",imessage:"iMessage",sms:"SMS","nextcloud-talk":"Nextcloud Talk",nostr:"Nostr","synology-chat":"Synology Chat",tlon:"Tlon",twitch:"Twitch",zalo:"Zalo",zalouser:"ZaloUser",clickclack:"ClickClack",raft:"Raft","qa-channel":"QA"},Mt={wechat:"💬",feishu:"📘",dingtalk:"🔔",telegram:"✈️",discord:"🎮",slack:"💼",signal:"🔒",whatsapp:"📱",line:"🟢",qqbot:"🐧",matrix:"🧩",mattermost:"🏢",msteams:"📋",googlechat:"📧",irc:"💻",imessage:"✉️",sms:"📨"},At=new Set(["mattermost","msteams","googlechat","irc","imessage","sms","nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser","clickclack","raft","qa-channel"]);function H(n){return Rt[n]??n}function Y(n){return Mt[n]??"📡"}function $(n){return At.has(n)}const W=[{labelKey:"im",types:["wechat","feishu","dingtalk"]},{labelKey:"international",types:["telegram","discord","slack","signal","whatsapp"]},{labelKey:"eastAsia",types:["line","qqbot"]},{labelKey:"collaboration",types:["matrix","mattermost","msteams","googlechat"]},{labelKey:"classic",types:["irc","imessage","sms"]},{labelKey:"other",types:["nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser"]},{labelKey:"builtin",types:["clickclack","raft","qa-channel"]}];function It(){const{t:n}=D(),{channels:i,availableTypes:s,selectedType:t,selectType:e,loadTypes:r}=Re();A.useEffect(()=>{r()},[r]);const l=A.useMemo(()=>{if(s.length>0){const d=new Set(s);return W.map(m=>({...m,types:m.types.filter(f=>d.has(f))})).filter(m=>m.types.length>0).concat(s.filter(m=>!W.flatMap(f=>f.types).includes(m)).length>0?[{labelKey:"plugins",types:s.filter(m=>!W.flatMap(f=>f.types).includes(m))}]:[])}return W},[s]),o=A.useMemo(()=>{const d=new Map;for(const m of i){const f=d.get(m.type)??{count:0,connected:0};d.set(m.type,{count:f.count+1,connected:f.connected+(m.connected?1:0)})}return d},[i]),c=s.length>0,u=A.useMemo(()=>c?[...o.keys()].filter(d=>!s.includes(d)):[],[c,o,s]);return a.jsxs("div",{className:"flex flex-col h-full min-h-0 border-r border-dark-border bg-dark-surface",children:[a.jsxs("div",{className:"shrink-0 px-4 py-3 border-b border-dark-border",children:[a.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-dark-muted",children:n("channels.sidebar.title")}),a.jsx("p",{className:"text-[11px] text-dark-muted mt-0.5",children:i.length>0?n("channels.sidebar.configuredCount",{n:i.length}):n("channels.sidebar.clickToConfigure")})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar",children:[l.map(d=>{const m=d.types.filter(f=>o.has(f));return m.length===0?null:a.jsxs("div",{children:[a.jsx("div",{className:"sticky top-0 bg-dark-surface/95 backdrop-blur px-4 py-1.5 text-[10px] font-semibold uppercase tracking-wider text-dark-muted/60",children:n(`channels.categories.${d.labelKey}`)}),m.map(f=>{const h=o.get(f);return a.jsx(ie,{label:H(f),icon:Y(f),isSelected:t===f,experimental:$(f),info:h,pluginMissing:c&&!s.includes(f),onClick:()=>e(f)},f)})]},d.labelKey)}),u.length>0&&a.jsxs("div",{children:[a.jsx("div",{className:"sticky top-0 bg-dark-surface/95 backdrop-blur px-4 py-1.5 text-[10px] font-semibold uppercase tracking-wider text-amber-500/80",children:n("channels.sidebar.configuredMissing")}),u.map(d=>{const m=o.get(d);return a.jsx(ie,{label:H(d),icon:Y(d),isSelected:t===d,experimental:$(d),info:m,pluginMissing:!0,onClick:()=>e(d)},d)})]}),(()=>{const d=l.flatMap(m=>m.types).filter(m=>!o.has(m));return d.length===0?null:a.jsxs("div",{children:[a.jsx("div",{className:"sticky top-0 bg-dark-surface/95 backdrop-blur px-4 py-1.5 text-[10px] font-semibold uppercase tracking-wider text-dark-muted/60",children:n("channels.sidebar.unconfigured")}),d.map(m=>a.jsx(ie,{label:H(m),icon:Y(m),isSelected:t===m,experimental:$(m),onClick:()=>e(m)},m))]})})()]})]})}function ie({label:n,icon:i,isSelected:s,experimental:t,info:e,pluginMissing:r,onClick:l}){const{t:o}=D();return a.jsxs("button",{onClick:l,className:`w-full flex items-center gap-2.5 px-4 py-2.5 text-left transition-colors hover:bg-dark-hover ${s?"bg-accent-blue/10 border-l-2 border-accent-blue":"border-l-2 border-transparent"}`,children:[a.jsx("span",{className:"text-lg shrink-0 w-7 h-7 flex items-center justify-center rounded-md bg-dark-bg",children:i}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:"text-sm font-medium text-dark-text truncate",children:n}),t&&a.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[9px] text-yellow-500 bg-yellow-500/10 px-1 py-0.5 rounded shrink-0",title:o("channels.experimentalTip"),children:[a.jsx(ft,{className:"w-2.5 h-2.5"})," ",o("channels.experimentalShort")]}),r&&a.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[9px] text-amber-500 bg-amber-500/10 border border-amber-500/30 px-1 py-0.5 rounded shrink-0",title:o("channels.pluginMissingTip"),children:[a.jsx(gt,{className:"w-2.5 h-2.5"})," ",o("channels.pluginMissingLabel")]}),e&&a.jsx("span",{className:"text-[10px] text-dark-muted bg-dark-hover px-1.5 py-0.5 rounded shrink-0",children:e.count})]}),a.jsx("div",{className:"flex items-center gap-1 mt-0.5",children:e?e.connected>0?a.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-green-400",children:[a.jsx(mt,{className:"w-3 h-3"}),e.connected===e.count?o("channels.status.connected"):o("channels.sidebar.partialConnected",{connected:e.connected,count:e.count})]}):a.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-dark-muted",children:[a.jsx(xt,{className:"w-3 h-3"}),o(r?"channels.sidebar.waitingPlugin":"channels.status.disconnected")]}):a.jsx("span",{className:"text-[11px] text-dark-muted",children:o("channels.sidebar.unconfigured")})})]})]})}const z={name:"",type:"wechat",appId:"",appSecret:"",token:"",encodingAESKey:"",enabled:!0};function Pt(){const{t:n}=D(),{channels:i,selectedType:s,availableTypes:t,create:e,update:r,remove:l,toggle:o,error:c,clearError:u,openQr:d,load:m}=Re(),f=A.useMemo(()=>t.length>0&&!!s&&!t.includes(s),[t,s]),h=A.useMemo(()=>s?i.filter(g=>g.type===s):[],[i,s]),[w,S]=A.useState(""),[M,y]=A.useState(z),[R,E]=A.useState(!1),C=w==="__new__",k=A.useMemo(()=>C?null:h.find(g=>g.id===w)??null,[h,w,C]);A.useEffect(()=>{S(""),y(z),E(!1),u()},[s]),A.useEffect(()=>{s==="wechat"&&h.length===0&&!f&&d(null)},[s,h.length,f,d]),A.useEffect(()=>{k?y({name:k.name,type:k.type,appId:k.appId||"",appSecret:"",token:"",encodingAESKey:k.encodingAESKey||"",enabled:k.enabled}):C&&y(g=>({...g,type:s}))},[w]);const x=(g,T)=>{u(),y(I=>({...I,[g]:T}))},p=g=>{S(g),u()},N=()=>{S("__new__"),y({...z,type:s}),u()},b=()=>{S(""),y(z),u()},B=async()=>{if(!M.name.trim())return;E(!0);const g=k?await r(k.id,M):await e(M);E(!1),g&&(S(""),y(z))},j=async g=>{if(!confirm(n("channels.actions.deleteConfirmShort")))return;await l(g)&&w===g&&(S(""),y(z))},v=(g,T)=>{o(g,T)};return s?a.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[a.jsx("div",{className:"shrink-0 px-6 py-4 border-b border-dark-border",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("span",{className:"text-2xl",children:Y(s)}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("h2",{className:"font-semibold text-base text-dark-text",children:H(s)}),$(s)&&a.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] text-yellow-500 bg-yellow-500/10 px-1.5 py-0.5 rounded",title:n("channels.experimentalTip"),children:[a.jsx(ft,{className:"w-3 h-3"})," ",n("channels.experimentalLabel")]})]}),a.jsx("p",{className:"text-xs text-dark-muted mt-0.5",children:h.length>0?n("channels.instancesCount",{n:h.length}):n("channels.notConfiguredYet")}),$(s)&&a.jsx("p",{className:"text-[10px] text-yellow-600/70 mt-1",children:n("channels.experimentalDesc")})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{onClick:()=>m(),className:"text-xs px-3 py-1.5 rounded-lg border border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:n("channels.actions.refresh")}),a.jsxs("button",{onClick:N,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-lg bg-accent-blue hover:bg-accent-blue/90 text-white transition-colors",children:[a.jsx(re,{className:"w-3.5 h-3.5"})," ",n("channels.createInstance")]})]})]})}),c&&a.jsxs("div",{className:"shrink-0 mx-6 mt-3 bg-red-500/10 border border-red-500/40 text-red-400 px-3 py-2 rounded-lg text-sm flex justify-between items-center",children:[a.jsx("span",{children:c}),a.jsx("button",{onClick:u,className:"text-red-400 hover:text-red-300",children:a.jsx("span",{className:"w-4 h-4 inline-flex items-center justify-center",children:"×"})})]}),f&&a.jsxs("div",{className:"shrink-0 mx-6 mt-3 flex items-start gap-2 bg-amber-500/10 border border-amber-500/40 text-amber-400 px-3 py-2 rounded-lg text-xs",children:[a.jsx(gt,{className:"w-3.5 h-3.5 mt-0.5 shrink-0"}),a.jsx("span",{children:n("channels.pluginMissingWarning",{name:s==="wechat"?" WeChat Channel":` ${H(s)}`})})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar p-6",children:[h.length>1&&!C&&a.jsxs("div",{className:"mb-4",children:[a.jsx("label",{className:"block text-xs text-dark-muted mb-1.5",children:n("channels.selectInstance")}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[h.map(g=>a.jsxs("button",{onClick:()=>p(g.id),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs border transition-colors ${w===g.id?"bg-accent-blue/10 border-accent-blue/40 text-accent-blue":"border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,children:[a.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${g.connected?"bg-green-500":"bg-gray-500"}`}),g.name]},g.id)),a.jsxs("button",{onClick:N,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs border border-dashed border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:[a.jsx(re,{className:"w-3 h-3"})," ",n("channels.createShort")]})]})]}),h.length===0&&w===""&&a.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[a.jsx("div",{className:"text-4xl mb-3",children:Y(s)}),a.jsx("p",{className:"text-dark-text font-medium",children:n("channels.emptyWithType",{type:H(s)})}),a.jsx("p",{className:"text-sm text-dark-muted mt-1 mb-4",children:n(s==="wechat"?"channels.wechatBindHint":"channels.startWithCreate")}),s==="wechat"&&a.jsxs("button",{onClick:()=>d(null),className:"flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 transition-colors mb-3",children:[a.jsx(Be,{className:"w-4 h-4"})," ",n("channels.scanToBind")]}),a.jsxs("button",{onClick:N,className:"flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-accent-blue hover:bg-accent-blue/90 text-white transition-colors",children:[a.jsx(re,{className:"w-4 h-4"})," ",n("channels.createInstance")]})]}),h.length===1&&w===""&&h[0]&&a.jsx(qe,{channel:h[0],onEdit:()=>p(h[0].id),onDelete:()=>j(h[0].id),onToggle:g=>v(h[0].id,g),onQr:()=>d(h[0])}),h.length>1&&w===""&&a.jsx("div",{className:"space-y-3",children:h.map(g=>a.jsx(qe,{channel:g,onEdit:()=>p(g.id),onDelete:()=>j(g.id),onToggle:T=>v(g.id,T),onQr:()=>d(g)},g.id))}),w!==""&&(C||k)&&a.jsx(Lt,{form:M,upd:x,saving:R,editing:!!k,channel:k??void 0,onSave:B,onCancel:b,onDelete:k?()=>j(k.id):void 0,onQr:k?()=>d(k):void 0})]})]}):a.jsx("div",{className:"flex-1 flex items-center justify-center",children:a.jsxs("div",{className:"text-center",children:[a.jsx(vt,{className:"w-12 h-12 mx-auto mb-3 text-dark-muted/40"}),a.jsx("p",{className:"text-dark-muted text-sm",children:n("channels.selectTypeHint")})]})})}function qe({channel:n,onEdit:i,onDelete:s,onToggle:t,onQr:e}){const{t:r}=D();return a.jsxs("div",{className:"border border-dark-border rounded-lg bg-dark-surface overflow-hidden",children:[a.jsx("div",{className:"p-5",children:a.jsxs("div",{className:"flex items-start justify-between",children:[a.jsxs("div",{children:[a.jsx("h3",{className:"font-medium text-dark-text",children:n.name}),a.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[a.jsx("span",{className:`flex items-center gap-1 text-xs ${n.connected?"text-green-400":"text-dark-muted"}`,children:n.connected?a.jsxs(a.Fragment,{children:[a.jsx(mt,{className:"w-3 h-3"})," ",r("channels.status.connected")]}):a.jsxs(a.Fragment,{children:[a.jsx(xt,{className:"w-3 h-3"})," ",r("channels.status.disconnected")]})}),a.jsxs("span",{className:"text-xs text-dark-muted",children:["AppID: ",n.appId||"—"]})]})]}),a.jsx("button",{onClick:()=>t(!n.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${n.enabled?"bg-green-600":"bg-gray-600"}`,children:a.jsx("span",{className:`absolute top-0.5 w-4 h-4 bg-white rounded-full transition-all ${n.enabled?"left-[18px]":"left-0.5"}`})})]})}),a.jsxs("div",{className:"flex items-center gap-1 px-5 py-2.5 bg-dark-bg/50 border-t border-dark-border",children:[n.type==="wechat"&&a.jsxs("button",{onClick:e,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-green-400 hover:bg-green-500/10 transition-colors",children:[a.jsx(Be,{className:"w-3.5 h-3.5"})," ",r("channels.actions.qrLogin")]}),a.jsxs("button",{onClick:i,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-accent-blue hover:bg-accent-blue/10 transition-colors",children:[a.jsx("span",{className:"w-3.5 h-3.5 inline-flex items-center justify-center",children:"✎"})," ",r("channels.actions.edit")]}),a.jsxs("button",{onClick:s,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-red-400 hover:bg-red-500/10 transition-colors ml-auto",children:[a.jsx(pt,{className:"w-3.5 h-3.5"})," ",r("channels.actions.delete")]})]})]})}function Lt({form:n,upd:i,saving:s,editing:t,channel:e,onSave:r,onCancel:l,onDelete:o,onQr:c}){const{t:u}=D();return a.jsxs("div",{className:"border border-dark-border rounded-lg bg-dark-surface overflow-hidden",children:[a.jsx("div",{className:"px-5 py-4 border-b border-dark-border",children:a.jsx("h3",{className:"font-medium text-dark-text",children:u(t?"channels.editConfig":"channels.createConfig")})}),a.jsxs("div",{className:"p-5 space-y-4",children:[a.jsx(_e,{label:u("channels.form.name"),required:!0,children:a.jsx("input",{value:n.name,onChange:d=>i("name",d.target.value),placeholder:u("channels.form.namePlaceholderDev"),className:Q})}),a.jsxs(_e,{label:u("channels.form.credentials"),children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:u("channels.form.appId")}),a.jsx("input",{value:n.appId,onChange:d=>i("appId",d.target.value),placeholder:"AppID",className:Q})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"AppSecret"}),a.jsx("input",{type:"password",value:n.appSecret,onChange:d=>i("appSecret",d.target.value),placeholder:u(t?"channels.form.leaveBlankUnchanged":"channels.form.appSecretValue"),className:Q})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"Token"}),a.jsx("input",{value:n.token,onChange:d=>i("token",d.target.value),placeholder:u(t?"channels.form.leaveBlankUnchanged":"channels.form.tokenCallback"),className:Q})]}),n.type==="wechat"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"EncodingAESKey"}),a.jsx("input",{value:n.encodingAESKey,onChange:d=>i("encodingAESKey",d.target.value),placeholder:u("channels.form.optionalShort"),className:Q})]})]}),n.type==="wechat"&&a.jsx("p",{className:"text-xs text-dark-muted mt-2",children:u("channels.form.wechatIlinkHint")})]}),a.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-dark-border px-3 py-2.5",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-dark-text",children:u("channels.form.enabled")}),a.jsx("p",{className:"text-xs text-dark-muted",children:u("channels.form.enabledOffHint")})]}),a.jsx("button",{onClick:()=>i("enabled",!n.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${n.enabled?"bg-green-600":"bg-gray-600"}`,children:a.jsx("span",{className:`absolute top-0.5 w-4 h-4 bg-white rounded-full transition-all ${n.enabled?"left-[18px]":"left-0.5"}`})})]}),t&&(e==null?void 0:e.type)==="wechat"&&c&&a.jsxs("button",{onClick:c,className:"w-full flex items-center justify-center gap-2 text-sm bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 px-3 py-2.5 rounded-lg transition-colors",children:[a.jsx(Be,{className:"w-4 h-4"})," ",u("channels.qrLoginReauth")]})]}),a.jsxs("div",{className:"flex items-center justify-between px-5 py-3 bg-dark-bg/50 border-t border-dark-border",children:[a.jsx("div",{children:t&&o&&a.jsxs("button",{onClick:o,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-red-400 hover:bg-red-500/10 transition-colors",children:[a.jsx(pt,{className:"w-3.5 h-3.5"})," ",u("channels.actions.delete")]})}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{onClick:l,className:"px-4 py-2 text-sm text-dark-muted hover:text-dark-text transition-colors",children:u("channels.actions.cancel")}),a.jsxs("button",{onClick:r,disabled:s||!n.name.trim(),className:"flex items-center gap-1.5 px-4 py-2 text-sm bg-accent-blue hover:bg-accent-blue/90 text-white rounded-lg disabled:opacity-50 transition-colors",children:[a.jsx(Et,{className:"w-3.5 h-3.5"}),u(s?"channels.saving":"channels.save")]})]})]})]})}function _e({label:n,required:i,children:s}){return a.jsxs("div",{children:[a.jsxs("label",{className:"block text-xs text-dark-muted mb-1.5",children:[n,i&&a.jsx("span",{className:"text-red-400 ml-0.5",children:"*"})]}),s]})}const Q="w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm text-dark-text placeholder-dark-muted/60 focus:outline-none focus:border-accent-blue transition-colors";var V={},ae,De;function qt(){return De||(De=1,ae=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),ae}var oe={},_={},Ue;function U(){if(Ue)return _;Ue=1;let n;const i=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return _.getSymbolSize=function(t){if(!t)throw new Error('"version" cannot be null or undefined');if(t<1||t>40)throw new Error('"version" should be in range from 1 to 40');return t*4+17},_.getSymbolTotalCodewords=function(t){return i[t]},_.getBCHDigit=function(s){let t=0;for(;s!==0;)t++,s>>>=1;return t},_.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');n=t},_.isKanjiModeEnabled=function(){return typeof n<"u"},_.toSJIS=function(t){return n(t)},_}var le={},Fe;function Me(){return Fe||(Fe=1,(function(n){n.L={bit:1},n.M={bit:0},n.Q={bit:3},n.H={bit:2};function i(s){if(typeof s!="string")throw new Error("Param is not a string");switch(s.toLowerCase()){case"l":case"low":return n.L;case"m":case"medium":return n.M;case"q":case"quartile":return n.Q;case"h":case"high":return n.H;default:throw new Error("Unknown EC Level: "+s)}}n.isValid=function(t){return t&&typeof t.bit<"u"&&t.bit>=0&&t.bit<4},n.from=function(t,e){if(n.isValid(t))return t;try{return i(t)}catch{return e}}})(le)),le}var ce,Ke;function _t(){if(Ke)return ce;Ke=1;function n(){this.buffer=[],this.length=0}return n.prototype={get:function(i){const s=Math.floor(i/8);return(this.buffer[s]>>>7-i%8&1)===1},put:function(i,s){for(let t=0;t<s;t++)this.putBit((i>>>s-t-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(i){const s=Math.floor(this.length/8);this.buffer.length<=s&&this.buffer.push(0),i&&(this.buffer[s]|=128>>>this.length%8),this.length++}},ce=n,ce}var de,ze;function Dt(){if(ze)return de;ze=1;function n(i){if(!i||i<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=i,this.data=new Uint8Array(i*i),this.reservedBit=new Uint8Array(i*i)}return n.prototype.set=function(i,s,t,e){const r=i*this.size+s;this.data[r]=t,e&&(this.reservedBit[r]=!0)},n.prototype.get=function(i,s){return this.data[i*this.size+s]},n.prototype.xor=function(i,s,t){this.data[i*this.size+s]^=t},n.prototype.isReserved=function(i,s){return this.reservedBit[i*this.size+s]},de=n,de}var ue={},Ve;function Ut(){return Ve||(Ve=1,(function(n){const i=U().getSymbolSize;n.getRowColCoords=function(t){if(t===1)return[];const e=Math.floor(t/7)+2,r=i(t),l=r===145?26:Math.ceil((r-13)/(2*e-2))*2,o=[r-7];for(let c=1;c<e-1;c++)o[c]=o[c-1]-l;return o.push(6),o.reverse()},n.getPositions=function(t){const e=[],r=n.getRowColCoords(t),l=r.length;for(let o=0;o<l;o++)for(let c=0;c<l;c++)o===0&&c===0||o===0&&c===l-1||o===l-1&&c===0||e.push([r[o],r[c]]);return e}})(ue)),ue}var he={},He;function Ft(){if(He)return he;He=1;const n=U().getSymbolSize,i=7;return he.getPositions=function(t){const e=n(t);return[[0,0],[e-i,0],[0,e-i]]},he}var fe={},Oe;function Kt(){return Oe||(Oe=1,(function(n){n.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const i={N1:3,N2:3,N3:40,N4:10};n.isValid=function(e){return e!=null&&e!==""&&!isNaN(e)&&e>=0&&e<=7},n.from=function(e){return n.isValid(e)?parseInt(e,10):void 0},n.getPenaltyN1=function(e){const r=e.size;let l=0,o=0,c=0,u=null,d=null;for(let m=0;m<r;m++){o=c=0,u=d=null;for(let f=0;f<r;f++){let h=e.get(m,f);h===u?o++:(o>=5&&(l+=i.N1+(o-5)),u=h,o=1),h=e.get(f,m),h===d?c++:(c>=5&&(l+=i.N1+(c-5)),d=h,c=1)}o>=5&&(l+=i.N1+(o-5)),c>=5&&(l+=i.N1+(c-5))}return l},n.getPenaltyN2=function(e){const r=e.size;let l=0;for(let o=0;o<r-1;o++)for(let c=0;c<r-1;c++){const u=e.get(o,c)+e.get(o,c+1)+e.get(o+1,c)+e.get(o+1,c+1);(u===4||u===0)&&l++}return l*i.N2},n.getPenaltyN3=function(e){const r=e.size;let l=0,o=0,c=0;for(let u=0;u<r;u++){o=c=0;for(let d=0;d<r;d++)o=o<<1&2047|e.get(u,d),d>=10&&(o===1488||o===93)&&l++,c=c<<1&2047|e.get(d,u),d>=10&&(c===1488||c===93)&&l++}return l*i.N3},n.getPenaltyN4=function(e){let r=0;const l=e.data.length;for(let c=0;c<l;c++)r+=e.data[c];return Math.abs(Math.ceil(r*100/l/5)-10)*i.N4};function s(t,e,r){switch(t){case n.Patterns.PATTERN000:return(e+r)%2===0;case n.Patterns.PATTERN001:return e%2===0;case n.Patterns.PATTERN010:return r%3===0;case n.Patterns.PATTERN011:return(e+r)%3===0;case n.Patterns.PATTERN100:return(Math.floor(e/2)+Math.floor(r/3))%2===0;case n.Patterns.PATTERN101:return e*r%2+e*r%3===0;case n.Patterns.PATTERN110:return(e*r%2+e*r%3)%2===0;case n.Patterns.PATTERN111:return(e*r%3+(e+r)%2)%2===0;default:throw new Error("bad maskPattern:"+t)}}n.applyMask=function(e,r){const l=r.size;for(let o=0;o<l;o++)for(let c=0;c<l;c++)r.isReserved(c,o)||r.xor(c,o,s(e,c,o))},n.getBestMask=function(e,r){const l=Object.keys(n.Patterns).length;let o=0,c=1/0;for(let u=0;u<l;u++){r(u),n.applyMask(u,e);const d=n.getPenaltyN1(e)+n.getPenaltyN2(e)+n.getPenaltyN3(e)+n.getPenaltyN4(e);n.applyMask(u,e),d<c&&(c=d,o=u)}return o}})(fe)),fe}var X={},Qe;function bt(){if(Qe)return X;Qe=1;const n=Me(),i=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],s=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return X.getBlocksCount=function(e,r){switch(r){case n.L:return i[(e-1)*4+0];case n.M:return i[(e-1)*4+1];case n.Q:return i[(e-1)*4+2];case n.H:return i[(e-1)*4+3];default:return}},X.getTotalCodewordsCount=function(e,r){switch(r){case n.L:return s[(e-1)*4+0];case n.M:return s[(e-1)*4+1];case n.Q:return s[(e-1)*4+2];case n.H:return s[(e-1)*4+3];default:return}},X}var ge={},J={},Je;function zt(){if(Je)return J;Je=1;const n=new Uint8Array(512),i=new Uint8Array(256);return(function(){let t=1;for(let e=0;e<255;e++)n[e]=t,i[t]=e,t<<=1,t&256&&(t^=285);for(let e=255;e<512;e++)n[e]=n[e-255]})(),J.log=function(t){if(t<1)throw new Error("log("+t+")");return i[t]},J.exp=function(t){return n[t]},J.mul=function(t,e){return t===0||e===0?0:n[i[t]+i[e]]},J}var Ye;function Vt(){return Ye||(Ye=1,(function(n){const i=zt();n.mul=function(t,e){const r=new Uint8Array(t.length+e.length-1);for(let l=0;l<t.length;l++)for(let o=0;o<e.length;o++)r[l+o]^=i.mul(t[l],e[o]);return r},n.mod=function(t,e){let r=new Uint8Array(t);for(;r.length-e.length>=0;){const l=r[0];for(let c=0;c<e.length;c++)r[c]^=i.mul(e[c],l);let o=0;for(;o<r.length&&r[o]===0;)o++;r=r.slice(o)}return r},n.generateECPolynomial=function(t){let e=new Uint8Array([1]);for(let r=0;r<t;r++)e=n.mul(e,new Uint8Array([1,i.exp(r)]));return e}})(ge)),ge}var me,$e;function Ht(){if($e)return me;$e=1;const n=Vt();function i(s){this.genPoly=void 0,this.degree=s,this.degree&&this.initialize(this.degree)}return i.prototype.initialize=function(t){this.degree=t,this.genPoly=n.generateECPolynomial(this.degree)},i.prototype.encode=function(t){if(!this.genPoly)throw new Error("Encoder not initialized");const e=new Uint8Array(t.length+this.degree);e.set(t);const r=n.mod(e,this.genPoly),l=this.degree-r.length;if(l>0){const o=new Uint8Array(this.degree);return o.set(r,l),o}return r},me=i,me}var xe={},pe={},be={},Ge;function wt(){return Ge||(Ge=1,be.isValid=function(i){return!isNaN(i)&&i>=1&&i<=40}),be}var P={},We;function yt(){if(We)return P;We=1;const n="[0-9]+",i="[A-Z $%*+\\-./:]+";let s="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";s=s.replace(/u/g,"\\u");const t="(?:(?![A-Z0-9 $%*+\\-./:]|"+s+`)(?:.|[\r
2
+ ]))+`;P.KANJI=new RegExp(s,"g"),P.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),P.BYTE=new RegExp(t,"g"),P.NUMERIC=new RegExp(n,"g"),P.ALPHANUMERIC=new RegExp(i,"g");const e=new RegExp("^"+s+"$"),r=new RegExp("^"+n+"$"),l=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return P.testKanji=function(c){return e.test(c)},P.testNumeric=function(c){return r.test(c)},P.testAlphanumeric=function(c){return l.test(c)},P}var Xe;function F(){return Xe||(Xe=1,(function(n){const i=wt(),s=yt();n.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},n.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},n.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},n.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},n.MIXED={bit:-1},n.getCharCountIndicator=function(r,l){if(!r.ccBits)throw new Error("Invalid mode: "+r);if(!i.isValid(l))throw new Error("Invalid version: "+l);return l>=1&&l<10?r.ccBits[0]:l<27?r.ccBits[1]:r.ccBits[2]},n.getBestModeForData=function(r){return s.testNumeric(r)?n.NUMERIC:s.testAlphanumeric(r)?n.ALPHANUMERIC:s.testKanji(r)?n.KANJI:n.BYTE},n.toString=function(r){if(r&&r.id)return r.id;throw new Error("Invalid mode")},n.isValid=function(r){return r&&r.bit&&r.ccBits};function t(e){if(typeof e!="string")throw new Error("Param is not a string");switch(e.toLowerCase()){case"numeric":return n.NUMERIC;case"alphanumeric":return n.ALPHANUMERIC;case"kanji":return n.KANJI;case"byte":return n.BYTE;default:throw new Error("Unknown mode: "+e)}}n.from=function(r,l){if(n.isValid(r))return r;try{return t(r)}catch{return l}}})(pe)),pe}var Ze;function Ot(){return Ze||(Ze=1,(function(n){const i=U(),s=bt(),t=Me(),e=F(),r=wt(),l=7973,o=i.getBCHDigit(l);function c(f,h,w){for(let S=1;S<=40;S++)if(h<=n.getCapacity(S,w,f))return S}function u(f,h){return e.getCharCountIndicator(f,h)+4}function d(f,h){let w=0;return f.forEach(function(S){const M=u(S.mode,h);w+=M+S.getBitsLength()}),w}function m(f,h){for(let w=1;w<=40;w++)if(d(f,w)<=n.getCapacity(w,h,e.MIXED))return w}n.from=function(h,w){return r.isValid(h)?parseInt(h,10):w},n.getCapacity=function(h,w,S){if(!r.isValid(h))throw new Error("Invalid QR Code version");typeof S>"u"&&(S=e.BYTE);const M=i.getSymbolTotalCodewords(h),y=s.getTotalCodewordsCount(h,w),R=(M-y)*8;if(S===e.MIXED)return R;const E=R-u(S,h);switch(S){case e.NUMERIC:return Math.floor(E/10*3);case e.ALPHANUMERIC:return Math.floor(E/11*2);case e.KANJI:return Math.floor(E/13);case e.BYTE:default:return Math.floor(E/8)}},n.getBestVersionForData=function(h,w){let S;const M=t.from(w,t.M);if(Array.isArray(h)){if(h.length>1)return m(h,M);if(h.length===0)return 1;S=h[0]}else S=h;return c(S.mode,S.getLength(),M)},n.getEncodedBits=function(h){if(!r.isValid(h)||h<7)throw new Error("Invalid QR Code version");let w=h<<12;for(;i.getBCHDigit(w)-o>=0;)w^=l<<i.getBCHDigit(w)-o;return h<<12|w}})(xe)),xe}var we={},et;function Qt(){if(et)return we;et=1;const n=U(),i=1335,s=21522,t=n.getBCHDigit(i);return we.getEncodedBits=function(r,l){const o=r.bit<<3|l;let c=o<<10;for(;n.getBCHDigit(c)-t>=0;)c^=i<<n.getBCHDigit(c)-t;return(o<<10|c)^s},we}var ye={},Ne,tt;function Jt(){if(tt)return Ne;tt=1;const n=F();function i(s){this.mode=n.NUMERIC,this.data=s.toString()}return i.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(t){let e,r,l;for(e=0;e+3<=this.data.length;e+=3)r=this.data.substr(e,3),l=parseInt(r,10),t.put(l,10);const o=this.data.length-e;o>0&&(r=this.data.substr(e),l=parseInt(r,10),t.put(l,o*3+1))},Ne=i,Ne}var Ce,nt;function Yt(){if(nt)return Ce;nt=1;const n=F(),i=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function s(t){this.mode=n.ALPHANUMERIC,this.data=t}return s.getBitsLength=function(e){return 11*Math.floor(e/2)+6*(e%2)},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(e){let r;for(r=0;r+2<=this.data.length;r+=2){let l=i.indexOf(this.data[r])*45;l+=i.indexOf(this.data[r+1]),e.put(l,11)}this.data.length%2&&e.put(i.indexOf(this.data[r]),6)},Ce=s,Ce}var ke,rt;function $t(){if(rt)return ke;rt=1;const n=F();function i(s){this.mode=n.BYTE,typeof s=="string"?this.data=new TextEncoder().encode(s):this.data=new Uint8Array(s)}return i.getBitsLength=function(t){return t*8},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(s){for(let t=0,e=this.data.length;t<e;t++)s.put(this.data[t],8)},ke=i,ke}var je,st;function Gt(){if(st)return je;st=1;const n=F(),i=U();function s(t){this.mode=n.KANJI,this.data=t}return s.getBitsLength=function(e){return e*13},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(t){let e;for(e=0;e<this.data.length;e++){let r=i.toSJIS(this.data[e]);if(r>=33088&&r<=40956)r-=33088;else if(r>=57408&&r<=60351)r-=49472;else throw new Error("Invalid SJIS character: "+this.data[e]+`
3
+ Make sure your charset is UTF-8`);r=(r>>>8&255)*192+(r&255),t.put(r,13)}},je=s,je}var ve={exports:{}},it;function Wt(){return it||(it=1,(function(n){var i={single_source_shortest_paths:function(s,t,e){var r={},l={};l[t]=0;var o=i.PriorityQueue.make();o.push(t,0);for(var c,u,d,m,f,h,w,S,M;!o.empty();){c=o.pop(),u=c.value,m=c.cost,f=s[u]||{};for(d in f)f.hasOwnProperty(d)&&(h=f[d],w=m+h,S=l[d],M=typeof l[d]>"u",(M||S>w)&&(l[d]=w,o.push(d,w),r[d]=u))}if(typeof e<"u"&&typeof l[e]>"u"){var y=["Could not find a path from ",t," to ",e,"."].join("");throw new Error(y)}return r},extract_shortest_path_from_predecessor_list:function(s,t){for(var e=[],r=t;r;)e.push(r),s[r],r=s[r];return e.reverse(),e},find_path:function(s,t,e){var r=i.single_source_shortest_paths(s,t,e);return i.extract_shortest_path_from_predecessor_list(r,e)},PriorityQueue:{make:function(s){var t=i.PriorityQueue,e={},r;s=s||{};for(r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e.queue=[],e.sorter=s.sorter||t.default_sorter,e},default_sorter:function(s,t){return s.cost-t.cost},push:function(s,t){var e={value:s,cost:t};this.queue.push(e),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};n.exports=i})(ve)),ve.exports}var at;function Xt(){return at||(at=1,(function(n){const i=F(),s=Jt(),t=Yt(),e=$t(),r=Gt(),l=yt(),o=U(),c=Wt();function u(y){return unescape(encodeURIComponent(y)).length}function d(y,R,E){const C=[];let k;for(;(k=y.exec(E))!==null;)C.push({data:k[0],index:k.index,mode:R,length:k[0].length});return C}function m(y){const R=d(l.NUMERIC,i.NUMERIC,y),E=d(l.ALPHANUMERIC,i.ALPHANUMERIC,y);let C,k;return o.isKanjiModeEnabled()?(C=d(l.BYTE,i.BYTE,y),k=d(l.KANJI,i.KANJI,y)):(C=d(l.BYTE_KANJI,i.BYTE,y),k=[]),R.concat(E,C,k).sort(function(p,N){return p.index-N.index}).map(function(p){return{data:p.data,mode:p.mode,length:p.length}})}function f(y,R){switch(R){case i.NUMERIC:return s.getBitsLength(y);case i.ALPHANUMERIC:return t.getBitsLength(y);case i.KANJI:return r.getBitsLength(y);case i.BYTE:return e.getBitsLength(y)}}function h(y){return y.reduce(function(R,E){const C=R.length-1>=0?R[R.length-1]:null;return C&&C.mode===E.mode?(R[R.length-1].data+=E.data,R):(R.push(E),R)},[])}function w(y){const R=[];for(let E=0;E<y.length;E++){const C=y[E];switch(C.mode){case i.NUMERIC:R.push([C,{data:C.data,mode:i.ALPHANUMERIC,length:C.length},{data:C.data,mode:i.BYTE,length:C.length}]);break;case i.ALPHANUMERIC:R.push([C,{data:C.data,mode:i.BYTE,length:C.length}]);break;case i.KANJI:R.push([C,{data:C.data,mode:i.BYTE,length:u(C.data)}]);break;case i.BYTE:R.push([{data:C.data,mode:i.BYTE,length:u(C.data)}])}}return R}function S(y,R){const E={},C={start:{}};let k=["start"];for(let x=0;x<y.length;x++){const p=y[x],N=[];for(let b=0;b<p.length;b++){const B=p[b],j=""+x+b;N.push(j),E[j]={node:B,lastCount:0},C[j]={};for(let v=0;v<k.length;v++){const g=k[v];E[g]&&E[g].node.mode===B.mode?(C[g][j]=f(E[g].lastCount+B.length,B.mode)-f(E[g].lastCount,B.mode),E[g].lastCount+=B.length):(E[g]&&(E[g].lastCount=B.length),C[g][j]=f(B.length,B.mode)+4+i.getCharCountIndicator(B.mode,R))}}k=N}for(let x=0;x<k.length;x++)C[k[x]].end=0;return{map:C,table:E}}function M(y,R){let E;const C=i.getBestModeForData(y);if(E=i.from(R,C),E!==i.BYTE&&E.bit<C.bit)throw new Error('"'+y+'" cannot be encoded with mode '+i.toString(E)+`.
4
+ Suggested mode is: `+i.toString(C));switch(E===i.KANJI&&!o.isKanjiModeEnabled()&&(E=i.BYTE),E){case i.NUMERIC:return new s(y);case i.ALPHANUMERIC:return new t(y);case i.KANJI:return new r(y);case i.BYTE:return new e(y)}}n.fromArray=function(R){return R.reduce(function(E,C){return typeof C=="string"?E.push(M(C,null)):C.data&&E.push(M(C.data,C.mode)),E},[])},n.fromString=function(R,E){const C=m(R,o.isKanjiModeEnabled()),k=w(C),x=S(k,E),p=c.find_path(x.map,"start","end"),N=[];for(let b=1;b<p.length-1;b++)N.push(x.table[p[b]].node);return n.fromArray(h(N))},n.rawSplit=function(R){return n.fromArray(m(R,o.isKanjiModeEnabled()))}})(ye)),ye}var ot;function Zt(){if(ot)return oe;ot=1;const n=U(),i=Me(),s=_t(),t=Dt(),e=Ut(),r=Ft(),l=Kt(),o=bt(),c=Ht(),u=Ot(),d=Qt(),m=F(),f=Xt();function h(x,p){const N=x.size,b=r.getPositions(p);for(let B=0;B<b.length;B++){const j=b[B][0],v=b[B][1];for(let g=-1;g<=7;g++)if(!(j+g<=-1||N<=j+g))for(let T=-1;T<=7;T++)v+T<=-1||N<=v+T||(g>=0&&g<=6&&(T===0||T===6)||T>=0&&T<=6&&(g===0||g===6)||g>=2&&g<=4&&T>=2&&T<=4?x.set(j+g,v+T,!0,!0):x.set(j+g,v+T,!1,!0))}}function w(x){const p=x.size;for(let N=8;N<p-8;N++){const b=N%2===0;x.set(N,6,b,!0),x.set(6,N,b,!0)}}function S(x,p){const N=e.getPositions(p);for(let b=0;b<N.length;b++){const B=N[b][0],j=N[b][1];for(let v=-2;v<=2;v++)for(let g=-2;g<=2;g++)v===-2||v===2||g===-2||g===2||v===0&&g===0?x.set(B+v,j+g,!0,!0):x.set(B+v,j+g,!1,!0)}}function M(x,p){const N=x.size,b=u.getEncodedBits(p);let B,j,v;for(let g=0;g<18;g++)B=Math.floor(g/3),j=g%3+N-8-3,v=(b>>g&1)===1,x.set(B,j,v,!0),x.set(j,B,v,!0)}function y(x,p,N){const b=x.size,B=d.getEncodedBits(p,N);let j,v;for(j=0;j<15;j++)v=(B>>j&1)===1,j<6?x.set(j,8,v,!0):j<8?x.set(j+1,8,v,!0):x.set(b-15+j,8,v,!0),j<8?x.set(8,b-j-1,v,!0):j<9?x.set(8,15-j-1+1,v,!0):x.set(8,15-j-1,v,!0);x.set(b-8,8,1,!0)}function R(x,p){const N=x.size;let b=-1,B=N-1,j=7,v=0;for(let g=N-1;g>0;g-=2)for(g===6&&g--;;){for(let T=0;T<2;T++)if(!x.isReserved(B,g-T)){let I=!1;v<p.length&&(I=(p[v]>>>j&1)===1),x.set(B,g-T,I),j--,j===-1&&(v++,j=7)}if(B+=b,B<0||N<=B){B-=b,b=-b;break}}}function E(x,p,N){const b=new s;N.forEach(function(T){b.put(T.mode.bit,4),b.put(T.getLength(),m.getCharCountIndicator(T.mode,x)),T.write(b)});const B=n.getSymbolTotalCodewords(x),j=o.getTotalCodewordsCount(x,p),v=(B-j)*8;for(b.getLengthInBits()+4<=v&&b.put(0,4);b.getLengthInBits()%8!==0;)b.putBit(0);const g=(v-b.getLengthInBits())/8;for(let T=0;T<g;T++)b.put(T%2?17:236,8);return C(b,x,p)}function C(x,p,N){const b=n.getSymbolTotalCodewords(p),B=o.getTotalCodewordsCount(p,N),j=b-B,v=o.getBlocksCount(p,N),g=b%v,T=v-g,I=Math.floor(b/v),O=Math.floor(j/v),Ct=O+1,Ae=I-O,kt=new c(Ae);let Z=0;const G=new Array(v),Ie=new Array(v);let ee=0;const jt=new Uint8Array(x.buffer);for(let K=0;K<v;K++){const ne=K<T?O:Ct;G[K]=jt.slice(Z,Z+ne),Ie[K]=kt.encode(G[K]),Z+=ne,ee=Math.max(ee,ne)}const te=new Uint8Array(b);let Pe=0,L,q;for(L=0;L<ee;L++)for(q=0;q<v;q++)L<G[q].length&&(te[Pe++]=G[q][L]);for(L=0;L<Ae;L++)for(q=0;q<v;q++)te[Pe++]=Ie[q][L];return te}function k(x,p,N,b){let B;if(Array.isArray(x))B=f.fromArray(x);else if(typeof x=="string"){let I=p;if(!I){const O=f.rawSplit(x);I=u.getBestVersionForData(O,N)}B=f.fromString(x,I||40)}else throw new Error("Invalid data");const j=u.getBestVersionForData(B,N);if(!j)throw new Error("The amount of data is too big to be stored in a QR Code");if(!p)p=j;else if(p<j)throw new Error(`
5
+ The chosen QR Code version cannot contain this amount of data.
6
+ Minimum version required to store current data is: `+j+`.
7
+ `);const v=E(p,N,B),g=n.getSymbolSize(p),T=new t(g);return h(T,p),w(T),S(T,p),y(T,N,0),p>=7&&M(T,p),R(T,v),isNaN(b)&&(b=l.getBestMask(T,y.bind(null,T,N))),l.applyMask(b,T),y(T,N,b),{modules:T,version:p,errorCorrectionLevel:N,maskPattern:b,segments:B}}return oe.create=function(p,N){if(typeof p>"u"||p==="")throw new Error("No input text");let b=i.M,B,j;return typeof N<"u"&&(b=i.from(N.errorCorrectionLevel,i.M),B=u.from(N.version),j=l.from(N.maskPattern),N.toSJISFunc&&n.setToSJISFunction(N.toSJISFunc)),k(p,B,b,j)},oe}var Ee={},Se={},lt;function Nt(){return lt||(lt=1,(function(n){function i(s){if(typeof s=="number"&&(s=s.toString()),typeof s!="string")throw new Error("Color should be defined as hex string");let t=s.slice().replace("#","").split("");if(t.length<3||t.length===5||t.length>8)throw new Error("Invalid hex color: "+s);(t.length===3||t.length===4)&&(t=Array.prototype.concat.apply([],t.map(function(r){return[r,r]}))),t.length===6&&t.push("F","F");const e=parseInt(t.join(""),16);return{r:e>>24&255,g:e>>16&255,b:e>>8&255,a:e&255,hex:"#"+t.slice(0,6).join("")}}n.getOptions=function(t){t||(t={}),t.color||(t.color={});const e=typeof t.margin>"u"||t.margin===null||t.margin<0?4:t.margin,r=t.width&&t.width>=21?t.width:void 0,l=t.scale||4;return{width:r,scale:r?4:l,margin:e,color:{dark:i(t.color.dark||"#000000ff"),light:i(t.color.light||"#ffffffff")},type:t.type,rendererOpts:t.rendererOpts||{}}},n.getScale=function(t,e){return e.width&&e.width>=t+e.margin*2?e.width/(t+e.margin*2):e.scale},n.getImageWidth=function(t,e){const r=n.getScale(t,e);return Math.floor((t+e.margin*2)*r)},n.qrToImageData=function(t,e,r){const l=e.modules.size,o=e.modules.data,c=n.getScale(l,r),u=Math.floor((l+r.margin*2)*c),d=r.margin*c,m=[r.color.light,r.color.dark];for(let f=0;f<u;f++)for(let h=0;h<u;h++){let w=(f*u+h)*4,S=r.color.light;if(f>=d&&h>=d&&f<u-d&&h<u-d){const M=Math.floor((f-d)/c),y=Math.floor((h-d)/c);S=m[o[M*l+y]?1:0]}t[w++]=S.r,t[w++]=S.g,t[w++]=S.b,t[w]=S.a}}})(Se)),Se}var ct;function en(){return ct||(ct=1,(function(n){const i=Nt();function s(e,r,l){e.clearRect(0,0,r.width,r.height),r.style||(r.style={}),r.height=l,r.width=l,r.style.height=l+"px",r.style.width=l+"px"}function t(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}n.render=function(r,l,o){let c=o,u=l;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),l||(u=t()),c=i.getOptions(c);const d=i.getImageWidth(r.modules.size,c),m=u.getContext("2d"),f=m.createImageData(d,d);return i.qrToImageData(f.data,r,c),s(m,u,d),m.putImageData(f,0,0),u},n.renderToDataURL=function(r,l,o){let c=o;typeof c>"u"&&(!l||!l.getContext)&&(c=l,l=void 0),c||(c={});const u=n.render(r,l,c),d=c.type||"image/png",m=c.rendererOpts||{};return u.toDataURL(d,m.quality)}})(Ee)),Ee}var Te={},dt;function tn(){if(dt)return Te;dt=1;const n=Nt();function i(e,r){const l=e.a/255,o=r+'="'+e.hex+'"';return l<1?o+" "+r+'-opacity="'+l.toFixed(2).slice(1)+'"':o}function s(e,r,l){let o=e+r;return typeof l<"u"&&(o+=" "+l),o}function t(e,r,l){let o="",c=0,u=!1,d=0;for(let m=0;m<e.length;m++){const f=Math.floor(m%r),h=Math.floor(m/r);!f&&!u&&(u=!0),e[m]?(d++,m>0&&f>0&&e[m-1]||(o+=u?s("M",f+l,.5+h+l):s("m",c,0),c=0,u=!1),f+1<r&&e[m+1]||(o+=s("h",d),d=0)):c++}return o}return Te.render=function(r,l,o){const c=n.getOptions(l),u=r.modules.size,d=r.modules.data,m=u+c.margin*2,f=c.color.light.a?"<path "+i(c.color.light,"fill")+' d="M0 0h'+m+"v"+m+'H0z"/>':"",h="<path "+i(c.color.dark,"stroke")+' d="'+t(d,u,c.margin)+'"/>',w='viewBox="0 0 '+m+" "+m+'"',M='<svg xmlns="http://www.w3.org/2000/svg" '+(c.width?'width="'+c.width+'" height="'+c.width+'" ':"")+w+' shape-rendering="crispEdges">'+f+h+`</svg>
8
+ `;return typeof o=="function"&&o(null,M),M},Te}var ut;function nn(){if(ut)return V;ut=1;const n=qt(),i=Zt(),s=en(),t=tn();function e(r,l,o,c,u){const d=[].slice.call(arguments,1),m=d.length,f=typeof d[m-1]=="function";if(!f&&!n())throw new Error("Callback required as last argument");if(f){if(m<2)throw new Error("Too few arguments provided");m===2?(u=o,o=l,l=c=void 0):m===3&&(l.getContext&&typeof u>"u"?(u=c,c=void 0):(u=c,c=o,o=l,l=void 0))}else{if(m<1)throw new Error("Too few arguments provided");return m===1?(o=l,l=c=void 0):m===2&&!l.getContext&&(c=o,o=l,l=void 0),new Promise(function(h,w){try{const S=i.create(o,c);h(r(S,l,c))}catch(S){w(S)}})}try{const h=i.create(o,c);u(null,r(h,l,c))}catch(h){u(h)}}return V.create=i.create,V.toCanvas=e.bind(null,s.render),V.toDataURL=e.bind(null,s.renderToDataURL),V.toString=e.bind(null,function(r,l,o){return t.render(r,o)}),V}var rn=nn();const sn=St(rn),an=2e3,ht=5;function on({channel:n,onClose:i}){const{t:s}=D(),[t,e]=A.useState("loading"),[r,l]=A.useState(null),[o,c]=A.useState(null),[u,d]=A.useState(""),m=A.useRef(null),f=A.useRef(0),h=A.useRef(null),w=A.useRef(!1),S=()=>{h.current&&(clearTimeout(h.current),h.current=null),w.current=!0},M=async k=>{if(m.current)try{await sn.toCanvas(m.current,k,{width:240,margin:2,color:{dark:"#000000ff",light:"#ffffffff"}})}catch(x){console.warn("[WechatQr] Canvas QR generation failed, falling back to URL:",x)}},y=async()=>{if(!(w.current||!o))try{const k=await Le.channels.weixin.bindStatus(o),x=(k==null?void 0:k.data)??k,p=(x==null?void 0:x.status)??"";if(f.current=0,p==="confirmed"){e("confirmed"),se.success(n?s("channels.toastReauthSuccess",{name:n.name}):s("channels.toastBindSuccess")),setTimeout(i,2400);return}if(p==="scaned")e("scanned");else if(p==="expired"){e("expired");return}w.current||(h.current=setTimeout(y,an))}catch(k){if(f.current++,console.warn("[WechatQr] poll error ("+f.current+"/"+ht+")",k),f.current>=ht)e("error"),d(s("channels.pollFailedRefresh")),se.error(s("channels.pollFailedToast"));else if(!w.current){const x=Math.min(1e3*Math.pow(2,f.current),1e4);h.current=setTimeout(y,x)}}},R=()=>{S(),w.current=!1,f.current=0,h.current=setTimeout(y,1e3)},E=async()=>{e("loading"),l(null),c(null),d(""),f.current=0;try{const k=await Le.channels.weixin.bind(),x=(k==null?void 0:k.data)??k,p=(x==null?void 0:x.qrcode_img_content)??"",N=(x==null?void 0:x.qrcode)??"";if(!p||!N){e("error"),d(s("channels.qrDataMissing",{data:JSON.stringify(x)}));return}l(p),c(N),await M(p),e("waiting")}catch(k){e("error");const x=String((k==null?void 0:k.message)??k);d(x),se.error(s("channels.fetchWechatQrFailed",{error:x}))}},C=()=>{E()};return A.useEffect(()=>(E(),S),[]),A.useEffect(()=>(o&&R(),S),[o]),a.jsx(Bt,{isOpen:!0,onClose:i,title:s("channels.bindTitle",{name:(n==null?void 0:n.name)??s("channels.typeLabels.wechat")}),size:"sm",children:a.jsxs("div",{className:"flex flex-col items-center gap-4 py-2",children:[a.jsxs("div",{className:"relative w-60 h-60 rounded-lg bg-white flex items-center justify-center overflow-hidden",children:[t==="loading"&&a.jsx("span",{className:"text-gray-400 text-sm",children:s("channels.qr.generating")}),t!=="error"&&t!=="expired"&&a.jsx("canvas",{ref:m,width:240,height:240,className:`w-full h-full object-contain ${t==="waiting"?"":"opacity-30"}`}),t==="scanned"&&a.jsxs("div",{className:"absolute inset-0 bg-black/70 flex flex-col items-center justify-center text-white gap-1",children:[a.jsx("span",{className:"text-2xl",children:"✓"}),a.jsx("span",{className:"text-sm",children:s("channels.qr.scanned")})]}),t==="confirmed"&&a.jsxs("div",{className:"absolute inset-0 bg-green-600/90 flex flex-col items-center justify-center text-white gap-2 px-4 text-center",children:[a.jsx("span",{className:"text-2xl",children:"🎉"}),a.jsx("span",{className:"text-sm font-medium",children:s("channels.bindSuccess")}),a.jsx("span",{className:"text-xs opacity-90",children:n?s("channels.connectedReady",{name:n.name}):s("channels.createdConnectedReady")}),a.jsx("button",{onClick:i,className:"mt-1 text-xs bg-white/20 hover:bg-white/30 px-3 py-1.5 rounded-md transition-colors",children:s("channels.startUsing")})]}),t==="expired"&&a.jsxs("div",{className:"absolute inset-0 bg-black/80 flex flex-col items-center justify-center text-white gap-2",children:[a.jsx("span",{className:"text-sm",children:s("channels.qr.expired")}),a.jsx("button",{onClick:C,className:"text-xs bg-green-600 hover:bg-green-500 px-3 py-1 rounded",children:s("channels.clickToRefresh")})]}),t==="error"&&a.jsxs("div",{className:"absolute inset-0 bg-black/80 flex flex-col items-center justify-center text-red-300 gap-2 px-4 text-center",children:[a.jsx("span",{className:"text-xs",children:u||s("channels.unknownError")}),a.jsx("button",{onClick:C,className:"text-xs bg-blue-600 hover:bg-blue-500 px-3 py-1 rounded text-white",children:s("channels.retry")})]})]}),a.jsxs("p",{className:"text-sm text-dark-muted text-center",children:[t==="waiting"&&s("channels.waitingAuthorize"),t==="scanned"&&s("channels.scannedConfirming"),t==="confirmed"&&s("channels.confirmedClosing"),t==="loading"&&s("channels.connectingIlink"),(t==="expired"||t==="error")&&(t==="expired"?s("channels.qr.expired"):"")]}),r&&t==="waiting"&&a.jsxs("button",{onClick:()=>window.open(r,"_blank","width=480,height=600,noopener"),className:"w-full flex items-center justify-center gap-2 text-sm bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 px-3 py-2.5 rounded-lg transition-colors",children:[a.jsx("span",{children:"🔔"})," ",s("channels.openInNewTabFallback")]})]})})}function gn(){const{t:n}=D(),{load:i,loading:s,qrOpen:t,qrChannel:e,closeQr:r}=Re();return A.useEffect(()=>{i()},[]),a.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-dark-bg text-dark-text",children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-dark-border shrink-0",children:[a.jsxs("div",{children:[a.jsx("h2",{className:"font-semibold text-base",children:n("channels.title")}),a.jsx("p",{className:"text-xs text-dark-muted mt-0.5",children:n("channels.viewSubtitle")})]}),a.jsx("div",{className:"flex items-center gap-2",children:a.jsx("button",{onClick:()=>i(),title:n("channels.actions.refresh"),className:"p-2 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:a.jsx(Tt,{className:`w-4 h-4 ${s?"animate-spin":""}`})})})]}),a.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[a.jsx("div",{className:"w-[260px] shrink-0",children:a.jsx(It,{})}),a.jsx("div",{className:"flex-1 min-w-0",children:a.jsx(Pt,{})})]}),t&&a.jsx(on,{channel:e,onClose:r})]})}export{gn as ChannelConfigView};
@@ -0,0 +1 @@
1
+ import{j as s}from"./markdown-yjmXQjrx.js";import{a as d,L as w,$ as A,aj as F,z as ae,h as ne,af as le,O as R,b6 as q,b9 as K,a1 as oe,aU as O,E as de,aq as ce,D as V,l as ie}from"./icons-qcawb7PZ.js";import{u as me,a as f}from"./index-DUpwXfa-.js";import"./react-vendor-CSlQceOk.js";import"./state-DOzZasIm.js";import"./panels-CX_dYEv0.js";const ue={"code-intelligence":"🧠 代码智能",filesystem:"📂 文件系统",databases:"🗄️ 数据库","browser-automation":"🌐 浏览器自动化","knowledge-memory":"🧠 知识/记忆","search-web":"🔎 搜索/网页","cloud-platforms":"☁️ 云平台",communication:"💬 通讯","developer-tools":"🛠️ 开发者工具",security:"🔒 安全","test-demo":"🧪 测试/Demo",other:"📦 其他"};function je(){const{t:r}=me(),[u,x]=d.useState([]),[D,C]=d.useState(!0),[E,S]=d.useState(null),[j,p]=d.useState({}),[z,m]=d.useState(null),[v,H]=d.useState(""),[b,$]=d.useState(null),[k,U]=d.useState("all"),[Y,g]=d.useState(null),[G,L]=d.useState({}),[M,N]=d.useState(!1),[l,i]=d.useState({name:"",command:"",args:"",env:"",transport:"stdio",url:"",headers:""}),Q=()=>i({name:"",command:"",args:"",env:"",transport:"stdio",url:"",headers:""}),T=e=>Object.fromEntries(e.split(",").map(t=>t.trim()).filter(Boolean).map(t=>{const n=t.indexOf("=");return n>0?[t.slice(0,n).trim(),t.slice(n+1).trim()]:[t,""]})),I=async()=>{const e=l.transport!=="stdio";if(!l.name.trim()||!e&&!l.command.trim()||e&&!l.url.trim()){m(r("connectors.customFormRequired"));return}p(t=>({...t,__add:!0})),m(null);try{const t=await f.connectors.addCustom({name:l.name.trim(),command:e?void 0:l.command.trim(),args:e?void 0:l.args.split(/\s+/).filter(Boolean),env:T(l.env),url:e?l.url.trim():void 0,transport:e?l.transport:void 0,headers:e?T(l.headers):void 0});t.success&&t.data?(x(n=>[...n,t.data]),N(!1),Q()):m(t.error||"添加失败")}catch(t){m(t instanceof Error?t.message:String(t))}finally{p(t=>({...t,__add:!1}))}},W=async e=>{p(t=>({...t,[e.id]:!0}));try{const t=await f.connectors.removeCustom(e.id);t.success?x(n=>n.filter(a=>a.id!==e.id)):m(t.error||"删除失败")}finally{p(t=>({...t,[e.id]:!1}))}},y=async()=>{var t;C(!0),S(null);const e=await f.connectors.list();e.success&&Array.isArray((t=e.data)==null?void 0:t.connectors)?x(e.data.connectors):S(e.error||"加载连接器失败"),C(!1)};d.useEffect(()=>{y()},[]);const B=(e,t,n,a)=>{m(n||null),x(o=>o.map(c=>c.id===e?{...c,enabled:!!a,status:"error"}:c))},P=async(e,t,n)=>{m(null),p(a=>({...a,[e.id]:!0})),x(a=>a.map(o=>o.id===e.id?{...o,enabled:t,status:t?"connecting":"installed"}:o));try{const a=await f.connectors.toggle(e.id,t,n);a.success&&a.data?x(o=>o.map(c=>c.id===e.id?a.data:c)):B(e.id,void 0,a.error||`切换 ${e.name} 失败`,!t)}catch(a){B(e.id,void 0,a instanceof Error?a.message:String(a),!t)}finally{p(a=>({...a,[e.id]:!1}))}},Z=e=>{var t,n;if(!e.enabled&&((t=e.requiresEnv)!=null&&t.length)&&((n=e.missingEnv)!=null&&n.length)){g(e.id);return}g(null),P(e,!e.enabled)},J=(e,t)=>{g(null),L(n=>({...n,[e.id]:{}})),P(e,!0,t)},X=e=>{const t="inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium";if(!e.installed)return s.jsxs("span",{className:`${t} bg-dark-hover text-dark-muted`,children:[s.jsx(V,{size:12}),r("connectors.notInstalled")]});switch(e.status){case"ready":return s.jsxs("span",{className:`${t} bg-accent-green/15 text-accent-green`,children:[s.jsx(ie,{size:12}),r("connectors.ready")]});case"connecting":return s.jsxs("span",{className:`${t} bg-accent-blue/15 text-accent-blue`,children:[s.jsx(w,{size:12,className:"animate-spin"}),r("connectors.connecting")]});case"error":return s.jsxs("span",{className:`${t} bg-accent-red/15 text-accent-red`,children:[s.jsx(A,{size:12}),r("connectors.error")]});case"disabled":return s.jsx("span",{className:`${t} bg-dark-hover text-dark-muted`,children:r("connectors.disabled")});default:return s.jsx("span",{className:`${t} bg-dark-hover text-dark-muted`,children:r("connectors.installed")})}},h=u.filter(e=>k==="all"||e.kind===k),_=h.filter(e=>{if(v){const t=v.toLowerCase();if(![e.name,e.id,e.description,e.category??"",e.kind,...e.languages??[]].join(" ").toLowerCase().includes(t))return!1}return!(b&&e.category!==b)}).sort((e,t)=>e.enabled!==t.enabled?e.enabled?-1:1:e.name.localeCompare(t.name)),ee=[...new Set(h.map(e=>e.category).filter(Boolean))];if(D)return s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(w,{size:32,className:"animate-spin mx-auto mb-2 text-accent-blue"}),s.jsx("p",{className:"text-dark-muted",children:r("common.loading")})]})});if(E)return s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(A,{size:32,className:"mx-auto mb-2 text-accent-red"}),s.jsx("p",{className:"text-accent-red mb-4",children:E}),s.jsx("button",{onClick:()=>void y(),className:"px-4 py-2 bg-accent-blue text-white rounded-lg",children:r("common.retry")})]})});const se=e=>{const t=G[e.id]??{},n=(a,o)=>L(c=>({...c,[e.id]:{...c[e.id]??{},[a]:o}}));return s.jsxs("div",{className:"mt-3 pt-3 border-t border-dark-border",children:[s.jsxs("div",{className:"text-xs text-dark-muted mb-2 flex items-center gap-1",children:[s.jsx(O,{size:12}),r("connectors.needCredentials")]}),s.jsx("div",{className:"space-y-2",children:(e.requiresEnv??[]).map(a=>s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:a.label}),s.jsx("input",{type:a.secret?"password":"text",value:t[a.key]??"",onChange:o=>n(a.key,o.target.value),placeholder:a.key,className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]},a.key))}),s.jsxs("div",{className:"flex gap-2 mt-2",children:[s.jsx("button",{onClick:()=>void J(e,t),className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm",children:r("connectors.connect")}),s.jsx("button",{onClick:()=>g(null),className:"px-3 py-1.5 bg-dark-surface border border-dark-border rounded-lg text-sm",children:r("common.cancel")})]})]})},te=e=>{var a,o,c;const t=!!j[e.id],n=Y===e.id;return s.jsxs("div",{className:`bg-dark-surface border border-dark-border rounded-lg p-4 transition-opacity ${e.enabled?"":"opacity-80"}`,children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[s.jsx("span",{className:`mt-0.5 shrink-0 px-2 py-1 rounded-md text-[11px] font-semibold uppercase ${e.kind==="lsp"?"bg-accent-purple/15 text-accent-purple":"bg-accent-green/15 text-accent-green"}`,children:e.kind==="lsp"?"LSP":"MCP"}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("span",{className:"font-medium text-sm truncate",children:e.name}),e.custom?s.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-purple/15 text-accent-purple",children:r("connectors.custom")}):null,e.official?s.jsxs("span",{title:"Official",className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-yellow/15 text-accent-yellow",children:["🎖️ ",r("connectors.official")]}):null,e.scope==="cloud"?s.jsxs("span",{title:"Cloud",className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/15 text-accent-blue",children:[s.jsx(q,{size:9}),r("connectors.cloud")]}):s.jsxs("span",{title:"Local",className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted",children:[s.jsx(K,{size:9}),r("connectors.local")]}),e.language?s.jsx("span",{className:"text-[10px]",children:e.language}):null,X(e)]}),s.jsx("p",{className:"text-xs text-dark-muted mt-1 line-clamp-2",children:e.description}),s.jsxs("div",{className:"flex items-center gap-3 mt-2 text-[11px] text-dark-muted flex-wrap",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(K,{size:11}),s.jsx("code",{className:"text-[10px]",children:e.installHint})]}),e.transport&&e.transport!=="stdio"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-accent-blue",children:[s.jsx(q,{size:11}),e.transport==="sse"?"SSE":"Streamable HTTP"]}):null,(a=e.languages)!=null&&a.length?s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(oe,{size:11}),e.languages.join(", ")]}):null,e.kind==="mcp"&&e.toolCount!==void 0?s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(F,{size:11}),r("connectors.toolCount",{count:e.toolCount})]}):null,(o=e.requiresEnv)!=null&&o.length?s.jsxs("span",{className:"inline-flex items-center gap-1 text-accent-yellow",children:[s.jsx(O,{size:11}),(c=e.missingEnv)!=null&&c.length?`${e.missingEnv.join(", ")} ${r("connectors.missing")}`:r("connectors.envConfigured")]}):null,e.docsUrl?s.jsxs("a",{href:e.docsUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 hover:text-accent-blue",onClick:re=>re.stopPropagation(),children:[s.jsx(de,{size:11}),r("connectors.docs")]}):null]}),e.error?s.jsx("p",{className:"text-[11px] text-accent-red mt-1",children:e.error}):null]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.custom?s.jsx("button",{onClick:()=>void W(e),disabled:t,title:r("connectors.removeCustom"),className:"p-1.5 rounded-lg text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors disabled:opacity-40",children:s.jsx(ce,{size:14})}):null,!e.installed&&e.enabled?s.jsxs("span",{className:"text-[11px] text-accent-blue flex items-center gap-1",children:[s.jsx(V,{size:11,className:"animate-pulse"}),r("connectors.installing")]}):null,s.jsx("button",{role:"switch","aria-checked":e.enabled,disabled:t,onClick:()=>Z(e),className:`relative w-12 h-6 rounded-full transition-colors disabled:opacity-50 ${e.enabled?"bg-accent-green":"bg-dark-border"}`,children:s.jsx("span",{className:`absolute top-1 w-4 h-4 bg-white rounded-full transition-transform ${e.enabled?"left-7":"left-1"}`})})]})]}),n?se(e):null]},e.id)};return s.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[s.jsx(F,{size:20}),r("nav.connectors"),s.jsxs("span",{className:"text-sm font-normal text-dark-muted",children:["· ",u.filter(e=>e.enabled).length,"/",u.length]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("button",{onClick:()=>N(e=>!e),className:"flex items-center gap-2 px-3 py-1.5 bg-accent-blue text-white rounded hover:bg-accent-blue/90 transition-colors",children:[s.jsx(ae,{size:14}),r("connectors.addCustom")]}),s.jsxs("button",{onClick:()=>void y(),className:"flex items-center gap-2 px-3 py-1.5 bg-dark-surface border border-dark-border rounded hover:bg-dark-hover transition-colors",children:[s.jsx(ne,{size:14}),r("common.refresh")]})]})]}),M?s.jsxs("div",{className:"mb-4 p-4 bg-dark-surface border border-dark-border rounded-lg",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[s.jsx(le,{size:15,className:"text-accent-purple"}),r("connectors.customTitle")]}),s.jsx("div",{className:"flex gap-1",children:[["stdio","🖥️ "+r("connectors.customLocal")],["http","🌐 HTTP"],["sse","📡 SSE"]].map(([e,t])=>s.jsx("button",{onClick:()=>i(n=>({...n,transport:e})),className:`px-3 py-1.5 rounded-lg text-xs transition-colors ${l.transport===e?"bg-accent-blue text-white":"bg-dark-bg border border-dark-border hover:bg-dark-hover"}`,children:t},e))})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customName")}),s.jsx("input",{value:l.name,onChange:e=>i(t=>({...t,name:e.target.value})),placeholder:"my-server",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),l.transport==="stdio"?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customCommand")}),s.jsx("input",{value:l.command,onChange:e=>i(t=>({...t,command:e.target.value})),placeholder:"npx -y @some/mcp-server",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customArgs")}),s.jsx("input",{value:l.args,onChange:e=>i(t=>({...t,args:e.target.value})),placeholder:"--arg value",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customUrl")}),s.jsx("input",{value:l.url,onChange:e=>i(t=>({...t,url:e.target.value})),placeholder:"https://mcp.example.com/mcp",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),l.transport==="stdio"?s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customEnv")}),s.jsx("input",{value:l.env,onChange:e=>i(t=>({...t,env:e.target.value})),placeholder:"KEY=value, KEY2=value2",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customHeaders")}),s.jsx("input",{value:l.headers,onChange:e=>i(t=>({...t,headers:e.target.value})),placeholder:"Authorization=Bearer xxx",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})]}),s.jsxs("div",{className:"flex gap-2 mt-3",children:[s.jsx("button",{onClick:()=>void I(),disabled:!!j.__add,className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm disabled:opacity-50",children:j.__add?s.jsx(w,{size:14,className:"animate-spin"}):r("connectors.add")}),s.jsx("button",{onClick:()=>N(!1),className:"px-3 py-1.5 bg-dark-surface border border-dark-border rounded-lg text-sm",children:r("common.cancel")})]})]}):null,s.jsx("div",{className:"flex gap-1 mb-3",children:[["all",`${r("connectors.all")} (${u.length})`],["lsp",`LSP (${u.filter(e=>e.kind==="lsp").length})`],["mcp",`MCP (${u.filter(e=>e.kind==="mcp").length})`]].map(([e,t])=>s.jsx("button",{onClick:()=>U(e),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${k===e?"bg-accent-blue text-white":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:t},e))}),s.jsx("div",{className:"flex gap-3 mb-3",children:s.jsxs("div",{className:"flex-1 relative",children:[s.jsx(R,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),s.jsx("input",{type:"text",value:v,onChange:e=>H(e.target.value),placeholder:r("connectors.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-dark-surface border border-dark-border rounded-lg text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})}),s.jsxs("div",{className:"flex gap-1 mb-4 flex-wrap",children:[s.jsxs("button",{onClick:()=>$(null),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${b?"bg-dark-surface border border-dark-border hover:bg-dark-hover":"bg-accent-blue text-white"}`,children:[r("connectors.all")," ",s.jsxs("span",{className:"opacity-70 text-xs",children:["(",h.length,")"]})]}),ee.map(e=>{const t=h.filter(n=>n.category===e).length;return s.jsxs("button",{onClick:()=>$(b===e?null:e),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${b===e?"bg-accent-blue text-white":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:[ue[e]??e," ",s.jsxs("span",{className:"opacity-70 text-xs",children:["(",t,")"]})]},e)})]}),z?s.jsx("div",{className:"mb-4 px-3 py-2 bg-accent-red/10 border border-accent-red/30 rounded-lg text-accent-red text-sm",children:z}):null,s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:_.length===0?s.jsxs("div",{className:"text-center text-dark-muted text-sm py-10",children:[s.jsx(R,{size:24,className:"mx-auto mb-2 opacity-50"}),r("connectors.noResults")]}):s.jsx("div",{className:"space-y-2",children:_.map(te)})})]})}export{je as ConnectorsView};
@@ -0,0 +1,11 @@
1
+ import{j as l}from"./markdown-yjmXQjrx.js";import{a as s,W as Q,ad as Ce,aE as Me,h as Ne,aM as Te,O as ke,u as le,a8 as Pe,D as ue,X as Ee,d as Re,K as Fe,aN as Le}from"./icons-qcawb7PZ.js";import{u as ze,a as B,t as F}from"./index-DUpwXfa-.js";import"./react-vendor-CSlQceOk.js";import"./state-DOzZasIm.js";import"./panels-CX_dYEv0.js";function de(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Ae(e){if(Array.isArray(e))return e}function De(e,t,r){return(t=We(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function $e(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n,o,u,p,v=[],g=!0,j=!1;try{if(u=(r=r.call(e)).next,t!==0)for(;!(g=(n=u.call(r)).done)&&(v.push(n.value),v.length!==t);g=!0);}catch(N){j=!0,o=N}finally{try{if(!g&&r.return!=null&&(p=r.return(),Object(p)!==p))return}finally{if(j)throw o}}return v}}function Ie(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
2
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function fe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),r.push.apply(r,n)}return r}function pe(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?fe(Object(r),!0).forEach(function(n){De(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):fe(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Ve(e,t){if(e==null)return{};var r,n,o=Ue(e,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)===-1&&{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function Ue(e,t){if(e==null)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.indexOf(n)!==-1)continue;r[n]=e[n]}return r}function He(e,t){return Ae(e)||$e(e,t)||Be(e,t)||Ie()}function qe(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function We(e){var t=qe(e,"string");return typeof t=="symbol"?t:t+""}function Be(e,t){if(e){if(typeof e=="string")return de(e,t);var r={}.toString.call(e).slice(8,-1);return r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set"?Array.from(e):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?de(e,t):void 0}}function Ke(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function he(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),r.push.apply(r,n)}return r}function me(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?he(Object(r),!0).forEach(function(n){Ke(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):he(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Qe(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(n){return t.reduceRight(function(o,u){return u(o)},n)}}function J(e){return function t(){for(var r=this,n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];return o.length>=e.length?e.apply(this,o):function(){for(var p=arguments.length,v=new Array(p),g=0;g<p;g++)v[g]=arguments[g];return t.apply(r,[].concat(o,v))}}}function ne(e){return{}.toString.call(e).includes("Object")}function Ge(e){return!Object.keys(e).length}function Y(e){return typeof e=="function"}function Je(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Xe(e,t){return ne(t)||A("changeType"),Object.keys(t).some(function(r){return!Je(e,r)})&&A("changeField"),t}function Ye(e){Y(e)||A("selectorType")}function _e(e){Y(e)||ne(e)||A("handlerType"),ne(e)&&Object.values(e).some(function(t){return!Y(t)})&&A("handlersType")}function Ze(e){e||A("initialIsRequired"),ne(e)||A("initialType"),Ge(e)&&A("initialContent")}function et(e,t){throw new Error(e[t]||e.default)}var tt={initialIsRequired:"initial state is required",initialType:"initial state should be an object",initialContent:"initial state shouldn't be an empty object",handlerType:"handler should be an object or a function",handlersType:"all handlers should be a functions",selectorType:"selector should be a function",changeType:"provided value of changes should be an object",changeField:'it seams you want to change a field in the state which is not specified in the "initial" state',default:"an unknown error accured in `state-local` package"},A=J(et)(tt),te={changes:Xe,selector:Ye,handler:_e,initial:Ze};function rt(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};te.initial(e),te.handler(t);var r={current:e},n=J(it)(r,t),o=J(at)(r),u=J(te.changes)(e),p=J(nt)(r);function v(){var j=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(N){return N};return te.selector(j),j(r.current)}function g(j){Qe(n,o,u,p)(j)}return[v,g]}function nt(e,t){return Y(t)?t(e.current):t}function at(e,t){return e.current=me(me({},e.current),t),t}function it(e,t,r){return Y(t)?t(e.current):Object.keys(r).forEach(function(n){var o;return(o=t[n])===null||o===void 0?void 0:o.call(t,e.current[n])}),r}var ot={create:rt},st={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function ct(e){return function t(){for(var r=this,n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];return o.length>=e.length?e.apply(this,o):function(){for(var p=arguments.length,v=new Array(p),g=0;g<p;g++)v[g]=arguments[g];return t.apply(r,[].concat(o,v))}}}function lt(e){return{}.toString.call(e).includes("Object")}function ut(e){return e||ge("configIsRequired"),lt(e)||ge("configType"),e.urls?(dt(),{paths:{vs:e.urls.monacoBase}}):e}function dt(){console.warn(ve.deprecation)}function ft(e,t){throw new Error(e[t]||e.default)}var ve={configIsRequired:"the configuration object is required",configType:"the configuration object should be an object",default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
3
+ You are using deprecated way of configuration.
4
+
5
+ Instead of using
6
+ monaco.config({ urls: { monacoBase: '...' } })
7
+ use
8
+ monaco.config({ paths: { vs: '...' } })
9
+
10
+ For more please check the link https://github.com/suren-atoyan/monaco-loader#config
11
+ `},ge=ct(ft)(ve),pt={config:ut},ht=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return function(o){return r.reduceRight(function(u,p){return p(u)},o)}};function be(e,t){return Object.keys(t).forEach(function(r){t[r]instanceof Object&&e[r]&&Object.assign(t[r],be(e[r],t[r]))}),pe(pe({},e),t)}var mt={type:"cancelation",msg:"operation is manually canceled"};function oe(e){var t=!1,r=new Promise(function(n,o){e.then(function(u){return t?o(mt):n(u)}),e.catch(o)});return r.cancel=function(){return t=!0},r}var gt=["monaco"],vt=ot.create({config:st,isInitialized:!1,resolve:null,reject:null,monaco:null}),ye=He(vt,2),_=ye[0],ae=ye[1];function bt(e){var t=pt.config(e),r=t.monaco,n=Ve(t,gt);ae(function(o){return{config:be(o.config,n),monaco:r}})}function yt(){var e=_(function(t){var r=t.monaco,n=t.isInitialized,o=t.resolve;return{monaco:r,isInitialized:n,resolve:o}});if(!e.isInitialized){if(ae({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),oe(se);if(window.monaco&&window.monaco.editor)return xe(window.monaco),e.resolve(window.monaco),oe(se);ht(xt,wt)(Ot)}return oe(se)}function xt(e){return document.body.appendChild(e)}function jt(e){var t=document.createElement("script");return e&&(t.src=e),t}function wt(e){var t=_(function(n){var o=n.config,u=n.reject;return{config:o,reject:u}}),r=jt("".concat(t.config.paths.vs,"/loader.js"));return r.onload=function(){return e()},r.onerror=t.reject,r}function Ot(){var e=_(function(r){var n=r.config,o=r.resolve,u=r.reject;return{config:n,resolve:o,reject:u}}),t=window.require;t.config(e.config),t(["vs/editor/editor.main"],function(r){var n=r.m||r;xe(n),e.resolve(n)},function(r){e.reject(r)})}function xe(e){_().monaco||ae({monaco:e})}function St(){return _(function(e){var t=e.monaco;return t})}var se=new Promise(function(e,t){return ae({resolve:e,reject:t})}),je={config:bt,init:yt,__getMonacoInstance:St},Ct={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},ce=Ct,Mt={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},Nt=Mt;function Tt({children:e}){return Q.createElement("div",{style:Nt.container},e)}var kt=Tt,Pt=kt;function Et({width:e,height:t,isEditorReady:r,loading:n,_ref:o,className:u,wrapperProps:p}){return Q.createElement("section",{style:{...ce.wrapper,width:e,height:t},...p},!r&&Q.createElement(Pt,null,n),Q.createElement("div",{ref:o,style:{...ce.fullWidth,...!r&&ce.hide},className:u}))}var Rt=Et,we=s.memo(Rt);function Ft(e){s.useEffect(e,[])}var Oe=Ft;function Lt(e,t,r=!0){let n=s.useRef(!0);s.useEffect(n.current||!r?()=>{n.current=!1}:e,t)}var M=Lt;function X(){}function K(e,t,r,n){return zt(e,n)||At(e,t,r,n)}function zt(e,t){return e.editor.getModel(Se(e,t))}function At(e,t,r,n){return e.editor.createModel(t,r,n?Se(e,n):void 0)}function Se(e,t){return e.Uri.parse(t)}function Dt({original:e,modified:t,language:r,originalLanguage:n,modifiedLanguage:o,originalModelPath:u,modifiedModelPath:p,keepCurrentOriginalModel:v=!1,keepCurrentModifiedModel:g=!1,theme:j="light",loading:N="Loading...",options:C={},height:G="100%",width:I="100%",className:V,wrapperProps:U={},beforeMount:H=X,onMount:q=X}){let[w,T]=s.useState(!1),[E,y]=s.useState(!0),x=s.useRef(null),b=s.useRef(null),L=s.useRef(null),O=s.useRef(q),h=s.useRef(H),R=s.useRef(!1);Oe(()=>{let d=je.init();return d.then(m=>(b.current=m)&&y(!1)).catch(m=>(m==null?void 0:m.type)!=="cancelation"&&console.error("Monaco initialization: error:",m)),()=>x.current?$():d.cancel()}),M(()=>{if(x.current&&b.current){let d=x.current.getOriginalEditor(),m=K(b.current,e||"",n||r||"text",u||"");m!==d.getModel()&&d.setModel(m)}},[u],w),M(()=>{if(x.current&&b.current){let d=x.current.getModifiedEditor(),m=K(b.current,t||"",o||r||"text",p||"");m!==d.getModel()&&d.setModel(m)}},[p],w),M(()=>{let d=x.current.getModifiedEditor();d.getOption(b.current.editor.EditorOption.readOnly)?d.setValue(t||""):t!==d.getValue()&&(d.executeEdits("",[{range:d.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),d.pushUndoStop())},[t],w),M(()=>{var d,m;(m=(d=x.current)==null?void 0:d.getModel())==null||m.original.setValue(e||"")},[e],w),M(()=>{let{original:d,modified:m}=x.current.getModel();b.current.editor.setModelLanguage(d,n||r||"text"),b.current.editor.setModelLanguage(m,o||r||"text")},[r,n,o],w),M(()=>{var d;(d=b.current)==null||d.editor.setTheme(j)},[j],w),M(()=>{var d;(d=x.current)==null||d.updateOptions(C)},[C],w);let D=s.useCallback(()=>{var k;if(!b.current)return;h.current(b.current);let d=K(b.current,e||"",n||r||"text",u||""),m=K(b.current,t||"",o||r||"text",p||"");(k=x.current)==null||k.setModel({original:d,modified:m})},[r,t,o,e,n,u,p]),W=s.useCallback(()=>{var d;!R.current&&L.current&&(x.current=b.current.editor.createDiffEditor(L.current,{automaticLayout:!0,...C}),D(),(d=b.current)==null||d.editor.setTheme(j),T(!0),R.current=!0)},[C,j,D]);s.useEffect(()=>{w&&O.current(x.current,b.current)},[w]),s.useEffect(()=>{!E&&!w&&W()},[E,w,W]);function $(){var m,k,P,z;let d=(m=x.current)==null?void 0:m.getModel();v||((k=d==null?void 0:d.original)==null||k.dispose()),g||((P=d==null?void 0:d.modified)==null||P.dispose()),(z=x.current)==null||z.dispose()}return Q.createElement(we,{width:I,height:G,isEditorReady:w,loading:N,_ref:L,className:V,wrapperProps:U})}var $t=Dt;s.memo($t);function It(e){let t=s.useRef();return s.useEffect(()=>{t.current=e},[e]),t.current}var Vt=It,re=new Map;function Ut({defaultValue:e,defaultLanguage:t,defaultPath:r,value:n,language:o,path:u,theme:p="light",line:v,loading:g="Loading...",options:j={},overrideServices:N={},saveViewState:C=!0,keepCurrentModel:G=!1,width:I="100%",height:V="100%",className:U,wrapperProps:H={},beforeMount:q=X,onMount:w=X,onChange:T,onValidate:E=X}){let[y,x]=s.useState(!1),[b,L]=s.useState(!0),O=s.useRef(null),h=s.useRef(null),R=s.useRef(null),D=s.useRef(w),W=s.useRef(q),$=s.useRef(),d=s.useRef(n),m=Vt(u),k=s.useRef(!1),P=s.useRef(!1);Oe(()=>{let a=je.init();return a.then(i=>(O.current=i)&&L(!1)).catch(i=>(i==null?void 0:i.type)!=="cancelation"&&console.error("Monaco initialization: error:",i)),()=>h.current?ie():a.cancel()}),M(()=>{var i,c,f,S;let a=K(O.current,e||n||"",t||o||"",u||r||"");a!==((i=h.current)==null?void 0:i.getModel())&&(C&&re.set(m,(c=h.current)==null?void 0:c.saveViewState()),(f=h.current)==null||f.setModel(a),C&&((S=h.current)==null||S.restoreViewState(re.get(u))))},[u],y),M(()=>{var a;(a=h.current)==null||a.updateOptions(j)},[j],y),M(()=>{!h.current||n===void 0||(h.current.getOption(O.current.editor.EditorOption.readOnly)?h.current.setValue(n):n!==h.current.getValue()&&(P.current=!0,h.current.executeEdits("",[{range:h.current.getModel().getFullModelRange(),text:n,forceMoveMarkers:!0}]),h.current.pushUndoStop(),P.current=!1))},[n],y),M(()=>{var i,c;let a=(i=h.current)==null?void 0:i.getModel();a&&o&&((c=O.current)==null||c.editor.setModelLanguage(a,o))},[o],y),M(()=>{var a;v!==void 0&&((a=h.current)==null||a.revealLine(v))},[v],y),M(()=>{var a;(a=O.current)==null||a.editor.setTheme(p)},[p],y);let z=s.useCallback(()=>{var a;if(!(!R.current||!O.current)&&!k.current){W.current(O.current);let i=u||r,c=K(O.current,n||e||"",t||o||"",i||"");h.current=(a=O.current)==null?void 0:a.editor.create(R.current,{model:c,automaticLayout:!0,...j},N),C&&h.current.restoreViewState(re.get(i)),O.current.editor.setTheme(p),v!==void 0&&h.current.revealLine(v),x(!0),k.current=!0}},[e,t,r,n,o,u,j,N,C,p,v]);s.useEffect(()=>{y&&D.current(h.current,O.current)},[y]),s.useEffect(()=>{!b&&!y&&z()},[b,y,z]),d.current=n,s.useEffect(()=>{var a,i;y&&T&&((a=$.current)==null||a.dispose(),$.current=(i=h.current)==null?void 0:i.onDidChangeModelContent(c=>{P.current||T(h.current.getValue(),c)}))},[y,T]),s.useEffect(()=>{if(y){let a=O.current.editor.onDidChangeMarkers(i=>{var f;let c=(f=h.current.getModel())==null?void 0:f.uri;if(c&&i.find(S=>S.path===c.path)){let S=O.current.editor.getModelMarkers({resource:c});E==null||E(S)}});return()=>{a==null||a.dispose()}}return()=>{}},[y,E]);function ie(){var a,i;(a=$.current)==null||a.dispose(),G?C&&re.set(u,h.current.saveViewState()):(i=h.current.getModel())==null||i.dispose(),h.current.dispose()}return Q.createElement(we,{width:I,height:V,isEditorReady:y,loading:g,_ref:R,className:U,wrapperProps:H})}var Ht=Ut,qt=s.memo(Ht),Wt=qt;function Bt(e){var n;const t=(n=e.split(".").pop())==null?void 0:n.toLowerCase();return{ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",json:"json",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",yaml:"yaml",yml:"yaml",toml:"toml",sql:"sql",sh:"shell",bat:"bat",ps1:"powershell",dockerfile:"dockerfile",properties:"properties",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",vue:"html",svelte:"html",svg:"xml"}[t||""]||"plaintext"}function _t(){const{t:e}=ze(),[t,r]=s.useState([]),[n,o]=s.useState(null),[u,p]=s.useState(""),[v,g]=s.useState(""),[j,N]=s.useState(!1),[C,G]=s.useState(""),[I,V]=s.useState(!1),[U,H]=s.useState(!1),[q,w]=s.useState(!1),[T,E]=s.useState(""),y=s.useRef(null);s.useEffect(()=>{if(!n){p(""),g("");return}N(!0),B.files.read(n).then(a=>{if(a.success&&a.data){const i=typeof a.data=="string"?a.data:JSON.stringify(a.data);p(i),g(i)}else F.error(a.error||e("fileTree.readFail"))}).catch(()=>F.error(e("fileTree.readFail"))).finally(()=>N(!1))},[n]);const x=async a=>{V(!0);try{const i=await B.files.list(a);i.success&&Array.isArray(i.data)&&r(i.data.map(c=>({...c,expanded:!1})))}finally{V(!1)}},b=async a=>{if(a.type==="directory")try{const i=await B.files.list(a.path);if(i.success&&Array.isArray(i.data)){const c=i.data.map(f=>({...f,expanded:!1}));r(f=>L(f,a.id,c))}}catch{}},L=(a,i,c)=>a.map(f=>f.id===i?{...f,children:c,expanded:!0}:f.children?{...f,children:L(f.children,i,c)}:f);s.useEffect(()=>{x()},[]);const O=a=>{const i=R(t,a);if(i&&i.type==="directory"&&!i.children){b(i);return}r(c=>h(c,a))},h=(a,i)=>a.map(c=>c.id===i&&c.type==="directory"?{...c,expanded:!c.expanded}:c.children?{...c,children:h(c.children,i)}:c),R=(a,i)=>{for(const c of a){if(c.id===i)return c;if(c.children){const f=R(c.children,i);if(f)return f}}return null},D=(a,i)=>i?a.reduce((c,f)=>{if(f.name.toLowerCase().includes(i.toLowerCase()))c.push(f);else if(f.children){const S=D(f.children,i);S.length>0&&c.push({...f,children:S,expanded:!0})}return c},[]):a,W=s.useCallback(async()=>{if(n){H(!0);try{const a=await B.files.update(n,u);a.success?(g(u),F.success(e("fileTree.saved"))):F.error(a.error||e("fileTree.saveFail"))}catch{F.error(e("fileTree.saveFail"))}finally{H(!1)}}},[n,u,e]),$=()=>{o(null),p(""),g("")},d=s.useCallback(async a=>{const i=await B.files.download(a);i.success?F.success(e("fileTree.downloadStarted")):F.error(i.error||e("fileTree.downloadFail"))},[e]),m=()=>{var a;return(a=y.current)==null?void 0:a.click()},k=s.useCallback(async a=>{if(!a||a.length===0)return;const i=T||(n?n.replace(/[\\/][^\\/]+$/,""):"");w(!0);let c=0,f=0;for(const S of Array.from(a)){const Z=i?`${i}/${S.name}`:S.name;(await B.files.upload(S,Z)).success?c++:f++}w(!1),c>0&&F.success(e("fileTree.uploadedCount",{count:c})),f>0&&F.error(e("fileTree.uploadFailedCount",{count:f})),await x()},[T,n,e]),P=u!==v,z=(a,i=0)=>{var Z;const c=a.type==="directory",f=n===a.path,S=T===a.path;return l.jsxs("div",{children:[l.jsxs("div",{className:`group flex items-center gap-1 px-2 py-0.5 cursor-pointer rounded text-xs transition-colors ${f?"bg-accent-blue/20 text-accent-blue":S?"bg-accent-blue/10":"hover:bg-dark-hover"}`,style:{paddingLeft:`${i*14+6}px`},onClick:()=>c?(E(a.path),O(a.id)):o(a.path),title:c?e("fileTree.setUploadDirHint"):a.path,children:[c&&l.jsx("span",{className:"text-dark-muted shrink-0",children:a.expanded?l.jsx(Re,{size:12}):l.jsx(Fe,{size:12})}),c?l.jsx(Le,{size:12,className:"text-accent-yellow shrink-0"}):l.jsx("span",{className:"w-3"}),l.jsx("span",{className:"truncate flex-1",children:a.name}),!c&&l.jsx("button",{onClick:ee=>{ee.stopPropagation(),d(a.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 rounded hover:bg-dark-border text-dark-muted hover:text-dark-text shrink-0",title:e("fileTree.download"),children:l.jsx(ue,{size:11})})]}),c&&a.expanded&&((Z=a.children)==null?void 0:Z.map(ee=>z(ee,i+1)))]},a.id)},ie=C?D(t,C):t;return l.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[l.jsxs("div",{className:"w-64 shrink-0 flex flex-col overflow-hidden border-r border-dark-border",children:[l.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-dark-border",children:[l.jsxs("h2",{className:"text-xs font-semibold flex items-center gap-1.5",children:[l.jsx(Ce,{size:14}),e("fileTree.title")]}),l.jsxs("div",{className:"flex items-center gap-0.5",children:[l.jsx("button",{onClick:m,disabled:q,className:"p-1 rounded hover:bg-dark-hover disabled:opacity-50",title:T?e("fileTree.uploadTo",{dir:T}):e("fileTree.uploadToRoot"),children:l.jsx(Me,{size:12,className:q?"animate-pulse":""})}),l.jsx("button",{onClick:()=>x(),disabled:I,className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.refresh"),children:l.jsx(Ne,{size:12,className:I?"animate-spin":""})}),l.jsx("button",{onClick:()=>{r(t.map(a=>({...a,expanded:!1}))),o(null)},className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.collapse"),children:l.jsx(Te,{size:12})})]})]}),l.jsx("div",{className:"p-1.5 border-b border-dark-border",children:l.jsxs("div",{className:"relative",children:[l.jsx(ke,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),l.jsx("input",{type:"text",value:C,onChange:a=>G(a.target.value),placeholder:e("fileTree.searchPlaceholder"),className:"w-full pl-6 pr-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:border-accent-blue focus:outline-none"})]})}),l.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar py-1",children:ie.map(a=>z(a))}),l.jsx("input",{ref:y,type:"file",multiple:!0,className:"hidden",onChange:a=>{k(a.target.files),a.currentTarget.value=""}})]}),l.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-dark-bg",children:n?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-dark-border bg-dark-surface",children:[l.jsxs("div",{className:"flex items-center gap-2 text-xs min-w-0",children:[l.jsx(le,{size:12,className:"text-dark-muted shrink-0"}),l.jsx("span",{className:"truncate",children:n}),P&&l.jsxs("span",{className:"text-accent-yellow text-[10px] shrink-0",children:["● ",e("fileTree.modified")]})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs("button",{onClick:W,disabled:!P||U,className:`px-2 py-0.5 text-[10px] rounded flex items-center gap-1 transition-colors ${P?"bg-accent-green text-white hover:opacity-90":"bg-dark-border text-dark-muted cursor-not-allowed"}`,children:[l.jsx(Pe,{size:10}),e(U?"fileTree.saving":"fileTree.save")]}),l.jsx("button",{onClick:()=>void d(n),className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.download"),children:l.jsx(ue,{size:12})}),l.jsx("button",{onClick:$,className:"p-1 rounded hover:bg-dark-hover",title:e("fileTree.close"),children:l.jsx(Ee,{size:12})})]})]}),l.jsx("div",{className:"flex-1 min-h-0",children:j?l.jsx("div",{className:"flex items-center justify-center h-full",children:l.jsx("div",{className:"w-4 h-4 border-2 border-accent-blue border-t-transparent rounded-full animate-spin"})}):l.jsx(Wt,{language:Bt(n),value:u,onChange:a=>p(a||""),theme:"vs-dark",options:{fontSize:13,fontFamily:'"Cascadia Code", "Fira Code", Consolas, monospace',minimap:{enabled:!1},lineNumbers:"on",scrollBeyondLastLine:!1,wordWrap:"on",automaticLayout:!0,tabSize:2}})})]}):l.jsx("div",{className:"flex-1 flex items-center justify-center",children:l.jsxs("div",{className:"text-center",children:[l.jsx(le,{size:32,className:"text-dark-muted mx-auto mb-2"}),l.jsx("p",{className:"text-sm text-dark-muted",children:e("fileTree.selectFileHint")})]})})})]})}export{_t as FileTreeView,_t as default};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-yjmXQjrx.js";import{a as y,aJ as L,S as D,aK as Y,aq as B,X as z,f as G,y as J,K as W,aL as _,ay as q,az as K,h as V,aE as X,D as Q,z as Z}from"./icons-qcawb7PZ.js";import{c as ee}from"./state-DOzZasIm.js";import{a as j,u as E}from"./index-DUpwXfa-.js";import"./react-vendor-CSlQceOk.js";import"./panels-CX_dYEv0.js";const P=ee((l,d)=>({rules:[],stats:null,events:[],agents:[],loading:!1,error:null,fieldErrors:null,formOpen:!1,editingRule:null,dryRunResult:null,loadRules:async()=>{const t=await j.hooks.list();t.success&&Array.isArray(t.data)?l({rules:t.data}):t.success&&t.data&&!Array.isArray(t.data)?l({error:"服务端返回的规则数据格式异常"}):l({error:t.error||"Failed to load rules"})},loadStats:async()=>{const t=await j.hooks.stats();t.success&&t.data&&l({stats:t.data})},loadEvents:async()=>{const t=await j.hooks.events();t.success&&Array.isArray(t.data)?l({events:t.data}):t.success&&t.data&&!Array.isArray(t.data)&&l({error:"服务端返回的事件数据格式异常"})},loadAgents:async()=>{const t=await j.hooks.agents();t.success&&Array.isArray(t.data)?l({agents:t.data}):t.success&&t.data&&!Array.isArray(t.data)&&l({error:"服务端返回的Agent数据格式异常"})},loadAll:async()=>{l({loading:!0,error:null});try{await Promise.all([d().loadRules(),d().loadStats(),d().loadEvents(),d().loadAgents()])}catch(t){l({error:String(t)})}finally{l({loading:!1})}},createRule:async t=>{l({fieldErrors:null});const r=await j.hooks.create(t);if(r.success)return await d().loadRules(),await d().loadStats(),l({formOpen:!1,editingRule:null}),!0;if(r.error){l({error:r.error});try{const c=JSON.parse(r.error);c.fieldErrors&&l({fieldErrors:c.fieldErrors})}catch{}}return!1},updateRule:async(t,r)=>{l({fieldErrors:null});const c=await j.hooks.update(t,r);return c.success?(await d().loadRules(),l({formOpen:!1,editingRule:null}),!0):(l({error:c.error||"Update failed"}),!1)},deleteRule:async t=>{const r=await j.hooks.delete(t);return r.success?(await d().loadRules(),await d().loadStats(),!0):(l({error:r.error||"Delete failed"}),!1)},batchDelete:async t=>{const r=await j.hooks.batchDelete(t);return r.success?(await d().loadRules(),await d().loadStats(),!0):(l({error:r.error||"Batch delete failed"}),!1)},toggleRule:async(t,r)=>(await j.hooks.toggle(t,r)).success?(l(x=>({rules:x.rules.map(p=>p.name===t?{...p,enabled:r}:p)})),!0):(await d().loadRules(),!1),batchToggle:async(t,r)=>(await j.hooks.batchToggle(t,r)).success?(l(x=>({rules:x.rules.map(p=>t.includes(p.name)?{...p,enabled:r}:p)})),!0):(await d().loadRules(),!1),dryRun:async t=>{const r=await j.hooks.dryRun(t);return r.success&&r.data?(l({dryRunResult:r.data}),r.data):(l({error:r.error||"Dry-run failed"}),null)},openForm:t=>l({formOpen:!0,editingRule:t||null,dryRunResult:null,fieldErrors:null}),closeForm:()=>l({formOpen:!1,editingRule:null,dryRunResult:null,fieldErrors:null}),setDryRunResult:t=>l({dryRunResult:t}),clearError:()=>l({error:null}),clearFieldErrors:()=>l({fieldErrors:null})})),te={SYSTEM:"bg-accent-red/15 text-accent-red",SECURITY:"bg-accent-orange/15 text-accent-orange",PROJECT:"bg-accent-blue/15 text-accent-blue",USER:"bg-accent-green/15 text-accent-green",PLUGIN:"bg-accent-purple/15 text-accent-purple"},ae={SHELL:"bg-accent-yellow/15 text-accent-yellow",HTTP:"bg-accent-cyan/15 text-accent-cyan",PROMPT:"bg-accent-purple/15 text-accent-purple",AGENT:"bg-accent-blue/15 text-accent-blue"};function se({rules:l,onEdit:d}){const{t}=E(),{toggleRule:r,deleteRule:c,batchDelete:x,batchToggle:p}=P(),[k,b]=y.useState(new Set),[R,v]=y.useState(!1),T=Array.isArray(l)?l:[];if(T.length===0)return e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 py-16 text-dark-muted",children:[e.jsx("div",{className:"text-4xl opacity-60",children:"🪝"}),e.jsx("p",{className:"text-sm",children:t("hook.noRules")}),e.jsx("p",{className:"text-xs text-dark-muted/70",children:t("hook.noRulesHint")})]});const C=n=>{const s=new Set(k);s.has(n)?s.delete(n):s.add(n),b(s),v(s.size===T.length)},h=()=>{R?(b(new Set),v(!1)):(b(new Set(T.map(n=>n.name))),v(!0))},w=()=>{k.size!==0&&confirm(t("hook.batchDeleteConfirm",{n:k.size}))&&(x(Array.from(k)),b(new Set),v(!1))},m=n=>{k.size!==0&&(p(Array.from(k),n),b(new Set),v(!1))};return e.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[k.size>0&&e.jsxs("div",{className:"mb-2 flex items-center gap-2 rounded-lg border border-accent-blue/30 bg-accent-blue/5 px-3 py-1.5 text-sm",children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.selectedItems",{n:k.size})}),e.jsx("button",{onClick:()=>m(!0),className:"rounded bg-accent-green/15 px-2 py-0.5 text-accent-green transition-colors hover:bg-accent-green/25",children:t("hook.enableAll")}),e.jsx("button",{onClick:()=>m(!1),className:"rounded bg-dark-hover px-2 py-0.5 text-dark-text transition-colors hover:bg-dark-border",children:t("hook.disableAll")}),e.jsx("button",{onClick:w,className:"rounded bg-accent-red/15 px-2 py-0.5 text-accent-red transition-colors hover:bg-accent-red/25",children:t("common.delete")})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar rounded-xl border border-dark-border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-dark-hover text-dark-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"w-8 p-2.5",children:e.jsx("button",{onClick:h,children:R?e.jsx(L,{size:14}):e.jsx(D,{size:14})})}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colName")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colEvents")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colType")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.fieldPriority")}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:t("hook.colStatus")}),e.jsx("th",{className:"p-2.5 text-right font-medium",children:t("hook.colActions")})]})}),e.jsx("tbody",{className:"divide-y divide-dark-border",children:T.map(n=>e.jsxs("tr",{className:"transition-colors hover:bg-dark-hover/50",children:[e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>C(n.name),children:k.has(n.name)?e.jsx(L,{size:14,className:"text-accent-blue"}):e.jsx(D,{size:14,className:"text-dark-muted"})})}),e.jsxs("td",{className:"p-2.5",children:[e.jsx("div",{className:"font-medium text-dark-text",children:n.name}),n.description&&e.jsx("div",{className:"mt-0.5 max-w-[220px] truncate text-xs text-dark-muted",children:n.description})]}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[Array.isArray(n.events)&&n.events.slice(0,3).map(s=>e.jsx("span",{className:"rounded bg-dark-hover px-1.5 py-0.5 text-xs text-dark-text",children:s},s)),Array.isArray(n.events)&&n.events.length>3&&e.jsxs("span",{className:"px-1 py-0.5 text-xs text-dark-muted",children:["+",n.events.length-3]})]})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${ae[n.implementationType]||"bg-dark-hover text-dark-muted"}`,children:n.implementationType})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${te[n.priority]||"bg-dark-hover text-dark-muted"}`,children:n.priority})}),e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>r(n.name,!n.enabled),className:`relative h-5 w-9 rounded-full transition-colors ${n.enabled?"bg-accent-green":"bg-dark-border"}`,title:n.enabled?t("hook.clickToDisable"):t("hook.clickToEnable"),children:e.jsx("span",{className:`absolute top-0.5 block h-3.5 w-3.5 rounded-full bg-white transition-all ${n.enabled?"left-[18px]":"left-[2px]"}`})})}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{onClick:()=>d(n),className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue",title:t("hook.actionEdit"),children:e.jsx(Y,{size:14})}),e.jsx("button",{onClick:()=>{confirm(t("hook.deleteRuleConfirm",{name:n.name}))&&c(n.name)},className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red",title:t("common.delete"),children:e.jsx(B,{size:14})})]})})]},n.name))})]})})]})}const re={name:"",description:"",events:[],implementationType:"SHELL",command:"",url:"",promptTemplate:"",agentName:"",priority:"USER",tools:[],matcherToolNamePattern:"",matcherFromState:"",matcherToState:"",timeoutMs:3e4,enabled:!0,failOpen:!0,scope:"project"},le=[{value:"SYSTEM",label:"SYSTEM (100)"},{value:"SECURITY",label:"SECURITY (80)"},{value:"PROJECT",label:"PROJECT (60)"},{value:"USER",label:"USER (40)"},{value:"PLUGIN",label:"PLUGIN (20)"}],g=l=>`w-full rounded-lg border bg-dark-bg px-3 py-2 text-sm text-dark-text placeholder-dark-muted/60 transition-colors focus:outline-none focus:ring-2 ${l?"border-accent-red focus:border-accent-red focus:ring-accent-red/20":"border-dark-border focus:border-accent-blue focus:ring-accent-blue/20"}`,f="mb-1 block text-xs font-medium text-dark-muted";function ne({events:l,agents:d}){const{t}=E(),{editingRule:r,fieldErrors:c,dryRunResult:x,createRule:p,updateRule:k,closeForm:b,dryRun:R,setDryRunResult:v,clearFieldErrors:T}=P(),C=[{value:"SHELL",label:t("hook.implShell"),desc:t("hook.implShellDesc")},{value:"HTTP",label:t("hook.implHttp"),desc:t("hook.implHttpDesc")},{value:"PROMPT",label:"LLM Prompt",desc:t("hook.implPromptDesc")},{value:"AGENT",label:"AI Agent",desc:t("hook.implAgentDesc")}],h=Array.isArray(l)?l:[],w=Array.isArray(d)?d:[],[m,n]=y.useState(0),[s,N]=y.useState(re),[S,O]=y.useState("");y.useEffect(()=>{var a,o,i;r&&N({name:r.name,description:r.description||"",events:r.events,implementationType:r.implementationType,command:r.command||"",url:r.url||"",promptTemplate:r.promptTemplate||"",agentName:r.agentName||"",priority:r.priority,tools:r.tools||[],matcherToolNamePattern:((a=r.matchers)==null?void 0:a.toolNamePattern)||"",matcherFromState:((o=r.matchers)==null?void 0:o.fromState)||"",matcherToState:((i=r.matchers)==null?void 0:i.toState)||"",timeoutMs:r.timeoutMs,enabled:r.enabled,failOpen:r.failOpen,scope:r.scope||"project"})},[r]);const u=(a,o)=>{N(i=>({...i,[a]:o})),T()},I=a=>{N(o=>({...o,events:o.events.includes(a)?o.events.filter(i=>i!==a):[...o.events,a]}))},F=a=>{const o=a.every(i=>s.events.includes(i));N(o?i=>({...i,events:i.events.filter(A=>!a.includes(A))}):i=>({...i,events:[...new Set([...i.events,...a])]}))},M=async()=>{const a={};s.matcherToolNamePattern&&(a.toolNamePattern=s.matcherToolNamePattern),s.matcherFromState&&(a.fromState=s.matcherFromState),s.matcherToState&&(a.toState=s.matcherToState);const i={...{...s,tools:s.tools.length>0?s.tools:[]}};i.matchers=a,delete i.matcherToolNamePattern,delete i.matcherFromState,delete i.matcherToState,r?await k(r.name,i):await p(i)},U=async()=>{v(null);const a={};s.matcherToolNamePattern&&(a.toolNamePattern=s.matcherToolNamePattern),await R({hook:{name:s.name||"dry-run",description:s.description,events:s.events,implementationType:s.implementationType,command:s.command,url:s.url,promptTemplate:s.promptTemplate,agentName:s.agentName,priority:s.priority,tools:s.tools,matchers:a,timeoutMs:s.timeoutMs,enabled:!0,failOpen:s.failOpen,scope:s.scope},eventType:s.events[0]||"PRE_TOOL_USE",toolName:"",toolInput:""})},H=S?h.map(a=>({...a,events:Array.isArray(a.events)?a.events.filter(o=>o.name.toLowerCase().includes(S.toLowerCase())||o.summary.includes(S)):[]})).filter(a=>a.events.length>0):h,$=[{title:t("hook.stepBasicTitle"),desc:t("hook.stepBasicDesc")},{title:t("hook.stepImplTitle"),desc:t("hook.stepImplDesc")},{title:t("hook.stepAdvancedTitle"),desc:t("hook.stepAdvancedDesc")}];return e.jsxs("div",{className:"fixed inset-0 z-50 flex justify-end",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:b}),e.jsxs("div",{className:"relative flex h-full w-[560px] flex-col border-l border-dark-border bg-dark-bg shadow-2xl animate-slide-in-right",children:[e.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-b border-dark-border px-4 py-3.5",children:[e.jsx("h3",{className:"text-base font-semibold text-dark-text",children:r?t("hook.editRule",{name:r.name}):t("hook.addRule")}),e.jsx("button",{onClick:b,className:"rounded-lg p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(z,{size:18})})]}),e.jsx("div",{className:"flex flex-shrink-0 border-b border-dark-border",children:$.map((a,o)=>{const i=o===m,A=o<m;return e.jsxs("button",{onClick:()=>n(o),className:`relative flex-1 border-b-2 px-2 py-2.5 text-center text-xs transition-colors ${i?"border-accent-blue bg-accent-blue/5 text-accent-blue":A?"border-transparent text-dark-text":"border-transparent text-dark-muted hover:text-dark-text"}`,children:[e.jsx("span",{className:`mr-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-[10px] ${i?"bg-accent-blue text-white":A?"bg-accent-green text-white":"bg-dark-hover text-dark-muted"}`,children:A?"✓":o+1}),e.jsx("span",{className:"font-medium",children:a.title})]},a.title)})}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-4 overflow-auto custom-scrollbar p-4",children:[c&&Object.keys(c).length>0&&e.jsx("div",{className:"rounded-lg border border-accent-red/40 bg-accent-red/10 p-2.5 text-xs text-accent-red",children:Object.entries(c).map(([a,o])=>e.jsxs("div",{children:[e.jsxs("strong",{children:[a,":"]})," ",o]},a))}),m===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldName")}),e.jsx("input",{value:s.name,onChange:a=>u("name",a.target.value),placeholder:"my-custom-hook",className:g(c==null?void 0:c.name)})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldDescription")}),e.jsx("textarea",{value:s.description,onChange:a=>u("description",a.target.value),placeholder:t("hook.descriptionPlaceholder"),rows:2,className:g()})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:"Scope"}),e.jsxs("select",{value:s.scope,onChange:a=>u("scope",a.target.value),className:g(),children:[e.jsx("option",{value:"project",children:"project (.agent/hooks.json)"}),e.jsx("option",{value:"user",children:"user (~/.agent/hooks.json)"}),e.jsx("option",{value:"local",children:"local (.agent/hooks.local.json)"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-medium text-dark-muted",children:t("hook.fieldEvents")}),e.jsx("span",{className:"text-xs text-accent-blue",children:t("hook.eventsSelected",{n:s.events.length})})]}),e.jsx("input",{value:S,onChange:a=>O(a.target.value),placeholder:t("hook.searchEventsPlaceholder"),className:g()+" mb-2"}),e.jsx("div",{className:"max-h-[280px] space-y-2 overflow-auto custom-scrollbar rounded-lg border border-dark-border bg-dark-surface p-2",children:H.map(a=>e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>F(a.events.map(o=>o.name)),className:"mb-1 text-xs font-medium text-dark-muted transition-colors hover:text-dark-text",children:[a.category," — ",t("hook.toggleAllEvents")]}),a.events.map(o=>{const i=s.events.includes(o.name);return e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded px-1 py-1 transition-colors hover:bg-dark-hover",children:[e.jsx("input",{type:"checkbox",checked:i,onChange:()=>I(o.name),className:"h-3.5 w-3.5 accent-accent-blue"}),e.jsx("span",{className:"text-xs text-dark-text",children:o.name}),e.jsxs("span",{className:"truncate text-xs text-dark-muted",children:["— ",o.summary]})]},o.name)})]},a.category))})]})]}),m===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldImplType")}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:C.map(a=>{const o=s.implementationType===a.value;return e.jsxs("button",{onClick:()=>u("implementationType",a.value),className:`rounded-lg border p-3 text-left transition-colors ${o?"border-accent-blue bg-accent-blue/10 ring-1 ring-accent-blue/30":"border-dark-border bg-dark-surface hover:bg-dark-hover"}`,children:[e.jsx("div",{className:`text-sm font-medium ${o?"text-accent-blue":"text-dark-text"}`,children:a.label}),e.jsx("div",{className:"mt-1 text-xs text-dark-muted",children:a.desc})]},a.value)})})]}),s.implementationType==="SHELL"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldCommand")}),e.jsx("input",{value:s.command,onChange:a=>u("command",a.target.value),placeholder:"python3 .agent/hooks/audit.py",className:`font-mono ${g(c==null?void 0:c.command)}`})]}),s.implementationType==="HTTP"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:"URL *"}),e.jsx("input",{value:s.url,onChange:a=>u("url",a.target.value),placeholder:"https://example.com/hooks/audit",className:g(c==null?void 0:c.url)})]}),s.implementationType==="PROMPT"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldPromptTemplate")}),e.jsx("textarea",{value:s.promptTemplate,onChange:a=>u("promptTemplate",a.target.value),placeholder:t("hook.promptTemplatePlaceholder"),rows:5,className:`font-mono ${g(c==null?void 0:c.promptTemplate)}`})]}),s.implementationType==="AGENT"&&e.jsxs("div",{children:[e.jsx("label",{className:f,children:"Agent *"}),e.jsxs("select",{value:s.agentName,onChange:a=>u("agentName",a.target.value),className:g(c==null?void 0:c.agentName),children:[e.jsx("option",{value:"",children:t("hook.selectAgentPlaceholder")}),w.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.description,")"]},a.id))]}),e.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:t("hook.agentReadOnlyHint")})]})]}),m===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldPriority")}),e.jsx("select",{value:s.priority,onChange:a=>u("priority",a.target.value),className:g(),children:le.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldTimeout")}),e.jsx("input",{type:"number",value:s.timeoutMs,onChange:a=>u("timeoutMs",parseInt(a.target.value)||3e4),min:100,max:3e5,step:1e3,className:g()})]}),e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:s.enabled,onChange:a=>u("enabled",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),t("hook.labelEnabled")]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:s.failOpen,onChange:a=>u("failOpen",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),t("hook.failOpenLabel")]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:t("hook.fieldToolFilter")}),e.jsx("input",{value:s.matcherToolNamePattern,onChange:a=>u("matcherToolNamePattern",a.target.value),placeholder:"Bash.*|FileWrite.*",className:`font-mono ${g()}`})]}),s.events.some(a=>a.includes("STATE"))&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:f,children:"From State"}),e.jsx("input",{value:s.matcherFromState,onChange:a=>u("matcherFromState",a.target.value),className:g()})]}),e.jsxs("div",{children:[e.jsx("label",{className:f,children:"To State"}),e.jsx("input",{value:s.matcherToState,onChange:a=>u("matcherToState",a.target.value),className:g()})]})]}),x&&e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-dark-text",children:t("hook.dryRunResultTitle")}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.dryRunDecision")}),e.jsx("span",{className:x.decision==="ALLOW"?"text-accent-green":x.decision==="DENY"?"text-accent-red":"text-accent-yellow",children:x.decision})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.dryRunReason")}),e.jsx("span",{className:"text-dark-text",children:x.reason})]}),x.contextOutput&&e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:t("hook.dryRunOutput")}),e.jsx("span",{className:"text-dark-text",children:x.contextOutput})]})]})]}),e.jsxs("button",{onClick:U,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-1.5 text-xs text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(G,{size:12})," ",t("hook.dryRunButton")]})]})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-t border-dark-border px-4 py-3",children:[e.jsx("div",{className:"flex gap-2",children:m>0&&e.jsxs("button",{onClick:()=>n(m-1),className:"inline-flex items-center gap-1 rounded-lg border border-dark-border bg-dark-surface px-3 py-1.5 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(J,{size:14})," ",t("hook.prevStep")]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:b,className:"rounded-lg border border-dark-border bg-dark-surface px-4 py-1.5 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:t("common.cancel")}),m<2?e.jsxs("button",{onClick:()=>n(m+1),className:"inline-flex items-center gap-1 rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:[t("hook.nextStep")," ",e.jsx(W,{size:14})]}):e.jsx("button",{onClick:M,className:"rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:t(r?"hook.saveChanges":"hook.createRule")})]})]})]})]})}function oe({stats:l}){const{t:d}=E();if(!l)return null;const t=[{id:"total",label:d("hook.statTotal"),value:l.totalHooks,icon:_,iconWrap:"bg-accent-blue/15 text-accent-blue"},{id:"enabled",label:d("common.enabled"),value:l.enabledCount,icon:q,iconWrap:"bg-accent-green/15 text-accent-green"},{id:"disabled",label:d("common.disabled"),value:l.disabledCount,icon:K,iconWrap:"bg-dark-hover text-dark-muted"}];return e.jsx("div",{className:"grid grid-cols-3 gap-3",children:t.map(r=>{const c=r.icon;return e.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-dark-border bg-dark-surface px-4 py-3",children:[e.jsx("span",{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg ${r.iconWrap}`,children:e.jsx(c,{size:18})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xl font-bold text-dark-text",children:r.value}),e.jsx("div",{className:"text-xs text-dark-muted",children:r.label})]})]},r.id)})})}function ue(){const{t:l}=E(),{rules:d,stats:t,events:r,agents:c,loading:x,error:p,formOpen:k,loadAll:b,openForm:R,clearError:v}=P();y.useEffect(()=>{b()},[]);const T=y.useCallback(async()=>{const h=await j.hooks.export();if(h.success&&h.data){const w=new Blob([JSON.stringify(h.data,null,2)],{type:"application/json"}),m=URL.createObjectURL(w),n=document.createElement("a");n.href=m,n.download="hooks-export.json",n.click(),URL.revokeObjectURL(m)}},[]),C=y.useCallback(()=>{const h=document.createElement("input");h.type="file",h.accept=".json",h.onchange=async w=>{var s;const m=(s=w.target.files)==null?void 0:s[0];if(!m)return;const n=await m.text();try{const N=JSON.parse(n),S=confirm(l("hook.importMergeConfirm"))?"merge":"replace";(await j.hooks.import({...N,mergeMode:S})).success&&b()}catch(N){console.error("Import failed:",N)}},h.click()},[b,l]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-dark-bg text-dark-text",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-dark-border px-6 py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-dark-text",children:l("hook.configTitle")}),e.jsx("p",{className:"mt-0.5 text-xs text-dark-muted",children:l("hook.configDesc")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:b,title:l("common.refresh"),className:"rounded-lg p-2 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(V,{size:16,className:x?"animate-spin":""})}),e.jsxs("button",{onClick:C,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(X,{size:14}),l("hook.import")]}),e.jsxs("button",{onClick:T,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(Q,{size:14}),l("hook.export")]}),e.jsxs("button",{onClick:()=>R(),className:"inline-flex items-center gap-1.5 rounded-lg bg-accent-blue px-3 py-2 text-sm text-white transition-colors hover:bg-accent-blue/90",children:[e.jsx(Z,{size:14}),l("hook.newRule")]})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar px-6 py-4",children:[p&&e.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-lg border border-accent-red/40 bg-accent-red/10 px-4 py-2 text-sm text-accent-red",children:[e.jsx("span",{children:p}),e.jsx("button",{onClick:v,className:"text-accent-red/70 transition-colors hover:text-accent-red",children:e.jsx(z,{size:16})})]}),e.jsx(oe,{stats:t}),e.jsxs("section",{className:"mt-4 min-w-0 rounded-xl border border-dark-border bg-dark-surface p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-dark-text",children:l("hook.ruleList")}),e.jsx("span",{className:"text-xs text-dark-muted",children:l("hook.ruleCount",{n:d.length})})]}),x&&d.length===0?e.jsx("div",{className:"flex h-[520px] items-center justify-center text-dark-muted",children:l("common.loading")}):e.jsx("div",{className:"min-h-[520px]",children:e.jsx(se,{rules:d,onEdit:h=>R(h)})})]})]}),k&&e.jsx(ne,{events:r,agents:c})]})}export{ue as HookConfigView};
@@ -0,0 +1 @@
1
+ import{j as e}from"./markdown-yjmXQjrx.js";import{a as o,h as te,a2 as Hs,z as Me,O as ae,X as cs,ap as qs,C as he,aq as Ie,ar as is,as as _s,ae as Vs,ag as Ys,at as Qs,au as Ws,D as Js,aj as Xs,av as us,$ as Zs,aw as et}from"./icons-qcawb7PZ.js";import{a as b,u as st,t as T,M as ms,P as tt}from"./index-DUpwXfa-.js";import"./react-vendor-CSlQceOk.js";import"./state-DOzZasIm.js";import"./panels-CX_dYEv0.js";function at(){const[v,y]=o.useState([]),[C,t]=o.useState("1.0"),[P,je]=o.useState(!0),[h,le]=o.useState(!0),[ke,Y]=o.useState(null),Q=o.useCallback(async()=>{le(!0),Y(null);try{const f=await b.providers.presets();f.success&&f.data?(y(Array.isArray(f.data.providers)?f.data.providers:[]),t(f.data.version||"1.0"),je(f.data.customSupported!==!1)):Y(f.error||"获取 Provider 列表失败")}catch(f){Y(f instanceof Error?f.message:"未知错误")}finally{le(!1)}},[]);return o.useEffect(()=>{Q()},[Q]),{presets:v,loading:h,error:ke,version:C,customSupported:P,reload:Q}}const lt={providerKey:"",apiKeys:"",modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!1,modelOverrides:{}},ps=tt,fe={"openai-chat-completions":"OpenAI Chat","openai-completions":"OpenAI Compatible","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages"};function J(v){return v.trim().split("|")[0].trim()}function rt(v){const y=v.toLowerCase();return y.includes("/anthropic")||y.includes("/coding")||y.includes("/claude")||y.includes("/messages")?"anthropic-messages":y.includes("/responses")?"openai-responses":"openai-completions"}function Ue(v){if(!v)return{};const y={};for(const C of v.models){const t={};C.apiType&&C.apiType!==v.apiType&&(t.apiType=C.apiType),C.baseUrl&&(t.baseUrl=C.baseUrl),Object.keys(t).length>0&&(y[C.id]=t)}return y}const ge={"opencode-free":5,deepseek:10,moonshotai:20,"moonshotai-cn":21,"kimi-for-coding":22,zhipuai:30,zai:31,"alibaba-cn":40,alibaba:41,minimax:50,"minimax-cn":51,moark:60,siliconflow:70,"siliconflow-cn":71,"stepfun-ai":80,stepfun:81,modelscope:90,openai:100,anthropic:110,google:120,"google-vertex":121,meta:130,mistral:140,groq:150,xai:160,cohere:170,openrouter:180,huggingface:190};function mt(){var ss,ts,as,ls,rs,os;const{presets:v,loading:y,reload:C}=at(),{t}=st(),[P,je]=o.useState([]),[h,le]=o.useState(null),[ke,Y]=o.useState(!0),[Q,f]=o.useState(null),[Ae,Ke]=o.useState(null),[n,bs]=o.useState(null),[M,hs]=o.useState([]),[fs,G]=o.useState(!1),[Ee,H]=o.useState("select"),[D,R]=o.useState(null),[m,j]=o.useState(lt),[gs,E]=o.useState(""),[$e,Fe]=o.useState(!1),[ze,$]=o.useState(null),[vs,X]=o.useState(!1),[re,Le]=o.useState(!1),[Z,oe]=o.useState(""),[Re,Oe]=o.useState({}),[Ne,Be]=o.useState(!1),[F,q]=o.useState([]),[ne,I]=o.useState(new Set),[Ge,O]=o.useState(null),[de,ee]=o.useState(""),[we,He]=o.useState(!1),[ce,B]=o.useState(null),_=o.useCallback(async()=>{try{const s=await b.config.provider.get();s.success&&s.data&&(bs(s.data),hs(Array.isArray(s.data.entries)?s.data.entries:[]))}catch{}},[]),k=o.useCallback(async()=>{Y(!0),f(null);try{const[s,a]=await Promise.all([b.models.list(),b.system.status()]);if(await _(),s.success&&s.data&&Array.isArray(s.data.models)&&je(s.data.models),a.success&&a.data){const l=a.data.models||{total:0,online:0,offline:0};le({overallStatus:l.offline===0?"healthy":l.online>0?"degraded":"unhealthy",healthRate:l.total>0?l.online/l.total:0,healthyInstances:l.online,totalInstances:l.total,totalRequests:0})}}catch{f(t("models.loadFailed"))}finally{Y(!1)}},[_,t]);o.useEffect(()=>{k()},[k]),o.useEffect(()=>{const s=()=>{k(),_()};return window.addEventListener("models-updated",s),()=>window.removeEventListener("models-updated",s)},[k,_]);const U=o.useCallback(s=>`${s.provider}:${s.id}`,[]),ys=o.useCallback(s=>Re[U(s)]||{inputTokens:0,outputTokens:0},[U,Re]),qe=o.useCallback((s,a,l)=>{const c=U(s);Oe(r=>{var d,i;return{...r,[c]:{inputTokens:a==="inputTokens"?l:((d=r[c])==null?void 0:d.inputTokens)||0,outputTokens:a==="outputTokens"?l:((i=r[c])==null?void 0:i.outputTokens)||0}}})},[U]),js=o.useCallback(s=>{Oe(a=>({...a,[U(s)]:{inputTokens:0,outputTokens:0}}))},[U]),z=o.useMemo(()=>{const s=[...v];return s.find(a=>a.key==="custom")||s.push({key:"custom",name:"Custom",baseUrl:"",apiType:"openai-completions",defaultModel:"",isCustom:!0}),s},[v]),ie=o.useMemo(()=>[...z].sort((s,a)=>{if(s.isCustom)return-1;if(a.isCustom)return 1;const l=ge[s.key],c=ge[a.key];return l!==void 0&&c!==void 0?l-c:l!==void 0?-1:c!==void 0?1:s.name.localeCompare(a.name)}),[z]),_e=o.useMemo(()=>{const s=Z.trim().toLowerCase();return s?ie.filter(a=>a.name.toLowerCase().includes(s)||a.key.toLowerCase().includes(s)||(a.defaultModel||"").toLowerCase().includes(s)||(a.baseUrl||"").toLowerCase().includes(s)||(a.models||[]).some(l=>String(l).toLowerCase().includes(s))):ie},[ie,Z]),L=o.useMemo(()=>{var c,r,d,i;const s=(n==null?void 0:n.providers)||{},a=new Set(z.map(u=>u.key)),l=Object.entries(s).filter(([u])=>!a.has(u));if(l.length!==0)return{keys:l.map(([u])=>u),modelCount:l.reduce((u,[,g])=>u+(g.modelCount||0),0),hasApiKey:l.some(([,u])=>u.hasApiKey),baseUrl:((r=(c=l.find(([,u])=>u.baseUrl))==null?void 0:c[1])==null?void 0:r.baseUrl)||"",apiType:((i=(d=l.find(([,u])=>u.apiType))==null?void 0:d[1])==null?void 0:i.apiType)||"openai-completions"}},[n,z]),V=D==="custom"?m.providerKey.trim():D||"",Ce=o.useMemo(()=>V?P.filter(s=>s.provider===V):[],[P,V]),ks=o.useMemo(()=>{const s=new Map;for(const l of P)s.has(l.provider)||s.set(l.provider,[]),s.get(l.provider).push(l);for(const l of M)s.has(l.key)||s.set(l.key,[]);const a=[...s.keys()];return a.sort((l,c)=>{const r=ge[l],d=ge[c];return r!==void 0&&d!==void 0?r-d:r!==void 0?-1:d!==void 0?1:l.localeCompare(c)}),a.map(l=>({provider:l,models:s.get(l)||[]}))},[P,M]),Ve=o.useCallback(s=>{var i,u;const a=(i=n==null?void 0:n.providers)==null?void 0:i[s.key],l=M.find(g=>g.key===s.key),c=P.filter(g=>g.provider===s.key).map(g=>g.id),r=((u=s.models)==null?void 0:u.slice(0,3).join(", "))||s.defaultModel,d=c.length>0?c.join(", "):r;R(s.key),E(""),j({providerKey:s.key,apiKeys:"",modelIds:d,baseUrl:(a==null?void 0:a.baseUrl)||s.baseUrl,apiType:(a==null?void 0:a.apiType)||s.apiType,fullPath:(a==null?void 0:a.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s.key,modelOverrides:Ue(l)}),H("form"),G(!0),$(null),X(!1),q([]),I(new Set),O(null),ee("")},[P,n,M]),Ns=o.useCallback(s=>{var r;const a=(r=n==null?void 0:n.providers)==null?void 0:r[s],l=M.find(d=>d.key===s),c=P.filter(d=>d.provider===s).map(d=>d.id).join(", ");R("custom"),E(s),j({providerKey:s,apiKeys:"",modelIds:c,baseUrl:(a==null?void 0:a.baseUrl)||"",apiType:(a==null?void 0:a.apiType)||"",fullPath:(a==null?void 0:a.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s,modelOverrides:Ue(l)}),$(null),X(!1),q([]),I(new Set),O(null),ee("")},[n,P,M]),Pe=o.useCallback(()=>{R("custom"),E(""),j({providerKey:"",apiKeys:"",modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!(n!=null&&n.configured),modelOverrides:{}}),H("form"),G(!0),$(null),X(!1),q([]),I(new Set),O(null),ee("")},[n]),ws=o.useCallback(async()=>{var a;const s=m.baseUrl;if(!s){O(t("models.baseUrlRequired"));return}Be(!0),O(null),q([]),I(new Set);try{const l=(m.apiKeys||"").split(/\r?\n|,/).map(d=>d.trim()).filter(Boolean)[0]||"",c=l.replace(/[^\x00-\xFF]/g,"");c!==l&&T.warning(t("models.apiKeySanitized"));const r=await b.models.fetch(s,c,m.fullPath===!0);if(r.success&&((a=r.data)!=null&&a.models)){const d=r.data.models;q(d);const i=new Set(d.map(w=>w.id)),u=m.modelIds.split(",").map(w=>w.trim()).filter(Boolean),g=u.filter(w=>i.has(w.split("|")[0].trim())),p=u.filter(w=>!i.has(w.split("|")[0].trim()));if(I(new Set(g.map(w=>w.split("|")[0].trim()))),p.length>0){const w=p.map(S=>S.split("|")[0].trim());j(S=>({...S,modelIds:g.join(", ")})),T.warning(t("models.autoRemovedMissingModels",{models:w.join(", ")}))}T.success(t("models.fetchedCount",{n:d.length}))}else O(r.error||t("models.fetchFailed"))}catch(l){O(l instanceof Error?l.message:t("models.requestFailed"))}finally{Be(!1)}},[m.baseUrl,m.apiKeys,m.modelIds,t]),Cs=o.useCallback(async()=>{var a,l;const s=m.baseUrl;if(!s){B({ok:!1,message:t("models.baseUrlRequired")});return}He(!0),B(null);try{const c=(m.apiKeys||"").split(/\r?\n|,/).map(i=>i.trim()).filter(Boolean)[0]||"",r=c.replace(/[^\x00-\xFF]/g,"");r!==c&&T.warning(t("models.apiKeySanitized"));const d=await b.providers.testConnection(s,r);if(d.success&&((a=d.data)!=null&&a.reachable)){const i=d.data,u={};i.resolvedBaseUrl&&i.resolvedBaseUrl!==m.baseUrl&&(u.baseUrl=i.resolvedBaseUrl),i.detectedApiType&&m.apiType===""&&(u.apiType=i.detectedApiType),Object.keys(u).length>0&&j(w=>({...w,...u}));const g=[];u.baseUrl&&g.push(t("models.baseUrlAutoCompleted",{url:u.baseUrl})),u.apiType&&g.push(t("models.apiTypeAutoSelected",{type:fe[u.apiType]}));const p=i.message||t("models.connectionSuccess");B({ok:!0,message:g.length>0?t("models.connectionSuccessWithHints",{message:p,hints:g.join(t("models.hintJoiner"))}):p})}else B({ok:!1,message:((l=d.data)==null?void 0:l.message)||d.error||t("models.connectionFailed")})}catch(c){B({ok:!1,message:c instanceof Error?c.message:t("models.requestFailed")})}finally{He(!1)}},[m.baseUrl,m.apiKeys,m.apiType,t]),Ps=o.useCallback(s=>{const a=new Set(ne);a.has(s)?a.delete(s):a.add(s),I(a),j(l=>({...l,modelIds:Array.from(a).join(", ")}))},[ne]),Ts=o.useCallback(s=>{const a=m.modelIds.split(",").map(d=>d.trim()).filter(Boolean),c=a.some(d=>J(d)===s.id)?a.filter(d=>J(d)!==s.id):[...a,s.name&&s.name!==s.id?`${s.id}|${s.name}`:s.id];j(d=>({...d,modelIds:c.join(", ")}));const r=new Set(F.map(d=>d.id));I(new Set(c.map(J).filter(d=>r.has(d))))},[m.modelIds,F]),[Ds,Ye]=o.useState(!1),[Te,Qe]=o.useState(""),[We,ue]=o.useState([]),[Ss,Je]=o.useState(!1),[Xe,me]=o.useState(null),[pe,Ms]=o.useState(!1),[xe,Is]=o.useState(!0),Us=o.useCallback(()=>{Qe(""),ue([]),me(null),Ye(!0),se("",{reason:!1,tool:!0})},[]),se=o.useCallback(async(s,a)=>{Je(!0),me(null);try{const l=await b.models.catalogSearch({q:s,reasoning:(a==null?void 0:a.reason)??!1,toolCall:(a==null?void 0:a.tool)??!0,limit:30});l.success&&l.data?ue(l.data.hits||[]):(me(l.error||t("models.catalogSearchFailed")),ue([]))}catch(l){me(l instanceof Error?l.message:t("models.requestFailed")),ue([])}finally{Je(!1)}},[t]),As=o.useCallback(s=>{j(a=>{const l=a.modelIds.split(",").map(c=>c.trim()).filter(Boolean);return l.includes(s.model.id)?a:{...a,modelIds:[...l,s.model.id].join(", ")}}),T.success(t("models.addedModel",{id:s.model.id}))},[t]),[De,Ks]=o.useState(null),Es=o.useCallback(s=>{Qe(s),De&&clearTimeout(De),Ks(setTimeout(()=>{se(s,{reason:pe,tool:xe})},300))},[De,pe,xe,se]),$s=async s=>{const a=s.provider,l=s.id,c=s.enabled!==!1,r=s.name||l,d=i=>c&&/default model/i.test(i);try{const i=await b.models.toggle(a,l);if(i.success){await k();return}const u=i.error||"";d(u)?T.error(t("models.defaultModelDisableBlocked",{name:r})):T.error(u||t("models.operationFailed"))}catch(i){const u=i instanceof Error?i.message:"";d(u)?T.error(t("models.defaultModelDisableBlocked",{name:r})):T.error(u||t("models.operationFailed"))}},Fs=async s=>{const a=U(s);Ke(a);try{await b.models.test(s.id),await k()}finally{Ke(null)}},zs=async(s,a)=>{if(confirm(t("models.deleteModelConfirm",{id:a})))try{(await b.models.delete(s,a)).success&&await k()}catch{}},Ze=o.useCallback(s=>{var d;const a=M.find(i=>i.key===s),l=z.find(i=>i.key===s),c=!l||l.isCustom,r=(d=n==null?void 0:n.providers)==null?void 0:d[s];R(c?"custom":s),E(c?s:""),j({providerKey:s,apiKeys:"",modelIds:(a==null?void 0:a.models.map(i=>i.name&&i.name!==i.id?`${i.id}|${i.name}`:i.id).join(", "))||"",baseUrl:(a==null?void 0:a.baseUrl)||(r==null?void 0:r.baseUrl)||(l==null?void 0:l.baseUrl)||"",apiType:(a==null?void 0:a.apiType)||(r==null?void 0:r.apiType)||(l==null?void 0:l.apiType)||"",fullPath:(a==null?void 0:a.fullPath)===!0||(r==null?void 0:r.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s,modelOverrides:Ue(a)}),H("form"),G(!0),$(null),X(!1),q([]),I(new Set),O(null),ee("")},[M,z,n]),Ls=s=>{Ze(s.provider)},Rs=async()=>{var ns,ds;const s=z.find(x=>x.key===D)||null,a=D==="custom"?m.providerKey.trim():(s==null?void 0:s.key)||"";if(!a){$(t("models.providerNameRequired"));return}const l=(m.apiKeys||"").split(/\r?\n|,/).map(x=>x.trim()).filter(Boolean),c=!!((ds=(ns=n==null?void 0:n.providers)==null?void 0:ns[a])!=null&&ds.hasApiKey);if(l.length===0&&!c){$(t("models.apiKeyRequired"));return}const r=s||{baseUrl:"",apiType:"openai-completions",defaultModel:""},d=l.map(x=>x.replace(/[^\x00-\xFF]/g,"")).filter(Boolean),i=F.length>0?new Set(F.map(x=>x.id)):null,u=(m.modelIds||r.defaultModel||"").split(",").map(x=>x.trim()).filter(Boolean),g=i?u.filter(x=>i.has(x.split("|")[0].trim())):u,p=i?u.filter(x=>!i.has(x.split("|")[0].trim())):[];p.length>0&&T.warning(t("models.autoSkippedMissingModels",{models:p.map(x=>x.split("|")[0].trim()).join(", ")}));const w=g.map(J).filter(Boolean),S=new Set;for(const x of P)x.provider!==a||w.includes(x.id)||(x.isGlobalDefault&&S.add("global"),x.isActDefault&&S.add("act"),x.isPlanDefault&&S.add("plan"),x.isGoalDefault&&S.add("goal"));const Se={provider:a,name:a,baseUrl:m.baseUrl||r.baseUrl,fullPath:m.fullPath===!0,apiType:m.apiType||rt(m.baseUrl||r.baseUrl)||r.apiType,models:g.map((x,be)=>{const A=x.trim().split("|").map(Gs=>Gs.trim()).filter(Boolean),K=A[0]||"",N=m.modelOverrides[K];return{id:K,name:A[1]||K,aliases:A.length>2?A.slice(2):void 0,enabled:!0,priority:10+be,...N!=null&&N.apiType?{apiType:N.apiType}:{},...N!=null&&N.baseUrl?{baseUrl:N.baseUrl}:{}}}).filter(x=>x.id.length>0)};d.length>0&&(Se.apiKeys=d),(!(n!=null&&n.configured)||m.setDefault)&&(Se.setDefault=!0),Fe(!0),$(null);try{const x=await b.config.provider.save(Se);if(x.success){if(S.size>0){const be=w[0]||"",A={};if(be){const K=`${a}:${be}`;for(const N of S)A[N]=K}else{const K=P.find(N=>N.provider!==a);for(const N of S)N==="plan"||N==="goal"?A[N]=null:K&&(A[N]=`${K.provider}:${K.id}`)}Object.keys(A).length>0&&(await b.models.setDefaults(A)).success&&T.success(t("models.defaultsAutoUpdated"))}G(!1),H("select"),R(null),E(""),await _(),await k()}else $(x.error||t("models.saveFailed"))}catch(x){$(x instanceof Error?x.message:t("models.unknownError"))}finally{Fe(!1)}},es=async s=>{if(confirm(t("models.removeConfirm",{providerKey:s})))try{await b.config.provider.delete(s),await _(),await k()}catch{}},Os=s=>{switch(s){case"online":return"text-accent-green";case"offline":return"text-dark-muted";case"error":return"text-accent-red";default:return"text-dark-muted"}},Bs=s=>{switch(s){case"online":return e.jsx(et,{size:14});case"offline":return e.jsx(us,{size:14});case"error":return e.jsx(Zs,{size:14});default:return e.jsx(us,{size:14})}},W=o.useMemo(()=>z.find(s=>s.key===D)||null,[D,z]);return ke?e.jsx("div",{className:"flex h-64 items-center justify-center text-dark-muted",children:t("models.loading")}):Q?e.jsx("div",{className:"flex h-64 items-center justify-center text-accent-red",children:Q}):e.jsx("div",{className:"ui-page flex-1 min-h-0",children:e.jsxs("div",{className:"ui-page-inner space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-base font-semibold",children:t("models.providerConfig")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:async()=>{try{await b.providers.refresh(),T.success(t("models.providerListRefreshed")),Le(!0),await C(),setTimeout(()=>{C()},3e3)}catch{T.error(t("models.refreshFailed"))}},className:"btn btn-secondary px-3 py-2 text-xs",title:t("models.refreshListTitle"),children:[e.jsx(te,{size:12}),t("models.refreshList")]}),e.jsxs("button",{onClick:()=>{re&&oe(""),Le(s=>!s)},className:"btn btn-accent px-3 py-2 text-xs",children:[re?e.jsx(Hs,{size:12}):e.jsx(Me,{size:12}),t(re?"models.collapse":"models.addProvider")]})]})]}),re&&e.jsxs("div",{children:[e.jsxs("div",{className:"relative mb-3 max-w-md",children:[e.jsx(ae,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:Z,onChange:s=>oe(s.target.value),className:"w-full pl-8 pr-8 py-1.5 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",placeholder:t("models.providerSearchPlaceholder")}),Z&&e.jsx("button",{onClick:()=>oe(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-white",title:t("models.clear"),"aria-label":t("models.clearSearch"),children:e.jsx(cs,{size:13})})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3 max-h-[420px] overflow-y-auto custom-scrollbar pr-1",children:y?e.jsxs("div",{className:"col-span-full flex items-center justify-center py-4 text-dark-muted text-sm",children:[e.jsx(qs,{size:14,className:"mr-2 animate-spin"}),t("models.loadingProviders")]}):_e.length===0?e.jsxs("div",{className:"col-span-full border border-accent-red/30 bg-accent-red/10 rounded-lg p-4 text-center",children:[e.jsx("div",{className:"text-sm text-accent-red font-medium mb-1",children:t("models.noMatchingProviders")}),e.jsx("div",{className:"text-xs text-dark-muted mb-3",children:t("models.noMatchingProvidersHint",{query:Z})}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsxs("button",{onClick:()=>oe(""),className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-dark-border rounded hover:bg-dark-hover",children:[e.jsx(cs,{size:12}),t("models.clearSearch")]}),e.jsxs("button",{onClick:Pe,className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs bg-accent-blue text-white rounded hover:opacity-90",children:[e.jsx(Me,{size:12}),t("models.addCustomProvider")]})]})]}):_e.map(s=>{var d,i;const a=s.key==="custom",l=a?L:(d=n==null?void 0:n.providers)==null?void 0:d[s.key],c=l==null?void 0:l.hasApiKey,r=a?!!(n!=null&&n.defaultProvider)&&((L==null?void 0:L.keys)||[]).includes(n.defaultProvider):(n==null?void 0:n.defaultProvider)===s.key;return e.jsxs("div",{className:`ui-card-interactive text-left p-4 relative ${c?"border-accent-green/30 bg-dark-surface hover:border-accent-green/50":"border-dark-border bg-dark-surface hover:border-dark-hover"}`,children:[e.jsxs("div",{onClick:()=>s.key==="custom"?Pe():Ve(s),className:"cursor-pointer",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),c&&e.jsx(he,{size:14,className:"text-accent-green"})]}),e.jsxs("div",{className:"text-[10px] text-dark-muted space-y-0.5",children:[e.jsx("div",{className:"truncate",children:a?(l==null?void 0:l.baseUrl)||t("models.customBaseUrl"):s.baseUrl||t("models.customBaseUrl")}),e.jsx("div",{className:"truncate",children:a&&L?`${L.keys.join(", ")}`:s.defaultModel||t("models.noDefaultModel")}),e.jsxs("div",{children:[l?t("models.configuredCount",{n:l.modelCount}):t("models.availableCount",{n:((i=s.models)==null?void 0:i.length)||0}),s.models&&s.models.length>0&&!l&&e.jsx("span",{className:"text-accent-blue",children:" ✓"})]})]}),r&&e.jsx("div",{className:"mt-1 text-[10px] text-accent-blue",children:t("models.defaultProviderBadge")})]}),c&&s.key!=="custom"&&e.jsx("button",{onClick:u=>{u.stopPropagation(),es(s.key)},className:"absolute top-1.5 right-1.5 p-1 rounded text-dark-muted hover:bg-accent-red/10 hover:text-accent-red transition-colors",title:t("models.deleteProvider"),"aria-label":t("models.deleteProviderNamed",{name:s.name}),children:e.jsx(Ie,{size:13})})]},s.key)})})]})]}),h&&e.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[e.jsx(ve,{title:t("models.overallStatus"),value:h.totalInstances===0?t("models.notConfigured"):h.overallStatus==="healthy"?t("models.healthy"):h.overallStatus==="degraded"?t("models.degraded"):t("models.abnormal"),color:h.totalInstances===0?"blue":h.overallStatus==="healthy"?"green":h.overallStatus==="degraded"?"yellow":"red"}),e.jsx(ve,{title:t("models.healthRate"),value:h.totalInstances===0?"N/A":`${(h.healthRate*100).toFixed(0)}%`,color:h.totalInstances===0?"blue":h.healthRate>.8?"green":h.healthRate>.5?"yellow":"red"}),e.jsx(ve,{title:t("models.onlineInstances"),value:h.totalInstances===0?t("models.none"):`${h.healthyInstances}/${h.totalInstances}`,color:h.healthyInstances>0?"green":"red"}),e.jsx(ve,{title:t("models.totalRequests"),value:h.totalRequests>0?h.totalRequests.toLocaleString():"0",color:"blue"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsx("h3",{className:"text-sm font-medium",children:t("models.configuredModels")})}),e.jsxs("div",{className:"space-y-4 max-h-[640px] overflow-y-auto custom-scrollbar pr-1",children:[ks.map(s=>{var c;const a=M.find(r=>r.key===s.provider),l=(c=n==null?void 0:n.providers)==null?void 0:c[s.provider];return e.jsxs("div",{className:"rounded-lg border border-dark-border overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 bg-dark-bg border-b border-dark-border",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[e.jsx("span",{className:"text-xs font-semibold whitespace-nowrap",children:s.provider}),(n==null?void 0:n.defaultProvider)===s.provider&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue whitespace-nowrap",children:t("models.defaultShort")}),e.jsx("span",{className:"text-[10px] text-dark-muted truncate",children:(l==null?void 0:l.baseUrl)||(a==null?void 0:a.baseUrl)||""}),e.jsx("span",{className:"text-[10px] text-dark-muted whitespace-nowrap",children:(a==null?void 0:a.apiType)||(l==null?void 0:l.apiType)||""}),l!=null&&l.hasApiKey||a!=null&&a.hasApiKey?e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-green/20 text-accent-green whitespace-nowrap",children:t("models.hasKey")}):e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red whitespace-nowrap",children:t("models.noKey")})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>Ze(s.provider),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:t("models.editProviderNamed",{name:s.provider}),children:e.jsx(is,{size:13})}),e.jsx("button",{onClick:()=>es(s.provider),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:t("models.deleteProviderNamed",{name:s.provider}),children:e.jsx(Ie,{size:13})})]})]}),e.jsxs("div",{className:"space-y-2 p-2 bg-dark-surface/40",children:[s.models.map(r=>{const d=ys(r),i=d.inputTokens+d.outputTokens,u=a==null?void 0:a.models.find(p=>p.id===r.id),g=!!(u!=null&&u.apiType&&u.apiType!==(a==null?void 0:a.apiType));return e.jsx("div",{className:`bg-dark-surface border rounded-lg p-3 ${r.status==="online"?"border-accent-green":"border-dark-border"} ${r.enabled===!1?"opacity-60":""}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:Os(r.status),children:Bs(r.status)}),e.jsx("span",{className:"font-medium text-sm",children:r.name}),e.jsx("span",{className:"text-[10px] text-dark-muted px-1.5 py-0.5 bg-dark-bg rounded",children:r.provider}),r.apiType&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${r.apiType==="anthropic-messages"||r.apiType==="openai-responses"?"bg-accent-purple/20 text-accent-purple":"bg-accent-blue/20 text-accent-blue"}`,children:fe[r.apiType]||r.apiType}),g&&e.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",title:t("models.overrideTitle"),children:t("models.overrideBadge")}),r.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-green/20 text-accent-green font-medium",children:t("models.globalDefault")}),r.isPlanDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue font-medium",children:t("models.planDefault")}),r.isActDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",children:t("models.actDefault")}),r.isGoalDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-purple/20 text-accent-purple font-medium",children:t("models.goalDefault")})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[e.jsx(ye,{label:t("models.loadLabel"),value:`${r.load}/${r.maxLoad}`}),e.jsx(ye,{label:"Token",value:`${r.tokens}/${r.maxTokens}`}),e.jsx(ye,{label:t("models.inputPrice"),value:`$${r.price.input}/1K`}),e.jsx(ye,{label:t("models.outputPrice"),value:`$${r.price.output}/1K`})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-4 gap-3 items-end",children:[e.jsx(xs,{label:t("models.inputTokensLabel"),value:d.inputTokens,onChange:p=>qe(r,"inputTokens",p)}),e.jsx(xs,{label:t("models.outputTokensLabel"),value:d.outputTokens,onChange:p=>qe(r,"outputTokens",p)}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] text-dark-muted mb-1",children:t("models.totalTokensLabel")}),e.jsx("div",{className:"px-3 py-2 rounded border border-dark-border bg-dark-bg text-sm font-mono",children:i.toLocaleString()})]}),e.jsxs("button",{onClick:()=>js(r),className:"inline-flex items-center justify-center gap-1.5 px-3 py-2 rounded border border-dark-border text-sm text-dark-muted hover:bg-dark-hover",children:[e.jsx(_s,{size:13}),t("models.reset")]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[!r.isGlobalDefault&&r.enabled!==!1&&e.jsx("button",{onClick:async()=>{try{await b.models.setDefaults({global:`${r.provider}:${r.id}`}),await k()}catch(p){f(p instanceof Error?p.message:t("models.setGlobalDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-accent-green/30 text-accent-green hover:bg-accent-green/10",title:t("models.setGlobalDefaultTitle"),children:t("models.globalDefault")}),!r.isPlanDefault&&r.enabled!==!1&&e.jsx("button",{onClick:async()=>{try{await b.models.setDefaults({plan:`${r.provider}:${r.id}`}),await k()}catch(p){f(p instanceof Error?p.message:t("models.setPlanDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-accent-blue/30 text-accent-blue hover:bg-accent-blue/10",title:t("models.setPlanDefaultTitle"),children:t("models.planDefault")}),r.isPlanDefault&&e.jsx("button",{onClick:async()=>{try{await b.models.setDefaults({plan:null}),await k()}catch(p){f(p instanceof Error?p.message:t("models.unsetPlanDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:bg-dark-hover",title:t("models.unsetPlanDefaultTitle"),children:t("models.unsetPlanDefault")}),!r.isActDefault&&r.enabled!==!1&&e.jsx("button",{onClick:async()=>{try{await b.models.setDefaults({act:`${r.provider}:${r.id}`}),await k()}catch(p){f(p instanceof Error?p.message:t("models.setActDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-accent-yellow/30 text-accent-yellow hover:bg-accent-yellow/10",title:t("models.setActDefaultTitle"),children:t("models.actDefault")}),r.isActDefault&&e.jsx("button",{onClick:async()=>{try{await b.models.setDefaults({act:null}),await k()}catch(p){f(p instanceof Error?p.message:t("models.unsetActDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:bg-dark-hover",title:t("models.unsetActDefaultTitle"),children:t("models.unsetActDefault")}),!r.isGoalDefault&&r.enabled!==!1&&e.jsx("button",{onClick:async()=>{try{await b.models.setDefaults({goal:`${r.provider}:${r.id}`}),await k()}catch(p){f(p instanceof Error?p.message:t("models.setGoalDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-accent-purple/30 text-accent-purple hover:bg-accent-purple/10",title:t("models.setGoalDefaultTitle"),children:t("models.goalDefault")}),r.isGoalDefault&&e.jsx("button",{onClick:async()=>{try{await b.models.setDefaults({goal:null}),await k()}catch(p){f(p instanceof Error?p.message:t("models.unsetGoalDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:bg-dark-hover",title:t("models.unsetGoalDefaultTitle"),children:t("models.unsetGoalDefault")}),e.jsx("button",{onClick:()=>Ls(r),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:t("models.editModel"),children:e.jsx(is,{size:13})}),e.jsx("button",{onClick:()=>zs(r.provider,r.id),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:t("models.deleteModel"),children:e.jsx(Ie,{size:13})}),e.jsx("button",{onClick:()=>Fs(r),disabled:Ae===U(r),className:"p-1.5 rounded hover:bg-dark-hover disabled:opacity-50",title:t("models.refresh"),children:e.jsx(te,{size:13,className:Ae===U(r)?"animate-spin":""})}),e.jsx("button",{onClick:()=>$s(r),className:`px-2 py-0.5 rounded text-xs transition-colors ${r.enabled===!1?"bg-accent-green/20 text-accent-green hover:bg-accent-green/30":"bg-accent-red/20 text-accent-red hover:bg-accent-red/30"}`,children:r.enabled===!1?t("models.enable"):t("models.disable")})]})]})},U(r))}),s.models.length===0&&e.jsx("div",{className:"text-center text-[11px] text-dark-muted py-3",children:t("models.noModelsInProvider")})]})]},s.provider)}),P.length===0&&M.length===0&&e.jsxs("div",{className:"text-center text-dark-muted py-6",children:[e.jsx(Vs,{size:36,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:t("models.emptyHint")})]})]})]}),e.jsx(ms,{isOpen:fs,onClose:()=>{G(!1),H("select"),R(null),E("")},title:Ee==="select"?t("models.selectProvider"):(W==null?void 0:W.name)||t("models.providerConfig"),size:"xl",children:Ee==="select"?e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[ie.filter(s=>s.key!=="custom").map(s=>e.jsxs("button",{onClick:()=>Ve(s),className:"text-left p-3 rounded-lg border border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(he,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium",children:s.name})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:s.defaultModel})]},s.key)),e.jsxs("button",{onClick:Pe,className:"text-left p-3 rounded-lg border border-dashed border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ys,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium",children:t("models.customProvider")})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("models.customProviderDesc")})]})]})}):e.jsxs("div",{className:"space-y-3",children:[D==="custom"&&e.jsxs("div",{className:"space-y-3",children:[L&&L.keys.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.editExistingConfig")}),e.jsxs("select",{value:gs,onChange:s=>{const a=s.target.value;a?Ns(a):(E(""),j(l=>({...l,providerKey:"",modelIds:"",baseUrl:"",apiType:"",apiKeys:""})))},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:t("models.newCustomProviderOption")}),L.keys.map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.editExistingConfigHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.providerNameLabel")}),e.jsx("input",{value:m.providerKey,onChange:s=>j(a=>({...a,providerKey:s.target.value})),className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:t("models.providerNamePlaceholder")})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:["API Keys",(ts=(ss=n==null?void 0:n.providers)==null?void 0:ss[D==="custom"?m.providerKey.trim():D||""])!=null&&ts.hasApiKey?"":" *",e.jsx("span",{className:"text-dark-muted/60 text-xs",children:(ls=(as=n==null?void 0:n.providers)==null?void 0:as[D==="custom"?m.providerKey.trim():D||""])!=null&&ls.hasApiKey?t("models.apiKeysHintConfigured"):t("models.apiKeysHintNew")})]}),e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{rows:3,value:m.apiKeys,onChange:s=>j(a=>({...a,apiKeys:s.target.value})),className:"w-full px-3 py-2 pr-10 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue resize-y custom-scrollbar",placeholder:t("models.apiKeyMultiPlaceholder")}),e.jsx("button",{onClick:()=>X(s=>!s),className:"absolute right-2 top-2 text-dark-muted hover:text-white",children:vs?e.jsx(Qs,{size:14}):e.jsx(Ws,{size:14})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.modelIdLabel")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:m.modelIds,onChange:s=>{const a=s.target.value;j(l=>({...l,modelIds:a})),I(()=>{const l=new Set;for(const c of a.split(",")){const r=c.trim().split("|")[0].trim();r&&F.some(d=>d.id===r)&&l.add(r)}return l})},className:"flex-1 px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:(W==null?void 0:W.defaultModel)||t("models.modelIdPlaceholder")}),e.jsxs("button",{onClick:ws,disabled:Ne||!m.baseUrl,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-blue/30 text-accent-blue hover:bg-accent-blue/10 disabled:opacity-50 whitespace-nowrap",title:t("models.fetchModelsTitle"),children:[Ne?e.jsx(te,{size:13,className:"animate-spin"}):e.jsx(Js,{size:13}),t(Ne?"models.fetchingModels":"models.fetchModels")]}),e.jsxs("button",{onClick:Cs,disabled:we||!m.baseUrl,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-yellow/30 text-accent-yellow hover:bg-accent-yellow/10 disabled:opacity-50 whitespace-nowrap",title:t("models.testConnectionTitle"),children:[we?e.jsx(te,{size:13,className:"animate-spin"}):e.jsx(Xs,{size:13}),t(we?"models.testingConnection":"models.testConnection")]}),e.jsxs("button",{onClick:Us,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-green/30 text-accent-green hover:bg-accent-green/10 whitespace-nowrap",title:t("models.catalogSearchTitle"),children:[e.jsx(ae,{size:13}),t("models.catalogSearch")]})]}),ce&&e.jsxs("div",{className:`mt-1 text-xs ${ce.ok?"text-accent-green":"text-accent-red"}`,children:[ce.ok?"✓ ":"✗ ",ce.message]}),Ge&&e.jsx("div",{className:"mt-1 text-xs text-accent-red",children:Ge}),F.length===0&&Ce.length>0&&e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("models.configuredPanelPrefix"),e.jsx("strong",{className:"text-dark-text",children:Ce.length}),t("models.configuredPanelSuffix"),e.jsx("span",{className:"text-accent-green/70",children:t("models.configuredPanelHint")})]})}),e.jsx("div",{className:"max-h-48 overflow-y-auto custom-scrollbar grid grid-cols-2 sm:grid-cols-3 gap-1",children:Ce.map(s=>{const a=m.modelIds.split(",").map(J).filter(Boolean).includes(s.id);return e.jsxs("div",{role:"checkbox","aria-checked":a,tabIndex:-1,onMouseDown:l=>l.preventDefault(),onClick:()=>Ts(s),className:`flex items-center gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${a?"bg-accent-green/20 text-accent-green border border-accent-green/30":"hover:bg-dark-hover border border-transparent"}`,children:[a?e.jsx(he,{size:10}):e.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"}),e.jsx("span",{className:"truncate",children:s.name||s.id}),s.isGlobalDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-green/20 shrink-0",children:t("models.globalShort")}),s.isPlanDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-blue/20 shrink-0",children:"Plan"}),s.isActDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-yellow/20 shrink-0",children:"Act"}),s.isGoalDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-purple/20 shrink-0",children:"Goal"})]},s.id)})})]}),F.length>0&&e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("models.fetchedPanelPrefix"),e.jsx("strong",{className:"text-dark-text",children:F.length}),t("models.fetchedPanelMiddle"),e.jsx("strong",{className:"text-accent-blue",children:ne.size}),t("models.fetchedPanelSuffix"),e.jsx("span",{className:"text-accent-blue/70",children:t("models.fetchedPanelHint")})]}),e.jsx("button",{onClick:()=>{q([]),I(new Set)},className:"px-2 py-0.5 text-[10px] border border-dark-border rounded hover:bg-dark-hover",children:t("models.close")})]}),e.jsxs("div",{className:"relative mb-2",children:[e.jsx(ae,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:de,onChange:s=>ee(s.target.value),className:"w-full pl-7 pr-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",placeholder:t("models.modelSearchPlaceholder")})]}),e.jsx("div",{className:"max-h-48 overflow-y-auto custom-scrollbar grid grid-cols-2 sm:grid-cols-3 gap-1",children:F.filter(s=>!de||s.id.toLowerCase().includes(de.toLowerCase())||s.name.toLowerCase().includes(de.toLowerCase())).map(s=>{const a=ne.has(s.id);return e.jsxs("div",{role:"checkbox","aria-checked":a,tabIndex:-1,onMouseDown:l=>l.preventDefault(),onClick:()=>Ps(s.id),className:`flex items-center gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${a?"bg-accent-blue/20 text-accent-blue border border-accent-blue/30":"hover:bg-dark-hover border border-transparent"}`,children:[a?e.jsx(he,{size:10}):e.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"}),e.jsx("span",{className:"truncate",children:s.id})]},s.id)})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"Base URL"}),e.jsx("input",{value:m.baseUrl,onChange:s=>{j(a=>({...a,baseUrl:s.target.value})),B(null)},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:"https://api.example.com/v1"}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none mt-2",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":m.fullPath,onClick:()=>{j(s=>({...s,fullPath:!s.fullPath})),B(null)},className:`relative w-9 h-5 rounded-full transition-colors shrink-0 ${m.fullPath?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${m.fullPath?"translate-x-[18px]":"translate-x-0.5"}`})}),e.jsx("span",{className:"text-sm text-dark-muted",children:t("models.fullPathLabel")})]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.fullPathHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.apiTypeLabel")}),e.jsxs("select",{value:m.apiType,onChange:s=>{j(a=>({...a,apiType:s.target.value})),B(null)},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:t("models.apiTypeAutoDetect")}),ps.map(s=>e.jsx("option",{value:s,children:fe[s]},s))]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.apiTypeHint")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:[t("models.modelApiTypeLabel"),e.jsx("span",{className:"text-dark-muted/60 text-xs",children:t("models.modelApiTypeHint")})]}),e.jsx("div",{className:"border border-dark-border rounded-lg divide-y divide-dark-border max-h-40 overflow-y-auto custom-scrollbar",children:(()=>{const s=m.modelIds.split(",").map(J).filter(Boolean);return s.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t("models.modelApiTypeEmpty")}):s.map(a=>{var l;return e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[e.jsx("span",{className:"text-xs truncate min-w-0",children:a}),e.jsxs("select",{value:((l=m.modelOverrides[a])==null?void 0:l.apiType)||"",onChange:c=>j(r=>({...r,modelOverrides:{...r.modelOverrides,[a]:{...r.modelOverrides[a]||{},apiType:c.target.value}}})),className:"w-52 px-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:"继承 Provider(默认)"}),ps.map(c=>e.jsx("option",{value:c,children:fe[c]},c))]})]},a)})})()})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:m.setDefault,onChange:s=>j(a=>({...a,setDefault:s.target.checked})),className:"accent-accent-blue"}),e.jsx("span",{className:"text-sm text-dark-muted",children:t("models.setDefaultProvider")})]}),ze&&e.jsx("div",{className:"text-sm text-accent-red",children:ze}),e.jsxs("div",{className:"flex justify-between gap-2 pt-2",children:[e.jsx("div",{children:V&&((os=(rs=n==null?void 0:n.providers)==null?void 0:rs[V])==null?void 0:os.hasApiKey)&&e.jsx("button",{onClick:async()=>{if(confirm(t("models.deleteProviderConfirm",{key:V})))try{await b.config.provider.delete(V),G(!1),H("select"),R(null),E(""),await _(),await k()}catch{}},className:"px-4 py-2 rounded border border-accent-red/30 text-accent-red hover:bg-accent-red/10 transition-colors text-sm",children:t("models.deleteProvider")})}),e.jsx("button",{onClick:()=>{H("select"),R(null),E(""),G(!1)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:t("common.cancel")}),e.jsx("button",{onClick:Rs,disabled:$e,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:t($e?"common.saving":"common.save")})]})]})}),e.jsx(ms,{isOpen:Ds,onClose:()=>Ye(!1),title:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ae,{size:15,className:"text-accent-green"}),t("models.catalogTitle")]}),size:"2xl",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ae,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:Te,onChange:s=>Es(s.target.value),className:"w-full pl-9 pr-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-green",placeholder:t("models.catalogSearchPlaceholder"),autoFocus:!0})]}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:xe,onChange:s=>{const a=s.target.checked;Is(a),se(Te,{reason:pe,tool:a})},className:"accent-accent-green"}),t("models.catalogOnlyToolCall")]}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:pe,onChange:s=>{const a=s.target.checked;Ms(a),se(Te,{reason:a,tool:xe})},className:"accent-accent-green"}),t("models.catalogOnlyReasoning")]})]}),Xe&&e.jsx("div",{className:"text-xs text-accent-red bg-accent-red/10 p-2 rounded",children:Xe}),Ss?e.jsxs("div",{className:"flex items-center justify-center py-10 text-dark-muted",children:[e.jsx(te,{size:18,className:"animate-spin mr-2"})," ",t("models.searching")]}):e.jsx("div",{className:"max-h-96 overflow-y-auto custom-scrollbar border border-dark-border rounded-lg divide-y divide-dark-border",children:We.length===0?e.jsx("div",{className:"py-10 text-center text-dark-muted text-sm",children:t("models.catalogNoResults")}):We.map(s=>{var a,l,c;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 hover:bg-dark-hover",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-dark-text truncate",children:s.model.name||s.model.id}),e.jsx("code",{className:"text-[10px] px-1.5 py-0.5 bg-dark-bg border border-dark-border rounded text-dark-muted truncate",children:s.model.id}),s.model.reasoning&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-yellow/10 text-accent-yellow rounded",children:t("models.badgeReasoning")}),s.model.tool_call&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-blue/10 text-accent-blue rounded",children:t("models.badgeToolCall")}),s.model.attachment&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-green/10 text-accent-green rounded",children:t("models.badgeMultimodal")})]}),e.jsxs("div",{className:"text-[11px] text-dark-muted mt-0.5",children:[s.providerName,(a=s.model.limit)!=null&&a.context?` · ${t("models.ctxLimit",{k:(s.model.limit.context/1e3).toFixed(0)})}`:"",(l=s.model.limit)!=null&&l.output?` · ${t("models.outLimit",{k:(s.model.limit.output/1e3).toFixed(0)})}`:"",((c=s.model.cost)==null?void 0:c.input)!==void 0?` · $${s.model.cost.input}/M in / $${s.model.cost.output}/M out`:""]})]}),e.jsxs("button",{onClick:()=>As(s),className:"shrink-0 inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-accent-green/30 text-accent-green rounded hover:bg-accent-green/10 whitespace-nowrap",title:t("models.catalogAddTitle"),children:[e.jsx(Me,{size:12})," ",t("models.add")]})]},`${s.providerId}:${s.model.id}`)})}),e.jsx("div",{className:"text-[11px] text-dark-muted/60",children:t("models.catalogSourceHint")})]})})]})})}function ve({title:v,value:y,color:C}){const t={green:"bg-accent-green/10 text-accent-green",yellow:"bg-accent-yellow/10 text-accent-yellow",red:"bg-accent-red/10 text-accent-red",blue:"bg-accent-blue/10 text-accent-blue"};return e.jsxs("div",{className:`${t[C]} rounded-lg p-3`,children:[e.jsx("div",{className:"text-xs opacity-70",children:v}),e.jsx("div",{className:"text-xl font-semibold",children:y})]})}function ye({label:v,value:y}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-dark-muted",children:v}),e.jsx("div",{children:y})]})}function xs({label:v,value:y,onChange:C}){return e.jsxs("div",{children:[e.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:v}),e.jsx("input",{type:"number",min:"0",value:y,onChange:t=>C(parseInt(t.target.value,10)||0),className:"w-full px-3 py-2 rounded border border-dark-border bg-dark-bg text-sm focus:outline-none focus:border-accent-blue"})]})}export{mt as ModelsView,mt as default};
@@ -0,0 +1 @@
1
+ import{j as t}from"./markdown-yjmXQjrx.js";import{a as s,aj as be,h as me,O as ge,X as J,$ as he,aA as W,bd as ke,ba as ve,aq as fe,D as ee,y as je,K as ye}from"./icons-qcawb7PZ.js";import{u as Ne,g as p,C as Ce}from"./index-DUpwXfa-.js";import"./react-vendor-CSlQceOk.js";import"./state-DOzZasIm.js";import"./panels-CX_dYEv0.js";const E=12,we="other",Se=[{value:"all"},{value:"builtin"},{value:"openclaw"},{value:"deepseek-harness"}];function $e(a){return a==="wired"?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":a==="pending"||a==="pending_wiring"?"bg-amber-500/15 text-amber-400 border-amber-500/30":"bg-dark-hover text-dark-muted border-dark-border"}function te(a){var n;return((n=a.category)==null?void 0:n.trim())||we}function Me(a,n){const f=n.trim().toLowerCase();return f?[a.id,a.name,a.description,a.category,...a.tags??[]].filter(S=>typeof S=="string").join(" ").toLowerCase().includes(f):!0}function Re(){const{t:a}=Ne(),[n,f]=s.useState("installed"),[b,S]=s.useState([]),[R,re]=s.useState([]),[F,ae]=s.useState(null),[j,O]=s.useState(!0),[$,L]=s.useState(null),[i,B]=s.useState(null),[M,U]=s.useState(null),[y,V]=s.useState(null),[N,P]=s.useState(null),[_,q]=s.useState(null),[m,D]=s.useState(""),[o,se]=s.useState(null),[c,le]=s.useState(null),[u,z]=s.useState(1),x=s.useCallback((e,r)=>{V({kind:e,text:r}),window.setTimeout(()=>V(null),4e3)},[]),g=s.useCallback(async()=>{O(!0),L(null);const[e,r]=await Promise.all([p.get("/api/plugins"),p.get("/api/plugins/market")]);e.success&&e.data?(S(e.data.plugins),ae(e.data.schemaVersion??null)):L(e.error??"Failed to load plugins"),r.success&&r.data&&re(r.data.plugins),O(!1)},[]);s.useEffect(()=>{g()},[g]);const T=s.useMemo(()=>b.filter(e=>e.installable!==!0),[b]),h=s.useMemo(()=>[...b.filter(e=>e.installable===!0),...R.filter(e=>!b.some(r=>r.id===e.id||r.marketId===e.id))],[b,R]),C=s.useCallback(e=>e.filter(r=>o&&te(r)!==o||c&&(r.market??null)!==c?!1:Me(r,m)),[o,m,c]),k=s.useMemo(()=>C(T),[C,T]),v=s.useMemo(()=>C(h),[C,h]),G=s.useMemo(()=>{const e=new Set;for(const r of h)e.add(te(r));return["all",...Array.from(e).sort()]},[h]),K=e=>Math.max(1,Math.ceil(e/E)),H=(e,r)=>e.slice((r-1)*E,r*E),A=K(k.length),I=K(v.length),ne=s.useMemo(()=>H(k,Math.min(u,A)),[k,u,A]),de=s.useMemo(()=>H(v,Math.min(u,I)),[v,u,I]);s.useEffect(()=>{z(1)},[n,m,o,c]);const ie=m.trim().length>0||o!==null||c!==null,w=s.useCallback(async(e,r,d)=>{B(e),U(r);try{const l=await d();l&&l.success===!1?x("err",String(l.error??"Request failed")):(x("ok",`${r} ${e} ✓`),await g())}catch(l){x("err",l instanceof Error?l.message:String(l))}finally{B(null),U(null)}},[g,x]),Q=(e,r)=>w(e,r?"installed+activated":"installed",()=>p.post("/api/plugins/install",{id:e,activate:r})),oe=e=>w(e,"activated",()=>p.post(`/api/plugins/${encodeURIComponent(e)}/activate`)),ce=e=>w(e,"deactivated",()=>p.post(`/api/plugins/${encodeURIComponent(e)}/deactivate`)),ue=e=>w(e,"uninstalled",()=>p.delete(`/api/plugins/${encodeURIComponent(e)}`)),xe=async e=>{q(e);try{const r=await p.post(`/api/plugins/l2/provider/${encodeURIComponent(e)}`);r.success&&r.data?(x("ok",`Provider ${r.data.applied} applied to config ✓`),await g()):x("err",r.error??"Apply failed")}catch(r){x("err",r instanceof Error?r.message:String(r))}finally{q(null)}},X=e=>{const r=e==="bundled"?"bg-blue-500/15 text-blue-400 border-blue-500/30":e==="npm"?"bg-purple-500/15 text-purple-400 border-purple-500/30":e==="local"?"bg-cyan-500/15 text-cyan-400 border-cyan-500/30":"bg-dark-hover text-dark-muted border-dark-border";return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border ${r}`,children:e})},pe=e=>{if(!e)return null;const r=e==="builtin"?"bg-dark-hover text-dark-muted border-dark-border":e==="openclaw"?"bg-amber-500/15 text-amber-400 border-amber-500/30":e==="deepseek-harness"?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":"bg-dark-hover text-dark-muted border-dark-border";return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border ${r}`,children:e})},Y=(e,r)=>r>1?t.jsxs("div",{className:"flex items-center justify-center gap-3 pt-3 pb-1 select-none",children:[t.jsxs("button",{onClick:()=>z(d=>Math.max(1,d-1)),disabled:u<=1,className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border bg-dark-hover text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[t.jsx(je,{size:12})," ",a("plugins.prevPage")]}),t.jsx("span",{className:"text-[11px] text-dark-muted",children:a("plugins.pageInfo",{page:Math.min(u,r),pages:r,count:e})}),t.jsxs("button",{onClick:()=>z(d=>Math.min(r,d+1)),disabled:u>=r,className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border bg-dark-hover text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[a("plugins.nextPage")," ",t.jsx(ye,{size:12})]})]}):null,Z=e=>t.jsx("div",{className:"mt-8 text-center text-[12px] text-dark-muted",children:ie?a("plugins.noMatch"):e});return t.jsxs("div",{className:"h-full flex flex-col min-h-0 bg-dark-bg",children:[t.jsxs("div",{className:"h-11 flex items-center gap-2 px-3 border-b border-dark-border bg-dark-bg shrink-0 select-none",children:[t.jsx(be,{size:15,className:"text-accent-blue"}),t.jsx("span",{className:"truncate text-[13px] font-medium text-dark-text",children:a("nav.plugins")}),F!==null&&t.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-dark-hover text-dark-muted border border-dark-border",children:["schema v",F]}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:()=>void g(),className:"p-1.5 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text transition-colors",title:"Refresh",children:t.jsx(me,{size:14,className:j?"animate-spin":""})})]}),t.jsx("div",{className:"flex items-center gap-1 px-3 pt-2 shrink-0",children:["installed","available"].map(e=>t.jsx("button",{onClick:()=>f(e),className:`px-3 py-1.5 rounded-t text-[12px] transition-colors ${n===e?"bg-dark-surface text-accent-blue border border-b-0 border-dark-border":"text-dark-muted hover:text-dark-text"}`,children:e==="installed"?a("plugins.installedTab",{count:T.length}):a("plugins.availableTab",{count:h.length})},e))}),t.jsxs("div",{className:"shrink-0 px-3 pt-2 pb-1 space-y-2 bg-dark-bg",children:[t.jsxs("div",{className:"relative",children:[t.jsx(ge,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted pointer-events-none"}),t.jsx("input",{value:m,onChange:e=>D(e.target.value),placeholder:a("plugins.searchPlaceholder"),className:"w-full pl-8 pr-8 py-1.5 rounded bg-dark-hover border border-dark-border text-[12px] text-dark-text placeholder-dark-muted outline-none focus:border-accent-blue/50 transition-colors"}),m&&t.jsx("button",{onClick:()=>D(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-dark-muted hover:text-dark-text transition-colors",title:a("plugins.clear"),children:t.jsx(J,{size:12})})]}),n==="available"&&G.length>2&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:G.map(e=>t.jsx("button",{onClick:()=>se(e==="all"?null:e),className:`px-2 py-0.5 rounded-full text-[11px] border transition-colors ${e==="all"&&o===null||o===e?"bg-accent-blue/20 text-accent-blue border-accent-blue/40":"bg-dark-hover text-dark-muted border-dark-border hover:text-dark-text"}`,children:e==="all"?a("plugins.allCategories"):e},e))}),n==="available"&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:Se.map(e=>{const r=e.value==="all"?a("plugins.marketFilterAll"):e.value==="builtin"?a("plugins.marketFilterBuiltin"):e.value;return t.jsx("button",{onClick:()=>le(e.value==="all"?null:e.value),className:`px-2 py-0.5 rounded-full text-[11px] border transition-colors ${e.value==="all"&&c===null||c===e.value?"bg-accent-blue/20 text-accent-blue border-accent-blue/40":"bg-dark-hover text-dark-muted border-dark-border hover:text-dark-text"}`,children:r},e.value)})})]}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-3 pb-4",children:[$&&t.jsxs("div",{className:"mt-3 flex items-center gap-2 px-3 py-2 rounded bg-red-500/10 border border-red-500/30 text-red-400 text-[12px]",children:[t.jsx(he,{size:14})," ",$]}),j&&!$&&t.jsx("div",{className:"mt-10 flex justify-center",children:t.jsx("div",{className:"w-5 h-5 border-2 border-accent-blue border-t-transparent rounded-full animate-spin"})}),!j&&n==="installed"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[k.length===0&&Z(a("plugins.emptyInstalled")),ne.map(e=>{const r=e.l2??[],d=e.status==="active";return t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-medium text-dark-text truncate",children:e.name||e.id}),e.version&&t.jsx("span",{className:"text-[11px] text-dark-muted shrink-0",children:e.version}),X(e.source),t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border shrink-0 ${d?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":"bg-dark-hover text-dark-muted border-dark-border"}`,children:d?"active":"installed"}),e.httpMounted&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[11px] bg-emerald-500/15 text-emerald-400 border border-emerald-500/30 shrink-0",children:"http mounted"}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-[11px] text-dark-muted font-mono shrink-0",children:e.id})]}),e.description&&t.jsx("p",{className:"mt-1 text-[12px] text-dark-muted",children:e.description}),r.length>0&&t.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[r.map(l=>t.jsxs("span",{title:l.note||l.id,className:`px-1.5 py-0.5 rounded text-[11px] border cursor-help ${$e(l.status)}`,children:[l.kind," · ",l.status,l.status==="wired"&&t.jsx(W,{size:10,className:"inline ml-0.5"})]},`${l.kind}-${l.id}`)),r.filter(l=>l.kind==="provider"&&l.status==="wired").map(l=>t.jsx("button",{disabled:_===l.id,onClick:()=>void xe(l.id),className:"px-1.5 py-0.5 rounded text-[11px] border border-accent-blue/40 text-accent-blue hover:bg-accent-blue/10 disabled:opacity-50 transition-colors",title:a("plugins.applyProviderTitle"),children:_===l.id?"applying…":"apply provider"},`apply-${l.id}`))]}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[d?t.jsxs("button",{onClick:()=>void ce(e.id),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-amber-500/15 border border-amber-500/30 text-amber-400 text-[11px] hover:bg-amber-500/25 disabled:opacity-50 transition-colors",children:[t.jsx(ke,{size:11})," ",i===e.id?`${M}…`:a("plugins.deactivate")]}):t.jsxs("button",{onClick:()=>void oe(e.id),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 text-[11px] hover:bg-emerald-500/25 disabled:opacity-50 transition-colors",children:[t.jsx(ve,{size:11})," ",i===e.id?`${M}…`:a("plugins.activate")]}),t.jsxs("button",{onClick:()=>P(e.id),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-hover border border-dark-border text-dark-muted text-[11px] hover:text-red-400 hover:border-red-500/40 disabled:opacity-50 transition-colors",children:[t.jsx(fe,{size:11})," ",a("plugins.uninstall")]})]})]},e.id)}),Y(k.length,A)]}),!j&&n==="available"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[v.length===0&&Z(a("plugins.emptyMarket")),de.map(e=>t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-medium text-dark-text truncate",children:e.name||e.id}),e.version&&t.jsx("span",{className:"text-[11px] text-dark-muted shrink-0",children:e.version}),X(e.source),pe(e.market),e.category&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[11px] bg-dark-hover text-dark-muted border border-dark-border shrink-0",children:e.category}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-[11px] text-dark-muted font-mono shrink-0",children:e.id})]}),e.description&&t.jsx("p",{className:"mt-1 text-[12px] text-dark-muted",children:e.description}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[t.jsxs("button",{onClick:()=>void Q(e.id,!0),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-blue/20 border border-accent-blue/40 text-accent-blue text-[11px] hover:bg-accent-blue/30 disabled:opacity-50 transition-colors",children:[t.jsx(ee,{size:11})," ",i===e.id?`${M}…`:a("plugins.installActivate")]}),t.jsxs("button",{onClick:()=>void Q(e.id,!1),disabled:i===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-hover border border-dark-border text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-50 transition-colors",children:[t.jsx(ee,{size:11})," ",a("plugins.installOnly")]})]})]},e.id)),Y(v.length,I)]})]}),y&&t.jsxs("div",{className:`fixed bottom-4 right-4 z-50 flex items-center gap-2 px-3 py-2 rounded-lg border text-[12px] shadow-lg ${y.kind==="ok"?"bg-emerald-500/15 border-emerald-500/30 text-emerald-400":"bg-red-500/15 border-red-500/30 text-red-400"}`,children:[y.kind==="ok"?t.jsx(W,{size:13}):t.jsx(J,{size:13})," ",y.text]}),t.jsx(Ce,{isOpen:N!==null,title:a("plugins.uninstallTitle"),message:a("plugins.uninstallConfirm",{id:N??""}),onConfirm:()=>{N&&ue(N),P(null)},onClose:()=>P(null)})]})}export{Re as PluginsView};