@chenpu17/cc-gw 0.7.21 → 0.8.0-alpha.0
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-g7O_JA6K.js +1 -0
- package/src/web/dist/assets/ApiKeys-CEJ9-jBz.js +1 -0
- package/src/web/dist/assets/ConfirmDialog-DwZk3ejq.js +1 -0
- package/src/web/dist/assets/Dashboard-OPVlXupp.js +1 -0
- package/src/web/dist/assets/EChart-CfTG8iSv.js +1 -0
- package/src/web/dist/assets/Events-D7p4pym8.js +1 -0
- package/src/web/dist/assets/Help-DbNTCxxV.js +8 -0
- package/src/web/dist/assets/Login-h9CRbinI.js +1 -0
- package/src/web/dist/assets/Logs-DN-Cl2dm.js +1 -0
- package/src/web/dist/assets/ModelManagement-CrpcomEc.js +1 -0
- package/src/web/dist/assets/PageHeader-CbpaEUEn.js +1 -0
- package/src/web/dist/assets/PageSection-6q9HngU5.js +1 -0
- package/src/web/dist/assets/Settings-Bp_GpSh3.js +1 -0
- package/src/web/dist/assets/Skeleton-DFeA7kZw.js +1 -0
- package/src/web/dist/assets/card-DRsnBFyp.js +1 -0
- package/src/web/dist/assets/charts-core-BjxPMAw_.js +12 -0
- package/src/web/dist/assets/charts-engine-B4YVo-Wh.js +16 -0
- package/src/web/dist/assets/charts-react-BxiU3S4Y.js +1 -0
- package/src/web/dist/assets/i18n-qAxAISVU.js +1 -0
- package/src/web/dist/assets/index-BKEgpvTe.js +61 -0
- package/src/web/dist/assets/index-BfFWdxjR.css +1 -0
- package/src/web/dist/assets/input-BCUUQfiv.js +1 -0
- package/src/web/dist/assets/label-CtuP7N6a.js +1 -0
- package/src/web/dist/assets/query-BnTlXVsy.js +1 -0
- package/src/web/dist/assets/radix-CwKvZelb.js +5 -0
- package/src/web/dist/assets/router-Ju3lwB-M.js +19 -0
- package/src/web/dist/assets/select-C-e-41FP.js +1 -0
- package/src/web/dist/assets/switch-D72iMnTO.js +1 -0
- package/src/web/dist/assets/useApiQuery-C4-HjWYY.js +1 -0
- package/src/web/dist/assets/vendor-UrUELLAG.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 i,f as e,ab as Pe,ac as qe,Y as Oe,ad as Ie,ae as Ue,a4 as Ee,h as Be}from"./vendor-UrUELLAG.js";import{u as Ce,a as Ge,t as He,c as u,B as b}from"./index-BKEgpvTe.js";import{u as z}from"./useApiQuery-C4-HjWYY.js";import{T as Qe,a as O}from"./Skeleton-DFeA7kZw.js";import{P as We,B as K}from"./PageHeader-CbpaEUEn.js";import{c as Ve}from"./clipboard-CALi6bTW.js";import{I as le}from"./input-BCUUQfiv.js";import{L as D}from"./label-CtuP7N6a.js";import{C as Ne,a as ke}from"./card-DRsnBFyp.js";import{S as G,a as H,b as Q,c as W,d as _}from"./select-C-e-41FP.js";import{u as V}from"./i18n-qAxAISVU.js";import"./router-Ju3lwB-M.js";import"./radix-CwKvZelb.js";import"./query-BnTlXVsy.js";const we=[20,50,100];function _e(s,o=!1){if(!s)return;const c=o?`${s}T23:59:59.999`:`${s}T00:00:00.000`,y=Date.parse(c);return Number.isFinite(y)?y:void 0}function Te(s){const o=new Date(s);return`${o.getFullYear()}-${`${o.getMonth()+1}`.padStart(2,"0")}-${`${o.getDate()}`.padStart(2,"0")} ${`${o.getHours()}`.padStart(2,"0")}:${`${o.getMinutes()}`.padStart(2,"0")}:${`${o.getSeconds()}`.padStart(2,"0")}`}function C(s){return s==null?"-":s.toLocaleString()}function E(s,o){const c=C(s);return c==="-"?"-":`${c} ${o}`}function Je(s){return s?"true":"false"}function Se(s,o){if(!s||s.trim().length===0)return o;try{const c=JSON.parse(s);return JSON.stringify(c,null,2)}catch{return s}}function ps(){var ge,he,fe,je,be,ye;const{t:s}=V(),{pushToast:o}=Ce(),[c,y]=i.useState("all"),[h,l]=i.useState("all"),[m,j]=i.useState(""),[g,f]=i.useState("all"),[a,N]=i.useState(""),[r,x]=i.useState(""),[d,k]=i.useState(1),[p,$]=i.useState(we[0]),[J,A]=i.useState(null),[Le,ae]=i.useState(!1),[T,Y]=i.useState([]),[I,re]=i.useState(!1),[oe,Re]=i.useState(!1),[X,ie]=i.useState("comfortable"),[De,$e]=i.useState(!1),Z=i.useRef(null);i.useEffect(()=>{k(1)},[c,h,m,g,a,r,p,T]);const U=i.useMemo(()=>{const t={limit:p,offset:(d-1)*p};c!=="all"&&(t.provider=c),h!=="all"&&(t.endpoint=h),m.trim().length>0&&(t.model=m.trim()),g!=="all"&&(t.status=g);const n=_e(a),S=_e(r,!0);return n!==void 0&&(t.from=n),S!==void 0&&(t.to=S),T.length>0&&(t.apiKeys=T.join(",")),t},[c,h,m,g,a,r,d,p,T]),v=z(["logs",U],{url:"/api/logs",method:"GET",params:U}),F=z(["providers","all"],{url:"/api/providers",method:"GET"}),ne=z(["api-keys"],{url:"/api/keys",method:"GET"}),ee=z(["custom-endpoints"],{url:"/api/custom-endpoints",method:"GET"}),de=z(["config","export-timeout"],{url:"/api/config",method:"GET"});i.useEffect(()=>{v.isError&&v.error&&o({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:v.error.message}),variant:"error"})},[v.isError,v.error,o,s]),i.useEffect(()=>{F.isError&&F.error&&o({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:F.error.message}),variant:"error"})},[F.isError,F.error,o,s]);const L=((ge=v.data)==null?void 0:ge.total)??0,w=L>0?Math.ceil(L/p):0,ce=((he=v.data)==null?void 0:he.items)??[],me=i.useMemo(()=>{var n;const t=(n=de.data)==null?void 0:n.logExportTimeoutSeconds;return typeof t=="number"&&Number.isFinite(t)?Math.min(Math.max(Math.round(t),5),600)*1e3:6e4},[(fe=de.data)==null?void 0:fe.logExportTimeoutSeconds]);i.useEffect(()=>{w>0&&d>w&&k(w)},[w,d]);const se=F.data??[],B=i.useMemo(()=>{const t=new Map;for(const n of se)n.id&&t.set(n.id,n.label??n.id);return t},[se]),xe=i.useMemo(()=>{var n;const t=new Map;t.set("anthropic",s("logs.filters.endpointAnthropic")),t.set("openai",s("logs.filters.endpointOpenAI"));for(const S of((n=ee.data)==null?void 0:n.endpoints)??[])t.set(S.id,S.label||S.id);return t},[(je=ee.data)==null?void 0:je.endpoints,s]),M=i.useMemo(()=>{const t=[];if(c!=="all"){const n=B.get(c)??c;t.push({key:"provider",label:`${s("logs.filters.provider")}: ${n}`,onRemove:()=>y("all")})}if(h!=="all"){const n=xe.get(h)??h;t.push({key:"endpoint",label:`${s("logs.filters.endpoint")}: ${n}`,onRemove:()=>l("all")})}if(m.trim()&&t.push({key:"model",label:`${s("logs.filters.modelId")}: ${m.trim()}`,onRemove:()=>j("")}),g!=="all"){const n=s(g==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");t.push({key:"status",label:`${s("logs.filters.status")}: ${n}`,onRemove:()=>f("all")})}return a&&t.push({key:"from",label:`${s("logs.filters.startDate")}: ${a}`,onRemove:()=>N("")}),r&&t.push({key:"to",label:`${s("logs.filters.endDate")}: ${r}`,onRemove:()=>x("")}),T.length>0&&t.push({key:"apiKeys",label:s("logs.filters.apiKeySelected",{count:T.length}),onRemove:()=>Y([])}),t},[c,B,h,xe,m,g,a,r,T,s]),te=ne.data??[],ue=i.useMemo(()=>{const t=new Map;for(const n of te)t.set(n.id,n);return t},[te]),pe=()=>{y("all"),j(""),l("all"),f("all"),N(""),x(""),Y([])},Fe=i.useCallback(async()=>{if(!I){re(!0);try{const t=L>0?Math.min(L,5e3):1e3,n={...U,limit:t,offset:0},S=await Ge.post("/api/logs/export",n,{responseType:"blob",timeout:me}),Ke=new Blob([S.data],{type:"application/zip"}),Ae=new Date().toISOString().replace(/[:.]/g,"-"),ve=URL.createObjectURL(Ke),q=document.createElement("a");q.href=ve,q.download=`cc-gw-logs-${Ae}.zip`,document.body.appendChild(q),q.click(),q.remove(),URL.revokeObjectURL(ve),o({title:s("logs.toast.exportSuccess.title"),description:s("logs.toast.exportSuccess.desc"),variant:"success"})}catch(t){const n=He(t);o({title:s("logs.toast.exportError.title"),description:s("logs.toast.exportError.desc",{message:n.message}),variant:"error"})}finally{re(!1)}}},[me,I,o,U,s,L]),Me=i.useCallback(t=>{A(t),ae(!0)},[]),ze=i.useCallback(()=>{ae(!1),A(null)},[]),P=i.useCallback(()=>{const t=Z.current;if(!t)return;const n=t.scrollWidth-t.scrollLeft-t.clientWidth>1;$e(n)},[]);return i.useEffect(()=>{const t=Z.current;if(!t)return;P(),t.addEventListener("scroll",P,{passive:!0});const n=new ResizeObserver(P);return n.observe(t),()=>{t.removeEventListener("scroll",P),n.disconnect()}},[P]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(We,{icon:e.jsx(Oe,{className:"h-5 w-5","aria-hidden":"true"}),title:s("logs.title"),description:s("logs.description"),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:()=>ie("comfortable"),className:u("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",X==="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:()=>ie("compact"),className:u("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",X==="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(b,{onClick:Fe,disabled:I,children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}),s(I?"common.actions.loading":"logs.actions.export")]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.summary.total",{value:L.toLocaleString()})}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>v.refetch(),disabled:v.isFetching,children:[e.jsx(qe,{className:u("mr-2 h-4 w-4",v.isFetching&&"animate-spin")}),v.isFetching?s("common.actions.refreshing"):s("logs.actions.manualRefresh")]})]})}),e.jsx(Ne,{className:"sticky top-20 z-20 border-white/40 bg-card/90 backdrop-blur",children:e.jsxs(ke,{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(K,{variant:"outline",children:s("logs.summary.total",{value:L.toLocaleString()})}),M.length>0&&e.jsx(K,{variant:"secondary",children:s("common.filters.activeCount",{count:M.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[M.length>0&&e.jsx(b,{variant:"ghost",size:"sm",onClick:pe,children:s("common.actions.reset")}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>Re(t=>!t),children:oe?e.jsxs(e.Fragment,{children:[s("common.filters.collapse"),e.jsx(Ie,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[s("common.filters.expand"),e.jsx(Ue,{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:M.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:M.map(t=>e.jsxs(K,{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(Ee,{className:"h-3 w-3","aria-hidden":"true"})]},t.key))}):e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.filters.allRequests")})})})]}),oe&&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(D,{children:s("logs.filters.provider")}),e.jsxs(G,{value:c,onValueChange:y,children:[e.jsx(H,{children:e.jsx(Q,{})}),e.jsxs(W,{children:[e.jsx(_,{value:"all",children:s("logs.filters.providerAll")}),se.map(t=>e.jsx(_,{value:t.id,children:t.label??t.id},t.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{children:s("logs.filters.endpoint")}),e.jsxs(G,{value:h,onValueChange:l,children:[e.jsx(H,{children:e.jsx(Q,{})}),e.jsxs(W,{children:[e.jsx(_,{value:"all",children:s("logs.filters.endpointAll")}),e.jsx(_,{value:"anthropic",children:s("logs.filters.endpointAnthropic")}),e.jsx(_,{value:"openai",children:s("logs.filters.endpointOpenAI")}),(ye=(be=ee.data)==null?void 0:be.endpoints)==null?void 0:ye.map(t=>e.jsx(_,{value:t.id,children:t.label||t.id},t.id))]})]})]}),e.jsx(Ze,{className:"md:col-span-2",apiKeys:te,selected:T,disabled:ne.isLoading,onChange:Y}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{children:s("logs.filters.modelId")}),e.jsx(le,{value:m,onChange:t=>j(t.target.value),placeholder:s("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{children:s("logs.filters.status")}),e.jsxs(G,{value:g,onValueChange:t=>f(t),children:[e.jsx(H,{children:e.jsx(Q,{})}),e.jsxs(W,{children:[e.jsx(_,{value:"all",children:s("logs.filters.statusAll")}),e.jsx(_,{value:"success",children:s("logs.filters.statusSuccess")}),e.jsx(_,{value:"error",children:s("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{children:s("logs.filters.startDate")}),e.jsx(le,{type:"date",value:a,onChange:t=>N(t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(D,{children:s("logs.filters.endDate")}),e.jsx(le,{type:"date",value:r,onChange:t=>x(t.target.value)})]})]})]})}),e.jsx(Ne,{children:e.jsxs(ke,{className:"p-0",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:Z,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")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.provider")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheReadTokens")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheCreationTokens")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.latency")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.ttft")}),e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.tpot")}),e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:s("logs.table.columns.status")}),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:v.isPending?Array.from({length:8}).map((t,n)=>e.jsx(Qe,{columns:16},n)):ce.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:16,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")}),M.length>0&&e.jsx(b,{variant:"outline",size:"sm",onClick:pe,children:s("common.actions.reset")})]})})}):ce.map((t,n)=>e.jsx(Ye,{record:t,providerLabelMap:B,apiKeyMap:ue,onSelect:Me,isEven:n%2===0,density:X},t.id))})]})}),De&&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(G,{value:p.toString(),onValueChange:t=>$(Number(t)),children:[e.jsx(H,{className:"w-[80px]",children:e.jsx(Q,{})}),e.jsx(W,{children:we.map(t=>e.jsx(_,{value:t.toString(),children:t},t))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:()=>k(t=>Math.max(t-1,1)),disabled:d<=1,children:s("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.pageLabel",{page:w===0?0:d,total:w})}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>k(t=>w===0?t:Math.min(t+1,w)),disabled:w===0||d>=w,children:s("logs.table.pagination.next")})]})]})]})}),e.jsx(Xe,{open:Le,logId:J,onClose:ze,providerLabelMap:B,apiKeyMap:ue})]})}function Ye({record:s,providerLabelMap:o,apiKeyMap:c,onSelect:y,isEven:h,density:l}){const{t:m}=V(),j=o.get(s.provider)??s.provider,g=s.endpoint||"-",f=!!s.error,a=s.status_code,N=s.client_model??m("logs.table.requestedModelFallback"),r=s.api_key_id!=null?c.get(s.api_key_id):void 0,x=s.api_key_id==null?m("logs.table.apiKeyUnknown"):r!=null&&r.isWildcard?m("apiKeys.wildcard"):r!=null&&r.name?r.name:s.api_key_name?s.api_key_name:m("logs.table.apiKeyUnknown"),d=l==="compact"?"px-3 py-1.5":"px-3 py-2",k=h?"bg-muted/30":"bg-background";return e.jsxs("tr",{className:u("transition-colors",h?"bg-muted/30":"","hover:bg-muted/50"),children:[e.jsx("td",{className:u("sticky left-0 z-10 text-xs",d,k),children:Te(s.timestamp)}),e.jsx("td",{className:u(d,"text-xs"),children:g}),e.jsx("td",{className:u(d,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:j,children:j})}),e.jsx("td",{className:u(d,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:N,children:N})}),e.jsx("td",{className:u(d,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),e.jsx("td",{className:u(d,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:x,children:x})}),e.jsx("td",{className:u(d,"text-right text-xs tabular-nums"),children:C(s.input_tokens)}),e.jsx("td",{className:u(d,"text-right text-xs tabular-nums"),children:C(s.cache_read_tokens)}),e.jsx("td",{className:u(d,"text-right text-xs tabular-nums"),children:C(s.cache_creation_tokens)}),e.jsx("td",{className:u(d,"text-right text-xs tabular-nums"),children:C(s.output_tokens)}),e.jsx("td",{className:u(d,"text-right text-xs tabular-nums"),children:E(s.latency_ms,"ms")}),e.jsx("td",{className:u(d,"text-right text-xs tabular-nums"),children:E(s.ttft_ms,"ms")}),e.jsx("td",{className:u(d,"text-right text-xs tabular-nums"),children:E(s.tpot_ms,"ms/tk")}),e.jsx("td",{className:u(d,"text-center"),children:e.jsx(K,{variant:f?"destructive":"default",className:"text-xs",children:a??(f?500:200)})}),e.jsx("td",{className:u(d,"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:u("sticky right-0 z-10 text-center",d,k),children:e.jsx(b,{variant:"outline",size:"sm",onClick:()=>y(s.id),children:m("logs.actions.detail")})})]})}function Xe({open:s,logId:o,onClose:c,providerLabelMap:y,apiKeyMap:h}){var d,k;const{t:l}=V(),{pushToast:m}=Ce(),j=i.useRef(null),g=z(["log-detail",o],{url:`/api/logs/${o}`,method:"GET"},{enabled:s&&o!==null,staleTime:3e4});i.useEffect(()=>{g.isError&&g.error&&m({title:l("logs.detail.loadError"),description:g.error.message,variant:"error"})},[g.isError,g.error,m,l]),i.useEffect(()=>{if(!s)return;const p=$=>{$.key==="Escape"&&c()};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[s,c]),i.useEffect(()=>{s&&j.current&&j.current.focus()},[s,o]);const f=i.useCallback(async(p,$,J)=>{if(!$){m({title:l("logs.detail.copy.empty",{label:p}),variant:"info"});return}try{await Ve($),m({title:l(J),variant:"success"})}catch(A){m({title:l("logs.detail.copy.failure"),description:A instanceof Error?A.message:l("logs.detail.copy.failureFallback"),variant:"error"})}},[m,l]);if(!s)return null;const a=g.data,N=a?y.get(a.provider)??a.provider:"",r=a&&a.api_key_id!=null?h.get(a.api_key_id):void 0,x=a?a.status_code??(a.error?500:200):null;return typeof document>"u"?null:Be.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:l("logs.detail.title")}),a&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l("logs.detail.id",{id:a.id})})]}),e.jsxs(b,{ref:j,variant:"outline",size:"sm",onClick:c,children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"}),l("common.actions.close")]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:g.isPending?e.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[e.jsx(O,{className:"h-5 w-40"}),e.jsx(O,{className:"h-4 w-full"}),e.jsx(O,{className:"h-4 w-3/4"}),e.jsx(O,{className:"h-32 w-full"}),e.jsx(O,{className:"h-4 w-1/2"})]}):a?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:l("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:l("logs.detail.summary.route",{from:a.client_model??l("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-muted-foreground",children:l("logs.detail.summary.latency",{value:E(a.latency_ms,l("common.units.ms"))})}),a.ttft_ms!==null&&e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",E(a.ttft_ms,l("common.units.ms"))]}),e.jsx(K,{variant:a.error?"destructive":"default",children:x==null?void 0:x.toString()}),e.jsx(K,{variant:"outline",children:a.stream?l("logs.stream.streaming"):l("logs.stream.single")})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsx(R,{label:l("logs.detail.info.latency"),value:E(a.latency_ms,l("common.units.ms"))}),e.jsx(R,{label:l("logs.detail.info.ttft"),value:E(a.ttft_ms,l("common.units.ms"))}),e.jsx(R,{label:l("logs.detail.info.tpot"),value:E(a.tpot_ms,l("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:l("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:Te(a.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:a.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:a.endpoint||"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:N})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:a.client_model??l("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:a.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:Je(a.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l("logs.detail.info.status")}),e.jsx("dd",{className:"font-medium",children:x})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(R,{label:l("logs.detail.info.inputTokens"),value:C(a.input_tokens)}),e.jsx(R,{label:l("logs.detail.info.cacheReadTokens"),value:C(a.cache_read_tokens)}),e.jsx(R,{label:l("logs.detail.info.cacheCreationTokens"),value:C(a.cache_creation_tokens)}),e.jsx(R,{label:l("logs.detail.info.outputTokens"),value:C(a.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:l("logs.detail.info.latency")}),e.jsx("dd",{className:"font-medium",children:E(a.latency_ms,l("common.units.ms"))})]})}),a.error&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:l("logs.detail.info.error")}),e.jsx("p",{className:"rounded-[1rem] border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:a.error})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:l("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:l("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id==null&&!a.api_key_name?l("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?l("apiKeys.wildcard"):(r==null?void 0:r.name)??a.api_key_name??l("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id??l("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:r!=null&&r.isWildcard?l("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??a.api_key_name??l("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():l("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:l("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:a.api_key_value_available?a.api_key_value_masked??l("logs.detail.apiKey.rawUnavailable"):l("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:l("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(b,{variant:"outline",size:"sm",onClick:()=>{var p;return f(l("logs.detail.payload.request"),(p=a.payload)==null?void 0:p.prompt,"logs.detail.copy.requestSuccess")},children:[l("logs.detail.payload.request")," · ",l("common.actions.copy")]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>{var p;return f(l("logs.detail.payload.response"),(p=a.payload)==null?void 0:p.response,"logs.detail.copy.responseSuccess")},children:[l("logs.detail.payload.response")," · ",l("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:l("logs.detail.payload.request")}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>{var p;return f(l("logs.detail.payload.request"),(p=a.payload)==null?void 0:p.prompt,"logs.detail.copy.requestSuccess")},children:l("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:Se((d=a.payload)==null?void 0:d.prompt,l("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:l("logs.detail.payload.response")}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>{var p;return f(l("logs.detail.payload.response"),(p=a.payload)==null?void 0:p.response,"logs.detail.copy.responseSuccess")},children:l("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:Se((k=a.payload)==null?void 0:k.response,l("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify-center p-8 text-sm text-muted-foreground",children:l("logs.detail.loadError")})})]})]}),document.body)}function R({label:s,value:o}){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:o})]})}function Ze({apiKeys:s,selected:o,onChange:c,disabled:y,className:h}){const{t:l}=V(),[m,j]=i.useState(!1),g=i.useRef(null);i.useEffect(()=>{if(!m)return;const r=x=>{var d;(d=g.current)!=null&&d.contains(x.target)||j(!1)};return window.addEventListener("mousedown",r),()=>window.removeEventListener("mousedown",r)},[m]);const f=i.useMemo(()=>{if(o.length===0)return[];const r=new Map;for(const x of s)r.set(x.id,x);return o.map(x=>{const d=r.get(x);return d?d.isWildcard?l("apiKeys.wildcard"):d.name:null}).filter(x=>!!x)},[s,o,l]),a=o.length===0?l("logs.filters.apiKeyAll"):l("logs.filters.apiKeySelected",{count:o.length}),N=r=>{o.includes(r)?c(o.filter(x=>x!==r)):c([...o,r])};return e.jsxs("div",{className:u("relative space-y-2",h),ref:g,children:[e.jsx(D,{children:l("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>j(r=>!r),disabled:y||s.length===0,title:l("logs.filters.apiKeyHint"),className:u("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",o.length>0&&"border-primary",m&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[a,f.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:f.join(", ")})]}),e.jsx("svg",{className:u("h-4 w-4 opacity-50 transition-transform",m&&"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"})})]}),m&&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:a}),e.jsx("button",{type:"button",onClick:()=>c([]),disabled:o.length===0,className:"text-primary hover:underline disabled:opacity-40",children:l("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(r=>{const x=r.isWildcard?l("apiKeys.wildcard"):r.name,d=o.includes(r.id);return e.jsxs("label",{className:u("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",d&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:d,onChange:()=>N(r.id)}),e.jsx("span",{className:"truncate",children:x})]},r.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:l("logs.filters.apiKeyAll")})]})]})]})}export{ps as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as h,f as e,ai as Fe,Z as Wt,a4 as Se,ac as es,aj as le,ae as ts,N as ss}from"./vendor-UrUELLAG.js";import{u as rs,a as as,b as rt}from"./query-BnTlXVsy.js";import{c as ie,u as it,B as D,a as Y,b as ye,t as Re,T as os,d as ns,f as ds,g as ls}from"./index-BKEgpvTe.js";import{u as is}from"./useApiQuery-C4-HjWYY.js";import{P as cs,B as V}from"./PageHeader-CbpaEUEn.js";import{C as ms,D as ct,a as mt,b as ut,c as pt,d as xt,e as ht}from"./ConfirmDialog-DwZk3ejq.js";import{I as re}from"./input-BCUUQfiv.js";import{L as te}from"./label-CtuP7N6a.js";import{C as Le,a as Ae}from"./card-DRsnBFyp.js";import{S as gt}from"./switch-D72iMnTO.js";import{S as ft,a as bt,b as vt,c as jt,d as Z}from"./select-C-e-41FP.js";import{l as us,m as ps,n as xs,o as yt}from"./radix-CwKvZelb.js";import{u as ce}from"./i18n-qAxAISVU.js";import"./router-Ju3lwB-M.js";const hs=us,gs=ps,Nt=h.forwardRef(({className:s,align:l="center",sideOffset:f=4,...g},x)=>e.jsx(xs,{children:e.jsx(yt,{ref:x,align:l,sideOffset:f,className:ie("z-50 w-72 rounded-[1.25rem] border border-white/60 bg-popover/95 p-4 text-popover-foreground shadow-[0_16px_40px_-28px_rgba(15,23,42,0.45)] backdrop-blur outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...g})}));Nt.displayName=yt.displayName;function Be(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function fs(){return{_key:Be(),id:"",label:""}}const Ee={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:{}},at=[{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 ot(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:Be()})),authMode:s.authMode??"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function bs(s){return{_key:Be(),id:s.id,label:s.label}}function vs({open:s,mode:l,provider:f,existingProviderIds:g,onClose:x,onSubmit:N}){const{t:a}=ce(),[c,M]=h.useState(()=>ot(f)),[p,P]=h.useState({}),[F,L]=h.useState(!1),[E,w]=h.useState(null),v=h.useRef(null),C=h.useRef(null),I=h.useRef(null),[K,Ne]=h.useState(l==="edit");h.useEffect(()=>{s&&(M(ot(f)),P({}),w(null),L(!1),Ne(l==="edit"))},[s,f,l]),h.useEffect(()=>{if(!s)return;const i=b=>{b.key==="Escape"&&x()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[s,x]),h.useEffect(()=>{if(s){if(l==="create"&&I.current){I.current.focus();return}C.current&&C.current.focus()}},[s,l]);const ae=l==="create",me=h.useMemo(()=>c.models.filter(i=>i.id.trim().length>0),[c.models]),ue=h.useMemo(()=>{var i;return((i=at.find(b=>b.value===c.type))==null?void 0:i.label)??"Custom"},[c.type]),G=c.label.trim()||c.id.trim()||a("providers.drawer.summary.untitled"),A=h.useMemo(()=>[{label:a("providers.drawer.summary.type"),value:ue},{label:a("providers.drawer.summary.auth"),value:c.authMode==="apiKey"?a("providers.drawer.fields.authModeApiKey"):c.authMode==="authToken"?a("providers.drawer.fields.authModeAuthToken"):a("providers.drawer.fields.authModeXAuthToken")},{label:a("providers.drawer.summary.models"),value:me.length.toLocaleString()}],[me.length,c.authMode,ue,a]),pe=i=>b=>{M(S=>({...S,[i]:b}))},z=i=>{M(b=>{const k=!K||b.label.trim().length===0||b.label===b.id?i:b.label;return{...b,id:i,label:k}})},De=i=>{M(b=>{var he;const k=Ee[i??"custom"]??Ee.custom,O=Object.values(Ee).map(Q=>Q.baseUrl).filter(Q=>!!Q),X=!b.baseUrl||O.includes(b.baseUrl),H=l==="create"&&(b.models.length===0||b.models.every(Q=>Q.id.trim().length===0)),q={...b,type:i,authMode:b.authMode??"apiKey"};return k!=null&&k.baseUrl&&X&&(q.baseUrl=k.baseUrl),k!=null&&k.models&&H&&(q.models=k.models.map(bs),q.defaultModel=k.defaultModel??((he=k.models[0])==null?void 0:he.id)??""),q})},we=(i,b)=>{M(S=>{const k=[...S.models];return k[i]={...k[i],...b},{...S,models:k}})},ke=(i,b)=>{M(S=>{const k=[...S.models],O=k[i];if(!O)return S;const X=!K||!O.label||O.label===O.id,H={...O,id:b,label:X?b:O.label};k[i]=H;const q=S.defaultModel===O.id?b:S.defaultModel;return{...S,models:k,defaultModel:q}})},xe=i=>{M(b=>{if(i<0||i>=b.models.length)return b;const S=b.models.filter((O,X)=>X!==i);let k=b.defaultModel;return S.some(O=>O.id===k)||(k=""),{...b,models:S,defaultModel:k}})},Me=()=>{M(i=>({...i,models:[...i.models,fs()]}))},oe=i=>{M(b=>({...b,authMode:i}))},Pe=()=>{const i={},b=c.id.trim(),S=c.baseUrl.trim();if(l==="create"&&(b.length===0?i.id=a("providers.drawer.errors.idRequired"):g.includes(b)&&(i.id=a("providers.drawer.errors.idDuplicate"))),l==="edit"&&b.length===0&&(i.id=a("providers.drawer.errors.idRequired")),S.length===0)i.baseUrl=a("providers.drawer.errors.baseUrlInvalid");else try{new URL(S)}catch{i.baseUrl=a("providers.drawer.errors.baseUrlInvalid")}if(c.models.length>0){const k=new Set;c.models.some(X=>{const H=X.id.trim();return H.length===0||k.has(H)?!0:(k.add(H),!1)})&&(i.models=a("providers.drawer.errors.modelInvalid"))}return c.defaultModel&&!c.models.some(k=>k.id===c.defaultModel)&&(i.models=a("providers.drawer.errors.defaultInvalid")),P(i),Object.keys(i).length===0},ne=()=>{const i=c.models.map(k=>{var O;return{id:k.id.trim(),label:(O=k.label)!=null&&O.trim()?k.label.trim():void 0}}).filter(k=>k.id.length>0),b=f!=null&&f.extraHeaders&&Object.keys(f.extraHeaders).length>0?f.extraHeaders:void 0,S=c.authMode!=="apiKey"?c.authMode:void 0;return{id:c.id.trim(),label:c.label.trim()||c.id.trim(),baseUrl:c.baseUrl.trim(),apiKey:c.apiKey.trim()||void 0,type:c.type??"custom",defaultModel:c.defaultModel||void 0,models:i.length>0?i:void 0,extraHeaders:b,authMode:S}},_e=async()=>{if(w(null),!!Pe()){L(!0);try{const i=ne();await N(i)}catch(i){w(a("providers.drawer.toast.saveFailure",{message:i instanceof Error?i.message:"unknown"})),L(!1);return}L(!1),x()}};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:x,"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:a(ae?"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:a(ae?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:a("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:C,onClick:x,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:a("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:A.map(i=>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:i.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:i.value})]},i.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:a("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:at.map(i=>{var S;const b=i.value===c.type;return e.jsxs("button",{type:"button",onClick:()=>De(i.value),className:ie("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:i.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((S=Ee[i.value??"custom"])==null?void 0:S.baseUrl)??a("providers.drawer.hints.customProvider")})]},i.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:a("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>Ne(i=>!i),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:a(K?"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:a("providers.drawer.fields.id")}),e.jsx("input",{value:c.id,ref:I,onChange:i=>z(i.target.value),disabled:!ae,placeholder:a("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":!!p.id}),p.id?e.jsx("span",{className:"text-xs text-red-500",children:p.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.label")}),e.jsx("input",{value:c.label,onChange:i=>pe("label")(i.target.value),placeholder:a("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:a("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:c.baseUrl,onChange:i=>pe("baseUrl")(i.target.value),placeholder:a("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":!!p.baseUrl}),p.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:p.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:a("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("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:a("providers.drawer.fields.apiKey")}),e.jsx("input",{value:c.apiKey,onChange:i=>pe("apiKey")(i.target.value),placeholder:a("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:a("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:a("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:c.authMode==="apiKey",onChange:()=>oe("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:a("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:c.authMode==="authToken",onChange:()=>oe("authToken"),className:"mt-0.5"}),e.jsx("span",{children:a("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:c.authMode==="xAuthToken",onChange:()=>oe("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:a("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:a("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:Me,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:a("providers.drawer.fields.addModel")})]}),p.models?e.jsx("p",{className:"text-xs text-red-500",children:p.models}):null,e.jsxs("div",{className:"space-y-4",children:[c.models.map((i,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:a("providers.drawer.fields.modelId")}),e.jsx("input",{value:i.id,onChange:S=>ke(b,S.target.value),placeholder:a("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"})]}),K?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:i.label??"",onChange:S=>we(b,{label:S.target.value}),placeholder:a("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:i.id,checked:c.defaultModel===i.id,onChange:()=>M(S=>({...S,defaultModel:i.id})),disabled:i.id.trim().length===0}),a("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:()=>xe(b),disabled:c.models.length===0,children:a("providers.drawer.fields.removeModel")})]})]},i._key)),c.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:a("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:a("providers.drawer.noModelsHint",{providerId:c.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:a("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-*": "',(c.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),me.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:a("providers.drawer.defaultHint",{model:c.defaultModel||a("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:a("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:G}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:A.map(i=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:i.label}),e.jsx("span",{className:"text-right font-medium",children:i.value})]},i.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:a("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:a("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:a("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:a("providers.drawer.hints.checkModels")})]})]}),K&&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:a("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:a("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:E?e.jsx("span",{children:E}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:x,className:"rounded-full border border-border/80 bg-background/85 px-4 py-2 transition hover:border-primary/20 hover:bg-primary/5",disabled:F,children:a("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:_e,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:F,children:a(F?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const js=["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"],ys=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function Ke(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function W(s){return s?Object.entries(s).map(([l,f])=>({id:Ke(),source:l,target:f})):[]}function $e(s,l){var x,N,a;if(!s)return{};const f={},g=s.endpointRouting??{};f.anthropic=W(((x=g.anthropic)==null?void 0:x.modelRoutes)??s.modelRoutes??{}),f.openai=W(((N=g.openai)==null?void 0:N.modelRoutes)??{});for(const c of l)(a=c.routing)!=null&&a.modelRoutes?f[c.id]=W(c.routing.modelRoutes):f[c.id]=[];return f}function nt(s,l,f){var N,a,c;const g=l.find(M=>M.id===f);if(g)return((N=g.routing)==null?void 0:N.modelRoutes)??{};const x=s.endpointRouting??{};return f==="anthropic"?((a=x.anthropic)==null?void 0:a.modelRoutes)??s.modelRoutes??{}:f==="openai"?((c=x.openai)==null?void 0:c.modelRoutes)??{}:{}}function Ns(s){const l={};for(const f of s){const g=f.source.trim(),x=f.target.trim();g&&x&&(l[g]=x)}return l}function dt(s,l){return JSON.stringify(Ns(s))!==JSON.stringify(l)}function ws(s,l){if(s==="anthropic")return!0;const f=l.find(g=>g.id===s);return f?f.paths&&f.paths.length>0?f.paths.some(g=>g.protocol==="anthropic"):f.protocol==="anthropic":!1}function ks(s,l,f){var x,N,a;if(!l)return;if(s==="anthropic"||s==="openai")return(N=(x=l.endpointRouting)==null?void 0:x[s])==null?void 0:N.validation;const g=f.find(c=>c.id===s);return(a=g==null?void 0:g.routing)==null?void 0:a.validation}function Vs(){const{t:s}=ce(),{pushToast:l}=it(),f=rs(),g=is(["config","full"],{url:"/api/config",method:"GET"}),{data:x}=as({queryKey:["custom-endpoints"],queryFn:ye.list,refetchInterval:1e4}),N=(x==null?void 0:x.endpoints)??[],a=h.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"]}],o=N.map(r=>{let n,d=[];if(r.paths&&r.paths.length>0){const m=r.paths.map(u=>`${u.path} (${u.protocol})`).join(", ");n=`${s("modelManagement.tabs.customEndpoint")}: ${m}`,d=[...new Set(r.paths.map(u=>u.protocol))]}else if(r.path){const m=r.protocol||"anthropic";n=`${s("modelManagement.tabs.customEndpoint")}: ${r.path} (${m})`,d=[m]}else n=s("modelManagement.tabs.customEndpoint");return{key:r.id,label:r.label,description:n,isSystem:!1,canDelete:r.deletable!==!1,protocols:d}});return[...t,...o]},[s,N]),[c,M]=h.useState("providers"),[p,P]=h.useState(null),[F,L]=h.useState(!1),[E,w]=h.useState("create"),[v,C]=h.useState(void 0),[I,K]=h.useState(null),[Ne,ae]=h.useState(!1),[me,ue]=h.useState(void 0),[G,A]=h.useState({}),[pe,z]=h.useState({}),[De,we]=h.useState(null),[ke,xe]=h.useState({}),[Me,oe]=h.useState({}),[Pe,ne]=h.useState({}),[_e,i]=h.useState(null),[b,S]=h.useState(null),[k,O]=h.useState(null),[X,H]=h.useState(!1),[q,he]=h.useState(null),[Q,Te]=h.useState(!0),[ze,Ve]=h.useState({}),[wt,He]=h.useState(!1),[kt,Mt]=h.useState({}),[Oe,Ue]=h.useState(null),[y,ge]=h.useState(null),[Ie,qe]=h.useState(!1),[Ce,Qe]=h.useState(""),[fe,Ge]=h.useState("all"),B=(p==null?void 0:p.providers)??[],Ct=B.length,Xe=h.useMemo(()=>B.filter(t=>{var d;if(!(fe==="all"||(t.type??"custom")===fe))return!1;const r=Ce.trim().toLowerCase();return r?[t.id,t.label??"",t.baseUrl,t.defaultModel??"",...((d=t.models)==null?void 0:d.map(m=>m.id))??[]].join(" ").toLowerCase().includes(r):!0}),[Ce,fe,B]),be=h.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]);h.useEffect(()=>{var t,o;if(g.data){const r=g.data;P(r),A(d=>{const m=$e(r,N);if(!d||Object.keys(d).length===0)return m;const u={...m};for(const[j,R]of Object.entries(d)){if(!(j in m))continue;const U=nt(r,N,j);dt(R,U)&&(u[j]=R)}return u}),z({});const n={anthropic:((t=r.routingPresets)==null?void 0:t.anthropic)??[],openai:((o=r.routingPresets)==null?void 0:o.openai)??[]};for(const d of N)n[d.id]=d.routingPresets??[];xe(n)}},[g.data,N]),h.useEffect(()=>{g.isError&&g.error&&l({title:s("providers.toast.loadFailure",{message:g.error.message}),variant:"error"})},[g.isError,g.error,l,s]);const Je=h.useMemo(()=>{const t=new Map;for(const o of B){if(!o.defaultModel||!o.models)continue;const r=o.models.find(n=>n.id===o.defaultModel);r&&t.set(o.id,lt(r))}return t},[B]),Et=h.useMemo(()=>{const t=[],o=new Set;for(const n of B){const d=n.label&&n.label!==n.id?`${n.label} (${n.id})`:n.id,m=n.models??[];if(m.length>0)for(const j of m){const R=`${n.id}:${j.id}`;o.has(R)||(o.add(R),t.push({value:R,label:`${d} · ${j.label??j.id}`}))}else if(n.defaultModel){const j=`${n.id}:${n.defaultModel}`;o.has(j)||(o.add(j),t.push({value:j,label:`${d} · ${n.defaultModel}`}))}const u=`${n.id}:*`;o.has(u)||(o.add(u),t.push({value:u,label:s("settings.routing.providerPassthroughOption",{provider:d})}))}const r=Object.values(G).flat();for(const n of r){const d=n.target.trim();d&&!o.has(d)&&(o.add(d),t.push({value:d,label:d}))}return t},[B,G,s]),St=t=>p?nt(p,N,t):{},Rt=(t,o)=>dt(t,o),Ye=h.useMemo(()=>{const t={};for(const o of a){if(o.key==="providers")continue;const r=G[o.key]||[],n=St(o.key);t[o.key]=Rt(r,n)}return t},[G,p,N,a]),Ze=(t,o)=>{xe(r=>({...r,[t]:o})),P(r=>{if(!r)return r;if(t==="anthropic"||t==="openai")return{...r,routingPresets:{...r.routingPresets,[t]:o}};const n=r.customEndpoints??[],d=n.findIndex(u=>u.id===t);if(d===-1)return r;const m=[...n];return m[d]={...m[d],routingPresets:o},{...r,customEndpoints:m}})},ee=()=>p?!0:(l({title:s("settings.toast.missingConfig"),variant:"error"}),g.refetch(),!1),Dt=(t,o)=>{oe(r=>({...r,[t]:o})),o.trim()&&ne(r=>({...r,[t]:null}))},Pt=async t=>{if(!ee())return;const o=Me[t].trim();if(!o){ne(r=>({...r,[t]:s("modelManagement.validation.presetName")}));return}if(ke[t].some(r=>r.name.toLowerCase()===o.toLowerCase())){ne(r=>({...r,[t]:s("modelManagement.validation.presetDuplicate",{name:o})}));return}i(t);try{const n=(await Y.post(`/api/routing-presets/${t}`,{name:o})).data.presets??[];Ze(t,n),oe(d=>({...d,[t]:""})),ne(d=>({...d,[t]:null})),l({title:s("modelManagement.toast.presetSaved",{name:o}),variant:"success"})}catch(r){l({title:s("modelManagement.toast.presetSaveFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{i(null),g.refetch()}},_t=async(t,o)=>{var r,n,d;if(ee()){S({endpoint:t,name:o.name});try{const u=(await Y.post(`/api/routing-presets/${t}/apply`,{name:o.name})).data.config;if(u){P(u),A($e(u,N));const j={anthropic:((r=u.routingPresets)==null?void 0:r.anthropic)??[],openai:((n=u.routingPresets)==null?void 0:n.openai)??[]};for(const R of N){const U=(d=u.customEndpoints)==null?void 0:d.find(_=>_.id===R.id);j[R.id]=(U==null?void 0:U.routingPresets)??[]}xe(j)}else A(j=>({...j,[t]:W(o.modelRoutes)}));l({title:s("modelManagement.toast.presetApplySuccess",{name:o.name}),variant:"success"})}catch(m){l({title:s("modelManagement.toast.presetApplyFailure",{message:m instanceof Error?m.message:"unknown"}),variant:"error"})}finally{S(null),g.refetch()}}},Tt=async(t,o)=>{if(ee()){O({endpoint:t,name:o.name});try{const n=(await Y.delete(`/api/routing-presets/${t}/${encodeURIComponent(o.name)}`)).data.presets??[];Ze(t,n),l({title:s("modelManagement.toast.presetDeleteSuccess",{name:o.name}),variant:"success"})}catch(r){l({title:s("modelManagement.toast.presetDeleteFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{O(null),g.refetch()}}},Ot=()=>{ee()&&(w("create"),C(void 0),L(!0))},Ut=t=>{ee()&&(w("edit"),C(t),L(!0))},It=async t=>{if(!p)throw new Error(s("settings.toast.missingConfig"));const o=E==="create"?[...B,t]:B.map(d=>v&&d.id===v.id?{...t,id:v.id}:d),r={...p,providers:o};await Y.put("/api/config",r),P(r),A($e(r,N)),g.refetch();const n=E==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});l({title:n,variant:"success"})},Lt=async t=>{const o=N.find(r=>r.id===t);if(o&&o.deletable!==!1)try{await ye.delete(t),f.invalidateQueries({queryKey:["custom-endpoints"]}),l({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),c===t&&M("providers")}catch(r){const n=Re(r);l({title:s("modelManagement.deleteEndpointError",{error:n.message}),variant:"error"})}},We=async(t,o)=>{K(t.id);try{const r=o&&(o.headers||o.query)?{headers:o.headers&&Object.keys(o.headers).length>0?o.headers:void 0,query:o.query&&o.query.trim().length>0?o.query.trim():void 0}:void 0,n=await Y.post(`/api/providers/${t.id}/test`,r);n.data.ok?l({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:n.data.status,duration:n.data.durationMs?`${n.data.durationMs} ms`:"—"}),variant:"success"}):l({title:s("providers.toast.testFailure",{message:`${n.data.status} ${n.data.statusText}`}),variant:"error"})}catch(r){l({title:s("providers.toast.testFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{K(null)}},At=t=>{if(t.type==="anthropic"){const o=t.extraHeaders??{},r=new Map(be.map(m=>[m.key.toLowerCase(),m])),n={};let d=!0;for(const m of be){const u=Object.entries(o).find(([j])=>j.toLowerCase()===m.key.toLowerCase());if(u){const[j,R]=u;String(R??"")===m.value||(d=!1,n[j]=String(R??""))}}for(const[m,u]of Object.entries(o))r.has(m.toLowerCase())||(n[m]=String(u??""));Ve(n),Te(d),he(t),H(!0);return}We(t)},et=()=>{H(!1),he(null),Te(!0),Ve({})},$t=async()=>{if(!q)return;const t={};if(Q)for(const n of be)t[n.key]=n.value;const o=new Map(be.map(n=>[n.key.toLowerCase(),n]));for(const[n,d]of Object.entries(ze)){const m=n.toLowerCase();o.get(m)&&Q||(t[n]=d)}const r=q;et(),await We(r,{headers:Object.keys(t).length>0?t:void 0,query:Q?"beta=true":void 0})},Ft=async t=>{var j,R,U,_;if(!ee())return;const o=B.filter($=>$.id!==t.id),r=$=>{const J={};if(!$)return J;for(const[ve,de]of Object.entries($)){if(!de)continue;const[je]=de.split(":");je&&je===t.id||de===t.id||(J[ve]=de)}return J},n=(p==null?void 0:p.endpointRouting)??{},d=r(((j=n.anthropic)==null?void 0:j.modelRoutes)??(p==null?void 0:p.modelRoutes)??{}),m=r(((R=n.openai)==null?void 0:R.modelRoutes)??{}),u={...p,providers:o,modelRoutes:d,endpointRouting:{anthropic:{defaults:((U=n.anthropic)==null?void 0:U.defaults)??p.defaults,modelRoutes:d},openai:{defaults:((_=n.openai)==null?void 0:_.defaults)??p.defaults,modelRoutes:m}}};try{await Y.put("/api/config",u),P(u),A({anthropic:W(d),openai:W(m)}),l({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),g.refetch()}catch($){l({title:s("providers.toast.deleteFailure",{message:$ instanceof Error?$.message:"unknown"}),variant:"error"})}},Kt=async()=>{if(y){qe(!0);try{y.kind==="provider"?await Ft(y.provider):y.kind==="preset"?await Tt(y.endpoint,y.preset):await Lt(y.endpoint.id),ge(null)}finally{qe(!1)}}},Bt=t=>{A(o=>({...o,[t]:[...o[t]||[],{id:Ke(),source:"",target:""}]})),z(o=>({...o,[t]:null}))},zt=async(t,o)=>{if(ee()){He(!0);try{if(t==="anthropic"||t==="openai"){const r=p.endpointRouting?{...p.endpointRouting}:{},n=r[t]??{defaults:p.defaults,modelRoutes:(t==="anthropic"?p.modelRoutes:{})??{}},d={defaults:n.defaults??p.defaults,modelRoutes:n.modelRoutes??{}};let m=n.validation;o?(m={...m??{},mode:"claude-code"},m.allowExperimentalBlocks===void 0&&(m.allowExperimentalBlocks=!0)):m=void 0;const u=m?{...d,validation:m}:{...d},j={...r,[t]:u},R={...p,endpointRouting:j};await Y.put("/api/config",R),P(R)}else{const r=p.customEndpoints??[],n=r.findIndex($=>$.id===t);if(n===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const d=r[n],m=d.routing??{defaults:p.defaults,modelRoutes:{}};let u=m.validation;o?(u={...u??{},mode:"claude-code"},u.allowExperimentalBlocks===void 0&&(u.allowExperimentalBlocks=!0)):u=void 0;const j=u?{...m,validation:u}:{...m},R={...d,routing:j},U=[...r];U[n]=R;const _={...p,customEndpoints:U};await Y.put("/api/config",_),P(_)}l({title:s(o?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),g.refetch()}catch(r){const n=Re(r);l({title:s("modelManagement.toast.claudeValidationFailure",{message:n.message}),variant:"error"})}finally{He(!1)}}},Vt=(t,o)=>{A(r=>{const n=r[t]||[];return n.some(d=>d.source.trim()===o.trim())?r:{...r,[t]:[...n,{id:Ke(),source:o,target:""}]}}),z(r=>({...r,[t]:null}))},tt=(t,o,r,n)=>{A(d=>({...d,[t]:(d[t]||[]).map(m=>m.id===o?{...m,[r]:n}:m)})),z(d=>({...d,[t]:null}))},Ht=(t,o)=>{A(r=>({...r,[t]:(r[t]||[]).filter(n=>n.id!==o)})),z(r=>({...r,[t]:null}))},qt=t=>{var r,n;if(!p)return;const o=N.find(d=>d.id===t);if(o){const d=((r=o.routing)==null?void 0:r.modelRoutes)??{};A(m=>({...m,[t]:W(d)}))}else{const d=p.endpointRouting??{},m=t,u=m==="anthropic"?p.modelRoutes??{}:{},j=((n=d[m])==null?void 0:n.modelRoutes)??u;A(R=>({...R,[t]:W(j)}))}z(d=>({...d,[t]:null}))},Qt=async t=>{var n;if(!ee())return;const o=G[t]||[],r={};for(const d of o){const m=d.source.trim(),u=d.target.trim();if(!(!m&&!u)){if(!m||!u){z(j=>({...j,[t]:s("settings.validation.routePair")}));return}if(r[m]){z(j=>({...j,[t]:s("settings.validation.routeDuplicate",{model:m})}));return}r[m]=u}}z(d=>({...d,[t]:null})),we(t);try{const d=N.find(m=>m.id===t);if(d){const m={...d.routing||{},modelRoutes:r,defaults:((n=d.routing)==null?void 0:n.defaults)||p.defaults};await ye.update(t,{routing:m}),f.invalidateQueries({queryKey:["custom-endpoints"]}),l({title:s("modelManagement.toast.routesSaved"),variant:"success"})}else{const m=p.endpointRouting?{...p.endpointRouting}:{},u=t,j=m[u]??{defaults:p.defaults,modelRoutes:u==="anthropic"?p.modelRoutes??{}:{}},R={...j,defaults:j.defaults??p.defaults,modelRoutes:r},U={...m,[u]:R},_={...p,endpointRouting:U,modelRoutes:u==="anthropic"?r:p.modelRoutes??{}};await Y.put("/api/config",_),P(_),l({title:s("modelManagement.toast.routesSaved"),variant:"success"}),g.refetch()}A(m=>({...m,[t]:W(r)}))}catch(d){l({title:s("modelManagement.toast.routesSaveFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{we(null)}},Gt=()=>e.jsx(Le,{className:"surface-1",children:e.jsxs(Ae,{className:"pt-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("providers.title")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s("providers.description")})]}),e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto sm:gap-3",children:[e.jsx(V,{variant:"secondary",children:s("providers.count",{count:Ct})}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>g.refetch(),disabled:g.isFetching,children:[e.jsx(es,{className:ie("mr-2 h-4 w-4",g.isFetching&&"animate-spin")}),g.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")]}),e.jsxs(D,{size:"sm",onClick:Ot,children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"}),s("providers.actions.add")]})]})]}),e.jsxs("div",{className:"grid gap-3 rounded-[1.35rem] border border-white/40 bg-background/45 p-4 md:grid-cols-[minmax(0,1fr)_220px_auto]",children:[e.jsx(re,{value:Ce,onChange:t=>Qe(t.target.value),placeholder:s("providers.filters.searchPlaceholder")}),e.jsxs(ft,{value:fe,onValueChange:Ge,children:[e.jsx(bt,{children:e.jsx(vt,{})}),e.jsxs(jt,{children:[e.jsx(Z,{value:"all",children:s("providers.filters.typeAll")}),e.jsx(Z,{value:"openai",children:"OpenAI"}),e.jsx(Z,{value:"anthropic",children:"Anthropic"}),e.jsx(Z,{value:"deepseek",children:"DeepSeek"}),e.jsx(Z,{value:"huawei",children:"Huawei"}),e.jsx(Z,{value:"kimi",children:"Kimi"}),e.jsx(Z,{value:"custom",children:"Custom"})]})]}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>{Qe(""),Ge("all")},disabled:!Ce.trim()&&fe==="all",children:s("common.actions.reset")})]}),g.isPending||!p&&g.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")}):B.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:"点击上方按钮添加您的第一个提供商"})})]}):Xe.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:Xe.map(t=>{var o;return e.jsx(Le,{className:"surface-1 flex flex-col",children:e.jsxs(Ae,{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:"font-semibold",children:t.label||t.id}),t.type&&e.jsx(Ss,{type:t.type})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",t.id]}),e.jsx("p",{className:"text-xs text-muted-foreground break-all",children:t.baseUrl})]}),t.defaultModel?e.jsx(V,{variant:"default",className:"text-xs",children:Je.get(t.id)??t.defaultModel}):e.jsx(V,{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-xl border border-border/70 bg-background/60 px-3 py-2",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-xl border border-border/70 bg-background/60 px-3 py-2",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:(o=t.models)!=null&&o.length?s("providers.card.modelCount",{count:t.models.length}):s("providers.card.passthrough")})]}),e.jsxs("div",{className:"rounded-xl border border-border/70 bg-background/60 px-3 py-2",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?Je.get(t.id)??t.defaultModel:s("providers.card.noDefault")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(te,{className:"text-xs",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(r=>e.jsx(V,{variant:"outline",className:"text-xs",children:lt(r)},r.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 pt-4",children:[e.jsx(D,{variant:"default",size:"sm",onClick:()=>Ut(t),children:s("providers.actions.edit")}),e.jsx(D,{variant:"outline",size:"sm",onClick:()=>At(t),disabled:I===t.id,children:I===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx(D,{variant:"destructive",size:"sm",onClick:()=>ge({kind:"provider",provider:t}),children:s("providers.actions.delete")})]})]})},t.id)})})]})}),Xt=t=>{const o=ke[t]??[],r=Me[t]??"",n=Pe[t],d=_e===t,m=kt[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:()=>Mt(u=>({...u,[t]:!m})),children:e.jsxs("div",{className:"flex items-center gap-2",children:[m?e.jsx(ts,{className:"h-4 w-4"}):e.jsx(ss,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:s("modelManagement.presets.title")}),e.jsx(V,{variant:"secondary",className:"text-xs",children:o.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:r,onChange:u=>Dt(t,u.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),disabled:d,className:"w-full md:w-48"}),e.jsx(D,{onClick:()=>void Pt(t),disabled:d,children:s(d?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n}),o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:s("modelManagement.presets.empty")}):e.jsx(os,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:o.map(u=>{const j=(b==null?void 0:b.endpoint)===t&&(b==null?void 0:b.name)===u.name,R=(k==null?void 0:k.endpoint)===t&&(k==null?void 0:k.name)===u.name,U=Object.entries(u.modelRoutes??{}),_=U.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(ns,{children:[e.jsx(ds,{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(V,{variant:"outline",className:"mt-1 text-xs",children:_>0?s("modelManagement.presets.rulesCount",{count:_}):s("modelManagement.presets.noRules")})]})}),_>0&&e.jsx(ls,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[U.slice(0,5).map(([$,J])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:$}),e.jsx(le,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:J})]},$)),_>5&&e.jsxs("div",{className:"text-muted-foreground",children:["…+",_-5]})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(D,{size:"sm",onClick:()=>Ue({endpoint:t,preset:u}),disabled:j||R,children:s(j?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(D,{variant:"destructive",size:"sm",onClick:()=>ge({kind:"preset",endpoint:t,preset:u}),disabled:R||j,children:s(R?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},u.name)})})})]})]})},Jt=t=>{var je;const o=G[t]||[],r=pe[t],n=a.find(T=>T.key===t),m=((je=n==null?void 0:n.protocols)==null?void 0:je.includes("anthropic"))??t==="anthropic"?js:ys,u=De===t,j=Ye[t]??!1,R=(n==null?void 0:n.label)??s(`modelManagement.tabs.${t}`),U=(n==null?void 0:n.isSystem)===!1?n.description:s(`settings.routing.descriptionByEndpoint.${t}`),_=`route-source-${t}`,$=ws(t,N),J=ks(t,p,N),ve=$&&(J==null?void 0:J.mode)==="claude-code",de=new Set(o.map(T=>T.source.trim()).filter(Boolean));return e.jsx(Le,{className:"surface-1",children:e.jsxs(Ae,{className:"pt-6 space-y-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("settings.routing.titleByEndpoint",{endpoint:R})}),e.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:U}),e.jsx("p",{className:"max-w-3xl text-xs text-muted-foreground",children:s("settings.routing.wildcardHint")})]}),$&&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(gt,{checked:ve,onCheckedChange:T=>void zt(t,T),disabled:wt}),e.jsx("span",{className:ie("text-xs font-medium",ve?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:s(ve?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}),Xt(t),r&&e.jsx("p",{className:"text-sm text-destructive",children:r}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(te,{children:s("modelManagement.routesEditorTitle")}),j&&e.jsx(V,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:s("modelManagement.actions.unsaved")})]}),o.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",{})]}),o.map(T=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3",children:[e.jsx(re,{value:T.source,onChange:se=>tt(t,T.id,"source",se.target.value),placeholder:s("settings.routing.sourcePlaceholder"),list:_,disabled:u}),e.jsx(le,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx(Cs,{value:T.target,onChange:se=>tt(t,T.id,"target",se),options:Et,disabled:u,placeholder:s("settings.routing.targetPlaceholder")}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>Ht(t,T.id),disabled:u,children:e.jsx(Se,{className:"h-4 w-4"})})]},T.id))]})]}),e.jsxs("div",{className:"rounded-[1.25rem] border border-border/70 bg-background/55 p-4 space-y-3",children:[e.jsx(te,{children:s("settings.routing.suggested")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(T=>{const se=de.has(T);return e.jsx(D,{variant:se?"ghost":"outline",size:"sm",onClick:()=>Vt(t,T),disabled:u||se,className:se?"opacity-50":"",children:T},`${t}-${T}`)})})]}),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(j?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(D,{variant:"outline",size:"sm",onClick:()=>Bt(t),disabled:u,children:s("settings.routing.add")}),e.jsx(D,{variant:"outline",size:"sm",onClick:()=>qt(t),disabled:u||!j,children:s("common.actions.reset")}),e.jsxs(D,{size:"sm",onClick:()=>void Qt(t),disabled:u,className:"relative",children:[s(u?"common.actions.saving":"modelManagement.actions.saveRoutes"),j&&e.jsx("span",{className:"absolute -top-1 -right-1 h-2 w-2 rounded-full bg-amber-500"})]})]})]}),e.jsx("datalist",{id:_,children:m.map(T=>e.jsx("option",{value:T},`${_}-${T}`))})]})})},Yt=(y==null?void 0:y.kind)==="provider"?s("providers.actions.delete"):(y==null?void 0:y.kind)==="preset"?s("modelManagement.presets.delete"):(y==null?void 0:y.kind)==="endpoint"?s("common.delete"):"",Zt=(y==null?void 0:y.kind)==="provider"?s("providers.confirm.delete",{name:y.provider.label||y.provider.id}):(y==null?void 0:y.kind)==="preset"?s("modelManagement.confirm.deletePreset",{name:y.preset.name}):(y==null?void 0:y.kind)==="endpoint"?s("modelManagement.deleteEndpointConfirm",{label:y.endpoint.label}):"",st=(y==null?void 0:y.kind)==="provider"?y.provider.label||y.provider.id:(y==null?void 0:y.kind)==="preset"?y.preset.name:(y==null?void 0:y.kind)==="endpoint"?y.endpoint.label:"";return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(cs,{icon:e.jsx(Wt,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),actions:e.jsxs(D,{onClick:()=>{ue(void 0),ae(!0)},children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"}),s("modelManagement.addEndpoint")]})}),e.jsx("div",{className:"flex gap-3 overflow-x-auto pb-2",children:a.map(t=>{const o=c===t.key,r=t.key!=="providers"&&Ye[t.key];return e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>M(t.key),className:ie("flex min-w-[150px] flex-col gap-1 rounded-[1.15rem] border px-4 py-3 text-left transition-all sm:min-w-[190px]",o?"border-primary/30 bg-primary/8 text-primary shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]":"border-white/50 bg-card/84 hover:bg-primary/5"),children:[e.jsxs("span",{className:"font-medium flex items-center gap-2",children:[t.label,r&&e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"line-clamp-2 text-xs text-muted-foreground",children:t.description})]}),t.canDelete&&e.jsx("button",{onClick:n=>{n.stopPropagation();const d=N.find(m=>m.id===t.key);d&&ge({kind:"endpoint",endpoint:d})},className:"absolute -top-2 -right-2 flex h-5 w-5 items-center justify-center rounded-full bg-destructive text-destructive-foreground text-xs hover:bg-destructive/90",title:s("common.delete"),children:e.jsx(Se,{className:"h-3 w-3"})})]},t.key)})}),c==="providers"?Gt():Jt(c),e.jsx(vs,{open:F,mode:E,provider:E==="edit"?v:void 0,existingProviderIds:B.map(t=>t.id).filter(t=>E==="edit"&&v?t!==v.id:!0),onClose:()=>{L(!1),C(void 0),w("create")},onSubmit:It}),e.jsx(Rs,{open:Ne,endpoint:me,onClose:()=>{ae(!1),ue(void 0)},onSuccess:()=>{f.invalidateQueries({queryKey:["custom-endpoints"]})}}),e.jsx(Ms,{open:X,provider:q,options:be,preservedExtras:ze,usePreset:Q,onPresetChange:Te,onConfirm:$t,onClose:et}),e.jsx(Es,{dialog:Oe,currentRoutes:Oe?G[Oe.endpoint]||[]:[],onConfirm:(t,o)=>{Ue(null),_t(t,o)},onClose:()=>Ue(null)}),e.jsx(ms,{open:!!y,onOpenChange:t=>{!t&&!Ie&&ge(null)},title:Yt,description:Zt,confirmLabel:s(Ie?"common.actions.loading":"common.delete"),cancelLabel:s("common.actions.cancel"),loading:Ie,onConfirm:Kt,children:st?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:st}):null})]})}function Ms({open:s,provider:l,options:f,usePreset:g,preservedExtras:x,onPresetChange:N,onConfirm:a,onClose:c}){const{t:M}=ce();return l?e.jsx(ct,{open:s,onOpenChange:p=>!p&&c(),children:e.jsxs(mt,{children:[e.jsxs(ut,{children:[e.jsx(pt,{children:M("providers.testDialog.title")}),e.jsx(xt,{children:M("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:M("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:g,onChange:p=>N(p.target.checked)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(te,{children:M("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:M("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:M("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:f.map(p=>e.jsxs("code",{className:"block rounded-xl border border-border/70 bg-background/85 px-2 py-1 text-xs",children:[p.key,": ",p.value]},p.key))})]})]})]}),Object.keys(x).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:M("providers.testDialog.preservedInfo")}),Object.entries(x).map(([p,P])=>e.jsxs("code",{className:"block rounded-xl border border-border/70 bg-background/85 px-2 py-1",children:[p,": ",P]},p))]})]}),e.jsxs(ht,{children:[e.jsx(D,{variant:"outline",onClick:c,children:M("providers.testDialog.cancel")}),e.jsx(D,{onClick:()=>void a(),children:M("providers.testDialog.primary")})]})]})}):null}function Cs({value:s,onChange:l,options:f,disabled:g,placeholder:x}){const{t:N}=ce(),[a,c]=h.useState(!1),[M,p]=h.useState(""),P=h.useRef(null),F=h.useMemo(()=>{if(!M.trim())return f;const E=M.toLowerCase();return f.filter(w=>w.label.toLowerCase().includes(E)||w.value.toLowerCase().includes(E))},[f,M]),L=E=>{l(E),p(""),c(!1)};return e.jsxs(hs,{open:a,onOpenChange:E=>{c(E),E&&p("")},children:[e.jsx(gs,{asChild:!0,children:e.jsx(re,{ref:P,value:s,onChange:E=>{l(E.target.value),p(E.target.value),a||c(!0)},onFocus:()=>{p(""),c(!0)},onClick:()=>{a||c(!0)},placeholder:x,disabled:g,autoComplete:"off"})}),e.jsx(Nt,{className:"w-[var(--radix-popover-trigger-width)] max-h-60 overflow-y-auto p-1",align:"start",onOpenAutoFocus:E=>E.preventDefault(),children:F.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:N("common.noMatches")}):F.map(E=>e.jsx("button",{type:"button",className:ie("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",E.value===s.trim()&&"bg-accent"),onMouseDown:w=>{w.preventDefault(),L(E.value)},children:e.jsx("span",{className:"truncate",children:E.label})},E.value))})]})}function Es({dialog:s,currentRoutes:l,onConfirm:f,onClose:g}){const{t:x}=ce();if(!s)return null;const{endpoint:N,preset:a}=s,c=a.modelRoutes??{},M={};for(const w of l){const v=w.source.trim(),C=w.target.trim();v&&C&&(M[v]=C)}const p=new Set([...Object.keys(M),...Object.keys(c)]),P=[],F=[],L=[];for(const w of p){const v=w in M,C=w in c;C&&!v?P.push([w,c[w]]):v&&!C?F.push([w,M[w]]):v&&C&&M[w]!==c[w]&&L.push([w,M[w],c[w]])}const E=P.length>0||F.length>0||L.length>0;return e.jsx(ct,{open:!0,onOpenChange:w=>!w&&g(),children:e.jsxs(mt,{className:"max-w-lg",children:[e.jsxs(ut,{children:[e.jsx(pt,{children:x("modelManagement.presets.diffTitle")}),e.jsx(xt,{children:x("modelManagement.presets.diffDescription",{name:a.name})})]}),E?e.jsxs("div",{className:"max-h-72 overflow-y-auto space-y-2 text-sm",children:[P.map(([w,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(V,{variant:"outline",className:"text-xs border-emerald-300 dark:border-emerald-700",children:x("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:w}),e.jsx(le,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`add-${w}`)),F.map(([w,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(V,{variant:"outline",className:"text-xs border-red-300 dark:border-red-700",children:x("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:w}),e.jsx(le,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`rm-${w}`)),L.map(([w,v,C])=>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(V,{variant:"outline",className:"text-xs border-amber-300 dark:border-amber-700",children:x("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:w}),e.jsx(le,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:v}),e.jsx(le,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:C})]},`chg-${w}`))]}):e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:x("modelManagement.presets.diffEmpty")}),e.jsxs(ht,{children:[e.jsx(D,{variant:"outline",onClick:g,children:x("common.cancel")}),e.jsx(D,{onClick:()=>f(N,a),disabled:!E,children:x("modelManagement.presets.diffConfirm")})]})]})})}function lt(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function Ss({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:g}=l[s]||l.custom;return e.jsx(V,{variant:g,className:"text-xs",children:f})}function Rs({open:s,endpoint:l,onClose:f,onSuccess:g}){const{t:x}=ce(),{pushToast:N}=it(),[a,c]=h.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});h.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"}],c({id:l.id,label:l.label,paths:v,enabled:l.enabled!==!1})}else c({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[l,s]);const M=rt({mutationFn:ye.create,onSuccess:()=>{N({title:x("modelManagement.createEndpointSuccess"),variant:"success"}),g(),f()},onError:v=>{const C=Re(v);N({title:x("modelManagement.createEndpointError",{error:C.message}),variant:"error"})}}),p=rt({mutationFn:v=>ye.update(v.id,v.updates),onSuccess:()=>{N({title:x("modelManagement.updateEndpointSuccess"),variant:"success"}),g(),f()},onError:v=>{const C=Re(v);N({title:x("modelManagement.updateEndpointError",{error:C.message}),variant:"error"})}}),P=()=>{c({...a,paths:[...a.paths,{path:"",protocol:"anthropic"}]})},F=v=>{if(a.paths.length===1){N({title:x("modelManagement.atLeastOnePath"),variant:"error"});return}const C=a.paths.filter((I,K)=>K!==v);c({...a,paths:C})},L=(v,C,I)=>{const K=[...a.paths];K[v]={...K[v],[C]:I},c({...a,paths:K})},E=v=>{if(v.preventDefault(),!a.id.trim()||!a.label.trim()){N({title:x("modelManagement.endpointValidationError"),variant:"error"});return}for(const I of a.paths)if(!I.path.trim()){N({title:x("modelManagement.pathValidationError"),variant:"error"});return}const C=a.paths.map(I=>({path:I.path.trim(),protocol:I.protocol}));l?p.mutate({id:l.id,updates:{label:a.label.trim(),paths:C,enabled:a.enabled}}):M.mutate({id:a.id.trim(),label:a.label.trim(),paths:C,enabled:a.enabled})},w=M.isPending||p.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:x(l?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx(D,{variant:"ghost",size:"sm",onClick:f,children:e.jsx(Se,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:E,className:"flex-1 overflow-y-auto p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(te,{children:[x("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{value:a.id,onChange:v=>c({...a,id:v.target.value}),placeholder:x("modelManagement.endpointIdPlaceholder"),disabled:!!l,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(te,{children:[x("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{value:a.label,onChange:v=>c({...a,label:v.target.value}),placeholder:x("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(te,{children:[x("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(D,{type:"button",variant:"ghost",size:"sm",onClick:P,children:[e.jsx(Fe,{className:"mr-1 h-3 w-3"}),x("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:a.paths.map((v,C)=>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:I=>L(C,"path",I.target.value),placeholder:x("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(ft,{value:v.protocol,onValueChange:I=>L(C,"protocol",I),children:[e.jsx(bt,{children:e.jsx(vt,{})}),e.jsxs(jt,{children:[e.jsx(Z,{value:"anthropic",children:x("modelManagement.protocolAnthropic")}),e.jsx(Z,{value:"openai-auto",children:x("modelManagement.protocolOpenAI")})]})]})]}),a.paths.length>1&&e.jsx(D,{type:"button",variant:"ghost",size:"sm",onClick:()=>F(C),className:"text-destructive",children:e.jsx(Se,{className:"h-4 w-4"})})]}),C===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:x("modelManagement.endpointPathHint")})]},C))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(gt,{id:"enabled",checked:a.enabled,onCheckedChange:v=>c({...a,enabled:v})}),e.jsx(te,{htmlFor:"enabled",children:x("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:x("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border/70 bg-background/70 p-6",children:[e.jsx(D,{variant:"outline",className:"flex-1",onClick:f,disabled:w,children:x("common.cancel")}),e.jsx(D,{className:"flex-1",onClick:E,disabled:w,children:x(w?"common.saving":l?"common.save":"common.create")})]})]})})]}):null}export{Vs as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as r,L as i}from"./vendor-UrUELLAG.js";import{c as n}from"./index-BKEgpvTe.js";const b=i("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 l({className:e,variant:d,...a}){return r.jsx("div",{className:n(b({variant:d}),e),...a})}function m({icon:e,title:d,description:a,badge:t,actions:o,className:s}){return r.jsxs("div",{className:n("flex flex-col gap-4 rounded-[1.6rem] border border-white/50 bg-background/60 p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)] backdrop-blur sm:flex-row sm:items-start sm:justify-between",s),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:"space-y-1",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[r.jsx("h1",{className:"text-2xl font-semibold tracking-[-0.02em]",children:d}),t&&r.jsx(l,{variant:"secondary",children:t})]}),a&&r.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:a})]})]}),o&&r.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:o})]})}export{l as B,m as P};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as s}from"./vendor-UrUELLAG.js";import{c as m}from"./index-BKEgpvTe.js";import{C as l,b as n,c as x,d as f,a as i}from"./card-DRsnBFyp.js";function j({title:a,description:e,actions:r,className:t,contentClassName:c,children:o}){const d=a||e||r;return s.jsxs(l,{className:m("surface-1 overflow-hidden",t),children:[d&&s.jsxs(n,{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:[s.jsxs("div",{className:"space-y-1.5",children:[typeof a=="string"?s.jsx(x,{className:"text-base font-semibold",children:a}):a,e&&(typeof e=="string"?s.jsx(f,{children:e}):s.jsx("div",{className:"text-sm text-muted-foreground",children:e}))]}),r&&s.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:r})]}),s.jsx(i,{className:m(!d&&"pt-6",d&&"pt-5",c),children:o})]})}export{j as P};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as o,f as e,a1 as et,ap as Y,an as tt,ak as st}from"./vendor-UrUELLAG.js";import{u as He}from"./useApiQuery-C4-HjWYY.js";import{u as at,B as j,h as Me,c as rt,a as J}from"./index-BKEgpvTe.js";import{P as nt,B as D}from"./PageHeader-CbpaEUEn.js";import{C as qe}from"./ConfirmDialog-DwZk3ejq.js";import{c as ot}from"./clipboard-CALi6bTW.js";import{I as b}from"./input-BCUUQfiv.js";import{L as c}from"./label-CtuP7N6a.js";import{C as w,a as C}from"./card-DRsnBFyp.js";import{S as N}from"./switch-D72iMnTO.js";import{S as it,a as lt,b as dt,c as ct,d as mt}from"./select-C-e-41FP.js";import{u as pt}from"./i18n-qAxAISVU.js";import"./query-BnTlXVsy.js";import"./router-Ju3lwB-M.js";import"./radix-CwKvZelb.js";const ht=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}],Oe=[{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 Z(t){var V,k,_,y,x,f,n,H,S,B,r;const m=t.storePayloads,K=i=>typeof i=="boolean"?i:typeof m=="boolean"?m:!0;return{port:String(t.port??((V=t.http)==null?void 0:V.port)??""),host:t.host??((k=t.http)==null?void 0:k.host)??"127.0.0.1",logRetentionDays:String(t.logRetentionDays??30),logExportTimeoutSeconds:String(t.logExportTimeoutSeconds??60),storeRequestPayloads:K(t.storeRequestPayloads),storeResponsePayloads:K(t.storeResponsePayloads),logLevel:t.logLevel??"info",requestLogging:t.requestLogging!==!1,responseLogging:t.responseLogging??t.requestLogging!==!1,bodyLimitMb:(()=>{const i=t.bodyLimit;return typeof i=="number"&&Number.isFinite(i)&&i>0?String(Math.max(1,Math.round(i/(1024*1024)))):"10"})(),enableRoutingFallback:t.enableRoutingFallback===!0,httpEnabled:((_=t.http)==null?void 0:_.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:((H=t.https)==null?void 0:H.host)??t.host??"127.0.0.1",httpsKeyPath:((S=t.https)==null?void 0:S.keyPath)??"",httpsCertPath:((B=t.https)==null?void 0:B.certPath)??"",httpsCaPath:((r=t.https)==null?void 0:r.caPath)??""}}function ee(t){return{enabled:t.enabled,username:t.username??"",password:"",confirmPassword:""}}function Et(){const{t}=pt(),{pushToast:m}=at(),[K,V]=o.useState(Oe[0].id),k=o.useRef(new Map),_=o.useCallback(s=>{const a=k.current.get(s);a&&a.scrollIntoView({behavior:"smooth",block:"start"})},[]),y=o.useCallback(s=>a=>{a?k.current.set(s,a):k.current.delete(s)},[]),x=He(["config","info"],{url:"/api/config/info",method:"GET"}),f=He(["auth","web"],{url:"/api/auth/web",method:"GET"}),[n,H]=o.useState(null),[S,B]=o.useState(""),[r,i]=o.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,te]=o.useState({}),[L,se]=o.useState(!1),[M,ae]=o.useState(!1),[q,re]=o.useState(!1),[De,z]=o.useState(!1),[Ke,Q]=o.useState(!1),[d,ne]=o.useState(null),[l,P]=o.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[E,I]=o.useState({}),[R,oe]=o.useState(!1),Ve=o.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=o.useMemo(()=>l.enabled?d!=null&&d.hasPassword?l.username.trim()!==((d==null?void 0:d.username)??""):!0:!1,[l.enabled,l.username,d]),W=o.useMemo(()=>n?Z(n):null,[n]),T=o.useMemo(()=>W?JSON.stringify(r)!==JSON.stringify(W):!1,[r,W]),$=o.useMemo(()=>d?ee(d):null,[d]),F=o.useMemo(()=>$?JSON.stringify(l)!==JSON.stringify($):!1,[l,$]);o.useEffect(()=>{x.data&&(H(x.data.config),B(x.data.path),i(Z(x.data.config)))},[x.data]),o.useEffect(()=>{f.data&&(ne(f.data),P(ee(f.data)),I({}))},[f.data]),o.useEffect(()=>{x.isError&&x.error&&m({title:t("settings.toast.loadFailure",{message:x.error.message}),variant:"error"})},[x.isError,x.error,m,t]),o.useEffect(()=>{f.isError&&f.error&&m({title:t("settings.toast.authLoadFailure",{message:f.error.message}),variant:"error"})},[f.isError,f.error,m,t]);const O=s=>a=>{i(h=>({...h,[s]:a}))},_e=()=>{const s={};if(!r.httpEnabled&&!r.httpsEnabled&&(s.protocol="至少需要启用 HTTP 或 HTTPS 协议"),r.httpEnabled){const v=Number(r.httpPort);(!Number.isFinite(v)||v<1||v>65535)&&(s.httpPort="HTTP 端口必须在 1-65535 之间")}if(r.httpsEnabled){const v=Number(r.httpsPort);(!Number.isFinite(v)||v<1||v>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 h=Number(r.logRetentionDays);(!Number.isFinite(h)||h<1||h>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 A=Number(r.bodyLimitMb);return(!Number.isFinite(A)||A<1||A>2048)&&(s.bodyLimitMb=t("settings.validation.bodyLimit")),te(s),Object.keys(s).length===0},Be=()=>{const s={},a=l.username.trim(),h=d?a!==(d.username??""):!0,g=l.enabled&&(!(d!=null&&d.hasPassword)||h);return l.enabled&&!a&&(s.username=t("settings.auth.validation.username")),l.password&&l.password.length<6&&(s.password=t("settings.auth.validation.minLength")),g&&!l.password&&(s.password=t("settings.auth.validation.passwordRequired")),(l.password||l.confirmPassword)&&l.password!==l.confirmPassword&&(s.confirmPassword=t("settings.auth.validation.confirmMismatch")),I(s),Object.keys(s).length===0},le=async()=>{var s,a,h,g,A,v,pe,he,ue,xe,ge,be,fe,je,ve,ye,Ne,ke,Pe,we,Ce,Se,Le,Ee,Re,Te;if(!n){m({title:t("settings.toast.loadFailure",{message:t("settings.toast.missingConfig")}),variant:"error"});return}if(_e()){se(!0);try{const G=Number(r.port),ze=Number(r.logRetentionDays),Qe=Number(r.logExportTimeoutSeconds),We=Number(r.bodyLimitMb),u={...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:G,host:r.host.trim()||void 0,logRetentionDays:ze,logExportTimeoutSeconds:Math.min(Math.max(Math.round(Qe),5),600),storeRequestPayloads:r.storeRequestPayloads,storeResponsePayloads:r.storeResponsePayloads,logLevel:r.logLevel,requestLogging:r.requestLogging,responseLogging:r.responseLogging,bodyLimit:Math.max(1,Math.floor(We*1024*1024)),enableRoutingFallback:r.enableRoutingFallback},Fe={...u};delete Fe.webAuth,await J.put("/api/config",Fe),H({...u,webAuth:n.webAuth});const Ae=X=>(X==null?void 0:X.trim())||void 0,$e=n.port??((s=n.http)==null?void 0:s.port)??4100,Ue=u.port??((a=u.http)==null?void 0:a.port)??4100,Xe=((h=n.host)==null?void 0:h.trim())||((A=(g=n.http)==null?void 0:g.host)==null?void 0:A.trim())||"127.0.0.1",Ye=((v=u.host)==null?void 0:v.trim())||((he=(pe=u.http)==null?void 0:pe.host)==null?void 0:he.trim())||"127.0.0.1",Ze=$e!==Ue||Xe!==Ye||((ue=n.http)==null?void 0:ue.enabled)!==((xe=u.http)==null?void 0:xe.enabled)||((ge=n.http)==null?void 0:ge.port)!==((be=u.http)==null?void 0:be.port)||(((fe=n.http)==null?void 0:fe.host)??n.host??"127.0.0.1")!==(((je=u.http)==null?void 0:je.host)??u.host??"127.0.0.1")||((ve=n.https)==null?void 0:ve.enabled)!==((ye=u.https)==null?void 0:ye.enabled)||((Ne=n.https)==null?void 0:Ne.port)!==((ke=u.https)==null?void 0:ke.port)||(((Pe=n.https)==null?void 0:Pe.host)??n.host??"127.0.0.1")!==(((we=u.https)==null?void 0:we.host)??u.host??"127.0.0.1")||((Ce=n.https)==null?void 0:Ce.keyPath)!==((Se=u.https)==null?void 0:Se.keyPath)||((Le=n.https)==null?void 0:Le.certPath)!==((Ee=u.https)==null?void 0:Ee.certPath)||Ae((Re=n.https)==null?void 0:Re.caPath)!==Ae((Te=u.https)==null?void 0:Te.caPath);m(Ze?{title:t("settings.toast.protocolRestartRequired"),variant:"success"}:{title:t("settings.toast.saveSuccess"),variant:"success"}),x.refetch()}catch(G){m({title:t("settings.toast.saveFailure",{message:G instanceof Error?G.message:"unknown"}),variant:"error"})}finally{se(!1)}}},de=()=>{n&&(i(Z(n)),te({}))},ce=async()=>{var s;if(Be()){oe(!0);try{const a={enabled:l.enabled,username:l.username.trim()||void 0};l.password&&(a.password=l.password);const g=(s=(await J.post("/api/auth/web",a)).data)==null?void 0:s.auth;g&&(ne(g),P({enabled:g.enabled,username:g.username??"",password:"",confirmPassword:""}),I({})),m({title:t("settings.auth.toast.success"),variant:"success"}),f.refetch()}catch(a){const h=a instanceof Error?a.message:"unknown";m({title:t("settings.auth.toast.failure",{message:h}),variant:"error"})}finally{oe(!1)}}},me=()=>{d&&(P(ee(d)),I({}))},Ie=async()=>{if(!S){m({title:t("settings.toast.copyFailure",{message:t("settings.file.unknown")}),variant:"error"});return}try{await ot(S),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"})}},Ge=async()=>{ae(!0);try{const a=(await J.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{ae(!1)}},Je=async()=>{re(!0);try{const s=await J.post("/api/logs/clear"),{deleted:a,metricsCleared:h}=s.data;m({title:t("settings.toast.clearAllSuccess",{logs:a,metrics:h}),variant:"success"})}catch(s){m({title:t("settings.toast.clearAllFailure",{message:s instanceof Error?s.message:"unknown"}),variant:"error"})}finally{re(!1)}},U=x.isPending||!n&&x.isFetching;return o.useEffect(()=>{if(U)return;const s=Array.from(k.current.values());if(s.length===0)return;const a=new IntersectionObserver(h=>{for(const g of h)if(g.isIntersecting){V(g.target.id);break}},{rootMargin:"-80px 0px -60% 0px",threshold:0});for(const h of s)a.observe(h);return()=>a.disconnect()},[U]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(nt,{icon:e.jsx(et,{className:"h-5 w-5","aria-hidden":"true"}),title:t("settings.title"),description:t("settings.description"),badge:T||F?t("modelManagement.actions.unsaved"):void 0,actions:n?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{variant:"outline",onClick:de,disabled:L||!T,children:t("common.actions.reset")}),e.jsx(j,{onClick:()=>void le(),disabled:L||!T,children:t(L?"common.actions.saving":"common.actions.save")})]}):null}),U?e.jsx(w,{children:e.jsx(C,{className:"flex min-h-[220px] items-center justify-center",children:e.jsx(Me,{})})}):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")}),Oe.map(s=>e.jsx("button",{type:"button",onClick:()=>_(s.id),className:rt("block w-full rounded-2xl px-3.5 py-2.5 text-left text-sm transition-all",K===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(w,{id:"section-basics",ref:y("section-basics"),children:e.jsxs(C,{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=>O("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=>O("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=>O("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=>O("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=>O("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(it,{value:r.logLevel,onValueChange:s=>i(a=>({...a,logLevel:s})),children:[e.jsx(lt,{children:e.jsx(dt,{})}),e.jsx(ct,{children:ht.map(s=>e.jsx(mt,{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(N,{checked:r.storeRequestPayloads,onCheckedChange:s=>i(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(N,{checked:r.storeResponsePayloads,onCheckedChange:s=>i(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(N,{checked:r.requestLogging,onCheckedChange:s=>i(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(N,{checked:r.responseLogging,onCheckedChange:s=>i(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(N,{checked:r.enableRoutingFallback,onCheckedChange:s=>i(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:Ve??t("settings.defaults.none")})]})]})]})}),e.jsx(w,{id:"section-protocol",ref:y("section-protocol"),children:e.jsxs(C,{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(N,{checked:r.httpEnabled,onCheckedChange:s=>i(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=>i(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=>i(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(tt,{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(N,{checked:r.httpsEnabled,onCheckedChange:s=>i(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=>i(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=>i(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=>i(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=>i(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=>i(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(w,{id:"section-security",ref:y("section-security"),children:e.jsxs(C,{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&&!d?e.jsx("div",{className:"flex min-h-[120px] items-center justify-center",children:e.jsx(Me,{})}):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(N,{checked:l.enabled,onCheckedChange:s=>P(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:l.username,onChange:s=>P(a=>({...a,username:s.target.value})),placeholder:t("settings.auth.usernamePlaceholder")}),E.username&&e.jsx("p",{className:"text-xs text-destructive",children:E.username})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c,{children:t("settings.auth.password")}),e.jsx(b,{type:"password",value:l.password,disabled:!l.enabled,onChange:s=>P(a=>({...a,password:s.target.value})),placeholder:t("settings.auth.passwordPlaceholder")}),E.password?e.jsx("p",{className:"text-xs text-destructive",children:E.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:t(ie?"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:l.confirmPassword,disabled:!l.enabled,onChange:s=>P(a=>({...a,confirmPassword:s.target.value})),placeholder:t("settings.auth.confirmPasswordPlaceholder")}),E.confirmPassword&&e.jsx("p",{className:"text-xs text-destructive",children:E.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:d!=null&&d.enabled?t("settings.auth.statusEnabled"):t("settings.auth.statusDisabled")}),(d==null?void 0:d.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"),": ",d.username]})]}),e.jsx("div",{className:"rounded-[1.2rem] border border-border/70 bg-background/55 p-4 text-xs text-muted-foreground",children:t(ie?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-3",children:[e.jsx(j,{onClick:()=>void ce(),disabled:R||!F,children:t(R?"common.actions.saving":"settings.auth.actions.save")}),e.jsx(j,{variant:"outline",onClick:me,disabled:R||!F,children:t("common.actions.reset")})]})]})]})}),e.jsx(w,{id:"section-config-file",ref:y("section-config-file"),children:e.jsxs(C,{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(j,{variant:"outline",size:"sm",onClick:()=>void Ie(),children:[e.jsx(st,{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:S||t("settings.file.unknown")})]})}),e.jsx(w,{id:"section-cleanup",ref:y("section-cleanup"),children:e.jsxs(C,{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(D,{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(j,{variant:"outline",onClick:()=>z(!0),disabled:M,className:"border-amber-500/40 text-amber-700 hover:bg-amber-500/10 dark:text-amber-300",children:t(M?"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(D,{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(j,{variant:"destructive",onClick:()=>Q(!0),disabled:q,children:t(q?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]})})]})]})})]}),(T||F)&&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(D,{variant:"secondary",children:t("modelManagement.actions.unsaved")}),T&&e.jsx(D,{variant:"outline",children:t("settings.sections.basics")}),F&&e.jsx(D,{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:[F&&e.jsxs(e.Fragment,{children:[e.jsx(j,{variant:"outline",onClick:me,disabled:R,children:t("common.actions.reset")}),e.jsx(j,{onClick:()=>void ce(),disabled:R,children:t(R?"common.actions.saving":"settings.auth.actions.save")})]}),T&&e.jsxs(e.Fragment,{children:[e.jsx(j,{variant:"outline",onClick:de,disabled:L,children:t("common.actions.reset")}),e.jsx(j,{onClick:()=>void le(),disabled:L,children:t(L?"common.actions.saving":"common.actions.save")})]})]})]})]}):e.jsx(w,{children:e.jsx(C,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:t("settings.toast.missingConfig")})})}),e.jsx(qe,{open:De,onOpenChange:s=>{!s&&!M&&z(!1)},title:t("settings.cleanup.softTitle"),description:t("settings.cleanup.confirmCleanup"),confirmLabel:t(M?"common.actions.loading":"common.actions.cleanup"),cancelLabel:t("common.actions.cancel"),loading:M,confirmVariant:"default",onConfirm:async()=>{await Ge(),z(!1)}}),e.jsx(qe,{open:Ke,onOpenChange:s=>{!s&&!q&&Q(!1)},title:t("settings.cleanup.clearAll"),description:t("settings.cleanup.confirmClearAll"),confirmLabel:t(q?"common.actions.loading":"settings.cleanup.clearAll"),cancelLabel:t("common.actions.cancel"),loading:q,onConfirm:async()=>{await Je(),Q(!1)}})]})}export{Et as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as e}from"./vendor-UrUELLAG.js";import{c as n}from"./index-BKEgpvTe.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-UrUELLAG.js";import{c as d}from"./index-BKEgpvTe.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};
|