@deepseekcode/cli 1.0.14 → 1.0.16

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 (43) hide show
  1. package/dist/cli.js +3751 -1062
  2. package/package.json +2 -2
  3. package/web/dist/assets/{AgentFlowView-CfSu-PAH.js → AgentFlowView-D-nPVDb9.js} +1 -1
  4. package/web/dist/assets/{AgentsView-0Gf3EdnC.js → AgentsView-DHNgV13S.js} +1 -1
  5. package/web/dist/assets/{AskQuestionModal-UE0P8HVH.js → AskQuestionModal-BKkh6JlF.js} +1 -1
  6. package/web/dist/assets/{AuditView-DzmxbLTN.js → AuditView-ZCIV7Q0I.js} +1 -1
  7. package/web/dist/assets/AutomationView-By6rBhla.js +1 -0
  8. package/web/dist/assets/ChannelConfigView-_cIgiA-O.js +8 -0
  9. package/web/dist/assets/ConnectorsView-BQQ_k_7I.js +1 -0
  10. package/web/dist/assets/{FileTreeView-Cc3rRokq.js → FileTreeView-DKUEkVqn.js} +1 -1
  11. package/web/dist/assets/HookApprovalModal-DC_q-If8.js +1 -0
  12. package/web/dist/assets/HookApprovalPreview-C8fU_Umi.js +3 -0
  13. package/web/dist/assets/HookConfigView-DbkxVuAs.js +3 -0
  14. package/web/dist/assets/{InboxView-DkJjMxlg.js → InboxView-B3ddpq78.js} +1 -1
  15. package/web/dist/assets/ModelsView-B2N4jMxM.js +1 -0
  16. package/web/dist/assets/SessionGrid-CnK6naC_.js +23 -0
  17. package/web/dist/assets/{SettingsPanel-BVIE5AdZ.js → SettingsPanel-czOfv9mx.js} +3 -3
  18. package/web/dist/assets/SkillsView-BwJowYXS.js +1 -0
  19. package/web/dist/assets/TemplatesTab-BB-6z4z4.js +1 -0
  20. package/web/dist/assets/TerminalView-D9e8fyOS.js +3 -0
  21. package/web/dist/assets/ToolsView-CQ3hybgP.js +1 -0
  22. package/web/dist/assets/{icons-CjRO1znb.js → icons-B5yCkBjC.js} +122 -102
  23. package/web/dist/assets/index-DVZ3Ws5S.css +1 -0
  24. package/web/dist/assets/index-YAnKQ1Q6.js +20 -0
  25. package/web/dist/assets/{markdown-hmVtvQNZ.js → markdown-D0iUI0Yw.js} +1 -1
  26. package/web/dist/assets/panels-DOT_5rsR.js +1 -0
  27. package/web/dist/assets/{react-vendor-Dp4P972X.js → react-vendor-Bxu3r3ox.js} +1 -1
  28. package/web/dist/assets/{state-C_jK7HTi.js → state-C80Yzgl0.js} +1 -1
  29. package/web/dist/index.html +6 -6
  30. package/web/dist/assets/AutomationView-zrlVDQLZ.js +0 -1
  31. package/web/dist/assets/ChannelConfigView-3CHuvU_y.js +0 -8
  32. package/web/dist/assets/HookApprovalModal-DVpdbNbM.js +0 -1
  33. package/web/dist/assets/HookConfigView-C3-HYLVR.js +0 -3
  34. package/web/dist/assets/ModelsView-DERNLd5f.js +0 -1
  35. package/web/dist/assets/SessionGrid-BD_2wvuD.js +0 -21
  36. package/web/dist/assets/SkillsView-DU81ko6V.js +0 -1
  37. package/web/dist/assets/TerminalView-DiRF3hQA.js +0 -3
  38. package/web/dist/assets/Toast-Bmm1ZZzF.js +0 -1
  39. package/web/dist/assets/ToolsView-Bo87RtdV.js +0 -1
  40. package/web/dist/assets/hookRisk-Ds8oxbfO.js +0 -1
  41. package/web/dist/assets/index-CAwHhr7A.js +0 -20
  42. package/web/dist/assets/index-Czlzypr3.css +0 -1
  43. package/web/dist/assets/panels-C0Mxu2Md.js +0 -1
@@ -1,4 +1,4 @@
1
- import{r as Pr,c as Fe,g as An}from"./icons-CjRO1znb.js";var Nt={exports:{}},Qe={};/**
1
+ import{r as Pr,c as Fe,g as An}from"./icons-B5yCkBjC.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-B5yCkBjC.js";
@@ -1,4 +1,4 @@
1
- import{r as _a}from"./icons-CjRO1znb.js";var Co={exports:{}},ve={},xo={exports:{}},_o={};/**
1
+ import{r as _a}from"./icons-B5yCkBjC.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 x,W as R}from"./icons-CjRO1znb.js";var w={exports:{}},D={};/**
1
+ import{r as _,g as x,W as R}from"./icons-B5yCkBjC.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-CAwHhr7A.js"></script>
16
- <link rel="modulepreload" crossorigin href="/assets/icons-CjRO1znb.js">
17
- <link rel="modulepreload" crossorigin href="/assets/markdown-hmVtvQNZ.js">
18
- <link rel="modulepreload" crossorigin href="/assets/react-vendor-Dp4P972X.js">
19
- <link rel="modulepreload" crossorigin href="/assets/state-C_jK7HTi.js">
20
- <link rel="stylesheet" crossorigin href="/assets/index-Czlzypr3.css">
15
+ <script type="module" crossorigin src="/assets/index-YAnKQ1Q6.js"></script>
16
+ <link rel="modulepreload" crossorigin href="/assets/icons-B5yCkBjC.js">
17
+ <link rel="modulepreload" crossorigin href="/assets/markdown-D0iUI0Yw.js">
18
+ <link rel="modulepreload" crossorigin href="/assets/react-vendor-Bxu3r3ox.js">
19
+ <link rel="modulepreload" crossorigin href="/assets/state-C80Yzgl0.js">
20
+ <link rel="stylesheet" crossorigin href="/assets/index-DVZ3Ws5S.css">
21
21
  </head>
22
22
  <body>
23
23
  <div id="root"></div>
@@ -1 +0,0 @@
1
- import{j as e}from"./markdown-hmVtvQNZ.js";import{r as a,e as k,R as $,P as I,A as T,aM as D,ak as L,$ as O,ap as J,X as U}from"./icons-CjRO1znb.js";import{x as B}from"./index-CAwHhr7A.js";import"./react-vendor-Dp4P972X.js";import"./state-C_jK7HTi.js";function F(){const{automations:r,runsByAutomation:c,fetchAutomations:n,createAutomation:v,deleteAutomation:N,toggleAutomation:y,runAutomation:w,fetchRuns:C,error:l}=B(),[A,i]=a.useState(!1),[x,S]=a.useState(null),[m,u]=a.useState(""),[p,b]=a.useState(""),[o,h]=a.useState("0 9 * * *"),[g,f]=a.useState("");a.useEffect(()=>{n()},[n]);const z=async t=>{const s=g.trim();if(!s)return;const[d,...R]=s.split(/\s+/),j=R.join(" ");d&&j&&(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tool:d,target:j})})).ok&&(f(""),await n())},P=async(t,s)=>{(await fetch(`/api/automations/${encodeURIComponent(t)}/permissions`,{method:"DELETE",headers:{"content-type":"application/json"},body:JSON.stringify({entry:s})})).ok&&await n()},E=async t=>{const s=x===t?null:t;S(s),s&&await C(t)};return e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(k,{size:20,className:"text-accent-blue"}),"定时自动化",e.jsxs("span",{className:"text-xs text-dark-muted font-normal",children:["(",r.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>void n(),className:"p-2 rounded-lg hover:bg-dark-hover text-dark-muted",title:"刷新",children:e.jsx($,{size:16})}),e.jsxs("button",{onClick:()=>i(t=>!t),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-blue/20 text-accent-blue hover:bg-accent-blue/30 text-sm font-medium",children:[e.jsx(I,{size:16})," 新建"]})]})]}),l&&e.jsxs("div",{className:"mb-3 p-3 rounded-lg bg-accent-red/10 text-accent-red text-sm flex items-center gap-2",children:[e.jsx(T,{size:16})," ",l]}),A&&e.jsxs("div",{className:"mb-4 rounded-lg border border-dark-border bg-dark-surface p-4 space-y-3",children:[e.jsx("input",{value:m,onChange:t=>u(t.target.value),placeholder:"名称(如:每早 9 点汇总 Git 状态)",className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),e.jsx("textarea",{value:p,onChange:t=>b(t.target.value),placeholder:"指令(agent 每次触发时执行的内容)",rows:3,className:"w-full px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue resize-none"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:o,onChange:t=>h(t.target.value),placeholder:"cron(5 段,如 0 9 * * *)",className:"flex-1 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border text-sm focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:async()=>{await v({name:m,instructions:p,schedule:{kind:"cron",cron:o}})&&(u(""),b(""),i(!1))},className:"px-4 py-2 rounded-lg bg-accent-blue text-white text-sm font-medium hover:bg-accent-blue/80",children:"创建"})]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:[["0 9 * * *","每天 9:00"],["0 9 * * 1-5","工作日 9:00"],["*/30 * * * *","每 30 分钟"]].map(([t,s])=>e.jsxs("button",{onClick:()=>h(t),className:`px-2 py-1 rounded text-xs ${o===t?"bg-accent-blue/20 text-accent-blue":"bg-dark-hover text-dark-muted hover:text-dark-text"}`,children:[s," (",t,")"]},t))})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2",children:[r.length===0&&e.jsx("p",{className:"text-dark-muted text-center py-8",children:"还没有定时自动化。新建一个,让 agent 无人值守干活。"}),r.map(t=>e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface",children:[e.jsxs("div",{className:"flex items-center justify-between p-3",children:[e.jsxs("button",{onClick:()=>void E(t.id),className:"flex items-center gap-2 min-w-0 text-left",children:[e.jsx(k,{size:16,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"font-medium text-sm truncate",children:t.name}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded shrink-0 ${t.status==="enabled"?"bg-accent-green/20 text-accent-green":"bg-dark-hover text-dark-muted"}`,children:t.status})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("span",{className:"text-xs text-dark-muted hidden lg:inline mr-1",children:[t.schedule.kind==="cron"?t.schedule.cron:t.schedule.fireAt,t.nextRunAt?` · ${new Date(t.nextRunAt).toLocaleString()}`:""]}),e.jsx("button",{onClick:()=>void y(t.id,t.status!=="enabled"),className:"p-1.5 rounded-lg hover:bg-dark-hover text-dark-muted",title:t.status==="enabled"?"停用":"启用",children:e.jsx(D,{size:15})}),e.jsx("button",{onClick:()=>void w(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-green",title:"手动触发",children:e.jsx(L,{size:15})}),e.jsx("button",{onClick:()=>void N(t.id),className:"p-1.5 rounded-lg hover:bg-dark-hover text-accent-red",title:"删除",children:e.jsx(O,{size:15})})]})]}),x===t.id&&e.jsxs("div",{className:"px-3 pb-3 space-y-3 border-t border-dark-border pt-3",children:[e.jsx("p",{className:"text-xs text-dark-muted whitespace-pre-wrap",children:t.instructions}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-xs font-semibold text-dark-muted mb-1 flex items-center gap-1",children:[e.jsx(J,{size:12})," 运行历史"]}),(c[t.id]||[]).length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:"暂无运行记录"}),(c[t.id]||[]).slice(0,10).map(s=>e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded ${s.status==="ok"?"bg-accent-green/20 text-accent-green":s.status==="error"?"bg-accent-red/20 text-accent-red":"bg-accent-yellow/20 text-accent-yellow"}`,children:s.status}),e.jsx("span",{className:"text-dark-muted",children:new Date(s.startedAt).toLocaleString()}),e.jsxs("span",{className:"text-dark-muted truncate flex-1",children:["#",s.id.slice(0,8)," · ",s.trigger]})]},s.id))]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-dark-muted mb-1",children:"作用域放行(tool target)"}),t.permissions.length===0&&e.jsx("p",{className:"text-xs text-dark-muted",children:"无。写操作将停放进 Inbox 等待批准。"}),e.jsx("div",{className:"flex flex-wrap gap-1 mb-1",children:t.permissions.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded bg-accent-blue/10 text-accent-blue text-xs",children:[s,e.jsx("button",{onClick:()=>void P(t.id,s),className:"hover:text-accent-red",children:e.jsx(U,{size:12})})]},s))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:g,onChange:s=>f(s.target.value),placeholder:"如:write_file docs/report.md",className:"flex-1 px-2 py-1.5 rounded-lg bg-dark-bg border border-dark-border text-xs focus:outline-none focus:border-accent-blue"}),e.jsx("button",{onClick:()=>void z(t.id),className:"px-3 py-1.5 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-xs",children:"添加"})]})]})]})]},t.id))]})]})}export{F as AutomationView};
@@ -1,8 +0,0 @@
1
- import{j as i}from"./markdown-hmVtvQNZ.js";import{r as v,aO as Pe,a5 as Re,a4 as Le,aP as Xe,P as ee,aQ as ue,$ as _e,ad as et,R as tt}from"./icons-CjRO1znb.js";import{v as fe,M as nt,a as be,t as te}from"./index-CAwHhr7A.js";import"./react-vendor-Dp4P972X.js";import"./state-C_jK7HTi.js";const we=new Set(["mattermost","msteams","googlechat","irc","imessage","sms","nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser","clickclack","raft","qa-channel"]),ye={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"},Ne={wechat:"💬",feishu:"📘",dingtalk:"🔔",telegram:"✈️",discord:"🎮",slack:"💼",signal:"🔒",whatsapp:"📱",line:"🟢",qqbot:"🐧",matrix:"🧩",mattermost:"🏢",msteams:"📋",googlechat:"📧",irc:"💻",imessage:"✉️",sms:"📨"},Ce=[{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 rt(){const{channels:t,selectedType:e,selectType:o}=fe(),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:[Ce.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(ke,{label:ye[a]??a,icon:Ne[a]??"📡",isSelected:e===a,experimental:we.has(a),info:l,onClick:()=>o(a)},a)})]},n.label)}),(()=>{const n=Ce.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(ke,{label:ye[s]??s,icon:Ne[s]??"📡",isSelected:e===s,experimental:we.has(s),onClick:()=>o(s)},s))]})})()]})]})}function ke({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(Pe,{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(Re,{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(Le,{className:"w-3 h-3"}),"未连接"]}):i.jsx("span",{className:"text-[11px] text-dark-muted",children:"未配置"})})]})]})}const je=new Set(["mattermost","msteams","googlechat","irc","imessage","sms","nextcloud-talk","nostr","synology-chat","tlon","twitch","zalo","zalouser","clickclack","raft","qa-channel"]),Ee={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"},ve={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 st(){const{channels:t,selectedType:e,create:o,update:r,remove:n,toggle:s,error:a,clearError:l,openQr:c,load:u}=fe(),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(()=>{e==="wechat"&&d.length===0&&c(null)},[e,d.length,c]),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:ve[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:Ee[e]??e}),je.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(Pe,{className:"w-3 h-3"})," 实验性"]})]}),i.jsx("p",{className:"text-xs text-dark-muted mt-0.5",children:d.length>0?`${d.length} 个配置实例`:"尚未配置"}),je.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:ve[e]??"📡"}),i.jsxs("p",{className:"text-dark-text font-medium",children:["还没有配置 ",Ee[e]??e]}),i.jsx("p",{className:"text-sm text-dark-muted mt-1 mb-4",children:e==="wechat"?"点击下方按钮,用微信扫码即可自动完成绑定":"点击上方「新建实例」开始配置"}),e==="wechat"&&i.jsxs("button",{onClick:()=>c(null),className:"flex items-center gap-1.5 text-sm px-4 py-2 rounded-lg bg-green-600/15 hover:bg-green-600/25 text-green-400 border border-green-600/40 transition-colors mb-3",children:[i.jsx(ue,{className:"w-4 h-4"})," 扫码绑定"]}),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(Se,{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(Se,{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(ot,{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(Xe,{className:"w-12 h-12 mx-auto mb-3 text-dark-muted/40"}),i.jsx("p",{className:"text-dark-muted text-sm",children:"请从左侧选择一个频道类型"})]})})}function Se({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(Re,{className:"w-3 h-3"})," 已连接"]}):i.jsxs(i.Fragment,{children:[i.jsx(Le,{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(ue,{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(_e,{className:"w-3.5 h-3.5"})," 删除"]})]})]})}function ot({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(Te,{label:"频道名称",required:!0,children:i.jsx("input",{value:t.name,onChange:u=>e("name",u.target.value),placeholder:"例如:研发群机器人",className:$})}),i.jsxs(Te,{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(ue,{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(_e,{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(et,{className:"w-3.5 h-3.5"}),o?"保存中...":"保存"]})]})]})]})}function Te({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={},it=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then},De={},T={};let he;const at=[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 at[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.');he=e};T.isKanjiModeEnabled=function(){return typeof he<"u"};T.toSJIS=function(e){return he(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 Ue(){this.buffer=[],this.length=0}Ue.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 lt=Ue;function q(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)}q.prototype.set=function(t,e,o,r){const n=t*this.size+e;this.data[n]=o,r&&(this.reservedBit[n]=!0)};q.prototype.get=function(t,e){return this.data[t*this.size+e]};q.prototype.xor=function(t,e,o){this.data[t*this.size+e]^=o};q.prototype.isReserved=function(t,e){return this.reservedBit[t*this.size+e]};var ct=q,Fe={};(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}})(Fe);var ze={};const dt=T.getSymbolSize,Ae=7;ze.getPositions=function(e){const o=dt(e);return[[0,0],[o-Ae,0],[0,o-Ae]]};var $e={};(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}})($e);var W={};const P=G,V=[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 V[(e-1)*4+0];case P.M:return V[(e-1)*4+1];case P.Q:return V[(e-1)*4+2];case P.H:return V[(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 Ke={},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}})(Ke);const He=Ke;function ge(t){this.genPoly=void 0,this.degree=t,this.degree&&this.initialize(this.degree)}ge.prototype.initialize=function(e){this.degree=e,this.genPoly=He.generateECPolynomial(this.degree)};ge.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=He.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 ut=ge,Oe={},R={},me={};me.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40};var I={};const qe="[0-9]+",ft="[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 ht="(?:(?![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(ht,"g");I.NUMERIC=new RegExp(qe,"g");I.ALPHANUMERIC=new RegExp(ft,"g");const gt=new RegExp("^"+H+"$"),mt=new RegExp("^"+qe+"$"),xt=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");I.testKanji=function(e){return gt.test(e)};I.testNumeric=function(e){return mt.test(e)};I.testAlphanumeric=function(e){return xt.test(e)};(function(t){const e=me,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=me,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}})(Oe);var Ve={};const ae=T,Qe=1335,pt=21522,Be=ae.getBCHDigit(Qe);Ve.getEncodedBits=function(e,o){const r=e.bit<<3|o;let n=r<<10;for(;ae.getBCHDigit(n)-Be>=0;)n^=Qe<<ae.getBCHDigit(n)-Be;return(r<<10|n)^pt};var Je={};const bt=R;function _(t){this.mode=bt.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 wt=_;const yt=R,ne=["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=yt.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=ne.indexOf(this.data[o])*45;r+=ne.indexOf(this.data[o+1]),e.put(r,11)}this.data.length%2&&e.put(ne.indexOf(this.data[o]),6)};var Nt=D;const Ct=R;function U(t){this.mode=Ct.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 kt=U;const jt=R,Et=T;function F(t){this.mode=jt.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=Et.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 vt=F,Ye={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})(Ye);var St=Ye.exports;(function(t){const e=R,o=wt,r=Nt,n=kt,s=vt,a=I,l=T,c=St;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()))}})(Je);const X=T,re=G,Tt=lt,At=ct,Bt=Fe,It=ze,le=$e,ce=W,Mt=ut,Y=Oe,Pt=Ve,Rt=R,se=Je;function Lt(t,e){const o=t.size,r=It.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 _t(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 Dt(t,e){const o=Bt.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 Ut(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 oe(t,e,o){const r=t.size,n=Pt.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 Ft(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 zt(t,e,o){const r=new Tt;o.forEach(function(c){r.put(c.mode.bit,4),r.put(c.getLength(),Rt.getCharCountIndicator(c.mode,t)),c.write(r)});const n=X.getSymbolTotalCodewords(t),s=ce.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 $t(r,t,e)}function $t(t,e,o){const r=X.getSymbolTotalCodewords(e),n=ce.getTotalCodewordsCount(e,o),s=r-n,a=ce.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 Mt(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 Kt(t,e,o,r){let n;if(Array.isArray(t))n=se.fromArray(t);else if(typeof t=="string"){let u=e;if(!u){const d=se.rawSplit(t);u=Y.getBestVersionForData(d,o)}n=se.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=zt(e,o,n),l=X.getSymbolSize(e),c=new At(l);return Lt(c,e),_t(c),Dt(c,e),oe(c,o,0),e>=7&&Ut(c,e),Ft(c,a),isNaN(r)&&(r=le.getBestMask(c,oe.bind(null,c,o))),le.applyMask(r,c),oe(c,o,r),{modules:c,version:e,errorCorrectionLevel:o,maskPattern:r,segments:n}}De.create=function(e,o){if(typeof e>"u"||e==="")throw new Error("No input text");let r=re.M,n,s;return typeof o<"u"&&(r=re.from(o.errorCorrectionLevel,re.M),n=Y.from(o.version),s=le.from(o.maskPattern),o.toSJISFunc&&X.setToSJISFunction(o.toSJISFunc)),Kt(e,n,r,s)};var Ge={},xe={};(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}}})(xe);(function(t){const e=xe;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)}})(Ge);var We={};const Ht=xe;function Ie(t,e){const o=t.a/255,r=e+'="'+t.hex+'"';return o<1?r+" "+e+'-opacity="'+o.toFixed(2).slice(1)+'"':r}function ie(t,e,o){let r=t+e;return typeof o<"u"&&(r+=" "+o),r}function Ot(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?ie("M",c+o,.5+u+o):ie("m",n,0),n=0,s=!1),c+1<e&&t[l+1]||(r+=ie("h",a),a=0)):n++}return r}We.render=function(e,o,r){const n=Ht.getOptions(o),s=e.modules.size,a=e.modules.data,l=s+n.margin*2,c=n.color.light.a?"<path "+Ie(n.color.light,"fill")+' d="M0 0h'+l+"v"+l+'H0z"/>':"",u="<path "+Ie(n.color.dark,"stroke")+' d="'+Ot(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 qt=it,de=De,Ze=Ge,Vt=We;function pe(t,e,o,r,n){const s=[].slice.call(arguments,1),a=s.length,l=typeof s[a-1]=="function";if(!l&&!qt())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=de.create(o,r);c(t(d,e,r))}catch(d){u(d)}})}try{const c=de.create(o,r);n(null,t(c,e,r))}catch(c){n(c)}}O.create=de.create;O.toCanvas=pe.bind(null,Ze.render);O.toDataURL=pe.bind(null,Ze.renderToDataURL);O.toString=pe.bind(null,function(t,e,o){return Vt.render(t,o)});const Qt=2e3,Me=5;function Jt({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 be.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"),te.success(t?`微信「${t.name}」重新授权成功,频道已连接`:"微信绑定成功,频道已自动创建并连接"),setTimeout(e,2400);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+"/"+Me+")",f),y.current>=Me)r("error"),u("轮询状态失败次数过多,请刷新二维码重试"),te.error("微信绑定状态轮询失败,请刷新二维码重试");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 be.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");const w=String((f==null?void 0:f.message)??f);u(w),te.error(`获取微信二维码失败:${w}`)}},b=()=>{m()};return v.useEffect(()=>(m(),x),[]),v.useEffect(()=>(a&&p(),x),[a]),i.jsx(nt,{isOpen:!0,onClose:e,title:`扫码绑定 · ${(t==null?void 0: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-2 px-4 text-center",children:[i.jsx("span",{className:"text-2xl",children:"🎉"}),i.jsx("span",{className:"text-sm font-medium",children:"绑定成功"}),i.jsx("span",{className:"text-xs opacity-90",children:t?`「${t.name}」已连接,可开始使用`:"微信频道已创建并连接,可开始使用"}),i.jsx("button",{onClick:e,className:"mt-1 text-xs bg-white/20 hover:bg-white/30 px-3 py-1.5 rounded-md transition-colors",children:"开始使用"})]}),o==="expired"&&i.jsxs("div",{className:"absolute inset-0 bg-black/80 flex flex-col items-center justify-center text-white gap-2",children:[i.jsx("span",{className:"text-sm",children:"二维码已失效"}),i.jsx("button",{onClick: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 en(){const{load:t,loading:e,qrOpen:o,qrChannel:r,closeQr:n}=fe();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(tt,{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(rt,{})}),i.jsx("div",{className:"flex-1 min-w-0",children:i.jsx(st,{})})]}),o&&i.jsx(Jt,{channel:r,onClose:n})]})}export{en as ChannelConfigView};
@@ -1 +0,0 @@
1
- import{j as t}from"./markdown-hmVtvQNZ.js";import{r,e as K,A as W,av as z}from"./icons-CjRO1znb.js";import{e as G,j as U,w as k,p as F,c as q,k as Q,u as V,M as B,A as b,q as X}from"./index-CAwHhr7A.js";import{c as Y,R as Z,e as ee}from"./hookRisk-Ds8oxbfO.js";import"./react-vendor-Dp4P972X.js";import"./state-C_jK7HTi.js";const g=15;function oe({isOpen:x,onCloseModal:j}){const{t:o}=G("hook"),i=U(),p=i.pendingApprovals,E=i.autoMode,R=i.setAutoMode,[w,M]=r.useState(0),[n,_]=r.useState(!1),[m,I]=r.useState(g),l=r.useRef(null),d=r.useRef(!1);r.useEffect(()=>{if(p.length!==0){if(E){p.forEach(s=>{k.send({type:"hook_allow",data:JSON.stringify({approvalId:s.approvalId})})}),i.clearApprovals();return}M(s=>Math.min(s,p.length-1))}},[p.length,E]);const e=p[w]??null,y=p.length>0&&e!==null,H=p.length,T=y?H-w-1:0;r.useEffect(()=>{if(!(!y||n||!x||!e))return I(g),l.current=setInterval(()=>{I(s=>s<=1?(l.current&&clearInterval(l.current),0):s-1)},1e3),()=>{l.current&&clearInterval(l.current)}},[y,n,x,e==null?void 0:e.approvalId]);const c=e?Y(e.toolName,e.askPayload):{level:"MEDIUM",reasonKey:"risk_default"},f=Z[c.level],L=F[c.level==="CRITICAL"?"critical":c.level==="HIGH"?"high":c.level==="LOW"?"low":"medium"],$=e?ee(e.toolName,e.askPayload):null,O=m/g*100,S=m<=5,J=X(g-m),P=r.useCallback((s,a)=>{const N=q.getState().activeSessionId;N&&Q.getState().updateHookApprovalStatus(N,s,a)},[]),u=r.useCallback(s=>{e&&(s&&P(e.approvalId,s),_(!0),setTimeout(()=>{i.removeApproval(e.approvalId),M(0),_(!1),d.current=!1,I(g)},200))},[e==null?void 0:e.approvalId,i,P]),v=r.useCallback(()=>{!e||n||d.current||(d.current=!0,l.current&&clearInterval(l.current),k.send({type:"hook_allow",data:JSON.stringify({approvalId:e.approvalId})}),u("approved"))},[e,u,n]),h=r.useCallback(()=>{!e||n||d.current||(d.current=!0,l.current&&clearInterval(l.current),k.send({type:"hook_deny",data:JSON.stringify({approvalId:e.approvalId})}),u("denied"))},[e,u,n]),A=r.useCallback(()=>{!e||n||d.current||(d.current=!0,l.current&&clearInterval(l.current),i.addToSessionAllowList(e.toolName),k.send({type:"hook_allow",data:JSON.stringify({approvalId:e.approvalId})}),u("approved"))},[e,u,i,n]),C=r.useCallback(()=>{!e||n||d.current||(d.current=!0,l.current&&clearInterval(l.current),R(!0),V.getState().setAuto(!0),k.send({type:"hook_allow",data:JSON.stringify({approvalId:e.approvalId})}),u("approved"))},[e,u,n,R]),D=(e==null?void 0:e.timeoutAction)==="deny"?h:v;return r.useEffect(()=>{m===0&&x&&!n&&e&&D()},[m,x,n,e,D]),r.useEffect(()=>{if(!x)return;const s=a=>{a.key==="Escape"?(a.preventDefault(),a.stopPropagation(),h()):a.key==="Enter"?(a.preventDefault(),v()):a.key==="1"?v():a.key==="2"?h():a.key==="3"?A():a.key==="4"&&C()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x,v,h,A,C]),!y||!e?null:t.jsx(B,{isOpen:x,onClose:()=>j==null?void 0:j(),title:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(z,{className:"w-4 h-4 text-yellow-400"}),t.jsx("span",{children:o("hookApproval")}),t.jsxs("span",{className:"text-xs text-dark-muted",children:["(",w+1,"/",H,")"]})]}),size:"lg",children:t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg ${f.bg} border ${f.border}`,children:[t.jsxs("span",{className:`px-1.5 py-0.5 rounded text-xs font-bold border ${f.badge}`,children:[f.icon," ",c.level]}),t.jsx("span",{className:"text-xs text-dark-muted",children:o(c.reasonKey)}),t.jsxs("div",{className:"flex items-center gap-1.5 ml-auto",children:[t.jsx(K,{size:12,className:S?"text-accent-red":"text-dark-muted"}),t.jsxs("span",{className:`text-xs font-mono ${S?"text-accent-red animate-pulse":"text-dark-muted"}`,children:[m,"s"]}),t.jsx("div",{className:"w-12 h-1.5 bg-dark-border rounded-full overflow-hidden",children:t.jsx("div",{className:`h-full rounded-full transition-all duration-700 ${S?"bg-accent-red":m<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${O}%`}})})]})]}),t.jsxs("div",{className:"grid gap-3 md:grid-cols-[1fr_1.2fr]",children:[t.jsxs("div",{className:"bg-dark-bg rounded-lg p-3 border border-dark-border space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[t.jsx("span",{className:"text-dark-muted shrink-0",children:o("tool")}),t.jsx("code",{className:"text-accent-blue font-mono text-xs bg-dark-surface px-1.5 py-0.5 rounded truncate",children:e.toolName})]}),t.jsx("div",{className:"text-xs text-dark-muted",children:J}),t.jsx("div",{className:"text-xs text-dark-muted",children:L.label}),e.timeoutAction&&t.jsxs("div",{className:`text-xs ${e.timeoutAction==="deny"?"text-accent-red":"text-accent-green"}`,children:["timeout: ",e.timeoutAction==="allow"?"auto-allow":"auto-deny",e.timeoutMs?` (${(e.timeoutMs/1e3).toFixed(0)}s)`:""]})]}),t.jsxs("div",{className:"bg-dark-bg rounded-lg p-3 border border-dark-border space-y-2",children:[$&&t.jsx("pre",{className:"text-xs font-mono text-dark-text whitespace-pre-wrap break-all leading-relaxed max-h-36 overflow-y-auto custom-scrollbar",children:$}),(c.level==="CRITICAL"||c.level==="HIGH")&&t.jsxs("div",{className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded ${f.bg} ${f.text}`,children:[t.jsx(W,{size:13}),t.jsx("span",{children:c.level==="CRITICAL"?o("highRiskWarning"):o("mediumRiskConfirm")})]})]})]}),t.jsx("div",{className:"grid gap-2 md:grid-cols-2",children:[b.allow,b.deny,b.allow_session,b.auto].map((s,a)=>{const N=[v,h,A,C][a];return t.jsxs("button",{onClick:N,disabled:n,className:"w-full text-left px-3 py-2 rounded-lg hover:bg-dark-hover transition-colors disabled:opacity-50 border border-transparent hover:border-dark-border/50",children:[t.jsxs("div",{className:"flex items-baseline gap-2",children:[t.jsxs("span",{className:"text-xs text-dark-muted font-mono shrink-0",children:[a+1,"."]}),t.jsx("span",{className:"text-sm text-dark-text",children:s.label}),t.jsxs("span",{className:"text-xs text-dark-muted",children:["[",s.key,"]"]})]}),t.jsx("div",{className:"text-xs text-dark-muted/60 ml-5 mt-0.5",children:a===0?o("optionAllowHint"):a===1?o("optionDenyHint"):a===2?o("optionAllowAlwaysHint",{tool:e.toolName}):o("optionAutoModeHint")})]},s.key)})}),t.jsxs("div",{className:"flex items-center justify-between text-xs text-dark-muted/60",children:[t.jsx("span",{children:o("shortcutHint")}),t.jsx("span",{children:T>0?o("morePending",{n:T}):o("lastItem")})]})]})})}export{oe as HookApprovalModal};
@@ -1,3 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CAwHhr7A.js","assets/markdown-hmVtvQNZ.js","assets/icons-CjRO1znb.js","assets/react-vendor-Dp4P972X.js","assets/state-C_jK7HTi.js","assets/index-Czlzypr3.css"])))=>i.map(i=>d[i]);
2
- import{a as j,_ as L}from"./index-CAwHhr7A.js";import{j as e}from"./markdown-hmVtvQNZ.js";import{r as N,ah as z,ai as I,aj as M,$ as U,X as _,ak as $,C as Y,b as G,al as J,a7 as B,a8 as W,R as V,ac as q,D as X,P as K}from"./icons-CjRO1znb.js";import{c as Q}from"./state-C_jK7HTi.js";import"./react-vendor-Dp4P972X.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-CAwHhr7A.js").then(t=>t.y);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-CAwHhr7A.js").then(E=>E.y);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-hmVtvQNZ.js";import{r as a,R as oe,Z as st,P as ce,u as Ke,X as De,_ as at,s as de,$ as Ae,a0 as rt,a1 as lt,N as nt,J as ot,a2 as ct,a3 as dt,D as it,a4 as $e,A as ut,a5 as xt}from"./icons-CjRO1znb.js";import"./Toast-Bmm1ZZzF.js";import{a as x,t as C,M as Ee}from"./index-CAwHhr7A.js";import"./react-vendor-Dp4P972X.js";import"./state-C_jK7HTi.js";function pt(){const[g,y]=a.useState([]),[k,h]=a.useState("1.0"),[O,d]=a.useState(!0),[I,H]=a.useState(!0),[Y,K]=a.useState(null),j=a.useCallback(async()=>{H(!0),K(null);try{const f=await x.providers.presets();f.success&&f.data?(y(Array.isArray(f.data.providers)?f.data.providers:[]),h(f.data.version||"1.0"),d(f.data.customSupported!==!1)):K(f.error||"获取 Provider 列表失败")}catch(f){K(f instanceof Error?f.message:"未知错误")}finally{H(!1)}},[]);return a.useEffect(()=>{j()},[j]),{presets:g,loading:I,error:Y,version:k,customSupported:O,reload:j}}const V={provider:"",modelId:"",modelName:"",baseUrl:"",apiKeys:"",apiType:"openai-completions",temperature:1,maxTokens:32768,contextWindow:1e6},mt={providerKey:"",apiKey:"",modelIds:"",baseUrl:"",apiType:"openai-completions",setDefault:!1},ze={deepseek:10,moonshotai:20,"moonshotai-cn":21,"kimi-for-coding":22,zhipuai:30,zai:31,"alibaba-cn":40,alibaba:41,minimax:50,"minimax-cn":51,moark:60,siliconflow:70,"siliconflow-cn":71,"stepfun-ai":80,stepfun:81,modelscope:90,openai:100,anthropic:110,google:120,"google-vertex":121,meta:130,mistral:140,groq:150,xai:160,cohere:170,openrouter:180,huggingface:190};function kt(){var Se,Me;const{presets:g,loading:y,reload:k}=pt(),[h,O]=a.useState([]),[d,I]=a.useState(null),[H,Y]=a.useState(!0),[K,j]=a.useState(null),[f,ue]=a.useState(null),[Fe,D]=a.useState(!1),[P,W]=a.useState(null),[n,b]=a.useState(V),[xe,pe]=a.useState(!1),[me,T]=a.useState(null),[o,Le]=a.useState(null),[Re,A]=a.useState(!1),[be,G]=a.useState("select"),[N,$]=a.useState(null),[i,w]=a.useState(mt),[he,fe]=a.useState(!1),[ge,S]=a.useState(null),[ve,se]=a.useState(!1),[J,ye]=a.useState(!1),[B,X]=a.useState(""),[ke,je]=a.useState({}),[ae,Ne]=a.useState(!1),[re,_]=a.useState([]),[E,z]=a.useState(new Set),[we,U]=a.useState(null),[Z,le]=a.useState(""),M=a.useCallback(async()=>{try{const e=await x.config.provider.get();e.success&&e.data&&Le(e.data)}catch{}},[]),p=a.useCallback(async()=>{Y(!0),j(null);try{const[e,s]=await Promise.all([x.models.list(),x.system.status()]);if(await M(),e.success&&e.data&&Array.isArray(e.data.models)&&O(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{Y(!1)}},[M]);a.useEffect(()=>{p()},[p]),a.useEffect(()=>{const e=()=>{p(),M()};return window.addEventListener("models-updated",e),()=>window.removeEventListener("models-updated",e)},[p,M]);const F=a.useCallback(e=>`${e.provider}:${e.id}`,[]),Oe=a.useCallback(e=>ke[F(e)]||{inputTokens:0,outputTokens:0},[F,ke]),Ce=a.useCallback((e,s,r)=>{const l=F(e);je(u=>{var c,m;return{...u,[l]:{inputTokens:s==="inputTokens"?r:((c=u[l])==null?void 0:c.inputTokens)||0,outputTokens:s==="outputTokens"?r:((m=u[l])==null?void 0:m.outputTokens)||0}}})},[F]),We=a.useCallback(e=>{je(s=>({...s,[F(e)]:{inputTokens:0,outputTokens:0}}))},[F]),q=a.useMemo(()=>{const e=[...g];return e.find(s=>s.key==="custom")||e.push({key:"custom",name:"Custom",baseUrl:"",apiType:"openai-completions",defaultModel:"",isCustom:!0}),e},[g]),Q=a.useMemo(()=>[...q].sort((e,s)=>{if(e.isCustom)return-1;if(s.isCustom)return 1;const r=ze[e.key],l=ze[s.key];return r!==void 0&&l!==void 0?r-l:r!==void 0?-1:l!==void 0?1:e.name.localeCompare(s.name)}),[q]),Pe=a.useMemo(()=>{const e=B.trim().toLowerCase();return e?Q.filter(s=>s.name.toLowerCase().includes(e)||s.key.toLowerCase().includes(e)||(s.defaultModel||"").toLowerCase().includes(e)||(s.baseUrl||"").toLowerCase().includes(e)||(s.models||[]).some(r=>String(r).toLowerCase().includes(e))):Q},[Q,B]),Te=a.useCallback(e=>{var c,m;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=((m=e.models)==null?void 0:m.slice(0,3).join(", "))||e.defaultModel,u=r.length>0?r.join(", "):l;$(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}),G("form"),A(!0),S(null),se(!1),_([]),z(new Set),U(null),le("")},[h,o]),ne=a.useCallback(()=>{$("custom"),w({providerKey:"",apiKey:"",modelIds:"",baseUrl:"",apiType:"openai-completions",setDefault:!(o!=null&&o.configured)}),G("form"),A(!0),S(null),se(!1),_([]),z(new Set),U(null),le("")},[o]),Ge=a.useCallback(async()=>{var s;const e=i.baseUrl;if(!e){U("请先填写 Base URL");return}Ne(!0),U(null),_([]),z(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)){_(l.data.models);const u=new Set(i.modelIds.split(",").map(c=>c.trim()).filter(Boolean));z(u),C.success(`获取到 ${l.data.models.length} 个模型`)}else U(l.error||"获取模型列表失败,请检查 Base URL 和 API Key")}catch(r){U(r instanceof Error?r.message:"请求失败")}finally{Ne(!1)}},[i.baseUrl,i.apiKey,i.modelIds]),Be=a.useCallback(e=>{z(s=>{const r=new Set(s);return r.has(e)?r.delete(e):r.add(e),r})},[]),_e=a.useCallback(()=>{const e=Array.from(E).join(", ");w(s=>({...s,modelIds:e}))},[E]),qe=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 p();return}const m=c.error||"";u(m)?C.error(`“${l}” 是默认模型,无法直接禁用。请先在「Provider 配置」中更换默认模型,再进行禁用。`):C.error(m||"操作失败,请重试")}catch(c){const m=c instanceof Error?c.message:"";u(m)?C.error(`“${l}” 是默认模型,无法直接禁用。请先在「Provider 配置」中更换默认模型,再进行禁用。`):C.error(m||"操作失败,请重试")}},Ve=async e=>{ue(e);try{await x.models.test(e),await p()}finally{ue(null)}},He=async(e,s)=>{if(confirm(`确定要删除模型 "${s}" 吗?此操作不可撤销。`))try{(await x.models.delete(e,s)).success&&await p()}catch{}},Ye=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),D(!0)},Je=async()=>{var Ie;const e=q.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=(Ie=o==null?void 0:o.providers)==null?void 0:Ie[s],c=i.apiKey.trim()||(l!=null&&l.hasApiKey?void 0:""),m=c!==void 0&&c!==""?c.replace(/[^\x00-\xFF]/g,""):c,R={provider:s,baseUrl:i.baseUrl||r.baseUrl,apiType:i.apiType||r.apiType,apiKey:m,models:(i.modelIds||r.defaultModel||"").split(",").map((v,tt)=>({id:v.trim(),name:v.trim(),enabled:!0,priority:10+tt})).filter(v=>v.id.length>0)};(!(o!=null&&o.configured)||i.setDefault)&&(R.setDefault=!0),fe(!0),S(null);try{const v=await x.config.provider.save(R);v.success?(A(!1),G("select"),$(null),await M(),await p()):S(v.error||"保存失败")}catch(v){S(v instanceof Error?v.message:"未知错误")}finally{fe(!1)}},Xe=async e=>{if(confirm(`确定要移除 "${e}" 的配置吗?这将删除其 API Key 和模型。`))try{await x.config.provider.delete(e),await M(),await p()}catch{}},Ze=async()=>{if(!n.provider.trim()||!n.modelId.trim()){T("提供商名称和模型 ID 不能为空");return}pe(!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?(D(!1),W(null),b(V),await p()):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?(D(!1),b(V),await p()):T(s.error||"保存失败")}}catch(e){T(e instanceof Error?e.message:"未知错误")}finally{pe(!1)}},Qe=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"}},et=e=>{switch(e){case"online":return t.jsx(xt,{size:14});case"offline":return t.jsx($e,{size:14});case"error":return t.jsx(ut,{size:14});default:return t.jsx($e,{size:14})}},L=a.useMemo(()=>q.find(e=>e.key===N)||null,[N,q]);return H?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 flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("h2",{className:"text-base font-semibold",children:"Provider 配置"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("button",{onClick:async()=>{try{await x.providers.refresh(),C.success("Provider 列表已刷新"),ye(!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(oe,{size:12}),"刷新列表"]}),t.jsxs("button",{onClick:()=>{J&&X(""),ye(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:[J?t.jsx(st,{size:12}):t.jsx(ce,{size:12}),J?"收起":"新增 Provider"]})]})]}),J&&t.jsxs("div",{children:[t.jsxs("div",{className:"relative mb-3 max-w-md",children:[t.jsx(Ke,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted"}),t.jsx("input",{value:B,onChange:e=>X(e.target.value),className:"w-full pl-8 pr-8 py-1.5 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",placeholder:"搜索 Provider 名称 / 模型..."}),B&&t.jsx("button",{onClick:()=>X(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-white",title:"清除","aria-label":"清除搜索",children:t.jsx(De,{size:13})})]}),t.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3 max-h-[420px] overflow-y-auto custom-scrollbar pr-1",children:y?t.jsxs("div",{className:"col-span-full flex items-center justify-center py-4 text-dark-muted text-sm",children:[t.jsx(at,{size:14,className:"mr-2 animate-spin"}),"加载 Provider 列表..."]}):Pe.length===0?t.jsxs("div",{className:"col-span-full border border-accent-red/30 bg-accent-red/10 rounded-lg p-4 text-center",children:[t.jsx("div",{className:"text-sm text-accent-red font-medium mb-1",children:"未找到匹配的 Provider"}),t.jsxs("div",{className:"text-xs text-dark-muted mb-3",children:["没有与「",B,"」匹配的 Provider,请检查拼写或改用完整列表"]}),t.jsxs("div",{className:"flex items-center justify-center gap-2",children:[t.jsxs("button",{onClick:()=>X(""),className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-dark-border rounded hover:bg-dark-hover",children:[t.jsx(De,{size:12}),"清除搜索"]}),t.jsxs("button",{onClick:ne,className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs bg-accent-blue text-white rounded hover:opacity-90",children:[t.jsx(ce,{size:12}),"添加自定义 Provider"]})]})]}):Pe.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"?ne():Te(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(de,{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:m=>{m.stopPropagation(),Xe(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(Ae,{size:13})})]})})})]})]}),d&&t.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[t.jsx(ee,{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(ee,{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(ee,{title:"在线实例",value:d.totalInstances===0?"无":`${d.healthyInstances}/${d.totalInstances}`,color:d.healthyInstances>0?"green":"red"}),t.jsx(ee,{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),D(!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(ce,{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=Oe(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:Qe(e.status),children:et(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(te,{label:"负载",value:`${e.load}/${e.maxLoad}`}),t.jsx(te,{label:"Token",value:`${e.tokens}/${e.maxTokens}`}),t.jsx(te,{label:"输入价格",value:`$${e.price.input}/1K`}),t.jsx(te,{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(Ue,{label:"输入 token",value:s.inputTokens,onChange:l=>Ce(e,"inputTokens",l)}),t.jsx(Ue,{label:"输出 token",value:s.outputTokens,onChange:l=>Ce(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:()=>We(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(rt,{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 p()}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 p()}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 p()}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 p()}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:()=>Ye(e),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:"编辑模型",children:t.jsx(lt,{size:13})}),t.jsx("button",{onClick:()=>He(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(Ae,{size:13})}),t.jsx("button",{onClick:()=>Ve(e.id),disabled:f===e.id,className:"p-1.5 rounded hover:bg-dark-hover disabled:opacity-50",title:"刷新",children:t.jsx(oe,{size:13,className:f===e.id?"animate-spin":""})}),t.jsx("button",{onClick:()=>qe(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(nt,{size:36,className:"mx-auto mb-2 opacity-40"}),t.jsx("p",{className:"text-sm",children:"暂无模型,请先在上方配置 Provider"})]})]})]}),t.jsx(Ee,{isOpen:Re,onClose:()=>{A(!1),G("select"),$(null)},title:be==="select"?"选择 Provider":(L==null?void 0:L.name)||"Provider 配置",size:"xl",children:be==="select"?t.jsx("div",{className:"space-y-4",children:t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[Q.filter(e=>e.key!=="custom").map(e=>t.jsxs("button",{onClick:()=>Te(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(de,{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:ne,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(ot,{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:ve?"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:()=>se(e=>!e),className:"absolute right-2 top-2 text-dark-muted hover:text-white",children:ve?t.jsx(ct,{size:14}):t.jsx(dt,{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:(L==null?void 0:L.defaultModel)||"gpt-4o, deepseek-chat"}),t.jsxs("button",{onClick:Ge,disabled:ae||!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:[ae?t.jsx(oe,{size:13,className:"animate-spin"}):t.jsx(it,{size:13}),ae?"获取中...":"获取模型列表"]})]}),we&&t.jsx("div",{className:"mt-1 text-xs text-accent-red",children:we}),re.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:re.length})," 个模型, 已选 ",t.jsx("strong",{className:"text-accent-blue",children:E.size})," 个"]}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx("button",{onClick:_e,className:"px-2 py-0.5 text-[10px] bg-accent-blue text-white rounded hover:opacity-90",children:"应用选中"}),t.jsx("button",{onClick:()=>{_([]),z(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(Ke,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),t.jsx("input",{value:Z,onChange:e=>le(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:re.filter(e=>!Z||e.id.toLowerCase().includes(Z.toLowerCase())||e.name.toLowerCase().includes(Z.toLowerCase())).map(e=>t.jsxs("label",{className:`flex items-center gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors ${E.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:E.has(e.id),onChange:()=>Be(e.id),className:"sr-only"}),E.has(e.id)?t.jsx(de,{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"})]}),ge&&t.jsx("div",{className:"text-sm text-accent-red",children:ge}),t.jsxs("div",{className:"flex justify-between gap-2 pt-2",children:[t.jsx("div",{children:N&&N!=="custom"&&((Me=(Se=o==null?void 0:o.providers)==null?void 0:Se[N])==null?void 0:Me.hasApiKey)&&t.jsx("button",{onClick:async()=>{if(confirm(`确定要删除 "${N}" 的配置吗?`))try{await x.config.provider.delete(N),A(!1),$(null),await M(),await p()}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:()=>{G("select"),$(null),A(!1)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:"取消"}),t.jsx("button",{onClick:Je,disabled:he,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:he?"保存中...":"保存"})]})]})}),t.jsx(Ee,{isOpen:Fe,onClose:()=>{D(!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(ie,{label:"温度",value:n.temperature,step:"0.1",min:"0",max:"2",onChange:e=>b(s=>({...s,temperature:e}))}),t.jsx(ie,{label:"最大 Token",value:n.maxTokens,onChange:e=>b(s=>({...s,maxTokens:e}))}),t.jsx(ie,{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))})]})]}),me&&t.jsx("div",{className:"text-sm text-accent-red bg-accent-red/10 p-2 rounded",children:me}),t.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[t.jsx("button",{onClick:()=>{D(!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:Ze,disabled:xe,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:xe?"保存中...":"保存"})]})]})})]})}function ee({title:g,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:g}),t.jsx("div",{className:"text-xl font-semibold",children:y})]})}function te({label:g,value:y}){return t.jsxs("div",{children:[t.jsx("div",{className:"text-dark-muted",children:g}),t.jsx("div",{children:y})]})}function Ue({label:g,value:y,onChange:k}){return t.jsxs("div",{children:[t.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:g}),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 ie({label:g,value:y,onChange:k,min:h,max:O,step:d}){return t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:g}),t.jsx("input",{type:"number",value:y,min:h,max:O,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{kt as ModelsView,kt as default};