@chenpu17/cc-gw 0.8.0-alpha.9 → 0.8.0-beta.2

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.
Files changed (64) hide show
  1. package/README.md +18 -2
  2. package/package.json +9 -5
  3. package/src/cli/dist/index.js +0 -2
  4. package/src/web/dist/assets/About-bnb_BU6z.js +1 -0
  5. package/src/web/dist/assets/ApiKeys-DXJYgiYr.js +1 -0
  6. package/src/web/dist/assets/Dashboard-_T1jT56-.js +1 -0
  7. package/src/web/dist/assets/DialogShell-s3yKnQyp.js +1 -0
  8. package/src/web/dist/assets/EChart-Dqa_Xbrn.js +1 -0
  9. package/src/web/dist/assets/Events-B7l9cIhA.js +1 -0
  10. package/src/web/dist/assets/Help-M_B7c7Hj.js +8 -0
  11. package/src/web/dist/assets/Login-CXG8h1Xd.js +1 -0
  12. package/src/web/dist/assets/Logs-DVPaFD7W.js +1 -0
  13. package/src/web/dist/assets/ModelManagement-m4p97Xel.js +1 -0
  14. package/src/web/dist/assets/PageHeader-KQ9mjVAV.js +1 -0
  15. package/src/web/dist/assets/PageSection-C9Wb9Oe3.js +1 -0
  16. package/src/web/dist/assets/PageState-D-1-sNyq.js +1 -0
  17. package/src/web/dist/assets/Profiler-Bb-I7NR2.js +1 -0
  18. package/src/web/dist/assets/Settings-CdZ_GGjR.js +1 -0
  19. package/src/web/dist/assets/Skeleton-H3SErRWs.js +1 -0
  20. package/src/web/dist/assets/badge-3ORqzzzc.js +1 -0
  21. package/src/web/dist/assets/card-D1l7si2X.js +1 -0
  22. package/src/web/dist/assets/{charts-core-BE9sa9zn.js → charts-core-vuhzGmuT.js} +1 -1
  23. package/src/web/dist/assets/{charts-engine-DAwKT7Yg.js → charts-engine-BJQRnjQ_.js} +1 -1
  24. package/src/web/dist/assets/{charts-react-Dnkr-ZWt.js → charts-react-BeVWPrMt.js} +1 -1
  25. package/src/web/dist/assets/gateway-CFNtAOS2.js +1 -0
  26. package/src/web/dist/assets/{i18n-CZ1qKIdj.js → i18n-CfLThlXq.js} +1 -1
  27. package/src/web/dist/assets/index-8bCfrPhk.css +1 -0
  28. package/src/web/dist/assets/index-MqPrlTQ4.js +61 -0
  29. package/src/web/dist/assets/input-Bb_t6wr6.js +1 -0
  30. package/src/web/dist/assets/{label-V0fmEe3U.js → label-8HO4VSYV.js} +1 -1
  31. package/src/web/dist/assets/popover-5I-o07-i.js +1 -0
  32. package/src/web/dist/assets/{query-CDpWKdnY.js → query-D3IfCUhp.js} +1 -1
  33. package/src/web/dist/assets/queryKeys-BMvyDTQS.js +1 -0
  34. package/src/web/dist/assets/radix-54BMi3RD.js +5 -0
  35. package/src/web/dist/assets/{router-DjNibHfR.js → router-CmaL1NgV.js} +2 -2
  36. package/src/web/dist/assets/select-kdaAyzec.js +1 -0
  37. package/src/web/dist/assets/{switch-V4Qh3v7X.js → switch-DLCOPP-U.js} +1 -1
  38. package/src/web/dist/assets/useApiQuery-Bcqr7uHV.js +1 -0
  39. package/src/web/dist/assets/useAppMutation-CqHoYeK1.js +1 -0
  40. package/src/web/dist/assets/utils-DQfq7gRo.js +1 -0
  41. package/src/web/dist/assets/{vendor-C92xTG6Z.js → vendor-CjJPKsTb.js} +125 -65
  42. package/src/web/dist/index.html +7 -7
  43. package/src/web/dist/assets/About-COC-5-Wo.js +0 -1
  44. package/src/web/dist/assets/ApiKeys-G_iglpy4.js +0 -1
  45. package/src/web/dist/assets/ConfirmDialog-B6Hd3Eud.js +0 -1
  46. package/src/web/dist/assets/Dashboard-CDrlVQsE.js +0 -1
  47. package/src/web/dist/assets/EChart-C_zeFtIj.js +0 -1
  48. package/src/web/dist/assets/Events-BJ2HraCN.js +0 -1
  49. package/src/web/dist/assets/Help-CUSHbKKs.js +0 -8
  50. package/src/web/dist/assets/Login-BUlmZ2Fi.js +0 -1
  51. package/src/web/dist/assets/Logs-cCODXwO-.js +0 -1
  52. package/src/web/dist/assets/ModelManagement-D9av2Cfc.js +0 -1
  53. package/src/web/dist/assets/PageHeader-BIhjesDo.js +0 -1
  54. package/src/web/dist/assets/PageSection-CTHA3Yub.js +0 -1
  55. package/src/web/dist/assets/Settings-DF49sT5q.js +0 -1
  56. package/src/web/dist/assets/Skeleton-D7zoK-3P.js +0 -1
  57. package/src/web/dist/assets/card-DKAxXuqe.js +0 -1
  58. package/src/web/dist/assets/index-NGg4j8sr.css +0 -1
  59. package/src/web/dist/assets/index-zyFaDjL5.js +0 -61
  60. package/src/web/dist/assets/input-CKjvZhjf.js +0 -1
  61. package/src/web/dist/assets/popover-CSAdpdw2.js +0 -1
  62. package/src/web/dist/assets/radix-Ccu1urVd.js +0 -5
  63. package/src/web/dist/assets/select-B9GMWo4R.js +0 -1
  64. package/src/web/dist/assets/useApiQuery-HKJqYJso.js +0 -1
@@ -5,13 +5,13 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no" />
6
6
  <meta name="format-detection" content="telephone=no" />
7
7
  <title>cc-gw 控制台</title>
8
- <script type="module" crossorigin src="/assets/index-zyFaDjL5.js"></script>
9
- <link rel="modulepreload" crossorigin href="/assets/vendor-C92xTG6Z.js">
10
- <link rel="modulepreload" crossorigin href="/assets/router-DjNibHfR.js">
11
- <link rel="modulepreload" crossorigin href="/assets/radix-Ccu1urVd.js">
12
- <link rel="modulepreload" crossorigin href="/assets/i18n-CZ1qKIdj.js">
13
- <link rel="modulepreload" crossorigin href="/assets/query-CDpWKdnY.js">
14
- <link rel="stylesheet" crossorigin href="/assets/index-NGg4j8sr.css">
8
+ <script type="module" crossorigin src="/assets/index-MqPrlTQ4.js"></script>
9
+ <link rel="modulepreload" crossorigin href="/assets/vendor-CjJPKsTb.js">
10
+ <link rel="modulepreload" crossorigin href="/assets/query-D3IfCUhp.js">
11
+ <link rel="modulepreload" crossorigin href="/assets/i18n-CfLThlXq.js">
12
+ <link rel="modulepreload" crossorigin href="/assets/router-CmaL1NgV.js">
13
+ <link rel="modulepreload" crossorigin href="/assets/radix-54BMi3RD.js">
14
+ <link rel="stylesheet" crossorigin href="/assets/index-8bCfrPhk.css">
15
15
  </head>
16
16
  <body class="bg-slate-50 text-slate-900 dark:bg-slate-900 dark:text-slate-50">
17
17
  <div id="root"></div>
@@ -1 +0,0 @@
1
- import{r as i,f as e,ar as w,as as k,ad as E,a3 as I}from"./vendor-C92xTG6Z.js";import{u as L}from"./useApiQuery-HKJqYJso.js";import{u as C,B as j}from"./index-zyFaDjL5.js";import{P as S,B as o}from"./PageHeader-BIhjesDo.js";import{P as d}from"./PageSection-CTHA3Yub.js";import{C as N,a as y}from"./card-DKAxXuqe.js";import{u as B}from"./i18n-CZ1qKIdj.js";import"./query-CDpWKdnY.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";const P="0.8.0-alpha.9",V={version:P},M={VITE_BUILD_TIME:"2026-03-17T10:38:32.779Z"};function v({items:a}){return a.length===0?null:e.jsx("dl",{className:"grid gap-4 sm:grid-cols-2",children:a.map(s=>e.jsx(N,{className:"surface-1",children:e.jsxs(y,{className:"pt-4",children:[e.jsx("dt",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:s.label}),e.jsx("dd",{className:"mt-1 text-sm font-semibold",children:s.value}),s.hint&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s.hint})]})},s.label))})}function H(){var m,p,b,x,h,f,g;const{t:a}=B(),{pushToast:s}=C(),t=L(["status","gateway"],{url:"/api/status",method:"GET"},{staleTime:6e4});i.useEffect(()=>{t.isError&&t.error&&s({title:a("about.toast.statusError.title"),description:t.error.message,variant:"error"})},[t.isError,t.error,s,a]);const l=V.version,c=i.useMemo(()=>({buildTime:M.VITE_BUILD_TIME}),[]),T=i.useMemo(()=>{var r,n;return[{label:a("about.app.labels.name"),value:e.jsx("span",{className:"font-mono",children:"cc-gw"})},{label:a("about.app.labels.version"),value:e.jsxs("span",{className:"font-mono text-primary",children:["v",l]})},{label:a("about.app.labels.buildTime"),value:c.buildTime,hint:a("about.app.hint.buildTime")},{label:a("about.app.labels.runtime"),value:e.jsx("span",{className:"font-mono",children:((r=t.data)==null?void 0:r.runtime)??"rust"})},{label:a("about.app.labels.backendVersion"),value:e.jsx("span",{className:"font-mono",children:((n=t.data)==null?void 0:n.backendVersion)??"-"})}]},[l,c.buildTime,(m=t.data)==null?void 0:m.backendVersion,(p=t.data)==null?void 0:p.runtime,a]),u=i.useMemo(()=>{var r;return t.data?[{label:a("about.status.labels.host"),value:t.data.host??"127.0.0.1"},{label:a("about.status.labels.port"),value:t.data.port.toLocaleString()},{label:a("about.status.labels.providers"),value:t.data.providers.toLocaleString()},{label:a("about.status.labels.active"),value:(t.data.activeRequests??0).toLocaleString(),hint:a("about.status.hint.active")},{label:a("about.status.labels.platform"),value:t.data.platform??"-"},{label:a("about.status.labels.pid"),value:((r=t.data.pid)==null?void 0:r.toLocaleString())??"-"}]:[]},[t.data,a]),_=()=>{s({title:a("about.toast.updatesPlanned"),variant:"info"})};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(S,{icon:e.jsx(k,{className:"h-5 w-5","aria-hidden":"true"}),title:a("about.title"),description:a("about.description"),badge:`v${l}`,actions:e.jsxs(j,{onClick:_,children:[e.jsx(w,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),a("about.support.actions.checkUpdates")]})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(o,{variant:"outline",children:((b=t.data)==null?void 0:b.runtime)??"rust"}),e.jsx(o,{variant:"outline",children:((x=t.data)==null?void 0:x.platform)??"-"}),e.jsxs(o,{variant:"secondary",children:[a("about.status.labels.providers"),": ",((f=(h=t.data)==null?void 0:h.providers)==null?void 0:f.toLocaleString())??"-"]}),e.jsxs(o,{variant:"secondary",children:[a("about.status.labels.active"),": ",(((g=t.data)==null?void 0:g.activeRequests)??0).toLocaleString()]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(d,{title:a("about.app.title"),description:a("about.app.subtitle"),children:e.jsx(v,{items:T})}),e.jsx(d,{title:a("about.status.title"),description:a("about.status.subtitle"),actions:e.jsxs(j,{variant:"outline",size:"sm",onClick:()=>t.refetch(),disabled:t.isFetching,children:[e.jsx(E,{className:`mr-2 h-4 w-4 ${t.isFetching?"animate-spin":""}`,"aria-hidden":"true"}),t.isFetching?a("common.actions.refreshing"):a("common.actions.refresh")]}),children:t.isLoading?e.jsxs("div",{className:"flex h-32 flex-col items-center justify-center gap-2 text-center",children:[e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-primary border-t-transparent"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("about.status.loading")})]}):u.length>0?e.jsx(v,{items:u}):e.jsxs("div",{className:"flex h-32 flex-col items-center justify-center gap-1 rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-6 text-center",children:[e.jsx("p",{className:"text-sm font-medium",children:a("about.status.empty")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("common.actions.refresh")})]})})]}),e.jsx(d,{title:a("about.support.title"),description:e.jsxs("span",{className:"space-y-1",children:[e.jsx("span",{className:"block text-sm font-medium text-primary",children:a("about.support.subtitle")}),e.jsx("span",{children:a("about.support.description")})]}),children:e.jsx(N,{className:"surface-1",children:e.jsxs(y,{className:"flex flex-col gap-4 pt-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-2xl bg-primary/10 text-primary shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]",children:e.jsx(I,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("p",{className:"flex-1 text-sm text-muted-foreground",children:a("about.support.tip")})]}),e.jsx("code",{className:"inline-flex self-start rounded-xl border border-border/70 bg-background/70 px-3 py-1.5 text-xs font-medium",children:"~/.cc-gw/config.json"})]})})})]})}export{H as default};
@@ -1 +0,0 @@
1
- import{r,f as e,aj as Oe,a1 as de,al as pe,am as me,an as ue,ao as We,ap as Fe,O as Pe}from"./vendor-C92xTG6Z.js";import{E as Ie}from"./EChart-C_zeFtIj.js";import{u as P}from"./useApiQuery-HKJqYJso.js";import{c as V,u as Re,h as Me,B as c,a as K,t as C}from"./index-zyFaDjL5.js";import{P as ze,B as y}from"./PageHeader-BIhjesDo.js";import{P as I}from"./PageSection-CTHA3Yub.js";import{D as R,a as M,b as z,c as $,d as xe,e as U,C as $e}from"./ConfirmDialog-B6Hd3Eud.js";import{c as Ue}from"./clipboard-CALi6bTW.js";import{I as he}from"./input-CKjvZhjf.js";import{L as G}from"./label-V0fmEe3U.js";import{C as J,a as X}from"./card-DKAxXuqe.js";import{u as Y}from"./i18n-CZ1qKIdj.js";import{e as Ge}from"./charts-core-BE9sa9zn.js";import"./charts-react-Dnkr-ZWt.js";import"./query-CDpWKdnY.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";import"./charts-engine-DAwKT7Yg.js";const be=r.forwardRef(({className:a,...i},l)=>e.jsx("textarea",{className:V("flex min-h-[96px] w-full rounded-[1.35rem] border border-border/80 bg-background/85 px-4 py-3 text-base shadow-[0_1px_2px_rgba(15,23,42,0.03)] ring-offset-background placeholder:text-muted-foreground/90 transition-all duration-200 focus-visible:border-primary/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/30 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",a),ref:l,...i}));be.displayName="Textarea";function He(){const[a,i]=r.useState([]);return r.useEffect(()=>{const l=[{id:"anthropic",label:"Anthropic"},{id:"openai",label:"OpenAI"}];K.get("/api/custom-endpoints").then(m=>{const x=(m.data.endpoints??[]).map(d=>({id:d.id,label:d.label}));i([...l,...x])}).catch(()=>{i(l)})},[]),a}function ye({available:a,selected:i,onChange:l,hint:m}){const{t:x}=Y(),d=i.length===0,E=()=>{l([])},N=o=>{i.includes(o)?l(i.filter(w=>w!==o)):l([...i,o])};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:m}),e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-2xl border border-border/70 bg-background/70 px-3 py-2.5 transition-colors hover:border-primary/20 hover:bg-primary/5",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:E,className:"h-4 w-4 rounded border-input accent-primary"}),e.jsx("span",{className:"text-sm font-medium",children:x("apiKeys.allEndpoints")})]}),e.jsx("div",{className:"grid max-h-40 gap-1 overflow-y-auto",children:a.map(o=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-2xl border border-border/70 bg-background/70 px-3 py-2.5 transition-colors hover:border-primary/20 hover:bg-primary/5",children:[e.jsx("input",{type:"checkbox",checked:!d&&i.includes(o.id),onChange:()=>N(o.id),className:"h-4 w-4 rounded border-input accent-primary"}),e.jsx("span",{className:"text-sm",children:o.label}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",o.id,")"]})]},o.id))})]})}function H({icon:a,title:i,description:l}){return e.jsxs("div",{className:"rounded-[1.25rem] border border-white/50 bg-card/88 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-2xl bg-primary/10 text-primary shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]",children:a}),e.jsx("p",{className:"mt-4 text-sm font-semibold",children:i}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:l})]})}const Qe=[{value:1,labelKey:"apiKeys.analytics.range.today"},{value:7,labelKey:"apiKeys.analytics.range.week"},{value:30,labelKey:"apiKeys.analytics.range.month"}];function ma(){const{t:a}=Y(),{pushToast:i}=Re(),[l,m]=r.useState(!1),[x,d]=r.useState(""),[E,N]=r.useState(""),[o,w]=r.useState([]),[p,L]=r.useState(null),[S,Z]=r.useState(null),[u,A]=r.useState(null),[b,fe]=r.useState(7),[ee,ae]=r.useState(new Map),[je,se]=r.useState(null),[f,D]=r.useState(null),[q,te]=r.useState([]),[O,ve]=r.useState(""),[_,Ke]=r.useState("all"),ie=He(),j=P(["api-keys"],{url:"/api/keys",method:"GET"}),T=P(["api-keys","overview",b],{url:"/api/stats/api-keys/overview",method:"GET",params:{days:b}}),k=P(["api-keys","usage",b],{url:"/api/stats/api-keys/usage",method:"GET",params:{days:b,limit:10}}),g=j.data??[],v=T.data,h=k.data??[],Ne=g.some(s=>s.isWildcard),re=g.filter(s=>{var t;return!s.isWildcard&&(((t=s.allowedEndpoints)==null?void 0:t.length)??0)>0}).length,we=v?v.totalKeys.toLocaleString():"-",ke=v?v.enabledKeys.toLocaleString():"-",Ce=v?v.activeKeys.toLocaleString():"-",W=r.useMemo(()=>g.filter(s=>{if(!(_==="all"||(_==="enabled"?s.enabled:!s.enabled)))return!1;const n=O.trim().toLowerCase();return n?[s.name,s.description??"",s.maskedKey??"",...s.allowedEndpoints??[]].join(" ").toLowerCase().includes(n):!0}),[g,O,_]),ne=async()=>{if(!x.trim()){i({title:a("apiKeys.errors.nameRequired"),variant:"error"});return}try{const s=await K.post("/api/keys",{name:x.trim(),description:E.trim()||void 0,allowedEndpoints:o.length>0?o:void 0});L(s.data),m(!1),d(""),N(""),w([]),j.refetch(),T.refetch(),k.refetch(),i({title:a("apiKeys.toast.keyCreated"),variant:"success"})}catch(s){const t=C(s);i({title:a("apiKeys.toast.createFailure",{message:t.message}),variant:"error"})}},Ee=async(s,t)=>{try{await K.patch(`/api/keys/${s}`,{enabled:!t}),j.refetch(),T.refetch(),i({title:a("apiKeys.toast.keyUpdated"),variant:"success"})}catch(n){const F=C(n);i({title:a("apiKeys.toast.updateFailure",{message:F.message}),variant:"error"})}},Se=async()=>{if(u){Z(u.id);try{await K.delete(`/api/keys/${u.id}`),j.refetch(),T.refetch(),k.refetch(),i({title:a("apiKeys.toast.keyDeleted"),variant:"success"}),A(null)}catch(s){const t=C(s);i({title:a("apiKeys.toast.deleteFailure",{message:t.message}),variant:"error"})}finally{Z(null)}}},De=async s=>{if(!ee.has(s)){se(s);try{const t=await K.get(`/api/keys/${s}/reveal`);ae(n=>new Map(n).set(s,t.data.key))}catch(t){const n=C(t);i({title:a("apiKeys.toast.revealFailure"),description:n.message,variant:"error"})}finally{se(null)}}},_e=s=>{ae(t=>{const n=new Map(t);return n.delete(s),n})},le=async s=>{try{await Ue(s),i({title:a("apiKeys.toast.keyCopied"),variant:"success"})}catch(t){i({title:a("apiKeys.toast.copyFailure"),description:t instanceof Error?t.message:a("common.unknownError"),variant:"error"})}},Te=r.useCallback(s=>{D(s),te(s.allowedEndpoints??[])},[]),Le=async()=>{if(f)try{await K.patch(`/api/keys/${f.id}`,{allowedEndpoints:q.length>0?q:null}),D(null),j.refetch(),i({title:a("apiKeys.toast.keyUpdated"),variant:"success"})}catch(s){const t=C(s);i({title:a("apiKeys.toast.updateFailure",{message:t.message}),variant:"error"})}},oe=s=>s?new Date(s).toLocaleString():a("common.noData"),Ae=r.useMemo(()=>{const s=h.map(t=>t.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:h.map(t=>t.requests),itemStyle:{color:"hsl(var(--primary))"}}]}},[h,a]),qe=r.useMemo(()=>{const s=h.map(t=>t.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:h.map(t=>t.inputTokens)},{name:a("apiKeys.analytics.tokens.output"),type:"bar",stack:"tokens",itemStyle:{color:"#0ea5e9"},data:h.map(t=>t.outputTokens)}]}},[h,a]);return j.isLoading?e.jsx(Me,{}):e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ze,{icon:e.jsx(de,{className:"h-5 w-5","aria-hidden":"true"}),title:a("apiKeys.title"),description:a("apiKeys.description"),eyebrow:"Access Control",breadcrumb:"Gateway / API Keys",helper:a("apiKeys.helper"),actions:e.jsxs(c,{onClick:()=>m(!0),children:[e.jsx(Oe,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),a("apiKeys.createNew")]})}),e.jsx(I,{eyebrow:"Recommended",title:a("apiKeys.quickStart.title"),description:a("apiKeys.quickStart.description"),contentClassName:"pt-5",children:e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(H,{icon:e.jsx(de,{className:"h-4 w-4","aria-hidden":"true"}),title:a("apiKeys.quickStart.create.title"),description:a("apiKeys.quickStart.create.description")}),e.jsx(H,{icon:e.jsx(pe,{className:"h-4 w-4","aria-hidden":"true"}),title:a("apiKeys.quickStart.restrict.title"),description:a("apiKeys.quickStart.restrict.description")}),e.jsx(H,{icon:e.jsx(me,{className:"h-4 w-4","aria-hidden":"true"}),title:a("apiKeys.quickStart.wildcard.title"),description:a("apiKeys.quickStart.wildcard.description")})]})}),e.jsx(I,{eyebrow:"Usage",title:a("apiKeys.analytics.title"),description:a("apiKeys.analytics.description",{days:b}),actions:e.jsx("div",{className:"flex items-center gap-1 rounded-full border border-border/70 bg-background/80 p-1 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:Qe.map(s=>{const t=b===s.value;return e.jsx("button",{type:"button",onClick:()=>fe(s.value),className:V("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",t?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:a(s.labelKey)},s.value)})}),children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(Q,{label:a("apiKeys.analytics.cards.total"),value:we}),e.jsx(Q,{label:a("apiKeys.analytics.cards.enabled"),value:ke}),e.jsx(Q,{label:a("apiKeys.analytics.cards.active",{days:b}),value:Ce})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(ge,{title:a("apiKeys.analytics.charts.requests"),loading:k.isLoading,empty:h.length===0,emptyText:a("apiKeys.analytics.empty"),option:Ae}),e.jsx(ge,{title:a("apiKeys.analytics.charts.tokens"),loading:k.isLoading,empty:h.length===0,emptyText:a("apiKeys.analytics.empty"),option:qe})]})]})}),e.jsx(I,{eyebrow:"Inventory",title:a("apiKeys.list.title"),description:Ne?a("apiKeys.wildcardHint"):void 0,actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(y,{variant:"outline",children:`${W.length}/${g.length}`}),e.jsx(y,{variant:"outline",children:a("apiKeys.summary.wildcard",{count:g.filter(s=>s.isWildcard).length})}),e.jsx(y,{variant:"outline",children:a("apiKeys.summary.restricted",{count:re})})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-3 rounded-2xl border border-white/40 bg-card/80 p-4 md:grid-cols-[minmax(0,1fr)_180px_auto]",children:[e.jsx(he,{value:O,onChange:s=>ve(s.target.value),placeholder:a("apiKeys.filters.searchPlaceholder")}),e.jsx("div",{className:"flex items-center gap-1 rounded-full border border-border/70 bg-background/80 p-1 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:["all","enabled","disabled"].map(s=>e.jsx("button",{type:"button",onClick:()=>Ke(s),className:V("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",_===s?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:a(`apiKeys.filters.${s}`)},s))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(y,{variant:"outline",children:a("apiKeys.summary.wildcard",{count:g.filter(s=>s.isWildcard).length})}),e.jsx(y,{variant:"outline",children:a("apiKeys.summary.restricted",{count:re})})]})]}),g.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center rounded-[1.25rem] border border-dashed border-border/70 bg-background/45",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:a("apiKeys.list.empty")})}):W.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center rounded-[1.25rem] border border-dashed border-border/70 bg-background/45",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:a("apiKeys.list.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4",children:W.map(s=>{const t=(s.totalInputTokens+s.totalOutputTokens).toLocaleString(),n=ee.get(s.id),F=je===s.id;return e.jsx(J,{className:"border-white/40 bg-card/90 backdrop-blur",children:e.jsx(X,{className:"space-y-4 pt-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-base font-semibold",children:s.name}),s.isWildcard&&e.jsx(y,{variant:"secondary",children:a("apiKeys.wildcard")}),e.jsx(y,{variant:s.enabled?"default":"outline",children:s.enabled?a("apiKeys.status.enabled"):a("apiKeys.status.disabled")}),!s.isWildcard&&s.allowedEndpoints&&s.allowedEndpoints.length>0?s.allowedEndpoints.map(ce=>e.jsx(y,{variant:"outline",className:"text-xs",children:ce},ce)):s.isWildcard?null:e.jsx(y,{variant:"secondary",className:"text-xs opacity-60",children:a("apiKeys.allEndpoints")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(B,{label:a("apiKeys.requestCount"),value:s.requestCount.toLocaleString()}),e.jsx(B,{label:a("apiKeys.totalTokens"),value:t}),e.jsx(B,{label:a("apiKeys.allowedEndpoints"),value:s.isWildcard?a("apiKeys.wildcard"):s.allowedEndpoints&&s.allowedEndpoints.length>0?s.allowedEndpoints.join(", "):a("apiKeys.allEndpoints")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"rounded-xl border border-border/70 bg-background/70 px-3 py-1.5 font-mono text-sm",children:s.isWildcard?a("apiKeys.wildcard"):n??s.maskedKey??"********"}),!s.isWildcard&&e.jsx("div",{className:"flex items-center gap-1",children:n?e.jsxs(e.Fragment,{children:[e.jsx(c,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>void le(n),"aria-label":a("common.actions.copy"),title:a("common.actions.copy"),children:e.jsx(ue,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx(c,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>_e(s.id),"aria-label":a("apiKeys.actions.hide"),title:a("apiKeys.actions.hide"),children:e.jsx(me,{className:"h-4 w-4","aria-hidden":"true"})})]}):e.jsx(c,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>void De(s.id),disabled:F,"aria-label":a("apiKeys.actions.reveal"),title:a("apiKeys.actions.reveal"),children:e.jsx(We,{className:"h-4 w-4","aria-hidden":"true"})})})]}),s.isWildcard?e.jsx("p",{className:"text-sm text-muted-foreground",children:a("apiKeys.wildcardHint")}):s.description?e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:s.description}):null,e.jsxs("div",{className:"grid gap-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:a("apiKeys.created")}),e.jsx("p",{className:"font-medium",children:oe(s.createdAt)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:a("apiKeys.lastUsed")}),e.jsx("p",{className:"font-medium",children:oe(s.lastUsedAt)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!s.isWildcard&&e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>Te(s),children:[e.jsx(pe,{className:"mr-1 h-3.5 w-3.5","aria-hidden":"true"}),a("apiKeys.editEndpoints")]}),e.jsx(c,{variant:s.enabled?"outline":"default",size:"sm",onClick:()=>Ee(s.id,s.enabled),children:s.enabled?a("apiKeys.actions.disable"):a("apiKeys.actions.enable")}),!s.isWildcard&&e.jsx(c,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:()=>A(s),disabled:S===s.id,"aria-label":a("apiKeys.actions.delete"),children:e.jsx(Fe,{className:"h-4 w-4","aria-hidden":"true"})})]})]})})},s.id)})})]})}),e.jsx(R,{open:l,onOpenChange:m,children:e.jsxs(M,{children:[e.jsxs(z,{children:[e.jsx($,{children:a("apiKeys.createNew")}),e.jsx(xe,{children:a("apiKeys.createDescription")})]}),e.jsxs("div",{className:"min-h-0 space-y-4 overflow-y-auto",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(G,{htmlFor:"keyName",children:[a("apiKeys.keyNamePlaceholder")," *"]}),e.jsx(he,{id:"keyName",value:x,onChange:s=>d(s.target.value),placeholder:a("apiKeys.keyNamePlaceholder"),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),ne())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{htmlFor:"keyDescription",children:a("apiKeys.descriptionLabel")}),e.jsx(be,{id:"keyDescription",value:E,onChange:s=>N(s.target.value),placeholder:a("apiKeys.keyDescriptionPlaceholder"),rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{children:a("apiKeys.allowedEndpoints")}),e.jsx(ye,{available:ie,selected:o,onChange:w,hint:a("apiKeys.selectEndpoints")})]})]}),e.jsxs(U,{children:[e.jsx(c,{variant:"outline",onClick:()=>{m(!1),d(""),N(""),w([])},children:a("common.actions.cancel")}),e.jsx(c,{onClick:()=>void ne(),children:a("apiKeys.createAction")})]})]})}),e.jsx(R,{open:!!p,onOpenChange:()=>L(null),children:e.jsxs(M,{children:[e.jsx(z,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-600",children:e.jsx(Pe,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx($,{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-[1.1rem] border border-border/70 bg-background/70 px-4 py-3 font-mono text-sm",children:p==null?void 0:p.key}),(p==null?void 0:p.description)&&e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:p.description}),e.jsxs(U,{children:[e.jsxs(c,{onClick:()=>void le((p==null?void 0:p.key)??""),children:[e.jsx(ue,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),a("common.actions.copy")]}),e.jsx(c,{variant:"outline",onClick:()=>L(null),children:a("common.actions.close")})]})]})}),e.jsx(R,{open:!!f,onOpenChange:s=>{s||D(null)},children:e.jsxs(M,{children:[e.jsxs(z,{children:[e.jsx($,{children:a("apiKeys.editEndpoints")}),e.jsx(xe,{children:f==null?void 0:f.name})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto",children:e.jsx(ye,{available:ie,selected:q,onChange:te,hint:a("apiKeys.selectEndpoints")})}),e.jsxs(U,{children:[e.jsx(c,{variant:"outline",onClick:()=>D(null),children:a("common.actions.cancel")}),e.jsx(c,{onClick:()=>void Le(),children:a("common.save")})]})]})}),e.jsx($e,{open:!!u,onOpenChange:s=>{!s&&S===null&&A(null)},title:a("apiKeys.deleteDialogTitle"),description:a("apiKeys.confirmDelete"),confirmLabel:u&&S===u.id?a("common.actions.loading"):a("apiKeys.actions.delete"),cancelLabel:a("common.actions.cancel"),loading:u?S===u.id:!1,onConfirm:Se,children:u?e.jsx("div",{className:"rounded-[1.1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:u.name}):null})]})}function Q({label:a,value:i}){return e.jsx(J,{className:"surface-1",children:e.jsxs(X,{className:"pt-4",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:a}),e.jsx("p",{className:"mt-2 text-2xl font-semibold",children:i})]})})}function B({label:a,value:i}){return e.jsxs("div",{className:"rounded-xl border border-border/70 bg-background/60 px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a}),e.jsx("p",{className:"mt-1 truncate text-sm font-medium",children:i})]})}function ge({title:a,option:i,loading:l,empty:m,emptyText:x}){const{t:d}=Y();return e.jsx(J,{className:"surface-1",children:e.jsxs(X,{className:"space-y-4 pt-4",children:[e.jsx("h3",{className:"text-base font-semibold",children:a}),l?e.jsx("div",{className:"flex h-[280px] items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:d("common.loadingShort")})}):m?e.jsx("div",{className:"flex h-[280px] items-center justify-center rounded-[1.25rem] border border-dashed border-border/70 bg-background/45",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:x})}):e.jsx(Ie,{echarts:Ge,option:i,style:{height:280},notMerge:!0,lazyUpdate:!0})]})})}export{ma as default};
@@ -1 +0,0 @@
1
- import{r,f as a,a5 as w}from"./vendor-C92xTG6Z.js";import{F as k,G as C,H as c,J as R,K as m,M as x,O as f}from"./radix-Ccu1urVd.js";import{c as o,B as i}from"./index-zyFaDjL5.js";const z=k,_=C,p=r.forwardRef(({className:s,...e},t)=>a.jsx(f,{ref:t,className:o("fixed inset-0 z-50 bg-slate-950/45 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...e}));p.displayName=f.displayName;const u=r.forwardRef(({className:s,children:e,...t},l)=>a.jsxs(_,{children:[a.jsx(p,{}),a.jsxs(c,{ref:l,className:o("fixed left-[50%] top-[50%] z-50 flex max-h-[85vh] w-full max-w-lg translate-x-[-50%] translate-y-[-50%] flex-col gap-4 rounded-[1.5rem] border border-white/60 bg-background/96 p-6 shadow-[0_24px_64px_-28px_rgba(15,23,42,0.42)] backdrop-blur duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]",s),...t,children:[e,a.jsxs(R,{className:"absolute right-4 top-4 rounded-2xl border border-transparent p-2 opacity-70 ring-offset-background transition-all hover:border-border hover:bg-accent hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[a.jsx(w,{className:"h-4 w-4"}),a.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));u.displayName=c.displayName;const g=({className:s,...e})=>a.jsx("div",{className:o("flex shrink-0 flex-col space-y-1.5 text-center sm:text-left",s),...e});g.displayName="DialogHeader";const b=({className:s,...e})=>a.jsx("div",{className:o("flex shrink-0 flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...e});b.displayName="DialogFooter";const j=r.forwardRef(({className:s,...e},t)=>a.jsx(m,{ref:t,className:o("text-lg font-semibold leading-none tracking-[-0.02em]",s),...e}));j.displayName=m.displayName;const h=r.forwardRef(({className:s,...e},t)=>a.jsx(x,{ref:t,className:o("text-sm leading-6 text-muted-foreground",s),...e}));h.displayName=x.displayName;function E({open:s,onOpenChange:e,title:t,description:l,confirmLabel:N,cancelLabel:y,onConfirm:v,loading:d=!1,confirmVariant:D="destructive",children:n}){return a.jsx(z,{open:s,onOpenChange:e,children:a.jsxs(u,{className:"max-w-md",children:[a.jsxs(g,{children:[a.jsx(j,{children:t}),l?a.jsx(h,{children:l}):null]}),n?a.jsx("div",{className:"text-sm text-muted-foreground",children:n}):null,a.jsxs(b,{children:[a.jsx(i,{variant:"outline",onClick:()=>e(!1),disabled:d,children:y}),a.jsx(i,{variant:D,onClick:()=>void v(),disabled:d,children:N})]})]})})}export{E as C,z as D,u as a,g as b,j as c,h as d,b as e};
@@ -1 +0,0 @@
1
- import{r as d,f as e,Y as Q,a9 as z,aa as Te,ab as Ce}from"./vendor-C92xTG6Z.js";import{E as Se}from"./EChart-C_zeFtIj.js";import{S as ke,C as Ee,T as Ie}from"./Skeleton-D7zoK-3P.js";import{P as le,B as q}from"./PageHeader-BIhjesDo.js";import{P as he}from"./PageSection-CTHA3Yub.js";import{c as k,u as Re,a as Le,t as we,B as ce}from"./index-zyFaDjL5.js";import{u as R}from"./useApiQuery-HKJqYJso.js";import{C as Y,a as K}from"./card-DKAxXuqe.js";import{S as qe,a as Me,b as Ae,c as Be,d as F}from"./select-B9GMWo4R.js";import{u as V}from"./i18n-CZ1qKIdj.js";import{e as _e}from"./charts-core-BE9sa9zn.js";import"./charts-react-Dnkr-ZWt.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";import"./query-CDpWKdnY.js";import"./charts-engine-DAwKT7Yg.js";const J=d.forwardRef(({className:t,...a},s)=>e.jsx("div",{className:"relative w-full overflow-auto rounded-[1.25rem] border border-border/60 bg-background/45",children:e.jsx("table",{ref:s,className:k("w-full caption-bottom border-collapse text-sm",t),...a})}));J.displayName="Table";const W=d.forwardRef(({className:t,...a},s)=>e.jsx("thead",{ref:s,className:k("bg-muted/35 [&_tr]:border-b [&_tr]:border-border/60",t),...a}));W.displayName="TableHeader";const X=d.forwardRef(({className:t,...a},s)=>e.jsx("tbody",{ref:s,className:k("[&_tr:last-child]:border-0",t),...a}));X.displayName="TableBody";const Pe=d.forwardRef(({className:t,...a},s)=>e.jsx("tfoot",{ref:s,className:k("border-t bg-muted/45 font-medium [&>tr]:last:border-b-0",t),...a}));Pe.displayName="TableFooter";const D=d.forwardRef(({className:t,...a},s)=>e.jsx("tr",{ref:s,className:k("border-b border-border/50 transition-all duration-150","hover:bg-primary/5 data-[state=selected]:bg-primary/10","group",t),...a}));D.displayName="TableRow";const p=d.forwardRef(({className:t,...a},s)=>e.jsx("th",{ref:s,className:k("h-12 px-4 text-left align-middle text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground/80","[&:has([role=checkbox])]:pr-0",t),...a}));p.displayName="TableHead";const b=d.forwardRef(({className:t,...a},s)=>e.jsx("td",{ref:s,className:k("px-4 py-3.5 align-middle text-sm","[&:has([role=checkbox])]:pr-0","group-hover:text-foreground transition-colors",t),...a}));b.displayName="TableCell";const De=d.forwardRef(({className:t,...a},s)=>e.jsx("caption",{ref:s,className:k("mt-4 text-sm text-muted-foreground",t),...a}));De.displayName="TableCaption";const H=15e3,U=6e4;function P(t,a,s){return t==null?"-":`${t.toLocaleString(void 0,s)} ${a}`}function me(t){if(t==null)return"-";if(t<1024)return`${t} B`;const a=["KB","MB","GB","TB"];let s=t/1024,h=0;for(;s>=1024&&h<a.length-1;)s/=1024,h+=1;return`${s.toFixed(s>=100?0:s>=10?1:2)} ${a[h]}`}const S={requests:"#3b82f6",input:"#10b981",output:"#f59e0b",cacheRead:"#8b5cf6",cacheCreation:"#f43f5e"};function rt(){var se,ae,re,oe,ne,de;const{t}=V(),{pushToast:a}=Re(),[s,h]=d.useState("all"),[l,o]=d.useState(!1),u=s==="all"?void 0:s,M=R(["custom-endpoints"],{url:"/api/custom-endpoints",method:"GET"},{refetchInterval:U,refetchIntervalInBackground:!0}),y=R(["stats","overview",s],{url:"/api/stats/overview",method:"GET",params:u?{endpoint:u}:void 0},{refetchInterval:H,refetchIntervalInBackground:!0}),v=R(["stats","daily",14,s],{url:"/api/stats/daily",method:"GET",params:{days:14,...u?{endpoint:u}:{}}},{refetchInterval:U,refetchIntervalInBackground:!0}),x=R(["stats","model",7,6,s],{url:"/api/stats/model",method:"GET",params:{days:7,limit:6,...u?{endpoint:u}:{}}},{refetchInterval:U,refetchIntervalInBackground:!0}),N=R(["status",s],{url:"/api/status",method:"GET",params:u?{endpoint:u}:void 0},{refetchInterval:H,refetchIntervalInBackground:!0}),g=R(["db","info"],{url:"/api/db/info",method:"GET"},{refetchInterval:H,refetchIntervalInBackground:!0}),Z=g.refetch??(async()=>{}),T=R(["logs","recent",s],{url:"/api/logs",method:"GET",params:{limit:5,...u?{endpoint:u}:{}}},{refetchInterval:H,refetchIntervalInBackground:!0}),ue=d.useCallback(async()=>{await Promise.all([M.refetch(),y.refetch(),v.refetch(),x.refetch(),N.refetch(),g.refetch(),T.refetch()])},[M,v,g,T,x,y,N]),ee=M.isFetching||y.isFetching||v.isFetching||x.isFetching||N.isFetching||g.isFetching||T.isFetching;d.useEffect(()=>{y.isError&&y.error&&a({title:t("dashboard.toast.overviewError"),description:y.error.message,variant:"error"})},[y.isError,y.error,a,t]),d.useEffect(()=>{v.isError&&v.error&&a({title:t("dashboard.toast.dailyError"),description:v.error.message,variant:"error"})},[v.isError,v.error,a,t]),d.useEffect(()=>{x.isError&&x.error&&a({title:t("dashboard.toast.modelError"),description:x.error.message,variant:"error"})},[x.isError,x.error,a,t]),d.useEffect(()=>{N.isError&&N.error&&a({title:t("dashboard.toast.statusError"),description:N.error.message,variant:"error"})},[N.isError,N.error,a,t]),d.useEffect(()=>{g.isError&&g.error&&a({title:t("dashboard.toast.dbError"),description:g.error.message,variant:"error"})},[g.isError,g.error,a,t]);const xe=d.useCallback(async()=>{if(!l){o(!0);try{await Le.post("/api/db/compact"),await Z(),a({title:t("dashboard.toast.compactSuccess.title"),description:t("dashboard.toast.compactSuccess.desc"),variant:"success"})}catch(r){const n=we(r);a({title:t("dashboard.toast.compactError.title"),description:n.message,variant:"error"})}finally{o(!1)}}},[l,a,Z,t]);d.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=y.data,C=v.data??[],c=x.data??[],E=N.data,L=g.data,pe=((se=T.data)==null?void 0:se.items)??[],be=L?me(L.totalBytes??L.sizeBytes):"-",ge=me(L==null?void 0:L.memoryRssBytes),te=s==="all"?t("dashboard.filters.endpointAll"):s==="anthropic"?t("dashboard.filters.endpointAnthropic"):s==="openai"?t("dashboard.filters.endpointOpenAI"):((oe=(re=(ae=M.data)==null?void 0:ae.endpoints)==null?void 0:re.find(r=>r.id===s))==null?void 0:oe.label)||s,fe=C.reduce((r,n)=>r+n.requestCount,0),$=C.reduce((r,n)=>!r||n.requestCount>r.requestCount?n:r,null),A=c[0],B=c.filter(r=>r.avgTtftMs!=null&&r.avgTtftMs>0).sort((r,n)=>(r.avgTtftMs??Number.POSITIVE_INFINITY)-(n.avgTtftMs??Number.POSITIVE_INFINITY))[0],je=d.useMemo(()=>{const r=C.map(j=>j.date),n=t("dashboard.charts.barRequests"),m=t("dashboard.charts.lineInput"),_=t("dashboard.charts.lineOutput"),f=t("dashboard.charts.lineCacheRead"),ie=t("dashboard.charts.lineCacheCreation");return{tooltip:{trigger:"axis"},legend:{data:[n,m,_,f,ie]},grid:{left:60,right:40,top:60,bottom:60},xAxis:{type:"category",data:r},yAxis:{type:"value"},series:[{name:n,type:"bar",data:C.map(j=>j.requestCount),itemStyle:{color:S.requests,borderRadius:[4,4,0,0]}},{name:m,type:"line",data:C.map(j=>j.inputTokens),smooth:!0,itemStyle:{color:S.input},lineStyle:{width:2}},{name:_,type:"line",data:C.map(j=>j.outputTokens),smooth:!0,itemStyle:{color:S.output},lineStyle:{width:2}},{name:f,type:"line",data:C.map(j=>j.cacheReadTokens),smooth:!0,itemStyle:{color:S.cacheRead},lineStyle:{width:2}},{name:ie,type:"line",data:C.map(j=>j.cacheCreationTokens),smooth:!0,itemStyle:{color:S.cacheCreation},lineStyle:{width:2}}]}},[C,t]),ye=d.useMemo(()=>{const r=c.map(f=>`${f.provider}/${f.model}`),n=t("dashboard.charts.barRequests"),m=t("dashboard.charts.lineInput"),_=t("dashboard.charts.lineOutput");return{tooltip:{trigger:"axis"},legend:{data:[n,m,_]},grid:{left:80,right:60,top:60,bottom:100},xAxis:{type:"category",data:r,axisLabel:{rotate:30}},yAxis:[{type:"value",name:n},{type:"value",name:t("dashboard.charts.axisTokens"),position:"right"}],series:[{name:n,type:"bar",data:c.map(f=>f.requests),itemStyle:{color:S.requests,borderRadius:[4,4,0,0]}},{name:m,type:"line",yAxisIndex:1,smooth:!0,data:c.map(f=>f.inputTokens??0),itemStyle:{color:S.input}},{name:_,type:"line",yAxisIndex:1,smooth:!0,data:c.map(f=>f.outputTokens??0),itemStyle:{color:S.output}}]}},[c,t]),ve=d.useMemo(()=>{const r=c.map(m=>`${m.provider}/${m.model}`),n=t("dashboard.charts.ttftLabel");return{tooltip:{trigger:"axis"},grid:{left:80,right:50,top:60,bottom:100},xAxis:{type:"category",data:r,axisLabel:{rotate:30}},yAxis:{type:"value",name:t("dashboard.charts.ttftAxis")},series:[{name:n,type:"bar",data:c.map(m=>m.avgTtftMs??0),itemStyle:{color:S.requests,borderRadius:[4,4,0,0]}}]}},[c,t]),Ne=d.useMemo(()=>{const r=c.map(m=>`${m.provider}/${m.model}`),n=t("dashboard.charts.tpotLabel");return{tooltip:{trigger:"axis"},grid:{left:80,right:50,top:60,bottom:100},xAxis:{type:"category",data:r,axisLabel:{rotate:30}},yAxis:{type:"value",name:t("dashboard.charts.tpotAxis")},series:[{name:n,type:"bar",data:c.map(m=>m.avgTpotMs??0),itemStyle:{color:S.output,borderRadius:[4,4,0,0]}}]}},[c,t]);return y.isPending||N.isPending||g.isPending?e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(le,{icon:e.jsx(Q,{className:"h-5 w-5","aria-hidden":"true"}),title:t("nav.dashboard"),description:t("dashboard.description")}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:Array.from({length:6}).map((r,n)=>e.jsx(ke,{},n))}),e.jsx("div",{className:"grid gap-6 lg:grid-cols-2",children:Array.from({length:4}).map((r,n)=>e.jsx(Ee,{},n))}),e.jsx("div",{className:"rounded-[1.25rem] border border-border/70 bg-background/55",children:e.jsx("table",{className:"w-full",children:e.jsx("tbody",{children:Array.from({length:5}).map((r,n)=>e.jsx(Ie,{columns:6},n))})})})]}):e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(le,{icon:e.jsx(Q,{className:"h-5 w-5","aria-hidden":"true"}),title:t("nav.dashboard"),description:t("dashboard.description"),badge:te,actions:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:t("dashboard.filters.endpoint")}),e.jsxs(qe,{value:s,onValueChange:h,children:[e.jsx(Me,{className:"w-[140px]",children:e.jsx(Ae,{})}),e.jsxs(Be,{children:[e.jsx(F,{value:"all",children:t("dashboard.filters.endpointAll")}),e.jsx(F,{value:"anthropic",children:t("dashboard.filters.endpointAnthropic")}),e.jsx(F,{value:"openai",children:t("dashboard.filters.endpointOpenAI")}),(de=(ne=M.data)==null?void 0:ne.endpoints)==null?void 0:de.map(r=>e.jsx(F,{value:r.id,children:r.label||r.id},r.id))]})]}),e.jsx(ce,{variant:"outline",size:"sm",onClick:()=>void ue(),disabled:ee,children:t(ee?"common.actions.refreshing":"common.actions.refresh")})]})}),E&&e.jsx(Y,{className:"surface-1",children:e.jsxs(K,{className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-emerald-300/90 bg-emerald-50 px-3.5 py-2 text-sm shadow-[0_10px_24px_-20px_rgba(5,150,105,0.85)] dark:border-emerald-800 dark:bg-emerald-950/50",children:[e.jsx("span",{className:"font-semibold text-emerald-800 dark:text-emerald-200",children:t("dashboard.status.listeningLabel")}),e.jsxs("span",{className:"font-mono text-[13px] font-semibold tracking-normal text-emerald-950 dark:text-emerald-50",children:[E.host??"0.0.0.0",":",E.port]})]}),e.jsx(q,{variant:"outline",children:te})]}),e.jsx(ce,{variant:"outline",size:"sm",onClick:xe,disabled:l,children:t(l?"dashboard.actions.compacting":"dashboard.actions.compact")})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4 2xl:grid-cols-8",children:[e.jsx(I,{label:t("dashboard.labels.providers"),value:E.providers.toLocaleString()}),e.jsx(I,{label:t("dashboard.labels.activeRequests"),value:(E.activeRequests??0).toLocaleString()}),e.jsx(I,{label:t("dashboard.labels.activeClientAddresses"),value:(E.activeClientAddresses??0).toLocaleString()}),e.jsx(I,{label:t("dashboard.labels.activeClientSessions"),value:(E.activeClientSessions??0).toLocaleString()}),e.jsx(I,{label:t("dashboard.labels.uniqueClientAddressesLastHour"),value:(E.uniqueClientAddressesLastHour??0).toLocaleString()}),e.jsx(I,{label:t("dashboard.labels.uniqueClientSessionsLastHour"),value:(E.uniqueClientSessionsLastHour??0).toLocaleString()}),e.jsx(I,{label:t("dashboard.labels.todayRequests"),value:((i==null?void 0:i.today.requests)??0).toLocaleString()}),e.jsx(I,{label:t("dashboard.labels.database"),value:be}),e.jsx(I,{label:t("dashboard.labels.memory"),value:ge})]})]})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(w,{icon:e.jsx(z,{className:"h-5 w-5"}),title:t("dashboard.cards.todayRequests"),value:(i==null?void 0:i.today.requests)??0,suffix:t("common.units.request"),color:"blue"}),e.jsx(w,{icon:e.jsx(Te,{className:"h-5 w-5"}),title:t("dashboard.cards.todayInput"),value:(i==null?void 0:i.today.inputTokens)??0,suffix:t("common.units.token"),color:"emerald"}),e.jsx(w,{icon:e.jsx(z,{className:"h-5 w-5"}),title:t("dashboard.cards.todayCacheRead"),value:(i==null?void 0:i.today.cacheReadTokens)??0,suffix:t("common.units.token"),color:"violet"}),e.jsx(w,{icon:e.jsx(z,{className:"h-5 w-5"}),title:t("dashboard.cards.todayCacheCreation"),value:(i==null?void 0:i.today.cacheCreationTokens)??0,suffix:t("common.units.token"),color:"rose"}),e.jsx(w,{icon:e.jsx(Q,{className:"h-5 w-5"}),title:t("dashboard.cards.todayOutput"),value:(i==null?void 0:i.today.outputTokens)??0,suffix:t("common.units.token"),color:"amber"}),e.jsx(w,{icon:e.jsx(Ce,{className:"h-5 w-5"}),title:t("dashboard.cards.avgLatency"),value:(i==null?void 0:i.today.avgLatencyMs)??0,suffix:t("common.units.ms"),color:"cyan"})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsx(O,{label:t("dashboard.insights.totalRequests"),value:fe.toLocaleString(),hint:t("dashboard.insights.totalRequestsHint")}),e.jsx(O,{label:t("dashboard.insights.busiestDay"),value:$?`${$.date}`:"-",hint:$?t("dashboard.insights.busiestDayHint",{value:$.requestCount.toLocaleString()}):t("common.noData")}),e.jsx(O,{label:t("dashboard.insights.topModel"),value:A?`${A.provider}/${A.model}`:"-",hint:A?t("dashboard.insights.topModelHint",{value:A.requests.toLocaleString()}):t("common.noData")}),e.jsx(O,{label:t("dashboard.insights.fastestTtft"),value:B?`${B.provider}/${B.model}`:"-",hint:B?P(B.avgTtftMs,t("common.units.ms")):t("common.noData")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(G,{title:t("dashboard.charts.requestsTitle"),description:t("dashboard.charts.requestsDesc"),loading:v.isPending,option:je,empty:!C.length,emptyText:t("dashboard.charts.empty")}),e.jsx(G,{title:t("dashboard.charts.modelTitle"),description:t("dashboard.charts.modelDesc"),loading:x.isPending,option:ye,empty:!c.length,emptyText:t("dashboard.charts.empty")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(G,{title:t("dashboard.charts.ttftTitle"),description:t("dashboard.charts.ttftDesc"),loading:x.isPending,option:ve,empty:!c.some(r=>r.avgTtftMs!=null&&r.avgTtftMs>0),emptyText:t("dashboard.charts.ttftEmpty")}),e.jsx(G,{title:t("dashboard.charts.tpotTitle"),description:t("dashboard.charts.tpotDesc"),loading:x.isPending,option:Ne,empty:!c.some(r=>r.avgTpotMs!=null&&r.avgTpotMs>0),emptyText:t("dashboard.charts.tpotEmpty")})]}),e.jsx(Fe,{models:c,loading:x.isPending}),e.jsx(He,{loading:T.isPending,records:pe})]})}const $e={blue:{gradient:"bg-gradient-to-br from-blue-500/10 via-blue-500/5 to-transparent",iconBg:"bg-blue-500/15",iconColor:"text-blue-600 dark:text-blue-400"},emerald:{gradient:"bg-gradient-to-br from-emerald-500/10 via-emerald-500/5 to-transparent",iconBg:"bg-emerald-500/15",iconColor:"text-emerald-600 dark:text-emerald-400"},amber:{gradient:"bg-gradient-to-br from-amber-500/10 via-amber-500/5 to-transparent",iconBg:"bg-amber-500/15",iconColor:"text-amber-600 dark:text-amber-400"},violet:{gradient:"bg-gradient-to-br from-violet-500/10 via-violet-500/5 to-transparent",iconBg:"bg-violet-500/15",iconColor:"text-violet-600 dark:text-violet-400"},rose:{gradient:"bg-gradient-to-br from-rose-500/10 via-rose-500/5 to-transparent",iconBg:"bg-rose-500/15",iconColor:"text-rose-600 dark:text-rose-400"},cyan:{gradient:"bg-gradient-to-br from-cyan-500/10 via-cyan-500/5 to-transparent",iconBg:"bg-cyan-500/15",iconColor:"text-cyan-600 dark:text-cyan-400"}};function w({icon:t,title:a,value:s,suffix:h,color:l="blue"}){const o=$e[l];return e.jsx(Y,{variant:"interactive",className:k("overflow-hidden",o.gradient),children:e.jsxs(K,{className:"pt-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:a}),t&&e.jsx("div",{className:k("flex h-10 w-10 items-center justify-center rounded-xl",o.iconBg,o.iconColor),children:t})]}),e.jsxs("p",{className:"text-3xl font-bold tracking-tight",children:[s.toLocaleString(),h&&e.jsx("span",{className:"ml-1.5 text-sm font-medium text-muted-foreground",children:h})]})]})})}function I({label:t,value:a}){return e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/70 px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-lg font-semibold",children:a})]})}function O({label:t,value:a,hint:s}){return e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/90 px-4 py-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)] backdrop-blur",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 line-clamp-1 text-sm font-semibold",children:a}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function G({title:t,description:a,option:s,loading:h,empty:l,emptyText:o}){const{t:u}=V();return e.jsx(Y,{className:"surface-1",children:e.jsxs(K,{className:"space-y-4 pt-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-semibold",children:t}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a})]}),h?e.jsx("div",{className:"flex min-h-[280px] h-[40vh] max-h-[420px] items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:u("common.loadingShort")})}):l?e.jsxs("div",{className:"flex min-h-[280px] h-[40vh] max-h-[420px] flex-col items-center justify-center rounded-[1.25rem] border border-dashed border-border/70 bg-background/45",children:[e.jsx(Q,{className:"mb-2 h-10 w-10 text-muted-foreground/50"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:o??u("dashboard.charts.empty")})]}):e.jsx(Se,{echarts:_e,option:s,className:"min-h-[280px] h-[40vh] max-h-[420px]",notMerge:!0,lazyUpdate:!0})]})})}function Fe({models:t,loading:a}){const{t:s}=V(),h=t.length>0;return e.jsx(he,{title:s("dashboard.modelTable.title"),description:s("dashboard.modelTable.description"),children:a?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.loadingShort")})}):h?e.jsx("div",{className:"max-h-80 overflow-auto rounded-[1.2rem]",children:e.jsxs(J,{children:[e.jsx(W,{children:e.jsxs(D,{children:[e.jsx(p,{children:s("dashboard.modelTable.columns.model")}),e.jsx(p,{className:"text-right",children:s("dashboard.modelTable.columns.requests")}),e.jsx(p,{className:"text-right",children:s("dashboard.modelTable.columns.latency")}),e.jsx(p,{className:"text-right",children:s("dashboard.modelTable.columns.ttft")}),e.jsx(p,{className:"text-right",children:s("dashboard.modelTable.columns.tpot")})]})}),e.jsx(X,{children:t.map(l=>e.jsxs(D,{children:[e.jsx(b,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:l.provider}),e.jsx("span",{className:"text-xs text-muted-foreground",children:l.model})]})}),e.jsx(b,{className:"text-right font-medium",children:l.requests.toLocaleString()}),e.jsx(b,{className:"text-right",children:P(l.avgLatencyMs,s("common.units.ms"))}),e.jsx(b,{className:"text-right",children:P(l.avgTtftMs,s("common.units.ms"))}),e.jsx(b,{className:"text-right",children:P(l.avgTpotMs,s("common.units.msPerToken"),{maximumFractionDigits:2})})]},`${l.provider}/${l.model}`))})]})}):e.jsx("div",{className:"flex h-32 items-center justify-center rounded-[1.25rem] border border-dashed border-border/70 bg-background/45",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:s("dashboard.modelTable.empty")})})})}function He({records:t,loading:a}){const{t:s}=V(),h=t.filter(o=>!o.error&&(o.status_code??200)<400).length,l=t.filter(o=>o.error||(o.status_code??200)>=400).length;return e.jsx(he,{title:s("dashboard.recent.title"),description:s("dashboard.recent.subtitle",{count:5}),children:a?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:s("dashboard.recent.loading")})}):t.length===0?e.jsx("div",{className:"flex h-32 items-center justify-center rounded-[1.25rem] border border-dashed border-border/70 bg-background/45",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:s("dashboard.recent.empty")})}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(q,{variant:"secondary",children:t.length}),e.jsxs(q,{variant:"outline",className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300",children:[s("common.status.success"),": ",h]}),e.jsxs(q,{variant:"outline",className:"border-destructive/30 bg-destructive/10 text-destructive",children:[s("common.status.error"),": ",l]})]}),e.jsx("div",{className:"max-h-80 overflow-auto rounded-[1.2rem]",children:e.jsxs(J,{children:[e.jsx(W,{children:e.jsxs(D,{children:[e.jsx(p,{children:s("dashboard.recent.columns.time")}),e.jsx(p,{children:s("dashboard.recent.columns.endpoint")}),e.jsx(p,{children:s("dashboard.recent.columns.provider")}),e.jsx(p,{children:s("dashboard.recent.columns.route")}),e.jsx(p,{className:"text-right",children:s("dashboard.recent.columns.latency")}),e.jsx(p,{children:s("dashboard.recent.columns.status")})]})}),e.jsx(X,{children:t.map(o=>e.jsxs(D,{children:[e.jsx(b,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs font-medium",children:new Date(o.timestamp).toLocaleString()}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["#",o.id]})]})}),e.jsx(b,{children:e.jsx(q,{variant:"outline",className:"text-[11px]",children:o.endpoint==="anthropic"?s("logs.table.endpointAnthropic"):o.endpoint==="openai"?s("logs.table.endpointOpenAI"):o.endpoint})}),e.jsx(b,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:o.provider}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:o.stream?"stream":"sync"})]})}),e.jsx(b,{children:e.jsxs("div",{className:"flex flex-col gap-1 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx("span",{children:o.client_model??s("dashboard.recent.routePlaceholder")}),e.jsx("span",{children:"→"}),e.jsx("span",{className:"font-medium text-foreground",children:o.model})]}),o.error?e.jsx("span",{className:"truncate text-destructive",children:o.error}):null]})}),e.jsx(b,{className:"text-right font-medium",children:P(o.latency_ms,s("common.units.ms"))}),e.jsx(b,{children:e.jsx(q,{variant:o.error?"destructive":"default",className:"min-w-14 justify-center",children:(o.status_code??(o.error?500:200)).toString()})})]},o.id))})]})})]})})}export{rt as default};
@@ -1 +0,0 @@
1
- import{_ as a}from"./charts-react-Dnkr-ZWt.js";import{u as s,i as l,a as t,b as i,c as n,d as o,f as r,g as $}from"./charts-core-BE9sa9zn.js";s([l,t,i,n,o,r,$]);const e=a;export{e as E};
@@ -1 +0,0 @@
1
- import{r as i,f as e,ag as $,N as L,ad as R,ah as T,ai as I}from"./vendor-C92xTG6Z.js";import{u as z,B as x,c as w,L as P,e as F,t as B}from"./index-zyFaDjL5.js";import{P as V,B as u}from"./PageHeader-BIhjesDo.js";import{I as D}from"./input-CKjvZhjf.js";import{C,a as S,b as K}from"./card-DKAxXuqe.js";import{S as H,a as J,b as O,c as U,d as v}from"./select-B9GMWo4R.js";import{u as _}from"./i18n-CZ1qKIdj.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";import"./query-CDpWKdnY.js";function q(t){const l=Date.now()-t,n=Math.abs(l),m=60*1e3,d=60*m,o=24*d;if(n<m){const r=Math.max(Math.round(n/1e3),1);return l>=0?`${r}s ago`:`in ${r}s`}if(n<d){const r=Math.round(n/m);return l>=0?`${r}m ago`:`in ${r}m`}if(n<o){const r=Math.round(n/d);return l>=0?`${r}h ago`:`in ${r}h`}const h=Math.round(n/o);return l>=0?`${h}d ago`:`in ${h}d`}function G(t){return new Date(t).toLocaleString()}const Q={info:"secondary",warn:"outline",error:"destructive"};function ne(){const{t}=_(),{pushToast:g}=z(),[l,n]=i.useState([]),[m,d]=i.useState(!0),[o,h]=i.useState(null),[r,A]=i.useState(null),[a,j]=i.useState({level:"",type:""}),[N,y]=i.useState(!1),f=async s=>{d(!0);try{const c=await F.list({cursor:(s==null?void 0:s.cursor)??void 0,limit:50,level:a.level||void 0,type:a.type||void 0});n(c.events),A(c.nextCursor),h((s==null?void 0:s.cursor)??null)}catch(c){const M=B(c);g({title:t("events.toast.loadFailure",{message:M.message}),variant:"error"})}finally{d(!1),y(!1)}};i.useEffect(()=>{f({reset:!0})},[a.level,a.type]);const k=()=>{y(!0),f({cursor:o,reset:!1})},b=()=>{j({level:"",type:""})},E=i.useMemo(()=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(x,{variant:"outline",size:"sm",disabled:!o,onClick:()=>void f({cursor:void 0}),children:[e.jsx($,{className:"mr-1 h-4 w-4"})," ",t("events.actions.newest")]}),e.jsxs(x,{variant:"outline",size:"sm",disabled:!r,onClick:()=>void f({cursor:r??void 0}),children:[t("events.actions.older")," ",e.jsx(L,{className:"ml-1 h-4 w-4"})]})]}),[o,r,t]),p=i.useMemo(()=>{const s=[];return a.level&&s.push(t(`events.levels.${a.level}`)),a.type.trim()&&s.push(a.type.trim()),s},[a.level,a.type,t]);return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(V,{icon:e.jsx(T,{className:"h-5 w-5"}),title:t("events.title"),description:t("events.description"),actions:e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsxs(x,{variant:"outline",size:"sm",onClick:k,disabled:N,children:[e.jsx(R,{className:w("mr-2 h-4 w-4",N&&"animate-spin")}),t(N?"common.actions.refreshing":"common.actions.refresh")]})})}),e.jsx(C,{className:"sticky top-20 z-20 surface-1",children:e.jsx(S,{className:"pt-4",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-foreground",children:[e.jsx(I,{className:"h-4 w-4 text-primary"}),t("events.filters.title"),e.jsx(u,{variant:"outline",children:l.length})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("events.description")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[p.length>0&&e.jsx(x,{variant:"ghost",size:"sm",onClick:b,children:t("common.actions.reset")}),E]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(H,{value:a.level,onValueChange:s=>j(c=>({...c,level:s==="all"?"":s})),children:[e.jsx(J,{className:"w-[140px]",children:e.jsx(O,{placeholder:t("events.filters.allLevels")})}),e.jsxs(U,{children:[e.jsx(v,{value:"all",children:t("events.filters.allLevels")}),e.jsx(v,{value:"info",children:t("events.levels.info")}),e.jsx(v,{value:"warn",children:t("events.levels.warn")}),e.jsx(v,{value:"error",children:t("events.levels.error")})]})]}),e.jsx(D,{className:"w-[180px]",placeholder:t("events.filters.typePlaceholder"),value:a.type,onChange:s=>j(c=>({...c,type:s.target.value}))}),e.jsx(x,{variant:"ghost",size:"sm",onClick:b,disabled:p.length===0,children:t("common.actions.reset")})]}),p.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:p.map(s=>e.jsx(u,{variant:"secondary",children:s},s))})]})})}),m?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(P,{})}):l.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-10 text-center",children:[e.jsx("p",{className:"text-base font-medium",children:t("events.empty.title")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t("events.empty.subtitle")})]}):e.jsx("div",{className:"grid gap-4",children:l.map(s=>e.jsxs(C,{className:w("overflow-hidden border-l-4",s.level==="error"?"border-l-destructive":s.level==="warn"?"border-l-amber-500":"border-l-emerald-500"),children:[e.jsx(K,{className:"pb-3",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(u,{variant:Q[s.level]||"secondary",children:t(`events.levels.${s.level}`)}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[G(s.createdAt)," · ",q(s.createdAt)]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(u,{variant:"outline",children:["#",s.id]}),s.mode&&e.jsx(u,{variant:"secondary",children:s.mode})]})]})}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-base font-semibold",children:s.title||t("events.defaultTitle")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s.message||t("events.defaultMessage")})]}),e.jsxs("div",{className:"grid gap-3 text-sm sm:grid-cols-2 lg:grid-cols-3",children:[s.ipAddress&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"IP"}),e.jsx("p",{children:s.ipAddress})]}),s.apiKeyName&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"API Key"}),e.jsx("p",{children:s.apiKeyName})]}),s.userAgent&&e.jsxs("div",{className:"space-y-1 sm:col-span-2 lg:col-span-3",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"User Agent"}),e.jsx("p",{className:"truncate",children:s.userAgent})]})]}),s.details&&e.jsxs("details",{className:"rounded-[1rem] border border-border/70 bg-background/45 p-3 text-sm",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium text-primary",children:t("events.details")}),e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:JSON.stringify(s.details,null,2)})]})]})]},s.id))})]})}export{ne as default};
@@ -1,8 +0,0 @@
1
- import{r as h,f as e,au as b,as as N,av as v,aw as w}from"./vendor-C92xTG6Z.js";import{P as y}from"./PageHeader-BIhjesDo.js";import{P as d}from"./PageSection-CTHA3Yub.js";import{c as u}from"./clipboard-CALi6bTW.js";import{C as p,a as j}from"./card-DKAxXuqe.js";import{B as f}from"./index-zyFaDjL5.js";import{u as x}from"./i18n-CZ1qKIdj.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";import"./query-CDpWKdnY.js";function $(){const{t:s}=x(),t=h.useMemo(()=>{const i=s("help.sections.configuration.items",{returnObjects:!0}),a=s("help.sections.claudeCodeConfig.items",{returnObjects:!0}),n=s("help.sections.codexConfig.items",{returnObjects:!0}),c=s("help.sections.usage.items",{returnObjects:!0}),g=s("help.sections.tips.items",{returnObjects:!0});return[{title:s("help.sections.configuration.title"),items:i},{title:s("help.sections.claudeCodeConfig.title"),items:a},{title:s("help.sections.codexConfig.title"),items:n},{title:s("help.sections.usage.title"),items:c},{title:s("help.sections.tips.title"),items:g}]},[s]),r=s("help.faq.items",{returnObjects:!0}),l=h.useMemo(()=>[{id:"configuration",title:t[0].title,subtitle:t[0].items[0]??""},{id:"claude",title:t[1].title,subtitle:t[1].items[0]??""},{id:"codex",title:t[2].title,subtitle:t[2].items[0]??""},{id:"faq",title:s("help.faq.title"),subtitle:`${r.length} FAQ`}],[r.length,t,s]);return e.jsxs("div",{className:"space-y-6",children:[e.jsx(y,{icon:e.jsx(b,{className:"h-5 w-5","aria-hidden":"true"}),title:s("help.title"),description:s("help.intro"),eyebrow:"Guided Setup",breadcrumb:"Gateway / Help",helper:s("help.helper")}),e.jsx(p,{className:"surface-1",children:e.jsxs(j,{className:"flex items-start gap-4 pt-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-2xl bg-primary/10 text-primary shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]",children:e.jsx(N,{className:"h-5 w-5","aria-hidden":"true"})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("help.note")})]})}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:l.map(i=>e.jsxs("a",{href:`#help-${i.id}`,className:"rounded-[1.35rem] border border-white/50 bg-card/88 px-4 py-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition hover:-translate-y-0.5 hover:shadow-[0_12px_36px_-24px_rgba(15,23,42,0.3)]",children:[e.jsx("p",{className:"text-sm font-semibold",children:i.title}),e.jsx("p",{className:"mt-2 line-clamp-2 text-xs text-muted-foreground",children:i.subtitle})]},i.id))}),e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{id:"help-configuration",children:e.jsx(d,{eyebrow:"01",title:t[0].title,children:e.jsx(o,{items:t[0].items})})}),e.jsxs("div",{className:"space-y-1 text-center",children:[e.jsx("h2",{className:"text-xl font-semibold",children:s("help.clientConfig.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("help.clientConfig.subtitle")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx("div",{id:"help-claude",children:e.jsxs(d,{eyebrow:"02",title:t[1].title,children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3 rounded-xl bg-primary/5 p-4",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-primary-foreground",children:e.jsx(v,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Claude Code"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"IDE / Desktop workflow"})]})]}),e.jsx(o,{items:t[1].items})]})}),e.jsx("div",{id:"help-codex",children:e.jsxs(d,{eyebrow:"03",title:t[2].title,children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3 rounded-xl bg-emerald-500/5 p-4 dark:bg-emerald-500/10",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-emerald-500 text-white",children:e.jsx(w,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Codex CLI"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Terminal workflow"})]})]}),e.jsx(o,{items:t[2].items})]})})]}),e.jsxs("div",{className:"mt-8",children:[e.jsxs("div",{className:"mb-6 space-y-1 text-center",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s("help.advancedGuide.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("help.advancedGuide.subtitle")})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(d,{eyebrow:"04",title:t[3].title,children:e.jsx(o,{items:t[3].items})}),e.jsx(d,{eyebrow:"05",title:t[4].title,children:e.jsx(o,{items:t[4].items})})]})]})]}),e.jsx("div",{id:"help-faq",children:e.jsx(d,{eyebrow:"FAQ",title:s("help.faq.title"),children:e.jsx(_,{items:r})})})]})}function o({items:s}){return e.jsx("ol",{className:"flex flex-col gap-3",children:s.map((t,r)=>e.jsxs("li",{className:"flex gap-3 rounded-[1.2rem] border border-white/50 bg-card/82 p-3 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-xl bg-primary text-xs font-medium text-primary-foreground",children:r+1}),e.jsx("div",{className:"flex-1 text-sm text-muted-foreground",children:e.jsx(C,{content:t})})]},`${r}-${t}`))})}function C({content:s}){const{t}=x();if(s.includes("```")){const r=s.split("```");return e.jsx("div",{className:"space-y-2",children:r.map((l,i)=>{if(i%2===0)return l?e.jsx("div",{className:"whitespace-pre-line",children:m(l)},i):null;{const[a,...n]=l.split(`
2
- `),c=n.join(`
3
- `);return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a||"bash"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>u(c),children:t("common.actions.copy")})]}),e.jsx("pre",{className:"overflow-x-auto rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:e.jsx("code",{children:c})})]},i)}})})}return s.includes(`
4
- `)?e.jsx("div",{className:"whitespace-pre-line",children:m(s)}):e.jsx("div",{children:m(s)})}function m(s){return s.split(/(\*\*[^*]+\*\*)/g).map((r,l)=>r.startsWith("**")&&r.endsWith("**")?e.jsx("strong",{className:"font-medium text-foreground",children:r.slice(2,-2)},l):e.jsx("span",{children:r},l))}function _({items:s}){return s.length===0?null:e.jsx("dl",{className:"flex flex-col gap-3",children:s.map(t=>e.jsx(p,{className:"surface-1",children:e.jsxs(j,{className:"pt-4",children:[e.jsx("dt",{className:"text-sm font-medium",children:t.q}),e.jsx("dd",{className:"mt-2 text-sm text-muted-foreground",children:e.jsx(k,{content:t.a})})]})},t.q))})}function k({content:s}){const{t}=x();if(s.includes("1)")||s.includes("2)")){const r=s.split(`
5
- `).filter(i=>i.trim());if(r.some(i=>/^\d+\)/.test(i.trim())))return e.jsx("div",{className:"space-y-1",children:r.map((i,a)=>{const n=i.match(/^\d+\)\s*(.*)/);return n?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"•"}),e.jsx("span",{children:n[1]})]},a):e.jsx("div",{children:i},a)})})}if(s.includes("```")){const r=s.split("```");return e.jsx("div",{className:"space-y-2",children:r.map((l,i)=>{if(i%2===0)return l?e.jsx("div",{className:"whitespace-pre-line",children:l},i):null;{const[a,...n]=l.split(`
6
- `),c=n.join(`
7
- `);return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:a||"bash"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>u(c),children:t("common.actions.copy")})]}),e.jsx("pre",{className:"overflow-x-auto rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:e.jsx("code",{children:c})})]},i)}})})}return s.includes(`
8
- `)?e.jsx("div",{className:"whitespace-pre-line",children:s}):e.jsx("div",{children:s})}export{$ as default};
@@ -1 +0,0 @@
1
- import{r as n,f as e}from"./vendor-C92xTG6Z.js";import{i as C,h as E,B as F}from"./index-zyFaDjL5.js";import{I as j}from"./input-CKjvZhjf.js";import{L as b}from"./label-V0fmEe3U.js";import{C as v,a as w,b as S,c as L,d as k,e as _}from"./card-DKAxXuqe.js";import{u as P}from"./i18n-CZ1qKIdj.js";import{c as T,u as A}from"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";import"./query-CDpWKdnY.js";function z(){const{t:s}=P(),i=T(),m=A(),{authEnabled:o,isAuthenticated:u,loading:l,login:y,error:p}=C(),[a,x]=n.useState({username:"",password:""}),[f,d]=n.useState(null),[h,g]=n.useState(!1),c=n.useMemo(()=>{var t;const r=m.state;return((t=r==null?void 0:r.from)==null?void 0:t.pathname)??"/"},[m.state]);n.useEffect(()=>{if(!o&&!l){i(c,{replace:!0});return}o&&u&&!l&&i(c,{replace:!0})},[o,u,l,i,c]);const N=async r=>{if(r.preventDefault(),d(null),!a.username.trim()||!a.password){d(s("login.validation.required"));return}g(!0);try{await y(a.username.trim(),a.password),i(c,{replace:!0})}catch(t){d(t instanceof Error?t.message:s("login.validation.failed"))}finally{g(!1)}};return l?e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-4",children:e.jsx(v,{className:"surface-2 w-full max-w-md",children:e.jsx(w,{className:"flex min-h-[320px] items-center justify-center",children:e.jsx(E,{})})})}):o?e.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-4",children:e.jsxs(v,{className:"surface-2 w-full max-w-md overflow-hidden",children:[e.jsxs(S,{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-[1.15rem] bg-gradient-to-br from-primary via-primary to-sky-400 text-lg font-bold text-primary-foreground shadow-[0_14px_30px_-18px_rgba(59,130,246,0.75)]",children:"GW"}),e.jsx(L,{className:"text-2xl",children:s("login.title")}),e.jsx(k,{className:"text-sm",children:s("login.description")})]}),e.jsx(w,{children:e.jsxs("form",{className:"space-y-4",onSubmit:N,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"username",children:s("login.fields.username")}),e.jsx(j,{id:"username",value:a.username,autoComplete:"username",autoFocus:!0,onChange:r=>x(t=>({...t,username:r.target.value})),placeholder:s("login.fields.usernamePlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"password",children:s("login.fields.password")}),e.jsx(j,{id:"password",type:"password",value:a.password,autoComplete:"current-password",onChange:r=>x(t=>({...t,password:r.target.value})),placeholder:s("login.fields.passwordPlaceholder")})]}),(f||p)&&e.jsx("div",{className:"rounded-[1rem] border border-destructive/50 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:f||p}),e.jsx(F,{type:"submit",className:"w-full",disabled:h,children:s(h?"common.actions.loading":"login.actions.submit")})]})}),e.jsx(_,{className:"justify-center",children:e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:s("login.hint")})})]})}):null}export{z as default};
@@ -1 +0,0 @@
1
- import{r as o,f as e,ac as Ze,ad as Xe,Z as es,ae as ss,af as ts,a5 as Fe,h as as}from"./vendor-C92xTG6Z.js";import{u as Ke,a as ls,t as rs,c as h,B as y}from"./index-zyFaDjL5.js";import{u as A}from"./useApiQuery-HKJqYJso.js";import{T as os,a as Q}from"./Skeleton-D7zoK-3P.js";import{P as ns,B as P}from"./PageHeader-BIhjesDo.js";import{c as is}from"./clipboard-CALi6bTW.js";import{I as me}from"./input-CKjvZhjf.js";import{L as O}from"./label-V0fmEe3U.js";import{C as Re,a as De}from"./card-DKAxXuqe.js";import{S as Z,a as X,b as ee,c as se,d as T}from"./select-B9GMWo4R.js";import{P as ds,a as cs,b as ms}from"./popover-CSAdpdw2.js";import{u as ae}from"./i18n-CZ1qKIdj.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";import"./query-CDpWKdnY.js";const Me=[20,50,100],ze="cc-gw.logs.visible-columns",Ae="cc-gw.logs.density",$=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","outputTokens","latency","status","error"],te=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function xs(){if(typeof window>"u")return $;try{const s=window.localStorage.getItem(ze);if(!s)return $;const i=JSON.parse(s);if(!Array.isArray(i))return $;const c=i.filter(v=>te.includes(v));return c.length>0?c:$}catch{return $}}function us(){return typeof window>"u"?"comfortable":window.localStorage.getItem(Ae)==="compact"?"compact":"comfortable"}function Oe(s,i=!1){if(!s)return;const c=i?`${s}T23:59:59.999`:`${s}T00:00:00.000`,v=Date.parse(c);return Number.isFinite(v)?v:void 0}function Pe(s){const i=new Date(s);return`${i.getFullYear()}-${`${i.getMonth()+1}`.padStart(2,"0")}-${`${i.getDate()}`.padStart(2,"0")} ${`${i.getHours()}`.padStart(2,"0")}:${`${i.getMinutes()}`.padStart(2,"0")}:${`${i.getSeconds()}`.padStart(2,"0")}`}function L(s){return s==null?"-":s.toLocaleString()}function C(s,i){const c=L(s);return c==="-"?"-":`${c} ${i}`}function ps(s){return s?"true":"false"}function $e(s,i){if(!s||s.trim().length===0)return i;try{const c=JSON.parse(s);return JSON.stringify(c,null,2)}catch{return s}}function hs(s,i,c){return s===c&&i===c}function Os(){var ke,_e,Se,Ee,Te,Ce;const{t:s}=ae(),{pushToast:i}=Ke(),[c,v]=o.useState("all"),[g,a]=o.useState("all"),[d,j]=o.useState(""),[x,N]=o.useState("all"),[l,S]=o.useState(""),[r,m]=o.useState(""),[f,p]=o.useState(1),[u,F]=o.useState(Me[0]),[le,I]=o.useState(null),[Ie,xe]=o.useState(!1),[w,re]=o.useState([]),[H,ue]=o.useState(!1),[pe,qe]=o.useState(!1),[q,he]=o.useState(us),[R,fe]=o.useState(xs),[Ue,Ge]=o.useState(!1),oe=o.useRef(null);o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(Ae,q)},[q]),o.useEffect(()=>{typeof window>"u"||window.localStorage.setItem(ze,JSON.stringify(R))},[R]),o.useEffect(()=>{p(1)},[c,g,d,x,l,r,u,w]);const W=o.useMemo(()=>{const t={limit:u,offset:(f-1)*u};c!=="all"&&(t.provider=c),g!=="all"&&(t.endpoint=g),d.trim().length>0&&(t.model=d.trim()),x!=="all"&&(t.status=x);const n=Oe(l),_=Oe(r,!0);return n!==void 0&&(t.from=n),_!==void 0&&(t.to=_),w.length>0&&(t.apiKeys=w.join(",")),t},[c,g,d,x,l,r,f,u,w]),k=A(["logs",W],{url:"/api/logs",method:"GET",params:W}),K=A(["providers","all"],{url:"/api/providers",method:"GET"}),ge=A(["api-keys"],{url:"/api/keys",method:"GET"}),ne=A(["custom-endpoints"],{url:"/api/custom-endpoints",method:"GET"}),je=A(["config","export-timeout"],{url:"/api/config",method:"GET"});o.useEffect(()=>{k.isError&&k.error&&i({title:s("logs.toast.listError.title"),description:s("logs.toast.listError.desc",{message:k.error.message}),variant:"error"})},[k.isError,k.error,i,s]),o.useEffect(()=>{K.isError&&K.error&&i({title:s("logs.toast.providerError.title"),description:s("logs.toast.providerError.desc",{message:K.error.message}),variant:"error"})},[K.isError,K.error,i,s]);const D=((ke=k.data)==null?void 0:ke.total)??0,E=D>0?Math.ceil(D/u):0,be=((_e=k.data)==null?void 0:_e.items)??[],ye=o.useMemo(()=>{var n;const t=(n=je.data)==null?void 0:n.logExportTimeoutSeconds;return typeof t=="number"&&Number.isFinite(t)?Math.min(Math.max(Math.round(t),5),600)*1e3:6e4},[(Se=je.data)==null?void 0:Se.logExportTimeoutSeconds]);o.useEffect(()=>{E>0&&f>E&&p(E)},[E,f]);const ie=K.data??[],J=o.useMemo(()=>{const t=new Map;for(const n of ie)n.id&&t.set(n.id,n.label??n.id);return t},[ie]),ve=o.useMemo(()=>{var n;const t=new Map;t.set("anthropic",s("logs.filters.endpointAnthropic")),t.set("openai",s("logs.filters.endpointOpenAI"));for(const _ of((n=ne.data)==null?void 0:n.endpoints)??[])t.set(_.id,_.label||_.id);return t},[(Ee=ne.data)==null?void 0:Ee.endpoints,s]),z=o.useMemo(()=>{const t=[];if(c!=="all"){const n=J.get(c)??c;t.push({key:"provider",label:`${s("logs.filters.provider")}: ${n}`,onRemove:()=>v("all")})}if(g!=="all"){const n=ve.get(g)??g;t.push({key:"endpoint",label:`${s("logs.filters.endpoint")}: ${n}`,onRemove:()=>a("all")})}if(d.trim()&&t.push({key:"model",label:`${s("logs.filters.modelId")}: ${d.trim()}`,onRemove:()=>j("")}),x!=="all"){const n=s(x==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");t.push({key:"status",label:`${s("logs.filters.status")}: ${n}`,onRemove:()=>N("all")})}return l&&t.push({key:"from",label:`${s("logs.filters.startDate")}: ${l}`,onRemove:()=>S("")}),r&&t.push({key:"to",label:`${s("logs.filters.endDate")}: ${r}`,onRemove:()=>m("")}),w.length>0&&t.push({key:"apiKeys",label:s("logs.filters.apiKeySelected",{count:w.length}),onRemove:()=>re([])}),t},[c,J,g,ve,d,x,l,r,w,s]),de=ge.data??[],Ne=o.useMemo(()=>{const t=new Map;for(const n of de)t.set(n.id,n);return t},[de]),b=o.useMemo(()=>new Set(R),[R]),Be=o.useMemo(()=>te.map(t=>({id:t,label:s(`logs.table.columns.${t}`)})),[s]),we=R.length+2,U=o.useMemo(()=>new Date().toISOString().slice(0,10),[]),Ve=o.useMemo(()=>c==="all"&&g==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"all":x==="error"&&g==="all"&&c==="all"&&d.trim()===""&&l===""&&r===""&&w.length===0?"errors":hs(l,r,U)&&g==="all"&&c==="all"&&d.trim()===""&&x==="all"&&w.length===0?"today":g==="anthropic"&&c==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"anthropic":g==="openai"&&c==="all"&&d.trim()===""&&x==="all"&&l===""&&r===""&&w.length===0?"openai":null,[g,l,d,c,w.length,x,r,U]),Qe=o.useCallback(t=>{fe(n=>{if(n.includes(t))return n.length===1?n:n.filter(B=>B!==t);const _=[...n,t];return _.sort((B,ce)=>te.indexOf(B)-te.indexOf(ce)),_})},[]),Y=o.useCallback(()=>{v("all"),j(""),a("all"),N("all"),S(""),m(""),re([])},[]),He=o.useCallback(t=>{if(p(1),Y(),t!=="all"){if(t==="errors"){N("error");return}if(t==="today"){S(U),m(U);return}if(t==="anthropic"){a("anthropic");return}t==="openai"&&a("openai")}},[Y,U]),We=o.useCallback(async()=>{if(!H){ue(!0);try{const t=D>0?Math.min(D,5e3):1e3,n={...W,limit:t,offset:0},_=await ls.post("/api/logs/export",n,{responseType:"blob",timeout:ye}),B=new Blob([_.data],{type:"application/zip"}),ce=new Date().toISOString().replace(/[:.]/g,"-"),Le=URL.createObjectURL(B),V=document.createElement("a");V.href=Le,V.download=`cc-gw-logs-${ce}.zip`,document.body.appendChild(V),V.click(),V.remove(),URL.revokeObjectURL(Le),i({title:s("logs.toast.exportSuccess.title"),description:s("logs.toast.exportSuccess.desc"),variant:"success"})}catch(t){const n=rs(t);i({title:s("logs.toast.exportError.title"),description:s("logs.toast.exportError.desc",{message:n.message}),variant:"error"})}finally{ue(!1)}}},[ye,H,i,W,s,D]),Je=o.useCallback(t=>{I(t),xe(!0)},[]),Ye=o.useCallback(()=>{xe(!1),I(null)},[]),G=o.useCallback(()=>{const t=oe.current;if(!t)return;const n=t.scrollWidth-t.scrollLeft-t.clientWidth>1;Ge(n)},[]);return o.useEffect(()=>{const t=oe.current;if(!t)return;G(),t.addEventListener("scroll",G,{passive:!0});const n=new ResizeObserver(G);return n.observe(t),()=>{t.removeEventListener("scroll",G),n.disconnect()}},[G]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ns,{icon:e.jsx(es,{className:"h-5 w-5","aria-hidden":"true"}),title:s("logs.title"),description:s("logs.description"),eyebrow:"Traffic Explorer",breadcrumb:"Gateway / Logs",helper:s("logs.filtersDescription"),actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-full border border-border/70 bg-background/80 p-1 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("button",{type:"button",onClick:()=>he("comfortable"),className:h("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",q==="comfortable"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:s("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>he("compact"),className:h("inline-flex h-8 items-center rounded-full px-3.5 text-xs font-medium transition-all",q==="compact"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:s("logs.table.density.compact")})]}),e.jsxs(ds,{children:[e.jsx(cs,{asChild:!0,children:e.jsx(y,{variant:"outline",size:"sm",children:s("logs.actions.columns")})}),e.jsxs(ms,{align:"end",className:"w-64 rounded-[1.2rem] border-white/60 p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:s("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.actions.visibleCount",{count:R.length})})]}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>fe($),disabled:JSON.stringify(R)===JSON.stringify($),children:s("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:Be.map(t=>{const n=b.has(t.id);return e.jsxs("label",{className:h("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",n&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:n,onChange:()=>Qe(t.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:t.label})]},t.id)})})]})]}),e.jsxs(y,{onClick:We,disabled:H,children:[e.jsx(Ze,{className:"mr-2 h-4 w-4"}),s(H?"common.actions.loading":"logs.actions.export")]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.summary.total",{value:D.toLocaleString()})}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>k.refetch(),disabled:k.isFetching,children:[e.jsx(Xe,{className:h("mr-2 h-4 w-4",k.isFetching&&"animate-spin")}),k.isFetching?s("common.actions.refreshing"):s("logs.actions.manualRefresh")]})]})}),e.jsx(Re,{className:"sticky top-20 z-20 border-white/40 bg-card/90 backdrop-blur",children:e.jsxs(De,{className:"pt-4",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:s("logs.filtersTitle")}),e.jsx(P,{variant:"outline",children:s("logs.summary.total",{value:D.toLocaleString()})}),z.length>0&&e.jsx(P,{variant:"secondary",children:s("common.filters.activeCount",{count:z.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[z.length>0&&e.jsx(y,{variant:"ghost",size:"sm",onClick:Y,children:s("common.actions.reset")}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>qe(t=>!t),children:pe?e.jsxs(e.Fragment,{children:[s("common.filters.collapse"),e.jsx(ss,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[s("common.filters.expand"),e.jsx(ts,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsx("div",{className:"flex flex-1 items-center gap-3 overflow-hidden",children:z.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:z.map(t=>e.jsxs(P,{variant:"secondary",role:"button",tabIndex:0,className:"cursor-pointer gap-1 hover:bg-destructive/10 hover:text-destructive",onClick:t.onRemove,onKeyDown:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),t.onRemove())},children:[t.label,e.jsx(Fe,{className:"h-3 w-3","aria-hidden":"true"})]},t.key))}):e.jsx("span",{className:"text-sm text-muted-foreground",children:s("common.filters.allRequests")})})}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:["all","errors","today","anthropic","openai"].map(t=>e.jsx(y,{variant:Ve===t?"default":"outline",size:"sm",className:"rounded-full",onClick:()=>He(t),children:s(`logs.quickViews.${t}`)},t))})]}),pe&&e.jsxs("div",{className:"mt-4 grid gap-4 md:grid-cols-2 xl:grid-cols-4 animate-in fade-in slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.provider")}),e.jsxs(Z,{value:c,onValueChange:v,children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.providerAll")}),ie.map(t=>e.jsx(T,{value:t.id,children:t.label??t.id},t.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.endpoint")}),e.jsxs(Z,{value:g,onValueChange:a,children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.endpointAll")}),e.jsx(T,{value:"anthropic",children:s("logs.filters.endpointAnthropic")}),e.jsx(T,{value:"openai",children:s("logs.filters.endpointOpenAI")}),(Ce=(Te=ne.data)==null?void 0:Te.endpoints)==null?void 0:Ce.map(t=>e.jsx(T,{value:t.id,children:t.label||t.id},t.id))]})]})]}),e.jsx(js,{className:"md:col-span-2",apiKeys:de,selected:w,disabled:ge.isLoading,onChange:re}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.modelId")}),e.jsx(me,{value:d,onChange:t=>j(t.target.value),placeholder:s("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.status")}),e.jsxs(Z,{value:x,onValueChange:t=>N(t),children:[e.jsx(X,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(T,{value:"all",children:s("logs.filters.statusAll")}),e.jsx(T,{value:"success",children:s("logs.filters.statusSuccess")}),e.jsx(T,{value:"error",children:s("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.startDate")}),e.jsx(me,{type:"date",value:l,onChange:t=>S(t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:s("logs.filters.endDate")}),e.jsx(me,{type:"date",value:r,onChange:t=>m(t.target.value)})]})]})]})}),e.jsx(Re,{children:e.jsxs(De,{className:"p-0",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:oe,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1200px] text-sm",children:[e.jsx("thead",{className:"border-b bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-muted/95 px-3 py-2 text-left text-xs font-medium backdrop-blur",children:s("logs.table.columns.time")}),b.has("endpoint")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.endpoint")}),b.has("provider")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.provider")}),b.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.requestedModel")}),b.has("routedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.routedModel")}),b.has("apiKey")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.apiKey")}),b.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.inputTokens")}),b.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheReadTokens")}),b.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.cacheCreationTokens")}),b.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.outputTokens")}),b.has("latency")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.latency")}),b.has("ttft")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.ttft")}),b.has("tpot")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:s("logs.table.columns.tpot")}),b.has("status")&&e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:s("logs.table.columns.status")}),b.has("error")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:s("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-muted/95 px-3 py-2 text-center text-xs font-medium backdrop-blur",children:s("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:k.isPending?Array.from({length:8}).map((t,n)=>e.jsx(os,{columns:we},n)):be.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:we,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[e.jsx("span",{children:s("logs.table.empty")}),z.length>0&&e.jsx(y,{variant:"outline",size:"sm",onClick:Y,children:s("common.actions.reset")})]})})}):be.map((t,n)=>e.jsx(fs,{record:t,providerLabelMap:J,apiKeyMap:Ne,onSelect:Je,isEven:n%2===0,density:q,visibleColumnSet:b},t.id))})]})}),Ue&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 border-t p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.perPage")}),e.jsxs(Z,{value:u.toString(),onValueChange:t=>F(Number(t)),children:[e.jsx(X,{className:"w-[80px]",children:e.jsx(ee,{})}),e.jsx(se,{children:Me.map(t=>e.jsx(T,{value:t.toString(),children:t},t))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>p(t=>Math.max(t-1,1)),disabled:f<=1,children:s("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("logs.table.pagination.pageLabel",{page:E===0?0:f,total:E})}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>p(t=>E===0?t:Math.min(t+1,E)),disabled:E===0||f>=E,children:s("logs.table.pagination.next")})]})]})]})}),e.jsx(gs,{open:Ie,logId:le,onClose:Ye,providerLabelMap:J,apiKeyMap:Ne})]})}function fs({record:s,providerLabelMap:i,apiKeyMap:c,onSelect:v,isEven:g,density:a,visibleColumnSet:d}){const{t:j}=ae(),x=i.get(s.provider)??s.provider,N=s.endpoint||"-",l=!!s.error,S=s.status_code,r=s.client_model??j("logs.table.requestedModelFallback"),m=s.api_key_id!=null?c.get(s.api_key_id):void 0,f=s.api_key_id==null?j("logs.table.apiKeyUnknown"):m!=null&&m.isWildcard?j("apiKeys.wildcard"):m!=null&&m.name?m.name:s.api_key_name?s.api_key_name:j("logs.table.apiKeyUnknown"),p=a==="compact"?"px-3 py-1.5":"px-3 py-2",u=g?"bg-muted/30":"bg-background";return e.jsxs("tr",{className:h("transition-colors",g?"bg-muted/30":"","hover:bg-muted/50"),children:[e.jsx("td",{className:h("sticky left-0 z-10 text-xs",p,u),children:Pe(s.timestamp)}),d.has("endpoint")&&e.jsx("td",{className:h(p,"text-xs"),children:N}),d.has("provider")&&e.jsx("td",{className:h(p,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:x,children:x})}),d.has("requestedModel")&&e.jsx("td",{className:h(p,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:r,children:r})}),d.has("routedModel")&&e.jsx("td",{className:h(p,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:s.model,children:s.model})}),d.has("apiKey")&&e.jsx("td",{className:h(p,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:f,children:f})}),d.has("inputTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.input_tokens)}),d.has("cacheReadTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.cache_read_tokens)}),d.has("cacheCreationTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.cache_creation_tokens)}),d.has("outputTokens")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:L(s.output_tokens)}),d.has("latency")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.latency_ms,"ms")}),d.has("ttft")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.ttft_ms,"ms")}),d.has("tpot")&&e.jsx("td",{className:h(p,"text-right text-xs tabular-nums"),children:C(s.tpot_ms,"ms/tk")}),d.has("status")&&e.jsx("td",{className:h(p,"text-center"),children:e.jsx(P,{variant:l?"destructive":"default",className:"text-xs",children:S??(l?500:200)})}),d.has("error")&&e.jsx("td",{className:h(p,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:s.error??"",children:s.error?s.error:"-"})}),e.jsx("td",{className:h("sticky right-0 z-10 text-center",p,u),children:e.jsx(y,{variant:"outline",size:"sm",onClick:()=>v(s.id),children:j("logs.actions.detail")})})]})}function gs({open:s,logId:i,onClose:c,providerLabelMap:v,apiKeyMap:g}){var f,p;const{t:a}=ae(),{pushToast:d}=Ke(),j=o.useRef(null),x=A(["log-detail",i],{url:`/api/logs/${i}`,method:"GET"},{enabled:s&&i!==null,staleTime:3e4});o.useEffect(()=>{x.isError&&x.error&&d({title:a("logs.detail.loadError"),description:x.error.message,variant:"error"})},[x.isError,x.error,d,a]),o.useEffect(()=>{if(!s)return;const u=F=>{F.key==="Escape"&&c()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[s,c]),o.useEffect(()=>{s&&j.current&&j.current.focus()},[s,i]);const N=o.useCallback(async(u,F,le)=>{if(!F){d({title:a("logs.detail.copy.empty",{label:u}),variant:"info"});return}try{await is(F),d({title:a(le),variant:"success"})}catch(I){d({title:a("logs.detail.copy.failure"),description:I instanceof Error?I.message:a("logs.detail.copy.failureFallback"),variant:"error"})}},[d,a]);if(!s)return null;const l=x.data,S=l?v.get(l.provider)??l.provider:"",r=l&&l.api_key_id!=null?g.get(l.api_key_id):void 0,m=l?l.status_code??(l.error?500:200):null;return typeof document>"u"?null:as.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm animate-in fade-in duration-200",onClick:c}),e.jsxs("aside",{role:"dialog","aria-modal":"true",className:"flex h-full w-full max-w-xl flex-col border-l bg-card shadow-xl animate-in slide-in-from-right duration-300",children:[e.jsxs("header",{className:"flex items-center justify-between border-b px-6 py-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:a("logs.detail.title")}),l&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a("logs.detail.id",{id:l.id})})]}),e.jsxs(y,{ref:j,variant:"outline",size:"sm",onClick:c,children:[e.jsx(Fe,{className:"mr-2 h-4 w-4"}),a("common.actions.close")]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:x.isPending?e.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[e.jsx(Q,{className:"h-5 w-40"}),e.jsx(Q,{className:"h-4 w-full"}),e.jsx(Q,{className:"h-4 w-3/4"}),e.jsx(Q,{className:"h-32 w-full"}),e.jsx(Q,{className:"h-4 w-1/2"})]}):l?e.jsxs("div",{className:"flex flex-col gap-6 px-6 py-5 text-sm",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-[1.15rem] border border-white/50 bg-background/70 p-3 text-xs shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("span",{className:"font-medium",children:a("logs.detail.summary.route",{from:l.client_model??a("logs.detail.info.noRequestedModel"),to:l.model})}),e.jsx("span",{className:"text-muted-foreground",children:a("logs.detail.summary.latency",{value:C(l.latency_ms,a("common.units.ms"))})}),l.ttft_ms!==null&&e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",C(l.ttft_ms,a("common.units.ms"))]}),e.jsx(P,{variant:l.error?"destructive":"default",children:m==null?void 0:m.toString()}),e.jsx(P,{variant:"outline",children:l.stream?a("logs.stream.streaming"):a("logs.stream.single")})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsx(M,{label:a("logs.detail.info.latency"),value:C(l.latency_ms,a("common.units.ms"))}),e.jsx(M,{label:a("logs.detail.info.ttft"),value:C(l.ttft_ms,a("common.units.ms"))}),e.jsx(M,{label:a("logs.detail.info.tpot"),value:C(l.tpot_ms,a("common.units.msPerToken"))})]}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.time")}),e.jsx("dd",{className:"font-medium",children:Pe(l.timestamp)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.sessionId")}),e.jsx("dd",{className:"font-medium",children:l.session_id??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.endpoint")}),e.jsx("dd",{className:"font-medium",children:l.endpoint||"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.provider")}),e.jsx("dd",{className:"font-medium",children:S})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.requestedModel")}),e.jsx("dd",{className:"font-medium",children:l.client_model??a("logs.detail.info.noRequestedModel")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.model")}),e.jsx("dd",{className:"font-medium",children:l.model})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.stream")}),e.jsx("dd",{className:"font-medium",children:ps(l.stream)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.status")}),e.jsx("dd",{className:"font-medium",children:m})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(M,{label:a("logs.detail.info.inputTokens"),value:L(l.input_tokens)}),e.jsx(M,{label:a("logs.detail.info.cacheReadTokens"),value:L(l.cache_read_tokens)}),e.jsx(M,{label:a("logs.detail.info.cacheCreationTokens"),value:L(l.cache_creation_tokens)}),e.jsx(M,{label:a("logs.detail.info.outputTokens"),value:L(l.output_tokens)})]}),e.jsx("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.latency")}),e.jsx("dd",{className:"font-medium",children:C(l.latency_ms,a("common.units.ms"))})]})}),l.error&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:a("logs.detail.info.error")}),e.jsx("p",{className:"rounded-[1rem] border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:l.error})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 text-sm sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.name")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id==null&&!l.api_key_name?a("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?a("apiKeys.wildcard"):(r==null?void 0:r.name)??l.api_key_name??a("logs.detail.apiKey.missing")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.identifier")}),e.jsx("dd",{className:"font-medium",children:l.api_key_id??a("common.noData")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.masked")}),e.jsx("dd",{className:"font-medium",children:r!=null&&r.isWildcard?a("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??l.api_key_name??a("logs.detail.apiKey.maskedUnavailable")})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:a("logs.detail.apiKey.lastUsed")}),e.jsx("dd",{className:"font-medium",children:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():a("common.noData")})]})]}),e.jsxs("div",{className:"rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:a("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:l.api_key_value_available?l.api_key_value_masked??a("logs.detail.apiKey.rawUnavailable"):a("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:a("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsx("section",{className:"space-y-3",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.request"),(u=l.payload)==null?void 0:u.prompt,"logs.detail.copy.requestSuccess")},children:[a("logs.detail.payload.request")," · ",a("common.actions.copy")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.response"),(u=l.payload)==null?void 0:u.response,"logs.detail.copy.responseSuccess")},children:[a("logs.detail.payload.response")," · ",a("common.actions.copy")]})]})}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.payload.request")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.request"),(u=l.payload)==null?void 0:u.prompt,"logs.detail.copy.requestSuccess")},children:a("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:$e((f=l.payload)==null?void 0:f.prompt,a("logs.detail.payload.emptyRequest"))})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:a("logs.detail.payload.response")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{var u;return N(a("logs.detail.payload.response"),(u=l.payload)==null?void 0:u.response,"logs.detail.copy.responseSuccess")},children:a("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap rounded-[1rem] border border-border/70 bg-background/70 p-3 text-xs",children:$e((p=l.payload)==null?void 0:p.response,a("logs.detail.payload.emptyResponse"))})]})]}):e.jsx("div",{className:"flex h-full items-center justify-center p-8 text-sm text-muted-foreground",children:a("logs.detail.loadError")})})]})]}),document.body)}function M({label:s,value:i}){return e.jsxs("div",{className:"rounded-xl border border-border/70 bg-background/60 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:"mt-2 text-sm font-semibold",children:i})]})}function js({apiKeys:s,selected:i,onChange:c,disabled:v,className:g}){const{t:a}=ae(),[d,j]=o.useState(!1),x=o.useRef(null);o.useEffect(()=>{if(!d)return;const r=m=>{var f;(f=x.current)!=null&&f.contains(m.target)||j(!1)};return window.addEventListener("mousedown",r),()=>window.removeEventListener("mousedown",r)},[d]);const N=o.useMemo(()=>{if(i.length===0)return[];const r=new Map;for(const m of s)r.set(m.id,m);return i.map(m=>{const f=r.get(m);return f?f.isWildcard?a("apiKeys.wildcard"):f.name:null}).filter(m=>!!m)},[s,i,a]),l=i.length===0?a("logs.filters.apiKeyAll"):a("logs.filters.apiKeySelected",{count:i.length}),S=r=>{i.includes(r)?c(i.filter(m=>m!==r)):c([...i,r])};return e.jsxs("div",{className:h("relative space-y-2",g),ref:x,children:[e.jsx(O,{children:a("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>j(r=>!r),disabled:v||s.length===0,title:a("logs.filters.apiKeyHint"),className:h("flex h-11 w-full items-center justify-between rounded-2xl border border-border/80 bg-background/85 px-4 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] ring-offset-background transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring/30 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",i.length>0&&"border-primary",d&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[l,N.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:N.join(", ")})]}),e.jsx("svg",{className:h("h-4 w-4 opacity-50 transition-transform",d&&"rotate-180"),viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.25a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z",clipRule:"evenodd"})})]}),d&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-[1.2rem] border border-white/60 bg-popover/95 p-2 shadow-[0_16px_40px_-28px_rgba(15,23,42,0.45)] backdrop-blur",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-xl bg-background/70 px-3 py-2 text-xs",children:[e.jsx("span",{children:l}),e.jsx("button",{type:"button",onClick:()=>c([]),disabled:i.length===0,className:"text-primary hover:underline disabled:opacity-40",children:a("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[s.map(r=>{const m=r.isWildcard?a("apiKeys.wildcard"):r.name,f=i.includes(r.id);return e.jsxs("label",{className:h("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",f&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:f,onChange:()=>S(r.id)}),e.jsx("span",{className:"truncate",children:m})]},r.id)}),s.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:a("logs.filters.apiKeyAll")})]})]})]})}export{Os as default};
@@ -1 +0,0 @@
1
- import{r as x,f as e,aj as Ve,$ as rs,a5 as _e,ad as as,ak as ce,k as ns,N as ht,af as os}from"./vendor-C92xTG6Z.js";import{u as ds,a as ls,b as lt}from"./query-CDpWKdnY.js";import{c as Z,u as gt,B as P,a as Y,b as ve,t as Te,T as is,d as cs,f as ms,g as us}from"./index-zyFaDjL5.js";import{u as ps}from"./useApiQuery-HKJqYJso.js";import{P as xs,B as F}from"./PageHeader-BIhjesDo.js";import{C as hs,D as ft,a as bt,b as vt,c as jt,d as yt,e as Nt}from"./ConfirmDialog-B6Hd3Eud.js";import{I as re}from"./input-CKjvZhjf.js";import{L as Q}from"./label-V0fmEe3U.js";import{C as Re,a as De}from"./card-DKAxXuqe.js";import{S as wt}from"./switch-V4Qh3v7X.js";import{S as kt,a as Mt,b as Ct,c as Et,d as W}from"./select-B9GMWo4R.js";import{P as gs,a as fs,b as bs}from"./popover-CSAdpdw2.js";import{u as me}from"./i18n-CZ1qKIdj.js";import"./router-DjNibHfR.js";import"./radix-Ccu1urVd.js";function qe(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function vs(){return{_key:qe(),id:"",label:""}}const Pe={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},it=[{value:"openai",label:"OpenAI"},{value:"deepseek",label:"DeepSeek"},{value:"huawei",label:"Huawei Cloud"},{value:"kimi",label:"Kimi"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"Custom"}];function ct(s){return s?{id:s.id,label:s.label??s.id,baseUrl:s.baseUrl,apiKey:s.apiKey??"",type:s.type??"custom",defaultModel:s.defaultModel??"",models:(s.models??[]).map(l=>({...l,_key:qe()})),authMode:s.authMode??"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function js(s){return{_key:qe(),id:s.id,label:s.label}}function ys({open:s,mode:l,provider:f,existingProviderIds:h,onClose:p,onSubmit:j}){const{t:r}=me(),[i,w]=x.useState(()=>ct(f)),[S,I]=x.useState({}),[U,g]=x.useState(!1),[C,k]=x.useState(null),v=x.useRef(null),E=x.useRef(null),$=x.useRef(null),[L,ae]=x.useState(l==="edit");x.useEffect(()=>{s&&(w(ct(f)),I({}),k(null),g(!1),ae(l==="edit"))},[s,f,l]),x.useEffect(()=>{if(!s)return;const c=b=>{b.key==="Escape"&&p()};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[s,p]),x.useEffect(()=>{if(s){if(l==="create"&&$.current){$.current.focus();return}E.current&&E.current.focus()}},[s,l]);const ne=l==="create",oe=x.useMemo(()=>i.models.filter(c=>c.id.trim().length>0),[i.models]),je=x.useMemo(()=>{var c;return((c=it.find(b=>b.value===i.type))==null?void 0:c.label)??"Custom"},[i.type]),ye=i.label.trim()||i.id.trim()||r("providers.drawer.summary.untitled"),Ne=x.useMemo(()=>[{label:r("providers.drawer.summary.type"),value:je},{label:r("providers.drawer.summary.auth"),value:i.authMode==="apiKey"?r("providers.drawer.fields.authModeApiKey"):i.authMode==="authToken"?r("providers.drawer.fields.authModeAuthToken"):r("providers.drawer.fields.authModeXAuthToken")},{label:r("providers.drawer.summary.models"),value:oe.length.toLocaleString()}],[oe.length,i.authMode,je,r]),de=c=>b=>{w(R=>({...R,[c]:b}))},G=c=>{w(b=>{const M=!L||b.label.trim().length===0||b.label===b.id?c:b.label;return{...b,id:c,label:M}})},B=c=>{w(b=>{var Ce;const M=Pe[c??"custom"]??Pe.custom,_=Object.values(Pe).map(te=>te.baseUrl).filter(te=>!!te),q=!b.baseUrl||_.includes(b.baseUrl),z=l==="create"&&(b.models.length===0||b.models.every(te=>te.id.trim().length===0)),X={...b,type:c,authMode:b.authMode??"apiKey"};return M!=null&&M.baseUrl&&q&&(X.baseUrl=M.baseUrl),M!=null&&M.models&&z&&(X.models=M.models.map(js),X.defaultModel=M.defaultModel??((Ce=M.models[0])==null?void 0:Ce.id)??""),X})},Oe=(c,b)=>{w(R=>{const M=[...R.models];return M[c]={...M[c],...b},{...R,models:M}})},H=(c,b)=>{w(R=>{const M=[...R.models],_=M[c];if(!_)return R;const q=!L||!_.label||_.label===_.id,z={..._,id:b,label:q?b:_.label};M[c]=z;const X=R.defaultModel===_.id?b:R.defaultModel;return{...R,models:M,defaultModel:X}})},Ue=c=>{w(b=>{if(c<0||c>=b.models.length)return b;const R=b.models.filter((_,q)=>q!==c);let M=b.defaultModel;return R.some(_=>_.id===M)||(M=""),{...b,models:R,defaultModel:M}})},we=()=>{w(c=>({...c,models:[...c.models,vs()]}))},le=c=>{w(b=>({...b,authMode:c}))},ue=()=>{const c={},b=i.id.trim(),R=i.baseUrl.trim();if(l==="create"&&(b.length===0?c.id=r("providers.drawer.errors.idRequired"):h.includes(b)&&(c.id=r("providers.drawer.errors.idDuplicate"))),l==="edit"&&b.length===0&&(c.id=r("providers.drawer.errors.idRequired")),R.length===0)c.baseUrl=r("providers.drawer.errors.baseUrlInvalid");else try{new URL(R)}catch{c.baseUrl=r("providers.drawer.errors.baseUrlInvalid")}if(i.models.length>0){const M=new Set;i.models.some(q=>{const z=q.id.trim();return z.length===0||M.has(z)?!0:(M.add(z),!1)})&&(c.models=r("providers.drawer.errors.modelInvalid"))}return i.defaultModel&&!i.models.some(M=>M.id===i.defaultModel)&&(c.models=r("providers.drawer.errors.defaultInvalid")),I(c),Object.keys(c).length===0},ke=()=>{const c=i.models.map(M=>{var _;return{id:M.id.trim(),label:(_=M.label)!=null&&_.trim()?M.label.trim():void 0}}).filter(M=>M.id.length>0),b=f!=null&&f.extraHeaders&&Object.keys(f.extraHeaders).length>0?f.extraHeaders:void 0,R=i.authMode!=="apiKey"?i.authMode:void 0;return{id:i.id.trim(),label:i.label.trim()||i.id.trim(),baseUrl:i.baseUrl.trim(),apiKey:i.apiKey.trim()||void 0,type:i.type??"custom",defaultModel:i.defaultModel||void 0,models:c.length>0?c:void 0,extraHeaders:b,authMode:R}},Me=async()=>{if(k(null),!!ue()){g(!0);try{const c=ke();await j(c)}catch(c){k(r("providers.drawer.toast.saveFailure",{message:c instanceof Error?c.message:"unknown"})),g(!1);return}g(!1),p()}};return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-slate-900/60 backdrop-blur-sm",onClick:p,"aria-hidden":"true"}),e.jsxs("aside",{ref:v,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-5xl flex-col border-l border-white/50 bg-background/96 shadow-[0_24px_80px_-32px_rgba(15,23,42,0.4)] backdrop-blur-xl dark:border-slate-800 dark:bg-slate-950/96",children:[e.jsxs("header",{className:"border-b border-border/70 bg-background/70 px-6 py-5 dark:border-slate-800",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"inline-flex rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em] text-primary",children:r(ne?"providers.drawer.quickStart":"providers.drawer.editTitle")}),e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold tracking-[-0.02em]",children:r(ne?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:r("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:E,onClick:p,className:"rounded-full border border-border/80 bg-background/85 px-4 py-2 text-sm transition hover:border-primary/20 hover:bg-primary/5",children:r("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:Ne.map(c=>e.jsxs("div",{className:"rounded-[1.2rem] border border-white/50 bg-card/88 px-4 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:c.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:c.value})]},c.label))})]}),e.jsxs("div",{className:"grid flex-1 overflow-hidden xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:r("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:it.map(c=>{var R;const b=c.value===i.type;return e.jsxs("button",{type:"button",onClick:()=>B(c.value),className:Z("rounded-2xl border px-4 py-3 text-left transition",b?"border-primary bg-primary/10 text-primary shadow-sm":"border-white/50 bg-card/88 text-foreground hover:border-primary/20 hover:bg-primary/5"),children:[e.jsx("div",{className:"text-sm font-semibold",children:c.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((R=Pe[c.value??"custom"])==null?void 0:R.baseUrl)??r("providers.drawer.hints.customProvider")})]},c.value??"custom")})})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-basic-info",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:r("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>ae(c=>!c),className:"rounded-full border border-border/80 bg-background/85 px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-primary/5",children:r(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-muted-foreground",children:r("providers.drawer.fields.id")}),e.jsx("input",{value:i.id,ref:$,onChange:c=>G(c.target.value),disabled:!ne,placeholder:r("providers.drawer.fields.idPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!S.id}),S.id?e.jsx("span",{className:"text-xs text-red-500",children:S.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.label")}),e.jsx("input",{value:i.label,onChange:c=>de("label")(c.target.value),placeholder:r("providers.drawer.fields.labelPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:i.baseUrl,onChange:c=>de("baseUrl")(c.target.value),placeholder:r("providers.drawer.fields.baseUrlPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!S.baseUrl}),S.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:S.baseUrl}):null]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-auth-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:r("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.hints.auth")})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.apiKey")}),e.jsx("input",{value:i.apiKey,onChange:c=>de("apiKey")(c.target.value),placeholder:r("providers.drawer.fields.apiKeyPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-[1.3rem] border border-white/50 bg-card/88 p-4 text-xs shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:r("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:r("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:i.authMode==="apiKey",onChange:()=>le("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:r("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:i.authMode==="authToken",onChange:()=>le("authToken"),className:"mt-0.5"}),e.jsx("span",{children:r("providers.drawer.fields.authModeAuthToken")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:i.authMode==="xAuthToken",onChange:()=>le("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:r("providers.drawer.fields.authModeXAuthToken")})]})]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-model-fields",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:r("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:we,className:"rounded-full border border-border/80 bg-background/85 px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-primary/5",children:r("providers.drawer.fields.addModel")})]}),S.models?e.jsx("p",{className:"text-xs text-red-500",children:S.models}):null,e.jsxs("div",{className:"space-y-4",children:[i.models.map((c,b)=>e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/88 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.modelId")}),e.jsx("input",{value:c.id,onChange:R=>H(b,R.target.value),placeholder:r("providers.drawer.fields.modelIdPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]}),L?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:r("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:c.label??"",onChange:R=>Oe(b,{label:R.target.value}),placeholder:r("providers.drawer.fields.modelLabelPlaceholder"),className:"h-11 rounded-2xl border border-border/80 bg-background/85 px-4 py-2 text-sm shadow-[0_1px_2px_rgba(15,23,42,0.03)] transition-all duration-200 focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:bg-muted/60 disabled:text-muted-foreground"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-slate-600 dark:text-slate-300",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:c.id,checked:i.defaultModel===c.id,onChange:()=>w(R=>({...R,defaultModel:c.id})),disabled:c.id.trim().length===0}),r("providers.drawer.fields.setDefault")]}),e.jsx("button",{type:"button",className:"text-red-500 transition hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>Ue(b),disabled:i.models.length===0,children:r("providers.drawer.fields.removeModel")})]})]},c._key)),i.models.length===0?e.jsx("div",{className:"rounded-2xl border border-amber-300 bg-gradient-to-br from-amber-50 to-yellow-50 p-5 shadow-sm dark:border-amber-600/60 dark:from-amber-900/20 dark:to-yellow-900/20",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:r("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:r("providers.drawer.noModelsHint",{providerId:i.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md bg-amber-100/80 p-2.5 dark:bg-amber-800/40",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-amber-900 dark:text-amber-200",children:r("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded-xl bg-white/90 px-2.5 py-1.5 font-mono text-xs text-amber-900 shadow-[0_1px_2px_rgba(15,23,42,0.06)] dark:bg-slate-900 dark:text-amber-100",children:['"claude-*": "',(i.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),oe.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:r("providers.drawer.defaultHint",{model:i.defaultModel||r("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden border-l border-border/70 bg-background/55 px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/92 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:ye}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:Ne.map(c=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:c.label}),e.jsx("span",{className:"text-right font-medium",children:c.value})]},c.label))})]}),e.jsxs("div",{className:"rounded-[1.3rem] border border-white/50 bg-card/92 p-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:r("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:r("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:r("providers.drawer.hints.checkModels")})]})]}),L&&e.jsxs("div",{className:"rounded-[1.3rem] border border-primary/20 bg-primary/5 p-4 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium text-primary",children:r("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:r("providers.drawer.hints.advancedBody")})]})]})})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-border/70 bg-background/70 px-6 py-4 text-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:C?e.jsx("span",{children:C}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:p,className:"rounded-full border border-border/80 bg-background/85 px-4 py-2 transition hover:border-primary/20 hover:bg-primary/5",disabled:U,children:r("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:Me,className:"rounded-full bg-primary px-5 py-2 text-primary-foreground shadow-[0_8px_20px_-12px_rgba(59,130,246,0.65)] transition hover:-translate-y-0.5 hover:bg-primary/95 disabled:opacity-60",disabled:U,children:r(U?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const Ns=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],ws=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function He(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function ee(s){return s?Object.entries(s).map(([l,f])=>({id:He(),source:l,target:f})):[]}function ze(s,l){var p,j,r;if(!s)return{};const f={},h=s.endpointRouting??{};f.anthropic=ee(((p=h.anthropic)==null?void 0:p.modelRoutes)??s.modelRoutes??{}),f.openai=ee(((j=h.openai)==null?void 0:j.modelRoutes)??{});for(const i of l)(r=i.routing)!=null&&r.modelRoutes?f[i.id]=ee(i.routing.modelRoutes):f[i.id]=[];return f}function mt(s,l,f){var j,r,i;const h=l.find(w=>w.id===f);if(h)return((j=h.routing)==null?void 0:j.modelRoutes)??{};const p=s.endpointRouting??{};return f==="anthropic"?((r=p.anthropic)==null?void 0:r.modelRoutes)??s.modelRoutes??{}:f==="openai"?((i=p.openai)==null?void 0:i.modelRoutes)??{}:{}}function ks(s){const l={};for(const f of s){const h=f.source.trim(),p=f.target.trim();h&&p&&(l[h]=p)}return l}function ut(s,l){return JSON.stringify(ks(s))!==JSON.stringify(l)}function Ms(s,l){if(s==="anthropic")return!0;const f=l.find(h=>h.id===s);return f?f.paths&&f.paths.length>0?f.paths.some(h=>h.protocol==="anthropic"):f.protocol==="anthropic":!1}function Cs(s,l,f){var p,j,r;if(!l)return;if(s==="anthropic"||s==="openai")return(j=(p=l.endpointRouting)==null?void 0:p[s])==null?void 0:j.validation;const h=f.find(i=>i.id===s);return(r=h==null?void 0:h.routing)==null?void 0:r.validation}function Qs(){const{t:s}=me(),{pushToast:l}=gt(),f=ds(),h=ps(["config","full"],{url:"/api/config",method:"GET"}),{data:p}=ls({queryKey:["custom-endpoints"],queryFn:ve.list,refetchInterval:1e4}),j=(p==null?void 0:p.endpoints)??[],r=x.useMemo(()=>{const t=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],n=j.map(a=>{let o,d=[];if(a.paths&&a.paths.length>0){const m=a.paths.map(u=>`${u.path} (${u.protocol})`).join(", ");o=`${s("modelManagement.tabs.customEndpoint")}: ${m}`,d=[...new Set(a.paths.map(u=>u.protocol))]}else if(a.path){const m=a.protocol||"anthropic";o=`${s("modelManagement.tabs.customEndpoint")}: ${a.path} (${m})`,d=[m]}else o=s("modelManagement.tabs.customEndpoint");return{key:a.id,label:a.label,description:o,isSystem:!1,canDelete:a.deletable!==!1,protocols:d}});return[...t,...n]},[s,j]),[i,w]=x.useState("providers"),S=x.useMemo(()=>r.filter(t=>t.isSystem),[r]),I=x.useMemo(()=>r.filter(t=>!t.isSystem),[r]),U=x.useMemo(()=>r.find(t=>t.key===i)??r[0]??null,[i,r]),[g,C]=x.useState(null),[k,v]=x.useState(!1),[E,$]=x.useState("create"),[L,ae]=x.useState(void 0),[ne,oe]=x.useState(null),[je,ye]=x.useState(!1),[Ne,de]=x.useState(void 0),[G,B]=x.useState({}),[Oe,H]=x.useState({}),[Ue,we]=x.useState(null),[le,ue]=x.useState({}),[ke,Me]=x.useState({}),[c,b]=x.useState({}),[R,M]=x.useState(null),[_,q]=x.useState(null),[z,X]=x.useState(null),[Ce,te]=x.useState(!1),[$e,Qe]=x.useState(null),[Ee,Ae]=x.useState(!0),[Ge,Xe]=x.useState({}),[St,Je]=x.useState(!1),[Rt,Dt]=x.useState({}),[Le,Ie]=x.useState(null),[N,pe]=x.useState(null),[Fe,Ye]=x.useState(!1),[Se,We]=x.useState(""),[xe,Ze]=x.useState("all"),V=(g==null?void 0:g.providers)??[],et=V.length,tt=x.useMemo(()=>V.filter(t=>{var d;if(!(xe==="all"||(t.type??"custom")===xe))return!1;const a=Se.trim().toLowerCase();return a?[t.id,t.label??"",t.baseUrl,t.defaultModel??"",...((d=t.models)==null?void 0:d.map(m=>m.id))??[]].join(" ").toLowerCase().includes(a):!0}),[Se,xe,V]),he=x.useMemo(()=>[{key:"anthropic-beta",value:"claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",label:s("providers.testDialog.options.beta.label"),description:s("providers.testDialog.options.beta.description")}],[s]);x.useEffect(()=>{var t,n;if(h.data){const a=h.data;C(a),B(d=>{const m=ze(a,j);if(!d||Object.keys(d).length===0)return m;const u={...m};for(const[y,D]of Object.entries(d)){if(!(y in m))continue;const A=mt(a,j,y);ut(D,A)&&(u[y]=D)}return u}),H({});const o={anthropic:((t=a.routingPresets)==null?void 0:t.anthropic)??[],openai:((n=a.routingPresets)==null?void 0:n.openai)??[]};for(const d of j)o[d.id]=d.routingPresets??[];ue(o)}},[h.data,j]),x.useEffect(()=>{h.isError&&h.error&&l({title:s("providers.toast.loadFailure",{message:h.error.message}),variant:"error"})},[h.isError,h.error,l,s]);const st=x.useMemo(()=>{const t=new Map;for(const n of V){if(!n.defaultModel||!n.models)continue;const a=n.models.find(o=>o.id===n.defaultModel);a&&t.set(n.id,xt(a))}return t},[V]),Pt=x.useMemo(()=>{const t=[],n=new Set;for(const o of V){const d=o.label&&o.label!==o.id?`${o.label} (${o.id})`:o.id,m=o.models??[];if(m.length>0)for(const y of m){const D=`${o.id}:${y.id}`;n.has(D)||(n.add(D),t.push({value:D,label:`${d} · ${y.label??y.id}`}))}else if(o.defaultModel){const y=`${o.id}:${o.defaultModel}`;n.has(y)||(n.add(y),t.push({value:y,label:`${d} · ${o.defaultModel}`}))}const u=`${o.id}:*`;n.has(u)||(n.add(u),t.push({value:u,label:s("settings.routing.providerPassthroughOption",{provider:d})}))}const a=Object.values(G).flat();for(const o of a){const d=o.target.trim();d&&!n.has(d)&&(n.add(d),t.push({value:d,label:d}))}return t},[V,G,s]),_t=t=>g?mt(g,j,t):{},Tt=(t,n)=>ut(t,n),Ke=x.useMemo(()=>{const t={};for(const n of r){if(n.key==="providers")continue;const a=G[n.key]||[],o=_t(n.key);t[n.key]=Tt(a,o)}return t},[G,g,j,r]),rt=(t,n)=>{ue(a=>({...a,[t]:n})),C(a=>{if(!a)return a;if(t==="anthropic"||t==="openai")return{...a,routingPresets:{...a.routingPresets,[t]:n}};const o=a.customEndpoints??[],d=o.findIndex(u=>u.id===t);if(d===-1)return a;const m=[...o];return m[d]={...m[d],routingPresets:n},{...a,customEndpoints:m}})},se=()=>g?!0:(l({title:s("settings.toast.missingConfig"),variant:"error"}),h.refetch(),!1),Ot=(t,n)=>{Me(a=>({...a,[t]:n})),n.trim()&&b(a=>({...a,[t]:null}))},Ut=async t=>{if(!se())return;const n=ke[t].trim();if(!n){b(a=>({...a,[t]:s("modelManagement.validation.presetName")}));return}if(le[t].some(a=>a.name.toLowerCase()===n.toLowerCase())){b(a=>({...a,[t]:s("modelManagement.validation.presetDuplicate",{name:n})}));return}M(t);try{const o=(await Y.post(`/api/routing-presets/${t}`,{name:n})).data.presets??[];rt(t,o),Me(d=>({...d,[t]:""})),b(d=>({...d,[t]:null})),l({title:s("modelManagement.toast.presetSaved",{name:n}),variant:"success"})}catch(a){l({title:s("modelManagement.toast.presetSaveFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{M(null),h.refetch()}},$t=async(t,n)=>{var a,o,d;if(se()){q({endpoint:t,name:n.name});try{const u=(await Y.post(`/api/routing-presets/${t}/apply`,{name:n.name})).data.config;if(u){C(u),B(ze(u,j));const y={anthropic:((a=u.routingPresets)==null?void 0:a.anthropic)??[],openai:((o=u.routingPresets)==null?void 0:o.openai)??[]};for(const D of j){const A=(d=u.customEndpoints)==null?void 0:d.find(T=>T.id===D.id);y[D.id]=(A==null?void 0:A.routingPresets)??[]}ue(y)}else B(y=>({...y,[t]:ee(n.modelRoutes)}));l({title:s("modelManagement.toast.presetApplySuccess",{name:n.name}),variant:"success"})}catch(m){l({title:s("modelManagement.toast.presetApplyFailure",{message:m instanceof Error?m.message:"unknown"}),variant:"error"})}finally{q(null),h.refetch()}}},At=async(t,n)=>{if(se()){X({endpoint:t,name:n.name});try{const o=(await Y.delete(`/api/routing-presets/${t}/${encodeURIComponent(n.name)}`)).data.presets??[];rt(t,o),l({title:s("modelManagement.toast.presetDeleteSuccess",{name:n.name}),variant:"success"})}catch(a){l({title:s("modelManagement.toast.presetDeleteFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{X(null),h.refetch()}}},Lt=()=>{se()&&($("create"),ae(void 0),v(!0))},It=t=>{se()&&($("edit"),ae(t),v(!0))},Ft=async t=>{if(!g)throw new Error(s("settings.toast.missingConfig"));const n=E==="create"?[...V,t]:V.map(d=>L&&d.id===L.id?{...t,id:L.id}:d),a={...g,providers:n};await Y.put("/api/config",a),C(a),B(ze(a,j)),h.refetch();const o=E==="create"?s("providers.toast.createSuccess",{name:t.label||t.id}):s("providers.toast.updateSuccess",{name:t.label||t.id});l({title:o,variant:"success"})},Kt=async t=>{const n=j.find(a=>a.id===t);if(n&&n.deletable!==!1)try{await ve.delete(t),f.invalidateQueries({queryKey:["custom-endpoints"]}),l({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),i===t&&w("providers")}catch(a){const o=Te(a);l({title:s("modelManagement.deleteEndpointError",{error:o.message}),variant:"error"})}},at=async(t,n)=>{oe(t.id);try{const a=n&&(n.headers||n.query)?{headers:n.headers&&Object.keys(n.headers).length>0?n.headers:void 0,query:n.query&&n.query.trim().length>0?n.query.trim():void 0}:void 0,o=await Y.post(`/api/providers/${t.id}/test`,a);o.data.ok?l({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:o.data.status,duration:o.data.durationMs?`${o.data.durationMs} ms`:"—"}),variant:"success"}):l({title:s("providers.toast.testFailure",{message:`${o.data.status} ${o.data.statusText}`}),variant:"error"})}catch(a){l({title:s("providers.toast.testFailure",{message:a instanceof Error?a.message:"unknown"}),variant:"error"})}finally{oe(null)}},Bt=t=>{if(t.type==="anthropic"){const n=t.extraHeaders??{},a=new Map(he.map(m=>[m.key.toLowerCase(),m])),o={};let d=!0;for(const m of he){const u=Object.entries(n).find(([y])=>y.toLowerCase()===m.key.toLowerCase());if(u){const[y,D]=u;String(D??"")===m.value||(d=!1,o[y]=String(D??""))}}for(const[m,u]of Object.entries(n))a.has(m.toLowerCase())||(o[m]=String(u??""));Xe(o),Ae(d),Qe(t),te(!0);return}at(t)},nt=()=>{te(!1),Qe(null),Ae(!0),Xe({})},zt=async()=>{if(!$e)return;const t={};if(Ee)for(const o of he)t[o.key]=o.value;const n=new Map(he.map(o=>[o.key.toLowerCase(),o]));for(const[o,d]of Object.entries(Ge)){const m=o.toLowerCase();n.get(m)&&Ee||(t[o]=d)}const a=$e;nt(),await at(a,{headers:Object.keys(t).length>0?t:void 0,query:Ee?"beta=true":void 0})},Vt=async t=>{var y,D,A,T;if(!se())return;const n=V.filter(K=>K.id!==t.id),a=K=>{const J={};if(!K)return J;for(const[ge,ie]of Object.entries(K)){if(!ie)continue;const[fe]=ie.split(":");fe&&fe===t.id||ie===t.id||(J[ge]=ie)}return J},o=(g==null?void 0:g.endpointRouting)??{},d=a(((y=o.anthropic)==null?void 0:y.modelRoutes)??(g==null?void 0:g.modelRoutes)??{}),m=a(((D=o.openai)==null?void 0:D.modelRoutes)??{}),u={...g,providers:n,modelRoutes:d,endpointRouting:{anthropic:{defaults:((A=o.anthropic)==null?void 0:A.defaults)??g.defaults,modelRoutes:d},openai:{defaults:((T=o.openai)==null?void 0:T.defaults)??g.defaults,modelRoutes:m}}};try{await Y.put("/api/config",u),C(u),B({anthropic:ee(d),openai:ee(m)}),l({title:s("providers.toast.deleteSuccess",{name:t.label||t.id}),variant:"success"}),h.refetch()}catch(K){l({title:s("providers.toast.deleteFailure",{message:K instanceof Error?K.message:"unknown"}),variant:"error"})}},Ht=async()=>{if(N){Ye(!0);try{N.kind==="provider"?await Vt(N.provider):N.kind==="preset"?await At(N.endpoint,N.preset):await Kt(N.endpoint.id),pe(null)}finally{Ye(!1)}}},qt=t=>{B(n=>({...n,[t]:[...n[t]||[],{id:He(),source:"",target:""}]})),H(n=>({...n,[t]:null}))},Qt=async(t,n)=>{if(se()){Je(!0);try{if(t==="anthropic"||t==="openai"){const a=g.endpointRouting?{...g.endpointRouting}:{},o=a[t]??{defaults:g.defaults,modelRoutes:(t==="anthropic"?g.modelRoutes:{})??{}},d={defaults:o.defaults??g.defaults,modelRoutes:o.modelRoutes??{}};let m=o.validation;n?(m={...m??{},mode:"claude-code"},m.allowExperimentalBlocks===void 0&&(m.allowExperimentalBlocks=!0)):m=void 0;const u=m?{...d,validation:m}:{...d},y={...a,[t]:u},D={...g,endpointRouting:y};await Y.put("/api/config",D),C(D)}else{const a=g.customEndpoints??[],o=a.findIndex(K=>K.id===t);if(o===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const d=a[o],m=d.routing??{defaults:g.defaults,modelRoutes:{}};let u=m.validation;n?(u={...u??{},mode:"claude-code"},u.allowExperimentalBlocks===void 0&&(u.allowExperimentalBlocks=!0)):u=void 0;const y=u?{...m,validation:u}:{...m},D={...d,routing:y},A=[...a];A[o]=D;const T={...g,customEndpoints:A};await Y.put("/api/config",T),C(T)}l({title:s(n?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),h.refetch()}catch(a){const o=Te(a);l({title:s("modelManagement.toast.claudeValidationFailure",{message:o.message}),variant:"error"})}finally{Je(!1)}}},Gt=(t,n)=>{B(a=>{const o=a[t]||[];return o.some(d=>d.source.trim()===n.trim())?a:{...a,[t]:[...o,{id:He(),source:n,target:""}]}}),H(a=>({...a,[t]:null}))},ot=(t,n,a,o)=>{B(d=>({...d,[t]:(d[t]||[]).map(m=>m.id===n?{...m,[a]:o}:m)})),H(d=>({...d,[t]:null}))},Xt=(t,n)=>{B(a=>({...a,[t]:(a[t]||[]).filter(o=>o.id!==n)})),H(a=>({...a,[t]:null}))},Jt=t=>{var a,o;if(!g)return;const n=j.find(d=>d.id===t);if(n){const d=((a=n.routing)==null?void 0:a.modelRoutes)??{};B(m=>({...m,[t]:ee(d)}))}else{const d=g.endpointRouting??{},m=t,u=m==="anthropic"?g.modelRoutes??{}:{},y=((o=d[m])==null?void 0:o.modelRoutes)??u;B(D=>({...D,[t]:ee(y)}))}H(d=>({...d,[t]:null}))},Yt=async t=>{var o;if(!se())return;const n=G[t]||[],a={};for(const d of n){const m=d.source.trim(),u=d.target.trim();if(!(!m&&!u)){if(!m||!u){H(y=>({...y,[t]:s("settings.validation.routePair")}));return}if(a[m]){H(y=>({...y,[t]:s("settings.validation.routeDuplicate",{model:m})}));return}a[m]=u}}H(d=>({...d,[t]:null})),we(t);try{const d=j.find(m=>m.id===t);if(d){const m={...d.routing||{},modelRoutes:a,defaults:((o=d.routing)==null?void 0:o.defaults)||g.defaults};await ve.update(t,{routing:m}),f.invalidateQueries({queryKey:["custom-endpoints"]}),l({title:s("modelManagement.toast.routesSaved"),variant:"success"})}else{const m=g.endpointRouting?{...g.endpointRouting}:{},u=t,y=m[u]??{defaults:g.defaults,modelRoutes:u==="anthropic"?g.modelRoutes??{}:{}},D={...y,defaults:y.defaults??g.defaults,modelRoutes:a},A={...m,[u]:D},T={...g,endpointRouting:A,modelRoutes:u==="anthropic"?a:g.modelRoutes??{}};await Y.put("/api/config",T),C(T),l({title:s("modelManagement.toast.routesSaved"),variant:"success"}),h.refetch()}B(m=>({...m,[t]:ee(a)}))}catch(d){l({title:s("modelManagement.toast.routesSaveFailure",{message:d instanceof Error?d.message:"unknown"}),variant:"error"})}finally{we(null)}},Wt=()=>e.jsx(Re,{className:"surface-1",children:e.jsxs(De,{className:"pt-6 space-y-6",children:[e.jsx(pt,{eyebrow:"Model Access",title:s("providers.title"),description:s("providers.description"),breadcrumb:[s("modelManagement.title"),s("modelManagement.tabs.providers")],aside:e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto sm:gap-3",children:[e.jsx(F,{variant:"secondary",children:s("providers.count",{count:et})}),e.jsxs(P,{variant:"outline",size:"sm",onClick:()=>h.refetch(),disabled:h.isFetching,children:[e.jsx(as,{className:Z("mr-2 h-4 w-4",h.isFetching&&"animate-spin")}),h.isFetching?s("common.actions.refreshing"):s("providers.actions.refresh")]}),e.jsxs(P,{size:"sm",onClick:Lt,children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("providers.actions.add")]})]})}),e.jsxs("div",{className:"grid gap-3 rounded-[1.35rem] border border-border/70 bg-[linear-gradient(135deg,rgba(255,255,255,0.7),rgba(248,250,252,0.82))] p-4 lg:grid-cols-[minmax(0,1fr)_220px_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.filters.searchPlaceholder")}),e.jsx(re,{value:Se,onChange:t=>We(t.target.value),placeholder:s("providers.filters.searchPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.filters.typeAll")}),e.jsxs(kt,{value:xe,onValueChange:Ze,children:[e.jsx(Mt,{children:e.jsx(Ct,{})}),e.jsxs(Et,{children:[e.jsx(W,{value:"all",children:s("providers.filters.typeAll")}),e.jsx(W,{value:"openai",children:"OpenAI"}),e.jsx(W,{value:"anthropic",children:"Anthropic"}),e.jsx(W,{value:"deepseek",children:"DeepSeek"}),e.jsx(W,{value:"huawei",children:"Huawei"}),e.jsx(W,{value:"kimi",children:"Kimi"}),e.jsx(W,{value:"custom",children:"Custom"})]})]})]}),e.jsx("div",{className:"flex items-end",children:e.jsx(P,{variant:"ghost",size:"sm",onClick:()=>{We(""),Ze("all")},disabled:!Se.trim()&&xe==="all",children:s("common.actions.reset")})})]}),h.isPending||!g&&h.isFetching?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-[1.25rem] border border-border/70 bg-background/45 text-sm text-muted-foreground",children:s("common.loading")}):V.length===0?e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:s("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:s("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):tt.length===0?e.jsx("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:s("providers.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4 [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:tt.map(t=>{var n;return e.jsx(Re,{className:"surface-1 flex flex-col overflow-hidden border-border/70",children:e.jsxs(De,{className:"flex flex-1 flex-col gap-4 pt-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold tracking-[-0.02em]",children:t.label||t.id}),t.type&&e.jsx(Ds,{type:t.type})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",t.id]}),e.jsx("p",{className:"break-all text-xs text-muted-foreground",children:t.baseUrl})]}),t.defaultModel?e.jsx(F,{variant:"default",className:"text-xs",children:st.get(t.id)??t.defaultModel}):e.jsx(F,{variant:"secondary",className:"text-xs",children:s("providers.card.noDefault")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.authMode")}),e.jsx("p",{className:"mt-1 text-sm font-medium",children:t.authMode==="authToken"?"Bearer":t.authMode==="xAuthToken"?"X-Auth-Token":"API Key"})]}),e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.modelsTitle")}),e.jsx("p",{className:"mt-1 text-sm font-medium",children:(n=t.models)!=null&&n.length?s("providers.card.modelCount",{count:t.models.length}):s("providers.card.passthrough")})]}),e.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/80 px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.defaultModelLabel")}),e.jsx("p",{className:"mt-1 truncate text-sm font-medium",children:t.defaultModel?st.get(t.id)??t.defaultModel:s("providers.card.noDefault")})]})]}),e.jsxs("div",{className:"space-y-2 rounded-[1.1rem] border border-border/70 bg-background/55 p-3",children:[e.jsx(Q,{className:"text-xs uppercase tracking-[0.16em] text-muted-foreground",children:s("providers.card.modelsTitle")}),t.models&&t.models.length>0?e.jsx("div",{className:"flex max-h-24 flex-wrap gap-1 overflow-y-auto",children:t.models.map(a=>e.jsx(F,{variant:"outline",className:"text-xs",children:xt(a)},a.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.card.noModels")})]}),e.jsxs("div",{className:"mt-auto flex flex-wrap gap-2 border-t border-border/70 pt-4",children:[e.jsx(P,{variant:"default",size:"sm",onClick:()=>It(t),children:s("providers.actions.edit")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Bt(t),disabled:ne===t.id,children:ne===t.id?s("common.actions.testingConnection"):s("providers.actions.test")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>pe({kind:"provider",provider:t}),children:s("providers.actions.delete")})]})]})},t.id)})})]})}),Zt=t=>{const n=le[t]??[],a=ke[t]??"",o=c[t],d=R===t,m=Rt[t]===!0;return e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 p-4 text-left transition-colors hover:bg-primary/5",onClick:()=>Dt(u=>({...u,[t]:!m})),children:e.jsxs("div",{className:"flex items-center gap-2",children:[m?e.jsx(os,{className:"h-4 w-4"}):e.jsx(ht,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:s("modelManagement.presets.title")}),e.jsx(F,{variant:"secondary",className:"text-xs",children:n.length})]})}),m&&e.jsxs("div",{className:"border-t px-4 pb-4 pt-3 space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(re,{value:a,onChange:u=>Ot(t,u.target.value),placeholder:s("modelManagement.presets.namePlaceholder"),disabled:d,className:"w-full md:w-48"}),e.jsx(P,{onClick:()=>void Ut(t),disabled:d,children:s(d?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),o&&e.jsx("p",{className:"text-sm text-destructive",children:o}),n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:s("modelManagement.presets.empty")}):e.jsx(is,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:n.map(u=>{const y=(_==null?void 0:_.endpoint)===t&&(_==null?void 0:_.name)===u.name,D=(z==null?void 0:z.endpoint)===t&&(z==null?void 0:z.name)===u.name,A=Object.entries(u.modelRoutes??{}),T=A.length;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[1.15rem] border border-white/50 bg-card/88 px-4 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsxs(cs,{children:[e.jsx(ms,{asChild:!0,children:e.jsxs("div",{className:"min-w-0 flex-1 cursor-default",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:u.name}),e.jsx(F,{variant:"outline",className:"mt-1 text-xs",children:T>0?s("modelManagement.presets.rulesCount",{count:T}):s("modelManagement.presets.noRules")})]})}),T>0&&e.jsx(us,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[A.slice(0,5).map(([K,J])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:K}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:J})]},K)),T>5&&e.jsxs("div",{className:"text-muted-foreground",children:["…+",T-5]})]})})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(P,{size:"sm",onClick:()=>Ie({endpoint:t,preset:u}),disabled:y||D,children:s(y?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(P,{variant:"destructive",size:"sm",onClick:()=>pe({kind:"preset",endpoint:t,preset:u}),disabled:D||y,children:s(D?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},u.name)})})})]})]})},es=t=>{var fe;const n=G[t]||[],a=Oe[t],o=r.find(O=>O.key===t),m=((fe=o==null?void 0:o.protocols)==null?void 0:fe.includes("anthropic"))??t==="anthropic"?Ns:ws,u=Ue===t,y=Ke[t]??!1,D=(o==null?void 0:o.label)??s(`modelManagement.tabs.${t}`),A=(o==null?void 0:o.isSystem)===!1?o.description:s(`settings.routing.descriptionByEndpoint.${t}`),T=`route-source-${t}`,K=Ms(t,j),J=Cs(t,g,j),ge=K&&(J==null?void 0:J.mode)==="claude-code",ie=new Set(n.map(O=>O.source.trim()).filter(Boolean));return e.jsx(Re,{className:"surface-1",children:e.jsxs(De,{className:"pt-6 space-y-6",children:[e.jsx(pt,{eyebrow:"Routing Workspace",title:s("settings.routing.titleByEndpoint",{endpoint:D}),description:A,breadcrumb:[s("modelManagement.title"),D],aside:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(F,{variant:"outline",children:[n.length," rules"]}),y?e.jsx(F,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:s("modelManagement.actions.unsaved")}):e.jsx(F,{variant:"secondary",children:s("common.status.success")})]})}),e.jsx("div",{className:"rounded-[1.2rem] border border-border/70 bg-background/55 px-4 py-3 text-xs text-muted-foreground",children:s("settings.routing.wildcardHint")}),K&&e.jsx("div",{className:"rounded-[1.25rem] border border-blue-200 bg-blue-50/75 p-4 dark:border-blue-800 dark:bg-blue-950",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:s("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-blue-700 dark:text-blue-300",children:s("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wt,{checked:ge,onCheckedChange:O=>void Qt(t,O),disabled:St}),e.jsx("span",{className:Z("text-xs font-medium",ge?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:s(ge?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}),Zt(t),a&&e.jsx("p",{className:"text-sm text-destructive",children:a}),e.jsxs("div",{className:"space-y-3 rounded-[1.35rem] border border-border/70 bg-[linear-gradient(135deg,rgba(255,255,255,0.7),rgba(248,250,252,0.82))] p-4",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx(Q,{className:"text-sm font-semibold text-foreground",children:s("modelManagement.routesEditorTitle")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Source model -> target provider:model"})]})}),n.length===0?e.jsxs("div",{className:"rounded-[1.25rem] border border-dashed border-border/70 bg-background/45 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:s("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:s("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{children:s("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:s("settings.routing.target")}),e.jsx("span",{})]}),n.map((O,be)=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 rounded-[1rem] border border-border/60 bg-background/80 p-3",children:[e.jsx(re,{value:O.source,onChange:Be=>ot(t,O.id,"source",Be.target.value),placeholder:s("settings.routing.sourcePlaceholder"),list:T,disabled:u,"aria-label":`route-source-${be+1}`}),e.jsx(ce,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),e.jsx(Ss,{value:O.target,onChange:Be=>ot(t,O.id,"target",Be),options:Pt,disabled:u,placeholder:s("settings.routing.targetPlaceholder")}),e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>Xt(t,O.id),disabled:u,children:e.jsx(_e,{className:"h-4 w-4"})})]},O.id))]})]}),e.jsxs("div",{className:"rounded-[1.25rem] border border-border/70 bg-background/55 p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsx(Q,{className:"text-sm font-semibold text-foreground",children:s("settings.routing.suggested")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"One click to seed common source models for this endpoint."})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(O=>{const be=ie.has(O);return e.jsx(P,{variant:be?"ghost":"outline",size:"sm",onClick:()=>Gt(t,O),disabled:u||be,className:be?"opacity-50":"",children:O},`${t}-${O}`)})})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-[1.25rem] border border-white/50 bg-card/82 p-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:s("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s(y?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{variant:"outline",size:"sm",onClick:()=>qt(t),disabled:u,children:s("settings.routing.add")}),e.jsx(P,{variant:"outline",size:"sm",onClick:()=>Jt(t),disabled:u||!y,children:s("common.actions.reset")}),e.jsxs(P,{size:"sm",onClick:()=>void Yt(t),disabled:u,className:"relative",children:[s(u?"common.actions.saving":"modelManagement.actions.saveRoutes"),y&&e.jsx("span",{className:"absolute -top-1 -right-1 h-2 w-2 rounded-full bg-amber-500"})]})]})]}),e.jsx("datalist",{id:T,children:m.map(O=>e.jsx("option",{value:O},`${T}-${O}`))})]})})},ts=(N==null?void 0:N.kind)==="provider"?s("providers.actions.delete"):(N==null?void 0:N.kind)==="preset"?s("modelManagement.presets.delete"):(N==null?void 0:N.kind)==="endpoint"?s("common.delete"):"",ss=(N==null?void 0:N.kind)==="provider"?s("providers.confirm.delete",{name:N.provider.label||N.provider.id}):(N==null?void 0:N.kind)==="preset"?s("modelManagement.confirm.deletePreset",{name:N.preset.name}):(N==null?void 0:N.kind)==="endpoint"?s("modelManagement.deleteEndpointConfirm",{label:N.endpoint.label}):"",dt=(N==null?void 0:N.kind)==="provider"?N.provider.label||N.provider.id:(N==null?void 0:N.kind)==="preset"?N.preset.name:(N==null?void 0:N.kind)==="endpoint"?N.endpoint.label:"";return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(xs,{icon:e.jsx(rs,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),actions:e.jsxs(P,{onClick:()=>{de(void 0),ye(!0)},children:[e.jsx(Ve,{className:"mr-2 h-4 w-4"}),s("modelManagement.addEndpoint")]})}),e.jsx(Re,{className:"surface-1 overflow-hidden",children:e.jsxs(De,{className:"space-y-5 pt-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(F,{variant:"outline",className:"border-primary/20 bg-primary/5 text-primary",children:[s("modelManagement.tabs.providers")," · ",et]}),e.jsxs(F,{variant:"outline",children:[s("modelManagement.tabs.customEndpoint")," · ",I.length]})]}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:U==null?void 0:U.label}),e.jsx("p",{className:"text-sm text-muted-foreground",children:U==null?void 0:U.description})]}),e.jsx("div",{className:"rounded-2xl border border-border/70 bg-background/75 px-3 py-2 text-xs text-muted-foreground",children:I.length>0?"自定义端点较多时,优先在下方端点带中切换,避免横向挤压布局。":"先配置提供商与内置路由,需要时再追加自定义端点。"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"内置视图"})}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:S.map(t=>{const n=i===t.key,a=t.key!=="providers"&&Ke[t.key];return e.jsxs("button",{type:"button",onClick:()=>w(t.key),className:Z("group flex min-h-[108px] flex-col justify-between rounded-[1.25rem] border px-4 py-4 text-left transition-all",n?"border-primary/35 bg-[linear-gradient(135deg,rgba(59,130,246,0.12),rgba(59,130,246,0.03))] shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]":"border-border/70 bg-background/75 hover:border-primary/20 hover:bg-primary/5"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:Z("text-lg font-semibold tracking-[-0.02em]",n?"text-primary":"text-foreground"),children:t.label}),a?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsx("span",{className:"line-clamp-2 text-sm text-muted-foreground",children:t.description})]},t.key)})})]}),I.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"自定义接入端点"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"端点较多时保留紧凑卡片与横向滚动,避免标题和路径把整行撑乱。"})]})}),e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-full gap-3",children:I.map(t=>{const n=i===t.key,a=Ke[t.key];return e.jsxs("div",{className:Z("group relative flex w-[260px] shrink-0 snap-start flex-col gap-3 rounded-[1.2rem] border px-4 py-4 text-left transition-all",n?"border-primary/35 bg-[linear-gradient(135deg,rgba(59,130,246,0.12),rgba(59,130,246,0.03))] shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]":"border-border/70 bg-background/80 hover:border-primary/20 hover:bg-primary/5"),children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>w(t.key),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:Z("truncate text-base font-semibold tracking-[-0.02em]",n?"text-primary":"text-foreground"),children:t.label}),a?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm text-muted-foreground",children:t.description})]}),t.canDelete?e.jsx("button",{type:"button",onClick:o=>{o.stopPropagation();const d=j.find(m=>m.id===t.key);d&&pe({kind:"endpoint",endpoint:d})},className:"flex h-7 w-7 items-center justify-center rounded-full border border-transparent text-muted-foreground transition hover:border-destructive/20 hover:bg-destructive/10 hover:text-destructive",title:s("common.delete"),children:e.jsx(_e,{className:"h-3.5 w-3.5"})}):null]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(t.protocols??[]).map(o=>e.jsx(F,{variant:"outline",className:"max-w-full truncate border-border/70 bg-background/80 text-[11px] text-muted-foreground",children:o},`${t.key}-${o}`))})]},t.key)})})})]}):null]})}),i==="providers"?Wt():es(i),e.jsx(ys,{open:k,mode:E,provider:E==="edit"?L:void 0,existingProviderIds:V.map(t=>t.id).filter(t=>E==="edit"&&L?t!==L.id:!0),onClose:()=>{v(!1),ae(void 0),$("create")},onSubmit:Ft}),e.jsx(Ps,{open:je,endpoint:Ne,onClose:()=>{ye(!1),de(void 0)},onSuccess:()=>{f.invalidateQueries({queryKey:["custom-endpoints"]})}}),e.jsx(Es,{open:Ce,provider:$e,options:he,preservedExtras:Ge,usePreset:Ee,onPresetChange:Ae,onConfirm:zt,onClose:nt}),e.jsx(Rs,{dialog:Le,currentRoutes:Le?G[Le.endpoint]||[]:[],onConfirm:(t,n)=>{Ie(null),$t(t,n)},onClose:()=>Ie(null)}),e.jsx(hs,{open:!!N,onOpenChange:t=>{!t&&!Fe&&pe(null)},title:ts,description:ss,confirmLabel:s(Fe?"common.actions.loading":"common.delete"),cancelLabel:s("common.actions.cancel"),loading:Fe,onConfirm:Ht,children:dt?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:dt}):null})]})}function pt({eyebrow:s,title:l,description:f,breadcrumb:h,aside:p}){return e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx("span",{children:s}),h.map((j,r)=>e.jsxs(ns.Fragment,{children:[r>0?e.jsx(ht,{className:"h-3.5 w-3.5"}):null,e.jsx("span",{className:Z(r===h.length-1&&"text-foreground"),children:j})]},`${j}-${r}`))]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-[-0.03em] text-foreground",children:l}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm text-muted-foreground",children:f})]})]}),p?e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:p}):null]})}function Es({open:s,provider:l,options:f,usePreset:h,preservedExtras:p,onPresetChange:j,onConfirm:r,onClose:i}){const{t:w}=me();return l?e.jsx(ft,{open:s,onOpenChange:S=>!S&&i(),children:e.jsxs(bt,{children:[e.jsxs(vt,{children:[e.jsx(jt,{children:w("providers.testDialog.title")}),e.jsx(yt,{children:w("providers.testDialog.subtitle",{name:l.label||l.id})})]}),e.jsxs("div",{className:"min-h-0 space-y-4 overflow-y-auto",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:w("providers.testDialog.description")}),e.jsxs("div",{className:"flex items-start gap-3 rounded-[1.2rem] border border-border/70 bg-background/45 p-4",children:[e.jsx("input",{type:"checkbox",className:"mt-1 h-4 w-4 rounded border",checked:h,onChange:S=>j(S.target.checked)}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{children:w("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:w("providers.testDialog.presetDescription")}),e.jsxs("details",{className:"rounded-[1rem] border border-border/70 bg-background/70 p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:w("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:f.map(S=>e.jsxs("code",{className:"block rounded-xl border border-border/70 bg-background/85 px-2 py-1 text-xs",children:[S.key,": ",S.value]},S.key))})]})]})]}),Object.keys(p).length>0&&e.jsxs("div",{className:"rounded-[1.15rem] border border-border/70 bg-background/70 p-4 text-xs space-y-2",children:[e.jsx("p",{className:"font-medium",children:w("providers.testDialog.preservedInfo")}),Object.entries(p).map(([S,I])=>e.jsxs("code",{className:"block rounded-xl border border-border/70 bg-background/85 px-2 py-1",children:[S,": ",I]},S))]})]}),e.jsxs(Nt,{children:[e.jsx(P,{variant:"outline",onClick:i,children:w("providers.testDialog.cancel")}),e.jsx(P,{onClick:()=>void r(),children:w("providers.testDialog.primary")})]})]})}):null}function Ss({value:s,onChange:l,options:f,disabled:h,placeholder:p}){const{t:j}=me(),[r,i]=x.useState(!1),[w,S]=x.useState(""),I=x.useRef(null),U=x.useMemo(()=>{if(!w.trim())return f;const C=w.toLowerCase();return f.filter(k=>k.label.toLowerCase().includes(C)||k.value.toLowerCase().includes(C))},[f,w]),g=C=>{l(C),S(""),i(!1)};return e.jsxs(gs,{open:r,onOpenChange:C=>{i(C),C&&S("")},children:[e.jsx(fs,{asChild:!0,children:e.jsx(re,{ref:I,value:s,onChange:C=>{l(C.target.value),S(C.target.value),r||i(!0)},onFocus:()=>{S(""),i(!0)},onClick:()=>{r||i(!0)},placeholder:p,disabled:h,autoComplete:"off"})}),e.jsx(bs,{className:"w-[var(--radix-popover-trigger-width)] max-h-60 overflow-y-auto p-1",align:"start",onOpenAutoFocus:C=>C.preventDefault(),children:U.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:j("common.noMatches")}):U.map(C=>e.jsx("button",{type:"button",className:Z("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",C.value===s.trim()&&"bg-accent"),onMouseDown:k=>{k.preventDefault(),g(C.value)},children:e.jsx("span",{className:"truncate",children:C.label})},C.value))})]})}function Rs({dialog:s,currentRoutes:l,onConfirm:f,onClose:h}){const{t:p}=me();if(!s)return null;const{endpoint:j,preset:r}=s,i=r.modelRoutes??{},w={};for(const k of l){const v=k.source.trim(),E=k.target.trim();v&&E&&(w[v]=E)}const S=new Set([...Object.keys(w),...Object.keys(i)]),I=[],U=[],g=[];for(const k of S){const v=k in w,E=k in i;E&&!v?I.push([k,i[k]]):v&&!E?U.push([k,w[k]]):v&&E&&w[k]!==i[k]&&g.push([k,w[k],i[k]])}const C=I.length>0||U.length>0||g.length>0;return e.jsx(ft,{open:!0,onOpenChange:k=>!k&&h(),children:e.jsxs(bt,{className:"max-w-lg",children:[e.jsxs(vt,{children:[e.jsx(jt,{children:p("modelManagement.presets.diffTitle")}),e.jsx(yt,{children:p("modelManagement.presets.diffDescription",{name:r.name})})]}),C?e.jsxs("div",{className:"max-h-72 overflow-y-auto space-y-2 text-sm",children:[I.map(([k,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-emerald-50 dark:bg-emerald-950 text-emerald-800 dark:text-emerald-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-emerald-300 dark:border-emerald-700",children:p("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`add-${k}`)),U.map(([k,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-red-50 dark:bg-red-950 text-red-800 dark:text-red-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-red-300 dark:border-red-700",children:p("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`rm-${k}`)),g.map(([k,v,E])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl px-2 py-1.5 bg-amber-50 dark:bg-amber-950 text-amber-800 dark:text-amber-200",children:[e.jsx(F,{variant:"outline",className:"text-xs border-amber-300 dark:border-amber-700",children:p("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:k}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:v}),e.jsx(ce,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:E})]},`chg-${k}`))]}):e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:p("modelManagement.presets.diffEmpty")}),e.jsxs(Nt,{children:[e.jsx(P,{variant:"outline",onClick:h,children:p("common.cancel")}),e.jsx(P,{onClick:()=>f(j,r),disabled:!C,children:p("modelManagement.presets.diffConfirm")})]})]})})}function xt(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function Ds({type:s}){const l={openai:{label:"OpenAI",variant:"success"},deepseek:{label:"DeepSeek",variant:"info"},huawei:{label:"华为云",variant:"warning"},kimi:{label:"Kimi",variant:"purple"},anthropic:{label:"Anthropic",variant:"pink"},custom:{label:"Custom",variant:"secondary"}},{label:f,variant:h}=l[s]||l.custom;return e.jsx(F,{variant:h,className:"text-xs",children:f})}function Ps({open:s,endpoint:l,onClose:f,onSuccess:h}){const{t:p}=me(),{pushToast:j}=gt(),[r,i]=x.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});x.useEffect(()=>{if(l){let v;l.paths&&l.paths.length>0?v=l.paths:l.path&&l.protocol?v=[{path:l.path,protocol:l.protocol}]:v=[{path:"",protocol:"openai-auto"}],i({id:l.id,label:l.label,paths:v,enabled:l.enabled!==!1})}else i({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[l,s]);const w=lt({mutationFn:ve.create,onSuccess:()=>{j({title:p("modelManagement.createEndpointSuccess"),variant:"success"}),h(),f()},onError:v=>{const E=Te(v);j({title:p("modelManagement.createEndpointError",{error:E.message}),variant:"error"})}}),S=lt({mutationFn:v=>ve.update(v.id,v.updates),onSuccess:()=>{j({title:p("modelManagement.updateEndpointSuccess"),variant:"success"}),h(),f()},onError:v=>{const E=Te(v);j({title:p("modelManagement.updateEndpointError",{error:E.message}),variant:"error"})}}),I=()=>{i({...r,paths:[...r.paths,{path:"",protocol:"anthropic"}]})},U=v=>{if(r.paths.length===1){j({title:p("modelManagement.atLeastOnePath"),variant:"error"});return}const E=r.paths.filter(($,L)=>L!==v);i({...r,paths:E})},g=(v,E,$)=>{const L=[...r.paths];L[v]={...L[v],[E]:$},i({...r,paths:L})},C=v=>{if(v.preventDefault(),!r.id.trim()||!r.label.trim()){j({title:p("modelManagement.endpointValidationError"),variant:"error"});return}for(const $ of r.paths)if(!$.path.trim()){j({title:p("modelManagement.pathValidationError"),variant:"error"});return}const E=r.paths.map($=>({path:$.path.trim(),protocol:$.protocol}));l?S.mutate({id:l.id,updates:{label:r.label.trim(),paths:E,enabled:r.enabled}}):w.mutate({id:r.id.trim(),label:r.label.trim(),paths:E,enabled:r.enabled})},k=w.isPending||S.isPending;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-slate-950/45 backdrop-blur-sm",onClick:f}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-white/50 bg-background/96 shadow-[0_24px_80px_-32px_rgba(15,23,42,0.4)] backdrop-blur-xl",children:e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/70 bg-background/70 p-6",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:p(l?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx(P,{variant:"ghost",size:"sm",onClick:f,children:e.jsx(_e,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:C,className:"flex-1 overflow-y-auto p-6 space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Q,{children:[p("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{value:r.id,onChange:v=>i({...r,id:v.target.value}),placeholder:p("modelManagement.endpointIdPlaceholder"),disabled:!!l,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Q,{children:[p("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(re,{value:r.label,onChange:v=>i({...r,label:v.target.value}),placeholder:p("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Q,{children:[p("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(P,{type:"button",variant:"ghost",size:"sm",onClick:I,children:[e.jsx(Ve,{className:"mr-1 h-3 w-3"}),p("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:r.paths.map((v,E)=>e.jsxs("div",{className:"rounded-[1.15rem] border border-white/50 bg-card/88 p-3 space-y-2 shadow-[0_1px_2px_rgba(15,23,42,0.03)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(re,{value:v.path,onChange:$=>g(E,"path",$.target.value),placeholder:p("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(kt,{value:v.protocol,onValueChange:$=>g(E,"protocol",$),children:[e.jsx(Mt,{children:e.jsx(Ct,{})}),e.jsxs(Et,{children:[e.jsx(W,{value:"anthropic",children:p("modelManagement.protocolAnthropic")}),e.jsx(W,{value:"openai-auto",children:p("modelManagement.protocolOpenAI")})]})]})]}),r.paths.length>1&&e.jsx(P,{type:"button",variant:"ghost",size:"sm",onClick:()=>U(E),className:"text-destructive",children:e.jsx(_e,{className:"h-4 w-4"})})]}),E===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:p("modelManagement.endpointPathHint")})]},E))})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(wt,{id:"enabled",checked:r.enabled,onCheckedChange:v=>i({...r,enabled:v})}),e.jsx(Q,{htmlFor:"enabled",children:p("modelManagement.endpointEnabled")})]}),!l&&e.jsx("div",{className:"rounded-[1.2rem] border border-blue-200 bg-blue-50/75 p-4 dark:border-blue-800 dark:bg-blue-950",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:p("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border/70 bg-background/70 p-6",children:[e.jsx(P,{variant:"outline",className:"flex-1",onClick:f,disabled:k,children:p("common.cancel")}),e.jsx(P,{className:"flex-1",onClick:C,disabled:k,children:p(k?"common.saving":l?"common.save":"common.create")})]})]})})]}):null}export{Qs as default};
@@ -1 +0,0 @@
1
- import{f as r,L as b}from"./vendor-C92xTG6Z.js";import{c as l}from"./index-zyFaDjL5.js";const c=b("inline-flex items-center rounded-full border px-2.5 py-1 text-[11px] font-semibold tracking-[0.02em] transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-primary/15 bg-primary/10 text-primary hover:bg-primary/15 dark:border-primary/25 dark:bg-primary/15 dark:text-primary-foreground",secondary:"border-border/70 bg-secondary/90 text-secondary-foreground hover:bg-secondary dark:border-border dark:bg-secondary/70 dark:text-secondary-foreground",destructive:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 dark:border-red-900 dark:bg-red-950/60 dark:text-red-300",outline:"border-border bg-transparent text-muted-foreground hover:bg-accent dark:border-border dark:text-muted-foreground dark:hover:bg-accent",success:"border-emerald-200 bg-emerald-50 text-emerald-700 hover:bg-emerald-100 dark:border-emerald-900 dark:bg-emerald-950/60 dark:text-emerald-300",warning:"border-amber-200 bg-amber-50 text-amber-700 hover:bg-amber-100 dark:border-amber-900 dark:bg-amber-950/60 dark:text-amber-300",info:"border-cyan-200 bg-cyan-50 text-cyan-700 hover:bg-cyan-100 dark:border-cyan-900 dark:bg-cyan-950/60 dark:text-cyan-300",purple:"border-violet-200 bg-violet-50 text-violet-700 hover:bg-violet-100 dark:border-violet-900 dark:bg-violet-950/60 dark:text-violet-300",pink:"border-pink-200 bg-pink-50 text-pink-700 hover:bg-pink-100 dark:border-pink-900 dark:bg-pink-950/60 dark:text-pink-300"}},defaultVariants:{variant:"default"}});function m({className:e,variant:n,...a}){return r.jsx("div",{className:l(c({variant:n}),e),...a})}function f({icon:e,title:n,description:a,badge:o,eyebrow:d,breadcrumb:t,helper:s,actions:i,className:x}){return r.jsxs("div",{className:l("flex flex-col gap-5 rounded-[1.6rem] border border-white/50 bg-[linear-gradient(135deg,rgba(255,255,255,0.72),rgba(248,250,252,0.88))] p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)] backdrop-blur sm:flex-row sm:items-start sm:justify-between",x),children:[r.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-4",children:[e&&r.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-2xl bg-primary/10 text-primary shadow-[inset_0_0_0_1px_rgba(59,130,246,0.08)]",children:e}),r.jsxs("div",{className:"min-w-0 space-y-2",children:[(d||t)&&r.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[d?r.jsx("span",{children:d}):null,d&&t?r.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/50"}):null,t?r.jsx("span",{className:"text-muted-foreground/90",children:t}):null]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[r.jsx("h1",{className:"text-2xl font-semibold tracking-[-0.02em]",children:n}),o&&r.jsx(m,{variant:"secondary",children:o})]}),a&&r.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:a}),s&&r.jsx("div",{className:"rounded-2xl border border-border/70 bg-background/70 px-3.5 py-2 text-xs text-muted-foreground",children:s})]})]}),i&&r.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2 self-start",children:i})]})}export{m as B,f as P};
@@ -1 +0,0 @@
1
- import{f as e}from"./vendor-C92xTG6Z.js";import{c as m}from"./index-zyFaDjL5.js";import{C as o,b as x,c as f,d as i,a as p}from"./card-DKAxXuqe.js";function b({title:a,description:s,eyebrow:d,actions:r,className:c,contentClassName:l,children:n}){const t=a||s||r;return e.jsxs(o,{className:m("surface-1 overflow-hidden",c),children:[t&&e.jsxs(x,{className:"flex flex-col gap-4 border-b border-border/60 bg-background/35 sm:flex-row sm:items-start sm:justify-between sm:space-y-0",children:[e.jsxs("div",{className:"space-y-1.5",children:[d?e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:d}):null,typeof a=="string"?e.jsx(f,{className:"text-base font-semibold",children:a}):a,s&&(typeof s=="string"?e.jsx(i,{children:s}):e.jsx("div",{className:"text-sm text-muted-foreground",children:s}))]}),r&&e.jsx("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:r})]}),e.jsx(p,{className:m(!t&&"pt-6",t&&"pt-5",l),children:n})]})}export{b as P};