@chenpu17/cc-gw 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +5 -5
- package/src/web/dist/assets/About-CTbbI3Xf.js +1 -0
- package/src/web/dist/assets/ApiKeys-Dca6MyO2.js +1 -0
- package/src/web/dist/assets/ConfirmDialog-DW7jBfm1.js +1 -0
- package/src/web/dist/assets/Dashboard-DMo-YHgS.js +1 -0
- package/src/web/dist/assets/{DialogShell-CavDTyu2.js → DialogShell-BqzUE3vU.js} +1 -1
- package/src/web/dist/assets/EChart-VRAvk6sX.js +1 -0
- package/src/web/dist/assets/{Events-CWJ2CJGy.js → Events-19qjsHJf.js} +1 -1
- package/src/web/dist/assets/{Help-DCOvIIDL.js → Help-FrXAXPhx.js} +1 -1
- package/src/web/dist/assets/{Login-DEMouEmI.js → Login-BYpsX-S8.js} +1 -1
- package/src/web/dist/assets/{Logs-3htB3A1j.js → Logs-ynLMNHgv.js} +1 -1
- package/src/web/dist/assets/ModelManagement-DrE_4kky.js +1 -0
- package/src/web/dist/assets/{PageHeader-Cq6w1STo.js → PageHeader-DDxjKW4B.js} +1 -1
- package/src/web/dist/assets/{PageSection-B59UM5tv.js → PageSection-DRyQEnmK.js} +1 -1
- package/src/web/dist/assets/{PageState-yC3iG0kI.js → PageState-DA98vXl7.js} +1 -1
- package/src/web/dist/assets/{Profiler-Bmr0aJGd.js → Profiler-D5P7FF0I.js} +1 -1
- package/src/web/dist/assets/Settings-D8Xgk7cH.js +1 -0
- package/src/web/dist/assets/{Skeleton-UxsX1sQ2.js → Skeleton-D_opZxQ7.js} +1 -1
- package/src/web/dist/assets/{badge-Dc9FIO0F.js → badge-B-TfGxGB.js} +1 -1
- package/src/web/dist/assets/{card-DIJGGwlM.js → card-I07afQF2.js} +1 -1
- package/src/web/dist/assets/{charts-core-vuhzGmuT.js → charts-core-C-3-Lo7l.js} +1 -1
- package/src/web/dist/assets/{charts-engine-BJQRnjQ_.js → charts-engine-BI1CmRJo.js} +1 -1
- package/src/web/dist/assets/{charts-react-BeVWPrMt.js → charts-react-DJ_0LNAP.js} +1 -1
- package/src/web/dist/assets/{gateway-UFtwEtkS.js → gateway-CkqHb_VE.js} +1 -1
- package/src/web/dist/assets/{i18n-CfLThlXq.js → i18n-C7VVFIdN.js} +1 -1
- package/src/web/dist/assets/index-CYeQpt9d.js +61 -0
- package/src/web/dist/assets/{input-lCtJklC0.js → input-DZMeIHxj.js} +1 -1
- package/src/web/dist/assets/{label-D1KIrtqS.js → label-DZr7itdg.js} +1 -1
- package/src/web/dist/assets/{popover-fTDjRCAd.js → popover-_LyL4tgU.js} +1 -1
- package/src/web/dist/assets/{query-D3IfCUhp.js → query-DxhDvnDC.js} +1 -1
- package/src/web/dist/assets/{radix-54BMi3RD.js → radix-CmyU-WBH.js} +1 -1
- package/src/web/dist/assets/{router-CmaL1NgV.js → router-D8u_RlVh.js} +1 -1
- package/src/web/dist/assets/{select-Bz0SzVLn.js → select-BUvJR07s.js} +1 -1
- package/src/web/dist/assets/{switch-up8rp8CD.js → switch-BpfcwR9i.js} +1 -1
- package/src/web/dist/assets/{useApiQuery-6NxamWaA.js → useApiQuery-BzbOtl4s.js} +1 -1
- package/src/web/dist/assets/useAppMutation-D8Mjcv9t.js +1 -0
- package/src/web/dist/assets/{vendor-CjJPKsTb.js → vendor-5iCEqDpV.js} +1 -1
- package/src/web/dist/index.html +6 -6
- package/src/web/dist/assets/About-ant07Da6.js +0 -1
- package/src/web/dist/assets/ApiKeys-C9gBxswL.js +0 -1
- package/src/web/dist/assets/Dashboard-B6M0SSmJ.js +0 -1
- package/src/web/dist/assets/EChart-Dqa_Xbrn.js +0 -1
- package/src/web/dist/assets/ModelManagement-CLq-Inin.js +0 -1
- package/src/web/dist/assets/Settings-BJvmyAD8.js +0 -1
- package/src/web/dist/assets/index-BSYfa5CS.js +0 -61
- package/src/web/dist/assets/useAppMutation-BxKJOVAx.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as g,j as e,ak as Be,al as We,a8 as Ge,am as Je,aj as Xe,V as Ze,T as Ye}from"./vendor-CjJPKsTb.js";import{P as et}from"./PageHeader-Cq6w1STo.js";import{c as w,B as E,b as tt,u as ge,s as _,t as st,a as R}from"./index-BSYfa5CS.js";import{B as K}from"./badge-Dc9FIO0F.js";import{C as _e,a as Ee}from"./card-DIJGGwlM.js";import{I as ue}from"./input-lCtJklC0.js";import{L as I}from"./label-D1KIrtqS.js";import{S as ee,a as te,b as se,c as le,d as L}from"./select-Bz0SzVLn.js";import{u as M}from"./i18n-CfLThlXq.js";import{D as lt,A as at,a as rt,b as ot,c as it,d as nt}from"./DialogShell-CavDTyu2.js";import{P as dt,a as xe}from"./PageState-yC3iG0kI.js";import{c as ct}from"./clipboard-CALi6bTW.js";import{u as $}from"./useApiQuery-6NxamWaA.js";import{q as U}from"./queryKeys-BMvyDTQS.js";import{f as O,a as De,b as mt,c as z,d as pt,g as ut}from"./utils-DQfq7gRo.js";import{P as xt,a as gt,b as ht}from"./popover-fTDjRCAd.js";import{T as ft}from"./Skeleton-UxsX1sQ2.js";import{g as Se}from"./gateway-UFtwEtkS.js";import"./query-D3IfCUhp.js";import"./router-CmaL1NgV.js";import"./radix-54BMi3RD.js";function bt({apiKeys:l,selected:t,onChange:o,disabled:n,className:d}){const{t:s}=M(),[r,h]=g.useState(!1),c=g.useRef(null);g.useEffect(()=>{if(!r)return;const i=a=>{var p;(p=c.current)!=null&&p.contains(a.target)||h(!1)};return window.addEventListener("mousedown",i),()=>window.removeEventListener("mousedown",i)},[r]);const v=g.useMemo(()=>{if(t.length===0)return[];const i=new Map;for(const a of l)i.set(a.id,a);return t.map(a=>{const p=i.get(a);return p?p.isWildcard?s("apiKeys.wildcard"):p.name:null}).filter(a=>!!a)},[l,t,s]),u=t.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:t.length}),j=i=>{t.includes(i)?o(t.filter(a=>a!==i)):o([...t,i])};return e.jsxs("div",{className:w("relative space-y-2",d),ref:c,children:[e.jsx(I,{children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>h(i=>!i),disabled:n||l.length===0,title:s("logs.filters.apiKeyHint"),className:w("flex h-10 w-full items-center justify-between rounded-md 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:[u,v.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:v.join(", ")})]}),e.jsx("svg",{className:w("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&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-md border bg-popover p-2 shadow-md",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-secondary px-3 py-2 text-xs",children:[e.jsx("span",{children:u}),e.jsx("button",{type:"button",onClick:()=>o([]),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(i=>{const a=i.isWildcard?s("apiKeys.wildcard"):i.name,p=t.includes(i.id);return e.jsxs("label",{className:w("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",p&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:p,onChange:()=>j(i.id)}),e.jsx("span",{className:"truncate",children:a})]},i.id)}),l.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:s("logs.filters.apiKeyAll")})]})]})]})}function yt(l){const{t}=M(),{total:o,activeFilters:n,filtersExpanded:d,setFiltersExpanded:s,handleResetFilters:r,activeQuickView:h,applyQuickView:c,providerFilter:v,setProviderFilter:u,endpointFilter:j,setEndpointFilter:i,selectedApiKeys:a,setSelectedApiKeys:p,modelFilter:f,setModelFilter:S,statusFilter:b,setStatusFilter:D,fromDate:C,setFromDate:T,toDate:N,setToDate:y,providerOptions:B,apiKeys:re,apiKeysLoading:oe,customEndpoints:W}=l;return e.jsx(_e,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(Ee,{className:"pt-4",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:t("logs.filtersTitle")}),e.jsx(K,{variant:"outline",children:t("logs.summary.total",{value:o.toLocaleString()})}),n.length>0&&e.jsx(K,{variant:"secondary",children:t("common.filters.activeCount",{count:n.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n.length>0&&e.jsx(E,{variant:"ghost",size:"sm",onClick:r,children:t("common.actions.reset")}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>s(x=>!x),children:d?e.jsxs(e.Fragment,{children:[t("common.filters.collapse"),e.jsx(Be,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[t("common.filters.expand"),e.jsx(We,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"flex min-h-[52px] items-center rounded-lg border border-border bg-secondary px-3 py-2",children:n.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(x=>e.jsxs(K,{variant:"secondary",role:"button",tabIndex:0,className:"cursor-pointer gap-1 border border-transparent bg-primary/10 text-primary hover:bg-destructive/10 hover:text-destructive",onClick:x.onRemove,onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),x.onRemove())},children:[x.label,e.jsx(Ge,{className:"h-3 w-3","aria-hidden":"true"})]},x.key))}):e.jsx("span",{className:"text-sm text-muted-foreground",children:t("common.filters.allRequests")})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4 lg:min-w-[360px]",children:[e.jsx(Y,{label:t("common.filters.activeCount",{count:n.length}),value:n.length.toString()}),e.jsx(Y,{label:t("logs.filters.apiKey"),value:a.length.toString()}),e.jsx(Y,{label:t("logs.filters.provider"),value:v==="all"?t("common.noData"):"1"}),e.jsx(Y,{label:t("logs.filters.endpoint"),value:j==="all"?t("common.noData"):"1"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border border-border bg-secondary p-2",children:["all","errors","today","anthropic","openai"].map(x=>e.jsx(E,{variant:h===x?"default":"outline",size:"sm",className:w("rounded-full border-transparent",h===x&&x==="all"&&"bg-foreground text-background hover:bg-foreground/90",h===x&&x==="errors"&&"bg-rose-500 text-white hover:bg-rose-500/90",h===x&&x==="today"&&"bg-emerald-500 text-white hover:bg-emerald-500/90",h===x&&(x==="anthropic"||x==="openai")&&"bg-amber-500 text-white hover:bg-amber-500/90"),onClick:()=>c(x),children:t(`logs.quickViews.${x}`)},x))})]}),d&&e.jsxs("div",{className:"mt-4 grid gap-4 rounded-lg border border-border bg-secondary p-4 md:grid-cols-2 xl:grid-cols-4 animate-in fade-in slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.provider")}),e.jsxs(ee,{value:v,onValueChange:u,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.providerAll")}),B.map(x=>e.jsx(L,{value:x.id,children:x.label??x.id},x.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endpoint")}),e.jsxs(ee,{value:j,onValueChange:i,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.endpointAll")}),e.jsx(L,{value:"anthropic",children:t("logs.filters.endpointAnthropic")}),e.jsx(L,{value:"openai",children:t("logs.filters.endpointOpenAI")}),W==null?void 0:W.map(x=>e.jsx(L,{value:x.id,children:x.label||x.id},x.id))]})]})]}),e.jsx(bt,{className:"md:col-span-2",apiKeys:re,selected:a,disabled:oe,onChange:p}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.modelId")}),e.jsx(ue,{value:f,onChange:x=>S(x.target.value),placeholder:t("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.status")}),e.jsxs(ee,{value:b,onValueChange:x=>D(x),children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.statusAll")}),e.jsx(L,{value:"success",children:t("logs.filters.statusSuccess")}),e.jsx(L,{value:"error",children:t("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.startDate")}),e.jsx(ue,{type:"date",value:C,onChange:x=>T(x.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endDate")}),e.jsx(ue,{type:"date",value:N,onChange:x=>y(x.target.value)})]})]})]})})}function Y({label:l,value:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-3 py-2",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:l}),e.jsx("p",{className:"mt-1 text-sm 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 o=await tt.post("/api/logs/export",l,{responseType:"blob",timeout:t});return new Blob([o.data],{type:"application/zip"})}};function jt({apiKeyMap:l,logId:t,open:o,providerLabelMap:n}){var i;const{t:d}=M(),{pushToast:s}=ge(),r=$(U.logs.detail(t),he.detailRequest(t),{enabled:o&&t!==null,staleTime:3e4});g.useEffect(()=>{!r.isError||!r.error||s({title:d("logs.detail.loadError"),description:r.error.message,variant:"error"})},[r.error,r.isError,s,d]);const h=g.useCallback(async(a,p,f)=>{if(!p){s({title:d("logs.detail.copy.empty",{label:a}),variant:"info"});return}try{await ct(p),s({title:d(f),variant:"success"})}catch(S){s({title:d("logs.detail.copy.failure"),description:S instanceof Error?S.message:d("logs.detail.copy.failureFallback"),variant:"error"})}},[s,d]),c=r.data,v=c?n.get(c.provider)??c.provider:"",u=c&&c.api_key_id!=null?l.get(c.api_key_id):void 0,j=c?c.status_code??(c.error?500:200):null;return{apiKeyMeta:u,errorMessage:r.isError?((i=r.error)==null?void 0:i.message)??null:null,handleCopy:h,isError:r.isError,isPending:r.isPending,providerLabel:v,refetch:r.refetch,record:c,statusCode:j}}function vt({open:l,logId:t,onClose:o,providerLabelMap:n,apiKeyMap:d}){var S,b,D,C,T,N;const{t:s}=M(),{apiKeyMeta:r,errorMessage:h,handleCopy:c,isError:v,isPending:u,providerLabel:j,refetch:i,record:a,statusCode:p}=jt({apiKeyMap:d,logId:t,open:l,providerLabelMap:n}),f=a?[{key:"client-request",title:s("logs.detail.payload.clientRequest"),value:((S=a.payload)==null?void 0:S.client_request)??null,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(b=a.payload)!=null&&b.upstream_request?[{key:"upstream-request",title:s("logs.detail.payload.upstreamRequest"),value:a.payload.upstream_request,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}]:[],...(D=a.payload)!=null&&D.upstream_response?[{key:"upstream-response",title:s("logs.detail.payload.upstreamResponse"),value:a.payload.upstream_response,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[],{key:"client-response",title:s("logs.detail.payload.clientResponse"),value:((C=a.payload)==null?void 0:C.client_response)??null,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[];return e.jsx(lt,{open:l,onOpenChange:y=>{y||o()},children:e.jsxs(at,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(rt,{className:"pr-14",children:[e.jsx(ot,{children:s("logs.detail.title")}),e.jsx(it,{children:a?s("logs.detail.id",{id:a.id}):s("logs.detail.loadError")})]}),e.jsx(nt,{className:"max-h-[78vh]",children:u?e.jsx(dt,{compact:!0,className:"min-h-[240px]",label:s("common.loading")}):v?e.jsx(xe,{compact:!0,className:"min-h-[240px]",tone:"danger",title:s("logs.detail.loadError"),description:h??s("common.unknownError"),action:e.jsx(E,{variant:"outline",onClick:()=>void i(),children:s("common.actions.refresh")})}):a?e.jsxs("div",{className:"space-y-6 text-sm",children:[e.jsxs("section",{className:"space-y-4 rounded-lg border border-border bg-card p-5",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 border-border bg-secondary p-3 text-xs",children:[e.jsx("span",{className:"font-medium",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-muted-foreground",children:s("logs.detail.summary.latency",{value:O(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",O(a.ttft_ms,s("common.units.ms"))]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(K,{variant:a.error?"destructive":"default",children:p==null?void 0:p.toString()}),e.jsx(K,{variant:"outline",children:a.stream?s("logs.stream.streaming"):s("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(A,{label:s("logs.detail.info.latency"),value:O(a.latency_ms,s("common.units.ms"))}),e.jsx(A,{label:s("logs.detail.info.ttft"),value:O(a.ttft_ms,s("common.units.ms"))}),e.jsx(A,{label:s("logs.detail.info.tpot"),value:O(a.tpot_ms,s("common.units.msPerToken"))}),e.jsx(A,{label:s("logs.detail.info.status"),value:(p==null?void 0:p.toString())??"-"})]}),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:De(a.timestamp)}),e.jsx(F,{label:s("logs.detail.info.sessionId"),value:a.session_id??"-"}),e.jsx(F,{label:s("logs.detail.info.endpoint"),value:a.endpoint||"-"}),e.jsx(F,{label:s("logs.detail.info.provider"),value:j}),e.jsx(F,{label:s("logs.detail.info.requestedModel"),value:a.client_model??s("logs.detail.info.noRequestedModel")}),e.jsx(F,{label:s("logs.detail.info.model"),value:a.model}),e.jsx(F,{label:s("logs.detail.info.stream"),value:mt(a.stream)}),e.jsx(F,{label:s("logs.detail.info.status"),value:p})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(A,{label:s("logs.detail.info.inputTokens"),value:z(a.input_tokens)}),e.jsx(A,{label:s("logs.detail.info.cacheReadTokens"),value:z(a.cache_read_tokens)}),e.jsx(A,{label:s("logs.detail.info.cacheCreationTokens"),value:z(a.cache_creation_tokens)}),e.jsx(A,{label:s("logs.detail.info.outputTokens"),value:z(a.output_tokens)})]}),a.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-[1rem] border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:a.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 border-border bg-card p-5",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:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.name)??a.api_key_name??s("logs.detail.apiKey.missing")}),e.jsx(F,{label:s("logs.detail.apiKey.identifier"),value:a.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)??a.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 border-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:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-4 rounded-lg border border-border bg-card p-5",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:(T=a.payload)!=null&&T.upstream_request||(N=a.payload)!=null&&N.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(y=>e.jsx(Nt,{title:y.title,value:y.value,emptyLabel:y.emptyLabel,onCopy:()=>c(y.title,y.value,y.copyToast),t:s},y.key))})]})]})]}):e.jsx(xe,{compact:!0,className:"min-h-[240px]",title:s("logs.detail.loadError"),description:s("common.noData")})})]})})}function A({label:l,value:t}){return e.jsxs("div",{className:"min-w-0 rounded-lg border border-border bg-secondary px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] 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 Nt({emptyLabel:l,onCopy:t,title:o,value:n,t:d}){return e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary/40 p-4",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:o}),e.jsx(E,{variant:"outline",size:"sm",onClick:t,children:d("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap rounded-lg border border-border bg-secondary p-3 text-xs",children:pt(n,l)})]})}const H=[20,50,100],Q=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"],ae=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function wt(){if(typeof window>"u")return Q;try{const l=window.localStorage.getItem(_.logs.visibleColumns);if(!l)return Q;const t=JSON.parse(l);if(!Array.isArray(t))return Q;const o=t.filter(n=>ae.includes(n));return o.length>0?o:Q}catch{return Q}}function kt(){return typeof window>"u"?"comfortable":window.localStorage.getItem(_.logs.density)==="compact"?"compact":"comfortable"}function St(){if(typeof window>"u")return H[0];const l=window.localStorage.getItem(_.logs.pageSize),t=Number(l);return H.includes(t)?t:H[0]}function Ct(){if(typeof window>"u")return[];try{const l=window.localStorage.getItem(_.logs.selectedApiKeys);if(!l)return[];const t=JSON.parse(l);return Array.isArray(t)?t.map(o=>Number(o)).filter(o=>Number.isInteger(o)&&o>0):[]}catch{return[]}}function Ce(l,t=!1){if(!l)return;const o=t?`${l}T23:59:59.999`:`${l}T00:00:00.000`,n=Date.parse(o);return Number.isFinite(n)?n:void 0}function _t(l,t,o){return l===o&&t===o}function Et({columnOptions:l,exporting:t,onExport:o,onRefresh:n,onResetColumns:d,onSetDensity:s,onToggleColumn:r,refreshing:h,rowDensity:c,total:v,visibleColumns:u,visibleColumnSet:j}){const{t:i}=M(),a=JSON.stringify(u)===JSON.stringify(Q);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 border border-border bg-secondary p-1 sm:w-auto",children:[e.jsx("button",{type:"button",onClick:()=>s("comfortable"),className:w("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",c==="comfortable"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:i("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>s("compact"),className:w("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",c==="compact"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:i("logs.table.density.compact")})]}),e.jsxs(xt,{children:[e.jsx(gt,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:i("logs.actions.columns")})}),e.jsxs(ht,{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:i("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("logs.actions.visibleCount",{count:u.length})})]}),e.jsx(E,{variant:"ghost",size:"sm",onClick:d,disabled:a,children:i("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(p=>{const f=j.has(p.id);return e.jsxs("label",{className:w("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",f&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:f,onChange:()=>r(p.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:p.label})]},p.id)})})]})]}),e.jsxs(E,{onClick:o,disabled:t,className:"w-full sm:w-auto",children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),i(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:i("logs.summary.total",{value:v.toLocaleString()})}),e.jsxs(E,{variant:"outline",size:"sm",onClick:n,disabled:h,className:"shrink-0",children:[e.jsx(Xe,{className:w("mr-2 h-4 w-4",h&&"animate-spin")}),i(h?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function Dt({record:l,providerLabelMap:t,apiKeyMap:o,onSelect:n,isEven:d,density:s,visibleColumnSet:r}){const{t:h}=M(),c=t.get(l.provider)??l.provider,v=l.endpoint||"-",u=!!l.error,j=l.status_code,i=l.client_model??h("logs.table.requestedModelFallback"),a=l.api_key_id!=null?o.get(l.api_key_id):void 0,p=l.api_key_id==null?h("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?h("apiKeys.wildcard"):a!=null&&a.name?a.name:l.api_key_name?l.api_key_name:h("logs.table.apiKeyUnknown"),f=s==="compact"?"px-3 py-1.5":"px-3 py-2",S=d?"bg-muted/30":"bg-background",b=ut(l.session_id),D=b==null?void 0:b.rowStyle,C=b==null?void 0:b.stickyStyle,T=b?{...b.stickyStyle,...b.accentStyle}:void 0;return e.jsxs("tr",{"data-session-id":b==null?void 0:b.sessionId,"data-session-color":b==null?void 0:b.colorKey,className:w("transition-colors",b?"":d?"bg-muted/30":"",b?"":"hover:bg-muted/50"),style:D,onMouseEnter:N=>{b&&Object.assign(N.currentTarget.style,b.hoverStyle)},onMouseLeave:N=>{b&&Object.assign(N.currentTarget.style,b.rowStyle)},children:[e.jsx("td",{className:w("sticky left-0 z-10 text-xs",f,b?"":S),style:T,children:De(l.timestamp)}),r.has("endpoint")&&e.jsx("td",{className:w(f,"text-xs"),children:v}),r.has("provider")&&e.jsx("td",{className:w(f,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:c,children:c})}),r.has("requestedModel")&&e.jsx("td",{className:w(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:i,children:i})}),r.has("routedModel")&&e.jsx("td",{className:w(f,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:l.model,children:l.model})}),r.has("apiKey")&&e.jsx("td",{className:w(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:p,children:p})}),r.has("inputTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.input_tokens)}),r.has("cacheReadTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.cache_read_tokens)}),r.has("cacheCreationTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.cache_creation_tokens)}),r.has("outputTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.output_tokens)}),r.has("latency")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.latency_ms,"ms")}),r.has("ttft")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.ttft_ms,"ms")}),r.has("tpot")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.tpot_ms,"ms/tk")}),r.has("status")&&e.jsx("td",{className:w(f,"text-center"),children:e.jsx(K,{variant:u?"destructive":"default",className:"text-xs",children:j??(u?500:200)})}),r.has("error")&&e.jsx("td",{className:w(f,"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:w("sticky right-0 z-10 text-center",f,b?"":S),style:C,children:e.jsx(E,{variant:"outline",size:"sm",onClick:()=>n(l.id),children:h("logs.actions.detail")})})]})}function Ft(l){const{t}=M(),{tableScrollRef:o,visibleColumnSet:n,visibleColumnCount:d,logsError:s,logsPending:r,items:h,activeFiltersCount:c,handleResetFilters:v,handleRetry:u,providerLabelMap:j,apiKeyMap:i,handleOpenDetail:a,rowDensity:p,showScrollHint:f,pageSize:S,setPageSize:b,page:D,totalPages:C,setPage:T}=l;return e.jsx(_e,{className:"overflow-hidden",children:e.jsxs(Ee,{className:"p-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-border bg-secondary px-4 py-3",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(K,{variant:"secondary",children:"Wide Table"}),e.jsx(K,{variant:"outline",children:t(p==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),f?e.jsx(K,{variant:"outline",className:"border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-300",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:o,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1480px] text-sm",children:[e.jsx("thead",{className:"border-b bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-muted/95 px-3 py-2 text-left text-xs font-medium backdrop-blur",children:t("logs.table.columns.time")}),n.has("endpoint")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.endpoint")}),n.has("provider")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.provider")}),n.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.requestedModel")}),n.has("routedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.routedModel")}),n.has("apiKey")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.apiKey")}),n.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.inputTokens")}),n.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.cacheReadTokens")}),n.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.cacheCreationTokens")}),n.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.outputTokens")}),n.has("latency")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.latency")}),n.has("ttft")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.ttft")}),n.has("tpot")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.tpot")}),n.has("status")&&e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:t("logs.table.columns.status")}),n.has("error")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-muted/95 px-3 py-2 text-center text-xs font-medium backdrop-blur",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:r?Array.from({length:8}).map((N,y)=>e.jsx(ft,{columns:d},y)):s&&h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-6",children:e.jsx(xe,{compact:!0,tone:"danger",icon:e.jsx(Ze,{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(E,{variant:"outline",size:"sm",onClick:u,children:t("common.actions.refresh")}),c>0?e.jsx(E,{variant:"ghost",size:"sm",onClick:v,children:t("common.actions.reset")}):null]})})})}):h.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.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[e.jsx("span",{children:t("logs.table.empty")}),c>0&&e.jsx(E,{variant:"outline",size:"sm",onClick:v,children:t("common.actions.reset")})]})})}):h.map((N,y)=>e.jsx(Dt,{record:N,providerLabelMap:j,apiKeyMap:i,onSelect:a,isEven:y%2===0,density:p,visibleColumnSet:n},N.id))})]})}),f&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 border-t p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.perPage")}),e.jsxs(ee,{value:S.toString(),onValueChange:N=>b(Number(N)),children:[e.jsx(te,{className:"w-[80px]",children:e.jsx(se,{})}),e.jsx(le,{children:H.map(N=>e.jsx(L,{value:N.toString(),children:N},N))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",onClick:()=>T(N=>Math.max(N-1,1)),disabled:D<=1,children:t("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.pageLabel",{page:C===0?0:D,total:C})}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>T(N=>C===0?N:Math.min(N+1,C)),disabled:C===0||D>=C,children:t("logs.table.pagination.next")})]})]})]})})}function Tt({exportTimeoutMs:l,queryParams:t,total:o}){const{t:n}=M(),{pushToast:d}=ge(),[s,r]=g.useState(!1),h=g.useCallback(async()=>{if(!s){r(!0);try{const c=o>0?Math.min(o,5e3):1e3,v={...t,limit:c,offset:0},u=await he.exportArchive(v,l),j=new Date().toISOString().replace(/[:.]/g,"-"),i=URL.createObjectURL(u),a=document.createElement("a");a.href=i,a.download=`cc-gw-logs-${j}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i),d({title:n("logs.toast.exportSuccess.title"),description:n("logs.toast.exportSuccess.desc"),variant:"success"})}catch(c){const v=st(c);d({title:n("logs.toast.exportError.title"),description:n("logs.toast.exportError.desc",{message:v.message}),variant:"error"})}finally{r(!1)}}},[l,s,d,t,n,o]);return{exporting:s,handleExport:h}}function Rt(){const l=g.useRef(null),[t,o]=g.useState(!1),n=g.useCallback(()=>{const d=l.current;if(!d)return;const s=d.scrollWidth-d.scrollLeft-d.clientWidth>1;o(s)},[]);return g.useEffect(()=>{const d=l.current;if(!d)return;n(),d.addEventListener("scroll",n,{passive:!0});const s=new ResizeObserver(n);return s.observe(d),()=>{d.removeEventListener("scroll",n),s.disconnect()}},[n]),{scrollRef:l,showScrollHint:t,updateScrollHint:n}}function Lt(){const[l,t]=R(_.logs.density,kt,{serialize:u=>u,deserialize:u=>u==="compact"?"compact":"comfortable"}),[o,n]=R(_.logs.visibleColumns,wt),{scrollRef:d,showScrollHint:s}=Rt(),r=g.useMemo(()=>new Set(o),[o]),h=o.length+2,c=g.useCallback(u=>{n(j=>{if(j.includes(u))return j.length===1?j:j.filter(a=>a!==u);const i=[...j,u];return i.sort((a,p)=>ae.indexOf(a)-ae.indexOf(p)),i})},[]);return{resetVisibleColumns:g.useCallback(()=>{n(Q)},[]),rowDensity:l,setRowDensity:t,showScrollHint:s,tableScrollRef:d,toggleColumn:c,visibleColumnCount:h,visibleColumns:o,visibleColumnSet:r}}function Mt(){var je,ve,Ne,we,ke;const{t:l}=M(),{pushToast:t}=ge(),[o,n]=R(_.logs.providerFilter,"all"),[d,s]=R(_.logs.endpointFilter,"all"),[r,h]=R(_.logs.modelFilter,""),[c,v]=R(_.logs.statusFilter,"all"),[u,j]=R(_.logs.fromDate,""),[i,a]=R(_.logs.toDate,""),[p,f]=g.useState(1),[S,b]=R(_.logs.pageSize,St,{serialize:m=>String(m),deserialize:m=>{const k=Number(m);return H.includes(k)?k:H[0]}}),[D,C]=g.useState(null),[T,N]=g.useState(!1),[y,B]=R(_.logs.selectedApiKeys,Ct),[re,oe]=R(_.logs.filtersExpanded,!1),{resetVisibleColumns:W,rowDensity:x,setRowDensity:G,showScrollHint:Fe,tableScrollRef:Te,toggleColumn:Re,visibleColumnCount:Le,visibleColumns:Me,visibleColumnSet:Ke}=Lt();g.useEffect(()=>{f(1)},[o,d,r,c,u,i,S,y]);const ie=g.useMemo(()=>{const m={limit:S,offset:(p-1)*S};o!=="all"&&(m.provider=o),d!=="all"&&(m.endpoint=d),r.trim().length>0&&(m.model=r.trim()),c!=="all"&&(m.status=c);const k=Ce(u),q=Ce(i,!0);return k!==void 0&&(m.from=k),q!==void 0&&(m.to=q),y.length>0&&(m.apiKeys=y.join(",")),m},[d,u,r,p,S,o,y,c,i]),P=$(U.logs.list(ie),he.listRequest(ie)),V=$(U.providers.all(),Se.providersRequest()),fe=$(U.apiKeys.all(),{url:"/api/keys",method:"GET"}),ne=$(U.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),be=$(U.config.exportTimeout(),Se.configRequest());g.useEffect(()=>{!P.isError||!P.error||t({title:l("logs.toast.listError.title"),description:l("logs.toast.listError.desc",{message:P.error.message}),variant:"error"})},[P.error,P.isError,t,l]),g.useEffect(()=>{!V.isError||!V.error||t({title:l("logs.toast.providerError.title"),description:l("logs.toast.providerError.desc",{message:V.error.message}),variant:"error"})},[V.error,V.isError,t,l]);const Z=((je=P.data)==null?void 0:je.total)??0,J=Z>0?Math.ceil(Z/S):0,Pe=((ve=P.data)==null?void 0:ve.items)??[],Ae=g.useMemo(()=>{var k;const m=(k=be.data)==null?void 0:k.logExportTimeoutSeconds;return typeof m=="number"&&Number.isFinite(m)?Math.min(Math.max(Math.round(m),5),600)*1e3:6e4},[(Ne=be.data)==null?void 0:Ne.logExportTimeoutSeconds]);g.useEffect(()=>{J>0&&p>J&&f(J)},[p,J]);const de=V.data??[],ce=g.useMemo(()=>{const m=new Map;for(const k of de)k.id&&m.set(k.id,k.label??k.id);return m},[de]),ye=g.useMemo(()=>{var k;const m=new Map;m.set("anthropic",l("logs.filters.endpointAnthropic")),m.set("openai",l("logs.filters.endpointOpenAI"));for(const q of((k=ne.data)==null?void 0:k.endpoints)??[])m.set(q.id,q.label||q.id);return m},[(we=ne.data)==null?void 0:we.endpoints,l]),Oe=g.useMemo(()=>{const m=[];if(o!=="all"){const k=ce.get(o)??o;m.push({key:"provider",label:`${l("logs.filters.provider")}: ${k}`,onRemove:()=>n("all")})}if(d!=="all"){const k=ye.get(d)??d;m.push({key:"endpoint",label:`${l("logs.filters.endpoint")}: ${k}`,onRemove:()=>s("all")})}if(r.trim()&&m.push({key:"model",label:`${l("logs.filters.modelId")}: ${r.trim()}`,onRemove:()=>h("")}),c!=="all"){const k=l(c==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");m.push({key:"status",label:`${l("logs.filters.status")}: ${k}`,onRemove:()=>v("all")})}return u&&m.push({key:"from",label:`${l("logs.filters.startDate")}: ${u}`,onRemove:()=>j("")}),i&&m.push({key:"to",label:`${l("logs.filters.endDate")}: ${i}`,onRemove:()=>a("")}),y.length>0&&m.push({key:"apiKeys",label:l("logs.filters.apiKeySelected",{count:y.length}),onRemove:()=>B([])}),m},[d,ye,u,r,o,ce,y.length,c,l,i]),me=fe.data??[],ze=g.useMemo(()=>{const m=new Map;for(const k of me)m.set(k.id,k);return m},[me]),qe=g.useMemo(()=>ae.map(m=>({id:m,label:l(`logs.table.columns.${m}`)})),[l]),X=g.useMemo(()=>new Date().toISOString().slice(0,10),[]),Ie=g.useMemo(()=>o==="all"&&d==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"all":c==="error"&&d==="all"&&o==="all"&&r.trim()===""&&u===""&&i===""&&y.length===0?"errors":_t(u,i,X)&&d==="all"&&o==="all"&&r.trim()===""&&c==="all"&&y.length===0?"today":d==="anthropic"&&o==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"anthropic":d==="openai"&&o==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"openai":null,[d,u,r,o,y.length,c,i,X]),pe=g.useCallback(()=>{n("all"),h(""),s("all"),v("all"),j(""),a(""),B([])},[]),Qe=g.useCallback(m=>{if(f(1),pe(),m!=="all"){if(m==="errors"){v("error");return}if(m==="today"){j(X),a(X);return}if(m==="anthropic"){s("anthropic");return}m==="openai"&&s("openai")}},[pe,X]),{exporting:Ve,handleExport:$e}=Tt({exportTimeoutMs:Ae,queryParams:ie,total:Z}),Ue=g.useCallback(m=>{C(m),N(!0)},[]),He=g.useCallback(()=>{N(!1),C(null)},[]);return{activeFilters:Oe,activeQuickView:Ie,apiKeyMap:ze,apiKeys:me,apiKeysQuery:fe,applyQuickView:Qe,columnOptions:qe,customEndpoints:(ke=ne.data)==null?void 0:ke.endpoints,endpointFilter:d,exporting:Ve,filtersExpanded:re,fromDate:u,handleCloseDetail:He,handleExport:$e,handleOpenDetail:Ue,handleResetFilters:pe,isDetailOpen:T,items:Pe,logsQuery:P,modelFilter:r,page:p,pageSize:S,providerFilter:o,providerLabelMap:ce,providerOptions:de,rowDensity:x,resetVisibleColumns:W,selectedApiKeys:y,selectedLogId:D,setEndpointFilter:s,setFiltersExpanded:oe,setFromDate:j,setModelFilter:h,setPage:f,setPageSize:b,setProviderFilter:n,setRowDensity:G,setSelectedApiKeys:B,setStatusFilter:v,setToDate:a,showScrollHint:Fe,statusFilter:c,tableScrollRef:Te,toDate:i,toggleColumn:Re,total:Z,totalPages:J,visibleColumnCount:Le,visibleColumns:Me,visibleColumnSet:Ke}}function ss(){var o;const{t:l}=M(),t=Mt();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(et,{icon:e.jsx(Ye,{className:"h-5 w-5","aria-hidden":"true"}),title:l("logs.title"),description:l("logs.description"),eyebrow:"Traffic Explorer",breadcrumb:"Gateway / Logs",helper:l("logs.filtersDescription"),badge:t.total>0?l("logs.summary.total",{value:t.total.toLocaleString()}):void 0,actions:e.jsx(Et,{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(yt,{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(Ft,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.visibleColumnSet,visibleColumnCount:t.visibleColumnCount,logsError:t.logsQuery.isError?((o=t.logsQuery.error)==null?void 0:o.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(vt,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{ss as default};
|
|
1
|
+
import{r as g,j as e,ak as Be,al as We,a8 as Ge,am as Je,aj as Xe,V as Ze,T as Ye}from"./vendor-5iCEqDpV.js";import{P as et}from"./PageHeader-DDxjKW4B.js";import{c as w,B as E,b as tt,u as ge,s as _,t as st,a as R}from"./index-CYeQpt9d.js";import{B as K}from"./badge-B-TfGxGB.js";import{C as _e,a as Ee}from"./card-I07afQF2.js";import{I as ue}from"./input-DZMeIHxj.js";import{L as I}from"./label-DZr7itdg.js";import{S as ee,a as te,b as se,c as le,d as L}from"./select-BUvJR07s.js";import{u as M}from"./i18n-C7VVFIdN.js";import{D as lt,A as at,a as rt,b as ot,c as it,d as nt}from"./DialogShell-BqzUE3vU.js";import{P as dt,a as xe}from"./PageState-DA98vXl7.js";import{c as ct}from"./clipboard-CALi6bTW.js";import{u as $}from"./useApiQuery-BzbOtl4s.js";import{q as U}from"./queryKeys-BMvyDTQS.js";import{f as O,a as De,b as mt,c as z,d as pt,g as ut}from"./utils-DQfq7gRo.js";import{P as xt,a as gt,b as ht}from"./popover-_LyL4tgU.js";import{T as ft}from"./Skeleton-D_opZxQ7.js";import{g as Se}from"./gateway-CkqHb_VE.js";import"./query-DxhDvnDC.js";import"./router-D8u_RlVh.js";import"./radix-CmyU-WBH.js";function bt({apiKeys:l,selected:t,onChange:o,disabled:n,className:d}){const{t:s}=M(),[r,h]=g.useState(!1),c=g.useRef(null);g.useEffect(()=>{if(!r)return;const i=a=>{var p;(p=c.current)!=null&&p.contains(a.target)||h(!1)};return window.addEventListener("mousedown",i),()=>window.removeEventListener("mousedown",i)},[r]);const v=g.useMemo(()=>{if(t.length===0)return[];const i=new Map;for(const a of l)i.set(a.id,a);return t.map(a=>{const p=i.get(a);return p?p.isWildcard?s("apiKeys.wildcard"):p.name:null}).filter(a=>!!a)},[l,t,s]),u=t.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:t.length}),j=i=>{t.includes(i)?o(t.filter(a=>a!==i)):o([...t,i])};return e.jsxs("div",{className:w("relative space-y-2",d),ref:c,children:[e.jsx(I,{children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>h(i=>!i),disabled:n||l.length===0,title:s("logs.filters.apiKeyHint"),className:w("flex h-10 w-full items-center justify-between rounded-md 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:[u,v.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:v.join(", ")})]}),e.jsx("svg",{className:w("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&&e.jsxs("div",{className:"absolute left-0 top-full z-30 mt-2 w-64 rounded-md border bg-popover p-2 shadow-md",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-secondary px-3 py-2 text-xs",children:[e.jsx("span",{children:u}),e.jsx("button",{type:"button",onClick:()=>o([]),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(i=>{const a=i.isWildcard?s("apiKeys.wildcard"):i.name,p=t.includes(i.id);return e.jsxs("label",{className:w("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",p&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:p,onChange:()=>j(i.id)}),e.jsx("span",{className:"truncate",children:a})]},i.id)}),l.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:s("logs.filters.apiKeyAll")})]})]})]})}function yt(l){const{t}=M(),{total:o,activeFilters:n,filtersExpanded:d,setFiltersExpanded:s,handleResetFilters:r,activeQuickView:h,applyQuickView:c,providerFilter:v,setProviderFilter:u,endpointFilter:j,setEndpointFilter:i,selectedApiKeys:a,setSelectedApiKeys:p,modelFilter:f,setModelFilter:S,statusFilter:b,setStatusFilter:D,fromDate:C,setFromDate:T,toDate:N,setToDate:y,providerOptions:B,apiKeys:re,apiKeysLoading:oe,customEndpoints:W}=l;return e.jsx(_e,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(Ee,{className:"pt-4",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:t("logs.filtersTitle")}),e.jsx(K,{variant:"outline",children:t("logs.summary.total",{value:o.toLocaleString()})}),n.length>0&&e.jsx(K,{variant:"secondary",children:t("common.filters.activeCount",{count:n.length})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("logs.filtersDescription")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n.length>0&&e.jsx(E,{variant:"ghost",size:"sm",onClick:r,children:t("common.actions.reset")}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>s(x=>!x),children:d?e.jsxs(e.Fragment,{children:[t("common.filters.collapse"),e.jsx(Be,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[t("common.filters.expand"),e.jsx(We,{className:"ml-1 h-4 w-4"})]})})]})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("div",{className:"flex min-h-[52px] items-center rounded-lg border border-border bg-secondary px-3 py-2",children:n.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(x=>e.jsxs(K,{variant:"secondary",role:"button",tabIndex:0,className:"cursor-pointer gap-1 border border-transparent bg-primary/10 text-primary hover:bg-destructive/10 hover:text-destructive",onClick:x.onRemove,onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),x.onRemove())},children:[x.label,e.jsx(Ge,{className:"h-3 w-3","aria-hidden":"true"})]},x.key))}):e.jsx("span",{className:"text-sm text-muted-foreground",children:t("common.filters.allRequests")})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4 lg:min-w-[360px]",children:[e.jsx(Y,{label:t("common.filters.activeCount",{count:n.length}),value:n.length.toString()}),e.jsx(Y,{label:t("logs.filters.apiKey"),value:a.length.toString()}),e.jsx(Y,{label:t("logs.filters.provider"),value:v==="all"?t("common.noData"):"1"}),e.jsx(Y,{label:t("logs.filters.endpoint"),value:j==="all"?t("common.noData"):"1"})]})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 rounded-lg border border-border bg-secondary p-2",children:["all","errors","today","anthropic","openai"].map(x=>e.jsx(E,{variant:h===x?"default":"outline",size:"sm",className:w("rounded-full border-transparent",h===x&&x==="all"&&"bg-foreground text-background hover:bg-foreground/90",h===x&&x==="errors"&&"bg-rose-500 text-white hover:bg-rose-500/90",h===x&&x==="today"&&"bg-emerald-500 text-white hover:bg-emerald-500/90",h===x&&(x==="anthropic"||x==="openai")&&"bg-amber-500 text-white hover:bg-amber-500/90"),onClick:()=>c(x),children:t(`logs.quickViews.${x}`)},x))})]}),d&&e.jsxs("div",{className:"mt-4 grid gap-4 rounded-lg border border-border bg-secondary p-4 md:grid-cols-2 xl:grid-cols-4 animate-in fade-in slide-in-from-top-2 duration-200",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.provider")}),e.jsxs(ee,{value:v,onValueChange:u,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.providerAll")}),B.map(x=>e.jsx(L,{value:x.id,children:x.label??x.id},x.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endpoint")}),e.jsxs(ee,{value:j,onValueChange:i,children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.endpointAll")}),e.jsx(L,{value:"anthropic",children:t("logs.filters.endpointAnthropic")}),e.jsx(L,{value:"openai",children:t("logs.filters.endpointOpenAI")}),W==null?void 0:W.map(x=>e.jsx(L,{value:x.id,children:x.label||x.id},x.id))]})]})]}),e.jsx(bt,{className:"md:col-span-2",apiKeys:re,selected:a,disabled:oe,onChange:p}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.modelId")}),e.jsx(ue,{value:f,onChange:x=>S(x.target.value),placeholder:t("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.status")}),e.jsxs(ee,{value:b,onValueChange:x=>D(x),children:[e.jsx(te,{children:e.jsx(se,{})}),e.jsxs(le,{children:[e.jsx(L,{value:"all",children:t("logs.filters.statusAll")}),e.jsx(L,{value:"success",children:t("logs.filters.statusSuccess")}),e.jsx(L,{value:"error",children:t("logs.filters.statusError")})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.startDate")}),e.jsx(ue,{type:"date",value:C,onChange:x=>T(x.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endDate")}),e.jsx(ue,{type:"date",value:N,onChange:x=>y(x.target.value)})]})]})]})})}function Y({label:l,value:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-3 py-2",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:l}),e.jsx("p",{className:"mt-1 text-sm 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 o=await tt.post("/api/logs/export",l,{responseType:"blob",timeout:t});return new Blob([o.data],{type:"application/zip"})}};function jt({apiKeyMap:l,logId:t,open:o,providerLabelMap:n}){var i;const{t:d}=M(),{pushToast:s}=ge(),r=$(U.logs.detail(t),he.detailRequest(t),{enabled:o&&t!==null,staleTime:3e4});g.useEffect(()=>{!r.isError||!r.error||s({title:d("logs.detail.loadError"),description:r.error.message,variant:"error"})},[r.error,r.isError,s,d]);const h=g.useCallback(async(a,p,f)=>{if(!p){s({title:d("logs.detail.copy.empty",{label:a}),variant:"info"});return}try{await ct(p),s({title:d(f),variant:"success"})}catch(S){s({title:d("logs.detail.copy.failure"),description:S instanceof Error?S.message:d("logs.detail.copy.failureFallback"),variant:"error"})}},[s,d]),c=r.data,v=c?n.get(c.provider)??c.provider:"",u=c&&c.api_key_id!=null?l.get(c.api_key_id):void 0,j=c?c.status_code??(c.error?500:200):null;return{apiKeyMeta:u,errorMessage:r.isError?((i=r.error)==null?void 0:i.message)??null:null,handleCopy:h,isError:r.isError,isPending:r.isPending,providerLabel:v,refetch:r.refetch,record:c,statusCode:j}}function vt({open:l,logId:t,onClose:o,providerLabelMap:n,apiKeyMap:d}){var S,b,D,C,T,N;const{t:s}=M(),{apiKeyMeta:r,errorMessage:h,handleCopy:c,isError:v,isPending:u,providerLabel:j,refetch:i,record:a,statusCode:p}=jt({apiKeyMap:d,logId:t,open:l,providerLabelMap:n}),f=a?[{key:"client-request",title:s("logs.detail.payload.clientRequest"),value:((S=a.payload)==null?void 0:S.client_request)??null,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(b=a.payload)!=null&&b.upstream_request?[{key:"upstream-request",title:s("logs.detail.payload.upstreamRequest"),value:a.payload.upstream_request,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"}]:[],...(D=a.payload)!=null&&D.upstream_response?[{key:"upstream-response",title:s("logs.detail.payload.upstreamResponse"),value:a.payload.upstream_response,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[],{key:"client-response",title:s("logs.detail.payload.clientResponse"),value:((C=a.payload)==null?void 0:C.client_response)??null,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[];return e.jsx(lt,{open:l,onOpenChange:y=>{y||o()},children:e.jsxs(at,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(rt,{className:"pr-14",children:[e.jsx(ot,{children:s("logs.detail.title")}),e.jsx(it,{children:a?s("logs.detail.id",{id:a.id}):s("logs.detail.loadError")})]}),e.jsx(nt,{className:"max-h-[78vh]",children:u?e.jsx(dt,{compact:!0,className:"min-h-[240px]",label:s("common.loading")}):v?e.jsx(xe,{compact:!0,className:"min-h-[240px]",tone:"danger",title:s("logs.detail.loadError"),description:h??s("common.unknownError"),action:e.jsx(E,{variant:"outline",onClick:()=>void i(),children:s("common.actions.refresh")})}):a?e.jsxs("div",{className:"space-y-6 text-sm",children:[e.jsxs("section",{className:"space-y-4 rounded-lg border border-border bg-card p-5",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 border-border bg-secondary p-3 text-xs",children:[e.jsx("span",{className:"font-medium",children:s("logs.detail.summary.route",{from:a.client_model??s("logs.detail.info.noRequestedModel"),to:a.model})}),e.jsx("span",{className:"text-muted-foreground",children:s("logs.detail.summary.latency",{value:O(a.latency_ms,s("common.units.ms"))})}),a.ttft_ms!==null?e.jsxs("span",{className:"text-muted-foreground",children:["TTFT: ",O(a.ttft_ms,s("common.units.ms"))]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(K,{variant:a.error?"destructive":"default",children:p==null?void 0:p.toString()}),e.jsx(K,{variant:"outline",children:a.stream?s("logs.stream.streaming"):s("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(A,{label:s("logs.detail.info.latency"),value:O(a.latency_ms,s("common.units.ms"))}),e.jsx(A,{label:s("logs.detail.info.ttft"),value:O(a.ttft_ms,s("common.units.ms"))}),e.jsx(A,{label:s("logs.detail.info.tpot"),value:O(a.tpot_ms,s("common.units.msPerToken"))}),e.jsx(A,{label:s("logs.detail.info.status"),value:(p==null?void 0:p.toString())??"-"})]}),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:De(a.timestamp)}),e.jsx(F,{label:s("logs.detail.info.sessionId"),value:a.session_id??"-"}),e.jsx(F,{label:s("logs.detail.info.endpoint"),value:a.endpoint||"-"}),e.jsx(F,{label:s("logs.detail.info.provider"),value:j}),e.jsx(F,{label:s("logs.detail.info.requestedModel"),value:a.client_model??s("logs.detail.info.noRequestedModel")}),e.jsx(F,{label:s("logs.detail.info.model"),value:a.model}),e.jsx(F,{label:s("logs.detail.info.stream"),value:mt(a.stream)}),e.jsx(F,{label:s("logs.detail.info.status"),value:p})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(A,{label:s("logs.detail.info.inputTokens"),value:z(a.input_tokens)}),e.jsx(A,{label:s("logs.detail.info.cacheReadTokens"),value:z(a.cache_read_tokens)}),e.jsx(A,{label:s("logs.detail.info.cacheCreationTokens"),value:z(a.cache_creation_tokens)}),e.jsx(A,{label:s("logs.detail.info.outputTokens"),value:z(a.output_tokens)})]}),a.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-[1rem] border border-destructive/50 bg-destructive/10 p-3 text-xs text-destructive",children:a.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 border-border bg-card p-5",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:a.api_key_id==null&&!a.api_key_name?s("logs.detail.apiKey.missing"):r!=null&&r.isWildcard?s("apiKeys.wildcard"):(r==null?void 0:r.name)??a.api_key_name??s("logs.detail.apiKey.missing")}),e.jsx(F,{label:s("logs.detail.apiKey.identifier"),value:a.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)??a.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 border-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:a.api_key_value_available?a.api_key_value_masked??s("logs.detail.apiKey.rawUnavailable"):s("logs.detail.apiKey.rawUnavailable")}),e.jsx("p",{className:"mt-2 text-[11px] text-muted-foreground",children:s("logs.detail.apiKey.rawMaskedHint")})]})]}),e.jsxs("section",{className:"space-y-4 rounded-lg border border-border bg-card p-5",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:(T=a.payload)!=null&&T.upstream_request||(N=a.payload)!=null&&N.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(y=>e.jsx(Nt,{title:y.title,value:y.value,emptyLabel:y.emptyLabel,onCopy:()=>c(y.title,y.value,y.copyToast),t:s},y.key))})]})]})]}):e.jsx(xe,{compact:!0,className:"min-h-[240px]",title:s("logs.detail.loadError"),description:s("common.noData")})})]})})}function A({label:l,value:t}){return e.jsxs("div",{className:"min-w-0 rounded-lg border border-border bg-secondary px-3 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] 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 Nt({emptyLabel:l,onCopy:t,title:o,value:n,t:d}){return e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary/40 p-4",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:o}),e.jsx(E,{variant:"outline",size:"sm",onClick:t,children:d("common.actions.copy")})]}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap rounded-lg border border-border bg-secondary p-3 text-xs",children:pt(n,l)})]})}const H=[20,50,100],Q=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"],ae=["endpoint","provider","requestedModel","routedModel","apiKey","inputTokens","cacheReadTokens","cacheCreationTokens","outputTokens","latency","ttft","tpot","status","error"];function wt(){if(typeof window>"u")return Q;try{const l=window.localStorage.getItem(_.logs.visibleColumns);if(!l)return Q;const t=JSON.parse(l);if(!Array.isArray(t))return Q;const o=t.filter(n=>ae.includes(n));return o.length>0?o:Q}catch{return Q}}function kt(){return typeof window>"u"?"comfortable":window.localStorage.getItem(_.logs.density)==="compact"?"compact":"comfortable"}function St(){if(typeof window>"u")return H[0];const l=window.localStorage.getItem(_.logs.pageSize),t=Number(l);return H.includes(t)?t:H[0]}function Ct(){if(typeof window>"u")return[];try{const l=window.localStorage.getItem(_.logs.selectedApiKeys);if(!l)return[];const t=JSON.parse(l);return Array.isArray(t)?t.map(o=>Number(o)).filter(o=>Number.isInteger(o)&&o>0):[]}catch{return[]}}function Ce(l,t=!1){if(!l)return;const o=t?`${l}T23:59:59.999`:`${l}T00:00:00.000`,n=Date.parse(o);return Number.isFinite(n)?n:void 0}function _t(l,t,o){return l===o&&t===o}function Et({columnOptions:l,exporting:t,onExport:o,onRefresh:n,onResetColumns:d,onSetDensity:s,onToggleColumn:r,refreshing:h,rowDensity:c,total:v,visibleColumns:u,visibleColumnSet:j}){const{t:i}=M(),a=JSON.stringify(u)===JSON.stringify(Q);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 border border-border bg-secondary p-1 sm:w-auto",children:[e.jsx("button",{type:"button",onClick:()=>s("comfortable"),className:w("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",c==="comfortable"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:i("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>s("compact"),className:w("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",c==="compact"?"bg-primary text-primary-foreground shadow-[0_8px_18px_-14px_rgba(59,130,246,0.7)]":"text-muted-foreground hover:bg-primary/5 hover:text-foreground"),children:i("logs.table.density.compact")})]}),e.jsxs(xt,{children:[e.jsx(gt,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:i("logs.actions.columns")})}),e.jsxs(ht,{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:i("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("logs.actions.visibleCount",{count:u.length})})]}),e.jsx(E,{variant:"ghost",size:"sm",onClick:d,disabled:a,children:i("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(p=>{const f=j.has(p.id);return e.jsxs("label",{className:w("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",f&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:f,onChange:()=>r(p.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:p.label})]},p.id)})})]})]}),e.jsxs(E,{onClick:o,disabled:t,className:"w-full sm:w-auto",children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),i(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:i("logs.summary.total",{value:v.toLocaleString()})}),e.jsxs(E,{variant:"outline",size:"sm",onClick:n,disabled:h,className:"shrink-0",children:[e.jsx(Xe,{className:w("mr-2 h-4 w-4",h&&"animate-spin")}),i(h?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function Dt({record:l,providerLabelMap:t,apiKeyMap:o,onSelect:n,isEven:d,density:s,visibleColumnSet:r}){const{t:h}=M(),c=t.get(l.provider)??l.provider,v=l.endpoint||"-",u=!!l.error,j=l.status_code,i=l.client_model??h("logs.table.requestedModelFallback"),a=l.api_key_id!=null?o.get(l.api_key_id):void 0,p=l.api_key_id==null?h("logs.table.apiKeyUnknown"):a!=null&&a.isWildcard?h("apiKeys.wildcard"):a!=null&&a.name?a.name:l.api_key_name?l.api_key_name:h("logs.table.apiKeyUnknown"),f=s==="compact"?"px-3 py-1.5":"px-3 py-2",S=d?"bg-muted/30":"bg-background",b=ut(l.session_id),D=b==null?void 0:b.rowStyle,C=b==null?void 0:b.stickyStyle,T=b?{...b.stickyStyle,...b.accentStyle}:void 0;return e.jsxs("tr",{"data-session-id":b==null?void 0:b.sessionId,"data-session-color":b==null?void 0:b.colorKey,className:w("transition-colors",b?"":d?"bg-muted/30":"",b?"":"hover:bg-muted/50"),style:D,onMouseEnter:N=>{b&&Object.assign(N.currentTarget.style,b.hoverStyle)},onMouseLeave:N=>{b&&Object.assign(N.currentTarget.style,b.rowStyle)},children:[e.jsx("td",{className:w("sticky left-0 z-10 text-xs",f,b?"":S),style:T,children:De(l.timestamp)}),r.has("endpoint")&&e.jsx("td",{className:w(f,"text-xs"),children:v}),r.has("provider")&&e.jsx("td",{className:w(f,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:c,children:c})}),r.has("requestedModel")&&e.jsx("td",{className:w(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:i,children:i})}),r.has("routedModel")&&e.jsx("td",{className:w(f,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:l.model,children:l.model})}),r.has("apiKey")&&e.jsx("td",{className:w(f,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:p,children:p})}),r.has("inputTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.input_tokens)}),r.has("cacheReadTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.cache_read_tokens)}),r.has("cacheCreationTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.cache_creation_tokens)}),r.has("outputTokens")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:z(l.output_tokens)}),r.has("latency")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.latency_ms,"ms")}),r.has("ttft")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.ttft_ms,"ms")}),r.has("tpot")&&e.jsx("td",{className:w(f,"text-right text-xs tabular-nums"),children:O(l.tpot_ms,"ms/tk")}),r.has("status")&&e.jsx("td",{className:w(f,"text-center"),children:e.jsx(K,{variant:u?"destructive":"default",className:"text-xs",children:j??(u?500:200)})}),r.has("error")&&e.jsx("td",{className:w(f,"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:w("sticky right-0 z-10 text-center",f,b?"":S),style:C,children:e.jsx(E,{variant:"outline",size:"sm",onClick:()=>n(l.id),children:h("logs.actions.detail")})})]})}function Ft(l){const{t}=M(),{tableScrollRef:o,visibleColumnSet:n,visibleColumnCount:d,logsError:s,logsPending:r,items:h,activeFiltersCount:c,handleResetFilters:v,handleRetry:u,providerLabelMap:j,apiKeyMap:i,handleOpenDetail:a,rowDensity:p,showScrollHint:f,pageSize:S,setPageSize:b,page:D,totalPages:C,setPage:T}=l;return e.jsx(_e,{className:"overflow-hidden",children:e.jsxs(Ee,{className:"p-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-border bg-secondary px-4 py-3",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(K,{variant:"secondary",children:"Wide Table"}),e.jsx(K,{variant:"outline",children:t(p==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),f?e.jsx(K,{variant:"outline",className:"border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-300",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:o,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1480px] text-sm",children:[e.jsx("thead",{className:"border-b bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"sticky left-0 z-20 bg-muted/95 px-3 py-2 text-left text-xs font-medium backdrop-blur",children:t("logs.table.columns.time")}),n.has("endpoint")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.endpoint")}),n.has("provider")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.provider")}),n.has("requestedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.requestedModel")}),n.has("routedModel")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.routedModel")}),n.has("apiKey")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.apiKey")}),n.has("inputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.inputTokens")}),n.has("cacheReadTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.cacheReadTokens")}),n.has("cacheCreationTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.cacheCreationTokens")}),n.has("outputTokens")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.outputTokens")}),n.has("latency")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.latency")}),n.has("ttft")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.ttft")}),n.has("tpot")&&e.jsx("th",{className:"px-3 py-2 text-right text-xs font-medium",children:t("logs.table.columns.tpot")}),n.has("status")&&e.jsx("th",{className:"px-3 py-2 text-center text-xs font-medium",children:t("logs.table.columns.status")}),n.has("error")&&e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium",children:t("logs.table.columns.error")}),e.jsx("th",{className:"sticky right-0 z-20 bg-muted/95 px-3 py-2 text-center text-xs font-medium backdrop-blur",children:t("logs.table.columns.actions")})]})}),e.jsx("tbody",{className:"divide-y",children:r?Array.from({length:8}).map((N,y)=>e.jsx(ft,{columns:d},y)):s&&h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:d,className:"px-3 py-6",children:e.jsx(xe,{compact:!0,tone:"danger",icon:e.jsx(Ze,{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(E,{variant:"outline",size:"sm",onClick:u,children:t("common.actions.refresh")}),c>0?e.jsx(E,{variant:"ghost",size:"sm",onClick:v,children:t("common.actions.reset")}):null]})})})}):h.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.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[e.jsx("span",{children:t("logs.table.empty")}),c>0&&e.jsx(E,{variant:"outline",size:"sm",onClick:v,children:t("common.actions.reset")})]})})}):h.map((N,y)=>e.jsx(Dt,{record:N,providerLabelMap:j,apiKeyMap:i,onSelect:a,isEven:y%2===0,density:p,visibleColumnSet:n},N.id))})]})}),f&&e.jsx("div",{className:"table-scroll-hint"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4 border-t p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.perPage")}),e.jsxs(ee,{value:S.toString(),onValueChange:N=>b(Number(N)),children:[e.jsx(te,{className:"w-[80px]",children:e.jsx(se,{})}),e.jsx(le,{children:H.map(N=>e.jsx(L,{value:N.toString(),children:N},N))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",onClick:()=>T(N=>Math.max(N-1,1)),disabled:D<=1,children:t("logs.table.pagination.previous")}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t("logs.table.pagination.pageLabel",{page:C===0?0:D,total:C})}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>T(N=>C===0?N:Math.min(N+1,C)),disabled:C===0||D>=C,children:t("logs.table.pagination.next")})]})]})]})})}function Tt({exportTimeoutMs:l,queryParams:t,total:o}){const{t:n}=M(),{pushToast:d}=ge(),[s,r]=g.useState(!1),h=g.useCallback(async()=>{if(!s){r(!0);try{const c=o>0?Math.min(o,5e3):1e3,v={...t,limit:c,offset:0},u=await he.exportArchive(v,l),j=new Date().toISOString().replace(/[:.]/g,"-"),i=URL.createObjectURL(u),a=document.createElement("a");a.href=i,a.download=`cc-gw-logs-${j}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i),d({title:n("logs.toast.exportSuccess.title"),description:n("logs.toast.exportSuccess.desc"),variant:"success"})}catch(c){const v=st(c);d({title:n("logs.toast.exportError.title"),description:n("logs.toast.exportError.desc",{message:v.message}),variant:"error"})}finally{r(!1)}}},[l,s,d,t,n,o]);return{exporting:s,handleExport:h}}function Rt(){const l=g.useRef(null),[t,o]=g.useState(!1),n=g.useCallback(()=>{const d=l.current;if(!d)return;const s=d.scrollWidth-d.scrollLeft-d.clientWidth>1;o(s)},[]);return g.useEffect(()=>{const d=l.current;if(!d)return;n(),d.addEventListener("scroll",n,{passive:!0});const s=new ResizeObserver(n);return s.observe(d),()=>{d.removeEventListener("scroll",n),s.disconnect()}},[n]),{scrollRef:l,showScrollHint:t,updateScrollHint:n}}function Lt(){const[l,t]=R(_.logs.density,kt,{serialize:u=>u,deserialize:u=>u==="compact"?"compact":"comfortable"}),[o,n]=R(_.logs.visibleColumns,wt),{scrollRef:d,showScrollHint:s}=Rt(),r=g.useMemo(()=>new Set(o),[o]),h=o.length+2,c=g.useCallback(u=>{n(j=>{if(j.includes(u))return j.length===1?j:j.filter(a=>a!==u);const i=[...j,u];return i.sort((a,p)=>ae.indexOf(a)-ae.indexOf(p)),i})},[]);return{resetVisibleColumns:g.useCallback(()=>{n(Q)},[]),rowDensity:l,setRowDensity:t,showScrollHint:s,tableScrollRef:d,toggleColumn:c,visibleColumnCount:h,visibleColumns:o,visibleColumnSet:r}}function Mt(){var je,ve,Ne,we,ke;const{t:l}=M(),{pushToast:t}=ge(),[o,n]=R(_.logs.providerFilter,"all"),[d,s]=R(_.logs.endpointFilter,"all"),[r,h]=R(_.logs.modelFilter,""),[c,v]=R(_.logs.statusFilter,"all"),[u,j]=R(_.logs.fromDate,""),[i,a]=R(_.logs.toDate,""),[p,f]=g.useState(1),[S,b]=R(_.logs.pageSize,St,{serialize:m=>String(m),deserialize:m=>{const k=Number(m);return H.includes(k)?k:H[0]}}),[D,C]=g.useState(null),[T,N]=g.useState(!1),[y,B]=R(_.logs.selectedApiKeys,Ct),[re,oe]=R(_.logs.filtersExpanded,!1),{resetVisibleColumns:W,rowDensity:x,setRowDensity:G,showScrollHint:Fe,tableScrollRef:Te,toggleColumn:Re,visibleColumnCount:Le,visibleColumns:Me,visibleColumnSet:Ke}=Lt();g.useEffect(()=>{f(1)},[o,d,r,c,u,i,S,y]);const ie=g.useMemo(()=>{const m={limit:S,offset:(p-1)*S};o!=="all"&&(m.provider=o),d!=="all"&&(m.endpoint=d),r.trim().length>0&&(m.model=r.trim()),c!=="all"&&(m.status=c);const k=Ce(u),q=Ce(i,!0);return k!==void 0&&(m.from=k),q!==void 0&&(m.to=q),y.length>0&&(m.apiKeys=y.join(",")),m},[d,u,r,p,S,o,y,c,i]),P=$(U.logs.list(ie),he.listRequest(ie)),V=$(U.providers.all(),Se.providersRequest()),fe=$(U.apiKeys.all(),{url:"/api/keys",method:"GET"}),ne=$(U.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),be=$(U.config.exportTimeout(),Se.configRequest());g.useEffect(()=>{!P.isError||!P.error||t({title:l("logs.toast.listError.title"),description:l("logs.toast.listError.desc",{message:P.error.message}),variant:"error"})},[P.error,P.isError,t,l]),g.useEffect(()=>{!V.isError||!V.error||t({title:l("logs.toast.providerError.title"),description:l("logs.toast.providerError.desc",{message:V.error.message}),variant:"error"})},[V.error,V.isError,t,l]);const Z=((je=P.data)==null?void 0:je.total)??0,J=Z>0?Math.ceil(Z/S):0,Pe=((ve=P.data)==null?void 0:ve.items)??[],Ae=g.useMemo(()=>{var k;const m=(k=be.data)==null?void 0:k.logExportTimeoutSeconds;return typeof m=="number"&&Number.isFinite(m)?Math.min(Math.max(Math.round(m),5),600)*1e3:6e4},[(Ne=be.data)==null?void 0:Ne.logExportTimeoutSeconds]);g.useEffect(()=>{J>0&&p>J&&f(J)},[p,J]);const de=V.data??[],ce=g.useMemo(()=>{const m=new Map;for(const k of de)k.id&&m.set(k.id,k.label??k.id);return m},[de]),ye=g.useMemo(()=>{var k;const m=new Map;m.set("anthropic",l("logs.filters.endpointAnthropic")),m.set("openai",l("logs.filters.endpointOpenAI"));for(const q of((k=ne.data)==null?void 0:k.endpoints)??[])m.set(q.id,q.label||q.id);return m},[(we=ne.data)==null?void 0:we.endpoints,l]),Oe=g.useMemo(()=>{const m=[];if(o!=="all"){const k=ce.get(o)??o;m.push({key:"provider",label:`${l("logs.filters.provider")}: ${k}`,onRemove:()=>n("all")})}if(d!=="all"){const k=ye.get(d)??d;m.push({key:"endpoint",label:`${l("logs.filters.endpoint")}: ${k}`,onRemove:()=>s("all")})}if(r.trim()&&m.push({key:"model",label:`${l("logs.filters.modelId")}: ${r.trim()}`,onRemove:()=>h("")}),c!=="all"){const k=l(c==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");m.push({key:"status",label:`${l("logs.filters.status")}: ${k}`,onRemove:()=>v("all")})}return u&&m.push({key:"from",label:`${l("logs.filters.startDate")}: ${u}`,onRemove:()=>j("")}),i&&m.push({key:"to",label:`${l("logs.filters.endDate")}: ${i}`,onRemove:()=>a("")}),y.length>0&&m.push({key:"apiKeys",label:l("logs.filters.apiKeySelected",{count:y.length}),onRemove:()=>B([])}),m},[d,ye,u,r,o,ce,y.length,c,l,i]),me=fe.data??[],ze=g.useMemo(()=>{const m=new Map;for(const k of me)m.set(k.id,k);return m},[me]),qe=g.useMemo(()=>ae.map(m=>({id:m,label:l(`logs.table.columns.${m}`)})),[l]),X=g.useMemo(()=>new Date().toISOString().slice(0,10),[]),Ie=g.useMemo(()=>o==="all"&&d==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"all":c==="error"&&d==="all"&&o==="all"&&r.trim()===""&&u===""&&i===""&&y.length===0?"errors":_t(u,i,X)&&d==="all"&&o==="all"&&r.trim()===""&&c==="all"&&y.length===0?"today":d==="anthropic"&&o==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"anthropic":d==="openai"&&o==="all"&&r.trim()===""&&c==="all"&&u===""&&i===""&&y.length===0?"openai":null,[d,u,r,o,y.length,c,i,X]),pe=g.useCallback(()=>{n("all"),h(""),s("all"),v("all"),j(""),a(""),B([])},[]),Qe=g.useCallback(m=>{if(f(1),pe(),m!=="all"){if(m==="errors"){v("error");return}if(m==="today"){j(X),a(X);return}if(m==="anthropic"){s("anthropic");return}m==="openai"&&s("openai")}},[pe,X]),{exporting:Ve,handleExport:$e}=Tt({exportTimeoutMs:Ae,queryParams:ie,total:Z}),Ue=g.useCallback(m=>{C(m),N(!0)},[]),He=g.useCallback(()=>{N(!1),C(null)},[]);return{activeFilters:Oe,activeQuickView:Ie,apiKeyMap:ze,apiKeys:me,apiKeysQuery:fe,applyQuickView:Qe,columnOptions:qe,customEndpoints:(ke=ne.data)==null?void 0:ke.endpoints,endpointFilter:d,exporting:Ve,filtersExpanded:re,fromDate:u,handleCloseDetail:He,handleExport:$e,handleOpenDetail:Ue,handleResetFilters:pe,isDetailOpen:T,items:Pe,logsQuery:P,modelFilter:r,page:p,pageSize:S,providerFilter:o,providerLabelMap:ce,providerOptions:de,rowDensity:x,resetVisibleColumns:W,selectedApiKeys:y,selectedLogId:D,setEndpointFilter:s,setFiltersExpanded:oe,setFromDate:j,setModelFilter:h,setPage:f,setPageSize:b,setProviderFilter:n,setRowDensity:G,setSelectedApiKeys:B,setStatusFilter:v,setToDate:a,showScrollHint:Fe,statusFilter:c,tableScrollRef:Te,toDate:i,toggleColumn:Re,total:Z,totalPages:J,visibleColumnCount:Le,visibleColumns:Me,visibleColumnSet:Ke}}function ss(){var o;const{t:l}=M(),t=Mt();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(et,{icon:e.jsx(Ye,{className:"h-5 w-5","aria-hidden":"true"}),title:l("logs.title"),description:l("logs.description"),eyebrow:"Traffic Explorer",breadcrumb:"Gateway / Logs",helper:l("logs.filtersDescription"),badge:t.total>0?l("logs.summary.total",{value:t.total.toLocaleString()}):void 0,actions:e.jsx(Et,{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(yt,{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(Ft,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.visibleColumnSet,visibleColumnCount:t.visibleColumnCount,logsError:t.logsQuery.isError?((o=t.logsQuery.error)==null?void 0:o.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(vt,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{ss as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as N,j as e,a8 as Se,as as pt,at as Ne,q as hs,a1 as xt,aj as fs,al as bs,U as vs}from"./vendor-5iCEqDpV.js";import{C as js}from"./ConfirmDialog-DW7jBfm1.js";import{P as ys}from"./PageHeader-DDxjKW4B.js";import{c as oe,B as L,d as Ee,T as Ns,e as ws,f as Ms,g as ks,h as Re,b as Te,u as Cs,t as ot}from"./index-CYeQpt9d.js";import{u as te}from"./i18n-C7VVFIdN.js";import{u as Le}from"./useAppMutation-D8Mjcv9t.js";import{I as fe}from"./input-DZMeIHxj.js";import{L as J}from"./label-DZr7itdg.js";import{S as gt,a as ht,b as ft,c as bt,d as me}from"./select-BUvJR07s.js";import{S as qe}from"./switch-BpfcwR9i.js";import{q as he}from"./queryKeys-BMvyDTQS.js";import{B as H}from"./badge-B-TfGxGB.js";import{C as Fe,a as Be}from"./card-I07afQF2.js";import{D as vt,A as jt,a as yt,b as Nt,c as wt,d as Mt,e as kt}from"./DialogShell-BqzUE3vU.js";import{P as Es,a as Ss,b as Ps}from"./popover-_LyL4tgU.js";import{u as Ds,a as Rs}from"./query-DxhDvnDC.js";import{g as ye}from"./gateway-CkqHb_VE.js";import{u as Ts}from"./useApiQuery-BzbOtl4s.js";import"./router-D8u_RlVh.js";import"./radix-CmyU-WBH.js";function We(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Os(){return{_key:We(),id:"",label:""}}const Oe={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:{}},dt=[{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 lt(s){return s?{id:s.id,label:s.label??s.id,baseUrl:s.baseUrl,apiKey:s.apiKey??"",type:s.type??"custom",defaultModel:s.defaultModel??"",models:(s.models??[]).map(t=>({...t,_key:We()})),authMode:s.authMode??"apiKey"}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:"apiKey"}}function As(s){return{_key:We(),id:s.id,label:s.label}}function Us({open:s,mode:t,provider:c,existingProviderIds:g,onClose:d,onSubmit:x}){const{t:a}=te(),[o,m]=N.useState(()=>lt(c)),[u,h]=N.useState({}),[F,k]=N.useState(!1),[M,C]=N.useState(null),v=N.useRef(null),f=N.useRef(null),b=N.useRef(null),[j,Q]=N.useState(t==="edit");N.useEffect(()=>{s&&(m(lt(c)),h({}),C(null),k(!1),Q(t==="edit"))},[s,c,t]),N.useEffect(()=>{if(!s)return;const i=E=>{E.key==="Escape"&&d()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[s,d]),N.useEffect(()=>{if(s){if(t==="create"&&b.current){b.current.focus();return}f.current&&f.current.focus()}},[s,t]);const Y=t==="create",ue=N.useMemo(()=>o.models.filter(i=>i.id.trim().length>0),[o.models]),le=N.useMemo(()=>{var i;return((i=dt.find(E=>E.value===o.type))==null?void 0:i.label)??"Custom"},[o.type]),Z=o.label.trim()||o.id.trim()||a("providers.drawer.summary.untitled"),V=N.useMemo(()=>[{label:a("providers.drawer.summary.type"),value:le},{label:a("providers.drawer.summary.auth"),value:o.authMode==="apiKey"?a("providers.drawer.fields.authModeApiKey"):o.authMode==="authToken"?a("providers.drawer.fields.authModeAuthToken"):a("providers.drawer.fields.authModeXAuthToken")},{label:a("providers.drawer.summary.models"),value:ue.length.toLocaleString()}],[ue.length,o.authMode,le,a]),pe=i=>E=>{m(R=>({...R,[i]:E}))},G=i=>{m(E=>{const P=!j||E.label.trim().length===0||E.label===E.id?i:E.label;return{...E,id:i,label:P}})},we=i=>{m(E=>{var de;const P=Oe[i??"custom"]??Oe.custom,B=Object.values(Oe).map(re=>re.baseUrl).filter(re=>!!re),X=!E.baseUrl||B.includes(E.baseUrl),A=t==="create"&&(E.models.length===0||E.models.every(re=>re.id.trim().length===0)),q={...E,type:i,authMode:E.authMode??"apiKey"};return P!=null&&P.baseUrl&&X&&(q.baseUrl=P.baseUrl),P!=null&&P.models&&A&&(q.models=P.models.map(As),q.defaultModel=P.defaultModel??((de=P.models[0])==null?void 0:de.id)??""),q})},be=(i,E)=>{m(R=>{const P=[...R.models];return P[i]={...P[i],...E},{...R,models:P}})},T=(i,E)=>{m(R=>{const P=[...R.models],B=P[i];if(!B)return R;const X=!j||!B.label||B.label===B.id,A={...B,id:E,label:X?E:B.label};P[i]=A;const q=R.defaultModel===B.id?E:R.defaultModel;return{...R,models:P,defaultModel:q}})},I=i=>{m(E=>{if(i<0||i>=E.models.length)return E;const R=E.models.filter((B,X)=>X!==i);let P=E.defaultModel;return R.some(B=>B.id===P)||(P=""),{...E,models:R,defaultModel:P}})},Me=()=>{m(i=>({...i,models:[...i.models,Os()]}))},se=i=>{m(E=>({...E,authMode:i}))},xe=()=>{const i={},E=o.id.trim(),R=o.baseUrl.trim();if(t==="create"&&(E.length===0?i.id=a("providers.drawer.errors.idRequired"):g.includes(E)&&(i.id=a("providers.drawer.errors.idDuplicate"))),t==="edit"&&E.length===0&&(i.id=a("providers.drawer.errors.idRequired")),R.length===0)i.baseUrl=a("providers.drawer.errors.baseUrlInvalid");else try{new URL(R)}catch{i.baseUrl=a("providers.drawer.errors.baseUrlInvalid")}if(o.models.length>0){const P=new Set;o.models.some(X=>{const A=X.id.trim();return A.length===0||P.has(A)?!0:(P.add(A),!1)})&&(i.models=a("providers.drawer.errors.modelInvalid"))}return o.defaultModel&&!o.models.some(P=>P.id===o.defaultModel)&&(i.models=a("providers.drawer.errors.defaultInvalid")),h(i),Object.keys(i).length===0},ie=()=>{const i=o.models.map(P=>{var B;return{id:P.id.trim(),label:(B=P.label)!=null&&B.trim()?P.label.trim():void 0}}).filter(P=>P.id.length>0),E=c!=null&&c.extraHeaders&&Object.keys(c.extraHeaders).length>0?c.extraHeaders:void 0,R=o.authMode!=="apiKey"?o.authMode:void 0;return{id:o.id.trim(),label:o.label.trim()||o.id.trim(),baseUrl:o.baseUrl.trim(),apiKey:o.apiKey.trim()||void 0,type:o.type??"custom",defaultModel:o.defaultModel||void 0,models:i.length>0?i:void 0,extraHeaders:E,authMode:R}},ge=async()=>{if(C(null),!!xe()){k(!0);try{const i=ie();await x(i)}catch(i){C(a("providers.drawer.toast.saveFailure",{message:i instanceof Error?i.message:"unknown"})),k(!1);return}k(!1),d()}};return s?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm",onClick:d,"aria-hidden":"true"}),e.jsxs("aside",{ref:v,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full w-full max-w-5xl flex-col border-l border-border bg-background shadow-lg",children:[e.jsxs("header",{className:"border-b border-border bg-secondary px-6 py-5",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(Y?"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(Y?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:a("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:f,onClick:d,className:"rounded-full border border-border bg-card px-4 py-2 text-sm transition hover:border-primary/20 hover:bg-accent/50",children:a("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:V.map(i=>e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:i.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:i.value})]},i.label))})]}),e.jsxs("div",{className:"grid flex-1 overflow-hidden xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"overflow-y-auto px-6 py-5",children:[e.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:dt.map(i=>{var R;const E=i.value===o.type;return e.jsxs("button",{type:"button",onClick:()=>we(i.value),className:oe("rounded-2xl border px-4 py-3 text-left transition",E?"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:i.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((R=Oe[i.value??"custom"])==null?void 0:R.baseUrl)??a("providers.drawer.hints.customProvider")})]},i.value??"custom")})})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-basic-info",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:a("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>Q(i=>!i),className:"rounded-full border border-border bg-card px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-accent/50",children:a(j?"providers.drawer.fields.hideAdvanced":"providers.drawer.fields.showAdvanced")})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.id")}),e.jsx("input",{value:o.id,ref:b,onChange:i=>G(i.target.value),disabled:!Y,placeholder:a("providers.drawer.fields.idPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!u.id}),u.id?e.jsx("span",{className:"text-xs text-red-500",children:u.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.label")}),e.jsx("input",{value:o.label,onChange:i=>pe("label")(i.target.value),placeholder:a("providers.drawer.fields.labelPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:o.baseUrl,onChange:i=>pe("baseUrl")(i.target.value),placeholder:a("providers.drawer.fields.baseUrlPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground","aria-invalid":!!u.baseUrl}),u.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:u.baseUrl}):null]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-auth-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-auth-fields",className:"text-sm font-semibold",children:a("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.hints.auth")})]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.apiKey")}),e.jsx("input",{value:o.apiKey,onChange:i=>pe("apiKey")(i.target.value),placeholder:a("providers.drawer.fields.apiKeyPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}),e.jsxs("fieldset",{className:"grid gap-2 rounded-lg border border-border bg-card p-4 text-xs",children:[e.jsx("legend",{className:"px-1 text-muted-foreground",children:a("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:a("providers.drawer.fields.authModeHint")}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"apiKey",checked:o.authMode==="apiKey",onChange:()=>se("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeApiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:o.authMode==="authToken",onChange:()=>se("authToken"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeAuthToken")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"xAuthToken",checked:o.authMode==="xAuthToken",onChange:()=>se("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:a("providers.drawer.fields.authModeXAuthToken")})]})]})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-model-fields",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-model-fields",className:"text-sm font-semibold",children:a("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:Me,className:"rounded-full border border-border bg-card px-3 py-1.5 text-xs transition hover:border-primary/20 hover:bg-accent/50",children:a("providers.drawer.fields.addModel")})]}),u.models?e.jsx("p",{className:"text-xs text-red-500",children:u.models}):null,e.jsxs("div",{className:"space-y-4",children:[o.models.map((i,E)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelId")}),e.jsx("input",{value:i.id,onChange:R=>T(E,R.target.value),placeholder:a("providers.drawer.fields.modelIdPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}),j?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:i.label??"",onChange:R=>be(E,{label:R.target.value}),placeholder:a("providers.drawer.fields.modelLabelPlaceholder"),className:"h-10 rounded-md border border-input bg-background px-3 py-2 text-sm transition-all focus:border-primary/40 focus:outline-none focus:ring-2 focus:ring-ring disabled:bg-muted/60 disabled:text-muted-foreground"})]}):null]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx("input",{type:"radio",name:"defaultModel",value:i.id,checked:o.defaultModel===i.id,onChange:()=>m(R=>({...R,defaultModel:i.id})),disabled:i.id.trim().length===0}),a("providers.drawer.fields.setDefault")]}),e.jsx("button",{type:"button",className:"text-red-500 transition hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>I(E),disabled:o.models.length===0,children:a("providers.drawer.fields.removeModel")})]})]},i._key)),o.models.length===0?e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50/60 p-5 dark:border-amber-700/50 dark:bg-amber-900/20",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900 dark:text-amber-200",children:a("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:a("providers.drawer.noModelsHint",{providerId:o.id||"provider-id"})}),e.jsxs("div",{className:"rounded-md border border-border bg-secondary 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-md border border-border bg-card px-2.5 py-1.5 font-mono text-xs text-foreground",children:['"claude-*": "',(o.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),ue.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:a("providers.drawer.defaultHint",{model:o.defaultModel||a("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden border-l border-border bg-secondary px-5 py-5 xl:block",children:e.jsxs("div",{className:"sticky top-0 space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",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:Z}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:V.map(i=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:i.label}),e.jsx("span",{className:"text-right font-medium",children:i.value})]},i.label))})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-card p-4",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")})]})]}),j&&e.jsxs("div",{className:"rounded-lg border border-primary/20 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 bg-secondary px-6 py-4 text-sm",children:[e.jsx("div",{className:"flex flex-col text-xs text-red-500","aria-live":"polite",children:M?e.jsx("span",{children:M}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:d,className:"rounded-full border border-border bg-card px-4 py-2 transition hover:border-primary/20 hover:bg-accent/50",disabled:F,children:a("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:ge,className:"rounded-full bg-primary px-5 py-2 text-primary-foreground shadow-[0_8px_20px_-12px_rgba(59,130,246,0.65)] transition hover:-translate-y-0.5 hover:bg-primary/95 disabled:opacity-60",disabled:F,children:a(F?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}const $s=["anthropic","openai-auto","openai-chat","openai-responses"];function Ls({open:s,endpoint:t,onClose:c,onSuccess:g}){const{t:d}=te(),[x,a]=N.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});N.useEffect(()=>{if(t){const v=t.paths&&t.paths.length>0?t.paths:t.path&&t.protocol?[{path:t.path,protocol:t.protocol}]:[{path:"",protocol:"openai-auto"}];a({id:t.id,label:t.label,paths:v,enabled:t.enabled!==!1});return}a({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[t,s]);const o=Le({mutationFn:Ee.create,invalidateKeys:[he.customEndpoints.all()],successToast:()=>({title:d("modelManagement.createEndpointSuccess")}),errorToast:v=>({title:d("modelManagement.createEndpointError",{error:v.message})}),onSuccess:async()=>{g(),c()}}),m=Le({mutationFn:v=>Ee.update(v.id,v.updates),invalidateKeys:[he.customEndpoints.all()],successToast:()=>({title:d("modelManagement.updateEndpointSuccess")}),errorToast:v=>({title:d("modelManagement.updateEndpointError",{error:v.message})}),onSuccess:async()=>{g(),c()}}),u=()=>{a(v=>({...v,paths:[...v.paths,{path:"",protocol:"anthropic"}]}))},h=v=>{x.paths.length!==1&&a(f=>({...f,paths:f.paths.filter((b,j)=>j!==v)}))},F=(v,f,b)=>{a(j=>{const Q=[...j.paths];return Q[v]={...Q[v],[f]:b},{...j,paths:Q}})},k=v=>{if(v==null||v.preventDefault(),!x.id.trim()||!x.label.trim())return;for(const b of x.paths)if(!b.path.trim())return;const f=x.paths.map(b=>({path:b.path.trim(),protocol:b.protocol}));if(t){m.mutate({id:t.id,updates:{label:x.label.trim(),paths:f,enabled:x.enabled}});return}o.mutate({id:x.id.trim(),label:x.label.trim(),paths:f,enabled:x.enabled})},M=o.isPending||m.isPending,C=x.paths.length===0?d("modelManagement.atLeastOnePath"):!x.id.trim()||!x.label.trim()?d("modelManagement.endpointValidationError"):x.paths.some(v=>!v.path.trim())?d("modelManagement.pathValidationError"):null;return s?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:c}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-border bg-background shadow-lg",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border bg-secondary p-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:d(t?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t?t.id:d("modelManagement.endpointRoutingHint")})]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:c,children:e.jsx(Se,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:k,className:"flex-1 space-y-6 overflow-y-auto p-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:d("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(t==null?void 0:t.id)||"new-endpoint"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:d("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:x.enabled?d("common.status.enabled"):d("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:[d("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(fe,{value:x.id,onChange:v=>a(f=>({...f,id:v.target.value})),placeholder:d("modelManagement.endpointIdPlaceholder"),disabled:!!t,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(J,{children:[d("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(fe,{value:x.label,onChange:v=>a(f=>({...f,label:v.target.value})),placeholder:d("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(J,{children:[d("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(L,{type:"button",variant:"ghost",size:"sm",onClick:u,children:[e.jsx(pt,{className:"mr-1 h-3 w-3"}),d("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:x.paths.map((v,f)=>e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(fe,{value:v.path,onChange:b=>F(f,"path",b.target.value),placeholder:d("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(gt,{value:v.protocol,onValueChange:b=>F(f,"protocol",b),children:[e.jsx(ht,{children:e.jsx(ft,{})}),e.jsx(bt,{children:$s.map(b=>e.jsx(me,{value:b,children:d(b==="anthropic"?"modelManagement.protocolAnthropic":b==="openai-auto"?"modelManagement.protocolOpenAI":b==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},b))})]})]}),x.paths.length>1?e.jsx(L,{type:"button",variant:"ghost",size:"sm",onClick:()=>h(f),className:"text-destructive",children:e.jsx(Se,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[f===0?e.jsx("p",{children:d("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:d(`modelManagement.protocolHints.${v.protocol}`)})]})]},`${v.protocol}-${f}`))}),C?e.jsx("p",{className:"text-xs text-destructive",children:C}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(qe,{id:"enabled",checked:x.enabled,onCheckedChange:v=>a(f=>({...f,enabled:v}))}),e.jsx(J,{htmlFor:"enabled",children:d("modelManagement.endpointEnabled")})]}),t?null:e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4",children:e.jsx("p",{className:"text-sm text-blue-800 dark:text-blue-200",children:d("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border bg-secondary p-6",children:[e.jsx(L,{variant:"outline",className:"flex-1",onClick:c,disabled:M,children:d("common.cancel")}),e.jsx(L,{className:"flex-1",onClick:()=>k(),disabled:M,children:d(M?"common.saving":t?"common.save":"common.create")})]})]})})]}):null}function Ke(s,t){return t(s==="anthropic"?"modelManagement.protocolAnthropic":s==="openai-chat"?"modelManagement.protocolOpenAIChat":s==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function Fs({activeTab:s,activeTabInfo:t,customEndpoints:c,customTabs:g,isDirtyByEndpoint:d,onDeleteEndpoint:x,onEditEndpoint:a,onSelectTab:o,providerCount:m,systemTabs:u}){const{t:h}=te(),F=Object.values(d).filter(Boolean).length,k=u.length-1+g.length;return e.jsx(Fe,{className:"overflow-hidden",children:e.jsxs(Be,{className:"space-y-5 pt-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(H,{variant:"outline",className:"border-primary/20 bg-accent text-primary",children:[h("modelManagement.tabs.providers")," · ",m]}),e.jsxs(H,{variant:"outline",children:[h("modelManagement.tabs.customEndpoint")," · ",g.length]}),F>0?e.jsx(H,{variant:"warning",children:h("modelManagement.overview.unsavedCount",{count:F})}):e.jsx(H,{variant:"success",children:h("modelManagement.overview.synced")})]}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:t==null?void 0:t.label}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t==null?void 0:t.description})]}),e.jsxs("div",{className:"flex w-full flex-col gap-3 sm:w-auto sm:flex-row sm:flex-wrap sm:items-center",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:g.length>0?h("modelManagement.overview.headerWithCustom"):h("modelManagement.overview.headerWithoutCustom")}),e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-accent px-3 py-2 text-xs font-medium text-primary",children:[h("modelManagement.overview.routeWorkspacesStat")," · ",k]})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(Ae,{label:h("modelManagement.overview.providersStat"),value:m.toString(),helper:h("modelManagement.overview.providersStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.routeWorkspacesStat"),value:k.toString(),helper:h("modelManagement.overview.routeWorkspacesStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.customEndpointsStat"),value:g.length.toString(),helper:h("modelManagement.overview.customEndpointsStatHint")}),e.jsx(Ae,{label:h("modelManagement.overview.activeWorkspace"),value:(t==null?void 0:t.label)??"-",helper:h(s==="providers"?"modelManagement.overview.activeWorkspaceProvider":"modelManagement.overview.activeWorkspaceRouting")})]}),e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 md:grid-cols-2",children:[e.jsx(it,{title:h("modelManagement.overview.resourceCardTitle"),description:h("modelManagement.overview.resourceCardDescription")}),e.jsx(it,{title:h("modelManagement.overview.entryCardTitle"),description:h("modelManagement.overview.entryCardDescription")})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:h("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:u.map(M=>{const C=s===M.key,v=M.key!=="providers"&&d[M.key];return e.jsxs("button",{type:"button",onClick:()=>o(M.key),className:oe("group flex min-h-[96px] flex-col justify-between rounded-lg border px-4 py-4 text-left transition-all",C?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("span",{className:oe("text-base font-semibold",C?"text-primary":"text-foreground"),children:M.label}),e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:M.key==="providers"?h("modelManagement.overview.providerPoolTag"):h("modelManagement.overview.systemEndpointTag")})]}),v?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsx("span",{className:"line-clamp-2 text-sm text-muted-foreground",children:M.description})]},M.key)})})]}),g.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:h("modelManagement.overview.customEndpoints")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:h("modelManagement.overview.customEndpointsHint")})]})}),e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-full snap-x gap-3",children:g.map(M=>{var b;const C=s===M.key,v=d[M.key],f=c.find(j=>j.id===M.key);return e.jsxs("div",{className:oe("group relative flex w-[260px] shrink-0 snap-start flex-col gap-3 rounded-lg border px-4 py-4 text-left transition-all",C?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("button",{type:"button",onClick:()=>o(M.key),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:oe("truncate text-base font-semibold",C?"text-primary":"text-foreground"),children:M.label}),v?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm text-muted-foreground",children:M.description})]}),e.jsxs("div",{className:"grid gap-2 sm:flex sm:items-start",children:[e.jsx(L,{variant:"ghost",size:"sm",className:"h-7 w-full px-2 text-xs sm:w-auto",disabled:!f,onClick:()=>{f&&a(f)},children:h("common.edit")}),M.canDelete?e.jsx("button",{type:"button",onClick:j=>{j.stopPropagation(),f&&x({kind:"endpoint",endpoint:f})},className:"flex h-7 w-full items-center justify-center rounded-full border border-transparent text-muted-foreground transition hover:border-destructive/20 hover:bg-destructive/10 hover:text-destructive sm:w-7",title:h("common.delete"),children:e.jsx(Se,{className:"h-3.5 w-3.5"})}):null]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(M.protocols??[]).map(j=>e.jsx(H,{variant:"outline",className:"max-w-full truncate text-[11px]",children:Ke(j,h)},`${M.key}-${j}`)),e.jsx(H,{variant:(f==null?void 0:f.enabled)===!1?"secondary":"success",className:"text-[11px]",children:(f==null?void 0:f.enabled)===!1?h("modelManagement.overview.endpointDisabled"):h("modelManagement.overview.endpointEnabled")})]}),f!=null&&f.paths&&f.paths.length>0?e.jsxs("div",{className:"space-y-1 rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:[f.paths.slice(0,2).map(j=>e.jsxs("div",{className:"truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:j.path})," · ",Ke(j.protocol,h)]},`${f.id}-${j.path}-${j.protocol}`)),f.paths.length>2?e.jsx("div",{children:h("modelManagement.overview.endpointMorePaths",{count:f.paths.length-2})}):null]}):f!=null&&f.path?e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:f.path})," · ",Ke(f.protocol??"anthropic",h)]}):null,e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:(b=M.protocols)!=null&&b.length?h("modelManagement.overview.endpointProtocols",{count:M.protocols.length}):h("modelManagement.overview.endpointNoProtocol")}),M.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground",children:h("modelManagement.overview.endpointManagedExternally")})]},M.key)})})})]}):null]})})}function it({description:s,title:t}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-foreground",children:s})]})}function Ae({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 truncate text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Bs({dialog:s,currentRoutes:t,onConfirm:c,onClose:g}){const{t:d}=te();if(!s)return null;const{endpoint:x,preset:a}=s,o=a.modelRoutes??{},m={};for(const C of t){const v=C.source.trim(),f=C.target.trim();v&&f&&(m[v]=f)}const u=new Set([...Object.keys(m),...Object.keys(o)]),h=[],F=[],k=[];for(const C of u){const v=C in m,f=C in o;f&&!v?h.push([C,o[C]]):v&&!f?F.push([C,m[C]]):v&&f&&m[C]!==o[C]&&k.push([C,m[C],o[C]])}const M=h.length>0||F.length>0||k.length>0;return e.jsx(vt,{open:!0,onOpenChange:C=>!C&&g(),children:e.jsxs(jt,{className:"max-w-2xl",children:[e.jsxs(yt,{children:[e.jsx(Nt,{children:d("modelManagement.presets.diffTitle")}),e.jsx(wt,{children:d("modelManagement.presets.diffDescription",{name:a.name})})]}),e.jsx(Mt,{children:M?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-lg border border-border bg-secondary p-3 text-sm",children:[h.map(([C,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-2 py-1.5 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",children:[e.jsx(H,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:d("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`add-${C}`)),F.map(([C,v])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-red-50 px-2 py-1.5 text-red-800 dark:bg-red-950 dark:text-red-200",children:[e.jsx(H,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:d("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:v})]},`rm-${C}`)),k.map(([C,v,f])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-amber-50 px-2 py-1.5 text-amber-800 dark:bg-amber-950 dark:text-amber-200",children:[e.jsx(H,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:d("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:v}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:f})]},`chg-${C}`))]}):e.jsx("p",{className:"rounded-lg border border-border bg-secondary py-8 text-center text-sm text-muted-foreground",children:d("modelManagement.presets.diffEmpty")})}),e.jsxs(kt,{children:[e.jsx(L,{variant:"outline",onClick:g,children:d("common.cancel")}),e.jsx(L,{onClick:()=>c(x,a),disabled:!M,children:d("modelManagement.presets.diffConfirm")})]})]})})}function Ct({eyebrow:s,title:t,description:c,breadcrumb:g,aside:d}){return e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[e.jsx("span",{children:s}),g.map((x,a)=>e.jsxs(hs.Fragment,{children:[a>0?e.jsx(xt,{className:"h-3.5 w-3.5"}):null,e.jsx("span",{className:oe(a===g.length-1&&"text-foreground"),children:x})]},`${x}-${a}`))]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-[-0.03em] text-foreground",children:t}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm text-muted-foreground",children:c})]})]}),d?e.jsx("div",{className:"w-full shrink-0 lg:w-auto",children:d}):null]})}const Hs=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],Is=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function ne(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Qe(s,t){var c;return(c=s==null?void 0:s.customEndpoints)!=null&&c.length?s.customEndpoints:t}function ze(s){return s?Object.entries(s).map(([t,c])=>({id:ne(),source:t,target:c})):[]}function Ve(s,t){var d,x,a;if(!s)return{};const c={},g=s.endpointRouting??{};c.anthropic=ze(((d=g.anthropic)==null?void 0:d.modelRoutes)??s.modelRoutes??{}),c.openai=ze(((x=g.openai)==null?void 0:x.modelRoutes)??{});for(const o of Qe(s,t))(a=o.routing)!=null&&a.modelRoutes?c[o.id]=ze(o.routing.modelRoutes):c[o.id]=[];return c}function ct(s,t,c){var x,a,o;const g=Qe(s,t).find(m=>m.id===c);if(g)return((x=g.routing)==null?void 0:x.modelRoutes)??{};const d=s.endpointRouting??{};return c==="anthropic"?((a=d.anthropic)==null?void 0:a.modelRoutes)??s.modelRoutes??{}:c==="openai"?((o=d.openai)==null?void 0:o.modelRoutes)??{}:{}}function Ks(s){const t={};for(const c of s){const g=c.source.trim(),d=c.target.trim();g&&d&&(t[g]=d)}return t}function mt(s,t){return JSON.stringify(Ks(s))!==JSON.stringify(t)}function zs(s,t){if(s==="anthropic")return!0;const c=t.find(g=>g.id===s);return c?c.paths&&c.paths.length>0?c.paths.some(g=>g.protocol==="anthropic"):c.protocol==="anthropic":!1}function Vs(s,t,c){var d,x,a;if(!t)return;if(s==="anthropic"||s==="openai")return(x=(d=t.endpointRouting)==null?void 0:d[s])==null?void 0:x.validation;const g=Qe(t,c).find(o=>o.id===s);return(a=g==null?void 0:g.routing)==null?void 0:a.validation}function _s(s,t){const c=[{key:"providers",label:s("modelManagement.tabs.providers"),description:s("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:s("modelManagement.tabs.anthropic"),description:s("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:s("modelManagement.tabs.openai"),description:s("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],g=t.map(d=>{let x=s("modelManagement.tabs.customEndpoint"),a=[];if(d.paths&&d.paths.length>0)x=`${s("modelManagement.tabs.customEndpoint")}: ${d.paths.map(o=>`${o.path} (${o.protocol})`).join(", ")}`,a=[...new Set(d.paths.map(o=>o.protocol))];else if(d.path){const o=d.protocol||"anthropic";x=`${s("modelManagement.tabs.customEndpoint")}: ${d.path} (${o})`,a=[o]}return{key:d.id,label:d.label||d.id,description:x,isSystem:!1,canDelete:d.deletable!==!1,protocols:a}});return[...c,...g]}function Et(s){return s.label&&s.label.trim().length>0?`${s.label} (${s.id})`:s.id}function qs({providerCount:s,providersLength:t,filteredProviders:c,defaultLabels:g,providerSearch:d,providerTypeFilter:x,configPending:a,configFetching:o,testingProviderId:m,onRefresh:u,onOpenCreate:h,onOpenEdit:F,onTestConnection:k,onRequestDelete:M,onProviderSearchChange:C,onProviderTypeChange:v,onResetFilters:f}){const{t:b}=te();return e.jsx(Fe,{children:e.jsxs(Be,{className:"space-y-6 pt-6",children:[e.jsx(Ct,{eyebrow:"Model Access",title:b("providers.title"),description:b("providers.description"),breadcrumb:[b("modelManagement.title"),b("modelManagement.tabs.providers")],aside:e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-2 sm:w-auto sm:gap-3",children:[e.jsx(H,{variant:"secondary",children:b("providers.count",{count:s})}),e.jsxs(L,{variant:"outline",size:"sm",onClick:u,disabled:o,className:"w-full sm:w-auto",children:[e.jsx(fs,{className:oe("mr-2 h-4 w-4",o&&"animate-spin")}),b(o?"common.actions.refreshing":"providers.actions.refresh")]}),e.jsxs(L,{size:"sm",onClick:h,className:"w-full sm:w-auto",children:[e.jsx(pt,{className:"mr-2 h-4 w-4"}),b("providers.actions.add")]})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsx(_e,{label:"Configured",value:s.toString(),helper:"Total providers in supply pool",tone:"blue"}),e.jsx(_e,{label:"Visible",value:c.length.toString(),helper:"Providers matching current filter",tone:"emerald"}),e.jsx(_e,{label:"Connection Status",value:m?"Testing":"Idle",helper:m?`Testing ${m}`:"Ready for diagnostics",tone:"amber"})]}),e.jsxs("div",{className:"rounded-lg border border-border bg-accent px-4 py-3 text-sm text-primary",children:[e.jsx("p",{className:"font-medium",children:b("modelManagement.providersSemantics.title")}),e.jsx("p",{className:"mt-1 leading-6 text-primary/80",children:b("modelManagement.providersSemantics.description")})]}),e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border bg-secondary p-4 sm:grid-cols-2 xl:grid-cols-[minmax(0,1fr)_220px_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.filters.searchPlaceholder")}),e.jsx(fe,{value:d,onChange:j=>C(j.target.value),placeholder:b("providers.filters.searchPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.filters.typeAll")}),e.jsxs(gt,{value:x,onValueChange:v,children:[e.jsx(ht,{children:e.jsx(ft,{})}),e.jsxs(bt,{children:[e.jsx(me,{value:"all",children:b("providers.filters.typeAll")}),e.jsx(me,{value:"openai",children:"OpenAI"}),e.jsx(me,{value:"anthropic",children:"Anthropic"}),e.jsx(me,{value:"deepseek",children:"DeepSeek"}),e.jsx(me,{value:"huawei",children:"Huawei"}),e.jsx(me,{value:"kimi",children:"Kimi"}),e.jsx(me,{value:"custom",children:"Custom"})]})]})]}),e.jsx("div",{className:"flex items-end sm:col-span-2 xl:col-span-1",children:e.jsx(L,{variant:"ghost",size:"sm",onClick:f,disabled:!d.trim()&&x==="all",className:"w-full xl:w-auto",children:b("common.actions.reset")})})]}),a?e.jsx("div",{className:"flex min-h-[200px] items-center justify-center rounded-lg border border-border bg-secondary text-sm text-muted-foreground",children:b("common.loading")}):t===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:b("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:b("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):c.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:e.jsx("p",{className:"font-medium",children:b("providers.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4 [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:c.map(j=>{var Q;return e.jsx(Fe,{className:"flex flex-col overflow-hidden","data-testid":"provider-card",children:e.jsxs(Be,{className:"flex flex-1 flex-col gap-4 pt-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold tracking-[-0.02em]",children:j.label||j.id}),j.type?e.jsx(Ws,{type:j.type}):null]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",j.id]}),e.jsx("code",{className:"block max-w-full break-all rounded-lg border border-border bg-secondary px-2.5 py-1.5 text-[11px] text-muted-foreground",children:j.baseUrl})]}),j.defaultModel?e.jsx(H,{variant:"default",className:"text-xs",children:g.get(j.id)??j.defaultModel}):e.jsx(H,{variant:"secondary",className:"text-xs",children:b("providers.card.noDefault")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(Ce,{label:b("providers.card.authMode"),value:j.authMode==="authToken"?"Bearer":j.authMode==="xAuthToken"?"X-Auth-Token":"API Key"}),e.jsx(Ce,{label:b("providers.card.modelsTitle"),value:(Q=j.models)!=null&&Q.length?b("providers.card.modelCount",{count:j.models.length}):b("providers.card.passthrough")}),e.jsx(Ce,{label:b("providers.card.defaultModelLabel"),value:j.defaultModel?g.get(j.id)??j.defaultModel:b("providers.card.noDefault"),truncate:!0})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsx(Ce,{label:"Routing readiness",value:j.defaultModel?"Ready":"Needs default"}),e.jsx(Ce,{label:"Endpoint type",value:j.type?j.type:"custom"})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-3",children:[e.jsx(J,{className:"text-xs uppercase tracking-[0.16em] text-muted-foreground",children:b("providers.card.modelsTitle")}),j.models&&j.models.length>0?e.jsx("div",{className:"flex max-h-24 flex-wrap gap-1 overflow-y-auto",children:j.models.map(Y=>e.jsx(H,{variant:"outline",className:"text-xs",children:Et(Y)},Y.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:b("providers.card.noModels")})]}),e.jsxs("div",{className:"mt-auto grid gap-2 border-t border-border pt-4 sm:grid-cols-3",children:[e.jsx(L,{variant:"default",size:"sm",onClick:()=>F(j),className:"w-full",children:b("providers.actions.edit")}),e.jsx(L,{variant:"outline",size:"sm",onClick:()=>k(j),disabled:m===j.id,className:"w-full",children:m===j.id?b("common.actions.testingConnection"):b("providers.actions.test")}),e.jsx(L,{variant:"destructive",size:"sm",onClick:()=>M(j),className:"w-full",children:b("providers.actions.delete")})]})]})},j.id)})})]})})}function _e({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Ce({label:s,value:t,truncate:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-[0.16em] text-muted-foreground",children:s}),e.jsx("p",{className:oe("mt-1 text-sm font-medium",c&&"truncate"),children:t})]})}function Ws({type:s}){const t={openai:{label:"OpenAI",variant:"success"},deepseek:{label:"DeepSeek",variant:"info"},huawei:{label:"华为云",variant:"warning"},kimi:{label:"Kimi",variant:"purple"},anthropic:{label:"Anthropic",variant:"pink"},custom:{label:"Custom",variant:"secondary"}},{label:c,variant:g}=t[s]||t.custom;return e.jsx(H,{variant:g,className:"text-xs",children:c})}function Qs({value:s,onChange:t,options:c,disabled:g,placeholder:d}){const{t:x}=te(),[a,o]=N.useState(!1),[m,u]=N.useState(""),h=N.useMemo(()=>{if(!m.trim())return c;const k=m.toLowerCase();return c.filter(M=>M.label.toLowerCase().includes(k)||M.value.toLowerCase().includes(k))},[c,m]),F=k=>{t(k),u(""),o(!1)};return e.jsxs(Es,{open:a,onOpenChange:k=>{o(k),k&&u("")},children:[e.jsx(Ss,{asChild:!0,children:e.jsx(fe,{value:s,onChange:k=>{t(k.target.value),u(k.target.value),a||o(!0)},onFocus:()=>{u(""),o(!0)},onClick:()=>{a||o(!0)},placeholder:d,disabled:g,autoComplete:"off"})}),e.jsx(Ps,{className:"max-h-60 w-[var(--radix-popover-trigger-width)] overflow-y-auto p-1",align:"start",onOpenAutoFocus:k=>k.preventDefault(),children:h.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:x("common.noMatches")}):h.map(k=>e.jsx("button",{type:"button",className:oe("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",k.value===s.trim()&&"bg-accent"),onMouseDown:M=>{M.preventDefault(),F(k.value)},children:e.jsx("span",{className:"truncate",children:k.label})},k.value))})]})}function Gs({endpoint:s,tabs:t,customEndpoints:c,config:g,routes:d,routeError:x,savingRoute:a,isDirty:o,presets:m,presetName:u,presetError:h,savingPreset:F,applyingPreset:k,deletingPreset:M,presetsExpanded:C,savingClaudeValidation:v,providerModelOptions:f,onTogglePresetsExpanded:b,onPresetNameChange:j,onSavePreset:Q,onRequestPresetDiff:Y,onRequestDeletePreset:ue,onToggleClaudeValidation:le,onRouteChange:Z,onRemoveRoute:V,onAddSuggestion:pe,onAddRoute:G,onResetRoutes:we,onSaveRoutes:be}){var B,X;const{t:T}=te(),I=t.find(A=>A.key===s),se=((B=I==null?void 0:I.protocols)==null?void 0:B.includes("anthropic"))??s==="anthropic"?Hs:Is,xe=(I==null?void 0:I.label)??s,ie=(I==null?void 0:I.isSystem)===!1?I.description:T(`settings.routing.descriptionByEndpoint.${s}`),ge=`route-source-${s}`,i=zs(s,c),E=Vs(s,g,c),R=i&&(E==null?void 0:E.mode)==="claude-code",P=new Set(d.map(A=>A.source.trim()).filter(Boolean));return e.jsx(Fe,{children:e.jsxs(Be,{className:"space-y-6 pt-6",children:[e.jsx(Ct,{eyebrow:"Routing Workspace",title:T("settings.routing.titleByEndpoint",{endpoint:xe}),description:ie,breadcrumb:[T("modelManagement.title"),xe],aside:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(H,{variant:"outline",children:[d.length," rules"]}),o?e.jsx(H,{variant:"outline",className:"border-amber-300 text-amber-700 dark:border-amber-700 dark:text-amber-300",children:T("modelManagement.actions.unsaved")}):e.jsx(H,{variant:"secondary",children:T("common.status.success")})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(Ue,{label:"Rules",value:d.length.toString(),helper:"Current model routes",tone:"blue"}),e.jsx(Ue,{label:"Presets",value:m.length.toString(),helper:"Reusable routing templates",tone:"emerald"}),e.jsx(Ue,{label:"Protocols",value:(((X=I==null?void 0:I.protocols)==null?void 0:X.length)??0).toString(),helper:"Bound to this endpoint",tone:"amber"}),e.jsx(Ue,{label:"Validation",value:i?R?"Claude Code":"Disabled":"Standard",helper:i?"Anthropic compatibility mode":"Default endpoint routing",tone:"rose"})]}),e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:T("settings.routing.wildcardHint")}),i?e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary",children:T("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-primary/80",children:T("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex items-center gap-2 self-start sm:self-auto",children:[e.jsx(qe,{checked:R,onCheckedChange:le,disabled:v}),e.jsx("span",{className:oe("text-xs font-medium",R?"text-emerald-600 dark:text-emerald-400":"text-muted-foreground"),children:T(R?"modelManagement.claudeValidation.statusEnabled":"modelManagement.claudeValidation.statusDisabled")})]})]})}):null,x?e.jsx("p",{className:"text-sm text-destructive",children:x}):null,e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"text-sm font-semibold text-foreground",children:T("modelManagement.routesEditorTitle")}),e.jsxs(H,{variant:"outline",children:[d.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:T("modelManagement.overview.routesEditorHint")})]}),e.jsxs("div",{className:"self-start rounded-lg border border-border bg-card px-3 py-2 text-[11px] text-muted-foreground",children:[xe," workspace"]})]}),d.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:T("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:T("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"hidden grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground md:grid",children:[e.jsx("span",{children:T("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:T("settings.routing.target")}),e.jsx("span",{})]}),d.map((A,q)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-3",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between md:hidden",children:[e.jsxs(H,{variant:"outline",className:"text-[11px]",children:["#",q+1]}),e.jsx(L,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>V(A.id),disabled:a,children:e.jsx(Se,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] md:items-center",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:T("settings.routing.source")}),e.jsx(fe,{value:A.source,onChange:de=>Z(A.id,"source",de.target.value),placeholder:T("settings.routing.sourcePlaceholder"),list:ge,disabled:a,"aria-label":`route-source-${q+1}`})]}),e.jsx(Ne,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:T("settings.routing.target")}),e.jsx(Qs,{value:A.target,onChange:de=>Z(A.id,"target",de),options:f,disabled:a,placeholder:T("settings.routing.targetPlaceholder")})]}),e.jsx(L,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>V(A.id),disabled:a,children:e.jsx(Se,{className:"h-4 w-4"})})]})]},A.id))]})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-secondary p-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"text-sm font-semibold text-foreground",children:T("settings.routing.suggested")}),e.jsxs(H,{variant:"outline",children:[se.length," presets"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:T("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:se.map(A=>{const q=P.has(A);return e.jsx(L,{variant:q?"ghost":"outline",size:"sm",onClick:()=>pe(A),disabled:a||q,className:q?"opacity-50":"",children:A},`${s}-${A}`)})})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-card p-4 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:T("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:T(o?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3 md:flex md:flex-wrap md:items-center",children:[e.jsx(L,{variant:"outline",size:"sm",onClick:G,disabled:a,className:"w-full",children:T("settings.routing.add")}),e.jsx(L,{variant:"outline",size:"sm",onClick:we,disabled:a||!o,className:"w-full",children:T("common.actions.reset")}),e.jsxs(L,{size:"sm",onClick:be,disabled:a,className:"relative w-full",children:[T(a?"common.actions.saving":"modelManagement.actions.saveRoutes"),o?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsx(Xs,{presets:m,presetName:u,presetError:h,savingPreset:F,applyingPreset:k,deletingPreset:M,expanded:C,onToggleExpanded:b,onPresetNameChange:j,onSavePreset:Q,onRequestPresetDiff:Y,onRequestDeletePreset:ue}),e.jsx("datalist",{id:ge,children:se.map(A=>e.jsx("option",{value:A},`${ge}-${A}`))})]})})}function Ue({helper:s,label:t,value:c}){return e.jsxs("div",{className:"rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:t}),e.jsx("p",{className:"mt-2 truncate text-base font-semibold text-foreground",children:c}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s})]})}function Xs({presets:s,presetName:t,presetError:c,savingPreset:g,applyingPreset:d,deletingPreset:x,expanded:a,onToggleExpanded:o,onPresetNameChange:m,onSavePreset:u,onRequestPresetDiff:h,onRequestDeletePreset:F}){const{t:k}=te();return e.jsxs("div",{className:"rounded-lg border border-dashed border-border bg-card",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 p-4 text-left transition-colors hover:bg-primary/5",onClick:o,children:e.jsxs("div",{className:"flex items-center gap-2",children:[a?e.jsx(bs,{className:"h-4 w-4"}):e.jsx(xt,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:k("modelManagement.presets.title")}),e.jsx(H,{variant:"secondary",className:"text-xs",children:s.length})]})}),a?e.jsxs("div",{className:"space-y-4 border-t px-4 pb-4 pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:k("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(fe,{value:t,onChange:M=>m(M.target.value),placeholder:k("modelManagement.presets.namePlaceholder"),disabled:g,className:"w-full md:w-48"}),e.jsx(L,{onClick:u,disabled:g,className:"w-full md:w-auto",children:k(g?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),c?e.jsx("p",{className:"text-sm text-destructive",children:c}):null,s.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:k("modelManagement.presets.empty")}):e.jsx(Ns,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:s.map(M=>{const C=d===M.name,v=x===M.name,f=Object.entries(M.modelRoutes??{}),b=f.length;return e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-border bg-secondary px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(ws,{children:[e.jsx(Ms,{asChild:!0,children:e.jsxs("div",{className:"min-w-0 flex-1 cursor-default",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:M.name}),e.jsx(H,{variant:"outline",className:"mt-1 text-xs",children:b>0?k("modelManagement.presets.rulesCount",{count:b}):k("modelManagement.presets.noRules")})]})}),b>0?e.jsx(ks,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[f.slice(0,5).map(([j,Q])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:j}),e.jsx(Ne,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:Q})]},j)),b>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",b-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(L,{size:"sm",onClick:()=>h(M),disabled:C||v,className:"w-full sm:w-auto",children:k(C?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(L,{variant:"destructive",size:"sm",onClick:()=>F(M),disabled:v||C,className:"w-full sm:w-auto",children:k(v?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},M.name)})})})]}):null]})}function Js({open:s,provider:t,options:c,usePreset:g,preservedExtras:d,onPresetChange:x,onConfirm:a,onClose:o}){const{t:m}=te();return t?e.jsx(vt,{open:s,onOpenChange:u=>!u&&o(),children:e.jsxs(jt,{className:"max-w-2xl",children:[e.jsxs(yt,{children:[e.jsx(Nt,{children:m("providers.testDialog.title")}),e.jsx(wt,{children:m("providers.testDialog.subtitle",{name:t.label||t.id})})]}),e.jsxs(Mt,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4 text-sm text-primary",children:m("providers.testDialog.description")}),e.jsxs("div",{className:"space-y-4 rounded-lg border border-border bg-secondary 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(J,{htmlFor:"provider-test-preset",children:m("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.testDialog.presetDescription")})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(qe,{id:"provider-test-preset",checked:g,onCheckedChange:x})})]}),g?e.jsx("div",{className:"space-y-2",children:e.jsxs("details",{className:"rounded-lg border border-border bg-secondary p-2 text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-primary hover:underline",children:m("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:c.map(u=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1 text-xs",children:[u.key,": ",u.value]},u.key))})]})}):e.jsx("p",{className:"text-xs text-muted-foreground",children:m("providers.testDialog.presetDescription")})]}),Object.keys(d).length>0&&e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-4 text-xs",children:[e.jsx("p",{className:"font-medium",children:m("providers.testDialog.preservedInfo")}),Object.entries(d).map(([u,h])=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1",children:[u,": ",h]},u))]})]}),e.jsxs(kt,{children:[e.jsx(L,{variant:"outline",onClick:o,children:m("providers.testDialog.cancel")}),e.jsx(L,{onClick:()=>void a(),children:m("providers.testDialog.primary")})]})]})}):null}const $e={savePreset(s,t){return Re(Te.post(`/api/routing-presets/${s}`,{name:t}))},applyPreset(s,t){return Re(Te.post(`/api/routing-presets/${s}/apply`,{name:t}))},deletePreset(s,t){return Re(Te.delete(`/api/routing-presets/${s}/${encodeURIComponent(t)}`))},testProvider(s,t){return Re(Te.post(`/api/providers/${s}/test`,t))}};function ut(s,t){var g,d,x;const c={anthropic:((g=s.routingPresets)==null?void 0:g.anthropic)??[],openai:((d=s.routingPresets)==null?void 0:d.openai)??[]};for(const a of t){const o=(x=s.customEndpoints)==null?void 0:x.find(m=>m.id===a.id);c[a.id]=(o==null?void 0:o.routingPresets)??a.routingPresets??[]}return c}function Ys(){var at;const{t:s}=te(),{pushToast:t}=Cs(),c=Ds(),g=Ts(he.config.full(),ye.configRequest()),x=((at=Rs({queryKey:he.customEndpoints.all(),queryFn:Ee.list,refetchInterval:1e4}).data)==null?void 0:at.endpoints)??[],a=N.useMemo(()=>_s(s,x),[x,s]),[o,m]=N.useState("providers"),[u,h]=N.useState(null),[F,k]=N.useState(!1),[M,C]=N.useState("create"),[v,f]=N.useState(void 0),[b,j]=N.useState(void 0),[Q,Y]=N.useState(null),[ue,le]=N.useState(!1),[Z,V]=N.useState({}),[pe,G]=N.useState({}),[we,be]=N.useState(null),[T,I]=N.useState({}),[Me,se]=N.useState({}),[xe,ie]=N.useState({}),[ge,i]=N.useState(null),[E,R]=N.useState(null),[P,B]=N.useState(null),[X,A]=N.useState(!1),[q,de]=N.useState(null),[re,He]=N.useState(!0),[Ge,Xe]=N.useState({}),[St,Je]=N.useState(!1),[Pt,Dt]=N.useState({}),[Rt,Tt]=N.useState(null),[S,Ye]=N.useState(null),[Ot,Ze]=N.useState(!1),[Ie,At]=N.useState(""),[Pe,Ut]=N.useState("all"),$t=N.useMemo(()=>a.filter(r=>r.isSystem),[a]),Lt=N.useMemo(()=>a.filter(r=>!r.isSystem),[a]),Ft=N.useMemo(()=>a.find(r=>r.key===o)??a[0]??null,[o,a]),ee=(u==null?void 0:u.providers)??[],Bt=ee.length,Ht=N.useMemo(()=>ee.filter(r=>{var w;if(!(Pe==="all"||(r.type??"custom")===Pe))return!1;const n=Ie.trim().toLowerCase();return n?[r.id,r.label??"",r.baseUrl,r.defaultModel??"",...((w=r.models)==null?void 0:w.map(y=>y.id))??[]].join(" ").toLowerCase().includes(n):!0}),[Ie,Pe,ee]),ke=N.useMemo(()=>[{key:"anthropic-beta",value:"claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",label:s("providers.testDialog.options.beta.label"),description:s("providers.testDialog.options.beta.description")}],[s]);N.useEffect(()=>{if(!g.data)return;const r=g.data;h(r),V(l=>{const n=Ve(r,x);if(!l||Object.keys(l).length===0)return n;const p={...n};for(const[w,y]of Object.entries(l)){if(!(w in n))continue;const D=ct(r,x,w);mt(y,D)&&(p[w]=y)}return p}),G({}),I(ut(r,x))},[g.data,x]),N.useEffect(()=>{!g.isError||!g.error||t({title:s("providers.toast.loadFailure",{message:g.error.message}),variant:"error"})},[g.error,g.isError,t,s]),N.useEffect(()=>{a.some(r=>r.key===o)||m("providers")},[o,a]);const It=N.useMemo(()=>{const r=new Map;for(const l of ee){if(!l.defaultModel||!l.models)continue;const n=l.models.find(p=>p.id===l.defaultModel);n&&r.set(l.id,Et(n))}return r},[ee]),Kt=N.useMemo(()=>{const r=[],l=new Set;for(const n of ee){const p=n.label&&n.label!==n.id?`${n.label} (${n.id})`:n.id,w=n.models??[];if(w.length>0)for(const D of w){const $=`${n.id}:${D.id}`;l.has($)||(l.add($),r.push({value:$,label:`${p} · ${D.label??D.id}`}))}else if(n.defaultModel){const D=`${n.id}:${n.defaultModel}`;l.has(D)||(l.add(D),r.push({value:D,label:`${p} · ${n.defaultModel}`}))}const y=`${n.id}:*`;l.has(y)||(l.add(y),r.push({value:y,label:s("settings.routing.providerPassthroughOption",{provider:p})}))}for(const n of Object.values(Z).flat()){const p=n.target.trim();p&&!l.has(p)&&(l.add(p),r.push({value:p,label:p}))}return r},[ee,Z,s]),zt=()=>{j(void 0),le(!0)},Vt=r=>{j(r),le(!0)},_t=r=>u?ct(u,x,r):{},qt=N.useMemo(()=>{const r={};for(const l of a){if(l.key==="providers")continue;const n=Z[l.key]||[];r[l.key]=mt(n,_t(l.key))}return r},[u,x,Z,a]),et=(r,l)=>{I(n=>({...n,[r]:l})),h(n=>{if(!n)return n;if(r==="anthropic"||r==="openai")return{...n,routingPresets:{...n.routingPresets,[r]:l}};const p=[...n.customEndpoints??[]],w=p.findIndex(y=>y.id===r);return w===-1?n:(p[w]={...p[w],routingPresets:l},{...n,customEndpoints:p})})},ce=()=>u?!0:(t({title:s("settings.toast.missingConfig"),variant:"error"}),g.refetch(),!1),Wt=(r,l)=>{se(n=>({...n,[r]:l})),l.trim()&&ie(n=>({...n,[r]:null}))},Qt=async r=>{if(!ce())return;const l=(Me[r]??"").trim();if(!l){ie(n=>({...n,[r]:s("modelManagement.validation.presetName")}));return}if((T[r]??[]).some(n=>n.name.toLowerCase()===l.toLowerCase())){ie(n=>({...n,[r]:s("modelManagement.validation.presetDuplicate",{name:l})}));return}i(r);try{const p=(await $e.savePreset(r,l)).presets??[];et(r,p),se(w=>({...w,[r]:""})),ie(w=>({...w,[r]:null})),t({title:s("modelManagement.toast.presetSaved",{name:l}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetSaveFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{i(null),g.refetch()}},Gt=async(r,l)=>{if(ce()){R({endpoint:r,name:l.name});try{const p=(await $e.applyPreset(r,l.name)).config;if(p)h(p),V(Ve(p,x)),I(ut(p,x));else{const w=l.modelRoutes??{};V(y=>({...y,[r]:Object.entries(w).map(([D,$])=>({id:ne(),source:D,target:$}))})),h(y=>{var $,U,O,K;if(!y)return y;const D=(y.customEndpoints??[]).findIndex(z=>z.id===r);if(D!==-1){const z=[...y.customEndpoints??[]],ae=z[D];return z[D]={...ae,routing:{defaults:(($=ae.routing)==null?void 0:$.defaults)??y.defaults,...ae.routing??{},modelRoutes:w}},{...y,customEndpoints:z}}return r==="anthropic"||r==="openai"?{...y,endpointRouting:{...y.endpointRouting??{},[r]:{defaults:((O=(U=y.endpointRouting)==null?void 0:U[r])==null?void 0:O.defaults)??y.defaults,...((K=y.endpointRouting)==null?void 0:K[r])??{},modelRoutes:w}},modelRoutes:r==="anthropic"?w:y.modelRoutes??{}}:y})}r!=="anthropic"&&r!=="openai"&&await c.invalidateQueries({queryKey:he.customEndpoints.all()}),t({title:s("modelManagement.toast.presetApplySuccess",{name:l.name}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetApplyFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{R(null),g.refetch()}}},Xt=async(r,l)=>{if(ce()){B({endpoint:r,name:l.name});try{const n=await $e.deletePreset(r,l.name);et(r,n.presets??[]),t({title:s("modelManagement.toast.presetDeleteSuccess",{name:l.name}),variant:"success"})}catch(n){t({title:s("modelManagement.toast.presetDeleteFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{B(null),g.refetch()}}},Jt=()=>{ce()&&(C("create"),f(void 0),k(!0))},Yt=r=>{ce()&&(C("edit"),f(r),k(!0))},Zt=async r=>{if(!u)throw new Error(s("settings.toast.missingConfig"));const l=M==="create"?[...ee,r]:ee.map(p=>v&&p.id===v.id?{...r,id:v.id}:p),n={...u,providers:l};await ye.saveConfig(n),h(n),V(Ve(n,x)),g.refetch(),t({title:M==="create"?s("providers.toast.createSuccess",{name:r.label||r.id}):s("providers.toast.updateSuccess",{name:r.label||r.id}),variant:"success"})},es=async r=>{const l=x.find(n=>n.id===r);if(!(!l||l.deletable===!1))try{await Ee.delete(r),await c.invalidateQueries({queryKey:he.customEndpoints.all()}),t({title:s("modelManagement.deleteEndpointSuccess"),variant:"success"}),o===r&&m("providers")}catch(n){const p=ot(n);t({title:s("modelManagement.deleteEndpointError",{error:p.message}),variant:"error"})}},tt=async(r,l)=>{Y(r.id);try{const n=l&&(l.headers||l.query)?{headers:l.headers&&Object.keys(l.headers).length>0?l.headers:void 0,query:l.query&&l.query.trim().length>0?l.query.trim():void 0}:void 0,p=await $e.testProvider(r.id,n);if(p.ok){t({title:s("providers.toast.testSuccess"),description:s("providers.toast.testSuccessDesc",{status:p.status,duration:p.durationMs?`${p.durationMs} ms`:"—"}),variant:"success"});return}t({title:s("providers.toast.testFailure",{message:`${p.status} ${p.statusText}`}),variant:"error"})}catch(n){t({title:s("providers.toast.testFailure",{message:n instanceof Error?n.message:"unknown"}),variant:"error"})}finally{Y(null)}},ts=r=>{if(r.type!=="anthropic"){tt(r);return}const l=r.extraHeaders??{},n=new Map(ke.map(y=>[y.key.toLowerCase(),y])),p={};let w=!0;for(const y of ke){const D=Object.entries(l).find(([O])=>O.toLowerCase()===y.key.toLowerCase());if(!D)continue;const[$,U]=D;String(U??"")!==y.value&&(w=!1,p[$]=String(U??""))}for(const[y,D]of Object.entries(l))n.has(y.toLowerCase())||(p[y]=String(D??""));Xe(p),He(w),de(r),A(!0)},st=()=>{A(!1),de(null),He(!0),Xe({})},ss=async()=>{if(!q)return;const r={};if(re)for(const p of ke)r[p.key]=p.value;const l=new Map(ke.map(p=>[p.key.toLowerCase(),p]));for(const[p,w]of Object.entries(Ge))l.get(p.toLowerCase())&&re||(r[p]=w);const n=q;st(),await tt(n,{headers:Object.keys(r).length>0?r:void 0,query:re?"beta=true":void 0})},rt=async r=>{var U,O,K,z,ae,De;if(!ce())return;const l=ee.filter(_=>_.id!==r.id),n=_=>{const W={};if(!_)return W;for(const[ve,je]of Object.entries(_)){if(!je)continue;const[nt]=je.split(":");nt&&nt===r.id||je===r.id||(W[ve]=je)}return W},p=(u==null?void 0:u.endpointRouting)??{},w=n(((U=p.anthropic)==null?void 0:U.modelRoutes)??(u==null?void 0:u.modelRoutes)??{}),y=n(((O=p.openai)==null?void 0:O.modelRoutes)??{}),D=((u==null?void 0:u.customEndpoints)??x).map(_=>{const W=_.routing,ve=W==null?void 0:W.modelRoutes;return ve?{..._,routing:{...W,defaults:W.defaults??u.defaults,modelRoutes:n(ve)}}:_}),$={...u,providers:l,modelRoutes:w,customEndpoints:D,endpointRouting:{anthropic:{defaults:((K=p.anthropic)==null?void 0:K.defaults)??u.defaults,modelRoutes:w,validation:(z=p.anthropic)==null?void 0:z.validation},openai:{defaults:((ae=p.openai)==null?void 0:ae.defaults)??u.defaults,modelRoutes:y,validation:(De=p.openai)==null?void 0:De.validation}}};try{await ye.saveConfig($),h($),V({anthropic:Object.entries(w).map(([_,W])=>({id:ne(),source:_,target:W})),openai:Object.entries(y).map(([_,W])=>({id:ne(),source:_,target:W})),...Object.fromEntries(D.map(_=>{var W;return[_.id,Object.entries(((W=_.routing)==null?void 0:W.modelRoutes)??{}).map(([ve,je])=>({id:ne(),source:ve,target:je}))]}))}),t({title:s("providers.toast.deleteSuccess",{name:r.label||r.id}),variant:"success"}),g.refetch()}catch(_){t({title:s("providers.toast.deleteFailure",{message:_ instanceof Error?_.message:"unknown"}),variant:"error"})}},rs=async()=>{if(S){Ze(!0);try{S.kind==="provider"?await rt(S.provider):S.kind==="preset"?await Xt(S.endpoint,S.preset):await es(S.endpoint.id),Ye(null)}finally{Ze(!1)}}},as=r=>{V(l=>({...l,[r]:[...l[r]||[],{id:ne(),source:"",target:""}]})),G(l=>({...l,[r]:null}))},ns=async(r,l)=>{var n,p;if(ce()){Je(!0);try{if(r==="anthropic"||r==="openai"){const w=r,y=u.endpointRouting?{...u.endpointRouting}:{},D=y[w]??{defaults:u.defaults,modelRoutes:(w==="anthropic"?u.modelRoutes:{})??{}},$={defaults:D.defaults??u.defaults,modelRoutes:D.modelRoutes??{}},U=l?{...D.validation??{},mode:"claude-code",allowExperimentalBlocks:((n=D.validation)==null?void 0:n.allowExperimentalBlocks)??!0}:void 0,O={...u,endpointRouting:{...y,[w]:U?{...$,validation:U}:{...$}}};await ye.saveConfig(O),h(O)}else{const w=[...u.customEndpoints??[]],y=w.findIndex(K=>K.id===r);if(y===-1)throw new Error(s("modelManagement.toast.endpointNotFound"));const D=w[y],$=D.routing??{defaults:u.defaults,modelRoutes:{}},U=l?{...$.validation??{},mode:"claude-code",allowExperimentalBlocks:((p=$.validation)==null?void 0:p.allowExperimentalBlocks)??!0}:void 0;w[y]={...D,routing:U?{...$,validation:U}:{defaults:$.defaults,modelRoutes:$.modelRoutes}};const O={...u,customEndpoints:w};await ye.saveConfig(O),h(O)}t({title:s(l?"modelManagement.toast.claudeValidationEnabled":"modelManagement.toast.claudeValidationDisabled"),variant:"success"}),g.refetch()}catch(w){const y=ot(w);t({title:s("modelManagement.toast.claudeValidationFailure",{message:y.message}),variant:"error"})}finally{Je(!1)}}},os=(r,l)=>{V(n=>{const p=n[r]||[];return p.some(w=>w.source.trim()===l.trim())?n:{...n,[r]:[...p,{id:ne(),source:l,target:""}]}}),G(n=>({...n,[r]:null}))},ds=(r,l,n,p)=>{V(w=>({...w,[r]:(w[r]||[]).map(y=>y.id===l?{...y,[n]:p}:y)})),G(w=>({...w,[r]:null}))},ls=(r,l)=>{V(n=>({...n,[r]:(n[r]||[]).filter(p=>p.id!==l)})),G(n=>({...n,[r]:null}))},is=r=>{var n;if(!u)return;const l=(u.customEndpoints??x).find(p=>p.id===r);if(l)V(p=>{var w;return{...p,[r]:Object.entries(((w=l.routing)==null?void 0:w.modelRoutes)??{}).map(([y,D])=>({id:ne(),source:y,target:D}))}});else{const p=u.endpointRouting??{},w=r,y=w==="anthropic"?u.modelRoutes??{}:{},D=((n=p[w])==null?void 0:n.modelRoutes)??y;V($=>({...$,[r]:Object.entries(D).map(([U,O])=>({id:ne(),source:U,target:O}))}))}G(p=>({...p,[r]:null}))},cs=Le({mutationFn:async r=>(await ye.saveConfig(r.nextConfig),r)}),ms=Le({mutationFn:async r=>(await Ee.update(r.endpoint,{routing:r.routing}),r)}),us=async r=>{var p,w,y,D,$;if(!ce())return;const l=Z[r]||[],n={};for(const U of l){const O=U.source.trim(),K=U.target.trim();if(!(!O&&!K)){if(!O||!K){G(z=>({...z,[r]:s("settings.validation.routePair")}));return}if(n[O]){G(z=>({...z,[r]:s("settings.validation.routeDuplicate",{model:O})}));return}n[O]=K}}G(U=>({...U,[r]:null})),be(r);try{const U=x.find(O=>O.id===r);if(U){const O={...U.routing??{},modelRoutes:n,defaults:((p=U.routing)==null?void 0:p.defaults)||u.defaults};await ms.mutateAsync({endpoint:r,routing:O}),h(K=>{if(!K)return K;const z=[...K.customEndpoints??[]],ae=z.findIndex(De=>De.id===r);return ae===-1?K:(z[ae]={...z[ae],routing:O},{...K,customEndpoints:z})}),await c.invalidateQueries({queryKey:he.customEndpoints.all()})}else{const O={...u,endpointRouting:{...u.endpointRouting??{},[r]:{defaults:((y=(w=u.endpointRouting)==null?void 0:w[r])==null?void 0:y.defaults)??u.defaults,modelRoutes:n,validation:($=(D=u.endpointRouting)==null?void 0:D[r])==null?void 0:$.validation}},modelRoutes:r==="anthropic"?n:u.modelRoutes??{}};await cs.mutateAsync({endpoint:r,nextConfig:O}),h(O)}V(O=>({...O,[r]:Object.entries(n).map(([K,z])=>({id:ne(),source:K,target:z}))})),t({title:s("modelManagement.toast.routesSaved"),variant:"success"}),g.refetch()}catch(U){t({title:s("modelManagement.toast.routesSaveFailure",{message:U instanceof Error?U.message:"unknown"}),variant:"error"})}finally{be(null)}},ps=(S==null?void 0:S.kind)==="provider"?s("providers.actions.delete"):(S==null?void 0:S.kind)==="preset"?s("modelManagement.presets.delete"):(S==null?void 0:S.kind)==="endpoint"?s("common.delete"):"",xs=(S==null?void 0:S.kind)==="provider"?s("providers.confirm.delete",{name:S.provider.label||S.provider.id}):(S==null?void 0:S.kind)==="preset"?s("modelManagement.confirm.deletePreset",{name:S.preset.name}):(S==null?void 0:S.kind)==="endpoint"?s("modelManagement.deleteEndpointConfirm",{label:S.endpoint.label}):"",gs=(S==null?void 0:S.kind)==="provider"?S.provider.label||S.provider.id:(S==null?void 0:S.kind)==="preset"?S.preset.name:(S==null?void 0:S.kind)==="endpoint"?S.endpoint.label:"";return{activeTab:o,activeTabInfo:Ft,anthropicTestHeaderOptions:ke,applyingPreset:E,config:u,configQuery:g,confirmAction:S,confirmDialogDescription:xs,confirmDialogName:gs,confirmDialogTitle:ps,confirmingAction:Ot,customEndpoints:x,customTabs:Lt,defaultLabels:It,deletingPreset:P,drawerMode:M,drawerOpen:F,editingEndpoint:b,editingProvider:v,endpointDrawerOpen:ue,filteredProviders:Ht,handleAddRoute:as,handleAddSuggestion:os,handleApplyPreset:Gt,handleConfirmDialog:rs,handleDeleteProvider:rt,handleOpenCreate:Jt,handleOpenCreateEndpoint:zt,handleOpenEditEndpoint:Vt,handleOpenEdit:Yt,handlePresetNameChange:Wt,handleProviderSubmit:Zt,handleRemoveRoute:ls,handleResetRoutes:is,handleRouteChange:ds,handleSavePreset:Qt,handleSaveRoutes:us,handleToggleClaudeValidation:ns,initiateTestConnection:ts,isDirtyByEndpoint:qt,presetDiffDialog:Rt,presetErrorByEndpoint:xe,presetNameByEndpoint:Me,presetsByEndpoint:T,presetsExpanded:Pt,providerCount:Bt,providerModelOptions:Kt,providerSearch:Ie,providerTypeFilter:Pe,providers:ee,pushToast:t,routeError:pe,routesByEndpoint:Z,savingClaudeValidation:St,savingPresetFor:ge,savingRouteFor:we,setActiveTab:m,setConfirmAction:Ye,setDrawerMode:C,setDrawerOpen:k,setEditingEndpoint:j,setEditingProvider:f,setEndpointDrawerOpen:le,setPresetDiffDialog:Tt,setPresetsExpanded:Dt,setProviderSearch:At,setProviderTypeFilter:Ut,setTestDialogUsePreset:He,systemTabs:$t,tabs:a,testDialogOpen:X,testDialogPreservedExtras:Ge,testDialogProvider:q,testDialogUsePreset:re,testingProviderId:Q,closeTestDialog:st,confirmTestDialog:ss}}function vr(){var x,a,o;const{t:s}=te(),t=Ys(),c=Object.values(t.isDirtyByEndpoint).filter(Boolean).length,g=Math.max(0,t.systemTabs.length-1)+t.customTabs.length,d=t.activeTab==="providers"?s("modelManagement.header.providersHelper"):s("modelManagement.header.routingHelper",{name:((x=t.activeTabInfo)==null?void 0:x.label)??t.activeTab});return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(ys,{icon:e.jsx(vs,{className:"h-5 w-5","aria-hidden":"true"}),title:s("modelManagement.title"),description:s("modelManagement.description"),eyebrow:"Routing Control",breadcrumb:"Gateway / Model Management",helper:d,badge:c>0?s("modelManagement.overview.unsavedCount",{count:c}):void 0,actions:e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:flex-row sm:flex-wrap sm:justify-end",children:[e.jsxs("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:[s("modelManagement.tabs.providers")," · ",t.providerCount," / ",s("modelManagement.overview.routeWorkspacesStat")," · ",g]}),e.jsx(L,{onClick:t.handleOpenCreateEndpoint,className:"w-full sm:w-auto",children:s("modelManagement.addEndpoint")})]})}),e.jsx(Fs,{activeTab:t.activeTab,activeTabInfo:t.activeTabInfo,customEndpoints:t.customEndpoints,customTabs:t.customTabs,isDirtyByEndpoint:t.isDirtyByEndpoint,onDeleteEndpoint:t.setConfirmAction,onEditEndpoint:t.handleOpenEditEndpoint,onSelectTab:t.setActiveTab,providerCount:t.providerCount,systemTabs:t.systemTabs}),t.activeTab==="providers"?e.jsx(qs,{configPending:t.configQuery.isPending||!t.config&&t.configQuery.isFetching,configFetching:t.configQuery.isFetching,defaultLabels:t.defaultLabels,filteredProviders:t.filteredProviders,onOpenCreate:t.handleOpenCreate,onOpenEdit:t.handleOpenEdit,onRefresh:()=>void t.configQuery.refetch(),onRequestDelete:m=>t.setConfirmAction({kind:"provider",provider:m}),onResetFilters:()=>{t.setProviderSearch(""),t.setProviderTypeFilter("all")},onProviderSearchChange:t.setProviderSearch,onProviderTypeChange:t.setProviderTypeFilter,onTestConnection:t.initiateTestConnection,providerCount:t.providerCount,providerSearch:t.providerSearch,providerTypeFilter:t.providerTypeFilter,providersLength:t.providers.length,testingProviderId:t.testingProviderId}):e.jsx(Gs,{endpoint:t.activeTab,applyingPreset:((a=t.applyingPreset)==null?void 0:a.endpoint)===t.activeTab?t.applyingPreset.name:null,config:t.config,customEndpoints:t.customEndpoints,deletingPreset:((o=t.deletingPreset)==null?void 0:o.endpoint)===t.activeTab?t.deletingPreset.name:null,isDirty:t.isDirtyByEndpoint[t.activeTab]??!1,onAddRoute:()=>t.handleAddRoute(t.activeTab),onAddSuggestion:m=>t.handleAddSuggestion(t.activeTab,m),onPresetNameChange:m=>t.handlePresetNameChange(t.activeTab,m),onRequestDeletePreset:m=>t.setConfirmAction({kind:"preset",endpoint:t.activeTab,preset:m}),onRequestPresetDiff:m=>t.setPresetDiffDialog({endpoint:t.activeTab,preset:m}),onRemoveRoute:m=>t.handleRemoveRoute(t.activeTab,m),onResetRoutes:()=>t.handleResetRoutes(t.activeTab),onRouteChange:(m,u,h)=>t.handleRouteChange(t.activeTab,m,u,h),onSavePreset:()=>void t.handleSavePreset(t.activeTab),onSaveRoutes:()=>void t.handleSaveRoutes(t.activeTab),onToggleClaudeValidation:m=>void t.handleToggleClaudeValidation(t.activeTab,m),onTogglePresetsExpanded:()=>t.setPresetsExpanded(m=>({...m,[t.activeTab]:!m[t.activeTab]})),presetError:t.presetErrorByEndpoint[t.activeTab],presetName:t.presetNameByEndpoint[t.activeTab]??"",presets:t.presetsByEndpoint[t.activeTab]??[],presetsExpanded:t.presetsExpanded[t.activeTab]===!0,providerModelOptions:t.providerModelOptions,routeError:t.routeError[t.activeTab],routes:t.routesByEndpoint[t.activeTab]||[],savingClaudeValidation:t.savingClaudeValidation,savingPreset:t.savingPresetFor===t.activeTab,savingRoute:t.savingRouteFor===t.activeTab,tabs:t.tabs}),e.jsx(Us,{open:t.drawerOpen,mode:t.drawerMode,provider:t.drawerMode==="edit"?t.editingProvider:void 0,existingProviderIds:t.providers.map(m=>m.id).filter(m=>t.drawerMode==="edit"&&t.editingProvider?m!==t.editingProvider.id:!0),onClose:()=>{t.setDrawerOpen(!1),t.setEditingProvider(void 0),t.setDrawerMode("create")},onSubmit:t.handleProviderSubmit}),e.jsx(Ls,{open:t.endpointDrawerOpen,endpoint:t.editingEndpoint,onClose:()=>{t.setEndpointDrawerOpen(!1),t.setEditingEndpoint(void 0)},onSuccess:()=>{t.configQuery.refetch()}}),e.jsx(Js,{open:t.testDialogOpen,provider:t.testDialogProvider,options:t.anthropicTestHeaderOptions,preservedExtras:t.testDialogPreservedExtras,usePreset:t.testDialogUsePreset,onPresetChange:t.setTestDialogUsePreset,onConfirm:t.confirmTestDialog,onClose:t.closeTestDialog}),e.jsx(Bs,{dialog:t.presetDiffDialog,currentRoutes:t.presetDiffDialog?t.routesByEndpoint[t.presetDiffDialog.endpoint]||[]:[],onConfirm:(m,u)=>{t.setPresetDiffDialog(null),t.handleApplyPreset(m,u)},onClose:()=>t.setPresetDiffDialog(null)}),e.jsx(js,{open:!!t.confirmAction,onOpenChange:m=>{!m&&!t.confirmingAction&&t.setConfirmAction(null)},title:t.confirmDialogTitle,description:t.confirmDialogDescription,confirmLabel:t.confirmingAction?s("common.actions.loading"):s("common.delete"),cancelLabel:s("common.actions.cancel"),loading:t.confirmingAction,onConfirm:t.handleConfirmDialog,children:t.confirmDialogName?e.jsx("div",{className:"rounded-[1rem] border border-destructive/20 bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground",children:t.confirmDialogName}):null})]})}export{vr as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./vendor-
|
|
1
|
+
import{j as e}from"./vendor-5iCEqDpV.js";import{c as i}from"./index-CYeQpt9d.js";import{B as c}from"./badge-B-TfGxGB.js";function u({icon:l,title:x,description:t,badge:a,eyebrow:s,breadcrumb:r,helper:d,actions:n,className:m}){return e.jsxs("div",{className:i("flex flex-col gap-5 rounded-lg border border-border bg-card p-5 sm:flex-row sm:items-start sm:justify-between",m),children:[e.jsxs("div",{className:"flex flex-1 flex-wrap items-start gap-4",children:[l&&e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-primary/10 text-primary",children:l}),e.jsxs("div",{className:"min-w-0 space-y-2",children:[(s||r)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:[s?e.jsx("span",{children:s}):null,s&&r?e.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/50"}):null,r?e.jsx("span",{className:"text-muted-foreground/90",children:r}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-[-0.02em]",children:x}),a&&e.jsx(c,{variant:"secondary",children:a})]}),t&&e.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:t}),d&&e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-xs text-muted-foreground",children:d})]})]}),n&&e.jsx("div",{className:"w-full shrink-0 self-start sm:w-auto",children:n})]})}export{u as P};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s}from"./vendor-
|
|
1
|
+
import{j as s}from"./vendor-5iCEqDpV.js";import{c as m}from"./index-CYeQpt9d.js";import{C as c,b as x,c as i,d as f,a as j}from"./card-I07afQF2.js";function b({title:a,description:e,eyebrow:d,actions:r,className:l,contentClassName:n,children:o}){const t=a||e||r;return s.jsxs(c,{className:m("overflow-hidden",l),children:[t&&s.jsxs(x,{className:"flex flex-col gap-4 border-b border-border bg-secondary sm:flex-row sm:items-start sm:justify-between sm:space-y-0",children:[s.jsxs("div",{className:"min-w-0 space-y-1.5",children:[d?s.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:d}):null,typeof a=="string"?s.jsx(i,{className:"text-base font-semibold",children:a}):a,e&&(typeof e=="string"?s.jsx(f,{children:e}):s.jsx("div",{className:"text-sm text-muted-foreground",children:e}))]}),r&&s.jsx("div",{className:"w-full shrink-0 sm:w-auto",children:r})]}),s.jsx(j,{className:m(!t&&"pt-6",t&&"pt-5",n),children:o})]})}export{b as P};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,P as c}from"./vendor-
|
|
1
|
+
import{j as e,P as c}from"./vendor-5iCEqDpV.js";import{c as i}from"./index-CYeQpt9d.js";const m={default:"border-border bg-secondary",primary:"border-primary/15 bg-accent",danger:"border-destructive/20 bg-destructive/10"},x={default:"bg-secondary text-primary",primary:"bg-primary/10 text-primary",danger:"bg-destructive/10 text-destructive"};function o({icon:r,title:s,description:t,action:a,className:d,compact:l=!1,tone:n="default"}){return e.jsxs("div",{className:i("flex flex-col items-center justify-center rounded-lg border border-dashed px-6 text-center",l?"min-h-[180px] py-8":"min-h-[260px] py-12",m[n],d),children:[r?e.jsx("div",{className:i("mb-4 flex h-12 w-12 items-center justify-center rounded-2xl",x[n]),children:r}):null,e.jsxs("div",{className:"max-w-xl space-y-1.5",children:[e.jsx("div",{className:"text-base font-semibold tracking-[-0.01em]",children:s}),t?e.jsx("div",{className:"text-sm text-muted-foreground",children:t}):null]}),a?e.jsx("div",{className:"mt-5 flex flex-wrap items-center justify-center gap-2",children:a}):null]})}function p({label:r,className:s,compact:t=!1}){return e.jsx(o,{className:s,compact:t,tone:"primary",icon:e.jsx(c,{className:"h-5 w-5 animate-spin","aria-hidden":"true"}),title:r})}export{p as P,o as a};
|