@chenpu17/cc-gw 0.7.5 → 0.7.11
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/package.json +1 -1
- package/src/server/dist/index.js +160 -60
- package/src/web/dist/assets/About-DCvCA-EN.js +6 -0
- package/src/web/dist/assets/ApiKeys-chBAE4F4.js +16 -0
- package/src/web/dist/assets/Dashboard-B4kvSkr7.js +16 -0
- package/src/web/dist/assets/{Events-DjHvrNLA.js → Events-D9F6cmSK.js} +1 -1
- package/src/web/dist/assets/{Help-B4aI51F7.js → Help-WBFjl1uQ.js} +6 -6
- package/src/web/dist/assets/{Login-D2mlt6E4.js → Login-C2ITDdIa.js} +1 -1
- package/src/web/dist/assets/Logs-Cb_N4UAX.js +6 -0
- package/src/web/dist/assets/{ModelManagement-BBL4JPx_.js → ModelManagement-IWXiEI0s.js} +1 -1
- package/src/web/dist/assets/{PageHeader-CArgoeOl.js → PageHeader-xFKpGYn6.js} +1 -1
- package/src/web/dist/assets/{PageSection-B9KNzbSh.js → PageSection-Vn4S3q9j.js} +1 -1
- package/src/web/dist/assets/Settings-DJ0_2N3_.js +11 -0
- package/src/web/dist/assets/{card-Hot3HWFO.js → card-C20_HqC6.js} +1 -1
- package/src/web/dist/assets/clipboard-CALi6bTW.js +1 -0
- package/src/web/dist/assets/{copy-DXxd_I6B.js → copy-CUEQDKMx.js} +1 -1
- package/src/web/dist/assets/{dialog-DOFVjgLV.js → dialog-Cx1HX_hR.js} +1 -1
- package/src/web/dist/assets/{index-DgZMz9ou.js → index-DgjUxG8I.js} +1 -1
- package/src/web/dist/assets/{index-DSWEYKFg.js → index-UV1Qa96f.js} +2 -2
- package/src/web/dist/assets/{info-C3Uvuy3w.js → info-CewFzdVp.js} +1 -1
- package/src/web/dist/assets/{input-CSRYqyMm.js → input-CBGvcnZr.js} +1 -1
- package/src/web/dist/assets/{label-sxZdAo5j.js → label-BqSverDm.js} +1 -1
- package/src/web/dist/assets/{refresh-cw-Cm_OQO9a.js → refresh-cw-ISOSG1Po.js} +1 -1
- package/src/web/dist/assets/{select-qZIYkE-k.js → select-C8rWWJbl.js} +1 -1
- package/src/web/dist/assets/{switch-DDvmmBlT.js → switch-ODrypdNp.js} +1 -1
- package/src/web/dist/assets/{useApiQuery-CDChhTqt.js → useApiQuery-C2OD7H7U.js} +1 -1
- package/src/web/dist/index.html +1 -1
- package/src/web/dist/assets/About-BH1K5IKD.js +0 -6
- package/src/web/dist/assets/ApiKeys-B5xWItFi.js +0 -16
- package/src/web/dist/assets/Dashboard-3H13REtP.js +0 -16
- package/src/web/dist/assets/Logs-mTxHOg7D.js +0 -6
- package/src/web/dist/assets/Settings-CzKp7gwN.js +0 -11
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{c as be,u as U,b as me,r as n,d as we,t as ke,j as e,e as k,a as L,F as _e,f as Se,X as Ee,L as Te}from"./index-UV1Qa96f.js";import{u as F}from"./useApiQuery-C2OD7H7U.js";import{P as Ce,B as xe}from"./PageHeader-xFKpGYn6.js";import{c as Le}from"./clipboard-CALi6bTW.js";import{I as Q}from"./input-CBGvcnZr.js";import{L as S}from"./label-BqSverDm.js";import{C as re,a as ne}from"./card-C20_HqC6.js";import{S as M,a as z,b as O,c as q,d as w}from"./select-C8rWWJbl.js";import{R as De}from"./refresh-cw-ISOSG1Po.js";/**
|
|
2
|
+
* @license lucide-react v0.344.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Re=be("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]),oe=[20,50,100];function de(s,r=!1){if(!s)return;const o=r?`${s}T23:59:59.999`:`${s}T00:00:00.000`,g=Date.parse(o);return Number.isFinite(g)?g:void 0}function ue(s){const r=new Date(s);return`${r.getFullYear()}-${`${r.getMonth()+1}`.padStart(2,"0")}-${`${r.getDate()}`.padStart(2,"0")} ${`${r.getHours()}`.padStart(2,"0")}:${`${r.getMinutes()}`.padStart(2,"0")}:${`${r.getSeconds()}`.padStart(2,"0")}`}function _(s){return s==null?"-":s.toLocaleString()}function E(s,r){const o=_(s);return o==="-"?"-":`${o} ${r}`}function Fe(s){return s?"true":"false"}function ce(s,r){if(!s||s.trim().length===0)return r;try{const o=JSON.parse(s);return JSON.stringify(o,null,2)}catch{return s}}function Qe(){var se,te,le,ae;const{t:s}=U(),{pushToast:r}=me(),[o,g]=n.useState("all"),[j,t]=n.useState("all"),[d,y]=n.useState(""),[m,v]=n.useState("all"),[l,h]=n.useState(""),[i,x]=n.useState(""),[c,p]=n.useState(1),[N,I]=n.useState(oe[0]),[K,H]=n.useState(null),[pe,V]=n.useState(!1),[D,W]=n.useState([]),[P,J]=n.useState(!1);n.useEffect(()=>{p(1)},[o,j,d,m,l,i,N,D]);const $=n.useMemo(()=>{const a={limit:N,offset:(c-1)*N};o!=="all"&&(a.provider=o),j!=="all"&&(a.endpoint=j),d.trim().length>0&&(a.model=d.trim()),m!=="all"&&(a.status=m);const u=de(l),A=de(i,!0);return u!==void 0&&(a.from=u),A!==void 0&&(a.to=A),D.length>0&&(a.apiKeys=D.join(",")),a},[o,j,d,m,l,i,c,N,D]),f=F(["logs",$],{url:"/api/logs",method:"GET",params:$}),T=F(["providers","all"],{url:"/api/providers",method:"GET"}),X=F(["api-keys"],{url:"/api/keys",method:"GET"}),he=F(["custom-endpoints"],{url:"/api/custom-endpoints",method:"GET"});n.useEffect(()=>{f.isError&&f.error&&r({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:f.error.message}),variant:"error"})},[f.isError,f.error,r,s]),n.useEffect(()=>{T.isError&&T.error&&r({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:T.error.message}),variant:"error"})},[T.isError,T.error,r,s]);const C=((se=f.data)==null?void 0:se.total)??0,b=C>0?Math.ceil(C/N):0,Y=((te=f.data)==null?void 0:te.items)??[];n.useEffect(()=>{b>0&&c>b&&p(b)},[b,c]);const B=T.data??[],Z=n.useMemo(()=>{const a=new Map;for(const u of B)u.id&&a.set(u.id,u.label??u.id);return a},[B]),G=X.data??[],ee=n.useMemo(()=>{const a=new Map;for(const u of G)a.set(u.id,u);return a},[G]),fe=()=>{g("all"),y(""),t("all"),v("all"),h(""),x(""),W([])},ge=n.useCallback(async()=>{if(!P){J(!0);try{const a=C>0?Math.min(C,5e3):1e3,u={...$,limit:a,offset:0},A=await we.post("/api/logs/export",u,{responseType:"blob"}),Ne=new Blob([A.data],{type:"application/zip"}),ve=new Date().toISOString().replace(/[:.]/g,"-"),ie=URL.createObjectURL(Ne),R=document.createElement("a");R.href=ie,R.download=`cc-gw-logs-${ve}.zip`,document.body.appendChild(R),R.click(),R.remove(),URL.revokeObjectURL(ie),r({title:s("logs.toast.exportSuccess.title"),description:s("logs.toast.exportSuccess.desc"),variant:"success"})}catch(a){const u=ke(a);r({title:s("logs.toast.exportError.title"),description:s("logs.toast.exportError.desc",{message:u.message}),variant:"error"})}finally{J(!1)}}},[P,r,$,s,C]),je=n.useCallback(a=>{H(a),V(!0)},[]),ye=n.useCallback(()=>{V(!1),H(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Ce,{icon:e.jsx(_e,{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(k,{onClick:ge,disabled:P,children:[e.jsx(Re,{className:"mr-2 h-4 w-4"}),s(P?"common.actions.loading":"logs.actions.export")]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.summary.total",{value:C.toLocaleString()})}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>f.refetch(),disabled:f.isFetching,children:[e.jsx(De,{className:L("mr-2 h-4 w-4",f.isFetching&&"animate-spin")}),f.isFetching?s("common.actions.refreshing"):s("logs.actions.manualRefresh")]})]})}),e.jsx(re,{children:e.jsxs(ne,{className:"pt-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:s("logs.filtersTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.filtersDescription")})]}),e.jsx(k,{variant:"ghost",size:"sm",onClick:fe,children:s("common.actions.reset")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.provider")}),e.jsxs(M,{value:o,onValueChange:g,children:[e.jsx(z,{children:e.jsx(O,{})}),e.jsxs(q,{children:[e.jsx(w,{value:"all",children:s("logs.filters.providerAll")}),B.map(a=>e.jsx(w,{value:a.id,children:a.label??a.id},a.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.endpoint")}),e.jsxs(M,{value:j,onValueChange:t,children:[e.jsx(z,{children:e.jsx(O,{})}),e.jsxs(q,{children:[e.jsx(w,{value:"all",children:s("logs.filters.endpointAll")}),e.jsx(w,{value:"anthropic",children:s("logs.filters.endpointAnthropic")}),e.jsx(w,{value:"openai",children:s("logs.filters.endpointOpenAI")}),(ae=(le=he.data)==null?void 0:le.endpoints)==null?void 0:ae.map(a=>e.jsx(w,{value:a.id,children:a.label||a.id},a.id))]})]})]}),e.jsx($e,{className:"md:col-span-2",apiKeys:G,selected:D,disabled:X.isLoading,onChange:W}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.modelId")}),e.jsx(Q,{value:d,onChange:a=>y(a.target.value),placeholder:s("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.status")}),e.jsxs(M,{value:m,onValueChange:a=>v(a),children:[e.jsx(z,{children:e.jsx(O,{})}),e.jsxs(q,{children:[e.jsx(w,{value:"all",children:s("logs.filters.statusAll")}),e.jsx(w,{value:"success",children:s("logs.filters.statusSuccess")}),e.jsx(w,{value:"error",children:s("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.startDate")}),e.jsx(Q,{type:"date",value:l,onChange:a=>h(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:s("logs.filters.endDate")}),e.jsx(Q,{type:"date",value:i,onChange:a=>x(a.target.value)})]})]})]})}),e.jsx(re,{children:e.jsxs(ne,{className:"p-0",children:[e.jsx("div",{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:"px-3 py-2 text-left text-xs font-medium",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:"px-3 py-2 text-center text-xs font-medium",children:s("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:f.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:16,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:s("logs.table.loading")})}):Y.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:16,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:s("logs.table.empty")})}):Y.map((a,u)=>e.jsx(Ke,{record:a,providerLabelMap:Z,apiKeyMap:ee,onSelect:je,isEven:u%2===0},a.id))})]})}),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(M,{value:N.toString(),onValueChange:a=>I(Number(a)),children:[e.jsx(z,{className:"w-[80px]",children:e.jsx(O,{})}),e.jsx(q,{children:oe.map(a=>e.jsx(w,{value:a.toString(),children:a},a))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:()=>p(a=>Math.max(a-1,1)),disabled:c<=1,children:s("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.pageLabel",{page:b===0?0:c,total:b})}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>p(a=>b===0?a:Math.min(a+1,b)),disabled:b===0||c>=b,children:s("logs.table.pagination.next")})]})]})]})}),e.jsx(Pe,{open:pe,logId:K,onClose:ye,providerLabelMap:Z,apiKeyMap:ee})]})}function Ke({record:s,providerLabelMap:r,apiKeyMap:o,onSelect:g,isEven:j}){const{t}=U(),d=r.get(s.provider)??s.provider,y=s.endpoint||"-",m=!!s.error,v=s.status_code,l=s.client_model??t("logs.table.requestedModelFallback"),h=s.api_key_id!=null?o.get(s.api_key_id):void 0,i=s.api_key_id==null?t("logs.table.apiKeyUnknown"):h!=null&&h.isWildcard?t("apiKeys.wildcard"):h!=null&&h.name?h.name:s.api_key_name?s.api_key_name:t("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:L("transition-colors",j?"bg-muted/30":"","hover:bg-muted/50"),children:[e.jsx("td",{className:"px-3 py-2 text-xs",children:ue(s.timestamp)}),e.jsx("td",{className:"px-3 py-2 text-xs",children:y}),e.jsx("td",{className:"px-3 py-2 text-xs",children:e.jsx("div",{className:"max-w-[100px] truncate",title:d,children:d})}),e.jsx("td",{className:"px-3 py-2 text-xs text-muted-foreground",children:e.jsx("div",{className:"max-w-[120px] truncate",title:l,children:l})}),e.jsx("td",{className:"px-3 py-2 text-xs",children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),e.jsx("td",{className:"px-3 py-2 text-xs text-muted-foreground",children:e.jsx("div",{className:"max-w-[90px] truncate",title:i,children:i})}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:_(s.input_tokens)}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:_(s.cache_read_tokens)}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:_(s.cache_creation_tokens)}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:_(s.output_tokens)}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:E(s.latency_ms,"ms")}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:E(s.ttft_ms,"ms")}),e.jsx("td",{className:"px-3 py-2 text-right text-xs tabular-nums",children:E(s.tpot_ms,"ms/tk")}),e.jsx("td",{className:"px-3 py-2 text-center",children:e.jsx(xe,{variant:m?"destructive":"default",className:"text-xs",children:v??(m?500:200)})}),e.jsx("td",{className:"px-3 py-2 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:"px-3 py-2 text-center",children:e.jsx(k,{variant:"outline",size:"sm",onClick:()=>g(s.id),children:t("logs.actions.detail")})})]})}function Pe({open:s,logId:r,onClose:o,providerLabelMap:g,apiKeyMap:j}){var x,c;const{t}=U(),{pushToast:d}=me(),y=n.useRef(null),m=F(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:s&&r!==null,staleTime:3e4});n.useEffect(()=>{m.isError&&m.error&&d({title:t("logs.detail.loadError"),description:m.error.message,variant:"error"})},[m.isError,m.error,d,t]),n.useEffect(()=>{if(!s)return;const p=N=>{N.key==="Escape"&&o()};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[s,o]),n.useEffect(()=>{s&&y.current&&y.current.focus()},[s,r]);const v=n.useCallback(async(p,N,I)=>{if(!N){d({title:t("logs.detail.copy.empty",{label:p}),variant:"info"});return}try{await Le(N),d({title:t(I),variant:"success"})}catch(K){d({title:t("logs.detail.copy.failure"),description:K instanceof Error?K.message:t("logs.detail.copy.failureFallback"),variant:"error"})}},[d,t]);if(!s)return null;const l=m.data,h=l?g.get(l.provider)??l.provider:"",i=l&&l.api_key_id!=null?j.get(l.api_key_id):void 0;return typeof document>"u"?null:Se.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm",onClick:o}),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",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:t("logs.detail.title")}),l&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.detail.id",{id:l.id})})]}),e.jsxs(k,{ref:y,variant:"outline",size:"sm",onClick:o,children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"}),t("common.actions.close")]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:m.isPending?e.jsx(Te,{}):l?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-md bg-muted p-3 text-xs",children:[e.jsx("span",{className:"font-medium",children:t("logs.detail.summary.route",{from:l.client_model??t("logs.detail.info.noRequestedModel"),to:l.model})}),e.jsx("span",{className:"text-muted-foreground",children:t("logs.detail.summary.latency",{value:E(l.latency_ms,t("common.units.ms"))})}),l.ttft_ms!==null&&e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",E(l.ttft_ms,t("common.units.ms"))]}),e.jsx(xe,{variant:l.error?"destructive":"default",children:(l.status_code??(l.error?500:200)).toString()})]}),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:t("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:ue(l.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:l.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:l.endpoint||"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:h})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:l.client_model??t("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:l.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:Fe(l.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.inputTokens")}),e.jsx("dd",{className:"font-medium",children:_(l.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.cacheReadTokens")}),e.jsx("dd",{className:"font-medium",children:_(l.cache_read_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.cacheCreationTokens")}),e.jsx("dd",{className:"font-medium",children:_(l.cache_creation_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:_(l.output_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.ttft")}),e.jsx("dd",{className:"font-medium",children:E(l.ttft_ms,t("common.units.ms"))})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.tpot")}),e.jsx("dd",{className:"font-medium",children:E(l.tpot_ms,t("common.units.msPerToken"))})]})]}),l.error&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.detail.info.error")}),e.jsx("p",{className:"rounded-md border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:l.error})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:t("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:t("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id==null&&!l.api_key_name?t("logs.detail.apiKey.missing"):i!=null&&i.isWildcard?t("apiKeys.wildcard"):(i==null?void 0:i.name)??l.api_key_name??t("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id??t("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:i!=null&&i.isWildcard?t("apiKeys.wildcard"):(i==null?void 0:i.maskedKey)??l.api_key_name??t("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:i!=null&&i.lastUsedAt?new Date(i.lastUsedAt).toLocaleString():t("common.noData")})]})]}),e.jsxs("div",{className:"rounded-md border bg-muted p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:t("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:l.api_key_value_available?l.api_key_value_masked??t("logs.detail.apiKey.rawUnavailable"):t("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:t("logs.detail.apiKey.rawMaskedHint")})]})]}),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:t("logs.detail.payload.request")}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>{var p;return v(t("logs.detail.payload.request"),(p=l.payload)==null?void 0:p.prompt,"logs.detail.copy.requestSuccess")},children:t("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border bg-muted p-3 text-xs",children:ce((x=l.payload)==null?void 0:x.prompt,t("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:t("logs.detail.payload.response")}),e.jsx(k,{variant:"outline",size:"sm",onClick:()=>{var p;return v(t("logs.detail.payload.response"),(p=l.payload)==null?void 0:p.response,"logs.detail.copy.responseSuccess")},children:t("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border bg-muted p-3 text-xs",children:ce((c=l.payload)==null?void 0:c.response,t("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify-center p-8 text-sm text-muted-foreground",children:t("logs.detail.loadError")})})]})]}),document.body)}function $e({apiKeys:s,selected:r,onChange:o,disabled:g,className:j}){const{t}=U(),[d,y]=n.useState(!1),m=n.useRef(null);n.useEffect(()=>{if(!d)return;const i=x=>{var c;(c=m.current)!=null&&c.contains(x.target)||y(!1)};return window.addEventListener("mousedown",i),()=>window.removeEventListener("mousedown",i)},[d]);const v=n.useMemo(()=>{if(r.length===0)return[];const i=new Map;for(const x of s)i.set(x.id,x);return r.map(x=>{const c=i.get(x);return c?c.isWildcard?t("apiKeys.wildcard"):c.name:null}).filter(x=>!!x)},[s,r,t]),l=r.length===0?t("logs.filters.apiKeyAll"):t("logs.filters.apiKeySelected",{count:r.length}),h=i=>{r.includes(i)?o(r.filter(x=>x!==i)):o([...r,i])};return e.jsxs("div",{className:L("relative space-y-2",j),ref:m,children:[e.jsx(S,{children:t("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>y(i=>!i),disabled:g||s.length===0,title:t("logs.filters.apiKeyHint"),className:L("flex h-10 w-full items-center justify-between rounded-md border bg-background px-3 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",r.length>0&&"border-primary",d&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[l,v.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:v.join(", ")})]}),e.jsx("svg",{className:L("h-4 w-4 opacity-50 transition-transform",d&&"rotate-180"),viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),d&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-1 w-64 rounded-md border bg-popover p-2 shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-muted px-3 py-2 text-xs",children:[e.jsx("span",{children:l}),e.jsx("button",{type:"button",onClick:()=>o([]),disabled:r.length===0,className:"text-primary hover:underline disabled:opacity-40",children:t("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(i=>{const x=i.isWildcard?t("apiKeys.wildcard"):i.name,c=r.includes(i.id);return e.jsxs("label",{className:L("flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm transition hover:bg-muted",c&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border",checked:c,onChange:()=>h(i.id)}),e.jsx("span",{className:"truncate",children:x})]},i.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:t("logs.filters.apiKeyAll")})]})]})]})}export{Qe as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var st=s=>{throw TypeError(s)};var Ae=(s,a,c)=>a.has(s)||st("Cannot "+c);var E=(s,a,c)=>(Ae(s,a,"read from private field"),c?c.call(s):a.get(s)),de=(s,a,c)=>a.has(s)?st("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(s):a.set(s,c),ce=(s,a,c,m)=>(Ae(s,a,"write to private field"),m?m.call(s,c):a.set(s,c),c),ue=(s,a,c)=>(Ae(s,a,"access private method"),c);import{S as $t,s as Ft,i as at,k as zt,n as it,l as dt,r as f,m as Bt,o as Vt,u as Pe,j as e,b as ct,e as P,p as _t,a as Le,X as Be,d as X,q as ve,t as Re}from"./index-DSWEYKFg.js";import{u as qt,a as Ht}from"./useApiQuery-CDChhTqt.js";import{P as Qt,B as me}from"./PageHeader-CArgoeOl.js";import{I as he}from"./input-CSRYqyMm.js";import{L as Z}from"./label-sxZdAo5j.js";import{C as Ke,a as $e}from"./card-Hot3HWFO.js";import{S as ut}from"./switch-DDvmmBlT.js";import{S as mt,a as ht,b as pt,c as xt,d as De}from"./select-qZIYkE-k.js";import{P as Ve,D as Gt,a as Xt,b as Yt,c as Jt,d as Wt,e as Zt}from"./dialog-DOFVjgLV.js";import{R as es}from"./refresh-cw-Cm_OQO9a.js";var J,le,K,W,ee,Se,_e,ot,ts=(ot=class extends $t{constructor(a,c){super();de(this,ee);de(this,J);de(this,le);de(this,K);de(this,W);ce(this,J,a),this.setOptions(c),this.bindMethods(),ue(this,ee,Se).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(a){var m;const c=this.options;this.options=E(this,J).defaultMutationOptions(a),Ft(this.options,c)||E(this,J).getMutationCache().notify({type:"observerOptionsUpdated",mutation:E(this,K),observer:this}),c!=null&&c.mutationKey&&this.options.mutationKey&&at(c.mutationKey)!==at(this.options.mutationKey)?this.reset():((m=E(this,K))==null?void 0:m.state.status)==="pending"&&E(this,K).setOptions(this.options)}onUnsubscribe(){var a;this.hasListeners()||(a=E(this,K))==null||a.removeObserver(this)}onMutationUpdate(a){ue(this,ee,Se).call(this),ue(this,ee,_e).call(this,a)}getCurrentResult(){return E(this,le)}reset(){var a;(a=E(this,K))==null||a.removeObserver(this),ce(this,K,void 0),ue(this,ee,Se).call(this),ue(this,ee,_e).call(this)}mutate(a,c){var m;return ce(this,W,c),(m=E(this,K))==null||m.removeObserver(this),ce(this,K,E(this,J).getMutationCache().build(E(this,J),this.options)),E(this,K).addObserver(this),E(this,K).execute(a)}},J=new WeakMap,le=new WeakMap,K=new WeakMap,W=new WeakMap,ee=new WeakSet,Se=function(){var c;const a=((c=E(this,K))==null?void 0:c.state)??zt();ce(this,le,{...a,isPending:a.status==="pending",isSuccess:a.status==="success",isError:a.status==="error",isIdle:a.status==="idle",mutate:this.mutate,reset:this.reset})},_e=function(a){it.batch(()=>{var c,m,g,y,o,h,N,p;if(E(this,W)&&this.hasListeners()){const R=E(this,le).variables,F=E(this,le).context,U={client:E(this,J),meta:this.options.meta,mutationKey:this.options.mutationKey};(a==null?void 0:a.type)==="success"?((m=(c=E(this,W)).onSuccess)==null||m.call(c,a.data,R,F,U),(y=(g=E(this,W)).onSettled)==null||y.call(g,a.data,null,R,F,U)):(a==null?void 0:a.type)==="error"&&((h=(o=E(this,W)).onError)==null||h.call(o,a.error,R,F,U),(p=(N=E(this,W)).onSettled)==null||p.call(N,void 0,a.error,R,F,U))}this.listeners.forEach(R=>{R(E(this,le))})})},ot);function rt(s,a){const c=dt(),[m]=f.useState(()=>new ts(c,s));f.useEffect(()=>{m.setOptions(s)},[m,s]);const g=f.useSyncExternalStore(f.useCallback(o=>m.subscribe(it.batchCalls(o)),[m]),()=>m.getCurrentResult(),()=>m.getCurrentResult()),y=f.useCallback((o,h)=>{m.mutate(o,h).catch(Bt)},[m]);if(g.error&&Vt(m.options.throwOnError,[g.error]))throw g.error;return{...g,mutate:y,mutateAsync:g.mutate}}function He(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ss(){return{_key:He(),id:"",label:""}}const Fe={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:{}};function lt(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(a=>({...a,_key:He()})),authMode:s.authMode==="authToken"?"authToken":"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function as(s){return{_key:He(),id:s.id,label:s.label}}function rs({open:s,mode:a,provider:c,existingProviderIds:m,onClose:g,onSubmit:y}){const{t:o}=Pe(),[h,N]=f.useState(()=>lt(c)),[p,R]=f.useState({}),[F,U]=f.useState(!1),[z,B]=f.useState(null),k=f.useRef(null),M=f.useRef(null),O=f.useRef(null),[I,je]=f.useState(a==="edit");f.useEffect(()=>{s&&(N(lt(c)),R({}),B(null),U(!1),je(a==="edit"))},[s,c,a]),f.useEffect(()=>{if(!s)return;const u=b=>{b.key==="Escape"&&g()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,g]),f.useEffect(()=>{if(s){if(a==="create"&&O.current){O.current.focus();return}M.current&&M.current.focus()}},[s,a]);const ye=f.useMemo(()=>h.models.filter(u=>u.id.trim().length>0),[h.models]),pe=u=>b=>{N(w=>({...w,[u]:b}))},ke=u=>{N(b=>{const v=!I||b.label.trim().length===0||b.label===b.id?u:b.label;return{...b,id:u,label:v}})},ne=u=>{N(b=>{var Me;const v=Fe[u??"custom"]??Fe.custom,C=Object.values(Fe).map(te=>te.baseUrl).filter(te=>!!te),H=!b.baseUrl||C.includes(b.baseUrl),L=a==="create"&&(b.models.length===0||b.models.every(te=>te.id.trim().length===0)),G={...b,type:u,authMode:u==="anthropic"?b.authMode??"apiKey":"apiKey"};return v!=null&&v.baseUrl&&H&&(G.baseUrl=v.baseUrl),v!=null&&v.models&&L&&(G.models=v.models.map(as),G.defaultModel=v.defaultModel??((Me=v.models[0])==null?void 0:Me.id)??""),G})},A=(u,b)=>{N(w=>{const v=[...w.models];return v[u]={...v[u],...b},{...w,models:v}})},Oe=(u,b)=>{N(w=>{const v=[...w.models],C=v[u];if(!C)return w;const H=!I||!C.label||C.label===C.id,L={...C,id:b,label:H?b:C.label};v[u]=L;const G=w.defaultModel===C.id?b:w.defaultModel;return{...w,models:v,defaultModel:G}})},V=u=>{N(b=>{if(u<0||u>=b.models.length)return b;const w=b.models.filter((C,H)=>H!==u);let v=b.defaultModel;return w.some(C=>C.id===v)||(v=""),{...b,models:w,defaultModel:v}})},Ue=()=>{N(u=>({...u,models:[...u.models,ss()]}))},xe=u=>{N(b=>({...b,authMode:u}))},Ne=()=>{const u={},b=h.id.trim(),w=h.baseUrl.trim();if(a==="create"&&(b.length===0?u.id=o("providers.drawer.errors.idRequired"):m.includes(b)&&(u.id=o("providers.drawer.errors.idDuplicate"))),a==="edit"&&b.length===0&&(u.id=o("providers.drawer.errors.idRequired")),w.length===0)u.baseUrl=o("providers.drawer.errors.baseUrlInvalid");else try{new URL(w)}catch{u.baseUrl=o("providers.drawer.errors.baseUrlInvalid")}if(h.models.length>0){const v=new Set;h.models.some(H=>{const L=H.id.trim();return L.length===0||v.has(L)?!0:(v.add(L),!1)})&&(u.models=o("providers.drawer.errors.modelInvalid"))}return h.defaultModel&&!h.models.some(v=>v.id===h.defaultModel)&&(u.models=o("providers.drawer.errors.defaultInvalid")),R(u),Object.keys(u).length===0},ge=()=>{const u=h.models.map(v=>{var C;return{id:v.id.trim(),label:(C=v.label)!=null&&C.trim()?v.label.trim():void 0}}).filter(v=>v.id.length>0),b=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,w=h.type==="anthropic"?h.authMode:void 0;return{id:h.id.trim(),label:h.label.trim()||h.id.trim(),baseUrl:h.baseUrl.trim(),apiKey:h.apiKey.trim()||void 0,type:h.type??"custom",defaultModel:h.defaultModel||void 0,models:u.length>0?u:void 0,extraHeaders:b,authMode:w}},we=async()=>{if(B(null),!!Ne()){U(!0);try{const u=ge();await y(u)}catch(u){B(o("providers.drawer.toast.saveFailure",{message:u instanceof Error?u.message:"unknown"})),U(!1);return}U(!1),g()}},fe=a==="create";return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:g,"aria-hidden":"true"}),e.jsxs("aside",{ref:k,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-3xl flex-col border-l border-slate-200 bg-white shadow-xl dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold",children:o(fe?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.description")})]}),e.jsx("button",{type:"button",ref:M,onClick:g,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:o("common.actions.close")})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-fields",children:[e.jsx("div",{id:"provider-basic-fields",className:"sr-only",children:o("providers.drawer.description")}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{type:"button",onClick:()=>je(u=>!u),className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:o(I?"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-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.id")}),e.jsx("input",{value:h.id,ref:O,onChange:u=>ke(u.target.value),disabled:!fe,placeholder:o("providers.drawer.fields.idPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60","aria-invalid":!!p.id}),p.id?e.jsx("span",{className:"text-xs text-red-500",children:p.id}):null]}),I?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.label")}),e.jsx("input",{value:h.label,onChange:u=>pe("label")(u.target.value),placeholder:o("providers.drawer.fields.labelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):null]}),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-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:h.baseUrl,onChange:u=>pe("baseUrl")(u.target.value),placeholder:o("providers.drawer.fields.baseUrlPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60","aria-invalid":!!p.baseUrl}),p.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:p.baseUrl}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.type")}),e.jsxs("select",{value:h.type??"custom",onChange:u=>ne(u.target.value),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60",children:[e.jsx("option",{value:"openai",children:"OpenAI"}),e.jsx("option",{value:"deepseek",children:"DeepSeek"}),e.jsx("option",{value:"huawei",children:"华为云"}),e.jsx("option",{value:"kimi",children:"Kimi"}),e.jsx("option",{value:"anthropic",children:"Anthropic (Claude)"}),e.jsx("option",{value:"custom",children:"Custom"})]})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.apiKey")}),e.jsx("input",{value:h.apiKey,onChange:u=>pe("apiKey")(u.target.value),placeholder:o("providers.drawer.fields.apiKeyPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}),h.type==="anthropic"?e.jsxs("fieldset",{className:"grid gap-2 rounded-lg border border-slate-200 p-3 text-xs dark:border-slate-700",children:[e.jsx("legend",{className:"px-1 text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 transition hover:bg-slate-100 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"radio",name:"anthropic-auth-mode",value:"apiKey",checked:h.authMode==="apiKey",onChange:()=>xe("apiKey")}),e.jsx("span",{children:o("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 transition hover:bg-slate-100 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"radio",name:"anthropic-auth-mode",value:"authToken",checked:h.authMode==="authToken",onChange:()=>xe("authToken")}),e.jsx("span",{children:o("providers.drawer.fields.authModeAuthToken")})]})]}):null]}),e.jsxs("section",{className:"mt-6 space-y-3","aria-labelledby":"provider-model-fields",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"provider-model-fields",className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:Ue,className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:o("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:[h.models.map((u,b)=>e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4 dark:border-slate-700 dark:bg-slate-800/40",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-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.modelId")}),e.jsx("input",{value:u.id,onChange:w=>Oe(b,w.target.value),placeholder:o("providers.drawer.fields.modelIdPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}),I?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:u.label??"",onChange:w=>A(b,{label:w.target.value}),placeholder:o("providers.drawer.fields.modelLabelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):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:u.id,checked:h.defaultModel===u.id,onChange:()=>N(w=>({...w,defaultModel:u.id})),disabled:u.id.trim().length===0}),o("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:()=>V(b),disabled:h.models.length===0,children:o("providers.drawer.fields.removeModel")})]})]},u._key)),h.models.length===0?e.jsx("div",{className:"rounded-xl border-2 border-amber-300 bg-gradient-to-br from-amber-50 to-yellow-50 p-5 shadow-md dark:border-amber-600/60 dark:from-amber-900/20 dark:to-yellow-900/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex-shrink-0 text-2xl",children:"💡"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:o("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:o("providers.drawer.noModelsHint",{providerId:h.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:o("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded bg-white px-2.5 py-1.5 font-mono text-xs text-amber-900 shadow-sm dark:bg-slate-900 dark:text-amber-100",children:['"claude-*": "',(h.id||"provider-id").trim()||"provider-id",':*"']})]})]})]})}):null]}),ye.length>1?e.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.defaultHint",{model:h.defaultModel||o("providers.card.noDefault")})}):null]})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-slate-200 px-6 py-4 text-sm dark:border-slate-800",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:z?e.jsx("span",{children:z}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:g,className:"rounded-md border border-slate-200 px-4 py-2 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",disabled:F,children:o("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:we,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:F,children:o(F?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const ls=["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"],ns=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function qe(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Y(s){return s?Object.entries(s).map(([a,c])=>({id:qe(),source:a,target:c})):[]}function ze(s,a){var g,y,o;if(!s)return{};const c={},m=s.endpointRouting??{};c.anthropic=Y(((g=m.anthropic)==null?void 0:g.modelRoutes)??s.modelRoutes??{}),c.openai=Y(((y=m.openai)==null?void 0:y.modelRoutes)??{});for(const h of a)(o=h.routing)!=null&&o.modelRoutes?c[h.id]=Y(h.routing.modelRoutes):c[h.id]=[];return c}function os(s,a){if(s==="anthropic")return!0;const c=a.find(m=>m.id===s);return c?c.paths&&c.paths.length>0?c.paths.some(m=>m.protocol==="anthropic"):c.protocol==="anthropic":!1}function is(s,a,c){var g,y,o;if(!a)return;if(s==="anthropic"||s==="openai")return(y=(g=a.endpointRouting)==null?void 0:g[s])==null?void 0:y.validation;const m=c.find(h=>h.id===s);return(o=m==null?void 0:m.routing)==null?void 0:o.validation}function ws(){const{t:s}=Pe(),{pushToast:a}=ct(),c=dt(),m=qt(["config","full"],{url:"/api/config",method:"GET"}),{data:g}=Ht({queryKey:["custom-endpoints"],queryFn:ve.list,refetchInterval:1e4}),y=(g==null?void 0:g.endpoints)??[],o=f.useMemo(()=>{const t=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],n=y.map(r=>{let l,i=[];if(r.paths&&r.paths.length>0){const d=r.paths.map(x=>`${x.path} (${x.protocol})`).join(", ");l=`${s("modelManagement.tabs.customEndpoint")}: ${d}`,i=[...new Set(r.paths.map(x=>x.protocol))]}else if(r.path){const d=r.protocol||"anthropic";l=`${s("modelManagement.tabs.customEndpoint")}: ${r.path} (${d})`,i=[d]}else l=s("modelManagement.tabs.customEndpoint");return{key:r.id,label:r.label,description:l,isSystem:!1,canDelete:!0,protocols:i}});return[...t,...n]},[s,y]),[h,N]=f.useState("providers"),[p,R]=f.useState(null),[F,U]=f.useState(!1),[z,B]=f.useState("create"),[k,M]=f.useState(void 0),[O,I]=f.useState(null),[je,ye]=f.useState(!1),[pe,ke]=f.useState(void 0),[ne,A]=f.useState({}),[Oe,V]=f.useState({}),[Ue,xe]=f.useState(null),[Ne,ge]=f.useState({}),[we,fe]=f.useState({}),[u,b]=f.useState({}),[w,v]=f.useState(null),[C,H]=f.useState(null),[L,G]=f.useState(null),[Me,te]=f.useState(!1),[Te,Qe]=f.useState(null),[Ee,Ie]=f.useState(!0),[Ge,Xe]=f.useState({}),[gt,Ye]=f.useState(!1),_=(p==null?void 0:p.providers)??[],ft=_.length,be=f.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]);f.useEffect(()=>{var t,n;if(m.data){const r=m.data;R(r),A(ze(r,y)),V({});const l={anthropic:((t=r.routingPresets)==null?void 0:t.anthropic)??[],openai:((n=r.routingPresets)==null?void 0:n.openai)??[]};for(const i of y)l[i.id]=i.routingPresets??[];ge(l)}},[m.data,y]),f.useEffect(()=>{m.isError&&m.error&&a({title:s("providers.toast.loadFailure",{message:m.error.message}),variant:"error"})},[m.isError,m.error,a,s]);const bt=f.useMemo(()=>{const t=new Map;for(const n of _){if(!n.defaultModel||!n.models)continue;const r=n.models.find(l=>l.id===n.defaultModel);r&&t.set(n.id,nt(r))}return t},[_]),Je=f.useMemo(()=>{const t=[],n=new Set;for(const l of _){const i=l.label||l.id,d=l.models??[];if(d.length>0)for(const j of d){const S=`${l.id}:${j.id}`;n.has(S)||(n.add(S),t.push({value:S,label:`${i} · ${j.label??j.id}`}))}else if(l.defaultModel){const j=`${l.id}:${l.defaultModel}`;n.has(j)||(n.add(j),t.push({value:j,label:`${i} · ${l.defaultModel}`}))}const x=`${l.id}:*`;n.has(x)||(n.add(x),t.push({value:x,label:s("settings.routing.providerPassthroughOption",{provider:i})}))}const r=[...ne.anthropic||[],...ne.openai||[]];for(const l of r){const i=l.target.trim();i&&!n.has(i)&&(n.add(i),t.push({value:i,label:i}))}return t},[_,ne,s]),We=(t,n)=>{ge(r=>({...r,[t]:n})),R(r=>{if(!r)return r;if(t==="anthropic"||t==="openai")return{...r,routingPresets:{...r.routingPresets,[t]:n}};const l=r.customEndpoints??[],i=l.findIndex(x=>x.id===t);if(i===-1)return r;const d=[...l];return d[i]={...d[i],routingPresets:n},{...r,customEndpoints:d}})},se=()=>p?!0:(a({title:s("settings.toast.missingConfig"),variant:"error"}),m.refetch(),!1),vt=(t,n)=>{fe(r=>({...r,[t]:n})),n.trim()&&b(r=>({...r,[t]:null}))},jt=async t=>{if(!se())return;const n=we[t].trim();if(!n){b(r=>({...r,[t]:s("modelManagement.validation.presetName")}));return}if(Ne[t].some(r=>r.name.toLowerCase()===n.toLowerCase())){b(r=>({...r,[t]:s("modelManagement.validation.presetDuplicate",{name:n})}));return}v(t);try{const l=(await X.post(`/api/routing-presets/${t}`,{name:n})).data.presets??[];We(t,l),fe(i=>({...i,[t]:""})),b(i=>({...i,[t]:null})),a({title:s("modelManagement.toast.presetSaved",{name:n}),variant:"success"})}catch(r){a({title:s("modelManagement.toast.presetSaveFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{v(null),m.refetch()}},yt=async(t,n)=>{var r,l,i;if(se()){H({endpoint:t,name:n.name});try{const x=(await X.post(`/api/routing-presets/${t}/apply`,{name:n.name})).data.config;if(x){R(x),A(ze(x,y));const j={anthropic:((r=x.routingPresets)==null?void 0:r.anthropic)??[],openai:((l=x.routingPresets)==null?void 0:l.openai)??[]};for(const S of y){const T=(i=x.customEndpoints)==null?void 0:i.find($=>$.id===S.id);j[S.id]=(T==null?void 0:T.routingPresets)??[]}ge(j)}else A(j=>({...j,[t]:Y(n.modelRoutes)}));a({title:s("modelManagement.toast.presetApplySuccess",{name:n.name}),variant:"success"})}catch(d){a({title:s("modelManagement.toast.presetApplyFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{H(null),m.refetch()}}},kt=async(t,n)=>{if(!(!se()||!window.confirm(s("modelManagement.confirm.deletePreset",{name:n.name})))){G({endpoint:t,name:n.name});try{const i=(await X.delete(`/api/routing-presets/${t}/${encodeURIComponent(n.name)}`)).data.presets??[];We(t,i),a({title:s("modelManagement.toast.presetDeleteSuccess",{name:n.name}),variant:"success"})}catch(l){a({title:s("modelManagement.toast.presetDeleteFailure",{message:l instanceof Error?l.message:"unknown"}),variant:"error"})}finally{G(null),m.refetch()}}},Nt=()=>{se()&&(B("create"),M(void 0),U(!0))},wt=t=>{se()&&(B("edit"),M(t),U(!0))},Mt=async t=>{if(!p)throw new Error(s("settings.toast.missingConfig"));const n=z==="create"?[..._,t]:_.map(i=>k&&i.id===k.id?{...t,id:k.id}:i),r={...p,providers:n};await X.put("/api/config",r),R(r),A(ze(r,y)),m.refetch();const l=z==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});a({title:l,variant:"success"})},Et=async t=>{const n=y.find(r=>r.id===t);if(n&&confirm(s("modelManagement.deleteEndpointConfirm",{label:n.label})))try{await ve.delete(t),c.invalidateQueries({queryKey:["custom-endpoints"]}),a({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),h===t&&N("providers")}catch(r){const l=Re(r);a({title:s("modelManagement.deleteEndpointError",{error:l.message}),variant:"error"})}},Ze=async(t,n)=>{I(t.id);try{const r=n&&(n.headers||n.query)?{headers:n.headers&&Object.keys(n.headers).length>0?n.headers:void 0,query:n.query&&n.query.trim().length>0?n.query.trim():void 0}:void 0,l=await X.post(`/api/providers/${t.id}/test`,r);l.data.ok?a({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:l.data.status,duration:l.data.durationMs?`${l.data.durationMs} ms`:"—"}),variant:"success"}):a({title:s("providers.toast.testFailure",{message:`${l.data.status} ${l.data.statusText}`}),variant:"error"})}catch(r){a({title:s("providers.toast.testFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{I(null)}},Ct=t=>{if(t.type==="anthropic"){const n=t.extraHeaders??{},r=new Map(be.map(d=>[d.key.toLowerCase(),d])),l={};let i=!0;for(const d of be){const x=Object.entries(n).find(([j])=>j.toLowerCase()===d.key.toLowerCase());if(x){const[j,S]=x;String(S??"")===d.value||(i=!1,l[j]=String(S??""))}}for(const[d,x]of Object.entries(n))r.has(d.toLowerCase())||(l[d]=String(x??""));Xe(l),Ie(i),Qe(t),te(!0);return}Ze(t)},et=()=>{te(!1),Qe(null),Ie(!0),Xe({})},St=async()=>{if(!Te)return;const t={};if(Ee)for(const l of be)t[l.key]=l.value;const n=new Map(be.map(l=>[l.key.toLowerCase(),l]));for(const[l,i]of Object.entries(Ge)){const d=l.toLowerCase();n.get(d)&&Ee||(t[l]=i)}const r=Te;et(),await Ze(r,{headers:Object.keys(t).length>0?t:void 0,query:Ee?"beta=true":void 0})},Rt=async t=>{var S,T,$,ae;if(!se()||!window.confirm(s("providers.confirm.delete",{name:t.label||t.id})))return;const r=_.filter(q=>q.id!==t.id),l=q=>{const oe={};if(!q)return oe;for(const[D,ie]of Object.entries(q)){if(!ie)continue;const[re]=ie.split(":");re&&re===t.id||ie===t.id||(oe[D]=ie)}return oe},i=(p==null?void 0:p.endpointRouting)??{},d=l(((S=i.anthropic)==null?void 0:S.modelRoutes)??(p==null?void 0:p.modelRoutes)??{}),x=l(((T=i.openai)==null?void 0:T.modelRoutes)??{}),j={...p,providers:r,modelRoutes:d,endpointRouting:{anthropic:{defaults:(($=i.anthropic)==null?void 0:$.defaults)??p.defaults,modelRoutes:d},openai:{defaults:((ae=i.openai)==null?void 0:ae.defaults)??p.defaults,modelRoutes:x}}};try{await X.put("/api/config",j),R(j),A({anthropic:Y(d),openai:Y(x)}),a({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),m.refetch()}catch(q){a({title:s("providers.toast.deleteFailure",{message:q instanceof Error?q.message:"unknown"}),variant:"error"})}},Dt=t=>{A(n=>({...n,[t]:[...n[t]||[],{id:qe(),source:"",target:""}]})),V(n=>({...n,[t]:null}))},Pt=async(t,n)=>{if(se()){Ye(!0);try{if(t==="anthropic"||t==="openai"){const r=p.endpointRouting?{...p.endpointRouting}:{},l=r[t]??{defaults:p.defaults,modelRoutes:(t==="anthropic"?p.modelRoutes:{})??{}},i={defaults:l.defaults??p.defaults,modelRoutes:l.modelRoutes??{}};let d=l.validation;n?(d={...d??{},mode:"claude-code"},d.allowExperimentalBlocks===void 0&&(d.allowExperimentalBlocks=!0)):d=void 0;const x=d?{...i,validation:d}:{...i},j={...r,[t]:x},S={...p,endpointRouting:j};await X.put("/api/config",S),R(S)}else{const r=p.customEndpoints??[],l=r.findIndex(ae=>ae.id===t);if(l===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const i=r[l],d=i.routing??{defaults:p.defaults,modelRoutes:{}};let x=d.validation;n?(x={...x??{},mode:"claude-code"},x.allowExperimentalBlocks===void 0&&(x.allowExperimentalBlocks=!0)):x=void 0;const j=x?{...d,validation:x}:{...d},S={...i,routing:j},T=[...r];T[l]=S;const $={...p,customEndpoints:T};await X.put("/api/config",$),R($)}a({title:s(n?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),m.refetch()}catch(r){const l=Re(r);a({title:s("modelManagement.toast.claudeValidationFailure",{message:l.message}),variant:"error"})}finally{Ye(!1)}}},Ot=(t,n)=>{A(r=>{const l=r[t]||[];return l.some(i=>i.source.trim()===n.trim())?r:{...r,[t]:[...l,{id:qe(),source:n,target:""}]}}),V(r=>({...r,[t]:null}))},Ce=(t,n,r,l)=>{A(i=>({...i,[t]:(i[t]||[]).map(d=>d.id===n?{...d,[r]:l}:d)})),V(i=>({...i,[t]:null}))},Ut=(t,n)=>{A(r=>({...r,[t]:(r[t]||[]).filter(l=>l.id!==n)})),V(r=>({...r,[t]:null}))},Tt=t=>{var r,l;if(!p)return;const n=y.find(i=>i.id===t);if(n){const i=((r=n.routing)==null?void 0:r.modelRoutes)??{};A(d=>({...d,[t]:Y(i)}))}else{const i=p.endpointRouting??{},d=t,x=d==="anthropic"?p.modelRoutes??{}:{},j=((l=i[d])==null?void 0:l.modelRoutes)??x;A(S=>({...S,[t]:Y(j)}))}V(i=>({...i,[t]:null}))},It=async t=>{var l;if(!se())return;const n=ne[t]||[],r={};for(const i of n){const d=i.source.trim(),x=i.target.trim();if(!(!d&&!x)){if(!d||!x){V(j=>({...j,[t]:s("settings.validation.routePair")}));return}if(r[d]){V(j=>({...j,[t]:s("settings.validation.routeDuplicate",{model:d})}));return}r[d]=x}}V(i=>({...i,[t]:null})),xe(t);try{const i=y.find(d=>d.id===t);if(i){const d={...i.routing||{},modelRoutes:r,defaults:((l=i.routing)==null?void 0:l.defaults)||p.defaults};await ve.update(t,{routing:d}),c.invalidateQueries({queryKey:["custom-endpoints"]}),a({title:s("modelManagement.toast.routesSaved"),variant:"success"})}else{const d=p.endpointRouting?{...p.endpointRouting}:{},x=t,j=d[x]??{defaults:p.defaults,modelRoutes:x==="anthropic"?p.modelRoutes??{}:{}},S={...j,defaults:j.defaults??p.defaults,modelRoutes:r},T={...d,[x]:S},$={...p,endpointRouting:T,modelRoutes:x==="anthropic"?r:p.modelRoutes??{}};await X.put("/api/config",$),R($),a({title:s("modelManagement.toast.routesSaved"),variant:"success"}),m.refetch()}A(d=>({...d,[t]:Y(r)}))}catch(i){a({title:s("modelManagement.toast.routesSaveFailure",{message:i instanceof Error?i.message:"unknown"}),variant:"error"})}finally{xe(null)}},At=()=>e.jsx(Ke,{children:e.jsxs($e,{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 flex-wrap items-center gap-3",children:[e.jsx(me,{variant:"secondary",children:s("providers.count",{count:ft})}),e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>m.refetch(),disabled:m.isFetching,children:[e.jsx(es,{className:Le("mr-2 h-4 w-4",m.isFetching&&"animate-spin")}),m.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")]}),e.jsxs(P,{size:"sm",onClick:Nt,children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("providers.actions.add")]})]})]}),m.isPending||!p&&m.isFetching?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-lg border bg-muted/50 text-sm text-muted-foreground",children:s("common.loading")}):_.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed 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:"点击上方按钮添加您的第一个提供商"})})]}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:_.map(t=>e.jsx(Ke,{className:"flex flex-col",children:e.jsxs($e,{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(cs,{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(me,{variant:"default",className:"text-xs",children:bt.get(t.id)??t.defaultModel}):e.jsx(me,{variant:"secondary",className:"text-xs",children:s("providers.card.noDefault")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{className:"text-xs",children:s("providers.card.modelsTitle")}),t.models&&t.models.length>0?e.jsx("div",{className:"flex flex-wrap gap-1",children:t.models.map(n=>e.jsx(me,{variant:"outline",className:"text-xs",children:nt(n)},n.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 pt-4 border-t",children:[e.jsx(P,{variant:"outline",size:"sm",onClick:()=>wt(t),children:s("providers.actions.edit")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Ct(t),disabled:O===t.id,children:O===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>Rt(t),children:s("providers.actions.delete")})]})]})},t.id))})]})}),Lt=t=>{const n=Ne[t]??[],r=we[t]??"",l=u[t],i=w===t;return e.jsxs("div",{className:"rounded-lg border border-dashed bg-muted/30 p-6 space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium",children:s("modelManagement.presets.title")}),e.jsx("p",{className:"mt-1 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(he,{value:r,onChange:d=>vt(t,d.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),disabled:i,className:"w-full md:w-48"}),e.jsx(P,{onClick:()=>void jt(t),disabled:i,children:s(i?"modelManagement.presets.saving":"modelManagement.presets.save")})]})]}),l&&e.jsx("p",{className:"text-sm text-destructive",children:l}),n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:s("modelManagement.presets.empty")}):e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:n.map(d=>{const x=(C==null?void 0:C.endpoint)===t&&(C==null?void 0:C.name)===d.name,j=(L==null?void 0:L.endpoint)===t&&(L==null?void 0:L.name)===d.name;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border bg-card px-4 py-3",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:d.name}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(P,{size:"sm",onClick:()=>void yt(t,d),disabled:x||j,children:s(x?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>void kt(t,d),disabled:j||x,children:s(j?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},d.name)})})]})},Kt=t=>{var oe;const n=ne[t]||[],r=Oe[t],l=o.find(D=>D.key===t),d=((oe=l==null?void 0:l.protocols)==null?void 0:oe.includes("anthropic"))??t==="anthropic"?ls:ns,x=Ue===t,j=(l==null?void 0:l.label)??s(`modelManagement.tabs.${t}`),S=(l==null?void 0:l.isSystem)===!1?l.description:s(`settings.routing.descriptionByEndpoint.${t}`),T=`route-source-${t}`,$=os(t,y),ae=is(t,p,y),q=$&&(ae==null?void 0:ae.mode)==="claude-code";return e.jsx(Ke,{children:e.jsxs($e,{className:"pt-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("settings.routing.titleByEndpoint",{endpoint:j})}),e.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:S}),e.jsx("p",{className:"max-w-3xl text-xs text-muted-foreground",children:s("settings.routing.wildcardHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Dt(t),disabled:x,children:s("settings.routing.add")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Tt(t),disabled:x,children:s("common.actions.reset")}),e.jsx(P,{size:"sm",onClick:()=>void It(t),disabled:x,children:s(x?"common.actions.saving":"modelManagement.actions.saveRoutes")})]})]}),$&&e.jsx("div",{className:"rounded-lg border border-blue-200 bg-blue-50 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(ut,{checked:q,onCheckedChange:D=>void Pt(t,D),disabled:gt}),e.jsx("span",{className:Le("text-xs font-medium",q?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:s(q?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}),Lt(t),r&&e.jsx("p",{className:"text-sm text-destructive",children:r}),n.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed 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("settings.routing.emptySub",{default:"点击上方按钮添加路由规则"})})]}):e.jsx("div",{className:"space-y-3",children:n.map((D,ie)=>e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(me,{variant:"secondary",children:ie+1}),e.jsx("span",{className:"text-sm font-medium",children:"路由规则"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:s("settings.routing.source")}),e.jsx(he,{value:D.source,onChange:re=>Ce(t,D.id,"source",re.target.value),placeholder:"claude-3.5-sonnet",list:T,disabled:x})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:s("settings.routing.target")}),(()=>{const re=D.target.trim(),tt=Je.some(Q=>Q.value===re)?re:"__custom";return e.jsxs(e.Fragment,{children:[e.jsxs(mt,{value:tt,onValueChange:Q=>{Q==="__custom"?Ce(t,D.id,"target",re):Ce(t,D.id,"target",Q)},disabled:x,children:[e.jsx(ht,{children:e.jsx(pt,{})}),e.jsxs(xt,{children:[e.jsx(De,{value:"__custom",children:s("settings.routing.customTargetOption")}),Je.map(Q=>e.jsx(De,{value:Q.value,children:Q.label},Q.value))]})]}),tt==="__custom"&&e.jsx(he,{value:D.target,onChange:Q=>Ce(t,D.id,"target",Q.target.value),placeholder:"providerId:modelId",disabled:x})]})})()]}),e.jsx("div",{className:"flex items-end",children:e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>Ut(t,D.id),disabled:x,children:s("settings.routing.remove")})})]})]},D.id))}),e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-3",children:[e.jsx(Z,{children:s("settings.routing.suggested")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(D=>e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Ot(t,D),disabled:x,children:D},`${t}-${D}`))})]}),e.jsx("datalist",{id:T,children:d.map(D=>e.jsx("option",{value:D},`${T}-${D}`))})]})})};return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Qt,{icon:e.jsx(_t,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),actions:e.jsxs(P,{onClick:()=>{ke(void 0),ye(!0)},children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("modelManagement.addEndpoint")]})}),e.jsx("div",{className:"flex flex-wrap gap-3",children:o.map(t=>{const n=h===t.key;return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>N(t.key),className:Le("flex min-w-[200px] flex-col gap-1 rounded-lg border px-4 py-3 text-left transition-all",n?"border-primary bg-primary/5 text-primary":"border-border bg-card hover:bg-accent"),children:[e.jsx("span",{className:"font-medium",children:t.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:t.description})]}),t.canDelete&&e.jsx("button",{onClick:r=>{r.stopPropagation(),Et(t.key)},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(Be,{className:"h-3 w-3"})})]},t.key)})}),h==="providers"?At():Kt(h),e.jsx(rs,{open:F,mode:z,provider:z==="edit"?k:void 0,existingProviderIds:_.map(t=>t.id).filter(t=>z==="edit"&&k?t!==k.id:!0),onClose:()=>{U(!1),M(void 0),B("create")},onSubmit:Mt}),e.jsx(us,{open:je,endpoint:pe,onClose:()=>{ye(!1),ke(void 0)},onSuccess:()=>{c.invalidateQueries({queryKey:["custom-endpoints"]})}}),e.jsx(ds,{open:Me,provider:Te,options:be,preservedExtras:Ge,usePreset:Ee,onPresetChange:Ie,onConfirm:St,onClose:et})]})}function ds({open:s,provider:a,options:c,usePreset:m,preservedExtras:g,onPresetChange:y,onConfirm:o,onClose:h}){const{t:N}=Pe();return a?e.jsx(Gt,{open:s,onOpenChange:p=>!p&&h(),children:e.jsxs(Xt,{children:[e.jsxs(Yt,{children:[e.jsx(Jt,{children:N("providers.testDialog.title")}),e.jsx(Wt,{children:N("providers.testDialog.subtitle",{name:a.label||a.id})})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:N("providers.testDialog.description")}),e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border p-4",children:[e.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 rounded border",checked:m,onChange:p=>y(p.target.checked)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:N("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:N("providers.testDialog.presetDescription")}),e.jsxs("details",{className:"rounded-md bg-muted p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:N("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:c.map(p=>e.jsxs("code",{className:"block rounded bg-background px-2 py-1 text-xs",children:[p.key,": ",p.value]},p.key))})]})]})]}),Object.keys(g).length>0&&e.jsxs("div",{className:"rounded-lg border bg-muted p-4 text-xs space-y-2",children:[e.jsx("p",{className:"font-medium",children:N("providers.testDialog.preservedInfo")}),Object.entries(g).map(([p,R])=>e.jsxs("code",{className:"block rounded bg-background px-2 py-1",children:[p,": ",R]},p))]}),e.jsxs(Zt,{children:[e.jsx(P,{variant:"outline",onClick:h,children:N("providers.testDialog.cancel")}),e.jsx(P,{onClick:()=>void o(),children:N("providers.testDialog.primary")})]})]})}):null}function nt(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function cs({type:s}){const a={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:c,variant:m}=a[s]||a.custom;return e.jsx(me,{variant:m,className:"text-xs",children:c})}function us({open:s,endpoint:a,onClose:c,onSuccess:m}){const{t:g}=Pe(),{pushToast:y}=ct(),[o,h]=f.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});f.useEffect(()=>{if(a){let k;a.paths&&a.paths.length>0?k=a.paths:a.path&&a.protocol?k=[{path:a.path,protocol:a.protocol}]:k=[{path:"",protocol:"openai-auto"}],h({id:a.id,label:a.label,paths:k,enabled:a.enabled!==!1})}else h({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[a,s]);const N=rt({mutationFn:ve.create,onSuccess:()=>{y({title:g("modelManagement.createEndpointSuccess"),variant:"success"}),m(),c()},onError:k=>{const M=Re(k);y({title:g("modelManagement.createEndpointError",{error:M.message}),variant:"error"})}}),p=rt({mutationFn:k=>ve.update(k.id,k.updates),onSuccess:()=>{y({title:g("modelManagement.updateEndpointSuccess"),variant:"success"}),m(),c()},onError:k=>{const M=Re(k);y({title:g("modelManagement.updateEndpointError",{error:M.message}),variant:"error"})}}),R=()=>{h({...o,paths:[...o.paths,{path:"",protocol:"anthropic"}]})},F=k=>{if(o.paths.length===1){y({title:g("modelManagement.atLeastOnePath"),variant:"error"});return}const M=o.paths.filter((O,I)=>I!==k);h({...o,paths:M})},U=(k,M,O)=>{const I=[...o.paths];I[k]={...I[k],[M]:O},h({...o,paths:I})},z=k=>{if(k.preventDefault(),!o.id.trim()||!o.label.trim()){y({title:g("modelManagement.endpointValidationError"),variant:"error"});return}for(const O of o.paths)if(!O.path.trim()){y({title:g("modelManagement.pathValidationError"),variant:"error"});return}const M=o.paths.map(O=>({path:O.path.trim(),protocol:O.protocol}));a?p.mutate({id:a.id,updates:{label:o.label.trim(),paths:M,enabled:o.enabled}}):N.mutate({id:o.id.trim(),label:o.label.trim(),paths:M,enabled:o.enabled})},B=N.isPending||p.isPending;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-background/80 backdrop-blur-sm z-40",onClick:c}),e.jsx("div",{className:"fixed inset-y-0 right-0 w-full max-w-md bg-card border-l shadow-xl z-50 overflow-y-auto",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b",children:[e.jsx("h2",{className:"text-lg font-semibold",children:g(a?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx(P,{variant:"ghost",size:"sm",onClick:c,children:e.jsx(Be,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:z,className:"flex-1 p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Z,{children:[g("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(he,{value:o.id,onChange:k=>h({...o,id:k.target.value}),placeholder:g("modelManagement.endpointIdPlaceholder"),disabled:!!a,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Z,{children:[g("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(he,{value:o.label,onChange:k=>h({...o,label:k.target.value}),placeholder:g("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Z,{children:[g("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(P,{type:"button",variant:"ghost",size:"sm",onClick:R,children:[e.jsx(Ve,{className:"mr-1 h-3 w-3"}),g("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:o.paths.map((k,M)=>e.jsxs("div",{className:"rounded-lg border p-3 space-y-2",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(he,{value:k.path,onChange:O=>U(M,"path",O.target.value),placeholder:g("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(mt,{value:k.protocol,onValueChange:O=>U(M,"protocol",O),children:[e.jsx(ht,{children:e.jsx(pt,{})}),e.jsxs(xt,{children:[e.jsx(De,{value:"anthropic",children:g("modelManagement.protocolAnthropic")}),e.jsx(De,{value:"openai-auto",children:g("modelManagement.protocolOpenAI")})]})]})]}),o.paths.length>1&&e.jsx(P,{type:"button",variant:"ghost",size:"sm",onClick:()=>F(M),className:"text-destructive",children:e.jsx(Be,{className:"h-4 w-4"})})]}),M===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:g("modelManagement.endpointPathHint")})]},M))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ut,{id:"enabled",checked:o.enabled,onCheckedChange:k=>h({...o,enabled:k})}),e.jsx(Z,{htmlFor:"enabled",children:g("modelManagement.endpointEnabled")})]}),!a&&e.jsx("div",{className:"rounded-lg border border-blue-200 bg-blue-50 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:g("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 p-6 border-t",children:[e.jsx(P,{variant:"outline",className:"flex-1",onClick:c,disabled:B,children:g("common.cancel")}),e.jsx(P,{className:"flex-1",onClick:z,disabled:B,children:g(B?"common.saving":a?"common.save":"common.create")})]})]})})]}):null}export{ws as default};
|
|
1
|
+
var st=s=>{throw TypeError(s)};var Ae=(s,a,c)=>a.has(s)||st("Cannot "+c);var E=(s,a,c)=>(Ae(s,a,"read from private field"),c?c.call(s):a.get(s)),de=(s,a,c)=>a.has(s)?st("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(s):a.set(s,c),ce=(s,a,c,m)=>(Ae(s,a,"write to private field"),m?m.call(s,c):a.set(s,c),c),ue=(s,a,c)=>(Ae(s,a,"access private method"),c);import{S as $t,s as Ft,i as at,k as zt,n as it,l as dt,r as f,m as Bt,o as Vt,u as Pe,j as e,b as ct,e as P,p as _t,a as Le,X as Be,d as X,q as ve,t as Re}from"./index-UV1Qa96f.js";import{u as qt,a as Ht}from"./useApiQuery-C2OD7H7U.js";import{P as Qt,B as me}from"./PageHeader-xFKpGYn6.js";import{I as he}from"./input-CBGvcnZr.js";import{L as Z}from"./label-BqSverDm.js";import{C as Ke,a as $e}from"./card-C20_HqC6.js";import{S as ut}from"./switch-ODrypdNp.js";import{S as mt,a as ht,b as pt,c as xt,d as De}from"./select-C8rWWJbl.js";import{P as Ve,D as Gt,a as Xt,b as Yt,c as Jt,d as Wt,e as Zt}from"./dialog-Cx1HX_hR.js";import{R as es}from"./refresh-cw-ISOSG1Po.js";var J,le,K,W,ee,Se,_e,ot,ts=(ot=class extends $t{constructor(a,c){super();de(this,ee);de(this,J);de(this,le);de(this,K);de(this,W);ce(this,J,a),this.setOptions(c),this.bindMethods(),ue(this,ee,Se).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(a){var m;const c=this.options;this.options=E(this,J).defaultMutationOptions(a),Ft(this.options,c)||E(this,J).getMutationCache().notify({type:"observerOptionsUpdated",mutation:E(this,K),observer:this}),c!=null&&c.mutationKey&&this.options.mutationKey&&at(c.mutationKey)!==at(this.options.mutationKey)?this.reset():((m=E(this,K))==null?void 0:m.state.status)==="pending"&&E(this,K).setOptions(this.options)}onUnsubscribe(){var a;this.hasListeners()||(a=E(this,K))==null||a.removeObserver(this)}onMutationUpdate(a){ue(this,ee,Se).call(this),ue(this,ee,_e).call(this,a)}getCurrentResult(){return E(this,le)}reset(){var a;(a=E(this,K))==null||a.removeObserver(this),ce(this,K,void 0),ue(this,ee,Se).call(this),ue(this,ee,_e).call(this)}mutate(a,c){var m;return ce(this,W,c),(m=E(this,K))==null||m.removeObserver(this),ce(this,K,E(this,J).getMutationCache().build(E(this,J),this.options)),E(this,K).addObserver(this),E(this,K).execute(a)}},J=new WeakMap,le=new WeakMap,K=new WeakMap,W=new WeakMap,ee=new WeakSet,Se=function(){var c;const a=((c=E(this,K))==null?void 0:c.state)??zt();ce(this,le,{...a,isPending:a.status==="pending",isSuccess:a.status==="success",isError:a.status==="error",isIdle:a.status==="idle",mutate:this.mutate,reset:this.reset})},_e=function(a){it.batch(()=>{var c,m,g,y,o,h,N,p;if(E(this,W)&&this.hasListeners()){const R=E(this,le).variables,F=E(this,le).context,U={client:E(this,J),meta:this.options.meta,mutationKey:this.options.mutationKey};(a==null?void 0:a.type)==="success"?((m=(c=E(this,W)).onSuccess)==null||m.call(c,a.data,R,F,U),(y=(g=E(this,W)).onSettled)==null||y.call(g,a.data,null,R,F,U)):(a==null?void 0:a.type)==="error"&&((h=(o=E(this,W)).onError)==null||h.call(o,a.error,R,F,U),(p=(N=E(this,W)).onSettled)==null||p.call(N,void 0,a.error,R,F,U))}this.listeners.forEach(R=>{R(E(this,le))})})},ot);function rt(s,a){const c=dt(),[m]=f.useState(()=>new ts(c,s));f.useEffect(()=>{m.setOptions(s)},[m,s]);const g=f.useSyncExternalStore(f.useCallback(o=>m.subscribe(it.batchCalls(o)),[m]),()=>m.getCurrentResult(),()=>m.getCurrentResult()),y=f.useCallback((o,h)=>{m.mutate(o,h).catch(Bt)},[m]);if(g.error&&Vt(m.options.throwOnError,[g.error]))throw g.error;return{...g,mutate:y,mutateAsync:g.mutate}}function He(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ss(){return{_key:He(),id:"",label:""}}const Fe={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:{}};function lt(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(a=>({...a,_key:He()})),authMode:s.authMode==="authToken"?"authToken":"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function as(s){return{_key:He(),id:s.id,label:s.label}}function rs({open:s,mode:a,provider:c,existingProviderIds:m,onClose:g,onSubmit:y}){const{t:o}=Pe(),[h,N]=f.useState(()=>lt(c)),[p,R]=f.useState({}),[F,U]=f.useState(!1),[z,B]=f.useState(null),k=f.useRef(null),M=f.useRef(null),O=f.useRef(null),[I,je]=f.useState(a==="edit");f.useEffect(()=>{s&&(N(lt(c)),R({}),B(null),U(!1),je(a==="edit"))},[s,c,a]),f.useEffect(()=>{if(!s)return;const u=b=>{b.key==="Escape"&&g()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,g]),f.useEffect(()=>{if(s){if(a==="create"&&O.current){O.current.focus();return}M.current&&M.current.focus()}},[s,a]);const ye=f.useMemo(()=>h.models.filter(u=>u.id.trim().length>0),[h.models]),pe=u=>b=>{N(w=>({...w,[u]:b}))},ke=u=>{N(b=>{const v=!I||b.label.trim().length===0||b.label===b.id?u:b.label;return{...b,id:u,label:v}})},ne=u=>{N(b=>{var Me;const v=Fe[u??"custom"]??Fe.custom,C=Object.values(Fe).map(te=>te.baseUrl).filter(te=>!!te),H=!b.baseUrl||C.includes(b.baseUrl),L=a==="create"&&(b.models.length===0||b.models.every(te=>te.id.trim().length===0)),G={...b,type:u,authMode:u==="anthropic"?b.authMode??"apiKey":"apiKey"};return v!=null&&v.baseUrl&&H&&(G.baseUrl=v.baseUrl),v!=null&&v.models&&L&&(G.models=v.models.map(as),G.defaultModel=v.defaultModel??((Me=v.models[0])==null?void 0:Me.id)??""),G})},A=(u,b)=>{N(w=>{const v=[...w.models];return v[u]={...v[u],...b},{...w,models:v}})},Oe=(u,b)=>{N(w=>{const v=[...w.models],C=v[u];if(!C)return w;const H=!I||!C.label||C.label===C.id,L={...C,id:b,label:H?b:C.label};v[u]=L;const G=w.defaultModel===C.id?b:w.defaultModel;return{...w,models:v,defaultModel:G}})},V=u=>{N(b=>{if(u<0||u>=b.models.length)return b;const w=b.models.filter((C,H)=>H!==u);let v=b.defaultModel;return w.some(C=>C.id===v)||(v=""),{...b,models:w,defaultModel:v}})},Ue=()=>{N(u=>({...u,models:[...u.models,ss()]}))},xe=u=>{N(b=>({...b,authMode:u}))},Ne=()=>{const u={},b=h.id.trim(),w=h.baseUrl.trim();if(a==="create"&&(b.length===0?u.id=o("providers.drawer.errors.idRequired"):m.includes(b)&&(u.id=o("providers.drawer.errors.idDuplicate"))),a==="edit"&&b.length===0&&(u.id=o("providers.drawer.errors.idRequired")),w.length===0)u.baseUrl=o("providers.drawer.errors.baseUrlInvalid");else try{new URL(w)}catch{u.baseUrl=o("providers.drawer.errors.baseUrlInvalid")}if(h.models.length>0){const v=new Set;h.models.some(H=>{const L=H.id.trim();return L.length===0||v.has(L)?!0:(v.add(L),!1)})&&(u.models=o("providers.drawer.errors.modelInvalid"))}return h.defaultModel&&!h.models.some(v=>v.id===h.defaultModel)&&(u.models=o("providers.drawer.errors.defaultInvalid")),R(u),Object.keys(u).length===0},ge=()=>{const u=h.models.map(v=>{var C;return{id:v.id.trim(),label:(C=v.label)!=null&&C.trim()?v.label.trim():void 0}}).filter(v=>v.id.length>0),b=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,w=h.type==="anthropic"?h.authMode:void 0;return{id:h.id.trim(),label:h.label.trim()||h.id.trim(),baseUrl:h.baseUrl.trim(),apiKey:h.apiKey.trim()||void 0,type:h.type??"custom",defaultModel:h.defaultModel||void 0,models:u.length>0?u:void 0,extraHeaders:b,authMode:w}},we=async()=>{if(B(null),!!Ne()){U(!0);try{const u=ge();await y(u)}catch(u){B(o("providers.drawer.toast.saveFailure",{message:u instanceof Error?u.message:"unknown"})),U(!1);return}U(!1),g()}},fe=a==="create";return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:g,"aria-hidden":"true"}),e.jsxs("aside",{ref:k,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-3xl flex-col border-l border-slate-200 bg-white shadow-xl dark:border-slate-800 dark:bg-slate-900",children:[e.jsxs("header",{className:"flex items-center justify-between border-b border-slate-200 px-6 py-4 dark:border-slate-800",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold",children:o(fe?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.description")})]}),e.jsx("button",{type:"button",ref:M,onClick:g,className:"rounded-md border border-slate-200 px-3 py-1 text-sm transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:o("common.actions.close")})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-4","aria-labelledby":"provider-basic-fields",children:[e.jsx("div",{id:"provider-basic-fields",className:"sr-only",children:o("providers.drawer.description")}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{type:"button",onClick:()=>je(u=>!u),className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:o(I?"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-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.id")}),e.jsx("input",{value:h.id,ref:O,onChange:u=>ke(u.target.value),disabled:!fe,placeholder:o("providers.drawer.fields.idPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60","aria-invalid":!!p.id}),p.id?e.jsx("span",{className:"text-xs text-red-500",children:p.id}):null]}),I?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.label")}),e.jsx("input",{value:h.label,onChange:u=>pe("label")(u.target.value),placeholder:o("providers.drawer.fields.labelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):null]}),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-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:h.baseUrl,onChange:u=>pe("baseUrl")(u.target.value),placeholder:o("providers.drawer.fields.baseUrlPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60","aria-invalid":!!p.baseUrl}),p.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:p.baseUrl}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.type")}),e.jsxs("select",{value:h.type??"custom",onChange:u=>ne(u.target.value),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60",children:[e.jsx("option",{value:"openai",children:"OpenAI"}),e.jsx("option",{value:"deepseek",children:"DeepSeek"}),e.jsx("option",{value:"huawei",children:"华为云"}),e.jsx("option",{value:"kimi",children:"Kimi"}),e.jsx("option",{value:"anthropic",children:"Anthropic (Claude)"}),e.jsx("option",{value:"custom",children:"Custom"})]})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.apiKey")}),e.jsx("input",{value:h.apiKey,onChange:u=>pe("apiKey")(u.target.value),placeholder:o("providers.drawer.fields.apiKeyPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}),h.type==="anthropic"?e.jsxs("fieldset",{className:"grid gap-2 rounded-lg border border-slate-200 p-3 text-xs dark:border-slate-700",children:[e.jsx("legend",{className:"px-1 text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 transition hover:bg-slate-100 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"radio",name:"anthropic-auth-mode",value:"apiKey",checked:h.authMode==="apiKey",onChange:()=>xe("apiKey")}),e.jsx("span",{children:o("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 transition hover:bg-slate-100 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"radio",name:"anthropic-auth-mode",value:"authToken",checked:h.authMode==="authToken",onChange:()=>xe("authToken")}),e.jsx("span",{children:o("providers.drawer.fields.authModeAuthToken")})]})]}):null]}),e.jsxs("section",{className:"mt-6 space-y-3","aria-labelledby":"provider-model-fields",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"provider-model-fields",className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:Ue,className:"rounded-md border border-slate-200 px-3 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:o("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:[h.models.map((u,b)=>e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-4 dark:border-slate-700 dark:bg-slate-800/40",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-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.modelId")}),e.jsx("input",{value:u.id,onChange:w=>Oe(b,w.target.value),placeholder:o("providers.drawer.fields.modelIdPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}),I?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:u.label??"",onChange:w=>A(b,{label:w.target.value}),placeholder:o("providers.drawer.fields.modelLabelPlaceholder"),className:"rounded-md border border-slate-200 bg-white px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-200 disabled:bg-slate-100 disabled:text-slate-400 dark:border-slate-700 dark:bg-slate-800 dark:focus:border-blue-400 dark:focus:ring-blue-400/40 dark:disabled:bg-slate-800/60"})]}):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:u.id,checked:h.defaultModel===u.id,onChange:()=>N(w=>({...w,defaultModel:u.id})),disabled:u.id.trim().length===0}),o("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:()=>V(b),disabled:h.models.length===0,children:o("providers.drawer.fields.removeModel")})]})]},u._key)),h.models.length===0?e.jsx("div",{className:"rounded-xl border-2 border-amber-300 bg-gradient-to-br from-amber-50 to-yellow-50 p-5 shadow-md dark:border-amber-600/60 dark:from-amber-900/20 dark:to-yellow-900/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex-shrink-0 text-2xl",children:"💡"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:o("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:o("providers.drawer.noModelsHint",{providerId:h.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:o("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded bg-white px-2.5 py-1.5 font-mono text-xs text-amber-900 shadow-sm dark:bg-slate-900 dark:text-amber-100",children:['"claude-*": "',(h.id||"provider-id").trim()||"provider-id",':*"']})]})]})]})}):null]}),ye.length>1?e.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:o("providers.drawer.defaultHint",{model:h.defaultModel||o("providers.card.noDefault")})}):null]})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-slate-200 px-6 py-4 text-sm dark:border-slate-800",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:z?e.jsx("span",{children:z}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:g,className:"rounded-md border border-slate-200 px-4 py-2 transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",disabled:F,children:o("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:we,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:F,children:o(F?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const ls=["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"],ns=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function qe(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Y(s){return s?Object.entries(s).map(([a,c])=>({id:qe(),source:a,target:c})):[]}function ze(s,a){var g,y,o;if(!s)return{};const c={},m=s.endpointRouting??{};c.anthropic=Y(((g=m.anthropic)==null?void 0:g.modelRoutes)??s.modelRoutes??{}),c.openai=Y(((y=m.openai)==null?void 0:y.modelRoutes)??{});for(const h of a)(o=h.routing)!=null&&o.modelRoutes?c[h.id]=Y(h.routing.modelRoutes):c[h.id]=[];return c}function os(s,a){if(s==="anthropic")return!0;const c=a.find(m=>m.id===s);return c?c.paths&&c.paths.length>0?c.paths.some(m=>m.protocol==="anthropic"):c.protocol==="anthropic":!1}function is(s,a,c){var g,y,o;if(!a)return;if(s==="anthropic"||s==="openai")return(y=(g=a.endpointRouting)==null?void 0:g[s])==null?void 0:y.validation;const m=c.find(h=>h.id===s);return(o=m==null?void 0:m.routing)==null?void 0:o.validation}function ws(){const{t:s}=Pe(),{pushToast:a}=ct(),c=dt(),m=qt(["config","full"],{url:"/api/config",method:"GET"}),{data:g}=Ht({queryKey:["custom-endpoints"],queryFn:ve.list,refetchInterval:1e4}),y=(g==null?void 0:g.endpoints)??[],o=f.useMemo(()=>{const t=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],n=y.map(r=>{let l,i=[];if(r.paths&&r.paths.length>0){const d=r.paths.map(x=>`${x.path} (${x.protocol})`).join(", ");l=`${s("modelManagement.tabs.customEndpoint")}: ${d}`,i=[...new Set(r.paths.map(x=>x.protocol))]}else if(r.path){const d=r.protocol||"anthropic";l=`${s("modelManagement.tabs.customEndpoint")}: ${r.path} (${d})`,i=[d]}else l=s("modelManagement.tabs.customEndpoint");return{key:r.id,label:r.label,description:l,isSystem:!1,canDelete:!0,protocols:i}});return[...t,...n]},[s,y]),[h,N]=f.useState("providers"),[p,R]=f.useState(null),[F,U]=f.useState(!1),[z,B]=f.useState("create"),[k,M]=f.useState(void 0),[O,I]=f.useState(null),[je,ye]=f.useState(!1),[pe,ke]=f.useState(void 0),[ne,A]=f.useState({}),[Oe,V]=f.useState({}),[Ue,xe]=f.useState(null),[Ne,ge]=f.useState({}),[we,fe]=f.useState({}),[u,b]=f.useState({}),[w,v]=f.useState(null),[C,H]=f.useState(null),[L,G]=f.useState(null),[Me,te]=f.useState(!1),[Te,Qe]=f.useState(null),[Ee,Ie]=f.useState(!0),[Ge,Xe]=f.useState({}),[gt,Ye]=f.useState(!1),_=(p==null?void 0:p.providers)??[],ft=_.length,be=f.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]);f.useEffect(()=>{var t,n;if(m.data){const r=m.data;R(r),A(ze(r,y)),V({});const l={anthropic:((t=r.routingPresets)==null?void 0:t.anthropic)??[],openai:((n=r.routingPresets)==null?void 0:n.openai)??[]};for(const i of y)l[i.id]=i.routingPresets??[];ge(l)}},[m.data,y]),f.useEffect(()=>{m.isError&&m.error&&a({title:s("providers.toast.loadFailure",{message:m.error.message}),variant:"error"})},[m.isError,m.error,a,s]);const bt=f.useMemo(()=>{const t=new Map;for(const n of _){if(!n.defaultModel||!n.models)continue;const r=n.models.find(l=>l.id===n.defaultModel);r&&t.set(n.id,nt(r))}return t},[_]),Je=f.useMemo(()=>{const t=[],n=new Set;for(const l of _){const i=l.label||l.id,d=l.models??[];if(d.length>0)for(const j of d){const S=`${l.id}:${j.id}`;n.has(S)||(n.add(S),t.push({value:S,label:`${i} · ${j.label??j.id}`}))}else if(l.defaultModel){const j=`${l.id}:${l.defaultModel}`;n.has(j)||(n.add(j),t.push({value:j,label:`${i} · ${l.defaultModel}`}))}const x=`${l.id}:*`;n.has(x)||(n.add(x),t.push({value:x,label:s("settings.routing.providerPassthroughOption",{provider:i})}))}const r=[...ne.anthropic||[],...ne.openai||[]];for(const l of r){const i=l.target.trim();i&&!n.has(i)&&(n.add(i),t.push({value:i,label:i}))}return t},[_,ne,s]),We=(t,n)=>{ge(r=>({...r,[t]:n})),R(r=>{if(!r)return r;if(t==="anthropic"||t==="openai")return{...r,routingPresets:{...r.routingPresets,[t]:n}};const l=r.customEndpoints??[],i=l.findIndex(x=>x.id===t);if(i===-1)return r;const d=[...l];return d[i]={...d[i],routingPresets:n},{...r,customEndpoints:d}})},se=()=>p?!0:(a({title:s("settings.toast.missingConfig"),variant:"error"}),m.refetch(),!1),vt=(t,n)=>{fe(r=>({...r,[t]:n})),n.trim()&&b(r=>({...r,[t]:null}))},jt=async t=>{if(!se())return;const n=we[t].trim();if(!n){b(r=>({...r,[t]:s("modelManagement.validation.presetName")}));return}if(Ne[t].some(r=>r.name.toLowerCase()===n.toLowerCase())){b(r=>({...r,[t]:s("modelManagement.validation.presetDuplicate",{name:n})}));return}v(t);try{const l=(await X.post(`/api/routing-presets/${t}`,{name:n})).data.presets??[];We(t,l),fe(i=>({...i,[t]:""})),b(i=>({...i,[t]:null})),a({title:s("modelManagement.toast.presetSaved",{name:n}),variant:"success"})}catch(r){a({title:s("modelManagement.toast.presetSaveFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{v(null),m.refetch()}},yt=async(t,n)=>{var r,l,i;if(se()){H({endpoint:t,name:n.name});try{const x=(await X.post(`/api/routing-presets/${t}/apply`,{name:n.name})).data.config;if(x){R(x),A(ze(x,y));const j={anthropic:((r=x.routingPresets)==null?void 0:r.anthropic)??[],openai:((l=x.routingPresets)==null?void 0:l.openai)??[]};for(const S of y){const T=(i=x.customEndpoints)==null?void 0:i.find($=>$.id===S.id);j[S.id]=(T==null?void 0:T.routingPresets)??[]}ge(j)}else A(j=>({...j,[t]:Y(n.modelRoutes)}));a({title:s("modelManagement.toast.presetApplySuccess",{name:n.name}),variant:"success"})}catch(d){a({title:s("modelManagement.toast.presetApplyFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{H(null),m.refetch()}}},kt=async(t,n)=>{if(!(!se()||!window.confirm(s("modelManagement.confirm.deletePreset",{name:n.name})))){G({endpoint:t,name:n.name});try{const i=(await X.delete(`/api/routing-presets/${t}/${encodeURIComponent(n.name)}`)).data.presets??[];We(t,i),a({title:s("modelManagement.toast.presetDeleteSuccess",{name:n.name}),variant:"success"})}catch(l){a({title:s("modelManagement.toast.presetDeleteFailure",{message:l instanceof Error?l.message:"unknown"}),variant:"error"})}finally{G(null),m.refetch()}}},Nt=()=>{se()&&(B("create"),M(void 0),U(!0))},wt=t=>{se()&&(B("edit"),M(t),U(!0))},Mt=async t=>{if(!p)throw new Error(s("settings.toast.missingConfig"));const n=z==="create"?[..._,t]:_.map(i=>k&&i.id===k.id?{...t,id:k.id}:i),r={...p,providers:n};await X.put("/api/config",r),R(r),A(ze(r,y)),m.refetch();const l=z==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});a({title:l,variant:"success"})},Et=async t=>{const n=y.find(r=>r.id===t);if(n&&confirm(s("modelManagement.deleteEndpointConfirm",{label:n.label})))try{await ve.delete(t),c.invalidateQueries({queryKey:["custom-endpoints"]}),a({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),h===t&&N("providers")}catch(r){const l=Re(r);a({title:s("modelManagement.deleteEndpointError",{error:l.message}),variant:"error"})}},Ze=async(t,n)=>{I(t.id);try{const r=n&&(n.headers||n.query)?{headers:n.headers&&Object.keys(n.headers).length>0?n.headers:void 0,query:n.query&&n.query.trim().length>0?n.query.trim():void 0}:void 0,l=await X.post(`/api/providers/${t.id}/test`,r);l.data.ok?a({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:l.data.status,duration:l.data.durationMs?`${l.data.durationMs} ms`:"—"}),variant:"success"}):a({title:s("providers.toast.testFailure",{message:`${l.data.status} ${l.data.statusText}`}),variant:"error"})}catch(r){a({title:s("providers.toast.testFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{I(null)}},Ct=t=>{if(t.type==="anthropic"){const n=t.extraHeaders??{},r=new Map(be.map(d=>[d.key.toLowerCase(),d])),l={};let i=!0;for(const d of be){const x=Object.entries(n).find(([j])=>j.toLowerCase()===d.key.toLowerCase());if(x){const[j,S]=x;String(S??"")===d.value||(i=!1,l[j]=String(S??""))}}for(const[d,x]of Object.entries(n))r.has(d.toLowerCase())||(l[d]=String(x??""));Xe(l),Ie(i),Qe(t),te(!0);return}Ze(t)},et=()=>{te(!1),Qe(null),Ie(!0),Xe({})},St=async()=>{if(!Te)return;const t={};if(Ee)for(const l of be)t[l.key]=l.value;const n=new Map(be.map(l=>[l.key.toLowerCase(),l]));for(const[l,i]of Object.entries(Ge)){const d=l.toLowerCase();n.get(d)&&Ee||(t[l]=i)}const r=Te;et(),await Ze(r,{headers:Object.keys(t).length>0?t:void 0,query:Ee?"beta=true":void 0})},Rt=async t=>{var S,T,$,ae;if(!se()||!window.confirm(s("providers.confirm.delete",{name:t.label||t.id})))return;const r=_.filter(q=>q.id!==t.id),l=q=>{const oe={};if(!q)return oe;for(const[D,ie]of Object.entries(q)){if(!ie)continue;const[re]=ie.split(":");re&&re===t.id||ie===t.id||(oe[D]=ie)}return oe},i=(p==null?void 0:p.endpointRouting)??{},d=l(((S=i.anthropic)==null?void 0:S.modelRoutes)??(p==null?void 0:p.modelRoutes)??{}),x=l(((T=i.openai)==null?void 0:T.modelRoutes)??{}),j={...p,providers:r,modelRoutes:d,endpointRouting:{anthropic:{defaults:(($=i.anthropic)==null?void 0:$.defaults)??p.defaults,modelRoutes:d},openai:{defaults:((ae=i.openai)==null?void 0:ae.defaults)??p.defaults,modelRoutes:x}}};try{await X.put("/api/config",j),R(j),A({anthropic:Y(d),openai:Y(x)}),a({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),m.refetch()}catch(q){a({title:s("providers.toast.deleteFailure",{message:q instanceof Error?q.message:"unknown"}),variant:"error"})}},Dt=t=>{A(n=>({...n,[t]:[...n[t]||[],{id:qe(),source:"",target:""}]})),V(n=>({...n,[t]:null}))},Pt=async(t,n)=>{if(se()){Ye(!0);try{if(t==="anthropic"||t==="openai"){const r=p.endpointRouting?{...p.endpointRouting}:{},l=r[t]??{defaults:p.defaults,modelRoutes:(t==="anthropic"?p.modelRoutes:{})??{}},i={defaults:l.defaults??p.defaults,modelRoutes:l.modelRoutes??{}};let d=l.validation;n?(d={...d??{},mode:"claude-code"},d.allowExperimentalBlocks===void 0&&(d.allowExperimentalBlocks=!0)):d=void 0;const x=d?{...i,validation:d}:{...i},j={...r,[t]:x},S={...p,endpointRouting:j};await X.put("/api/config",S),R(S)}else{const r=p.customEndpoints??[],l=r.findIndex(ae=>ae.id===t);if(l===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const i=r[l],d=i.routing??{defaults:p.defaults,modelRoutes:{}};let x=d.validation;n?(x={...x??{},mode:"claude-code"},x.allowExperimentalBlocks===void 0&&(x.allowExperimentalBlocks=!0)):x=void 0;const j=x?{...d,validation:x}:{...d},S={...i,routing:j},T=[...r];T[l]=S;const $={...p,customEndpoints:T};await X.put("/api/config",$),R($)}a({title:s(n?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),m.refetch()}catch(r){const l=Re(r);a({title:s("modelManagement.toast.claudeValidationFailure",{message:l.message}),variant:"error"})}finally{Ye(!1)}}},Ot=(t,n)=>{A(r=>{const l=r[t]||[];return l.some(i=>i.source.trim()===n.trim())?r:{...r,[t]:[...l,{id:qe(),source:n,target:""}]}}),V(r=>({...r,[t]:null}))},Ce=(t,n,r,l)=>{A(i=>({...i,[t]:(i[t]||[]).map(d=>d.id===n?{...d,[r]:l}:d)})),V(i=>({...i,[t]:null}))},Ut=(t,n)=>{A(r=>({...r,[t]:(r[t]||[]).filter(l=>l.id!==n)})),V(r=>({...r,[t]:null}))},Tt=t=>{var r,l;if(!p)return;const n=y.find(i=>i.id===t);if(n){const i=((r=n.routing)==null?void 0:r.modelRoutes)??{};A(d=>({...d,[t]:Y(i)}))}else{const i=p.endpointRouting??{},d=t,x=d==="anthropic"?p.modelRoutes??{}:{},j=((l=i[d])==null?void 0:l.modelRoutes)??x;A(S=>({...S,[t]:Y(j)}))}V(i=>({...i,[t]:null}))},It=async t=>{var l;if(!se())return;const n=ne[t]||[],r={};for(const i of n){const d=i.source.trim(),x=i.target.trim();if(!(!d&&!x)){if(!d||!x){V(j=>({...j,[t]:s("settings.validation.routePair")}));return}if(r[d]){V(j=>({...j,[t]:s("settings.validation.routeDuplicate",{model:d})}));return}r[d]=x}}V(i=>({...i,[t]:null})),xe(t);try{const i=y.find(d=>d.id===t);if(i){const d={...i.routing||{},modelRoutes:r,defaults:((l=i.routing)==null?void 0:l.defaults)||p.defaults};await ve.update(t,{routing:d}),c.invalidateQueries({queryKey:["custom-endpoints"]}),a({title:s("modelManagement.toast.routesSaved"),variant:"success"})}else{const d=p.endpointRouting?{...p.endpointRouting}:{},x=t,j=d[x]??{defaults:p.defaults,modelRoutes:x==="anthropic"?p.modelRoutes??{}:{}},S={...j,defaults:j.defaults??p.defaults,modelRoutes:r},T={...d,[x]:S},$={...p,endpointRouting:T,modelRoutes:x==="anthropic"?r:p.modelRoutes??{}};await X.put("/api/config",$),R($),a({title:s("modelManagement.toast.routesSaved"),variant:"success"}),m.refetch()}A(d=>({...d,[t]:Y(r)}))}catch(i){a({title:s("modelManagement.toast.routesSaveFailure",{message:i instanceof Error?i.message:"unknown"}),variant:"error"})}finally{xe(null)}},At=()=>e.jsx(Ke,{children:e.jsxs($e,{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 flex-wrap items-center gap-3",children:[e.jsx(me,{variant:"secondary",children:s("providers.count",{count:ft})}),e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>m.refetch(),disabled:m.isFetching,children:[e.jsx(es,{className:Le("mr-2 h-4 w-4",m.isFetching&&"animate-spin")}),m.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")]}),e.jsxs(P,{size:"sm",onClick:Nt,children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("providers.actions.add")]})]})]}),m.isPending||!p&&m.isFetching?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-lg border bg-muted/50 text-sm text-muted-foreground",children:s("common.loading")}):_.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed 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:"点击上方按钮添加您的第一个提供商"})})]}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:_.map(t=>e.jsx(Ke,{className:"flex flex-col",children:e.jsxs($e,{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(cs,{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(me,{variant:"default",className:"text-xs",children:bt.get(t.id)??t.defaultModel}):e.jsx(me,{variant:"secondary",className:"text-xs",children:s("providers.card.noDefault")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{className:"text-xs",children:s("providers.card.modelsTitle")}),t.models&&t.models.length>0?e.jsx("div",{className:"flex flex-wrap gap-1",children:t.models.map(n=>e.jsx(me,{variant:"outline",className:"text-xs",children:nt(n)},n.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 pt-4 border-t",children:[e.jsx(P,{variant:"outline",size:"sm",onClick:()=>wt(t),children:s("providers.actions.edit")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Ct(t),disabled:O===t.id,children:O===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>Rt(t),children:s("providers.actions.delete")})]})]})},t.id))})]})}),Lt=t=>{const n=Ne[t]??[],r=we[t]??"",l=u[t],i=w===t;return e.jsxs("div",{className:"rounded-lg border border-dashed bg-muted/30 p-6 space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium",children:s("modelManagement.presets.title")}),e.jsx("p",{className:"mt-1 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(he,{value:r,onChange:d=>vt(t,d.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),disabled:i,className:"w-full md:w-48"}),e.jsx(P,{onClick:()=>void jt(t),disabled:i,children:s(i?"modelManagement.presets.saving":"modelManagement.presets.save")})]})]}),l&&e.jsx("p",{className:"text-sm text-destructive",children:l}),n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:s("modelManagement.presets.empty")}):e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:n.map(d=>{const x=(C==null?void 0:C.endpoint)===t&&(C==null?void 0:C.name)===d.name,j=(L==null?void 0:L.endpoint)===t&&(L==null?void 0:L.name)===d.name;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border bg-card px-4 py-3",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:d.name}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(P,{size:"sm",onClick:()=>void yt(t,d),disabled:x||j,children:s(x?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>void kt(t,d),disabled:j||x,children:s(j?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},d.name)})})]})},Kt=t=>{var oe;const n=ne[t]||[],r=Oe[t],l=o.find(D=>D.key===t),d=((oe=l==null?void 0:l.protocols)==null?void 0:oe.includes("anthropic"))??t==="anthropic"?ls:ns,x=Ue===t,j=(l==null?void 0:l.label)??s(`modelManagement.tabs.${t}`),S=(l==null?void 0:l.isSystem)===!1?l.description:s(`settings.routing.descriptionByEndpoint.${t}`),T=`route-source-${t}`,$=os(t,y),ae=is(t,p,y),q=$&&(ae==null?void 0:ae.mode)==="claude-code";return e.jsx(Ke,{children:e.jsxs($e,{className:"pt-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("settings.routing.titleByEndpoint",{endpoint:j})}),e.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:S}),e.jsx("p",{className:"max-w-3xl text-xs text-muted-foreground",children:s("settings.routing.wildcardHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Dt(t),disabled:x,children:s("settings.routing.add")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Tt(t),disabled:x,children:s("common.actions.reset")}),e.jsx(P,{size:"sm",onClick:()=>void It(t),disabled:x,children:s(x?"common.actions.saving":"modelManagement.actions.saveRoutes")})]})]}),$&&e.jsx("div",{className:"rounded-lg border border-blue-200 bg-blue-50 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(ut,{checked:q,onCheckedChange:D=>void Pt(t,D),disabled:gt}),e.jsx("span",{className:Le("text-xs font-medium",q?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:s(q?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}),Lt(t),r&&e.jsx("p",{className:"text-sm text-destructive",children:r}),n.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed 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("settings.routing.emptySub",{default:"点击上方按钮添加路由规则"})})]}):e.jsx("div",{className:"space-y-3",children:n.map((D,ie)=>e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx(me,{variant:"secondary",children:ie+1}),e.jsx("span",{className:"text-sm font-medium",children:"路由规则"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:s("settings.routing.source")}),e.jsx(he,{value:D.source,onChange:re=>Ce(t,D.id,"source",re.target.value),placeholder:"claude-3.5-sonnet",list:T,disabled:x})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:s("settings.routing.target")}),(()=>{const re=D.target.trim(),tt=Je.some(Q=>Q.value===re)?re:"__custom";return e.jsxs(e.Fragment,{children:[e.jsxs(mt,{value:tt,onValueChange:Q=>{Q==="__custom"?Ce(t,D.id,"target",re):Ce(t,D.id,"target",Q)},disabled:x,children:[e.jsx(ht,{children:e.jsx(pt,{})}),e.jsxs(xt,{children:[e.jsx(De,{value:"__custom",children:s("settings.routing.customTargetOption")}),Je.map(Q=>e.jsx(De,{value:Q.value,children:Q.label},Q.value))]})]}),tt==="__custom"&&e.jsx(he,{value:D.target,onChange:Q=>Ce(t,D.id,"target",Q.target.value),placeholder:"providerId:modelId",disabled:x})]})})()]}),e.jsx("div",{className:"flex items-end",children:e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>Ut(t,D.id),disabled:x,children:s("settings.routing.remove")})})]})]},D.id))}),e.jsxs("div",{className:"rounded-lg border bg-muted/50 p-4 space-y-3",children:[e.jsx(Z,{children:s("settings.routing.suggested")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(D=>e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Ot(t,D),disabled:x,children:D},`${t}-${D}`))})]}),e.jsx("datalist",{id:T,children:d.map(D=>e.jsx("option",{value:D},`${T}-${D}`))})]})})};return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Qt,{icon:e.jsx(_t,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),actions:e.jsxs(P,{onClick:()=>{ke(void 0),ye(!0)},children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("modelManagement.addEndpoint")]})}),e.jsx("div",{className:"flex flex-wrap gap-3",children:o.map(t=>{const n=h===t.key;return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>N(t.key),className:Le("flex min-w-[200px] flex-col gap-1 rounded-lg border px-4 py-3 text-left transition-all",n?"border-primary bg-primary/5 text-primary":"border-border bg-card hover:bg-accent"),children:[e.jsx("span",{className:"font-medium",children:t.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:t.description})]}),t.canDelete&&e.jsx("button",{onClick:r=>{r.stopPropagation(),Et(t.key)},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(Be,{className:"h-3 w-3"})})]},t.key)})}),h==="providers"?At():Kt(h),e.jsx(rs,{open:F,mode:z,provider:z==="edit"?k:void 0,existingProviderIds:_.map(t=>t.id).filter(t=>z==="edit"&&k?t!==k.id:!0),onClose:()=>{U(!1),M(void 0),B("create")},onSubmit:Mt}),e.jsx(us,{open:je,endpoint:pe,onClose:()=>{ye(!1),ke(void 0)},onSuccess:()=>{c.invalidateQueries({queryKey:["custom-endpoints"]})}}),e.jsx(ds,{open:Me,provider:Te,options:be,preservedExtras:Ge,usePreset:Ee,onPresetChange:Ie,onConfirm:St,onClose:et})]})}function ds({open:s,provider:a,options:c,usePreset:m,preservedExtras:g,onPresetChange:y,onConfirm:o,onClose:h}){const{t:N}=Pe();return a?e.jsx(Gt,{open:s,onOpenChange:p=>!p&&h(),children:e.jsxs(Xt,{children:[e.jsxs(Yt,{children:[e.jsx(Jt,{children:N("providers.testDialog.title")}),e.jsx(Wt,{children:N("providers.testDialog.subtitle",{name:a.label||a.id})})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:N("providers.testDialog.description")}),e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border p-4",children:[e.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 rounded border",checked:m,onChange:p=>y(p.target.checked)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Z,{children:N("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:N("providers.testDialog.presetDescription")}),e.jsxs("details",{className:"rounded-md bg-muted p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:N("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:c.map(p=>e.jsxs("code",{className:"block rounded bg-background px-2 py-1 text-xs",children:[p.key,": ",p.value]},p.key))})]})]})]}),Object.keys(g).length>0&&e.jsxs("div",{className:"rounded-lg border bg-muted p-4 text-xs space-y-2",children:[e.jsx("p",{className:"font-medium",children:N("providers.testDialog.preservedInfo")}),Object.entries(g).map(([p,R])=>e.jsxs("code",{className:"block rounded bg-background px-2 py-1",children:[p,": ",R]},p))]}),e.jsxs(Zt,{children:[e.jsx(P,{variant:"outline",onClick:h,children:N("providers.testDialog.cancel")}),e.jsx(P,{onClick:()=>void o(),children:N("providers.testDialog.primary")})]})]})}):null}function nt(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function cs({type:s}){const a={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:c,variant:m}=a[s]||a.custom;return e.jsx(me,{variant:m,className:"text-xs",children:c})}function us({open:s,endpoint:a,onClose:c,onSuccess:m}){const{t:g}=Pe(),{pushToast:y}=ct(),[o,h]=f.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});f.useEffect(()=>{if(a){let k;a.paths&&a.paths.length>0?k=a.paths:a.path&&a.protocol?k=[{path:a.path,protocol:a.protocol}]:k=[{path:"",protocol:"openai-auto"}],h({id:a.id,label:a.label,paths:k,enabled:a.enabled!==!1})}else h({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[a,s]);const N=rt({mutationFn:ve.create,onSuccess:()=>{y({title:g("modelManagement.createEndpointSuccess"),variant:"success"}),m(),c()},onError:k=>{const M=Re(k);y({title:g("modelManagement.createEndpointError",{error:M.message}),variant:"error"})}}),p=rt({mutationFn:k=>ve.update(k.id,k.updates),onSuccess:()=>{y({title:g("modelManagement.updateEndpointSuccess"),variant:"success"}),m(),c()},onError:k=>{const M=Re(k);y({title:g("modelManagement.updateEndpointError",{error:M.message}),variant:"error"})}}),R=()=>{h({...o,paths:[...o.paths,{path:"",protocol:"anthropic"}]})},F=k=>{if(o.paths.length===1){y({title:g("modelManagement.atLeastOnePath"),variant:"error"});return}const M=o.paths.filter((O,I)=>I!==k);h({...o,paths:M})},U=(k,M,O)=>{const I=[...o.paths];I[k]={...I[k],[M]:O},h({...o,paths:I})},z=k=>{if(k.preventDefault(),!o.id.trim()||!o.label.trim()){y({title:g("modelManagement.endpointValidationError"),variant:"error"});return}for(const O of o.paths)if(!O.path.trim()){y({title:g("modelManagement.pathValidationError"),variant:"error"});return}const M=o.paths.map(O=>({path:O.path.trim(),protocol:O.protocol}));a?p.mutate({id:a.id,updates:{label:o.label.trim(),paths:M,enabled:o.enabled}}):N.mutate({id:o.id.trim(),label:o.label.trim(),paths:M,enabled:o.enabled})},B=N.isPending||p.isPending;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-background/80 backdrop-blur-sm z-40",onClick:c}),e.jsx("div",{className:"fixed inset-y-0 right-0 w-full max-w-md bg-card border-l shadow-xl z-50 overflow-y-auto",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b",children:[e.jsx("h2",{className:"text-lg font-semibold",children:g(a?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx(P,{variant:"ghost",size:"sm",onClick:c,children:e.jsx(Be,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:z,className:"flex-1 p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Z,{children:[g("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(he,{value:o.id,onChange:k=>h({...o,id:k.target.value}),placeholder:g("modelManagement.endpointIdPlaceholder"),disabled:!!a,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Z,{children:[g("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(he,{value:o.label,onChange:k=>h({...o,label:k.target.value}),placeholder:g("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Z,{children:[g("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(P,{type:"button",variant:"ghost",size:"sm",onClick:R,children:[e.jsx(Ve,{className:"mr-1 h-3 w-3"}),g("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:o.paths.map((k,M)=>e.jsxs("div",{className:"rounded-lg border p-3 space-y-2",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(he,{value:k.path,onChange:O=>U(M,"path",O.target.value),placeholder:g("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(mt,{value:k.protocol,onValueChange:O=>U(M,"protocol",O),children:[e.jsx(ht,{children:e.jsx(pt,{})}),e.jsxs(xt,{children:[e.jsx(De,{value:"anthropic",children:g("modelManagement.protocolAnthropic")}),e.jsx(De,{value:"openai-auto",children:g("modelManagement.protocolOpenAI")})]})]})]}),o.paths.length>1&&e.jsx(P,{type:"button",variant:"ghost",size:"sm",onClick:()=>F(M),className:"text-destructive",children:e.jsx(Be,{className:"h-4 w-4"})})]}),M===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:g("modelManagement.endpointPathHint")})]},M))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ut,{id:"enabled",checked:o.enabled,onCheckedChange:k=>h({...o,enabled:k})}),e.jsx(Z,{htmlFor:"enabled",children:g("modelManagement.endpointEnabled")})]}),!a&&e.jsx("div",{className:"rounded-lg border border-blue-200 bg-blue-50 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:g("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 p-6 border-t",children:[e.jsx(P,{variant:"outline",className:"flex-1",onClick:c,disabled:B,children:g("common.cancel")}),e.jsx(P,{className:"flex-1",onClick:z,disabled:B,children:g(B?"common.saving":a?"common.save":"common.create")})]})]})})]}):null}export{ws as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as r,a as s,ah as n}from"./index-
|
|
1
|
+
import{j as r,a as s,ah as n}from"./index-UV1Qa96f.js";const l=n("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 shadow-sm",{variants:{variant:{default:"border-primary/20 bg-primary/10 text-primary hover:bg-primary/15 dark:border-primary/30 dark:bg-primary/20 dark:text-primary-foreground",secondary:"border-slate-200 bg-slate-100 text-slate-700 hover:bg-slate-200 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-300",destructive:"border-red-200 bg-gradient-to-r from-red-50 to-red-100 text-red-700 hover:from-red-100 hover:to-red-150 dark:border-red-800 dark:from-red-950 dark:to-red-900 dark:text-red-300",outline:"border-slate-300 bg-transparent text-slate-600 hover:bg-slate-50 dark:border-slate-600 dark:text-slate-400 dark:hover:bg-slate-800",success:"border-emerald-200 bg-gradient-to-r from-emerald-50 to-emerald-100 text-emerald-700 hover:from-emerald-100 hover:to-emerald-150 dark:border-emerald-800 dark:from-emerald-950 dark:to-emerald-900 dark:text-emerald-300",warning:"border-amber-200 bg-gradient-to-r from-amber-50 to-amber-100 text-amber-700 hover:from-amber-100 hover:to-amber-150 dark:border-amber-800 dark:from-amber-950 dark:to-amber-900 dark:text-amber-300",info:"border-cyan-200 bg-gradient-to-r from-cyan-50 to-cyan-100 text-cyan-700 hover:from-cyan-100 hover:to-cyan-150 dark:border-cyan-800 dark:from-cyan-950 dark:to-cyan-900 dark:text-cyan-300",purple:"border-violet-200 bg-gradient-to-r from-violet-50 to-violet-100 text-violet-700 hover:from-violet-100 hover:to-violet-150 dark:border-violet-800 dark:from-violet-950 dark:to-violet-900 dark:text-violet-300",pink:"border-pink-200 bg-gradient-to-r from-pink-50 to-pink-100 text-pink-700 hover:from-pink-100 hover:to-pink-150 dark:border-pink-800 dark:from-pink-950 dark:to-pink-900 dark:text-pink-300"}},defaultVariants:{variant:"default"}});function m({className:e,variant:t,...a}){return r.jsx("div",{className:s(l({variant:t}),e),...a})}function f({icon:e,title:t,description:a,badge:o,actions:d,className:i}){return r.jsxs("div",{className:s("flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",i),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-lg bg-primary/10 text-primary",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-tight",children:t}),o&&r.jsx(m,{variant:"secondary",children:o})]}),a&&r.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:a})]})]}),d&&r.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:d})]})}export{m as B,f as P};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s,a as d}from"./index-
|
|
1
|
+
import{j as s,a as d}from"./index-UV1Qa96f.js";import{C as m,b as l,c as i,d as j,a as f}from"./card-C20_HqC6.js";function p({title:a,description:e,actions:r,className:n,contentClassName:x,children:c}){const t=a||e||r;return s.jsxs(m,{className:n,children:[t&&s.jsxs(l,{className:"flex flex-row items-start justify-between space-y-0",children:[s.jsxs("div",{className:"space-y-1.5",children:[typeof a=="string"?s.jsx(i,{className:"text-base",children:a}):a,e&&(typeof e=="string"?s.jsx(j,{children:e}):s.jsx("div",{className:"text-sm text-muted-foreground",children:e}))]}),r&&s.jsx("div",{className:"flex shrink-0 items-center gap-2",children:r})]}),s.jsx(f,{className:d(!t&&"pt-6",x),children:c})]})}export{p as P};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{c as te,u as xe,b as be,r as u,j as e,e as S,U as fe,L as Z,d as K}from"./index-UV1Qa96f.js";import{u as ee}from"./useApiQuery-C2OD7H7U.js";import{P as je}from"./PageHeader-xFKpGYn6.js";import{c as ye}from"./clipboard-CALi6bTW.js";import{I as f}from"./input-CBGvcnZr.js";import{L as l}from"./label-BqSverDm.js";import{C as F,a as H}from"./card-C20_HqC6.js";import{S as L}from"./switch-ODrypdNp.js";import{S as ve,a as Ne,b as Pe,c as ke,d as we}from"./select-C8rWWJbl.js";import{C as Ce}from"./copy-CUEQDKMx.js";/**
|
|
2
|
+
* @license lucide-react v0.344.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const I=te("AlertCircle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);/**
|
|
7
|
+
* @license lucide-react v0.344.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const Le=te("Shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]),Re=[{value:"fatal",labelKey:"fatal"},{value:"error",labelKey:"error"},{value:"warn",labelKey:"warn"},{value:"info",labelKey:"info"},{value:"debug",labelKey:"debug"},{value:"trace",labelKey:"trace"}];function Oe(){const{t}=xe(),{pushToast:p}=be(),b=ee(["config","info"],{url:"/api/config/info",method:"GET"}),j=ee(["auth","web"],{url:"/api/auth/web",method:"GET"}),[n,_]=u.useState(null),[V,se]=u.useState(""),[r,m]=u.useState({port:"",host:"",logRetentionDays:"",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:""}),[g,G]=u.useState({}),[O,Q]=u.useState(!1),[z,W]=u.useState(!1),[U,$]=u.useState(!1),[d,J]=u.useState(null),[i,R]=u.useState({enabled:!1,username:"",password:"",confirmPassword:""}),[q,T]=u.useState({}),[B,X]=u.useState(!1),ae=u.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]),Y=u.useMemo(()=>i.enabled?d!=null&&d.hasPassword?i.username.trim()!==((d==null?void 0:d.username)??""):!0:!1,[i.enabled,i.username,d]);u.useEffect(()=>{var s,a,c,h,x,N,P,k,w,y,A;if(b.data){_(b.data.config),se(b.data.path);const M=b.data.config.storePayloads,E=v=>typeof v=="boolean"?v:typeof M=="boolean"?M:!0,o=b.data.config;m({port:String(o.port??((s=o.http)==null?void 0:s.port)??""),host:o.host??((a=o.http)==null?void 0:a.host)??"127.0.0.1",logRetentionDays:String(o.logRetentionDays??30),storeRequestPayloads:E(o.storeRequestPayloads),storeResponsePayloads:E(o.storeResponsePayloads),logLevel:o.logLevel??"info",requestLogging:o.requestLogging!==!1,responseLogging:o.responseLogging??o.requestLogging!==!1,bodyLimitMb:(()=>{const v=o.bodyLimit;return typeof v=="number"&&Number.isFinite(v)&&v>0?String(Math.max(1,Math.round(v/(1024*1024)))):"10"})(),enableRoutingFallback:o.enableRoutingFallback===!0,httpEnabled:((c=o.http)==null?void 0:c.enabled)!==!1,httpPort:String(((h=o.http)==null?void 0:h.port)??o.port??4100),httpHost:((x=o.http)==null?void 0:x.host)??o.host??"127.0.0.1",httpsEnabled:((N=o.https)==null?void 0:N.enabled)===!0,httpsPort:String(((P=o.https)==null?void 0:P.port)??4443),httpsHost:((k=o.https)==null?void 0:k.host)??o.host??"127.0.0.1",httpsKeyPath:((w=o.https)==null?void 0:w.keyPath)??"",httpsCertPath:((y=o.https)==null?void 0:y.certPath)??"",httpsCaPath:((A=o.https)==null?void 0:A.caPath)??""})}},[b.data]),u.useEffect(()=>{j.data&&(J(j.data),R({enabled:j.data.enabled,username:j.data.username??"",password:"",confirmPassword:""}),T({}))},[j.data]),u.useEffect(()=>{b.isError&&b.error&&p({title:t("settings.toast.loadFailure",{message:b.error.message}),variant:"error"})},[b.isError,b.error,p,t]),u.useEffect(()=>{j.isError&&j.error&&p({title:t("settings.toast.authLoadFailure",{message:j.error.message}),variant:"error"})},[j.isError,j.error,p,t]);const D=s=>a=>{m(c=>({...c,[s]:a}))},re=()=>{const s={};if(!r.httpEnabled&&!r.httpsEnabled&&(s.protocol="至少需要启用 HTTP 或 HTTPS 协议"),r.httpEnabled){const x=Number(r.httpPort);(!Number.isFinite(x)||x<1||x>65535)&&(s.httpPort="HTTP 端口必须在 1-65535 之间")}if(r.httpsEnabled){const x=Number(r.httpsPort);(!Number.isFinite(x)||x<1||x>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 c=Number(r.logRetentionDays);(!Number.isFinite(c)||c<1||c>365)&&(s.logRetentionDays=t("settings.validation.retention"));const h=Number(r.bodyLimitMb);return(!Number.isFinite(h)||h<1||h>2048)&&(s.bodyLimitMb=t("settings.validation.bodyLimit")),G(s),Object.keys(s).length===0},ne=()=>{const s={},a=i.username.trim(),c=d?a!==(d.username??""):!0,h=i.enabled&&(!(d!=null&&d.hasPassword)||c);return i.enabled&&!a&&(s.username=t("settings.auth.validation.username")),i.password&&i.password.length<6&&(s.password=t("settings.auth.validation.minLength")),h&&!i.password&&(s.password=t("settings.auth.validation.passwordRequired")),(i.password||i.confirmPassword)&&i.password!==i.confirmPassword&&(s.confirmPassword=t("settings.auth.validation.confirmMismatch")),T(s),Object.keys(s).length===0},oe=async()=>{var s,a,c,h,x,N,P,k,w,y,A,M;if(!n){p({title:t("settings.toast.loadFailure",{message:t("settings.toast.missingConfig")}),variant:"error"});return}if(re()){Q(!0);try{const E=Number(r.port),o=Number(r.logRetentionDays),v=Number(r.bodyLimitMb),C={...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:E,host:r.host.trim()||void 0,logRetentionDays:o,storeRequestPayloads:r.storeRequestPayloads,storeResponsePayloads:r.storeResponsePayloads,logLevel:r.logLevel,requestLogging:r.requestLogging,responseLogging:r.responseLogging,bodyLimit:Math.max(1,Math.floor(v*1024*1024)),enableRoutingFallback:r.enableRoutingFallback},{webAuth:Ee,...ge}=C;await K.put("/api/config",ge),_({...C,webAuth:n.webAuth});const ue=((s=n.http)==null?void 0:s.enabled)!==((a=C.http)==null?void 0:a.enabled)||((c=n.http)==null?void 0:c.port)!==((h=C.http)==null?void 0:h.port)||((x=n.https)==null?void 0:x.enabled)!==((N=C.https)==null?void 0:N.enabled)||((P=n.https)==null?void 0:P.port)!==((k=C.https)==null?void 0:k.port)||((w=n.https)==null?void 0:w.keyPath)!==((y=C.https)==null?void 0:y.keyPath)||((A=n.https)==null?void 0:A.certPath)!==((M=C.https)==null?void 0:M.certPath);p(ue?{title:"配置已保存!请执行 cc-gw restart --daemon 重启服务使协议配置生效",variant:"success"}:{title:t("settings.toast.saveSuccess"),variant:"success"}),b.refetch()}catch(E){p({title:t("settings.toast.saveFailure",{message:E instanceof Error?E.message:"unknown"}),variant:"error"})}finally{Q(!1)}}},ie=()=>{var s,a,c,h,x,N,P,k,w;n&&(m({port:String(n.port??""),host:n.host??"",logRetentionDays:String(n.logRetentionDays??30),storeRequestPayloads:typeof n.storeRequestPayloads=="boolean"?n.storeRequestPayloads:typeof n.storePayloads=="boolean"?n.storePayloads:!0,storeResponsePayloads:typeof n.storeResponsePayloads=="boolean"?n.storeResponsePayloads:typeof n.storePayloads=="boolean"?n.storePayloads:!0,logLevel:n.logLevel??"info",requestLogging:n.requestLogging!==!1,responseLogging:n.responseLogging??n.requestLogging!==!1,bodyLimitMb:(()=>{const y=n.bodyLimit;return typeof y=="number"&&Number.isFinite(y)&&y>0?String(Math.max(1,Math.round(y/(1024*1024)))):"10"})(),enableRoutingFallback:n.enableRoutingFallback===!0,httpEnabled:((s=n.http)==null?void 0:s.enabled)!==!1,httpPort:String(((a=n.http)==null?void 0:a.port)??n.port??4100),httpHost:((c=n.http)==null?void 0:c.host)??n.host??"127.0.0.1",httpsEnabled:((h=n.https)==null?void 0:h.enabled)===!0,httpsPort:String(((x=n.https)==null?void 0:x.port)??4443),httpsHost:((N=n.https)==null?void 0:N.host)??n.host??"127.0.0.1",httpsKeyPath:((P=n.https)==null?void 0:P.keyPath)??"",httpsCertPath:((k=n.https)==null?void 0:k.certPath)??"",httpsCaPath:((w=n.https)==null?void 0:w.caPath)??""}),G({}))},le=async()=>{var s;if(ne()){X(!0);try{const a={enabled:i.enabled,username:i.username.trim()||void 0};i.password&&(a.password=i.password);const h=(s=(await K.post("/api/auth/web",a)).data)==null?void 0:s.auth;h&&(J(h),R({enabled:h.enabled,username:h.username??"",password:"",confirmPassword:""}),T({})),p({title:t("settings.auth.toast.success"),variant:"success"}),j.refetch()}catch(a){const c=a instanceof Error?a.message:"unknown";p({title:t("settings.auth.toast.failure",{message:c}),variant:"error"})}finally{X(!1)}}},de=()=>{d&&(R({enabled:d.enabled,username:d.username??"",password:"",confirmPassword:""}),T({}))},ce=async()=>{if(!V){p({title:t("settings.toast.copyFailure",{message:t("settings.file.unknown")}),variant:"error"});return}try{await ye(V),p({title:t("settings.toast.copySuccess"),variant:"success"})}catch(s){p({title:t("settings.toast.copyFailure",{message:s instanceof Error?s.message:"unknown"}),variant:"error"})}},he=async()=>{W(!0);try{const a=(await K.post("/api/logs/cleanup")).data.deleted??0;p({title:a>0?t("settings.toast.cleanupSuccess",{count:a}):t("settings.toast.cleanupNone"),variant:"success"})}catch(s){p({title:t("settings.toast.cleanupFailure",{message:s instanceof Error?s.message:"unknown"}),variant:"error"})}finally{W(!1)}},me=async()=>{$(!0);try{const s=await K.post("/api/logs/clear"),{deleted:a,metricsCleared:c}=s.data;p({title:t("settings.toast.clearAllSuccess",{logs:a,metrics:c}),variant:"success"})}catch(s){p({title:t("settings.toast.clearAllFailure",{message:s instanceof Error?s.message:"unknown"}),variant:"error"})}finally{$(!1)}},pe=b.isPending||!n&&b.isFetching;return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(je,{icon:e.jsx(fe,{className:"h-5 w-5","aria-hidden":"true"}),title:t("settings.title"),description:t("settings.description"),actions:n?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",onClick:ie,disabled:O,children:t("common.actions.reset")}),e.jsx(S,{onClick:()=>void oe(),disabled:O,children:t(O?"common.actions.saving":"common.actions.save")})]}):null}),pe?e.jsx(F,{children:e.jsx(H,{className:"flex min-h-[220px] items-center justify-center",children:e.jsx(Z,{})})}):n?e.jsxs(e.Fragment,{children:[e.jsx(F,{children:e.jsxs(H,{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(l,{children:t("settings.fields.port")}),e.jsx(f,{type:"number",min:1,max:65535,value:r.port,onChange:s=>D("port")(s.target.value),"aria-invalid":!!g.port}),g.port&&e.jsx("p",{className:"text-xs text-destructive",children:g.port})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.fields.host")}),e.jsx(f,{value:r.host,onChange:s=>D("host")(s.target.value),placeholder:t("settings.fields.hostPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.fields.retention")}),e.jsx(f,{type:"number",min:1,max:365,value:r.logRetentionDays,onChange:s=>D("logRetentionDays")(s.target.value),"aria-invalid":!!g.logRetentionDays}),g.logRetentionDays&&e.jsx("p",{className:"text-xs text-destructive",children:g.logRetentionDays})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.fields.bodyLimit")}),e.jsx(f,{type:"number",min:1,max:2048,value:r.bodyLimitMb,onChange:s=>D("bodyLimitMb")(s.target.value),"aria-invalid":!!g.bodyLimitMb}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.fields.bodyLimitHint")}),g.bodyLimitMb&&e.jsx("p",{className:"text-xs text-destructive",children:g.bodyLimitMb})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.fields.logLevel")}),e.jsxs(ve,{value:r.logLevel,onValueChange:s=>m(a=>({...a,logLevel:s})),children:[e.jsx(Ne,{children:e.jsx(Pe,{})}),e.jsx(ke,{children:Re.map(s=>e.jsx(we,{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-lg border p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{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(L,{checked:r.storeRequestPayloads,onCheckedChange:s=>m(a=>({...a,storeRequestPayloads:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{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(L,{checked:r.storeResponsePayloads,onCheckedChange:s=>m(a=>({...a,storeResponsePayloads:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{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(L,{checked:r.requestLogging,onCheckedChange:s=>m(a=>({...a,requestLogging:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{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(L,{checked:r.responseLogging,onCheckedChange:s=>m(a=>({...a,responseLogging:s}))})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-800 dark:bg-amber-950",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{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(L,{checked:r.enableRoutingFallback,onCheckedChange:s=>m(a=>({...a,enableRoutingFallback:s}))})]})]}),e.jsxs("div",{className:"md:col-span-2 rounded-lg border bg-muted/50 p-4",children:[e.jsx(l,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:t("settings.fields.defaults")}),e.jsx("p",{className:"mt-2 text-sm",children:ae??t("settings.defaults.none")})]})]})]})}),e.jsx(F,{children:e.jsxs(H,{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-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-800 dark:bg-amber-950",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(I,{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-md bg-amber-100 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")})]})]})}),g.protocol&&e.jsxs("div",{className:"rounded-lg border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",children:[e.jsx(I,{className:"inline h-4 w-4 mr-2"}),g.protocol]}),e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50/50 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(l,{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(L,{checked:r.httpEnabled,onCheckedChange:s=>m(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(l,{children:t("settings.protocol.http.port")}),e.jsx(f,{type:"number",min:1,max:65535,value:r.httpPort,onChange:s=>m(a=>({...a,httpPort:s.target.value})),"aria-invalid":!!g.httpPort}),g.httpPort&&e.jsx("p",{className:"text-xs text-destructive",children:g.httpPort})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.protocol.http.host")}),e.jsx(f,{value:r.httpHost,onChange:s=>m(a=>({...a,httpHost:s.target.value})),placeholder:"127.0.0.1"})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-green-200 bg-green-50/50 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(l,{className:"text-sm font-medium text-green-800 dark:text-green-200",children:t("settings.protocol.https.enable")}),e.jsx(Le,{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(L,{checked:r.httpsEnabled,onCheckedChange:s=>m(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(l,{children:t("settings.protocol.https.port")}),e.jsx(f,{type:"number",min:1,max:65535,value:r.httpsPort,onChange:s=>m(a=>({...a,httpsPort:s.target.value})),"aria-invalid":!!g.httpsPort}),g.httpsPort&&e.jsx("p",{className:"text-xs text-destructive",children:g.httpsPort})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.protocol.https.host")}),e.jsx(f,{value:r.httpsHost,onChange:s=>m(a=>({...a,httpsHost:s.target.value})),placeholder:"127.0.0.1"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.protocol.https.keyPath")}),e.jsx(f,{value:r.httpsKeyPath,onChange:s=>m(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(l,{children:t("settings.protocol.https.certPath")}),e.jsx(f,{value:r.httpsCertPath,onChange:s=>m(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(l,{children:t("settings.protocol.https.caPath")}),e.jsx(f,{value:r.httpsCaPath,onChange:s=>m(a=>({...a,httpsCaPath:s.target.value})),placeholder:"留空则不使用",className:"font-mono text-xs"})]}),e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50 p-4 dark:border-amber-800 dark:bg-amber-950",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(I,{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(F,{children:e.jsxs(H,{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")})]}),j.isPending&&!d?e.jsx("div",{className:"flex min-h-[120px] items-center justify-center",children:e.jsx(Z,{})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{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 bg-muted px-3 py-1",children:"/ui"}),e.jsx("span",{className:"rounded-full bg-muted px-3 py-1",children:"/api/*"}),e.jsx("span",{className:"rounded-full bg-muted px-3 py-1",children:"Cookie Session"})]})]}),e.jsx(L,{checked:i.enabled,onCheckedChange:s=>R(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(l,{children:t("settings.auth.username")}),e.jsx(f,{value:i.username,onChange:s=>R(a=>({...a,username:s.target.value})),placeholder:t("settings.auth.usernamePlaceholder")}),q.username&&e.jsx("p",{className:"text-xs text-destructive",children:q.username})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.auth.password")}),e.jsx(f,{type:"password",value:i.password,disabled:!i.enabled,onChange:s=>R(a=>({...a,password:s.target.value})),placeholder:t("settings.auth.passwordPlaceholder")}),q.password?e.jsx("p",{className:"text-xs text-destructive",children:q.password}):e.jsx("p",{className:"text-xs text-muted-foreground",children:t(Y?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:t("settings.auth.confirmPassword")}),e.jsx(f,{type:"password",value:i.confirmPassword,disabled:!i.enabled,onChange:s=>R(a=>({...a,confirmPassword:s.target.value})),placeholder:t("settings.auth.confirmPasswordPlaceholder")}),q.confirmPassword&&e.jsx("p",{className:"text-xs text-destructive",children:q.confirmPassword})]})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"rounded-lg border bg-card 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-md 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-lg border bg-muted/50 p-4 text-xs text-muted-foreground",children:t(Y?"settings.auth.passwordHintRequired":"settings.auth.passwordHintOptional")})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-3",children:[e.jsx(S,{onClick:()=>void le(),disabled:B,children:t(B?"common.actions.saving":"settings.auth.actions.save")}),e.jsx(S,{variant:"outline",onClick:de,disabled:B,children:t("common.actions.reset")})]})]})]})}),e.jsx(F,{children:e.jsxs(H,{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(S,{variant:"outline",size:"sm",onClick:()=>void ce(),children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"}),t("common.actions.copy")]})]}),e.jsx("code",{className:"block break-all rounded-lg border bg-muted px-4 py-3 text-xs",children:V||t("settings.file.unknown")})]})}),e.jsx(F,{children:e.jsxs(H,{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:"flex flex-wrap gap-3",children:[e.jsx(S,{variant:"outline",onClick:()=>void he(),disabled:z,className:"border-destructive/50 text-destructive hover:bg-destructive/10",children:t(z?"common.actions.cleaning":"common.actions.cleanup")}),e.jsx(S,{variant:"destructive",onClick:()=>void me(),disabled:U,children:t(U?"settings.cleanup.clearingAll":"settings.cleanup.clearAll")})]}),e.jsx("p",{className:"text-xs text-destructive",children:t("settings.cleanup.clearAllWarning")})]})})]}):e.jsx(F,{children:e.jsx(H,{className:"pt-6",children:e.jsx("p",{className:"text-sm font-medium text-destructive",children:t("settings.toast.missingConfig")})})})]})}export{Oe as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,j as t,a as d,ah as n}from"./index-
|
|
1
|
+
import{r as s,j as t,a as d,ah as n}from"./index-UV1Qa96f.js";const i=n("rounded-xl border bg-card text-card-foreground transition-all duration-200",{variants:{variant:{default:"shadow-sm hover:shadow-md",elevated:"shadow-md hover:shadow-lg",outline:"shadow-none border-2",ghost:"border-transparent shadow-none bg-transparent",interactive:"shadow-sm hover:shadow-lg hover:-translate-y-0.5 cursor-pointer"}},defaultVariants:{variant:"default"}}),l=s.forwardRef(({className:a,variant:e,...r},o)=>t.jsx("div",{ref:o,className:d(i({variant:e}),a),...r}));l.displayName="Card";const c=s.forwardRef(({className:a,...e},r)=>t.jsx("div",{ref:r,className:d("flex flex-col space-y-1.5 p-5",a),...e}));c.displayName="CardHeader";const m=s.forwardRef(({className:a,...e},r)=>t.jsx("div",{ref:r,className:d("text-lg font-semibold leading-none tracking-tight",a),...e}));m.displayName="CardTitle";const f=s.forwardRef(({className:a,...e},r)=>t.jsx("div",{ref:r,className:d("text-sm text-muted-foreground",a),...e}));f.displayName="CardDescription";const p=s.forwardRef(({className:a,...e},r)=>t.jsx("div",{ref:r,className:d("p-5 pt-0",a),...e}));p.displayName="CardContent";const x=s.forwardRef(({className:a,...e},r)=>t.jsx("div",{ref:r,className:d("flex items-center p-5 pt-0",a),...e}));x.displayName="CardFooter";export{l as C,p as a,c as b,m as c,f as d,x as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
async function n(t){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function")try{await navigator.clipboard.writeText(t);return}catch{}const e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.top="0",e.style.left="0",e.style.width="2em",e.style.height="2em",e.style.padding="0",e.style.border="none",e.style.outline="none",e.style.boxShadow="none",e.style.background="transparent",e.setAttribute("readonly",""),document.body.appendChild(e),e.select();try{if(!document.execCommand("copy"))throw new Error("execCommand copy failed")}finally{document.body.removeChild(e)}}export{n as c};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as J,r as i,y as K,j as n,z as Q,A as N,P as h,D as U,E as x,G as m,H as C,I as X,J as Y,M as Z,N as ee,O as te,Q as oe,T as ae,a as p,X as ne}from"./index-
|
|
1
|
+
import{c as J,r as i,y as K,j as n,z as Q,A as N,P as h,D as U,E as x,G as m,H as C,I as X,J as Y,M as Z,N as ee,O as te,Q as oe,T as ae,a as p,X as ne}from"./index-UV1Qa96f.js";/**
|
|
2
2
|
* @license lucide-react v0.344.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|