@chenpu17/cc-gw 0.6.2 → 0.6.4

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.
@@ -1,6 +0,0 @@
1
- import{c as f,u as v,a as j,r,j as e,d as o,W as k,m as i}from"./index-BoThpdfs.js";import{u as N}from"./useApiQuery-B6AV-yNf.js";import{P as w,a as d}from"./PageSection-D043B876.js";import"./Input-BLqaRoSo.js";import{B as b}from"./Button-BA3yKRV9.js";import{I as T}from"./info-XnK1Lt65.js";import{R as y}from"./refresh-cw-B-xip7Eo.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 E=f("Sparkles",[["path",{d:"m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z",key:"17u4zn"}],["path",{d:"M5 3v4",key:"bklmnn"}],["path",{d:"M19 17v4",key:"iiml17"}],["path",{d:"M3 5h4",key:"nem4j1"}],["path",{d:"M17 19h4",key:"lbex7p"}]]),I="0.6.2",_={version:I},L={VITE_BUILD_TIME:"2025-11-20T11:43:59.953Z",VITE_NODE_VERSION:"v22.16.0"};function m({items:t}){return t.length===0?null:e.jsx("dl",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-2",children:t.map(s=>e.jsxs("div",{className:"rounded-2xl border border-slate-200/50 bg-white p-4 shadow-sm shadow-slate-200/30 transition-all duration-200 hover:-translate-y-0.5 hover:border-slate-200/70 hover:shadow-md hover:shadow-slate-200/40 dark:border-slate-700/50 dark:bg-slate-900/80 dark:shadow-lg dark:shadow-slate-900/30 dark:hover:border-slate-600/70",children:[e.jsx("dt",{className:"text-xs font-semibold uppercase tracking-[0.14em] text-slate-500 dark:text-slate-400",children:s.label}),e.jsx("dd",{className:"mt-2 text-base font-semibold text-slate-900 dark:text-slate-100",children:s.value}),s.hint?e.jsx("p",{className:o(i,"mt-2 text-xs leading-relaxed"),children:s.hint}):null]},s.label))})}function D(){const{t}=v(),{pushToast:s}=j(),a=N(["status","gateway"],{url:"/api/status",method:"GET"},{staleTime:6e4});r.useEffect(()=>{a.isError&&a.error&&s({title:t("about.toast.statusError.title"),description:a.error.message,variant:"error"})},[a.isError,a.error,s,t]);const n=_.version,l=r.useMemo(()=>{const u=L,h=u.VITE_BUILD_TIME,g=u.VITE_NODE_VERSION;return{buildTime:h,nodeVersion:g}},[]),p=r.useMemo(()=>[{label:t("about.app.labels.name"),value:e.jsx("span",{className:"font-mono text-sm font-semibold text-slate-900 dark:text-slate-100",children:"cc-gw"})},{label:t("about.app.labels.version"),value:e.jsxs("span",{className:"font-mono text-sm font-semibold text-blue-700 dark:text-blue-200",children:["v",n]})},{label:t("about.app.labels.buildTime"),value:l.buildTime,hint:t("about.app.hint.buildTime")},{label:t("about.app.labels.node"),value:e.jsx("span",{className:"font-mono text-sm text-slate-800 dark:text-slate-200",children:l.nodeVersion})}],[n,l.buildTime,l.nodeVersion,t]),c=r.useMemo(()=>a.data?[{label:t("about.status.labels.host"),value:a.data.host??"127.0.0.1"},{label:t("about.status.labels.port"),value:a.data.port.toLocaleString()},{label:t("about.status.labels.providers"),value:a.data.providers.toLocaleString()},{label:t("about.status.labels.active"),value:(a.data.activeRequests??0).toLocaleString(),hint:t("about.status.hint.active")}]:[],[a.data,t]),x=()=>{s({title:t("about.toast.updatesPlanned"),variant:"info"})};return e.jsxs("div",{className:"space-y-8",children:[e.jsx(w,{icon:e.jsx(T,{className:"h-6 w-6","aria-hidden":"true"}),title:t("about.title"),description:t("about.description"),badge:`v${n}`,actions:e.jsx(b,{variant:"primary",icon:e.jsx(E,{className:"h-4 w-4","aria-hidden":"true"}),onClick:x,children:t("about.support.actions.checkUpdates")})}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(d,{title:t("about.app.title"),description:t("about.app.subtitle"),className:"h-full",contentClassName:"gap-4",children:e.jsx(m,{items:p})}),e.jsx(d,{title:t("about.status.title"),description:t("about.status.subtitle"),className:"h-full",contentClassName:"gap-4",actions:e.jsx(b,{variant:"subtle",size:"sm",icon:e.jsx(y,{className:"h-4 w-4","aria-hidden":"true"}),onClick:()=>a.refetch(),loading:a.isFetching,children:a.isFetching?t("common.actions.refreshing"):t("common.actions.refresh")}),children:a.isLoading?e.jsxs("div",{className:"flex h-36 flex-col items-center justify-center gap-3 text-center",children:[e.jsx("div",{className:"h-10 w-10 animate-spin rounded-full border-[3px] border-blue-500/30 border-t-blue-600 dark:border-blue-400/20 dark:border-t-blue-300"}),e.jsx("p",{className:o(i,"text-sm"),children:t("about.status.loading")})]}):c.length>0?e.jsx(m,{items:c}):e.jsxs("div",{className:"flex h-36 flex-col items-center justify-center gap-2 rounded-2xl border border-dashed border-slate-200/60 bg-white p-6 text-center shadow-inner dark:border-slate-700/60 dark:bg-slate-900/60",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:t("about.status.empty")}),e.jsx("p",{className:o(i,"text-xs"),children:t("common.actions.refresh")})]})})]}),e.jsx(d,{title:t("about.support.title"),description:e.jsxs("span",{className:"space-y-1",children:[e.jsx("span",{className:"block text-sm font-semibold text-blue-600 dark:text-blue-300",children:t("about.support.subtitle")}),e.jsx("span",{children:t("about.support.description")})]}),className:"relative overflow-hidden",contentClassName:"gap-6",children:e.jsxs("div",{className:"flex flex-col gap-4 rounded-3xl border border-slate-200/50 bg-white p-6 shadow-lg shadow-slate-200/30 backdrop-blur-md dark:border-slate-700/50 dark:bg-slate-900/80 dark:shadow-slate-900/40",children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-4",children:[e.jsx("div",{className:"grid h-12 w-12 place-items-center rounded-2xl bg-gradient-to-br from-blue-500/20 to-indigo-500/20 text-blue-600 shadow-inner dark:text-blue-200",children:e.jsx(k,{className:"h-6 w-6","aria-hidden":"true"})}),e.jsx("p",{className:o(i,"text-sm leading-6"),children:t("about.support.tip")})]}),e.jsx("code",{className:"inline-flex items-center gap-2 self-start rounded-full border border-blue-200/50 bg-blue-50/80 px-4 py-2 text-xs font-semibold tracking-wide text-blue-700 shadow-sm dark:border-blue-500/30 dark:bg-blue-900/30 dark:text-blue-200",children:"~/.cc-gw/config.json"})]})})]})}export{D as default};
@@ -1,16 +0,0 @@
1
- import{c as T,u as W,a as _,r as d,j as e,L as X,P as Y,d as t,b as K,m as r,J as m,H as Z,k as ee,l as ae,f as se,h as te}from"./index-BoThpdfs.js";import{E as le}from"./index-ChDuX9Yn.js";import{u as w}from"./useApiQuery-B6AV-yNf.js";import{P as ie,a as q}from"./PageSection-D043B876.js";import{F as I}from"./FormField-DdAleV-5.js";import{I as re}from"./Input-BLqaRoSo.js";import{B as C}from"./Button-BA3yKRV9.js";import{S as ne}from"./StatusBadge--UpDQrE2.js";import{C as ce}from"./copy-eJjQpBgC.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 de=T("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
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 oe=T("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
12
- * @license lucide-react v0.344.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const pe=T("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]),me=[{value:1,labelKey:"apiKeys.analytics.range.today"},{value:7,labelKey:"apiKeys.analytics.range.week"},{value:30,labelKey:"apiKeys.analytics.range.month"}];function ve(){const{t:a}=W(),{pushToast:i}=_(),[k,x]=d.useState(!1),[u,y]=d.useState(""),[D,v]=d.useState(""),[h,L]=d.useState(null),[F,A]=d.useState(null),[o,z]=d.useState(7),g=w(["api-keys"],{url:"/api/keys",method:"GET"}),j=w(["api-keys","overview",o],{url:"/api/stats/api-keys/overview",method:"GET",params:{days:o}}),f=w(["api-keys","usage",o],{url:"/api/stats/api-keys/usage",method:"GET",params:{days:o,limit:10}}),N=g.data??[],p=j.data,c=f.data??[],B=N.some(s=>s.isWildcard),H=p?p.totalKeys.toLocaleString():"–",R=p?p.enabledKeys.toLocaleString():"–",V=p?p.activeKeys.toLocaleString():"–",P=async()=>{var s,l;if(!u.trim()){i({title:a("apiKeys.errors.nameRequired"),variant:"error"});return}try{const n=await K.post("/api/keys",{name:u.trim(),description:D.trim()||void 0});L(n.data),x(!1),y(""),v(""),g.refetch(),j.refetch(),f.refetch(),i({title:a("apiKeys.toast.keyCreated"),variant:"success"})}catch(n){i({title:a("apiKeys.toast.createFailure",{message:((l=(s=n.response)==null?void 0:s.data)==null?void 0:l.error)||n.message}),variant:"error"})}},G=async(s,l)=>{var n,b;try{await K.patch(`/api/keys/${s}`,{enabled:!l}),g.refetch(),j.refetch(),i({title:a("apiKeys.toast.keyUpdated"),variant:"success"})}catch(M){i({title:a("apiKeys.toast.updateFailure",{message:((b=(n=M.response)==null?void 0:n.data)==null?void 0:b.error)||M.message}),variant:"error"})}},Q=async s=>{var l,n;if(confirm(a("apiKeys.confirmDelete"))){A(s);try{await K.delete(`/api/keys/${s}`),g.refetch(),j.refetch(),f.refetch(),i({title:a("apiKeys.toast.keyDeleted"),variant:"success"})}catch(b){i({title:a("apiKeys.toast.deleteFailure",{message:((n=(l=b.response)==null?void 0:l.data)==null?void 0:n.error)||b.message}),variant:"error"})}finally{A(null)}}},U=s=>{navigator.clipboard.writeText(s),i({title:a("apiKeys.toast.keyCopied"),variant:"success"})},E=s=>s?new Date(s).toLocaleString():a("common.noData"),$=d.useMemo(()=>{const s=c.map(l=>l.apiKeyName??a("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},grid:{left:60,right:20,top:40,bottom:40},xAxis:{type:"category",data:s,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:a("apiKeys.analytics.requestsSeries"),type:"bar",data:c.map(l=>l.requests),itemStyle:{color:"#2563eb"}}]}},[c,a]),J=d.useMemo(()=>{const s=c.map(l=>l.apiKeyName??a("apiKeys.analytics.unknownKey"));return{tooltip:{trigger:"axis"},legend:{data:[a("apiKeys.analytics.tokens.input"),a("apiKeys.analytics.tokens.output")]},grid:{left:60,right:20,top:50,bottom:40},xAxis:{type:"category",data:s,axisLabel:{interval:0,rotate:20}},yAxis:{type:"value"},series:[{name:a("apiKeys.analytics.tokens.input"),type:"bar",stack:"tokens",itemStyle:{color:"#22c55e"},data:c.map(l=>l.inputTokens)},{name:a("apiKeys.analytics.tokens.output"),type:"bar",stack:"tokens",itemStyle:{color:"#0ea5e9"},data:c.map(l=>l.outputTokens)}]}},[c,a]);return g.isLoading?e.jsx(X,{}):e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(ie,{icon:e.jsx(Y,{className:"h-6 w-6","aria-hidden":"true"}),title:a("apiKeys.title"),description:a("apiKeys.description"),actions:e.jsx(C,{onClick:()=>x(!0),variant:"primary",size:"lg",icon:e.jsx(oe,{className:"h-4 w-4","aria-hidden":"true"}),className:"rounded-full",children:a("apiKeys.createNew")})}),e.jsxs(q,{title:a("apiKeys.analytics.title"),description:a("apiKeys.analytics.description",{days:o}),actions:e.jsx("div",{className:"flex items-center gap-2 rounded-full bg-white/70 px-2 py-1 shadow-sm shadow-slate-200/60 ring-1 ring-slate-200/60 backdrop-blur dark:bg-slate-900/70 dark:ring-slate-700/60",children:me.map(s=>{const l=o===s.value;return e.jsx("button",{type:"button",onClick:()=>z(s.value),className:t("inline-flex h-8 items-center rounded-full px-3 text-xs font-semibold transition",l?"bg-blue-600 text-white shadow-sm shadow-blue-500/20":"text-slate-600 hover:bg-white/80 dark:text-slate-300 dark:hover:bg-slate-800/60"),children:a(s.labelKey)},s.value)})}),contentClassName:"gap-6",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(S,{label:a("apiKeys.analytics.cards.total"),value:H}),e.jsx(S,{label:a("apiKeys.analytics.cards.enabled"),value:R}),e.jsx(S,{label:a("apiKeys.analytics.cards.active",{days:o}),value:V})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(O,{title:a("apiKeys.analytics.charts.requests"),loading:f.isLoading,empty:c.length===0,emptyText:a("apiKeys.analytics.empty"),option:$}),e.jsx(O,{title:a("apiKeys.analytics.charts.tokens"),loading:f.isLoading,empty:c.length===0,emptyText:a("apiKeys.analytics.empty"),option:J})]})]}),e.jsx(q,{title:a("apiKeys.list.title"),description:B?a("apiKeys.wildcardHint"):void 0,contentClassName:"gap-4",children:N.length===0?e.jsx("div",{className:t(m,"p-6 text-center"),children:e.jsx("p",{className:t(r,"text-sm"),children:a("apiKeys.list.empty")})}):e.jsx("div",{className:"grid gap-4",children:N.map(s=>{const l=(s.totalInputTokens+s.totalOutputTokens).toLocaleString();return e.jsx("div",{className:t(m,"space-y-4"),children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-slate-50",children:s.name}),s.isWildcard?e.jsx("span",{className:"inline-flex items-center rounded-full bg-purple-500/10 px-3 py-1 text-xs font-semibold text-purple-600 dark:bg-purple-500/20 dark:text-purple-200",children:a("apiKeys.wildcard")}):null,e.jsx(ne,{variant:s.enabled?"success":"info",children:s.enabled?a("apiKeys.status.enabled"):a("apiKeys.status.disabled")})]}),e.jsx("code",{className:"inline-flex items-center rounded-2xl bg-slate-900/90 px-4 py-2 font-mono text-sm text-slate-50 shadow-inner shadow-slate-900/30 dark:bg-slate-800/80",children:s.isWildcard?a("apiKeys.wildcard"):s.maskedKey??"********"}),s.isWildcard?e.jsx("p",{className:t(r,"text-sm text-purple-600 dark:text-purple-200"),children:a("apiKeys.wildcardHint")}):s.description?e.jsx("p",{className:t(r,"whitespace-pre-wrap text-sm"),children:s.description}):null,e.jsxs("div",{className:"grid gap-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{className:t(r,"flex flex-col gap-1"),children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("apiKeys.created")}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-100",children:E(s.createdAt)})]}),e.jsxs("div",{className:t(r,"flex flex-col gap-1"),children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("apiKeys.lastUsed")}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-100",children:E(s.lastUsedAt)})]}),e.jsxs("div",{className:t(r,"flex flex-col gap-1"),children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("apiKeys.requestCount")}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-100",children:s.requestCount.toLocaleString()})]}),e.jsxs("div",{className:t(r,"flex flex-col gap-1"),children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("apiKeys.totalTokens")}),e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-100",children:l})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>G(s.id,s.enabled),className:t("inline-flex h-9 items-center rounded-full px-4 text-sm font-semibold transition",s.enabled?"bg-slate-200/80 text-slate-700 hover:bg-slate-300 dark:bg-slate-800/80 dark:text-slate-200 dark:hover:bg-slate-700/70":"bg-emerald-500 text-white shadow-sm shadow-emerald-500/30 hover:bg-emerald-500/90"),children:s.enabled?a("apiKeys.actions.disable"):a("apiKeys.actions.enable")}),s.isWildcard?null:e.jsx("button",{type:"button",onClick:()=>Q(s.id),disabled:F===s.id,className:"inline-flex h-9 w-9 items-center justify-center rounded-full text-red-500 transition hover:bg-red-500/10 disabled:opacity-50","aria-label":a("apiKeys.actions.delete"),children:e.jsx(pe,{className:"h-4 w-4","aria-hidden":"true"})})]})]})},s.id)})})}),k&&e.jsx("div",{className:"fixed inset-0 z-40 flex items-center justify-center bg-slate-950/60 p-4 backdrop-blur-sm",children:e.jsxs("div",{className:t(m,"w-full max-w-md space-y-5 p-6 shadow-xl shadow-slate-900/30 dark:shadow-black/40"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-xl font-semibold text-slate-900 dark:text-slate-50",children:a("apiKeys.createNew")}),e.jsx("p",{className:t(r,"text-sm"),children:a("apiKeys.createDescription")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(I,{label:a("apiKeys.keyNamePlaceholder"),required:!0,children:e.jsx(re,{value:u,onChange:s=>y(s.target.value),placeholder:a("apiKeys.keyNamePlaceholder"),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),P())}})}),e.jsx(I,{label:a("apiKeys.descriptionLabel"),children:e.jsx("textarea",{value:D,onChange:s=>v(s.target.value),placeholder:a("apiKeys.keyDescriptionPlaceholder"),className:"w-full rounded-2xl border border-slate-200/50 bg-white/90 px-4 py-3 text-sm text-slate-800 shadow-sm shadow-slate-200/30 transition-all duration-200 focus:border-blue-400/70 focus:bg-white focus:outline-none focus:ring-2 focus:ring-blue-400/20 focus:shadow-md focus:shadow-blue-200/40 dark:border-slate-700/50 dark:bg-slate-900/90 dark:text-slate-200 dark:shadow-lg dark:shadow-slate-900/30 dark:focus:border-blue-400/70 dark:focus:ring-blue-400/20 min-h-[96px] resize-none"})})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(C,{onClick:()=>{x(!1),y(""),v("")},variant:"subtle",className:"rounded-full",children:a("common.actions.cancel")}),e.jsx(C,{onClick:()=>void P(),variant:"primary",className:"rounded-full",children:a("apiKeys.createAction")})]})]})}),h&&e.jsx("div",{className:"fixed inset-0 z-40 flex items-center justify-center bg-slate-950/60 p-4 backdrop-blur-sm",children:e.jsxs("div",{className:t(m,"w-full max-w-md space-y-5 p-6 shadow-xl shadow-slate-900/30 dark:shadow-black/40"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"grid h-10 w-10 place-items-center rounded-full bg-emerald-500/20 text-emerald-600 dark:bg-emerald-500/30 dark:text-emerald-200",children:e.jsx(de,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("h2",{className:"text-xl font-semibold text-slate-900 dark:text-slate-50",children:a("apiKeys.keyCreated")})]}),e.jsx("p",{className:"text-sm font-medium text-amber-600 dark:text-amber-400",children:a("apiKeys.saveKeyWarning")}),e.jsx("div",{className:"rounded-2xl bg-slate-900/95 px-4 py-3 font-mono text-sm text-slate-50 shadow-inner shadow-slate-900/40 dark:bg-slate-800/90",children:h.key}),h.description?e.jsx("p",{className:t(r,"whitespace-pre-wrap text-sm"),children:h.description}):null,e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>U(h.key),className:t(Z,"h-10 rounded-full px-4"),children:[e.jsx(ce,{className:"h-4 w-4","aria-hidden":"true"}),a("common.actions.copy")]}),e.jsx("button",{type:"button",onClick:()=>L(null),className:t(ee,"h-10 rounded-full px-4"),children:a("common.actions.close")})]})]})})]})}function S({label:a,value:i}){return e.jsxs("div",{className:t(m,"p-6"),children:[e.jsx("p",{className:t(r,"text-xs font-semibold uppercase tracking-[0.18em]"),children:a}),e.jsx("p",{className:"mt-3 text-3xl font-semibold text-slate-900 dark:text-slate-50",children:i})]})}function O({title:a,option:i,loading:k,empty:x,emptyText:u}){const{t:y}=W();return e.jsxs("div",{className:t(m,"space-y-4 p-6"),children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-900 dark:text-slate-50",children:a}),k?e.jsx("div",{className:ae,children:e.jsx("span",{className:t(r,"text-sm"),children:y("common.loadingShort")})}):x?e.jsx("div",{className:se,children:e.jsx("span",{className:t(r,"text-sm"),children:u})}):e.jsx(le,{option:i,style:{height:280},notMerge:!0,lazyUpdate:!0,className:te})]})}export{ve as default};
@@ -1 +0,0 @@
1
- import{j as s,d as c,M as i,H as p,k as b}from"./index-BoThpdfs.js";function h({variant:n="subtle",size:o="md",children:a,loading:t,icon:e,className:l,disabled:r,...u}){const m={subtle:b,primary:p,danger:i}[n],x={sm:"h-8 px-3 text-xs",md:"h-10 px-4 text-sm",lg:"h-12 px-6 text-base"}[o];return s.jsx("button",{className:c(m,x,t&&"cursor-wait opacity-70",r&&"cursor-not-allowed opacity-50",l),disabled:r||t,...u,children:t?s.jsx("div",{className:"inline-block animate-spin rounded-full h-4 w-4 border-b-2 border-current"}):e?s.jsxs(s.Fragment,{children:[e,a]}):a})}export{h as B};
@@ -1,16 +0,0 @@
1
- import{c as O,u as q,a as te,r as h,b as se,t as ae,j as e,L as re,B,d as o,m as g,g as z,e as $,f as G,h as oe,l as _,s as le,i as M,k as ie,n as P}from"./index-BoThpdfs.js";import{E as ne}from"./index-ChDuX9Yn.js";import{P as de,a as H}from"./PageSection-D043B876.js";import{S as ce}from"./Input-BLqaRoSo.js";import{S as me}from"./StatusBadge--UpDQrE2.js";import{u as C}from"./useApiQuery-B6AV-yNf.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 D=O("Activity",[["path",{d:"M22 12h-4l-3 9L9 3l-3 9H2",key:"d5dnw9"}]]);/**
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 xe=O("Timer",[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]]);/**
12
- * @license lucide-react v0.344.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const he=O("TrendingUp",[["polyline",{points:"22 7 13.5 15.5 8.5 10.5 2 17",key:"126l90"}],["polyline",{points:"16 7 22 7 22 13",key:"kwv8wd"}]]);function w(t,a,s){return t==null?"-":`${t.toLocaleString(void 0,s)} ${a}`}function U(t){if(t==null)return"-";if(t<1024)return`${t} B`;const a=["KB","MB","GB","TB"];let s=t/1024,r=0;for(;s>=1024&&r<a.length-1;)s/=1024,r+=1;return`${s.toFixed(s>=100?0:s>=10?1:2)} ${a[r]}`}function ve(){var F;const{t}=q(),{pushToast:a}=te(),[s,r]=h.useState("all"),[n,L]=h.useState(!1),p=s==="all"?void 0:s,v=C(["stats","overview",s],{url:"/api/stats/overview",method:"GET",params:p?{endpoint:p}:void 0}),k=C(["stats","daily",14,s],{url:"/api/stats/daily",method:"GET",params:{days:14,...p?{endpoint:p}:{}}}),y=C(["stats","model",7,6,s],{url:"/api/stats/model",method:"GET",params:{days:7,limit:6,...p?{endpoint:p}:{}}}),S=C(["status"],{url:"/api/status",method:"GET"}),f=C(["db","info"],{url:"/api/db/info",method:"GET"}),Q=f.refetch??(async()=>{}),T=C(["logs","recent",s],{url:"/api/logs",method:"GET",params:{limit:5,...p?{endpoint:p}:{}}},{refetchInterval:3e4});h.useEffect(()=>{v.isError&&v.error&&a({title:t("dashboard.toast.overviewError"),description:v.error.message,variant:"error"})},[v.isError,v.error,a,t]),h.useEffect(()=>{k.isError&&k.error&&a({title:t("dashboard.toast.dailyError"),description:k.error.message,variant:"error"})},[k.isError,k.error,a,t]),h.useEffect(()=>{y.isError&&y.error&&a({title:t("dashboard.toast.modelError"),description:y.error.message,variant:"error"})},[y.isError,y.error,a,t]),h.useEffect(()=>{S.isError&&S.error&&a({title:t("dashboard.toast.statusError"),description:S.error.message,variant:"error"})},[S.isError,S.error,a,t]),h.useEffect(()=>{f.isError&&f.error&&a({title:t("dashboard.toast.dbError"),description:f.error.message,variant:"error"})},[f.isError,f.error,a,t]);const K=h.useCallback(async()=>{if(!n){L(!0);try{await se.post("/api/db/compact"),await Q(),a({title:t("dashboard.toast.compactSuccess.title"),description:t("dashboard.toast.compactSuccess.desc"),variant:"success"})}catch(d){const x=ae(d);a({title:t("dashboard.toast.compactError.title"),description:x.message,variant:"error"})}finally{L(!1)}}},[n,a,Q,t]);h.useEffect(()=>{T.isError&&T.error&&a({title:t("dashboard.toast.recentError"),description:T.error.message,variant:"error"})},[T.isError,T.error,a,t]);const i=v.data,j=k.data??[],c=y.data??[],A=S.data,I=f.data,V=((F=T.data)==null?void 0:F.items)??[],J=I?U(I.totalBytes??I.sizeBytes):"-",W=I?U(I.memoryRssBytes??0):"-",X=h.useMemo(()=>{const d=j.map(b=>b.date),x=t("dashboard.charts.barRequests"),l=t("dashboard.charts.lineInput"),u=t("dashboard.charts.lineOutput"),m=t("dashboard.charts.lineCacheRead"),N=t("dashboard.charts.lineCacheCreation");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"}},legend:{data:[x,l,u,m,N],textStyle:{color:"#64748b"}},grid:{left:60,right:40,top:60,bottom:60},xAxis:{type:"category",data:d,axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:{type:"value",axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},series:[{name:x,type:"bar",data:j.map(b=>b.requestCount),itemStyle:{color:"#3b82f6",borderRadius:[4,4,0,0]},emphasis:{itemStyle:{color:"#2563eb"}}},{name:l,type:"line",yAxisIndex:0,data:j.map(b=>b.inputTokens),smooth:!0,itemStyle:{color:"#10b981"},lineStyle:{width:3},symbol:"circle",symbolSize:6},{name:u,type:"line",yAxisIndex:0,data:j.map(b=>b.outputTokens),smooth:!0,itemStyle:{color:"#f59e0b"},lineStyle:{width:3},symbol:"circle",symbolSize:6},{name:m,type:"line",yAxisIndex:0,data:j.map(b=>b.cacheReadTokens),smooth:!0,itemStyle:{color:"#8b5cf6"},lineStyle:{width:3},symbol:"circle",symbolSize:6},{name:N,type:"line",yAxisIndex:0,data:j.map(b=>b.cacheCreationTokens),smooth:!0,itemStyle:{color:"#ec4899"},lineStyle:{width:3},symbol:"circle",symbolSize:6}]}},[j,t]),Y=h.useMemo(()=>{const d=c.map(m=>`${m.provider}/${m.model}`),x=t("dashboard.charts.barRequests"),l=t("dashboard.charts.lineInput"),u=t("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"}},legend:{data:[x,l,u],textStyle:{color:"#64748b"}},grid:{left:80,right:60,top:60,bottom:100},xAxis:{type:"category",data:d,axisLabel:{rotate:30,color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:[{type:"value",name:x,axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},{type:"value",name:t("dashboard.charts.axisTokens"),position:"right",axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}}],series:[{name:x,type:"bar",data:c.map(m=>m.requests),itemStyle:{color:"#6366f1",borderRadius:[4,4,0,0]},yAxisIndex:0},{name:l,type:"line",yAxisIndex:1,smooth:!0,data:c.map(m=>m.inputTokens??0),itemStyle:{color:"#10b981"},lineStyle:{width:3}},{name:u,type:"line",yAxisIndex:1,smooth:!0,data:c.map(m=>m.outputTokens??0),itemStyle:{color:"#f59e0b"},lineStyle:{width:3}}]}},[c,t]),Z=h.useMemo(()=>{const d=c.map(l=>`${l.provider}/${l.model}`),x=t("dashboard.charts.ttftLabel");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"},formatter(l){var N;if(!Array.isArray(l)||l.length===0)return"";const u=((N=l[0])==null?void 0:N.dataIndex)??0,m=c[u];return m?`<strong>${d[u]}</strong><br/>${x}: ${w(m.avgTtftMs,t("common.units.ms"))}`:""}},grid:{left:80,right:50,top:60,bottom:100},xAxis:{type:"category",data:d,axisLabel:{rotate:30,color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:{type:"value",name:t("dashboard.charts.ttftAxis"),axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},series:[{name:x,type:"bar",data:c.map(l=>l.avgTtftMs??0),itemStyle:{color:"#3b82f6",borderRadius:[4,4,0,0]}}]}},[c,t]),ee=h.useMemo(()=>{const d=c.map(l=>`${l.provider}/${l.model}`),x=t("dashboard.charts.tpotLabel");return{tooltip:{trigger:"axis",backgroundColor:"rgba(15, 23, 42, 0.9)",borderColor:"rgba(59, 130, 246, 0.3)",textStyle:{color:"#e2e8f0"},formatter(l){var N;if(!Array.isArray(l)||l.length===0)return"";const u=((N=l[0])==null?void 0:N.dataIndex)??0,m=c[u];return m?`<strong>${d[u]}</strong><br/>${x}: ${w(m.avgTpotMs,t("common.units.msPerToken"),{maximumFractionDigits:2})}`:""}},grid:{left:80,right:50,top:60,bottom:100},xAxis:{type:"category",data:d,axisLabel:{rotate:30,color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}}},yAxis:{type:"value",name:t("dashboard.charts.tpotAxis"),axisLabel:{color:"#64748b"},axisLine:{lineStyle:{color:"#334155"}},splitLine:{lineStyle:{color:"#1e293b"}}},series:[{name:x,type:"bar",data:c.map(l=>l.avgTpotMs??0),itemStyle:{color:"#f59e0b",borderRadius:[4,4,0,0]}}]}},[c,t]);return v.isPending||S.isPending||f.isPending?e.jsx(re,{}):e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(de,{icon:e.jsx(B,{className:"h-7 w-7","aria-hidden":"true"}),title:t("nav.dashboard"),description:t("dashboard.description"),actions:e.jsxs("div",{className:"flex items-center gap-4 rounded-2xl bg-white/90 px-4 py-3 shadow-lg shadow-slate-200/30 ring-1 ring-slate-200/40 backdrop-blur-lg dark:bg-slate-900/90 dark:shadow-xl dark:shadow-slate-900/30 dark:ring-slate-700/40",children:[e.jsx("label",{htmlFor:"dashboard-endpoint-filter",className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:t("dashboard.filters.endpoint")}),e.jsx("div",{className:"relative",children:e.jsx(ce,{id:"dashboard-endpoint-filter",value:s,onChange:d=>r(d.target.value),options:[{value:"all",label:t("dashboard.filters.endpointAll")},{value:"anthropic",label:t("dashboard.filters.endpointAnthropic")},{value:"openai",label:t("dashboard.filters.endpointOpenAI")}]})})]})}),A?e.jsxs("section",{className:o(z,"flex flex-wrap items-center gap-4 text-sm leading-relaxed animate-slide-up"),"aria-live":"polite",children:[e.jsxs("span",{className:o(le.success,"inline-flex items-center gap-2 rounded-full px-4 py-2 font-semibold"),children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-current shadow-lg","aria-hidden":"true"}),t("dashboard.status.listening",{host:A.host??"0.0.0.0",port:A.port})]}),e.jsx("span",{className:o(M.default,"font-semibold"),children:t("dashboard.status.providers",{value:A.providers.toLocaleString()})}),e.jsx("span",{className:o(M.primary,"font-semibold"),children:t("dashboard.status.todayRequests",{value:((i==null?void 0:i.today.requests)??0).toLocaleString()})}),e.jsx("span",{className:o(M.default,"font-semibold"),children:t("dashboard.status.active",{value:(A.activeRequests??0).toLocaleString()})}),e.jsx("span",{className:o(M.default,"font-semibold"),children:t("dashboard.status.dbSize",{value:J})}),e.jsx("span",{className:o(M.default,"font-semibold"),children:t("dashboard.status.memory",{value:W})}),e.jsx("button",{type:"button",onClick:K,disabled:n,className:o(ie,"h-9 rounded-full px-4 text-xs font-semibold",n?"cursor-wait opacity-70":""),children:t(n?"dashboard.actions.compacting":"dashboard.actions.compact")})]}):null,e.jsxs("section",{className:o(P.auto,"gap-4 sm:gap-6"),children:[e.jsx(E,{icon:e.jsx(D,{className:"h-5 w-5"}),title:t("dashboard.cards.todayRequests"),value:(i==null?void 0:i.today.requests)??0,suffix:t("common.units.request"),trend:"+12%",trendDirection:"up"}),e.jsx(E,{icon:e.jsx(he,{className:"h-5 w-5"}),title:t("dashboard.cards.todayInput"),value:(i==null?void 0:i.today.inputTokens)??0,suffix:t("common.units.token"),trend:"+8%",trendDirection:"up"}),e.jsx(E,{icon:e.jsx(D,{className:"h-5 w-5"}),title:t("dashboard.cards.todayCacheRead"),value:(i==null?void 0:i.today.cacheReadTokens)??0,suffix:t("common.units.token")}),e.jsx(E,{icon:e.jsx(D,{className:"h-5 w-5"}),title:t("dashboard.cards.todayCacheCreation"),value:(i==null?void 0:i.today.cacheCreationTokens)??0,suffix:t("common.units.token")}),e.jsx(E,{icon:e.jsx(B,{className:"h-5 w-5"}),title:t("dashboard.cards.todayOutput"),value:(i==null?void 0:i.today.outputTokens)??0,suffix:t("common.units.token"),trend:"+15%",trendDirection:"up"}),e.jsx(E,{icon:e.jsx(xe,{className:"h-5 w-5"}),title:t("dashboard.cards.avgLatency"),value:(i==null?void 0:i.today.avgLatencyMs)??0,suffix:t("common.units.ms"),trend:"-5%",trendDirection:"down"})]}),e.jsxs("div",{className:o(P.fixed[2],"gap-6 sm:gap-8"),children:[e.jsx(R,{title:t("dashboard.charts.requestsTitle"),description:t("dashboard.charts.requestsDesc"),loading:k.isPending,option:X,empty:!j.length,emptyText:t("dashboard.charts.empty")}),e.jsx(R,{title:t("dashboard.charts.modelTitle"),description:t("dashboard.charts.modelDesc"),loading:y.isPending,option:Y,empty:!c.length,emptyText:t("dashboard.charts.empty")})]}),e.jsxs("div",{className:o(P.fixed[2],"gap-6 sm:gap-8"),children:[e.jsx(R,{title:t("dashboard.charts.ttftTitle"),description:t("dashboard.charts.ttftDesc"),loading:y.isPending,option:Z,empty:!c.some(d=>d.avgTtftMs!=null&&d.avgTtftMs>0),emptyText:t("dashboard.charts.ttftEmpty")}),e.jsx(R,{title:t("dashboard.charts.tpotTitle"),description:t("dashboard.charts.tpotDesc"),loading:y.isPending,option:ee,empty:!c.some(d=>d.avgTpotMs!=null&&d.avgTpotMs>0),emptyText:t("dashboard.charts.tpotEmpty")})]}),e.jsx(pe,{models:c,loading:y.isPending}),e.jsx(ue,{loading:T.isPending,records:V})]})}function E({icon:t,title:a,value:s,suffix:r,trend:n,trendDirection:L}){return e.jsxs("div",{className:o(z,"group hover-lift animate-slide-up"),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("div",{className:o(g,"text-xs font-bold uppercase tracking-[0.15em]"),children:a}),t&&e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-xl bg-gradient-to-br from-blue-600/15 to-indigo-600/10 text-blue-600 ring-1 ring-blue-500/20 dark:from-blue-500/25 dark:to-indigo-500/15 dark:text-blue-200 dark:ring-blue-400/20",children:t})]}),e.jsx("div",{className:"flex items-end justify-between",children:e.jsxs("div",{children:[e.jsxs("p",{className:"text-3xl font-bold text-slate-900 dark:text-slate-50",children:[s.toLocaleString(),r?e.jsx("span",{className:o(g,"ml-2 text-base sm:text-lg font-medium"),children:r}):null]}),n&&e.jsxs("div",{className:o("mt-2 flex items-center gap-1 text-xs font-semibold",L==="up"?"text-emerald-600 dark:text-emerald-400":"text-red-600 dark:text-red-400"),children:[e.jsx("span",{children:n}),e.jsx("span",{className:"text-slate-500",children:"vs last period"})]})]})})]})}function R({title:t,description:a,option:s,loading:r,empty:n,emptyText:L}){const{t:p}=q();return e.jsxs("div",{className:o(z,"space-y-4 sm:space-y-6 hover-lift animate-slide-up"),children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xl font-bold text-slate-900 dark:text-slate-50",children:t}),e.jsx("p",{className:o(g,"mt-2 text-xs sm:text-sm leading-relaxed"),children:a})]}),r?e.jsx("div",{className:$.container,children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:$.spinner}),e.jsx("span",{className:o($.text),children:p("common.loadingShort")})]})}):n?e.jsx("div",{className:G,children:e.jsxs("div",{className:"text-center",children:[e.jsx(B,{className:"mx-auto h-12 w-12 text-slate-300 dark:text-slate-600 mb-4"}),e.jsx("span",{className:o(g,"text-sm"),children:L??p("dashboard.charts.empty")})]})}):e.jsx(ne,{option:s,style:{height:320},notMerge:!0,lazyUpdate:!0,theme:void 0,className:oe})]})}function pe({models:t,loading:a}){const{t:s}=q(),r=t.length>0;return e.jsx(H,{title:e.jsx("span",{className:"text-sm font-semibold text-slate-900 dark:text-slate-50",children:s("dashboard.modelTable.title")}),description:s("dashboard.modelTable.description"),contentClassName:"gap-0 overflow-hidden p-0",children:a?e.jsx("div",{className:_,children:e.jsx("span",{className:o(g,"text-sm"),children:s("common.loadingShort")})}):r?e.jsx("div",{className:"max-h-80 overflow-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-slate-200/70 text-sm dark:divide-slate-700/60",children:[e.jsx("caption",{className:"sr-only",children:s("dashboard.modelTable.title")}),e.jsx("thead",{className:"bg-slate-100/70 text-left text-xs font-semibold uppercase tracking-wide text-slate-500 dark:bg-slate-800/60 dark:text-slate-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.modelTable.columns.model")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.requests")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.latency")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.ttft")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.modelTable.columns.tpot")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/60 dark:divide-slate-800/60",children:t.map(n=>e.jsxs("tr",{className:"transition hover:bg-slate-50/70 dark:hover:bg-slate-800/40",children:[e.jsx("td",{className:"px-5 py-3",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-semibold text-slate-800 dark:text-slate-50",children:n.provider}),e.jsx("span",{className:o(g,"text-xs"),children:n.model})]})}),e.jsx("td",{className:"px-5 py-3 text-right font-medium text-slate-800 dark:text-slate-50",children:n.requests.toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-right",children:w(n.avgLatencyMs,s("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3 text-right",children:w(n.avgTtftMs,s("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3 text-right",children:w(n.avgTpotMs,s("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${n.provider}/${n.model}`))})]})}):e.jsx("div",{className:G,children:e.jsx("span",{className:o(g,"text-sm"),children:s("dashboard.modelTable.empty")})})})}function ue({records:t,loading:a}){const{t:s}=q();return e.jsx(H,{title:e.jsx("span",{className:"text-sm font-semibold text-slate-900 dark:text-slate-50",children:s("dashboard.recent.title")}),description:s("dashboard.recent.subtitle",{count:5}),contentClassName:"gap-0 overflow-hidden p-0",children:a?e.jsx("div",{className:_,children:e.jsx("span",{className:o(g,"text-sm"),children:s("dashboard.recent.loading")})}):t.length===0?e.jsx("div",{className:G,children:e.jsx("span",{className:o(g,"text-sm"),children:s("dashboard.recent.empty")})}):e.jsx("div",{className:"max-h-80 overflow-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-slate-200/70 text-sm dark:divide-slate-700/60",children:[e.jsx("caption",{className:"sr-only",children:s("dashboard.recent.title")}),e.jsx("thead",{className:"bg-slate-100/70 text-left text-xs font-semibold uppercase tracking-wide text-slate-500 dark:bg-slate-800/60 dark:text-slate-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.time")}),e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.endpoint")}),e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.provider")}),e.jsx("th",{className:"px-5 py-3 font-semibold",children:s("dashboard.recent.columns.route")}),e.jsx("th",{className:"px-5 py-3 text-right font-semibold",children:s("dashboard.recent.columns.latency")}),e.jsx("th",{className:"px-5 py-3 text-left font-semibold",children:s("dashboard.recent.columns.status")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/60 dark:divide-slate-800/60",children:t.map(r=>e.jsxs("tr",{className:"transition hover:bg-slate-50/70 dark:hover:bg-slate-800/40",children:[e.jsx("td",{className:"px-5 py-3 text-xs font-medium text-slate-600 dark:text-slate-300",children:new Date(r.timestamp).toLocaleString()}),e.jsx("td",{className:"px-5 py-3 text-xs text-slate-500 dark:text-slate-400",children:r.endpoint==="anthropic"?s("logs.table.endpointAnthropic"):r.endpoint==="openai"?s("logs.table.endpointOpenAI"):r.endpoint}),e.jsx("td",{className:"px-5 py-3 text-sm font-medium text-slate-800 dark:text-slate-50",children:r.provider}),e.jsx("td",{className:"px-5 py-3",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500 dark:text-slate-400",children:[e.jsx("span",{children:r.client_model??s("dashboard.recent.routePlaceholder")}),e.jsx("span",{"aria-hidden":"true",className:"text-slate-400",children:"→"}),e.jsx("span",{className:"font-semibold text-slate-700 dark:text-slate-100",children:r.model})]})}),e.jsx("td",{className:"px-5 py-3 text-right text-sm font-medium text-slate-800 dark:text-slate-100",children:w(r.latency_ms,s("common.units.ms"))}),e.jsx("td",{className:"px-5 py-3",children:e.jsxs(me,{variant:r.error?"error":"success",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-current","aria-hidden":"true"}),(r.status_code??(r.error?500:200)).toString(),e.jsx("span",{children:r.error?s("common.status.error"):s("common.status.success")})]})})]},r.id))})]})})})}export{ve as default};
@@ -1,21 +0,0 @@
1
- import{c as p,u as E,a as S,r as n,j as e,k as h,d as b,v as R,w as L,t as $,i as k}from"./index-BoThpdfs.js";import{R as z}from"./refresh-cw-B-xip7Eo.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 T=p("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);/**
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 F=p("ChevronRight",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);/**
12
- * @license lucide-react v0.344.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const D=p("Filter",[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]]);/**
17
- * @license lucide-react v0.344.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const I=p("ShieldAlert",[["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"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);function P(t){const r=Date.now()-t,l=Math.abs(r),x=60*1e3,o=60*x,i=24*o;if(l<x){const a=Math.max(Math.round(l/1e3),1);return r>=0?`${a}s ago`:`in ${a}s`}if(l<o){const a=Math.round(l/x);return r>=0?`${a}m ago`:`in ${a}m`}if(l<i){const a=Math.round(l/o);return r>=0?`${a}h ago`:`in ${a}h`}const m=Math.round(l/i);return r>=0?`${m}d ago`:`in ${m}d`}function K(t){return new Date(t).toLocaleString()}const N={info:"bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-200",warn:"bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-200",error:"bg-rose-100 text-rose-800 dark:bg-rose-900/40 dark:text-rose-200"};function q(){const{t}=E(),{pushToast:f}=S(),[r,l]=n.useState([]),[x,o]=n.useState(!0),[i,m]=n.useState(null),[a,y]=n.useState(null),[c,g]=n.useState({level:"",type:""}),[v,j]=n.useState(!1),u=async s=>{o(!0);try{const d=await L.list({cursor:(s==null?void 0:s.cursor)??void 0,limit:50,level:c.level||void 0,type:c.type||void 0});l(d.events),y(d.nextCursor),m((s==null?void 0:s.cursor)??null)}catch(d){const M=$(d);f({title:t("events.toast.loadFailure",{message:M.message}),variant:"error"})}finally{o(!1),j(!1)}};n.useEffect(()=>{u({reset:!0})},[c.level,c.type]);const w=()=>{j(!0),u({cursor:i,reset:!1})},C=()=>{g({level:"",type:""})},A=n.useMemo(()=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",className:h,disabled:!i,onClick:()=>void u({cursor:void 0}),children:[e.jsx(T,{size:16})," ",t("events.actions.newest")]}),e.jsxs("button",{type:"button",className:h,disabled:!a,onClick:()=>void u({cursor:a??void 0}),children:[t("events.actions.older")," ",e.jsx(F,{size:16})]})]}),[i,a,t]);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("header",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("h1",{className:"text-2xl font-bold text-slate-800 dark:text-slate-100 flex items-center gap-2",children:[e.jsx(I,{size:22,className:"text-blue-600 dark:text-blue-300"}),t("events.title")]}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-400",children:t("events.description")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[A,e.jsxs("button",{type:"button",onClick:w,className:b(h,"inline-flex items-center gap-2"),disabled:v,children:[e.jsx(z,{size:14,className:v?"animate-spin":void 0}),t(v?"common.actions.refreshing":"common.actions.refresh")]})]})]}),e.jsx("section",{className:"rounded-3xl border border-slate-200/60 bg-white/80 p-4 shadow-lg shadow-slate-200/50 backdrop-blur dark:border-slate-800/50 dark:bg-slate-900/80 dark:shadow-slate-900/40",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-600 dark:text-slate-300",children:[e.jsx(D,{size:16}),t("events.filters.title")]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs("select",{className:"rounded-full border border-slate-200/70 bg-white/70 px-3 py-1.5 text-sm text-slate-700 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200/50 dark:border-slate-700/70 dark:bg-slate-900/70 dark:text-slate-200 dark:focus:border-blue-500",value:c.level,onChange:s=>g(d=>({...d,level:s.target.value})),children:[e.jsx("option",{value:"",children:t("events.filters.allLevels")}),e.jsx("option",{value:"info",children:t("events.levels.info")}),e.jsx("option",{value:"warn",children:t("events.levels.warn")}),e.jsx("option",{value:"error",children:t("events.levels.error")})]}),e.jsx("input",{type:"text",className:"rounded-full border border-slate-200/70 bg-white/70 px-3 py-1.5 text-sm text-slate-700 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200/50 dark:border-slate-700/70 dark:bg-slate-900/70 dark:text-slate-200 dark:focus:border-blue-500",placeholder:t("events.filters.typePlaceholder"),value:c.type,onChange:s=>g(d=>({...d,type:s.target.value}))}),e.jsx("button",{type:"button",onClick:C,className:h,children:t("common.actions.reset")})]})]})}),x?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(R,{})}):r.length===0?e.jsxs("div",{className:"rounded-3xl border border-dashed border-slate-200/70 bg-white/60 p-10 text-center text-slate-500 shadow-inner shadow-slate-200/40 dark:border-slate-700/60 dark:bg-slate-900/60 dark:text-slate-400 dark:shadow-slate-900/40",children:[e.jsx("p",{className:"text-lg font-semibold",children:t("events.empty.title")}),e.jsx("p",{className:"text-sm mt-2",children:t("events.empty.subtitle")})]}):e.jsx("div",{className:"grid gap-4",children:r.map(s=>e.jsxs("article",{className:"rounded-3xl border border-slate-200/70 bg-gradient-to-br from-white/95 to-white/85 p-5 shadow-md shadow-slate-200/40 backdrop-blur dark:border-slate-800/60 dark:from-slate-900/90 dark:to-slate-900/80 dark:shadow-slate-900/50",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:b("text-sm font-semibold px-3 py-1 rounded-full",N[s.level]||N.info),children:t(`events.levels.${s.level}`)}),e.jsxs("span",{className:"text-sm text-slate-500 dark:text-slate-400",children:[K(s.createdAt)," · ",P(s.createdAt)]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500 dark:text-slate-400",children:[e.jsxs("span",{className:b(k.default,"bg-slate-100 dark:bg-slate-800"),children:["#",s.id]}),s.mode?e.jsx("span",{className:b(k.default,"bg-blue-100 dark:bg-blue-900/40"),children:s.mode}):null]})]}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx("h3",{className:"text-lg font-semibold text-slate-800 dark:text-slate-100",children:s.title||t("events.defaultTitle")}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-300",children:s.message||t("events.defaultMessage")})]}),e.jsxs("div",{className:"mt-4 grid gap-3 text-sm text-slate-600 dark:text-slate-300 sm:grid-cols-2 lg:grid-cols-3",children:[s.ipAddress?e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-widest text-slate-400 dark:text-slate-500",children:"IP"}),e.jsx("p",{children:s.ipAddress})]}):null,s.apiKeyName?e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-widest text-slate-400 dark:text-slate-500",children:"API Key"}),e.jsx("p",{children:s.apiKeyName})]}):null,s.userAgent?e.jsxs("div",{className:"sm:col-span-2 lg:col-span-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-widest text-slate-400 dark:text-slate-500",children:"User Agent"}),e.jsx("p",{className:"truncate",children:s.userAgent})]}):null]}),s.details?e.jsxs("details",{className:"mt-4 rounded-2xl border border-slate-200/60 bg-slate-50/70 p-3 text-sm dark:border-slate-800/60 dark:bg-slate-900/60",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold text-blue-600 dark:text-blue-300",children:t("events.details")}),e.jsx("pre",{className:"mt-3 rounded-xl bg-white/80 p-3 text-xs text-slate-700 shadow-inner dark:bg-slate-950/80 dark:text-slate-200",children:JSON.stringify(s.details,null,2)})]}):null]},s.id))})]})}export{q as default};
@@ -1 +0,0 @@
1
- import{j as s,d,T as m,U as x}from"./index-BoThpdfs.js";function i({label:a,children:l,className:t,required:r,error:e}){return s.jsxs("div",{className:d(x,t),children:[s.jsxs("label",{className:m,children:[a,r&&s.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),l,e&&s.jsx("p",{className:"text-xs text-red-600 dark:text-red-400 mt-1",children:e})]})}export{i as F};
@@ -1,23 +0,0 @@
1
- import{c as u,u as p,r as b,j as e,d as x,m}from"./index-BoThpdfs.js";import{P as g,a as o}from"./PageSection-D043B876.js";import{I as j}from"./info-XnK1Lt65.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 f=u("BookOpen",[["path",{d:"M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z",key:"vv98re"}],["path",{d:"M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z",key:"1cyq3y"}]]);/**
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 N=u("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);/**
12
- * @license lucide-react v0.344.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const v=u("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]);function O(){const{t:s}=p(),t=b.useMemo(()=>{const r=s("help.sections.configuration.items",{returnObjects:!0}),l=s("help.sections.claudeCodeConfig.items",{returnObjects:!0}),i=s("help.sections.codexConfig.items",{returnObjects:!0}),d=s("help.sections.usage.items",{returnObjects:!0}),n=s("help.sections.tips.items",{returnObjects:!0});return[{title:s("help.sections.configuration.title"),items:r},{title:s("help.sections.claudeCodeConfig.title"),items:l},{title:s("help.sections.codexConfig.title"),items:i},{title:s("help.sections.usage.title"),items:d},{title:s("help.sections.tips.title"),items:n}]},[s]),a=s("help.faq.items",{returnObjects:!0});return e.jsxs("div",{className:"space-y-8",children:[e.jsx(g,{icon:e.jsx(f,{className:"h-6 w-6","aria-hidden":"true"}),title:s("help.title"),description:s("help.intro")}),e.jsx("div",{className:"rounded-3xl border border-blue-200/40 bg-gradient-to-br from-blue-50/90 via-white/90 to-purple-50/80 p-6 shadow-lg shadow-blue-100/40 backdrop-blur-sm dark:border-blue-900/30 dark:from-blue-900/40 dark:via-slate-900/70 dark:to-indigo-900/30 dark:shadow-indigo-900/40",children:e.jsxs("div",{className:"flex flex-wrap items-start gap-4",children:[e.jsx("div",{className:"grid h-12 w-12 place-items-center rounded-2xl bg-blue-500/10 text-blue-600 dark:bg-blue-500/20 dark:text-blue-200",children:e.jsx(j,{className:"h-6 w-6","aria-hidden":"true"})}),e.jsx("p",{className:x(m,"text-sm leading-6"),children:s("help.note")})]})}),e.jsxs("div",{className:"space-y-8",children:[e.jsx(o,{title:t[0].title,className:"animate-slide-up",contentClassName:"gap-4",children:e.jsx(c,{items:t[0].items})}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("h2",{className:"text-2xl font-bold text-slate-900 dark:text-slate-100",children:s("help.clientConfig.title")}),e.jsx("p",{className:x(m,"text-sm"),children:s("help.clientConfig.subtitle")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(o,{title:t[1].title,className:"h-full animate-slide-up border-2 border-blue-200/60 bg-gradient-to-br from-blue-50/80 via-white/60 to-indigo-50/60 dark:border-blue-700/60 dark:from-blue-900/30 dark:via-slate-900/50 dark:to-indigo-900/30 shadow-lg shadow-blue-100/50 dark:shadow-blue-900/30",contentClassName:"gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6 p-3 bg-blue-100/50 rounded-xl dark:bg-blue-900/20",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-blue-500 flex items-center justify-center shadow-lg shadow-blue-500/30",children:e.jsx(N,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-semibold text-blue-700 dark:text-blue-300",children:"Claude Code"}),e.jsx("p",{className:"text-xs text-blue-600 dark:text-blue-400",children:"IDE 插件配置"})]})]}),e.jsx(c,{items:t[1].items})]}),e.jsxs(o,{title:t[2].title,className:"h-full animate-slide-up border-2 border-green-200/60 bg-gradient-to-br from-green-50/80 via-white/60 to-emerald-50/60 dark:border-green-700/60 dark:from-green-900/30 dark:via-slate-900/50 dark:to-emerald-900/30 shadow-lg shadow-green-100/50 dark:shadow-green-900/30",contentClassName:"gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6 p-3 bg-green-100/50 rounded-xl dark:bg-green-900/20",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-green-500 flex items-center justify-center shadow-lg shadow-green-500/30",children:e.jsx(v,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-semibold text-green-700 dark:text-green-300",children:"Codex CLI"}),e.jsx("p",{className:"text-xs text-green-600 dark:text-green-400",children:"命令行工具配置"})]})]}),e.jsx(c,{items:t[2].items})]})]}),e.jsxs("div",{className:"mt-12",children:[e.jsxs("div",{className:"text-center space-y-2 mb-8",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900 dark:text-slate-100",children:s("help.advancedGuide.title")}),e.jsx("p",{className:x(m,"text-sm"),children:s("help.advancedGuide.subtitle")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(o,{title:t[3].title,className:"h-full animate-slide-up",contentClassName:"gap-4",children:e.jsx(c,{items:t[3].items})}),e.jsx(o,{title:t[4].title,className:"h-full animate-slide-up",contentClassName:"gap-4",children:e.jsx(c,{items:t[4].items})})]})]})]}),e.jsx(o,{title:s("help.faq.title"),contentClassName:"gap-4",children:e.jsx(w,{items:a})})]})}function c({items:s}){return e.jsx("ol",{className:"flex flex-col gap-4",children:s.map((t,a)=>e.jsxs("li",{className:"group flex gap-4 rounded-3xl border border-slate-200/60 bg-white p-4 shadow-sm shadow-slate-200/30 transition-all duration-200 hover:-translate-y-0.5 hover:border-blue-200/60 hover:shadow-md hover:shadow-blue-200/40 dark:border-slate-700/60 dark:bg-slate-900/80 dark:shadow-slate-900/40 dark:hover:border-blue-500/40",children:[e.jsx("span",{className:"flex h-9 w-9 items-center justify-center rounded-2xl bg-gradient-to-br from-blue-500 to-indigo-500 text-sm font-semibold text-white shadow-lg shadow-blue-500/30 dark:from-blue-400 dark:to-indigo-400 flex-shrink-0",children:a+1}),e.jsx("div",{className:x(m,"text-sm leading-6 flex-1"),children:e.jsx(k,{content:t})})]},`${a}-${t}`))})}function k({content:s}){const{t}=p();if(s.includes("```")){const a=s.split("```");return e.jsx("div",{className:"space-y-2",children:a.map((r,l)=>{if(l%2===0)return r?e.jsx("div",{className:"whitespace-pre-line",children:h(r)},l):null;{const[i,...d]=r.split(`
17
- `),n=d.join(`
18
- `);return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:i||"bash"}),e.jsx("button",{onClick:()=>navigator.clipboard.writeText(n),className:"text-xs px-2 py-1 rounded bg-slate-100 dark:bg-slate-800 hover:bg-slate-200 dark:hover:bg-slate-700 transition-colors",children:t("common.actions.copy")})]}),e.jsx("pre",{className:"bg-slate-50 dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-lg p-3 overflow-x-auto text-xs",children:e.jsx("code",{children:n})})]},l)}})})}return s.includes(`
19
- `)?e.jsx("div",{className:"whitespace-pre-line",children:h(s)}):e.jsx("div",{children:h(s)})}function h(s){return s.split(/(\*\*[^*]+\*\*)/g).map((a,r)=>a.startsWith("**")&&a.endsWith("**")?e.jsx("strong",{className:"font-semibold text-slate-700 dark:text-slate-200",children:a.slice(2,-2)},r):e.jsx("span",{children:a},r))}function w({items:s}){return s.length===0?null:e.jsx("dl",{className:"flex flex-col gap-4",children:s.map(t=>e.jsxs("div",{className:"rounded-3xl border border-slate-200/60 bg-white p-5 shadow-sm shadow-slate-200/30 transition-all duration-200 hover:-translate-y-0.5 hover:border-blue-200/60 hover:shadow-md hover:shadow-blue-200/40 dark:border-slate-700/60 dark:bg-slate-900/80 dark:shadow-slate-900/40 dark:hover:border-blue-500/40",children:[e.jsx("dt",{className:"text-sm font-semibold text-slate-900 dark:text-slate-100",children:t.q}),e.jsx("dd",{className:x(m,"mt-2 text-sm leading-6"),children:e.jsx(y,{content:t.a})})]},t.q))})}function y({content:s}){const{t}=p();if(s.includes("1)")||s.includes("2)")){const a=s.split(`
20
- `).filter(l=>l.trim());if(a.some(l=>/^\d+\)/.test(l.trim())))return e.jsx("div",{className:"space-y-2",children:a.map((l,i)=>{const d=l.match(/^\d+\)\s*(.*)/);return d?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:"•"}),e.jsx("span",{children:d[1]})]},i):e.jsx("div",{children:l},i)})})}if(s.includes("```")){const a=s.split("```");return e.jsx("div",{className:"space-y-2",children:a.map((r,l)=>{if(l%2===0)return r?e.jsx("div",{className:"whitespace-pre-line",children:r},l):null;{const[i,...d]=r.split(`
21
- `),n=d.join(`
22
- `);return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-medium text-slate-500 dark:text-slate-400",children:i||"bash"}),e.jsx("button",{onClick:()=>navigator.clipboard.writeText(n),className:"text-xs px-2 py-1 rounded bg-slate-100 dark:bg-slate-800 hover:bg-slate-200 dark:hover:bg-slate-700 transition-colors",children:t("common.actions.copy")})]}),e.jsx("pre",{className:"bg-slate-50 dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-lg p-3 overflow-x-auto text-xs",children:e.jsx("code",{children:n})})]},l)}})})}return s.includes(`
23
- `)?e.jsx("div",{className:"whitespace-pre-line",children:s}):e.jsx("div",{children:s})}export{O as default};
@@ -1 +0,0 @@
1
- import{r as d,j as e,d as n,O as c,N as i}from"./index-BoThpdfs.js";const f=d.forwardRef(({options:t,placeholder:s,className:r,...l},u)=>e.jsxs("select",{ref:u,className:n(c,r),...l,children:[s&&e.jsx("option",{value:"",disabled:!0,children:s}),t.map(a=>e.jsx("option",{value:a.value,disabled:a.disabled,children:a.label},a.value))]})),j=d.forwardRef(({variant:t="default",className:s,...r},l)=>e.jsx("input",{ref:l,className:n(i,s),...r}));export{j as I,f as S};
@@ -1 +0,0 @@
1
- import{u as y,aa as E,ab as C,ac as S,r as l,j as e,d,L as _,m as j,N as v,H as L}from"./index-BoThpdfs.js";function P(){const{t:a}=y(),o=E(),m=C(),{authEnabled:n,isAuthenticated:x,loading:i,login:k,error:b}=S(),[r,h]=l.useState({username:"",password:""}),[f,u]=l.useState(null),[p,g]=l.useState(!1),c=l.useMemo(()=>{var t;const s=m.state;return((t=s==null?void 0:s.from)==null?void 0:t.pathname)??"/"},[m.state]);l.useEffect(()=>{if(!n&&!i){o(c,{replace:!0});return}n&&x&&!i&&o(c,{replace:!0})},[n,x,i,o,c]);const N=async s=>{if(s.preventDefault(),u(null),!r.username.trim()||!r.password){u(a("login.validation.required"));return}g(!0);try{await k(r.username.trim(),r.password),o(c,{replace:!0})}catch(t){u(t instanceof Error?t.message:a("login.validation.failed"))}finally{g(!1)}},w=s=>e.jsxs("div",{className:"relative flex min-h-screen items-center justify-center overflow-hidden bg-gradient-to-br from-slate-100 via-white to-slate-200 px-4 dark:from-slate-950/95 dark:via-slate-950 dark:to-slate-900",children:[e.jsxs("div",{className:"pointer-events-none absolute inset-0",children:[e.jsx("div",{className:"absolute left-10 top-20 h-48 w-48 rounded-full bg-slate-200/40 blur-3xl dark:bg-slate-700/30"}),e.jsx("div",{className:"absolute right-16 bottom-32 h-56 w-56 rounded-full bg-slate-300/35 blur-3xl dark:bg-slate-800/30"}),e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(circle_at_top,_rgba(15,23,42,0.08),_transparent_55%)]"})]}),e.jsx("div",{className:"relative z-10 w-full max-w-lg",children:s})]});return i?w(e.jsx("div",{className:"flex min-h-[320px] items-center justify-center rounded-3xl border border-blue-200/60 bg-white/90 shadow-2xl shadow-blue-200/50 backdrop-blur-xl dark:border-slate-800/50 dark:bg-slate-900/80 dark:shadow-slate-900/60",children:e.jsx(_,{})})):n?w(e.jsxs("main",{className:"rounded-3xl border border-slate-200/70 bg-white/95 px-8 pb-10 pt-9 shadow-2xl shadow-slate-200/40 backdrop-blur-xl dark:border-slate-800/60 dark:bg-slate-900/85 dark:shadow-slate-900/60",children:[e.jsxs("header",{className:"mb-8 flex flex-col items-center gap-3 text-center",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-slate-900 via-slate-800 to-slate-700 text-xl font-bold text-white shadow-lg shadow-slate-400/30 dark:from-blue-500 dark:via-blue-600 dark:to-indigo-600 dark:shadow-blue-900/40",children:"GW"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h1",{className:"text-2xl font-semibold text-slate-900 dark:text-slate-50",children:a("login.title")}),e.jsx("p",{className:d(j,"text-sm leading-relaxed max-w-[360px]"),children:a("login.description")})]})]}),e.jsxs("form",{className:"space-y-5",onSubmit:N,children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("login.fields.username")}),e.jsx("input",{value:r.username,autoComplete:"username",autoFocus:!0,onChange:s=>h(t=>({...t,username:s.target.value})),placeholder:a("login.fields.usernamePlaceholder"),className:d(v,"h-11 font-medium")})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("login.fields.password")}),e.jsx("input",{type:"password",value:r.password,autoComplete:"current-password",onChange:s=>h(t=>({...t,password:s.target.value})),placeholder:a("login.fields.passwordPlaceholder"),className:d(v,"h-11")})]}),f||b?e.jsx("div",{className:"rounded-2xl border border-red-200/70 bg-red-50/80 px-4 py-3 text-sm font-medium text-red-600 shadow-sm shadow-red-200/40 dark:border-red-500/40 dark:bg-red-500/15 dark:text-red-100",children:f||b}):null,e.jsx("button",{type:"submit",className:d(L,"w-full justify-center rounded-full py-3 text-sm font-semibold"),disabled:p,children:a(p?"common.actions.loading":"login.actions.submit")})]}),e.jsx("footer",{className:"mt-7 text-center text-xs",children:e.jsx("p",{className:d(j,"leading-relaxed"),children:a("login.hint")})})]})):null}export{P as default};
@@ -1 +0,0 @@
1
- import{u as M,a as oe,r as i,b as be,t as je,j as e,d as y,k as te,F as ye,p as ke,o as Ne,m as A,q as ve,L as we}from"./index-BoThpdfs.js";import{u as K}from"./useApiQuery-B6AV-yNf.js";import{P as _e,a as se}from"./PageSection-D043B876.js";import{F as T}from"./FormField-DdAleV-5.js";import{S as I,I as W}from"./Input-BLqaRoSo.js";import{B as $}from"./Button-BA3yKRV9.js";import{S as de}from"./StatusBadge--UpDQrE2.js";const ae=[20,50,100];function le(t,r=!1){if(!t)return;const n=r?`${t}T23:59:59.999`:`${t}T00:00:00.000`,b=Date.parse(n);return Number.isFinite(b)?b:void 0}function ne(t){const r=new Date(t);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 v(t){return t==null?"-":t.toLocaleString()}function w(t,r){const n=v(t);return n==="-"?"-":`${n} ${r}`}function re(t){return t?"true":"false"}function ie(t,r){if(!t||t.trim().length===0)return r;try{const n=JSON.parse(t);return JSON.stringify(n,null,2)}catch{return t}}function Ke(){var Z,V;const{t}=M(),{pushToast:r}=oe(),[n,b]=i.useState("all"),[j,s]=i.useState("all"),[c,N]=i.useState(""),[u,h]=i.useState("all"),[g,a]=i.useState(""),[d,o]=i.useState(""),[x,_]=i.useState(1),[m,S]=i.useState(ae[0]),[O,L]=i.useState(null),[ce,G]=i.useState(!1),[D,Q]=i.useState([]),[q,H]=i.useState(!1);i.useEffect(()=>{_(1)},[n,j,c,u,g,d,m,D]);const R=i.useMemo(()=>{const l={limit:m,offset:(x-1)*m};n!=="all"&&(l.provider=n),j!=="all"&&(l.endpoint=j),c.trim().length>0&&(l.model=c.trim()),u!=="all"&&(l.status=u);const p=le(g),P=le(d,!0);return p!==void 0&&(l.from=p),P!==void 0&&(l.to=P),D.length>0&&(l.apiKeys=D.join(",")),l},[n,j,c,u,g,d,x,m,D]),f=K(["logs",R],{url:"/api/logs",method:"GET",params:R}),E=K(["providers","all"],{url:"/api/providers",method:"GET"}),J=K(["api-keys"],{url:"/api/keys",method:"GET"});i.useEffect(()=>{f.isError&&f.error&&r({title:t("logs.toast.listError.title"),description:t("logs.toast.listError.desc",{message:f.error.message}),variant:"error"})},[f.isError,f.error,r,t]),i.useEffect(()=>{E.isError&&E.error&&r({title:t("logs.toast.providerError.title"),description:t("logs.toast.providerError.desc",{message:E.error.message}),variant:"error"})},[E.isError,E.error,r,t]);const C=((Z=f.data)==null?void 0:Z.total)??0,k=C>0?Math.ceil(C/m):0,U=((V=f.data)==null?void 0:V.items)??[];i.useEffect(()=>{k>0&&x>k&&_(k)},[k,x]),i.useEffect(()=>{const l=document.querySelector(".table-container");l&&(l.style.overflow="hidden",setTimeout(()=>{l.style.overflow="auto"},10))},[U]);const z=E.data??[],Y=i.useMemo(()=>{const l=new Map;for(const p of z)p.id&&l.set(p.id,p.label??p.id);return l},[z]),B=J.data??[],X=i.useMemo(()=>{const l=new Map;for(const p of B)l.set(p.id,p);return l},[B]),xe=i.useMemo(()=>[{value:"all",label:t("logs.filters.statusAll")},{value:"success",label:t("logs.filters.statusSuccess")},{value:"error",label:t("logs.filters.statusError")}],[t]),me=()=>{b("all"),N(""),s("all"),h("all"),a(""),o(""),Q([])},pe=i.useCallback(async()=>{if(!q){H(!0);try{const l=C>0?Math.min(C,5e3):1e3,p={...R,limit:l,offset:0},P=await be.post("/api/logs/export",p,{responseType:"blob"}),ge=new Blob([P.data],{type:"application/zip"}),fe=new Date().toISOString().replace(/[:.]/g,"-"),ee=URL.createObjectURL(ge),F=document.createElement("a");F.href=ee,F.download=`cc-gw-logs-${fe}.zip`,document.body.appendChild(F),F.click(),F.remove(),URL.revokeObjectURL(ee),r({title:t("logs.toast.exportSuccess.title"),description:t("logs.toast.exportSuccess.desc"),variant:"success"})}catch(l){const p=je(l);r({title:t("logs.toast.exportError.title"),description:t("logs.toast.exportError.desc",{message:p.message}),variant:"error"})}finally{H(!1)}}},[q,r,R,t,C]),ue=i.useCallback(l=>{L(l),G(!0)},[]),he=i.useCallback(()=>{G(!1),L(null)},[]);return e.jsxs("div",{className:"flex flex-col gap-8",style:{width:"100%",maxWidth:"100%",overflow:"hidden"},children:[e.jsx(_e,{icon:e.jsx(ye,{className:"h-6 w-6","aria-hidden":"true"}),title:t("logs.title"),description:t("logs.description"),disableAnimation:!0,variant:"plain",className:"max-w-full",actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm","aria-live":"polite",children:[e.jsx($,{variant:"primary",onClick:pe,loading:q,"aria-label":t("logs.actions.export"),className:"rounded-full",children:t("logs.actions.export")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.summary.total",{value:C.toLocaleString()})}),e.jsx("button",{type:"button",onClick:()=>f.refetch(),disabled:f.isFetching,className:y(te,"h-10 rounded-full px-4",f.isFetching?"cursor-wait opacity-70":""),children:f.isFetching?t("common.actions.refreshing"):t("logs.actions.manualRefresh")})]})}),e.jsxs(se,{title:t("logs.filtersTitle"),description:t("logs.filtersDescription"),actions:e.jsx("button",{type:"button",onClick:me,className:y(te,"h-9 rounded-full px-4"),children:t("common.actions.reset")}),disableAnimation:!0,variant:"plain",className:"max-w-full",contentClassName:"grid w-full gap-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(T,{label:t("logs.filters.provider"),children:e.jsx(I,{value:n,onChange:l=>b(l.target.value),options:[{value:"all",label:t("logs.filters.providerAll")},...z.map(l=>({value:l.id,label:l.label??l.id}))]})}),e.jsx(T,{label:t("logs.filters.endpoint"),children:e.jsx(I,{value:j,onChange:l=>s(l.target.value),options:[{value:"all",label:t("logs.filters.endpointAll")},{value:"anthropic",label:t("logs.filters.endpointAnthropic")},{value:"openai",label:t("logs.filters.endpointOpenAI")}]})}),e.jsx(Ce,{className:"md:col-span-2",apiKeys:B,selected:D,disabled:J.isLoading,onChange:Q}),e.jsx(T,{label:t("logs.filters.modelId"),children:e.jsx(W,{value:c,onChange:l=>N(l.target.value),placeholder:t("logs.filters.modelPlaceholder")})}),e.jsx(T,{label:t("logs.filters.status"),children:e.jsx(I,{value:u,onChange:l=>h(l.target.value),options:xe})}),e.jsx(T,{label:t("logs.filters.startDate"),children:e.jsx(W,{type:"date",value:g,onChange:l=>a(l.target.value)})}),e.jsx(T,{label:t("logs.filters.endDate"),children:e.jsx(W,{type:"date",value:d,onChange:l=>o(l.target.value)})})]}),e.jsxs(se,{disableAnimation:!0,variant:"plain",className:"p-0 max-w-full",contentClassName:"gap-0",children:[e.jsx("div",{className:"w-full rounded-lg border border-slate-200 dark:border-slate-700",children:e.jsx("div",{className:"table-container",style:{overflowX:"auto",overflowY:"hidden",width:"100%"},children:e.jsx("div",{style:{width:"1380px",minWidth:"1380px"},children:e.jsxs("table",{className:"divide-y divide-slate-200 dark:divide-slate-700",style:{width:"100%",tableLayout:"fixed"},children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"140px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"130px"}}),e.jsx("col",{style:{width:"100px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"70px"}}),e.jsx("col",{style:{width:"80px"}}),e.jsx("col",{style:{width:"90px"}}),e.jsx("col",{style:{width:"120px"}}),e.jsx("col",{style:{width:"120px"}})]}),e.jsx("caption",{className:"sr-only",children:t("logs.title")}),e.jsx("thead",{className:"bg-gradient-to-b from-slate-100 to-slate-50 dark:from-slate-800 dark:to-slate-800/60 text-left font-bold uppercase tracking-wider text-slate-600 dark:text-slate-300 border-b-2 border-slate-200 dark:border-slate-700",style:{fontSize:"10px"},children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.time")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.endpoint")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.provider")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.requestedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.routedModel")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.apiKey")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.inputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cacheReadTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.cacheCreationTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.outputTokens")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.latency")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.ttft")}),e.jsx("th",{className:"px-3 py-2 text-right font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.tpot")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.status")}),e.jsx("th",{className:"px-3 py-2 text-left font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.error")}),e.jsx("th",{className:"px-3 py-2 text-center font-semibold text-slate-600 dark:text-slate-200",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-200/80 bg-white dark:divide-slate-700/80 dark:bg-slate-900",children:f.isPending?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.loading")})}):U.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:15,className:"px-3 py-8 text-center text-xs text-slate-400 dark:text-slate-500",children:t("logs.table.empty")})}):U.map((l,p)=>e.jsx(Se,{record:l,providerLabelMap:Y,apiKeyMap:X,onSelect:ue,isEven:p%2===0},l.id))})]})})})}),e.jsxs("div",{className:ke,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:y(A,"whitespace-nowrap"),children:t("logs.table.pagination.perPage")}),e.jsx("select",{value:m,onChange:l=>S(Number(l.target.value)),className:Ne,children:ae.map(l=>e.jsxs("option",{value:l,children:[l," ",t("logs.table.pagination.unit")]},l))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{onClick:()=>_(l=>Math.max(l-1,1)),disabled:x<=1,size:"sm",className:"rounded-full",children:t("logs.table.pagination.previous")}),e.jsx("span",{className:y(A,"font-medium"),children:t("logs.table.pagination.pageLabel",{page:k===0?0:x,total:k})}),e.jsx($,{onClick:()=>_(l=>k===0?l:Math.min(l+1,k)),disabled:k===0||x>=k,size:"sm",className:"rounded-full",children:t("logs.table.pagination.next")})]})]})]}),e.jsx(Ee,{open:ce,logId:O,onClose:he,providerLabelMap:Y,apiKeyMap:X})]})}function Se({record:t,providerLabelMap:r,apiKeyMap:n,onSelect:b,isEven:j}){const{t:s}=M(),c=r.get(t.provider)??t.provider,N=t.endpoint||"-",u=!!t.error,h=t.status_code,g=t.client_model??s("logs.table.requestedModelFallback"),a=t.api_key_id!=null?n.get(t.api_key_id):void 0,d=t.api_key_id==null?s("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?s("apiKeys.wildcard"):a!=null&&a.name?a.name:t.api_key_name?t.api_key_name:s("logs.table.apiKeyUnknown");return e.jsxs("tr",{className:y("transition-colors duration-150",j?"bg-slate-50/30 dark:bg-slate-800/20":"bg-white dark:bg-slate-900","hover:bg-blue-50/50 dark:hover:bg-blue-900/20"),children:[e.jsx("td",{className:"px-3 py-2.5 text-xs font-medium text-slate-700 dark:text-slate-100 whitespace-nowrap",children:ne(t.timestamp)}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100 whitespace-nowrap",children:N}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:c,children:c})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-600 dark:text-slate-200",children:e.jsx("div",{className:"truncate",title:g,children:g})}),e.jsx("td",{className:"px-3 py-2.5 text-xs text-slate-700 dark:text-slate-100",children:e.jsx("div",{className:"truncate",title:t.model,children:t.model})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("div",{className:y(A,"truncate text-xs"),title:d,children:d})}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.input_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.cache_read_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.cache_creation_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs font-medium text-slate-700 dark:text-slate-100 tabular-nums",children:v(t.output_tokens)}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.latency_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.ttft_ms,"ms")}),e.jsx("td",{className:"px-3 py-2.5 text-right text-xs text-slate-700 dark:text-slate-100 tabular-nums whitespace-nowrap",children:w(t.tpot_ms,"ms/tk")}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx(de,{variant:u?"error":"success",children:h??(u?500:200)})}),e.jsx("td",{className:"px-3 py-2.5 text-[10px] text-slate-500 dark:text-slate-400",children:e.jsx("div",{className:"truncate",title:t.error??"",children:t.error?t.error:"-"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx($,{onClick:()=>b(t.id),size:"sm",className:"rounded-full text-xs px-2 py-1",children:s("logs.actions.detail")})})]})}function Ee({open:t,logId:r,onClose:n,providerLabelMap:b,apiKeyMap:j}){var x,_;const{t:s}=M(),{pushToast:c}=oe(),N=i.useRef(null),u=i.useRef(null),h=K(["log-detail",r],{url:`/api/logs/${r}`,method:"GET"},{enabled:t&&r!==null,staleTime:3e4});i.useEffect(()=>{h.isError&&h.error&&c({title:s("logs.detail.loadError"),description:h.error.message,variant:"error"})},[h.isError,h.error,c,s]),i.useEffect(()=>{if(!t)return;const m=S=>{S.key==="Escape"&&n()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,n]),i.useEffect(()=>{t&&u.current&&u.current.focus()},[t,r]);const g=i.useCallback(async(m,S,O)=>{if(!S){c({title:s("logs.detail.copy.empty",{label:m}),variant:"info"});return}try{await navigator.clipboard.writeText(S),c({title:s(O),variant:"success"})}catch(L){c({title:s("logs.detail.copy.failure"),description:L instanceof Error?L.message:s("logs.detail.copy.failureFallback"),variant:"error"})}},[c,s]);if(!t)return null;const a=h.data,d=a?b.get(a.provider)??a.provider:"",o=a&&a.api_key_id!=null?j.get(a.api_key_id):void 0;return typeof document>"u"?null:ve.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60",onClick:n,"aria-hidden":"true"}),e.jsxs("aside",{ref:N,role:"dialog","aria-modal":"true","aria-labelledby":"log-detail-title","aria-describedby":"log-detail-content",className:"flex h-full w-full max-w-xl flex-col border-l border-slate-200 bg-white shadow-xl transition-all 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:"log-detail-title",className:"text-lg font-semibold",children:s("logs.detail.title")}),a?e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.id",{id:a.id})}):null]}),e.jsx("button",{type:"button",ref:u,onClick:n,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:s("common.actions.close")})]}),e.jsx("div",{id:"log-detail-content",className:"flex-1 overflow-y-auto",children:h.isPending?e.jsx(we,{}):a?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-md bg-slate-100 px-3 py-2 text-xs text-slate-600 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-100",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.latency",{value:w(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.ttft",{value:w(a.ttft_ms,s("common.units.ms"))})}):null,a.tpot_ms!==null?e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.tpot",{value:w(a.tpot_ms,s("common.units.msPerToken"))})}):null,e.jsx("span",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.summary.stream",{value:re(a.stream)})}),e.jsxs(de,{variant:a.error?"error":"success",children:[(a.status_code??(a.error?500:200)).toString(),e.jsx("span",{children:a.error?s("common.status.error"):s("common.status.success")})]})]}),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-slate-500 dark:text-slate-400",children:s("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:ne(a.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:a.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:a.endpoint||"-"}),e.jsx("dt",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:d})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:a.client_model??s("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:a.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:re(a.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.inputTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.input_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cacheReadTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.cache_read_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.cacheCreationTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.cache_creation_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.outputTokens")}),e.jsx("dd",{className:"font-medium",children:v(a.output_tokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.ttft")}),e.jsx("dd",{className:"font-medium",children:w(a.ttft_ms,s("common.units.ms"))})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.tpot")}),e.jsx("dd",{className:"font-medium",children:w(a.tpot_ms,s("common.units.msPerToken"))})]})]}),a.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-md border border-red-200 bg-red-50 p-3 text-xs leading-5 text-red-700 dark:border-red-800/70 dark:bg-red-900/40 dark:text-red-200",children:a.error})]}):null]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("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-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.name)??a.api_key_name??s("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:a.api_key_id??s("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.isWildcard?s("apiKeys.wildcard"):(o==null?void 0:o.maskedKey)??a.api_key_name??s("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:o!=null&&o.lastUsedAt?new Date(o.lastUsedAt).toLocaleString():s("common.noData")})]})]}),e.jsxs("div",{className:"rounded-md border border-slate-200 bg-slate-50 px-3 py-3 text-xs text-slate-600 dark:border-slate-800 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-200",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all text-xs font-mono",children:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] leading-relaxed text-slate-500 dark:text-slate-400",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.request")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.request"),(m=a.payload)==null?void 0:m.prompt,"logs.detail.copy.requestSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((x=a.payload)==null?void 0:x.prompt,s("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("header",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.detail.payload.response")}),e.jsx("button",{type:"button",onClick:()=>{var m;return g(s("logs.detail.payload.response"),(m=a.payload)==null?void 0:m.response,"logs.detail.copy.responseSuccess")},className:"rounded-md border border-slate-200 px-2 py-1 text-xs transition hover:bg-slate-100 dark:border-slate-700 dark:hover:bg-slate-800",children:s("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-md border border-slate-200 bg-slate-50 p-3 text-xs leading-5 text-slate-700 dark:border-slate-800 dark:bg-slate-900/80 dark:text-slate-200",children:ie((_=a.payload)==null?void 0:_.response,s("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify.center p-8 text-sm text-slate-500 dark:text-slate-400",children:s("logs.detail.loadError")})})]})]}),document.body)}function Ce({apiKeys:t,selected:r,onChange:n,disabled:b,className:j}){const{t:s}=M(),[c,N]=i.useState(!1),u=i.useRef(null);i.useEffect(()=>{if(!c)return;const d=o=>{var x;(x=u.current)!=null&&x.contains(o.target)||N(!1)};return window.addEventListener("mousedown",d),()=>window.removeEventListener("mousedown",d)},[c]);const h=i.useMemo(()=>{if(r.length===0)return[];const d=new Map;for(const o of t)d.set(o.id,o);return r.map(o=>{const x=d.get(o);return x?x.isWildcard?s("apiKeys.wildcard"):x.name:null}).filter(o=>!!o)},[t,r,s]),g=r.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:r.length}),a=d=>{r.includes(d)?n(r.filter(o=>o!==d)):n([...r,d])};return e.jsxs("div",{className:y("relative flex flex-col gap-2",j),ref:u,children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>N(d=>!d),disabled:b||t.length===0,title:s("logs.filters.apiKeyHint"),className:y("flex h-10 w-full items-center justify-between rounded-xl border border-slate-200/70 bg-white/90 px-3 text-sm font-medium text-slate-600 shadow-sm shadow-slate-200/60 transition focus:outline-none focus:ring-2 focus:ring-blue-400/30 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-700/60 dark:bg-slate-900/80 dark:text-slate-200",r.length>0?"border-blue-400 text-blue-700 dark:border-blue-400 dark:text-blue-200":"",c?"ring-2 ring-blue-400/30":""),"aria-haspopup":"listbox","aria-expanded":c,children:[e.jsxs("span",{className:"truncate",children:[g,h.length>0&&e.jsx("span",{className:"ml-1 text-xs text-slate-500 dark:text-slate-400",children:h.join(", ")})]}),e.jsx("svg",{className:y("h-4 w-4 text-slate-400 transition-all dark:text-slate-300",c?"rotate-180":""),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",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"})})]}),c&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-2xl border border-slate-200/70 bg-white p-2 shadow-lg shadow-slate-200/70 dark:border-slate-700/60 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-slate-200/60 bg-slate-50/70 px-3 py-2 text-xs font-medium text-slate-500 dark:border-slate-700/50 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("span",{children:g}),e.jsx("button",{type:"button",onClick:()=>n([]),disabled:r.length===0,className:"text-blue-600 hover:underline disabled:opacity-40 dark:text-blue-400",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto px-1 py-2",children:[t.map(d=>{const o=d.isWildcard?s("apiKeys.wildcard"):d.name,x=r.includes(d.id);return e.jsxs("label",{className:y("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-slate-100 dark:hover:bg-slate-800",x?"bg-blue-50/70 text-blue-600 dark:bg-blue-900/30 dark:text-blue-200":"text-slate-600 dark:text-slate-200"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-slate-300 text-blue-600 focus:ring-blue-400 dark:border-slate-600",checked:x,onChange:()=>a(d.id)}),e.jsx("span",{className:"truncate",children:o})]},d.id)}),t.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:s("logs.filters.apiKeyAll")})]})]})]})}export{Ke as default};
@@ -1 +0,0 @@
1
- var Ze=s=>{throw TypeError(s)};var Te=(s,a,c)=>a.has(s)||Ze("Cannot "+c);var C=(s,a,c)=>(Te(s,a,"read from private field"),c?c.call(s):a.get(s)),de=(s,a,c)=>a.has(s)?Ze("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(s):a.set(s,c),ne=(s,a,c,m)=>(Te(s,a,"write to private field"),m?m.call(s,c):a.set(s,c),c),ie=(s,a,c)=>(Te(s,a,"access private method"),c);import{S as Ut,x as Lt,y as et,z as Tt,A as dt,C as nt,r as g,D as $t,E as At,u as Pe,j as e,a as it,G as It,H as oe,b as W,I as ge,t as Re,J as tt,i as Kt,k as q,K as st,M as $e,N as ce,O as ct}from"./index-BoThpdfs.js";import{u as Bt,a as Vt}from"./useApiQuery-B6AV-yNf.js";var Y,se,A,X,Z,Se,Ke,ot,Ft=(ot=class extends Ut{constructor(a,c){super();de(this,Z);de(this,Y);de(this,se);de(this,A);de(this,X);ne(this,Y,a),this.setOptions(c),this.bindMethods(),ie(this,Z,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=C(this,Y).defaultMutationOptions(a),Lt(this.options,c)||C(this,Y).getMutationCache().notify({type:"observerOptionsUpdated",mutation:C(this,A),observer:this}),c!=null&&c.mutationKey&&this.options.mutationKey&&et(c.mutationKey)!==et(this.options.mutationKey)?this.reset():((m=C(this,A))==null?void 0:m.state.status)==="pending"&&C(this,A).setOptions(this.options)}onUnsubscribe(){var a;this.hasListeners()||(a=C(this,A))==null||a.removeObserver(this)}onMutationUpdate(a){ie(this,Z,Se).call(this),ie(this,Z,Ke).call(this,a)}getCurrentResult(){return C(this,se)}reset(){var a;(a=C(this,A))==null||a.removeObserver(this),ne(this,A,void 0),ie(this,Z,Se).call(this),ie(this,Z,Ke).call(this)}mutate(a,c){var m;return ne(this,X,c),(m=C(this,A))==null||m.removeObserver(this),ne(this,A,C(this,Y).getMutationCache().build(C(this,Y),this.options)),C(this,A).addObserver(this),C(this,A).execute(a)}},Y=new WeakMap,se=new WeakMap,A=new WeakMap,X=new WeakMap,Z=new WeakSet,Se=function(){var c;const a=((c=C(this,A))==null?void 0:c.state)??Tt();ne(this,se,{...a,isPending:a.status==="pending",isSuccess:a.status==="success",isError:a.status==="error",isIdle:a.status==="idle",mutate:this.mutate,reset:this.reset})},Ke=function(a){dt.batch(()=>{var c,m,p,j,d,x,N,b;if(C(this,X)&&this.hasListeners()){const P=C(this,se).variables,I=C(this,se).context,O={client:C(this,Y),meta:this.options.meta,mutationKey:this.options.mutationKey};(a==null?void 0:a.type)==="success"?((m=(c=C(this,X)).onSuccess)==null||m.call(c,a.data,P,I,O),(j=(p=C(this,X)).onSettled)==null||j.call(p,a.data,null,P,I,O)):(a==null?void 0:a.type)==="error"&&((x=(d=C(this,X)).onError)==null||x.call(d,a.error,P,I,O),(b=(N=C(this,X)).onSettled)==null||b.call(N,void 0,a.error,P,I,O))}this.listeners.forEach(P=>{P(C(this,se))})})},ot);function at(s,a){const c=nt(),[m]=g.useState(()=>new Ft(c,s));g.useEffect(()=>{m.setOptions(s)},[m,s]);const p=g.useSyncExternalStore(g.useCallback(d=>m.subscribe(dt.batchCalls(d)),[m]),()=>m.getCurrentResult(),()=>m.getCurrentResult()),j=g.useCallback((d,x)=>{m.mutate(d,x).catch($t)},[m]);if(p.error&&At(m.options.throwOnError,[p.error]))throw p.error;return{...p,mutate:j,mutateAsync:p.mutate}}function Ve(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Ht(){return{_key:Ve(),id:"",label:""}}const Ae={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 rt(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:Ve()})),authMode:s.authMode==="authToken"?"authToken":"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function _t(s){return{_key:Ve(),id:s.id,label:s.label}}function qt({open:s,mode:a,provider:c,existingProviderIds:m,onClose:p,onSubmit:j}){const{t:d}=Pe(),[x,N]=g.useState(()=>rt(c)),[b,P]=g.useState({}),[I,O]=g.useState(!1),[B,V]=g.useState(null),y=g.useRef(null),E=g.useRef(null),D=g.useRef(null),[L,fe]=g.useState(a==="edit");g.useEffect(()=>{s&&(N(rt(c)),P({}),V(null),O(!1),fe(a==="edit"))},[s,c,a]),g.useEffect(()=>{if(!s)return;const u=f=>{f.key==="Escape"&&p()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,p]),g.useEffect(()=>{if(s){if(a==="create"&&D.current){D.current.focus();return}E.current&&E.current.focus()}},[s,a]);const ve=g.useMemo(()=>x.models.filter(u=>u.id.trim().length>0),[x.models]),ue=u=>f=>{N(w=>({...w,[u]:f}))},ke=u=>{N(f=>{const k=!L||f.label.trim().length===0||f.label===f.id?u:f.label;return{...f,id:u,label:k}})},ae=u=>{N(f=>{var Ne;const k=Ae[u??"custom"]??Ae.custom,S=Object.values(Ae).map(ee=>ee.baseUrl).filter(ee=>!!ee),z=!f.baseUrl||S.includes(f.baseUrl),$=a==="create"&&(f.models.length===0||f.models.every(ee=>ee.id.trim().length===0)),Q={...f,type:u,authMode:u==="anthropic"?f.authMode??"apiKey":"apiKey"};return k!=null&&k.baseUrl&&z&&(Q.baseUrl=k.baseUrl),k!=null&&k.models&&$&&(Q.models=k.models.map(_t),Q.defaultModel=k.defaultModel??((Ne=k.models[0])==null?void 0:Ne.id)??""),Q})},T=(u,f)=>{N(w=>{const k=[...w.models];return k[u]={...k[u],...f},{...w,models:k}})},De=(u,f)=>{N(w=>{const k=[...w.models],S=k[u];if(!S)return w;const z=!L||!S.label||S.label===S.id,$={...S,id:f,label:z?f:S.label};k[u]=$;const Q=w.defaultModel===S.id?f:w.defaultModel;return{...w,models:k,defaultModel:Q}})},F=u=>{N(f=>{if(u<0||u>=f.models.length)return f;const w=f.models.filter((S,z)=>z!==u);let k=f.defaultModel;return w.some(S=>S.id===k)||(k=""),{...f,models:w,defaultModel:k}})},Oe=()=>{N(u=>({...u,models:[...u.models,Ht()]}))},me=u=>{N(f=>({...f,authMode:u}))},je=()=>{const u={},f=x.id.trim(),w=x.baseUrl.trim();if(a==="create"&&(f.length===0?u.id=d("providers.drawer.errors.idRequired"):m.includes(f)&&(u.id=d("providers.drawer.errors.idDuplicate"))),a==="edit"&&f.length===0&&(u.id=d("providers.drawer.errors.idRequired")),w.length===0)u.baseUrl=d("providers.drawer.errors.baseUrlInvalid");else try{new URL(w)}catch{u.baseUrl=d("providers.drawer.errors.baseUrlInvalid")}if(x.models.length>0){const k=new Set;x.models.some(z=>{const $=z.id.trim();return $.length===0||k.has($)?!0:(k.add($),!1)})&&(u.models=d("providers.drawer.errors.modelInvalid"))}return x.defaultModel&&!x.models.some(k=>k.id===x.defaultModel)&&(u.models=d("providers.drawer.errors.defaultInvalid")),P(u),Object.keys(u).length===0},xe=()=>{const u=x.models.map(k=>{var S;return{id:k.id.trim(),label:(S=k.label)!=null&&S.trim()?k.label.trim():void 0}}).filter(k=>k.id.length>0),f=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,w=x.type==="anthropic"?x.authMode:void 0;return{id:x.id.trim(),label:x.label.trim()||x.id.trim(),baseUrl:x.baseUrl.trim(),apiKey:x.apiKey.trim()||void 0,type:x.type??"custom",defaultModel:x.defaultModel||void 0,models:u.length>0?u:void 0,extraHeaders:f,authMode:w}},ye=async()=>{if(V(null),!!je()){O(!0);try{const u=xe();await j(u)}catch(u){V(d("providers.drawer.toast.saveFailure",{message:u instanceof Error?u.message:"unknown"})),O(!1);return}O(!1),p()}},he=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:p,"aria-hidden":"true"}),e.jsxs("aside",{ref:y,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:d(he?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-xs text-slate-500 dark:text-slate-400",children:d("providers.drawer.description")})]}),e.jsx("button",{type:"button",ref:E,onClick:p,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:d("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:d("providers.drawer.description")}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{type:"button",onClick:()=>fe(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:d(L?"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:d("providers.drawer.fields.id")}),e.jsx("input",{value:x.id,ref:D,onChange:u=>ke(u.target.value),disabled:!he,placeholder:d("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":!!b.id}),b.id?e.jsx("span",{className:"text-xs text-red-500",children:b.id}):null]}),L?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:d("providers.drawer.fields.label")}),e.jsx("input",{value:x.label,onChange:u=>ue("label")(u.target.value),placeholder:d("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:d("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:x.baseUrl,onChange:u=>ue("baseUrl")(u.target.value),placeholder:d("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":!!b.baseUrl}),b.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:b.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:d("providers.drawer.fields.type")}),e.jsxs("select",{value:x.type??"custom",onChange:u=>ae(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:d("providers.drawer.fields.apiKey")}),e.jsx("input",{value:x.apiKey,onChange:u=>ue("apiKey")(u.target.value),placeholder:d("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"})]}),x.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:d("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:d("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:x.authMode==="apiKey",onChange:()=>me("apiKey")}),e.jsx("span",{children:d("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:x.authMode==="authToken",onChange:()=>me("authToken")}),e.jsx("span",{children:d("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:d("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:d("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:Oe,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:d("providers.drawer.fields.addModel")})]}),b.models?e.jsx("p",{className:"text-xs text-red-500",children:b.models}):null,e.jsxs("div",{className:"space-y-4",children:[x.models.map((u,f)=>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:d("providers.drawer.fields.modelId")}),e.jsx("input",{value:u.id,onChange:w=>De(f,w.target.value),placeholder:d("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"})]}),L?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:d("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:u.label??"",onChange:w=>T(f,{label:w.target.value}),placeholder:d("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:x.defaultModel===u.id,onChange:()=>N(w=>({...w,defaultModel:u.id})),disabled:u.id.trim().length===0}),d("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:()=>F(f),disabled:x.models.length===0,children:d("providers.drawer.fields.removeModel")})]})]},u._key)),x.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:d("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:d("providers.drawer.noModelsHint",{providerId:x.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:d("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-*": "',(x.id||"provider-id").trim()||"provider-id",':*"']})]})]})]})}):null]}),ve.length>1?e.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:d("providers.drawer.defaultHint",{model:x.defaultModel||d("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:B?e.jsx("span",{children:B}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:p,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:I,children:d("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:ye,className:"rounded-md bg-blue-600 px-4 py-2 text-white transition hover:bg-blue-700 disabled:opacity-60",disabled:I,children:d(I?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const zt=["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"],Qt=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function Be(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function J(s){return s?Object.entries(s).map(([a,c])=>({id:Be(),source:a,target:c})):[]}function Ie(s,a){var p,j,d;if(!s)return{};const c={},m=s.endpointRouting??{};c.anthropic=J(((p=m.anthropic)==null?void 0:p.modelRoutes)??s.modelRoutes??{}),c.openai=J(((j=m.openai)==null?void 0:j.modelRoutes)??{});for(const x of a)(d=x.routing)!=null&&d.modelRoutes?c[x.id]=J(x.routing.modelRoutes):c[x.id]=[];return c}function Gt(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 Wt(s,a,c){var p,j,d;if(!a)return;if(s==="anthropic"||s==="openai")return(j=(p=a.endpointRouting)==null?void 0:p[s])==null?void 0:j.validation;const m=c.find(x=>x.id===s);return(d=m==null?void 0:m.routing)==null?void 0:d.validation}function as(){const{t:s}=Pe(),{pushToast:a}=it(),c=nt(),m=Bt(["config","full"],{url:"/api/config",method:"GET"}),{data:p}=Vt({queryKey:["custom-endpoints"],queryFn:ge.list,refetchInterval:1e4}),j=(p==null?void 0:p.endpoints)??[],d=g.useMemo(()=>{const t=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],o=j.map(r=>{let l,n=[];if(r.paths&&r.paths.length>0){const i=r.paths.map(h=>`${h.path} (${h.protocol})`).join(", ");l=`${s("modelManagement.tabs.customEndpoint")}: ${i}`,n=[...new Set(r.paths.map(h=>h.protocol))]}else if(r.path){const i=r.protocol||"anthropic";l=`${s("modelManagement.tabs.customEndpoint")}: ${r.path} (${i})`,n=[i]}else l=s("modelManagement.tabs.customEndpoint");return{key:r.id,label:r.label,description:l,isSystem:!1,canDelete:!0,protocols:n}});return[...t,...o]},[s,j]),[x,N]=g.useState("providers"),[b,P]=g.useState(null),[I,O]=g.useState(!1),[B,V]=g.useState("create"),[y,E]=g.useState(void 0),[D,L]=g.useState(null),[fe,ve]=g.useState(!1),[ue,ke]=g.useState(void 0),[ae,T]=g.useState({}),[De,F]=g.useState({}),[Oe,me]=g.useState(null),[je,xe]=g.useState({}),[ye,he]=g.useState({}),[u,f]=g.useState({}),[w,k]=g.useState(null),[S,z]=g.useState(null),[$,Q]=g.useState(null),[Ne,ee]=g.useState(!1),[Ue,Fe]=g.useState(null),[we,Le]=g.useState(!0),[He,_e]=g.useState({}),[qe,ze]=g.useState(!1),H=(b==null?void 0:b.providers)??[],ut=H.length,be=g.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]);g.useEffect(()=>{var t,o;if(m.data){const r=m.data;P(r),T(Ie(r,j)),F({});const l={anthropic:((t=r.routingPresets)==null?void 0:t.anthropic)??[],openai:((o=r.routingPresets)==null?void 0:o.openai)??[]};for(const n of j)l[n.id]=n.routingPresets??[];xe(l)}},[m.data,j]),g.useEffect(()=>{m.isError&&m.error&&a({title:s("providers.toast.loadFailure",{message:m.error.message}),variant:"error"})},[m.isError,m.error,a,s]);const mt=g.useMemo(()=>{const t=new Map;for(const o of H){if(!o.defaultModel||!o.models)continue;const r=o.models.find(l=>l.id===o.defaultModel);r&&t.set(o.id,lt(r))}return t},[H]),Qe=g.useMemo(()=>{const t=[],o=new Set;for(const l of H){const n=l.label||l.id,i=l.models??[];if(i.length>0)for(const v of i){const R=`${l.id}:${v.id}`;o.has(R)||(o.add(R),t.push({value:R,label:`${n} · ${v.label??v.id}`}))}else if(l.defaultModel){const v=`${l.id}:${l.defaultModel}`;o.has(v)||(o.add(v),t.push({value:v,label:`${n} · ${l.defaultModel}`}))}const h=`${l.id}:*`;o.has(h)||(o.add(h),t.push({value:h,label:s("settings.routing.providerPassthroughOption",{provider:n})}))}const r=[...ae.anthropic||[],...ae.openai||[]];for(const l of r){const n=l.target.trim();n&&!o.has(n)&&(o.add(n),t.push({value:n,label:n}))}return t},[H,ae,s]),Ge=(t,o)=>{xe(r=>({...r,[t]:o})),P(r=>{if(!r)return r;if(t==="anthropic"||t==="openai")return{...r,routingPresets:{...r.routingPresets,[t]:o}};const l=r.customEndpoints??[],n=l.findIndex(h=>h.id===t);if(n===-1)return r;const i=[...l];return i[n]={...i[n],routingPresets:o},{...r,customEndpoints:i}})},te=()=>b?!0:(a({title:s("settings.toast.missingConfig"),variant:"error"}),m.refetch(),!1),xt=(t,o)=>{he(r=>({...r,[t]:o})),o.trim()&&f(r=>({...r,[t]:null}))},ht=async t=>{if(!te())return;const o=ye[t].trim();if(!o){f(r=>({...r,[t]:s("modelManagement.validation.presetName")}));return}if(je[t].some(r=>r.name.toLowerCase()===o.toLowerCase())){f(r=>({...r,[t]:s("modelManagement.validation.presetDuplicate",{name:o})}));return}k(t);try{const l=(await W.post(`/api/routing-presets/${t}`,{name:o})).data.presets??[];Ge(t,l),he(n=>({...n,[t]:""})),f(n=>({...n,[t]:null})),a({title:s("modelManagement.toast.presetSaved",{name:o}),variant:"success"})}catch(r){a({title:s("modelManagement.toast.presetSaveFailure",{message:r instanceof Error?r.message:"unknown"}),variant:"error"})}finally{k(null),m.refetch()}},bt=async(t,o)=>{var r,l,n;if(te()){z({endpoint:t,name:o.name});try{const h=(await W.post(`/api/routing-presets/${t}/apply`,{name:o.name})).data.config;if(h){P(h),T(Ie(h,j));const v={anthropic:((r=h.routingPresets)==null?void 0:r.anthropic)??[],openai:((l=h.routingPresets)==null?void 0:l.openai)??[]};for(const R of j){const U=(n=h.customEndpoints)==null?void 0:n.find(K=>K.id===R.id);v[R.id]=(U==null?void 0:U.routingPresets)??[]}xe(v)}else T(v=>({...v,[t]:J(o.modelRoutes)}));a({title:s("modelManagement.toast.presetApplySuccess",{name:o.name}),variant:"success"})}catch(i){a({title:s("modelManagement.toast.presetApplyFailure",{message:i instanceof Error?i.message:"unknown"}),variant:"error"})}finally{z(null),m.refetch()}}},pt=async(t,o)=>{if(!(!te()||!window.confirm(s("modelManagement.confirm.deletePreset",{name:o.name})))){Q({endpoint:t,name:o.name});try{const n=(await W.delete(`/api/routing-presets/${t}/${encodeURIComponent(o.name)}`)).data.presets??[];Ge(t,n),a({title:s("modelManagement.toast.presetDeleteSuccess",{name:o.name}),variant:"success"})}catch(l){a({title:s("modelManagement.toast.presetDeleteFailure",{message:l instanceof Error?l.message:"unknown"}),variant:"error"})}finally{Q(null),m.refetch()}}},gt=()=>{te()&&(V("create"),E(void 0),O(!0))},ft=t=>{te()&&(V("edit"),E(t),O(!0))},vt=async t=>{if(!b)throw new Error(s("settings.toast.missingConfig"));const o=B==="create"?[...H,t]:H.map(n=>y&&n.id===y.id?{...t,id:y.id}:n),r={...b,providers:o};await W.put("/api/config",r),P(r),T(Ie(r,j)),m.refetch();const l=B==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});a({title:l,variant:"success"})},kt=async t=>{const o=j.find(r=>r.id===t);if(o&&confirm(s("modelManagement.deleteEndpointConfirm",{label:o.label})))try{await ge.delete(t),c.invalidateQueries({queryKey:["custom-endpoints"]}),a({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),x===t&&N("providers")}catch(r){const l=Re(r);a({title:s("modelManagement.deleteEndpointError",{error:l.message}),variant:"error"})}},We=async(t,o)=>{L(t.id);try{const r=o&&(o.headers||o.query)?{headers:o.headers&&Object.keys(o.headers).length>0?o.headers:void 0,query:o.query&&o.query.trim().length>0?o.query.trim():void 0}:void 0,l=await W.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{L(null)}},jt=t=>{if(t.type==="anthropic"){const o=t.extraHeaders??{},r=new Map(be.map(i=>[i.key.toLowerCase(),i])),l={};let n=!0;for(const i of be){const h=Object.entries(o).find(([v])=>v.toLowerCase()===i.key.toLowerCase());if(h){const[v,R]=h;String(R??"")===i.value||(n=!1,l[v]=String(R??""))}}for(const[i,h]of Object.entries(o))r.has(i.toLowerCase())||(l[i]=String(h??""));_e(l),Le(n),Fe(t),ee(!0);return}We(t)},Je=()=>{ee(!1),Fe(null),Le(!0),_e({})},yt=async()=>{if(!Ue)return;const t={};if(we)for(const l of be)t[l.key]=l.value;const o=new Map(be.map(l=>[l.key.toLowerCase(),l]));for(const[l,n]of Object.entries(He)){const i=l.toLowerCase();o.get(i)&&we||(t[l]=n)}const r=Ue;Je(),await We(r,{headers:Object.keys(t).length>0?t:void 0,query:we?"beta=true":void 0})},Nt=async t=>{var R,U,K,re;if(!te()||!window.confirm(s("providers.confirm.delete",{name:t.label||t.id})))return;const r=H.filter(_=>_.id!==t.id),l=_=>{const le={};if(!_)return le;for(const[Ee,M]of Object.entries(_)){if(!M)continue;const[Ce]=M.split(":");Ce&&Ce===t.id||M===t.id||(le[Ee]=M)}return le},n=(b==null?void 0:b.endpointRouting)??{},i=l(((R=n.anthropic)==null?void 0:R.modelRoutes)??(b==null?void 0:b.modelRoutes)??{}),h=l(((U=n.openai)==null?void 0:U.modelRoutes)??{}),v={...b,providers:r,modelRoutes:i,endpointRouting:{anthropic:{defaults:((K=n.anthropic)==null?void 0:K.defaults)??b.defaults,modelRoutes:i},openai:{defaults:((re=n.openai)==null?void 0:re.defaults)??b.defaults,modelRoutes:h}}};try{await W.put("/api/config",v),P(v),T({anthropic:J(i),openai:J(h)}),a({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),m.refetch()}catch(_){a({title:s("providers.toast.deleteFailure",{message:_ instanceof Error?_.message:"unknown"}),variant:"error"})}},wt=t=>{T(o=>({...o,[t]:[...o[t]||[],{id:Be(),source:"",target:""}]})),F(o=>({...o,[t]:null}))},Mt=async(t,o)=>{if(te()){ze(!0);try{if(t==="anthropic"||t==="openai"){const r=b.endpointRouting?{...b.endpointRouting}:{},l=r[t]??{defaults:b.defaults,modelRoutes:(t==="anthropic"?b.modelRoutes:{})??{}},n={defaults:l.defaults??b.defaults,modelRoutes:l.modelRoutes??{}};let i=l.validation;o?(i={...i??{},mode:"claude-code"},i.allowExperimentalBlocks===void 0&&(i.allowExperimentalBlocks=!0)):i=void 0;const h=i?{...n,validation:i}:{...n},v={...r,[t]:h},R={...b,endpointRouting:v};await W.put("/api/config",R),P(R)}else{const r=b.customEndpoints??[],l=r.findIndex(re=>re.id===t);if(l===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const n=r[l],i=n.routing??{defaults:b.defaults,modelRoutes:{}};let h=i.validation;o?(h={...h??{},mode:"claude-code"},h.allowExperimentalBlocks===void 0&&(h.allowExperimentalBlocks=!0)):h=void 0;const v=h?{...i,validation:h}:{...i},R={...n,routing:v},U=[...r];U[l]=R;const K={...b,customEndpoints:U};await W.put("/api/config",K),P(K)}a({title:s(o?"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{ze(!1)}}},Et=(t,o)=>{T(r=>{const l=r[t]||[];return l.some(n=>n.source.trim()===o.trim())?r:{...r,[t]:[...l,{id:Be(),source:o,target:""}]}}),F(r=>({...r,[t]:null}))},Me=(t,o,r,l)=>{T(n=>({...n,[t]:(n[t]||[]).map(i=>i.id===o?{...i,[r]:l}:i)})),F(n=>({...n,[t]:null}))},Ct=(t,o)=>{T(r=>({...r,[t]:(r[t]||[]).filter(l=>l.id!==o)})),F(r=>({...r,[t]:null}))},St=t=>{var r,l;if(!b)return;const o=j.find(n=>n.id===t);if(o){const n=((r=o.routing)==null?void 0:r.modelRoutes)??{};T(i=>({...i,[t]:J(n)}))}else{const n=b.endpointRouting??{},i=t,h=i==="anthropic"?b.modelRoutes??{}:{},v=((l=n[i])==null?void 0:l.modelRoutes)??h;T(R=>({...R,[t]:J(v)}))}F(n=>({...n,[t]:null}))},Rt=async t=>{var l;if(!te())return;const o=ae[t]||[],r={};for(const n of o){const i=n.source.trim(),h=n.target.trim();if(!(!i&&!h)){if(!i||!h){F(v=>({...v,[t]:s("settings.validation.routePair")}));return}if(r[i]){F(v=>({...v,[t]:s("settings.validation.routeDuplicate",{model:i})}));return}r[i]=h}}F(n=>({...n,[t]:null})),me(t);try{const n=j.find(i=>i.id===t);if(n){const i={...n.routing||{},modelRoutes:r,defaults:((l=n.routing)==null?void 0:l.defaults)||b.defaults};await ge.update(t,{routing:i}),c.invalidateQueries({queryKey:["custom-endpoints"]}),a({title:s("modelManagement.toast.routesSaved"),variant:"success"})}else{const i=b.endpointRouting?{...b.endpointRouting}:{},h=t,v=i[h]??{defaults:b.defaults,modelRoutes:h==="anthropic"?b.modelRoutes??{}:{}},R={...v,defaults:v.defaults??b.defaults,modelRoutes:r},U={...i,[h]:R},K={...b,endpointRouting:U,modelRoutes:h==="anthropic"?r:b.modelRoutes??{}};await W.put("/api/config",K),P(K),a({title:s("modelManagement.toast.routesSaved"),variant:"success"}),m.refetch()}T(i=>({...i,[t]:J(r)}))}catch(n){a({title:s("modelManagement.toast.routesSaveFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{me(null)}},Pt=()=>e.jsxs("section",{className:tt,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800 dark:text-slate-100",children:s("providers.title")}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-400",children:s("providers.description")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("div",{className:Kt.default,children:s("providers.count",{count:ut})}),e.jsx("button",{type:"button",className:q,onClick:()=>m.refetch(),disabled:m.isFetching,children:m.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")}),e.jsx("button",{type:"button",className:oe,onClick:gt,children:s("providers.actions.add")})]})]}),m.isPending||!b&&m.isFetching?e.jsx("section",{className:"flex min-h-[200px] items-center justify-center rounded-3xl border border-slate-200/50 bg-gradient-to-br from-white/80 to-white/70 text-sm text-slate-600 dark:border-slate-700/50 dark:from-slate-900/80 dark:to-slate-900/70 dark:text-slate-400 backdrop-blur-lg",children:s("common.loading")}):H.length===0?e.jsx("section",{className:"rounded-3xl border border-dashed border-slate-300/60 bg-gradient-to-br from-slate-50/80 to-white/70 p-12 text-center text-sm text-slate-600 dark:border-slate-600/60 dark:from-slate-900/80 dark:to-slate-800/70 dark:text-slate-400 backdrop-blur-lg",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"rounded-2xl bg-slate-200/50 p-4 dark:bg-slate-700/50",children:e.jsx("svg",{className:"h-8 w-8 text-slate-400 dark:text-slate-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-300",children:s("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]})]})}):e.jsx("div",{className:"grid gap-6 md:grid-cols-2 xl:grid-cols-3",children:H.map(t=>e.jsxs("article",{className:"group flex h-full flex-col gap-5 rounded-3xl border border-slate-200/50 bg-gradient-to-br from-white/85 via-white/80 to-white/75 p-6 shadow-lg shadow-slate-200/30 backdrop-blur-md transition-all duration-300 hover:border-slate-200/70 hover:shadow-xl hover:shadow-slate-200/50 hover:-translate-y-1 dark:border-slate-700/50 dark:from-slate-900/85 dark:via-slate-900/80 dark:to-slate-900/75 dark:shadow-2xl dark:shadow-slate-900/40 dark:hover:border-slate-600/70 dark:hover:bg-slate-900/90",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-2xl bg-gradient-to-br from-blue-500 via-blue-600 to-indigo-600 text-white shadow-lg shadow-blue-500/30",children:e.jsx("span",{className:"text-lg font-bold",children:(t.label||t.id).charAt(0).toUpperCase()})}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-lg font-bold text-slate-800 dark:text-slate-100",children:t.label||t.id}),t.type?e.jsx(Yt,{type:t.type}):null]}),e.jsxs("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:["ID: ",t.id]})]})]}),e.jsxs("div",{className:"mt-3 space-y-1",children:[e.jsx("p",{className:"text-xs text-slate-600 dark:text-slate-400 font-medium",children:"Base URL:"}),e.jsx("p",{className:"text-xs font-mono text-slate-700 dark:text-slate-300 bg-slate-100/50 dark:bg-slate-800/50 rounded-lg px-2 py-1 break-all",children:t.baseUrl})]})]}),e.jsx("div",{className:"flex flex-col gap-2",children:t.defaultModel?e.jsx("div",{className:st.success,children:s("providers.card.defaultModel",{model:mt.get(t.id)??t.defaultModel})}):e.jsx("div",{className:st.info,children:s("providers.card.noDefault")})})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h4",{className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:s("providers.card.modelsTitle")}),t.models&&t.models.length>0?e.jsx("div",{className:"flex flex-wrap gap-2",children:t.models.map(o=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-slate-200/60 bg-gradient-to-r from-slate-50/80 to-slate-100/70 px-3 py-1.5 text-xs dark:border-slate-700/60 dark:from-slate-800/60 dark:to-slate-700/50 backdrop-blur-sm transition-all duration-200 hover:border-slate-300/70 hover:bg-slate-100/80 dark:hover:border-slate-600/70 dark:hover:bg-slate-700/60",children:[e.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-blue-500"}),e.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-200",children:lt(o)})]},o.id))}):e.jsx("div",{className:"rounded-xl border border-dashed border-slate-300/50 bg-slate-50/50 px-4 py-3 text-xs text-slate-500 dark:border-slate-600/50 dark:bg-slate-800/30 dark:text-slate-400",children:s("providers.card.noModels")})]}),e.jsxs("footer",{className:"mt-auto flex flex-wrap gap-3 pt-2 border-t border-slate-200/30 dark:border-slate-700/30",children:[e.jsx("button",{type:"button",className:q,onClick:()=>ft(t),children:s("providers.actions.edit")}),e.jsx("button",{type:"button",onClick:()=>jt(t),disabled:D===t.id,className:D===t.id?`${q} opacity-60 cursor-not-allowed`:q,children:D===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx("button",{type:"button",className:$e,onClick:()=>Nt(t),children:s("providers.actions.delete")})]})]},t.id))})]}),Dt=t=>{const o=je[t],r=ye[t],l=u[t],n=w===t;return e.jsxs("div",{className:"rounded-2xl border border-dashed border-slate-300/60 bg-gradient-to-br from-slate-50/80 to-white/70 p-6 dark:border-slate-600/60 dark:from-slate-800/60 dark:to-slate-900/70 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("h3",{className:"text-base font-bold text-slate-800 dark:text-slate-100",children:s("modelManagement.presets.title")}),e.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-400",children:s("modelManagement.presets.description")})]}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx("input",{type:"text",value:r,onChange:i=>xt(t,i.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),className:ce,disabled:n}),e.jsx("button",{type:"button",onClick:()=>ht(t),className:oe,disabled:n,children:s(n?"modelManagement.presets.saving":"modelManagement.presets.save")})]})]}),l?e.jsx("div",{className:"rounded-xl bg-red-50/80 border border-red-200/50 p-3 text-xs text-red-700 dark:bg-red-900/40 dark:border-red-800/50 dark:text-red-300 backdrop-blur-sm",children:l}):null,o.length===0?e.jsx("div",{className:"rounded-xl border border-slate-200/40 bg-slate-50/60 p-6 text-center text-sm text-slate-600 dark:border-slate-700/40 dark:bg-slate-800/40 dark:text-slate-400 backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"rounded-xl bg-slate-200/50 p-3 dark:bg-slate-700/50",children:e.jsx("svg",{className:"h-6 w-6 text-slate-400 dark:text-slate-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-300",children:s("modelManagement.presets.empty")})]})}):e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:o.map(i=>{const h=(S==null?void 0:S.endpoint)===t&&(S==null?void 0:S.name)===i.name,v=($==null?void 0:$.endpoint)===t&&($==null?void 0:$.name)===i.name;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-slate-200/50 bg-gradient-to-r from-white/90 to-white/80 px-4 py-3 text-sm shadow-sm backdrop-blur-sm transition-all duration-200 hover:border-slate-300/70 hover:bg-white/95 hover:shadow-md dark:border-slate-700/50 dark:from-slate-900/90 dark:to-slate-900/80 dark:hover:border-slate-600/70 dark:hover:bg-slate-900/95",children:[e.jsx("span",{className:"truncate font-medium text-slate-700 dark:text-slate-200",children:i.name}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>bt(t,i),className:h||v?`${q} opacity-60 cursor-not-allowed text-xs px-2 py-1`:`${oe} text-xs px-2 py-1`,disabled:h||v,children:s(h?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx("button",{type:"button",onClick:()=>pt(t,i),className:v||h?`${q} opacity-60 cursor-not-allowed text-xs px-2 py-1`:`${$e} text-xs px-2 py-1`,disabled:v||h,children:s(v?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},i.name)})})]})},Ot=t=>{var Ee;const o=ae[t]||[],r=De[t],l=d.find(M=>M.key===t),i=((Ee=l==null?void 0:l.protocols)==null?void 0:Ee.includes("anthropic"))??t==="anthropic"?zt:Qt,h=Oe===t,v=(l==null?void 0:l.label)??s(`modelManagement.tabs.${t}`),R=(l==null?void 0:l.isSystem)===!1?l.description:s(`settings.routing.descriptionByEndpoint.${t}`),U=`route-source-${t}`,K=`route-target-${t}`,re=Gt(t,j),_=Wt(t,b,j),le=re&&(_==null?void 0:_.mode)==="claude-code";return e.jsxs("section",{className:tt,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800 dark:text-slate-100",children:s("settings.routing.titleByEndpoint",{endpoint:v})}),e.jsx("p",{className:"max-w-3xl text-sm text-slate-600 dark:text-slate-400",children:R}),e.jsx("p",{className:"max-w-3xl text-xs text-slate-500 dark:text-slate-400",children:s("settings.routing.wildcardHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>wt(t),className:q,disabled:h,children:s("settings.routing.add")}),e.jsx("button",{type:"button",onClick:()=>St(t),className:q,disabled:h,children:s("common.actions.reset")}),e.jsx("button",{type:"button",onClick:()=>Rt(t),className:oe,disabled:h,children:s(h?"common.actions.saving":"modelManagement.actions.saveRoutes")})]})]}),re&&e.jsx("div",{className:"mt-6 rounded-xl border border-blue-200/60 bg-blue-50/60 p-4 dark:border-blue-500/40 dark:bg-blue-900/30 backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-sm font-semibold text-blue-700 dark:text-blue-200",children:s("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-blue-600/80 dark:text-blue-200/80",children:s("modelManagement.claudeValidation.description")})]}),e.jsxs("label",{className:"inline-flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-blue-300 text-blue-600 focus:ring-blue-500",checked:!!le,onChange:M=>Mt(t,M.target.checked),disabled:qe}),e.jsx("span",{className:"text-xs font-medium text-blue-700 dark:text-blue-200",children:s(qe?"common.actions.saving":"modelManagement.claudeValidation.toggleLabel")})]})]}),e.jsx("span",{className:`text-xs font-semibold ${le?"text-emerald-600 dark:text-emerald-300":"text-slate-500 dark:text-slate-400"}`,children:s(le?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})}),Dt(t),r?e.jsx("div",{className:"rounded-xl bg-red-50/80 border border-red-200/50 p-4 text-sm text-red-700 dark:bg-red-900/40 dark:border-red-800/50 dark:text-red-300 backdrop-blur-sm",children:r}):null,o.length===0?e.jsx("div",{className:"rounded-xl border border-dashed border-slate-300/60 bg-gradient-to-br from-slate-50/80 to-white/70 p-12 text-center text-sm text-slate-600 dark:border-slate-600/60 dark:from-slate-800/60 dark:to-slate-900/70 dark:text-slate-400 backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"rounded-2xl bg-slate-200/50 p-4 dark:bg-slate-700/50",children:e.jsx("svg",{className:"h-8 w-8 text-slate-400 dark:text-slate-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 20l-5.447-2.724A1 1 0 013 16.382V5.618a1 1 0 011.447-.894L9 7m0 13l6-3m-6 3V7m6 10l4.553 2.276A1 1 0 0021 18.382V7.618a1 1 0 00-.553-.894L15 4m0 13V4m0 0L9 7"})})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-700 dark:text-slate-300",children:s("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs text-slate-500 dark:text-slate-400",children:s("settings.routing.emptySub",{default:"点击上方按钮添加路由规则"})})]})]})}):e.jsx("div",{className:"space-y-4",children:o.map((M,Ce)=>e.jsxs("div",{className:"rounded-xl border border-slate-200/50 bg-gradient-to-r from-white/90 to-white/85 p-4 shadow-sm backdrop-blur-sm transition-all duration-200 hover:border-slate-300/70 hover:bg-white/95 hover:shadow-md dark:border-slate-700/50 dark:from-slate-900/90 dark:to-slate-900/85 dark:hover:border-slate-600/70 dark:hover:bg-slate-900/95",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-blue-100 text-blue-600 dark:bg-blue-900/40 dark:text-blue-300",children:e.jsx("span",{className:"text-sm font-bold",children:Ce+1})}),e.jsx("span",{className:"text-sm font-medium text-slate-700 dark:text-slate-300",children:"路由规则"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("label",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:s("settings.routing.source")}),e.jsx("input",{type:"text",value:M.source,onChange:pe=>Me(t,M.id,"source",pe.target.value),className:ce,placeholder:"claude-3.5-sonnet",list:U,disabled:h})]})}),e.jsx("div",{className:"space-y-2",children:e.jsxs("label",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:s("settings.routing.target")}),(()=>{const pe=M.target.trim(),Ye=Qe.some(G=>G.value===pe)?pe:"__custom";return e.jsxs(e.Fragment,{children:[e.jsxs("select",{value:Ye,onChange:G=>{const Xe=G.target.value;Xe==="__custom"?Me(t,M.id,"target",pe):Me(t,M.id,"target",Xe)},className:ct,disabled:h,children:[e.jsx("option",{value:"__custom",children:s("settings.routing.customTargetOption")}),Qe.map(G=>e.jsx("option",{value:G.value,children:G.label},`${K}-${G.value}`))]}),Ye==="__custom"&&e.jsx("input",{type:"text",value:M.target,onChange:G=>Me(t,M.id,"target",G.target.value),className:ce,placeholder:"providerId:modelId",disabled:h})]})})()]})}),e.jsx("div",{className:"flex items-end",children:e.jsx("button",{type:"button",className:$e,onClick:()=>Ct(t,M.id),disabled:h,children:s("settings.routing.remove")})})]})]},M.id))}),e.jsx("div",{className:"rounded-xl border border-slate-200/40 bg-gradient-to-r from-slate-50/80 to-white/70 p-4 dark:border-slate-700/40 dark:from-slate-800/60 dark:to-slate-900/70 backdrop-blur-sm",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-[0.15em] text-slate-600 dark:text-slate-300",children:s("settings.routing.suggested")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:i.map(M=>e.jsx("button",{type:"button",onClick:()=>Et(t,M),className:q,disabled:h,children:M},`${t}-${M}`))})]})}),e.jsx("datalist",{id:U,children:i.map(M=>e.jsx("option",{value:M},`${U}-${M}`))})]})};return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx("div",{className:It,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("h1",{className:"text-3xl font-bold bg-gradient-to-r from-slate-900 to-slate-700 bg-clip-text text-transparent dark:from-slate-100 dark:to-slate-300",children:s("modelManagement.title")}),e.jsx("p",{className:"text-base text-slate-600 dark:text-slate-400",children:s("modelManagement.description")})]}),e.jsxs("button",{onClick:()=>{ke(void 0),ve(!0)},className:oe,children:["+ ",s("modelManagement.addEndpoint")]})]})}),e.jsx("div",{className:"flex flex-wrap gap-4",children:d.map(t=>{const o=x===t.key;return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>N(t.key),className:`flex min-w-[240px] flex-col gap-2 rounded-2xl border px-6 py-4 text-left transition-all duration-300 hover-lift ${o?"border-blue-500/30 bg-gradient-to-r from-blue-50 to-indigo-50 text-blue-700 shadow-lg shadow-blue-200/40 ring-1 ring-blue-500/20 dark:border-blue-400/30 dark:from-blue-900/40 dark:to-indigo-900/30 dark:text-blue-100 dark:shadow-xl dark:shadow-blue-500/20 dark:ring-blue-400/20":"border-slate-200/50 bg-white/80 hover:bg-white/90 hover:shadow-md hover:shadow-slate-200/30 dark:border-slate-700/50 dark:bg-slate-900/80 dark:hover:bg-slate-900/90 dark:hover:shadow-lg dark:hover:shadow-slate-900/30"}`,children:[e.jsx("span",{className:"text-base font-bold",children:t.label}),e.jsx("span",{className:"text-sm text-slate-600 dark:text-slate-400",children:t.description})]}),t.canDelete&&e.jsx("button",{onClick:r=>{r.stopPropagation(),kt(t.key)},className:"absolute -top-2 -right-2 h-6 w-6 rounded-full bg-red-500 text-white hover:bg-red-600 flex items-center justify-center text-xs shadow-md",title:s("common.delete"),children:"×"})]},t.key)})}),x==="providers"?Pt():Ot(x),e.jsx(qt,{open:I,mode:B,provider:B==="edit"?y:void 0,existingProviderIds:H.map(t=>t.id).filter(t=>B==="edit"&&y?t!==y.id:!0),onClose:()=>{O(!1),E(void 0),V("create")},onSubmit:vt}),e.jsx(Xt,{open:fe,endpoint:ue,onClose:()=>{ve(!1),ke(void 0)},onSuccess:()=>{c.invalidateQueries({queryKey:["custom-endpoints"]})}}),e.jsx(Jt,{open:Ne,provider:Ue,options:be,preservedExtras:He,usePreset:we,onPresetChange:Le,onConfirm:yt,onClose:Je})]})}function Jt({open:s,provider:a,options:c,usePreset:m,preservedExtras:p,onPresetChange:j,onConfirm:d,onClose:x}){const{t:N}=Pe();return!s||!a?null:e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-slate-900/60 backdrop-blur-sm",onClick:x,"aria-hidden":"true"}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"connection-test-dialog-title",className:"relative z-10 w-full max-w-lg rounded-2xl border border-slate-200/70 bg-white/95 p-6 shadow-2xl backdrop-blur-xl animate-fade-in dark:border-slate-800/60 dark:bg-slate-900/95",children:[e.jsxs("header",{className:"mb-4 space-y-1",children:[e.jsx("h2",{id:"connection-test-dialog-title",className:"text-lg font-semibold text-slate-900 dark:text-slate-100",children:N("providers.testDialog.title")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:N("providers.testDialog.subtitle",{name:a.label||a.id})})]}),e.jsx("p",{className:"mb-5 text-sm leading-relaxed text-slate-600 dark:text-slate-300",children:N("providers.testDialog.description")}),e.jsx("div",{className:"space-y-3",children:e.jsxs("label",{className:"flex items-start gap-3 rounded-xl border border-slate-200 bg-white/90 p-4 shadow-sm transition hover:border-blue-200 hover:bg-blue-50/70 dark:border-slate-700 dark:bg-slate-800/70 dark:hover:border-blue-500/60 dark:hover:bg-slate-800",children:[e.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 rounded border-slate-300 text-blue-600 focus:ring-blue-500",checked:m,onChange:b=>j(b.target.checked)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-800 dark:text-slate-100",children:N("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs leading-relaxed text-slate-500 dark:text-slate-400",children:N("providers.testDialog.presetDescription")}),e.jsxs("details",{className:"rounded-lg bg-slate-50/60 px-3 py-2 text-xs text-slate-600 transition dark:bg-slate-800/50 dark:text-slate-300",children:[e.jsx("summary",{className:"cursor-pointer text-blue-600 hover:underline dark:text-blue-300",children:N("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 grid gap-1",children:c.map(b=>e.jsxs("code",{className:"rounded bg-white/80 px-2 py-1 text-[11px] text-slate-700 shadow-sm dark:bg-slate-900/60 dark:text-slate-200",children:[b.key,": ",b.value]},b.key))})]})]})]})}),Object.keys(p).length>0?e.jsxs("div",{className:"mt-6 rounded-xl border border-slate-200 bg-slate-50/80 p-4 text-xs text-slate-600 dark:border-slate-700 dark:bg-slate-800/60 dark:text-slate-300",children:[e.jsx("p",{className:"mb-2 font-semibold text-slate-700 dark:text-slate-200",children:N("providers.testDialog.preservedInfo")}),e.jsx("div",{className:"grid gap-2",children:Object.entries(p).map(([b,P])=>e.jsxs("code",{className:"rounded bg-white/70 px-2 py-1 text-[11px] text-slate-700 shadow-sm dark:bg-slate-900/70 dark:text-slate-200",children:[b,": ",P]},b))})]}):null,e.jsxs("footer",{className:"mt-6 flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:x,className:q,children:N("providers.testDialog.cancel")}),e.jsx("button",{type:"button",onClick:()=>{d()},className:oe,children:N("providers.testDialog.primary")})]})]})]})}function lt(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function Yt({type:s}){const a={openai:{label:"OpenAI",color:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300"},deepseek:{label:"DeepSeek",color:"bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300"},huawei:{label:"华为云",color:"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300"},kimi:{label:"Kimi",color:"bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300"},anthropic:{label:"Anthropic",color:"bg-indigo-100 text-indigo-700 dark:bg-indigo-900/40 dark:text-indigo-300"},custom:{label:"Custom",color:"bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300"}},{label:c,color:m}=a[s]||a.custom;return e.jsx("span",{className:`rounded-full ${m} px-2.5 py-1 text-xs font-semibold shadow-sm`,children:c})}function Xt({open:s,endpoint:a,onClose:c,onSuccess:m}){const{t:p}=Pe(),{pushToast:j}=it(),[d,x]=g.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});g.useEffect(()=>{if(a){let y;a.paths&&a.paths.length>0?y=a.paths:a.path&&a.protocol?y=[{path:a.path,protocol:a.protocol}]:y=[{path:"",protocol:"openai-auto"}],x({id:a.id,label:a.label,paths:y,enabled:a.enabled!==!1})}else x({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[a,s]);const N=at({mutationFn:ge.create,onSuccess:()=>{j({title:p("modelManagement.createEndpointSuccess"),variant:"success"}),m(),c()},onError:y=>{const E=Re(y);j({title:p("modelManagement.createEndpointError",{error:E.message}),variant:"error"})}}),b=at({mutationFn:y=>ge.update(y.id,y.updates),onSuccess:()=>{j({title:p("modelManagement.updateEndpointSuccess"),variant:"success"}),m(),c()},onError:y=>{const E=Re(y);j({title:p("modelManagement.updateEndpointError",{error:E.message}),variant:"error"})}}),P=()=>{x({...d,paths:[...d.paths,{path:"",protocol:"anthropic"}]})},I=y=>{if(d.paths.length===1){j({title:p("modelManagement.atLeastOnePath"),variant:"error"});return}const E=d.paths.filter((D,L)=>L!==y);x({...d,paths:E})},O=(y,E,D)=>{const L=[...d.paths];L[y]={...L[y],[E]:D},x({...d,paths:L})},B=y=>{if(y.preventDefault(),!d.id.trim()||!d.label.trim()){j({title:p("modelManagement.endpointValidationError"),variant:"error"});return}for(const D of d.paths)if(!D.path.trim()){j({title:p("modelManagement.pathValidationError"),variant:"error"});return}const E=d.paths.map(D=>({path:D.path.trim(),protocol:D.protocol}));a?b.mutate({id:a.id,updates:{label:d.label.trim(),paths:E,enabled:d.enabled}}):N.mutate({id:d.id.trim(),label:d.label.trim(),paths:E,enabled:d.enabled})},V=N.isPending||b.isPending;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 dark:bg-black/70 z-40 transition-opacity",onClick:c}),e.jsx("div",{className:"fixed inset-y-0 right-0 w-full max-w-md bg-white dark:bg-gray-900 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 border-gray-200 dark:border-gray-800",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-gray-100",children:p(a?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("button",{onClick:c,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",children:e.jsx("svg",{className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("form",{onSubmit:B,className:"flex-1 p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[p("modelManagement.endpointId")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:d.id,onChange:y=>x({...d,id:y.target.value}),className:ce,placeholder:p("modelManagement.endpointIdPlaceholder"),disabled:!!a,required:!0}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:p("modelManagement.endpointIdHint")})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:[p("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:d.label,onChange:y=>x({...d,label:y.target.value}),className:ce,placeholder:p("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:[p("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("button",{type:"button",onClick:P,className:"text-sm text-blue-600 hover:text-blue-700 dark:text-blue-400 dark:hover:text-blue-300",children:["+ ",p("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:d.paths.map((y,E)=>e.jsxs("div",{className:"p-3 border border-gray-200 dark:border-gray-700 rounded-lg 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("input",{type:"text",value:y.path,onChange:D=>O(E,"path",D.target.value),className:ce,placeholder:p("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs("select",{value:y.protocol,onChange:D=>O(E,"protocol",D.target.value),className:ct,required:!0,children:[e.jsx("option",{value:"anthropic",children:p("modelManagement.protocolAnthropic")}),e.jsx("option",{value:"openai-auto",children:p("modelManagement.protocolOpenAI")})]})]}),d.paths.length>1&&e.jsx("button",{type:"button",onClick:()=>I(E),className:"text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 mt-1",title:p("modelManagement.removePath"),children:e.jsx("svg",{className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]}),E===0&&e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:p("modelManagement.endpointPathHint")})]},E))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",id:"enabled",checked:d.enabled,onChange:y=>x({...d,enabled:y.target.checked}),className:"h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-700 dark:bg-gray-800"}),e.jsx("label",{htmlFor:"enabled",className:"text-sm text-gray-700 dark:text-gray-300",children:p("modelManagement.endpointEnabled")})]}),!a&&e.jsx("div",{className:"rounded-lg bg-blue-50 dark:bg-blue-900/20 p-4",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-300",children:p("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 p-6 border-t border-gray-200 dark:border-gray-800",children:[e.jsx("button",{type:"button",onClick:c,className:`${q} flex-1`,disabled:V,children:p("common.cancel")}),e.jsx("button",{type:"submit",onClick:B,className:`${oe} flex-1`,disabled:V,children:p(V?"common.saving":a?"common.save":"common.create")})]})]})})]}):null}export{as as default};
@@ -1 +0,0 @@
1
- import{j as e,d as s,a6 as u,m,a7 as h,G as f,a8 as g,a9 as o,J as p}from"./index-BoThpdfs.js";function j({icon:a,title:r,description:l,badge:d,actions:n,className:i,disableAnimation:t,variant:x="default"}){const c=x==="plain"?h:f;return e.jsxs("div",{className:s(c,!t&&"animate-slide-up",i),children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-6",children:[a?e.jsx("div",{className:"grid h-14 w-14 place-items-center rounded-2xl bg-gradient-to-br from-blue-600/15 to-indigo-600/10 text-blue-600 shadow-lg shadow-blue-200/30 ring-1 ring-blue-500/20 backdrop-blur-sm dark:from-blue-500/25 dark:to-indigo-500/15 dark:text-blue-200 dark:shadow-xl dark:shadow-blue-500/20 dark:ring-blue-400/20",children:a}):null,e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight text-slate-900 dark:text-slate-50 gradient-text",children:r}),d?e.jsx("span",{className:s(u,"shadow-md"),children:d}):null]}),l?e.jsx("div",{className:s(m,"max-w-3xl text-base leading-relaxed"),children:l}):null]})]}),n?e.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-4",children:n}):null]})}function N({title:a,description:r,actions:l,className:d,contentClassName:n,children:i,disableAnimation:t,variant:x="default"}){const c=x==="plain"?o:p;return e.jsxs("section",{className:s(c,!t&&"animate-slide-up",d),children:[(a||r||l)&&e.jsxs("div",{className:"mb-6 flex flex-wrap items-center justify-between gap-6",children:[e.jsxs("div",{className:"space-y-3",children:[typeof a=="string"?e.jsx("h2",{className:s(g,"text-base font-bold"),children:a}):a,r?e.jsx("div",{className:s(m,"max-w-3xl text-sm leading-relaxed"),children:r}):null]}),l?e.jsx("div",{className:"flex shrink-0 items-center gap-3",children:l}):null]}),e.jsx("div",{className:s("flex flex-col gap-6",n),children:i})]})}export{j as P,N as a};