@deepseekcode/cli 1.0.30 → 1.0.31

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.
@@ -12,7 +12,7 @@
12
12
  <meta name="theme-color" content="#0d1117" />
13
13
  <meta name="color-scheme" content="dark light" />
14
14
  <title>DeepSeekCode Web</title>
15
- <script type="module" crossorigin src="/assets/index-Dkxsd1Rx.js"></script>
15
+ <script type="module" crossorigin src="/assets/index-CWqFf5l2.js"></script>
16
16
  <link rel="modulepreload" crossorigin href="/assets/icons-Di-qMB6n.js">
17
17
  <link rel="modulepreload" crossorigin href="/assets/markdown-D-c9V8Xq.js">
18
18
  <link rel="modulepreload" crossorigin href="/assets/react-vendor-DU8XgZt2.js">
@@ -1 +0,0 @@
1
- import{j as s}from"./markdown-D-c9V8Xq.js";import{a as d,L as w,$ as _,aj as A,z as ae,h as ne,ag as le,O as F,aR as q,bh as K,a1 as oe,aW as O,E as de,aq as ce,D as V,l as ie}from"./icons-Di-qMB6n.js";import{u as me,a as f}from"./index-Dkxsd1Rx.js";import"./react-vendor-DU8XgZt2.js";import"./state-D2vcUGVk.js";import"./panels-CpHTincc.js";const ue={"code-intelligence":"🧠 代码智能",filesystem:"📂 文件系统",databases:"🗄️ 数据库","browser-automation":"🌐 浏览器自动化","knowledge-memory":"🧠 知识/记忆","search-web":"🔎 搜索/网页","cloud-platforms":"☁️ 云平台",communication:"💬 通讯","developer-tools":"🛠️ 开发者工具",security:"🔒 安全","test-demo":"🧪 测试/Demo",other:"📦 其他"};function je(){const{t:r}=me(),[u,x]=d.useState([]),[D,C]=d.useState(!0),[E,S]=d.useState(null),[j,p]=d.useState({}),[z,m]=d.useState(null),[v,H]=d.useState(""),[b,$]=d.useState(null),[k,U]=d.useState("all"),[Y,g]=d.useState(null),[G,L]=d.useState({}),[M,N]=d.useState(!1),[l,i]=d.useState({name:"",command:"",args:"",env:"",transport:"stdio",url:"",headers:""}),Q=()=>i({name:"",command:"",args:"",env:"",transport:"stdio",url:"",headers:""}),T=e=>Object.fromEntries(e.split(",").map(t=>t.trim()).filter(Boolean).map(t=>{const n=t.indexOf("=");return n>0?[t.slice(0,n).trim(),t.slice(n+1).trim()]:[t,""]})),W=async()=>{const e=l.transport!=="stdio";if(!l.name.trim()||!e&&!l.command.trim()||e&&!l.url.trim()){m(r("connectors.customFormRequired"));return}p(t=>({...t,__add:!0})),m(null);try{const t=await f.connectors.addCustom({name:l.name.trim(),command:e?void 0:l.command.trim(),args:e?void 0:l.args.split(/\s+/).filter(Boolean),env:T(l.env),url:e?l.url.trim():void 0,transport:e?l.transport:void 0,headers:e?T(l.headers):void 0});t.success&&t.data?(x(n=>[...n,t.data]),N(!1),Q()):m(t.error||"添加失败")}catch(t){m(t instanceof Error?t.message:String(t))}finally{p(t=>({...t,__add:!1}))}},I=async e=>{p(t=>({...t,[e.id]:!0}));try{const t=await f.connectors.removeCustom(e.id);t.success?x(n=>n.filter(a=>a.id!==e.id)):m(t.error||"删除失败")}finally{p(t=>({...t,[e.id]:!1}))}},y=async()=>{var t;C(!0),S(null);const e=await f.connectors.list();e.success&&Array.isArray((t=e.data)==null?void 0:t.connectors)?x(e.data.connectors):S(e.error||"加载连接器失败"),C(!1)};d.useEffect(()=>{y()},[]);const B=(e,t,n,a)=>{m(n||null),x(o=>o.map(c=>c.id===e?{...c,enabled:!!a,status:"error"}:c))},P=async(e,t,n)=>{m(null),p(a=>({...a,[e.id]:!0})),x(a=>a.map(o=>o.id===e.id?{...o,enabled:t,status:t?"connecting":"installed"}:o));try{const a=await f.connectors.toggle(e.id,t,n);a.success&&a.data?x(o=>o.map(c=>c.id===e.id?a.data:c)):B(e.id,void 0,a.error||`切换 ${e.name} 失败`,!t)}catch(a){B(e.id,void 0,a instanceof Error?a.message:String(a),!t)}finally{p(a=>({...a,[e.id]:!1}))}},Z=e=>{var t,n;if(!e.enabled&&((t=e.requiresEnv)!=null&&t.length)&&((n=e.missingEnv)!=null&&n.length)){g(e.id);return}g(null),P(e,!e.enabled)},J=(e,t)=>{g(null),L(n=>({...n,[e.id]:{}})),P(e,!0,t)},X=e=>{const t="inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium";if(!e.installed)return s.jsxs("span",{className:`${t} bg-dark-hover text-dark-muted`,children:[s.jsx(V,{size:12}),r("connectors.notInstalled")]});switch(e.status){case"ready":return s.jsxs("span",{className:`${t} bg-accent-green/15 text-accent-green`,children:[s.jsx(ie,{size:12}),r("connectors.ready")]});case"connecting":return s.jsxs("span",{className:`${t} bg-accent-blue/15 text-accent-blue`,children:[s.jsx(w,{size:12,className:"animate-spin"}),r("connectors.connecting")]});case"error":return s.jsxs("span",{className:`${t} bg-accent-red/15 text-accent-red`,children:[s.jsx(_,{size:12}),r("connectors.error")]});case"disabled":return s.jsx("span",{className:`${t} bg-dark-hover text-dark-muted`,children:r("connectors.disabled")});default:return s.jsx("span",{className:`${t} bg-dark-hover text-dark-muted`,children:r("connectors.installed")})}},h=u.filter(e=>k==="all"||e.kind===k),R=h.filter(e=>{if(v){const t=v.toLowerCase();if(![e.name,e.id,e.description,e.category??"",e.kind,...e.languages??[]].join(" ").toLowerCase().includes(t))return!1}return!(b&&e.category!==b)}).sort((e,t)=>e.enabled!==t.enabled?e.enabled?-1:1:e.name.localeCompare(t.name)),ee=[...new Set(h.map(e=>e.category).filter(Boolean))];if(D)return s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(w,{size:32,className:"animate-spin mx-auto mb-2 text-accent-blue"}),s.jsx("p",{className:"text-dark-muted",children:r("common.loading")})]})});if(E)return s.jsx("div",{className:"flex-1 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx(_,{size:32,className:"mx-auto mb-2 text-accent-red"}),s.jsx("p",{className:"text-accent-red mb-4",children:E}),s.jsx("button",{onClick:()=>void y(),className:"px-4 py-2 bg-accent-blue text-white rounded-lg",children:r("common.retry")})]})});const se=e=>{const t=G[e.id]??{},n=(a,o)=>L(c=>({...c,[e.id]:{...c[e.id]??{},[a]:o}}));return s.jsxs("div",{className:"mt-3 pt-3 border-t border-dark-border",children:[s.jsxs("div",{className:"text-xs text-dark-muted mb-2 flex items-center gap-1",children:[s.jsx(O,{size:12}),r("connectors.needCredentials")]}),s.jsx("div",{className:"space-y-2",children:(e.requiresEnv??[]).map(a=>s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:a.label}),s.jsx("input",{type:a.secret?"password":"text",value:t[a.key]??"",onChange:o=>n(a.key,o.target.value),placeholder:a.key,className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]},a.key))}),s.jsxs("div",{className:"flex gap-2 mt-2",children:[s.jsx("button",{onClick:()=>void J(e,t),className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm",children:r("connectors.connect")}),s.jsx("button",{onClick:()=>g(null),className:"px-3 py-1.5 bg-dark-surface border border-dark-border rounded-lg text-sm",children:r("common.cancel")})]})]})},te=e=>{var a,o,c;const t=!!j[e.id],n=Y===e.id;return s.jsxs("div",{className:`bg-dark-surface border border-dark-border rounded-lg p-4 transition-opacity ${e.enabled?"":"opacity-80"}`,children:[s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[s.jsx("span",{className:`mt-0.5 shrink-0 px-2 py-1 rounded-md text-[11px] font-semibold uppercase ${e.kind==="lsp"?"bg-accent-purple/15 text-accent-purple":"bg-accent-green/15 text-accent-green"}`,children:e.kind==="lsp"?"LSP":"MCP"}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx("span",{className:"font-medium text-sm truncate",children:e.name}),e.custom?s.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-purple/15 text-accent-purple",children:r("connectors.custom")}):null,e.official?s.jsxs("span",{title:"Official",className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-yellow/15 text-accent-yellow",children:["🎖️ ",r("connectors.official")]}):null,e.scope==="cloud"?s.jsxs("span",{title:"Cloud",className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/15 text-accent-blue",children:[s.jsx(q,{size:9}),r("connectors.cloud")]}):s.jsxs("span",{title:"Local",className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded bg-dark-hover text-dark-muted",children:[s.jsx(K,{size:9}),r("connectors.local")]}),e.language?s.jsx("span",{className:"text-[10px]",children:e.language}):null,X(e)]}),s.jsx("p",{className:"text-xs text-dark-muted mt-1 line-clamp-2",children:e.description}),s.jsxs("div",{className:"flex items-center gap-3 mt-2 text-[11px] text-dark-muted flex-wrap",children:[s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(K,{size:11}),s.jsx("code",{className:"text-[10px]",children:e.installHint})]}),e.transport&&e.transport!=="stdio"?s.jsxs("span",{className:"inline-flex items-center gap-1 text-accent-blue",children:[s.jsx(q,{size:11}),e.transport==="sse"?"SSE":"Streamable HTTP"]}):null,(a=e.languages)!=null&&a.length?s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(oe,{size:11}),e.languages.join(", ")]}):null,e.kind==="mcp"&&e.toolCount!==void 0?s.jsxs("span",{className:"inline-flex items-center gap-1",children:[s.jsx(A,{size:11}),r("connectors.toolCount",{count:e.toolCount})]}):null,(o=e.requiresEnv)!=null&&o.length?s.jsxs("span",{className:"inline-flex items-center gap-1 text-accent-yellow",children:[s.jsx(O,{size:11}),(c=e.missingEnv)!=null&&c.length?`${e.missingEnv.join(", ")} ${r("connectors.missing")}`:r("connectors.envConfigured")]}):null,e.docsUrl?s.jsxs("a",{href:e.docsUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 hover:text-accent-blue",onClick:re=>re.stopPropagation(),children:[s.jsx(de,{size:11}),r("connectors.docs")]}):null]}),e.error?s.jsx("p",{className:"text-[11px] text-accent-red mt-1",children:e.error}):null]})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.custom?s.jsx("button",{onClick:()=>void I(e),disabled:t,title:r("connectors.removeCustom"),className:"p-1.5 rounded-lg text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors disabled:opacity-40",children:s.jsx(ce,{size:14})}):null,!e.installed&&e.enabled?s.jsxs("span",{className:"text-[11px] text-accent-blue flex items-center gap-1",children:[s.jsx(V,{size:11,className:"animate-pulse"}),r("connectors.installing")]}):null,s.jsx("button",{role:"switch","aria-checked":e.enabled,disabled:t,onClick:()=>Z(e),className:`relative w-12 h-6 rounded-full transition-colors disabled:opacity-50 ${e.enabled?"bg-accent-green":"bg-dark-border"}`,children:s.jsx("span",{className:`absolute top-1 w-4 h-4 bg-white rounded-full transition-transform ${e.enabled?"left-7":"left-1"}`})})]})]}),n?se(e):null]},e.id)};return s.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden p-4",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[s.jsx(A,{size:20}),r("nav.connectors"),s.jsxs("span",{className:"text-sm font-normal text-dark-muted",children:["· ",u.filter(e=>e.enabled).length,"/",u.length]})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("button",{onClick:()=>N(e=>!e),className:"flex items-center gap-2 px-3 py-1.5 bg-accent-blue text-white rounded hover:bg-accent-blue/90 transition-colors",children:[s.jsx(ae,{size:14}),r("connectors.addCustom")]}),s.jsxs("button",{onClick:()=>void y(),className:"flex items-center gap-2 px-3 py-1.5 bg-dark-surface border border-dark-border rounded hover:bg-dark-hover transition-colors",children:[s.jsx(ne,{size:14}),r("common.refresh")]})]})]}),M?s.jsxs("div",{className:"mb-4 p-4 bg-dark-surface border border-dark-border rounded-lg",children:[s.jsxs("div",{className:"flex items-center justify-between mb-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[s.jsx(le,{size:15,className:"text-accent-purple"}),r("connectors.customTitle")]}),s.jsx("div",{className:"flex gap-1",children:[["stdio","🖥️ "+r("connectors.customLocal")],["http","🌐 HTTP"],["sse","📡 SSE"]].map(([e,t])=>s.jsx("button",{onClick:()=>i(n=>({...n,transport:e})),className:`px-3 py-1.5 rounded-lg text-xs transition-colors ${l.transport===e?"bg-accent-blue text-white":"bg-dark-bg border border-dark-border hover:bg-dark-hover"}`,children:t},e))})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customName")}),s.jsx("input",{value:l.name,onChange:e=>i(t=>({...t,name:e.target.value})),placeholder:"my-server",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),l.transport==="stdio"?s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customCommand")}),s.jsx("input",{value:l.command,onChange:e=>i(t=>({...t,command:e.target.value})),placeholder:"npx -y @some/mcp-server",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customArgs")}),s.jsx("input",{value:l.args,onChange:e=>i(t=>({...t,args:e.target.value})),placeholder:"--arg value",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customUrl")}),s.jsx("input",{value:l.url,onChange:e=>i(t=>({...t,url:e.target.value})),placeholder:"https://mcp.example.com/mcp",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}),l.transport==="stdio"?s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customEnv")}),s.jsx("input",{value:l.env,onChange:e=>i(t=>({...t,env:e.target.value})),placeholder:"KEY=value, KEY2=value2",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]}):s.jsxs("div",{children:[s.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:r("connectors.customHeaders")}),s.jsx("input",{value:l.headers,onChange:e=>i(t=>({...t,headers:e.target.value})),placeholder:"Authorization=Bearer xxx",className:"w-full px-3 py-1.5 bg-dark-bg border border-dark-border rounded-lg text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})]}),s.jsxs("div",{className:"flex gap-2 mt-3",children:[s.jsx("button",{onClick:()=>void W(),disabled:!!j.__add,className:"px-3 py-1.5 bg-accent-blue text-white rounded-lg text-sm disabled:opacity-50",children:j.__add?s.jsx(w,{size:14,className:"animate-spin"}):r("connectors.add")}),s.jsx("button",{onClick:()=>N(!1),className:"px-3 py-1.5 bg-dark-surface border border-dark-border rounded-lg text-sm",children:r("common.cancel")})]})]}):null,s.jsx("div",{className:"flex gap-1 mb-3",children:[["all",`${r("connectors.all")} (${u.length})`],["lsp",`LSP (${u.filter(e=>e.kind==="lsp").length})`],["mcp",`MCP (${u.filter(e=>e.kind==="mcp").length})`]].map(([e,t])=>s.jsx("button",{onClick:()=>U(e),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${k===e?"bg-accent-blue text-white":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:t},e))}),s.jsx("div",{className:"flex gap-3 mb-3",children:s.jsxs("div",{className:"flex-1 relative",children:[s.jsx(F,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),s.jsx("input",{type:"text",value:v,onChange:e=>H(e.target.value),placeholder:r("connectors.searchPlaceholder"),className:"w-full pl-10 pr-4 py-2 bg-dark-surface border border-dark-border rounded-lg text-dark-text placeholder-dark-muted focus:border-accent-blue focus:outline-none"})]})}),s.jsxs("div",{className:"flex gap-1 mb-4 flex-wrap",children:[s.jsxs("button",{onClick:()=>$(null),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${b?"bg-dark-surface border border-dark-border hover:bg-dark-hover":"bg-accent-blue text-white"}`,children:[r("connectors.all")," ",s.jsxs("span",{className:"opacity-70 text-xs",children:["(",h.length,")"]})]}),ee.map(e=>{const t=h.filter(n=>n.category===e).length;return s.jsxs("button",{onClick:()=>$(b===e?null:e),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${b===e?"bg-accent-blue text-white":"bg-dark-surface border border-dark-border hover:bg-dark-hover"}`,children:[ue[e]??e," ",s.jsxs("span",{className:"opacity-70 text-xs",children:["(",t,")"]})]},e)})]}),z?s.jsx("div",{className:"mb-4 px-3 py-2 bg-accent-red/10 border border-accent-red/30 rounded-lg text-accent-red text-sm",children:z}):null,s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar",children:R.length===0?s.jsxs("div",{className:"text-center text-dark-muted text-sm py-10",children:[s.jsx(F,{size:24,className:"mx-auto mb-2 opacity-50"}),r("connectors.noResults")]}):s.jsx("div",{className:"space-y-2",children:R.map(te)})})]})}export{je as ConnectorsView};
@@ -1 +0,0 @@
1
- import{j as e}from"./markdown-D-c9V8Xq.js";import{a as o,h as te,a2 as Hs,z as Me,O as ae,X as cs,ap as qs,C as be,aq as Ie,ar as is,as as _s,af as Vs,ac as Ws,at as Ys,au as Qs,D as Js,aj as Xs,av as us,$ as Zs,aw as et}from"./icons-Di-qMB6n.js";import{a as h,u as st,t as T,M as ms,P as tt}from"./index-Dkxsd1Rx.js";import"./react-vendor-DU8XgZt2.js";import"./state-D2vcUGVk.js";import"./panels-CpHTincc.js";function at(){const[y,b]=o.useState([]),[C,t]=o.useState("1.0"),[P,je]=o.useState(!0),[f,le]=o.useState(!0),[ke,W]=o.useState(null),Y=o.useCallback(async()=>{le(!0),W(null);try{const g=await h.providers.presets();g.success&&g.data?(b(Array.isArray(g.data.providers)?g.data.providers:[]),t(g.data.version||"1.0"),je(g.data.customSupported!==!1)):W(g.error||"获取 Provider 列表失败")}catch(g){W(g instanceof Error?g.message:"未知错误")}finally{le(!1)}},[]);return o.useEffect(()=>{Y()},[Y]),{presets:y,loading:f,error:ke,version:C,customSupported:P,reload:Y}}const lt={providerKey:"",apiKeys:"",modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!1,modelOverrides:{}},ps=tt,fe={"openai-chat-completions":"OpenAI Chat","openai-completions":"OpenAI Compatible","openai-responses":"OpenAI Responses","anthropic-messages":"Anthropic Messages","codex-responses":"Codex (本机登录)","claude-code":"Claude Code (本机登录)"};function J(y){return y.trim().split("|")[0].trim()}function rt(y){const b=y.toLowerCase();return b.startsWith("claude-code://")||b.includes("/backend-api/codex")?b.startsWith("claude-code://")?"claude-code":"codex-responses":b.includes("/anthropic")||b.includes("/coding")||b.includes("/claude")||b.includes("/messages")?"anthropic-messages":b.includes("/responses")?"openai-responses":"openai-completions"}function Ue(y){if(!y)return{};const b={};for(const C of y.models){const t={};C.apiType&&C.apiType!==y.apiType&&(t.apiType=C.apiType),C.baseUrl&&(t.baseUrl=C.baseUrl),Object.keys(t).length>0&&(b[C.id]=t)}return b}const ge={"opencode-free":5,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 mt(){var ss,ts,as,ls,rs,os;const{presets:y,loading:b,reload:C}=at(),{t}=st(),[P,je]=o.useState([]),[f,le]=o.useState(null),[ke,W]=o.useState(!0),[Y,g]=o.useState(null),[Ae,Ke]=o.useState(null),[n,hs]=o.useState(null),[M,bs]=o.useState([]),[fs,G]=o.useState(!1),[Ee,H]=o.useState("select"),[D,R]=o.useState(null),[m,j]=o.useState(lt),[gs,E]=o.useState(""),[$e,Fe]=o.useState(!1),[ze,$]=o.useState(null),[vs,X]=o.useState(!1),[re,Le]=o.useState(!1),[Z,oe]=o.useState(""),[Re,Oe]=o.useState({}),[Ne,Be]=o.useState(!1),[F,q]=o.useState([]),[ne,I]=o.useState(new Set),[Ge,O]=o.useState(null),[de,ee]=o.useState(""),[we,He]=o.useState(!1),[ce,B]=o.useState(null),_=o.useCallback(async()=>{try{const s=await h.config.provider.get();s.success&&s.data&&(hs(s.data),bs(Array.isArray(s.data.entries)?s.data.entries:[]))}catch{}},[]),k=o.useCallback(async()=>{W(!0),g(null);try{const[s,a]=await Promise.all([h.models.list(),h.system.status()]);if(await _(),s.success&&s.data&&Array.isArray(s.data.models)&&je(s.data.models),a.success&&a.data){const l=a.data.models||{total:0,online:0,offline:0};le({overallStatus:l.offline===0?"healthy":l.online>0?"degraded":"unhealthy",healthRate:l.total>0?l.online/l.total:0,healthyInstances:l.online,totalInstances:l.total,totalRequests:0})}}catch{g(t("models.loadFailed"))}finally{W(!1)}},[_,t]);o.useEffect(()=>{k()},[k]),o.useEffect(()=>{const s=()=>{k(),_()};return window.addEventListener("models-updated",s),()=>window.removeEventListener("models-updated",s)},[k,_]);const U=o.useCallback(s=>`${s.provider}:${s.id}`,[]),ys=o.useCallback(s=>Re[U(s)]||{inputTokens:0,outputTokens:0},[U,Re]),qe=o.useCallback((s,a,l)=>{const c=U(s);Oe(r=>{var d,i;return{...r,[c]:{inputTokens:a==="inputTokens"?l:((d=r[c])==null?void 0:d.inputTokens)||0,outputTokens:a==="outputTokens"?l:((i=r[c])==null?void 0:i.outputTokens)||0}}})},[U]),js=o.useCallback(s=>{Oe(a=>({...a,[U(s)]:{inputTokens:0,outputTokens:0}}))},[U]),z=o.useMemo(()=>{const s=[...y];return s.find(a=>a.key==="custom")||s.push({key:"custom",name:"Custom",baseUrl:"",apiType:"openai-completions",defaultModel:"",isCustom:!0}),s},[y]),ie=o.useMemo(()=>[...z].sort((s,a)=>{if(s.isCustom)return-1;if(a.isCustom)return 1;const l=ge[s.key],c=ge[a.key];return l!==void 0&&c!==void 0?l-c:l!==void 0?-1:c!==void 0?1:s.name.localeCompare(a.name)}),[z]),_e=o.useMemo(()=>{const s=Z.trim().toLowerCase();return s?ie.filter(a=>a.name.toLowerCase().includes(s)||a.key.toLowerCase().includes(s)||(a.defaultModel||"").toLowerCase().includes(s)||(a.baseUrl||"").toLowerCase().includes(s)||(a.models||[]).some(l=>String(l).toLowerCase().includes(s))):ie},[ie,Z]),L=o.useMemo(()=>{var c,r,d,i;const s=(n==null?void 0:n.providers)||{},a=new Set(z.map(u=>u.key)),l=Object.entries(s).filter(([u])=>!a.has(u));if(l.length!==0)return{keys:l.map(([u])=>u),modelCount:l.reduce((u,[,v])=>u+(v.modelCount||0),0),hasApiKey:l.some(([,u])=>u.hasApiKey),baseUrl:((r=(c=l.find(([,u])=>u.baseUrl))==null?void 0:c[1])==null?void 0:r.baseUrl)||"",apiType:((i=(d=l.find(([,u])=>u.apiType))==null?void 0:d[1])==null?void 0:i.apiType)||"openai-completions"}},[n,z]),V=D==="custom"?m.providerKey.trim():D||"",Ce=o.useMemo(()=>V?P.filter(s=>s.provider===V):[],[P,V]),ks=o.useMemo(()=>{const s=new Map;for(const l of P)s.has(l.provider)||s.set(l.provider,[]),s.get(l.provider).push(l);for(const l of M)s.has(l.key)||s.set(l.key,[]);const a=[...s.keys()];return a.sort((l,c)=>{const r=ge[l],d=ge[c];return r!==void 0&&d!==void 0?r-d:r!==void 0?-1:d!==void 0?1:l.localeCompare(c)}),a.map(l=>({provider:l,models:s.get(l)||[]}))},[P,M]),Ve=o.useCallback(s=>{var i,u;const a=(i=n==null?void 0:n.providers)==null?void 0:i[s.key],l=M.find(v=>v.key===s.key),c=P.filter(v=>v.provider===s.key).map(v=>v.id),r=((u=s.models)==null?void 0:u.slice(0,3).join(", "))||s.defaultModel,d=c.length>0?c.join(", "):r;R(s.key),E(""),j({providerKey:s.key,apiKeys:"",modelIds:d,baseUrl:(a==null?void 0:a.baseUrl)||s.baseUrl,apiType:(a==null?void 0:a.apiType)||s.apiType,fullPath:(a==null?void 0:a.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s.key,modelOverrides:Ue(l)}),H("form"),G(!0),$(null),X(!1),q([]),I(new Set),O(null),ee("")},[P,n,M]),Ns=o.useCallback(s=>{var r;const a=(r=n==null?void 0:n.providers)==null?void 0:r[s],l=M.find(d=>d.key===s),c=P.filter(d=>d.provider===s).map(d=>d.id).join(", ");R("custom"),E(s),j({providerKey:s,apiKeys:"",modelIds:c,baseUrl:(a==null?void 0:a.baseUrl)||"",apiType:(a==null?void 0:a.apiType)||"",fullPath:(a==null?void 0:a.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s,modelOverrides:Ue(l)}),$(null),X(!1),q([]),I(new Set),O(null),ee("")},[n,P,M]),Pe=o.useCallback(()=>{R("custom"),E(""),j({providerKey:"",apiKeys:"",modelIds:"",baseUrl:"",apiType:"",fullPath:!1,setDefault:!(n!=null&&n.configured),modelOverrides:{}}),H("form"),G(!0),$(null),X(!1),q([]),I(new Set),O(null),ee("")},[n]),ws=o.useCallback(async()=>{var a;const s=m.baseUrl;if(!s){O(t("models.baseUrlRequired"));return}Be(!0),O(null),q([]),I(new Set);try{const l=(m.apiKeys||"").split(/\r?\n|,/).map(d=>d.trim()).filter(Boolean)[0]||"",c=l.replace(/[^\x00-\xFF]/g,"");c!==l&&T.warning(t("models.apiKeySanitized"));const r=await h.models.fetch(s,c,m.fullPath===!0);if(r.success&&((a=r.data)!=null&&a.models)){const d=r.data.models;q(d);const i=new Set(d.map(w=>w.id)),u=m.modelIds.split(",").map(w=>w.trim()).filter(Boolean),v=u.filter(w=>i.has(w.split("|")[0].trim())),p=u.filter(w=>!i.has(w.split("|")[0].trim()));if(I(new Set(v.map(w=>w.split("|")[0].trim()))),p.length>0){const w=p.map(S=>S.split("|")[0].trim());j(S=>({...S,modelIds:v.join(", ")})),T.warning(t("models.autoRemovedMissingModels",{models:w.join(", ")}))}T.success(t("models.fetchedCount",{n:d.length}))}else O(r.error||t("models.fetchFailed"))}catch(l){O(l instanceof Error?l.message:t("models.requestFailed"))}finally{Be(!1)}},[m.baseUrl,m.apiKeys,m.modelIds,t]),Cs=o.useCallback(async()=>{var a,l;const s=m.baseUrl;if(!s){B({ok:!1,message:t("models.baseUrlRequired")});return}He(!0),B(null);try{const c=(m.apiKeys||"").split(/\r?\n|,/).map(i=>i.trim()).filter(Boolean)[0]||"",r=c.replace(/[^\x00-\xFF]/g,"");r!==c&&T.warning(t("models.apiKeySanitized"));const d=await h.providers.testConnection(s,r);if(d.success&&((a=d.data)!=null&&a.reachable)){const i=d.data,u={};i.resolvedBaseUrl&&i.resolvedBaseUrl!==m.baseUrl&&(u.baseUrl=i.resolvedBaseUrl),i.detectedApiType&&m.apiType===""&&(u.apiType=i.detectedApiType),Object.keys(u).length>0&&j(w=>({...w,...u}));const v=[];u.baseUrl&&v.push(t("models.baseUrlAutoCompleted",{url:u.baseUrl})),u.apiType&&v.push(t("models.apiTypeAutoSelected",{type:fe[u.apiType]}));const p=i.message||t("models.connectionSuccess");B({ok:!0,message:v.length>0?t("models.connectionSuccessWithHints",{message:p,hints:v.join(t("models.hintJoiner"))}):p})}else B({ok:!1,message:((l=d.data)==null?void 0:l.message)||d.error||t("models.connectionFailed")})}catch(c){B({ok:!1,message:c instanceof Error?c.message:t("models.requestFailed")})}finally{He(!1)}},[m.baseUrl,m.apiKeys,m.apiType,t]),Ps=o.useCallback(s=>{const a=new Set(ne);a.has(s)?a.delete(s):a.add(s),I(a),j(l=>({...l,modelIds:Array.from(a).join(", ")}))},[ne]),Ts=o.useCallback(s=>{const a=m.modelIds.split(",").map(d=>d.trim()).filter(Boolean),c=a.some(d=>J(d)===s.id)?a.filter(d=>J(d)!==s.id):[...a,s.name&&s.name!==s.id?`${s.id}|${s.name}`:s.id];j(d=>({...d,modelIds:c.join(", ")}));const r=new Set(F.map(d=>d.id));I(new Set(c.map(J).filter(d=>r.has(d))))},[m.modelIds,F]),[Ds,We]=o.useState(!1),[Te,Ye]=o.useState(""),[Qe,ue]=o.useState([]),[Ss,Je]=o.useState(!1),[Xe,me]=o.useState(null),[pe,Ms]=o.useState(!1),[xe,Is]=o.useState(!0),Us=o.useCallback(()=>{Ye(""),ue([]),me(null),We(!0),se("",{reason:!1,tool:!0})},[]),se=o.useCallback(async(s,a)=>{Je(!0),me(null);try{const l=await h.models.catalogSearch({q:s,reasoning:(a==null?void 0:a.reason)??!1,toolCall:(a==null?void 0:a.tool)??!0,limit:30});l.success&&l.data?ue(l.data.hits||[]):(me(l.error||t("models.catalogSearchFailed")),ue([]))}catch(l){me(l instanceof Error?l.message:t("models.requestFailed")),ue([])}finally{Je(!1)}},[t]),As=o.useCallback(s=>{j(a=>{const l=a.modelIds.split(",").map(c=>c.trim()).filter(Boolean);return l.includes(s.model.id)?a:{...a,modelIds:[...l,s.model.id].join(", ")}}),T.success(t("models.addedModel",{id:s.model.id}))},[t]),[De,Ks]=o.useState(null),Es=o.useCallback(s=>{Ye(s),De&&clearTimeout(De),Ks(setTimeout(()=>{se(s,{reason:pe,tool:xe})},300))},[De,pe,xe,se]),$s=async s=>{const a=s.provider,l=s.id,c=s.enabled!==!1,r=s.name||l,d=i=>c&&/default model/i.test(i);try{const i=await h.models.toggle(a,l);if(i.success){await k();return}const u=i.error||"";d(u)?T.error(t("models.defaultModelDisableBlocked",{name:r})):T.error(u||t("models.operationFailed"))}catch(i){const u=i instanceof Error?i.message:"";d(u)?T.error(t("models.defaultModelDisableBlocked",{name:r})):T.error(u||t("models.operationFailed"))}},Fs=async s=>{const a=U(s);Ke(a);try{await h.models.test(s.id),await k()}finally{Ke(null)}},zs=async(s,a)=>{if(confirm(t("models.deleteModelConfirm",{id:a})))try{(await h.models.delete(s,a)).success&&await k()}catch{}},Ze=o.useCallback(s=>{var d;const a=M.find(i=>i.key===s),l=z.find(i=>i.key===s),c=!l||l.isCustom,r=(d=n==null?void 0:n.providers)==null?void 0:d[s];R(c?"custom":s),E(c?s:""),j({providerKey:s,apiKeys:"",modelIds:(a==null?void 0:a.models.map(i=>i.name&&i.name!==i.id?`${i.id}|${i.name}`:i.id).join(", "))||"",baseUrl:(a==null?void 0:a.baseUrl)||(r==null?void 0:r.baseUrl)||(l==null?void 0:l.baseUrl)||"",apiType:(a==null?void 0:a.apiType)||(r==null?void 0:r.apiType)||(l==null?void 0:l.apiType)||"",fullPath:(a==null?void 0:a.fullPath)===!0||(r==null?void 0:r.fullPath)===!0,setDefault:(n==null?void 0:n.defaultProvider)!==s,modelOverrides:Ue(a)}),H("form"),G(!0),$(null),X(!1),q([]),I(new Set),O(null),ee("")},[M,z,n]),Ls=s=>{Ze(s.provider)},Rs=async()=>{var ns,ds;const s=z.find(x=>x.key===D)||null,a=D==="custom"?m.providerKey.trim():(s==null?void 0:s.key)||"";if(!a){$(t("models.providerNameRequired"));return}const l=(m.apiKeys||"").split(/\r?\n|,/).map(x=>x.trim()).filter(Boolean),c=!!((ds=(ns=n==null?void 0:n.providers)==null?void 0:ns[a])!=null&&ds.hasApiKey);if(l.length===0&&!c){$(t("models.apiKeyRequired"));return}const r=s||{baseUrl:"",apiType:"openai-completions",defaultModel:""},d=l.map(x=>x.replace(/[^\x00-\xFF]/g,"")).filter(Boolean),i=F.length>0?new Set(F.map(x=>x.id)):null,u=(m.modelIds||r.defaultModel||"").split(",").map(x=>x.trim()).filter(Boolean),v=i?u.filter(x=>i.has(x.split("|")[0].trim())):u,p=i?u.filter(x=>!i.has(x.split("|")[0].trim())):[];p.length>0&&T.warning(t("models.autoSkippedMissingModels",{models:p.map(x=>x.split("|")[0].trim()).join(", ")}));const w=v.map(J).filter(Boolean),S=new Set;for(const x of P)x.provider!==a||w.includes(x.id)||(x.isGlobalDefault&&S.add("global"),x.isActDefault&&S.add("act"),x.isPlanDefault&&S.add("plan"),x.isGoalDefault&&S.add("goal"));const Se={provider:a,name:a,baseUrl:m.baseUrl||r.baseUrl,fullPath:m.fullPath===!0,apiType:m.apiType||rt(m.baseUrl||r.baseUrl)||r.apiType,models:v.map((x,he)=>{const A=x.trim().split("|").map(Gs=>Gs.trim()).filter(Boolean),K=A[0]||"",N=m.modelOverrides[K];return{id:K,name:A[1]||K,aliases:A.length>2?A.slice(2):void 0,enabled:!0,priority:10+he,...N!=null&&N.apiType?{apiType:N.apiType}:{},...N!=null&&N.baseUrl?{baseUrl:N.baseUrl}:{}}}).filter(x=>x.id.length>0)};d.length>0&&(Se.apiKeys=d),(!(n!=null&&n.configured)||m.setDefault)&&(Se.setDefault=!0),Fe(!0),$(null);try{const x=await h.config.provider.save(Se);if(x.success){if(S.size>0){const he=w[0]||"",A={};if(he){const K=`${a}:${he}`;for(const N of S)A[N]=K}else{const K=P.find(N=>N.provider!==a);for(const N of S)N==="plan"||N==="goal"?A[N]=null:K&&(A[N]=`${K.provider}:${K.id}`)}Object.keys(A).length>0&&(await h.models.setDefaults(A)).success&&T.success(t("models.defaultsAutoUpdated"))}G(!1),H("select"),R(null),E(""),await _(),await k()}else $(x.error||t("models.saveFailed"))}catch(x){$(x instanceof Error?x.message:t("models.unknownError"))}finally{Fe(!1)}},es=async s=>{if(confirm(t("models.removeConfirm",{providerKey:s})))try{await h.config.provider.delete(s),await _(),await k()}catch{}},Os=s=>{switch(s){case"online":return"text-accent-green";case"offline":return"text-dark-muted";case"error":return"text-accent-red";default:return"text-dark-muted"}},Bs=s=>{switch(s){case"online":return e.jsx(et,{size:14});case"offline":return e.jsx(us,{size:14});case"error":return e.jsx(Zs,{size:14});default:return e.jsx(us,{size:14})}},Q=o.useMemo(()=>z.find(s=>s.key===D)||null,[D,z]);return ke?e.jsx("div",{className:"flex h-64 items-center justify-center text-dark-muted",children:t("models.loading")}):Y?e.jsx("div",{className:"flex h-64 items-center justify-center text-accent-red",children:Y}):e.jsx("div",{className:"ui-page flex-1 min-h-0",children:e.jsxs("div",{className:"ui-page-inner space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h2",{className:"text-base font-semibold",children:t("models.providerConfig")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:async()=>{try{await h.providers.refresh(),T.success(t("models.providerListRefreshed")),Le(!0),await C(),setTimeout(()=>{C()},3e3)}catch{T.error(t("models.refreshFailed"))}},className:"btn btn-secondary px-3 py-2 text-xs",title:t("models.refreshListTitle"),children:[e.jsx(te,{size:12}),t("models.refreshList")]}),e.jsxs("button",{onClick:()=>{re&&oe(""),Le(s=>!s)},className:"btn btn-accent px-3 py-2 text-xs",children:[re?e.jsx(Hs,{size:12}):e.jsx(Me,{size:12}),t(re?"models.collapse":"models.addProvider")]})]})]}),re&&e.jsxs("div",{children:[e.jsxs("div",{className:"relative mb-3 max-w-md",children:[e.jsx(ae,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:Z,onChange:s=>oe(s.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:t("models.providerSearchPlaceholder")}),Z&&e.jsx("button",{onClick:()=>oe(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-white",title:t("models.clear"),"aria-label":t("models.clearSearch"),children:e.jsx(cs,{size:13})})]}),e.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:b?e.jsxs("div",{className:"col-span-full flex items-center justify-center py-4 text-dark-muted text-sm",children:[e.jsx(qs,{size:14,className:"mr-2 animate-spin"}),t("models.loadingProviders")]}):_e.length===0?e.jsxs("div",{className:"col-span-full border border-accent-red/30 bg-accent-red/10 rounded-lg p-4 text-center",children:[e.jsx("div",{className:"text-sm text-accent-red font-medium mb-1",children:t("models.noMatchingProviders")}),e.jsx("div",{className:"text-xs text-dark-muted mb-3",children:t("models.noMatchingProvidersHint",{query:Z})}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsxs("button",{onClick:()=>oe(""),className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs border border-dark-border rounded hover:bg-dark-hover",children:[e.jsx(cs,{size:12}),t("models.clearSearch")]}),e.jsxs("button",{onClick:Pe,className:"inline-flex items-center gap-1 px-2.5 py-1 text-xs bg-accent-blue text-white rounded hover:opacity-90",children:[e.jsx(Me,{size:12}),t("models.addCustomProvider")]})]})]}):_e.map(s=>{var d,i;const a=s.key==="custom",l=a?L:(d=n==null?void 0:n.providers)==null?void 0:d[s.key],c=l==null?void 0:l.hasApiKey,r=a?!!(n!=null&&n.defaultProvider)&&((L==null?void 0:L.keys)||[]).includes(n.defaultProvider):(n==null?void 0:n.defaultProvider)===s.key;return e.jsxs("div",{className:`ui-card-interactive text-left p-4 relative ${c?"border-accent-green/30 bg-dark-surface hover:border-accent-green/50":"border-dark-border bg-dark-surface hover:border-dark-hover"}`,children:[e.jsxs("div",{onClick:()=>s.key==="custom"?Pe():Ve(s),className:"cursor-pointer",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),c&&e.jsx(be,{size:14,className:"text-accent-green"})]}),e.jsxs("div",{className:"text-[10px] text-dark-muted space-y-0.5",children:[e.jsx("div",{className:"truncate",children:a?(l==null?void 0:l.baseUrl)||t("models.customBaseUrl"):s.baseUrl||t("models.customBaseUrl")}),e.jsx("div",{className:"truncate",children:a&&L?`${L.keys.join(", ")}`:s.defaultModel||t("models.noDefaultModel")}),e.jsxs("div",{children:[l?t("models.configuredCount",{n:l.modelCount}):t("models.availableCount",{n:((i=s.models)==null?void 0:i.length)||0}),s.models&&s.models.length>0&&!l&&e.jsx("span",{className:"text-accent-blue",children:" ✓"})]})]}),r&&e.jsx("div",{className:"mt-1 text-[10px] text-accent-blue",children:t("models.defaultProviderBadge")})]}),c&&s.key!=="custom"&&e.jsx("button",{onClick:u=>{u.stopPropagation(),es(s.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:t("models.deleteProvider"),"aria-label":t("models.deleteProviderNamed",{name:s.name}),children:e.jsx(Ie,{size:13})})]},s.key)})})]})]}),f&&e.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[e.jsx(ve,{title:t("models.overallStatus"),value:f.totalInstances===0?t("models.notConfigured"):f.overallStatus==="healthy"?t("models.healthy"):f.overallStatus==="degraded"?t("models.degraded"):t("models.abnormal"),color:f.totalInstances===0?"blue":f.overallStatus==="healthy"?"green":f.overallStatus==="degraded"?"yellow":"red"}),e.jsx(ve,{title:t("models.healthRate"),value:f.totalInstances===0?"N/A":`${(f.healthRate*100).toFixed(0)}%`,color:f.totalInstances===0?"blue":f.healthRate>.8?"green":f.healthRate>.5?"yellow":"red"}),e.jsx(ve,{title:t("models.onlineInstances"),value:f.totalInstances===0?t("models.none"):`${f.healthyInstances}/${f.totalInstances}`,color:f.healthyInstances>0?"green":"red"}),e.jsx(ve,{title:t("models.totalRequests"),value:f.totalRequests>0?f.totalRequests.toLocaleString():"0",color:"blue"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsx("h3",{className:"text-sm font-medium",children:t("models.configuredModels")})}),e.jsxs("div",{className:"space-y-4 max-h-[640px] overflow-y-auto custom-scrollbar pr-1",children:[ks.map(s=>{var c;const a=M.find(r=>r.key===s.provider),l=(c=n==null?void 0:n.providers)==null?void 0:c[s.provider];return e.jsxs("div",{className:"rounded-lg border border-dark-border overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2 bg-dark-bg border-b border-dark-border",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[e.jsx("span",{className:"text-xs font-semibold whitespace-nowrap text-accent-purple",children:s.provider}),(n==null?void 0:n.defaultProvider)===s.provider&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue whitespace-nowrap",children:t("models.defaultShort")}),e.jsx("span",{className:"text-[10px] text-dark-muted truncate",children:(l==null?void 0:l.baseUrl)||(a==null?void 0:a.baseUrl)||""}),e.jsx("span",{className:"text-[10px] text-dark-muted whitespace-nowrap",children:(a==null?void 0:a.apiType)||(l==null?void 0:l.apiType)||""}),l!=null&&l.hasApiKey||a!=null&&a.hasApiKey?e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-green/20 text-accent-green whitespace-nowrap",children:t("models.hasKey")}):e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded bg-accent-red/20 text-accent-red whitespace-nowrap",children:t("models.noKey")})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>Ze(s.provider),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:t("models.editProviderNamed",{name:s.provider}),children:e.jsx(is,{size:13})}),e.jsx("button",{onClick:()=>es(s.provider),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:t("models.deleteProviderNamed",{name:s.provider}),children:e.jsx(Ie,{size:13})})]})]}),e.jsxs("div",{className:"space-y-2 p-2 bg-dark-surface/40",children:[s.models.map(r=>{const d=ys(r),i=d.inputTokens+d.outputTokens,u=a==null?void 0:a.models.find(p=>p.id===r.id),v=!!(u!=null&&u.apiType&&u.apiType!==(a==null?void 0:a.apiType));return e.jsx("div",{className:`bg-dark-surface border rounded-lg p-3 ${r.status==="online"?"border-accent-green":"border-dark-border"} ${r.enabled===!1?"opacity-60":""}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:Os(r.status),children:Bs(r.status)}),e.jsx("span",{className:"font-medium text-sm text-accent-blue",children:r.name}),e.jsx("span",{className:"text-[10px] text-accent-purple px-1.5 py-0.5 bg-accent-purple/10 rounded",children:r.provider}),r.apiType&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded ${r.apiType==="anthropic-messages"||r.apiType==="openai-responses"?"bg-accent-purple/20 text-accent-purple":"bg-accent-blue/20 text-accent-blue"}`,children:fe[r.apiType]||r.apiType}),v&&e.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",title:t("models.overrideTitle"),children:t("models.overrideBadge")}),r.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-green/20 text-accent-green font-medium",children:t("chat.globalDefault")}),r.isPlanDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue font-medium",children:t("chat.planDefault")}),r.isActDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-yellow/20 text-accent-yellow font-medium",children:t("chat.actDefault")}),r.isGoalDefault&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-purple/20 text-accent-purple font-medium",children:t("chat.goalDefault")})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs",children:[e.jsx(ye,{label:t("models.loadLabel"),value:`${r.load}/${r.maxLoad}`}),e.jsx(ye,{label:"Token",value:`${r.tokens}/${r.maxTokens}`}),e.jsx(ye,{label:t("models.inputPrice"),value:`$${r.price.input}/1K`}),e.jsx(ye,{label:t("models.outputPrice"),value:`$${r.price.output}/1K`})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 sm:grid-cols-4 gap-3 items-end",children:[e.jsx(xs,{label:t("models.inputTokensLabel"),value:d.inputTokens,onChange:p=>qe(r,"inputTokens",p)}),e.jsx(xs,{label:t("models.outputTokensLabel"),value:d.outputTokens,onChange:p=>qe(r,"outputTokens",p)}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] text-dark-muted mb-1",children:t("models.totalTokensLabel")}),e.jsx("div",{className:"px-3 py-2 rounded border border-dark-border bg-dark-bg text-sm font-mono",children:i.toLocaleString()})]}),e.jsxs("button",{onClick:()=>js(r),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:[e.jsx(_s,{size:13}),t("models.reset")]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[!r.isGlobalDefault&&r.enabled!==!1&&e.jsx("button",{onClick:async()=>{try{await h.models.setDefaults({global:`${r.provider}:${r.id}`}),await k()}catch(p){g(p instanceof Error?p.message:t("models.setGlobalDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-accent-green/30 text-accent-green hover:bg-accent-green/10",title:t("models.setGlobalDefaultTitle"),children:t("chat.globalDefault")}),!r.isPlanDefault&&r.enabled!==!1&&e.jsx("button",{onClick:async()=>{try{await h.models.setDefaults({plan:`${r.provider}:${r.id}`}),await k()}catch(p){g(p instanceof Error?p.message:t("models.setPlanDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-accent-blue/30 text-accent-blue hover:bg-accent-blue/10",title:t("models.setPlanDefaultTitle"),children:t("chat.planDefault")}),r.isPlanDefault&&e.jsx("button",{onClick:async()=>{try{await h.models.setDefaults({plan:null}),await k()}catch(p){g(p instanceof Error?p.message:t("models.unsetPlanDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:bg-dark-hover",title:t("models.unsetPlanDefaultTitle"),children:t("models.unsetPlanDefault")}),!r.isActDefault&&r.enabled!==!1&&e.jsx("button",{onClick:async()=>{try{await h.models.setDefaults({act:`${r.provider}:${r.id}`}),await k()}catch(p){g(p instanceof Error?p.message:t("models.setActDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-accent-yellow/30 text-accent-yellow hover:bg-accent-yellow/10",title:t("models.setActDefaultTitle"),children:t("chat.actDefault")}),r.isActDefault&&e.jsx("button",{onClick:async()=>{try{await h.models.setDefaults({act:null}),await k()}catch(p){g(p instanceof Error?p.message:t("models.unsetActDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:bg-dark-hover",title:t("models.unsetActDefaultTitle"),children:t("models.unsetActDefault")}),!r.isGoalDefault&&r.enabled!==!1&&e.jsx("button",{onClick:async()=>{try{await h.models.setDefaults({goal:`${r.provider}:${r.id}`}),await k()}catch(p){g(p instanceof Error?p.message:t("models.setGoalDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-accent-purple/30 text-accent-purple hover:bg-accent-purple/10",title:t("models.setGoalDefaultTitle"),children:t("chat.goalDefault")}),r.isGoalDefault&&e.jsx("button",{onClick:async()=>{try{await h.models.setDefaults({goal:null}),await k()}catch(p){g(p instanceof Error?p.message:t("models.unsetGoalDefaultFailed"))}},className:"px-2 py-1 rounded text-[10px] border border-dark-border text-dark-muted hover:bg-dark-hover",title:t("models.unsetGoalDefaultTitle"),children:t("models.unsetGoalDefault")}),e.jsx("button",{onClick:()=>Ls(r),className:"p-1.5 rounded hover:bg-accent-blue/10 text-dark-muted hover:text-accent-blue",title:t("models.editModel"),children:e.jsx(is,{size:13})}),e.jsx("button",{onClick:()=>zs(r.provider,r.id),className:"p-1.5 rounded hover:bg-accent-red/10 text-dark-muted hover:text-accent-red",title:t("models.deleteModel"),children:e.jsx(Ie,{size:13})}),e.jsx("button",{onClick:()=>Fs(r),disabled:Ae===U(r),className:"p-1.5 rounded hover:bg-dark-hover disabled:opacity-50",title:t("models.refresh"),children:e.jsx(te,{size:13,className:Ae===U(r)?"animate-spin":""})}),e.jsx("button",{onClick:()=>$s(r),className:`px-2 py-0.5 rounded text-xs transition-colors ${r.enabled===!1?"bg-accent-green/20 text-accent-green hover:bg-accent-green/30":"bg-accent-red/20 text-accent-red hover:bg-accent-red/30"}`,children:r.enabled===!1?t("models.enable"):t("models.disable")})]})]})},U(r))}),s.models.length===0&&e.jsx("div",{className:"text-center text-[11px] text-dark-muted py-3",children:t("models.noModelsInProvider")})]})]},s.provider)}),P.length===0&&M.length===0&&e.jsxs("div",{className:"text-center text-dark-muted py-6",children:[e.jsx(Vs,{size:36,className:"mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:t("models.emptyHint")})]})]})]}),e.jsx(ms,{isOpen:fs,onClose:()=>{G(!1),H("select"),R(null),E("")},title:Ee==="select"?t("chat.selectProvider"):(Q==null?void 0:Q.name)||t("models.providerConfig"),size:"xl",children:Ee==="select"?e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[ie.filter(s=>s.key!=="custom").map(s=>e.jsxs("button",{onClick:()=>Ve(s),className:"text-left p-3 rounded-lg border border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(be,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium",children:s.name})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:s.defaultModel})]},s.key)),e.jsxs("button",{onClick:Pe,className:"text-left p-3 rounded-lg border border-dashed border-dark-border bg-dark-bg hover:border-accent-blue transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ws,{size:14,className:"text-accent-blue"}),e.jsx("span",{className:"text-sm font-medium",children:t("models.customProvider")})]}),e.jsx("div",{className:"text-xs text-dark-muted",children:t("models.customProviderDesc")})]})]})}):e.jsxs("div",{className:"space-y-3",children:[D==="custom"&&e.jsxs("div",{className:"space-y-3",children:[L&&L.keys.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.editExistingConfig")}),e.jsxs("select",{value:gs,onChange:s=>{const a=s.target.value;a?Ns(a):(E(""),j(l=>({...l,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:[e.jsx("option",{value:"",children:t("models.newCustomProviderOption")}),L.keys.map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.editExistingConfigHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.providerNameLabel")}),e.jsx("input",{value:m.providerKey,onChange:s=>j(a=>({...a,providerKey:s.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:t("models.providerNamePlaceholder")})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:["API Keys",(ts=(ss=n==null?void 0:n.providers)==null?void 0:ss[D==="custom"?m.providerKey.trim():D||""])!=null&&ts.hasApiKey?"":" *",e.jsx("span",{className:"text-dark-muted/60 text-xs",children:(ls=(as=n==null?void 0:n.providers)==null?void 0:as[D==="custom"?m.providerKey.trim():D||""])!=null&&ls.hasApiKey?t("models.apiKeysHintConfigured"):t("models.apiKeysHintNew")})]}),e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{rows:3,value:m.apiKeys,onChange:s=>j(a=>({...a,apiKeys:s.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:t("models.apiKeyMultiPlaceholder")}),e.jsx("button",{onClick:()=>X(s=>!s),className:"absolute right-2 top-2 text-dark-muted hover:text-white",children:vs?e.jsx(Ys,{size:14}):e.jsx(Qs,{size:14})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.modelIdLabel")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:m.modelIds,onChange:s=>{const a=s.target.value;j(l=>({...l,modelIds:a})),I(()=>{const l=new Set;for(const c of a.split(",")){const r=c.trim().split("|")[0].trim();r&&F.some(d=>d.id===r)&&l.add(r)}return l})},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:(Q==null?void 0:Q.defaultModel)||t("models.modelIdPlaceholder")}),e.jsxs("button",{onClick:ws,disabled:Ne||!m.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:t("models.fetchModelsTitle"),children:[Ne?e.jsx(te,{size:13,className:"animate-spin"}):e.jsx(Js,{size:13}),t(Ne?"models.fetchingModels":"models.fetchModels")]}),e.jsxs("button",{onClick:Cs,disabled:we||!m.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:t("models.testConnectionTitle"),children:[we?e.jsx(te,{size:13,className:"animate-spin"}):e.jsx(Xs,{size:13}),t(we?"models.testingConnection":"models.testConnection")]}),e.jsxs("button",{onClick:Us,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:t("models.catalogSearchTitle"),children:[e.jsx(ae,{size:13}),t("models.catalogSearch")]})]}),ce&&e.jsxs("div",{className:`mt-1 text-xs ${ce.ok?"text-accent-green":"text-accent-red"}`,children:[ce.ok?"✓ ":"✗ ",ce.message]}),Ge&&e.jsx("div",{className:"mt-1 text-xs text-accent-red",children:Ge}),F.length===0&&Ce.length>0&&e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("models.configuredPanelPrefix"),e.jsx("strong",{className:"text-dark-text",children:Ce.length}),t("models.configuredPanelSuffix"),e.jsx("span",{className:"text-accent-green/70",children:t("models.configuredPanelHint")})]})}),e.jsx("div",{className:"max-h-48 overflow-y-auto custom-scrollbar grid grid-cols-2 sm:grid-cols-3 gap-1",children:Ce.map(s=>{const a=m.modelIds.split(",").map(J).filter(Boolean).includes(s.id);return e.jsxs("div",{role:"checkbox","aria-checked":a,tabIndex:-1,onMouseDown:l=>l.preventDefault(),onClick:()=>Ts(s),className:`flex items-center gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${a?"bg-accent-green/20 text-accent-green border border-accent-green/30":"hover:bg-dark-hover border border-transparent"}`,children:[a?e.jsx(be,{size:10}):e.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"}),e.jsx("span",{className:"truncate",children:s.name||s.id}),s.isGlobalDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-green/20 shrink-0",children:t("models.globalShort")}),s.isPlanDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-blue/20 shrink-0",children:"Plan"}),s.isActDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-yellow/20 shrink-0",children:"Act"}),s.isGoalDefault&&e.jsx("span",{className:"text-[9px] px-1 rounded bg-accent-purple/20 shrink-0",children:"Goal"})]},s.id)})})]}),F.length>0&&e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg bg-dark-bg p-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-xs text-dark-muted",children:[t("models.fetchedPanelPrefix"),e.jsx("strong",{className:"text-dark-text",children:F.length}),t("models.fetchedPanelMiddle"),e.jsx("strong",{className:"text-accent-blue",children:ne.size}),t("models.fetchedPanelSuffix"),e.jsx("span",{className:"text-accent-blue/70",children:t("models.fetchedPanelHint")})]}),e.jsx("button",{onClick:()=>{q([]),I(new Set)},className:"px-2 py-0.5 text-[10px] border border-dark-border rounded hover:bg-dark-hover",children:t("models.close")})]}),e.jsxs("div",{className:"relative mb-2",children:[e.jsx(ae,{size:12,className:"absolute left-2 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:de,onChange:s=>ee(s.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("models.modelSearchPlaceholder")})]}),e.jsx("div",{className:"max-h-48 overflow-y-auto custom-scrollbar grid grid-cols-2 sm:grid-cols-3 gap-1",children:F.filter(s=>!de||s.id.toLowerCase().includes(de.toLowerCase())||s.name.toLowerCase().includes(de.toLowerCase())).map(s=>{const a=ne.has(s.id);return e.jsxs("div",{role:"checkbox","aria-checked":a,tabIndex:-1,onMouseDown:l=>l.preventDefault(),onClick:()=>Ps(s.id),className:`flex items-center gap-1.5 px-2 py-1 rounded cursor-pointer text-xs transition-colors select-none ${a?"bg-accent-blue/20 text-accent-blue border border-accent-blue/30":"hover:bg-dark-hover border border-transparent"}`,children:[a?e.jsx(be,{size:10}):e.jsx("div",{className:"w-2.5 h-2.5 rounded border border-dark-border"}),e.jsx("span",{className:"truncate",children:s.id})]},s.id)})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:"Base URL"}),e.jsx("input",{value:m.baseUrl,onChange:s=>{j(a=>({...a,baseUrl:s.target.value})),B(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"}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none mt-2",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":m.fullPath,onClick:()=>{j(s=>({...s,fullPath:!s.fullPath})),B(null)},className:`relative w-9 h-5 rounded-full transition-colors shrink-0 ${m.fullPath?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${m.fullPath?"translate-x-[18px]":"translate-x-0.5"}`})}),e.jsx("span",{className:"text-sm text-dark-muted",children:t("models.fullPathLabel")})]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.fullPathHint")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm text-dark-muted mb-1",children:t("models.apiTypeLabel")}),e.jsxs("select",{value:m.apiType,onChange:s=>{j(a=>({...a,apiType:s.target.value})),B(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:[e.jsx("option",{value:"",children:t("models.apiTypeAutoDetect")}),ps.map(s=>e.jsx("option",{value:s,children:fe[s]},s))]}),e.jsx("div",{className:"text-[11px] text-dark-muted/60 mt-1",children:t("models.apiTypeHint")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm text-dark-muted mb-1",children:[t("models.modelApiTypeLabel"),e.jsx("span",{className:"text-dark-muted/60 text-xs",children:t("models.modelApiTypeHint")})]}),e.jsx("div",{className:"border border-dark-border rounded-lg divide-y divide-dark-border max-h-40 overflow-y-auto custom-scrollbar",children:(()=>{const s=m.modelIds.split(",").map(J).filter(Boolean);return s.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t("models.modelApiTypeEmpty")}):s.map(a=>{var l;return e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5",children:[e.jsx("span",{className:"text-xs truncate min-w-0",children:a}),e.jsxs("select",{value:((l=m.modelOverrides[a])==null?void 0:l.apiType)||"",onChange:c=>j(r=>({...r,modelOverrides:{...r.modelOverrides,[a]:{...r.modelOverrides[a]||{},apiType:c.target.value}}})),className:"w-52 px-2 py-1 text-xs bg-dark-bg border border-dark-border rounded focus:outline-none focus:border-accent-blue",children:[e.jsx("option",{value:"",children:"继承 Provider(默认)"}),ps.map(c=>e.jsx("option",{value:c,children:fe[c]},c))]})]},a)})})()})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:m.setDefault,onChange:s=>j(a=>({...a,setDefault:s.target.checked})),className:"accent-accent-blue"}),e.jsx("span",{className:"text-sm text-dark-muted",children:t("models.setDefaultProvider")})]}),ze&&e.jsx("div",{className:"text-sm text-accent-red",children:ze}),e.jsxs("div",{className:"flex justify-between gap-2 pt-2",children:[e.jsx("div",{children:V&&((os=(rs=n==null?void 0:n.providers)==null?void 0:rs[V])==null?void 0:os.hasApiKey)&&e.jsx("button",{onClick:async()=>{if(confirm(t("models.deleteProviderConfirm",{key:V})))try{await h.config.provider.delete(V),G(!1),H("select"),R(null),E(""),await _(),await k()}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:t("models.deleteProvider")})}),e.jsx("button",{onClick:()=>{H("select"),R(null),E(""),G(!1)},className:"px-4 py-2 rounded border border-dark-border hover:bg-dark-hover transition-colors text-sm",children:t("common.cancel")}),e.jsx("button",{onClick:Rs,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:t($e?"common.saving":"common.save")})]})]})}),e.jsx(ms,{isOpen:Ds,onClose:()=>We(!1),title:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ae,{size:15,className:"text-accent-green"}),t("models.catalogTitle")]}),size:"2xl",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ae,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted"}),e.jsx("input",{value:Te,onChange:s=>Es(s.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:t("models.catalogSearchPlaceholder"),autoFocus:!0})]}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:xe,onChange:s=>{const a=s.target.checked;Is(a),se(Te,{reason:pe,tool:a})},className:"accent-accent-green"}),t("models.catalogOnlyToolCall")]}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-dark-muted whitespace-nowrap cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:pe,onChange:s=>{const a=s.target.checked;Ms(a),se(Te,{reason:a,tool:xe})},className:"accent-accent-green"}),t("models.catalogOnlyReasoning")]})]}),Xe&&e.jsx("div",{className:"text-xs text-accent-red bg-accent-red/10 p-2 rounded",children:Xe}),Ss?e.jsxs("div",{className:"flex items-center justify-center py-10 text-dark-muted",children:[e.jsx(te,{size:18,className:"animate-spin mr-2"})," ",t("models.searching")]}):e.jsx("div",{className:"max-h-96 overflow-y-auto custom-scrollbar border border-dark-border rounded-lg divide-y divide-dark-border",children:Qe.length===0?e.jsx("div",{className:"py-10 text-center text-dark-muted text-sm",children:t("models.catalogNoResults")}):Qe.map(s=>{var a,l,c;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 hover:bg-dark-hover",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-dark-text truncate",children:s.model.name||s.model.id}),e.jsx("code",{className:"text-[10px] px-1.5 py-0.5 bg-dark-bg border border-dark-border rounded text-dark-muted truncate",children:s.model.id}),s.model.reasoning&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-yellow/10 text-accent-yellow rounded",children:t("models.badgeReasoning")}),s.model.tool_call&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-blue/10 text-accent-blue rounded",children:t("models.badgeToolCall")}),s.model.attachment&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-green/10 text-accent-green rounded",children:t("models.badgeMultimodal")})]}),e.jsxs("div",{className:"text-[11px] text-dark-muted mt-0.5",children:[s.providerName,(a=s.model.limit)!=null&&a.context?` · ${t("models.ctxLimit",{k:(s.model.limit.context/1e3).toFixed(0)})}`:"",(l=s.model.limit)!=null&&l.output?` · ${t("models.outLimit",{k:(s.model.limit.output/1e3).toFixed(0)})}`:"",((c=s.model.cost)==null?void 0:c.input)!==void 0?` · $${s.model.cost.input}/M in / $${s.model.cost.output}/M out`:""]})]}),e.jsxs("button",{onClick:()=>As(s),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:t("models.catalogAddTitle"),children:[e.jsx(Me,{size:12})," ",t("models.add")]})]},`${s.providerId}:${s.model.id}`)})}),e.jsx("div",{className:"text-[11px] text-dark-muted/60",children:t("models.catalogSourceHint")})]})})]})})}function ve({title:y,value:b,color:C}){const t={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 e.jsxs("div",{className:`${t[C]} rounded-lg p-3`,children:[e.jsx("div",{className:"text-xs opacity-70",children:y}),e.jsx("div",{className:"text-xl font-semibold",children:b})]})}function ye({label:y,value:b}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-dark-muted",children:y}),e.jsx("div",{children:b})]})}function xs({label:y,value:b,onChange:C}){return e.jsxs("div",{children:[e.jsx("label",{className:"block text-[11px] text-dark-muted mb-1",children:y}),e.jsx("input",{type:"number",min:"0",value:b,onChange:t=>C(parseInt(t.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{mt as ModelsView,mt as default};
@@ -1,4 +0,0 @@
1
- import{j as e}from"./markdown-D-c9V8Xq.js";import{a as s,h as G,F as de,$ as _,a8 as xe,aO as ue,l as X,L as W,b as Z,ba as J,o as me,b1 as q,D as pe,k as he,aQ as ce,bb as ie,E as Y,bc as ge,bd as be,be as fe,al as je,O as ee,aR as ke,bf as te,_ as se,bg as ve,b4 as ye,t as we,bh as Ne,bi as Ce,a9 as Se,ac as Te}from"./icons-Di-qMB6n.js";import{a as E,t as h,u as H,d as ae,f as ze,U as Ee,V as $e,X as Oe,z as ne}from"./index-Dkxsd1Rx.js";import{n as Me,s as Be}from"./sttLanguages-BNRptAQA.js";import"./react-vendor-DU8XgZt2.js";import"./state-D2vcUGVk.js";import"./panels-CpHTincc.js";function Ie(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function De(t){return new Date(t).toLocaleString()}function Le(){const[t,d]=s.useState([]),[i,n]=s.useState(null),[p,l]=s.useState(""),[f,j]=s.useState(""),[k,x]=s.useState(!1),[v,N]=s.useState(!1),C=s.useCallback(async()=>{x(!0);try{const a=await E.config.files.list();a.success&&Array.isArray(a.data)&&d(a.data)}catch{h.error("Failed to load config files")}finally{x(!1)}},[]),y=s.useCallback(async a=>{try{const c=await E.config.files.read(a);if(c.success&&c.data){const u=c.data;n(u.name),l(u.content),j(u.content)}}catch{h.error(`Failed to read ${a}`)}},[]);s.useEffect(()=>{C()},[C]);const A=s.useCallback(async()=>{if(i){N(!0);try{const a=await E.config.files.write(i,p);a.success?(j(p),h.success(`${i} saved`),C()):h.error(a.error||"Failed to save")}catch{h.error("Failed to save file")}finally{N(!1)}}},[i,p,C]),g=p!==f,O=(i==null?void 0:i.endsWith(".yaml"))||(i==null?void 0:i.endsWith(".yml")),M=i==null?void 0:i.endsWith(".json"),P=a=>O?a.replace(/(#.*)$/,'<span class="text-dark-muted">$1</span>').replace(/^(\s*)([\w-]+)(:)/,'$1<span class="text-accent-blue">$2</span>$3').replace(/:\s+(true|false|null|~)(\s*)$/,': <span class="text-accent-purple">$1</span>$2').replace(/:\s+(\d+\.?\d*)(\s*)$/,': <span class="text-accent-green">$1</span>$2').replace(/:\s+"([^"]*)"(\s*)$/,': <span class="text-accent-yellow">"$1"</span>$2'):M?a.replace(/(\s*"[^"]*")(\s*:)/g,'<span class="text-accent-blue">$1</span>$2').replace(/:\s+(true|false|null)/g,': <span class="text-accent-purple">$1</span>').replace(/:\s+(\d+\.?\d*)/g,': <span class="text-accent-green">$1</span>').replace(/:\s+"([^"]*)"/g,': <span class="text-accent-yellow">"$1"</span>'):a;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-medium text-dark-text",children:"Config Files"}),e.jsx("button",{onClick:C,disabled:k,className:"p-1.5 rounded hover:bg-dark-hover transition-colors text-dark-muted",title:"Refresh file list",children:e.jsx(G,{size:14,className:k?"animate-spin":""})})]}),t.length===0&&!k&&e.jsx("p",{className:"text-xs text-dark-muted",children:"No config files found in ~/.agent/"}),t.length>0&&e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"w-48 shrink-0 space-y-0.5 max-h-[300px] overflow-y-auto custom-scrollbar",children:t.map(a=>e.jsxs("button",{onClick:()=>y(a.name),className:`w-full text-left px-2.5 py-1.5 rounded text-xs flex items-center gap-2 transition-colors ${i===a.name?"bg-accent-blue/10 text-accent-blue":"text-dark-text hover:bg-dark-hover"}`,children:[e.jsx(de,{size:12,className:"shrink-0"}),e.jsx("span",{className:"truncate flex-1",children:a.name}),!a.editable&&e.jsx("span",{className:"text-[10px] text-dark-muted shrink-0",title:"Read-only",children:"read"})]},a.name))}),i?e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx("span",{className:"text-dark-text font-medium",children:i}),t.find(a=>a.name===i)&&e.jsxs("span",{children:[Ie(t.find(a=>a.name===i).size)," · ",De(t.find(a=>a.name===i).modified)]}),g&&e.jsxs("span",{className:"text-accent-yellow flex items-center gap-1",children:[e.jsx(_,{size:10}),"unsaved changes"]})]}),e.jsxs("button",{onClick:A,disabled:!g||v,className:`flex items-center gap-1 px-2.5 py-1 rounded text-xs transition-all ${g?"bg-accent-blue text-white hover:opacity-90":"bg-dark-hover text-dark-muted cursor-not-allowed"}`,children:[e.jsx(xe,{size:12}),v?"Saving...":"Save"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"w-full h-[260px] p-3 rounded-lg bg-dark-bg border border-dark-border font-mono text-xs leading-relaxed overflow-auto custom-scrollbar pointer-events-none",dangerouslySetInnerHTML:{__html:p.split(`
2
- `).map(P).join(`
3
- `)||"&nbsp;"}}),e.jsx("textarea",{value:p,onChange:a=>l(a.target.value),className:"absolute inset-0 w-full h-full p-3 rounded-lg bg-transparent border border-dark-border font-mono text-xs leading-relaxed resize-none overflow-auto custom-scrollbar text-transparent caret-dark-text focus:outline-none focus:border-accent-blue/50",style:{color:"transparent"},spellCheck:!1})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-xs text-dark-muted",children:"Select a file to edit"})]})]})}function Re(){var m,w,T;const{t}=H(),[d,i]=s.useState(null),[n,p]=s.useState(null),[l,f]=s.useState({running:!1,logs:[]}),[j,k]=s.useState(!1),x=s.useRef(null),v=s.useRef(l),N=s.useRef(null),[C,y]=s.useState(()=>{try{return Me(localStorage.getItem("dsc.stt.lang"))}catch{return"en"}}),A=s.useCallback(o=>{y(o);try{localStorage.setItem("dsc.stt.lang",o)}catch{}window.dispatchEvent(new CustomEvent("stt-lang-changed",{detail:{lang:o}}))},[]);s.useEffect(()=>{v.current=l},[l]);const g=s.useCallback(async()=>{k(!0);const o=await E.stt.status();o.success&&o.data?(i(o.data),o.data.env&&p(o.data.env)):o.error&&h.error(o.error),k(!1)},[]);s.useEffect(()=>{g()},[g]);const O=s.useCallback(async()=>{const o=await E.stt.installStatus();if(o.success&&o.data){const L=v.current.running;f(o.data),o.data.running?x.current=window.setTimeout(()=>void O(),1e3):(g(),L&&o.data.status==="done"&&window.dispatchEvent(new CustomEvent("stt-backends-changed")))}},[g]);s.useEffect(()=>()=>{x.current&&window.clearTimeout(x.current)},[]),s.useEffect(()=>{N.current&&(N.current.scrollTop=N.current.scrollHeight)},[l.logs]);const M=s.useCallback(async o=>{var U,R,r,$;const L=await E.stt.install(o);L.success&&((U=L.data)!=null&&U.started)?(f({running:!0,backend:o,logs:[],status:"running"}),O()):(R=L.data)!=null&&R.alreadyRunning?(h.info(t("stt.setup.jobInProgress")),O()):f({running:!1,backend:o,logs:[],status:"error",error:L.error||((r=L.data)==null?void 0:r.error)||"install failed",manualCommand:($=L.data)==null?void 0:$.manualCommand})},[O,t]),P=s.useCallback(async()=>{await E.stt.cancelInstall(),O()},[O]),a=s.useCallback(o=>{navigator.clipboard.writeText(o).then(()=>h.success(t("stt.setup.copySuccess")),()=>h.error(t("stt.setup.copyFailed")))},[t]),c=l.running?l.backend:void 0,u=l.running,b=!u&&l.status==="done"&&l.backend?(m=d==null?void 0:d.backends)==null?void 0:m[l.backend]:void 0,S=b?!b.installed:!1,B=o=>o?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-accent-green/15 text-accent-green",children:[e.jsx(X,{size:12}),t("stt.setup.installed")]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-dark-hover text-dark-muted",children:[e.jsx(he,{size:12}),t("stt.setup.notInstalled")]}),D=(o,L,U)=>{var Q;const R=((Q=d==null?void 0:d.backends)==null?void 0:Q[o])??{installed:!1},r=c===o,$=u&&!r,z=o==="zh"?C==="zh":C!=="zh",I=o==="en"&&C!=="en"&&C!=="zh"?Be(C):null;return e.jsxs("div",{className:ae("rounded-lg border p-3 flex items-start justify-between gap-3 transition-colors cursor-pointer",z?"border-accent-blue/50 bg-accent-blue/5":"border-dark-border bg-dark-bg hover:border-dark-hover"),onClick:()=>A(o),children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:ae("w-9 h-9 shrink-0 rounded-lg flex items-center justify-center text-sm font-semibold",z?"bg-accent-blue/15 text-accent-blue":"bg-accent-blue/10 text-accent-blue"),children:o==="en"?"W":"F"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-dark-text",children:L}),B(R.installed),z&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-accent-blue/15 text-accent-blue",children:[e.jsx(J,{size:12}),t("stt.setup.inUse")]}),I&&e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-dark-hover text-dark-muted",children:I.label})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-[11px] text-dark-muted",children:[e.jsx("code",{className:"text-[10px] bg-dark-hover px-1.5 py-0.5 rounded",children:U}),e.jsx("span",{children:t(o==="en"?"stt.setup.whisperDesc":"stt.setup.funasrDesc")})]}),o==="zh"&&e.jsxs("p",{className:"mt-1 text-[11px] text-dark-muted flex items-center gap-1",children:[e.jsx(q,{size:11}),t("stt.setup.torchHint")]}),z&&!R.installed&&e.jsxs("p",{className:"mt-1 text-[11px] text-accent-orange flex items-center gap-1",children:[e.jsx(_,{size:11}),t("stt.setup.engineNotInstalledHint")]}),!R.installed&&R.error&&e.jsxs("p",{className:"mt-1 text-[11px] text-accent-orange break-all",title:R.error,children:[e.jsx(_,{size:11}),t("stt.setup.probeError"),R.error]})]})]}),e.jsx("div",{className:"shrink-0",onClick:oe=>oe.stopPropagation(),children:r?e.jsxs("button",{className:"btn btn-secondary cursor-not-allowed opacity-70",disabled:!0,children:[e.jsx(W,{size:14,className:"animate-spin"}),t("stt.setup.installing")]}):$?e.jsx("button",{className:"btn btn-secondary cursor-not-allowed opacity-50",disabled:!0,children:t("stt.setup.installing")}):R.installed?e.jsxs("button",{className:"btn btn-ghost",onClick:()=>void g(),title:t("stt.setup.recheck"),children:[e.jsx(G,{size:14}),t("stt.setup.recheck")]}):e.jsxs("button",{className:"btn btn-accent",onClick:()=>void M(o),children:[e.jsx(pe,{size:14}),t("stt.setup.install")]})})]})},K=(n==null?void 0:n.pythonAvailable)&&(n==null?void 0:n.pipAvailable);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-bg p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-dark-text",children:[e.jsx(ue,{size:14,className:"text-accent-blue"}),t("stt.setup.envCard")]}),e.jsxs("button",{className:"btn btn-ghost",onClick:()=>void g(),disabled:j,children:[e.jsx(G,{size:13,className:j?"animate-spin":""}),t("stt.setup.recheck")]})]}),e.jsxs("div",{className:"mt-2.5 space-y-2",children:[n?n.pythonAvailable?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-text",children:[e.jsx(X,{size:13,className:"text-accent-green"}),t("stt.setup.pythonOk",{version:(n.pythonVersion||"").replace(/^Python\s*/i,"")||n.pythonPath||"Python"}),n.pythonPath?e.jsx("code",{className:"text-[10px] text-dark-muted",children:n.pythonPath}):null]}):e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-accent-red/30 bg-accent-red/5 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-red",children:[e.jsx(_,{size:13}),t("stt.setup.pythonMissing")]}),e.jsx("a",{className:"btn btn-secondary !py-1 !px-2 text-xs",href:"https://www.python.org/downloads/",target:"_blank",rel:"noreferrer",children:t("stt.setup.pythonGuide")})]}):e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx(W,{size:13,className:"animate-spin"}),t("stt.setup.envChecking")]}),n&&!n.pipAvailable&&e.jsxs("div",{className:"rounded-md border border-accent-red/30 bg-accent-red/5 px-2.5 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-red",children:[e.jsx(_,{size:13}),t("stt.setup.pipMissing")]}),e.jsxs("div",{className:"mt-1.5",children:[e.jsx("div",{className:"text-[10px] text-dark-muted mb-1",children:t("stt.setup.pipGuide")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("code",{className:"flex-1 rounded bg-dark-bg border border-dark-border px-2 py-1 font-mono text-[10px] text-dark-text break-all select-all",children:[n.pythonPath||"python"," -m ensurepip --upgrade"]}),e.jsx("button",{className:"btn btn-ghost !py-1 !px-2 text-xs",onClick:()=>a(`${n.pythonPath||"python"} -m ensurepip --upgrade`),children:e.jsx(Z,{size:12})})]})]})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-dark-text",children:[e.jsx(J,{size:14,className:"text-accent-blue"}),t("stt.setup.defaultEngine")]}),e.jsx("p",{className:"mt-1 text-[11px] text-dark-muted",children:t("stt.setup.defaultEngineHint")})]}),D("en",t("stt.setup.whisperTitle"),"base.en"),D("zh",t("stt.setup.funasrTitle"),"paraformer-zh"),u&&e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-bg p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-blue font-medium",children:[e.jsx(W,{size:13,className:"animate-spin"}),t("stt.setup.installing"),e.jsxs("span",{className:"text-dark-muted font-normal",children:["(",c==="en"?"whisper":"funasr",")"]})]}),e.jsx("button",{className:"btn btn-danger !py-1 !px-2 text-xs",onClick:()=>void P(),children:t("stt.setup.cancel")})]}),e.jsx("div",{ref:N,className:"rounded-md border border-dark-border bg-dark-bg p-2.5 font-mono text-[11px] text-dark-muted overflow-auto max-h-48 whitespace-pre-wrap custom-scrollbar",children:l.logs.length===0?e.jsx("span",{className:"text-dark-muted/70",children:t("stt.setup.logWaiting")}):l.logs.join(`
4
- `)})]}),!u&&l.status&&l.status!=="done"&&e.jsxs("div",{className:"rounded-lg border border-accent-red/30 bg-accent-red/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-red font-medium",children:[e.jsx(_,{size:13}),l.status==="timeout"?t("stt.setup.installTimeout"):l.status==="cancelled"?t("stt.setup.installCancelled"):t("stt.setup.installFailed")]}),l.error?e.jsx("p",{className:"mt-1 text-xs text-accent-red/90 break-all",children:l.error}):null,(l.manualCommand||l.status==="error"&&c)&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"text-[10px] text-dark-muted mb-1 flex items-center gap-1",children:[e.jsx(me,{size:11}),t("stt.setup.manualCommand")]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("code",{className:"flex-1 rounded bg-dark-bg border border-dark-border px-2 py-1.5 font-mono text-[10px] text-dark-text break-all whitespace-pre-wrap select-all",children:l.manualCommand??(c==="zh"?`${(n==null?void 0:n.pythonPath)||"python"} -m pip install -U "funasr>=1.1.0" "modelscope>=1.15.0" "torch>=2.0.0"`:`${(n==null?void 0:n.pythonPath)||"python"} -m pip install "faster-whisper>=1.0.0"`)}),l.manualCommand&&e.jsxs("button",{className:"btn btn-ghost !py-1 !px-2 text-xs shrink-0",onClick:()=>a(l.manualCommand),children:[e.jsx(Z,{size:12}),t("stt.setup.copyCommand")]})]})]})]}),!u&&l.status==="done"&&!S&&e.jsxs("div",{className:"rounded-lg border border-accent-green/30 bg-accent-green/5 px-3 py-2.5 flex items-center gap-2 text-xs text-accent-green",children:[e.jsx(X,{size:14}),t("stt.setup.installDone")]}),!u&&l.status==="done"&&S&&e.jsxs("div",{className:"rounded-lg border border-accent-orange/30 bg-accent-orange/5 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-accent-orange font-medium",children:[e.jsx(_,{size:13}),t("stt.setup.installDoneButMissing")]}),(b==null?void 0:b.error)&&e.jsx("p",{className:"mt-1 text-xs text-accent-orange/90 break-all",children:b.error}),e.jsx("p",{className:"mt-1 text-[11px] text-dark-muted",children:t("stt.setup.installDoneButMissingHint")})]}),!u&&K&&d&&!((w=d.backends.en)!=null&&w.installed)&&!((T=d.backends.zh)!=null&&T.installed)&&e.jsx("p",{className:"text-[11px] text-dark-muted px-1",children:t("stt.setup.chooseHint")})]})}const re=["google-workspace","gmail","ms365-graph","x-twitter"],Ae={"google-workspace":ie,gmail:fe,"ms365-graph":be,"x-twitter":ge},Fe={"google-workspace":"Google Workspace",gmail:"Gmail","ms365-graph":"Microsoft 365","x-twitter":"X / Twitter"},Pe={ready:"text-accent-green",installed:"text-dark-muted",connecting:"text-accent-yellow",installing:"text-accent-yellow",error:"text-accent-red",disabled:"text-dark-muted","not-installed":"text-dark-muted"};function _e({onNavigate:t}){const{t:d}=H(),[i,n]=s.useState(null),[p,l]=s.useState(!1),[f,j]=s.useState([]),[k,x]=s.useState(!0),[v,N]=s.useState(null),[C,y]=s.useState(null),A=s.useCallback(async()=>{l(!0);try{const a=await E.tools.get("computer_use");n(a.success&&a.data?!!a.data.enabled:!1)}catch{n(!1)}l(!1)},[]),g=s.useCallback(async()=>{var c;x(!0),y(null);const a=await E.connectors.list();a.success&&Array.isArray((c=a.data)==null?void 0:c.connectors)?j(a.data.connectors.filter(u=>re.includes(u.id))):y(a.error||d("settings.capabilities.loadFailed")),x(!1)},[d]);s.useEffect(()=>{A(),g()},[]);const O=async()=>{if(i===null)return;const a=!i;N("computer_use");try{const c=await E.tools.toggle("computer_use",a);c.success?n(a):y(c.error||d("settings.capabilities.toggleFailed"))}catch(c){y(c instanceof Error?c.message:String(c))}N(null)},M=async a=>{const c=!a.enabled;if(c&&a.missingEnv&&a.missingEnv.length>0){t==null||t("connectors");return}N(a.id),y(null),j(u=>u.map(b=>b.id===a.id?{...b,enabled:c,status:c?"connecting":"disabled"}:b));try{const u=await E.connectors.toggle(a.id,c);if(u.success&&u.data){const b=u.data;j(S=>S.map(B=>B.id===b.id?b:B))}else y(u.error||d("settings.capabilities.toggleFailed")),g()}catch(u){y(u instanceof Error?u.message:String(u)),g()}N(null)},P=a=>{if(a.missingEnv&&a.missingEnv.length>0)return`${d("connectors.needCredentials")} ${a.missingEnv.join(", ")}`;const c=a.status==="not-installed"?"notInstalled":a.status;return d(`connectors.${c}`)||a.status};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 py-1",children:[e.jsxs("div",{className:"min-w-0 flex items-start gap-2",children:[e.jsx(ce,{size:16,className:"text-accent-blue mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-dark-text",children:"Computer Use"}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:"GUI 截屏 + 鼠标键盘操控(Windows)。每次调用需审批;需要视觉模型读屏。"})]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":!!i,disabled:p||v==="computer_use",onClick:O,className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:opacity-50 ${i?"bg-accent-blue":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${i?"translate-x-[18px]":"translate-x-0.5"}`})})]}),e.jsxs("div",{className:"pt-3 border-t border-dark-border",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"text-xs font-semibold text-dark-text flex items-center gap-1.5",children:[e.jsx(ie,{size:13,className:"text-accent-purple"}),"Grok 式连接器(Gmail / Workspace / M365 / X)"]}),e.jsxs("button",{onClick:()=>t==null?void 0:t("connectors"),className:"text-xs text-dark-muted hover:text-accent-blue flex items-center gap-1 transition-colors",children:["全部管理",e.jsx(Y,{size:11})]})]}),k?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted py-2",children:[e.jsx(W,{size:12,className:"animate-spin"}),"Loading..."]}):e.jsx("div",{className:"space-y-1",children:re.map(a=>{const c=f.find(D=>D.id===a),u=Ae[a]??Ke,b=v===a,S=(c==null?void 0:c.missingEnv)&&c.missingEnv.length>0,B=c?Pe[c.status]??"text-dark-muted":"text-dark-muted";return e.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm text-dark-text flex items-center gap-1.5 truncate",children:[e.jsx(u,{size:14,className:"shrink-0 text-dark-muted"}),Fe[a],S&&e.jsx(_,{size:12,className:"text-accent-yellow shrink-0"})]}),c&&e.jsxs("div",{className:`text-[11px] mt-0.5 flex items-center gap-1 ${B}`,children:[c.status==="ready"?e.jsx(X,{size:10}):null,P(c),typeof c.toolCount=="number"&&c.toolCount>0?` · ${d("connectors.toolCount",{count:c.toolCount})}`:""]})]}),c?e.jsx("button",{type:"button",role:"switch","aria-checked":c.enabled,disabled:b,onClick:()=>M(c),className:`relative w-9 h-5 rounded-full transition-colors shrink-0 disabled:opacity-50 ${c.enabled?"bg-accent-blue":"bg-dark-border"}`,children:b?e.jsx(W,{size:12,className:"absolute left-[7px] top-[3px] animate-spin text-white"}):e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${c.enabled?"translate-x-[18px]":"translate-x-0.5"}`})}):e.jsx("button",{onClick:()=>t==null?void 0:t("connectors"),className:"text-xs text-dark-muted hover:text-accent-blue shrink-0 transition-colors",children:"添加"})]},a)})})]}),e.jsxs("div",{className:"pt-3 border-t border-dark-border flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex items-start gap-2",children:[e.jsx(q,{size:16,className:"text-accent-yellow mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-dark-text",children:"xAI (Grok) API"}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:"官方 OpenAI 兼容端点,支持 X 实时数据的 Grok 系列模型。"})]})]}),e.jsxs("button",{onClick:()=>t==null?void 0:t("models"),className:"flex items-center gap-1.5 px-3 py-1.5 bg-accent-blue/10 text-accent-blue border border-accent-blue/30 rounded-lg hover:bg-accent-blue/20 transition-colors text-xs shrink-0",children:["配置",e.jsx(Y,{size:11})]})]}),C&&e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs text-accent-red bg-accent-red/10 border border-accent-red/30 rounded-lg px-3 py-2",children:[e.jsx("span",{className:"truncate",children:C}),e.jsxs("button",{onClick:()=>{g(),A(),y(null)},className:"shrink-0 hover:text-accent-red/80 flex items-center gap-1",children:[e.jsx(G,{size:11}),"重试"]})]})]})}function Ke(t){return e.jsxs("svg",{width:t.size??14,height:t.size??14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:t.className,children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z"})]})}function V({label:t,value:d,onChange:i,min:n,max:p,disabled:l,envOverridden:f,hint:j}){return e.jsxs("div",{className:"mb-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-muted mb-1",children:[t,f&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-accent-yellow",title:j,children:[e.jsx(_,{size:12})," env"]})]}),e.jsx("input",{type:"number",value:d,onChange:k=>i(k.target.value),min:n,max:p,disabled:l||f,className:"w-40 bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all disabled:opacity-50"})]})}function Ue(){const{t}=H(),[d,i]=s.useState(!0),[n,p]=s.useState(!1),[l,f]=s.useState({}),[j,k]=s.useState(!1),[x,v]=s.useState(""),[N,C]=s.useState(null),[y,A]=s.useState(!1),[g,O]=s.useState(""),[M,P]=s.useState(""),[a,c]=s.useState(""),[u,b]=s.useState(""),[S,B]=s.useState(""),D=s.useCallback(async()=>{i(!0);try{const m=await E.config.context.get();if(m.success&&m.data){const w=m.data.values??{};f(m.data.envOverridden??{}),k(m.data.effective.offload),v(m.data.defaultArtifactRoot??""),C(m.data.stats??null),A(!!w.artifactOffload),O(typeof w.artifactDir=="string"?w.artifactDir:""),P(w.artifactMaxTotalMb!=null?String(w.artifactMaxTotalMb):""),c(w.artifactTtlDays!=null?String(w.artifactTtlDays):""),b(w.outboundToolBytes!=null?String(w.outboundToolBytes):""),B(w.turnBudgetTokens!=null?String(w.turnBudgetTokens):"")}}catch{}i(!1)},[]);s.useEffect(()=>{D()},[D]);const K=async()=>{p(!0);try{const m={artifactOffload:y};l.artifactDir||(m.artifactDir=g.trim()||null),!l.artifactMaxTotalMb&&M.trim()&&(m.artifactMaxTotalMb=parseInt(M,10)),!l.artifactTtlDays&&a.trim()&&(m.artifactTtlDays=parseInt(a,10)),!l.outboundToolBytes&&u.trim()&&(m.outboundToolBytes=parseInt(u,10)),!l.turnBudgetTokens&&S.trim()&&(m.turnBudgetTokens=parseInt(S,10));for(const T of["artifactMaxTotalMb","artifactTtlDays","outboundToolBytes","turnBudgetTokens"])if(T in m&&(isNaN(m[T])||m[T]<=0)){h.error(t("settings.contextOffload.invalidNumber")),p(!1);return}const w=await E.config.context.save(m);w.success?(h.success(t("settings.contextOffload.saved")),await D()):h.error(w.error||t("settings.contextOffload.saveFailed"))}catch(m){h.error(m instanceof Error?m.message:String(m))}p(!1)};return d?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-dark-muted py-2",children:[e.jsx(W,{size:14,className:"animate-spin"}),t("common.loading")]}):e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:t("settings.contextOffload.desc")}),e.jsxs("label",{className:"flex items-center justify-between mb-4 cursor-pointer",children:[e.jsxs("span",{className:"text-sm",children:[t("settings.contextOffload.enableLabel"),e.jsxs("span",{className:`ml-2 text-xs ${j?"text-accent-green":"text-dark-muted"}`,children:["(",t("settings.contextOffload.currently"),": ",j?"ON":"OFF",")"]})]}),e.jsx("button",{role:"switch","aria-checked":y,onClick:()=>A(!y),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${y?"bg-accent-green":"bg-dark-border"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${y?"translate-x-6":"translate-x-1"}`})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-6",children:[e.jsx(V,{label:t("settings.contextOffload.maxTotalMb"),value:M,onChange:P,min:1,envOverridden:l.artifactMaxTotalMb}),e.jsx(V,{label:t("settings.contextOffload.ttlDays"),value:a,onChange:c,min:1,max:365,envOverridden:l.artifactTtlDays}),e.jsx(V,{label:`${t("settings.contextOffload.outboundBytes")} (${t("settings.contextOffload.optional")})`,value:u,onChange:b,min:1024,envOverridden:l.outboundToolBytes}),e.jsx(V,{label:t("settings.contextOffload.turnBudget"),value:S,onChange:B,min:1e3,envOverridden:l.turnBudgetTokens})]}),e.jsxs("div",{className:"mb-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm text-dark-muted mb-1",children:[t("settings.contextOffload.dir")," (",t("settings.contextOffload.optional"),")",l.artifactDir&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-accent-yellow",children:[e.jsx(_,{size:12})," env"]})]}),e.jsx("input",{type:"text",value:g,onChange:m=>O(m.target.value),disabled:l.artifactDir,placeholder:x,className:"w-full bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all disabled:opacity-50"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:K,disabled:n||d,className:"px-3 py-1.5 rounded-lg text-sm bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:t(n?"common.saving":"common.save")}),e.jsx("span",{className:"text-xs text-dark-muted",children:t("settings.contextOffload.envHint")})]}),N&&N.count>0&&e.jsx("p",{className:"text-xs text-dark-muted mt-2",children:t("settings.contextOffload.stats",{count:N.count,size:(N.totalBytes/1024/1024).toFixed(1)})})]})}const We=s.memo(function({nameKey:d,descriptionKey:i,colors:n,isSelected:p,onClick:l}){const{t:f}=H(),j=["bg","surface","border","text","muted","accentBlue","accentGreen","accentRed","accentYellow","accentPurple"];return e.jsxs("button",{onClick:l,className:`relative flex flex-col items-center rounded-xl p-2 transition-all focus:outline-none focus:ring-2 focus:ring-accent-blue/50 ${p?"ring-2 ring-accent-blue/60 bg-dark-bg border border-accent-blue/40 shadow-sm":"border border-dark-border hover:border-accent-blue/30 bg-dark-bg hover:shadow-sm"}`,title:f(i),"aria-pressed":p,"aria-label":f(d),children:[e.jsx("div",{className:"flex gap-[2px] rounded-md overflow-hidden w-full h-8 mb-1.5 border border-dark-border/40",children:j.map(k=>e.jsx("div",{className:"flex-1",style:{backgroundColor:n[k]},title:k},k))}),e.jsx("span",{className:`text-[11px] font-medium truncate w-full text-center ${p?"text-accent-blue":"text-dark-text"}`,children:f(d)}),p&&e.jsx("span",{className:"absolute top-1 right-1 w-4 h-4 bg-accent-blue rounded-full flex items-center justify-center shadow-sm",children:e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",fill:"none",children:e.jsx("path",{d:"M1.5 4L3.5 6L6.5 2",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})}),Ge="1.0.0",He={version:Ge},le=[{key:"bg",labelKey:"settings.colorBg"},{key:"surface",labelKey:"settings.colorSurface"},{key:"border",labelKey:"settings.colorBorder"},{key:"text",labelKey:"settings.colorText"},{key:"muted",labelKey:"settings.colorMuted"},{key:"accentBlue",labelKey:"settings.colorAccentBlue"},{key:"accentGreen",labelKey:"settings.colorAccentGreen"},{key:"accentRed",labelKey:"settings.colorAccentRed"},{key:"accentYellow",labelKey:"settings.colorAccentYellow"},{key:"accentPurple",labelKey:"settings.colorAccentPurple"}],Ve={language:["language","lang","Chinese","中文","English","en","zh"],theme:["theme","dark","light","color","palette","custom"],display:["display","view","developer","activity","界面","视图","开发者","活动"],provider:["provider","model","api","key","openai","anthropic","deepseek"],context:["context","max","window","token","上下文","offload","artifact","外置"],configFiles:["config","file","yaml","json","editor"],capabilities:["capabilities","computer","use","gmail","google","workspace","sharepoint","m365","twitter","x","grok","xai","connector","agent","能力","电脑","推特"],system:["system","server","uptime","restart","reboot"],about:["about","version","info"],stt:["voice","语音","stt","whisper","funasr","安装","install","python","pip","speech"]},st=s.memo(function({onNavigate:d,focusSection:i}){const{t:n}=H(),{theme:p,setTheme:l,themePresetId:f,setThemePreset:j,language:k,setLanguage:x,customTheme:v,customThemeEnabled:N,setCustomTheme:C,setCustomThemeEnabled:y,resetCustomTheme:A,developerView:g,setDeveloperView:O}=ze(),[M,P]=s.useState(N),a=s.useMemo(()=>p==="dark"?"dark":p==="light"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",[p]),c=s.useMemo(()=>Object.values(Ee),[]),[u,b]=s.useState(0),[S,B]=s.useState(!1),[D,K]=s.useState(!1),[m,w]=s.useState(""),T=s.useCallback(r=>{if(!m.trim())return!0;const $=m.toLowerCase().trim();return(Ve[r]??[]).some(I=>I.toLowerCase().includes($))},[m]),o=s.useRef(null);s.useEffect(()=>{var r;(i==null?void 0:i.section)==="stt"&&((r=o.current)==null||r.scrollIntoView({behavior:"smooth",block:"start"}))},[i==null?void 0:i.nonce]),s.useEffect(()=>{let r=!0;const $=async()=>{try{const I=await E.system.status();r&&I.success&&I.data&&b(I.data.uptime)}catch{}};$();const z=setInterval($,S?2e3:1e4);return()=>{r=!1,clearInterval(z)}},[S]);const L=s.useCallback(async()=>{if(window.confirm("Restart the server? All active sessions will be disconnected.")){B(!0);try{const r=await E.system.restart();r.success?h.info("Server restarting..."):(h.error(r.error||"Restart failed"),B(!1))}catch{h.error("Failed to send restart request"),B(!1)}}},[]),U=s.useCallback(async()=>{if(window.confirm("Shut down the server? This will stop the entire backend process.")&&window.confirm("Are you sure? All active sessions and unsaved work will be lost.")){K(!0);try{const r=await E.system.shutdown();r.success?h.info("Server shutting down..."):(h.error(r.error||"Shutdown failed"),K(!1))}catch{h.error("Failed to send shutdown request"),K(!1)}}},[]);s.useEffect(()=>{S&&u<1e4&&(B(!1),h.success("Server restarted"))},[u,S]);const R=r=>{const $=Math.floor(r/1e3),z=Math.floor($/60),I=Math.floor(z/60);return I>0?`${I}h ${z%60}m`:z>0?`${z}m ${$%60}s`:`${$}s`};return e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar p-4 bg-transparent",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 gap-4 rounded-xl border border-dark-border bg-dark-surface p-3",children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2 shrink-0",children:[e.jsx(je,{size:18,className:"text-accent-blue"}),n("settings.title")]}),e.jsxs("div",{className:"relative flex-1 max-w-xs",children:[e.jsx(ee,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-dark-muted pointer-events-none"}),e.jsx("input",{type:"text",value:m,onChange:r=>w(r.target.value),placeholder:"Search settings...",className:"w-full bg-dark-bg border border-dark-border rounded-lg pl-9 pr-3 py-1.5 text-sm text-dark-text placeholder-dark-muted focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all"}),m&&e.jsx("button",{onClick:()=>w(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-dark-muted hover:text-dark-text text-xs p-1 rounded",children:"×"})]})]}),e.jsxs("div",{className:"space-y-5 max-w-3xl",children:[T("language")&&e.jsx(F,{icon:ke,iconColor:"text-accent-blue",title:n("settings.language"),children:e.jsx("div",{className:"flex gap-2",children:["zh-CN","en"].map(r=>e.jsx("button",{onClick:()=>x(r),className:`px-4 py-2 rounded-lg transition-all ${k===r?"bg-accent-blue text-white":"bg-dark-hover text-dark-text hover:bg-dark-border"}`,children:n(r==="zh-CN"?"settings.languageZh":"settings.languageEn")},r))})}),T("theme")&&e.jsxs(F,{icon:te,iconColor:"text-accent-purple",title:n("settings.theme"),children:[e.jsx("div",{className:"flex gap-2 mb-4",children:["dark","light","auto"].map(r=>e.jsx("button",{onClick:()=>l(r),className:`px-4 py-2 rounded-lg transition-all ${p===r?"bg-accent-blue text-white":"bg-dark-hover text-dark-text hover:bg-dark-border"}`,children:n(r==="dark"?"settings.themeDark":r==="light"?"settings.themeLight":"settings.themeAuto")},r))}),e.jsxs("div",{className:"mb-4",children:[e.jsx("h4",{className:"text-xs font-semibold text-dark-text mb-2",children:n("settings.themePresets")}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2",children:c.map(r=>{if(!r)return null;const $=(f||$e)===r.id,z=a==="dark"?r.dark:r.light;return e.jsx(We,{id:r.id,nameKey:r.nameKey,descriptionKey:r.descriptionKey,colors:z,isSelected:$,onClick:()=>j(r.id)},r.id)})})]}),e.jsxs("div",{className:"pt-4 border-t border-dark-border",children:[e.jsxs("button",{onClick:()=>{const r=!M;P(r),y(r)},className:"flex items-center gap-2 text-sm text-dark-muted hover:text-dark-text transition-colors",children:[e.jsx(te,{size:14}),e.jsx("span",{children:n("settings.customOverrides")}),e.jsx("span",{className:`w-8 h-4 rounded-full transition-colors ${M?"bg-accent-blue":"bg-dark-border"}`,children:e.jsx("span",{className:`block w-3 h-3 rounded-full bg-white transition-transform mt-0.5 ${M?"ml-4":"ml-0.5"}`})})]}),M&&e.jsx("p",{className:"text-[10px] text-dark-muted mt-1 mb-2",children:n("settings.customOverridesHint")}),M&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"flex gap-1 mb-3 rounded-lg overflow-hidden h-6",children:le.map(({key:r})=>e.jsx("div",{className:"flex-1",style:{backgroundColor:v[r]},title:r},r))}),e.jsx("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2",children:le.map(({key:r,labelKey:$})=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:v[r],onChange:z=>C({[r]:z.target.value}),className:"w-8 h-8 rounded border border-dark-border cursor-pointer bg-transparent p-0.5 shrink-0"}),e.jsx("span",{className:"text-xs text-dark-muted flex-1 truncate",children:n($)}),e.jsx("input",{type:"text",value:v[r],onChange:z=>{const I=z.target.value;/^#[0-9a-fA-F]{0,6}$/.test(I)&&C({[r]:I})},className:"w-16 bg-dark-bg border border-dark-border rounded px-1 py-0.5 text-xs text-dark-text font-mono text-center",maxLength:7})]},r))}),e.jsx("button",{onClick:A,className:"mt-2 text-xs text-dark-muted hover:text-accent-red transition-colors",children:n("settings.resetColors")})]})]})]}),T("display")&&e.jsx(F,{icon:se,iconColor:"text-accent-blue",title:n("settings.display"),children:e.jsxs("label",{className:"flex items-center justify-between gap-3 py-1 cursor-pointer",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-dark-text",children:n("settings.developerView")}),e.jsx("div",{className:"text-xs text-dark-muted mt-0.5",children:n("settings.developerViewHint")})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":g,onClick:()=>O(!g),className:`relative w-9 h-5 rounded-full transition-colors shrink-0 ${g?"bg-accent-blue":"bg-dark-border"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0 w-4 h-4 rounded-full bg-white shadow transition-transform ${g?"translate-x-[18px]":"translate-x-0.5"}`})})]})}),T("provider")&&e.jsxs(F,{icon:q,iconColor:"text-accent-yellow",title:"Provider & Models",children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:"Configure AI providers, API keys, and model settings. Add or remove providers like OpenAI, Anthropic, DeepSeek, and more."}),e.jsxs("button",{onClick:()=>d==null?void 0:d("models"),className:"flex items-center gap-2 px-4 py-2 bg-accent-blue text-white rounded-lg hover:opacity-90 transition-opacity text-sm w-fit",children:[e.jsx(Y,{size:14}),"Manage Providers & Models"]})]}),T("capabilities")&&e.jsx(F,{icon:ce,iconColor:"text-accent-green",title:n("settings.capabilities.title"),children:e.jsx(_e,{onNavigate:d})}),T("context")&&e.jsx(F,{icon:ve,iconColor:"text-accent-blue",title:"Max Context",children:e.jsx(Xe,{})}),T("context")&&e.jsx(F,{icon:se,iconColor:"text-accent-purple",title:n("settings.contextOffload.title"),children:e.jsx(Ue,{})}),T("stt")&&e.jsx(F,{icon:ye,iconColor:"text-accent-blue",title:n("stt.setup.title"),children:e.jsx("div",{ref:o,id:"settings-section-stt",className:"scroll-mt-4",children:e.jsx(Re,{})})}),T("configFiles")&&e.jsx(F,{icon:we,iconColor:"text-accent-green",title:"Config Files (~/.agent/)",children:e.jsx(Le,{})}),T("system")&&e.jsx(F,{icon:Ne,iconColor:"text-dark-muted",title:"System",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-dark-muted",children:"Server Uptime"}),e.jsx("span",{className:"text-dark-text font-mono",children:R(u)})]}),e.jsxs("button",{onClick:L,disabled:S,className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm transition-all ${S?"bg-dark-hover text-dark-muted cursor-wait":"bg-accent-red/10 text-accent-red hover:bg-accent-red/20 border border-accent-red/30"}`,children:[e.jsx(G,{size:14,className:S?"animate-spin":""}),S?"Restarting...":"Restart Server"]}),e.jsxs("button",{onClick:U,disabled:D,className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm transition-all ${D?"bg-dark-hover text-dark-muted cursor-wait":"bg-accent-red/10 text-accent-red hover:bg-accent-red/20 border border-accent-red/30"}`,children:[e.jsx(Ce,{size:14,className:D?"animate-pulse":""}),D?"Shutting Down...":"Shutdown Server"]})]})}),T("about")&&e.jsx(F,{icon:Se,iconColor:"text-accent-blue",title:n("settings.about"),children:e.jsxs("div",{className:"text-sm text-dark-muted space-y-2",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-dark-text",children:"DeepSeekCode Web"})," v",He.version]}),e.jsx("p",{children:n("settings.aboutDesc")}),e.jsx("p",{className:"text-xs",children:"Powered by React + TypeScript + TailwindCSS"}),e.jsx("p",{className:"text-xs",children:"联系:ngwlh2026@gmail.com"}),e.jsxs("button",{onClick:()=>Oe.getState().openWhatsNew(),className:"mt-2 flex items-center gap-2 px-4 py-2 rounded-lg text-sm transition-all bg-accent-blue/10 text-accent-blue hover:bg-accent-blue/20 border border-accent-blue/30",children:[e.jsx(Te,{size:14}),n("settings.whatsNew")]})]})}),m.trim()&&!["language","theme","provider","capabilities","context","stt","configFiles","system","about"].some(T)&&e.jsxs("div",{className:"text-center py-12 text-dark-muted",children:[e.jsx(ee,{size:32,className:"mx-auto mb-2 opacity-40"}),e.jsxs("p",{className:"text-sm",children:["No settings match “",m,"”"]})]})]})]})});function Xe(){const t=ne(x=>x.maxContextTokens),d=ne(x=>x.setMaxContextTokens),[i,n]=s.useState(String(t)),[p,l]=s.useState(!1),f=[32e3,64e3,128e3,256e3,512e3,1e6,2e6],j=async()=>{const x=parseInt(i,10);if(!(isNaN(x)||x<1e3)){l(!0),d(x);try{await E.config.provider.save({contextWindow:x}),h.success("Context window saved")}catch(v){h.error("Failed to save context window: "+(v instanceof Error?v.message:"Unknown error"))}l(!1)}},k=x=>x>=1e6?(x/1e6).toFixed(0)+"M":(x/1e3).toFixed(0)+"K";return e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-dark-muted mb-3",children:"Set the maximum context window (in tokens) for your AI model. This controls how the progress bar and usage percentage are calculated."}),e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("input",{type:"number",value:i,onChange:x=>n(x.target.value),min:1e3,max:1e7,step:1e3,className:"w-32 bg-dark-bg border border-dark-border rounded-lg px-3 py-1.5 text-sm text-dark-text font-mono focus:border-accent-blue/60 focus:ring-2 focus:ring-accent-blue/15 outline-none transition-all"}),e.jsx("span",{className:"text-sm text-dark-muted",children:"tokens"}),e.jsx("button",{onClick:j,disabled:p,className:"px-3 py-1.5 rounded-lg text-sm bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:p?"Saving...":"Apply"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:f.map(x=>e.jsx("button",{onClick:async()=>{n(String(x)),d(x);try{await E.config.provider.save({contextWindow:x}),h.success("Context window saved")}catch(v){h.error("Failed to save context window: "+(v instanceof Error?v.message:"Unknown error"))}},className:"px-3 py-1 rounded-lg text-xs transition-all",children:k(x)},x))}),e.jsxs("p",{className:"text-xs text-dark-muted mt-2",children:["Current: ",e.jsx("span",{className:"font-mono text-dark-text",children:parseInt(i,10).toLocaleString()})," tokens"]})]})}function F({icon:t,iconColor:d,title:i,children:n}){return e.jsxs("div",{className:"rounded-xl border border-dark-border bg-dark-surface p-4",children:[e.jsxs("h3",{className:"font-medium mb-3 flex items-center gap-2",children:[e.jsx(t,{size:16,className:d}),i]}),n]})}export{st as SettingsPanel};