@chenpu17/cc-gw 0.8.18 → 0.8.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/package.json +5 -5
  2. package/src/web/dist/assets/{About-eUM4Yunu.js → About-E813AXIS.js} +1 -1
  3. package/src/web/dist/assets/{ApiKeys-Btsn7hGM.js → ApiKeys-CHoWjny5.js} +1 -1
  4. package/src/web/dist/assets/{ConfirmDialog-Gz0TZO4h.js → ConfirmDialog-BuV2d3aQ.js} +1 -1
  5. package/src/web/dist/assets/{Dashboard-fqsy4ACs.js → Dashboard-B0KXfDqB.js} +1 -1
  6. package/src/web/dist/assets/{DialogShell-BTPrPt5l.js → DialogShell-Dciv2SOq.js} +1 -1
  7. package/src/web/dist/assets/{Events-CFoh5-D7.js → Events-CQ47M36I.js} +1 -1
  8. package/src/web/dist/assets/{Help-CVtNNMfH.js → Help-DlkNELd-.js} +1 -1
  9. package/src/web/dist/assets/{Login-BPgP3ttc.js → Login-Cnx2XHdt.js} +1 -1
  10. package/src/web/dist/assets/Logs-MHwalvMS.js +1 -0
  11. package/src/web/dist/assets/{ModelManagement-Cy_vY5A5.js → ModelManagement-DBUODkXB.js} +1 -1
  12. package/src/web/dist/assets/{PageSection-uD1ZrEC_.js → PageSection-D4IIQeYC.js} +1 -1
  13. package/src/web/dist/assets/{PageState-Cq7xpTfp.js → PageState-C9j-dOzv.js} +1 -1
  14. package/src/web/dist/assets/{PageToolbar-BBTEUrko.js → PageToolbar-CDzxx36L.js} +1 -1
  15. package/src/web/dist/assets/{Profiler-C4MYIrXV.js → Profiler-C-LEcskT.js} +1 -1
  16. package/src/web/dist/assets/RoutingManagement-CUzrRFdV.js +1 -0
  17. package/src/web/dist/assets/{Settings-CITbVmtl.js → Settings-kC8ItAD8.js} +1 -1
  18. package/src/web/dist/assets/{Skeleton-DEhFppby.js → Skeleton-C54borRX.js} +1 -1
  19. package/src/web/dist/assets/{app-BBdow7GJ.js → app-BF0X4ljN.js} +4 -4
  20. package/src/web/dist/assets/{card-Do7RepdY.js → card-D-kPX9ag.js} +1 -1
  21. package/src/web/dist/assets/{gateway-g4snI3mT.js → gateway-Bo9FVYfn.js} +1 -1
  22. package/src/web/dist/assets/{global-DWbUmocj.css → global-Dcdq4qY7.css} +1 -1
  23. package/src/web/dist/assets/{input-E9i52oYD.js → input-k8bXT6Gd.js} +1 -1
  24. package/src/web/dist/assets/{label-ClDL__fF.js → label-DDQd-HKi.js} +1 -1
  25. package/src/web/dist/assets/{landing-DYbMaEZw.js → landing-D5PpgO3n.js} +1 -1
  26. package/src/web/dist/assets/package-BeIzyZKv.js +1 -0
  27. package/src/web/dist/assets/popover-D4mE0Sqd.js +1 -0
  28. package/src/web/dist/assets/{queryKeys-BiuXKawV.js → queryKeys-0HDa7byL.js} +1 -1
  29. package/src/web/dist/assets/{select-CohvZ6L7.js → select-CrEhP63g.js} +1 -1
  30. package/src/web/dist/assets/{switch-CwlkqLey.js → switch-DfFXX_ey.js} +1 -1
  31. package/src/web/dist/assets/{table-CnAkbq3u.js → table-Dft0HY_N.js} +1 -1
  32. package/src/web/dist/assets/{useApiQuery-nMqbFkID.js → useApiQuery-DaxeBDln.js} +1 -1
  33. package/src/web/dist/assets/{useAppMutation-D2xDZiR6.js → useAppMutation-C8scr-Sv.js} +1 -1
  34. package/src/web/dist/assets/{useModelManagementState-Zwu7DIdu.js → useModelManagementState-B3Ht0eWY.js} +1 -1
  35. package/src/web/dist/assets/utils-RIyUChKi.js +1 -0
  36. package/src/web/dist/index.html +3 -3
  37. package/src/web/dist/landing.html +4 -4
  38. package/src/web/dist/assets/Logs-facmq1-X.js +0 -1
  39. package/src/web/dist/assets/RoutingManagement-B7apqRxw.js +0 -1
  40. package/src/web/dist/assets/package-BMoxvLUB.js +0 -1
  41. package/src/web/dist/assets/popover-CLCOu-wx.js +0 -1
  42. package/src/web/dist/assets/utils-DSaa7c6v.js +0 -1
  43. /package/src/web/dist/assets/{global-CaQPIFGa.js → global-CsDL9Nt2.js} +0 -0
@@ -1 +1 @@
1
- import{r as m}from"./vendor-DdPBfMMb.js";import{u as Nt,a as Ut}from"./query-QCek5MsK.js";import{g as K,b as H,u as Vt,t as G,c as ie}from"./app-BBdow7GJ.js";import{g as I}from"./gateway-g4snI3mT.js";import{q as U}from"./queryKeys-BiuXKawV.js";import{u as Ie}from"./useAppMutation-D2xDZiR6.js";import{u as Qt}from"./useApiQuery-nMqbFkID.js";import{u as zt}from"./i18n-C8tBby0x.js";const _={savePreset(n,i){return K(H.post(`/api/routing-presets/${n}`,{name:i}))},applyPreset(n,i){return K(H.post(`/api/routing-presets/${n}/apply`,{name:i}))},deletePreset(n,i){return K(H.delete(`/api/routing-presets/${n}/${encodeURIComponent(i)}`))},testProvider(n,i){return K(H.post(`/api/providers/${n}/test`,i??{}))}},tn=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],nn=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function O(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function J(n,i){var p;return(p=n==null?void 0:n.customEndpoints)!=null&&p.length?n.customEndpoints:i}function le(n){return n?Object.entries(n).map(([i,p])=>({id:O(),source:i,target:p})):[]}function ue(n,i){var v,f,g;if(!n)return{};const p={},d=n.endpointRouting??{};p.anthropic=le(((v=d.anthropic)==null?void 0:v.modelRoutes)??n.modelRoutes??{}),p.openai=le(((f=d.openai)==null?void 0:f.modelRoutes)??{});for(const y of J(n,i))(g=y.routing)!=null&&g.modelRoutes?p[y.id]=le(y.routing.modelRoutes):p[y.id]=[];return p}function Fe(n,i,p){var f,g,y;const d=J(n,i).find(F=>F.id===p);if(d)return((f=d.routing)==null?void 0:f.modelRoutes)??{};const v=n.endpointRouting??{};return p==="anthropic"?((g=v.anthropic)==null?void 0:g.modelRoutes)??n.modelRoutes??{}:p==="openai"?((y=v.openai)==null?void 0:y.modelRoutes)??{}:{}}function At(n){const i={};for(const p of n){const d=p.source.trim(),v=p.target.trim();d&&v&&(i[d]=v)}return i}function Le(n,i){return JSON.stringify(At(n))!==JSON.stringify(i)}function on(n,i){if(n==="anthropic")return!0;const p=i.find(d=>d.id===n);return p?p.paths&&p.paths.length>0?p.paths.some(d=>d.protocol==="anthropic"):p.protocol==="anthropic":!1}function sn(n,i,p){var v,f,g;if(!i)return;if(n==="anthropic"||n==="openai")return(f=(v=i.endpointRouting)==null?void 0:v[n])==null?void 0:f.validation;const d=J(i,p).find(y=>y.id===n);return(g=d==null?void 0:d.routing)==null?void 0:g.validation}function an(n,i,p){var v,f,g;if(!i)return;if(n==="anthropic"||n==="openai")return(f=(v=i.endpointRouting)==null?void 0:v[n])==null?void 0:f.compatibility;const d=J(i,p).find(y=>y.id===n);return(g=d==null?void 0:d.routing)==null?void 0:g.compatibility}function Kt(n,i){const p=[{key:"providers",label:n("modelManagement.tabs.providers"),description:n("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:n("modelManagement.tabs.anthropic"),description:n("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:n("modelManagement.tabs.openai"),description:n("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],d=i.map(v=>{let f=n("modelManagement.tabs.customEndpoint"),g=[];if(v.paths&&v.paths.length>0)f=`${n("modelManagement.tabs.customEndpoint")}: ${v.paths.map(y=>`${y.path} (${y.protocol})`).join(", ")}`,g=[...new Set(v.paths.map(y=>y.protocol))];else if(v.path){const y=v.protocol||"anthropic";f=`${n("modelManagement.tabs.customEndpoint")}: ${v.path} (${y})`,g=[y]}return{key:v.id,label:v.label||v.id,description:f,isSystem:!1,canDelete:v.deletable!==!1,protocols:g}});return[...p,...d]}function Ht(n){return n.label&&n.label.trim().length>0?`${n.label} (${n.id})`:n.id}function je(n,i){var d,v,f;const p={anthropic:((d=n.routingPresets)==null?void 0:d.anthropic)??[],openai:((v=n.routingPresets)==null?void 0:v.openai)??[]};for(const g of i){const y=(f=n.customEndpoints)==null?void 0:f.find(F=>F.id===g.id);p[g.id]=(y==null?void 0:y.routingPresets)??g.routingPresets??[]}return p}function rn(){var Te;const{t:n}=zt(),{pushToast:i}=Vt(),p=Nt(),d=Qt(U.config.full(),I.configRequest()),f=((Te=Ut({queryKey:U.customEndpoints.all(),queryFn:ie.list,refetchInterval:1e4}).data)==null?void 0:Te.endpoints)??[],g=m.useMemo(()=>Kt(n,f),[f,n]),[y,F]=m.useState("providers"),[l,k]=m.useState(null),[Be,W]=m.useState(!1),[X,Y]=m.useState("create"),[V,Z]=m.useState(void 0),[qe,ee]=m.useState(void 0),[Ne,de]=m.useState(null),[Ue,te]=m.useState(!1),[L,D]=m.useState({}),[Ve,T]=m.useState({}),[Qe,ce]=m.useState(null),[me,ne]=m.useState({}),[pe,fe]=m.useState({}),[ze,Q]=m.useState({}),[Ae,ge]=m.useState(null),[Ke,he]=m.useState(null),[He,ve]=m.useState(null),[Ge,ye]=m.useState(!1),[oe,Ee]=m.useState(null),[se,ae]=m.useState(!0),[be,Re]=m.useState({}),[_e,Se]=m.useState(null),[Je,Me]=m.useState(!1),[We,we]=m.useState(!1),[Xe,Ye]=m.useState({}),[Ze,et]=m.useState(null),[c,Ce]=m.useState(null),[tt,Pe]=m.useState(!1),[re,nt]=m.useState(""),[z,ot]=m.useState("all"),st=m.useMemo(()=>g.filter(e=>e.isSystem),[g]),at=m.useMemo(()=>g.filter(e=>!e.isSystem),[g]),rt=m.useMemo(()=>g.find(e=>e.key===y)??g[0]??null,[y,g]),x=(l==null?void 0:l.providers)??[],it=x.length,lt=m.useMemo(()=>x.filter(e=>{var a;if(!(z==="all"||(e.type??"custom")===z))return!1;const t=re.trim().toLowerCase();return t?[e.id,e.label??"",e.baseUrl,e.defaultModel??"",...((a=e.models)==null?void 0:a.map(r=>r.id))??[]].join(" ").toLowerCase().includes(t):!0}),[re,z,x]),N=m.useMemo(()=>[{key:"anthropic-beta",value:"claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",label:n("providers.testDialog.options.beta.label"),description:n("providers.testDialog.options.beta.description")}],[n]);m.useEffect(()=>{if(!d.data)return;const e=d.data;k(e),D(s=>{const t=ue(e,f);if(!s||Object.keys(s).length===0)return t;const o={...t};for(const[a,r]of Object.entries(s)){if(!(a in t))continue;const u=Fe(e,f,a);Le(r,u)&&(o[a]=r)}return o}),T({}),ne(je(e,f))},[d.data,f]),m.useEffect(()=>{!d.isError||!d.error||i({title:n("providers.toast.loadFailure",{message:d.error.message}),variant:"error"})},[d.error,d.isError,i,n]),m.useEffect(()=>{g.some(e=>e.key===y)||F("providers")},[y,g]);const ut=m.useMemo(()=>{const e=new Map;for(const s of x){if(!s.defaultModel||!s.models)continue;const t=s.models.find(o=>o.id===s.defaultModel);t&&e.set(s.id,Ht(t))}return e},[x]),dt=m.useMemo(()=>{const e=[],s=new Set;for(const t of x){const o=t.label&&t.label!==t.id?`${t.label} (${t.id})`:t.id,a=t.models??[];if(a.length>0)for(const u of a){const h=`${t.id}:${u.id}`;s.has(h)||(s.add(h),e.push({value:h,label:`${o} · ${u.label??u.id}`,providerId:t.id,providerLabel:o,modelId:u.id,modelLabel:u.label??u.id,kind:"model",isDefault:t.defaultModel===u.id}))}else if(t.defaultModel){const u=`${t.id}:${t.defaultModel}`;s.has(u)||(s.add(u),e.push({value:u,label:`${o} · ${t.defaultModel}`,providerId:t.id,providerLabel:o,modelId:t.defaultModel,modelLabel:t.defaultModel,kind:"model",isDefault:!0}))}const r=`${t.id}:*`;s.has(r)||(s.add(r),e.push({value:r,label:n("settings.routing.providerPassthroughOption",{provider:o}),providerId:t.id,providerLabel:o,modelId:"*",modelLabel:"*",kind:"passthrough"}))}for(const t of Object.values(L).flat()){const o=t.target.trim();o&&!s.has(o)&&(s.add(o),e.push({value:o,label:o,modelId:o,modelLabel:o,kind:"custom"}))}return e},[x,L,n]),ct=()=>{ee(void 0),te(!0)},mt=e=>{ee(e),te(!0)},pt=e=>l?Fe(l,f,e):{},ft=m.useMemo(()=>{const e={};for(const s of g){if(s.key==="providers")continue;const t=L[s.key]||[];e[s.key]=Le(t,pt(s.key))}return e},[l,f,L,g]),ke=(e,s)=>{ne(t=>({...t,[e]:s})),k(t=>{if(!t)return t;if(e==="anthropic"||e==="openai")return{...t,routingPresets:{...t.routingPresets,[e]:s}};const o=[...t.customEndpoints??[]],a=o.findIndex(r=>r.id===e);return a===-1?t:(o[a]={...o[a],routingPresets:s},{...t,customEndpoints:o})})},$=()=>l?!0:(i({title:n("settings.toast.missingConfig"),variant:"error"}),d.refetch(),!1),gt=(e,s)=>{fe(t=>({...t,[e]:s})),s.trim()&&Q(t=>({...t,[e]:null}))},ht=async e=>{if(!$())return;const s=(pe[e]??"").trim();if(!s){Q(t=>({...t,[e]:n("modelManagement.validation.presetName")}));return}if((me[e]??[]).some(t=>t.name.toLowerCase()===s.toLowerCase())){Q(t=>({...t,[e]:n("modelManagement.validation.presetDuplicate",{name:s})}));return}ge(e);try{const o=(await _.savePreset(e,s)).presets??[];ke(e,o),fe(a=>({...a,[e]:""})),Q(a=>({...a,[e]:null})),i({title:n("modelManagement.toast.presetSaved",{name:s}),variant:"success"})}catch(t){i({title:n("modelManagement.toast.presetSaveFailure",{message:t instanceof Error?t.message:"unknown"}),variant:"error"})}finally{ge(null),d.refetch()}},vt=async(e,s)=>{if($()){he({endpoint:e,name:s.name});try{const o=(await _.applyPreset(e,s.name)).config;if(o)k(o),D(ue(o,f)),ne(je(o,f));else{const a=s.modelRoutes??{};D(r=>({...r,[e]:Object.entries(a).map(([u,h])=>({id:O(),source:u,target:h}))})),k(r=>{var h,E,R,S;if(!r)return r;const u=(r.customEndpoints??[]).findIndex(b=>b.id===e);if(u!==-1){const b=[...r.customEndpoints??[]],M=b[u];return b[u]={...M,routing:{defaults:((h=M.routing)==null?void 0:h.defaults)??r.defaults,...M.routing??{},modelRoutes:a}},{...r,customEndpoints:b}}return e==="anthropic"||e==="openai"?{...r,endpointRouting:{...r.endpointRouting??{},[e]:{defaults:((R=(E=r.endpointRouting)==null?void 0:E[e])==null?void 0:R.defaults)??r.defaults,...((S=r.endpointRouting)==null?void 0:S[e])??{},modelRoutes:a}},modelRoutes:e==="anthropic"?a:r.modelRoutes??{}}:r})}e!=="anthropic"&&e!=="openai"&&await p.invalidateQueries({queryKey:U.customEndpoints.all()}),i({title:n("modelManagement.toast.presetApplySuccess",{name:s.name}),variant:"success"})}catch(t){i({title:n("modelManagement.toast.presetApplyFailure",{message:t instanceof Error?t.message:"unknown"}),variant:"error"})}finally{he(null),d.refetch()}}},yt=async(e,s)=>{if($()){ve({endpoint:e,name:s.name});try{const t=await _.deletePreset(e,s.name);ke(e,t.presets??[]),i({title:n("modelManagement.toast.presetDeleteSuccess",{name:s.name}),variant:"success"})}catch(t){i({title:n("modelManagement.toast.presetDeleteFailure",{message:t instanceof Error?t.message:"unknown"}),variant:"error"})}finally{ve(null),d.refetch()}}},Et=()=>{$()&&(Y("create"),Z(void 0),W(!0))},bt=e=>{$()&&(Y("edit"),Z(e),W(!0))},Rt=async e=>{if(!l)throw new Error(n("settings.toast.missingConfig"));const s=X==="create"?[...x,e]:x.map(o=>V&&o.id===V.id?{...e,id:V.id}:o),t={...l,providers:s};await I.saveConfig(t),k(t),D(ue(t,f)),d.refetch(),i({title:X==="create"?n("providers.toast.createSuccess",{name:e.label||e.id}):n("providers.toast.updateSuccess",{name:e.label||e.id}),variant:"success"})},St=async e=>{const s=f.find(t=>t.id===e);if(!(!s||s.deletable===!1))try{await ie.delete(e),await p.invalidateQueries({queryKey:U.customEndpoints.all()}),i({title:n("modelManagement.deleteEndpointSuccess"),variant:"success"}),y===e&&F("providers")}catch(t){const o=G(t);i({title:n("modelManagement.deleteEndpointError",{error:o.message}),variant:"error"})}},De=async(e,s)=>{de(e.id);try{const t=s&&(s.headers||s.query)?{headers:s.headers&&Object.keys(s.headers).length>0?s.headers:void 0,query:s.query&&s.query.trim().length>0?s.query.trim():void 0}:void 0,o=await _.testProvider(e.id,t);if(o.ok){i({title:n("providers.toast.testSuccess"),description:n("providers.toast.testSuccessDesc",{status:o.status,duration:o.durationMs?`${o.durationMs} ms`:"—"}),variant:"success"});return}i({title:n("providers.toast.testFailure",{message:`${o.status} ${o.statusText}`}),variant:"error"})}catch(t){const o=G(t);i({title:n("providers.toast.testFailure",{message:o.status?`${o.status} ${o.message}`:o.message}),variant:"error"})}finally{de(null)}},Mt=e=>{var u,h;if(!(!!((u=e.defaultModel)!=null&&u.trim())||!!((h=e.models)!=null&&h.some(E=>E.id.trim().length>0)))){Se(e);return}if(e.type!=="anthropic"){De(e);return}const t=e.extraHeaders??{},o=new Map(N.map(E=>[E.key.toLowerCase(),E])),a={};let r=!0;for(const E of N){const R=Object.entries(t).find(([M])=>M.toLowerCase()===E.key.toLowerCase());if(!R)continue;const[S,b]=R;String(b??"")!==E.value&&(r=!1,a[S]=String(b??""))}for(const[E,R]of Object.entries(t))o.has(E.toLowerCase())||(a[E]=String(R??""));Re(a),ae(r),Ee(e),ye(!0)},xe=()=>{ye(!1),Ee(null),ae(!0),Re({})},wt=async()=>{if(!oe)return;const e={};if(se)for(const o of N)e[o.key]=o.value;const s=new Map(N.map(o=>[o.key.toLowerCase(),o]));for(const[o,a]of Object.entries(be))s.get(o.toLowerCase())&&se||(e[o]=a);const t=oe;xe(),await De(t,{headers:Object.keys(e).length>0?e:void 0})},Oe=async e=>{var E,R,S,b,M,P,j,A;if(!$())return;const s=x.filter(w=>w.id!==e.id),t=w=>{const C={};if(!w)return C;for(const[B,q]of Object.entries(w)){if(!q)continue;const[$e]=q.split(":");$e&&$e===e.id||q===e.id||(C[B]=q)}return C},o=(l==null?void 0:l.endpointRouting)??{},a=t(((E=o.anthropic)==null?void 0:E.modelRoutes)??(l==null?void 0:l.modelRoutes)??{}),r=t(((R=o.openai)==null?void 0:R.modelRoutes)??{}),u=((l==null?void 0:l.customEndpoints)??f).map(w=>{const C=w.routing,B=C==null?void 0:C.modelRoutes;return B?{...w,routing:{...C,defaults:C.defaults??l.defaults,modelRoutes:t(B)}}:w}),h={...l,providers:s,modelRoutes:a,customEndpoints:u,endpointRouting:{anthropic:{defaults:((S=o.anthropic)==null?void 0:S.defaults)??l.defaults,modelRoutes:a,validation:(b=o.anthropic)==null?void 0:b.validation,compatibility:(M=o.anthropic)==null?void 0:M.compatibility},openai:{defaults:((P=o.openai)==null?void 0:P.defaults)??l.defaults,modelRoutes:r,validation:(j=o.openai)==null?void 0:j.validation,compatibility:(A=o.openai)==null?void 0:A.compatibility}}};try{await I.saveConfig(h),k(h),D({anthropic:Object.entries(a).map(([w,C])=>({id:O(),source:w,target:C})),openai:Object.entries(r).map(([w,C])=>({id:O(),source:w,target:C})),...Object.fromEntries(u.map(w=>{var C;return[w.id,Object.entries(((C=w.routing)==null?void 0:C.modelRoutes)??{}).map(([B,q])=>({id:O(),source:B,target:q}))]}))}),i({title:n("providers.toast.deleteSuccess",{name:e.label||e.id}),variant:"success"}),d.refetch()}catch(w){i({title:n("providers.toast.deleteFailure",{message:w instanceof Error?w.message:"unknown"}),variant:"error"})}},Ct=async()=>{if(c){Pe(!0);try{c.kind==="provider"?await Oe(c.provider):c.kind==="preset"?await yt(c.endpoint,c.preset):await St(c.endpoint.id),Ce(null)}finally{Pe(!1)}}},Pt=e=>{D(s=>({...s,[e]:[...s[e]||[],{id:O(),source:"",target:""}]})),T(s=>({...s,[e]:null}))},kt=async(e,s)=>{var t,o;if($()){Me(!0);try{if(e==="anthropic"||e==="openai"){const a=e,r=l.endpointRouting?{...l.endpointRouting}:{},u=r[a]??{defaults:l.defaults,modelRoutes:(a==="anthropic"?l.modelRoutes:{})??{}},h={defaults:u.defaults??l.defaults,modelRoutes:u.modelRoutes??{},compatibility:u.compatibility},E=s==="off"?void 0:{...u.validation??{},mode:s,allowExperimentalBlocks:((t=u.validation)==null?void 0:t.allowExperimentalBlocks)??!0},R={...l,endpointRouting:{...r,[a]:E?{...h,validation:E}:{...h}}};await I.saveConfig(R),k(R)}else{const a=[...l.customEndpoints??[]],r=a.findIndex(S=>S.id===e);if(r===-1)throw new Error(n("modelManagement.toast.endpointNotFound"));const u=a[r],h=u.routing??{defaults:l.defaults,modelRoutes:{}},E=s==="off"?void 0:{...h.validation??{},mode:s,allowExperimentalBlocks:((o=h.validation)==null?void 0:o.allowExperimentalBlocks)??!0};a[r]={...u,routing:E?{...h,validation:E}:{defaults:h.defaults,modelRoutes:h.modelRoutes,compatibility:h.compatibility}};const R={...l,customEndpoints:a};await I.saveConfig(R),k(R)}i({title:n("modelManagement.toast.validationModeSaved",{mode:n(`modelManagement.claudeValidation.options.${s}.label`)}),variant:"success"}),d.refetch()}catch(a){const r=G(a);i({title:n("modelManagement.toast.validationModeFailure",{message:r.message}),variant:"error"})}finally{Me(!1)}}},Dt=async(e,s)=>{if($()){we(!0);try{if(e==="anthropic"||e==="openai"){const t=e,o=l.endpointRouting?{...l.endpointRouting}:{},a=o[t]??{defaults:l.defaults,modelRoutes:(t==="anthropic"?l.modelRoutes:{})??{}},r={defaults:a.defaults??l.defaults,modelRoutes:a.modelRoutes??{},validation:a.validation},u={...l,endpointRouting:{...o,[t]:s?{...r,compatibility:{enabled:!0}}:{...r}}};await I.saveConfig(u),k(u)}else{const t=[...l.customEndpoints??[]],o=t.findIndex(h=>h.id===e);if(o===-1)throw new Error(n("modelManagement.toast.endpointNotFound"));const a=t[o],r=a.routing??{defaults:l.defaults,modelRoutes:{}};t[o]={...a,routing:s?{...r,compatibility:{enabled:!0}}:{defaults:r.defaults,modelRoutes:r.modelRoutes,validation:r.validation}};const u={...l,customEndpoints:t};await I.saveConfig(u),k(u)}i({title:n("modelManagement.toast.compatibilitySaved",{state:n(s?"common.enabled":"common.disabled")}),variant:"success"}),d.refetch()}catch(t){const o=G(t);i({title:n("modelManagement.toast.compatibilitySaveFailure",{message:o.message}),variant:"error"})}finally{we(!1)}}},xt=(e,s)=>{D(t=>{const o=t[e]||[];return o.some(a=>a.source.trim()===s.trim())?t:{...t,[e]:[...o,{id:O(),source:s,target:""}]}}),T(t=>({...t,[e]:null}))},Ot=(e,s,t,o)=>{D(a=>({...a,[e]:(a[e]||[]).map(r=>r.id===s?{...r,[t]:o}:r)})),T(a=>({...a,[e]:null}))},Tt=(e,s)=>{D(t=>({...t,[e]:(t[e]||[]).filter(o=>o.id!==s)})),T(t=>({...t,[e]:null}))},$t=e=>{var t;if(!l)return;const s=(l.customEndpoints??f).find(o=>o.id===e);if(s)D(o=>{var a;return{...o,[e]:Object.entries(((a=s.routing)==null?void 0:a.modelRoutes)??{}).map(([r,u])=>({id:O(),source:r,target:u}))}});else{const o=l.endpointRouting??{},a=e,r=a==="anthropic"?l.modelRoutes??{}:{},u=((t=o[a])==null?void 0:t.modelRoutes)??r;D(h=>({...h,[e]:Object.entries(u).map(([E,R])=>({id:O(),source:E,target:R}))}))}T(o=>({...o,[e]:null}))},It=Ie({mutationFn:async e=>(await I.saveConfig(e.nextConfig),e)}),Ft=Ie({mutationFn:async e=>(await ie.update(e.endpoint,{routing:e.routing}),e)}),Lt=async e=>{var o,a,r,u,h,E,R;if(!$())return;const s=L[e]||[],t={};for(const S of s){const b=S.source.trim(),M=S.target.trim();if(!(!b&&!M)){if(!b||!M){T(P=>({...P,[e]:n("settings.validation.routePair")}));return}if(t[b]){T(P=>({...P,[e]:n("settings.validation.routeDuplicate",{model:b})}));return}t[b]=M}}T(S=>({...S,[e]:null})),ce(e);try{const S=f.find(b=>b.id===e);if(S){const b={...S.routing??{},modelRoutes:t,defaults:((o=S.routing)==null?void 0:o.defaults)||l.defaults};await Ft.mutateAsync({endpoint:e,routing:b}),k(M=>{if(!M)return M;const P=[...M.customEndpoints??[]],j=P.findIndex(A=>A.id===e);return j===-1?M:(P[j]={...P[j],routing:b},{...M,customEndpoints:P})}),await p.invalidateQueries({queryKey:U.customEndpoints.all()})}else{const b={...l,endpointRouting:{...l.endpointRouting??{},[e]:{defaults:((r=(a=l.endpointRouting)==null?void 0:a[e])==null?void 0:r.defaults)??l.defaults,modelRoutes:t,validation:(h=(u=l.endpointRouting)==null?void 0:u[e])==null?void 0:h.validation,compatibility:(R=(E=l.endpointRouting)==null?void 0:E[e])==null?void 0:R.compatibility}},modelRoutes:e==="anthropic"?t:l.modelRoutes??{}};await It.mutateAsync({endpoint:e,nextConfig:b}),k(b)}D(b=>({...b,[e]:Object.entries(t).map(([M,P])=>({id:O(),source:M,target:P}))})),i({title:n("modelManagement.toast.routesSaved"),variant:"success"}),d.refetch()}catch(S){i({title:n("modelManagement.toast.routesSaveFailure",{message:S instanceof Error?S.message:"unknown"}),variant:"error"})}finally{ce(null)}},jt=(c==null?void 0:c.kind)==="provider"?n("providers.actions.delete"):(c==null?void 0:c.kind)==="preset"?n("modelManagement.presets.delete"):(c==null?void 0:c.kind)==="endpoint"?n("common.delete"):"",Bt=(c==null?void 0:c.kind)==="provider"?n("providers.confirm.delete",{name:c.provider.label||c.provider.id}):(c==null?void 0:c.kind)==="preset"?n("modelManagement.confirm.deletePreset",{name:c.preset.name}):(c==null?void 0:c.kind)==="endpoint"?n("modelManagement.deleteEndpointConfirm",{label:c.endpoint.label}):"",qt=(c==null?void 0:c.kind)==="provider"?c.provider.label||c.provider.id:(c==null?void 0:c.kind)==="preset"?c.preset.name:(c==null?void 0:c.kind)==="endpoint"?c.endpoint.label:"";return{activeTab:y,activeTabInfo:rt,anthropicTestHeaderOptions:N,applyingPreset:Ke,config:l,configQuery:d,confirmAction:c,confirmDialogDescription:Bt,confirmDialogName:qt,confirmDialogTitle:jt,confirmingAction:tt,customEndpoints:f,customTabs:at,defaultLabels:ut,deletingPreset:He,drawerMode:X,drawerOpen:Be,editingEndpoint:qe,editingProvider:V,endpointDrawerOpen:Ue,filteredProviders:lt,noModelDialogProvider:_e,handleAddRoute:Pt,handleAddSuggestion:xt,handleApplyPreset:vt,handleCompatibilityEnabledChange:Dt,handleConfirmDialog:Ct,handleDeleteProvider:Oe,handleOpenCreate:Et,handleOpenCreateEndpoint:ct,handleOpenEditEndpoint:mt,handleOpenEdit:bt,handlePresetNameChange:gt,handleProviderSubmit:Rt,handleRemoveRoute:Tt,handleResetRoutes:$t,handleRouteChange:Ot,handleSavePreset:ht,handleSaveRoutes:Lt,handleValidationModeChange:kt,initiateTestConnection:Mt,isDirtyByEndpoint:ft,presetDiffDialog:Ze,presetErrorByEndpoint:ze,presetNameByEndpoint:pe,presetsByEndpoint:me,presetsExpanded:Xe,providerCount:it,providerModelOptions:dt,providerSearch:re,providerTypeFilter:z,providers:x,pushToast:i,routeError:Ve,routesByEndpoint:L,savingClaudeValidation:Je,savingCompatibilityPolicy:We,savingPresetFor:Ae,savingRouteFor:Qe,setActiveTab:F,setConfirmAction:Ce,setDrawerMode:Y,setDrawerOpen:W,setEditingEndpoint:ee,setEditingProvider:Z,setEndpointDrawerOpen:te,setNoModelDialogProvider:Se,setPresetDiffDialog:et,setPresetsExpanded:Ye,setProviderSearch:nt,setProviderTypeFilter:ot,setTestDialogUsePreset:ae,systemTabs:st,tabs:g,testDialogOpen:Ge,testDialogPreservedExtras:be,testDialogProvider:oe,testDialogUsePreset:se,testingProviderId:Ne,closeTestDialog:xe,confirmTestDialog:wt}}export{tn as C,nn as O,an as a,sn as g,on as i,rn as u};
1
+ import{r as m}from"./vendor-DdPBfMMb.js";import{u as Nt,a as Ut}from"./query-QCek5MsK.js";import{g as K,b as H,u as Vt,t as G,c as ie}from"./app-BF0X4ljN.js";import{g as I}from"./gateway-Bo9FVYfn.js";import{q as U}from"./queryKeys-0HDa7byL.js";import{u as Ie}from"./useAppMutation-C8scr-Sv.js";import{u as Qt}from"./useApiQuery-DaxeBDln.js";import{u as zt}from"./i18n-C8tBby0x.js";const _={savePreset(n,i){return K(H.post(`/api/routing-presets/${n}`,{name:i}))},applyPreset(n,i){return K(H.post(`/api/routing-presets/${n}/apply`,{name:i}))},deletePreset(n,i){return K(H.delete(`/api/routing-presets/${n}/${encodeURIComponent(i)}`))},testProvider(n,i){return K(H.post(`/api/providers/${n}/test`,i??{}))}},tn=["claude-sonnet-4-5-20250929","claude-sonnet-4-5-20250929-thinking","claude-sonnet-4-20250514","claude-opus-4-1-20250805","claude-opus-4-1-20250805-thinking","claude-haiku-4-5-20251001","claude-haiku-4-5-20251001-thinking","claude-3-5-haiku-20241022"],nn=["gpt-4o-mini","gpt-4o","o4-mini","o4-large","gpt-5-codex"];function O(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2,10)}function J(n,i){var p;return(p=n==null?void 0:n.customEndpoints)!=null&&p.length?n.customEndpoints:i}function le(n){return n?Object.entries(n).map(([i,p])=>({id:O(),source:i,target:p})):[]}function ue(n,i){var v,f,g;if(!n)return{};const p={},d=n.endpointRouting??{};p.anthropic=le(((v=d.anthropic)==null?void 0:v.modelRoutes)??n.modelRoutes??{}),p.openai=le(((f=d.openai)==null?void 0:f.modelRoutes)??{});for(const y of J(n,i))(g=y.routing)!=null&&g.modelRoutes?p[y.id]=le(y.routing.modelRoutes):p[y.id]=[];return p}function Fe(n,i,p){var f,g,y;const d=J(n,i).find(F=>F.id===p);if(d)return((f=d.routing)==null?void 0:f.modelRoutes)??{};const v=n.endpointRouting??{};return p==="anthropic"?((g=v.anthropic)==null?void 0:g.modelRoutes)??n.modelRoutes??{}:p==="openai"?((y=v.openai)==null?void 0:y.modelRoutes)??{}:{}}function At(n){const i={};for(const p of n){const d=p.source.trim(),v=p.target.trim();d&&v&&(i[d]=v)}return i}function Le(n,i){return JSON.stringify(At(n))!==JSON.stringify(i)}function on(n,i){if(n==="anthropic")return!0;const p=i.find(d=>d.id===n);return p?p.paths&&p.paths.length>0?p.paths.some(d=>d.protocol==="anthropic"):p.protocol==="anthropic":!1}function sn(n,i,p){var v,f,g;if(!i)return;if(n==="anthropic"||n==="openai")return(f=(v=i.endpointRouting)==null?void 0:v[n])==null?void 0:f.validation;const d=J(i,p).find(y=>y.id===n);return(g=d==null?void 0:d.routing)==null?void 0:g.validation}function an(n,i,p){var v,f,g;if(!i)return;if(n==="anthropic"||n==="openai")return(f=(v=i.endpointRouting)==null?void 0:v[n])==null?void 0:f.compatibility;const d=J(i,p).find(y=>y.id===n);return(g=d==null?void 0:d.routing)==null?void 0:g.compatibility}function Kt(n,i){const p=[{key:"providers",label:n("modelManagement.tabs.providers"),description:n("modelManagement.tabs.providersDesc"),isSystem:!0,canDelete:!1},{key:"anthropic",label:n("modelManagement.tabs.anthropic"),description:n("modelManagement.tabs.anthropicDesc"),isSystem:!0,canDelete:!1,protocols:["anthropic"]},{key:"openai",label:n("modelManagement.tabs.openai"),description:n("modelManagement.tabs.openaiDesc"),isSystem:!0,canDelete:!1,protocols:["openai-auto","openai-chat","openai-responses"]}],d=i.map(v=>{let f=n("modelManagement.tabs.customEndpoint"),g=[];if(v.paths&&v.paths.length>0)f=`${n("modelManagement.tabs.customEndpoint")}: ${v.paths.map(y=>`${y.path} (${y.protocol})`).join(", ")}`,g=[...new Set(v.paths.map(y=>y.protocol))];else if(v.path){const y=v.protocol||"anthropic";f=`${n("modelManagement.tabs.customEndpoint")}: ${v.path} (${y})`,g=[y]}return{key:v.id,label:v.label||v.id,description:f,isSystem:!1,canDelete:v.deletable!==!1,protocols:g}});return[...p,...d]}function Ht(n){return n.label&&n.label.trim().length>0?`${n.label} (${n.id})`:n.id}function je(n,i){var d,v,f;const p={anthropic:((d=n.routingPresets)==null?void 0:d.anthropic)??[],openai:((v=n.routingPresets)==null?void 0:v.openai)??[]};for(const g of i){const y=(f=n.customEndpoints)==null?void 0:f.find(F=>F.id===g.id);p[g.id]=(y==null?void 0:y.routingPresets)??g.routingPresets??[]}return p}function rn(){var Te;const{t:n}=zt(),{pushToast:i}=Vt(),p=Nt(),d=Qt(U.config.full(),I.configRequest()),f=((Te=Ut({queryKey:U.customEndpoints.all(),queryFn:ie.list,refetchInterval:1e4}).data)==null?void 0:Te.endpoints)??[],g=m.useMemo(()=>Kt(n,f),[f,n]),[y,F]=m.useState("providers"),[l,k]=m.useState(null),[Be,W]=m.useState(!1),[X,Y]=m.useState("create"),[V,Z]=m.useState(void 0),[qe,ee]=m.useState(void 0),[Ne,de]=m.useState(null),[Ue,te]=m.useState(!1),[L,D]=m.useState({}),[Ve,T]=m.useState({}),[Qe,ce]=m.useState(null),[me,ne]=m.useState({}),[pe,fe]=m.useState({}),[ze,Q]=m.useState({}),[Ae,ge]=m.useState(null),[Ke,he]=m.useState(null),[He,ve]=m.useState(null),[Ge,ye]=m.useState(!1),[oe,Ee]=m.useState(null),[se,ae]=m.useState(!0),[be,Re]=m.useState({}),[_e,Se]=m.useState(null),[Je,Me]=m.useState(!1),[We,we]=m.useState(!1),[Xe,Ye]=m.useState({}),[Ze,et]=m.useState(null),[c,Ce]=m.useState(null),[tt,Pe]=m.useState(!1),[re,nt]=m.useState(""),[z,ot]=m.useState("all"),st=m.useMemo(()=>g.filter(e=>e.isSystem),[g]),at=m.useMemo(()=>g.filter(e=>!e.isSystem),[g]),rt=m.useMemo(()=>g.find(e=>e.key===y)??g[0]??null,[y,g]),x=(l==null?void 0:l.providers)??[],it=x.length,lt=m.useMemo(()=>x.filter(e=>{var a;if(!(z==="all"||(e.type??"custom")===z))return!1;const t=re.trim().toLowerCase();return t?[e.id,e.label??"",e.baseUrl,e.defaultModel??"",...((a=e.models)==null?void 0:a.map(r=>r.id))??[]].join(" ").toLowerCase().includes(t):!0}),[re,z,x]),N=m.useMemo(()=>[{key:"anthropic-beta",value:"claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14",label:n("providers.testDialog.options.beta.label"),description:n("providers.testDialog.options.beta.description")}],[n]);m.useEffect(()=>{if(!d.data)return;const e=d.data;k(e),D(s=>{const t=ue(e,f);if(!s||Object.keys(s).length===0)return t;const o={...t};for(const[a,r]of Object.entries(s)){if(!(a in t))continue;const u=Fe(e,f,a);Le(r,u)&&(o[a]=r)}return o}),T({}),ne(je(e,f))},[d.data,f]),m.useEffect(()=>{!d.isError||!d.error||i({title:n("providers.toast.loadFailure",{message:d.error.message}),variant:"error"})},[d.error,d.isError,i,n]),m.useEffect(()=>{g.some(e=>e.key===y)||F("providers")},[y,g]);const ut=m.useMemo(()=>{const e=new Map;for(const s of x){if(!s.defaultModel||!s.models)continue;const t=s.models.find(o=>o.id===s.defaultModel);t&&e.set(s.id,Ht(t))}return e},[x]),dt=m.useMemo(()=>{const e=[],s=new Set;for(const t of x){const o=t.label&&t.label!==t.id?`${t.label} (${t.id})`:t.id,a=t.models??[];if(a.length>0)for(const u of a){const h=`${t.id}:${u.id}`;s.has(h)||(s.add(h),e.push({value:h,label:`${o} · ${u.label??u.id}`,providerId:t.id,providerLabel:o,modelId:u.id,modelLabel:u.label??u.id,kind:"model",isDefault:t.defaultModel===u.id}))}else if(t.defaultModel){const u=`${t.id}:${t.defaultModel}`;s.has(u)||(s.add(u),e.push({value:u,label:`${o} · ${t.defaultModel}`,providerId:t.id,providerLabel:o,modelId:t.defaultModel,modelLabel:t.defaultModel,kind:"model",isDefault:!0}))}const r=`${t.id}:*`;s.has(r)||(s.add(r),e.push({value:r,label:n("settings.routing.providerPassthroughOption",{provider:o}),providerId:t.id,providerLabel:o,modelId:"*",modelLabel:"*",kind:"passthrough"}))}for(const t of Object.values(L).flat()){const o=t.target.trim();o&&!s.has(o)&&(s.add(o),e.push({value:o,label:o,modelId:o,modelLabel:o,kind:"custom"}))}return e},[x,L,n]),ct=()=>{ee(void 0),te(!0)},mt=e=>{ee(e),te(!0)},pt=e=>l?Fe(l,f,e):{},ft=m.useMemo(()=>{const e={};for(const s of g){if(s.key==="providers")continue;const t=L[s.key]||[];e[s.key]=Le(t,pt(s.key))}return e},[l,f,L,g]),ke=(e,s)=>{ne(t=>({...t,[e]:s})),k(t=>{if(!t)return t;if(e==="anthropic"||e==="openai")return{...t,routingPresets:{...t.routingPresets,[e]:s}};const o=[...t.customEndpoints??[]],a=o.findIndex(r=>r.id===e);return a===-1?t:(o[a]={...o[a],routingPresets:s},{...t,customEndpoints:o})})},$=()=>l?!0:(i({title:n("settings.toast.missingConfig"),variant:"error"}),d.refetch(),!1),gt=(e,s)=>{fe(t=>({...t,[e]:s})),s.trim()&&Q(t=>({...t,[e]:null}))},ht=async e=>{if(!$())return;const s=(pe[e]??"").trim();if(!s){Q(t=>({...t,[e]:n("modelManagement.validation.presetName")}));return}if((me[e]??[]).some(t=>t.name.toLowerCase()===s.toLowerCase())){Q(t=>({...t,[e]:n("modelManagement.validation.presetDuplicate",{name:s})}));return}ge(e);try{const o=(await _.savePreset(e,s)).presets??[];ke(e,o),fe(a=>({...a,[e]:""})),Q(a=>({...a,[e]:null})),i({title:n("modelManagement.toast.presetSaved",{name:s}),variant:"success"})}catch(t){i({title:n("modelManagement.toast.presetSaveFailure",{message:t instanceof Error?t.message:"unknown"}),variant:"error"})}finally{ge(null),d.refetch()}},vt=async(e,s)=>{if($()){he({endpoint:e,name:s.name});try{const o=(await _.applyPreset(e,s.name)).config;if(o)k(o),D(ue(o,f)),ne(je(o,f));else{const a=s.modelRoutes??{};D(r=>({...r,[e]:Object.entries(a).map(([u,h])=>({id:O(),source:u,target:h}))})),k(r=>{var h,E,R,S;if(!r)return r;const u=(r.customEndpoints??[]).findIndex(b=>b.id===e);if(u!==-1){const b=[...r.customEndpoints??[]],M=b[u];return b[u]={...M,routing:{defaults:((h=M.routing)==null?void 0:h.defaults)??r.defaults,...M.routing??{},modelRoutes:a}},{...r,customEndpoints:b}}return e==="anthropic"||e==="openai"?{...r,endpointRouting:{...r.endpointRouting??{},[e]:{defaults:((R=(E=r.endpointRouting)==null?void 0:E[e])==null?void 0:R.defaults)??r.defaults,...((S=r.endpointRouting)==null?void 0:S[e])??{},modelRoutes:a}},modelRoutes:e==="anthropic"?a:r.modelRoutes??{}}:r})}e!=="anthropic"&&e!=="openai"&&await p.invalidateQueries({queryKey:U.customEndpoints.all()}),i({title:n("modelManagement.toast.presetApplySuccess",{name:s.name}),variant:"success"})}catch(t){i({title:n("modelManagement.toast.presetApplyFailure",{message:t instanceof Error?t.message:"unknown"}),variant:"error"})}finally{he(null),d.refetch()}}},yt=async(e,s)=>{if($()){ve({endpoint:e,name:s.name});try{const t=await _.deletePreset(e,s.name);ke(e,t.presets??[]),i({title:n("modelManagement.toast.presetDeleteSuccess",{name:s.name}),variant:"success"})}catch(t){i({title:n("modelManagement.toast.presetDeleteFailure",{message:t instanceof Error?t.message:"unknown"}),variant:"error"})}finally{ve(null),d.refetch()}}},Et=()=>{$()&&(Y("create"),Z(void 0),W(!0))},bt=e=>{$()&&(Y("edit"),Z(e),W(!0))},Rt=async e=>{if(!l)throw new Error(n("settings.toast.missingConfig"));const s=X==="create"?[...x,e]:x.map(o=>V&&o.id===V.id?{...e,id:V.id}:o),t={...l,providers:s};await I.saveConfig(t),k(t),D(ue(t,f)),d.refetch(),i({title:X==="create"?n("providers.toast.createSuccess",{name:e.label||e.id}):n("providers.toast.updateSuccess",{name:e.label||e.id}),variant:"success"})},St=async e=>{const s=f.find(t=>t.id===e);if(!(!s||s.deletable===!1))try{await ie.delete(e),await p.invalidateQueries({queryKey:U.customEndpoints.all()}),i({title:n("modelManagement.deleteEndpointSuccess"),variant:"success"}),y===e&&F("providers")}catch(t){const o=G(t);i({title:n("modelManagement.deleteEndpointError",{error:o.message}),variant:"error"})}},De=async(e,s)=>{de(e.id);try{const t=s&&(s.headers||s.query)?{headers:s.headers&&Object.keys(s.headers).length>0?s.headers:void 0,query:s.query&&s.query.trim().length>0?s.query.trim():void 0}:void 0,o=await _.testProvider(e.id,t);if(o.ok){i({title:n("providers.toast.testSuccess"),description:n("providers.toast.testSuccessDesc",{status:o.status,duration:o.durationMs?`${o.durationMs} ms`:"—"}),variant:"success"});return}i({title:n("providers.toast.testFailure",{message:`${o.status} ${o.statusText}`}),variant:"error"})}catch(t){const o=G(t);i({title:n("providers.toast.testFailure",{message:o.status?`${o.status} ${o.message}`:o.message}),variant:"error"})}finally{de(null)}},Mt=e=>{var u,h;if(!(!!((u=e.defaultModel)!=null&&u.trim())||!!((h=e.models)!=null&&h.some(E=>E.id.trim().length>0)))){Se(e);return}if(e.type!=="anthropic"){De(e);return}const t=e.extraHeaders??{},o=new Map(N.map(E=>[E.key.toLowerCase(),E])),a={};let r=!0;for(const E of N){const R=Object.entries(t).find(([M])=>M.toLowerCase()===E.key.toLowerCase());if(!R)continue;const[S,b]=R;String(b??"")!==E.value&&(r=!1,a[S]=String(b??""))}for(const[E,R]of Object.entries(t))o.has(E.toLowerCase())||(a[E]=String(R??""));Re(a),ae(r),Ee(e),ye(!0)},xe=()=>{ye(!1),Ee(null),ae(!0),Re({})},wt=async()=>{if(!oe)return;const e={};if(se)for(const o of N)e[o.key]=o.value;const s=new Map(N.map(o=>[o.key.toLowerCase(),o]));for(const[o,a]of Object.entries(be))s.get(o.toLowerCase())&&se||(e[o]=a);const t=oe;xe(),await De(t,{headers:Object.keys(e).length>0?e:void 0})},Oe=async e=>{var E,R,S,b,M,P,j,A;if(!$())return;const s=x.filter(w=>w.id!==e.id),t=w=>{const C={};if(!w)return C;for(const[B,q]of Object.entries(w)){if(!q)continue;const[$e]=q.split(":");$e&&$e===e.id||q===e.id||(C[B]=q)}return C},o=(l==null?void 0:l.endpointRouting)??{},a=t(((E=o.anthropic)==null?void 0:E.modelRoutes)??(l==null?void 0:l.modelRoutes)??{}),r=t(((R=o.openai)==null?void 0:R.modelRoutes)??{}),u=((l==null?void 0:l.customEndpoints)??f).map(w=>{const C=w.routing,B=C==null?void 0:C.modelRoutes;return B?{...w,routing:{...C,defaults:C.defaults??l.defaults,modelRoutes:t(B)}}:w}),h={...l,providers:s,modelRoutes:a,customEndpoints:u,endpointRouting:{anthropic:{defaults:((S=o.anthropic)==null?void 0:S.defaults)??l.defaults,modelRoutes:a,validation:(b=o.anthropic)==null?void 0:b.validation,compatibility:(M=o.anthropic)==null?void 0:M.compatibility},openai:{defaults:((P=o.openai)==null?void 0:P.defaults)??l.defaults,modelRoutes:r,validation:(j=o.openai)==null?void 0:j.validation,compatibility:(A=o.openai)==null?void 0:A.compatibility}}};try{await I.saveConfig(h),k(h),D({anthropic:Object.entries(a).map(([w,C])=>({id:O(),source:w,target:C})),openai:Object.entries(r).map(([w,C])=>({id:O(),source:w,target:C})),...Object.fromEntries(u.map(w=>{var C;return[w.id,Object.entries(((C=w.routing)==null?void 0:C.modelRoutes)??{}).map(([B,q])=>({id:O(),source:B,target:q}))]}))}),i({title:n("providers.toast.deleteSuccess",{name:e.label||e.id}),variant:"success"}),d.refetch()}catch(w){i({title:n("providers.toast.deleteFailure",{message:w instanceof Error?w.message:"unknown"}),variant:"error"})}},Ct=async()=>{if(c){Pe(!0);try{c.kind==="provider"?await Oe(c.provider):c.kind==="preset"?await yt(c.endpoint,c.preset):await St(c.endpoint.id),Ce(null)}finally{Pe(!1)}}},Pt=e=>{D(s=>({...s,[e]:[...s[e]||[],{id:O(),source:"",target:""}]})),T(s=>({...s,[e]:null}))},kt=async(e,s)=>{var t,o;if($()){Me(!0);try{if(e==="anthropic"||e==="openai"){const a=e,r=l.endpointRouting?{...l.endpointRouting}:{},u=r[a]??{defaults:l.defaults,modelRoutes:(a==="anthropic"?l.modelRoutes:{})??{}},h={defaults:u.defaults??l.defaults,modelRoutes:u.modelRoutes??{},compatibility:u.compatibility},E=s==="off"?void 0:{...u.validation??{},mode:s,allowExperimentalBlocks:((t=u.validation)==null?void 0:t.allowExperimentalBlocks)??!0},R={...l,endpointRouting:{...r,[a]:E?{...h,validation:E}:{...h}}};await I.saveConfig(R),k(R)}else{const a=[...l.customEndpoints??[]],r=a.findIndex(S=>S.id===e);if(r===-1)throw new Error(n("modelManagement.toast.endpointNotFound"));const u=a[r],h=u.routing??{defaults:l.defaults,modelRoutes:{}},E=s==="off"?void 0:{...h.validation??{},mode:s,allowExperimentalBlocks:((o=h.validation)==null?void 0:o.allowExperimentalBlocks)??!0};a[r]={...u,routing:E?{...h,validation:E}:{defaults:h.defaults,modelRoutes:h.modelRoutes,compatibility:h.compatibility}};const R={...l,customEndpoints:a};await I.saveConfig(R),k(R)}i({title:n("modelManagement.toast.validationModeSaved",{mode:n(`modelManagement.claudeValidation.options.${s}.label`)}),variant:"success"}),d.refetch()}catch(a){const r=G(a);i({title:n("modelManagement.toast.validationModeFailure",{message:r.message}),variant:"error"})}finally{Me(!1)}}},Dt=async(e,s)=>{if($()){we(!0);try{if(e==="anthropic"||e==="openai"){const t=e,o=l.endpointRouting?{...l.endpointRouting}:{},a=o[t]??{defaults:l.defaults,modelRoutes:(t==="anthropic"?l.modelRoutes:{})??{}},r={defaults:a.defaults??l.defaults,modelRoutes:a.modelRoutes??{},validation:a.validation},u={...l,endpointRouting:{...o,[t]:s?{...r,compatibility:{enabled:!0}}:{...r}}};await I.saveConfig(u),k(u)}else{const t=[...l.customEndpoints??[]],o=t.findIndex(h=>h.id===e);if(o===-1)throw new Error(n("modelManagement.toast.endpointNotFound"));const a=t[o],r=a.routing??{defaults:l.defaults,modelRoutes:{}};t[o]={...a,routing:s?{...r,compatibility:{enabled:!0}}:{defaults:r.defaults,modelRoutes:r.modelRoutes,validation:r.validation}};const u={...l,customEndpoints:t};await I.saveConfig(u),k(u)}i({title:n("modelManagement.toast.compatibilitySaved",{state:n(s?"common.enabled":"common.disabled")}),variant:"success"}),d.refetch()}catch(t){const o=G(t);i({title:n("modelManagement.toast.compatibilitySaveFailure",{message:o.message}),variant:"error"})}finally{we(!1)}}},xt=(e,s)=>{D(t=>{const o=t[e]||[];return o.some(a=>a.source.trim()===s.trim())?t:{...t,[e]:[...o,{id:O(),source:s,target:""}]}}),T(t=>({...t,[e]:null}))},Ot=(e,s,t,o)=>{D(a=>({...a,[e]:(a[e]||[]).map(r=>r.id===s?{...r,[t]:o}:r)})),T(a=>({...a,[e]:null}))},Tt=(e,s)=>{D(t=>({...t,[e]:(t[e]||[]).filter(o=>o.id!==s)})),T(t=>({...t,[e]:null}))},$t=e=>{var t;if(!l)return;const s=(l.customEndpoints??f).find(o=>o.id===e);if(s)D(o=>{var a;return{...o,[e]:Object.entries(((a=s.routing)==null?void 0:a.modelRoutes)??{}).map(([r,u])=>({id:O(),source:r,target:u}))}});else{const o=l.endpointRouting??{},a=e,r=a==="anthropic"?l.modelRoutes??{}:{},u=((t=o[a])==null?void 0:t.modelRoutes)??r;D(h=>({...h,[e]:Object.entries(u).map(([E,R])=>({id:O(),source:E,target:R}))}))}T(o=>({...o,[e]:null}))},It=Ie({mutationFn:async e=>(await I.saveConfig(e.nextConfig),e)}),Ft=Ie({mutationFn:async e=>(await ie.update(e.endpoint,{routing:e.routing}),e)}),Lt=async e=>{var o,a,r,u,h,E,R;if(!$())return;const s=L[e]||[],t={};for(const S of s){const b=S.source.trim(),M=S.target.trim();if(!(!b&&!M)){if(!b||!M){T(P=>({...P,[e]:n("settings.validation.routePair")}));return}if(t[b]){T(P=>({...P,[e]:n("settings.validation.routeDuplicate",{model:b})}));return}t[b]=M}}T(S=>({...S,[e]:null})),ce(e);try{const S=f.find(b=>b.id===e);if(S){const b={...S.routing??{},modelRoutes:t,defaults:((o=S.routing)==null?void 0:o.defaults)||l.defaults};await Ft.mutateAsync({endpoint:e,routing:b}),k(M=>{if(!M)return M;const P=[...M.customEndpoints??[]],j=P.findIndex(A=>A.id===e);return j===-1?M:(P[j]={...P[j],routing:b},{...M,customEndpoints:P})}),await p.invalidateQueries({queryKey:U.customEndpoints.all()})}else{const b={...l,endpointRouting:{...l.endpointRouting??{},[e]:{defaults:((r=(a=l.endpointRouting)==null?void 0:a[e])==null?void 0:r.defaults)??l.defaults,modelRoutes:t,validation:(h=(u=l.endpointRouting)==null?void 0:u[e])==null?void 0:h.validation,compatibility:(R=(E=l.endpointRouting)==null?void 0:E[e])==null?void 0:R.compatibility}},modelRoutes:e==="anthropic"?t:l.modelRoutes??{}};await It.mutateAsync({endpoint:e,nextConfig:b}),k(b)}D(b=>({...b,[e]:Object.entries(t).map(([M,P])=>({id:O(),source:M,target:P}))})),i({title:n("modelManagement.toast.routesSaved"),variant:"success"}),d.refetch()}catch(S){i({title:n("modelManagement.toast.routesSaveFailure",{message:S instanceof Error?S.message:"unknown"}),variant:"error"})}finally{ce(null)}},jt=(c==null?void 0:c.kind)==="provider"?n("providers.actions.delete"):(c==null?void 0:c.kind)==="preset"?n("modelManagement.presets.delete"):(c==null?void 0:c.kind)==="endpoint"?n("common.delete"):"",Bt=(c==null?void 0:c.kind)==="provider"?n("providers.confirm.delete",{name:c.provider.label||c.provider.id}):(c==null?void 0:c.kind)==="preset"?n("modelManagement.confirm.deletePreset",{name:c.preset.name}):(c==null?void 0:c.kind)==="endpoint"?n("modelManagement.deleteEndpointConfirm",{label:c.endpoint.label}):"",qt=(c==null?void 0:c.kind)==="provider"?c.provider.label||c.provider.id:(c==null?void 0:c.kind)==="preset"?c.preset.name:(c==null?void 0:c.kind)==="endpoint"?c.endpoint.label:"";return{activeTab:y,activeTabInfo:rt,anthropicTestHeaderOptions:N,applyingPreset:Ke,config:l,configQuery:d,confirmAction:c,confirmDialogDescription:Bt,confirmDialogName:qt,confirmDialogTitle:jt,confirmingAction:tt,customEndpoints:f,customTabs:at,defaultLabels:ut,deletingPreset:He,drawerMode:X,drawerOpen:Be,editingEndpoint:qe,editingProvider:V,endpointDrawerOpen:Ue,filteredProviders:lt,noModelDialogProvider:_e,handleAddRoute:Pt,handleAddSuggestion:xt,handleApplyPreset:vt,handleCompatibilityEnabledChange:Dt,handleConfirmDialog:Ct,handleDeleteProvider:Oe,handleOpenCreate:Et,handleOpenCreateEndpoint:ct,handleOpenEditEndpoint:mt,handleOpenEdit:bt,handlePresetNameChange:gt,handleProviderSubmit:Rt,handleRemoveRoute:Tt,handleResetRoutes:$t,handleRouteChange:Ot,handleSavePreset:ht,handleSaveRoutes:Lt,handleValidationModeChange:kt,initiateTestConnection:Mt,isDirtyByEndpoint:ft,presetDiffDialog:Ze,presetErrorByEndpoint:ze,presetNameByEndpoint:pe,presetsByEndpoint:me,presetsExpanded:Xe,providerCount:it,providerModelOptions:dt,providerSearch:re,providerTypeFilter:z,providers:x,pushToast:i,routeError:Ve,routesByEndpoint:L,savingClaudeValidation:Je,savingCompatibilityPolicy:We,savingPresetFor:Ae,savingRouteFor:Qe,setActiveTab:F,setConfirmAction:Ce,setDrawerMode:Y,setDrawerOpen:W,setEditingEndpoint:ee,setEditingProvider:Z,setEndpointDrawerOpen:te,setNoModelDialogProvider:Se,setPresetDiffDialog:et,setPresetsExpanded:Ye,setProviderSearch:nt,setProviderTypeFilter:ot,setTestDialogUsePreset:ae,systemTabs:st,tabs:g,testDialogOpen:Ge,testDialogPreservedExtras:be,testDialogProvider:oe,testDialogUsePreset:se,testingProviderId:Ne,closeTestDialog:xe,confirmTestDialog:wt}}export{tn as C,nn as O,an as a,sn as g,on as i,rn as u};
@@ -0,0 +1 @@
1
+ const o=[168,184,198,208,218,228,238,248,258,268,278,292],s=2e5;function c(t){const e=new Date(t);return`${e.getFullYear()}-${`${e.getMonth()+1}`.padStart(2,"0")}-${`${e.getDate()}`.padStart(2,"0")} ${`${e.getHours()}`.padStart(2,"0")}:${`${e.getMinutes()}`.padStart(2,"0")}:${`${e.getSeconds()}`.padStart(2,"0")}`}function u(t){return t==null?"-":t.toLocaleString()}function i(t,e){const r=u(t);return r==="-"?"-":`${r} ${e}`}function g(t){return t?"true":"false"}function f(t,e){if(!t||t.trim().length===0)return e;if(t.length>s)return t;try{const r=JSON.parse(t);return JSON.stringify(r,null,2)}catch{return t}}function S(t,e){return t.status_code===null||t.status_code===void 0?t.error?{label:e("common.status.error"),tone:"error",variant:"destructive"}:{label:e("common.status.pending"),tone:"pending",variant:"warning"}:t.error||t.status_code>=400?{label:t.status_code.toString(),tone:"error",variant:"destructive"}:{label:t.status_code.toString(),tone:"success",variant:"success"}}function d(t,e){if(!(!!t.error||(t.status_code??0)>=400))return{label:e("logs.detail.errorSource.none"),tone:"none"};switch(t.error_source){case"client":return{label:e("logs.detail.errorSource.client"),tone:"client"};case"gateway":return{label:e("logs.detail.errorSource.gateway"),tone:"gateway"};case"upstream":return{label:e("logs.detail.errorSource.upstream"),tone:"upstream"};default:return{label:e("logs.detail.errorSource.unknown"),tone:"unknown"}}}function l(t){let e=0;for(let r=0;r<t.length;r+=1)e=e*31+t.charCodeAt(r)>>>0;return e}function h(t){const e=t==null?void 0:t.trim();if(!e)return null;const r=l(e),n=o[r%o.length],a=`hsl(${n} 74% 46%)`;return{sessionId:e,colorKey:`${n}`,rowStyle:{backgroundColor:`hsl(${n} 74% 46% / 0.05)`},hoverStyle:{backgroundColor:`hsl(${n} 74% 46% / 0.09)`},stickyStyle:{backgroundColor:`hsl(${n} 74% 46% / 0.08)`},accentStyle:{borderLeft:`3px solid ${a}`}}}export{d as a,i as b,c,g as d,u as e,f,S as g,h};
@@ -8,14 +8,14 @@
8
8
  <link rel="apple-touch-icon" href="/cc-gw-mark.svg" />
9
9
  <link rel="manifest" href="/site.webmanifest" />
10
10
  <title>cc-gw 控制台</title>
11
- <script type="module" crossorigin src="/assets/app-BBdow7GJ.js"></script>
11
+ <script type="module" crossorigin src="/assets/app-BF0X4ljN.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="/assets/vendor-DdPBfMMb.js">
13
- <link rel="modulepreload" crossorigin href="/assets/global-CaQPIFGa.js">
13
+ <link rel="modulepreload" crossorigin href="/assets/global-CsDL9Nt2.js">
14
14
  <link rel="modulepreload" crossorigin href="/assets/query-QCek5MsK.js">
15
15
  <link rel="modulepreload" crossorigin href="/assets/i18n-C8tBby0x.js">
16
16
  <link rel="modulepreload" crossorigin href="/assets/router-D2Fb4U0L.js">
17
17
  <link rel="modulepreload" crossorigin href="/assets/radix-CtQBp6Ie.js">
18
- <link rel="stylesheet" crossorigin href="/assets/global-DWbUmocj.css">
18
+ <link rel="stylesheet" crossorigin href="/assets/global-Dcdq4qY7.css">
19
19
  </head>
20
20
  <body class="bg-slate-50 text-slate-900 dark:bg-slate-900 dark:text-slate-50">
21
21
  <div id="root"></div>
@@ -42,12 +42,12 @@
42
42
  }
43
43
  </script>
44
44
  <title>cc-gw | 你的 API Key 不该躺在 30 个 .env 里 · local-first AI gateway</title>
45
- <script type="module" crossorigin src="/assets/landing-DYbMaEZw.js"></script>
45
+ <script type="module" crossorigin src="/assets/landing-D5PpgO3n.js"></script>
46
46
  <link rel="modulepreload" crossorigin href="/assets/vendor-DdPBfMMb.js">
47
- <link rel="modulepreload" crossorigin href="/assets/global-CaQPIFGa.js">
47
+ <link rel="modulepreload" crossorigin href="/assets/global-CsDL9Nt2.js">
48
48
  <link rel="modulepreload" crossorigin href="/assets/clipboard-CALi6bTW.js">
49
- <link rel="modulepreload" crossorigin href="/assets/package-BMoxvLUB.js">
50
- <link rel="stylesheet" crossorigin href="/assets/global-DWbUmocj.css">
49
+ <link rel="modulepreload" crossorigin href="/assets/package-BeIzyZKv.js">
50
+ <link rel="stylesheet" crossorigin href="/assets/global-Dcdq4qY7.css">
51
51
  </head>
52
52
  <body class="bg-slate-50 text-slate-900">
53
53
  <div id="landing-root"></div>
@@ -1 +0,0 @@
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-BBTEUrko.js";import{c as j}from"./global-CaQPIFGa.js";import{B as _,b as rt,u as fe,s as D,t as ot,a as K}from"./app-BBdow7GJ.js";import{B as A,q as V}from"./queryKeys-BiuXKawV.js";import{C as Ee,a as De}from"./card-Do7RepdY.js";import{I as xe}from"./input-E9i52oYD.js";import{L as U}from"./label-ClDL__fF.js";import{S as te,a as se,b as le,c as ae,d as M}from"./select-CohvZ6L7.js";import{u as P}from"./i18n-C8tBby0x.js";import{D as it,A as nt,a as dt,b as ct,c as pt,d as ut}from"./DialogShell-BTPrPt5l.js";import{P as mt,a as re}from"./PageState-Cq7xpTfp.js";import{c as xt}from"./clipboard-CALi6bTW.js";import{u as B}from"./useApiQuery-nMqbFkID.js";import{g as Fe,f as gt,a as q,b as Te,c as ft,d as Q,e as ht}from"./utils-DSaa7c6v.js";import{P as yt,a as bt,b as jt}from"./popover-CLCOu-wx.js";import{L as vt}from"./router-D2Fb4U0L.js";import{T as wt}from"./Skeleton-DEhFppby.js";import{u as Nt}from"./query-QCek5MsK.js";import{g as Ce}from"./gateway-g4snI3mT.js";import"./radix-CtQBp6Ie.js";function kt({apiKeys:l,selected:t,onChange:d,disabled:r,className:c}){const{t:s}=P(),[o,h]=m.useState(!1),x=m.useRef(null);m.useEffect(()=>{if(!o)return;const n=a=>{var i;(i=x.current)!=null&&i.contains(a.target)||h(!1)};return window.addEventListener("mousedown",n),()=>window.removeEventListener("mousedown",n)},[o]);const f=m.useMemo(()=>{if(t.length===0)return[];const n=new Map;for(const a of l)n.set(a.id,a);return t.map(a=>{const i=n.get(a);return i?i.isWildcard?s("apiKeys.wildcard"):i.name:null}).filter(a=>!!a)},[l,t,s]),y=t.length===0?s("logs.filters.apiKeyAll"):s("logs.filters.apiKeySelected",{count:t.length}),g=n=>{t.includes(n)?d(t.filter(a=>a!==n)):d([...t,n])};return e.jsxs("div",{className:j("relative space-y-2",c),ref:x,children:[e.jsx(U,{children:s("logs.filters.apiKey")}),e.jsxs("button",{type:"button",onClick:()=>h(n=>!n),disabled:r||l.length===0,title:s("logs.filters.apiKeyHint"),className:j("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:[y,f.length>0&&e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:f.join(", ")})]}),e.jsx("svg",{className:j("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:y}),e.jsx("button",{type:"button",onClick:()=>d([]),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(n=>{const a=n.isWildcard?s("apiKeys.wildcard"):n.name,i=t.includes(n.id);return e.jsxs("label",{className:j("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-primary/5",i&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-border",checked:i,onChange:()=>g(n.id)}),e.jsx("span",{className:"truncate",children:a})]},n.id)}),l.length===0&&e.jsx("p",{className:"px-2 py-2 text-xs text-muted-foreground",children:s("logs.filters.apiKeyAll")})]})]})]})}function St(l){const{t}=P(),{total:d,activeFilters:r,filtersExpanded:c,setFiltersExpanded:s,handleResetFilters:o,activeQuickView:h,applyQuickView:x,providerFilter:f,setProviderFilter:y,endpointFilter:g,setEndpointFilter:n,selectedApiKeys:a,setSelectedApiKeys:i,modelFilter:N,setModelFilter:u,statusFilter:E,setStatusFilter:k,fromDate:C,setFromDate:F,toDate:w,setToDate:L,providerOptions:S,apiKeys:G,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(A,{variant:"secondary",className:"rounded-full px-2.5 py-0.5 text-[11px] font-semibold",children:t("logs.summary.total",{value:d.toLocaleString()})}),r.length>0&&e.jsx(A,{variant:"outline",className:"rounded-full border-transparent bg-primary/10 px-2.5 py-0.5 text-[11px] font-semibold text-primary",children:t("common.filters.activeCount",{count: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(b=>!b),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(b=>e.jsxs(A,{variant:"outline",role:"button",tabIndex:0,className:"flex cursor-pointer items-center gap-1 rounded-full border border-border bg-card/90 px-2.5 py-1 text-[11px] font-semibold text-foreground/90 transition hover:bg-secondary/80",onClick:b.onRemove,onKeyDown:X=>{(X.key==="Enter"||X.key===" ")&&(X.preventDefault(),b.onRemove())},children:[b.label,e.jsx(Ye,{className:"h-3 w-3","aria-hidden":"true"})]},b.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:a.length.toString()}),e.jsx(ge,{label:t("logs.filters.provider"),value:f==="all"?"0":"1"}),e.jsx(ge,{label:t("logs.filters.endpoint"),value:g==="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(b=>e.jsx(_,{variant:"ghost",size:"sm",className:j("h-7 rounded-full px-3 text-[11px] font-semibold transition-colors",h===b?"bg-card text-foreground shadow-[0_12px_28px_-24px_rgba(15,23,42,0.32)]":"text-muted-foreground"),onClick:()=>x(b),children:t(`logs.quickViews.${b}`)},b))})]}),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(U,{children:t("logs.filters.provider")}),e.jsxs(te,{value:f,onValueChange:y,children:[e.jsx(se,{children:e.jsx(le,{})}),e.jsxs(ae,{children:[e.jsx(M,{value:"all",children:t("logs.filters.providerAll")}),S.map(b=>e.jsx(M,{value:b.id,children:b.label??b.id},b.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{children:t("logs.filters.endpoint")}),e.jsxs(te,{value:g,onValueChange:n,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(b=>e.jsx(M,{value:b.id,children:b.label||b.id},b.id))]})]})]}),e.jsx(kt,{className:"md:col-span-2",apiKeys:G,selected:a,disabled:ie,onChange:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{children:t("logs.filters.modelId")}),e.jsx(xe,{value:N,onChange:b=>u(b.target.value),placeholder:t("logs.filters.modelPlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{children:t("logs.filters.status")}),e.jsxs(te,{value:E,onValueChange:b=>k(b),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(U,{children:t("logs.filters.startDate")}),e.jsx(xe,{type:"date",value:C,onChange:b=>F(b.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{children:t("logs.filters.endDate")}),e.jsx(xe,{type:"date",value:w,onChange:b=>L(b.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 d=await rt.post("/api/logs/export",l,{responseType:"blob",timeout:t});return new Blob([d.data],{type:"application/zip"})}};function Ct({apiKeyMap:l,logId:t,open:d,providerLabelMap:r}){var n;const{t:c}=P(),{pushToast:s}=fe(),o=B(V.logs.detail(t),he.detailRequest(t),{enabled:d&&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 h=m.useCallback(async(a,i,N)=>{if(!i){s({title:c("logs.detail.copy.empty",{label:a}),variant:"info"});return}try{await xt(i),s({title:c(N),variant:"success"})}catch(u){s({title:c("logs.detail.copy.failure"),description:u instanceof Error?u.message:c("logs.detail.copy.failureFallback"),variant:"error"})}},[s,c]),x=o.data,f=x?r.get(x.provider)??x.provider:"",y=x&&x.api_key_id!=null?l.get(x.api_key_id):void 0,g=x?Fe(x,c):null;return{apiKeyMeta:y,errorMessage:o.isError?((n=o.error)==null?void 0:n.message)??null:null,handleCopy:h,isError:o.isError,isPending:o.isPending,providerLabel:f,refetch:o.refetch,record:x,statusMeta:g}}function _t({open:l,logId:t,onClose:d,providerLabelMap:r,apiKeyMap:c}){var u,E;const{t:s}=P(),{apiKeyMeta:o,errorMessage:h,handleCopy:x,isError:f,isPending:y,providerLabel:g,refetch:n,record:a,statusMeta:i}=Ct({apiKeyMap:c,logId:t,open:l,providerLabelMap:r}),N=m.useMemo(()=>{var C,F,w,L;return a?[{key:"client-request",title:s("logs.detail.payload.clientRequest"),value:((C=a.payload)==null?void 0:C.client_request)??null,emptyLabel:s("logs.detail.payload.emptyRequest"),copyToast:"logs.detail.copy.requestSuccess"},...(F=a.payload)!=null&&F.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"}]:[],...(w=a.payload)!=null&&w.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:((L=a.payload)==null?void 0:L.client_response)??null,emptyLabel:s("logs.detail.payload.emptyResponse"),copyToast:"logs.detail.copy.responseSuccess"}].map(S=>({...S,displayValue:gt(S.value,S.emptyLabel)})):[]},[a,s]);return e.jsx(it,{open:l,onOpenChange:k=>{k||d()},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(pt,{children:a?s("logs.detail.id",{id:a.id}):s("logs.detail.loadError")})]}),e.jsx(ut,{className:"max-h-[78vh]",children:y?e.jsx(mt,{compact:!0,className:"min-h-[240px]",label:s("common.loading")}):f?e.jsx(re,{compact:!0,className:"min-h-[240px]",tone:"danger",title:s("logs.detail.loadError"),description:h??s("common.unknownError"),action:e.jsx(_,{variant:"outline",onClick:()=>void n(),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(A,{variant:i==null?void 0:i.variant,children:(i==null?void 0:i.label)??"-"}),e.jsx(A,{variant:"outline",children:a.stream?s("logs.stream.streaming"):s("logs.stream.single")})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(O,{label:s("logs.detail.info.latency"),value:q(a.latency_ms,s("common.units.ms"))}),e.jsx(O,{label:s("logs.detail.info.ttft"),value:q(a.ttft_ms,s("common.units.ms"))}),e.jsx(O,{label:s("logs.detail.info.tpot"),value:q(a.tpot_ms,s("common.units.msPerToken"))}),e.jsx(O,{label:s("logs.detail.info.status"),value:(i==null?void 0:i.label)??"-"})]}),e.jsxs("dl",{className:"grid gap-x-4 gap-y-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(R,{label:s("logs.detail.info.time"),value:Te(a.timestamp)}),e.jsx(R,{label:s("logs.detail.info.sessionId"),value:a.session_id??"-"}),e.jsx(R,{label:s("logs.detail.info.endpoint"),value:a.endpoint||"-"}),e.jsx(R,{label:s("logs.detail.info.provider"),value:g}),e.jsx(R,{label:s("logs.detail.info.requestedModel"),value:a.client_model??s("logs.detail.info.noRequestedModel")}),e.jsx(R,{label:s("logs.detail.info.model"),value:a.model}),e.jsx(R,{label:s("logs.detail.info.stream"),value:ft(a.stream)}),e.jsx(R,{label:s("logs.detail.info.status"),value:(i==null?void 0:i.label)??"-"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(O,{label:s("logs.detail.info.inputTokens"),value:Q(a.input_tokens)}),e.jsx(O,{label:s("logs.detail.info.cacheReadTokens"),value:Q(a.cache_read_tokens)}),e.jsx(O,{label:s("logs.detail.info.cacheCreationTokens"),value:Q(a.cache_creation_tokens)}),e.jsx(O,{label:s("logs.detail.info.outputTokens"),value:Q(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(R,{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(R,{label:s("logs.detail.apiKey.identifier"),value:a.api_key_id??s("common.noData")}),e.jsx(R,{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(R,{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:(u=a.payload)!=null&&u.upstream_request||(E=a.payload)!=null&&E.upstream_response?s("logs.detail.payload.helperWithUpstream"):s("logs.detail.payload.helperClientOnly")})]}),e.jsx("div",{className:"grid gap-4 xl:grid-cols-2",children:N.map(k=>e.jsx(Et,{title:k.title,value:k.value,displayValue:k.displayValue,onCopy:()=>x(k.title,k.value,k.copyToast),t:s},k.key))})]})]})]}):e.jsx(re,{compact:!0,className:"min-h-[240px]",title:s("logs.detail.loadError"),description:s("common.noData")})})]})})}function O({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 R({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 Et({displayValue:l,onCopy:t,title:d,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:d}),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 W=[20,50,100],$=["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 Dt(){if(typeof window>"u")return $;try{const l=window.localStorage.getItem(D.logs.visibleColumns);if(!l)return $;const t=JSON.parse(l);if(!Array.isArray(t))return $;const d=t.filter(r=>oe.includes(r));return d.length>0?d:$}catch{return $}}function Ft(){return typeof window>"u"?"comfortable":window.localStorage.getItem(D.logs.density)==="compact"?"compact":"comfortable"}function Tt(){if(typeof window>"u")return W[0];const l=window.localStorage.getItem(D.logs.pageSize),t=Number(l);return W.includes(t)?t:W[0]}function Rt(){if(typeof window>"u")return[];try{const l=window.localStorage.getItem(D.logs.selectedApiKeys);if(!l)return[];const t=JSON.parse(l);return Array.isArray(t)?t.map(d=>Number(d)).filter(d=>Number.isInteger(d)&&d>0):[]}catch{return[]}}function _e(l,t=!1){if(!l)return;const d=t?`${l}T23:59:59.999`:`${l}T00:00:00.000`,r=Date.parse(d);return Number.isFinite(r)?r:void 0}function Lt(l,t,d){return l===d&&t===d}function Kt({columnOptions:l,exporting:t,onExport:d,onRefresh:r,onResetColumns:c,onSetDensity:s,onToggleColumn:o,refreshing:h,rowDensity:x,total:f,visibleColumns:y,visibleColumnSet:g}){const{t:n}=P(),a=JSON.stringify(y)===JSON.stringify($);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:j("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",x==="comfortable"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"),children:n("logs.table.density.comfortable")}),e.jsx("button",{type:"button",onClick:()=>s("compact"),className:j("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",x==="compact"?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"),children:n("logs.table.density.compact")})]}),e.jsxs(yt,{children:[e.jsx(bt,{asChild:!0,children:e.jsx(_,{variant:"outline",size:"sm",className:"w-full sm:w-auto",children:n("logs.actions.columns")})}),e.jsxs(jt,{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:n("logs.actions.columns")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("logs.actions.visibleCount",{count:y.length})})]}),e.jsx(_,{variant:"ghost",size:"sm",onClick:c,disabled:a,children:n("common.actions.reset")})]}),e.jsx("div",{className:"grid gap-1.5",children:l.map(i=>{const N=g.has(i.id);return e.jsxs("label",{className:j("flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2 text-sm transition hover:bg-accent",N&&"bg-primary/10 text-primary"),children:[e.jsx("input",{type:"checkbox",checked:N,onChange:()=>o(i.id),className:"h-4 w-4 rounded border-border"}),e.jsx("span",{children:i.label})]},i.id)})})]})]}),e.jsxs(_,{onClick:d,disabled:t,className:"w-full sm:w-auto",children:[e.jsx(et,{className:"mr-2 h-4 w-4"}),n(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:n("logs.summary.total",{value:f.toLocaleString()})}),e.jsxs(_,{variant:"outline",size:"sm",onClick:r,disabled:h,className:"shrink-0",children:[e.jsx(tt,{className:j("mr-2 h-4 w-4",h&&"animate-spin")}),n(h?"common.actions.refreshing":"logs.actions.manualRefresh")]})]})]})}function Mt({record:l,providerLabelMap:t,apiKeyMap:d,onSelect:r,isEven:c,density:s,visibleColumnSet:o}){const{t:h}=P(),x=t.get(l.provider)??l.provider,f=l.endpoint||"-",y=Fe(l,h),g=l.client_model??h("logs.table.requestedModelFallback"),n=l.api_key_id!=null?d.get(l.api_key_id):void 0,a=l.api_key_id==null?h("logs.table.apiKeyUnknown"):n!=null&&n.isWildcard?h("apiKeys.wildcard"):n!=null&&n.name?n.name:l.api_key_name?l.api_key_name:h("logs.table.apiKeyUnknown"),i=s==="compact"?"px-3 py-1.5":"px-3 py-2",N=c?"bg-muted/30":"bg-background",u=ht(l.session_id),E=u==null?void 0:u.rowStyle,k=u==null?void 0:u.stickyStyle,C=u?{...u.stickyStyle,...u.accentStyle}:void 0;return e.jsxs("tr",{"data-session-id":u==null?void 0:u.sessionId,"data-session-color":u==null?void 0:u.colorKey,className:j("transition-colors",u?"":c?"bg-muted/30":"",u?"":"hover:bg-muted/50"),style:E,onMouseEnter:F=>{u&&Object.assign(F.currentTarget.style,u.hoverStyle)},onMouseLeave:F=>{u&&Object.assign(F.currentTarget.style,u.rowStyle)},children:[e.jsx("td",{className:j("sticky left-0 z-10 text-xs",i,u?"":N),style:C,children:Te(l.timestamp)}),o.has("endpoint")&&e.jsx("td",{className:j(i,"text-xs"),children:f}),o.has("provider")&&e.jsx("td",{className:j(i,"text-xs"),children:e.jsx("div",{className:"max-w-[100px] truncate",title:x,children:x})}),o.has("requestedModel")&&e.jsx("td",{className:j(i,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:g,children:g})}),o.has("routedModel")&&e.jsx("td",{className:j(i,"text-xs"),children:e.jsx("div",{className:"max-w-[120px] truncate",title:l.model,children:l.model})}),o.has("apiKey")&&e.jsx("td",{className:j(i,"text-xs text-muted-foreground"),children:e.jsx("div",{className:"max-w-[90px] truncate",title:a,children:a})}),o.has("inputTokens")&&e.jsx("td",{className:j(i,"text-right text-xs tabular-nums"),children:Q(l.input_tokens)}),o.has("cacheReadTokens")&&e.jsx("td",{className:j(i,"text-right text-xs tabular-nums"),children:Q(l.cache_read_tokens)}),o.has("cacheCreationTokens")&&e.jsx("td",{className:j(i,"text-right text-xs tabular-nums"),children:Q(l.cache_creation_tokens)}),o.has("outputTokens")&&e.jsx("td",{className:j(i,"text-right text-xs tabular-nums"),children:Q(l.output_tokens)}),o.has("latency")&&e.jsx("td",{className:j(i,"text-right text-xs tabular-nums"),children:q(l.latency_ms,"ms")}),o.has("ttft")&&e.jsx("td",{className:j(i,"text-right text-xs tabular-nums"),children:q(l.ttft_ms,"ms")}),o.has("tpot")&&e.jsx("td",{className:j(i,"text-right text-xs tabular-nums"),children:q(l.tpot_ms,"ms/tk")}),o.has("status")&&e.jsx("td",{className:j(i,"text-center"),children:e.jsx(A,{variant:y.variant,className:"text-xs",children:y.label})}),o.has("error")&&e.jsx("td",{className:j(i,"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:j("sticky right-0 z-10 text-center",i,u?"":N),style:k,children:e.jsx(_,{variant:"outline",size:"sm",onClick:()=>r(l.id),children:h("logs.actions.detail")})})]})}function Pt(l){const{t}=P(),{tableScrollRef:d,visibleColumnSet:r,visibleColumnCount:c,logsError:s,logsPending:o,items:h,activeFiltersCount:x,handleResetFilters:f,handleRetry:y,providerLabelMap:g,apiKeyMap:n,handleOpenDetail:a,rowDensity:i,showScrollHint:N,pageSize:u,setPageSize:E,page:k,totalPages:C,setPage:F}=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(A,{variant:"secondary",children:"Wide Table"}),e.jsx(A,{variant:"outline",className:"bg-background",children:t(i==="compact"?"logs.table.density.compact":"logs.table.density.comfortable")}),N?e.jsx(A,{variant:"warning",children:"Scroll for more"}):null]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{ref:d,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((w,L)=>e.jsx(wt,{columns:c},L)):s&&h.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:y,children:t("common.actions.refresh")}),x>0?e.jsx(_,{variant:"ghost",size:"sm",onClick:f,children:t("common.actions.reset")}):null]})})})}):h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:c,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:e.jsx(re,{compact:!0,tone:"primary",icon:e.jsx(lt,{className:"h-5 w-5","aria-hidden":"true"}),title:x>0?t("logs.empty.filteredTitle"):t("logs.empty.title"),description:x>0?t("logs.empty.filteredSubtitle"):t("logs.empty.subtitle"),action:e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[x>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(vt,{to:"/api-keys",children:t("logs.empty.actions.apiKeys")})})]})})})}):h.map((w,L)=>e.jsx(Mt,{record:w,providerLabelMap:g,apiKeyMap:n,onSelect:a,isEven:L%2===0,density:i,visibleColumnSet:r},w.id))})]})}),N&&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:u.toString(),onValueChange:w=>E(Number(w)),children:[e.jsx(se,{className:"h-8 w-[80px] bg-background",children:e.jsx(le,{})}),e.jsx(ae,{children:W.map(w=>e.jsx(M,{value:w.toString(),children:w},w))})]})]}),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:()=>F(w=>Math.max(w-1,1)),disabled:k<=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:C===0?0:k,total:C})}),e.jsx(_,{variant:"outline",size:"sm",onClick:()=>F(w=>C===0?w:Math.min(w+1,C)),disabled:C===0||k>=C,children:t("logs.table.pagination.next")})]})]})]})})}function At({exportTimeoutMs:l,queryParams:t,total:d}){const{t:r}=P(),{pushToast:c}=fe(),[s,o]=m.useState(!1),h=m.useCallback(async()=>{if(!s){o(!0);try{const x=d>0?Math.min(d,5e3):1e3,f={...t,limit:x,offset:0},y=await he.exportArchive(f,l),g=new Date().toISOString().replace(/[:.]/g,"-"),n=URL.createObjectURL(y),a=document.createElement("a");a.href=n,a.download=`cc-gw-logs-${g}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(n),c({title:r("logs.toast.exportSuccess.title"),description:r("logs.toast.exportSuccess.desc"),variant:"success"})}catch(x){const f=ot(x);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,d]);return{exporting:s,handleExport:h}}function zt(){const l=m.useRef(null),[t,d]=m.useState(!1),r=m.useCallback(()=>{const c=l.current;if(!c)return;const s=c.scrollWidth-c.scrollLeft-c.clientWidth>1;d(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 Ot(){const[l,t]=K(D.logs.density,Ft,{serialize:y=>y,deserialize:y=>y==="compact"?"compact":"comfortable"}),[d,r]=K(D.logs.visibleColumns,Dt),{scrollRef:c,showScrollHint:s}=zt(),o=m.useMemo(()=>new Set(d),[d]),h=d.length+2,x=m.useCallback(y=>{r(g=>{if(g.includes(y))return g.length===1?g:g.filter(a=>a!==y);const n=[...g,y];return n.sort((a,i)=>oe.indexOf(a)-oe.indexOf(i)),n})},[]);return{resetVisibleColumns:m.useCallback(()=>{r($)},[]),rowDensity:l,setRowDensity:t,showScrollHint:s,tableScrollRef:c,toggleColumn:x,visibleColumnCount:h,visibleColumns:d,visibleColumnSet:o}}function qt(){var ve,we,Ne,ke,Se;const{t:l}=P(),{pushToast:t}=fe(),d=Nt(),[r,c]=K(D.logs.providerFilter,"all"),[s,o]=K(D.logs.endpointFilter,"all"),[h,x]=K(D.logs.modelFilter,""),[f,y]=K(D.logs.statusFilter,"all"),[g,n]=K(D.logs.fromDate,""),[a,i]=K(D.logs.toDate,""),[N,u]=m.useState(1),[E,k]=K(D.logs.pageSize,Tt,{serialize:p=>String(p),deserialize:p=>{const v=Number(p);return W.includes(v)?v:W[0]}}),[C,F]=m.useState(null),[w,L]=m.useState(!1),[S,G]=K(D.logs.selectedApiKeys,Rt),[ie,J]=K(D.logs.filtersExpanded,!1),{resetVisibleColumns:b,rowDensity:X,setRowDensity:Re,showScrollHint:Le,tableScrollRef:Ke,toggleColumn:Me,visibleColumnCount:Pe,visibleColumns:Ae,visibleColumnSet:ze}=Ot(),Oe=m.useDeferredValue(h),T=h===""?"":Oe;m.useEffect(()=>{u(1)},[r,s,T,f,g,a,E,S]);const ne=m.useMemo(()=>{const p={limit:E,offset:(N-1)*E};r!=="all"&&(p.provider=r),s!=="all"&&(p.endpoint=s),T.trim().length>0&&(p.model=T.trim()),f!=="all"&&(p.status=f);const v=_e(g),I=_e(a,!0);return v!==void 0&&(p.from=v),I!==void 0&&(p.to=I),S.length>0&&(p.apiKeys=S.join(",")),p},[T,s,g,N,E,r,S,f,a]),z=B(V.logs.list(ne),he.listRequest(ne),{gcTime:6e4}),H=B(V.providers.all(),Ce.providersRequest()),ye=B(V.apiKeys.all(),{url:"/api/keys",method:"GET"}),de=B(V.customEndpoints.all(),{url:"/api/custom-endpoints",method:"GET"}),be=B(V.config.exportTimeout(),Ce.configRequest());m.useEffect(()=>{!z.isError||!z.error||t({title:l("logs.toast.listError.title"),description:l("logs.toast.listError.desc",{message:z.error.message}),variant:"error"})},[z.error,z.isError,t,l]),m.useEffect(()=>{!H.isError||!H.error||t({title:l("logs.toast.providerError.title"),description:l("logs.toast.providerError.desc",{message:H.error.message}),variant:"error"})},[H.error,H.isError,t,l]);const ee=((ve=z.data)==null?void 0:ve.total)??0,Z=ee>0?Math.ceil(ee/E):0,qe=((we=z.data)==null?void 0:we.items)??[],Qe=m.useMemo(()=>{var v;const p=(v=be.data)==null?void 0:v.logExportTimeoutSeconds;return typeof p=="number"&&Number.isFinite(p)?Math.min(Math.max(Math.round(p),5),600)*1e3:6e4},[(Ne=be.data)==null?void 0:Ne.logExportTimeoutSeconds]);m.useEffect(()=>{Z>0&&N>Z&&u(Z)},[N,Z]);const ce=H.data??[],pe=m.useMemo(()=>{const p=new Map;for(const v of ce)v.id&&p.set(v.id,v.label??v.id);return p},[ce]),je=m.useMemo(()=>{var v;const p=new Map;p.set("anthropic",l("logs.filters.endpointAnthropic")),p.set("openai",l("logs.filters.endpointOpenAI"));for(const I of((v=de.data)==null?void 0:v.endpoints)??[])p.set(I.id,I.label||I.id);return p},[(ke=de.data)==null?void 0:ke.endpoints,l]),Ie=m.useMemo(()=>{const p=[];if(r!=="all"){const v=pe.get(r)??r;p.push({key:"provider",label:`${l("logs.filters.provider")}: ${v}`,onRemove:()=>c("all")})}if(s!=="all"){const v=je.get(s)??s;p.push({key:"endpoint",label:`${l("logs.filters.endpoint")}: ${v}`,onRemove:()=>o("all")})}if(T.trim()&&p.push({key:"model",label:`${l("logs.filters.modelId")}: ${T.trim()}`,onRemove:()=>x("")}),f!=="all"){const v=l(f==="success"?"logs.filters.statusSuccess":"logs.filters.statusError");p.push({key:"status",label:`${l("logs.filters.status")}: ${v}`,onRemove:()=>y("all")})}return g&&p.push({key:"from",label:`${l("logs.filters.startDate")}: ${g}`,onRemove:()=>n("")}),a&&p.push({key:"to",label:`${l("logs.filters.endDate")}: ${a}`,onRemove:()=>i("")}),S.length>0&&p.push({key:"apiKeys",label:l("logs.filters.apiKeySelected",{count:S.length}),onRemove:()=>G([])}),p},[T,s,je,g,r,pe,S.length,f,l,a]),ue=ye.data??[],Ve=m.useMemo(()=>{const p=new Map;for(const v of ue)p.set(v.id,v);return p},[ue]),Ue=m.useMemo(()=>oe.map(p=>({id:p,label:l(`logs.table.columns.${p}`)})),[l]),Y=m.useMemo(()=>new Date().toISOString().slice(0,10),[]),$e=m.useMemo(()=>r==="all"&&s==="all"&&T.trim()===""&&f==="all"&&g===""&&a===""&&S.length===0?"all":f==="error"&&s==="all"&&r==="all"&&T.trim()===""&&g===""&&a===""&&S.length===0?"errors":Lt(g,a,Y)&&s==="all"&&r==="all"&&T.trim()===""&&f==="all"&&S.length===0?"today":s==="anthropic"&&r==="all"&&T.trim()===""&&f==="all"&&g===""&&a===""&&S.length===0?"anthropic":s==="openai"&&r==="all"&&T.trim()===""&&f==="all"&&g===""&&a===""&&S.length===0?"openai":null,[T,s,g,r,S.length,f,a,Y]),me=m.useCallback(()=>{c("all"),x(""),o("all"),y("all"),n(""),i(""),G([])},[]),He=m.useCallback(p=>{if(u(1),me(),p!=="all"){if(p==="errors"){y("error");return}if(p==="today"){n(Y),i(Y);return}if(p==="anthropic"){o("anthropic");return}p==="openai"&&o("openai")}},[me,Y]),{exporting:Be,handleExport:We}=At({exportTimeoutMs:Qe,queryParams:ne,total:ee}),Ge=m.useCallback(p=>{d.removeQueries({queryKey:["logs","detail"],type:"inactive"}),F(p),L(!0)},[d]),Je=m.useCallback(()=>{L(!1)},[]);return m.useEffect(()=>{w||C===null||(d.removeQueries({queryKey:V.logs.detail(C),exact:!0}),F(null))},[w,d,C]),{activeFilters:Ie,activeQuickView:$e,apiKeyMap:Ve,apiKeys:ue,apiKeysQuery:ye,applyQuickView:He,columnOptions:Ue,customEndpoints:(Se=de.data)==null?void 0:Se.endpoints,endpointFilter:s,exporting:Be,filtersExpanded:ie,fromDate:g,handleCloseDetail:Je,handleExport:We,handleOpenDetail:Ge,handleResetFilters:me,isDetailOpen:w,items:qe,logsQuery:z,modelFilter:h,page:N,pageSize:E,providerFilter:r,providerLabelMap:pe,providerOptions:ce,rowDensity:X,resetVisibleColumns:b,selectedApiKeys:S,selectedLogId:C,setEndpointFilter:o,setFiltersExpanded:J,setFromDate:n,setModelFilter:x,setPage:u,setPageSize:k,setProviderFilter:c,setRowDensity:Re,setSelectedApiKeys:G,setStatusFilter:y,setToDate:i,showScrollHint:Le,statusFilter:f,tableScrollRef:Ke,toDate:a,toggleColumn:Me,total:ee,totalPages:Z,visibleColumnCount:Pe,visibleColumns:Ae,visibleColumnSet:ze}}function ns(){var d;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(Kt,{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(St,{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(Pt,{tableScrollRef:t.tableScrollRef,visibleColumnSet:t.visibleColumnSet,visibleColumnCount:t.visibleColumnCount,logsError:t.logsQuery.isError?((d=t.logsQuery.error)==null?void 0:d.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(_t,{open:t.isDetailOpen,logId:t.selectedLogId,onClose:t.handleCloseDetail,providerLabelMap:t.providerLabelMap,apiKeyMap:t.apiKeyMap})]})}export{ns as default};
@@ -1 +0,0 @@
1
- import{r as S,j as e,a7 as H,aH as be,aI as J,ac as $,al as ve,a0 as Ne,S as ye}from"./vendor-DdPBfMMb.js";import{L as we}from"./router-D2Fb4U0L.js";import{C as ke}from"./ConfirmDialog-Gz0TZO4h.js";import{P as Me}from"./PageToolbar-BBTEUrko.js";import{B as k,c as te,a as Ce,s as Ee,T as Pe,d as De,e as Ae,f as Se}from"./app-BBdow7GJ.js";import{u as ne}from"./useAppMutation-D2xDZiR6.js";import{I as T}from"./input-E9i52oYD.js";import{L as P}from"./label-ClDL__fF.js";import{S as ie,a as oe,b as de,c as ce,d as F}from"./select-CohvZ6L7.js";import{S as me}from"./switch-CwlkqLey.js";import{q as re,B as C}from"./queryKeys-BiuXKawV.js";import{u as O}from"./i18n-C8tBby0x.js";import{C as xe,a as pe}from"./card-Do7RepdY.js";import{c as z}from"./global-CaQPIFGa.js";import{D as Te,A as Oe,a as Re,b as Le,c as _e,d as $e,e as ze}from"./DialogShell-BTPrPt5l.js";import{P as Ve,a as Be,b as He}from"./popover-CLCOu-wx.js";import{i as Ie,g as Fe,a as qe,C as Ge,O as Ke,u as Ue}from"./useModelManagementState-Zwu7DIdu.js";import"./query-QCek5MsK.js";import"./radix-CtQBp6Ie.js";import"./gateway-g4snI3mT.js";import"./useApiQuery-nMqbFkID.js";const We=["anthropic","openai-auto","openai-chat","openai-responses"];function Qe({open:o,endpoint:s,onClose:g,onSuccess:r}){const{t:a}=O(),[d,p]=S.useState({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0});S.useEffect(()=>{if(s){const t=s.paths&&s.paths.length>0?s.paths:s.path&&s.protocol?[{path:s.path,protocol:s.protocol}]:[{path:"",protocol:"openai-auto"}];p({id:s.id,label:s.label,paths:t,enabled:s.enabled!==!1});return}p({id:"",label:"",paths:[{path:"",protocol:"openai-auto"}],enabled:!0})},[s,o]);const n=ne({mutationFn:te.create,invalidateKeys:[re.customEndpoints.all()],successToast:()=>({title:a("modelManagement.createEndpointSuccess")}),errorToast:t=>({title:a("modelManagement.createEndpointError",{error:t.message})}),onSuccess:async()=>{r(),g()}}),c=ne({mutationFn:t=>te.update(t.id,t.updates),invalidateKeys:[re.customEndpoints.all()],successToast:()=>({title:a("modelManagement.updateEndpointSuccess")}),errorToast:t=>({title:a("modelManagement.updateEndpointError",{error:t.message})}),onSuccess:async()=>{r(),g()}}),w=()=>{p(t=>({...t,paths:[...t.paths,{path:"",protocol:"anthropic"}]}))},m=t=>{d.paths.length!==1&&p(x=>({...x,paths:x.paths.filter((j,E)=>E!==t)}))},N=(t,x,j)=>{p(E=>{const D=[...E.paths];return D[t]={...D[t],[x]:j},{...E,paths:D}})},f=t=>{if(t==null||t.preventDefault(),!d.id.trim()||!d.label.trim())return;for(const j of d.paths)if(!j.path.trim())return;const x=d.paths.map(j=>({path:j.path.trim(),protocol:j.protocol}));if(s){c.mutate({id:s.id,updates:{label:d.label.trim(),paths:x,enabled:d.enabled}});return}n.mutate({id:d.id.trim(),label:d.label.trim(),paths:x,enabled:d.enabled})},u=n.isPending||c.isPending,l=d.paths.length===0?a("modelManagement.atLeastOnePath"):!d.id.trim()||!d.label.trim()?a("modelManagement.endpointValidationError"):d.paths.some(t=>!t.path.trim())?a("modelManagement.pathValidationError"):null;return o?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40 bg-background/80 backdrop-blur-sm",onClick:g}),e.jsx("div",{className:"fixed inset-y-0 right-0 z-50 w-full max-w-md border-l border-border/45 bg-background/96 shadow-[var(--surface-shadow-lg)] backdrop-blur",children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border/45 bg-secondary/45 p-6 backdrop-blur-sm",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-semibold tracking-[-0.02em]",children:a(s?"modelManagement.editEndpoint":"modelManagement.createEndpoint")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s?s.id:a("modelManagement.endpointRoutingHint")})]}),e.jsx(k,{variant:"ghost",size:"sm",onClick:g,className:"rounded-2xl bg-white/70",children:e.jsx(H,{className:"h-4 w-4"})})]}),e.jsxs("form",{onSubmit:f,className:"flex-1 space-y-6 overflow-y-auto p-6",children:[e.jsxs("div",{className:"grid gap-3 rounded-xl bg-secondary/50 p-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointId")}),e.jsx("p",{className:"truncate text-sm font-medium text-foreground",children:(s==null?void 0:s.id)||"new-endpoint"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground",children:a("modelManagement.endpointEnabled")}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:d.enabled?a("common.status.enabled"):a("common.status.disabled")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(P,{children:[a("modelManagement.endpointId")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T,{value:d.id,onChange:t=>p(x=>({...x,id:t.target.value})),placeholder:a("modelManagement.endpointIdPlaceholder"),disabled:!!s,required:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("modelManagement.endpointIdHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(P,{children:[a("modelManagement.endpointLabel")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(T,{value:d.label,onChange:t=>p(x=>({...x,label:t.target.value})),placeholder:a("modelManagement.endpointLabelPlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(P,{children:[a("modelManagement.endpointPaths")," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(k,{type:"button",variant:"ghost",size:"sm",onClick:w,children:[e.jsx(be,{className:"mr-1 h-3 w-3"}),a("modelManagement.addPath")]})]}),e.jsx("div",{className:"space-y-3",children:d.paths.map((t,x)=>e.jsxs("div",{className:"space-y-2 rounded-xl border border-transparent bg-card p-3 shadow-[var(--surface-shadow)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(T,{value:t.path,onChange:j=>N(x,"path",j.target.value),placeholder:a("modelManagement.endpointPathPlaceholder"),required:!0}),e.jsxs(ie,{value:t.protocol,onValueChange:j=>N(x,"protocol",j),children:[e.jsx(oe,{children:e.jsx(de,{})}),e.jsx(ce,{children:We.map(j=>e.jsx(F,{value:j,children:a(j==="anthropic"?"modelManagement.protocolAnthropic":j==="openai-auto"?"modelManagement.protocolOpenAI":j==="openai-chat"?"modelManagement.protocolOpenAIChat":"modelManagement.protocolOpenAIResponses")},j))})]})]}),d.paths.length>1?e.jsx(k,{type:"button",variant:"ghost",size:"sm",onClick:()=>m(x),className:"text-destructive",children:e.jsx(H,{className:"h-4 w-4"})}):null]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[x===0?e.jsx("p",{children:a("modelManagement.endpointPathHint")}):null,e.jsx("p",{children:a(`modelManagement.protocolHints.${t.protocol}`)})]})]},`${t.protocol}-${x}`))}),l?e.jsx("p",{className:"text-xs text-destructive",children:l}):null]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(me,{id:"enabled",checked:d.enabled,onCheckedChange:t=>p(x=>({...x,enabled:t}))}),e.jsx(P,{htmlFor:"enabled",children:a("modelManagement.endpointEnabled")})]}),s?null:e.jsx("div",{className:"rounded-xl bg-accent p-4",children:e.jsx("p",{className:"text-sm text-primary",children:a("modelManagement.endpointRoutingHint")})})]}),e.jsxs("div",{className:"flex gap-3 border-t border-border/45 bg-secondary/45 p-6 backdrop-blur-sm",children:[e.jsx(k,{variant:"outline",className:"flex-1",onClick:g,disabled:u,children:a("common.cancel")}),e.jsx(k,{className:"flex-1",onClick:()=>f(),disabled:u,children:a(u?"common.saving":s?"common.save":"common.create")})]})]})})]}):null}function q(o,s){return s(o==="anthropic"?"modelManagement.protocolAnthropic":o==="openai-chat"?"modelManagement.protocolOpenAIChat":o==="openai-responses"?"modelManagement.protocolOpenAIResponses":"modelManagement.protocolOpenAI")}function Xe({activeTab:o,customEndpoints:s,customTabs:g,isDirtyByEndpoint:r,onDeleteEndpoint:a,onEditEndpoint:d,onSelectTab:p,systemTabs:n}){const{t:c}=O(),w=[...n,...g].find(m=>m.key===o)??null;return e.jsx(xe,{className:"overflow-hidden rounded-[1.35rem] border border-white/70 bg-card/95 shadow-[0_22px_56px_-46px_rgba(15,23,42,0.22)]",children:e.jsxs(pe,{className:"space-y-4 p-4 sm:p-5",children:[e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(280px,0.6fr)]",children:[e.jsxs("div",{className:"rounded-[1.1rem] bg-secondary/60 p-2.5",children:[e.jsx("div",{className:"mb-2 flex items-center justify-between px-1",children:e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/75",children:c("modelManagement.overview.providerAndSystem")})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-3",children:n.map(m=>{const N=o===m.key,f=m.key!=="providers"&&r[m.key];return e.jsxs("button",{type:"button",onClick:()=>p(m.key),"aria-pressed":N,className:z("group flex min-h-[76px] flex-col justify-between rounded-[0.95rem] px-3 py-3 text-left transition-all",N?"bg-card text-foreground shadow-[0_14px_34px_-28px_rgba(15,23,42,0.3)] ring-1 ring-primary/10":"bg-transparent text-muted-foreground hover:bg-card/58 hover:text-foreground"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-[15px] font-semibold text-foreground",children:m.label}),e.jsx("div",{className:"mt-0.5 text-[10px] uppercase tracking-[0.14em] text-muted-foreground/70",children:m.key==="providers"?c("modelManagement.overview.providerPoolTag"):c("modelManagement.overview.systemEndpointTag")})]}),f?e.jsx("span",{className:"mt-1 h-2.5 w-2.5 rounded-full bg-amber-500"}):null]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between gap-3",children:[e.jsx("span",{className:"line-clamp-1 text-xs text-muted-foreground/70",children:m.description}),N?e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(J,{className:"h-3.5 w-3.5"})}):null]})]},m.key)})})]}),w?e.jsxs("div",{className:"flex min-h-[116px] flex-col justify-between rounded-[1.1rem] bg-[linear-gradient(135deg,hsl(var(--primary)/0.1),rgba(255,255,255,0.78))] p-4 ring-1 ring-primary/10 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.14),rgba(15,23,42,0.72))] dark:ring-white/10",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"inline-flex h-8 w-8 items-center justify-center rounded-xl bg-primary/10 text-primary",children:e.jsx(J,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/75",children:"Active workspace"}),e.jsx("p",{className:"truncate text-sm font-semibold text-foreground",children:w.label})]})]}),e.jsx("p",{className:"mt-3 line-clamp-2 text-xs leading-5 text-muted-foreground",children:w.description})]}):null]}),g.length>0?e.jsxs("div",{className:"space-y-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-muted-foreground/75",children:c("modelManagement.overview.customEndpoints")}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2 2xl:grid-cols-3",children:g.map(m=>{const N=o===m.key,f=r[m.key],u=s.find(l=>l.id===m.key);return e.jsxs("div",{className:z("group relative flex min-w-0 flex-col gap-2.5 overflow-hidden rounded-[1.05rem] border px-3 py-3 text-left transition-all sm:px-3.5",N?"border-primary/20 bg-secondary/80 text-foreground shadow-[0_14px_34px_-30px_rgba(59,130,246,0.32)]":"border-border/55 bg-background/42 hover:bg-secondary/50"),children:[e.jsxs("button",{type:"button",onClick:()=>p(m.key),"aria-pressed":N,className:"min-w-0 flex-1 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-foreground sm:text-[15px]",title:m.label,children:m.label}),f?e.jsx("span",{className:"h-2 w-2 rounded-full bg-amber-500"}):null]}),e.jsxs("div",{className:"mt-1.5 flex items-end justify-between gap-3",children:[e.jsx("p",{className:"line-clamp-2 text-[11px] leading-4.5 text-muted-foreground/72 sm:line-clamp-1 sm:text-xs",children:m.description}),N?e.jsx("span",{className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(J,{className:"h-3.5 w-3.5"})}):null]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-1.5",children:[e.jsx(C,{variant:(u==null?void 0:u.enabled)===!1?"secondary":"success",className:"rounded-full border-0 px-2 py-0.5 text-[10px]",children:(u==null?void 0:u.enabled)===!1?c("modelManagement.overview.endpointDisabled"):c("modelManagement.overview.endpointEnabled")}),(m.protocols??[]).slice(0,2).map(l=>e.jsx(C,{variant:"outline",className:"max-w-[130px] truncate rounded-full text-[10px]",title:q(l,c),children:q(l,c)},`${m.key}-${l}`))]}),e.jsxs("div",{className:"min-w-0 rounded-[0.8rem] bg-secondary/55 px-2.5 py-2",children:[e.jsx("p",{className:"mb-1 text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground/70",children:c("modelManagement.overview.endpointPaths")}),e.jsx("div",{className:"space-y-1",children:Je(u,c).map(l=>e.jsx("p",{className:"truncate text-xs font-medium text-foreground",title:l,children:l},l))})]}),e.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-2",children:[e.jsx(k,{variant:"ghost",size:"sm",className:"h-7 justify-start rounded-full px-2 text-[11px]",disabled:!u,onClick:()=>{u&&d(u)},children:c("common.edit")}),m.canDelete?e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),u&&a({kind:"endpoint",endpoint:u})},className:"flex h-7 w-full items-center justify-center rounded-md text-muted-foreground transition hover:bg-destructive/10 hover:text-destructive sm:w-7",title:c("common.delete"),children:e.jsx(H,{className:"h-3.5 w-3.5"})}):null]}),m.canDelete?null:e.jsx("div",{className:"text-[11px] text-muted-foreground/70",children:c("modelManagement.overview.endpointManagedExternally")})]},m.key)})})]}):null]})})}function Je(o,s){var g;if(!o)return[s("common.noData")];if((g=o.paths)!=null&&g.length){const r=o.paths.slice(0,2).map(a=>`${a.path} · ${q(a.protocol,s)}`);return o.paths.length>2&&r.push(s("modelManagement.overview.endpointMorePaths",{count:o.paths.length-2})),r}return o.path?[`${o.path} · ${q(o.protocol??"anthropic",s)}`]:[s("common.noData")]}function Ye({dialog:o,currentRoutes:s,onConfirm:g,onClose:r}){const{t:a}=O();if(!o)return null;const{endpoint:d,preset:p}=o,n=p.modelRoutes??{},c={};for(const l of s){const t=l.source.trim(),x=l.target.trim();t&&x&&(c[t]=x)}const w=new Set([...Object.keys(c),...Object.keys(n)]),m=[],N=[],f=[];for(const l of w){const t=l in c,x=l in n;x&&!t?m.push([l,n[l]]):t&&!x?N.push([l,c[l]]):t&&x&&c[l]!==n[l]&&f.push([l,c[l],n[l]])}const u=m.length>0||N.length>0||f.length>0;return e.jsx(Te,{open:!0,onOpenChange:l=>!l&&r(),children:e.jsxs(Oe,{className:"max-w-2xl",children:[e.jsxs(Re,{children:[e.jsx(Le,{children:a("modelManagement.presets.diffTitle")}),e.jsx(_e,{children:a("modelManagement.presets.diffDescription",{name:p.name})})]}),e.jsx($e,{children:u?e.jsxs("div",{className:"max-h-80 space-y-2 rounded-xl bg-secondary/50 p-3 text-sm",children:[m.map(([l,t])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-emerald-50 px-2 py-1.5 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200",children:[e.jsx(C,{variant:"outline",className:"border-emerald-300 text-xs dark:border-emerald-700",children:a("modelManagement.presets.diffAdded")}),e.jsx("span",{className:"truncate",children:l}),e.jsx($,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t})]},`add-${l}`)),N.map(([l,t])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-red-50 px-2 py-1.5 text-red-800 dark:bg-red-950 dark:text-red-200",children:[e.jsx(C,{variant:"outline",className:"border-red-300 text-xs dark:border-red-700",children:a("modelManagement.presets.diffRemoved")}),e.jsx("span",{className:"truncate",children:l}),e.jsx($,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t})]},`rm-${l}`)),f.map(([l,t,x])=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-amber-50 px-2 py-1.5 text-amber-800 dark:bg-amber-950 dark:text-amber-200",children:[e.jsx(C,{variant:"outline",className:"border-amber-300 text-xs dark:border-amber-700",children:a("modelManagement.presets.diffChanged")}),e.jsx("span",{className:"truncate",children:l}),e.jsx($,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate line-through opacity-60",children:t}),e.jsx($,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:x})]},`chg-${l}`))]}):e.jsx("p",{className:"rounded-xl bg-secondary/50 py-8 text-center text-sm text-muted-foreground",children:a("modelManagement.presets.diffEmpty")})}),e.jsxs(ze,{children:[e.jsx(k,{variant:"outline",onClick:r,children:a("common.cancel")}),e.jsx(k,{onClick:()=>g(d,p),disabled:!u,children:a("modelManagement.presets.diffConfirm")})]})]})})}const le=6;function Ze({value:o,onChange:s,options:g,disabled:r,placeholder:a}){const{t:d}=O(),[p,n]=S.useState(!1),[c,w]=S.useState(""),m=S.useRef(null),[N,f]=Ce(Ee.modelManagement.recentRouteTargets,[]),u=S.useMemo(()=>{const i=new Map;for(const b of g)i.set(b.value,b);return i},[g]),l=(i,b)=>b?[i.label,i.value,i.providerId??"",i.providerLabel??"",i.modelId??"",i.modelLabel??""].join(" ").toLowerCase().includes(b):!0,t=S.useMemo(()=>{const i=c.trim().toLowerCase(),b=g.filter(y=>l(y,i)),A=N.map(y=>u.get(y)??(i?void 0:{value:y,label:y,kind:"custom"})).filter(y=>!!y).filter(y=>l(y,i)).slice(0,le),R=[];A.length>0&&R.push({key:"recent",label:d("modelManagement.targetPicker.recent"),options:A});const V=new Map,L=[];for(const y of b){if(y.kind==="custom"||!y.providerId){L.push(y);continue}const B=`provider:${y.providerId}`,I=V.get(B);I?I.options.push(y):V.set(B,{key:B,label:y.providerLabel??y.providerId,options:[y]})}return R.push(...V.values()),L.length>0&&R.push({key:"custom",label:d("modelManagement.targetPicker.custom"),options:L,muted:!0}),R},[u,g,N,c,d]),x=t.reduce((i,b)=>i+b.options.length,0),j=i=>{s(i),f(b=>[i,...b.filter(A=>A!==i)].slice(0,le)),w(""),n(!1)},E=i=>i.kind==="passthrough"?d("modelManagement.targetPicker.passthrough"):i.kind==="custom"?d("modelManagement.targetPicker.customValue"):d("modelManagement.targetPicker.model"),D=i=>i.kind==="passthrough"||i.kind==="custom"?i.label:i.modelLabel??i.label;return e.jsxs(Ve,{open:p,onOpenChange:i=>{n(i),i&&w("")},children:[e.jsx(Be,{asChild:!0,children:e.jsx(T,{value:o,onChange:i=>{s(i.target.value),w(i.target.value),p||n(!0)},onFocus:()=>{w(""),n(!0)},onClick:()=>{p||n(!0)},placeholder:a,disabled:r,autoComplete:"off"})}),e.jsxs(He,{className:"flex max-h-[min(28rem,var(--radix-popover-content-available-height))] flex-col overflow-hidden rounded-xl border border-[color:var(--surface-border)] bg-popover/96 p-0 shadow-[var(--surface-shadow-lg)] backdrop-blur",style:{width:"max(var(--radix-popover-trigger-width), 360px)"},align:"start",onOpenAutoFocus:i=>{var b;i.preventDefault(),(b=m.current)==null||b.focus()},children:[e.jsxs("div",{className:"space-y-2 border-b border-border/70 px-3 py-3",children:[e.jsx(T,{ref:m,value:c,onChange:i=>w(i.target.value),placeholder:d("modelManagement.targetPicker.searchPlaceholder"),className:"h-9",autoComplete:"off"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:c.trim()?d("modelManagement.targetPicker.matchCount",{count:x}):d("modelManagement.targetPicker.helper")})]}),x===0?e.jsx("div",{className:"px-3 py-4 text-center text-xs text-muted-foreground",children:d("common.noMatches")}):e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-1.5",children:t.map(i=>e.jsxs("div",{className:"py-1",children:[e.jsxs("div",{className:z("sticky top-0 z-10 flex items-center justify-between bg-popover/95 px-2 py-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground backdrop-blur",i.muted&&"opacity-80"),children:[e.jsx("span",{className:"truncate",children:i.label}),e.jsx("span",{children:i.options.length})]}),e.jsx("div",{className:"space-y-1",children:i.options.map(b=>e.jsxs("button",{type:"button",className:z("flex w-full min-w-0 items-center gap-2 rounded-lg px-3 py-2 text-left text-sm transition-colors hover:bg-accent/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",b.value===o.trim()&&"bg-accent/90 text-accent-foreground"),onMouseDown:A=>{A.preventDefault(),j(b.value)},children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-medium",children:D(b)}),e.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:b.value})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[b.isDefault?e.jsx(C,{variant:"secondary",className:"text-[10px]",children:d("modelManagement.targetPicker.default")}):null,e.jsx(C,{variant:b.kind==="passthrough"?"outline":"secondary",className:"text-[10px]",children:E(b)})]})]},`${i.key}-${b.value}`))})]},i.key))})]})]})}function es({endpoint:o,tabs:s,customEndpoints:g,config:r,routes:a,routeError:d,savingRoute:p,isDirty:n,presets:c,presetName:w,presetError:m,savingPreset:N,applyingPreset:f,deletingPreset:u,presetsExpanded:l,savingClaudeValidation:t,savingCompatibilityPolicy:x,providerModelOptions:j,onTogglePresetsExpanded:E,onPresetNameChange:D,onSavePreset:i,onRequestPresetDiff:b,onRequestDeletePreset:A,onValidationModeChange:R,onCompatibilityEnabledChange:V,onRouteChange:L,onRemoveRoute:y,onAddSuggestion:B,onAddRoute:I,onResetRoutes:ue,onSaveRoutes:he}){var se,ae;const{t:h}=O(),M=s.find(v=>v.key===o),G=((se=M==null?void 0:M.protocols)==null?void 0:se.includes("anthropic"))??o==="anthropic"?Ge:Ke,ge=(M==null?void 0:M.label)??o;(M==null?void 0:M.isSystem)===!1?M.description:h(`settings.routing.descriptionByEndpoint.${o}`);const K=`route-source-${o}`,Y=Ie(o,g),Z=((ae=M==null?void 0:M.protocols)==null?void 0:ae.some(v=>v.startsWith("openai")))??o==="openai",U=Fe(o,r,g),W=qe(o,r,g),Q=Y?(U==null?void 0:U.mode)??"off":"off",ee=Z?(W==null?void 0:W.enabled)??!1:!1,fe=new Set(a.map(v=>v.source.trim()).filter(Boolean)),je=`modelManagement.claudeValidation.options.${Q}.description`;return e.jsx(xe,{children:e.jsxs(pe,{className:"space-y-6 pt-6",children:[e.jsx("div",{className:"rounded-full bg-secondary px-4 py-3 text-xs text-muted-foreground",children:h("settings.routing.wildcardHint")}),Y?e.jsx("div",{className:"rounded-xl border border-primary/12 bg-[linear-gradient(135deg,hsl(var(--primary)/0.08),hsl(var(--accent)/0.72))] p-4 shadow-[var(--surface-shadow)] dark:border-sky-300/12 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.12),rgba(15,23,42,0.72))]",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary dark:text-sky-100",children:h("modelManagement.claudeValidation.title")}),e.jsx("p",{className:"max-w-2xl text-xs leading-5 text-muted-foreground dark:text-slate-300",children:h("modelManagement.claudeValidation.description")})]}),e.jsxs("div",{className:"flex w-full max-w-xs flex-col gap-2 self-start sm:self-auto",children:[e.jsx(P,{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/70 dark:text-sky-200/75",children:h("modelManagement.claudeValidation.modeLabel")}),e.jsxs(ie,{value:Q,onValueChange:v=>R(v),disabled:t,children:[e.jsx(oe,{className:"border-primary/15 bg-card/90 dark:border-white/10 dark:bg-slate-950/50",children:e.jsx(de,{})}),e.jsxs(ce,{children:[e.jsx(F,{value:"off",children:h("modelManagement.claudeValidation.options.off.label")}),e.jsx(F,{value:"anthropic-strict",children:h("modelManagement.claudeValidation.options.anthropic-strict.label")}),e.jsx(F,{value:"claude-code",children:h("modelManagement.claudeValidation.options.claude-code.label")})]})]}),e.jsx("span",{className:z("text-xs",Q==="off"?"text-muted-foreground dark:text-slate-400":"text-primary/80 dark:text-sky-200/80"),children:h(je)})]})]})}):null,Z?e.jsx("div",{className:"rounded-xl border border-primary/12 bg-[linear-gradient(135deg,hsl(var(--primary)/0.08),hsl(var(--accent)/0.72))] p-4 shadow-[var(--surface-shadow)] dark:border-sky-300/12 dark:bg-[linear-gradient(135deg,rgba(14,165,233,0.12),rgba(15,23,42,0.72))]",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-primary dark:text-sky-100",children:h("modelManagement.openaiCompatibility.title")}),e.jsx("p",{className:"max-w-2xl text-xs leading-5 text-muted-foreground dark:text-slate-300",children:h("modelManagement.openaiCompatibility.description")})]}),e.jsx("div",{className:"flex w-full max-w-xs flex-col gap-2 self-start sm:self-auto",children:e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-primary/12 bg-card/85 px-3 py-2 dark:border-white/10 dark:bg-slate-950/50",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(P,{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-primary/70 dark:text-sky-200/75",children:h("modelManagement.openaiCompatibility.toggleLabel")}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-slate-300",children:h(ee?"modelManagement.openaiCompatibility.enabledHint":"modelManagement.openaiCompatibility.disabledHint")})]}),e.jsx(me,{checked:ee,onCheckedChange:V,disabled:x,"aria-label":h("modelManagement.openaiCompatibility.toggleLabel")})]})})]})}):null,d?e.jsx("p",{className:"text-sm text-destructive",children:d}):null,e.jsx(ss,{presets:c,presetName:w,presetError:m,savingPreset:N,applyingPreset:f,deletingPreset:u,expanded:l,onToggleExpanded:E,onPresetNameChange:D,onSavePreset:i,onRequestPresetDiff:b,onRequestDeletePreset:A}),e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{className:"text-sm font-semibold text-foreground",children:h("modelManagement.routesEditorTitle")}),e.jsxs(C,{variant:"outline",children:[a.length," active"]})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:h("modelManagement.overview.routesEditorHint")})]}),e.jsxs("div",{className:"self-start rounded-full bg-card px-3 py-2 text-[11px] font-medium text-muted-foreground",children:["Active workspace · ",ge]})]}),a.length===0?e.jsxs("div",{className:"rounded-xl border-2 border-dashed border-border/30 bg-background/60 p-12 text-center text-sm text-muted-foreground",children:[e.jsx("p",{className:"font-medium",children:h("settings.routing.empty")}),e.jsx("p",{className:"mt-2 text-xs",children:h("modelManagement.emptyRoutesHint")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"hidden grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] items-center gap-3 px-1 text-xs font-medium text-muted-foreground md:grid",children:[e.jsx("span",{children:h("settings.routing.source")}),e.jsx("span",{}),e.jsx("span",{children:h("settings.routing.target")}),e.jsx("span",{})]}),a.map((v,_)=>e.jsxs("div",{className:"rounded-xl bg-card p-3 shadow-sm",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between md:hidden",children:[e.jsxs(C,{variant:"outline",className:"text-[11px]",children:["#",_+1]}),e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>y(v.id),disabled:p,children:e.jsx(H,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)_auto] md:items-center",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(P,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:h("settings.routing.source")}),e.jsx(T,{value:v.source,onChange:X=>L(v.id,"source",X.target.value),placeholder:h("settings.routing.sourcePlaceholder"),list:K,disabled:p,"aria-label":`route-source-${_+1}`})]}),e.jsx($,{className:"hidden h-4 w-4 flex-shrink-0 text-muted-foreground md:block"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(P,{className:"text-[11px] uppercase tracking-[0.16em] text-muted-foreground md:hidden",children:h("settings.routing.target")}),e.jsx(Ze,{value:v.target,onChange:X=>L(v.id,"target",X),options:j,disabled:p,placeholder:h("settings.routing.targetPlaceholder")})]}),e.jsx(k,{variant:"ghost",size:"icon",className:"hidden h-8 w-8 text-muted-foreground hover:text-destructive md:inline-flex",onClick:()=>y(v.id),disabled:p,children:e.jsx(H,{className:"h-4 w-4"})})]})]},v.id))]})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl bg-card p-4 shadow-[var(--surface-shadow)] md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium",children:h("modelManagement.actions.footerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:h(n?"modelManagement.actions.footerDirtyHint":"modelManagement.actions.footerSavedHint")})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3 md:flex md:flex-wrap md:items-center",children:[e.jsx(k,{variant:"outline",size:"sm",onClick:I,disabled:p,className:"w-full",children:h("settings.routing.add")}),e.jsx(k,{variant:"outline",size:"sm",onClick:ue,disabled:p||!n,className:"w-full",children:h("common.actions.reset")}),e.jsxs(k,{size:"sm",onClick:he,disabled:p,className:"relative w-full",children:[h(p?"common.actions.saving":"modelManagement.actions.saveRoutes"),n?e.jsx("span",{className:"absolute -right-1 -top-1 h-2 w-2 rounded-full bg-amber-500"}):null]})]})]}),e.jsxs("div",{className:"space-y-3 rounded-xl bg-secondary/50 p-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{className:"text-sm font-medium text-foreground",children:h("settings.routing.suggested")}),e.jsx(C,{variant:"outline",className:"text-[11px]",children:G.length})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:h("modelManagement.overview.suggestionHint")})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:G.map(v=>{const _=fe.has(v);return e.jsx(k,{variant:_?"ghost":"outline",size:"sm",onClick:()=>B(v),disabled:p||_,className:z("h-7 rounded-md px-2.5 text-[11px] font-normal",_?"opacity-45":"bg-background/70"),children:v},`${o}-${v}`)})})]}),e.jsx("datalist",{id:K,children:G.map(v=>e.jsx("option",{value:v},`${K}-${v}`))})]})})}function ss({presets:o,presetName:s,presetError:g,savingPreset:r,applyingPreset:a,deletingPreset:d,expanded:p,onToggleExpanded:n,onPresetNameChange:c,onSavePreset:w,onRequestPresetDiff:m,onRequestDeletePreset:N}){const{t:f}=O();return e.jsxs("div",{className:"rounded-xl bg-card shadow-[var(--surface-shadow)]",children:[e.jsx("button",{type:"button",className:"flex w-full items-center justify-between gap-3 rounded-xl p-4 text-left transition-colors hover:bg-accent",onClick:n,children:e.jsxs("div",{className:"flex items-center gap-2",children:[p?e.jsx(ve,{className:"h-4 w-4"}):e.jsx(Ne,{className:"h-4 w-4"}),e.jsx("h3",{className:"font-medium",children:f("modelManagement.presets.title")}),e.jsx(C,{variant:"secondary",className:"text-xs",children:o.length})]})}),p?e.jsxs("div",{className:"space-y-4 border-t border-border/45 px-4 pb-4 pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:f("modelManagement.presets.description")}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center",children:[e.jsx(T,{value:s,onChange:u=>c(u.target.value),placeholder:f("modelManagement.presets.namePlaceholder"),disabled:r,className:"w-full md:w-48"}),e.jsx(k,{onClick:w,disabled:r,className:"w-full md:w-auto",children:f(r?"modelManagement.presets.saving":"modelManagement.presets.save")})]}),g?e.jsx("p",{className:"text-sm text-destructive",children:g}):null,o.length===0?e.jsx("p",{className:"py-4 text-center text-sm text-muted-foreground",children:f("modelManagement.presets.empty")}):e.jsx(Pe,{children:e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:o.map(u=>{const l=a===u.name,t=d===u.name,x=Object.entries(u.modelRoutes??{}),j=x.length;return e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl bg-secondary/50 px-4 py-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs(De,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs("div",{className:"min-w-0 flex-1 cursor-default",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:u.name}),e.jsx(C,{variant:"outline",className:"mt-1 text-xs",children:j>0?f("modelManagement.presets.rulesCount",{count:j}):f("modelManagement.presets.noRules")})]})}),j>0?e.jsx(Se,{side:"bottom",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 text-xs",children:[x.slice(0,5).map(([E,D])=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"truncate",children:E}),e.jsx($,{className:"h-3 w-3 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:D})]},E)),j>5?e.jsxs("div",{className:"text-muted-foreground",children:["…+",j-5]}):null]})}):null]}),e.jsxs("div",{className:"grid flex-shrink-0 gap-2 sm:flex sm:items-center",children:[e.jsx(k,{size:"sm",onClick:()=>m(u),disabled:l||t,className:"w-full sm:w-auto",children:f(l?"modelManagement.presets.applying":"modelManagement.presets.apply")}),e.jsx(k,{variant:"destructive",size:"sm",onClick:()=>N(u),disabled:t||l,className:"w-full sm:w-auto",children:f(t?"modelManagement.presets.deleting":"modelManagement.presets.delete")})]})]},u.name)})})})]}):null]})}function ks(){var d,p;const{t:o}=O(),s=Ue(),g=s.systemTabs.filter(n=>n.key!=="providers"),r=s.activeTab==="providers"?"anthropic":s.activeTab,a=s.tabs.find(n=>n.key===r)??null;return S.useEffect(()=>{s.activeTab==="providers"&&s.setActiveTab("anthropic")},[s.activeTab,s.setActiveTab]),e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsx(Me,{info:(a==null?void 0:a.label)??r?e.jsx("span",{className:"rounded-full bg-secondary px-2.5 py-1 text-xs text-muted-foreground",children:(a==null?void 0:a.label)??r}):null,actions:e.jsxs(e.Fragment,{children:[e.jsx(k,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs(we,{to:"/models",children:[e.jsx(ye,{className:"h-4 w-4","aria-hidden":"true"}),o("nav.models")]})}),e.jsx(k,{size:"sm",onClick:s.handleOpenCreateEndpoint,children:o("modelManagement.addEndpoint")})]})}),e.jsx(Xe,{activeTab:r,customEndpoints:s.customEndpoints,customTabs:s.customTabs,isDirtyByEndpoint:s.isDirtyByEndpoint,onDeleteEndpoint:s.setConfirmAction,onEditEndpoint:s.handleOpenEditEndpoint,onSelectTab:s.setActiveTab,systemTabs:g}),e.jsx(es,{endpoint:r,applyingPreset:((d=s.applyingPreset)==null?void 0:d.endpoint)===r?s.applyingPreset.name:null,config:s.config,customEndpoints:s.customEndpoints,deletingPreset:((p=s.deletingPreset)==null?void 0:p.endpoint)===r?s.deletingPreset.name:null,isDirty:s.isDirtyByEndpoint[r]??!1,onAddRoute:()=>s.handleAddRoute(r),onAddSuggestion:n=>s.handleAddSuggestion(r,n),onPresetNameChange:n=>s.handlePresetNameChange(r,n),onRequestDeletePreset:n=>s.setConfirmAction({kind:"preset",endpoint:r,preset:n}),onRequestPresetDiff:n=>s.setPresetDiffDialog({endpoint:r,preset:n}),onRemoveRoute:n=>s.handleRemoveRoute(r,n),onResetRoutes:()=>s.handleResetRoutes(r),onRouteChange:(n,c,w)=>s.handleRouteChange(r,n,c,w),onSavePreset:()=>void s.handleSavePreset(r),onSaveRoutes:()=>void s.handleSaveRoutes(r),onCompatibilityEnabledChange:n=>void s.handleCompatibilityEnabledChange(r,n),onValidationModeChange:n=>void s.handleValidationModeChange(r,n),onTogglePresetsExpanded:()=>s.setPresetsExpanded(n=>({...n,[r]:!n[r]})),presetError:s.presetErrorByEndpoint[r],presetName:s.presetNameByEndpoint[r]??"",presets:s.presetsByEndpoint[r]??[],presetsExpanded:s.presetsExpanded[r]===!0,providerModelOptions:s.providerModelOptions,routeError:s.routeError[r],routes:s.routesByEndpoint[r]||[],savingClaudeValidation:s.savingClaudeValidation,savingCompatibilityPolicy:s.savingCompatibilityPolicy,savingPreset:s.savingPresetFor===r,savingRoute:s.savingRouteFor===r,tabs:s.tabs.filter(n=>n.key!=="providers")}),e.jsx(Qe,{open:s.endpointDrawerOpen,endpoint:s.editingEndpoint,onClose:()=>{s.setEndpointDrawerOpen(!1),s.setEditingEndpoint(void 0)},onSuccess:()=>{s.configQuery.refetch()}}),e.jsx(Ye,{dialog:s.presetDiffDialog,currentRoutes:s.presetDiffDialog?s.routesByEndpoint[s.presetDiffDialog.endpoint]||[]:[],onConfirm:(n,c)=>{s.setPresetDiffDialog(null),s.handleApplyPreset(n,c)},onClose:()=>s.setPresetDiffDialog(null)}),e.jsx(ke,{open:!!s.confirmAction,onOpenChange:n=>{!n&&!s.confirmingAction&&s.setConfirmAction(null)},title:s.confirmDialogTitle,description:s.confirmDialogDescription,confirmLabel:s.confirmingAction?o("common.actions.loading"):o("common.delete"),cancelLabel:o("common.actions.cancel"),loading:s.confirmingAction,onConfirm:s.handleConfirmDialog,children:s.confirmDialogName?e.jsx("div",{className:"rounded-lg bg-destructive/5 px-3 py-2 font-mono text-xs text-foreground ring-1 ring-destructive/20",children:s.confirmDialogName}):null})]})}export{ks as default};
@@ -1 +0,0 @@
1
- const o="0.8.18",s={version:o};export{s as p};
@@ -1 +0,0 @@
1
- import{r as i,j as o}from"./vendor-DdPBfMMb.js";import{l as n,m,n as p,o as a}from"./radix-CtQBp6Ie.js";import{c as l}from"./global-CaQPIFGa.js";const g=n,v=m,c=i.forwardRef(({className:t,align:e="center",sideOffset:r=4,...s},d)=>o.jsx(p,{children:o.jsx(a,{ref:d,align:e,sideOffset:r,className:l("z-50 w-72 rounded-[1.1rem] border border-[color:var(--surface-border)] bg-popover/96 p-4 text-popover-foreground shadow-[var(--surface-shadow-lg)] backdrop-blur outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...s})}));c.displayName=a.displayName;export{g as P,v as a,c as b};
@@ -1 +0,0 @@
1
- const o=[168,184,198,208,218,228,238,248,258,268,278,292],s=2e5;function i(t){const r=new Date(t);return`${r.getFullYear()}-${`${r.getMonth()+1}`.padStart(2,"0")}-${`${r.getDate()}`.padStart(2,"0")} ${`${r.getHours()}`.padStart(2,"0")}:${`${r.getMinutes()}`.padStart(2,"0")}:${`${r.getSeconds()}`.padStart(2,"0")}`}function u(t){return t==null?"-":t.toLocaleString()}function l(t,r){const n=u(t);return n==="-"?"-":`${n} ${r}`}function f(t){return t?"true":"false"}function g(t,r){if(!t||t.trim().length===0)return r;if(t.length>s)return t;try{const n=JSON.parse(t);return JSON.stringify(n,null,2)}catch{return t}}function S(t,r){return t.status_code===null||t.status_code===void 0?t.error?{label:r("common.status.error"),tone:"error",variant:"destructive"}:{label:r("common.status.pending"),tone:"pending",variant:"warning"}:t.error||t.status_code>=400?{label:t.status_code.toString(),tone:"error",variant:"destructive"}:{label:t.status_code.toString(),tone:"success",variant:"success"}}function c(t){let r=0;for(let n=0;n<t.length;n+=1)r=r*31+t.charCodeAt(n)>>>0;return r}function d(t){const r=t==null?void 0:t.trim();if(!r)return null;const n=c(r),e=o[n%o.length],a=`hsl(${e} 74% 46%)`;return{sessionId:r,colorKey:`${e}`,rowStyle:{backgroundColor:`hsl(${e} 74% 46% / 0.05)`},hoverStyle:{backgroundColor:`hsl(${e} 74% 46% / 0.09)`},stickyStyle:{backgroundColor:`hsl(${e} 74% 46% / 0.08)`},accentStyle:{borderLeft:`3px solid ${a}`}}}export{l as a,i as b,f as c,u as d,d as e,g as f,S as g};