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