@deepseekcode/cli 1.0.10 → 1.0.12

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 (24) hide show
  1. package/dist/cli.js +702 -687
  2. package/package.json +2 -2
  3. package/web/dist/assets/{AgentFlowView-CRwXzsUU.js → AgentFlowView-BevVKfXk.js} +1 -1
  4. package/web/dist/assets/{AgentsView-CDY8XrTg.js → AgentsView-C6uUk-Ot.js} +1 -1
  5. package/web/dist/assets/{AskQuestionModal-CKt1m8Jo.js → AskQuestionModal-ydX_B4wI.js} +1 -1
  6. package/web/dist/assets/{AuditView-DbfHUxzt.js → AuditView-BzMImL6n.js} +1 -1
  7. package/web/dist/assets/{AutomationView-Cy1-vLAP.js → AutomationView-CUDpr7WY.js} +1 -1
  8. package/web/dist/assets/{ChannelConfigView-CprbcO4h.js → ChannelConfigView-DlRO4DS2.js} +1 -1
  9. package/web/dist/assets/{FileTreeView-CbGQmQay.js → FileTreeView-PejM6X2U.js} +1 -1
  10. package/web/dist/assets/{HookApprovalModal-DU0Gen9V.js → HookApprovalModal-BZrqAd9G.js} +1 -1
  11. package/web/dist/assets/{HookConfigView-bKFZ-DDV.js → HookConfigView-5pYKJRQk.js} +2 -2
  12. package/web/dist/assets/{InboxView-B5puastg.js → InboxView-72c5rEjQ.js} +1 -1
  13. package/web/dist/assets/{ModelsView-Df8fwn3X.js → ModelsView-CVg05tUX.js} +1 -1
  14. package/web/dist/assets/{SessionGrid-BPcnOjbx.js → SessionGrid-CHFCkdr0.js} +10 -10
  15. package/web/dist/assets/{SettingsPanel-CWlTCD1c.js → SettingsPanel-qg3WBeuf.js} +1 -1
  16. package/web/dist/assets/{SkillsView-m_a2rauP.js → SkillsView-C13I-2on.js} +1 -1
  17. package/web/dist/assets/{TerminalView-UaCcIjqn.js → TerminalView-BVRuIrII.js} +1 -1
  18. package/web/dist/assets/{ToolsView-DH4XhAov.js → ToolsView-_k5gi04A.js} +1 -1
  19. package/web/dist/assets/{hookRisk-BkOtQiAS.js → hookRisk-DHeJr1SL.js} +1 -1
  20. package/web/dist/assets/index-DuBeChMI.css +1 -0
  21. package/web/dist/assets/index-futMRNcm.js +21 -0
  22. package/web/dist/index.html +2 -2
  23. package/web/dist/assets/index-Bpfxw0Lr.js +0 -21
  24. package/web/dist/assets/index-xDhqs-ld.css +0 -1
@@ -1 +1 @@
1
- import{j as t}from"./markdown-BUScHEtT.js";import{r as c,J as m,p as f,o as j,at as k,X as v,aQ as N,aR as y,k as w}from"./icons-uody4X-4.js";import{v as C}from"./index-Bpfxw0Lr.js";import"./react-vendor-C5NlWs7r.js";import"./state-DKyBAq9j.js";function R(){const{items:i,pendingCount:x,fetchInbox:l,resolveInbox:d,loading:p,error:u}=C(),[r,g]=c.useState("pending");c.useEffect(()=>{l()},[l]);const o=c.useMemo(()=>i.filter(e=>r==="all"||e.state===r),[i,r]),h=e=>e.kind==="approval"?{label:"需要批准",icon:y,color:"text-accent-yellow"}:e.kind==="question"?{label:"需要回答",icon:w,color:"text-accent-blue"}:{label:"通知",icon:m,color:"text-dark-muted"},b=e=>{var n;if(e.kind!=="approval")return null;const a=((n=e.data)==null?void 0:n.payload)||{};for(const s of["target","recipient","channel","url"])if(typeof a[s]=="string"&&a[s])return a[s];for(const s of["path","filePath"])if(typeof a[s]=="string"&&a[s])return a[s];return null};return t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-4",children:[t.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[t.jsx(m,{size:20,className:"text-accent-blue"}),"Inbox",x>0&&t.jsxs("span",{className:"ml-1 px-2 py-0.5 rounded-full bg-accent-yellow/20 text-accent-yellow text-xs",children:[x," 待处理"]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"flex rounded-lg bg-dark-hover p-0.5 text-sm",children:["pending","resolved","all"].map(e=>t.jsx("button",{onClick:()=>g(e),className:`px-3 py-1 rounded-md transition-colors ${r===e?"bg-accent-blue/20 text-accent-blue":"text-dark-muted hover:text-dark-text"}`,children:e==="pending"?"待处理":e==="resolved"?"已解决":"全部"},e))}),t.jsx("button",{onClick:()=>void l(),className:"p-2 rounded-lg hover:bg-dark-hover text-dark-muted",title:"刷新",children:t.jsx(f,{size:16})})]})]}),u&&t.jsxs("div",{className:"mb-3 p-3 rounded-lg bg-accent-red/10 text-accent-red text-sm flex items-center gap-2",children:[t.jsx(j,{size:16})," ",u]}),t.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2",children:[p&&o.length===0&&t.jsx("p",{className:"text-dark-muted text-center py-8",children:"加载中..."}),!p&&o.length===0&&t.jsxs("p",{className:"text-dark-muted text-center py-8",children:["没有",r==="pending"?"待处理":"","事项"]}),o.map(e=>{const a=h(e),n=a.icon;return t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(n,{size:16,className:`${a.color} shrink-0`}),t.jsx("span",{className:"font-medium text-sm truncate",children:e.title}),t.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted shrink-0",children:e.kind})]}),t.jsx("span",{className:`text-xs shrink-0 ${e.state==="pending"?"text-accent-yellow":"text-accent-green"}`,children:e.state==="pending"?"pending":e.resolution||"resolved"})]}),e.body&&t.jsx("p",{className:"mt-1 text-xs text-dark-muted break-all",children:e.body}),e.data&&typeof e.data.toolName=="string"&&e.data.toolName&&t.jsxs("div",{className:"mt-2 p-2 rounded bg-dark-bg border border-dark-border",children:[t.jsxs("code",{className:"text-xs text-accent-blue",children:["工具: ",String(e.data.toolName)]}),typeof e.data.payload=="object"&&e.data.payload!==null&&t.jsx("pre",{className:"mt-1 text-[11px] text-dark-muted whitespace-pre-wrap max-h-24 overflow-y-auto",children:JSON.stringify(e.data.payload,null,2).slice(0,800)})]}),e.state==="pending"&&t.jsxs("div",{className:"mt-2 flex gap-2",children:[t.jsxs("button",{onClick:()=>void d(e.id,"allow"),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-green/20 text-accent-green hover:bg-accent-green/30 text-xs font-medium",children:[t.jsx(k,{size:14})," 批准"]}),t.jsxs("button",{onClick:()=>void d(e.id,"deny"),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-red/20 text-accent-red hover:bg-accent-red/30 text-xs font-medium",children:[t.jsx(v,{size:14})," 拒绝"]}),e.kind==="approval"&&(()=>{const s=b(e);return t.jsxs("button",{onClick:()=>void d(e.id,"always"),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-xs font-medium",title:s?`此目标后续自动放行:${s}`:"此工具本次会话后续自动放行",children:[t.jsx(N,{size:14})," 总是允许",s?` ${s}`:""]})})()]})]},e.id)})]})]})}export{R as InboxView};
1
+ import{j as t}from"./markdown-BUScHEtT.js";import{r as c,J as m,p as f,o as j,at as k,X as v,aQ as N,aR as y,k as w}from"./icons-uody4X-4.js";import{v as C}from"./index-futMRNcm.js";import"./react-vendor-C5NlWs7r.js";import"./state-DKyBAq9j.js";function R(){const{items:i,pendingCount:x,fetchInbox:l,resolveInbox:d,loading:p,error:u}=C(),[r,g]=c.useState("pending");c.useEffect(()=>{l()},[l]);const o=c.useMemo(()=>i.filter(e=>r==="all"||e.state===r),[i,r]),h=e=>e.kind==="approval"?{label:"需要批准",icon:y,color:"text-accent-yellow"}:e.kind==="question"?{label:"需要回答",icon:w,color:"text-accent-blue"}:{label:"通知",icon:m,color:"text-dark-muted"},b=e=>{var n;if(e.kind!=="approval")return null;const a=((n=e.data)==null?void 0:n.payload)||{};for(const s of["target","recipient","channel","url"])if(typeof a[s]=="string"&&a[s])return a[s];for(const s of["path","filePath"])if(typeof a[s]=="string"&&a[s])return a[s];return null};return t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-4",children:[t.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[t.jsx(m,{size:20,className:"text-accent-blue"}),"Inbox",x>0&&t.jsxs("span",{className:"ml-1 px-2 py-0.5 rounded-full bg-accent-yellow/20 text-accent-yellow text-xs",children:[x," 待处理"]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"flex rounded-lg bg-dark-hover p-0.5 text-sm",children:["pending","resolved","all"].map(e=>t.jsx("button",{onClick:()=>g(e),className:`px-3 py-1 rounded-md transition-colors ${r===e?"bg-accent-blue/20 text-accent-blue":"text-dark-muted hover:text-dark-text"}`,children:e==="pending"?"待处理":e==="resolved"?"已解决":"全部"},e))}),t.jsx("button",{onClick:()=>void l(),className:"p-2 rounded-lg hover:bg-dark-hover text-dark-muted",title:"刷新",children:t.jsx(f,{size:16})})]})]}),u&&t.jsxs("div",{className:"mb-3 p-3 rounded-lg bg-accent-red/10 text-accent-red text-sm flex items-center gap-2",children:[t.jsx(j,{size:16})," ",u]}),t.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2",children:[p&&o.length===0&&t.jsx("p",{className:"text-dark-muted text-center py-8",children:"加载中..."}),!p&&o.length===0&&t.jsxs("p",{className:"text-dark-muted text-center py-8",children:["没有",r==="pending"?"待处理":"","事项"]}),o.map(e=>{const a=h(e),n=a.icon;return t.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(n,{size:16,className:`${a.color} shrink-0`}),t.jsx("span",{className:"font-medium text-sm truncate",children:e.title}),t.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted shrink-0",children:e.kind})]}),t.jsx("span",{className:`text-xs shrink-0 ${e.state==="pending"?"text-accent-yellow":"text-accent-green"}`,children:e.state==="pending"?"pending":e.resolution||"resolved"})]}),e.body&&t.jsx("p",{className:"mt-1 text-xs text-dark-muted break-all",children:e.body}),e.data&&typeof e.data.toolName=="string"&&e.data.toolName&&t.jsxs("div",{className:"mt-2 p-2 rounded bg-dark-bg border border-dark-border",children:[t.jsxs("code",{className:"text-xs text-accent-blue",children:["工具: ",String(e.data.toolName)]}),typeof e.data.payload=="object"&&e.data.payload!==null&&t.jsx("pre",{className:"mt-1 text-[11px] text-dark-muted whitespace-pre-wrap max-h-24 overflow-y-auto",children:JSON.stringify(e.data.payload,null,2).slice(0,800)})]}),e.state==="pending"&&t.jsxs("div",{className:"mt-2 flex gap-2",children:[t.jsxs("button",{onClick:()=>void d(e.id,"allow"),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-green/20 text-accent-green hover:bg-accent-green/30 text-xs font-medium",children:[t.jsx(k,{size:14})," 批准"]}),t.jsxs("button",{onClick:()=>void d(e.id,"deny"),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-accent-red/20 text-accent-red hover:bg-accent-red/30 text-xs font-medium",children:[t.jsx(v,{size:14})," 拒绝"]}),e.kind==="approval"&&(()=>{const s=b(e);return t.jsxs("button",{onClick:()=>void d(e.id,"always"),className:"flex items-center gap-1 px-3 py-1.5 rounded-lg bg-dark-hover text-dark-muted hover:text-dark-text text-xs font-medium",title:s?`此目标后续自动放行:${s}`:"此工具本次会话后续自动放行",children:[t.jsx(N,{size:14})," 总是允许",s?` ${s}`:""]})})()]})]},e.id)})]})]})}export{R as InboxView};
@@ -1 +1 @@
1
- import{j as t}from"./markdown-BUScHEtT.js";import{r as a,p as oe,C as st,P as ce,y as Ke,X as De,$ as at,w as de,a0 as Ae,a1 as rt,a2 as lt,T as nt,O as ot,a3 as ct,a4 as dt,D as it,a5 as $e,o as ut,a6 as xt}from"./icons-uody4X-4.js";import"./Toast-CcbSW0V2.js";import{a as x,t as C,M as Ee}from"./index-Bpfxw0Lr.js";import"./react-vendor-C5NlWs7r.js";import"./state-DKyBAq9j.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),[X,ye]=a.useState(!1),[B,J]=a.useState(""),[ke,je]=a.useState({}),[ae,Ne]=a.useState(!1),[re,q]=a.useState([]),[E,z]=a.useState(new Set),[we,U]=a.useState(null),[Q,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]),_=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]),Z=a.useMemo(()=>[..._].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)}),[_]),Pe=a.useMemo(()=>{const e=B.trim().toLowerCase();return e?Z.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))):Z},[Z,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),q([]),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),q([]),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),q([]),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)){q(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})},[]),qe=a.useCallback(()=>{const e=Array.from(E).join(", ");w(s=>({...s,modelIds:e}))},[E]),_e=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)},Xe=async()=>{var Ie;const e=_.find(v=>v.key===N)||null,s=N==="custom"?i.providerKey.trim():(e==null?void 0:e.key)||"";if(!s){S("请先输入 Provider 名称");return}if(!i.apiKey.trim()){S("请输入 API Key");return}const r=e||{baseUrl:"",apiType:"openai-completions",defaultModel:""},l=(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)}},Je=async e=>{if(confirm(`确定要移除 "${e}" 的配置吗?这将删除其 API Key 和模型。`))try{await x.config.provider.delete(e),await M(),await p()}catch{}},Qe=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)}},Ze=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(()=>_.find(e=>e.key===N)||null,[N,_]);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:()=>{X&&J(""),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:[X?t.jsx(st,{size:12}):t.jsx(ce,{size:12}),X?"收起":"新增 Provider"]})]})]}),X&&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=>J(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:()=>J(""),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:()=>J(""),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(),Je(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:Ze(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:()=>_e(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:[Z.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:qe,className:"px-2 py-0.5 text-[10px] bg-accent-blue text-white rounded hover:opacity-90",children:"应用选中"}),t.jsx("button",{onClick:()=>{q([]),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:Q,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=>!Q||e.id.toLowerCase().includes(Q.toLowerCase())||e.name.toLowerCase().includes(Q.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:Xe,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:Qe,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};
1
+ import{j as t}from"./markdown-BUScHEtT.js";import{r as a,p as oe,C as st,P as ce,y as Ke,X as De,$ as at,w as de,a0 as Ae,a1 as rt,a2 as lt,T as nt,O as ot,a3 as ct,a4 as dt,D as it,a5 as $e,o as ut,a6 as xt}from"./icons-uody4X-4.js";import"./Toast-CcbSW0V2.js";import{a as x,t as C,M as Ee}from"./index-futMRNcm.js";import"./react-vendor-C5NlWs7r.js";import"./state-DKyBAq9j.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),[X,ye]=a.useState(!1),[B,J]=a.useState(""),[ke,je]=a.useState({}),[ae,Ne]=a.useState(!1),[re,q]=a.useState([]),[E,z]=a.useState(new Set),[we,U]=a.useState(null),[Q,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]),_=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]),Z=a.useMemo(()=>[..._].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)}),[_]),Pe=a.useMemo(()=>{const e=B.trim().toLowerCase();return e?Z.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))):Z},[Z,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),q([]),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),q([]),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),q([]),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)){q(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})},[]),qe=a.useCallback(()=>{const e=Array.from(E).join(", ");w(s=>({...s,modelIds:e}))},[E]),_e=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)},Xe=async()=>{var Ie;const e=_.find(v=>v.key===N)||null,s=N==="custom"?i.providerKey.trim():(e==null?void 0:e.key)||"";if(!s){S("请先输入 Provider 名称");return}if(!i.apiKey.trim()){S("请输入 API Key");return}const r=e||{baseUrl:"",apiType:"openai-completions",defaultModel:""},l=(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)}},Je=async e=>{if(confirm(`确定要移除 "${e}" 的配置吗?这将删除其 API Key 和模型。`))try{await x.config.provider.delete(e),await M(),await p()}catch{}},Qe=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)}},Ze=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(()=>_.find(e=>e.key===N)||null,[N,_]);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:()=>{X&&J(""),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:[X?t.jsx(st,{size:12}):t.jsx(ce,{size:12}),X?"收起":"新增 Provider"]})]})]}),X&&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=>J(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:()=>J(""),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:()=>J(""),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(),Je(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:Ze(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:()=>_e(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:[Z.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:qe,className:"px-2 py-0.5 text-[10px] bg-accent-blue text-white rounded hover:opacity-90",children:"应用选中"}),t.jsx("button",{onClick:()=>{q([]),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:Q,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=>!Q||e.id.toLowerCase().includes(Q.toLowerCase())||e.name.toLowerCase().includes(Q.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:Xe,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:Qe,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};