@deepseekcode/cli 1.0.20 → 1.0.23
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.
- package/dist/cli.js +1301 -1219
- package/package.json +3 -3
- package/web/dist/assets/AutomationView-BbLzZ7Db.js +1 -0
- package/web/dist/assets/ChannelConfigView-CjcMwBSL.js +8 -0
- package/web/dist/assets/ConnectorsView-CTFoG0sF.js +1 -0
- package/web/dist/assets/{FileTreeView-DL66cxki.js → FileTreeView-_N5eobgO.js} +2 -2
- package/web/dist/assets/HookConfigView-DM6IVFGm.js +2 -0
- package/web/dist/assets/ModelsView-CPm2WAbG.js +2 -0
- package/web/dist/assets/PluginsView-D9pzIe-R.js +1 -0
- package/web/dist/assets/SessionGrid-C-Z-kzmG.js +35 -0
- package/web/dist/assets/SettingsPanel-D9kr-sFj.js +4 -0
- package/web/dist/assets/SkillsView-CS0XvZ4N.js +1 -0
- package/web/dist/assets/TemplatesTab-Pwfjxer7.js +1 -0
- package/web/dist/assets/TerminalView-C__4-QSL.js +3 -0
- package/web/dist/assets/ToolsView-Y5MpTnXY.js +1 -0
- package/web/dist/assets/{icons-CrV0VGFQ.js → icons-BXecaLRH.js} +161 -121
- package/web/dist/assets/index-CFxV9r1K.css +1 -0
- package/web/dist/assets/index-CcPIw0Dj.js +68 -0
- package/web/dist/assets/markdown-BASfeONY.js +30 -0
- package/web/dist/assets/panels-Bod3sKnK.js +1 -0
- package/web/dist/assets/react-vendor-7At16BnY.js +9 -0
- package/web/dist/assets/state-D4zgKwQs.js +17 -0
- package/web/dist/assets/terminal-DgJRGhIz.js +9 -0
- package/web/dist/index.html +7 -6
- package/web/dist/assets/AgentFlowView-qR01S0jV.js +0 -1
- package/web/dist/assets/AgentsView-CLvG8aae.js +0 -1
- package/web/dist/assets/AuditView-CMYlGV9S.js +0 -1
- package/web/dist/assets/AutomationView-wrcdqhJY.js +0 -1
- package/web/dist/assets/ChannelConfigView-DM70m5RE.js +0 -8
- package/web/dist/assets/ConnectorsView-B5ndd8pU.js +0 -1
- package/web/dist/assets/HookConfigView-BugHBHlO.js +0 -3
- package/web/dist/assets/InboxView-DLPWNrqG.js +0 -1
- package/web/dist/assets/ModelsView-CwhL9YPX.js +0 -2
- package/web/dist/assets/SessionGrid-CC1NAZ45.js +0 -26
- package/web/dist/assets/SettingsPanel-n1UbEjzX.js +0 -4
- package/web/dist/assets/SkillsView-DznSS50I.js +0 -1
- package/web/dist/assets/TemplatesTab-BPD0hvrG.js +0 -1
- package/web/dist/assets/TerminalView-B4WUBGzA.js +0 -3
- package/web/dist/assets/ToolsView-CQgPyD6U.js +0 -1
- package/web/dist/assets/index-DMxlsuNM.js +0 -20
- package/web/dist/assets/index-DjWfcgLQ.css +0 -1
- package/web/dist/assets/markdown-CaPdHFK5.js +0 -30
- package/web/dist/assets/panels-B3UcQJtY.js +0 -1
- package/web/dist/assets/react-vendor-DnYXnA42.js +0 -24
- package/web/dist/assets/state-BHmvnECu.js +0 -17
- package/web/dist/assets/terminal-Ck_l6svU.js +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseekcode/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"description": "DeepSeekCode TypeScript CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"go": "bun build.mjs && node dist/cli.js run",
|
|
19
19
|
"start": "bun build.mjs && node dist/cli.js start",
|
|
20
20
|
"prepublishOnly": "bun build.mjs --publish",
|
|
21
|
-
"version": "node -e \"const
|
|
21
|
+
"version": "node -e \"const v=require('./package.json').version;console.log('bumped to',v)\" && git add package.json",
|
|
22
22
|
"postversion": "git push origin main --follow-tags && git push origin v$(node -p \"require('./package.json').version\")"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
@@ -63,4 +63,4 @@
|
|
|
63
63
|
"typescript": "^5.6.3",
|
|
64
64
|
"vitest": "^4.1.7"
|
|
65
65
|
}
|
|
66
|
-
}
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e}from"./markdown-BASfeONY.js";import{a,ak as k,h as $,z as T,_ as O,b8 as D,f as I,aq as L,aO as U,X as J}from"./icons-BXecaLRH.js";import{U as _}from"./index-CcPIw0Dj.js";import"./react-vendor-7At16BnY.js";import"./state-D4zgKwQs.js";import"./panels-Bod3sKnK.js";function K(){const{automations:r,runsByAutomation:c,fetchAutomations:n,createAutomation:v,deleteAutomation:N,toggleAutomation:y,runAutomation:w,fetchRuns:C,error:l}=_(),[A,i]=a.useState(!1),[x,S]=a.useState(null),[m,u]=a.useState(""),[p,h]=a.useState(""),[o,b]=a.useState("0 9 * * *"),[g,f]=a.useState("");a.useEffect(()=>{n()},[n]);const z=async t=>{const s=g.trim();if(!s)return;const[d,...R]=s.split(/\s+/),j=R.join(" ");d&&j&&(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tool:d,target:j})})).ok&&(f(""),await n())},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 n()},P=async t=>{const s=x===t?null:t;S(s),s&&await C(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(k,{size:20,className:"text-accent-blue"}),"定时自动化",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 n(),className:"p-2 rounded-lg hover:bg-dark-hover text-dark-muted",title:"刷新",children:e.jsx($,{size:16})}),e.jsxs("button",{onClick:()=>i(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(T,{size:16})," 新建"]})]})]}),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]}),A&&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:m,onChange:t=>u(t.target.value),placeholder:"名称(如:每早 9 点汇总 Git 状态)",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:p,onChange:t=>h(t.target.value),placeholder:"指令(agent 每次触发时执行的内容)",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:o,onChange:t=>b(t.target.value),placeholder:"cron(5 段,如 0 9 * * *)",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 v({name:m,instructions:p,schedule:{kind:"cron",cron:o}})&&(u(""),h(""),i(!1))},className:"px-4 py-2 rounded-lg bg-accent-blue text-white text-sm font-medium hover:bg-accent-blue/80",children:"创建"})]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:[["0 9 * * *","每天 9:00"],["0 9 * * 1-5","工作日 9:00"],["*/30 * * * *","每 30 分钟"]].map(([t,s])=>e.jsxs("button",{onClick:()=>b(t),className:`px-2 py-1 rounded text-xs ${o===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:"还没有定时自动化。新建一个,让 agent 无人值守干活。"}),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 P(t.id),className:"flex items-center gap-2 min-w-0 text-left",children:[e.jsx(k,{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 y(t.id,t.status!=="enabled"),className:"p-1.5 rounded-lg hover:bg-dark-hover text-dark-muted",title:t.status==="enabled"?"停用":"启用",children:e.jsx(D,{size:15})}),e.jsx("button",{onClick:()=>void w(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-green",title:"手动触发",children:e.jsx(I,{size:15})}),e.jsx("button",{onClick:()=>void N(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-red",title:"删除",children:e.jsx(L,{size:15})})]})]}),x===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})," 运行历史"]}),(c[t.id]||[]).length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:"暂无运行记录"}),(c[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:"作用域放行(tool target)"}),t.permissions.length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:"无。未放行的写操作需人工批准,超时后自动拒绝。"}),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(J,{size:12})})]},s))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:g,onChange:s=>f(s.target.value),placeholder:"如:write_file docs/report.md",className:"flex-1 px-2 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-xs focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:()=>void z(t.id),className:"px-3 py-1.5 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-xs",children:"添加"})]})]})]})]},t.id))]})]})}export{K as AutomationView};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{j as i}from"./markdown-BASfeONY.js";import{a as M,b9 as ft,_ as ht,aw as gt,av as mt,aj as kt,z as ne,ba as Be,aq as xt,a7 as Et,g as vt,h as St}from"./icons-BXecaLRH.js";import{S as Te,M as Bt,a as Pe,t as re}from"./index-CcPIw0Dj.js";import"./react-vendor-7At16BnY.js";import"./state-D4zgKwQs.js";import"./panels-Bod3sKnK.js";const Tt={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"},At={wechat:"💬",feishu:"📘",dingtalk:"🔔",telegram:"✈️",discord:"🎮",slack:"💼",signal:"🔒",whatsapp:"📱",line:"🟢",qqbot:"🐧",matrix:"🧩",mattermost:"🏢",msteams:"📋",googlechat:"📧",irc:"💻",imessage:"✉️",sms:"📨"},Rt=new Set(["mattermost","msteams","googlechat","irc","imessage","sms","nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser","clickclack","raft","qa-channel"]);function V(n){return Tt[n]??n}function $(n){return At[n]??"📡"}function J(n){return Rt.has(n)}const G=[{label:"即时通讯",types:["wechat","feishu","dingtalk"]},{label:"国际主流",types:["telegram","discord","slack","signal","whatsapp"]},{label:"东亚",types:["line","qqbot"]},{label:"协作平台",types:["matrix","mattermost","msteams","googlechat"]},{label:"经典协议",types:["irc","imessage","sms"]},{label:"其他",types:["nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser"]},{label:"内置",types:["clickclack","raft","qa-channel"]}];function Mt(){const{channels:n,availableTypes:r,selectedType:o,selectType:t,loadTypes:e}=Te();M.useEffect(()=>{e()},[e]);const s=M.useMemo(()=>{if(r.length>0){const u=new Set(r);return G.map(d=>({...d,types:d.types.filter(m=>u.has(m))})).filter(d=>d.types.length>0).concat(r.filter(d=>!G.flatMap(m=>m.types).includes(d)).length>0?[{label:"插件扩展",types:r.filter(d=>!G.flatMap(m=>m.types).includes(d))}]:[])}return G},[r]),a=M.useMemo(()=>{const u=new Map;for(const d of n){const m=u.get(d.type)??{count:0,connected:0};u.set(d.type,{count:m.count+1,connected:m.connected+(d.connected?1:0)})}return u},[n]),c=r.length>0,l=M.useMemo(()=>c?[...a.keys()].filter(u=>!r.includes(u)):[],[c,a,r]);return i.jsxs("div",{className:"flex flex-col h-full min-h-0 border-r border-dark-border bg-dark-surface",children:[i.jsxs("div",{className:"shrink-0 px-4 py-3 border-b border-dark-border",children:[i.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-dark-muted",children:"频道列表"}),i.jsx("p",{className:"text-[11px] text-dark-muted mt-0.5",children:n.length>0?`${n.length} 个已配置`:"点击下方频道开始配置"})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar",children:[s.map(u=>{const d=u.types.filter(m=>a.has(m));return d.length===0?null:i.jsxs("div",{children:[i.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:u.label}),d.map(m=>{const g=a.get(m);return i.jsx(se,{label:V(m),icon:$(m),isSelected:o===m,experimental:J(m),info:g,pluginMissing:c&&!r.includes(m),onClick:()=>t(m)},m)})]},u.label)}),l.length>0&&i.jsxs("div",{children:[i.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:"已配置 · 插件未安装"}),l.map(u=>{const d=a.get(u);return i.jsx(se,{label:V(u),icon:$(u),isSelected:o===u,experimental:J(u),info:d,pluginMissing:!0,onClick:()=>t(u)},u)})]}),(()=>{const u=s.flatMap(d=>d.types).filter(d=>!a.has(d));return u.length===0?null:i.jsxs("div",{children:[i.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:"未配置"}),u.map(d=>i.jsx(se,{label:V(d),icon:$(d),isSelected:o===d,experimental:J(d),onClick:()=>t(d)},d))]})})()]})]})}function se({label:n,icon:r,isSelected:o,experimental:t,info:e,pluginMissing:s,onClick:a}){return i.jsxs("button",{onClick:a,className:`w-full flex items-center gap-2.5 px-4 py-2.5 text-left transition-colors hover:bg-dark-hover ${o?"bg-accent-blue/10 border-l-2 border-accent-blue":"border-l-2 border-transparent"}`,children:[i.jsx("span",{className:"text-lg shrink-0 w-7 h-7 flex items-center justify-center rounded-md bg-dark-bg",children:r}),i.jsxs("div",{className:"flex-1 min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"text-sm font-medium text-dark-text truncate",children:n}),t&&i.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:"实验性实现,功能不完整",children:[i.jsx(ft,{className:"w-2.5 h-2.5"})," 实验"]}),s&&i.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:"该频道类型的插件未安装或未激活,无法启动实例",children:[i.jsx(ht,{className:"w-2.5 h-2.5"})," 插件未安装"]}),e&&i.jsx("span",{className:"text-[10px] text-dark-muted bg-dark-hover px-1.5 py-0.5 rounded shrink-0",children:e.count})]}),i.jsx("div",{className:"flex items-center gap-1 mt-0.5",children:e?e.connected>0?i.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-green-400",children:[i.jsx(gt,{className:"w-3 h-3"}),e.connected===e.count?"已连接":`${e.connected}/${e.count} 已连接`]}):i.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-dark-muted",children:[i.jsx(mt,{className:"w-3 h-3"}),s?"等待安装插件":"未连接"]}):i.jsx("span",{className:"text-[11px] text-dark-muted",children:"未配置"})})]})]})}const z={name:"",type:"wechat",appId:"",appSecret:"",token:"",encodingAESKey:"",enabled:!0};function It(){const{channels:n,selectedType:r,availableTypes:o,create:t,update:e,remove:s,toggle:a,error:c,clearError:l,openQr:u,load:d}=Te(),m=M.useMemo(()=>o.length>0&&!!r&&!o.includes(r),[o,r]),g=M.useMemo(()=>r?n.filter(h=>h.type===r):[],[n,r]),[x,j]=M.useState(""),[S,R]=M.useState(z),[v,B]=M.useState(!1),C=x==="__new__",f=M.useMemo(()=>C?null:g.find(h=>h.id===x)??null,[g,x,C]);M.useEffect(()=>{j(""),R(z),B(!1),l()},[r]),M.useEffect(()=>{r==="wechat"&&g.length===0&&!m&&u(null)},[r,g.length,m,u]),M.useEffect(()=>{f?R({name:f.name,type:f.type,appId:f.appId||"",appSecret:"",token:"",encodingAESKey:f.encodingAESKey||"",enabled:f.enabled}):C&&R(h=>({...h,type:r}))},[x]);const A=(h,w)=>{l(),R(T=>({...T,[h]:w}))},p=h=>{j(h),l()},y=()=>{j("__new__"),R({...z,type:r}),l()},k=()=>{j(""),R(z),l()},b=async()=>{if(!S.name.trim())return;B(!0);const h=f?await e(f.id,S):await t(S);B(!1),h&&(j(""),R(z))},E=async h=>{if(!confirm("确认删除该频道?"))return;await s(h)&&x===h&&(j(""),R(z))},N=(h,w)=>{a(h,w)};return r?i.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[i.jsx("div",{className:"shrink-0 px-6 py-4 border-b border-dark-border",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("span",{className:"text-2xl",children:$(r)}),i.jsxs("div",{children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("h2",{className:"font-semibold text-base text-dark-text",children:V(r)}),J(r)&&i.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:"实验性实现,功能不完整",children:[i.jsx(ft,{className:"w-3 h-3"})," 实验性"]})]}),i.jsx("p",{className:"text-xs text-dark-muted mt-0.5",children:g.length>0?`${g.length} 个配置实例`:"尚未配置"}),J(r)&&i.jsx("p",{className:"text-[10px] text-yellow-600/70 mt-1",children:"此频道为基础适配器封装,支持基础消息收发,部分高级功能可能不完整"})]})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("button",{onClick:()=>d(),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:"刷新"}),i.jsxs("button",{onClick:y,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:[i.jsx(ne,{className:"w-3.5 h-3.5"})," 新建实例"]})]})]})}),c&&i.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:[i.jsx("span",{children:c}),i.jsx("button",{onClick:l,className:"text-red-400 hover:text-red-300",children:i.jsx("span",{className:"w-4 h-4 inline-flex items-center justify-center",children:"×"})})]}),m&&i.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:[i.jsx(ht,{className:"w-3.5 h-3.5 mt-0.5 shrink-0"}),i.jsxs("span",{children:["该频道类型的插件未安装或未激活,实例无法启动。请到「插件」页安装并激活",r==="wechat"?" WeChat Channel":` ${V(r)}`," 插件后重试。"]})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar p-6",children:[g.length>1&&!C&&i.jsxs("div",{className:"mb-4",children:[i.jsx("label",{className:"block text-xs text-dark-muted mb-1.5",children:"选择实例"}),i.jsxs("div",{className:"flex flex-wrap gap-2",children:[g.map(h=>i.jsxs("button",{onClick:()=>p(h.id),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs border transition-colors ${x===h.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:[i.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${h.connected?"bg-green-500":"bg-gray-500"}`}),h.name]},h.id)),i.jsxs("button",{onClick:y,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:[i.jsx(ne,{className:"w-3 h-3"})," 新建"]})]})]}),g.length===0&&x===""&&i.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[i.jsx("div",{className:"text-4xl mb-3",children:$(r)}),i.jsxs("p",{className:"text-dark-text font-medium",children:["还没有配置 ",V(r)]}),i.jsx("p",{className:"text-sm text-dark-muted mt-1 mb-4",children:r==="wechat"?"点击下方按钮,用微信扫码即可自动完成绑定":"点击上方「新建实例」开始配置"}),r==="wechat"&&i.jsxs("button",{onClick:()=>u(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:[i.jsx(Be,{className:"w-4 h-4"})," 扫码绑定"]}),i.jsxs("button",{onClick:y,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:[i.jsx(ne,{className:"w-4 h-4"})," 新建实例"]})]}),g.length===1&&x===""&&g[0]&&i.jsx(Le,{channel:g[0],onEdit:()=>p(g[0].id),onDelete:()=>E(g[0].id),onToggle:h=>N(g[0].id,h),onQr:()=>u(g[0])}),g.length>1&&x===""&&i.jsx("div",{className:"space-y-3",children:g.map(h=>i.jsx(Le,{channel:h,onEdit:()=>p(h.id),onDelete:()=>E(h.id),onToggle:w=>N(h.id,w),onQr:()=>u(h)},h.id))}),x!==""&&(C||f)&&i.jsx(Pt,{form:S,upd:A,saving:v,editing:!!f,channel:f??void 0,onSave:b,onCancel:k,onDelete:f?()=>E(f.id):void 0,onQr:f?()=>u(f):void 0})]})]}):i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsxs("div",{className:"text-center",children:[i.jsx(kt,{className:"w-12 h-12 mx-auto mb-3 text-dark-muted/40"}),i.jsx("p",{className:"text-dark-muted text-sm",children:"请从左侧选择一个频道类型"})]})})}function Le({channel:n,onEdit:r,onDelete:o,onToggle:t,onQr:e}){return i.jsxs("div",{className:"border border-dark-border rounded-lg bg-dark-surface overflow-hidden",children:[i.jsx("div",{className:"p-5",children:i.jsxs("div",{className:"flex items-start justify-between",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"font-medium text-dark-text",children:n.name}),i.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[i.jsx("span",{className:`flex items-center gap-1 text-xs ${n.connected?"text-green-400":"text-dark-muted"}`,children:n.connected?i.jsxs(i.Fragment,{children:[i.jsx(gt,{className:"w-3 h-3"})," 已连接"]}):i.jsxs(i.Fragment,{children:[i.jsx(mt,{className:"w-3 h-3"})," 未连接"]})}),i.jsxs("span",{className:"text-xs text-dark-muted",children:["AppID: ",n.appId||"—"]})]})]}),i.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:i.jsx("span",{className:`absolute top-0.5 w-4 h-4 bg-white rounded-full transition-all ${n.enabled?"left-[18px]":"left-0.5"}`})})]})}),i.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"&&i.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:[i.jsx(Be,{className:"w-3.5 h-3.5"})," 扫码登录"]}),i.jsxs("button",{onClick:r,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:[i.jsx("span",{className:"w-3.5 h-3.5 inline-flex items-center justify-center",children:"✎"})," 编辑"]}),i.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 ml-auto",children:[i.jsx(xt,{className:"w-3.5 h-3.5"})," 删除"]})]})]})}function Pt({form:n,upd:r,saving:o,editing:t,channel:e,onSave:s,onCancel:a,onDelete:c,onQr:l}){return i.jsxs("div",{className:"border border-dark-border rounded-lg bg-dark-surface overflow-hidden",children:[i.jsx("div",{className:"px-5 py-4 border-b border-dark-border",children:i.jsx("h3",{className:"font-medium text-dark-text",children:t?"编辑配置":"新建配置"})}),i.jsxs("div",{className:"p-5 space-y-4",children:[i.jsx(qe,{label:"频道名称",required:!0,children:i.jsx("input",{value:n.name,onChange:u=>r("name",u.target.value),placeholder:"例如:研发群机器人",className:O})}),i.jsxs(qe,{label:"接入凭证",children:[i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"AppID / 企业ID"}),i.jsx("input",{value:n.appId,onChange:u=>r("appId",u.target.value),placeholder:"AppID",className:O})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"AppSecret"}),i.jsx("input",{type:"password",value:n.appSecret,onChange:u=>r("appSecret",u.target.value),placeholder:t?"留空不修改":"应用密钥",className:O})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"Token"}),i.jsx("input",{value:n.token,onChange:u=>r("token",u.target.value),placeholder:t?"留空不修改":"回调校验 Token",className:O})]}),n.type==="wechat"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"EncodingAESKey"}),i.jsx("input",{value:n.encodingAESKey,onChange:u=>r("encodingAESKey",u.target.value),placeholder:"选填",className:O})]})]}),n.type==="wechat"&&i.jsx("p",{className:"text-xs text-dark-muted mt-2",children:"微信 iLink 机器人通过扫码授权,凭证可留空,保存后扫码登录即可。"})]}),i.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-dark-border px-3 py-2.5",children:[i.jsxs("div",{children:[i.jsx("p",{className:"text-sm text-dark-text",children:"启用频道"}),i.jsx("p",{className:"text-xs text-dark-muted",children:"关闭后停止收发消息"})]}),i.jsx("button",{onClick:()=>r("enabled",!n.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${n.enabled?"bg-green-600":"bg-gray-600"}`,children:i.jsx("span",{className:`absolute top-0.5 w-4 h-4 bg-white rounded-full transition-all ${n.enabled?"left-[18px]":"left-0.5"}`})})]}),t&&(e==null?void 0:e.type)==="wechat"&&l&&i.jsxs("button",{onClick:l,className:"w-full flex items-center justify-center gap-2 text-sm bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 px-3 py-2.5 rounded-lg transition-colors",children:[i.jsx(Be,{className:"w-4 h-4"})," 扫码登录 / 重新授权"]})]}),i.jsxs("div",{className:"flex items-center justify-between px-5 py-3 bg-dark-bg/50 border-t border-dark-border",children:[i.jsx("div",{children:t&&c&&i.jsxs("button",{onClick:c,className:"flex items-center gap-1.5 text-xs px-3 py-1.5 rounded-md text-red-400 hover:bg-red-500/10 transition-colors",children:[i.jsx(xt,{className:"w-3.5 h-3.5"})," 删除"]})}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("button",{onClick:a,className:"px-4 py-2 text-sm text-dark-muted hover:text-dark-text transition-colors",children:"取消"}),i.jsxs("button",{onClick:s,disabled:o||!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:[i.jsx(Et,{className:"w-3.5 h-3.5"}),o?"保存中...":"保存"]})]})]})]})}function qe({label:n,required:r,children:o}){return i.jsxs("div",{children:[i.jsxs("label",{className:"block text-xs text-dark-muted mb-1.5",children:[n,r&&i.jsx("span",{className:"text-red-400 ml-0.5",children:"*"})]}),o]})}const O="w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-2 text-sm text-dark-text placeholder-dark-muted/60 focus:outline-none focus:border-accent-blue transition-colors";var K={},ie,_e;function Lt(){return _e||(_e=1,ie=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),ie}var oe={},_={},De;function D(){if(De)return _;De=1;let n;const r=[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 r[t]},_.getBCHDigit=function(o){let t=0;for(;o!==0;)t++,o>>>=1;return t},_.setToSJISFunction=function(t){if(typeof t!="function")throw new Error('"toSJISFunc" is not a valid function.');n=t},_.isKanjiModeEnabled=function(){return typeof n<"u"},_.toSJIS=function(t){return n(t)},_}var ae={},Ue;function Ae(){return Ue||(Ue=1,(function(n){n.L={bit:1},n.M={bit:0},n.Q={bit:3},n.H={bit:2};function r(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.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: "+o)}}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 r(t)}catch{return e}}})(ae)),ae}var le,Fe;function qt(){if(Fe)return le;Fe=1;function n(){this.buffer=[],this.length=0}return n.prototype={get:function(r){const o=Math.floor(r/8);return(this.buffer[o]>>>7-r%8&1)===1},put:function(r,o){for(let t=0;t<o;t++)this.putBit((r>>>o-t-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(r){const o=Math.floor(this.length/8);this.buffer.length<=o&&this.buffer.push(0),r&&(this.buffer[o]|=128>>>this.length%8),this.length++}},le=n,le}var ce,ze;function _t(){if(ze)return ce;ze=1;function n(r){if(!r||r<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=r,this.data=new Uint8Array(r*r),this.reservedBit=new Uint8Array(r*r)}return n.prototype.set=function(r,o,t,e){const s=r*this.size+o;this.data[s]=t,e&&(this.reservedBit[s]=!0)},n.prototype.get=function(r,o){return this.data[r*this.size+o]},n.prototype.xor=function(r,o,t){this.data[r*this.size+o]^=t},n.prototype.isReserved=function(r,o){return this.reservedBit[r*this.size+o]},ce=n,ce}var ue={},Ke;function Dt(){return Ke||(Ke=1,(function(n){const r=D().getSymbolSize;n.getRowColCoords=function(t){if(t===1)return[];const e=Math.floor(t/7)+2,s=r(t),a=s===145?26:Math.ceil((s-13)/(2*e-2))*2,c=[s-7];for(let l=1;l<e-1;l++)c[l]=c[l-1]-a;return c.push(6),c.reverse()},n.getPositions=function(t){const e=[],s=n.getRowColCoords(t),a=s.length;for(let c=0;c<a;c++)for(let l=0;l<a;l++)c===0&&l===0||c===0&&l===a-1||c===a-1&&l===0||e.push([s[c],s[l]]);return e}})(ue)),ue}var de={},Ve;function Ut(){if(Ve)return de;Ve=1;const n=D().getSymbolSize,r=7;return de.getPositions=function(t){const e=n(t);return[[0,0],[e-r,0],[0,e-r]]},de}var fe={},He;function Ft(){return He||(He=1,(function(n){n.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const r={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 s=e.size;let a=0,c=0,l=0,u=null,d=null;for(let m=0;m<s;m++){c=l=0,u=d=null;for(let g=0;g<s;g++){let x=e.get(m,g);x===u?c++:(c>=5&&(a+=r.N1+(c-5)),u=x,c=1),x=e.get(g,m),x===d?l++:(l>=5&&(a+=r.N1+(l-5)),d=x,l=1)}c>=5&&(a+=r.N1+(c-5)),l>=5&&(a+=r.N1+(l-5))}return a},n.getPenaltyN2=function(e){const s=e.size;let a=0;for(let c=0;c<s-1;c++)for(let l=0;l<s-1;l++){const u=e.get(c,l)+e.get(c,l+1)+e.get(c+1,l)+e.get(c+1,l+1);(u===4||u===0)&&a++}return a*r.N2},n.getPenaltyN3=function(e){const s=e.size;let a=0,c=0,l=0;for(let u=0;u<s;u++){c=l=0;for(let d=0;d<s;d++)c=c<<1&2047|e.get(u,d),d>=10&&(c===1488||c===93)&&a++,l=l<<1&2047|e.get(d,u),d>=10&&(l===1488||l===93)&&a++}return a*r.N3},n.getPenaltyN4=function(e){let s=0;const a=e.data.length;for(let l=0;l<a;l++)s+=e.data[l];return Math.abs(Math.ceil(s*100/a/5)-10)*r.N4};function o(t,e,s){switch(t){case n.Patterns.PATTERN000:return(e+s)%2===0;case n.Patterns.PATTERN001:return e%2===0;case n.Patterns.PATTERN010:return s%3===0;case n.Patterns.PATTERN011:return(e+s)%3===0;case n.Patterns.PATTERN100:return(Math.floor(e/2)+Math.floor(s/3))%2===0;case n.Patterns.PATTERN101:return e*s%2+e*s%3===0;case n.Patterns.PATTERN110:return(e*s%2+e*s%3)%2===0;case n.Patterns.PATTERN111:return(e*s%3+(e+s)%2)%2===0;default:throw new Error("bad maskPattern:"+t)}}n.applyMask=function(e,s){const a=s.size;for(let c=0;c<a;c++)for(let l=0;l<a;l++)s.isReserved(l,c)||s.xor(l,c,o(e,l,c))},n.getBestMask=function(e,s){const a=Object.keys(n.Patterns).length;let c=0,l=1/0;for(let u=0;u<a;u++){s(u),n.applyMask(u,e);const d=n.getPenaltyN1(e)+n.getPenaltyN2(e)+n.getPenaltyN3(e)+n.getPenaltyN4(e);n.applyMask(u,e),d<l&&(l=d,c=u)}return c}})(fe)),fe}var W={},Oe;function pt(){if(Oe)return W;Oe=1;const n=Ae(),r=[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],o=[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 W.getBlocksCount=function(e,s){switch(s){case n.L:return r[(e-1)*4+0];case n.M:return r[(e-1)*4+1];case n.Q:return r[(e-1)*4+2];case n.H:return r[(e-1)*4+3];default:return}},W.getTotalCodewordsCount=function(e,s){switch(s){case n.L:return o[(e-1)*4+0];case n.M:return o[(e-1)*4+1];case n.Q:return o[(e-1)*4+2];case n.H:return o[(e-1)*4+3];default:return}},W}var he={},Q={},Qe;function zt(){if(Qe)return Q;Qe=1;const n=new Uint8Array(512),r=new Uint8Array(256);return(function(){let t=1;for(let e=0;e<255;e++)n[e]=t,r[t]=e,t<<=1,t&256&&(t^=285);for(let e=255;e<512;e++)n[e]=n[e-255]})(),Q.log=function(t){if(t<1)throw new Error("log("+t+")");return r[t]},Q.exp=function(t){return n[t]},Q.mul=function(t,e){return t===0||e===0?0:n[r[t]+r[e]]},Q}var $e;function Kt(){return $e||($e=1,(function(n){const r=zt();n.mul=function(t,e){const s=new Uint8Array(t.length+e.length-1);for(let a=0;a<t.length;a++)for(let c=0;c<e.length;c++)s[a+c]^=r.mul(t[a],e[c]);return s},n.mod=function(t,e){let s=new Uint8Array(t);for(;s.length-e.length>=0;){const a=s[0];for(let l=0;l<e.length;l++)s[l]^=r.mul(e[l],a);let c=0;for(;c<s.length&&s[c]===0;)c++;s=s.slice(c)}return s},n.generateECPolynomial=function(t){let e=new Uint8Array([1]);for(let s=0;s<t;s++)e=n.mul(e,new Uint8Array([1,r.exp(s)]));return e}})(he)),he}var ge,Je;function Vt(){if(Je)return ge;Je=1;const n=Kt();function r(o){this.genPoly=void 0,this.degree=o,this.degree&&this.initialize(this.degree)}return r.prototype.initialize=function(t){this.degree=t,this.genPoly=n.generateECPolynomial(this.degree)},r.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 s=n.mod(e,this.genPoly),a=this.degree-s.length;if(a>0){const c=new Uint8Array(this.degree);return c.set(s,a),c}return s},ge=r,ge}var me={},xe={},pe={},Ye;function bt(){return Ye||(Ye=1,pe.isValid=function(r){return!isNaN(r)&&r>=1&&r<=40}),pe}var I={},Ge;function wt(){if(Ge)return I;Ge=1;const n="[0-9]+",r="[A-Z $%*+\\-./:]+";let o="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";o=o.replace(/u/g,"\\u");const t="(?:(?![A-Z0-9 $%*+\\-./:]|"+o+`)(?:.|[\r
|
|
2
|
+
]))+`;I.KANJI=new RegExp(o,"g"),I.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),I.BYTE=new RegExp(t,"g"),I.NUMERIC=new RegExp(n,"g"),I.ALPHANUMERIC=new RegExp(r,"g");const e=new RegExp("^"+o+"$"),s=new RegExp("^"+n+"$"),a=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return I.testKanji=function(l){return e.test(l)},I.testNumeric=function(l){return s.test(l)},I.testAlphanumeric=function(l){return a.test(l)},I}var We;function U(){return We||(We=1,(function(n){const r=bt(),o=wt();n.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},n.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},n.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},n.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},n.MIXED={bit:-1},n.getCharCountIndicator=function(s,a){if(!s.ccBits)throw new Error("Invalid mode: "+s);if(!r.isValid(a))throw new Error("Invalid version: "+a);return a>=1&&a<10?s.ccBits[0]:a<27?s.ccBits[1]:s.ccBits[2]},n.getBestModeForData=function(s){return o.testNumeric(s)?n.NUMERIC:o.testAlphanumeric(s)?n.ALPHANUMERIC:o.testKanji(s)?n.KANJI:n.BYTE},n.toString=function(s){if(s&&s.id)return s.id;throw new Error("Invalid mode")},n.isValid=function(s){return s&&s.bit&&s.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(s,a){if(n.isValid(s))return s;try{return t(s)}catch{return a}}})(xe)),xe}var Ze;function Ht(){return Ze||(Ze=1,(function(n){const r=D(),o=pt(),t=Ae(),e=U(),s=bt(),a=7973,c=r.getBCHDigit(a);function l(g,x,j){for(let S=1;S<=40;S++)if(x<=n.getCapacity(S,j,g))return S}function u(g,x){return e.getCharCountIndicator(g,x)+4}function d(g,x){let j=0;return g.forEach(function(S){const R=u(S.mode,x);j+=R+S.getBitsLength()}),j}function m(g,x){for(let j=1;j<=40;j++)if(d(g,j)<=n.getCapacity(j,x,e.MIXED))return j}n.from=function(x,j){return s.isValid(x)?parseInt(x,10):j},n.getCapacity=function(x,j,S){if(!s.isValid(x))throw new Error("Invalid QR Code version");typeof S>"u"&&(S=e.BYTE);const R=r.getSymbolTotalCodewords(x),v=o.getTotalCodewordsCount(x,j),B=(R-v)*8;if(S===e.MIXED)return B;const C=B-u(S,x);switch(S){case e.NUMERIC:return Math.floor(C/10*3);case e.ALPHANUMERIC:return Math.floor(C/11*2);case e.KANJI:return Math.floor(C/13);case e.BYTE:default:return Math.floor(C/8)}},n.getBestVersionForData=function(x,j){let S;const R=t.from(j,t.M);if(Array.isArray(x)){if(x.length>1)return m(x,R);if(x.length===0)return 1;S=x[0]}else S=x;return l(S.mode,S.getLength(),R)},n.getEncodedBits=function(x){if(!s.isValid(x)||x<7)throw new Error("Invalid QR Code version");let j=x<<12;for(;r.getBCHDigit(j)-c>=0;)j^=a<<r.getBCHDigit(j)-c;return x<<12|j}})(me)),me}var be={},Xe;function Ot(){if(Xe)return be;Xe=1;const n=D(),r=1335,o=21522,t=n.getBCHDigit(r);return be.getEncodedBits=function(s,a){const c=s.bit<<3|a;let l=c<<10;for(;n.getBCHDigit(l)-t>=0;)l^=r<<n.getBCHDigit(l)-t;return(c<<10|l)^o},be}var we={},ye,et;function Qt(){if(et)return ye;et=1;const n=U();function r(o){this.mode=n.NUMERIC,this.data=o.toString()}return r.getBitsLength=function(t){return 10*Math.floor(t/3)+(t%3?t%3*3+1:0)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(t){let e,s,a;for(e=0;e+3<=this.data.length;e+=3)s=this.data.substr(e,3),a=parseInt(s,10),t.put(a,10);const c=this.data.length-e;c>0&&(s=this.data.substr(e),a=parseInt(s,10),t.put(a,c*3+1))},ye=r,ye}var Ne,tt;function $t(){if(tt)return Ne;tt=1;const n=U(),r=["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 o(t){this.mode=n.ALPHANUMERIC,this.data=t}return o.getBitsLength=function(e){return 11*Math.floor(e/2)+6*(e%2)},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(e){let s;for(s=0;s+2<=this.data.length;s+=2){let a=r.indexOf(this.data[s])*45;a+=r.indexOf(this.data[s+1]),e.put(a,11)}this.data.length%2&&e.put(r.indexOf(this.data[s]),6)},Ne=o,Ne}var Ce,nt;function Jt(){if(nt)return Ce;nt=1;const n=U();function r(o){this.mode=n.BYTE,typeof o=="string"?this.data=new TextEncoder().encode(o):this.data=new Uint8Array(o)}return r.getBitsLength=function(t){return t*8},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(o){for(let t=0,e=this.data.length;t<e;t++)o.put(this.data[t],8)},Ce=r,Ce}var je,rt;function Yt(){if(rt)return je;rt=1;const n=U(),r=D();function o(t){this.mode=n.KANJI,this.data=t}return o.getBitsLength=function(e){return e*13},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(t){let e;for(e=0;e<this.data.length;e++){let s=r.toSJIS(this.data[e]);if(s>=33088&&s<=40956)s-=33088;else if(s>=57408&&s<=60351)s-=49472;else throw new Error("Invalid SJIS character: "+this.data[e]+`
|
|
3
|
+
Make sure your charset is UTF-8`);s=(s>>>8&255)*192+(s&255),t.put(s,13)}},je=o,je}var ke={exports:{}},st;function Gt(){return st||(st=1,(function(n){var r={single_source_shortest_paths:function(o,t,e){var s={},a={};a[t]=0;var c=r.PriorityQueue.make();c.push(t,0);for(var l,u,d,m,g,x,j,S,R;!c.empty();){l=c.pop(),u=l.value,m=l.cost,g=o[u]||{};for(d in g)g.hasOwnProperty(d)&&(x=g[d],j=m+x,S=a[d],R=typeof a[d]>"u",(R||S>j)&&(a[d]=j,c.push(d,j),s[d]=u))}if(typeof e<"u"&&typeof a[e]>"u"){var v=["Could not find a path from ",t," to ",e,"."].join("");throw new Error(v)}return s},extract_shortest_path_from_predecessor_list:function(o,t){for(var e=[],s=t;s;)e.push(s),o[s],s=o[s];return e.reverse(),e},find_path:function(o,t,e){var s=r.single_source_shortest_paths(o,t,e);return r.extract_shortest_path_from_predecessor_list(s,e)},PriorityQueue:{make:function(o){var t=r.PriorityQueue,e={},s;o=o||{};for(s in t)t.hasOwnProperty(s)&&(e[s]=t[s]);return e.queue=[],e.sorter=o.sorter||t.default_sorter,e},default_sorter:function(o,t){return o.cost-t.cost},push:function(o,t){var e={value:o,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=r})(ke)),ke.exports}var it;function Wt(){return it||(it=1,(function(n){const r=U(),o=Qt(),t=$t(),e=Jt(),s=Yt(),a=wt(),c=D(),l=Gt();function u(v){return unescape(encodeURIComponent(v)).length}function d(v,B,C){const f=[];let A;for(;(A=v.exec(C))!==null;)f.push({data:A[0],index:A.index,mode:B,length:A[0].length});return f}function m(v){const B=d(a.NUMERIC,r.NUMERIC,v),C=d(a.ALPHANUMERIC,r.ALPHANUMERIC,v);let f,A;return c.isKanjiModeEnabled()?(f=d(a.BYTE,r.BYTE,v),A=d(a.KANJI,r.KANJI,v)):(f=d(a.BYTE_KANJI,r.BYTE,v),A=[]),B.concat(C,f,A).sort(function(y,k){return y.index-k.index}).map(function(y){return{data:y.data,mode:y.mode,length:y.length}})}function g(v,B){switch(B){case r.NUMERIC:return o.getBitsLength(v);case r.ALPHANUMERIC:return t.getBitsLength(v);case r.KANJI:return s.getBitsLength(v);case r.BYTE:return e.getBitsLength(v)}}function x(v){return v.reduce(function(B,C){const f=B.length-1>=0?B[B.length-1]:null;return f&&f.mode===C.mode?(B[B.length-1].data+=C.data,B):(B.push(C),B)},[])}function j(v){const B=[];for(let C=0;C<v.length;C++){const f=v[C];switch(f.mode){case r.NUMERIC:B.push([f,{data:f.data,mode:r.ALPHANUMERIC,length:f.length},{data:f.data,mode:r.BYTE,length:f.length}]);break;case r.ALPHANUMERIC:B.push([f,{data:f.data,mode:r.BYTE,length:f.length}]);break;case r.KANJI:B.push([f,{data:f.data,mode:r.BYTE,length:u(f.data)}]);break;case r.BYTE:B.push([{data:f.data,mode:r.BYTE,length:u(f.data)}])}}return B}function S(v,B){const C={},f={start:{}};let A=["start"];for(let p=0;p<v.length;p++){const y=v[p],k=[];for(let b=0;b<y.length;b++){const E=y[b],N=""+p+b;k.push(N),C[N]={node:E,lastCount:0},f[N]={};for(let h=0;h<A.length;h++){const w=A[h];C[w]&&C[w].node.mode===E.mode?(f[w][N]=g(C[w].lastCount+E.length,E.mode)-g(C[w].lastCount,E.mode),C[w].lastCount+=E.length):(C[w]&&(C[w].lastCount=E.length),f[w][N]=g(E.length,E.mode)+4+r.getCharCountIndicator(E.mode,B))}}A=k}for(let p=0;p<A.length;p++)f[A[p]].end=0;return{map:f,table:C}}function R(v,B){let C;const f=r.getBestModeForData(v);if(C=r.from(B,f),C!==r.BYTE&&C.bit<f.bit)throw new Error('"'+v+'" cannot be encoded with mode '+r.toString(C)+`.
|
|
4
|
+
Suggested mode is: `+r.toString(f));switch(C===r.KANJI&&!c.isKanjiModeEnabled()&&(C=r.BYTE),C){case r.NUMERIC:return new o(v);case r.ALPHANUMERIC:return new t(v);case r.KANJI:return new s(v);case r.BYTE:return new e(v)}}n.fromArray=function(B){return B.reduce(function(C,f){return typeof f=="string"?C.push(R(f,null)):f.data&&C.push(R(f.data,f.mode)),C},[])},n.fromString=function(B,C){const f=m(B,c.isKanjiModeEnabled()),A=j(f),p=S(A,C),y=l.find_path(p.map,"start","end"),k=[];for(let b=1;b<y.length-1;b++)k.push(p.table[y[b]].node);return n.fromArray(x(k))},n.rawSplit=function(B){return n.fromArray(m(B,c.isKanjiModeEnabled()))}})(we)),we}var ot;function Zt(){if(ot)return oe;ot=1;const n=D(),r=Ae(),o=qt(),t=_t(),e=Dt(),s=Ut(),a=Ft(),c=pt(),l=Vt(),u=Ht(),d=Ot(),m=U(),g=Wt();function x(p,y){const k=p.size,b=s.getPositions(y);for(let E=0;E<b.length;E++){const N=b[E][0],h=b[E][1];for(let w=-1;w<=7;w++)if(!(N+w<=-1||k<=N+w))for(let T=-1;T<=7;T++)h+T<=-1||k<=h+T||(w>=0&&w<=6&&(T===0||T===6)||T>=0&&T<=6&&(w===0||w===6)||w>=2&&w<=4&&T>=2&&T<=4?p.set(N+w,h+T,!0,!0):p.set(N+w,h+T,!1,!0))}}function j(p){const y=p.size;for(let k=8;k<y-8;k++){const b=k%2===0;p.set(k,6,b,!0),p.set(6,k,b,!0)}}function S(p,y){const k=e.getPositions(y);for(let b=0;b<k.length;b++){const E=k[b][0],N=k[b][1];for(let h=-2;h<=2;h++)for(let w=-2;w<=2;w++)h===-2||h===2||w===-2||w===2||h===0&&w===0?p.set(E+h,N+w,!0,!0):p.set(E+h,N+w,!1,!0)}}function R(p,y){const k=p.size,b=u.getEncodedBits(y);let E,N,h;for(let w=0;w<18;w++)E=Math.floor(w/3),N=w%3+k-8-3,h=(b>>w&1)===1,p.set(E,N,h,!0),p.set(N,E,h,!0)}function v(p,y,k){const b=p.size,E=d.getEncodedBits(y,k);let N,h;for(N=0;N<15;N++)h=(E>>N&1)===1,N<6?p.set(N,8,h,!0):N<8?p.set(N+1,8,h,!0):p.set(b-15+N,8,h,!0),N<8?p.set(8,b-N-1,h,!0):N<9?p.set(8,15-N-1+1,h,!0):p.set(8,15-N-1,h,!0);p.set(b-8,8,1,!0)}function B(p,y){const k=p.size;let b=-1,E=k-1,N=7,h=0;for(let w=k-1;w>0;w-=2)for(w===6&&w--;;){for(let T=0;T<2;T++)if(!p.isReserved(E,w-T)){let q=!1;h<y.length&&(q=(y[h]>>>N&1)===1),p.set(E,w-T,q),N--,N===-1&&(h++,N=7)}if(E+=b,E<0||k<=E){E-=b,b=-b;break}}}function C(p,y,k){const b=new o;k.forEach(function(T){b.put(T.mode.bit,4),b.put(T.getLength(),m.getCharCountIndicator(T.mode,p)),T.write(b)});const E=n.getSymbolTotalCodewords(p),N=c.getTotalCodewordsCount(p,y),h=(E-N)*8;for(b.getLengthInBits()+4<=h&&b.put(0,4);b.getLengthInBits()%8!==0;)b.putBit(0);const w=(h-b.getLengthInBits())/8;for(let T=0;T<w;T++)b.put(T%2?17:236,8);return f(b,p,y)}function f(p,y,k){const b=n.getSymbolTotalCodewords(y),E=c.getTotalCodewordsCount(y,k),N=b-E,h=c.getBlocksCount(y,k),w=b%h,T=h-w,q=Math.floor(b/h),H=Math.floor(N/h),Nt=H+1,Re=q-H,Ct=new l(Re);let Z=0;const Y=new Array(h),Me=new Array(h);let X=0;const jt=new Uint8Array(p.buffer);for(let F=0;F<h;F++){const te=F<T?H:Nt;Y[F]=jt.slice(Z,Z+te),Me[F]=Ct.encode(Y[F]),Z+=te,X=Math.max(X,te)}const ee=new Uint8Array(b);let Ie=0,P,L;for(P=0;P<X;P++)for(L=0;L<h;L++)P<Y[L].length&&(ee[Ie++]=Y[L][P]);for(P=0;P<Re;P++)for(L=0;L<h;L++)ee[Ie++]=Me[L][P];return ee}function A(p,y,k,b){let E;if(Array.isArray(p))E=g.fromArray(p);else if(typeof p=="string"){let q=y;if(!q){const H=g.rawSplit(p);q=u.getBestVersionForData(H,k)}E=g.fromString(p,q||40)}else throw new Error("Invalid data");const N=u.getBestVersionForData(E,k);if(!N)throw new Error("The amount of data is too big to be stored in a QR Code");if(!y)y=N;else if(y<N)throw new Error(`
|
|
5
|
+
The chosen QR Code version cannot contain this amount of data.
|
|
6
|
+
Minimum version required to store current data is: `+N+`.
|
|
7
|
+
`);const h=C(y,k,E),w=n.getSymbolSize(y),T=new t(w);return x(T,y),j(T),S(T,y),v(T,k,0),y>=7&&R(T,y),B(T,h),isNaN(b)&&(b=a.getBestMask(T,v.bind(null,T,k))),a.applyMask(b,T),v(T,k,b),{modules:T,version:y,errorCorrectionLevel:k,maskPattern:b,segments:E}}return oe.create=function(y,k){if(typeof y>"u"||y==="")throw new Error("No input text");let b=r.M,E,N;return typeof k<"u"&&(b=r.from(k.errorCorrectionLevel,r.M),E=u.from(k.version),N=a.from(k.maskPattern),k.toSJISFunc&&n.setToSJISFunction(k.toSJISFunc)),A(y,E,b,N)},oe}var Ee={},ve={},at;function yt(){return at||(at=1,(function(n){function r(o){if(typeof o=="number"&&(o=o.toString()),typeof o!="string")throw new Error("Color should be defined as hex string");let t=o.slice().replace("#","").split("");if(t.length<3||t.length===5||t.length>8)throw new Error("Invalid hex color: "+o);(t.length===3||t.length===4)&&(t=Array.prototype.concat.apply([],t.map(function(s){return[s,s]}))),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,s=t.width&&t.width>=21?t.width:void 0,a=t.scale||4;return{width:s,scale:s?4:a,margin:e,color:{dark:r(t.color.dark||"#000000ff"),light:r(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 s=n.getScale(t,e);return Math.floor((t+e.margin*2)*s)},n.qrToImageData=function(t,e,s){const a=e.modules.size,c=e.modules.data,l=n.getScale(a,s),u=Math.floor((a+s.margin*2)*l),d=s.margin*l,m=[s.color.light,s.color.dark];for(let g=0;g<u;g++)for(let x=0;x<u;x++){let j=(g*u+x)*4,S=s.color.light;if(g>=d&&x>=d&&g<u-d&&x<u-d){const R=Math.floor((g-d)/l),v=Math.floor((x-d)/l);S=m[c[R*a+v]?1:0]}t[j++]=S.r,t[j++]=S.g,t[j++]=S.b,t[j]=S.a}}})(ve)),ve}var lt;function Xt(){return lt||(lt=1,(function(n){const r=yt();function o(e,s,a){e.clearRect(0,0,s.width,s.height),s.style||(s.style={}),s.height=a,s.width=a,s.style.height=a+"px",s.style.width=a+"px"}function t(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}n.render=function(s,a,c){let l=c,u=a;typeof l>"u"&&(!a||!a.getContext)&&(l=a,a=void 0),a||(u=t()),l=r.getOptions(l);const d=r.getImageWidth(s.modules.size,l),m=u.getContext("2d"),g=m.createImageData(d,d);return r.qrToImageData(g.data,s,l),o(m,u,d),m.putImageData(g,0,0),u},n.renderToDataURL=function(s,a,c){let l=c;typeof l>"u"&&(!a||!a.getContext)&&(l=a,a=void 0),l||(l={});const u=n.render(s,a,l),d=l.type||"image/png",m=l.rendererOpts||{};return u.toDataURL(d,m.quality)}})(Ee)),Ee}var Se={},ct;function en(){if(ct)return Se;ct=1;const n=yt();function r(e,s){const a=e.a/255,c=s+'="'+e.hex+'"';return a<1?c+" "+s+'-opacity="'+a.toFixed(2).slice(1)+'"':c}function o(e,s,a){let c=e+s;return typeof a<"u"&&(c+=" "+a),c}function t(e,s,a){let c="",l=0,u=!1,d=0;for(let m=0;m<e.length;m++){const g=Math.floor(m%s),x=Math.floor(m/s);!g&&!u&&(u=!0),e[m]?(d++,m>0&&g>0&&e[m-1]||(c+=u?o("M",g+a,.5+x+a):o("m",l,0),l=0,u=!1),g+1<s&&e[m+1]||(c+=o("h",d),d=0)):l++}return c}return Se.render=function(s,a,c){const l=n.getOptions(a),u=s.modules.size,d=s.modules.data,m=u+l.margin*2,g=l.color.light.a?"<path "+r(l.color.light,"fill")+' d="M0 0h'+m+"v"+m+'H0z"/>':"",x="<path "+r(l.color.dark,"stroke")+' d="'+t(d,u,l.margin)+'"/>',j='viewBox="0 0 '+m+" "+m+'"',R='<svg xmlns="http://www.w3.org/2000/svg" '+(l.width?'width="'+l.width+'" height="'+l.width+'" ':"")+j+' shape-rendering="crispEdges">'+g+x+`</svg>
|
|
8
|
+
`;return typeof c=="function"&&c(null,R),R},Se}var ut;function tn(){if(ut)return K;ut=1;const n=Lt(),r=Zt(),o=Xt(),t=en();function e(s,a,c,l,u){const d=[].slice.call(arguments,1),m=d.length,g=typeof d[m-1]=="function";if(!g&&!n())throw new Error("Callback required as last argument");if(g){if(m<2)throw new Error("Too few arguments provided");m===2?(u=c,c=a,a=l=void 0):m===3&&(a.getContext&&typeof u>"u"?(u=l,l=void 0):(u=l,l=c,c=a,a=void 0))}else{if(m<1)throw new Error("Too few arguments provided");return m===1?(c=a,a=l=void 0):m===2&&!a.getContext&&(l=c,c=a,a=void 0),new Promise(function(x,j){try{const S=r.create(c,l);x(s(S,a,l))}catch(S){j(S)}})}try{const x=r.create(c,l);u(null,s(x,a,l))}catch(x){u(x)}}return K.create=r.create,K.toCanvas=e.bind(null,o.render),K.toDataURL=e.bind(null,o.renderToDataURL),K.toString=e.bind(null,function(s,a,c){return t.render(s,c)}),K}var nn=tn();const rn=vt(nn),sn=2e3,dt=5;function on({channel:n,onClose:r}){const[o,t]=M.useState("loading"),[e,s]=M.useState(null),[a,c]=M.useState(null),[l,u]=M.useState(""),d=M.useRef(null),m=M.useRef(0),g=M.useRef(null),x=M.useRef(!1),j=()=>{g.current&&(clearTimeout(g.current),g.current=null),x.current=!0},S=async f=>{if(d.current)try{await rn.toCanvas(d.current,f,{width:240,margin:2,color:{dark:"#000000ff",light:"#ffffffff"}})}catch(A){console.warn("[WechatQr] Canvas QR generation failed, falling back to URL:",A)}},R=async()=>{if(!(x.current||!a))try{const f=await Pe.channels.weixin.bindStatus(a),A=(f==null?void 0:f.data)??f,p=(A==null?void 0:A.status)??"";if(m.current=0,p==="confirmed"){t("confirmed"),re.success(n?`微信「${n.name}」重新授权成功,频道已连接`:"微信绑定成功,频道已自动创建并连接"),setTimeout(r,2400);return}if(p==="scaned")t("scanned");else if(p==="expired"){t("expired");return}x.current||(g.current=setTimeout(R,sn))}catch(f){if(m.current++,console.warn("[WechatQr] poll error ("+m.current+"/"+dt+")",f),m.current>=dt)t("error"),u("轮询状态失败次数过多,请刷新二维码重试"),re.error("微信绑定状态轮询失败,请刷新二维码重试");else if(!x.current){const A=Math.min(1e3*Math.pow(2,m.current),1e4);g.current=setTimeout(R,A)}}},v=()=>{j(),x.current=!1,m.current=0,g.current=setTimeout(R,1e3)},B=async()=>{t("loading"),s(null),c(null),u(""),m.current=0;try{const f=await Pe.channels.weixin.bind(),A=(f==null?void 0:f.data)??f,p=(A==null?void 0:A.qrcode_img_content)??"",y=(A==null?void 0:A.qrcode)??"";if(!p||!y){t("error"),u(`二维码数据缺失: ${JSON.stringify(A)}`);return}s(p),c(y),await S(p),t("waiting")}catch(f){t("error");const A=String((f==null?void 0:f.message)??f);u(A),re.error(`获取微信二维码失败:${A}`)}},C=()=>{B()};return M.useEffect(()=>(B(),j),[]),M.useEffect(()=>(a&&v(),j),[a]),i.jsx(Bt,{isOpen:!0,onClose:r,title:`扫码绑定 · ${(n==null?void 0:n.name)??"微信"}`,size:"sm",children:i.jsxs("div",{className:"flex flex-col items-center gap-4 py-2",children:[i.jsxs("div",{className:"relative w-60 h-60 rounded-lg bg-white flex items-center justify-center overflow-hidden",children:[o==="loading"&&i.jsx("span",{className:"text-gray-400 text-sm",children:"二维码生成中..."}),o!=="error"&&o!=="expired"&&i.jsx("canvas",{ref:d,width:240,height:240,className:`w-full h-full object-contain ${o==="waiting"?"":"opacity-30"}`}),o==="scanned"&&i.jsxs("div",{className:"absolute inset-0 bg-black/70 flex flex-col items-center justify-center text-white gap-1",children:[i.jsx("span",{className:"text-2xl",children:"✓"}),i.jsx("span",{className:"text-sm",children:"已扫描,请在手机上确认"})]}),o==="confirmed"&&i.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:[i.jsx("span",{className:"text-2xl",children:"🎉"}),i.jsx("span",{className:"text-sm font-medium",children:"绑定成功"}),i.jsx("span",{className:"text-xs opacity-90",children:n?`「${n.name}」已连接,可开始使用`:"微信频道已创建并连接,可开始使用"}),i.jsx("button",{onClick:r,className:"mt-1 text-xs bg-white/20 hover:bg-white/30 px-3 py-1.5 rounded-md transition-colors",children:"开始使用"})]}),o==="expired"&&i.jsxs("div",{className:"absolute inset-0 bg-black/80 flex flex-col items-center justify-center text-white gap-2",children:[i.jsx("span",{className:"text-sm",children:"二维码已失效"}),i.jsx("button",{onClick:C,className:"text-xs bg-green-600 hover:bg-green-500 px-3 py-1 rounded",children:"点击刷新"})]}),o==="error"&&i.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:[i.jsx("span",{className:"text-xs",children:l||"未知错误"}),i.jsx("button",{onClick:C,className:"text-xs bg-blue-600 hover:bg-blue-500 px-3 py-1 rounded text-white",children:"重试"})]})]}),i.jsxs("p",{className:"text-sm text-dark-muted text-center",children:[o==="waiting"&&"请使用微信扫描二维码授权机器人",o==="scanned"&&"已扫描,请在手机上确认...",o==="confirmed"&&"机器人已授权并启动,即将自动关闭",o==="loading"&&"正在连接 iLink 服务...",(o==="expired"||o==="error")&&(o==="expired"?"二维码已失效":"")]}),e&&o==="waiting"&&i.jsxs("button",{onClick:()=>window.open(e,"_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:[i.jsx("span",{children:"🔔"})," 在新标签页打开(备用)"]})]})})}function hn(){const{load:n,loading:r,qrOpen:o,qrChannel:t,closeQr:e}=Te();return M.useEffect(()=>{n()},[]),i.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-dark-bg text-dark-text",children:[i.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-dark-border shrink-0",children:[i.jsxs("div",{children:[i.jsx("h2",{className:"font-semibold text-base",children:"频道管理"}),i.jsx("p",{className:"text-xs text-dark-muted mt-0.5",children:"接入微信、飞书、钉钉,用户可通过频道发送任务并实时接收进度与结果"})]}),i.jsx("div",{className:"flex items-center gap-2",children:i.jsx("button",{onClick:()=>n(),title:"刷新",className:"p-2 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:i.jsx(St,{className:`w-4 h-4 ${r?"animate-spin":""}`})})})]}),i.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[i.jsx("div",{className:"w-[260px] shrink-0",children:i.jsx(Mt,{})}),i.jsx("div",{className:"flex-1 min-w-0",children:i.jsx(It,{})})]}),o&&i.jsx(on,{channel:t,onClose:e})]})}export{hn as ChannelConfigView};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as s}from"./markdown-BASfeONY.js";import{a as d,L as w,_ as A,aj as F,z as ae,h as ne,af as le,aa as R,b4 as q,b7 as K,a0 as oe,aU as V,E as de,aq as ce,D,l as ie}from"./icons-BXecaLRH.js";import{c as me,a as f}from"./index-CcPIw0Dj.js";import"./react-vendor-7At16BnY.js";import"./state-D4zgKwQs.js";import"./panels-Bod3sKnK.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([]),[H,C]=d.useState(!0),[E,S]=d.useState(null),[j,p]=d.useState({}),[z,m]=d.useState(null),[v,O]=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))},_=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),_(e,!e.enabled)},J=(e,t)=>{g(null),L(n=>({...n,[e.id]:{}})),_(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(D,{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),P=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(H)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(V,{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(V,{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(D,{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=>O(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:P.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:P.map(te)})})]})}export{je as ConnectorsView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as l}from"./markdown-
|
|
1
|
+
import{j as l}from"./markdown-BASfeONY.js";import{a as c,W as J,ad as Se,aE as Ce,h as Me,aM as Ne,aa as ke,u as ce,a7 as Ee,D as le,X as Pe,d as Re,K as Le,aN as $e}from"./icons-BXecaLRH.js";import{a as Q,t as $}from"./index-CcPIw0Dj.js";import"./react-vendor-7At16BnY.js";import"./state-D4zgKwQs.js";import"./panels-Bod3sKnK.js";function ue(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 ze(e){if(Array.isArray(e))return e}function Ae(e,t,r){return(t=qe(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function De(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n,o,u,h,g=[],b=!0,x=!1;try{if(u=(r=r.call(e)).next,t!==0)for(;!(b=(n=u.call(r)).done)&&(g.push(n.value),g.length!==t);b=!0);}catch(M){x=!0,o=M}finally{try{if(!b&&r.return!=null&&(h=r.return(),Object(h)!==h))return}finally{if(x)throw o}}return g}}function Fe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
2
2
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function de(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 fe(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?de(Object(r),!0).forEach(function(n){Ae(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):de(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Te(e,t){if(e==null)return{};var r,n,o=Ie(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 Ie(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 Ve(e,t){return ze(e)||De(e,t)||We(e,t)||Fe()}function Ue(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 qe(e){var t=Ue(e,"string");return typeof t=="symbol"?t:t+""}function We(e,t){if(e){if(typeof e=="string")return ue(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)?ue(e,t):void 0}}function He(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function pe(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 he(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?pe(Object(r),!0).forEach(function(n){He(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):pe(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Be(){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 X(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 h=arguments.length,g=new Array(h),b=0;b<h;b++)g[b]=arguments[b];return t.apply(r,[].concat(o,g))}}}function ne(e){return{}.toString.call(e).includes("Object")}function Ke(e){return!Object.keys(e).length}function _(e){return typeof e=="function"}function Qe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ge(e,t){return ne(t)||A("changeType"),Object.keys(t).some(function(r){return!Qe(e,r)})&&A("changeField"),t}function Je(e){_(e)||A("selectorType")}function Xe(e){_(e)||ne(e)||A("handlerType"),ne(e)&&Object.values(e).some(function(t){return!_(t)})&&A("handlersType")}function Ye(e){e||A("initialIsRequired"),ne(e)||A("initialType"),Ke(e)&&A("initialContent")}function _e(e,t){throw new Error(e[t]||e.default)}var Ze={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=X(_e)(Ze),te={changes:Ge,selector:Je,handler:Xe,initial:Ye};function et(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};te.initial(e),te.handler(t);var r={current:e},n=X(nt)(r,t),o=X(rt)(r),u=X(te.changes)(e),h=X(tt)(r);function g(){var x=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(M){return M};return te.selector(x),x(r.current)}function b(x){Be(n,o,u,h)(x)}return[g,b]}function tt(e,t){return _(t)?t(e.current):t}function rt(e,t){return e.current=he(he({},e.current),t),t}function nt(e,t,r){return _(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 at={create:et},it={paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs"}};function ot(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 h=arguments.length,g=new Array(h),b=0;b<h;b++)g[b]=arguments[b];return t.apply(r,[].concat(o,g))}}}function st(e){return{}.toString.call(e).includes("Object")}function ct(e){return e||me("configIsRequired"),st(e)||me("configType"),e.urls?(lt(),{paths:{vs:e.urls.monacoBase}}):e}function lt(){console.warn(ge.deprecation)}function ut(e,t){throw new Error(e[t]||e.default)}var ge={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
3
|
You are using deprecated way of configuration.
|
|
4
4
|
|
|
@@ -8,4 +8,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
8
8
|
monaco.config({ paths: { vs: '...' } })
|
|
9
9
|
|
|
10
10
|
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
11
|
-
`},me=ot(ut)(ge),dt={config:ct},ft=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,h){return h(u)},o)}};function ve(e,t){return Object.keys(t).forEach(function(r){t[r]instanceof Object&&e[r]&&Object.assign(t[r],ve(e[r],t[r]))}),fe(fe({},e),t)}var pt={type:"cancelation",msg:"operation is manually canceled"};function ie(e){var t=!1,r=new Promise(function(n,o){e.then(function(u){return t?o(pt):n(u)}),e.catch(o)});return r.cancel=function(){return t=!0},r}var ht=["monaco"],mt=at.create({config:it,isInitialized:!1,resolve:null,reject:null,monaco:null}),be=Ve(mt,2),Z=be[0],ae=be[1];function gt(e){var t=dt.config(e),r=t.monaco,n=Te(t,ht);ae(function(o){return{config:ve(o.config,n),monaco:r}})}function vt(){var e=Z(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),ie(oe);if(window.monaco&&window.monaco.editor)return ye(window.monaco),e.resolve(window.monaco),ie(oe);ft(bt,xt)(jt)}return ie(oe)}function bt(e){return document.body.appendChild(e)}function yt(e){var t=document.createElement("script");return e&&(t.src=e),t}function xt(e){var t=Z(function(n){var o=n.config,u=n.reject;return{config:o,reject:u}}),r=yt("".concat(t.config.paths.vs,"/loader.js"));return r.onload=function(){return e()},r.onerror=t.reject,r}function jt(){var e=Z(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;ye(n),e.resolve(n)},function(r){e.reject(r)})}function ye(e){Z().monaco||ae({monaco:e})}function wt(){return Z(function(e){var t=e.monaco;return t})}var oe=new Promise(function(e,t){return ae({resolve:e,reject:t})}),xe={config:gt,init:vt,__getMonacoInstance:wt},Ot={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},se=Ot,St={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},Ct=St;function Mt({children:e}){return J.createElement("div",{style:Ct.container},e)}var Nt=Mt,kt=Nt;function Pt({width:e,height:t,isEditorReady:r,loading:n,_ref:o,className:u,wrapperProps:h}){return J.createElement("section",{style:{...se.wrapper,width:e,height:t},...h},!r&&J.createElement(kt,null,n),J.createElement("div",{ref:o,style:{...se.fullWidth,...!r&&se.hide},className:u}))}var Et=Pt,je=c.memo(Et);function Rt(e){c.useEffect(e,[])}var we=Rt;function Lt(e,t,r=!0){let n=c.useRef(!0);c.useEffect(n.current||!r?()=>{n.current=!1}:e,t)}var C=Lt;function Y(){}function G(e,t,r,n){return $t(e,n)||zt(e,t,r,n)}function $t(e,t){return e.editor.getModel(Oe(e,t))}function zt(e,t,r,n){return e.editor.createModel(t,r,n?Oe(e,n):void 0)}function Oe(e,t){return e.Uri.parse(t)}function At({original:e,modified:t,language:r,originalLanguage:n,modifiedLanguage:o,originalModelPath:u,modifiedModelPath:h,keepCurrentOriginalModel:g=!1,keepCurrentModifiedModel:b=!1,theme:x="light",loading:M="Loading...",options:N={},height:I="100%",width:V="100%",className:U,wrapperProps:q={},beforeMount:W=Y,onMount:H=Y}){let[j,D]=c.useState(!1),[E,y]=c.useState(!0),w=c.useRef(null),v=c.useRef(null),F=c.useRef(null),O=c.useRef(H),p=c.useRef(W),R=c.useRef(!1);we(()=>{let d=xe.init();return d.then(m=>(v.current=m)&&y(!1)).catch(m=>(m==null?void 0:m.type)!=="cancelation"&&console.error("Monaco initialization: error:",m)),()=>w.current?z():d.cancel()}),C(()=>{if(w.current&&v.current){let d=w.current.getOriginalEditor(),m=G(v.current,e||"",n||r||"text",u||"");m!==d.getModel()&&d.setModel(m)}},[u],j),C(()=>{if(w.current&&v.current){let d=w.current.getModifiedEditor(),m=G(v.current,t||"",o||r||"text",h||"");m!==d.getModel()&&d.setModel(m)}},[h],j),C(()=>{let d=w.current.getModifiedEditor();d.getOption(v.current.editor.EditorOption.readOnly)?d.setValue(t||""):t!==d.getValue()&&(d.executeEdits("",[{range:d.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),d.pushUndoStop())},[t],j),C(()=>{var d,m;(m=(d=w.current)==null?void 0:d.getModel())==null||m.original.setValue(e||"")},[e],j),C(()=>{let{original:d,modified:m}=w.current.getModel();v.current.editor.setModelLanguage(d,n||r||"text"),v.current.editor.setModelLanguage(m,o||r||"text")},[r,n,o],j),C(()=>{var d;(d=v.current)==null||d.editor.setTheme(x)},[x],j),C(()=>{var d;(d=w.current)==null||d.updateOptions(N)},[N],j);let B=c.useCallback(()=>{var k;if(!v.current)return;p.current(v.current);let d=G(v.current,e||"",n||r||"text",u||""),m=G(v.current,t||"",o||r||"text",h||"");(k=w.current)==null||k.setModel({original:d,modified:m})},[r,t,o,e,n,u,h]),K=c.useCallback(()=>{var d;!R.current&&F.current&&(w.current=v.current.editor.createDiffEditor(F.current,{automaticLayout:!0,...N}),B(),(d=v.current)==null||d.editor.setTheme(x),D(!0),R.current=!0)},[N,x,B]);c.useEffect(()=>{j&&O.current(w.current,v.current)},[j]),c.useEffect(()=>{!E&&!j&&K()},[E,j,K]);function z(){var m,k,L,T;let d=(m=w.current)==null?void 0:m.getModel();g||((k=d==null?void 0:d.original)==null||k.dispose()),b||((L=d==null?void 0:d.modified)==null||L.dispose()),(T=w.current)==null||T.dispose()}return J.createElement(je,{width:V,height:I,isEditorReady:j,loading:M,_ref:F,className:U,wrapperProps:q})}var Dt=At;c.memo(Dt);function Ft(e){let t=c.useRef();return c.useEffect(()=>{t.current=e},[e]),t.current}var Tt=Ft,re=new Map;function It({defaultValue:e,defaultLanguage:t,defaultPath:r,value:n,language:o,path:u,theme:h="light",line:g,loading:b="Loading...",options:x={},overrideServices:M={},saveViewState:N=!0,keepCurrentModel:I=!1,width:V="100%",height:U="100%",className:q,wrapperProps:W={},beforeMount:H=Y,onMount:j=Y,onChange:D,onValidate:E=Y}){let[y,w]=c.useState(!1),[v,F]=c.useState(!0),O=c.useRef(null),p=c.useRef(null),R=c.useRef(null),B=c.useRef(j),K=c.useRef(H),z=c.useRef(),d=c.useRef(n),m=Tt(u),k=c.useRef(!1),L=c.useRef(!1);we(()=>{let a=xe.init();return a.then(s=>(O.current=s)&&F(!1)).catch(s=>(s==null?void 0:s.type)!=="cancelation"&&console.error("Monaco initialization: error:",s)),()=>p.current?i():a.cancel()}),C(()=>{var s,f,S,P;let a=G(O.current,e||n||"",t||o||"",u||r||"");a!==((s=p.current)==null?void 0:s.getModel())&&(N&&re.set(m,(f=p.current)==null?void 0:f.saveViewState()),(S=p.current)==null||S.setModel(a),N&&((P=p.current)==null||P.restoreViewState(re.get(u))))},[u],y),C(()=>{var a;(a=p.current)==null||a.updateOptions(x)},[x],y),C(()=>{!p.current||n===void 0||(p.current.getOption(O.current.editor.EditorOption.readOnly)?p.current.setValue(n):n!==p.current.getValue()&&(L.current=!0,p.current.executeEdits("",[{range:p.current.getModel().getFullModelRange(),text:n,forceMoveMarkers:!0}]),p.current.pushUndoStop(),L.current=!1))},[n],y),C(()=>{var s,f;let a=(s=p.current)==null?void 0:s.getModel();a&&o&&((f=O.current)==null||f.editor.setModelLanguage(a,o))},[o],y),C(()=>{var a;g!==void 0&&((a=p.current)==null||a.revealLine(g))},[g],y),C(()=>{var a;(a=O.current)==null||a.editor.setTheme(h)},[h],y);let T=c.useCallback(()=>{var a;if(!(!R.current||!O.current)&&!k.current){K.current(O.current);let s=u||r,f=G(O.current,n||e||"",t||o||"",s||"");p.current=(a=O.current)==null?void 0:a.editor.create(R.current,{model:f,automaticLayout:!0,...x},M),N&&p.current.restoreViewState(re.get(s)),O.current.editor.setTheme(h),g!==void 0&&p.current.revealLine(g),w(!0),k.current=!0}},[e,t,r,n,o,u,x,M,N,h,g]);c.useEffect(()=>{y&&B.current(p.current,O.current)},[y]),c.useEffect(()=>{!v&&!y&&T()},[v,y,T]),d.current=n,c.useEffect(()=>{var a,s;y&&D&&((a=z.current)==null||a.dispose(),z.current=(s=p.current)==null?void 0:s.onDidChangeModelContent(f=>{L.current||D(p.current.getValue(),f)}))},[y,D]),c.useEffect(()=>{if(y){let a=O.current.editor.onDidChangeMarkers(s=>{var S;let f=(S=p.current.getModel())==null?void 0:S.uri;if(f&&s.find(P=>P.path===f.path)){let P=O.current.editor.getModelMarkers({resource:f});E==null||E(P)}});return()=>{a==null||a.dispose()}}return()=>{}},[y,E]);function i(){var a,s;(a=z.current)==null||a.dispose(),I?N&&re.set(u,p.current.saveViewState()):(s=p.current.getModel())==null||s.dispose(),p.current.dispose()}return J.createElement(je,{width:V,height:U,isEditorReady:y,loading:b,_ref:R,className:q,wrapperProps:W})}var Vt=It,Ut=c.memo(Vt),qt=Ut;function Wt(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 Jt(){const[e,t]=c.useState([]),[r,n]=c.useState(null),[o,u]=c.useState(""),[h,g]=c.useState(""),[b,x]=c.useState(!1),[M,N]=c.useState(""),[I,V]=c.useState(!1),[U,q]=c.useState(!1),[W,H]=c.useState(!1),[j,D]=c.useState(""),E=c.useRef(null);c.useEffect(()=>{if(!r){u(""),g("");return}x(!0),Q.files.read(r).then(i=>{if(i.success&&i.data){const a=typeof i.data=="string"?i.data:JSON.stringify(i.data);u(a),g(a)}else $.error(i.error||"读取文件失败")}).catch(()=>$.error("读取文件失败")).finally(()=>x(!1))},[r]);const y=async i=>{V(!0);try{const a=await Q.files.list(i);a.success&&Array.isArray(a.data)&&t(a.data.map(s=>({...s,expanded:!1})))}finally{V(!1)}},w=async i=>{if(i.type==="directory")try{const a=await Q.files.list(i.path);if(a.success&&Array.isArray(a.data)){const s=a.data.map(f=>({...f,expanded:!1}));t(f=>v(f,i.id,s))}}catch{}},v=(i,a,s)=>i.map(f=>f.id===a?{...f,children:s,expanded:!0}:f.children?{...f,children:v(f.children,a,s)}:f);c.useEffect(()=>{y()},[]);const F=i=>{const a=p(e,i);if(a&&a.type==="directory"&&!a.children){w(a);return}t(s=>O(s,i))},O=(i,a)=>i.map(s=>s.id===a&&s.type==="directory"?{...s,expanded:!s.expanded}:s.children?{...s,children:O(s.children,a)}:s),p=(i,a)=>{for(const s of i){if(s.id===a)return s;if(s.children){const f=p(s.children,a);if(f)return f}}return null},R=(i,a)=>a?i.reduce((s,f)=>{if(f.name.toLowerCase().includes(a.toLowerCase()))s.push(f);else if(f.children){const S=R(f.children,a);S.length>0&&s.push({...f,children:S,expanded:!0})}return s},[]):i,B=c.useCallback(async()=>{if(r){q(!0);try{const i=await Q.files.update(r,o);i.success?(g(o),$.success("文件已保存")):$.error(i.error||"保存失败")}catch{$.error("保存失败")}finally{q(!1)}}},[r,o]),K=()=>{n(null),u(""),g("")},z=c.useCallback(async i=>{const a=await Q.files.download(i);a.success?$.success("已开始下载"):$.error(a.error||"下载失败")},[]),d=()=>{var i;return(i=E.current)==null?void 0:i.click()},m=c.useCallback(async i=>{if(!i||i.length===0)return;const a=j||(r?r.replace(/[\\/][^\\/]+$/,""):"");H(!0);let s=0,f=0;for(const S of Array.from(i)){const P=a?`${a}/${S.name}`:S.name;(await Q.files.upload(S,P)).success?s++:f++}H(!1),s>0&&$.success(`已上传 ${s} 个文件`),f>0&&$.error(`${f} 个文件上传失败`),await y()},[j,r]),k=o!==h,L=(i,a=0)=>{var P;const s=i.type==="directory",f=r===i.path,S=j===i.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:`${a*14+6}px`},onClick:()=>s?(D(i.path),F(i.id)):n(i.path),title:s?"点击设为上传目录并展开":i.path,children:[s&&l.jsx("span",{className:"text-dark-muted shrink-0",children:i.expanded?l.jsx(Re,{size:12}):l.jsx(Le,{size:12})}),s?l.jsx($e,{size:12,className:"text-accent-yellow shrink-0"}):l.jsx("span",{className:"w-3"}),l.jsx("span",{className:"truncate flex-1",children:i.name}),!s&&l.jsx("button",{onClick:ee=>{ee.stopPropagation(),z(i.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:"下载",children:l.jsx(le,{size:11})})]}),s&&i.expanded&&((P=i.children)==null?void 0:P.map(ee=>L(ee,a+1)))]},i.id)},T=M?R(e,M):e;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(Se,{size:14}),"文件浏览器"]}),l.jsxs("div",{className:"flex items-center gap-0.5",children:[l.jsx("button",{onClick:d,disabled:W,className:"p-1 rounded hover:bg-dark-hover disabled:opacity-50",title:j?`上传到 ${j}`:"上传到工作区根目录",children:l.jsx(Ce,{size:12,className:W?"animate-pulse":""})}),l.jsx("button",{onClick:()=>y(),disabled:I,className:"p-1 rounded hover:bg-dark-hover",title:"刷新",children:l.jsx(Me,{size:12,className:I?"animate-spin":""})}),l.jsx("button",{onClick:()=>{t(e.map(i=>({...i,expanded:!1}))),n(null)},className:"p-1 rounded hover:bg-dark-hover",title:"折叠",children:l.jsx(Ne,{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:M,onChange:i=>N(i.target.value),placeholder:"搜索...",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:T.map(i=>L(i))}),l.jsx("input",{ref:E,type:"file",multiple:!0,className:"hidden",onChange:i=>{m(i.target.files),i.currentTarget.value=""}})]}),l.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-dark-bg",children:r?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(ce,{size:12,className:"text-dark-muted shrink-0"}),l.jsx("span",{className:"truncate",children:r}),k&&l.jsx("span",{className:"text-accent-yellow text-[10px] shrink-0",children:"● 已修改"})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs("button",{onClick:B,disabled:!k||U,className:`px-2 py-0.5 text-[10px] rounded flex items-center gap-1 transition-colors ${k?"bg-accent-green text-white hover:opacity-90":"bg-dark-border text-dark-muted cursor-not-allowed"}`,children:[l.jsx(Pe,{size:10}),U?"保存中...":"保存"]}),l.jsx("button",{onClick:()=>void z(r),className:"p-1 rounded hover:bg-dark-hover",title:"下载",children:l.jsx(le,{size:12})}),l.jsx("button",{onClick:K,className:"p-1 rounded hover:bg-dark-hover",title:"关闭",children:l.jsx(Ee,{size:12})})]})]}),l.jsx("div",{className:"flex-1 min-h-0",children:b?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(qt,{language:Wt(r),value:o,onChange:i=>u(i||""),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(ce,{size:32,className:"text-dark-muted mx-auto mb-2"}),l.jsx("p",{className:"text-sm text-dark-muted",children:"选择文件以预览或编辑"})]})})})]})}export{Jt as FileTreeView,Jt as default};
|
|
11
|
+
`},me=ot(ut)(ge),dt={config:ct},ft=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,h){return h(u)},o)}};function ve(e,t){return Object.keys(t).forEach(function(r){t[r]instanceof Object&&e[r]&&Object.assign(t[r],ve(e[r],t[r]))}),fe(fe({},e),t)}var pt={type:"cancelation",msg:"operation is manually canceled"};function ie(e){var t=!1,r=new Promise(function(n,o){e.then(function(u){return t?o(pt):n(u)}),e.catch(o)});return r.cancel=function(){return t=!0},r}var ht=["monaco"],mt=at.create({config:it,isInitialized:!1,resolve:null,reject:null,monaco:null}),be=Ve(mt,2),Z=be[0],ae=be[1];function gt(e){var t=dt.config(e),r=t.monaco,n=Te(t,ht);ae(function(o){return{config:ve(o.config,n),monaco:r}})}function vt(){var e=Z(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),ie(oe);if(window.monaco&&window.monaco.editor)return ye(window.monaco),e.resolve(window.monaco),ie(oe);ft(bt,xt)(jt)}return ie(oe)}function bt(e){return document.body.appendChild(e)}function yt(e){var t=document.createElement("script");return e&&(t.src=e),t}function xt(e){var t=Z(function(n){var o=n.config,u=n.reject;return{config:o,reject:u}}),r=yt("".concat(t.config.paths.vs,"/loader.js"));return r.onload=function(){return e()},r.onerror=t.reject,r}function jt(){var e=Z(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;ye(n),e.resolve(n)},function(r){e.reject(r)})}function ye(e){Z().monaco||ae({monaco:e})}function wt(){return Z(function(e){var t=e.monaco;return t})}var oe=new Promise(function(e,t){return ae({resolve:e,reject:t})}),xe={config:gt,init:vt,__getMonacoInstance:wt},Ot={wrapper:{display:"flex",position:"relative",textAlign:"initial"},fullWidth:{width:"100%"},hide:{display:"none"}},se=Ot,St={container:{display:"flex",height:"100%",width:"100%",justifyContent:"center",alignItems:"center"}},Ct=St;function Mt({children:e}){return J.createElement("div",{style:Ct.container},e)}var Nt=Mt,kt=Nt;function Et({width:e,height:t,isEditorReady:r,loading:n,_ref:o,className:u,wrapperProps:h}){return J.createElement("section",{style:{...se.wrapper,width:e,height:t},...h},!r&&J.createElement(kt,null,n),J.createElement("div",{ref:o,style:{...se.fullWidth,...!r&&se.hide},className:u}))}var Pt=Et,je=c.memo(Pt);function Rt(e){c.useEffect(e,[])}var we=Rt;function Lt(e,t,r=!0){let n=c.useRef(!0);c.useEffect(n.current||!r?()=>{n.current=!1}:e,t)}var C=Lt;function Y(){}function G(e,t,r,n){return $t(e,n)||zt(e,t,r,n)}function $t(e,t){return e.editor.getModel(Oe(e,t))}function zt(e,t,r,n){return e.editor.createModel(t,r,n?Oe(e,n):void 0)}function Oe(e,t){return e.Uri.parse(t)}function At({original:e,modified:t,language:r,originalLanguage:n,modifiedLanguage:o,originalModelPath:u,modifiedModelPath:h,keepCurrentOriginalModel:g=!1,keepCurrentModifiedModel:b=!1,theme:x="light",loading:M="Loading...",options:N={},height:I="100%",width:V="100%",className:U,wrapperProps:q={},beforeMount:W=Y,onMount:H=Y}){let[j,D]=c.useState(!1),[P,y]=c.useState(!0),w=c.useRef(null),v=c.useRef(null),F=c.useRef(null),O=c.useRef(H),p=c.useRef(W),R=c.useRef(!1);we(()=>{let d=xe.init();return d.then(m=>(v.current=m)&&y(!1)).catch(m=>(m==null?void 0:m.type)!=="cancelation"&&console.error("Monaco initialization: error:",m)),()=>w.current?z():d.cancel()}),C(()=>{if(w.current&&v.current){let d=w.current.getOriginalEditor(),m=G(v.current,e||"",n||r||"text",u||"");m!==d.getModel()&&d.setModel(m)}},[u],j),C(()=>{if(w.current&&v.current){let d=w.current.getModifiedEditor(),m=G(v.current,t||"",o||r||"text",h||"");m!==d.getModel()&&d.setModel(m)}},[h],j),C(()=>{let d=w.current.getModifiedEditor();d.getOption(v.current.editor.EditorOption.readOnly)?d.setValue(t||""):t!==d.getValue()&&(d.executeEdits("",[{range:d.getModel().getFullModelRange(),text:t||"",forceMoveMarkers:!0}]),d.pushUndoStop())},[t],j),C(()=>{var d,m;(m=(d=w.current)==null?void 0:d.getModel())==null||m.original.setValue(e||"")},[e],j),C(()=>{let{original:d,modified:m}=w.current.getModel();v.current.editor.setModelLanguage(d,n||r||"text"),v.current.editor.setModelLanguage(m,o||r||"text")},[r,n,o],j),C(()=>{var d;(d=v.current)==null||d.editor.setTheme(x)},[x],j),C(()=>{var d;(d=w.current)==null||d.updateOptions(N)},[N],j);let B=c.useCallback(()=>{var k;if(!v.current)return;p.current(v.current);let d=G(v.current,e||"",n||r||"text",u||""),m=G(v.current,t||"",o||r||"text",h||"");(k=w.current)==null||k.setModel({original:d,modified:m})},[r,t,o,e,n,u,h]),K=c.useCallback(()=>{var d;!R.current&&F.current&&(w.current=v.current.editor.createDiffEditor(F.current,{automaticLayout:!0,...N}),B(),(d=v.current)==null||d.editor.setTheme(x),D(!0),R.current=!0)},[N,x,B]);c.useEffect(()=>{j&&O.current(w.current,v.current)},[j]),c.useEffect(()=>{!P&&!j&&K()},[P,j,K]);function z(){var m,k,L,T;let d=(m=w.current)==null?void 0:m.getModel();g||((k=d==null?void 0:d.original)==null||k.dispose()),b||((L=d==null?void 0:d.modified)==null||L.dispose()),(T=w.current)==null||T.dispose()}return J.createElement(je,{width:V,height:I,isEditorReady:j,loading:M,_ref:F,className:U,wrapperProps:q})}var Dt=At;c.memo(Dt);function Ft(e){let t=c.useRef();return c.useEffect(()=>{t.current=e},[e]),t.current}var Tt=Ft,re=new Map;function It({defaultValue:e,defaultLanguage:t,defaultPath:r,value:n,language:o,path:u,theme:h="light",line:g,loading:b="Loading...",options:x={},overrideServices:M={},saveViewState:N=!0,keepCurrentModel:I=!1,width:V="100%",height:U="100%",className:q,wrapperProps:W={},beforeMount:H=Y,onMount:j=Y,onChange:D,onValidate:P=Y}){let[y,w]=c.useState(!1),[v,F]=c.useState(!0),O=c.useRef(null),p=c.useRef(null),R=c.useRef(null),B=c.useRef(j),K=c.useRef(H),z=c.useRef(),d=c.useRef(n),m=Tt(u),k=c.useRef(!1),L=c.useRef(!1);we(()=>{let a=xe.init();return a.then(s=>(O.current=s)&&F(!1)).catch(s=>(s==null?void 0:s.type)!=="cancelation"&&console.error("Monaco initialization: error:",s)),()=>p.current?i():a.cancel()}),C(()=>{var s,f,S,E;let a=G(O.current,e||n||"",t||o||"",u||r||"");a!==((s=p.current)==null?void 0:s.getModel())&&(N&&re.set(m,(f=p.current)==null?void 0:f.saveViewState()),(S=p.current)==null||S.setModel(a),N&&((E=p.current)==null||E.restoreViewState(re.get(u))))},[u],y),C(()=>{var a;(a=p.current)==null||a.updateOptions(x)},[x],y),C(()=>{!p.current||n===void 0||(p.current.getOption(O.current.editor.EditorOption.readOnly)?p.current.setValue(n):n!==p.current.getValue()&&(L.current=!0,p.current.executeEdits("",[{range:p.current.getModel().getFullModelRange(),text:n,forceMoveMarkers:!0}]),p.current.pushUndoStop(),L.current=!1))},[n],y),C(()=>{var s,f;let a=(s=p.current)==null?void 0:s.getModel();a&&o&&((f=O.current)==null||f.editor.setModelLanguage(a,o))},[o],y),C(()=>{var a;g!==void 0&&((a=p.current)==null||a.revealLine(g))},[g],y),C(()=>{var a;(a=O.current)==null||a.editor.setTheme(h)},[h],y);let T=c.useCallback(()=>{var a;if(!(!R.current||!O.current)&&!k.current){K.current(O.current);let s=u||r,f=G(O.current,n||e||"",t||o||"",s||"");p.current=(a=O.current)==null?void 0:a.editor.create(R.current,{model:f,automaticLayout:!0,...x},M),N&&p.current.restoreViewState(re.get(s)),O.current.editor.setTheme(h),g!==void 0&&p.current.revealLine(g),w(!0),k.current=!0}},[e,t,r,n,o,u,x,M,N,h,g]);c.useEffect(()=>{y&&B.current(p.current,O.current)},[y]),c.useEffect(()=>{!v&&!y&&T()},[v,y,T]),d.current=n,c.useEffect(()=>{var a,s;y&&D&&((a=z.current)==null||a.dispose(),z.current=(s=p.current)==null?void 0:s.onDidChangeModelContent(f=>{L.current||D(p.current.getValue(),f)}))},[y,D]),c.useEffect(()=>{if(y){let a=O.current.editor.onDidChangeMarkers(s=>{var S;let f=(S=p.current.getModel())==null?void 0:S.uri;if(f&&s.find(E=>E.path===f.path)){let E=O.current.editor.getModelMarkers({resource:f});P==null||P(E)}});return()=>{a==null||a.dispose()}}return()=>{}},[y,P]);function i(){var a,s;(a=z.current)==null||a.dispose(),I?N&&re.set(u,p.current.saveViewState()):(s=p.current.getModel())==null||s.dispose(),p.current.dispose()}return J.createElement(je,{width:V,height:U,isEditorReady:y,loading:b,_ref:R,className:q,wrapperProps:W})}var Vt=It,Ut=c.memo(Vt),qt=Ut;function Wt(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 Xt(){const[e,t]=c.useState([]),[r,n]=c.useState(null),[o,u]=c.useState(""),[h,g]=c.useState(""),[b,x]=c.useState(!1),[M,N]=c.useState(""),[I,V]=c.useState(!1),[U,q]=c.useState(!1),[W,H]=c.useState(!1),[j,D]=c.useState(""),P=c.useRef(null);c.useEffect(()=>{if(!r){u(""),g("");return}x(!0),Q.files.read(r).then(i=>{if(i.success&&i.data){const a=typeof i.data=="string"?i.data:JSON.stringify(i.data);u(a),g(a)}else $.error(i.error||"读取文件失败")}).catch(()=>$.error("读取文件失败")).finally(()=>x(!1))},[r]);const y=async i=>{V(!0);try{const a=await Q.files.list(i);a.success&&Array.isArray(a.data)&&t(a.data.map(s=>({...s,expanded:!1})))}finally{V(!1)}},w=async i=>{if(i.type==="directory")try{const a=await Q.files.list(i.path);if(a.success&&Array.isArray(a.data)){const s=a.data.map(f=>({...f,expanded:!1}));t(f=>v(f,i.id,s))}}catch{}},v=(i,a,s)=>i.map(f=>f.id===a?{...f,children:s,expanded:!0}:f.children?{...f,children:v(f.children,a,s)}:f);c.useEffect(()=>{y()},[]);const F=i=>{const a=p(e,i);if(a&&a.type==="directory"&&!a.children){w(a);return}t(s=>O(s,i))},O=(i,a)=>i.map(s=>s.id===a&&s.type==="directory"?{...s,expanded:!s.expanded}:s.children?{...s,children:O(s.children,a)}:s),p=(i,a)=>{for(const s of i){if(s.id===a)return s;if(s.children){const f=p(s.children,a);if(f)return f}}return null},R=(i,a)=>a?i.reduce((s,f)=>{if(f.name.toLowerCase().includes(a.toLowerCase()))s.push(f);else if(f.children){const S=R(f.children,a);S.length>0&&s.push({...f,children:S,expanded:!0})}return s},[]):i,B=c.useCallback(async()=>{if(r){q(!0);try{const i=await Q.files.update(r,o);i.success?(g(o),$.success("文件已保存")):$.error(i.error||"保存失败")}catch{$.error("保存失败")}finally{q(!1)}}},[r,o]),K=()=>{n(null),u(""),g("")},z=c.useCallback(async i=>{const a=await Q.files.download(i);a.success?$.success("已开始下载"):$.error(a.error||"下载失败")},[]),d=()=>{var i;return(i=P.current)==null?void 0:i.click()},m=c.useCallback(async i=>{if(!i||i.length===0)return;const a=j||(r?r.replace(/[\\/][^\\/]+$/,""):"");H(!0);let s=0,f=0;for(const S of Array.from(i)){const E=a?`${a}/${S.name}`:S.name;(await Q.files.upload(S,E)).success?s++:f++}H(!1),s>0&&$.success(`已上传 ${s} 个文件`),f>0&&$.error(`${f} 个文件上传失败`),await y()},[j,r]),k=o!==h,L=(i,a=0)=>{var E;const s=i.type==="directory",f=r===i.path,S=j===i.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:`${a*14+6}px`},onClick:()=>s?(D(i.path),F(i.id)):n(i.path),title:s?"点击设为上传目录并展开":i.path,children:[s&&l.jsx("span",{className:"text-dark-muted shrink-0",children:i.expanded?l.jsx(Re,{size:12}):l.jsx(Le,{size:12})}),s?l.jsx($e,{size:12,className:"text-accent-yellow shrink-0"}):l.jsx("span",{className:"w-3"}),l.jsx("span",{className:"truncate flex-1",children:i.name}),!s&&l.jsx("button",{onClick:ee=>{ee.stopPropagation(),z(i.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:"下载",children:l.jsx(le,{size:11})})]}),s&&i.expanded&&((E=i.children)==null?void 0:E.map(ee=>L(ee,a+1)))]},i.id)},T=M?R(e,M):e;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(Se,{size:14}),"文件浏览器"]}),l.jsxs("div",{className:"flex items-center gap-0.5",children:[l.jsx("button",{onClick:d,disabled:W,className:"p-1 rounded hover:bg-dark-hover disabled:opacity-50",title:j?`上传到 ${j}`:"上传到工作区根目录",children:l.jsx(Ce,{size:12,className:W?"animate-pulse":""})}),l.jsx("button",{onClick:()=>y(),disabled:I,className:"p-1 rounded hover:bg-dark-hover",title:"刷新",children:l.jsx(Me,{size:12,className:I?"animate-spin":""})}),l.jsx("button",{onClick:()=>{t(e.map(i=>({...i,expanded:!1}))),n(null)},className:"p-1 rounded hover:bg-dark-hover",title:"折叠",children:l.jsx(Ne,{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:M,onChange:i=>N(i.target.value),placeholder:"搜索...",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:T.map(i=>L(i))}),l.jsx("input",{ref:P,type:"file",multiple:!0,className:"hidden",onChange:i=>{m(i.target.files),i.currentTarget.value=""}})]}),l.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-dark-bg",children:r?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(ce,{size:12,className:"text-dark-muted shrink-0"}),l.jsx("span",{className:"truncate",children:r}),k&&l.jsx("span",{className:"text-accent-yellow text-[10px] shrink-0",children:"● 已修改"})]}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs("button",{onClick:B,disabled:!k||U,className:`px-2 py-0.5 text-[10px] rounded flex items-center gap-1 transition-colors ${k?"bg-accent-green text-white hover:opacity-90":"bg-dark-border text-dark-muted cursor-not-allowed"}`,children:[l.jsx(Ee,{size:10}),U?"保存中...":"保存"]}),l.jsx("button",{onClick:()=>void z(r),className:"p-1 rounded hover:bg-dark-hover",title:"下载",children:l.jsx(le,{size:12})}),l.jsx("button",{onClick:K,className:"p-1 rounded hover:bg-dark-hover",title:"关闭",children:l.jsx(Pe,{size:12})})]})]}),l.jsx("div",{className:"flex-1 min-h-0",children:b?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(qt,{language:Wt(r),value:o,onChange:i=>u(i||""),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(ce,{size:32,className:"text-dark-muted mx-auto mb-2"}),l.jsx("p",{className:"text-sm text-dark-muted",children:"选择文件以预览或编辑"})]})})})]})}export{Xt as FileTreeView,Xt as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{j as e}from"./markdown-BASfeONY.js";import{a as N,aJ as E,S as P,aK as U,aq as D,X as O,f as $,y as Y,K as G,aL as J,ay as _,az as B,h as W,aE as q,D as K,z as V}from"./icons-BXecaLRH.js";import{c as X}from"./state-D4zgKwQs.js";import{a as f}from"./index-CcPIw0Dj.js";import"./react-vendor-7At16BnY.js";import"./panels-Bod3sKnK.js";const A=X((l,o)=>({rules:[],stats:null,events:[],agents:[],loading:!1,error:null,fieldErrors:null,formOpen:!1,editingRule:null,dryRunResult:null,loadRules:async()=>{const s=await f.hooks.list();s.success&&Array.isArray(s.data)?l({rules:s.data}):s.success&&s.data&&!Array.isArray(s.data)?l({error:"服务端返回的规则数据格式异常"}):l({error:s.error||"Failed to load rules"})},loadStats:async()=>{const s=await f.hooks.stats();s.success&&s.data&&l({stats:s.data})},loadEvents:async()=>{const s=await f.hooks.events();s.success&&Array.isArray(s.data)?l({events:s.data}):s.success&&s.data&&!Array.isArray(s.data)&&l({error:"服务端返回的事件数据格式异常"})},loadAgents:async()=>{const s=await f.hooks.agents();s.success&&Array.isArray(s.data)?l({agents:s.data}):s.success&&s.data&&!Array.isArray(s.data)&&l({error:"服务端返回的Agent数据格式异常"})},loadAll:async()=>{l({loading:!0,error:null});try{await Promise.all([o().loadRules(),o().loadStats(),o().loadEvents(),o().loadAgents()])}catch(s){l({error:String(s)})}finally{l({loading:!1})}},createRule:async s=>{l({fieldErrors:null});const r=await f.hooks.create(s);if(r.success)return await o().loadRules(),await o().loadStats(),l({formOpen:!1,editingRule:null}),!0;if(r.error){l({error:r.error});try{const i=JSON.parse(r.error);i.fieldErrors&&l({fieldErrors:i.fieldErrors})}catch{}}return!1},updateRule:async(s,r)=>{l({fieldErrors:null});const i=await f.hooks.update(s,r);return i.success?(await o().loadRules(),l({formOpen:!1,editingRule:null}),!0):(l({error:i.error||"Update failed"}),!1)},deleteRule:async s=>{const r=await f.hooks.delete(s);return r.success?(await o().loadRules(),await o().loadStats(),!0):(l({error:r.error||"Delete failed"}),!1)},batchDelete:async s=>{const r=await f.hooks.batchDelete(s);return r.success?(await o().loadRules(),await o().loadStats(),!0):(l({error:r.error||"Batch delete failed"}),!1)},toggleRule:async(s,r)=>(await f.hooks.toggle(s,r)).success?(l(v=>({rules:v.rules.map(d=>d.name===s?{...d,enabled:r}:d)})),!0):(await o().loadRules(),!1),batchToggle:async(s,r)=>(await f.hooks.batchToggle(s,r)).success?(l(v=>({rules:v.rules.map(d=>s.includes(d.name)?{...d,enabled:r}:d)})),!0):(await o().loadRules(),!1),dryRun:async s=>{const r=await f.hooks.dryRun(s);return r.success&&r.data?(l({dryRunResult:r.data}),r.data):(l({error:r.error||"Dry-run failed"}),null)},openForm:s=>l({formOpen:!0,editingRule:s||null,dryRunResult:null,fieldErrors:null}),closeForm:()=>l({formOpen:!1,editingRule:null,dryRunResult:null,fieldErrors:null}),setDryRunResult:s=>l({dryRunResult:s}),clearError:()=>l({error:null}),clearFieldErrors:()=>l({fieldErrors:null})})),Q={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"},Z={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 ee({rules:l,onEdit:o}){const{toggleRule:s,deleteRule:r,batchDelete:i,batchToggle:v}=A(),[d,h]=N.useState(new Set),[w,k]=N.useState(!1),y=Array.isArray(l)?l:[];if(y.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:"暂无 Hook 规则"}),e.jsx("p",{className:"text-xs text-dark-muted/70",children:'点击右上角"新增规则"创建第一个 Hook'})]});const S=t=>{const m=new Set(d);m.has(t)?m.delete(t):m.add(t),h(m),k(m.size===y.length)},p=()=>{w?(h(new Set),k(!1)):(h(new Set(y.map(t=>t.name))),k(!0))},u=()=>{d.size!==0&&confirm(`确认删除 ${d.size} 条规则?`)&&(i(Array.from(d)),h(new Set),k(!1))},j=t=>{d.size!==0&&(v(Array.from(d),t),h(new Set),k(!1))};return e.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[d.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.jsxs("span",{className:"text-dark-muted",children:["已选 ",d.size," 项"]}),e.jsx("button",{onClick:()=>j(!0),className:"rounded bg-accent-green/15 px-2 py-0.5 text-accent-green transition-colors hover:bg-accent-green/25",children:"全部启用"}),e.jsx("button",{onClick:()=>j(!1),className:"rounded bg-dark-hover px-2 py-0.5 text-dark-text transition-colors hover:bg-dark-border",children:"全部禁用"}),e.jsx("button",{onClick:u,className:"rounded bg-accent-red/15 px-2 py-0.5 text-accent-red transition-colors hover:bg-accent-red/25",children:"删除"})]}),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:p,children:w?e.jsx(E,{size:14}):e.jsx(P,{size:14})})}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"名称"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"事件"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"类型"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"优先级"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"状态"}),e.jsx("th",{className:"p-2.5 text-right font-medium",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-dark-border",children:y.map(t=>e.jsxs("tr",{className:"transition-colors hover:bg-dark-hover/50",children:[e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>S(t.name),children:d.has(t.name)?e.jsx(E,{size:14,className:"text-accent-blue"}):e.jsx(P,{size:14,className:"text-dark-muted"})})}),e.jsxs("td",{className:"p-2.5",children:[e.jsx("div",{className:"font-medium text-dark-text",children:t.name}),t.description&&e.jsx("div",{className:"mt-0.5 max-w-[220px] truncate text-xs text-dark-muted",children:t.description})]}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[Array.isArray(t.events)&&t.events.slice(0,3).map(m=>e.jsx("span",{className:"rounded bg-dark-hover px-1.5 py-0.5 text-xs text-dark-text",children:m},m)),Array.isArray(t.events)&&t.events.length>3&&e.jsxs("span",{className:"px-1 py-0.5 text-xs text-dark-muted",children:["+",t.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 ${Z[t.implementationType]||"bg-dark-hover text-dark-muted"}`,children:t.implementationType})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${Q[t.priority]||"bg-dark-hover text-dark-muted"}`,children:t.priority})}),e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>s(t.name,!t.enabled),className:`relative h-5 w-9 rounded-full transition-colors ${t.enabled?"bg-accent-green":"bg-dark-border"}`,title:t.enabled?"点击禁用":"点击启用",children:e.jsx("span",{className:`absolute top-0.5 block h-3.5 w-3.5 rounded-full bg-white transition-all ${t.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:()=>o(t),className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue",title:"编辑",children:e.jsx(U,{size:14})}),e.jsx("button",{onClick:()=>{confirm(`删除规则 "${t.name}"?`)&&r(t.name)},className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red",title:"删除",children:e.jsx(D,{size:14})})]})})]},t.name))})]})})]})}const te={name:"",description:"",events:[],implementationType:"SHELL",command:"",url:"",promptTemplate:"",agentName:"",priority:"USER",tools:[],matcherToolNamePattern:"",matcherFromState:"",matcherToState:"",timeoutMs:3e4,enabled:!0,failOpen:!0,scope:"project"},ae=[{value:"SHELL",label:"Shell 脚本",desc:"执行外部脚本,stdin 接收 JSON,stdout 返回决策"},{value:"HTTP",label:"HTTP 端点",desc:"POST JSON 到外部端点"},{value:"PROMPT",label:"LLM Prompt",desc:"发送单轮 Prompt 给 LLM 做风险评估"},{value:"AGENT",label:"AI Agent",desc:"启动只读子代理做深度调查"}],se=[{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)"}],b=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"}`,g="mb-1 block text-xs font-medium text-dark-muted";function re({events:l,agents:o}){const{editingRule:s,fieldErrors:r,dryRunResult:i,createRule:v,updateRule:d,closeForm:h,dryRun:w,setDryRunResult:k,clearFieldErrors:y}=A(),S=Array.isArray(l)?l:[],p=Array.isArray(o)?o:[],[u,j]=N.useState(0),[t,m]=N.useState(te),[T,C]=N.useState("");N.useEffect(()=>{var a,n,c;s&&m({name:s.name,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||[],matcherToolNamePattern:((a=s.matchers)==null?void 0:a.toolNamePattern)||"",matcherFromState:((n=s.matchers)==null?void 0:n.fromState)||"",matcherToState:((c=s.matchers)==null?void 0:c.toState)||"",timeoutMs:s.timeoutMs,enabled:s.enabled,failOpen:s.failOpen,scope:s.scope||"project"})},[s]);const x=(a,n)=>{m(c=>({...c,[a]:n})),y()},L=a=>{m(n=>({...n,events:n.events.includes(a)?n.events.filter(c=>c!==a):[...n.events,a]}))},z=a=>{const n=a.every(c=>t.events.includes(c));m(n?c=>({...c,events:c.events.filter(R=>!a.includes(R))}):c=>({...c,events:[...new Set([...c.events,...a])]}))},F=async()=>{const a={};t.matcherToolNamePattern&&(a.toolNamePattern=t.matcherToolNamePattern),t.matcherFromState&&(a.fromState=t.matcherFromState),t.matcherToState&&(a.toState=t.matcherToState);const c={...{...t,tools:t.tools.length>0?t.tools:[]}};c.matchers=a,delete c.matcherToolNamePattern,delete c.matcherFromState,delete c.matcherToState,s?await d(s.name,c):await v(c)},H=async()=>{k(null);const a={};t.matcherToolNamePattern&&(a.toolNamePattern=t.matcherToolNamePattern),await w({hook:{name:t.name||"dry-run",description:t.description,events:t.events,implementationType:t.implementationType,command:t.command,url:t.url,promptTemplate:t.promptTemplate,agentName:t.agentName,priority:t.priority,tools:t.tools,matchers:a,timeoutMs:t.timeoutMs,enabled:!0,failOpen:t.failOpen,scope:t.scope},eventType:t.events[0]||"PRE_TOOL_USE",toolName:"",toolInput:""})},I=T?S.map(a=>({...a,events:Array.isArray(a.events)?a.events.filter(n=>n.name.toLowerCase().includes(T.toLowerCase())||n.summary.includes(T)):[]})).filter(a=>a.events.length>0):S,M=[{title:"基本信息",desc:"名称、描述、事件"},{title:"实现配置",desc:"执行方式与参数"},{title:"高级选项",desc:"优先级、过滤、测试"}];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:h}),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:s?`编辑: ${s.name}`:"添加 Hook 规则"}),e.jsx("button",{onClick:h,className:"rounded-lg p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(O,{size:18})})]}),e.jsx("div",{className:"flex flex-shrink-0 border-b border-dark-border",children:M.map((a,n)=>{const c=n===u,R=n<u;return e.jsxs("button",{onClick:()=>j(n),className:`relative flex-1 border-b-2 px-2 py-2.5 text-center text-xs transition-colors ${c?"border-accent-blue bg-accent-blue/5 text-accent-blue":R?"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] ${c?"bg-accent-blue text-white":R?"bg-accent-green text-white":"bg-dark-hover text-dark-muted"}`,children:R?"✓":n+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:[r&&Object.keys(r).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(r).map(([a,n])=>e.jsxs("div",{children:[e.jsxs("strong",{children:[a,":"]})," ",n]},a))}),u===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"名称 *"}),e.jsx("input",{value:t.name,onChange:a=>x("name",a.target.value),placeholder:"my-custom-hook",className:b(r==null?void 0:r.name)})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"描述"}),e.jsx("textarea",{value:t.description,onChange:a=>x("description",a.target.value),placeholder:"这个 Hook 的作用...",rows:2,className:b()})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"Scope"}),e.jsxs("select",{value:t.scope,onChange:a=>x("scope",a.target.value),className:b(),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:"事件 *"}),e.jsxs("span",{className:"text-xs text-accent-blue",children:[t.events.length," 已选"]})]}),e.jsx("input",{value:T,onChange:a=>C(a.target.value),placeholder:"搜索事件...",className:b()+" 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:I.map(a=>e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>z(a.events.map(n=>n.name)),className:"mb-1 text-xs font-medium text-dark-muted transition-colors hover:text-dark-text",children:[a.category," — 全选/取消"]}),a.events.map(n=>{const c=t.events.includes(n.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:c,onChange:()=>L(n.name),className:"h-3.5 w-3.5 accent-accent-blue"}),e.jsx("span",{className:"text-xs text-dark-text",children:n.name}),e.jsxs("span",{className:"truncate text-xs text-dark-muted",children:["— ",n.summary]})]},n.name)})]},a.category))})]})]}),u===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"实现类型 *"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:ae.map(a=>{const n=t.implementationType===a.value;return e.jsxs("button",{onClick:()=>x("implementationType",a.value),className:`rounded-lg border p-3 text-left transition-colors ${n?"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 ${n?"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)})})]}),t.implementationType==="SHELL"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"命令 *"}),e.jsx("input",{value:t.command,onChange:a=>x("command",a.target.value),placeholder:"python3 .agent/hooks/audit.py",className:`font-mono ${b(r==null?void 0:r.command)}`})]}),t.implementationType==="HTTP"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"URL *"}),e.jsx("input",{value:t.url,onChange:a=>x("url",a.target.value),placeholder:"https://example.com/hooks/audit",className:b(r==null?void 0:r.url)})]}),t.implementationType==="PROMPT"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"Prompt 模板 *"}),e.jsx("textarea",{value:t.promptTemplate,onChange:a=>x("promptTemplate",a.target.value),placeholder:"你是一个安全审计专家,请分析以下工具调用...",rows:5,className:`font-mono ${b(r==null?void 0:r.promptTemplate)}`})]}),t.implementationType==="AGENT"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"Agent *"}),e.jsxs("select",{value:t.agentName,onChange:a=>x("agentName",a.target.value),className:b(r==null?void 0:r.agentName),children:[e.jsx("option",{value:"",children:"选择 Agent..."}),p.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:"Agent 将以只读模式运行(Read/Grep/Glob),不会修改文件"})]})]}),u===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"优先级"}),e.jsx("select",{value:t.priority,onChange:a=>x("priority",a.target.value),className:b(),children:se.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:g,children:"超时 (ms)"}),e.jsx("input",{type:"number",value:t.timeoutMs,onChange:a=>x("timeoutMs",parseInt(a.target.value)||3e4),min:100,max:3e5,step:1e3,className:b()})]}),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:t.enabled,onChange:a=>x("enabled",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),"启用"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:t.failOpen,onChange:a=>x("failOpen",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),"Fail-open(超时放行)"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"工具过滤(正则,可选)"}),e.jsx("input",{value:t.matcherToolNamePattern,onChange:a=>x("matcherToolNamePattern",a.target.value),placeholder:"Bash.*|FileWrite.*",className:`font-mono ${b()}`})]}),t.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:g,children:"From State"}),e.jsx("input",{value:t.matcherFromState,onChange:a=>x("matcherFromState",a.target.value),className:b()})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"To State"}),e.jsx("input",{value:t.matcherToState,onChange:a=>x("matcherToState",a.target.value),className:b()})]})]}),i&&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:"Dry-run 结果"}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"决策: "}),e.jsx("span",{className:i.decision==="ALLOW"?"text-accent-green":i.decision==="DENY"?"text-accent-red":"text-accent-yellow",children:i.decision})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"原因: "}),e.jsx("span",{className:"text-dark-text",children:i.reason})]}),i.contextOutput&&e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"输出: "}),e.jsx("span",{className:"text-dark-text",children:i.contextOutput})]})]})]}),e.jsxs("button",{onClick:H,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($,{size:12})," 试运行 (Dry Run)"]})]})]}),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:u>0&&e.jsxs("button",{onClick:()=>j(u-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(Y,{size:14})," 上一步"]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:h,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:"取消"}),u<2?e.jsxs("button",{onClick:()=>j(u+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:["下一步 ",e.jsx(G,{size:14})]}):e.jsx("button",{onClick:F,className:"rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:s?"保存修改":"创建规则"})]})]})]})]})}function le({stats:l}){if(!l)return null;const o=[{label:"总规则数",value:l.totalHooks,icon:J,iconWrap:"bg-accent-blue/15 text-accent-blue"},{label:"已启用",value:l.enabledCount,icon:_,iconWrap:"bg-accent-green/15 text-accent-green"},{label:"已禁用",value:l.disabledCount,icon:B,iconWrap:"bg-dark-hover text-dark-muted"}];return e.jsx("div",{className:"grid grid-cols-3 gap-3",children:o.map(s=>{const r=s.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 ${s.iconWrap}`,children:e.jsx(r,{size:18})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xl font-bold text-dark-text",children:s.value}),e.jsx("div",{className:"text-xs text-dark-muted",children:s.label})]})]},s.label)})})}function xe(){const{rules:l,stats:o,events:s,agents:r,loading:i,error:v,formOpen:d,loadAll:h,openForm:w,clearError:k}=A();N.useEffect(()=>{h()},[]);const y=N.useCallback(async()=>{const p=await f.hooks.export();if(p.success&&p.data){const u=new Blob([JSON.stringify(p.data,null,2)],{type:"application/json"}),j=URL.createObjectURL(u),t=document.createElement("a");t.href=j,t.download="hooks-export.json",t.click(),URL.revokeObjectURL(j)}},[]),S=N.useCallback(()=>{const p=document.createElement("input");p.type="file",p.accept=".json",p.onchange=async u=>{var m;const j=(m=u.target.files)==null?void 0:m[0];if(!j)return;const t=await j.text();try{const T=JSON.parse(t),C=confirm(`合并到现有配置吗?
|
|
2
|
+
"确定"=合并 / "取消"=替换`)?"merge":"replace";(await f.hooks.import({...T,mergeMode:C})).success&&h()}catch(T){console.error("Import failed:",T)}},p.click()},[h]);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:"Hook 配置"}),e.jsx("p",{className:"mt-0.5 text-xs text-dark-muted",children:"在工具执行、任务流转等生命周期事件上挂载拦截器,实现审批与自定义逻辑"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:h,title:"刷新",className:"rounded-lg p-2 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(W,{size:16,className:i?"animate-spin":""})}),e.jsxs("button",{onClick:S,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}),"导入"]}),e.jsxs("button",{onClick:y,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(K,{size:14}),"导出"]}),e.jsxs("button",{onClick:()=>w(),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(V,{size:14}),"新增规则"]})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar px-6 py-4",children:[v&&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:v}),e.jsx("button",{onClick:k,className:"text-accent-red/70 transition-colors hover:text-accent-red",children:e.jsx(O,{size:16})})]}),e.jsx(le,{stats:o}),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:"规则列表"}),e.jsxs("span",{className:"text-xs text-dark-muted",children:[l.length," 条"]})]}),i&&l.length===0?e.jsx("div",{className:"flex h-[520px] items-center justify-center text-dark-muted",children:"加载中..."}):e.jsx("div",{className:"min-h-[520px]",children:e.jsx(ee,{rules:l,onEdit:p=>w(p)})})]})]}),d&&e.jsx(re,{events:s,agents:r})]})}export{xe as HookConfigView};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{j as t}from"./markdown-BASfeONY.js";import{a as r,h as oe,a1 as Dt,z as fe,aa as G,X as et,ap as Mt,C as ve,aq as tt,ar as $t,as as Et,ae as zt,ag as Lt,at as Rt,au as Ut,D as Ft,av as st,_ as Ot,aw as _t}from"./icons-BXecaLRH.js";import{a as p,t as P,M as ye,P as Bt}from"./index-CcPIw0Dj.js";import"./react-vendor-7At16BnY.js";import"./state-D4zgKwQs.js";import"./panels-Bod3sKnK.js";function Gt(){const[y,m]=r.useState([]),[I,f]=r.useState("1.0"),[ie,x]=r.useState(!0),[ue,H]=r.useState(!0),[Y,$]=r.useState(null),j=r.useCallback(async()=>{H(!0),$(null);try{const v=await p.providers.presets();v.success&&v.data?(m(Array.isArray(v.data.providers)?v.data.providers:[]),f(v.data.version||"1.0"),x(v.data.customSupported!==!1)):$(v.error||"获取 Provider 列表失败")}catch(v){$(v instanceof Error?v.message:"未知错误")}finally{H(!1)}},[]);return r.useEffect(()=>{j()},[j]),{presets:y,loading:ue,error:Y,version:I,customSupported:ie,reload:j}}const je={provider:"",modelId:"",modelName:"",apiKey:""},Ht={providerKey:"",apiKeys:"",modelIds:"",baseUrl:"",apiType:"",setDefault:!1},Yt=Bt,qt={"openai-chat-completions":"OpenAI Chat","openai-completions":"OpenAI Compatible","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages"};function Vt(y){const m=y.toLowerCase();return m.includes("/anthropic")||m.includes("/coding")||m.includes("/claude")||m.includes("/messages")?"anthropic-messages":m.includes("/responses")?"openai-responses":"openai-completions"}const at={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 ts(){var Be,Ge,He,Ye,qe,Ve,Qe,We,Xe,Je;const{presets:y,loading:m,reload:I}=Gt(),[f,ie]=r.useState([]),[x,ue]=r.useState(null),[H,Y]=r.useState(!0),[$,j]=r.useState(null),[v,ke]=r.useState(null),[lt,q]=r.useState(!1),[k,V]=r.useState(null),[N,S]=r.useState(je),[Ne,we]=r.useState(!1),[Ce,U]=r.useState(null),[n,nt]=r.useState(null),[ot,E]=r.useState(!1),[Pe,F]=r.useState("select"),[g,z]=r.useState(null),[i,w]=r.useState(Ht),[Ie,Se]=r.useState(!1),[Ke,K]=r.useState(null),[ct,xe]=r.useState(!1),[Q,Te]=r.useState(!1),[O,W]=r.useState(""),[Ae,De]=r.useState({}),[pe,Me]=r.useState(!1),[X,_]=r.useState([]),[J,T]=r.useState(new Set),[$e,L]=r.useState(null),[Z,me]=r.useState(""),A=r.useCallback(async()=>{try{const e=await p.config.provider.get();e.success&&e.data&&nt(e.data)}catch{}},[]),b=r.useCallback(async()=>{Y(!0),j(null);try{const[e,s]=await Promise.all([p.models.list(),p.system.status()]);if(await A(),e.success&&e.data&&Array.isArray(e.data.models)&&ie(e.data.models),s.success&&s.data){const a=s.data.models||{total:0,online:0,offline:0};ue({overallStatus:a.offline===0?"healthy":a.online>0?"degraded":"unhealthy",healthRate:a.total>0?a.online/a.total:0,healthyInstances:a.online,totalInstances:a.total,totalRequests:0})}}catch{j("加载模型失败")}finally{Y(!1)}},[A]);r.useEffect(()=>{b()},[b]),r.useEffect(()=>{const e=()=>{b(),A()};return window.addEventListener("models-updated",e),()=>window.removeEventListener("models-updated",e)},[b,A]);const D=r.useCallback(e=>`${e.provider}:${e.id}`,[]),dt=r.useCallback(e=>Ae[D(e)]||{inputTokens:0,outputTokens:0},[D,Ae]),Ee=r.useCallback((e,s,a)=>{const l=D(e);De(c=>{var o,d;return{...c,[l]:{inputTokens:s==="inputTokens"?a:((o=c[l])==null?void 0:o.inputTokens)||0,outputTokens:s==="outputTokens"?a:((d=c[l])==null?void 0:d.outputTokens)||0}}})},[D]),it=r.useCallback(e=>{De(s=>({...s,[D(e)]:{inputTokens:0,outputTokens:0}}))},[D]),M=r.useMemo(()=>{const e=[...y];return e.find(s=>s.key==="custom")||e.push({key:"custom",name:"Custom",baseUrl:"",apiType:"openai-completions",defaultModel:"",isCustom:!0}),e},[y]),ee=r.useMemo(()=>[...M].sort((e,s)=>{if(e.isCustom)return-1;if(s.isCustom)return 1;const a=at[e.key],l=at[s.key];return a!==void 0&&l!==void 0?a-l:a!==void 0?-1:l!==void 0?1:e.name.localeCompare(s.name)}),[M]),ze=r.useMemo(()=>{const e=O.trim().toLowerCase();return e?ee.filter(s=>s.name.toLowerCase().includes(e)||s.key.toLowerCase().includes(e)||(s.defaultModel||"").toLowerCase().includes(e)||(s.baseUrl||"").toLowerCase().includes(e)||(s.models||[]).some(a=>String(a).toLowerCase().includes(e))):ee},[ee,O]),C=r.useMemo(()=>{var l,c,o,d;const e=(n==null?void 0:n.providers)||{},s=new Set(M.map(u=>u.key)),a=Object.entries(e).filter(([u])=>!s.has(u));if(a.length!==0)return{keys:a.map(([u])=>u),modelCount:a.reduce((u,[,le])=>u+(le.modelCount||0),0),hasApiKey:a.some(([,u])=>u.hasApiKey),baseUrl:((c=(l=a.find(([,u])=>u.baseUrl))==null?void 0:l[1])==null?void 0:c.baseUrl)||"",apiType:((d=(o=a.find(([,u])=>u.apiType))==null?void 0:o[1])==null?void 0:d.apiType)||"openai-completions"}},[n,M]),Le=r.useCallback(e=>{var o,d;const s=(o=n==null?void 0:n.providers)==null?void 0:o[e.key],a=f.filter(u=>u.provider===e.key).map(u=>u.id),l=((d=e.models)==null?void 0:d.slice(0,3).join(", "))||e.defaultModel,c=a.length>0?a.join(", "):l;z(e.key),w({providerKey:e.key,apiKeys:"",modelIds:c,baseUrl:(s==null?void 0:s.baseUrl)||e.baseUrl,apiType:(s==null?void 0:s.apiType)||e.apiType,setDefault:(n==null?void 0:n.defaultProvider)!==e.key}),F("form"),E(!0),K(null),xe(!1),_([]),T(new Set),L(null),me("")},[f,n]),be=r.useCallback(()=>{var l,c;z("custom");const e=(l=C==null?void 0:C.keys)==null?void 0:l[0],s=e?(c=n==null?void 0:n.providers)==null?void 0:c[e]:void 0,a=e?f.filter(o=>o.provider===e).map(o=>o.id).join(", "):"";w({providerKey:e||"",apiKeys:"",modelIds:a,baseUrl:(s==null?void 0:s.baseUrl)||"",apiType:(s==null?void 0:s.apiType)||"openai-completions",setDefault:!(n!=null&&n.configured)}),F("form"),E(!0),K(null),xe(!1),_([]),T(new Set),L(null),me("")},[n,C,f]),ut=r.useCallback(async()=>{var s;const e=i.baseUrl;if(!e){L("请先填写 Base URL");return}Me(!0),L(null),_([]),T(new Set);try{const a=(i.apiKeys||"").split(/\r?\n|,/).map(o=>o.trim()).filter(Boolean)[0]||"",l=a.replace(/[^\x00-\xFF]/g,"");l!==a&&P.warning("API Key 包含非法字符,已自动过滤");const c=await p.models.fetch(e,l);if(c.success&&((s=c.data)!=null&&s.models)){_(c.data.models);const o=new Set(i.modelIds.split(",").map(d=>d.trim()).filter(Boolean));T(o),P.success(`获取到 ${c.data.models.length} 个模型`)}else L(c.error||"获取模型列表失败,请检查 Base URL 和 API Key")}catch(a){L(a instanceof Error?a.message:"请求失败")}finally{Me(!1)}},[i.baseUrl,i.apiKeys,i.modelIds]),xt=r.useCallback(e=>{const s=new Set(J);s.has(e)?s.delete(e):s.add(e),T(s),w(a=>({...a,modelIds:Array.from(s).join(", ")}))},[J]),[pt,Re]=r.useState(!1),[he,Ue]=r.useState(""),[Fe,te]=r.useState([]),[mt,Oe]=r.useState(!1),[_e,se]=r.useState(null),[ae,bt]=r.useState(!1),[re,ht]=r.useState(!0),gt=r.useCallback(()=>{Ue(""),te([]),se(null),Re(!0),B("",{reason:!1,tool:!0})},[]),B=r.useCallback(async(e,s)=>{Oe(!0),se(null);try{const a=await p.models.catalogSearch({q:e,reasoning:(s==null?void 0:s.reason)??!1,toolCall:(s==null?void 0:s.tool)??!0,limit:30});a.success&&a.data?te(a.data.hits||[]):(se(a.error||"目录搜索失败"),te([]))}catch(a){se(a instanceof Error?a.message:"请求失败"),te([])}finally{Oe(!1)}},[]),ft=r.useCallback(e=>{w(s=>{const a=s.modelIds.split(",").map(l=>l.trim()).filter(Boolean);return a.includes(e.model.id)?s:{...s,modelIds:[...a,e.model.id].join(", ")}}),P.success(`已添加 ${e.model.id}`)},[]),[ge,vt]=r.useState(null),yt=r.useCallback(e=>{Ue(e),ge&&clearTimeout(ge),vt(setTimeout(()=>{B(e,{reason:ae,tool:re})},300))},[ge,ae,re,B]),jt=async e=>{const s=f.find(o=>o.id===e);if(!s)return;const a=s.enabled!==!1,l=s.name||e,c=o=>a&&/default model/i.test(o);try{const o=await p.models.toggle(s.provider,e);if(o.success){await b();return}const d=o.error||"";c(d)?P.error(`“${l}” 是默认模型,无法直接禁用。请先在「Provider 配置」中更换默认模型,再进行禁用。`):P.error(d||"操作失败,请重试")}catch(o){const d=o instanceof Error?o.message:"";c(d)?P.error(`“${l}” 是默认模型,无法直接禁用。请先在「Provider 配置」中更换默认模型,再进行禁用。`):P.error(d||"操作失败,请重试")}},kt=async e=>{ke(e);try{await p.models.test(e),await b()}finally{ke(null)}},Nt=async(e,s)=>{if(confirm(`确定要删除模型 "${s}" 吗?此操作不可撤销。`))try{(await p.models.delete(e,s)).success&&await b()}catch{}},wt=e=>{V({provider:e.provider,modelId:e.id}),S({provider:e.provider,modelId:e.id,modelName:e.name,apiKey:""}),U(null),q(!0)},Ct=async()=>{var u,le;const e=M.find(h=>h.key===g)||null,s=g==="custom"?i.providerKey.trim():(e==null?void 0:e.key)||"";if(!s){K("请先输入 Provider 名称");return}const a=(i.apiKeys||"").split(/\r?\n|,/).map(h=>h.trim()).filter(Boolean),l=!!((le=(u=n==null?void 0:n.providers)==null?void 0:u[s])!=null&&le.hasApiKey);if(a.length===0&&!l){K("请至少输入一把 API Key");return}const c=e||{baseUrl:"",apiType:"openai-completions",defaultModel:""},o=a.map(h=>h.replace(/[^\x00-\xFF]/g,"")).filter(Boolean),d={provider:s,name:s,baseUrl:i.baseUrl||c.baseUrl,apiType:i.apiType||Vt(i.baseUrl||c.baseUrl)||c.apiType,models:(i.modelIds||c.defaultModel||"").split(",").map((h,Tt)=>{const ne=h.trim().split("|").map(At=>At.trim()).filter(Boolean),Ze=ne[0]||"";return{id:Ze,name:ne[1]||Ze,aliases:ne.length>2?ne.slice(2):void 0,enabled:!0,priority:10+Tt}}).filter(h=>h.id.length>0)};o.length>0&&(d.apiKeys=o),(!(n!=null&&n.configured)||i.setDefault)&&(d.setDefault=!0),Se(!0),K(null);try{const h=await p.config.provider.save(d);h.success?(E(!1),F("select"),z(null),await A(),await b()):K(h.error||"保存失败")}catch(h){K(h instanceof Error?h.message:"未知错误")}finally{Se(!1)}},Pt=async e=>{if(confirm(`确定要移除 "${e}" 的配置吗?这将删除其 API Key 和模型。`))try{await p.config.provider.delete(e),await A(),await b()}catch{}},It=async()=>{if(k){if(!N.provider.trim()||!N.modelId.trim()){U("提供商名称和模型 ID 不能为空");return}we(!0),U(null);try{const e={name:N.modelName.trim()||N.modelId.trim(),...N.apiKey.trim()?{apiKey:N.apiKey.trim()}:{}},s=await p.models.update(k.provider,k.modelId,{model:e});s.success?(q(!1),V(null),S(je),await b()):U(s.error||"保存失败")}catch(e){U(e instanceof Error?e.message:"未知错误")}finally{we(!1)}}},St=e=>{switch(e){case"online":return"text-accent-green";case"offline":return"text-dark-muted";case"error":return"text-accent-red";default:return"text-dark-muted"}},Kt=e=>{switch(e){case"online":return t.jsx(_t,{size:14});case"offline":return t.jsx(st,{size:14});case"error":return t.jsx(Ot,{size:14});default:return t.jsx(st,{size:14})}},R=r.useMemo(()=>M.find(e=>e.key===g)||null,[g,M]);return H?t.jsx("div",{className:"flex h-64 items-center justify-center text-dark-muted",children:"加载中..."}):$?t.jsx("div",{className:"flex h-64 items-center justify-center text-accent-red",children:$}):t.jsxs("div",{className:"p-6 space-y-6 flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("h2",{className:"text-base font-semibold",children:"Provider 配置"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("button",{onClick:async()=>{try{await p.providers.refresh(),P.success("Provider 列表已刷新"),Te(!0),await I(),setTimeout(()=>{I()},3e3)}catch{P.error("刷新失败,请稍后重试")}},className:"inline-flex items-center gap-1.5 px-2.5 py-1 text-xs border border-dark-border rounded hover:bg-dark-hover",title:"从远端刷新 Provider 列表",children:[t.jsx(oe,{size:12}),"刷新列表"]}),t.jsxs("button",{onClick:()=>{Q&&W(""),Te(e=>!e)},className:"inline-flex items-center gap-1.5 px-2.5 py-1 text-xs bg-accent-blue text-white rounded hover:opacity-90",children:[Q?t.jsx(Dt,{size:12}):t.jsx(fe,{size:12}),Q?"收起":"新增 Provider"]})]})]}),Q&&t.jsxs("div",{children:[t.jsxs("div",{className:"relative mb-3 max-w-md",children:[t.jsx(G,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted"}),t.jsx("input",{value:O,onChange:e=>W(e.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:"搜索 Provider 名称 / 模型..."}),O&&t.jsx("button",{onClick:()=>W(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-white",title:"清除","aria-label":"清除搜索",children:t.jsx(et,{size:13})})]}),t.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:m?t.jsxs("div",{className:"col-span-full flex items-center justify-center py-4 text-dark-muted text-sm",children:[t.jsx(Mt,{size:14,className:"mr-2 animate-spin"}),"加载 Provider 列表..."]}):ze.length===0?t.jsxs("div",{className:"col-span-full border border-accent-red/30 bg-accent-red/10 rounded-lg p-4 text-center",children:[t.jsx("div",{className:"text-sm text-accent-red font-medium mb-1",children:"未找到匹配的 Provider"}),t.jsxs("div",{className:"text-xs text-dark-muted mb-3",children:["没有与「",O,"」匹配的 Provider,请检查拼写或改用完整列表"]}),t.jsxs("div",{className:"flex items-center justify-center gap-2",children:[t.jsxs("button",{onClick:()=>W(""),className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-dark-border rounded hover:bg-dark-hover",children:[t.jsx(et,{size:12}),"清除搜索"]}),t.jsxs("button",{onClick:be,className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs bg-accent-blue text-white rounded hover:opacity-90",children:[t.jsx(fe,{size:12}),"添加自定义 Provider"]})]})]}):ze.map(e=>{var o,d;const s=e.key==="custom",a=s?C:(o=n==null?void 0:n.providers)==null?void 0:o[e.key],l=a==null?void 0:a.hasApiKey,c=s?!!(n!=null&&n.defaultProvider)&&((C==null?void 0:C.keys)||[]).includes(n.defaultProvider):(n==null?void 0:n.defaultProvider)===e.key;return t.jsxs("div",{className:`text-left p-3 rounded-lg border transition-colors relative ${l?"border-accent-green/30 bg-dark-surface hover:border-accent-green/50":"border-dark-border bg-dark-surface hover:border-dark-hover"}`,children:[t.jsxs("div",{onClick:()=>e.key==="custom"?be():Le(e),className:"cursor-pointer",children:[t.jsxs("div",{className:"flex items-center justify-between mb-1",children:[t.jsx("span",{className:"text-sm font-medium",children:e.name}),l&&t.jsx(ve,{size:14,className:"text-accent-green"})]}),t.jsxs("div",{className:"text-[10px] text-dark-muted space-y-0.5",children:[t.jsx("div",{className:"truncate",children:s?(a==null?void 0:a.baseUrl)||"自定义地址":e.baseUrl||"自定义地址"}),t.jsx("div",{className:"truncate",children:s&&C?`${C.keys.join(", ")}`:e.defaultModel||"无默认模型"}),t.jsxs("div",{children:[a?`${a.modelCount} 已配置`:`${((d=e.models)==null?void 0:d.length)||0} 可用`,e.models&&e.models.length>0&&!a&&t.jsx("span",{className:"text-accent-blue",children:" ✓"})]})]}),c&&t.jsx("div",{className:"mt-1 text-[10px] text-accent-blue",children:"默认 Provider"})]}),l&&e.key!=="custom"&&t.jsx("button",{onClick:u=>{u.stopPropagation(),Pt(e.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:"删除 Provider","aria-label":`删除 ${e.name}`,children:t.jsx(tt,{size:13})})]},e.key)})})]})]}),x&&t.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[t.jsx(ce,{title:"总体状态",value:x.totalInstances===0?"未配置":x.overallStatus==="healthy"?"健康":x.overallStatus==="degraded"?"降级":"异常",color:x.totalInstances===0?"blue":x.overallStatus==="healthy"?"green":x.overallStatus==="degraded"?"yellow":"red"}),t.jsx(ce,{title:"健康率",value:x.totalInstances===0?"N/A":`${(x.healthRate*100).toFixed(0)}%`,color:x.totalInstances===0?"blue":x.healthRate>.8?"green":x.healthRate>.5?"yellow":"red"}),t.jsx(ce,{title:"在线实例",value:x.totalInstances===0?"无":`${x.healthyInstances}/${x.totalInstances}`,color:x.healthyInstances>0?"green":"red"}),t.jsx(ce,{title:"总请求数",value:x.totalRequests>0?x.totalRequests.toLocaleString():"0",color:"blue"})]}),t.jsxs("div",{children:[t.jsx("div",{className:"flex items-center justify-between mb-3",children:t.jsx("h3",{className:"text-sm font-medium",children:"已配置模型"})}),t.jsxs("div",{className:"space-y-2 max-h-[480px] overflow-y-auto custom-scrollbar pr-1",children:[f.map(e=>{const s=dt(e),a=s.inputTokens+s.outputTokens;return t.jsx("div",{className:`bg-dark-surface border rounded-lg p-3 ${e.status==="online"?"border-accent-green":"border-dark-border opacity-70"}`,children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[t.jsx("span",{className:St(e.status),children:Kt(e.status)}),t.jsx("span",{className:"font-medium text-sm",children:e.name}),t.jsx("span",{className:"text-[10px] text-dark-muted px-1.5 py-0.5 bg-dark-bg rounded",children:e.provider}),e.apiType&&t.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${e.apiType==="anthropic-messages"?"bg-accent-purple/20 text-accent-purple":"bg-accent-blue/20 text-accent-blue"}`,children:e.apiType==="anthropic-messages"?"Anthropic":"OpenAI"}),e.isGlobalDefault&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-green/20 text-accent-green font-medium",children:"全局默认"}),e.isPlanDefault&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue font-medium",children:"Plan 默认"}),e.isActDefault&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",children:"Act 默认"}),e.isGoalDefault&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-purple/20 text-accent-purple font-medium",children:"Goal 默认"})]}),t.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[t.jsx(de,{label:"负载",value:`${e.load}/${e.maxLoad}`}),t.jsx(de,{label:"Token",value:`${e.tokens}/${e.maxTokens}`}),t.jsx(de,{label:"输入价格",value:`$${e.price.input}/1K`}),t.jsx(de,{label:"输出价格",value:`$${e.price.output}/1K`})]}),t.jsxs("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-4 gap-3 items-end",children:[t.jsx(rt,{label:"输入 token",value:s.inputTokens,onChange:l=>Ee(e,"inputTokens",l)}),t.jsx(rt,{label:"输出 token",value:s.outputTokens,onChange:l=>Ee(e,"outputTokens",l)}),t.jsxs("div",{children:[t.jsx("div",{className:"text-[11px] text-dark-muted mb-1",children:"总 token"}),t.jsx("div",{className:"px-3 py-2 rounded border border-dark-border bg-dark-bg text-sm font-mono",children:a.toLocaleString()})]}),t.jsxs("button",{onClick:()=>it(e),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:[t.jsx($t,{size:13}),"重置"]})]})]}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[!e.isGlobalDefault&&e.enabled!==!1&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({global:`${e.provider}:${e.id}`}),await b()}catch(l){j(l instanceof Error?l.message:"设置全局默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-accent-green/30 text-accent-green hover:bg-accent-green/10",title:"设为全局默认",children:"全局默认"}),!e.isPlanDefault&&e.enabled!==!1&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({plan:`${e.provider}:${e.id}`}),await b()}catch(l){j(l instanceof Error?l.message:"设置 Plan 默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-accent-blue/30 text-accent-blue hover:bg-accent-blue/10",title:"设为 Plan 默认",children:"Plan 默认"}),!e.isActDefault&&e.enabled!==!1&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({act:`${e.provider}:${e.id}`}),await b()}catch(l){j(l instanceof Error?l.message:"设置 Act 默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-accent-yellow/30 text-accent-yellow hover:bg-accent-yellow/10",title:"设为 Act 默认",children:"Act 默认"}),!e.isGoalDefault&&e.enabled!==!1&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({goal:`${e.provider}:${e.id}`}),await b()}catch(l){j(l instanceof Error?l.message:"设置 Goal 默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-accent-purple/30 text-accent-purple hover:bg-accent-purple/10",title:"设为 Goal 默认",children:"Goal 默认"}),t.jsx("button",{onClick:()=>wt(e),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:"编辑模型",children:t.jsx(Et,{size:13})}),t.jsx("button",{onClick:()=>Nt(e.provider,e.id),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:"删除模型",children:t.jsx(tt,{size:13})}),t.jsx("button",{onClick:()=>kt(e.id),disabled:v===e.id,className:"p-1.5 rounded hover:bg-dark-hover disabled:opacity-50",title:"刷新",children:t.jsx(oe,{size:13,className:v===e.id?"animate-spin":""})}),t.jsx("button",{onClick:()=>jt(e.id),className:`px-2 py-0.5 rounded text-xs transition-colors ${e.status==="online"?"bg-accent-red/20 text-accent-red hover:bg-accent-red/30":"bg-accent-green/20 text-accent-green hover:bg-accent-green/30"}`,children:e.status==="online"?"禁用":"启用"})]})]})},D(e))}),f.length===0&&t.jsxs("div",{className:"text-center text-dark-muted py-6",children:[t.jsx(zt,{size:36,className:"mx-auto mb-2 opacity-40"}),t.jsx("p",{className:"text-sm",children:"暂无模型,请先在上方配置 Provider"})]})]})]}),t.jsx(ye,{isOpen:ot,onClose:()=>{E(!1),F("select"),z(null)},title:Pe==="select"?"选择 Provider":(R==null?void 0:R.name)||"Provider 配置",size:"xl",children:Pe==="select"?t.jsx("div",{className:"space-y-4",children:t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[ee.filter(e=>e.key!=="custom").map(e=>t.jsxs("button",{onClick:()=>Le(e),className:"text-left p-3 rounded-lg border border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx(ve,{size:14,className:"text-accent-blue"}),t.jsx("span",{className:"text-sm font-medium",children:e.name})]}),t.jsx("div",{className:"text-xs text-dark-muted",children:e.defaultModel})]},e.key)),t.jsxs("button",{onClick:be,className:"text-left p-3 rounded-lg border border-dashed border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx(Lt,{size:14,className:"text-accent-blue"}),t.jsx("span",{className:"text-sm font-medium",children:"自定义 Provider"})]}),t.jsx("div",{className:"text-xs text-dark-muted",children:"手动填写 Provider 名称、Base URL 和模型 ID"})]})]})}):t.jsxs("div",{className:"space-y-3",children:[g==="custom"&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"Provider 名称 *"}),t.jsx("input",{value:i.providerKey,onChange:e=>w(s=>({...s,providerKey:e.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:"例如: my-provider"})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:["API Keys",(Ge=(Be=n==null?void 0:n.providers)==null?void 0:Be[g==="custom"?i.providerKey.trim():g||""])!=null&&Ge.hasApiKey?"":" *",t.jsxs("span",{className:"text-dark-muted/60 text-xs",children:["(每行一把,可多把",(Ye=(He=n==null?void 0:n.providers)==null?void 0:He[g==="custom"?i.providerKey.trim():g||""])!=null&&Ye.hasApiKey?",留空则保留已保存的 Key":"",")"]})]}),t.jsxs("div",{className:"relative",children:[t.jsx("textarea",{rows:3,value:i.apiKeys,onChange:e=>w(s=>({...s,apiKeys:e.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:`每行输入一把 API Key
|
|
2
|
+
支持多把(运行时取第一把,其余备用)`}),t.jsx("button",{onClick:()=>xe(e=>!e),className:"absolute right-2 top-2 text-dark-muted hover:text-white",children:ct?t.jsx(Rt,{size:14}):t.jsx(Ut,{size:14})})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"模型 ID"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:i.modelIds,onChange:e=>{const s=e.target.value;w(a=>({...a,modelIds:s})),T(()=>{const a=new Set;for(const l of s.split(",")){const c=l.trim().split("|")[0].trim();c&&X.some(o=>o.id===c)&&a.add(c)}return a})},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:(R==null?void 0:R.defaultModel)||"gpt-4o, deepseek-chat (格式: id|名称|别名)"}),t.jsxs("button",{onClick:ut,disabled:pe||!i.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:"从 API 获取模型列表",children:[pe?t.jsx(oe,{size:13,className:"animate-spin"}):t.jsx(Ft,{size:13}),pe?"获取中...":"获取模型列表"]}),t.jsxs("button",{onClick:gt,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:"搜索 models.dev 全厂商模型目录(含 context/价格/能力元数据)",children:[t.jsx(G,{size:13}),"目录搜索"]})]}),$e&&t.jsx("div",{className:"mt-1 text-xs text-accent-red",children:$e}),X.length>0&&t.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("span",{className:"text-xs text-dark-muted",children:["已获取 ",t.jsx("strong",{className:"text-dark-text",children:X.length})," 个模型, 已选 ",t.jsx("strong",{className:"text-accent-blue",children:J.size})," 个",t.jsx("span",{className:"text-accent-blue/70",children:"(勾选即自动应用到「模型 ID」输入框)"})]}),t.jsx("button",{onClick:()=>{_([]),T(new Set)},className:"px-2 py-0.5 text-[10px] border border-dark-border rounded hover:bg-dark-hover",children:"关闭"})]}),t.jsxs("div",{className:"relative mb-2",children:[t.jsx(G,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),t.jsx("input",{value:Z,onChange:e=>me(e.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.jsx("div",{className:"max-h-48 overflow-y-auto custom-scrollbar grid grid-cols-2 sm:grid-cols-3 gap-1",children:X.filter(e=>!Z||e.id.toLowerCase().includes(Z.toLowerCase())||e.name.toLowerCase().includes(Z.toLowerCase())).map(e=>{const s=J.has(e.id);return t.jsxs("div",{role:"checkbox","aria-checked":s,tabIndex:-1,onMouseDown:a=>a.preventDefault(),onClick:()=>xt(e.id),className:`flex items-center gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${s?"bg-accent-blue/20 text-accent-blue border border-accent-blue/30":"hover:bg-dark-hover border border-transparent"}`,children:[s?t.jsx(ve,{size:10}):t.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"}),t.jsx("span",{className:"truncate",children:e.id})]},e.id)})})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"Base URL"}),t.jsx("input",{value:i.baseUrl,onChange:e=>w(s=>({...s,baseUrl:e.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:"https://api.example.com/v1"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"API 类型"}),t.jsxs("select",{value:i.apiType,onChange:e=>w(s=>({...s,apiType:e.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",children:[t.jsx("option",{value:"",children:"自动探测(推荐)"}),Yt.map(e=>t.jsx("option",{value:e,children:qt[e]},e))]}),t.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:"默认 OpenAI 兼容;Anthropic/Claude 类网关(URL 含 /anthropic、/coding)自动切 Anthropic Messages。"})]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:i.setDefault,onChange:e=>w(s=>({...s,setDefault:e.target.checked})),className:"accent-accent-blue"}),t.jsx("span",{className:"text-sm text-dark-muted",children:"设为默认 Provider"})]}),Ke&&t.jsx("div",{className:"text-sm text-accent-red",children:Ke}),t.jsxs("div",{className:"flex justify-between gap-2 pt-2",children:[t.jsx("div",{children:g&&g!=="custom"&&((Ve=(qe=n==null?void 0:n.providers)==null?void 0:qe[g])==null?void 0:Ve.hasApiKey)&&t.jsx("button",{onClick:async()=>{if(confirm(`确定要删除 "${g}" 的配置吗?`))try{await p.config.provider.delete(g),E(!1),z(null),await A(),await b()}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:"删除 Provider"})}),t.jsx("button",{onClick:()=>{F("select"),z(null),E(!1)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:"取消"}),t.jsx("button",{onClick:Ct,disabled:Ie,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:Ie?"保存中...":"保存"})]})]})}),t.jsx(ye,{isOpen:pt,onClose:()=>Re(!1),title:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(G,{size:15,className:"text-accent-green"}),"models.dev 模型目录搜索"]}),size:"2xl",children:t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"relative flex-1",children:[t.jsx(G,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),t.jsx("input",{value:he,onChange:e=>yt(e.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:"搜索全厂商模型,如 gpt-4o / deepseek / claude ...(匹配模型 id / 名称 / 厂商)",autoFocus:!0})]}),t.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:re,onChange:e=>{const s=e.target.checked;ht(s),B(he,{reason:ae,tool:s})},className:"accent-accent-green"}),"仅工具调用"]}),t.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:ae,onChange:e=>{const s=e.target.checked;bt(s),B(he,{reason:s,tool:re})},className:"accent-accent-green"}),"仅推理模型"]})]}),_e&&t.jsx("div",{className:"text-xs text-accent-red bg-accent-red/10 p-2 rounded",children:_e}),mt?t.jsxs("div",{className:"flex items-center justify-center py-10 text-dark-muted",children:[t.jsx(oe,{size:18,className:"animate-spin mr-2"})," 搜索中..."]}):t.jsx("div",{className:"max-h-96 overflow-y-auto custom-scrollbar border border-dark-border rounded-lg divide-y divide-dark-border",children:Fe.length===0?t.jsx("div",{className:"py-10 text-center text-dark-muted text-sm",children:"无匹配模型,换个关键词试试"}):Fe.map(e=>{var s,a,l;return t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 hover:bg-dark-hover",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm font-medium text-dark-text truncate",children:e.model.name||e.model.id}),t.jsx("code",{className:"text-[10px] px-1.5 py-0.5 bg-dark-bg border border-dark-border rounded text-dark-muted truncate",children:e.model.id}),e.model.reasoning&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-yellow/10 text-accent-yellow rounded",children:"推理"}),e.model.tool_call&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-blue/10 text-accent-blue rounded",children:"工具"}),e.model.attachment&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-green/10 text-accent-green rounded",children:"多模态"})]}),t.jsxs("div",{className:"text-[11px] text-dark-muted mt-0.5",children:[e.providerName,(s=e.model.limit)!=null&&s.context?` · 上下文 ${(e.model.limit.context/1e3).toFixed(0)}K`:"",(a=e.model.limit)!=null&&a.output?` · 输出 ${(e.model.limit.output/1e3).toFixed(0)}K`:"",((l=e.model.cost)==null?void 0:l.input)!==void 0?` · $${e.model.cost.input}/M in / $${e.model.cost.output}/M out`:""]})]}),t.jsxs("button",{onClick:()=>ft(e),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:"添加到模型 ID 输入框",children:[t.jsx(fe,{size:12})," 添加"]})]},`${e.providerId}:${e.model.id}`)})}),t.jsx("div",{className:"text-[11px] text-dark-muted/60",children:"数据源:models.dev 模型目录(内置快照,离线可用)。点击「添加」将模型 ID 写入「模型 ID」输入框。"})]})}),t.jsx(ye,{isOpen:lt,onClose:()=>{q(!1),V(null)},title:"编辑模型",size:"lg",children:t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"提供商名称 *"}),t.jsx("input",{value:N.provider,onChange:e=>S(s=>({...s,provider:e.target.value})),disabled:!!k,className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue disabled:opacity-50",placeholder:"例如: openai, deepseek"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"模型 ID *"}),t.jsx("input",{value:N.modelId,onChange:e=>S(s=>({...s,modelId:e.target.value})),disabled:!!k,className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue disabled:opacity-50",placeholder:"例如: gpt-4o, deepseek-chat"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"模型名称"}),t.jsx("input",{value:N.modelName,onChange:e=>S(s=>({...s,modelName:e.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:"留空则使用模型 ID"})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:["API Key",k&&((We=(Qe=n==null?void 0:n.providers)==null?void 0:Qe[k.provider])==null?void 0:We.hasApiKey)&&t.jsx("span",{className:"text-accent-green/80 text-xs ml-1",children:"已配置(留空则保持不变)"})]}),t.jsx("input",{type:"password",value:N.apiKey,onChange:e=>S(s=>({...s,apiKey:e.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:k&&((Je=(Xe=n==null?void 0:n.providers)==null?void 0:Xe[k.provider])!=null&&Je.hasApiKey)?"留空保持当前 API Key":"输入新的 API Key"})]}),Ce&&t.jsx("div",{className:"text-sm text-accent-red bg-accent-red/10 p-2 rounded",children:Ce}),t.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[t.jsx("button",{onClick:()=>{q(!1),V(null),S(je)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:"取消"}),t.jsx("button",{onClick:It,disabled:Ne,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:Ne?"保存中...":"保存"})]})]})})]})}function ce({title:y,value:m,color:I}){const f={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 t.jsxs("div",{className:`${f[I]} rounded-lg p-3`,children:[t.jsx("div",{className:"text-xs opacity-70",children:y}),t.jsx("div",{className:"text-xl font-semibold",children:m})]})}function de({label:y,value:m}){return t.jsxs("div",{children:[t.jsx("div",{className:"text-dark-muted",children:y}),t.jsx("div",{children:m})]})}function rt({label:y,value:m,onChange:I}){return t.jsxs("div",{children:[t.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:y}),t.jsx("input",{type:"number",min:"0",value:m,onChange:f=>I(parseInt(f.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{ts as ModelsView,ts as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as t}from"./markdown-BASfeONY.js";import{a as s,aj as xe,h as ue,aa as me,X as Z,_ as be,aA as J,bb as pe,b8 as he,aq as ge,D as W,y as ke,K as ve}from"./icons-BXecaLRH.js";import{c as fe,g as u,C as je}from"./index-CcPIw0Dj.js";import"./react-vendor-7At16BnY.js";import"./state-D4zgKwQs.js";import"./panels-Bod3sKnK.js";const I=12,ye="other";function Ne(d){return d==="wired"?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":d==="pending"||d==="pending_wiring"?"bg-amber-500/15 text-amber-400 border-amber-500/30":"bg-dark-hover text-dark-muted border-dark-border"}function ee(d){var n;return((n=d.category)==null?void 0:n.trim())||ye}function Ce(d,n){const v=n.trim().toLowerCase();return v?[d.id,d.name,d.description,d.category,...d.tags??[]].filter(w=>typeof w=="string").join(" ").toLowerCase().includes(v):!0}function Ae(){const{t:d}=fe(),[n,v]=s.useState("installed"),[m,w]=s.useState([]),[R,te]=s.useState([]),[T,re]=s.useState(null),[f,L]=s.useState(!0),[S,O]=s.useState(null),[i,U]=s.useState(null),[$,V]=s.useState(null),[j,_]=s.useState(null),[y,P]=s.useState(null),[q,B]=s.useState(null),[b,D]=s.useState(""),[o,se]=s.useState(null),[c,z]=s.useState(1),x=s.useCallback((e,r)=>{_({kind:e,text:r}),window.setTimeout(()=>_(null),4e3)},[]),p=s.useCallback(async()=>{L(!0),O(null);const[e,r]=await Promise.all([u.get("/api/plugins"),u.get("/api/plugins/market")]);e.success&&e.data?(w(e.data.plugins),re(e.data.schemaVersion??null)):O(e.error??"Failed to load plugins"),r.success&&r.data&&te(r.data.plugins),L(!1)},[]);s.useEffect(()=>{p()},[p]);const M=s.useMemo(()=>m.filter(e=>e.installable!==!0),[m]),h=s.useMemo(()=>[...m.filter(e=>e.installable===!0),...R.filter(e=>!m.some(r=>r.id===e.id||r.marketId===e.id))],[m,R]),N=s.useCallback(e=>e.filter(r=>o&&ee(r)!==o?!1:Ce(r,b)),[o,b]),g=s.useMemo(()=>N(M),[N,M]),k=s.useMemo(()=>N(h),[N,h]),F=s.useMemo(()=>{const e=new Set;for(const r of h)e.add(ee(r));return["all",...Array.from(e).sort()]},[h]),G=e=>Math.max(1,Math.ceil(e/I)),H=(e,r)=>e.slice((r-1)*I,r*I),A=G(g.length),E=G(k.length),ae=s.useMemo(()=>H(g,Math.min(c,A)),[g,c,A]),de=s.useMemo(()=>H(k,Math.min(c,E)),[k,c,E]);s.useEffect(()=>{z(1)},[n,b,o]);const ne=b.trim().length>0||o!==null,C=s.useCallback(async(e,r,l)=>{U(e),V(r);try{const a=await l();a&&a.success===!1?x("err",String(a.error??"Request failed")):(x("ok",`${r} ${e} ✓`),await p())}catch(a){x("err",a instanceof Error?a.message:String(a))}finally{U(null),V(null)}},[p,x]),K=(e,r)=>C(e,r?"installed+activated":"installed",()=>u.post("/api/plugins/install",{id:e,activate:r})),le=e=>C(e,"activated",()=>u.post(`/api/plugins/${encodeURIComponent(e)}/activate`)),ie=e=>C(e,"deactivated",()=>u.post(`/api/plugins/${encodeURIComponent(e)}/deactivate`)),oe=e=>C(e,"uninstalled",()=>u.delete(`/api/plugins/${encodeURIComponent(e)}`)),ce=async e=>{B(e);try{const r=await u.post(`/api/plugins/l2/provider/${encodeURIComponent(e)}`);r.success&&r.data?(x("ok",`Provider ${r.data.applied} applied to config ✓`),await p()):x("err",r.error??"Apply failed")}catch(r){x("err",r instanceof Error?r.message:String(r))}finally{B(null)}},Q=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})},X=(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(l=>Math.max(1,l-1)),disabled:c<=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(ke,{size:12})," 上一页"]}),t.jsxs("span",{className:"text-[11px] text-dark-muted",children:["第 ",Math.min(c,r)," / ",r," 页 · 共 ",e," 条"]}),t.jsxs("button",{onClick:()=>z(l=>Math.min(r,l+1)),disabled:c>=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:["下一页 ",t.jsx(ve,{size:12})]})]}):null,Y=e=>t.jsx("div",{className:"mt-8 text-center text-[12px] text-dark-muted",children:ne?"无匹配插件":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(xe,{size:15,className:"text-accent-blue"}),t.jsx("span",{className:"truncate text-[13px] font-medium text-dark-text",children:d("nav.plugins")}),T!==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",T]}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:()=>void p(),className:"p-1.5 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text transition-colors",title:"Refresh",children:t.jsx(ue,{size:14,className:f?"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:()=>v(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"?`已安装 (${M.length})`:`可安装 (${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(me,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted pointer-events-none"}),t.jsx("input",{value:b,onChange:e=>D(e.target.value),placeholder:"搜索插件(名称 / id / 描述 / 标签)",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"}),b&&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:"清除",children:t.jsx(Z,{size:12})})]}),n==="available"&&F.length>2&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:F.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"?"全部":e},e))})]}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-3 pb-4",children:[S&&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(be,{size:14})," ",S]}),f&&!S&&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"})}),!f&&n==="installed"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[g.length===0&&Y("暂无插件 — 到「可安装」页从市场安装"),ae.map(e=>{const r=e.l2??[],l=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}),Q(e.source),t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border shrink-0 ${l?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":"bg-dark-hover text-dark-muted border-dark-border"}`,children:l?"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(a=>t.jsxs("span",{title:a.note||a.id,className:`px-1.5 py-0.5 rounded text-[11px] border cursor-help ${Ne(a.status)}`,children:[a.kind," · ",a.status,a.status==="wired"&&t.jsx(J,{size:10,className:"inline ml-0.5"})]},`${a.kind}-${a.id}`)),r.filter(a=>a.kind==="provider"&&a.status==="wired").map(a=>t.jsx("button",{disabled:q===a.id,onClick:()=>void ce(a.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:"把插件 provider preset 写入 ProviderConfigStore(用户授权)",children:q===a.id?"applying…":"apply provider"},`apply-${a.id}`))]}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[l?t.jsxs("button",{onClick:()=>void ie(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(pe,{size:11})," ",i===e.id?`${$}…`:"停用"]}):t.jsxs("button",{onClick:()=>void le(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(he,{size:11})," ",i===e.id?`${$}…`:"激活"]}),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(ge,{size:11})," 卸载"]})]})]},e.id)}),X(g.length,A)]}),!f&&n==="available"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[k.length===0&&Y("市场暂无可用插件"),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}),Q(e.source),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 K(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(W,{size:11})," ",i===e.id?`${$}…`:"安装并激活"]}),t.jsxs("button",{onClick:()=>void K(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(W,{size:11})," 仅安装"]})]})]},e.id)),X(k.length,E)]})]}),j&&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 ${j.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:[j.kind==="ok"?t.jsx(J,{size:13}):t.jsx(Z,{size:13})," ",j.text]}),t.jsx(je,{isOpen:y!==null,title:"卸载插件",message:`确定要卸载 ${y} 吗?插件文件将被删除(bundled 除外)。`,onConfirm:()=>{y&&oe(y),P(null)},onClose:()=>P(null)})]})}export{Ae as PluginsView};
|