@deepseekcode/cli 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cli.js +932 -954
  2. package/package.json +1 -1
  3. package/web/dist/assets/{AgentFlowView-Co1aujcZ.js → AgentFlowView-3ALl4Xq6.js} +1 -1
  4. package/web/dist/assets/{AgentsView-CHvg1cY0.js → AgentsView-LbT0yWgw.js} +1 -1
  5. package/web/dist/assets/{AskQuestionModal-nAvPzz0y.js → AskQuestionModal-CLBTdbTg.js} +1 -1
  6. package/web/dist/assets/AuditView-DRP8v7Md.js +1 -0
  7. package/web/dist/assets/AutomationView-BAPQBUPl.js +1 -0
  8. package/web/dist/assets/ChannelConfigView-CV-fYNTp.js +8 -0
  9. package/web/dist/assets/{FileTreeView-DA87bArS.js → FileTreeView-Lz2howvU.js} +3 -3
  10. package/web/dist/assets/{HookApprovalModal-qN4gBTAu.js → HookApprovalModal-BSJSlWoo.js} +1 -1
  11. package/web/dist/assets/HookConfigView-D32et-2f.js +3 -0
  12. package/web/dist/assets/InboxView-BFMN2Kq7.js +1 -0
  13. package/web/dist/assets/ModelsView-CWZNnuo_.js +1 -0
  14. package/web/dist/assets/SessionGrid-BT52IjwR.js +20 -0
  15. package/web/dist/assets/{SettingsPanel-UUAdnvtB.js → SettingsPanel-B5nk8Ut9.js} +3 -3
  16. package/web/dist/assets/{SkillsView-C1s0EA-r.js → SkillsView-C9FG2LYN.js} +1 -1
  17. package/web/dist/assets/TerminalView-DFtqERpj.js +3 -0
  18. package/web/dist/assets/Toast-CcbSW0V2.js +1 -0
  19. package/web/dist/assets/{ToolsView-DvbfsrpK.js → ToolsView-XDi6U66v.js} +1 -1
  20. package/web/dist/assets/{hookRisk-CbXD9F3U.js → hookRisk-CYBIelde.js} +1 -1
  21. package/web/dist/assets/{icons-CjYP2PII.js → icons-uody4X-4.js} +89 -64
  22. package/web/dist/assets/index-C8wRfTaF.css +1 -0
  23. package/web/dist/assets/index-NG58DXPC.js +21 -0
  24. package/web/dist/assets/{markdown-CIsUyqRd.js → markdown-BUScHEtT.js} +1 -1
  25. package/web/dist/assets/panels-C_0RapVg.js +1 -0
  26. package/web/dist/assets/{react-vendor-DuqM3ddv.js → react-vendor-C5NlWs7r.js} +1 -1
  27. package/web/dist/assets/{state-BCeK45RP.js → state-DKyBAq9j.js} +1 -1
  28. package/web/dist/index.html +6 -6
  29. package/web/dist/assets/ChannelConfigView-DPg31Ui7.js +0 -8
  30. package/web/dist/assets/HookConfigView-CBzuNojA.js +0 -3
  31. package/web/dist/assets/ModelsView-D4X70i7U.js +0 -1
  32. package/web/dist/assets/SessionGrid-CG6wC-sh.js +0 -20
  33. package/web/dist/assets/TerminalView-DJitpAf8.js +0 -3
  34. package/web/dist/assets/Toast-DJAVHqFo.js +0 -1
  35. package/web/dist/assets/index-B-DFEdP3.js +0 -21
  36. package/web/dist/assets/index-D2PsJB4J.css +0 -1
  37. package/web/dist/assets/panels-DP49kN7A.js +0 -1
@@ -1,4 +1,4 @@
1
- import{r as Pr,c as Fe,g as An}from"./icons-CjYP2PII.js";var Nt={exports:{}},Qe={};/**
1
+ import{r as Pr,c as Fe,g as An}from"./icons-uody4X-4.js";var Nt={exports:{}},Qe={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -0,0 +1 @@
1
+ import"./icons-uody4X-4.js";
@@ -1,4 +1,4 @@
1
- import{r as _a,g as Na}from"./icons-CjYP2PII.js";var Co={exports:{}},ve={},xo={exports:{}},_o={};/**
1
+ import{r as _a,g as Na}from"./icons-uody4X-4.js";var Co={exports:{}},ve={},xo={exports:{}},_o={};/**
2
2
  * @license React
3
3
  * scheduler.production.min.js
4
4
  *
@@ -1,4 +1,4 @@
1
- import{r as _,g as R,R as x}from"./icons-CjYP2PII.js";var w={exports:{}},D={};/**
1
+ import{r as _,g as R,R as x}from"./icons-uody4X-4.js";var w={exports:{}},D={};/**
2
2
  * @license React
3
3
  * use-sync-external-store-shim.production.js
4
4
  *
@@ -12,12 +12,12 @@
12
12
  <meta name="theme-color" content="#0d1117" />
13
13
  <meta name="color-scheme" content="dark light" />
14
14
  <title>DeepSeekCode Web</title>
15
- <script type="module" crossorigin src="/assets/index-B-DFEdP3.js"></script>
16
- <link rel="modulepreload" crossorigin href="/assets/icons-CjYP2PII.js">
17
- <link rel="modulepreload" crossorigin href="/assets/markdown-CIsUyqRd.js">
18
- <link rel="modulepreload" crossorigin href="/assets/react-vendor-DuqM3ddv.js">
19
- <link rel="modulepreload" crossorigin href="/assets/state-BCeK45RP.js">
20
- <link rel="stylesheet" crossorigin href="/assets/index-D2PsJB4J.css">
15
+ <script type="module" crossorigin src="/assets/index-NG58DXPC.js"></script>
16
+ <link rel="modulepreload" crossorigin href="/assets/icons-uody4X-4.js">
17
+ <link rel="modulepreload" crossorigin href="/assets/markdown-BUScHEtT.js">
18
+ <link rel="modulepreload" crossorigin href="/assets/react-vendor-C5NlWs7r.js">
19
+ <link rel="modulepreload" crossorigin href="/assets/state-DKyBAq9j.js">
20
+ <link rel="stylesheet" crossorigin href="/assets/index-C8wRfTaF.css">
21
21
  </head>
22
22
  <body>
23
23
  <div id="root"></div>
@@ -1,8 +0,0 @@
1
- import{j as i}from"./markdown-CIsUyqRd.js";import{r as v,aM as Ie,a5 as Me,a4 as Pe,aN as Ze,P as ee,aO as Re,$ as Le,ac as Xe,p as et}from"./icons-CjYP2PII.js";import{s as de,M as tt,a as xe}from"./index-B-DFEdP3.js";import"./react-vendor-DuqM3ddv.js";import"./state-BCeK45RP.js";const pe=new Set(["mattermost","msteams","googlechat","irc","imessage","sms","nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser","clickclack","raft","qa-channel"]),be={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"},we={wechat:"💬",feishu:"📘",dingtalk:"🔔",telegram:"✈️",discord:"🎮",slack:"💼",signal:"🔒",whatsapp:"📱",line:"🟢",qqbot:"🐧",matrix:"🧩",mattermost:"🏢",msteams:"📋",googlechat:"📧",irc:"💻",imessage:"✉️",sms:"📨"},ye=[{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 nt(){const{channels:t,selectedType:e,selectType:o}=de(),r=v.useMemo(()=>{const n=new Map;for(const s of t){const a=n.get(s.type)??{count:0,connected:0};n.set(s.type,{count:a.count+1,connected:a.connected+(s.connected?1:0)})}return n},[t]);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:t.length>0?`${t.length} 个已配置`:"点击下方频道开始配置"})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar",children:[ye.map(n=>{const s=n.types.filter(a=>r.has(a));return s.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:n.label}),s.map(a=>{const l=r.get(a);return i.jsx(Ne,{label:be[a]??a,icon:we[a]??"📡",isSelected:e===a,experimental:pe.has(a),info:l,onClick:()=>o(a)},a)})]},n.label)}),(()=>{const n=ye.flatMap(s=>s.types).filter(s=>!r.has(s));return n.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:"未配置"}),n.map(s=>i.jsx(Ne,{label:be[s]??s,icon:we[s]??"📡",isSelected:e===s,experimental:pe.has(s),onClick:()=>o(s)},s))]})})()]})]})}function Ne({label:t,icon:e,isSelected:o,experimental:r,info:n,onClick:s}){return i.jsxs("button",{onClick:s,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:e}),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:t}),r&&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(Ie,{className:"w-2.5 h-2.5"})," 实验"]}),n&&i.jsx("span",{className:"text-[10px] text-dark-muted bg-dark-hover px-1.5 py-0.5 rounded shrink-0",children:n.count})]}),i.jsx("div",{className:"flex items-center gap-1 mt-0.5",children:n?n.connected>0?i.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-green-400",children:[i.jsx(Me,{className:"w-3 h-3"}),n.connected===n.count?"已连接":`${n.connected}/${n.count} 已连接`]}):i.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-dark-muted",children:[i.jsx(Pe,{className:"w-3 h-3"}),"未连接"]}):i.jsx("span",{className:"text-[11px] text-dark-muted",children:"未配置"})})]})]})}const Ce=new Set(["mattermost","msteams","googlechat","irc","imessage","sms","nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser","clickclack","raft","qa-channel"]),ke={wechat:"微信",feishu:"飞书",dingtalk:"钉钉",telegram:"Telegram",discord:"Discord",slack:"Slack",signal:"Signal",whatsapp:"WhatsApp",line:"LINE",qqbot:"QQ Bot",matrix:"Matrix",mattermost:"Mattermost",msteams:"Microsoft 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 Channel"},je={wechat:"💬",feishu:"📘",dingtalk:"🔔",telegram:"✈️",discord:"🎮",slack:"💼",signal:"🔒",whatsapp:"📱",line:"🟢",qqbot:"🐧",matrix:"🧩",mattermost:"🏢",msteams:"📋",googlechat:"📧",irc:"💻",imessage:"✉️",sms:"📨"},L={name:"",type:"wechat",appId:"",appSecret:"",token:"",encodingAESKey:"",enabled:!0};function rt(){const{channels:t,selectedType:e,create:o,update:r,remove:n,toggle:s,error:a,clearError:l,openQr:c,load:u}=de(),d=v.useMemo(()=>e?t.filter(N=>N.type===e):[],[t,e]),[y,g]=v.useState(""),[h,x]=v.useState(L),[C,j]=v.useState(!1),p=y==="__new__",m=v.useMemo(()=>p?null:d.find(N=>N.id===y)??null,[d,y,p]);v.useEffect(()=>{g(""),x(L),j(!1),l()},[e]),v.useEffect(()=>{m?x({name:m.name,type:m.type,appId:m.appId||"",appSecret:"",token:"",encodingAESKey:m.encodingAESKey||"",enabled:m.enabled}):p&&x(N=>({...N,type:e}))},[y]);const b=(N,A)=>{l(),x(z=>({...z,[N]:A}))},f=N=>{g(N),l()},w=()=>{g("__new__"),x({...L,type:e}),l()},k=()=>{g(""),x(L),l()},E=async()=>{if(!h.name.trim())return;j(!0);const N=m?await r(m.id,h):await o(h);j(!1),N&&(g(""),x(L))},S=async N=>{if(!confirm("确认删除该频道?"))return;await n(N)&&y===N&&(g(""),x(L))},B=(N,A)=>{s(N,A)};return e?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:je[e]??"📡"}),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:ke[e]??e}),Ce.has(e)&&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(Ie,{className:"w-3 h-3"})," 实验性"]})]}),i.jsx("p",{className:"text-xs text-dark-muted mt-0.5",children:d.length>0?`${d.length} 个配置实例`:"尚未配置"}),Ce.has(e)&&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:()=>u(),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:w,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(ee,{className:"w-3.5 h-3.5"})," 新建实例"]})]})]})}),a&&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:a}),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:"×"})})]}),i.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar p-6",children:[d.length>1&&!p&&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:[d.map(N=>i.jsxs("button",{onClick:()=>f(N.id),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs border transition-colors ${y===N.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 ${N.connected?"bg-green-500":"bg-gray-500"}`}),N.name]},N.id)),i.jsxs("button",{onClick:w,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(ee,{className:"w-3 h-3"})," 新建"]})]})]}),d.length===0&&y===""&&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:je[e]??"📡"}),i.jsxs("p",{className:"text-dark-text font-medium",children:["还没有配置 ",ke[e]??e]}),i.jsx("p",{className:"text-sm text-dark-muted mt-1 mb-4",children:"点击上方「新建实例」开始配置"}),i.jsxs("button",{onClick:w,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(ee,{className:"w-4 h-4"})," 新建实例"]})]}),d.length===1&&y===""&&d[0]&&i.jsx(Ee,{channel:d[0],onEdit:()=>f(d[0].id),onDelete:()=>S(d[0].id),onToggle:N=>B(d[0].id,N),onQr:()=>c(d[0])}),d.length>1&&y===""&&i.jsx("div",{className:"space-y-3",children:d.map(N=>i.jsx(Ee,{channel:N,onEdit:()=>f(N.id),onDelete:()=>S(N.id),onToggle:A=>B(N.id,A),onQr:()=>c(N)},N.id))}),y!==""&&(p||m)&&i.jsx(st,{form:h,upd:b,saving:C,editing:!!m,channel:m??void 0,onSave:E,onCancel:k,onDelete:m?()=>S(m.id):void 0,onQr:m?()=>c(m):void 0})]})]}):i.jsx("div",{className:"flex-1 flex items-center justify-center",children:i.jsxs("div",{className:"text-center",children:[i.jsx(Ze,{className:"w-12 h-12 mx-auto mb-3 text-dark-muted/40"}),i.jsx("p",{className:"text-dark-muted text-sm",children:"请从左侧选择一个频道类型"})]})})}function Ee({channel:t,onEdit:e,onDelete:o,onToggle:r,onQr:n}){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:t.name}),i.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[i.jsx("span",{className:`flex items-center gap-1 text-xs ${t.connected?"text-green-400":"text-dark-muted"}`,children:t.connected?i.jsxs(i.Fragment,{children:[i.jsx(Me,{className:"w-3 h-3"})," 已连接"]}):i.jsxs(i.Fragment,{children:[i.jsx(Pe,{className:"w-3 h-3"})," 未连接"]})}),i.jsxs("span",{className:"text-xs text-dark-muted",children:["AppID: ",t.appId||"—"]})]})]}),i.jsx("button",{onClick:()=>r(!t.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${t.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 ${t.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:[t.type==="wechat"&&i.jsxs("button",{onClick:n,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(Re,{className:"w-3.5 h-3.5"})," 扫码登录"]}),i.jsxs("button",{onClick:e,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(Le,{className:"w-3.5 h-3.5"})," 删除"]})]})]})}function st({form:t,upd:e,saving:o,editing:r,channel:n,onSave:s,onCancel:a,onDelete:l,onQr:c}){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:r?"编辑配置":"新建配置"})}),i.jsxs("div",{className:"p-5 space-y-4",children:[i.jsx(ve,{label:"频道名称",required:!0,children:i.jsx("input",{value:t.name,onChange:u=>e("name",u.target.value),placeholder:"例如:研发群机器人",className:$})}),i.jsxs(ve,{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:t.appId,onChange:u=>e("appId",u.target.value),placeholder:"AppID",className:$})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"AppSecret"}),i.jsx("input",{type:"password",value:t.appSecret,onChange:u=>e("appSecret",u.target.value),placeholder:r?"留空不修改":"应用密钥",className:$})]}),i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"Token"}),i.jsx("input",{value:t.token,onChange:u=>e("token",u.target.value),placeholder:r?"留空不修改":"回调校验 Token",className:$})]}),t.type==="wechat"&&i.jsxs("div",{children:[i.jsx("label",{className:"block text-[10px] text-dark-muted mb-1",children:"EncodingAESKey"}),i.jsx("input",{value:t.encodingAESKey,onChange:u=>e("encodingAESKey",u.target.value),placeholder:"选填",className:$})]})]}),t.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:()=>e("enabled",!t.enabled),className:`w-9 h-5 rounded-full relative transition-colors shrink-0 ${t.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 ${t.enabled?"left-[18px]":"left-0.5"}`})})]}),r&&(n==null?void 0:n.type)==="wechat"&&c&&i.jsxs("button",{onClick:c,className:"w-full flex items-center justify-center gap-2 text-sm bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 px-3 py-2.5 rounded-lg transition-colors",children:[i.jsx(Re,{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:r&&l&&i.jsxs("button",{onClick:l,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(Le,{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||!t.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(Xe,{className:"w-3.5 h-3.5"}),o?"保存中...":"保存"]})]})]})]})}function ve({label:t,required:e,children:o}){return i.jsxs("div",{children:[i.jsxs("label",{className:"block text-xs text-dark-muted mb-1.5",children:[t,e&&i.jsx("span",{className:"text-red-400 ml-0.5",children:"*"})]}),o]})}const $="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 O={},ot=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},_e={},T={};let ue;const it=[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];T.getSymbolSize=function(e){if(!e)throw new Error('"version" cannot be null or undefined');if(e<1||e>40)throw new Error('"version" should be in range from 1 to 40');return e*4+17};T.getSymbolTotalCodewords=function(e){return it[e]};T.getBCHDigit=function(t){let e=0;for(;t!==0;)e++,t>>>=1;return e};T.setToSJISFunction=function(e){if(typeof e!="function")throw new Error('"toSJISFunc" is not a valid function.');ue=e};T.isKanjiModeEnabled=function(){return typeof ue<"u"};T.toSJIS=function(e){return ue(e)};var G={};(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function e(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+o)}}t.isValid=function(r){return r&&typeof r.bit<"u"&&r.bit>=0&&r.bit<4},t.from=function(r,n){if(t.isValid(r))return r;try{return e(r)}catch{return n}}})(G);function De(){this.buffer=[],this.length=0}De.prototype={get:function(t){const e=Math.floor(t/8);return(this.buffer[e]>>>7-t%8&1)===1},put:function(t,e){for(let o=0;o<e;o++)this.putBit((t>>>e-o-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(t){const e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}};var at=De;function V(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}V.prototype.set=function(t,e,o,r){const n=t*this.size+e;this.data[n]=o,r&&(this.reservedBit[n]=!0)};V.prototype.get=function(t,e){return this.data[t*this.size+e]};V.prototype.xor=function(t,e,o){this.data[t*this.size+e]^=o};V.prototype.isReserved=function(t,e){return this.reservedBit[t*this.size+e]};var lt=V,Ue={};(function(t){const e=T.getSymbolSize;t.getRowColCoords=function(r){if(r===1)return[];const n=Math.floor(r/7)+2,s=e(r),a=s===145?26:Math.ceil((s-13)/(2*n-2))*2,l=[s-7];for(let c=1;c<n-1;c++)l[c]=l[c-1]-a;return l.push(6),l.reverse()},t.getPositions=function(r){const n=[],s=t.getRowColCoords(r),a=s.length;for(let l=0;l<a;l++)for(let c=0;c<a;c++)l===0&&c===0||l===0&&c===a-1||l===a-1&&c===0||n.push([s[l],s[c]]);return n}})(Ue);var Fe={};const ct=T.getSymbolSize,Se=7;Fe.getPositions=function(e){const o=ct(e);return[[0,0],[o-Se,0],[0,o-Se]]};var ze={};(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const e={N1:3,N2:3,N3:40,N4:10};t.isValid=function(n){return n!=null&&n!==""&&!isNaN(n)&&n>=0&&n<=7},t.from=function(n){return t.isValid(n)?parseInt(n,10):void 0},t.getPenaltyN1=function(n){const s=n.size;let a=0,l=0,c=0,u=null,d=null;for(let y=0;y<s;y++){l=c=0,u=d=null;for(let g=0;g<s;g++){let h=n.get(y,g);h===u?l++:(l>=5&&(a+=e.N1+(l-5)),u=h,l=1),h=n.get(g,y),h===d?c++:(c>=5&&(a+=e.N1+(c-5)),d=h,c=1)}l>=5&&(a+=e.N1+(l-5)),c>=5&&(a+=e.N1+(c-5))}return a},t.getPenaltyN2=function(n){const s=n.size;let a=0;for(let l=0;l<s-1;l++)for(let c=0;c<s-1;c++){const u=n.get(l,c)+n.get(l,c+1)+n.get(l+1,c)+n.get(l+1,c+1);(u===4||u===0)&&a++}return a*e.N2},t.getPenaltyN3=function(n){const s=n.size;let a=0,l=0,c=0;for(let u=0;u<s;u++){l=c=0;for(let d=0;d<s;d++)l=l<<1&2047|n.get(u,d),d>=10&&(l===1488||l===93)&&a++,c=c<<1&2047|n.get(d,u),d>=10&&(c===1488||c===93)&&a++}return a*e.N3},t.getPenaltyN4=function(n){let s=0;const a=n.data.length;for(let c=0;c<a;c++)s+=n.data[c];return Math.abs(Math.ceil(s*100/a/5)-10)*e.N4};function o(r,n,s){switch(r){case t.Patterns.PATTERN000:return(n+s)%2===0;case t.Patterns.PATTERN001:return n%2===0;case t.Patterns.PATTERN010:return s%3===0;case t.Patterns.PATTERN011:return(n+s)%3===0;case t.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(s/3))%2===0;case t.Patterns.PATTERN101:return n*s%2+n*s%3===0;case t.Patterns.PATTERN110:return(n*s%2+n*s%3)%2===0;case t.Patterns.PATTERN111:return(n*s%3+(n+s)%2)%2===0;default:throw new Error("bad maskPattern:"+r)}}t.applyMask=function(n,s){const a=s.size;for(let l=0;l<a;l++)for(let c=0;c<a;c++)s.isReserved(c,l)||s.xor(c,l,o(n,c,l))},t.getBestMask=function(n,s){const a=Object.keys(t.Patterns).length;let l=0,c=1/0;for(let u=0;u<a;u++){s(u),t.applyMask(u,n);const d=t.getPenaltyN1(n)+t.getPenaltyN2(n)+t.getPenaltyN3(n)+t.getPenaltyN4(n);t.applyMask(u,n),d<c&&(c=d,l=u)}return l}})(ze);var W={};const P=G,q=[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],Q=[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];W.getBlocksCount=function(e,o){switch(o){case P.L:return q[(e-1)*4+0];case P.M:return q[(e-1)*4+1];case P.Q:return q[(e-1)*4+2];case P.H:return q[(e-1)*4+3];default:return}};W.getTotalCodewordsCount=function(e,o){switch(o){case P.L:return Q[(e-1)*4+0];case P.M:return Q[(e-1)*4+1];case P.Q:return Q[(e-1)*4+2];case P.H:return Q[(e-1)*4+3];default:return}};var $e={},Z={};const K=new Uint8Array(512),J=new Uint8Array(256);(function(){let e=1;for(let o=0;o<255;o++)K[o]=e,J[e]=o,e<<=1,e&256&&(e^=285);for(let o=255;o<512;o++)K[o]=K[o-255]})();Z.log=function(e){if(e<1)throw new Error("log("+e+")");return J[e]};Z.exp=function(e){return K[e]};Z.mul=function(e,o){return e===0||o===0?0:K[J[e]+J[o]]};(function(t){const e=Z;t.mul=function(r,n){const s=new Uint8Array(r.length+n.length-1);for(let a=0;a<r.length;a++)for(let l=0;l<n.length;l++)s[a+l]^=e.mul(r[a],n[l]);return s},t.mod=function(r,n){let s=new Uint8Array(r);for(;s.length-n.length>=0;){const a=s[0];for(let c=0;c<n.length;c++)s[c]^=e.mul(n[c],a);let l=0;for(;l<s.length&&s[l]===0;)l++;s=s.slice(l)}return s},t.generateECPolynomial=function(r){let n=new Uint8Array([1]);for(let s=0;s<r;s++)n=t.mul(n,new Uint8Array([1,e.exp(s)]));return n}})($e);const Ke=$e;function fe(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}fe.prototype.initialize=function(e){this.degree=e,this.genPoly=Ke.generateECPolynomial(this.degree)};fe.prototype.encode=function(e){if(!this.genPoly)throw new Error("Encoder not initialized");const o=new Uint8Array(e.length+this.degree);o.set(e);const r=Ke.mod(o,this.genPoly),n=this.degree-r.length;if(n>0){const s=new Uint8Array(this.degree);return s.set(r,n),s}return r};var dt=fe,He={},R={},he={};he.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40};var I={};const Oe="[0-9]+",ut="[A-Z $%*+\\-./:]+";let H="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";H=H.replace(/u/g,"\\u");const ft="(?:(?![A-Z0-9 $%*+\\-./:]|"+H+`)(?:.|[\r
2
- ]))+`;I.KANJI=new RegExp(H,"g");I.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g");I.BYTE=new RegExp(ft,"g");I.NUMERIC=new RegExp(Oe,"g");I.ALPHANUMERIC=new RegExp(ut,"g");const ht=new RegExp("^"+H+"$"),gt=new RegExp("^"+Oe+"$"),mt=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");I.testKanji=function(e){return ht.test(e)};I.testNumeric=function(e){return gt.test(e)};I.testAlphanumeric=function(e){return mt.test(e)};(function(t){const e=he,o=I;t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(s,a){if(!s.ccBits)throw new Error("Invalid mode: "+s);if(!e.isValid(a))throw new Error("Invalid version: "+a);return a>=1&&a<10?s.ccBits[0]:a<27?s.ccBits[1]:s.ccBits[2]},t.getBestModeForData=function(s){return o.testNumeric(s)?t.NUMERIC:o.testAlphanumeric(s)?t.ALPHANUMERIC:o.testKanji(s)?t.KANJI:t.BYTE},t.toString=function(s){if(s&&s.id)return s.id;throw new Error("Invalid mode")},t.isValid=function(s){return s&&s.bit&&s.ccBits};function r(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+n)}}t.from=function(s,a){if(t.isValid(s))return s;try{return r(s)}catch{return a}}})(R);(function(t){const e=T,o=W,r=G,n=R,s=he,a=7973,l=e.getBCHDigit(a);function c(g,h,x){for(let C=1;C<=40;C++)if(h<=t.getCapacity(C,x,g))return C}function u(g,h){return n.getCharCountIndicator(g,h)+4}function d(g,h){let x=0;return g.forEach(function(C){const j=u(C.mode,h);x+=j+C.getBitsLength()}),x}function y(g,h){for(let x=1;x<=40;x++)if(d(g,x)<=t.getCapacity(x,h,n.MIXED))return x}t.from=function(h,x){return s.isValid(h)?parseInt(h,10):x},t.getCapacity=function(h,x,C){if(!s.isValid(h))throw new Error("Invalid QR Code version");typeof C>"u"&&(C=n.BYTE);const j=e.getSymbolTotalCodewords(h),p=o.getTotalCodewordsCount(h,x),m=(j-p)*8;if(C===n.MIXED)return m;const b=m-u(C,h);switch(C){case n.NUMERIC:return Math.floor(b/10*3);case n.ALPHANUMERIC:return Math.floor(b/11*2);case n.KANJI:return Math.floor(b/13);case n.BYTE:default:return Math.floor(b/8)}},t.getBestVersionForData=function(h,x){let C;const j=r.from(x,r.M);if(Array.isArray(h)){if(h.length>1)return y(h,j);if(h.length===0)return 1;C=h[0]}else C=h;return c(C.mode,C.getLength(),j)},t.getEncodedBits=function(h){if(!s.isValid(h)||h<7)throw new Error("Invalid QR Code version");let x=h<<12;for(;e.getBCHDigit(x)-l>=0;)x^=a<<e.getBCHDigit(x)-l;return h<<12|x}})(He);var Ve={};const ie=T,qe=1335,xt=21522,Te=ie.getBCHDigit(qe);Ve.getEncodedBits=function(e,o){const r=e.bit<<3|o;let n=r<<10;for(;ie.getBCHDigit(n)-Te>=0;)n^=qe<<ie.getBCHDigit(n)-Te;return(r<<10|n)^xt};var Qe={};const pt=R;function _(t){this.mode=pt.NUMERIC,this.data=t.toString()}_.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)};_.prototype.getLength=function(){return this.data.length};_.prototype.getBitsLength=function(){return _.getBitsLength(this.data.length)};_.prototype.write=function(e){let o,r,n;for(o=0;o+3<=this.data.length;o+=3)r=this.data.substr(o,3),n=parseInt(r,10),e.put(n,10);const s=this.data.length-o;s>0&&(r=this.data.substr(o),n=parseInt(r,10),e.put(n,s*3+1))};var bt=_;const wt=R,te=["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 D(t){this.mode=wt.ALPHANUMERIC,this.data=t}D.getBitsLength=function(e){return 11*Math.floor(e/2)+6*(e%2)};D.prototype.getLength=function(){return this.data.length};D.prototype.getBitsLength=function(){return D.getBitsLength(this.data.length)};D.prototype.write=function(e){let o;for(o=0;o+2<=this.data.length;o+=2){let r=te.indexOf(this.data[o])*45;r+=te.indexOf(this.data[o+1]),e.put(r,11)}this.data.length%2&&e.put(te.indexOf(this.data[o]),6)};var yt=D;const Nt=R;function U(t){this.mode=Nt.BYTE,typeof t=="string"?this.data=new TextEncoder().encode(t):this.data=new Uint8Array(t)}U.getBitsLength=function(e){return e*8};U.prototype.getLength=function(){return this.data.length};U.prototype.getBitsLength=function(){return U.getBitsLength(this.data.length)};U.prototype.write=function(t){for(let e=0,o=this.data.length;e<o;e++)t.put(this.data[e],8)};var Ct=U;const kt=R,jt=T;function F(t){this.mode=kt.KANJI,this.data=t}F.getBitsLength=function(e){return e*13};F.prototype.getLength=function(){return this.data.length};F.prototype.getBitsLength=function(){return F.getBitsLength(this.data.length)};F.prototype.write=function(t){let e;for(e=0;e<this.data.length;e++){let o=jt.toSJIS(this.data[e]);if(o>=33088&&o<=40956)o-=33088;else if(o>=57408&&o<=60351)o-=49472;else throw new Error("Invalid SJIS character: "+this.data[e]+`
3
- Make sure your charset is UTF-8`);o=(o>>>8&255)*192+(o&255),t.put(o,13)}};var Et=F,Je={exports:{}};(function(t){var e={single_source_shortest_paths:function(o,r,n){var s={},a={};a[r]=0;var l=e.PriorityQueue.make();l.push(r,0);for(var c,u,d,y,g,h,x,C,j;!l.empty();){c=l.pop(),u=c.value,y=c.cost,g=o[u]||{};for(d in g)g.hasOwnProperty(d)&&(h=g[d],x=y+h,C=a[d],j=typeof a[d]>"u",(j||C>x)&&(a[d]=x,l.push(d,x),s[d]=u))}if(typeof n<"u"&&typeof a[n]>"u"){var p=["Could not find a path from ",r," to ",n,"."].join("");throw new Error(p)}return s},extract_shortest_path_from_predecessor_list:function(o,r){for(var n=[],s=r;s;)n.push(s),o[s],s=o[s];return n.reverse(),n},find_path:function(o,r,n){var s=e.single_source_shortest_paths(o,r,n);return e.extract_shortest_path_from_predecessor_list(s,n)},PriorityQueue:{make:function(o){var r=e.PriorityQueue,n={},s;o=o||{};for(s in r)r.hasOwnProperty(s)&&(n[s]=r[s]);return n.queue=[],n.sorter=o.sorter||r.default_sorter,n},default_sorter:function(o,r){return o.cost-r.cost},push:function(o,r){var n={value:o,cost:r};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=e})(Je);var vt=Je.exports;(function(t){const e=R,o=bt,r=yt,n=Ct,s=Et,a=I,l=T,c=vt;function u(p){return unescape(encodeURIComponent(p)).length}function d(p,m,b){const f=[];let w;for(;(w=p.exec(b))!==null;)f.push({data:w[0],index:w.index,mode:m,length:w[0].length});return f}function y(p){const m=d(a.NUMERIC,e.NUMERIC,p),b=d(a.ALPHANUMERIC,e.ALPHANUMERIC,p);let f,w;return l.isKanjiModeEnabled()?(f=d(a.BYTE,e.BYTE,p),w=d(a.KANJI,e.KANJI,p)):(f=d(a.BYTE_KANJI,e.BYTE,p),w=[]),m.concat(b,f,w).sort(function(E,S){return E.index-S.index}).map(function(E){return{data:E.data,mode:E.mode,length:E.length}})}function g(p,m){switch(m){case e.NUMERIC:return o.getBitsLength(p);case e.ALPHANUMERIC:return r.getBitsLength(p);case e.KANJI:return s.getBitsLength(p);case e.BYTE:return n.getBitsLength(p)}}function h(p){return p.reduce(function(m,b){const f=m.length-1>=0?m[m.length-1]:null;return f&&f.mode===b.mode?(m[m.length-1].data+=b.data,m):(m.push(b),m)},[])}function x(p){const m=[];for(let b=0;b<p.length;b++){const f=p[b];switch(f.mode){case e.NUMERIC:m.push([f,{data:f.data,mode:e.ALPHANUMERIC,length:f.length},{data:f.data,mode:e.BYTE,length:f.length}]);break;case e.ALPHANUMERIC:m.push([f,{data:f.data,mode:e.BYTE,length:f.length}]);break;case e.KANJI:m.push([f,{data:f.data,mode:e.BYTE,length:u(f.data)}]);break;case e.BYTE:m.push([{data:f.data,mode:e.BYTE,length:u(f.data)}])}}return m}function C(p,m){const b={},f={start:{}};let w=["start"];for(let k=0;k<p.length;k++){const E=p[k],S=[];for(let B=0;B<E.length;B++){const N=E[B],A=""+k+B;S.push(A),b[A]={node:N,lastCount:0},f[A]={};for(let z=0;z<w.length;z++){const M=w[z];b[M]&&b[M].node.mode===N.mode?(f[M][A]=g(b[M].lastCount+N.length,N.mode)-g(b[M].lastCount,N.mode),b[M].lastCount+=N.length):(b[M]&&(b[M].lastCount=N.length),f[M][A]=g(N.length,N.mode)+4+e.getCharCountIndicator(N.mode,m))}}w=S}for(let k=0;k<w.length;k++)f[w[k]].end=0;return{map:f,table:b}}function j(p,m){let b;const f=e.getBestModeForData(p);if(b=e.from(m,f),b!==e.BYTE&&b.bit<f.bit)throw new Error('"'+p+'" cannot be encoded with mode '+e.toString(b)+`.
4
- Suggested mode is: `+e.toString(f));switch(b===e.KANJI&&!l.isKanjiModeEnabled()&&(b=e.BYTE),b){case e.NUMERIC:return new o(p);case e.ALPHANUMERIC:return new r(p);case e.KANJI:return new s(p);case e.BYTE:return new n(p)}}t.fromArray=function(m){return m.reduce(function(b,f){return typeof f=="string"?b.push(j(f,null)):f.data&&b.push(j(f.data,f.mode)),b},[])},t.fromString=function(m,b){const f=y(m,l.isKanjiModeEnabled()),w=x(f),k=C(w,b),E=c.find_path(k.map,"start","end"),S=[];for(let B=1;B<E.length-1;B++)S.push(k.table[E[B]].node);return t.fromArray(h(S))},t.rawSplit=function(m){return t.fromArray(y(m,l.isKanjiModeEnabled()))}})(Qe);const X=T,ne=G,St=at,Tt=lt,At=Ue,Bt=Fe,ae=ze,le=W,It=dt,Y=He,Mt=Ve,Pt=R,re=Qe;function Rt(t,e){const o=t.size,r=Bt.getPositions(e);for(let n=0;n<r.length;n++){const s=r[n][0],a=r[n][1];for(let l=-1;l<=7;l++)if(!(s+l<=-1||o<=s+l))for(let c=-1;c<=7;c++)a+c<=-1||o<=a+c||(l>=0&&l<=6&&(c===0||c===6)||c>=0&&c<=6&&(l===0||l===6)||l>=2&&l<=4&&c>=2&&c<=4?t.set(s+l,a+c,!0,!0):t.set(s+l,a+c,!1,!0))}}function Lt(t){const e=t.size;for(let o=8;o<e-8;o++){const r=o%2===0;t.set(o,6,r,!0),t.set(6,o,r,!0)}}function _t(t,e){const o=At.getPositions(e);for(let r=0;r<o.length;r++){const n=o[r][0],s=o[r][1];for(let a=-2;a<=2;a++)for(let l=-2;l<=2;l++)a===-2||a===2||l===-2||l===2||a===0&&l===0?t.set(n+a,s+l,!0,!0):t.set(n+a,s+l,!1,!0)}}function Dt(t,e){const o=t.size,r=Y.getEncodedBits(e);let n,s,a;for(let l=0;l<18;l++)n=Math.floor(l/3),s=l%3+o-8-3,a=(r>>l&1)===1,t.set(n,s,a,!0),t.set(s,n,a,!0)}function se(t,e,o){const r=t.size,n=Mt.getEncodedBits(e,o);let s,a;for(s=0;s<15;s++)a=(n>>s&1)===1,s<6?t.set(s,8,a,!0):s<8?t.set(s+1,8,a,!0):t.set(r-15+s,8,a,!0),s<8?t.set(8,r-s-1,a,!0):s<9?t.set(8,15-s-1+1,a,!0):t.set(8,15-s-1,a,!0);t.set(r-8,8,1,!0)}function Ut(t,e){const o=t.size;let r=-1,n=o-1,s=7,a=0;for(let l=o-1;l>0;l-=2)for(l===6&&l--;;){for(let c=0;c<2;c++)if(!t.isReserved(n,l-c)){let u=!1;a<e.length&&(u=(e[a]>>>s&1)===1),t.set(n,l-c,u),s--,s===-1&&(a++,s=7)}if(n+=r,n<0||o<=n){n-=r,r=-r;break}}}function Ft(t,e,o){const r=new St;o.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),Pt.getCharCountIndicator(c.mode,t)),c.write(r)});const n=X.getSymbolTotalCodewords(t),s=le.getTotalCodewordsCount(t,e),a=(n-s)*8;for(r.getLengthInBits()+4<=a&&r.put(0,4);r.getLengthInBits()%8!==0;)r.putBit(0);const l=(a-r.getLengthInBits())/8;for(let c=0;c<l;c++)r.put(c%2?17:236,8);return zt(r,t,e)}function zt(t,e,o){const r=X.getSymbolTotalCodewords(e),n=le.getTotalCodewordsCount(e,o),s=r-n,a=le.getBlocksCount(e,o),l=r%a,c=a-l,u=Math.floor(r/a),d=Math.floor(s/a),y=d+1,g=u-d,h=new It(g);let x=0;const C=new Array(a),j=new Array(a);let p=0;const m=new Uint8Array(t.buffer);for(let E=0;E<a;E++){const S=E<c?d:y;C[E]=m.slice(x,x+S),j[E]=h.encode(C[E]),x+=S,p=Math.max(p,S)}const b=new Uint8Array(r);let f=0,w,k;for(w=0;w<p;w++)for(k=0;k<a;k++)w<C[k].length&&(b[f++]=C[k][w]);for(w=0;w<g;w++)for(k=0;k<a;k++)b[f++]=j[k][w];return b}function $t(t,e,o,r){let n;if(Array.isArray(t))n=re.fromArray(t);else if(typeof t=="string"){let u=e;if(!u){const d=re.rawSplit(t);u=Y.getBestVersionForData(d,o)}n=re.fromString(t,u||40)}else throw new Error("Invalid data");const s=Y.getBestVersionForData(n,o);if(!s)throw new Error("The amount of data is too big to be stored in a QR Code");if(!e)e=s;else if(e<s)throw new Error(`
5
- The chosen QR Code version cannot contain this amount of data.
6
- Minimum version required to store current data is: `+s+`.
7
- `);const a=Ft(e,o,n),l=X.getSymbolSize(e),c=new Tt(l);return Rt(c,e),Lt(c),_t(c,e),se(c,o,0),e>=7&&Dt(c,e),Ut(c,a),isNaN(r)&&(r=ae.getBestMask(c,se.bind(null,c,o))),ae.applyMask(r,c),se(c,o,r),{modules:c,version:e,errorCorrectionLevel:o,maskPattern:r,segments:n}}_e.create=function(e,o){if(typeof e>"u"||e==="")throw new Error("No input text");let r=ne.M,n,s;return typeof o<"u"&&(r=ne.from(o.errorCorrectionLevel,ne.M),n=Y.from(o.version),s=ae.from(o.maskPattern),o.toSJISFunc&&X.setToSJISFunction(o.toSJISFunc)),$t(e,n,r,s)};var Ye={},ge={};(function(t){function e(o){if(typeof o=="number"&&(o=o.toString()),typeof o!="string")throw new Error("Color should be defined as hex string");let r=o.slice().replace("#","").split("");if(r.length<3||r.length===5||r.length>8)throw new Error("Invalid hex color: "+o);(r.length===3||r.length===4)&&(r=Array.prototype.concat.apply([],r.map(function(s){return[s,s]}))),r.length===6&&r.push("F","F");const n=parseInt(r.join(""),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:n&255,hex:"#"+r.slice(0,6).join("")}}t.getOptions=function(r){r||(r={}),r.color||(r.color={});const n=typeof r.margin>"u"||r.margin===null||r.margin<0?4:r.margin,s=r.width&&r.width>=21?r.width:void 0,a=r.scale||4;return{width:s,scale:s?4:a,margin:n,color:{dark:e(r.color.dark||"#000000ff"),light:e(r.color.light||"#ffffffff")},type:r.type,rendererOpts:r.rendererOpts||{}}},t.getScale=function(r,n){return n.width&&n.width>=r+n.margin*2?n.width/(r+n.margin*2):n.scale},t.getImageWidth=function(r,n){const s=t.getScale(r,n);return Math.floor((r+n.margin*2)*s)},t.qrToImageData=function(r,n,s){const a=n.modules.size,l=n.modules.data,c=t.getScale(a,s),u=Math.floor((a+s.margin*2)*c),d=s.margin*c,y=[s.color.light,s.color.dark];for(let g=0;g<u;g++)for(let h=0;h<u;h++){let x=(g*u+h)*4,C=s.color.light;if(g>=d&&h>=d&&g<u-d&&h<u-d){const j=Math.floor((g-d)/c),p=Math.floor((h-d)/c);C=y[l[j*a+p]?1:0]}r[x++]=C.r,r[x++]=C.g,r[x++]=C.b,r[x]=C.a}}})(ge);(function(t){const e=ge;function o(n,s,a){n.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 r(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(s,a,l){let c=l,u=a;typeof c>"u"&&(!a||!a.getContext)&&(c=a,a=void 0),a||(u=r()),c=e.getOptions(c);const d=e.getImageWidth(s.modules.size,c),y=u.getContext("2d"),g=y.createImageData(d,d);return e.qrToImageData(g.data,s,c),o(y,u,d),y.putImageData(g,0,0),u},t.renderToDataURL=function(s,a,l){let c=l;typeof c>"u"&&(!a||!a.getContext)&&(c=a,a=void 0),c||(c={});const u=t.render(s,a,c),d=c.type||"image/png",y=c.rendererOpts||{};return u.toDataURL(d,y.quality)}})(Ye);var Ge={};const Kt=ge;function Ae(t,e){const o=t.a/255,r=e+'="'+t.hex+'"';return o<1?r+" "+e+'-opacity="'+o.toFixed(2).slice(1)+'"':r}function oe(t,e,o){let r=t+e;return typeof o<"u"&&(r+=" "+o),r}function Ht(t,e,o){let r="",n=0,s=!1,a=0;for(let l=0;l<t.length;l++){const c=Math.floor(l%e),u=Math.floor(l/e);!c&&!s&&(s=!0),t[l]?(a++,l>0&&c>0&&t[l-1]||(r+=s?oe("M",c+o,.5+u+o):oe("m",n,0),n=0,s=!1),c+1<e&&t[l+1]||(r+=oe("h",a),a=0)):n++}return r}Ge.render=function(e,o,r){const n=Kt.getOptions(o),s=e.modules.size,a=e.modules.data,l=s+n.margin*2,c=n.color.light.a?"<path "+Ae(n.color.light,"fill")+' d="M0 0h'+l+"v"+l+'H0z"/>':"",u="<path "+Ae(n.color.dark,"stroke")+' d="'+Ht(a,s,n.margin)+'"/>',d='viewBox="0 0 '+l+" "+l+'"',g='<svg xmlns="http://www.w3.org/2000/svg" '+(n.width?'width="'+n.width+'" height="'+n.width+'" ':"")+d+' shape-rendering="crispEdges">'+c+u+`</svg>
8
- `;return typeof r=="function"&&r(null,g),g};const Ot=ot,ce=_e,We=Ye,Vt=Ge;function me(t,e,o,r,n){const s=[].slice.call(arguments,1),a=s.length,l=typeof s[a-1]=="function";if(!l&&!Ot())throw new Error("Callback required as last argument");if(l){if(a<2)throw new Error("Too few arguments provided");a===2?(n=o,o=e,e=r=void 0):a===3&&(e.getContext&&typeof n>"u"?(n=r,r=void 0):(n=r,r=o,o=e,e=void 0))}else{if(a<1)throw new Error("Too few arguments provided");return a===1?(o=e,e=r=void 0):a===2&&!e.getContext&&(r=o,o=e,e=void 0),new Promise(function(c,u){try{const d=ce.create(o,r);c(t(d,e,r))}catch(d){u(d)}})}try{const c=ce.create(o,r);n(null,t(c,e,r))}catch(c){n(c)}}O.create=ce.create;O.toCanvas=me.bind(null,We.render);O.toDataURL=me.bind(null,We.renderToDataURL);O.toString=me.bind(null,function(t,e,o){return Vt.render(t,o)});const qt=2e3,Be=5;function Qt({channel:t,onClose:e}){const[o,r]=v.useState("loading"),[n,s]=v.useState(null),[a,l]=v.useState(null),[c,u]=v.useState(""),d=v.useRef(null),y=v.useRef(0),g=v.useRef(null),h=v.useRef(!1),x=()=>{g.current&&(clearTimeout(g.current),g.current=null),h.current=!0},C=async f=>{if(d.current)try{await O.toCanvas(d.current,f,{width:240,margin:2,color:{dark:"#000000ff",light:"#ffffffff"}})}catch(w){console.warn("[WechatQr] Canvas QR generation failed, falling back to URL:",w)}},j=async()=>{if(!(h.current||!a))try{const f=await xe.channels.weixin.bindStatus(a),w=(f==null?void 0:f.data)??f,k=(w==null?void 0:w.status)??"";if(y.current=0,k==="confirmed"){r("confirmed"),setTimeout(e,1200);return}if(k==="scaned")r("scanned");else if(k==="expired"){r("expired");return}h.current||(g.current=setTimeout(j,qt))}catch(f){if(y.current++,console.warn("[WechatQr] poll error ("+y.current+"/"+Be+")",f),y.current>=Be)r("error"),u("轮询状态失败次数过多,请刷新二维码重试");else if(!h.current){const w=Math.min(1e3*Math.pow(2,y.current),1e4);g.current=setTimeout(j,w)}}},p=()=>{x(),h.current=!1,y.current=0,g.current=setTimeout(j,1e3)},m=async()=>{r("loading"),s(null),l(null),u(""),y.current=0;try{const f=await xe.channels.weixin.bind(),w=(f==null?void 0:f.data)??f,k=(w==null?void 0:w.qrcode_img_content)??"",E=(w==null?void 0:w.qrcode)??"";if(!k||!E){r("error"),u(`二维码数据缺失: ${JSON.stringify(w)}`);return}s(k),l(E),await C(k),r("waiting")}catch(f){r("error"),u(String((f==null?void 0:f.message)??f))}},b=()=>{m()};return v.useEffect(()=>(m(),x),[]),v.useEffect(()=>(a&&p(),x),[a]),i.jsx(tt,{isOpen:!0,onClose:e,title:`扫码绑定 · ${t.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-1",children:[i.jsx("span",{className:"text-2xl",children:"🎉"}),i.jsx("span",{className:"text-sm",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:b,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:c||"未知错误"}),i.jsx("button",{onClick:b,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"?"二维码已失效":"")]}),n&&o==="waiting"&&i.jsxs("button",{onClick:()=>window.open(n,"_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 Xt(){const{load:t,loading:e,qrChannel:o,closeQr:r}=de();return v.useEffect(()=>{t()},[]),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:()=>t(),title:"刷新",className:"p-2 rounded-lg text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors",children:i.jsx(et,{className:`w-4 h-4 ${e?"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(nt,{})}),i.jsx("div",{className:"flex-1 min-w-0",children:i.jsx(rt,{})})]}),o&&i.jsx(Qt,{channel:o,onClose:r})]})}export{Xt as ChannelConfigView};
@@ -1,3 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-B-DFEdP3.js","assets/markdown-CIsUyqRd.js","assets/icons-CjYP2PII.js","assets/react-vendor-DuqM3ddv.js","assets/state-BCeK45RP.js","assets/index-D2PsJB4J.css"])))=>i.map(i=>d[i]);
2
- import{a as j,_ as L}from"./index-B-DFEdP3.js";import{j as e}from"./markdown-CIsUyqRd.js";import{r as N,af as z,ag as I,ah as M,$ as U,X as _,ai as $,h as Y,i as G,aj as J,a7 as B,a8 as W,p as V,ab as q,D as X,P as K}from"./icons-CjYP2PII.js";import{c as Q}from"./state-BCeK45RP.js";import"./react-vendor-DuqM3ddv.js";const P=Q((l,o)=>({rules:[],stats:null,events:[],agents:[],loading:!1,error:null,fieldErrors:null,formOpen:!1,editingRule:null,dryRunResult:null,loadRules:async()=>{const s=await j.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 j.hooks.stats();s.success&&s.data&&l({stats:s.data})},loadEvents:async()=>{const s=await j.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 j.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 j.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 m=JSON.parse(r.error);m.fieldErrors&&l({fieldErrors:m.fieldErrors})}catch{}}return!1},updateRule:async(s,r)=>{l({fieldErrors:null});const m=await j.hooks.update(s,r);return m.success?(await o().loadRules(),l({formOpen:!1,editingRule:null}),!0):(l({error:m.error||"Update failed"}),!1)},deleteRule:async s=>{const r=await j.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 j.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 j.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 j.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 j.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})})),Z={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"},ee={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 te({rules:l,onEdit:o}){const{toggleRule:s,deleteRule:r,batchDelete:m,batchToggle:v}=P(),[d,h]=N.useState(new Set),[T,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 i=new Set(d);i.has(t)?i.delete(t):i.add(t),h(i),k(i.size===y.length)},f=()=>{T?(h(new Set),k(!1)):(h(new Set(y.map(t=>t.name))),k(!0))},x=()=>{d.size!==0&&confirm(`确认删除 ${d.size} 条规则?`)&&(m(Array.from(d)),h(new Set),k(!1))},p=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:()=>p(!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:()=>p(!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:x,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:f,children:T?e.jsx(z,{size:14}):e.jsx(I,{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(z,{size:14,className:"text-accent-blue"}):e.jsx(I,{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(i=>e.jsx("span",{className:"rounded bg-dark-hover px-1.5 py-0.5 text-xs text-dark-text",children:i},i)),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 ${ee[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 ${Z[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(M,{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(U,{size:14})})]})})]},t.name))})]})})]})}const ae={name:"",description:"",events:[],implementationType:"SHELL",command:"",url:"",promptTemplate:"",agentName:"",priority:"USER",tools:[],matcherToolNamePattern:"",matcherFromState:"",matcherToState:"",timeoutMs:3e4,enabled:!0,failOpen:!0,scope:"project"},se=[{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:"启动只读子代理做深度调查"}],re=[{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 le({events:l,agents:o}){const{editingRule:s,fieldErrors:r,dryRunResult:m,createRule:v,updateRule:d,closeForm:h,dryRun:T,setDryRunResult:k,clearFieldErrors:y}=P(),S=Array.isArray(l)?l:[],f=Array.isArray(o)?o:[],[x,p]=N.useState(0),[t,i]=N.useState(ae),[w,C]=N.useState("");N.useEffect(()=>{var a,n,c;s&&i({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 u=(a,n)=>{i(c=>({...c,[a]:n})),y()},O=a=>{i(n=>({...n,events:n.events.includes(a)?n.events.filter(c=>c!==a):[...n.events,a]}))},A=a=>{const n=a.every(c=>t.events.includes(c));i(n?c=>({...c,events:c.events.filter(R=>!a.includes(R))}):c=>({...c,events:[...new Set([...c.events,...a])]}))},E=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)},D=async()=>{k(null);const a={};t.matcherToolNamePattern&&(a.toolNamePattern=t.matcherToolNamePattern),await T({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:""})},F=w?S.map(a=>({...a,events:Array.isArray(a.events)?a.events.filter(n=>n.name.toLowerCase().includes(w.toLowerCase())||n.summary.includes(w)):[]})).filter(a=>a.events.length>0):S,H=[{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(_,{size:18})})]}),e.jsx("div",{className:"flex flex-shrink-0 border-b border-dark-border",children:H.map((a,n)=>{const c=n===x,R=n<x;return e.jsxs("button",{onClick:()=>p(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))}),x===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=>u("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=>u("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=>u("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:w,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:F.map(a=>e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>A(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:()=>O(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))})]})]}),x===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:se.map(a=>{const n=t.implementationType===a.value;return e.jsxs("button",{onClick:()=>u("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=>u("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=>u("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=>u("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=>u("agentName",a.target.value),className:b(r==null?void 0:r.agentName),children:[e.jsx("option",{value:"",children:"选择 Agent..."}),f.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),不会修改文件"})]})]}),x===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=>u("priority",a.target.value),className:b(),children:re.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=>u("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=>u("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=>u("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=>u("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=>u("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=>u("matcherToState",a.target.value),className:b()})]})]}),m&&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:m.decision==="ALLOW"?"text-accent-green":m.decision==="DENY"?"text-accent-red":"text-accent-yellow",children:m.decision})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"原因: "}),e.jsx("span",{className:"text-dark-text",children:m.reason})]}),m.contextOutput&&e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"输出: "}),e.jsx("span",{className:"text-dark-text",children:m.contextOutput})]})]})]}),e.jsxs("button",{onClick:D,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:x>0&&e.jsxs("button",{onClick:()=>p(x-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:"取消"}),x<2?e.jsxs("button",{onClick:()=>p(x+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:E,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 ne({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:B,iconWrap:"bg-accent-green/15 text-accent-green"},{label:"已禁用",value:l.disabledCount,icon:W,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:m,error:v,formOpen:d,loadAll:h,openForm:T,clearError:k}=P();N.useEffect(()=>{h()},[]);const y=N.useCallback(async()=>{const{api:f}=await L(async()=>{const{api:p}=await import("./index-B-DFEdP3.js").then(t=>t.v);return{api:p}},__vite__mapDeps([0,1,2,3,4,5])),x=await f.hooks.export();if(x.success&&x.data){const p=new Blob([JSON.stringify(x.data,null,2)],{type:"application/json"}),t=URL.createObjectURL(p),i=document.createElement("a");i.href=t,i.download="hooks-export.json",i.click(),URL.revokeObjectURL(t)}},[]),S=N.useCallback(()=>{const f=document.createElement("input");f.type="file",f.accept=".json",f.onchange=async x=>{var i;const p=(i=x.target.files)==null?void 0:i[0];if(!p)return;const t=await p.text();try{const w=JSON.parse(t),{api:C}=await L(async()=>{const{api:A}=await import("./index-B-DFEdP3.js").then(E=>E.v);return{api:A}},__vite__mapDeps([0,1,2,3,4,5])),u=confirm(`合并到现有配置吗?
3
- "确定"=合并 / "取消"=替换`)?"merge":"replace";(await C.hooks.import({...w,mergeMode:u})).success&&h()}catch(w){console.error("Import failed:",w)}},f.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(V,{size:16,className:m?"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(X,{size:14}),"导出"]}),e.jsxs("button",{onClick:()=>T(),className:"inline-flex items-center gap-1.5 rounded-lg bg-accent-blue px-3 py-2 text-sm text-white transition-colors hover:bg-accent-blue/90",children:[e.jsx(K,{size:14}),"新增规则"]})]})]}),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(_,{size:16})})]}),e.jsx(ne,{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," 条"]})]}),m&&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(te,{rules:l,onEdit:f=>T(f)})})]})]}),d&&e.jsx(le,{events:s,agents:r})]})}export{xe as HookConfigView};
@@ -1 +0,0 @@
1
- import{j as t}from"./markdown-CIsUyqRd.js";import{r as a,p as ae,C as Ye,P as Pe,_ as Qe,w as re,$ as Te,a0 as Je,a1 as Xe,Q as Ze,N as et,a2 as tt,a3 as st,D as at,y as rt,a4 as Se,o as lt,a5 as nt}from"./icons-CjYP2PII.js";import"./Toast-DJAVHqFo.js";import{a as x,t as C,M as Ie}from"./index-B-DFEdP3.js";import"./react-vendor-DuqM3ddv.js";import"./state-BCeK45RP.js";function ot(){const[f,y]=a.useState([]),[k,h]=a.useState("1.0"),[L,d]=a.useState(!0),[I,q]=a.useState(!0),[H,K]=a.useState(null),j=a.useCallback(async()=>{q(!0),K(null);try{const g=await x.providers.presets();g.success&&g.data?(y(Array.isArray(g.data.providers)?g.data.providers:[]),h(g.data.version||"1.0"),d(g.data.customSupported!==!1)):K(g.error||"获取 Provider 列表失败")}catch(g){K(g instanceof Error?g.message:"未知错误")}finally{q(!1)}},[]);return a.useEffect(()=>{j()},[j]),{presets:f,loading:I,error:H,version:k,customSupported:L,reload:j}}const V={provider:"",modelId:"",modelName:"",baseUrl:"",apiKeys:"",apiType:"openai-completions",temperature:1,maxTokens:32768,contextWindow:1e6},ct={providerKey:"",apiKey:"",modelIds:"",baseUrl:"",apiType:"openai-completions",setDefault:!1};function mt(){var Ne,we;const{presets:f,loading:y,reload:k}=ot(),[h,L]=a.useState([]),[d,I]=a.useState(null),[q,H]=a.useState(!0),[K,j]=a.useState(null),[g,ne]=a.useState(null),[Me,M]=a.useState(!1),[P,W]=a.useState(null),[n,b]=a.useState(V),[oe,ce]=a.useState(!1),[de,T]=a.useState(null),[o,De]=a.useState(null),[Ae,D]=a.useState(!1),[ie,O]=a.useState("select"),[N,A]=a.useState(null),[i,w]=a.useState(ct),[ue,xe]=a.useState(!1),[pe,S]=a.useState(null),[be,X]=a.useState(!1),[Z,me]=a.useState(!1),[he,ge]=a.useState({}),[ee,fe]=a.useState(!1),[te,G]=a.useState([]),[$,E]=a.useState(new Set),[ve,U]=a.useState(null),[Y,se]=a.useState(""),B=a.useCallback(async()=>{try{const e=await x.config.provider.get();e.success&&e.data&&De(e.data)}catch{}},[]),m=a.useCallback(async()=>{H(!0),j(null);try{const[e,s]=await Promise.all([x.models.list(),x.system.status()]);if(await B(),e.success&&e.data&&Array.isArray(e.data.models)&&L(e.data.models),s.success&&s.data){const r=s.data.models||{total:0,online:0,offline:0};I({overallStatus:r.offline===0?"healthy":r.online>0?"degraded":"unhealthy",healthRate:r.total>0?r.online/r.total:0,healthyInstances:r.online,totalInstances:r.total,totalRequests:0})}}catch{j("加载模型失败")}finally{H(!1)}},[B]);a.useEffect(()=>{m()},[m]);const z=a.useCallback(e=>`${e.provider}:${e.id}`,[]),$e=a.useCallback(e=>he[z(e)]||{inputTokens:0,outputTokens:0},[z,he]),ye=a.useCallback((e,s,r)=>{const l=z(e);ge(u=>{var c,p;return{...u,[l]:{inputTokens:s==="inputTokens"?r:((c=u[l])==null?void 0:c.inputTokens)||0,outputTokens:s==="outputTokens"?r:((p=u[l])==null?void 0:p.outputTokens)||0}}})},[z]),Ee=a.useCallback(e=>{ge(s=>({...s,[z(e)]:{inputTokens:0,outputTokens:0}}))},[z]),_=a.useMemo(()=>{const e=[...f];return e.find(s=>s.key==="custom")||e.push({key:"custom",name:"Custom",baseUrl:"",apiType:"openai-completions",defaultModel:"",isCustom:!0}),e},[f]),ke=a.useCallback(e=>{var c,p;const s=(c=o==null?void 0:o.providers)==null?void 0:c[e.key],r=h.filter(R=>R.provider===e.key).map(R=>R.id),l=((p=e.models)==null?void 0:p.slice(0,3).join(", "))||e.defaultModel,u=r.length>0?r.join(", "):l;A(e.key),w({providerKey:e.key,apiKey:"",modelIds:u,baseUrl:(s==null?void 0:s.baseUrl)||e.baseUrl,apiType:(s==null?void 0:s.apiType)||e.apiType,setDefault:(o==null?void 0:o.defaultProvider)!==e.key}),O("form"),D(!0),S(null),X(!1),G([]),E(new Set),U(null),se("")},[h,o]),je=a.useCallback(()=>{A("custom"),w({providerKey:"",apiKey:"",modelIds:"",baseUrl:"",apiType:"openai-completions",setDefault:!(o!=null&&o.configured)}),O("form"),D(!0),S(null),X(!1),G([]),E(new Set),U(null),se("")},[o]),Ue=a.useCallback(async()=>{var s;const e=i.baseUrl;if(!e){U("请先填写 Base URL");return}fe(!0),U(null),G([]),E(new Set);try{const r=i.apiKey.replace(/[^\x00-\xFF]/g,"");r!==i.apiKey&&C.warning("API Key 包含非法字符,已自动过滤");const l=await x.models.fetch(e,r);if(l.success&&((s=l.data)!=null&&s.models)){G(l.data.models);const u=new Set(i.modelIds.split(",").map(c=>c.trim()).filter(Boolean));E(u),C.success(`获取到 ${l.data.models.length} 个模型`)}else U(l.error||"获取模型列表失败,请检查 Base URL 和 API Key")}catch(r){U(r instanceof Error?r.message:"请求失败")}finally{fe(!1)}},[i.baseUrl,i.apiKey,i.modelIds]),ze=a.useCallback(e=>{E(s=>{const r=new Set(s);return r.has(e)?r.delete(e):r.add(e),r})},[]),Fe=a.useCallback(()=>{const e=Array.from($).join(", ");w(s=>({...s,modelIds:e}))},[$]),Re=async e=>{const s=h.find(c=>c.id===e);if(!s)return;const r=s.enabled!==!1,l=s.name||e,u=c=>r&&/default model/i.test(c);try{const c=await x.models.toggle(s.provider,e);if(c.success){await m();return}const p=c.error||"";u(p)?C.error(`“${l}” 是默认模型,无法直接禁用。请先在「Provider 配置」中更换默认模型,再进行禁用。`):C.error(p||"操作失败,请重试")}catch(c){const p=c instanceof Error?c.message:"";u(p)?C.error(`“${l}” 是默认模型,无法直接禁用。请先在「Provider 配置」中更换默认模型,再进行禁用。`):C.error(p||"操作失败,请重试")}},Le=async e=>{ne(e);try{await x.models.test(e),await m()}finally{ne(null)}},We=async(e,s)=>{if(confirm(`确定要删除模型 "${s}" 吗?此操作不可撤销。`))try{(await x.models.delete(e,s)).success&&await m()}catch{}},Oe=e=>{W({provider:e.provider,modelId:e.id}),b({provider:e.provider,modelId:e.id,modelName:e.name,baseUrl:"",apiKeys:"",apiType:e.apiType||"openai-completions",temperature:e.temperature??1,maxTokens:e.maxTokens??32768,contextWindow:e.contextWindow??1e6}),T(null),M(!0)},Ge=async()=>{var Ce;const e=_.find(v=>v.key===N)||null,s=N==="custom"?i.providerKey.trim():(e==null?void 0:e.key)||"";if(!s){S("请先输入 Provider 名称");return}if(!i.apiKey.trim()){S("请输入 API Key");return}const r=e||{baseUrl:"",apiType:"openai-completions",defaultModel:""},l=(Ce=o==null?void 0:o.providers)==null?void 0:Ce[s],c=i.apiKey.trim()||(l!=null&&l.hasApiKey?void 0:""),p=c!==void 0&&c!==""?c.replace(/[^\x00-\xFF]/g,""):c,R={provider:s,baseUrl:i.baseUrl||r.baseUrl,apiType:i.apiType||r.apiType,apiKey:p,models:(i.modelIds||r.defaultModel||"").split(",").map((v,He)=>({id:v.trim(),name:v.trim(),enabled:!0,priority:10+He})).filter(v=>v.id.length>0)};(!(o!=null&&o.configured)||i.setDefault)&&(R.setDefault=!0),xe(!0),S(null);try{const v=await x.config.provider.save(R);v.success?(D(!1),O("select"),A(null),await B(),await m()):S(v.error||"保存失败")}catch(v){S(v instanceof Error?v.message:"未知错误")}finally{xe(!1)}},Be=async e=>{if(confirm(`确定要移除 "${e}" 的配置吗?这将删除其 API Key 和模型。`))try{await x.config.provider.delete(e),await B(),await m()}catch{}},_e=async()=>{if(!n.provider.trim()||!n.modelId.trim()){T("提供商名称和模型 ID 不能为空");return}ce(!0),T(null);try{if(P){const e={name:n.modelName.trim()||n.modelId.trim(),temperature:n.temperature,maxTokens:n.maxTokens,contextWindow:n.contextWindow},s=await x.models.update(P.provider,P.modelId,{model:e});s.success?(M(!1),W(null),b(V),await m()):T(s.error||"保存失败")}else{const e={id:n.modelId.trim(),name:n.modelName.trim()||n.modelId.trim(),temperature:n.temperature,maxTokens:n.maxTokens,contextWindow:n.contextWindow,enabled:!0,apiType:n.apiType};if(n.baseUrl.trim()&&(e.baseUrl=n.baseUrl.trim()),n.apiKeys.trim()){const l=n.apiKeys.split(",").map(u=>u.trim()).filter(Boolean).map(u=>u.replace(/[^\x00-\xFF]/g,""));e.apiKeys=l,e.apiKey=l[0]}const s=await x.models.create({provider:n.provider.trim(),model:e});s.success?(M(!1),b(V),await m()):T(s.error||"保存失败")}}catch(e){T(e instanceof Error?e.message:"未知错误")}finally{ce(!1)}},Ve=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"}},qe=e=>{switch(e){case"online":return t.jsx(nt,{size:14});case"offline":return t.jsx(Se,{size:14});case"error":return t.jsx(lt,{size:14});default:return t.jsx(Se,{size:14})}},F=a.useMemo(()=>_.find(e=>e.key===N)||null,[N,_]);return q?t.jsx("div",{className:"flex h-64 items-center justify-center text-dark-muted",children:"加载中..."}):K?t.jsx("div",{className:"flex h-64 items-center justify-center text-accent-red",children:K}):t.jsxs("div",{className:"p-6 space-y-6",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 x.providers.refresh(),C.success("Provider 列表已刷新"),me(!0),await k(),setTimeout(()=>{k()},3e3)}catch{C.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(ae,{size:12}),"刷新列表"]}),t.jsxs("button",{onClick:()=>me(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:[Z?t.jsx(Ye,{size:12}):t.jsx(Pe,{size:12}),Z?"收起":"新增 Provider"]})]})]}),Z&&t.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3",children:y?t.jsxs("div",{className:"col-span-full flex items-center justify-center py-4 text-dark-muted text-sm",children:[t.jsx(Qe,{size:14,className:"mr-2 animate-spin"}),"加载 Provider 列表..."]}):_.map(e=>{var u,c;const s=(u=o==null?void 0:o.providers)==null?void 0:u[e.key],r=s==null?void 0:s.hasApiKey,l=(o==null?void 0:o.defaultProvider)===e.key;return t.jsxs("div",{className:`text-left p-3 rounded-lg border transition-colors relative ${r?"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"?je():ke(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}),r&&t.jsx(re,{size:14,className:"text-accent-green"})]}),t.jsxs("div",{className:"text-[10px] text-dark-muted space-y-0.5",children:[t.jsx("div",{children:e.baseUrl||"自定义地址"}),t.jsx("div",{children:e.defaultModel||"无默认模型"}),t.jsxs("div",{children:[s?`${s.modelCount} 已配置`:`${((c=e.models)==null?void 0:c.length)||0} 可用`,e.models&&e.models.length>0&&!s&&t.jsx("span",{className:"text-accent-blue",children:" ✓"})]})]}),l&&t.jsx("div",{className:"mt-1 text-[10px] text-accent-blue",children:"默认 Provider"})]}),r&&t.jsx("button",{onClick:p=>{p.stopPropagation(),Be(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(Te,{size:13})})]})})})]}),d&&t.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[t.jsx(Q,{title:"总体状态",value:d.totalInstances===0?"未配置":d.overallStatus==="healthy"?"健康":d.overallStatus==="degraded"?"降级":"异常",color:d.totalInstances===0?"blue":d.overallStatus==="healthy"?"green":d.overallStatus==="degraded"?"yellow":"red"}),t.jsx(Q,{title:"健康率",value:d.totalInstances===0?"N/A":`${(d.healthRate*100).toFixed(0)}%`,color:d.totalInstances===0?"blue":d.healthRate>.8?"green":d.healthRate>.5?"yellow":"red"}),t.jsx(Q,{title:"在线实例",value:d.totalInstances===0?"无":`${d.healthyInstances}/${d.totalInstances}`,color:d.healthyInstances>0?"green":"red"}),t.jsx(Q,{title:"总请求数",value:d.totalRequests>0?d.totalRequests.toLocaleString():"0",color:"blue"})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("h3",{className:"text-sm font-medium",children:"已配置模型"}),t.jsxs("button",{onClick:()=>{W(null),b(V),T(null),M(!0)},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:[t.jsx(Pe,{size:12}),"添加模型"]})]}),t.jsxs("div",{className:"space-y-2 max-h-[480px] overflow-y-auto custom-scrollbar pr-1",children:[h.map(e=>{const s=$e(e),r=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:Ve(e.status),children:qe(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(J,{label:"负载",value:`${e.load}/${e.maxLoad}`}),t.jsx(J,{label:"Token",value:`${e.tokens}/${e.maxTokens}`}),t.jsx(J,{label:"输入价格",value:`$${e.price.input}/1K`}),t.jsx(J,{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(Ke,{label:"输入 token",value:s.inputTokens,onChange:l=>ye(e,"inputTokens",l)}),t.jsx(Ke,{label:"输出 token",value:s.outputTokens,onChange:l=>ye(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:r.toLocaleString()})]}),t.jsxs("button",{onClick:()=>Ee(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(Je,{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 x.models.setDefaults({global:`${e.provider}:${e.id}`}),await m()}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 x.models.setDefaults({plan:`${e.provider}:${e.id}`}),await m()}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 x.models.setDefaults({act:`${e.provider}:${e.id}`}),await m()}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 x.models.setDefaults({goal:`${e.provider}:${e.id}`}),await m()}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:()=>Oe(e),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:"编辑模型",children:t.jsx(Xe,{size:13})}),t.jsx("button",{onClick:()=>We(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(Te,{size:13})}),t.jsx("button",{onClick:()=>Le(e.id),disabled:g===e.id,className:"p-1.5 rounded hover:bg-dark-hover disabled:opacity-50",title:"刷新",children:t.jsx(ae,{size:13,className:g===e.id?"animate-spin":""})}),t.jsx("button",{onClick:()=>Re(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"?"禁用":"启用"})]})]})},e.id)}),h.length===0&&t.jsxs("div",{className:"text-center text-dark-muted py-6",children:[t.jsx(Ze,{size:36,className:"mx-auto mb-2 opacity-40"}),t.jsx("p",{className:"text-sm",children:"暂无模型,请先在上方配置 Provider"})]})]})]}),t.jsx(Ie,{isOpen:Ae,onClose:()=>{D(!1),O("select"),A(null)},title:ie==="select"?"选择 Provider":(F==null?void 0:F.name)||"Provider 配置",size:"xl",children:ie==="select"?t.jsx("div",{className:"space-y-4",children:t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[_.filter(e=>e.key!=="custom").map(e=>t.jsxs("button",{onClick:()=>ke(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(re,{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:je,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(et,{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:[N==="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.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"API Key *"}),t.jsxs("div",{className:"relative",children:[t.jsx("input",{type:be?"text":"password",value:i.apiKey,onChange:e=>w(s=>({...s,apiKey: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",placeholder:"输入 API Key"}),t.jsx("button",{onClick:()=>X(e=>!e),className:"absolute right-2 top-2 text-dark-muted hover:text-white",children:be?t.jsx(tt,{size:14}):t.jsx(st,{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=>w(s=>({...s,modelIds:e.target.value})),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:(F==null?void 0:F.defaultModel)||"gpt-4o, deepseek-chat"}),t.jsxs("button",{onClick:Ue,disabled:ee||!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:[ee?t.jsx(ae,{size:13,className:"animate-spin"}):t.jsx(at,{size:13}),ee?"获取中...":"获取模型列表"]})]}),ve&&t.jsx("div",{className:"mt-1 text-xs text-accent-red",children:ve}),te.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:te.length})," 个模型, 已选 ",t.jsx("strong",{className:"text-accent-blue",children:$.size})," 个"]}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx("button",{onClick:Fe,className:"px-2 py-0.5 text-[10px] bg-accent-blue text-white rounded hover:opacity-90",children:"应用选中"}),t.jsx("button",{onClick:()=>{G([]),E(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(rt,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),t.jsx("input",{value:Y,onChange:e=>se(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:te.filter(e=>!Y||e.id.toLowerCase().includes(Y.toLowerCase())||e.name.toLowerCase().includes(Y.toLowerCase())).map(e=>t.jsxs("label",{className:`flex items-center gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors ${$.has(e.id)?"bg-accent-blue/20 text-accent-blue border border-accent-blue/30":"hover:bg-dark-hover border border-transparent"}`,children:[t.jsx("input",{type:"checkbox",checked:$.has(e.id),onChange:()=>ze(e.id),className:"sr-only"}),$.has(e.id)?t.jsx(re,{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.jsx("div",{className:"grid grid-cols-2 gap-2",children:["openai-completions","anthropic-messages"].map(e=>t.jsxs("label",{className:`flex items-center justify-center gap-1.5 px-3 py-2 rounded text-sm cursor-pointer border transition-colors ${i.apiType===e?"bg-accent-blue/20 border-accent-blue text-accent-blue":"bg-dark-bg border-dark-border text-dark-muted hover:border-dark-hover"}`,children:[t.jsx("input",{type:"radio",name:"providerApiType",value:e,checked:i.apiType===e,onChange:s=>w(r=>({...r,apiType:s.target.value})),className:"sr-only"}),e==="openai-completions"?"OpenAI Compatible":"Anthropic Messages"]},e))})]}),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"})]}),pe&&t.jsx("div",{className:"text-sm text-accent-red",children:pe}),t.jsxs("div",{className:"flex justify-between gap-2 pt-2",children:[t.jsx("div",{children:N&&N!=="custom"&&((we=(Ne=o==null?void 0:o.providers)==null?void 0:Ne[N])==null?void 0:we.hasApiKey)&&t.jsx("button",{onClick:async()=>{if(confirm(`确定要删除 "${N}" 的配置吗?`))try{await x.config.provider.delete(N),D(!1),A(null),await B(),await m()}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:()=>{O("select"),A(null),D(!1)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:"取消"}),t.jsx("button",{onClick:Ge,disabled:ue,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:ue?"保存中...":"保存"})]})]})}),t.jsx(Ie,{isOpen:Me,onClose:()=>{M(!1),W(null)},title:P?"编辑模型":"添加模型",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=>b(s=>({...s,provider:e.target.value})),disabled:!!P,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=>b(s=>({...s,modelId:e.target.value})),disabled:!!P,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=>b(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",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[t.jsx(le,{label:"温度",value:n.temperature,step:"0.1",min:"0",max:"2",onChange:e=>b(s=>({...s,temperature:e}))}),t.jsx(le,{label:"最大 Token",value:n.maxTokens,onChange:e=>b(s=>({...s,maxTokens:e}))}),t.jsx(le,{label:"上下文窗",value:n.contextWindow,onChange:e=>b(s=>({...s,contextWindow:e}))})]}),!P&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"API 地址"}),t.jsx("input",{value:n.baseUrl,onChange:e=>b(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 Key(多个用逗号分隔)"}),t.jsx("input",{value:n.apiKeys,onChange:e=>b(s=>({...s,apiKeys: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:"sk-xxx, sk-yyy"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"API 类型"}),t.jsx("div",{className:"grid grid-cols-2 gap-2",children:["openai-completions","anthropic-messages"].map(e=>t.jsxs("label",{className:`flex items-center justify-center gap-1.5 px-3 py-2 rounded text-sm cursor-pointer border transition-colors ${n.apiType===e?"bg-accent-blue/20 border-accent-blue text-accent-blue":"bg-dark-bg border-dark-border text-dark-muted hover:border-dark-hover"}`,children:[t.jsx("input",{type:"radio",name:"addModelApiType",value:e,checked:n.apiType===e,onChange:s=>b(r=>({...r,apiType:s.target.value})),className:"sr-only"}),e==="openai-completions"?"OpenAI Compatible":"Anthropic Messages"]},e))})]})]}),de&&t.jsx("div",{className:"text-sm text-accent-red bg-accent-red/10 p-2 rounded",children:de}),t.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[t.jsx("button",{onClick:()=>{M(!1),W(null),b(V)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:"取消"}),t.jsx("button",{onClick:_e,disabled:oe,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:oe?"保存中...":"保存"})]})]})})]})}function Q({title:f,value:y,color:k}){const h={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:`${h[k]} rounded-lg p-3`,children:[t.jsx("div",{className:"text-xs opacity-70",children:f}),t.jsx("div",{className:"text-xl font-semibold",children:y})]})}function J({label:f,value:y}){return t.jsxs("div",{children:[t.jsx("div",{className:"text-dark-muted",children:f}),t.jsx("div",{children:y})]})}function Ke({label:f,value:y,onChange:k}){return t.jsxs("div",{children:[t.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:f}),t.jsx("input",{type:"number",min:"0",value:y,onChange:h=>k(parseInt(h.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"})]})}function le({label:f,value:y,onChange:k,min:h,max:L,step:d}){return t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:f}),t.jsx("input",{type:"number",value:y,min:h,max:L,step:d,onChange:I=>k(d?parseFloat(I.target.value)||0:parseInt(I.target.value,10)||0),className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue"})]})}export{mt as ModelsView,mt as default};