@chenpu17/cc-gw 0.8.28 → 0.8.29

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 (23) hide show
  1. package/package.json +5 -5
  2. package/src/web/dist/assets/{About-BKiMaHb0.js → About-Cm8SdgXs.js} +1 -1
  3. package/src/web/dist/assets/{ApiKeys-BTcIIgmL.js → ApiKeys-Buc2uXF3.js} +1 -1
  4. package/src/web/dist/assets/{ConfirmDialog-BKK6xsPe.js → ConfirmDialog-BYuZwgWC.js} +1 -1
  5. package/src/web/dist/assets/{Dashboard-B3kEUYKY.js → Dashboard-DShNHNh0.js} +1 -1
  6. package/src/web/dist/assets/{Events-BH7AnRJM.js → Events-TZCjFq06.js} +1 -1
  7. package/src/web/dist/assets/{Help-BvQpcGeD.js → Help-Bwzt4gRi.js} +1 -1
  8. package/src/web/dist/assets/{Login-B44jDA1h.js → Login-DTIGK-8_.js} +1 -1
  9. package/src/web/dist/assets/{Logs-CtJDEq1D.js → Logs-CTGZCZ3d.js} +1 -1
  10. package/src/web/dist/assets/{ModelManagement-DuQUQprh.js → ModelManagement-Bu4yl0en.js} +1 -1
  11. package/src/web/dist/assets/{Profiler-aNY5CbJF.js → Profiler-B-Lg2yQp.js} +1 -1
  12. package/src/web/dist/assets/{RoutingManagement-BU_t7qZ5.js → RoutingManagement-RFMTV2o6.js} +1 -1
  13. package/src/web/dist/assets/{Settings-DYNFf-x2.js → Settings-iT-oQVjg.js} +1 -1
  14. package/src/web/dist/assets/{app-D2luR0w8.js → app-CUHICvDo.js} +2 -2
  15. package/src/web/dist/assets/{gateway-0dI95Pk4.js → gateway-DhxavTUf.js} +1 -1
  16. package/src/web/dist/assets/{landing-CF3whjCU.js → landing-aXQw-el0.js} +1 -1
  17. package/src/web/dist/assets/package-BcqrltRw.js +1 -0
  18. package/src/web/dist/assets/{useApiQuery-B4UkNdxl.js → useApiQuery-DhdisbOK.js} +1 -1
  19. package/src/web/dist/assets/{useAppMutation-CT0ETbRx.js → useAppMutation-CJrALOdE.js} +1 -1
  20. package/src/web/dist/assets/{useModelManagementState-CO7s8w5p.js → useModelManagementState-DFFjS9uq.js} +1 -1
  21. package/src/web/dist/index.html +1 -1
  22. package/src/web/dist/landing.html +2 -2
  23. package/src/web/dist/assets/package-DglEFv2B.js +0 -1
@@ -1 +1 @@
1
- import{r as p,j as e,o as Ze,ay as Ye,al as et,a7 as tt,am as st,az as _e,ax as lt,U as at,P as rt}from"./vendor-DdPBfMMb.js";import{P as ot}from"./PageToolbar-DATSQ0uI.js";import{c as C}from"./global-DA-0y145.js";import{B as L,b as nt,u as fe,s as R,t as it,a as K}from"./app-D2luR0w8.js";import{B as A,q as V}from"./queryKeys-DLyolp-A.js";import{C as Le,a as Re}from"./card-DPI7HeM2.js";import{I as xe}from"./input-CRm3Lt3O.js";import{L as H}from"./label-D0KXM_V7.js";import{S as se,a as le,b as ae,c as re,d as M}from"./select-C4IDwhTu.js";import{u as P}from"./i18n-C8tBby0x.js";import{D as dt,A as ct,a as ut,b as mt,c as pt,d as xt}from"./DialogShell-C0YGDw-Y.js";import{P as gt,a as oe}from"./PageState-B8pYAtQ5.js";import{c as ft}from"./clipboard-BnAnBk_-.js";import{u as G}from"./useApiQuery-B4UkNdxl.js";import{a as ht,g as De,b as yt,f as Q,c as Fe,d as bt,e as I,h as jt}from"./utils-DNPbJsD2.js";import{P as vt,a as wt,b as Nt}from"./popover-DVsRdElU.js";import{L as kt}from"./router-D2Fb4U0L.js";import{T as St}from"./Skeleton-9Z0ltPLO.js";import{u as Ct}from"./query-QCek5MsK.js";import{g as Ce}from"./gateway-0dI95Pk4.js";import"./radix-C0Bt6n-I.js";function Et({apiKeys:l,selected:t,onChange:i,disabled:a,className:d}){const{t:s}=P(),[r,b]=p.useState(!1),[k,u]=p.useState(null),v=p.useRef(null),h=p.useRef(null),x=p.useRef(null),m=()=>{const f=h.current;if(!f)return;const j=f.getBoundingClientRect(),y=Math.max(j.width,256),w=window.innerWidth-12;u({left:Math.min(j.left,w-y),top:j.bottom+8,width:y})};p.useEffect(()=>{if(!r)return;const f=j=>{var w,S;const y=j.target;!((w=v.current)!=null&&w.contains(y))&&!((S=x.current)!=null&&S.contains(y))&&b(!1)};return window.addEventListener("mousedown",f),()=>window.removeEventListener("mousedown",f)},[r]),p.useEffect(()=>{if(r)return m(),window.addEventListener("resize",m),window.addEventListener("scroll",m,!0),()=>{window.removeEventListener("resize",m),window.removeEventListener("scroll",m,!0)}},[r]);const g=p.useMemo(()=>{if(t.length===0)return[];const f=new Map;for(const j of l)f.set(j.id,j);return t.map(j=>{const y=f.get(j);return y?y.isWildcard?s("apiKeys.wildcard"):y.name:null}).filter(j=>!!j)},[l,t,s]),o=t.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:t.length}),n=f=>{t.includes(f)?i(t.filter(j=>j!==f)):i([...t,f])};return e.jsxs("div",{className:C("relative space-y-2",d),ref:v,children:[e.jsx(H,{children:s("logs.filters.apiKey")}),e.jsxs("button",{ref:h,type:"button",onClick:()=>{m(),b(f=>!f)},disabled:a||l.length===0,title:s("logs.filters.apiKeyHint"),className:C("flex h-10 w-full items-center justify-between rounded-lg border border-input bg-background px-3 text-sm ring-offset-background transition-all focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t.length>0&&"border-primary",r&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[o,g.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:g.join(", ")})]}),e.jsx("svg",{className:C("h-4 w-4 opacity-50 transition-transform",r&&"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"})})]}),r&&k&&Ze.createPortal(e.jsxs("div",{ref:x,className:"fixed z-50 rounded-lg border bg-popover p-2 shadow-[var(--surface-shadow-lg)]",style:k,children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg bg-secondary px-3 py-2 text-xs",children:[e.jsx("span",{children:o}),e.jsx("button",{type:"button",onClick:()=>i([]),disabled:t.length===0,className:"text-primary hover:underline disabled:opacity-40",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[l.map(f=>{const j=f.isWildcard?s("apiKeys.wildcard"):f.name,y=t.includes(f.id);return e.jsxs("label",{className:C("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",y&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:y,onChange:()=>n(f.id)}),e.jsx("span",{className:"truncate",children:j})]},f.id)}),l.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:s("logs.filters.apiKeyAll")})]})]}),document.body)]})}function _t(l){const{t}=P(),{total:i,activeFilters:a,filtersExpanded:d,setFiltersExpanded:s,handleResetFilters:r,activeQuickView:b,applyQuickView:k,providerFilter:u,setProviderFilter:v,endpointFilter:h,setEndpointFilter:x,selectedApiKeys:m,setSelectedApiKeys:g,modelFilter:o,setModelFilter:n,statusFilter:f,setStatusFilter:j,fromDate:y,setFromDate:w,toDate:S,setToDate:T,providerOptions:_,apiKeys:O,apiKeysLoading:$,customEndpoints:X}=l;return e.jsx(Le,{"data-testid":"logs-filters-card",className:"overflow-hidden rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsxs(Re,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3",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:t("logs.filtersTitle")}),e.jsx(A,{variant:"secondary",className:"rounded-full px-2.5 py-0.5 text-[11px] font-semibold",children:t("logs.summary.total",{value:i.toLocaleString()})}),a.length>0&&e.jsx(A,{variant:"outline",className:"rounded-full border-transparent bg-primary/10 px-2.5 py-0.5 text-[11px] font-semibold text-primary",children:t("common.filters.activeCount",{count:a.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[a.length>0&&e.jsx(L,{variant:"ghost",size:"sm",onClick:r,className:"h-8 rounded-full px-3 text-xs",children:t("common.actions.reset")}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>s(N=>!N),className:"h-8 rounded-full px-3 text-xs",children:d?e.jsxs(e.Fragment,{children:[t("common.filters.collapse"),e.jsx(Ye,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[t("common.filters.expand"),e.jsx(et,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsxs("div",{className:"grid gap-2 lg:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"flex min-h-10 items-center rounded-[0.9rem] bg-secondary/70 px-3 py-2",children:a.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:a.map(N=>e.jsxs(A,{variant:"outline",role:"button",tabIndex:0,className:"flex cursor-pointer items-center gap-1 rounded-full border border-border bg-card/90 px-2.5 py-1 text-[11px] font-semibold text-foreground/90 transition hover:bg-secondary/80",onClick:N.onRemove,onKeyDown:Z=>{(Z.key==="Enter"||Z.key===" ")&&(Z.preventDefault(),N.onRemove())},children:[N.label,e.jsx(tt,{className:"h-3 w-3","aria-hidden":"true"})]},N.key))}):e.jsx("span",{className:"text-xs text-muted-foreground",children:t("common.filters.allRequests")})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 lg:justify-end",children:[e.jsx(ge,{label:t("logs.filters.apiKey"),value:m.length.toString()}),e.jsx(ge,{label:t("logs.filters.provider"),value:u==="all"?"0":"1"}),e.jsx(ge,{label:t("logs.filters.endpoint"),value:h==="all"?"0":"1"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 rounded-[0.9rem] bg-secondary/70 px-2 py-1.5",children:["all","errors","today","anthropic","openai"].map(N=>e.jsx(L,{variant:"ghost",size:"sm",className:C("h-7 rounded-full px-3 text-[11px] font-semibold transition-colors",b===N?"bg-card text-foreground shadow-[0_12px_28px_-24px_rgba(15,23,42,0.32)]":"text-muted-foreground"),onClick:()=>k(N),children:t(`logs.quickViews.${N}`)},N))})]}),d&&e.jsxs("div",{className:"mt-3 grid gap-3 rounded-[1rem] bg-secondary/45 p-3 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(H,{children:t("logs.filters.provider")}),e.jsxs(se,{value:u,onValueChange:v,children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(M,{value:"all",children:t("logs.filters.providerAll")}),_.map(N=>e.jsx(M,{value:N.id,children:N.label??N.id},N.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:t("logs.filters.endpoint")}),e.jsxs(se,{value:h,onValueChange:x,children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(M,{value:"all",children:t("logs.filters.endpointAll")}),e.jsx(M,{value:"anthropic",children:t("logs.filters.endpointAnthropic")}),e.jsx(M,{value:"openai",children:t("logs.filters.endpointOpenAI")}),X==null?void 0:X.map(N=>e.jsx(M,{value:N.id,children:N.label||N.id},N.id))]})]})]}),e.jsx(Et,{className:"md:col-span-2",apiKeys:O,selected:m,disabled:$,onChange:g}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:t("logs.filters.modelId")}),e.jsx(xe,{value:o,onChange:N=>n(N.target.value),placeholder:t("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:t("logs.filters.status")}),e.jsxs(se,{value:f,onValueChange:N=>j(N),children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(M,{value:"all",children:t("logs.filters.statusAll")}),e.jsx(M,{value:"success",children:t("logs.filters.statusSuccess")}),e.jsx(M,{value:"error",children:t("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:t("logs.filters.startDate")}),e.jsx(xe,{type:"date",value:y,onChange:N=>w(N.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:t("logs.filters.endDate")}),e.jsx(xe,{type:"date",value:S,onChange:N=>T(N.target.value)})]})]})]})})}function ge({label:l,value:t}){return e.jsxs("div",{className:"inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-card/92 px-2.5 py-1 text-[11px] text-muted-foreground shadow-[0_10px_24px_-22px_rgba(15,23,42,0.28)]",children:[e.jsx("span",{children:l}),e.jsx("span",{className:"metric-number font-semibold text-foreground",children:t})]})}const he={listRequest(l){return{url:"/api/logs",method:"GET",params:l}},detailRequest(l){return{url:l===null?"":`/api/logs/${l}`,method:"GET"}},async exportArchive(l,t){const i=await nt.post("/api/logs/export",l,{responseType:"blob",timeout:t});return new Blob([i.data],{type:"application/zip"})}};function Lt({apiKeyMap:l,logId:t,open:i,providerLabelMap:a}){var g;const{t:d}=P(),{pushToast:s}=fe(),r=G(V.logs.detail(t),he.detailRequest(t),{enabled:i&&t!==null,staleTime:3e4,gcTime:15e3,placeholderData:void 0});p.useEffect(()=>{!r.isError||!r.error||s({title:d("logs.detail.loadError"),description:r.error.message,variant:"error"})},[r.error,r.isError,s,d]);const b=p.useCallback(async(o,n,f)=>{if(!n){s({title:d("logs.detail.copy.empty",{label:o}),variant:"info"});return}try{await ft(n),s({title:d(f),variant:"success"})}catch(j){s({title:d("logs.detail.copy.failure"),description:j instanceof Error?j.message:d("logs.detail.copy.failureFallback"),variant:"error"})}},[s,d]),k=p.useCallback((o,n)=>{if(!n){s({title:d("logs.detail.copy.empty",{label:o}),variant:"info"});return}const f=new Blob([n],{type:"application/json;charset=utf-8"}),j=URL.createObjectURL(f),y=document.createElement("a"),w=new Date().toISOString().replace(/[:.]/g,"-"),S=o.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/gi,"-").replace(/^-+|-+$/g,"")||"payload";y.href=j,y.download=`cc-gw-log-${t??"payload"}-${S}-${w}.json`,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(j)},[t,s,d]),u=r.data,v=u?a.get(u.provider)??u.provider:"",h=u&&u.api_key_id!=null?l.get(u.api_key_id):void 0,x=u?ht(u,d):null,m=u?De(u,d):null;return{apiKeyMeta:h,errorSourceMeta:x,errorMessage:r.isError?((g=r.error)==null?void 0:g.message)??null:null,handleCopy:b,handleDownloadPayload:k,isError:r.isError,isPending:r.isPending,providerLabel:v,refetch:r.refetch,record:u,statusMeta:m}}function Rt({open:l,logId:t,onClose:i,providerLabelMap:a,apiKeyMap:d}){var j,y;const{t:s}=P(),{apiKeyMeta:r,errorSourceMeta:b,errorMessage:k,handleCopy:u,handleDownloadPayload:v,isError:h,isPending:x,providerLabel:m,refetch:g,record:o,statusMeta:n}=Lt({apiKeyMap:d,logId:t,open:l,providerLabelMap:a}),f=p.useMemo(()=>{var S,T,_,O;return o?[{key:"client-request",title:s("logs.detail.payload.clientRequest"),value:((S=o.payload)==null?void 0:S.client_request)??null,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(T=o.payload)!=null&&T.upstream_request?[{key:"upstream-request",title:s("logs.detail.payload.upstreamRequest"),value:o.payload.upstream_request,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}]:[],...(_=o.payload)!=null&&_.upstream_response?[{key:"upstream-response",title:s("logs.detail.payload.upstreamResponse"),value:o.payload.upstream_response,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[],{key:"client-response",title:s("logs.detail.payload.clientResponse"),value:((O=o.payload)==null?void 0:O.client_response)??null,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}].map($=>({...$,display:yt($.value,$.emptyLabel)})):[]},[o,s]);return e.jsx(dt,{open:l,onOpenChange:w=>{w||i()},children:e.jsxs(ct,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(ut,{className:"pr-14",children:[e.jsx(mt,{children:s("logs.detail.title")}),e.jsx(pt,{children:o?s("logs.detail.id",{id:o.id}):s("logs.detail.loadError")})]}),e.jsx(xt,{className:"max-h-[78vh]",children:x?e.jsx(gt,{compact:!0,className:"min-h-[240px]",label:s("common.loading")}):h?e.jsx(oe,{compact:!0,className:"min-h-[240px]",tone:"danger",title:s("logs.detail.loadError"),description:k??s("common.unknownError"),action:e.jsx(L,{variant:"outline",onClick:()=>void g(),children:s("common.actions.refresh")})}):o?e.jsxs("div",{className:"space-y-6 text-sm",children:[e.jsxs("section",{className:"space-y-4 rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border bg-secondary p-3 text-xs",children:[e.jsx("span",{className:"font-medium",children:s("logs.detail.summary.route",{from:o.client_model??s("logs.detail.info.noRequestedModel"),to:o.model})}),e.jsx("span",{className:"text-muted-foreground",children:s("logs.detail.summary.latency",{value:Q(o.latency_ms,s("common.units.ms"))})}),o.ttft_ms!==null?e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",Q(o.ttft_ms,s("common.units.ms"))]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(A,{variant:n==null?void 0:n.variant,children:(n==null?void 0:n.label)??"-"}),e.jsx(A,{variant:"outline",children:o.stream?s("logs.stream.streaming"):s("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-5",children:[e.jsx(z,{label:s("logs.detail.info.latency"),value:Q(o.latency_ms,s("common.units.ms"))}),e.jsx(z,{label:s("logs.detail.info.ttft"),value:Q(o.ttft_ms,s("common.units.ms"))}),e.jsx(z,{label:s("logs.detail.info.tpot"),value:Q(o.tpot_ms,s("common.units.msPerToken"))}),e.jsx(z,{label:s("logs.detail.info.status"),value:(n==null?void 0:n.label)??"-"}),e.jsx(z,{label:s("logs.detail.info.errorSource"),value:(b==null?void 0:b.label)??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(F,{label:s("logs.detail.info.time"),value:Fe(o.timestamp)}),e.jsx(F,{label:s("logs.detail.info.sessionId"),value:o.session_id??"-"}),e.jsx(F,{label:s("logs.detail.info.endpoint"),value:o.endpoint||"-"}),e.jsx(F,{label:s("logs.detail.info.provider"),value:m}),e.jsx(F,{label:s("logs.detail.info.requestedModel"),value:o.client_model??s("logs.detail.info.noRequestedModel")}),e.jsx(F,{label:s("logs.detail.info.model"),value:o.model}),e.jsx(F,{label:s("logs.detail.info.stream"),value:bt(o.stream)}),e.jsx(F,{label:s("logs.detail.info.status"),value:(n==null?void 0:n.label)??"-"}),e.jsx(F,{label:s("logs.detail.info.errorSource"),value:(b==null?void 0:b.label)??"-"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(z,{label:s("logs.detail.info.inputTokens"),value:I(o.input_tokens)}),e.jsx(z,{label:s("logs.detail.info.cacheReadTokens"),value:I(o.cache_read_tokens)}),e.jsx(z,{label:s("logs.detail.info.cacheCreationTokens"),value:I(o.cache_creation_tokens)}),e.jsx(z,{label:s("logs.detail.info.outputTokens"),value:I(o.output_tokens)})]}),o.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-xl border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:o.error})]}):null]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("section",{className:"space-y-3 rounded-lg border bg-card p-4",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 sm:grid-cols-2",children:[e.jsx(F,{label:s("logs.detail.apiKey.name"),value:o.api_key_id==null&&!o.api_key_name?s("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.name)??o.api_key_name??s("logs.detail.apiKey.missing")}),e.jsx(F,{label:s("logs.detail.apiKey.identifier"),value:o.api_key_id??s("common.noData")}),e.jsx(F,{label:s("logs.detail.apiKey.masked"),value:r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??o.api_key_name??s("logs.detail.apiKey.maskedUnavailable")}),e.jsx(F,{label:s("logs.detail.apiKey.lastUsed"),value:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():s("common.noData")})]}),e.jsxs("div",{className:"rounded-lg border bg-secondary p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:o.api_key_value_available?o.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-4 rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.payload.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(j=o.payload)!=null&&j.upstream_request||(y=o.payload)!=null&&y.upstream_response?s("logs.detail.payload.helperWithUpstream"):s("logs.detail.payload.helperClientOnly")})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:f.map(w=>e.jsx(Dt,{title:w.title,display:w.display,onCopy:()=>u(w.title,w.value,w.copyToast),onDownload:()=>v(w.title,w.value),panelKey:w.key,t:s},w.key))})]})]})]}):e.jsx(oe,{compact:!0,className:"min-h-[240px]",title:s("logs.detail.loadError"),description:s("common.noData")})})]})})}function z({label:l,value:t}){return e.jsxs("div",{className:"min-w-0 rounded-lg border bg-secondary px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:l}),e.jsx("p",{className:"mt-2 break-all text-sm font-semibold leading-6",children:t})]})}function F({label:l,value:t}){return e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l}),e.jsx("dd",{className:"min-w-0 break-all whitespace-pre-wrap text-sm font-medium leading-6 text-foreground",children:t??"-"})]})}function Dt({display:l,onCopy:t,onDownload:i,panelKey:a,title:d,t:s}){return e.jsxs("div",{className:"space-y-3 rounded-lg border bg-secondary/40 p-4","data-testid":`log-payload-${a}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:d}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(L,{variant:"outline",size:"sm",onClick:t,children:[e.jsx(st,{className:"mr-2 h-3.5 w-3.5"}),s("common.actions.copy")]}),e.jsxs(L,{variant:"outline",size:"sm",onClick:i,children:[e.jsx(_e,{className:"mr-2 h-3.5 w-3.5"}),s("common.actions.download")]})]})]}),l.isTruncated?e.jsx("p",{className:"rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900 dark:border-amber-900/50 dark:bg-amber-950/30 dark:text-amber-200",children:s("logs.detail.payload.truncated",{shown:l.displayedLength.toLocaleString(),total:l.originalLength.toLocaleString()})}):null,e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre rounded-lg border bg-secondary p-3 text-xs",children:l.text})]})}const J=[20,50,100],B=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"],ne=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function Ft(){if(typeof window>"u")return B;try{const l=window.localStorage.getItem(R.logs.visibleColumns);if(!l)return B;const t=JSON.parse(l);if(!Array.isArray(t))return B;const i=t.filter(a=>ne.includes(a));return i.length>0?i:B}catch{return B}}function Tt(){return typeof window>"u"?"comfortable":window.localStorage.getItem(R.logs.density)==="compact"?"compact":"comfortable"}function Kt(){if(typeof window>"u")return J[0];const l=window.localStorage.getItem(R.logs.pageSize),t=Number(l);return J.includes(t)?t:J[0]}function Mt(){if(typeof window>"u")return[];try{const l=window.localStorage.getItem(R.logs.selectedApiKeys);if(!l)return[];const t=JSON.parse(l);return Array.isArray(t)?t.map(i=>Number(i)).filter(i=>Number.isInteger(i)&&i>0):[]}catch{return[]}}function Ee(l,t=!1){if(!l)return;const i=t?`${l}T23:59:59.999`:`${l}T00:00:00.000`,a=Date.parse(i);return Number.isFinite(a)?a:void 0}function Pt(l,t,i){return l===i&&t===i}function zt({columnOptions:l,exporting:t,onExport:i,onRefresh:a,onResetColumns:d,onSetDensity:s,onToggleColumn:r,refreshing:b,rowDensity:k,total:u,visibleColumns:v,visibleColumnSet:h}){const{t:x}=P(),m=JSON.stringify(v)===JSON.stringify(B);return e.jsxs("div",{className:"flex w-full flex-col gap-3 xl:w-auto xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"flex w-full flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center xl:w-auto xl:flex-nowrap",children:[e.jsxs("div",{className:"flex w-full items-center gap-1 overflow-x-auto rounded-full bg-secondary p-1 sm:w-auto",children:[e.jsx("button",{type:"button",onClick:()=>s("comfortable"),className:C("inline-flex h-8 flex-1 items-center justify-center whitespace-nowrap rounded-full px-3.5 text-xs font-medium transition-all sm:flex-none",k==="comfortable"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"),children:x("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>s("compact"),className:C("inline-flex h-8 flex-1 items-center justify-center whitespace-nowrap rounded-full px-3.5 text-xs font-medium transition-all sm:flex-none",k==="compact"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"),children:x("logs.table.density.compact")})]}),e.jsxs(vt,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(L,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:x("logs.actions.columns")})}),e.jsxs(Nt,{align:"end",className:"w-64 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:x("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x("logs.actions.visibleCount",{count:v.length})})]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:d,disabled:m,children:x("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(g=>{const o=h.has(g.id);return e.jsxs("label",{className:C("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-accent",o&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:o,onChange:()=>r(g.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:g.label})]},g.id)})})]})]}),e.jsxs(L,{onClick:i,disabled:t,className:"w-full sm:w-auto",children:[e.jsx(_e,{className:"mr-2 h-4 w-4"}),x(t?"logs.actions.exporting":"logs.actions.export")]})]}),e.jsxs("div",{className:"flex w-full items-center justify-between gap-3 xl:w-auto xl:justify-start",children:[e.jsx("span",{className:"text-xs text-muted-foreground sm:text-sm",children:x("logs.summary.total",{value:u.toLocaleString()})}),e.jsxs(L,{variant:"outline",size:"sm",onClick:a,disabled:b,className:"shrink-0",children:[e.jsx(lt,{className:C("mr-2 h-4 w-4",b&&"animate-spin")}),x(b?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function At({record:l,providerLabelMap:t,apiKeyMap:i,onSelect:a,isEven:d,density:s,visibleColumnSet:r}){const{t:b}=P(),k=t.get(l.provider)??l.provider,u=l.endpoint||"-",v=De(l,b),h=l.client_model??b("logs.table.requestedModelFallback"),x=l.api_key_id!=null?i.get(l.api_key_id):void 0,m=l.api_key_id==null?b("logs.table.apiKeyUnknown"):x!=null&&x.isWildcard?b("apiKeys.wildcard"):x!=null&&x.name?x.name:l.api_key_name?l.api_key_name:b("logs.table.apiKeyUnknown"),g=s==="compact"?"px-3 py-1.5":"px-3 py-2",o=d?"bg-muted/30":"bg-background",n=jt(l.session_id),f=n==null?void 0:n.rowStyle,j=n==null?void 0:n.stickyStyle,y=n?{...n.stickyStyle,...n.accentStyle}:void 0;return e.jsxs("tr",{"data-session-id":n==null?void 0:n.sessionId,"data-session-color":n==null?void 0:n.colorKey,className:C("transition-colors",n?"":d?"bg-muted/30":"",n?"":"hover:bg-muted/50"),style:f,onMouseEnter:w=>{n&&Object.assign(w.currentTarget.style,n.hoverStyle)},onMouseLeave:w=>{n&&Object.assign(w.currentTarget.style,n.rowStyle)},children:[e.jsx("td",{className:C("sticky left-0 z-10 text-xs",g,n?"":o),style:y,children:Fe(l.timestamp)}),r.has("endpoint")&&e.jsx("td",{className:C(g,"text-xs"),children:u}),r.has("provider")&&e.jsx("td",{className:C(g,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:k,children:k})}),r.has("requestedModel")&&e.jsx("td",{className:C(g,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:h,children:h})}),r.has("routedModel")&&e.jsx("td",{className:C(g,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:l.model,children:l.model})}),r.has("apiKey")&&e.jsx("td",{className:C(g,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:m,children:m})}),r.has("inputTokens")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:I(l.input_tokens)}),r.has("cacheReadTokens")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:I(l.cache_read_tokens)}),r.has("cacheCreationTokens")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:I(l.cache_creation_tokens)}),r.has("outputTokens")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:I(l.output_tokens)}),r.has("latency")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:Q(l.latency_ms,"ms")}),r.has("ttft")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:Q(l.ttft_ms,"ms")}),r.has("tpot")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:Q(l.tpot_ms,"ms/tk")}),r.has("status")&&e.jsx("td",{className:C(g,"text-center"),children:e.jsx(A,{variant:v.variant,className:"text-xs",children:v.label})}),r.has("error")&&e.jsx("td",{className:C(g,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:l.error??"",children:l.error?l.error:"-"})}),e.jsx("td",{className:C("sticky right-0 z-10 text-center",g,n?"":o),style:j,children:e.jsx(L,{variant:"outline",size:"sm",onClick:()=>a(l.id),children:b("logs.actions.detail")})})]})}function Ot(l){const{t}=P(),{tableScrollRef:i,visibleColumnSet:a,visibleColumnCount:d,logsError:s,logsPending:r,items:b,activeFiltersCount:k,handleResetFilters:u,handleRetry:v,providerLabelMap:h,apiKeyMap:x,handleOpenDetail:m,rowDensity:g,showScrollHint:o,pageSize:n,setPageSize:f,page:j,totalPages:y,setPage:w}=l;return e.jsx(Le,{className:"overflow-hidden bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(Re,{className:"p-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 bg-secondary/50 px-4 py-3 border-b border-border",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold",children:t("logs.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.actions.visibleCount",{count:d-2})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(A,{variant:"secondary",children:"Wide Table"}),e.jsx(A,{variant:"outline",className:"bg-background",children:t(g==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),o?e.jsx(A,{variant:"warning",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:i,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1480px] text-sm",children:[e.jsx("thead",{className:"border-b border-border/50 bg-secondary/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-secondary px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.time")}),a.has("endpoint")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.endpoint")}),a.has("provider")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.provider")}),a.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.requestedModel")}),a.has("routedModel")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.routedModel")}),a.has("apiKey")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.apiKey")}),a.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.inputTokens")}),a.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.cacheReadTokens")}),a.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.cacheCreationTokens")}),a.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.outputTokens")}),a.has("latency")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.latency")}),a.has("ttft")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.ttft")}),a.has("tpot")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.tpot")}),a.has("status")&&e.jsx("th",{className:"px-3 py-2.5 text-center text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.status")}),a.has("error")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-secondary px-3 py-2.5 text-center text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:r?Array.from({length:8}).map((S,T)=>e.jsx(St,{columns:d},T)):s&&b.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-6",children:e.jsx(oe,{compact:!0,tone:"danger",icon:e.jsx(at,{className:"h-5 w-5","aria-hidden":"true"}),title:t("logs.toast.listError.title"),description:s,action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:v,children:t("common.actions.refresh")}),k>0?e.jsx(L,{variant:"ghost",size:"sm",onClick:u,children:t("common.actions.reset")}):null]})})})}):b.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:e.jsx(oe,{compact:!0,tone:"primary",icon:e.jsx(rt,{className:"h-5 w-5","aria-hidden":"true"}),title:k>0?t("logs.empty.filteredTitle"):t("logs.empty.title"),description:k>0?t("logs.empty.filteredSubtitle"):t("logs.empty.subtitle"),action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[k>0?e.jsx(L,{variant:"outline",size:"sm",onClick:u,children:t("logs.empty.actions.reset")}):null,e.jsx(L,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(kt,{to:"/api-keys",children:t("logs.empty.actions.apiKeys")})})]})})})}):b.map((S,T)=>e.jsx(At,{record:S,providerLabelMap:h,apiKeyMap:x,onSelect:m,isEven:T%2===0,density:g,visibleColumnSet:a},S.id))})]})}),o&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 bg-secondary/50 p-4 border-t border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-secondary px-3 py-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.perPage")}),e.jsxs(se,{value:n.toString(),onValueChange:S=>f(Number(S)),children:[e.jsx(le,{className:"h-8 w-[80px] bg-background",children:e.jsx(ae,{})}),e.jsx(re,{children:J.map(S=>e.jsx(M,{value:S.toString(),children:S},S))})]})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-secondary px-2 py-2",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:()=>w(S=>Math.max(S-1,1)),disabled:j<=1,children:t("logs.table.pagination.previous")}),e.jsx("span",{className:"metric-number px-1 text-sm text-muted-foreground",children:t("logs.table.pagination.pageLabel",{page:y===0?0:j,total:y})}),e.jsx(L,{variant:"outline",size:"sm",onClick:()=>w(S=>y===0?S:Math.min(S+1,y)),disabled:y===0||j>=y,children:t("logs.table.pagination.next")})]})]})]})})}function qt({exportTimeoutMs:l,queryParams:t,total:i}){const{t:a}=P(),{pushToast:d}=fe(),[s,r]=p.useState(!1),b=p.useCallback(async()=>{if(!s){r(!0);try{const k=i>0?Math.min(i,5e3):1e3,u={...t,limit:k,offset:0},v=await he.exportArchive(u,l),h=new Date().toISOString().replace(/[:.]/g,"-"),x=URL.createObjectURL(v),m=document.createElement("a");m.href=x,m.download=`cc-gw-logs-${h}.zip`,document.body.appendChild(m),m.click(),m.remove(),URL.revokeObjectURL(x),d({title:a("logs.toast.exportSuccess.title"),description:a("logs.toast.exportSuccess.desc"),variant:"success"})}catch(k){const u=it(k);d({title:a("logs.toast.exportError.title"),description:a("logs.toast.exportError.desc",{message:u.message}),variant:"error"})}finally{r(!1)}}},[l,s,d,t,a,i]);return{exporting:s,handleExport:b}}function Qt(){const l=p.useRef(null),[t,i]=p.useState(!1),a=p.useCallback(()=>{const d=l.current;if(!d)return;const s=d.scrollWidth-d.scrollLeft-d.clientWidth>1;i(s)},[]);return p.useEffect(()=>{const d=l.current;if(!d)return;a(),d.addEventListener("scroll",a,{passive:!0});const s=new ResizeObserver(a);return s.observe(d),()=>{d.removeEventListener("scroll",a),s.disconnect()}},[a]),{scrollRef:l,showScrollHint:t,updateScrollHint:a}}function It(){const[l,t]=K(R.logs.density,Tt,{serialize:v=>v,deserialize:v=>v==="compact"?"compact":"comfortable"}),[i,a]=K(R.logs.visibleColumns,Ft),{scrollRef:d,showScrollHint:s}=Qt(),r=p.useMemo(()=>new Set(i),[i]),b=i.length+2,k=p.useCallback(v=>{a(h=>{if(h.includes(v))return h.length===1?h:h.filter(m=>m!==v);const x=[...h,v];return x.sort((m,g)=>ne.indexOf(m)-ne.indexOf(g)),x})},[]);return{resetVisibleColumns:p.useCallback(()=>{a(B)},[]),rowDensity:l,setRowDensity:t,showScrollHint:s,tableScrollRef:d,toggleColumn:k,visibleColumnCount:b,visibleColumns:i,visibleColumnSet:r}}function $t(){var ve,we,Ne,ke,Se;const{t:l}=P(),{pushToast:t}=fe(),i=Ct(),[a,d]=K(R.logs.providerFilter,"all"),[s,r]=K(R.logs.endpointFilter,"all"),[b,k]=K(R.logs.modelFilter,""),[u,v]=K(R.logs.statusFilter,"all"),[h,x]=K(R.logs.fromDate,""),[m,g]=K(R.logs.toDate,""),[o,n]=p.useState(1),[f,j]=K(R.logs.pageSize,Kt,{serialize:c=>String(c),deserialize:c=>{const E=Number(c);return J.includes(E)?E:J[0]}}),[y,w]=p.useState(null),[S,T]=p.useState(!1),[_,O]=K(R.logs.selectedApiKeys,Mt),[$,X]=K(R.logs.filtersExpanded,!1),{resetVisibleColumns:N,rowDensity:Z,setRowDensity:Te,showScrollHint:Ke,tableScrollRef:Me,toggleColumn:Pe,visibleColumnCount:ze,visibleColumns:Ae,visibleColumnSet:Oe}=It(),qe=p.useDeferredValue(b),D=b===""?"":qe;p.useEffect(()=>{n(1)},[a,s,D,u,h,m,f,_]);const ie=p.useMemo(()=>{const c={limit:f,offset:(o-1)*f};a!=="all"&&(c.provider=a),s!=="all"&&(c.endpoint=s),D.trim().length>0&&(c.model=D.trim()),u!=="all"&&(c.status=u);const E=Ee(h),U=Ee(m,!0);return E!==void 0&&(c.from=E),U!==void 0&&(c.to=U),_.length>0&&(c.apiKeys=_.join(",")),c},[D,s,h,o,f,a,_,u,m]),q=G(V.logs.list(ie),he.listRequest(ie),{gcTime:6e4}),W=G(V.providers.all(),Ce.providersRequest()),ye=G(V.apiKeys.all(),{url:"/api/keys",method:"GET"}),de=G(V.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),be=G(V.config.exportTimeout(),Ce.configRequest());p.useEffect(()=>{!q.isError||!q.error||t({title:l("logs.toast.listError.title"),description:l("logs.toast.listError.desc",{message:q.error.message}),variant:"error"})},[q.error,q.isError,t,l]),p.useEffect(()=>{!W.isError||!W.error||t({title:l("logs.toast.providerError.title"),description:l("logs.toast.providerError.desc",{message:W.error.message}),variant:"error"})},[W.error,W.isError,t,l]);const te=((ve=q.data)==null?void 0:ve.total)??0,Y=te>0?Math.ceil(te/f):0,Qe=((we=q.data)==null?void 0:we.items)??[],Ie=p.useMemo(()=>{var E;const c=(E=be.data)==null?void 0:E.logExportTimeoutSeconds;return typeof c=="number"&&Number.isFinite(c)?Math.min(Math.max(Math.round(c),5),600)*1e3:6e4},[(Ne=be.data)==null?void 0:Ne.logExportTimeoutSeconds]);p.useEffect(()=>{Y>0&&o>Y&&n(Y)},[o,Y]);const ce=W.data??[],ue=p.useMemo(()=>{const c=new Map;for(const E of ce)E.id&&c.set(E.id,E.label??E.id);return c},[ce]),je=p.useMemo(()=>{var E;const c=new Map;c.set("anthropic",l("logs.filters.endpointAnthropic")),c.set("openai",l("logs.filters.endpointOpenAI"));for(const U of((E=de.data)==null?void 0:E.endpoints)??[])c.set(U.id,U.label||U.id);return c},[(ke=de.data)==null?void 0:ke.endpoints,l]),$e=p.useMemo(()=>{const c=[];if(a!=="all"){const E=ue.get(a)??a;c.push({key:"provider",label:`${l("logs.filters.provider")}: ${E}`,onRemove:()=>d("all")})}if(s!=="all"){const E=je.get(s)??s;c.push({key:"endpoint",label:`${l("logs.filters.endpoint")}: ${E}`,onRemove:()=>r("all")})}if(D.trim()&&c.push({key:"model",label:`${l("logs.filters.modelId")}: ${D.trim()}`,onRemove:()=>k("")}),u!=="all"){const E=l(u==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");c.push({key:"status",label:`${l("logs.filters.status")}: ${E}`,onRemove:()=>v("all")})}return h&&c.push({key:"from",label:`${l("logs.filters.startDate")}: ${h}`,onRemove:()=>x("")}),m&&c.push({key:"to",label:`${l("logs.filters.endDate")}: ${m}`,onRemove:()=>g("")}),_.length>0&&c.push({key:"apiKeys",label:l("logs.filters.apiKeySelected",{count:_.length}),onRemove:()=>O([])}),c},[D,s,je,h,a,ue,_.length,u,l,m]),me=ye.data??[],Ue=p.useMemo(()=>{const c=new Map;for(const E of me)c.set(E.id,E);return c},[me]),Ve=p.useMemo(()=>ne.map(c=>({id:c,label:l(`logs.table.columns.${c}`)})),[l]),ee=p.useMemo(()=>new Date().toISOString().slice(0,10),[]),He=p.useMemo(()=>a==="all"&&s==="all"&&D.trim()===""&&u==="all"&&h===""&&m===""&&_.length===0?"all":u==="error"&&s==="all"&&a==="all"&&D.trim()===""&&h===""&&m===""&&_.length===0?"errors":Pt(h,m,ee)&&s==="all"&&a==="all"&&D.trim()===""&&u==="all"&&_.length===0?"today":s==="anthropic"&&a==="all"&&D.trim()===""&&u==="all"&&h===""&&m===""&&_.length===0?"anthropic":s==="openai"&&a==="all"&&D.trim()===""&&u==="all"&&h===""&&m===""&&_.length===0?"openai":null,[D,s,h,a,_.length,u,m,ee]),pe=p.useCallback(()=>{d("all"),k(""),r("all"),v("all"),x(""),g(""),O([])},[]),Be=p.useCallback(c=>{if(n(1),pe(),c!=="all"){if(c==="errors"){v("error");return}if(c==="today"){x(ee),g(ee);return}if(c==="anthropic"){r("anthropic");return}c==="openai"&&r("openai")}},[pe,ee]),{exporting:We,handleExport:Ge}=qt({exportTimeoutMs:Ie,queryParams:ie,total:te}),Je=p.useCallback(c=>{i.removeQueries({queryKey:["logs","detail"],type:"inactive"}),w(c),T(!0)},[i]),Xe=p.useCallback(()=>{T(!1)},[]);return p.useEffect(()=>{S||y===null||(i.removeQueries({queryKey:V.logs.detail(y),exact:!0}),w(null))},[S,i,y]),{activeFilters:$e,activeQuickView:He,apiKeyMap:Ue,apiKeys:me,apiKeysQuery:ye,applyQuickView:Be,columnOptions:Ve,customEndpoints:(Se=de.data)==null?void 0:Se.endpoints,endpointFilter:s,exporting:We,filtersExpanded:$,fromDate:h,handleCloseDetail:Xe,handleExport:Ge,handleOpenDetail:Je,handleResetFilters:pe,isDetailOpen:S,items:Qe,logsQuery:q,modelFilter:b,page:o,pageSize:f,providerFilter:a,providerLabelMap:ue,providerOptions:ce,rowDensity:Z,resetVisibleColumns:N,selectedApiKeys:_,selectedLogId:y,setEndpointFilter:r,setFiltersExpanded:X,setFromDate:x,setModelFilter:k,setPage:n,setPageSize:j,setProviderFilter:d,setRowDensity:Te,setSelectedApiKeys:O,setStatusFilter:v,setToDate:g,showScrollHint:Ke,statusFilter:u,tableScrollRef:Me,toDate:m,toggleColumn:Pe,total:te,totalPages:Y,visibleColumnCount:ze,visibleColumns:Ae,visibleColumnSet:Oe}}function us(){var i;const{t:l}=P(),t=$t();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(ot,{info:t.total>0?e.jsx("span",{className:"rounded-full bg-secondary px-2.5 py-1 text-xs text-muted-foreground",children:l("logs.summary.total",{value:t.total.toLocaleString()})}):null,actions:e.jsx(zt,{columnOptions:t.columnOptions,exporting:t.exporting,onExport:()=>void t.handleExport(),onRefresh:()=>void t.logsQuery.refetch(),onResetColumns:t.resetVisibleColumns,onSetDensity:t.setRowDensity,onToggleColumn:t.toggleColumn,refreshing:t.logsQuery.isFetching,rowDensity:t.rowDensity,total:t.total,visibleColumns:t.visibleColumns,visibleColumnSet:t.visibleColumnSet})}),e.jsx(_t,{total:t.total,activeFilters:t.activeFilters,filtersExpanded:t.filtersExpanded,setFiltersExpanded:t.setFiltersExpanded,handleResetFilters:t.handleResetFilters,activeQuickView:t.activeQuickView,applyQuickView:t.applyQuickView,providerFilter:t.providerFilter,setProviderFilter:t.setProviderFilter,endpointFilter:t.endpointFilter,setEndpointFilter:t.setEndpointFilter,selectedApiKeys:t.selectedApiKeys,setSelectedApiKeys:t.setSelectedApiKeys,modelFilter:t.modelFilter,setModelFilter:t.setModelFilter,statusFilter:t.statusFilter,setStatusFilter:t.setStatusFilter,fromDate:t.fromDate,setFromDate:t.setFromDate,toDate:t.toDate,setToDate:t.setToDate,providerOptions:t.providerOptions,apiKeys:t.apiKeys,apiKeysLoading:t.apiKeysQuery.isLoading,customEndpoints:t.customEndpoints}),e.jsx(Ot,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.visibleColumnSet,visibleColumnCount:t.visibleColumnCount,logsError:t.logsQuery.isError?((i=t.logsQuery.error)==null?void 0:i.message)??null:null,logsPending:t.logsQuery.isPending,items:t.items,activeFiltersCount:t.activeFilters.length,handleResetFilters:t.handleResetFilters,handleRetry:()=>void t.logsQuery.refetch(),providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap,handleOpenDetail:t.handleOpenDetail,rowDensity:t.rowDensity,showScrollHint:t.showScrollHint,pageSize:t.pageSize,setPageSize:t.setPageSize,page:t.page,totalPages:t.totalPages,setPage:t.setPage}),e.jsx(Rt,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{us as default};
1
+ import{r as p,j as e,o as Ze,ay as Ye,al as et,a7 as tt,am as st,az as _e,ax as lt,U as at,P as rt}from"./vendor-DdPBfMMb.js";import{P as ot}from"./PageToolbar-DATSQ0uI.js";import{c as C}from"./global-DA-0y145.js";import{B as L,b as nt,u as fe,s as R,t as it,a as K}from"./app-CUHICvDo.js";import{B as A,q as V}from"./queryKeys-DLyolp-A.js";import{C as Le,a as Re}from"./card-DPI7HeM2.js";import{I as xe}from"./input-CRm3Lt3O.js";import{L as H}from"./label-D0KXM_V7.js";import{S as se,a as le,b as ae,c as re,d as M}from"./select-C4IDwhTu.js";import{u as P}from"./i18n-C8tBby0x.js";import{D as dt,A as ct,a as ut,b as mt,c as pt,d as xt}from"./DialogShell-C0YGDw-Y.js";import{P as gt,a as oe}from"./PageState-B8pYAtQ5.js";import{c as ft}from"./clipboard-BnAnBk_-.js";import{u as G}from"./useApiQuery-DhdisbOK.js";import{a as ht,g as De,b as yt,f as Q,c as Fe,d as bt,e as I,h as jt}from"./utils-DNPbJsD2.js";import{P as vt,a as wt,b as Nt}from"./popover-DVsRdElU.js";import{L as kt}from"./router-D2Fb4U0L.js";import{T as St}from"./Skeleton-9Z0ltPLO.js";import{u as Ct}from"./query-QCek5MsK.js";import{g as Ce}from"./gateway-DhxavTUf.js";import"./radix-C0Bt6n-I.js";function Et({apiKeys:l,selected:t,onChange:i,disabled:a,className:d}){const{t:s}=P(),[r,b]=p.useState(!1),[k,u]=p.useState(null),v=p.useRef(null),h=p.useRef(null),x=p.useRef(null),m=()=>{const f=h.current;if(!f)return;const j=f.getBoundingClientRect(),y=Math.max(j.width,256),w=window.innerWidth-12;u({left:Math.min(j.left,w-y),top:j.bottom+8,width:y})};p.useEffect(()=>{if(!r)return;const f=j=>{var w,S;const y=j.target;!((w=v.current)!=null&&w.contains(y))&&!((S=x.current)!=null&&S.contains(y))&&b(!1)};return window.addEventListener("mousedown",f),()=>window.removeEventListener("mousedown",f)},[r]),p.useEffect(()=>{if(r)return m(),window.addEventListener("resize",m),window.addEventListener("scroll",m,!0),()=>{window.removeEventListener("resize",m),window.removeEventListener("scroll",m,!0)}},[r]);const g=p.useMemo(()=>{if(t.length===0)return[];const f=new Map;for(const j of l)f.set(j.id,j);return t.map(j=>{const y=f.get(j);return y?y.isWildcard?s("apiKeys.wildcard"):y.name:null}).filter(j=>!!j)},[l,t,s]),o=t.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:t.length}),n=f=>{t.includes(f)?i(t.filter(j=>j!==f)):i([...t,f])};return e.jsxs("div",{className:C("relative space-y-2",d),ref:v,children:[e.jsx(H,{children:s("logs.filters.apiKey")}),e.jsxs("button",{ref:h,type:"button",onClick:()=>{m(),b(f=>!f)},disabled:a||l.length===0,title:s("logs.filters.apiKeyHint"),className:C("flex h-10 w-full items-center justify-between rounded-lg border border-input bg-background px-3 text-sm ring-offset-background transition-all focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t.length>0&&"border-primary",r&&"ring-2 ring-ring ring-offset-2"),children:[e.jsxs("span",{className:"truncate",children:[o,g.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:g.join(", ")})]}),e.jsx("svg",{className:C("h-4 w-4 opacity-50 transition-transform",r&&"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"})})]}),r&&k&&Ze.createPortal(e.jsxs("div",{ref:x,className:"fixed z-50 rounded-lg border bg-popover p-2 shadow-[var(--surface-shadow-lg)]",style:k,children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg bg-secondary px-3 py-2 text-xs",children:[e.jsx("span",{children:o}),e.jsx("button",{type:"button",onClick:()=>i([]),disabled:t.length===0,className:"text-primary hover:underline disabled:opacity-40",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[l.map(f=>{const j=f.isWildcard?s("apiKeys.wildcard"):f.name,y=t.includes(f.id);return e.jsxs("label",{className:C("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",y&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:y,onChange:()=>n(f.id)}),e.jsx("span",{className:"truncate",children:j})]},f.id)}),l.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:s("logs.filters.apiKeyAll")})]})]}),document.body)]})}function _t(l){const{t}=P(),{total:i,activeFilters:a,filtersExpanded:d,setFiltersExpanded:s,handleResetFilters:r,activeQuickView:b,applyQuickView:k,providerFilter:u,setProviderFilter:v,endpointFilter:h,setEndpointFilter:x,selectedApiKeys:m,setSelectedApiKeys:g,modelFilter:o,setModelFilter:n,statusFilter:f,setStatusFilter:j,fromDate:y,setFromDate:w,toDate:S,setToDate:T,providerOptions:_,apiKeys:O,apiKeysLoading:$,customEndpoints:X}=l;return e.jsx(Le,{"data-testid":"logs-filters-card",className:"overflow-hidden rounded-[1.25rem] border border-white/70 bg-card/95 shadow-[0_20px_50px_-42px_rgba(15,23,42,0.24)]",children:e.jsxs(Re,{className:"space-y-3 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3",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:t("logs.filtersTitle")}),e.jsx(A,{variant:"secondary",className:"rounded-full px-2.5 py-0.5 text-[11px] font-semibold",children:t("logs.summary.total",{value:i.toLocaleString()})}),a.length>0&&e.jsx(A,{variant:"outline",className:"rounded-full border-transparent bg-primary/10 px-2.5 py-0.5 text-[11px] font-semibold text-primary",children:t("common.filters.activeCount",{count:a.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[a.length>0&&e.jsx(L,{variant:"ghost",size:"sm",onClick:r,className:"h-8 rounded-full px-3 text-xs",children:t("common.actions.reset")}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>s(N=>!N),className:"h-8 rounded-full px-3 text-xs",children:d?e.jsxs(e.Fragment,{children:[t("common.filters.collapse"),e.jsx(Ye,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[t("common.filters.expand"),e.jsx(et,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsxs("div",{className:"grid gap-2 lg:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"flex min-h-10 items-center rounded-[0.9rem] bg-secondary/70 px-3 py-2",children:a.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:a.map(N=>e.jsxs(A,{variant:"outline",role:"button",tabIndex:0,className:"flex cursor-pointer items-center gap-1 rounded-full border border-border bg-card/90 px-2.5 py-1 text-[11px] font-semibold text-foreground/90 transition hover:bg-secondary/80",onClick:N.onRemove,onKeyDown:Z=>{(Z.key==="Enter"||Z.key===" ")&&(Z.preventDefault(),N.onRemove())},children:[N.label,e.jsx(tt,{className:"h-3 w-3","aria-hidden":"true"})]},N.key))}):e.jsx("span",{className:"text-xs text-muted-foreground",children:t("common.filters.allRequests")})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 lg:justify-end",children:[e.jsx(ge,{label:t("logs.filters.apiKey"),value:m.length.toString()}),e.jsx(ge,{label:t("logs.filters.provider"),value:u==="all"?"0":"1"}),e.jsx(ge,{label:t("logs.filters.endpoint"),value:h==="all"?"0":"1"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 rounded-[0.9rem] bg-secondary/70 px-2 py-1.5",children:["all","errors","today","anthropic","openai"].map(N=>e.jsx(L,{variant:"ghost",size:"sm",className:C("h-7 rounded-full px-3 text-[11px] font-semibold transition-colors",b===N?"bg-card text-foreground shadow-[0_12px_28px_-24px_rgba(15,23,42,0.32)]":"text-muted-foreground"),onClick:()=>k(N),children:t(`logs.quickViews.${N}`)},N))})]}),d&&e.jsxs("div",{className:"mt-3 grid gap-3 rounded-[1rem] bg-secondary/45 p-3 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(H,{children:t("logs.filters.provider")}),e.jsxs(se,{value:u,onValueChange:v,children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(M,{value:"all",children:t("logs.filters.providerAll")}),_.map(N=>e.jsx(M,{value:N.id,children:N.label??N.id},N.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:t("logs.filters.endpoint")}),e.jsxs(se,{value:h,onValueChange:x,children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(M,{value:"all",children:t("logs.filters.endpointAll")}),e.jsx(M,{value:"anthropic",children:t("logs.filters.endpointAnthropic")}),e.jsx(M,{value:"openai",children:t("logs.filters.endpointOpenAI")}),X==null?void 0:X.map(N=>e.jsx(M,{value:N.id,children:N.label||N.id},N.id))]})]})]}),e.jsx(Et,{className:"md:col-span-2",apiKeys:O,selected:m,disabled:$,onChange:g}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:t("logs.filters.modelId")}),e.jsx(xe,{value:o,onChange:N=>n(N.target.value),placeholder:t("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:t("logs.filters.status")}),e.jsxs(se,{value:f,onValueChange:N=>j(N),children:[e.jsx(le,{children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(M,{value:"all",children:t("logs.filters.statusAll")}),e.jsx(M,{value:"success",children:t("logs.filters.statusSuccess")}),e.jsx(M,{value:"error",children:t("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:t("logs.filters.startDate")}),e.jsx(xe,{type:"date",value:y,onChange:N=>w(N.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(H,{children:t("logs.filters.endDate")}),e.jsx(xe,{type:"date",value:S,onChange:N=>T(N.target.value)})]})]})]})})}function ge({label:l,value:t}){return e.jsxs("div",{className:"inline-flex items-center gap-1.5 rounded-full border border-border/60 bg-card/92 px-2.5 py-1 text-[11px] text-muted-foreground shadow-[0_10px_24px_-22px_rgba(15,23,42,0.28)]",children:[e.jsx("span",{children:l}),e.jsx("span",{className:"metric-number font-semibold text-foreground",children:t})]})}const he={listRequest(l){return{url:"/api/logs",method:"GET",params:l}},detailRequest(l){return{url:l===null?"":`/api/logs/${l}`,method:"GET"}},async exportArchive(l,t){const i=await nt.post("/api/logs/export",l,{responseType:"blob",timeout:t});return new Blob([i.data],{type:"application/zip"})}};function Lt({apiKeyMap:l,logId:t,open:i,providerLabelMap:a}){var g;const{t:d}=P(),{pushToast:s}=fe(),r=G(V.logs.detail(t),he.detailRequest(t),{enabled:i&&t!==null,staleTime:3e4,gcTime:15e3,placeholderData:void 0});p.useEffect(()=>{!r.isError||!r.error||s({title:d("logs.detail.loadError"),description:r.error.message,variant:"error"})},[r.error,r.isError,s,d]);const b=p.useCallback(async(o,n,f)=>{if(!n){s({title:d("logs.detail.copy.empty",{label:o}),variant:"info"});return}try{await ft(n),s({title:d(f),variant:"success"})}catch(j){s({title:d("logs.detail.copy.failure"),description:j instanceof Error?j.message:d("logs.detail.copy.failureFallback"),variant:"error"})}},[s,d]),k=p.useCallback((o,n)=>{if(!n){s({title:d("logs.detail.copy.empty",{label:o}),variant:"info"});return}const f=new Blob([n],{type:"application/json;charset=utf-8"}),j=URL.createObjectURL(f),y=document.createElement("a"),w=new Date().toISOString().replace(/[:.]/g,"-"),S=o.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fa5]+/gi,"-").replace(/^-+|-+$/g,"")||"payload";y.href=j,y.download=`cc-gw-log-${t??"payload"}-${S}-${w}.json`,document.body.appendChild(y),y.click(),document.body.removeChild(y),URL.revokeObjectURL(j)},[t,s,d]),u=r.data,v=u?a.get(u.provider)??u.provider:"",h=u&&u.api_key_id!=null?l.get(u.api_key_id):void 0,x=u?ht(u,d):null,m=u?De(u,d):null;return{apiKeyMeta:h,errorSourceMeta:x,errorMessage:r.isError?((g=r.error)==null?void 0:g.message)??null:null,handleCopy:b,handleDownloadPayload:k,isError:r.isError,isPending:r.isPending,providerLabel:v,refetch:r.refetch,record:u,statusMeta:m}}function Rt({open:l,logId:t,onClose:i,providerLabelMap:a,apiKeyMap:d}){var j,y;const{t:s}=P(),{apiKeyMeta:r,errorSourceMeta:b,errorMessage:k,handleCopy:u,handleDownloadPayload:v,isError:h,isPending:x,providerLabel:m,refetch:g,record:o,statusMeta:n}=Lt({apiKeyMap:d,logId:t,open:l,providerLabelMap:a}),f=p.useMemo(()=>{var S,T,_,O;return o?[{key:"client-request",title:s("logs.detail.payload.clientRequest"),value:((S=o.payload)==null?void 0:S.client_request)??null,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(T=o.payload)!=null&&T.upstream_request?[{key:"upstream-request",title:s("logs.detail.payload.upstreamRequest"),value:o.payload.upstream_request,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}]:[],...(_=o.payload)!=null&&_.upstream_response?[{key:"upstream-response",title:s("logs.detail.payload.upstreamResponse"),value:o.payload.upstream_response,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[],{key:"client-response",title:s("logs.detail.payload.clientResponse"),value:((O=o.payload)==null?void 0:O.client_response)??null,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}].map($=>({...$,display:yt($.value,$.emptyLabel)})):[]},[o,s]);return e.jsx(dt,{open:l,onOpenChange:w=>{w||i()},children:e.jsxs(ct,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(ut,{className:"pr-14",children:[e.jsx(mt,{children:s("logs.detail.title")}),e.jsx(pt,{children:o?s("logs.detail.id",{id:o.id}):s("logs.detail.loadError")})]}),e.jsx(xt,{className:"max-h-[78vh]",children:x?e.jsx(gt,{compact:!0,className:"min-h-[240px]",label:s("common.loading")}):h?e.jsx(oe,{compact:!0,className:"min-h-[240px]",tone:"danger",title:s("logs.detail.loadError"),description:k??s("common.unknownError"),action:e.jsx(L,{variant:"outline",onClick:()=>void g(),children:s("common.actions.refresh")})}):o?e.jsxs("div",{className:"space-y-6 text-sm",children:[e.jsxs("section",{className:"space-y-4 rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.infoSection")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border bg-secondary p-3 text-xs",children:[e.jsx("span",{className:"font-medium",children:s("logs.detail.summary.route",{from:o.client_model??s("logs.detail.info.noRequestedModel"),to:o.model})}),e.jsx("span",{className:"text-muted-foreground",children:s("logs.detail.summary.latency",{value:Q(o.latency_ms,s("common.units.ms"))})}),o.ttft_ms!==null?e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",Q(o.ttft_ms,s("common.units.ms"))]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(A,{variant:n==null?void 0:n.variant,children:(n==null?void 0:n.label)??"-"}),e.jsx(A,{variant:"outline",children:o.stream?s("logs.stream.streaming"):s("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-5",children:[e.jsx(z,{label:s("logs.detail.info.latency"),value:Q(o.latency_ms,s("common.units.ms"))}),e.jsx(z,{label:s("logs.detail.info.ttft"),value:Q(o.ttft_ms,s("common.units.ms"))}),e.jsx(z,{label:s("logs.detail.info.tpot"),value:Q(o.tpot_ms,s("common.units.msPerToken"))}),e.jsx(z,{label:s("logs.detail.info.status"),value:(n==null?void 0:n.label)??"-"}),e.jsx(z,{label:s("logs.detail.info.errorSource"),value:(b==null?void 0:b.label)??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(F,{label:s("logs.detail.info.time"),value:Fe(o.timestamp)}),e.jsx(F,{label:s("logs.detail.info.sessionId"),value:o.session_id??"-"}),e.jsx(F,{label:s("logs.detail.info.endpoint"),value:o.endpoint||"-"}),e.jsx(F,{label:s("logs.detail.info.provider"),value:m}),e.jsx(F,{label:s("logs.detail.info.requestedModel"),value:o.client_model??s("logs.detail.info.noRequestedModel")}),e.jsx(F,{label:s("logs.detail.info.model"),value:o.model}),e.jsx(F,{label:s("logs.detail.info.stream"),value:bt(o.stream)}),e.jsx(F,{label:s("logs.detail.info.status"),value:(n==null?void 0:n.label)??"-"}),e.jsx(F,{label:s("logs.detail.info.errorSource"),value:(b==null?void 0:b.label)??"-"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(z,{label:s("logs.detail.info.inputTokens"),value:I(o.input_tokens)}),e.jsx(z,{label:s("logs.detail.info.cacheReadTokens"),value:I(o.cache_read_tokens)}),e.jsx(z,{label:s("logs.detail.info.cacheCreationTokens"),value:I(o.cache_creation_tokens)}),e.jsx(z,{label:s("logs.detail.info.outputTokens"),value:I(o.output_tokens)})]}),o.error?e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("logs.detail.info.error")}),e.jsx("p",{className:"rounded-xl border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:o.error})]}):null]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,0.9fr)_minmax(0,1.1fr)]",children:[e.jsxs("section",{className:"space-y-3 rounded-lg border bg-card p-4",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.apiKey.title")}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 sm:grid-cols-2",children:[e.jsx(F,{label:s("logs.detail.apiKey.name"),value:o.api_key_id==null&&!o.api_key_name?s("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.name)??o.api_key_name??s("logs.detail.apiKey.missing")}),e.jsx(F,{label:s("logs.detail.apiKey.identifier"),value:o.api_key_id??s("common.noData")}),e.jsx(F,{label:s("logs.detail.apiKey.masked"),value:r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.maskedKey)??o.api_key_name??s("logs.detail.apiKey.maskedUnavailable")}),e.jsx(F,{label:s("logs.detail.apiKey.lastUsed"),value:r!=null&&r.lastUsedAt?new Date(r.lastUsedAt).toLocaleString():s("common.noData")})]}),e.jsxs("div",{className:"rounded-lg border bg-secondary p-3 text-xs",children:[e.jsx("p",{className:"font-medium",children:s("logs.detail.apiKey.rawMasked")}),e.jsx("p",{className:"mt-1 break-all font-mono",children:o.api_key_value_available?o.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-4 rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:s("logs.detail.payload.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(j=o.payload)!=null&&j.upstream_request||(y=o.payload)!=null&&y.upstream_response?s("logs.detail.payload.helperWithUpstream"):s("logs.detail.payload.helperClientOnly")})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:f.map(w=>e.jsx(Dt,{title:w.title,display:w.display,onCopy:()=>u(w.title,w.value,w.copyToast),onDownload:()=>v(w.title,w.value),panelKey:w.key,t:s},w.key))})]})]})]}):e.jsx(oe,{compact:!0,className:"min-h-[240px]",title:s("logs.detail.loadError"),description:s("common.noData")})})]})})}function z({label:l,value:t}){return e.jsxs("div",{className:"min-w-0 rounded-lg border bg-secondary px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:l}),e.jsx("p",{className:"mt-2 break-all text-sm font-semibold leading-6",children:t})]})}function F({label:l,value:t}){return e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:l}),e.jsx("dd",{className:"min-w-0 break-all whitespace-pre-wrap text-sm font-medium leading-6 text-foreground",children:t??"-"})]})}function Dt({display:l,onCopy:t,onDownload:i,panelKey:a,title:d,t:s}){return e.jsxs("div",{className:"space-y-3 rounded-lg border bg-secondary/40 p-4","data-testid":`log-payload-${a}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:d}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(L,{variant:"outline",size:"sm",onClick:t,children:[e.jsx(st,{className:"mr-2 h-3.5 w-3.5"}),s("common.actions.copy")]}),e.jsxs(L,{variant:"outline",size:"sm",onClick:i,children:[e.jsx(_e,{className:"mr-2 h-3.5 w-3.5"}),s("common.actions.download")]})]})]}),l.isTruncated?e.jsx("p",{className:"rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900 dark:border-amber-900/50 dark:bg-amber-950/30 dark:text-amber-200",children:s("logs.detail.payload.truncated",{shown:l.displayedLength.toLocaleString(),total:l.originalLength.toLocaleString()})}):null,e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre rounded-lg border bg-secondary p-3 text-xs",children:l.text})]})}const J=[20,50,100],B=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"],ne=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function Ft(){if(typeof window>"u")return B;try{const l=window.localStorage.getItem(R.logs.visibleColumns);if(!l)return B;const t=JSON.parse(l);if(!Array.isArray(t))return B;const i=t.filter(a=>ne.includes(a));return i.length>0?i:B}catch{return B}}function Tt(){return typeof window>"u"?"comfortable":window.localStorage.getItem(R.logs.density)==="compact"?"compact":"comfortable"}function Kt(){if(typeof window>"u")return J[0];const l=window.localStorage.getItem(R.logs.pageSize),t=Number(l);return J.includes(t)?t:J[0]}function Mt(){if(typeof window>"u")return[];try{const l=window.localStorage.getItem(R.logs.selectedApiKeys);if(!l)return[];const t=JSON.parse(l);return Array.isArray(t)?t.map(i=>Number(i)).filter(i=>Number.isInteger(i)&&i>0):[]}catch{return[]}}function Ee(l,t=!1){if(!l)return;const i=t?`${l}T23:59:59.999`:`${l}T00:00:00.000`,a=Date.parse(i);return Number.isFinite(a)?a:void 0}function Pt(l,t,i){return l===i&&t===i}function zt({columnOptions:l,exporting:t,onExport:i,onRefresh:a,onResetColumns:d,onSetDensity:s,onToggleColumn:r,refreshing:b,rowDensity:k,total:u,visibleColumns:v,visibleColumnSet:h}){const{t:x}=P(),m=JSON.stringify(v)===JSON.stringify(B);return e.jsxs("div",{className:"flex w-full flex-col gap-3 xl:w-auto xl:flex-row xl:items-center",children:[e.jsxs("div",{className:"flex w-full flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center xl:w-auto xl:flex-nowrap",children:[e.jsxs("div",{className:"flex w-full items-center gap-1 overflow-x-auto rounded-full bg-secondary p-1 sm:w-auto",children:[e.jsx("button",{type:"button",onClick:()=>s("comfortable"),className:C("inline-flex h-8 flex-1 items-center justify-center whitespace-nowrap rounded-full px-3.5 text-xs font-medium transition-all sm:flex-none",k==="comfortable"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"),children:x("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>s("compact"),className:C("inline-flex h-8 flex-1 items-center justify-center whitespace-nowrap rounded-full px-3.5 text-xs font-medium transition-all sm:flex-none",k==="compact"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"),children:x("logs.table.density.compact")})]}),e.jsxs(vt,{children:[e.jsx(wt,{asChild:!0,children:e.jsx(L,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:x("logs.actions.columns")})}),e.jsxs(Nt,{align:"end",className:"w-64 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:x("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x("logs.actions.visibleCount",{count:v.length})})]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:d,disabled:m,children:x("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(g=>{const o=h.has(g.id);return e.jsxs("label",{className:C("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-accent",o&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:o,onChange:()=>r(g.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:g.label})]},g.id)})})]})]}),e.jsxs(L,{onClick:i,disabled:t,className:"w-full sm:w-auto",children:[e.jsx(_e,{className:"mr-2 h-4 w-4"}),x(t?"logs.actions.exporting":"logs.actions.export")]})]}),e.jsxs("div",{className:"flex w-full items-center justify-between gap-3 xl:w-auto xl:justify-start",children:[e.jsx("span",{className:"text-xs text-muted-foreground sm:text-sm",children:x("logs.summary.total",{value:u.toLocaleString()})}),e.jsxs(L,{variant:"outline",size:"sm",onClick:a,disabled:b,className:"shrink-0",children:[e.jsx(lt,{className:C("mr-2 h-4 w-4",b&&"animate-spin")}),x(b?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function At({record:l,providerLabelMap:t,apiKeyMap:i,onSelect:a,isEven:d,density:s,visibleColumnSet:r}){const{t:b}=P(),k=t.get(l.provider)??l.provider,u=l.endpoint||"-",v=De(l,b),h=l.client_model??b("logs.table.requestedModelFallback"),x=l.api_key_id!=null?i.get(l.api_key_id):void 0,m=l.api_key_id==null?b("logs.table.apiKeyUnknown"):x!=null&&x.isWildcard?b("apiKeys.wildcard"):x!=null&&x.name?x.name:l.api_key_name?l.api_key_name:b("logs.table.apiKeyUnknown"),g=s==="compact"?"px-3 py-1.5":"px-3 py-2",o=d?"bg-muted/30":"bg-background",n=jt(l.session_id),f=n==null?void 0:n.rowStyle,j=n==null?void 0:n.stickyStyle,y=n?{...n.stickyStyle,...n.accentStyle}:void 0;return e.jsxs("tr",{"data-session-id":n==null?void 0:n.sessionId,"data-session-color":n==null?void 0:n.colorKey,className:C("transition-colors",n?"":d?"bg-muted/30":"",n?"":"hover:bg-muted/50"),style:f,onMouseEnter:w=>{n&&Object.assign(w.currentTarget.style,n.hoverStyle)},onMouseLeave:w=>{n&&Object.assign(w.currentTarget.style,n.rowStyle)},children:[e.jsx("td",{className:C("sticky left-0 z-10 text-xs",g,n?"":o),style:y,children:Fe(l.timestamp)}),r.has("endpoint")&&e.jsx("td",{className:C(g,"text-xs"),children:u}),r.has("provider")&&e.jsx("td",{className:C(g,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:k,children:k})}),r.has("requestedModel")&&e.jsx("td",{className:C(g,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:h,children:h})}),r.has("routedModel")&&e.jsx("td",{className:C(g,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:l.model,children:l.model})}),r.has("apiKey")&&e.jsx("td",{className:C(g,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:m,children:m})}),r.has("inputTokens")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:I(l.input_tokens)}),r.has("cacheReadTokens")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:I(l.cache_read_tokens)}),r.has("cacheCreationTokens")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:I(l.cache_creation_tokens)}),r.has("outputTokens")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:I(l.output_tokens)}),r.has("latency")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:Q(l.latency_ms,"ms")}),r.has("ttft")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:Q(l.ttft_ms,"ms")}),r.has("tpot")&&e.jsx("td",{className:C(g,"text-right text-xs tabular-nums"),children:Q(l.tpot_ms,"ms/tk")}),r.has("status")&&e.jsx("td",{className:C(g,"text-center"),children:e.jsx(A,{variant:v.variant,className:"text-xs",children:v.label})}),r.has("error")&&e.jsx("td",{className:C(g,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:l.error??"",children:l.error?l.error:"-"})}),e.jsx("td",{className:C("sticky right-0 z-10 text-center",g,n?"":o),style:j,children:e.jsx(L,{variant:"outline",size:"sm",onClick:()=>a(l.id),children:b("logs.actions.detail")})})]})}function Ot(l){const{t}=P(),{tableScrollRef:i,visibleColumnSet:a,visibleColumnCount:d,logsError:s,logsPending:r,items:b,activeFiltersCount:k,handleResetFilters:u,handleRetry:v,providerLabelMap:h,apiKeyMap:x,handleOpenDetail:m,rowDensity:g,showScrollHint:o,pageSize:n,setPageSize:f,page:j,totalPages:y,setPage:w}=l;return e.jsx(Le,{className:"overflow-hidden bg-card shadow-[var(--surface-shadow)]",children:e.jsxs(Re,{className:"p-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 bg-secondary/50 px-4 py-3 border-b border-border",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-semibold",children:t("logs.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.actions.visibleCount",{count:d-2})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(A,{variant:"secondary",children:"Wide Table"}),e.jsx(A,{variant:"outline",className:"bg-background",children:t(g==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),o?e.jsx(A,{variant:"warning",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:i,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1480px] text-sm",children:[e.jsx("thead",{className:"border-b border-border/50 bg-secondary/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-secondary px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.time")}),a.has("endpoint")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.endpoint")}),a.has("provider")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.provider")}),a.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.requestedModel")}),a.has("routedModel")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.routedModel")}),a.has("apiKey")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.apiKey")}),a.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.inputTokens")}),a.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.cacheReadTokens")}),a.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.cacheCreationTokens")}),a.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.outputTokens")}),a.has("latency")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.latency")}),a.has("ttft")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.ttft")}),a.has("tpot")&&e.jsx("th",{className:"px-3 py-2.5 text-right text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.tpot")}),a.has("status")&&e.jsx("th",{className:"px-3 py-2.5 text-center text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.status")}),a.has("error")&&e.jsx("th",{className:"px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-secondary px-3 py-2.5 text-center text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y divide-border/50",children:r?Array.from({length:8}).map((S,T)=>e.jsx(St,{columns:d},T)):s&&b.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-6",children:e.jsx(oe,{compact:!0,tone:"danger",icon:e.jsx(at,{className:"h-5 w-5","aria-hidden":"true"}),title:t("logs.toast.listError.title"),description:s,action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:v,children:t("common.actions.refresh")}),k>0?e.jsx(L,{variant:"ghost",size:"sm",onClick:u,children:t("common.actions.reset")}):null]})})})}):b.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:e.jsx(oe,{compact:!0,tone:"primary",icon:e.jsx(rt,{className:"h-5 w-5","aria-hidden":"true"}),title:k>0?t("logs.empty.filteredTitle"):t("logs.empty.title"),description:k>0?t("logs.empty.filteredSubtitle"):t("logs.empty.subtitle"),action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[k>0?e.jsx(L,{variant:"outline",size:"sm",onClick:u,children:t("logs.empty.actions.reset")}):null,e.jsx(L,{asChild:!0,variant:"ghost",size:"sm",children:e.jsx(kt,{to:"/api-keys",children:t("logs.empty.actions.apiKeys")})})]})})})}):b.map((S,T)=>e.jsx(At,{record:S,providerLabelMap:h,apiKeyMap:x,onSelect:m,isEven:T%2===0,density:g,visibleColumnSet:a},S.id))})]})}),o&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 bg-secondary/50 p-4 border-t border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-secondary px-3 py-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.perPage")}),e.jsxs(se,{value:n.toString(),onValueChange:S=>f(Number(S)),children:[e.jsx(le,{className:"h-8 w-[80px] bg-background",children:e.jsx(ae,{})}),e.jsx(re,{children:J.map(S=>e.jsx(M,{value:S.toString(),children:S},S))})]})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-secondary px-2 py-2",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:()=>w(S=>Math.max(S-1,1)),disabled:j<=1,children:t("logs.table.pagination.previous")}),e.jsx("span",{className:"metric-number px-1 text-sm text-muted-foreground",children:t("logs.table.pagination.pageLabel",{page:y===0?0:j,total:y})}),e.jsx(L,{variant:"outline",size:"sm",onClick:()=>w(S=>y===0?S:Math.min(S+1,y)),disabled:y===0||j>=y,children:t("logs.table.pagination.next")})]})]})]})})}function qt({exportTimeoutMs:l,queryParams:t,total:i}){const{t:a}=P(),{pushToast:d}=fe(),[s,r]=p.useState(!1),b=p.useCallback(async()=>{if(!s){r(!0);try{const k=i>0?Math.min(i,5e3):1e3,u={...t,limit:k,offset:0},v=await he.exportArchive(u,l),h=new Date().toISOString().replace(/[:.]/g,"-"),x=URL.createObjectURL(v),m=document.createElement("a");m.href=x,m.download=`cc-gw-logs-${h}.zip`,document.body.appendChild(m),m.click(),m.remove(),URL.revokeObjectURL(x),d({title:a("logs.toast.exportSuccess.title"),description:a("logs.toast.exportSuccess.desc"),variant:"success"})}catch(k){const u=it(k);d({title:a("logs.toast.exportError.title"),description:a("logs.toast.exportError.desc",{message:u.message}),variant:"error"})}finally{r(!1)}}},[l,s,d,t,a,i]);return{exporting:s,handleExport:b}}function Qt(){const l=p.useRef(null),[t,i]=p.useState(!1),a=p.useCallback(()=>{const d=l.current;if(!d)return;const s=d.scrollWidth-d.scrollLeft-d.clientWidth>1;i(s)},[]);return p.useEffect(()=>{const d=l.current;if(!d)return;a(),d.addEventListener("scroll",a,{passive:!0});const s=new ResizeObserver(a);return s.observe(d),()=>{d.removeEventListener("scroll",a),s.disconnect()}},[a]),{scrollRef:l,showScrollHint:t,updateScrollHint:a}}function It(){const[l,t]=K(R.logs.density,Tt,{serialize:v=>v,deserialize:v=>v==="compact"?"compact":"comfortable"}),[i,a]=K(R.logs.visibleColumns,Ft),{scrollRef:d,showScrollHint:s}=Qt(),r=p.useMemo(()=>new Set(i),[i]),b=i.length+2,k=p.useCallback(v=>{a(h=>{if(h.includes(v))return h.length===1?h:h.filter(m=>m!==v);const x=[...h,v];return x.sort((m,g)=>ne.indexOf(m)-ne.indexOf(g)),x})},[]);return{resetVisibleColumns:p.useCallback(()=>{a(B)},[]),rowDensity:l,setRowDensity:t,showScrollHint:s,tableScrollRef:d,toggleColumn:k,visibleColumnCount:b,visibleColumns:i,visibleColumnSet:r}}function $t(){var ve,we,Ne,ke,Se;const{t:l}=P(),{pushToast:t}=fe(),i=Ct(),[a,d]=K(R.logs.providerFilter,"all"),[s,r]=K(R.logs.endpointFilter,"all"),[b,k]=K(R.logs.modelFilter,""),[u,v]=K(R.logs.statusFilter,"all"),[h,x]=K(R.logs.fromDate,""),[m,g]=K(R.logs.toDate,""),[o,n]=p.useState(1),[f,j]=K(R.logs.pageSize,Kt,{serialize:c=>String(c),deserialize:c=>{const E=Number(c);return J.includes(E)?E:J[0]}}),[y,w]=p.useState(null),[S,T]=p.useState(!1),[_,O]=K(R.logs.selectedApiKeys,Mt),[$,X]=K(R.logs.filtersExpanded,!1),{resetVisibleColumns:N,rowDensity:Z,setRowDensity:Te,showScrollHint:Ke,tableScrollRef:Me,toggleColumn:Pe,visibleColumnCount:ze,visibleColumns:Ae,visibleColumnSet:Oe}=It(),qe=p.useDeferredValue(b),D=b===""?"":qe;p.useEffect(()=>{n(1)},[a,s,D,u,h,m,f,_]);const ie=p.useMemo(()=>{const c={limit:f,offset:(o-1)*f};a!=="all"&&(c.provider=a),s!=="all"&&(c.endpoint=s),D.trim().length>0&&(c.model=D.trim()),u!=="all"&&(c.status=u);const E=Ee(h),U=Ee(m,!0);return E!==void 0&&(c.from=E),U!==void 0&&(c.to=U),_.length>0&&(c.apiKeys=_.join(",")),c},[D,s,h,o,f,a,_,u,m]),q=G(V.logs.list(ie),he.listRequest(ie),{gcTime:6e4}),W=G(V.providers.all(),Ce.providersRequest()),ye=G(V.apiKeys.all(),{url:"/api/keys",method:"GET"}),de=G(V.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),be=G(V.config.exportTimeout(),Ce.configRequest());p.useEffect(()=>{!q.isError||!q.error||t({title:l("logs.toast.listError.title"),description:l("logs.toast.listError.desc",{message:q.error.message}),variant:"error"})},[q.error,q.isError,t,l]),p.useEffect(()=>{!W.isError||!W.error||t({title:l("logs.toast.providerError.title"),description:l("logs.toast.providerError.desc",{message:W.error.message}),variant:"error"})},[W.error,W.isError,t,l]);const te=((ve=q.data)==null?void 0:ve.total)??0,Y=te>0?Math.ceil(te/f):0,Qe=((we=q.data)==null?void 0:we.items)??[],Ie=p.useMemo(()=>{var E;const c=(E=be.data)==null?void 0:E.logExportTimeoutSeconds;return typeof c=="number"&&Number.isFinite(c)?Math.min(Math.max(Math.round(c),5),600)*1e3:6e4},[(Ne=be.data)==null?void 0:Ne.logExportTimeoutSeconds]);p.useEffect(()=>{Y>0&&o>Y&&n(Y)},[o,Y]);const ce=W.data??[],ue=p.useMemo(()=>{const c=new Map;for(const E of ce)E.id&&c.set(E.id,E.label??E.id);return c},[ce]),je=p.useMemo(()=>{var E;const c=new Map;c.set("anthropic",l("logs.filters.endpointAnthropic")),c.set("openai",l("logs.filters.endpointOpenAI"));for(const U of((E=de.data)==null?void 0:E.endpoints)??[])c.set(U.id,U.label||U.id);return c},[(ke=de.data)==null?void 0:ke.endpoints,l]),$e=p.useMemo(()=>{const c=[];if(a!=="all"){const E=ue.get(a)??a;c.push({key:"provider",label:`${l("logs.filters.provider")}: ${E}`,onRemove:()=>d("all")})}if(s!=="all"){const E=je.get(s)??s;c.push({key:"endpoint",label:`${l("logs.filters.endpoint")}: ${E}`,onRemove:()=>r("all")})}if(D.trim()&&c.push({key:"model",label:`${l("logs.filters.modelId")}: ${D.trim()}`,onRemove:()=>k("")}),u!=="all"){const E=l(u==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");c.push({key:"status",label:`${l("logs.filters.status")}: ${E}`,onRemove:()=>v("all")})}return h&&c.push({key:"from",label:`${l("logs.filters.startDate")}: ${h}`,onRemove:()=>x("")}),m&&c.push({key:"to",label:`${l("logs.filters.endDate")}: ${m}`,onRemove:()=>g("")}),_.length>0&&c.push({key:"apiKeys",label:l("logs.filters.apiKeySelected",{count:_.length}),onRemove:()=>O([])}),c},[D,s,je,h,a,ue,_.length,u,l,m]),me=ye.data??[],Ue=p.useMemo(()=>{const c=new Map;for(const E of me)c.set(E.id,E);return c},[me]),Ve=p.useMemo(()=>ne.map(c=>({id:c,label:l(`logs.table.columns.${c}`)})),[l]),ee=p.useMemo(()=>new Date().toISOString().slice(0,10),[]),He=p.useMemo(()=>a==="all"&&s==="all"&&D.trim()===""&&u==="all"&&h===""&&m===""&&_.length===0?"all":u==="error"&&s==="all"&&a==="all"&&D.trim()===""&&h===""&&m===""&&_.length===0?"errors":Pt(h,m,ee)&&s==="all"&&a==="all"&&D.trim()===""&&u==="all"&&_.length===0?"today":s==="anthropic"&&a==="all"&&D.trim()===""&&u==="all"&&h===""&&m===""&&_.length===0?"anthropic":s==="openai"&&a==="all"&&D.trim()===""&&u==="all"&&h===""&&m===""&&_.length===0?"openai":null,[D,s,h,a,_.length,u,m,ee]),pe=p.useCallback(()=>{d("all"),k(""),r("all"),v("all"),x(""),g(""),O([])},[]),Be=p.useCallback(c=>{if(n(1),pe(),c!=="all"){if(c==="errors"){v("error");return}if(c==="today"){x(ee),g(ee);return}if(c==="anthropic"){r("anthropic");return}c==="openai"&&r("openai")}},[pe,ee]),{exporting:We,handleExport:Ge}=qt({exportTimeoutMs:Ie,queryParams:ie,total:te}),Je=p.useCallback(c=>{i.removeQueries({queryKey:["logs","detail"],type:"inactive"}),w(c),T(!0)},[i]),Xe=p.useCallback(()=>{T(!1)},[]);return p.useEffect(()=>{S||y===null||(i.removeQueries({queryKey:V.logs.detail(y),exact:!0}),w(null))},[S,i,y]),{activeFilters:$e,activeQuickView:He,apiKeyMap:Ue,apiKeys:me,apiKeysQuery:ye,applyQuickView:Be,columnOptions:Ve,customEndpoints:(Se=de.data)==null?void 0:Se.endpoints,endpointFilter:s,exporting:We,filtersExpanded:$,fromDate:h,handleCloseDetail:Xe,handleExport:Ge,handleOpenDetail:Je,handleResetFilters:pe,isDetailOpen:S,items:Qe,logsQuery:q,modelFilter:b,page:o,pageSize:f,providerFilter:a,providerLabelMap:ue,providerOptions:ce,rowDensity:Z,resetVisibleColumns:N,selectedApiKeys:_,selectedLogId:y,setEndpointFilter:r,setFiltersExpanded:X,setFromDate:x,setModelFilter:k,setPage:n,setPageSize:j,setProviderFilter:d,setRowDensity:Te,setSelectedApiKeys:O,setStatusFilter:v,setToDate:g,showScrollHint:Ke,statusFilter:u,tableScrollRef:Me,toDate:m,toggleColumn:Pe,total:te,totalPages:Y,visibleColumnCount:ze,visibleColumns:Ae,visibleColumnSet:Oe}}function us(){var i;const{t:l}=P(),t=$t();return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(ot,{info:t.total>0?e.jsx("span",{className:"rounded-full bg-secondary px-2.5 py-1 text-xs text-muted-foreground",children:l("logs.summary.total",{value:t.total.toLocaleString()})}):null,actions:e.jsx(zt,{columnOptions:t.columnOptions,exporting:t.exporting,onExport:()=>void t.handleExport(),onRefresh:()=>void t.logsQuery.refetch(),onResetColumns:t.resetVisibleColumns,onSetDensity:t.setRowDensity,onToggleColumn:t.toggleColumn,refreshing:t.logsQuery.isFetching,rowDensity:t.rowDensity,total:t.total,visibleColumns:t.visibleColumns,visibleColumnSet:t.visibleColumnSet})}),e.jsx(_t,{total:t.total,activeFilters:t.activeFilters,filtersExpanded:t.filtersExpanded,setFiltersExpanded:t.setFiltersExpanded,handleResetFilters:t.handleResetFilters,activeQuickView:t.activeQuickView,applyQuickView:t.applyQuickView,providerFilter:t.providerFilter,setProviderFilter:t.setProviderFilter,endpointFilter:t.endpointFilter,setEndpointFilter:t.setEndpointFilter,selectedApiKeys:t.selectedApiKeys,setSelectedApiKeys:t.setSelectedApiKeys,modelFilter:t.modelFilter,setModelFilter:t.setModelFilter,statusFilter:t.statusFilter,setStatusFilter:t.setStatusFilter,fromDate:t.fromDate,setFromDate:t.setFromDate,toDate:t.toDate,setToDate:t.setToDate,providerOptions:t.providerOptions,apiKeys:t.apiKeys,apiKeysLoading:t.apiKeysQuery.isLoading,customEndpoints:t.customEndpoints}),e.jsx(Ot,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.visibleColumnSet,visibleColumnCount:t.visibleColumnCount,logsError:t.logsQuery.isError?((i=t.logsQuery.error)==null?void 0:i.message)??null:null,logsPending:t.logsQuery.isPending,items:t.items,activeFiltersCount:t.activeFilters.length,handleResetFilters:t.handleResetFilters,handleRetry:()=>void t.logsQuery.refetch(),providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap,handleOpenDetail:t.handleOpenDetail,rowDensity:t.rowDensity,showScrollHint:t.showScrollHint,pageSize:t.pageSize,setPageSize:t.setPageSize,page:t.page,totalPages:t.totalPages,setPage:t.setPage}),e.jsx(Rt,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{us as default};
@@ -1 +1 @@
1
- import{j as e,aA as ye,aF as Ne,aG as we,N as ke,r as b,ac as Me}from"./vendor-DdPBfMMb.js";import{L as Se}from"./router-D2Fb4U0L.js";import{C as De}from"./ConfirmDialog-BKK6xsPe.js";import{P as Ce}from"./PageToolbar-DATSQ0uI.js";import{B as h}from"./app-D2luR0w8.js";import{D as Z,A as $,a as ee,b as re,c as se,d as ae,e as te}from"./DialogShell-C0YGDw-Y.js";import{u as U}from"./i18n-C8tBby0x.js";import{B as de}from"./queryKeys-DLyolp-A.js";import{C as le,a as ie}from"./card-DPI7HeM2.js";import{I as S}from"./input-CRm3Lt3O.js";import{L as w}from"./label-D0KXM_V7.js";import{S as oe}from"./switch-W7ZoAE3i.js";import{u as Pe}from"./useModelManagementState-CO7s8w5p.js";import{S as Te,a as Ue,b as Ae,c as _e,d as B}from"./select-C4IDwhTu.js";import{c as Ie}from"./global-DA-0y145.js";import"./query-QCek5MsK.js";import"./radix-C0Bt6n-I.js";import"./gateway-0dI95Pk4.js";import"./useAppMutation-CT0ETbRx.js";import"./useApiQuery-B4UkNdxl.js";function Ee({open:l,provider:s,onClose:c,onEdit:f}){const{t:x}=U();return s?e.jsx(Z,{open:l,onOpenChange:y=>!y&&c(),children:e.jsxs($,{className:"max-w-md",children:[e.jsxs(ee,{children:[e.jsx(re,{children:x("providers.noModelDialog.title")}),e.jsx(se,{children:x("providers.noModelDialog.subtitle",{name:s.label||s.id})})]}),e.jsxs(ae,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-xl bg-accent p-4 text-sm text-primary",children:x("providers.noModelDialog.description")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x("providers.noModelDialog.hint")})]}),e.jsxs(te,{children:[e.jsx(h,{variant:"outline",onClick:c,children:x("common.actions.close")}),e.jsx(h,{onClick:()=>f(s),children:x("providers.noModelDialog.primary")})]})]})}):null}function Ve({providersLength:l,filteredProviders:s,defaultLabels:c,providerSearch:f,providerTypeFilter:x,configPending:y,testingProviderId:a,onOpenEdit:d,onTestConnection:i,onRequestDelete:m,onProviderSearchChange:N,onResetFilters:k}){const{t:g}=U(),A=p=>{const D=p.authMode??(p.type==="anthropic"?"authToken":"apiKey");return D==="authToken"?"Bearer":D==="xAuthToken"?"X-Auth-Token":p.type==="anthropic"?"X-API-Key":g("providers.card.providerDefault")};return e.jsx(le,{className:"rounded-[1.35rem] border border-white/70 bg-card/95 shadow-[0_22px_56px_-46px_rgba(15,23,42,0.24)]",children:e.jsxs(ie,{className:"space-y-4 p-4 sm:p-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-[1.1rem] bg-secondary/60 p-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(S,{value:f,onChange:p=>N(p.target.value),placeholder:g("providers.filters.searchPlaceholder"),className:"h-10 bg-card/90 sm:max-w-[520px]"})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(de,{variant:"secondary",className:"rounded-full px-3 py-1 text-xs",children:g("providers.count",{count:s.length})}),e.jsx(h,{variant:"ghost",size:"sm",onClick:k,disabled:!f.trim()&&x==="all",className:"h-8 rounded-full px-3 text-xs",children:g("common.actions.reset")})]})]}),y?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-lg bg-secondary text-sm text-muted-foreground",children:g("common.loading")}):l===0?e.jsxs("div",{className:"rounded-lg border-2 border-dashed border-border/30 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:g("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:g("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):s.length===0?e.jsx("div",{className:"rounded-lg border-2 border-dashed border-border/30 p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:g("providers.emptyFiltered")})}):e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"grid gap-2.5 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5",children:s.map(p=>{var v;const D=A(p),C=((v=p.models)==null?void 0:v.length)??0,P=c.get(p.id);return e.jsx(Le,{provider:p,authMode:D,modelCount:C,defaultModel:P,isTesting:a===p.id,onEdit:()=>d(p),onTest:()=>i(p),onDelete:()=>m(p),t:g},p.id)})})})]})})}function Le({provider:l,authMode:s,modelCount:c,defaultModel:f,isTesting:x,onEdit:y,onTest:a,onDelete:d,t:i}){const m=!!f,N=m?"success":"warning",k=i(m?"providers.status.ready":"providers.status.needsDefault");return e.jsx(le,{"data-testid":"provider-card",className:"overflow-hidden rounded-[1rem] border border-border/60 bg-[linear-gradient(180deg,rgba(255,255,255,0.97)_0%,rgba(250,251,253,0.94)_100%)] shadow-[0_14px_32px_-30px_rgba(15,23,42,0.2)] transition-all duration-200 hover:-translate-y-0.5 hover:shadow-[0_20px_38px_-32px_rgba(59,130,246,0.18)] dark:border-white/10 dark:bg-[linear-gradient(180deg,rgba(15,23,42,0.92)_0%,rgba(2,6,23,0.88)_100%)]",children:e.jsxs(ie,{className:"space-y-2.5 p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2.5",children:e.jsx("h3",{className:"truncate text-[14px] font-semibold tracking-[-0.02em] text-foreground",title:l.label||l.id,children:l.label||l.id})}),e.jsx("code",{className:"mt-0.5 block truncate text-[11px] text-muted-foreground",title:l.id,children:l.id})]}),e.jsx(de,{variant:N,className:"shrink-0 rounded-full px-2 py-0.5 text-[10px]",children:k})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1.5 text-[11px]",children:[e.jsx(Y,{icon:e.jsx(ye,{className:"h-3.5 w-3.5"}),label:i("providers.card.authMode"),value:s}),e.jsx(Y,{icon:e.jsx(Ne,{className:"h-3.5 w-3.5"}),label:i("providers.card.modelsTitle"),value:c>0?i("providers.card.modelCount",{count:c}):i("providers.card.passthrough")})]}),e.jsxs("div",{className:"space-y-1.5 rounded-[0.85rem] bg-secondary/45 p-2 shadow-[inset_0_1px_0_rgba(255,255,255,0.55)] dark:bg-slate-900/[0.42]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsx(we,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("code",{className:"truncate",title:l.baseUrl,children:l.baseUrl})]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground/70",children:i("providers.card.defaultModelLabel")}),f?e.jsx("code",{className:"min-w-0 truncate rounded-full border border-border/65 bg-background/82 px-2 py-0.5 text-[10px] text-foreground dark:border-white/10 dark:bg-slate-950/[0.58]",title:f,children:f}):e.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:i("providers.card.noDefault")})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-1 border-t border-border/45 pt-2",children:[e.jsx(h,{variant:"ghost",size:"sm",onClick:y,className:"h-7 rounded-full px-2 text-[11px]",children:i("providers.actions.edit")}),e.jsx(h,{variant:"ghost",size:"sm",onClick:a,disabled:x,className:"h-7 rounded-full px-2 text-[11px]",children:x?e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"mr-1 h-3 w-3 animate-spin"}),i("common.actions.testingConnection")]}):i("providers.actions.test")}),e.jsx(h,{variant:"ghost",size:"sm",onClick:d,className:"h-7 rounded-full px-2 text-[11px] text-destructive hover:bg-destructive/10 hover:text-destructive",children:i("providers.actions.delete")})]})]})})}function Y({icon:l,label:s,value:c}){return e.jsxs("div",{className:"min-w-0 rounded-[0.75rem] bg-secondary/55 px-2 py-1.5 shadow-[inset_0_1px_0_rgba(255,255,255,0.58)] dark:bg-slate-900/[0.5]",children:[e.jsxs("div",{className:"mb-0.5 flex min-w-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[l,e.jsx("span",{className:"truncate",children:s})]}),e.jsx("p",{className:"truncate text-[11px] font-medium text-foreground",title:c,children:c})]})}function Ke({open:l,provider:s,options:c,usePreset:f,preservedExtras:x,onPresetChange:y,onConfirm:a,onClose:d}){const{t:i}=U();return s?e.jsx(Z,{open:l,onOpenChange:m=>!m&&d(),children:e.jsxs($,{className:"max-w-2xl",children:[e.jsxs(ee,{children:[e.jsx(re,{children:i("providers.testDialog.title")}),e.jsx(se,{children:i("providers.testDialog.subtitle",{name:s.label||s.id})})]}),e.jsxs(ae,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-xl bg-accent p-4 text-sm text-primary",children:i("providers.testDialog.description")}),e.jsxs("div",{className:"space-y-4 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"provider-test-preset",children:i("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.testDialog.presetDescription")})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(oe,{id:"provider-test-preset",checked:f,onCheckedChange:y})})]}),f?e.jsx("div",{className:"space-y-2",children:e.jsxs("details",{className:"rounded-xl border border-transparent bg-card p-2 text-xs shadow-[var(--surface-shadow)]",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:i("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:c.map(m=>e.jsxs("code",{className:"block rounded-lg bg-secondary px-2 py-1 text-xs",children:[m.key,": ",m.value]},m.key))})]})}):e.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.testDialog.presetDescription")})]}),Object.keys(x).length>0&&e.jsxs("div",{className:"space-y-2 rounded-xl bg-secondary/50 p-4 text-xs",children:[e.jsx("p",{className:"font-medium",children:i("providers.testDialog.preservedInfo")}),Object.entries(x).map(([m,N])=>e.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2 py-1 shadow-[var(--surface-shadow)]",children:[m,": ",N]},m))]})]}),e.jsxs(te,{children:[e.jsx(h,{variant:"outline",onClick:d,children:i("providers.testDialog.cancel")}),e.jsx(h,{onClick:()=>void a(),children:i("providers.testDialog.primary")})]})]})}):null}function F(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Oe(){return{_key:F(),id:"",label:""}}const I={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:{}},W=[{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 E(l){return l==="anthropic"?"authToken":"apiKey"}function J(l){return l?{id:l.id,label:l.label??l.id,baseUrl:l.baseUrl,apiKey:l.apiKey??"",type:l.type??"custom",defaultModel:l.defaultModel??"",models:(l.models??[]).map(s=>({...s,_key:F()})),authMode:l.authMode??E(l.type??"custom"),nonStreamViaStream:l.nonStreamViaStream??!1}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:E("custom"),nonStreamViaStream:!1}}function Re(l){return{_key:F(),id:l.id,label:l.label,nonStreamViaStream:l.nonStreamViaStream}}function Be({open:l,mode:s,provider:c,existingProviderIds:f,onClose:x,onSubmit:y}){const{t:a}=U(),[d,i]=b.useState(()=>J(c)),[m,N]=b.useState({}),[k,g]=b.useState(!1),[A,p]=b.useState(null),D=b.useRef(null),C=b.useRef(null),P=b.useRef(null),[v,z]=b.useState(s==="edit");b.useEffect(()=>{l&&(i(J(c)),N({}),p(null),g(!1),z(s==="edit"))},[l,c,s]),b.useEffect(()=>{if(!l)return;const r=t=>{t.key==="Escape"&&x()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[l,x]),b.useEffect(()=>{if(l){if(s==="create"&&P.current){P.current.focus();return}C.current&&C.current.focus()}},[l,s]);const V=s==="create",L=b.useMemo(()=>d.models.filter(r=>r.id.trim().length>0),[d.models]),H=b.useMemo(()=>{var r;return((r=W.find(t=>t.value===d.type))==null?void 0:r.label)??"Custom"},[d.type]),q=(r,t)=>a(t==="authToken"?"providers.drawer.fields.authModeAuthToken":t==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":r==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault"),ne=d.label.trim()||d.id.trim()||a("providers.drawer.summary.untitled"),X=b.useMemo(()=>[{label:a("providers.drawer.summary.type"),value:H},{label:a("providers.drawer.summary.auth"),value:q(d.type,d.authMode)},{label:a("providers.drawer.summary.models"),value:L.length.toLocaleString()}],[L.length,d.authMode,d.type,H,a]),K=r=>t=>{i(o=>({...o,[r]:t}))},ce=r=>{i(t=>{const n=!v||t.label.trim().length===0||t.label===t.id?r:t.label;return{...t,id:r,label:n}})},me=r=>{i(t=>{var Q;const n=I[r??"custom"]??I.custom,u=E(t.type),j=E(r),M=Object.values(I).map(T=>T.baseUrl).filter(T=>!!T),R=!t.baseUrl||M.includes(t.baseUrl),je=s==="create"&&(t.models.length===0||t.models.every(T=>T.id.trim().length===0)),_={...t,type:r,authMode:t.authMode===u?j:t.authMode};return n!=null&&n.baseUrl&&R&&(_.baseUrl=n.baseUrl),n!=null&&n.models&&je&&(_.models=n.models.map(Re),_.defaultModel=n.defaultModel??((Q=n.models[0])==null?void 0:Q.id)??""),_})},G=(r,t)=>{i(o=>{const n=[...o.models];return n[r]={...n[r],...t},{...o,models:n}})},xe=(r,t)=>{i(o=>{const n=[...o.models],u=n[r];if(!u)return o;const j=!v||!u.label||u.label===u.id,M={...u,id:t,label:j?t:u.label};n[r]=M;const R=o.defaultModel===u.id?t:o.defaultModel;return{...o,models:n,defaultModel:R}})},ue=r=>{i(t=>{if(r<0||r>=t.models.length)return t;const o=t.models.filter((u,j)=>j!==r);let n=t.defaultModel;return o.some(u=>u.id===n)||(n=""),{...t,models:o,defaultModel:n}})},pe=()=>{i(r=>({...r,models:[...r.models,Oe()]}))},O=r=>{i(t=>({...t,authMode:r}))},he=r=>{i(t=>({...t,nonStreamViaStream:r}))},fe=(r,t)=>{G(r,{nonStreamViaStream:t==="inherit"?void 0:t==="enabled"})},ge=()=>{const r={},t=d.id.trim(),o=d.baseUrl.trim();if(s==="create"&&(t.length===0?r.id=a("providers.drawer.errors.idRequired"):f.includes(t)&&(r.id=a("providers.drawer.errors.idDuplicate"))),s==="edit"&&t.length===0&&(r.id=a("providers.drawer.errors.idRequired")),o.length===0)r.baseUrl=a("providers.drawer.errors.baseUrlInvalid");else try{new URL(o)}catch{r.baseUrl=a("providers.drawer.errors.baseUrlInvalid")}if(d.models.length>0){const n=new Set;d.models.some(j=>{const M=j.id.trim();return M.length===0||n.has(M)?!0:(n.add(M),!1)})&&(r.models=a("providers.drawer.errors.modelInvalid"))}return d.defaultModel&&!d.models.some(n=>n.id===d.defaultModel)&&(r.models=a("providers.drawer.errors.defaultInvalid")),N(r),Object.keys(r).length===0},be=()=>{const r=d.models.map(u=>{var j;return{id:u.id.trim(),label:(j=u.label)!=null&&j.trim()?u.label.trim():void 0,nonStreamViaStream:u.nonStreamViaStream}}).filter(u=>u.id.length>0),t=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,o=d.authMode==="apiKey"&&d.type!=="anthropic"?void 0:d.authMode,n={id:d.id.trim(),label:d.label.trim()||d.id.trim(),baseUrl:d.baseUrl.trim(),apiKey:d.apiKey.trim()||void 0,type:d.type??"custom",defaultModel:d.defaultModel||void 0,models:r.length>0?r:void 0,extraHeaders:t,authMode:o};return d.nonStreamViaStream&&(n.nonStreamViaStream=!0),n},ve=async()=>{if(p(null),!!ge()){g(!0);try{const r=be();await y(r)}catch(r){p(a("providers.drawer.toast.saveFailure",{message:r instanceof Error?r.message:"unknown"})),g(!1);return}g(!1),x()}};return l?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm",onClick:x,"aria-hidden":"true"}),e.jsxs("aside",{ref:D,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full min-h-0 w-full max-w-5xl flex-col border-l border-border/45 bg-background/96 shadow-[var(--surface-shadow-lg)] backdrop-blur",children:[e.jsxs("header",{className:"border-b border-border/45 bg-secondary/45 px-6 py-5 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"inline-flex rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em] text-primary",children:a(V?"providers.drawer.quickStart":"providers.drawer.editTitle")}),e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold tracking-[-0.02em]",children:a(V?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:a("providers.drawer.description")})]})]}),e.jsx(h,{type:"button",ref:C,variant:"outline",onClick:x,className:"bg-card",children:a("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:X.map(r=>e.jsxs("div",{className:"rounded-xl border border-transparent bg-card px-4 py-3 shadow-[var(--surface-shadow)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:r.value})]},r.label))})]}),e.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"min-h-0 overflow-y-auto px-6 py-5 pb-10",children:[e.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:W.map(r=>{var o;const t=r.value===d.type;return e.jsxs("button",{type:"button",onClick:()=>me(r.value),className:Ie("rounded-2xl border px-4 py-3 text-left transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t?"border-primary bg-primary/10 text-primary shadow-sm":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[e.jsx("div",{className:"text-sm font-semibold",children:r.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((o=I[r.value??"custom"])==null?void 0:o.baseUrl)??a("providers.drawer.hints.customProvider")})]},r.value??"custom")})})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-basic-info",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:a("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.basic")})]}),e.jsx(h,{type:"button",variant:"outline",size:"sm",onClick:()=>z(r=>!r),className:"bg-card text-xs",children:a(v?"providers.drawer.fields.hideAdvanced":"providers.drawer.fields.showAdvanced")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.id")}),e.jsx(S,{value:d.id,ref:P,onChange:r=>ce(r.target.value),disabled:!V,placeholder:a("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!m.id}),m.id?e.jsx("span",{className:"text-xs text-destructive",children:m.id}):null]}),e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.label")}),e.jsx(S,{value:d.label,onChange:r=>K("label")(r.target.value),placeholder:a("providers.drawer.fields.labelPlaceholder")})]})]}),e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.baseUrl")}),e.jsx(S,{value:d.baseUrl,onChange:r=>K("baseUrl")(r.target.value),placeholder:a("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!m.baseUrl}),m.baseUrl?e.jsx("span",{className:"text-xs text-destructive",children:m.baseUrl}):null]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-auth-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.auth")})]}),e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.apiKey")}),e.jsx(S,{value:d.apiKey,onChange:r=>K("apiKey")(r.target.value),placeholder:a("providers.drawer.fields.apiKeyPlaceholder")})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-xl border border-transparent bg-card p-4 text-xs shadow-[var(--surface-shadow)]",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:a("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:a("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:d.authMode==="apiKey",onChange:()=>O("apiKey"),className:"mt-0.5 h-4 w-4 accent-[hsl(var(--primary))]"}),e.jsx("span",{children:q(d.type,"apiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:d.authMode==="authToken",onChange:()=>O("authToken"),className:"mt-0.5 h-4 w-4 accent-[hsl(var(--primary))]"}),e.jsx("span",{children:a("providers.drawer.fields.authModeAuthToken")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:d.authMode==="xAuthToken",onChange:()=>O("xAuthToken"),className:"mt-0.5 h-4 w-4 accent-[hsl(var(--primary))]"}),e.jsx("span",{children:a("providers.drawer.fields.authModeXAuthToken")})]})]}),v?e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:a("providers.drawer.fields.nonStreamViaStream")}),e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:a("providers.drawer.fields.nonStreamViaStreamHint")})]}),e.jsx(oe,{checked:d.nonStreamViaStream,onCheckedChange:he,"aria-label":a("providers.drawer.fields.nonStreamViaStream")})]}):null]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-model-fields",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:a("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.modelsDescription")})]}),e.jsx(h,{type:"button",variant:"outline",size:"sm",onClick:pe,className:"bg-card text-xs",children:a("providers.drawer.fields.addModel")})]}),m.models?e.jsx("p",{className:"text-xs text-destructive",children:m.models}):null,e.jsxs("div",{className:"space-y-4",children:[d.models.map((r,t)=>e.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelId")}),e.jsx(S,{value:r.id,onChange:o=>xe(t,o.target.value),placeholder:a("providers.drawer.fields.modelIdPlaceholder")})]}),v?e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelLabel")}),e.jsx(S,{value:r.label??"",onChange:o=>G(t,{label:o.target.value}),placeholder:a("providers.drawer.fields.modelLabelPlaceholder")})]}):null]}),v?e.jsxs(w,{className:"mt-4 flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelNonStreamViaStream")}),e.jsxs(Te,{value:r.nonStreamViaStream===void 0?"inherit":r.nonStreamViaStream?"enabled":"disabled",onValueChange:o=>fe(t,o),children:[e.jsx(Ue,{children:e.jsx(Ae,{})}),e.jsxs(_e,{children:[e.jsx(B,{value:"inherit",children:a("providers.drawer.fields.modelNonStreamViaStreamInherit")}),e.jsx(B,{value:"enabled",children:a("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),e.jsx(B,{value:"disabled",children:a("providers.drawer.fields.modelNonStreamViaStreamDisabled")})]})]})]}):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-muted-foreground",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:r.id,checked:d.defaultModel===r.id,onChange:()=>i(o=>({...o,defaultModel:r.id})),disabled:r.id.trim().length===0,className:"h-4 w-4 accent-[hsl(var(--primary))]"}),a("providers.drawer.fields.setDefault")]}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>ue(t),disabled:d.models.length===0,children:a("providers.drawer.fields.removeModel")})]})]},r._key)),d.models.length===0?e.jsx("div",{className:"rounded-xl border border-amber-200 bg-amber-50 p-5 dark:border-amber-800 dark:bg-amber-950/30",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:a("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:a("providers.drawer.noModelsHint",{providerId:d.id||"provider-id"})}),e.jsxs("div",{className:"rounded-lg bg-secondary/50 p-2.5",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:a("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2.5 py-1.5 font-mono text-xs text-foreground shadow-[var(--surface-shadow)]",children:['"claude-*": "',(d.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),L.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:a("providers.drawer.defaultHint",{model:d.defaultModel||a("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden min-h-0 overflow-y-auto border-l border-border/45 bg-secondary/40 px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:ne}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:X.map(r=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:r.label}),e.jsx("span",{className:"text-right font-medium",children:r.value})]},r.label))})]}),e.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:a("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:a("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:a("providers.drawer.hints.checkModels")})]})]}),v&&e.jsxs("div",{className:"rounded-xl bg-accent p-4 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium text-primary",children:a("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:a("providers.drawer.hints.advancedBody")})]})]})})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-border/45 bg-secondary/45 px-6 py-4 text-sm backdrop-blur-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-destructive","aria-live":"polite",children:A?e.jsx("span",{children:A}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:x,disabled:k,className:"bg-card",children:a("common.actions.cancel")}),e.jsx(h,{type:"button",onClick:ve,disabled:k,children:a(k?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}function or(){const{t:l}=U(),s=Pe();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Ce,{info:e.jsx("span",{className:"rounded-full bg-secondary px-2.5 py-1 text-xs text-muted-foreground",children:l("providers.count",{count:s.providerCount})}),actions:e.jsxs(e.Fragment,{children:[e.jsx(h,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs(Se,{to:"/routing",children:[l("nav.routing"),e.jsx(Me,{className:"h-4 w-4","aria-hidden":"true"})]})}),e.jsx(h,{size:"sm",onClick:s.handleOpenCreate,children:l("providers.actions.add")})]})}),e.jsx(Ve,{configPending:s.configQuery.isPending||!s.config&&s.configQuery.isFetching,defaultLabels:s.defaultLabels,filteredProviders:s.filteredProviders,onOpenEdit:s.handleOpenEdit,onRequestDelete:c=>s.setConfirmAction({kind:"provider",provider:c}),onResetFilters:()=>{s.setProviderSearch(""),s.setProviderTypeFilter("all")},onProviderSearchChange:s.setProviderSearch,onProviderTypeChange:s.setProviderTypeFilter,onTestConnection:s.initiateTestConnection,providerSearch:s.providerSearch,providerTypeFilter:s.providerTypeFilter,providersLength:s.providers.length,testingProviderId:s.testingProviderId}),e.jsx(Be,{open:s.drawerOpen,mode:s.drawerMode,provider:s.drawerMode==="edit"?s.editingProvider:void 0,existingProviderIds:s.providers.map(c=>c.id).filter(c=>s.drawerMode==="edit"&&s.editingProvider?c!==s.editingProvider.id:!0),onClose:()=>{s.setDrawerOpen(!1),s.setEditingProvider(void 0),s.setDrawerMode("create")},onSubmit:s.handleProviderSubmit}),e.jsx(Ke,{open:s.testDialogOpen,provider:s.testDialogProvider,options:s.anthropicTestHeaderOptions,preservedExtras:s.testDialogPreservedExtras,usePreset:s.testDialogUsePreset,onPresetChange:s.setTestDialogUsePreset,onConfirm:s.confirmTestDialog,onClose:s.closeTestDialog}),e.jsx(Ee,{open:!!s.noModelDialogProvider,provider:s.noModelDialogProvider,onClose:()=>s.setNoModelDialogProvider(null),onEdit:c=>{s.setNoModelDialogProvider(null),s.handleOpenEdit(c)}}),e.jsx(De,{open:!!s.confirmAction,onOpenChange:c=>{!c&&!s.confirmingAction&&s.setConfirmAction(null)},title:s.confirmDialogTitle,description:s.confirmDialogDescription,confirmLabel:s.confirmingAction?l("common.actions.loading"):l("common.delete"),cancelLabel:l("common.actions.cancel"),loading:s.confirmingAction,onConfirm:s.handleConfirmDialog,children:s.confirmDialogName?e.jsx("div",{className:"rounded-xl border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:s.confirmDialogName}):null})]})}export{or as default};
1
+ import{j as e,aA as ye,aF as Ne,aG as we,N as ke,r as b,ac as Me}from"./vendor-DdPBfMMb.js";import{L as Se}from"./router-D2Fb4U0L.js";import{C as De}from"./ConfirmDialog-BYuZwgWC.js";import{P as Ce}from"./PageToolbar-DATSQ0uI.js";import{B as h}from"./app-CUHICvDo.js";import{D as Z,A as $,a as ee,b as re,c as se,d as ae,e as te}from"./DialogShell-C0YGDw-Y.js";import{u as U}from"./i18n-C8tBby0x.js";import{B as de}from"./queryKeys-DLyolp-A.js";import{C as le,a as ie}from"./card-DPI7HeM2.js";import{I as S}from"./input-CRm3Lt3O.js";import{L as w}from"./label-D0KXM_V7.js";import{S as oe}from"./switch-W7ZoAE3i.js";import{u as Pe}from"./useModelManagementState-DFFjS9uq.js";import{S as Te,a as Ue,b as Ae,c as _e,d as B}from"./select-C4IDwhTu.js";import{c as Ie}from"./global-DA-0y145.js";import"./query-QCek5MsK.js";import"./radix-C0Bt6n-I.js";import"./gateway-DhxavTUf.js";import"./useAppMutation-CJrALOdE.js";import"./useApiQuery-DhdisbOK.js";function Ee({open:l,provider:s,onClose:c,onEdit:f}){const{t:x}=U();return s?e.jsx(Z,{open:l,onOpenChange:y=>!y&&c(),children:e.jsxs($,{className:"max-w-md",children:[e.jsxs(ee,{children:[e.jsx(re,{children:x("providers.noModelDialog.title")}),e.jsx(se,{children:x("providers.noModelDialog.subtitle",{name:s.label||s.id})})]}),e.jsxs(ae,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-xl bg-accent p-4 text-sm text-primary",children:x("providers.noModelDialog.description")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x("providers.noModelDialog.hint")})]}),e.jsxs(te,{children:[e.jsx(h,{variant:"outline",onClick:c,children:x("common.actions.close")}),e.jsx(h,{onClick:()=>f(s),children:x("providers.noModelDialog.primary")})]})]})}):null}function Ve({providersLength:l,filteredProviders:s,defaultLabels:c,providerSearch:f,providerTypeFilter:x,configPending:y,testingProviderId:a,onOpenEdit:d,onTestConnection:i,onRequestDelete:m,onProviderSearchChange:N,onResetFilters:k}){const{t:g}=U(),A=p=>{const D=p.authMode??(p.type==="anthropic"?"authToken":"apiKey");return D==="authToken"?"Bearer":D==="xAuthToken"?"X-Auth-Token":p.type==="anthropic"?"X-API-Key":g("providers.card.providerDefault")};return e.jsx(le,{className:"rounded-[1.35rem] border border-white/70 bg-card/95 shadow-[0_22px_56px_-46px_rgba(15,23,42,0.24)]",children:e.jsxs(ie,{className:"space-y-4 p-4 sm:p-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-[1.1rem] bg-secondary/60 p-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(S,{value:f,onChange:p=>N(p.target.value),placeholder:g("providers.filters.searchPlaceholder"),className:"h-10 bg-card/90 sm:max-w-[520px]"})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(de,{variant:"secondary",className:"rounded-full px-3 py-1 text-xs",children:g("providers.count",{count:s.length})}),e.jsx(h,{variant:"ghost",size:"sm",onClick:k,disabled:!f.trim()&&x==="all",className:"h-8 rounded-full px-3 text-xs",children:g("common.actions.reset")})]})]}),y?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-lg bg-secondary text-sm text-muted-foreground",children:g("common.loading")}):l===0?e.jsxs("div",{className:"rounded-lg border-2 border-dashed border-border/30 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:g("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:g("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):s.length===0?e.jsx("div",{className:"rounded-lg border-2 border-dashed border-border/30 p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:g("providers.emptyFiltered")})}):e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"grid gap-2.5 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5",children:s.map(p=>{var v;const D=A(p),C=((v=p.models)==null?void 0:v.length)??0,P=c.get(p.id);return e.jsx(Le,{provider:p,authMode:D,modelCount:C,defaultModel:P,isTesting:a===p.id,onEdit:()=>d(p),onTest:()=>i(p),onDelete:()=>m(p),t:g},p.id)})})})]})})}function Le({provider:l,authMode:s,modelCount:c,defaultModel:f,isTesting:x,onEdit:y,onTest:a,onDelete:d,t:i}){const m=!!f,N=m?"success":"warning",k=i(m?"providers.status.ready":"providers.status.needsDefault");return e.jsx(le,{"data-testid":"provider-card",className:"overflow-hidden rounded-[1rem] border border-border/60 bg-[linear-gradient(180deg,rgba(255,255,255,0.97)_0%,rgba(250,251,253,0.94)_100%)] shadow-[0_14px_32px_-30px_rgba(15,23,42,0.2)] transition-all duration-200 hover:-translate-y-0.5 hover:shadow-[0_20px_38px_-32px_rgba(59,130,246,0.18)] dark:border-white/10 dark:bg-[linear-gradient(180deg,rgba(15,23,42,0.92)_0%,rgba(2,6,23,0.88)_100%)]",children:e.jsxs(ie,{className:"space-y-2.5 p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2.5",children:e.jsx("h3",{className:"truncate text-[14px] font-semibold tracking-[-0.02em] text-foreground",title:l.label||l.id,children:l.label||l.id})}),e.jsx("code",{className:"mt-0.5 block truncate text-[11px] text-muted-foreground",title:l.id,children:l.id})]}),e.jsx(de,{variant:N,className:"shrink-0 rounded-full px-2 py-0.5 text-[10px]",children:k})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1.5 text-[11px]",children:[e.jsx(Y,{icon:e.jsx(ye,{className:"h-3.5 w-3.5"}),label:i("providers.card.authMode"),value:s}),e.jsx(Y,{icon:e.jsx(Ne,{className:"h-3.5 w-3.5"}),label:i("providers.card.modelsTitle"),value:c>0?i("providers.card.modelCount",{count:c}):i("providers.card.passthrough")})]}),e.jsxs("div",{className:"space-y-1.5 rounded-[0.85rem] bg-secondary/45 p-2 shadow-[inset_0_1px_0_rgba(255,255,255,0.55)] dark:bg-slate-900/[0.42]",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsx(we,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("code",{className:"truncate",title:l.baseUrl,children:l.baseUrl})]}),e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground/70",children:i("providers.card.defaultModelLabel")}),f?e.jsx("code",{className:"min-w-0 truncate rounded-full border border-border/65 bg-background/82 px-2 py-0.5 text-[10px] text-foreground dark:border-white/10 dark:bg-slate-950/[0.58]",title:f,children:f}):e.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:i("providers.card.noDefault")})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-1 border-t border-border/45 pt-2",children:[e.jsx(h,{variant:"ghost",size:"sm",onClick:y,className:"h-7 rounded-full px-2 text-[11px]",children:i("providers.actions.edit")}),e.jsx(h,{variant:"ghost",size:"sm",onClick:a,disabled:x,className:"h-7 rounded-full px-2 text-[11px]",children:x?e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"mr-1 h-3 w-3 animate-spin"}),i("common.actions.testingConnection")]}):i("providers.actions.test")}),e.jsx(h,{variant:"ghost",size:"sm",onClick:d,className:"h-7 rounded-full px-2 text-[11px] text-destructive hover:bg-destructive/10 hover:text-destructive",children:i("providers.actions.delete")})]})]})})}function Y({icon:l,label:s,value:c}){return e.jsxs("div",{className:"min-w-0 rounded-[0.75rem] bg-secondary/55 px-2 py-1.5 shadow-[inset_0_1px_0_rgba(255,255,255,0.58)] dark:bg-slate-900/[0.5]",children:[e.jsxs("div",{className:"mb-0.5 flex min-w-0 items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[l,e.jsx("span",{className:"truncate",children:s})]}),e.jsx("p",{className:"truncate text-[11px] font-medium text-foreground",title:c,children:c})]})}function Ke({open:l,provider:s,options:c,usePreset:f,preservedExtras:x,onPresetChange:y,onConfirm:a,onClose:d}){const{t:i}=U();return s?e.jsx(Z,{open:l,onOpenChange:m=>!m&&d(),children:e.jsxs($,{className:"max-w-2xl",children:[e.jsxs(ee,{children:[e.jsx(re,{children:i("providers.testDialog.title")}),e.jsx(se,{children:i("providers.testDialog.subtitle",{name:s.label||s.id})})]}),e.jsxs(ae,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-xl bg-accent p-4 text-sm text-primary",children:i("providers.testDialog.description")}),e.jsxs("div",{className:"space-y-4 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"provider-test-preset",children:i("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.testDialog.presetDescription")})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(oe,{id:"provider-test-preset",checked:f,onCheckedChange:y})})]}),f?e.jsx("div",{className:"space-y-2",children:e.jsxs("details",{className:"rounded-xl border border-transparent bg-card p-2 text-xs shadow-[var(--surface-shadow)]",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:i("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:c.map(m=>e.jsxs("code",{className:"block rounded-lg bg-secondary px-2 py-1 text-xs",children:[m.key,": ",m.value]},m.key))})]})}):e.jsx("p",{className:"text-xs text-muted-foreground",children:i("providers.testDialog.presetDescription")})]}),Object.keys(x).length>0&&e.jsxs("div",{className:"space-y-2 rounded-xl bg-secondary/50 p-4 text-xs",children:[e.jsx("p",{className:"font-medium",children:i("providers.testDialog.preservedInfo")}),Object.entries(x).map(([m,N])=>e.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2 py-1 shadow-[var(--surface-shadow)]",children:[m,": ",N]},m))]})]}),e.jsxs(te,{children:[e.jsx(h,{variant:"outline",onClick:d,children:i("providers.testDialog.cancel")}),e.jsx(h,{onClick:()=>void a(),children:i("providers.testDialog.primary")})]})]})}):null}function F(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Oe(){return{_key:F(),id:"",label:""}}const I={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:{}},W=[{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 E(l){return l==="anthropic"?"authToken":"apiKey"}function J(l){return l?{id:l.id,label:l.label??l.id,baseUrl:l.baseUrl,apiKey:l.apiKey??"",type:l.type??"custom",defaultModel:l.defaultModel??"",models:(l.models??[]).map(s=>({...s,_key:F()})),authMode:l.authMode??E(l.type??"custom"),nonStreamViaStream:l.nonStreamViaStream??!1}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:E("custom"),nonStreamViaStream:!1}}function Re(l){return{_key:F(),id:l.id,label:l.label,nonStreamViaStream:l.nonStreamViaStream}}function Be({open:l,mode:s,provider:c,existingProviderIds:f,onClose:x,onSubmit:y}){const{t:a}=U(),[d,i]=b.useState(()=>J(c)),[m,N]=b.useState({}),[k,g]=b.useState(!1),[A,p]=b.useState(null),D=b.useRef(null),C=b.useRef(null),P=b.useRef(null),[v,z]=b.useState(s==="edit");b.useEffect(()=>{l&&(i(J(c)),N({}),p(null),g(!1),z(s==="edit"))},[l,c,s]),b.useEffect(()=>{if(!l)return;const r=t=>{t.key==="Escape"&&x()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[l,x]),b.useEffect(()=>{if(l){if(s==="create"&&P.current){P.current.focus();return}C.current&&C.current.focus()}},[l,s]);const V=s==="create",L=b.useMemo(()=>d.models.filter(r=>r.id.trim().length>0),[d.models]),H=b.useMemo(()=>{var r;return((r=W.find(t=>t.value===d.type))==null?void 0:r.label)??"Custom"},[d.type]),q=(r,t)=>a(t==="authToken"?"providers.drawer.fields.authModeAuthToken":t==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":r==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault"),ne=d.label.trim()||d.id.trim()||a("providers.drawer.summary.untitled"),X=b.useMemo(()=>[{label:a("providers.drawer.summary.type"),value:H},{label:a("providers.drawer.summary.auth"),value:q(d.type,d.authMode)},{label:a("providers.drawer.summary.models"),value:L.length.toLocaleString()}],[L.length,d.authMode,d.type,H,a]),K=r=>t=>{i(o=>({...o,[r]:t}))},ce=r=>{i(t=>{const n=!v||t.label.trim().length===0||t.label===t.id?r:t.label;return{...t,id:r,label:n}})},me=r=>{i(t=>{var Q;const n=I[r??"custom"]??I.custom,u=E(t.type),j=E(r),M=Object.values(I).map(T=>T.baseUrl).filter(T=>!!T),R=!t.baseUrl||M.includes(t.baseUrl),je=s==="create"&&(t.models.length===0||t.models.every(T=>T.id.trim().length===0)),_={...t,type:r,authMode:t.authMode===u?j:t.authMode};return n!=null&&n.baseUrl&&R&&(_.baseUrl=n.baseUrl),n!=null&&n.models&&je&&(_.models=n.models.map(Re),_.defaultModel=n.defaultModel??((Q=n.models[0])==null?void 0:Q.id)??""),_})},G=(r,t)=>{i(o=>{const n=[...o.models];return n[r]={...n[r],...t},{...o,models:n}})},xe=(r,t)=>{i(o=>{const n=[...o.models],u=n[r];if(!u)return o;const j=!v||!u.label||u.label===u.id,M={...u,id:t,label:j?t:u.label};n[r]=M;const R=o.defaultModel===u.id?t:o.defaultModel;return{...o,models:n,defaultModel:R}})},ue=r=>{i(t=>{if(r<0||r>=t.models.length)return t;const o=t.models.filter((u,j)=>j!==r);let n=t.defaultModel;return o.some(u=>u.id===n)||(n=""),{...t,models:o,defaultModel:n}})},pe=()=>{i(r=>({...r,models:[...r.models,Oe()]}))},O=r=>{i(t=>({...t,authMode:r}))},he=r=>{i(t=>({...t,nonStreamViaStream:r}))},fe=(r,t)=>{G(r,{nonStreamViaStream:t==="inherit"?void 0:t==="enabled"})},ge=()=>{const r={},t=d.id.trim(),o=d.baseUrl.trim();if(s==="create"&&(t.length===0?r.id=a("providers.drawer.errors.idRequired"):f.includes(t)&&(r.id=a("providers.drawer.errors.idDuplicate"))),s==="edit"&&t.length===0&&(r.id=a("providers.drawer.errors.idRequired")),o.length===0)r.baseUrl=a("providers.drawer.errors.baseUrlInvalid");else try{new URL(o)}catch{r.baseUrl=a("providers.drawer.errors.baseUrlInvalid")}if(d.models.length>0){const n=new Set;d.models.some(j=>{const M=j.id.trim();return M.length===0||n.has(M)?!0:(n.add(M),!1)})&&(r.models=a("providers.drawer.errors.modelInvalid"))}return d.defaultModel&&!d.models.some(n=>n.id===d.defaultModel)&&(r.models=a("providers.drawer.errors.defaultInvalid")),N(r),Object.keys(r).length===0},be=()=>{const r=d.models.map(u=>{var j;return{id:u.id.trim(),label:(j=u.label)!=null&&j.trim()?u.label.trim():void 0,nonStreamViaStream:u.nonStreamViaStream}}).filter(u=>u.id.length>0),t=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,o=d.authMode==="apiKey"&&d.type!=="anthropic"?void 0:d.authMode,n={id:d.id.trim(),label:d.label.trim()||d.id.trim(),baseUrl:d.baseUrl.trim(),apiKey:d.apiKey.trim()||void 0,type:d.type??"custom",defaultModel:d.defaultModel||void 0,models:r.length>0?r:void 0,extraHeaders:t,authMode:o};return d.nonStreamViaStream&&(n.nonStreamViaStream=!0),n},ve=async()=>{if(p(null),!!ge()){g(!0);try{const r=be();await y(r)}catch(r){p(a("providers.drawer.toast.saveFailure",{message:r instanceof Error?r.message:"unknown"})),g(!1);return}g(!1),x()}};return l?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm",onClick:x,"aria-hidden":"true"}),e.jsxs("aside",{ref:D,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full min-h-0 w-full max-w-5xl flex-col border-l border-border/45 bg-background/96 shadow-[var(--surface-shadow-lg)] backdrop-blur",children:[e.jsxs("header",{className:"border-b border-border/45 bg-secondary/45 px-6 py-5 backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"inline-flex rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em] text-primary",children:a(V?"providers.drawer.quickStart":"providers.drawer.editTitle")}),e.jsxs("div",{children:[e.jsx("h2",{id:"provider-drawer-title",className:"text-lg font-semibold tracking-[-0.02em]",children:a(V?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:a("providers.drawer.description")})]})]}),e.jsx(h,{type:"button",ref:C,variant:"outline",onClick:x,className:"bg-card",children:a("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:X.map(r=>e.jsxs("div",{className:"rounded-xl border border-transparent bg-card px-4 py-3 shadow-[var(--surface-shadow)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:r.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:r.value})]},r.label))})]}),e.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"min-h-0 overflow-y-auto px-6 py-5 pb-10",children:[e.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:W.map(r=>{var o;const t=r.value===d.type;return e.jsxs("button",{type:"button",onClick:()=>me(r.value),className:Ie("rounded-2xl border px-4 py-3 text-left transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t?"border-primary bg-primary/10 text-primary shadow-sm":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[e.jsx("div",{className:"text-sm font-semibold",children:r.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((o=I[r.value??"custom"])==null?void 0:o.baseUrl)??a("providers.drawer.hints.customProvider")})]},r.value??"custom")})})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-basic-info",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:a("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.basic")})]}),e.jsx(h,{type:"button",variant:"outline",size:"sm",onClick:()=>z(r=>!r),className:"bg-card text-xs",children:a(v?"providers.drawer.fields.hideAdvanced":"providers.drawer.fields.showAdvanced")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.id")}),e.jsx(S,{value:d.id,ref:P,onChange:r=>ce(r.target.value),disabled:!V,placeholder:a("providers.drawer.fields.idPlaceholder"),"aria-invalid":!!m.id}),m.id?e.jsx("span",{className:"text-xs text-destructive",children:m.id}):null]}),e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.label")}),e.jsx(S,{value:d.label,onChange:r=>K("label")(r.target.value),placeholder:a("providers.drawer.fields.labelPlaceholder")})]})]}),e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.baseUrl")}),e.jsx(S,{value:d.baseUrl,onChange:r=>K("baseUrl")(r.target.value),placeholder:a("providers.drawer.fields.baseUrlPlaceholder"),"aria-invalid":!!m.baseUrl}),m.baseUrl?e.jsx("span",{className:"text-xs text-destructive",children:m.baseUrl}):null]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-auth-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.auth")})]}),e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.apiKey")}),e.jsx(S,{value:d.apiKey,onChange:r=>K("apiKey")(r.target.value),placeholder:a("providers.drawer.fields.apiKeyPlaceholder")})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-xl border border-transparent bg-card p-4 text-xs shadow-[var(--surface-shadow)]",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:a("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:a("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:d.authMode==="apiKey",onChange:()=>O("apiKey"),className:"mt-0.5 h-4 w-4 accent-[hsl(var(--primary))]"}),e.jsx("span",{children:q(d.type,"apiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:d.authMode==="authToken",onChange:()=>O("authToken"),className:"mt-0.5 h-4 w-4 accent-[hsl(var(--primary))]"}),e.jsx("span",{children:a("providers.drawer.fields.authModeAuthToken")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-accent focus-within:bg-accent",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:d.authMode==="xAuthToken",onChange:()=>O("xAuthToken"),className:"mt-0.5 h-4 w-4 accent-[hsl(var(--primary))]"}),e.jsx("span",{children:a("providers.drawer.fields.authModeXAuthToken")})]})]}),v?e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:a("providers.drawer.fields.nonStreamViaStream")}),e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:a("providers.drawer.fields.nonStreamViaStreamHint")})]}),e.jsx(oe,{checked:d.nonStreamViaStream,onCheckedChange:he,"aria-label":a("providers.drawer.fields.nonStreamViaStream")})]}):null]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-model-fields",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:a("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.modelsDescription")})]}),e.jsx(h,{type:"button",variant:"outline",size:"sm",onClick:pe,className:"bg-card text-xs",children:a("providers.drawer.fields.addModel")})]}),m.models?e.jsx("p",{className:"text-xs text-destructive",children:m.models}):null,e.jsxs("div",{className:"space-y-4",children:[d.models.map((r,t)=>e.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelId")}),e.jsx(S,{value:r.id,onChange:o=>xe(t,o.target.value),placeholder:a("providers.drawer.fields.modelIdPlaceholder")})]}),v?e.jsxs(w,{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelLabel")}),e.jsx(S,{value:r.label??"",onChange:o=>G(t,{label:o.target.value}),placeholder:a("providers.drawer.fields.modelLabelPlaceholder")})]}):null]}),v?e.jsxs(w,{className:"mt-4 flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelNonStreamViaStream")}),e.jsxs(Te,{value:r.nonStreamViaStream===void 0?"inherit":r.nonStreamViaStream?"enabled":"disabled",onValueChange:o=>fe(t,o),children:[e.jsx(Ue,{children:e.jsx(Ae,{})}),e.jsxs(_e,{children:[e.jsx(B,{value:"inherit",children:a("providers.drawer.fields.modelNonStreamViaStreamInherit")}),e.jsx(B,{value:"enabled",children:a("providers.drawer.fields.modelNonStreamViaStreamEnabled")}),e.jsx(B,{value:"disabled",children:a("providers.drawer.fields.modelNonStreamViaStreamDisabled")})]})]})]}):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-muted-foreground",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:r.id,checked:d.defaultModel===r.id,onChange:()=>i(o=>({...o,defaultModel:r.id})),disabled:r.id.trim().length===0,className:"h-4 w-4 accent-[hsl(var(--primary))]"}),a("providers.drawer.fields.setDefault")]}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",className:"h-auto px-2 text-destructive",onClick:()=>ue(t),disabled:d.models.length===0,children:a("providers.drawer.fields.removeModel")})]})]},r._key)),d.models.length===0?e.jsx("div",{className:"rounded-xl border border-amber-200 bg-amber-50 p-5 dark:border-amber-800 dark:bg-amber-950/30",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:a("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:a("providers.drawer.noModelsHint",{providerId:d.id||"provider-id"})}),e.jsxs("div",{className:"rounded-lg bg-secondary/50 p-2.5",children:[e.jsx("p",{className:"mb-1.5 text-xs font-medium text-foreground",children:a("providers.drawer.routeExample")}),e.jsxs("code",{className:"block rounded-lg border border-transparent bg-card px-2.5 py-1.5 font-mono text-xs text-foreground shadow-[var(--surface-shadow)]",children:['"claude-*": "',(d.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),L.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:a("providers.drawer.defaultHint",{model:d.defaultModel||a("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden min-h-0 overflow-y-auto border-l border-border/45 bg-secondary/40 px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:ne}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:X.map(r=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:r.label}),e.jsx("span",{className:"text-right font-medium",children:r.value})]},r.label))})]}),e.jsxs("div",{className:"rounded-xl border border-transparent bg-card p-4 shadow-[var(--surface-shadow)]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:a("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:a("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:a("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:a("providers.drawer.hints.checkModels")})]})]}),v&&e.jsxs("div",{className:"rounded-xl bg-accent p-4 text-sm text-foreground",children:[e.jsx("p",{className:"font-medium text-primary",children:a("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:a("providers.drawer.hints.advancedBody")})]})]})})]}),e.jsxs("footer",{className:"flex items-center justify-between gap-3 border-t border-border/45 bg-secondary/45 px-6 py-4 text-sm backdrop-blur-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-destructive","aria-live":"polite",children:A?e.jsx("span",{children:A}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(h,{type:"button",variant:"outline",onClick:x,disabled:k,className:"bg-card",children:a("common.actions.cancel")}),e.jsx(h,{type:"button",onClick:ve,disabled:k,children:a(k?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}function or(){const{t:l}=U(),s=Pe();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Ce,{info:e.jsx("span",{className:"rounded-full bg-secondary px-2.5 py-1 text-xs text-muted-foreground",children:l("providers.count",{count:s.providerCount})}),actions:e.jsxs(e.Fragment,{children:[e.jsx(h,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs(Se,{to:"/routing",children:[l("nav.routing"),e.jsx(Me,{className:"h-4 w-4","aria-hidden":"true"})]})}),e.jsx(h,{size:"sm",onClick:s.handleOpenCreate,children:l("providers.actions.add")})]})}),e.jsx(Ve,{configPending:s.configQuery.isPending||!s.config&&s.configQuery.isFetching,defaultLabels:s.defaultLabels,filteredProviders:s.filteredProviders,onOpenEdit:s.handleOpenEdit,onRequestDelete:c=>s.setConfirmAction({kind:"provider",provider:c}),onResetFilters:()=>{s.setProviderSearch(""),s.setProviderTypeFilter("all")},onProviderSearchChange:s.setProviderSearch,onProviderTypeChange:s.setProviderTypeFilter,onTestConnection:s.initiateTestConnection,providerSearch:s.providerSearch,providerTypeFilter:s.providerTypeFilter,providersLength:s.providers.length,testingProviderId:s.testingProviderId}),e.jsx(Be,{open:s.drawerOpen,mode:s.drawerMode,provider:s.drawerMode==="edit"?s.editingProvider:void 0,existingProviderIds:s.providers.map(c=>c.id).filter(c=>s.drawerMode==="edit"&&s.editingProvider?c!==s.editingProvider.id:!0),onClose:()=>{s.setDrawerOpen(!1),s.setEditingProvider(void 0),s.setDrawerMode("create")},onSubmit:s.handleProviderSubmit}),e.jsx(Ke,{open:s.testDialogOpen,provider:s.testDialogProvider,options:s.anthropicTestHeaderOptions,preservedExtras:s.testDialogPreservedExtras,usePreset:s.testDialogUsePreset,onPresetChange:s.setTestDialogUsePreset,onConfirm:s.confirmTestDialog,onClose:s.closeTestDialog}),e.jsx(Ee,{open:!!s.noModelDialogProvider,provider:s.noModelDialogProvider,onClose:()=>s.setNoModelDialogProvider(null),onEdit:c=>{s.setNoModelDialogProvider(null),s.handleOpenEdit(c)}}),e.jsx(De,{open:!!s.confirmAction,onOpenChange:c=>{!c&&!s.confirmingAction&&s.setConfirmAction(null)},title:s.confirmDialogTitle,description:s.confirmDialogDescription,confirmLabel:s.confirmingAction?l("common.actions.loading"):l("common.delete"),cancelLabel:l("common.actions.cancel"),loading:s.confirmingAction,onConfirm:s.handleConfirmDialog,children:s.confirmDialogName?e.jsx("div",{className:"rounded-xl border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:s.confirmDialogName}):null})]})}export{or as default};