@chenpu17/cc-gw 0.7.21 → 0.8.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +98 -548
- package/package.json +41 -62
- package/src/cli/dist/index.js +95 -32
- package/src/web/dist/assets/About-DK8nmPZ6.js +1 -0
- package/src/web/dist/assets/ApiKeys-BrP75sWu.js +1 -0
- package/src/web/dist/assets/ConfirmDialog-Dhp5pCJl.js +1 -0
- package/src/web/dist/assets/Dashboard-BIW14z5s.js +1 -0
- package/src/web/dist/assets/EChart-T3foksfR.js +1 -0
- package/src/web/dist/assets/Events-CnvgH7ed.js +1 -0
- package/src/web/dist/assets/Help-CVp-PrLr.js +8 -0
- package/src/web/dist/assets/Login-Bplhk_cV.js +1 -0
- package/src/web/dist/assets/Logs-DoYv6X2i.js +1 -0
- package/src/web/dist/assets/ModelManagement-CDNkOZMr.js +1 -0
- package/src/web/dist/assets/PageHeader-BDJTHSc4.js +1 -0
- package/src/web/dist/assets/PageSection-opNH6Eh_.js +1 -0
- package/src/web/dist/assets/Settings-nv1XiDhg.js +1 -0
- package/src/web/dist/assets/Skeleton-nQ45JH_C.js +1 -0
- package/src/web/dist/assets/card-BvCN6Enp.js +1 -0
- package/src/web/dist/assets/charts-core-BvEliZR3.js +12 -0
- package/src/web/dist/assets/charts-engine-_HMDDVBV.js +16 -0
- package/src/web/dist/assets/charts-react-ChNmcnvb.js +1 -0
- package/src/web/dist/assets/i18n-DJG0aQry.js +1 -0
- package/src/web/dist/assets/index-DRy01TFD.js +61 -0
- package/src/web/dist/assets/index-NGg4j8sr.css +1 -0
- package/src/web/dist/assets/input-BiHju62h.js +1 -0
- package/src/web/dist/assets/label-DDyzn2Km.js +1 -0
- package/src/web/dist/assets/popover-BmyFxZJG.js +1 -0
- package/src/web/dist/assets/query-krBOLGyc.js +1 -0
- package/src/web/dist/assets/radix-CWM98B4t.js +5 -0
- package/src/web/dist/assets/router-CYXnniTf.js +19 -0
- package/src/web/dist/assets/select-DCRn4QJE.js +1 -0
- package/src/web/dist/assets/switch-DWuisIdD.js +1 -0
- package/src/web/dist/assets/useApiQuery-DqJ_GQ6F.js +1 -0
- package/src/web/dist/assets/vendor-DORguW2v.js +317 -0
- package/src/web/dist/index.html +7 -2
- package/src/server/dist/index.js +0 -18202
- package/src/web/dist/assets/About-Bjq70P_K.js +0 -6
- package/src/web/dist/assets/ApiKeys-BHwlIBRG.js +0 -16
- package/src/web/dist/assets/Dashboard-Bv6E5M2u.js +0 -16
- package/src/web/dist/assets/Events-DyqUKr1b.js +0 -16
- package/src/web/dist/assets/Help-BNn_Zuo4.js +0 -23
- package/src/web/dist/assets/Login-BHXuuVq3.js +0 -1
- package/src/web/dist/assets/Logs-CRnJOy2J.js +0 -6
- package/src/web/dist/assets/ModelManagement-DAE8AYAE.js +0 -6
- package/src/web/dist/assets/PageHeader-D2u2opjK.js +0 -1
- package/src/web/dist/assets/PageSection-jfq2rgUu.js +0 -1
- package/src/web/dist/assets/Settings-CssUPWdg.js +0 -6
- package/src/web/dist/assets/Skeleton-BwMNCVcg.js +0 -1
- package/src/web/dist/assets/card-C9wVDhpJ.js +0 -1
- package/src/web/dist/assets/dialog-DbEoPxgf.js +0 -10
- package/src/web/dist/assets/index-B1EJcuR-.css +0 -1
- package/src/web/dist/assets/index-BjqieXJo.js +0 -48
- package/src/web/dist/assets/index-Blclkvp7.js +0 -280
- package/src/web/dist/assets/info-BmVX8zJd.js +0 -6
- package/src/web/dist/assets/input-CGgq_gCJ.js +0 -1
- package/src/web/dist/assets/label-BGUvZ4t2.js +0 -1
- package/src/web/dist/assets/refresh-cw-D7rJxbFV.js +0 -6
- package/src/web/dist/assets/select-Chuh7X1A.js +0 -11
- package/src/web/dist/assets/shield-Beuqdf31.js +0 -11
- package/src/web/dist/assets/switch-XbPwmM_b.js +0 -1
- package/src/web/dist/assets/useApiQuery-DiX6xcfY.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as o,f as e,ab as Xe,ac as Ze,Y as es,ad as ss,ae as ts,a4 as Fe,h as as}from"./vendor-DORguW2v.js";import{u as Ke,a as ls,t as rs,c as h,B as y}from"./index-DRy01TFD.js";import{u as A}from"./useApiQuery-DqJ_GQ6F.js";import{T as os,a as Q}from"./Skeleton-nQ45JH_C.js";import{P as ns,B as P}from"./PageHeader-BDJTHSc4.js";import{c as is}from"./clipboard-CALi6bTW.js";import{I as me}from"./input-BiHju62h.js";import{L as O}from"./label-DDyzn2Km.js";import{C as Re,a as De}from"./card-BvCN6Enp.js";import{S as X,a as Z,b as ee,c as se,d as T}from"./select-DCRn4QJE.js";import{P as ds,a as cs,b as ms}from"./popover-BmyFxZJG.js";import{u as ae}from"./i18n-DJG0aQry.js";import"./router-CYXnniTf.js";import"./radix-CWM98B4t.js";import"./query-krBOLGyc.js";const Me=[20,50,100],ze="cc-gw.logs.visible-columns",Ae="cc-gw.logs.density",$=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","outputTokens","latency","status","error"],te=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function xs(){if(typeof window>"u")return $;try{const s=window.localStorage.getItem(ze);if(!s)return $;const i=JSON.parse(s);if(!Array.isArray(i))return $;const c=i.filter(v=>te.includes(v));return c.length>0?c:$}catch{return $}}function us(){return typeof window>"u"?"comfortable":window.localStorage.getItem(Ae)==="compact"?"compact":"comfortable"}function Oe(s,i=!1){if(!s)return;const c=i?`${s}T23:59:59.999`:`${s}T00:00:00.000`,v=Date.parse(c);return Number.isFinite(v)?v:void 0}function Pe(s){const i=new Date(s);return`${i.getFullYear()}-${`${i.getMonth()+1}`.padStart(2,"0")}-${`${i.getDate()}`.padStart(2,"0")} ${`${i.getHours()}`.padStart(2,"0")}:${`${i.getMinutes()}`.padStart(2,"0")}:${`${i.getSeconds()}`.padStart(2,"0")}`}function L(s){return s==null?"-":s.toLocaleString()}function C(s,i){const c=L(s);return c==="-"?"-":`${c} ${i}`}function ps(s){return s?"true":"false"}function $e(s,i){if(!s||s.trim().length===0)return i;try{const c=JSON.parse(s);return JSON.stringify(c,null,2)}catch{return s}}function hs(s,i,c){return s===c&&i===c}function Os(){var ke,_e,Se,Ee,Te,Ce;const{t:s}=ae(),{pushToast:i}=Ke(),[c,v]=o.useState("all"),[g,a]=o.useState("all"),[d,j]=o.useState(""),[x,N]=o.useState("all"),[l,S]=o.useState(""),[r,m]=o.useState(""),[f,p]=o.useState(1),[u,F]=o.useState(Me[0]),[le,I]=o.useState(null),[Ie,xe]=o.useState(!1),[w,re]=o.useState([]),[H,ue]=o.useState(!1),[pe,qe]=o.useState(!1),[q,he]=o.useState(us),[R,fe]=o.useState(xs),[Ue,Ge]=o.useState(!1),oe=o.useRef(null);o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Ae,q)},[q]),o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(ze,JSON.stringify(R))},[R]),o.useEffect(()=>{p(1)},[c,g,d,x,l,r,u,w]);const W=o.useMemo(()=>{const t={limit:u,offset:(f-1)*u};c!=="all"&&(t.provider=c),g!=="all"&&(t.endpoint=g),d.trim().length>0&&(t.model=d.trim()),x!=="all"&&(t.status=x);const n=Oe(l),_=Oe(r,!0);return n!==void 0&&(t.from=n),_!==void 0&&(t.to=_),w.length>0&&(t.apiKeys=w.join(",")),t},[c,g,d,x,l,r,f,u,w]),k=A(["logs",W],{url:"/api/logs",method:"GET",params:W}),K=A(["providers","all"],{url:"/api/providers",method:"GET"}),ge=A(["api-keys"],{url:"/api/keys",method:"GET"}),ne=A(["custom-endpoints"],{url:"/api/custom-endpoints",method:"GET"}),je=A(["config","export-timeout"],{url:"/api/config",method:"GET"});o.useEffect(()=>{k.isError&&k.error&&i({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:k.error.message}),variant:"error"})},[k.isError,k.error,i,s]),o.useEffect(()=>{K.isError&&K.error&&i({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:K.error.message}),variant:"error"})},[K.isError,K.error,i,s]);const D=((ke=k.data)==null?void 0:ke.total)??0,E=D>0?Math.ceil(D/u):0,be=((_e=k.data)==null?void 0:_e.items)??[],ye=o.useMemo(()=>{var n;const t=(n=je.data)==null?void 0:n.logExportTimeoutSeconds;return typeof t=="number"&&Number.isFinite(t)?Math.min(Math.max(Math.round(t),5),600)*1e3:6e4},[(Se=je.data)==null?void 0:Se.logExportTimeoutSeconds]);o.useEffect(()=>{E>0&&f>E&&p(E)},[E,f]);const ie=K.data??[],J=o.useMemo(()=>{const t=new Map;for(const n of ie)n.id&&t.set(n.id,n.label??n.id);return t},[ie]),ve=o.useMemo(()=>{var n;const t=new Map;t.set("anthropic",s("logs.filters.endpointAnthropic")),t.set("openai",s("logs.filters.endpointOpenAI"));for(const _ of((n=ne.data)==null?void 0:n.endpoints)??[])t.set(_.id,_.label||_.id);return t},[(Ee=ne.data)==null?void 0:Ee.endpoints,s]),z=o.useMemo(()=>{const t=[];if(c!=="all"){const n=J.get(c)??c;t.push({key:"provider",label:`${s("logs.filters.provider")}: ${n}`,onRemove:()=>v("all")})}if(g!=="all"){const n=ve.get(g)??g;t.push({key:"endpoint",label:`${s("logs.filters.endpoint")}: ${n}`,onRemove:()=>a("all")})}if(d.trim()&&t.push({key:"model",label:`${s("logs.filters.modelId")}: ${d.trim()}`,onRemove:()=>j("")}),x!=="all"){const n=s(x==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");t.push({key:"status",label:`${s("logs.filters.status")}: ${n}`,onRemove:()=>N("all")})}return l&&t.push({key:"from",label:`${s("logs.filters.startDate")}: ${l}`,onRemove:()=>S("")}),r&&t.push({key:"to",label:`${s("logs.filters.endDate")}: ${r}`,onRemove:()=>m("")}),w.length>0&&t.push({key:"apiKeys",label:s("logs.filters.apiKeySelected",{count:w.length}),onRemove:()=>re([])}),t},[c,J,g,ve,d,x,l,r,w,s]),de=ge.data??[],Ne=o.useMemo(()=>{const t=new Map;for(const n of de)t.set(n.id,n);return t},[de]),b=o.useMemo(()=>new Set(R),[R]),Be=o.useMemo(()=>te.map(t=>({id:t,label:s(`logs.table.columns.${t}`)})),[s]),we=R.length+2,U=o.useMemo(()=>new Date().toISOString().slice(0,10),[]),Ve=o.useMemo(()=>c==="all"&&g==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"all":x==="error"&&g==="all"&&c==="all"&&d.trim()===""&&l===""&&r===""&&w.length===0?"errors":hs(l,r,U)&&g==="all"&&c==="all"&&d.trim()===""&&x==="all"&&w.length===0?"today":g==="anthropic"&&c==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"anthropic":g==="openai"&&c==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"openai":null,[g,l,d,c,w.length,x,r,U]),Qe=o.useCallback(t=>{fe(n=>{if(n.includes(t))return n.length===1?n:n.filter(B=>B!==t);const _=[...n,t];return _.sort((B,ce)=>te.indexOf(B)-te.indexOf(ce)),_})},[]),Y=o.useCallback(()=>{v("all"),j(""),a("all"),N("all"),S(""),m(""),re([])},[]),He=o.useCallback(t=>{if(p(1),Y(),t!=="all"){if(t==="errors"){N("error");return}if(t==="today"){S(U),m(U);return}if(t==="anthropic"){a("anthropic");return}t==="openai"&&a("openai")}},[Y,U]),We=o.useCallback(async()=>{if(!H){ue(!0);try{const t=D>0?Math.min(D,5e3):1e3,n={...W,limit:t,offset:0},_=await ls.post("/api/logs/export",n,{responseType:"blob",timeout:ye}),B=new Blob([_.data],{type:"application/zip"}),ce=new Date().toISOString().replace(/[:.]/g,"-"),Le=URL.createObjectURL(B),V=document.createElement("a");V.href=Le,V.download=`cc-gw-logs-${ce}.zip`,document.body.appendChild(V),V.click(),V.remove(),URL.revokeObjectURL(Le),i({title:s("logs.toast.exportSuccess.title"),description:s("logs.toast.exportSuccess.desc"),variant:"success"})}catch(t){const n=rs(t);i({title:s("logs.toast.exportError.title"),description:s("logs.toast.exportError.desc",{message:n.message}),variant:"error"})}finally{ue(!1)}}},[ye,H,i,W,s,D]),Je=o.useCallback(t=>{I(t),xe(!0)},[]),Ye=o.useCallback(()=>{xe(!1),I(null)},[]),G=o.useCallback(()=>{const t=oe.current;if(!t)return;const n=t.scrollWidth-t.scrollLeft-t.clientWidth>1;Ge(n)},[]);return o.useEffect(()=>{const t=oe.current;if(!t)return;G(),t.addEventListener("scroll",G,{passive:!0});const n=new ResizeObserver(G);return n.observe(t),()=>{t.removeEventListener("scroll",G),n.disconnect()}},[G]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ns,{icon:e.jsx(es,{className:"h-5 w-5","aria-hidden":"true"}),title:s("logs.title"),description:s("logs.description"),eyebrow:"Traffic Explorer",breadcrumb:"Gateway / Logs",helper:s("logs.filtersDescription"),actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-full border border-border/70 bg-background/80 p-1 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("button",{type:"button",onClick:()=>he("comfortable"),className:h("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",q==="comfortable"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:s("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>he("compact"),className:h("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",q==="compact"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:s("logs.table.density.compact")})]}),e.jsxs(ds,{children:[e.jsx(cs,{asChild:!0,children:e.jsx(y,{variant:"outline",size:"sm",children:s("logs.actions.columns")})}),e.jsxs(ms,{align:"end",className:"w-64 rounded-[1.2rem] border-white/60 p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:s("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.actions.visibleCount",{count:R.length})})]}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>fe($),disabled:JSON.stringify(R)===JSON.stringify($),children:s("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:Be.map(t=>{const n=b.has(t.id);return e.jsxs("label",{className:h("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",n&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:n,onChange:()=>Qe(t.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:t.label})]},t.id)})})]})]}),e.jsxs(y,{onClick:We,disabled:H,children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),s(H?"common.actions.loading":"logs.actions.export")]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.summary.total",{value:D.toLocaleString()})}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>k.refetch(),disabled:k.isFetching,children:[e.jsx(Ze,{className:h("mr-2 h-4 w-4",k.isFetching&&"animate-spin")}),k.isFetching?s("common.actions.refreshing"):s("logs.actions.manualRefresh")]})]})}),e.jsx(Re,{className:"sticky top-20 z-20 border-white/40 bg-card/90 backdrop-blur",children:e.jsxs(De,{className:"pt-4",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:s("logs.filtersTitle")}),e.jsx(P,{variant:"outline",children:s("logs.summary.total",{value:D.toLocaleString()})}),z.length>0&&e.jsx(P,{variant:"secondary",children:s("common.filters.activeCount",{count:z.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[z.length>0&&e.jsx(y,{variant:"ghost",size:"sm",onClick:Y,children:s("common.actions.reset")}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>qe(t=>!t),children:pe?e.jsxs(e.Fragment,{children:[s("common.filters.collapse"),e.jsx(ss,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[s("common.filters.expand"),e.jsx(ts,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsx("div",{className:"flex flex-1 items-center gap-3 overflow-hidden",children:z.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:z.map(t=>e.jsxs(P,{variant:"secondary",role:"button",tabIndex:0,className:"cursor-pointer gap-1 hover:bg-destructive/10 hover:text-destructive",onClick:t.onRemove,onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),t.onRemove())},children:[t.label,e.jsx(Fe,{className:"h-3 w-3","aria-hidden":"true"})]},t.key))}):e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.filters.allRequests")})})}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:["all","errors","today","anthropic","openai"].map(t=>e.jsx(y,{variant:Ve===t?"default":"outline",size:"sm",className:"rounded-full",onClick:()=>He(t),children:s(`logs.quickViews.${t}`)},t))})]}),pe&&e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-2 xl:grid-cols-4 animate-in fade-in slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.provider")}),e.jsxs(X,{value:c,onValueChange:v,children:[e.jsx(Z,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.providerAll")}),ie.map(t=>e.jsx(T,{value:t.id,children:t.label??t.id},t.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.endpoint")}),e.jsxs(X,{value:g,onValueChange:a,children:[e.jsx(Z,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.endpointAll")}),e.jsx(T,{value:"anthropic",children:s("logs.filters.endpointAnthropic")}),e.jsx(T,{value:"openai",children:s("logs.filters.endpointOpenAI")}),(Ce=(Te=ne.data)==null?void 0:Te.endpoints)==null?void 0:Ce.map(t=>e.jsx(T,{value:t.id,children:t.label||t.id},t.id))]})]})]}),e.jsx(js,{className:"md:col-span-2",apiKeys:de,selected:w,disabled:ge.isLoading,onChange:re}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.modelId")}),e.jsx(me,{value:d,onChange:t=>j(t.target.value),placeholder:s("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.status")}),e.jsxs(X,{value:x,onValueChange:t=>N(t),children:[e.jsx(Z,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.statusAll")}),e.jsx(T,{value:"success",children:s("logs.filters.statusSuccess")}),e.jsx(T,{value:"error",children:s("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.startDate")}),e.jsx(me,{type:"date",value:l,onChange:t=>S(t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.endDate")}),e.jsx(me,{type:"date",value:r,onChange:t=>m(t.target.value)})]})]})]})}),e.jsx(Re,{children:e.jsxs(De,{className:"p-0",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:oe,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1200px] text-sm",children:[e.jsx("thead",{className:"border-b bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-muted/95 px-3 py-2 text-left text-xs font-medium backdrop-blur",children:s("logs.table.columns.time")}),b.has("endpoint")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.endpoint")}),b.has("provider")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.provider")}),b.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.requestedModel")}),b.has("routedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.routedModel")}),b.has("apiKey")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.apiKey")}),b.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.inputTokens")}),b.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheReadTokens")}),b.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheCreationTokens")}),b.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.outputTokens")}),b.has("latency")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.latency")}),b.has("ttft")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.ttft")}),b.has("tpot")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.tpot")}),b.has("status")&&e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:s("logs.table.columns.status")}),b.has("error")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-muted/95 px-3 py-2 text-center text-xs font-medium backdrop-blur",children:s("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:k.isPending?Array.from({length:8}).map((t,n)=>e.jsx(os,{columns:we},n)):be.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:we,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[e.jsx("span",{children:s("logs.table.empty")}),z.length>0&&e.jsx(y,{variant:"outline",size:"sm",onClick:Y,children:s("common.actions.reset")})]})})}):be.map((t,n)=>e.jsx(fs,{record:t,providerLabelMap:J,apiKeyMap:Ne,onSelect:Je,isEven:n%2===0,density:q,visibleColumnSet:b},t.id))})]})}),Ue&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 border-t p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.perPage")}),e.jsxs(X,{value:u.toString(),onValueChange:t=>F(Number(t)),children:[e.jsx(Z,{className:"w-[80px]",children:e.jsx(ee,{})}),e.jsx(se,{children:Me.map(t=>e.jsx(T,{value:t.toString(),children:t},t))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>p(t=>Math.max(t-1,1)),disabled:f<=1,children:s("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.pageLabel",{page:E===0?0:f,total:E})}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>p(t=>E===0?t:Math.min(t+1,E)),disabled:E===0||f>=E,children:s("logs.table.pagination.next")})]})]})]})}),e.jsx(gs,{open:Ie,logId:le,onClose:Ye,providerLabelMap:J,apiKeyMap:Ne})]})}function fs({record:s,providerLabelMap:i,apiKeyMap:c,onSelect:v,isEven:g,density:a,visibleColumnSet:d}){const{t:j}=ae(),x=i.get(s.provider)??s.provider,N=s.endpoint||"-",l=!!s.error,S=s.status_code,r=s.client_model??j("logs.table.requestedModelFallback"),m=s.api_key_id!=null?c.get(s.api_key_id):void 0,f=s.api_key_id==null?j("logs.table.apiKeyUnknown"):m!=null&&m.isWildcard?j("apiKeys.wildcard"):m!=null&&m.name?m.name:s.api_key_name?s.api_key_name:j("logs.table.apiKeyUnknown"),p=a==="compact"?"px-3 py-1.5":"px-3 py-2",u=g?"bg-muted/30":"bg-background";return e.jsxs("tr",{className:h("transition-colors",g?"bg-muted/30":"","hover:bg-muted/50"),children:[e.jsx("td",{className:h("sticky left-0 z-10 text-xs",p,u),children:Pe(s.timestamp)}),d.has("endpoint")&&e.jsx("td",{className:h(p,"text-xs"),children:N}),d.has("provider")&&e.jsx("td",{className:h(p,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:x,children:x})}),d.has("requestedModel")&&e.jsx("td",{className:h(p,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:r,children:r})}),d.has("routedModel")&&e.jsx("td",{className:h(p,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),d.has("apiKey")&&e.jsx("td",{className:h(p,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:f,children:f})}),d.has("inputTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.input_tokens)}),d.has("cacheReadTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.cache_read_tokens)}),d.has("cacheCreationTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.cache_creation_tokens)}),d.has("outputTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.output_tokens)}),d.has("latency")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.latency_ms,"ms")}),d.has("ttft")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.ttft_ms,"ms")}),d.has("tpot")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.tpot_ms,"ms/tk")}),d.has("status")&&e.jsx("td",{className:h(p,"text-center"),children:e.jsx(P,{variant:l?"destructive":"default",className:"text-xs",children:S??(l?500:200)})}),d.has("error")&&e.jsx("td",{className:h(p,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:s.error??"",children:s.error?s.error:"-"})}),e.jsx("td",{className:h("sticky right-0 z-10 text-center",p,u),children:e.jsx(y,{variant:"outline",size:"sm",onClick:()=>v(s.id),children:j("logs.actions.detail")})})]})}function gs({open:s,logId:i,onClose:c,providerLabelMap:v,apiKeyMap:g}){var f,p;const{t:a}=ae(),{pushToast:d}=Ke(),j=o.useRef(null),x=A(["log-detail",i],{url:`/api/logs/${i}`,method:"GET"},{enabled:s&&i!==null,staleTime:3e4});o.useEffect(()=>{x.isError&&x.error&&d({title:a("logs.detail.loadError"),description:x.error.message,variant:"error"})},[x.isError,x.error,d,a]),o.useEffect(()=>{if(!s)return;const u=F=>{F.key==="Escape"&&c()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,c]),o.useEffect(()=>{s&&j.current&&j.current.focus()},[s,i]);const N=o.useCallback(async(u,F,le)=>{if(!F){d({title:a("logs.detail.copy.empty",{label:u}),variant:"info"});return}try{await is(F),d({title:a(le),variant:"success"})}catch(I){d({title:a("logs.detail.copy.failure"),description:I instanceof Error?I.message:a("logs.detail.copy.failureFallback"),variant:"error"})}},[d,a]);if(!s)return null;const l=x.data,S=l?v.get(l.provider)??l.provider:"",r=l&&l.api_key_id!=null?g.get(l.api_key_id):void 0,m=l?l.status_code??(l.error?500:200):null;return typeof document>"u"?null:as.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm animate-in fade-in duration-200",onClick:c}),e.jsxs("aside",{role:"dialog","aria-modal":"true",className:"flex h-full w-full max-w-xl flex-col border-l bg-card shadow-xl animate-in slide-in-from-right duration-300",children:[e.jsxs("header",{className:"flex items-center justify-between border-b px-6 py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:a("logs.detail.title")}),l&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a("logs.detail.id",{id:l.id})})]}),e.jsxs(y,{ref:j,variant:"outline",size:"sm",onClick:c,children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"}),a("common.actions.close")]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:x.isPending?e.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[e.jsx(Q,{className:"h-5 w-40"}),e.jsx(Q,{className:"h-4 w-full"}),e.jsx(Q,{className:"h-4 w-3/4"}),e.jsx(Q,{className:"h-32 w-full"}),e.jsx(Q,{className:"h-4 w-1/2"})]}):l?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-[1.15rem] border border-white/50 bg-background/70 p-3 text-xs shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("span",{className:"font-medium",children:a("logs.detail.summary.route",{from:l.client_model??a("logs.detail.info.noRequestedModel"),to:l.model})}),e.jsx("span",{className:"text-muted-foreground",children:a("logs.detail.summary.latency",{value:C(l.latency_ms,a("common.units.ms"))})}),l.ttft_ms!==null&&e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",C(l.ttft_ms,a("common.units.ms"))]}),e.jsx(P,{variant:l.error?"destructive":"default",children:m==null?void 0:m.toString()}),e.jsx(P,{variant:"outline",children:l.stream?a("logs.stream.streaming"):a("logs.stream.single")})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsx(M,{label:a("logs.detail.info.latency"),value:C(l.latency_ms,a("common.units.ms"))}),e.jsx(M,{label:a("logs.detail.info.ttft"),value:C(l.ttft_ms,a("common.units.ms"))}),e.jsx(M,{label:a("logs.detail.info.tpot"),value:C(l.tpot_ms,a("common.units.msPerToken"))})]}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:Pe(l.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:l.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:l.endpoint||"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:S})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:l.client_model??a("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:l.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:ps(l.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.status")}),e.jsx("dd",{className:"font-medium",children:m})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(M,{label:a("logs.detail.info.inputTokens"),value:L(l.input_tokens)}),e.jsx(M,{label:a("logs.detail.info.cacheReadTokens"),value:L(l.cache_read_tokens)}),e.jsx(M,{label:a("logs.detail.info.cacheCreationTokens"),value:L(l.cache_creation_tokens)}),e.jsx(M,{label:a("logs.detail.info.outputTokens"),value:L(l.output_tokens)})]}),e.jsx("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.latency")}),e.jsx("dd",{className:"font-medium",children:C(l.latency_ms,a("common.units.ms"))})]})}),l.error&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.error")}),e.jsx("p",{className:"rounded-[1rem] border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:l.error})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id==null&&!l.api_key_name?a("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?a("apiKeys.wildcard"):(r==null?void 0:r.name)??l.api_key_name??a("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id??a("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:r!=null&&r.isWildcard?a("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??l.api_key_name??a("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():a("common.noData")})]})]}),e.jsxs("div",{className:"rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:a("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:l.api_key_value_available?l.api_key_value_masked??a("logs.detail.apiKey.rawUnavailable"):a("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:a("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsx("section",{className:"space-y-3",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.request"),(u=l.payload)==null?void 0:u.prompt,"logs.detail.copy.requestSuccess")},children:[a("logs.detail.payload.request")," · ",a("common.actions.copy")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.response"),(u=l.payload)==null?void 0:u.response,"logs.detail.copy.responseSuccess")},children:[a("logs.detail.payload.response")," · ",a("common.actions.copy")]})]})}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.payload.request")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.request"),(u=l.payload)==null?void 0:u.prompt,"logs.detail.copy.requestSuccess")},children:a("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:$e((f=l.payload)==null?void 0:f.prompt,a("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.payload.response")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.response"),(u=l.payload)==null?void 0:u.response,"logs.detail.copy.responseSuccess")},children:a("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:$e((p=l.payload)==null?void 0:p.response,a("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify-center p-8 text-sm text-muted-foreground",children:a("logs.detail.loadError")})})]})]}),document.body)}function M({label:s,value:i}){return e.jsxs("div",{className:"rounded-xl border border-border/70 bg-background/60 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-2 text-sm font-semibold",children:i})]})}function js({apiKeys:s,selected:i,onChange:c,disabled:v,className:g}){const{t:a}=ae(),[d,j]=o.useState(!1),x=o.useRef(null);o.useEffect(()=>{if(!d)return;const r=m=>{var f;(f=x.current)!=null&&f.contains(m.target)||j(!1)};return window.addEventListener("mousedown",r),()=>window.removeEventListener("mousedown",r)},[d]);const N=o.useMemo(()=>{if(i.length===0)return[];const r=new Map;for(const m of s)r.set(m.id,m);return i.map(m=>{const f=r.get(m);return f?f.isWildcard?a("apiKeys.wildcard"):f.name:null}).filter(m=>!!m)},[s,i,a]),l=i.length===0?a("logs.filters.apiKeyAll"):a("logs.filters.apiKeySelected",{count:i.length}),S=r=>{i.includes(r)?c(i.filter(m=>m!==r)):c([...i,r])};return e.jsxs("div",{className:h("relative space-y-2",g),ref:x,children:[e.jsx(O,{children:a("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>j(r=>!r),disabled:v||s.length===0,title:a("logs.filters.apiKeyHint"),className:h("flex h-11 w-full items-center justify-between rounded-2xl border border-border/80 bg-background/85 px-4 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] ring-offset-background transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring/30 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",i.length>0&&"border-primary",d&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[l,N.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:N.join(", ")})]}),e.jsx("svg",{className:h("h-4 w-4 opacity-50 transition-transform",d&&"rotate-180"),viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),d&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-[1.2rem] border border-white/60 bg-popover/95 p-2 shadow-[0_16px_40px_-28px_rgba(15,23,42,0.45)] backdrop-blur",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl bg-background/70 px-3 py-2 text-xs",children:[e.jsx("span",{children:l}),e.jsx("button",{type:"button",onClick:()=>c([]),disabled:i.length===0,className:"text-primary hover:underline disabled:opacity-40",children:a("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(r=>{const m=r.isWildcard?a("apiKeys.wildcard"):r.name,f=i.includes(r.id);return e.jsxs("label",{className:h("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",f&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:f,onChange:()=>S(r.id)}),e.jsx("span",{className:"truncate",children:m})]},r.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:a("logs.filters.apiKeyAll")})]})]})]})}export{Os as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as x,f as e,ai as Ve,Z as rs,a4 as _e,ac as as,aj as ce,k as ns,N as ht,ae as os}from"./vendor-DORguW2v.js";import{u as ds,a as ls,b as lt}from"./query-krBOLGyc.js";import{c as Z,u as gt,B as P,a as Y,b as ve,t as Te,T as is,d as cs,f as ms,g as us}from"./index-DRy01TFD.js";import{u as ps}from"./useApiQuery-DqJ_GQ6F.js";import{P as xs,B as F}from"./PageHeader-BDJTHSc4.js";import{C as hs,D as ft,a as bt,b as vt,c as jt,d as yt,e as Nt}from"./ConfirmDialog-Dhp5pCJl.js";import{I as re}from"./input-BiHju62h.js";import{L as Q}from"./label-DDyzn2Km.js";import{C as Re,a as De}from"./card-BvCN6Enp.js";import{S as wt}from"./switch-DWuisIdD.js";import{S as kt,a as Mt,b as Ct,c as Et,d as W}from"./select-DCRn4QJE.js";import{P as gs,a as fs,b as bs}from"./popover-BmyFxZJG.js";import{u as me}from"./i18n-DJG0aQry.js";import"./router-CYXnniTf.js";import"./radix-CWM98B4t.js";function qe(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function vs(){return{_key:qe(),id:"",label:""}}const Pe={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},it=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}];function ct(s){return s?{id:s.id,label:s.label??s.id,baseUrl:s.baseUrl,apiKey:s.apiKey??"",type:s.type??"custom",defaultModel:s.defaultModel??"",models:(s.models??[]).map(l=>({...l,_key:qe()})),authMode:s.authMode??"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function js(s){return{_key:qe(),id:s.id,label:s.label}}function ys({open:s,mode:l,provider:f,existingProviderIds:h,onClose:p,onSubmit:j}){const{t:r}=me(),[i,w]=x.useState(()=>ct(f)),[S,I]=x.useState({}),[U,g]=x.useState(!1),[C,k]=x.useState(null),v=x.useRef(null),E=x.useRef(null),A=x.useRef(null),[$,ae]=x.useState(l==="edit");x.useEffect(()=>{s&&(w(ct(f)),I({}),k(null),g(!1),ae(l==="edit"))},[s,f,l]),x.useEffect(()=>{if(!s)return;const c=b=>{b.key==="Escape"&&p()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s,p]),x.useEffect(()=>{if(s){if(l==="create"&&A.current){A.current.focus();return}E.current&&E.current.focus()}},[s,l]);const ne=l==="create",oe=x.useMemo(()=>i.models.filter(c=>c.id.trim().length>0),[i.models]),je=x.useMemo(()=>{var c;return((c=it.find(b=>b.value===i.type))==null?void 0:c.label)??"Custom"},[i.type]),ye=i.label.trim()||i.id.trim()||r("providers.drawer.summary.untitled"),Ne=x.useMemo(()=>[{label:r("providers.drawer.summary.type"),value:je},{label:r("providers.drawer.summary.auth"),value:i.authMode==="apiKey"?r("providers.drawer.fields.authModeApiKey"):i.authMode==="authToken"?r("providers.drawer.fields.authModeAuthToken"):r("providers.drawer.fields.authModeXAuthToken")},{label:r("providers.drawer.summary.models"),value:oe.length.toLocaleString()}],[oe.length,i.authMode,je,r]),de=c=>b=>{w(R=>({...R,[c]:b}))},G=c=>{w(b=>{const M=!$||b.label.trim().length===0||b.label===b.id?c:b.label;return{...b,id:c,label:M}})},B=c=>{w(b=>{var Ce;const M=Pe[c??"custom"]??Pe.custom,_=Object.values(Pe).map(te=>te.baseUrl).filter(te=>!!te),q=!b.baseUrl||_.includes(b.baseUrl),z=l==="create"&&(b.models.length===0||b.models.every(te=>te.id.trim().length===0)),X={...b,type:c,authMode:b.authMode??"apiKey"};return M!=null&&M.baseUrl&&q&&(X.baseUrl=M.baseUrl),M!=null&&M.models&&z&&(X.models=M.models.map(js),X.defaultModel=M.defaultModel??((Ce=M.models[0])==null?void 0:Ce.id)??""),X})},Oe=(c,b)=>{w(R=>{const M=[...R.models];return M[c]={...M[c],...b},{...R,models:M}})},H=(c,b)=>{w(R=>{const M=[...R.models],_=M[c];if(!_)return R;const q=!$||!_.label||_.label===_.id,z={..._,id:b,label:q?b:_.label};M[c]=z;const X=R.defaultModel===_.id?b:R.defaultModel;return{...R,models:M,defaultModel:X}})},Ue=c=>{w(b=>{if(c<0||c>=b.models.length)return b;const R=b.models.filter((_,q)=>q!==c);let M=b.defaultModel;return R.some(_=>_.id===M)||(M=""),{...b,models:R,defaultModel:M}})},we=()=>{w(c=>({...c,models:[...c.models,vs()]}))},le=c=>{w(b=>({...b,authMode:c}))},ue=()=>{const c={},b=i.id.trim(),R=i.baseUrl.trim();if(l==="create"&&(b.length===0?c.id=r("providers.drawer.errors.idRequired"):h.includes(b)&&(c.id=r("providers.drawer.errors.idDuplicate"))),l==="edit"&&b.length===0&&(c.id=r("providers.drawer.errors.idRequired")),R.length===0)c.baseUrl=r("providers.drawer.errors.baseUrlInvalid");else try{new URL(R)}catch{c.baseUrl=r("providers.drawer.errors.baseUrlInvalid")}if(i.models.length>0){const M=new Set;i.models.some(q=>{const z=q.id.trim();return z.length===0||M.has(z)?!0:(M.add(z),!1)})&&(c.models=r("providers.drawer.errors.modelInvalid"))}return i.defaultModel&&!i.models.some(M=>M.id===i.defaultModel)&&(c.models=r("providers.drawer.errors.defaultInvalid")),I(c),Object.keys(c).length===0},ke=()=>{const c=i.models.map(M=>{var _;return{id:M.id.trim(),label:(_=M.label)!=null&&_.trim()?M.label.trim():void 0}}).filter(M=>M.id.length>0),b=f!=null&&f.extraHeaders&&Object.keys(f.extraHeaders).length>0?f.extraHeaders:void 0,R=i.authMode!=="apiKey"?i.authMode:void 0;return{id:i.id.trim(),label:i.label.trim()||i.id.trim(),baseUrl:i.baseUrl.trim(),apiKey:i.apiKey.trim()||void 0,type:i.type??"custom",defaultModel:i.defaultModel||void 0,models:c.length>0?c:void 0,extraHeaders:b,authMode:R}},Me=async()=>{if(k(null),!!ue()){g(!0);try{const c=ke();await j(c)}catch(c){k(r("providers.drawer.toast.saveFailure",{message:c instanceof Error?c.message:"unknown"})),g(!1);return}g(!1),p()}};return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60 backdrop-blur-sm",onClick:p,"aria-hidden":"true"}),e.jsxs("aside",{ref:v,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-5xl flex-col border-l border-white/50 bg-background/96 shadow-[0_24px_80px_-32px_rgba(15,23,42,0.4)] backdrop-blur-xl dark:border-slate-800 dark:bg-slate-950/96",children:[e.jsxs("header",{className:"border-b border-border/70 bg-background/70 px-6 py-5 dark:border-slate-800",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"inline-flex rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em] text-primary",children:r(ne?"providers.drawer.quickStart":"providers.drawer.editTitle")}),e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold tracking-[-0.02em]",children:r(ne?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:r("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:E,onClick:p,className:"rounded-full border border-border/80 bg-background/85 px-4 py-2 text-sm transition hover:border-primary/20 hover:bg-primary/5",children:r("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:Ne.map(c=>e.jsxs("div",{className:"rounded-[1.2rem] border border-white/50 bg-card/88 px-4 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:c.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:c.value})]},c.label))})]}),e.jsxs("div",{className:"grid flex-1 overflow-hidden xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:r("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:it.map(c=>{var R;const b=c.value===i.type;return e.jsxs("button",{type:"button",onClick:()=>B(c.value),className:Z("rounded-2xl border px-4 py-3 text-left transition",b?"border-primary bg-primary/10 text-primary shadow-sm":"border-white/50 bg-card/88 text-foreground hover:border-primary/20 hover:bg-primary/5"),children:[e.jsx("div",{className:"text-sm font-semibold",children:c.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((R=Pe[c.value??"custom"])==null?void 0:R.baseUrl)??r("providers.drawer.hints.customProvider")})]},c.value??"custom")})})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-basic-info",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:r("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>ae(c=>!c),className:"rounded-full border border-border/80 bg-background/85 px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-primary/5",children:r($?"providers.drawer.fields.hideAdvanced":"providers.drawer.fields.showAdvanced")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.id")}),e.jsx("input",{value:i.id,ref:A,onChange:c=>G(c.target.value),disabled:!ne,placeholder:r("providers.drawer.fields.idPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!S.id}),S.id?e.jsx("span",{className:"text-xs text-red-500",children:S.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.label")}),e.jsx("input",{value:i.label,onChange:c=>de("label")(c.target.value),placeholder:r("providers.drawer.fields.labelPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:i.baseUrl,onChange:c=>de("baseUrl")(c.target.value),placeholder:r("providers.drawer.fields.baseUrlPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!S.baseUrl}),S.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:S.baseUrl}):null]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-auth-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:r("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.hints.auth")})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.apiKey")}),e.jsx("input",{value:i.apiKey,onChange:c=>de("apiKey")(c.target.value),placeholder:r("providers.drawer.fields.apiKeyPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-[1.3rem] border border-white/50 bg-card/88 p-4 text-xs shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:r("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:r("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:i.authMode==="apiKey",onChange:()=>le("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:r("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:i.authMode==="authToken",onChange:()=>le("authToken"),className:"mt-0.5"}),e.jsx("span",{children:r("providers.drawer.fields.authModeAuthToken")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:i.authMode==="xAuthToken",onChange:()=>le("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:r("providers.drawer.fields.authModeXAuthToken")})]})]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-model-fields",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:r("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:we,className:"rounded-full border border-border/80 bg-background/85 px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-primary/5",children:r("providers.drawer.fields.addModel")})]}),S.models?e.jsx("p",{className:"text-xs text-red-500",children:S.models}):null,e.jsxs("div",{className:"space-y-4",children:[i.models.map((c,b)=>e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/88 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.modelId")}),e.jsx("input",{value:c.id,onChange:R=>H(b,R.target.value),placeholder:r("providers.drawer.fields.modelIdPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]}),$?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:c.label??"",onChange:R=>Oe(b,{label:R.target.value}),placeholder:r("providers.drawer.fields.modelLabelPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-slate-600 dark:text-slate-300",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:c.id,checked:i.defaultModel===c.id,onChange:()=>w(R=>({...R,defaultModel:c.id})),disabled:c.id.trim().length===0}),r("providers.drawer.fields.setDefault")]}),e.jsx("button",{type:"button",className:"text-red-500 transition hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>Ue(b),disabled:i.models.length===0,children:r("providers.drawer.fields.removeModel")})]})]},c._key)),i.models.length===0?e.jsx("div",{className:"rounded-2xl border border-amber-300 bg-gradient-to-br from-amber-50 to-yellow-50 p-5 shadow-sm dark:border-amber-600/60 dark:from-amber-900/20 dark:to-yellow-900/20",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:r("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:r("providers.drawer.noModelsHint",{providerId:i.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md bg-amber-100/80 p-2.5 dark:bg-amber-800/40",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-amber-900 dark:text-amber-200",children:r("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded-xl bg-white/90 px-2.5 py-1.5 font-mono text-xs text-amber-900 shadow-[0_1px_2px_rgba(15,23,42,0.06)] dark:bg-slate-900 dark:text-amber-100",children:['"claude-*": "',(i.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),oe.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:r("providers.drawer.defaultHint",{model:i.defaultModel||r("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden border-l border-border/70 bg-background/55 px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/92 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:ye}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:Ne.map(c=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:c.label}),e.jsx("span",{className:"text-right font-medium",children:c.value})]},c.label))})]}),e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/92 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:r("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:r("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:r("providers.drawer.hints.checkModels")})]})]}),$&&e.jsxs("div",{className:"rounded-[1.3rem] border border-primary/20 bg-primary/5 p-4 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium text-primary",children:r("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:r("providers.drawer.hints.advancedBody")})]})]})})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-border/70 bg-background/70 px-6 py-4 text-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:C?e.jsx("span",{children:C}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:p,className:"rounded-full border border-border/80 bg-background/85 px-4 py-2 transition hover:border-primary/20 hover:bg-primary/5",disabled:U,children:r("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:Me,className:"rounded-full bg-primary px-5 py-2 text-primary-foreground shadow-[0_8px_20px_-12px_rgba(59,130,246,0.65)] transition hover:-translate-y-0.5 hover:bg-primary/95 disabled:opacity-60",disabled:U,children:r(U?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const Ns=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],ws=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function He(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ee(s){return s?Object.entries(s).map(([l,f])=>({id:He(),source:l,target:f})):[]}function ze(s,l){var p,j,r;if(!s)return{};const f={},h=s.endpointRouting??{};f.anthropic=ee(((p=h.anthropic)==null?void 0:p.modelRoutes)??s.modelRoutes??{}),f.openai=ee(((j=h.openai)==null?void 0:j.modelRoutes)??{});for(const i of l)(r=i.routing)!=null&&r.modelRoutes?f[i.id]=ee(i.routing.modelRoutes):f[i.id]=[];return f}function mt(s,l,f){var j,r,i;const h=l.find(w=>w.id===f);if(h)return((j=h.routing)==null?void 0:j.modelRoutes)??{};const p=s.endpointRouting??{};return f==="anthropic"?((r=p.anthropic)==null?void 0:r.modelRoutes)??s.modelRoutes??{}:f==="openai"?((i=p.openai)==null?void 0:i.modelRoutes)??{}:{}}function ks(s){const l={};for(const f of s){const h=f.source.trim(),p=f.target.trim();h&&p&&(l[h]=p)}return l}function ut(s,l){return JSON.stringify(ks(s))!==JSON.stringify(l)}function Ms(s,l){if(s==="anthropic")return!0;const f=l.find(h=>h.id===s);return f?f.paths&&f.paths.length>0?f.paths.some(h=>h.protocol==="anthropic"):f.protocol==="anthropic":!1}function Cs(s,l,f){var p,j,r;if(!l)return;if(s==="anthropic"||s==="openai")return(j=(p=l.endpointRouting)==null?void 0:p[s])==null?void 0:j.validation;const h=f.find(i=>i.id===s);return(r=h==null?void 0:h.routing)==null?void 0:r.validation}function Qs(){const{t:s}=me(),{pushToast:l}=gt(),f=ds(),h=ps(["config","full"],{url:"/api/config",method:"GET"}),{data:p}=ls({queryKey:["custom-endpoints"],queryFn:ve.list,refetchInterval:1e4}),j=(p==null?void 0:p.endpoints)??[],r=x.useMemo(()=>{const t=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],n=j.map(a=>{let o,d=[];if(a.paths&&a.paths.length>0){const m=a.paths.map(u=>`${u.path} (${u.protocol})`).join(", ");o=`${s("modelManagement.tabs.customEndpoint")}: ${m}`,d=[...new Set(a.paths.map(u=>u.protocol))]}else if(a.path){const m=a.protocol||"anthropic";o=`${s("modelManagement.tabs.customEndpoint")}: ${a.path} (${m})`,d=[m]}else o=s("modelManagement.tabs.customEndpoint");return{key:a.id,label:a.label,description:o,isSystem:!1,canDelete:a.deletable!==!1,protocols:d}});return[...t,...n]},[s,j]),[i,w]=x.useState("providers"),S=x.useMemo(()=>r.filter(t=>t.isSystem),[r]),I=x.useMemo(()=>r.filter(t=>!t.isSystem),[r]),U=x.useMemo(()=>r.find(t=>t.key===i)??r[0]??null,[i,r]),[g,C]=x.useState(null),[k,v]=x.useState(!1),[E,A]=x.useState("create"),[$,ae]=x.useState(void 0),[ne,oe]=x.useState(null),[je,ye]=x.useState(!1),[Ne,de]=x.useState(void 0),[G,B]=x.useState({}),[Oe,H]=x.useState({}),[Ue,we]=x.useState(null),[le,ue]=x.useState({}),[ke,Me]=x.useState({}),[c,b]=x.useState({}),[R,M]=x.useState(null),[_,q]=x.useState(null),[z,X]=x.useState(null),[Ce,te]=x.useState(!1),[Ae,Qe]=x.useState(null),[Ee,Le]=x.useState(!0),[Ge,Xe]=x.useState({}),[St,Je]=x.useState(!1),[Rt,Dt]=x.useState({}),[$e,Ie]=x.useState(null),[N,pe]=x.useState(null),[Fe,Ye]=x.useState(!1),[Se,We]=x.useState(""),[xe,Ze]=x.useState("all"),V=(g==null?void 0:g.providers)??[],et=V.length,tt=x.useMemo(()=>V.filter(t=>{var d;if(!(xe==="all"||(t.type??"custom")===xe))return!1;const a=Se.trim().toLowerCase();return a?[t.id,t.label??"",t.baseUrl,t.defaultModel??"",...((d=t.models)==null?void 0:d.map(m=>m.id))??[]].join(" ").toLowerCase().includes(a):!0}),[Se,xe,V]),he=x.useMemo(()=>[{key:"anthropic-beta",value:"claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",label:s("providers.testDialog.options.beta.label"),description:s("providers.testDialog.options.beta.description")}],[s]);x.useEffect(()=>{var t,n;if(h.data){const a=h.data;C(a),B(d=>{const m=ze(a,j);if(!d||Object.keys(d).length===0)return m;const u={...m};for(const[y,D]of Object.entries(d)){if(!(y in m))continue;const L=mt(a,j,y);ut(D,L)&&(u[y]=D)}return u}),H({});const o={anthropic:((t=a.routingPresets)==null?void 0:t.anthropic)??[],openai:((n=a.routingPresets)==null?void 0:n.openai)??[]};for(const d of j)o[d.id]=d.routingPresets??[];ue(o)}},[h.data,j]),x.useEffect(()=>{h.isError&&h.error&&l({title:s("providers.toast.loadFailure",{message:h.error.message}),variant:"error"})},[h.isError,h.error,l,s]);const st=x.useMemo(()=>{const t=new Map;for(const n of V){if(!n.defaultModel||!n.models)continue;const a=n.models.find(o=>o.id===n.defaultModel);a&&t.set(n.id,xt(a))}return t},[V]),Pt=x.useMemo(()=>{const t=[],n=new Set;for(const o of V){const d=o.label&&o.label!==o.id?`${o.label} (${o.id})`:o.id,m=o.models??[];if(m.length>0)for(const y of m){const D=`${o.id}:${y.id}`;n.has(D)||(n.add(D),t.push({value:D,label:`${d} · ${y.label??y.id}`}))}else if(o.defaultModel){const y=`${o.id}:${o.defaultModel}`;n.has(y)||(n.add(y),t.push({value:y,label:`${d} · ${o.defaultModel}`}))}const u=`${o.id}:*`;n.has(u)||(n.add(u),t.push({value:u,label:s("settings.routing.providerPassthroughOption",{provider:d})}))}const a=Object.values(G).flat();for(const o of a){const d=o.target.trim();d&&!n.has(d)&&(n.add(d),t.push({value:d,label:d}))}return t},[V,G,s]),_t=t=>g?mt(g,j,t):{},Tt=(t,n)=>ut(t,n),Ke=x.useMemo(()=>{const t={};for(const n of r){if(n.key==="providers")continue;const a=G[n.key]||[],o=_t(n.key);t[n.key]=Tt(a,o)}return t},[G,g,j,r]),rt=(t,n)=>{ue(a=>({...a,[t]:n})),C(a=>{if(!a)return a;if(t==="anthropic"||t==="openai")return{...a,routingPresets:{...a.routingPresets,[t]:n}};const o=a.customEndpoints??[],d=o.findIndex(u=>u.id===t);if(d===-1)return a;const m=[...o];return m[d]={...m[d],routingPresets:n},{...a,customEndpoints:m}})},se=()=>g?!0:(l({title:s("settings.toast.missingConfig"),variant:"error"}),h.refetch(),!1),Ot=(t,n)=>{Me(a=>({...a,[t]:n})),n.trim()&&b(a=>({...a,[t]:null}))},Ut=async t=>{if(!se())return;const n=ke[t].trim();if(!n){b(a=>({...a,[t]:s("modelManagement.validation.presetName")}));return}if(le[t].some(a=>a.name.toLowerCase()===n.toLowerCase())){b(a=>({...a,[t]:s("modelManagement.validation.presetDuplicate",{name:n})}));return}M(t);try{const o=(await Y.post(`/api/routing-presets/${t}`,{name:n})).data.presets??[];rt(t,o),Me(d=>({...d,[t]:""})),b(d=>({...d,[t]:null})),l({title:s("modelManagement.toast.presetSaved",{name:n}),variant:"success"})}catch(a){l({title:s("modelManagement.toast.presetSaveFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{M(null),h.refetch()}},At=async(t,n)=>{var a,o,d;if(se()){q({endpoint:t,name:n.name});try{const u=(await Y.post(`/api/routing-presets/${t}/apply`,{name:n.name})).data.config;if(u){C(u),B(ze(u,j));const y={anthropic:((a=u.routingPresets)==null?void 0:a.anthropic)??[],openai:((o=u.routingPresets)==null?void 0:o.openai)??[]};for(const D of j){const L=(d=u.customEndpoints)==null?void 0:d.find(T=>T.id===D.id);y[D.id]=(L==null?void 0:L.routingPresets)??[]}ue(y)}else B(y=>({...y,[t]:ee(n.modelRoutes)}));l({title:s("modelManagement.toast.presetApplySuccess",{name:n.name}),variant:"success"})}catch(m){l({title:s("modelManagement.toast.presetApplyFailure",{message:m instanceof Error?m.message:"unknown"}),variant:"error"})}finally{q(null),h.refetch()}}},Lt=async(t,n)=>{if(se()){X({endpoint:t,name:n.name});try{const o=(await Y.delete(`/api/routing-presets/${t}/${encodeURIComponent(n.name)}`)).data.presets??[];rt(t,o),l({title:s("modelManagement.toast.presetDeleteSuccess",{name:n.name}),variant:"success"})}catch(a){l({title:s("modelManagement.toast.presetDeleteFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{X(null),h.refetch()}}},$t=()=>{se()&&(A("create"),ae(void 0),v(!0))},It=t=>{se()&&(A("edit"),ae(t),v(!0))},Ft=async t=>{if(!g)throw new Error(s("settings.toast.missingConfig"));const n=E==="create"?[...V,t]:V.map(d=>$&&d.id===$.id?{...t,id:$.id}:d),a={...g,providers:n};await Y.put("/api/config",a),C(a),B(ze(a,j)),h.refetch();const o=E==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});l({title:o,variant:"success"})},Kt=async t=>{const n=j.find(a=>a.id===t);if(n&&n.deletable!==!1)try{await ve.delete(t),f.invalidateQueries({queryKey:["custom-endpoints"]}),l({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),i===t&&w("providers")}catch(a){const o=Te(a);l({title:s("modelManagement.deleteEndpointError",{error:o.message}),variant:"error"})}},at=async(t,n)=>{oe(t.id);try{const a=n&&(n.headers||n.query)?{headers:n.headers&&Object.keys(n.headers).length>0?n.headers:void 0,query:n.query&&n.query.trim().length>0?n.query.trim():void 0}:void 0,o=await Y.post(`/api/providers/${t.id}/test`,a);o.data.ok?l({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:o.data.status,duration:o.data.durationMs?`${o.data.durationMs} ms`:"—"}),variant:"success"}):l({title:s("providers.toast.testFailure",{message:`${o.data.status} ${o.data.statusText}`}),variant:"error"})}catch(a){l({title:s("providers.toast.testFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{oe(null)}},Bt=t=>{if(t.type==="anthropic"){const n=t.extraHeaders??{},a=new Map(he.map(m=>[m.key.toLowerCase(),m])),o={};let d=!0;for(const m of he){const u=Object.entries(n).find(([y])=>y.toLowerCase()===m.key.toLowerCase());if(u){const[y,D]=u;String(D??"")===m.value||(d=!1,o[y]=String(D??""))}}for(const[m,u]of Object.entries(n))a.has(m.toLowerCase())||(o[m]=String(u??""));Xe(o),Le(d),Qe(t),te(!0);return}at(t)},nt=()=>{te(!1),Qe(null),Le(!0),Xe({})},zt=async()=>{if(!Ae)return;const t={};if(Ee)for(const o of he)t[o.key]=o.value;const n=new Map(he.map(o=>[o.key.toLowerCase(),o]));for(const[o,d]of Object.entries(Ge)){const m=o.toLowerCase();n.get(m)&&Ee||(t[o]=d)}const a=Ae;nt(),await at(a,{headers:Object.keys(t).length>0?t:void 0,query:Ee?"beta=true":void 0})},Vt=async t=>{var y,D,L,T;if(!se())return;const n=V.filter(K=>K.id!==t.id),a=K=>{const J={};if(!K)return J;for(const[ge,ie]of Object.entries(K)){if(!ie)continue;const[fe]=ie.split(":");fe&&fe===t.id||ie===t.id||(J[ge]=ie)}return J},o=(g==null?void 0:g.endpointRouting)??{},d=a(((y=o.anthropic)==null?void 0:y.modelRoutes)??(g==null?void 0:g.modelRoutes)??{}),m=a(((D=o.openai)==null?void 0:D.modelRoutes)??{}),u={...g,providers:n,modelRoutes:d,endpointRouting:{anthropic:{defaults:((L=o.anthropic)==null?void 0:L.defaults)??g.defaults,modelRoutes:d},openai:{defaults:((T=o.openai)==null?void 0:T.defaults)??g.defaults,modelRoutes:m}}};try{await Y.put("/api/config",u),C(u),B({anthropic:ee(d),openai:ee(m)}),l({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),h.refetch()}catch(K){l({title:s("providers.toast.deleteFailure",{message:K instanceof Error?K.message:"unknown"}),variant:"error"})}},Ht=async()=>{if(N){Ye(!0);try{N.kind==="provider"?await Vt(N.provider):N.kind==="preset"?await Lt(N.endpoint,N.preset):await Kt(N.endpoint.id),pe(null)}finally{Ye(!1)}}},qt=t=>{B(n=>({...n,[t]:[...n[t]||[],{id:He(),source:"",target:""}]})),H(n=>({...n,[t]:null}))},Qt=async(t,n)=>{if(se()){Je(!0);try{if(t==="anthropic"||t==="openai"){const a=g.endpointRouting?{...g.endpointRouting}:{},o=a[t]??{defaults:g.defaults,modelRoutes:(t==="anthropic"?g.modelRoutes:{})??{}},d={defaults:o.defaults??g.defaults,modelRoutes:o.modelRoutes??{}};let m=o.validation;n?(m={...m??{},mode:"claude-code"},m.allowExperimentalBlocks===void 0&&(m.allowExperimentalBlocks=!0)):m=void 0;const u=m?{...d,validation:m}:{...d},y={...a,[t]:u},D={...g,endpointRouting:y};await Y.put("/api/config",D),C(D)}else{const a=g.customEndpoints??[],o=a.findIndex(K=>K.id===t);if(o===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const d=a[o],m=d.routing??{defaults:g.defaults,modelRoutes:{}};let u=m.validation;n?(u={...u??{},mode:"claude-code"},u.allowExperimentalBlocks===void 0&&(u.allowExperimentalBlocks=!0)):u=void 0;const y=u?{...m,validation:u}:{...m},D={...d,routing:y},L=[...a];L[o]=D;const T={...g,customEndpoints:L};await Y.put("/api/config",T),C(T)}l({title:s(n?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),h.refetch()}catch(a){const o=Te(a);l({title:s("modelManagement.toast.claudeValidationFailure",{message:o.message}),variant:"error"})}finally{Je(!1)}}},Gt=(t,n)=>{B(a=>{const o=a[t]||[];return o.some(d=>d.source.trim()===n.trim())?a:{...a,[t]:[...o,{id:He(),source:n,target:""}]}}),H(a=>({...a,[t]:null}))},ot=(t,n,a,o)=>{B(d=>({...d,[t]:(d[t]||[]).map(m=>m.id===n?{...m,[a]:o}:m)})),H(d=>({...d,[t]:null}))},Xt=(t,n)=>{B(a=>({...a,[t]:(a[t]||[]).filter(o=>o.id!==n)})),H(a=>({...a,[t]:null}))},Jt=t=>{var a,o;if(!g)return;const n=j.find(d=>d.id===t);if(n){const d=((a=n.routing)==null?void 0:a.modelRoutes)??{};B(m=>({...m,[t]:ee(d)}))}else{const d=g.endpointRouting??{},m=t,u=m==="anthropic"?g.modelRoutes??{}:{},y=((o=d[m])==null?void 0:o.modelRoutes)??u;B(D=>({...D,[t]:ee(y)}))}H(d=>({...d,[t]:null}))},Yt=async t=>{var o;if(!se())return;const n=G[t]||[],a={};for(const d of n){const m=d.source.trim(),u=d.target.trim();if(!(!m&&!u)){if(!m||!u){H(y=>({...y,[t]:s("settings.validation.routePair")}));return}if(a[m]){H(y=>({...y,[t]:s("settings.validation.routeDuplicate",{model:m})}));return}a[m]=u}}H(d=>({...d,[t]:null})),we(t);try{const d=j.find(m=>m.id===t);if(d){const m={...d.routing||{},modelRoutes:a,defaults:((o=d.routing)==null?void 0:o.defaults)||g.defaults};await ve.update(t,{routing:m}),f.invalidateQueries({queryKey:["custom-endpoints"]}),l({title:s("modelManagement.toast.routesSaved"),variant:"success"})}else{const m=g.endpointRouting?{...g.endpointRouting}:{},u=t,y=m[u]??{defaults:g.defaults,modelRoutes:u==="anthropic"?g.modelRoutes??{}:{}},D={...y,defaults:y.defaults??g.defaults,modelRoutes:a},L={...m,[u]:D},T={...g,endpointRouting:L,modelRoutes:u==="anthropic"?a:g.modelRoutes??{}};await Y.put("/api/config",T),C(T),l({title:s("modelManagement.toast.routesSaved"),variant:"success"}),h.refetch()}B(m=>({...m,[t]:ee(a)}))}catch(d){l({title:s("modelManagement.toast.routesSaveFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{we(null)}},Wt=()=>e.jsx(Re,{className:"surface-1",children:e.jsxs(De,{className:"pt-6 space-y-6",children:[e.jsx(pt,{eyebrow:"Model Access",title:s("providers.title"),description:s("providers.description"),breadcrumb:[s("modelManagement.title"),s("modelManagement.tabs.providers")],aside:e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto sm:gap-3",children:[e.jsx(F,{variant:"secondary",children:s("providers.count",{count:et})}),e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>h.refetch(),disabled:h.isFetching,children:[e.jsx(as,{className:Z("mr-2 h-4 w-4",h.isFetching&&"animate-spin")}),h.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")]}),e.jsxs(P,{size:"sm",onClick:$t,children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("providers.actions.add")]})]})}),e.jsxs("div",{className:"grid gap-3 rounded-[1.35rem] border border-border/70 bg-[linear-gradient(135deg,rgba(255,255,255,0.7),rgba(248,250,252,0.82))] p-4 lg:grid-cols-[minmax(0,1fr)_220px_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.filters.searchPlaceholder")}),e.jsx(re,{value:Se,onChange:t=>We(t.target.value),placeholder:s("providers.filters.searchPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.filters.typeAll")}),e.jsxs(kt,{value:xe,onValueChange:Ze,children:[e.jsx(Mt,{children:e.jsx(Ct,{})}),e.jsxs(Et,{children:[e.jsx(W,{value:"all",children:s("providers.filters.typeAll")}),e.jsx(W,{value:"openai",children:"OpenAI"}),e.jsx(W,{value:"anthropic",children:"Anthropic"}),e.jsx(W,{value:"deepseek",children:"DeepSeek"}),e.jsx(W,{value:"huawei",children:"Huawei"}),e.jsx(W,{value:"kimi",children:"Kimi"}),e.jsx(W,{value:"custom",children:"Custom"})]})]})]}),e.jsx("div",{className:"flex items-end",children:e.jsx(P,{variant:"ghost",size:"sm",onClick:()=>{We(""),Ze("all")},disabled:!Se.trim()&&xe==="all",children:s("common.actions.reset")})})]}),h.isPending||!g&&h.isFetching?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-[1.25rem] border border-border/70 bg-background/45 text-sm text-muted-foreground",children:s("common.loading")}):V.length===0?e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:s("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:s("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):tt.length===0?e.jsx("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:s("providers.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4 [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:tt.map(t=>{var n;return e.jsx(Re,{className:"surface-1 flex flex-col overflow-hidden border-border/70",children:e.jsxs(De,{className:"flex flex-1 flex-col gap-4 pt-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold tracking-[-0.02em]",children:t.label||t.id}),t.type&&e.jsx(Ds,{type:t.type})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",t.id]}),e.jsx("p",{className:"break-all text-xs text-muted-foreground",children:t.baseUrl})]}),t.defaultModel?e.jsx(F,{variant:"default",className:"text-xs",children:st.get(t.id)??t.defaultModel}):e.jsx(F,{variant:"secondary",className:"text-xs",children:s("providers.card.noDefault")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.authMode")}),e.jsx("p",{className:"mt-1 text-sm font-medium",children:t.authMode==="authToken"?"Bearer":t.authMode==="xAuthToken"?"X-Auth-Token":"API Key"})]}),e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.modelsTitle")}),e.jsx("p",{className:"mt-1 text-sm font-medium",children:(n=t.models)!=null&&n.length?s("providers.card.modelCount",{count:t.models.length}):s("providers.card.passthrough")})]}),e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.defaultModelLabel")}),e.jsx("p",{className:"mt-1 truncate text-sm font-medium",children:t.defaultModel?st.get(t.id)??t.defaultModel:s("providers.card.noDefault")})]})]}),e.jsxs("div",{className:"space-y-2 rounded-[1.1rem] border border-border/70 bg-background/55 p-3",children:[e.jsx(Q,{className:"text-xs uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.modelsTitle")}),t.models&&t.models.length>0?e.jsx("div",{className:"flex max-h-24 flex-wrap gap-1 overflow-y-auto",children:t.models.map(a=>e.jsx(F,{variant:"outline",className:"text-xs",children:xt(a)},a.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.card.noModels")})]}),e.jsxs("div",{className:"mt-auto flex flex-wrap gap-2 border-t border-border/70 pt-4",children:[e.jsx(P,{variant:"default",size:"sm",onClick:()=>It(t),children:s("providers.actions.edit")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Bt(t),disabled:ne===t.id,children:ne===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>pe({kind:"provider",provider:t}),children:s("providers.actions.delete")})]})]})},t.id)})})]})}),Zt=t=>{const n=le[t]??[],a=ke[t]??"",o=c[t],d=R===t,m=Rt[t]===!0;return e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 p-4 text-left transition-colors hover:bg-primary/5",onClick:()=>Dt(u=>({...u,[t]:!m})),children:e.jsxs("div",{className:"flex items-center gap-2",children:[m?e.jsx(os,{className:"h-4 w-4"}):e.jsx(ht,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:s("modelManagement.presets.title")}),e.jsx(F,{variant:"secondary",className:"text-xs",children:n.length})]})}),m&&e.jsxs("div",{className:"border-t px-4 pb-4 pt-3 space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(re,{value:a,onChange:u=>Ot(t,u.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),disabled:d,className:"w-full md:w-48"}),e.jsx(P,{onClick:()=>void Ut(t),disabled:d,children:s(d?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),o&&e.jsx("p",{className:"text-sm text-destructive",children:o}),n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:s("modelManagement.presets.empty")}):e.jsx(is,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:n.map(u=>{const y=(_==null?void 0:_.endpoint)===t&&(_==null?void 0:_.name)===u.name,D=(z==null?void 0:z.endpoint)===t&&(z==null?void 0:z.name)===u.name,L=Object.entries(u.modelRoutes??{}),T=L.length;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[1.15rem] border border-white/50 bg-card/88 px-4 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsxs(cs,{children:[e.jsx(ms,{asChild:!0,children:e.jsxs("div",{className:"min-w-0 flex-1 cursor-default",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:u.name}),e.jsx(F,{variant:"outline",className:"mt-1 text-xs",children:T>0?s("modelManagement.presets.rulesCount",{count:T}):s("modelManagement.presets.noRules")})]})}),T>0&&e.jsx(us,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[L.slice(0,5).map(([K,J])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:K}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:J})]},K)),T>5&&e.jsxs("div",{className:"text-muted-foreground",children:["…+",T-5]})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(P,{size:"sm",onClick:()=>Ie({endpoint:t,preset:u}),disabled:y||D,children:s(y?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>pe({kind:"preset",endpoint:t,preset:u}),disabled:D||y,children:s(D?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},u.name)})})})]})]})},es=t=>{var fe;const n=G[t]||[],a=Oe[t],o=r.find(O=>O.key===t),m=((fe=o==null?void 0:o.protocols)==null?void 0:fe.includes("anthropic"))??t==="anthropic"?Ns:ws,u=Ue===t,y=Ke[t]??!1,D=(o==null?void 0:o.label)??s(`modelManagement.tabs.${t}`),L=(o==null?void 0:o.isSystem)===!1?o.description:s(`settings.routing.descriptionByEndpoint.${t}`),T=`route-source-${t}`,K=Ms(t,j),J=Cs(t,g,j),ge=K&&(J==null?void 0:J.mode)==="claude-code",ie=new Set(n.map(O=>O.source.trim()).filter(Boolean));return e.jsx(Re,{className:"surface-1",children:e.jsxs(De,{className:"pt-6 space-y-6",children:[e.jsx(pt,{eyebrow:"Routing Workspace",title:s("settings.routing.titleByEndpoint",{endpoint:D}),description:L,breadcrumb:[s("modelManagement.title"),D],aside:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(F,{variant:"outline",children:[n.length," rules"]}),y?e.jsx(F,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:s("modelManagement.actions.unsaved")}):e.jsx(F,{variant:"secondary",children:s("common.status.success")})]})}),e.jsx("div",{className:"rounded-[1.2rem] border border-border/70 bg-background/55 px-4 py-3 text-xs text-muted-foreground",children:s("settings.routing.wildcardHint")}),K&&e.jsx("div",{className:"rounded-[1.25rem] border border-blue-200 bg-blue-50/75 p-4 dark:border-blue-800 dark:bg-blue-950",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:s("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-blue-700 dark:text-blue-300",children:s("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wt,{checked:ge,onCheckedChange:O=>void Qt(t,O),disabled:St}),e.jsx("span",{className:Z("text-xs font-medium",ge?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:s(ge?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}),Zt(t),a&&e.jsx("p",{className:"text-sm text-destructive",children:a}),e.jsxs("div",{className:"space-y-3 rounded-[1.35rem] border border-border/70 bg-[linear-gradient(135deg,rgba(255,255,255,0.7),rgba(248,250,252,0.82))] p-4",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx(Q,{className:"text-sm font-semibold text-foreground",children:s("modelManagement.routesEditorTitle")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Source model -> target provider:model"})]})}),n.length===0?e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:s("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:s("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{children:s("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:s("settings.routing.target")}),e.jsx("span",{})]}),n.map((O,be)=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 rounded-[1rem] border border-border/60 bg-background/80 p-3",children:[e.jsx(re,{value:O.source,onChange:Be=>ot(t,O.id,"source",Be.target.value),placeholder:s("settings.routing.sourcePlaceholder"),list:T,disabled:u,"aria-label":`route-source-${be+1}`}),e.jsx(ce,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx(Ss,{value:O.target,onChange:Be=>ot(t,O.id,"target",Be),options:Pt,disabled:u,placeholder:s("settings.routing.targetPlaceholder")}),e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>Xt(t,O.id),disabled:u,children:e.jsx(_e,{className:"h-4 w-4"})})]},O.id))]})]}),e.jsxs("div",{className:"rounded-[1.25rem] border border-border/70 bg-background/55 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx(Q,{className:"text-sm font-semibold text-foreground",children:s("settings.routing.suggested")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"One click to seed common source models for this endpoint."})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(O=>{const be=ie.has(O);return e.jsx(P,{variant:be?"ghost":"outline",size:"sm",onClick:()=>Gt(t,O),disabled:u||be,className:be?"opacity-50":"",children:O},`${t}-${O}`)})})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-[1.25rem] border border-white/50 bg-card/82 p-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:s("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s(y?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{variant:"outline",size:"sm",onClick:()=>qt(t),disabled:u,children:s("settings.routing.add")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Jt(t),disabled:u||!y,children:s("common.actions.reset")}),e.jsxs(P,{size:"sm",onClick:()=>void Yt(t),disabled:u,className:"relative",children:[s(u?"common.actions.saving":"modelManagement.actions.saveRoutes"),y&&e.jsx("span",{className:"absolute -top-1 -right-1 h-2 w-2 rounded-full bg-amber-500"})]})]})]}),e.jsx("datalist",{id:T,children:m.map(O=>e.jsx("option",{value:O},`${T}-${O}`))})]})})},ts=(N==null?void 0:N.kind)==="provider"?s("providers.actions.delete"):(N==null?void 0:N.kind)==="preset"?s("modelManagement.presets.delete"):(N==null?void 0:N.kind)==="endpoint"?s("common.delete"):"",ss=(N==null?void 0:N.kind)==="provider"?s("providers.confirm.delete",{name:N.provider.label||N.provider.id}):(N==null?void 0:N.kind)==="preset"?s("modelManagement.confirm.deletePreset",{name:N.preset.name}):(N==null?void 0:N.kind)==="endpoint"?s("modelManagement.deleteEndpointConfirm",{label:N.endpoint.label}):"",dt=(N==null?void 0:N.kind)==="provider"?N.provider.label||N.provider.id:(N==null?void 0:N.kind)==="preset"?N.preset.name:(N==null?void 0:N.kind)==="endpoint"?N.endpoint.label:"";return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(xs,{icon:e.jsx(rs,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),actions:e.jsxs(P,{onClick:()=>{de(void 0),ye(!0)},children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("modelManagement.addEndpoint")]})}),e.jsx(Re,{className:"surface-1 overflow-hidden",children:e.jsxs(De,{className:"space-y-5 pt-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(F,{variant:"outline",className:"border-primary/20 bg-primary/5 text-primary",children:[s("modelManagement.tabs.providers")," · ",et]}),e.jsxs(F,{variant:"outline",children:[s("modelManagement.tabs.customEndpoint")," · ",I.length]})]}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:U==null?void 0:U.label}),e.jsx("p",{className:"text-sm text-muted-foreground",children:U==null?void 0:U.description})]}),e.jsx("div",{className:"rounded-2xl border border-border/70 bg-background/75 px-3 py-2 text-xs text-muted-foreground",children:I.length>0?"自定义端点较多时,优先在下方端点带中切换,避免横向挤压布局。":"先配置提供商与内置路由,需要时再追加自定义端点。"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"内置视图"})}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:S.map(t=>{const n=i===t.key,a=t.key!=="providers"&&Ke[t.key];return e.jsxs("button",{type:"button",onClick:()=>w(t.key),className:Z("group flex min-h-[108px] flex-col justify-between rounded-[1.25rem] border px-4 py-4 text-left transition-all",n?"border-primary/35 bg-[linear-gradient(135deg,rgba(59,130,246,0.12),rgba(59,130,246,0.03))] shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]":"border-border/70 bg-background/75 hover:border-primary/20 hover:bg-primary/5"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:Z("text-lg font-semibold tracking-[-0.02em]",n?"text-primary":"text-foreground"),children:t.label}),a?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsx("span",{className:"line-clamp-2 text-sm text-muted-foreground",children:t.description})]},t.key)})})]}),I.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"自定义接入端点"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"端点较多时保留紧凑卡片与横向滚动,避免标题和路径把整行撑乱。"})]})}),e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-full gap-3",children:I.map(t=>{const n=i===t.key,a=Ke[t.key];return e.jsxs("div",{className:Z("group relative flex w-[260px] shrink-0 snap-start flex-col gap-3 rounded-[1.2rem] border px-4 py-4 text-left transition-all",n?"border-primary/35 bg-[linear-gradient(135deg,rgba(59,130,246,0.12),rgba(59,130,246,0.03))] shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]":"border-border/70 bg-background/80 hover:border-primary/20 hover:bg-primary/5"),children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>w(t.key),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:Z("truncate text-base font-semibold tracking-[-0.02em]",n?"text-primary":"text-foreground"),children:t.label}),a?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm text-muted-foreground",children:t.description})]}),t.canDelete?e.jsx("button",{type:"button",onClick:o=>{o.stopPropagation();const d=j.find(m=>m.id===t.key);d&&pe({kind:"endpoint",endpoint:d})},className:"flex h-7 w-7 items-center justify-center rounded-full border border-transparent text-muted-foreground transition hover:border-destructive/20 hover:bg-destructive/10 hover:text-destructive",title:s("common.delete"),children:e.jsx(_e,{className:"h-3.5 w-3.5"})}):null]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(t.protocols??[]).map(o=>e.jsx(F,{variant:"outline",className:"max-w-full truncate border-border/70 bg-background/80 text-[11px] text-muted-foreground",children:o},`${t.key}-${o}`))})]},t.key)})})})]}):null]})}),i==="providers"?Wt():es(i),e.jsx(ys,{open:k,mode:E,provider:E==="edit"?$:void 0,existingProviderIds:V.map(t=>t.id).filter(t=>E==="edit"&&$?t!==$.id:!0),onClose:()=>{v(!1),ae(void 0),A("create")},onSubmit:Ft}),e.jsx(Ps,{open:je,endpoint:Ne,onClose:()=>{ye(!1),de(void 0)},onSuccess:()=>{f.invalidateQueries({queryKey:["custom-endpoints"]})}}),e.jsx(Es,{open:Ce,provider:Ae,options:he,preservedExtras:Ge,usePreset:Ee,onPresetChange:Le,onConfirm:zt,onClose:nt}),e.jsx(Rs,{dialog:$e,currentRoutes:$e?G[$e.endpoint]||[]:[],onConfirm:(t,n)=>{Ie(null),At(t,n)},onClose:()=>Ie(null)}),e.jsx(hs,{open:!!N,onOpenChange:t=>{!t&&!Fe&&pe(null)},title:ts,description:ss,confirmLabel:s(Fe?"common.actions.loading":"common.delete"),cancelLabel:s("common.actions.cancel"),loading:Fe,onConfirm:Ht,children:dt?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:dt}):null})]})}function pt({eyebrow:s,title:l,description:f,breadcrumb:h,aside:p}){return e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx("span",{children:s}),h.map((j,r)=>e.jsxs(ns.Fragment,{children:[r>0?e.jsx(ht,{className:"h-3.5 w-3.5"}):null,e.jsx("span",{className:Z(r===h.length-1&&"text-foreground"),children:j})]},`${j}-${r}`))]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-[-0.03em] text-foreground",children:l}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm text-muted-foreground",children:f})]})]}),p?e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:p}):null]})}function Es({open:s,provider:l,options:f,usePreset:h,preservedExtras:p,onPresetChange:j,onConfirm:r,onClose:i}){const{t:w}=me();return l?e.jsx(ft,{open:s,onOpenChange:S=>!S&&i(),children:e.jsxs(bt,{children:[e.jsxs(vt,{children:[e.jsx(jt,{children:w("providers.testDialog.title")}),e.jsx(yt,{children:w("providers.testDialog.subtitle",{name:l.label||l.id})})]}),e.jsxs("div",{className:"min-h-0 space-y-4 overflow-y-auto",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:w("providers.testDialog.description")}),e.jsxs("div",{className:"flex items-start gap-3 rounded-[1.2rem] border border-border/70 bg-background/45 p-4",children:[e.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 rounded border",checked:h,onChange:S=>j(S.target.checked)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{children:w("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:w("providers.testDialog.presetDescription")}),e.jsxs("details",{className:"rounded-[1rem] border border-border/70 bg-background/70 p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:w("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:f.map(S=>e.jsxs("code",{className:"block rounded-xl border border-border/70 bg-background/85 px-2 py-1 text-xs",children:[S.key,": ",S.value]},S.key))})]})]})]}),Object.keys(p).length>0&&e.jsxs("div",{className:"rounded-[1.15rem] border border-border/70 bg-background/70 p-4 text-xs space-y-2",children:[e.jsx("p",{className:"font-medium",children:w("providers.testDialog.preservedInfo")}),Object.entries(p).map(([S,I])=>e.jsxs("code",{className:"block rounded-xl border border-border/70 bg-background/85 px-2 py-1",children:[S,": ",I]},S))]})]}),e.jsxs(Nt,{children:[e.jsx(P,{variant:"outline",onClick:i,children:w("providers.testDialog.cancel")}),e.jsx(P,{onClick:()=>void r(),children:w("providers.testDialog.primary")})]})]})}):null}function Ss({value:s,onChange:l,options:f,disabled:h,placeholder:p}){const{t:j}=me(),[r,i]=x.useState(!1),[w,S]=x.useState(""),I=x.useRef(null),U=x.useMemo(()=>{if(!w.trim())return f;const C=w.toLowerCase();return f.filter(k=>k.label.toLowerCase().includes(C)||k.value.toLowerCase().includes(C))},[f,w]),g=C=>{l(C),S(""),i(!1)};return e.jsxs(gs,{open:r,onOpenChange:C=>{i(C),C&&S("")},children:[e.jsx(fs,{asChild:!0,children:e.jsx(re,{ref:I,value:s,onChange:C=>{l(C.target.value),S(C.target.value),r||i(!0)},onFocus:()=>{S(""),i(!0)},onClick:()=>{r||i(!0)},placeholder:p,disabled:h,autoComplete:"off"})}),e.jsx(bs,{className:"w-[var(--radix-popover-trigger-width)] max-h-60 overflow-y-auto p-1",align:"start",onOpenAutoFocus:C=>C.preventDefault(),children:U.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:j("common.noMatches")}):U.map(C=>e.jsx("button",{type:"button",className:Z("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",C.value===s.trim()&&"bg-accent"),onMouseDown:k=>{k.preventDefault(),g(C.value)},children:e.jsx("span",{className:"truncate",children:C.label})},C.value))})]})}function Rs({dialog:s,currentRoutes:l,onConfirm:f,onClose:h}){const{t:p}=me();if(!s)return null;const{endpoint:j,preset:r}=s,i=r.modelRoutes??{},w={};for(const k of l){const v=k.source.trim(),E=k.target.trim();v&&E&&(w[v]=E)}const S=new Set([...Object.keys(w),...Object.keys(i)]),I=[],U=[],g=[];for(const k of S){const v=k in w,E=k in i;E&&!v?I.push([k,i[k]]):v&&!E?U.push([k,w[k]]):v&&E&&w[k]!==i[k]&&g.push([k,w[k],i[k]])}const C=I.length>0||U.length>0||g.length>0;return e.jsx(ft,{open:!0,onOpenChange:k=>!k&&h(),children:e.jsxs(bt,{className:"max-w-lg",children:[e.jsxs(vt,{children:[e.jsx(jt,{children:p("modelManagement.presets.diffTitle")}),e.jsx(yt,{children:p("modelManagement.presets.diffDescription",{name:r.name})})]}),C?e.jsxs("div",{className:"max-h-72 overflow-y-auto space-y-2 text-sm",children:[I.map(([k,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-emerald-50 dark:bg-emerald-950 text-emerald-800 dark:text-emerald-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-emerald-300 dark:border-emerald-700",children:p("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`add-${k}`)),U.map(([k,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-red-50 dark:bg-red-950 text-red-800 dark:text-red-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-red-300 dark:border-red-700",children:p("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`rm-${k}`)),g.map(([k,v,E])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-amber-50 dark:bg-amber-950 text-amber-800 dark:text-amber-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-amber-300 dark:border-amber-700",children:p("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:v}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:E})]},`chg-${k}`))]}):e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:p("modelManagement.presets.diffEmpty")}),e.jsxs(Nt,{children:[e.jsx(P,{variant:"outline",onClick:h,children:p("common.cancel")}),e.jsx(P,{onClick:()=>f(j,r),disabled:!C,children:p("modelManagement.presets.diffConfirm")})]})]})})}function xt(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function Ds({type:s}){const l={openai:{label:"OpenAI",variant:"success"},deepseek:{label:"DeepSeek",variant:"info"},huawei:{label:"华为云",variant:"warning"},kimi:{label:"Kimi",variant:"purple"},anthropic:{label:"Anthropic",variant:"pink"},custom:{label:"Custom",variant:"secondary"}},{label:f,variant:h}=l[s]||l.custom;return e.jsx(F,{variant:h,className:"text-xs",children:f})}function Ps({open:s,endpoint:l,onClose:f,onSuccess:h}){const{t:p}=me(),{pushToast:j}=gt(),[r,i]=x.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});x.useEffect(()=>{if(l){let v;l.paths&&l.paths.length>0?v=l.paths:l.path&&l.protocol?v=[{path:l.path,protocol:l.protocol}]:v=[{path:"",protocol:"openai-auto"}],i({id:l.id,label:l.label,paths:v,enabled:l.enabled!==!1})}else i({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[l,s]);const w=lt({mutationFn:ve.create,onSuccess:()=>{j({title:p("modelManagement.createEndpointSuccess"),variant:"success"}),h(),f()},onError:v=>{const E=Te(v);j({title:p("modelManagement.createEndpointError",{error:E.message}),variant:"error"})}}),S=lt({mutationFn:v=>ve.update(v.id,v.updates),onSuccess:()=>{j({title:p("modelManagement.updateEndpointSuccess"),variant:"success"}),h(),f()},onError:v=>{const E=Te(v);j({title:p("modelManagement.updateEndpointError",{error:E.message}),variant:"error"})}}),I=()=>{i({...r,paths:[...r.paths,{path:"",protocol:"anthropic"}]})},U=v=>{if(r.paths.length===1){j({title:p("modelManagement.atLeastOnePath"),variant:"error"});return}const E=r.paths.filter((A,$)=>$!==v);i({...r,paths:E})},g=(v,E,A)=>{const $=[...r.paths];$[v]={...$[v],[E]:A},i({...r,paths:$})},C=v=>{if(v.preventDefault(),!r.id.trim()||!r.label.trim()){j({title:p("modelManagement.endpointValidationError"),variant:"error"});return}for(const A of r.paths)if(!A.path.trim()){j({title:p("modelManagement.pathValidationError"),variant:"error"});return}const E=r.paths.map(A=>({path:A.path.trim(),protocol:A.protocol}));l?S.mutate({id:l.id,updates:{label:r.label.trim(),paths:E,enabled:r.enabled}}):w.mutate({id:r.id.trim(),label:r.label.trim(),paths:E,enabled:r.enabled})},k=w.isPending||S.isPending;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-slate-950/45 backdrop-blur-sm",onClick:f}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-white/50 bg-background/96 shadow-[0_24px_80px_-32px_rgba(15,23,42,0.4)] backdrop-blur-xl",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/70 bg-background/70 p-6",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:p(l?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx(P,{variant:"ghost",size:"sm",onClick:f,children:e.jsx(_e,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:C,className:"flex-1 overflow-y-auto p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Q,{children:[p("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{value:r.id,onChange:v=>i({...r,id:v.target.value}),placeholder:p("modelManagement.endpointIdPlaceholder"),disabled:!!l,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Q,{children:[p("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{value:r.label,onChange:v=>i({...r,label:v.target.value}),placeholder:p("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Q,{children:[p("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(P,{type:"button",variant:"ghost",size:"sm",onClick:I,children:[e.jsx(Ve,{className:"mr-1 h-3 w-3"}),p("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:r.paths.map((v,E)=>e.jsxs("div",{className:"rounded-[1.15rem] border border-white/50 bg-card/88 p-3 space-y-2 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(re,{value:v.path,onChange:A=>g(E,"path",A.target.value),placeholder:p("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(kt,{value:v.protocol,onValueChange:A=>g(E,"protocol",A),children:[e.jsx(Mt,{children:e.jsx(Ct,{})}),e.jsxs(Et,{children:[e.jsx(W,{value:"anthropic",children:p("modelManagement.protocolAnthropic")}),e.jsx(W,{value:"openai-auto",children:p("modelManagement.protocolOpenAI")})]})]})]}),r.paths.length>1&&e.jsx(P,{type:"button",variant:"ghost",size:"sm",onClick:()=>U(E),className:"text-destructive",children:e.jsx(_e,{className:"h-4 w-4"})})]}),E===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:p("modelManagement.endpointPathHint")})]},E))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(wt,{id:"enabled",checked:r.enabled,onCheckedChange:v=>i({...r,enabled:v})}),e.jsx(Q,{htmlFor:"enabled",children:p("modelManagement.endpointEnabled")})]}),!l&&e.jsx("div",{className:"rounded-[1.2rem] border border-blue-200 bg-blue-50/75 p-4 dark:border-blue-800 dark:bg-blue-950",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:p("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border/70 bg-background/70 p-6",children:[e.jsx(P,{variant:"outline",className:"flex-1",onClick:f,disabled:k,children:p("common.cancel")}),e.jsx(P,{className:"flex-1",onClick:C,disabled:k,children:p(k?"common.saving":l?"common.save":"common.create")})]})]})})]}):null}export{Qs as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as r,L as b}from"./vendor-DORguW2v.js";import{c as l}from"./index-DRy01TFD.js";const c=b("inline-flex items-center rounded-full border px-2.5 py-1 text-[11px] font-semibold tracking-[0.02em] transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-primary/15 bg-primary/10 text-primary hover:bg-primary/15 dark:border-primary/25 dark:bg-primary/15 dark:text-primary-foreground",secondary:"border-border/70 bg-secondary/90 text-secondary-foreground hover:bg-secondary dark:border-border dark:bg-secondary/70 dark:text-secondary-foreground",destructive:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 dark:border-red-900 dark:bg-red-950/60 dark:text-red-300",outline:"border-border bg-transparent text-muted-foreground hover:bg-accent dark:border-border dark:text-muted-foreground dark:hover:bg-accent",success:"border-emerald-200 bg-emerald-50 text-emerald-700 hover:bg-emerald-100 dark:border-emerald-900 dark:bg-emerald-950/60 dark:text-emerald-300",warning:"border-amber-200 bg-amber-50 text-amber-700 hover:bg-amber-100 dark:border-amber-900 dark:bg-amber-950/60 dark:text-amber-300",info:"border-cyan-200 bg-cyan-50 text-cyan-700 hover:bg-cyan-100 dark:border-cyan-900 dark:bg-cyan-950/60 dark:text-cyan-300",purple:"border-violet-200 bg-violet-50 text-violet-700 hover:bg-violet-100 dark:border-violet-900 dark:bg-violet-950/60 dark:text-violet-300",pink:"border-pink-200 bg-pink-50 text-pink-700 hover:bg-pink-100 dark:border-pink-900 dark:bg-pink-950/60 dark:text-pink-300"}},defaultVariants:{variant:"default"}});function m({className:e,variant:n,...a}){return r.jsx("div",{className:l(c({variant:n}),e),...a})}function f({icon:e,title:n,description:a,badge:o,eyebrow:d,breadcrumb:t,helper:s,actions:i,className:x}){return r.jsxs("div",{className:l("flex flex-col gap-5 rounded-[1.6rem] border border-white/50 bg-[linear-gradient(135deg,rgba(255,255,255,0.72),rgba(248,250,252,0.88))] p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)] backdrop-blur sm:flex-row sm:items-start sm:justify-between",x),children:[r.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-4",children:[e&&r.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-2xl bg-primary/10 text-primary shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]",children:e}),r.jsxs("div",{className:"min-w-0 space-y-2",children:[(d||t)&&r.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[d?r.jsx("span",{children:d}):null,d&&t?r.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/50"}):null,t?r.jsx("span",{className:"text-muted-foreground/90",children:t}):null]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[r.jsx("h1",{className:"text-2xl font-semibold tracking-[-0.02em]",children:n}),o&&r.jsx(m,{variant:"secondary",children:o})]}),a&&r.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:a}),s&&r.jsx("div",{className:"rounded-2xl border border-border/70 bg-background/70 px-3.5 py-2 text-xs text-muted-foreground",children:s})]})]}),i&&r.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2 self-start",children:i})]})}export{m as B,f as P};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as e}from"./vendor-DORguW2v.js";import{c as m}from"./index-DRy01TFD.js";import{C as o,b as x,c as f,d as i,a as p}from"./card-BvCN6Enp.js";function b({title:a,description:s,eyebrow:d,actions:r,className:c,contentClassName:l,children:n}){const t=a||s||r;return e.jsxs(o,{className:m("surface-1 overflow-hidden",c),children:[t&&e.jsxs(x,{className:"flex flex-col gap-4 border-b border-border/60 bg-background/35 sm:flex-row sm:items-start sm:justify-between sm:space-y-0",children:[e.jsxs("div",{className:"space-y-1.5",children:[d?e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:d}):null,typeof a=="string"?e.jsx(f,{className:"text-base font-semibold",children:a}):a,s&&(typeof s=="string"?e.jsx(i,{children:s}):e.jsx("div",{className:"text-sm text-muted-foreground",children:s}))]}),r&&e.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:r})]}),e.jsx(p,{className:m(!t&&"pt-6",t&&"pt-5",l),children:n})]})}export{b as P};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as i,f as e,a1 as at,ap as Y,ak as rt,am as nt}from"./vendor-DORguW2v.js";import{u as qe}from"./useApiQuery-DqJ_GQ6F.js";import{u as ot,B as v,h as De,c as ae,a as G}from"./index-DRy01TFD.js";import{P as it,B as V}from"./PageHeader-BDJTHSc4.js";import{C as Ke}from"./ConfirmDialog-Dhp5pCJl.js";import{c as lt}from"./clipboard-CALi6bTW.js";import{I as b}from"./input-BiHju62h.js";import{L as c}from"./label-DDyzn2Km.js";import{C as N,a as k}from"./card-BvCN6Enp.js";import{S as w}from"./switch-DWuisIdD.js";import{S as dt,a as ct,b as mt,c as pt,d as ut}from"./select-DCRn4QJE.js";import{u as ht}from"./i18n-DJG0aQry.js";import"./query-krBOLGyc.js";import"./router-CYXnniTf.js";import"./radix-CWM98B4t.js";const xt=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}],Z=[{id:"section-basics",labelKey:"settings.sections.basics"},{id:"section-protocol",labelKey:"settings.sections.protocol"},{id:"section-security",labelKey:"settings.sections.security"},{id:"section-config-file",labelKey:"settings.sections.configFile"},{id:"section-cleanup",labelKey:"settings.sections.cleanup"}];function ee(t){var S,C,O,y,x,f,n,q,E,B,r;const m=t.storePayloads,P=l=>typeof l=="boolean"?l:typeof m=="boolean"?m:!0;return{port:String(t.port??((S=t.http)==null?void 0:S.port)??""),host:t.host??((C=t.http)==null?void 0:C.host)??"127.0.0.1",logRetentionDays:String(t.logRetentionDays??30),logExportTimeoutSeconds:String(t.logExportTimeoutSeconds??60),storeRequestPayloads:P(t.storeRequestPayloads),storeResponsePayloads:P(t.storeResponsePayloads),logLevel:t.logLevel??"info",requestLogging:t.requestLogging!==!1,responseLogging:t.responseLogging??t.requestLogging!==!1,bodyLimitMb:(()=>{const l=t.bodyLimit;return typeof l=="number"&&Number.isFinite(l)&&l>0?String(Math.max(1,Math.round(l/(1024*1024)))):"10"})(),enableRoutingFallback:t.enableRoutingFallback===!0,httpEnabled:((O=t.http)==null?void 0:O.enabled)!==!1,httpPort:String(((y=t.http)==null?void 0:y.port)??t.port??4100),httpHost:((x=t.http)==null?void 0:x.host)??t.host??"127.0.0.1",httpsEnabled:((f=t.https)==null?void 0:f.enabled)===!0,httpsPort:String(((n=t.https)==null?void 0:n.port)??4443),httpsHost:((q=t.https)==null?void 0:q.host)??t.host??"127.0.0.1",httpsKeyPath:((E=t.https)==null?void 0:E.keyPath)??"",httpsCertPath:((B=t.https)==null?void 0:B.certPath)??"",httpsCaPath:((r=t.https)==null?void 0:r.caPath)??""}}function te(t){return{enabled:t.enabled,username:t.username??"",password:"",confirmPassword:""}}function Tt(){const{t}=ht(),{pushToast:m}=ot(),[P,S]=i.useState(Z[0].id),C=i.useRef(new Map),O=i.useCallback(s=>{const a=C.current.get(s);a&&a.scrollIntoView({behavior:"smooth",block:"start"})},[]),y=i.useCallback(s=>a=>{a?C.current.set(s,a):C.current.delete(s)},[]),x=qe(["config","info"],{url:"/api/config/info",method:"GET"}),f=qe(["auth","web"],{url:"/api/auth/web",method:"GET"}),[n,q]=i.useState(null),[E,B]=i.useState(""),[r,l]=i.useState({port:"",host:"",logRetentionDays:"",logExportTimeoutSeconds:"60",storeRequestPayloads:!0,storeResponsePayloads:!0,logLevel:"info",requestLogging:!0,responseLogging:!0,bodyLimitMb:"10",enableRoutingFallback:!1,httpEnabled:!0,httpPort:"4100",httpHost:"127.0.0.1",httpsEnabled:!1,httpsPort:"4443",httpsHost:"127.0.0.1",httpsKeyPath:"",httpsCertPath:"",httpsCaPath:""}),[p,re]=i.useState({}),[R,ne]=i.useState(!1),[D,oe]=i.useState(!1),[K,ie]=i.useState(!1),[_e,J]=i.useState(!1),[Ve,z]=i.useState(!1),[o,le]=i.useState(null),[d,L]=i.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[T,I]=i.useState({}),[F,de]=i.useState(!1),Be=i.useMemo(()=>{if(!n)return null;const s=n.defaults;if(!s)return null;const a=[];return s.completion&&a.push(t("settings.defaults.completion",{model:s.completion})),s.reasoning&&a.push(t("settings.defaults.reasoning",{model:s.reasoning})),s.background&&a.push(t("settings.defaults.background",{model:s.background})),a.length>0?a.join(" | "):t("settings.defaults.none")},[n,t]),Ie=i.useMemo(()=>r.httpEnabled&&r.httpsEnabled?t("settings.overview.values.httpAndHttps"):r.httpsEnabled?t("settings.overview.values.httpsOnly"):t("settings.overview.values.httpOnly"),[r.httpEnabled,r.httpsEnabled,t]),ce=i.useMemo(()=>d.enabled?o!=null&&o.hasPassword?d.username.trim()!==((o==null?void 0:o.username)??""):!0:!1,[d.enabled,d.username,o]),Q=i.useMemo(()=>n?ee(n):null,[n]),H=i.useMemo(()=>Q?JSON.stringify(r)!==JSON.stringify(Q):!1,[r,Q]),W=i.useMemo(()=>o?te(o):null,[o]),A=i.useMemo(()=>W?JSON.stringify(d)!==JSON.stringify(W):!1,[d,W]);i.useEffect(()=>{x.data&&(q(x.data.config),B(x.data.path),l(ee(x.data.config)))},[x.data]),i.useEffect(()=>{f.data&&(le(f.data),L(te(f.data)),I({}))},[f.data]),i.useEffect(()=>{x.isError&&x.error&&m({title:t("settings.toast.loadFailure",{message:x.error.message}),variant:"error"})},[x.isError,x.error,m,t]),i.useEffect(()=>{f.isError&&f.error&&m({title:t("settings.toast.authLoadFailure",{message:f.error.message}),variant:"error"})},[f.isError,f.error,m,t]);const _=s=>a=>{l(u=>({...u,[s]:a}))},$e=()=>{const s={};if(!r.httpEnabled&&!r.httpsEnabled&&(s.protocol="至少需要启用 HTTP 或 HTTPS 协议"),r.httpEnabled){const j=Number(r.httpPort);(!Number.isFinite(j)||j<1||j>65535)&&(s.httpPort="HTTP 端口必须在 1-65535 之间")}if(r.httpsEnabled){const j=Number(r.httpsPort);(!Number.isFinite(j)||j<1||j>65535)&&(s.httpsPort="HTTPS 端口必须在 1-65535 之间"),(!r.httpsKeyPath||!r.httpsCertPath)&&(s.protocol="HTTPS 已启用但缺少证书路径,请手动配置受信任的证书")}const a=Number(r.port);(!Number.isFinite(a)||a<1||a>65535)&&(s.port=t("settings.validation.port"));const u=Number(r.logRetentionDays);(!Number.isFinite(u)||u<1||u>365)&&(s.logRetentionDays=t("settings.validation.retention"));const g=Number(r.logExportTimeoutSeconds);(!Number.isFinite(g)||g<5||g>600)&&(s.logExportTimeoutSeconds=t("settings.validation.logExportTimeout"));const M=Number(r.bodyLimitMb);return(!Number.isFinite(M)||M<1||M>2048)&&(s.bodyLimitMb=t("settings.validation.bodyLimit")),re(s),Object.keys(s).length===0},Ge=()=>{const s={},a=d.username.trim(),u=o?a!==(o.username??""):!0,g=d.enabled&&(!(o!=null&&o.hasPassword)||u);return d.enabled&&!a&&(s.username=t("settings.auth.validation.username")),d.password&&d.password.length<6&&(s.password=t("settings.auth.validation.minLength")),g&&!d.password&&(s.password=t("settings.auth.validation.passwordRequired")),(d.password||d.confirmPassword)&&d.password!==d.confirmPassword&&(s.confirmPassword=t("settings.auth.validation.confirmMismatch")),I(s),Object.keys(s).length===0},me=async()=>{var s,a,u,g,M,j,xe,ge,be,fe,ve,je,ye,Ne,ke,we,Pe,Ce,Ee,Le,Se,Re,Te,Fe,He,Ae;if(!n){m({title:t("settings.toast.loadFailure",{message:t("settings.toast.missingConfig")}),variant:"error"});return}if($e()){ne(!0);try{const $=Number(r.port),We=Number(r.logRetentionDays),Ue=Number(r.logExportTimeoutSeconds),Xe=Number(r.bodyLimitMb),h={...n,http:{enabled:r.httpEnabled,port:Number(r.httpPort),host:r.httpHost.trim()||"127.0.0.1"},https:{enabled:r.httpsEnabled,port:Number(r.httpsPort),host:r.httpsHost.trim()||"127.0.0.1",keyPath:r.httpsKeyPath.trim(),certPath:r.httpsCertPath.trim(),caPath:r.httpsCaPath.trim()||void 0},port:$,host:r.host.trim()||void 0,logRetentionDays:We,logExportTimeoutSeconds:Math.min(Math.max(Math.round(Ue),5),600),storeRequestPayloads:r.storeRequestPayloads,storeResponsePayloads:r.storeResponsePayloads,logLevel:r.logLevel,requestLogging:r.requestLogging,responseLogging:r.responseLogging,bodyLimit:Math.max(1,Math.floor(Xe*1024*1024)),enableRoutingFallback:r.enableRoutingFallback},Me={...h};delete Me.webAuth,await G.put("/api/config",Me),q({...h,webAuth:n.webAuth});const Oe=X=>(X==null?void 0:X.trim())||void 0,Ye=n.port??((s=n.http)==null?void 0:s.port)??4100,Ze=h.port??((a=h.http)==null?void 0:a.port)??4100,et=((u=n.host)==null?void 0:u.trim())||((M=(g=n.http)==null?void 0:g.host)==null?void 0:M.trim())||"127.0.0.1",tt=((j=h.host)==null?void 0:j.trim())||((ge=(xe=h.http)==null?void 0:xe.host)==null?void 0:ge.trim())||"127.0.0.1",st=Ye!==Ze||et!==tt||((be=n.http)==null?void 0:be.enabled)!==((fe=h.http)==null?void 0:fe.enabled)||((ve=n.http)==null?void 0:ve.port)!==((je=h.http)==null?void 0:je.port)||(((ye=n.http)==null?void 0:ye.host)??n.host??"127.0.0.1")!==(((Ne=h.http)==null?void 0:Ne.host)??h.host??"127.0.0.1")||((ke=n.https)==null?void 0:ke.enabled)!==((we=h.https)==null?void 0:we.enabled)||((Pe=n.https)==null?void 0:Pe.port)!==((Ce=h.https)==null?void 0:Ce.port)||(((Ee=n.https)==null?void 0:Ee.host)??n.host??"127.0.0.1")!==(((Le=h.https)==null?void 0:Le.host)??h.host??"127.0.0.1")||((Se=n.https)==null?void 0:Se.keyPath)!==((Re=h.https)==null?void 0:Re.keyPath)||((Te=n.https)==null?void 0:Te.certPath)!==((Fe=h.https)==null?void 0:Fe.certPath)||Oe((He=n.https)==null?void 0:He.caPath)!==Oe((Ae=h.https)==null?void 0:Ae.caPath);m(st?{title:t("settings.toast.protocolRestartRequired"),variant:"success"}:{title:t("settings.toast.saveSuccess"),variant:"success"}),x.refetch()}catch($){m({title:t("settings.toast.saveFailure",{message:$ instanceof Error?$.message:"unknown"}),variant:"error"})}finally{ne(!1)}}},pe=()=>{n&&(l(ee(n)),re({}))},ue=async()=>{var s;if(Ge()){de(!0);try{const a={enabled:d.enabled,username:d.username.trim()||void 0};d.password&&(a.password=d.password);const g=(s=(await G.post("/api/auth/web",a)).data)==null?void 0:s.auth;g&&(le(g),L({enabled:g.enabled,username:g.username??"",password:"",confirmPassword:""}),I({})),m({title:t("settings.auth.toast.success"),variant:"success"}),f.refetch()}catch(a){const u=a instanceof Error?a.message:"unknown";m({title:t("settings.auth.toast.failure",{message:u}),variant:"error"})}finally{de(!1)}}},he=()=>{o&&(L(te(o)),I({}))},Je=async()=>{if(!E){m({title:t("settings.toast.copyFailure",{message:t("settings.file.unknown")}),variant:"error"});return}try{await lt(E),m({title:t("settings.toast.copySuccess"),variant:"success"})}catch(s){m({title:t("settings.toast.copyFailure",{message:s instanceof Error?s.message:"unknown"}),variant:"error"})}},ze=async()=>{oe(!0);try{const a=(await G.post("/api/logs/cleanup")).data.deleted??0;m({title:a>0?t("settings.toast.cleanupSuccess",{count:a}):t("settings.toast.cleanupNone"),variant:"success"})}catch(s){m({title:t("settings.toast.cleanupFailure",{message:s instanceof Error?s.message:"unknown"}),variant:"error"})}finally{oe(!1)}},Qe=async()=>{ie(!0);try{const s=await G.post("/api/logs/clear"),{deleted:a,metricsCleared:u}=s.data;m({title:t("settings.toast.clearAllSuccess",{logs:a,metrics:u}),variant:"success"})}catch(s){m({title:t("settings.toast.clearAllFailure",{message:s instanceof Error?s.message:"unknown"}),variant:"error"})}finally{ie(!1)}},U=x.isPending||!n&&x.isFetching;return i.useEffect(()=>{if(U)return;const s=Array.from(C.current.values());if(s.length===0)return;const a=new IntersectionObserver(u=>{for(const g of u)if(g.isIntersecting){S(g.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const u of s)a.observe(u);return()=>a.disconnect()},[U]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(it,{icon:e.jsx(at,{className:"h-5 w-5","aria-hidden":"true"}),title:t("settings.title"),description:t("settings.description"),eyebrow:"Gateway Controls",breadcrumb:"Gateway / Settings",helper:t("settings.overview.description"),badge:H||A?t("modelManagement.actions.unsaved"):void 0,actions:n?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{variant:"outline",onClick:pe,disabled:R||!H,children:t("common.actions.reset")}),e.jsx(v,{onClick:()=>void me(),disabled:R||!H,children:t(R?"common.actions.saving":"common.actions.save")})]}):null}),U?e.jsx(N,{children:e.jsx(k,{className:"flex min-h-[220px] items-center justify-center",children:e.jsx(De,{})})}):n?e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-[200px_1fr] gap-6",children:[e.jsx("nav",{className:"hidden xl:block",children:e.jsxs("div",{className:"sticky top-20 space-y-1",children:[e.jsx("p",{className:"mb-3 text-xs font-medium uppercase tracking-wider text-muted-foreground",children:t("settings.sections.jump")}),Z.map(s=>e.jsx("button",{type:"button",onClick:()=>O(s.id),className:ae("block w-full rounded-2xl px-3.5 py-2.5 text-left text-sm transition-all",P===s.id?"bg-primary/10 font-medium text-primary shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]":"text-muted-foreground hover:bg-background/80 hover:text-foreground"),children:t(s.labelKey)},s.id))]})}),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(N,{className:"border-white/40 bg-card/88 backdrop-blur",children:e.jsxs(k,{className:"space-y-4 pt-5",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:t("settings.overview.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("settings.overview.description")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(se,{label:t("settings.overview.cards.protocols"),value:Ie,helper:`${r.httpHost||"127.0.0.1"}:${r.httpPort}${r.httpsEnabled?` / ${r.httpsHost||"127.0.0.1"}:${r.httpsPort}`:""}`}),e.jsx(se,{label:t("settings.overview.cards.security"),value:o!=null&&o.enabled?t("settings.overview.values.authEnabled"):t("settings.overview.values.authDisabled"),helper:o!=null&&o.username?`${t("settings.auth.username")}: ${o.username}`:t("settings.auth.enableHint")}),e.jsx(se,{label:t("settings.overview.cards.configFile"),value:E||t("settings.file.unknown"),helper:t("settings.file.description"),mono:!0})]})]})}),e.jsx("div",{className:"xl:hidden",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:Z.map(s=>e.jsx("button",{type:"button",onClick:()=>O(s.id),className:ae("rounded-full border px-3.5 py-2 text-xs font-medium transition-all",P===s.id?"border-primary/20 bg-primary text-primary-foreground shadow-[0_10px_24px_-18px_rgba(59,130,246,0.8)]":"border-border/70 bg-background/80 text-muted-foreground hover:border-primary/20 hover:bg-primary/5 hover:text-foreground"),children:t(s.labelKey)},s.id))})}),e.jsx(N,{id:"section-basics",ref:y("section-basics"),children:e.jsxs(k,{className:"pt-6",children:[e.jsx("h3",{className:"mb-4 text-sm font-semibold",children:t("settings.sections.basics")}),e.jsxs("div",{className:"grid gap-5 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.fields.port")}),e.jsx(b,{type:"number",min:1,max:65535,value:r.port,onChange:s=>_("port")(s.target.value),"aria-invalid":!!p.port}),p.port&&e.jsx("p",{className:"text-xs text-destructive",children:p.port})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.fields.host")}),e.jsx(b,{value:r.host,onChange:s=>_("host")(s.target.value),placeholder:t("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.fields.retention")}),e.jsx(b,{type:"number",min:1,max:365,value:r.logRetentionDays,onChange:s=>_("logRetentionDays")(s.target.value),"aria-invalid":!!p.logRetentionDays}),p.logRetentionDays&&e.jsx("p",{className:"text-xs text-destructive",children:p.logRetentionDays})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.fields.logExportTimeout")}),e.jsx(b,{type:"number",min:5,max:600,value:r.logExportTimeoutSeconds,onChange:s=>_("logExportTimeoutSeconds")(s.target.value),"aria-invalid":!!p.logExportTimeoutSeconds}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.logExportTimeoutHint")}),p.logExportTimeoutSeconds&&e.jsx("p",{className:"text-xs text-destructive",children:p.logExportTimeoutSeconds})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.fields.bodyLimit")}),e.jsx(b,{type:"number",min:1,max:2048,value:r.bodyLimitMb,onChange:s=>_("bodyLimitMb")(s.target.value),"aria-invalid":!!p.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.bodyLimitHint")}),p.bodyLimitMb&&e.jsx("p",{className:"text-xs text-destructive",children:p.bodyLimitMb})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.fields.logLevel")}),e.jsxs(dt,{value:r.logLevel,onValueChange:s=>l(a=>({...a,logLevel:s})),children:[e.jsx(ct,{children:e.jsx(mt,{})}),e.jsx(pt,{children:xt.map(s=>e.jsx(ut,{value:s.value,children:t(`settings.fields.logLevelOption.${s.labelKey}`)},s.value))})]})]}),e.jsxs("div",{className:"md:col-span-2 grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-[1.2rem] border border-border/70 bg-background/55 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-sm font-medium",children:t("settings.fields.storeRequestPayloads")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.storeRequestPayloadsHint")})]}),e.jsx(w,{checked:r.storeRequestPayloads,onCheckedChange:s=>l(a=>({...a,storeRequestPayloads:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-[1.2rem] border border-border/70 bg-background/55 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-sm font-medium",children:t("settings.fields.storeResponsePayloads")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.storeResponsePayloadsHint")})]}),e.jsx(w,{checked:r.storeResponsePayloads,onCheckedChange:s=>l(a=>({...a,storeResponsePayloads:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-[1.2rem] border border-border/70 bg-background/55 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-sm font-medium",children:t("settings.fields.requestLogging")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.requestLoggingHint")})]}),e.jsx(w,{checked:r.requestLogging,onCheckedChange:s=>l(a=>({...a,requestLogging:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-[1.2rem] border border-border/70 bg-background/55 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-sm font-medium",children:t("settings.fields.responseLogging")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.responseLoggingHint")})]}),e.jsx(w,{checked:r.responseLogging,onCheckedChange:s=>l(a=>({...a,responseLogging:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-[1.2rem] border border-amber-200 bg-amber-50/85 p-4 dark:border-amber-800 dark:bg-amber-950",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-sm font-medium text-amber-700 dark:text-amber-300",children:t("settings.fields.enableRoutingFallback")}),e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:t("settings.fields.enableRoutingFallbackHint")})]}),e.jsx(w,{checked:r.enableRoutingFallback,onCheckedChange:s=>l(a=>({...a,enableRoutingFallback:s}))})]})]}),e.jsxs("div",{className:"md:col-span-2 rounded-[1.2rem] border border-border/70 bg-background/55 p-4",children:[e.jsx(c,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:t("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:Be??t("settings.defaults.none")})]})]})]})}),e.jsx(N,{id:"section-protocol",ref:y("section-protocol"),children:e.jsxs(k,{className:"pt-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:t("settings.sections.protocol")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("settings.protocol.description")})]}),e.jsx("div",{className:"rounded-[1.2rem] border border-amber-200 bg-amber-50/85 p-4 dark:border-amber-800 dark:bg-amber-950",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Y,{className:"h-5 w-5 text-amber-600 dark:text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:t("settings.protocol.restartWarning")}),e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:t("settings.protocol.restartHint")}),e.jsx("code",{className:"block rounded-xl bg-amber-100/90 px-3 py-2 text-xs font-mono text-amber-900 dark:bg-amber-900 dark:text-amber-100",children:"cc-gw restart --daemon"}),e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:t("settings.protocol.restartTip")})]})]})}),p.protocol&&e.jsxs("div",{className:"rounded-[1.2rem] border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:[e.jsx(Y,{className:"inline h-4 w-4 mr-2"}),p.protocol]}),e.jsxs("div",{className:"rounded-[1.4rem] border border-blue-200 bg-blue-50/60 p-5 dark:border-blue-800 dark:bg-blue-950/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:t("settings.protocol.http.enable")}),e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400",children:t("settings.protocol.http.hint")})]}),e.jsx(w,{checked:r.httpEnabled,onCheckedChange:s=>l(a=>({...a,httpEnabled:s}))})]}),r.httpEnabled&&e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 mt-4 pt-4 border-t border-blue-200 dark:border-blue-800",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.protocol.http.port")}),e.jsx(b,{type:"number",min:1,max:65535,value:r.httpPort,onChange:s=>l(a=>({...a,httpPort:s.target.value})),"aria-invalid":!!p.httpPort}),p.httpPort&&e.jsx("p",{className:"text-xs text-destructive",children:p.httpPort})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.protocol.http.host")}),e.jsx(b,{value:r.httpHost,onChange:s=>l(a=>({...a,httpHost:s.target.value})),placeholder:"127.0.0.1"})]})]})]}),e.jsxs("div",{className:"rounded-[1.4rem] border border-green-200 bg-green-50/60 p-5 dark:border-green-800 dark:bg-green-950/50",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(c,{className:"text-sm font-medium text-green-800 dark:text-green-200",children:t("settings.protocol.https.enable")}),e.jsx(rt,{className:"h-4 w-4 text-green-600 dark:text-green-400"})]}),e.jsx("p",{className:"text-xs text-green-600 dark:text-green-400",children:t("settings.protocol.https.hint")})]}),e.jsx(w,{checked:r.httpsEnabled,onCheckedChange:s=>l(a=>({...a,httpsEnabled:s}))})]}),r.httpsEnabled&&e.jsxs("div",{className:"space-y-4 mt-4 pt-4 border-t border-green-200 dark:border-green-800",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.protocol.https.port")}),e.jsx(b,{type:"number",min:1,max:65535,value:r.httpsPort,onChange:s=>l(a=>({...a,httpsPort:s.target.value})),"aria-invalid":!!p.httpsPort}),p.httpsPort&&e.jsx("p",{className:"text-xs text-destructive",children:p.httpsPort})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.protocol.https.host")}),e.jsx(b,{value:r.httpsHost,onChange:s=>l(a=>({...a,httpsHost:s.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.protocol.https.keyPath")}),e.jsx(b,{value:r.httpsKeyPath,onChange:s=>l(a=>({...a,httpsKeyPath:s.target.value})),placeholder:"~/.cc-gw/certs/key.pem",className:"font-mono text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.protocol.https.certPath")}),e.jsx(b,{value:r.httpsCertPath,onChange:s=>l(a=>({...a,httpsCertPath:s.target.value})),placeholder:"~/.cc-gw/certs/cert.pem",className:"font-mono text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.protocol.https.caPath")}),e.jsx(b,{value:r.httpsCaPath,onChange:s=>l(a=>({...a,httpsCaPath:s.target.value})),placeholder:"留空则不使用",className:"font-mono text-xs"})]}),e.jsx("div",{className:"rounded-[1.2rem] border border-amber-200 bg-amber-50/85 p-4 dark:border-amber-800 dark:bg-amber-950",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Y,{className:"h-5 w-5 text-amber-600 dark:text-amber-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-amber-800 dark:text-amber-200",children:t("settings.protocol.https.warning")}),e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-300 leading-relaxed",children:[e.jsx("strong",{children:t("settings.protocol.https.invalidCert")}),t("settings.protocol.https.invalidCertDetail")]}),e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-300 leading-relaxed",children:[e.jsx("strong",{children:t("settings.protocol.https.recommended")}),t("settings.protocol.https.recommendedDetail")]}),e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 leading-relaxed",children:t("settings.protocol.https.tip")})]})]})})]})]})]})}),e.jsx(N,{id:"section-security",ref:y("section-security"),children:e.jsxs(k,{className:"pt-6 space-y-5",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:t("settings.sections.security")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("settings.auth.description")})]}),f.isPending&&!o?e.jsx("div",{className:"flex min-h-[120px] items-center justify-center",children:e.jsx(De,{})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-[1.2rem] border border-border/70 bg-background/55 p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{className:"text-sm font-medium",children:t("settings.auth.enable")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.auth.enableHint")}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"rounded-full border border-border/70 bg-background/70 px-3 py-1",children:"/ui"}),e.jsx("span",{className:"rounded-full border border-border/70 bg-background/70 px-3 py-1",children:"/api/*"}),e.jsx("span",{className:"rounded-full border border-border/70 bg-background/70 px-3 py-1",children:"Cookie Session"})]})]}),e.jsx(w,{checked:d.enabled,onCheckedChange:s=>L(a=>({...a,enabled:s}))})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(c,{children:t("settings.auth.username")}),e.jsx(b,{value:d.username,onChange:s=>L(a=>({...a,username:s.target.value})),placeholder:t("settings.auth.usernamePlaceholder")}),T.username&&e.jsx("p",{className:"text-xs text-destructive",children:T.username})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.auth.password")}),e.jsx(b,{type:"password",value:d.password,disabled:!d.enabled,onChange:s=>L(a=>({...a,password:s.target.value})),placeholder:t("settings.auth.passwordPlaceholder")}),T.password?e.jsx("p",{className:"text-xs text-destructive",children:T.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:t(ce?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.auth.confirmPassword")}),e.jsx(b,{type:"password",value:d.confirmPassword,disabled:!d.enabled,onChange:s=>L(a=>({...a,confirmPassword:s.target.value})),placeholder:t("settings.auth.confirmPasswordPlaceholder")}),T.confirmPassword&&e.jsx("p",{className:"text-xs text-destructive",children:T.confirmPassword})]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-[1.2rem] border border-border/70 bg-card/88 p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:t("settings.auth.status")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:o!=null&&o.enabled?t("settings.auth.statusEnabled"):t("settings.auth.statusDisabled")}),(o==null?void 0:o.username)&&e.jsxs("div",{className:"mt-3 rounded-xl bg-primary/10 px-3 py-2 text-xs font-medium text-primary",children:[t("settings.auth.username"),": ",o.username]})]}),e.jsx("div",{className:"rounded-[1.2rem] border border-border/70 bg-background/55 p-4 text-xs text-muted-foreground",children:t(ce?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-3",children:[e.jsx(v,{onClick:()=>void ue(),disabled:F||!A,children:t(F?"common.actions.saving":"settings.auth.actions.save")}),e.jsx(v,{variant:"outline",onClick:he,disabled:F||!A,children:t("common.actions.reset")})]})]})]})}),e.jsx(N,{id:"section-config-file",ref:y("section-config-file"),children:e.jsxs(k,{className:"pt-6 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:t("settings.sections.configFile")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("settings.file.description")})]}),e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>void Je(),children:[e.jsx(nt,{className:"mr-2 h-4 w-4"}),t("common.actions.copy")]})]}),e.jsx("code",{className:"block break-all rounded-[1.2rem] border border-border/70 bg-background/70 px-4 py-3 text-xs",children:E||t("settings.file.unknown")})]})}),e.jsx(N,{id:"section-cleanup",ref:y("section-cleanup"),children:e.jsxs(k,{className:"pt-6 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:t("settings.sections.cleanup")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("settings.cleanup.description")})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx("div",{className:"rounded-2xl border border-amber-300/70 bg-amber-50/70 p-4 dark:border-amber-700/70 dark:bg-amber-950/20",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{variant:"outline",className:"border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300",children:t("settings.cleanup.softLabel")}),e.jsx("p",{className:"text-sm font-medium",children:t("settings.cleanup.softTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.cleanup.softDescription")}),e.jsx(v,{variant:"outline",onClick:()=>J(!0),disabled:D,className:"border-amber-500/40 text-amber-700 hover:bg-amber-500/10 dark:text-amber-300",children:t(D?"common.actions.cleaning":"common.actions.cleanup")})]})}),e.jsx("div",{className:"rounded-[1.3rem] border border-destructive/40 bg-destructive/5 p-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{variant:"outline",className:"border-destructive/40 bg-destructive/10 text-destructive",children:t("settings.cleanup.hardLabel")}),e.jsx("p",{className:"text-sm font-medium",children:t("settings.cleanup.hardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.cleanup.clearAllWarning")}),e.jsx(v,{variant:"destructive",onClick:()=>z(!0),disabled:K,children:t(K?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]})]})})]}),(H||A)&&e.jsxs("div",{className:"sticky bottom-4 z-20 flex flex-col gap-3 rounded-[1.35rem] border border-primary/20 bg-background/95 p-4 shadow-[0_24px_64px_-28px_rgba(15,23,42,0.35)] backdrop-blur md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(V,{variant:"secondary",children:t("modelManagement.actions.unsaved")}),H&&e.jsx(V,{variant:"outline",children:t("settings.sections.basics")}),A&&e.jsx(V,{variant:"outline",children:t("settings.sections.security")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("modelManagement.actions.footerDirtyHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[A&&e.jsxs(e.Fragment,{children:[e.jsx(v,{variant:"outline",onClick:he,disabled:F,children:t("common.actions.reset")}),e.jsx(v,{onClick:()=>void ue(),disabled:F,children:t(F?"common.actions.saving":"settings.auth.actions.save")})]}),H&&e.jsxs(e.Fragment,{children:[e.jsx(v,{variant:"outline",onClick:pe,disabled:R,children:t("common.actions.reset")}),e.jsx(v,{onClick:()=>void me(),disabled:R,children:t(R?"common.actions.saving":"common.actions.save")})]})]})]})]}):e.jsx(N,{children:e.jsx(k,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:t("settings.toast.missingConfig")})})}),e.jsx(Ke,{open:_e,onOpenChange:s=>{!s&&!D&&J(!1)},title:t("settings.cleanup.softTitle"),description:t("settings.cleanup.confirmCleanup"),confirmLabel:t(D?"common.actions.loading":"common.actions.cleanup"),cancelLabel:t("common.actions.cancel"),loading:D,confirmVariant:"default",onConfirm:async()=>{await ze(),J(!1)}}),e.jsx(Ke,{open:Ve,onOpenChange:s=>{!s&&!K&&z(!1)},title:t("settings.cleanup.clearAll"),description:t("settings.cleanup.confirmClearAll"),confirmLabel:t(K?"common.actions.loading":"settings.cleanup.clearAll"),cancelLabel:t("common.actions.cancel"),loading:K,onConfirm:async()=>{await Qe(),z(!1)}})]})}function se({label:t,value:m,helper:P,mono:S=!1}){return e.jsxs("div",{className:"rounded-[1.2rem] border border-border/70 bg-background/60 p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:t}),e.jsx("p",{className:ae("mt-2 text-sm font-semibold text-foreground",S&&"break-all font-mono text-xs"),children:m}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:P})]})}export{Tt as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as e}from"./vendor-DORguW2v.js";import{c as n}from"./index-DRy01TFD.js";function s({className:a}){return e.jsx("div",{role:"status","aria-label":"Loading",className:n("animate-pulse rounded-xl bg-muted/70",a)})}function x(){return e.jsxs("div",{className:"rounded-[1.35rem] border border-white/60 bg-card/92 p-5 space-y-3 shadow-[0_1px_2px_rgba(15,23,42,0.04),0_10px_30px_-24px_rgba(15,23,42,0.26)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s,{className:"h-3 w-24"}),e.jsx(s,{className:"h-10 w-10 rounded-xl"})]}),e.jsx(s,{className:"h-8 w-32"})]})}function o(){return e.jsxs("div",{className:"rounded-[1.35rem] border border-white/60 bg-card/92 p-4 space-y-4 shadow-[0_1px_2px_rgba(15,23,42,0.04),0_10px_30px_-24px_rgba(15,23,42,0.26)]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s,{className:"h-4 w-32"}),e.jsx(s,{className:"h-3 w-48"})]}),e.jsx(s,{className:"h-[320px] w-full rounded-[1.2rem]"})]})}function m({columns:a=6}){const r=["w-24","w-16","w-20","w-28","w-14","w-12","w-20","w-16","w-14","w-12"];return e.jsx("tr",{className:"border-b",children:Array.from({length:a}).map((t,l)=>e.jsx("td",{className:"px-3 py-3",children:e.jsx(s,{className:n("h-4",r[l%r.length])})},l))})}export{o as C,x as S,m as T,s as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as s,f as o,L as p}from"./vendor-DORguW2v.js";import{c as d}from"./index-DRy01TFD.js";const n=p("rounded-[1.35rem] border border-white/60 bg-card/92 text-card-foreground backdrop-blur transition-all duration-200",{variants:{variant:{default:"shadow-[0_1px_2px_rgba(15,23,42,0.04),0_10px_30px_-24px_rgba(15,23,42,0.26)] hover:shadow-[0_12px_36px_-24px_rgba(15,23,42,0.3)]",elevated:"shadow-[0_1px_2px_rgba(15,23,42,0.05),0_18px_48px_-28px_rgba(15,23,42,0.34)] hover:shadow-[0_18px_52px_-28px_rgba(15,23,42,0.38)]",outline:"border-border/80 bg-background/80 shadow-none",ghost:"border-transparent bg-transparent shadow-none",interactive:"cursor-pointer shadow-[0_1px_2px_rgba(15,23,42,0.04),0_10px_30px_-24px_rgba(15,23,42,0.26)] hover:-translate-y-0.5 hover:border-primary/20 hover:shadow-[0_18px_42px_-26px_rgba(59,130,246,0.28)]"}},defaultVariants:{variant:"default"}}),x=s.forwardRef(({className:a,variant:r,...e},t)=>o.jsx("div",{ref:t,className:d(n({variant:r}),a),...e}));x.displayName="Card";const i=s.forwardRef(({className:a,...r},e)=>o.jsx("div",{ref:e,className:d("flex flex-col space-y-1.5 p-6",a),...r}));i.displayName="CardHeader";const _=s.forwardRef(({className:a,...r},e)=>o.jsx("div",{ref:e,className:d("text-lg font-semibold leading-none tracking-[-0.01em]",a),...r}));_.displayName="CardTitle";const c=s.forwardRef(({className:a,...r},e)=>o.jsx("div",{ref:e,className:d("text-sm leading-6 text-muted-foreground",a),...r}));c.displayName="CardDescription";const l=s.forwardRef(({className:a,...r},e)=>o.jsx("div",{ref:e,className:d("p-6 pt-0",a),...r}));l.displayName="CardContent";const f=s.forwardRef(({className:a,...r},e)=>o.jsx("div",{ref:e,className:d("flex items-center p-6 pt-0",a),...r}));f.displayName="CardFooter";export{x as C,l as a,i as b,_ as c,c as d,f as e};
|