@chenpu17/cc-gw 0.8.4 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/web/dist/assets/{About-C_aKibBC.js → About-DI7ipumV.js} +1 -1
- package/src/web/dist/assets/{ApiKeys-DsAyIbwB.js → ApiKeys-p_HrxRk7.js} +1 -1
- package/src/web/dist/assets/{ConfirmDialog-z8FIBVOS.js → ConfirmDialog-8iSYQ7NE.js} +1 -1
- package/src/web/dist/assets/Dashboard-CjMh6Cr5.js +1 -0
- package/src/web/dist/assets/{DialogShell-Cdf4kRdb.js → DialogShell-CygWjkEa.js} +1 -1
- package/src/web/dist/assets/EChart-B2VLuu4H.js +1 -0
- package/src/web/dist/assets/{Events-D8BFNMmT.js → Events-BtwqpvkH.js} +1 -1
- package/src/web/dist/assets/{Help-CLnzpKCo.js → Help-Ch8s4btZ.js} +1 -1
- package/src/web/dist/assets/{Login-DaukwolD.js → Login-D8OeR4Ya.js} +1 -1
- package/src/web/dist/assets/{Logs-CxWTzBAj.js → Logs-seICabmw.js} +1 -1
- package/src/web/dist/assets/ModelManagement-bbVLSR-e.js +1 -0
- package/src/web/dist/assets/{PageHeader-bBBkQNPI.js → PageHeader-DKkO-Kdm.js} +1 -1
- package/src/web/dist/assets/{PageSection-Bkk2okl7.js → PageSection-D9se25qM.js} +1 -1
- package/src/web/dist/assets/{PageState-QEhNwS9Q.js → PageState-DSoiwsKr.js} +1 -1
- package/src/web/dist/assets/{Profiler-LHVe6wwO.js → Profiler-Brnhx0iq.js} +1 -1
- package/src/web/dist/assets/RoutingManagement-B5xsDNPf.js +1 -0
- package/src/web/dist/assets/{Settings-D7qUYpBC.js → Settings-CjMhqGQf.js} +1 -1
- package/src/web/dist/assets/{Skeleton-CCQlvfTP.js → Skeleton-C7Qi01SG.js} +1 -1
- package/src/web/dist/assets/{badge-dFhP0Qyo.js → badge-CkaH3uCO.js} +1 -1
- package/src/web/dist/assets/{card-BeBgk27f.js → card-Bem3kP2L.js} +1 -1
- package/src/web/dist/assets/{charts-core-B4zLPEwd.js → charts-core-D_rRW-0W.js} +1 -1
- package/src/web/dist/assets/{charts-engine-CmnAuZWT.js → charts-engine-BXnGh0aE.js} +1 -1
- package/src/web/dist/assets/{charts-react-C9hy6r5j.js → charts-react-t97X9Vfc.js} +1 -1
- package/src/web/dist/assets/{gateway-DWOrDCuI.js → gateway-DrmzHCwu.js} +1 -1
- package/src/web/dist/assets/{i18n-DJXLExhE.js → i18n-dgCQR_PB.js} +1 -1
- package/src/web/dist/assets/index--7y4K3jp.css +1 -0
- package/src/web/dist/assets/index-OvGsIZkZ.js +61 -0
- package/src/web/dist/assets/{input-BTCXiXUM.js → input-DCNoHAkn.js} +1 -1
- package/src/web/dist/assets/{label-DjpX-mjh.js → label-9kbpUKaR.js} +1 -1
- package/src/web/dist/assets/{popover-Brp8rADW.js → popover-BGkrY50i.js} +1 -1
- package/src/web/dist/assets/{query-CR1zzqi0.js → query-Db16w3tH.js} +1 -1
- package/src/web/dist/assets/{radix-BMe0_WA0.js → radix-D08JKSgz.js} +1 -1
- package/src/web/dist/assets/{router-cKa0BaP7.js → router-BURlSZbt.js} +2 -2
- package/src/web/dist/assets/{select-C3RskPYc.js → select-DS37xdev.js} +1 -1
- package/src/web/dist/assets/{switch-n7tI2AqZ.js → switch-DVok_beq.js} +1 -1
- package/src/web/dist/assets/{useApiQuery-olO5q8vr.js → useApiQuery-3ZHohr5l.js} +1 -1
- package/src/web/dist/assets/{useAppMutation-BJbRpdNF.js → useAppMutation-C2rsFjm5.js} +1 -1
- package/src/web/dist/assets/useModelManagementState-Irif8Gdi.js +1 -0
- package/src/web/dist/assets/{vendor-CseyjbPR.js → vendor-DfnQOGOQ.js} +46 -41
- package/src/web/dist/index.html +7 -7
- package/src/web/dist/assets/Dashboard-DVP7GTtz.js +0 -1
- package/src/web/dist/assets/EChart-BlZFJiWb.js +0 -1
- package/src/web/dist/assets/ModelManagement-D5SFzd2o.js +0 -1
- package/src/web/dist/assets/index-CXBZSNMv.css +0 -1
- package/src/web/dist/assets/index-wrD5MdRi.js +0 -61
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as f,j as e,am as We,an as Ge,a8 as Je,ao as Xe,al as Ze,V as Ye,T as et}from"./vendor-CseyjbPR.js";import{P as tt}from"./PageHeader-bBBkQNPI.js";import{c as v,B as E,b as st,u as ge,s as C,t as lt,a as T}from"./index-wrD5MdRi.js";import{B as M}from"./badge-dFhP0Qyo.js";import{C as Ee,a as _e}from"./card-BeBgk27f.js";import{I as ue}from"./input-BTCXiXUM.js";import{L as I}from"./label-DjpX-mjh.js";import{S as ee,a as te,b as se,c as le,d as L}from"./select-C3RskPYc.js";import{u as K}from"./i18n-DJXLExhE.js";import{D as at,A as rt,a as ot,b as it,c as nt,d as dt}from"./DialogShell-Cdf4kRdb.js";import{P as ct,a as xe}from"./PageState-QEhNwS9Q.js";import{c as mt}from"./clipboard-CALi6bTW.js";import{u as $}from"./useApiQuery-olO5q8vr.js";import{q as U}from"./queryKeys-BMvyDTQS.js";import{g as De,f as O,a as Fe,b as pt,c as z,d as ut,e as xt}from"./utils-BHook6QN.js";import{P as gt,a as ht,b as ft}from"./popover-Brp8rADW.js";import{T as bt}from"./Skeleton-CCQlvfTP.js";import{g as Se}from"./gateway-DWOrDCuI.js";import"./query-CR1zzqi0.js";import"./router-cKa0BaP7.js";import"./radix-BMe0_WA0.js";function yt({apiKeys:l,selected:t,onChange:i,disabled:n,className:c}){const{t:s}=K(),[r,h]=f.useState(!1),p=f.useRef(null);f.useEffect(()=>{if(!r)return;const o=a=>{var d;(d=p.current)!=null&&d.contains(a.target)||h(!1)};return window.addEventListener("mousedown",o),()=>window.removeEventListener("mousedown",o)},[r]);const j=f.useMemo(()=>{if(t.length===0)return[];const o=new Map;for(const a of l)o.set(a.id,a);return t.map(a=>{const d=o.get(a);return d?d.isWildcard?s("apiKeys.wildcard"):d.name:null}).filter(a=>!!a)},[l,t,s]),u=t.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:t.length}),y=o=>{t.includes(o)?i(t.filter(a=>a!==o)):i([...t,o])};return e.jsxs("div",{className:v("relative space-y-2",c),ref:p,children:[e.jsx(I,{children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>h(o=>!o),disabled:n||l.length===0,title:s("logs.filters.apiKeyHint"),className:v("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,j.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:j.join(", ")})]}),e.jsx("svg",{className:v("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:()=>i([]),disabled:t.length===0,className:"text-primary hover:underline disabled:opacity-40",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[l.map(o=>{const a=o.isWildcard?s("apiKeys.wildcard"):o.name,d=t.includes(o.id);return e.jsxs("label",{className:v("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",d&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:d,onChange:()=>y(o.id)}),e.jsx("span",{className:"truncate",children:a})]},o.id)}),l.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:s("logs.filters.apiKeyAll")})]})]})]})}function jt(l){const{t}=K(),{total:i,activeFilters:n,filtersExpanded:c,setFiltersExpanded:s,handleResetFilters:r,activeQuickView:h,applyQuickView:p,providerFilter:j,setProviderFilter:u,endpointFilter:y,setEndpointFilter:o,selectedApiKeys:a,setSelectedApiKeys:d,modelFilter:k,setModelFilter:x,statusFilter:R,setStatusFilter:D,fromDate:S,setFromDate:_,toDate:w,setToDate:b,providerOptions:B,apiKeys:re,apiKeysLoading:oe,customEndpoints:W}=l;return e.jsx(Ee,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(_e,{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(M,{variant:"outline",children:t("logs.summary.total",{value:i.toLocaleString()})}),n.length>0&&e.jsx(M,{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(g=>!g),children:c?e.jsxs(e.Fragment,{children:[t("common.filters.collapse"),e.jsx(We,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[t("common.filters.expand"),e.jsx(Ge,{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(g=>e.jsxs(M,{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:g.onRemove,onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),g.onRemove())},children:[g.label,e.jsx(Je,{className:"h-3 w-3","aria-hidden":"true"})]},g.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:j==="all"?t("common.noData"):"1"}),e.jsx(Y,{label:t("logs.filters.endpoint"),value:y==="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(g=>e.jsx(E,{variant:h===g?"default":"outline",size:"sm",className:v("rounded-full border-transparent",h===g&&g==="all"&&"bg-foreground text-background hover:bg-foreground/90",h===g&&g==="errors"&&"bg-rose-500 text-white hover:bg-rose-500/90",h===g&&g==="today"&&"bg-emerald-500 text-white hover:bg-emerald-500/90",h===g&&(g==="anthropic"||g==="openai")&&"bg-amber-500 text-white hover:bg-amber-500/90"),onClick:()=>p(g),children:t(`logs.quickViews.${g}`)},g))})]}),c&&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:j,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(g=>e.jsx(L,{value:g.id,children:g.label??g.id},g.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endpoint")}),e.jsxs(ee,{value:y,onValueChange:o,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(g=>e.jsx(L,{value:g.id,children:g.label||g.id},g.id))]})]})]}),e.jsx(yt,{className:"md:col-span-2",apiKeys:re,selected:a,disabled:oe,onChange:d}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.modelId")}),e.jsx(ue,{value:k,onChange:g=>x(g.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:R,onValueChange:g=>D(g),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:S,onChange:g=>_(g.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endDate")}),e.jsx(ue,{type:"date",value:w,onChange:g=>b(g.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 i=await st.post("/api/logs/export",l,{responseType:"blob",timeout:t});return new Blob([i.data],{type:"application/zip"})}};function vt({apiKeyMap:l,logId:t,open:i,providerLabelMap:n}){var o;const{t:c}=K(),{pushToast:s}=ge(),r=$(U.logs.detail(t),he.detailRequest(t),{enabled:i&&t!==null,staleTime:3e4});f.useEffect(()=>{!r.isError||!r.error||s({title:c("logs.detail.loadError"),description:r.error.message,variant:"error"})},[r.error,r.isError,s,c]);const h=f.useCallback(async(a,d,k)=>{if(!d){s({title:c("logs.detail.copy.empty",{label:a}),variant:"info"});return}try{await mt(d),s({title:c(k),variant:"success"})}catch(x){s({title:c("logs.detail.copy.failure"),description:x instanceof Error?x.message:c("logs.detail.copy.failureFallback"),variant:"error"})}},[s,c]),p=r.data,j=p?n.get(p.provider)??p.provider:"",u=p&&p.api_key_id!=null?l.get(p.api_key_id):void 0,y=p?De(p,c):null;return{apiKeyMeta:u,errorMessage:r.isError?((o=r.error)==null?void 0:o.message)??null:null,handleCopy:h,isError:r.isError,isPending:r.isPending,providerLabel:j,refetch:r.refetch,record:p,statusMeta:y}}function Nt({open:l,logId:t,onClose:i,providerLabelMap:n,apiKeyMap:c}){var x,R,D,S,_,w;const{t:s}=K(),{apiKeyMeta:r,errorMessage:h,handleCopy:p,isError:j,isPending:u,providerLabel:y,refetch:o,record:a,statusMeta:d}=vt({apiKeyMap:c,logId:t,open:l,providerLabelMap:n}),k=a?[{key:"client-request",title:s("logs.detail.payload.clientRequest"),value:((x=a.payload)==null?void 0:x.client_request)??null,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(R=a.payload)!=null&&R.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:((S=a.payload)==null?void 0:S.client_response)??null,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[];return e.jsx(at,{open:l,onOpenChange:b=>{b||i()},children:e.jsxs(rt,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(ot,{className:"pr-14",children:[e.jsx(it,{children:s("logs.detail.title")}),e.jsx(nt,{children:a?s("logs.detail.id",{id:a.id}):s("logs.detail.loadError")})]}),e.jsx(dt,{className:"max-h-[78vh]",children:u?e.jsx(ct,{compact:!0,className:"min-h-[240px]",label:s("common.loading")}):j?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 o(),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(M,{variant:d==null?void 0:d.variant,children:(d==null?void 0:d.label)??"-"}),e.jsx(M,{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:(d==null?void 0:d.label)??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(F,{label:s("logs.detail.info.time"),value:Fe(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:y}),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:pt(a.stream)}),e.jsx(F,{label:s("logs.detail.info.status"),value:(d==null?void 0:d.label)??"-"})]}),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:(_=a.payload)!=null&&_.upstream_request||(w=a.payload)!=null&&w.upstream_response?s("logs.detail.payload.helperWithUpstream"):s("logs.detail.payload.helperClientOnly")})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:k.map(b=>e.jsx(wt,{title:b.title,value:b.value,emptyLabel:b.emptyLabel,onCopy:()=>p(b.title,b.value,b.copyToast),t:s},b.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 wt({emptyLabel:l,onCopy:t,title:i,value:n,t:c}){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:i}),e.jsx(E,{variant:"outline",size:"sm",onClick:t,children:c("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:ut(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 kt(){if(typeof window>"u")return Q;try{const l=window.localStorage.getItem(C.logs.visibleColumns);if(!l)return Q;const t=JSON.parse(l);if(!Array.isArray(t))return Q;const i=t.filter(n=>ae.includes(n));return i.length>0?i:Q}catch{return Q}}function St(){return typeof window>"u"?"comfortable":window.localStorage.getItem(C.logs.density)==="compact"?"compact":"comfortable"}function Ct(){if(typeof window>"u")return H[0];const l=window.localStorage.getItem(C.logs.pageSize),t=Number(l);return H.includes(t)?t:H[0]}function Et(){if(typeof window>"u")return[];try{const l=window.localStorage.getItem(C.logs.selectedApiKeys);if(!l)return[];const t=JSON.parse(l);return Array.isArray(t)?t.map(i=>Number(i)).filter(i=>Number.isInteger(i)&&i>0):[]}catch{return[]}}function Ce(l,t=!1){if(!l)return;const i=t?`${l}T23:59:59.999`:`${l}T00:00:00.000`,n=Date.parse(i);return Number.isFinite(n)?n:void 0}function _t(l,t,i){return l===i&&t===i}function Dt({columnOptions:l,exporting:t,onExport:i,onRefresh:n,onResetColumns:c,onSetDensity:s,onToggleColumn:r,refreshing:h,rowDensity:p,total:j,visibleColumns:u,visibleColumnSet:y}){const{t:o}=K(),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:v("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",p==="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:o("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>s("compact"),className:v("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",p==="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:o("logs.table.density.compact")})]}),e.jsxs(gt,{children:[e.jsx(ht,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:o("logs.actions.columns")})}),e.jsxs(ft,{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:o("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o("logs.actions.visibleCount",{count:u.length})})]}),e.jsx(E,{variant:"ghost",size:"sm",onClick:c,disabled:a,children:o("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(d=>{const k=y.has(d.id);return e.jsxs("label",{className:v("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",k&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:k,onChange:()=>r(d.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:d.label})]},d.id)})})]})]}),e.jsxs(E,{onClick:i,disabled:t,className:"w-full sm:w-auto",children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),o(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:o("logs.summary.total",{value:j.toLocaleString()})}),e.jsxs(E,{variant:"outline",size:"sm",onClick:n,disabled:h,className:"shrink-0",children:[e.jsx(Ze,{className:v("mr-2 h-4 w-4",h&&"animate-spin")}),o(h?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function Ft({record:l,providerLabelMap:t,apiKeyMap:i,onSelect:n,isEven:c,density:s,visibleColumnSet:r}){const{t:h}=K(),p=t.get(l.provider)??l.provider,j=l.endpoint||"-",u=De(l,h),y=l.client_model??h("logs.table.requestedModelFallback"),o=l.api_key_id!=null?i.get(l.api_key_id):void 0,a=l.api_key_id==null?h("logs.table.apiKeyUnknown"):o!=null&&o.isWildcard?h("apiKeys.wildcard"):o!=null&&o.name?o.name:l.api_key_name?l.api_key_name:h("logs.table.apiKeyUnknown"),d=s==="compact"?"px-3 py-1.5":"px-3 py-2",k=c?"bg-muted/30":"bg-background",x=xt(l.session_id),R=x==null?void 0:x.rowStyle,D=x==null?void 0:x.stickyStyle,S=x?{...x.stickyStyle,...x.accentStyle}:void 0;return e.jsxs("tr",{"data-session-id":x==null?void 0:x.sessionId,"data-session-color":x==null?void 0:x.colorKey,className:v("transition-colors",x?"":c?"bg-muted/30":"",x?"":"hover:bg-muted/50"),style:R,onMouseEnter:_=>{x&&Object.assign(_.currentTarget.style,x.hoverStyle)},onMouseLeave:_=>{x&&Object.assign(_.currentTarget.style,x.rowStyle)},children:[e.jsx("td",{className:v("sticky left-0 z-10 text-xs",d,x?"":k),style:S,children:Fe(l.timestamp)}),r.has("endpoint")&&e.jsx("td",{className:v(d,"text-xs"),children:j}),r.has("provider")&&e.jsx("td",{className:v(d,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:p,children:p})}),r.has("requestedModel")&&e.jsx("td",{className:v(d,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:y,children:y})}),r.has("routedModel")&&e.jsx("td",{className:v(d,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:l.model,children:l.model})}),r.has("apiKey")&&e.jsx("td",{className:v(d,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:a,children:a})}),r.has("inputTokens")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:z(l.input_tokens)}),r.has("cacheReadTokens")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:z(l.cache_read_tokens)}),r.has("cacheCreationTokens")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:z(l.cache_creation_tokens)}),r.has("outputTokens")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:z(l.output_tokens)}),r.has("latency")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:O(l.latency_ms,"ms")}),r.has("ttft")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:O(l.ttft_ms,"ms")}),r.has("tpot")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:O(l.tpot_ms,"ms/tk")}),r.has("status")&&e.jsx("td",{className:v(d,"text-center"),children:e.jsx(M,{variant:u.variant,className:"text-xs",children:u.label})}),r.has("error")&&e.jsx("td",{className:v(d,"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:v("sticky right-0 z-10 text-center",d,x?"":k),style:D,children:e.jsx(E,{variant:"outline",size:"sm",onClick:()=>n(l.id),children:h("logs.actions.detail")})})]})}function Tt(l){const{t}=K(),{tableScrollRef:i,visibleColumnSet:n,visibleColumnCount:c,logsError:s,logsPending:r,items:h,activeFiltersCount:p,handleResetFilters:j,handleRetry:u,providerLabelMap:y,apiKeyMap:o,handleOpenDetail:a,rowDensity:d,showScrollHint:k,pageSize:x,setPageSize:R,page:D,totalPages:S,setPage:_}=l;return e.jsx(Ee,{className:"overflow-hidden",children:e.jsxs(_e,{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:c-2})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(M,{variant:"secondary",children:"Wide Table"}),e.jsx(M,{variant:"outline",children:t(d==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),k?e.jsx(M,{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:i,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((w,b)=>e.jsx(bt,{columns:c},b)):s&&h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:c,className:"px-3 py-6",children:e.jsx(xe,{compact:!0,tone:"danger",icon:e.jsx(Ye,{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")}),p>0?e.jsx(E,{variant:"ghost",size:"sm",onClick:j,children:t("common.actions.reset")}):null]})})})}):h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:c,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")}),p>0&&e.jsx(E,{variant:"outline",size:"sm",onClick:j,children:t("common.actions.reset")})]})})}):h.map((w,b)=>e.jsx(Ft,{record:w,providerLabelMap:y,apiKeyMap:o,onSelect:a,isEven:b%2===0,density:d,visibleColumnSet:n},w.id))})]})}),k&&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:x.toString(),onValueChange:w=>R(Number(w)),children:[e.jsx(te,{className:"w-[80px]",children:e.jsx(se,{})}),e.jsx(le,{children:H.map(w=>e.jsx(L,{value:w.toString(),children:w},w))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",onClick:()=>_(w=>Math.max(w-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:S===0?0:D,total:S})}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>_(w=>S===0?w:Math.min(w+1,S)),disabled:S===0||D>=S,children:t("logs.table.pagination.next")})]})]})]})})}function Rt({exportTimeoutMs:l,queryParams:t,total:i}){const{t:n}=K(),{pushToast:c}=ge(),[s,r]=f.useState(!1),h=f.useCallback(async()=>{if(!s){r(!0);try{const p=i>0?Math.min(i,5e3):1e3,j={...t,limit:p,offset:0},u=await he.exportArchive(j,l),y=new Date().toISOString().replace(/[:.]/g,"-"),o=URL.createObjectURL(u),a=document.createElement("a");a.href=o,a.download=`cc-gw-logs-${y}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(o),c({title:n("logs.toast.exportSuccess.title"),description:n("logs.toast.exportSuccess.desc"),variant:"success"})}catch(p){const j=lt(p);c({title:n("logs.toast.exportError.title"),description:n("logs.toast.exportError.desc",{message:j.message}),variant:"error"})}finally{r(!1)}}},[l,s,c,t,n,i]);return{exporting:s,handleExport:h}}function Lt(){const l=f.useRef(null),[t,i]=f.useState(!1),n=f.useCallback(()=>{const c=l.current;if(!c)return;const s=c.scrollWidth-c.scrollLeft-c.clientWidth>1;i(s)},[]);return f.useEffect(()=>{const c=l.current;if(!c)return;n(),c.addEventListener("scroll",n,{passive:!0});const s=new ResizeObserver(n);return s.observe(c),()=>{c.removeEventListener("scroll",n),s.disconnect()}},[n]),{scrollRef:l,showScrollHint:t,updateScrollHint:n}}function Kt(){const[l,t]=T(C.logs.density,St,{serialize:u=>u,deserialize:u=>u==="compact"?"compact":"comfortable"}),[i,n]=T(C.logs.visibleColumns,kt),{scrollRef:c,showScrollHint:s}=Lt(),r=f.useMemo(()=>new Set(i),[i]),h=i.length+2,p=f.useCallback(u=>{n(y=>{if(y.includes(u))return y.length===1?y:y.filter(a=>a!==u);const o=[...y,u];return o.sort((a,d)=>ae.indexOf(a)-ae.indexOf(d)),o})},[]);return{resetVisibleColumns:f.useCallback(()=>{n(Q)},[]),rowDensity:l,setRowDensity:t,showScrollHint:s,tableScrollRef:c,toggleColumn:p,visibleColumnCount:h,visibleColumns:i,visibleColumnSet:r}}function Mt(){var je,ve,Ne,we,ke;const{t:l}=K(),{pushToast:t}=ge(),[i,n]=T(C.logs.providerFilter,"all"),[c,s]=T(C.logs.endpointFilter,"all"),[r,h]=T(C.logs.modelFilter,""),[p,j]=T(C.logs.statusFilter,"all"),[u,y]=T(C.logs.fromDate,""),[o,a]=T(C.logs.toDate,""),[d,k]=f.useState(1),[x,R]=T(C.logs.pageSize,Ct,{serialize:m=>String(m),deserialize:m=>{const N=Number(m);return H.includes(N)?N:H[0]}}),[D,S]=f.useState(null),[_,w]=f.useState(!1),[b,B]=T(C.logs.selectedApiKeys,Et),[re,oe]=T(C.logs.filtersExpanded,!1),{resetVisibleColumns:W,rowDensity:g,setRowDensity:G,showScrollHint:Te,tableScrollRef:Re,toggleColumn:Le,visibleColumnCount:Ke,visibleColumns:Me,visibleColumnSet:Pe}=Kt();f.useEffect(()=>{k(1)},[i,c,r,p,u,o,x,b]);const ie=f.useMemo(()=>{const m={limit:x,offset:(d-1)*x};i!=="all"&&(m.provider=i),c!=="all"&&(m.endpoint=c),r.trim().length>0&&(m.model=r.trim()),p!=="all"&&(m.status=p);const N=Ce(u),q=Ce(o,!0);return N!==void 0&&(m.from=N),q!==void 0&&(m.to=q),b.length>0&&(m.apiKeys=b.join(",")),m},[c,u,r,d,x,i,b,p,o]),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());f.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]),f.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/x):0,Ae=((ve=P.data)==null?void 0:ve.items)??[],Oe=f.useMemo(()=>{var N;const m=(N=be.data)==null?void 0:N.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]);f.useEffect(()=>{J>0&&d>J&&k(J)},[d,J]);const de=V.data??[],ce=f.useMemo(()=>{const m=new Map;for(const N of de)N.id&&m.set(N.id,N.label??N.id);return m},[de]),ye=f.useMemo(()=>{var N;const m=new Map;m.set("anthropic",l("logs.filters.endpointAnthropic")),m.set("openai",l("logs.filters.endpointOpenAI"));for(const q of((N=ne.data)==null?void 0:N.endpoints)??[])m.set(q.id,q.label||q.id);return m},[(we=ne.data)==null?void 0:we.endpoints,l]),ze=f.useMemo(()=>{const m=[];if(i!=="all"){const N=ce.get(i)??i;m.push({key:"provider",label:`${l("logs.filters.provider")}: ${N}`,onRemove:()=>n("all")})}if(c!=="all"){const N=ye.get(c)??c;m.push({key:"endpoint",label:`${l("logs.filters.endpoint")}: ${N}`,onRemove:()=>s("all")})}if(r.trim()&&m.push({key:"model",label:`${l("logs.filters.modelId")}: ${r.trim()}`,onRemove:()=>h("")}),p!=="all"){const N=l(p==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");m.push({key:"status",label:`${l("logs.filters.status")}: ${N}`,onRemove:()=>j("all")})}return u&&m.push({key:"from",label:`${l("logs.filters.startDate")}: ${u}`,onRemove:()=>y("")}),o&&m.push({key:"to",label:`${l("logs.filters.endDate")}: ${o}`,onRemove:()=>a("")}),b.length>0&&m.push({key:"apiKeys",label:l("logs.filters.apiKeySelected",{count:b.length}),onRemove:()=>B([])}),m},[c,ye,u,r,i,ce,b.length,p,l,o]),me=fe.data??[],qe=f.useMemo(()=>{const m=new Map;for(const N of me)m.set(N.id,N);return m},[me]),Ie=f.useMemo(()=>ae.map(m=>({id:m,label:l(`logs.table.columns.${m}`)})),[l]),X=f.useMemo(()=>new Date().toISOString().slice(0,10),[]),Qe=f.useMemo(()=>i==="all"&&c==="all"&&r.trim()===""&&p==="all"&&u===""&&o===""&&b.length===0?"all":p==="error"&&c==="all"&&i==="all"&&r.trim()===""&&u===""&&o===""&&b.length===0?"errors":_t(u,o,X)&&c==="all"&&i==="all"&&r.trim()===""&&p==="all"&&b.length===0?"today":c==="anthropic"&&i==="all"&&r.trim()===""&&p==="all"&&u===""&&o===""&&b.length===0?"anthropic":c==="openai"&&i==="all"&&r.trim()===""&&p==="all"&&u===""&&o===""&&b.length===0?"openai":null,[c,u,r,i,b.length,p,o,X]),pe=f.useCallback(()=>{n("all"),h(""),s("all"),j("all"),y(""),a(""),B([])},[]),Ve=f.useCallback(m=>{if(k(1),pe(),m!=="all"){if(m==="errors"){j("error");return}if(m==="today"){y(X),a(X);return}if(m==="anthropic"){s("anthropic");return}m==="openai"&&s("openai")}},[pe,X]),{exporting:$e,handleExport:Ue}=Rt({exportTimeoutMs:Oe,queryParams:ie,total:Z}),He=f.useCallback(m=>{S(m),w(!0)},[]),Be=f.useCallback(()=>{w(!1),S(null)},[]);return{activeFilters:ze,activeQuickView:Qe,apiKeyMap:qe,apiKeys:me,apiKeysQuery:fe,applyQuickView:Ve,columnOptions:Ie,customEndpoints:(ke=ne.data)==null?void 0:ke.endpoints,endpointFilter:c,exporting:$e,filtersExpanded:re,fromDate:u,handleCloseDetail:Be,handleExport:Ue,handleOpenDetail:He,handleResetFilters:pe,isDetailOpen:_,items:Ae,logsQuery:P,modelFilter:r,page:d,pageSize:x,providerFilter:i,providerLabelMap:ce,providerOptions:de,rowDensity:g,resetVisibleColumns:W,selectedApiKeys:b,selectedLogId:D,setEndpointFilter:s,setFiltersExpanded:oe,setFromDate:y,setModelFilter:h,setPage:k,setPageSize:R,setProviderFilter:n,setRowDensity:G,setSelectedApiKeys:B,setStatusFilter:j,setToDate:a,showScrollHint:Te,statusFilter:p,tableScrollRef:Re,toDate:o,toggleColumn:Le,total:Z,totalPages:J,visibleColumnCount:Ke,visibleColumns:Me,visibleColumnSet:Pe}}function ls(){var i;const{t:l}=K(),t=Mt();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(tt,{icon:e.jsx(et,{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(Dt,{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(jt,{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(Tt,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.visibleColumnSet,visibleColumnCount:t.visibleColumnCount,logsError:t.logsQuery.isError?((i=t.logsQuery.error)==null?void 0:i.message)??null:null,logsPending:t.logsQuery.isPending,items:t.items,activeFiltersCount:t.activeFilters.length,handleResetFilters:t.handleResetFilters,handleRetry:()=>void t.logsQuery.refetch(),providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap,handleOpenDetail:t.handleOpenDetail,rowDensity:t.rowDensity,showScrollHint:t.showScrollHint,pageSize:t.pageSize,setPageSize:t.setPageSize,page:t.page,totalPages:t.totalPages,setPage:t.setPage}),e.jsx(Nt,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{ls as default};
|
|
1
|
+
import{r as f,j as e,an as We,ao as Ge,a9 as Je,ap as Xe,am as Ze,W as Ye,T as et}from"./vendor-DfnQOGOQ.js";import{P as tt}from"./PageHeader-DKkO-Kdm.js";import{c as v,B as E,b as st,u as ge,s as C,t as lt,a as T}from"./index-OvGsIZkZ.js";import{B as M}from"./badge-CkaH3uCO.js";import{C as Ee,a as _e}from"./card-Bem3kP2L.js";import{I as ue}from"./input-DCNoHAkn.js";import{L as I}from"./label-9kbpUKaR.js";import{S as ee,a as te,b as se,c as le,d as L}from"./select-DS37xdev.js";import{u as K}from"./i18n-dgCQR_PB.js";import{D as at,A as rt,a as ot,b as it,c as nt,d as dt}from"./DialogShell-CygWjkEa.js";import{P as ct,a as xe}from"./PageState-DSoiwsKr.js";import{c as mt}from"./clipboard-CALi6bTW.js";import{u as $}from"./useApiQuery-3ZHohr5l.js";import{q as U}from"./queryKeys-BMvyDTQS.js";import{g as De,f as O,a as Fe,b as pt,c as z,d as ut,e as xt}from"./utils-BHook6QN.js";import{P as gt,a as ht,b as ft}from"./popover-BGkrY50i.js";import{T as bt}from"./Skeleton-C7Qi01SG.js";import{g as Se}from"./gateway-DrmzHCwu.js";import"./query-Db16w3tH.js";import"./router-BURlSZbt.js";import"./radix-D08JKSgz.js";function yt({apiKeys:l,selected:t,onChange:i,disabled:n,className:c}){const{t:s}=K(),[r,h]=f.useState(!1),p=f.useRef(null);f.useEffect(()=>{if(!r)return;const o=a=>{var d;(d=p.current)!=null&&d.contains(a.target)||h(!1)};return window.addEventListener("mousedown",o),()=>window.removeEventListener("mousedown",o)},[r]);const j=f.useMemo(()=>{if(t.length===0)return[];const o=new Map;for(const a of l)o.set(a.id,a);return t.map(a=>{const d=o.get(a);return d?d.isWildcard?s("apiKeys.wildcard"):d.name:null}).filter(a=>!!a)},[l,t,s]),u=t.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:t.length}),y=o=>{t.includes(o)?i(t.filter(a=>a!==o)):i([...t,o])};return e.jsxs("div",{className:v("relative space-y-2",c),ref:p,children:[e.jsx(I,{children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>h(o=>!o),disabled:n||l.length===0,title:s("logs.filters.apiKeyHint"),className:v("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,j.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:j.join(", ")})]}),e.jsx("svg",{className:v("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:()=>i([]),disabled:t.length===0,className:"text-primary hover:underline disabled:opacity-40",children:s("common.actions.reset")})]}),e.jsxs("div",{className:"max-h-56 overflow-y-auto py-2",children:[l.map(o=>{const a=o.isWildcard?s("apiKeys.wildcard"):o.name,d=t.includes(o.id);return e.jsxs("label",{className:v("flex cursor-pointer items-center gap-2 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",d&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:d,onChange:()=>y(o.id)}),e.jsx("span",{className:"truncate",children:a})]},o.id)}),l.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:s("logs.filters.apiKeyAll")})]})]})]})}function jt(l){const{t}=K(),{total:i,activeFilters:n,filtersExpanded:c,setFiltersExpanded:s,handleResetFilters:r,activeQuickView:h,applyQuickView:p,providerFilter:j,setProviderFilter:u,endpointFilter:y,setEndpointFilter:o,selectedApiKeys:a,setSelectedApiKeys:d,modelFilter:k,setModelFilter:x,statusFilter:R,setStatusFilter:D,fromDate:S,setFromDate:_,toDate:w,setToDate:b,providerOptions:B,apiKeys:re,apiKeysLoading:oe,customEndpoints:W}=l;return e.jsx(Ee,{"data-testid":"logs-filters-card",className:"overflow-hidden",children:e.jsxs(_e,{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(M,{variant:"outline",children:t("logs.summary.total",{value:i.toLocaleString()})}),n.length>0&&e.jsx(M,{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(g=>!g),children:c?e.jsxs(e.Fragment,{children:[t("common.filters.collapse"),e.jsx(We,{className:"ml-1 h-4 w-4"})]}):e.jsxs(e.Fragment,{children:[t("common.filters.expand"),e.jsx(Ge,{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(g=>e.jsxs(M,{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:g.onRemove,onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),g.onRemove())},children:[g.label,e.jsx(Je,{className:"h-3 w-3","aria-hidden":"true"})]},g.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:j==="all"?t("common.noData"):"1"}),e.jsx(Y,{label:t("logs.filters.endpoint"),value:y==="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(g=>e.jsx(E,{variant:h===g?"default":"outline",size:"sm",className:v("rounded-full border-transparent",h===g&&g==="all"&&"bg-foreground text-background hover:bg-foreground/90",h===g&&g==="errors"&&"bg-rose-500 text-white hover:bg-rose-500/90",h===g&&g==="today"&&"bg-emerald-500 text-white hover:bg-emerald-500/90",h===g&&(g==="anthropic"||g==="openai")&&"bg-amber-500 text-white hover:bg-amber-500/90"),onClick:()=>p(g),children:t(`logs.quickViews.${g}`)},g))})]}),c&&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:j,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(g=>e.jsx(L,{value:g.id,children:g.label??g.id},g.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endpoint")}),e.jsxs(ee,{value:y,onValueChange:o,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(g=>e.jsx(L,{value:g.id,children:g.label||g.id},g.id))]})]})]}),e.jsx(yt,{className:"md:col-span-2",apiKeys:re,selected:a,disabled:oe,onChange:d}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.modelId")}),e.jsx(ue,{value:k,onChange:g=>x(g.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:R,onValueChange:g=>D(g),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:S,onChange:g=>_(g.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:t("logs.filters.endDate")}),e.jsx(ue,{type:"date",value:w,onChange:g=>b(g.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 i=await st.post("/api/logs/export",l,{responseType:"blob",timeout:t});return new Blob([i.data],{type:"application/zip"})}};function vt({apiKeyMap:l,logId:t,open:i,providerLabelMap:n}){var o;const{t:c}=K(),{pushToast:s}=ge(),r=$(U.logs.detail(t),he.detailRequest(t),{enabled:i&&t!==null,staleTime:3e4});f.useEffect(()=>{!r.isError||!r.error||s({title:c("logs.detail.loadError"),description:r.error.message,variant:"error"})},[r.error,r.isError,s,c]);const h=f.useCallback(async(a,d,k)=>{if(!d){s({title:c("logs.detail.copy.empty",{label:a}),variant:"info"});return}try{await mt(d),s({title:c(k),variant:"success"})}catch(x){s({title:c("logs.detail.copy.failure"),description:x instanceof Error?x.message:c("logs.detail.copy.failureFallback"),variant:"error"})}},[s,c]),p=r.data,j=p?n.get(p.provider)??p.provider:"",u=p&&p.api_key_id!=null?l.get(p.api_key_id):void 0,y=p?De(p,c):null;return{apiKeyMeta:u,errorMessage:r.isError?((o=r.error)==null?void 0:o.message)??null:null,handleCopy:h,isError:r.isError,isPending:r.isPending,providerLabel:j,refetch:r.refetch,record:p,statusMeta:y}}function Nt({open:l,logId:t,onClose:i,providerLabelMap:n,apiKeyMap:c}){var x,R,D,S,_,w;const{t:s}=K(),{apiKeyMeta:r,errorMessage:h,handleCopy:p,isError:j,isPending:u,providerLabel:y,refetch:o,record:a,statusMeta:d}=vt({apiKeyMap:c,logId:t,open:l,providerLabelMap:n}),k=a?[{key:"client-request",title:s("logs.detail.payload.clientRequest"),value:((x=a.payload)==null?void 0:x.client_request)??null,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(R=a.payload)!=null&&R.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:((S=a.payload)==null?void 0:S.client_response)??null,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}]:[];return e.jsx(at,{open:l,onOpenChange:b=>{b||i()},children:e.jsxs(rt,{className:"w-[min(96vw,1200px)] max-w-[1200px]",children:[e.jsxs(ot,{className:"pr-14",children:[e.jsx(it,{children:s("logs.detail.title")}),e.jsx(nt,{children:a?s("logs.detail.id",{id:a.id}):s("logs.detail.loadError")})]}),e.jsx(dt,{className:"max-h-[78vh]",children:u?e.jsx(ct,{compact:!0,className:"min-h-[240px]",label:s("common.loading")}):j?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 o(),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(M,{variant:d==null?void 0:d.variant,children:(d==null?void 0:d.label)??"-"}),e.jsx(M,{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:(d==null?void 0:d.label)??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(F,{label:s("logs.detail.info.time"),value:Fe(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:y}),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:pt(a.stream)}),e.jsx(F,{label:s("logs.detail.info.status"),value:(d==null?void 0:d.label)??"-"})]}),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:(_=a.payload)!=null&&_.upstream_request||(w=a.payload)!=null&&w.upstream_response?s("logs.detail.payload.helperWithUpstream"):s("logs.detail.payload.helperClientOnly")})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:k.map(b=>e.jsx(wt,{title:b.title,value:b.value,emptyLabel:b.emptyLabel,onCopy:()=>p(b.title,b.value,b.copyToast),t:s},b.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 wt({emptyLabel:l,onCopy:t,title:i,value:n,t:c}){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:i}),e.jsx(E,{variant:"outline",size:"sm",onClick:t,children:c("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:ut(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 kt(){if(typeof window>"u")return Q;try{const l=window.localStorage.getItem(C.logs.visibleColumns);if(!l)return Q;const t=JSON.parse(l);if(!Array.isArray(t))return Q;const i=t.filter(n=>ae.includes(n));return i.length>0?i:Q}catch{return Q}}function St(){return typeof window>"u"?"comfortable":window.localStorage.getItem(C.logs.density)==="compact"?"compact":"comfortable"}function Ct(){if(typeof window>"u")return H[0];const l=window.localStorage.getItem(C.logs.pageSize),t=Number(l);return H.includes(t)?t:H[0]}function Et(){if(typeof window>"u")return[];try{const l=window.localStorage.getItem(C.logs.selectedApiKeys);if(!l)return[];const t=JSON.parse(l);return Array.isArray(t)?t.map(i=>Number(i)).filter(i=>Number.isInteger(i)&&i>0):[]}catch{return[]}}function Ce(l,t=!1){if(!l)return;const i=t?`${l}T23:59:59.999`:`${l}T00:00:00.000`,n=Date.parse(i);return Number.isFinite(n)?n:void 0}function _t(l,t,i){return l===i&&t===i}function Dt({columnOptions:l,exporting:t,onExport:i,onRefresh:n,onResetColumns:c,onSetDensity:s,onToggleColumn:r,refreshing:h,rowDensity:p,total:j,visibleColumns:u,visibleColumnSet:y}){const{t:o}=K(),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:v("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",p==="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:o("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>s("compact"),className:v("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",p==="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:o("logs.table.density.compact")})]}),e.jsxs(gt,{children:[e.jsx(ht,{asChild:!0,children:e.jsx(E,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:o("logs.actions.columns")})}),e.jsxs(ft,{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:o("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o("logs.actions.visibleCount",{count:u.length})})]}),e.jsx(E,{variant:"ghost",size:"sm",onClick:c,disabled:a,children:o("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(d=>{const k=y.has(d.id);return e.jsxs("label",{className:v("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",k&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:k,onChange:()=>r(d.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:d.label})]},d.id)})})]})]}),e.jsxs(E,{onClick:i,disabled:t,className:"w-full sm:w-auto",children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),o(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:o("logs.summary.total",{value:j.toLocaleString()})}),e.jsxs(E,{variant:"outline",size:"sm",onClick:n,disabled:h,className:"shrink-0",children:[e.jsx(Ze,{className:v("mr-2 h-4 w-4",h&&"animate-spin")}),o(h?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function Ft({record:l,providerLabelMap:t,apiKeyMap:i,onSelect:n,isEven:c,density:s,visibleColumnSet:r}){const{t:h}=K(),p=t.get(l.provider)??l.provider,j=l.endpoint||"-",u=De(l,h),y=l.client_model??h("logs.table.requestedModelFallback"),o=l.api_key_id!=null?i.get(l.api_key_id):void 0,a=l.api_key_id==null?h("logs.table.apiKeyUnknown"):o!=null&&o.isWildcard?h("apiKeys.wildcard"):o!=null&&o.name?o.name:l.api_key_name?l.api_key_name:h("logs.table.apiKeyUnknown"),d=s==="compact"?"px-3 py-1.5":"px-3 py-2",k=c?"bg-muted/30":"bg-background",x=xt(l.session_id),R=x==null?void 0:x.rowStyle,D=x==null?void 0:x.stickyStyle,S=x?{...x.stickyStyle,...x.accentStyle}:void 0;return e.jsxs("tr",{"data-session-id":x==null?void 0:x.sessionId,"data-session-color":x==null?void 0:x.colorKey,className:v("transition-colors",x?"":c?"bg-muted/30":"",x?"":"hover:bg-muted/50"),style:R,onMouseEnter:_=>{x&&Object.assign(_.currentTarget.style,x.hoverStyle)},onMouseLeave:_=>{x&&Object.assign(_.currentTarget.style,x.rowStyle)},children:[e.jsx("td",{className:v("sticky left-0 z-10 text-xs",d,x?"":k),style:S,children:Fe(l.timestamp)}),r.has("endpoint")&&e.jsx("td",{className:v(d,"text-xs"),children:j}),r.has("provider")&&e.jsx("td",{className:v(d,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:p,children:p})}),r.has("requestedModel")&&e.jsx("td",{className:v(d,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:y,children:y})}),r.has("routedModel")&&e.jsx("td",{className:v(d,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:l.model,children:l.model})}),r.has("apiKey")&&e.jsx("td",{className:v(d,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:a,children:a})}),r.has("inputTokens")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:z(l.input_tokens)}),r.has("cacheReadTokens")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:z(l.cache_read_tokens)}),r.has("cacheCreationTokens")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:z(l.cache_creation_tokens)}),r.has("outputTokens")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:z(l.output_tokens)}),r.has("latency")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:O(l.latency_ms,"ms")}),r.has("ttft")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:O(l.ttft_ms,"ms")}),r.has("tpot")&&e.jsx("td",{className:v(d,"text-right text-xs tabular-nums"),children:O(l.tpot_ms,"ms/tk")}),r.has("status")&&e.jsx("td",{className:v(d,"text-center"),children:e.jsx(M,{variant:u.variant,className:"text-xs",children:u.label})}),r.has("error")&&e.jsx("td",{className:v(d,"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:v("sticky right-0 z-10 text-center",d,x?"":k),style:D,children:e.jsx(E,{variant:"outline",size:"sm",onClick:()=>n(l.id),children:h("logs.actions.detail")})})]})}function Tt(l){const{t}=K(),{tableScrollRef:i,visibleColumnSet:n,visibleColumnCount:c,logsError:s,logsPending:r,items:h,activeFiltersCount:p,handleResetFilters:j,handleRetry:u,providerLabelMap:y,apiKeyMap:o,handleOpenDetail:a,rowDensity:d,showScrollHint:k,pageSize:x,setPageSize:R,page:D,totalPages:S,setPage:_}=l;return e.jsx(Ee,{className:"overflow-hidden",children:e.jsxs(_e,{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:c-2})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(M,{variant:"secondary",children:"Wide Table"}),e.jsx(M,{variant:"outline",children:t(d==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),k?e.jsx(M,{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:i,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((w,b)=>e.jsx(bt,{columns:c},b)):s&&h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:c,className:"px-3 py-6",children:e.jsx(xe,{compact:!0,tone:"danger",icon:e.jsx(Ye,{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")}),p>0?e.jsx(E,{variant:"ghost",size:"sm",onClick:j,children:t("common.actions.reset")}):null]})})})}):h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:c,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")}),p>0&&e.jsx(E,{variant:"outline",size:"sm",onClick:j,children:t("common.actions.reset")})]})})}):h.map((w,b)=>e.jsx(Ft,{record:w,providerLabelMap:y,apiKeyMap:o,onSelect:a,isEven:b%2===0,density:d,visibleColumnSet:n},w.id))})]})}),k&&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:x.toString(),onValueChange:w=>R(Number(w)),children:[e.jsx(te,{className:"w-[80px]",children:e.jsx(se,{})}),e.jsx(le,{children:H.map(w=>e.jsx(L,{value:w.toString(),children:w},w))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",onClick:()=>_(w=>Math.max(w-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:S===0?0:D,total:S})}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>_(w=>S===0?w:Math.min(w+1,S)),disabled:S===0||D>=S,children:t("logs.table.pagination.next")})]})]})]})})}function Rt({exportTimeoutMs:l,queryParams:t,total:i}){const{t:n}=K(),{pushToast:c}=ge(),[s,r]=f.useState(!1),h=f.useCallback(async()=>{if(!s){r(!0);try{const p=i>0?Math.min(i,5e3):1e3,j={...t,limit:p,offset:0},u=await he.exportArchive(j,l),y=new Date().toISOString().replace(/[:.]/g,"-"),o=URL.createObjectURL(u),a=document.createElement("a");a.href=o,a.download=`cc-gw-logs-${y}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(o),c({title:n("logs.toast.exportSuccess.title"),description:n("logs.toast.exportSuccess.desc"),variant:"success"})}catch(p){const j=lt(p);c({title:n("logs.toast.exportError.title"),description:n("logs.toast.exportError.desc",{message:j.message}),variant:"error"})}finally{r(!1)}}},[l,s,c,t,n,i]);return{exporting:s,handleExport:h}}function Lt(){const l=f.useRef(null),[t,i]=f.useState(!1),n=f.useCallback(()=>{const c=l.current;if(!c)return;const s=c.scrollWidth-c.scrollLeft-c.clientWidth>1;i(s)},[]);return f.useEffect(()=>{const c=l.current;if(!c)return;n(),c.addEventListener("scroll",n,{passive:!0});const s=new ResizeObserver(n);return s.observe(c),()=>{c.removeEventListener("scroll",n),s.disconnect()}},[n]),{scrollRef:l,showScrollHint:t,updateScrollHint:n}}function Kt(){const[l,t]=T(C.logs.density,St,{serialize:u=>u,deserialize:u=>u==="compact"?"compact":"comfortable"}),[i,n]=T(C.logs.visibleColumns,kt),{scrollRef:c,showScrollHint:s}=Lt(),r=f.useMemo(()=>new Set(i),[i]),h=i.length+2,p=f.useCallback(u=>{n(y=>{if(y.includes(u))return y.length===1?y:y.filter(a=>a!==u);const o=[...y,u];return o.sort((a,d)=>ae.indexOf(a)-ae.indexOf(d)),o})},[]);return{resetVisibleColumns:f.useCallback(()=>{n(Q)},[]),rowDensity:l,setRowDensity:t,showScrollHint:s,tableScrollRef:c,toggleColumn:p,visibleColumnCount:h,visibleColumns:i,visibleColumnSet:r}}function Mt(){var je,ve,Ne,we,ke;const{t:l}=K(),{pushToast:t}=ge(),[i,n]=T(C.logs.providerFilter,"all"),[c,s]=T(C.logs.endpointFilter,"all"),[r,h]=T(C.logs.modelFilter,""),[p,j]=T(C.logs.statusFilter,"all"),[u,y]=T(C.logs.fromDate,""),[o,a]=T(C.logs.toDate,""),[d,k]=f.useState(1),[x,R]=T(C.logs.pageSize,Ct,{serialize:m=>String(m),deserialize:m=>{const N=Number(m);return H.includes(N)?N:H[0]}}),[D,S]=f.useState(null),[_,w]=f.useState(!1),[b,B]=T(C.logs.selectedApiKeys,Et),[re,oe]=T(C.logs.filtersExpanded,!1),{resetVisibleColumns:W,rowDensity:g,setRowDensity:G,showScrollHint:Te,tableScrollRef:Re,toggleColumn:Le,visibleColumnCount:Ke,visibleColumns:Me,visibleColumnSet:Pe}=Kt();f.useEffect(()=>{k(1)},[i,c,r,p,u,o,x,b]);const ie=f.useMemo(()=>{const m={limit:x,offset:(d-1)*x};i!=="all"&&(m.provider=i),c!=="all"&&(m.endpoint=c),r.trim().length>0&&(m.model=r.trim()),p!=="all"&&(m.status=p);const N=Ce(u),q=Ce(o,!0);return N!==void 0&&(m.from=N),q!==void 0&&(m.to=q),b.length>0&&(m.apiKeys=b.join(",")),m},[c,u,r,d,x,i,b,p,o]),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());f.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]),f.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/x):0,Ae=((ve=P.data)==null?void 0:ve.items)??[],Oe=f.useMemo(()=>{var N;const m=(N=be.data)==null?void 0:N.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]);f.useEffect(()=>{J>0&&d>J&&k(J)},[d,J]);const de=V.data??[],ce=f.useMemo(()=>{const m=new Map;for(const N of de)N.id&&m.set(N.id,N.label??N.id);return m},[de]),ye=f.useMemo(()=>{var N;const m=new Map;m.set("anthropic",l("logs.filters.endpointAnthropic")),m.set("openai",l("logs.filters.endpointOpenAI"));for(const q of((N=ne.data)==null?void 0:N.endpoints)??[])m.set(q.id,q.label||q.id);return m},[(we=ne.data)==null?void 0:we.endpoints,l]),ze=f.useMemo(()=>{const m=[];if(i!=="all"){const N=ce.get(i)??i;m.push({key:"provider",label:`${l("logs.filters.provider")}: ${N}`,onRemove:()=>n("all")})}if(c!=="all"){const N=ye.get(c)??c;m.push({key:"endpoint",label:`${l("logs.filters.endpoint")}: ${N}`,onRemove:()=>s("all")})}if(r.trim()&&m.push({key:"model",label:`${l("logs.filters.modelId")}: ${r.trim()}`,onRemove:()=>h("")}),p!=="all"){const N=l(p==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");m.push({key:"status",label:`${l("logs.filters.status")}: ${N}`,onRemove:()=>j("all")})}return u&&m.push({key:"from",label:`${l("logs.filters.startDate")}: ${u}`,onRemove:()=>y("")}),o&&m.push({key:"to",label:`${l("logs.filters.endDate")}: ${o}`,onRemove:()=>a("")}),b.length>0&&m.push({key:"apiKeys",label:l("logs.filters.apiKeySelected",{count:b.length}),onRemove:()=>B([])}),m},[c,ye,u,r,i,ce,b.length,p,l,o]),me=fe.data??[],qe=f.useMemo(()=>{const m=new Map;for(const N of me)m.set(N.id,N);return m},[me]),Ie=f.useMemo(()=>ae.map(m=>({id:m,label:l(`logs.table.columns.${m}`)})),[l]),X=f.useMemo(()=>new Date().toISOString().slice(0,10),[]),Qe=f.useMemo(()=>i==="all"&&c==="all"&&r.trim()===""&&p==="all"&&u===""&&o===""&&b.length===0?"all":p==="error"&&c==="all"&&i==="all"&&r.trim()===""&&u===""&&o===""&&b.length===0?"errors":_t(u,o,X)&&c==="all"&&i==="all"&&r.trim()===""&&p==="all"&&b.length===0?"today":c==="anthropic"&&i==="all"&&r.trim()===""&&p==="all"&&u===""&&o===""&&b.length===0?"anthropic":c==="openai"&&i==="all"&&r.trim()===""&&p==="all"&&u===""&&o===""&&b.length===0?"openai":null,[c,u,r,i,b.length,p,o,X]),pe=f.useCallback(()=>{n("all"),h(""),s("all"),j("all"),y(""),a(""),B([])},[]),Ve=f.useCallback(m=>{if(k(1),pe(),m!=="all"){if(m==="errors"){j("error");return}if(m==="today"){y(X),a(X);return}if(m==="anthropic"){s("anthropic");return}m==="openai"&&s("openai")}},[pe,X]),{exporting:$e,handleExport:Ue}=Rt({exportTimeoutMs:Oe,queryParams:ie,total:Z}),He=f.useCallback(m=>{S(m),w(!0)},[]),Be=f.useCallback(()=>{w(!1),S(null)},[]);return{activeFilters:ze,activeQuickView:Qe,apiKeyMap:qe,apiKeys:me,apiKeysQuery:fe,applyQuickView:Ve,columnOptions:Ie,customEndpoints:(ke=ne.data)==null?void 0:ke.endpoints,endpointFilter:c,exporting:$e,filtersExpanded:re,fromDate:u,handleCloseDetail:Be,handleExport:Ue,handleOpenDetail:He,handleResetFilters:pe,isDetailOpen:_,items:Ae,logsQuery:P,modelFilter:r,page:d,pageSize:x,providerFilter:i,providerLabelMap:ce,providerOptions:de,rowDensity:g,resetVisibleColumns:W,selectedApiKeys:b,selectedLogId:D,setEndpointFilter:s,setFiltersExpanded:oe,setFromDate:y,setModelFilter:h,setPage:k,setPageSize:R,setProviderFilter:n,setRowDensity:G,setSelectedApiKeys:B,setStatusFilter:j,setToDate:a,showScrollHint:Te,statusFilter:p,tableScrollRef:Re,toDate:o,toggleColumn:Le,total:Z,totalPages:J,visibleColumnCount:Ke,visibleColumns:Me,visibleColumnSet:Pe}}function ls(){var i;const{t:l}=K(),t=Mt();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(tt,{icon:e.jsx(et,{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(Dt,{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(jt,{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(Tt,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.visibleColumnSet,visibleColumnCount:t.visibleColumnCount,logsError:t.logsQuery.isError?((i=t.logsQuery.error)==null?void 0:i.message)??null:null,logsPending:t.logsQuery.isPending,items:t.items,activeFiltersCount:t.activeFilters.length,handleResetFilters:t.handleResetFilters,handleRetry:()=>void t.logsQuery.refetch(),providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap,handleOpenDetail:t.handleOpenDetail,rowDensity:t.rowDensity,showScrollHint:t.showScrollHint,pageSize:t.pageSize,setPageSize:t.setPageSize,page:t.page,totalPages:t.totalPages,setPage:t.setPage}),e.jsx(Nt,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{ls as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,r as h,av as me,U as ue}from"./vendor-DfnQOGOQ.js";import{L as pe}from"./router-BURlSZbt.js";import{C as xe}from"./ConfirmDialog-8iSYQ7NE.js";import{P as he}from"./PageHeader-DKkO-Kdm.js";import{B as v,c as $}from"./index-OvGsIZkZ.js";import{B as E}from"./badge-CkaH3uCO.js";import{C as G,a as W}from"./card-Bem3kP2L.js";import{I as be}from"./input-DCNoHAkn.js";import{L as K}from"./label-9kbpUKaR.js";import{S as fe,a as ge,b as ve,c as ye,d as N}from"./select-DS37xdev.js";import{r as je,u as Ne}from"./useModelManagementState-Irif8Gdi.js";import{u as R}from"./i18n-dgCQR_PB.js";import{D as we,A as ke,a as Me,b as Ce,c as De,d as Te,e as Pe}from"./DialogShell-CygWjkEa.js";import{S as Ae}from"./switch-DVok_beq.js";import"./query-Db16w3tH.js";import"./radix-D08JKSgz.js";import"./gateway-DrmzHCwu.js";import"./queryKeys-BMvyDTQS.js";import"./useAppMutation-C2rsFjm5.js";import"./useApiQuery-3ZHohr5l.js";function Se({providersLength:l,filteredProviders:a,defaultLabels:m,providerSearch:f,providerTypeFilter:b,configPending:C,testingProviderId:s,onOpenEdit:d,onTestConnection:u,onRequestDelete:p,onProviderSearchChange:w,onProviderTypeChange:D,onResetFilters:k}){const{t:c}=R(),T=o=>{const g=o.authMode??(o.type==="anthropic"?"authToken":"apiKey");return g==="authToken"?"Bearer":g==="xAuthToken"?"X-Auth-Token":o.type==="anthropic"?"X-API-Key":c("providers.card.providerDefault")};return e.jsx(G,{children:e.jsxs(W,{className:"space-y-6 pt-6",children:[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(K,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:c("providers.filters.searchPlaceholder")}),e.jsx(be,{value:f,onChange:o=>w(o.target.value),placeholder:c("providers.filters.searchPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(K,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground",children:c("providers.filters.typeAll")}),e.jsxs(fe,{value:b,onValueChange:D,children:[e.jsx(ge,{children:e.jsx(ve,{})}),e.jsxs(ye,{children:[e.jsx(N,{value:"all",children:c("providers.filters.typeAll")}),e.jsx(N,{value:"openai",children:"OpenAI"}),e.jsx(N,{value:"anthropic",children:"Anthropic"}),e.jsx(N,{value:"deepseek",children:"DeepSeek"}),e.jsx(N,{value:"huawei",children:"Huawei"}),e.jsx(N,{value:"kimi",children:"Kimi"}),e.jsx(N,{value:"custom",children:"Custom"})]})]})]}),e.jsx("div",{className:"flex items-end sm:col-span-2 xl:col-span-1",children:e.jsx(v,{variant:"ghost",size:"sm",onClick:k,disabled:!f.trim()&&b==="all",className:"w-full xl:w-auto",children:c("common.actions.reset")})})]}),C?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:c("common.loading")}):l===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:c("providers.emptyState")}),e.jsx("p",{className:"mt-2 text-xs",children:c("providers.emptyStateSub",{default:"点击上方按钮添加您的第一个提供商"})})]}):a.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:c("providers.emptyFiltered")})}):e.jsx("div",{className:"grid gap-4 [grid-template-columns:repeat(auto-fit,minmax(280px,1fr))]",children:a.map(o=>{var g;return e.jsx(G,{className:"flex flex-col overflow-hidden","data-testid":"provider-card",children:e.jsxs(W,{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:o.label||o.id}),o.type?e.jsx(Ue,{type:o.type}):null]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",o.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:o.baseUrl})]}),o.defaultModel?e.jsx(E,{variant:"default",className:"text-xs",children:m.get(o.id)??o.defaultModel}):e.jsx(E,{variant:"secondary",className:"text-xs",children:c("providers.card.noDefault")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsx(S,{label:c("providers.card.authMode"),value:T(o)}),e.jsx(S,{label:c("providers.card.modelsTitle"),value:(g=o.models)!=null&&g.length?c("providers.card.modelCount",{count:o.models.length}):c("providers.card.passthrough")}),e.jsx(S,{label:c("providers.card.defaultModelLabel"),value:o.defaultModel?m.get(o.id)??o.defaultModel:c("providers.card.noDefault"),truncate:!0})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsx(S,{label:"Routing readiness",value:o.defaultModel?"Ready":"Needs default"}),e.jsx(S,{label:"Endpoint type",value:o.type?o.type:"custom"})]}),e.jsxs("div",{className:"space-y-2 rounded-lg border border-border bg-secondary p-3",children:[e.jsx(K,{className:"text-xs uppercase tracking-[0.16em] text-muted-foreground",children:c("providers.card.modelsTitle")}),o.models&&o.models.length>0?e.jsx("div",{className:"flex max-h-24 flex-wrap gap-1 overflow-y-auto",children:o.models.map(M=>e.jsx(E,{variant:"outline",className:"text-xs",children:je(M)},M.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:c("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(v,{variant:"default",size:"sm",onClick:()=>d(o),className:"w-full",children:c("providers.actions.edit")}),e.jsx(v,{variant:"outline",size:"sm",onClick:()=>u(o),disabled:s===o.id,className:"w-full",children:s===o.id?c("common.actions.testingConnection"):c("providers.actions.test")}),e.jsx(v,{variant:"destructive",size:"sm",onClick:()=>p(o),className:"w-full",children:c("providers.actions.delete")})]})]})},o.id)})})]})})}function S({label:l,value:a,truncate:m}){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:l}),e.jsx("p",{className:$("mt-1 text-sm font-medium",m&&"truncate"),children:a})]})}function Ue({type:l}){const a={openai:{label:"OpenAI",variant:"success"},deepseek:{label:"DeepSeek",variant:"info"},huawei:{label:"华为云",variant:"warning"},kimi:{label:"Kimi",variant:"purple"},anthropic:{label:"Anthropic",variant:"pink"},custom:{label:"Custom",variant:"secondary"}},{label:m,variant:f}=a[l]||a.custom;return e.jsx(E,{variant:f,className:"text-xs",children:m})}function Ie({open:l,provider:a,options:m,usePreset:f,preservedExtras:b,onPresetChange:C,onConfirm:s,onClose:d}){const{t:u}=R();return a?e.jsx(we,{open:l,onOpenChange:p=>!p&&d(),children:e.jsxs(ke,{className:"max-w-2xl",children:[e.jsxs(Me,{children:[e.jsx(Ce,{children:u("providers.testDialog.title")}),e.jsx(De,{children:u("providers.testDialog.subtitle",{name:a.label||a.id})})]}),e.jsxs(Te,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-primary/20 bg-accent p-4 text-sm text-primary",children:u("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(K,{htmlFor:"provider-test-preset",children:u("providers.testDialog.presetLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u("providers.testDialog.presetDescription")})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(Ae,{id:"provider-test-preset",checked:f,onCheckedChange:C})})]}),f?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:u("providers.testDialog.presetPreviewSummary")}),e.jsx("div",{className:"mt-2 space-y-1",children:m.map(p=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1 text-xs",children:[p.key,": ",p.value]},p.key))})]})}):e.jsx("p",{className:"text-xs text-muted-foreground",children:u("providers.testDialog.presetDescription")})]}),Object.keys(b).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:u("providers.testDialog.preservedInfo")}),Object.entries(b).map(([p,w])=>e.jsxs("code",{className:"block rounded-md border border-border bg-card px-2 py-1",children:[p,": ",w]},p))]})]}),e.jsxs(Pe,{children:[e.jsx(v,{variant:"outline",onClick:d,children:u("providers.testDialog.cancel")}),e.jsx(v,{onClick:()=>void s(),children:u("providers.testDialog.primary")})]})]})}):null}function z(){return typeof globalThis.crypto<"u"&&typeof globalThis.crypto.randomUUID=="function"?globalThis.crypto.randomUUID():Math.random().toString(36).slice(2,10)}function Ee(){return{_key:z(),id:"",label:""}}const I={openai:{baseUrl:"https://api.openai.com/v1"},deepseek:{baseUrl:"https://api.deepseek.com/v1"},huawei:{baseUrl:"https://api.modelarts-maas.com/v1"},kimi:{baseUrl:"https://api.moonshot.cn/v1"},anthropic:{baseUrl:"https://api.anthropic.com/v1"},custom:{}},J=[{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 L(l){return l==="anthropic"?"authToken":"apiKey"}function Z(l){return l?{id:l.id,label:l.label??l.id,baseUrl:l.baseUrl,apiKey:l.apiKey??"",type:l.type??"custom",defaultModel:l.defaultModel??"",models:(l.models??[]).map(a=>({...a,_key:z()})),authMode:l.authMode??L(l.type??"custom")}:{id:"",label:"",baseUrl:"",apiKey:"",type:"custom",defaultModel:"",models:[],authMode:L("custom")}}function Ke(l){return{_key:z(),id:l.id,label:l.label}}function Le({open:l,mode:a,provider:m,existingProviderIds:f,onClose:b,onSubmit:C}){const{t:s}=R(),[d,u]=h.useState(()=>Z(m)),[p,w]=h.useState({}),[D,k]=h.useState(!1),[c,T]=h.useState(null),o=h.useRef(null),g=h.useRef(null),M=h.useRef(null),[P,q]=h.useState(a==="edit");h.useEffect(()=>{l&&(u(Z(m)),w({}),T(null),k(!1),q(a==="edit"))},[l,m,a]),h.useEffect(()=>{if(!l)return;const r=t=>{t.key==="Escape"&&b()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[l,b]),h.useEffect(()=>{if(l){if(a==="create"&&M.current){M.current.focus();return}g.current&&g.current.focus()}},[l,a]);const O=a==="create",_=h.useMemo(()=>d.models.filter(r=>r.id.trim().length>0),[d.models]),V=h.useMemo(()=>{var r;return((r=J.find(t=>t.value===d.type))==null?void 0:r.label)??"Custom"},[d.type]),X=(r,t)=>s(t==="authToken"?"providers.drawer.fields.authModeAuthToken":t==="xAuthToken"?"providers.drawer.fields.authModeXAuthToken":r==="anthropic"?"providers.drawer.fields.authModeApiKey":"providers.drawer.fields.authModeProviderDefault"),ee=d.label.trim()||d.id.trim()||s("providers.drawer.summary.untitled"),Q=h.useMemo(()=>[{label:s("providers.drawer.summary.type"),value:V},{label:s("providers.drawer.summary.auth"),value:X(d.type,d.authMode)},{label:s("providers.drawer.summary.models"),value:_.length.toLocaleString()}],[_.length,d.authMode,d.type,V,s]),B=r=>t=>{u(n=>({...n,[r]:t}))},re=r=>{u(t=>{const i=!P||t.label.trim().length===0||t.label===t.id?r:t.label;return{...t,id:r,label:i}})},se=r=>{u(t=>{var Y;const i=I[r??"custom"]??I.custom,x=L(t.type),y=L(r),j=Object.values(I).map(A=>A.baseUrl).filter(A=>!!A),F=!t.baseUrl||j.includes(t.baseUrl),ce=a==="create"&&(t.models.length===0||t.models.every(A=>A.id.trim().length===0)),U={...t,type:r,authMode:t.authMode===x?y:t.authMode};return i!=null&&i.baseUrl&&F&&(U.baseUrl=i.baseUrl),i!=null&&i.models&&ce&&(U.models=i.models.map(Ke),U.defaultModel=i.defaultModel??((Y=i.models[0])==null?void 0:Y.id)??""),U})},ae=(r,t)=>{u(n=>{const i=[...n.models];return i[r]={...i[r],...t},{...n,models:i}})},de=(r,t)=>{u(n=>{const i=[...n.models],x=i[r];if(!x)return n;const y=!P||!x.label||x.label===x.id,j={...x,id:t,label:y?t:x.label};i[r]=j;const F=n.defaultModel===x.id?t:n.defaultModel;return{...n,models:i,defaultModel:F}})},te=r=>{u(t=>{if(r<0||r>=t.models.length)return t;const n=t.models.filter((x,y)=>y!==r);let i=t.defaultModel;return n.some(x=>x.id===i)||(i=""),{...t,models:n,defaultModel:i}})},le=()=>{u(r=>({...r,models:[...r.models,Ee()]}))},H=r=>{u(t=>({...t,authMode:r}))},oe=()=>{const r={},t=d.id.trim(),n=d.baseUrl.trim();if(a==="create"&&(t.length===0?r.id=s("providers.drawer.errors.idRequired"):f.includes(t)&&(r.id=s("providers.drawer.errors.idDuplicate"))),a==="edit"&&t.length===0&&(r.id=s("providers.drawer.errors.idRequired")),n.length===0)r.baseUrl=s("providers.drawer.errors.baseUrlInvalid");else try{new URL(n)}catch{r.baseUrl=s("providers.drawer.errors.baseUrlInvalid")}if(d.models.length>0){const i=new Set;d.models.some(y=>{const j=y.id.trim();return j.length===0||i.has(j)?!0:(i.add(j),!1)})&&(r.models=s("providers.drawer.errors.modelInvalid"))}return d.defaultModel&&!d.models.some(i=>i.id===d.defaultModel)&&(r.models=s("providers.drawer.errors.defaultInvalid")),w(r),Object.keys(r).length===0},ie=()=>{const r=d.models.map(i=>{var x;return{id:i.id.trim(),label:(x=i.label)!=null&&x.trim()?i.label.trim():void 0}}).filter(i=>i.id.length>0),t=m!=null&&m.extraHeaders&&Object.keys(m.extraHeaders).length>0?m.extraHeaders:void 0,n=d.authMode==="apiKey"&&d.type!=="anthropic"?void 0:d.authMode;return{id:d.id.trim(),label:d.label.trim()||d.id.trim(),baseUrl:d.baseUrl.trim(),apiKey:d.apiKey.trim()||void 0,type:d.type??"custom",defaultModel:d.defaultModel||void 0,models:r.length>0?r:void 0,extraHeaders:t,authMode:n}},ne=async()=>{if(T(null),!!oe()){k(!0);try{const r=ie();await C(r)}catch(r){T(s("providers.drawer.toast.saveFailure",{message:r instanceof Error?r.message:"unknown"})),k(!1);return}k(!1),b()}};return l?e.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[e.jsx("div",{className:"flex-1 bg-background/80 backdrop-blur-sm",onClick:b,"aria-hidden":"true"}),e.jsxs("aside",{ref:o,role:"dialog","aria-modal":"true","aria-labelledby":"provider-drawer-title","aria-describedby":"provider-drawer-desc",className:"flex h-full min-h-0 w-full max-w-5xl flex-col border-l border-border 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:s(O?"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:s(O?"providers.drawer.createTitle":"providers.drawer.editTitle")}),e.jsx("p",{id:"provider-drawer-desc",className:"text-sm text-muted-foreground",children:s("providers.drawer.description")})]})]}),e.jsx("button",{type:"button",ref:g,onClick:b,className:"rounded-full border border-border bg-card px-4 py-2 text-sm transition hover:border-primary/20 hover:bg-accent/50",children:s("common.actions.close")})]}),e.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-3",children:Q.map(r=>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:r.label}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-foreground",children:r.value})]},r.label))})]}),e.jsxs("div",{className:"grid min-h-0 flex-1 overflow-hidden xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"min-h-0 overflow-y-auto px-6 py-5 pb-10",children:[e.jsxs("section",{className:"space-y-5","aria-labelledby":"provider-type-fields",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-type-fields",className:"text-sm font-semibold",children:s("providers.drawer.sections.type")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.drawer.hints.type")})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:J.map(r=>{var n;const t=r.value===d.type;return e.jsxs("button",{type:"button",onClick:()=>se(r.value),className:$("rounded-2xl border px-4 py-3 text-left transition",t?"border-primary bg-primary/10 text-primary shadow-sm":"border-border bg-card text-foreground hover:border-primary/20 hover:bg-accent/50"),children:[e.jsx("div",{className:"text-sm font-semibold",children:r.label}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:((n=I[r.value??"custom"])==null?void 0:n.baseUrl)??s("providers.drawer.hints.customProvider")})]},r.value??"custom")})})]}),e.jsxs("section",{className:"mt-8 space-y-4","aria-labelledby":"provider-basic-info",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{id:"provider-basic-info",className:"text-sm font-semibold",children:s("providers.drawer.sections.basic")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.drawer.hints.basic")})]}),e.jsx("button",{type:"button",onClick:()=>q(r=>!r),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:s(P?"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:s("providers.drawer.fields.id")}),e.jsx("input",{value:d.id,ref:M,onChange:r=>re(r.target.value),disabled:!O,placeholder:s("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":!!p.id}),p.id?e.jsx("span",{className:"text-xs text-red-500",children:p.id}):null]}),e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s("providers.drawer.fields.label")}),e.jsx("input",{value:d.label,onChange:r=>B("label")(r.target.value),placeholder:s("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:s("providers.drawer.fields.baseUrl")}),e.jsx("input",{value:d.baseUrl,onChange:r=>B("baseUrl")(r.target.value),placeholder:s("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":!!p.baseUrl}),p.baseUrl?e.jsx("span",{className:"text-xs text-red-500",children:p.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:s("providers.drawer.sections.auth")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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:s("providers.drawer.fields.apiKey")}),e.jsx("input",{value:d.apiKey,onChange:r=>B("apiKey")(r.target.value),placeholder:s("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:s("providers.drawer.fields.authMode")}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:s("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:d.authMode==="apiKey",onChange:()=>H("apiKey"),className:"mt-0.5"}),e.jsx("span",{children:X(d.type,"apiKey")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-xl border border-transparent px-3 py-2 transition hover:bg-primary/5",children:[e.jsx("input",{type:"radio",name:"provider-auth-mode",value:"authToken",checked:d.authMode==="authToken",onChange:()=>H("authToken"),className:"mt-0.5"}),e.jsx("span",{children:s("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:d.authMode==="xAuthToken",onChange:()=>H("xAuthToken"),className:"mt-0.5"}),e.jsx("span",{children:s("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:s("providers.drawer.fields.models")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("providers.drawer.modelsDescription")})]}),e.jsx("button",{type:"button",onClick:le,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:s("providers.drawer.fields.addModel")})]}),p.models?e.jsx("p",{className:"text-xs text-red-500",children:p.models}):null,e.jsxs("div",{className:"space-y-4",children:[d.models.map((r,t)=>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:s("providers.drawer.fields.modelId")}),e.jsx("input",{value:r.id,onChange:n=>de(t,n.target.value),placeholder:s("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"})]}),P?e.jsxs("label",{className:"flex flex-col gap-2 text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s("providers.drawer.fields.modelLabel")}),e.jsx("input",{value:r.label??"",onChange:n=>ae(t,{label:n.target.value}),placeholder:s("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:r.id,checked:d.defaultModel===r.id,onChange:()=>u(n=>({...n,defaultModel:r.id})),disabled:r.id.trim().length===0}),s("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:()=>te(t),disabled:d.models.length===0,children:s("providers.drawer.fields.removeModel")})]})]},r._key)),d.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:s("providers.drawer.noModelsTitle")}),e.jsx("p",{className:"text-xs leading-relaxed text-amber-800 dark:text-amber-300",children:s("providers.drawer.noModelsHint",{providerId:d.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:s("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-*": "',(d.id||"provider-id").trim()||"provider-id",':*"']})]})]})}):null]}),_.length>1?e.jsx("div",{className:"text-xs text-muted-foreground",children:s("providers.drawer.defaultHint",{model:d.defaultModel||s("providers.card.noDefault")})}):null]})]}),e.jsx("aside",{className:"hidden min-h-0 overflow-y-auto 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:s("providers.drawer.formSummary")}),e.jsx("p",{className:"mt-2 text-base font-semibold",children:ee}),e.jsx("div",{className:"mt-4 space-y-3 text-sm",children:Q.map(r=>e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"text-muted-foreground",children:r.label}),e.jsx("span",{className:"text-right font-medium",children:r.value})]},r.label))})]}),e.jsxs("div",{className:"rounded-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:s("providers.drawer.sections.checklist")}),e.jsxs("ul",{className:"mt-3 space-y-2 text-sm text-muted-foreground",children:[e.jsx("li",{children:s("providers.drawer.hints.checkUrl")}),e.jsx("li",{children:s("providers.drawer.hints.checkAuth")}),e.jsx("li",{children:s("providers.drawer.hints.checkModels")})]})]}),P&&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:s("providers.drawer.hints.advancedTitle")}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:s("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:c?e.jsx("span",{children:c}):null}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:b,className:"rounded-full border border-border bg-card px-4 py-2 transition hover:border-primary/20 hover:bg-accent/50",disabled:D,children:s("common.actions.cancel")}),e.jsx("button",{type:"button",onClick:ne,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:D,children:s(D?"common.actions.saving":"common.actions.save")})]})]})]})]}):null}function ar(){const{t:l}=R(),a=Ne();return e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(he,{icon:e.jsx(ue,{className:"h-5 w-5","aria-hidden":"true"}),title:l("providers.title"),description:l("providers.description"),eyebrow:l("modelManagement.providersEyebrow"),breadcrumb:"Gateway / Providers",badge:l("providers.count",{count:a.providerCount}),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.jsx(v,{asChild:!0,variant:"outline",className:"w-full sm:w-auto",children:e.jsxs(pe,{to:"/routing",children:[l("nav.routing"),e.jsx(me,{className:"h-4 w-4","aria-hidden":"true"})]})}),e.jsx(v,{onClick:a.handleOpenCreate,className:"w-full sm:w-auto",children:l("providers.actions.add")})]})}),e.jsx(Se,{configPending:a.configQuery.isPending||!a.config&&a.configQuery.isFetching,defaultLabels:a.defaultLabels,filteredProviders:a.filteredProviders,onOpenEdit:a.handleOpenEdit,onRequestDelete:m=>a.setConfirmAction({kind:"provider",provider:m}),onResetFilters:()=>{a.setProviderSearch(""),a.setProviderTypeFilter("all")},onProviderSearchChange:a.setProviderSearch,onProviderTypeChange:a.setProviderTypeFilter,onTestConnection:a.initiateTestConnection,providerSearch:a.providerSearch,providerTypeFilter:a.providerTypeFilter,providersLength:a.providers.length,testingProviderId:a.testingProviderId}),e.jsx(Le,{open:a.drawerOpen,mode:a.drawerMode,provider:a.drawerMode==="edit"?a.editingProvider:void 0,existingProviderIds:a.providers.map(m=>m.id).filter(m=>a.drawerMode==="edit"&&a.editingProvider?m!==a.editingProvider.id:!0),onClose:()=>{a.setDrawerOpen(!1),a.setEditingProvider(void 0),a.setDrawerMode("create")},onSubmit:a.handleProviderSubmit}),e.jsx(Ie,{open:a.testDialogOpen,provider:a.testDialogProvider,options:a.anthropicTestHeaderOptions,preservedExtras:a.testDialogPreservedExtras,usePreset:a.testDialogUsePreset,onPresetChange:a.setTestDialogUsePreset,onConfirm:a.confirmTestDialog,onClose:a.closeTestDialog}),e.jsx(xe,{open:!!a.confirmAction,onOpenChange:m=>{!m&&!a.confirmingAction&&a.setConfirmAction(null)},title:a.confirmDialogTitle,description:a.confirmDialogDescription,confirmLabel:a.confirmingAction?l("common.actions.loading"):l("common.delete"),cancelLabel:l("common.actions.cancel"),loading:a.confirmingAction,onConfirm:a.handleConfirmDialog,children:a.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:a.confirmDialogName}):null})]})}export{ar as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./vendor-
|
|
1
|
+
import{j as e}from"./vendor-DfnQOGOQ.js";import{c as i}from"./index-OvGsIZkZ.js";import{B as c}from"./badge-CkaH3uCO.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-DfnQOGOQ.js";import{c as m}from"./index-OvGsIZkZ.js";import{C as c,b as x,c as i,d as f,a as j}from"./card-Bem3kP2L.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-DfnQOGOQ.js";import{c as i}from"./index-OvGsIZkZ.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as f,j as e,X as Y,ao as ie,aA as Z,aJ as oe,aK as de,S as ce,at as xe,a1 as me,an as ue}from"./vendor-CseyjbPR.js";import{u as pe,a as A,b as S}from"./query-CR1zzqi0.js";import{P as ee,a as M}from"./PageState-QEhNwS9Q.js";import{B as se}from"./badge-dFhP0Qyo.js";import{h as F,b as q,r as O,c as m,B as $}from"./index-wrD5MdRi.js";import{d as he}from"./utils-BHook6QN.js";import{q as b}from"./queryKeys-BMvyDTQS.js";import"./i18n-DJXLExhE.js";import"./router-cKa0BaP7.js";import"./radix-BMe0_WA0.js";const v={getStatus:()=>O({url:"/api/profiler/status",method:"GET"}),start:()=>F(q.post("/api/profiler/start")),stop:()=>F(q.post("/api/profiler/stop")),listSessions:s=>O({url:"/api/profiler/sessions",method:"GET",params:s}),getSession:s=>O({url:`/api/profiler/sessions/${s}`,method:"GET"}),deleteSession:s=>F(q.delete(`/api/profiler/sessions/${s}`)),clearAll:()=>F(q.post("/api/profiler/sessions/clear"))};function g(s){return s==null?"-":s>=1e3?`${(s/1e3).toFixed(2)}s`:`${Math.round(s)}ms`}function R(s){return s==null?"-":s>=1e3?`${(s/1e3).toFixed(1)}s`:`${Math.round(s)}ms`}function k(s){return s==null?"-":s.toLocaleString()}function Q(s){return s==null?"-":s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function L(s){return s.endedAt==null||s.turnCount===0?s.totalLatencyMs??0:s.endedAt-s.startedAt}function fe(s){const t=s.sessionId;return t.length>18?`${t.slice(0,8)}…${t.slice(-6)}`:t}function be(s){const t=Math.max(0,Date.now()-s),n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n} min ago`;const l=Math.floor(n/60);if(l<24)return`${l} hr ago`;const r=Math.floor(l/24);return`${r} day${r===1?"":"s"} ago`}function ge(s){if(!s)return null;try{return JSON.parse(s)}catch{return null}}function _(s,t){if(Array.isArray(s)){for(const n of s)_(n,t);return}if(s&&typeof s=="object"){const n=s,l=n.tool_calls;Array.isArray(l)&&t.push(...l);const r=n.content;if(Array.isArray(r)){for(const i of r)if(i&&typeof i=="object"){const a=i;a.type==="tool_use"&&t.push(a)}}for(const i of Object.values(n))_(i,t)}}function I(s){const t=[];return _(ge(s.clientResponse),t),t}function le(s,t){const n=s.timestamp-t,l=n+(s.latencyMs??0);return`${(n/1e3).toFixed(3)}s → ${(l/1e3).toFixed(3)}s`}function K(s,t){return he(s??null,t)}function je(s,t){const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),l=URL.createObjectURL(n),r=document.createElement("a");r.href=l,r.download=s,r.click(),URL.revokeObjectURL(l)}function B({tone:s="default",children:t}){return e.jsx("span",{className:m("inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium",s==="accent"?"bg-indigo-100 text-indigo-700":"bg-slate-100 text-slate-600"),children:t})}function Ne({session:s,selected:t,index:n,onClick:l}){const r=["bg-indigo-500","bg-emerald-500","bg-amber-500"],i=t?"bg-indigo-500":r[n%r.length],a=(s.totalInputTokens??0)+(s.totalOutputTokens??0);return e.jsxs("button",{type:"button",onClick:l,className:m("w-full border-b border-border px-4 py-3 text-left transition-colors",t?"bg-indigo-50/70":"hover:bg-slate-50"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:m("h-2 w-2 flex-shrink-0 rounded-full",i)}),e.jsx("span",{className:m("truncate text-sm font-semibold",t?"text-indigo-700":"text-slate-800"),children:fe(s)})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:be(s.startedAt)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 pl-4",children:[e.jsxs(B,{tone:t?"accent":"default",children:[s.turnCount," turns"]}),e.jsx(B,{children:R(L(s))}),e.jsxs(B,{children:[Q(a)," tok"]})]})]})}function te({active:s,icon:t,label:n,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:m("inline-flex h-7 items-center gap-1.5 rounded-full border px-3 text-xs font-medium transition-colors",s?"border-indigo-200 bg-indigo-50 text-indigo-700":"border-transparent bg-slate-50 text-slate-500 hover:bg-slate-100 hover:text-slate-700"),children:[e.jsx(t,{className:"h-3.5 w-3.5"}),n]})}function D({active:s,label:t,count:n,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:m("inline-flex h-6 items-center gap-1.5 rounded-full border px-2.5 text-[11px] font-medium transition-colors",s?"border-indigo-200 bg-indigo-50 text-indigo-700":"border-transparent bg-transparent text-slate-500 hover:bg-slate-100 hover:text-slate-700"),children:[e.jsx("span",{children:t}),typeof n=="number"&&e.jsx("span",{className:"rounded-full bg-amber-100 px-1.5 py-0.5 text-[10px] font-semibold text-amber-800",children:n})]})}function ve({detail:s,selectedTurn:t,onSelectTurn:n}){const l=s.records;if(l.length===0)return e.jsx(M,{compact:!0,className:"min-h-[220px]",title:"No turns recorded"});const r=L(s),i=Math.max(1,...l.map(a=>Math.max(a.latencyMs??0,a.ttftMs??0,1)));return Math.max(1,...l.map(a=>I(a).length)),e.jsxs("div",{className:"border-b border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 px-5 py-3",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Compressed overview · idle gaps folded · wraps as turns grow"}),e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"text-slate-500",children:"Mode:"}),e.jsx("span",{className:"rounded border border-slate-200 bg-slate-100 px-2 py-0.5 font-medium text-slate-700",children:"Compressed"}),e.jsxs("span",{className:"rounded border border-slate-200 bg-white px-2 py-0.5 font-medium text-slate-700",children:["Session ",R(r)]})]})]}),e.jsxs("div",{className:"px-5 pb-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between text-[10px] text-slate-400",children:[e.jsx("span",{children:"start"}),e.jsxs("span",{children:[(r/1e3).toFixed(1),"s"]})]}),e.jsx("div",{className:"grid gap-x-2 gap-y-5",style:{gridTemplateColumns:"repeat(10, minmax(0, 1fr))"},children:l.map((a,u)=>{const p=u===t,y=Math.max(a.latencyMs??0,1),o=`${Math.max(28,Math.min(100,y/i*100))}%`,x=a.ttftMs!=null?`${Math.max(0,Math.min(100,Math.min(a.ttftMs,i)/i*100))}%`:null,C=Math.max(0,a.timestamp-s.startedAt),w=I(a);return e.jsxs("button",{type:"button",onClick:()=>n(u),className:m("border border-transparent px-1.5 py-1 text-left transition-colors",p?"rounded-md border-rose-300":"hover:bg-slate-50/40"),title:`Turn ${a.turnIndex+1}`,children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:m("inline-flex h-5 min-w-5 items-center justify-center rounded-full border px-1.5 text-[11px] font-semibold",p?"border-indigo-300 bg-indigo-100 text-indigo-700":"border-slate-200 bg-white text-slate-700"),children:a.turnIndex+1}),e.jsx("span",{className:"truncate text-[15px] font-semibold text-slate-800",children:R(a.latencyMs)})]})}),e.jsxs("p",{className:"mt-1 text-[10px] text-slate-500",children:["start ",(C/1e3).toFixed(1),"s"]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center justify-between text-[10px] text-slate-500",children:e.jsxs("span",{children:[g(a.ttftMs)," TTFT"]})}),e.jsxs("div",{className:"relative mt-1 h-4 rounded-sm bg-slate-100",children:[e.jsx("div",{className:"h-4 rounded-sm bg-blue-200",style:{width:o}}),x!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"absolute top-[-3px] h-5 w-[3px] -translate-x-1/2 rounded-full bg-violet-500 shadow-[0_0_0_1px_rgba(255,255,255,0.9)]",style:{left:x}}),e.jsx("span",{className:"absolute top-[-6px] h-2.5 w-2.5 -translate-x-1/2 rounded-full border border-white bg-violet-500",style:{left:x}})]})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-[10px] text-slate-500",children:[e.jsx("span",{children:"Tools"}),e.jsx("span",{children:w.length})]}),e.jsx("div",{className:"flex h-5 items-center gap-1",children:e.jsx("span",{className:m("inline-flex h-5 min-w-5 items-center justify-center rounded-md border text-[10px] font-semibold",w.length>0?"border-amber-400 bg-amber-200 text-amber-900":"border-slate-300 bg-white text-slate-500"),children:w.length})})]})]},a.id)})}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-4 text-[11px] text-slate-500",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm bg-blue-200"}),"Total latency"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"relative inline-block h-2.5 w-2.5 rounded-full border border-white bg-violet-500 shadow-[0_0_0_1px_rgba(139,92,246,0.35)]"}),"First token (TTFT)"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-amber-400 bg-amber-200"}),"Tool executing"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-rose-300 bg-rose-50"}),"Selected turn"]})]})]})]})}function ye({detail:s,selectedTurn:t,detailTab:n,onDetailTabChange:l,onSelectTurn:r}){const i=s.records[t];if(!i)return null;const a=I(i),u=(i.inputTokens??0)+(i.outputTokens??0),p=n==="request"?K(i.clientRequest,"(empty request)"):n==="response"?K(i.clientResponse,"(empty response)"):a.length>0?JSON.stringify(a,null,2):"(no tool calls)";return e.jsxs("div",{"data-testid":"profiler-turn-detail",className:"shrink-0 bg-slate-50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-slate-200 bg-white px-5 py-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-xs",children:[e.jsxs("span",{className:"rounded-full px-2 py-1 font-semibold text-white",style:{background:"linear-gradient(135deg, #6E63FF, #4E8DFF)"},children:["Turn ",i.turnIndex+1]}),e.jsx("span",{className:"text-slate-500",children:le(i,s.startedAt)}),e.jsxs("span",{className:"rounded-full bg-violet-100 px-2 py-1 font-semibold text-violet-700",children:["TTFT ",g(i.ttftMs)]}),e.jsxs("span",{className:"rounded-full bg-blue-100 px-2 py-1 font-semibold text-blue-700",children:[Q(u)," tokens"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500",children:[e.jsx("button",{type:"button",onClick:()=>r(Math.max(0,t-1)),disabled:t===0,className:"rounded p-1 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Previous turn",children:e.jsx(xe,{className:"h-4 w-4"})}),e.jsxs("span",{className:"min-w-10 text-center font-medium text-slate-600",children:[t+1," / ",s.records.length]}),e.jsx("button",{type:"button",onClick:()=>r(Math.min(s.records.length-1,t+1)),disabled:t===s.records.length-1,className:"rounded p-1 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Next turn",children:e.jsx(me,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"border-b border-slate-200 bg-white px-5 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(D,{active:n==="request",label:"Request",onClick:()=>l("request")}),e.jsx(D,{active:n==="response",label:"Response",onClick:()=>l("response")}),e.jsx(D,{active:n==="tools",label:"Tool Calls",count:a.length,onClick:()=>l("tools")})]})}),e.jsxs("div",{className:"p-5",children:[e.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-xl bg-[#1E1E2E] p-4 text-xs leading-5 text-slate-200",children:p}),i.error&&e.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:i.error})]})]})}function we({detail:s,selectedTurn:t,detailTab:n,onSelectTurn:l,onDetailTabChange:r}){return e.jsxs("div",{className:"flex min-h-full flex-col",children:[e.jsx(ve,{detail:s,selectedTurn:t,onSelectTurn:l}),e.jsx(ye,{detail:s,selectedTurn:t,detailTab:n,onDetailTabChange:r,onSelectTurn:l})]})}function ne({title:s,payload:t,accentClass:n}){return e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:m("mb-2 text-[11px] font-semibold uppercase tracking-[0.16em]",n),children:s}),e.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:K(t,"(empty)")})]})}function T({label:s,value:t,sub:n,accentClass:l}){return e.jsxs("div",{className:"rounded-2xl border border-border bg-white p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500",children:s}),e.jsx("p",{className:m("mt-2 text-2xl font-semibold text-slate-900",l),children:t}),n&&e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:n})]})}function Te({record:s,sessionStart:t,expanded:n,onToggle:l}){const r=I(s);return e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border bg-white",children:[e.jsxs("button",{type:"button",onClick:l,className:"flex w-full items-center gap-4 px-4 py-3 text-left hover:bg-slate-50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsxs("span",{className:"rounded-full px-2 py-0.5 text-[11px] font-semibold text-white",style:{background:"linear-gradient(135deg, #6E63FF, #4E8DFF)"},children:["T",s.turnIndex+1]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900",children:le(s,t)}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-slate-500",children:[e.jsxs("span",{children:["Total ",g(s.latencyMs)]}),e.jsxs("span",{children:["TTFT ",g(s.ttftMs)]}),e.jsxs("span",{children:["TPOT ",s.tpotMs!=null?`${s.tpotMs.toFixed(1)} ms/tok`:"-"]}),e.jsxs("span",{children:["↑ ",k(s.inputTokens)]}),e.jsxs("span",{children:["↓ ",k(s.outputTokens)]}),e.jsxs("span",{children:[r.length," tool calls"]}),s.error&&e.jsx("span",{className:"rounded-full bg-red-50 px-2 py-0.5 font-medium text-red-600",children:"Error"})]})]})]}),e.jsx(ue,{className:m("h-4 w-4 flex-shrink-0 text-slate-400 transition-transform",n&&"rotate-180")})]}),n&&e.jsxs("div",{className:"border-t border-border bg-slate-50/70 p-4",children:[e.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[e.jsx(ne,{title:"Request",payload:s.clientRequest,accentClass:"text-blue-600"}),e.jsx(ne,{title:"Response",payload:s.clientResponse,accentClass:"text-violet-600"})]}),e.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-amber-600",children:"Tool Calls"}),e.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:r.length>0?JSON.stringify(r,null,2):"(no tool calls)"})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500",children:"Turn Metrics"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-3 gap-y-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Duration"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:g(s.latencyMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"TTFT"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:g(s.ttftMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"TPOT"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:s.tpotMs!=null?`${s.tpotMs.toFixed(1)} ms/tok`:"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Status"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:s.statusCode??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Input"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:k(s.inputTokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Output"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:k(s.outputTokens)})]})]}),s.error&&e.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:s.error})]})]})]})]})}function Me({detail:s,expandedTurn:t,onToggleTurn:n}){if(s.records.length===0)return e.jsx(M,{compact:!0,className:"min-h-[220px]",title:"No turns recorded"});const l=L(s),r=s.records.reduce((o,x)=>{const C=x.latencyMs??0,w=x.ttftMs??0;return o+Math.max(C-w,0)},0),i=l>0?(r/l*100).toFixed(1):"-",a=s.records.map(o=>o.ttftMs).filter(o=>o!=null),u=s.records.map(o=>o.tpotMs).filter(o=>o!=null),p=a.length>0?a.reduce((o,x)=>o+x,0)/a.length:null,y=u.length>0?u.reduce((o,x)=>o+x,0)/u.length:null;return e.jsxs("div",{className:"space-y-5 p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-6",children:[e.jsx(T,{label:"Total Duration",value:g(l),sub:`${s.records.length} turns`}),e.jsx(T,{label:"LLM Time",value:g(r),sub:`${i}% of session`,accentClass:"text-violet-700"}),e.jsx(T,{label:"Avg TTFT",value:g(p)}),e.jsx(T,{label:"Avg TPOT",value:y!=null?`${y.toFixed(1)} ms/tok`:"-"}),e.jsx(T,{label:"Input Tokens",value:k(s.totalInputTokens)}),e.jsx(T,{label:"Output Tokens",value:k(s.totalOutputTokens)})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-900",children:"Per-Turn Breakdown"}),e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Expand a turn to inspect request, response, tool calls, and errors."})]})}),s.records.map(o=>e.jsx(Te,{record:o,sessionStart:s.startedAt,expanded:t===o.turnIndex,onToggle:()=>n(o.turnIndex)},o.id))]})]})}function Ee(){var X,H;const s=pe(),[t,n]=f.useState(null),[l,r]=f.useState("timeline"),[i,a]=f.useState("request"),[u,p]=f.useState(0),[y,o]=f.useState(0),[x,C]=f.useState(""),h=((X=A({queryKey:b.profiler.status(),queryFn:()=>v.getStatus(),refetchInterval:3e3}).data)==null?void 0:X.active)??!1,J=A({queryKey:b.profiler.sessions({}),queryFn:()=>v.listSessions({limit:100}),refetchInterval:h?2e3:!1}),j=((H=J.data)==null?void 0:H.items)??[],P=A({queryKey:b.profiler.session(t),queryFn:()=>v.getSession(t),enabled:t!=null,refetchInterval:h&&t!=null?2e3:!1}),z=S({mutationFn:()=>v.start(),onSuccess:()=>{s.invalidateQueries({queryKey:b.profiler.status()}),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),U=S({mutationFn:()=>v.stop(),onSuccess:()=>{s.invalidateQueries({queryKey:b.profiler.status()}),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),G=S({mutationFn:d=>v.deleteSession(d),onSuccess:(d,N)=>{t===N&&n(null),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),ae=S({mutationFn:()=>v.clearAll(),onSuccess:()=>{n(null),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),V=f.useMemo(()=>{const d=x.trim().toLowerCase();return d?j.filter(N=>N.sessionId.toLowerCase().includes(d)):j},[x,j]),c=P.data,E=j.find(d=>d.id===t)??null,W=(c==null?void 0:c.records[u])??null;f.useEffect(()=>{t&&!j.some(d=>d.id===t)&&n(null)},[t,j]),f.useEffect(()=>{p(0),o(0),a("request")},[t]),f.useEffect(()=>{if(!c){p(0),o(0);return}p(d=>Math.min(d,Math.max(c.records.length-1,0))),o(d=>d==null?0:Math.min(d,Math.max(c.records.length-1,0)))},[c]);const re=()=>{c&&je(`profiler-${c.sessionId}.json`,c)};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",style:{height:"calc(100vh - 64px)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-white px-6 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Y,{className:"h-5 w-5 text-indigo-500"}),e.jsx("span",{className:"text-base font-semibold text-slate-900",children:"Profiler"}),e.jsxs(se,{variant:"outline",className:m("rounded-full border px-2.5 py-1 text-xs font-semibold",h?"border-red-200 bg-red-50 text-red-600":"border-slate-200 bg-slate-50 text-slate-500"),children:[e.jsx("span",{className:m("mr-2 inline-block h-1.5 w-1.5 rounded-full",h?"bg-red-500":"bg-slate-400")}),h?"Recording":"Not Recording"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{size:"sm",variant:h?"destructive":"default",onClick:()=>h?U.mutate():z.mutate(),disabled:z.isPending||U.isPending,children:h?"Stop Recording":"Start Recording"}),e.jsxs($,{size:"sm",variant:"outline",onClick:re,disabled:!c,children:[e.jsx(ie,{className:"mr-1.5 h-3.5 w-3.5"}),"Export"]}),e.jsxs($,{size:"sm",variant:"outline",onClick:()=>ae.mutate(),disabled:j.length===0,className:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 hover:text-red-800",children:[e.jsx(Z,{className:"mr-1.5 h-3.5 w-3.5"}),"Clear"]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden bg-[#F1F3F4]",children:[e.jsxs("div",{className:"flex w-80 flex-shrink-0 flex-col border-r border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-900",children:"Sessions"}),e.jsx(se,{variant:"secondary",className:"rounded-full px-2 py-0.5",children:j.length})]}),e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2.5",children:[e.jsx(oe,{className:"h-3.5 w-3.5 text-slate-400"}),e.jsx("input",{className:"w-full bg-transparent text-sm outline-none placeholder:text-slate-400",placeholder:"Search sessions...",value:x,onChange:d=>C(d.target.value)})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:J.isPending?e.jsx(ee,{compact:!0,className:"min-h-[160px]",label:"Loading..."}):V.length===0?e.jsx(M,{compact:!0,className:"m-4 min-h-[160px]",title:h?"Waiting for requests…":"No sessions",description:h?"Requests with session_id will appear here.":"Start recording to capture LLM sessions."}):V.map((d,N)=>e.jsx(Ne,{session:d,selected:t===d.id,index:N,onClick:()=>n(d.id)},d.id))})]}),e.jsx("div",{className:"flex min-w-0 flex-1 flex-col bg-white",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-white px-5 py-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full bg-indigo-500"}),e.jsx("span",{className:"truncate text-sm font-semibold text-slate-900",children:(c==null?void 0:c.sessionId)??(E==null?void 0:E.sessionId)??t}),e.jsx("span",{className:"text-slate-300",children:"·"}),e.jsx("span",{className:"truncate text-sm text-slate-500",children:c?`${c.turnCount} turns · ${R(L(c))} · ${Q((c.totalInputTokens??0)+(c.totalOutputTokens??0))} tokens`:"Loading session…"})]}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>t&&G.mutate(t),disabled:!t||G.isPending,className:"text-slate-500 hover:text-red-700",children:e.jsx(Z,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"border-b border-border bg-white px-5 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{active:l==="timeline",icon:de,label:"Timeline",onClick:()=>r("timeline")}),e.jsx(te,{active:l==="breakdown",icon:ce,label:"Breakdown",onClick:()=>r("breakdown")})]})}),e.jsx("div",{"data-testid":"profiler-session-content",className:"min-h-0 flex-1 overflow-auto bg-slate-50",children:P.isPending?e.jsx(ee,{compact:!0,className:"min-h-[240px]",label:"Loading session..."}):P.isError?e.jsx(M,{compact:!0,className:"m-5 min-h-[220px]",tone:"danger",title:"Failed to load session"}):c?l==="timeline"?e.jsx(we,{detail:c,selectedTurn:u,detailTab:i,onSelectTurn:p,onDetailTabChange:a}):e.jsx(Me,{detail:c,expandedTurn:y,onToggleTurn:d=>o(N=>N===d?null:d)}):e.jsx(M,{compact:!0,className:"m-5 min-h-[220px]",title:"Session not found"})}),W&&e.jsxs("span",{className:"sr-only",children:["Selected turn ",W.turnIndex+1]})]}):e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(M,{title:"Select a session",description:"Choose a session from the left to inspect its timeline, message payloads, and stats.",icon:e.jsx(Y,{className:"h-5 w-5"})})})})]})]})}export{Ee as default};
|
|
1
|
+
import{r as f,j as e,Y as X,ap as ie,aB as Z,aK as oe,aL as de,S as ce,au as xe,a2 as me,ao as ue}from"./vendor-DfnQOGOQ.js";import{u as pe,a as A,b as S}from"./query-Db16w3tH.js";import{P as ee,a as M}from"./PageState-DSoiwsKr.js";import{B as se}from"./badge-CkaH3uCO.js";import{h as F,b as q,r as O,c as m,B as $}from"./index-OvGsIZkZ.js";import{d as he}from"./utils-BHook6QN.js";import{q as b}from"./queryKeys-BMvyDTQS.js";import"./i18n-dgCQR_PB.js";import"./router-BURlSZbt.js";import"./radix-D08JKSgz.js";const v={getStatus:()=>O({url:"/api/profiler/status",method:"GET"}),start:()=>F(q.post("/api/profiler/start")),stop:()=>F(q.post("/api/profiler/stop")),listSessions:s=>O({url:"/api/profiler/sessions",method:"GET",params:s}),getSession:s=>O({url:`/api/profiler/sessions/${s}`,method:"GET"}),deleteSession:s=>F(q.delete(`/api/profiler/sessions/${s}`)),clearAll:()=>F(q.post("/api/profiler/sessions/clear"))};function g(s){return s==null?"-":s>=1e3?`${(s/1e3).toFixed(2)}s`:`${Math.round(s)}ms`}function R(s){return s==null?"-":s>=1e3?`${(s/1e3).toFixed(1)}s`:`${Math.round(s)}ms`}function k(s){return s==null?"-":s.toLocaleString()}function Q(s){return s==null?"-":s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function L(s){return s.endedAt==null||s.turnCount===0?s.totalLatencyMs??0:s.endedAt-s.startedAt}function fe(s){const t=s.sessionId;return t.length>18?`${t.slice(0,8)}…${t.slice(-6)}`:t}function be(s){const t=Math.max(0,Date.now()-s),n=Math.floor(t/6e4);if(n<1)return"just now";if(n<60)return`${n} min ago`;const l=Math.floor(n/60);if(l<24)return`${l} hr ago`;const r=Math.floor(l/24);return`${r} day${r===1?"":"s"} ago`}function ge(s){if(!s)return null;try{return JSON.parse(s)}catch{return null}}function _(s,t){if(Array.isArray(s)){for(const n of s)_(n,t);return}if(s&&typeof s=="object"){const n=s,l=n.tool_calls;Array.isArray(l)&&t.push(...l);const r=n.content;if(Array.isArray(r)){for(const i of r)if(i&&typeof i=="object"){const a=i;a.type==="tool_use"&&t.push(a)}}for(const i of Object.values(n))_(i,t)}}function I(s){const t=[];return _(ge(s.clientResponse),t),t}function le(s,t){const n=s.timestamp-t,l=n+(s.latencyMs??0);return`${(n/1e3).toFixed(3)}s → ${(l/1e3).toFixed(3)}s`}function K(s,t){return he(s??null,t)}function je(s,t){const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),l=URL.createObjectURL(n),r=document.createElement("a");r.href=l,r.download=s,r.click(),URL.revokeObjectURL(l)}function B({tone:s="default",children:t}){return e.jsx("span",{className:m("inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium",s==="accent"?"bg-indigo-100 text-indigo-700":"bg-slate-100 text-slate-600"),children:t})}function Ne({session:s,selected:t,index:n,onClick:l}){const r=["bg-indigo-500","bg-emerald-500","bg-amber-500"],i=t?"bg-indigo-500":r[n%r.length],a=(s.totalInputTokens??0)+(s.totalOutputTokens??0);return e.jsxs("button",{type:"button",onClick:l,className:m("w-full border-b border-border px-4 py-3 text-left transition-colors",t?"bg-indigo-50/70":"hover:bg-slate-50"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:m("h-2 w-2 flex-shrink-0 rounded-full",i)}),e.jsx("span",{className:m("truncate text-sm font-semibold",t?"text-indigo-700":"text-slate-800"),children:fe(s)})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:be(s.startedAt)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 pl-4",children:[e.jsxs(B,{tone:t?"accent":"default",children:[s.turnCount," turns"]}),e.jsx(B,{children:R(L(s))}),e.jsxs(B,{children:[Q(a)," tok"]})]})]})}function te({active:s,icon:t,label:n,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:m("inline-flex h-7 items-center gap-1.5 rounded-full border px-3 text-xs font-medium transition-colors",s?"border-indigo-200 bg-indigo-50 text-indigo-700":"border-transparent bg-slate-50 text-slate-500 hover:bg-slate-100 hover:text-slate-700"),children:[e.jsx(t,{className:"h-3.5 w-3.5"}),n]})}function D({active:s,label:t,count:n,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,className:m("inline-flex h-6 items-center gap-1.5 rounded-full border px-2.5 text-[11px] font-medium transition-colors",s?"border-indigo-200 bg-indigo-50 text-indigo-700":"border-transparent bg-transparent text-slate-500 hover:bg-slate-100 hover:text-slate-700"),children:[e.jsx("span",{children:t}),typeof n=="number"&&e.jsx("span",{className:"rounded-full bg-amber-100 px-1.5 py-0.5 text-[10px] font-semibold text-amber-800",children:n})]})}function ve({detail:s,selectedTurn:t,onSelectTurn:n}){const l=s.records;if(l.length===0)return e.jsx(M,{compact:!0,className:"min-h-[220px]",title:"No turns recorded"});const r=L(s),i=Math.max(1,...l.map(a=>Math.max(a.latencyMs??0,a.ttftMs??0,1)));return Math.max(1,...l.map(a=>I(a).length)),e.jsxs("div",{className:"border-b border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 px-5 py-3",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"Compressed overview · idle gaps folded · wraps as turns grow"}),e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"text-slate-500",children:"Mode:"}),e.jsx("span",{className:"rounded border border-slate-200 bg-slate-100 px-2 py-0.5 font-medium text-slate-700",children:"Compressed"}),e.jsxs("span",{className:"rounded border border-slate-200 bg-white px-2 py-0.5 font-medium text-slate-700",children:["Session ",R(r)]})]})]}),e.jsxs("div",{className:"px-5 pb-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between text-[10px] text-slate-400",children:[e.jsx("span",{children:"start"}),e.jsxs("span",{children:[(r/1e3).toFixed(1),"s"]})]}),e.jsx("div",{className:"grid gap-x-2 gap-y-5",style:{gridTemplateColumns:"repeat(10, minmax(0, 1fr))"},children:l.map((a,u)=>{const p=u===t,y=Math.max(a.latencyMs??0,1),o=`${Math.max(28,Math.min(100,y/i*100))}%`,x=a.ttftMs!=null?`${Math.max(0,Math.min(100,Math.min(a.ttftMs,i)/i*100))}%`:null,C=Math.max(0,a.timestamp-s.startedAt),w=I(a);return e.jsxs("button",{type:"button",onClick:()=>n(u),className:m("border border-transparent px-1.5 py-1 text-left transition-colors",p?"rounded-md border-rose-300":"hover:bg-slate-50/40"),title:`Turn ${a.turnIndex+1}`,children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:m("inline-flex h-5 min-w-5 items-center justify-center rounded-full border px-1.5 text-[11px] font-semibold",p?"border-indigo-300 bg-indigo-100 text-indigo-700":"border-slate-200 bg-white text-slate-700"),children:a.turnIndex+1}),e.jsx("span",{className:"truncate text-[15px] font-semibold text-slate-800",children:R(a.latencyMs)})]})}),e.jsxs("p",{className:"mt-1 text-[10px] text-slate-500",children:["start ",(C/1e3).toFixed(1),"s"]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex items-center justify-between text-[10px] text-slate-500",children:e.jsxs("span",{children:[g(a.ttftMs)," TTFT"]})}),e.jsxs("div",{className:"relative mt-1 h-4 rounded-sm bg-slate-100",children:[e.jsx("div",{className:"h-4 rounded-sm bg-blue-200",style:{width:o}}),x!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"absolute top-[-3px] h-5 w-[3px] -translate-x-1/2 rounded-full bg-violet-500 shadow-[0_0_0_1px_rgba(255,255,255,0.9)]",style:{left:x}}),e.jsx("span",{className:"absolute top-[-6px] h-2.5 w-2.5 -translate-x-1/2 rounded-full border border-white bg-violet-500",style:{left:x}})]})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-[10px] text-slate-500",children:[e.jsx("span",{children:"Tools"}),e.jsx("span",{children:w.length})]}),e.jsx("div",{className:"flex h-5 items-center gap-1",children:e.jsx("span",{className:m("inline-flex h-5 min-w-5 items-center justify-center rounded-md border text-[10px] font-semibold",w.length>0?"border-amber-400 bg-amber-200 text-amber-900":"border-slate-300 bg-white text-slate-500"),children:w.length})})]})]},a.id)})}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-4 text-[11px] text-slate-500",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm bg-blue-200"}),"Total latency"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"relative inline-block h-2.5 w-2.5 rounded-full border border-white bg-violet-500 shadow-[0_0_0_1px_rgba(139,92,246,0.35)]"}),"First token (TTFT)"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-amber-400 bg-amber-200"}),"Tool executing"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-sm border border-rose-300 bg-rose-50"}),"Selected turn"]})]})]})]})}function ye({detail:s,selectedTurn:t,detailTab:n,onDetailTabChange:l,onSelectTurn:r}){const i=s.records[t];if(!i)return null;const a=I(i),u=(i.inputTokens??0)+(i.outputTokens??0),p=n==="request"?K(i.clientRequest,"(empty request)"):n==="response"?K(i.clientResponse,"(empty response)"):a.length>0?JSON.stringify(a,null,2):"(no tool calls)";return e.jsxs("div",{"data-testid":"profiler-turn-detail",className:"shrink-0 bg-slate-50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-slate-200 bg-white px-5 py-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-xs",children:[e.jsxs("span",{className:"rounded-full px-2 py-1 font-semibold text-white",style:{background:"linear-gradient(135deg, #6E63FF, #4E8DFF)"},children:["Turn ",i.turnIndex+1]}),e.jsx("span",{className:"text-slate-500",children:le(i,s.startedAt)}),e.jsxs("span",{className:"rounded-full bg-violet-100 px-2 py-1 font-semibold text-violet-700",children:["TTFT ",g(i.ttftMs)]}),e.jsxs("span",{className:"rounded-full bg-blue-100 px-2 py-1 font-semibold text-blue-700",children:[Q(u)," tokens"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500",children:[e.jsx("button",{type:"button",onClick:()=>r(Math.max(0,t-1)),disabled:t===0,className:"rounded p-1 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Previous turn",children:e.jsx(xe,{className:"h-4 w-4"})}),e.jsxs("span",{className:"min-w-10 text-center font-medium text-slate-600",children:[t+1," / ",s.records.length]}),e.jsx("button",{type:"button",onClick:()=>r(Math.min(s.records.length-1,t+1)),disabled:t===s.records.length-1,className:"rounded p-1 hover:bg-slate-100 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Next turn",children:e.jsx(me,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"border-b border-slate-200 bg-white px-5 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(D,{active:n==="request",label:"Request",onClick:()=>l("request")}),e.jsx(D,{active:n==="response",label:"Response",onClick:()=>l("response")}),e.jsx(D,{active:n==="tools",label:"Tool Calls",count:a.length,onClick:()=>l("tools")})]})}),e.jsxs("div",{className:"p-5",children:[e.jsx("pre",{className:"max-h-[420px] overflow-auto rounded-xl bg-[#1E1E2E] p-4 text-xs leading-5 text-slate-200",children:p}),i.error&&e.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:i.error})]})]})}function we({detail:s,selectedTurn:t,detailTab:n,onSelectTurn:l,onDetailTabChange:r}){return e.jsxs("div",{className:"flex min-h-full flex-col",children:[e.jsx(ve,{detail:s,selectedTurn:t,onSelectTurn:l}),e.jsx(ye,{detail:s,selectedTurn:t,detailTab:n,onDetailTabChange:r,onSelectTurn:l})]})}function ne({title:s,payload:t,accentClass:n}){return e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:m("mb-2 text-[11px] font-semibold uppercase tracking-[0.16em]",n),children:s}),e.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:K(t,"(empty)")})]})}function T({label:s,value:t,sub:n,accentClass:l}){return e.jsxs("div",{className:"rounded-2xl border border-border bg-white p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500",children:s}),e.jsx("p",{className:m("mt-2 text-2xl font-semibold text-slate-900",l),children:t}),n&&e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:n})]})}function Te({record:s,sessionStart:t,expanded:n,onToggle:l}){const r=I(s);return e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-border bg-white",children:[e.jsxs("button",{type:"button",onClick:l,className:"flex w-full items-center gap-4 px-4 py-3 text-left hover:bg-slate-50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsxs("span",{className:"rounded-full px-2 py-0.5 text-[11px] font-semibold text-white",style:{background:"linear-gradient(135deg, #6E63FF, #4E8DFF)"},children:["T",s.turnIndex+1]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900",children:le(s,t)}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-slate-500",children:[e.jsxs("span",{children:["Total ",g(s.latencyMs)]}),e.jsxs("span",{children:["TTFT ",g(s.ttftMs)]}),e.jsxs("span",{children:["TPOT ",s.tpotMs!=null?`${s.tpotMs.toFixed(1)} ms/tok`:"-"]}),e.jsxs("span",{children:["↑ ",k(s.inputTokens)]}),e.jsxs("span",{children:["↓ ",k(s.outputTokens)]}),e.jsxs("span",{children:[r.length," tool calls"]}),s.error&&e.jsx("span",{className:"rounded-full bg-red-50 px-2 py-0.5 font-medium text-red-600",children:"Error"})]})]})]}),e.jsx(ue,{className:m("h-4 w-4 flex-shrink-0 text-slate-400 transition-transform",n&&"rotate-180")})]}),n&&e.jsxs("div",{className:"border-t border-border bg-slate-50/70 p-4",children:[e.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[e.jsx(ne,{title:"Request",payload:s.clientRequest,accentClass:"text-blue-600"}),e.jsx(ne,{title:"Response",payload:s.clientResponse,accentClass:"text-violet-600"})]}),e.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-amber-600",children:"Tool Calls"}),e.jsx("pre",{className:"max-h-64 overflow-auto rounded-lg bg-slate-950/95 p-3 text-xs leading-5 text-slate-200",children:r.length>0?JSON.stringify(r,null,2):"(no tool calls)"})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-white p-3",children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-slate-500",children:"Turn Metrics"}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-3 gap-y-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Duration"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:g(s.latencyMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"TTFT"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:g(s.ttftMs)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"TPOT"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:s.tpotMs!=null?`${s.tpotMs.toFixed(1)} ms/tok`:"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Status"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:s.statusCode??"-"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Input"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:k(s.inputTokens)})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-slate-500",children:"Output"}),e.jsx("dd",{className:"mt-0.5 font-medium text-slate-900",children:k(s.outputTokens)})]})]}),s.error&&e.jsx("p",{className:"mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:s.error})]})]})]})]})}function Me({detail:s,expandedTurn:t,onToggleTurn:n}){if(s.records.length===0)return e.jsx(M,{compact:!0,className:"min-h-[220px]",title:"No turns recorded"});const l=L(s),r=s.records.reduce((o,x)=>{const C=x.latencyMs??0,w=x.ttftMs??0;return o+Math.max(C-w,0)},0),i=l>0?(r/l*100).toFixed(1):"-",a=s.records.map(o=>o.ttftMs).filter(o=>o!=null),u=s.records.map(o=>o.tpotMs).filter(o=>o!=null),p=a.length>0?a.reduce((o,x)=>o+x,0)/a.length:null,y=u.length>0?u.reduce((o,x)=>o+x,0)/u.length:null;return e.jsxs("div",{className:"space-y-5 p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-6",children:[e.jsx(T,{label:"Total Duration",value:g(l),sub:`${s.records.length} turns`}),e.jsx(T,{label:"LLM Time",value:g(r),sub:`${i}% of session`,accentClass:"text-violet-700"}),e.jsx(T,{label:"Avg TTFT",value:g(p)}),e.jsx(T,{label:"Avg TPOT",value:y!=null?`${y.toFixed(1)} ms/tok`:"-"}),e.jsx(T,{label:"Input Tokens",value:k(s.totalInputTokens)}),e.jsx(T,{label:"Output Tokens",value:k(s.totalOutputTokens)})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-900",children:"Per-Turn Breakdown"}),e.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Expand a turn to inspect request, response, tool calls, and errors."})]})}),s.records.map(o=>e.jsx(Te,{record:o,sessionStart:s.startedAt,expanded:t===o.turnIndex,onToggle:()=>n(o.turnIndex)},o.id))]})]})}function Ee(){var Y,H;const s=pe(),[t,n]=f.useState(null),[l,r]=f.useState("timeline"),[i,a]=f.useState("request"),[u,p]=f.useState(0),[y,o]=f.useState(0),[x,C]=f.useState(""),h=((Y=A({queryKey:b.profiler.status(),queryFn:()=>v.getStatus(),refetchInterval:3e3}).data)==null?void 0:Y.active)??!1,J=A({queryKey:b.profiler.sessions({}),queryFn:()=>v.listSessions({limit:100}),refetchInterval:h?2e3:!1}),j=((H=J.data)==null?void 0:H.items)??[],P=A({queryKey:b.profiler.session(t),queryFn:()=>v.getSession(t),enabled:t!=null,refetchInterval:h&&t!=null?2e3:!1}),z=S({mutationFn:()=>v.start(),onSuccess:()=>{s.invalidateQueries({queryKey:b.profiler.status()}),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),U=S({mutationFn:()=>v.stop(),onSuccess:()=>{s.invalidateQueries({queryKey:b.profiler.status()}),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),G=S({mutationFn:d=>v.deleteSession(d),onSuccess:(d,N)=>{t===N&&n(null),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),ae=S({mutationFn:()=>v.clearAll(),onSuccess:()=>{n(null),s.invalidateQueries({queryKey:b.profiler.sessions({})})}}),V=f.useMemo(()=>{const d=x.trim().toLowerCase();return d?j.filter(N=>N.sessionId.toLowerCase().includes(d)):j},[x,j]),c=P.data,E=j.find(d=>d.id===t)??null,W=(c==null?void 0:c.records[u])??null;f.useEffect(()=>{t&&!j.some(d=>d.id===t)&&n(null)},[t,j]),f.useEffect(()=>{p(0),o(0),a("request")},[t]),f.useEffect(()=>{if(!c){p(0),o(0);return}p(d=>Math.min(d,Math.max(c.records.length-1,0))),o(d=>d==null?0:Math.min(d,Math.max(c.records.length-1,0)))},[c]);const re=()=>{c&&je(`profiler-${c.sessionId}.json`,c)};return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",style:{height:"calc(100vh - 64px)"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-white px-6 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(X,{className:"h-5 w-5 text-indigo-500"}),e.jsx("span",{className:"text-base font-semibold text-slate-900",children:"Profiler"}),e.jsxs(se,{variant:"outline",className:m("rounded-full border px-2.5 py-1 text-xs font-semibold",h?"border-red-200 bg-red-50 text-red-600":"border-slate-200 bg-slate-50 text-slate-500"),children:[e.jsx("span",{className:m("mr-2 inline-block h-1.5 w-1.5 rounded-full",h?"bg-red-500":"bg-slate-400")}),h?"Recording":"Not Recording"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{size:"sm",variant:h?"destructive":"default",onClick:()=>h?U.mutate():z.mutate(),disabled:z.isPending||U.isPending,children:h?"Stop Recording":"Start Recording"}),e.jsxs($,{size:"sm",variant:"outline",onClick:re,disabled:!c,children:[e.jsx(ie,{className:"mr-1.5 h-3.5 w-3.5"}),"Export"]}),e.jsxs($,{size:"sm",variant:"outline",onClick:()=>ae.mutate(),disabled:j.length===0,className:"border-red-200 bg-red-50 text-red-700 hover:bg-red-100 hover:text-red-800",children:[e.jsx(Z,{className:"mr-1.5 h-3.5 w-3.5"}),"Clear"]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden bg-[#F1F3F4]",children:[e.jsxs("div",{className:"flex w-80 flex-shrink-0 flex-col border-r border-border bg-white",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-4 py-3",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-900",children:"Sessions"}),e.jsx(se,{variant:"secondary",className:"rounded-full px-2 py-0.5",children:j.length})]}),e.jsxs("div",{className:"flex items-center gap-2 border-b border-border px-3 py-2.5",children:[e.jsx(oe,{className:"h-3.5 w-3.5 text-slate-400"}),e.jsx("input",{className:"w-full bg-transparent text-sm outline-none placeholder:text-slate-400",placeholder:"Search sessions...",value:x,onChange:d=>C(d.target.value)})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:J.isPending?e.jsx(ee,{compact:!0,className:"min-h-[160px]",label:"Loading..."}):V.length===0?e.jsx(M,{compact:!0,className:"m-4 min-h-[160px]",title:h?"Waiting for requests…":"No sessions",description:h?"Requests with session_id will appear here.":"Start recording to capture LLM sessions."}):V.map((d,N)=>e.jsx(Ne,{session:d,selected:t===d.id,index:N,onClick:()=>n(d.id)},d.id))})]}),e.jsx("div",{className:"flex min-w-0 flex-1 flex-col bg-white",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-border bg-white px-5 py-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("span",{className:"h-2.5 w-2.5 flex-shrink-0 rounded-full bg-indigo-500"}),e.jsx("span",{className:"truncate text-sm font-semibold text-slate-900",children:(c==null?void 0:c.sessionId)??(E==null?void 0:E.sessionId)??t}),e.jsx("span",{className:"text-slate-300",children:"·"}),e.jsx("span",{className:"truncate text-sm text-slate-500",children:c?`${c.turnCount} turns · ${R(L(c))} · ${Q((c.totalInputTokens??0)+(c.totalOutputTokens??0))} tokens`:"Loading session…"})]}),e.jsx($,{variant:"ghost",size:"sm",onClick:()=>t&&G.mutate(t),disabled:!t||G.isPending,className:"text-slate-500 hover:text-red-700",children:e.jsx(Z,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"border-b border-border bg-white px-5 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{active:l==="timeline",icon:de,label:"Timeline",onClick:()=>r("timeline")}),e.jsx(te,{active:l==="breakdown",icon:ce,label:"Breakdown",onClick:()=>r("breakdown")})]})}),e.jsx("div",{"data-testid":"profiler-session-content",className:"min-h-0 flex-1 overflow-auto bg-slate-50",children:P.isPending?e.jsx(ee,{compact:!0,className:"min-h-[240px]",label:"Loading session..."}):P.isError?e.jsx(M,{compact:!0,className:"m-5 min-h-[220px]",tone:"danger",title:"Failed to load session"}):c?l==="timeline"?e.jsx(we,{detail:c,selectedTurn:u,detailTab:i,onSelectTurn:p,onDetailTabChange:a}):e.jsx(Me,{detail:c,expandedTurn:y,onToggleTurn:d=>o(N=>N===d?null:d)}):e.jsx(M,{compact:!0,className:"m-5 min-h-[220px]",title:"Session not found"})}),W&&e.jsxs("span",{className:"sr-only",children:["Selected turn ",W.turnIndex+1]})]}):e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(M,{title:"Select a session",description:"Choose a session from the left to inspect its timeline, message payloads, and stats.",icon:e.jsx(X,{className:"h-5 w-5"})})})})]})]})}export{Ee as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as S,j as e,a9 as O,aw as ce,av as A,ao as me,a2 as xe,U as pe,V as ue}from"./vendor-DfnQOGOQ.js";import{L as he}from"./router-BURlSZbt.js";import{C as ge}from"./ConfirmDialog-8iSYQ7NE.js";import{P as fe}from"./PageHeader-DKkO-Kdm.js";import{B as b,d as I,c as E,T as je,e as be,f as ve,g as Ne}from"./index-OvGsIZkZ.js";import{u as K}from"./useAppMutation-C2rsFjm5.js";import{I as T}from"./input-DCNoHAkn.js";import{L as k}from"./label-9kbpUKaR.js";import{S as Q,a as W,b as X,c as J,d as R}from"./select-DS37xdev.js";import{S as ye}from"./switch-DVok_beq.js";import{q as U}from"./queryKeys-BMvyDTQS.js";import{u as P}from"./i18n-dgCQR_PB.js";import{B as w}from"./badge-CkaH3uCO.js";import{C as Y,a as Z}from"./card-Bem3kP2L.js";import{D as we,A as Me,a as ke,b as Ce,c as Ee,d as Pe,e as De}from"./DialogShell-CygWjkEa.js";import{P as Ae,a as Se,b as Te}from"./popover-BGkrY50i.js";import{i as Oe,g as Re,C as Le,O as $e,u as Ve}from"./useModelManagementState-Irif8Gdi.js";import"./query-Db16w3tH.js";import"./radix-D08JKSgz.js";import"./gateway-DrmzHCwu.js";import"./useApiQuery-3ZHohr5l.js";const Be=["anthropic","openai-auto","openai-chat","openai-responses"];function ze({open:d,endpoint:s,onClose:f,onSuccess:o}){const{t:a}=P(),[x,m]=S.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});S.useEffect(()=>{if(s){const n=s.paths&&s.paths.length>0?s.paths:s.path&&s.protocol?[{path:s.path,protocol:s.protocol}]:[{path:"",protocol:"openai-auto"}];m({id:s.id,label:s.label,paths:n,enabled:s.enabled!==!1});return}m({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[s,d]);const r=K({mutationFn:I.create,invalidateKeys:[U.customEndpoints.all()],successToast:()=>({title:a("modelManagement.createEndpointSuccess")}),errorToast:n=>({title:a("modelManagement.createEndpointError",{error:n.message})}),onSuccess:async()=>{o(),f()}}),i=K({mutationFn:n=>I.update(n.id,n.updates),invalidateKeys:[U.customEndpoints.all()],successToast:()=>({title:a("modelManagement.updateEndpointSuccess")}),errorToast:n=>({title:a("modelManagement.updateEndpointError",{error:n.message})}),onSuccess:async()=>{o(),f()}}),c=()=>{m(n=>({...n,paths:[...n.paths,{path:"",protocol:"anthropic"}]}))},v=n=>{x.paths.length!==1&&m(p=>({...p,paths:p.paths.filter((g,M)=>M!==n)}))},N=(n,p,g)=>{m(M=>{const C=[...M.paths];return C[n]={...C[n],[p]:g},{...M,paths:C}})},t=n=>{if(n==null||n.preventDefault(),!x.id.trim()||!x.label.trim())return;for(const g of x.paths)if(!g.path.trim())return;const p=x.paths.map(g=>({path:g.path.trim(),protocol:g.protocol}));if(s){i.mutate({id:s.id,updates:{label:x.label.trim(),paths:p,enabled:x.enabled}});return}r.mutate({id:x.id.trim(),label:x.label.trim(),paths:p,enabled:x.enabled})},h=r.isPending||i.isPending,l=x.paths.length===0?a("modelManagement.atLeastOnePath"):!x.id.trim()||!x.label.trim()?a("modelManagement.endpointValidationError"):x.paths.some(n=>!n.path.trim())?a("modelManagement.pathValidationError"):null;return d?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:f}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-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:a(s?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s?s.id:a("modelManagement.endpointRoutingHint")})]}),e.jsx(b,{variant:"ghost",size:"sm",onClick:f,children:e.jsx(O,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:t,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:a("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(s==null?void 0:s.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:a("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:x.enabled?a("common.status.enabled"):a("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{children:[a("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T,{value:x.id,onChange:n=>m(p=>({...p,id:n.target.value})),placeholder:a("modelManagement.endpointIdPlaceholder"),disabled:!!s,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{children:[a("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T,{value:x.label,onChange:n=>m(p=>({...p,label:n.target.value})),placeholder:a("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(k,{children:[a("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(b,{type:"button",variant:"ghost",size:"sm",onClick:c,children:[e.jsx(ce,{className:"mr-1 h-3 w-3"}),a("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:x.paths.map((n,p)=>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(T,{value:n.path,onChange:g=>N(p,"path",g.target.value),placeholder:a("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(Q,{value:n.protocol,onValueChange:g=>N(p,"protocol",g),children:[e.jsx(W,{children:e.jsx(X,{})}),e.jsx(J,{children:Be.map(g=>e.jsx(R,{value:g,children:a(g==="anthropic"?"modelManagement.protocolAnthropic":g==="openai-auto"?"modelManagement.protocolOpenAI":g==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},g))})]})]}),x.paths.length>1?e.jsx(b,{type:"button",variant:"ghost",size:"sm",onClick:()=>v(p),className:"text-destructive",children:e.jsx(O,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[p===0?e.jsx("p",{children:a("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:a(`modelManagement.protocolHints.${n.protocol}`)})]})]},`${n.protocol}-${p}`))}),l?e.jsx("p",{className:"text-xs text-destructive",children:l}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ye,{id:"enabled",checked:x.enabled,onCheckedChange:n=>m(p=>({...p,enabled:n}))}),e.jsx(k,{htmlFor:"enabled",children:a("modelManagement.endpointEnabled")})]}),s?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:a("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border bg-secondary p-6",children:[e.jsx(b,{variant:"outline",className:"flex-1",onClick:f,disabled:h,children:a("common.cancel")}),e.jsx(b,{className:"flex-1",onClick:()=>t(),disabled:h,children:a(h?"common.saving":s?"common.save":"common.create")})]})]})})]}):null}function H(d,s){return s(d==="anthropic"?"modelManagement.protocolAnthropic":d==="openai-chat"?"modelManagement.protocolOpenAIChat":d==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function He({activeTab:d,customEndpoints:s,customTabs:f,isDirtyByEndpoint:o,onDeleteEndpoint:a,onEditEndpoint:x,onSelectTab:m,systemTabs:r}){const{t:i}=P();return e.jsx(Y,{className:"overflow-hidden",children:e.jsxs(Z,{className:"space-y-4 pt-5",children:[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:i("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:r.map(c=>{const v=d===c.key,N=c.key!=="providers"&&o[c.key];return e.jsxs("button",{type:"button",onClick:()=>m(c.key),className:E("group flex min-h-[96px] flex-col justify-between rounded-lg border px-4 py-4 text-left transition-all",v?"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:E("text-base font-semibold",v?"text-primary":"text-foreground"),children:c.label}),e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-muted-foreground",children:c.key==="providers"?i("modelManagement.overview.providerPoolTag"):i("modelManagement.overview.systemEndpointTag")})]}),N?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:c.description})]},c.key)})})]}),f.length>0?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:i("modelManagement.overview.customEndpoints")}),e.jsx("div",{className:"overflow-x-auto pb-1",children:e.jsx("div",{className:"flex min-w-full snap-x gap-3",children:f.map(c=>{var h;const v=d===c.key,N=o[c.key],t=s.find(l=>l.id===c.key);return e.jsxs("div",{className:E("group relative flex w-[260px] shrink-0 snap-start flex-col gap-3 rounded-lg border px-4 py-4 text-left transition-all",v?"border-primary/30 bg-accent":"border-border bg-card hover:border-primary/20 hover:bg-accent/50"),children:[e.jsxs("button",{type:"button",onClick:()=>m(c.key),className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:E("truncate text-base font-semibold",v?"text-primary":"text-foreground"),children:c.label}),N?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:c.description})]}),e.jsxs("div",{className:"grid gap-2 sm:flex sm:items-start",children:[e.jsx(b,{variant:"ghost",size:"sm",className:"h-7 w-full px-2 text-xs sm:w-auto",disabled:!t,onClick:()=>{t&&x(t)},children:i("common.edit")}),c.canDelete?e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),t&&a({kind:"endpoint",endpoint:t})},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:i("common.delete"),children:e.jsx(O,{className:"h-3.5 w-3.5"})}):null]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(c.protocols??[]).map(l=>e.jsx(w,{variant:"outline",className:"max-w-full truncate text-[11px]",children:H(l,i)},`${c.key}-${l}`)),e.jsx(w,{variant:(t==null?void 0:t.enabled)===!1?"secondary":"success",className:"text-[11px]",children:(t==null?void 0:t.enabled)===!1?i("modelManagement.overview.endpointDisabled"):i("modelManagement.overview.endpointEnabled")})]}),t!=null&&t.paths&&t.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:[t.paths.slice(0,2).map(l=>e.jsxs("div",{className:"truncate",children:[e.jsx("span",{className:"font-medium text-foreground",children:l.path})," · ",H(l.protocol,i)]},`${t.id}-${l.path}-${l.protocol}`)),t.paths.length>2?e.jsx("div",{children:i("modelManagement.overview.endpointMorePaths",{count:t.paths.length-2})}):null]}):t!=null&&t.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:t.path})," · ",H(t.protocol??"anthropic",i)]}):null,e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-3 py-2 text-[11px] text-muted-foreground",children:(h=c.protocols)!=null&&h.length?i("modelManagement.overview.endpointProtocols",{count:c.protocols.length}):i("modelManagement.overview.endpointNoProtocol")}),c.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground",children:i("modelManagement.overview.endpointManagedExternally")})]},c.key)})})})]}):null]})})}function _e({dialog:d,currentRoutes:s,onConfirm:f,onClose:o}){const{t:a}=P();if(!d)return null;const{endpoint:x,preset:m}=d,r=m.modelRoutes??{},i={};for(const l of s){const n=l.source.trim(),p=l.target.trim();n&&p&&(i[n]=p)}const c=new Set([...Object.keys(i),...Object.keys(r)]),v=[],N=[],t=[];for(const l of c){const n=l in i,p=l in r;p&&!n?v.push([l,r[l]]):n&&!p?N.push([l,i[l]]):n&&p&&i[l]!==r[l]&&t.push([l,i[l],r[l]])}const h=v.length>0||N.length>0||t.length>0;return e.jsx(we,{open:!0,onOpenChange:l=>!l&&o(),children:e.jsxs(Me,{className:"max-w-2xl",children:[e.jsxs(ke,{children:[e.jsx(Ce,{children:a("modelManagement.presets.diffTitle")}),e.jsx(Ee,{children:a("modelManagement.presets.diffDescription",{name:m.name})})]}),e.jsx(Pe,{children:h?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-lg border border-border bg-secondary p-3 text-sm",children:[v.map(([l,n])=>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(w,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:a("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(A,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:n})]},`add-${l}`)),N.map(([l,n])=>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(w,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:a("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(A,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:n})]},`rm-${l}`)),t.map(([l,n,p])=>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(w,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:a("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:l}),e.jsx(A,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:n}),e.jsx(A,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:p})]},`chg-${l}`))]}):e.jsx("p",{className:"rounded-lg border border-border bg-secondary py-8 text-center text-sm text-muted-foreground",children:a("modelManagement.presets.diffEmpty")})}),e.jsxs(De,{children:[e.jsx(b,{variant:"outline",onClick:o,children:a("common.cancel")}),e.jsx(b,{onClick:()=>f(x,m),disabled:!h,children:a("modelManagement.presets.diffConfirm")})]})]})})}function Fe({value:d,onChange:s,options:f,disabled:o,placeholder:a}){const{t:x}=P(),[m,r]=S.useState(!1),[i,c]=S.useState(""),v=S.useMemo(()=>{if(!i.trim())return f;const t=i.toLowerCase();return f.filter(h=>h.label.toLowerCase().includes(t)||h.value.toLowerCase().includes(t))},[f,i]),N=t=>{s(t),c(""),r(!1)};return e.jsxs(Ae,{open:m,onOpenChange:t=>{r(t),t&&c("")},children:[e.jsx(Se,{asChild:!0,children:e.jsx(T,{value:d,onChange:t=>{s(t.target.value),c(t.target.value),m||r(!0)},onFocus:()=>{c(""),r(!0)},onClick:()=>{m||r(!0)},placeholder:a,disabled:o,autoComplete:"off"})}),e.jsx(Te,{className:"max-h-60 w-[var(--radix-popover-trigger-width)] overflow-y-auto p-1",align:"start",onOpenAutoFocus:t=>t.preventDefault(),children:v.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:x("common.noMatches")}):v.map(t=>e.jsx("button",{type:"button",className:E("flex w-full items-center rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent",t.value===d.trim()&&"bg-accent"),onMouseDown:h=>{h.preventDefault(),N(t.value)},children:e.jsx("span",{className:"truncate",children:t.label})},t.value))})]})}function qe({endpoint:d,tabs:s,customEndpoints:f,config:o,routes:a,routeError:x,savingRoute:m,isDirty:r,presets:i,presetName:c,presetError:v,savingPreset:N,applyingPreset:t,deletingPreset:h,presetsExpanded:l,savingClaudeValidation:n,providerModelOptions:p,onTogglePresetsExpanded:g,onPresetNameChange:M,onSavePreset:C,onRequestPresetDiff:ee,onRequestDeletePreset:se,onValidationModeChange:te,onRouteChange:_,onRemoveRoute:F,onAddSuggestion:ae,onAddRoute:ne,onResetRoutes:re,onSaveRoutes:le}){var G;const{t:u}=P(),y=s.find(j=>j.key===d),L=((G=y==null?void 0:y.protocols)==null?void 0:G.includes("anthropic"))??d==="anthropic"?Le:$e,oe=(y==null?void 0:y.label)??d;(y==null?void 0:y.isSystem)===!1?y.description:u(`settings.routing.descriptionByEndpoint.${d}`);const $=`route-source-${d}`,q=Oe(d,f),V=Re(d,o,f),B=q?(V==null?void 0:V.mode)??"off":"off",de=new Set(a.map(j=>j.source.trim()).filter(Boolean)),ie=`modelManagement.claudeValidation.options.${B}.description`;return e.jsx(Y,{children:e.jsxs(Z,{className:"space-y-6 pt-6",children:[e.jsx("div",{className:"rounded-lg border border-border bg-secondary px-4 py-3 text-xs text-muted-foreground",children:u("settings.routing.wildcardHint")}),q?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:u("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"text-xs text-primary/80",children:u("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2 self-start sm:self-auto",children:[e.jsx(k,{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/70",children:u("modelManagement.claudeValidation.modeLabel")}),e.jsxs(Q,{value:B,onValueChange:j=>te(j),disabled:n,children:[e.jsx(W,{className:"bg-card",children:e.jsx(X,{})}),e.jsxs(J,{children:[e.jsx(R,{value:"off",children:u("modelManagement.claudeValidation.options.off.label")}),e.jsx(R,{value:"anthropic-strict",children:u("modelManagement.claudeValidation.options.anthropic-strict.label")}),e.jsx(R,{value:"claude-code",children:u("modelManagement.claudeValidation.options.claude-code.label")})]})]}),e.jsx("span",{className:E("text-xs",B==="off"?"text-muted-foreground":"text-primary/80"),children:u(ie)})]})]})}):null,x?e.jsx("p",{className:"text-sm text-destructive",children:x}):null,e.jsx(Ge,{presets:i,presetName:c,presetError:v,savingPreset:N,applyingPreset:t,deletingPreset:h,expanded:l,onToggleExpanded:g,onPresetNameChange:M,onSavePreset:C,onRequestPresetDiff:ee,onRequestDeletePreset:se}),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(k,{className:"text-sm font-semibold text-foreground",children:u("modelManagement.routesEditorTitle")}),e.jsxs(w,{variant:"outline",children:[a.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:u("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:[oe," workspace"]})]}),a.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:u("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:u("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:u("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:u("settings.routing.target")}),e.jsx("span",{})]}),a.map((j,D)=>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(w,{variant:"outline",className:"text-[11px]",children:["#",D+1]}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>F(j.id),disabled:m,children:e.jsx(O,{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(k,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:u("settings.routing.source")}),e.jsx(T,{value:j.source,onChange:z=>_(j.id,"source",z.target.value),placeholder:u("settings.routing.sourcePlaceholder"),list:$,disabled:m,"aria-label":`route-source-${D+1}`})]}),e.jsx(A,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(k,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:u("settings.routing.target")}),e.jsx(Fe,{value:j.target,onChange:z=>_(j.id,"target",z),options:p,disabled:m,placeholder:u("settings.routing.targetPlaceholder")})]}),e.jsx(b,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>F(j.id),disabled:m,children:e.jsx(O,{className:"h-4 w-4"})})]})]},j.id))]})]}),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:u("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u(r?"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(b,{variant:"outline",size:"sm",onClick:ne,disabled:m,className:"w-full",children:u("settings.routing.add")}),e.jsx(b,{variant:"outline",size:"sm",onClick:re,disabled:m||!r,className:"w-full",children:u("common.actions.reset")}),e.jsxs(b,{size:"sm",onClick:le,disabled:m,className:"relative w-full",children:[u(m?"common.actions.saving":"modelManagement.actions.saveRoutes"),r?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-border/70 bg-secondary/55 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(k,{className:"text-sm font-medium text-foreground",children:u("settings.routing.suggested")}),e.jsx(w,{variant:"outline",className:"text-[11px]",children:L.length})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:u("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:L.map(j=>{const D=de.has(j);return e.jsx(b,{variant:D?"ghost":"outline",size:"sm",onClick:()=>ae(j),disabled:m||D,className:E("h-7 rounded-md px-2.5 text-[11px] font-normal",D?"opacity-45":"bg-background/70"),children:j},`${d}-${j}`)})})]}),e.jsx("datalist",{id:$,children:L.map(j=>e.jsx("option",{value:j},`${$}-${j}`))})]})})}function Ge({presets:d,presetName:s,presetError:f,savingPreset:o,applyingPreset:a,deletingPreset:x,expanded:m,onToggleExpanded:r,onPresetNameChange:i,onSavePreset:c,onRequestPresetDiff:v,onRequestDeletePreset:N}){const{t}=P();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:r,children:e.jsxs("div",{className:"flex items-center gap-2",children:[m?e.jsx(me,{className:"h-4 w-4"}):e.jsx(xe,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:t("modelManagement.presets.title")}),e.jsx(w,{variant:"secondary",className:"text-xs",children:d.length})]})}),m?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:t("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(T,{value:s,onChange:h=>i(h.target.value),placeholder:t("modelManagement.presets.namePlaceholder"),disabled:o,className:"w-full md:w-48"}),e.jsx(b,{onClick:c,disabled:o,className:"w-full md:w-auto",children:t(o?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),f?e.jsx("p",{className:"text-sm text-destructive",children:f}):null,d.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:t("modelManagement.presets.empty")}):e.jsx(je,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:d.map(h=>{const l=a===h.name,n=x===h.name,p=Object.entries(h.modelRoutes??{}),g=p.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(be,{children:[e.jsx(ve,{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:h.name}),e.jsx(w,{variant:"outline",className:"mt-1 text-xs",children:g>0?t("modelManagement.presets.rulesCount",{count:g}):t("modelManagement.presets.noRules")})]})}),g>0?e.jsx(Ne,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[p.slice(0,5).map(([M,C])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:M}),e.jsx(A,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:C})]},M)),g>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",g-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(b,{size:"sm",onClick:()=>v(h),disabled:l||n,className:"w-full sm:w-auto",children:t(l?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(b,{variant:"destructive",size:"sm",onClick:()=>N(h),disabled:n||l,className:"w-full sm:w-auto",children:t(n?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},h.name)})})})]}):null]})}function ps(){var x,m;const{t:d}=P(),s=Ve(),f=s.systemTabs.filter(r=>r.key!=="providers"),o=s.activeTab==="providers"?"anthropic":s.activeTab,a=s.tabs.find(r=>r.key===o)??null;return S.useEffect(()=>{s.activeTab==="providers"&&s.setActiveTab("anthropic")},[s.activeTab,s.setActiveTab]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(fe,{icon:e.jsx(ue,{className:"h-5 w-5","aria-hidden":"true"}),title:d("routingManagement.title"),description:d("routingManagement.description"),eyebrow:d("routingManagement.eyebrow"),breadcrumb:"Gateway / Routing",badge:(a==null?void 0:a.label)??o,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.jsx(b,{asChild:!0,variant:"outline",className:"w-full sm:w-auto",children:e.jsxs(he,{to:"/models",children:[e.jsx(pe,{className:"h-4 w-4","aria-hidden":"true"}),d("nav.models")]})}),e.jsx(b,{onClick:s.handleOpenCreateEndpoint,className:"w-full sm:w-auto",children:d("modelManagement.addEndpoint")})]})}),e.jsx(He,{activeTab:o,customEndpoints:s.customEndpoints,customTabs:s.customTabs,isDirtyByEndpoint:s.isDirtyByEndpoint,onDeleteEndpoint:s.setConfirmAction,onEditEndpoint:s.handleOpenEditEndpoint,onSelectTab:s.setActiveTab,systemTabs:f}),e.jsx(qe,{endpoint:o,applyingPreset:((x=s.applyingPreset)==null?void 0:x.endpoint)===o?s.applyingPreset.name:null,config:s.config,customEndpoints:s.customEndpoints,deletingPreset:((m=s.deletingPreset)==null?void 0:m.endpoint)===o?s.deletingPreset.name:null,isDirty:s.isDirtyByEndpoint[o]??!1,onAddRoute:()=>s.handleAddRoute(o),onAddSuggestion:r=>s.handleAddSuggestion(o,r),onPresetNameChange:r=>s.handlePresetNameChange(o,r),onRequestDeletePreset:r=>s.setConfirmAction({kind:"preset",endpoint:o,preset:r}),onRequestPresetDiff:r=>s.setPresetDiffDialog({endpoint:o,preset:r}),onRemoveRoute:r=>s.handleRemoveRoute(o,r),onResetRoutes:()=>s.handleResetRoutes(o),onRouteChange:(r,i,c)=>s.handleRouteChange(o,r,i,c),onSavePreset:()=>void s.handleSavePreset(o),onSaveRoutes:()=>void s.handleSaveRoutes(o),onValidationModeChange:r=>void s.handleValidationModeChange(o,r),onTogglePresetsExpanded:()=>s.setPresetsExpanded(r=>({...r,[o]:!r[o]})),presetError:s.presetErrorByEndpoint[o],presetName:s.presetNameByEndpoint[o]??"",presets:s.presetsByEndpoint[o]??[],presetsExpanded:s.presetsExpanded[o]===!0,providerModelOptions:s.providerModelOptions,routeError:s.routeError[o],routes:s.routesByEndpoint[o]||[],savingClaudeValidation:s.savingClaudeValidation,savingPreset:s.savingPresetFor===o,savingRoute:s.savingRouteFor===o,tabs:s.tabs.filter(r=>r.key!=="providers")}),e.jsx(ze,{open:s.endpointDrawerOpen,endpoint:s.editingEndpoint,onClose:()=>{s.setEndpointDrawerOpen(!1),s.setEditingEndpoint(void 0)},onSuccess:()=>{s.configQuery.refetch()}}),e.jsx(_e,{dialog:s.presetDiffDialog,currentRoutes:s.presetDiffDialog?s.routesByEndpoint[s.presetDiffDialog.endpoint]||[]:[],onConfirm:(r,i)=>{s.setPresetDiffDialog(null),s.handleApplyPreset(r,i)},onClose:()=>s.setPresetDiffDialog(null)}),e.jsx(ge,{open:!!s.confirmAction,onOpenChange:r=>{!r&&!s.confirmingAction&&s.setConfirmAction(null)},title:s.confirmDialogTitle,description:s.confirmDialogDescription,confirmLabel:s.confirmingAction?d("common.actions.loading"):d("common.delete"),cancelLabel:d("common.actions.cancel"),loading:s.confirmingAction,onConfirm:s.handleConfirmDialog,children:s.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:s.confirmDialogName}):null})]})}export{ps as default};
|