@deepseekcode/cli 1.0.25 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1170 -1124
- package/package.json +4 -1
- package/web/dist/assets/AutomationView-CPCd-Qhd.js +1 -0
- package/web/dist/assets/ChannelConfigView-D6JtjZyf.js +8 -0
- package/web/dist/assets/ConnectorsView-BPPr7T9p.js +1 -0
- package/web/dist/assets/FileTreeView-CO8knuwu.js +11 -0
- package/web/dist/assets/HookConfigView-CYuzwf8u.js +1 -0
- package/web/dist/assets/ModelsView-Cji4mbXE.js +1 -0
- package/web/dist/assets/PluginsView-CKKnYKMP.js +1 -0
- package/web/dist/assets/SessionGrid-BOpVWUEK.js +37 -0
- package/web/dist/assets/SettingsPanel-R1fOoB25.js +4 -0
- package/web/dist/assets/{SkillsView-BrQY_vgT.js → SkillsView-DmQGY9v0.js} +1 -1
- package/web/dist/assets/TemplatesTab-_vSIuTZP.js +1 -0
- package/web/dist/assets/TerminalView-CTU0aA8o.js +3 -0
- package/web/dist/assets/ToolsView-DUEqePPo.js +1 -0
- package/web/dist/assets/{icons-B9mi2ie6.js → icons-qcawb7PZ.js} +1 -1
- package/web/dist/assets/index-DL2ULWxM.css +1 -0
- package/web/dist/assets/index-DUpwXfa-.js +70 -0
- package/web/dist/assets/{markdown-BrFQfawv.js → markdown-yjmXQjrx.js} +1 -1
- package/web/dist/assets/{panels-BX-TtLOU.js → panels-CX_dYEv0.js} +1 -1
- package/web/dist/assets/{react-vendor-CiRFOYk_.js → react-vendor-CSlQceOk.js} +1 -1
- package/web/dist/assets/{state-BcoCffxz.js → state-DOzZasIm.js} +1 -1
- package/web/dist/favicon.svg +32 -12
- package/web/dist/index.html +7 -7
- package/web/dist/logo.svg +32 -12
- package/web/dist/assets/AutomationView-MOGwMs0s.js +0 -1
- package/web/dist/assets/ChannelConfigView-CHWC4ETy.js +0 -8
- package/web/dist/assets/ConnectorsView-DaP_wB0W.js +0 -1
- package/web/dist/assets/FileTreeView-N64-Dser.js +0 -11
- package/web/dist/assets/HookConfigView-DsZDeVFi.js +0 -2
- package/web/dist/assets/ModelsView-C1cE2wMN.js +0 -2
- package/web/dist/assets/PluginsView-CsSjjfrn.js +0 -1
- package/web/dist/assets/SessionGrid-Bg-UTI2P.js +0 -37
- package/web/dist/assets/SettingsPanel-pZbjabYJ.js +0 -4
- package/web/dist/assets/TemplatesTab-DSfCryw2.js +0 -1
- package/web/dist/assets/TerminalView-Drr72DaP.js +0 -3
- package/web/dist/assets/ToolsView-ByqbKwqW.js +0 -1
- package/web/dist/assets/index-DCj9TkXV.css +0 -1
- package/web/dist/assets/index-PcXINYWS.js +0 -68
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./markdown-BrFQfawv.js";import{a as N,aJ as E,S as P,aK as U,aq as D,X as O,f as $,y as Y,K as G,aL as J,ay as _,az as B,h as W,aE as q,D as K,z as V}from"./icons-B9mi2ie6.js";import{c as X}from"./state-BcoCffxz.js";import{a as f}from"./index-PcXINYWS.js";import"./react-vendor-CiRFOYk_.js";import"./panels-BX-TtLOU.js";const A=X((l,o)=>({rules:[],stats:null,events:[],agents:[],loading:!1,error:null,fieldErrors:null,formOpen:!1,editingRule:null,dryRunResult:null,loadRules:async()=>{const s=await f.hooks.list();s.success&&Array.isArray(s.data)?l({rules:s.data}):s.success&&s.data&&!Array.isArray(s.data)?l({error:"服务端返回的规则数据格式异常"}):l({error:s.error||"Failed to load rules"})},loadStats:async()=>{const s=await f.hooks.stats();s.success&&s.data&&l({stats:s.data})},loadEvents:async()=>{const s=await f.hooks.events();s.success&&Array.isArray(s.data)?l({events:s.data}):s.success&&s.data&&!Array.isArray(s.data)&&l({error:"服务端返回的事件数据格式异常"})},loadAgents:async()=>{const s=await f.hooks.agents();s.success&&Array.isArray(s.data)?l({agents:s.data}):s.success&&s.data&&!Array.isArray(s.data)&&l({error:"服务端返回的Agent数据格式异常"})},loadAll:async()=>{l({loading:!0,error:null});try{await Promise.all([o().loadRules(),o().loadStats(),o().loadEvents(),o().loadAgents()])}catch(s){l({error:String(s)})}finally{l({loading:!1})}},createRule:async s=>{l({fieldErrors:null});const r=await f.hooks.create(s);if(r.success)return await o().loadRules(),await o().loadStats(),l({formOpen:!1,editingRule:null}),!0;if(r.error){l({error:r.error});try{const i=JSON.parse(r.error);i.fieldErrors&&l({fieldErrors:i.fieldErrors})}catch{}}return!1},updateRule:async(s,r)=>{l({fieldErrors:null});const i=await f.hooks.update(s,r);return i.success?(await o().loadRules(),l({formOpen:!1,editingRule:null}),!0):(l({error:i.error||"Update failed"}),!1)},deleteRule:async s=>{const r=await f.hooks.delete(s);return r.success?(await o().loadRules(),await o().loadStats(),!0):(l({error:r.error||"Delete failed"}),!1)},batchDelete:async s=>{const r=await f.hooks.batchDelete(s);return r.success?(await o().loadRules(),await o().loadStats(),!0):(l({error:r.error||"Batch delete failed"}),!1)},toggleRule:async(s,r)=>(await f.hooks.toggle(s,r)).success?(l(v=>({rules:v.rules.map(d=>d.name===s?{...d,enabled:r}:d)})),!0):(await o().loadRules(),!1),batchToggle:async(s,r)=>(await f.hooks.batchToggle(s,r)).success?(l(v=>({rules:v.rules.map(d=>s.includes(d.name)?{...d,enabled:r}:d)})),!0):(await o().loadRules(),!1),dryRun:async s=>{const r=await f.hooks.dryRun(s);return r.success&&r.data?(l({dryRunResult:r.data}),r.data):(l({error:r.error||"Dry-run failed"}),null)},openForm:s=>l({formOpen:!0,editingRule:s||null,dryRunResult:null,fieldErrors:null}),closeForm:()=>l({formOpen:!1,editingRule:null,dryRunResult:null,fieldErrors:null}),setDryRunResult:s=>l({dryRunResult:s}),clearError:()=>l({error:null}),clearFieldErrors:()=>l({fieldErrors:null})})),Q={SYSTEM:"bg-accent-red/15 text-accent-red",SECURITY:"bg-accent-orange/15 text-accent-orange",PROJECT:"bg-accent-blue/15 text-accent-blue",USER:"bg-accent-green/15 text-accent-green",PLUGIN:"bg-accent-purple/15 text-accent-purple"},Z={SHELL:"bg-accent-yellow/15 text-accent-yellow",HTTP:"bg-accent-cyan/15 text-accent-cyan",PROMPT:"bg-accent-purple/15 text-accent-purple",AGENT:"bg-accent-blue/15 text-accent-blue"};function ee({rules:l,onEdit:o}){const{toggleRule:s,deleteRule:r,batchDelete:i,batchToggle:v}=A(),[d,h]=N.useState(new Set),[w,k]=N.useState(!1),y=Array.isArray(l)?l:[];if(y.length===0)return e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 py-16 text-dark-muted",children:[e.jsx("div",{className:"text-4xl opacity-60",children:"🪝"}),e.jsx("p",{className:"text-sm",children:"暂无 Hook 规则"}),e.jsx("p",{className:"text-xs text-dark-muted/70",children:'点击右上角"新增规则"创建第一个 Hook'})]});const S=t=>{const m=new Set(d);m.has(t)?m.delete(t):m.add(t),h(m),k(m.size===y.length)},p=()=>{w?(h(new Set),k(!1)):(h(new Set(y.map(t=>t.name))),k(!0))},u=()=>{d.size!==0&&confirm(`确认删除 ${d.size} 条规则?`)&&(i(Array.from(d)),h(new Set),k(!1))},j=t=>{d.size!==0&&(v(Array.from(d),t),h(new Set),k(!1))};return e.jsxs("div",{className:"flex flex-1 flex-col min-h-0",children:[d.size>0&&e.jsxs("div",{className:"mb-2 flex items-center gap-2 rounded-lg border border-accent-blue/30 bg-accent-blue/5 px-3 py-1.5 text-sm",children:[e.jsxs("span",{className:"text-dark-muted",children:["已选 ",d.size," 项"]}),e.jsx("button",{onClick:()=>j(!0),className:"rounded bg-accent-green/15 px-2 py-0.5 text-accent-green transition-colors hover:bg-accent-green/25",children:"全部启用"}),e.jsx("button",{onClick:()=>j(!1),className:"rounded bg-dark-hover px-2 py-0.5 text-dark-text transition-colors hover:bg-dark-border",children:"全部禁用"}),e.jsx("button",{onClick:u,className:"rounded bg-accent-red/15 px-2 py-0.5 text-accent-red transition-colors hover:bg-accent-red/25",children:"删除"})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar rounded-xl border border-dark-border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"sticky top-0 bg-dark-hover text-dark-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"w-8 p-2.5",children:e.jsx("button",{onClick:p,children:w?e.jsx(E,{size:14}):e.jsx(P,{size:14})})}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"名称"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"事件"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"类型"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"优先级"}),e.jsx("th",{className:"p-2.5 text-left font-medium",children:"状态"}),e.jsx("th",{className:"p-2.5 text-right font-medium",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-dark-border",children:y.map(t=>e.jsxs("tr",{className:"transition-colors hover:bg-dark-hover/50",children:[e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>S(t.name),children:d.has(t.name)?e.jsx(E,{size:14,className:"text-accent-blue"}):e.jsx(P,{size:14,className:"text-dark-muted"})})}),e.jsxs("td",{className:"p-2.5",children:[e.jsx("div",{className:"font-medium text-dark-text",children:t.name}),t.description&&e.jsx("div",{className:"mt-0.5 max-w-[220px] truncate text-xs text-dark-muted",children:t.description})]}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[Array.isArray(t.events)&&t.events.slice(0,3).map(m=>e.jsx("span",{className:"rounded bg-dark-hover px-1.5 py-0.5 text-xs text-dark-text",children:m},m)),Array.isArray(t.events)&&t.events.length>3&&e.jsxs("span",{className:"px-1 py-0.5 text-xs text-dark-muted",children:["+",t.events.length-3]})]})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${Z[t.implementationType]||"bg-dark-hover text-dark-muted"}`,children:t.implementationType})}),e.jsx("td",{className:"p-2.5",children:e.jsx("span",{className:`rounded px-1.5 py-0.5 text-xs font-medium ${Q[t.priority]||"bg-dark-hover text-dark-muted"}`,children:t.priority})}),e.jsx("td",{className:"p-2.5",children:e.jsx("button",{onClick:()=>s(t.name,!t.enabled),className:`relative h-5 w-9 rounded-full transition-colors ${t.enabled?"bg-accent-green":"bg-dark-border"}`,title:t.enabled?"点击禁用":"点击启用",children:e.jsx("span",{className:`absolute top-0.5 block h-3.5 w-3.5 rounded-full bg-white transition-all ${t.enabled?"left-[18px]":"left-[2px]"}`})})}),e.jsx("td",{className:"p-2.5",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{onClick:()=>o(t),className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue",title:"编辑",children:e.jsx(U,{size:14})}),e.jsx("button",{onClick:()=>{confirm(`删除规则 "${t.name}"?`)&&r(t.name)},className:"rounded p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red",title:"删除",children:e.jsx(D,{size:14})})]})})]},t.name))})]})})]})}const te={name:"",description:"",events:[],implementationType:"SHELL",command:"",url:"",promptTemplate:"",agentName:"",priority:"USER",tools:[],matcherToolNamePattern:"",matcherFromState:"",matcherToState:"",timeoutMs:3e4,enabled:!0,failOpen:!0,scope:"project"},ae=[{value:"SHELL",label:"Shell 脚本",desc:"执行外部脚本,stdin 接收 JSON,stdout 返回决策"},{value:"HTTP",label:"HTTP 端点",desc:"POST JSON 到外部端点"},{value:"PROMPT",label:"LLM Prompt",desc:"发送单轮 Prompt 给 LLM 做风险评估"},{value:"AGENT",label:"AI Agent",desc:"启动只读子代理做深度调查"}],se=[{value:"SYSTEM",label:"SYSTEM (100)"},{value:"SECURITY",label:"SECURITY (80)"},{value:"PROJECT",label:"PROJECT (60)"},{value:"USER",label:"USER (40)"},{value:"PLUGIN",label:"PLUGIN (20)"}],b=l=>`w-full rounded-lg border bg-dark-bg px-3 py-2 text-sm text-dark-text placeholder-dark-muted/60 transition-colors focus:outline-none focus:ring-2 ${l?"border-accent-red focus:border-accent-red focus:ring-accent-red/20":"border-dark-border focus:border-accent-blue focus:ring-accent-blue/20"}`,g="mb-1 block text-xs font-medium text-dark-muted";function re({events:l,agents:o}){const{editingRule:s,fieldErrors:r,dryRunResult:i,createRule:v,updateRule:d,closeForm:h,dryRun:w,setDryRunResult:k,clearFieldErrors:y}=A(),S=Array.isArray(l)?l:[],p=Array.isArray(o)?o:[],[u,j]=N.useState(0),[t,m]=N.useState(te),[T,C]=N.useState("");N.useEffect(()=>{var a,n,c;s&&m({name:s.name,description:s.description||"",events:s.events,implementationType:s.implementationType,command:s.command||"",url:s.url||"",promptTemplate:s.promptTemplate||"",agentName:s.agentName||"",priority:s.priority,tools:s.tools||[],matcherToolNamePattern:((a=s.matchers)==null?void 0:a.toolNamePattern)||"",matcherFromState:((n=s.matchers)==null?void 0:n.fromState)||"",matcherToState:((c=s.matchers)==null?void 0:c.toState)||"",timeoutMs:s.timeoutMs,enabled:s.enabled,failOpen:s.failOpen,scope:s.scope||"project"})},[s]);const x=(a,n)=>{m(c=>({...c,[a]:n})),y()},L=a=>{m(n=>({...n,events:n.events.includes(a)?n.events.filter(c=>c!==a):[...n.events,a]}))},z=a=>{const n=a.every(c=>t.events.includes(c));m(n?c=>({...c,events:c.events.filter(R=>!a.includes(R))}):c=>({...c,events:[...new Set([...c.events,...a])]}))},F=async()=>{const a={};t.matcherToolNamePattern&&(a.toolNamePattern=t.matcherToolNamePattern),t.matcherFromState&&(a.fromState=t.matcherFromState),t.matcherToState&&(a.toState=t.matcherToState);const c={...{...t,tools:t.tools.length>0?t.tools:[]}};c.matchers=a,delete c.matcherToolNamePattern,delete c.matcherFromState,delete c.matcherToState,s?await d(s.name,c):await v(c)},H=async()=>{k(null);const a={};t.matcherToolNamePattern&&(a.toolNamePattern=t.matcherToolNamePattern),await w({hook:{name:t.name||"dry-run",description:t.description,events:t.events,implementationType:t.implementationType,command:t.command,url:t.url,promptTemplate:t.promptTemplate,agentName:t.agentName,priority:t.priority,tools:t.tools,matchers:a,timeoutMs:t.timeoutMs,enabled:!0,failOpen:t.failOpen,scope:t.scope},eventType:t.events[0]||"PRE_TOOL_USE",toolName:"",toolInput:""})},I=T?S.map(a=>({...a,events:Array.isArray(a.events)?a.events.filter(n=>n.name.toLowerCase().includes(T.toLowerCase())||n.summary.includes(T)):[]})).filter(a=>a.events.length>0):S,M=[{title:"基本信息",desc:"名称、描述、事件"},{title:"实现配置",desc:"执行方式与参数"},{title:"高级选项",desc:"优先级、过滤、测试"}];return e.jsxs("div",{className:"fixed inset-0 z-50 flex justify-end",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:h}),e.jsxs("div",{className:"relative flex h-full w-[560px] flex-col border-l border-dark-border bg-dark-bg shadow-2xl animate-slide-in-right",children:[e.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-b border-dark-border px-4 py-3.5",children:[e.jsx("h3",{className:"text-base font-semibold text-dark-text",children:s?`编辑: ${s.name}`:"添加 Hook 规则"}),e.jsx("button",{onClick:h,className:"rounded-lg p-1 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(O,{size:18})})]}),e.jsx("div",{className:"flex flex-shrink-0 border-b border-dark-border",children:M.map((a,n)=>{const c=n===u,R=n<u;return e.jsxs("button",{onClick:()=>j(n),className:`relative flex-1 border-b-2 px-2 py-2.5 text-center text-xs transition-colors ${c?"border-accent-blue bg-accent-blue/5 text-accent-blue":R?"border-transparent text-dark-text":"border-transparent text-dark-muted hover:text-dark-text"}`,children:[e.jsx("span",{className:`mr-1 inline-flex h-4 w-4 items-center justify-center rounded-full text-[10px] ${c?"bg-accent-blue text-white":R?"bg-accent-green text-white":"bg-dark-hover text-dark-muted"}`,children:R?"✓":n+1}),e.jsx("span",{className:"font-medium",children:a.title})]},a.title)})}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-4 overflow-auto custom-scrollbar p-4",children:[r&&Object.keys(r).length>0&&e.jsx("div",{className:"rounded-lg border border-accent-red/40 bg-accent-red/10 p-2.5 text-xs text-accent-red",children:Object.entries(r).map(([a,n])=>e.jsxs("div",{children:[e.jsxs("strong",{children:[a,":"]})," ",n]},a))}),u===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"名称 *"}),e.jsx("input",{value:t.name,onChange:a=>x("name",a.target.value),placeholder:"my-custom-hook",className:b(r==null?void 0:r.name)})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"描述"}),e.jsx("textarea",{value:t.description,onChange:a=>x("description",a.target.value),placeholder:"这个 Hook 的作用...",rows:2,className:b()})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"Scope"}),e.jsxs("select",{value:t.scope,onChange:a=>x("scope",a.target.value),className:b(),children:[e.jsx("option",{value:"project",children:"project (.agent/hooks.json)"}),e.jsx("option",{value:"user",children:"user (~/.agent/hooks.json)"}),e.jsx("option",{value:"local",children:"local (.agent/hooks.local.json)"})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-medium text-dark-muted",children:"事件 *"}),e.jsxs("span",{className:"text-xs text-accent-blue",children:[t.events.length," 已选"]})]}),e.jsx("input",{value:T,onChange:a=>C(a.target.value),placeholder:"搜索事件...",className:b()+" mb-2"}),e.jsx("div",{className:"max-h-[280px] space-y-2 overflow-auto custom-scrollbar rounded-lg border border-dark-border bg-dark-surface p-2",children:I.map(a=>e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>z(a.events.map(n=>n.name)),className:"mb-1 text-xs font-medium text-dark-muted transition-colors hover:text-dark-text",children:[a.category," — 全选/取消"]}),a.events.map(n=>{const c=t.events.includes(n.name);return e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded px-1 py-1 transition-colors hover:bg-dark-hover",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:()=>L(n.name),className:"h-3.5 w-3.5 accent-accent-blue"}),e.jsx("span",{className:"text-xs text-dark-text",children:n.name}),e.jsxs("span",{className:"truncate text-xs text-dark-muted",children:["— ",n.summary]})]},n.name)})]},a.category))})]})]}),u===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"实现类型 *"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:ae.map(a=>{const n=t.implementationType===a.value;return e.jsxs("button",{onClick:()=>x("implementationType",a.value),className:`rounded-lg border p-3 text-left transition-colors ${n?"border-accent-blue bg-accent-blue/10 ring-1 ring-accent-blue/30":"border-dark-border bg-dark-surface hover:bg-dark-hover"}`,children:[e.jsx("div",{className:`text-sm font-medium ${n?"text-accent-blue":"text-dark-text"}`,children:a.label}),e.jsx("div",{className:"mt-1 text-xs text-dark-muted",children:a.desc})]},a.value)})})]}),t.implementationType==="SHELL"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"命令 *"}),e.jsx("input",{value:t.command,onChange:a=>x("command",a.target.value),placeholder:"python3 .agent/hooks/audit.py",className:`font-mono ${b(r==null?void 0:r.command)}`})]}),t.implementationType==="HTTP"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"URL *"}),e.jsx("input",{value:t.url,onChange:a=>x("url",a.target.value),placeholder:"https://example.com/hooks/audit",className:b(r==null?void 0:r.url)})]}),t.implementationType==="PROMPT"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"Prompt 模板 *"}),e.jsx("textarea",{value:t.promptTemplate,onChange:a=>x("promptTemplate",a.target.value),placeholder:"你是一个安全审计专家,请分析以下工具调用...",rows:5,className:`font-mono ${b(r==null?void 0:r.promptTemplate)}`})]}),t.implementationType==="AGENT"&&e.jsxs("div",{children:[e.jsx("label",{className:g,children:"Agent *"}),e.jsxs("select",{value:t.agentName,onChange:a=>x("agentName",a.target.value),className:b(r==null?void 0:r.agentName),children:[e.jsx("option",{value:"",children:"选择 Agent..."}),p.map(a=>e.jsxs("option",{value:a.id,children:[a.name," (",a.description,")"]},a.id))]}),e.jsx("p",{className:"mt-1 text-xs text-dark-muted",children:"Agent 将以只读模式运行(Read/Grep/Glob),不会修改文件"})]})]}),u===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"优先级"}),e.jsx("select",{value:t.priority,onChange:a=>x("priority",a.target.value),className:b(),children:se.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"超时 (ms)"}),e.jsx("input",{type:"number",value:t.timeoutMs,onChange:a=>x("timeoutMs",parseInt(a.target.value)||3e4),min:100,max:3e5,step:1e3,className:b()})]}),e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:t.enabled,onChange:a=>x("enabled",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),"启用"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-text",children:[e.jsx("input",{type:"checkbox",checked:t.failOpen,onChange:a=>x("failOpen",a.target.checked),className:"h-3.5 w-3.5 accent-accent-blue"}),"Fail-open(超时放行)"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"工具过滤(正则,可选)"}),e.jsx("input",{value:t.matcherToolNamePattern,onChange:a=>x("matcherToolNamePattern",a.target.value),placeholder:"Bash.*|FileWrite.*",className:`font-mono ${b()}`})]}),t.events.some(a=>a.includes("STATE"))&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:g,children:"From State"}),e.jsx("input",{value:t.matcherFromState,onChange:a=>x("matcherFromState",a.target.value),className:b()})]}),e.jsxs("div",{children:[e.jsx("label",{className:g,children:"To State"}),e.jsx("input",{value:t.matcherToState,onChange:a=>x("matcherToState",a.target.value),className:b()})]})]}),i&&e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-dark-text",children:"Dry-run 结果"}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"决策: "}),e.jsx("span",{className:i.decision==="ALLOW"?"text-accent-green":i.decision==="DENY"?"text-accent-red":"text-accent-yellow",children:i.decision})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"原因: "}),e.jsx("span",{className:"text-dark-text",children:i.reason})]}),i.contextOutput&&e.jsxs("div",{children:[e.jsx("span",{className:"text-dark-muted",children:"输出: "}),e.jsx("span",{className:"text-dark-text",children:i.contextOutput})]})]})]}),e.jsxs("button",{onClick:H,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-1.5 text-xs text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx($,{size:12})," 试运行 (Dry Run)"]})]})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center justify-between border-t border-dark-border px-4 py-3",children:[e.jsx("div",{className:"flex gap-2",children:u>0&&e.jsxs("button",{onClick:()=>j(u-1),className:"inline-flex items-center gap-1 rounded-lg border border-dark-border bg-dark-surface px-3 py-1.5 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(Y,{size:14})," 上一步"]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:h,className:"rounded-lg border border-dark-border bg-dark-surface px-4 py-1.5 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:"取消"}),u<2?e.jsxs("button",{onClick:()=>j(u+1),className:"inline-flex items-center gap-1 rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:["下一步 ",e.jsx(G,{size:14})]}):e.jsx("button",{onClick:F,className:"rounded-lg bg-accent-blue px-4 py-1.5 text-sm text-white transition-colors hover:bg-accent-blue/90",children:s?"保存修改":"创建规则"})]})]})]})]})}function le({stats:l}){if(!l)return null;const o=[{label:"总规则数",value:l.totalHooks,icon:J,iconWrap:"bg-accent-blue/15 text-accent-blue"},{label:"已启用",value:l.enabledCount,icon:_,iconWrap:"bg-accent-green/15 text-accent-green"},{label:"已禁用",value:l.disabledCount,icon:B,iconWrap:"bg-dark-hover text-dark-muted"}];return e.jsx("div",{className:"grid grid-cols-3 gap-3",children:o.map(s=>{const r=s.icon;return e.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-dark-border bg-dark-surface px-4 py-3",children:[e.jsx("span",{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg ${s.iconWrap}`,children:e.jsx(r,{size:18})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xl font-bold text-dark-text",children:s.value}),e.jsx("div",{className:"text-xs text-dark-muted",children:s.label})]})]},s.label)})})}function xe(){const{rules:l,stats:o,events:s,agents:r,loading:i,error:v,formOpen:d,loadAll:h,openForm:w,clearError:k}=A();N.useEffect(()=>{h()},[]);const y=N.useCallback(async()=>{const p=await f.hooks.export();if(p.success&&p.data){const u=new Blob([JSON.stringify(p.data,null,2)],{type:"application/json"}),j=URL.createObjectURL(u),t=document.createElement("a");t.href=j,t.download="hooks-export.json",t.click(),URL.revokeObjectURL(j)}},[]),S=N.useCallback(()=>{const p=document.createElement("input");p.type="file",p.accept=".json",p.onchange=async u=>{var m;const j=(m=u.target.files)==null?void 0:m[0];if(!j)return;const t=await j.text();try{const T=JSON.parse(t),C=confirm(`合并到现有配置吗?
|
|
2
|
-
"确定"=合并 / "取消"=替换`)?"merge":"replace";(await f.hooks.import({...T,mergeMode:C})).success&&h()}catch(T){console.error("Import failed:",T)}},p.click()},[h]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-dark-bg text-dark-text",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-dark-border px-6 py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-dark-text",children:"Hook 配置"}),e.jsx("p",{className:"mt-0.5 text-xs text-dark-muted",children:"在工具执行、任务流转等生命周期事件上挂载拦截器,实现审批与自定义逻辑"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:h,title:"刷新",className:"rounded-lg p-2 text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:e.jsx(W,{size:16,className:i?"animate-spin":""})}),e.jsxs("button",{onClick:S,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(q,{size:14}),"导入"]}),e.jsxs("button",{onClick:y,className:"inline-flex items-center gap-1.5 rounded-lg border border-dark-border bg-dark-surface px-3 py-2 text-sm text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(K,{size:14}),"导出"]}),e.jsxs("button",{onClick:()=>w(),className:"inline-flex items-center gap-1.5 rounded-lg bg-accent-blue px-3 py-2 text-sm text-white transition-colors hover:bg-accent-blue/90",children:[e.jsx(V,{size:14}),"新增规则"]})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-auto custom-scrollbar px-6 py-4",children:[v&&e.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-lg border border-accent-red/40 bg-accent-red/10 px-4 py-2 text-sm text-accent-red",children:[e.jsx("span",{children:v}),e.jsx("button",{onClick:k,className:"text-accent-red/70 transition-colors hover:text-accent-red",children:e.jsx(O,{size:16})})]}),e.jsx(le,{stats:o}),e.jsxs("section",{className:"mt-4 min-w-0 rounded-xl border border-dark-border bg-dark-surface p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-dark-text",children:"规则列表"}),e.jsxs("span",{className:"text-xs text-dark-muted",children:[l.length," 条"]})]}),i&&l.length===0?e.jsx("div",{className:"flex h-[520px] items-center justify-center text-dark-muted",children:"加载中..."}):e.jsx("div",{className:"min-h-[520px]",children:e.jsx(ee,{rules:l,onEdit:p=>w(p)})})]})]}),d&&e.jsx(re,{events:s,agents:r})]})}export{xe as HookConfigView};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{j as t}from"./markdown-BrFQfawv.js";import{a as r,h as X,a1 as Ht,z as Ce,aa as J,X as dt,ap as Yt,C as Pe,aq as it,ar as qt,as as Vt,ae as Qt,ag as Wt,at as Xt,au as Jt,D as Zt,aj as es,av as ut,_ as ts,aw as ss}from"./icons-B9mi2ie6.js";import{a as p,t as w,M as Ie,P as as}from"./index-PcXINYWS.js";import"./react-vendor-CiRFOYk_.js";import"./state-BcoCffxz.js";import"./panels-BX-TtLOU.js";function rs(){const[N,h]=r.useState([]),[T,y]=r.useState("1.0"),[ge,m]=r.useState(!0),[ve,Z]=r.useState(!0),[ee,B]=r.useState(null),j=r.useCallback(async()=>{Z(!0),B(null);try{const k=await p.providers.presets();k.success&&k.data?(h(Array.isArray(k.data.providers)?k.data.providers:[]),y(k.data.version||"1.0"),m(k.data.customSupported!==!1)):B(k.error||"获取 Provider 列表失败")}catch(k){B(k instanceof Error?k.message:"未知错误")}finally{Z(!1)}},[]);return r.useEffect(()=>{j()},[j]),{presets:N,loading:ve,error:ee,version:T,customSupported:ge,reload:j}}const Ke={provider:"",modelId:"",modelName:"",apiKey:""},ls={providerKey:"",apiKeys:"",modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!1},ns=as,xt={"openai-chat-completions":"OpenAI Chat","openai-completions":"OpenAI Compatible","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages"};function os(N){const h=N.toLowerCase();return h.includes("/anthropic")||h.includes("/coding")||h.includes("/claude")||h.includes("/messages")?"anthropic-messages":h.includes("/responses")?"openai-responses":"openai-completions"}const pt={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 ms(){var Xe,Je,Ze,et,tt,st,at,rt,lt,nt;const{presets:N,loading:h,reload:T}=rs(),[y,ge]=r.useState([]),[m,ve]=r.useState(null),[Z,ee]=r.useState(!0),[B,j]=r.useState(null),[k,Te]=r.useState(null),[bt,te]=r.useState(!1),[P,se]=r.useState(null),[I,$]=r.useState(Ke),[Se,Ae]=r.useState(!1),[De,q]=r.useState(null),[n,ht]=r.useState(null),[ft,O]=r.useState(!1),[Me,V]=r.useState("select"),[v,E]=r.useState(null),[c,f]=r.useState(ls),[gt,S]=r.useState(""),[$e,Ee]=r.useState(!1),[Ue,A]=r.useState(null),[vt,ae]=r.useState(!1),[re,ze]=r.useState(!1),[Q,le]=r.useState(""),[Re,Le]=r.useState({}),[ye,Fe]=r.useState(!1),[_,G]=r.useState([]),[ne,D]=r.useState(new Set),[Be,U]=r.useState(null),[oe,ce]=r.useState(""),[je,Oe]=r.useState(!1),[de,M]=r.useState(null),z=r.useCallback(async()=>{try{const e=await p.config.provider.get();e.success&&e.data&&ht(e.data)}catch{}},[]),b=r.useCallback(async()=>{ee(!0),j(null);try{const[e,s]=await Promise.all([p.models.list(),p.system.status()]);if(await z(),e.success&&e.data&&Array.isArray(e.data.models)&&ge(e.data.models),s.success&&s.data){const a=s.data.models||{total:0,online:0,offline:0};ve({overallStatus:a.offline===0?"healthy":a.online>0?"degraded":"unhealthy",healthRate:a.total>0?a.online/a.total:0,healthyInstances:a.online,totalInstances:a.total,totalRequests:0})}}catch{j("加载模型失败")}finally{ee(!1)}},[z]);r.useEffect(()=>{b()},[b]),r.useEffect(()=>{const e=()=>{b(),z()};return window.addEventListener("models-updated",e),()=>window.removeEventListener("models-updated",e)},[b,z]);const R=r.useCallback(e=>`${e.provider}:${e.id}`,[]),yt=r.useCallback(e=>Re[R(e)]||{inputTokens:0,outputTokens:0},[R,Re]),_e=r.useCallback((e,s,a)=>{const l=R(e);Le(u=>{var o,d;return{...u,[l]:{inputTokens:s==="inputTokens"?a:((o=u[l])==null?void 0:o.inputTokens)||0,outputTokens:s==="outputTokens"?a:((d=u[l])==null?void 0:d.outputTokens)||0}}})},[R]),jt=r.useCallback(e=>{Le(s=>({...s,[R(e)]:{inputTokens:0,outputTokens:0}}))},[R]),L=r.useMemo(()=>{const e=[...N];return e.find(s=>s.key==="custom")||e.push({key:"custom",name:"Custom",baseUrl:"",apiType:"openai-completions",defaultModel:"",isCustom:!0}),e},[N]),ie=r.useMemo(()=>[...L].sort((e,s)=>{if(e.isCustom)return-1;if(s.isCustom)return 1;const a=pt[e.key],l=pt[s.key];return a!==void 0&&l!==void 0?a-l:a!==void 0?-1:l!==void 0?1:e.name.localeCompare(s.name)}),[L]),Ge=r.useMemo(()=>{const e=Q.trim().toLowerCase();return e?ie.filter(s=>s.name.toLowerCase().includes(e)||s.key.toLowerCase().includes(e)||(s.defaultModel||"").toLowerCase().includes(e)||(s.baseUrl||"").toLowerCase().includes(e)||(s.models||[]).some(a=>String(a).toLowerCase().includes(e))):ie},[ie,Q]),K=r.useMemo(()=>{var l,u,o,d;const e=(n==null?void 0:n.providers)||{},s=new Set(L.map(i=>i.key)),a=Object.entries(e).filter(([i])=>!s.has(i));if(a.length!==0)return{keys:a.map(([i])=>i),modelCount:a.reduce((i,[,C])=>i+(C.modelCount||0),0),hasApiKey:a.some(([,i])=>i.hasApiKey),baseUrl:((u=(l=a.find(([,i])=>i.baseUrl))==null?void 0:l[1])==null?void 0:u.baseUrl)||"",apiType:((d=(o=a.find(([,i])=>i.apiType))==null?void 0:o[1])==null?void 0:d.apiType)||"openai-completions"}},[n,L]),He=r.useCallback(e=>{var o,d;const s=(o=n==null?void 0:n.providers)==null?void 0:o[e.key],a=y.filter(i=>i.provider===e.key).map(i=>i.id),l=((d=e.models)==null?void 0:d.slice(0,3).join(", "))||e.defaultModel,u=a.length>0?a.join(", "):l;E(e.key),S(""),f({providerKey:e.key,apiKeys:"",modelIds:u,baseUrl:(s==null?void 0:s.baseUrl)||e.baseUrl,apiType:(s==null?void 0:s.apiType)||e.apiType,fullPath:(s==null?void 0:s.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==e.key}),V("form"),O(!0),A(null),ae(!1),G([]),D(new Set),U(null),ce("")},[y,n]),kt=r.useCallback(e=>{var l;const s=(l=n==null?void 0:n.providers)==null?void 0:l[e],a=y.filter(u=>u.provider===e).map(u=>u.id).join(", ");E("custom"),S(e),f({providerKey:e,apiKeys:"",modelIds:a,baseUrl:(s==null?void 0:s.baseUrl)||"",apiType:(s==null?void 0:s.apiType)||"",fullPath:(s==null?void 0:s.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==e}),A(null),ae(!1),G([]),D(new Set),U(null),ce("")},[n,y]),ke=r.useCallback(()=>{E("custom"),S(""),f({providerKey:"",apiKeys:"",modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!(n!=null&&n.configured)}),V("form"),O(!0),A(null),ae(!1),G([]),D(new Set),U(null),ce("")},[n]),Nt=r.useCallback(async()=>{var s;const e=c.baseUrl;if(!e){U("请先填写 Base URL");return}Fe(!0),U(null),G([]),D(new Set);try{const a=(c.apiKeys||"").split(/\r?\n|,/).map(o=>o.trim()).filter(Boolean)[0]||"",l=a.replace(/[^\x00-\xFF]/g,"");l!==a&&w.warning("API Key 包含非法字符,已自动过滤");const u=await p.models.fetch(e,l,c.fullPath===!0);if(u.success&&((s=u.data)!=null&&s.models)){const o=u.data.models;G(o);const d=new Set(o.map(g=>g.id)),i=c.modelIds.split(",").map(g=>g.trim()).filter(Boolean),C=i.filter(g=>d.has(g.split("|")[0].trim())),F=i.filter(g=>!d.has(g.split("|")[0].trim()));if(D(new Set(C.map(g=>g.split("|")[0].trim()))),F.length>0){const g=F.map(Y=>Y.split("|")[0].trim());f(Y=>({...Y,modelIds:C.join(", ")})),w.warning(`已自动移除服务端不存在的模型:${g.join(", ")}`)}w.success(`获取到 ${o.length} 个模型`)}else U(u.error||"获取模型列表失败,请检查 Base URL 和 API Key")}catch(a){U(a instanceof Error?a.message:"请求失败")}finally{Fe(!1)}},[c.baseUrl,c.apiKeys,c.modelIds]),wt=r.useCallback(async()=>{var s,a;const e=c.baseUrl;if(!e){M({ok:!1,message:"请先填写 Base URL"});return}Oe(!0),M(null);try{const l=(c.apiKeys||"").split(/\r?\n|,/).map(d=>d.trim()).filter(Boolean)[0]||"",u=l.replace(/[^\x00-\xFF]/g,"");u!==l&&w.warning("API Key 包含非法字符,已自动过滤");const o=await p.providers.testConnection(e,u);if(o.success&&((s=o.data)!=null&&s.reachable)){const d=o.data,i={};d.resolvedBaseUrl&&d.resolvedBaseUrl!==c.baseUrl&&(i.baseUrl=d.resolvedBaseUrl),d.detectedApiType&&c.apiType===""&&(i.apiType=d.detectedApiType),Object.keys(i).length>0&&f(F=>({...F,...i}));const C=[];i.baseUrl&&C.push(`Base URL 已自动补全为 ${i.baseUrl}`),i.apiType&&C.push(`API 类型已自动选择为 ${xt[i.apiType]}`),M({ok:!0,message:C.length>0?`${d.message||"连接成功"}。${C.join(";")}。`:d.message||"连接成功"})}else M({ok:!1,message:((a=o.data)==null?void 0:a.message)||o.error||"连接失败"})}catch(l){M({ok:!1,message:l instanceof Error?l.message:"请求失败"})}finally{Oe(!1)}},[c.baseUrl,c.apiKeys,c.apiType]),Ct=r.useCallback(e=>{const s=new Set(ne);s.has(e)?s.delete(e):s.add(e),D(s),f(a=>({...a,modelIds:Array.from(s).join(", ")}))},[ne]),[Pt,Ye]=r.useState(!1),[Ne,qe]=r.useState(""),[Ve,ue]=r.useState([]),[It,Qe]=r.useState(!1),[We,xe]=r.useState(null),[pe,Kt]=r.useState(!1),[me,Tt]=r.useState(!0),St=r.useCallback(()=>{qe(""),ue([]),xe(null),Ye(!0),W("",{reason:!1,tool:!0})},[]),W=r.useCallback(async(e,s)=>{Qe(!0),xe(null);try{const a=await p.models.catalogSearch({q:e,reasoning:(s==null?void 0:s.reason)??!1,toolCall:(s==null?void 0:s.tool)??!0,limit:30});a.success&&a.data?ue(a.data.hits||[]):(xe(a.error||"目录搜索失败"),ue([]))}catch(a){xe(a instanceof Error?a.message:"请求失败"),ue([])}finally{Qe(!1)}},[]),At=r.useCallback(e=>{f(s=>{const a=s.modelIds.split(",").map(l=>l.trim()).filter(Boolean);return a.includes(e.model.id)?s:{...s,modelIds:[...a,e.model.id].join(", ")}}),w.success(`已添加 ${e.model.id}`)},[]),[we,Dt]=r.useState(null),Mt=r.useCallback(e=>{qe(e),we&&clearTimeout(we),Dt(setTimeout(()=>{W(e,{reason:pe,tool:me})},300))},[we,pe,me,W]),$t=async e=>{const s=y.find(o=>o.id===e);if(!s)return;const a=s.enabled!==!1,l=s.name||e,u=o=>a&&/default model/i.test(o);try{const o=await p.models.toggle(s.provider,e);if(o.success){await b();return}const d=o.error||"";u(d)?w.error(`“${l}” 是默认模型,无法直接禁用。请先在「Provider 配置」中更换默认模型,再进行禁用。`):w.error(d||"操作失败,请重试")}catch(o){const d=o instanceof Error?o.message:"";u(d)?w.error(`“${l}” 是默认模型,无法直接禁用。请先在「Provider 配置」中更换默认模型,再进行禁用。`):w.error(d||"操作失败,请重试")}},Et=async e=>{Te(e);try{await p.models.test(e),await b()}finally{Te(null)}},Ut=async(e,s)=>{if(confirm(`确定要删除模型 "${s}" 吗?此操作不可撤销。`))try{(await p.models.delete(e,s)).success&&await b()}catch{}},zt=e=>{se({provider:e.provider,modelId:e.id}),$({provider:e.provider,modelId:e.id,modelName:e.name,apiKey:""}),q(null),te(!0)},Rt=async()=>{var Y,ot;const e=L.find(x=>x.key===v)||null,s=v==="custom"?c.providerKey.trim():(e==null?void 0:e.key)||"";if(!s){A("请先输入 Provider 名称");return}const a=(c.apiKeys||"").split(/\r?\n|,/).map(x=>x.trim()).filter(Boolean),l=!!((ot=(Y=n==null?void 0:n.providers)==null?void 0:Y[s])!=null&&ot.hasApiKey);if(a.length===0&&!l){A("请至少输入一把 API Key");return}const u=e||{baseUrl:"",apiType:"openai-completions",defaultModel:""},o=a.map(x=>x.replace(/[^\x00-\xFF]/g,"")).filter(Boolean),d=_.length>0?new Set(_.map(x=>x.id)):null,i=(c.modelIds||u.defaultModel||"").split(",").map(x=>x.trim()).filter(Boolean),C=d?i.filter(x=>d.has(x.split("|")[0].trim())):i,F=d?i.filter(x=>!d.has(x.split("|")[0].trim())):[];F.length>0&&w.warning(`已自动跳过服务端不存在的模型:${F.map(x=>x.split("|")[0].trim()).join(", ")}`);const g={provider:s,name:s,baseUrl:c.baseUrl||u.baseUrl,fullPath:c.fullPath===!0,apiType:c.apiType||os(c.baseUrl||u.baseUrl)||u.apiType,models:C.map((x,_t)=>{const be=x.trim().split("|").map(Gt=>Gt.trim()).filter(Boolean),ct=be[0]||"";return{id:ct,name:be[1]||ct,aliases:be.length>2?be.slice(2):void 0,enabled:!0,priority:10+_t}}).filter(x=>x.id.length>0)};o.length>0&&(g.apiKeys=o),(!(n!=null&&n.configured)||c.setDefault)&&(g.setDefault=!0),Ee(!0),A(null);try{const x=await p.config.provider.save(g);x.success?(O(!1),V("select"),E(null),S(""),await z(),await b()):A(x.error||"保存失败")}catch(x){A(x instanceof Error?x.message:"未知错误")}finally{Ee(!1)}},Lt=async e=>{if(confirm(`确定要移除 "${e}" 的配置吗?这将删除其 API Key 和模型。`))try{await p.config.provider.delete(e),await z(),await b()}catch{}},Ft=async()=>{if(P){if(!I.provider.trim()||!I.modelId.trim()){q("提供商名称和模型 ID 不能为空");return}Ae(!0),q(null);try{const e={name:I.modelName.trim()||I.modelId.trim(),...I.apiKey.trim()?{apiKey:I.apiKey.trim()}:{}},s=await p.models.update(P.provider,P.modelId,{model:e});s.success?(te(!1),se(null),$(Ke),await b()):q(s.error||"保存失败")}catch(e){q(e instanceof Error?e.message:"未知错误")}finally{Ae(!1)}}},Bt=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"}},Ot=e=>{switch(e){case"online":return t.jsx(ss,{size:14});case"offline":return t.jsx(ut,{size:14});case"error":return t.jsx(ts,{size:14});default:return t.jsx(ut,{size:14})}},H=r.useMemo(()=>L.find(e=>e.key===v)||null,[v,L]);return Z?t.jsx("div",{className:"flex h-64 items-center justify-center text-dark-muted",children:"加载中..."}):B?t.jsx("div",{className:"flex h-64 items-center justify-center text-accent-red",children:B}):t.jsxs("div",{className:"p-6 space-y-6 flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("h2",{className:"text-base font-semibold",children:"Provider 配置"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("button",{onClick:async()=>{try{await p.providers.refresh(),w.success("Provider 列表已刷新"),ze(!0),await T(),setTimeout(()=>{T()},3e3)}catch{w.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(X,{size:12}),"刷新列表"]}),t.jsxs("button",{onClick:()=>{re&&le(""),ze(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:[re?t.jsx(Ht,{size:12}):t.jsx(Ce,{size:12}),re?"收起":"新增 Provider"]})]})]}),re&&t.jsxs("div",{children:[t.jsxs("div",{className:"relative mb-3 max-w-md",children:[t.jsx(J,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted"}),t.jsx("input",{value:Q,onChange:e=>le(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 名称 / 模型..."}),Q&&t.jsx("button",{onClick:()=>le(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-white",title:"清除","aria-label":"清除搜索",children:t.jsx(dt,{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:h?t.jsxs("div",{className:"col-span-full flex items-center justify-center py-4 text-dark-muted text-sm",children:[t.jsx(Yt,{size:14,className:"mr-2 animate-spin"}),"加载 Provider 列表..."]}):Ge.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:["没有与「",Q,"」匹配的 Provider,请检查拼写或改用完整列表"]}),t.jsxs("div",{className:"flex items-center justify-center gap-2",children:[t.jsxs("button",{onClick:()=>le(""),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(dt,{size:12}),"清除搜索"]}),t.jsxs("button",{onClick:ke,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"]})]})]}):Ge.map(e=>{var o,d;const s=e.key==="custom",a=s?K:(o=n==null?void 0:n.providers)==null?void 0:o[e.key],l=a==null?void 0:a.hasApiKey,u=s?!!(n!=null&&n.defaultProvider)&&((K==null?void 0:K.keys)||[]).includes(n.defaultProvider):(n==null?void 0:n.defaultProvider)===e.key;return t.jsxs("div",{className:`text-left p-3 rounded-lg border transition-colors relative ${l?"border-accent-green/30 bg-dark-surface hover:border-accent-green/50":"border-dark-border bg-dark-surface hover:border-dark-hover"}`,children:[t.jsxs("div",{onClick:()=>e.key==="custom"?ke():He(e),className:"cursor-pointer",children:[t.jsxs("div",{className:"flex items-center justify-between mb-1",children:[t.jsx("span",{className:"text-sm font-medium",children:e.name}),l&&t.jsx(Pe,{size:14,className:"text-accent-green"})]}),t.jsxs("div",{className:"text-[10px] text-dark-muted space-y-0.5",children:[t.jsx("div",{className:"truncate",children:s?(a==null?void 0:a.baseUrl)||"自定义地址":e.baseUrl||"自定义地址"}),t.jsx("div",{className:"truncate",children:s&&K?`${K.keys.join(", ")}`:e.defaultModel||"无默认模型"}),t.jsxs("div",{children:[a?`${a.modelCount} 已配置`:`${((d=e.models)==null?void 0:d.length)||0} 可用`,e.models&&e.models.length>0&&!a&&t.jsx("span",{className:"text-accent-blue",children:" ✓"})]})]}),u&&t.jsx("div",{className:"mt-1 text-[10px] text-accent-blue",children:"默认 Provider"})]}),l&&e.key!=="custom"&&t.jsx("button",{onClick:i=>{i.stopPropagation(),Lt(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(it,{size:13})})]},e.key)})})]})]}),m&&t.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[t.jsx(he,{title:"总体状态",value:m.totalInstances===0?"未配置":m.overallStatus==="healthy"?"健康":m.overallStatus==="degraded"?"降级":"异常",color:m.totalInstances===0?"blue":m.overallStatus==="healthy"?"green":m.overallStatus==="degraded"?"yellow":"red"}),t.jsx(he,{title:"健康率",value:m.totalInstances===0?"N/A":`${(m.healthRate*100).toFixed(0)}%`,color:m.totalInstances===0?"blue":m.healthRate>.8?"green":m.healthRate>.5?"yellow":"red"}),t.jsx(he,{title:"在线实例",value:m.totalInstances===0?"无":`${m.healthyInstances}/${m.totalInstances}`,color:m.healthyInstances>0?"green":"red"}),t.jsx(he,{title:"总请求数",value:m.totalRequests>0?m.totalRequests.toLocaleString():"0",color:"blue"})]}),t.jsxs("div",{children:[t.jsx("div",{className:"flex items-center justify-between mb-3",children:t.jsx("h3",{className:"text-sm font-medium",children:"已配置模型"})}),t.jsxs("div",{className:"space-y-2 max-h-[480px] overflow-y-auto custom-scrollbar pr-1",children:[y.map(e=>{const s=yt(e),a=s.inputTokens+s.outputTokens;return t.jsx("div",{className:`bg-dark-surface border rounded-lg p-3 ${e.status==="online"?"border-accent-green":"border-dark-border opacity-70"}`,children:t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[t.jsx("span",{className:Bt(e.status),children:Ot(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(fe,{label:"负载",value:`${e.load}/${e.maxLoad}`}),t.jsx(fe,{label:"Token",value:`${e.tokens}/${e.maxTokens}`}),t.jsx(fe,{label:"输入价格",value:`$${e.price.input}/1K`}),t.jsx(fe,{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(mt,{label:"输入 token",value:s.inputTokens,onChange:l=>_e(e,"inputTokens",l)}),t.jsx(mt,{label:"输出 token",value:s.outputTokens,onChange:l=>_e(e,"outputTokens",l)}),t.jsxs("div",{children:[t.jsx("div",{className:"text-[11px] text-dark-muted mb-1",children:"总 token"}),t.jsx("div",{className:"px-3 py-2 rounded border border-dark-border bg-dark-bg text-sm font-mono",children:a.toLocaleString()})]}),t.jsxs("button",{onClick:()=>jt(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(qt,{size:13}),"重置"]})]})]}),t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[!e.isGlobalDefault&&e.enabled!==!1&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({global:`${e.provider}:${e.id}`}),await b()}catch(l){j(l instanceof Error?l.message:"设置全局默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-accent-green/30 text-accent-green hover:bg-accent-green/10",title:"设为全局默认",children:"全局默认"}),!e.isPlanDefault&&e.enabled!==!1&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({plan:`${e.provider}:${e.id}`}),await b()}catch(l){j(l instanceof Error?l.message:"设置 Plan 默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-accent-blue/30 text-accent-blue hover:bg-accent-blue/10",title:"设为 Plan 默认",children:"Plan 默认"}),e.isPlanDefault&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({plan:null}),await b()}catch(l){j(l instanceof Error?l.message:"取消 Plan 默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:bg-dark-hover",title:"取消 Plan 默认(该模式回退到全局默认)",children:"取消 Plan 默认"}),!e.isActDefault&&e.enabled!==!1&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({act:`${e.provider}:${e.id}`}),await b()}catch(l){j(l instanceof Error?l.message:"设置 Act 默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-accent-yellow/30 text-accent-yellow hover:bg-accent-yellow/10",title:"设为 Act 默认",children:"Act 默认"}),e.isActDefault&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({act:null}),await b()}catch(l){j(l instanceof Error?l.message:"取消 Act 默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:bg-dark-hover",title:"取消 Act 默认(该模式回退到全局默认)",children:"取消 Act 默认"}),!e.isGoalDefault&&e.enabled!==!1&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({goal:`${e.provider}:${e.id}`}),await b()}catch(l){j(l instanceof Error?l.message:"设置 Goal 默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-accent-purple/30 text-accent-purple hover:bg-accent-purple/10",title:"设为 Goal 默认",children:"Goal 默认"}),e.isGoalDefault&&t.jsx("button",{onClick:async()=>{try{await p.models.setDefaults({goal:null}),await b()}catch(l){j(l instanceof Error?l.message:"取消 Goal 默认失败")}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:bg-dark-hover",title:"取消 Goal 默认(该模式回退到全局默认)",children:"取消 Goal 默认"}),t.jsx("button",{onClick:()=>zt(e),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:"编辑模型",children:t.jsx(Vt,{size:13})}),t.jsx("button",{onClick:()=>Ut(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(it,{size:13})}),t.jsx("button",{onClick:()=>Et(e.id),disabled:k===e.id,className:"p-1.5 rounded hover:bg-dark-hover disabled:opacity-50",title:"刷新",children:t.jsx(X,{size:13,className:k===e.id?"animate-spin":""})}),t.jsx("button",{onClick:()=>$t(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"?"禁用":"启用"})]})]})},R(e))}),y.length===0&&t.jsxs("div",{className:"text-center text-dark-muted py-6",children:[t.jsx(Qt,{size:36,className:"mx-auto mb-2 opacity-40"}),t.jsx("p",{className:"text-sm",children:"暂无模型,请先在上方配置 Provider"})]})]})]}),t.jsx(Ie,{isOpen:ft,onClose:()=>{O(!1),V("select"),E(null),S("")},title:Me==="select"?"选择 Provider":(H==null?void 0:H.name)||"Provider 配置",size:"xl",children:Me==="select"?t.jsx("div",{className:"space-y-4",children:t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[ie.filter(e=>e.key!=="custom").map(e=>t.jsxs("button",{onClick:()=>He(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(Pe,{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:ke,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(Wt,{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:[v==="custom"&&t.jsxs("div",{className:"space-y-3",children:[K&&K.keys.length>0&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"编辑已有配置(可选)"}),t.jsxs("select",{value:gt,onChange:e=>{const s=e.target.value;s?kt(s):(S(""),f(a=>({...a,providerKey:"",modelIds:"",baseUrl:"",apiType:"",apiKeys:""})))},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",children:[t.jsx("option",{value:"",children:"+ 新建自定义 Provider"}),K.keys.map(e=>t.jsx("option",{value:e,children:e},e))]}),t.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:"默认新建空表单;选择已保存的配置可回填继续编辑(API Key 不回显,留空保存即保留原 Key)。"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"Provider 名称 *"}),t.jsx("input",{value:c.providerKey,onChange:e=>f(s=>({...s,providerKey:e.target.value})),className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:"例如: my-provider"})]})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:["API Keys",(Je=(Xe=n==null?void 0:n.providers)==null?void 0:Xe[v==="custom"?c.providerKey.trim():v||""])!=null&&Je.hasApiKey?"":" *",t.jsxs("span",{className:"text-dark-muted/60 text-xs",children:["(每行一把,可多把",(et=(Ze=n==null?void 0:n.providers)==null?void 0:Ze[v==="custom"?c.providerKey.trim():v||""])!=null&&et.hasApiKey?",留空则保留已保存的 Key":"",")"]})]}),t.jsxs("div",{className:"relative",children:[t.jsx("textarea",{rows:3,value:c.apiKeys,onChange:e=>f(s=>({...s,apiKeys:e.target.value})),className:"w-full px-3 py-2 pr-10 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue resize-y custom-scrollbar",placeholder:`每行输入一把 API Key
|
|
2
|
-
支持多把(运行时取第一把,其余备用)`}),t.jsx("button",{onClick:()=>ae(e=>!e),className:"absolute right-2 top-2 text-dark-muted hover:text-white",children:vt?t.jsx(Xt,{size:14}):t.jsx(Jt,{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:c.modelIds,onChange:e=>{const s=e.target.value;f(a=>({...a,modelIds:s})),D(()=>{const a=new Set;for(const l of s.split(",")){const u=l.trim().split("|")[0].trim();u&&_.some(o=>o.id===u)&&a.add(u)}return a})},className:"flex-1 px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:(H==null?void 0:H.defaultModel)||"gpt-4o, deepseek-chat (格式: id|名称|别名)"}),t.jsxs("button",{onClick:Nt,disabled:ye||!c.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:[ye?t.jsx(X,{size:13,className:"animate-spin"}):t.jsx(Zt,{size:13}),ye?"获取中...":"获取模型列表"]}),t.jsxs("button",{onClick:wt,disabled:je||!c.baseUrl,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-yellow/30 text-accent-yellow hover:bg-accent-yellow/10 disabled:opacity-50 whitespace-nowrap",title:"探测端点连通性,自动推断 API 类型并修复 Base URL",children:[je?t.jsx(X,{size:13,className:"animate-spin"}):t.jsx(es,{size:13}),je?"测试中...":"测试连接"]}),t.jsxs("button",{onClick:St,className:"inline-flex items-center gap-1 px-3 py-2 rounded text-sm border border-accent-green/30 text-accent-green hover:bg-accent-green/10 whitespace-nowrap",title:"搜索 models.dev 全厂商模型目录(含 context/价格/能力元数据)",children:[t.jsx(J,{size:13}),"目录搜索"]})]}),de&&t.jsxs("div",{className:`mt-1 text-xs ${de.ok?"text-accent-green":"text-accent-red"}`,children:[de.ok?"✓ ":"✗ ",de.message]}),Be&&t.jsx("div",{className:"mt-1 text-xs text-accent-red",children:Be}),_.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:_.length})," 个模型, 已选 ",t.jsx("strong",{className:"text-accent-blue",children:ne.size})," 个",t.jsx("span",{className:"text-accent-blue/70",children:"(勾选即自动应用到「模型 ID」输入框)"})]}),t.jsx("button",{onClick:()=>{G([]),D(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(J,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),t.jsx("input",{value:oe,onChange:e=>ce(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:_.filter(e=>!oe||e.id.toLowerCase().includes(oe.toLowerCase())||e.name.toLowerCase().includes(oe.toLowerCase())).map(e=>{const s=ne.has(e.id);return t.jsxs("div",{role:"checkbox","aria-checked":s,tabIndex:-1,onMouseDown:a=>a.preventDefault(),onClick:()=>Ct(e.id),className:`flex items-center gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${s?"bg-accent-blue/20 text-accent-blue border border-accent-blue/30":"hover:bg-dark-hover border border-transparent"}`,children:[s?t.jsx(Pe,{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:c.baseUrl,onChange:e=>{f(s=>({...s,baseUrl:e.target.value})),M(null)},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:"https://api.example.com/v1"}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none mt-2",children:[t.jsx("button",{type:"button",role:"switch","aria-checked":c.fullPath,onClick:()=>{f(e=>({...e,fullPath:!e.fullPath})),M(null)},className:`relative w-9 h-5 rounded-full transition-colors shrink-0 ${c.fullPath?"bg-accent-green":"bg-dark-border"}`,children:t.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${c.fullPath?"translate-x-[18px]":"translate-x-0.5"}`})}),t.jsx("span",{className:"text-sm text-dark-muted",children:"完整路径(不自动拼接 /chat/completions、/responses、/v1/messages)"})]}),t.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:"开启后 Base URL 按原样使用(如 https://host/v1/chat/completions),后端不再转换。"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"API 类型"}),t.jsxs("select",{value:c.apiType,onChange:e=>{f(s=>({...s,apiType:e.target.value})),M(null)},className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",children:[t.jsx("option",{value:"",children:"自动探测(推荐)"}),ns.map(e=>t.jsx("option",{value:e,children:xt[e]},e))]}),t.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:"默认 OpenAI 兼容;Anthropic/Claude 类网关(URL 含 /anthropic、/coding)自动切 Anthropic Messages。"})]}),t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:c.setDefault,onChange:e=>f(s=>({...s,setDefault:e.target.checked})),className:"accent-accent-blue"}),t.jsx("span",{className:"text-sm text-dark-muted",children:"设为默认 Provider"})]}),Ue&&t.jsx("div",{className:"text-sm text-accent-red",children:Ue}),t.jsxs("div",{className:"flex justify-between gap-2 pt-2",children:[t.jsx("div",{children:v&&v!=="custom"&&((st=(tt=n==null?void 0:n.providers)==null?void 0:tt[v])==null?void 0:st.hasApiKey)&&t.jsx("button",{onClick:async()=>{if(confirm(`确定要删除 "${v}" 的配置吗?`))try{await p.config.provider.delete(v),O(!1),E(null),S(""),await z(),await b()}catch{}},className:"px-4 py-2 rounded border border-accent-red/30 text-accent-red hover:bg-accent-red/10 transition-colors text-sm",children:"删除 Provider"})}),t.jsx("button",{onClick:()=>{V("select"),E(null),S(""),O(!1)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:"取消"}),t.jsx("button",{onClick:Rt,disabled:$e,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:$e?"保存中...":"保存"})]})]})}),t.jsx(Ie,{isOpen:Pt,onClose:()=>Ye(!1),title:t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx(J,{size:15,className:"text-accent-green"}),"models.dev 模型目录搜索"]}),size:"2xl",children:t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("div",{className:"relative flex-1",children:[t.jsx(J,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),t.jsx("input",{value:Ne,onChange:e=>Mt(e.target.value),className:"w-full pl-9 pr-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-green",placeholder:"搜索全厂商模型,如 gpt-4o / deepseek / claude ...(匹配模型 id / 名称 / 厂商)",autoFocus:!0})]}),t.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:me,onChange:e=>{const s=e.target.checked;Tt(s),W(Ne,{reason:pe,tool:s})},className:"accent-accent-green"}),"仅工具调用"]}),t.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[t.jsx("input",{type:"checkbox",checked:pe,onChange:e=>{const s=e.target.checked;Kt(s),W(Ne,{reason:s,tool:me})},className:"accent-accent-green"}),"仅推理模型"]})]}),We&&t.jsx("div",{className:"text-xs text-accent-red bg-accent-red/10 p-2 rounded",children:We}),It?t.jsxs("div",{className:"flex items-center justify-center py-10 text-dark-muted",children:[t.jsx(X,{size:18,className:"animate-spin mr-2"})," 搜索中..."]}):t.jsx("div",{className:"max-h-96 overflow-y-auto custom-scrollbar border border-dark-border rounded-lg divide-y divide-dark-border",children:Ve.length===0?t.jsx("div",{className:"py-10 text-center text-dark-muted text-sm",children:"无匹配模型,换个关键词试试"}):Ve.map(e=>{var s,a,l;return t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 hover:bg-dark-hover",children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm font-medium text-dark-text truncate",children:e.model.name||e.model.id}),t.jsx("code",{className:"text-[10px] px-1.5 py-0.5 bg-dark-bg border border-dark-border rounded text-dark-muted truncate",children:e.model.id}),e.model.reasoning&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-yellow/10 text-accent-yellow rounded",children:"推理"}),e.model.tool_call&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-blue/10 text-accent-blue rounded",children:"工具"}),e.model.attachment&&t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-green/10 text-accent-green rounded",children:"多模态"})]}),t.jsxs("div",{className:"text-[11px] text-dark-muted mt-0.5",children:[e.providerName,(s=e.model.limit)!=null&&s.context?` · 上下文 ${(e.model.limit.context/1e3).toFixed(0)}K`:"",(a=e.model.limit)!=null&&a.output?` · 输出 ${(e.model.limit.output/1e3).toFixed(0)}K`:"",((l=e.model.cost)==null?void 0:l.input)!==void 0?` · $${e.model.cost.input}/M in / $${e.model.cost.output}/M out`:""]})]}),t.jsxs("button",{onClick:()=>At(e),className:"shrink-0 inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-accent-green/30 text-accent-green rounded hover:bg-accent-green/10 whitespace-nowrap",title:"添加到模型 ID 输入框",children:[t.jsx(Ce,{size:12})," 添加"]})]},`${e.providerId}:${e.model.id}`)})}),t.jsx("div",{className:"text-[11px] text-dark-muted/60",children:"数据源:models.dev 模型目录(内置快照,离线可用)。点击「添加」将模型 ID 写入「模型 ID」输入框。"})]})}),t.jsx(Ie,{isOpen:bt,onClose:()=>{te(!1),se(null)},title:"编辑模型",size:"lg",children:t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"提供商名称 *"}),t.jsx("input",{value:I.provider,onChange:e=>$(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:I.modelId,onChange:e=>$(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:I.modelName,onChange:e=>$(s=>({...s,modelName:e.target.value})),className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:"留空则使用模型 ID"})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:["API Key",P&&((rt=(at=n==null?void 0:n.providers)==null?void 0:at[P.provider])==null?void 0:rt.hasApiKey)&&t.jsx("span",{className:"text-accent-green/80 text-xs ml-1",children:"已配置(留空则保持不变)"})]}),t.jsx("input",{type:"password",value:I.apiKey,onChange:e=>$(s=>({...s,apiKey:e.target.value})),className:"w-full px-3 py-2 bg-dark-bg border border-dark-border rounded text-sm focus:outline-none focus:border-accent-blue",placeholder:P&&((nt=(lt=n==null?void 0:n.providers)==null?void 0:lt[P.provider])!=null&&nt.hasApiKey)?"留空保持当前 API Key":"输入新的 API Key"})]}),De&&t.jsx("div",{className:"text-sm text-accent-red bg-accent-red/10 p-2 rounded",children:De}),t.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[t.jsx("button",{onClick:()=>{te(!1),se(null),$(Ke)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:"取消"}),t.jsx("button",{onClick:Ft,disabled:Se,className:"px-4 py-2 bg-accent-blue text-white rounded hover:bg-accent-blue/80 transition-colors text-sm disabled:opacity-50",children:Se?"保存中...":"保存"})]})]})})]})}function he({title:N,value:h,color:T}){const y={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:`${y[T]} rounded-lg p-3`,children:[t.jsx("div",{className:"text-xs opacity-70",children:N}),t.jsx("div",{className:"text-xl font-semibold",children:h})]})}function fe({label:N,value:h}){return t.jsxs("div",{children:[t.jsx("div",{className:"text-dark-muted",children:N}),t.jsx("div",{children:h})]})}function mt({label:N,value:h,onChange:T}){return t.jsxs("div",{children:[t.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:N}),t.jsx("input",{type:"number",min:"0",value:h,onChange:y=>T(parseInt(y.target.value,10)||0),className:"w-full px-3 py-2 rounded border border-dark-border bg-dark-bg text-sm focus:outline-none focus:border-accent-blue"})]})}export{ms as ModelsView,ms as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as t}from"./markdown-BrFQfawv.js";import{a,aj as me,h as pe,aa as he,X as J,_ as ge,aA as W,bd as ke,ba as ve,aq as fe,D as ee,y as je,K as ye}from"./icons-B9mi2ie6.js";import{c as Ne,g as b,C as Ce}from"./index-PcXINYWS.js";import"./react-vendor-CiRFOYk_.js";import"./state-BcoCffxz.js";import"./panels-BX-TtLOU.js";const I=12,we="other",Se=[{value:"all",label:"全部"},{value:"builtin",label:"内置"},{value:"openclaw",label:"openclaw"},{value:"deepseek-harness",label:"deepseek-harness"}];function $e(l){return l==="wired"?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":l==="pending"||l==="pending_wiring"?"bg-amber-500/15 text-amber-400 border-amber-500/30":"bg-dark-hover text-dark-muted border-dark-border"}function te(l){var d;return((d=l.category)==null?void 0:d.trim())||we}function Me(l,d){const f=d.trim().toLowerCase();return f?[l.id,l.name,l.description,l.category,...l.tags??[]].filter(S=>typeof S=="string").join(" ").toLowerCase().includes(f):!0}function Te(){const{t:l}=Ne(),[d,f]=a.useState("installed"),[m,S]=a.useState([]),[T,re]=a.useState([]),[L,ae]=a.useState(null),[j,F]=a.useState(!0),[$,O]=a.useState(null),[o,U]=a.useState(null),[M,_]=a.useState(null),[y,B]=a.useState(null),[N,P]=a.useState(null),[V,q]=a.useState(null),[p,D]=a.useState(""),[i,se]=a.useState(null),[c,le]=a.useState(null),[x,z]=a.useState(1),u=a.useCallback((e,r)=>{B({kind:e,text:r}),window.setTimeout(()=>B(null),4e3)},[]),h=a.useCallback(async()=>{F(!0),O(null);const[e,r]=await Promise.all([b.get("/api/plugins"),b.get("/api/plugins/market")]);e.success&&e.data?(S(e.data.plugins),ae(e.data.schemaVersion??null)):O(e.error??"Failed to load plugins"),r.success&&r.data&&re(r.data.plugins),F(!1)},[]);a.useEffect(()=>{h()},[h]);const A=a.useMemo(()=>m.filter(e=>e.installable!==!0),[m]),g=a.useMemo(()=>[...m.filter(e=>e.installable===!0),...T.filter(e=>!m.some(r=>r.id===e.id||r.marketId===e.id))],[m,T]),C=a.useCallback(e=>e.filter(r=>i&&te(r)!==i||c&&(r.market??null)!==c?!1:Me(r,p)),[i,p,c]),k=a.useMemo(()=>C(A),[C,A]),v=a.useMemo(()=>C(g),[C,g]),G=a.useMemo(()=>{const e=new Set;for(const r of g)e.add(te(r));return["all",...Array.from(e).sort()]},[g]),K=e=>Math.max(1,Math.ceil(e/I)),H=(e,r)=>e.slice((r-1)*I,r*I),E=K(k.length),R=K(v.length),de=a.useMemo(()=>H(k,Math.min(x,E)),[k,x,E]),ne=a.useMemo(()=>H(v,Math.min(x,R)),[v,x,R]);a.useEffect(()=>{z(1)},[d,p,i,c]);const oe=p.trim().length>0||i!==null||c!==null,w=a.useCallback(async(e,r,n)=>{U(e),_(r);try{const s=await n();s&&s.success===!1?u("err",String(s.error??"Request failed")):(u("ok",`${r} ${e} ✓`),await h())}catch(s){u("err",s instanceof Error?s.message:String(s))}finally{U(null),_(null)}},[h,u]),Q=(e,r)=>w(e,r?"installed+activated":"installed",()=>b.post("/api/plugins/install",{id:e,activate:r})),ie=e=>w(e,"activated",()=>b.post(`/api/plugins/${encodeURIComponent(e)}/activate`)),ce=e=>w(e,"deactivated",()=>b.post(`/api/plugins/${encodeURIComponent(e)}/deactivate`)),xe=e=>w(e,"uninstalled",()=>b.delete(`/api/plugins/${encodeURIComponent(e)}`)),ue=async e=>{q(e);try{const r=await b.post(`/api/plugins/l2/provider/${encodeURIComponent(e)}`);r.success&&r.data?(u("ok",`Provider ${r.data.applied} applied to config ✓`),await h()):u("err",r.error??"Apply failed")}catch(r){u("err",r instanceof Error?r.message:String(r))}finally{q(null)}},X=e=>{const r=e==="bundled"?"bg-blue-500/15 text-blue-400 border-blue-500/30":e==="npm"?"bg-purple-500/15 text-purple-400 border-purple-500/30":e==="local"?"bg-cyan-500/15 text-cyan-400 border-cyan-500/30":"bg-dark-hover text-dark-muted border-dark-border";return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border ${r}`,children:e})},be=e=>{if(!e)return null;const r=e==="builtin"?"bg-dark-hover text-dark-muted border-dark-border":e==="openclaw"?"bg-amber-500/15 text-amber-400 border-amber-500/30":e==="deepseek-harness"?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":"bg-dark-hover text-dark-muted border-dark-border";return t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border ${r}`,children:e})},Y=(e,r)=>r>1?t.jsxs("div",{className:"flex items-center justify-center gap-3 pt-3 pb-1 select-none",children:[t.jsxs("button",{onClick:()=>z(n=>Math.max(1,n-1)),disabled:x<=1,className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border bg-dark-hover text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[t.jsx(je,{size:12})," 上一页"]}),t.jsxs("span",{className:"text-[11px] text-dark-muted",children:["第 ",Math.min(x,r)," / ",r," 页 · 共 ",e," 条"]}),t.jsxs("button",{onClick:()=>z(n=>Math.min(r,n+1)),disabled:x>=r,className:"flex items-center gap-1 px-2 py-1 rounded border border-dark-border bg-dark-hover text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:["下一页 ",t.jsx(ye,{size:12})]})]}):null,Z=e=>t.jsx("div",{className:"mt-8 text-center text-[12px] text-dark-muted",children:oe?"无匹配插件":e});return t.jsxs("div",{className:"h-full flex flex-col min-h-0 bg-dark-bg",children:[t.jsxs("div",{className:"h-11 flex items-center gap-2 px-3 border-b border-dark-border bg-dark-bg shrink-0 select-none",children:[t.jsx(me,{size:15,className:"text-accent-blue"}),t.jsx("span",{className:"truncate text-[13px] font-medium text-dark-text",children:l("nav.plugins")}),L!==null&&t.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-dark-hover text-dark-muted border border-dark-border",children:["schema v",L]}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:()=>void h(),className:"p-1.5 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text transition-colors",title:"Refresh",children:t.jsx(pe,{size:14,className:j?"animate-spin":""})})]}),t.jsx("div",{className:"flex items-center gap-1 px-3 pt-2 shrink-0",children:["installed","available"].map(e=>t.jsx("button",{onClick:()=>f(e),className:`px-3 py-1.5 rounded-t text-[12px] transition-colors ${d===e?"bg-dark-surface text-accent-blue border border-b-0 border-dark-border":"text-dark-muted hover:text-dark-text"}`,children:e==="installed"?`已安装 (${A.length})`:`可安装 (${g.length})`},e))}),t.jsxs("div",{className:"shrink-0 px-3 pt-2 pb-1 space-y-2 bg-dark-bg",children:[t.jsxs("div",{className:"relative",children:[t.jsx(he,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted pointer-events-none"}),t.jsx("input",{value:p,onChange:e=>D(e.target.value),placeholder:"搜索插件(名称 / id / 描述 / 标签)",className:"w-full pl-8 pr-8 py-1.5 rounded bg-dark-hover border border-dark-border text-[12px] text-dark-text placeholder-dark-muted outline-none focus:border-accent-blue/50 transition-colors"}),p&&t.jsx("button",{onClick:()=>D(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-dark-muted hover:text-dark-text transition-colors",title:"清除",children:t.jsx(J,{size:12})})]}),d==="available"&&G.length>2&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:G.map(e=>t.jsx("button",{onClick:()=>se(e==="all"?null:e),className:`px-2 py-0.5 rounded-full text-[11px] border transition-colors ${e==="all"&&i===null||i===e?"bg-accent-blue/20 text-accent-blue border-accent-blue/40":"bg-dark-hover text-dark-muted border-dark-border hover:text-dark-text"}`,children:e==="all"?"全部":e},e))}),d==="available"&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:Se.map(e=>t.jsx("button",{onClick:()=>le(e.value==="all"?null:e.value),className:`px-2 py-0.5 rounded-full text-[11px] border transition-colors ${e.value==="all"&&c===null||c===e.value?"bg-accent-blue/20 text-accent-blue border-accent-blue/40":"bg-dark-hover text-dark-muted border-dark-border hover:text-dark-text"}`,children:e.label},e.value))})]}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-3 pb-4",children:[$&&t.jsxs("div",{className:"mt-3 flex items-center gap-2 px-3 py-2 rounded bg-red-500/10 border border-red-500/30 text-red-400 text-[12px]",children:[t.jsx(ge,{size:14})," ",$]}),j&&!$&&t.jsx("div",{className:"mt-10 flex justify-center",children:t.jsx("div",{className:"w-5 h-5 border-2 border-accent-blue border-t-transparent rounded-full animate-spin"})}),!j&&d==="installed"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[k.length===0&&Z("暂无插件 — 到「可安装」页从市场安装"),de.map(e=>{const r=e.l2??[],n=e.status==="active";return t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-medium text-dark-text truncate",children:e.name||e.id}),e.version&&t.jsx("span",{className:"text-[11px] text-dark-muted shrink-0",children:e.version}),X(e.source),t.jsx("span",{className:`px-1.5 py-0.5 rounded text-[11px] border shrink-0 ${n?"bg-emerald-500/15 text-emerald-400 border-emerald-500/30":"bg-dark-hover text-dark-muted border-dark-border"}`,children:n?"active":"installed"}),e.httpMounted&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[11px] bg-emerald-500/15 text-emerald-400 border border-emerald-500/30 shrink-0",children:"http mounted"}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-[11px] text-dark-muted font-mono shrink-0",children:e.id})]}),e.description&&t.jsx("p",{className:"mt-1 text-[12px] text-dark-muted",children:e.description}),r.length>0&&t.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[r.map(s=>t.jsxs("span",{title:s.note||s.id,className:`px-1.5 py-0.5 rounded text-[11px] border cursor-help ${$e(s.status)}`,children:[s.kind," · ",s.status,s.status==="wired"&&t.jsx(W,{size:10,className:"inline ml-0.5"})]},`${s.kind}-${s.id}`)),r.filter(s=>s.kind==="provider"&&s.status==="wired").map(s=>t.jsx("button",{disabled:V===s.id,onClick:()=>void ue(s.id),className:"px-1.5 py-0.5 rounded text-[11px] border border-accent-blue/40 text-accent-blue hover:bg-accent-blue/10 disabled:opacity-50 transition-colors",title:"把插件 provider preset 写入 ProviderConfigStore(用户授权)",children:V===s.id?"applying…":"apply provider"},`apply-${s.id}`))]}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[n?t.jsxs("button",{onClick:()=>void ce(e.id),disabled:o===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-amber-500/15 border border-amber-500/30 text-amber-400 text-[11px] hover:bg-amber-500/25 disabled:opacity-50 transition-colors",children:[t.jsx(ke,{size:11})," ",o===e.id?`${M}…`:"停用"]}):t.jsxs("button",{onClick:()=>void ie(e.id),disabled:o===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-emerald-500/15 border border-emerald-500/30 text-emerald-400 text-[11px] hover:bg-emerald-500/25 disabled:opacity-50 transition-colors",children:[t.jsx(ve,{size:11})," ",o===e.id?`${M}…`:"激活"]}),t.jsxs("button",{onClick:()=>P(e.id),disabled:o===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-hover border border-dark-border text-dark-muted text-[11px] hover:text-red-400 hover:border-red-500/40 disabled:opacity-50 transition-colors",children:[t.jsx(fe,{size:11})," 卸载"]})]})]},e.id)}),Y(k.length,E)]}),!j&&d==="available"&&t.jsxs("div",{className:"mt-3 space-y-2",children:[v.length===0&&Z("市场暂无可用插件"),ne.map(e=>t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-medium text-dark-text truncate",children:e.name||e.id}),e.version&&t.jsx("span",{className:"text-[11px] text-dark-muted shrink-0",children:e.version}),X(e.source),be(e.market),e.category&&t.jsx("span",{className:"px-1.5 py-0.5 rounded text-[11px] bg-dark-hover text-dark-muted border border-dark-border shrink-0",children:e.category}),t.jsx("div",{className:"flex-1"}),t.jsx("span",{className:"text-[11px] text-dark-muted font-mono shrink-0",children:e.id})]}),e.description&&t.jsx("p",{className:"mt-1 text-[12px] text-dark-muted",children:e.description}),t.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[t.jsxs("button",{onClick:()=>void Q(e.id,!0),disabled:o===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-accent-blue/20 border border-accent-blue/40 text-accent-blue text-[11px] hover:bg-accent-blue/30 disabled:opacity-50 transition-colors",children:[t.jsx(ee,{size:11})," ",o===e.id?`${M}…`:"安装并激活"]}),t.jsxs("button",{onClick:()=>void Q(e.id,!1),disabled:o===e.id,className:"flex items-center gap-1 px-2 py-1 rounded bg-dark-hover border border-dark-border text-dark-muted text-[11px] hover:text-dark-text disabled:opacity-50 transition-colors",children:[t.jsx(ee,{size:11})," 仅安装"]})]})]},e.id)),Y(v.length,R)]})]}),y&&t.jsxs("div",{className:`fixed bottom-4 right-4 z-50 flex items-center gap-2 px-3 py-2 rounded-lg border text-[12px] shadow-lg ${y.kind==="ok"?"bg-emerald-500/15 border-emerald-500/30 text-emerald-400":"bg-red-500/15 border-red-500/30 text-red-400"}`,children:[y.kind==="ok"?t.jsx(W,{size:13}):t.jsx(J,{size:13})," ",y.text]}),t.jsx(Ce,{isOpen:N!==null,title:"卸载插件",message:`确定要卸载 ${N} 吗?插件文件将被删除(bundled 除外)。`,onConfirm:()=>{N&&xe(N),P(null)},onClose:()=>P(null)})]})}export{Te as PluginsView};
|